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/sched.h>
48 #include <linux/net.h>
49 #include <linux/in6.h>
50 #include <linux/netdevice.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 <linux/if_tunnel.h>
76 #include <linux/rtnetlink.h>
78 #ifdef CONFIG_IPV6_PRIVACY
79 #include <linux/random.h>
82 #include <asm/uaccess.h>
84 #include <linux/proc_fs.h>
85 #include <linux/seq_file.h>
87 /* Set to 3 to get tracing... */
91 #define ADBG(x) printk x
96 #define INFINITY_LIFE_TIME 0xFFFFFFFF
97 #define TIME_DELTA(a,b) ((unsigned long)((long)(a) - (long)(b)))
100 static void addrconf_sysctl_register(struct inet6_dev *idev, struct ipv6_devconf *p);
101 static void addrconf_sysctl_unregister(struct ipv6_devconf *p);
104 #ifdef CONFIG_IPV6_PRIVACY
105 static int __ipv6_regen_rndid(struct inet6_dev *idev);
106 static int __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr);
107 static void ipv6_regen_rndid(unsigned long data);
109 static int desync_factor = MAX_DESYNC_FACTOR * HZ;
112 static int ipv6_count_addresses(struct inet6_dev *idev);
115 * Configured unicast address hash table
117 static struct inet6_ifaddr *inet6_addr_lst[IN6_ADDR_HSIZE];
118 static DEFINE_RWLOCK(addrconf_hash_lock);
120 /* Protects inet6 devices */
121 DEFINE_RWLOCK(addrconf_lock);
123 static void addrconf_verify(unsigned long);
125 static DEFINE_TIMER(addr_chk_timer, addrconf_verify, 0, 0);
126 static DEFINE_SPINLOCK(addrconf_verify_lock);
128 static void addrconf_join_anycast(struct inet6_ifaddr *ifp);
129 static void addrconf_leave_anycast(struct inet6_ifaddr *ifp);
131 static int addrconf_ifdown(struct net_device *dev, int how);
133 static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags);
134 static void addrconf_dad_timer(unsigned long data);
135 static void addrconf_dad_completed(struct inet6_ifaddr *ifp);
136 static void addrconf_dad_run(struct inet6_dev *idev);
137 static void addrconf_rs_timer(unsigned long data);
138 static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
139 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
141 static void inet6_prefix_notify(int event, struct inet6_dev *idev,
142 struct prefix_info *pinfo);
143 static int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *dev);
145 static ATOMIC_NOTIFIER_HEAD(inet6addr_chain);
147 struct ipv6_devconf ipv6_devconf = {
149 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
150 .mtu6 = IPV6_MIN_MTU,
152 .accept_redirects = 1,
154 .force_mld_version = 0,
156 .rtr_solicits = MAX_RTR_SOLICITATIONS,
157 .rtr_solicit_interval = RTR_SOLICITATION_INTERVAL,
158 .rtr_solicit_delay = MAX_RTR_SOLICITATION_DELAY,
159 #ifdef CONFIG_IPV6_PRIVACY
161 .temp_valid_lft = TEMP_VALID_LIFETIME,
162 .temp_prefered_lft = TEMP_PREFERRED_LIFETIME,
163 .regen_max_retry = REGEN_MAX_RETRY,
164 .max_desync_factor = MAX_DESYNC_FACTOR,
166 .max_addresses = IPV6_MAX_ADDRESSES,
167 .accept_ra_defrtr = 1,
168 .accept_ra_pinfo = 1,
169 #ifdef CONFIG_IPV6_ROUTER_PREF
170 .accept_ra_rtr_pref = 1,
171 .rtr_probe_interval = 60 * HZ,
172 #ifdef CONFIG_IPV6_ROUTE_INFO
173 .accept_ra_rt_info_max_plen = 0,
178 static struct ipv6_devconf ipv6_devconf_dflt = {
180 .hop_limit = IPV6_DEFAULT_HOPLIMIT,
181 .mtu6 = IPV6_MIN_MTU,
183 .accept_redirects = 1,
186 .rtr_solicits = MAX_RTR_SOLICITATIONS,
187 .rtr_solicit_interval = RTR_SOLICITATION_INTERVAL,
188 .rtr_solicit_delay = MAX_RTR_SOLICITATION_DELAY,
189 #ifdef CONFIG_IPV6_PRIVACY
191 .temp_valid_lft = TEMP_VALID_LIFETIME,
192 .temp_prefered_lft = TEMP_PREFERRED_LIFETIME,
193 .regen_max_retry = REGEN_MAX_RETRY,
194 .max_desync_factor = MAX_DESYNC_FACTOR,
196 .max_addresses = IPV6_MAX_ADDRESSES,
197 .accept_ra_defrtr = 1,
198 .accept_ra_pinfo = 1,
199 #ifdef CONFIG_IPV6_ROUTER_PREF
200 .accept_ra_rtr_pref = 1,
201 .rtr_probe_interval = 60 * HZ,
202 #ifdef CONFIG_IPV6_ROUTE_INFO
203 .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 #define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
216 static inline unsigned ipv6_addr_scope2type(unsigned scope)
219 case IPV6_ADDR_SCOPE_NODELOCAL:
220 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_NODELOCAL) |
222 case IPV6_ADDR_SCOPE_LINKLOCAL:
223 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL) |
224 IPV6_ADDR_LINKLOCAL);
225 case IPV6_ADDR_SCOPE_SITELOCAL:
226 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL) |
227 IPV6_ADDR_SITELOCAL);
229 return IPV6_ADDR_SCOPE_TYPE(scope);
232 int __ipv6_addr_type(const struct in6_addr *addr)
236 st = addr->s6_addr32[0];
238 /* Consider all addresses with the first three bits different of
239 000 and 111 as unicasts.
241 if ((st & htonl(0xE0000000)) != htonl(0x00000000) &&
242 (st & htonl(0xE0000000)) != htonl(0xE0000000))
243 return (IPV6_ADDR_UNICAST |
244 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL));
246 if ((st & htonl(0xFF000000)) == htonl(0xFF000000)) {
248 /* addr-select 3.1 */
249 return (IPV6_ADDR_MULTICAST |
250 ipv6_addr_scope2type(IPV6_ADDR_MC_SCOPE(addr)));
253 if ((st & htonl(0xFFC00000)) == htonl(0xFE800000))
254 return (IPV6_ADDR_LINKLOCAL | IPV6_ADDR_UNICAST |
255 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL)); /* addr-select 3.1 */
256 if ((st & htonl(0xFFC00000)) == htonl(0xFEC00000))
257 return (IPV6_ADDR_SITELOCAL | IPV6_ADDR_UNICAST |
258 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL)); /* addr-select 3.1 */
260 if ((addr->s6_addr32[0] | addr->s6_addr32[1]) == 0) {
261 if (addr->s6_addr32[2] == 0) {
262 if (addr->s6_addr32[3] == 0)
263 return IPV6_ADDR_ANY;
265 if (addr->s6_addr32[3] == htonl(0x00000001))
266 return (IPV6_ADDR_LOOPBACK | IPV6_ADDR_UNICAST |
267 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL)); /* addr-select 3.4 */
269 return (IPV6_ADDR_COMPATv4 | IPV6_ADDR_UNICAST |
270 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL)); /* addr-select 3.3 */
273 if (addr->s6_addr32[2] == htonl(0x0000ffff))
274 return (IPV6_ADDR_MAPPED |
275 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL)); /* addr-select 3.3 */
278 return (IPV6_ADDR_RESERVED |
279 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL)); /* addr-select 3.4 */
282 static void addrconf_del_timer(struct inet6_ifaddr *ifp)
284 if (del_timer(&ifp->timer))
288 enum addrconf_timer_t
295 static void addrconf_mod_timer(struct inet6_ifaddr *ifp,
296 enum addrconf_timer_t what,
299 if (!del_timer(&ifp->timer))
304 ifp->timer.function = addrconf_dad_timer;
307 ifp->timer.function = addrconf_rs_timer;
311 ifp->timer.expires = jiffies + when;
312 add_timer(&ifp->timer);
315 /* Nobody refers to this device, we may destroy it. */
317 void in6_dev_finish_destroy(struct inet6_dev *idev)
319 struct net_device *dev = idev->dev;
320 BUG_TRAP(idev->addr_list==NULL);
321 BUG_TRAP(idev->mc_list==NULL);
322 #ifdef NET_REFCNT_DEBUG
323 printk(KERN_DEBUG "in6_dev_finish_destroy: %s\n", dev ? dev->name : "NIL");
327 printk("Freeing alive inet6 device %p\n", idev);
330 snmp6_free_dev(idev);
334 static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
336 struct inet6_dev *ndev;
340 if (dev->mtu < IPV6_MIN_MTU)
343 ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL);
348 rwlock_init(&ndev->lock);
350 memcpy(&ndev->cnf, &ipv6_devconf_dflt, sizeof(ndev->cnf));
351 ndev->cnf.mtu6 = dev->mtu;
352 ndev->cnf.sysctl = NULL;
353 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
354 if (ndev->nd_parms == NULL) {
358 /* We refer to the device */
361 if (snmp6_alloc_dev(ndev) < 0) {
363 "%s(): cannot allocate memory for statistics; dev=%s.\n",
364 __FUNCTION__, dev->name));
365 neigh_parms_release(&nd_tbl, ndev->nd_parms);
367 in6_dev_finish_destroy(ndev);
371 if (snmp6_register_dev(ndev) < 0) {
373 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
374 __FUNCTION__, dev->name));
375 neigh_parms_release(&nd_tbl, ndev->nd_parms);
377 in6_dev_finish_destroy(ndev);
381 /* One reference from device. We must do this before
382 * we invoke __ipv6_regen_rndid().
386 #ifdef CONFIG_IPV6_PRIVACY
387 init_timer(&ndev->regen_timer);
388 ndev->regen_timer.function = ipv6_regen_rndid;
389 ndev->regen_timer.data = (unsigned long) ndev;
390 if ((dev->flags&IFF_LOOPBACK) ||
391 dev->type == ARPHRD_TUNNEL ||
392 dev->type == ARPHRD_NONE ||
393 dev->type == ARPHRD_SIT) {
395 "%s: Disabled Privacy Extensions\n",
397 ndev->cnf.use_tempaddr = -1;
400 ipv6_regen_rndid((unsigned long) ndev);
404 if (netif_carrier_ok(dev))
405 ndev->if_flags |= IF_READY;
407 write_lock_bh(&addrconf_lock);
409 write_unlock_bh(&addrconf_lock);
411 ipv6_mc_init_dev(ndev);
412 ndev->tstamp = jiffies;
414 neigh_sysctl_register(dev, ndev->nd_parms, NET_IPV6,
415 NET_IPV6_NEIGH, "ipv6",
416 &ndisc_ifinfo_sysctl_change,
418 addrconf_sysctl_register(ndev, &ndev->cnf);
423 static struct inet6_dev * ipv6_find_idev(struct net_device *dev)
425 struct inet6_dev *idev;
429 if ((idev = __in6_dev_get(dev)) == NULL) {
430 if ((idev = ipv6_add_dev(dev)) == NULL)
434 if (dev->flags&IFF_UP)
440 static void dev_forward_change(struct inet6_dev *idev)
442 struct net_device *dev;
443 struct inet6_ifaddr *ifa;
444 struct in6_addr addr;
449 if (dev && (dev->flags & IFF_MULTICAST)) {
450 ipv6_addr_all_routers(&addr);
452 if (idev->cnf.forwarding)
453 ipv6_dev_mc_inc(dev, &addr);
455 ipv6_dev_mc_dec(dev, &addr);
457 for (ifa=idev->addr_list; ifa; ifa=ifa->if_next) {
458 if (idev->cnf.forwarding)
459 addrconf_join_anycast(ifa);
461 addrconf_leave_anycast(ifa);
466 static void addrconf_forward_change(void)
468 struct net_device *dev;
469 struct inet6_dev *idev;
471 read_lock(&dev_base_lock);
472 for (dev=dev_base; dev; dev=dev->next) {
473 read_lock(&addrconf_lock);
474 idev = __in6_dev_get(dev);
476 int changed = (!idev->cnf.forwarding) ^ (!ipv6_devconf.forwarding);
477 idev->cnf.forwarding = ipv6_devconf.forwarding;
479 dev_forward_change(idev);
481 read_unlock(&addrconf_lock);
483 read_unlock(&dev_base_lock);
487 /* Nobody refers to this ifaddr, destroy it */
489 void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
491 BUG_TRAP(ifp->if_next==NULL);
492 BUG_TRAP(ifp->lst_next==NULL);
493 #ifdef NET_REFCNT_DEBUG
494 printk(KERN_DEBUG "inet6_ifa_finish_destroy\n");
497 in6_dev_put(ifp->idev);
499 if (del_timer(&ifp->timer))
500 printk("Timer is still running, when freeing ifa=%p\n", ifp);
503 printk("Freeing alive inet6 address %p\n", ifp);
506 dst_release(&ifp->rt->u.dst);
511 /* On success it returns ifp with increased reference count */
513 static struct inet6_ifaddr *
514 ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, int pfxlen,
515 int scope, u32 flags)
517 struct inet6_ifaddr *ifa = NULL;
522 read_lock_bh(&addrconf_lock);
524 err = -ENODEV; /*XXX*/
528 write_lock(&addrconf_hash_lock);
530 /* Ignore adding duplicate addresses on an interface */
531 if (ipv6_chk_same_addr(addr, idev->dev)) {
532 ADBG(("ipv6_add_addr: already assigned\n"));
537 ifa = kzalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC);
540 ADBG(("ipv6_add_addr: malloc failed\n"));
545 rt = addrconf_dst_alloc(idev, addr, 0);
551 ipv6_addr_copy(&ifa->addr, addr);
553 spin_lock_init(&ifa->lock);
554 init_timer(&ifa->timer);
555 ifa->timer.data = (unsigned long) ifa;
557 ifa->prefix_len = pfxlen;
558 ifa->flags = flags | IFA_F_TENTATIVE;
559 ifa->cstamp = ifa->tstamp = jiffies;
566 /* Add to big hash table */
567 hash = ipv6_addr_hash(addr);
569 ifa->lst_next = inet6_addr_lst[hash];
570 inet6_addr_lst[hash] = ifa;
572 write_unlock(&addrconf_hash_lock);
574 write_lock(&idev->lock);
575 /* Add to inet6_dev unicast addr list. */
576 ifa->if_next = idev->addr_list;
577 idev->addr_list = ifa;
579 #ifdef CONFIG_IPV6_PRIVACY
580 if (ifa->flags&IFA_F_TEMPORARY) {
581 ifa->tmp_next = idev->tempaddr_list;
582 idev->tempaddr_list = ifa;
590 write_unlock(&idev->lock);
592 read_unlock_bh(&addrconf_lock);
594 if (likely(err == 0))
595 atomic_notifier_call_chain(&inet6addr_chain, NETDEV_UP, ifa);
603 write_unlock(&addrconf_hash_lock);
607 /* This function wants to get referenced ifp and releases it before return */
609 static void ipv6_del_addr(struct inet6_ifaddr *ifp)
611 struct inet6_ifaddr *ifa, **ifap;
612 struct inet6_dev *idev = ifp->idev;
614 int deleted = 0, onlink = 0;
615 unsigned long expires = jiffies;
617 hash = ipv6_addr_hash(&ifp->addr);
621 write_lock_bh(&addrconf_hash_lock);
622 for (ifap = &inet6_addr_lst[hash]; (ifa=*ifap) != NULL;
623 ifap = &ifa->lst_next) {
625 *ifap = ifa->lst_next;
627 ifa->lst_next = NULL;
631 write_unlock_bh(&addrconf_hash_lock);
633 write_lock_bh(&idev->lock);
634 #ifdef CONFIG_IPV6_PRIVACY
635 if (ifp->flags&IFA_F_TEMPORARY) {
636 for (ifap = &idev->tempaddr_list; (ifa=*ifap) != NULL;
637 ifap = &ifa->tmp_next) {
639 *ifap = ifa->tmp_next;
641 in6_ifa_put(ifp->ifpub);
645 ifa->tmp_next = NULL;
652 for (ifap = &idev->addr_list; (ifa=*ifap) != NULL;) {
654 *ifap = ifa->if_next;
657 if (!(ifp->flags & IFA_F_PERMANENT) || onlink > 0)
661 } else if (ifp->flags & IFA_F_PERMANENT) {
662 if (ipv6_prefix_equal(&ifa->addr, &ifp->addr,
664 if (ifa->flags & IFA_F_PERMANENT) {
669 unsigned long lifetime;
674 spin_lock(&ifa->lock);
675 lifetime = min_t(unsigned long,
676 ifa->valid_lft, 0x7fffffffUL/HZ);
677 if (time_before(expires,
678 ifa->tstamp + lifetime * HZ))
679 expires = ifa->tstamp + lifetime * HZ;
680 spin_unlock(&ifa->lock);
684 ifap = &ifa->if_next;
686 write_unlock_bh(&idev->lock);
688 ipv6_ifa_notify(RTM_DELADDR, ifp);
690 atomic_notifier_call_chain(&inet6addr_chain, NETDEV_DOWN, ifp);
692 addrconf_del_timer(ifp);
695 * Purge or update corresponding prefix
697 * 1) we don't purge prefix here if address was not permanent.
698 * prefix is managed by its own lifetime.
699 * 2) if there're no addresses, delete prefix.
700 * 3) if there're still other permanent address(es),
701 * corresponding prefix is still permanent.
702 * 4) otherwise, update prefix lifetime to the
703 * longest valid lifetime among the corresponding
704 * addresses on the device.
705 * Note: subsequent RA will update lifetime.
709 if ((ifp->flags & IFA_F_PERMANENT) && onlink < 1) {
710 struct in6_addr prefix;
713 ipv6_addr_prefix(&prefix, &ifp->addr, ifp->prefix_len);
714 rt = rt6_lookup(&prefix, NULL, ifp->idev->dev->ifindex, 1);
716 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
718 ip6_del_rt(rt, NULL, NULL, NULL);
720 } else if (!(rt->rt6i_flags & RTF_EXPIRES)) {
721 rt->rt6i_expires = expires;
722 rt->rt6i_flags |= RTF_EXPIRES;
725 dst_release(&rt->u.dst);
731 #ifdef CONFIG_IPV6_PRIVACY
732 static int ipv6_create_tempaddr(struct inet6_ifaddr *ifp, struct inet6_ifaddr *ift)
734 struct inet6_dev *idev = ifp->idev;
735 struct in6_addr addr, *tmpaddr;
736 unsigned long tmp_prefered_lft, tmp_valid_lft, tmp_cstamp, tmp_tstamp;
741 write_lock(&idev->lock);
743 spin_lock_bh(&ift->lock);
744 memcpy(&addr.s6_addr[8], &ift->addr.s6_addr[8], 8);
745 spin_unlock_bh(&ift->lock);
752 if (idev->cnf.use_tempaddr <= 0) {
753 write_unlock(&idev->lock);
755 "ipv6_create_tempaddr(): use_tempaddr is disabled.\n");
760 spin_lock_bh(&ifp->lock);
761 if (ifp->regen_count++ >= idev->cnf.regen_max_retry) {
762 idev->cnf.use_tempaddr = -1; /*XXX*/
763 spin_unlock_bh(&ifp->lock);
764 write_unlock(&idev->lock);
766 "ipv6_create_tempaddr(): regeneration time exceeded. disabled temporary address support.\n");
772 memcpy(addr.s6_addr, ifp->addr.s6_addr, 8);
773 if (__ipv6_try_regen_rndid(idev, tmpaddr) < 0) {
774 spin_unlock_bh(&ifp->lock);
775 write_unlock(&idev->lock);
777 "ipv6_create_tempaddr(): regeneration of randomized interface id failed.\n");
783 memcpy(&addr.s6_addr[8], idev->rndid, 8);
784 tmp_valid_lft = min_t(__u32,
786 idev->cnf.temp_valid_lft);
787 tmp_prefered_lft = min_t(__u32,
789 idev->cnf.temp_prefered_lft - desync_factor / HZ);
790 tmp_plen = ifp->prefix_len;
791 max_addresses = idev->cnf.max_addresses;
792 tmp_cstamp = ifp->cstamp;
793 tmp_tstamp = ifp->tstamp;
794 spin_unlock_bh(&ifp->lock);
796 write_unlock(&idev->lock);
797 ift = !max_addresses ||
798 ipv6_count_addresses(idev) < max_addresses ?
799 ipv6_add_addr(idev, &addr, tmp_plen,
800 ipv6_addr_type(&addr)&IPV6_ADDR_SCOPE_MASK, IFA_F_TEMPORARY) : NULL;
801 if (!ift || IS_ERR(ift)) {
805 "ipv6_create_tempaddr(): retry temporary address regeneration.\n");
807 write_lock(&idev->lock);
811 spin_lock_bh(&ift->lock);
813 ift->valid_lft = tmp_valid_lft;
814 ift->prefered_lft = tmp_prefered_lft;
815 ift->cstamp = tmp_cstamp;
816 ift->tstamp = tmp_tstamp;
817 spin_unlock_bh(&ift->lock);
819 addrconf_dad_start(ift, 0);
828 * Choose an appropriate source address (RFC3484)
830 struct ipv6_saddr_score {
838 #define IPV6_SADDR_SCORE_LOCAL 0x0001
839 #define IPV6_SADDR_SCORE_PREFERRED 0x0004
840 #define IPV6_SADDR_SCORE_HOA 0x0008
841 #define IPV6_SADDR_SCORE_OIF 0x0010
842 #define IPV6_SADDR_SCORE_LABEL 0x0020
843 #define IPV6_SADDR_SCORE_PRIVACY 0x0040
845 static int inline ipv6_saddr_preferred(int type)
847 if (type & (IPV6_ADDR_MAPPED|IPV6_ADDR_COMPATv4|
848 IPV6_ADDR_LOOPBACK|IPV6_ADDR_RESERVED))
853 /* static matching label */
854 static int inline ipv6_saddr_label(const struct in6_addr *addr, int type)
857 * prefix (longest match) label
858 * -----------------------------
867 if (type & IPV6_ADDR_LOOPBACK)
869 else if (type & IPV6_ADDR_COMPATv4)
871 else if (type & IPV6_ADDR_MAPPED)
873 else if (addr->s6_addr32[0] == htonl(0x20010000))
875 else if (addr->s6_addr16[0] == htons(0x2002))
877 else if ((addr->s6_addr[0] & 0xfe) == 0xfc)
882 int ipv6_dev_get_saddr(struct net_device *daddr_dev,
883 struct in6_addr *daddr, struct in6_addr *saddr)
885 struct ipv6_saddr_score hiscore;
886 struct inet6_ifaddr *ifa_result = NULL;
887 int daddr_type = __ipv6_addr_type(daddr);
888 int daddr_scope = __ipv6_addr_src_scope(daddr_type);
889 u32 daddr_label = ipv6_saddr_label(daddr, daddr_type);
890 struct net_device *dev;
892 memset(&hiscore, 0, sizeof(hiscore));
894 read_lock(&dev_base_lock);
895 read_lock(&addrconf_lock);
897 for (dev = dev_base; dev; dev=dev->next) {
898 struct inet6_dev *idev;
899 struct inet6_ifaddr *ifa;
901 /* Rule 0: Candidate Source Address (section 4)
902 * - multicast and link-local destination address,
903 * the set of candidate source address MUST only
904 * include addresses assigned to interfaces
905 * belonging to the same link as the outgoing
907 * (- For site-local destination addresses, the
908 * set of candidate source addresses MUST only
909 * include addresses assigned to interfaces
910 * belonging to the same site as the outgoing
913 if ((daddr_type & IPV6_ADDR_MULTICAST ||
914 daddr_scope <= IPV6_ADDR_SCOPE_LINKLOCAL) &&
915 daddr_dev && dev != daddr_dev)
918 idev = __in6_dev_get(dev);
922 read_lock_bh(&idev->lock);
923 for (ifa = idev->addr_list; ifa; ifa = ifa->if_next) {
924 struct ipv6_saddr_score score;
926 score.addr_type = __ipv6_addr_type(&ifa->addr);
929 * - Tentative Address (RFC2462 section 5.4)
930 * - A tentative address is not considered
931 * "assigned to an interface" in the traditional
933 * - Candidate Source Address (section 4)
934 * - In any case, anycast addresses, multicast
935 * addresses, and the unspecified address MUST
936 * NOT be included in a candidate set.
938 if (ifa->flags & IFA_F_TENTATIVE)
940 if (unlikely(score.addr_type == IPV6_ADDR_ANY ||
941 score.addr_type & IPV6_ADDR_MULTICAST)) {
942 LIMIT_NETDEBUG(KERN_DEBUG
943 "ADDRCONF: unspecified / multicast address"
944 "assigned as unicast address on %s",
954 if (ifa_result == NULL) {
955 /* record it if the first available entry */
959 /* Rule 1: Prefer same address */
960 if (hiscore.rule < 1) {
961 if (ipv6_addr_equal(&ifa_result->addr, daddr))
962 hiscore.attrs |= IPV6_SADDR_SCORE_LOCAL;
965 if (ipv6_addr_equal(&ifa->addr, daddr)) {
966 score.attrs |= IPV6_SADDR_SCORE_LOCAL;
967 if (!(hiscore.attrs & IPV6_SADDR_SCORE_LOCAL)) {
972 if (hiscore.attrs & IPV6_SADDR_SCORE_LOCAL)
976 /* Rule 2: Prefer appropriate scope */
977 if (hiscore.rule < 2) {
978 hiscore.scope = __ipv6_addr_src_scope(hiscore.addr_type);
981 score.scope = __ipv6_addr_src_scope(score.addr_type);
982 if (hiscore.scope < score.scope) {
983 if (hiscore.scope < daddr_scope) {
988 } else if (score.scope < hiscore.scope) {
989 if (score.scope < daddr_scope)
997 /* Rule 3: Avoid deprecated address */
998 if (hiscore.rule < 3) {
999 if (ipv6_saddr_preferred(hiscore.addr_type) ||
1000 !(ifa_result->flags & IFA_F_DEPRECATED))
1001 hiscore.attrs |= IPV6_SADDR_SCORE_PREFERRED;
1004 if (ipv6_saddr_preferred(score.addr_type) ||
1005 !(ifa->flags & IFA_F_DEPRECATED)) {
1006 score.attrs |= IPV6_SADDR_SCORE_PREFERRED;
1007 if (!(hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED)) {
1012 if (hiscore.attrs & IPV6_SADDR_SCORE_PREFERRED)
1016 /* Rule 4: Prefer home address -- not implemented yet */
1017 if (hiscore.rule < 4)
1020 /* Rule 5: Prefer outgoing interface */
1021 if (hiscore.rule < 5) {
1022 if (daddr_dev == NULL ||
1023 daddr_dev == ifa_result->idev->dev)
1024 hiscore.attrs |= IPV6_SADDR_SCORE_OIF;
1027 if (daddr_dev == NULL ||
1028 daddr_dev == ifa->idev->dev) {
1029 score.attrs |= IPV6_SADDR_SCORE_OIF;
1030 if (!(hiscore.attrs & IPV6_SADDR_SCORE_OIF)) {
1035 if (hiscore.attrs & IPV6_SADDR_SCORE_OIF)
1039 /* Rule 6: Prefer matching label */
1040 if (hiscore.rule < 6) {
1041 if (ipv6_saddr_label(&ifa_result->addr, hiscore.addr_type) == daddr_label)
1042 hiscore.attrs |= IPV6_SADDR_SCORE_LABEL;
1045 if (ipv6_saddr_label(&ifa->addr, score.addr_type) == daddr_label) {
1046 score.attrs |= IPV6_SADDR_SCORE_LABEL;
1047 if (!(hiscore.attrs & IPV6_SADDR_SCORE_LABEL)) {
1052 if (hiscore.attrs & IPV6_SADDR_SCORE_LABEL)
1056 #ifdef CONFIG_IPV6_PRIVACY
1057 /* Rule 7: Prefer public address
1058 * Note: prefer temprary address if use_tempaddr >= 2
1060 if (hiscore.rule < 7) {
1061 if ((!(ifa_result->flags & IFA_F_TEMPORARY)) ^
1062 (ifa_result->idev->cnf.use_tempaddr >= 2))
1063 hiscore.attrs |= IPV6_SADDR_SCORE_PRIVACY;
1066 if ((!(ifa->flags & IFA_F_TEMPORARY)) ^
1067 (ifa->idev->cnf.use_tempaddr >= 2)) {
1068 score.attrs |= IPV6_SADDR_SCORE_PRIVACY;
1069 if (!(hiscore.attrs & IPV6_SADDR_SCORE_PRIVACY)) {
1074 if (hiscore.attrs & IPV6_SADDR_SCORE_PRIVACY)
1078 if (hiscore.rule < 7)
1081 /* Rule 8: Use longest matching prefix */
1082 if (hiscore.rule < 8) {
1083 hiscore.matchlen = ipv6_addr_diff(&ifa_result->addr, daddr);
1086 score.matchlen = ipv6_addr_diff(&ifa->addr, daddr);
1087 if (score.matchlen > hiscore.matchlen) {
1092 else if (score.matchlen < hiscore.matchlen)
1096 /* Final Rule: choose first available one */
1100 in6_ifa_put(ifa_result);
1105 read_unlock_bh(&idev->lock);
1107 read_unlock(&addrconf_lock);
1108 read_unlock(&dev_base_lock);
1111 return -EADDRNOTAVAIL;
1113 ipv6_addr_copy(saddr, &ifa_result->addr);
1114 in6_ifa_put(ifa_result);
1119 int ipv6_get_saddr(struct dst_entry *dst,
1120 struct in6_addr *daddr, struct in6_addr *saddr)
1122 return ipv6_dev_get_saddr(dst ? ((struct rt6_info *)dst)->rt6i_idev->dev : NULL, daddr, saddr);
1126 int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr)
1128 struct inet6_dev *idev;
1129 int err = -EADDRNOTAVAIL;
1131 read_lock(&addrconf_lock);
1132 if ((idev = __in6_dev_get(dev)) != NULL) {
1133 struct inet6_ifaddr *ifp;
1135 read_lock_bh(&idev->lock);
1136 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
1137 if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) {
1138 ipv6_addr_copy(addr, &ifp->addr);
1143 read_unlock_bh(&idev->lock);
1145 read_unlock(&addrconf_lock);
1149 static int ipv6_count_addresses(struct inet6_dev *idev)
1152 struct inet6_ifaddr *ifp;
1154 read_lock_bh(&idev->lock);
1155 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next)
1157 read_unlock_bh(&idev->lock);
1161 int ipv6_chk_addr(struct in6_addr *addr, struct net_device *dev, int strict)
1163 struct inet6_ifaddr * ifp;
1164 u8 hash = ipv6_addr_hash(addr);
1166 read_lock_bh(&addrconf_hash_lock);
1167 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1168 if (ipv6_addr_equal(&ifp->addr, addr) &&
1169 !(ifp->flags&IFA_F_TENTATIVE)) {
1170 if (dev == NULL || ifp->idev->dev == dev ||
1171 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))
1175 read_unlock_bh(&addrconf_hash_lock);
1180 int ipv6_chk_same_addr(const struct in6_addr *addr, struct net_device *dev)
1182 struct inet6_ifaddr * ifp;
1183 u8 hash = ipv6_addr_hash(addr);
1185 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1186 if (ipv6_addr_equal(&ifp->addr, addr)) {
1187 if (dev == NULL || ifp->idev->dev == dev)
1194 struct inet6_ifaddr * ipv6_get_ifaddr(struct in6_addr *addr, struct net_device *dev, int strict)
1196 struct inet6_ifaddr * ifp;
1197 u8 hash = ipv6_addr_hash(addr);
1199 read_lock_bh(&addrconf_hash_lock);
1200 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
1201 if (ipv6_addr_equal(&ifp->addr, addr)) {
1202 if (dev == NULL || ifp->idev->dev == dev ||
1203 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) {
1209 read_unlock_bh(&addrconf_hash_lock);
1214 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
1216 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
1217 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
1218 u32 sk_rcv_saddr = inet_sk(sk)->rcv_saddr;
1219 u32 sk2_rcv_saddr = inet_rcv_saddr(sk2);
1220 int sk_ipv6only = ipv6_only_sock(sk);
1221 int sk2_ipv6only = inet_v6_ipv6only(sk2);
1222 int addr_type = ipv6_addr_type(sk_rcv_saddr6);
1223 int addr_type2 = sk2_rcv_saddr6 ? ipv6_addr_type(sk2_rcv_saddr6) : IPV6_ADDR_MAPPED;
1225 if (!sk2_rcv_saddr && !sk_ipv6only)
1228 if (addr_type2 == IPV6_ADDR_ANY &&
1229 !(sk2_ipv6only && addr_type == IPV6_ADDR_MAPPED))
1232 if (addr_type == IPV6_ADDR_ANY &&
1233 !(sk_ipv6only && addr_type2 == IPV6_ADDR_MAPPED))
1236 if (sk2_rcv_saddr6 &&
1237 ipv6_addr_equal(sk_rcv_saddr6, sk2_rcv_saddr6))
1240 if (addr_type == IPV6_ADDR_MAPPED &&
1242 (!sk2_rcv_saddr || !sk_rcv_saddr || sk_rcv_saddr == sk2_rcv_saddr))
1248 /* Gets referenced address, destroys ifaddr */
1250 static void addrconf_dad_stop(struct inet6_ifaddr *ifp)
1252 if (ifp->flags&IFA_F_PERMANENT) {
1253 spin_lock_bh(&ifp->lock);
1254 addrconf_del_timer(ifp);
1255 ifp->flags |= IFA_F_TENTATIVE;
1256 spin_unlock_bh(&ifp->lock);
1258 #ifdef CONFIG_IPV6_PRIVACY
1259 } else if (ifp->flags&IFA_F_TEMPORARY) {
1260 struct inet6_ifaddr *ifpub;
1261 spin_lock_bh(&ifp->lock);
1264 in6_ifa_hold(ifpub);
1265 spin_unlock_bh(&ifp->lock);
1266 ipv6_create_tempaddr(ifpub, ifp);
1269 spin_unlock_bh(&ifp->lock);
1277 void addrconf_dad_failure(struct inet6_ifaddr *ifp)
1279 if (net_ratelimit())
1280 printk(KERN_INFO "%s: duplicate address detected!\n", ifp->idev->dev->name);
1281 addrconf_dad_stop(ifp);
1284 /* Join to solicited addr multicast group. */
1286 void addrconf_join_solict(struct net_device *dev, struct in6_addr *addr)
1288 struct in6_addr maddr;
1290 if (dev->flags&(IFF_LOOPBACK|IFF_NOARP))
1293 addrconf_addr_solict_mult(addr, &maddr);
1294 ipv6_dev_mc_inc(dev, &maddr);
1297 void addrconf_leave_solict(struct inet6_dev *idev, struct in6_addr *addr)
1299 struct in6_addr maddr;
1301 if (idev->dev->flags&(IFF_LOOPBACK|IFF_NOARP))
1304 addrconf_addr_solict_mult(addr, &maddr);
1305 __ipv6_dev_mc_dec(idev, &maddr);
1308 static void addrconf_join_anycast(struct inet6_ifaddr *ifp)
1310 struct in6_addr addr;
1311 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len);
1312 if (ipv6_addr_any(&addr))
1314 ipv6_dev_ac_inc(ifp->idev->dev, &addr);
1317 static void addrconf_leave_anycast(struct inet6_ifaddr *ifp)
1319 struct in6_addr addr;
1320 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len);
1321 if (ipv6_addr_any(&addr))
1323 __ipv6_dev_ac_dec(ifp->idev, &addr);
1326 static int addrconf_ifid_eui48(u8 *eui, struct net_device *dev)
1328 if (dev->addr_len != ETH_ALEN)
1330 memcpy(eui, dev->dev_addr, 3);
1331 memcpy(eui + 5, dev->dev_addr + 3, 3);
1334 * The zSeries OSA network cards can be shared among various
1335 * OS instances, but the OSA cards have only one MAC address.
1336 * This leads to duplicate address conflicts in conjunction
1337 * with IPv6 if more than one instance uses the same card.
1339 * The driver for these cards can deliver a unique 16-bit
1340 * identifier for each instance sharing the same card. It is
1341 * placed instead of 0xFFFE in the interface identifier. The
1342 * "u" bit of the interface identifier is not inverted in this
1343 * case. Hence the resulting interface identifier has local
1344 * scope according to RFC2373.
1347 eui[3] = (dev->dev_id >> 8) & 0xFF;
1348 eui[4] = dev->dev_id & 0xFF;
1357 static int addrconf_ifid_arcnet(u8 *eui, struct net_device *dev)
1359 /* XXX: inherit EUI-64 from other interface -- yoshfuji */
1360 if (dev->addr_len != ARCNET_ALEN)
1363 eui[7] = *(u8*)dev->dev_addr;
1367 static int addrconf_ifid_infiniband(u8 *eui, struct net_device *dev)
1369 if (dev->addr_len != INFINIBAND_ALEN)
1371 memcpy(eui, dev->dev_addr + 12, 8);
1376 static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
1378 switch (dev->type) {
1381 case ARPHRD_IEEE802_TR:
1382 return addrconf_ifid_eui48(eui, dev);
1384 return addrconf_ifid_arcnet(eui, dev);
1385 case ARPHRD_INFINIBAND:
1386 return addrconf_ifid_infiniband(eui, dev);
1391 static int ipv6_inherit_eui64(u8 *eui, struct inet6_dev *idev)
1394 struct inet6_ifaddr *ifp;
1396 read_lock_bh(&idev->lock);
1397 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
1398 if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) {
1399 memcpy(eui, ifp->addr.s6_addr+8, 8);
1404 read_unlock_bh(&idev->lock);
1408 #ifdef CONFIG_IPV6_PRIVACY
1409 /* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */
1410 static int __ipv6_regen_rndid(struct inet6_dev *idev)
1413 get_random_bytes(idev->rndid, sizeof(idev->rndid));
1414 idev->rndid[0] &= ~0x02;
1417 * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>:
1418 * check if generated address is not inappropriate
1420 * - Reserved subnet anycast (RFC 2526)
1421 * 11111101 11....11 1xxxxxxx
1422 * - ISATAP (draft-ietf-ngtrans-isatap-13.txt) 5.1
1423 * 00-00-5E-FE-xx-xx-xx-xx
1425 * - XXX: already assigned to an address on the device
1427 if (idev->rndid[0] == 0xfd &&
1428 (idev->rndid[1]&idev->rndid[2]&idev->rndid[3]&idev->rndid[4]&idev->rndid[5]&idev->rndid[6]) == 0xff &&
1429 (idev->rndid[7]&0x80))
1431 if ((idev->rndid[0]|idev->rndid[1]) == 0) {
1432 if (idev->rndid[2] == 0x5e && idev->rndid[3] == 0xfe)
1434 if ((idev->rndid[2]|idev->rndid[3]|idev->rndid[4]|idev->rndid[5]|idev->rndid[6]|idev->rndid[7]) == 0x00)
1441 static void ipv6_regen_rndid(unsigned long data)
1443 struct inet6_dev *idev = (struct inet6_dev *) data;
1444 unsigned long expires;
1446 read_lock_bh(&addrconf_lock);
1447 write_lock_bh(&idev->lock);
1452 if (__ipv6_regen_rndid(idev) < 0)
1456 idev->cnf.temp_prefered_lft * HZ -
1457 idev->cnf.regen_max_retry * idev->cnf.dad_transmits * idev->nd_parms->retrans_time - desync_factor;
1458 if (time_before(expires, jiffies)) {
1460 "ipv6_regen_rndid(): too short regeneration interval; timer disabled for %s.\n",
1465 if (!mod_timer(&idev->regen_timer, expires))
1469 write_unlock_bh(&idev->lock);
1470 read_unlock_bh(&addrconf_lock);
1474 static int __ipv6_try_regen_rndid(struct inet6_dev *idev, struct in6_addr *tmpaddr) {
1477 if (tmpaddr && memcmp(idev->rndid, &tmpaddr->s6_addr[8], 8) == 0)
1478 ret = __ipv6_regen_rndid(idev);
1488 addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
1489 unsigned long expires, u32 flags)
1491 struct in6_rtmsg rtmsg;
1493 memset(&rtmsg, 0, sizeof(rtmsg));
1494 ipv6_addr_copy(&rtmsg.rtmsg_dst, pfx);
1495 rtmsg.rtmsg_dst_len = plen;
1496 rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF;
1497 rtmsg.rtmsg_ifindex = dev->ifindex;
1498 rtmsg.rtmsg_info = expires;
1499 rtmsg.rtmsg_flags = RTF_UP|flags;
1500 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
1502 /* Prevent useless cloning on PtP SIT.
1503 This thing is done here expecting that the whole
1504 class of non-broadcast devices need not cloning.
1506 if (dev->type == ARPHRD_SIT && (dev->flags&IFF_POINTOPOINT))
1507 rtmsg.rtmsg_flags |= RTF_NONEXTHOP;
1509 ip6_route_add(&rtmsg, NULL, NULL, NULL);
1512 /* Create "default" multicast route to the interface */
1514 static void addrconf_add_mroute(struct net_device *dev)
1516 struct in6_rtmsg rtmsg;
1518 memset(&rtmsg, 0, sizeof(rtmsg));
1519 ipv6_addr_set(&rtmsg.rtmsg_dst,
1520 htonl(0xFF000000), 0, 0, 0);
1521 rtmsg.rtmsg_dst_len = 8;
1522 rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF;
1523 rtmsg.rtmsg_ifindex = dev->ifindex;
1524 rtmsg.rtmsg_flags = RTF_UP;
1525 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
1526 ip6_route_add(&rtmsg, NULL, NULL, NULL);
1529 static void sit_route_add(struct net_device *dev)
1531 struct in6_rtmsg rtmsg;
1533 memset(&rtmsg, 0, sizeof(rtmsg));
1535 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
1536 rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF;
1538 /* prefix length - 96 bits "::d.d.d.d" */
1539 rtmsg.rtmsg_dst_len = 96;
1540 rtmsg.rtmsg_flags = RTF_UP|RTF_NONEXTHOP;
1541 rtmsg.rtmsg_ifindex = dev->ifindex;
1543 ip6_route_add(&rtmsg, NULL, NULL, NULL);
1546 static void addrconf_add_lroute(struct net_device *dev)
1548 struct in6_addr addr;
1550 ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0);
1551 addrconf_prefix_route(&addr, 64, dev, 0, 0);
1554 static struct inet6_dev *addrconf_add_dev(struct net_device *dev)
1556 struct inet6_dev *idev;
1560 if ((idev = ipv6_find_idev(dev)) == NULL)
1563 /* Add default multicast route */
1564 addrconf_add_mroute(dev);
1566 /* Add link local route */
1567 addrconf_add_lroute(dev);
1571 void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
1573 struct prefix_info *pinfo;
1577 unsigned long rt_expires;
1578 struct inet6_dev *in6_dev;
1580 pinfo = (struct prefix_info *) opt;
1582 if (len < sizeof(struct prefix_info)) {
1583 ADBG(("addrconf: prefix option too short\n"));
1588 * Validation checks ([ADDRCONF], page 19)
1591 addr_type = ipv6_addr_type(&pinfo->prefix);
1593 if (addr_type & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL))
1596 valid_lft = ntohl(pinfo->valid);
1597 prefered_lft = ntohl(pinfo->prefered);
1599 if (prefered_lft > valid_lft) {
1600 if (net_ratelimit())
1601 printk(KERN_WARNING "addrconf: prefix option has invalid lifetime\n");
1605 in6_dev = in6_dev_get(dev);
1607 if (in6_dev == NULL) {
1608 if (net_ratelimit())
1609 printk(KERN_DEBUG "addrconf: device %s not configured\n", dev->name);
1614 * Two things going on here:
1615 * 1) Add routes for on-link prefixes
1616 * 2) Configure prefixes with the auto flag set
1619 /* Avoid arithmetic overflow. Really, we could
1620 save rt_expires in seconds, likely valid_lft,
1621 but it would require division in fib gc, that it
1624 if (valid_lft >= 0x7FFFFFFF/HZ)
1625 rt_expires = 0x7FFFFFFF - (0x7FFFFFFF % HZ);
1627 rt_expires = valid_lft * HZ;
1630 * We convert this (in jiffies) to clock_t later.
1631 * Avoid arithmetic overflow there as well.
1632 * Overflow can happen only if HZ < USER_HZ.
1634 if (HZ < USER_HZ && rt_expires > 0x7FFFFFFF / USER_HZ)
1635 rt_expires = 0x7FFFFFFF / USER_HZ;
1637 if (pinfo->onlink) {
1638 struct rt6_info *rt;
1639 rt = rt6_lookup(&pinfo->prefix, NULL, dev->ifindex, 1);
1641 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
1642 if (rt->rt6i_flags&RTF_EXPIRES) {
1643 if (valid_lft == 0) {
1644 ip6_del_rt(rt, NULL, NULL, NULL);
1647 rt->rt6i_expires = jiffies + rt_expires;
1650 } else if (valid_lft) {
1651 addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
1652 dev, jiffies_to_clock_t(rt_expires), RTF_ADDRCONF|RTF_EXPIRES|RTF_PREFIX_RT);
1655 dst_release(&rt->u.dst);
1658 /* Try to figure out our local address for this prefix */
1660 if (pinfo->autoconf && in6_dev->cnf.autoconf) {
1661 struct inet6_ifaddr * ifp;
1662 struct in6_addr addr;
1663 int create = 0, update_lft = 0;
1665 if (pinfo->prefix_len == 64) {
1666 memcpy(&addr, &pinfo->prefix, 8);
1667 if (ipv6_generate_eui64(addr.s6_addr + 8, dev) &&
1668 ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) {
1669 in6_dev_put(in6_dev);
1674 if (net_ratelimit())
1675 printk(KERN_DEBUG "IPv6 addrconf: prefix with wrong length %d\n",
1677 in6_dev_put(in6_dev);
1682 ifp = ipv6_get_ifaddr(&addr, dev, 1);
1684 if (ifp == NULL && valid_lft) {
1685 int max_addresses = in6_dev->cnf.max_addresses;
1687 /* Do not allow to create too much of autoconfigured
1688 * addresses; this would be too easy way to crash kernel.
1690 if (!max_addresses ||
1691 ipv6_count_addresses(in6_dev) < max_addresses)
1692 ifp = ipv6_add_addr(in6_dev, &addr, pinfo->prefix_len,
1693 addr_type&IPV6_ADDR_SCOPE_MASK, 0);
1695 if (!ifp || IS_ERR(ifp)) {
1696 in6_dev_put(in6_dev);
1700 update_lft = create = 1;
1701 ifp->cstamp = jiffies;
1702 addrconf_dad_start(ifp, RTF_ADDRCONF|RTF_PREFIX_RT);
1708 #ifdef CONFIG_IPV6_PRIVACY
1709 struct inet6_ifaddr *ift;
1713 /* update lifetime (RFC2462 5.5.3 e) */
1714 spin_lock(&ifp->lock);
1716 if (ifp->valid_lft > (now - ifp->tstamp) / HZ)
1717 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ;
1720 if (!update_lft && stored_lft) {
1721 if (valid_lft > MIN_VALID_LIFETIME ||
1722 valid_lft > stored_lft)
1724 else if (stored_lft <= MIN_VALID_LIFETIME) {
1725 /* valid_lft <= stored_lft is always true */
1729 valid_lft = MIN_VALID_LIFETIME;
1730 if (valid_lft < prefered_lft)
1731 prefered_lft = valid_lft;
1737 ifp->valid_lft = valid_lft;
1738 ifp->prefered_lft = prefered_lft;
1741 ifp->flags &= ~IFA_F_DEPRECATED;
1742 spin_unlock(&ifp->lock);
1744 if (!(flags&IFA_F_TENTATIVE))
1745 ipv6_ifa_notify(0, ifp);
1747 spin_unlock(&ifp->lock);
1749 #ifdef CONFIG_IPV6_PRIVACY
1750 read_lock_bh(&in6_dev->lock);
1751 /* update all temporary addresses in the list */
1752 for (ift=in6_dev->tempaddr_list; ift; ift=ift->tmp_next) {
1754 * When adjusting the lifetimes of an existing
1755 * temporary address, only lower the lifetimes.
1756 * Implementations must not increase the
1757 * lifetimes of an existing temporary address
1758 * when processing a Prefix Information Option.
1760 spin_lock(&ift->lock);
1762 if (ift->valid_lft > valid_lft &&
1763 ift->valid_lft - valid_lft > (jiffies - ift->tstamp) / HZ)
1764 ift->valid_lft = valid_lft + (jiffies - ift->tstamp) / HZ;
1765 if (ift->prefered_lft > prefered_lft &&
1766 ift->prefered_lft - prefered_lft > (jiffies - ift->tstamp) / HZ)
1767 ift->prefered_lft = prefered_lft + (jiffies - ift->tstamp) / HZ;
1768 spin_unlock(&ift->lock);
1769 if (!(flags&IFA_F_TENTATIVE))
1770 ipv6_ifa_notify(0, ift);
1773 if (create && in6_dev->cnf.use_tempaddr > 0) {
1775 * When a new public address is created as described in [ADDRCONF],
1776 * also create a new temporary address.
1778 read_unlock_bh(&in6_dev->lock);
1779 ipv6_create_tempaddr(ifp, NULL);
1781 read_unlock_bh(&in6_dev->lock);
1788 inet6_prefix_notify(RTM_NEWPREFIX, in6_dev, pinfo);
1789 in6_dev_put(in6_dev);
1793 * Set destination address.
1794 * Special case for SIT interfaces where we create a new "virtual"
1797 int addrconf_set_dstaddr(void __user *arg)
1799 struct in6_ifreq ireq;
1800 struct net_device *dev;
1806 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
1809 dev = __dev_get_by_index(ireq.ifr6_ifindex);
1815 if (dev->type == ARPHRD_SIT) {
1818 struct ip_tunnel_parm p;
1820 err = -EADDRNOTAVAIL;
1821 if (!(ipv6_addr_type(&ireq.ifr6_addr) & IPV6_ADDR_COMPATv4))
1824 memset(&p, 0, sizeof(p));
1825 p.iph.daddr = ireq.ifr6_addr.s6_addr32[3];
1829 p.iph.protocol = IPPROTO_IPV6;
1831 ifr.ifr_ifru.ifru_data = (void __user *)&p;
1833 oldfs = get_fs(); set_fs(KERNEL_DS);
1834 err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL);
1839 if ((dev = __dev_get_by_name(p.name)) == NULL)
1841 err = dev_open(dev);
1851 * Manual configuration of address on an interface
1853 static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen)
1855 struct inet6_ifaddr *ifp;
1856 struct inet6_dev *idev;
1857 struct net_device *dev;
1862 if ((dev = __dev_get_by_index(ifindex)) == NULL)
1865 if (!(dev->flags&IFF_UP))
1868 if ((idev = addrconf_add_dev(dev)) == NULL)
1871 scope = ipv6_addr_scope(pfx);
1873 ifp = ipv6_add_addr(idev, pfx, plen, scope, IFA_F_PERMANENT);
1875 addrconf_dad_start(ifp, 0);
1880 return PTR_ERR(ifp);
1883 static int inet6_addr_del(int ifindex, struct in6_addr *pfx, int plen)
1885 struct inet6_ifaddr *ifp;
1886 struct inet6_dev *idev;
1887 struct net_device *dev;
1889 if ((dev = __dev_get_by_index(ifindex)) == NULL)
1892 if ((idev = __in6_dev_get(dev)) == NULL)
1895 read_lock_bh(&idev->lock);
1896 for (ifp = idev->addr_list; ifp; ifp=ifp->if_next) {
1897 if (ifp->prefix_len == plen &&
1898 ipv6_addr_equal(pfx, &ifp->addr)) {
1900 read_unlock_bh(&idev->lock);
1904 /* If the last address is deleted administratively,
1905 disable IPv6 on this interface.
1907 if (idev->addr_list == NULL)
1908 addrconf_ifdown(idev->dev, 1);
1912 read_unlock_bh(&idev->lock);
1913 return -EADDRNOTAVAIL;
1917 int addrconf_add_ifaddr(void __user *arg)
1919 struct in6_ifreq ireq;
1922 if (!capable(CAP_NET_ADMIN))
1925 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
1929 err = inet6_addr_add(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen);
1934 int addrconf_del_ifaddr(void __user *arg)
1936 struct in6_ifreq ireq;
1939 if (!capable(CAP_NET_ADMIN))
1942 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
1946 err = inet6_addr_del(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen);
1951 static void sit_add_v4_addrs(struct inet6_dev *idev)
1953 struct inet6_ifaddr * ifp;
1954 struct in6_addr addr;
1955 struct net_device *dev;
1960 memset(&addr, 0, sizeof(struct in6_addr));
1961 memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4);
1963 if (idev->dev->flags&IFF_POINTOPOINT) {
1964 addr.s6_addr32[0] = htonl(0xfe800000);
1967 scope = IPV6_ADDR_COMPATv4;
1970 if (addr.s6_addr32[3]) {
1971 ifp = ipv6_add_addr(idev, &addr, 128, scope, IFA_F_PERMANENT);
1973 spin_lock_bh(&ifp->lock);
1974 ifp->flags &= ~IFA_F_TENTATIVE;
1975 spin_unlock_bh(&ifp->lock);
1976 ipv6_ifa_notify(RTM_NEWADDR, ifp);
1982 for (dev = dev_base; dev != NULL; dev = dev->next) {
1983 struct in_device * in_dev = __in_dev_get_rtnl(dev);
1984 if (in_dev && (dev->flags & IFF_UP)) {
1985 struct in_ifaddr * ifa;
1989 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1992 addr.s6_addr32[3] = ifa->ifa_local;
1994 if (ifa->ifa_scope == RT_SCOPE_LINK)
1996 if (ifa->ifa_scope >= RT_SCOPE_HOST) {
1997 if (idev->dev->flags&IFF_POINTOPOINT)
2001 if (idev->dev->flags&IFF_POINTOPOINT)
2006 ifp = ipv6_add_addr(idev, &addr, plen, flag,
2009 spin_lock_bh(&ifp->lock);
2010 ifp->flags &= ~IFA_F_TENTATIVE;
2011 spin_unlock_bh(&ifp->lock);
2012 ipv6_ifa_notify(RTM_NEWADDR, ifp);
2020 static void init_loopback(struct net_device *dev)
2022 struct inet6_dev *idev;
2023 struct inet6_ifaddr * ifp;
2029 if ((idev = ipv6_find_idev(dev)) == NULL) {
2030 printk(KERN_DEBUG "init loopback: add_dev failed\n");
2034 ifp = ipv6_add_addr(idev, &in6addr_loopback, 128, IFA_HOST, IFA_F_PERMANENT);
2036 spin_lock_bh(&ifp->lock);
2037 ifp->flags &= ~IFA_F_TENTATIVE;
2038 spin_unlock_bh(&ifp->lock);
2039 ipv6_ifa_notify(RTM_NEWADDR, ifp);
2044 static void addrconf_add_linklocal(struct inet6_dev *idev, struct in6_addr *addr)
2046 struct inet6_ifaddr * ifp;
2048 ifp = ipv6_add_addr(idev, addr, 64, IFA_LINK, IFA_F_PERMANENT);
2050 addrconf_dad_start(ifp, 0);
2055 static void addrconf_dev_config(struct net_device *dev)
2057 struct in6_addr addr;
2058 struct inet6_dev * idev;
2062 if ((dev->type != ARPHRD_ETHER) &&
2063 (dev->type != ARPHRD_FDDI) &&
2064 (dev->type != ARPHRD_IEEE802_TR) &&
2065 (dev->type != ARPHRD_ARCNET) &&
2066 (dev->type != ARPHRD_INFINIBAND)) {
2067 /* Alas, we support only Ethernet autoconfiguration. */
2071 idev = addrconf_add_dev(dev);
2075 memset(&addr, 0, sizeof(struct in6_addr));
2076 addr.s6_addr32[0] = htonl(0xFE800000);
2078 if (ipv6_generate_eui64(addr.s6_addr + 8, dev) == 0)
2079 addrconf_add_linklocal(idev, &addr);
2082 static void addrconf_sit_config(struct net_device *dev)
2084 struct inet6_dev *idev;
2089 * Configure the tunnel with one of our IPv4
2090 * addresses... we should configure all of
2091 * our v4 addrs in the tunnel
2094 if ((idev = ipv6_find_idev(dev)) == NULL) {
2095 printk(KERN_DEBUG "init sit: add_dev failed\n");
2099 sit_add_v4_addrs(idev);
2101 if (dev->flags&IFF_POINTOPOINT) {
2102 addrconf_add_mroute(dev);
2103 addrconf_add_lroute(dev);
2109 ipv6_inherit_linklocal(struct inet6_dev *idev, struct net_device *link_dev)
2111 struct in6_addr lladdr;
2113 if (!ipv6_get_lladdr(link_dev, &lladdr)) {
2114 addrconf_add_linklocal(idev, &lladdr);
2120 static void ip6_tnl_add_linklocal(struct inet6_dev *idev)
2122 struct net_device *link_dev;
2124 /* first try to inherit the link-local address from the link device */
2125 if (idev->dev->iflink &&
2126 (link_dev = __dev_get_by_index(idev->dev->iflink))) {
2127 if (!ipv6_inherit_linklocal(idev, link_dev))
2130 /* then try to inherit it from any device */
2131 for (link_dev = dev_base; link_dev; link_dev = link_dev->next) {
2132 if (!ipv6_inherit_linklocal(idev, link_dev))
2135 printk(KERN_DEBUG "init ip6-ip6: add_linklocal failed\n");
2139 * Autoconfigure tunnel with a link-local address so routing protocols,
2140 * DHCPv6, MLD etc. can be run over the virtual link
2143 static void addrconf_ip6_tnl_config(struct net_device *dev)
2145 struct inet6_dev *idev;
2149 if ((idev = addrconf_add_dev(dev)) == NULL) {
2150 printk(KERN_DEBUG "init ip6-ip6: add_dev failed\n");
2153 ip6_tnl_add_linklocal(idev);
2156 static int addrconf_notify(struct notifier_block *this, unsigned long event,
2159 struct net_device *dev = (struct net_device *) data;
2160 struct inet6_dev *idev = __in6_dev_get(dev);
2161 int run_pending = 0;
2166 if (event == NETDEV_UP) {
2167 if (!netif_carrier_ok(dev)) {
2168 /* device is not ready yet. */
2170 "ADDRCONF(NETDEV_UP): %s: "
2171 "link is not ready\n",
2177 idev->if_flags |= IF_READY;
2179 if (!netif_carrier_ok(dev)) {
2180 /* device is still not ready. */
2185 if (idev->if_flags & IF_READY) {
2186 /* device is already configured. */
2189 idev->if_flags |= IF_READY;
2193 "ADDRCONF(NETDEV_CHANGE): %s: "
2194 "link becomes ready\n",
2202 addrconf_sit_config(dev);
2204 case ARPHRD_TUNNEL6:
2205 addrconf_ip6_tnl_config(dev);
2207 case ARPHRD_LOOPBACK:
2212 addrconf_dev_config(dev);
2217 addrconf_dad_run(idev);
2219 /* If the MTU changed during the interface down, when the
2220 interface up, the changed MTU must be reflected in the
2221 idev as well as routers.
2223 if (idev->cnf.mtu6 != dev->mtu && dev->mtu >= IPV6_MIN_MTU) {
2224 rt6_mtu_change(dev, dev->mtu);
2225 idev->cnf.mtu6 = dev->mtu;
2227 idev->tstamp = jiffies;
2228 inet6_ifinfo_notify(RTM_NEWLINK, idev);
2229 /* If the changed mtu during down is lower than IPV6_MIN_MTU
2230 stop IPv6 on this interface.
2232 if (dev->mtu < IPV6_MIN_MTU)
2233 addrconf_ifdown(dev, event != NETDEV_DOWN);
2237 case NETDEV_CHANGEMTU:
2238 if ( idev && dev->mtu >= IPV6_MIN_MTU) {
2239 rt6_mtu_change(dev, dev->mtu);
2240 idev->cnf.mtu6 = dev->mtu;
2244 /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */
2247 case NETDEV_UNREGISTER:
2249 * Remove all addresses from this interface.
2251 addrconf_ifdown(dev, event != NETDEV_DOWN);
2254 case NETDEV_CHANGENAME:
2255 #ifdef CONFIG_SYSCTL
2257 addrconf_sysctl_unregister(&idev->cnf);
2258 neigh_sysctl_unregister(idev->nd_parms);
2259 neigh_sysctl_register(dev, idev->nd_parms,
2260 NET_IPV6, NET_IPV6_NEIGH, "ipv6",
2261 &ndisc_ifinfo_sysctl_change,
2263 addrconf_sysctl_register(idev, &idev->cnf);
2273 * addrconf module should be notified of a device going up
2275 static struct notifier_block ipv6_dev_notf = {
2276 .notifier_call = addrconf_notify,
2280 static int addrconf_ifdown(struct net_device *dev, int how)
2282 struct inet6_dev *idev;
2283 struct inet6_ifaddr *ifa, **bifa;
2288 if (dev == &loopback_dev && how == 1)
2292 neigh_ifdown(&nd_tbl, dev);
2294 idev = __in6_dev_get(dev);
2298 /* Step 1: remove reference to ipv6 device from parent device.
2302 write_lock_bh(&addrconf_lock);
2303 dev->ip6_ptr = NULL;
2305 write_unlock_bh(&addrconf_lock);
2307 /* Step 1.5: remove snmp6 entry */
2308 snmp6_unregister_dev(idev);
2312 /* Step 2: clear hash table */
2313 for (i=0; i<IN6_ADDR_HSIZE; i++) {
2314 bifa = &inet6_addr_lst[i];
2316 write_lock_bh(&addrconf_hash_lock);
2317 while ((ifa = *bifa) != NULL) {
2318 if (ifa->idev == idev) {
2319 *bifa = ifa->lst_next;
2320 ifa->lst_next = NULL;
2321 addrconf_del_timer(ifa);
2325 bifa = &ifa->lst_next;
2327 write_unlock_bh(&addrconf_hash_lock);
2330 write_lock_bh(&idev->lock);
2332 /* Step 3: clear flags for stateless addrconf */
2334 idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY);
2336 /* Step 4: clear address list */
2337 #ifdef CONFIG_IPV6_PRIVACY
2338 if (how == 1 && del_timer(&idev->regen_timer))
2341 /* clear tempaddr list */
2342 while ((ifa = idev->tempaddr_list) != NULL) {
2343 idev->tempaddr_list = ifa->tmp_next;
2344 ifa->tmp_next = NULL;
2346 write_unlock_bh(&idev->lock);
2347 spin_lock_bh(&ifa->lock);
2350 in6_ifa_put(ifa->ifpub);
2353 spin_unlock_bh(&ifa->lock);
2355 write_lock_bh(&idev->lock);
2358 while ((ifa = idev->addr_list) != NULL) {
2359 idev->addr_list = ifa->if_next;
2360 ifa->if_next = NULL;
2362 addrconf_del_timer(ifa);
2363 write_unlock_bh(&idev->lock);
2365 __ipv6_ifa_notify(RTM_DELADDR, ifa);
2368 write_lock_bh(&idev->lock);
2370 write_unlock_bh(&idev->lock);
2372 /* Step 5: Discard multicast list */
2375 ipv6_mc_destroy_dev(idev);
2379 /* Step 5: netlink notification of this interface */
2380 idev->tstamp = jiffies;
2381 inet6_ifinfo_notify(RTM_DELLINK, idev);
2383 /* Shot the device (if unregistered) */
2386 #ifdef CONFIG_SYSCTL
2387 addrconf_sysctl_unregister(&idev->cnf);
2388 neigh_sysctl_unregister(idev->nd_parms);
2390 neigh_parms_release(&nd_tbl, idev->nd_parms);
2391 neigh_ifdown(&nd_tbl, dev);
2397 static void addrconf_rs_timer(unsigned long data)
2399 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data;
2401 if (ifp->idev->cnf.forwarding)
2404 if (ifp->idev->if_flags & IF_RA_RCVD) {
2406 * Announcement received after solicitation
2412 spin_lock(&ifp->lock);
2413 if (ifp->probes++ < ifp->idev->cnf.rtr_solicits) {
2414 struct in6_addr all_routers;
2416 /* The wait after the last probe can be shorter */
2417 addrconf_mod_timer(ifp, AC_RS,
2418 (ifp->probes == ifp->idev->cnf.rtr_solicits) ?
2419 ifp->idev->cnf.rtr_solicit_delay :
2420 ifp->idev->cnf.rtr_solicit_interval);
2421 spin_unlock(&ifp->lock);
2423 ipv6_addr_all_routers(&all_routers);
2425 ndisc_send_rs(ifp->idev->dev, &ifp->addr, &all_routers);
2427 spin_unlock(&ifp->lock);
2429 * Note: we do not support deprecated "all on-link"
2430 * assumption any longer.
2432 printk(KERN_DEBUG "%s: no IPv6 routers present\n",
2433 ifp->idev->dev->name);
2441 * Duplicate Address Detection
2443 static void addrconf_dad_kick(struct inet6_ifaddr *ifp)
2445 unsigned long rand_num;
2446 struct inet6_dev *idev = ifp->idev;
2448 rand_num = net_random() % (idev->cnf.rtr_solicit_delay ? : 1);
2449 ifp->probes = idev->cnf.dad_transmits;
2450 addrconf_mod_timer(ifp, AC_DAD, rand_num);
2453 static void addrconf_dad_start(struct inet6_ifaddr *ifp, u32 flags)
2455 struct inet6_dev *idev = ifp->idev;
2456 struct net_device *dev = idev->dev;
2458 addrconf_join_solict(dev, &ifp->addr);
2460 if (ifp->prefix_len != 128 && (ifp->flags&IFA_F_PERMANENT))
2461 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, 0,
2464 net_srandom(ifp->addr.s6_addr32[3]);
2466 read_lock_bh(&idev->lock);
2469 spin_lock_bh(&ifp->lock);
2471 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) ||
2472 !(ifp->flags&IFA_F_TENTATIVE)) {
2473 ifp->flags &= ~IFA_F_TENTATIVE;
2474 spin_unlock_bh(&ifp->lock);
2475 read_unlock_bh(&idev->lock);
2477 addrconf_dad_completed(ifp);
2481 if (!(idev->if_flags & IF_READY)) {
2482 spin_unlock_bh(&ifp->lock);
2483 read_unlock_bh(&idev->lock);
2485 * If the defice is not ready:
2486 * - keep it tentative if it is a permanent address.
2487 * - otherwise, kill it.
2490 addrconf_dad_stop(ifp);
2493 addrconf_dad_kick(ifp);
2494 spin_unlock_bh(&ifp->lock);
2496 read_unlock_bh(&idev->lock);
2499 static void addrconf_dad_timer(unsigned long data)
2501 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data;
2502 struct inet6_dev *idev = ifp->idev;
2503 struct in6_addr unspec;
2504 struct in6_addr mcaddr;
2506 read_lock_bh(&idev->lock);
2508 read_unlock_bh(&idev->lock);
2511 spin_lock_bh(&ifp->lock);
2512 if (ifp->probes == 0) {
2514 * DAD was successful
2517 ifp->flags &= ~IFA_F_TENTATIVE;
2518 spin_unlock_bh(&ifp->lock);
2519 read_unlock_bh(&idev->lock);
2521 addrconf_dad_completed(ifp);
2527 addrconf_mod_timer(ifp, AC_DAD, ifp->idev->nd_parms->retrans_time);
2528 spin_unlock_bh(&ifp->lock);
2529 read_unlock_bh(&idev->lock);
2531 /* send a neighbour solicitation for our addr */
2532 memset(&unspec, 0, sizeof(unspec));
2533 addrconf_addr_solict_mult(&ifp->addr, &mcaddr);
2534 ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &unspec);
2539 static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
2541 struct net_device * dev = ifp->idev->dev;
2544 * Configure the address for reception. Now it is valid.
2547 ipv6_ifa_notify(RTM_NEWADDR, ifp);
2549 /* If added prefix is link local and forwarding is off,
2550 start sending router solicitations.
2553 if (ifp->idev->cnf.forwarding == 0 &&
2554 ifp->idev->cnf.rtr_solicits > 0 &&
2555 (dev->flags&IFF_LOOPBACK) == 0 &&
2556 (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) {
2557 struct in6_addr all_routers;
2559 ipv6_addr_all_routers(&all_routers);
2562 * If a host as already performed a random delay
2563 * [...] as part of DAD [...] there is no need
2564 * to delay again before sending the first RS
2566 ndisc_send_rs(ifp->idev->dev, &ifp->addr, &all_routers);
2568 spin_lock_bh(&ifp->lock);
2570 ifp->idev->if_flags |= IF_RS_SENT;
2571 addrconf_mod_timer(ifp, AC_RS, ifp->idev->cnf.rtr_solicit_interval);
2572 spin_unlock_bh(&ifp->lock);
2576 static void addrconf_dad_run(struct inet6_dev *idev) {
2577 struct inet6_ifaddr *ifp;
2579 read_lock_bh(&idev->lock);
2580 for (ifp = idev->addr_list; ifp; ifp = ifp->if_next) {
2581 spin_lock_bh(&ifp->lock);
2582 if (!(ifp->flags & IFA_F_TENTATIVE)) {
2583 spin_unlock_bh(&ifp->lock);
2586 spin_unlock_bh(&ifp->lock);
2587 addrconf_dad_kick(ifp);
2589 read_unlock_bh(&idev->lock);
2592 #ifdef CONFIG_PROC_FS
2593 struct if6_iter_state {
2597 static struct inet6_ifaddr *if6_get_first(struct seq_file *seq)
2599 struct inet6_ifaddr *ifa = NULL;
2600 struct if6_iter_state *state = seq->private;
2602 for (state->bucket = 0; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) {
2603 ifa = inet6_addr_lst[state->bucket];
2610 static struct inet6_ifaddr *if6_get_next(struct seq_file *seq, struct inet6_ifaddr *ifa)
2612 struct if6_iter_state *state = seq->private;
2614 ifa = ifa->lst_next;
2616 if (!ifa && ++state->bucket < IN6_ADDR_HSIZE) {
2617 ifa = inet6_addr_lst[state->bucket];
2623 static struct inet6_ifaddr *if6_get_idx(struct seq_file *seq, loff_t pos)
2625 struct inet6_ifaddr *ifa = if6_get_first(seq);
2628 while(pos && (ifa = if6_get_next(seq, ifa)) != NULL)
2630 return pos ? NULL : ifa;
2633 static void *if6_seq_start(struct seq_file *seq, loff_t *pos)
2635 read_lock_bh(&addrconf_hash_lock);
2636 return if6_get_idx(seq, *pos);
2639 static void *if6_seq_next(struct seq_file *seq, void *v, loff_t *pos)
2641 struct inet6_ifaddr *ifa;
2643 ifa = if6_get_next(seq, v);
2648 static void if6_seq_stop(struct seq_file *seq, void *v)
2650 read_unlock_bh(&addrconf_hash_lock);
2653 static int if6_seq_show(struct seq_file *seq, void *v)
2655 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *)v;
2657 NIP6_SEQFMT " %02x %02x %02x %02x %8s\n",
2659 ifp->idev->dev->ifindex,
2663 ifp->idev->dev->name);
2667 static struct seq_operations if6_seq_ops = {
2668 .start = if6_seq_start,
2669 .next = if6_seq_next,
2670 .show = if6_seq_show,
2671 .stop = if6_seq_stop,
2674 static int if6_seq_open(struct inode *inode, struct file *file)
2676 struct seq_file *seq;
2678 struct if6_iter_state *s = kzalloc(sizeof(*s), GFP_KERNEL);
2683 rc = seq_open(file, &if6_seq_ops);
2687 seq = file->private_data;
2696 static struct file_operations if6_fops = {
2697 .owner = THIS_MODULE,
2698 .open = if6_seq_open,
2700 .llseek = seq_lseek,
2701 .release = seq_release_private,
2704 int __init if6_proc_init(void)
2706 if (!proc_net_fops_create("if_inet6", S_IRUGO, &if6_fops))
2711 void if6_proc_exit(void)
2713 proc_net_remove("if_inet6");
2715 #endif /* CONFIG_PROC_FS */
2718 * Periodic address status verification
2721 static void addrconf_verify(unsigned long foo)
2723 struct inet6_ifaddr *ifp;
2724 unsigned long now, next;
2727 spin_lock_bh(&addrconf_verify_lock);
2729 next = now + ADDR_CHECK_FREQUENCY;
2731 del_timer(&addr_chk_timer);
2733 for (i=0; i < IN6_ADDR_HSIZE; i++) {
2736 read_lock(&addrconf_hash_lock);
2737 for (ifp=inet6_addr_lst[i]; ifp; ifp=ifp->lst_next) {
2739 #ifdef CONFIG_IPV6_PRIVACY
2740 unsigned long regen_advance;
2743 if (ifp->flags & IFA_F_PERMANENT)
2746 spin_lock(&ifp->lock);
2747 age = (now - ifp->tstamp) / HZ;
2749 #ifdef CONFIG_IPV6_PRIVACY
2750 regen_advance = ifp->idev->cnf.regen_max_retry *
2751 ifp->idev->cnf.dad_transmits *
2752 ifp->idev->nd_parms->retrans_time / HZ;
2755 if (age >= ifp->valid_lft) {
2756 spin_unlock(&ifp->lock);
2758 read_unlock(&addrconf_hash_lock);
2761 } else if (age >= ifp->prefered_lft) {
2762 /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */
2765 if (!(ifp->flags&IFA_F_DEPRECATED)) {
2767 ifp->flags |= IFA_F_DEPRECATED;
2770 if (time_before(ifp->tstamp + ifp->valid_lft * HZ, next))
2771 next = ifp->tstamp + ifp->valid_lft * HZ;
2773 spin_unlock(&ifp->lock);
2777 read_unlock(&addrconf_hash_lock);
2779 ipv6_ifa_notify(0, ifp);
2783 #ifdef CONFIG_IPV6_PRIVACY
2784 } else if ((ifp->flags&IFA_F_TEMPORARY) &&
2785 !(ifp->flags&IFA_F_TENTATIVE)) {
2786 if (age >= ifp->prefered_lft - regen_advance) {
2787 struct inet6_ifaddr *ifpub = ifp->ifpub;
2788 if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next))
2789 next = ifp->tstamp + ifp->prefered_lft * HZ;
2790 if (!ifp->regen_count && ifpub) {
2793 in6_ifa_hold(ifpub);
2794 spin_unlock(&ifp->lock);
2795 read_unlock(&addrconf_hash_lock);
2796 spin_lock(&ifpub->lock);
2797 ifpub->regen_count = 0;
2798 spin_unlock(&ifpub->lock);
2799 ipv6_create_tempaddr(ifpub, ifp);
2804 } else if (time_before(ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ, next))
2805 next = ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ;
2806 spin_unlock(&ifp->lock);
2809 /* ifp->prefered_lft <= ifp->valid_lft */
2810 if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next))
2811 next = ifp->tstamp + ifp->prefered_lft * HZ;
2812 spin_unlock(&ifp->lock);
2815 read_unlock(&addrconf_hash_lock);
2818 addr_chk_timer.expires = time_before(next, jiffies + HZ) ? jiffies + HZ : next;
2819 add_timer(&addr_chk_timer);
2820 spin_unlock_bh(&addrconf_verify_lock);
2824 inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
2826 struct rtattr **rta = arg;
2827 struct ifaddrmsg *ifm = NLMSG_DATA(nlh);
2828 struct in6_addr *pfx;
2831 if (rta[IFA_ADDRESS-1]) {
2832 if (RTA_PAYLOAD(rta[IFA_ADDRESS-1]) < sizeof(*pfx))
2834 pfx = RTA_DATA(rta[IFA_ADDRESS-1]);
2836 if (rta[IFA_LOCAL-1]) {
2837 if (pfx && memcmp(pfx, RTA_DATA(rta[IFA_LOCAL-1]), sizeof(*pfx)))
2839 pfx = RTA_DATA(rta[IFA_LOCAL-1]);
2844 return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen);
2848 inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
2850 struct rtattr **rta = arg;
2851 struct ifaddrmsg *ifm = NLMSG_DATA(nlh);
2852 struct in6_addr *pfx;
2855 if (rta[IFA_ADDRESS-1]) {
2856 if (RTA_PAYLOAD(rta[IFA_ADDRESS-1]) < sizeof(*pfx))
2858 pfx = RTA_DATA(rta[IFA_ADDRESS-1]);
2860 if (rta[IFA_LOCAL-1]) {
2861 if (pfx && memcmp(pfx, RTA_DATA(rta[IFA_LOCAL-1]), sizeof(*pfx)))
2863 pfx = RTA_DATA(rta[IFA_LOCAL-1]);
2868 return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen);
2871 /* Maximum length of ifa_cacheinfo attributes */
2872 #define INET6_IFADDR_RTA_SPACE \
2873 RTA_SPACE(16) /* IFA_ADDRESS */ + \
2874 RTA_SPACE(sizeof(struct ifa_cacheinfo)) /* CACHEINFO */
2876 static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
2877 u32 pid, u32 seq, int event, unsigned int flags)
2879 struct ifaddrmsg *ifm;
2880 struct nlmsghdr *nlh;
2881 struct ifa_cacheinfo ci;
2882 unsigned char *b = skb->tail;
2884 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
2885 ifm = NLMSG_DATA(nlh);
2886 ifm->ifa_family = AF_INET6;
2887 ifm->ifa_prefixlen = ifa->prefix_len;
2888 ifm->ifa_flags = ifa->flags;
2889 ifm->ifa_scope = RT_SCOPE_UNIVERSE;
2890 if (ifa->scope&IFA_HOST)
2891 ifm->ifa_scope = RT_SCOPE_HOST;
2892 else if (ifa->scope&IFA_LINK)
2893 ifm->ifa_scope = RT_SCOPE_LINK;
2894 else if (ifa->scope&IFA_SITE)
2895 ifm->ifa_scope = RT_SCOPE_SITE;
2896 ifm->ifa_index = ifa->idev->dev->ifindex;
2897 RTA_PUT(skb, IFA_ADDRESS, 16, &ifa->addr);
2898 if (!(ifa->flags&IFA_F_PERMANENT)) {
2899 ci.ifa_prefered = ifa->prefered_lft;
2900 ci.ifa_valid = ifa->valid_lft;
2901 if (ci.ifa_prefered != INFINITY_LIFE_TIME) {
2902 long tval = (jiffies - ifa->tstamp)/HZ;
2903 ci.ifa_prefered -= tval;
2904 if (ci.ifa_valid != INFINITY_LIFE_TIME)
2905 ci.ifa_valid -= tval;
2908 ci.ifa_prefered = INFINITY_LIFE_TIME;
2909 ci.ifa_valid = INFINITY_LIFE_TIME;
2911 ci.cstamp = (__u32)(TIME_DELTA(ifa->cstamp, INITIAL_JIFFIES) / HZ * 100
2912 + TIME_DELTA(ifa->cstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
2913 ci.tstamp = (__u32)(TIME_DELTA(ifa->tstamp, INITIAL_JIFFIES) / HZ * 100
2914 + TIME_DELTA(ifa->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
2915 RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci);
2916 nlh->nlmsg_len = skb->tail - b;
2921 skb_trim(skb, b - skb->data);
2925 static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca,
2926 u32 pid, u32 seq, int event, u16 flags)
2928 struct ifaddrmsg *ifm;
2929 struct nlmsghdr *nlh;
2930 struct ifa_cacheinfo ci;
2931 unsigned char *b = skb->tail;
2933 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
2934 ifm = NLMSG_DATA(nlh);
2935 ifm->ifa_family = AF_INET6;
2936 ifm->ifa_prefixlen = 128;
2937 ifm->ifa_flags = IFA_F_PERMANENT;
2938 ifm->ifa_scope = RT_SCOPE_UNIVERSE;
2939 if (ipv6_addr_scope(&ifmca->mca_addr)&IFA_SITE)
2940 ifm->ifa_scope = RT_SCOPE_SITE;
2941 ifm->ifa_index = ifmca->idev->dev->ifindex;
2942 RTA_PUT(skb, IFA_MULTICAST, 16, &ifmca->mca_addr);
2943 ci.cstamp = (__u32)(TIME_DELTA(ifmca->mca_cstamp, INITIAL_JIFFIES) / HZ
2944 * 100 + TIME_DELTA(ifmca->mca_cstamp, INITIAL_JIFFIES) % HZ
2946 ci.tstamp = (__u32)(TIME_DELTA(ifmca->mca_tstamp, INITIAL_JIFFIES) / HZ
2947 * 100 + TIME_DELTA(ifmca->mca_tstamp, INITIAL_JIFFIES) % HZ
2949 ci.ifa_prefered = INFINITY_LIFE_TIME;
2950 ci.ifa_valid = INFINITY_LIFE_TIME;
2951 RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci);
2952 nlh->nlmsg_len = skb->tail - b;
2957 skb_trim(skb, b - skb->data);
2961 static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca,
2962 u32 pid, u32 seq, int event, unsigned int flags)
2964 struct ifaddrmsg *ifm;
2965 struct nlmsghdr *nlh;
2966 struct ifa_cacheinfo ci;
2967 unsigned char *b = skb->tail;
2969 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
2970 ifm = NLMSG_DATA(nlh);
2971 ifm->ifa_family = AF_INET6;
2972 ifm->ifa_prefixlen = 128;
2973 ifm->ifa_flags = IFA_F_PERMANENT;
2974 ifm->ifa_scope = RT_SCOPE_UNIVERSE;
2975 if (ipv6_addr_scope(&ifaca->aca_addr)&IFA_SITE)
2976 ifm->ifa_scope = RT_SCOPE_SITE;
2977 ifm->ifa_index = ifaca->aca_idev->dev->ifindex;
2978 RTA_PUT(skb, IFA_ANYCAST, 16, &ifaca->aca_addr);
2979 ci.cstamp = (__u32)(TIME_DELTA(ifaca->aca_cstamp, INITIAL_JIFFIES) / HZ
2980 * 100 + TIME_DELTA(ifaca->aca_cstamp, INITIAL_JIFFIES) % HZ
2982 ci.tstamp = (__u32)(TIME_DELTA(ifaca->aca_tstamp, INITIAL_JIFFIES) / HZ
2983 * 100 + TIME_DELTA(ifaca->aca_tstamp, INITIAL_JIFFIES) % HZ
2985 ci.ifa_prefered = INFINITY_LIFE_TIME;
2986 ci.ifa_valid = INFINITY_LIFE_TIME;
2987 RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci);
2988 nlh->nlmsg_len = skb->tail - b;
2993 skb_trim(skb, b - skb->data);
3004 static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
3005 enum addr_type_t type)
3008 int s_idx, s_ip_idx;
3010 struct net_device *dev;
3011 struct inet6_dev *idev = NULL;
3012 struct inet6_ifaddr *ifa;
3013 struct ifmcaddr6 *ifmca;
3014 struct ifacaddr6 *ifaca;
3016 s_idx = cb->args[0];
3017 s_ip_idx = ip_idx = cb->args[1];
3018 read_lock(&dev_base_lock);
3020 for (dev = dev_base, idx = 0; dev; dev = dev->next, idx++) {
3026 if ((idev = in6_dev_get(dev)) == NULL)
3028 read_lock_bh(&idev->lock);
3031 /* unicast address incl. temp addr */
3032 for (ifa = idev->addr_list; ifa;
3033 ifa = ifa->if_next, ip_idx++) {
3034 if (ip_idx < s_ip_idx)
3036 if ((err = inet6_fill_ifaddr(skb, ifa,
3037 NETLINK_CB(cb->skb).pid,
3038 cb->nlh->nlmsg_seq, RTM_NEWADDR,
3043 case MULTICAST_ADDR:
3044 /* multicast address */
3045 for (ifmca = idev->mc_list; ifmca;
3046 ifmca = ifmca->next, ip_idx++) {
3047 if (ip_idx < s_ip_idx)
3049 if ((err = inet6_fill_ifmcaddr(skb, ifmca,
3050 NETLINK_CB(cb->skb).pid,
3051 cb->nlh->nlmsg_seq, RTM_GETMULTICAST,
3057 /* anycast address */
3058 for (ifaca = idev->ac_list; ifaca;
3059 ifaca = ifaca->aca_next, ip_idx++) {
3060 if (ip_idx < s_ip_idx)
3062 if ((err = inet6_fill_ifacaddr(skb, ifaca,
3063 NETLINK_CB(cb->skb).pid,
3064 cb->nlh->nlmsg_seq, RTM_GETANYCAST,
3072 read_unlock_bh(&idev->lock);
3077 read_unlock_bh(&idev->lock);
3080 read_unlock(&dev_base_lock);
3082 cb->args[1] = ip_idx;
3086 static int inet6_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
3088 enum addr_type_t type = UNICAST_ADDR;
3089 return inet6_dump_addr(skb, cb, type);
3092 static int inet6_dump_ifmcaddr(struct sk_buff *skb, struct netlink_callback *cb)
3094 enum addr_type_t type = MULTICAST_ADDR;
3095 return inet6_dump_addr(skb, cb, type);
3099 static int inet6_dump_ifacaddr(struct sk_buff *skb, struct netlink_callback *cb)
3101 enum addr_type_t type = ANYCAST_ADDR;
3102 return inet6_dump_addr(skb, cb, type);
3105 static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
3107 struct sk_buff *skb;
3108 int size = NLMSG_SPACE(sizeof(struct ifaddrmsg) + INET6_IFADDR_RTA_SPACE);
3110 skb = alloc_skb(size, GFP_ATOMIC);
3112 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFADDR, ENOBUFS);
3115 if (inet6_fill_ifaddr(skb, ifa, current->pid, 0, event, 0) < 0) {
3117 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFADDR, EINVAL);
3120 NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_IFADDR;
3121 netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_IFADDR, GFP_ATOMIC);
3124 static void inline ipv6_store_devconf(struct ipv6_devconf *cnf,
3125 __s32 *array, int bytes)
3127 memset(array, 0, bytes);
3128 array[DEVCONF_FORWARDING] = cnf->forwarding;
3129 array[DEVCONF_HOPLIMIT] = cnf->hop_limit;
3130 array[DEVCONF_MTU6] = cnf->mtu6;
3131 array[DEVCONF_ACCEPT_RA] = cnf->accept_ra;
3132 array[DEVCONF_ACCEPT_REDIRECTS] = cnf->accept_redirects;
3133 array[DEVCONF_AUTOCONF] = cnf->autoconf;
3134 array[DEVCONF_DAD_TRANSMITS] = cnf->dad_transmits;
3135 array[DEVCONF_RTR_SOLICITS] = cnf->rtr_solicits;
3136 array[DEVCONF_RTR_SOLICIT_INTERVAL] = cnf->rtr_solicit_interval;
3137 array[DEVCONF_RTR_SOLICIT_DELAY] = cnf->rtr_solicit_delay;
3138 array[DEVCONF_FORCE_MLD_VERSION] = cnf->force_mld_version;
3139 #ifdef CONFIG_IPV6_PRIVACY
3140 array[DEVCONF_USE_TEMPADDR] = cnf->use_tempaddr;
3141 array[DEVCONF_TEMP_VALID_LFT] = cnf->temp_valid_lft;
3142 array[DEVCONF_TEMP_PREFERED_LFT] = cnf->temp_prefered_lft;
3143 array[DEVCONF_REGEN_MAX_RETRY] = cnf->regen_max_retry;
3144 array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor;
3146 array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses;
3147 array[DEVCONF_ACCEPT_RA_DEFRTR] = cnf->accept_ra_defrtr;
3148 array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo;
3149 #ifdef CONFIG_IPV6_ROUTER_PREF
3150 array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref;
3151 array[DEVCONF_RTR_PROBE_INTERVAL] = cnf->rtr_probe_interval;
3152 #ifdef CONFIV_IPV6_ROUTE_INFO
3153 array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen;
3158 /* Maximum length of ifinfomsg attributes */
3159 #define INET6_IFINFO_RTA_SPACE \
3160 RTA_SPACE(IFNAMSIZ) /* IFNAME */ + \
3161 RTA_SPACE(MAX_ADDR_LEN) /* ADDRESS */ + \
3162 RTA_SPACE(sizeof(u32)) /* MTU */ + \
3163 RTA_SPACE(sizeof(int)) /* LINK */ + \
3164 RTA_SPACE(0) /* PROTINFO */ + \
3165 RTA_SPACE(sizeof(u32)) /* FLAGS */ + \
3166 RTA_SPACE(sizeof(struct ifla_cacheinfo)) /* CACHEINFO */ + \
3167 RTA_SPACE(sizeof(__s32[DEVCONF_MAX])) /* CONF */
3169 static int inet6_fill_ifinfo(struct sk_buff *skb, struct inet6_dev *idev,
3170 u32 pid, u32 seq, int event, unsigned int flags)
3172 struct net_device *dev = idev->dev;
3173 __s32 *array = NULL;
3174 struct ifinfomsg *r;
3175 struct nlmsghdr *nlh;
3176 unsigned char *b = skb->tail;
3177 struct rtattr *subattr;
3178 __u32 mtu = dev->mtu;
3179 struct ifla_cacheinfo ci;
3181 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags);
3182 r = NLMSG_DATA(nlh);
3183 r->ifi_family = AF_INET6;
3185 r->ifi_type = dev->type;
3186 r->ifi_index = dev->ifindex;
3187 r->ifi_flags = dev_get_flags(dev);
3190 RTA_PUT(skb, IFLA_IFNAME, strlen(dev->name)+1, dev->name);
3193 RTA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr);
3195 RTA_PUT(skb, IFLA_MTU, sizeof(mtu), &mtu);
3196 if (dev->ifindex != dev->iflink)
3197 RTA_PUT(skb, IFLA_LINK, sizeof(int), &dev->iflink);
3199 subattr = (struct rtattr*)skb->tail;
3201 RTA_PUT(skb, IFLA_PROTINFO, 0, NULL);
3203 /* return the device flags */
3204 RTA_PUT(skb, IFLA_INET6_FLAGS, sizeof(__u32), &idev->if_flags);
3206 /* return interface cacheinfo */
3207 ci.max_reasm_len = IPV6_MAXPLEN;
3208 ci.tstamp = (__u32)(TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) / HZ * 100
3209 + TIME_DELTA(idev->tstamp, INITIAL_JIFFIES) % HZ * 100 / HZ);
3210 ci.reachable_time = idev->nd_parms->reachable_time;
3211 ci.retrans_time = idev->nd_parms->retrans_time;
3212 RTA_PUT(skb, IFLA_INET6_CACHEINFO, sizeof(ci), &ci);
3214 /* return the device sysctl params */
3215 if ((array = kmalloc(DEVCONF_MAX * sizeof(*array), GFP_ATOMIC)) == NULL)
3216 goto rtattr_failure;
3217 ipv6_store_devconf(&idev->cnf, array, DEVCONF_MAX * sizeof(*array));
3218 RTA_PUT(skb, IFLA_INET6_CONF, DEVCONF_MAX * sizeof(*array), array);
3220 /* XXX - Statistics/MC not implemented */
3221 subattr->rta_len = skb->tail - (u8*)subattr;
3223 nlh->nlmsg_len = skb->tail - b;
3230 skb_trim(skb, b - skb->data);
3234 static int inet6_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
3237 int s_idx = cb->args[0];
3238 struct net_device *dev;
3239 struct inet6_dev *idev;
3241 read_lock(&dev_base_lock);
3242 for (dev=dev_base, idx=0; dev; dev = dev->next, idx++) {
3245 if ((idev = in6_dev_get(dev)) == NULL)
3247 err = inet6_fill_ifinfo(skb, idev, NETLINK_CB(cb->skb).pid,
3248 cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI);
3253 read_unlock(&dev_base_lock);
3259 void inet6_ifinfo_notify(int event, struct inet6_dev *idev)
3261 struct sk_buff *skb;
3262 int size = NLMSG_SPACE(sizeof(struct ifinfomsg) + INET6_IFINFO_RTA_SPACE);
3264 skb = alloc_skb(size, GFP_ATOMIC);
3266 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFINFO, ENOBUFS);
3269 if (inet6_fill_ifinfo(skb, idev, current->pid, 0, event, 0) < 0) {
3271 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_IFINFO, EINVAL);
3274 NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_IFINFO;
3275 netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_IFINFO, GFP_ATOMIC);
3278 /* Maximum length of prefix_cacheinfo attributes */
3279 #define INET6_PREFIX_RTA_SPACE \
3280 RTA_SPACE(sizeof(((struct prefix_info *)NULL)->prefix)) /* ADDRESS */ + \
3281 RTA_SPACE(sizeof(struct prefix_cacheinfo)) /* CACHEINFO */
3283 static int inet6_fill_prefix(struct sk_buff *skb, struct inet6_dev *idev,
3284 struct prefix_info *pinfo, u32 pid, u32 seq,
3285 int event, unsigned int flags)
3287 struct prefixmsg *pmsg;
3288 struct nlmsghdr *nlh;
3289 unsigned char *b = skb->tail;
3290 struct prefix_cacheinfo ci;
3292 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*pmsg), flags);
3293 pmsg = NLMSG_DATA(nlh);
3294 pmsg->prefix_family = AF_INET6;
3295 pmsg->prefix_pad1 = 0;
3296 pmsg->prefix_pad2 = 0;
3297 pmsg->prefix_ifindex = idev->dev->ifindex;
3298 pmsg->prefix_len = pinfo->prefix_len;
3299 pmsg->prefix_type = pinfo->type;
3300 pmsg->prefix_pad3 = 0;
3302 pmsg->prefix_flags = 0;
3304 pmsg->prefix_flags |= IF_PREFIX_ONLINK;
3305 if (pinfo->autoconf)
3306 pmsg->prefix_flags |= IF_PREFIX_AUTOCONF;
3308 RTA_PUT(skb, PREFIX_ADDRESS, sizeof(pinfo->prefix), &pinfo->prefix);
3310 ci.preferred_time = ntohl(pinfo->prefered);
3311 ci.valid_time = ntohl(pinfo->valid);
3312 RTA_PUT(skb, PREFIX_CACHEINFO, sizeof(ci), &ci);
3314 nlh->nlmsg_len = skb->tail - b;
3319 skb_trim(skb, b - skb->data);
3323 static void inet6_prefix_notify(int event, struct inet6_dev *idev,
3324 struct prefix_info *pinfo)
3326 struct sk_buff *skb;
3327 int size = NLMSG_SPACE(sizeof(struct prefixmsg) + INET6_PREFIX_RTA_SPACE);
3329 skb = alloc_skb(size, GFP_ATOMIC);
3331 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_PREFIX, ENOBUFS);
3334 if (inet6_fill_prefix(skb, idev, pinfo, current->pid, 0, event, 0) < 0) {
3336 netlink_set_err(rtnl, 0, RTNLGRP_IPV6_PREFIX, EINVAL);
3339 NETLINK_CB(skb).dst_group = RTNLGRP_IPV6_PREFIX;
3340 netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV6_PREFIX, GFP_ATOMIC);
3343 static struct rtnetlink_link inet6_rtnetlink_table[RTM_NR_MSGTYPES] = {
3344 [RTM_GETLINK - RTM_BASE] = { .dumpit = inet6_dump_ifinfo, },
3345 [RTM_NEWADDR - RTM_BASE] = { .doit = inet6_rtm_newaddr, },
3346 [RTM_DELADDR - RTM_BASE] = { .doit = inet6_rtm_deladdr, },
3347 [RTM_GETADDR - RTM_BASE] = { .dumpit = inet6_dump_ifaddr, },
3348 [RTM_GETMULTICAST - RTM_BASE] = { .dumpit = inet6_dump_ifmcaddr, },
3349 [RTM_GETANYCAST - RTM_BASE] = { .dumpit = inet6_dump_ifacaddr, },
3350 [RTM_NEWROUTE - RTM_BASE] = { .doit = inet6_rtm_newroute, },
3351 [RTM_DELROUTE - RTM_BASE] = { .doit = inet6_rtm_delroute, },
3352 [RTM_GETROUTE - RTM_BASE] = { .doit = inet6_rtm_getroute,
3353 .dumpit = inet6_dump_fib, },
3356 static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3358 inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
3362 ip6_ins_rt(ifp->rt, NULL, NULL, NULL);
3363 if (ifp->idev->cnf.forwarding)
3364 addrconf_join_anycast(ifp);
3367 if (ifp->idev->cnf.forwarding)
3368 addrconf_leave_anycast(ifp);
3369 addrconf_leave_solict(ifp->idev, &ifp->addr);
3370 dst_hold(&ifp->rt->u.dst);
3371 if (ip6_del_rt(ifp->rt, NULL, NULL, NULL))
3372 dst_free(&ifp->rt->u.dst);
3377 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
3379 read_lock_bh(&addrconf_lock);
3380 if (likely(ifp->idev->dead == 0))
3381 __ipv6_ifa_notify(event, ifp);
3382 read_unlock_bh(&addrconf_lock);
3385 #ifdef CONFIG_SYSCTL
3388 int addrconf_sysctl_forward(ctl_table *ctl, int write, struct file * filp,
3389 void __user *buffer, size_t *lenp, loff_t *ppos)
3391 int *valp = ctl->data;
3395 ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
3397 if (write && valp != &ipv6_devconf_dflt.forwarding) {
3398 if (valp != &ipv6_devconf.forwarding) {
3399 if ((!*valp) ^ (!val)) {
3400 struct inet6_dev *idev = (struct inet6_dev *)ctl->extra1;
3403 dev_forward_change(idev);
3406 ipv6_devconf_dflt.forwarding = ipv6_devconf.forwarding;
3407 addrconf_forward_change();
3410 rt6_purge_dflt_routers();
3416 static int addrconf_sysctl_forward_strategy(ctl_table *table,
3417 int __user *name, int nlen,
3418 void __user *oldval,
3419 size_t __user *oldlenp,
3420 void __user *newval, size_t newlen,
3423 int *valp = table->data;
3426 if (!newval || !newlen)
3428 if (newlen != sizeof(int))
3430 if (get_user(new, (int __user *)newval))
3434 if (oldval && oldlenp) {
3436 if (get_user(len, oldlenp))
3439 if (len > table->maxlen)
3440 len = table->maxlen;
3441 if (copy_to_user(oldval, valp, len))
3443 if (put_user(len, oldlenp))
3448 if (valp != &ipv6_devconf_dflt.forwarding) {
3449 if (valp != &ipv6_devconf.forwarding) {
3450 struct inet6_dev *idev = (struct inet6_dev *)table->extra1;
3452 if (unlikely(idev == NULL))
3454 changed = (!*valp) ^ (!new);
3457 dev_forward_change(idev);
3460 addrconf_forward_change();
3464 rt6_purge_dflt_routers();
3471 static struct addrconf_sysctl_table
3473 struct ctl_table_header *sysctl_header;
3474 ctl_table addrconf_vars[__NET_IPV6_MAX];
3475 ctl_table addrconf_dev[2];
3476 ctl_table addrconf_conf_dir[2];
3477 ctl_table addrconf_proto_dir[2];
3478 ctl_table addrconf_root_dir[2];
3479 } addrconf_sysctl = {
3480 .sysctl_header = NULL,
3483 .ctl_name = NET_IPV6_FORWARDING,
3484 .procname = "forwarding",
3485 .data = &ipv6_devconf.forwarding,
3486 .maxlen = sizeof(int),
3488 .proc_handler = &addrconf_sysctl_forward,
3489 .strategy = &addrconf_sysctl_forward_strategy,
3492 .ctl_name = NET_IPV6_HOP_LIMIT,
3493 .procname = "hop_limit",
3494 .data = &ipv6_devconf.hop_limit,
3495 .maxlen = sizeof(int),
3497 .proc_handler = proc_dointvec,
3500 .ctl_name = NET_IPV6_MTU,
3502 .data = &ipv6_devconf.mtu6,
3503 .maxlen = sizeof(int),
3505 .proc_handler = &proc_dointvec,
3508 .ctl_name = NET_IPV6_ACCEPT_RA,
3509 .procname = "accept_ra",
3510 .data = &ipv6_devconf.accept_ra,
3511 .maxlen = sizeof(int),
3513 .proc_handler = &proc_dointvec,
3516 .ctl_name = NET_IPV6_ACCEPT_REDIRECTS,
3517 .procname = "accept_redirects",
3518 .data = &ipv6_devconf.accept_redirects,
3519 .maxlen = sizeof(int),
3521 .proc_handler = &proc_dointvec,
3524 .ctl_name = NET_IPV6_AUTOCONF,
3525 .procname = "autoconf",
3526 .data = &ipv6_devconf.autoconf,
3527 .maxlen = sizeof(int),
3529 .proc_handler = &proc_dointvec,
3532 .ctl_name = NET_IPV6_DAD_TRANSMITS,
3533 .procname = "dad_transmits",
3534 .data = &ipv6_devconf.dad_transmits,
3535 .maxlen = sizeof(int),
3537 .proc_handler = &proc_dointvec,
3540 .ctl_name = NET_IPV6_RTR_SOLICITS,
3541 .procname = "router_solicitations",
3542 .data = &ipv6_devconf.rtr_solicits,
3543 .maxlen = sizeof(int),
3545 .proc_handler = &proc_dointvec,
3548 .ctl_name = NET_IPV6_RTR_SOLICIT_INTERVAL,
3549 .procname = "router_solicitation_interval",
3550 .data = &ipv6_devconf.rtr_solicit_interval,
3551 .maxlen = sizeof(int),
3553 .proc_handler = &proc_dointvec_jiffies,
3554 .strategy = &sysctl_jiffies,
3557 .ctl_name = NET_IPV6_RTR_SOLICIT_DELAY,
3558 .procname = "router_solicitation_delay",
3559 .data = &ipv6_devconf.rtr_solicit_delay,
3560 .maxlen = sizeof(int),
3562 .proc_handler = &proc_dointvec_jiffies,
3563 .strategy = &sysctl_jiffies,
3566 .ctl_name = NET_IPV6_FORCE_MLD_VERSION,
3567 .procname = "force_mld_version",
3568 .data = &ipv6_devconf.force_mld_version,
3569 .maxlen = sizeof(int),
3571 .proc_handler = &proc_dointvec,
3573 #ifdef CONFIG_IPV6_PRIVACY
3575 .ctl_name = NET_IPV6_USE_TEMPADDR,
3576 .procname = "use_tempaddr",
3577 .data = &ipv6_devconf.use_tempaddr,
3578 .maxlen = sizeof(int),
3580 .proc_handler = &proc_dointvec,
3583 .ctl_name = NET_IPV6_TEMP_VALID_LFT,
3584 .procname = "temp_valid_lft",
3585 .data = &ipv6_devconf.temp_valid_lft,
3586 .maxlen = sizeof(int),
3588 .proc_handler = &proc_dointvec,
3591 .ctl_name = NET_IPV6_TEMP_PREFERED_LFT,
3592 .procname = "temp_prefered_lft",
3593 .data = &ipv6_devconf.temp_prefered_lft,
3594 .maxlen = sizeof(int),
3596 .proc_handler = &proc_dointvec,
3599 .ctl_name = NET_IPV6_REGEN_MAX_RETRY,
3600 .procname = "regen_max_retry",
3601 .data = &ipv6_devconf.regen_max_retry,
3602 .maxlen = sizeof(int),
3604 .proc_handler = &proc_dointvec,
3607 .ctl_name = NET_IPV6_MAX_DESYNC_FACTOR,
3608 .procname = "max_desync_factor",
3609 .data = &ipv6_devconf.max_desync_factor,
3610 .maxlen = sizeof(int),
3612 .proc_handler = &proc_dointvec,
3616 .ctl_name = NET_IPV6_MAX_ADDRESSES,
3617 .procname = "max_addresses",
3618 .data = &ipv6_devconf.max_addresses,
3619 .maxlen = sizeof(int),
3621 .proc_handler = &proc_dointvec,
3624 .ctl_name = NET_IPV6_ACCEPT_RA_DEFRTR,
3625 .procname = "accept_ra_defrtr",
3626 .data = &ipv6_devconf.accept_ra_defrtr,
3627 .maxlen = sizeof(int),
3629 .proc_handler = &proc_dointvec,
3632 .ctl_name = NET_IPV6_ACCEPT_RA_PINFO,
3633 .procname = "accept_ra_pinfo",
3634 .data = &ipv6_devconf.accept_ra_pinfo,
3635 .maxlen = sizeof(int),
3637 .proc_handler = &proc_dointvec,
3639 #ifdef CONFIG_IPV6_ROUTER_PREF
3641 .ctl_name = NET_IPV6_ACCEPT_RA_RTR_PREF,
3642 .procname = "accept_ra_rtr_pref",
3643 .data = &ipv6_devconf.accept_ra_rtr_pref,
3644 .maxlen = sizeof(int),
3646 .proc_handler = &proc_dointvec,
3649 .ctl_name = NET_IPV6_RTR_PROBE_INTERVAL,
3650 .procname = "router_probe_interval",
3651 .data = &ipv6_devconf.rtr_probe_interval,
3652 .maxlen = sizeof(int),
3654 .proc_handler = &proc_dointvec_jiffies,
3655 .strategy = &sysctl_jiffies,
3657 #ifdef CONFIV_IPV6_ROUTE_INFO
3659 .ctl_name = NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN,
3660 .procname = "accept_ra_rt_info_max_plen",
3661 .data = &ipv6_devconf.accept_ra_rt_info_max_plen,
3662 .maxlen = sizeof(int),
3664 .proc_handler = &proc_dointvec,
3669 .ctl_name = 0, /* sentinel */
3674 .ctl_name = NET_PROTO_CONF_ALL,
3677 .child = addrconf_sysctl.addrconf_vars,
3680 .ctl_name = 0, /* sentinel */
3683 .addrconf_conf_dir = {
3685 .ctl_name = NET_IPV6_CONF,
3688 .child = addrconf_sysctl.addrconf_dev,
3691 .ctl_name = 0, /* sentinel */
3694 .addrconf_proto_dir = {
3696 .ctl_name = NET_IPV6,
3699 .child = addrconf_sysctl.addrconf_conf_dir,
3702 .ctl_name = 0, /* sentinel */
3705 .addrconf_root_dir = {
3707 .ctl_name = CTL_NET,
3710 .child = addrconf_sysctl.addrconf_proto_dir,
3713 .ctl_name = 0, /* sentinel */
3718 static void addrconf_sysctl_register(struct inet6_dev *idev, struct ipv6_devconf *p)
3721 struct net_device *dev = idev ? idev->dev : NULL;
3722 struct addrconf_sysctl_table *t;
3723 char *dev_name = NULL;
3725 t = kmalloc(sizeof(*t), GFP_KERNEL);
3728 memcpy(t, &addrconf_sysctl, sizeof(*t));
3729 for (i=0; t->addrconf_vars[i].data; i++) {
3730 t->addrconf_vars[i].data += (char*)p - (char*)&ipv6_devconf;
3731 t->addrconf_vars[i].de = NULL;
3732 t->addrconf_vars[i].extra1 = idev; /* embedded; no ref */
3735 dev_name = dev->name;
3736 t->addrconf_dev[0].ctl_name = dev->ifindex;
3738 dev_name = "default";
3739 t->addrconf_dev[0].ctl_name = NET_PROTO_CONF_DEFAULT;
3743 * Make a copy of dev_name, because '.procname' is regarded as const
3744 * by sysctl and we wouldn't want anyone to change it under our feet
3745 * (see SIOCSIFNAME).
3747 dev_name = kstrdup(dev_name, GFP_KERNEL);
3751 t->addrconf_dev[0].procname = dev_name;
3753 t->addrconf_dev[0].child = t->addrconf_vars;
3754 t->addrconf_dev[0].de = NULL;
3755 t->addrconf_conf_dir[0].child = t->addrconf_dev;
3756 t->addrconf_conf_dir[0].de = NULL;
3757 t->addrconf_proto_dir[0].child = t->addrconf_conf_dir;
3758 t->addrconf_proto_dir[0].de = NULL;
3759 t->addrconf_root_dir[0].child = t->addrconf_proto_dir;
3760 t->addrconf_root_dir[0].de = NULL;
3762 t->sysctl_header = register_sysctl_table(t->addrconf_root_dir, 0);
3763 if (t->sysctl_header == NULL)
3778 static void addrconf_sysctl_unregister(struct ipv6_devconf *p)
3781 struct addrconf_sysctl_table *t = p->sysctl;
3783 unregister_sysctl_table(t->sysctl_header);
3784 kfree(t->addrconf_dev[0].procname);
3796 int register_inet6addr_notifier(struct notifier_block *nb)
3798 return atomic_notifier_chain_register(&inet6addr_chain, nb);
3801 int unregister_inet6addr_notifier(struct notifier_block *nb)
3803 return atomic_notifier_chain_unregister(&inet6addr_chain,nb);
3807 * Init / cleanup code
3810 int __init addrconf_init(void)
3814 /* The addrconf netdev notifier requires that loopback_dev
3815 * has it's ipv6 private information allocated and setup
3816 * before it can bring up and give link-local addresses
3817 * to other devices which are up.
3819 * Unfortunately, loopback_dev is not necessarily the first
3820 * entry in the global dev_base list of net devices. In fact,
3821 * it is likely to be the very last entry on that list.
3822 * So this causes the notifier registry below to try and
3823 * give link-local addresses to all devices besides loopback_dev
3824 * first, then loopback_dev, which cases all the non-loopback_dev
3825 * devices to fail to get a link-local address.
3827 * So, as a temporary fix, allocate the ipv6 structure for
3828 * loopback_dev first by hand.
3829 * Longer term, all of the dependencies ipv6 has upon the loopback
3830 * device and it being up should be removed.
3833 if (!ipv6_add_dev(&loopback_dev))
3839 ip6_null_entry.rt6i_idev = in6_dev_get(&loopback_dev);
3841 register_netdevice_notifier(&ipv6_dev_notf);
3844 rtnetlink_links[PF_INET6] = inet6_rtnetlink_table;
3845 #ifdef CONFIG_SYSCTL
3846 addrconf_sysctl.sysctl_header =
3847 register_sysctl_table(addrconf_sysctl.addrconf_root_dir, 0);
3848 addrconf_sysctl_register(NULL, &ipv6_devconf_dflt);
3854 void __exit addrconf_cleanup(void)
3856 struct net_device *dev;
3857 struct inet6_dev *idev;
3858 struct inet6_ifaddr *ifa;
3861 unregister_netdevice_notifier(&ipv6_dev_notf);
3863 rtnetlink_links[PF_INET6] = NULL;
3864 #ifdef CONFIG_SYSCTL
3865 addrconf_sysctl_unregister(&ipv6_devconf_dflt);
3866 addrconf_sysctl_unregister(&ipv6_devconf);
3875 for (dev=dev_base; dev; dev=dev->next) {
3876 if ((idev = __in6_dev_get(dev)) == NULL)
3878 addrconf_ifdown(dev, 1);
3880 addrconf_ifdown(&loopback_dev, 2);
3886 write_lock_bh(&addrconf_hash_lock);
3887 for (i=0; i < IN6_ADDR_HSIZE; i++) {
3888 for (ifa=inet6_addr_lst[i]; ifa; ) {
3889 struct inet6_ifaddr *bifa;
3892 ifa = ifa->lst_next;
3893 printk(KERN_DEBUG "bug: IPv6 address leakage detected: ifa=%p\n", bifa);
3894 /* Do not free it; something is wrong.
3895 Now we can investigate it with debugger.
3899 write_unlock_bh(&addrconf_hash_lock);
3901 del_timer(&addr_chk_timer);
3905 #ifdef CONFIG_PROC_FS
3906 proc_net_remove("if_inet6");