2 * IPv6 Address [auto]configuration
3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
9 * $Id: addrconf.c,v 1.69 2001/10/31 21:55:54 davem Exp $
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
20 * Janos Farkas : delete timer on ifdown
21 * <chexum@bankinf.banki.hu>
22 * Andi Kleen : kill double kfree on module
24 * Maciej W. Rozycki : FDDI support
25 * sekiya@USAGI : Don't send too many RS
27 * yoshfuji@USAGI : Fixed interval between DAD
29 * YOSHIFUJI Hideaki @USAGI : improved accuracy of
30 * address validation timer.
31 * YOSHIFUJI Hideaki @USAGI : Privacy Extensions (RFC3041)
33 * Yuji SEKIYA @USAGI : Don't assign a same IPv6
34 * address on a same interface.
35 * YOSHIFUJI Hideaki @USAGI : ARCnet support
36 * YOSHIFUJI Hideaki @USAGI : convert /proc/net/if_inet6 to
38 * YOSHIFUJI Hideaki @USAGI : improved source address
39 * selection; consider scope,
43 #include <linux/errno.h>
44 #include <linux/types.h>
45 #include <linux/socket.h>
46 #include <linux/sockios.h>
47 #include <linux/sched.h>
48 #include <linux/net.h>
49 #include <linux/in6.h>
50 #include <linux/netdevice.h>
51 #include <linux/if_arp.h>
52 #include <linux/if_arcnet.h>
53 #include <linux/if_infiniband.h>
54 #include <linux/route.h>
55 #include <linux/inetdevice.h>
56 #include <linux/init.h>
58 #include <linux/sysctl.h>
60 #include <linux/capability.h>
61 #include <linux/delay.h>
62 #include <linux/notifier.h>
63 #include <linux/string.h>
69 #include <net/protocol.h>
70 #include <net/ndisc.h>
71 #include <net/ip6_route.h>
72 #include <net/addrconf.h>
75 #include <linux/if_tunnel.h>
76 #include <linux/rtnetlink.h>
78 #ifdef CONFIG_IPV6_PRIVACY
79 #include <linux/random.h>
82 #include <asm/uaccess.h>
84 #include <linux/proc_fs.h>
85 #include <linux/seq_file.h>
87 /* Set to 3 to get tracing... */
91 #define ADBG(x) printk x
96 #define INFINITY_LIFE_TIME 0xFFFFFFFF
97 #define TIME_DELTA(a,b) ((unsigned long)((long)(a) - (long)(b)))
100 static void addrconf_sysctl_register(struct inet6_dev
*idev
, struct ipv6_devconf
*p
);
101 static void addrconf_sysctl_unregister(struct ipv6_devconf
*p
);
104 #ifdef CONFIG_IPV6_PRIVACY
105 static int __ipv6_regen_rndid(struct inet6_dev
*idev
);
106 static int __ipv6_try_regen_rndid(struct inet6_dev
*idev
, struct in6_addr
*tmpaddr
);
107 static void ipv6_regen_rndid(unsigned long data
);
109 static int desync_factor
= MAX_DESYNC_FACTOR
* HZ
;
112 static int ipv6_count_addresses(struct inet6_dev
*idev
);
115 * Configured unicast address hash table
117 static struct inet6_ifaddr
*inet6_addr_lst
[IN6_ADDR_HSIZE
];
118 static DEFINE_RWLOCK(addrconf_hash_lock
);
120 /* Protects inet6 devices */
121 DEFINE_RWLOCK(addrconf_lock
);
123 static void addrconf_verify(unsigned long);
125 static DEFINE_TIMER(addr_chk_timer
, addrconf_verify
, 0, 0);
126 static DEFINE_SPINLOCK(addrconf_verify_lock
);
128 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
);
129 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
);
131 static int addrconf_ifdown(struct net_device
*dev
, int how
);
133 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
);
134 static void addrconf_dad_timer(unsigned long data
);
135 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
);
136 static void addrconf_dad_run(struct inet6_dev
*idev
);
137 static void addrconf_rs_timer(unsigned long data
);
138 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
);
139 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
);
141 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
142 struct prefix_info
*pinfo
);
143 static int ipv6_chk_same_addr(const struct in6_addr
*addr
, struct net_device
*dev
);
145 static ATOMIC_NOTIFIER_HEAD(inet6addr_chain
);
147 struct ipv6_devconf ipv6_devconf
= {
149 .hop_limit
= IPV6_DEFAULT_HOPLIMIT
,
150 .mtu6
= IPV6_MIN_MTU
,
152 .accept_redirects
= 1,
154 .force_mld_version
= 0,
156 .rtr_solicits
= MAX_RTR_SOLICITATIONS
,
157 .rtr_solicit_interval
= RTR_SOLICITATION_INTERVAL
,
158 .rtr_solicit_delay
= MAX_RTR_SOLICITATION_DELAY
,
159 #ifdef CONFIG_IPV6_PRIVACY
161 .temp_valid_lft
= TEMP_VALID_LIFETIME
,
162 .temp_prefered_lft
= TEMP_PREFERRED_LIFETIME
,
163 .regen_max_retry
= REGEN_MAX_RETRY
,
164 .max_desync_factor
= MAX_DESYNC_FACTOR
,
166 .max_addresses
= IPV6_MAX_ADDRESSES
,
167 .accept_ra_defrtr
= 1,
168 .accept_ra_pinfo
= 1,
169 #ifdef CONFIG_IPV6_ROUTER_PREF
170 .accept_ra_rtr_pref
= 1,
171 .rtr_probe_interval
= 60 * HZ
,
172 #ifdef CONFIG_IPV6_ROUTE_INFO
173 .accept_ra_rt_info_max_plen
= 0,
178 static struct ipv6_devconf ipv6_devconf_dflt
= {
180 .hop_limit
= IPV6_DEFAULT_HOPLIMIT
,
181 .mtu6
= IPV6_MIN_MTU
,
183 .accept_redirects
= 1,
186 .rtr_solicits
= MAX_RTR_SOLICITATIONS
,
187 .rtr_solicit_interval
= RTR_SOLICITATION_INTERVAL
,
188 .rtr_solicit_delay
= MAX_RTR_SOLICITATION_DELAY
,
189 #ifdef CONFIG_IPV6_PRIVACY
191 .temp_valid_lft
= TEMP_VALID_LIFETIME
,
192 .temp_prefered_lft
= TEMP_PREFERRED_LIFETIME
,
193 .regen_max_retry
= REGEN_MAX_RETRY
,
194 .max_desync_factor
= MAX_DESYNC_FACTOR
,
196 .max_addresses
= IPV6_MAX_ADDRESSES
,
197 .accept_ra_defrtr
= 1,
198 .accept_ra_pinfo
= 1,
199 #ifdef CONFIG_IPV6_ROUTER_PREF
200 .accept_ra_rtr_pref
= 1,
201 .rtr_probe_interval
= 60 * HZ
,
202 #ifdef CONFIG_IPV6_ROUTE_INFO
203 .accept_ra_rt_info_max_plen
= 0,
208 /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
210 const struct in6_addr in6addr_any
= IN6ADDR_ANY_INIT
;
212 const struct in6_addr in6addr_loopback
= IN6ADDR_LOOPBACK_INIT
;
214 #define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
216 static inline unsigned ipv6_addr_scope2type(unsigned scope
)
219 case IPV6_ADDR_SCOPE_NODELOCAL
:
220 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_NODELOCAL
) |
222 case IPV6_ADDR_SCOPE_LINKLOCAL
:
223 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
) |
224 IPV6_ADDR_LINKLOCAL
);
225 case IPV6_ADDR_SCOPE_SITELOCAL
:
226 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL
) |
227 IPV6_ADDR_SITELOCAL
);
229 return IPV6_ADDR_SCOPE_TYPE(scope
);
232 int __ipv6_addr_type(const struct in6_addr
*addr
)
236 st
= addr
->s6_addr32
[0];
238 /* Consider all addresses with the first three bits different of
239 000 and 111 as unicasts.
241 if ((st
& htonl(0xE0000000)) != htonl(0x00000000) &&
242 (st
& htonl(0xE0000000)) != htonl(0xE0000000))
243 return (IPV6_ADDR_UNICAST
|
244 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
));
246 if ((st
& htonl(0xFF000000)) == htonl(0xFF000000)) {
248 /* addr-select 3.1 */
249 return (IPV6_ADDR_MULTICAST
|
250 ipv6_addr_scope2type(IPV6_ADDR_MC_SCOPE(addr
)));
253 if ((st
& htonl(0xFFC00000)) == htonl(0xFE800000))
254 return (IPV6_ADDR_LINKLOCAL
| IPV6_ADDR_UNICAST
|
255 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
)); /* addr-select 3.1 */
256 if ((st
& htonl(0xFFC00000)) == htonl(0xFEC00000))
257 return (IPV6_ADDR_SITELOCAL
| IPV6_ADDR_UNICAST
|
258 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL
)); /* addr-select 3.1 */
260 if ((addr
->s6_addr32
[0] | addr
->s6_addr32
[1]) == 0) {
261 if (addr
->s6_addr32
[2] == 0) {
262 if (addr
->s6_addr32
[3] == 0)
263 return IPV6_ADDR_ANY
;
265 if (addr
->s6_addr32
[3] == htonl(0x00000001))
266 return (IPV6_ADDR_LOOPBACK
| IPV6_ADDR_UNICAST
|
267 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
)); /* addr-select 3.4 */
269 return (IPV6_ADDR_COMPATv4
| IPV6_ADDR_UNICAST
|
270 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.3 */
273 if (addr
->s6_addr32
[2] == htonl(0x0000ffff))
274 return (IPV6_ADDR_MAPPED
|
275 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.3 */
278 return (IPV6_ADDR_RESERVED
|
279 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.4 */
282 static void addrconf_del_timer(struct inet6_ifaddr
*ifp
)
284 if (del_timer(&ifp
->timer
))
288 enum addrconf_timer_t
295 static void addrconf_mod_timer(struct inet6_ifaddr
*ifp
,
296 enum addrconf_timer_t what
,
299 if (!del_timer(&ifp
->timer
))
304 ifp
->timer
.function
= addrconf_dad_timer
;
307 ifp
->timer
.function
= addrconf_rs_timer
;
311 ifp
->timer
.expires
= jiffies
+ when
;
312 add_timer(&ifp
->timer
);
315 /* Nobody refers to this device, we may destroy it. */
317 void in6_dev_finish_destroy(struct inet6_dev
*idev
)
319 struct net_device
*dev
= idev
->dev
;
320 BUG_TRAP(idev
->addr_list
==NULL
);
321 BUG_TRAP(idev
->mc_list
==NULL
);
322 #ifdef NET_REFCNT_DEBUG
323 printk(KERN_DEBUG
"in6_dev_finish_destroy: %s\n", dev
? dev
->name
: "NIL");
327 printk("Freeing alive inet6 device %p\n", idev
);
330 snmp6_free_dev(idev
);
334 static struct inet6_dev
* ipv6_add_dev(struct net_device
*dev
)
336 struct inet6_dev
*ndev
;
340 if (dev
->mtu
< IPV6_MIN_MTU
)
343 ndev
= kzalloc(sizeof(struct inet6_dev
), GFP_KERNEL
);
348 rwlock_init(&ndev
->lock
);
350 memcpy(&ndev
->cnf
, &ipv6_devconf_dflt
, sizeof(ndev
->cnf
));
351 ndev
->cnf
.mtu6
= dev
->mtu
;
352 ndev
->cnf
.sysctl
= NULL
;
353 ndev
->nd_parms
= neigh_parms_alloc(dev
, &nd_tbl
);
354 if (ndev
->nd_parms
== NULL
) {
358 /* We refer to the device */
361 if (snmp6_alloc_dev(ndev
) < 0) {
363 "%s(): cannot allocate memory for statistics; dev=%s.\n",
364 __FUNCTION__
, dev
->name
));
365 neigh_parms_release(&nd_tbl
, ndev
->nd_parms
);
367 in6_dev_finish_destroy(ndev
);
371 if (snmp6_register_dev(ndev
) < 0) {
373 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
374 __FUNCTION__
, dev
->name
));
375 neigh_parms_release(&nd_tbl
, ndev
->nd_parms
);
377 in6_dev_finish_destroy(ndev
);
381 /* One reference from device. We must do this before
382 * we invoke __ipv6_regen_rndid().
386 #ifdef CONFIG_IPV6_PRIVACY
387 init_timer(&ndev
->regen_timer
);
388 ndev
->regen_timer
.function
= ipv6_regen_rndid
;
389 ndev
->regen_timer
.data
= (unsigned long) ndev
;
390 if ((dev
->flags
&IFF_LOOPBACK
) ||
391 dev
->type
== ARPHRD_TUNNEL
||
392 dev
->type
== ARPHRD_NONE
||
393 dev
->type
== ARPHRD_SIT
) {
395 "%s: Disabled Privacy Extensions\n",
397 ndev
->cnf
.use_tempaddr
= -1;
400 ipv6_regen_rndid((unsigned long) ndev
);
404 if (netif_carrier_ok(dev
))
405 ndev
->if_flags
|= IF_READY
;
407 write_lock_bh(&addrconf_lock
);
409 write_unlock_bh(&addrconf_lock
);
411 ipv6_mc_init_dev(ndev
);
412 ndev
->tstamp
= jiffies
;
414 neigh_sysctl_register(dev
, ndev
->nd_parms
, NET_IPV6
,
415 NET_IPV6_NEIGH
, "ipv6",
416 &ndisc_ifinfo_sysctl_change
,
418 addrconf_sysctl_register(ndev
, &ndev
->cnf
);
423 static struct inet6_dev
* ipv6_find_idev(struct net_device
*dev
)
425 struct inet6_dev
*idev
;
429 if ((idev
= __in6_dev_get(dev
)) == NULL
) {
430 if ((idev
= ipv6_add_dev(dev
)) == NULL
)
434 if (dev
->flags
&IFF_UP
)
440 static void dev_forward_change(struct inet6_dev
*idev
)
442 struct net_device
*dev
;
443 struct inet6_ifaddr
*ifa
;
444 struct in6_addr addr
;
449 if (dev
&& (dev
->flags
& IFF_MULTICAST
)) {
450 ipv6_addr_all_routers(&addr
);
452 if (idev
->cnf
.forwarding
)
453 ipv6_dev_mc_inc(dev
, &addr
);
455 ipv6_dev_mc_dec(dev
, &addr
);
457 for (ifa
=idev
->addr_list
; ifa
; ifa
=ifa
->if_next
) {
458 if (idev
->cnf
.forwarding
)
459 addrconf_join_anycast(ifa
);
461 addrconf_leave_anycast(ifa
);
466 static void addrconf_forward_change(void)
468 struct net_device
*dev
;
469 struct inet6_dev
*idev
;
471 read_lock(&dev_base_lock
);
472 for (dev
=dev_base
; dev
; dev
=dev
->next
) {
473 read_lock(&addrconf_lock
);
474 idev
= __in6_dev_get(dev
);
476 int changed
= (!idev
->cnf
.forwarding
) ^ (!ipv6_devconf
.forwarding
);
477 idev
->cnf
.forwarding
= ipv6_devconf
.forwarding
;
479 dev_forward_change(idev
);
481 read_unlock(&addrconf_lock
);
483 read_unlock(&dev_base_lock
);
487 /* Nobody refers to this ifaddr, destroy it */
489 void inet6_ifa_finish_destroy(struct inet6_ifaddr
*ifp
)
491 BUG_TRAP(ifp
->if_next
==NULL
);
492 BUG_TRAP(ifp
->lst_next
==NULL
);
493 #ifdef NET_REFCNT_DEBUG
494 printk(KERN_DEBUG
"inet6_ifa_finish_destroy\n");
497 in6_dev_put(ifp
->idev
);
499 if (del_timer(&ifp
->timer
))
500 printk("Timer is still running, when freeing ifa=%p\n", ifp
);
503 printk("Freeing alive inet6 address %p\n", ifp
);
506 dst_release(&ifp
->rt
->u
.dst
);
512 ipv6_link_dev_addr(struct inet6_dev
*idev
, struct inet6_ifaddr
*ifp
)
514 struct inet6_ifaddr
*ifa
, **ifap
;
515 int ifp_scope
= ipv6_addr_src_scope(&ifp
->addr
);
518 * Each device address list is sorted in order of scope -
519 * global before linklocal.
521 for (ifap
= &idev
->addr_list
; (ifa
= *ifap
) != NULL
;
522 ifap
= &ifa
->if_next
) {
523 if (ifp_scope
>= ipv6_addr_src_scope(&ifa
->addr
))
527 ifp
->if_next
= *ifap
;
531 /* On success it returns ifp with increased reference count */
533 static struct inet6_ifaddr
*
534 ipv6_add_addr(struct inet6_dev
*idev
, const struct in6_addr
*addr
, int pfxlen
,
535 int scope
, u32 flags
)
537 struct inet6_ifaddr
*ifa
= NULL
;
542 read_lock_bh(&addrconf_lock
);
544 err
= -ENODEV
; /*XXX*/
548 write_lock(&addrconf_hash_lock
);
550 /* Ignore adding duplicate addresses on an interface */
551 if (ipv6_chk_same_addr(addr
, idev
->dev
)) {
552 ADBG(("ipv6_add_addr: already assigned\n"));
557 ifa
= kzalloc(sizeof(struct inet6_ifaddr
), GFP_ATOMIC
);
560 ADBG(("ipv6_add_addr: malloc failed\n"));
565 rt
= addrconf_dst_alloc(idev
, addr
, 0);
571 ipv6_addr_copy(&ifa
->addr
, addr
);
573 spin_lock_init(&ifa
->lock
);
574 init_timer(&ifa
->timer
);
575 ifa
->timer
.data
= (unsigned long) ifa
;
577 ifa
->prefix_len
= pfxlen
;
578 ifa
->flags
= flags
| IFA_F_TENTATIVE
;
579 ifa
->cstamp
= ifa
->tstamp
= jiffies
;
586 /* Add to big hash table */
587 hash
= ipv6_addr_hash(addr
);
589 ifa
->lst_next
= inet6_addr_lst
[hash
];
590 inet6_addr_lst
[hash
] = ifa
;
592 write_unlock(&addrconf_hash_lock
);
594 write_lock(&idev
->lock
);
595 /* Add to inet6_dev unicast addr list. */
596 ipv6_link_dev_addr(idev
, ifa
);
598 #ifdef CONFIG_IPV6_PRIVACY
599 if (ifa
->flags
&IFA_F_TEMPORARY
) {
600 ifa
->tmp_next
= idev
->tempaddr_list
;
601 idev
->tempaddr_list
= ifa
;
609 write_unlock(&idev
->lock
);
611 read_unlock_bh(&addrconf_lock
);
613 if (likely(err
== 0))
614 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_UP
, ifa
);
622 write_unlock(&addrconf_hash_lock
);
626 /* This function wants to get referenced ifp and releases it before return */
628 static void ipv6_del_addr(struct inet6_ifaddr
*ifp
)
630 struct inet6_ifaddr
*ifa
, **ifap
;
631 struct inet6_dev
*idev
= ifp
->idev
;
633 int deleted
= 0, onlink
= 0;
634 unsigned long expires
= jiffies
;
636 hash
= ipv6_addr_hash(&ifp
->addr
);
640 write_lock_bh(&addrconf_hash_lock
);
641 for (ifap
= &inet6_addr_lst
[hash
]; (ifa
=*ifap
) != NULL
;
642 ifap
= &ifa
->lst_next
) {
644 *ifap
= ifa
->lst_next
;
646 ifa
->lst_next
= NULL
;
650 write_unlock_bh(&addrconf_hash_lock
);
652 write_lock_bh(&idev
->lock
);
653 #ifdef CONFIG_IPV6_PRIVACY
654 if (ifp
->flags
&IFA_F_TEMPORARY
) {
655 for (ifap
= &idev
->tempaddr_list
; (ifa
=*ifap
) != NULL
;
656 ifap
= &ifa
->tmp_next
) {
658 *ifap
= ifa
->tmp_next
;
660 in6_ifa_put(ifp
->ifpub
);
664 ifa
->tmp_next
= NULL
;
671 for (ifap
= &idev
->addr_list
; (ifa
=*ifap
) != NULL
;) {
673 *ifap
= ifa
->if_next
;
676 if (!(ifp
->flags
& IFA_F_PERMANENT
) || onlink
> 0)
680 } else if (ifp
->flags
& IFA_F_PERMANENT
) {
681 if (ipv6_prefix_equal(&ifa
->addr
, &ifp
->addr
,
683 if (ifa
->flags
& IFA_F_PERMANENT
) {
688 unsigned long lifetime
;
693 spin_lock(&ifa
->lock
);
694 lifetime
= min_t(unsigned long,
695 ifa
->valid_lft
, 0x7fffffffUL
/HZ
);
696 if (time_before(expires
,
697 ifa
->tstamp
+ lifetime
* HZ
))
698 expires
= ifa
->tstamp
+ lifetime
* HZ
;
699 spin_unlock(&ifa
->lock
);
703 ifap
= &ifa
->if_next
;
705 write_unlock_bh(&idev
->lock
);
707 ipv6_ifa_notify(RTM_DELADDR
, ifp
);
709 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_DOWN
, ifp
);
711 addrconf_del_timer(ifp
);
714 * Purge or update corresponding prefix
716 * 1) we don't purge prefix here if address was not permanent.
717 * prefix is managed by its own lifetime.
718 * 2) if there're no addresses, delete prefix.
719 * 3) if there're still other permanent address(es),
720 * corresponding prefix is still permanent.
721 * 4) otherwise, update prefix lifetime to the
722 * longest valid lifetime among the corresponding
723 * addresses on the device.
724 * Note: subsequent RA will update lifetime.
728 if ((ifp
->flags
& IFA_F_PERMANENT
) && onlink
< 1) {
729 struct in6_addr prefix
;
732 ipv6_addr_prefix(&prefix
, &ifp
->addr
, ifp
->prefix_len
);
733 rt
= rt6_lookup(&prefix
, NULL
, ifp
->idev
->dev
->ifindex
, 1);
735 if (rt
&& ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0)) {
737 ip6_del_rt(rt
, NULL
, NULL
, NULL
);
739 } else if (!(rt
->rt6i_flags
& RTF_EXPIRES
)) {
740 rt
->rt6i_expires
= expires
;
741 rt
->rt6i_flags
|= RTF_EXPIRES
;
744 dst_release(&rt
->u
.dst
);
750 #ifdef CONFIG_IPV6_PRIVACY
751 static int ipv6_create_tempaddr(struct inet6_ifaddr
*ifp
, struct inet6_ifaddr
*ift
)
753 struct inet6_dev
*idev
= ifp
->idev
;
754 struct in6_addr addr
, *tmpaddr
;
755 unsigned long tmp_prefered_lft
, tmp_valid_lft
, tmp_cstamp
, tmp_tstamp
;
760 write_lock(&idev
->lock
);
762 spin_lock_bh(&ift
->lock
);
763 memcpy(&addr
.s6_addr
[8], &ift
->addr
.s6_addr
[8], 8);
764 spin_unlock_bh(&ift
->lock
);
771 if (idev
->cnf
.use_tempaddr
<= 0) {
772 write_unlock(&idev
->lock
);
774 "ipv6_create_tempaddr(): use_tempaddr is disabled.\n");
779 spin_lock_bh(&ifp
->lock
);
780 if (ifp
->regen_count
++ >= idev
->cnf
.regen_max_retry
) {
781 idev
->cnf
.use_tempaddr
= -1; /*XXX*/
782 spin_unlock_bh(&ifp
->lock
);
783 write_unlock(&idev
->lock
);
785 "ipv6_create_tempaddr(): regeneration time exceeded. disabled temporary address support.\n");
791 memcpy(addr
.s6_addr
, ifp
->addr
.s6_addr
, 8);
792 if (__ipv6_try_regen_rndid(idev
, tmpaddr
) < 0) {
793 spin_unlock_bh(&ifp
->lock
);
794 write_unlock(&idev
->lock
);
796 "ipv6_create_tempaddr(): regeneration of randomized interface id failed.\n");
802 memcpy(&addr
.s6_addr
[8], idev
->rndid
, 8);
803 tmp_valid_lft
= min_t(__u32
,
805 idev
->cnf
.temp_valid_lft
);
806 tmp_prefered_lft
= min_t(__u32
,
808 idev
->cnf
.temp_prefered_lft
- desync_factor
/ HZ
);
809 tmp_plen
= ifp
->prefix_len
;
810 max_addresses
= idev
->cnf
.max_addresses
;
811 tmp_cstamp
= ifp
->cstamp
;
812 tmp_tstamp
= ifp
->tstamp
;
813 spin_unlock_bh(&ifp
->lock
);
815 write_unlock(&idev
->lock
);
816 ift
= !max_addresses
||
817 ipv6_count_addresses(idev
) < max_addresses
?
818 ipv6_add_addr(idev
, &addr
, tmp_plen
,
819 ipv6_addr_type(&addr
)&IPV6_ADDR_SCOPE_MASK
, IFA_F_TEMPORARY
) : NULL
;
820 if (!ift
|| IS_ERR(ift
)) {
824 "ipv6_create_tempaddr(): retry temporary address regeneration.\n");
826 write_lock(&idev
->lock
);
830 spin_lock_bh(&ift
->lock
);
832 ift
->valid_lft
= tmp_valid_lft
;
833 ift
->prefered_lft
= tmp_prefered_lft
;
834 ift
->cstamp
= tmp_cstamp
;
835 ift
->tstamp
= tmp_tstamp
;
836 spin_unlock_bh(&ift
->lock
);
838 addrconf_dad_start(ift
, 0);
847 * Choose an appropriate source address (RFC3484)
849 struct ipv6_saddr_score
{
857 #define IPV6_SADDR_SCORE_LOCAL 0x0001
858 #define IPV6_SADDR_SCORE_PREFERRED 0x0004
859 #define IPV6_SADDR_SCORE_HOA 0x0008
860 #define IPV6_SADDR_SCORE_OIF 0x0010
861 #define IPV6_SADDR_SCORE_LABEL 0x0020
862 #define IPV6_SADDR_SCORE_PRIVACY 0x0040
864 static int inline ipv6_saddr_preferred(int type
)
866 if (type
& (IPV6_ADDR_MAPPED
|IPV6_ADDR_COMPATv4
|
867 IPV6_ADDR_LOOPBACK
|IPV6_ADDR_RESERVED
))
872 /* static matching label */
873 static int inline ipv6_saddr_label(const struct in6_addr
*addr
, int type
)
876 * prefix (longest match) label
877 * -----------------------------
886 if (type
& IPV6_ADDR_LOOPBACK
)
888 else if (type
& IPV6_ADDR_COMPATv4
)
890 else if (type
& IPV6_ADDR_MAPPED
)
892 else if (addr
->s6_addr32
[0] == htonl(0x20010000))
894 else if (addr
->s6_addr16
[0] == htons(0x2002))
896 else if ((addr
->s6_addr
[0] & 0xfe) == 0xfc)
901 int ipv6_dev_get_saddr(struct net_device
*daddr_dev
,
902 struct in6_addr
*daddr
, struct in6_addr
*saddr
)
904 struct ipv6_saddr_score hiscore
;
905 struct inet6_ifaddr
*ifa_result
= NULL
;
906 int daddr_type
= __ipv6_addr_type(daddr
);
907 int daddr_scope
= __ipv6_addr_src_scope(daddr_type
);
908 u32 daddr_label
= ipv6_saddr_label(daddr
, daddr_type
);
909 struct net_device
*dev
;
911 memset(&hiscore
, 0, sizeof(hiscore
));
913 read_lock(&dev_base_lock
);
914 read_lock(&addrconf_lock
);
916 for (dev
= dev_base
; dev
; dev
=dev
->next
) {
917 struct inet6_dev
*idev
;
918 struct inet6_ifaddr
*ifa
;
920 /* Rule 0: Candidate Source Address (section 4)
921 * - multicast and link-local destination address,
922 * the set of candidate source address MUST only
923 * include addresses assigned to interfaces
924 * belonging to the same link as the outgoing
926 * (- For site-local destination addresses, the
927 * set of candidate source addresses MUST only
928 * include addresses assigned to interfaces
929 * belonging to the same site as the outgoing
932 if ((daddr_type
& IPV6_ADDR_MULTICAST
||
933 daddr_scope
<= IPV6_ADDR_SCOPE_LINKLOCAL
) &&
934 daddr_dev
&& dev
!= daddr_dev
)
937 idev
= __in6_dev_get(dev
);
941 read_lock_bh(&idev
->lock
);
942 for (ifa
= idev
->addr_list
; ifa
; ifa
= ifa
->if_next
) {
943 struct ipv6_saddr_score score
;
945 score
.addr_type
= __ipv6_addr_type(&ifa
->addr
);
948 * - Tentative Address (RFC2462 section 5.4)
949 * - A tentative address is not considered
950 * "assigned to an interface" in the traditional
952 * - Candidate Source Address (section 4)
953 * - In any case, anycast addresses, multicast
954 * addresses, and the unspecified address MUST
955 * NOT be included in a candidate set.
957 if (ifa
->flags
& IFA_F_TENTATIVE
)
959 if (unlikely(score
.addr_type
== IPV6_ADDR_ANY
||
960 score
.addr_type
& IPV6_ADDR_MULTICAST
)) {
961 LIMIT_NETDEBUG(KERN_DEBUG
962 "ADDRCONF: unspecified / multicast address"
963 "assigned as unicast address on %s",
973 if (ifa_result
== NULL
) {
974 /* record it if the first available entry */
978 /* Rule 1: Prefer same address */
979 if (hiscore
.rule
< 1) {
980 if (ipv6_addr_equal(&ifa_result
->addr
, daddr
))
981 hiscore
.attrs
|= IPV6_SADDR_SCORE_LOCAL
;
984 if (ipv6_addr_equal(&ifa
->addr
, daddr
)) {
985 score
.attrs
|= IPV6_SADDR_SCORE_LOCAL
;
986 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_LOCAL
)) {
991 if (hiscore
.attrs
& IPV6_SADDR_SCORE_LOCAL
)
995 /* Rule 2: Prefer appropriate scope */
996 if (hiscore
.rule
< 2) {
997 hiscore
.scope
= __ipv6_addr_src_scope(hiscore
.addr_type
);
1000 score
.scope
= __ipv6_addr_src_scope(score
.addr_type
);
1001 if (hiscore
.scope
< score
.scope
) {
1002 if (hiscore
.scope
< daddr_scope
) {
1007 } else if (score
.scope
< hiscore
.scope
) {
1008 if (score
.scope
< daddr_scope
)
1009 break; /* addresses sorted by scope */
1016 /* Rule 3: Avoid deprecated address */
1017 if (hiscore
.rule
< 3) {
1018 if (ipv6_saddr_preferred(hiscore
.addr_type
) ||
1019 !(ifa_result
->flags
& IFA_F_DEPRECATED
))
1020 hiscore
.attrs
|= IPV6_SADDR_SCORE_PREFERRED
;
1023 if (ipv6_saddr_preferred(score
.addr_type
) ||
1024 !(ifa
->flags
& IFA_F_DEPRECATED
)) {
1025 score
.attrs
|= IPV6_SADDR_SCORE_PREFERRED
;
1026 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_PREFERRED
)) {
1031 if (hiscore
.attrs
& IPV6_SADDR_SCORE_PREFERRED
)
1035 /* Rule 4: Prefer home address -- not implemented yet */
1036 if (hiscore
.rule
< 4)
1039 /* Rule 5: Prefer outgoing interface */
1040 if (hiscore
.rule
< 5) {
1041 if (daddr_dev
== NULL
||
1042 daddr_dev
== ifa_result
->idev
->dev
)
1043 hiscore
.attrs
|= IPV6_SADDR_SCORE_OIF
;
1046 if (daddr_dev
== NULL
||
1047 daddr_dev
== ifa
->idev
->dev
) {
1048 score
.attrs
|= IPV6_SADDR_SCORE_OIF
;
1049 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_OIF
)) {
1054 if (hiscore
.attrs
& IPV6_SADDR_SCORE_OIF
)
1058 /* Rule 6: Prefer matching label */
1059 if (hiscore
.rule
< 6) {
1060 if (ipv6_saddr_label(&ifa_result
->addr
, hiscore
.addr_type
) == daddr_label
)
1061 hiscore
.attrs
|= IPV6_SADDR_SCORE_LABEL
;
1064 if (ipv6_saddr_label(&ifa
->addr
, score
.addr_type
) == daddr_label
) {
1065 score
.attrs
|= IPV6_SADDR_SCORE_LABEL
;
1066 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_LABEL
)) {
1071 if (hiscore
.attrs
& IPV6_SADDR_SCORE_LABEL
)
1075 #ifdef CONFIG_IPV6_PRIVACY
1076 /* Rule 7: Prefer public address
1077 * Note: prefer temprary address if use_tempaddr >= 2
1079 if (hiscore
.rule
< 7) {
1080 if ((!(ifa_result
->flags
& IFA_F_TEMPORARY
)) ^
1081 (ifa_result
->idev
->cnf
.use_tempaddr
>= 2))
1082 hiscore
.attrs
|= IPV6_SADDR_SCORE_PRIVACY
;
1085 if ((!(ifa
->flags
& IFA_F_TEMPORARY
)) ^
1086 (ifa
->idev
->cnf
.use_tempaddr
>= 2)) {
1087 score
.attrs
|= IPV6_SADDR_SCORE_PRIVACY
;
1088 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_PRIVACY
)) {
1093 if (hiscore
.attrs
& IPV6_SADDR_SCORE_PRIVACY
)
1097 if (hiscore
.rule
< 7)
1100 /* Rule 8: Use longest matching prefix */
1101 if (hiscore
.rule
< 8) {
1102 hiscore
.matchlen
= ipv6_addr_diff(&ifa_result
->addr
, daddr
);
1105 score
.matchlen
= ipv6_addr_diff(&ifa
->addr
, daddr
);
1106 if (score
.matchlen
> hiscore
.matchlen
) {
1111 else if (score
.matchlen
< hiscore
.matchlen
)
1115 /* Final Rule: choose first available one */
1119 in6_ifa_put(ifa_result
);
1124 read_unlock_bh(&idev
->lock
);
1126 read_unlock(&addrconf_lock
);
1127 read_unlock(&dev_base_lock
);
1130 return -EADDRNOTAVAIL
;
1132 ipv6_addr_copy(saddr
, &ifa_result
->addr
);
1133 in6_ifa_put(ifa_result
);
1138 int ipv6_get_saddr(struct dst_entry
*dst
,
1139 struct in6_addr
*daddr
, struct in6_addr
*saddr
)
1141 return ipv6_dev_get_saddr(dst
? ((struct rt6_info
*)dst
)->rt6i_idev
->dev
: NULL
, daddr
, saddr
);
1145 int ipv6_get_lladdr(struct net_device
*dev
, struct in6_addr
*addr
)
1147 struct inet6_dev
*idev
;
1148 int err
= -EADDRNOTAVAIL
;
1150 read_lock(&addrconf_lock
);
1151 if ((idev
= __in6_dev_get(dev
)) != NULL
) {
1152 struct inet6_ifaddr
*ifp
;
1154 read_lock_bh(&idev
->lock
);
1155 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1156 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1157 ipv6_addr_copy(addr
, &ifp
->addr
);
1162 read_unlock_bh(&idev
->lock
);
1164 read_unlock(&addrconf_lock
);
1168 static int ipv6_count_addresses(struct inet6_dev
*idev
)
1171 struct inet6_ifaddr
*ifp
;
1173 read_lock_bh(&idev
->lock
);
1174 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
)
1176 read_unlock_bh(&idev
->lock
);
1180 int ipv6_chk_addr(struct in6_addr
*addr
, struct net_device
*dev
, int strict
)
1182 struct inet6_ifaddr
* ifp
;
1183 u8 hash
= ipv6_addr_hash(addr
);
1185 read_lock_bh(&addrconf_hash_lock
);
1186 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1187 if (ipv6_addr_equal(&ifp
->addr
, addr
) &&
1188 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1189 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1190 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
))
1194 read_unlock_bh(&addrconf_hash_lock
);
1199 int ipv6_chk_same_addr(const struct in6_addr
*addr
, struct net_device
*dev
)
1201 struct inet6_ifaddr
* ifp
;
1202 u8 hash
= ipv6_addr_hash(addr
);
1204 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1205 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1206 if (dev
== NULL
|| ifp
->idev
->dev
== dev
)
1213 struct inet6_ifaddr
* ipv6_get_ifaddr(struct in6_addr
*addr
, struct net_device
*dev
, int strict
)
1215 struct inet6_ifaddr
* ifp
;
1216 u8 hash
= ipv6_addr_hash(addr
);
1218 read_lock_bh(&addrconf_hash_lock
);
1219 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1220 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1221 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1222 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
)) {
1228 read_unlock_bh(&addrconf_hash_lock
);
1233 int ipv6_rcv_saddr_equal(const struct sock
*sk
, const struct sock
*sk2
)
1235 const struct in6_addr
*sk_rcv_saddr6
= &inet6_sk(sk
)->rcv_saddr
;
1236 const struct in6_addr
*sk2_rcv_saddr6
= inet6_rcv_saddr(sk2
);
1237 u32 sk_rcv_saddr
= inet_sk(sk
)->rcv_saddr
;
1238 u32 sk2_rcv_saddr
= inet_rcv_saddr(sk2
);
1239 int sk_ipv6only
= ipv6_only_sock(sk
);
1240 int sk2_ipv6only
= inet_v6_ipv6only(sk2
);
1241 int addr_type
= ipv6_addr_type(sk_rcv_saddr6
);
1242 int addr_type2
= sk2_rcv_saddr6
? ipv6_addr_type(sk2_rcv_saddr6
) : IPV6_ADDR_MAPPED
;
1244 if (!sk2_rcv_saddr
&& !sk_ipv6only
)
1247 if (addr_type2
== IPV6_ADDR_ANY
&&
1248 !(sk2_ipv6only
&& addr_type
== IPV6_ADDR_MAPPED
))
1251 if (addr_type
== IPV6_ADDR_ANY
&&
1252 !(sk_ipv6only
&& addr_type2
== IPV6_ADDR_MAPPED
))
1255 if (sk2_rcv_saddr6
&&
1256 ipv6_addr_equal(sk_rcv_saddr6
, sk2_rcv_saddr6
))
1259 if (addr_type
== IPV6_ADDR_MAPPED
&&
1261 (!sk2_rcv_saddr
|| !sk_rcv_saddr
|| sk_rcv_saddr
== sk2_rcv_saddr
))
1267 /* Gets referenced address, destroys ifaddr */
1269 static void addrconf_dad_stop(struct inet6_ifaddr
*ifp
)
1271 if (ifp
->flags
&IFA_F_PERMANENT
) {
1272 spin_lock_bh(&ifp
->lock
);
1273 addrconf_del_timer(ifp
);
1274 ifp
->flags
|= IFA_F_TENTATIVE
;
1275 spin_unlock_bh(&ifp
->lock
);
1277 #ifdef CONFIG_IPV6_PRIVACY
1278 } else if (ifp
->flags
&IFA_F_TEMPORARY
) {
1279 struct inet6_ifaddr
*ifpub
;
1280 spin_lock_bh(&ifp
->lock
);
1283 in6_ifa_hold(ifpub
);
1284 spin_unlock_bh(&ifp
->lock
);
1285 ipv6_create_tempaddr(ifpub
, ifp
);
1288 spin_unlock_bh(&ifp
->lock
);
1296 void addrconf_dad_failure(struct inet6_ifaddr
*ifp
)
1298 if (net_ratelimit())
1299 printk(KERN_INFO
"%s: duplicate address detected!\n", ifp
->idev
->dev
->name
);
1300 addrconf_dad_stop(ifp
);
1303 /* Join to solicited addr multicast group. */
1305 void addrconf_join_solict(struct net_device
*dev
, struct in6_addr
*addr
)
1307 struct in6_addr maddr
;
1309 if (dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1312 addrconf_addr_solict_mult(addr
, &maddr
);
1313 ipv6_dev_mc_inc(dev
, &maddr
);
1316 void addrconf_leave_solict(struct inet6_dev
*idev
, struct in6_addr
*addr
)
1318 struct in6_addr maddr
;
1320 if (idev
->dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1323 addrconf_addr_solict_mult(addr
, &maddr
);
1324 __ipv6_dev_mc_dec(idev
, &maddr
);
1327 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
)
1329 struct in6_addr addr
;
1330 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1331 if (ipv6_addr_any(&addr
))
1333 ipv6_dev_ac_inc(ifp
->idev
->dev
, &addr
);
1336 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
)
1338 struct in6_addr addr
;
1339 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1340 if (ipv6_addr_any(&addr
))
1342 __ipv6_dev_ac_dec(ifp
->idev
, &addr
);
1345 static int addrconf_ifid_eui48(u8
*eui
, struct net_device
*dev
)
1347 if (dev
->addr_len
!= ETH_ALEN
)
1349 memcpy(eui
, dev
->dev_addr
, 3);
1350 memcpy(eui
+ 5, dev
->dev_addr
+ 3, 3);
1353 * The zSeries OSA network cards can be shared among various
1354 * OS instances, but the OSA cards have only one MAC address.
1355 * This leads to duplicate address conflicts in conjunction
1356 * with IPv6 if more than one instance uses the same card.
1358 * The driver for these cards can deliver a unique 16-bit
1359 * identifier for each instance sharing the same card. It is
1360 * placed instead of 0xFFFE in the interface identifier. The
1361 * "u" bit of the interface identifier is not inverted in this
1362 * case. Hence the resulting interface identifier has local
1363 * scope according to RFC2373.
1366 eui
[3] = (dev
->dev_id
>> 8) & 0xFF;
1367 eui
[4] = dev
->dev_id
& 0xFF;
1376 static int addrconf_ifid_arcnet(u8
*eui
, struct net_device
*dev
)
1378 /* XXX: inherit EUI-64 from other interface -- yoshfuji */
1379 if (dev
->addr_len
!= ARCNET_ALEN
)
1382 eui
[7] = *(u8
*)dev
->dev_addr
;
1386 static int addrconf_ifid_infiniband(u8
*eui
, struct net_device
*dev
)
1388 if (dev
->addr_len
!= INFINIBAND_ALEN
)
1390 memcpy(eui
, dev
->dev_addr
+ 12, 8);
1395 static int ipv6_generate_eui64(u8
*eui
, struct net_device
*dev
)
1397 switch (dev
->type
) {
1400 case ARPHRD_IEEE802_TR
:
1401 return addrconf_ifid_eui48(eui
, dev
);
1403 return addrconf_ifid_arcnet(eui
, dev
);
1404 case ARPHRD_INFINIBAND
:
1405 return addrconf_ifid_infiniband(eui
, dev
);
1410 static int ipv6_inherit_eui64(u8
*eui
, struct inet6_dev
*idev
)
1413 struct inet6_ifaddr
*ifp
;
1415 read_lock_bh(&idev
->lock
);
1416 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1417 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1418 memcpy(eui
, ifp
->addr
.s6_addr
+8, 8);
1423 read_unlock_bh(&idev
->lock
);
1427 #ifdef CONFIG_IPV6_PRIVACY
1428 /* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */
1429 static int __ipv6_regen_rndid(struct inet6_dev
*idev
)
1432 get_random_bytes(idev
->rndid
, sizeof(idev
->rndid
));
1433 idev
->rndid
[0] &= ~0x02;
1436 * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>:
1437 * check if generated address is not inappropriate
1439 * - Reserved subnet anycast (RFC 2526)
1440 * 11111101 11....11 1xxxxxxx
1441 * - ISATAP (draft-ietf-ngtrans-isatap-13.txt) 5.1
1442 * 00-00-5E-FE-xx-xx-xx-xx
1444 * - XXX: already assigned to an address on the device
1446 if (idev
->rndid
[0] == 0xfd &&
1447 (idev
->rndid
[1]&idev
->rndid
[2]&idev
->rndid
[3]&idev
->rndid
[4]&idev
->rndid
[5]&idev
->rndid
[6]) == 0xff &&
1448 (idev
->rndid
[7]&0x80))
1450 if ((idev
->rndid
[0]|idev
->rndid
[1]) == 0) {
1451 if (idev
->rndid
[2] == 0x5e && idev
->rndid
[3] == 0xfe)
1453 if ((idev
->rndid
[2]|idev
->rndid
[3]|idev
->rndid
[4]|idev
->rndid
[5]|idev
->rndid
[6]|idev
->rndid
[7]) == 0x00)
1460 static void ipv6_regen_rndid(unsigned long data
)
1462 struct inet6_dev
*idev
= (struct inet6_dev
*) data
;
1463 unsigned long expires
;
1465 read_lock_bh(&addrconf_lock
);
1466 write_lock_bh(&idev
->lock
);
1471 if (__ipv6_regen_rndid(idev
) < 0)
1475 idev
->cnf
.temp_prefered_lft
* HZ
-
1476 idev
->cnf
.regen_max_retry
* idev
->cnf
.dad_transmits
* idev
->nd_parms
->retrans_time
- desync_factor
;
1477 if (time_before(expires
, jiffies
)) {
1479 "ipv6_regen_rndid(): too short regeneration interval; timer disabled for %s.\n",
1484 if (!mod_timer(&idev
->regen_timer
, expires
))
1488 write_unlock_bh(&idev
->lock
);
1489 read_unlock_bh(&addrconf_lock
);
1493 static int __ipv6_try_regen_rndid(struct inet6_dev
*idev
, struct in6_addr
*tmpaddr
) {
1496 if (tmpaddr
&& memcmp(idev
->rndid
, &tmpaddr
->s6_addr
[8], 8) == 0)
1497 ret
= __ipv6_regen_rndid(idev
);
1507 addrconf_prefix_route(struct in6_addr
*pfx
, int plen
, struct net_device
*dev
,
1508 unsigned long expires
, u32 flags
)
1510 struct in6_rtmsg rtmsg
;
1512 memset(&rtmsg
, 0, sizeof(rtmsg
));
1513 ipv6_addr_copy(&rtmsg
.rtmsg_dst
, pfx
);
1514 rtmsg
.rtmsg_dst_len
= plen
;
1515 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1516 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1517 rtmsg
.rtmsg_info
= expires
;
1518 rtmsg
.rtmsg_flags
= RTF_UP
|flags
;
1519 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1521 /* Prevent useless cloning on PtP SIT.
1522 This thing is done here expecting that the whole
1523 class of non-broadcast devices need not cloning.
1525 if (dev
->type
== ARPHRD_SIT
&& (dev
->flags
&IFF_POINTOPOINT
))
1526 rtmsg
.rtmsg_flags
|= RTF_NONEXTHOP
;
1528 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
);
1531 /* Create "default" multicast route to the interface */
1533 static void addrconf_add_mroute(struct net_device
*dev
)
1535 struct in6_rtmsg rtmsg
;
1537 memset(&rtmsg
, 0, sizeof(rtmsg
));
1538 ipv6_addr_set(&rtmsg
.rtmsg_dst
,
1539 htonl(0xFF000000), 0, 0, 0);
1540 rtmsg
.rtmsg_dst_len
= 8;
1541 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1542 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1543 rtmsg
.rtmsg_flags
= RTF_UP
;
1544 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1545 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
);
1548 static void sit_route_add(struct net_device
*dev
)
1550 struct in6_rtmsg rtmsg
;
1552 memset(&rtmsg
, 0, sizeof(rtmsg
));
1554 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1555 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1557 /* prefix length - 96 bits "::d.d.d.d" */
1558 rtmsg
.rtmsg_dst_len
= 96;
1559 rtmsg
.rtmsg_flags
= RTF_UP
|RTF_NONEXTHOP
;
1560 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1562 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
);
1565 static void addrconf_add_lroute(struct net_device
*dev
)
1567 struct in6_addr addr
;
1569 ipv6_addr_set(&addr
, htonl(0xFE800000), 0, 0, 0);
1570 addrconf_prefix_route(&addr
, 64, dev
, 0, 0);
1573 static struct inet6_dev
*addrconf_add_dev(struct net_device
*dev
)
1575 struct inet6_dev
*idev
;
1579 if ((idev
= ipv6_find_idev(dev
)) == NULL
)
1582 /* Add default multicast route */
1583 addrconf_add_mroute(dev
);
1585 /* Add link local route */
1586 addrconf_add_lroute(dev
);
1590 void addrconf_prefix_rcv(struct net_device
*dev
, u8
*opt
, int len
)
1592 struct prefix_info
*pinfo
;
1596 unsigned long rt_expires
;
1597 struct inet6_dev
*in6_dev
;
1599 pinfo
= (struct prefix_info
*) opt
;
1601 if (len
< sizeof(struct prefix_info
)) {
1602 ADBG(("addrconf: prefix option too short\n"));
1607 * Validation checks ([ADDRCONF], page 19)
1610 addr_type
= ipv6_addr_type(&pinfo
->prefix
);
1612 if (addr_type
& (IPV6_ADDR_MULTICAST
|IPV6_ADDR_LINKLOCAL
))
1615 valid_lft
= ntohl(pinfo
->valid
);
1616 prefered_lft
= ntohl(pinfo
->prefered
);
1618 if (prefered_lft
> valid_lft
) {
1619 if (net_ratelimit())
1620 printk(KERN_WARNING
"addrconf: prefix option has invalid lifetime\n");
1624 in6_dev
= in6_dev_get(dev
);
1626 if (in6_dev
== NULL
) {
1627 if (net_ratelimit())
1628 printk(KERN_DEBUG
"addrconf: device %s not configured\n", dev
->name
);
1633 * Two things going on here:
1634 * 1) Add routes for on-link prefixes
1635 * 2) Configure prefixes with the auto flag set
1638 /* Avoid arithmetic overflow. Really, we could
1639 save rt_expires in seconds, likely valid_lft,
1640 but it would require division in fib gc, that it
1643 if (valid_lft
>= 0x7FFFFFFF/HZ
)
1644 rt_expires
= 0x7FFFFFFF - (0x7FFFFFFF % HZ
);
1646 rt_expires
= valid_lft
* HZ
;
1649 * We convert this (in jiffies) to clock_t later.
1650 * Avoid arithmetic overflow there as well.
1651 * Overflow can happen only if HZ < USER_HZ.
1653 if (HZ
< USER_HZ
&& rt_expires
> 0x7FFFFFFF / USER_HZ
)
1654 rt_expires
= 0x7FFFFFFF / USER_HZ
;
1656 if (pinfo
->onlink
) {
1657 struct rt6_info
*rt
;
1658 rt
= rt6_lookup(&pinfo
->prefix
, NULL
, dev
->ifindex
, 1);
1660 if (rt
&& ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0)) {
1661 if (rt
->rt6i_flags
&RTF_EXPIRES
) {
1662 if (valid_lft
== 0) {
1663 ip6_del_rt(rt
, NULL
, NULL
, NULL
);
1666 rt
->rt6i_expires
= jiffies
+ rt_expires
;
1669 } else if (valid_lft
) {
1670 addrconf_prefix_route(&pinfo
->prefix
, pinfo
->prefix_len
,
1671 dev
, jiffies_to_clock_t(rt_expires
), RTF_ADDRCONF
|RTF_EXPIRES
|RTF_PREFIX_RT
);
1674 dst_release(&rt
->u
.dst
);
1677 /* Try to figure out our local address for this prefix */
1679 if (pinfo
->autoconf
&& in6_dev
->cnf
.autoconf
) {
1680 struct inet6_ifaddr
* ifp
;
1681 struct in6_addr addr
;
1682 int create
= 0, update_lft
= 0;
1684 if (pinfo
->prefix_len
== 64) {
1685 memcpy(&addr
, &pinfo
->prefix
, 8);
1686 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) &&
1687 ipv6_inherit_eui64(addr
.s6_addr
+ 8, in6_dev
)) {
1688 in6_dev_put(in6_dev
);
1693 if (net_ratelimit())
1694 printk(KERN_DEBUG
"IPv6 addrconf: prefix with wrong length %d\n",
1696 in6_dev_put(in6_dev
);
1701 ifp
= ipv6_get_ifaddr(&addr
, dev
, 1);
1703 if (ifp
== NULL
&& valid_lft
) {
1704 int max_addresses
= in6_dev
->cnf
.max_addresses
;
1706 /* Do not allow to create too much of autoconfigured
1707 * addresses; this would be too easy way to crash kernel.
1709 if (!max_addresses
||
1710 ipv6_count_addresses(in6_dev
) < max_addresses
)
1711 ifp
= ipv6_add_addr(in6_dev
, &addr
, pinfo
->prefix_len
,
1712 addr_type
&IPV6_ADDR_SCOPE_MASK
, 0);
1714 if (!ifp
|| IS_ERR(ifp
)) {
1715 in6_dev_put(in6_dev
);
1719 update_lft
= create
= 1;
1720 ifp
->cstamp
= jiffies
;
1721 addrconf_dad_start(ifp
, RTF_ADDRCONF
|RTF_PREFIX_RT
);
1727 #ifdef CONFIG_IPV6_PRIVACY
1728 struct inet6_ifaddr
*ift
;
1732 /* update lifetime (RFC2462 5.5.3 e) */
1733 spin_lock(&ifp
->lock
);
1735 if (ifp
->valid_lft
> (now
- ifp
->tstamp
) / HZ
)
1736 stored_lft
= ifp
->valid_lft
- (now
- ifp
->tstamp
) / HZ
;
1739 if (!update_lft
&& stored_lft
) {
1740 if (valid_lft
> MIN_VALID_LIFETIME
||
1741 valid_lft
> stored_lft
)
1743 else if (stored_lft
<= MIN_VALID_LIFETIME
) {
1744 /* valid_lft <= stored_lft is always true */
1748 valid_lft
= MIN_VALID_LIFETIME
;
1749 if (valid_lft
< prefered_lft
)
1750 prefered_lft
= valid_lft
;
1756 ifp
->valid_lft
= valid_lft
;
1757 ifp
->prefered_lft
= prefered_lft
;
1760 ifp
->flags
&= ~IFA_F_DEPRECATED
;
1761 spin_unlock(&ifp
->lock
);
1763 if (!(flags
&IFA_F_TENTATIVE
))
1764 ipv6_ifa_notify(0, ifp
);
1766 spin_unlock(&ifp
->lock
);
1768 #ifdef CONFIG_IPV6_PRIVACY
1769 read_lock_bh(&in6_dev
->lock
);
1770 /* update all temporary addresses in the list */
1771 for (ift
=in6_dev
->tempaddr_list
; ift
; ift
=ift
->tmp_next
) {
1773 * When adjusting the lifetimes of an existing
1774 * temporary address, only lower the lifetimes.
1775 * Implementations must not increase the
1776 * lifetimes of an existing temporary address
1777 * when processing a Prefix Information Option.
1779 spin_lock(&ift
->lock
);
1781 if (ift
->valid_lft
> valid_lft
&&
1782 ift
->valid_lft
- valid_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1783 ift
->valid_lft
= valid_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1784 if (ift
->prefered_lft
> prefered_lft
&&
1785 ift
->prefered_lft
- prefered_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1786 ift
->prefered_lft
= prefered_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1787 spin_unlock(&ift
->lock
);
1788 if (!(flags
&IFA_F_TENTATIVE
))
1789 ipv6_ifa_notify(0, ift
);
1792 if (create
&& in6_dev
->cnf
.use_tempaddr
> 0) {
1794 * When a new public address is created as described in [ADDRCONF],
1795 * also create a new temporary address.
1797 read_unlock_bh(&in6_dev
->lock
);
1798 ipv6_create_tempaddr(ifp
, NULL
);
1800 read_unlock_bh(&in6_dev
->lock
);
1807 inet6_prefix_notify(RTM_NEWPREFIX
, in6_dev
, pinfo
);
1808 in6_dev_put(in6_dev
);
1812 * Set destination address.
1813 * Special case for SIT interfaces where we create a new "virtual"
1816 int addrconf_set_dstaddr(void __user
*arg
)
1818 struct in6_ifreq ireq
;
1819 struct net_device
*dev
;
1825 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1828 dev
= __dev_get_by_index(ireq
.ifr6_ifindex
);
1834 if (dev
->type
== ARPHRD_SIT
) {
1837 struct ip_tunnel_parm p
;
1839 err
= -EADDRNOTAVAIL
;
1840 if (!(ipv6_addr_type(&ireq
.ifr6_addr
) & IPV6_ADDR_COMPATv4
))
1843 memset(&p
, 0, sizeof(p
));
1844 p
.iph
.daddr
= ireq
.ifr6_addr
.s6_addr32
[3];
1848 p
.iph
.protocol
= IPPROTO_IPV6
;
1850 ifr
.ifr_ifru
.ifru_data
= (void __user
*)&p
;
1852 oldfs
= get_fs(); set_fs(KERNEL_DS
);
1853 err
= dev
->do_ioctl(dev
, &ifr
, SIOCADDTUNNEL
);
1858 if ((dev
= __dev_get_by_name(p
.name
)) == NULL
)
1860 err
= dev_open(dev
);
1870 * Manual configuration of address on an interface
1872 static int inet6_addr_add(int ifindex
, struct in6_addr
*pfx
, int plen
)
1874 struct inet6_ifaddr
*ifp
;
1875 struct inet6_dev
*idev
;
1876 struct net_device
*dev
;
1881 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
1884 if (!(dev
->flags
&IFF_UP
))
1887 if ((idev
= addrconf_add_dev(dev
)) == NULL
)
1890 scope
= ipv6_addr_scope(pfx
);
1892 ifp
= ipv6_add_addr(idev
, pfx
, plen
, scope
, IFA_F_PERMANENT
);
1894 addrconf_dad_start(ifp
, 0);
1899 return PTR_ERR(ifp
);
1902 static int inet6_addr_del(int ifindex
, struct in6_addr
*pfx
, int plen
)
1904 struct inet6_ifaddr
*ifp
;
1905 struct inet6_dev
*idev
;
1906 struct net_device
*dev
;
1908 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
1911 if ((idev
= __in6_dev_get(dev
)) == NULL
)
1914 read_lock_bh(&idev
->lock
);
1915 for (ifp
= idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1916 if (ifp
->prefix_len
== plen
&&
1917 ipv6_addr_equal(pfx
, &ifp
->addr
)) {
1919 read_unlock_bh(&idev
->lock
);
1923 /* If the last address is deleted administratively,
1924 disable IPv6 on this interface.
1926 if (idev
->addr_list
== NULL
)
1927 addrconf_ifdown(idev
->dev
, 1);
1931 read_unlock_bh(&idev
->lock
);
1932 return -EADDRNOTAVAIL
;
1936 int addrconf_add_ifaddr(void __user
*arg
)
1938 struct in6_ifreq ireq
;
1941 if (!capable(CAP_NET_ADMIN
))
1944 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1948 err
= inet6_addr_add(ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
, ireq
.ifr6_prefixlen
);
1953 int addrconf_del_ifaddr(void __user
*arg
)
1955 struct in6_ifreq ireq
;
1958 if (!capable(CAP_NET_ADMIN
))
1961 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1965 err
= inet6_addr_del(ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
, ireq
.ifr6_prefixlen
);
1970 static void sit_add_v4_addrs(struct inet6_dev
*idev
)
1972 struct inet6_ifaddr
* ifp
;
1973 struct in6_addr addr
;
1974 struct net_device
*dev
;
1979 memset(&addr
, 0, sizeof(struct in6_addr
));
1980 memcpy(&addr
.s6_addr32
[3], idev
->dev
->dev_addr
, 4);
1982 if (idev
->dev
->flags
&IFF_POINTOPOINT
) {
1983 addr
.s6_addr32
[0] = htonl(0xfe800000);
1986 scope
= IPV6_ADDR_COMPATv4
;
1989 if (addr
.s6_addr32
[3]) {
1990 ifp
= ipv6_add_addr(idev
, &addr
, 128, scope
, IFA_F_PERMANENT
);
1992 spin_lock_bh(&ifp
->lock
);
1993 ifp
->flags
&= ~IFA_F_TENTATIVE
;
1994 spin_unlock_bh(&ifp
->lock
);
1995 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2001 for (dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
) {
2002 struct in_device
* in_dev
= __in_dev_get_rtnl(dev
);
2003 if (in_dev
&& (dev
->flags
& IFF_UP
)) {
2004 struct in_ifaddr
* ifa
;
2008 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
2011 addr
.s6_addr32
[3] = ifa
->ifa_local
;
2013 if (ifa
->ifa_scope
== RT_SCOPE_LINK
)
2015 if (ifa
->ifa_scope
>= RT_SCOPE_HOST
) {
2016 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2020 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2025 ifp
= ipv6_add_addr(idev
, &addr
, plen
, flag
,
2028 spin_lock_bh(&ifp
->lock
);
2029 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2030 spin_unlock_bh(&ifp
->lock
);
2031 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2039 static void init_loopback(struct net_device
*dev
)
2041 struct inet6_dev
*idev
;
2042 struct inet6_ifaddr
* ifp
;
2048 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2049 printk(KERN_DEBUG
"init loopback: add_dev failed\n");
2053 ifp
= ipv6_add_addr(idev
, &in6addr_loopback
, 128, IFA_HOST
, IFA_F_PERMANENT
);
2055 spin_lock_bh(&ifp
->lock
);
2056 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2057 spin_unlock_bh(&ifp
->lock
);
2058 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2063 static void addrconf_add_linklocal(struct inet6_dev
*idev
, struct in6_addr
*addr
)
2065 struct inet6_ifaddr
* ifp
;
2067 ifp
= ipv6_add_addr(idev
, addr
, 64, IFA_LINK
, IFA_F_PERMANENT
);
2069 addrconf_dad_start(ifp
, 0);
2074 static void addrconf_dev_config(struct net_device
*dev
)
2076 struct in6_addr addr
;
2077 struct inet6_dev
* idev
;
2081 if ((dev
->type
!= ARPHRD_ETHER
) &&
2082 (dev
->type
!= ARPHRD_FDDI
) &&
2083 (dev
->type
!= ARPHRD_IEEE802_TR
) &&
2084 (dev
->type
!= ARPHRD_ARCNET
) &&
2085 (dev
->type
!= ARPHRD_INFINIBAND
)) {
2086 /* Alas, we support only Ethernet autoconfiguration. */
2090 idev
= addrconf_add_dev(dev
);
2094 memset(&addr
, 0, sizeof(struct in6_addr
));
2095 addr
.s6_addr32
[0] = htonl(0xFE800000);
2097 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) == 0)
2098 addrconf_add_linklocal(idev
, &addr
);
2101 static void addrconf_sit_config(struct net_device
*dev
)
2103 struct inet6_dev
*idev
;
2108 * Configure the tunnel with one of our IPv4
2109 * addresses... we should configure all of
2110 * our v4 addrs in the tunnel
2113 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2114 printk(KERN_DEBUG
"init sit: add_dev failed\n");
2118 sit_add_v4_addrs(idev
);
2120 if (dev
->flags
&IFF_POINTOPOINT
) {
2121 addrconf_add_mroute(dev
);
2122 addrconf_add_lroute(dev
);
2128 ipv6_inherit_linklocal(struct inet6_dev
*idev
, struct net_device
*link_dev
)
2130 struct in6_addr lladdr
;
2132 if (!ipv6_get_lladdr(link_dev
, &lladdr
)) {
2133 addrconf_add_linklocal(idev
, &lladdr
);
2139 static void ip6_tnl_add_linklocal(struct inet6_dev
*idev
)
2141 struct net_device
*link_dev
;
2143 /* first try to inherit the link-local address from the link device */
2144 if (idev
->dev
->iflink
&&
2145 (link_dev
= __dev_get_by_index(idev
->dev
->iflink
))) {
2146 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2149 /* then try to inherit it from any device */
2150 for (link_dev
= dev_base
; link_dev
; link_dev
= link_dev
->next
) {
2151 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2154 printk(KERN_DEBUG
"init ip6-ip6: add_linklocal failed\n");
2158 * Autoconfigure tunnel with a link-local address so routing protocols,
2159 * DHCPv6, MLD etc. can be run over the virtual link
2162 static void addrconf_ip6_tnl_config(struct net_device
*dev
)
2164 struct inet6_dev
*idev
;
2168 if ((idev
= addrconf_add_dev(dev
)) == NULL
) {
2169 printk(KERN_DEBUG
"init ip6-ip6: add_dev failed\n");
2172 ip6_tnl_add_linklocal(idev
);
2175 static int addrconf_notify(struct notifier_block
*this, unsigned long event
,
2178 struct net_device
*dev
= (struct net_device
*) data
;
2179 struct inet6_dev
*idev
= __in6_dev_get(dev
);
2180 int run_pending
= 0;
2185 if (event
== NETDEV_UP
) {
2186 if (!netif_carrier_ok(dev
)) {
2187 /* device is not ready yet. */
2189 "ADDRCONF(NETDEV_UP): %s: "
2190 "link is not ready\n",
2196 idev
->if_flags
|= IF_READY
;
2198 if (!netif_carrier_ok(dev
)) {
2199 /* device is still not ready. */
2204 if (idev
->if_flags
& IF_READY
) {
2205 /* device is already configured. */
2208 idev
->if_flags
|= IF_READY
;
2212 "ADDRCONF(NETDEV_CHANGE): %s: "
2213 "link becomes ready\n",
2221 addrconf_sit_config(dev
);
2223 case ARPHRD_TUNNEL6
:
2224 addrconf_ip6_tnl_config(dev
);
2226 case ARPHRD_LOOPBACK
:
2231 addrconf_dev_config(dev
);
2236 addrconf_dad_run(idev
);
2238 /* If the MTU changed during the interface down, when the
2239 interface up, the changed MTU must be reflected in the
2240 idev as well as routers.
2242 if (idev
->cnf
.mtu6
!= dev
->mtu
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2243 rt6_mtu_change(dev
, dev
->mtu
);
2244 idev
->cnf
.mtu6
= dev
->mtu
;
2246 idev
->tstamp
= jiffies
;
2247 inet6_ifinfo_notify(RTM_NEWLINK
, idev
);
2248 /* If the changed mtu during down is lower than IPV6_MIN_MTU
2249 stop IPv6 on this interface.
2251 if (dev
->mtu
< IPV6_MIN_MTU
)
2252 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2256 case NETDEV_CHANGEMTU
:
2257 if ( idev
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2258 rt6_mtu_change(dev
, dev
->mtu
);
2259 idev
->cnf
.mtu6
= dev
->mtu
;
2263 /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */
2266 case NETDEV_UNREGISTER
:
2268 * Remove all addresses from this interface.
2270 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2273 case NETDEV_CHANGENAME
:
2274 #ifdef CONFIG_SYSCTL
2276 addrconf_sysctl_unregister(&idev
->cnf
);
2277 neigh_sysctl_unregister(idev
->nd_parms
);
2278 neigh_sysctl_register(dev
, idev
->nd_parms
,
2279 NET_IPV6
, NET_IPV6_NEIGH
, "ipv6",
2280 &ndisc_ifinfo_sysctl_change
,
2282 addrconf_sysctl_register(idev
, &idev
->cnf
);
2292 * addrconf module should be notified of a device going up
2294 static struct notifier_block ipv6_dev_notf
= {
2295 .notifier_call
= addrconf_notify
,
2299 static int addrconf_ifdown(struct net_device
*dev
, int how
)
2301 struct inet6_dev
*idev
;
2302 struct inet6_ifaddr
*ifa
, **bifa
;
2307 if (dev
== &loopback_dev
&& how
== 1)
2311 neigh_ifdown(&nd_tbl
, dev
);
2313 idev
= __in6_dev_get(dev
);
2317 /* Step 1: remove reference to ipv6 device from parent device.
2321 write_lock_bh(&addrconf_lock
);
2322 dev
->ip6_ptr
= NULL
;
2324 write_unlock_bh(&addrconf_lock
);
2326 /* Step 1.5: remove snmp6 entry */
2327 snmp6_unregister_dev(idev
);
2331 /* Step 2: clear hash table */
2332 for (i
=0; i
<IN6_ADDR_HSIZE
; i
++) {
2333 bifa
= &inet6_addr_lst
[i
];
2335 write_lock_bh(&addrconf_hash_lock
);
2336 while ((ifa
= *bifa
) != NULL
) {
2337 if (ifa
->idev
== idev
) {
2338 *bifa
= ifa
->lst_next
;
2339 ifa
->lst_next
= NULL
;
2340 addrconf_del_timer(ifa
);
2344 bifa
= &ifa
->lst_next
;
2346 write_unlock_bh(&addrconf_hash_lock
);
2349 write_lock_bh(&idev
->lock
);
2351 /* Step 3: clear flags for stateless addrconf */
2353 idev
->if_flags
&= ~(IF_RS_SENT
|IF_RA_RCVD
|IF_READY
);
2355 /* Step 4: clear address list */
2356 #ifdef CONFIG_IPV6_PRIVACY
2357 if (how
== 1 && del_timer(&idev
->regen_timer
))
2360 /* clear tempaddr list */
2361 while ((ifa
= idev
->tempaddr_list
) != NULL
) {
2362 idev
->tempaddr_list
= ifa
->tmp_next
;
2363 ifa
->tmp_next
= NULL
;
2365 write_unlock_bh(&idev
->lock
);
2366 spin_lock_bh(&ifa
->lock
);
2369 in6_ifa_put(ifa
->ifpub
);
2372 spin_unlock_bh(&ifa
->lock
);
2374 write_lock_bh(&idev
->lock
);
2377 while ((ifa
= idev
->addr_list
) != NULL
) {
2378 idev
->addr_list
= ifa
->if_next
;
2379 ifa
->if_next
= NULL
;
2381 addrconf_del_timer(ifa
);
2382 write_unlock_bh(&idev
->lock
);
2384 __ipv6_ifa_notify(RTM_DELADDR
, ifa
);
2387 write_lock_bh(&idev
->lock
);
2389 write_unlock_bh(&idev
->lock
);
2391 /* Step 5: Discard multicast list */
2394 ipv6_mc_destroy_dev(idev
);
2398 /* Step 5: netlink notification of this interface */
2399 idev
->tstamp
= jiffies
;
2400 inet6_ifinfo_notify(RTM_DELLINK
, idev
);
2402 /* Shot the device (if unregistered) */
2405 #ifdef CONFIG_SYSCTL
2406 addrconf_sysctl_unregister(&idev
->cnf
);
2407 neigh_sysctl_unregister(idev
->nd_parms
);
2409 neigh_parms_release(&nd_tbl
, idev
->nd_parms
);
2410 neigh_ifdown(&nd_tbl
, dev
);
2416 static void addrconf_rs_timer(unsigned long data
)
2418 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2420 if (ifp
->idev
->cnf
.forwarding
)
2423 if (ifp
->idev
->if_flags
& IF_RA_RCVD
) {
2425 * Announcement received after solicitation
2431 spin_lock(&ifp
->lock
);
2432 if (ifp
->probes
++ < ifp
->idev
->cnf
.rtr_solicits
) {
2433 struct in6_addr all_routers
;
2435 /* The wait after the last probe can be shorter */
2436 addrconf_mod_timer(ifp
, AC_RS
,
2437 (ifp
->probes
== ifp
->idev
->cnf
.rtr_solicits
) ?
2438 ifp
->idev
->cnf
.rtr_solicit_delay
:
2439 ifp
->idev
->cnf
.rtr_solicit_interval
);
2440 spin_unlock(&ifp
->lock
);
2442 ipv6_addr_all_routers(&all_routers
);
2444 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &all_routers
);
2446 spin_unlock(&ifp
->lock
);
2448 * Note: we do not support deprecated "all on-link"
2449 * assumption any longer.
2451 printk(KERN_DEBUG
"%s: no IPv6 routers present\n",
2452 ifp
->idev
->dev
->name
);
2460 * Duplicate Address Detection
2462 static void addrconf_dad_kick(struct inet6_ifaddr
*ifp
)
2464 unsigned long rand_num
;
2465 struct inet6_dev
*idev
= ifp
->idev
;
2467 rand_num
= net_random() % (idev
->cnf
.rtr_solicit_delay
? : 1);
2468 ifp
->probes
= idev
->cnf
.dad_transmits
;
2469 addrconf_mod_timer(ifp
, AC_DAD
, rand_num
);
2472 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
)
2474 struct inet6_dev
*idev
= ifp
->idev
;
2475 struct net_device
*dev
= idev
->dev
;
2477 addrconf_join_solict(dev
, &ifp
->addr
);
2479 if (ifp
->prefix_len
!= 128 && (ifp
->flags
&IFA_F_PERMANENT
))
2480 addrconf_prefix_route(&ifp
->addr
, ifp
->prefix_len
, dev
, 0,
2483 net_srandom(ifp
->addr
.s6_addr32
[3]);
2485 read_lock_bh(&idev
->lock
);
2488 spin_lock_bh(&ifp
->lock
);
2490 if (dev
->flags
&(IFF_NOARP
|IFF_LOOPBACK
) ||
2491 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
2492 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2493 spin_unlock_bh(&ifp
->lock
);
2494 read_unlock_bh(&idev
->lock
);
2496 addrconf_dad_completed(ifp
);
2500 if (!(idev
->if_flags
& IF_READY
)) {
2501 spin_unlock_bh(&ifp
->lock
);
2502 read_unlock_bh(&idev
->lock
);
2504 * If the defice is not ready:
2505 * - keep it tentative if it is a permanent address.
2506 * - otherwise, kill it.
2509 addrconf_dad_stop(ifp
);
2512 addrconf_dad_kick(ifp
);
2513 spin_unlock_bh(&ifp
->lock
);
2515 read_unlock_bh(&idev
->lock
);
2518 static void addrconf_dad_timer(unsigned long data
)
2520 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2521 struct inet6_dev
*idev
= ifp
->idev
;
2522 struct in6_addr unspec
;
2523 struct in6_addr mcaddr
;
2525 read_lock_bh(&idev
->lock
);
2527 read_unlock_bh(&idev
->lock
);
2530 spin_lock_bh(&ifp
->lock
);
2531 if (ifp
->probes
== 0) {
2533 * DAD was successful
2536 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2537 spin_unlock_bh(&ifp
->lock
);
2538 read_unlock_bh(&idev
->lock
);
2540 addrconf_dad_completed(ifp
);
2546 addrconf_mod_timer(ifp
, AC_DAD
, ifp
->idev
->nd_parms
->retrans_time
);
2547 spin_unlock_bh(&ifp
->lock
);
2548 read_unlock_bh(&idev
->lock
);
2550 /* send a neighbour solicitation for our addr */
2551 memset(&unspec
, 0, sizeof(unspec
));
2552 addrconf_addr_solict_mult(&ifp
->addr
, &mcaddr
);
2553 ndisc_send_ns(ifp
->idev
->dev
, NULL
, &ifp
->addr
, &mcaddr
, &unspec
);
2558 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
)
2560 struct net_device
* dev
= ifp
->idev
->dev
;
2563 * Configure the address for reception. Now it is valid.
2566 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2568 /* If added prefix is link local and forwarding is off,
2569 start sending router solicitations.
2572 if (ifp
->idev
->cnf
.forwarding
== 0 &&
2573 ifp
->idev
->cnf
.rtr_solicits
> 0 &&
2574 (dev
->flags
&IFF_LOOPBACK
) == 0 &&
2575 (ipv6_addr_type(&ifp
->addr
) & IPV6_ADDR_LINKLOCAL
)) {
2576 struct in6_addr all_routers
;
2578 ipv6_addr_all_routers(&all_routers
);
2581 * If a host as already performed a random delay
2582 * [...] as part of DAD [...] there is no need
2583 * to delay again before sending the first RS
2585 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &all_routers
);
2587 spin_lock_bh(&ifp
->lock
);
2589 ifp
->idev
->if_flags
|= IF_RS_SENT
;
2590 addrconf_mod_timer(ifp
, AC_RS
, ifp
->idev
->cnf
.rtr_solicit_interval
);
2591 spin_unlock_bh(&ifp
->lock
);
2595 static void addrconf_dad_run(struct inet6_dev
*idev
) {
2596 struct inet6_ifaddr
*ifp
;
2598 read_lock_bh(&idev
->lock
);
2599 for (ifp
= idev
->addr_list
; ifp
; ifp
= ifp
->if_next
) {
2600 spin_lock_bh(&ifp
->lock
);
2601 if (!(ifp
->flags
& IFA_F_TENTATIVE
)) {
2602 spin_unlock_bh(&ifp
->lock
);
2605 spin_unlock_bh(&ifp
->lock
);
2606 addrconf_dad_kick(ifp
);
2608 read_unlock_bh(&idev
->lock
);
2611 #ifdef CONFIG_PROC_FS
2612 struct if6_iter_state
{
2616 static struct inet6_ifaddr
*if6_get_first(struct seq_file
*seq
)
2618 struct inet6_ifaddr
*ifa
= NULL
;
2619 struct if6_iter_state
*state
= seq
->private;
2621 for (state
->bucket
= 0; state
->bucket
< IN6_ADDR_HSIZE
; ++state
->bucket
) {
2622 ifa
= inet6_addr_lst
[state
->bucket
];
2629 static struct inet6_ifaddr
*if6_get_next(struct seq_file
*seq
, struct inet6_ifaddr
*ifa
)
2631 struct if6_iter_state
*state
= seq
->private;
2633 ifa
= ifa
->lst_next
;
2635 if (!ifa
&& ++state
->bucket
< IN6_ADDR_HSIZE
) {
2636 ifa
= inet6_addr_lst
[state
->bucket
];
2642 static struct inet6_ifaddr
*if6_get_idx(struct seq_file
*seq
, loff_t pos
)
2644 struct inet6_ifaddr
*ifa
= if6_get_first(seq
);
2647 while(pos
&& (ifa
= if6_get_next(seq
, ifa
)) != NULL
)
2649 return pos
? NULL
: ifa
;
2652 static void *if6_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2654 read_lock_bh(&addrconf_hash_lock
);
2655 return if6_get_idx(seq
, *pos
);
2658 static void *if6_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2660 struct inet6_ifaddr
*ifa
;
2662 ifa
= if6_get_next(seq
, v
);
2667 static void if6_seq_stop(struct seq_file
*seq
, void *v
)
2669 read_unlock_bh(&addrconf_hash_lock
);
2672 static int if6_seq_show(struct seq_file
*seq
, void *v
)
2674 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*)v
;
2676 NIP6_SEQFMT
" %02x %02x %02x %02x %8s\n",
2678 ifp
->idev
->dev
->ifindex
,
2682 ifp
->idev
->dev
->name
);
2686 static struct seq_operations if6_seq_ops
= {
2687 .start
= if6_seq_start
,
2688 .next
= if6_seq_next
,
2689 .show
= if6_seq_show
,
2690 .stop
= if6_seq_stop
,
2693 static int if6_seq_open(struct inode
*inode
, struct file
*file
)
2695 struct seq_file
*seq
;
2697 struct if6_iter_state
*s
= kzalloc(sizeof(*s
), GFP_KERNEL
);
2702 rc
= seq_open(file
, &if6_seq_ops
);
2706 seq
= file
->private_data
;
2715 static struct file_operations if6_fops
= {
2716 .owner
= THIS_MODULE
,
2717 .open
= if6_seq_open
,
2719 .llseek
= seq_lseek
,
2720 .release
= seq_release_private
,
2723 int __init
if6_proc_init(void)
2725 if (!proc_net_fops_create("if_inet6", S_IRUGO
, &if6_fops
))
2730 void if6_proc_exit(void)
2732 proc_net_remove("if_inet6");
2734 #endif /* CONFIG_PROC_FS */
2737 * Periodic address status verification
2740 static void addrconf_verify(unsigned long foo
)
2742 struct inet6_ifaddr
*ifp
;
2743 unsigned long now
, next
;
2746 spin_lock_bh(&addrconf_verify_lock
);
2748 next
= now
+ ADDR_CHECK_FREQUENCY
;
2750 del_timer(&addr_chk_timer
);
2752 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
2755 read_lock(&addrconf_hash_lock
);
2756 for (ifp
=inet6_addr_lst
[i
]; ifp
; ifp
=ifp
->lst_next
) {
2758 #ifdef CONFIG_IPV6_PRIVACY
2759 unsigned long regen_advance
;
2762 if (ifp
->flags
& IFA_F_PERMANENT
)
2765 spin_lock(&ifp
->lock
);
2766 age
= (now
- ifp
->tstamp
) / HZ
;
2768 #ifdef CONFIG_IPV6_PRIVACY
2769 regen_advance
= ifp
->idev
->cnf
.regen_max_retry
*
2770 ifp
->idev
->cnf
.dad_transmits
*
2771 ifp
->idev
->nd_parms
->retrans_time
/ HZ
;
2774 if (age
>= ifp
->valid_lft
) {
2775 spin_unlock(&ifp
->lock
);
2777 read_unlock(&addrconf_hash_lock
);
2780 } else if (age
>= ifp
->prefered_lft
) {
2781 /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */
2784 if (!(ifp
->flags
&IFA_F_DEPRECATED
)) {
2786 ifp
->flags
|= IFA_F_DEPRECATED
;
2789 if (time_before(ifp
->tstamp
+ ifp
->valid_lft
* HZ
, next
))
2790 next
= ifp
->tstamp
+ ifp
->valid_lft
* HZ
;
2792 spin_unlock(&ifp
->lock
);
2796 read_unlock(&addrconf_hash_lock
);
2798 ipv6_ifa_notify(0, ifp
);
2802 #ifdef CONFIG_IPV6_PRIVACY
2803 } else if ((ifp
->flags
&IFA_F_TEMPORARY
) &&
2804 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
2805 if (age
>= ifp
->prefered_lft
- regen_advance
) {
2806 struct inet6_ifaddr
*ifpub
= ifp
->ifpub
;
2807 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
2808 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
2809 if (!ifp
->regen_count
&& ifpub
) {
2812 in6_ifa_hold(ifpub
);
2813 spin_unlock(&ifp
->lock
);
2814 read_unlock(&addrconf_hash_lock
);
2815 spin_lock(&ifpub
->lock
);
2816 ifpub
->regen_count
= 0;
2817 spin_unlock(&ifpub
->lock
);
2818 ipv6_create_tempaddr(ifpub
, ifp
);
2823 } else if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
, next
))
2824 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
;
2825 spin_unlock(&ifp
->lock
);
2828 /* ifp->prefered_lft <= ifp->valid_lft */
2829 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
2830 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
2831 spin_unlock(&ifp
->lock
);
2834 read_unlock(&addrconf_hash_lock
);
2837 addr_chk_timer
.expires
= time_before(next
, jiffies
+ HZ
) ? jiffies
+ HZ
: next
;
2838 add_timer(&addr_chk_timer
);
2839 spin_unlock_bh(&addrconf_verify_lock
);
2843 inet6_rtm_deladdr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
2845 struct rtattr
**rta
= arg
;
2846 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
2847 struct in6_addr
*pfx
;
2850 if (rta
[IFA_ADDRESS
-1]) {
2851 if (RTA_PAYLOAD(rta
[IFA_ADDRESS
-1]) < sizeof(*pfx
))
2853 pfx
= RTA_DATA(rta
[IFA_ADDRESS
-1]);
2855 if (rta
[IFA_LOCAL
-1]) {
2856 if (pfx
&& memcmp(pfx
, RTA_DATA(rta
[IFA_LOCAL
-1]), sizeof(*pfx
)))
2858 pfx
= RTA_DATA(rta
[IFA_LOCAL
-1]);
2863 return inet6_addr_del(ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
);
2867 inet6_rtm_newaddr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
2869 struct rtattr
**rta
= arg
;
2870 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
2871 struct in6_addr
*pfx
;
2874 if (rta
[IFA_ADDRESS
-1]) {
2875 if (RTA_PAYLOAD(rta
[IFA_ADDRESS
-1]) < sizeof(*pfx
))
2877 pfx
= RTA_DATA(rta
[IFA_ADDRESS
-1]);
2879 if (rta
[IFA_LOCAL
-1]) {
2880 if (pfx
&& memcmp(pfx
, RTA_DATA(rta
[IFA_LOCAL
-1]), sizeof(*pfx
)))
2882 pfx
= RTA_DATA(rta
[IFA_LOCAL
-1]);
2887 return inet6_addr_add(ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
);
2890 /* Maximum length of ifa_cacheinfo attributes */
2891 #define INET6_IFADDR_RTA_SPACE \
2892 RTA_SPACE(16) /* IFA_ADDRESS */ + \
2893 RTA_SPACE(sizeof(struct ifa_cacheinfo)) /* CACHEINFO */
2895 static int inet6_fill_ifaddr(struct sk_buff
*skb
, struct inet6_ifaddr
*ifa
,
2896 u32 pid
, u32 seq
, int event
, unsigned int flags
)
2898 struct ifaddrmsg
*ifm
;
2899 struct nlmsghdr
*nlh
;
2900 struct ifa_cacheinfo ci
;
2901 unsigned char *b
= skb
->tail
;
2903 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
2904 ifm
= NLMSG_DATA(nlh
);
2905 ifm
->ifa_family
= AF_INET6
;
2906 ifm
->ifa_prefixlen
= ifa
->prefix_len
;
2907 ifm
->ifa_flags
= ifa
->flags
;
2908 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
2909 if (ifa
->scope
&IFA_HOST
)
2910 ifm
->ifa_scope
= RT_SCOPE_HOST
;
2911 else if (ifa
->scope
&IFA_LINK
)
2912 ifm
->ifa_scope
= RT_SCOPE_LINK
;
2913 else if (ifa
->scope
&IFA_SITE
)
2914 ifm
->ifa_scope
= RT_SCOPE_SITE
;
2915 ifm
->ifa_index
= ifa
->idev
->dev
->ifindex
;
2916 RTA_PUT(skb
, IFA_ADDRESS
, 16, &ifa
->addr
);
2917 if (!(ifa
->flags
&IFA_F_PERMANENT
)) {
2918 ci
.ifa_prefered
= ifa
->prefered_lft
;
2919 ci
.ifa_valid
= ifa
->valid_lft
;
2920 if (ci
.ifa_prefered
!= INFINITY_LIFE_TIME
) {
2921 long tval
= (jiffies
- ifa
->tstamp
)/HZ
;
2922 ci
.ifa_prefered
-= tval
;
2923 if (ci
.ifa_valid
!= INFINITY_LIFE_TIME
)
2924 ci
.ifa_valid
-= tval
;
2927 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
2928 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
2930 ci
.cstamp
= (__u32
)(TIME_DELTA(ifa
->cstamp
, INITIAL_JIFFIES
) / HZ
* 100
2931 + TIME_DELTA(ifa
->cstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
2932 ci
.tstamp
= (__u32
)(TIME_DELTA(ifa
->tstamp
, INITIAL_JIFFIES
) / HZ
* 100
2933 + TIME_DELTA(ifa
->tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
2934 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
2935 nlh
->nlmsg_len
= skb
->tail
- b
;
2940 skb_trim(skb
, b
- skb
->data
);
2944 static int inet6_fill_ifmcaddr(struct sk_buff
*skb
, struct ifmcaddr6
*ifmca
,
2945 u32 pid
, u32 seq
, int event
, u16 flags
)
2947 struct ifaddrmsg
*ifm
;
2948 struct nlmsghdr
*nlh
;
2949 struct ifa_cacheinfo ci
;
2950 unsigned char *b
= skb
->tail
;
2952 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
2953 ifm
= NLMSG_DATA(nlh
);
2954 ifm
->ifa_family
= AF_INET6
;
2955 ifm
->ifa_prefixlen
= 128;
2956 ifm
->ifa_flags
= IFA_F_PERMANENT
;
2957 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
2958 if (ipv6_addr_scope(&ifmca
->mca_addr
)&IFA_SITE
)
2959 ifm
->ifa_scope
= RT_SCOPE_SITE
;
2960 ifm
->ifa_index
= ifmca
->idev
->dev
->ifindex
;
2961 RTA_PUT(skb
, IFA_MULTICAST
, 16, &ifmca
->mca_addr
);
2962 ci
.cstamp
= (__u32
)(TIME_DELTA(ifmca
->mca_cstamp
, INITIAL_JIFFIES
) / HZ
2963 * 100 + TIME_DELTA(ifmca
->mca_cstamp
, INITIAL_JIFFIES
) % HZ
2965 ci
.tstamp
= (__u32
)(TIME_DELTA(ifmca
->mca_tstamp
, INITIAL_JIFFIES
) / HZ
2966 * 100 + TIME_DELTA(ifmca
->mca_tstamp
, INITIAL_JIFFIES
) % HZ
2968 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
2969 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
2970 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
2971 nlh
->nlmsg_len
= skb
->tail
- b
;
2976 skb_trim(skb
, b
- skb
->data
);
2980 static int inet6_fill_ifacaddr(struct sk_buff
*skb
, struct ifacaddr6
*ifaca
,
2981 u32 pid
, u32 seq
, int event
, unsigned int flags
)
2983 struct ifaddrmsg
*ifm
;
2984 struct nlmsghdr
*nlh
;
2985 struct ifa_cacheinfo ci
;
2986 unsigned char *b
= skb
->tail
;
2988 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
2989 ifm
= NLMSG_DATA(nlh
);
2990 ifm
->ifa_family
= AF_INET6
;
2991 ifm
->ifa_prefixlen
= 128;
2992 ifm
->ifa_flags
= IFA_F_PERMANENT
;
2993 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
2994 if (ipv6_addr_scope(&ifaca
->aca_addr
)&IFA_SITE
)
2995 ifm
->ifa_scope
= RT_SCOPE_SITE
;
2996 ifm
->ifa_index
= ifaca
->aca_idev
->dev
->ifindex
;
2997 RTA_PUT(skb
, IFA_ANYCAST
, 16, &ifaca
->aca_addr
);
2998 ci
.cstamp
= (__u32
)(TIME_DELTA(ifaca
->aca_cstamp
, INITIAL_JIFFIES
) / HZ
2999 * 100 + TIME_DELTA(ifaca
->aca_cstamp
, INITIAL_JIFFIES
) % HZ
3001 ci
.tstamp
= (__u32
)(TIME_DELTA(ifaca
->aca_tstamp
, INITIAL_JIFFIES
) / HZ
3002 * 100 + TIME_DELTA(ifaca
->aca_tstamp
, INITIAL_JIFFIES
) % HZ
3004 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
3005 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
3006 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
3007 nlh
->nlmsg_len
= skb
->tail
- b
;
3012 skb_trim(skb
, b
- skb
->data
);
3023 static int inet6_dump_addr(struct sk_buff
*skb
, struct netlink_callback
*cb
,
3024 enum addr_type_t type
)
3027 int s_idx
, s_ip_idx
;
3029 struct net_device
*dev
;
3030 struct inet6_dev
*idev
= NULL
;
3031 struct inet6_ifaddr
*ifa
;
3032 struct ifmcaddr6
*ifmca
;
3033 struct ifacaddr6
*ifaca
;
3035 s_idx
= cb
->args
[0];
3036 s_ip_idx
= ip_idx
= cb
->args
[1];
3037 read_lock(&dev_base_lock
);
3039 for (dev
= dev_base
, idx
= 0; dev
; dev
= dev
->next
, idx
++) {
3045 if ((idev
= in6_dev_get(dev
)) == NULL
)
3047 read_lock_bh(&idev
->lock
);
3050 /* unicast address incl. temp addr */
3051 for (ifa
= idev
->addr_list
; ifa
;
3052 ifa
= ifa
->if_next
, ip_idx
++) {
3053 if (ip_idx
< s_ip_idx
)
3055 if ((err
= inet6_fill_ifaddr(skb
, ifa
,
3056 NETLINK_CB(cb
->skb
).pid
,
3057 cb
->nlh
->nlmsg_seq
, RTM_NEWADDR
,
3062 case MULTICAST_ADDR
:
3063 /* multicast address */
3064 for (ifmca
= idev
->mc_list
; ifmca
;
3065 ifmca
= ifmca
->next
, ip_idx
++) {
3066 if (ip_idx
< s_ip_idx
)
3068 if ((err
= inet6_fill_ifmcaddr(skb
, ifmca
,
3069 NETLINK_CB(cb
->skb
).pid
,
3070 cb
->nlh
->nlmsg_seq
, RTM_GETMULTICAST
,
3076 /* anycast address */
3077 for (ifaca
= idev
->ac_list
; ifaca
;
3078 ifaca
= ifaca
->aca_next
, ip_idx
++) {
3079 if (ip_idx
< s_ip_idx
)
3081 if ((err
= inet6_fill_ifacaddr(skb
, ifaca
,
3082 NETLINK_CB(cb
->skb
).pid
,
3083 cb
->nlh
->nlmsg_seq
, RTM_GETANYCAST
,
3091 read_unlock_bh(&idev
->lock
);
3096 read_unlock_bh(&idev
->lock
);
3099 read_unlock(&dev_base_lock
);
3101 cb
->args
[1] = ip_idx
;
3105 static int inet6_dump_ifaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3107 enum addr_type_t type
= UNICAST_ADDR
;
3108 return inet6_dump_addr(skb
, cb
, type
);
3111 static int inet6_dump_ifmcaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3113 enum addr_type_t type
= MULTICAST_ADDR
;
3114 return inet6_dump_addr(skb
, cb
, type
);
3118 static int inet6_dump_ifacaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3120 enum addr_type_t type
= ANYCAST_ADDR
;
3121 return inet6_dump_addr(skb
, cb
, type
);
3124 static void inet6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
)
3126 struct sk_buff
*skb
;
3127 int size
= NLMSG_SPACE(sizeof(struct ifaddrmsg
) + INET6_IFADDR_RTA_SPACE
);
3129 skb
= alloc_skb(size
, GFP_ATOMIC
);
3131 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFADDR
, ENOBUFS
);
3134 if (inet6_fill_ifaddr(skb
, ifa
, current
->pid
, 0, event
, 0) < 0) {
3136 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFADDR
, EINVAL
);
3139 NETLINK_CB(skb
).dst_group
= RTNLGRP_IPV6_IFADDR
;
3140 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_IPV6_IFADDR
, GFP_ATOMIC
);
3143 static void inline ipv6_store_devconf(struct ipv6_devconf
*cnf
,
3144 __s32
*array
, int bytes
)
3146 memset(array
, 0, bytes
);
3147 array
[DEVCONF_FORWARDING
] = cnf
->forwarding
;
3148 array
[DEVCONF_HOPLIMIT
] = cnf
->hop_limit
;
3149 array
[DEVCONF_MTU6
] = cnf
->mtu6
;
3150 array
[DEVCONF_ACCEPT_RA
] = cnf
->accept_ra
;
3151 array
[DEVCONF_ACCEPT_REDIRECTS
] = cnf
->accept_redirects
;
3152 array
[DEVCONF_AUTOCONF
] = cnf
->autoconf
;
3153 array
[DEVCONF_DAD_TRANSMITS
] = cnf
->dad_transmits
;
3154 array
[DEVCONF_RTR_SOLICITS
] = cnf
->rtr_solicits
;
3155 array
[DEVCONF_RTR_SOLICIT_INTERVAL
] = cnf
->rtr_solicit_interval
;
3156 array
[DEVCONF_RTR_SOLICIT_DELAY
] = cnf
->rtr_solicit_delay
;
3157 array
[DEVCONF_FORCE_MLD_VERSION
] = cnf
->force_mld_version
;
3158 #ifdef CONFIG_IPV6_PRIVACY
3159 array
[DEVCONF_USE_TEMPADDR
] = cnf
->use_tempaddr
;
3160 array
[DEVCONF_TEMP_VALID_LFT
] = cnf
->temp_valid_lft
;
3161 array
[DEVCONF_TEMP_PREFERED_LFT
] = cnf
->temp_prefered_lft
;
3162 array
[DEVCONF_REGEN_MAX_RETRY
] = cnf
->regen_max_retry
;
3163 array
[DEVCONF_MAX_DESYNC_FACTOR
] = cnf
->max_desync_factor
;
3165 array
[DEVCONF_MAX_ADDRESSES
] = cnf
->max_addresses
;
3166 array
[DEVCONF_ACCEPT_RA_DEFRTR
] = cnf
->accept_ra_defrtr
;
3167 array
[DEVCONF_ACCEPT_RA_PINFO
] = cnf
->accept_ra_pinfo
;
3168 #ifdef CONFIG_IPV6_ROUTER_PREF
3169 array
[DEVCONF_ACCEPT_RA_RTR_PREF
] = cnf
->accept_ra_rtr_pref
;
3170 array
[DEVCONF_RTR_PROBE_INTERVAL
] = cnf
->rtr_probe_interval
;
3171 #ifdef CONFIV_IPV6_ROUTE_INFO
3172 array
[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN
] = cnf
->accept_ra_rt_info_max_plen
;
3177 /* Maximum length of ifinfomsg attributes */
3178 #define INET6_IFINFO_RTA_SPACE \
3179 RTA_SPACE(IFNAMSIZ) /* IFNAME */ + \
3180 RTA_SPACE(MAX_ADDR_LEN) /* ADDRESS */ + \
3181 RTA_SPACE(sizeof(u32)) /* MTU */ + \
3182 RTA_SPACE(sizeof(int)) /* LINK */ + \
3183 RTA_SPACE(0) /* PROTINFO */ + \
3184 RTA_SPACE(sizeof(u32)) /* FLAGS */ + \
3185 RTA_SPACE(sizeof(struct ifla_cacheinfo)) /* CACHEINFO */ + \
3186 RTA_SPACE(sizeof(__s32[DEVCONF_MAX])) /* CONF */
3188 static int inet6_fill_ifinfo(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3189 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3191 struct net_device
*dev
= idev
->dev
;
3192 __s32
*array
= NULL
;
3193 struct ifinfomsg
*r
;
3194 struct nlmsghdr
*nlh
;
3195 unsigned char *b
= skb
->tail
;
3196 struct rtattr
*subattr
;
3197 __u32 mtu
= dev
->mtu
;
3198 struct ifla_cacheinfo ci
;
3200 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*r
), flags
);
3201 r
= NLMSG_DATA(nlh
);
3202 r
->ifi_family
= AF_INET6
;
3204 r
->ifi_type
= dev
->type
;
3205 r
->ifi_index
= dev
->ifindex
;
3206 r
->ifi_flags
= dev_get_flags(dev
);
3209 RTA_PUT(skb
, IFLA_IFNAME
, strlen(dev
->name
)+1, dev
->name
);
3212 RTA_PUT(skb
, IFLA_ADDRESS
, dev
->addr_len
, dev
->dev_addr
);
3214 RTA_PUT(skb
, IFLA_MTU
, sizeof(mtu
), &mtu
);
3215 if (dev
->ifindex
!= dev
->iflink
)
3216 RTA_PUT(skb
, IFLA_LINK
, sizeof(int), &dev
->iflink
);
3218 subattr
= (struct rtattr
*)skb
->tail
;
3220 RTA_PUT(skb
, IFLA_PROTINFO
, 0, NULL
);
3222 /* return the device flags */
3223 RTA_PUT(skb
, IFLA_INET6_FLAGS
, sizeof(__u32
), &idev
->if_flags
);
3225 /* return interface cacheinfo */
3226 ci
.max_reasm_len
= IPV6_MAXPLEN
;
3227 ci
.tstamp
= (__u32
)(TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) / HZ
* 100
3228 + TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3229 ci
.reachable_time
= idev
->nd_parms
->reachable_time
;
3230 ci
.retrans_time
= idev
->nd_parms
->retrans_time
;
3231 RTA_PUT(skb
, IFLA_INET6_CACHEINFO
, sizeof(ci
), &ci
);
3233 /* return the device sysctl params */
3234 if ((array
= kmalloc(DEVCONF_MAX
* sizeof(*array
), GFP_ATOMIC
)) == NULL
)
3235 goto rtattr_failure
;
3236 ipv6_store_devconf(&idev
->cnf
, array
, DEVCONF_MAX
* sizeof(*array
));
3237 RTA_PUT(skb
, IFLA_INET6_CONF
, DEVCONF_MAX
* sizeof(*array
), array
);
3239 /* XXX - Statistics/MC not implemented */
3240 subattr
->rta_len
= skb
->tail
- (u8
*)subattr
;
3242 nlh
->nlmsg_len
= skb
->tail
- b
;
3249 skb_trim(skb
, b
- skb
->data
);
3253 static int inet6_dump_ifinfo(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3256 int s_idx
= cb
->args
[0];
3257 struct net_device
*dev
;
3258 struct inet6_dev
*idev
;
3260 read_lock(&dev_base_lock
);
3261 for (dev
=dev_base
, idx
=0; dev
; dev
= dev
->next
, idx
++) {
3264 if ((idev
= in6_dev_get(dev
)) == NULL
)
3266 err
= inet6_fill_ifinfo(skb
, idev
, NETLINK_CB(cb
->skb
).pid
,
3267 cb
->nlh
->nlmsg_seq
, RTM_NEWLINK
, NLM_F_MULTI
);
3272 read_unlock(&dev_base_lock
);
3278 void inet6_ifinfo_notify(int event
, struct inet6_dev
*idev
)
3280 struct sk_buff
*skb
;
3281 int size
= NLMSG_SPACE(sizeof(struct ifinfomsg
) + INET6_IFINFO_RTA_SPACE
);
3283 skb
= alloc_skb(size
, GFP_ATOMIC
);
3285 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFINFO
, ENOBUFS
);
3288 if (inet6_fill_ifinfo(skb
, idev
, current
->pid
, 0, event
, 0) < 0) {
3290 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFINFO
, EINVAL
);
3293 NETLINK_CB(skb
).dst_group
= RTNLGRP_IPV6_IFINFO
;
3294 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_IPV6_IFINFO
, GFP_ATOMIC
);
3297 /* Maximum length of prefix_cacheinfo attributes */
3298 #define INET6_PREFIX_RTA_SPACE \
3299 RTA_SPACE(sizeof(((struct prefix_info *)NULL)->prefix)) /* ADDRESS */ + \
3300 RTA_SPACE(sizeof(struct prefix_cacheinfo)) /* CACHEINFO */
3302 static int inet6_fill_prefix(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3303 struct prefix_info
*pinfo
, u32 pid
, u32 seq
,
3304 int event
, unsigned int flags
)
3306 struct prefixmsg
*pmsg
;
3307 struct nlmsghdr
*nlh
;
3308 unsigned char *b
= skb
->tail
;
3309 struct prefix_cacheinfo ci
;
3311 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*pmsg
), flags
);
3312 pmsg
= NLMSG_DATA(nlh
);
3313 pmsg
->prefix_family
= AF_INET6
;
3314 pmsg
->prefix_pad1
= 0;
3315 pmsg
->prefix_pad2
= 0;
3316 pmsg
->prefix_ifindex
= idev
->dev
->ifindex
;
3317 pmsg
->prefix_len
= pinfo
->prefix_len
;
3318 pmsg
->prefix_type
= pinfo
->type
;
3319 pmsg
->prefix_pad3
= 0;
3321 pmsg
->prefix_flags
= 0;
3323 pmsg
->prefix_flags
|= IF_PREFIX_ONLINK
;
3324 if (pinfo
->autoconf
)
3325 pmsg
->prefix_flags
|= IF_PREFIX_AUTOCONF
;
3327 RTA_PUT(skb
, PREFIX_ADDRESS
, sizeof(pinfo
->prefix
), &pinfo
->prefix
);
3329 ci
.preferred_time
= ntohl(pinfo
->prefered
);
3330 ci
.valid_time
= ntohl(pinfo
->valid
);
3331 RTA_PUT(skb
, PREFIX_CACHEINFO
, sizeof(ci
), &ci
);
3333 nlh
->nlmsg_len
= skb
->tail
- b
;
3338 skb_trim(skb
, b
- skb
->data
);
3342 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
3343 struct prefix_info
*pinfo
)
3345 struct sk_buff
*skb
;
3346 int size
= NLMSG_SPACE(sizeof(struct prefixmsg
) + INET6_PREFIX_RTA_SPACE
);
3348 skb
= alloc_skb(size
, GFP_ATOMIC
);
3350 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_PREFIX
, ENOBUFS
);
3353 if (inet6_fill_prefix(skb
, idev
, pinfo
, current
->pid
, 0, event
, 0) < 0) {
3355 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_PREFIX
, EINVAL
);
3358 NETLINK_CB(skb
).dst_group
= RTNLGRP_IPV6_PREFIX
;
3359 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_IPV6_PREFIX
, GFP_ATOMIC
);
3362 static struct rtnetlink_link inet6_rtnetlink_table
[RTM_NR_MSGTYPES
] = {
3363 [RTM_GETLINK
- RTM_BASE
] = { .dumpit
= inet6_dump_ifinfo
, },
3364 [RTM_NEWADDR
- RTM_BASE
] = { .doit
= inet6_rtm_newaddr
, },
3365 [RTM_DELADDR
- RTM_BASE
] = { .doit
= inet6_rtm_deladdr
, },
3366 [RTM_GETADDR
- RTM_BASE
] = { .dumpit
= inet6_dump_ifaddr
, },
3367 [RTM_GETMULTICAST
- RTM_BASE
] = { .dumpit
= inet6_dump_ifmcaddr
, },
3368 [RTM_GETANYCAST
- RTM_BASE
] = { .dumpit
= inet6_dump_ifacaddr
, },
3369 [RTM_NEWROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_newroute
, },
3370 [RTM_DELROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_delroute
, },
3371 [RTM_GETROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_getroute
,
3372 .dumpit
= inet6_dump_fib
, },
3375 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3377 inet6_ifa_notify(event
? : RTM_NEWADDR
, ifp
);
3381 ip6_ins_rt(ifp
->rt
, NULL
, NULL
, NULL
);
3382 if (ifp
->idev
->cnf
.forwarding
)
3383 addrconf_join_anycast(ifp
);
3386 if (ifp
->idev
->cnf
.forwarding
)
3387 addrconf_leave_anycast(ifp
);
3388 addrconf_leave_solict(ifp
->idev
, &ifp
->addr
);
3389 dst_hold(&ifp
->rt
->u
.dst
);
3390 if (ip6_del_rt(ifp
->rt
, NULL
, NULL
, NULL
))
3391 dst_free(&ifp
->rt
->u
.dst
);
3396 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3398 read_lock_bh(&addrconf_lock
);
3399 if (likely(ifp
->idev
->dead
== 0))
3400 __ipv6_ifa_notify(event
, ifp
);
3401 read_unlock_bh(&addrconf_lock
);
3404 #ifdef CONFIG_SYSCTL
3407 int addrconf_sysctl_forward(ctl_table
*ctl
, int write
, struct file
* filp
,
3408 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3410 int *valp
= ctl
->data
;
3414 ret
= proc_dointvec(ctl
, write
, filp
, buffer
, lenp
, ppos
);
3416 if (write
&& valp
!= &ipv6_devconf_dflt
.forwarding
) {
3417 if (valp
!= &ipv6_devconf
.forwarding
) {
3418 if ((!*valp
) ^ (!val
)) {
3419 struct inet6_dev
*idev
= (struct inet6_dev
*)ctl
->extra1
;
3422 dev_forward_change(idev
);
3425 ipv6_devconf_dflt
.forwarding
= ipv6_devconf
.forwarding
;
3426 addrconf_forward_change();
3429 rt6_purge_dflt_routers();
3435 static int addrconf_sysctl_forward_strategy(ctl_table
*table
,
3436 int __user
*name
, int nlen
,
3437 void __user
*oldval
,
3438 size_t __user
*oldlenp
,
3439 void __user
*newval
, size_t newlen
,
3442 int *valp
= table
->data
;
3445 if (!newval
|| !newlen
)
3447 if (newlen
!= sizeof(int))
3449 if (get_user(new, (int __user
*)newval
))
3453 if (oldval
&& oldlenp
) {
3455 if (get_user(len
, oldlenp
))
3458 if (len
> table
->maxlen
)
3459 len
= table
->maxlen
;
3460 if (copy_to_user(oldval
, valp
, len
))
3462 if (put_user(len
, oldlenp
))
3467 if (valp
!= &ipv6_devconf_dflt
.forwarding
) {
3468 if (valp
!= &ipv6_devconf
.forwarding
) {
3469 struct inet6_dev
*idev
= (struct inet6_dev
*)table
->extra1
;
3471 if (unlikely(idev
== NULL
))
3473 changed
= (!*valp
) ^ (!new);
3476 dev_forward_change(idev
);
3479 addrconf_forward_change();
3483 rt6_purge_dflt_routers();
3490 static struct addrconf_sysctl_table
3492 struct ctl_table_header
*sysctl_header
;
3493 ctl_table addrconf_vars
[__NET_IPV6_MAX
];
3494 ctl_table addrconf_dev
[2];
3495 ctl_table addrconf_conf_dir
[2];
3496 ctl_table addrconf_proto_dir
[2];
3497 ctl_table addrconf_root_dir
[2];
3498 } addrconf_sysctl
= {
3499 .sysctl_header
= NULL
,
3502 .ctl_name
= NET_IPV6_FORWARDING
,
3503 .procname
= "forwarding",
3504 .data
= &ipv6_devconf
.forwarding
,
3505 .maxlen
= sizeof(int),
3507 .proc_handler
= &addrconf_sysctl_forward
,
3508 .strategy
= &addrconf_sysctl_forward_strategy
,
3511 .ctl_name
= NET_IPV6_HOP_LIMIT
,
3512 .procname
= "hop_limit",
3513 .data
= &ipv6_devconf
.hop_limit
,
3514 .maxlen
= sizeof(int),
3516 .proc_handler
= proc_dointvec
,
3519 .ctl_name
= NET_IPV6_MTU
,
3521 .data
= &ipv6_devconf
.mtu6
,
3522 .maxlen
= sizeof(int),
3524 .proc_handler
= &proc_dointvec
,
3527 .ctl_name
= NET_IPV6_ACCEPT_RA
,
3528 .procname
= "accept_ra",
3529 .data
= &ipv6_devconf
.accept_ra
,
3530 .maxlen
= sizeof(int),
3532 .proc_handler
= &proc_dointvec
,
3535 .ctl_name
= NET_IPV6_ACCEPT_REDIRECTS
,
3536 .procname
= "accept_redirects",
3537 .data
= &ipv6_devconf
.accept_redirects
,
3538 .maxlen
= sizeof(int),
3540 .proc_handler
= &proc_dointvec
,
3543 .ctl_name
= NET_IPV6_AUTOCONF
,
3544 .procname
= "autoconf",
3545 .data
= &ipv6_devconf
.autoconf
,
3546 .maxlen
= sizeof(int),
3548 .proc_handler
= &proc_dointvec
,
3551 .ctl_name
= NET_IPV6_DAD_TRANSMITS
,
3552 .procname
= "dad_transmits",
3553 .data
= &ipv6_devconf
.dad_transmits
,
3554 .maxlen
= sizeof(int),
3556 .proc_handler
= &proc_dointvec
,
3559 .ctl_name
= NET_IPV6_RTR_SOLICITS
,
3560 .procname
= "router_solicitations",
3561 .data
= &ipv6_devconf
.rtr_solicits
,
3562 .maxlen
= sizeof(int),
3564 .proc_handler
= &proc_dointvec
,
3567 .ctl_name
= NET_IPV6_RTR_SOLICIT_INTERVAL
,
3568 .procname
= "router_solicitation_interval",
3569 .data
= &ipv6_devconf
.rtr_solicit_interval
,
3570 .maxlen
= sizeof(int),
3572 .proc_handler
= &proc_dointvec_jiffies
,
3573 .strategy
= &sysctl_jiffies
,
3576 .ctl_name
= NET_IPV6_RTR_SOLICIT_DELAY
,
3577 .procname
= "router_solicitation_delay",
3578 .data
= &ipv6_devconf
.rtr_solicit_delay
,
3579 .maxlen
= sizeof(int),
3581 .proc_handler
= &proc_dointvec_jiffies
,
3582 .strategy
= &sysctl_jiffies
,
3585 .ctl_name
= NET_IPV6_FORCE_MLD_VERSION
,
3586 .procname
= "force_mld_version",
3587 .data
= &ipv6_devconf
.force_mld_version
,
3588 .maxlen
= sizeof(int),
3590 .proc_handler
= &proc_dointvec
,
3592 #ifdef CONFIG_IPV6_PRIVACY
3594 .ctl_name
= NET_IPV6_USE_TEMPADDR
,
3595 .procname
= "use_tempaddr",
3596 .data
= &ipv6_devconf
.use_tempaddr
,
3597 .maxlen
= sizeof(int),
3599 .proc_handler
= &proc_dointvec
,
3602 .ctl_name
= NET_IPV6_TEMP_VALID_LFT
,
3603 .procname
= "temp_valid_lft",
3604 .data
= &ipv6_devconf
.temp_valid_lft
,
3605 .maxlen
= sizeof(int),
3607 .proc_handler
= &proc_dointvec
,
3610 .ctl_name
= NET_IPV6_TEMP_PREFERED_LFT
,
3611 .procname
= "temp_prefered_lft",
3612 .data
= &ipv6_devconf
.temp_prefered_lft
,
3613 .maxlen
= sizeof(int),
3615 .proc_handler
= &proc_dointvec
,
3618 .ctl_name
= NET_IPV6_REGEN_MAX_RETRY
,
3619 .procname
= "regen_max_retry",
3620 .data
= &ipv6_devconf
.regen_max_retry
,
3621 .maxlen
= sizeof(int),
3623 .proc_handler
= &proc_dointvec
,
3626 .ctl_name
= NET_IPV6_MAX_DESYNC_FACTOR
,
3627 .procname
= "max_desync_factor",
3628 .data
= &ipv6_devconf
.max_desync_factor
,
3629 .maxlen
= sizeof(int),
3631 .proc_handler
= &proc_dointvec
,
3635 .ctl_name
= NET_IPV6_MAX_ADDRESSES
,
3636 .procname
= "max_addresses",
3637 .data
= &ipv6_devconf
.max_addresses
,
3638 .maxlen
= sizeof(int),
3640 .proc_handler
= &proc_dointvec
,
3643 .ctl_name
= NET_IPV6_ACCEPT_RA_DEFRTR
,
3644 .procname
= "accept_ra_defrtr",
3645 .data
= &ipv6_devconf
.accept_ra_defrtr
,
3646 .maxlen
= sizeof(int),
3648 .proc_handler
= &proc_dointvec
,
3651 .ctl_name
= NET_IPV6_ACCEPT_RA_PINFO
,
3652 .procname
= "accept_ra_pinfo",
3653 .data
= &ipv6_devconf
.accept_ra_pinfo
,
3654 .maxlen
= sizeof(int),
3656 .proc_handler
= &proc_dointvec
,
3658 #ifdef CONFIG_IPV6_ROUTER_PREF
3660 .ctl_name
= NET_IPV6_ACCEPT_RA_RTR_PREF
,
3661 .procname
= "accept_ra_rtr_pref",
3662 .data
= &ipv6_devconf
.accept_ra_rtr_pref
,
3663 .maxlen
= sizeof(int),
3665 .proc_handler
= &proc_dointvec
,
3668 .ctl_name
= NET_IPV6_RTR_PROBE_INTERVAL
,
3669 .procname
= "router_probe_interval",
3670 .data
= &ipv6_devconf
.rtr_probe_interval
,
3671 .maxlen
= sizeof(int),
3673 .proc_handler
= &proc_dointvec_jiffies
,
3674 .strategy
= &sysctl_jiffies
,
3676 #ifdef CONFIV_IPV6_ROUTE_INFO
3678 .ctl_name
= NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN
,
3679 .procname
= "accept_ra_rt_info_max_plen",
3680 .data
= &ipv6_devconf
.accept_ra_rt_info_max_plen
,
3681 .maxlen
= sizeof(int),
3683 .proc_handler
= &proc_dointvec
,
3688 .ctl_name
= 0, /* sentinel */
3693 .ctl_name
= NET_PROTO_CONF_ALL
,
3696 .child
= addrconf_sysctl
.addrconf_vars
,
3699 .ctl_name
= 0, /* sentinel */
3702 .addrconf_conf_dir
= {
3704 .ctl_name
= NET_IPV6_CONF
,
3707 .child
= addrconf_sysctl
.addrconf_dev
,
3710 .ctl_name
= 0, /* sentinel */
3713 .addrconf_proto_dir
= {
3715 .ctl_name
= NET_IPV6
,
3718 .child
= addrconf_sysctl
.addrconf_conf_dir
,
3721 .ctl_name
= 0, /* sentinel */
3724 .addrconf_root_dir
= {
3726 .ctl_name
= CTL_NET
,
3729 .child
= addrconf_sysctl
.addrconf_proto_dir
,
3732 .ctl_name
= 0, /* sentinel */
3737 static void addrconf_sysctl_register(struct inet6_dev
*idev
, struct ipv6_devconf
*p
)
3740 struct net_device
*dev
= idev
? idev
->dev
: NULL
;
3741 struct addrconf_sysctl_table
*t
;
3742 char *dev_name
= NULL
;
3744 t
= kmalloc(sizeof(*t
), GFP_KERNEL
);
3747 memcpy(t
, &addrconf_sysctl
, sizeof(*t
));
3748 for (i
=0; t
->addrconf_vars
[i
].data
; i
++) {
3749 t
->addrconf_vars
[i
].data
+= (char*)p
- (char*)&ipv6_devconf
;
3750 t
->addrconf_vars
[i
].de
= NULL
;
3751 t
->addrconf_vars
[i
].extra1
= idev
; /* embedded; no ref */
3754 dev_name
= dev
->name
;
3755 t
->addrconf_dev
[0].ctl_name
= dev
->ifindex
;
3757 dev_name
= "default";
3758 t
->addrconf_dev
[0].ctl_name
= NET_PROTO_CONF_DEFAULT
;
3762 * Make a copy of dev_name, because '.procname' is regarded as const
3763 * by sysctl and we wouldn't want anyone to change it under our feet
3764 * (see SIOCSIFNAME).
3766 dev_name
= kstrdup(dev_name
, GFP_KERNEL
);
3770 t
->addrconf_dev
[0].procname
= dev_name
;
3772 t
->addrconf_dev
[0].child
= t
->addrconf_vars
;
3773 t
->addrconf_dev
[0].de
= NULL
;
3774 t
->addrconf_conf_dir
[0].child
= t
->addrconf_dev
;
3775 t
->addrconf_conf_dir
[0].de
= NULL
;
3776 t
->addrconf_proto_dir
[0].child
= t
->addrconf_conf_dir
;
3777 t
->addrconf_proto_dir
[0].de
= NULL
;
3778 t
->addrconf_root_dir
[0].child
= t
->addrconf_proto_dir
;
3779 t
->addrconf_root_dir
[0].de
= NULL
;
3781 t
->sysctl_header
= register_sysctl_table(t
->addrconf_root_dir
, 0);
3782 if (t
->sysctl_header
== NULL
)
3797 static void addrconf_sysctl_unregister(struct ipv6_devconf
*p
)
3800 struct addrconf_sysctl_table
*t
= p
->sysctl
;
3802 unregister_sysctl_table(t
->sysctl_header
);
3803 kfree(t
->addrconf_dev
[0].procname
);
3815 int register_inet6addr_notifier(struct notifier_block
*nb
)
3817 return atomic_notifier_chain_register(&inet6addr_chain
, nb
);
3820 int unregister_inet6addr_notifier(struct notifier_block
*nb
)
3822 return atomic_notifier_chain_unregister(&inet6addr_chain
,nb
);
3826 * Init / cleanup code
3829 int __init
addrconf_init(void)
3833 /* The addrconf netdev notifier requires that loopback_dev
3834 * has it's ipv6 private information allocated and setup
3835 * before it can bring up and give link-local addresses
3836 * to other devices which are up.
3838 * Unfortunately, loopback_dev is not necessarily the first
3839 * entry in the global dev_base list of net devices. In fact,
3840 * it is likely to be the very last entry on that list.
3841 * So this causes the notifier registry below to try and
3842 * give link-local addresses to all devices besides loopback_dev
3843 * first, then loopback_dev, which cases all the non-loopback_dev
3844 * devices to fail to get a link-local address.
3846 * So, as a temporary fix, allocate the ipv6 structure for
3847 * loopback_dev first by hand.
3848 * Longer term, all of the dependencies ipv6 has upon the loopback
3849 * device and it being up should be removed.
3852 if (!ipv6_add_dev(&loopback_dev
))
3858 ip6_null_entry
.rt6i_idev
= in6_dev_get(&loopback_dev
);
3860 register_netdevice_notifier(&ipv6_dev_notf
);
3863 rtnetlink_links
[PF_INET6
] = inet6_rtnetlink_table
;
3864 #ifdef CONFIG_SYSCTL
3865 addrconf_sysctl
.sysctl_header
=
3866 register_sysctl_table(addrconf_sysctl
.addrconf_root_dir
, 0);
3867 addrconf_sysctl_register(NULL
, &ipv6_devconf_dflt
);
3873 void __exit
addrconf_cleanup(void)
3875 struct net_device
*dev
;
3876 struct inet6_dev
*idev
;
3877 struct inet6_ifaddr
*ifa
;
3880 unregister_netdevice_notifier(&ipv6_dev_notf
);
3882 rtnetlink_links
[PF_INET6
] = NULL
;
3883 #ifdef CONFIG_SYSCTL
3884 addrconf_sysctl_unregister(&ipv6_devconf_dflt
);
3885 addrconf_sysctl_unregister(&ipv6_devconf
);
3894 for (dev
=dev_base
; dev
; dev
=dev
->next
) {
3895 if ((idev
= __in6_dev_get(dev
)) == NULL
)
3897 addrconf_ifdown(dev
, 1);
3899 addrconf_ifdown(&loopback_dev
, 2);
3905 write_lock_bh(&addrconf_hash_lock
);
3906 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
3907 for (ifa
=inet6_addr_lst
[i
]; ifa
; ) {
3908 struct inet6_ifaddr
*bifa
;
3911 ifa
= ifa
->lst_next
;
3912 printk(KERN_DEBUG
"bug: IPv6 address leakage detected: ifa=%p\n", bifa
);
3913 /* Do not free it; something is wrong.
3914 Now we can investigate it with debugger.
3918 write_unlock_bh(&addrconf_hash_lock
);
3920 del_timer(&addr_chk_timer
);
3924 #ifdef CONFIG_PROC_FS
3925 proc_net_remove("if_inet6");