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
;
517 * Each device address list is sorted in order of scope -
518 * global before linklocal.
520 for (ifap
= &idev
->addr_list
; (ifa
= *ifap
) != NULL
;
521 ifap
= &ifa
->if_next
) {
522 if (ifp
->scope
> ifa
->scope
)
526 ifp
->if_next
= *ifap
;
530 /* On success it returns ifp with increased reference count */
532 static struct inet6_ifaddr
*
533 ipv6_add_addr(struct inet6_dev
*idev
, const struct in6_addr
*addr
, int pfxlen
,
534 int scope
, u32 flags
)
536 struct inet6_ifaddr
*ifa
= NULL
;
541 read_lock_bh(&addrconf_lock
);
543 err
= -ENODEV
; /*XXX*/
547 write_lock(&addrconf_hash_lock
);
549 /* Ignore adding duplicate addresses on an interface */
550 if (ipv6_chk_same_addr(addr
, idev
->dev
)) {
551 ADBG(("ipv6_add_addr: already assigned\n"));
556 ifa
= kzalloc(sizeof(struct inet6_ifaddr
), GFP_ATOMIC
);
559 ADBG(("ipv6_add_addr: malloc failed\n"));
564 rt
= addrconf_dst_alloc(idev
, addr
, 0);
570 ipv6_addr_copy(&ifa
->addr
, addr
);
572 spin_lock_init(&ifa
->lock
);
573 init_timer(&ifa
->timer
);
574 ifa
->timer
.data
= (unsigned long) ifa
;
576 ifa
->prefix_len
= pfxlen
;
577 ifa
->flags
= flags
| IFA_F_TENTATIVE
;
578 ifa
->cstamp
= ifa
->tstamp
= jiffies
;
585 /* Add to big hash table */
586 hash
= ipv6_addr_hash(addr
);
588 ifa
->lst_next
= inet6_addr_lst
[hash
];
589 inet6_addr_lst
[hash
] = ifa
;
591 write_unlock(&addrconf_hash_lock
);
593 write_lock(&idev
->lock
);
594 /* Add to inet6_dev unicast addr list. */
595 ipv6_link_dev_addr(idev
, ifa
);
597 #ifdef CONFIG_IPV6_PRIVACY
598 if (ifa
->flags
&IFA_F_TEMPORARY
) {
599 ifa
->tmp_next
= idev
->tempaddr_list
;
600 idev
->tempaddr_list
= ifa
;
608 write_unlock(&idev
->lock
);
610 read_unlock_bh(&addrconf_lock
);
612 if (likely(err
== 0))
613 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_UP
, ifa
);
621 write_unlock(&addrconf_hash_lock
);
625 /* This function wants to get referenced ifp and releases it before return */
627 static void ipv6_del_addr(struct inet6_ifaddr
*ifp
)
629 struct inet6_ifaddr
*ifa
, **ifap
;
630 struct inet6_dev
*idev
= ifp
->idev
;
632 int deleted
= 0, onlink
= 0;
633 unsigned long expires
= jiffies
;
635 hash
= ipv6_addr_hash(&ifp
->addr
);
639 write_lock_bh(&addrconf_hash_lock
);
640 for (ifap
= &inet6_addr_lst
[hash
]; (ifa
=*ifap
) != NULL
;
641 ifap
= &ifa
->lst_next
) {
643 *ifap
= ifa
->lst_next
;
645 ifa
->lst_next
= NULL
;
649 write_unlock_bh(&addrconf_hash_lock
);
651 write_lock_bh(&idev
->lock
);
652 #ifdef CONFIG_IPV6_PRIVACY
653 if (ifp
->flags
&IFA_F_TEMPORARY
) {
654 for (ifap
= &idev
->tempaddr_list
; (ifa
=*ifap
) != NULL
;
655 ifap
= &ifa
->tmp_next
) {
657 *ifap
= ifa
->tmp_next
;
659 in6_ifa_put(ifp
->ifpub
);
663 ifa
->tmp_next
= NULL
;
670 for (ifap
= &idev
->addr_list
; (ifa
=*ifap
) != NULL
;) {
672 *ifap
= ifa
->if_next
;
675 if (!(ifp
->flags
& IFA_F_PERMANENT
) || onlink
> 0)
679 } else if (ifp
->flags
& IFA_F_PERMANENT
) {
680 if (ipv6_prefix_equal(&ifa
->addr
, &ifp
->addr
,
682 if (ifa
->flags
& IFA_F_PERMANENT
) {
687 unsigned long lifetime
;
692 spin_lock(&ifa
->lock
);
693 lifetime
= min_t(unsigned long,
694 ifa
->valid_lft
, 0x7fffffffUL
/HZ
);
695 if (time_before(expires
,
696 ifa
->tstamp
+ lifetime
* HZ
))
697 expires
= ifa
->tstamp
+ lifetime
* HZ
;
698 spin_unlock(&ifa
->lock
);
702 ifap
= &ifa
->if_next
;
704 write_unlock_bh(&idev
->lock
);
706 ipv6_ifa_notify(RTM_DELADDR
, ifp
);
708 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_DOWN
, ifp
);
710 addrconf_del_timer(ifp
);
713 * Purge or update corresponding prefix
715 * 1) we don't purge prefix here if address was not permanent.
716 * prefix is managed by its own lifetime.
717 * 2) if there're no addresses, delete prefix.
718 * 3) if there're still other permanent address(es),
719 * corresponding prefix is still permanent.
720 * 4) otherwise, update prefix lifetime to the
721 * longest valid lifetime among the corresponding
722 * addresses on the device.
723 * Note: subsequent RA will update lifetime.
727 if ((ifp
->flags
& IFA_F_PERMANENT
) && onlink
< 1) {
728 struct in6_addr prefix
;
731 ipv6_addr_prefix(&prefix
, &ifp
->addr
, ifp
->prefix_len
);
732 rt
= rt6_lookup(&prefix
, NULL
, ifp
->idev
->dev
->ifindex
, 1);
734 if (rt
&& ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0)) {
736 ip6_del_rt(rt
, NULL
, NULL
, NULL
);
738 } else if (!(rt
->rt6i_flags
& RTF_EXPIRES
)) {
739 rt
->rt6i_expires
= expires
;
740 rt
->rt6i_flags
|= RTF_EXPIRES
;
743 dst_release(&rt
->u
.dst
);
749 #ifdef CONFIG_IPV6_PRIVACY
750 static int ipv6_create_tempaddr(struct inet6_ifaddr
*ifp
, struct inet6_ifaddr
*ift
)
752 struct inet6_dev
*idev
= ifp
->idev
;
753 struct in6_addr addr
, *tmpaddr
;
754 unsigned long tmp_prefered_lft
, tmp_valid_lft
, tmp_cstamp
, tmp_tstamp
;
759 write_lock(&idev
->lock
);
761 spin_lock_bh(&ift
->lock
);
762 memcpy(&addr
.s6_addr
[8], &ift
->addr
.s6_addr
[8], 8);
763 spin_unlock_bh(&ift
->lock
);
770 if (idev
->cnf
.use_tempaddr
<= 0) {
771 write_unlock(&idev
->lock
);
773 "ipv6_create_tempaddr(): use_tempaddr is disabled.\n");
778 spin_lock_bh(&ifp
->lock
);
779 if (ifp
->regen_count
++ >= idev
->cnf
.regen_max_retry
) {
780 idev
->cnf
.use_tempaddr
= -1; /*XXX*/
781 spin_unlock_bh(&ifp
->lock
);
782 write_unlock(&idev
->lock
);
784 "ipv6_create_tempaddr(): regeneration time exceeded. disabled temporary address support.\n");
790 memcpy(addr
.s6_addr
, ifp
->addr
.s6_addr
, 8);
791 if (__ipv6_try_regen_rndid(idev
, tmpaddr
) < 0) {
792 spin_unlock_bh(&ifp
->lock
);
793 write_unlock(&idev
->lock
);
795 "ipv6_create_tempaddr(): regeneration of randomized interface id failed.\n");
801 memcpy(&addr
.s6_addr
[8], idev
->rndid
, 8);
802 tmp_valid_lft
= min_t(__u32
,
804 idev
->cnf
.temp_valid_lft
);
805 tmp_prefered_lft
= min_t(__u32
,
807 idev
->cnf
.temp_prefered_lft
- desync_factor
/ HZ
);
808 tmp_plen
= ifp
->prefix_len
;
809 max_addresses
= idev
->cnf
.max_addresses
;
810 tmp_cstamp
= ifp
->cstamp
;
811 tmp_tstamp
= ifp
->tstamp
;
812 spin_unlock_bh(&ifp
->lock
);
814 write_unlock(&idev
->lock
);
815 ift
= !max_addresses
||
816 ipv6_count_addresses(idev
) < max_addresses
?
817 ipv6_add_addr(idev
, &addr
, tmp_plen
,
818 ipv6_addr_type(&addr
)&IPV6_ADDR_SCOPE_MASK
, IFA_F_TEMPORARY
) : NULL
;
819 if (!ift
|| IS_ERR(ift
)) {
823 "ipv6_create_tempaddr(): retry temporary address regeneration.\n");
825 write_lock(&idev
->lock
);
829 spin_lock_bh(&ift
->lock
);
831 ift
->valid_lft
= tmp_valid_lft
;
832 ift
->prefered_lft
= tmp_prefered_lft
;
833 ift
->cstamp
= tmp_cstamp
;
834 ift
->tstamp
= tmp_tstamp
;
835 spin_unlock_bh(&ift
->lock
);
837 addrconf_dad_start(ift
, 0);
846 * Choose an appropriate source address (RFC3484)
848 struct ipv6_saddr_score
{
856 #define IPV6_SADDR_SCORE_LOCAL 0x0001
857 #define IPV6_SADDR_SCORE_PREFERRED 0x0004
858 #define IPV6_SADDR_SCORE_HOA 0x0008
859 #define IPV6_SADDR_SCORE_OIF 0x0010
860 #define IPV6_SADDR_SCORE_LABEL 0x0020
861 #define IPV6_SADDR_SCORE_PRIVACY 0x0040
863 static int inline ipv6_saddr_preferred(int type
)
865 if (type
& (IPV6_ADDR_MAPPED
|IPV6_ADDR_COMPATv4
|
866 IPV6_ADDR_LOOPBACK
|IPV6_ADDR_RESERVED
))
871 /* static matching label */
872 static int inline ipv6_saddr_label(const struct in6_addr
*addr
, int type
)
875 * prefix (longest match) label
876 * -----------------------------
885 if (type
& IPV6_ADDR_LOOPBACK
)
887 else if (type
& IPV6_ADDR_COMPATv4
)
889 else if (type
& IPV6_ADDR_MAPPED
)
891 else if (addr
->s6_addr32
[0] == htonl(0x20010000))
893 else if (addr
->s6_addr16
[0] == htons(0x2002))
895 else if ((addr
->s6_addr
[0] & 0xfe) == 0xfc)
900 int ipv6_dev_get_saddr(struct net_device
*daddr_dev
,
901 struct in6_addr
*daddr
, struct in6_addr
*saddr
)
903 struct ipv6_saddr_score hiscore
;
904 struct inet6_ifaddr
*ifa_result
= NULL
;
905 int daddr_type
= __ipv6_addr_type(daddr
);
906 int daddr_scope
= __ipv6_addr_src_scope(daddr_type
);
907 u32 daddr_label
= ipv6_saddr_label(daddr
, daddr_type
);
908 struct net_device
*dev
;
910 memset(&hiscore
, 0, sizeof(hiscore
));
912 read_lock(&dev_base_lock
);
913 read_lock(&addrconf_lock
);
915 for (dev
= dev_base
; dev
; dev
=dev
->next
) {
916 struct inet6_dev
*idev
;
917 struct inet6_ifaddr
*ifa
;
919 /* Rule 0: Candidate Source Address (section 4)
920 * - multicast and link-local destination address,
921 * the set of candidate source address MUST only
922 * include addresses assigned to interfaces
923 * belonging to the same link as the outgoing
925 * (- For site-local destination addresses, the
926 * set of candidate source addresses MUST only
927 * include addresses assigned to interfaces
928 * belonging to the same site as the outgoing
931 if ((daddr_type
& IPV6_ADDR_MULTICAST
||
932 daddr_scope
<= IPV6_ADDR_SCOPE_LINKLOCAL
) &&
933 daddr_dev
&& dev
!= daddr_dev
)
936 idev
= __in6_dev_get(dev
);
940 read_lock_bh(&idev
->lock
);
941 for (ifa
= idev
->addr_list
; ifa
; ifa
= ifa
->if_next
) {
942 struct ipv6_saddr_score score
;
944 score
.addr_type
= __ipv6_addr_type(&ifa
->addr
);
947 * - Tentative Address (RFC2462 section 5.4)
948 * - A tentative address is not considered
949 * "assigned to an interface" in the traditional
951 * - Candidate Source Address (section 4)
952 * - In any case, anycast addresses, multicast
953 * addresses, and the unspecified address MUST
954 * NOT be included in a candidate set.
956 if (ifa
->flags
& IFA_F_TENTATIVE
)
958 if (unlikely(score
.addr_type
== IPV6_ADDR_ANY
||
959 score
.addr_type
& IPV6_ADDR_MULTICAST
)) {
960 LIMIT_NETDEBUG(KERN_DEBUG
961 "ADDRCONF: unspecified / multicast address"
962 "assigned as unicast address on %s",
972 if (ifa_result
== NULL
) {
973 /* record it if the first available entry */
977 /* Rule 1: Prefer same address */
978 if (hiscore
.rule
< 1) {
979 if (ipv6_addr_equal(&ifa_result
->addr
, daddr
))
980 hiscore
.attrs
|= IPV6_SADDR_SCORE_LOCAL
;
983 if (ipv6_addr_equal(&ifa
->addr
, daddr
)) {
984 score
.attrs
|= IPV6_SADDR_SCORE_LOCAL
;
985 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_LOCAL
)) {
990 if (hiscore
.attrs
& IPV6_SADDR_SCORE_LOCAL
)
994 /* Rule 2: Prefer appropriate scope */
995 if (hiscore
.rule
< 2) {
996 hiscore
.scope
= __ipv6_addr_src_scope(hiscore
.addr_type
);
999 score
.scope
= __ipv6_addr_src_scope(score
.addr_type
);
1000 if (hiscore
.scope
< score
.scope
) {
1001 if (hiscore
.scope
< daddr_scope
) {
1006 } else if (score
.scope
< hiscore
.scope
) {
1007 if (score
.scope
< daddr_scope
)
1008 break; /* addresses sorted by scope */
1015 /* Rule 3: Avoid deprecated address */
1016 if (hiscore
.rule
< 3) {
1017 if (ipv6_saddr_preferred(hiscore
.addr_type
) ||
1018 !(ifa_result
->flags
& IFA_F_DEPRECATED
))
1019 hiscore
.attrs
|= IPV6_SADDR_SCORE_PREFERRED
;
1022 if (ipv6_saddr_preferred(score
.addr_type
) ||
1023 !(ifa
->flags
& IFA_F_DEPRECATED
)) {
1024 score
.attrs
|= IPV6_SADDR_SCORE_PREFERRED
;
1025 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_PREFERRED
)) {
1030 if (hiscore
.attrs
& IPV6_SADDR_SCORE_PREFERRED
)
1034 /* Rule 4: Prefer home address -- not implemented yet */
1035 if (hiscore
.rule
< 4)
1038 /* Rule 5: Prefer outgoing interface */
1039 if (hiscore
.rule
< 5) {
1040 if (daddr_dev
== NULL
||
1041 daddr_dev
== ifa_result
->idev
->dev
)
1042 hiscore
.attrs
|= IPV6_SADDR_SCORE_OIF
;
1045 if (daddr_dev
== NULL
||
1046 daddr_dev
== ifa
->idev
->dev
) {
1047 score
.attrs
|= IPV6_SADDR_SCORE_OIF
;
1048 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_OIF
)) {
1053 if (hiscore
.attrs
& IPV6_SADDR_SCORE_OIF
)
1057 /* Rule 6: Prefer matching label */
1058 if (hiscore
.rule
< 6) {
1059 if (ipv6_saddr_label(&ifa_result
->addr
, hiscore
.addr_type
) == daddr_label
)
1060 hiscore
.attrs
|= IPV6_SADDR_SCORE_LABEL
;
1063 if (ipv6_saddr_label(&ifa
->addr
, score
.addr_type
) == daddr_label
) {
1064 score
.attrs
|= IPV6_SADDR_SCORE_LABEL
;
1065 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_LABEL
)) {
1070 if (hiscore
.attrs
& IPV6_SADDR_SCORE_LABEL
)
1074 #ifdef CONFIG_IPV6_PRIVACY
1075 /* Rule 7: Prefer public address
1076 * Note: prefer temprary address if use_tempaddr >= 2
1078 if (hiscore
.rule
< 7) {
1079 if ((!(ifa_result
->flags
& IFA_F_TEMPORARY
)) ^
1080 (ifa_result
->idev
->cnf
.use_tempaddr
>= 2))
1081 hiscore
.attrs
|= IPV6_SADDR_SCORE_PRIVACY
;
1084 if ((!(ifa
->flags
& IFA_F_TEMPORARY
)) ^
1085 (ifa
->idev
->cnf
.use_tempaddr
>= 2)) {
1086 score
.attrs
|= IPV6_SADDR_SCORE_PRIVACY
;
1087 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_PRIVACY
)) {
1092 if (hiscore
.attrs
& IPV6_SADDR_SCORE_PRIVACY
)
1096 if (hiscore
.rule
< 7)
1099 /* Rule 8: Use longest matching prefix */
1100 if (hiscore
.rule
< 8) {
1101 hiscore
.matchlen
= ipv6_addr_diff(&ifa_result
->addr
, daddr
);
1104 score
.matchlen
= ipv6_addr_diff(&ifa
->addr
, daddr
);
1105 if (score
.matchlen
> hiscore
.matchlen
) {
1110 else if (score
.matchlen
< hiscore
.matchlen
)
1114 /* Final Rule: choose first available one */
1118 in6_ifa_put(ifa_result
);
1123 read_unlock_bh(&idev
->lock
);
1125 read_unlock(&addrconf_lock
);
1126 read_unlock(&dev_base_lock
);
1129 return -EADDRNOTAVAIL
;
1131 ipv6_addr_copy(saddr
, &ifa_result
->addr
);
1132 in6_ifa_put(ifa_result
);
1137 int ipv6_get_saddr(struct dst_entry
*dst
,
1138 struct in6_addr
*daddr
, struct in6_addr
*saddr
)
1140 return ipv6_dev_get_saddr(dst
? ((struct rt6_info
*)dst
)->rt6i_idev
->dev
: NULL
, daddr
, saddr
);
1144 int ipv6_get_lladdr(struct net_device
*dev
, struct in6_addr
*addr
)
1146 struct inet6_dev
*idev
;
1147 int err
= -EADDRNOTAVAIL
;
1149 read_lock(&addrconf_lock
);
1150 if ((idev
= __in6_dev_get(dev
)) != NULL
) {
1151 struct inet6_ifaddr
*ifp
;
1153 read_lock_bh(&idev
->lock
);
1154 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1155 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1156 ipv6_addr_copy(addr
, &ifp
->addr
);
1161 read_unlock_bh(&idev
->lock
);
1163 read_unlock(&addrconf_lock
);
1167 static int ipv6_count_addresses(struct inet6_dev
*idev
)
1170 struct inet6_ifaddr
*ifp
;
1172 read_lock_bh(&idev
->lock
);
1173 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
)
1175 read_unlock_bh(&idev
->lock
);
1179 int ipv6_chk_addr(struct in6_addr
*addr
, struct net_device
*dev
, int strict
)
1181 struct inet6_ifaddr
* ifp
;
1182 u8 hash
= ipv6_addr_hash(addr
);
1184 read_lock_bh(&addrconf_hash_lock
);
1185 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1186 if (ipv6_addr_equal(&ifp
->addr
, addr
) &&
1187 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1188 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1189 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
))
1193 read_unlock_bh(&addrconf_hash_lock
);
1198 int ipv6_chk_same_addr(const struct in6_addr
*addr
, struct net_device
*dev
)
1200 struct inet6_ifaddr
* ifp
;
1201 u8 hash
= ipv6_addr_hash(addr
);
1203 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1204 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1205 if (dev
== NULL
|| ifp
->idev
->dev
== dev
)
1212 struct inet6_ifaddr
* ipv6_get_ifaddr(struct in6_addr
*addr
, struct net_device
*dev
, int strict
)
1214 struct inet6_ifaddr
* ifp
;
1215 u8 hash
= ipv6_addr_hash(addr
);
1217 read_lock_bh(&addrconf_hash_lock
);
1218 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1219 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1220 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1221 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
)) {
1227 read_unlock_bh(&addrconf_hash_lock
);
1232 int ipv6_rcv_saddr_equal(const struct sock
*sk
, const struct sock
*sk2
)
1234 const struct in6_addr
*sk_rcv_saddr6
= &inet6_sk(sk
)->rcv_saddr
;
1235 const struct in6_addr
*sk2_rcv_saddr6
= inet6_rcv_saddr(sk2
);
1236 u32 sk_rcv_saddr
= inet_sk(sk
)->rcv_saddr
;
1237 u32 sk2_rcv_saddr
= inet_rcv_saddr(sk2
);
1238 int sk_ipv6only
= ipv6_only_sock(sk
);
1239 int sk2_ipv6only
= inet_v6_ipv6only(sk2
);
1240 int addr_type
= ipv6_addr_type(sk_rcv_saddr6
);
1241 int addr_type2
= sk2_rcv_saddr6
? ipv6_addr_type(sk2_rcv_saddr6
) : IPV6_ADDR_MAPPED
;
1243 if (!sk2_rcv_saddr
&& !sk_ipv6only
)
1246 if (addr_type2
== IPV6_ADDR_ANY
&&
1247 !(sk2_ipv6only
&& addr_type
== IPV6_ADDR_MAPPED
))
1250 if (addr_type
== IPV6_ADDR_ANY
&&
1251 !(sk_ipv6only
&& addr_type2
== IPV6_ADDR_MAPPED
))
1254 if (sk2_rcv_saddr6
&&
1255 ipv6_addr_equal(sk_rcv_saddr6
, sk2_rcv_saddr6
))
1258 if (addr_type
== IPV6_ADDR_MAPPED
&&
1260 (!sk2_rcv_saddr
|| !sk_rcv_saddr
|| sk_rcv_saddr
== sk2_rcv_saddr
))
1266 /* Gets referenced address, destroys ifaddr */
1268 static void addrconf_dad_stop(struct inet6_ifaddr
*ifp
)
1270 if (ifp
->flags
&IFA_F_PERMANENT
) {
1271 spin_lock_bh(&ifp
->lock
);
1272 addrconf_del_timer(ifp
);
1273 ifp
->flags
|= IFA_F_TENTATIVE
;
1274 spin_unlock_bh(&ifp
->lock
);
1276 #ifdef CONFIG_IPV6_PRIVACY
1277 } else if (ifp
->flags
&IFA_F_TEMPORARY
) {
1278 struct inet6_ifaddr
*ifpub
;
1279 spin_lock_bh(&ifp
->lock
);
1282 in6_ifa_hold(ifpub
);
1283 spin_unlock_bh(&ifp
->lock
);
1284 ipv6_create_tempaddr(ifpub
, ifp
);
1287 spin_unlock_bh(&ifp
->lock
);
1295 void addrconf_dad_failure(struct inet6_ifaddr
*ifp
)
1297 if (net_ratelimit())
1298 printk(KERN_INFO
"%s: duplicate address detected!\n", ifp
->idev
->dev
->name
);
1299 addrconf_dad_stop(ifp
);
1302 /* Join to solicited addr multicast group. */
1304 void addrconf_join_solict(struct net_device
*dev
, struct in6_addr
*addr
)
1306 struct in6_addr maddr
;
1308 if (dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1311 addrconf_addr_solict_mult(addr
, &maddr
);
1312 ipv6_dev_mc_inc(dev
, &maddr
);
1315 void addrconf_leave_solict(struct inet6_dev
*idev
, struct in6_addr
*addr
)
1317 struct in6_addr maddr
;
1319 if (idev
->dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1322 addrconf_addr_solict_mult(addr
, &maddr
);
1323 __ipv6_dev_mc_dec(idev
, &maddr
);
1326 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
)
1328 struct in6_addr addr
;
1329 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1330 if (ipv6_addr_any(&addr
))
1332 ipv6_dev_ac_inc(ifp
->idev
->dev
, &addr
);
1335 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
)
1337 struct in6_addr addr
;
1338 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1339 if (ipv6_addr_any(&addr
))
1341 __ipv6_dev_ac_dec(ifp
->idev
, &addr
);
1344 static int addrconf_ifid_eui48(u8
*eui
, struct net_device
*dev
)
1346 if (dev
->addr_len
!= ETH_ALEN
)
1348 memcpy(eui
, dev
->dev_addr
, 3);
1349 memcpy(eui
+ 5, dev
->dev_addr
+ 3, 3);
1352 * The zSeries OSA network cards can be shared among various
1353 * OS instances, but the OSA cards have only one MAC address.
1354 * This leads to duplicate address conflicts in conjunction
1355 * with IPv6 if more than one instance uses the same card.
1357 * The driver for these cards can deliver a unique 16-bit
1358 * identifier for each instance sharing the same card. It is
1359 * placed instead of 0xFFFE in the interface identifier. The
1360 * "u" bit of the interface identifier is not inverted in this
1361 * case. Hence the resulting interface identifier has local
1362 * scope according to RFC2373.
1365 eui
[3] = (dev
->dev_id
>> 8) & 0xFF;
1366 eui
[4] = dev
->dev_id
& 0xFF;
1375 static int addrconf_ifid_arcnet(u8
*eui
, struct net_device
*dev
)
1377 /* XXX: inherit EUI-64 from other interface -- yoshfuji */
1378 if (dev
->addr_len
!= ARCNET_ALEN
)
1381 eui
[7] = *(u8
*)dev
->dev_addr
;
1385 static int addrconf_ifid_infiniband(u8
*eui
, struct net_device
*dev
)
1387 if (dev
->addr_len
!= INFINIBAND_ALEN
)
1389 memcpy(eui
, dev
->dev_addr
+ 12, 8);
1394 static int ipv6_generate_eui64(u8
*eui
, struct net_device
*dev
)
1396 switch (dev
->type
) {
1399 case ARPHRD_IEEE802_TR
:
1400 return addrconf_ifid_eui48(eui
, dev
);
1402 return addrconf_ifid_arcnet(eui
, dev
);
1403 case ARPHRD_INFINIBAND
:
1404 return addrconf_ifid_infiniband(eui
, dev
);
1409 static int ipv6_inherit_eui64(u8
*eui
, struct inet6_dev
*idev
)
1412 struct inet6_ifaddr
*ifp
;
1414 read_lock_bh(&idev
->lock
);
1415 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1416 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1417 memcpy(eui
, ifp
->addr
.s6_addr
+8, 8);
1422 read_unlock_bh(&idev
->lock
);
1426 #ifdef CONFIG_IPV6_PRIVACY
1427 /* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */
1428 static int __ipv6_regen_rndid(struct inet6_dev
*idev
)
1431 get_random_bytes(idev
->rndid
, sizeof(idev
->rndid
));
1432 idev
->rndid
[0] &= ~0x02;
1435 * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>:
1436 * check if generated address is not inappropriate
1438 * - Reserved subnet anycast (RFC 2526)
1439 * 11111101 11....11 1xxxxxxx
1440 * - ISATAP (draft-ietf-ngtrans-isatap-13.txt) 5.1
1441 * 00-00-5E-FE-xx-xx-xx-xx
1443 * - XXX: already assigned to an address on the device
1445 if (idev
->rndid
[0] == 0xfd &&
1446 (idev
->rndid
[1]&idev
->rndid
[2]&idev
->rndid
[3]&idev
->rndid
[4]&idev
->rndid
[5]&idev
->rndid
[6]) == 0xff &&
1447 (idev
->rndid
[7]&0x80))
1449 if ((idev
->rndid
[0]|idev
->rndid
[1]) == 0) {
1450 if (idev
->rndid
[2] == 0x5e && idev
->rndid
[3] == 0xfe)
1452 if ((idev
->rndid
[2]|idev
->rndid
[3]|idev
->rndid
[4]|idev
->rndid
[5]|idev
->rndid
[6]|idev
->rndid
[7]) == 0x00)
1459 static void ipv6_regen_rndid(unsigned long data
)
1461 struct inet6_dev
*idev
= (struct inet6_dev
*) data
;
1462 unsigned long expires
;
1464 read_lock_bh(&addrconf_lock
);
1465 write_lock_bh(&idev
->lock
);
1470 if (__ipv6_regen_rndid(idev
) < 0)
1474 idev
->cnf
.temp_prefered_lft
* HZ
-
1475 idev
->cnf
.regen_max_retry
* idev
->cnf
.dad_transmits
* idev
->nd_parms
->retrans_time
- desync_factor
;
1476 if (time_before(expires
, jiffies
)) {
1478 "ipv6_regen_rndid(): too short regeneration interval; timer disabled for %s.\n",
1483 if (!mod_timer(&idev
->regen_timer
, expires
))
1487 write_unlock_bh(&idev
->lock
);
1488 read_unlock_bh(&addrconf_lock
);
1492 static int __ipv6_try_regen_rndid(struct inet6_dev
*idev
, struct in6_addr
*tmpaddr
) {
1495 if (tmpaddr
&& memcmp(idev
->rndid
, &tmpaddr
->s6_addr
[8], 8) == 0)
1496 ret
= __ipv6_regen_rndid(idev
);
1506 addrconf_prefix_route(struct in6_addr
*pfx
, int plen
, struct net_device
*dev
,
1507 unsigned long expires
, u32 flags
)
1509 struct in6_rtmsg rtmsg
;
1511 memset(&rtmsg
, 0, sizeof(rtmsg
));
1512 ipv6_addr_copy(&rtmsg
.rtmsg_dst
, pfx
);
1513 rtmsg
.rtmsg_dst_len
= plen
;
1514 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1515 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1516 rtmsg
.rtmsg_info
= expires
;
1517 rtmsg
.rtmsg_flags
= RTF_UP
|flags
;
1518 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1520 /* Prevent useless cloning on PtP SIT.
1521 This thing is done here expecting that the whole
1522 class of non-broadcast devices need not cloning.
1524 if (dev
->type
== ARPHRD_SIT
&& (dev
->flags
&IFF_POINTOPOINT
))
1525 rtmsg
.rtmsg_flags
|= RTF_NONEXTHOP
;
1527 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
);
1530 /* Create "default" multicast route to the interface */
1532 static void addrconf_add_mroute(struct net_device
*dev
)
1534 struct in6_rtmsg rtmsg
;
1536 memset(&rtmsg
, 0, sizeof(rtmsg
));
1537 ipv6_addr_set(&rtmsg
.rtmsg_dst
,
1538 htonl(0xFF000000), 0, 0, 0);
1539 rtmsg
.rtmsg_dst_len
= 8;
1540 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1541 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1542 rtmsg
.rtmsg_flags
= RTF_UP
;
1543 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1544 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
);
1547 static void sit_route_add(struct net_device
*dev
)
1549 struct in6_rtmsg rtmsg
;
1551 memset(&rtmsg
, 0, sizeof(rtmsg
));
1553 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1554 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1556 /* prefix length - 96 bits "::d.d.d.d" */
1557 rtmsg
.rtmsg_dst_len
= 96;
1558 rtmsg
.rtmsg_flags
= RTF_UP
|RTF_NONEXTHOP
;
1559 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1561 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
);
1564 static void addrconf_add_lroute(struct net_device
*dev
)
1566 struct in6_addr addr
;
1568 ipv6_addr_set(&addr
, htonl(0xFE800000), 0, 0, 0);
1569 addrconf_prefix_route(&addr
, 64, dev
, 0, 0);
1572 static struct inet6_dev
*addrconf_add_dev(struct net_device
*dev
)
1574 struct inet6_dev
*idev
;
1578 if ((idev
= ipv6_find_idev(dev
)) == NULL
)
1581 /* Add default multicast route */
1582 addrconf_add_mroute(dev
);
1584 /* Add link local route */
1585 addrconf_add_lroute(dev
);
1589 void addrconf_prefix_rcv(struct net_device
*dev
, u8
*opt
, int len
)
1591 struct prefix_info
*pinfo
;
1595 unsigned long rt_expires
;
1596 struct inet6_dev
*in6_dev
;
1598 pinfo
= (struct prefix_info
*) opt
;
1600 if (len
< sizeof(struct prefix_info
)) {
1601 ADBG(("addrconf: prefix option too short\n"));
1606 * Validation checks ([ADDRCONF], page 19)
1609 addr_type
= ipv6_addr_type(&pinfo
->prefix
);
1611 if (addr_type
& (IPV6_ADDR_MULTICAST
|IPV6_ADDR_LINKLOCAL
))
1614 valid_lft
= ntohl(pinfo
->valid
);
1615 prefered_lft
= ntohl(pinfo
->prefered
);
1617 if (prefered_lft
> valid_lft
) {
1618 if (net_ratelimit())
1619 printk(KERN_WARNING
"addrconf: prefix option has invalid lifetime\n");
1623 in6_dev
= in6_dev_get(dev
);
1625 if (in6_dev
== NULL
) {
1626 if (net_ratelimit())
1627 printk(KERN_DEBUG
"addrconf: device %s not configured\n", dev
->name
);
1632 * Two things going on here:
1633 * 1) Add routes for on-link prefixes
1634 * 2) Configure prefixes with the auto flag set
1637 /* Avoid arithmetic overflow. Really, we could
1638 save rt_expires in seconds, likely valid_lft,
1639 but it would require division in fib gc, that it
1642 if (valid_lft
>= 0x7FFFFFFF/HZ
)
1643 rt_expires
= 0x7FFFFFFF - (0x7FFFFFFF % HZ
);
1645 rt_expires
= valid_lft
* HZ
;
1648 * We convert this (in jiffies) to clock_t later.
1649 * Avoid arithmetic overflow there as well.
1650 * Overflow can happen only if HZ < USER_HZ.
1652 if (HZ
< USER_HZ
&& rt_expires
> 0x7FFFFFFF / USER_HZ
)
1653 rt_expires
= 0x7FFFFFFF / USER_HZ
;
1655 if (pinfo
->onlink
) {
1656 struct rt6_info
*rt
;
1657 rt
= rt6_lookup(&pinfo
->prefix
, NULL
, dev
->ifindex
, 1);
1659 if (rt
&& ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0)) {
1660 if (rt
->rt6i_flags
&RTF_EXPIRES
) {
1661 if (valid_lft
== 0) {
1662 ip6_del_rt(rt
, NULL
, NULL
, NULL
);
1665 rt
->rt6i_expires
= jiffies
+ rt_expires
;
1668 } else if (valid_lft
) {
1669 addrconf_prefix_route(&pinfo
->prefix
, pinfo
->prefix_len
,
1670 dev
, jiffies_to_clock_t(rt_expires
), RTF_ADDRCONF
|RTF_EXPIRES
|RTF_PREFIX_RT
);
1673 dst_release(&rt
->u
.dst
);
1676 /* Try to figure out our local address for this prefix */
1678 if (pinfo
->autoconf
&& in6_dev
->cnf
.autoconf
) {
1679 struct inet6_ifaddr
* ifp
;
1680 struct in6_addr addr
;
1681 int create
= 0, update_lft
= 0;
1683 if (pinfo
->prefix_len
== 64) {
1684 memcpy(&addr
, &pinfo
->prefix
, 8);
1685 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) &&
1686 ipv6_inherit_eui64(addr
.s6_addr
+ 8, in6_dev
)) {
1687 in6_dev_put(in6_dev
);
1692 if (net_ratelimit())
1693 printk(KERN_DEBUG
"IPv6 addrconf: prefix with wrong length %d\n",
1695 in6_dev_put(in6_dev
);
1700 ifp
= ipv6_get_ifaddr(&addr
, dev
, 1);
1702 if (ifp
== NULL
&& valid_lft
) {
1703 int max_addresses
= in6_dev
->cnf
.max_addresses
;
1705 /* Do not allow to create too much of autoconfigured
1706 * addresses; this would be too easy way to crash kernel.
1708 if (!max_addresses
||
1709 ipv6_count_addresses(in6_dev
) < max_addresses
)
1710 ifp
= ipv6_add_addr(in6_dev
, &addr
, pinfo
->prefix_len
,
1711 addr_type
&IPV6_ADDR_SCOPE_MASK
, 0);
1713 if (!ifp
|| IS_ERR(ifp
)) {
1714 in6_dev_put(in6_dev
);
1718 update_lft
= create
= 1;
1719 ifp
->cstamp
= jiffies
;
1720 addrconf_dad_start(ifp
, RTF_ADDRCONF
|RTF_PREFIX_RT
);
1726 #ifdef CONFIG_IPV6_PRIVACY
1727 struct inet6_ifaddr
*ift
;
1731 /* update lifetime (RFC2462 5.5.3 e) */
1732 spin_lock(&ifp
->lock
);
1734 if (ifp
->valid_lft
> (now
- ifp
->tstamp
) / HZ
)
1735 stored_lft
= ifp
->valid_lft
- (now
- ifp
->tstamp
) / HZ
;
1738 if (!update_lft
&& stored_lft
) {
1739 if (valid_lft
> MIN_VALID_LIFETIME
||
1740 valid_lft
> stored_lft
)
1742 else if (stored_lft
<= MIN_VALID_LIFETIME
) {
1743 /* valid_lft <= stored_lft is always true */
1747 valid_lft
= MIN_VALID_LIFETIME
;
1748 if (valid_lft
< prefered_lft
)
1749 prefered_lft
= valid_lft
;
1755 ifp
->valid_lft
= valid_lft
;
1756 ifp
->prefered_lft
= prefered_lft
;
1759 ifp
->flags
&= ~IFA_F_DEPRECATED
;
1760 spin_unlock(&ifp
->lock
);
1762 if (!(flags
&IFA_F_TENTATIVE
))
1763 ipv6_ifa_notify(0, ifp
);
1765 spin_unlock(&ifp
->lock
);
1767 #ifdef CONFIG_IPV6_PRIVACY
1768 read_lock_bh(&in6_dev
->lock
);
1769 /* update all temporary addresses in the list */
1770 for (ift
=in6_dev
->tempaddr_list
; ift
; ift
=ift
->tmp_next
) {
1772 * When adjusting the lifetimes of an existing
1773 * temporary address, only lower the lifetimes.
1774 * Implementations must not increase the
1775 * lifetimes of an existing temporary address
1776 * when processing a Prefix Information Option.
1778 spin_lock(&ift
->lock
);
1780 if (ift
->valid_lft
> valid_lft
&&
1781 ift
->valid_lft
- valid_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1782 ift
->valid_lft
= valid_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1783 if (ift
->prefered_lft
> prefered_lft
&&
1784 ift
->prefered_lft
- prefered_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1785 ift
->prefered_lft
= prefered_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1786 spin_unlock(&ift
->lock
);
1787 if (!(flags
&IFA_F_TENTATIVE
))
1788 ipv6_ifa_notify(0, ift
);
1791 if (create
&& in6_dev
->cnf
.use_tempaddr
> 0) {
1793 * When a new public address is created as described in [ADDRCONF],
1794 * also create a new temporary address.
1796 read_unlock_bh(&in6_dev
->lock
);
1797 ipv6_create_tempaddr(ifp
, NULL
);
1799 read_unlock_bh(&in6_dev
->lock
);
1806 inet6_prefix_notify(RTM_NEWPREFIX
, in6_dev
, pinfo
);
1807 in6_dev_put(in6_dev
);
1811 * Set destination address.
1812 * Special case for SIT interfaces where we create a new "virtual"
1815 int addrconf_set_dstaddr(void __user
*arg
)
1817 struct in6_ifreq ireq
;
1818 struct net_device
*dev
;
1824 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1827 dev
= __dev_get_by_index(ireq
.ifr6_ifindex
);
1833 if (dev
->type
== ARPHRD_SIT
) {
1836 struct ip_tunnel_parm p
;
1838 err
= -EADDRNOTAVAIL
;
1839 if (!(ipv6_addr_type(&ireq
.ifr6_addr
) & IPV6_ADDR_COMPATv4
))
1842 memset(&p
, 0, sizeof(p
));
1843 p
.iph
.daddr
= ireq
.ifr6_addr
.s6_addr32
[3];
1847 p
.iph
.protocol
= IPPROTO_IPV6
;
1849 ifr
.ifr_ifru
.ifru_data
= (void __user
*)&p
;
1851 oldfs
= get_fs(); set_fs(KERNEL_DS
);
1852 err
= dev
->do_ioctl(dev
, &ifr
, SIOCADDTUNNEL
);
1857 if ((dev
= __dev_get_by_name(p
.name
)) == NULL
)
1859 err
= dev_open(dev
);
1869 * Manual configuration of address on an interface
1871 static int inet6_addr_add(int ifindex
, struct in6_addr
*pfx
, int plen
)
1873 struct inet6_ifaddr
*ifp
;
1874 struct inet6_dev
*idev
;
1875 struct net_device
*dev
;
1880 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
1883 if (!(dev
->flags
&IFF_UP
))
1886 if ((idev
= addrconf_add_dev(dev
)) == NULL
)
1889 scope
= ipv6_addr_scope(pfx
);
1891 ifp
= ipv6_add_addr(idev
, pfx
, plen
, scope
, IFA_F_PERMANENT
);
1893 addrconf_dad_start(ifp
, 0);
1898 return PTR_ERR(ifp
);
1901 static int inet6_addr_del(int ifindex
, struct in6_addr
*pfx
, int plen
)
1903 struct inet6_ifaddr
*ifp
;
1904 struct inet6_dev
*idev
;
1905 struct net_device
*dev
;
1907 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
1910 if ((idev
= __in6_dev_get(dev
)) == NULL
)
1913 read_lock_bh(&idev
->lock
);
1914 for (ifp
= idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1915 if (ifp
->prefix_len
== plen
&&
1916 ipv6_addr_equal(pfx
, &ifp
->addr
)) {
1918 read_unlock_bh(&idev
->lock
);
1922 /* If the last address is deleted administratively,
1923 disable IPv6 on this interface.
1925 if (idev
->addr_list
== NULL
)
1926 addrconf_ifdown(idev
->dev
, 1);
1930 read_unlock_bh(&idev
->lock
);
1931 return -EADDRNOTAVAIL
;
1935 int addrconf_add_ifaddr(void __user
*arg
)
1937 struct in6_ifreq ireq
;
1940 if (!capable(CAP_NET_ADMIN
))
1943 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1947 err
= inet6_addr_add(ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
, ireq
.ifr6_prefixlen
);
1952 int addrconf_del_ifaddr(void __user
*arg
)
1954 struct in6_ifreq ireq
;
1957 if (!capable(CAP_NET_ADMIN
))
1960 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1964 err
= inet6_addr_del(ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
, ireq
.ifr6_prefixlen
);
1969 static void sit_add_v4_addrs(struct inet6_dev
*idev
)
1971 struct inet6_ifaddr
* ifp
;
1972 struct in6_addr addr
;
1973 struct net_device
*dev
;
1978 memset(&addr
, 0, sizeof(struct in6_addr
));
1979 memcpy(&addr
.s6_addr32
[3], idev
->dev
->dev_addr
, 4);
1981 if (idev
->dev
->flags
&IFF_POINTOPOINT
) {
1982 addr
.s6_addr32
[0] = htonl(0xfe800000);
1985 scope
= IPV6_ADDR_COMPATv4
;
1988 if (addr
.s6_addr32
[3]) {
1989 ifp
= ipv6_add_addr(idev
, &addr
, 128, scope
, IFA_F_PERMANENT
);
1991 spin_lock_bh(&ifp
->lock
);
1992 ifp
->flags
&= ~IFA_F_TENTATIVE
;
1993 spin_unlock_bh(&ifp
->lock
);
1994 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2000 for (dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
) {
2001 struct in_device
* in_dev
= __in_dev_get_rtnl(dev
);
2002 if (in_dev
&& (dev
->flags
& IFF_UP
)) {
2003 struct in_ifaddr
* ifa
;
2007 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
2010 addr
.s6_addr32
[3] = ifa
->ifa_local
;
2012 if (ifa
->ifa_scope
== RT_SCOPE_LINK
)
2014 if (ifa
->ifa_scope
>= RT_SCOPE_HOST
) {
2015 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2019 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2024 ifp
= ipv6_add_addr(idev
, &addr
, plen
, flag
,
2027 spin_lock_bh(&ifp
->lock
);
2028 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2029 spin_unlock_bh(&ifp
->lock
);
2030 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2038 static void init_loopback(struct net_device
*dev
)
2040 struct inet6_dev
*idev
;
2041 struct inet6_ifaddr
* ifp
;
2047 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2048 printk(KERN_DEBUG
"init loopback: add_dev failed\n");
2052 ifp
= ipv6_add_addr(idev
, &in6addr_loopback
, 128, IFA_HOST
, IFA_F_PERMANENT
);
2054 spin_lock_bh(&ifp
->lock
);
2055 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2056 spin_unlock_bh(&ifp
->lock
);
2057 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2062 static void addrconf_add_linklocal(struct inet6_dev
*idev
, struct in6_addr
*addr
)
2064 struct inet6_ifaddr
* ifp
;
2066 ifp
= ipv6_add_addr(idev
, addr
, 64, IFA_LINK
, IFA_F_PERMANENT
);
2068 addrconf_dad_start(ifp
, 0);
2073 static void addrconf_dev_config(struct net_device
*dev
)
2075 struct in6_addr addr
;
2076 struct inet6_dev
* idev
;
2080 if ((dev
->type
!= ARPHRD_ETHER
) &&
2081 (dev
->type
!= ARPHRD_FDDI
) &&
2082 (dev
->type
!= ARPHRD_IEEE802_TR
) &&
2083 (dev
->type
!= ARPHRD_ARCNET
) &&
2084 (dev
->type
!= ARPHRD_INFINIBAND
)) {
2085 /* Alas, we support only Ethernet autoconfiguration. */
2089 idev
= addrconf_add_dev(dev
);
2093 memset(&addr
, 0, sizeof(struct in6_addr
));
2094 addr
.s6_addr32
[0] = htonl(0xFE800000);
2096 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) == 0)
2097 addrconf_add_linklocal(idev
, &addr
);
2100 static void addrconf_sit_config(struct net_device
*dev
)
2102 struct inet6_dev
*idev
;
2107 * Configure the tunnel with one of our IPv4
2108 * addresses... we should configure all of
2109 * our v4 addrs in the tunnel
2112 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2113 printk(KERN_DEBUG
"init sit: add_dev failed\n");
2117 sit_add_v4_addrs(idev
);
2119 if (dev
->flags
&IFF_POINTOPOINT
) {
2120 addrconf_add_mroute(dev
);
2121 addrconf_add_lroute(dev
);
2127 ipv6_inherit_linklocal(struct inet6_dev
*idev
, struct net_device
*link_dev
)
2129 struct in6_addr lladdr
;
2131 if (!ipv6_get_lladdr(link_dev
, &lladdr
)) {
2132 addrconf_add_linklocal(idev
, &lladdr
);
2138 static void ip6_tnl_add_linklocal(struct inet6_dev
*idev
)
2140 struct net_device
*link_dev
;
2142 /* first try to inherit the link-local address from the link device */
2143 if (idev
->dev
->iflink
&&
2144 (link_dev
= __dev_get_by_index(idev
->dev
->iflink
))) {
2145 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2148 /* then try to inherit it from any device */
2149 for (link_dev
= dev_base
; link_dev
; link_dev
= link_dev
->next
) {
2150 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2153 printk(KERN_DEBUG
"init ip6-ip6: add_linklocal failed\n");
2157 * Autoconfigure tunnel with a link-local address so routing protocols,
2158 * DHCPv6, MLD etc. can be run over the virtual link
2161 static void addrconf_ip6_tnl_config(struct net_device
*dev
)
2163 struct inet6_dev
*idev
;
2167 if ((idev
= addrconf_add_dev(dev
)) == NULL
) {
2168 printk(KERN_DEBUG
"init ip6-ip6: add_dev failed\n");
2171 ip6_tnl_add_linklocal(idev
);
2174 static int addrconf_notify(struct notifier_block
*this, unsigned long event
,
2177 struct net_device
*dev
= (struct net_device
*) data
;
2178 struct inet6_dev
*idev
= __in6_dev_get(dev
);
2179 int run_pending
= 0;
2184 if (event
== NETDEV_UP
) {
2185 if (!netif_carrier_ok(dev
)) {
2186 /* device is not ready yet. */
2188 "ADDRCONF(NETDEV_UP): %s: "
2189 "link is not ready\n",
2195 idev
->if_flags
|= IF_READY
;
2197 if (!netif_carrier_ok(dev
)) {
2198 /* device is still not ready. */
2203 if (idev
->if_flags
& IF_READY
) {
2204 /* device is already configured. */
2207 idev
->if_flags
|= IF_READY
;
2211 "ADDRCONF(NETDEV_CHANGE): %s: "
2212 "link becomes ready\n",
2220 addrconf_sit_config(dev
);
2222 case ARPHRD_TUNNEL6
:
2223 addrconf_ip6_tnl_config(dev
);
2225 case ARPHRD_LOOPBACK
:
2230 addrconf_dev_config(dev
);
2235 addrconf_dad_run(idev
);
2237 /* If the MTU changed during the interface down, when the
2238 interface up, the changed MTU must be reflected in the
2239 idev as well as routers.
2241 if (idev
->cnf
.mtu6
!= dev
->mtu
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2242 rt6_mtu_change(dev
, dev
->mtu
);
2243 idev
->cnf
.mtu6
= dev
->mtu
;
2245 idev
->tstamp
= jiffies
;
2246 inet6_ifinfo_notify(RTM_NEWLINK
, idev
);
2247 /* If the changed mtu during down is lower than IPV6_MIN_MTU
2248 stop IPv6 on this interface.
2250 if (dev
->mtu
< IPV6_MIN_MTU
)
2251 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2255 case NETDEV_CHANGEMTU
:
2256 if ( idev
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2257 rt6_mtu_change(dev
, dev
->mtu
);
2258 idev
->cnf
.mtu6
= dev
->mtu
;
2262 /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */
2265 case NETDEV_UNREGISTER
:
2267 * Remove all addresses from this interface.
2269 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2272 case NETDEV_CHANGENAME
:
2273 #ifdef CONFIG_SYSCTL
2275 addrconf_sysctl_unregister(&idev
->cnf
);
2276 neigh_sysctl_unregister(idev
->nd_parms
);
2277 neigh_sysctl_register(dev
, idev
->nd_parms
,
2278 NET_IPV6
, NET_IPV6_NEIGH
, "ipv6",
2279 &ndisc_ifinfo_sysctl_change
,
2281 addrconf_sysctl_register(idev
, &idev
->cnf
);
2291 * addrconf module should be notified of a device going up
2293 static struct notifier_block ipv6_dev_notf
= {
2294 .notifier_call
= addrconf_notify
,
2298 static int addrconf_ifdown(struct net_device
*dev
, int how
)
2300 struct inet6_dev
*idev
;
2301 struct inet6_ifaddr
*ifa
, **bifa
;
2306 if (dev
== &loopback_dev
&& how
== 1)
2310 neigh_ifdown(&nd_tbl
, dev
);
2312 idev
= __in6_dev_get(dev
);
2316 /* Step 1: remove reference to ipv6 device from parent device.
2320 write_lock_bh(&addrconf_lock
);
2321 dev
->ip6_ptr
= NULL
;
2323 write_unlock_bh(&addrconf_lock
);
2325 /* Step 1.5: remove snmp6 entry */
2326 snmp6_unregister_dev(idev
);
2330 /* Step 2: clear hash table */
2331 for (i
=0; i
<IN6_ADDR_HSIZE
; i
++) {
2332 bifa
= &inet6_addr_lst
[i
];
2334 write_lock_bh(&addrconf_hash_lock
);
2335 while ((ifa
= *bifa
) != NULL
) {
2336 if (ifa
->idev
== idev
) {
2337 *bifa
= ifa
->lst_next
;
2338 ifa
->lst_next
= NULL
;
2339 addrconf_del_timer(ifa
);
2343 bifa
= &ifa
->lst_next
;
2345 write_unlock_bh(&addrconf_hash_lock
);
2348 write_lock_bh(&idev
->lock
);
2350 /* Step 3: clear flags for stateless addrconf */
2352 idev
->if_flags
&= ~(IF_RS_SENT
|IF_RA_RCVD
|IF_READY
);
2354 /* Step 4: clear address list */
2355 #ifdef CONFIG_IPV6_PRIVACY
2356 if (how
== 1 && del_timer(&idev
->regen_timer
))
2359 /* clear tempaddr list */
2360 while ((ifa
= idev
->tempaddr_list
) != NULL
) {
2361 idev
->tempaddr_list
= ifa
->tmp_next
;
2362 ifa
->tmp_next
= NULL
;
2364 write_unlock_bh(&idev
->lock
);
2365 spin_lock_bh(&ifa
->lock
);
2368 in6_ifa_put(ifa
->ifpub
);
2371 spin_unlock_bh(&ifa
->lock
);
2373 write_lock_bh(&idev
->lock
);
2376 while ((ifa
= idev
->addr_list
) != NULL
) {
2377 idev
->addr_list
= ifa
->if_next
;
2378 ifa
->if_next
= NULL
;
2380 addrconf_del_timer(ifa
);
2381 write_unlock_bh(&idev
->lock
);
2383 __ipv6_ifa_notify(RTM_DELADDR
, ifa
);
2386 write_lock_bh(&idev
->lock
);
2388 write_unlock_bh(&idev
->lock
);
2390 /* Step 5: Discard multicast list */
2393 ipv6_mc_destroy_dev(idev
);
2397 /* Step 5: netlink notification of this interface */
2398 idev
->tstamp
= jiffies
;
2399 inet6_ifinfo_notify(RTM_DELLINK
, idev
);
2401 /* Shot the device (if unregistered) */
2404 #ifdef CONFIG_SYSCTL
2405 addrconf_sysctl_unregister(&idev
->cnf
);
2406 neigh_sysctl_unregister(idev
->nd_parms
);
2408 neigh_parms_release(&nd_tbl
, idev
->nd_parms
);
2409 neigh_ifdown(&nd_tbl
, dev
);
2415 static void addrconf_rs_timer(unsigned long data
)
2417 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2419 if (ifp
->idev
->cnf
.forwarding
)
2422 if (ifp
->idev
->if_flags
& IF_RA_RCVD
) {
2424 * Announcement received after solicitation
2430 spin_lock(&ifp
->lock
);
2431 if (ifp
->probes
++ < ifp
->idev
->cnf
.rtr_solicits
) {
2432 struct in6_addr all_routers
;
2434 /* The wait after the last probe can be shorter */
2435 addrconf_mod_timer(ifp
, AC_RS
,
2436 (ifp
->probes
== ifp
->idev
->cnf
.rtr_solicits
) ?
2437 ifp
->idev
->cnf
.rtr_solicit_delay
:
2438 ifp
->idev
->cnf
.rtr_solicit_interval
);
2439 spin_unlock(&ifp
->lock
);
2441 ipv6_addr_all_routers(&all_routers
);
2443 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &all_routers
);
2445 spin_unlock(&ifp
->lock
);
2447 * Note: we do not support deprecated "all on-link"
2448 * assumption any longer.
2450 printk(KERN_DEBUG
"%s: no IPv6 routers present\n",
2451 ifp
->idev
->dev
->name
);
2459 * Duplicate Address Detection
2461 static void addrconf_dad_kick(struct inet6_ifaddr
*ifp
)
2463 unsigned long rand_num
;
2464 struct inet6_dev
*idev
= ifp
->idev
;
2466 rand_num
= net_random() % (idev
->cnf
.rtr_solicit_delay
? : 1);
2467 ifp
->probes
= idev
->cnf
.dad_transmits
;
2468 addrconf_mod_timer(ifp
, AC_DAD
, rand_num
);
2471 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
)
2473 struct inet6_dev
*idev
= ifp
->idev
;
2474 struct net_device
*dev
= idev
->dev
;
2476 addrconf_join_solict(dev
, &ifp
->addr
);
2478 if (ifp
->prefix_len
!= 128 && (ifp
->flags
&IFA_F_PERMANENT
))
2479 addrconf_prefix_route(&ifp
->addr
, ifp
->prefix_len
, dev
, 0,
2482 net_srandom(ifp
->addr
.s6_addr32
[3]);
2484 read_lock_bh(&idev
->lock
);
2487 spin_lock_bh(&ifp
->lock
);
2489 if (dev
->flags
&(IFF_NOARP
|IFF_LOOPBACK
) ||
2490 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
2491 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2492 spin_unlock_bh(&ifp
->lock
);
2493 read_unlock_bh(&idev
->lock
);
2495 addrconf_dad_completed(ifp
);
2499 if (!(idev
->if_flags
& IF_READY
)) {
2500 spin_unlock_bh(&ifp
->lock
);
2501 read_unlock_bh(&idev
->lock
);
2503 * If the defice is not ready:
2504 * - keep it tentative if it is a permanent address.
2505 * - otherwise, kill it.
2508 addrconf_dad_stop(ifp
);
2511 addrconf_dad_kick(ifp
);
2512 spin_unlock_bh(&ifp
->lock
);
2514 read_unlock_bh(&idev
->lock
);
2517 static void addrconf_dad_timer(unsigned long data
)
2519 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2520 struct inet6_dev
*idev
= ifp
->idev
;
2521 struct in6_addr unspec
;
2522 struct in6_addr mcaddr
;
2524 read_lock_bh(&idev
->lock
);
2526 read_unlock_bh(&idev
->lock
);
2529 spin_lock_bh(&ifp
->lock
);
2530 if (ifp
->probes
== 0) {
2532 * DAD was successful
2535 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2536 spin_unlock_bh(&ifp
->lock
);
2537 read_unlock_bh(&idev
->lock
);
2539 addrconf_dad_completed(ifp
);
2545 addrconf_mod_timer(ifp
, AC_DAD
, ifp
->idev
->nd_parms
->retrans_time
);
2546 spin_unlock_bh(&ifp
->lock
);
2547 read_unlock_bh(&idev
->lock
);
2549 /* send a neighbour solicitation for our addr */
2550 memset(&unspec
, 0, sizeof(unspec
));
2551 addrconf_addr_solict_mult(&ifp
->addr
, &mcaddr
);
2552 ndisc_send_ns(ifp
->idev
->dev
, NULL
, &ifp
->addr
, &mcaddr
, &unspec
);
2557 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
)
2559 struct net_device
* dev
= ifp
->idev
->dev
;
2562 * Configure the address for reception. Now it is valid.
2565 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2567 /* If added prefix is link local and forwarding is off,
2568 start sending router solicitations.
2571 if (ifp
->idev
->cnf
.forwarding
== 0 &&
2572 ifp
->idev
->cnf
.rtr_solicits
> 0 &&
2573 (dev
->flags
&IFF_LOOPBACK
) == 0 &&
2574 (ipv6_addr_type(&ifp
->addr
) & IPV6_ADDR_LINKLOCAL
)) {
2575 struct in6_addr all_routers
;
2577 ipv6_addr_all_routers(&all_routers
);
2580 * If a host as already performed a random delay
2581 * [...] as part of DAD [...] there is no need
2582 * to delay again before sending the first RS
2584 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &all_routers
);
2586 spin_lock_bh(&ifp
->lock
);
2588 ifp
->idev
->if_flags
|= IF_RS_SENT
;
2589 addrconf_mod_timer(ifp
, AC_RS
, ifp
->idev
->cnf
.rtr_solicit_interval
);
2590 spin_unlock_bh(&ifp
->lock
);
2594 static void addrconf_dad_run(struct inet6_dev
*idev
) {
2595 struct inet6_ifaddr
*ifp
;
2597 read_lock_bh(&idev
->lock
);
2598 for (ifp
= idev
->addr_list
; ifp
; ifp
= ifp
->if_next
) {
2599 spin_lock_bh(&ifp
->lock
);
2600 if (!(ifp
->flags
& IFA_F_TENTATIVE
)) {
2601 spin_unlock_bh(&ifp
->lock
);
2604 spin_unlock_bh(&ifp
->lock
);
2605 addrconf_dad_kick(ifp
);
2607 read_unlock_bh(&idev
->lock
);
2610 #ifdef CONFIG_PROC_FS
2611 struct if6_iter_state
{
2615 static struct inet6_ifaddr
*if6_get_first(struct seq_file
*seq
)
2617 struct inet6_ifaddr
*ifa
= NULL
;
2618 struct if6_iter_state
*state
= seq
->private;
2620 for (state
->bucket
= 0; state
->bucket
< IN6_ADDR_HSIZE
; ++state
->bucket
) {
2621 ifa
= inet6_addr_lst
[state
->bucket
];
2628 static struct inet6_ifaddr
*if6_get_next(struct seq_file
*seq
, struct inet6_ifaddr
*ifa
)
2630 struct if6_iter_state
*state
= seq
->private;
2632 ifa
= ifa
->lst_next
;
2634 if (!ifa
&& ++state
->bucket
< IN6_ADDR_HSIZE
) {
2635 ifa
= inet6_addr_lst
[state
->bucket
];
2641 static struct inet6_ifaddr
*if6_get_idx(struct seq_file
*seq
, loff_t pos
)
2643 struct inet6_ifaddr
*ifa
= if6_get_first(seq
);
2646 while(pos
&& (ifa
= if6_get_next(seq
, ifa
)) != NULL
)
2648 return pos
? NULL
: ifa
;
2651 static void *if6_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2653 read_lock_bh(&addrconf_hash_lock
);
2654 return if6_get_idx(seq
, *pos
);
2657 static void *if6_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2659 struct inet6_ifaddr
*ifa
;
2661 ifa
= if6_get_next(seq
, v
);
2666 static void if6_seq_stop(struct seq_file
*seq
, void *v
)
2668 read_unlock_bh(&addrconf_hash_lock
);
2671 static int if6_seq_show(struct seq_file
*seq
, void *v
)
2673 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*)v
;
2675 NIP6_SEQFMT
" %02x %02x %02x %02x %8s\n",
2677 ifp
->idev
->dev
->ifindex
,
2681 ifp
->idev
->dev
->name
);
2685 static struct seq_operations if6_seq_ops
= {
2686 .start
= if6_seq_start
,
2687 .next
= if6_seq_next
,
2688 .show
= if6_seq_show
,
2689 .stop
= if6_seq_stop
,
2692 static int if6_seq_open(struct inode
*inode
, struct file
*file
)
2694 struct seq_file
*seq
;
2696 struct if6_iter_state
*s
= kzalloc(sizeof(*s
), GFP_KERNEL
);
2701 rc
= seq_open(file
, &if6_seq_ops
);
2705 seq
= file
->private_data
;
2714 static struct file_operations if6_fops
= {
2715 .owner
= THIS_MODULE
,
2716 .open
= if6_seq_open
,
2718 .llseek
= seq_lseek
,
2719 .release
= seq_release_private
,
2722 int __init
if6_proc_init(void)
2724 if (!proc_net_fops_create("if_inet6", S_IRUGO
, &if6_fops
))
2729 void if6_proc_exit(void)
2731 proc_net_remove("if_inet6");
2733 #endif /* CONFIG_PROC_FS */
2736 * Periodic address status verification
2739 static void addrconf_verify(unsigned long foo
)
2741 struct inet6_ifaddr
*ifp
;
2742 unsigned long now
, next
;
2745 spin_lock_bh(&addrconf_verify_lock
);
2747 next
= now
+ ADDR_CHECK_FREQUENCY
;
2749 del_timer(&addr_chk_timer
);
2751 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
2754 read_lock(&addrconf_hash_lock
);
2755 for (ifp
=inet6_addr_lst
[i
]; ifp
; ifp
=ifp
->lst_next
) {
2757 #ifdef CONFIG_IPV6_PRIVACY
2758 unsigned long regen_advance
;
2761 if (ifp
->flags
& IFA_F_PERMANENT
)
2764 spin_lock(&ifp
->lock
);
2765 age
= (now
- ifp
->tstamp
) / HZ
;
2767 #ifdef CONFIG_IPV6_PRIVACY
2768 regen_advance
= ifp
->idev
->cnf
.regen_max_retry
*
2769 ifp
->idev
->cnf
.dad_transmits
*
2770 ifp
->idev
->nd_parms
->retrans_time
/ HZ
;
2773 if (age
>= ifp
->valid_lft
) {
2774 spin_unlock(&ifp
->lock
);
2776 read_unlock(&addrconf_hash_lock
);
2779 } else if (age
>= ifp
->prefered_lft
) {
2780 /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */
2783 if (!(ifp
->flags
&IFA_F_DEPRECATED
)) {
2785 ifp
->flags
|= IFA_F_DEPRECATED
;
2788 if (time_before(ifp
->tstamp
+ ifp
->valid_lft
* HZ
, next
))
2789 next
= ifp
->tstamp
+ ifp
->valid_lft
* HZ
;
2791 spin_unlock(&ifp
->lock
);
2795 read_unlock(&addrconf_hash_lock
);
2797 ipv6_ifa_notify(0, ifp
);
2801 #ifdef CONFIG_IPV6_PRIVACY
2802 } else if ((ifp
->flags
&IFA_F_TEMPORARY
) &&
2803 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
2804 if (age
>= ifp
->prefered_lft
- regen_advance
) {
2805 struct inet6_ifaddr
*ifpub
= ifp
->ifpub
;
2806 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
2807 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
2808 if (!ifp
->regen_count
&& ifpub
) {
2811 in6_ifa_hold(ifpub
);
2812 spin_unlock(&ifp
->lock
);
2813 read_unlock(&addrconf_hash_lock
);
2814 spin_lock(&ifpub
->lock
);
2815 ifpub
->regen_count
= 0;
2816 spin_unlock(&ifpub
->lock
);
2817 ipv6_create_tempaddr(ifpub
, ifp
);
2822 } else if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
, next
))
2823 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
;
2824 spin_unlock(&ifp
->lock
);
2827 /* ifp->prefered_lft <= ifp->valid_lft */
2828 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
2829 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
2830 spin_unlock(&ifp
->lock
);
2833 read_unlock(&addrconf_hash_lock
);
2836 addr_chk_timer
.expires
= time_before(next
, jiffies
+ HZ
) ? jiffies
+ HZ
: next
;
2837 add_timer(&addr_chk_timer
);
2838 spin_unlock_bh(&addrconf_verify_lock
);
2842 inet6_rtm_deladdr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
2844 struct rtattr
**rta
= arg
;
2845 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
2846 struct in6_addr
*pfx
;
2849 if (rta
[IFA_ADDRESS
-1]) {
2850 if (RTA_PAYLOAD(rta
[IFA_ADDRESS
-1]) < sizeof(*pfx
))
2852 pfx
= RTA_DATA(rta
[IFA_ADDRESS
-1]);
2854 if (rta
[IFA_LOCAL
-1]) {
2855 if (pfx
&& memcmp(pfx
, RTA_DATA(rta
[IFA_LOCAL
-1]), sizeof(*pfx
)))
2857 pfx
= RTA_DATA(rta
[IFA_LOCAL
-1]);
2862 return inet6_addr_del(ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
);
2866 inet6_rtm_newaddr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
2868 struct rtattr
**rta
= arg
;
2869 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
2870 struct in6_addr
*pfx
;
2873 if (rta
[IFA_ADDRESS
-1]) {
2874 if (RTA_PAYLOAD(rta
[IFA_ADDRESS
-1]) < sizeof(*pfx
))
2876 pfx
= RTA_DATA(rta
[IFA_ADDRESS
-1]);
2878 if (rta
[IFA_LOCAL
-1]) {
2879 if (pfx
&& memcmp(pfx
, RTA_DATA(rta
[IFA_LOCAL
-1]), sizeof(*pfx
)))
2881 pfx
= RTA_DATA(rta
[IFA_LOCAL
-1]);
2886 return inet6_addr_add(ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
);
2889 /* Maximum length of ifa_cacheinfo attributes */
2890 #define INET6_IFADDR_RTA_SPACE \
2891 RTA_SPACE(16) /* IFA_ADDRESS */ + \
2892 RTA_SPACE(sizeof(struct ifa_cacheinfo)) /* CACHEINFO */
2894 static int inet6_fill_ifaddr(struct sk_buff
*skb
, struct inet6_ifaddr
*ifa
,
2895 u32 pid
, u32 seq
, int event
, unsigned int flags
)
2897 struct ifaddrmsg
*ifm
;
2898 struct nlmsghdr
*nlh
;
2899 struct ifa_cacheinfo ci
;
2900 unsigned char *b
= skb
->tail
;
2902 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
2903 ifm
= NLMSG_DATA(nlh
);
2904 ifm
->ifa_family
= AF_INET6
;
2905 ifm
->ifa_prefixlen
= ifa
->prefix_len
;
2906 ifm
->ifa_flags
= ifa
->flags
;
2907 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
2908 if (ifa
->scope
&IFA_HOST
)
2909 ifm
->ifa_scope
= RT_SCOPE_HOST
;
2910 else if (ifa
->scope
&IFA_LINK
)
2911 ifm
->ifa_scope
= RT_SCOPE_LINK
;
2912 else if (ifa
->scope
&IFA_SITE
)
2913 ifm
->ifa_scope
= RT_SCOPE_SITE
;
2914 ifm
->ifa_index
= ifa
->idev
->dev
->ifindex
;
2915 RTA_PUT(skb
, IFA_ADDRESS
, 16, &ifa
->addr
);
2916 if (!(ifa
->flags
&IFA_F_PERMANENT
)) {
2917 ci
.ifa_prefered
= ifa
->prefered_lft
;
2918 ci
.ifa_valid
= ifa
->valid_lft
;
2919 if (ci
.ifa_prefered
!= INFINITY_LIFE_TIME
) {
2920 long tval
= (jiffies
- ifa
->tstamp
)/HZ
;
2921 ci
.ifa_prefered
-= tval
;
2922 if (ci
.ifa_valid
!= INFINITY_LIFE_TIME
)
2923 ci
.ifa_valid
-= tval
;
2926 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
2927 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
2929 ci
.cstamp
= (__u32
)(TIME_DELTA(ifa
->cstamp
, INITIAL_JIFFIES
) / HZ
* 100
2930 + TIME_DELTA(ifa
->cstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
2931 ci
.tstamp
= (__u32
)(TIME_DELTA(ifa
->tstamp
, INITIAL_JIFFIES
) / HZ
* 100
2932 + TIME_DELTA(ifa
->tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
2933 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
2934 nlh
->nlmsg_len
= skb
->tail
- b
;
2939 skb_trim(skb
, b
- skb
->data
);
2943 static int inet6_fill_ifmcaddr(struct sk_buff
*skb
, struct ifmcaddr6
*ifmca
,
2944 u32 pid
, u32 seq
, int event
, u16 flags
)
2946 struct ifaddrmsg
*ifm
;
2947 struct nlmsghdr
*nlh
;
2948 struct ifa_cacheinfo ci
;
2949 unsigned char *b
= skb
->tail
;
2951 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
2952 ifm
= NLMSG_DATA(nlh
);
2953 ifm
->ifa_family
= AF_INET6
;
2954 ifm
->ifa_prefixlen
= 128;
2955 ifm
->ifa_flags
= IFA_F_PERMANENT
;
2956 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
2957 if (ipv6_addr_scope(&ifmca
->mca_addr
)&IFA_SITE
)
2958 ifm
->ifa_scope
= RT_SCOPE_SITE
;
2959 ifm
->ifa_index
= ifmca
->idev
->dev
->ifindex
;
2960 RTA_PUT(skb
, IFA_MULTICAST
, 16, &ifmca
->mca_addr
);
2961 ci
.cstamp
= (__u32
)(TIME_DELTA(ifmca
->mca_cstamp
, INITIAL_JIFFIES
) / HZ
2962 * 100 + TIME_DELTA(ifmca
->mca_cstamp
, INITIAL_JIFFIES
) % HZ
2964 ci
.tstamp
= (__u32
)(TIME_DELTA(ifmca
->mca_tstamp
, INITIAL_JIFFIES
) / HZ
2965 * 100 + TIME_DELTA(ifmca
->mca_tstamp
, INITIAL_JIFFIES
) % HZ
2967 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
2968 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
2969 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
2970 nlh
->nlmsg_len
= skb
->tail
- b
;
2975 skb_trim(skb
, b
- skb
->data
);
2979 static int inet6_fill_ifacaddr(struct sk_buff
*skb
, struct ifacaddr6
*ifaca
,
2980 u32 pid
, u32 seq
, int event
, unsigned int flags
)
2982 struct ifaddrmsg
*ifm
;
2983 struct nlmsghdr
*nlh
;
2984 struct ifa_cacheinfo ci
;
2985 unsigned char *b
= skb
->tail
;
2987 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
2988 ifm
= NLMSG_DATA(nlh
);
2989 ifm
->ifa_family
= AF_INET6
;
2990 ifm
->ifa_prefixlen
= 128;
2991 ifm
->ifa_flags
= IFA_F_PERMANENT
;
2992 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
2993 if (ipv6_addr_scope(&ifaca
->aca_addr
)&IFA_SITE
)
2994 ifm
->ifa_scope
= RT_SCOPE_SITE
;
2995 ifm
->ifa_index
= ifaca
->aca_idev
->dev
->ifindex
;
2996 RTA_PUT(skb
, IFA_ANYCAST
, 16, &ifaca
->aca_addr
);
2997 ci
.cstamp
= (__u32
)(TIME_DELTA(ifaca
->aca_cstamp
, INITIAL_JIFFIES
) / HZ
2998 * 100 + TIME_DELTA(ifaca
->aca_cstamp
, INITIAL_JIFFIES
) % HZ
3000 ci
.tstamp
= (__u32
)(TIME_DELTA(ifaca
->aca_tstamp
, INITIAL_JIFFIES
) / HZ
3001 * 100 + TIME_DELTA(ifaca
->aca_tstamp
, INITIAL_JIFFIES
) % HZ
3003 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
3004 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
3005 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
3006 nlh
->nlmsg_len
= skb
->tail
- b
;
3011 skb_trim(skb
, b
- skb
->data
);
3022 static int inet6_dump_addr(struct sk_buff
*skb
, struct netlink_callback
*cb
,
3023 enum addr_type_t type
)
3026 int s_idx
, s_ip_idx
;
3028 struct net_device
*dev
;
3029 struct inet6_dev
*idev
= NULL
;
3030 struct inet6_ifaddr
*ifa
;
3031 struct ifmcaddr6
*ifmca
;
3032 struct ifacaddr6
*ifaca
;
3034 s_idx
= cb
->args
[0];
3035 s_ip_idx
= ip_idx
= cb
->args
[1];
3036 read_lock(&dev_base_lock
);
3038 for (dev
= dev_base
, idx
= 0; dev
; dev
= dev
->next
, idx
++) {
3044 if ((idev
= in6_dev_get(dev
)) == NULL
)
3046 read_lock_bh(&idev
->lock
);
3049 /* unicast address incl. temp addr */
3050 for (ifa
= idev
->addr_list
; ifa
;
3051 ifa
= ifa
->if_next
, ip_idx
++) {
3052 if (ip_idx
< s_ip_idx
)
3054 if ((err
= inet6_fill_ifaddr(skb
, ifa
,
3055 NETLINK_CB(cb
->skb
).pid
,
3056 cb
->nlh
->nlmsg_seq
, RTM_NEWADDR
,
3061 case MULTICAST_ADDR
:
3062 /* multicast address */
3063 for (ifmca
= idev
->mc_list
; ifmca
;
3064 ifmca
= ifmca
->next
, ip_idx
++) {
3065 if (ip_idx
< s_ip_idx
)
3067 if ((err
= inet6_fill_ifmcaddr(skb
, ifmca
,
3068 NETLINK_CB(cb
->skb
).pid
,
3069 cb
->nlh
->nlmsg_seq
, RTM_GETMULTICAST
,
3075 /* anycast address */
3076 for (ifaca
= idev
->ac_list
; ifaca
;
3077 ifaca
= ifaca
->aca_next
, ip_idx
++) {
3078 if (ip_idx
< s_ip_idx
)
3080 if ((err
= inet6_fill_ifacaddr(skb
, ifaca
,
3081 NETLINK_CB(cb
->skb
).pid
,
3082 cb
->nlh
->nlmsg_seq
, RTM_GETANYCAST
,
3090 read_unlock_bh(&idev
->lock
);
3095 read_unlock_bh(&idev
->lock
);
3098 read_unlock(&dev_base_lock
);
3100 cb
->args
[1] = ip_idx
;
3104 static int inet6_dump_ifaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3106 enum addr_type_t type
= UNICAST_ADDR
;
3107 return inet6_dump_addr(skb
, cb
, type
);
3110 static int inet6_dump_ifmcaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3112 enum addr_type_t type
= MULTICAST_ADDR
;
3113 return inet6_dump_addr(skb
, cb
, type
);
3117 static int inet6_dump_ifacaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3119 enum addr_type_t type
= ANYCAST_ADDR
;
3120 return inet6_dump_addr(skb
, cb
, type
);
3123 static void inet6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
)
3125 struct sk_buff
*skb
;
3126 int size
= NLMSG_SPACE(sizeof(struct ifaddrmsg
) + INET6_IFADDR_RTA_SPACE
);
3128 skb
= alloc_skb(size
, GFP_ATOMIC
);
3130 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFADDR
, ENOBUFS
);
3133 if (inet6_fill_ifaddr(skb
, ifa
, current
->pid
, 0, event
, 0) < 0) {
3135 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFADDR
, EINVAL
);
3138 NETLINK_CB(skb
).dst_group
= RTNLGRP_IPV6_IFADDR
;
3139 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_IPV6_IFADDR
, GFP_ATOMIC
);
3142 static void inline ipv6_store_devconf(struct ipv6_devconf
*cnf
,
3143 __s32
*array
, int bytes
)
3145 memset(array
, 0, bytes
);
3146 array
[DEVCONF_FORWARDING
] = cnf
->forwarding
;
3147 array
[DEVCONF_HOPLIMIT
] = cnf
->hop_limit
;
3148 array
[DEVCONF_MTU6
] = cnf
->mtu6
;
3149 array
[DEVCONF_ACCEPT_RA
] = cnf
->accept_ra
;
3150 array
[DEVCONF_ACCEPT_REDIRECTS
] = cnf
->accept_redirects
;
3151 array
[DEVCONF_AUTOCONF
] = cnf
->autoconf
;
3152 array
[DEVCONF_DAD_TRANSMITS
] = cnf
->dad_transmits
;
3153 array
[DEVCONF_RTR_SOLICITS
] = cnf
->rtr_solicits
;
3154 array
[DEVCONF_RTR_SOLICIT_INTERVAL
] = cnf
->rtr_solicit_interval
;
3155 array
[DEVCONF_RTR_SOLICIT_DELAY
] = cnf
->rtr_solicit_delay
;
3156 array
[DEVCONF_FORCE_MLD_VERSION
] = cnf
->force_mld_version
;
3157 #ifdef CONFIG_IPV6_PRIVACY
3158 array
[DEVCONF_USE_TEMPADDR
] = cnf
->use_tempaddr
;
3159 array
[DEVCONF_TEMP_VALID_LFT
] = cnf
->temp_valid_lft
;
3160 array
[DEVCONF_TEMP_PREFERED_LFT
] = cnf
->temp_prefered_lft
;
3161 array
[DEVCONF_REGEN_MAX_RETRY
] = cnf
->regen_max_retry
;
3162 array
[DEVCONF_MAX_DESYNC_FACTOR
] = cnf
->max_desync_factor
;
3164 array
[DEVCONF_MAX_ADDRESSES
] = cnf
->max_addresses
;
3165 array
[DEVCONF_ACCEPT_RA_DEFRTR
] = cnf
->accept_ra_defrtr
;
3166 array
[DEVCONF_ACCEPT_RA_PINFO
] = cnf
->accept_ra_pinfo
;
3167 #ifdef CONFIG_IPV6_ROUTER_PREF
3168 array
[DEVCONF_ACCEPT_RA_RTR_PREF
] = cnf
->accept_ra_rtr_pref
;
3169 array
[DEVCONF_RTR_PROBE_INTERVAL
] = cnf
->rtr_probe_interval
;
3170 #ifdef CONFIV_IPV6_ROUTE_INFO
3171 array
[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN
] = cnf
->accept_ra_rt_info_max_plen
;
3176 /* Maximum length of ifinfomsg attributes */
3177 #define INET6_IFINFO_RTA_SPACE \
3178 RTA_SPACE(IFNAMSIZ) /* IFNAME */ + \
3179 RTA_SPACE(MAX_ADDR_LEN) /* ADDRESS */ + \
3180 RTA_SPACE(sizeof(u32)) /* MTU */ + \
3181 RTA_SPACE(sizeof(int)) /* LINK */ + \
3182 RTA_SPACE(0) /* PROTINFO */ + \
3183 RTA_SPACE(sizeof(u32)) /* FLAGS */ + \
3184 RTA_SPACE(sizeof(struct ifla_cacheinfo)) /* CACHEINFO */ + \
3185 RTA_SPACE(sizeof(__s32[DEVCONF_MAX])) /* CONF */
3187 static int inet6_fill_ifinfo(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3188 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3190 struct net_device
*dev
= idev
->dev
;
3191 __s32
*array
= NULL
;
3192 struct ifinfomsg
*r
;
3193 struct nlmsghdr
*nlh
;
3194 unsigned char *b
= skb
->tail
;
3195 struct rtattr
*subattr
;
3196 __u32 mtu
= dev
->mtu
;
3197 struct ifla_cacheinfo ci
;
3199 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*r
), flags
);
3200 r
= NLMSG_DATA(nlh
);
3201 r
->ifi_family
= AF_INET6
;
3203 r
->ifi_type
= dev
->type
;
3204 r
->ifi_index
= dev
->ifindex
;
3205 r
->ifi_flags
= dev_get_flags(dev
);
3208 RTA_PUT(skb
, IFLA_IFNAME
, strlen(dev
->name
)+1, dev
->name
);
3211 RTA_PUT(skb
, IFLA_ADDRESS
, dev
->addr_len
, dev
->dev_addr
);
3213 RTA_PUT(skb
, IFLA_MTU
, sizeof(mtu
), &mtu
);
3214 if (dev
->ifindex
!= dev
->iflink
)
3215 RTA_PUT(skb
, IFLA_LINK
, sizeof(int), &dev
->iflink
);
3217 subattr
= (struct rtattr
*)skb
->tail
;
3219 RTA_PUT(skb
, IFLA_PROTINFO
, 0, NULL
);
3221 /* return the device flags */
3222 RTA_PUT(skb
, IFLA_INET6_FLAGS
, sizeof(__u32
), &idev
->if_flags
);
3224 /* return interface cacheinfo */
3225 ci
.max_reasm_len
= IPV6_MAXPLEN
;
3226 ci
.tstamp
= (__u32
)(TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) / HZ
* 100
3227 + TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3228 ci
.reachable_time
= idev
->nd_parms
->reachable_time
;
3229 ci
.retrans_time
= idev
->nd_parms
->retrans_time
;
3230 RTA_PUT(skb
, IFLA_INET6_CACHEINFO
, sizeof(ci
), &ci
);
3232 /* return the device sysctl params */
3233 if ((array
= kmalloc(DEVCONF_MAX
* sizeof(*array
), GFP_ATOMIC
)) == NULL
)
3234 goto rtattr_failure
;
3235 ipv6_store_devconf(&idev
->cnf
, array
, DEVCONF_MAX
* sizeof(*array
));
3236 RTA_PUT(skb
, IFLA_INET6_CONF
, DEVCONF_MAX
* sizeof(*array
), array
);
3238 /* XXX - Statistics/MC not implemented */
3239 subattr
->rta_len
= skb
->tail
- (u8
*)subattr
;
3241 nlh
->nlmsg_len
= skb
->tail
- b
;
3248 skb_trim(skb
, b
- skb
->data
);
3252 static int inet6_dump_ifinfo(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3255 int s_idx
= cb
->args
[0];
3256 struct net_device
*dev
;
3257 struct inet6_dev
*idev
;
3259 read_lock(&dev_base_lock
);
3260 for (dev
=dev_base
, idx
=0; dev
; dev
= dev
->next
, idx
++) {
3263 if ((idev
= in6_dev_get(dev
)) == NULL
)
3265 err
= inet6_fill_ifinfo(skb
, idev
, NETLINK_CB(cb
->skb
).pid
,
3266 cb
->nlh
->nlmsg_seq
, RTM_NEWLINK
, NLM_F_MULTI
);
3271 read_unlock(&dev_base_lock
);
3277 void inet6_ifinfo_notify(int event
, struct inet6_dev
*idev
)
3279 struct sk_buff
*skb
;
3280 int size
= NLMSG_SPACE(sizeof(struct ifinfomsg
) + INET6_IFINFO_RTA_SPACE
);
3282 skb
= alloc_skb(size
, GFP_ATOMIC
);
3284 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFINFO
, ENOBUFS
);
3287 if (inet6_fill_ifinfo(skb
, idev
, current
->pid
, 0, event
, 0) < 0) {
3289 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFINFO
, EINVAL
);
3292 NETLINK_CB(skb
).dst_group
= RTNLGRP_IPV6_IFINFO
;
3293 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_IPV6_IFINFO
, GFP_ATOMIC
);
3296 /* Maximum length of prefix_cacheinfo attributes */
3297 #define INET6_PREFIX_RTA_SPACE \
3298 RTA_SPACE(sizeof(((struct prefix_info *)NULL)->prefix)) /* ADDRESS */ + \
3299 RTA_SPACE(sizeof(struct prefix_cacheinfo)) /* CACHEINFO */
3301 static int inet6_fill_prefix(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3302 struct prefix_info
*pinfo
, u32 pid
, u32 seq
,
3303 int event
, unsigned int flags
)
3305 struct prefixmsg
*pmsg
;
3306 struct nlmsghdr
*nlh
;
3307 unsigned char *b
= skb
->tail
;
3308 struct prefix_cacheinfo ci
;
3310 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*pmsg
), flags
);
3311 pmsg
= NLMSG_DATA(nlh
);
3312 pmsg
->prefix_family
= AF_INET6
;
3313 pmsg
->prefix_pad1
= 0;
3314 pmsg
->prefix_pad2
= 0;
3315 pmsg
->prefix_ifindex
= idev
->dev
->ifindex
;
3316 pmsg
->prefix_len
= pinfo
->prefix_len
;
3317 pmsg
->prefix_type
= pinfo
->type
;
3318 pmsg
->prefix_pad3
= 0;
3320 pmsg
->prefix_flags
= 0;
3322 pmsg
->prefix_flags
|= IF_PREFIX_ONLINK
;
3323 if (pinfo
->autoconf
)
3324 pmsg
->prefix_flags
|= IF_PREFIX_AUTOCONF
;
3326 RTA_PUT(skb
, PREFIX_ADDRESS
, sizeof(pinfo
->prefix
), &pinfo
->prefix
);
3328 ci
.preferred_time
= ntohl(pinfo
->prefered
);
3329 ci
.valid_time
= ntohl(pinfo
->valid
);
3330 RTA_PUT(skb
, PREFIX_CACHEINFO
, sizeof(ci
), &ci
);
3332 nlh
->nlmsg_len
= skb
->tail
- b
;
3337 skb_trim(skb
, b
- skb
->data
);
3341 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
3342 struct prefix_info
*pinfo
)
3344 struct sk_buff
*skb
;
3345 int size
= NLMSG_SPACE(sizeof(struct prefixmsg
) + INET6_PREFIX_RTA_SPACE
);
3347 skb
= alloc_skb(size
, GFP_ATOMIC
);
3349 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_PREFIX
, ENOBUFS
);
3352 if (inet6_fill_prefix(skb
, idev
, pinfo
, current
->pid
, 0, event
, 0) < 0) {
3354 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_PREFIX
, EINVAL
);
3357 NETLINK_CB(skb
).dst_group
= RTNLGRP_IPV6_PREFIX
;
3358 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_IPV6_PREFIX
, GFP_ATOMIC
);
3361 static struct rtnetlink_link inet6_rtnetlink_table
[RTM_NR_MSGTYPES
] = {
3362 [RTM_GETLINK
- RTM_BASE
] = { .dumpit
= inet6_dump_ifinfo
, },
3363 [RTM_NEWADDR
- RTM_BASE
] = { .doit
= inet6_rtm_newaddr
, },
3364 [RTM_DELADDR
- RTM_BASE
] = { .doit
= inet6_rtm_deladdr
, },
3365 [RTM_GETADDR
- RTM_BASE
] = { .dumpit
= inet6_dump_ifaddr
, },
3366 [RTM_GETMULTICAST
- RTM_BASE
] = { .dumpit
= inet6_dump_ifmcaddr
, },
3367 [RTM_GETANYCAST
- RTM_BASE
] = { .dumpit
= inet6_dump_ifacaddr
, },
3368 [RTM_NEWROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_newroute
, },
3369 [RTM_DELROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_delroute
, },
3370 [RTM_GETROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_getroute
,
3371 .dumpit
= inet6_dump_fib
, },
3374 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3376 inet6_ifa_notify(event
? : RTM_NEWADDR
, ifp
);
3380 ip6_ins_rt(ifp
->rt
, NULL
, NULL
, NULL
);
3381 if (ifp
->idev
->cnf
.forwarding
)
3382 addrconf_join_anycast(ifp
);
3385 if (ifp
->idev
->cnf
.forwarding
)
3386 addrconf_leave_anycast(ifp
);
3387 addrconf_leave_solict(ifp
->idev
, &ifp
->addr
);
3388 dst_hold(&ifp
->rt
->u
.dst
);
3389 if (ip6_del_rt(ifp
->rt
, NULL
, NULL
, NULL
))
3390 dst_free(&ifp
->rt
->u
.dst
);
3395 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3397 read_lock_bh(&addrconf_lock
);
3398 if (likely(ifp
->idev
->dead
== 0))
3399 __ipv6_ifa_notify(event
, ifp
);
3400 read_unlock_bh(&addrconf_lock
);
3403 #ifdef CONFIG_SYSCTL
3406 int addrconf_sysctl_forward(ctl_table
*ctl
, int write
, struct file
* filp
,
3407 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3409 int *valp
= ctl
->data
;
3413 ret
= proc_dointvec(ctl
, write
, filp
, buffer
, lenp
, ppos
);
3415 if (write
&& valp
!= &ipv6_devconf_dflt
.forwarding
) {
3416 if (valp
!= &ipv6_devconf
.forwarding
) {
3417 if ((!*valp
) ^ (!val
)) {
3418 struct inet6_dev
*idev
= (struct inet6_dev
*)ctl
->extra1
;
3421 dev_forward_change(idev
);
3424 ipv6_devconf_dflt
.forwarding
= ipv6_devconf
.forwarding
;
3425 addrconf_forward_change();
3428 rt6_purge_dflt_routers();
3434 static int addrconf_sysctl_forward_strategy(ctl_table
*table
,
3435 int __user
*name
, int nlen
,
3436 void __user
*oldval
,
3437 size_t __user
*oldlenp
,
3438 void __user
*newval
, size_t newlen
,
3441 int *valp
= table
->data
;
3444 if (!newval
|| !newlen
)
3446 if (newlen
!= sizeof(int))
3448 if (get_user(new, (int __user
*)newval
))
3452 if (oldval
&& oldlenp
) {
3454 if (get_user(len
, oldlenp
))
3457 if (len
> table
->maxlen
)
3458 len
= table
->maxlen
;
3459 if (copy_to_user(oldval
, valp
, len
))
3461 if (put_user(len
, oldlenp
))
3466 if (valp
!= &ipv6_devconf_dflt
.forwarding
) {
3467 if (valp
!= &ipv6_devconf
.forwarding
) {
3468 struct inet6_dev
*idev
= (struct inet6_dev
*)table
->extra1
;
3470 if (unlikely(idev
== NULL
))
3472 changed
= (!*valp
) ^ (!new);
3475 dev_forward_change(idev
);
3478 addrconf_forward_change();
3482 rt6_purge_dflt_routers();
3489 static struct addrconf_sysctl_table
3491 struct ctl_table_header
*sysctl_header
;
3492 ctl_table addrconf_vars
[__NET_IPV6_MAX
];
3493 ctl_table addrconf_dev
[2];
3494 ctl_table addrconf_conf_dir
[2];
3495 ctl_table addrconf_proto_dir
[2];
3496 ctl_table addrconf_root_dir
[2];
3497 } addrconf_sysctl
= {
3498 .sysctl_header
= NULL
,
3501 .ctl_name
= NET_IPV6_FORWARDING
,
3502 .procname
= "forwarding",
3503 .data
= &ipv6_devconf
.forwarding
,
3504 .maxlen
= sizeof(int),
3506 .proc_handler
= &addrconf_sysctl_forward
,
3507 .strategy
= &addrconf_sysctl_forward_strategy
,
3510 .ctl_name
= NET_IPV6_HOP_LIMIT
,
3511 .procname
= "hop_limit",
3512 .data
= &ipv6_devconf
.hop_limit
,
3513 .maxlen
= sizeof(int),
3515 .proc_handler
= proc_dointvec
,
3518 .ctl_name
= NET_IPV6_MTU
,
3520 .data
= &ipv6_devconf
.mtu6
,
3521 .maxlen
= sizeof(int),
3523 .proc_handler
= &proc_dointvec
,
3526 .ctl_name
= NET_IPV6_ACCEPT_RA
,
3527 .procname
= "accept_ra",
3528 .data
= &ipv6_devconf
.accept_ra
,
3529 .maxlen
= sizeof(int),
3531 .proc_handler
= &proc_dointvec
,
3534 .ctl_name
= NET_IPV6_ACCEPT_REDIRECTS
,
3535 .procname
= "accept_redirects",
3536 .data
= &ipv6_devconf
.accept_redirects
,
3537 .maxlen
= sizeof(int),
3539 .proc_handler
= &proc_dointvec
,
3542 .ctl_name
= NET_IPV6_AUTOCONF
,
3543 .procname
= "autoconf",
3544 .data
= &ipv6_devconf
.autoconf
,
3545 .maxlen
= sizeof(int),
3547 .proc_handler
= &proc_dointvec
,
3550 .ctl_name
= NET_IPV6_DAD_TRANSMITS
,
3551 .procname
= "dad_transmits",
3552 .data
= &ipv6_devconf
.dad_transmits
,
3553 .maxlen
= sizeof(int),
3555 .proc_handler
= &proc_dointvec
,
3558 .ctl_name
= NET_IPV6_RTR_SOLICITS
,
3559 .procname
= "router_solicitations",
3560 .data
= &ipv6_devconf
.rtr_solicits
,
3561 .maxlen
= sizeof(int),
3563 .proc_handler
= &proc_dointvec
,
3566 .ctl_name
= NET_IPV6_RTR_SOLICIT_INTERVAL
,
3567 .procname
= "router_solicitation_interval",
3568 .data
= &ipv6_devconf
.rtr_solicit_interval
,
3569 .maxlen
= sizeof(int),
3571 .proc_handler
= &proc_dointvec_jiffies
,
3572 .strategy
= &sysctl_jiffies
,
3575 .ctl_name
= NET_IPV6_RTR_SOLICIT_DELAY
,
3576 .procname
= "router_solicitation_delay",
3577 .data
= &ipv6_devconf
.rtr_solicit_delay
,
3578 .maxlen
= sizeof(int),
3580 .proc_handler
= &proc_dointvec_jiffies
,
3581 .strategy
= &sysctl_jiffies
,
3584 .ctl_name
= NET_IPV6_FORCE_MLD_VERSION
,
3585 .procname
= "force_mld_version",
3586 .data
= &ipv6_devconf
.force_mld_version
,
3587 .maxlen
= sizeof(int),
3589 .proc_handler
= &proc_dointvec
,
3591 #ifdef CONFIG_IPV6_PRIVACY
3593 .ctl_name
= NET_IPV6_USE_TEMPADDR
,
3594 .procname
= "use_tempaddr",
3595 .data
= &ipv6_devconf
.use_tempaddr
,
3596 .maxlen
= sizeof(int),
3598 .proc_handler
= &proc_dointvec
,
3601 .ctl_name
= NET_IPV6_TEMP_VALID_LFT
,
3602 .procname
= "temp_valid_lft",
3603 .data
= &ipv6_devconf
.temp_valid_lft
,
3604 .maxlen
= sizeof(int),
3606 .proc_handler
= &proc_dointvec
,
3609 .ctl_name
= NET_IPV6_TEMP_PREFERED_LFT
,
3610 .procname
= "temp_prefered_lft",
3611 .data
= &ipv6_devconf
.temp_prefered_lft
,
3612 .maxlen
= sizeof(int),
3614 .proc_handler
= &proc_dointvec
,
3617 .ctl_name
= NET_IPV6_REGEN_MAX_RETRY
,
3618 .procname
= "regen_max_retry",
3619 .data
= &ipv6_devconf
.regen_max_retry
,
3620 .maxlen
= sizeof(int),
3622 .proc_handler
= &proc_dointvec
,
3625 .ctl_name
= NET_IPV6_MAX_DESYNC_FACTOR
,
3626 .procname
= "max_desync_factor",
3627 .data
= &ipv6_devconf
.max_desync_factor
,
3628 .maxlen
= sizeof(int),
3630 .proc_handler
= &proc_dointvec
,
3634 .ctl_name
= NET_IPV6_MAX_ADDRESSES
,
3635 .procname
= "max_addresses",
3636 .data
= &ipv6_devconf
.max_addresses
,
3637 .maxlen
= sizeof(int),
3639 .proc_handler
= &proc_dointvec
,
3642 .ctl_name
= NET_IPV6_ACCEPT_RA_DEFRTR
,
3643 .procname
= "accept_ra_defrtr",
3644 .data
= &ipv6_devconf
.accept_ra_defrtr
,
3645 .maxlen
= sizeof(int),
3647 .proc_handler
= &proc_dointvec
,
3650 .ctl_name
= NET_IPV6_ACCEPT_RA_PINFO
,
3651 .procname
= "accept_ra_pinfo",
3652 .data
= &ipv6_devconf
.accept_ra_pinfo
,
3653 .maxlen
= sizeof(int),
3655 .proc_handler
= &proc_dointvec
,
3657 #ifdef CONFIG_IPV6_ROUTER_PREF
3659 .ctl_name
= NET_IPV6_ACCEPT_RA_RTR_PREF
,
3660 .procname
= "accept_ra_rtr_pref",
3661 .data
= &ipv6_devconf
.accept_ra_rtr_pref
,
3662 .maxlen
= sizeof(int),
3664 .proc_handler
= &proc_dointvec
,
3667 .ctl_name
= NET_IPV6_RTR_PROBE_INTERVAL
,
3668 .procname
= "router_probe_interval",
3669 .data
= &ipv6_devconf
.rtr_probe_interval
,
3670 .maxlen
= sizeof(int),
3672 .proc_handler
= &proc_dointvec_jiffies
,
3673 .strategy
= &sysctl_jiffies
,
3675 #ifdef CONFIV_IPV6_ROUTE_INFO
3677 .ctl_name
= NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN
,
3678 .procname
= "accept_ra_rt_info_max_plen",
3679 .data
= &ipv6_devconf
.accept_ra_rt_info_max_plen
,
3680 .maxlen
= sizeof(int),
3682 .proc_handler
= &proc_dointvec
,
3687 .ctl_name
= 0, /* sentinel */
3692 .ctl_name
= NET_PROTO_CONF_ALL
,
3695 .child
= addrconf_sysctl
.addrconf_vars
,
3698 .ctl_name
= 0, /* sentinel */
3701 .addrconf_conf_dir
= {
3703 .ctl_name
= NET_IPV6_CONF
,
3706 .child
= addrconf_sysctl
.addrconf_dev
,
3709 .ctl_name
= 0, /* sentinel */
3712 .addrconf_proto_dir
= {
3714 .ctl_name
= NET_IPV6
,
3717 .child
= addrconf_sysctl
.addrconf_conf_dir
,
3720 .ctl_name
= 0, /* sentinel */
3723 .addrconf_root_dir
= {
3725 .ctl_name
= CTL_NET
,
3728 .child
= addrconf_sysctl
.addrconf_proto_dir
,
3731 .ctl_name
= 0, /* sentinel */
3736 static void addrconf_sysctl_register(struct inet6_dev
*idev
, struct ipv6_devconf
*p
)
3739 struct net_device
*dev
= idev
? idev
->dev
: NULL
;
3740 struct addrconf_sysctl_table
*t
;
3741 char *dev_name
= NULL
;
3743 t
= kmalloc(sizeof(*t
), GFP_KERNEL
);
3746 memcpy(t
, &addrconf_sysctl
, sizeof(*t
));
3747 for (i
=0; t
->addrconf_vars
[i
].data
; i
++) {
3748 t
->addrconf_vars
[i
].data
+= (char*)p
- (char*)&ipv6_devconf
;
3749 t
->addrconf_vars
[i
].de
= NULL
;
3750 t
->addrconf_vars
[i
].extra1
= idev
; /* embedded; no ref */
3753 dev_name
= dev
->name
;
3754 t
->addrconf_dev
[0].ctl_name
= dev
->ifindex
;
3756 dev_name
= "default";
3757 t
->addrconf_dev
[0].ctl_name
= NET_PROTO_CONF_DEFAULT
;
3761 * Make a copy of dev_name, because '.procname' is regarded as const
3762 * by sysctl and we wouldn't want anyone to change it under our feet
3763 * (see SIOCSIFNAME).
3765 dev_name
= kstrdup(dev_name
, GFP_KERNEL
);
3769 t
->addrconf_dev
[0].procname
= dev_name
;
3771 t
->addrconf_dev
[0].child
= t
->addrconf_vars
;
3772 t
->addrconf_dev
[0].de
= NULL
;
3773 t
->addrconf_conf_dir
[0].child
= t
->addrconf_dev
;
3774 t
->addrconf_conf_dir
[0].de
= NULL
;
3775 t
->addrconf_proto_dir
[0].child
= t
->addrconf_conf_dir
;
3776 t
->addrconf_proto_dir
[0].de
= NULL
;
3777 t
->addrconf_root_dir
[0].child
= t
->addrconf_proto_dir
;
3778 t
->addrconf_root_dir
[0].de
= NULL
;
3780 t
->sysctl_header
= register_sysctl_table(t
->addrconf_root_dir
, 0);
3781 if (t
->sysctl_header
== NULL
)
3796 static void addrconf_sysctl_unregister(struct ipv6_devconf
*p
)
3799 struct addrconf_sysctl_table
*t
= p
->sysctl
;
3801 unregister_sysctl_table(t
->sysctl_header
);
3802 kfree(t
->addrconf_dev
[0].procname
);
3814 int register_inet6addr_notifier(struct notifier_block
*nb
)
3816 return atomic_notifier_chain_register(&inet6addr_chain
, nb
);
3819 int unregister_inet6addr_notifier(struct notifier_block
*nb
)
3821 return atomic_notifier_chain_unregister(&inet6addr_chain
,nb
);
3825 * Init / cleanup code
3828 int __init
addrconf_init(void)
3832 /* The addrconf netdev notifier requires that loopback_dev
3833 * has it's ipv6 private information allocated and setup
3834 * before it can bring up and give link-local addresses
3835 * to other devices which are up.
3837 * Unfortunately, loopback_dev is not necessarily the first
3838 * entry in the global dev_base list of net devices. In fact,
3839 * it is likely to be the very last entry on that list.
3840 * So this causes the notifier registry below to try and
3841 * give link-local addresses to all devices besides loopback_dev
3842 * first, then loopback_dev, which cases all the non-loopback_dev
3843 * devices to fail to get a link-local address.
3845 * So, as a temporary fix, allocate the ipv6 structure for
3846 * loopback_dev first by hand.
3847 * Longer term, all of the dependencies ipv6 has upon the loopback
3848 * device and it being up should be removed.
3851 if (!ipv6_add_dev(&loopback_dev
))
3857 ip6_null_entry
.rt6i_idev
= in6_dev_get(&loopback_dev
);
3859 register_netdevice_notifier(&ipv6_dev_notf
);
3862 rtnetlink_links
[PF_INET6
] = inet6_rtnetlink_table
;
3863 #ifdef CONFIG_SYSCTL
3864 addrconf_sysctl
.sysctl_header
=
3865 register_sysctl_table(addrconf_sysctl
.addrconf_root_dir
, 0);
3866 addrconf_sysctl_register(NULL
, &ipv6_devconf_dflt
);
3872 void __exit
addrconf_cleanup(void)
3874 struct net_device
*dev
;
3875 struct inet6_dev
*idev
;
3876 struct inet6_ifaddr
*ifa
;
3879 unregister_netdevice_notifier(&ipv6_dev_notf
);
3881 rtnetlink_links
[PF_INET6
] = NULL
;
3882 #ifdef CONFIG_SYSCTL
3883 addrconf_sysctl_unregister(&ipv6_devconf_dflt
);
3884 addrconf_sysctl_unregister(&ipv6_devconf
);
3893 for (dev
=dev_base
; dev
; dev
=dev
->next
) {
3894 if ((idev
= __in6_dev_get(dev
)) == NULL
)
3896 addrconf_ifdown(dev
, 1);
3898 addrconf_ifdown(&loopback_dev
, 2);
3904 write_lock_bh(&addrconf_hash_lock
);
3905 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
3906 for (ifa
=inet6_addr_lst
[i
]; ifa
; ) {
3907 struct inet6_ifaddr
*bifa
;
3910 ifa
= ifa
->lst_next
;
3911 printk(KERN_DEBUG
"bug: IPv6 address leakage detected: ifa=%p\n", bifa
);
3912 /* Do not free it; something is wrong.
3913 Now we can investigate it with debugger.
3917 write_unlock_bh(&addrconf_hash_lock
);
3919 del_timer(&addr_chk_timer
);
3923 #ifdef CONFIG_PROC_FS
3924 proc_net_remove("if_inet6");