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/config.h>
44 #include <linux/errno.h>
45 #include <linux/types.h>
46 #include <linux/socket.h>
47 #include <linux/sockios.h>
48 #include <linux/sched.h>
49 #include <linux/net.h>
50 #include <linux/in6.h>
51 #include <linux/netdevice.h>
52 #include <linux/if_arp.h>
53 #include <linux/if_arcnet.h>
54 #include <linux/if_infiniband.h>
55 #include <linux/route.h>
56 #include <linux/inetdevice.h>
57 #include <linux/init.h>
59 #include <linux/sysctl.h>
61 #include <linux/capability.h>
62 #include <linux/delay.h>
63 #include <linux/notifier.h>
64 #include <linux/string.h>
70 #include <net/protocol.h>
71 #include <net/ndisc.h>
72 #include <net/ip6_route.h>
73 #include <net/addrconf.h>
76 #include <linux/if_tunnel.h>
77 #include <linux/rtnetlink.h>
79 #ifdef CONFIG_IPV6_PRIVACY
80 #include <linux/random.h>
83 #include <asm/uaccess.h>
85 #include <linux/proc_fs.h>
86 #include <linux/seq_file.h>
88 /* Set to 3 to get tracing... */
92 #define ADBG(x) printk x
97 #define INFINITY_LIFE_TIME 0xFFFFFFFF
98 #define TIME_DELTA(a,b) ((unsigned long)((long)(a) - (long)(b)))
101 static void addrconf_sysctl_register(struct inet6_dev
*idev
, struct ipv6_devconf
*p
);
102 static void addrconf_sysctl_unregister(struct ipv6_devconf
*p
);
105 #ifdef CONFIG_IPV6_PRIVACY
106 static int __ipv6_regen_rndid(struct inet6_dev
*idev
);
107 static int __ipv6_try_regen_rndid(struct inet6_dev
*idev
, struct in6_addr
*tmpaddr
);
108 static void ipv6_regen_rndid(unsigned long data
);
110 static int desync_factor
= MAX_DESYNC_FACTOR
* HZ
;
113 static int ipv6_count_addresses(struct inet6_dev
*idev
);
116 * Configured unicast address hash table
118 static struct inet6_ifaddr
*inet6_addr_lst
[IN6_ADDR_HSIZE
];
119 static DEFINE_RWLOCK(addrconf_hash_lock
);
121 /* Protects inet6 devices */
122 DEFINE_RWLOCK(addrconf_lock
);
124 static void addrconf_verify(unsigned long);
126 static DEFINE_TIMER(addr_chk_timer
, addrconf_verify
, 0, 0);
127 static DEFINE_SPINLOCK(addrconf_verify_lock
);
129 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
);
130 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
);
132 static int addrconf_ifdown(struct net_device
*dev
, int how
);
134 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
);
135 static void addrconf_dad_timer(unsigned long data
);
136 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
);
137 static void addrconf_dad_run(struct inet6_dev
*idev
);
138 static void addrconf_rs_timer(unsigned long data
);
139 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
);
140 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
);
142 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
143 struct prefix_info
*pinfo
);
144 static int ipv6_chk_same_addr(const struct in6_addr
*addr
, struct net_device
*dev
);
146 static ATOMIC_NOTIFIER_HEAD(inet6addr_chain
);
148 struct ipv6_devconf ipv6_devconf
= {
150 .hop_limit
= IPV6_DEFAULT_HOPLIMIT
,
151 .mtu6
= IPV6_MIN_MTU
,
153 .accept_redirects
= 1,
155 .force_mld_version
= 0,
157 .rtr_solicits
= MAX_RTR_SOLICITATIONS
,
158 .rtr_solicit_interval
= RTR_SOLICITATION_INTERVAL
,
159 .rtr_solicit_delay
= MAX_RTR_SOLICITATION_DELAY
,
160 #ifdef CONFIG_IPV6_PRIVACY
162 .temp_valid_lft
= TEMP_VALID_LIFETIME
,
163 .temp_prefered_lft
= TEMP_PREFERRED_LIFETIME
,
164 .regen_max_retry
= REGEN_MAX_RETRY
,
165 .max_desync_factor
= MAX_DESYNC_FACTOR
,
167 .max_addresses
= IPV6_MAX_ADDRESSES
,
168 .accept_ra_defrtr
= 1,
169 .accept_ra_pinfo
= 1,
170 #ifdef CONFIG_IPV6_ROUTER_PREF
171 .accept_ra_rtr_pref
= 1,
172 .rtr_probe_interval
= 60 * HZ
,
173 #ifdef CONFIG_IPV6_ROUTE_INFO
174 .accept_ra_rt_info_max_plen
= 0,
179 static struct ipv6_devconf ipv6_devconf_dflt
= {
181 .hop_limit
= IPV6_DEFAULT_HOPLIMIT
,
182 .mtu6
= IPV6_MIN_MTU
,
184 .accept_redirects
= 1,
187 .rtr_solicits
= MAX_RTR_SOLICITATIONS
,
188 .rtr_solicit_interval
= RTR_SOLICITATION_INTERVAL
,
189 .rtr_solicit_delay
= MAX_RTR_SOLICITATION_DELAY
,
190 #ifdef CONFIG_IPV6_PRIVACY
192 .temp_valid_lft
= TEMP_VALID_LIFETIME
,
193 .temp_prefered_lft
= TEMP_PREFERRED_LIFETIME
,
194 .regen_max_retry
= REGEN_MAX_RETRY
,
195 .max_desync_factor
= MAX_DESYNC_FACTOR
,
197 .max_addresses
= IPV6_MAX_ADDRESSES
,
198 .accept_ra_defrtr
= 1,
199 .accept_ra_pinfo
= 1,
200 #ifdef CONFIG_IPV6_ROUTER_PREF
201 .accept_ra_rtr_pref
= 1,
202 .rtr_probe_interval
= 60 * HZ
,
203 #ifdef CONFIG_IPV6_ROUTE_INFO
204 .accept_ra_rt_info_max_plen
= 0,
209 /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
211 const struct in6_addr in6addr_any
= IN6ADDR_ANY_INIT
;
213 const struct in6_addr in6addr_loopback
= IN6ADDR_LOOPBACK_INIT
;
215 #define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
217 static inline unsigned ipv6_addr_scope2type(unsigned scope
)
220 case IPV6_ADDR_SCOPE_NODELOCAL
:
221 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_NODELOCAL
) |
223 case IPV6_ADDR_SCOPE_LINKLOCAL
:
224 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
) |
225 IPV6_ADDR_LINKLOCAL
);
226 case IPV6_ADDR_SCOPE_SITELOCAL
:
227 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL
) |
228 IPV6_ADDR_SITELOCAL
);
230 return IPV6_ADDR_SCOPE_TYPE(scope
);
233 int __ipv6_addr_type(const struct in6_addr
*addr
)
237 st
= addr
->s6_addr32
[0];
239 /* Consider all addresses with the first three bits different of
240 000 and 111 as unicasts.
242 if ((st
& htonl(0xE0000000)) != htonl(0x00000000) &&
243 (st
& htonl(0xE0000000)) != htonl(0xE0000000))
244 return (IPV6_ADDR_UNICAST
|
245 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
));
247 if ((st
& htonl(0xFF000000)) == htonl(0xFF000000)) {
249 /* addr-select 3.1 */
250 return (IPV6_ADDR_MULTICAST
|
251 ipv6_addr_scope2type(IPV6_ADDR_MC_SCOPE(addr
)));
254 if ((st
& htonl(0xFFC00000)) == htonl(0xFE800000))
255 return (IPV6_ADDR_LINKLOCAL
| IPV6_ADDR_UNICAST
|
256 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
)); /* addr-select 3.1 */
257 if ((st
& htonl(0xFFC00000)) == htonl(0xFEC00000))
258 return (IPV6_ADDR_SITELOCAL
| IPV6_ADDR_UNICAST
|
259 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL
)); /* addr-select 3.1 */
261 if ((addr
->s6_addr32
[0] | addr
->s6_addr32
[1]) == 0) {
262 if (addr
->s6_addr32
[2] == 0) {
263 if (addr
->s6_addr32
[3] == 0)
264 return IPV6_ADDR_ANY
;
266 if (addr
->s6_addr32
[3] == htonl(0x00000001))
267 return (IPV6_ADDR_LOOPBACK
| IPV6_ADDR_UNICAST
|
268 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
)); /* addr-select 3.4 */
270 return (IPV6_ADDR_COMPATv4
| IPV6_ADDR_UNICAST
|
271 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.3 */
274 if (addr
->s6_addr32
[2] == htonl(0x0000ffff))
275 return (IPV6_ADDR_MAPPED
|
276 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.3 */
279 return (IPV6_ADDR_RESERVED
|
280 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.4 */
283 static void addrconf_del_timer(struct inet6_ifaddr
*ifp
)
285 if (del_timer(&ifp
->timer
))
289 enum addrconf_timer_t
296 static void addrconf_mod_timer(struct inet6_ifaddr
*ifp
,
297 enum addrconf_timer_t what
,
300 if (!del_timer(&ifp
->timer
))
305 ifp
->timer
.function
= addrconf_dad_timer
;
308 ifp
->timer
.function
= addrconf_rs_timer
;
312 ifp
->timer
.expires
= jiffies
+ when
;
313 add_timer(&ifp
->timer
);
316 /* Nobody refers to this device, we may destroy it. */
318 void in6_dev_finish_destroy(struct inet6_dev
*idev
)
320 struct net_device
*dev
= idev
->dev
;
321 BUG_TRAP(idev
->addr_list
==NULL
);
322 BUG_TRAP(idev
->mc_list
==NULL
);
323 #ifdef NET_REFCNT_DEBUG
324 printk(KERN_DEBUG
"in6_dev_finish_destroy: %s\n", dev
? dev
->name
: "NIL");
328 printk("Freeing alive inet6 device %p\n", idev
);
331 snmp6_free_dev(idev
);
335 static struct inet6_dev
* ipv6_add_dev(struct net_device
*dev
)
337 struct inet6_dev
*ndev
;
341 if (dev
->mtu
< IPV6_MIN_MTU
)
344 ndev
= kzalloc(sizeof(struct inet6_dev
), GFP_KERNEL
);
349 rwlock_init(&ndev
->lock
);
351 memcpy(&ndev
->cnf
, &ipv6_devconf_dflt
, sizeof(ndev
->cnf
));
352 ndev
->cnf
.mtu6
= dev
->mtu
;
353 ndev
->cnf
.sysctl
= NULL
;
354 ndev
->nd_parms
= neigh_parms_alloc(dev
, &nd_tbl
);
355 if (ndev
->nd_parms
== NULL
) {
359 /* We refer to the device */
362 if (snmp6_alloc_dev(ndev
) < 0) {
364 "%s(): cannot allocate memory for statistics; dev=%s.\n",
365 __FUNCTION__
, dev
->name
));
366 neigh_parms_release(&nd_tbl
, ndev
->nd_parms
);
368 in6_dev_finish_destroy(ndev
);
372 if (snmp6_register_dev(ndev
) < 0) {
374 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
375 __FUNCTION__
, dev
->name
));
376 neigh_parms_release(&nd_tbl
, ndev
->nd_parms
);
378 in6_dev_finish_destroy(ndev
);
382 /* One reference from device. We must do this before
383 * we invoke __ipv6_regen_rndid().
387 #ifdef CONFIG_IPV6_PRIVACY
388 init_timer(&ndev
->regen_timer
);
389 ndev
->regen_timer
.function
= ipv6_regen_rndid
;
390 ndev
->regen_timer
.data
= (unsigned long) ndev
;
391 if ((dev
->flags
&IFF_LOOPBACK
) ||
392 dev
->type
== ARPHRD_TUNNEL
||
393 dev
->type
== ARPHRD_NONE
||
394 dev
->type
== ARPHRD_SIT
) {
396 "%s: Disabled Privacy Extensions\n",
398 ndev
->cnf
.use_tempaddr
= -1;
401 ipv6_regen_rndid((unsigned long) ndev
);
405 if (netif_carrier_ok(dev
))
406 ndev
->if_flags
|= IF_READY
;
408 write_lock_bh(&addrconf_lock
);
410 write_unlock_bh(&addrconf_lock
);
412 ipv6_mc_init_dev(ndev
);
413 ndev
->tstamp
= jiffies
;
415 neigh_sysctl_register(dev
, ndev
->nd_parms
, NET_IPV6
,
416 NET_IPV6_NEIGH
, "ipv6",
417 &ndisc_ifinfo_sysctl_change
,
419 addrconf_sysctl_register(ndev
, &ndev
->cnf
);
424 static struct inet6_dev
* ipv6_find_idev(struct net_device
*dev
)
426 struct inet6_dev
*idev
;
430 if ((idev
= __in6_dev_get(dev
)) == NULL
) {
431 if ((idev
= ipv6_add_dev(dev
)) == NULL
)
435 if (dev
->flags
&IFF_UP
)
441 static void dev_forward_change(struct inet6_dev
*idev
)
443 struct net_device
*dev
;
444 struct inet6_ifaddr
*ifa
;
445 struct in6_addr addr
;
450 if (dev
&& (dev
->flags
& IFF_MULTICAST
)) {
451 ipv6_addr_all_routers(&addr
);
453 if (idev
->cnf
.forwarding
)
454 ipv6_dev_mc_inc(dev
, &addr
);
456 ipv6_dev_mc_dec(dev
, &addr
);
458 for (ifa
=idev
->addr_list
; ifa
; ifa
=ifa
->if_next
) {
459 if (idev
->cnf
.forwarding
)
460 addrconf_join_anycast(ifa
);
462 addrconf_leave_anycast(ifa
);
467 static void addrconf_forward_change(void)
469 struct net_device
*dev
;
470 struct inet6_dev
*idev
;
472 read_lock(&dev_base_lock
);
473 for (dev
=dev_base
; dev
; dev
=dev
->next
) {
474 read_lock(&addrconf_lock
);
475 idev
= __in6_dev_get(dev
);
477 int changed
= (!idev
->cnf
.forwarding
) ^ (!ipv6_devconf
.forwarding
);
478 idev
->cnf
.forwarding
= ipv6_devconf
.forwarding
;
480 dev_forward_change(idev
);
482 read_unlock(&addrconf_lock
);
484 read_unlock(&dev_base_lock
);
488 /* Nobody refers to this ifaddr, destroy it */
490 void inet6_ifa_finish_destroy(struct inet6_ifaddr
*ifp
)
492 BUG_TRAP(ifp
->if_next
==NULL
);
493 BUG_TRAP(ifp
->lst_next
==NULL
);
494 #ifdef NET_REFCNT_DEBUG
495 printk(KERN_DEBUG
"inet6_ifa_finish_destroy\n");
498 in6_dev_put(ifp
->idev
);
500 if (del_timer(&ifp
->timer
))
501 printk("Timer is still running, when freeing ifa=%p\n", ifp
);
504 printk("Freeing alive inet6 address %p\n", ifp
);
507 dst_release(&ifp
->rt
->u
.dst
);
512 /* On success it returns ifp with increased reference count */
514 static struct inet6_ifaddr
*
515 ipv6_add_addr(struct inet6_dev
*idev
, const struct in6_addr
*addr
, int pfxlen
,
516 int scope
, u32 flags
)
518 struct inet6_ifaddr
*ifa
= NULL
;
523 read_lock_bh(&addrconf_lock
);
525 err
= -ENODEV
; /*XXX*/
529 write_lock(&addrconf_hash_lock
);
531 /* Ignore adding duplicate addresses on an interface */
532 if (ipv6_chk_same_addr(addr
, idev
->dev
)) {
533 ADBG(("ipv6_add_addr: already assigned\n"));
538 ifa
= kzalloc(sizeof(struct inet6_ifaddr
), GFP_ATOMIC
);
541 ADBG(("ipv6_add_addr: malloc failed\n"));
546 rt
= addrconf_dst_alloc(idev
, addr
, 0);
552 ipv6_addr_copy(&ifa
->addr
, addr
);
554 spin_lock_init(&ifa
->lock
);
555 init_timer(&ifa
->timer
);
556 ifa
->timer
.data
= (unsigned long) ifa
;
558 ifa
->prefix_len
= pfxlen
;
559 ifa
->flags
= flags
| IFA_F_TENTATIVE
;
560 ifa
->cstamp
= ifa
->tstamp
= jiffies
;
567 /* Add to big hash table */
568 hash
= ipv6_addr_hash(addr
);
570 ifa
->lst_next
= inet6_addr_lst
[hash
];
571 inet6_addr_lst
[hash
] = ifa
;
573 write_unlock(&addrconf_hash_lock
);
575 write_lock(&idev
->lock
);
576 /* Add to inet6_dev unicast addr list. */
577 ifa
->if_next
= idev
->addr_list
;
578 idev
->addr_list
= ifa
;
580 #ifdef CONFIG_IPV6_PRIVACY
581 if (ifa
->flags
&IFA_F_TEMPORARY
) {
582 ifa
->tmp_next
= idev
->tempaddr_list
;
583 idev
->tempaddr_list
= ifa
;
591 write_unlock(&idev
->lock
);
593 read_unlock_bh(&addrconf_lock
);
595 if (likely(err
== 0))
596 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_UP
, ifa
);
604 write_unlock(&addrconf_hash_lock
);
608 /* This function wants to get referenced ifp and releases it before return */
610 static void ipv6_del_addr(struct inet6_ifaddr
*ifp
)
612 struct inet6_ifaddr
*ifa
, **ifap
;
613 struct inet6_dev
*idev
= ifp
->idev
;
615 int deleted
= 0, onlink
= 0;
616 unsigned long expires
= jiffies
;
618 hash
= ipv6_addr_hash(&ifp
->addr
);
622 write_lock_bh(&addrconf_hash_lock
);
623 for (ifap
= &inet6_addr_lst
[hash
]; (ifa
=*ifap
) != NULL
;
624 ifap
= &ifa
->lst_next
) {
626 *ifap
= ifa
->lst_next
;
628 ifa
->lst_next
= NULL
;
632 write_unlock_bh(&addrconf_hash_lock
);
634 write_lock_bh(&idev
->lock
);
635 #ifdef CONFIG_IPV6_PRIVACY
636 if (ifp
->flags
&IFA_F_TEMPORARY
) {
637 for (ifap
= &idev
->tempaddr_list
; (ifa
=*ifap
) != NULL
;
638 ifap
= &ifa
->tmp_next
) {
640 *ifap
= ifa
->tmp_next
;
642 in6_ifa_put(ifp
->ifpub
);
646 ifa
->tmp_next
= NULL
;
653 for (ifap
= &idev
->addr_list
; (ifa
=*ifap
) != NULL
;) {
655 *ifap
= ifa
->if_next
;
658 if (!(ifp
->flags
& IFA_F_PERMANENT
) || onlink
> 0)
662 } else if (ifp
->flags
& IFA_F_PERMANENT
) {
663 if (ipv6_prefix_equal(&ifa
->addr
, &ifp
->addr
,
665 if (ifa
->flags
& IFA_F_PERMANENT
) {
670 unsigned long lifetime
;
675 spin_lock(&ifa
->lock
);
676 lifetime
= min_t(unsigned long,
677 ifa
->valid_lft
, 0x7fffffffUL
/HZ
);
678 if (time_before(expires
,
679 ifa
->tstamp
+ lifetime
* HZ
))
680 expires
= ifa
->tstamp
+ lifetime
* HZ
;
681 spin_unlock(&ifa
->lock
);
685 ifap
= &ifa
->if_next
;
687 write_unlock_bh(&idev
->lock
);
689 ipv6_ifa_notify(RTM_DELADDR
, ifp
);
691 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_DOWN
, ifp
);
693 addrconf_del_timer(ifp
);
696 * Purge or update corresponding prefix
698 * 1) we don't purge prefix here if address was not permanent.
699 * prefix is managed by its own lifetime.
700 * 2) if there're no addresses, delete prefix.
701 * 3) if there're still other permanent address(es),
702 * corresponding prefix is still permanent.
703 * 4) otherwise, update prefix lifetime to the
704 * longest valid lifetime among the corresponding
705 * addresses on the device.
706 * Note: subsequent RA will update lifetime.
710 if ((ifp
->flags
& IFA_F_PERMANENT
) && onlink
< 1) {
711 struct in6_addr prefix
;
714 ipv6_addr_prefix(&prefix
, &ifp
->addr
, ifp
->prefix_len
);
715 rt
= rt6_lookup(&prefix
, NULL
, ifp
->idev
->dev
->ifindex
, 1);
717 if (rt
&& ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0)) {
719 ip6_del_rt(rt
, NULL
, NULL
, NULL
);
721 } else if (!(rt
->rt6i_flags
& RTF_EXPIRES
)) {
722 rt
->rt6i_expires
= expires
;
723 rt
->rt6i_flags
|= RTF_EXPIRES
;
726 dst_release(&rt
->u
.dst
);
732 #ifdef CONFIG_IPV6_PRIVACY
733 static int ipv6_create_tempaddr(struct inet6_ifaddr
*ifp
, struct inet6_ifaddr
*ift
)
735 struct inet6_dev
*idev
= ifp
->idev
;
736 struct in6_addr addr
, *tmpaddr
;
737 unsigned long tmp_prefered_lft
, tmp_valid_lft
, tmp_cstamp
, tmp_tstamp
;
742 write_lock(&idev
->lock
);
744 spin_lock_bh(&ift
->lock
);
745 memcpy(&addr
.s6_addr
[8], &ift
->addr
.s6_addr
[8], 8);
746 spin_unlock_bh(&ift
->lock
);
753 if (idev
->cnf
.use_tempaddr
<= 0) {
754 write_unlock(&idev
->lock
);
756 "ipv6_create_tempaddr(): use_tempaddr is disabled.\n");
761 spin_lock_bh(&ifp
->lock
);
762 if (ifp
->regen_count
++ >= idev
->cnf
.regen_max_retry
) {
763 idev
->cnf
.use_tempaddr
= -1; /*XXX*/
764 spin_unlock_bh(&ifp
->lock
);
765 write_unlock(&idev
->lock
);
767 "ipv6_create_tempaddr(): regeneration time exceeded. disabled temporary address support.\n");
773 memcpy(addr
.s6_addr
, ifp
->addr
.s6_addr
, 8);
774 if (__ipv6_try_regen_rndid(idev
, tmpaddr
) < 0) {
775 spin_unlock_bh(&ifp
->lock
);
776 write_unlock(&idev
->lock
);
778 "ipv6_create_tempaddr(): regeneration of randomized interface id failed.\n");
784 memcpy(&addr
.s6_addr
[8], idev
->rndid
, 8);
785 tmp_valid_lft
= min_t(__u32
,
787 idev
->cnf
.temp_valid_lft
);
788 tmp_prefered_lft
= min_t(__u32
,
790 idev
->cnf
.temp_prefered_lft
- desync_factor
/ HZ
);
791 tmp_plen
= ifp
->prefix_len
;
792 max_addresses
= idev
->cnf
.max_addresses
;
793 tmp_cstamp
= ifp
->cstamp
;
794 tmp_tstamp
= ifp
->tstamp
;
795 spin_unlock_bh(&ifp
->lock
);
797 write_unlock(&idev
->lock
);
798 ift
= !max_addresses
||
799 ipv6_count_addresses(idev
) < max_addresses
?
800 ipv6_add_addr(idev
, &addr
, tmp_plen
,
801 ipv6_addr_type(&addr
)&IPV6_ADDR_SCOPE_MASK
, IFA_F_TEMPORARY
) : NULL
;
802 if (!ift
|| IS_ERR(ift
)) {
806 "ipv6_create_tempaddr(): retry temporary address regeneration.\n");
808 write_lock(&idev
->lock
);
812 spin_lock_bh(&ift
->lock
);
814 ift
->valid_lft
= tmp_valid_lft
;
815 ift
->prefered_lft
= tmp_prefered_lft
;
816 ift
->cstamp
= tmp_cstamp
;
817 ift
->tstamp
= tmp_tstamp
;
818 spin_unlock_bh(&ift
->lock
);
820 addrconf_dad_start(ift
, 0);
829 * Choose an appropriate source address (RFC3484)
831 struct ipv6_saddr_score
{
839 #define IPV6_SADDR_SCORE_LOCAL 0x0001
840 #define IPV6_SADDR_SCORE_PREFERRED 0x0004
841 #define IPV6_SADDR_SCORE_HOA 0x0008
842 #define IPV6_SADDR_SCORE_OIF 0x0010
843 #define IPV6_SADDR_SCORE_LABEL 0x0020
844 #define IPV6_SADDR_SCORE_PRIVACY 0x0040
846 static int inline ipv6_saddr_preferred(int type
)
848 if (type
& (IPV6_ADDR_MAPPED
|IPV6_ADDR_COMPATv4
|
849 IPV6_ADDR_LOOPBACK
|IPV6_ADDR_RESERVED
))
854 /* static matching label */
855 static int inline ipv6_saddr_label(const struct in6_addr
*addr
, int type
)
858 * prefix (longest match) label
859 * -----------------------------
868 if (type
& IPV6_ADDR_LOOPBACK
)
870 else if (type
& IPV6_ADDR_COMPATv4
)
872 else if (type
& IPV6_ADDR_MAPPED
)
874 else if (addr
->s6_addr32
[0] == htonl(0x20010000))
876 else if (addr
->s6_addr16
[0] == htons(0x2002))
878 else if ((addr
->s6_addr
[0] & 0xfe) == 0xfc)
883 int ipv6_dev_get_saddr(struct net_device
*daddr_dev
,
884 struct in6_addr
*daddr
, struct in6_addr
*saddr
)
886 struct ipv6_saddr_score hiscore
;
887 struct inet6_ifaddr
*ifa_result
= NULL
;
888 int daddr_type
= __ipv6_addr_type(daddr
);
889 int daddr_scope
= __ipv6_addr_src_scope(daddr_type
);
890 u32 daddr_label
= ipv6_saddr_label(daddr
, daddr_type
);
891 struct net_device
*dev
;
893 memset(&hiscore
, 0, sizeof(hiscore
));
895 read_lock(&dev_base_lock
);
896 read_lock(&addrconf_lock
);
898 for (dev
= dev_base
; dev
; dev
=dev
->next
) {
899 struct inet6_dev
*idev
;
900 struct inet6_ifaddr
*ifa
;
902 /* Rule 0: Candidate Source Address (section 4)
903 * - multicast and link-local destination address,
904 * the set of candidate source address MUST only
905 * include addresses assigned to interfaces
906 * belonging to the same link as the outgoing
908 * (- For site-local destination addresses, the
909 * set of candidate source addresses MUST only
910 * include addresses assigned to interfaces
911 * belonging to the same site as the outgoing
914 if ((daddr_type
& IPV6_ADDR_MULTICAST
||
915 daddr_scope
<= IPV6_ADDR_SCOPE_LINKLOCAL
) &&
916 daddr_dev
&& dev
!= daddr_dev
)
919 idev
= __in6_dev_get(dev
);
923 read_lock_bh(&idev
->lock
);
924 for (ifa
= idev
->addr_list
; ifa
; ifa
= ifa
->if_next
) {
925 struct ipv6_saddr_score score
;
927 score
.addr_type
= __ipv6_addr_type(&ifa
->addr
);
930 * - Tentative Address (RFC2462 section 5.4)
931 * - A tentative address is not considered
932 * "assigned to an interface" in the traditional
934 * - Candidate Source Address (section 4)
935 * - In any case, anycast addresses, multicast
936 * addresses, and the unspecified address MUST
937 * NOT be included in a candidate set.
939 if (ifa
->flags
& IFA_F_TENTATIVE
)
941 if (unlikely(score
.addr_type
== IPV6_ADDR_ANY
||
942 score
.addr_type
& IPV6_ADDR_MULTICAST
)) {
943 LIMIT_NETDEBUG(KERN_DEBUG
944 "ADDRCONF: unspecified / multicast address"
945 "assigned as unicast address on %s",
955 if (ifa_result
== NULL
) {
956 /* record it if the first available entry */
960 /* Rule 1: Prefer same address */
961 if (hiscore
.rule
< 1) {
962 if (ipv6_addr_equal(&ifa_result
->addr
, daddr
))
963 hiscore
.attrs
|= IPV6_SADDR_SCORE_LOCAL
;
966 if (ipv6_addr_equal(&ifa
->addr
, daddr
)) {
967 score
.attrs
|= IPV6_SADDR_SCORE_LOCAL
;
968 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_LOCAL
)) {
973 if (hiscore
.attrs
& IPV6_SADDR_SCORE_LOCAL
)
977 /* Rule 2: Prefer appropriate scope */
978 if (hiscore
.rule
< 2) {
979 hiscore
.scope
= __ipv6_addr_src_scope(hiscore
.addr_type
);
982 score
.scope
= __ipv6_addr_src_scope(score
.addr_type
);
983 if (hiscore
.scope
< score
.scope
) {
984 if (hiscore
.scope
< daddr_scope
) {
989 } else if (score
.scope
< hiscore
.scope
) {
990 if (score
.scope
< daddr_scope
)
998 /* Rule 3: Avoid deprecated address */
999 if (hiscore
.rule
< 3) {
1000 if (ipv6_saddr_preferred(hiscore
.addr_type
) ||
1001 !(ifa_result
->flags
& IFA_F_DEPRECATED
))
1002 hiscore
.attrs
|= IPV6_SADDR_SCORE_PREFERRED
;
1005 if (ipv6_saddr_preferred(score
.addr_type
) ||
1006 !(ifa
->flags
& IFA_F_DEPRECATED
)) {
1007 score
.attrs
|= IPV6_SADDR_SCORE_PREFERRED
;
1008 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_PREFERRED
)) {
1013 if (hiscore
.attrs
& IPV6_SADDR_SCORE_PREFERRED
)
1017 /* Rule 4: Prefer home address -- not implemented yet */
1018 if (hiscore
.rule
< 4)
1021 /* Rule 5: Prefer outgoing interface */
1022 if (hiscore
.rule
< 5) {
1023 if (daddr_dev
== NULL
||
1024 daddr_dev
== ifa_result
->idev
->dev
)
1025 hiscore
.attrs
|= IPV6_SADDR_SCORE_OIF
;
1028 if (daddr_dev
== NULL
||
1029 daddr_dev
== ifa
->idev
->dev
) {
1030 score
.attrs
|= IPV6_SADDR_SCORE_OIF
;
1031 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_OIF
)) {
1036 if (hiscore
.attrs
& IPV6_SADDR_SCORE_OIF
)
1040 /* Rule 6: Prefer matching label */
1041 if (hiscore
.rule
< 6) {
1042 if (ipv6_saddr_label(&ifa_result
->addr
, hiscore
.addr_type
) == daddr_label
)
1043 hiscore
.attrs
|= IPV6_SADDR_SCORE_LABEL
;
1046 if (ipv6_saddr_label(&ifa
->addr
, score
.addr_type
) == daddr_label
) {
1047 score
.attrs
|= IPV6_SADDR_SCORE_LABEL
;
1048 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_LABEL
)) {
1053 if (hiscore
.attrs
& IPV6_SADDR_SCORE_LABEL
)
1057 #ifdef CONFIG_IPV6_PRIVACY
1058 /* Rule 7: Prefer public address
1059 * Note: prefer temprary address if use_tempaddr >= 2
1061 if (hiscore
.rule
< 7) {
1062 if ((!(ifa_result
->flags
& IFA_F_TEMPORARY
)) ^
1063 (ifa_result
->idev
->cnf
.use_tempaddr
>= 2))
1064 hiscore
.attrs
|= IPV6_SADDR_SCORE_PRIVACY
;
1067 if ((!(ifa
->flags
& IFA_F_TEMPORARY
)) ^
1068 (ifa
->idev
->cnf
.use_tempaddr
>= 2)) {
1069 score
.attrs
|= IPV6_SADDR_SCORE_PRIVACY
;
1070 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_PRIVACY
)) {
1075 if (hiscore
.attrs
& IPV6_SADDR_SCORE_PRIVACY
)
1079 if (hiscore
.rule
< 7)
1082 /* Rule 8: Use longest matching prefix */
1083 if (hiscore
.rule
< 8) {
1084 hiscore
.matchlen
= ipv6_addr_diff(&ifa_result
->addr
, daddr
);
1087 score
.matchlen
= ipv6_addr_diff(&ifa
->addr
, daddr
);
1088 if (score
.matchlen
> hiscore
.matchlen
) {
1093 else if (score
.matchlen
< hiscore
.matchlen
)
1097 /* Final Rule: choose first available one */
1101 in6_ifa_put(ifa_result
);
1106 read_unlock_bh(&idev
->lock
);
1108 read_unlock(&addrconf_lock
);
1109 read_unlock(&dev_base_lock
);
1112 return -EADDRNOTAVAIL
;
1114 ipv6_addr_copy(saddr
, &ifa_result
->addr
);
1115 in6_ifa_put(ifa_result
);
1120 int ipv6_get_saddr(struct dst_entry
*dst
,
1121 struct in6_addr
*daddr
, struct in6_addr
*saddr
)
1123 return ipv6_dev_get_saddr(dst
? ((struct rt6_info
*)dst
)->rt6i_idev
->dev
: NULL
, daddr
, saddr
);
1127 int ipv6_get_lladdr(struct net_device
*dev
, struct in6_addr
*addr
)
1129 struct inet6_dev
*idev
;
1130 int err
= -EADDRNOTAVAIL
;
1132 read_lock(&addrconf_lock
);
1133 if ((idev
= __in6_dev_get(dev
)) != NULL
) {
1134 struct inet6_ifaddr
*ifp
;
1136 read_lock_bh(&idev
->lock
);
1137 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1138 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1139 ipv6_addr_copy(addr
, &ifp
->addr
);
1144 read_unlock_bh(&idev
->lock
);
1146 read_unlock(&addrconf_lock
);
1150 static int ipv6_count_addresses(struct inet6_dev
*idev
)
1153 struct inet6_ifaddr
*ifp
;
1155 read_lock_bh(&idev
->lock
);
1156 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
)
1158 read_unlock_bh(&idev
->lock
);
1162 int ipv6_chk_addr(struct in6_addr
*addr
, struct net_device
*dev
, int strict
)
1164 struct inet6_ifaddr
* ifp
;
1165 u8 hash
= ipv6_addr_hash(addr
);
1167 read_lock_bh(&addrconf_hash_lock
);
1168 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1169 if (ipv6_addr_equal(&ifp
->addr
, addr
) &&
1170 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1171 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1172 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
))
1176 read_unlock_bh(&addrconf_hash_lock
);
1181 int ipv6_chk_same_addr(const struct in6_addr
*addr
, struct net_device
*dev
)
1183 struct inet6_ifaddr
* ifp
;
1184 u8 hash
= ipv6_addr_hash(addr
);
1186 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1187 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1188 if (dev
== NULL
|| ifp
->idev
->dev
== dev
)
1195 struct inet6_ifaddr
* ipv6_get_ifaddr(struct in6_addr
*addr
, struct net_device
*dev
, int strict
)
1197 struct inet6_ifaddr
* ifp
;
1198 u8 hash
= ipv6_addr_hash(addr
);
1200 read_lock_bh(&addrconf_hash_lock
);
1201 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1202 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1203 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1204 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
)) {
1210 read_unlock_bh(&addrconf_hash_lock
);
1215 int ipv6_rcv_saddr_equal(const struct sock
*sk
, const struct sock
*sk2
)
1217 const struct in6_addr
*sk_rcv_saddr6
= &inet6_sk(sk
)->rcv_saddr
;
1218 const struct in6_addr
*sk2_rcv_saddr6
= inet6_rcv_saddr(sk2
);
1219 u32 sk_rcv_saddr
= inet_sk(sk
)->rcv_saddr
;
1220 u32 sk2_rcv_saddr
= inet_rcv_saddr(sk2
);
1221 int sk_ipv6only
= ipv6_only_sock(sk
);
1222 int sk2_ipv6only
= inet_v6_ipv6only(sk2
);
1223 int addr_type
= ipv6_addr_type(sk_rcv_saddr6
);
1224 int addr_type2
= sk2_rcv_saddr6
? ipv6_addr_type(sk2_rcv_saddr6
) : IPV6_ADDR_MAPPED
;
1226 if (!sk2_rcv_saddr
&& !sk_ipv6only
)
1229 if (addr_type2
== IPV6_ADDR_ANY
&&
1230 !(sk2_ipv6only
&& addr_type
== IPV6_ADDR_MAPPED
))
1233 if (addr_type
== IPV6_ADDR_ANY
&&
1234 !(sk_ipv6only
&& addr_type2
== IPV6_ADDR_MAPPED
))
1237 if (sk2_rcv_saddr6
&&
1238 ipv6_addr_equal(sk_rcv_saddr6
, sk2_rcv_saddr6
))
1241 if (addr_type
== IPV6_ADDR_MAPPED
&&
1243 (!sk2_rcv_saddr
|| !sk_rcv_saddr
|| sk_rcv_saddr
== sk2_rcv_saddr
))
1249 /* Gets referenced address, destroys ifaddr */
1251 static void addrconf_dad_stop(struct inet6_ifaddr
*ifp
)
1253 if (ifp
->flags
&IFA_F_PERMANENT
) {
1254 spin_lock_bh(&ifp
->lock
);
1255 addrconf_del_timer(ifp
);
1256 ifp
->flags
|= IFA_F_TENTATIVE
;
1257 spin_unlock_bh(&ifp
->lock
);
1259 #ifdef CONFIG_IPV6_PRIVACY
1260 } else if (ifp
->flags
&IFA_F_TEMPORARY
) {
1261 struct inet6_ifaddr
*ifpub
;
1262 spin_lock_bh(&ifp
->lock
);
1265 in6_ifa_hold(ifpub
);
1266 spin_unlock_bh(&ifp
->lock
);
1267 ipv6_create_tempaddr(ifpub
, ifp
);
1270 spin_unlock_bh(&ifp
->lock
);
1278 void addrconf_dad_failure(struct inet6_ifaddr
*ifp
)
1280 if (net_ratelimit())
1281 printk(KERN_INFO
"%s: duplicate address detected!\n", ifp
->idev
->dev
->name
);
1282 addrconf_dad_stop(ifp
);
1285 /* Join to solicited addr multicast group. */
1287 void addrconf_join_solict(struct net_device
*dev
, struct in6_addr
*addr
)
1289 struct in6_addr maddr
;
1291 if (dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1294 addrconf_addr_solict_mult(addr
, &maddr
);
1295 ipv6_dev_mc_inc(dev
, &maddr
);
1298 void addrconf_leave_solict(struct inet6_dev
*idev
, struct in6_addr
*addr
)
1300 struct in6_addr maddr
;
1302 if (idev
->dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1305 addrconf_addr_solict_mult(addr
, &maddr
);
1306 __ipv6_dev_mc_dec(idev
, &maddr
);
1309 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
)
1311 struct in6_addr addr
;
1312 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1313 if (ipv6_addr_any(&addr
))
1315 ipv6_dev_ac_inc(ifp
->idev
->dev
, &addr
);
1318 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
)
1320 struct in6_addr addr
;
1321 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1322 if (ipv6_addr_any(&addr
))
1324 __ipv6_dev_ac_dec(ifp
->idev
, &addr
);
1327 static int addrconf_ifid_eui48(u8
*eui
, struct net_device
*dev
)
1329 if (dev
->addr_len
!= ETH_ALEN
)
1331 memcpy(eui
, dev
->dev_addr
, 3);
1332 memcpy(eui
+ 5, dev
->dev_addr
+ 3, 3);
1335 * The zSeries OSA network cards can be shared among various
1336 * OS instances, but the OSA cards have only one MAC address.
1337 * This leads to duplicate address conflicts in conjunction
1338 * with IPv6 if more than one instance uses the same card.
1340 * The driver for these cards can deliver a unique 16-bit
1341 * identifier for each instance sharing the same card. It is
1342 * placed instead of 0xFFFE in the interface identifier. The
1343 * "u" bit of the interface identifier is not inverted in this
1344 * case. Hence the resulting interface identifier has local
1345 * scope according to RFC2373.
1348 eui
[3] = (dev
->dev_id
>> 8) & 0xFF;
1349 eui
[4] = dev
->dev_id
& 0xFF;
1358 static int addrconf_ifid_arcnet(u8
*eui
, struct net_device
*dev
)
1360 /* XXX: inherit EUI-64 from other interface -- yoshfuji */
1361 if (dev
->addr_len
!= ARCNET_ALEN
)
1364 eui
[7] = *(u8
*)dev
->dev_addr
;
1368 static int addrconf_ifid_infiniband(u8
*eui
, struct net_device
*dev
)
1370 if (dev
->addr_len
!= INFINIBAND_ALEN
)
1372 memcpy(eui
, dev
->dev_addr
+ 12, 8);
1377 static int ipv6_generate_eui64(u8
*eui
, struct net_device
*dev
)
1379 switch (dev
->type
) {
1382 case ARPHRD_IEEE802_TR
:
1383 return addrconf_ifid_eui48(eui
, dev
);
1385 return addrconf_ifid_arcnet(eui
, dev
);
1386 case ARPHRD_INFINIBAND
:
1387 return addrconf_ifid_infiniband(eui
, dev
);
1392 static int ipv6_inherit_eui64(u8
*eui
, struct inet6_dev
*idev
)
1395 struct inet6_ifaddr
*ifp
;
1397 read_lock_bh(&idev
->lock
);
1398 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1399 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1400 memcpy(eui
, ifp
->addr
.s6_addr
+8, 8);
1405 read_unlock_bh(&idev
->lock
);
1409 #ifdef CONFIG_IPV6_PRIVACY
1410 /* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */
1411 static int __ipv6_regen_rndid(struct inet6_dev
*idev
)
1414 get_random_bytes(idev
->rndid
, sizeof(idev
->rndid
));
1415 idev
->rndid
[0] &= ~0x02;
1418 * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>:
1419 * check if generated address is not inappropriate
1421 * - Reserved subnet anycast (RFC 2526)
1422 * 11111101 11....11 1xxxxxxx
1423 * - ISATAP (draft-ietf-ngtrans-isatap-13.txt) 5.1
1424 * 00-00-5E-FE-xx-xx-xx-xx
1426 * - XXX: already assigned to an address on the device
1428 if (idev
->rndid
[0] == 0xfd &&
1429 (idev
->rndid
[1]&idev
->rndid
[2]&idev
->rndid
[3]&idev
->rndid
[4]&idev
->rndid
[5]&idev
->rndid
[6]) == 0xff &&
1430 (idev
->rndid
[7]&0x80))
1432 if ((idev
->rndid
[0]|idev
->rndid
[1]) == 0) {
1433 if (idev
->rndid
[2] == 0x5e && idev
->rndid
[3] == 0xfe)
1435 if ((idev
->rndid
[2]|idev
->rndid
[3]|idev
->rndid
[4]|idev
->rndid
[5]|idev
->rndid
[6]|idev
->rndid
[7]) == 0x00)
1442 static void ipv6_regen_rndid(unsigned long data
)
1444 struct inet6_dev
*idev
= (struct inet6_dev
*) data
;
1445 unsigned long expires
;
1447 read_lock_bh(&addrconf_lock
);
1448 write_lock_bh(&idev
->lock
);
1453 if (__ipv6_regen_rndid(idev
) < 0)
1457 idev
->cnf
.temp_prefered_lft
* HZ
-
1458 idev
->cnf
.regen_max_retry
* idev
->cnf
.dad_transmits
* idev
->nd_parms
->retrans_time
- desync_factor
;
1459 if (time_before(expires
, jiffies
)) {
1461 "ipv6_regen_rndid(): too short regeneration interval; timer disabled for %s.\n",
1466 if (!mod_timer(&idev
->regen_timer
, expires
))
1470 write_unlock_bh(&idev
->lock
);
1471 read_unlock_bh(&addrconf_lock
);
1475 static int __ipv6_try_regen_rndid(struct inet6_dev
*idev
, struct in6_addr
*tmpaddr
) {
1478 if (tmpaddr
&& memcmp(idev
->rndid
, &tmpaddr
->s6_addr
[8], 8) == 0)
1479 ret
= __ipv6_regen_rndid(idev
);
1489 addrconf_prefix_route(struct in6_addr
*pfx
, int plen
, struct net_device
*dev
,
1490 unsigned long expires
, u32 flags
)
1492 struct in6_rtmsg rtmsg
;
1494 memset(&rtmsg
, 0, sizeof(rtmsg
));
1495 ipv6_addr_copy(&rtmsg
.rtmsg_dst
, pfx
);
1496 rtmsg
.rtmsg_dst_len
= plen
;
1497 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1498 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1499 rtmsg
.rtmsg_info
= expires
;
1500 rtmsg
.rtmsg_flags
= RTF_UP
|flags
;
1501 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1503 /* Prevent useless cloning on PtP SIT.
1504 This thing is done here expecting that the whole
1505 class of non-broadcast devices need not cloning.
1507 if (dev
->type
== ARPHRD_SIT
&& (dev
->flags
&IFF_POINTOPOINT
))
1508 rtmsg
.rtmsg_flags
|= RTF_NONEXTHOP
;
1510 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
);
1513 /* Create "default" multicast route to the interface */
1515 static void addrconf_add_mroute(struct net_device
*dev
)
1517 struct in6_rtmsg rtmsg
;
1519 memset(&rtmsg
, 0, sizeof(rtmsg
));
1520 ipv6_addr_set(&rtmsg
.rtmsg_dst
,
1521 htonl(0xFF000000), 0, 0, 0);
1522 rtmsg
.rtmsg_dst_len
= 8;
1523 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1524 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1525 rtmsg
.rtmsg_flags
= RTF_UP
;
1526 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1527 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
);
1530 static void sit_route_add(struct net_device
*dev
)
1532 struct in6_rtmsg rtmsg
;
1534 memset(&rtmsg
, 0, sizeof(rtmsg
));
1536 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1537 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1539 /* prefix length - 96 bits "::d.d.d.d" */
1540 rtmsg
.rtmsg_dst_len
= 96;
1541 rtmsg
.rtmsg_flags
= RTF_UP
|RTF_NONEXTHOP
;
1542 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1544 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
);
1547 static void addrconf_add_lroute(struct net_device
*dev
)
1549 struct in6_addr addr
;
1551 ipv6_addr_set(&addr
, htonl(0xFE800000), 0, 0, 0);
1552 addrconf_prefix_route(&addr
, 64, dev
, 0, 0);
1555 static struct inet6_dev
*addrconf_add_dev(struct net_device
*dev
)
1557 struct inet6_dev
*idev
;
1561 if ((idev
= ipv6_find_idev(dev
)) == NULL
)
1564 /* Add default multicast route */
1565 addrconf_add_mroute(dev
);
1567 /* Add link local route */
1568 addrconf_add_lroute(dev
);
1572 void addrconf_prefix_rcv(struct net_device
*dev
, u8
*opt
, int len
)
1574 struct prefix_info
*pinfo
;
1578 unsigned long rt_expires
;
1579 struct inet6_dev
*in6_dev
;
1581 pinfo
= (struct prefix_info
*) opt
;
1583 if (len
< sizeof(struct prefix_info
)) {
1584 ADBG(("addrconf: prefix option too short\n"));
1589 * Validation checks ([ADDRCONF], page 19)
1592 addr_type
= ipv6_addr_type(&pinfo
->prefix
);
1594 if (addr_type
& (IPV6_ADDR_MULTICAST
|IPV6_ADDR_LINKLOCAL
))
1597 valid_lft
= ntohl(pinfo
->valid
);
1598 prefered_lft
= ntohl(pinfo
->prefered
);
1600 if (prefered_lft
> valid_lft
) {
1601 if (net_ratelimit())
1602 printk(KERN_WARNING
"addrconf: prefix option has invalid lifetime\n");
1606 in6_dev
= in6_dev_get(dev
);
1608 if (in6_dev
== NULL
) {
1609 if (net_ratelimit())
1610 printk(KERN_DEBUG
"addrconf: device %s not configured\n", dev
->name
);
1615 * Two things going on here:
1616 * 1) Add routes for on-link prefixes
1617 * 2) Configure prefixes with the auto flag set
1620 /* Avoid arithmetic overflow. Really, we could
1621 save rt_expires in seconds, likely valid_lft,
1622 but it would require division in fib gc, that it
1625 if (valid_lft
>= 0x7FFFFFFF/HZ
)
1626 rt_expires
= 0x7FFFFFFF - (0x7FFFFFFF % HZ
);
1628 rt_expires
= valid_lft
* HZ
;
1631 * We convert this (in jiffies) to clock_t later.
1632 * Avoid arithmetic overflow there as well.
1633 * Overflow can happen only if HZ < USER_HZ.
1635 if (HZ
< USER_HZ
&& rt_expires
> 0x7FFFFFFF / USER_HZ
)
1636 rt_expires
= 0x7FFFFFFF / USER_HZ
;
1638 if (pinfo
->onlink
) {
1639 struct rt6_info
*rt
;
1640 rt
= rt6_lookup(&pinfo
->prefix
, NULL
, dev
->ifindex
, 1);
1642 if (rt
&& ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0)) {
1643 if (rt
->rt6i_flags
&RTF_EXPIRES
) {
1644 if (valid_lft
== 0) {
1645 ip6_del_rt(rt
, NULL
, NULL
, NULL
);
1648 rt
->rt6i_expires
= jiffies
+ rt_expires
;
1651 } else if (valid_lft
) {
1652 addrconf_prefix_route(&pinfo
->prefix
, pinfo
->prefix_len
,
1653 dev
, jiffies_to_clock_t(rt_expires
), RTF_ADDRCONF
|RTF_EXPIRES
|RTF_PREFIX_RT
);
1656 dst_release(&rt
->u
.dst
);
1659 /* Try to figure out our local address for this prefix */
1661 if (pinfo
->autoconf
&& in6_dev
->cnf
.autoconf
) {
1662 struct inet6_ifaddr
* ifp
;
1663 struct in6_addr addr
;
1664 int create
= 0, update_lft
= 0;
1666 if (pinfo
->prefix_len
== 64) {
1667 memcpy(&addr
, &pinfo
->prefix
, 8);
1668 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) &&
1669 ipv6_inherit_eui64(addr
.s6_addr
+ 8, in6_dev
)) {
1670 in6_dev_put(in6_dev
);
1675 if (net_ratelimit())
1676 printk(KERN_DEBUG
"IPv6 addrconf: prefix with wrong length %d\n",
1678 in6_dev_put(in6_dev
);
1683 ifp
= ipv6_get_ifaddr(&addr
, dev
, 1);
1685 if (ifp
== NULL
&& valid_lft
) {
1686 int max_addresses
= in6_dev
->cnf
.max_addresses
;
1688 /* Do not allow to create too much of autoconfigured
1689 * addresses; this would be too easy way to crash kernel.
1691 if (!max_addresses
||
1692 ipv6_count_addresses(in6_dev
) < max_addresses
)
1693 ifp
= ipv6_add_addr(in6_dev
, &addr
, pinfo
->prefix_len
,
1694 addr_type
&IPV6_ADDR_SCOPE_MASK
, 0);
1696 if (!ifp
|| IS_ERR(ifp
)) {
1697 in6_dev_put(in6_dev
);
1701 update_lft
= create
= 1;
1702 ifp
->cstamp
= jiffies
;
1703 addrconf_dad_start(ifp
, RTF_ADDRCONF
|RTF_PREFIX_RT
);
1709 #ifdef CONFIG_IPV6_PRIVACY
1710 struct inet6_ifaddr
*ift
;
1714 /* update lifetime (RFC2462 5.5.3 e) */
1715 spin_lock(&ifp
->lock
);
1717 if (ifp
->valid_lft
> (now
- ifp
->tstamp
) / HZ
)
1718 stored_lft
= ifp
->valid_lft
- (now
- ifp
->tstamp
) / HZ
;
1721 if (!update_lft
&& stored_lft
) {
1722 if (valid_lft
> MIN_VALID_LIFETIME
||
1723 valid_lft
> stored_lft
)
1725 else if (stored_lft
<= MIN_VALID_LIFETIME
) {
1726 /* valid_lft <= stored_lft is always true */
1730 valid_lft
= MIN_VALID_LIFETIME
;
1731 if (valid_lft
< prefered_lft
)
1732 prefered_lft
= valid_lft
;
1738 ifp
->valid_lft
= valid_lft
;
1739 ifp
->prefered_lft
= prefered_lft
;
1742 ifp
->flags
&= ~IFA_F_DEPRECATED
;
1743 spin_unlock(&ifp
->lock
);
1745 if (!(flags
&IFA_F_TENTATIVE
))
1746 ipv6_ifa_notify(0, ifp
);
1748 spin_unlock(&ifp
->lock
);
1750 #ifdef CONFIG_IPV6_PRIVACY
1751 read_lock_bh(&in6_dev
->lock
);
1752 /* update all temporary addresses in the list */
1753 for (ift
=in6_dev
->tempaddr_list
; ift
; ift
=ift
->tmp_next
) {
1755 * When adjusting the lifetimes of an existing
1756 * temporary address, only lower the lifetimes.
1757 * Implementations must not increase the
1758 * lifetimes of an existing temporary address
1759 * when processing a Prefix Information Option.
1761 spin_lock(&ift
->lock
);
1763 if (ift
->valid_lft
> valid_lft
&&
1764 ift
->valid_lft
- valid_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1765 ift
->valid_lft
= valid_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1766 if (ift
->prefered_lft
> prefered_lft
&&
1767 ift
->prefered_lft
- prefered_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1768 ift
->prefered_lft
= prefered_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1769 spin_unlock(&ift
->lock
);
1770 if (!(flags
&IFA_F_TENTATIVE
))
1771 ipv6_ifa_notify(0, ift
);
1774 if (create
&& in6_dev
->cnf
.use_tempaddr
> 0) {
1776 * When a new public address is created as described in [ADDRCONF],
1777 * also create a new temporary address.
1779 read_unlock_bh(&in6_dev
->lock
);
1780 ipv6_create_tempaddr(ifp
, NULL
);
1782 read_unlock_bh(&in6_dev
->lock
);
1789 inet6_prefix_notify(RTM_NEWPREFIX
, in6_dev
, pinfo
);
1790 in6_dev_put(in6_dev
);
1794 * Set destination address.
1795 * Special case for SIT interfaces where we create a new "virtual"
1798 int addrconf_set_dstaddr(void __user
*arg
)
1800 struct in6_ifreq ireq
;
1801 struct net_device
*dev
;
1807 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1810 dev
= __dev_get_by_index(ireq
.ifr6_ifindex
);
1816 if (dev
->type
== ARPHRD_SIT
) {
1819 struct ip_tunnel_parm p
;
1821 err
= -EADDRNOTAVAIL
;
1822 if (!(ipv6_addr_type(&ireq
.ifr6_addr
) & IPV6_ADDR_COMPATv4
))
1825 memset(&p
, 0, sizeof(p
));
1826 p
.iph
.daddr
= ireq
.ifr6_addr
.s6_addr32
[3];
1830 p
.iph
.protocol
= IPPROTO_IPV6
;
1832 ifr
.ifr_ifru
.ifru_data
= (void __user
*)&p
;
1834 oldfs
= get_fs(); set_fs(KERNEL_DS
);
1835 err
= dev
->do_ioctl(dev
, &ifr
, SIOCADDTUNNEL
);
1840 if ((dev
= __dev_get_by_name(p
.name
)) == NULL
)
1842 err
= dev_open(dev
);
1852 * Manual configuration of address on an interface
1854 static int inet6_addr_add(int ifindex
, struct in6_addr
*pfx
, int plen
)
1856 struct inet6_ifaddr
*ifp
;
1857 struct inet6_dev
*idev
;
1858 struct net_device
*dev
;
1863 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
1866 if (!(dev
->flags
&IFF_UP
))
1869 if ((idev
= addrconf_add_dev(dev
)) == NULL
)
1872 scope
= ipv6_addr_scope(pfx
);
1874 ifp
= ipv6_add_addr(idev
, pfx
, plen
, scope
, IFA_F_PERMANENT
);
1876 addrconf_dad_start(ifp
, 0);
1881 return PTR_ERR(ifp
);
1884 static int inet6_addr_del(int ifindex
, struct in6_addr
*pfx
, int plen
)
1886 struct inet6_ifaddr
*ifp
;
1887 struct inet6_dev
*idev
;
1888 struct net_device
*dev
;
1890 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
1893 if ((idev
= __in6_dev_get(dev
)) == NULL
)
1896 read_lock_bh(&idev
->lock
);
1897 for (ifp
= idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1898 if (ifp
->prefix_len
== plen
&&
1899 ipv6_addr_equal(pfx
, &ifp
->addr
)) {
1901 read_unlock_bh(&idev
->lock
);
1905 /* If the last address is deleted administratively,
1906 disable IPv6 on this interface.
1908 if (idev
->addr_list
== NULL
)
1909 addrconf_ifdown(idev
->dev
, 1);
1913 read_unlock_bh(&idev
->lock
);
1914 return -EADDRNOTAVAIL
;
1918 int addrconf_add_ifaddr(void __user
*arg
)
1920 struct in6_ifreq ireq
;
1923 if (!capable(CAP_NET_ADMIN
))
1926 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1930 err
= inet6_addr_add(ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
, ireq
.ifr6_prefixlen
);
1935 int addrconf_del_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_del(ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
, ireq
.ifr6_prefixlen
);
1952 static void sit_add_v4_addrs(struct inet6_dev
*idev
)
1954 struct inet6_ifaddr
* ifp
;
1955 struct in6_addr addr
;
1956 struct net_device
*dev
;
1961 memset(&addr
, 0, sizeof(struct in6_addr
));
1962 memcpy(&addr
.s6_addr32
[3], idev
->dev
->dev_addr
, 4);
1964 if (idev
->dev
->flags
&IFF_POINTOPOINT
) {
1965 addr
.s6_addr32
[0] = htonl(0xfe800000);
1968 scope
= IPV6_ADDR_COMPATv4
;
1971 if (addr
.s6_addr32
[3]) {
1972 ifp
= ipv6_add_addr(idev
, &addr
, 128, scope
, IFA_F_PERMANENT
);
1974 spin_lock_bh(&ifp
->lock
);
1975 ifp
->flags
&= ~IFA_F_TENTATIVE
;
1976 spin_unlock_bh(&ifp
->lock
);
1977 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
1983 for (dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
) {
1984 struct in_device
* in_dev
= __in_dev_get_rtnl(dev
);
1985 if (in_dev
&& (dev
->flags
& IFF_UP
)) {
1986 struct in_ifaddr
* ifa
;
1990 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
1993 addr
.s6_addr32
[3] = ifa
->ifa_local
;
1995 if (ifa
->ifa_scope
== RT_SCOPE_LINK
)
1997 if (ifa
->ifa_scope
>= RT_SCOPE_HOST
) {
1998 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2002 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2007 ifp
= ipv6_add_addr(idev
, &addr
, plen
, flag
,
2010 spin_lock_bh(&ifp
->lock
);
2011 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2012 spin_unlock_bh(&ifp
->lock
);
2013 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2021 static void init_loopback(struct net_device
*dev
)
2023 struct inet6_dev
*idev
;
2024 struct inet6_ifaddr
* ifp
;
2030 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2031 printk(KERN_DEBUG
"init loopback: add_dev failed\n");
2035 ifp
= ipv6_add_addr(idev
, &in6addr_loopback
, 128, IFA_HOST
, IFA_F_PERMANENT
);
2037 spin_lock_bh(&ifp
->lock
);
2038 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2039 spin_unlock_bh(&ifp
->lock
);
2040 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2045 static void addrconf_add_linklocal(struct inet6_dev
*idev
, struct in6_addr
*addr
)
2047 struct inet6_ifaddr
* ifp
;
2049 ifp
= ipv6_add_addr(idev
, addr
, 64, IFA_LINK
, IFA_F_PERMANENT
);
2051 addrconf_dad_start(ifp
, 0);
2056 static void addrconf_dev_config(struct net_device
*dev
)
2058 struct in6_addr addr
;
2059 struct inet6_dev
* idev
;
2063 if ((dev
->type
!= ARPHRD_ETHER
) &&
2064 (dev
->type
!= ARPHRD_FDDI
) &&
2065 (dev
->type
!= ARPHRD_IEEE802_TR
) &&
2066 (dev
->type
!= ARPHRD_ARCNET
) &&
2067 (dev
->type
!= ARPHRD_INFINIBAND
)) {
2068 /* Alas, we support only Ethernet autoconfiguration. */
2072 idev
= addrconf_add_dev(dev
);
2076 memset(&addr
, 0, sizeof(struct in6_addr
));
2077 addr
.s6_addr32
[0] = htonl(0xFE800000);
2079 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) == 0)
2080 addrconf_add_linklocal(idev
, &addr
);
2083 static void addrconf_sit_config(struct net_device
*dev
)
2085 struct inet6_dev
*idev
;
2090 * Configure the tunnel with one of our IPv4
2091 * addresses... we should configure all of
2092 * our v4 addrs in the tunnel
2095 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2096 printk(KERN_DEBUG
"init sit: add_dev failed\n");
2100 sit_add_v4_addrs(idev
);
2102 if (dev
->flags
&IFF_POINTOPOINT
) {
2103 addrconf_add_mroute(dev
);
2104 addrconf_add_lroute(dev
);
2110 ipv6_inherit_linklocal(struct inet6_dev
*idev
, struct net_device
*link_dev
)
2112 struct in6_addr lladdr
;
2114 if (!ipv6_get_lladdr(link_dev
, &lladdr
)) {
2115 addrconf_add_linklocal(idev
, &lladdr
);
2121 static void ip6_tnl_add_linklocal(struct inet6_dev
*idev
)
2123 struct net_device
*link_dev
;
2125 /* first try to inherit the link-local address from the link device */
2126 if (idev
->dev
->iflink
&&
2127 (link_dev
= __dev_get_by_index(idev
->dev
->iflink
))) {
2128 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2131 /* then try to inherit it from any device */
2132 for (link_dev
= dev_base
; link_dev
; link_dev
= link_dev
->next
) {
2133 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2136 printk(KERN_DEBUG
"init ip6-ip6: add_linklocal failed\n");
2140 * Autoconfigure tunnel with a link-local address so routing protocols,
2141 * DHCPv6, MLD etc. can be run over the virtual link
2144 static void addrconf_ip6_tnl_config(struct net_device
*dev
)
2146 struct inet6_dev
*idev
;
2150 if ((idev
= addrconf_add_dev(dev
)) == NULL
) {
2151 printk(KERN_DEBUG
"init ip6-ip6: add_dev failed\n");
2154 ip6_tnl_add_linklocal(idev
);
2157 static int addrconf_notify(struct notifier_block
*this, unsigned long event
,
2160 struct net_device
*dev
= (struct net_device
*) data
;
2161 struct inet6_dev
*idev
= __in6_dev_get(dev
);
2162 int run_pending
= 0;
2167 if (event
== NETDEV_UP
) {
2168 if (!netif_carrier_ok(dev
)) {
2169 /* device is not ready yet. */
2171 "ADDRCONF(NETDEV_UP): %s: "
2172 "link is not ready\n",
2178 idev
->if_flags
|= IF_READY
;
2180 if (!netif_carrier_ok(dev
)) {
2181 /* device is still not ready. */
2186 if (idev
->if_flags
& IF_READY
) {
2187 /* device is already configured. */
2190 idev
->if_flags
|= IF_READY
;
2194 "ADDRCONF(NETDEV_CHANGE): %s: "
2195 "link becomes ready\n",
2203 addrconf_sit_config(dev
);
2205 case ARPHRD_TUNNEL6
:
2206 addrconf_ip6_tnl_config(dev
);
2208 case ARPHRD_LOOPBACK
:
2213 addrconf_dev_config(dev
);
2218 addrconf_dad_run(idev
);
2220 /* If the MTU changed during the interface down, when the
2221 interface up, the changed MTU must be reflected in the
2222 idev as well as routers.
2224 if (idev
->cnf
.mtu6
!= dev
->mtu
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2225 rt6_mtu_change(dev
, dev
->mtu
);
2226 idev
->cnf
.mtu6
= dev
->mtu
;
2228 idev
->tstamp
= jiffies
;
2229 inet6_ifinfo_notify(RTM_NEWLINK
, idev
);
2230 /* If the changed mtu during down is lower than IPV6_MIN_MTU
2231 stop IPv6 on this interface.
2233 if (dev
->mtu
< IPV6_MIN_MTU
)
2234 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2238 case NETDEV_CHANGEMTU
:
2239 if ( idev
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2240 rt6_mtu_change(dev
, dev
->mtu
);
2241 idev
->cnf
.mtu6
= dev
->mtu
;
2245 /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */
2248 case NETDEV_UNREGISTER
:
2250 * Remove all addresses from this interface.
2252 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2255 case NETDEV_CHANGENAME
:
2256 #ifdef CONFIG_SYSCTL
2258 addrconf_sysctl_unregister(&idev
->cnf
);
2259 neigh_sysctl_unregister(idev
->nd_parms
);
2260 neigh_sysctl_register(dev
, idev
->nd_parms
,
2261 NET_IPV6
, NET_IPV6_NEIGH
, "ipv6",
2262 &ndisc_ifinfo_sysctl_change
,
2264 addrconf_sysctl_register(idev
, &idev
->cnf
);
2274 * addrconf module should be notified of a device going up
2276 static struct notifier_block ipv6_dev_notf
= {
2277 .notifier_call
= addrconf_notify
,
2281 static int addrconf_ifdown(struct net_device
*dev
, int how
)
2283 struct inet6_dev
*idev
;
2284 struct inet6_ifaddr
*ifa
, **bifa
;
2289 if (dev
== &loopback_dev
&& how
== 1)
2293 neigh_ifdown(&nd_tbl
, dev
);
2295 idev
= __in6_dev_get(dev
);
2299 /* Step 1: remove reference to ipv6 device from parent device.
2303 write_lock_bh(&addrconf_lock
);
2304 dev
->ip6_ptr
= NULL
;
2306 write_unlock_bh(&addrconf_lock
);
2308 /* Step 1.5: remove snmp6 entry */
2309 snmp6_unregister_dev(idev
);
2313 /* Step 2: clear hash table */
2314 for (i
=0; i
<IN6_ADDR_HSIZE
; i
++) {
2315 bifa
= &inet6_addr_lst
[i
];
2317 write_lock_bh(&addrconf_hash_lock
);
2318 while ((ifa
= *bifa
) != NULL
) {
2319 if (ifa
->idev
== idev
) {
2320 *bifa
= ifa
->lst_next
;
2321 ifa
->lst_next
= NULL
;
2322 addrconf_del_timer(ifa
);
2326 bifa
= &ifa
->lst_next
;
2328 write_unlock_bh(&addrconf_hash_lock
);
2331 write_lock_bh(&idev
->lock
);
2333 /* Step 3: clear flags for stateless addrconf */
2335 idev
->if_flags
&= ~(IF_RS_SENT
|IF_RA_RCVD
|IF_READY
);
2337 /* Step 4: clear address list */
2338 #ifdef CONFIG_IPV6_PRIVACY
2339 if (how
== 1 && del_timer(&idev
->regen_timer
))
2342 /* clear tempaddr list */
2343 while ((ifa
= idev
->tempaddr_list
) != NULL
) {
2344 idev
->tempaddr_list
= ifa
->tmp_next
;
2345 ifa
->tmp_next
= NULL
;
2347 write_unlock_bh(&idev
->lock
);
2348 spin_lock_bh(&ifa
->lock
);
2351 in6_ifa_put(ifa
->ifpub
);
2354 spin_unlock_bh(&ifa
->lock
);
2356 write_lock_bh(&idev
->lock
);
2359 while ((ifa
= idev
->addr_list
) != NULL
) {
2360 idev
->addr_list
= ifa
->if_next
;
2361 ifa
->if_next
= NULL
;
2363 addrconf_del_timer(ifa
);
2364 write_unlock_bh(&idev
->lock
);
2366 __ipv6_ifa_notify(RTM_DELADDR
, ifa
);
2369 write_lock_bh(&idev
->lock
);
2371 write_unlock_bh(&idev
->lock
);
2373 /* Step 5: Discard multicast list */
2376 ipv6_mc_destroy_dev(idev
);
2380 /* Step 5: netlink notification of this interface */
2381 idev
->tstamp
= jiffies
;
2382 inet6_ifinfo_notify(RTM_DELLINK
, idev
);
2384 /* Shot the device (if unregistered) */
2387 #ifdef CONFIG_SYSCTL
2388 addrconf_sysctl_unregister(&idev
->cnf
);
2389 neigh_sysctl_unregister(idev
->nd_parms
);
2391 neigh_parms_release(&nd_tbl
, idev
->nd_parms
);
2392 neigh_ifdown(&nd_tbl
, dev
);
2398 static void addrconf_rs_timer(unsigned long data
)
2400 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2402 if (ifp
->idev
->cnf
.forwarding
)
2405 if (ifp
->idev
->if_flags
& IF_RA_RCVD
) {
2407 * Announcement received after solicitation
2413 spin_lock(&ifp
->lock
);
2414 if (ifp
->probes
++ < ifp
->idev
->cnf
.rtr_solicits
) {
2415 struct in6_addr all_routers
;
2417 /* The wait after the last probe can be shorter */
2418 addrconf_mod_timer(ifp
, AC_RS
,
2419 (ifp
->probes
== ifp
->idev
->cnf
.rtr_solicits
) ?
2420 ifp
->idev
->cnf
.rtr_solicit_delay
:
2421 ifp
->idev
->cnf
.rtr_solicit_interval
);
2422 spin_unlock(&ifp
->lock
);
2424 ipv6_addr_all_routers(&all_routers
);
2426 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &all_routers
);
2428 spin_unlock(&ifp
->lock
);
2430 * Note: we do not support deprecated "all on-link"
2431 * assumption any longer.
2433 printk(KERN_DEBUG
"%s: no IPv6 routers present\n",
2434 ifp
->idev
->dev
->name
);
2442 * Duplicate Address Detection
2444 static void addrconf_dad_kick(struct inet6_ifaddr
*ifp
)
2446 unsigned long rand_num
;
2447 struct inet6_dev
*idev
= ifp
->idev
;
2449 rand_num
= net_random() % (idev
->cnf
.rtr_solicit_delay
? : 1);
2450 ifp
->probes
= idev
->cnf
.dad_transmits
;
2451 addrconf_mod_timer(ifp
, AC_DAD
, rand_num
);
2454 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
)
2456 struct inet6_dev
*idev
= ifp
->idev
;
2457 struct net_device
*dev
= idev
->dev
;
2459 addrconf_join_solict(dev
, &ifp
->addr
);
2461 if (ifp
->prefix_len
!= 128 && (ifp
->flags
&IFA_F_PERMANENT
))
2462 addrconf_prefix_route(&ifp
->addr
, ifp
->prefix_len
, dev
, 0,
2465 net_srandom(ifp
->addr
.s6_addr32
[3]);
2467 read_lock_bh(&idev
->lock
);
2470 spin_lock_bh(&ifp
->lock
);
2472 if (dev
->flags
&(IFF_NOARP
|IFF_LOOPBACK
) ||
2473 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
2474 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2475 spin_unlock_bh(&ifp
->lock
);
2476 read_unlock_bh(&idev
->lock
);
2478 addrconf_dad_completed(ifp
);
2482 if (!(idev
->if_flags
& IF_READY
)) {
2483 spin_unlock_bh(&ifp
->lock
);
2484 read_unlock_bh(&idev
->lock
);
2486 * If the defice is not ready:
2487 * - keep it tentative if it is a permanent address.
2488 * - otherwise, kill it.
2491 addrconf_dad_stop(ifp
);
2494 addrconf_dad_kick(ifp
);
2495 spin_unlock_bh(&ifp
->lock
);
2497 read_unlock_bh(&idev
->lock
);
2500 static void addrconf_dad_timer(unsigned long data
)
2502 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2503 struct inet6_dev
*idev
= ifp
->idev
;
2504 struct in6_addr unspec
;
2505 struct in6_addr mcaddr
;
2507 read_lock_bh(&idev
->lock
);
2509 read_unlock_bh(&idev
->lock
);
2512 spin_lock_bh(&ifp
->lock
);
2513 if (ifp
->probes
== 0) {
2515 * DAD was successful
2518 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2519 spin_unlock_bh(&ifp
->lock
);
2520 read_unlock_bh(&idev
->lock
);
2522 addrconf_dad_completed(ifp
);
2528 addrconf_mod_timer(ifp
, AC_DAD
, ifp
->idev
->nd_parms
->retrans_time
);
2529 spin_unlock_bh(&ifp
->lock
);
2530 read_unlock_bh(&idev
->lock
);
2532 /* send a neighbour solicitation for our addr */
2533 memset(&unspec
, 0, sizeof(unspec
));
2534 addrconf_addr_solict_mult(&ifp
->addr
, &mcaddr
);
2535 ndisc_send_ns(ifp
->idev
->dev
, NULL
, &ifp
->addr
, &mcaddr
, &unspec
);
2540 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
)
2542 struct net_device
* dev
= ifp
->idev
->dev
;
2545 * Configure the address for reception. Now it is valid.
2548 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2550 /* If added prefix is link local and forwarding is off,
2551 start sending router solicitations.
2554 if (ifp
->idev
->cnf
.forwarding
== 0 &&
2555 ifp
->idev
->cnf
.rtr_solicits
> 0 &&
2556 (dev
->flags
&IFF_LOOPBACK
) == 0 &&
2557 (ipv6_addr_type(&ifp
->addr
) & IPV6_ADDR_LINKLOCAL
)) {
2558 struct in6_addr all_routers
;
2560 ipv6_addr_all_routers(&all_routers
);
2563 * If a host as already performed a random delay
2564 * [...] as part of DAD [...] there is no need
2565 * to delay again before sending the first RS
2567 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &all_routers
);
2569 spin_lock_bh(&ifp
->lock
);
2571 ifp
->idev
->if_flags
|= IF_RS_SENT
;
2572 addrconf_mod_timer(ifp
, AC_RS
, ifp
->idev
->cnf
.rtr_solicit_interval
);
2573 spin_unlock_bh(&ifp
->lock
);
2577 static void addrconf_dad_run(struct inet6_dev
*idev
) {
2578 struct inet6_ifaddr
*ifp
;
2580 read_lock_bh(&idev
->lock
);
2581 for (ifp
= idev
->addr_list
; ifp
; ifp
= ifp
->if_next
) {
2582 spin_lock_bh(&ifp
->lock
);
2583 if (!(ifp
->flags
& IFA_F_TENTATIVE
)) {
2584 spin_unlock_bh(&ifp
->lock
);
2587 spin_unlock_bh(&ifp
->lock
);
2588 addrconf_dad_kick(ifp
);
2590 read_unlock_bh(&idev
->lock
);
2593 #ifdef CONFIG_PROC_FS
2594 struct if6_iter_state
{
2598 static struct inet6_ifaddr
*if6_get_first(struct seq_file
*seq
)
2600 struct inet6_ifaddr
*ifa
= NULL
;
2601 struct if6_iter_state
*state
= seq
->private;
2603 for (state
->bucket
= 0; state
->bucket
< IN6_ADDR_HSIZE
; ++state
->bucket
) {
2604 ifa
= inet6_addr_lst
[state
->bucket
];
2611 static struct inet6_ifaddr
*if6_get_next(struct seq_file
*seq
, struct inet6_ifaddr
*ifa
)
2613 struct if6_iter_state
*state
= seq
->private;
2615 ifa
= ifa
->lst_next
;
2617 if (!ifa
&& ++state
->bucket
< IN6_ADDR_HSIZE
) {
2618 ifa
= inet6_addr_lst
[state
->bucket
];
2624 static struct inet6_ifaddr
*if6_get_idx(struct seq_file
*seq
, loff_t pos
)
2626 struct inet6_ifaddr
*ifa
= if6_get_first(seq
);
2629 while(pos
&& (ifa
= if6_get_next(seq
, ifa
)) != NULL
)
2631 return pos
? NULL
: ifa
;
2634 static void *if6_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2636 read_lock_bh(&addrconf_hash_lock
);
2637 return if6_get_idx(seq
, *pos
);
2640 static void *if6_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2642 struct inet6_ifaddr
*ifa
;
2644 ifa
= if6_get_next(seq
, v
);
2649 static void if6_seq_stop(struct seq_file
*seq
, void *v
)
2651 read_unlock_bh(&addrconf_hash_lock
);
2654 static int if6_seq_show(struct seq_file
*seq
, void *v
)
2656 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*)v
;
2658 NIP6_SEQFMT
" %02x %02x %02x %02x %8s\n",
2660 ifp
->idev
->dev
->ifindex
,
2664 ifp
->idev
->dev
->name
);
2668 static struct seq_operations if6_seq_ops
= {
2669 .start
= if6_seq_start
,
2670 .next
= if6_seq_next
,
2671 .show
= if6_seq_show
,
2672 .stop
= if6_seq_stop
,
2675 static int if6_seq_open(struct inode
*inode
, struct file
*file
)
2677 struct seq_file
*seq
;
2679 struct if6_iter_state
*s
= kzalloc(sizeof(*s
), GFP_KERNEL
);
2684 rc
= seq_open(file
, &if6_seq_ops
);
2688 seq
= file
->private_data
;
2697 static struct file_operations if6_fops
= {
2698 .owner
= THIS_MODULE
,
2699 .open
= if6_seq_open
,
2701 .llseek
= seq_lseek
,
2702 .release
= seq_release_private
,
2705 int __init
if6_proc_init(void)
2707 if (!proc_net_fops_create("if_inet6", S_IRUGO
, &if6_fops
))
2712 void if6_proc_exit(void)
2714 proc_net_remove("if_inet6");
2716 #endif /* CONFIG_PROC_FS */
2719 * Periodic address status verification
2722 static void addrconf_verify(unsigned long foo
)
2724 struct inet6_ifaddr
*ifp
;
2725 unsigned long now
, next
;
2728 spin_lock_bh(&addrconf_verify_lock
);
2730 next
= now
+ ADDR_CHECK_FREQUENCY
;
2732 del_timer(&addr_chk_timer
);
2734 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
2737 read_lock(&addrconf_hash_lock
);
2738 for (ifp
=inet6_addr_lst
[i
]; ifp
; ifp
=ifp
->lst_next
) {
2740 #ifdef CONFIG_IPV6_PRIVACY
2741 unsigned long regen_advance
;
2744 if (ifp
->flags
& IFA_F_PERMANENT
)
2747 spin_lock(&ifp
->lock
);
2748 age
= (now
- ifp
->tstamp
) / HZ
;
2750 #ifdef CONFIG_IPV6_PRIVACY
2751 regen_advance
= ifp
->idev
->cnf
.regen_max_retry
*
2752 ifp
->idev
->cnf
.dad_transmits
*
2753 ifp
->idev
->nd_parms
->retrans_time
/ HZ
;
2756 if (age
>= ifp
->valid_lft
) {
2757 spin_unlock(&ifp
->lock
);
2759 read_unlock(&addrconf_hash_lock
);
2762 } else if (age
>= ifp
->prefered_lft
) {
2763 /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */
2766 if (!(ifp
->flags
&IFA_F_DEPRECATED
)) {
2768 ifp
->flags
|= IFA_F_DEPRECATED
;
2771 if (time_before(ifp
->tstamp
+ ifp
->valid_lft
* HZ
, next
))
2772 next
= ifp
->tstamp
+ ifp
->valid_lft
* HZ
;
2774 spin_unlock(&ifp
->lock
);
2778 read_unlock(&addrconf_hash_lock
);
2780 ipv6_ifa_notify(0, ifp
);
2784 #ifdef CONFIG_IPV6_PRIVACY
2785 } else if ((ifp
->flags
&IFA_F_TEMPORARY
) &&
2786 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
2787 if (age
>= ifp
->prefered_lft
- regen_advance
) {
2788 struct inet6_ifaddr
*ifpub
= ifp
->ifpub
;
2789 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
2790 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
2791 if (!ifp
->regen_count
&& ifpub
) {
2794 in6_ifa_hold(ifpub
);
2795 spin_unlock(&ifp
->lock
);
2796 read_unlock(&addrconf_hash_lock
);
2797 spin_lock(&ifpub
->lock
);
2798 ifpub
->regen_count
= 0;
2799 spin_unlock(&ifpub
->lock
);
2800 ipv6_create_tempaddr(ifpub
, ifp
);
2805 } else if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
, next
))
2806 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
;
2807 spin_unlock(&ifp
->lock
);
2810 /* ifp->prefered_lft <= ifp->valid_lft */
2811 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
2812 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
2813 spin_unlock(&ifp
->lock
);
2816 read_unlock(&addrconf_hash_lock
);
2819 addr_chk_timer
.expires
= time_before(next
, jiffies
+ HZ
) ? jiffies
+ HZ
: next
;
2820 add_timer(&addr_chk_timer
);
2821 spin_unlock_bh(&addrconf_verify_lock
);
2825 inet6_rtm_deladdr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
2827 struct rtattr
**rta
= arg
;
2828 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
2829 struct in6_addr
*pfx
;
2832 if (rta
[IFA_ADDRESS
-1]) {
2833 if (RTA_PAYLOAD(rta
[IFA_ADDRESS
-1]) < sizeof(*pfx
))
2835 pfx
= RTA_DATA(rta
[IFA_ADDRESS
-1]);
2837 if (rta
[IFA_LOCAL
-1]) {
2838 if (pfx
&& memcmp(pfx
, RTA_DATA(rta
[IFA_LOCAL
-1]), sizeof(*pfx
)))
2840 pfx
= RTA_DATA(rta
[IFA_LOCAL
-1]);
2845 return inet6_addr_del(ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
);
2849 inet6_rtm_newaddr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
2851 struct rtattr
**rta
= arg
;
2852 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
2853 struct in6_addr
*pfx
;
2856 if (rta
[IFA_ADDRESS
-1]) {
2857 if (RTA_PAYLOAD(rta
[IFA_ADDRESS
-1]) < sizeof(*pfx
))
2859 pfx
= RTA_DATA(rta
[IFA_ADDRESS
-1]);
2861 if (rta
[IFA_LOCAL
-1]) {
2862 if (pfx
&& memcmp(pfx
, RTA_DATA(rta
[IFA_LOCAL
-1]), sizeof(*pfx
)))
2864 pfx
= RTA_DATA(rta
[IFA_LOCAL
-1]);
2869 return inet6_addr_add(ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
);
2872 /* Maximum length of ifa_cacheinfo attributes */
2873 #define INET6_IFADDR_RTA_SPACE \
2874 RTA_SPACE(16) /* IFA_ADDRESS */ + \
2875 RTA_SPACE(sizeof(struct ifa_cacheinfo)) /* CACHEINFO */
2877 static int inet6_fill_ifaddr(struct sk_buff
*skb
, struct inet6_ifaddr
*ifa
,
2878 u32 pid
, u32 seq
, int event
, unsigned int flags
)
2880 struct ifaddrmsg
*ifm
;
2881 struct nlmsghdr
*nlh
;
2882 struct ifa_cacheinfo ci
;
2883 unsigned char *b
= skb
->tail
;
2885 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
2886 ifm
= NLMSG_DATA(nlh
);
2887 ifm
->ifa_family
= AF_INET6
;
2888 ifm
->ifa_prefixlen
= ifa
->prefix_len
;
2889 ifm
->ifa_flags
= ifa
->flags
;
2890 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
2891 if (ifa
->scope
&IFA_HOST
)
2892 ifm
->ifa_scope
= RT_SCOPE_HOST
;
2893 else if (ifa
->scope
&IFA_LINK
)
2894 ifm
->ifa_scope
= RT_SCOPE_LINK
;
2895 else if (ifa
->scope
&IFA_SITE
)
2896 ifm
->ifa_scope
= RT_SCOPE_SITE
;
2897 ifm
->ifa_index
= ifa
->idev
->dev
->ifindex
;
2898 RTA_PUT(skb
, IFA_ADDRESS
, 16, &ifa
->addr
);
2899 if (!(ifa
->flags
&IFA_F_PERMANENT
)) {
2900 ci
.ifa_prefered
= ifa
->prefered_lft
;
2901 ci
.ifa_valid
= ifa
->valid_lft
;
2902 if (ci
.ifa_prefered
!= INFINITY_LIFE_TIME
) {
2903 long tval
= (jiffies
- ifa
->tstamp
)/HZ
;
2904 ci
.ifa_prefered
-= tval
;
2905 if (ci
.ifa_valid
!= INFINITY_LIFE_TIME
)
2906 ci
.ifa_valid
-= tval
;
2909 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
2910 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
2912 ci
.cstamp
= (__u32
)(TIME_DELTA(ifa
->cstamp
, INITIAL_JIFFIES
) / HZ
* 100
2913 + TIME_DELTA(ifa
->cstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
2914 ci
.tstamp
= (__u32
)(TIME_DELTA(ifa
->tstamp
, INITIAL_JIFFIES
) / HZ
* 100
2915 + TIME_DELTA(ifa
->tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
2916 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
2917 nlh
->nlmsg_len
= skb
->tail
- b
;
2922 skb_trim(skb
, b
- skb
->data
);
2926 static int inet6_fill_ifmcaddr(struct sk_buff
*skb
, struct ifmcaddr6
*ifmca
,
2927 u32 pid
, u32 seq
, int event
, u16 flags
)
2929 struct ifaddrmsg
*ifm
;
2930 struct nlmsghdr
*nlh
;
2931 struct ifa_cacheinfo ci
;
2932 unsigned char *b
= skb
->tail
;
2934 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
2935 ifm
= NLMSG_DATA(nlh
);
2936 ifm
->ifa_family
= AF_INET6
;
2937 ifm
->ifa_prefixlen
= 128;
2938 ifm
->ifa_flags
= IFA_F_PERMANENT
;
2939 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
2940 if (ipv6_addr_scope(&ifmca
->mca_addr
)&IFA_SITE
)
2941 ifm
->ifa_scope
= RT_SCOPE_SITE
;
2942 ifm
->ifa_index
= ifmca
->idev
->dev
->ifindex
;
2943 RTA_PUT(skb
, IFA_MULTICAST
, 16, &ifmca
->mca_addr
);
2944 ci
.cstamp
= (__u32
)(TIME_DELTA(ifmca
->mca_cstamp
, INITIAL_JIFFIES
) / HZ
2945 * 100 + TIME_DELTA(ifmca
->mca_cstamp
, INITIAL_JIFFIES
) % HZ
2947 ci
.tstamp
= (__u32
)(TIME_DELTA(ifmca
->mca_tstamp
, INITIAL_JIFFIES
) / HZ
2948 * 100 + TIME_DELTA(ifmca
->mca_tstamp
, INITIAL_JIFFIES
) % HZ
2950 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
2951 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
2952 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
2953 nlh
->nlmsg_len
= skb
->tail
- b
;
2958 skb_trim(skb
, b
- skb
->data
);
2962 static int inet6_fill_ifacaddr(struct sk_buff
*skb
, struct ifacaddr6
*ifaca
,
2963 u32 pid
, u32 seq
, int event
, unsigned int flags
)
2965 struct ifaddrmsg
*ifm
;
2966 struct nlmsghdr
*nlh
;
2967 struct ifa_cacheinfo ci
;
2968 unsigned char *b
= skb
->tail
;
2970 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
2971 ifm
= NLMSG_DATA(nlh
);
2972 ifm
->ifa_family
= AF_INET6
;
2973 ifm
->ifa_prefixlen
= 128;
2974 ifm
->ifa_flags
= IFA_F_PERMANENT
;
2975 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
2976 if (ipv6_addr_scope(&ifaca
->aca_addr
)&IFA_SITE
)
2977 ifm
->ifa_scope
= RT_SCOPE_SITE
;
2978 ifm
->ifa_index
= ifaca
->aca_idev
->dev
->ifindex
;
2979 RTA_PUT(skb
, IFA_ANYCAST
, 16, &ifaca
->aca_addr
);
2980 ci
.cstamp
= (__u32
)(TIME_DELTA(ifaca
->aca_cstamp
, INITIAL_JIFFIES
) / HZ
2981 * 100 + TIME_DELTA(ifaca
->aca_cstamp
, INITIAL_JIFFIES
) % HZ
2983 ci
.tstamp
= (__u32
)(TIME_DELTA(ifaca
->aca_tstamp
, INITIAL_JIFFIES
) / HZ
2984 * 100 + TIME_DELTA(ifaca
->aca_tstamp
, INITIAL_JIFFIES
) % HZ
2986 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
2987 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
2988 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
2989 nlh
->nlmsg_len
= skb
->tail
- b
;
2994 skb_trim(skb
, b
- skb
->data
);
3005 static int inet6_dump_addr(struct sk_buff
*skb
, struct netlink_callback
*cb
,
3006 enum addr_type_t type
)
3009 int s_idx
, s_ip_idx
;
3011 struct net_device
*dev
;
3012 struct inet6_dev
*idev
= NULL
;
3013 struct inet6_ifaddr
*ifa
;
3014 struct ifmcaddr6
*ifmca
;
3015 struct ifacaddr6
*ifaca
;
3017 s_idx
= cb
->args
[0];
3018 s_ip_idx
= ip_idx
= cb
->args
[1];
3019 read_lock(&dev_base_lock
);
3021 for (dev
= dev_base
, idx
= 0; dev
; dev
= dev
->next
, idx
++) {
3027 if ((idev
= in6_dev_get(dev
)) == NULL
)
3029 read_lock_bh(&idev
->lock
);
3032 /* unicast address incl. temp addr */
3033 for (ifa
= idev
->addr_list
; ifa
;
3034 ifa
= ifa
->if_next
, ip_idx
++) {
3035 if (ip_idx
< s_ip_idx
)
3037 if ((err
= inet6_fill_ifaddr(skb
, ifa
,
3038 NETLINK_CB(cb
->skb
).pid
,
3039 cb
->nlh
->nlmsg_seq
, RTM_NEWADDR
,
3044 case MULTICAST_ADDR
:
3045 /* multicast address */
3046 for (ifmca
= idev
->mc_list
; ifmca
;
3047 ifmca
= ifmca
->next
, ip_idx
++) {
3048 if (ip_idx
< s_ip_idx
)
3050 if ((err
= inet6_fill_ifmcaddr(skb
, ifmca
,
3051 NETLINK_CB(cb
->skb
).pid
,
3052 cb
->nlh
->nlmsg_seq
, RTM_GETMULTICAST
,
3058 /* anycast address */
3059 for (ifaca
= idev
->ac_list
; ifaca
;
3060 ifaca
= ifaca
->aca_next
, ip_idx
++) {
3061 if (ip_idx
< s_ip_idx
)
3063 if ((err
= inet6_fill_ifacaddr(skb
, ifaca
,
3064 NETLINK_CB(cb
->skb
).pid
,
3065 cb
->nlh
->nlmsg_seq
, RTM_GETANYCAST
,
3073 read_unlock_bh(&idev
->lock
);
3078 read_unlock_bh(&idev
->lock
);
3081 read_unlock(&dev_base_lock
);
3083 cb
->args
[1] = ip_idx
;
3087 static int inet6_dump_ifaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3089 enum addr_type_t type
= UNICAST_ADDR
;
3090 return inet6_dump_addr(skb
, cb
, type
);
3093 static int inet6_dump_ifmcaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3095 enum addr_type_t type
= MULTICAST_ADDR
;
3096 return inet6_dump_addr(skb
, cb
, type
);
3100 static int inet6_dump_ifacaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3102 enum addr_type_t type
= ANYCAST_ADDR
;
3103 return inet6_dump_addr(skb
, cb
, type
);
3106 static void inet6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
)
3108 struct sk_buff
*skb
;
3109 int size
= NLMSG_SPACE(sizeof(struct ifaddrmsg
) + INET6_IFADDR_RTA_SPACE
);
3111 skb
= alloc_skb(size
, GFP_ATOMIC
);
3113 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFADDR
, ENOBUFS
);
3116 if (inet6_fill_ifaddr(skb
, ifa
, current
->pid
, 0, event
, 0) < 0) {
3118 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFADDR
, EINVAL
);
3121 NETLINK_CB(skb
).dst_group
= RTNLGRP_IPV6_IFADDR
;
3122 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_IPV6_IFADDR
, GFP_ATOMIC
);
3125 static void inline ipv6_store_devconf(struct ipv6_devconf
*cnf
,
3126 __s32
*array
, int bytes
)
3128 memset(array
, 0, bytes
);
3129 array
[DEVCONF_FORWARDING
] = cnf
->forwarding
;
3130 array
[DEVCONF_HOPLIMIT
] = cnf
->hop_limit
;
3131 array
[DEVCONF_MTU6
] = cnf
->mtu6
;
3132 array
[DEVCONF_ACCEPT_RA
] = cnf
->accept_ra
;
3133 array
[DEVCONF_ACCEPT_REDIRECTS
] = cnf
->accept_redirects
;
3134 array
[DEVCONF_AUTOCONF
] = cnf
->autoconf
;
3135 array
[DEVCONF_DAD_TRANSMITS
] = cnf
->dad_transmits
;
3136 array
[DEVCONF_RTR_SOLICITS
] = cnf
->rtr_solicits
;
3137 array
[DEVCONF_RTR_SOLICIT_INTERVAL
] = cnf
->rtr_solicit_interval
;
3138 array
[DEVCONF_RTR_SOLICIT_DELAY
] = cnf
->rtr_solicit_delay
;
3139 array
[DEVCONF_FORCE_MLD_VERSION
] = cnf
->force_mld_version
;
3140 #ifdef CONFIG_IPV6_PRIVACY
3141 array
[DEVCONF_USE_TEMPADDR
] = cnf
->use_tempaddr
;
3142 array
[DEVCONF_TEMP_VALID_LFT
] = cnf
->temp_valid_lft
;
3143 array
[DEVCONF_TEMP_PREFERED_LFT
] = cnf
->temp_prefered_lft
;
3144 array
[DEVCONF_REGEN_MAX_RETRY
] = cnf
->regen_max_retry
;
3145 array
[DEVCONF_MAX_DESYNC_FACTOR
] = cnf
->max_desync_factor
;
3147 array
[DEVCONF_MAX_ADDRESSES
] = cnf
->max_addresses
;
3148 array
[DEVCONF_ACCEPT_RA_DEFRTR
] = cnf
->accept_ra_defrtr
;
3149 array
[DEVCONF_ACCEPT_RA_PINFO
] = cnf
->accept_ra_pinfo
;
3150 #ifdef CONFIG_IPV6_ROUTER_PREF
3151 array
[DEVCONF_ACCEPT_RA_RTR_PREF
] = cnf
->accept_ra_rtr_pref
;
3152 array
[DEVCONF_RTR_PROBE_INTERVAL
] = cnf
->rtr_probe_interval
;
3153 #ifdef CONFIV_IPV6_ROUTE_INFO
3154 array
[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN
] = cnf
->accept_ra_rt_info_max_plen
;
3159 /* Maximum length of ifinfomsg attributes */
3160 #define INET6_IFINFO_RTA_SPACE \
3161 RTA_SPACE(IFNAMSIZ) /* IFNAME */ + \
3162 RTA_SPACE(MAX_ADDR_LEN) /* ADDRESS */ + \
3163 RTA_SPACE(sizeof(u32)) /* MTU */ + \
3164 RTA_SPACE(sizeof(int)) /* LINK */ + \
3165 RTA_SPACE(0) /* PROTINFO */ + \
3166 RTA_SPACE(sizeof(u32)) /* FLAGS */ + \
3167 RTA_SPACE(sizeof(struct ifla_cacheinfo)) /* CACHEINFO */ + \
3168 RTA_SPACE(sizeof(__s32[DEVCONF_MAX])) /* CONF */
3170 static int inet6_fill_ifinfo(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3171 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3173 struct net_device
*dev
= idev
->dev
;
3174 __s32
*array
= NULL
;
3175 struct ifinfomsg
*r
;
3176 struct nlmsghdr
*nlh
;
3177 unsigned char *b
= skb
->tail
;
3178 struct rtattr
*subattr
;
3179 __u32 mtu
= dev
->mtu
;
3180 struct ifla_cacheinfo ci
;
3182 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*r
), flags
);
3183 r
= NLMSG_DATA(nlh
);
3184 r
->ifi_family
= AF_INET6
;
3186 r
->ifi_type
= dev
->type
;
3187 r
->ifi_index
= dev
->ifindex
;
3188 r
->ifi_flags
= dev_get_flags(dev
);
3191 RTA_PUT(skb
, IFLA_IFNAME
, strlen(dev
->name
)+1, dev
->name
);
3194 RTA_PUT(skb
, IFLA_ADDRESS
, dev
->addr_len
, dev
->dev_addr
);
3196 RTA_PUT(skb
, IFLA_MTU
, sizeof(mtu
), &mtu
);
3197 if (dev
->ifindex
!= dev
->iflink
)
3198 RTA_PUT(skb
, IFLA_LINK
, sizeof(int), &dev
->iflink
);
3200 subattr
= (struct rtattr
*)skb
->tail
;
3202 RTA_PUT(skb
, IFLA_PROTINFO
, 0, NULL
);
3204 /* return the device flags */
3205 RTA_PUT(skb
, IFLA_INET6_FLAGS
, sizeof(__u32
), &idev
->if_flags
);
3207 /* return interface cacheinfo */
3208 ci
.max_reasm_len
= IPV6_MAXPLEN
;
3209 ci
.tstamp
= (__u32
)(TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) / HZ
* 100
3210 + TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3211 ci
.reachable_time
= idev
->nd_parms
->reachable_time
;
3212 ci
.retrans_time
= idev
->nd_parms
->retrans_time
;
3213 RTA_PUT(skb
, IFLA_INET6_CACHEINFO
, sizeof(ci
), &ci
);
3215 /* return the device sysctl params */
3216 if ((array
= kmalloc(DEVCONF_MAX
* sizeof(*array
), GFP_ATOMIC
)) == NULL
)
3217 goto rtattr_failure
;
3218 ipv6_store_devconf(&idev
->cnf
, array
, DEVCONF_MAX
* sizeof(*array
));
3219 RTA_PUT(skb
, IFLA_INET6_CONF
, DEVCONF_MAX
* sizeof(*array
), array
);
3221 /* XXX - Statistics/MC not implemented */
3222 subattr
->rta_len
= skb
->tail
- (u8
*)subattr
;
3224 nlh
->nlmsg_len
= skb
->tail
- b
;
3231 skb_trim(skb
, b
- skb
->data
);
3235 static int inet6_dump_ifinfo(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3238 int s_idx
= cb
->args
[0];
3239 struct net_device
*dev
;
3240 struct inet6_dev
*idev
;
3242 read_lock(&dev_base_lock
);
3243 for (dev
=dev_base
, idx
=0; dev
; dev
= dev
->next
, idx
++) {
3246 if ((idev
= in6_dev_get(dev
)) == NULL
)
3248 err
= inet6_fill_ifinfo(skb
, idev
, NETLINK_CB(cb
->skb
).pid
,
3249 cb
->nlh
->nlmsg_seq
, RTM_NEWLINK
, NLM_F_MULTI
);
3254 read_unlock(&dev_base_lock
);
3260 void inet6_ifinfo_notify(int event
, struct inet6_dev
*idev
)
3262 struct sk_buff
*skb
;
3263 int size
= NLMSG_SPACE(sizeof(struct ifinfomsg
) + INET6_IFINFO_RTA_SPACE
);
3265 skb
= alloc_skb(size
, GFP_ATOMIC
);
3267 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFINFO
, ENOBUFS
);
3270 if (inet6_fill_ifinfo(skb
, idev
, current
->pid
, 0, event
, 0) < 0) {
3272 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_IFINFO
, EINVAL
);
3275 NETLINK_CB(skb
).dst_group
= RTNLGRP_IPV6_IFINFO
;
3276 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_IPV6_IFINFO
, GFP_ATOMIC
);
3279 /* Maximum length of prefix_cacheinfo attributes */
3280 #define INET6_PREFIX_RTA_SPACE \
3281 RTA_SPACE(sizeof(((struct prefix_info *)NULL)->prefix)) /* ADDRESS */ + \
3282 RTA_SPACE(sizeof(struct prefix_cacheinfo)) /* CACHEINFO */
3284 static int inet6_fill_prefix(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3285 struct prefix_info
*pinfo
, u32 pid
, u32 seq
,
3286 int event
, unsigned int flags
)
3288 struct prefixmsg
*pmsg
;
3289 struct nlmsghdr
*nlh
;
3290 unsigned char *b
= skb
->tail
;
3291 struct prefix_cacheinfo ci
;
3293 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*pmsg
), flags
);
3294 pmsg
= NLMSG_DATA(nlh
);
3295 pmsg
->prefix_family
= AF_INET6
;
3296 pmsg
->prefix_pad1
= 0;
3297 pmsg
->prefix_pad2
= 0;
3298 pmsg
->prefix_ifindex
= idev
->dev
->ifindex
;
3299 pmsg
->prefix_len
= pinfo
->prefix_len
;
3300 pmsg
->prefix_type
= pinfo
->type
;
3301 pmsg
->prefix_pad3
= 0;
3303 pmsg
->prefix_flags
= 0;
3305 pmsg
->prefix_flags
|= IF_PREFIX_ONLINK
;
3306 if (pinfo
->autoconf
)
3307 pmsg
->prefix_flags
|= IF_PREFIX_AUTOCONF
;
3309 RTA_PUT(skb
, PREFIX_ADDRESS
, sizeof(pinfo
->prefix
), &pinfo
->prefix
);
3311 ci
.preferred_time
= ntohl(pinfo
->prefered
);
3312 ci
.valid_time
= ntohl(pinfo
->valid
);
3313 RTA_PUT(skb
, PREFIX_CACHEINFO
, sizeof(ci
), &ci
);
3315 nlh
->nlmsg_len
= skb
->tail
- b
;
3320 skb_trim(skb
, b
- skb
->data
);
3324 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
3325 struct prefix_info
*pinfo
)
3327 struct sk_buff
*skb
;
3328 int size
= NLMSG_SPACE(sizeof(struct prefixmsg
) + INET6_PREFIX_RTA_SPACE
);
3330 skb
= alloc_skb(size
, GFP_ATOMIC
);
3332 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_PREFIX
, ENOBUFS
);
3335 if (inet6_fill_prefix(skb
, idev
, pinfo
, current
->pid
, 0, event
, 0) < 0) {
3337 netlink_set_err(rtnl
, 0, RTNLGRP_IPV6_PREFIX
, EINVAL
);
3340 NETLINK_CB(skb
).dst_group
= RTNLGRP_IPV6_PREFIX
;
3341 netlink_broadcast(rtnl
, skb
, 0, RTNLGRP_IPV6_PREFIX
, GFP_ATOMIC
);
3344 static struct rtnetlink_link inet6_rtnetlink_table
[RTM_NR_MSGTYPES
] = {
3345 [RTM_GETLINK
- RTM_BASE
] = { .dumpit
= inet6_dump_ifinfo
, },
3346 [RTM_NEWADDR
- RTM_BASE
] = { .doit
= inet6_rtm_newaddr
, },
3347 [RTM_DELADDR
- RTM_BASE
] = { .doit
= inet6_rtm_deladdr
, },
3348 [RTM_GETADDR
- RTM_BASE
] = { .dumpit
= inet6_dump_ifaddr
, },
3349 [RTM_GETMULTICAST
- RTM_BASE
] = { .dumpit
= inet6_dump_ifmcaddr
, },
3350 [RTM_GETANYCAST
- RTM_BASE
] = { .dumpit
= inet6_dump_ifacaddr
, },
3351 [RTM_NEWROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_newroute
, },
3352 [RTM_DELROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_delroute
, },
3353 [RTM_GETROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_getroute
,
3354 .dumpit
= inet6_dump_fib
, },
3357 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3359 inet6_ifa_notify(event
? : RTM_NEWADDR
, ifp
);
3363 ip6_ins_rt(ifp
->rt
, NULL
, NULL
, NULL
);
3364 if (ifp
->idev
->cnf
.forwarding
)
3365 addrconf_join_anycast(ifp
);
3368 if (ifp
->idev
->cnf
.forwarding
)
3369 addrconf_leave_anycast(ifp
);
3370 addrconf_leave_solict(ifp
->idev
, &ifp
->addr
);
3371 dst_hold(&ifp
->rt
->u
.dst
);
3372 if (ip6_del_rt(ifp
->rt
, NULL
, NULL
, NULL
))
3373 dst_free(&ifp
->rt
->u
.dst
);
3378 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3380 read_lock_bh(&addrconf_lock
);
3381 if (likely(ifp
->idev
->dead
== 0))
3382 __ipv6_ifa_notify(event
, ifp
);
3383 read_unlock_bh(&addrconf_lock
);
3386 #ifdef CONFIG_SYSCTL
3389 int addrconf_sysctl_forward(ctl_table
*ctl
, int write
, struct file
* filp
,
3390 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3392 int *valp
= ctl
->data
;
3396 ret
= proc_dointvec(ctl
, write
, filp
, buffer
, lenp
, ppos
);
3398 if (write
&& valp
!= &ipv6_devconf_dflt
.forwarding
) {
3399 if (valp
!= &ipv6_devconf
.forwarding
) {
3400 if ((!*valp
) ^ (!val
)) {
3401 struct inet6_dev
*idev
= (struct inet6_dev
*)ctl
->extra1
;
3404 dev_forward_change(idev
);
3407 ipv6_devconf_dflt
.forwarding
= ipv6_devconf
.forwarding
;
3408 addrconf_forward_change();
3411 rt6_purge_dflt_routers();
3417 static int addrconf_sysctl_forward_strategy(ctl_table
*table
,
3418 int __user
*name
, int nlen
,
3419 void __user
*oldval
,
3420 size_t __user
*oldlenp
,
3421 void __user
*newval
, size_t newlen
,
3424 int *valp
= table
->data
;
3427 if (!newval
|| !newlen
)
3429 if (newlen
!= sizeof(int))
3431 if (get_user(new, (int __user
*)newval
))
3435 if (oldval
&& oldlenp
) {
3437 if (get_user(len
, oldlenp
))
3440 if (len
> table
->maxlen
)
3441 len
= table
->maxlen
;
3442 if (copy_to_user(oldval
, valp
, len
))
3444 if (put_user(len
, oldlenp
))
3449 if (valp
!= &ipv6_devconf_dflt
.forwarding
) {
3450 if (valp
!= &ipv6_devconf
.forwarding
) {
3451 struct inet6_dev
*idev
= (struct inet6_dev
*)table
->extra1
;
3453 if (unlikely(idev
== NULL
))
3455 changed
= (!*valp
) ^ (!new);
3458 dev_forward_change(idev
);
3461 addrconf_forward_change();
3465 rt6_purge_dflt_routers();
3472 static struct addrconf_sysctl_table
3474 struct ctl_table_header
*sysctl_header
;
3475 ctl_table addrconf_vars
[__NET_IPV6_MAX
];
3476 ctl_table addrconf_dev
[2];
3477 ctl_table addrconf_conf_dir
[2];
3478 ctl_table addrconf_proto_dir
[2];
3479 ctl_table addrconf_root_dir
[2];
3480 } addrconf_sysctl
= {
3481 .sysctl_header
= NULL
,
3484 .ctl_name
= NET_IPV6_FORWARDING
,
3485 .procname
= "forwarding",
3486 .data
= &ipv6_devconf
.forwarding
,
3487 .maxlen
= sizeof(int),
3489 .proc_handler
= &addrconf_sysctl_forward
,
3490 .strategy
= &addrconf_sysctl_forward_strategy
,
3493 .ctl_name
= NET_IPV6_HOP_LIMIT
,
3494 .procname
= "hop_limit",
3495 .data
= &ipv6_devconf
.hop_limit
,
3496 .maxlen
= sizeof(int),
3498 .proc_handler
= proc_dointvec
,
3501 .ctl_name
= NET_IPV6_MTU
,
3503 .data
= &ipv6_devconf
.mtu6
,
3504 .maxlen
= sizeof(int),
3506 .proc_handler
= &proc_dointvec
,
3509 .ctl_name
= NET_IPV6_ACCEPT_RA
,
3510 .procname
= "accept_ra",
3511 .data
= &ipv6_devconf
.accept_ra
,
3512 .maxlen
= sizeof(int),
3514 .proc_handler
= &proc_dointvec
,
3517 .ctl_name
= NET_IPV6_ACCEPT_REDIRECTS
,
3518 .procname
= "accept_redirects",
3519 .data
= &ipv6_devconf
.accept_redirects
,
3520 .maxlen
= sizeof(int),
3522 .proc_handler
= &proc_dointvec
,
3525 .ctl_name
= NET_IPV6_AUTOCONF
,
3526 .procname
= "autoconf",
3527 .data
= &ipv6_devconf
.autoconf
,
3528 .maxlen
= sizeof(int),
3530 .proc_handler
= &proc_dointvec
,
3533 .ctl_name
= NET_IPV6_DAD_TRANSMITS
,
3534 .procname
= "dad_transmits",
3535 .data
= &ipv6_devconf
.dad_transmits
,
3536 .maxlen
= sizeof(int),
3538 .proc_handler
= &proc_dointvec
,
3541 .ctl_name
= NET_IPV6_RTR_SOLICITS
,
3542 .procname
= "router_solicitations",
3543 .data
= &ipv6_devconf
.rtr_solicits
,
3544 .maxlen
= sizeof(int),
3546 .proc_handler
= &proc_dointvec
,
3549 .ctl_name
= NET_IPV6_RTR_SOLICIT_INTERVAL
,
3550 .procname
= "router_solicitation_interval",
3551 .data
= &ipv6_devconf
.rtr_solicit_interval
,
3552 .maxlen
= sizeof(int),
3554 .proc_handler
= &proc_dointvec_jiffies
,
3555 .strategy
= &sysctl_jiffies
,
3558 .ctl_name
= NET_IPV6_RTR_SOLICIT_DELAY
,
3559 .procname
= "router_solicitation_delay",
3560 .data
= &ipv6_devconf
.rtr_solicit_delay
,
3561 .maxlen
= sizeof(int),
3563 .proc_handler
= &proc_dointvec_jiffies
,
3564 .strategy
= &sysctl_jiffies
,
3567 .ctl_name
= NET_IPV6_FORCE_MLD_VERSION
,
3568 .procname
= "force_mld_version",
3569 .data
= &ipv6_devconf
.force_mld_version
,
3570 .maxlen
= sizeof(int),
3572 .proc_handler
= &proc_dointvec
,
3574 #ifdef CONFIG_IPV6_PRIVACY
3576 .ctl_name
= NET_IPV6_USE_TEMPADDR
,
3577 .procname
= "use_tempaddr",
3578 .data
= &ipv6_devconf
.use_tempaddr
,
3579 .maxlen
= sizeof(int),
3581 .proc_handler
= &proc_dointvec
,
3584 .ctl_name
= NET_IPV6_TEMP_VALID_LFT
,
3585 .procname
= "temp_valid_lft",
3586 .data
= &ipv6_devconf
.temp_valid_lft
,
3587 .maxlen
= sizeof(int),
3589 .proc_handler
= &proc_dointvec
,
3592 .ctl_name
= NET_IPV6_TEMP_PREFERED_LFT
,
3593 .procname
= "temp_prefered_lft",
3594 .data
= &ipv6_devconf
.temp_prefered_lft
,
3595 .maxlen
= sizeof(int),
3597 .proc_handler
= &proc_dointvec
,
3600 .ctl_name
= NET_IPV6_REGEN_MAX_RETRY
,
3601 .procname
= "regen_max_retry",
3602 .data
= &ipv6_devconf
.regen_max_retry
,
3603 .maxlen
= sizeof(int),
3605 .proc_handler
= &proc_dointvec
,
3608 .ctl_name
= NET_IPV6_MAX_DESYNC_FACTOR
,
3609 .procname
= "max_desync_factor",
3610 .data
= &ipv6_devconf
.max_desync_factor
,
3611 .maxlen
= sizeof(int),
3613 .proc_handler
= &proc_dointvec
,
3617 .ctl_name
= NET_IPV6_MAX_ADDRESSES
,
3618 .procname
= "max_addresses",
3619 .data
= &ipv6_devconf
.max_addresses
,
3620 .maxlen
= sizeof(int),
3622 .proc_handler
= &proc_dointvec
,
3625 .ctl_name
= NET_IPV6_ACCEPT_RA_DEFRTR
,
3626 .procname
= "accept_ra_defrtr",
3627 .data
= &ipv6_devconf
.accept_ra_defrtr
,
3628 .maxlen
= sizeof(int),
3630 .proc_handler
= &proc_dointvec
,
3633 .ctl_name
= NET_IPV6_ACCEPT_RA_PINFO
,
3634 .procname
= "accept_ra_pinfo",
3635 .data
= &ipv6_devconf
.accept_ra_pinfo
,
3636 .maxlen
= sizeof(int),
3638 .proc_handler
= &proc_dointvec
,
3640 #ifdef CONFIG_IPV6_ROUTER_PREF
3642 .ctl_name
= NET_IPV6_ACCEPT_RA_RTR_PREF
,
3643 .procname
= "accept_ra_rtr_pref",
3644 .data
= &ipv6_devconf
.accept_ra_rtr_pref
,
3645 .maxlen
= sizeof(int),
3647 .proc_handler
= &proc_dointvec
,
3650 .ctl_name
= NET_IPV6_RTR_PROBE_INTERVAL
,
3651 .procname
= "router_probe_interval",
3652 .data
= &ipv6_devconf
.rtr_probe_interval
,
3653 .maxlen
= sizeof(int),
3655 .proc_handler
= &proc_dointvec_jiffies
,
3656 .strategy
= &sysctl_jiffies
,
3658 #ifdef CONFIV_IPV6_ROUTE_INFO
3660 .ctl_name
= NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN
,
3661 .procname
= "accept_ra_rt_info_max_plen",
3662 .data
= &ipv6_devconf
.accept_ra_rt_info_max_plen
,
3663 .maxlen
= sizeof(int),
3665 .proc_handler
= &proc_dointvec
,
3670 .ctl_name
= 0, /* sentinel */
3675 .ctl_name
= NET_PROTO_CONF_ALL
,
3678 .child
= addrconf_sysctl
.addrconf_vars
,
3681 .ctl_name
= 0, /* sentinel */
3684 .addrconf_conf_dir
= {
3686 .ctl_name
= NET_IPV6_CONF
,
3689 .child
= addrconf_sysctl
.addrconf_dev
,
3692 .ctl_name
= 0, /* sentinel */
3695 .addrconf_proto_dir
= {
3697 .ctl_name
= NET_IPV6
,
3700 .child
= addrconf_sysctl
.addrconf_conf_dir
,
3703 .ctl_name
= 0, /* sentinel */
3706 .addrconf_root_dir
= {
3708 .ctl_name
= CTL_NET
,
3711 .child
= addrconf_sysctl
.addrconf_proto_dir
,
3714 .ctl_name
= 0, /* sentinel */
3719 static void addrconf_sysctl_register(struct inet6_dev
*idev
, struct ipv6_devconf
*p
)
3722 struct net_device
*dev
= idev
? idev
->dev
: NULL
;
3723 struct addrconf_sysctl_table
*t
;
3724 char *dev_name
= NULL
;
3726 t
= kmalloc(sizeof(*t
), GFP_KERNEL
);
3729 memcpy(t
, &addrconf_sysctl
, sizeof(*t
));
3730 for (i
=0; t
->addrconf_vars
[i
].data
; i
++) {
3731 t
->addrconf_vars
[i
].data
+= (char*)p
- (char*)&ipv6_devconf
;
3732 t
->addrconf_vars
[i
].de
= NULL
;
3733 t
->addrconf_vars
[i
].extra1
= idev
; /* embedded; no ref */
3736 dev_name
= dev
->name
;
3737 t
->addrconf_dev
[0].ctl_name
= dev
->ifindex
;
3739 dev_name
= "default";
3740 t
->addrconf_dev
[0].ctl_name
= NET_PROTO_CONF_DEFAULT
;
3744 * Make a copy of dev_name, because '.procname' is regarded as const
3745 * by sysctl and we wouldn't want anyone to change it under our feet
3746 * (see SIOCSIFNAME).
3748 dev_name
= kstrdup(dev_name
, GFP_KERNEL
);
3752 t
->addrconf_dev
[0].procname
= dev_name
;
3754 t
->addrconf_dev
[0].child
= t
->addrconf_vars
;
3755 t
->addrconf_dev
[0].de
= NULL
;
3756 t
->addrconf_conf_dir
[0].child
= t
->addrconf_dev
;
3757 t
->addrconf_conf_dir
[0].de
= NULL
;
3758 t
->addrconf_proto_dir
[0].child
= t
->addrconf_conf_dir
;
3759 t
->addrconf_proto_dir
[0].de
= NULL
;
3760 t
->addrconf_root_dir
[0].child
= t
->addrconf_proto_dir
;
3761 t
->addrconf_root_dir
[0].de
= NULL
;
3763 t
->sysctl_header
= register_sysctl_table(t
->addrconf_root_dir
, 0);
3764 if (t
->sysctl_header
== NULL
)
3779 static void addrconf_sysctl_unregister(struct ipv6_devconf
*p
)
3782 struct addrconf_sysctl_table
*t
= p
->sysctl
;
3784 unregister_sysctl_table(t
->sysctl_header
);
3785 kfree(t
->addrconf_dev
[0].procname
);
3797 int register_inet6addr_notifier(struct notifier_block
*nb
)
3799 return atomic_notifier_chain_register(&inet6addr_chain
, nb
);
3802 int unregister_inet6addr_notifier(struct notifier_block
*nb
)
3804 return atomic_notifier_chain_unregister(&inet6addr_chain
,nb
);
3808 * Init / cleanup code
3811 int __init
addrconf_init(void)
3815 /* The addrconf netdev notifier requires that loopback_dev
3816 * has it's ipv6 private information allocated and setup
3817 * before it can bring up and give link-local addresses
3818 * to other devices which are up.
3820 * Unfortunately, loopback_dev is not necessarily the first
3821 * entry in the global dev_base list of net devices. In fact,
3822 * it is likely to be the very last entry on that list.
3823 * So this causes the notifier registry below to try and
3824 * give link-local addresses to all devices besides loopback_dev
3825 * first, then loopback_dev, which cases all the non-loopback_dev
3826 * devices to fail to get a link-local address.
3828 * So, as a temporary fix, allocate the ipv6 structure for
3829 * loopback_dev first by hand.
3830 * Longer term, all of the dependencies ipv6 has upon the loopback
3831 * device and it being up should be removed.
3834 if (!ipv6_add_dev(&loopback_dev
))
3840 ip6_null_entry
.rt6i_idev
= in6_dev_get(&loopback_dev
);
3842 register_netdevice_notifier(&ipv6_dev_notf
);
3845 rtnetlink_links
[PF_INET6
] = inet6_rtnetlink_table
;
3846 #ifdef CONFIG_SYSCTL
3847 addrconf_sysctl
.sysctl_header
=
3848 register_sysctl_table(addrconf_sysctl
.addrconf_root_dir
, 0);
3849 addrconf_sysctl_register(NULL
, &ipv6_devconf_dflt
);
3855 void __exit
addrconf_cleanup(void)
3857 struct net_device
*dev
;
3858 struct inet6_dev
*idev
;
3859 struct inet6_ifaddr
*ifa
;
3862 unregister_netdevice_notifier(&ipv6_dev_notf
);
3864 rtnetlink_links
[PF_INET6
] = NULL
;
3865 #ifdef CONFIG_SYSCTL
3866 addrconf_sysctl_unregister(&ipv6_devconf_dflt
);
3867 addrconf_sysctl_unregister(&ipv6_devconf
);
3876 for (dev
=dev_base
; dev
; dev
=dev
->next
) {
3877 if ((idev
= __in6_dev_get(dev
)) == NULL
)
3879 addrconf_ifdown(dev
, 1);
3881 addrconf_ifdown(&loopback_dev
, 2);
3887 write_lock_bh(&addrconf_hash_lock
);
3888 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
3889 for (ifa
=inet6_addr_lst
[i
]; ifa
; ) {
3890 struct inet6_ifaddr
*bifa
;
3893 ifa
= ifa
->lst_next
;
3894 printk(KERN_DEBUG
"bug: IPv6 address leakage detected: ifa=%p\n", bifa
);
3895 /* Do not free it; something is wrong.
3896 Now we can investigate it with debugger.
3900 write_unlock_bh(&addrconf_hash_lock
);
3902 del_timer(&addr_chk_timer
);
3906 #ifdef CONFIG_PROC_FS
3907 proc_net_remove("if_inet6");