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_addr.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 <net/netlink.h>
77 #include <linux/if_tunnel.h>
78 #include <linux/rtnetlink.h>
80 #ifdef CONFIG_IPV6_PRIVACY
81 #include <linux/random.h>
84 #include <asm/uaccess.h>
86 #include <linux/proc_fs.h>
87 #include <linux/seq_file.h>
89 /* Set to 3 to get tracing... */
93 #define ADBG(x) printk x
98 #define INFINITY_LIFE_TIME 0xFFFFFFFF
99 #define TIME_DELTA(a,b) ((unsigned long)((long)(a) - (long)(b)))
102 static void addrconf_sysctl_register(struct inet6_dev
*idev
, struct ipv6_devconf
*p
);
103 static void addrconf_sysctl_unregister(struct ipv6_devconf
*p
);
106 #ifdef CONFIG_IPV6_PRIVACY
107 static int __ipv6_regen_rndid(struct inet6_dev
*idev
);
108 static int __ipv6_try_regen_rndid(struct inet6_dev
*idev
, struct in6_addr
*tmpaddr
);
109 static void ipv6_regen_rndid(unsigned long data
);
111 static int desync_factor
= MAX_DESYNC_FACTOR
* HZ
;
114 static int ipv6_count_addresses(struct inet6_dev
*idev
);
117 * Configured unicast address hash table
119 static struct inet6_ifaddr
*inet6_addr_lst
[IN6_ADDR_HSIZE
];
120 static DEFINE_RWLOCK(addrconf_hash_lock
);
122 /* Protects inet6 devices */
123 DEFINE_RWLOCK(addrconf_lock
);
125 static void addrconf_verify(unsigned long);
127 static DEFINE_TIMER(addr_chk_timer
, addrconf_verify
, 0, 0);
128 static DEFINE_SPINLOCK(addrconf_verify_lock
);
130 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
);
131 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
);
133 static int addrconf_ifdown(struct net_device
*dev
, int how
);
135 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
);
136 static void addrconf_dad_timer(unsigned long data
);
137 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
);
138 static void addrconf_dad_run(struct inet6_dev
*idev
);
139 static void addrconf_rs_timer(unsigned long data
);
140 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
);
141 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
);
143 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
144 struct prefix_info
*pinfo
);
145 static int ipv6_chk_same_addr(const struct in6_addr
*addr
, struct net_device
*dev
);
147 static ATOMIC_NOTIFIER_HEAD(inet6addr_chain
);
149 struct ipv6_devconf ipv6_devconf __read_mostly
= {
151 .hop_limit
= IPV6_DEFAULT_HOPLIMIT
,
152 .mtu6
= IPV6_MIN_MTU
,
154 .accept_redirects
= 1,
156 .force_mld_version
= 0,
158 .rtr_solicits
= MAX_RTR_SOLICITATIONS
,
159 .rtr_solicit_interval
= RTR_SOLICITATION_INTERVAL
,
160 .rtr_solicit_delay
= MAX_RTR_SOLICITATION_DELAY
,
161 #ifdef CONFIG_IPV6_PRIVACY
163 .temp_valid_lft
= TEMP_VALID_LIFETIME
,
164 .temp_prefered_lft
= TEMP_PREFERRED_LIFETIME
,
165 .regen_max_retry
= REGEN_MAX_RETRY
,
166 .max_desync_factor
= MAX_DESYNC_FACTOR
,
168 .max_addresses
= IPV6_MAX_ADDRESSES
,
169 .accept_ra_defrtr
= 1,
170 .accept_ra_pinfo
= 1,
171 #ifdef CONFIG_IPV6_ROUTER_PREF
172 .accept_ra_rtr_pref
= 1,
173 .rtr_probe_interval
= 60 * HZ
,
174 #ifdef CONFIG_IPV6_ROUTE_INFO
175 .accept_ra_rt_info_max_plen
= 0,
180 static struct ipv6_devconf ipv6_devconf_dflt __read_mostly
= {
182 .hop_limit
= IPV6_DEFAULT_HOPLIMIT
,
183 .mtu6
= IPV6_MIN_MTU
,
185 .accept_redirects
= 1,
188 .rtr_solicits
= MAX_RTR_SOLICITATIONS
,
189 .rtr_solicit_interval
= RTR_SOLICITATION_INTERVAL
,
190 .rtr_solicit_delay
= MAX_RTR_SOLICITATION_DELAY
,
191 #ifdef CONFIG_IPV6_PRIVACY
193 .temp_valid_lft
= TEMP_VALID_LIFETIME
,
194 .temp_prefered_lft
= TEMP_PREFERRED_LIFETIME
,
195 .regen_max_retry
= REGEN_MAX_RETRY
,
196 .max_desync_factor
= MAX_DESYNC_FACTOR
,
198 .max_addresses
= IPV6_MAX_ADDRESSES
,
199 .accept_ra_defrtr
= 1,
200 .accept_ra_pinfo
= 1,
201 #ifdef CONFIG_IPV6_ROUTER_PREF
202 .accept_ra_rtr_pref
= 1,
203 .rtr_probe_interval
= 60 * HZ
,
204 #ifdef CONFIG_IPV6_ROUTE_INFO
205 .accept_ra_rt_info_max_plen
= 0,
210 /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
212 const struct in6_addr in6addr_any
= IN6ADDR_ANY_INIT
;
214 const struct in6_addr in6addr_loopback
= IN6ADDR_LOOPBACK_INIT
;
216 #define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
218 static inline unsigned ipv6_addr_scope2type(unsigned scope
)
221 case IPV6_ADDR_SCOPE_NODELOCAL
:
222 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_NODELOCAL
) |
224 case IPV6_ADDR_SCOPE_LINKLOCAL
:
225 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
) |
226 IPV6_ADDR_LINKLOCAL
);
227 case IPV6_ADDR_SCOPE_SITELOCAL
:
228 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL
) |
229 IPV6_ADDR_SITELOCAL
);
231 return IPV6_ADDR_SCOPE_TYPE(scope
);
234 int __ipv6_addr_type(const struct in6_addr
*addr
)
238 st
= addr
->s6_addr32
[0];
240 /* Consider all addresses with the first three bits different of
241 000 and 111 as unicasts.
243 if ((st
& htonl(0xE0000000)) != htonl(0x00000000) &&
244 (st
& htonl(0xE0000000)) != htonl(0xE0000000))
245 return (IPV6_ADDR_UNICAST
|
246 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
));
248 if ((st
& htonl(0xFF000000)) == htonl(0xFF000000)) {
250 /* addr-select 3.1 */
251 return (IPV6_ADDR_MULTICAST
|
252 ipv6_addr_scope2type(IPV6_ADDR_MC_SCOPE(addr
)));
255 if ((st
& htonl(0xFFC00000)) == htonl(0xFE800000))
256 return (IPV6_ADDR_LINKLOCAL
| IPV6_ADDR_UNICAST
|
257 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
)); /* addr-select 3.1 */
258 if ((st
& htonl(0xFFC00000)) == htonl(0xFEC00000))
259 return (IPV6_ADDR_SITELOCAL
| IPV6_ADDR_UNICAST
|
260 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL
)); /* addr-select 3.1 */
262 if ((addr
->s6_addr32
[0] | addr
->s6_addr32
[1]) == 0) {
263 if (addr
->s6_addr32
[2] == 0) {
264 if (addr
->s6_addr32
[3] == 0)
265 return IPV6_ADDR_ANY
;
267 if (addr
->s6_addr32
[3] == htonl(0x00000001))
268 return (IPV6_ADDR_LOOPBACK
| IPV6_ADDR_UNICAST
|
269 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
)); /* addr-select 3.4 */
271 return (IPV6_ADDR_COMPATv4
| IPV6_ADDR_UNICAST
|
272 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.3 */
275 if (addr
->s6_addr32
[2] == htonl(0x0000ffff))
276 return (IPV6_ADDR_MAPPED
|
277 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.3 */
280 return (IPV6_ADDR_RESERVED
|
281 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.4 */
284 static void addrconf_del_timer(struct inet6_ifaddr
*ifp
)
286 if (del_timer(&ifp
->timer
))
290 enum addrconf_timer_t
297 static void addrconf_mod_timer(struct inet6_ifaddr
*ifp
,
298 enum addrconf_timer_t what
,
301 if (!del_timer(&ifp
->timer
))
306 ifp
->timer
.function
= addrconf_dad_timer
;
309 ifp
->timer
.function
= addrconf_rs_timer
;
313 ifp
->timer
.expires
= jiffies
+ when
;
314 add_timer(&ifp
->timer
);
317 /* Nobody refers to this device, we may destroy it. */
319 void in6_dev_finish_destroy(struct inet6_dev
*idev
)
321 struct net_device
*dev
= idev
->dev
;
322 BUG_TRAP(idev
->addr_list
==NULL
);
323 BUG_TRAP(idev
->mc_list
==NULL
);
324 #ifdef NET_REFCNT_DEBUG
325 printk(KERN_DEBUG
"in6_dev_finish_destroy: %s\n", dev
? dev
->name
: "NIL");
329 printk("Freeing alive inet6 device %p\n", idev
);
332 snmp6_free_dev(idev
);
336 static struct inet6_dev
* ipv6_add_dev(struct net_device
*dev
)
338 struct inet6_dev
*ndev
;
342 if (dev
->mtu
< IPV6_MIN_MTU
)
345 ndev
= kzalloc(sizeof(struct inet6_dev
), GFP_KERNEL
);
350 rwlock_init(&ndev
->lock
);
352 memcpy(&ndev
->cnf
, &ipv6_devconf_dflt
, sizeof(ndev
->cnf
));
353 ndev
->cnf
.mtu6
= dev
->mtu
;
354 ndev
->cnf
.sysctl
= NULL
;
355 ndev
->nd_parms
= neigh_parms_alloc(dev
, &nd_tbl
);
356 if (ndev
->nd_parms
== NULL
) {
360 /* We refer to the device */
363 if (snmp6_alloc_dev(ndev
) < 0) {
365 "%s(): cannot allocate memory for statistics; dev=%s.\n",
366 __FUNCTION__
, dev
->name
));
367 neigh_parms_release(&nd_tbl
, ndev
->nd_parms
);
369 in6_dev_finish_destroy(ndev
);
373 if (snmp6_register_dev(ndev
) < 0) {
375 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
376 __FUNCTION__
, dev
->name
));
377 neigh_parms_release(&nd_tbl
, ndev
->nd_parms
);
379 in6_dev_finish_destroy(ndev
);
383 /* One reference from device. We must do this before
384 * we invoke __ipv6_regen_rndid().
388 #ifdef CONFIG_IPV6_PRIVACY
389 init_timer(&ndev
->regen_timer
);
390 ndev
->regen_timer
.function
= ipv6_regen_rndid
;
391 ndev
->regen_timer
.data
= (unsigned long) ndev
;
392 if ((dev
->flags
&IFF_LOOPBACK
) ||
393 dev
->type
== ARPHRD_TUNNEL
||
394 dev
->type
== ARPHRD_NONE
||
395 dev
->type
== ARPHRD_SIT
) {
397 "%s: Disabled Privacy Extensions\n",
399 ndev
->cnf
.use_tempaddr
= -1;
402 ipv6_regen_rndid((unsigned long) ndev
);
406 if (netif_carrier_ok(dev
))
407 ndev
->if_flags
|= IF_READY
;
409 write_lock_bh(&addrconf_lock
);
411 write_unlock_bh(&addrconf_lock
);
413 ipv6_mc_init_dev(ndev
);
414 ndev
->tstamp
= jiffies
;
416 neigh_sysctl_register(dev
, ndev
->nd_parms
, NET_IPV6
,
417 NET_IPV6_NEIGH
, "ipv6",
418 &ndisc_ifinfo_sysctl_change
,
420 addrconf_sysctl_register(ndev
, &ndev
->cnf
);
425 static struct inet6_dev
* ipv6_find_idev(struct net_device
*dev
)
427 struct inet6_dev
*idev
;
431 if ((idev
= __in6_dev_get(dev
)) == NULL
) {
432 if ((idev
= ipv6_add_dev(dev
)) == NULL
)
436 if (dev
->flags
&IFF_UP
)
442 static void dev_forward_change(struct inet6_dev
*idev
)
444 struct net_device
*dev
;
445 struct inet6_ifaddr
*ifa
;
446 struct in6_addr addr
;
451 if (dev
&& (dev
->flags
& IFF_MULTICAST
)) {
452 ipv6_addr_all_routers(&addr
);
454 if (idev
->cnf
.forwarding
)
455 ipv6_dev_mc_inc(dev
, &addr
);
457 ipv6_dev_mc_dec(dev
, &addr
);
459 for (ifa
=idev
->addr_list
; ifa
; ifa
=ifa
->if_next
) {
460 if (idev
->cnf
.forwarding
)
461 addrconf_join_anycast(ifa
);
463 addrconf_leave_anycast(ifa
);
468 static void addrconf_forward_change(void)
470 struct net_device
*dev
;
471 struct inet6_dev
*idev
;
473 read_lock(&dev_base_lock
);
474 for (dev
=dev_base
; dev
; dev
=dev
->next
) {
475 read_lock(&addrconf_lock
);
476 idev
= __in6_dev_get(dev
);
478 int changed
= (!idev
->cnf
.forwarding
) ^ (!ipv6_devconf
.forwarding
);
479 idev
->cnf
.forwarding
= ipv6_devconf
.forwarding
;
481 dev_forward_change(idev
);
483 read_unlock(&addrconf_lock
);
485 read_unlock(&dev_base_lock
);
489 /* Nobody refers to this ifaddr, destroy it */
491 void inet6_ifa_finish_destroy(struct inet6_ifaddr
*ifp
)
493 BUG_TRAP(ifp
->if_next
==NULL
);
494 BUG_TRAP(ifp
->lst_next
==NULL
);
495 #ifdef NET_REFCNT_DEBUG
496 printk(KERN_DEBUG
"inet6_ifa_finish_destroy\n");
499 in6_dev_put(ifp
->idev
);
501 if (del_timer(&ifp
->timer
))
502 printk("Timer is still running, when freeing ifa=%p\n", ifp
);
505 printk("Freeing alive inet6 address %p\n", ifp
);
508 dst_release(&ifp
->rt
->u
.dst
);
514 ipv6_link_dev_addr(struct inet6_dev
*idev
, struct inet6_ifaddr
*ifp
)
516 struct inet6_ifaddr
*ifa
, **ifap
;
517 int ifp_scope
= ipv6_addr_src_scope(&ifp
->addr
);
520 * Each device address list is sorted in order of scope -
521 * global before linklocal.
523 for (ifap
= &idev
->addr_list
; (ifa
= *ifap
) != NULL
;
524 ifap
= &ifa
->if_next
) {
525 if (ifp_scope
>= ipv6_addr_src_scope(&ifa
->addr
))
529 ifp
->if_next
= *ifap
;
533 /* On success it returns ifp with increased reference count */
535 static struct inet6_ifaddr
*
536 ipv6_add_addr(struct inet6_dev
*idev
, const struct in6_addr
*addr
, int pfxlen
,
537 int scope
, u32 flags
)
539 struct inet6_ifaddr
*ifa
= NULL
;
544 read_lock_bh(&addrconf_lock
);
546 err
= -ENODEV
; /*XXX*/
550 write_lock(&addrconf_hash_lock
);
552 /* Ignore adding duplicate addresses on an interface */
553 if (ipv6_chk_same_addr(addr
, idev
->dev
)) {
554 ADBG(("ipv6_add_addr: already assigned\n"));
559 ifa
= kzalloc(sizeof(struct inet6_ifaddr
), GFP_ATOMIC
);
562 ADBG(("ipv6_add_addr: malloc failed\n"));
567 rt
= addrconf_dst_alloc(idev
, addr
, 0);
573 ipv6_addr_copy(&ifa
->addr
, addr
);
575 spin_lock_init(&ifa
->lock
);
576 init_timer(&ifa
->timer
);
577 ifa
->timer
.data
= (unsigned long) ifa
;
579 ifa
->prefix_len
= pfxlen
;
580 ifa
->flags
= flags
| IFA_F_TENTATIVE
;
581 ifa
->cstamp
= ifa
->tstamp
= jiffies
;
590 /* Add to big hash table */
591 hash
= ipv6_addr_hash(addr
);
593 ifa
->lst_next
= inet6_addr_lst
[hash
];
594 inet6_addr_lst
[hash
] = ifa
;
596 write_unlock(&addrconf_hash_lock
);
598 write_lock(&idev
->lock
);
599 /* Add to inet6_dev unicast addr list. */
600 ipv6_link_dev_addr(idev
, ifa
);
602 #ifdef CONFIG_IPV6_PRIVACY
603 if (ifa
->flags
&IFA_F_TEMPORARY
) {
604 ifa
->tmp_next
= idev
->tempaddr_list
;
605 idev
->tempaddr_list
= ifa
;
611 write_unlock(&idev
->lock
);
613 read_unlock_bh(&addrconf_lock
);
615 if (likely(err
== 0))
616 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_UP
, ifa
);
624 write_unlock(&addrconf_hash_lock
);
628 /* This function wants to get referenced ifp and releases it before return */
630 static void ipv6_del_addr(struct inet6_ifaddr
*ifp
)
632 struct inet6_ifaddr
*ifa
, **ifap
;
633 struct inet6_dev
*idev
= ifp
->idev
;
635 int deleted
= 0, onlink
= 0;
636 unsigned long expires
= jiffies
;
638 hash
= ipv6_addr_hash(&ifp
->addr
);
642 write_lock_bh(&addrconf_hash_lock
);
643 for (ifap
= &inet6_addr_lst
[hash
]; (ifa
=*ifap
) != NULL
;
644 ifap
= &ifa
->lst_next
) {
646 *ifap
= ifa
->lst_next
;
648 ifa
->lst_next
= NULL
;
652 write_unlock_bh(&addrconf_hash_lock
);
654 write_lock_bh(&idev
->lock
);
655 #ifdef CONFIG_IPV6_PRIVACY
656 if (ifp
->flags
&IFA_F_TEMPORARY
) {
657 for (ifap
= &idev
->tempaddr_list
; (ifa
=*ifap
) != NULL
;
658 ifap
= &ifa
->tmp_next
) {
660 *ifap
= ifa
->tmp_next
;
662 in6_ifa_put(ifp
->ifpub
);
666 ifa
->tmp_next
= NULL
;
673 for (ifap
= &idev
->addr_list
; (ifa
=*ifap
) != NULL
;) {
675 *ifap
= ifa
->if_next
;
678 if (!(ifp
->flags
& IFA_F_PERMANENT
) || onlink
> 0)
682 } else if (ifp
->flags
& IFA_F_PERMANENT
) {
683 if (ipv6_prefix_equal(&ifa
->addr
, &ifp
->addr
,
685 if (ifa
->flags
& IFA_F_PERMANENT
) {
690 unsigned long lifetime
;
695 spin_lock(&ifa
->lock
);
696 lifetime
= min_t(unsigned long,
697 ifa
->valid_lft
, 0x7fffffffUL
/HZ
);
698 if (time_before(expires
,
699 ifa
->tstamp
+ lifetime
* HZ
))
700 expires
= ifa
->tstamp
+ lifetime
* HZ
;
701 spin_unlock(&ifa
->lock
);
705 ifap
= &ifa
->if_next
;
707 write_unlock_bh(&idev
->lock
);
709 ipv6_ifa_notify(RTM_DELADDR
, ifp
);
711 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_DOWN
, ifp
);
713 addrconf_del_timer(ifp
);
716 * Purge or update corresponding prefix
718 * 1) we don't purge prefix here if address was not permanent.
719 * prefix is managed by its own lifetime.
720 * 2) if there're no addresses, delete prefix.
721 * 3) if there're still other permanent address(es),
722 * corresponding prefix is still permanent.
723 * 4) otherwise, update prefix lifetime to the
724 * longest valid lifetime among the corresponding
725 * addresses on the device.
726 * Note: subsequent RA will update lifetime.
730 if ((ifp
->flags
& IFA_F_PERMANENT
) && onlink
< 1) {
731 struct in6_addr prefix
;
734 ipv6_addr_prefix(&prefix
, &ifp
->addr
, ifp
->prefix_len
);
735 rt
= rt6_lookup(&prefix
, NULL
, ifp
->idev
->dev
->ifindex
, 1);
737 if (rt
&& ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0)) {
739 ip6_del_rt(rt
, NULL
, NULL
, NULL
);
741 } else if (!(rt
->rt6i_flags
& RTF_EXPIRES
)) {
742 rt
->rt6i_expires
= expires
;
743 rt
->rt6i_flags
|= RTF_EXPIRES
;
746 dst_release(&rt
->u
.dst
);
752 #ifdef CONFIG_IPV6_PRIVACY
753 static int ipv6_create_tempaddr(struct inet6_ifaddr
*ifp
, struct inet6_ifaddr
*ift
)
755 struct inet6_dev
*idev
= ifp
->idev
;
756 struct in6_addr addr
, *tmpaddr
;
757 unsigned long tmp_prefered_lft
, tmp_valid_lft
, tmp_cstamp
, tmp_tstamp
;
762 write_lock(&idev
->lock
);
764 spin_lock_bh(&ift
->lock
);
765 memcpy(&addr
.s6_addr
[8], &ift
->addr
.s6_addr
[8], 8);
766 spin_unlock_bh(&ift
->lock
);
773 if (idev
->cnf
.use_tempaddr
<= 0) {
774 write_unlock(&idev
->lock
);
776 "ipv6_create_tempaddr(): use_tempaddr is disabled.\n");
781 spin_lock_bh(&ifp
->lock
);
782 if (ifp
->regen_count
++ >= idev
->cnf
.regen_max_retry
) {
783 idev
->cnf
.use_tempaddr
= -1; /*XXX*/
784 spin_unlock_bh(&ifp
->lock
);
785 write_unlock(&idev
->lock
);
787 "ipv6_create_tempaddr(): regeneration time exceeded. disabled temporary address support.\n");
793 memcpy(addr
.s6_addr
, ifp
->addr
.s6_addr
, 8);
794 if (__ipv6_try_regen_rndid(idev
, tmpaddr
) < 0) {
795 spin_unlock_bh(&ifp
->lock
);
796 write_unlock(&idev
->lock
);
798 "ipv6_create_tempaddr(): regeneration of randomized interface id failed.\n");
804 memcpy(&addr
.s6_addr
[8], idev
->rndid
, 8);
805 tmp_valid_lft
= min_t(__u32
,
807 idev
->cnf
.temp_valid_lft
);
808 tmp_prefered_lft
= min_t(__u32
,
810 idev
->cnf
.temp_prefered_lft
- desync_factor
/ HZ
);
811 tmp_plen
= ifp
->prefix_len
;
812 max_addresses
= idev
->cnf
.max_addresses
;
813 tmp_cstamp
= ifp
->cstamp
;
814 tmp_tstamp
= ifp
->tstamp
;
815 spin_unlock_bh(&ifp
->lock
);
817 write_unlock(&idev
->lock
);
818 ift
= !max_addresses
||
819 ipv6_count_addresses(idev
) < max_addresses
?
820 ipv6_add_addr(idev
, &addr
, tmp_plen
,
821 ipv6_addr_type(&addr
)&IPV6_ADDR_SCOPE_MASK
, IFA_F_TEMPORARY
) : NULL
;
822 if (!ift
|| IS_ERR(ift
)) {
826 "ipv6_create_tempaddr(): retry temporary address regeneration.\n");
828 write_lock(&idev
->lock
);
832 spin_lock_bh(&ift
->lock
);
834 ift
->valid_lft
= tmp_valid_lft
;
835 ift
->prefered_lft
= tmp_prefered_lft
;
836 ift
->cstamp
= tmp_cstamp
;
837 ift
->tstamp
= tmp_tstamp
;
838 spin_unlock_bh(&ift
->lock
);
840 addrconf_dad_start(ift
, 0);
849 * Choose an appropriate source address (RFC3484)
851 struct ipv6_saddr_score
{
859 #define IPV6_SADDR_SCORE_LOCAL 0x0001
860 #define IPV6_SADDR_SCORE_PREFERRED 0x0004
861 #define IPV6_SADDR_SCORE_HOA 0x0008
862 #define IPV6_SADDR_SCORE_OIF 0x0010
863 #define IPV6_SADDR_SCORE_LABEL 0x0020
864 #define IPV6_SADDR_SCORE_PRIVACY 0x0040
866 static int inline ipv6_saddr_preferred(int type
)
868 if (type
& (IPV6_ADDR_MAPPED
|IPV6_ADDR_COMPATv4
|
869 IPV6_ADDR_LOOPBACK
|IPV6_ADDR_RESERVED
))
874 /* static matching label */
875 static int inline ipv6_saddr_label(const struct in6_addr
*addr
, int type
)
878 * prefix (longest match) label
879 * -----------------------------
888 if (type
& IPV6_ADDR_LOOPBACK
)
890 else if (type
& IPV6_ADDR_COMPATv4
)
892 else if (type
& IPV6_ADDR_MAPPED
)
894 else if (addr
->s6_addr32
[0] == htonl(0x20010000))
896 else if (addr
->s6_addr16
[0] == htons(0x2002))
898 else if ((addr
->s6_addr
[0] & 0xfe) == 0xfc)
903 int ipv6_dev_get_saddr(struct net_device
*daddr_dev
,
904 struct in6_addr
*daddr
, struct in6_addr
*saddr
)
906 struct ipv6_saddr_score hiscore
;
907 struct inet6_ifaddr
*ifa_result
= NULL
;
908 int daddr_type
= __ipv6_addr_type(daddr
);
909 int daddr_scope
= __ipv6_addr_src_scope(daddr_type
);
910 u32 daddr_label
= ipv6_saddr_label(daddr
, daddr_type
);
911 struct net_device
*dev
;
913 memset(&hiscore
, 0, sizeof(hiscore
));
915 read_lock(&dev_base_lock
);
916 read_lock(&addrconf_lock
);
918 for (dev
= dev_base
; dev
; dev
=dev
->next
) {
919 struct inet6_dev
*idev
;
920 struct inet6_ifaddr
*ifa
;
922 /* Rule 0: Candidate Source Address (section 4)
923 * - multicast and link-local destination address,
924 * the set of candidate source address MUST only
925 * include addresses assigned to interfaces
926 * belonging to the same link as the outgoing
928 * (- For site-local destination addresses, the
929 * set of candidate source addresses MUST only
930 * include addresses assigned to interfaces
931 * belonging to the same site as the outgoing
934 if ((daddr_type
& IPV6_ADDR_MULTICAST
||
935 daddr_scope
<= IPV6_ADDR_SCOPE_LINKLOCAL
) &&
936 daddr_dev
&& dev
!= daddr_dev
)
939 idev
= __in6_dev_get(dev
);
943 read_lock_bh(&idev
->lock
);
944 for (ifa
= idev
->addr_list
; ifa
; ifa
= ifa
->if_next
) {
945 struct ipv6_saddr_score score
;
947 score
.addr_type
= __ipv6_addr_type(&ifa
->addr
);
950 * - Tentative Address (RFC2462 section 5.4)
951 * - A tentative address is not considered
952 * "assigned to an interface" in the traditional
954 * - Candidate Source Address (section 4)
955 * - In any case, anycast addresses, multicast
956 * addresses, and the unspecified address MUST
957 * NOT be included in a candidate set.
959 if (ifa
->flags
& IFA_F_TENTATIVE
)
961 if (unlikely(score
.addr_type
== IPV6_ADDR_ANY
||
962 score
.addr_type
& IPV6_ADDR_MULTICAST
)) {
963 LIMIT_NETDEBUG(KERN_DEBUG
964 "ADDRCONF: unspecified / multicast address"
965 "assigned as unicast address on %s",
975 if (ifa_result
== NULL
) {
976 /* record it if the first available entry */
980 /* Rule 1: Prefer same address */
981 if (hiscore
.rule
< 1) {
982 if (ipv6_addr_equal(&ifa_result
->addr
, daddr
))
983 hiscore
.attrs
|= IPV6_SADDR_SCORE_LOCAL
;
986 if (ipv6_addr_equal(&ifa
->addr
, daddr
)) {
987 score
.attrs
|= IPV6_SADDR_SCORE_LOCAL
;
988 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_LOCAL
)) {
993 if (hiscore
.attrs
& IPV6_SADDR_SCORE_LOCAL
)
997 /* Rule 2: Prefer appropriate scope */
998 if (hiscore
.rule
< 2) {
999 hiscore
.scope
= __ipv6_addr_src_scope(hiscore
.addr_type
);
1002 score
.scope
= __ipv6_addr_src_scope(score
.addr_type
);
1003 if (hiscore
.scope
< score
.scope
) {
1004 if (hiscore
.scope
< daddr_scope
) {
1009 } else if (score
.scope
< hiscore
.scope
) {
1010 if (score
.scope
< daddr_scope
)
1011 break; /* addresses sorted by scope */
1018 /* Rule 3: Avoid deprecated address */
1019 if (hiscore
.rule
< 3) {
1020 if (ipv6_saddr_preferred(hiscore
.addr_type
) ||
1021 !(ifa_result
->flags
& IFA_F_DEPRECATED
))
1022 hiscore
.attrs
|= IPV6_SADDR_SCORE_PREFERRED
;
1025 if (ipv6_saddr_preferred(score
.addr_type
) ||
1026 !(ifa
->flags
& IFA_F_DEPRECATED
)) {
1027 score
.attrs
|= IPV6_SADDR_SCORE_PREFERRED
;
1028 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_PREFERRED
)) {
1033 if (hiscore
.attrs
& IPV6_SADDR_SCORE_PREFERRED
)
1037 /* Rule 4: Prefer home address -- not implemented yet */
1038 if (hiscore
.rule
< 4)
1041 /* Rule 5: Prefer outgoing interface */
1042 if (hiscore
.rule
< 5) {
1043 if (daddr_dev
== NULL
||
1044 daddr_dev
== ifa_result
->idev
->dev
)
1045 hiscore
.attrs
|= IPV6_SADDR_SCORE_OIF
;
1048 if (daddr_dev
== NULL
||
1049 daddr_dev
== ifa
->idev
->dev
) {
1050 score
.attrs
|= IPV6_SADDR_SCORE_OIF
;
1051 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_OIF
)) {
1056 if (hiscore
.attrs
& IPV6_SADDR_SCORE_OIF
)
1060 /* Rule 6: Prefer matching label */
1061 if (hiscore
.rule
< 6) {
1062 if (ipv6_saddr_label(&ifa_result
->addr
, hiscore
.addr_type
) == daddr_label
)
1063 hiscore
.attrs
|= IPV6_SADDR_SCORE_LABEL
;
1066 if (ipv6_saddr_label(&ifa
->addr
, score
.addr_type
) == daddr_label
) {
1067 score
.attrs
|= IPV6_SADDR_SCORE_LABEL
;
1068 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_LABEL
)) {
1073 if (hiscore
.attrs
& IPV6_SADDR_SCORE_LABEL
)
1077 #ifdef CONFIG_IPV6_PRIVACY
1078 /* Rule 7: Prefer public address
1079 * Note: prefer temprary address if use_tempaddr >= 2
1081 if (hiscore
.rule
< 7) {
1082 if ((!(ifa_result
->flags
& IFA_F_TEMPORARY
)) ^
1083 (ifa_result
->idev
->cnf
.use_tempaddr
>= 2))
1084 hiscore
.attrs
|= IPV6_SADDR_SCORE_PRIVACY
;
1087 if ((!(ifa
->flags
& IFA_F_TEMPORARY
)) ^
1088 (ifa
->idev
->cnf
.use_tempaddr
>= 2)) {
1089 score
.attrs
|= IPV6_SADDR_SCORE_PRIVACY
;
1090 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_PRIVACY
)) {
1095 if (hiscore
.attrs
& IPV6_SADDR_SCORE_PRIVACY
)
1099 if (hiscore
.rule
< 7)
1102 /* Rule 8: Use longest matching prefix */
1103 if (hiscore
.rule
< 8) {
1104 hiscore
.matchlen
= ipv6_addr_diff(&ifa_result
->addr
, daddr
);
1107 score
.matchlen
= ipv6_addr_diff(&ifa
->addr
, daddr
);
1108 if (score
.matchlen
> hiscore
.matchlen
) {
1113 else if (score
.matchlen
< hiscore
.matchlen
)
1117 /* Final Rule: choose first available one */
1121 in6_ifa_put(ifa_result
);
1126 read_unlock_bh(&idev
->lock
);
1128 read_unlock(&addrconf_lock
);
1129 read_unlock(&dev_base_lock
);
1132 return -EADDRNOTAVAIL
;
1134 ipv6_addr_copy(saddr
, &ifa_result
->addr
);
1135 in6_ifa_put(ifa_result
);
1140 int ipv6_get_saddr(struct dst_entry
*dst
,
1141 struct in6_addr
*daddr
, struct in6_addr
*saddr
)
1143 return ipv6_dev_get_saddr(dst
? ((struct rt6_info
*)dst
)->rt6i_idev
->dev
: NULL
, daddr
, saddr
);
1147 int ipv6_get_lladdr(struct net_device
*dev
, struct in6_addr
*addr
)
1149 struct inet6_dev
*idev
;
1150 int err
= -EADDRNOTAVAIL
;
1152 read_lock(&addrconf_lock
);
1153 if ((idev
= __in6_dev_get(dev
)) != NULL
) {
1154 struct inet6_ifaddr
*ifp
;
1156 read_lock_bh(&idev
->lock
);
1157 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1158 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1159 ipv6_addr_copy(addr
, &ifp
->addr
);
1164 read_unlock_bh(&idev
->lock
);
1166 read_unlock(&addrconf_lock
);
1170 static int ipv6_count_addresses(struct inet6_dev
*idev
)
1173 struct inet6_ifaddr
*ifp
;
1175 read_lock_bh(&idev
->lock
);
1176 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
)
1178 read_unlock_bh(&idev
->lock
);
1182 int ipv6_chk_addr(struct in6_addr
*addr
, struct net_device
*dev
, int strict
)
1184 struct inet6_ifaddr
* ifp
;
1185 u8 hash
= ipv6_addr_hash(addr
);
1187 read_lock_bh(&addrconf_hash_lock
);
1188 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1189 if (ipv6_addr_equal(&ifp
->addr
, addr
) &&
1190 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1191 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1192 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
))
1196 read_unlock_bh(&addrconf_hash_lock
);
1201 int ipv6_chk_same_addr(const struct in6_addr
*addr
, struct net_device
*dev
)
1203 struct inet6_ifaddr
* ifp
;
1204 u8 hash
= ipv6_addr_hash(addr
);
1206 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1207 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1208 if (dev
== NULL
|| ifp
->idev
->dev
== dev
)
1215 struct inet6_ifaddr
* ipv6_get_ifaddr(struct in6_addr
*addr
, struct net_device
*dev
, int strict
)
1217 struct inet6_ifaddr
* ifp
;
1218 u8 hash
= ipv6_addr_hash(addr
);
1220 read_lock_bh(&addrconf_hash_lock
);
1221 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1222 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1223 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1224 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
)) {
1230 read_unlock_bh(&addrconf_hash_lock
);
1235 int ipv6_rcv_saddr_equal(const struct sock
*sk
, const struct sock
*sk2
)
1237 const struct in6_addr
*sk_rcv_saddr6
= &inet6_sk(sk
)->rcv_saddr
;
1238 const struct in6_addr
*sk2_rcv_saddr6
= inet6_rcv_saddr(sk2
);
1239 u32 sk_rcv_saddr
= inet_sk(sk
)->rcv_saddr
;
1240 u32 sk2_rcv_saddr
= inet_rcv_saddr(sk2
);
1241 int sk_ipv6only
= ipv6_only_sock(sk
);
1242 int sk2_ipv6only
= inet_v6_ipv6only(sk2
);
1243 int addr_type
= ipv6_addr_type(sk_rcv_saddr6
);
1244 int addr_type2
= sk2_rcv_saddr6
? ipv6_addr_type(sk2_rcv_saddr6
) : IPV6_ADDR_MAPPED
;
1246 if (!sk2_rcv_saddr
&& !sk_ipv6only
)
1249 if (addr_type2
== IPV6_ADDR_ANY
&&
1250 !(sk2_ipv6only
&& addr_type
== IPV6_ADDR_MAPPED
))
1253 if (addr_type
== IPV6_ADDR_ANY
&&
1254 !(sk_ipv6only
&& addr_type2
== IPV6_ADDR_MAPPED
))
1257 if (sk2_rcv_saddr6
&&
1258 ipv6_addr_equal(sk_rcv_saddr6
, sk2_rcv_saddr6
))
1261 if (addr_type
== IPV6_ADDR_MAPPED
&&
1263 (!sk2_rcv_saddr
|| !sk_rcv_saddr
|| sk_rcv_saddr
== sk2_rcv_saddr
))
1269 /* Gets referenced address, destroys ifaddr */
1271 static void addrconf_dad_stop(struct inet6_ifaddr
*ifp
)
1273 if (ifp
->flags
&IFA_F_PERMANENT
) {
1274 spin_lock_bh(&ifp
->lock
);
1275 addrconf_del_timer(ifp
);
1276 ifp
->flags
|= IFA_F_TENTATIVE
;
1277 spin_unlock_bh(&ifp
->lock
);
1279 #ifdef CONFIG_IPV6_PRIVACY
1280 } else if (ifp
->flags
&IFA_F_TEMPORARY
) {
1281 struct inet6_ifaddr
*ifpub
;
1282 spin_lock_bh(&ifp
->lock
);
1285 in6_ifa_hold(ifpub
);
1286 spin_unlock_bh(&ifp
->lock
);
1287 ipv6_create_tempaddr(ifpub
, ifp
);
1290 spin_unlock_bh(&ifp
->lock
);
1298 void addrconf_dad_failure(struct inet6_ifaddr
*ifp
)
1300 if (net_ratelimit())
1301 printk(KERN_INFO
"%s: duplicate address detected!\n", ifp
->idev
->dev
->name
);
1302 addrconf_dad_stop(ifp
);
1305 /* Join to solicited addr multicast group. */
1307 void addrconf_join_solict(struct net_device
*dev
, struct in6_addr
*addr
)
1309 struct in6_addr maddr
;
1311 if (dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1314 addrconf_addr_solict_mult(addr
, &maddr
);
1315 ipv6_dev_mc_inc(dev
, &maddr
);
1318 void addrconf_leave_solict(struct inet6_dev
*idev
, struct in6_addr
*addr
)
1320 struct in6_addr maddr
;
1322 if (idev
->dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1325 addrconf_addr_solict_mult(addr
, &maddr
);
1326 __ipv6_dev_mc_dec(idev
, &maddr
);
1329 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
)
1331 struct in6_addr addr
;
1332 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1333 if (ipv6_addr_any(&addr
))
1335 ipv6_dev_ac_inc(ifp
->idev
->dev
, &addr
);
1338 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
)
1340 struct in6_addr addr
;
1341 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1342 if (ipv6_addr_any(&addr
))
1344 __ipv6_dev_ac_dec(ifp
->idev
, &addr
);
1347 static int addrconf_ifid_eui48(u8
*eui
, struct net_device
*dev
)
1349 if (dev
->addr_len
!= ETH_ALEN
)
1351 memcpy(eui
, dev
->dev_addr
, 3);
1352 memcpy(eui
+ 5, dev
->dev_addr
+ 3, 3);
1355 * The zSeries OSA network cards can be shared among various
1356 * OS instances, but the OSA cards have only one MAC address.
1357 * This leads to duplicate address conflicts in conjunction
1358 * with IPv6 if more than one instance uses the same card.
1360 * The driver for these cards can deliver a unique 16-bit
1361 * identifier for each instance sharing the same card. It is
1362 * placed instead of 0xFFFE in the interface identifier. The
1363 * "u" bit of the interface identifier is not inverted in this
1364 * case. Hence the resulting interface identifier has local
1365 * scope according to RFC2373.
1368 eui
[3] = (dev
->dev_id
>> 8) & 0xFF;
1369 eui
[4] = dev
->dev_id
& 0xFF;
1378 static int addrconf_ifid_arcnet(u8
*eui
, struct net_device
*dev
)
1380 /* XXX: inherit EUI-64 from other interface -- yoshfuji */
1381 if (dev
->addr_len
!= ARCNET_ALEN
)
1384 eui
[7] = *(u8
*)dev
->dev_addr
;
1388 static int addrconf_ifid_infiniband(u8
*eui
, struct net_device
*dev
)
1390 if (dev
->addr_len
!= INFINIBAND_ALEN
)
1392 memcpy(eui
, dev
->dev_addr
+ 12, 8);
1397 static int ipv6_generate_eui64(u8
*eui
, struct net_device
*dev
)
1399 switch (dev
->type
) {
1402 case ARPHRD_IEEE802_TR
:
1403 return addrconf_ifid_eui48(eui
, dev
);
1405 return addrconf_ifid_arcnet(eui
, dev
);
1406 case ARPHRD_INFINIBAND
:
1407 return addrconf_ifid_infiniband(eui
, dev
);
1412 static int ipv6_inherit_eui64(u8
*eui
, struct inet6_dev
*idev
)
1415 struct inet6_ifaddr
*ifp
;
1417 read_lock_bh(&idev
->lock
);
1418 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1419 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1420 memcpy(eui
, ifp
->addr
.s6_addr
+8, 8);
1425 read_unlock_bh(&idev
->lock
);
1429 #ifdef CONFIG_IPV6_PRIVACY
1430 /* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */
1431 static int __ipv6_regen_rndid(struct inet6_dev
*idev
)
1434 get_random_bytes(idev
->rndid
, sizeof(idev
->rndid
));
1435 idev
->rndid
[0] &= ~0x02;
1438 * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>:
1439 * check if generated address is not inappropriate
1441 * - Reserved subnet anycast (RFC 2526)
1442 * 11111101 11....11 1xxxxxxx
1443 * - ISATAP (draft-ietf-ngtrans-isatap-13.txt) 5.1
1444 * 00-00-5E-FE-xx-xx-xx-xx
1446 * - XXX: already assigned to an address on the device
1448 if (idev
->rndid
[0] == 0xfd &&
1449 (idev
->rndid
[1]&idev
->rndid
[2]&idev
->rndid
[3]&idev
->rndid
[4]&idev
->rndid
[5]&idev
->rndid
[6]) == 0xff &&
1450 (idev
->rndid
[7]&0x80))
1452 if ((idev
->rndid
[0]|idev
->rndid
[1]) == 0) {
1453 if (idev
->rndid
[2] == 0x5e && idev
->rndid
[3] == 0xfe)
1455 if ((idev
->rndid
[2]|idev
->rndid
[3]|idev
->rndid
[4]|idev
->rndid
[5]|idev
->rndid
[6]|idev
->rndid
[7]) == 0x00)
1462 static void ipv6_regen_rndid(unsigned long data
)
1464 struct inet6_dev
*idev
= (struct inet6_dev
*) data
;
1465 unsigned long expires
;
1467 read_lock_bh(&addrconf_lock
);
1468 write_lock_bh(&idev
->lock
);
1473 if (__ipv6_regen_rndid(idev
) < 0)
1477 idev
->cnf
.temp_prefered_lft
* HZ
-
1478 idev
->cnf
.regen_max_retry
* idev
->cnf
.dad_transmits
* idev
->nd_parms
->retrans_time
- desync_factor
;
1479 if (time_before(expires
, jiffies
)) {
1481 "ipv6_regen_rndid(): too short regeneration interval; timer disabled for %s.\n",
1486 if (!mod_timer(&idev
->regen_timer
, expires
))
1490 write_unlock_bh(&idev
->lock
);
1491 read_unlock_bh(&addrconf_lock
);
1495 static int __ipv6_try_regen_rndid(struct inet6_dev
*idev
, struct in6_addr
*tmpaddr
) {
1498 if (tmpaddr
&& memcmp(idev
->rndid
, &tmpaddr
->s6_addr
[8], 8) == 0)
1499 ret
= __ipv6_regen_rndid(idev
);
1509 addrconf_prefix_route(struct in6_addr
*pfx
, int plen
, struct net_device
*dev
,
1510 unsigned long expires
, u32 flags
)
1512 struct in6_rtmsg rtmsg
;
1514 memset(&rtmsg
, 0, sizeof(rtmsg
));
1515 ipv6_addr_copy(&rtmsg
.rtmsg_dst
, pfx
);
1516 rtmsg
.rtmsg_dst_len
= plen
;
1517 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1518 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1519 rtmsg
.rtmsg_info
= expires
;
1520 rtmsg
.rtmsg_flags
= RTF_UP
|flags
;
1521 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1523 /* Prevent useless cloning on PtP SIT.
1524 This thing is done here expecting that the whole
1525 class of non-broadcast devices need not cloning.
1527 if (dev
->type
== ARPHRD_SIT
&& (dev
->flags
&IFF_POINTOPOINT
))
1528 rtmsg
.rtmsg_flags
|= RTF_NONEXTHOP
;
1530 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
, RT6_TABLE_PREFIX
);
1533 /* Create "default" multicast route to the interface */
1535 static void addrconf_add_mroute(struct net_device
*dev
)
1537 struct in6_rtmsg rtmsg
;
1539 memset(&rtmsg
, 0, sizeof(rtmsg
));
1540 ipv6_addr_set(&rtmsg
.rtmsg_dst
,
1541 htonl(0xFF000000), 0, 0, 0);
1542 rtmsg
.rtmsg_dst_len
= 8;
1543 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1544 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1545 rtmsg
.rtmsg_flags
= RTF_UP
;
1546 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1547 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
, RT6_TABLE_LOCAL
);
1550 static void sit_route_add(struct net_device
*dev
)
1552 struct in6_rtmsg rtmsg
;
1554 memset(&rtmsg
, 0, sizeof(rtmsg
));
1556 rtmsg
.rtmsg_type
= RTMSG_NEWROUTE
;
1557 rtmsg
.rtmsg_metric
= IP6_RT_PRIO_ADDRCONF
;
1559 /* prefix length - 96 bits "::d.d.d.d" */
1560 rtmsg
.rtmsg_dst_len
= 96;
1561 rtmsg
.rtmsg_flags
= RTF_UP
|RTF_NONEXTHOP
;
1562 rtmsg
.rtmsg_ifindex
= dev
->ifindex
;
1564 ip6_route_add(&rtmsg
, NULL
, NULL
, NULL
, RT6_TABLE_MAIN
);
1567 static void addrconf_add_lroute(struct net_device
*dev
)
1569 struct in6_addr addr
;
1571 ipv6_addr_set(&addr
, htonl(0xFE800000), 0, 0, 0);
1572 addrconf_prefix_route(&addr
, 64, dev
, 0, 0);
1575 static struct inet6_dev
*addrconf_add_dev(struct net_device
*dev
)
1577 struct inet6_dev
*idev
;
1581 if ((idev
= ipv6_find_idev(dev
)) == NULL
)
1584 /* Add default multicast route */
1585 addrconf_add_mroute(dev
);
1587 /* Add link local route */
1588 addrconf_add_lroute(dev
);
1592 void addrconf_prefix_rcv(struct net_device
*dev
, u8
*opt
, int len
)
1594 struct prefix_info
*pinfo
;
1598 unsigned long rt_expires
;
1599 struct inet6_dev
*in6_dev
;
1601 pinfo
= (struct prefix_info
*) opt
;
1603 if (len
< sizeof(struct prefix_info
)) {
1604 ADBG(("addrconf: prefix option too short\n"));
1609 * Validation checks ([ADDRCONF], page 19)
1612 addr_type
= ipv6_addr_type(&pinfo
->prefix
);
1614 if (addr_type
& (IPV6_ADDR_MULTICAST
|IPV6_ADDR_LINKLOCAL
))
1617 valid_lft
= ntohl(pinfo
->valid
);
1618 prefered_lft
= ntohl(pinfo
->prefered
);
1620 if (prefered_lft
> valid_lft
) {
1621 if (net_ratelimit())
1622 printk(KERN_WARNING
"addrconf: prefix option has invalid lifetime\n");
1626 in6_dev
= in6_dev_get(dev
);
1628 if (in6_dev
== NULL
) {
1629 if (net_ratelimit())
1630 printk(KERN_DEBUG
"addrconf: device %s not configured\n", dev
->name
);
1635 * Two things going on here:
1636 * 1) Add routes for on-link prefixes
1637 * 2) Configure prefixes with the auto flag set
1640 /* Avoid arithmetic overflow. Really, we could
1641 save rt_expires in seconds, likely valid_lft,
1642 but it would require division in fib gc, that it
1645 if (valid_lft
>= 0x7FFFFFFF/HZ
)
1646 rt_expires
= 0x7FFFFFFF - (0x7FFFFFFF % HZ
);
1648 rt_expires
= valid_lft
* HZ
;
1651 * We convert this (in jiffies) to clock_t later.
1652 * Avoid arithmetic overflow there as well.
1653 * Overflow can happen only if HZ < USER_HZ.
1655 if (HZ
< USER_HZ
&& rt_expires
> 0x7FFFFFFF / USER_HZ
)
1656 rt_expires
= 0x7FFFFFFF / USER_HZ
;
1658 if (pinfo
->onlink
) {
1659 struct rt6_info
*rt
;
1660 rt
= rt6_lookup(&pinfo
->prefix
, NULL
, dev
->ifindex
, 1);
1662 if (rt
&& ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0)) {
1663 if (rt
->rt6i_flags
&RTF_EXPIRES
) {
1664 if (valid_lft
== 0) {
1665 ip6_del_rt(rt
, NULL
, NULL
, NULL
);
1668 rt
->rt6i_expires
= jiffies
+ rt_expires
;
1671 } else if (valid_lft
) {
1672 addrconf_prefix_route(&pinfo
->prefix
, pinfo
->prefix_len
,
1673 dev
, jiffies_to_clock_t(rt_expires
), RTF_ADDRCONF
|RTF_EXPIRES
|RTF_PREFIX_RT
);
1676 dst_release(&rt
->u
.dst
);
1679 /* Try to figure out our local address for this prefix */
1681 if (pinfo
->autoconf
&& in6_dev
->cnf
.autoconf
) {
1682 struct inet6_ifaddr
* ifp
;
1683 struct in6_addr addr
;
1684 int create
= 0, update_lft
= 0;
1686 if (pinfo
->prefix_len
== 64) {
1687 memcpy(&addr
, &pinfo
->prefix
, 8);
1688 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) &&
1689 ipv6_inherit_eui64(addr
.s6_addr
+ 8, in6_dev
)) {
1690 in6_dev_put(in6_dev
);
1695 if (net_ratelimit())
1696 printk(KERN_DEBUG
"IPv6 addrconf: prefix with wrong length %d\n",
1698 in6_dev_put(in6_dev
);
1703 ifp
= ipv6_get_ifaddr(&addr
, dev
, 1);
1705 if (ifp
== NULL
&& valid_lft
) {
1706 int max_addresses
= in6_dev
->cnf
.max_addresses
;
1708 /* Do not allow to create too much of autoconfigured
1709 * addresses; this would be too easy way to crash kernel.
1711 if (!max_addresses
||
1712 ipv6_count_addresses(in6_dev
) < max_addresses
)
1713 ifp
= ipv6_add_addr(in6_dev
, &addr
, pinfo
->prefix_len
,
1714 addr_type
&IPV6_ADDR_SCOPE_MASK
, 0);
1716 if (!ifp
|| IS_ERR(ifp
)) {
1717 in6_dev_put(in6_dev
);
1721 update_lft
= create
= 1;
1722 ifp
->cstamp
= jiffies
;
1723 addrconf_dad_start(ifp
, RTF_ADDRCONF
|RTF_PREFIX_RT
);
1729 #ifdef CONFIG_IPV6_PRIVACY
1730 struct inet6_ifaddr
*ift
;
1734 /* update lifetime (RFC2462 5.5.3 e) */
1735 spin_lock(&ifp
->lock
);
1737 if (ifp
->valid_lft
> (now
- ifp
->tstamp
) / HZ
)
1738 stored_lft
= ifp
->valid_lft
- (now
- ifp
->tstamp
) / HZ
;
1741 if (!update_lft
&& stored_lft
) {
1742 if (valid_lft
> MIN_VALID_LIFETIME
||
1743 valid_lft
> stored_lft
)
1745 else if (stored_lft
<= MIN_VALID_LIFETIME
) {
1746 /* valid_lft <= stored_lft is always true */
1750 valid_lft
= MIN_VALID_LIFETIME
;
1751 if (valid_lft
< prefered_lft
)
1752 prefered_lft
= valid_lft
;
1758 ifp
->valid_lft
= valid_lft
;
1759 ifp
->prefered_lft
= prefered_lft
;
1762 ifp
->flags
&= ~IFA_F_DEPRECATED
;
1763 spin_unlock(&ifp
->lock
);
1765 if (!(flags
&IFA_F_TENTATIVE
))
1766 ipv6_ifa_notify(0, ifp
);
1768 spin_unlock(&ifp
->lock
);
1770 #ifdef CONFIG_IPV6_PRIVACY
1771 read_lock_bh(&in6_dev
->lock
);
1772 /* update all temporary addresses in the list */
1773 for (ift
=in6_dev
->tempaddr_list
; ift
; ift
=ift
->tmp_next
) {
1775 * When adjusting the lifetimes of an existing
1776 * temporary address, only lower the lifetimes.
1777 * Implementations must not increase the
1778 * lifetimes of an existing temporary address
1779 * when processing a Prefix Information Option.
1781 spin_lock(&ift
->lock
);
1783 if (ift
->valid_lft
> valid_lft
&&
1784 ift
->valid_lft
- valid_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1785 ift
->valid_lft
= valid_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1786 if (ift
->prefered_lft
> prefered_lft
&&
1787 ift
->prefered_lft
- prefered_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1788 ift
->prefered_lft
= prefered_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1789 spin_unlock(&ift
->lock
);
1790 if (!(flags
&IFA_F_TENTATIVE
))
1791 ipv6_ifa_notify(0, ift
);
1794 if (create
&& in6_dev
->cnf
.use_tempaddr
> 0) {
1796 * When a new public address is created as described in [ADDRCONF],
1797 * also create a new temporary address.
1799 read_unlock_bh(&in6_dev
->lock
);
1800 ipv6_create_tempaddr(ifp
, NULL
);
1802 read_unlock_bh(&in6_dev
->lock
);
1809 inet6_prefix_notify(RTM_NEWPREFIX
, in6_dev
, pinfo
);
1810 in6_dev_put(in6_dev
);
1814 * Set destination address.
1815 * Special case for SIT interfaces where we create a new "virtual"
1818 int addrconf_set_dstaddr(void __user
*arg
)
1820 struct in6_ifreq ireq
;
1821 struct net_device
*dev
;
1827 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1830 dev
= __dev_get_by_index(ireq
.ifr6_ifindex
);
1836 if (dev
->type
== ARPHRD_SIT
) {
1839 struct ip_tunnel_parm p
;
1841 err
= -EADDRNOTAVAIL
;
1842 if (!(ipv6_addr_type(&ireq
.ifr6_addr
) & IPV6_ADDR_COMPATv4
))
1845 memset(&p
, 0, sizeof(p
));
1846 p
.iph
.daddr
= ireq
.ifr6_addr
.s6_addr32
[3];
1850 p
.iph
.protocol
= IPPROTO_IPV6
;
1852 ifr
.ifr_ifru
.ifru_data
= (void __user
*)&p
;
1854 oldfs
= get_fs(); set_fs(KERNEL_DS
);
1855 err
= dev
->do_ioctl(dev
, &ifr
, SIOCADDTUNNEL
);
1860 if ((dev
= __dev_get_by_name(p
.name
)) == NULL
)
1862 err
= dev_open(dev
);
1872 * Manual configuration of address on an interface
1874 static int inet6_addr_add(int ifindex
, struct in6_addr
*pfx
, int plen
,
1875 __u32 prefered_lft
, __u32 valid_lft
)
1877 struct inet6_ifaddr
*ifp
;
1878 struct inet6_dev
*idev
;
1879 struct net_device
*dev
;
1885 /* check the lifetime */
1886 if (!valid_lft
|| prefered_lft
> valid_lft
)
1889 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
1892 if (!(dev
->flags
&IFF_UP
))
1895 if ((idev
= addrconf_add_dev(dev
)) == NULL
)
1898 scope
= ipv6_addr_scope(pfx
);
1900 if (valid_lft
== INFINITY_LIFE_TIME
)
1901 ifa_flags
|= IFA_F_PERMANENT
;
1902 else if (valid_lft
>= 0x7FFFFFFF/HZ
)
1903 valid_lft
= 0x7FFFFFFF/HZ
;
1905 if (prefered_lft
== 0)
1906 ifa_flags
|= IFA_F_DEPRECATED
;
1907 else if ((prefered_lft
>= 0x7FFFFFFF/HZ
) &&
1908 (prefered_lft
!= INFINITY_LIFE_TIME
))
1909 prefered_lft
= 0x7FFFFFFF/HZ
;
1911 ifp
= ipv6_add_addr(idev
, pfx
, plen
, scope
, ifa_flags
);
1914 spin_lock_bh(&ifp
->lock
);
1915 ifp
->valid_lft
= valid_lft
;
1916 ifp
->prefered_lft
= prefered_lft
;
1917 ifp
->tstamp
= jiffies
;
1918 spin_unlock_bh(&ifp
->lock
);
1920 addrconf_dad_start(ifp
, 0);
1926 return PTR_ERR(ifp
);
1929 static int inet6_addr_del(int ifindex
, struct in6_addr
*pfx
, int plen
)
1931 struct inet6_ifaddr
*ifp
;
1932 struct inet6_dev
*idev
;
1933 struct net_device
*dev
;
1935 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
1938 if ((idev
= __in6_dev_get(dev
)) == NULL
)
1941 read_lock_bh(&idev
->lock
);
1942 for (ifp
= idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1943 if (ifp
->prefix_len
== plen
&&
1944 ipv6_addr_equal(pfx
, &ifp
->addr
)) {
1946 read_unlock_bh(&idev
->lock
);
1950 /* If the last address is deleted administratively,
1951 disable IPv6 on this interface.
1953 if (idev
->addr_list
== NULL
)
1954 addrconf_ifdown(idev
->dev
, 1);
1958 read_unlock_bh(&idev
->lock
);
1959 return -EADDRNOTAVAIL
;
1963 int addrconf_add_ifaddr(void __user
*arg
)
1965 struct in6_ifreq ireq
;
1968 if (!capable(CAP_NET_ADMIN
))
1971 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1975 err
= inet6_addr_add(ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
, ireq
.ifr6_prefixlen
,
1976 INFINITY_LIFE_TIME
, INFINITY_LIFE_TIME
);
1981 int addrconf_del_ifaddr(void __user
*arg
)
1983 struct in6_ifreq ireq
;
1986 if (!capable(CAP_NET_ADMIN
))
1989 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1993 err
= inet6_addr_del(ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
, ireq
.ifr6_prefixlen
);
1998 static void sit_add_v4_addrs(struct inet6_dev
*idev
)
2000 struct inet6_ifaddr
* ifp
;
2001 struct in6_addr addr
;
2002 struct net_device
*dev
;
2007 memset(&addr
, 0, sizeof(struct in6_addr
));
2008 memcpy(&addr
.s6_addr32
[3], idev
->dev
->dev_addr
, 4);
2010 if (idev
->dev
->flags
&IFF_POINTOPOINT
) {
2011 addr
.s6_addr32
[0] = htonl(0xfe800000);
2014 scope
= IPV6_ADDR_COMPATv4
;
2017 if (addr
.s6_addr32
[3]) {
2018 ifp
= ipv6_add_addr(idev
, &addr
, 128, scope
, IFA_F_PERMANENT
);
2020 spin_lock_bh(&ifp
->lock
);
2021 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2022 spin_unlock_bh(&ifp
->lock
);
2023 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2029 for (dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
) {
2030 struct in_device
* in_dev
= __in_dev_get_rtnl(dev
);
2031 if (in_dev
&& (dev
->flags
& IFF_UP
)) {
2032 struct in_ifaddr
* ifa
;
2036 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
2039 addr
.s6_addr32
[3] = ifa
->ifa_local
;
2041 if (ifa
->ifa_scope
== RT_SCOPE_LINK
)
2043 if (ifa
->ifa_scope
>= RT_SCOPE_HOST
) {
2044 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2048 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2053 ifp
= ipv6_add_addr(idev
, &addr
, plen
, flag
,
2056 spin_lock_bh(&ifp
->lock
);
2057 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2058 spin_unlock_bh(&ifp
->lock
);
2059 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2067 static void init_loopback(struct net_device
*dev
)
2069 struct inet6_dev
*idev
;
2070 struct inet6_ifaddr
* ifp
;
2076 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2077 printk(KERN_DEBUG
"init loopback: add_dev failed\n");
2081 ifp
= ipv6_add_addr(idev
, &in6addr_loopback
, 128, IFA_HOST
, IFA_F_PERMANENT
);
2083 spin_lock_bh(&ifp
->lock
);
2084 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2085 spin_unlock_bh(&ifp
->lock
);
2086 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2091 static void addrconf_add_linklocal(struct inet6_dev
*idev
, struct in6_addr
*addr
)
2093 struct inet6_ifaddr
* ifp
;
2095 ifp
= ipv6_add_addr(idev
, addr
, 64, IFA_LINK
, IFA_F_PERMANENT
);
2097 addrconf_dad_start(ifp
, 0);
2102 static void addrconf_dev_config(struct net_device
*dev
)
2104 struct in6_addr addr
;
2105 struct inet6_dev
* idev
;
2109 if ((dev
->type
!= ARPHRD_ETHER
) &&
2110 (dev
->type
!= ARPHRD_FDDI
) &&
2111 (dev
->type
!= ARPHRD_IEEE802_TR
) &&
2112 (dev
->type
!= ARPHRD_ARCNET
) &&
2113 (dev
->type
!= ARPHRD_INFINIBAND
)) {
2114 /* Alas, we support only Ethernet autoconfiguration. */
2118 idev
= addrconf_add_dev(dev
);
2122 memset(&addr
, 0, sizeof(struct in6_addr
));
2123 addr
.s6_addr32
[0] = htonl(0xFE800000);
2125 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) == 0)
2126 addrconf_add_linklocal(idev
, &addr
);
2129 static void addrconf_sit_config(struct net_device
*dev
)
2131 struct inet6_dev
*idev
;
2136 * Configure the tunnel with one of our IPv4
2137 * addresses... we should configure all of
2138 * our v4 addrs in the tunnel
2141 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2142 printk(KERN_DEBUG
"init sit: add_dev failed\n");
2146 sit_add_v4_addrs(idev
);
2148 if (dev
->flags
&IFF_POINTOPOINT
) {
2149 addrconf_add_mroute(dev
);
2150 addrconf_add_lroute(dev
);
2156 ipv6_inherit_linklocal(struct inet6_dev
*idev
, struct net_device
*link_dev
)
2158 struct in6_addr lladdr
;
2160 if (!ipv6_get_lladdr(link_dev
, &lladdr
)) {
2161 addrconf_add_linklocal(idev
, &lladdr
);
2167 static void ip6_tnl_add_linklocal(struct inet6_dev
*idev
)
2169 struct net_device
*link_dev
;
2171 /* first try to inherit the link-local address from the link device */
2172 if (idev
->dev
->iflink
&&
2173 (link_dev
= __dev_get_by_index(idev
->dev
->iflink
))) {
2174 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2177 /* then try to inherit it from any device */
2178 for (link_dev
= dev_base
; link_dev
; link_dev
= link_dev
->next
) {
2179 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2182 printk(KERN_DEBUG
"init ip6-ip6: add_linklocal failed\n");
2186 * Autoconfigure tunnel with a link-local address so routing protocols,
2187 * DHCPv6, MLD etc. can be run over the virtual link
2190 static void addrconf_ip6_tnl_config(struct net_device
*dev
)
2192 struct inet6_dev
*idev
;
2196 if ((idev
= addrconf_add_dev(dev
)) == NULL
) {
2197 printk(KERN_DEBUG
"init ip6-ip6: add_dev failed\n");
2200 ip6_tnl_add_linklocal(idev
);
2203 static int addrconf_notify(struct notifier_block
*this, unsigned long event
,
2206 struct net_device
*dev
= (struct net_device
*) data
;
2207 struct inet6_dev
*idev
= __in6_dev_get(dev
);
2208 int run_pending
= 0;
2213 if (event
== NETDEV_UP
) {
2214 if (!netif_carrier_ok(dev
)) {
2215 /* device is not ready yet. */
2217 "ADDRCONF(NETDEV_UP): %s: "
2218 "link is not ready\n",
2224 idev
->if_flags
|= IF_READY
;
2226 if (!netif_carrier_ok(dev
)) {
2227 /* device is still not ready. */
2232 if (idev
->if_flags
& IF_READY
) {
2233 /* device is already configured. */
2236 idev
->if_flags
|= IF_READY
;
2240 "ADDRCONF(NETDEV_CHANGE): %s: "
2241 "link becomes ready\n",
2249 addrconf_sit_config(dev
);
2251 case ARPHRD_TUNNEL6
:
2252 addrconf_ip6_tnl_config(dev
);
2254 case ARPHRD_LOOPBACK
:
2259 addrconf_dev_config(dev
);
2264 addrconf_dad_run(idev
);
2266 /* If the MTU changed during the interface down, when the
2267 interface up, the changed MTU must be reflected in the
2268 idev as well as routers.
2270 if (idev
->cnf
.mtu6
!= dev
->mtu
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2271 rt6_mtu_change(dev
, dev
->mtu
);
2272 idev
->cnf
.mtu6
= dev
->mtu
;
2274 idev
->tstamp
= jiffies
;
2275 inet6_ifinfo_notify(RTM_NEWLINK
, idev
);
2276 /* If the changed mtu during down is lower than IPV6_MIN_MTU
2277 stop IPv6 on this interface.
2279 if (dev
->mtu
< IPV6_MIN_MTU
)
2280 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2284 case NETDEV_CHANGEMTU
:
2285 if ( idev
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2286 rt6_mtu_change(dev
, dev
->mtu
);
2287 idev
->cnf
.mtu6
= dev
->mtu
;
2291 /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */
2294 case NETDEV_UNREGISTER
:
2296 * Remove all addresses from this interface.
2298 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2301 case NETDEV_CHANGENAME
:
2302 #ifdef CONFIG_SYSCTL
2304 addrconf_sysctl_unregister(&idev
->cnf
);
2305 neigh_sysctl_unregister(idev
->nd_parms
);
2306 neigh_sysctl_register(dev
, idev
->nd_parms
,
2307 NET_IPV6
, NET_IPV6_NEIGH
, "ipv6",
2308 &ndisc_ifinfo_sysctl_change
,
2310 addrconf_sysctl_register(idev
, &idev
->cnf
);
2320 * addrconf module should be notified of a device going up
2322 static struct notifier_block ipv6_dev_notf
= {
2323 .notifier_call
= addrconf_notify
,
2327 static int addrconf_ifdown(struct net_device
*dev
, int how
)
2329 struct inet6_dev
*idev
;
2330 struct inet6_ifaddr
*ifa
, **bifa
;
2335 if (dev
== &loopback_dev
&& how
== 1)
2339 neigh_ifdown(&nd_tbl
, dev
);
2341 idev
= __in6_dev_get(dev
);
2345 /* Step 1: remove reference to ipv6 device from parent device.
2349 write_lock_bh(&addrconf_lock
);
2350 dev
->ip6_ptr
= NULL
;
2352 write_unlock_bh(&addrconf_lock
);
2354 /* Step 1.5: remove snmp6 entry */
2355 snmp6_unregister_dev(idev
);
2359 /* Step 2: clear hash table */
2360 for (i
=0; i
<IN6_ADDR_HSIZE
; i
++) {
2361 bifa
= &inet6_addr_lst
[i
];
2363 write_lock_bh(&addrconf_hash_lock
);
2364 while ((ifa
= *bifa
) != NULL
) {
2365 if (ifa
->idev
== idev
) {
2366 *bifa
= ifa
->lst_next
;
2367 ifa
->lst_next
= NULL
;
2368 addrconf_del_timer(ifa
);
2372 bifa
= &ifa
->lst_next
;
2374 write_unlock_bh(&addrconf_hash_lock
);
2377 write_lock_bh(&idev
->lock
);
2379 /* Step 3: clear flags for stateless addrconf */
2381 idev
->if_flags
&= ~(IF_RS_SENT
|IF_RA_RCVD
|IF_READY
);
2383 /* Step 4: clear address list */
2384 #ifdef CONFIG_IPV6_PRIVACY
2385 if (how
== 1 && del_timer(&idev
->regen_timer
))
2388 /* clear tempaddr list */
2389 while ((ifa
= idev
->tempaddr_list
) != NULL
) {
2390 idev
->tempaddr_list
= ifa
->tmp_next
;
2391 ifa
->tmp_next
= NULL
;
2393 write_unlock_bh(&idev
->lock
);
2394 spin_lock_bh(&ifa
->lock
);
2397 in6_ifa_put(ifa
->ifpub
);
2400 spin_unlock_bh(&ifa
->lock
);
2402 write_lock_bh(&idev
->lock
);
2405 while ((ifa
= idev
->addr_list
) != NULL
) {
2406 idev
->addr_list
= ifa
->if_next
;
2407 ifa
->if_next
= NULL
;
2409 addrconf_del_timer(ifa
);
2410 write_unlock_bh(&idev
->lock
);
2412 __ipv6_ifa_notify(RTM_DELADDR
, ifa
);
2415 write_lock_bh(&idev
->lock
);
2417 write_unlock_bh(&idev
->lock
);
2419 /* Step 5: Discard multicast list */
2422 ipv6_mc_destroy_dev(idev
);
2426 /* Step 5: netlink notification of this interface */
2427 idev
->tstamp
= jiffies
;
2428 inet6_ifinfo_notify(RTM_DELLINK
, idev
);
2430 /* Shot the device (if unregistered) */
2433 #ifdef CONFIG_SYSCTL
2434 addrconf_sysctl_unregister(&idev
->cnf
);
2435 neigh_sysctl_unregister(idev
->nd_parms
);
2437 neigh_parms_release(&nd_tbl
, idev
->nd_parms
);
2438 neigh_ifdown(&nd_tbl
, dev
);
2444 static void addrconf_rs_timer(unsigned long data
)
2446 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2448 if (ifp
->idev
->cnf
.forwarding
)
2451 if (ifp
->idev
->if_flags
& IF_RA_RCVD
) {
2453 * Announcement received after solicitation
2459 spin_lock(&ifp
->lock
);
2460 if (ifp
->probes
++ < ifp
->idev
->cnf
.rtr_solicits
) {
2461 struct in6_addr all_routers
;
2463 /* The wait after the last probe can be shorter */
2464 addrconf_mod_timer(ifp
, AC_RS
,
2465 (ifp
->probes
== ifp
->idev
->cnf
.rtr_solicits
) ?
2466 ifp
->idev
->cnf
.rtr_solicit_delay
:
2467 ifp
->idev
->cnf
.rtr_solicit_interval
);
2468 spin_unlock(&ifp
->lock
);
2470 ipv6_addr_all_routers(&all_routers
);
2472 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &all_routers
);
2474 spin_unlock(&ifp
->lock
);
2476 * Note: we do not support deprecated "all on-link"
2477 * assumption any longer.
2479 printk(KERN_DEBUG
"%s: no IPv6 routers present\n",
2480 ifp
->idev
->dev
->name
);
2488 * Duplicate Address Detection
2490 static void addrconf_dad_kick(struct inet6_ifaddr
*ifp
)
2492 unsigned long rand_num
;
2493 struct inet6_dev
*idev
= ifp
->idev
;
2495 rand_num
= net_random() % (idev
->cnf
.rtr_solicit_delay
? : 1);
2496 ifp
->probes
= idev
->cnf
.dad_transmits
;
2497 addrconf_mod_timer(ifp
, AC_DAD
, rand_num
);
2500 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
)
2502 struct inet6_dev
*idev
= ifp
->idev
;
2503 struct net_device
*dev
= idev
->dev
;
2505 addrconf_join_solict(dev
, &ifp
->addr
);
2507 if (ifp
->prefix_len
!= 128 && (ifp
->flags
&IFA_F_PERMANENT
))
2508 addrconf_prefix_route(&ifp
->addr
, ifp
->prefix_len
, dev
, 0,
2511 net_srandom(ifp
->addr
.s6_addr32
[3]);
2513 read_lock_bh(&idev
->lock
);
2516 spin_lock_bh(&ifp
->lock
);
2518 if (dev
->flags
&(IFF_NOARP
|IFF_LOOPBACK
) ||
2519 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
2520 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2521 spin_unlock_bh(&ifp
->lock
);
2522 read_unlock_bh(&idev
->lock
);
2524 addrconf_dad_completed(ifp
);
2528 if (!(idev
->if_flags
& IF_READY
)) {
2529 spin_unlock_bh(&ifp
->lock
);
2530 read_unlock_bh(&idev
->lock
);
2532 * If the defice is not ready:
2533 * - keep it tentative if it is a permanent address.
2534 * - otherwise, kill it.
2537 addrconf_dad_stop(ifp
);
2540 addrconf_dad_kick(ifp
);
2541 spin_unlock_bh(&ifp
->lock
);
2543 read_unlock_bh(&idev
->lock
);
2546 static void addrconf_dad_timer(unsigned long data
)
2548 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2549 struct inet6_dev
*idev
= ifp
->idev
;
2550 struct in6_addr unspec
;
2551 struct in6_addr mcaddr
;
2553 read_lock_bh(&idev
->lock
);
2555 read_unlock_bh(&idev
->lock
);
2558 spin_lock_bh(&ifp
->lock
);
2559 if (ifp
->probes
== 0) {
2561 * DAD was successful
2564 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2565 spin_unlock_bh(&ifp
->lock
);
2566 read_unlock_bh(&idev
->lock
);
2568 addrconf_dad_completed(ifp
);
2574 addrconf_mod_timer(ifp
, AC_DAD
, ifp
->idev
->nd_parms
->retrans_time
);
2575 spin_unlock_bh(&ifp
->lock
);
2576 read_unlock_bh(&idev
->lock
);
2578 /* send a neighbour solicitation for our addr */
2579 memset(&unspec
, 0, sizeof(unspec
));
2580 addrconf_addr_solict_mult(&ifp
->addr
, &mcaddr
);
2581 ndisc_send_ns(ifp
->idev
->dev
, NULL
, &ifp
->addr
, &mcaddr
, &unspec
);
2586 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
)
2588 struct net_device
* dev
= ifp
->idev
->dev
;
2591 * Configure the address for reception. Now it is valid.
2594 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2596 /* If added prefix is link local and forwarding is off,
2597 start sending router solicitations.
2600 if (ifp
->idev
->cnf
.forwarding
== 0 &&
2601 ifp
->idev
->cnf
.rtr_solicits
> 0 &&
2602 (dev
->flags
&IFF_LOOPBACK
) == 0 &&
2603 (ipv6_addr_type(&ifp
->addr
) & IPV6_ADDR_LINKLOCAL
)) {
2604 struct in6_addr all_routers
;
2606 ipv6_addr_all_routers(&all_routers
);
2609 * If a host as already performed a random delay
2610 * [...] as part of DAD [...] there is no need
2611 * to delay again before sending the first RS
2613 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &all_routers
);
2615 spin_lock_bh(&ifp
->lock
);
2617 ifp
->idev
->if_flags
|= IF_RS_SENT
;
2618 addrconf_mod_timer(ifp
, AC_RS
, ifp
->idev
->cnf
.rtr_solicit_interval
);
2619 spin_unlock_bh(&ifp
->lock
);
2623 static void addrconf_dad_run(struct inet6_dev
*idev
) {
2624 struct inet6_ifaddr
*ifp
;
2626 read_lock_bh(&idev
->lock
);
2627 for (ifp
= idev
->addr_list
; ifp
; ifp
= ifp
->if_next
) {
2628 spin_lock_bh(&ifp
->lock
);
2629 if (!(ifp
->flags
& IFA_F_TENTATIVE
)) {
2630 spin_unlock_bh(&ifp
->lock
);
2633 spin_unlock_bh(&ifp
->lock
);
2634 addrconf_dad_kick(ifp
);
2636 read_unlock_bh(&idev
->lock
);
2639 #ifdef CONFIG_PROC_FS
2640 struct if6_iter_state
{
2644 static struct inet6_ifaddr
*if6_get_first(struct seq_file
*seq
)
2646 struct inet6_ifaddr
*ifa
= NULL
;
2647 struct if6_iter_state
*state
= seq
->private;
2649 for (state
->bucket
= 0; state
->bucket
< IN6_ADDR_HSIZE
; ++state
->bucket
) {
2650 ifa
= inet6_addr_lst
[state
->bucket
];
2657 static struct inet6_ifaddr
*if6_get_next(struct seq_file
*seq
, struct inet6_ifaddr
*ifa
)
2659 struct if6_iter_state
*state
= seq
->private;
2661 ifa
= ifa
->lst_next
;
2663 if (!ifa
&& ++state
->bucket
< IN6_ADDR_HSIZE
) {
2664 ifa
= inet6_addr_lst
[state
->bucket
];
2670 static struct inet6_ifaddr
*if6_get_idx(struct seq_file
*seq
, loff_t pos
)
2672 struct inet6_ifaddr
*ifa
= if6_get_first(seq
);
2675 while(pos
&& (ifa
= if6_get_next(seq
, ifa
)) != NULL
)
2677 return pos
? NULL
: ifa
;
2680 static void *if6_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2682 read_lock_bh(&addrconf_hash_lock
);
2683 return if6_get_idx(seq
, *pos
);
2686 static void *if6_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2688 struct inet6_ifaddr
*ifa
;
2690 ifa
= if6_get_next(seq
, v
);
2695 static void if6_seq_stop(struct seq_file
*seq
, void *v
)
2697 read_unlock_bh(&addrconf_hash_lock
);
2700 static int if6_seq_show(struct seq_file
*seq
, void *v
)
2702 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*)v
;
2704 NIP6_SEQFMT
" %02x %02x %02x %02x %8s\n",
2706 ifp
->idev
->dev
->ifindex
,
2710 ifp
->idev
->dev
->name
);
2714 static struct seq_operations if6_seq_ops
= {
2715 .start
= if6_seq_start
,
2716 .next
= if6_seq_next
,
2717 .show
= if6_seq_show
,
2718 .stop
= if6_seq_stop
,
2721 static int if6_seq_open(struct inode
*inode
, struct file
*file
)
2723 struct seq_file
*seq
;
2725 struct if6_iter_state
*s
= kzalloc(sizeof(*s
), GFP_KERNEL
);
2730 rc
= seq_open(file
, &if6_seq_ops
);
2734 seq
= file
->private_data
;
2743 static struct file_operations if6_fops
= {
2744 .owner
= THIS_MODULE
,
2745 .open
= if6_seq_open
,
2747 .llseek
= seq_lseek
,
2748 .release
= seq_release_private
,
2751 int __init
if6_proc_init(void)
2753 if (!proc_net_fops_create("if_inet6", S_IRUGO
, &if6_fops
))
2758 void if6_proc_exit(void)
2760 proc_net_remove("if_inet6");
2762 #endif /* CONFIG_PROC_FS */
2765 * Periodic address status verification
2768 static void addrconf_verify(unsigned long foo
)
2770 struct inet6_ifaddr
*ifp
;
2771 unsigned long now
, next
;
2774 spin_lock_bh(&addrconf_verify_lock
);
2776 next
= now
+ ADDR_CHECK_FREQUENCY
;
2778 del_timer(&addr_chk_timer
);
2780 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
2783 read_lock(&addrconf_hash_lock
);
2784 for (ifp
=inet6_addr_lst
[i
]; ifp
; ifp
=ifp
->lst_next
) {
2786 #ifdef CONFIG_IPV6_PRIVACY
2787 unsigned long regen_advance
;
2790 if (ifp
->flags
& IFA_F_PERMANENT
)
2793 spin_lock(&ifp
->lock
);
2794 age
= (now
- ifp
->tstamp
) / HZ
;
2796 #ifdef CONFIG_IPV6_PRIVACY
2797 regen_advance
= ifp
->idev
->cnf
.regen_max_retry
*
2798 ifp
->idev
->cnf
.dad_transmits
*
2799 ifp
->idev
->nd_parms
->retrans_time
/ HZ
;
2802 if (ifp
->valid_lft
!= INFINITY_LIFE_TIME
&&
2803 age
>= ifp
->valid_lft
) {
2804 spin_unlock(&ifp
->lock
);
2806 read_unlock(&addrconf_hash_lock
);
2809 } else if (ifp
->prefered_lft
== INFINITY_LIFE_TIME
) {
2810 spin_unlock(&ifp
->lock
);
2812 } else if (age
>= ifp
->prefered_lft
) {
2813 /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */
2816 if (!(ifp
->flags
&IFA_F_DEPRECATED
)) {
2818 ifp
->flags
|= IFA_F_DEPRECATED
;
2821 if (time_before(ifp
->tstamp
+ ifp
->valid_lft
* HZ
, next
))
2822 next
= ifp
->tstamp
+ ifp
->valid_lft
* HZ
;
2824 spin_unlock(&ifp
->lock
);
2828 read_unlock(&addrconf_hash_lock
);
2830 ipv6_ifa_notify(0, ifp
);
2834 #ifdef CONFIG_IPV6_PRIVACY
2835 } else if ((ifp
->flags
&IFA_F_TEMPORARY
) &&
2836 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
2837 if (age
>= ifp
->prefered_lft
- regen_advance
) {
2838 struct inet6_ifaddr
*ifpub
= ifp
->ifpub
;
2839 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
2840 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
2841 if (!ifp
->regen_count
&& ifpub
) {
2844 in6_ifa_hold(ifpub
);
2845 spin_unlock(&ifp
->lock
);
2846 read_unlock(&addrconf_hash_lock
);
2847 spin_lock(&ifpub
->lock
);
2848 ifpub
->regen_count
= 0;
2849 spin_unlock(&ifpub
->lock
);
2850 ipv6_create_tempaddr(ifpub
, ifp
);
2855 } else if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
, next
))
2856 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
;
2857 spin_unlock(&ifp
->lock
);
2860 /* ifp->prefered_lft <= ifp->valid_lft */
2861 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
2862 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
2863 spin_unlock(&ifp
->lock
);
2866 read_unlock(&addrconf_hash_lock
);
2869 addr_chk_timer
.expires
= time_before(next
, jiffies
+ HZ
) ? jiffies
+ HZ
: next
;
2870 add_timer(&addr_chk_timer
);
2871 spin_unlock_bh(&addrconf_verify_lock
);
2875 inet6_rtm_deladdr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
2877 struct rtattr
**rta
= arg
;
2878 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
2879 struct in6_addr
*pfx
;
2882 if (rta
[IFA_ADDRESS
-1]) {
2883 if (RTA_PAYLOAD(rta
[IFA_ADDRESS
-1]) < sizeof(*pfx
))
2885 pfx
= RTA_DATA(rta
[IFA_ADDRESS
-1]);
2887 if (rta
[IFA_LOCAL
-1]) {
2888 if (RTA_PAYLOAD(rta
[IFA_LOCAL
-1]) < sizeof(*pfx
) ||
2889 (pfx
&& memcmp(pfx
, RTA_DATA(rta
[IFA_LOCAL
-1]), sizeof(*pfx
))))
2891 pfx
= RTA_DATA(rta
[IFA_LOCAL
-1]);
2896 return inet6_addr_del(ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
);
2900 inet6_addr_modify(int ifindex
, struct in6_addr
*pfx
,
2901 __u32 prefered_lft
, __u32 valid_lft
)
2903 struct inet6_ifaddr
*ifp
= NULL
;
2904 struct net_device
*dev
;
2907 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
2910 if (!(dev
->flags
&IFF_UP
))
2913 if (!valid_lft
|| (prefered_lft
> valid_lft
))
2916 ifp
= ipv6_get_ifaddr(pfx
, dev
, 1);
2920 if (valid_lft
== INFINITY_LIFE_TIME
)
2921 ifa_flags
= IFA_F_PERMANENT
;
2922 else if (valid_lft
>= 0x7FFFFFFF/HZ
)
2923 valid_lft
= 0x7FFFFFFF/HZ
;
2925 if (prefered_lft
== 0)
2926 ifa_flags
= IFA_F_DEPRECATED
;
2927 else if ((prefered_lft
>= 0x7FFFFFFF/HZ
) &&
2928 (prefered_lft
!= INFINITY_LIFE_TIME
))
2929 prefered_lft
= 0x7FFFFFFF/HZ
;
2931 spin_lock_bh(&ifp
->lock
);
2932 ifp
->flags
= (ifp
->flags
& ~(IFA_F_DEPRECATED
|IFA_F_PERMANENT
)) | ifa_flags
;
2934 ifp
->tstamp
= jiffies
;
2935 ifp
->valid_lft
= valid_lft
;
2936 ifp
->prefered_lft
= prefered_lft
;
2938 spin_unlock_bh(&ifp
->lock
);
2939 if (!(ifp
->flags
&IFA_F_TENTATIVE
))
2940 ipv6_ifa_notify(0, ifp
);
2949 inet6_rtm_newaddr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
2951 struct rtattr
**rta
= arg
;
2952 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
2953 struct in6_addr
*pfx
;
2954 __u32 valid_lft
= INFINITY_LIFE_TIME
, prefered_lft
= INFINITY_LIFE_TIME
;
2957 if (rta
[IFA_ADDRESS
-1]) {
2958 if (RTA_PAYLOAD(rta
[IFA_ADDRESS
-1]) < sizeof(*pfx
))
2960 pfx
= RTA_DATA(rta
[IFA_ADDRESS
-1]);
2962 if (rta
[IFA_LOCAL
-1]) {
2963 if (RTA_PAYLOAD(rta
[IFA_LOCAL
-1]) < sizeof(*pfx
) ||
2964 (pfx
&& memcmp(pfx
, RTA_DATA(rta
[IFA_LOCAL
-1]), sizeof(*pfx
))))
2966 pfx
= RTA_DATA(rta
[IFA_LOCAL
-1]);
2971 if (rta
[IFA_CACHEINFO
-1]) {
2972 struct ifa_cacheinfo
*ci
;
2973 if (RTA_PAYLOAD(rta
[IFA_CACHEINFO
-1]) < sizeof(*ci
))
2975 ci
= RTA_DATA(rta
[IFA_CACHEINFO
-1]);
2976 valid_lft
= ci
->ifa_valid
;
2977 prefered_lft
= ci
->ifa_prefered
;
2980 if (nlh
->nlmsg_flags
& NLM_F_REPLACE
) {
2982 ret
= inet6_addr_modify(ifm
->ifa_index
, pfx
,
2983 prefered_lft
, valid_lft
);
2984 if (ret
== 0 || !(nlh
->nlmsg_flags
& NLM_F_CREATE
))
2988 return inet6_addr_add(ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
,
2989 prefered_lft
, valid_lft
);
2993 /* Maximum length of ifa_cacheinfo attributes */
2994 #define INET6_IFADDR_RTA_SPACE \
2995 RTA_SPACE(16) /* IFA_ADDRESS */ + \
2996 RTA_SPACE(sizeof(struct ifa_cacheinfo)) /* CACHEINFO */
2998 static int inet6_fill_ifaddr(struct sk_buff
*skb
, struct inet6_ifaddr
*ifa
,
2999 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3001 struct ifaddrmsg
*ifm
;
3002 struct nlmsghdr
*nlh
;
3003 struct ifa_cacheinfo ci
;
3004 unsigned char *b
= skb
->tail
;
3006 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
3007 ifm
= NLMSG_DATA(nlh
);
3008 ifm
->ifa_family
= AF_INET6
;
3009 ifm
->ifa_prefixlen
= ifa
->prefix_len
;
3010 ifm
->ifa_flags
= ifa
->flags
;
3011 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
3012 if (ifa
->scope
&IFA_HOST
)
3013 ifm
->ifa_scope
= RT_SCOPE_HOST
;
3014 else if (ifa
->scope
&IFA_LINK
)
3015 ifm
->ifa_scope
= RT_SCOPE_LINK
;
3016 else if (ifa
->scope
&IFA_SITE
)
3017 ifm
->ifa_scope
= RT_SCOPE_SITE
;
3018 ifm
->ifa_index
= ifa
->idev
->dev
->ifindex
;
3019 RTA_PUT(skb
, IFA_ADDRESS
, 16, &ifa
->addr
);
3020 if (!(ifa
->flags
&IFA_F_PERMANENT
)) {
3021 ci
.ifa_prefered
= ifa
->prefered_lft
;
3022 ci
.ifa_valid
= ifa
->valid_lft
;
3023 if (ci
.ifa_prefered
!= INFINITY_LIFE_TIME
) {
3024 long tval
= (jiffies
- ifa
->tstamp
)/HZ
;
3025 ci
.ifa_prefered
-= tval
;
3026 if (ci
.ifa_valid
!= INFINITY_LIFE_TIME
)
3027 ci
.ifa_valid
-= tval
;
3030 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
3031 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
3033 ci
.cstamp
= (__u32
)(TIME_DELTA(ifa
->cstamp
, INITIAL_JIFFIES
) / HZ
* 100
3034 + TIME_DELTA(ifa
->cstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3035 ci
.tstamp
= (__u32
)(TIME_DELTA(ifa
->tstamp
, INITIAL_JIFFIES
) / HZ
* 100
3036 + TIME_DELTA(ifa
->tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3037 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
3038 nlh
->nlmsg_len
= skb
->tail
- b
;
3043 skb_trim(skb
, b
- skb
->data
);
3047 static int inet6_fill_ifmcaddr(struct sk_buff
*skb
, struct ifmcaddr6
*ifmca
,
3048 u32 pid
, u32 seq
, int event
, u16 flags
)
3050 struct ifaddrmsg
*ifm
;
3051 struct nlmsghdr
*nlh
;
3052 struct ifa_cacheinfo ci
;
3053 unsigned char *b
= skb
->tail
;
3055 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
3056 ifm
= NLMSG_DATA(nlh
);
3057 ifm
->ifa_family
= AF_INET6
;
3058 ifm
->ifa_prefixlen
= 128;
3059 ifm
->ifa_flags
= IFA_F_PERMANENT
;
3060 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
3061 if (ipv6_addr_scope(&ifmca
->mca_addr
)&IFA_SITE
)
3062 ifm
->ifa_scope
= RT_SCOPE_SITE
;
3063 ifm
->ifa_index
= ifmca
->idev
->dev
->ifindex
;
3064 RTA_PUT(skb
, IFA_MULTICAST
, 16, &ifmca
->mca_addr
);
3065 ci
.cstamp
= (__u32
)(TIME_DELTA(ifmca
->mca_cstamp
, INITIAL_JIFFIES
) / HZ
3066 * 100 + TIME_DELTA(ifmca
->mca_cstamp
, INITIAL_JIFFIES
) % HZ
3068 ci
.tstamp
= (__u32
)(TIME_DELTA(ifmca
->mca_tstamp
, INITIAL_JIFFIES
) / HZ
3069 * 100 + TIME_DELTA(ifmca
->mca_tstamp
, INITIAL_JIFFIES
) % HZ
3071 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
3072 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
3073 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
3074 nlh
->nlmsg_len
= skb
->tail
- b
;
3079 skb_trim(skb
, b
- skb
->data
);
3083 static int inet6_fill_ifacaddr(struct sk_buff
*skb
, struct ifacaddr6
*ifaca
,
3084 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3086 struct ifaddrmsg
*ifm
;
3087 struct nlmsghdr
*nlh
;
3088 struct ifa_cacheinfo ci
;
3089 unsigned char *b
= skb
->tail
;
3091 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*ifm
), flags
);
3092 ifm
= NLMSG_DATA(nlh
);
3093 ifm
->ifa_family
= AF_INET6
;
3094 ifm
->ifa_prefixlen
= 128;
3095 ifm
->ifa_flags
= IFA_F_PERMANENT
;
3096 ifm
->ifa_scope
= RT_SCOPE_UNIVERSE
;
3097 if (ipv6_addr_scope(&ifaca
->aca_addr
)&IFA_SITE
)
3098 ifm
->ifa_scope
= RT_SCOPE_SITE
;
3099 ifm
->ifa_index
= ifaca
->aca_idev
->dev
->ifindex
;
3100 RTA_PUT(skb
, IFA_ANYCAST
, 16, &ifaca
->aca_addr
);
3101 ci
.cstamp
= (__u32
)(TIME_DELTA(ifaca
->aca_cstamp
, INITIAL_JIFFIES
) / HZ
3102 * 100 + TIME_DELTA(ifaca
->aca_cstamp
, INITIAL_JIFFIES
) % HZ
3104 ci
.tstamp
= (__u32
)(TIME_DELTA(ifaca
->aca_tstamp
, INITIAL_JIFFIES
) / HZ
3105 * 100 + TIME_DELTA(ifaca
->aca_tstamp
, INITIAL_JIFFIES
) % HZ
3107 ci
.ifa_prefered
= INFINITY_LIFE_TIME
;
3108 ci
.ifa_valid
= INFINITY_LIFE_TIME
;
3109 RTA_PUT(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
3110 nlh
->nlmsg_len
= skb
->tail
- b
;
3115 skb_trim(skb
, b
- skb
->data
);
3126 static int inet6_dump_addr(struct sk_buff
*skb
, struct netlink_callback
*cb
,
3127 enum addr_type_t type
)
3130 int s_idx
, s_ip_idx
;
3132 struct net_device
*dev
;
3133 struct inet6_dev
*idev
= NULL
;
3134 struct inet6_ifaddr
*ifa
;
3135 struct ifmcaddr6
*ifmca
;
3136 struct ifacaddr6
*ifaca
;
3138 s_idx
= cb
->args
[0];
3139 s_ip_idx
= ip_idx
= cb
->args
[1];
3140 read_lock(&dev_base_lock
);
3142 for (dev
= dev_base
, idx
= 0; dev
; dev
= dev
->next
, idx
++) {
3148 if ((idev
= in6_dev_get(dev
)) == NULL
)
3150 read_lock_bh(&idev
->lock
);
3153 /* unicast address incl. temp addr */
3154 for (ifa
= idev
->addr_list
; ifa
;
3155 ifa
= ifa
->if_next
, ip_idx
++) {
3156 if (ip_idx
< s_ip_idx
)
3158 if ((err
= inet6_fill_ifaddr(skb
, ifa
,
3159 NETLINK_CB(cb
->skb
).pid
,
3160 cb
->nlh
->nlmsg_seq
, RTM_NEWADDR
,
3165 case MULTICAST_ADDR
:
3166 /* multicast address */
3167 for (ifmca
= idev
->mc_list
; ifmca
;
3168 ifmca
= ifmca
->next
, ip_idx
++) {
3169 if (ip_idx
< s_ip_idx
)
3171 if ((err
= inet6_fill_ifmcaddr(skb
, ifmca
,
3172 NETLINK_CB(cb
->skb
).pid
,
3173 cb
->nlh
->nlmsg_seq
, RTM_GETMULTICAST
,
3179 /* anycast address */
3180 for (ifaca
= idev
->ac_list
; ifaca
;
3181 ifaca
= ifaca
->aca_next
, ip_idx
++) {
3182 if (ip_idx
< s_ip_idx
)
3184 if ((err
= inet6_fill_ifacaddr(skb
, ifaca
,
3185 NETLINK_CB(cb
->skb
).pid
,
3186 cb
->nlh
->nlmsg_seq
, RTM_GETANYCAST
,
3194 read_unlock_bh(&idev
->lock
);
3199 read_unlock_bh(&idev
->lock
);
3202 read_unlock(&dev_base_lock
);
3204 cb
->args
[1] = ip_idx
;
3208 static int inet6_dump_ifaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3210 enum addr_type_t type
= UNICAST_ADDR
;
3211 return inet6_dump_addr(skb
, cb
, type
);
3214 static int inet6_dump_ifmcaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3216 enum addr_type_t type
= MULTICAST_ADDR
;
3217 return inet6_dump_addr(skb
, cb
, type
);
3221 static int inet6_dump_ifacaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3223 enum addr_type_t type
= ANYCAST_ADDR
;
3224 return inet6_dump_addr(skb
, cb
, type
);
3227 static int inet6_rtm_getaddr(struct sk_buff
*in_skb
,
3228 struct nlmsghdr
* nlh
, void *arg
)
3230 struct rtattr
**rta
= arg
;
3231 struct ifaddrmsg
*ifm
= NLMSG_DATA(nlh
);
3232 struct in6_addr
*addr
= NULL
;
3233 struct net_device
*dev
= NULL
;
3234 struct inet6_ifaddr
*ifa
;
3235 struct sk_buff
*skb
;
3236 int size
= NLMSG_SPACE(sizeof(struct ifaddrmsg
) + INET6_IFADDR_RTA_SPACE
);
3239 if (rta
[IFA_ADDRESS
-1]) {
3240 if (RTA_PAYLOAD(rta
[IFA_ADDRESS
-1]) < sizeof(*addr
))
3242 addr
= RTA_DATA(rta
[IFA_ADDRESS
-1]);
3244 if (rta
[IFA_LOCAL
-1]) {
3245 if (RTA_PAYLOAD(rta
[IFA_LOCAL
-1]) < sizeof(*addr
) ||
3246 (addr
&& memcmp(addr
, RTA_DATA(rta
[IFA_LOCAL
-1]), sizeof(*addr
))))
3248 addr
= RTA_DATA(rta
[IFA_LOCAL
-1]);
3254 dev
= __dev_get_by_index(ifm
->ifa_index
);
3256 if ((ifa
= ipv6_get_ifaddr(addr
, dev
, 1)) == NULL
)
3257 return -EADDRNOTAVAIL
;
3259 if ((skb
= alloc_skb(size
, GFP_KERNEL
)) == NULL
) {
3264 NETLINK_CB(skb
).dst_pid
= NETLINK_CB(in_skb
).pid
;
3265 err
= inet6_fill_ifaddr(skb
, ifa
, NETLINK_CB(in_skb
).pid
,
3266 nlh
->nlmsg_seq
, RTM_NEWADDR
, 0);
3272 err
= rtnl_unicast(skb
, NETLINK_CB(in_skb
).pid
);
3281 static void inet6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
)
3283 struct sk_buff
*skb
;
3284 int payload
= sizeof(struct ifaddrmsg
) + INET6_IFADDR_RTA_SPACE
;
3287 skb
= nlmsg_new(nlmsg_total_size(payload
), GFP_ATOMIC
);
3291 err
= inet6_fill_ifaddr(skb
, ifa
, 0, 0, event
, 0);
3297 err
= rtnl_notify(skb
, 0, RTNLGRP_IPV6_IFADDR
, NULL
, GFP_ATOMIC
);
3300 rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR
, err
);
3303 static void inline ipv6_store_devconf(struct ipv6_devconf
*cnf
,
3304 __s32
*array
, int bytes
)
3306 memset(array
, 0, bytes
);
3307 array
[DEVCONF_FORWARDING
] = cnf
->forwarding
;
3308 array
[DEVCONF_HOPLIMIT
] = cnf
->hop_limit
;
3309 array
[DEVCONF_MTU6
] = cnf
->mtu6
;
3310 array
[DEVCONF_ACCEPT_RA
] = cnf
->accept_ra
;
3311 array
[DEVCONF_ACCEPT_REDIRECTS
] = cnf
->accept_redirects
;
3312 array
[DEVCONF_AUTOCONF
] = cnf
->autoconf
;
3313 array
[DEVCONF_DAD_TRANSMITS
] = cnf
->dad_transmits
;
3314 array
[DEVCONF_RTR_SOLICITS
] = cnf
->rtr_solicits
;
3315 array
[DEVCONF_RTR_SOLICIT_INTERVAL
] = cnf
->rtr_solicit_interval
;
3316 array
[DEVCONF_RTR_SOLICIT_DELAY
] = cnf
->rtr_solicit_delay
;
3317 array
[DEVCONF_FORCE_MLD_VERSION
] = cnf
->force_mld_version
;
3318 #ifdef CONFIG_IPV6_PRIVACY
3319 array
[DEVCONF_USE_TEMPADDR
] = cnf
->use_tempaddr
;
3320 array
[DEVCONF_TEMP_VALID_LFT
] = cnf
->temp_valid_lft
;
3321 array
[DEVCONF_TEMP_PREFERED_LFT
] = cnf
->temp_prefered_lft
;
3322 array
[DEVCONF_REGEN_MAX_RETRY
] = cnf
->regen_max_retry
;
3323 array
[DEVCONF_MAX_DESYNC_FACTOR
] = cnf
->max_desync_factor
;
3325 array
[DEVCONF_MAX_ADDRESSES
] = cnf
->max_addresses
;
3326 array
[DEVCONF_ACCEPT_RA_DEFRTR
] = cnf
->accept_ra_defrtr
;
3327 array
[DEVCONF_ACCEPT_RA_PINFO
] = cnf
->accept_ra_pinfo
;
3328 #ifdef CONFIG_IPV6_ROUTER_PREF
3329 array
[DEVCONF_ACCEPT_RA_RTR_PREF
] = cnf
->accept_ra_rtr_pref
;
3330 array
[DEVCONF_RTR_PROBE_INTERVAL
] = cnf
->rtr_probe_interval
;
3331 #ifdef CONFIV_IPV6_ROUTE_INFO
3332 array
[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN
] = cnf
->accept_ra_rt_info_max_plen
;
3337 /* Maximum length of ifinfomsg attributes */
3338 #define INET6_IFINFO_RTA_SPACE \
3339 RTA_SPACE(IFNAMSIZ) /* IFNAME */ + \
3340 RTA_SPACE(MAX_ADDR_LEN) /* ADDRESS */ + \
3341 RTA_SPACE(sizeof(u32)) /* MTU */ + \
3342 RTA_SPACE(sizeof(int)) /* LINK */ + \
3343 RTA_SPACE(0) /* PROTINFO */ + \
3344 RTA_SPACE(sizeof(u32)) /* FLAGS */ + \
3345 RTA_SPACE(sizeof(struct ifla_cacheinfo)) /* CACHEINFO */ + \
3346 RTA_SPACE(sizeof(__s32[DEVCONF_MAX])) /* CONF */
3348 static int inet6_fill_ifinfo(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3349 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3351 struct net_device
*dev
= idev
->dev
;
3352 __s32
*array
= NULL
;
3353 struct ifinfomsg
*r
;
3354 struct nlmsghdr
*nlh
;
3355 unsigned char *b
= skb
->tail
;
3356 struct rtattr
*subattr
;
3357 __u32 mtu
= dev
->mtu
;
3358 struct ifla_cacheinfo ci
;
3360 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*r
), flags
);
3361 r
= NLMSG_DATA(nlh
);
3362 r
->ifi_family
= AF_INET6
;
3364 r
->ifi_type
= dev
->type
;
3365 r
->ifi_index
= dev
->ifindex
;
3366 r
->ifi_flags
= dev_get_flags(dev
);
3369 RTA_PUT(skb
, IFLA_IFNAME
, strlen(dev
->name
)+1, dev
->name
);
3372 RTA_PUT(skb
, IFLA_ADDRESS
, dev
->addr_len
, dev
->dev_addr
);
3374 RTA_PUT(skb
, IFLA_MTU
, sizeof(mtu
), &mtu
);
3375 if (dev
->ifindex
!= dev
->iflink
)
3376 RTA_PUT(skb
, IFLA_LINK
, sizeof(int), &dev
->iflink
);
3378 subattr
= (struct rtattr
*)skb
->tail
;
3380 RTA_PUT(skb
, IFLA_PROTINFO
, 0, NULL
);
3382 /* return the device flags */
3383 RTA_PUT(skb
, IFLA_INET6_FLAGS
, sizeof(__u32
), &idev
->if_flags
);
3385 /* return interface cacheinfo */
3386 ci
.max_reasm_len
= IPV6_MAXPLEN
;
3387 ci
.tstamp
= (__u32
)(TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) / HZ
* 100
3388 + TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3389 ci
.reachable_time
= idev
->nd_parms
->reachable_time
;
3390 ci
.retrans_time
= idev
->nd_parms
->retrans_time
;
3391 RTA_PUT(skb
, IFLA_INET6_CACHEINFO
, sizeof(ci
), &ci
);
3393 /* return the device sysctl params */
3394 if ((array
= kmalloc(DEVCONF_MAX
* sizeof(*array
), GFP_ATOMIC
)) == NULL
)
3395 goto rtattr_failure
;
3396 ipv6_store_devconf(&idev
->cnf
, array
, DEVCONF_MAX
* sizeof(*array
));
3397 RTA_PUT(skb
, IFLA_INET6_CONF
, DEVCONF_MAX
* sizeof(*array
), array
);
3399 /* XXX - Statistics/MC not implemented */
3400 subattr
->rta_len
= skb
->tail
- (u8
*)subattr
;
3402 nlh
->nlmsg_len
= skb
->tail
- b
;
3409 skb_trim(skb
, b
- skb
->data
);
3413 static int inet6_dump_ifinfo(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3416 int s_idx
= cb
->args
[0];
3417 struct net_device
*dev
;
3418 struct inet6_dev
*idev
;
3420 read_lock(&dev_base_lock
);
3421 for (dev
=dev_base
, idx
=0; dev
; dev
= dev
->next
, idx
++) {
3424 if ((idev
= in6_dev_get(dev
)) == NULL
)
3426 err
= inet6_fill_ifinfo(skb
, idev
, NETLINK_CB(cb
->skb
).pid
,
3427 cb
->nlh
->nlmsg_seq
, RTM_NEWLINK
, NLM_F_MULTI
);
3432 read_unlock(&dev_base_lock
);
3438 void inet6_ifinfo_notify(int event
, struct inet6_dev
*idev
)
3440 struct sk_buff
*skb
;
3441 int payload
= sizeof(struct ifinfomsg
) + INET6_IFINFO_RTA_SPACE
;
3444 skb
= nlmsg_new(nlmsg_total_size(payload
), GFP_ATOMIC
);
3448 err
= inet6_fill_ifinfo(skb
, idev
, 0, 0, event
, 0);
3454 err
= rtnl_notify(skb
, 0, RTNLGRP_IPV6_IFADDR
, NULL
, GFP_ATOMIC
);
3457 rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR
, err
);
3460 /* Maximum length of prefix_cacheinfo attributes */
3461 #define INET6_PREFIX_RTA_SPACE \
3462 RTA_SPACE(sizeof(((struct prefix_info *)NULL)->prefix)) /* ADDRESS */ + \
3463 RTA_SPACE(sizeof(struct prefix_cacheinfo)) /* CACHEINFO */
3465 static int inet6_fill_prefix(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3466 struct prefix_info
*pinfo
, u32 pid
, u32 seq
,
3467 int event
, unsigned int flags
)
3469 struct prefixmsg
*pmsg
;
3470 struct nlmsghdr
*nlh
;
3471 unsigned char *b
= skb
->tail
;
3472 struct prefix_cacheinfo ci
;
3474 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*pmsg
), flags
);
3475 pmsg
= NLMSG_DATA(nlh
);
3476 pmsg
->prefix_family
= AF_INET6
;
3477 pmsg
->prefix_pad1
= 0;
3478 pmsg
->prefix_pad2
= 0;
3479 pmsg
->prefix_ifindex
= idev
->dev
->ifindex
;
3480 pmsg
->prefix_len
= pinfo
->prefix_len
;
3481 pmsg
->prefix_type
= pinfo
->type
;
3482 pmsg
->prefix_pad3
= 0;
3484 pmsg
->prefix_flags
= 0;
3486 pmsg
->prefix_flags
|= IF_PREFIX_ONLINK
;
3487 if (pinfo
->autoconf
)
3488 pmsg
->prefix_flags
|= IF_PREFIX_AUTOCONF
;
3490 RTA_PUT(skb
, PREFIX_ADDRESS
, sizeof(pinfo
->prefix
), &pinfo
->prefix
);
3492 ci
.preferred_time
= ntohl(pinfo
->prefered
);
3493 ci
.valid_time
= ntohl(pinfo
->valid
);
3494 RTA_PUT(skb
, PREFIX_CACHEINFO
, sizeof(ci
), &ci
);
3496 nlh
->nlmsg_len
= skb
->tail
- b
;
3501 skb_trim(skb
, b
- skb
->data
);
3505 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
3506 struct prefix_info
*pinfo
)
3508 struct sk_buff
*skb
;
3509 int payload
= sizeof(struct prefixmsg
) + INET6_PREFIX_RTA_SPACE
;
3512 skb
= nlmsg_new(nlmsg_total_size(payload
), GFP_ATOMIC
);
3516 err
= inet6_fill_prefix(skb
, idev
, pinfo
, 0, 0, event
, 0);
3522 err
= rtnl_notify(skb
, 0, RTNLGRP_IPV6_PREFIX
, NULL
, GFP_ATOMIC
);
3525 rtnl_set_sk_err(RTNLGRP_IPV6_PREFIX
, err
);
3528 static struct rtnetlink_link inet6_rtnetlink_table
[RTM_NR_MSGTYPES
] = {
3529 [RTM_GETLINK
- RTM_BASE
] = { .dumpit
= inet6_dump_ifinfo
, },
3530 [RTM_NEWADDR
- RTM_BASE
] = { .doit
= inet6_rtm_newaddr
, },
3531 [RTM_DELADDR
- RTM_BASE
] = { .doit
= inet6_rtm_deladdr
, },
3532 [RTM_GETADDR
- RTM_BASE
] = { .doit
= inet6_rtm_getaddr
,
3533 .dumpit
= inet6_dump_ifaddr
, },
3534 [RTM_GETMULTICAST
- RTM_BASE
] = { .dumpit
= inet6_dump_ifmcaddr
, },
3535 [RTM_GETANYCAST
- RTM_BASE
] = { .dumpit
= inet6_dump_ifacaddr
, },
3536 [RTM_NEWROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_newroute
, },
3537 [RTM_DELROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_delroute
, },
3538 [RTM_GETROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_getroute
,
3539 .dumpit
= inet6_dump_fib
, },
3540 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
3541 [RTM_GETRULE
- RTM_BASE
] = { .dumpit
= fib6_rules_dump
, },
3545 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3547 inet6_ifa_notify(event
? : RTM_NEWADDR
, ifp
);
3551 ip6_ins_rt(ifp
->rt
, NULL
, NULL
, NULL
);
3552 if (ifp
->idev
->cnf
.forwarding
)
3553 addrconf_join_anycast(ifp
);
3556 if (ifp
->idev
->cnf
.forwarding
)
3557 addrconf_leave_anycast(ifp
);
3558 addrconf_leave_solict(ifp
->idev
, &ifp
->addr
);
3559 dst_hold(&ifp
->rt
->u
.dst
);
3560 if (ip6_del_rt(ifp
->rt
, NULL
, NULL
, NULL
))
3561 dst_free(&ifp
->rt
->u
.dst
);
3566 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3568 read_lock_bh(&addrconf_lock
);
3569 if (likely(ifp
->idev
->dead
== 0))
3570 __ipv6_ifa_notify(event
, ifp
);
3571 read_unlock_bh(&addrconf_lock
);
3574 #ifdef CONFIG_SYSCTL
3577 int addrconf_sysctl_forward(ctl_table
*ctl
, int write
, struct file
* filp
,
3578 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3580 int *valp
= ctl
->data
;
3584 ret
= proc_dointvec(ctl
, write
, filp
, buffer
, lenp
, ppos
);
3586 if (write
&& valp
!= &ipv6_devconf_dflt
.forwarding
) {
3587 if (valp
!= &ipv6_devconf
.forwarding
) {
3588 if ((!*valp
) ^ (!val
)) {
3589 struct inet6_dev
*idev
= (struct inet6_dev
*)ctl
->extra1
;
3592 dev_forward_change(idev
);
3595 ipv6_devconf_dflt
.forwarding
= ipv6_devconf
.forwarding
;
3596 addrconf_forward_change();
3599 rt6_purge_dflt_routers();
3605 static int addrconf_sysctl_forward_strategy(ctl_table
*table
,
3606 int __user
*name
, int nlen
,
3607 void __user
*oldval
,
3608 size_t __user
*oldlenp
,
3609 void __user
*newval
, size_t newlen
,
3612 int *valp
= table
->data
;
3615 if (!newval
|| !newlen
)
3617 if (newlen
!= sizeof(int))
3619 if (get_user(new, (int __user
*)newval
))
3623 if (oldval
&& oldlenp
) {
3625 if (get_user(len
, oldlenp
))
3628 if (len
> table
->maxlen
)
3629 len
= table
->maxlen
;
3630 if (copy_to_user(oldval
, valp
, len
))
3632 if (put_user(len
, oldlenp
))
3637 if (valp
!= &ipv6_devconf_dflt
.forwarding
) {
3638 if (valp
!= &ipv6_devconf
.forwarding
) {
3639 struct inet6_dev
*idev
= (struct inet6_dev
*)table
->extra1
;
3641 if (unlikely(idev
== NULL
))
3643 changed
= (!*valp
) ^ (!new);
3646 dev_forward_change(idev
);
3649 addrconf_forward_change();
3653 rt6_purge_dflt_routers();
3660 static struct addrconf_sysctl_table
3662 struct ctl_table_header
*sysctl_header
;
3663 ctl_table addrconf_vars
[__NET_IPV6_MAX
];
3664 ctl_table addrconf_dev
[2];
3665 ctl_table addrconf_conf_dir
[2];
3666 ctl_table addrconf_proto_dir
[2];
3667 ctl_table addrconf_root_dir
[2];
3668 } addrconf_sysctl __read_mostly
= {
3669 .sysctl_header
= NULL
,
3672 .ctl_name
= NET_IPV6_FORWARDING
,
3673 .procname
= "forwarding",
3674 .data
= &ipv6_devconf
.forwarding
,
3675 .maxlen
= sizeof(int),
3677 .proc_handler
= &addrconf_sysctl_forward
,
3678 .strategy
= &addrconf_sysctl_forward_strategy
,
3681 .ctl_name
= NET_IPV6_HOP_LIMIT
,
3682 .procname
= "hop_limit",
3683 .data
= &ipv6_devconf
.hop_limit
,
3684 .maxlen
= sizeof(int),
3686 .proc_handler
= proc_dointvec
,
3689 .ctl_name
= NET_IPV6_MTU
,
3691 .data
= &ipv6_devconf
.mtu6
,
3692 .maxlen
= sizeof(int),
3694 .proc_handler
= &proc_dointvec
,
3697 .ctl_name
= NET_IPV6_ACCEPT_RA
,
3698 .procname
= "accept_ra",
3699 .data
= &ipv6_devconf
.accept_ra
,
3700 .maxlen
= sizeof(int),
3702 .proc_handler
= &proc_dointvec
,
3705 .ctl_name
= NET_IPV6_ACCEPT_REDIRECTS
,
3706 .procname
= "accept_redirects",
3707 .data
= &ipv6_devconf
.accept_redirects
,
3708 .maxlen
= sizeof(int),
3710 .proc_handler
= &proc_dointvec
,
3713 .ctl_name
= NET_IPV6_AUTOCONF
,
3714 .procname
= "autoconf",
3715 .data
= &ipv6_devconf
.autoconf
,
3716 .maxlen
= sizeof(int),
3718 .proc_handler
= &proc_dointvec
,
3721 .ctl_name
= NET_IPV6_DAD_TRANSMITS
,
3722 .procname
= "dad_transmits",
3723 .data
= &ipv6_devconf
.dad_transmits
,
3724 .maxlen
= sizeof(int),
3726 .proc_handler
= &proc_dointvec
,
3729 .ctl_name
= NET_IPV6_RTR_SOLICITS
,
3730 .procname
= "router_solicitations",
3731 .data
= &ipv6_devconf
.rtr_solicits
,
3732 .maxlen
= sizeof(int),
3734 .proc_handler
= &proc_dointvec
,
3737 .ctl_name
= NET_IPV6_RTR_SOLICIT_INTERVAL
,
3738 .procname
= "router_solicitation_interval",
3739 .data
= &ipv6_devconf
.rtr_solicit_interval
,
3740 .maxlen
= sizeof(int),
3742 .proc_handler
= &proc_dointvec_jiffies
,
3743 .strategy
= &sysctl_jiffies
,
3746 .ctl_name
= NET_IPV6_RTR_SOLICIT_DELAY
,
3747 .procname
= "router_solicitation_delay",
3748 .data
= &ipv6_devconf
.rtr_solicit_delay
,
3749 .maxlen
= sizeof(int),
3751 .proc_handler
= &proc_dointvec_jiffies
,
3752 .strategy
= &sysctl_jiffies
,
3755 .ctl_name
= NET_IPV6_FORCE_MLD_VERSION
,
3756 .procname
= "force_mld_version",
3757 .data
= &ipv6_devconf
.force_mld_version
,
3758 .maxlen
= sizeof(int),
3760 .proc_handler
= &proc_dointvec
,
3762 #ifdef CONFIG_IPV6_PRIVACY
3764 .ctl_name
= NET_IPV6_USE_TEMPADDR
,
3765 .procname
= "use_tempaddr",
3766 .data
= &ipv6_devconf
.use_tempaddr
,
3767 .maxlen
= sizeof(int),
3769 .proc_handler
= &proc_dointvec
,
3772 .ctl_name
= NET_IPV6_TEMP_VALID_LFT
,
3773 .procname
= "temp_valid_lft",
3774 .data
= &ipv6_devconf
.temp_valid_lft
,
3775 .maxlen
= sizeof(int),
3777 .proc_handler
= &proc_dointvec
,
3780 .ctl_name
= NET_IPV6_TEMP_PREFERED_LFT
,
3781 .procname
= "temp_prefered_lft",
3782 .data
= &ipv6_devconf
.temp_prefered_lft
,
3783 .maxlen
= sizeof(int),
3785 .proc_handler
= &proc_dointvec
,
3788 .ctl_name
= NET_IPV6_REGEN_MAX_RETRY
,
3789 .procname
= "regen_max_retry",
3790 .data
= &ipv6_devconf
.regen_max_retry
,
3791 .maxlen
= sizeof(int),
3793 .proc_handler
= &proc_dointvec
,
3796 .ctl_name
= NET_IPV6_MAX_DESYNC_FACTOR
,
3797 .procname
= "max_desync_factor",
3798 .data
= &ipv6_devconf
.max_desync_factor
,
3799 .maxlen
= sizeof(int),
3801 .proc_handler
= &proc_dointvec
,
3805 .ctl_name
= NET_IPV6_MAX_ADDRESSES
,
3806 .procname
= "max_addresses",
3807 .data
= &ipv6_devconf
.max_addresses
,
3808 .maxlen
= sizeof(int),
3810 .proc_handler
= &proc_dointvec
,
3813 .ctl_name
= NET_IPV6_ACCEPT_RA_DEFRTR
,
3814 .procname
= "accept_ra_defrtr",
3815 .data
= &ipv6_devconf
.accept_ra_defrtr
,
3816 .maxlen
= sizeof(int),
3818 .proc_handler
= &proc_dointvec
,
3821 .ctl_name
= NET_IPV6_ACCEPT_RA_PINFO
,
3822 .procname
= "accept_ra_pinfo",
3823 .data
= &ipv6_devconf
.accept_ra_pinfo
,
3824 .maxlen
= sizeof(int),
3826 .proc_handler
= &proc_dointvec
,
3828 #ifdef CONFIG_IPV6_ROUTER_PREF
3830 .ctl_name
= NET_IPV6_ACCEPT_RA_RTR_PREF
,
3831 .procname
= "accept_ra_rtr_pref",
3832 .data
= &ipv6_devconf
.accept_ra_rtr_pref
,
3833 .maxlen
= sizeof(int),
3835 .proc_handler
= &proc_dointvec
,
3838 .ctl_name
= NET_IPV6_RTR_PROBE_INTERVAL
,
3839 .procname
= "router_probe_interval",
3840 .data
= &ipv6_devconf
.rtr_probe_interval
,
3841 .maxlen
= sizeof(int),
3843 .proc_handler
= &proc_dointvec_jiffies
,
3844 .strategy
= &sysctl_jiffies
,
3846 #ifdef CONFIV_IPV6_ROUTE_INFO
3848 .ctl_name
= NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN
,
3849 .procname
= "accept_ra_rt_info_max_plen",
3850 .data
= &ipv6_devconf
.accept_ra_rt_info_max_plen
,
3851 .maxlen
= sizeof(int),
3853 .proc_handler
= &proc_dointvec
,
3858 .ctl_name
= 0, /* sentinel */
3863 .ctl_name
= NET_PROTO_CONF_ALL
,
3866 .child
= addrconf_sysctl
.addrconf_vars
,
3869 .ctl_name
= 0, /* sentinel */
3872 .addrconf_conf_dir
= {
3874 .ctl_name
= NET_IPV6_CONF
,
3877 .child
= addrconf_sysctl
.addrconf_dev
,
3880 .ctl_name
= 0, /* sentinel */
3883 .addrconf_proto_dir
= {
3885 .ctl_name
= NET_IPV6
,
3888 .child
= addrconf_sysctl
.addrconf_conf_dir
,
3891 .ctl_name
= 0, /* sentinel */
3894 .addrconf_root_dir
= {
3896 .ctl_name
= CTL_NET
,
3899 .child
= addrconf_sysctl
.addrconf_proto_dir
,
3902 .ctl_name
= 0, /* sentinel */
3907 static void addrconf_sysctl_register(struct inet6_dev
*idev
, struct ipv6_devconf
*p
)
3910 struct net_device
*dev
= idev
? idev
->dev
: NULL
;
3911 struct addrconf_sysctl_table
*t
;
3912 char *dev_name
= NULL
;
3914 t
= kmalloc(sizeof(*t
), GFP_KERNEL
);
3917 memcpy(t
, &addrconf_sysctl
, sizeof(*t
));
3918 for (i
=0; t
->addrconf_vars
[i
].data
; i
++) {
3919 t
->addrconf_vars
[i
].data
+= (char*)p
- (char*)&ipv6_devconf
;
3920 t
->addrconf_vars
[i
].de
= NULL
;
3921 t
->addrconf_vars
[i
].extra1
= idev
; /* embedded; no ref */
3924 dev_name
= dev
->name
;
3925 t
->addrconf_dev
[0].ctl_name
= dev
->ifindex
;
3927 dev_name
= "default";
3928 t
->addrconf_dev
[0].ctl_name
= NET_PROTO_CONF_DEFAULT
;
3932 * Make a copy of dev_name, because '.procname' is regarded as const
3933 * by sysctl and we wouldn't want anyone to change it under our feet
3934 * (see SIOCSIFNAME).
3936 dev_name
= kstrdup(dev_name
, GFP_KERNEL
);
3940 t
->addrconf_dev
[0].procname
= dev_name
;
3942 t
->addrconf_dev
[0].child
= t
->addrconf_vars
;
3943 t
->addrconf_dev
[0].de
= NULL
;
3944 t
->addrconf_conf_dir
[0].child
= t
->addrconf_dev
;
3945 t
->addrconf_conf_dir
[0].de
= NULL
;
3946 t
->addrconf_proto_dir
[0].child
= t
->addrconf_conf_dir
;
3947 t
->addrconf_proto_dir
[0].de
= NULL
;
3948 t
->addrconf_root_dir
[0].child
= t
->addrconf_proto_dir
;
3949 t
->addrconf_root_dir
[0].de
= NULL
;
3951 t
->sysctl_header
= register_sysctl_table(t
->addrconf_root_dir
, 0);
3952 if (t
->sysctl_header
== NULL
)
3967 static void addrconf_sysctl_unregister(struct ipv6_devconf
*p
)
3970 struct addrconf_sysctl_table
*t
= p
->sysctl
;
3972 unregister_sysctl_table(t
->sysctl_header
);
3973 kfree(t
->addrconf_dev
[0].procname
);
3985 int register_inet6addr_notifier(struct notifier_block
*nb
)
3987 return atomic_notifier_chain_register(&inet6addr_chain
, nb
);
3990 int unregister_inet6addr_notifier(struct notifier_block
*nb
)
3992 return atomic_notifier_chain_unregister(&inet6addr_chain
,nb
);
3996 * Init / cleanup code
3999 int __init
addrconf_init(void)
4003 /* The addrconf netdev notifier requires that loopback_dev
4004 * has it's ipv6 private information allocated and setup
4005 * before it can bring up and give link-local addresses
4006 * to other devices which are up.
4008 * Unfortunately, loopback_dev is not necessarily the first
4009 * entry in the global dev_base list of net devices. In fact,
4010 * it is likely to be the very last entry on that list.
4011 * So this causes the notifier registry below to try and
4012 * give link-local addresses to all devices besides loopback_dev
4013 * first, then loopback_dev, which cases all the non-loopback_dev
4014 * devices to fail to get a link-local address.
4016 * So, as a temporary fix, allocate the ipv6 structure for
4017 * loopback_dev first by hand.
4018 * Longer term, all of the dependencies ipv6 has upon the loopback
4019 * device and it being up should be removed.
4022 if (!ipv6_add_dev(&loopback_dev
))
4028 ip6_null_entry
.rt6i_idev
= in6_dev_get(&loopback_dev
);
4030 register_netdevice_notifier(&ipv6_dev_notf
);
4033 rtnetlink_links
[PF_INET6
] = inet6_rtnetlink_table
;
4034 #ifdef CONFIG_SYSCTL
4035 addrconf_sysctl
.sysctl_header
=
4036 register_sysctl_table(addrconf_sysctl
.addrconf_root_dir
, 0);
4037 addrconf_sysctl_register(NULL
, &ipv6_devconf_dflt
);
4043 void __exit
addrconf_cleanup(void)
4045 struct net_device
*dev
;
4046 struct inet6_dev
*idev
;
4047 struct inet6_ifaddr
*ifa
;
4050 unregister_netdevice_notifier(&ipv6_dev_notf
);
4052 rtnetlink_links
[PF_INET6
] = NULL
;
4053 #ifdef CONFIG_SYSCTL
4054 addrconf_sysctl_unregister(&ipv6_devconf_dflt
);
4055 addrconf_sysctl_unregister(&ipv6_devconf
);
4064 for (dev
=dev_base
; dev
; dev
=dev
->next
) {
4065 if ((idev
= __in6_dev_get(dev
)) == NULL
)
4067 addrconf_ifdown(dev
, 1);
4069 addrconf_ifdown(&loopback_dev
, 2);
4075 write_lock_bh(&addrconf_hash_lock
);
4076 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
4077 for (ifa
=inet6_addr_lst
[i
]; ifa
; ) {
4078 struct inet6_ifaddr
*bifa
;
4081 ifa
= ifa
->lst_next
;
4082 printk(KERN_DEBUG
"bug: IPv6 address leakage detected: ifa=%p\n", bifa
);
4083 /* Do not free it; something is wrong.
4084 Now we can investigate it with debugger.
4088 write_unlock_bh(&addrconf_hash_lock
);
4090 del_timer(&addr_chk_timer
);
4094 #ifdef CONFIG_PROC_FS
4095 proc_net_remove("if_inet6");