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 static void addrconf_verify(unsigned long);
124 static DEFINE_TIMER(addr_chk_timer
, addrconf_verify
, 0, 0);
125 static DEFINE_SPINLOCK(addrconf_verify_lock
);
127 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
);
128 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
);
130 static int addrconf_ifdown(struct net_device
*dev
, int how
);
132 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
);
133 static void addrconf_dad_timer(unsigned long data
);
134 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
);
135 static void addrconf_dad_run(struct inet6_dev
*idev
);
136 static void addrconf_rs_timer(unsigned long data
);
137 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
);
138 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
);
140 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
141 struct prefix_info
*pinfo
);
142 static int ipv6_chk_same_addr(const struct in6_addr
*addr
, struct net_device
*dev
);
144 static ATOMIC_NOTIFIER_HEAD(inet6addr_chain
);
146 struct ipv6_devconf ipv6_devconf __read_mostly
= {
148 .hop_limit
= IPV6_DEFAULT_HOPLIMIT
,
149 .mtu6
= IPV6_MIN_MTU
,
151 .accept_redirects
= 1,
153 .force_mld_version
= 0,
155 .rtr_solicits
= MAX_RTR_SOLICITATIONS
,
156 .rtr_solicit_interval
= RTR_SOLICITATION_INTERVAL
,
157 .rtr_solicit_delay
= MAX_RTR_SOLICITATION_DELAY
,
158 #ifdef CONFIG_IPV6_PRIVACY
160 .temp_valid_lft
= TEMP_VALID_LIFETIME
,
161 .temp_prefered_lft
= TEMP_PREFERRED_LIFETIME
,
162 .regen_max_retry
= REGEN_MAX_RETRY
,
163 .max_desync_factor
= MAX_DESYNC_FACTOR
,
165 .max_addresses
= IPV6_MAX_ADDRESSES
,
166 .accept_ra_defrtr
= 1,
167 .accept_ra_pinfo
= 1,
168 #ifdef CONFIG_IPV6_ROUTER_PREF
169 .accept_ra_rtr_pref
= 1,
170 .rtr_probe_interval
= 60 * HZ
,
171 #ifdef CONFIG_IPV6_ROUTE_INFO
172 .accept_ra_rt_info_max_plen
= 0,
178 static struct ipv6_devconf ipv6_devconf_dflt __read_mostly
= {
180 .hop_limit
= IPV6_DEFAULT_HOPLIMIT
,
181 .mtu6
= IPV6_MIN_MTU
,
183 .accept_redirects
= 1,
186 .rtr_solicits
= MAX_RTR_SOLICITATIONS
,
187 .rtr_solicit_interval
= RTR_SOLICITATION_INTERVAL
,
188 .rtr_solicit_delay
= MAX_RTR_SOLICITATION_DELAY
,
189 #ifdef CONFIG_IPV6_PRIVACY
191 .temp_valid_lft
= TEMP_VALID_LIFETIME
,
192 .temp_prefered_lft
= TEMP_PREFERRED_LIFETIME
,
193 .regen_max_retry
= REGEN_MAX_RETRY
,
194 .max_desync_factor
= MAX_DESYNC_FACTOR
,
196 .max_addresses
= IPV6_MAX_ADDRESSES
,
197 .accept_ra_defrtr
= 1,
198 .accept_ra_pinfo
= 1,
199 #ifdef CONFIG_IPV6_ROUTER_PREF
200 .accept_ra_rtr_pref
= 1,
201 .rtr_probe_interval
= 60 * HZ
,
202 #ifdef CONFIG_IPV6_ROUTE_INFO
203 .accept_ra_rt_info_max_plen
= 0,
209 /* IPv6 Wildcard Address and Loopback Address defined by RFC2553 */
211 const struct in6_addr in6addr_any
= IN6ADDR_ANY_INIT
;
213 const struct in6_addr in6addr_loopback
= IN6ADDR_LOOPBACK_INIT
;
215 #define IPV6_ADDR_SCOPE_TYPE(scope) ((scope) << 16)
217 static inline unsigned ipv6_addr_scope2type(unsigned scope
)
220 case IPV6_ADDR_SCOPE_NODELOCAL
:
221 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_NODELOCAL
) |
223 case IPV6_ADDR_SCOPE_LINKLOCAL
:
224 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
) |
225 IPV6_ADDR_LINKLOCAL
);
226 case IPV6_ADDR_SCOPE_SITELOCAL
:
227 return (IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL
) |
228 IPV6_ADDR_SITELOCAL
);
230 return IPV6_ADDR_SCOPE_TYPE(scope
);
233 int __ipv6_addr_type(const struct in6_addr
*addr
)
237 st
= addr
->s6_addr32
[0];
239 /* Consider all addresses with the first three bits different of
240 000 and 111 as unicasts.
242 if ((st
& htonl(0xE0000000)) != htonl(0x00000000) &&
243 (st
& htonl(0xE0000000)) != htonl(0xE0000000))
244 return (IPV6_ADDR_UNICAST
|
245 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
));
247 if ((st
& htonl(0xFF000000)) == htonl(0xFF000000)) {
249 /* addr-select 3.1 */
250 return (IPV6_ADDR_MULTICAST
|
251 ipv6_addr_scope2type(IPV6_ADDR_MC_SCOPE(addr
)));
254 if ((st
& htonl(0xFFC00000)) == htonl(0xFE800000))
255 return (IPV6_ADDR_LINKLOCAL
| IPV6_ADDR_UNICAST
|
256 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
)); /* addr-select 3.1 */
257 if ((st
& htonl(0xFFC00000)) == htonl(0xFEC00000))
258 return (IPV6_ADDR_SITELOCAL
| IPV6_ADDR_UNICAST
|
259 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_SITELOCAL
)); /* addr-select 3.1 */
261 if ((addr
->s6_addr32
[0] | addr
->s6_addr32
[1]) == 0) {
262 if (addr
->s6_addr32
[2] == 0) {
263 if (addr
->s6_addr32
[3] == 0)
264 return IPV6_ADDR_ANY
;
266 if (addr
->s6_addr32
[3] == htonl(0x00000001))
267 return (IPV6_ADDR_LOOPBACK
| IPV6_ADDR_UNICAST
|
268 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_LINKLOCAL
)); /* addr-select 3.4 */
270 return (IPV6_ADDR_COMPATv4
| IPV6_ADDR_UNICAST
|
271 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.3 */
274 if (addr
->s6_addr32
[2] == htonl(0x0000ffff))
275 return (IPV6_ADDR_MAPPED
|
276 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.3 */
279 return (IPV6_ADDR_RESERVED
|
280 IPV6_ADDR_SCOPE_TYPE(IPV6_ADDR_SCOPE_GLOBAL
)); /* addr-select 3.4 */
283 static void addrconf_del_timer(struct inet6_ifaddr
*ifp
)
285 if (del_timer(&ifp
->timer
))
289 enum addrconf_timer_t
296 static void addrconf_mod_timer(struct inet6_ifaddr
*ifp
,
297 enum addrconf_timer_t what
,
300 if (!del_timer(&ifp
->timer
))
305 ifp
->timer
.function
= addrconf_dad_timer
;
308 ifp
->timer
.function
= addrconf_rs_timer
;
312 ifp
->timer
.expires
= jiffies
+ when
;
313 add_timer(&ifp
->timer
);
316 /* Nobody refers to this device, we may destroy it. */
318 static void in6_dev_finish_destroy_rcu(struct rcu_head
*head
)
320 struct inet6_dev
*idev
= container_of(head
, struct inet6_dev
, rcu
);
324 void in6_dev_finish_destroy(struct inet6_dev
*idev
)
326 struct net_device
*dev
= idev
->dev
;
327 BUG_TRAP(idev
->addr_list
==NULL
);
328 BUG_TRAP(idev
->mc_list
==NULL
);
329 #ifdef NET_REFCNT_DEBUG
330 printk(KERN_DEBUG
"in6_dev_finish_destroy: %s\n", dev
? dev
->name
: "NIL");
334 printk("Freeing alive inet6 device %p\n", idev
);
337 snmp6_free_dev(idev
);
338 call_rcu(&idev
->rcu
, in6_dev_finish_destroy_rcu
);
341 static struct inet6_dev
* ipv6_add_dev(struct net_device
*dev
)
343 struct inet6_dev
*ndev
;
347 if (dev
->mtu
< IPV6_MIN_MTU
)
350 ndev
= kzalloc(sizeof(struct inet6_dev
), GFP_KERNEL
);
355 rwlock_init(&ndev
->lock
);
357 memcpy(&ndev
->cnf
, &ipv6_devconf_dflt
, sizeof(ndev
->cnf
));
358 ndev
->cnf
.mtu6
= dev
->mtu
;
359 ndev
->cnf
.sysctl
= NULL
;
360 ndev
->nd_parms
= neigh_parms_alloc(dev
, &nd_tbl
);
361 if (ndev
->nd_parms
== NULL
) {
365 /* We refer to the device */
368 if (snmp6_alloc_dev(ndev
) < 0) {
370 "%s(): cannot allocate memory for statistics; dev=%s.\n",
371 __FUNCTION__
, dev
->name
));
372 neigh_parms_release(&nd_tbl
, ndev
->nd_parms
);
374 in6_dev_finish_destroy(ndev
);
378 if (snmp6_register_dev(ndev
) < 0) {
380 "%s(): cannot create /proc/net/dev_snmp6/%s\n",
381 __FUNCTION__
, dev
->name
));
382 neigh_parms_release(&nd_tbl
, ndev
->nd_parms
);
384 in6_dev_finish_destroy(ndev
);
388 /* One reference from device. We must do this before
389 * we invoke __ipv6_regen_rndid().
393 #ifdef CONFIG_IPV6_PRIVACY
394 init_timer(&ndev
->regen_timer
);
395 ndev
->regen_timer
.function
= ipv6_regen_rndid
;
396 ndev
->regen_timer
.data
= (unsigned long) ndev
;
397 if ((dev
->flags
&IFF_LOOPBACK
) ||
398 dev
->type
== ARPHRD_TUNNEL
||
399 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
400 dev
->type
== ARPHRD_SIT
||
402 dev
->type
== ARPHRD_NONE
) {
404 "%s: Disabled Privacy Extensions\n",
406 ndev
->cnf
.use_tempaddr
= -1;
409 ipv6_regen_rndid((unsigned long) ndev
);
413 if (netif_carrier_ok(dev
))
414 ndev
->if_flags
|= IF_READY
;
416 /* protected by rtnl_lock */
417 rcu_assign_pointer(dev
->ip6_ptr
, ndev
);
419 ipv6_mc_init_dev(ndev
);
420 ndev
->tstamp
= jiffies
;
422 neigh_sysctl_register(dev
, ndev
->nd_parms
, NET_IPV6
,
423 NET_IPV6_NEIGH
, "ipv6",
424 &ndisc_ifinfo_sysctl_change
,
426 addrconf_sysctl_register(ndev
, &ndev
->cnf
);
431 static struct inet6_dev
* ipv6_find_idev(struct net_device
*dev
)
433 struct inet6_dev
*idev
;
437 if ((idev
= __in6_dev_get(dev
)) == NULL
) {
438 if ((idev
= ipv6_add_dev(dev
)) == NULL
)
442 if (dev
->flags
&IFF_UP
)
448 static void dev_forward_change(struct inet6_dev
*idev
)
450 struct net_device
*dev
;
451 struct inet6_ifaddr
*ifa
;
452 struct in6_addr addr
;
457 if (dev
&& (dev
->flags
& IFF_MULTICAST
)) {
458 ipv6_addr_all_routers(&addr
);
460 if (idev
->cnf
.forwarding
)
461 ipv6_dev_mc_inc(dev
, &addr
);
463 ipv6_dev_mc_dec(dev
, &addr
);
465 for (ifa
=idev
->addr_list
; ifa
; ifa
=ifa
->if_next
) {
466 if (idev
->cnf
.forwarding
)
467 addrconf_join_anycast(ifa
);
469 addrconf_leave_anycast(ifa
);
474 static void addrconf_forward_change(void)
476 struct net_device
*dev
;
477 struct inet6_dev
*idev
;
479 read_lock(&dev_base_lock
);
480 for (dev
=dev_base
; dev
; dev
=dev
->next
) {
482 idev
= __in6_dev_get(dev
);
484 int changed
= (!idev
->cnf
.forwarding
) ^ (!ipv6_devconf
.forwarding
);
485 idev
->cnf
.forwarding
= ipv6_devconf
.forwarding
;
487 dev_forward_change(idev
);
491 read_unlock(&dev_base_lock
);
495 /* Nobody refers to this ifaddr, destroy it */
497 void inet6_ifa_finish_destroy(struct inet6_ifaddr
*ifp
)
499 BUG_TRAP(ifp
->if_next
==NULL
);
500 BUG_TRAP(ifp
->lst_next
==NULL
);
501 #ifdef NET_REFCNT_DEBUG
502 printk(KERN_DEBUG
"inet6_ifa_finish_destroy\n");
505 in6_dev_put(ifp
->idev
);
507 if (del_timer(&ifp
->timer
))
508 printk("Timer is still running, when freeing ifa=%p\n", ifp
);
511 printk("Freeing alive inet6 address %p\n", ifp
);
514 dst_release(&ifp
->rt
->u
.dst
);
520 ipv6_link_dev_addr(struct inet6_dev
*idev
, struct inet6_ifaddr
*ifp
)
522 struct inet6_ifaddr
*ifa
, **ifap
;
523 int ifp_scope
= ipv6_addr_src_scope(&ifp
->addr
);
526 * Each device address list is sorted in order of scope -
527 * global before linklocal.
529 for (ifap
= &idev
->addr_list
; (ifa
= *ifap
) != NULL
;
530 ifap
= &ifa
->if_next
) {
531 if (ifp_scope
>= ipv6_addr_src_scope(&ifa
->addr
))
535 ifp
->if_next
= *ifap
;
539 /* On success it returns ifp with increased reference count */
541 static struct inet6_ifaddr
*
542 ipv6_add_addr(struct inet6_dev
*idev
, const struct in6_addr
*addr
, int pfxlen
,
543 int scope
, u32 flags
)
545 struct inet6_ifaddr
*ifa
= NULL
;
552 err
= -ENODEV
; /*XXX*/
556 write_lock(&addrconf_hash_lock
);
558 /* Ignore adding duplicate addresses on an interface */
559 if (ipv6_chk_same_addr(addr
, idev
->dev
)) {
560 ADBG(("ipv6_add_addr: already assigned\n"));
565 ifa
= kzalloc(sizeof(struct inet6_ifaddr
), GFP_ATOMIC
);
568 ADBG(("ipv6_add_addr: malloc failed\n"));
573 rt
= addrconf_dst_alloc(idev
, addr
, 0);
579 ipv6_addr_copy(&ifa
->addr
, addr
);
581 spin_lock_init(&ifa
->lock
);
582 init_timer(&ifa
->timer
);
583 ifa
->timer
.data
= (unsigned long) ifa
;
585 ifa
->prefix_len
= pfxlen
;
586 ifa
->flags
= flags
| IFA_F_TENTATIVE
;
587 ifa
->cstamp
= ifa
->tstamp
= jiffies
;
596 /* Add to big hash table */
597 hash
= ipv6_addr_hash(addr
);
599 ifa
->lst_next
= inet6_addr_lst
[hash
];
600 inet6_addr_lst
[hash
] = ifa
;
602 write_unlock(&addrconf_hash_lock
);
604 write_lock(&idev
->lock
);
605 /* Add to inet6_dev unicast addr list. */
606 ipv6_link_dev_addr(idev
, ifa
);
608 #ifdef CONFIG_IPV6_PRIVACY
609 if (ifa
->flags
&IFA_F_TEMPORARY
) {
610 ifa
->tmp_next
= idev
->tempaddr_list
;
611 idev
->tempaddr_list
= ifa
;
617 write_unlock(&idev
->lock
);
619 rcu_read_unlock_bh();
621 if (likely(err
== 0))
622 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_UP
, ifa
);
630 write_unlock(&addrconf_hash_lock
);
634 /* This function wants to get referenced ifp and releases it before return */
636 static void ipv6_del_addr(struct inet6_ifaddr
*ifp
)
638 struct inet6_ifaddr
*ifa
, **ifap
;
639 struct inet6_dev
*idev
= ifp
->idev
;
641 int deleted
= 0, onlink
= 0;
642 unsigned long expires
= jiffies
;
644 hash
= ipv6_addr_hash(&ifp
->addr
);
648 write_lock_bh(&addrconf_hash_lock
);
649 for (ifap
= &inet6_addr_lst
[hash
]; (ifa
=*ifap
) != NULL
;
650 ifap
= &ifa
->lst_next
) {
652 *ifap
= ifa
->lst_next
;
654 ifa
->lst_next
= NULL
;
658 write_unlock_bh(&addrconf_hash_lock
);
660 write_lock_bh(&idev
->lock
);
661 #ifdef CONFIG_IPV6_PRIVACY
662 if (ifp
->flags
&IFA_F_TEMPORARY
) {
663 for (ifap
= &idev
->tempaddr_list
; (ifa
=*ifap
) != NULL
;
664 ifap
= &ifa
->tmp_next
) {
666 *ifap
= ifa
->tmp_next
;
668 in6_ifa_put(ifp
->ifpub
);
672 ifa
->tmp_next
= NULL
;
679 for (ifap
= &idev
->addr_list
; (ifa
=*ifap
) != NULL
;) {
681 *ifap
= ifa
->if_next
;
684 if (!(ifp
->flags
& IFA_F_PERMANENT
) || onlink
> 0)
688 } else if (ifp
->flags
& IFA_F_PERMANENT
) {
689 if (ipv6_prefix_equal(&ifa
->addr
, &ifp
->addr
,
691 if (ifa
->flags
& IFA_F_PERMANENT
) {
696 unsigned long lifetime
;
701 spin_lock(&ifa
->lock
);
702 lifetime
= min_t(unsigned long,
703 ifa
->valid_lft
, 0x7fffffffUL
/HZ
);
704 if (time_before(expires
,
705 ifa
->tstamp
+ lifetime
* HZ
))
706 expires
= ifa
->tstamp
+ lifetime
* HZ
;
707 spin_unlock(&ifa
->lock
);
711 ifap
= &ifa
->if_next
;
713 write_unlock_bh(&idev
->lock
);
715 ipv6_ifa_notify(RTM_DELADDR
, ifp
);
717 atomic_notifier_call_chain(&inet6addr_chain
, NETDEV_DOWN
, ifp
);
719 addrconf_del_timer(ifp
);
722 * Purge or update corresponding prefix
724 * 1) we don't purge prefix here if address was not permanent.
725 * prefix is managed by its own lifetime.
726 * 2) if there're no addresses, delete prefix.
727 * 3) if there're still other permanent address(es),
728 * corresponding prefix is still permanent.
729 * 4) otherwise, update prefix lifetime to the
730 * longest valid lifetime among the corresponding
731 * addresses on the device.
732 * Note: subsequent RA will update lifetime.
736 if ((ifp
->flags
& IFA_F_PERMANENT
) && onlink
< 1) {
737 struct in6_addr prefix
;
740 ipv6_addr_prefix(&prefix
, &ifp
->addr
, ifp
->prefix_len
);
741 rt
= rt6_lookup(&prefix
, NULL
, ifp
->idev
->dev
->ifindex
, 1);
743 if (rt
&& ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0)) {
747 } else if (!(rt
->rt6i_flags
& RTF_EXPIRES
)) {
748 rt
->rt6i_expires
= expires
;
749 rt
->rt6i_flags
|= RTF_EXPIRES
;
752 dst_release(&rt
->u
.dst
);
758 #ifdef CONFIG_IPV6_PRIVACY
759 static int ipv6_create_tempaddr(struct inet6_ifaddr
*ifp
, struct inet6_ifaddr
*ift
)
761 struct inet6_dev
*idev
= ifp
->idev
;
762 struct in6_addr addr
, *tmpaddr
;
763 unsigned long tmp_prefered_lft
, tmp_valid_lft
, tmp_cstamp
, tmp_tstamp
;
768 write_lock(&idev
->lock
);
770 spin_lock_bh(&ift
->lock
);
771 memcpy(&addr
.s6_addr
[8], &ift
->addr
.s6_addr
[8], 8);
772 spin_unlock_bh(&ift
->lock
);
779 if (idev
->cnf
.use_tempaddr
<= 0) {
780 write_unlock(&idev
->lock
);
782 "ipv6_create_tempaddr(): use_tempaddr is disabled.\n");
787 spin_lock_bh(&ifp
->lock
);
788 if (ifp
->regen_count
++ >= idev
->cnf
.regen_max_retry
) {
789 idev
->cnf
.use_tempaddr
= -1; /*XXX*/
790 spin_unlock_bh(&ifp
->lock
);
791 write_unlock(&idev
->lock
);
793 "ipv6_create_tempaddr(): regeneration time exceeded. disabled temporary address support.\n");
799 memcpy(addr
.s6_addr
, ifp
->addr
.s6_addr
, 8);
800 if (__ipv6_try_regen_rndid(idev
, tmpaddr
) < 0) {
801 spin_unlock_bh(&ifp
->lock
);
802 write_unlock(&idev
->lock
);
804 "ipv6_create_tempaddr(): regeneration of randomized interface id failed.\n");
810 memcpy(&addr
.s6_addr
[8], idev
->rndid
, 8);
811 tmp_valid_lft
= min_t(__u32
,
813 idev
->cnf
.temp_valid_lft
);
814 tmp_prefered_lft
= min_t(__u32
,
816 idev
->cnf
.temp_prefered_lft
- desync_factor
/ HZ
);
817 tmp_plen
= ifp
->prefix_len
;
818 max_addresses
= idev
->cnf
.max_addresses
;
819 tmp_cstamp
= ifp
->cstamp
;
820 tmp_tstamp
= ifp
->tstamp
;
821 spin_unlock_bh(&ifp
->lock
);
823 write_unlock(&idev
->lock
);
824 ift
= !max_addresses
||
825 ipv6_count_addresses(idev
) < max_addresses
?
826 ipv6_add_addr(idev
, &addr
, tmp_plen
,
827 ipv6_addr_type(&addr
)&IPV6_ADDR_SCOPE_MASK
, IFA_F_TEMPORARY
) : NULL
;
828 if (!ift
|| IS_ERR(ift
)) {
832 "ipv6_create_tempaddr(): retry temporary address regeneration.\n");
834 write_lock(&idev
->lock
);
838 spin_lock_bh(&ift
->lock
);
840 ift
->valid_lft
= tmp_valid_lft
;
841 ift
->prefered_lft
= tmp_prefered_lft
;
842 ift
->cstamp
= tmp_cstamp
;
843 ift
->tstamp
= tmp_tstamp
;
844 spin_unlock_bh(&ift
->lock
);
846 addrconf_dad_start(ift
, 0);
855 * Choose an appropriate source address (RFC3484)
857 struct ipv6_saddr_score
{
865 #define IPV6_SADDR_SCORE_LOCAL 0x0001
866 #define IPV6_SADDR_SCORE_PREFERRED 0x0004
867 #define IPV6_SADDR_SCORE_HOA 0x0008
868 #define IPV6_SADDR_SCORE_OIF 0x0010
869 #define IPV6_SADDR_SCORE_LABEL 0x0020
870 #define IPV6_SADDR_SCORE_PRIVACY 0x0040
872 static int inline ipv6_saddr_preferred(int type
)
874 if (type
& (IPV6_ADDR_MAPPED
|IPV6_ADDR_COMPATv4
|
875 IPV6_ADDR_LOOPBACK
|IPV6_ADDR_RESERVED
))
880 /* static matching label */
881 static int inline ipv6_saddr_label(const struct in6_addr
*addr
, int type
)
884 * prefix (longest match) label
885 * -----------------------------
894 if (type
& IPV6_ADDR_LOOPBACK
)
896 else if (type
& IPV6_ADDR_COMPATv4
)
898 else if (type
& IPV6_ADDR_MAPPED
)
900 else if (addr
->s6_addr32
[0] == htonl(0x20010000))
902 else if (addr
->s6_addr16
[0] == htons(0x2002))
904 else if ((addr
->s6_addr
[0] & 0xfe) == 0xfc)
909 int ipv6_dev_get_saddr(struct net_device
*daddr_dev
,
910 struct in6_addr
*daddr
, struct in6_addr
*saddr
)
912 struct ipv6_saddr_score hiscore
;
913 struct inet6_ifaddr
*ifa_result
= NULL
;
914 int daddr_type
= __ipv6_addr_type(daddr
);
915 int daddr_scope
= __ipv6_addr_src_scope(daddr_type
);
916 u32 daddr_label
= ipv6_saddr_label(daddr
, daddr_type
);
917 struct net_device
*dev
;
919 memset(&hiscore
, 0, sizeof(hiscore
));
921 read_lock(&dev_base_lock
);
924 for (dev
= dev_base
; dev
; dev
=dev
->next
) {
925 struct inet6_dev
*idev
;
926 struct inet6_ifaddr
*ifa
;
928 /* Rule 0: Candidate Source Address (section 4)
929 * - multicast and link-local destination address,
930 * the set of candidate source address MUST only
931 * include addresses assigned to interfaces
932 * belonging to the same link as the outgoing
934 * (- For site-local destination addresses, the
935 * set of candidate source addresses MUST only
936 * include addresses assigned to interfaces
937 * belonging to the same site as the outgoing
940 if ((daddr_type
& IPV6_ADDR_MULTICAST
||
941 daddr_scope
<= IPV6_ADDR_SCOPE_LINKLOCAL
) &&
942 daddr_dev
&& dev
!= daddr_dev
)
945 idev
= __in6_dev_get(dev
);
949 read_lock_bh(&idev
->lock
);
950 for (ifa
= idev
->addr_list
; ifa
; ifa
= ifa
->if_next
) {
951 struct ipv6_saddr_score score
;
953 score
.addr_type
= __ipv6_addr_type(&ifa
->addr
);
956 * - Tentative Address (RFC2462 section 5.4)
957 * - A tentative address is not considered
958 * "assigned to an interface" in the traditional
960 * - Candidate Source Address (section 4)
961 * - In any case, anycast addresses, multicast
962 * addresses, and the unspecified address MUST
963 * NOT be included in a candidate set.
965 if (ifa
->flags
& IFA_F_TENTATIVE
)
967 if (unlikely(score
.addr_type
== IPV6_ADDR_ANY
||
968 score
.addr_type
& IPV6_ADDR_MULTICAST
)) {
969 LIMIT_NETDEBUG(KERN_DEBUG
970 "ADDRCONF: unspecified / multicast address"
971 "assigned as unicast address on %s",
981 if (ifa_result
== NULL
) {
982 /* record it if the first available entry */
986 /* Rule 1: Prefer same address */
987 if (hiscore
.rule
< 1) {
988 if (ipv6_addr_equal(&ifa_result
->addr
, daddr
))
989 hiscore
.attrs
|= IPV6_SADDR_SCORE_LOCAL
;
992 if (ipv6_addr_equal(&ifa
->addr
, daddr
)) {
993 score
.attrs
|= IPV6_SADDR_SCORE_LOCAL
;
994 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_LOCAL
)) {
999 if (hiscore
.attrs
& IPV6_SADDR_SCORE_LOCAL
)
1003 /* Rule 2: Prefer appropriate scope */
1004 if (hiscore
.rule
< 2) {
1005 hiscore
.scope
= __ipv6_addr_src_scope(hiscore
.addr_type
);
1008 score
.scope
= __ipv6_addr_src_scope(score
.addr_type
);
1009 if (hiscore
.scope
< score
.scope
) {
1010 if (hiscore
.scope
< daddr_scope
) {
1015 } else if (score
.scope
< hiscore
.scope
) {
1016 if (score
.scope
< daddr_scope
)
1017 break; /* addresses sorted by scope */
1024 /* Rule 3: Avoid deprecated address */
1025 if (hiscore
.rule
< 3) {
1026 if (ipv6_saddr_preferred(hiscore
.addr_type
) ||
1027 !(ifa_result
->flags
& IFA_F_DEPRECATED
))
1028 hiscore
.attrs
|= IPV6_SADDR_SCORE_PREFERRED
;
1031 if (ipv6_saddr_preferred(score
.addr_type
) ||
1032 !(ifa
->flags
& IFA_F_DEPRECATED
)) {
1033 score
.attrs
|= IPV6_SADDR_SCORE_PREFERRED
;
1034 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_PREFERRED
)) {
1039 if (hiscore
.attrs
& IPV6_SADDR_SCORE_PREFERRED
)
1043 /* Rule 4: Prefer home address */
1044 #ifdef CONFIG_IPV6_MIP6
1045 if (hiscore
.rule
< 4) {
1046 if (ifa_result
->flags
& IFA_F_HOMEADDRESS
)
1047 hiscore
.attrs
|= IPV6_SADDR_SCORE_HOA
;
1050 if (ifa
->flags
& IFA_F_HOMEADDRESS
) {
1051 score
.attrs
|= IPV6_SADDR_SCORE_HOA
;
1052 if (!(ifa_result
->flags
& IFA_F_HOMEADDRESS
)) {
1057 if (hiscore
.attrs
& IPV6_SADDR_SCORE_HOA
)
1061 if (hiscore
.rule
< 4)
1065 /* Rule 5: Prefer outgoing interface */
1066 if (hiscore
.rule
< 5) {
1067 if (daddr_dev
== NULL
||
1068 daddr_dev
== ifa_result
->idev
->dev
)
1069 hiscore
.attrs
|= IPV6_SADDR_SCORE_OIF
;
1072 if (daddr_dev
== NULL
||
1073 daddr_dev
== ifa
->idev
->dev
) {
1074 score
.attrs
|= IPV6_SADDR_SCORE_OIF
;
1075 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_OIF
)) {
1080 if (hiscore
.attrs
& IPV6_SADDR_SCORE_OIF
)
1084 /* Rule 6: Prefer matching label */
1085 if (hiscore
.rule
< 6) {
1086 if (ipv6_saddr_label(&ifa_result
->addr
, hiscore
.addr_type
) == daddr_label
)
1087 hiscore
.attrs
|= IPV6_SADDR_SCORE_LABEL
;
1090 if (ipv6_saddr_label(&ifa
->addr
, score
.addr_type
) == daddr_label
) {
1091 score
.attrs
|= IPV6_SADDR_SCORE_LABEL
;
1092 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_LABEL
)) {
1097 if (hiscore
.attrs
& IPV6_SADDR_SCORE_LABEL
)
1101 #ifdef CONFIG_IPV6_PRIVACY
1102 /* Rule 7: Prefer public address
1103 * Note: prefer temprary address if use_tempaddr >= 2
1105 if (hiscore
.rule
< 7) {
1106 if ((!(ifa_result
->flags
& IFA_F_TEMPORARY
)) ^
1107 (ifa_result
->idev
->cnf
.use_tempaddr
>= 2))
1108 hiscore
.attrs
|= IPV6_SADDR_SCORE_PRIVACY
;
1111 if ((!(ifa
->flags
& IFA_F_TEMPORARY
)) ^
1112 (ifa
->idev
->cnf
.use_tempaddr
>= 2)) {
1113 score
.attrs
|= IPV6_SADDR_SCORE_PRIVACY
;
1114 if (!(hiscore
.attrs
& IPV6_SADDR_SCORE_PRIVACY
)) {
1119 if (hiscore
.attrs
& IPV6_SADDR_SCORE_PRIVACY
)
1123 if (hiscore
.rule
< 7)
1126 /* Rule 8: Use longest matching prefix */
1127 if (hiscore
.rule
< 8) {
1128 hiscore
.matchlen
= ipv6_addr_diff(&ifa_result
->addr
, daddr
);
1131 score
.matchlen
= ipv6_addr_diff(&ifa
->addr
, daddr
);
1132 if (score
.matchlen
> hiscore
.matchlen
) {
1137 else if (score
.matchlen
< hiscore
.matchlen
)
1141 /* Final Rule: choose first available one */
1145 in6_ifa_put(ifa_result
);
1150 read_unlock_bh(&idev
->lock
);
1153 read_unlock(&dev_base_lock
);
1156 return -EADDRNOTAVAIL
;
1158 ipv6_addr_copy(saddr
, &ifa_result
->addr
);
1159 in6_ifa_put(ifa_result
);
1164 int ipv6_get_saddr(struct dst_entry
*dst
,
1165 struct in6_addr
*daddr
, struct in6_addr
*saddr
)
1167 return ipv6_dev_get_saddr(dst
? ((struct rt6_info
*)dst
)->rt6i_idev
->dev
: NULL
, daddr
, saddr
);
1171 int ipv6_get_lladdr(struct net_device
*dev
, struct in6_addr
*addr
)
1173 struct inet6_dev
*idev
;
1174 int err
= -EADDRNOTAVAIL
;
1177 if ((idev
= __in6_dev_get(dev
)) != NULL
) {
1178 struct inet6_ifaddr
*ifp
;
1180 read_lock_bh(&idev
->lock
);
1181 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1182 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1183 ipv6_addr_copy(addr
, &ifp
->addr
);
1188 read_unlock_bh(&idev
->lock
);
1194 static int ipv6_count_addresses(struct inet6_dev
*idev
)
1197 struct inet6_ifaddr
*ifp
;
1199 read_lock_bh(&idev
->lock
);
1200 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
)
1202 read_unlock_bh(&idev
->lock
);
1206 int ipv6_chk_addr(struct in6_addr
*addr
, struct net_device
*dev
, int strict
)
1208 struct inet6_ifaddr
* ifp
;
1209 u8 hash
= ipv6_addr_hash(addr
);
1211 read_lock_bh(&addrconf_hash_lock
);
1212 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1213 if (ipv6_addr_equal(&ifp
->addr
, addr
) &&
1214 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1215 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1216 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
))
1220 read_unlock_bh(&addrconf_hash_lock
);
1225 int ipv6_chk_same_addr(const struct in6_addr
*addr
, struct net_device
*dev
)
1227 struct inet6_ifaddr
* ifp
;
1228 u8 hash
= ipv6_addr_hash(addr
);
1230 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1231 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1232 if (dev
== NULL
|| ifp
->idev
->dev
== dev
)
1239 struct inet6_ifaddr
* ipv6_get_ifaddr(struct in6_addr
*addr
, struct net_device
*dev
, int strict
)
1241 struct inet6_ifaddr
* ifp
;
1242 u8 hash
= ipv6_addr_hash(addr
);
1244 read_lock_bh(&addrconf_hash_lock
);
1245 for(ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
=ifp
->lst_next
) {
1246 if (ipv6_addr_equal(&ifp
->addr
, addr
)) {
1247 if (dev
== NULL
|| ifp
->idev
->dev
== dev
||
1248 !(ifp
->scope
&(IFA_LINK
|IFA_HOST
) || strict
)) {
1254 read_unlock_bh(&addrconf_hash_lock
);
1259 int ipv6_rcv_saddr_equal(const struct sock
*sk
, const struct sock
*sk2
)
1261 const struct in6_addr
*sk_rcv_saddr6
= &inet6_sk(sk
)->rcv_saddr
;
1262 const struct in6_addr
*sk2_rcv_saddr6
= inet6_rcv_saddr(sk2
);
1263 __be32 sk_rcv_saddr
= inet_sk(sk
)->rcv_saddr
;
1264 __be32 sk2_rcv_saddr
= inet_rcv_saddr(sk2
);
1265 int sk_ipv6only
= ipv6_only_sock(sk
);
1266 int sk2_ipv6only
= inet_v6_ipv6only(sk2
);
1267 int addr_type
= ipv6_addr_type(sk_rcv_saddr6
);
1268 int addr_type2
= sk2_rcv_saddr6
? ipv6_addr_type(sk2_rcv_saddr6
) : IPV6_ADDR_MAPPED
;
1270 if (!sk2_rcv_saddr
&& !sk_ipv6only
)
1273 if (addr_type2
== IPV6_ADDR_ANY
&&
1274 !(sk2_ipv6only
&& addr_type
== IPV6_ADDR_MAPPED
))
1277 if (addr_type
== IPV6_ADDR_ANY
&&
1278 !(sk_ipv6only
&& addr_type2
== IPV6_ADDR_MAPPED
))
1281 if (sk2_rcv_saddr6
&&
1282 ipv6_addr_equal(sk_rcv_saddr6
, sk2_rcv_saddr6
))
1285 if (addr_type
== IPV6_ADDR_MAPPED
&&
1287 (!sk2_rcv_saddr
|| !sk_rcv_saddr
|| sk_rcv_saddr
== sk2_rcv_saddr
))
1293 /* Gets referenced address, destroys ifaddr */
1295 static void addrconf_dad_stop(struct inet6_ifaddr
*ifp
)
1297 if (ifp
->flags
&IFA_F_PERMANENT
) {
1298 spin_lock_bh(&ifp
->lock
);
1299 addrconf_del_timer(ifp
);
1300 ifp
->flags
|= IFA_F_TENTATIVE
;
1301 spin_unlock_bh(&ifp
->lock
);
1303 #ifdef CONFIG_IPV6_PRIVACY
1304 } else if (ifp
->flags
&IFA_F_TEMPORARY
) {
1305 struct inet6_ifaddr
*ifpub
;
1306 spin_lock_bh(&ifp
->lock
);
1309 in6_ifa_hold(ifpub
);
1310 spin_unlock_bh(&ifp
->lock
);
1311 ipv6_create_tempaddr(ifpub
, ifp
);
1314 spin_unlock_bh(&ifp
->lock
);
1322 void addrconf_dad_failure(struct inet6_ifaddr
*ifp
)
1324 if (net_ratelimit())
1325 printk(KERN_INFO
"%s: duplicate address detected!\n", ifp
->idev
->dev
->name
);
1326 addrconf_dad_stop(ifp
);
1329 /* Join to solicited addr multicast group. */
1331 void addrconf_join_solict(struct net_device
*dev
, struct in6_addr
*addr
)
1333 struct in6_addr maddr
;
1335 if (dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1338 addrconf_addr_solict_mult(addr
, &maddr
);
1339 ipv6_dev_mc_inc(dev
, &maddr
);
1342 void addrconf_leave_solict(struct inet6_dev
*idev
, struct in6_addr
*addr
)
1344 struct in6_addr maddr
;
1346 if (idev
->dev
->flags
&(IFF_LOOPBACK
|IFF_NOARP
))
1349 addrconf_addr_solict_mult(addr
, &maddr
);
1350 __ipv6_dev_mc_dec(idev
, &maddr
);
1353 static void addrconf_join_anycast(struct inet6_ifaddr
*ifp
)
1355 struct in6_addr addr
;
1356 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1357 if (ipv6_addr_any(&addr
))
1359 ipv6_dev_ac_inc(ifp
->idev
->dev
, &addr
);
1362 static void addrconf_leave_anycast(struct inet6_ifaddr
*ifp
)
1364 struct in6_addr addr
;
1365 ipv6_addr_prefix(&addr
, &ifp
->addr
, ifp
->prefix_len
);
1366 if (ipv6_addr_any(&addr
))
1368 __ipv6_dev_ac_dec(ifp
->idev
, &addr
);
1371 static int addrconf_ifid_eui48(u8
*eui
, struct net_device
*dev
)
1373 if (dev
->addr_len
!= ETH_ALEN
)
1375 memcpy(eui
, dev
->dev_addr
, 3);
1376 memcpy(eui
+ 5, dev
->dev_addr
+ 3, 3);
1379 * The zSeries OSA network cards can be shared among various
1380 * OS instances, but the OSA cards have only one MAC address.
1381 * This leads to duplicate address conflicts in conjunction
1382 * with IPv6 if more than one instance uses the same card.
1384 * The driver for these cards can deliver a unique 16-bit
1385 * identifier for each instance sharing the same card. It is
1386 * placed instead of 0xFFFE in the interface identifier. The
1387 * "u" bit of the interface identifier is not inverted in this
1388 * case. Hence the resulting interface identifier has local
1389 * scope according to RFC2373.
1392 eui
[3] = (dev
->dev_id
>> 8) & 0xFF;
1393 eui
[4] = dev
->dev_id
& 0xFF;
1402 static int addrconf_ifid_arcnet(u8
*eui
, struct net_device
*dev
)
1404 /* XXX: inherit EUI-64 from other interface -- yoshfuji */
1405 if (dev
->addr_len
!= ARCNET_ALEN
)
1408 eui
[7] = *(u8
*)dev
->dev_addr
;
1412 static int addrconf_ifid_infiniband(u8
*eui
, struct net_device
*dev
)
1414 if (dev
->addr_len
!= INFINIBAND_ALEN
)
1416 memcpy(eui
, dev
->dev_addr
+ 12, 8);
1421 static int ipv6_generate_eui64(u8
*eui
, struct net_device
*dev
)
1423 switch (dev
->type
) {
1426 case ARPHRD_IEEE802_TR
:
1427 return addrconf_ifid_eui48(eui
, dev
);
1429 return addrconf_ifid_arcnet(eui
, dev
);
1430 case ARPHRD_INFINIBAND
:
1431 return addrconf_ifid_infiniband(eui
, dev
);
1436 static int ipv6_inherit_eui64(u8
*eui
, struct inet6_dev
*idev
)
1439 struct inet6_ifaddr
*ifp
;
1441 read_lock_bh(&idev
->lock
);
1442 for (ifp
=idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1443 if (ifp
->scope
== IFA_LINK
&& !(ifp
->flags
&IFA_F_TENTATIVE
)) {
1444 memcpy(eui
, ifp
->addr
.s6_addr
+8, 8);
1449 read_unlock_bh(&idev
->lock
);
1453 #ifdef CONFIG_IPV6_PRIVACY
1454 /* (re)generation of randomized interface identifier (RFC 3041 3.2, 3.5) */
1455 static int __ipv6_regen_rndid(struct inet6_dev
*idev
)
1458 get_random_bytes(idev
->rndid
, sizeof(idev
->rndid
));
1459 idev
->rndid
[0] &= ~0x02;
1462 * <draft-ietf-ipngwg-temp-addresses-v2-00.txt>:
1463 * check if generated address is not inappropriate
1465 * - Reserved subnet anycast (RFC 2526)
1466 * 11111101 11....11 1xxxxxxx
1467 * - ISATAP (draft-ietf-ngtrans-isatap-13.txt) 5.1
1468 * 00-00-5E-FE-xx-xx-xx-xx
1470 * - XXX: already assigned to an address on the device
1472 if (idev
->rndid
[0] == 0xfd &&
1473 (idev
->rndid
[1]&idev
->rndid
[2]&idev
->rndid
[3]&idev
->rndid
[4]&idev
->rndid
[5]&idev
->rndid
[6]) == 0xff &&
1474 (idev
->rndid
[7]&0x80))
1476 if ((idev
->rndid
[0]|idev
->rndid
[1]) == 0) {
1477 if (idev
->rndid
[2] == 0x5e && idev
->rndid
[3] == 0xfe)
1479 if ((idev
->rndid
[2]|idev
->rndid
[3]|idev
->rndid
[4]|idev
->rndid
[5]|idev
->rndid
[6]|idev
->rndid
[7]) == 0x00)
1486 static void ipv6_regen_rndid(unsigned long data
)
1488 struct inet6_dev
*idev
= (struct inet6_dev
*) data
;
1489 unsigned long expires
;
1492 write_lock_bh(&idev
->lock
);
1497 if (__ipv6_regen_rndid(idev
) < 0)
1501 idev
->cnf
.temp_prefered_lft
* HZ
-
1502 idev
->cnf
.regen_max_retry
* idev
->cnf
.dad_transmits
* idev
->nd_parms
->retrans_time
- desync_factor
;
1503 if (time_before(expires
, jiffies
)) {
1505 "ipv6_regen_rndid(): too short regeneration interval; timer disabled for %s.\n",
1510 if (!mod_timer(&idev
->regen_timer
, expires
))
1514 write_unlock_bh(&idev
->lock
);
1515 rcu_read_unlock_bh();
1519 static int __ipv6_try_regen_rndid(struct inet6_dev
*idev
, struct in6_addr
*tmpaddr
) {
1522 if (tmpaddr
&& memcmp(idev
->rndid
, &tmpaddr
->s6_addr
[8], 8) == 0)
1523 ret
= __ipv6_regen_rndid(idev
);
1533 addrconf_prefix_route(struct in6_addr
*pfx
, int plen
, struct net_device
*dev
,
1534 unsigned long expires
, u32 flags
)
1536 struct fib6_config cfg
= {
1537 .fc_table
= RT6_TABLE_PREFIX
,
1538 .fc_metric
= IP6_RT_PRIO_ADDRCONF
,
1539 .fc_ifindex
= dev
->ifindex
,
1540 .fc_expires
= expires
,
1542 .fc_flags
= RTF_UP
| flags
,
1545 ipv6_addr_copy(&cfg
.fc_dst
, pfx
);
1547 /* Prevent useless cloning on PtP SIT.
1548 This thing is done here expecting that the whole
1549 class of non-broadcast devices need not cloning.
1551 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1552 if (dev
->type
== ARPHRD_SIT
&& (dev
->flags
& IFF_POINTOPOINT
))
1553 cfg
.fc_flags
|= RTF_NONEXTHOP
;
1556 ip6_route_add(&cfg
);
1559 /* Create "default" multicast route to the interface */
1561 static void addrconf_add_mroute(struct net_device
*dev
)
1563 struct fib6_config cfg
= {
1564 .fc_table
= RT6_TABLE_LOCAL
,
1565 .fc_metric
= IP6_RT_PRIO_ADDRCONF
,
1566 .fc_ifindex
= dev
->ifindex
,
1571 ipv6_addr_set(&cfg
.fc_dst
, htonl(0xFF000000), 0, 0, 0);
1573 ip6_route_add(&cfg
);
1576 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1577 static void sit_route_add(struct net_device
*dev
)
1579 struct fib6_config cfg
= {
1580 .fc_table
= RT6_TABLE_MAIN
,
1581 .fc_metric
= IP6_RT_PRIO_ADDRCONF
,
1582 .fc_ifindex
= dev
->ifindex
,
1584 .fc_flags
= RTF_UP
| RTF_NONEXTHOP
,
1587 /* prefix length - 96 bits "::d.d.d.d" */
1588 ip6_route_add(&cfg
);
1592 static void addrconf_add_lroute(struct net_device
*dev
)
1594 struct in6_addr addr
;
1596 ipv6_addr_set(&addr
, htonl(0xFE800000), 0, 0, 0);
1597 addrconf_prefix_route(&addr
, 64, dev
, 0, 0);
1600 static struct inet6_dev
*addrconf_add_dev(struct net_device
*dev
)
1602 struct inet6_dev
*idev
;
1606 if ((idev
= ipv6_find_idev(dev
)) == NULL
)
1609 /* Add default multicast route */
1610 addrconf_add_mroute(dev
);
1612 /* Add link local route */
1613 addrconf_add_lroute(dev
);
1617 void addrconf_prefix_rcv(struct net_device
*dev
, u8
*opt
, int len
)
1619 struct prefix_info
*pinfo
;
1623 unsigned long rt_expires
;
1624 struct inet6_dev
*in6_dev
;
1626 pinfo
= (struct prefix_info
*) opt
;
1628 if (len
< sizeof(struct prefix_info
)) {
1629 ADBG(("addrconf: prefix option too short\n"));
1634 * Validation checks ([ADDRCONF], page 19)
1637 addr_type
= ipv6_addr_type(&pinfo
->prefix
);
1639 if (addr_type
& (IPV6_ADDR_MULTICAST
|IPV6_ADDR_LINKLOCAL
))
1642 valid_lft
= ntohl(pinfo
->valid
);
1643 prefered_lft
= ntohl(pinfo
->prefered
);
1645 if (prefered_lft
> valid_lft
) {
1646 if (net_ratelimit())
1647 printk(KERN_WARNING
"addrconf: prefix option has invalid lifetime\n");
1651 in6_dev
= in6_dev_get(dev
);
1653 if (in6_dev
== NULL
) {
1654 if (net_ratelimit())
1655 printk(KERN_DEBUG
"addrconf: device %s not configured\n", dev
->name
);
1660 * Two things going on here:
1661 * 1) Add routes for on-link prefixes
1662 * 2) Configure prefixes with the auto flag set
1665 /* Avoid arithmetic overflow. Really, we could
1666 save rt_expires in seconds, likely valid_lft,
1667 but it would require division in fib gc, that it
1670 if (valid_lft
>= 0x7FFFFFFF/HZ
)
1671 rt_expires
= 0x7FFFFFFF - (0x7FFFFFFF % HZ
);
1673 rt_expires
= valid_lft
* HZ
;
1676 * We convert this (in jiffies) to clock_t later.
1677 * Avoid arithmetic overflow there as well.
1678 * Overflow can happen only if HZ < USER_HZ.
1680 if (HZ
< USER_HZ
&& rt_expires
> 0x7FFFFFFF / USER_HZ
)
1681 rt_expires
= 0x7FFFFFFF / USER_HZ
;
1683 if (pinfo
->onlink
) {
1684 struct rt6_info
*rt
;
1685 rt
= rt6_lookup(&pinfo
->prefix
, NULL
, dev
->ifindex
, 1);
1687 if (rt
&& ((rt
->rt6i_flags
& (RTF_GATEWAY
| RTF_DEFAULT
)) == 0)) {
1688 if (rt
->rt6i_flags
&RTF_EXPIRES
) {
1689 if (valid_lft
== 0) {
1693 rt
->rt6i_expires
= jiffies
+ rt_expires
;
1696 } else if (valid_lft
) {
1697 addrconf_prefix_route(&pinfo
->prefix
, pinfo
->prefix_len
,
1698 dev
, jiffies_to_clock_t(rt_expires
), RTF_ADDRCONF
|RTF_EXPIRES
|RTF_PREFIX_RT
);
1701 dst_release(&rt
->u
.dst
);
1704 /* Try to figure out our local address for this prefix */
1706 if (pinfo
->autoconf
&& in6_dev
->cnf
.autoconf
) {
1707 struct inet6_ifaddr
* ifp
;
1708 struct in6_addr addr
;
1709 int create
= 0, update_lft
= 0;
1711 if (pinfo
->prefix_len
== 64) {
1712 memcpy(&addr
, &pinfo
->prefix
, 8);
1713 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) &&
1714 ipv6_inherit_eui64(addr
.s6_addr
+ 8, in6_dev
)) {
1715 in6_dev_put(in6_dev
);
1720 if (net_ratelimit())
1721 printk(KERN_DEBUG
"IPv6 addrconf: prefix with wrong length %d\n",
1723 in6_dev_put(in6_dev
);
1728 ifp
= ipv6_get_ifaddr(&addr
, dev
, 1);
1730 if (ifp
== NULL
&& valid_lft
) {
1731 int max_addresses
= in6_dev
->cnf
.max_addresses
;
1733 /* Do not allow to create too much of autoconfigured
1734 * addresses; this would be too easy way to crash kernel.
1736 if (!max_addresses
||
1737 ipv6_count_addresses(in6_dev
) < max_addresses
)
1738 ifp
= ipv6_add_addr(in6_dev
, &addr
, pinfo
->prefix_len
,
1739 addr_type
&IPV6_ADDR_SCOPE_MASK
, 0);
1741 if (!ifp
|| IS_ERR(ifp
)) {
1742 in6_dev_put(in6_dev
);
1746 update_lft
= create
= 1;
1747 ifp
->cstamp
= jiffies
;
1748 addrconf_dad_start(ifp
, RTF_ADDRCONF
|RTF_PREFIX_RT
);
1754 #ifdef CONFIG_IPV6_PRIVACY
1755 struct inet6_ifaddr
*ift
;
1759 /* update lifetime (RFC2462 5.5.3 e) */
1760 spin_lock(&ifp
->lock
);
1762 if (ifp
->valid_lft
> (now
- ifp
->tstamp
) / HZ
)
1763 stored_lft
= ifp
->valid_lft
- (now
- ifp
->tstamp
) / HZ
;
1766 if (!update_lft
&& stored_lft
) {
1767 if (valid_lft
> MIN_VALID_LIFETIME
||
1768 valid_lft
> stored_lft
)
1770 else if (stored_lft
<= MIN_VALID_LIFETIME
) {
1771 /* valid_lft <= stored_lft is always true */
1775 valid_lft
= MIN_VALID_LIFETIME
;
1776 if (valid_lft
< prefered_lft
)
1777 prefered_lft
= valid_lft
;
1783 ifp
->valid_lft
= valid_lft
;
1784 ifp
->prefered_lft
= prefered_lft
;
1787 ifp
->flags
&= ~IFA_F_DEPRECATED
;
1788 spin_unlock(&ifp
->lock
);
1790 if (!(flags
&IFA_F_TENTATIVE
))
1791 ipv6_ifa_notify(0, ifp
);
1793 spin_unlock(&ifp
->lock
);
1795 #ifdef CONFIG_IPV6_PRIVACY
1796 read_lock_bh(&in6_dev
->lock
);
1797 /* update all temporary addresses in the list */
1798 for (ift
=in6_dev
->tempaddr_list
; ift
; ift
=ift
->tmp_next
) {
1800 * When adjusting the lifetimes of an existing
1801 * temporary address, only lower the lifetimes.
1802 * Implementations must not increase the
1803 * lifetimes of an existing temporary address
1804 * when processing a Prefix Information Option.
1806 spin_lock(&ift
->lock
);
1808 if (ift
->valid_lft
> valid_lft
&&
1809 ift
->valid_lft
- valid_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1810 ift
->valid_lft
= valid_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1811 if (ift
->prefered_lft
> prefered_lft
&&
1812 ift
->prefered_lft
- prefered_lft
> (jiffies
- ift
->tstamp
) / HZ
)
1813 ift
->prefered_lft
= prefered_lft
+ (jiffies
- ift
->tstamp
) / HZ
;
1814 spin_unlock(&ift
->lock
);
1815 if (!(flags
&IFA_F_TENTATIVE
))
1816 ipv6_ifa_notify(0, ift
);
1819 if (create
&& in6_dev
->cnf
.use_tempaddr
> 0) {
1821 * When a new public address is created as described in [ADDRCONF],
1822 * also create a new temporary address.
1824 read_unlock_bh(&in6_dev
->lock
);
1825 ipv6_create_tempaddr(ifp
, NULL
);
1827 read_unlock_bh(&in6_dev
->lock
);
1834 inet6_prefix_notify(RTM_NEWPREFIX
, in6_dev
, pinfo
);
1835 in6_dev_put(in6_dev
);
1839 * Set destination address.
1840 * Special case for SIT interfaces where we create a new "virtual"
1843 int addrconf_set_dstaddr(void __user
*arg
)
1845 struct in6_ifreq ireq
;
1846 struct net_device
*dev
;
1852 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1855 dev
= __dev_get_by_index(ireq
.ifr6_ifindex
);
1861 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
1862 if (dev
->type
== ARPHRD_SIT
) {
1865 struct ip_tunnel_parm p
;
1867 err
= -EADDRNOTAVAIL
;
1868 if (!(ipv6_addr_type(&ireq
.ifr6_addr
) & IPV6_ADDR_COMPATv4
))
1871 memset(&p
, 0, sizeof(p
));
1872 p
.iph
.daddr
= ireq
.ifr6_addr
.s6_addr32
[3];
1876 p
.iph
.protocol
= IPPROTO_IPV6
;
1878 ifr
.ifr_ifru
.ifru_data
= (void __user
*)&p
;
1880 oldfs
= get_fs(); set_fs(KERNEL_DS
);
1881 err
= dev
->do_ioctl(dev
, &ifr
, SIOCADDTUNNEL
);
1886 if ((dev
= __dev_get_by_name(p
.name
)) == NULL
)
1888 err
= dev_open(dev
);
1899 * Manual configuration of address on an interface
1901 static int inet6_addr_add(int ifindex
, struct in6_addr
*pfx
, int plen
,
1902 __u8 ifa_flags
, __u32 prefered_lft
, __u32 valid_lft
)
1904 struct inet6_ifaddr
*ifp
;
1905 struct inet6_dev
*idev
;
1906 struct net_device
*dev
;
1911 /* check the lifetime */
1912 if (!valid_lft
|| prefered_lft
> valid_lft
)
1915 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
1918 if ((idev
= addrconf_add_dev(dev
)) == NULL
)
1921 scope
= ipv6_addr_scope(pfx
);
1923 if (valid_lft
== INFINITY_LIFE_TIME
)
1924 ifa_flags
|= IFA_F_PERMANENT
;
1925 else if (valid_lft
>= 0x7FFFFFFF/HZ
)
1926 valid_lft
= 0x7FFFFFFF/HZ
;
1928 if (prefered_lft
== 0)
1929 ifa_flags
|= IFA_F_DEPRECATED
;
1930 else if ((prefered_lft
>= 0x7FFFFFFF/HZ
) &&
1931 (prefered_lft
!= INFINITY_LIFE_TIME
))
1932 prefered_lft
= 0x7FFFFFFF/HZ
;
1934 ifp
= ipv6_add_addr(idev
, pfx
, plen
, scope
, ifa_flags
);
1937 spin_lock_bh(&ifp
->lock
);
1938 ifp
->valid_lft
= valid_lft
;
1939 ifp
->prefered_lft
= prefered_lft
;
1940 ifp
->tstamp
= jiffies
;
1941 spin_unlock_bh(&ifp
->lock
);
1943 addrconf_dad_start(ifp
, 0);
1949 return PTR_ERR(ifp
);
1952 static int inet6_addr_del(int ifindex
, struct in6_addr
*pfx
, int plen
)
1954 struct inet6_ifaddr
*ifp
;
1955 struct inet6_dev
*idev
;
1956 struct net_device
*dev
;
1958 if ((dev
= __dev_get_by_index(ifindex
)) == NULL
)
1961 if ((idev
= __in6_dev_get(dev
)) == NULL
)
1964 read_lock_bh(&idev
->lock
);
1965 for (ifp
= idev
->addr_list
; ifp
; ifp
=ifp
->if_next
) {
1966 if (ifp
->prefix_len
== plen
&&
1967 ipv6_addr_equal(pfx
, &ifp
->addr
)) {
1969 read_unlock_bh(&idev
->lock
);
1973 /* If the last address is deleted administratively,
1974 disable IPv6 on this interface.
1976 if (idev
->addr_list
== NULL
)
1977 addrconf_ifdown(idev
->dev
, 1);
1981 read_unlock_bh(&idev
->lock
);
1982 return -EADDRNOTAVAIL
;
1986 int addrconf_add_ifaddr(void __user
*arg
)
1988 struct in6_ifreq ireq
;
1991 if (!capable(CAP_NET_ADMIN
))
1994 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
1998 err
= inet6_addr_add(ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
, ireq
.ifr6_prefixlen
,
1999 IFA_F_PERMANENT
, INFINITY_LIFE_TIME
, INFINITY_LIFE_TIME
);
2004 int addrconf_del_ifaddr(void __user
*arg
)
2006 struct in6_ifreq ireq
;
2009 if (!capable(CAP_NET_ADMIN
))
2012 if (copy_from_user(&ireq
, arg
, sizeof(struct in6_ifreq
)))
2016 err
= inet6_addr_del(ireq
.ifr6_ifindex
, &ireq
.ifr6_addr
, ireq
.ifr6_prefixlen
);
2021 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2022 static void sit_add_v4_addrs(struct inet6_dev
*idev
)
2024 struct inet6_ifaddr
* ifp
;
2025 struct in6_addr addr
;
2026 struct net_device
*dev
;
2031 memset(&addr
, 0, sizeof(struct in6_addr
));
2032 memcpy(&addr
.s6_addr32
[3], idev
->dev
->dev_addr
, 4);
2034 if (idev
->dev
->flags
&IFF_POINTOPOINT
) {
2035 addr
.s6_addr32
[0] = htonl(0xfe800000);
2038 scope
= IPV6_ADDR_COMPATv4
;
2041 if (addr
.s6_addr32
[3]) {
2042 ifp
= ipv6_add_addr(idev
, &addr
, 128, scope
, IFA_F_PERMANENT
);
2044 spin_lock_bh(&ifp
->lock
);
2045 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2046 spin_unlock_bh(&ifp
->lock
);
2047 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2053 for (dev
= dev_base
; dev
!= NULL
; dev
= dev
->next
) {
2054 struct in_device
* in_dev
= __in_dev_get_rtnl(dev
);
2055 if (in_dev
&& (dev
->flags
& IFF_UP
)) {
2056 struct in_ifaddr
* ifa
;
2060 for (ifa
= in_dev
->ifa_list
; ifa
; ifa
= ifa
->ifa_next
) {
2063 addr
.s6_addr32
[3] = ifa
->ifa_local
;
2065 if (ifa
->ifa_scope
== RT_SCOPE_LINK
)
2067 if (ifa
->ifa_scope
>= RT_SCOPE_HOST
) {
2068 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2072 if (idev
->dev
->flags
&IFF_POINTOPOINT
)
2077 ifp
= ipv6_add_addr(idev
, &addr
, plen
, flag
,
2080 spin_lock_bh(&ifp
->lock
);
2081 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2082 spin_unlock_bh(&ifp
->lock
);
2083 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2092 static void init_loopback(struct net_device
*dev
)
2094 struct inet6_dev
*idev
;
2095 struct inet6_ifaddr
* ifp
;
2101 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2102 printk(KERN_DEBUG
"init loopback: add_dev failed\n");
2106 ifp
= ipv6_add_addr(idev
, &in6addr_loopback
, 128, IFA_HOST
, IFA_F_PERMANENT
);
2108 spin_lock_bh(&ifp
->lock
);
2109 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2110 spin_unlock_bh(&ifp
->lock
);
2111 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2116 static void addrconf_add_linklocal(struct inet6_dev
*idev
, struct in6_addr
*addr
)
2118 struct inet6_ifaddr
* ifp
;
2120 ifp
= ipv6_add_addr(idev
, addr
, 64, IFA_LINK
, IFA_F_PERMANENT
);
2122 addrconf_dad_start(ifp
, 0);
2127 static void addrconf_dev_config(struct net_device
*dev
)
2129 struct in6_addr addr
;
2130 struct inet6_dev
* idev
;
2134 if ((dev
->type
!= ARPHRD_ETHER
) &&
2135 (dev
->type
!= ARPHRD_FDDI
) &&
2136 (dev
->type
!= ARPHRD_IEEE802_TR
) &&
2137 (dev
->type
!= ARPHRD_ARCNET
) &&
2138 (dev
->type
!= ARPHRD_INFINIBAND
)) {
2139 /* Alas, we support only Ethernet autoconfiguration. */
2143 idev
= addrconf_add_dev(dev
);
2147 memset(&addr
, 0, sizeof(struct in6_addr
));
2148 addr
.s6_addr32
[0] = htonl(0xFE800000);
2150 if (ipv6_generate_eui64(addr
.s6_addr
+ 8, dev
) == 0)
2151 addrconf_add_linklocal(idev
, &addr
);
2154 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2155 static void addrconf_sit_config(struct net_device
*dev
)
2157 struct inet6_dev
*idev
;
2162 * Configure the tunnel with one of our IPv4
2163 * addresses... we should configure all of
2164 * our v4 addrs in the tunnel
2167 if ((idev
= ipv6_find_idev(dev
)) == NULL
) {
2168 printk(KERN_DEBUG
"init sit: add_dev failed\n");
2172 sit_add_v4_addrs(idev
);
2174 if (dev
->flags
&IFF_POINTOPOINT
) {
2175 addrconf_add_mroute(dev
);
2176 addrconf_add_lroute(dev
);
2183 ipv6_inherit_linklocal(struct inet6_dev
*idev
, struct net_device
*link_dev
)
2185 struct in6_addr lladdr
;
2187 if (!ipv6_get_lladdr(link_dev
, &lladdr
)) {
2188 addrconf_add_linklocal(idev
, &lladdr
);
2194 static void ip6_tnl_add_linklocal(struct inet6_dev
*idev
)
2196 struct net_device
*link_dev
;
2198 /* first try to inherit the link-local address from the link device */
2199 if (idev
->dev
->iflink
&&
2200 (link_dev
= __dev_get_by_index(idev
->dev
->iflink
))) {
2201 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2204 /* then try to inherit it from any device */
2205 for (link_dev
= dev_base
; link_dev
; link_dev
= link_dev
->next
) {
2206 if (!ipv6_inherit_linklocal(idev
, link_dev
))
2209 printk(KERN_DEBUG
"init ip6-ip6: add_linklocal failed\n");
2213 * Autoconfigure tunnel with a link-local address so routing protocols,
2214 * DHCPv6, MLD etc. can be run over the virtual link
2217 static void addrconf_ip6_tnl_config(struct net_device
*dev
)
2219 struct inet6_dev
*idev
;
2223 if ((idev
= addrconf_add_dev(dev
)) == NULL
) {
2224 printk(KERN_DEBUG
"init ip6-ip6: add_dev failed\n");
2227 ip6_tnl_add_linklocal(idev
);
2230 static int addrconf_notify(struct notifier_block
*this, unsigned long event
,
2233 struct net_device
*dev
= (struct net_device
*) data
;
2234 struct inet6_dev
*idev
= __in6_dev_get(dev
);
2235 int run_pending
= 0;
2240 if (event
== NETDEV_UP
) {
2241 if (!netif_carrier_ok(dev
)) {
2242 /* device is not ready yet. */
2244 "ADDRCONF(NETDEV_UP): %s: "
2245 "link is not ready\n",
2251 idev
->if_flags
|= IF_READY
;
2253 if (!netif_carrier_ok(dev
)) {
2254 /* device is still not ready. */
2259 if (idev
->if_flags
& IF_READY
) {
2260 /* device is already configured. */
2263 idev
->if_flags
|= IF_READY
;
2267 "ADDRCONF(NETDEV_CHANGE): %s: "
2268 "link becomes ready\n",
2275 #if defined(CONFIG_IPV6_SIT) || defined(CONFIG_IPV6_SIT_MODULE)
2277 addrconf_sit_config(dev
);
2280 case ARPHRD_TUNNEL6
:
2281 addrconf_ip6_tnl_config(dev
);
2283 case ARPHRD_LOOPBACK
:
2288 addrconf_dev_config(dev
);
2293 addrconf_dad_run(idev
);
2295 /* If the MTU changed during the interface down, when the
2296 interface up, the changed MTU must be reflected in the
2297 idev as well as routers.
2299 if (idev
->cnf
.mtu6
!= dev
->mtu
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2300 rt6_mtu_change(dev
, dev
->mtu
);
2301 idev
->cnf
.mtu6
= dev
->mtu
;
2303 idev
->tstamp
= jiffies
;
2304 inet6_ifinfo_notify(RTM_NEWLINK
, idev
);
2305 /* If the changed mtu during down is lower than IPV6_MIN_MTU
2306 stop IPv6 on this interface.
2308 if (dev
->mtu
< IPV6_MIN_MTU
)
2309 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2313 case NETDEV_CHANGEMTU
:
2314 if ( idev
&& dev
->mtu
>= IPV6_MIN_MTU
) {
2315 rt6_mtu_change(dev
, dev
->mtu
);
2316 idev
->cnf
.mtu6
= dev
->mtu
;
2320 /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */
2323 case NETDEV_UNREGISTER
:
2325 * Remove all addresses from this interface.
2327 addrconf_ifdown(dev
, event
!= NETDEV_DOWN
);
2330 case NETDEV_CHANGENAME
:
2331 #ifdef CONFIG_SYSCTL
2333 addrconf_sysctl_unregister(&idev
->cnf
);
2334 neigh_sysctl_unregister(idev
->nd_parms
);
2335 neigh_sysctl_register(dev
, idev
->nd_parms
,
2336 NET_IPV6
, NET_IPV6_NEIGH
, "ipv6",
2337 &ndisc_ifinfo_sysctl_change
,
2339 addrconf_sysctl_register(idev
, &idev
->cnf
);
2349 * addrconf module should be notified of a device going up
2351 static struct notifier_block ipv6_dev_notf
= {
2352 .notifier_call
= addrconf_notify
,
2356 static int addrconf_ifdown(struct net_device
*dev
, int how
)
2358 struct inet6_dev
*idev
;
2359 struct inet6_ifaddr
*ifa
, **bifa
;
2364 if (dev
== &loopback_dev
&& how
== 1)
2368 neigh_ifdown(&nd_tbl
, dev
);
2370 idev
= __in6_dev_get(dev
);
2374 /* Step 1: remove reference to ipv6 device from parent device.
2380 /* protected by rtnl_lock */
2381 rcu_assign_pointer(dev
->ip6_ptr
, NULL
);
2383 /* Step 1.5: remove snmp6 entry */
2384 snmp6_unregister_dev(idev
);
2388 /* Step 2: clear hash table */
2389 for (i
=0; i
<IN6_ADDR_HSIZE
; i
++) {
2390 bifa
= &inet6_addr_lst
[i
];
2392 write_lock_bh(&addrconf_hash_lock
);
2393 while ((ifa
= *bifa
) != NULL
) {
2394 if (ifa
->idev
== idev
) {
2395 *bifa
= ifa
->lst_next
;
2396 ifa
->lst_next
= NULL
;
2397 addrconf_del_timer(ifa
);
2401 bifa
= &ifa
->lst_next
;
2403 write_unlock_bh(&addrconf_hash_lock
);
2406 write_lock_bh(&idev
->lock
);
2408 /* Step 3: clear flags for stateless addrconf */
2410 idev
->if_flags
&= ~(IF_RS_SENT
|IF_RA_RCVD
|IF_READY
);
2412 /* Step 4: clear address list */
2413 #ifdef CONFIG_IPV6_PRIVACY
2414 if (how
== 1 && del_timer(&idev
->regen_timer
))
2417 /* clear tempaddr list */
2418 while ((ifa
= idev
->tempaddr_list
) != NULL
) {
2419 idev
->tempaddr_list
= ifa
->tmp_next
;
2420 ifa
->tmp_next
= NULL
;
2422 write_unlock_bh(&idev
->lock
);
2423 spin_lock_bh(&ifa
->lock
);
2426 in6_ifa_put(ifa
->ifpub
);
2429 spin_unlock_bh(&ifa
->lock
);
2431 write_lock_bh(&idev
->lock
);
2434 while ((ifa
= idev
->addr_list
) != NULL
) {
2435 idev
->addr_list
= ifa
->if_next
;
2436 ifa
->if_next
= NULL
;
2438 addrconf_del_timer(ifa
);
2439 write_unlock_bh(&idev
->lock
);
2441 __ipv6_ifa_notify(RTM_DELADDR
, ifa
);
2444 write_lock_bh(&idev
->lock
);
2446 write_unlock_bh(&idev
->lock
);
2448 /* Step 5: Discard multicast list */
2451 ipv6_mc_destroy_dev(idev
);
2455 /* Step 5: netlink notification of this interface */
2456 idev
->tstamp
= jiffies
;
2457 inet6_ifinfo_notify(RTM_DELLINK
, idev
);
2459 /* Shot the device (if unregistered) */
2462 #ifdef CONFIG_SYSCTL
2463 addrconf_sysctl_unregister(&idev
->cnf
);
2464 neigh_sysctl_unregister(idev
->nd_parms
);
2466 neigh_parms_release(&nd_tbl
, idev
->nd_parms
);
2467 neigh_ifdown(&nd_tbl
, dev
);
2473 static void addrconf_rs_timer(unsigned long data
)
2475 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2477 if (ifp
->idev
->cnf
.forwarding
)
2480 if (ifp
->idev
->if_flags
& IF_RA_RCVD
) {
2482 * Announcement received after solicitation
2488 spin_lock(&ifp
->lock
);
2489 if (ifp
->probes
++ < ifp
->idev
->cnf
.rtr_solicits
) {
2490 struct in6_addr all_routers
;
2492 /* The wait after the last probe can be shorter */
2493 addrconf_mod_timer(ifp
, AC_RS
,
2494 (ifp
->probes
== ifp
->idev
->cnf
.rtr_solicits
) ?
2495 ifp
->idev
->cnf
.rtr_solicit_delay
:
2496 ifp
->idev
->cnf
.rtr_solicit_interval
);
2497 spin_unlock(&ifp
->lock
);
2499 ipv6_addr_all_routers(&all_routers
);
2501 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &all_routers
);
2503 spin_unlock(&ifp
->lock
);
2505 * Note: we do not support deprecated "all on-link"
2506 * assumption any longer.
2508 printk(KERN_DEBUG
"%s: no IPv6 routers present\n",
2509 ifp
->idev
->dev
->name
);
2517 * Duplicate Address Detection
2519 static void addrconf_dad_kick(struct inet6_ifaddr
*ifp
)
2521 unsigned long rand_num
;
2522 struct inet6_dev
*idev
= ifp
->idev
;
2524 rand_num
= net_random() % (idev
->cnf
.rtr_solicit_delay
? : 1);
2525 ifp
->probes
= idev
->cnf
.dad_transmits
;
2526 addrconf_mod_timer(ifp
, AC_DAD
, rand_num
);
2529 static void addrconf_dad_start(struct inet6_ifaddr
*ifp
, u32 flags
)
2531 struct inet6_dev
*idev
= ifp
->idev
;
2532 struct net_device
*dev
= idev
->dev
;
2534 addrconf_join_solict(dev
, &ifp
->addr
);
2536 if (ifp
->prefix_len
!= 128 && (ifp
->flags
&IFA_F_PERMANENT
))
2537 addrconf_prefix_route(&ifp
->addr
, ifp
->prefix_len
, dev
, 0,
2540 net_srandom(ifp
->addr
.s6_addr32
[3]);
2542 read_lock_bh(&idev
->lock
);
2545 spin_lock_bh(&ifp
->lock
);
2547 if (dev
->flags
&(IFF_NOARP
|IFF_LOOPBACK
) ||
2548 !(ifp
->flags
&IFA_F_TENTATIVE
) ||
2549 ifp
->flags
& IFA_F_NODAD
) {
2550 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2551 spin_unlock_bh(&ifp
->lock
);
2552 read_unlock_bh(&idev
->lock
);
2554 addrconf_dad_completed(ifp
);
2558 if (!(idev
->if_flags
& IF_READY
)) {
2559 spin_unlock_bh(&ifp
->lock
);
2560 read_unlock_bh(&idev
->lock
);
2562 * If the defice is not ready:
2563 * - keep it tentative if it is a permanent address.
2564 * - otherwise, kill it.
2567 addrconf_dad_stop(ifp
);
2570 addrconf_dad_kick(ifp
);
2571 spin_unlock_bh(&ifp
->lock
);
2573 read_unlock_bh(&idev
->lock
);
2576 static void addrconf_dad_timer(unsigned long data
)
2578 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*) data
;
2579 struct inet6_dev
*idev
= ifp
->idev
;
2580 struct in6_addr unspec
;
2581 struct in6_addr mcaddr
;
2583 read_lock_bh(&idev
->lock
);
2585 read_unlock_bh(&idev
->lock
);
2588 spin_lock_bh(&ifp
->lock
);
2589 if (ifp
->probes
== 0) {
2591 * DAD was successful
2594 ifp
->flags
&= ~IFA_F_TENTATIVE
;
2595 spin_unlock_bh(&ifp
->lock
);
2596 read_unlock_bh(&idev
->lock
);
2598 addrconf_dad_completed(ifp
);
2604 addrconf_mod_timer(ifp
, AC_DAD
, ifp
->idev
->nd_parms
->retrans_time
);
2605 spin_unlock_bh(&ifp
->lock
);
2606 read_unlock_bh(&idev
->lock
);
2608 /* send a neighbour solicitation for our addr */
2609 memset(&unspec
, 0, sizeof(unspec
));
2610 addrconf_addr_solict_mult(&ifp
->addr
, &mcaddr
);
2611 ndisc_send_ns(ifp
->idev
->dev
, NULL
, &ifp
->addr
, &mcaddr
, &unspec
);
2616 static void addrconf_dad_completed(struct inet6_ifaddr
*ifp
)
2618 struct net_device
* dev
= ifp
->idev
->dev
;
2621 * Configure the address for reception. Now it is valid.
2624 ipv6_ifa_notify(RTM_NEWADDR
, ifp
);
2626 /* If added prefix is link local and forwarding is off,
2627 start sending router solicitations.
2630 if (ifp
->idev
->cnf
.forwarding
== 0 &&
2631 ifp
->idev
->cnf
.rtr_solicits
> 0 &&
2632 (dev
->flags
&IFF_LOOPBACK
) == 0 &&
2633 (ipv6_addr_type(&ifp
->addr
) & IPV6_ADDR_LINKLOCAL
)) {
2634 struct in6_addr all_routers
;
2636 ipv6_addr_all_routers(&all_routers
);
2639 * If a host as already performed a random delay
2640 * [...] as part of DAD [...] there is no need
2641 * to delay again before sending the first RS
2643 ndisc_send_rs(ifp
->idev
->dev
, &ifp
->addr
, &all_routers
);
2645 spin_lock_bh(&ifp
->lock
);
2647 ifp
->idev
->if_flags
|= IF_RS_SENT
;
2648 addrconf_mod_timer(ifp
, AC_RS
, ifp
->idev
->cnf
.rtr_solicit_interval
);
2649 spin_unlock_bh(&ifp
->lock
);
2653 static void addrconf_dad_run(struct inet6_dev
*idev
) {
2654 struct inet6_ifaddr
*ifp
;
2656 read_lock_bh(&idev
->lock
);
2657 for (ifp
= idev
->addr_list
; ifp
; ifp
= ifp
->if_next
) {
2658 spin_lock_bh(&ifp
->lock
);
2659 if (!(ifp
->flags
& IFA_F_TENTATIVE
)) {
2660 spin_unlock_bh(&ifp
->lock
);
2663 spin_unlock_bh(&ifp
->lock
);
2664 addrconf_dad_kick(ifp
);
2666 read_unlock_bh(&idev
->lock
);
2669 #ifdef CONFIG_PROC_FS
2670 struct if6_iter_state
{
2674 static struct inet6_ifaddr
*if6_get_first(struct seq_file
*seq
)
2676 struct inet6_ifaddr
*ifa
= NULL
;
2677 struct if6_iter_state
*state
= seq
->private;
2679 for (state
->bucket
= 0; state
->bucket
< IN6_ADDR_HSIZE
; ++state
->bucket
) {
2680 ifa
= inet6_addr_lst
[state
->bucket
];
2687 static struct inet6_ifaddr
*if6_get_next(struct seq_file
*seq
, struct inet6_ifaddr
*ifa
)
2689 struct if6_iter_state
*state
= seq
->private;
2691 ifa
= ifa
->lst_next
;
2693 if (!ifa
&& ++state
->bucket
< IN6_ADDR_HSIZE
) {
2694 ifa
= inet6_addr_lst
[state
->bucket
];
2700 static struct inet6_ifaddr
*if6_get_idx(struct seq_file
*seq
, loff_t pos
)
2702 struct inet6_ifaddr
*ifa
= if6_get_first(seq
);
2705 while(pos
&& (ifa
= if6_get_next(seq
, ifa
)) != NULL
)
2707 return pos
? NULL
: ifa
;
2710 static void *if6_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2712 read_lock_bh(&addrconf_hash_lock
);
2713 return if6_get_idx(seq
, *pos
);
2716 static void *if6_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
2718 struct inet6_ifaddr
*ifa
;
2720 ifa
= if6_get_next(seq
, v
);
2725 static void if6_seq_stop(struct seq_file
*seq
, void *v
)
2727 read_unlock_bh(&addrconf_hash_lock
);
2730 static int if6_seq_show(struct seq_file
*seq
, void *v
)
2732 struct inet6_ifaddr
*ifp
= (struct inet6_ifaddr
*)v
;
2734 NIP6_SEQFMT
" %02x %02x %02x %02x %8s\n",
2736 ifp
->idev
->dev
->ifindex
,
2740 ifp
->idev
->dev
->name
);
2744 static struct seq_operations if6_seq_ops
= {
2745 .start
= if6_seq_start
,
2746 .next
= if6_seq_next
,
2747 .show
= if6_seq_show
,
2748 .stop
= if6_seq_stop
,
2751 static int if6_seq_open(struct inode
*inode
, struct file
*file
)
2753 struct seq_file
*seq
;
2755 struct if6_iter_state
*s
= kzalloc(sizeof(*s
), GFP_KERNEL
);
2760 rc
= seq_open(file
, &if6_seq_ops
);
2764 seq
= file
->private_data
;
2773 static struct file_operations if6_fops
= {
2774 .owner
= THIS_MODULE
,
2775 .open
= if6_seq_open
,
2777 .llseek
= seq_lseek
,
2778 .release
= seq_release_private
,
2781 int __init
if6_proc_init(void)
2783 if (!proc_net_fops_create("if_inet6", S_IRUGO
, &if6_fops
))
2788 void if6_proc_exit(void)
2790 proc_net_remove("if_inet6");
2792 #endif /* CONFIG_PROC_FS */
2794 #ifdef CONFIG_IPV6_MIP6
2795 /* Check if address is a home address configured on any interface. */
2796 int ipv6_chk_home_addr(struct in6_addr
*addr
)
2799 struct inet6_ifaddr
* ifp
;
2800 u8 hash
= ipv6_addr_hash(addr
);
2801 read_lock_bh(&addrconf_hash_lock
);
2802 for (ifp
= inet6_addr_lst
[hash
]; ifp
; ifp
= ifp
->lst_next
) {
2803 if (ipv6_addr_cmp(&ifp
->addr
, addr
) == 0 &&
2804 (ifp
->flags
& IFA_F_HOMEADDRESS
)) {
2809 read_unlock_bh(&addrconf_hash_lock
);
2815 * Periodic address status verification
2818 static void addrconf_verify(unsigned long foo
)
2820 struct inet6_ifaddr
*ifp
;
2821 unsigned long now
, next
;
2824 spin_lock_bh(&addrconf_verify_lock
);
2826 next
= now
+ ADDR_CHECK_FREQUENCY
;
2828 del_timer(&addr_chk_timer
);
2830 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
2833 read_lock(&addrconf_hash_lock
);
2834 for (ifp
=inet6_addr_lst
[i
]; ifp
; ifp
=ifp
->lst_next
) {
2836 #ifdef CONFIG_IPV6_PRIVACY
2837 unsigned long regen_advance
;
2840 if (ifp
->flags
& IFA_F_PERMANENT
)
2843 spin_lock(&ifp
->lock
);
2844 age
= (now
- ifp
->tstamp
) / HZ
;
2846 #ifdef CONFIG_IPV6_PRIVACY
2847 regen_advance
= ifp
->idev
->cnf
.regen_max_retry
*
2848 ifp
->idev
->cnf
.dad_transmits
*
2849 ifp
->idev
->nd_parms
->retrans_time
/ HZ
;
2852 if (ifp
->valid_lft
!= INFINITY_LIFE_TIME
&&
2853 age
>= ifp
->valid_lft
) {
2854 spin_unlock(&ifp
->lock
);
2856 read_unlock(&addrconf_hash_lock
);
2859 } else if (ifp
->prefered_lft
== INFINITY_LIFE_TIME
) {
2860 spin_unlock(&ifp
->lock
);
2862 } else if (age
>= ifp
->prefered_lft
) {
2863 /* jiffies - ifp->tsamp > age >= ifp->prefered_lft */
2866 if (!(ifp
->flags
&IFA_F_DEPRECATED
)) {
2868 ifp
->flags
|= IFA_F_DEPRECATED
;
2871 if (time_before(ifp
->tstamp
+ ifp
->valid_lft
* HZ
, next
))
2872 next
= ifp
->tstamp
+ ifp
->valid_lft
* HZ
;
2874 spin_unlock(&ifp
->lock
);
2878 read_unlock(&addrconf_hash_lock
);
2880 ipv6_ifa_notify(0, ifp
);
2884 #ifdef CONFIG_IPV6_PRIVACY
2885 } else if ((ifp
->flags
&IFA_F_TEMPORARY
) &&
2886 !(ifp
->flags
&IFA_F_TENTATIVE
)) {
2887 if (age
>= ifp
->prefered_lft
- regen_advance
) {
2888 struct inet6_ifaddr
*ifpub
= ifp
->ifpub
;
2889 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
2890 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
2891 if (!ifp
->regen_count
&& ifpub
) {
2894 in6_ifa_hold(ifpub
);
2895 spin_unlock(&ifp
->lock
);
2896 read_unlock(&addrconf_hash_lock
);
2897 spin_lock(&ifpub
->lock
);
2898 ifpub
->regen_count
= 0;
2899 spin_unlock(&ifpub
->lock
);
2900 ipv6_create_tempaddr(ifpub
, ifp
);
2905 } else if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
, next
))
2906 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
- regen_advance
* HZ
;
2907 spin_unlock(&ifp
->lock
);
2910 /* ifp->prefered_lft <= ifp->valid_lft */
2911 if (time_before(ifp
->tstamp
+ ifp
->prefered_lft
* HZ
, next
))
2912 next
= ifp
->tstamp
+ ifp
->prefered_lft
* HZ
;
2913 spin_unlock(&ifp
->lock
);
2916 read_unlock(&addrconf_hash_lock
);
2919 addr_chk_timer
.expires
= time_before(next
, jiffies
+ HZ
) ? jiffies
+ HZ
: next
;
2920 add_timer(&addr_chk_timer
);
2921 spin_unlock_bh(&addrconf_verify_lock
);
2924 static struct in6_addr
*extract_addr(struct nlattr
*addr
, struct nlattr
*local
)
2926 struct in6_addr
*pfx
= NULL
;
2929 pfx
= nla_data(addr
);
2932 if (pfx
&& nla_memcmp(local
, pfx
, sizeof(*pfx
)))
2935 pfx
= nla_data(local
);
2941 static struct nla_policy ifa_ipv6_policy
[IFA_MAX
+1] __read_mostly
= {
2942 [IFA_ADDRESS
] = { .len
= sizeof(struct in6_addr
) },
2943 [IFA_LOCAL
] = { .len
= sizeof(struct in6_addr
) },
2944 [IFA_CACHEINFO
] = { .len
= sizeof(struct ifa_cacheinfo
) },
2948 inet6_rtm_deladdr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
2950 struct ifaddrmsg
*ifm
;
2951 struct nlattr
*tb
[IFA_MAX
+1];
2952 struct in6_addr
*pfx
;
2955 err
= nlmsg_parse(nlh
, sizeof(*ifm
), tb
, IFA_MAX
, ifa_ipv6_policy
);
2959 ifm
= nlmsg_data(nlh
);
2960 pfx
= extract_addr(tb
[IFA_ADDRESS
], tb
[IFA_LOCAL
]);
2964 return inet6_addr_del(ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
);
2967 static int inet6_addr_modify(struct inet6_ifaddr
*ifp
, u8 ifa_flags
,
2968 u32 prefered_lft
, u32 valid_lft
)
2970 if (!valid_lft
|| (prefered_lft
> valid_lft
))
2973 if (valid_lft
== INFINITY_LIFE_TIME
)
2974 ifa_flags
|= IFA_F_PERMANENT
;
2975 else if (valid_lft
>= 0x7FFFFFFF/HZ
)
2976 valid_lft
= 0x7FFFFFFF/HZ
;
2978 if (prefered_lft
== 0)
2979 ifa_flags
|= IFA_F_DEPRECATED
;
2980 else if ((prefered_lft
>= 0x7FFFFFFF/HZ
) &&
2981 (prefered_lft
!= INFINITY_LIFE_TIME
))
2982 prefered_lft
= 0x7FFFFFFF/HZ
;
2984 spin_lock_bh(&ifp
->lock
);
2985 ifp
->flags
= (ifp
->flags
& ~(IFA_F_DEPRECATED
| IFA_F_PERMANENT
| IFA_F_NODAD
| IFA_F_HOMEADDRESS
)) | ifa_flags
;
2986 ifp
->tstamp
= jiffies
;
2987 ifp
->valid_lft
= valid_lft
;
2988 ifp
->prefered_lft
= prefered_lft
;
2990 spin_unlock_bh(&ifp
->lock
);
2991 if (!(ifp
->flags
&IFA_F_TENTATIVE
))
2992 ipv6_ifa_notify(0, ifp
);
3000 inet6_rtm_newaddr(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, void *arg
)
3002 struct ifaddrmsg
*ifm
;
3003 struct nlattr
*tb
[IFA_MAX
+1];
3004 struct in6_addr
*pfx
;
3005 struct inet6_ifaddr
*ifa
;
3006 struct net_device
*dev
;
3007 u32 valid_lft
= INFINITY_LIFE_TIME
, preferred_lft
= INFINITY_LIFE_TIME
;
3011 err
= nlmsg_parse(nlh
, sizeof(*ifm
), tb
, IFA_MAX
, ifa_ipv6_policy
);
3015 ifm
= nlmsg_data(nlh
);
3016 pfx
= extract_addr(tb
[IFA_ADDRESS
], tb
[IFA_LOCAL
]);
3020 if (tb
[IFA_CACHEINFO
]) {
3021 struct ifa_cacheinfo
*ci
;
3023 ci
= nla_data(tb
[IFA_CACHEINFO
]);
3024 valid_lft
= ci
->ifa_valid
;
3025 preferred_lft
= ci
->ifa_prefered
;
3027 preferred_lft
= INFINITY_LIFE_TIME
;
3028 valid_lft
= INFINITY_LIFE_TIME
;
3031 dev
= __dev_get_by_index(ifm
->ifa_index
);
3035 /* We ignore other flags so far. */
3036 ifa_flags
= ifm
->ifa_flags
& (IFA_F_NODAD
| IFA_F_HOMEADDRESS
);
3038 ifa
= ipv6_get_ifaddr(pfx
, dev
, 1);
3041 * It would be best to check for !NLM_F_CREATE here but
3042 * userspace alreay relies on not having to provide this.
3044 return inet6_addr_add(ifm
->ifa_index
, pfx
, ifm
->ifa_prefixlen
,
3045 ifa_flags
, preferred_lft
, valid_lft
);
3048 if (nlh
->nlmsg_flags
& NLM_F_EXCL
||
3049 !(nlh
->nlmsg_flags
& NLM_F_REPLACE
))
3052 err
= inet6_addr_modify(ifa
, ifa_flags
, preferred_lft
, valid_lft
);
3059 static void put_ifaddrmsg(struct nlmsghdr
*nlh
, u8 prefixlen
, u8 flags
,
3060 u8 scope
, int ifindex
)
3062 struct ifaddrmsg
*ifm
;
3064 ifm
= nlmsg_data(nlh
);
3065 ifm
->ifa_family
= AF_INET6
;
3066 ifm
->ifa_prefixlen
= prefixlen
;
3067 ifm
->ifa_flags
= flags
;
3068 ifm
->ifa_scope
= scope
;
3069 ifm
->ifa_index
= ifindex
;
3072 static int put_cacheinfo(struct sk_buff
*skb
, unsigned long cstamp
,
3073 unsigned long tstamp
, u32 preferred
, u32 valid
)
3075 struct ifa_cacheinfo ci
;
3077 ci
.cstamp
= (u32
)(TIME_DELTA(cstamp
, INITIAL_JIFFIES
) / HZ
* 100
3078 + TIME_DELTA(cstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3079 ci
.tstamp
= (u32
)(TIME_DELTA(tstamp
, INITIAL_JIFFIES
) / HZ
* 100
3080 + TIME_DELTA(tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3081 ci
.ifa_prefered
= preferred
;
3082 ci
.ifa_valid
= valid
;
3084 return nla_put(skb
, IFA_CACHEINFO
, sizeof(ci
), &ci
);
3087 static inline int rt_scope(int ifa_scope
)
3089 if (ifa_scope
& IFA_HOST
)
3090 return RT_SCOPE_HOST
;
3091 else if (ifa_scope
& IFA_LINK
)
3092 return RT_SCOPE_LINK
;
3093 else if (ifa_scope
& IFA_SITE
)
3094 return RT_SCOPE_SITE
;
3096 return RT_SCOPE_UNIVERSE
;
3099 static inline int inet6_ifaddr_msgsize(void)
3101 return nlmsg_total_size(sizeof(struct ifaddrmsg
) +
3102 nla_total_size(16) +
3103 nla_total_size(sizeof(struct ifa_cacheinfo
)) +
3107 static int inet6_fill_ifaddr(struct sk_buff
*skb
, struct inet6_ifaddr
*ifa
,
3108 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3110 struct nlmsghdr
*nlh
;
3111 u32 preferred
, valid
;
3113 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(struct ifaddrmsg
), flags
);
3117 put_ifaddrmsg(nlh
, ifa
->prefix_len
, ifa
->flags
, rt_scope(ifa
->scope
),
3118 ifa
->idev
->dev
->ifindex
);
3120 if (!(ifa
->flags
&IFA_F_PERMANENT
)) {
3121 preferred
= ifa
->prefered_lft
;
3122 valid
= ifa
->valid_lft
;
3123 if (preferred
!= INFINITY_LIFE_TIME
) {
3124 long tval
= (jiffies
- ifa
->tstamp
)/HZ
;
3126 if (valid
!= INFINITY_LIFE_TIME
)
3130 preferred
= INFINITY_LIFE_TIME
;
3131 valid
= INFINITY_LIFE_TIME
;
3134 if (nla_put(skb
, IFA_ADDRESS
, 16, &ifa
->addr
) < 0 ||
3135 put_cacheinfo(skb
, ifa
->cstamp
, ifa
->tstamp
, preferred
, valid
) < 0)
3136 return nlmsg_cancel(skb
, nlh
);
3138 return nlmsg_end(skb
, nlh
);
3141 static int inet6_fill_ifmcaddr(struct sk_buff
*skb
, struct ifmcaddr6
*ifmca
,
3142 u32 pid
, u32 seq
, int event
, u16 flags
)
3144 struct nlmsghdr
*nlh
;
3145 u8 scope
= RT_SCOPE_UNIVERSE
;
3146 int ifindex
= ifmca
->idev
->dev
->ifindex
;
3148 if (ipv6_addr_scope(&ifmca
->mca_addr
) & IFA_SITE
)
3149 scope
= RT_SCOPE_SITE
;
3151 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(struct ifaddrmsg
), flags
);
3155 put_ifaddrmsg(nlh
, 128, IFA_F_PERMANENT
, scope
, ifindex
);
3156 if (nla_put(skb
, IFA_MULTICAST
, 16, &ifmca
->mca_addr
) < 0 ||
3157 put_cacheinfo(skb
, ifmca
->mca_cstamp
, ifmca
->mca_tstamp
,
3158 INFINITY_LIFE_TIME
, INFINITY_LIFE_TIME
) < 0)
3159 return nlmsg_cancel(skb
, nlh
);
3161 return nlmsg_end(skb
, nlh
);
3164 static int inet6_fill_ifacaddr(struct sk_buff
*skb
, struct ifacaddr6
*ifaca
,
3165 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3167 struct nlmsghdr
*nlh
;
3168 u8 scope
= RT_SCOPE_UNIVERSE
;
3169 int ifindex
= ifaca
->aca_idev
->dev
->ifindex
;
3171 if (ipv6_addr_scope(&ifaca
->aca_addr
) & IFA_SITE
)
3172 scope
= RT_SCOPE_SITE
;
3174 nlh
= nlmsg_put(skb
, pid
, seq
, event
, sizeof(struct ifaddrmsg
), flags
);
3178 put_ifaddrmsg(nlh
, 128, IFA_F_PERMANENT
, scope
, ifindex
);
3179 if (nla_put(skb
, IFA_ANYCAST
, 16, &ifaca
->aca_addr
) < 0 ||
3180 put_cacheinfo(skb
, ifaca
->aca_cstamp
, ifaca
->aca_tstamp
,
3181 INFINITY_LIFE_TIME
, INFINITY_LIFE_TIME
) < 0)
3182 return nlmsg_cancel(skb
, nlh
);
3184 return nlmsg_end(skb
, nlh
);
3194 static int inet6_dump_addr(struct sk_buff
*skb
, struct netlink_callback
*cb
,
3195 enum addr_type_t type
)
3198 int s_idx
, s_ip_idx
;
3200 struct net_device
*dev
;
3201 struct inet6_dev
*idev
= NULL
;
3202 struct inet6_ifaddr
*ifa
;
3203 struct ifmcaddr6
*ifmca
;
3204 struct ifacaddr6
*ifaca
;
3206 s_idx
= cb
->args
[0];
3207 s_ip_idx
= ip_idx
= cb
->args
[1];
3208 read_lock(&dev_base_lock
);
3210 for (dev
= dev_base
, idx
= 0; dev
; dev
= dev
->next
, idx
++) {
3216 if ((idev
= in6_dev_get(dev
)) == NULL
)
3218 read_lock_bh(&idev
->lock
);
3221 /* unicast address incl. temp addr */
3222 for (ifa
= idev
->addr_list
; ifa
;
3223 ifa
= ifa
->if_next
, ip_idx
++) {
3224 if (ip_idx
< s_ip_idx
)
3226 if ((err
= inet6_fill_ifaddr(skb
, ifa
,
3227 NETLINK_CB(cb
->skb
).pid
,
3228 cb
->nlh
->nlmsg_seq
, RTM_NEWADDR
,
3233 case MULTICAST_ADDR
:
3234 /* multicast address */
3235 for (ifmca
= idev
->mc_list
; ifmca
;
3236 ifmca
= ifmca
->next
, ip_idx
++) {
3237 if (ip_idx
< s_ip_idx
)
3239 if ((err
= inet6_fill_ifmcaddr(skb
, ifmca
,
3240 NETLINK_CB(cb
->skb
).pid
,
3241 cb
->nlh
->nlmsg_seq
, RTM_GETMULTICAST
,
3247 /* anycast address */
3248 for (ifaca
= idev
->ac_list
; ifaca
;
3249 ifaca
= ifaca
->aca_next
, ip_idx
++) {
3250 if (ip_idx
< s_ip_idx
)
3252 if ((err
= inet6_fill_ifacaddr(skb
, ifaca
,
3253 NETLINK_CB(cb
->skb
).pid
,
3254 cb
->nlh
->nlmsg_seq
, RTM_GETANYCAST
,
3262 read_unlock_bh(&idev
->lock
);
3267 read_unlock_bh(&idev
->lock
);
3270 read_unlock(&dev_base_lock
);
3272 cb
->args
[1] = ip_idx
;
3276 static int inet6_dump_ifaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3278 enum addr_type_t type
= UNICAST_ADDR
;
3279 return inet6_dump_addr(skb
, cb
, type
);
3282 static int inet6_dump_ifmcaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3284 enum addr_type_t type
= MULTICAST_ADDR
;
3285 return inet6_dump_addr(skb
, cb
, type
);
3289 static int inet6_dump_ifacaddr(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3291 enum addr_type_t type
= ANYCAST_ADDR
;
3292 return inet6_dump_addr(skb
, cb
, type
);
3295 static int inet6_rtm_getaddr(struct sk_buff
*in_skb
, struct nlmsghdr
* nlh
,
3298 struct ifaddrmsg
*ifm
;
3299 struct nlattr
*tb
[IFA_MAX
+1];
3300 struct in6_addr
*addr
= NULL
;
3301 struct net_device
*dev
= NULL
;
3302 struct inet6_ifaddr
*ifa
;
3303 struct sk_buff
*skb
;
3306 err
= nlmsg_parse(nlh
, sizeof(*ifm
), tb
, IFA_MAX
, ifa_ipv6_policy
);
3310 addr
= extract_addr(tb
[IFA_ADDRESS
], tb
[IFA_LOCAL
]);
3316 ifm
= nlmsg_data(nlh
);
3318 dev
= __dev_get_by_index(ifm
->ifa_index
);
3320 if ((ifa
= ipv6_get_ifaddr(addr
, dev
, 1)) == NULL
) {
3321 err
= -EADDRNOTAVAIL
;
3325 if ((skb
= nlmsg_new(inet6_ifaddr_msgsize(), GFP_KERNEL
)) == NULL
) {
3330 err
= inet6_fill_ifaddr(skb
, ifa
, NETLINK_CB(in_skb
).pid
,
3331 nlh
->nlmsg_seq
, RTM_NEWADDR
, 0);
3337 err
= rtnl_unicast(skb
, NETLINK_CB(in_skb
).pid
);
3344 static void inet6_ifa_notify(int event
, struct inet6_ifaddr
*ifa
)
3346 struct sk_buff
*skb
;
3349 skb
= nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC
);
3353 err
= inet6_fill_ifaddr(skb
, ifa
, 0, 0, event
, 0);
3359 err
= rtnl_notify(skb
, 0, RTNLGRP_IPV6_IFADDR
, NULL
, GFP_ATOMIC
);
3362 rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR
, err
);
3365 static void inline ipv6_store_devconf(struct ipv6_devconf
*cnf
,
3366 __s32
*array
, int bytes
)
3368 memset(array
, 0, bytes
);
3369 array
[DEVCONF_FORWARDING
] = cnf
->forwarding
;
3370 array
[DEVCONF_HOPLIMIT
] = cnf
->hop_limit
;
3371 array
[DEVCONF_MTU6
] = cnf
->mtu6
;
3372 array
[DEVCONF_ACCEPT_RA
] = cnf
->accept_ra
;
3373 array
[DEVCONF_ACCEPT_REDIRECTS
] = cnf
->accept_redirects
;
3374 array
[DEVCONF_AUTOCONF
] = cnf
->autoconf
;
3375 array
[DEVCONF_DAD_TRANSMITS
] = cnf
->dad_transmits
;
3376 array
[DEVCONF_RTR_SOLICITS
] = cnf
->rtr_solicits
;
3377 array
[DEVCONF_RTR_SOLICIT_INTERVAL
] = cnf
->rtr_solicit_interval
;
3378 array
[DEVCONF_RTR_SOLICIT_DELAY
] = cnf
->rtr_solicit_delay
;
3379 array
[DEVCONF_FORCE_MLD_VERSION
] = cnf
->force_mld_version
;
3380 #ifdef CONFIG_IPV6_PRIVACY
3381 array
[DEVCONF_USE_TEMPADDR
] = cnf
->use_tempaddr
;
3382 array
[DEVCONF_TEMP_VALID_LFT
] = cnf
->temp_valid_lft
;
3383 array
[DEVCONF_TEMP_PREFERED_LFT
] = cnf
->temp_prefered_lft
;
3384 array
[DEVCONF_REGEN_MAX_RETRY
] = cnf
->regen_max_retry
;
3385 array
[DEVCONF_MAX_DESYNC_FACTOR
] = cnf
->max_desync_factor
;
3387 array
[DEVCONF_MAX_ADDRESSES
] = cnf
->max_addresses
;
3388 array
[DEVCONF_ACCEPT_RA_DEFRTR
] = cnf
->accept_ra_defrtr
;
3389 array
[DEVCONF_ACCEPT_RA_PINFO
] = cnf
->accept_ra_pinfo
;
3390 #ifdef CONFIG_IPV6_ROUTER_PREF
3391 array
[DEVCONF_ACCEPT_RA_RTR_PREF
] = cnf
->accept_ra_rtr_pref
;
3392 array
[DEVCONF_RTR_PROBE_INTERVAL
] = cnf
->rtr_probe_interval
;
3393 #ifdef CONFIV_IPV6_ROUTE_INFO
3394 array
[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN
] = cnf
->accept_ra_rt_info_max_plen
;
3397 array
[DEVCONF_PROXY_NDP
] = cnf
->proxy_ndp
;
3400 /* Maximum length of ifinfomsg attributes */
3401 #define INET6_IFINFO_RTA_SPACE \
3402 RTA_SPACE(IFNAMSIZ) /* IFNAME */ + \
3403 RTA_SPACE(MAX_ADDR_LEN) /* ADDRESS */ + \
3404 RTA_SPACE(sizeof(u32)) /* MTU */ + \
3405 RTA_SPACE(sizeof(int)) /* LINK */ + \
3406 RTA_SPACE(0) /* PROTINFO */ + \
3407 RTA_SPACE(sizeof(u32)) /* FLAGS */ + \
3408 RTA_SPACE(sizeof(struct ifla_cacheinfo)) /* CACHEINFO */ + \
3409 RTA_SPACE(sizeof(__s32[DEVCONF_MAX])) /* CONF */
3411 static int inet6_fill_ifinfo(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3412 u32 pid
, u32 seq
, int event
, unsigned int flags
)
3414 struct net_device
*dev
= idev
->dev
;
3415 __s32
*array
= NULL
;
3416 struct ifinfomsg
*r
;
3417 struct nlmsghdr
*nlh
;
3418 unsigned char *b
= skb
->tail
;
3419 struct rtattr
*subattr
;
3420 __u32 mtu
= dev
->mtu
;
3421 struct ifla_cacheinfo ci
;
3423 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*r
), flags
);
3424 r
= NLMSG_DATA(nlh
);
3425 r
->ifi_family
= AF_INET6
;
3427 r
->ifi_type
= dev
->type
;
3428 r
->ifi_index
= dev
->ifindex
;
3429 r
->ifi_flags
= dev_get_flags(dev
);
3432 RTA_PUT(skb
, IFLA_IFNAME
, strlen(dev
->name
)+1, dev
->name
);
3435 RTA_PUT(skb
, IFLA_ADDRESS
, dev
->addr_len
, dev
->dev_addr
);
3437 RTA_PUT(skb
, IFLA_MTU
, sizeof(mtu
), &mtu
);
3438 if (dev
->ifindex
!= dev
->iflink
)
3439 RTA_PUT(skb
, IFLA_LINK
, sizeof(int), &dev
->iflink
);
3441 subattr
= (struct rtattr
*)skb
->tail
;
3443 RTA_PUT(skb
, IFLA_PROTINFO
, 0, NULL
);
3445 /* return the device flags */
3446 RTA_PUT(skb
, IFLA_INET6_FLAGS
, sizeof(__u32
), &idev
->if_flags
);
3448 /* return interface cacheinfo */
3449 ci
.max_reasm_len
= IPV6_MAXPLEN
;
3450 ci
.tstamp
= (__u32
)(TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) / HZ
* 100
3451 + TIME_DELTA(idev
->tstamp
, INITIAL_JIFFIES
) % HZ
* 100 / HZ
);
3452 ci
.reachable_time
= idev
->nd_parms
->reachable_time
;
3453 ci
.retrans_time
= idev
->nd_parms
->retrans_time
;
3454 RTA_PUT(skb
, IFLA_INET6_CACHEINFO
, sizeof(ci
), &ci
);
3456 /* return the device sysctl params */
3457 if ((array
= kmalloc(DEVCONF_MAX
* sizeof(*array
), GFP_ATOMIC
)) == NULL
)
3458 goto rtattr_failure
;
3459 ipv6_store_devconf(&idev
->cnf
, array
, DEVCONF_MAX
* sizeof(*array
));
3460 RTA_PUT(skb
, IFLA_INET6_CONF
, DEVCONF_MAX
* sizeof(*array
), array
);
3462 /* XXX - Statistics/MC not implemented */
3463 subattr
->rta_len
= skb
->tail
- (u8
*)subattr
;
3465 nlh
->nlmsg_len
= skb
->tail
- b
;
3472 skb_trim(skb
, b
- skb
->data
);
3476 static int inet6_dump_ifinfo(struct sk_buff
*skb
, struct netlink_callback
*cb
)
3479 int s_idx
= cb
->args
[0];
3480 struct net_device
*dev
;
3481 struct inet6_dev
*idev
;
3483 read_lock(&dev_base_lock
);
3484 for (dev
=dev_base
, idx
=0; dev
; dev
= dev
->next
, idx
++) {
3487 if ((idev
= in6_dev_get(dev
)) == NULL
)
3489 err
= inet6_fill_ifinfo(skb
, idev
, NETLINK_CB(cb
->skb
).pid
,
3490 cb
->nlh
->nlmsg_seq
, RTM_NEWLINK
, NLM_F_MULTI
);
3495 read_unlock(&dev_base_lock
);
3501 void inet6_ifinfo_notify(int event
, struct inet6_dev
*idev
)
3503 struct sk_buff
*skb
;
3504 int payload
= sizeof(struct ifinfomsg
) + INET6_IFINFO_RTA_SPACE
;
3507 skb
= nlmsg_new(nlmsg_total_size(payload
), GFP_ATOMIC
);
3511 err
= inet6_fill_ifinfo(skb
, idev
, 0, 0, event
, 0);
3517 err
= rtnl_notify(skb
, 0, RTNLGRP_IPV6_IFADDR
, NULL
, GFP_ATOMIC
);
3520 rtnl_set_sk_err(RTNLGRP_IPV6_IFADDR
, err
);
3523 /* Maximum length of prefix_cacheinfo attributes */
3524 #define INET6_PREFIX_RTA_SPACE \
3525 RTA_SPACE(sizeof(((struct prefix_info *)NULL)->prefix)) /* ADDRESS */ + \
3526 RTA_SPACE(sizeof(struct prefix_cacheinfo)) /* CACHEINFO */
3528 static int inet6_fill_prefix(struct sk_buff
*skb
, struct inet6_dev
*idev
,
3529 struct prefix_info
*pinfo
, u32 pid
, u32 seq
,
3530 int event
, unsigned int flags
)
3532 struct prefixmsg
*pmsg
;
3533 struct nlmsghdr
*nlh
;
3534 unsigned char *b
= skb
->tail
;
3535 struct prefix_cacheinfo ci
;
3537 nlh
= NLMSG_NEW(skb
, pid
, seq
, event
, sizeof(*pmsg
), flags
);
3538 pmsg
= NLMSG_DATA(nlh
);
3539 pmsg
->prefix_family
= AF_INET6
;
3540 pmsg
->prefix_pad1
= 0;
3541 pmsg
->prefix_pad2
= 0;
3542 pmsg
->prefix_ifindex
= idev
->dev
->ifindex
;
3543 pmsg
->prefix_len
= pinfo
->prefix_len
;
3544 pmsg
->prefix_type
= pinfo
->type
;
3545 pmsg
->prefix_pad3
= 0;
3547 pmsg
->prefix_flags
= 0;
3549 pmsg
->prefix_flags
|= IF_PREFIX_ONLINK
;
3550 if (pinfo
->autoconf
)
3551 pmsg
->prefix_flags
|= IF_PREFIX_AUTOCONF
;
3553 RTA_PUT(skb
, PREFIX_ADDRESS
, sizeof(pinfo
->prefix
), &pinfo
->prefix
);
3555 ci
.preferred_time
= ntohl(pinfo
->prefered
);
3556 ci
.valid_time
= ntohl(pinfo
->valid
);
3557 RTA_PUT(skb
, PREFIX_CACHEINFO
, sizeof(ci
), &ci
);
3559 nlh
->nlmsg_len
= skb
->tail
- b
;
3564 skb_trim(skb
, b
- skb
->data
);
3568 static void inet6_prefix_notify(int event
, struct inet6_dev
*idev
,
3569 struct prefix_info
*pinfo
)
3571 struct sk_buff
*skb
;
3572 int payload
= sizeof(struct prefixmsg
) + INET6_PREFIX_RTA_SPACE
;
3575 skb
= nlmsg_new(nlmsg_total_size(payload
), GFP_ATOMIC
);
3579 err
= inet6_fill_prefix(skb
, idev
, pinfo
, 0, 0, event
, 0);
3585 err
= rtnl_notify(skb
, 0, RTNLGRP_IPV6_PREFIX
, NULL
, GFP_ATOMIC
);
3588 rtnl_set_sk_err(RTNLGRP_IPV6_PREFIX
, err
);
3591 static struct rtnetlink_link inet6_rtnetlink_table
[RTM_NR_MSGTYPES
] = {
3592 [RTM_GETLINK
- RTM_BASE
] = { .dumpit
= inet6_dump_ifinfo
, },
3593 [RTM_NEWADDR
- RTM_BASE
] = { .doit
= inet6_rtm_newaddr
, },
3594 [RTM_DELADDR
- RTM_BASE
] = { .doit
= inet6_rtm_deladdr
, },
3595 [RTM_GETADDR
- RTM_BASE
] = { .doit
= inet6_rtm_getaddr
,
3596 .dumpit
= inet6_dump_ifaddr
, },
3597 [RTM_GETMULTICAST
- RTM_BASE
] = { .dumpit
= inet6_dump_ifmcaddr
, },
3598 [RTM_GETANYCAST
- RTM_BASE
] = { .dumpit
= inet6_dump_ifacaddr
, },
3599 [RTM_NEWROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_newroute
, },
3600 [RTM_DELROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_delroute
, },
3601 [RTM_GETROUTE
- RTM_BASE
] = { .doit
= inet6_rtm_getroute
,
3602 .dumpit
= inet6_dump_fib
, },
3603 #ifdef CONFIG_IPV6_MULTIPLE_TABLES
3604 [RTM_GETRULE
- RTM_BASE
] = { .dumpit
= fib6_rules_dump
, },
3608 static void __ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3610 inet6_ifa_notify(event
? : RTM_NEWADDR
, ifp
);
3614 ip6_ins_rt(ifp
->rt
);
3615 if (ifp
->idev
->cnf
.forwarding
)
3616 addrconf_join_anycast(ifp
);
3619 if (ifp
->idev
->cnf
.forwarding
)
3620 addrconf_leave_anycast(ifp
);
3621 addrconf_leave_solict(ifp
->idev
, &ifp
->addr
);
3622 dst_hold(&ifp
->rt
->u
.dst
);
3623 if (ip6_del_rt(ifp
->rt
))
3624 dst_free(&ifp
->rt
->u
.dst
);
3629 static void ipv6_ifa_notify(int event
, struct inet6_ifaddr
*ifp
)
3632 if (likely(ifp
->idev
->dead
== 0))
3633 __ipv6_ifa_notify(event
, ifp
);
3634 rcu_read_unlock_bh();
3637 #ifdef CONFIG_SYSCTL
3640 int addrconf_sysctl_forward(ctl_table
*ctl
, int write
, struct file
* filp
,
3641 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
3643 int *valp
= ctl
->data
;
3647 ret
= proc_dointvec(ctl
, write
, filp
, buffer
, lenp
, ppos
);
3649 if (write
&& valp
!= &ipv6_devconf_dflt
.forwarding
) {
3650 if (valp
!= &ipv6_devconf
.forwarding
) {
3651 if ((!*valp
) ^ (!val
)) {
3652 struct inet6_dev
*idev
= (struct inet6_dev
*)ctl
->extra1
;
3655 dev_forward_change(idev
);
3658 ipv6_devconf_dflt
.forwarding
= ipv6_devconf
.forwarding
;
3659 addrconf_forward_change();
3662 rt6_purge_dflt_routers();
3668 static int addrconf_sysctl_forward_strategy(ctl_table
*table
,
3669 int __user
*name
, int nlen
,
3670 void __user
*oldval
,
3671 size_t __user
*oldlenp
,
3672 void __user
*newval
, size_t newlen
,
3675 int *valp
= table
->data
;
3678 if (!newval
|| !newlen
)
3680 if (newlen
!= sizeof(int))
3682 if (get_user(new, (int __user
*)newval
))
3686 if (oldval
&& oldlenp
) {
3688 if (get_user(len
, oldlenp
))
3691 if (len
> table
->maxlen
)
3692 len
= table
->maxlen
;
3693 if (copy_to_user(oldval
, valp
, len
))
3695 if (put_user(len
, oldlenp
))
3700 if (valp
!= &ipv6_devconf_dflt
.forwarding
) {
3701 if (valp
!= &ipv6_devconf
.forwarding
) {
3702 struct inet6_dev
*idev
= (struct inet6_dev
*)table
->extra1
;
3704 if (unlikely(idev
== NULL
))
3706 changed
= (!*valp
) ^ (!new);
3709 dev_forward_change(idev
);
3712 addrconf_forward_change();
3716 rt6_purge_dflt_routers();
3723 static struct addrconf_sysctl_table
3725 struct ctl_table_header
*sysctl_header
;
3726 ctl_table addrconf_vars
[__NET_IPV6_MAX
];
3727 ctl_table addrconf_dev
[2];
3728 ctl_table addrconf_conf_dir
[2];
3729 ctl_table addrconf_proto_dir
[2];
3730 ctl_table addrconf_root_dir
[2];
3731 } addrconf_sysctl __read_mostly
= {
3732 .sysctl_header
= NULL
,
3735 .ctl_name
= NET_IPV6_FORWARDING
,
3736 .procname
= "forwarding",
3737 .data
= &ipv6_devconf
.forwarding
,
3738 .maxlen
= sizeof(int),
3740 .proc_handler
= &addrconf_sysctl_forward
,
3741 .strategy
= &addrconf_sysctl_forward_strategy
,
3744 .ctl_name
= NET_IPV6_HOP_LIMIT
,
3745 .procname
= "hop_limit",
3746 .data
= &ipv6_devconf
.hop_limit
,
3747 .maxlen
= sizeof(int),
3749 .proc_handler
= proc_dointvec
,
3752 .ctl_name
= NET_IPV6_MTU
,
3754 .data
= &ipv6_devconf
.mtu6
,
3755 .maxlen
= sizeof(int),
3757 .proc_handler
= &proc_dointvec
,
3760 .ctl_name
= NET_IPV6_ACCEPT_RA
,
3761 .procname
= "accept_ra",
3762 .data
= &ipv6_devconf
.accept_ra
,
3763 .maxlen
= sizeof(int),
3765 .proc_handler
= &proc_dointvec
,
3768 .ctl_name
= NET_IPV6_ACCEPT_REDIRECTS
,
3769 .procname
= "accept_redirects",
3770 .data
= &ipv6_devconf
.accept_redirects
,
3771 .maxlen
= sizeof(int),
3773 .proc_handler
= &proc_dointvec
,
3776 .ctl_name
= NET_IPV6_AUTOCONF
,
3777 .procname
= "autoconf",
3778 .data
= &ipv6_devconf
.autoconf
,
3779 .maxlen
= sizeof(int),
3781 .proc_handler
= &proc_dointvec
,
3784 .ctl_name
= NET_IPV6_DAD_TRANSMITS
,
3785 .procname
= "dad_transmits",
3786 .data
= &ipv6_devconf
.dad_transmits
,
3787 .maxlen
= sizeof(int),
3789 .proc_handler
= &proc_dointvec
,
3792 .ctl_name
= NET_IPV6_RTR_SOLICITS
,
3793 .procname
= "router_solicitations",
3794 .data
= &ipv6_devconf
.rtr_solicits
,
3795 .maxlen
= sizeof(int),
3797 .proc_handler
= &proc_dointvec
,
3800 .ctl_name
= NET_IPV6_RTR_SOLICIT_INTERVAL
,
3801 .procname
= "router_solicitation_interval",
3802 .data
= &ipv6_devconf
.rtr_solicit_interval
,
3803 .maxlen
= sizeof(int),
3805 .proc_handler
= &proc_dointvec_jiffies
,
3806 .strategy
= &sysctl_jiffies
,
3809 .ctl_name
= NET_IPV6_RTR_SOLICIT_DELAY
,
3810 .procname
= "router_solicitation_delay",
3811 .data
= &ipv6_devconf
.rtr_solicit_delay
,
3812 .maxlen
= sizeof(int),
3814 .proc_handler
= &proc_dointvec_jiffies
,
3815 .strategy
= &sysctl_jiffies
,
3818 .ctl_name
= NET_IPV6_FORCE_MLD_VERSION
,
3819 .procname
= "force_mld_version",
3820 .data
= &ipv6_devconf
.force_mld_version
,
3821 .maxlen
= sizeof(int),
3823 .proc_handler
= &proc_dointvec
,
3825 #ifdef CONFIG_IPV6_PRIVACY
3827 .ctl_name
= NET_IPV6_USE_TEMPADDR
,
3828 .procname
= "use_tempaddr",
3829 .data
= &ipv6_devconf
.use_tempaddr
,
3830 .maxlen
= sizeof(int),
3832 .proc_handler
= &proc_dointvec
,
3835 .ctl_name
= NET_IPV6_TEMP_VALID_LFT
,
3836 .procname
= "temp_valid_lft",
3837 .data
= &ipv6_devconf
.temp_valid_lft
,
3838 .maxlen
= sizeof(int),
3840 .proc_handler
= &proc_dointvec
,
3843 .ctl_name
= NET_IPV6_TEMP_PREFERED_LFT
,
3844 .procname
= "temp_prefered_lft",
3845 .data
= &ipv6_devconf
.temp_prefered_lft
,
3846 .maxlen
= sizeof(int),
3848 .proc_handler
= &proc_dointvec
,
3851 .ctl_name
= NET_IPV6_REGEN_MAX_RETRY
,
3852 .procname
= "regen_max_retry",
3853 .data
= &ipv6_devconf
.regen_max_retry
,
3854 .maxlen
= sizeof(int),
3856 .proc_handler
= &proc_dointvec
,
3859 .ctl_name
= NET_IPV6_MAX_DESYNC_FACTOR
,
3860 .procname
= "max_desync_factor",
3861 .data
= &ipv6_devconf
.max_desync_factor
,
3862 .maxlen
= sizeof(int),
3864 .proc_handler
= &proc_dointvec
,
3868 .ctl_name
= NET_IPV6_MAX_ADDRESSES
,
3869 .procname
= "max_addresses",
3870 .data
= &ipv6_devconf
.max_addresses
,
3871 .maxlen
= sizeof(int),
3873 .proc_handler
= &proc_dointvec
,
3876 .ctl_name
= NET_IPV6_ACCEPT_RA_DEFRTR
,
3877 .procname
= "accept_ra_defrtr",
3878 .data
= &ipv6_devconf
.accept_ra_defrtr
,
3879 .maxlen
= sizeof(int),
3881 .proc_handler
= &proc_dointvec
,
3884 .ctl_name
= NET_IPV6_ACCEPT_RA_PINFO
,
3885 .procname
= "accept_ra_pinfo",
3886 .data
= &ipv6_devconf
.accept_ra_pinfo
,
3887 .maxlen
= sizeof(int),
3889 .proc_handler
= &proc_dointvec
,
3891 #ifdef CONFIG_IPV6_ROUTER_PREF
3893 .ctl_name
= NET_IPV6_ACCEPT_RA_RTR_PREF
,
3894 .procname
= "accept_ra_rtr_pref",
3895 .data
= &ipv6_devconf
.accept_ra_rtr_pref
,
3896 .maxlen
= sizeof(int),
3898 .proc_handler
= &proc_dointvec
,
3901 .ctl_name
= NET_IPV6_RTR_PROBE_INTERVAL
,
3902 .procname
= "router_probe_interval",
3903 .data
= &ipv6_devconf
.rtr_probe_interval
,
3904 .maxlen
= sizeof(int),
3906 .proc_handler
= &proc_dointvec_jiffies
,
3907 .strategy
= &sysctl_jiffies
,
3909 #ifdef CONFIV_IPV6_ROUTE_INFO
3911 .ctl_name
= NET_IPV6_ACCEPT_RA_RT_INFO_MAX_PLEN
,
3912 .procname
= "accept_ra_rt_info_max_plen",
3913 .data
= &ipv6_devconf
.accept_ra_rt_info_max_plen
,
3914 .maxlen
= sizeof(int),
3916 .proc_handler
= &proc_dointvec
,
3921 .ctl_name
= NET_IPV6_PROXY_NDP
,
3922 .procname
= "proxy_ndp",
3923 .data
= &ipv6_devconf
.proxy_ndp
,
3924 .maxlen
= sizeof(int),
3926 .proc_handler
= &proc_dointvec
,
3929 .ctl_name
= 0, /* sentinel */
3934 .ctl_name
= NET_PROTO_CONF_ALL
,
3937 .child
= addrconf_sysctl
.addrconf_vars
,
3940 .ctl_name
= 0, /* sentinel */
3943 .addrconf_conf_dir
= {
3945 .ctl_name
= NET_IPV6_CONF
,
3948 .child
= addrconf_sysctl
.addrconf_dev
,
3951 .ctl_name
= 0, /* sentinel */
3954 .addrconf_proto_dir
= {
3956 .ctl_name
= NET_IPV6
,
3959 .child
= addrconf_sysctl
.addrconf_conf_dir
,
3962 .ctl_name
= 0, /* sentinel */
3965 .addrconf_root_dir
= {
3967 .ctl_name
= CTL_NET
,
3970 .child
= addrconf_sysctl
.addrconf_proto_dir
,
3973 .ctl_name
= 0, /* sentinel */
3978 static void addrconf_sysctl_register(struct inet6_dev
*idev
, struct ipv6_devconf
*p
)
3981 struct net_device
*dev
= idev
? idev
->dev
: NULL
;
3982 struct addrconf_sysctl_table
*t
;
3983 char *dev_name
= NULL
;
3985 t
= kmalloc(sizeof(*t
), GFP_KERNEL
);
3988 memcpy(t
, &addrconf_sysctl
, sizeof(*t
));
3989 for (i
=0; t
->addrconf_vars
[i
].data
; i
++) {
3990 t
->addrconf_vars
[i
].data
+= (char*)p
- (char*)&ipv6_devconf
;
3991 t
->addrconf_vars
[i
].de
= NULL
;
3992 t
->addrconf_vars
[i
].extra1
= idev
; /* embedded; no ref */
3995 dev_name
= dev
->name
;
3996 t
->addrconf_dev
[0].ctl_name
= dev
->ifindex
;
3998 dev_name
= "default";
3999 t
->addrconf_dev
[0].ctl_name
= NET_PROTO_CONF_DEFAULT
;
4003 * Make a copy of dev_name, because '.procname' is regarded as const
4004 * by sysctl and we wouldn't want anyone to change it under our feet
4005 * (see SIOCSIFNAME).
4007 dev_name
= kstrdup(dev_name
, GFP_KERNEL
);
4011 t
->addrconf_dev
[0].procname
= dev_name
;
4013 t
->addrconf_dev
[0].child
= t
->addrconf_vars
;
4014 t
->addrconf_dev
[0].de
= NULL
;
4015 t
->addrconf_conf_dir
[0].child
= t
->addrconf_dev
;
4016 t
->addrconf_conf_dir
[0].de
= NULL
;
4017 t
->addrconf_proto_dir
[0].child
= t
->addrconf_conf_dir
;
4018 t
->addrconf_proto_dir
[0].de
= NULL
;
4019 t
->addrconf_root_dir
[0].child
= t
->addrconf_proto_dir
;
4020 t
->addrconf_root_dir
[0].de
= NULL
;
4022 t
->sysctl_header
= register_sysctl_table(t
->addrconf_root_dir
, 0);
4023 if (t
->sysctl_header
== NULL
)
4038 static void addrconf_sysctl_unregister(struct ipv6_devconf
*p
)
4041 struct addrconf_sysctl_table
*t
= p
->sysctl
;
4043 unregister_sysctl_table(t
->sysctl_header
);
4044 kfree(t
->addrconf_dev
[0].procname
);
4056 int register_inet6addr_notifier(struct notifier_block
*nb
)
4058 return atomic_notifier_chain_register(&inet6addr_chain
, nb
);
4061 int unregister_inet6addr_notifier(struct notifier_block
*nb
)
4063 return atomic_notifier_chain_unregister(&inet6addr_chain
,nb
);
4067 * Init / cleanup code
4070 int __init
addrconf_init(void)
4074 /* The addrconf netdev notifier requires that loopback_dev
4075 * has it's ipv6 private information allocated and setup
4076 * before it can bring up and give link-local addresses
4077 * to other devices which are up.
4079 * Unfortunately, loopback_dev is not necessarily the first
4080 * entry in the global dev_base list of net devices. In fact,
4081 * it is likely to be the very last entry on that list.
4082 * So this causes the notifier registry below to try and
4083 * give link-local addresses to all devices besides loopback_dev
4084 * first, then loopback_dev, which cases all the non-loopback_dev
4085 * devices to fail to get a link-local address.
4087 * So, as a temporary fix, allocate the ipv6 structure for
4088 * loopback_dev first by hand.
4089 * Longer term, all of the dependencies ipv6 has upon the loopback
4090 * device and it being up should be removed.
4093 if (!ipv6_add_dev(&loopback_dev
))
4099 ip6_null_entry
.rt6i_idev
= in6_dev_get(&loopback_dev
);
4101 register_netdevice_notifier(&ipv6_dev_notf
);
4104 rtnetlink_links
[PF_INET6
] = inet6_rtnetlink_table
;
4105 #ifdef CONFIG_SYSCTL
4106 addrconf_sysctl
.sysctl_header
=
4107 register_sysctl_table(addrconf_sysctl
.addrconf_root_dir
, 0);
4108 addrconf_sysctl_register(NULL
, &ipv6_devconf_dflt
);
4114 void __exit
addrconf_cleanup(void)
4116 struct net_device
*dev
;
4117 struct inet6_dev
*idev
;
4118 struct inet6_ifaddr
*ifa
;
4121 unregister_netdevice_notifier(&ipv6_dev_notf
);
4123 rtnetlink_links
[PF_INET6
] = NULL
;
4124 #ifdef CONFIG_SYSCTL
4125 addrconf_sysctl_unregister(&ipv6_devconf_dflt
);
4126 addrconf_sysctl_unregister(&ipv6_devconf
);
4135 for (dev
=dev_base
; dev
; dev
=dev
->next
) {
4136 if ((idev
= __in6_dev_get(dev
)) == NULL
)
4138 addrconf_ifdown(dev
, 1);
4140 addrconf_ifdown(&loopback_dev
, 2);
4146 write_lock_bh(&addrconf_hash_lock
);
4147 for (i
=0; i
< IN6_ADDR_HSIZE
; i
++) {
4148 for (ifa
=inet6_addr_lst
[i
]; ifa
; ) {
4149 struct inet6_ifaddr
*bifa
;
4152 ifa
= ifa
->lst_next
;
4153 printk(KERN_DEBUG
"bug: IPv6 address leakage detected: ifa=%p\n", bifa
);
4154 /* Do not free it; something is wrong.
4155 Now we can investigate it with debugger.
4159 write_unlock_bh(&addrconf_hash_lock
);
4161 del_timer(&addr_chk_timer
);
4165 #ifdef CONFIG_PROC_FS
4166 proc_net_remove("if_inet6");