2 * IPv6 Address [auto]configuration
3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
9 * $Id: addrconf.c,v 1.69 2001/10/31 21:55:54 davem Exp $
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
20 * Janos Farkas : delete timer on ifdown
21 * <chexum@bankinf.banki.hu>
22 * Andi Kleen : kill double kfree on module
24 * Maciej W. Rozycki : FDDI support
25 * sekiya@USAGI : Don't send too many RS
27 * yoshfuji@USAGI : Fixed interval between DAD
29 * YOSHIFUJI Hideaki @USAGI : improved accuracy of
30 * address validation timer.
31 * YOSHIFUJI Hideaki @USAGI : Privacy Extensions (RFC3041)
33 * Yuji SEKIYA @USAGI : Don't assign a same IPv6
34 * address on a same interface.
35 * YOSHIFUJI Hideaki @USAGI : ARCnet support
36 * YOSHIFUJI Hideaki @USAGI : convert /proc/net/if_inet6 to
38 * YOSHIFUJI Hideaki @USAGI : improved source address
39 * selection; consider scope,
43 #include <linux/errno.h>
44 #include <linux/types.h>
45 #include <linux/socket.h>
46 #include <linux/sockios.h>
47 #include <linux/net.h>
48 #include <linux/in6.h>
49 #include <linux/netdevice.h>
50 #include <linux/if_addr.h>
51 #include <linux/if_arp.h>
52 #include <linux/if_arcnet.h>
53 #include <linux/if_infiniband.h>
54 #include <linux/route.h>
55 #include <linux/inetdevice.h>
56 #include <linux/init.h>
58 #include <linux/sysctl.h>
60 #include <linux/capability.h>
61 #include <linux/delay.h>
62 #include <linux/notifier.h>
63 #include <linux/string.h>
69 #include <net/protocol.h>
70 #include <net/ndisc.h>
71 #include <net/ip6_route.h>
72 #include <net/addrconf.h>
75 #include <net/netlink.h>
76 #include <linux/if_tunnel.h>
77 #include <linux/rtnetlink.h>
79 #ifdef CONFIG_IPV6_PRIVACY
80 #include <linux/random.h>
83 #include <asm/uaccess.h>
85 #include <linux/proc_fs.h>
86 #include <linux/seq_file.h>
88 /* Set to 3 to get tracing... */
92 #define ADBG(x) printk x
97 #define INFINITY_LIFE_TIME 0xFFFFFFFF
98 #define TIME_DELTA(a,b) ((unsigned long)((long)(a) - (long)(b)))
101 static void addrconf_sysctl_register(struct inet6_dev *idev, struct ipv6_devconf *p);
102 static void addrconf_sysctl_unregister(struct ipv6_devconf *p);
105 #ifdef CONFIG_IPV6_PRIVACY
106 static int __ipv6_regen_rndid(struct inet6_dev *idev);
107 static int __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr);
108 static void ipv6_regen_rndid(unsigned long data);
110 static int desync_factor = MAX_DESYNC_FACTOR * HZ;
113 static int ipv6_count_addresses(struct inet6_dev *idev);
116 * Configured unicast address hash table
118 static struct inet6_ifaddr *inet6_addr_lst[IN6_ADDR_HSIZE];
119 static DEFINE_RWLOCK(addrconf_hash_lock);
121 static void addrconf_verify(unsigned long);
123 static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0);
124 static DEFINE_SPINLOCK(addrconf_verify_lock);
126 static void addrconf_join_anycast(struct inet6_ifaddr *ifp);
127 static void addrconf_leave_anycast(struct inet6_ifaddr *ifp);
129 static int addrconf_ifdown(struct net_device *dev, int how);
131 static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags);
132 static void addrconf_dad_timer(unsigned long data);
133 static void addrconf_dad_completed(struct inet6_ifaddr *ifp);
134 static void addrconf_dad_run(struct inet6_dev *idev);
135 static void addrconf_rs_timer(unsigned long data);
136 static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
137 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
139 static void inet6_prefix_notify(int event, struct inet6_dev *idev,
140 struct prefix_info *pinfo);
141 static int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *dev);
143 static ATOMIC_NOTIFIER_HEAD(inet6addr_chain);
145 struct ipv6_devconf ipv6_devconf __read_mostly = {
147 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
148 .mtu6 = IPV6_MIN_MTU,
150 .accept_redirects = 1,
152 .force_mld_version = 0,
154 .rtr_solicits = MAX_RTR_SOLICITATIONS,
155 .rtr_solicit_interval = RTR_SOLICITATION_INTERVAL,
156 .rtr_solicit_delay = MAX_RTR_SOLICITATION_DELAY,
157 #ifdef CONFIG_IPV6_PRIVACY
159 .temp_valid_lft = TEMP_VALID_LIFETIME,
160 .temp_prefered_lft = TEMP_PREFERRED_LIFETIME,
161 .regen_max_retry = REGEN_MAX_RETRY,
162 .max_desync_factor = MAX_DESYNC_FACTOR,
164 .max_addresses = IPV6_MAX_ADDRESSES,
165 .accept_ra_defrtr = 1,
166 .accept_ra_pinfo = 1,
167 #ifdef CONFIG_IPV6_ROUTER_PREF
168 .accept_ra_rtr_pref = 1,
169 .rtr_probe_interval = 60 * HZ,
170 #ifdef CONFIG_IPV6_ROUTE_INFO
171 .accept_ra_rt_info_max_plen = 0,
177 static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = {
179 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
180 .mtu6 = IPV6_MIN_MTU,
182 .accept_redirects = 1,
185 .rtr_solicits = MAX_RTR_SOLICITATIONS,
186 .rtr_solicit_interval = RTR_SOLICITATION_INTERVAL,
187 .rtr_solicit_delay = MAX_RTR_SOLICITATION_DELAY,
188 #ifdef CONFIG_IPV6_PRIVACY
190 .temp_valid_lft = TEMP_VALID_LIFETIME,
191 .temp_prefered_lft = TEMP_PREFERRED_LIFETIME,
192 .regen_max_retry = REGEN_MAX_RETRY,
193 .max_desync_factor = MAX_DESYNC_FACTOR,
195 .max_addresses = IPV6_MAX_ADDRESSES,
196 .accept_ra_defrtr = 1,
197 .accept_ra_pinfo = 1,
198 #ifdef CONFIG_IPV6_ROUTER_PREF
199 .accept_ra_rtr_pref = 1,
200 .rtr_probe_interval = 60 * HZ,
201 #ifdef CONFIG_IPV6_ROUTE_INFO
202 .accept_ra_rt_info_max_plen = 0,
208 /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
210 const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
212 const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
214 static void addrconf_del_timer(struct inet6_ifaddr *ifp)
216 if (del_timer(&ifp->timer))
220 enum addrconf_timer_t
227 static void addrconf_mod_timer(struct inet6_ifaddr *ifp,
228 enum addrconf_timer_t what,
231 if (!del_timer(&ifp->timer))
236 ifp->timer.function = addrconf_dad_timer;
239 ifp->timer.function = addrconf_rs_timer;
243 ifp->timer.expires = jiffies + when;
244 add_timer(&ifp->timer);
247 /* Nobody refers to this device, we may destroy it. */
249 static void in6_dev_finish_destroy_rcu(struct rcu_head *head)
251 struct inet6_dev *idev = container_of(head, struct inet6_dev, rcu);
255 void in6_dev_finish_destroy(struct inet6_dev *idev)
257 struct net_device *dev = idev->dev;
258 BUG_TRAP(idev->addr_list==NULL);
259 BUG_TRAP(idev->mc_list==NULL);
260 #ifdef NET_REFCNT_DEBUG
261 printk(KERN_DEBUG "in6_dev_finish_destroy: %s\n", dev ? dev->name : "NIL");
265 printk("Freeing alive inet6 device %p\n", idev);
268 snmp6_free_dev(idev);
269 call_rcu(&idev->rcu, in6_dev_finish_destroy_rcu);
272 static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
274 struct inet6_dev *ndev;
275 struct in6_addr maddr;
279 if (dev->mtu < IPV6_MIN_MTU)
282 ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
287 rwlock_init(&ndev->lock);
289 memcpy(&ndev->cnf, &ipv6_devconf_dflt, sizeof(ndev->cnf));
290 ndev->cnf.mtu6 = dev->mtu;
291 ndev->cnf.sysctl = NULL;
292 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
293 if (ndev->nd_parms == NULL) {
297 /* We refer to the device */
300 if (snmp6_alloc_dev(ndev) < 0) {
302 "%s(): cannot allocate memory for statistics; dev=%s.\n",
303 __FUNCTION__, dev->name));
304 neigh_parms_release(&nd_tbl, ndev->nd_parms);
306 in6_dev_finish_destroy(ndev);
310 if (snmp6_register_dev(ndev) < 0) {
312 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
313 __FUNCTION__, dev->name));
314 neigh_parms_release(&nd_tbl, ndev->nd_parms);
316 in6_dev_finish_destroy(ndev);
320 /* One reference from device. We must do this before
321 * we invoke __ipv6_regen_rndid().
325 #ifdef CONFIG_IPV6_PRIVACY
326 init_timer(&ndev->regen_timer);
327 ndev->regen_timer.function = ipv6_regen_rndid;
328 ndev->regen_timer.data = (unsigned long) ndev;
329 if ((dev->flags&IFF_LOOPBACK) ||
330 dev->type == ARPHRD_TUNNEL ||
331 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
332 dev->type == ARPHRD_SIT ||
334 dev->type == ARPHRD_NONE) {
336 "%s: Disabled Privacy Extensions\n",
338 ndev->cnf.use_tempaddr = -1;
341 ipv6_regen_rndid((unsigned long) ndev);
345 if (netif_running(dev) && netif_carrier_ok(dev))
346 ndev->if_flags |= IF_READY;
348 ipv6_mc_init_dev(ndev);
349 ndev->tstamp = jiffies;
351 neigh_sysctl_register(dev, ndev->nd_parms, NET_IPV6,
352 NET_IPV6_NEIGH, "ipv6",
353 &ndisc_ifinfo_sysctl_change,
355 addrconf_sysctl_register(ndev, &ndev->cnf);
357 /* protected by rtnl_lock */
358 rcu_assign_pointer(dev->ip6_ptr, ndev);
360 /* Join all-node multicast group */
361 ipv6_addr_all_nodes(&maddr);
362 ipv6_dev_mc_inc(dev, &maddr);
367 static struct inet6_dev * ipv6_find_idev(struct net_device *dev)
369 struct inet6_dev *idev;
373 if ((idev = __in6_dev_get(dev)) == NULL) {
374 if ((idev = ipv6_add_dev(dev)) == NULL)
378 if (dev->flags&IFF_UP)
384 static void dev_forward_change(struct inet6_dev *idev)
386 struct net_device *dev;
387 struct inet6_ifaddr *ifa;
388 struct in6_addr addr;
393 if (dev && (dev->flags & IFF_MULTICAST)) {
394 ipv6_addr_all_routers(&addr);
396 if (idev->cnf.forwarding)
397 ipv6_dev_mc_inc(dev, &addr);
399 ipv6_dev_mc_dec(dev, &addr);
401 for (ifa=idev->addr_list; ifa; ifa=ifa->if_next) {
402 if (ifa->flags&IFA_F_TENTATIVE)
404 if (idev->cnf.forwarding)
405 addrconf_join_anycast(ifa);
407 addrconf_leave_anycast(ifa);
412 static void addrconf_forward_change(void)
414 struct net_device *dev;
415 struct inet6_dev *idev;
417 read_lock(&dev_base_lock);
418 for (dev=dev_base; dev; dev=dev->next) {
420 idev = __in6_dev_get(dev);
422 int changed = (!idev->cnf.forwarding) ^ (!ipv6_devconf.forwarding);
423 idev->cnf.forwarding = ipv6_devconf.forwarding;
425 dev_forward_change(idev);
429 read_unlock(&dev_base_lock);
433 /* Nobody refers to this ifaddr, destroy it */
435 void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
437 BUG_TRAP(ifp->if_next==NULL);
438 BUG_TRAP(ifp->lst_next==NULL);
439 #ifdef NET_REFCNT_DEBUG
440 printk(KERN_DEBUG "inet6_ifa_finish_destroy\n");
443 in6_dev_put(ifp->idev);
445 if (del_timer(&ifp->timer))
446 printk("Timer is still running, when freeing ifa=%p\n", ifp);
449 printk("Freeing alive inet6 address %p\n", ifp);
452 dst_release(&ifp->rt->u.dst);
458 ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp)
460 struct inet6_ifaddr *ifa, **ifap;
461 int ifp_scope = ipv6_addr_src_scope(&ifp->addr);
464 * Each device address list is sorted in order of scope -
465 * global before linklocal.
467 for (ifap = &idev->addr_list; (ifa = *ifap) != NULL;
468 ifap = &ifa->if_next) {
469 if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr))
473 ifp->if_next = *ifap;
477 /* On success it returns ifp with increased reference count */
479 static struct inet6_ifaddr *
480 ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
481 int scope, u32 flags)
483 struct inet6_ifaddr *ifa = NULL;
490 err = -ENODEV; /*XXX*/
494 write_lock(&addrconf_hash_lock);
496 /* Ignore adding duplicate addresses on an interface */
497 if (ipv6_chk_same_addr(addr, idev->dev)) {
498 ADBG(("ipv6_add_addr: already assigned\n"));
503 ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC);
506 ADBG(("ipv6_add_addr: malloc failed\n"));
511 rt = addrconf_dst_alloc(idev, addr, 0);
517 ipv6_addr_copy(&ifa->addr, addr);
519 spin_lock_init(&ifa->lock);
520 init_timer(&ifa->timer);
521 ifa->timer.data = (unsigned long) ifa;
523 ifa->prefix_len = pfxlen;
524 ifa->flags = flags | IFA_F_TENTATIVE;
525 ifa->cstamp = ifa->tstamp = jiffies;
534 /* Add to big hash table */
535 hash = ipv6_addr_hash(addr);
537 ifa->lst_next = inet6_addr_lst[hash];
538 inet6_addr_lst[hash] = ifa;
540 write_unlock(&addrconf_hash_lock);
542 write_lock(&idev->lock);
543 /* Add to inet6_dev unicast addr list. */
544 ipv6_link_dev_addr(idev, ifa);
546 #ifdef CONFIG_IPV6_PRIVACY
547 if (ifa->flags&IFA_F_TEMPORARY) {
548 ifa->tmp_next = idev->tempaddr_list;
549 idev->tempaddr_list = ifa;
555 write_unlock(&idev->lock);
557 rcu_read_unlock_bh();
559 if (likely(err == 0))
560 atomic_notifier_call_chain(&inet6addr_chain, NETDEV_UP, ifa);
568 write_unlock(&addrconf_hash_lock);
572 /* This function wants to get referenced ifp and releases it before return */
574 static void ipv6_del_addr(struct inet6_ifaddr *ifp)
576 struct inet6_ifaddr *ifa, **ifap;
577 struct inet6_dev *idev = ifp->idev;
579 int deleted = 0, onlink = 0;
580 unsigned long expires = jiffies;
582 hash = ipv6_addr_hash(&ifp->addr);
586 write_lock_bh(&addrconf_hash_lock);
587 for (ifap = &inet6_addr_lst[hash]; (ifa=*ifap) != NULL;
588 ifap = &ifa->lst_next) {
590 *ifap = ifa->lst_next;
592 ifa->lst_next = NULL;
596 write_unlock_bh(&addrconf_hash_lock);
598 write_lock_bh(&idev->lock);
599 #ifdef CONFIG_IPV6_PRIVACY
600 if (ifp->flags&IFA_F_TEMPORARY) {
601 for (ifap = &idev->tempaddr_list; (ifa=*ifap) != NULL;
602 ifap = &ifa->tmp_next) {
604 *ifap = ifa->tmp_next;
606 in6_ifa_put(ifp->ifpub);
610 ifa->tmp_next = NULL;
617 for (ifap = &idev->addr_list; (ifa=*ifap) != NULL;) {
619 *ifap = ifa->if_next;
622 if (!(ifp->flags & IFA_F_PERMANENT) || onlink > 0)
626 } else if (ifp->flags & IFA_F_PERMANENT) {
627 if (ipv6_prefix_equal(&ifa->addr, &ifp->addr,
629 if (ifa->flags & IFA_F_PERMANENT) {
634 unsigned long lifetime;
639 spin_lock(&ifa->lock);
640 lifetime = min_t(unsigned long,
641 ifa->valid_lft, 0x7fffffffUL/HZ);
642 if (time_before(expires,
643 ifa->tstamp + lifetime * HZ))
644 expires = ifa->tstamp + lifetime * HZ;
645 spin_unlock(&ifa->lock);
649 ifap = &ifa->if_next;
651 write_unlock_bh(&idev->lock);
653 ipv6_ifa_notify(RTM_DELADDR, ifp);
655 atomic_notifier_call_chain(&inet6addr_chain, NETDEV_DOWN, ifp);
657 addrconf_del_timer(ifp);
660 * Purge or update corresponding prefix
662 * 1) we don't purge prefix here if address was not permanent.
663 * prefix is managed by its own lifetime.
664 * 2) if there're no addresses, delete prefix.
665 * 3) if there're still other permanent address(es),
666 * corresponding prefix is still permanent.
667 * 4) otherwise, update prefix lifetime to the
668 * longest valid lifetime among the corresponding
669 * addresses on the device.
670 * Note: subsequent RA will update lifetime.
674 if ((ifp->flags & IFA_F_PERMANENT) && onlink < 1) {
675 struct in6_addr prefix;
678 ipv6_addr_prefix(&prefix, &ifp->addr, ifp->prefix_len);
679 rt = rt6_lookup(&prefix, NULL, ifp->idev->dev->ifindex, 1);
681 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
685 } else if (!(rt->rt6i_flags & RTF_EXPIRES)) {
686 rt->rt6i_expires = expires;
687 rt->rt6i_flags |= RTF_EXPIRES;
690 dst_release(&rt->u.dst);
696 #ifdef CONFIG_IPV6_PRIVACY
697 static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, struct inet6_ifaddr *ift)
699 struct inet6_dev *idev = ifp->idev;
700 struct in6_addr addr, *tmpaddr;
701 unsigned long tmp_prefered_lft, tmp_valid_lft, tmp_cstamp, tmp_tstamp;
706 write_lock(&idev->lock);
708 spin_lock_bh(&ift->lock);
709 memcpy(&addr.s6_addr[8], &ift->addr.s6_addr[8], 8);
710 spin_unlock_bh(&ift->lock);
717 if (idev->cnf.use_tempaddr <= 0) {
718 write_unlock(&idev->lock);
720 "ipv6_create_tempaddr(): use_tempaddr is disabled.\n");
725 spin_lock_bh(&ifp->lock);
726 if (ifp->regen_count++ >= idev->cnf.regen_max_retry) {
727 idev->cnf.use_tempaddr = -1; /*XXX*/
728 spin_unlock_bh(&ifp->lock);
729 write_unlock(&idev->lock);
731 "ipv6_create_tempaddr(): regeneration time exceeded. disabled temporary address support.\n");
737 memcpy(addr.s6_addr, ifp->addr.s6_addr, 8);
738 if (__ipv6_try_regen_rndid(idev, tmpaddr) < 0) {
739 spin_unlock_bh(&ifp->lock);
740 write_unlock(&idev->lock);
742 "ipv6_create_tempaddr(): regeneration of randomized interface id failed.\n");
748 memcpy(&addr.s6_addr[8], idev->rndid, 8);
749 tmp_valid_lft = min_t(__u32,
751 idev->cnf.temp_valid_lft);
752 tmp_prefered_lft = min_t(__u32,
754 idev->cnf.temp_prefered_lft - desync_factor / HZ);
755 tmp_plen = ifp->prefix_len;
756 max_addresses = idev->cnf.max_addresses;
757 tmp_cstamp = ifp->cstamp;
758 tmp_tstamp = ifp->tstamp;
759 spin_unlock_bh(&ifp->lock);
761 write_unlock(&idev->lock);
762 ift = !max_addresses ||
763 ipv6_count_addresses(idev) < max_addresses ?
764 ipv6_add_addr(idev, &addr, tmp_plen,
765 ipv6_addr_type(&addr)&IPV6_ADDR_SCOPE_MASK, IFA_F_TEMPORARY) : NULL;
766 if (!ift || IS_ERR(ift)) {
770 "ipv6_create_tempaddr(): retry temporary address regeneration.\n");
772 write_lock(&idev->lock);
776 spin_lock_bh(&ift->lock);
778 ift->valid_lft = tmp_valid_lft;
779 ift->prefered_lft = tmp_prefered_lft;
780 ift->cstamp = tmp_cstamp;
781 ift->tstamp = tmp_tstamp;
782 spin_unlock_bh(&ift->lock);
784 addrconf_dad_start(ift, 0);
793 * Choose an appropriate source address (RFC3484)
795 struct ipv6_saddr_score {
803 #define IPV6_SADDR_SCORE_LOCAL 0x0001
804 #define IPV6_SADDR_SCORE_PREFERRED 0x0004
805 #define IPV6_SADDR_SCORE_HOA 0x0008
806 #define IPV6_SADDR_SCORE_OIF 0x0010
807 #define IPV6_SADDR_SCORE_LABEL 0x0020
808 #define IPV6_SADDR_SCORE_PRIVACY 0x0040
810 static inline int ipv6_saddr_preferred(int type)
812 if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4|
813 IPV6_ADDR_LOOPBACK|IPV6_ADDR_RESERVED))
818 /* static matching label */
819 static inline int ipv6_saddr_label(const struct in6_addr *addr, int type)
822 * prefix (longest match) label
823 * -----------------------------
832 if (type & IPV6_ADDR_LOOPBACK)
834 else if (type & IPV6_ADDR_COMPATv4)
836 else if (type & IPV6_ADDR_MAPPED)
838 else if (addr->s6_addr32[0] == htonl(0x20010000))
840 else if (addr->s6_addr16[0] == htons(0x2002))
842 else if ((addr->s6_addr[0] & 0xfe) == 0xfc)
847 int ipv6_dev_get_saddr(struct net_device *daddr_dev,
848 struct in6_addr *daddr, struct in6_addr *saddr)
850 struct ipv6_saddr_score hiscore;
851 struct inet6_ifaddr *ifa_result = NULL;
852 int daddr_type = __ipv6_addr_type(daddr);
853 int daddr_scope = __ipv6_addr_src_scope(daddr_type);
854 u32 daddr_label = ipv6_saddr_label(daddr, daddr_type);
855 struct net_device *dev;
857 memset(&hiscore, 0, sizeof(hiscore));
859 read_lock(&dev_base_lock);
862 for (dev = dev_base; dev; dev=dev->next) {
863 struct inet6_dev *idev;
864 struct inet6_ifaddr *ifa;
866 /* Rule 0: Candidate Source Address (section 4)
867 * - multicast and link-local destination address,
868 * the set of candidate source address MUST only
869 * include addresses assigned to interfaces
870 * belonging to the same link as the outgoing
872 * (- For site-local destination addresses, the
873 * set of candidate source addresses MUST only
874 * include addresses assigned to interfaces
875 * belonging to the same site as the outgoing
878 if ((daddr_type & IPV6_ADDR_MULTICAST ||
879 daddr_scope <= IPV6_ADDR_SCOPE_LINKLOCAL) &&
880 daddr_dev && dev != daddr_dev)
883 idev = __in6_dev_get(dev);
887 read_lock_bh(&idev->lock);
888 for (ifa = idev->addr_list; ifa; ifa = ifa->if_next) {
889 struct ipv6_saddr_score score;
891 score.addr_type = __ipv6_addr_type(&ifa->addr);
894 * - Tentative Address (RFC2462 section 5.4)
895 * - A tentative address is not considered
896 * "assigned to an interface" in the traditional
898 * - Candidate Source Address (section 4)
899 * - In any case, anycast addresses, multicast
900 * addresses, and the unspecified address MUST
901 * NOT be included in a candidate set.
903 if (ifa->flags & IFA_F_TENTATIVE)
905 if (unlikely(score.addr_type == IPV6_ADDR_ANY ||
906 score.addr_type & IPV6_ADDR_MULTICAST)) {
907 LIMIT_NETDEBUG(KERN_DEBUG
908 "ADDRCONF: unspecified / multicast address"
909 "assigned as unicast address on %s",
919 if (ifa_result == NULL) {
920 /* record it if the first available entry */
924 /* Rule 1: Prefer same address */
925 if (hiscore.rule < 1) {
926 if (ipv6_addr_equal(&ifa_result->addr, daddr))
927 hiscore.attrs |= IPV6_SADDR_SCORE_LOCAL;
930 if (ipv6_addr_equal(&ifa->addr, daddr)) {
931 score.attrs |= IPV6_SADDR_SCORE_LOCAL;
932 if (!(hiscore.attrs & IPV6_SADDR_SCORE_LOCAL)) {
937 if (hiscore.attrs & IPV6_SADDR_SCORE_LOCAL)
941 /* Rule 2: Prefer appropriate scope */
942 if (hiscore.rule < 2) {
943 hiscore.scope = __ipv6_addr_src_scope(hiscore.addr_type);
946 score.scope = __ipv6_addr_src_scope(score.addr_type);
947 if (hiscore.scope < score.scope) {
948 if (hiscore.scope < daddr_scope) {
953 } else if (score.scope < hiscore.scope) {
954 if (score.scope < daddr_scope)
955 break; /* addresses sorted by scope */
962 /* Rule 3: Avoid deprecated address */
963 if (hiscore.rule < 3) {
964 if (ipv6_saddr_preferred(hiscore.addr_type) ||
965 !(ifa_result->flags & IFA_F_DEPRECATED))
966 hiscore.attrs |= IPV6_SADDR_SCORE_PREFERRED;
969 if (ipv6_saddr_preferred(score.addr_type) ||
970 !(ifa->flags & IFA_F_DEPRECATED)) {
971 score.attrs |= IPV6_SADDR_SCORE_PREFERRED;
972 if (!(hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED)) {
977 if (hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED)
981 /* Rule 4: Prefer home address */
982 #ifdef CONFIG_IPV6_MIP6
983 if (hiscore.rule < 4) {
984 if (ifa_result->flags & IFA_F_HOMEADDRESS)
985 hiscore.attrs |= IPV6_SADDR_SCORE_HOA;
988 if (ifa->flags & IFA_F_HOMEADDRESS) {
989 score.attrs |= IPV6_SADDR_SCORE_HOA;
990 if (!(ifa_result->flags & IFA_F_HOMEADDRESS)) {
995 if (hiscore.attrs & IPV6_SADDR_SCORE_HOA)
999 if (hiscore.rule < 4)
1003 /* Rule 5: Prefer outgoing interface */
1004 if (hiscore.rule < 5) {
1005 if (daddr_dev == NULL ||
1006 daddr_dev == ifa_result->idev->dev)
1007 hiscore.attrs |= IPV6_SADDR_SCORE_OIF;
1010 if (daddr_dev == NULL ||
1011 daddr_dev == ifa->idev->dev) {
1012 score.attrs |= IPV6_SADDR_SCORE_OIF;
1013 if (!(hiscore.attrs & IPV6_SADDR_SCORE_OIF)) {
1018 if (hiscore.attrs & IPV6_SADDR_SCORE_OIF)
1022 /* Rule 6: Prefer matching label */
1023 if (hiscore.rule < 6) {
1024 if (ipv6_saddr_label(&ifa_result->addr, hiscore.addr_type) == daddr_label)
1025 hiscore.attrs |= IPV6_SADDR_SCORE_LABEL;
1028 if (ipv6_saddr_label(&ifa->addr, score.addr_type) == daddr_label) {
1029 score.attrs |= IPV6_SADDR_SCORE_LABEL;
1030 if (!(hiscore.attrs & IPV6_SADDR_SCORE_LABEL)) {
1035 if (hiscore.attrs & IPV6_SADDR_SCORE_LABEL)
1039 #ifdef CONFIG_IPV6_PRIVACY
1040 /* Rule 7: Prefer public address
1041 * Note: prefer temprary address if use_tempaddr >= 2
1043 if (hiscore.rule < 7) {
1044 if ((!(ifa_result->flags & IFA_F_TEMPORARY)) ^
1045 (ifa_result->idev->cnf.use_tempaddr >= 2))
1046 hiscore.attrs |= IPV6_SADDR_SCORE_PRIVACY;
1049 if ((!(ifa->flags & IFA_F_TEMPORARY)) ^
1050 (ifa->idev->cnf.use_tempaddr >= 2)) {
1051 score.attrs |= IPV6_SADDR_SCORE_PRIVACY;
1052 if (!(hiscore.attrs & IPV6_SADDR_SCORE_PRIVACY)) {
1057 if (hiscore.attrs & IPV6_SADDR_SCORE_PRIVACY)
1061 if (hiscore.rule < 7)
1064 /* Rule 8: Use longest matching prefix */
1065 if (hiscore.rule < 8) {
1066 hiscore.matchlen = ipv6_addr_diff(&ifa_result->addr, daddr);
1069 score.matchlen = ipv6_addr_diff(&ifa->addr, daddr);
1070 if (score.matchlen > hiscore.matchlen) {
1075 else if (score.matchlen < hiscore.matchlen)
1079 /* Final Rule: choose first available one */
1083 in6_ifa_put(ifa_result);
1088 read_unlock_bh(&idev->lock);
1091 read_unlock(&dev_base_lock);
1094 return -EADDRNOTAVAIL;
1096 ipv6_addr_copy(saddr, &ifa_result->addr);
1097 in6_ifa_put(ifa_result);
1102 int ipv6_get_saddr(struct dst_entry *dst,
1103 struct in6_addr *daddr, struct in6_addr *saddr)
1105 return ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL, daddr, saddr);
1109 int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr)
1111 struct inet6_dev *idev;
1112 int err = -EADDRNOTAVAIL;
1115 if ((idev = __in6_dev_get(dev)) != NULL) {
1116 struct inet6_ifaddr *ifp;
1118 read_lock_bh(&idev->lock);
1119 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
1120 if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) {
1121 ipv6_addr_copy(addr, &ifp->addr);
1126 read_unlock_bh(&idev->lock);
1132 static int ipv6_count_addresses(struct inet6_dev *idev)
1135 struct inet6_ifaddr *ifp;
1137 read_lock_bh(&idev->lock);
1138 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next)
1140 read_unlock_bh(&idev->lock);
1144 int ipv6_chk_addr(struct in6_addr *addr, struct net_device *dev, int strict)
1146 struct inet6_ifaddr * ifp;
1147 u8 hash = ipv6_addr_hash(addr);
1149 read_lock_bh(&addrconf_hash_lock);
1150 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1151 if (ipv6_addr_equal(&ifp->addr, addr) &&
1152 !(ifp->flags&IFA_F_TENTATIVE)) {
1153 if (dev == NULL || ifp->idev->dev == dev ||
1154 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))
1158 read_unlock_bh(&addrconf_hash_lock);
1163 int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *dev)
1165 struct inet6_ifaddr * ifp;
1166 u8 hash = ipv6_addr_hash(addr);
1168 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1169 if (ipv6_addr_equal(&ifp->addr, addr)) {
1170 if (dev == NULL || ifp->idev->dev == dev)
1177 struct inet6_ifaddr * ipv6_get_ifaddr(struct in6_addr *addr, struct net_device *dev, int strict)
1179 struct inet6_ifaddr * ifp;
1180 u8 hash = ipv6_addr_hash(addr);
1182 read_lock_bh(&addrconf_hash_lock);
1183 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1184 if (ipv6_addr_equal(&ifp->addr, addr)) {
1185 if (dev == NULL || ifp->idev->dev == dev ||
1186 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) {
1192 read_unlock_bh(&addrconf_hash_lock);
1197 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
1199 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
1200 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
1201 __be32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
1202 __be32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
1203 int sk_ipv6only = ipv6_only_sock(sk);
1204 int sk2_ipv6only = inet_v6_ipv6only(sk2);
1205 int addr_type = ipv6_addr_type(sk_rcv_saddr6);
1206 int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
1208 if (!sk2_rcv_saddr && !sk_ipv6only)
1211 if (addr_type2 == IPV6_ADDR_ANY &&
1212 !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
1215 if (addr_type == IPV6_ADDR_ANY &&
1216 !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
1219 if (sk2_rcv_saddr6 &&
1220 ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
1223 if (addr_type == IPV6_ADDR_MAPPED &&
1225 (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
1231 /* Gets referenced address, destroys ifaddr */
1233 static void addrconf_dad_stop(struct inet6_ifaddr *ifp)
1235 if (ifp->flags&IFA_F_PERMANENT) {
1236 spin_lock_bh(&ifp->lock);
1237 addrconf_del_timer(ifp);
1238 ifp->flags |= IFA_F_TENTATIVE;
1239 spin_unlock_bh(&ifp->lock);
1241 #ifdef CONFIG_IPV6_PRIVACY
1242 } else if (ifp->flags&IFA_F_TEMPORARY) {
1243 struct inet6_ifaddr *ifpub;
1244 spin_lock_bh(&ifp->lock);
1247 in6_ifa_hold(ifpub);
1248 spin_unlock_bh(&ifp->lock);
1249 ipv6_create_tempaddr(ifpub, ifp);
1252 spin_unlock_bh(&ifp->lock);
1260 void addrconf_dad_failure(struct inet6_ifaddr *ifp)
1262 if (net_ratelimit())
1263 printk(KERN_INFO "%s: duplicate address detected!\n", ifp->idev->dev->name);
1264 addrconf_dad_stop(ifp);
1267 /* Join to solicited addr multicast group. */
1269 void addrconf_join_solict(struct net_device *dev, struct in6_addr *addr)
1271 struct in6_addr maddr;
1273 if (dev->flags&(IFF_LOOPBACK|IFF_NOARP))
1276 addrconf_addr_solict_mult(addr, &maddr);
1277 ipv6_dev_mc_inc(dev, &maddr);
1280 void addrconf_leave_solict(struct inet6_dev *idev, struct in6_addr *addr)
1282 struct in6_addr maddr;
1284 if (idev->dev->flags&(IFF_LOOPBACK|IFF_NOARP))
1287 addrconf_addr_solict_mult(addr, &maddr);
1288 __ipv6_dev_mc_dec(idev, &maddr);
1291 static void addrconf_join_anycast(struct inet6_ifaddr *ifp)
1293 struct in6_addr addr;
1294 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len);
1295 if (ipv6_addr_any(&addr))
1297 ipv6_dev_ac_inc(ifp->idev->dev, &addr);
1300 static void addrconf_leave_anycast(struct inet6_ifaddr *ifp)
1302 struct in6_addr addr;
1303 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len);
1304 if (ipv6_addr_any(&addr))
1306 __ipv6_dev_ac_dec(ifp->idev, &addr);
1309 static int addrconf_ifid_eui48(u8 *eui, struct net_device *dev)
1311 if (dev->addr_len != ETH_ALEN)
1313 memcpy(eui, dev->dev_addr, 3);
1314 memcpy(eui + 5, dev->dev_addr + 3, 3);
1317 * The zSeries OSA network cards can be shared among various
1318 * OS instances, but the OSA cards have only one MAC address.
1319 * This leads to duplicate address conflicts in conjunction
1320 * with IPv6 if more than one instance uses the same card.
1322 * The driver for these cards can deliver a unique 16-bit
1323 * identifier for each instance sharing the same card. It is
1324 * placed instead of 0xFFFE in the interface identifier. The
1325 * "u" bit of the interface identifier is not inverted in this
1326 * case. Hence the resulting interface identifier has local
1327 * scope according to RFC2373.
1330 eui[3] = (dev->dev_id >> 8) & 0xFF;
1331 eui[4] = dev->dev_id & 0xFF;
1340 static int addrconf_ifid_arcnet(u8 *eui, struct net_device *dev)
1342 /* XXX: inherit EUI-64 from other interface -- yoshfuji */
1343 if (dev->addr_len != ARCNET_ALEN)
1346 eui[7] = *(u8*)dev->dev_addr;
1350 static int addrconf_ifid_infiniband(u8 *eui, struct net_device *dev)
1352 if (dev->addr_len != INFINIBAND_ALEN)
1354 memcpy(eui, dev->dev_addr + 12, 8);
1359 static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
1361 switch (dev->type) {
1364 case ARPHRD_IEEE802_TR:
1365 return addrconf_ifid_eui48(eui, dev);
1367 return addrconf_ifid_arcnet(eui, dev);
1368 case ARPHRD_INFINIBAND:
1369 return addrconf_ifid_infiniband(eui, dev);
1374 static int ipv6_inherit_eui64(u8 *eui, struct inet6_dev *idev)
1377 struct inet6_ifaddr *ifp;
1379 read_lock_bh(&idev->lock);
1380 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
1381 if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) {
1382 memcpy(eui, ifp->addr.s6_addr+8, 8);
1387 read_unlock_bh(&idev->lock);
1391 #ifdef CONFIG_IPV6_PRIVACY
1392 /* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */
1393 static int __ipv6_regen_rndid(struct inet6_dev *idev)
1396 get_random_bytes(idev->rndid, sizeof(idev->rndid));
1397 idev->rndid[0] &= ~0x02;
1400 * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>:
1401 * check if generated address is not inappropriate
1403 * - Reserved subnet anycast (RFC 2526)
1404 * 11111101 11....11 1xxxxxxx
1405 * - ISATAP (draft-ietf-ngtrans-isatap-13.txt) 5.1
1406 * 00-00-5E-FE-xx-xx-xx-xx
1408 * - XXX: already assigned to an address on the device
1410 if (idev->rndid[0] == 0xfd &&
1411 (idev->rndid[1]&idev->rndid[2]&idev->rndid[3]&idev->rndid[4]&idev->rndid[5]&idev->rndid[6]) == 0xff &&
1412 (idev->rndid[7]&0x80))
1414 if ((idev->rndid[0]|idev->rndid[1]) == 0) {
1415 if (idev->rndid[2] == 0x5e && idev->rndid[3] == 0xfe)
1417 if ((idev->rndid[2]|idev->rndid[3]|idev->rndid[4]|idev->rndid[5]|idev->rndid[6]|idev->rndid[7]) == 0x00)
1424 static void ipv6_regen_rndid(unsigned long data)
1426 struct inet6_dev *idev = (struct inet6_dev *) data;
1427 unsigned long expires;
1430 write_lock_bh(&idev->lock);
1435 if (__ipv6_regen_rndid(idev) < 0)
1439 idev->cnf.temp_prefered_lft * HZ -
1440 idev->cnf.regen_max_retry * idev->cnf.dad_transmits * idev->nd_parms->retrans_time - desync_factor;
1441 if (time_before(expires, jiffies)) {
1443 "ipv6_regen_rndid(): too short regeneration interval; timer disabled for %s.\n",
1448 if (!mod_timer(&idev->regen_timer, expires))
1452 write_unlock_bh(&idev->lock);
1453 rcu_read_unlock_bh();
1457 static int __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr) {
1460 if (tmpaddr && memcmp(idev->rndid, &tmpaddr->s6_addr[8], 8) == 0)
1461 ret = __ipv6_regen_rndid(idev);
1471 addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
1472 unsigned long expires, u32 flags)
1474 struct fib6_config cfg = {
1475 .fc_table = RT6_TABLE_PREFIX,
1476 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1477 .fc_ifindex = dev->ifindex,
1478 .fc_expires = expires,
1480 .fc_flags = RTF_UP | flags,
1483 ipv6_addr_copy(&cfg.fc_dst, pfx);
1485 /* Prevent useless cloning on PtP SIT.
1486 This thing is done here expecting that the whole
1487 class of non-broadcast devices need not cloning.
1489 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1490 if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT))
1491 cfg.fc_flags |= RTF_NONEXTHOP;
1494 ip6_route_add(&cfg);
1497 /* Create "default" multicast route to the interface */
1499 static void addrconf_add_mroute(struct net_device *dev)
1501 struct fib6_config cfg = {
1502 .fc_table = RT6_TABLE_LOCAL,
1503 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1504 .fc_ifindex = dev->ifindex,
1509 ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0);
1511 ip6_route_add(&cfg);
1514 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1515 static void sit_route_add(struct net_device *dev)
1517 struct fib6_config cfg = {
1518 .fc_table = RT6_TABLE_MAIN,
1519 .fc_metric = IP6_RT_PRIO_ADDRCONF,
1520 .fc_ifindex = dev->ifindex,
1522 .fc_flags = RTF_UP | RTF_NONEXTHOP,
1525 /* prefix length - 96 bits "::d.d.d.d" */
1526 ip6_route_add(&cfg);
1530 static void addrconf_add_lroute(struct net_device *dev)
1532 struct in6_addr addr;
1534 ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
1535 addrconf_prefix_route(&addr, 64, dev, 0, 0);
1538 static struct inet6_dev *addrconf_add_dev(struct net_device *dev)
1540 struct inet6_dev *idev;
1544 if ((idev = ipv6_find_idev(dev)) == NULL)
1547 /* Add default multicast route */
1548 addrconf_add_mroute(dev);
1550 /* Add link local route */
1551 addrconf_add_lroute(dev);
1555 void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
1557 struct prefix_info *pinfo;
1561 unsigned long rt_expires;
1562 struct inet6_dev *in6_dev;
1564 pinfo = (struct prefix_info *) opt;
1566 if (len < sizeof(struct prefix_info)) {
1567 ADBG(("addrconf: prefix option too short\n"));
1572 * Validation checks ([ADDRCONF], page 19)
1575 addr_type = ipv6_addr_type(&pinfo->prefix);
1577 if (addr_type & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL))
1580 valid_lft = ntohl(pinfo->valid);
1581 prefered_lft = ntohl(pinfo->prefered);
1583 if (prefered_lft > valid_lft) {
1584 if (net_ratelimit())
1585 printk(KERN_WARNING "addrconf: prefix option has invalid lifetime\n");
1589 in6_dev = in6_dev_get(dev);
1591 if (in6_dev == NULL) {
1592 if (net_ratelimit())
1593 printk(KERN_DEBUG "addrconf: device %s not configured\n", dev->name);
1598 * Two things going on here:
1599 * 1) Add routes for on-link prefixes
1600 * 2) Configure prefixes with the auto flag set
1603 /* Avoid arithmetic overflow. Really, we could
1604 save rt_expires in seconds, likely valid_lft,
1605 but it would require division in fib gc, that it
1608 if (valid_lft >= 0x7FFFFFFF/HZ)
1609 rt_expires = 0x7FFFFFFF - (0x7FFFFFFF % HZ);
1611 rt_expires = valid_lft * HZ;
1614 * We convert this (in jiffies) to clock_t later.
1615 * Avoid arithmetic overflow there as well.
1616 * Overflow can happen only if HZ < USER_HZ.
1618 if (HZ < USER_HZ && rt_expires > 0x7FFFFFFF / USER_HZ)
1619 rt_expires = 0x7FFFFFFF / USER_HZ;
1621 if (pinfo->onlink) {
1622 struct rt6_info *rt;
1623 rt = rt6_lookup(&pinfo->prefix, NULL, dev->ifindex, 1);
1625 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
1626 if (rt->rt6i_flags&RTF_EXPIRES) {
1627 if (valid_lft == 0) {
1631 rt->rt6i_expires = jiffies + rt_expires;
1634 } else if (valid_lft) {
1635 addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
1636 dev, jiffies_to_clock_t(rt_expires), RTF_ADDRCONF|RTF_EXPIRES|RTF_PREFIX_RT);
1639 dst_release(&rt->u.dst);
1642 /* Try to figure out our local address for this prefix */
1644 if (pinfo->autoconf && in6_dev->cnf.autoconf) {
1645 struct inet6_ifaddr * ifp;
1646 struct in6_addr addr;
1647 int create = 0, update_lft = 0;
1649 if (pinfo->prefix_len == 64) {
1650 memcpy(&addr, &pinfo->prefix, 8);
1651 if (ipv6_generate_eui64(addr.s6_addr + 8, dev) &&
1652 ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) {
1653 in6_dev_put(in6_dev);
1658 if (net_ratelimit())
1659 printk(KERN_DEBUG "IPv6 addrconf: prefix with wrong length %d\n",
1661 in6_dev_put(in6_dev);
1666 ifp = ipv6_get_ifaddr(&addr, dev, 1);
1668 if (ifp == NULL && valid_lft) {
1669 int max_addresses = in6_dev->cnf.max_addresses;
1671 /* Do not allow to create too much of autoconfigured
1672 * addresses; this would be too easy way to crash kernel.
1674 if (!max_addresses ||
1675 ipv6_count_addresses(in6_dev) < max_addresses)
1676 ifp = ipv6_add_addr(in6_dev, &addr, pinfo->prefix_len,
1677 addr_type&IPV6_ADDR_SCOPE_MASK, 0);
1679 if (!ifp || IS_ERR(ifp)) {
1680 in6_dev_put(in6_dev);
1684 update_lft = create = 1;
1685 ifp->cstamp = jiffies;
1686 addrconf_dad_start(ifp, RTF_ADDRCONF|RTF_PREFIX_RT);
1692 #ifdef CONFIG_IPV6_PRIVACY
1693 struct inet6_ifaddr *ift;
1697 /* update lifetime (RFC2462 5.5.3 e) */
1698 spin_lock(&ifp->lock);
1700 if (ifp->valid_lft > (now - ifp->tstamp) / HZ)
1701 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ;
1704 if (!update_lft && stored_lft) {
1705 if (valid_lft > MIN_VALID_LIFETIME ||
1706 valid_lft > stored_lft)
1708 else if (stored_lft <= MIN_VALID_LIFETIME) {
1709 /* valid_lft <= stored_lft is always true */
1713 valid_lft = MIN_VALID_LIFETIME;
1714 if (valid_lft < prefered_lft)
1715 prefered_lft = valid_lft;
1721 ifp->valid_lft = valid_lft;
1722 ifp->prefered_lft = prefered_lft;
1725 ifp->flags &= ~IFA_F_DEPRECATED;
1726 spin_unlock(&ifp->lock);
1728 if (!(flags&IFA_F_TENTATIVE))
1729 ipv6_ifa_notify(0, ifp);
1731 spin_unlock(&ifp->lock);
1733 #ifdef CONFIG_IPV6_PRIVACY
1734 read_lock_bh(&in6_dev->lock);
1735 /* update all temporary addresses in the list */
1736 for (ift=in6_dev->tempaddr_list; ift; ift=ift->tmp_next) {
1738 * When adjusting the lifetimes of an existing
1739 * temporary address, only lower the lifetimes.
1740 * Implementations must not increase the
1741 * lifetimes of an existing temporary address
1742 * when processing a Prefix Information Option.
1744 spin_lock(&ift->lock);
1746 if (ift->valid_lft > valid_lft &&
1747 ift->valid_lft - valid_lft > (jiffies - ift->tstamp) / HZ)
1748 ift->valid_lft = valid_lft + (jiffies - ift->tstamp) / HZ;
1749 if (ift->prefered_lft > prefered_lft &&
1750 ift->prefered_lft - prefered_lft > (jiffies - ift->tstamp) / HZ)
1751 ift->prefered_lft = prefered_lft + (jiffies - ift->tstamp) / HZ;
1752 spin_unlock(&ift->lock);
1753 if (!(flags&IFA_F_TENTATIVE))
1754 ipv6_ifa_notify(0, ift);
1757 if (create && in6_dev->cnf.use_tempaddr > 0) {
1759 * When a new public address is created as described in [ADDRCONF],
1760 * also create a new temporary address.
1762 read_unlock_bh(&in6_dev->lock);
1763 ipv6_create_tempaddr(ifp, NULL);
1765 read_unlock_bh(&in6_dev->lock);
1772 inet6_prefix_notify(RTM_NEWPREFIX, in6_dev, pinfo);
1773 in6_dev_put(in6_dev);
1777 * Set destination address.
1778 * Special case for SIT interfaces where we create a new "virtual"
1781 int addrconf_set_dstaddr(void __user *arg)
1783 struct in6_ifreq ireq;
1784 struct net_device *dev;
1790 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
1793 dev = __dev_get_by_index(ireq.ifr6_ifindex);
1799 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1800 if (dev->type == ARPHRD_SIT) {
1803 struct ip_tunnel_parm p;
1805 err = -EADDRNOTAVAIL;
1806 if (!(ipv6_addr_type(&ireq.ifr6_addr) & IPV6_ADDR_COMPATv4))
1809 memset(&p, 0, sizeof(p));
1810 p.iph.daddr = ireq.ifr6_addr.s6_addr32[3];
1814 p.iph.protocol = IPPROTO_IPV6;
1816 ifr.ifr_ifru.ifru_data = (void __user *)&p;
1818 oldfs = get_fs(); set_fs(KERNEL_DS);
1819 err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL);
1824 if ((dev = __dev_get_by_name(p.name)) == NULL)
1826 err = dev_open(dev);
1837 * Manual configuration of address on an interface
1839 static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen,
1840 __u8 ifa_flags, __u32 prefered_lft, __u32 valid_lft)
1842 struct inet6_ifaddr *ifp;
1843 struct inet6_dev *idev;
1844 struct net_device *dev;
1846 u32 flags = RTF_EXPIRES;
1850 /* check the lifetime */
1851 if (!valid_lft || prefered_lft > valid_lft)
1854 if ((dev = __dev_get_by_index(ifindex)) == NULL)
1857 if ((idev = addrconf_add_dev(dev)) == NULL)
1860 scope = ipv6_addr_scope(pfx);
1862 if (valid_lft == INFINITY_LIFE_TIME) {
1863 ifa_flags |= IFA_F_PERMANENT;
1865 } else if (valid_lft >= 0x7FFFFFFF/HZ)
1866 valid_lft = 0x7FFFFFFF/HZ;
1868 if (prefered_lft == 0)
1869 ifa_flags |= IFA_F_DEPRECATED;
1870 else if ((prefered_lft >= 0x7FFFFFFF/HZ) &&
1871 (prefered_lft != INFINITY_LIFE_TIME))
1872 prefered_lft = 0x7FFFFFFF/HZ;
1874 ifp = ipv6_add_addr(idev, pfx, plen, scope, ifa_flags);
1877 spin_lock_bh(&ifp->lock);
1878 ifp->valid_lft = valid_lft;
1879 ifp->prefered_lft = prefered_lft;
1880 ifp->tstamp = jiffies;
1881 spin_unlock_bh(&ifp->lock);
1883 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev,
1884 jiffies_to_clock_t(valid_lft * HZ), flags);
1885 addrconf_dad_start(ifp, 0);
1891 return PTR_ERR(ifp);
1894 static int inet6_addr_del(int ifindex, struct in6_addr *pfx, int plen)
1896 struct inet6_ifaddr *ifp;
1897 struct inet6_dev *idev;
1898 struct net_device *dev;
1900 if ((dev = __dev_get_by_index(ifindex)) == NULL)
1903 if ((idev = __in6_dev_get(dev)) == NULL)
1906 read_lock_bh(&idev->lock);
1907 for (ifp = idev->addr_list; ifp; ifp=ifp->if_next) {
1908 if (ifp->prefix_len == plen &&
1909 ipv6_addr_equal(pfx, &ifp->addr)) {
1911 read_unlock_bh(&idev->lock);
1915 /* If the last address is deleted administratively,
1916 disable IPv6 on this interface.
1918 if (idev->addr_list == NULL)
1919 addrconf_ifdown(idev->dev, 1);
1923 read_unlock_bh(&idev->lock);
1924 return -EADDRNOTAVAIL;
1928 int addrconf_add_ifaddr(void __user *arg)
1930 struct in6_ifreq ireq;
1933 if (!capable(CAP_NET_ADMIN))
1936 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
1940 err = inet6_addr_add(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen,
1941 IFA_F_PERMANENT, INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
1946 int addrconf_del_ifaddr(void __user *arg)
1948 struct in6_ifreq ireq;
1951 if (!capable(CAP_NET_ADMIN))
1954 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
1958 err = inet6_addr_del(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen);
1963 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1964 static void sit_add_v4_addrs(struct inet6_dev *idev)
1966 struct inet6_ifaddr * ifp;
1967 struct in6_addr addr;
1968 struct net_device *dev;
1973 memset(&addr, 0, sizeof(struct in6_addr));
1974 memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4);
1976 if (idev->dev->flags&IFF_POINTOPOINT) {
1977 addr.s6_addr32[0] = htonl(0xfe800000);
1980 scope = IPV6_ADDR_COMPATv4;
1983 if (addr.s6_addr32[3]) {
1984 ifp = ipv6_add_addr(idev, &addr, 128, scope, IFA_F_PERMANENT);
1986 spin_lock_bh(&ifp->lock);
1987 ifp->flags &= ~IFA_F_TENTATIVE;
1988 spin_unlock_bh(&ifp->lock);
1989 ipv6_ifa_notify(RTM_NEWADDR, ifp);
1995 for (dev = dev_base; dev != NULL; dev = dev->next) {
1996 struct in_device * in_dev = __in_dev_get_rtnl(dev);
1997 if (in_dev && (dev->flags & IFF_UP)) {
1998 struct in_ifaddr * ifa;
2002 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
2005 addr.s6_addr32[3] = ifa->ifa_local;
2007 if (ifa->ifa_scope == RT_SCOPE_LINK)
2009 if (ifa->ifa_scope >= RT_SCOPE_HOST) {
2010 if (idev->dev->flags&IFF_POINTOPOINT)
2014 if (idev->dev->flags&IFF_POINTOPOINT)
2019 ifp = ipv6_add_addr(idev, &addr, plen, flag,
2022 spin_lock_bh(&ifp->lock);
2023 ifp->flags &= ~IFA_F_TENTATIVE;
2024 spin_unlock_bh(&ifp->lock);
2025 ipv6_ifa_notify(RTM_NEWADDR, ifp);
2034 static void init_loopback(struct net_device *dev)
2036 struct inet6_dev *idev;
2037 struct inet6_ifaddr * ifp;
2043 if ((idev = ipv6_find_idev(dev)) == NULL) {
2044 printk(KERN_DEBUG "init loopback: add_dev failed\n");
2048 ifp = ipv6_add_addr(idev, &in6addr_loopback, 128, IFA_HOST, IFA_F_PERMANENT);
2050 spin_lock_bh(&ifp->lock);
2051 ifp->flags &= ~IFA_F_TENTATIVE;
2052 spin_unlock_bh(&ifp->lock);
2053 ipv6_ifa_notify(RTM_NEWADDR, ifp);
2058 static void addrconf_add_linklocal(struct inet6_dev *idev, struct in6_addr *addr)
2060 struct inet6_ifaddr * ifp;
2062 ifp = ipv6_add_addr(idev, addr, 64, IFA_LINK, IFA_F_PERMANENT);
2064 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, 0, 0);
2065 addrconf_dad_start(ifp, 0);
2070 static void addrconf_dev_config(struct net_device *dev)
2072 struct in6_addr addr;
2073 struct inet6_dev * idev;
2077 if ((dev->type != ARPHRD_ETHER) &&
2078 (dev->type != ARPHRD_FDDI) &&
2079 (dev->type != ARPHRD_IEEE802_TR) &&
2080 (dev->type != ARPHRD_ARCNET) &&
2081 (dev->type != ARPHRD_INFINIBAND)) {
2082 /* Alas, we support only Ethernet autoconfiguration. */
2086 idev = addrconf_add_dev(dev);
2090 memset(&addr, 0, sizeof(struct in6_addr));
2091 addr.s6_addr32[0] = htonl(0xFE800000);
2093 if (ipv6_generate_eui64(addr.s6_addr + 8, dev) == 0)
2094 addrconf_add_linklocal(idev, &addr);
2097 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2098 static void addrconf_sit_config(struct net_device *dev)
2100 struct inet6_dev *idev;
2105 * Configure the tunnel with one of our IPv4
2106 * addresses... we should configure all of
2107 * our v4 addrs in the tunnel
2110 if ((idev = ipv6_find_idev(dev)) == NULL) {
2111 printk(KERN_DEBUG "init sit: add_dev failed\n");
2115 sit_add_v4_addrs(idev);
2117 if (dev->flags&IFF_POINTOPOINT) {
2118 addrconf_add_mroute(dev);
2119 addrconf_add_lroute(dev);
2126 ipv6_inherit_linklocal(struct inet6_dev *idev, struct net_device *link_dev)
2128 struct in6_addr lladdr;
2130 if (!ipv6_get_lladdr(link_dev, &lladdr)) {
2131 addrconf_add_linklocal(idev, &lladdr);
2137 static void ip6_tnl_add_linklocal(struct inet6_dev *idev)
2139 struct net_device *link_dev;
2141 /* first try to inherit the link-local address from the link device */
2142 if (idev->dev->iflink &&
2143 (link_dev = __dev_get_by_index(idev->dev->iflink))) {
2144 if (!ipv6_inherit_linklocal(idev, link_dev))
2147 /* then try to inherit it from any device */
2148 for (link_dev = dev_base; link_dev; link_dev = link_dev->next) {
2149 if (!ipv6_inherit_linklocal(idev, link_dev))
2152 printk(KERN_DEBUG "init ip6-ip6: add_linklocal failed\n");
2156 * Autoconfigure tunnel with a link-local address so routing protocols,
2157 * DHCPv6, MLD etc. can be run over the virtual link
2160 static void addrconf_ip6_tnl_config(struct net_device *dev)
2162 struct inet6_dev *idev;
2166 if ((idev = addrconf_add_dev(dev)) == NULL) {
2167 printk(KERN_DEBUG "init ip6-ip6: add_dev failed\n");
2170 ip6_tnl_add_linklocal(idev);
2173 static int addrconf_notify(struct notifier_block *this, unsigned long event,
2176 struct net_device *dev = (struct net_device *) data;
2177 struct inet6_dev *idev = __in6_dev_get(dev);
2178 int run_pending = 0;
2181 case NETDEV_REGISTER:
2183 idev = ipv6_add_dev(dev);
2185 printk(KERN_WARNING "IPv6: add_dev failed for %s\n",
2191 if (event == NETDEV_UP) {
2192 if (!netif_carrier_ok(dev)) {
2193 /* device is not ready yet. */
2195 "ADDRCONF(NETDEV_UP): %s: "
2196 "link is not ready\n",
2202 idev->if_flags |= IF_READY;
2204 if (!netif_carrier_ok(dev)) {
2205 /* device is still not ready. */
2210 if (idev->if_flags & IF_READY) {
2211 /* device is already configured. */
2214 idev->if_flags |= IF_READY;
2218 "ADDRCONF(NETDEV_CHANGE): %s: "
2219 "link becomes ready\n",
2226 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2228 addrconf_sit_config(dev);
2231 case ARPHRD_TUNNEL6:
2232 addrconf_ip6_tnl_config(dev);
2234 case ARPHRD_LOOPBACK:
2239 addrconf_dev_config(dev);
2244 addrconf_dad_run(idev);
2246 /* If the MTU changed during the interface down, when the
2247 interface up, the changed MTU must be reflected in the
2248 idev as well as routers.
2250 if (idev->cnf.mtu6 != dev->mtu && dev->mtu >= IPV6_MIN_MTU) {
2251 rt6_mtu_change(dev, dev->mtu);
2252 idev->cnf.mtu6 = dev->mtu;
2254 idev->tstamp = jiffies;
2255 inet6_ifinfo_notify(RTM_NEWLINK, idev);
2256 /* If the changed mtu during down is lower than IPV6_MIN_MTU
2257 stop IPv6 on this interface.
2259 if (dev->mtu < IPV6_MIN_MTU)
2260 addrconf_ifdown(dev, event != NETDEV_DOWN);
2264 case NETDEV_CHANGEMTU:
2265 if ( idev && dev->mtu >= IPV6_MIN_MTU) {
2266 rt6_mtu_change(dev, dev->mtu);
2267 idev->cnf.mtu6 = dev->mtu;
2271 /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */
2274 case NETDEV_UNREGISTER:
2276 * Remove all addresses from this interface.
2278 addrconf_ifdown(dev, event != NETDEV_DOWN);
2281 case NETDEV_CHANGENAME:
2282 #ifdef CONFIG_SYSCTL
2284 addrconf_sysctl_unregister(&idev->cnf);
2285 neigh_sysctl_unregister(idev->nd_parms);
2286 neigh_sysctl_register(dev, idev->nd_parms,
2287 NET_IPV6, NET_IPV6_NEIGH, "ipv6",
2288 &ndisc_ifinfo_sysctl_change,
2290 addrconf_sysctl_register(idev, &idev->cnf);
2300 * addrconf module should be notified of a device going up
2302 static struct notifier_block ipv6_dev_notf = {
2303 .notifier_call = addrconf_notify,
2307 static int addrconf_ifdown(struct net_device *dev, int how)
2309 struct inet6_dev *idev;
2310 struct inet6_ifaddr *ifa, **bifa;
2315 if (dev == &loopback_dev && how == 1)
2319 neigh_ifdown(&nd_tbl, dev);
2321 idev = __in6_dev_get(dev);
2325 /* Step 1: remove reference to ipv6 device from parent device.
2331 /* protected by rtnl_lock */
2332 rcu_assign_pointer(dev->ip6_ptr, NULL);
2334 /* Step 1.5: remove snmp6 entry */
2335 snmp6_unregister_dev(idev);
2339 /* Step 2: clear hash table */
2340 for (i=0; i<IN6_ADDR_HSIZE; i++) {
2341 bifa = &inet6_addr_lst[i];
2343 write_lock_bh(&addrconf_hash_lock);
2344 while ((ifa = *bifa) != NULL) {
2345 if (ifa->idev == idev) {
2346 *bifa = ifa->lst_next;
2347 ifa->lst_next = NULL;
2348 addrconf_del_timer(ifa);
2352 bifa = &ifa->lst_next;
2354 write_unlock_bh(&addrconf_hash_lock);
2357 write_lock_bh(&idev->lock);
2359 /* Step 3: clear flags for stateless addrconf */
2361 idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY);
2363 /* Step 4: clear address list */
2364 #ifdef CONFIG_IPV6_PRIVACY
2365 if (how == 1 && del_timer(&idev->regen_timer))
2368 /* clear tempaddr list */
2369 while ((ifa = idev->tempaddr_list) != NULL) {
2370 idev->tempaddr_list = ifa->tmp_next;
2371 ifa->tmp_next = NULL;
2373 write_unlock_bh(&idev->lock);
2374 spin_lock_bh(&ifa->lock);
2377 in6_ifa_put(ifa->ifpub);
2380 spin_unlock_bh(&ifa->lock);
2382 write_lock_bh(&idev->lock);
2385 while ((ifa = idev->addr_list) != NULL) {
2386 idev->addr_list = ifa->if_next;
2387 ifa->if_next = NULL;
2389 addrconf_del_timer(ifa);
2390 write_unlock_bh(&idev->lock);
2392 __ipv6_ifa_notify(RTM_DELADDR, ifa);
2395 write_lock_bh(&idev->lock);
2397 write_unlock_bh(&idev->lock);
2399 /* Step 5: Discard multicast list */
2402 ipv6_mc_destroy_dev(idev);
2406 /* Step 5: netlink notification of this interface */
2407 idev->tstamp = jiffies;
2408 inet6_ifinfo_notify(RTM_DELLINK, idev);
2410 /* Shot the device (if unregistered) */
2413 #ifdef CONFIG_SYSCTL
2414 addrconf_sysctl_unregister(&idev->cnf);
2415 neigh_sysctl_unregister(idev->nd_parms);
2417 neigh_parms_release(&nd_tbl, idev->nd_parms);
2418 neigh_ifdown(&nd_tbl, dev);
2424 static void addrconf_rs_timer(unsigned long data)
2426 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data;
2428 if (ifp->idev->cnf.forwarding)
2431 if (ifp->idev->if_flags & IF_RA_RCVD) {
2433 * Announcement received after solicitation
2439 spin_lock(&ifp->lock);
2440 if (ifp->probes++ < ifp->idev->cnf.rtr_solicits) {
2441 struct in6_addr all_routers;
2443 /* The wait after the last probe can be shorter */
2444 addrconf_mod_timer(ifp, AC_RS,
2445 (ifp->probes == ifp->idev->cnf.rtr_solicits) ?
2446 ifp->idev->cnf.rtr_solicit_delay :
2447 ifp->idev->cnf.rtr_solicit_interval);
2448 spin_unlock(&ifp->lock);
2450 ipv6_addr_all_routers(&all_routers);
2452 ndisc_send_rs(ifp->idev->dev, &ifp->addr, &all_routers);
2454 spin_unlock(&ifp->lock);
2456 * Note: we do not support deprecated "all on-link"
2457 * assumption any longer.
2459 printk(KERN_DEBUG "%s: no IPv6 routers present\n",
2460 ifp->idev->dev->name);
2468 * Duplicate Address Detection
2470 static void addrconf_dad_kick(struct inet6_ifaddr *ifp)
2472 unsigned long rand_num;
2473 struct inet6_dev *idev = ifp->idev;
2475 rand_num = net_random() % (idev->cnf.rtr_solicit_delay ? : 1);
2476 ifp->probes = idev->cnf.dad_transmits;
2477 addrconf_mod_timer(ifp, AC_DAD, rand_num);
2480 static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags)
2482 struct inet6_dev *idev = ifp->idev;
2483 struct net_device *dev = idev->dev;
2485 addrconf_join_solict(dev, &ifp->addr);
2487 net_srandom(ifp->addr.s6_addr32[3]);
2489 read_lock_bh(&idev->lock);
2492 spin_lock_bh(&ifp->lock);
2494 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) ||
2495 !(ifp->flags&IFA_F_TENTATIVE) ||
2496 ifp->flags & IFA_F_NODAD) {
2497 ifp->flags &= ~IFA_F_TENTATIVE;
2498 spin_unlock_bh(&ifp->lock);
2499 read_unlock_bh(&idev->lock);
2501 addrconf_dad_completed(ifp);
2505 if (!(idev->if_flags & IF_READY)) {
2506 spin_unlock_bh(&ifp->lock);
2507 read_unlock_bh(&idev->lock);
2509 * If the defice is not ready:
2510 * - keep it tentative if it is a permanent address.
2511 * - otherwise, kill it.
2514 addrconf_dad_stop(ifp);
2517 addrconf_dad_kick(ifp);
2518 spin_unlock_bh(&ifp->lock);
2520 read_unlock_bh(&idev->lock);
2523 static void addrconf_dad_timer(unsigned long data)
2525 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data;
2526 struct inet6_dev *idev = ifp->idev;
2527 struct in6_addr unspec;
2528 struct in6_addr mcaddr;
2530 read_lock_bh(&idev->lock);
2532 read_unlock_bh(&idev->lock);
2535 spin_lock_bh(&ifp->lock);
2536 if (ifp->probes == 0) {
2538 * DAD was successful
2541 ifp->flags &= ~IFA_F_TENTATIVE;
2542 spin_unlock_bh(&ifp->lock);
2543 read_unlock_bh(&idev->lock);
2545 addrconf_dad_completed(ifp);
2551 addrconf_mod_timer(ifp, AC_DAD, ifp->idev->nd_parms->retrans_time);
2552 spin_unlock_bh(&ifp->lock);
2553 read_unlock_bh(&idev->lock);
2555 /* send a neighbour solicitation for our addr */
2556 memset(&unspec, 0, sizeof(unspec));
2557 addrconf_addr_solict_mult(&ifp->addr, &mcaddr);
2558 ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &unspec);
2563 static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
2565 struct net_device * dev = ifp->idev->dev;
2568 * Configure the address for reception. Now it is valid.
2571 ipv6_ifa_notify(RTM_NEWADDR, ifp);
2573 /* If added prefix is link local and forwarding is off,
2574 start sending router solicitations.
2577 if (ifp->idev->cnf.forwarding == 0 &&
2578 ifp->idev->cnf.rtr_solicits > 0 &&
2579 (dev->flags&IFF_LOOPBACK) == 0 &&
2580 (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) {
2581 struct in6_addr all_routers;
2583 ipv6_addr_all_routers(&all_routers);
2586 * If a host as already performed a random delay
2587 * [...] as part of DAD [...] there is no need
2588 * to delay again before sending the first RS
2590 ndisc_send_rs(ifp->idev->dev, &ifp->addr, &all_routers);
2592 spin_lock_bh(&ifp->lock);
2594 ifp->idev->if_flags |= IF_RS_SENT;
2595 addrconf_mod_timer(ifp, AC_RS, ifp->idev->cnf.rtr_solicit_interval);
2596 spin_unlock_bh(&ifp->lock);
2600 static void addrconf_dad_run(struct inet6_dev *idev) {
2601 struct inet6_ifaddr *ifp;
2603 read_lock_bh(&idev->lock);
2604 for (ifp = idev->addr_list; ifp; ifp = ifp->if_next) {
2605 spin_lock_bh(&ifp->lock);
2606 if (!(ifp->flags & IFA_F_TENTATIVE)) {
2607 spin_unlock_bh(&ifp->lock);
2610 spin_unlock_bh(&ifp->lock);
2611 addrconf_dad_kick(ifp);
2613 read_unlock_bh(&idev->lock);
2616 #ifdef CONFIG_PROC_FS
2617 struct if6_iter_state {
2621 static struct inet6_ifaddr *if6_get_first(struct seq_file *seq)
2623 struct inet6_ifaddr *ifa = NULL;
2624 struct if6_iter_state *state = seq->private;
2626 for (state->bucket = 0; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) {
2627 ifa = inet6_addr_lst[state->bucket];
2634 static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, struct inet6_ifaddr *ifa)
2636 struct if6_iter_state *state = seq->private;
2638 ifa = ifa->lst_next;
2640 if (!ifa && ++state->bucket < IN6_ADDR_HSIZE) {
2641 ifa = inet6_addr_lst[state->bucket];
2647 static struct inet6_ifaddr *if6_get_idx(struct seq_file *seq, loff_t pos)
2649 struct inet6_ifaddr *ifa = if6_get_first(seq);
2652 while(pos && (ifa = if6_get_next(seq, ifa)) != NULL)
2654 return pos ? NULL : ifa;
2657 static void *if6_seq_start(struct seq_file *seq, loff_t *pos)
2659 read_lock_bh(&addrconf_hash_lock);
2660 return if6_get_idx(seq, *pos);
2663 static void *if6_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2665 struct inet6_ifaddr *ifa;
2667 ifa = if6_get_next(seq, v);
2672 static void if6_seq_stop(struct seq_file *seq, void *v)
2674 read_unlock_bh(&addrconf_hash_lock);
2677 static int if6_seq_show(struct seq_file *seq, void *v)
2679 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
2681 NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
2683 ifp->idev->dev->ifindex,
2687 ifp->idev->dev->name);
2691 static struct seq_operations if6_seq_ops = {
2692 .start = if6_seq_start,
2693 .next = if6_seq_next,
2694 .show = if6_seq_show,
2695 .stop = if6_seq_stop,
2698 static int if6_seq_open(struct inode *inode, struct file *file)
2700 struct seq_file *seq;
2702 struct if6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
2707 rc = seq_open(file, &if6_seq_ops);
2711 seq = file->private_data;
2720 static const struct file_operations if6_fops = {
2721 .owner = THIS_MODULE,
2722 .open = if6_seq_open,
2724 .llseek = seq_lseek,
2725 .release = seq_release_private,
2728 int __init if6_proc_init(void)
2730 if (!proc_net_fops_create("if_inet6", S_IRUGO, &if6_fops))
2735 void if6_proc_exit(void)
2737 proc_net_remove("if_inet6");
2739 #endif /* CONFIG_PROC_FS */
2741 #ifdef CONFIG_IPV6_MIP6
2742 /* Check if address is a home address configured on any interface. */
2743 int ipv6_chk_home_addr(struct in6_addr *addr)
2746 struct inet6_ifaddr * ifp;
2747 u8 hash = ipv6_addr_hash(addr);
2748 read_lock_bh(&addrconf_hash_lock);
2749 for (ifp = inet6_addr_lst[hash]; ifp; ifp = ifp->lst_next) {
2750 if (ipv6_addr_cmp(&ifp->addr, addr) == 0 &&
2751 (ifp->flags & IFA_F_HOMEADDRESS)) {
2756 read_unlock_bh(&addrconf_hash_lock);
2762 * Periodic address status verification
2765 static void addrconf_verify(unsigned long foo)
2767 struct inet6_ifaddr *ifp;
2768 unsigned long now, next;
2771 spin_lock_bh(&addrconf_verify_lock);
2773 next = now + ADDR_CHECK_FREQUENCY;
2775 del_timer(&addr_chk_timer);
2777 for (i=0; i < IN6_ADDR_HSIZE; i++) {
2780 read_lock(&addrconf_hash_lock);
2781 for (ifp=inet6_addr_lst[i]; ifp; ifp=ifp->lst_next) {
2783 #ifdef CONFIG_IPV6_PRIVACY
2784 unsigned long regen_advance;
2787 if (ifp->flags & IFA_F_PERMANENT)
2790 spin_lock(&ifp->lock);
2791 age = (now - ifp->tstamp) / HZ;
2793 #ifdef CONFIG_IPV6_PRIVACY
2794 regen_advance = ifp->idev->cnf.regen_max_retry *
2795 ifp->idev->cnf.dad_transmits *
2796 ifp->idev->nd_parms->retrans_time / HZ;
2799 if (ifp->valid_lft != INFINITY_LIFE_TIME &&
2800 age >= ifp->valid_lft) {
2801 spin_unlock(&ifp->lock);
2803 read_unlock(&addrconf_hash_lock);
2806 } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) {
2807 spin_unlock(&ifp->lock);
2809 } else if (age >= ifp->prefered_lft) {
2810 /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */
2813 if (!(ifp->flags&IFA_F_DEPRECATED)) {
2815 ifp->flags |= IFA_F_DEPRECATED;
2818 if (time_before(ifp->tstamp + ifp->valid_lft * HZ, next))
2819 next = ifp->tstamp + ifp->valid_lft * HZ;
2821 spin_unlock(&ifp->lock);
2825 read_unlock(&addrconf_hash_lock);
2827 ipv6_ifa_notify(0, ifp);
2831 #ifdef CONFIG_IPV6_PRIVACY
2832 } else if ((ifp->flags&IFA_F_TEMPORARY) &&
2833 !(ifp->flags&IFA_F_TENTATIVE)) {
2834 if (age >= ifp->prefered_lft - regen_advance) {
2835 struct inet6_ifaddr *ifpub = ifp->ifpub;
2836 if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next))
2837 next = ifp->tstamp + ifp->prefered_lft * HZ;
2838 if (!ifp->regen_count && ifpub) {
2841 in6_ifa_hold(ifpub);
2842 spin_unlock(&ifp->lock);
2843 read_unlock(&addrconf_hash_lock);
2844 spin_lock(&ifpub->lock);
2845 ifpub->regen_count = 0;
2846 spin_unlock(&ifpub->lock);
2847 ipv6_create_tempaddr(ifpub, ifp);
2852 } else if (time_before(ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ, next))
2853 next = ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ;
2854 spin_unlock(&ifp->lock);
2857 /* ifp->prefered_lft <= ifp->valid_lft */
2858 if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next))
2859 next = ifp->tstamp + ifp->prefered_lft * HZ;
2860 spin_unlock(&ifp->lock);
2863 read_unlock(&addrconf_hash_lock);
2866 addr_chk_timer.expires = time_before(next, jiffies + HZ) ? jiffies + HZ : next;
2867 add_timer(&addr_chk_timer);
2868 spin_unlock_bh(&addrconf_verify_lock);
2871 static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local)
2873 struct in6_addr *pfx = NULL;
2876 pfx = nla_data(addr);
2879 if (pfx && nla_memcmp(local, pfx, sizeof(*pfx)))
2882 pfx = nla_data(local);
2888 static struct nla_policy ifa_ipv6_policy[IFA_MAX+1] __read_mostly = {
2889 [IFA_ADDRESS] = { .len = sizeof(struct in6_addr) },
2890 [IFA_LOCAL] = { .len = sizeof(struct in6_addr) },
2891 [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) },
2895 inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
2897 struct ifaddrmsg *ifm;
2898 struct nlattr *tb[IFA_MAX+1];
2899 struct in6_addr *pfx;
2902 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
2906 ifm = nlmsg_data(nlh);
2907 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
2911 return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen);
2914 static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
2915 u32 prefered_lft, u32 valid_lft)
2917 u32 flags = RTF_EXPIRES;
2919 if (!valid_lft || (prefered_lft > valid_lft))
2922 if (valid_lft == INFINITY_LIFE_TIME) {
2923 ifa_flags |= IFA_F_PERMANENT;
2925 } else if (valid_lft >= 0x7FFFFFFF/HZ)
2926 valid_lft = 0x7FFFFFFF/HZ;
2928 if (prefered_lft == 0)
2929 ifa_flags |= IFA_F_DEPRECATED;
2930 else if ((prefered_lft >= 0x7FFFFFFF/HZ) &&
2931 (prefered_lft != INFINITY_LIFE_TIME))
2932 prefered_lft = 0x7FFFFFFF/HZ;
2934 spin_lock_bh(&ifp->lock);
2935 ifp->flags = (ifp->flags & ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | IFA_F_HOMEADDRESS)) | ifa_flags;
2936 ifp->tstamp = jiffies;
2937 ifp->valid_lft = valid_lft;
2938 ifp->prefered_lft = prefered_lft;
2940 spin_unlock_bh(&ifp->lock);
2941 if (!(ifp->flags&IFA_F_TENTATIVE))
2942 ipv6_ifa_notify(0, ifp);
2944 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev,
2945 jiffies_to_clock_t(valid_lft * HZ), flags);
2952 inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
2954 struct ifaddrmsg *ifm;
2955 struct nlattr *tb[IFA_MAX+1];
2956 struct in6_addr *pfx;
2957 struct inet6_ifaddr *ifa;
2958 struct net_device *dev;
2959 u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME;
2963 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
2967 ifm = nlmsg_data(nlh);
2968 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
2972 if (tb[IFA_CACHEINFO]) {
2973 struct ifa_cacheinfo *ci;
2975 ci = nla_data(tb[IFA_CACHEINFO]);
2976 valid_lft = ci->ifa_valid;
2977 preferred_lft = ci->ifa_prefered;
2979 preferred_lft = INFINITY_LIFE_TIME;
2980 valid_lft = INFINITY_LIFE_TIME;
2983 dev = __dev_get_by_index(ifm->ifa_index);
2987 /* We ignore other flags so far. */
2988 ifa_flags = ifm->ifa_flags & (IFA_F_NODAD | IFA_F_HOMEADDRESS);
2990 ifa = ipv6_get_ifaddr(pfx, dev, 1);
2993 * It would be best to check for !NLM_F_CREATE here but
2994 * userspace alreay relies on not having to provide this.
2996 return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen,
2997 ifa_flags, preferred_lft, valid_lft);
3000 if (nlh->nlmsg_flags & NLM_F_EXCL ||
3001 !(nlh->nlmsg_flags & NLM_F_REPLACE))
3004 err = inet6_addr_modify(ifa, ifa_flags, preferred_lft, valid_lft);
3011 static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u8 flags,
3012 u8 scope, int ifindex)
3014 struct ifaddrmsg *ifm;
3016 ifm = nlmsg_data(nlh);
3017 ifm->ifa_family = AF_INET6;
3018 ifm->ifa_prefixlen = prefixlen;
3019 ifm->ifa_flags = flags;
3020 ifm->ifa_scope = scope;
3021 ifm->ifa_index = ifindex;
3024 static int put_cacheinfo(struct sk_buff *skb, unsigned long cstamp,
3025 unsigned long tstamp, u32 preferred, u32 valid)
3027 struct ifa_cacheinfo ci;
3029 ci.cstamp = (u32)(TIME_DELTA(cstamp, INITIAL_JIFFIES) / HZ * 100
3030 + TIME_DELTA(cstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
3031 ci.tstamp = (u32)(TIME_DELTA(tstamp, INITIAL_JIFFIES) / HZ * 100
3032 + TIME_DELTA(tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
3033 ci.ifa_prefered = preferred;
3034 ci.ifa_valid = valid;
3036 return nla_put(skb, IFA_CACHEINFO, sizeof(ci), &ci);
3039 static inline int rt_scope(int ifa_scope)
3041 if (ifa_scope & IFA_HOST)
3042 return RT_SCOPE_HOST;
3043 else if (ifa_scope & IFA_LINK)
3044 return RT_SCOPE_LINK;
3045 else if (ifa_scope & IFA_SITE)
3046 return RT_SCOPE_SITE;
3048 return RT_SCOPE_UNIVERSE;
3051 static inline int inet6_ifaddr_msgsize(void)
3053 return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
3054 + nla_total_size(16) /* IFA_ADDRESS */
3055 + nla_total_size(sizeof(struct ifa_cacheinfo));
3058 static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
3059 u32 pid, u32 seq, int event, unsigned int flags)
3061 struct nlmsghdr *nlh;
3062 u32 preferred, valid;
3064 nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
3068 put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope),
3069 ifa->idev->dev->ifindex);
3071 if (!(ifa->flags&IFA_F_PERMANENT)) {
3072 preferred = ifa->prefered_lft;
3073 valid = ifa->valid_lft;
3074 if (preferred != INFINITY_LIFE_TIME) {
3075 long tval = (jiffies - ifa->tstamp)/HZ;
3077 if (valid != INFINITY_LIFE_TIME)
3081 preferred = INFINITY_LIFE_TIME;
3082 valid = INFINITY_LIFE_TIME;
3085 if (nla_put(skb, IFA_ADDRESS, 16, &ifa->addr) < 0 ||
3086 put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) {
3087 nlmsg_cancel(skb, nlh);
3091 return nlmsg_end(skb, nlh);
3094 static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca,
3095 u32 pid, u32 seq, int event, u16 flags)
3097 struct nlmsghdr *nlh;
3098 u8 scope = RT_SCOPE_UNIVERSE;
3099 int ifindex = ifmca->idev->dev->ifindex;
3101 if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE)
3102 scope = RT_SCOPE_SITE;
3104 nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
3108 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
3109 if (nla_put(skb, IFA_MULTICAST, 16, &ifmca->mca_addr) < 0 ||
3110 put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp,
3111 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
3112 nlmsg_cancel(skb, nlh);
3116 return nlmsg_end(skb, nlh);
3119 static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca,
3120 u32 pid, u32 seq, int event, unsigned int flags)
3122 struct nlmsghdr *nlh;
3123 u8 scope = RT_SCOPE_UNIVERSE;
3124 int ifindex = ifaca->aca_idev->dev->ifindex;
3126 if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE)
3127 scope = RT_SCOPE_SITE;
3129 nlh = nlmsg_put(skb, pid, seq, event, sizeof(struct ifaddrmsg), flags);
3133 put_ifaddrmsg(nlh, 128, IFA_F_PERMANENT, scope, ifindex);
3134 if (nla_put(skb, IFA_ANYCAST, 16, &ifaca->aca_addr) < 0 ||
3135 put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp,
3136 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME) < 0) {
3137 nlmsg_cancel(skb, nlh);
3141 return nlmsg_end(skb, nlh);
3151 static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
3152 enum addr_type_t type)
3155 int s_idx, s_ip_idx;
3157 struct net_device *dev;
3158 struct inet6_dev *idev = NULL;
3159 struct inet6_ifaddr *ifa;
3160 struct ifmcaddr6 *ifmca;
3161 struct ifacaddr6 *ifaca;
3163 s_idx = cb->args[0];
3164 s_ip_idx = ip_idx = cb->args[1];
3165 read_lock(&dev_base_lock);
3167 for (dev = dev_base, idx = 0; dev; dev = dev->next, idx++) {
3173 if ((idev = in6_dev_get(dev)) == NULL)
3175 read_lock_bh(&idev->lock);
3178 /* unicast address incl. temp addr */
3179 for (ifa = idev->addr_list; ifa;
3180 ifa = ifa->if_next, ip_idx++) {
3181 if (ip_idx < s_ip_idx)
3183 if ((err = inet6_fill_ifaddr(skb, ifa,
3184 NETLINK_CB(cb->skb).pid,
3185 cb->nlh->nlmsg_seq, RTM_NEWADDR,
3190 case MULTICAST_ADDR:
3191 /* multicast address */
3192 for (ifmca = idev->mc_list; ifmca;
3193 ifmca = ifmca->next, ip_idx++) {
3194 if (ip_idx < s_ip_idx)
3196 if ((err = inet6_fill_ifmcaddr(skb, ifmca,
3197 NETLINK_CB(cb->skb).pid,
3198 cb->nlh->nlmsg_seq, RTM_GETMULTICAST,
3204 /* anycast address */
3205 for (ifaca = idev->ac_list; ifaca;
3206 ifaca = ifaca->aca_next, ip_idx++) {
3207 if (ip_idx < s_ip_idx)
3209 if ((err = inet6_fill_ifacaddr(skb, ifaca,
3210 NETLINK_CB(cb->skb).pid,
3211 cb->nlh->nlmsg_seq, RTM_GETANYCAST,
3219 read_unlock_bh(&idev->lock);
3224 read_unlock_bh(&idev->lock);
3227 read_unlock(&dev_base_lock);
3229 cb->args[1] = ip_idx;
3233 static int inet6_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
3235 enum addr_type_t type = UNICAST_ADDR;
3236 return inet6_dump_addr(skb, cb, type);
3239 static int inet6_dump_ifmcaddr(struct sk_buff *skb, struct netlink_callback *cb)
3241 enum addr_type_t type = MULTICAST_ADDR;
3242 return inet6_dump_addr(skb, cb, type);
3246 static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb)
3248 enum addr_type_t type = ANYCAST_ADDR;
3249 return inet6_dump_addr(skb, cb, type);
3252 static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr* nlh,
3255 struct ifaddrmsg *ifm;
3256 struct nlattr *tb[IFA_MAX+1];
3257 struct in6_addr *addr = NULL;
3258 struct net_device *dev = NULL;
3259 struct inet6_ifaddr *ifa;
3260 struct sk_buff *skb;
3263 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy);
3267 addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]);
3273 ifm = nlmsg_data(nlh);
3275 dev = __dev_get_by_index(ifm->ifa_index);
3277 if ((ifa = ipv6_get_ifaddr(addr, dev, 1)) == NULL) {
3278 err = -EADDRNOTAVAIL;
3282 if ((skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL)) == NULL) {
3287 err = inet6_fill_ifaddr(skb, ifa, NETLINK_CB(in_skb).pid,
3288 nlh->nlmsg_seq, RTM_NEWADDR, 0);
3290 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
3291 WARN_ON(err == -EMSGSIZE);
3295 err = rtnl_unicast(skb, NETLINK_CB(in_skb).pid);
3302 static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
3304 struct sk_buff *skb;
3307 skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC);
3311 err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0);
3313 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
3314 WARN_ON(err == -EMSGSIZE);
3318 err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
3321 rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err);
3324 static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
3325 __s32 *array, int bytes)
3327 BUG_ON(bytes < (DEVCONF_MAX * 4));
3329 memset(array, 0, bytes);
3330 array[DEVCONF_FORWARDING] = cnf->forwarding;
3331 array[DEVCONF_HOPLIMIT] = cnf->hop_limit;
3332 array[DEVCONF_MTU6] = cnf->mtu6;
3333 array[DEVCONF_ACCEPT_RA] = cnf->accept_ra;
3334 array[DEVCONF_ACCEPT_REDIRECTS] = cnf->accept_redirects;
3335 array[DEVCONF_AUTOCONF] = cnf->autoconf;
3336 array[DEVCONF_DAD_TRANSMITS] = cnf->dad_transmits;
3337 array[DEVCONF_RTR_SOLICITS] = cnf->rtr_solicits;
3338 array[DEVCONF_RTR_SOLICIT_INTERVAL] = cnf->rtr_solicit_interval;
3339 array[DEVCONF_RTR_SOLICIT_DELAY] = cnf->rtr_solicit_delay;
3340 array[DEVCONF_FORCE_MLD_VERSION] = cnf->force_mld_version;
3341 #ifdef CONFIG_IPV6_PRIVACY
3342 array[DEVCONF_USE_TEMPADDR] = cnf->use_tempaddr;
3343 array[DEVCONF_TEMP_VALID_LFT] = cnf->temp_valid_lft;
3344 array[DEVCONF_TEMP_PREFERED_LFT] = cnf->temp_prefered_lft;
3345 array[DEVCONF_REGEN_MAX_RETRY] = cnf->regen_max_retry;
3346 array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor;
3348 array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses;
3349 array[DEVCONF_ACCEPT_RA_DEFRTR] = cnf->accept_ra_defrtr;
3350 array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo;
3351 #ifdef CONFIG_IPV6_ROUTER_PREF
3352 array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref;
3353 array[DEVCONF_RTR_PROBE_INTERVAL] = cnf->rtr_probe_interval;
3354 #ifdef CONFIG_IPV6_ROUTE_INFO
3355 array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen;
3358 array[DEVCONF_PROXY_NDP] = cnf->proxy_ndp;
3361 static inline size_t inet6_if_nlmsg_size(void)
3363 return NLMSG_ALIGN(sizeof(struct ifinfomsg))
3364 + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
3365 + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
3366 + nla_total_size(4) /* IFLA_MTU */
3367 + nla_total_size(4) /* IFLA_LINK */
3368 + nla_total_size( /* IFLA_PROTINFO */
3369 nla_total_size(4) /* IFLA_INET6_FLAGS */
3370 + nla_total_size(sizeof(struct ifla_cacheinfo))
3371 + nla_total_size(DEVCONF_MAX * 4) /* IFLA_INET6_CONF */
3375 static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
3376 u32 pid, u32 seq, int event, unsigned int flags)
3378 struct net_device *dev = idev->dev;
3379 struct nlattr *conf;
3380 struct ifinfomsg *hdr;
3381 struct nlmsghdr *nlh;
3383 struct ifla_cacheinfo ci;
3385 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*hdr), flags);
3389 hdr = nlmsg_data(nlh);
3390 hdr->ifi_family = AF_INET6;
3392 hdr->ifi_type = dev->type;
3393 hdr->ifi_index = dev->ifindex;
3394 hdr->ifi_flags = dev_get_flags(dev);
3395 hdr->ifi_change = 0;
3397 NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name);
3400 NLA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr);
3402 NLA_PUT_U32(skb, IFLA_MTU, dev->mtu);
3403 if (dev->ifindex != dev->iflink)
3404 NLA_PUT_U32(skb, IFLA_LINK, dev->iflink);
3406 protoinfo = nla_nest_start(skb, IFLA_PROTINFO);
3407 if (protoinfo == NULL)
3408 goto nla_put_failure;
3410 NLA_PUT_U32(skb, IFLA_INET6_FLAGS, idev->if_flags);
3412 ci.max_reasm_len = IPV6_MAXPLEN;
3413 ci.tstamp = (__u32)(TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) / HZ * 100
3414 + TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
3415 ci.reachable_time = idev->nd_parms->reachable_time;
3416 ci.retrans_time = idev->nd_parms->retrans_time;
3417 NLA_PUT(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci);
3419 conf = nla_reserve(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(s32));
3421 goto nla_put_failure;
3422 ipv6_store_devconf(&idev->cnf, nla_data(conf), nla_len(conf));
3424 /* XXX - Statistics/MC not implemented */
3426 nla_nest_end(skb, protoinfo);
3427 return nlmsg_end(skb, nlh);
3430 nlmsg_cancel(skb, nlh);
3434 static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
3437 int s_idx = cb->args[0];
3438 struct net_device *dev;
3439 struct inet6_dev *idev;
3441 read_lock(&dev_base_lock);
3442 for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) {
3445 if ((idev = in6_dev_get(dev)) == NULL)
3447 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
3448 cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI);
3453 read_unlock(&dev_base_lock);
3459 void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
3461 struct sk_buff *skb;
3464 skb = nlmsg_new(inet6_if_nlmsg_size(), GFP_ATOMIC);
3468 err = inet6_fill_ifinfo(skb, idev, 0, 0, event, 0);
3470 /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */
3471 WARN_ON(err == -EMSGSIZE);
3475 err = rtnl_notify(skb, 0, RTNLGRP_IPV6_IFADDR, NULL, GFP_ATOMIC);
3478 rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR, err);
3481 static inline size_t inet6_prefix_nlmsg_size(void)
3483 return NLMSG_ALIGN(sizeof(struct prefixmsg))
3484 + nla_total_size(sizeof(struct in6_addr))
3485 + nla_total_size(sizeof(struct prefix_cacheinfo));
3488 static int inet6_fill_prefix(struct sk_buff *skb, struct inet6_dev *idev,
3489 struct prefix_info *pinfo, u32 pid, u32 seq,
3490 int event, unsigned int flags)
3492 struct prefixmsg *pmsg;
3493 struct nlmsghdr *nlh;
3494 struct prefix_cacheinfo ci;
3496 nlh = nlmsg_put(skb, pid, seq, event, sizeof(*pmsg), flags);
3500 pmsg = nlmsg_data(nlh);
3501 pmsg->prefix_family = AF_INET6;
3502 pmsg->prefix_pad1 = 0;
3503 pmsg->prefix_pad2 = 0;
3504 pmsg->prefix_ifindex = idev->dev->ifindex;
3505 pmsg->prefix_len = pinfo->prefix_len;
3506 pmsg->prefix_type = pinfo->type;
3507 pmsg->prefix_pad3 = 0;
3508 pmsg->prefix_flags = 0;
3510 pmsg->prefix_flags |= IF_PREFIX_ONLINK;
3511 if (pinfo->autoconf)
3512 pmsg->prefix_flags |= IF_PREFIX_AUTOCONF;
3514 NLA_PUT(skb, PREFIX_ADDRESS, sizeof(pinfo->prefix), &pinfo->prefix);
3516 ci.preferred_time = ntohl(pinfo->prefered);
3517 ci.valid_time = ntohl(pinfo->valid);
3518 NLA_PUT(skb, PREFIX_CACHEINFO, sizeof(ci), &ci);
3520 return nlmsg_end(skb, nlh);
3523 nlmsg_cancel(skb, nlh);
3527 static void inet6_prefix_notify(int event, struct inet6_dev *idev,
3528 struct prefix_info *pinfo)
3530 struct sk_buff *skb;
3533 skb = nlmsg_new(inet6_prefix_nlmsg_size(), GFP_ATOMIC);
3537 err = inet6_fill_prefix(skb, idev, pinfo, 0, 0, event, 0);
3539 /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */
3540 WARN_ON(err == -EMSGSIZE);
3544 err = rtnl_notify(skb, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC);
3547 rtnl_set_sk_err(RTNLGRP_IPV6_PREFIX, err);
3550 static struct rtnetlink_link inet6_rtnetlink_table[RTM_NR_MSGTYPES] = {
3551 [RTM_GETLINK - RTM_BASE] = { .dumpit = inet6_dump_ifinfo, },
3552 [RTM_NEWADDR - RTM_BASE] = { .doit = inet6_rtm_newaddr, },
3553 [RTM_DELADDR - RTM_BASE] = { .doit = inet6_rtm_deladdr, },
3554 [RTM_GETADDR - RTM_BASE] = { .doit = inet6_rtm_getaddr,
3555 .dumpit = inet6_dump_ifaddr, },
3556 [RTM_GETMULTICAST - RTM_BASE] = { .dumpit = inet6_dump_ifmcaddr, },
3557 [RTM_GETANYCAST - RTM_BASE] = { .dumpit = inet6_dump_ifacaddr, },
3558 [RTM_NEWROUTE - RTM_BASE] = { .doit = inet6_rtm_newroute, },
3559 [RTM_DELROUTE - RTM_BASE] = { .doit = inet6_rtm_delroute, },
3560 [RTM_GETROUTE - RTM_BASE] = { .doit = inet6_rtm_getroute,
3561 .dumpit = inet6_dump_fib, },
3562 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
3563 [RTM_GETRULE - RTM_BASE] = { .dumpit = fib6_rules_dump, },
3567 static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3569 inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
3573 ip6_ins_rt(ifp->rt);
3574 if (ifp->idev->cnf.forwarding)
3575 addrconf_join_anycast(ifp);
3578 if (ifp->idev->cnf.forwarding)
3579 addrconf_leave_anycast(ifp);
3580 addrconf_leave_solict(ifp->idev, &ifp->addr);
3581 dst_hold(&ifp->rt->u.dst);
3582 if (ip6_del_rt(ifp->rt))
3583 dst_free(&ifp->rt->u.dst);
3588 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3591 if (likely(ifp->idev->dead == 0))
3592 __ipv6_ifa_notify(event, ifp);
3593 rcu_read_unlock_bh();
3596 #ifdef CONFIG_SYSCTL
3599 int addrconf_sysctl_forward(ctl_table *ctl, int write, struct file * filp,
3600 void __user *buffer, size_t *lenp, loff_t *ppos)
3602 int *valp = ctl->data;
3606 ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
3608 if (write && valp != &ipv6_devconf_dflt.forwarding) {
3609 if (valp != &ipv6_devconf.forwarding) {
3610 if ((!*valp) ^ (!val)) {
3611 struct inet6_dev *idev = (struct inet6_dev *)ctl->extra1;
3614 dev_forward_change(idev);
3617 ipv6_devconf_dflt.forwarding = ipv6_devconf.forwarding;
3618 addrconf_forward_change();
3621 rt6_purge_dflt_routers();
3627 static int addrconf_sysctl_forward_strategy(ctl_table *table,
3628 int __user *name, int nlen,
3629 void __user *oldval,
3630 size_t __user *oldlenp,
3631 void __user *newval, size_t newlen)
3633 int *valp = table->data;
3636 if (!newval || !newlen)
3638 if (newlen != sizeof(int))
3640 if (get_user(new, (int __user *)newval))
3644 if (oldval && oldlenp) {
3646 if (get_user(len, oldlenp))
3649 if (len > table->maxlen)
3650 len = table->maxlen;
3651 if (copy_to_user(oldval, valp, len))
3653 if (put_user(len, oldlenp))
3658 if (valp != &ipv6_devconf_dflt.forwarding) {
3659 if (valp != &ipv6_devconf.forwarding) {
3660 struct inet6_dev *idev = (struct inet6_dev *)table->extra1;
3662 if (unlikely(idev == NULL))
3664 changed = (!*valp) ^ (!new);
3667 dev_forward_change(idev);
3670 addrconf_forward_change();
3674 rt6_purge_dflt_routers();
3681 static struct addrconf_sysctl_table
3683 struct ctl_table_header *sysctl_header;
3684 ctl_table addrconf_vars[__NET_IPV6_MAX];
3685 ctl_table addrconf_dev[2];
3686 ctl_table addrconf_conf_dir[2];
3687 ctl_table addrconf_proto_dir[2];
3688 ctl_table addrconf_root_dir[2];
3689 } addrconf_sysctl __read_mostly = {
3690 .sysctl_header = NULL,
3693 .ctl_name = NET_IPV6_FORWARDING,
3694 .procname = "forwarding",
3695 .data = &ipv6_devconf.forwarding,
3696 .maxlen = sizeof(int),
3698 .proc_handler = &addrconf_sysctl_forward,
3699 .strategy = &addrconf_sysctl_forward_strategy,
3702 .ctl_name = NET_IPV6_HOP_LIMIT,
3703 .procname = "hop_limit",
3704 .data = &ipv6_devconf.hop_limit,
3705 .maxlen = sizeof(int),
3707 .proc_handler = proc_dointvec,
3710 .ctl_name = NET_IPV6_MTU,
3712 .data = &ipv6_devconf.mtu6,
3713 .maxlen = sizeof(int),
3715 .proc_handler = &proc_dointvec,
3718 .ctl_name = NET_IPV6_ACCEPT_RA,
3719 .procname = "accept_ra",
3720 .data = &ipv6_devconf.accept_ra,
3721 .maxlen = sizeof(int),
3723 .proc_handler = &proc_dointvec,
3726 .ctl_name = NET_IPV6_ACCEPT_REDIRECTS,
3727 .procname = "accept_redirects",
3728 .data = &ipv6_devconf.accept_redirects,
3729 .maxlen = sizeof(int),
3731 .proc_handler = &proc_dointvec,
3734 .ctl_name = NET_IPV6_AUTOCONF,
3735 .procname = "autoconf",
3736 .data = &ipv6_devconf.autoconf,
3737 .maxlen = sizeof(int),
3739 .proc_handler = &proc_dointvec,
3742 .ctl_name = NET_IPV6_DAD_TRANSMITS,
3743 .procname = "dad_transmits",
3744 .data = &ipv6_devconf.dad_transmits,
3745 .maxlen = sizeof(int),
3747 .proc_handler = &proc_dointvec,
3750 .ctl_name = NET_IPV6_RTR_SOLICITS,
3751 .procname = "router_solicitations",
3752 .data = &ipv6_devconf.rtr_solicits,
3753 .maxlen = sizeof(int),
3755 .proc_handler = &proc_dointvec,
3758 .ctl_name = NET_IPV6_RTR_SOLICIT_INTERVAL,
3759 .procname = "router_solicitation_interval",
3760 .data = &ipv6_devconf.rtr_solicit_interval,
3761 .maxlen = sizeof(int),
3763 .proc_handler = &proc_dointvec_jiffies,
3764 .strategy = &sysctl_jiffies,
3767 .ctl_name = NET_IPV6_RTR_SOLICIT_DELAY,
3768 .procname = "router_solicitation_delay",
3769 .data = &ipv6_devconf.rtr_solicit_delay,
3770 .maxlen = sizeof(int),
3772 .proc_handler = &proc_dointvec_jiffies,
3773 .strategy = &sysctl_jiffies,
3776 .ctl_name = NET_IPV6_FORCE_MLD_VERSION,
3777 .procname = "force_mld_version",
3778 .data = &ipv6_devconf.force_mld_version,
3779 .maxlen = sizeof(int),
3781 .proc_handler = &proc_dointvec,
3783 #ifdef CONFIG_IPV6_PRIVACY
3785 .ctl_name = NET_IPV6_USE_TEMPADDR,
3786 .procname = "use_tempaddr",
3787 .data = &ipv6_devconf.use_tempaddr,
3788 .maxlen = sizeof(int),
3790 .proc_handler = &proc_dointvec,
3793 .ctl_name = NET_IPV6_TEMP_VALID_LFT,
3794 .procname = "temp_valid_lft",
3795 .data = &ipv6_devconf.temp_valid_lft,
3796 .maxlen = sizeof(int),
3798 .proc_handler = &proc_dointvec,
3801 .ctl_name = NET_IPV6_TEMP_PREFERED_LFT,
3802 .procname = "temp_prefered_lft",
3803 .data = &ipv6_devconf.temp_prefered_lft,
3804 .maxlen = sizeof(int),
3806 .proc_handler = &proc_dointvec,
3809 .ctl_name = NET_IPV6_REGEN_MAX_RETRY,
3810 .procname = "regen_max_retry",
3811 .data = &ipv6_devconf.regen_max_retry,
3812 .maxlen = sizeof(int),
3814 .proc_handler = &proc_dointvec,
3817 .ctl_name = NET_IPV6_MAX_DESYNC_FACTOR,
3818 .procname = "max_desync_factor",
3819 .data = &ipv6_devconf.max_desync_factor,
3820 .maxlen = sizeof(int),
3822 .proc_handler = &proc_dointvec,
3826 .ctl_name = NET_IPV6_MAX_ADDRESSES,
3827 .procname = "max_addresses",
3828 .data = &ipv6_devconf.max_addresses,
3829 .maxlen = sizeof(int),
3831 .proc_handler = &proc_dointvec,
3834 .ctl_name = NET_IPV6_ACCEPT_RA_DEFRTR,
3835 .procname = "accept_ra_defrtr",
3836 .data = &ipv6_devconf.accept_ra_defrtr,
3837 .maxlen = sizeof(int),
3839 .proc_handler = &proc_dointvec,
3842 .ctl_name = NET_IPV6_ACCEPT_RA_PINFO,
3843 .procname = "accept_ra_pinfo",
3844 .data = &ipv6_devconf.accept_ra_pinfo,
3845 .maxlen = sizeof(int),
3847 .proc_handler = &proc_dointvec,
3849 #ifdef CONFIG_IPV6_ROUTER_PREF
3851 .ctl_name = NET_IPV6_ACCEPT_RA_RTR_PREF,
3852 .procname = "accept_ra_rtr_pref",
3853 .data = &ipv6_devconf.accept_ra_rtr_pref,
3854 .maxlen = sizeof(int),
3856 .proc_handler = &proc_dointvec,
3859 .ctl_name = NET_IPV6_RTR_PROBE_INTERVAL,
3860 .procname = "router_probe_interval",
3861 .data = &ipv6_devconf.rtr_probe_interval,
3862 .maxlen = sizeof(int),
3864 .proc_handler = &proc_dointvec_jiffies,
3865 .strategy = &sysctl_jiffies,
3867 #ifdef CONFIG_IPV6_ROUTE_INFO
3869 .ctl_name = NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN,
3870 .procname = "accept_ra_rt_info_max_plen",
3871 .data = &ipv6_devconf.accept_ra_rt_info_max_plen,
3872 .maxlen = sizeof(int),
3874 .proc_handler = &proc_dointvec,
3879 .ctl_name = NET_IPV6_PROXY_NDP,
3880 .procname = "proxy_ndp",
3881 .data = &ipv6_devconf.proxy_ndp,
3882 .maxlen = sizeof(int),
3884 .proc_handler = &proc_dointvec,
3887 .ctl_name = 0, /* sentinel */
3892 .ctl_name = NET_PROTO_CONF_ALL,
3895 .child = addrconf_sysctl.addrconf_vars,
3898 .ctl_name = 0, /* sentinel */
3901 .addrconf_conf_dir = {
3903 .ctl_name = NET_IPV6_CONF,
3906 .child = addrconf_sysctl.addrconf_dev,
3909 .ctl_name = 0, /* sentinel */
3912 .addrconf_proto_dir = {
3914 .ctl_name = NET_IPV6,
3917 .child = addrconf_sysctl.addrconf_conf_dir,
3920 .ctl_name = 0, /* sentinel */
3923 .addrconf_root_dir = {
3925 .ctl_name = CTL_NET,
3928 .child = addrconf_sysctl.addrconf_proto_dir,
3931 .ctl_name = 0, /* sentinel */
3936 static void addrconf_sysctl_register(struct inet6_dev *idev, struct ipv6_devconf *p)
3939 struct net_device *dev = idev ? idev->dev : NULL;
3940 struct addrconf_sysctl_table *t;
3941 char *dev_name = NULL;
3943 t = kmemdup(&addrconf_sysctl, sizeof(*t), GFP_KERNEL);
3946 for (i=0; t->addrconf_vars[i].data; i++) {
3947 t->addrconf_vars[i].data += (char*)p - (char*)&ipv6_devconf;
3948 t->addrconf_vars[i].extra1 = idev; /* embedded; no ref */
3951 dev_name = dev->name;
3952 t->addrconf_dev[0].ctl_name = dev->ifindex;
3954 dev_name = "default";
3955 t->addrconf_dev[0].ctl_name = NET_PROTO_CONF_DEFAULT;
3959 * Make a copy of dev_name, because '.procname' is regarded as const
3960 * by sysctl and we wouldn't want anyone to change it under our feet
3961 * (see SIOCSIFNAME).
3963 dev_name = kstrdup(dev_name, GFP_KERNEL);
3967 t->addrconf_dev[0].procname = dev_name;
3969 t->addrconf_dev[0].child = t->addrconf_vars;
3970 t->addrconf_conf_dir[0].child = t->addrconf_dev;
3971 t->addrconf_proto_dir[0].child = t->addrconf_conf_dir;
3972 t->addrconf_root_dir[0].child = t->addrconf_proto_dir;
3974 t->sysctl_header = register_sysctl_table(t->addrconf_root_dir);
3975 if (t->sysctl_header == NULL)
3990 static void addrconf_sysctl_unregister(struct ipv6_devconf *p)
3993 struct addrconf_sysctl_table *t = p->sysctl;
3995 unregister_sysctl_table(t->sysctl_header);
3996 kfree(t->addrconf_dev[0].procname);
4008 int register_inet6addr_notifier(struct notifier_block *nb)
4010 return atomic_notifier_chain_register(&inet6addr_chain, nb);
4013 int unregister_inet6addr_notifier(struct notifier_block *nb)
4015 return atomic_notifier_chain_unregister(&inet6addr_chain,nb);
4019 * Init / cleanup code
4022 int __init addrconf_init(void)
4026 /* The addrconf netdev notifier requires that loopback_dev
4027 * has it's ipv6 private information allocated and setup
4028 * before it can bring up and give link-local addresses
4029 * to other devices which are up.
4031 * Unfortunately, loopback_dev is not necessarily the first
4032 * entry in the global dev_base list of net devices. In fact,
4033 * it is likely to be the very last entry on that list.
4034 * So this causes the notifier registry below to try and
4035 * give link-local addresses to all devices besides loopback_dev
4036 * first, then loopback_dev, which cases all the non-loopback_dev
4037 * devices to fail to get a link-local address.
4039 * So, as a temporary fix, allocate the ipv6 structure for
4040 * loopback_dev first by hand.
4041 * Longer term, all of the dependencies ipv6 has upon the loopback
4042 * device and it being up should be removed.
4045 if (!ipv6_add_dev(&loopback_dev))
4051 ip6_null_entry.rt6i_idev = in6_dev_get(&loopback_dev);
4053 register_netdevice_notifier(&ipv6_dev_notf);
4056 rtnetlink_links[PF_INET6] = inet6_rtnetlink_table;
4057 #ifdef CONFIG_SYSCTL
4058 addrconf_sysctl.sysctl_header =
4059 register_sysctl_table(addrconf_sysctl.addrconf_root_dir);
4060 addrconf_sysctl_register(NULL, &ipv6_devconf_dflt);
4066 void __exit addrconf_cleanup(void)
4068 struct net_device *dev;
4069 struct inet6_dev *idev;
4070 struct inet6_ifaddr *ifa;
4073 unregister_netdevice_notifier(&ipv6_dev_notf);
4075 rtnetlink_links[PF_INET6] = NULL;
4076 #ifdef CONFIG_SYSCTL
4077 addrconf_sysctl_unregister(&ipv6_devconf_dflt);
4078 addrconf_sysctl_unregister(&ipv6_devconf);
4087 for (dev=dev_base; dev; dev=dev->next) {
4088 if ((idev = __in6_dev_get(dev)) == NULL)
4090 addrconf_ifdown(dev, 1);
4092 addrconf_ifdown(&loopback_dev, 2);
4098 write_lock_bh(&addrconf_hash_lock);
4099 for (i=0; i < IN6_ADDR_HSIZE; i++) {
4100 for (ifa=inet6_addr_lst[i]; ifa; ) {
4101 struct inet6_ifaddr *bifa;
4104 ifa = ifa->lst_next;
4105 printk(KERN_DEBUG "bug: IPv6 address leakage detected: ifa=%p\n", bifa);
4106 /* Do not free it; something is wrong.
4107 Now we can investigate it with debugger.
4111 write_unlock_bh(&addrconf_hash_lock);
4113 del_timer(&addr_chk_timer);
4117 #ifdef CONFIG_PROC_FS
4118 proc_net_remove("if_inet6");