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 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
18 * Janos Farkas : delete timer on ifdown
19 * <chexum@bankinf.banki.hu>
20 * Andi Kleen : kill double kfree on module
22 * Maciej W. Rozycki : FDDI support
23 * sekiya@USAGI : Don't send too many RS
25 * yoshfuji@USAGI : Fixed interval between DAD
27 * YOSHIFUJI Hideaki @USAGI : improved accuracy of
28 * address validation timer.
29 * YOSHIFUJI Hideaki @USAGI : Privacy Extensions (RFC3041)
31 * Yuji SEKIYA @USAGI : Don't assign a same IPv6
32 * address on a same interface.
33 * YOSHIFUJI Hideaki @USAGI : ARCnet support
34 * YOSHIFUJI Hideaki @USAGI : convert /proc/net/if_inet6 to
36 * YOSHIFUJI Hideaki @USAGI : improved source address
37 * selection; consider scope,
41 #include <linux/errno.h>
42 #include <linux/types.h>
43 #include <linux/socket.h>
44 #include <linux/sockios.h>
45 #include <linux/net.h>
46 #include <linux/in6.h>
47 #include <linux/netdevice.h>
48 #include <linux/if_addr.h>
49 #include <linux/if_arp.h>
50 #include <linux/if_arcnet.h>
51 #include <linux/if_infiniband.h>
52 #include <linux/route.h>
53 #include <linux/inetdevice.h>
54 #include <linux/init.h>
56 #include <linux/sysctl.h>
58 #include <linux/capability.h>
59 #include <linux/delay.h>
60 #include <linux/notifier.h>
61 #include <linux/string.h>
63 #include <net/net_namespace.h>
68 #include <net/protocol.h>
69 #include <net/ndisc.h>
70 #include <net/ip6_route.h>
71 #include <net/addrconf.h>
74 #include <net/netlink.h>
75 #include <net/pkt_sched.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>
84 #include <asm/unaligned.h>
86 #include <linux/proc_fs.h>
87 #include <linux/seq_file.h>
89 /* Set to 3 to get tracing... */
93 #define ADBG(x) printk x
98 #define INFINITY_LIFE_TIME 0xFFFFFFFF
99 #define TIME_DELTA(a,b) ((unsigned long)((long)(a) - (long)(b)))
102 static void addrconf_sysctl_register(struct inet6_dev
*idev
);
103 static void addrconf_sysctl_unregister(struct inet6_dev
*idev
);
105 static inline void addrconf_sysctl_register(struct inet6_dev
*idev
)
109 static inline void addrconf_sysctl_unregister(struct inet6_dev
*idev
)
114 #ifdef CONFIG_IPV6_PRIVACY
115 static int __ipv6_regen_rndid(struct inet6_dev
*idev
);
116 static int __ipv6_try_regen_rndid(struct inet6_dev
*idev
, struct in6_addr
*tmpaddr
);
117 static void ipv6_regen_rndid(unsigned long data
);
119 static int desync_factor
= MAX_DESYNC_FACTOR
* HZ
;
122 static int ipv6_count_addresses(struct inet6_dev
*idev
);
125 * Configured unicast address hash table
127 static struct inet6_ifaddr
*inet6_addr_lst
[IN6_ADDR_HSIZE
];
128 static DEFINE_RWLOCK(addrconf_hash_lock
);
130 static void addrconf_verify(unsigned long);
132 static DEFINE_TIMER(addr_chk_timer
, addrconf_verify
, 0, 0);
133 static DEFINE_SPINLOCK(addrconf_verify_lock
);
135 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
);
136 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
);
138 static int addrconf_ifdown(struct net_device
*dev
, int how
);
140 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
);
141 static void addrconf_dad_timer(unsigned long data
);
142 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
);
143 static void addrconf_dad_run(struct inet6_dev
*idev
);
144 static void addrconf_rs_timer(unsigned long data
);
145 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
);
146 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
);
148 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
149 struct prefix_info
*pinfo
);
150 static int ipv6_chk_same_addr(struct net
*net
, const struct in6_addr
*addr
,
151 struct net_device
*dev
);
153 static ATOMIC_NOTIFIER_HEAD(inet6addr_chain
);
155 struct ipv6_devconf ipv6_devconf __read_mostly
= {
157 .hop_limit
= IPV6_DEFAULT_HOPLIMIT
,
158 .mtu6
= IPV6_MIN_MTU
,
160 .accept_redirects
= 1,
162 .force_mld_version
= 0,
164 .rtr_solicits
= MAX_RTR_SOLICITATIONS
,
165 .rtr_solicit_interval
= RTR_SOLICITATION_INTERVAL
,
166 .rtr_solicit_delay
= MAX_RTR_SOLICITATION_DELAY
,
167 #ifdef CONFIG_IPV6_PRIVACY
169 .temp_valid_lft
= TEMP_VALID_LIFETIME
,
170 .temp_prefered_lft
= TEMP_PREFERRED_LIFETIME
,
171 .regen_max_retry
= REGEN_MAX_RETRY
,
172 .max_desync_factor
= MAX_DESYNC_FACTOR
,
174 .max_addresses
= IPV6_MAX_ADDRESSES
,
175 .accept_ra_defrtr
= 1,
176 .accept_ra_pinfo
= 1,
177 #ifdef CONFIG_IPV6_ROUTER_PREF
178 .accept_ra_rtr_pref
= 1,
179 .rtr_probe_interval
= 60 * HZ
,
180 #ifdef CONFIG_IPV6_ROUTE_INFO
181 .accept_ra_rt_info_max_plen
= 0,
185 .accept_source_route
= 0, /* we do not accept RH0 by default. */
188 static struct ipv6_devconf ipv6_devconf_dflt __read_mostly
= {
190 .hop_limit
= IPV6_DEFAULT_HOPLIMIT
,
191 .mtu6
= IPV6_MIN_MTU
,
193 .accept_redirects
= 1,
196 .rtr_solicits
= MAX_RTR_SOLICITATIONS
,
197 .rtr_solicit_interval
= RTR_SOLICITATION_INTERVAL
,
198 .rtr_solicit_delay
= MAX_RTR_SOLICITATION_DELAY
,
199 #ifdef CONFIG_IPV6_PRIVACY
201 .temp_valid_lft
= TEMP_VALID_LIFETIME
,
202 .temp_prefered_lft
= TEMP_PREFERRED_LIFETIME
,
203 .regen_max_retry
= REGEN_MAX_RETRY
,
204 .max_desync_factor
= MAX_DESYNC_FACTOR
,
206 .max_addresses
= IPV6_MAX_ADDRESSES
,
207 .accept_ra_defrtr
= 1,
208 .accept_ra_pinfo
= 1,
209 #ifdef CONFIG_IPV6_ROUTER_PREF
210 .accept_ra_rtr_pref
= 1,
211 .rtr_probe_interval
= 60 * HZ
,
212 #ifdef CONFIG_IPV6_ROUTE_INFO
213 .accept_ra_rt_info_max_plen
= 0,
217 .accept_source_route
= 0, /* we do not accept RH0 by default. */
220 /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
221 const struct in6_addr in6addr_any
= IN6ADDR_ANY_INIT
;
222 const struct in6_addr in6addr_loopback
= IN6ADDR_LOOPBACK_INIT
;
223 const struct in6_addr in6addr_linklocal_allnodes
= IN6ADDR_LINKLOCAL_ALLNODES_INIT
;
224 const struct in6_addr in6addr_linklocal_allrouters
= IN6ADDR_LINKLOCAL_ALLROUTERS_INIT
;
226 /* Check if a valid qdisc is available */
227 static inline int addrconf_qdisc_ok(struct net_device
*dev
)
229 return (dev
->qdisc
!= &noop_qdisc
);
232 /* Check if a route is valid prefix route */
233 static inline int addrconf_is_prefix_route(const struct rt6_info
*rt
)
235 return ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0);
238 static void addrconf_del_timer(struct inet6_ifaddr
*ifp
)
240 if (del_timer(&ifp
->timer
))
244 enum addrconf_timer_t
251 static void addrconf_mod_timer(struct inet6_ifaddr
*ifp
,
252 enum addrconf_timer_t what
,
255 if (!del_timer(&ifp
->timer
))
260 ifp
->timer
.function
= addrconf_dad_timer
;
263 ifp
->timer
.function
= addrconf_rs_timer
;
267 ifp
->timer
.expires
= jiffies
+ when
;
268 add_timer(&ifp
->timer
);
271 static int snmp6_alloc_dev(struct inet6_dev
*idev
)
273 if (snmp_mib_init((void **)idev
->stats
.ipv6
,
274 sizeof(struct ipstats_mib
)) < 0)
276 if (snmp_mib_init((void **)idev
->stats
.icmpv6
,
277 sizeof(struct icmpv6_mib
)) < 0)
279 if (snmp_mib_init((void **)idev
->stats
.icmpv6msg
,
280 sizeof(struct icmpv6msg_mib
)) < 0)
286 snmp_mib_free((void **)idev
->stats
.icmpv6
);
288 snmp_mib_free((void **)idev
->stats
.ipv6
);
293 static void snmp6_free_dev(struct inet6_dev
*idev
)
295 snmp_mib_free((void **)idev
->stats
.icmpv6msg
);
296 snmp_mib_free((void **)idev
->stats
.icmpv6
);
297 snmp_mib_free((void **)idev
->stats
.ipv6
);
300 /* Nobody refers to this device, we may destroy it. */
302 static void in6_dev_finish_destroy_rcu(struct rcu_head
*head
)
304 struct inet6_dev
*idev
= container_of(head
, struct inet6_dev
, rcu
);
308 void in6_dev_finish_destroy(struct inet6_dev
*idev
)
310 struct net_device
*dev
= idev
->dev
;
311 BUG_TRAP(idev
->addr_list
==NULL
);
312 BUG_TRAP(idev
->mc_list
==NULL
);
313 #ifdef NET_REFCNT_DEBUG
314 printk(KERN_DEBUG
"in6_dev_finish_destroy: %s\n", dev
? dev
->name
: "NIL");
318 printk("Freeing alive inet6 device %p\n", idev
);
321 snmp6_free_dev(idev
);
322 call_rcu(&idev
->rcu
, in6_dev_finish_destroy_rcu
);
325 EXPORT_SYMBOL(in6_dev_finish_destroy
);
327 static struct inet6_dev
* ipv6_add_dev(struct net_device
*dev
)
329 struct inet6_dev
*ndev
;
333 if (dev
->mtu
< IPV6_MIN_MTU
)
336 ndev
= kzalloc(sizeof(struct inet6_dev
), GFP_KERNEL
);
341 rwlock_init(&ndev
->lock
);
343 memcpy(&ndev
->cnf
, dev_net(dev
)->ipv6
.devconf_dflt
, sizeof(ndev
->cnf
));
344 ndev
->cnf
.mtu6
= dev
->mtu
;
345 ndev
->cnf
.sysctl
= NULL
;
346 ndev
->nd_parms
= neigh_parms_alloc(dev
, &nd_tbl
);
347 if (ndev
->nd_parms
== NULL
) {
351 /* We refer to the device */
354 if (snmp6_alloc_dev(ndev
) < 0) {
356 "%s(): cannot allocate memory for statistics; dev=%s.\n",
357 __func__
, dev
->name
));
358 neigh_parms_release(&nd_tbl
, ndev
->nd_parms
);
360 in6_dev_finish_destroy(ndev
);
364 if (snmp6_register_dev(ndev
) < 0) {
366 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
367 __func__
, dev
->name
));
368 neigh_parms_release(&nd_tbl
, ndev
->nd_parms
);
370 in6_dev_finish_destroy(ndev
);
374 /* One reference from device. We must do this before
375 * we invoke __ipv6_regen_rndid().
379 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
380 if (dev
->type
== ARPHRD_SIT
&& (dev
->priv_flags
& IFF_ISATAP
)) {
382 "%s: Disabled Multicast RS\n",
384 ndev
->cnf
.rtr_solicits
= 0;
388 #ifdef CONFIG_IPV6_PRIVACY
389 setup_timer(&ndev
->regen_timer
, ipv6_regen_rndid
, (unsigned long)ndev
);
390 if ((dev
->flags
&IFF_LOOPBACK
) ||
391 dev
->type
== ARPHRD_TUNNEL
||
392 dev
->type
== ARPHRD_TUNNEL6
||
393 dev
->type
== ARPHRD_SIT
||
394 dev
->type
== ARPHRD_NONE
) {
396 "%s: Disabled Privacy Extensions\n",
398 ndev
->cnf
.use_tempaddr
= -1;
401 ipv6_regen_rndid((unsigned long) ndev
);
405 if (netif_running(dev
) && addrconf_qdisc_ok(dev
))
406 ndev
->if_flags
|= IF_READY
;
408 ipv6_mc_init_dev(ndev
);
409 ndev
->tstamp
= jiffies
;
410 addrconf_sysctl_register(ndev
);
411 /* protected by rtnl_lock */
412 rcu_assign_pointer(dev
->ip6_ptr
, ndev
);
414 /* Join all-node multicast group */
415 ipv6_dev_mc_inc(dev
, &in6addr_linklocal_allnodes
);
420 static struct inet6_dev
* ipv6_find_idev(struct net_device
*dev
)
422 struct inet6_dev
*idev
;
426 if ((idev
= __in6_dev_get(dev
)) == NULL
) {
427 if ((idev
= ipv6_add_dev(dev
)) == NULL
)
431 if (dev
->flags
&IFF_UP
)
437 static void dev_forward_change(struct inet6_dev
*idev
)
439 struct net_device
*dev
;
440 struct inet6_ifaddr
*ifa
;
445 if (dev
&& (dev
->flags
& IFF_MULTICAST
)) {
446 if (idev
->cnf
.forwarding
)
447 ipv6_dev_mc_inc(dev
, &in6addr_linklocal_allrouters
);
449 ipv6_dev_mc_dec(dev
, &in6addr_linklocal_allrouters
);
451 for (ifa
=idev
->addr_list
; ifa
; ifa
=ifa
->if_next
) {
452 if (ifa
->flags
&IFA_F_TENTATIVE
)
454 if (idev
->cnf
.forwarding
)
455 addrconf_join_anycast(ifa
);
457 addrconf_leave_anycast(ifa
);
462 static void addrconf_forward_change(struct net
*net
, __s32 newf
)
464 struct net_device
*dev
;
465 struct inet6_dev
*idev
;
467 read_lock(&dev_base_lock
);
468 for_each_netdev(net
, dev
) {
470 idev
= __in6_dev_get(dev
);
472 int changed
= (!idev
->cnf
.forwarding
) ^ (!newf
);
473 idev
->cnf
.forwarding
= newf
;
475 dev_forward_change(idev
);
479 read_unlock(&dev_base_lock
);
482 static void addrconf_fixup_forwarding(struct ctl_table
*table
, int *p
, int old
)
486 net
= (struct net
*)table
->extra2
;
487 if (p
== &net
->ipv6
.devconf_dflt
->forwarding
)
490 if (p
== &net
->ipv6
.devconf_all
->forwarding
) {
491 __s32 newf
= net
->ipv6
.devconf_all
->forwarding
;
492 net
->ipv6
.devconf_dflt
->forwarding
= newf
;
493 addrconf_forward_change(net
, newf
);
494 } else if ((!*p
) ^ (!old
))
495 dev_forward_change((struct inet6_dev
*)table
->extra1
);
498 rt6_purge_dflt_routers(net
);
502 /* Nobody refers to this ifaddr, destroy it */
504 void inet6_ifa_finish_destroy(struct inet6_ifaddr
*ifp
)
506 BUG_TRAP(ifp
->if_next
==NULL
);
507 BUG_TRAP(ifp
->lst_next
==NULL
);
508 #ifdef NET_REFCNT_DEBUG
509 printk(KERN_DEBUG
"inet6_ifa_finish_destroy\n");
512 in6_dev_put(ifp
->idev
);
514 if (del_timer(&ifp
->timer
))
515 printk("Timer is still running, when freeing ifa=%p\n", ifp
);
518 printk("Freeing alive inet6 address %p\n", ifp
);
521 dst_release(&ifp
->rt
->u
.dst
);
527 ipv6_link_dev_addr(struct inet6_dev
*idev
, struct inet6_ifaddr
*ifp
)
529 struct inet6_ifaddr
*ifa
, **ifap
;
530 int ifp_scope
= ipv6_addr_src_scope(&ifp
->addr
);
533 * Each device address list is sorted in order of scope -
534 * global before linklocal.
536 for (ifap
= &idev
->addr_list
; (ifa
= *ifap
) != NULL
;
537 ifap
= &ifa
->if_next
) {
538 if (ifp_scope
>= ipv6_addr_src_scope(&ifa
->addr
))
542 ifp
->if_next
= *ifap
;
547 * Hash function taken from net_alias.c
549 static u8
ipv6_addr_hash(const struct in6_addr
*addr
)
554 * We perform the hash function over the last 64 bits of the address
555 * This will include the IEEE address token on links that support it.
558 word
= (__force u32
)(addr
->s6_addr32
[2] ^ addr
->s6_addr32
[3]);
559 word
^= (word
>> 16);
562 return ((word
^ (word
>> 4)) & 0x0f);
565 /* On success it returns ifp with increased reference count */
567 static struct inet6_ifaddr
*
568 ipv6_add_addr(struct inet6_dev
*idev
, const struct in6_addr
*addr
, int pfxlen
,
569 int scope
, u32 flags
)
571 struct inet6_ifaddr
*ifa
= NULL
;
578 err
= -ENODEV
; /*XXX*/
582 write_lock(&addrconf_hash_lock
);
584 /* Ignore adding duplicate addresses on an interface */
585 if (ipv6_chk_same_addr(dev_net(idev
->dev
), addr
, idev
->dev
)) {
586 ADBG(("ipv6_add_addr: already assigned\n"));
591 ifa
= kzalloc(sizeof(struct inet6_ifaddr
), GFP_ATOMIC
);
594 ADBG(("ipv6_add_addr: malloc failed\n"));
599 rt
= addrconf_dst_alloc(idev
, addr
, 0);
605 ipv6_addr_copy(&ifa
->addr
, addr
);
607 spin_lock_init(&ifa
->lock
);
608 init_timer(&ifa
->timer
);
609 ifa
->timer
.data
= (unsigned long) ifa
;
611 ifa
->prefix_len
= pfxlen
;
612 ifa
->flags
= flags
| IFA_F_TENTATIVE
;
613 ifa
->cstamp
= ifa
->tstamp
= jiffies
;
618 * part one of RFC 4429, section 3.3
619 * We should not configure an address as
620 * optimistic if we do not yet know the link
621 * layer address of our nexhop router
624 if (rt
->rt6i_nexthop
== NULL
)
625 ifa
->flags
&= ~IFA_F_OPTIMISTIC
;
632 /* Add to big hash table */
633 hash
= ipv6_addr_hash(addr
);
635 ifa
->lst_next
= inet6_addr_lst
[hash
];
636 inet6_addr_lst
[hash
] = ifa
;
638 write_unlock(&addrconf_hash_lock
);
640 write_lock(&idev
->lock
);
641 /* Add to inet6_dev unicast addr list. */
642 ipv6_link_dev_addr(idev
, ifa
);
644 #ifdef CONFIG_IPV6_PRIVACY
645 if (ifa
->flags
&IFA_F_TEMPORARY
) {
646 ifa
->tmp_next
= idev
->tempaddr_list
;
647 idev
->tempaddr_list
= ifa
;
653 write_unlock(&idev
->lock
);
655 rcu_read_unlock_bh();
657 if (likely(err
== 0))
658 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_UP
, ifa
);
666 write_unlock(&addrconf_hash_lock
);
670 /* This function wants to get referenced ifp and releases it before return */
672 static void ipv6_del_addr(struct inet6_ifaddr
*ifp
)
674 struct inet6_ifaddr
*ifa
, **ifap
;
675 struct inet6_dev
*idev
= ifp
->idev
;
677 int deleted
= 0, onlink
= 0;
678 unsigned long expires
= jiffies
;
680 hash
= ipv6_addr_hash(&ifp
->addr
);
684 write_lock_bh(&addrconf_hash_lock
);
685 for (ifap
= &inet6_addr_lst
[hash
]; (ifa
=*ifap
) != NULL
;
686 ifap
= &ifa
->lst_next
) {
688 *ifap
= ifa
->lst_next
;
690 ifa
->lst_next
= NULL
;
694 write_unlock_bh(&addrconf_hash_lock
);
696 write_lock_bh(&idev
->lock
);
697 #ifdef CONFIG_IPV6_PRIVACY
698 if (ifp
->flags
&IFA_F_TEMPORARY
) {
699 for (ifap
= &idev
->tempaddr_list
; (ifa
=*ifap
) != NULL
;
700 ifap
= &ifa
->tmp_next
) {
702 *ifap
= ifa
->tmp_next
;
704 in6_ifa_put(ifp
->ifpub
);
708 ifa
->tmp_next
= NULL
;
715 for (ifap
= &idev
->addr_list
; (ifa
=*ifap
) != NULL
;) {
717 *ifap
= ifa
->if_next
;
720 if (!(ifp
->flags
& IFA_F_PERMANENT
) || onlink
> 0)
724 } else if (ifp
->flags
& IFA_F_PERMANENT
) {
725 if (ipv6_prefix_equal(&ifa
->addr
, &ifp
->addr
,
727 if (ifa
->flags
& IFA_F_PERMANENT
) {
732 unsigned long lifetime
;
737 spin_lock(&ifa
->lock
);
739 lifetime
= addrconf_timeout_fixup(ifa
->valid_lft
, HZ
);
741 * Note: Because this address is
742 * not permanent, lifetime <
743 * LONG_MAX / HZ here.
745 if (time_before(expires
,
746 ifa
->tstamp
+ lifetime
* HZ
))
747 expires
= ifa
->tstamp
+ lifetime
* HZ
;
748 spin_unlock(&ifa
->lock
);
752 ifap
= &ifa
->if_next
;
754 write_unlock_bh(&idev
->lock
);
756 ipv6_ifa_notify(RTM_DELADDR
, ifp
);
758 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_DOWN
, ifp
);
760 addrconf_del_timer(ifp
);
763 * Purge or update corresponding prefix
765 * 1) we don't purge prefix here if address was not permanent.
766 * prefix is managed by its own lifetime.
767 * 2) if there're no addresses, delete prefix.
768 * 3) if there're still other permanent address(es),
769 * corresponding prefix is still permanent.
770 * 4) otherwise, update prefix lifetime to the
771 * longest valid lifetime among the corresponding
772 * addresses on the device.
773 * Note: subsequent RA will update lifetime.
777 if ((ifp
->flags
& IFA_F_PERMANENT
) && onlink
< 1) {
778 struct in6_addr prefix
;
780 struct net
*net
= dev_net(ifp
->idev
->dev
);
781 ipv6_addr_prefix(&prefix
, &ifp
->addr
, ifp
->prefix_len
);
782 rt
= rt6_lookup(net
, &prefix
, NULL
, ifp
->idev
->dev
->ifindex
, 1);
784 if (rt
&& addrconf_is_prefix_route(rt
)) {
788 } else if (!(rt
->rt6i_flags
& RTF_EXPIRES
)) {
789 rt
->rt6i_expires
= expires
;
790 rt
->rt6i_flags
|= RTF_EXPIRES
;
793 dst_release(&rt
->u
.dst
);
799 #ifdef CONFIG_IPV6_PRIVACY
800 static int ipv6_create_tempaddr(struct inet6_ifaddr
*ifp
, struct inet6_ifaddr
*ift
)
802 struct inet6_dev
*idev
= ifp
->idev
;
803 struct in6_addr addr
, *tmpaddr
;
804 unsigned long tmp_prefered_lft
, tmp_valid_lft
, tmp_cstamp
, tmp_tstamp
;
805 unsigned long regen_advance
;
811 write_lock(&idev
->lock
);
813 spin_lock_bh(&ift
->lock
);
814 memcpy(&addr
.s6_addr
[8], &ift
->addr
.s6_addr
[8], 8);
815 spin_unlock_bh(&ift
->lock
);
822 if (idev
->cnf
.use_tempaddr
<= 0) {
823 write_unlock(&idev
->lock
);
825 "ipv6_create_tempaddr(): use_tempaddr is disabled.\n");
830 spin_lock_bh(&ifp
->lock
);
831 if (ifp
->regen_count
++ >= idev
->cnf
.regen_max_retry
) {
832 idev
->cnf
.use_tempaddr
= -1; /*XXX*/
833 spin_unlock_bh(&ifp
->lock
);
834 write_unlock(&idev
->lock
);
836 "ipv6_create_tempaddr(): regeneration time exceeded. disabled temporary address support.\n");
842 memcpy(addr
.s6_addr
, ifp
->addr
.s6_addr
, 8);
843 if (__ipv6_try_regen_rndid(idev
, tmpaddr
) < 0) {
844 spin_unlock_bh(&ifp
->lock
);
845 write_unlock(&idev
->lock
);
847 "ipv6_create_tempaddr(): regeneration of randomized interface id failed.\n");
853 memcpy(&addr
.s6_addr
[8], idev
->rndid
, 8);
854 tmp_valid_lft
= min_t(__u32
,
856 idev
->cnf
.temp_valid_lft
);
857 tmp_prefered_lft
= min_t(__u32
,
859 idev
->cnf
.temp_prefered_lft
- desync_factor
/ HZ
);
860 tmp_plen
= ifp
->prefix_len
;
861 max_addresses
= idev
->cnf
.max_addresses
;
862 tmp_cstamp
= ifp
->cstamp
;
863 tmp_tstamp
= ifp
->tstamp
;
864 spin_unlock_bh(&ifp
->lock
);
866 regen_advance
= idev
->cnf
.regen_max_retry
*
867 idev
->cnf
.dad_transmits
*
868 idev
->nd_parms
->retrans_time
/ HZ
;
869 write_unlock(&idev
->lock
);
871 /* A temporary address is created only if this calculated Preferred
872 * Lifetime is greater than REGEN_ADVANCE time units. In particular,
873 * an implementation must not create a temporary address with a zero
874 * Preferred Lifetime.
876 if (tmp_prefered_lft
<= regen_advance
) {
883 addr_flags
= IFA_F_TEMPORARY
;
884 /* set in addrconf_prefix_rcv() */
885 if (ifp
->flags
& IFA_F_OPTIMISTIC
)
886 addr_flags
|= IFA_F_OPTIMISTIC
;
888 ift
= !max_addresses
||
889 ipv6_count_addresses(idev
) < max_addresses
?
890 ipv6_add_addr(idev
, &addr
, tmp_plen
,
891 ipv6_addr_type(&addr
)&IPV6_ADDR_SCOPE_MASK
,
893 if (!ift
|| IS_ERR(ift
)) {
897 "ipv6_create_tempaddr(): retry temporary address regeneration.\n");
899 write_lock(&idev
->lock
);
903 spin_lock_bh(&ift
->lock
);
905 ift
->valid_lft
= tmp_valid_lft
;
906 ift
->prefered_lft
= tmp_prefered_lft
;
907 ift
->cstamp
= tmp_cstamp
;
908 ift
->tstamp
= tmp_tstamp
;
909 spin_unlock_bh(&ift
->lock
);
911 addrconf_dad_start(ift
, 0);
920 * Choose an appropriate source address (RFC3484)
923 IPV6_SADDR_RULE_INIT
= 0,
924 IPV6_SADDR_RULE_LOCAL
,
925 IPV6_SADDR_RULE_SCOPE
,
926 IPV6_SADDR_RULE_PREFERRED
,
927 #ifdef CONFIG_IPV6_MIP6
931 IPV6_SADDR_RULE_LABEL
,
932 #ifdef CONFIG_IPV6_PRIVACY
933 IPV6_SADDR_RULE_PRIVACY
,
935 IPV6_SADDR_RULE_ORCHID
,
936 IPV6_SADDR_RULE_PREFIX
,
940 struct ipv6_saddr_score
{
943 struct inet6_ifaddr
*ifa
;
944 DECLARE_BITMAP(scorebits
, IPV6_SADDR_RULE_MAX
);
949 struct ipv6_saddr_dst
{
950 const struct in6_addr
*addr
;
957 static inline int ipv6_saddr_preferred(int type
)
959 if (type
& (IPV6_ADDR_MAPPED
|IPV6_ADDR_COMPATv4
|
960 IPV6_ADDR_LOOPBACK
|IPV6_ADDR_RESERVED
))
965 static int ipv6_get_saddr_eval(struct net
*net
,
966 struct ipv6_saddr_score
*score
,
967 struct ipv6_saddr_dst
*dst
,
972 if (i
<= score
->rule
) {
974 case IPV6_SADDR_RULE_SCOPE
:
975 ret
= score
->scopedist
;
977 case IPV6_SADDR_RULE_PREFIX
:
978 ret
= score
->matchlen
;
981 ret
= !!test_bit(i
, score
->scorebits
);
987 case IPV6_SADDR_RULE_INIT
:
988 /* Rule 0: remember if hiscore is not ready yet */
991 case IPV6_SADDR_RULE_LOCAL
:
992 /* Rule 1: Prefer same address */
993 ret
= ipv6_addr_equal(&score
->ifa
->addr
, dst
->addr
);
995 case IPV6_SADDR_RULE_SCOPE
:
996 /* Rule 2: Prefer appropriate scope
1001 * ---+--+-+---> scope
1003 * | d is scope of the destination.
1005 * | \ <- smaller scope is better if
1006 * B-15 | \ if scope is enough for destinaion.
1007 * | ret = B - scope (-1 <= scope >= d <= 15).
1009 * |/ <- greater is better
1010 * -C / if scope is not enough for destination.
1011 * /| ret = scope - C (-1 <= d < scope <= 15).
1013 * d - C - 1 < B -15 (for all -1 <= d <= 15).
1014 * C > d + 14 - B >= 15 + 14 - B = 29 - B.
1015 * Assume B = 0 and we get C > 29.
1017 ret
= __ipv6_addr_src_scope(score
->addr_type
);
1018 if (ret
>= dst
->scope
)
1021 ret
-= 128; /* 30 is enough */
1022 score
->scopedist
= ret
;
1024 case IPV6_SADDR_RULE_PREFERRED
:
1025 /* Rule 3: Avoid deprecated and optimistic addresses */
1026 ret
= ipv6_saddr_preferred(score
->addr_type
) ||
1027 !(score
->ifa
->flags
& (IFA_F_DEPRECATED
|IFA_F_OPTIMISTIC
));
1029 #ifdef CONFIG_IPV6_MIP6
1030 case IPV6_SADDR_RULE_HOA
:
1032 /* Rule 4: Prefer home address */
1033 int prefhome
= !(dst
->prefs
& IPV6_PREFER_SRC_COA
);
1034 ret
= !(score
->ifa
->flags
& IFA_F_HOMEADDRESS
) ^ prefhome
;
1038 case IPV6_SADDR_RULE_OIF
:
1039 /* Rule 5: Prefer outgoing interface */
1040 ret
= (!dst
->ifindex
||
1041 dst
->ifindex
== score
->ifa
->idev
->dev
->ifindex
);
1043 case IPV6_SADDR_RULE_LABEL
:
1044 /* Rule 6: Prefer matching label */
1045 ret
= ipv6_addr_label(net
,
1046 &score
->ifa
->addr
, score
->addr_type
,
1047 score
->ifa
->idev
->dev
->ifindex
) == dst
->label
;
1049 #ifdef CONFIG_IPV6_PRIVACY
1050 case IPV6_SADDR_RULE_PRIVACY
:
1052 /* Rule 7: Prefer public address
1053 * Note: prefer temprary address if use_tempaddr >= 2
1055 int preftmp
= dst
->prefs
& (IPV6_PREFER_SRC_PUBLIC
|IPV6_PREFER_SRC_TMP
) ?
1056 !!(dst
->prefs
& IPV6_PREFER_SRC_TMP
) :
1057 score
->ifa
->idev
->cnf
.use_tempaddr
>= 2;
1058 ret
= (!(score
->ifa
->flags
& IFA_F_TEMPORARY
)) ^ preftmp
;
1062 case IPV6_SADDR_RULE_ORCHID
:
1063 /* Rule 8-: Prefer ORCHID vs ORCHID or
1064 * non-ORCHID vs non-ORCHID
1066 ret
= !(ipv6_addr_orchid(&score
->ifa
->addr
) ^
1067 ipv6_addr_orchid(dst
->addr
));
1069 case IPV6_SADDR_RULE_PREFIX
:
1070 /* Rule 8: Use longest matching prefix */
1071 score
->matchlen
= ret
= ipv6_addr_diff(&score
->ifa
->addr
,
1079 __set_bit(i
, score
->scorebits
);
1085 int ipv6_dev_get_saddr(struct net_device
*dst_dev
,
1086 const struct in6_addr
*daddr
, unsigned int prefs
,
1087 struct in6_addr
*saddr
)
1089 struct ipv6_saddr_score scores
[2],
1090 *score
= &scores
[0], *hiscore
= &scores
[1];
1091 struct net
*net
= dev_net(dst_dev
);
1092 struct ipv6_saddr_dst dst
;
1093 struct net_device
*dev
;
1096 dst_type
= __ipv6_addr_type(daddr
);
1098 dst
.ifindex
= dst_dev
? dst_dev
->ifindex
: 0;
1099 dst
.scope
= __ipv6_addr_src_scope(dst_type
);
1100 dst
.label
= ipv6_addr_label(net
, daddr
, dst_type
, dst
.ifindex
);
1104 hiscore
->ifa
= NULL
;
1106 read_lock(&dev_base_lock
);
1109 for_each_netdev(net
, dev
) {
1110 struct inet6_dev
*idev
;
1112 /* Candidate Source Address (section 4)
1113 * - multicast and link-local destination address,
1114 * the set of candidate source address MUST only
1115 * include addresses assigned to interfaces
1116 * belonging to the same link as the outgoing
1118 * (- For site-local destination addresses, the
1119 * set of candidate source addresses MUST only
1120 * include addresses assigned to interfaces
1121 * belonging to the same site as the outgoing
1124 if (((dst_type
& IPV6_ADDR_MULTICAST
) ||
1125 dst
.scope
<= IPV6_ADDR_SCOPE_LINKLOCAL
) &&
1126 dst
.ifindex
&& dev
->ifindex
!= dst
.ifindex
)
1129 idev
= __in6_dev_get(dev
);
1133 read_lock_bh(&idev
->lock
);
1134 for (score
->ifa
= idev
->addr_list
; score
->ifa
; score
->ifa
= score
->ifa
->if_next
) {
1138 * - Tentative Address (RFC2462 section 5.4)
1139 * - A tentative address is not considered
1140 * "assigned to an interface" in the traditional
1141 * sense, unless it is also flagged as optimistic.
1142 * - Candidate Source Address (section 4)
1143 * - In any case, anycast addresses, multicast
1144 * addresses, and the unspecified address MUST
1145 * NOT be included in a candidate set.
1147 if ((score
->ifa
->flags
& IFA_F_TENTATIVE
) &&
1148 (!(score
->ifa
->flags
& IFA_F_OPTIMISTIC
)))
1151 score
->addr_type
= __ipv6_addr_type(&score
->ifa
->addr
);
1153 if (unlikely(score
->addr_type
== IPV6_ADDR_ANY
||
1154 score
->addr_type
& IPV6_ADDR_MULTICAST
)) {
1155 LIMIT_NETDEBUG(KERN_DEBUG
1156 "ADDRCONF: unspecified / multicast address "
1157 "assigned as unicast address on %s",
1163 bitmap_zero(score
->scorebits
, IPV6_SADDR_RULE_MAX
);
1165 for (i
= 0; i
< IPV6_SADDR_RULE_MAX
; i
++) {
1166 int minihiscore
, miniscore
;
1168 minihiscore
= ipv6_get_saddr_eval(net
, hiscore
, &dst
, i
);
1169 miniscore
= ipv6_get_saddr_eval(net
, score
, &dst
, i
);
1171 if (minihiscore
> miniscore
) {
1172 if (i
== IPV6_SADDR_RULE_SCOPE
&&
1173 score
->scopedist
> 0) {
1176 * each remaining entry
1177 * has too small (not enough)
1178 * scope, because ifa entries
1179 * are sorted by their scope
1185 } else if (minihiscore
< miniscore
) {
1186 struct ipv6_saddr_score
*tmp
;
1189 in6_ifa_put(hiscore
->ifa
);
1191 in6_ifa_hold(score
->ifa
);
1197 /* restore our iterator */
1198 score
->ifa
= hiscore
->ifa
;
1205 read_unlock_bh(&idev
->lock
);
1208 read_unlock(&dev_base_lock
);
1211 return -EADDRNOTAVAIL
;
1213 ipv6_addr_copy(saddr
, &hiscore
->ifa
->addr
);
1214 in6_ifa_put(hiscore
->ifa
);
1218 EXPORT_SYMBOL(ipv6_dev_get_saddr
);
1220 int ipv6_get_lladdr(struct net_device
*dev
, struct in6_addr
*addr
,
1221 unsigned char banned_flags
)
1223 struct inet6_dev
*idev
;
1224 int err
= -EADDRNOTAVAIL
;
1227 if ((idev
= __in6_dev_get(dev
)) != NULL
) {
1228 struct inet6_ifaddr
*ifp
;
1230 read_lock_bh(&idev
->lock
);
1231 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1232 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
& banned_flags
)) {
1233 ipv6_addr_copy(addr
, &ifp
->addr
);
1238 read_unlock_bh(&idev
->lock
);
1244 static int ipv6_count_addresses(struct inet6_dev
*idev
)
1247 struct inet6_ifaddr
*ifp
;
1249 read_lock_bh(&idev
->lock
);
1250 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
)
1252 read_unlock_bh(&idev
->lock
);
1256 int ipv6_chk_addr(struct net
*net
, struct in6_addr
*addr
,
1257 struct net_device
*dev
, int strict
)
1259 struct inet6_ifaddr
* ifp
;
1260 u8 hash
= ipv6_addr_hash(addr
);
1262 read_lock_bh(&addrconf_hash_lock
);
1263 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1264 if (!net_eq(dev_net(ifp
->idev
->dev
), net
))
1266 if (ipv6_addr_equal(&ifp
->addr
, addr
) &&
1267 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1268 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1269 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
))
1273 read_unlock_bh(&addrconf_hash_lock
);
1276 EXPORT_SYMBOL(ipv6_chk_addr
);
1279 int ipv6_chk_same_addr(struct net
*net
, const struct in6_addr
*addr
,
1280 struct net_device
*dev
)
1282 struct inet6_ifaddr
* ifp
;
1283 u8 hash
= ipv6_addr_hash(addr
);
1285 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1286 if (!net_eq(dev_net(ifp
->idev
->dev
), net
))
1288 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1289 if (dev
== NULL
|| ifp
->idev
->dev
== dev
)
1296 int ipv6_chk_prefix(struct in6_addr
*addr
, struct net_device
*dev
)
1298 struct inet6_dev
*idev
;
1299 struct inet6_ifaddr
*ifa
;
1304 idev
= __in6_dev_get(dev
);
1306 read_lock_bh(&idev
->lock
);
1307 for (ifa
= idev
->addr_list
; ifa
; ifa
= ifa
->if_next
) {
1308 onlink
= ipv6_prefix_equal(addr
, &ifa
->addr
,
1313 read_unlock_bh(&idev
->lock
);
1319 EXPORT_SYMBOL(ipv6_chk_prefix
);
1321 struct inet6_ifaddr
*ipv6_get_ifaddr(struct net
*net
, const struct in6_addr
*addr
,
1322 struct net_device
*dev
, int strict
)
1324 struct inet6_ifaddr
* ifp
;
1325 u8 hash
= ipv6_addr_hash(addr
);
1327 read_lock_bh(&addrconf_hash_lock
);
1328 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1329 if (!net_eq(dev_net(ifp
->idev
->dev
), net
))
1331 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1332 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1333 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
)) {
1339 read_unlock_bh(&addrconf_hash_lock
);
1344 int ipv6_rcv_saddr_equal(const struct sock
*sk
, const struct sock
*sk2
)
1346 const struct in6_addr
*sk_rcv_saddr6
= &inet6_sk(sk
)->rcv_saddr
;
1347 const struct in6_addr
*sk2_rcv_saddr6
= inet6_rcv_saddr(sk2
);
1348 __be32 sk_rcv_saddr
= inet_sk(sk
)->rcv_saddr
;
1349 __be32 sk2_rcv_saddr
= inet_rcv_saddr(sk2
);
1350 int sk_ipv6only
= ipv6_only_sock(sk
);
1351 int sk2_ipv6only
= inet_v6_ipv6only(sk2
);
1352 int addr_type
= ipv6_addr_type(sk_rcv_saddr6
);
1353 int addr_type2
= sk2_rcv_saddr6
? ipv6_addr_type(sk2_rcv_saddr6
) : IPV6_ADDR_MAPPED
;
1355 if (!sk2_rcv_saddr
&& !sk_ipv6only
)
1358 if (addr_type2
== IPV6_ADDR_ANY
&&
1359 !(sk2_ipv6only
&& addr_type
== IPV6_ADDR_MAPPED
))
1362 if (addr_type
== IPV6_ADDR_ANY
&&
1363 !(sk_ipv6only
&& addr_type2
== IPV6_ADDR_MAPPED
))
1366 if (sk2_rcv_saddr6
&&
1367 ipv6_addr_equal(sk_rcv_saddr6
, sk2_rcv_saddr6
))
1370 if (addr_type
== IPV6_ADDR_MAPPED
&&
1372 (!sk2_rcv_saddr
|| !sk_rcv_saddr
|| sk_rcv_saddr
== sk2_rcv_saddr
))
1378 /* Gets referenced address, destroys ifaddr */
1380 static void addrconf_dad_stop(struct inet6_ifaddr
*ifp
)
1382 if (ifp
->flags
&IFA_F_PERMANENT
) {
1383 spin_lock_bh(&ifp
->lock
);
1384 addrconf_del_timer(ifp
);
1385 ifp
->flags
|= IFA_F_TENTATIVE
;
1386 spin_unlock_bh(&ifp
->lock
);
1388 #ifdef CONFIG_IPV6_PRIVACY
1389 } else if (ifp
->flags
&IFA_F_TEMPORARY
) {
1390 struct inet6_ifaddr
*ifpub
;
1391 spin_lock_bh(&ifp
->lock
);
1394 in6_ifa_hold(ifpub
);
1395 spin_unlock_bh(&ifp
->lock
);
1396 ipv6_create_tempaddr(ifpub
, ifp
);
1399 spin_unlock_bh(&ifp
->lock
);
1407 void addrconf_dad_failure(struct inet6_ifaddr
*ifp
)
1409 if (net_ratelimit())
1410 printk(KERN_INFO
"%s: duplicate address detected!\n", ifp
->idev
->dev
->name
);
1411 addrconf_dad_stop(ifp
);
1414 /* Join to solicited addr multicast group. */
1416 void addrconf_join_solict(struct net_device
*dev
, struct in6_addr
*addr
)
1418 struct in6_addr maddr
;
1420 if (dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1423 addrconf_addr_solict_mult(addr
, &maddr
);
1424 ipv6_dev_mc_inc(dev
, &maddr
);
1427 void addrconf_leave_solict(struct inet6_dev
*idev
, struct in6_addr
*addr
)
1429 struct in6_addr maddr
;
1431 if (idev
->dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1434 addrconf_addr_solict_mult(addr
, &maddr
);
1435 __ipv6_dev_mc_dec(idev
, &maddr
);
1438 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
)
1440 struct in6_addr addr
;
1441 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1442 if (ipv6_addr_any(&addr
))
1444 ipv6_dev_ac_inc(ifp
->idev
->dev
, &addr
);
1447 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
)
1449 struct in6_addr addr
;
1450 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1451 if (ipv6_addr_any(&addr
))
1453 __ipv6_dev_ac_dec(ifp
->idev
, &addr
);
1456 static int addrconf_ifid_eui48(u8
*eui
, struct net_device
*dev
)
1458 if (dev
->addr_len
!= ETH_ALEN
)
1460 memcpy(eui
, dev
->dev_addr
, 3);
1461 memcpy(eui
+ 5, dev
->dev_addr
+ 3, 3);
1464 * The zSeries OSA network cards can be shared among various
1465 * OS instances, but the OSA cards have only one MAC address.
1466 * This leads to duplicate address conflicts in conjunction
1467 * with IPv6 if more than one instance uses the same card.
1469 * The driver for these cards can deliver a unique 16-bit
1470 * identifier for each instance sharing the same card. It is
1471 * placed instead of 0xFFFE in the interface identifier. The
1472 * "u" bit of the interface identifier is not inverted in this
1473 * case. Hence the resulting interface identifier has local
1474 * scope according to RFC2373.
1477 eui
[3] = (dev
->dev_id
>> 8) & 0xFF;
1478 eui
[4] = dev
->dev_id
& 0xFF;
1487 static int addrconf_ifid_arcnet(u8
*eui
, struct net_device
*dev
)
1489 /* XXX: inherit EUI-64 from other interface -- yoshfuji */
1490 if (dev
->addr_len
!= ARCNET_ALEN
)
1493 eui
[7] = *(u8
*)dev
->dev_addr
;
1497 static int addrconf_ifid_infiniband(u8
*eui
, struct net_device
*dev
)
1499 if (dev
->addr_len
!= INFINIBAND_ALEN
)
1501 memcpy(eui
, dev
->dev_addr
+ 12, 8);
1506 int __ipv6_isatap_ifid(u8
*eui
, __be32 addr
)
1508 eui
[0] = (ipv4_is_zeronet(addr
) || ipv4_is_private_10(addr
) ||
1509 ipv4_is_loopback(addr
) || ipv4_is_linklocal_169(addr
) ||
1510 ipv4_is_private_172(addr
) || ipv4_is_test_192(addr
) ||
1511 ipv4_is_anycast_6to4(addr
) || ipv4_is_private_192(addr
) ||
1512 ipv4_is_test_198(addr
) || ipv4_is_multicast(addr
) ||
1513 ipv4_is_lbcast(addr
)) ? 0x00 : 0x02;
1517 memcpy(eui
+ 4, &addr
, 4);
1520 EXPORT_SYMBOL(__ipv6_isatap_ifid
);
1522 static int addrconf_ifid_sit(u8
*eui
, struct net_device
*dev
)
1524 if (dev
->priv_flags
& IFF_ISATAP
)
1525 return __ipv6_isatap_ifid(eui
, *(__be32
*)dev
->dev_addr
);
1529 static int ipv6_generate_eui64(u8
*eui
, struct net_device
*dev
)
1531 switch (dev
->type
) {
1534 case ARPHRD_IEEE802_TR
:
1535 return addrconf_ifid_eui48(eui
, dev
);
1537 return addrconf_ifid_arcnet(eui
, dev
);
1538 case ARPHRD_INFINIBAND
:
1539 return addrconf_ifid_infiniband(eui
, dev
);
1541 return addrconf_ifid_sit(eui
, dev
);
1546 static int ipv6_inherit_eui64(u8
*eui
, struct inet6_dev
*idev
)
1549 struct inet6_ifaddr
*ifp
;
1551 read_lock_bh(&idev
->lock
);
1552 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1553 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1554 memcpy(eui
, ifp
->addr
.s6_addr
+8, 8);
1559 read_unlock_bh(&idev
->lock
);
1563 #ifdef CONFIG_IPV6_PRIVACY
1564 /* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */
1565 static int __ipv6_regen_rndid(struct inet6_dev
*idev
)
1568 get_random_bytes(idev
->rndid
, sizeof(idev
->rndid
));
1569 idev
->rndid
[0] &= ~0x02;
1572 * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>:
1573 * check if generated address is not inappropriate
1575 * - Reserved subnet anycast (RFC 2526)
1576 * 11111101 11....11 1xxxxxxx
1577 * - ISATAP (RFC4214) 6.1
1578 * 00-00-5E-FE-xx-xx-xx-xx
1580 * - XXX: already assigned to an address on the device
1582 if (idev
->rndid
[0] == 0xfd &&
1583 (idev
->rndid
[1]&idev
->rndid
[2]&idev
->rndid
[3]&idev
->rndid
[4]&idev
->rndid
[5]&idev
->rndid
[6]) == 0xff &&
1584 (idev
->rndid
[7]&0x80))
1586 if ((idev
->rndid
[0]|idev
->rndid
[1]) == 0) {
1587 if (idev
->rndid
[2] == 0x5e && idev
->rndid
[3] == 0xfe)
1589 if ((idev
->rndid
[2]|idev
->rndid
[3]|idev
->rndid
[4]|idev
->rndid
[5]|idev
->rndid
[6]|idev
->rndid
[7]) == 0x00)
1596 static void ipv6_regen_rndid(unsigned long data
)
1598 struct inet6_dev
*idev
= (struct inet6_dev
*) data
;
1599 unsigned long expires
;
1602 write_lock_bh(&idev
->lock
);
1607 if (__ipv6_regen_rndid(idev
) < 0)
1611 idev
->cnf
.temp_prefered_lft
* HZ
-
1612 idev
->cnf
.regen_max_retry
* idev
->cnf
.dad_transmits
* idev
->nd_parms
->retrans_time
- desync_factor
;
1613 if (time_before(expires
, jiffies
)) {
1615 "ipv6_regen_rndid(): too short regeneration interval; timer disabled for %s.\n",
1620 if (!mod_timer(&idev
->regen_timer
, expires
))
1624 write_unlock_bh(&idev
->lock
);
1625 rcu_read_unlock_bh();
1629 static int __ipv6_try_regen_rndid(struct inet6_dev
*idev
, struct in6_addr
*tmpaddr
) {
1632 if (tmpaddr
&& memcmp(idev
->rndid
, &tmpaddr
->s6_addr
[8], 8) == 0)
1633 ret
= __ipv6_regen_rndid(idev
);
1643 addrconf_prefix_route(struct in6_addr
*pfx
, int plen
, struct net_device
*dev
,
1644 unsigned long expires
, u32 flags
)
1646 struct fib6_config cfg
= {
1647 .fc_table
= RT6_TABLE_PREFIX
,
1648 .fc_metric
= IP6_RT_PRIO_ADDRCONF
,
1649 .fc_ifindex
= dev
->ifindex
,
1650 .fc_expires
= expires
,
1652 .fc_flags
= RTF_UP
| flags
,
1653 .fc_nlinfo
.nl_net
= dev_net(dev
),
1656 ipv6_addr_copy(&cfg
.fc_dst
, pfx
);
1658 /* Prevent useless cloning on PtP SIT.
1659 This thing is done here expecting that the whole
1660 class of non-broadcast devices need not cloning.
1662 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1663 if (dev
->type
== ARPHRD_SIT
&& (dev
->flags
& IFF_POINTOPOINT
))
1664 cfg
.fc_flags
|= RTF_NONEXTHOP
;
1667 ip6_route_add(&cfg
);
1670 /* Create "default" multicast route to the interface */
1672 static void addrconf_add_mroute(struct net_device
*dev
)
1674 struct fib6_config cfg
= {
1675 .fc_table
= RT6_TABLE_LOCAL
,
1676 .fc_metric
= IP6_RT_PRIO_ADDRCONF
,
1677 .fc_ifindex
= dev
->ifindex
,
1680 .fc_nlinfo
.nl_net
= dev_net(dev
),
1683 ipv6_addr_set(&cfg
.fc_dst
, htonl(0xFF000000), 0, 0, 0);
1685 ip6_route_add(&cfg
);
1688 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1689 static void sit_route_add(struct net_device
*dev
)
1691 struct fib6_config cfg
= {
1692 .fc_table
= RT6_TABLE_MAIN
,
1693 .fc_metric
= IP6_RT_PRIO_ADDRCONF
,
1694 .fc_ifindex
= dev
->ifindex
,
1696 .fc_flags
= RTF_UP
| RTF_NONEXTHOP
,
1697 .fc_nlinfo
.nl_net
= dev_net(dev
),
1700 /* prefix length - 96 bits "::d.d.d.d" */
1701 ip6_route_add(&cfg
);
1705 static void addrconf_add_lroute(struct net_device
*dev
)
1707 struct in6_addr addr
;
1709 ipv6_addr_set(&addr
, htonl(0xFE800000), 0, 0, 0);
1710 addrconf_prefix_route(&addr
, 64, dev
, 0, 0);
1713 static struct inet6_dev
*addrconf_add_dev(struct net_device
*dev
)
1715 struct inet6_dev
*idev
;
1719 if ((idev
= ipv6_find_idev(dev
)) == NULL
)
1722 /* Add default multicast route */
1723 addrconf_add_mroute(dev
);
1725 /* Add link local route */
1726 addrconf_add_lroute(dev
);
1730 void addrconf_prefix_rcv(struct net_device
*dev
, u8
*opt
, int len
)
1732 struct prefix_info
*pinfo
;
1736 struct inet6_dev
*in6_dev
;
1738 pinfo
= (struct prefix_info
*) opt
;
1740 if (len
< sizeof(struct prefix_info
)) {
1741 ADBG(("addrconf: prefix option too short\n"));
1746 * Validation checks ([ADDRCONF], page 19)
1749 addr_type
= ipv6_addr_type(&pinfo
->prefix
);
1751 if (addr_type
& (IPV6_ADDR_MULTICAST
|IPV6_ADDR_LINKLOCAL
))
1754 valid_lft
= ntohl(pinfo
->valid
);
1755 prefered_lft
= ntohl(pinfo
->prefered
);
1757 if (prefered_lft
> valid_lft
) {
1758 if (net_ratelimit())
1759 printk(KERN_WARNING
"addrconf: prefix option has invalid lifetime\n");
1763 in6_dev
= in6_dev_get(dev
);
1765 if (in6_dev
== NULL
) {
1766 if (net_ratelimit())
1767 printk(KERN_DEBUG
"addrconf: device %s not configured\n", dev
->name
);
1772 * Two things going on here:
1773 * 1) Add routes for on-link prefixes
1774 * 2) Configure prefixes with the auto flag set
1777 if (pinfo
->onlink
) {
1778 struct rt6_info
*rt
;
1779 unsigned long rt_expires
;
1781 /* Avoid arithmetic overflow. Really, we could
1782 * save rt_expires in seconds, likely valid_lft,
1783 * but it would require division in fib gc, that it
1787 rt_expires
= addrconf_timeout_fixup(valid_lft
, HZ
);
1789 rt_expires
= addrconf_timeout_fixup(valid_lft
, USER_HZ
);
1791 if (addrconf_finite_timeout(rt_expires
))
1794 rt
= rt6_lookup(dev_net(dev
), &pinfo
->prefix
, NULL
,
1797 if (rt
&& addrconf_is_prefix_route(rt
)) {
1798 /* Autoconf prefix route */
1799 if (valid_lft
== 0) {
1802 } else if (addrconf_finite_timeout(rt_expires
)) {
1804 rt
->rt6i_expires
= jiffies
+ rt_expires
;
1805 rt
->rt6i_flags
|= RTF_EXPIRES
;
1807 rt
->rt6i_flags
&= ~RTF_EXPIRES
;
1808 rt
->rt6i_expires
= 0;
1810 } else if (valid_lft
) {
1811 clock_t expires
= 0;
1812 int flags
= RTF_ADDRCONF
| RTF_PREFIX_RT
;
1813 if (addrconf_finite_timeout(rt_expires
)) {
1815 flags
|= RTF_EXPIRES
;
1816 expires
= jiffies_to_clock_t(rt_expires
);
1818 addrconf_prefix_route(&pinfo
->prefix
, pinfo
->prefix_len
,
1819 dev
, expires
, flags
);
1822 dst_release(&rt
->u
.dst
);
1825 /* Try to figure out our local address for this prefix */
1827 if (pinfo
->autoconf
&& in6_dev
->cnf
.autoconf
) {
1828 struct inet6_ifaddr
* ifp
;
1829 struct in6_addr addr
;
1830 int create
= 0, update_lft
= 0;
1832 if (pinfo
->prefix_len
== 64) {
1833 memcpy(&addr
, &pinfo
->prefix
, 8);
1834 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) &&
1835 ipv6_inherit_eui64(addr
.s6_addr
+ 8, in6_dev
)) {
1836 in6_dev_put(in6_dev
);
1841 if (net_ratelimit())
1842 printk(KERN_DEBUG
"IPv6 addrconf: prefix with wrong length %d\n",
1844 in6_dev_put(in6_dev
);
1849 ifp
= ipv6_get_ifaddr(dev_net(dev
), &addr
, dev
, 1);
1851 if (ifp
== NULL
&& valid_lft
) {
1852 int max_addresses
= in6_dev
->cnf
.max_addresses
;
1855 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
1856 if (in6_dev
->cnf
.optimistic_dad
&&
1857 !ipv6_devconf
.forwarding
)
1858 addr_flags
= IFA_F_OPTIMISTIC
;
1861 /* Do not allow to create too much of autoconfigured
1862 * addresses; this would be too easy way to crash kernel.
1864 if (!max_addresses
||
1865 ipv6_count_addresses(in6_dev
) < max_addresses
)
1866 ifp
= ipv6_add_addr(in6_dev
, &addr
, pinfo
->prefix_len
,
1867 addr_type
&IPV6_ADDR_SCOPE_MASK
,
1870 if (!ifp
|| IS_ERR(ifp
)) {
1871 in6_dev_put(in6_dev
);
1875 update_lft
= create
= 1;
1876 ifp
->cstamp
= jiffies
;
1877 addrconf_dad_start(ifp
, RTF_ADDRCONF
|RTF_PREFIX_RT
);
1883 #ifdef CONFIG_IPV6_PRIVACY
1884 struct inet6_ifaddr
*ift
;
1888 /* update lifetime (RFC2462 5.5.3 e) */
1889 spin_lock(&ifp
->lock
);
1891 if (ifp
->valid_lft
> (now
- ifp
->tstamp
) / HZ
)
1892 stored_lft
= ifp
->valid_lft
- (now
- ifp
->tstamp
) / HZ
;
1895 if (!update_lft
&& stored_lft
) {
1896 if (valid_lft
> MIN_VALID_LIFETIME
||
1897 valid_lft
> stored_lft
)
1899 else if (stored_lft
<= MIN_VALID_LIFETIME
) {
1900 /* valid_lft <= stored_lft is always true */
1904 valid_lft
= MIN_VALID_LIFETIME
;
1905 if (valid_lft
< prefered_lft
)
1906 prefered_lft
= valid_lft
;
1912 ifp
->valid_lft
= valid_lft
;
1913 ifp
->prefered_lft
= prefered_lft
;
1916 ifp
->flags
&= ~IFA_F_DEPRECATED
;
1917 spin_unlock(&ifp
->lock
);
1919 if (!(flags
&IFA_F_TENTATIVE
))
1920 ipv6_ifa_notify(0, ifp
);
1922 spin_unlock(&ifp
->lock
);
1924 #ifdef CONFIG_IPV6_PRIVACY
1925 read_lock_bh(&in6_dev
->lock
);
1926 /* update all temporary addresses in the list */
1927 for (ift
=in6_dev
->tempaddr_list
; ift
; ift
=ift
->tmp_next
) {
1929 * When adjusting the lifetimes of an existing
1930 * temporary address, only lower the lifetimes.
1931 * Implementations must not increase the
1932 * lifetimes of an existing temporary address
1933 * when processing a Prefix Information Option.
1935 if (ifp
!= ift
->ifpub
)
1938 spin_lock(&ift
->lock
);
1940 if (ift
->valid_lft
> valid_lft
&&
1941 ift
->valid_lft
- valid_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1942 ift
->valid_lft
= valid_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1943 if (ift
->prefered_lft
> prefered_lft
&&
1944 ift
->prefered_lft
- prefered_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1945 ift
->prefered_lft
= prefered_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1946 spin_unlock(&ift
->lock
);
1947 if (!(flags
&IFA_F_TENTATIVE
))
1948 ipv6_ifa_notify(0, ift
);
1951 if (create
&& in6_dev
->cnf
.use_tempaddr
> 0) {
1953 * When a new public address is created as described in [ADDRCONF],
1954 * also create a new temporary address.
1956 read_unlock_bh(&in6_dev
->lock
);
1957 ipv6_create_tempaddr(ifp
, NULL
);
1959 read_unlock_bh(&in6_dev
->lock
);
1966 inet6_prefix_notify(RTM_NEWPREFIX
, in6_dev
, pinfo
);
1967 in6_dev_put(in6_dev
);
1971 * Set destination address.
1972 * Special case for SIT interfaces where we create a new "virtual"
1975 int addrconf_set_dstaddr(struct net
*net
, void __user
*arg
)
1977 struct in6_ifreq ireq
;
1978 struct net_device
*dev
;
1984 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1987 dev
= __dev_get_by_index(net
, ireq
.ifr6_ifindex
);
1993 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1994 if (dev
->type
== ARPHRD_SIT
) {
1997 struct ip_tunnel_parm p
;
1999 err
= -EADDRNOTAVAIL
;
2000 if (!(ipv6_addr_type(&ireq
.ifr6_addr
) & IPV6_ADDR_COMPATv4
))
2003 memset(&p
, 0, sizeof(p
));
2004 p
.iph
.daddr
= ireq
.ifr6_addr
.s6_addr32
[3];
2008 p
.iph
.protocol
= IPPROTO_IPV6
;
2010 ifr
.ifr_ifru
.ifru_data
= (__force
void __user
*)&p
;
2012 oldfs
= get_fs(); set_fs(KERNEL_DS
);
2013 err
= dev
->do_ioctl(dev
, &ifr
, SIOCADDTUNNEL
);
2018 dev
= __dev_get_by_name(net
, p
.name
);
2021 err
= dev_open(dev
);
2032 * Manual configuration of address on an interface
2034 static int inet6_addr_add(struct net
*net
, int ifindex
, struct in6_addr
*pfx
,
2035 unsigned int plen
, __u8 ifa_flags
, __u32 prefered_lft
,
2038 struct inet6_ifaddr
*ifp
;
2039 struct inet6_dev
*idev
;
2040 struct net_device
*dev
;
2044 unsigned long timeout
;
2051 /* check the lifetime */
2052 if (!valid_lft
|| prefered_lft
> valid_lft
)
2055 dev
= __dev_get_by_index(net
, ifindex
);
2059 if ((idev
= addrconf_add_dev(dev
)) == NULL
)
2062 scope
= ipv6_addr_scope(pfx
);
2064 timeout
= addrconf_timeout_fixup(valid_lft
, HZ
);
2065 if (addrconf_finite_timeout(timeout
)) {
2066 expires
= jiffies_to_clock_t(timeout
* HZ
);
2067 valid_lft
= timeout
;
2068 flags
= RTF_EXPIRES
;
2072 ifa_flags
|= IFA_F_PERMANENT
;
2075 timeout
= addrconf_timeout_fixup(prefered_lft
, HZ
);
2076 if (addrconf_finite_timeout(timeout
)) {
2078 ifa_flags
|= IFA_F_DEPRECATED
;
2079 prefered_lft
= timeout
;
2082 ifp
= ipv6_add_addr(idev
, pfx
, plen
, scope
, ifa_flags
);
2085 spin_lock_bh(&ifp
->lock
);
2086 ifp
->valid_lft
= valid_lft
;
2087 ifp
->prefered_lft
= prefered_lft
;
2088 ifp
->tstamp
= jiffies
;
2089 spin_unlock_bh(&ifp
->lock
);
2091 addrconf_prefix_route(&ifp
->addr
, ifp
->prefix_len
, dev
,
2094 * Note that section 3.1 of RFC 4429 indicates
2095 * that the Optimistic flag should not be set for
2096 * manually configured addresses
2098 addrconf_dad_start(ifp
, 0);
2104 return PTR_ERR(ifp
);
2107 static int inet6_addr_del(struct net
*net
, int ifindex
, struct in6_addr
*pfx
,
2110 struct inet6_ifaddr
*ifp
;
2111 struct inet6_dev
*idev
;
2112 struct net_device
*dev
;
2117 dev
= __dev_get_by_index(net
, ifindex
);
2121 if ((idev
= __in6_dev_get(dev
)) == NULL
)
2124 read_lock_bh(&idev
->lock
);
2125 for (ifp
= idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
2126 if (ifp
->prefix_len
== plen
&&
2127 ipv6_addr_equal(pfx
, &ifp
->addr
)) {
2129 read_unlock_bh(&idev
->lock
);
2133 /* If the last address is deleted administratively,
2134 disable IPv6 on this interface.
2136 if (idev
->addr_list
== NULL
)
2137 addrconf_ifdown(idev
->dev
, 1);
2141 read_unlock_bh(&idev
->lock
);
2142 return -EADDRNOTAVAIL
;
2146 int addrconf_add_ifaddr(struct net
*net
, void __user
*arg
)
2148 struct in6_ifreq ireq
;
2151 if (!capable(CAP_NET_ADMIN
))
2154 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
2158 err
= inet6_addr_add(net
, ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
,
2159 ireq
.ifr6_prefixlen
, IFA_F_PERMANENT
,
2160 INFINITY_LIFE_TIME
, INFINITY_LIFE_TIME
);
2165 int addrconf_del_ifaddr(struct net
*net
, void __user
*arg
)
2167 struct in6_ifreq ireq
;
2170 if (!capable(CAP_NET_ADMIN
))
2173 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
2177 err
= inet6_addr_del(net
, ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
,
2178 ireq
.ifr6_prefixlen
);
2183 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2184 static void sit_add_v4_addrs(struct inet6_dev
*idev
)
2186 struct inet6_ifaddr
* ifp
;
2187 struct in6_addr addr
;
2188 struct net_device
*dev
;
2189 struct net
*net
= dev_net(idev
->dev
);
2194 memset(&addr
, 0, sizeof(struct in6_addr
));
2195 memcpy(&addr
.s6_addr32
[3], idev
->dev
->dev_addr
, 4);
2197 if (idev
->dev
->flags
&IFF_POINTOPOINT
) {
2198 addr
.s6_addr32
[0] = htonl(0xfe800000);
2201 scope
= IPV6_ADDR_COMPATv4
;
2204 if (addr
.s6_addr32
[3]) {
2205 ifp
= ipv6_add_addr(idev
, &addr
, 128, scope
, IFA_F_PERMANENT
);
2207 spin_lock_bh(&ifp
->lock
);
2208 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2209 spin_unlock_bh(&ifp
->lock
);
2210 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2216 for_each_netdev(net
, dev
) {
2217 struct in_device
* in_dev
= __in_dev_get_rtnl(dev
);
2218 if (in_dev
&& (dev
->flags
& IFF_UP
)) {
2219 struct in_ifaddr
* ifa
;
2223 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
2226 addr
.s6_addr32
[3] = ifa
->ifa_local
;
2228 if (ifa
->ifa_scope
== RT_SCOPE_LINK
)
2230 if (ifa
->ifa_scope
>= RT_SCOPE_HOST
) {
2231 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2235 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2240 ifp
= ipv6_add_addr(idev
, &addr
, plen
, flag
,
2243 spin_lock_bh(&ifp
->lock
);
2244 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2245 spin_unlock_bh(&ifp
->lock
);
2246 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2255 static void init_loopback(struct net_device
*dev
)
2257 struct inet6_dev
*idev
;
2258 struct inet6_ifaddr
* ifp
;
2264 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2265 printk(KERN_DEBUG
"init loopback: add_dev failed\n");
2269 ifp
= ipv6_add_addr(idev
, &in6addr_loopback
, 128, IFA_HOST
, IFA_F_PERMANENT
);
2271 spin_lock_bh(&ifp
->lock
);
2272 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2273 spin_unlock_bh(&ifp
->lock
);
2274 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2279 static void addrconf_add_linklocal(struct inet6_dev
*idev
, struct in6_addr
*addr
)
2281 struct inet6_ifaddr
* ifp
;
2282 u32 addr_flags
= IFA_F_PERMANENT
;
2284 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
2285 if (idev
->cnf
.optimistic_dad
&&
2286 !ipv6_devconf
.forwarding
)
2287 addr_flags
|= IFA_F_OPTIMISTIC
;
2291 ifp
= ipv6_add_addr(idev
, addr
, 64, IFA_LINK
, addr_flags
);
2293 addrconf_prefix_route(&ifp
->addr
, ifp
->prefix_len
, idev
->dev
, 0, 0);
2294 addrconf_dad_start(ifp
, 0);
2299 static void addrconf_dev_config(struct net_device
*dev
)
2301 struct in6_addr addr
;
2302 struct inet6_dev
* idev
;
2306 if ((dev
->type
!= ARPHRD_ETHER
) &&
2307 (dev
->type
!= ARPHRD_FDDI
) &&
2308 (dev
->type
!= ARPHRD_IEEE802_TR
) &&
2309 (dev
->type
!= ARPHRD_ARCNET
) &&
2310 (dev
->type
!= ARPHRD_INFINIBAND
)) {
2311 /* Alas, we support only Ethernet autoconfiguration. */
2315 idev
= addrconf_add_dev(dev
);
2319 memset(&addr
, 0, sizeof(struct in6_addr
));
2320 addr
.s6_addr32
[0] = htonl(0xFE800000);
2322 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) == 0)
2323 addrconf_add_linklocal(idev
, &addr
);
2326 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2327 static void addrconf_sit_config(struct net_device
*dev
)
2329 struct inet6_dev
*idev
;
2334 * Configure the tunnel with one of our IPv4
2335 * addresses... we should configure all of
2336 * our v4 addrs in the tunnel
2339 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2340 printk(KERN_DEBUG
"init sit: add_dev failed\n");
2344 if (dev
->priv_flags
& IFF_ISATAP
) {
2345 struct in6_addr addr
;
2347 ipv6_addr_set(&addr
, htonl(0xFE800000), 0, 0, 0);
2348 addrconf_prefix_route(&addr
, 64, dev
, 0, 0);
2349 if (!ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
))
2350 addrconf_add_linklocal(idev
, &addr
);
2354 sit_add_v4_addrs(idev
);
2356 if (dev
->flags
&IFF_POINTOPOINT
) {
2357 addrconf_add_mroute(dev
);
2358 addrconf_add_lroute(dev
);
2365 ipv6_inherit_linklocal(struct inet6_dev
*idev
, struct net_device
*link_dev
)
2367 struct in6_addr lladdr
;
2369 if (!ipv6_get_lladdr(link_dev
, &lladdr
, IFA_F_TENTATIVE
)) {
2370 addrconf_add_linklocal(idev
, &lladdr
);
2376 static void ip6_tnl_add_linklocal(struct inet6_dev
*idev
)
2378 struct net_device
*link_dev
;
2379 struct net
*net
= dev_net(idev
->dev
);
2381 /* first try to inherit the link-local address from the link device */
2382 if (idev
->dev
->iflink
&&
2383 (link_dev
= __dev_get_by_index(net
, idev
->dev
->iflink
))) {
2384 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2387 /* then try to inherit it from any device */
2388 for_each_netdev(net
, link_dev
) {
2389 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2392 printk(KERN_DEBUG
"init ip6-ip6: add_linklocal failed\n");
2396 * Autoconfigure tunnel with a link-local address so routing protocols,
2397 * DHCPv6, MLD etc. can be run over the virtual link
2400 static void addrconf_ip6_tnl_config(struct net_device
*dev
)
2402 struct inet6_dev
*idev
;
2406 if ((idev
= addrconf_add_dev(dev
)) == NULL
) {
2407 printk(KERN_DEBUG
"init ip6-ip6: add_dev failed\n");
2410 ip6_tnl_add_linklocal(idev
);
2413 static int addrconf_notify(struct notifier_block
*this, unsigned long event
,
2416 struct net_device
*dev
= (struct net_device
*) data
;
2417 struct inet6_dev
*idev
= __in6_dev_get(dev
);
2418 int run_pending
= 0;
2422 case NETDEV_REGISTER
:
2423 if (!idev
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2424 idev
= ipv6_add_dev(dev
);
2426 return notifier_from_errno(-ENOMEM
);
2431 if (dev
->flags
& IFF_SLAVE
)
2434 if (event
== NETDEV_UP
) {
2435 if (!addrconf_qdisc_ok(dev
)) {
2436 /* device is not ready yet. */
2438 "ADDRCONF(NETDEV_UP): %s: "
2439 "link is not ready\n",
2444 if (!idev
&& dev
->mtu
>= IPV6_MIN_MTU
)
2445 idev
= ipv6_add_dev(dev
);
2448 idev
->if_flags
|= IF_READY
;
2450 if (!addrconf_qdisc_ok(dev
)) {
2451 /* device is still not ready. */
2456 if (idev
->if_flags
& IF_READY
) {
2457 /* device is already configured. */
2460 idev
->if_flags
|= IF_READY
;
2464 "ADDRCONF(NETDEV_CHANGE): %s: "
2465 "link becomes ready\n",
2472 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2474 addrconf_sit_config(dev
);
2477 case ARPHRD_TUNNEL6
:
2478 addrconf_ip6_tnl_config(dev
);
2480 case ARPHRD_LOOPBACK
:
2485 addrconf_dev_config(dev
);
2490 addrconf_dad_run(idev
);
2492 /* If the MTU changed during the interface down, when the
2493 interface up, the changed MTU must be reflected in the
2494 idev as well as routers.
2496 if (idev
->cnf
.mtu6
!= dev
->mtu
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2497 rt6_mtu_change(dev
, dev
->mtu
);
2498 idev
->cnf
.mtu6
= dev
->mtu
;
2500 idev
->tstamp
= jiffies
;
2501 inet6_ifinfo_notify(RTM_NEWLINK
, idev
);
2502 /* If the changed mtu during down is lower than IPV6_MIN_MTU
2503 stop IPv6 on this interface.
2505 if (dev
->mtu
< IPV6_MIN_MTU
)
2506 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2510 case NETDEV_CHANGEMTU
:
2511 if (idev
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2512 rt6_mtu_change(dev
, dev
->mtu
);
2513 idev
->cnf
.mtu6
= dev
->mtu
;
2517 if (!idev
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2518 idev
= ipv6_add_dev(dev
);
2523 /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */
2526 case NETDEV_UNREGISTER
:
2528 * Remove all addresses from this interface.
2530 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2533 case NETDEV_CHANGENAME
:
2535 snmp6_unregister_dev(idev
);
2536 addrconf_sysctl_unregister(idev
);
2537 addrconf_sysctl_register(idev
);
2538 err
= snmp6_register_dev(idev
);
2540 return notifier_from_errno(err
);
2549 * addrconf module should be notified of a device going up
2551 static struct notifier_block ipv6_dev_notf
= {
2552 .notifier_call
= addrconf_notify
,
2556 static int addrconf_ifdown(struct net_device
*dev
, int how
)
2558 struct inet6_dev
*idev
;
2559 struct inet6_ifaddr
*ifa
, **bifa
;
2560 struct net
*net
= dev_net(dev
);
2565 if ((dev
->flags
& IFF_LOOPBACK
) && how
== 1)
2568 rt6_ifdown(net
, dev
);
2569 neigh_ifdown(&nd_tbl
, dev
);
2571 idev
= __in6_dev_get(dev
);
2575 /* Step 1: remove reference to ipv6 device from parent device.
2581 /* protected by rtnl_lock */
2582 rcu_assign_pointer(dev
->ip6_ptr
, NULL
);
2584 /* Step 1.5: remove snmp6 entry */
2585 snmp6_unregister_dev(idev
);
2589 /* Step 2: clear hash table */
2590 for (i
=0; i
<IN6_ADDR_HSIZE
; i
++) {
2591 bifa
= &inet6_addr_lst
[i
];
2593 write_lock_bh(&addrconf_hash_lock
);
2594 while ((ifa
= *bifa
) != NULL
) {
2595 if (ifa
->idev
== idev
) {
2596 *bifa
= ifa
->lst_next
;
2597 ifa
->lst_next
= NULL
;
2598 addrconf_del_timer(ifa
);
2602 bifa
= &ifa
->lst_next
;
2604 write_unlock_bh(&addrconf_hash_lock
);
2607 write_lock_bh(&idev
->lock
);
2609 /* Step 3: clear flags for stateless addrconf */
2611 idev
->if_flags
&= ~(IF_RS_SENT
|IF_RA_RCVD
|IF_READY
);
2613 /* Step 4: clear address list */
2614 #ifdef CONFIG_IPV6_PRIVACY
2615 if (how
&& del_timer(&idev
->regen_timer
))
2618 /* clear tempaddr list */
2619 while ((ifa
= idev
->tempaddr_list
) != NULL
) {
2620 idev
->tempaddr_list
= ifa
->tmp_next
;
2621 ifa
->tmp_next
= NULL
;
2623 write_unlock_bh(&idev
->lock
);
2624 spin_lock_bh(&ifa
->lock
);
2627 in6_ifa_put(ifa
->ifpub
);
2630 spin_unlock_bh(&ifa
->lock
);
2632 write_lock_bh(&idev
->lock
);
2635 while ((ifa
= idev
->addr_list
) != NULL
) {
2636 idev
->addr_list
= ifa
->if_next
;
2637 ifa
->if_next
= NULL
;
2639 addrconf_del_timer(ifa
);
2640 write_unlock_bh(&idev
->lock
);
2642 __ipv6_ifa_notify(RTM_DELADDR
, ifa
);
2643 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_DOWN
, ifa
);
2646 write_lock_bh(&idev
->lock
);
2648 write_unlock_bh(&idev
->lock
);
2650 /* Step 5: Discard multicast list */
2653 ipv6_mc_destroy_dev(idev
);
2657 idev
->tstamp
= jiffies
;
2659 /* Shot the device (if unregistered) */
2662 addrconf_sysctl_unregister(idev
);
2663 neigh_parms_release(&nd_tbl
, idev
->nd_parms
);
2664 neigh_ifdown(&nd_tbl
, dev
);
2670 static void addrconf_rs_timer(unsigned long data
)
2672 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2674 if (ifp
->idev
->cnf
.forwarding
)
2677 if (ifp
->idev
->if_flags
& IF_RA_RCVD
) {
2679 * Announcement received after solicitation
2685 spin_lock(&ifp
->lock
);
2686 if (ifp
->probes
++ < ifp
->idev
->cnf
.rtr_solicits
) {
2687 /* The wait after the last probe can be shorter */
2688 addrconf_mod_timer(ifp
, AC_RS
,
2689 (ifp
->probes
== ifp
->idev
->cnf
.rtr_solicits
) ?
2690 ifp
->idev
->cnf
.rtr_solicit_delay
:
2691 ifp
->idev
->cnf
.rtr_solicit_interval
);
2692 spin_unlock(&ifp
->lock
);
2694 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &in6addr_linklocal_allrouters
);
2696 spin_unlock(&ifp
->lock
);
2698 * Note: we do not support deprecated "all on-link"
2699 * assumption any longer.
2701 printk(KERN_DEBUG
"%s: no IPv6 routers present\n",
2702 ifp
->idev
->dev
->name
);
2710 * Duplicate Address Detection
2712 static void addrconf_dad_kick(struct inet6_ifaddr
*ifp
)
2714 unsigned long rand_num
;
2715 struct inet6_dev
*idev
= ifp
->idev
;
2717 if (ifp
->flags
& IFA_F_OPTIMISTIC
)
2720 rand_num
= net_random() % (idev
->cnf
.rtr_solicit_delay
? : 1);
2722 ifp
->probes
= idev
->cnf
.dad_transmits
;
2723 addrconf_mod_timer(ifp
, AC_DAD
, rand_num
);
2726 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
)
2728 struct inet6_dev
*idev
= ifp
->idev
;
2729 struct net_device
*dev
= idev
->dev
;
2731 addrconf_join_solict(dev
, &ifp
->addr
);
2733 net_srandom(ifp
->addr
.s6_addr32
[3]);
2735 read_lock_bh(&idev
->lock
);
2738 spin_lock_bh(&ifp
->lock
);
2740 if (dev
->flags
&(IFF_NOARP
|IFF_LOOPBACK
) ||
2741 !(ifp
->flags
&IFA_F_TENTATIVE
) ||
2742 ifp
->flags
& IFA_F_NODAD
) {
2743 ifp
->flags
&= ~(IFA_F_TENTATIVE
|IFA_F_OPTIMISTIC
);
2744 spin_unlock_bh(&ifp
->lock
);
2745 read_unlock_bh(&idev
->lock
);
2747 addrconf_dad_completed(ifp
);
2751 if (!(idev
->if_flags
& IF_READY
)) {
2752 spin_unlock_bh(&ifp
->lock
);
2753 read_unlock_bh(&idev
->lock
);
2755 * If the defice is not ready:
2756 * - keep it tentative if it is a permanent address.
2757 * - otherwise, kill it.
2760 addrconf_dad_stop(ifp
);
2765 * Optimistic nodes can start receiving
2768 if(ifp
->flags
& IFA_F_OPTIMISTIC
)
2769 ip6_ins_rt(ifp
->rt
);
2771 addrconf_dad_kick(ifp
);
2772 spin_unlock_bh(&ifp
->lock
);
2774 read_unlock_bh(&idev
->lock
);
2777 static void addrconf_dad_timer(unsigned long data
)
2779 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2780 struct inet6_dev
*idev
= ifp
->idev
;
2781 struct in6_addr mcaddr
;
2783 read_lock_bh(&idev
->lock
);
2785 read_unlock_bh(&idev
->lock
);
2788 spin_lock_bh(&ifp
->lock
);
2789 if (ifp
->probes
== 0) {
2791 * DAD was successful
2794 ifp
->flags
&= ~(IFA_F_TENTATIVE
|IFA_F_OPTIMISTIC
);
2795 spin_unlock_bh(&ifp
->lock
);
2796 read_unlock_bh(&idev
->lock
);
2798 addrconf_dad_completed(ifp
);
2804 addrconf_mod_timer(ifp
, AC_DAD
, ifp
->idev
->nd_parms
->retrans_time
);
2805 spin_unlock_bh(&ifp
->lock
);
2806 read_unlock_bh(&idev
->lock
);
2808 /* send a neighbour solicitation for our addr */
2809 addrconf_addr_solict_mult(&ifp
->addr
, &mcaddr
);
2810 ndisc_send_ns(ifp
->idev
->dev
, NULL
, &ifp
->addr
, &mcaddr
, &in6addr_any
);
2815 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
)
2817 struct net_device
* dev
= ifp
->idev
->dev
;
2820 * Configure the address for reception. Now it is valid.
2823 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2825 /* If added prefix is link local and forwarding is off,
2826 start sending router solicitations.
2829 if (ifp
->idev
->cnf
.forwarding
== 0 &&
2830 ifp
->idev
->cnf
.rtr_solicits
> 0 &&
2831 (dev
->flags
&IFF_LOOPBACK
) == 0 &&
2832 (ipv6_addr_type(&ifp
->addr
) & IPV6_ADDR_LINKLOCAL
)) {
2834 * If a host as already performed a random delay
2835 * [...] as part of DAD [...] there is no need
2836 * to delay again before sending the first RS
2838 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &in6addr_linklocal_allrouters
);
2840 spin_lock_bh(&ifp
->lock
);
2842 ifp
->idev
->if_flags
|= IF_RS_SENT
;
2843 addrconf_mod_timer(ifp
, AC_RS
, ifp
->idev
->cnf
.rtr_solicit_interval
);
2844 spin_unlock_bh(&ifp
->lock
);
2848 static void addrconf_dad_run(struct inet6_dev
*idev
) {
2849 struct inet6_ifaddr
*ifp
;
2851 read_lock_bh(&idev
->lock
);
2852 for (ifp
= idev
->addr_list
; ifp
; ifp
= ifp
->if_next
) {
2853 spin_lock_bh(&ifp
->lock
);
2854 if (!(ifp
->flags
& IFA_F_TENTATIVE
)) {
2855 spin_unlock_bh(&ifp
->lock
);
2858 spin_unlock_bh(&ifp
->lock
);
2859 addrconf_dad_kick(ifp
);
2861 read_unlock_bh(&idev
->lock
);
2864 #ifdef CONFIG_PROC_FS
2865 struct if6_iter_state
{
2866 struct seq_net_private p
;
2870 static struct inet6_ifaddr
*if6_get_first(struct seq_file
*seq
)
2872 struct inet6_ifaddr
*ifa
= NULL
;
2873 struct if6_iter_state
*state
= seq
->private;
2874 struct net
*net
= seq_file_net(seq
);
2876 for (state
->bucket
= 0; state
->bucket
< IN6_ADDR_HSIZE
; ++state
->bucket
) {
2877 ifa
= inet6_addr_lst
[state
->bucket
];
2879 while (ifa
&& !net_eq(dev_net(ifa
->idev
->dev
), net
))
2880 ifa
= ifa
->lst_next
;
2887 static struct inet6_ifaddr
*if6_get_next(struct seq_file
*seq
, struct inet6_ifaddr
*ifa
)
2889 struct if6_iter_state
*state
= seq
->private;
2890 struct net
*net
= seq_file_net(seq
);
2892 ifa
= ifa
->lst_next
;
2895 if (!net_eq(dev_net(ifa
->idev
->dev
), net
)) {
2896 ifa
= ifa
->lst_next
;
2901 if (!ifa
&& ++state
->bucket
< IN6_ADDR_HSIZE
) {
2902 ifa
= inet6_addr_lst
[state
->bucket
];
2909 static struct inet6_ifaddr
*if6_get_idx(struct seq_file
*seq
, loff_t pos
)
2911 struct inet6_ifaddr
*ifa
= if6_get_first(seq
);
2914 while(pos
&& (ifa
= if6_get_next(seq
, ifa
)) != NULL
)
2916 return pos
? NULL
: ifa
;
2919 static void *if6_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2920 __acquires(addrconf_hash_lock
)
2922 read_lock_bh(&addrconf_hash_lock
);
2923 return if6_get_idx(seq
, *pos
);
2926 static void *if6_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2928 struct inet6_ifaddr
*ifa
;
2930 ifa
= if6_get_next(seq
, v
);
2935 static void if6_seq_stop(struct seq_file
*seq
, void *v
)
2936 __releases(addrconf_hash_lock
)
2938 read_unlock_bh(&addrconf_hash_lock
);
2941 static int if6_seq_show(struct seq_file
*seq
, void *v
)
2943 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*)v
;
2945 NIP6_SEQFMT
" %02x %02x %02x %02x %8s\n",
2947 ifp
->idev
->dev
->ifindex
,
2951 ifp
->idev
->dev
->name
);
2955 static const struct seq_operations if6_seq_ops
= {
2956 .start
= if6_seq_start
,
2957 .next
= if6_seq_next
,
2958 .show
= if6_seq_show
,
2959 .stop
= if6_seq_stop
,
2962 static int if6_seq_open(struct inode
*inode
, struct file
*file
)
2964 return seq_open_net(inode
, file
, &if6_seq_ops
,
2965 sizeof(struct if6_iter_state
));
2968 static const struct file_operations if6_fops
= {
2969 .owner
= THIS_MODULE
,
2970 .open
= if6_seq_open
,
2972 .llseek
= seq_lseek
,
2973 .release
= seq_release_net
,
2976 static int if6_proc_net_init(struct net
*net
)
2978 if (!proc_net_fops_create(net
, "if_inet6", S_IRUGO
, &if6_fops
))
2983 static void if6_proc_net_exit(struct net
*net
)
2985 proc_net_remove(net
, "if_inet6");
2988 static struct pernet_operations if6_proc_net_ops
= {
2989 .init
= if6_proc_net_init
,
2990 .exit
= if6_proc_net_exit
,
2993 int __init
if6_proc_init(void)
2995 return register_pernet_subsys(&if6_proc_net_ops
);
2998 void if6_proc_exit(void)
3000 unregister_pernet_subsys(&if6_proc_net_ops
);
3002 #endif /* CONFIG_PROC_FS */
3004 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
3005 /* Check if address is a home address configured on any interface. */
3006 int ipv6_chk_home_addr(struct net
*net
, struct in6_addr
*addr
)
3009 struct inet6_ifaddr
* ifp
;
3010 u8 hash
= ipv6_addr_hash(addr
);
3011 read_lock_bh(&addrconf_hash_lock
);
3012 for (ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
= ifp
->lst_next
) {
3013 if (!net_eq(dev_net(ifp
->idev
->dev
), net
))
3015 if (ipv6_addr_equal(&ifp
->addr
, addr
) &&
3016 (ifp
->flags
& IFA_F_HOMEADDRESS
)) {
3021 read_unlock_bh(&addrconf_hash_lock
);
3027 * Periodic address status verification
3030 static void addrconf_verify(unsigned long foo
)
3032 struct inet6_ifaddr
*ifp
;
3033 unsigned long now
, next
;
3036 spin_lock_bh(&addrconf_verify_lock
);
3038 next
= now
+ ADDR_CHECK_FREQUENCY
;
3040 del_timer(&addr_chk_timer
);
3042 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
3045 read_lock(&addrconf_hash_lock
);
3046 for (ifp
=inet6_addr_lst
[i
]; ifp
; ifp
=ifp
->lst_next
) {
3048 #ifdef CONFIG_IPV6_PRIVACY
3049 unsigned long regen_advance
;
3052 if (ifp
->flags
& IFA_F_PERMANENT
)
3055 spin_lock(&ifp
->lock
);
3056 age
= (now
- ifp
->tstamp
) / HZ
;
3058 #ifdef CONFIG_IPV6_PRIVACY
3059 regen_advance
= ifp
->idev
->cnf
.regen_max_retry
*
3060 ifp
->idev
->cnf
.dad_transmits
*
3061 ifp
->idev
->nd_parms
->retrans_time
/ HZ
;
3064 if (ifp
->valid_lft
!= INFINITY_LIFE_TIME
&&
3065 age
>= ifp
->valid_lft
) {
3066 spin_unlock(&ifp
->lock
);
3068 read_unlock(&addrconf_hash_lock
);
3071 } else if (ifp
->prefered_lft
== INFINITY_LIFE_TIME
) {
3072 spin_unlock(&ifp
->lock
);
3074 } else if (age
>= ifp
->prefered_lft
) {
3075 /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */
3078 if (!(ifp
->flags
&IFA_F_DEPRECATED
)) {
3080 ifp
->flags
|= IFA_F_DEPRECATED
;
3083 if (time_before(ifp
->tstamp
+ ifp
->valid_lft
* HZ
, next
))
3084 next
= ifp
->tstamp
+ ifp
->valid_lft
* HZ
;
3086 spin_unlock(&ifp
->lock
);
3090 read_unlock(&addrconf_hash_lock
);
3092 ipv6_ifa_notify(0, ifp
);
3096 #ifdef CONFIG_IPV6_PRIVACY
3097 } else if ((ifp
->flags
&IFA_F_TEMPORARY
) &&
3098 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
3099 if (age
>= ifp
->prefered_lft
- regen_advance
) {
3100 struct inet6_ifaddr
*ifpub
= ifp
->ifpub
;
3101 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
3102 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
3103 if (!ifp
->regen_count
&& ifpub
) {
3106 in6_ifa_hold(ifpub
);
3107 spin_unlock(&ifp
->lock
);
3108 read_unlock(&addrconf_hash_lock
);
3109 spin_lock(&ifpub
->lock
);
3110 ifpub
->regen_count
= 0;
3111 spin_unlock(&ifpub
->lock
);
3112 ipv6_create_tempaddr(ifpub
, ifp
);
3117 } else if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
, next
))
3118 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
;
3119 spin_unlock(&ifp
->lock
);
3122 /* ifp->prefered_lft <= ifp->valid_lft */
3123 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
3124 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
3125 spin_unlock(&ifp
->lock
);
3128 read_unlock(&addrconf_hash_lock
);
3131 addr_chk_timer
.expires
= time_before(next
, jiffies
+ HZ
) ? jiffies
+ HZ
: next
;
3132 add_timer(&addr_chk_timer
);
3133 spin_unlock_bh(&addrconf_verify_lock
);
3136 static struct in6_addr
*extract_addr(struct nlattr
*addr
, struct nlattr
*local
)
3138 struct in6_addr
*pfx
= NULL
;
3141 pfx
= nla_data(addr
);
3144 if (pfx
&& nla_memcmp(local
, pfx
, sizeof(*pfx
)))
3147 pfx
= nla_data(local
);
3153 static const struct nla_policy ifa_ipv6_policy
[IFA_MAX
+1] = {
3154 [IFA_ADDRESS
] = { .len
= sizeof(struct in6_addr
) },
3155 [IFA_LOCAL
] = { .len
= sizeof(struct in6_addr
) },
3156 [IFA_CACHEINFO
] = { .len
= sizeof(struct ifa_cacheinfo
) },
3160 inet6_rtm_deladdr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
3162 struct net
*net
= sock_net(skb
->sk
);
3163 struct ifaddrmsg
*ifm
;
3164 struct nlattr
*tb
[IFA_MAX
+1];
3165 struct in6_addr
*pfx
;
3168 err
= nlmsg_parse(nlh
, sizeof(*ifm
), tb
, IFA_MAX
, ifa_ipv6_policy
);
3172 ifm
= nlmsg_data(nlh
);
3173 pfx
= extract_addr(tb
[IFA_ADDRESS
], tb
[IFA_LOCAL
]);
3177 return inet6_addr_del(net
, ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
);
3180 static int inet6_addr_modify(struct inet6_ifaddr
*ifp
, u8 ifa_flags
,
3181 u32 prefered_lft
, u32 valid_lft
)
3185 unsigned long timeout
;
3187 if (!valid_lft
|| (prefered_lft
> valid_lft
))
3190 timeout
= addrconf_timeout_fixup(valid_lft
, HZ
);
3191 if (addrconf_finite_timeout(timeout
)) {
3192 expires
= jiffies_to_clock_t(timeout
* HZ
);
3193 valid_lft
= timeout
;
3194 flags
= RTF_EXPIRES
;
3198 ifa_flags
|= IFA_F_PERMANENT
;
3201 timeout
= addrconf_timeout_fixup(prefered_lft
, HZ
);
3202 if (addrconf_finite_timeout(timeout
)) {
3204 ifa_flags
|= IFA_F_DEPRECATED
;
3205 prefered_lft
= timeout
;
3208 spin_lock_bh(&ifp
->lock
);
3209 ifp
->flags
= (ifp
->flags
& ~(IFA_F_DEPRECATED
| IFA_F_PERMANENT
| IFA_F_NODAD
| IFA_F_HOMEADDRESS
)) | ifa_flags
;
3210 ifp
->tstamp
= jiffies
;
3211 ifp
->valid_lft
= valid_lft
;
3212 ifp
->prefered_lft
= prefered_lft
;
3214 spin_unlock_bh(&ifp
->lock
);
3215 if (!(ifp
->flags
&IFA_F_TENTATIVE
))
3216 ipv6_ifa_notify(0, ifp
);
3218 addrconf_prefix_route(&ifp
->addr
, ifp
->prefix_len
, ifp
->idev
->dev
,
3226 inet6_rtm_newaddr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
3228 struct net
*net
= sock_net(skb
->sk
);
3229 struct ifaddrmsg
*ifm
;
3230 struct nlattr
*tb
[IFA_MAX
+1];
3231 struct in6_addr
*pfx
;
3232 struct inet6_ifaddr
*ifa
;
3233 struct net_device
*dev
;
3234 u32 valid_lft
= INFINITY_LIFE_TIME
, preferred_lft
= INFINITY_LIFE_TIME
;
3238 err
= nlmsg_parse(nlh
, sizeof(*ifm
), tb
, IFA_MAX
, ifa_ipv6_policy
);
3242 ifm
= nlmsg_data(nlh
);
3243 pfx
= extract_addr(tb
[IFA_ADDRESS
], tb
[IFA_LOCAL
]);
3247 if (tb
[IFA_CACHEINFO
]) {
3248 struct ifa_cacheinfo
*ci
;
3250 ci
= nla_data(tb
[IFA_CACHEINFO
]);
3251 valid_lft
= ci
->ifa_valid
;
3252 preferred_lft
= ci
->ifa_prefered
;
3254 preferred_lft
= INFINITY_LIFE_TIME
;
3255 valid_lft
= INFINITY_LIFE_TIME
;
3258 dev
= __dev_get_by_index(net
, ifm
->ifa_index
);
3262 /* We ignore other flags so far. */
3263 ifa_flags
= ifm
->ifa_flags
& (IFA_F_NODAD
| IFA_F_HOMEADDRESS
);
3265 ifa
= ipv6_get_ifaddr(net
, pfx
, dev
, 1);
3268 * It would be best to check for !NLM_F_CREATE here but
3269 * userspace alreay relies on not having to provide this.
3271 return inet6_addr_add(net
, ifm
->ifa_index
, pfx
,
3272 ifm
->ifa_prefixlen
, ifa_flags
,
3273 preferred_lft
, valid_lft
);
3276 if (nlh
->nlmsg_flags
& NLM_F_EXCL
||
3277 !(nlh
->nlmsg_flags
& NLM_F_REPLACE
))
3280 err
= inet6_addr_modify(ifa
, ifa_flags
, preferred_lft
, valid_lft
);
3287 static void put_ifaddrmsg(struct nlmsghdr
*nlh
, u8 prefixlen
, u8 flags
,
3288 u8 scope
, int ifindex
)
3290 struct ifaddrmsg
*ifm
;
3292 ifm
= nlmsg_data(nlh
);
3293 ifm
->ifa_family
= AF_INET6
;
3294 ifm
->ifa_prefixlen
= prefixlen
;
3295 ifm
->ifa_flags
= flags
;
3296 ifm
->ifa_scope
= scope
;
3297 ifm
->ifa_index
= ifindex
;
3300 static int put_cacheinfo(struct sk_buff
*skb
, unsigned long cstamp
,
3301 unsigned long tstamp
, u32 preferred
, u32 valid
)
3303 struct ifa_cacheinfo ci
;
3305 ci
.cstamp
= (u32
)(TIME_DELTA(cstamp
, INITIAL_JIFFIES
) / HZ
* 100
3306 + TIME_DELTA(cstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3307 ci
.tstamp
= (u32
)(TIME_DELTA(tstamp
, INITIAL_JIFFIES
) / HZ
* 100
3308 + TIME_DELTA(tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3309 ci
.ifa_prefered
= preferred
;
3310 ci
.ifa_valid
= valid
;
3312 return nla_put(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
3315 static inline int rt_scope(int ifa_scope
)
3317 if (ifa_scope
& IFA_HOST
)
3318 return RT_SCOPE_HOST
;
3319 else if (ifa_scope
& IFA_LINK
)
3320 return RT_SCOPE_LINK
;
3321 else if (ifa_scope
& IFA_SITE
)
3322 return RT_SCOPE_SITE
;
3324 return RT_SCOPE_UNIVERSE
;
3327 static inline int inet6_ifaddr_msgsize(void)
3329 return NLMSG_ALIGN(sizeof(struct ifaddrmsg
))
3330 + nla_total_size(16) /* IFA_ADDRESS */
3331 + nla_total_size(sizeof(struct ifa_cacheinfo
));
3334 static int inet6_fill_ifaddr(struct sk_buff
*skb
, struct inet6_ifaddr
*ifa
,
3335 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3337 struct nlmsghdr
*nlh
;
3338 u32 preferred
, valid
;
3340 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(struct ifaddrmsg
), flags
);
3344 put_ifaddrmsg(nlh
, ifa
->prefix_len
, ifa
->flags
, rt_scope(ifa
->scope
),
3345 ifa
->idev
->dev
->ifindex
);
3347 if (!(ifa
->flags
&IFA_F_PERMANENT
)) {
3348 preferred
= ifa
->prefered_lft
;
3349 valid
= ifa
->valid_lft
;
3350 if (preferred
!= INFINITY_LIFE_TIME
) {
3351 long tval
= (jiffies
- ifa
->tstamp
)/HZ
;
3353 if (valid
!= INFINITY_LIFE_TIME
)
3357 preferred
= INFINITY_LIFE_TIME
;
3358 valid
= INFINITY_LIFE_TIME
;
3361 if (nla_put(skb
, IFA_ADDRESS
, 16, &ifa
->addr
) < 0 ||
3362 put_cacheinfo(skb
, ifa
->cstamp
, ifa
->tstamp
, preferred
, valid
) < 0) {
3363 nlmsg_cancel(skb
, nlh
);
3367 return nlmsg_end(skb
, nlh
);
3370 static int inet6_fill_ifmcaddr(struct sk_buff
*skb
, struct ifmcaddr6
*ifmca
,
3371 u32 pid
, u32 seq
, int event
, u16 flags
)
3373 struct nlmsghdr
*nlh
;
3374 u8 scope
= RT_SCOPE_UNIVERSE
;
3375 int ifindex
= ifmca
->idev
->dev
->ifindex
;
3377 if (ipv6_addr_scope(&ifmca
->mca_addr
) & IFA_SITE
)
3378 scope
= RT_SCOPE_SITE
;
3380 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(struct ifaddrmsg
), flags
);
3384 put_ifaddrmsg(nlh
, 128, IFA_F_PERMANENT
, scope
, ifindex
);
3385 if (nla_put(skb
, IFA_MULTICAST
, 16, &ifmca
->mca_addr
) < 0 ||
3386 put_cacheinfo(skb
, ifmca
->mca_cstamp
, ifmca
->mca_tstamp
,
3387 INFINITY_LIFE_TIME
, INFINITY_LIFE_TIME
) < 0) {
3388 nlmsg_cancel(skb
, nlh
);
3392 return nlmsg_end(skb
, nlh
);
3395 static int inet6_fill_ifacaddr(struct sk_buff
*skb
, struct ifacaddr6
*ifaca
,
3396 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3398 struct nlmsghdr
*nlh
;
3399 u8 scope
= RT_SCOPE_UNIVERSE
;
3400 int ifindex
= ifaca
->aca_idev
->dev
->ifindex
;
3402 if (ipv6_addr_scope(&ifaca
->aca_addr
) & IFA_SITE
)
3403 scope
= RT_SCOPE_SITE
;
3405 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(struct ifaddrmsg
), flags
);
3409 put_ifaddrmsg(nlh
, 128, IFA_F_PERMANENT
, scope
, ifindex
);
3410 if (nla_put(skb
, IFA_ANYCAST
, 16, &ifaca
->aca_addr
) < 0 ||
3411 put_cacheinfo(skb
, ifaca
->aca_cstamp
, ifaca
->aca_tstamp
,
3412 INFINITY_LIFE_TIME
, INFINITY_LIFE_TIME
) < 0) {
3413 nlmsg_cancel(skb
, nlh
);
3417 return nlmsg_end(skb
, nlh
);
3427 static int inet6_dump_addr(struct sk_buff
*skb
, struct netlink_callback
*cb
,
3428 enum addr_type_t type
)
3431 int s_idx
, s_ip_idx
;
3433 struct net_device
*dev
;
3434 struct inet6_dev
*idev
= NULL
;
3435 struct inet6_ifaddr
*ifa
;
3436 struct ifmcaddr6
*ifmca
;
3437 struct ifacaddr6
*ifaca
;
3438 struct net
*net
= sock_net(skb
->sk
);
3440 s_idx
= cb
->args
[0];
3441 s_ip_idx
= ip_idx
= cb
->args
[1];
3444 for_each_netdev(net
, dev
) {
3450 if ((idev
= in6_dev_get(dev
)) == NULL
)
3452 read_lock_bh(&idev
->lock
);
3455 /* unicast address incl. temp addr */
3456 for (ifa
= idev
->addr_list
; ifa
;
3457 ifa
= ifa
->if_next
, ip_idx
++) {
3458 if (ip_idx
< s_ip_idx
)
3460 err
= inet6_fill_ifaddr(skb
, ifa
,
3461 NETLINK_CB(cb
->skb
).pid
,
3467 case MULTICAST_ADDR
:
3468 /* multicast address */
3469 for (ifmca
= idev
->mc_list
; ifmca
;
3470 ifmca
= ifmca
->next
, ip_idx
++) {
3471 if (ip_idx
< s_ip_idx
)
3473 err
= inet6_fill_ifmcaddr(skb
, ifmca
,
3474 NETLINK_CB(cb
->skb
).pid
,
3481 /* anycast address */
3482 for (ifaca
= idev
->ac_list
; ifaca
;
3483 ifaca
= ifaca
->aca_next
, ip_idx
++) {
3484 if (ip_idx
< s_ip_idx
)
3486 err
= inet6_fill_ifacaddr(skb
, ifaca
,
3487 NETLINK_CB(cb
->skb
).pid
,
3496 read_unlock_bh(&idev
->lock
);
3505 cb
->args
[1] = ip_idx
;
3509 static int inet6_dump_ifaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3511 enum addr_type_t type
= UNICAST_ADDR
;
3513 return inet6_dump_addr(skb
, cb
, type
);
3516 static int inet6_dump_ifmcaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3518 enum addr_type_t type
= MULTICAST_ADDR
;
3520 return inet6_dump_addr(skb
, cb
, type
);
3524 static int inet6_dump_ifacaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3526 enum addr_type_t type
= ANYCAST_ADDR
;
3528 return inet6_dump_addr(skb
, cb
, type
);
3531 static int inet6_rtm_getaddr(struct sk_buff
*in_skb
, struct nlmsghdr
* nlh
,
3534 struct net
*net
= sock_net(in_skb
->sk
);
3535 struct ifaddrmsg
*ifm
;
3536 struct nlattr
*tb
[IFA_MAX
+1];
3537 struct in6_addr
*addr
= NULL
;
3538 struct net_device
*dev
= NULL
;
3539 struct inet6_ifaddr
*ifa
;
3540 struct sk_buff
*skb
;
3543 err
= nlmsg_parse(nlh
, sizeof(*ifm
), tb
, IFA_MAX
, ifa_ipv6_policy
);
3547 addr
= extract_addr(tb
[IFA_ADDRESS
], tb
[IFA_LOCAL
]);
3553 ifm
= nlmsg_data(nlh
);
3555 dev
= __dev_get_by_index(net
, ifm
->ifa_index
);
3557 if ((ifa
= ipv6_get_ifaddr(net
, addr
, dev
, 1)) == NULL
) {
3558 err
= -EADDRNOTAVAIL
;
3562 if ((skb
= nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL
)) == NULL
) {
3567 err
= inet6_fill_ifaddr(skb
, ifa
, NETLINK_CB(in_skb
).pid
,
3568 nlh
->nlmsg_seq
, RTM_NEWADDR
, 0);
3570 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
3571 WARN_ON(err
== -EMSGSIZE
);
3575 err
= rtnl_unicast(skb
, net
, NETLINK_CB(in_skb
).pid
);
3582 static void inet6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
)
3584 struct sk_buff
*skb
;
3585 struct net
*net
= dev_net(ifa
->idev
->dev
);
3588 skb
= nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC
);
3592 err
= inet6_fill_ifaddr(skb
, ifa
, 0, 0, event
, 0);
3594 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */
3595 WARN_ON(err
== -EMSGSIZE
);
3599 err
= rtnl_notify(skb
, net
, 0, RTNLGRP_IPV6_IFADDR
, NULL
, GFP_ATOMIC
);
3602 rtnl_set_sk_err(net
, RTNLGRP_IPV6_IFADDR
, err
);
3605 static inline void ipv6_store_devconf(struct ipv6_devconf
*cnf
,
3606 __s32
*array
, int bytes
)
3608 BUG_ON(bytes
< (DEVCONF_MAX
* 4));
3610 memset(array
, 0, bytes
);
3611 array
[DEVCONF_FORWARDING
] = cnf
->forwarding
;
3612 array
[DEVCONF_HOPLIMIT
] = cnf
->hop_limit
;
3613 array
[DEVCONF_MTU6
] = cnf
->mtu6
;
3614 array
[DEVCONF_ACCEPT_RA
] = cnf
->accept_ra
;
3615 array
[DEVCONF_ACCEPT_REDIRECTS
] = cnf
->accept_redirects
;
3616 array
[DEVCONF_AUTOCONF
] = cnf
->autoconf
;
3617 array
[DEVCONF_DAD_TRANSMITS
] = cnf
->dad_transmits
;
3618 array
[DEVCONF_RTR_SOLICITS
] = cnf
->rtr_solicits
;
3619 array
[DEVCONF_RTR_SOLICIT_INTERVAL
] = cnf
->rtr_solicit_interval
;
3620 array
[DEVCONF_RTR_SOLICIT_DELAY
] = cnf
->rtr_solicit_delay
;
3621 array
[DEVCONF_FORCE_MLD_VERSION
] = cnf
->force_mld_version
;
3622 #ifdef CONFIG_IPV6_PRIVACY
3623 array
[DEVCONF_USE_TEMPADDR
] = cnf
->use_tempaddr
;
3624 array
[DEVCONF_TEMP_VALID_LFT
] = cnf
->temp_valid_lft
;
3625 array
[DEVCONF_TEMP_PREFERED_LFT
] = cnf
->temp_prefered_lft
;
3626 array
[DEVCONF_REGEN_MAX_RETRY
] = cnf
->regen_max_retry
;
3627 array
[DEVCONF_MAX_DESYNC_FACTOR
] = cnf
->max_desync_factor
;
3629 array
[DEVCONF_MAX_ADDRESSES
] = cnf
->max_addresses
;
3630 array
[DEVCONF_ACCEPT_RA_DEFRTR
] = cnf
->accept_ra_defrtr
;
3631 array
[DEVCONF_ACCEPT_RA_PINFO
] = cnf
->accept_ra_pinfo
;
3632 #ifdef CONFIG_IPV6_ROUTER_PREF
3633 array
[DEVCONF_ACCEPT_RA_RTR_PREF
] = cnf
->accept_ra_rtr_pref
;
3634 array
[DEVCONF_RTR_PROBE_INTERVAL
] = cnf
->rtr_probe_interval
;
3635 #ifdef CONFIG_IPV6_ROUTE_INFO
3636 array
[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN
] = cnf
->accept_ra_rt_info_max_plen
;
3639 array
[DEVCONF_PROXY_NDP
] = cnf
->proxy_ndp
;
3640 array
[DEVCONF_ACCEPT_SOURCE_ROUTE
] = cnf
->accept_source_route
;
3641 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
3642 array
[DEVCONF_OPTIMISTIC_DAD
] = cnf
->optimistic_dad
;
3644 #ifdef CONFIG_IPV6_MROUTE
3645 array
[DEVCONF_MC_FORWARDING
] = cnf
->mc_forwarding
;
3649 static inline size_t inet6_if_nlmsg_size(void)
3651 return NLMSG_ALIGN(sizeof(struct ifinfomsg
))
3652 + nla_total_size(IFNAMSIZ
) /* IFLA_IFNAME */
3653 + nla_total_size(MAX_ADDR_LEN
) /* IFLA_ADDRESS */
3654 + nla_total_size(4) /* IFLA_MTU */
3655 + nla_total_size(4) /* IFLA_LINK */
3656 + nla_total_size( /* IFLA_PROTINFO */
3657 nla_total_size(4) /* IFLA_INET6_FLAGS */
3658 + nla_total_size(sizeof(struct ifla_cacheinfo
))
3659 + nla_total_size(DEVCONF_MAX
* 4) /* IFLA_INET6_CONF */
3660 + nla_total_size(IPSTATS_MIB_MAX
* 8) /* IFLA_INET6_STATS */
3661 + nla_total_size(ICMP6_MIB_MAX
* 8) /* IFLA_INET6_ICMP6STATS */
3665 static inline void __snmp6_fill_stats(u64
*stats
, void **mib
, int items
,
3669 int pad
= bytes
- sizeof(u64
) * items
;
3672 /* Use put_unaligned() because stats may not be aligned for u64. */
3673 put_unaligned(items
, &stats
[0]);
3674 for (i
= 1; i
< items
; i
++)
3675 put_unaligned(snmp_fold_field(mib
, i
), &stats
[i
]);
3677 memset(&stats
[items
], 0, pad
);
3680 static void snmp6_fill_stats(u64
*stats
, struct inet6_dev
*idev
, int attrtype
,
3684 case IFLA_INET6_STATS
:
3685 __snmp6_fill_stats(stats
, (void **)idev
->stats
.ipv6
, IPSTATS_MIB_MAX
, bytes
);
3687 case IFLA_INET6_ICMP6STATS
:
3688 __snmp6_fill_stats(stats
, (void **)idev
->stats
.icmpv6
, ICMP6_MIB_MAX
, bytes
);
3693 static int inet6_fill_ifinfo(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3694 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3696 struct net_device
*dev
= idev
->dev
;
3698 struct ifinfomsg
*hdr
;
3699 struct nlmsghdr
*nlh
;
3701 struct ifla_cacheinfo ci
;
3703 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(*hdr
), flags
);
3707 hdr
= nlmsg_data(nlh
);
3708 hdr
->ifi_family
= AF_INET6
;
3710 hdr
->ifi_type
= dev
->type
;
3711 hdr
->ifi_index
= dev
->ifindex
;
3712 hdr
->ifi_flags
= dev_get_flags(dev
);
3713 hdr
->ifi_change
= 0;
3715 NLA_PUT_STRING(skb
, IFLA_IFNAME
, dev
->name
);
3718 NLA_PUT(skb
, IFLA_ADDRESS
, dev
->addr_len
, dev
->dev_addr
);
3720 NLA_PUT_U32(skb
, IFLA_MTU
, dev
->mtu
);
3721 if (dev
->ifindex
!= dev
->iflink
)
3722 NLA_PUT_U32(skb
, IFLA_LINK
, dev
->iflink
);
3724 protoinfo
= nla_nest_start(skb
, IFLA_PROTINFO
);
3725 if (protoinfo
== NULL
)
3726 goto nla_put_failure
;
3728 NLA_PUT_U32(skb
, IFLA_INET6_FLAGS
, idev
->if_flags
);
3730 ci
.max_reasm_len
= IPV6_MAXPLEN
;
3731 ci
.tstamp
= (__u32
)(TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) / HZ
* 100
3732 + TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3733 ci
.reachable_time
= idev
->nd_parms
->reachable_time
;
3734 ci
.retrans_time
= idev
->nd_parms
->retrans_time
;
3735 NLA_PUT(skb
, IFLA_INET6_CACHEINFO
, sizeof(ci
), &ci
);
3737 nla
= nla_reserve(skb
, IFLA_INET6_CONF
, DEVCONF_MAX
* sizeof(s32
));
3739 goto nla_put_failure
;
3740 ipv6_store_devconf(&idev
->cnf
, nla_data(nla
), nla_len(nla
));
3742 /* XXX - MC not implemented */
3744 nla
= nla_reserve(skb
, IFLA_INET6_STATS
, IPSTATS_MIB_MAX
* sizeof(u64
));
3746 goto nla_put_failure
;
3747 snmp6_fill_stats(nla_data(nla
), idev
, IFLA_INET6_STATS
, nla_len(nla
));
3749 nla
= nla_reserve(skb
, IFLA_INET6_ICMP6STATS
, ICMP6_MIB_MAX
* sizeof(u64
));
3751 goto nla_put_failure
;
3752 snmp6_fill_stats(nla_data(nla
), idev
, IFLA_INET6_ICMP6STATS
, nla_len(nla
));
3754 nla_nest_end(skb
, protoinfo
);
3755 return nlmsg_end(skb
, nlh
);
3758 nlmsg_cancel(skb
, nlh
);
3762 static int inet6_dump_ifinfo(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3764 struct net
*net
= sock_net(skb
->sk
);
3766 int s_idx
= cb
->args
[0];
3767 struct net_device
*dev
;
3768 struct inet6_dev
*idev
;
3770 read_lock(&dev_base_lock
);
3772 for_each_netdev(net
, dev
) {
3775 if ((idev
= in6_dev_get(dev
)) == NULL
)
3777 err
= inet6_fill_ifinfo(skb
, idev
, NETLINK_CB(cb
->skb
).pid
,
3778 cb
->nlh
->nlmsg_seq
, RTM_NEWLINK
, NLM_F_MULTI
);
3785 read_unlock(&dev_base_lock
);
3791 void inet6_ifinfo_notify(int event
, struct inet6_dev
*idev
)
3793 struct sk_buff
*skb
;
3794 struct net
*net
= dev_net(idev
->dev
);
3797 skb
= nlmsg_new(inet6_if_nlmsg_size(), GFP_ATOMIC
);
3801 err
= inet6_fill_ifinfo(skb
, idev
, 0, 0, event
, 0);
3803 /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */
3804 WARN_ON(err
== -EMSGSIZE
);
3808 err
= rtnl_notify(skb
, net
, 0, RTNLGRP_IPV6_IFADDR
, NULL
, GFP_ATOMIC
);
3811 rtnl_set_sk_err(net
, RTNLGRP_IPV6_IFADDR
, err
);
3814 static inline size_t inet6_prefix_nlmsg_size(void)
3816 return NLMSG_ALIGN(sizeof(struct prefixmsg
))
3817 + nla_total_size(sizeof(struct in6_addr
))
3818 + nla_total_size(sizeof(struct prefix_cacheinfo
));
3821 static int inet6_fill_prefix(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3822 struct prefix_info
*pinfo
, u32 pid
, u32 seq
,
3823 int event
, unsigned int flags
)
3825 struct prefixmsg
*pmsg
;
3826 struct nlmsghdr
*nlh
;
3827 struct prefix_cacheinfo ci
;
3829 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(*pmsg
), flags
);
3833 pmsg
= nlmsg_data(nlh
);
3834 pmsg
->prefix_family
= AF_INET6
;
3835 pmsg
->prefix_pad1
= 0;
3836 pmsg
->prefix_pad2
= 0;
3837 pmsg
->prefix_ifindex
= idev
->dev
->ifindex
;
3838 pmsg
->prefix_len
= pinfo
->prefix_len
;
3839 pmsg
->prefix_type
= pinfo
->type
;
3840 pmsg
->prefix_pad3
= 0;
3841 pmsg
->prefix_flags
= 0;
3843 pmsg
->prefix_flags
|= IF_PREFIX_ONLINK
;
3844 if (pinfo
->autoconf
)
3845 pmsg
->prefix_flags
|= IF_PREFIX_AUTOCONF
;
3847 NLA_PUT(skb
, PREFIX_ADDRESS
, sizeof(pinfo
->prefix
), &pinfo
->prefix
);
3849 ci
.preferred_time
= ntohl(pinfo
->prefered
);
3850 ci
.valid_time
= ntohl(pinfo
->valid
);
3851 NLA_PUT(skb
, PREFIX_CACHEINFO
, sizeof(ci
), &ci
);
3853 return nlmsg_end(skb
, nlh
);
3856 nlmsg_cancel(skb
, nlh
);
3860 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
3861 struct prefix_info
*pinfo
)
3863 struct sk_buff
*skb
;
3864 struct net
*net
= dev_net(idev
->dev
);
3867 skb
= nlmsg_new(inet6_prefix_nlmsg_size(), GFP_ATOMIC
);
3871 err
= inet6_fill_prefix(skb
, idev
, pinfo
, 0, 0, event
, 0);
3873 /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */
3874 WARN_ON(err
== -EMSGSIZE
);
3878 err
= rtnl_notify(skb
, net
, 0, RTNLGRP_IPV6_PREFIX
, NULL
, GFP_ATOMIC
);
3881 rtnl_set_sk_err(net
, RTNLGRP_IPV6_PREFIX
, err
);
3884 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3886 inet6_ifa_notify(event
? : RTM_NEWADDR
, ifp
);
3891 * If the address was optimistic
3892 * we inserted the route at the start of
3893 * our DAD process, so we don't need
3896 if (!(ifp
->rt
->rt6i_node
))
3897 ip6_ins_rt(ifp
->rt
);
3898 if (ifp
->idev
->cnf
.forwarding
)
3899 addrconf_join_anycast(ifp
);
3902 if (ifp
->idev
->cnf
.forwarding
)
3903 addrconf_leave_anycast(ifp
);
3904 addrconf_leave_solict(ifp
->idev
, &ifp
->addr
);
3905 dst_hold(&ifp
->rt
->u
.dst
);
3906 if (ip6_del_rt(ifp
->rt
))
3907 dst_free(&ifp
->rt
->u
.dst
);
3912 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3915 if (likely(ifp
->idev
->dead
== 0))
3916 __ipv6_ifa_notify(event
, ifp
);
3917 rcu_read_unlock_bh();
3920 #ifdef CONFIG_SYSCTL
3923 int addrconf_sysctl_forward(ctl_table
*ctl
, int write
, struct file
* filp
,
3924 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3926 int *valp
= ctl
->data
;
3930 ret
= proc_dointvec(ctl
, write
, filp
, buffer
, lenp
, ppos
);
3933 addrconf_fixup_forwarding(ctl
, valp
, val
);
3937 static int addrconf_sysctl_forward_strategy(ctl_table
*table
,
3938 int __user
*name
, int nlen
,
3939 void __user
*oldval
,
3940 size_t __user
*oldlenp
,
3941 void __user
*newval
, size_t newlen
)
3943 int *valp
= table
->data
;
3947 if (!newval
|| !newlen
)
3949 if (newlen
!= sizeof(int))
3951 if (get_user(new, (int __user
*)newval
))
3955 if (oldval
&& oldlenp
) {
3957 if (get_user(len
, oldlenp
))
3960 if (len
> table
->maxlen
)
3961 len
= table
->maxlen
;
3962 if (copy_to_user(oldval
, valp
, len
))
3964 if (put_user(len
, oldlenp
))
3970 addrconf_fixup_forwarding(table
, valp
, val
);
3974 static struct addrconf_sysctl_table
3976 struct ctl_table_header
*sysctl_header
;
3977 ctl_table addrconf_vars
[DEVCONF_MAX
+1];
3979 } addrconf_sysctl __read_mostly
= {
3980 .sysctl_header
= NULL
,
3983 .ctl_name
= NET_IPV6_FORWARDING
,
3984 .procname
= "forwarding",
3985 .data
= &ipv6_devconf
.forwarding
,
3986 .maxlen
= sizeof(int),
3988 .proc_handler
= &addrconf_sysctl_forward
,
3989 .strategy
= &addrconf_sysctl_forward_strategy
,
3992 .ctl_name
= NET_IPV6_HOP_LIMIT
,
3993 .procname
= "hop_limit",
3994 .data
= &ipv6_devconf
.hop_limit
,
3995 .maxlen
= sizeof(int),
3997 .proc_handler
= proc_dointvec
,
4000 .ctl_name
= NET_IPV6_MTU
,
4002 .data
= &ipv6_devconf
.mtu6
,
4003 .maxlen
= sizeof(int),
4005 .proc_handler
= &proc_dointvec
,
4008 .ctl_name
= NET_IPV6_ACCEPT_RA
,
4009 .procname
= "accept_ra",
4010 .data
= &ipv6_devconf
.accept_ra
,
4011 .maxlen
= sizeof(int),
4013 .proc_handler
= &proc_dointvec
,
4016 .ctl_name
= NET_IPV6_ACCEPT_REDIRECTS
,
4017 .procname
= "accept_redirects",
4018 .data
= &ipv6_devconf
.accept_redirects
,
4019 .maxlen
= sizeof(int),
4021 .proc_handler
= &proc_dointvec
,
4024 .ctl_name
= NET_IPV6_AUTOCONF
,
4025 .procname
= "autoconf",
4026 .data
= &ipv6_devconf
.autoconf
,
4027 .maxlen
= sizeof(int),
4029 .proc_handler
= &proc_dointvec
,
4032 .ctl_name
= NET_IPV6_DAD_TRANSMITS
,
4033 .procname
= "dad_transmits",
4034 .data
= &ipv6_devconf
.dad_transmits
,
4035 .maxlen
= sizeof(int),
4037 .proc_handler
= &proc_dointvec
,
4040 .ctl_name
= NET_IPV6_RTR_SOLICITS
,
4041 .procname
= "router_solicitations",
4042 .data
= &ipv6_devconf
.rtr_solicits
,
4043 .maxlen
= sizeof(int),
4045 .proc_handler
= &proc_dointvec
,
4048 .ctl_name
= NET_IPV6_RTR_SOLICIT_INTERVAL
,
4049 .procname
= "router_solicitation_interval",
4050 .data
= &ipv6_devconf
.rtr_solicit_interval
,
4051 .maxlen
= sizeof(int),
4053 .proc_handler
= &proc_dointvec_jiffies
,
4054 .strategy
= &sysctl_jiffies
,
4057 .ctl_name
= NET_IPV6_RTR_SOLICIT_DELAY
,
4058 .procname
= "router_solicitation_delay",
4059 .data
= &ipv6_devconf
.rtr_solicit_delay
,
4060 .maxlen
= sizeof(int),
4062 .proc_handler
= &proc_dointvec_jiffies
,
4063 .strategy
= &sysctl_jiffies
,
4066 .ctl_name
= NET_IPV6_FORCE_MLD_VERSION
,
4067 .procname
= "force_mld_version",
4068 .data
= &ipv6_devconf
.force_mld_version
,
4069 .maxlen
= sizeof(int),
4071 .proc_handler
= &proc_dointvec
,
4073 #ifdef CONFIG_IPV6_PRIVACY
4075 .ctl_name
= NET_IPV6_USE_TEMPADDR
,
4076 .procname
= "use_tempaddr",
4077 .data
= &ipv6_devconf
.use_tempaddr
,
4078 .maxlen
= sizeof(int),
4080 .proc_handler
= &proc_dointvec
,
4083 .ctl_name
= NET_IPV6_TEMP_VALID_LFT
,
4084 .procname
= "temp_valid_lft",
4085 .data
= &ipv6_devconf
.temp_valid_lft
,
4086 .maxlen
= sizeof(int),
4088 .proc_handler
= &proc_dointvec
,
4091 .ctl_name
= NET_IPV6_TEMP_PREFERED_LFT
,
4092 .procname
= "temp_prefered_lft",
4093 .data
= &ipv6_devconf
.temp_prefered_lft
,
4094 .maxlen
= sizeof(int),
4096 .proc_handler
= &proc_dointvec
,
4099 .ctl_name
= NET_IPV6_REGEN_MAX_RETRY
,
4100 .procname
= "regen_max_retry",
4101 .data
= &ipv6_devconf
.regen_max_retry
,
4102 .maxlen
= sizeof(int),
4104 .proc_handler
= &proc_dointvec
,
4107 .ctl_name
= NET_IPV6_MAX_DESYNC_FACTOR
,
4108 .procname
= "max_desync_factor",
4109 .data
= &ipv6_devconf
.max_desync_factor
,
4110 .maxlen
= sizeof(int),
4112 .proc_handler
= &proc_dointvec
,
4116 .ctl_name
= NET_IPV6_MAX_ADDRESSES
,
4117 .procname
= "max_addresses",
4118 .data
= &ipv6_devconf
.max_addresses
,
4119 .maxlen
= sizeof(int),
4121 .proc_handler
= &proc_dointvec
,
4124 .ctl_name
= NET_IPV6_ACCEPT_RA_DEFRTR
,
4125 .procname
= "accept_ra_defrtr",
4126 .data
= &ipv6_devconf
.accept_ra_defrtr
,
4127 .maxlen
= sizeof(int),
4129 .proc_handler
= &proc_dointvec
,
4132 .ctl_name
= NET_IPV6_ACCEPT_RA_PINFO
,
4133 .procname
= "accept_ra_pinfo",
4134 .data
= &ipv6_devconf
.accept_ra_pinfo
,
4135 .maxlen
= sizeof(int),
4137 .proc_handler
= &proc_dointvec
,
4139 #ifdef CONFIG_IPV6_ROUTER_PREF
4141 .ctl_name
= NET_IPV6_ACCEPT_RA_RTR_PREF
,
4142 .procname
= "accept_ra_rtr_pref",
4143 .data
= &ipv6_devconf
.accept_ra_rtr_pref
,
4144 .maxlen
= sizeof(int),
4146 .proc_handler
= &proc_dointvec
,
4149 .ctl_name
= NET_IPV6_RTR_PROBE_INTERVAL
,
4150 .procname
= "router_probe_interval",
4151 .data
= &ipv6_devconf
.rtr_probe_interval
,
4152 .maxlen
= sizeof(int),
4154 .proc_handler
= &proc_dointvec_jiffies
,
4155 .strategy
= &sysctl_jiffies
,
4157 #ifdef CONFIG_IPV6_ROUTE_INFO
4159 .ctl_name
= NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN
,
4160 .procname
= "accept_ra_rt_info_max_plen",
4161 .data
= &ipv6_devconf
.accept_ra_rt_info_max_plen
,
4162 .maxlen
= sizeof(int),
4164 .proc_handler
= &proc_dointvec
,
4169 .ctl_name
= NET_IPV6_PROXY_NDP
,
4170 .procname
= "proxy_ndp",
4171 .data
= &ipv6_devconf
.proxy_ndp
,
4172 .maxlen
= sizeof(int),
4174 .proc_handler
= &proc_dointvec
,
4177 .ctl_name
= NET_IPV6_ACCEPT_SOURCE_ROUTE
,
4178 .procname
= "accept_source_route",
4179 .data
= &ipv6_devconf
.accept_source_route
,
4180 .maxlen
= sizeof(int),
4182 .proc_handler
= &proc_dointvec
,
4184 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
4186 .ctl_name
= CTL_UNNUMBERED
,
4187 .procname
= "optimistic_dad",
4188 .data
= &ipv6_devconf
.optimistic_dad
,
4189 .maxlen
= sizeof(int),
4191 .proc_handler
= &proc_dointvec
,
4195 #ifdef CONFIG_IPV6_MROUTE
4197 .ctl_name
= CTL_UNNUMBERED
,
4198 .procname
= "mc_forwarding",
4199 .data
= &ipv6_devconf
.mc_forwarding
,
4200 .maxlen
= sizeof(int),
4202 .proc_handler
= &proc_dointvec
,
4206 .ctl_name
= 0, /* sentinel */
4211 static int __addrconf_sysctl_register(struct net
*net
, char *dev_name
,
4212 int ctl_name
, struct inet6_dev
*idev
, struct ipv6_devconf
*p
)
4215 struct addrconf_sysctl_table
*t
;
4217 #define ADDRCONF_CTL_PATH_DEV 3
4219 struct ctl_path addrconf_ctl_path
[] = {
4220 { .procname
= "net", .ctl_name
= CTL_NET
, },
4221 { .procname
= "ipv6", .ctl_name
= NET_IPV6
, },
4222 { .procname
= "conf", .ctl_name
= NET_IPV6_CONF
, },
4223 { /* to be set */ },
4228 t
= kmemdup(&addrconf_sysctl
, sizeof(*t
), GFP_KERNEL
);
4232 for (i
=0; t
->addrconf_vars
[i
].data
; i
++) {
4233 t
->addrconf_vars
[i
].data
+= (char*)p
- (char*)&ipv6_devconf
;
4234 t
->addrconf_vars
[i
].extra1
= idev
; /* embedded; no ref */
4235 t
->addrconf_vars
[i
].extra2
= net
;
4239 * Make a copy of dev_name, because '.procname' is regarded as const
4240 * by sysctl and we wouldn't want anyone to change it under our feet
4241 * (see SIOCSIFNAME).
4243 t
->dev_name
= kstrdup(dev_name
, GFP_KERNEL
);
4247 addrconf_ctl_path
[ADDRCONF_CTL_PATH_DEV
].procname
= t
->dev_name
;
4248 addrconf_ctl_path
[ADDRCONF_CTL_PATH_DEV
].ctl_name
= ctl_name
;
4250 t
->sysctl_header
= register_net_sysctl_table(net
, addrconf_ctl_path
,
4252 if (t
->sysctl_header
== NULL
)
4266 static void __addrconf_sysctl_unregister(struct ipv6_devconf
*p
)
4268 struct addrconf_sysctl_table
*t
;
4270 if (p
->sysctl
== NULL
)
4275 unregister_sysctl_table(t
->sysctl_header
);
4280 static void addrconf_sysctl_register(struct inet6_dev
*idev
)
4282 neigh_sysctl_register(idev
->dev
, idev
->nd_parms
, NET_IPV6
,
4283 NET_IPV6_NEIGH
, "ipv6",
4284 &ndisc_ifinfo_sysctl_change
,
4285 ndisc_ifinfo_sysctl_strategy
);
4286 __addrconf_sysctl_register(dev_net(idev
->dev
), idev
->dev
->name
,
4287 idev
->dev
->ifindex
, idev
, &idev
->cnf
);
4290 static void addrconf_sysctl_unregister(struct inet6_dev
*idev
)
4292 __addrconf_sysctl_unregister(&idev
->cnf
);
4293 neigh_sysctl_unregister(idev
->nd_parms
);
4299 static int addrconf_init_net(struct net
*net
)
4302 struct ipv6_devconf
*all
, *dflt
;
4305 all
= &ipv6_devconf
;
4306 dflt
= &ipv6_devconf_dflt
;
4308 if (net
!= &init_net
) {
4309 all
= kmemdup(all
, sizeof(ipv6_devconf
), GFP_KERNEL
);
4313 dflt
= kmemdup(dflt
, sizeof(ipv6_devconf_dflt
), GFP_KERNEL
);
4315 goto err_alloc_dflt
;
4318 net
->ipv6
.devconf_all
= all
;
4319 net
->ipv6
.devconf_dflt
= dflt
;
4321 #ifdef CONFIG_SYSCTL
4322 err
= __addrconf_sysctl_register(net
, "all", NET_PROTO_CONF_ALL
,
4327 err
= __addrconf_sysctl_register(net
, "default", NET_PROTO_CONF_DEFAULT
,
4334 #ifdef CONFIG_SYSCTL
4336 __addrconf_sysctl_unregister(all
);
4346 static void addrconf_exit_net(struct net
*net
)
4348 #ifdef CONFIG_SYSCTL
4349 __addrconf_sysctl_unregister(net
->ipv6
.devconf_dflt
);
4350 __addrconf_sysctl_unregister(net
->ipv6
.devconf_all
);
4352 if (net
!= &init_net
) {
4353 kfree(net
->ipv6
.devconf_dflt
);
4354 kfree(net
->ipv6
.devconf_all
);
4358 static struct pernet_operations addrconf_ops
= {
4359 .init
= addrconf_init_net
,
4360 .exit
= addrconf_exit_net
,
4367 int register_inet6addr_notifier(struct notifier_block
*nb
)
4369 return atomic_notifier_chain_register(&inet6addr_chain
, nb
);
4372 EXPORT_SYMBOL(register_inet6addr_notifier
);
4374 int unregister_inet6addr_notifier(struct notifier_block
*nb
)
4376 return atomic_notifier_chain_unregister(&inet6addr_chain
,nb
);
4379 EXPORT_SYMBOL(unregister_inet6addr_notifier
);
4381 static void addrconf_net_exit(struct net
*net
)
4383 struct net_device
*dev
;
4386 /* clean dev list */
4387 for_each_netdev(net
, dev
) {
4388 if (__in6_dev_get(dev
) == NULL
)
4390 addrconf_ifdown(dev
, 1);
4392 addrconf_ifdown(net
->loopback_dev
, 2);
4396 static struct pernet_operations addrconf_net_ops
= {
4397 .exit
= addrconf_net_exit
,
4401 * Init / cleanup code
4404 int __init
addrconf_init(void)
4408 if ((err
= ipv6_addr_label_init()) < 0) {
4409 printk(KERN_CRIT
"IPv6 Addrconf: cannot initialize default policy table: %d.\n",
4414 register_pernet_subsys(&addrconf_ops
);
4416 /* The addrconf netdev notifier requires that loopback_dev
4417 * has it's ipv6 private information allocated and setup
4418 * before it can bring up and give link-local addresses
4419 * to other devices which are up.
4421 * Unfortunately, loopback_dev is not necessarily the first
4422 * entry in the global dev_base list of net devices. In fact,
4423 * it is likely to be the very last entry on that list.
4424 * So this causes the notifier registry below to try and
4425 * give link-local addresses to all devices besides loopback_dev
4426 * first, then loopback_dev, which cases all the non-loopback_dev
4427 * devices to fail to get a link-local address.
4429 * So, as a temporary fix, allocate the ipv6 structure for
4430 * loopback_dev first by hand.
4431 * Longer term, all of the dependencies ipv6 has upon the loopback
4432 * device and it being up should be removed.
4435 if (!ipv6_add_dev(init_net
.loopback_dev
))
4441 err
= register_pernet_device(&addrconf_net_ops
);
4445 register_netdevice_notifier(&ipv6_dev_notf
);
4449 err
= __rtnl_register(PF_INET6
, RTM_GETLINK
, NULL
, inet6_dump_ifinfo
);
4453 /* Only the first call to __rtnl_register can fail */
4454 __rtnl_register(PF_INET6
, RTM_NEWADDR
, inet6_rtm_newaddr
, NULL
);
4455 __rtnl_register(PF_INET6
, RTM_DELADDR
, inet6_rtm_deladdr
, NULL
);
4456 __rtnl_register(PF_INET6
, RTM_GETADDR
, inet6_rtm_getaddr
, inet6_dump_ifaddr
);
4457 __rtnl_register(PF_INET6
, RTM_GETMULTICAST
, NULL
, inet6_dump_ifmcaddr
);
4458 __rtnl_register(PF_INET6
, RTM_GETANYCAST
, NULL
, inet6_dump_ifacaddr
);
4460 ipv6_addr_label_rtnl_register();
4464 unregister_netdevice_notifier(&ipv6_dev_notf
);
4466 unregister_pernet_subsys(&addrconf_ops
);
4471 void addrconf_cleanup(void)
4473 struct inet6_ifaddr
*ifa
;
4476 unregister_netdevice_notifier(&ipv6_dev_notf
);
4477 unregister_pernet_device(&addrconf_net_ops
);
4479 unregister_pernet_subsys(&addrconf_ops
);
4486 write_lock_bh(&addrconf_hash_lock
);
4487 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
4488 for (ifa
=inet6_addr_lst
[i
]; ifa
; ) {
4489 struct inet6_ifaddr
*bifa
;
4492 ifa
= ifa
->lst_next
;
4493 printk(KERN_DEBUG
"bug: IPv6 address leakage detected: ifa=%p\n", bifa
);
4494 /* Do not free it; something is wrong.
4495 Now we can investigate it with debugger.
4499 write_unlock_bh(&addrconf_hash_lock
);
4501 del_timer(&addr_chk_timer
);
4504 unregister_pernet_subsys(&addrconf_net_ops
);