File: /usr/src/linux/net/ipv6/addrconf.c
1 /*
2 * IPv6 Address [auto]configuration
3 * Linux INET6 implementation
4 *
5 * Authors:
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 *
9 * $Id: addrconf.c,v 1.68 2001/09/01 00:31:50 davem Exp $
10 *
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.
15 */
16
17 /*
18 * Changes:
19 *
20 * Janos Farkas : delete timer on ifdown
21 * <chexum@bankinf.banki.hu>
22 * Andi Kleen : kill doube kfree on module
23 * unload.
24 * Maciej W. Rozycki : FDDI support
25 * sekiya@USAGI : Don't send too many RS
26 * packets.
27 * yoshfuji@USAGI : Fixed interval between DAD
28 * packets.
29 */
30
31 #include <linux/config.h>
32 #include <linux/errno.h>
33 #include <linux/types.h>
34 #include <linux/socket.h>
35 #include <linux/sockios.h>
36 #include <linux/sched.h>
37 #include <linux/net.h>
38 #include <linux/in6.h>
39 #include <linux/netdevice.h>
40 #include <linux/if_arp.h>
41 #include <linux/route.h>
42 #include <linux/inetdevice.h>
43 #include <linux/init.h>
44 #ifdef CONFIG_SYSCTL
45 #include <linux/sysctl.h>
46 #endif
47 #include <linux/delay.h>
48 #include <linux/notifier.h>
49
50 #include <linux/proc_fs.h>
51 #include <net/sock.h>
52 #include <net/snmp.h>
53
54 #include <net/ipv6.h>
55 #include <net/protocol.h>
56 #include <net/ndisc.h>
57 #include <net/ip6_route.h>
58 #include <net/addrconf.h>
59 #include <net/ip.h>
60 #include <linux/if_tunnel.h>
61 #include <linux/rtnetlink.h>
62
63 #include <asm/uaccess.h>
64
65 /* Set to 3 to get tracing... */
66 #define ACONF_DEBUG 2
67
68 #if ACONF_DEBUG >= 3
69 #define ADBG(x) printk x
70 #else
71 #define ADBG(x)
72 #endif
73
74 #ifdef CONFIG_SYSCTL
75 static void addrconf_sysctl_register(struct inet6_dev *idev, struct ipv6_devconf *p);
76 static void addrconf_sysctl_unregister(struct ipv6_devconf *p);
77 #endif
78
79 int inet6_dev_count;
80 int inet6_ifa_count;
81
82 /*
83 * Configured unicast address hash table
84 */
85 static struct inet6_ifaddr *inet6_addr_lst[IN6_ADDR_HSIZE];
86 static rwlock_t addrconf_hash_lock = RW_LOCK_UNLOCKED;
87
88 /* Protects inet6 devices */
89 rwlock_t addrconf_lock = RW_LOCK_UNLOCKED;
90
91 void addrconf_verify(unsigned long);
92
93 static struct timer_list addr_chk_timer = { function: addrconf_verify };
94
95 static int addrconf_ifdown(struct net_device *dev, int how);
96
97 static void addrconf_dad_start(struct inet6_ifaddr *ifp);
98 static void addrconf_dad_timer(unsigned long data);
99 static void addrconf_dad_completed(struct inet6_ifaddr *ifp);
100 static void addrconf_rs_timer(unsigned long data);
101 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifa);
102
103 static struct notifier_block *inet6addr_chain;
104
105 struct ipv6_devconf ipv6_devconf =
106 {
107 0, /* forwarding */
108 IPV6_DEFAULT_HOPLIMIT, /* hop limit */
109 IPV6_MIN_MTU, /* mtu */
110 1, /* accept RAs */
111 1, /* accept redirects */
112 1, /* autoconfiguration */
113 1, /* dad transmits */
114 MAX_RTR_SOLICITATIONS, /* router solicits */
115 RTR_SOLICITATION_INTERVAL, /* rtr solicit interval */
116 MAX_RTR_SOLICITATION_DELAY, /* rtr solicit delay */
117 };
118
119 static struct ipv6_devconf ipv6_devconf_dflt =
120 {
121 0, /* forwarding */
122 IPV6_DEFAULT_HOPLIMIT, /* hop limit */
123 IPV6_MIN_MTU, /* mtu */
124 1, /* accept RAs */
125 1, /* accept redirects */
126 1, /* autoconfiguration */
127 1, /* dad transmits */
128 MAX_RTR_SOLICITATIONS, /* router solicits */
129 RTR_SOLICITATION_INTERVAL, /* rtr solicit interval */
130 MAX_RTR_SOLICITATION_DELAY, /* rtr solicit delay */
131 };
132
133 int ipv6_addr_type(struct in6_addr *addr)
134 {
135 u32 st;
136
137 st = addr->s6_addr32[0];
138
139 /* Consider all addresses with the first three bits different of
140 000 and 111 as unicasts.
141 */
142 if ((st & __constant_htonl(0xE0000000)) != __constant_htonl(0x00000000) &&
143 (st & __constant_htonl(0xE0000000)) != __constant_htonl(0xE0000000))
144 return IPV6_ADDR_UNICAST;
145
146 if ((st & __constant_htonl(0xFF000000)) == __constant_htonl(0xFF000000)) {
147 int type = IPV6_ADDR_MULTICAST;
148
149 switch((st & __constant_htonl(0x00FF0000))) {
150 case __constant_htonl(0x00010000):
151 type |= IPV6_ADDR_LOOPBACK;
152 break;
153
154 case __constant_htonl(0x00020000):
155 type |= IPV6_ADDR_LINKLOCAL;
156 break;
157
158 case __constant_htonl(0x00050000):
159 type |= IPV6_ADDR_SITELOCAL;
160 break;
161 };
162 return type;
163 }
164
165 if ((st & __constant_htonl(0xFFC00000)) == __constant_htonl(0xFE800000))
166 return (IPV6_ADDR_LINKLOCAL | IPV6_ADDR_UNICAST);
167
168 if ((st & __constant_htonl(0xFFC00000)) == __constant_htonl(0xFEC00000))
169 return (IPV6_ADDR_SITELOCAL | IPV6_ADDR_UNICAST);
170
171 if ((addr->s6_addr32[0] | addr->s6_addr32[1]) == 0) {
172 if (addr->s6_addr32[2] == 0) {
173 if (addr->in6_u.u6_addr32[3] == 0)
174 return IPV6_ADDR_ANY;
175
176 if (addr->s6_addr32[3] == __constant_htonl(0x00000001))
177 return (IPV6_ADDR_LOOPBACK | IPV6_ADDR_UNICAST);
178
179 return (IPV6_ADDR_COMPATv4 | IPV6_ADDR_UNICAST);
180 }
181
182 if (addr->s6_addr32[2] == __constant_htonl(0x0000ffff))
183 return IPV6_ADDR_MAPPED;
184 }
185
186 return IPV6_ADDR_RESERVED;
187 }
188
189 static void addrconf_del_timer(struct inet6_ifaddr *ifp)
190 {
191 if (del_timer(&ifp->timer))
192 __in6_ifa_put(ifp);
193 }
194
195 enum addrconf_timer_t
196 {
197 AC_NONE,
198 AC_DAD,
199 AC_RS,
200 };
201
202 static void addrconf_mod_timer(struct inet6_ifaddr *ifp,
203 enum addrconf_timer_t what,
204 unsigned long when)
205 {
206 if (!del_timer(&ifp->timer))
207 in6_ifa_hold(ifp);
208
209 switch (what) {
210 case AC_DAD:
211 ifp->timer.function = addrconf_dad_timer;
212 break;
213 case AC_RS:
214 ifp->timer.function = addrconf_rs_timer;
215 break;
216 default:;
217 }
218 ifp->timer.expires = jiffies + when;
219 add_timer(&ifp->timer);
220 }
221
222
223 /* Nobody refers to this device, we may destroy it. */
224
225 void in6_dev_finish_destroy(struct inet6_dev *idev)
226 {
227 struct net_device *dev = idev->dev;
228 BUG_TRAP(idev->addr_list==NULL);
229 BUG_TRAP(idev->mc_list==NULL);
230 #ifdef NET_REFCNT_DEBUG
231 printk(KERN_DEBUG "in6_dev_finish_destroy: %s\n", dev ? dev->name : "NIL");
232 #endif
233 dev_put(dev);
234 if (!idev->dead) {
235 printk("Freeing alive inet6 device %p\n", idev);
236 return;
237 }
238 inet6_dev_count--;
239 kfree(idev);
240 }
241
242 static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
243 {
244 struct inet6_dev *ndev;
245
246 ASSERT_RTNL();
247
248 if (dev->mtu < IPV6_MIN_MTU)
249 return NULL;
250
251 ndev = kmalloc(sizeof(struct inet6_dev), GFP_KERNEL);
252
253 if (ndev) {
254 memset(ndev, 0, sizeof(struct inet6_dev));
255
256 ndev->lock = RW_LOCK_UNLOCKED;
257 ndev->dev = dev;
258 memcpy(&ndev->cnf, &ipv6_devconf_dflt, sizeof(ndev->cnf));
259 ndev->cnf.mtu6 = dev->mtu;
260 ndev->cnf.sysctl = NULL;
261 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl);
262 if (ndev->nd_parms == NULL) {
263 kfree(ndev);
264 return NULL;
265 }
266 inet6_dev_count++;
267 /* We refer to the device */
268 dev_hold(dev);
269
270 write_lock_bh(&addrconf_lock);
271 dev->ip6_ptr = ndev;
272 /* One reference from device */
273 in6_dev_hold(ndev);
274 write_unlock_bh(&addrconf_lock);
275
276 ipv6_mc_init_dev(ndev);
277
278 #ifdef CONFIG_SYSCTL
279 neigh_sysctl_register(dev, ndev->nd_parms, NET_IPV6, NET_IPV6_NEIGH, "ipv6");
280 addrconf_sysctl_register(ndev, &ndev->cnf);
281 #endif
282 }
283 return ndev;
284 }
285
286 static struct inet6_dev * ipv6_find_idev(struct net_device *dev)
287 {
288 struct inet6_dev *idev;
289
290 ASSERT_RTNL();
291
292 if ((idev = __in6_dev_get(dev)) == NULL) {
293 if ((idev = ipv6_add_dev(dev)) == NULL)
294 return NULL;
295 }
296 if (dev->flags&IFF_UP)
297 ipv6_mc_up(idev);
298 return idev;
299 }
300
301 static void addrconf_forward_change(struct inet6_dev *idev)
302 {
303 struct net_device *dev;
304
305 if (idev)
306 return;
307
308 read_lock(&dev_base_lock);
309 for (dev=dev_base; dev; dev=dev->next) {
310 read_lock(&addrconf_lock);
311 idev = __in6_dev_get(dev);
312 if (idev)
313 idev->cnf.forwarding = ipv6_devconf.forwarding;
314 read_unlock(&addrconf_lock);
315 }
316 read_unlock(&dev_base_lock);
317 }
318
319 /* Nobody refers to this ifaddr, destroy it */
320
321 void inet6_ifa_finish_destroy(struct inet6_ifaddr *ifp)
322 {
323 BUG_TRAP(ifp->if_next==NULL);
324 BUG_TRAP(ifp->lst_next==NULL);
325 #ifdef NET_REFCNT_DEBUG
326 printk(KERN_DEBUG "inet6_ifa_finish_destroy\n");
327 #endif
328
329 in6_dev_put(ifp->idev);
330
331 if (del_timer(&ifp->timer))
332 printk("Timer is still running, when freeing ifa=%p\n", ifp);
333
334 if (!ifp->dead) {
335 printk("Freeing alive inet6 address %p\n", ifp);
336 return;
337 }
338 inet6_ifa_count--;
339 kfree(ifp);
340 }
341
342 /* On success it returns ifp with increased reference count */
343
344 static struct inet6_ifaddr *
345 ipv6_add_addr(struct inet6_dev *idev, struct in6_addr *addr, int pfxlen,
346 int scope, unsigned flags)
347 {
348 struct inet6_ifaddr *ifa;
349 int hash;
350
351 ifa = kmalloc(sizeof(struct inet6_ifaddr), GFP_ATOMIC);
352
353 if (ifa == NULL) {
354 ADBG(("ipv6_add_addr: malloc failed\n"));
355 return NULL;
356 }
357
358 memset(ifa, 0, sizeof(struct inet6_ifaddr));
359 ipv6_addr_copy(&ifa->addr, addr);
360
361 spin_lock_init(&ifa->lock);
362 init_timer(&ifa->timer);
363 ifa->timer.data = (unsigned long) ifa;
364 ifa->scope = scope;
365 ifa->prefix_len = pfxlen;
366 ifa->flags = flags | IFA_F_TENTATIVE;
367
368 read_lock(&addrconf_lock);
369 if (idev->dead) {
370 read_unlock(&addrconf_lock);
371 kfree(ifa);
372 return NULL;
373 }
374
375 inet6_ifa_count++;
376 ifa->idev = idev;
377 in6_dev_hold(idev);
378 /* For caller */
379 in6_ifa_hold(ifa);
380
381 /* Add to big hash table */
382 hash = ipv6_addr_hash(addr);
383
384 write_lock_bh(&addrconf_hash_lock);
385 ifa->lst_next = inet6_addr_lst[hash];
386 inet6_addr_lst[hash] = ifa;
387 in6_ifa_hold(ifa);
388 write_unlock_bh(&addrconf_hash_lock);
389
390 write_lock_bh(&idev->lock);
391 /* Add to inet6_dev unicast addr list. */
392 ifa->if_next = idev->addr_list;
393 idev->addr_list = ifa;
394 in6_ifa_hold(ifa);
395 write_unlock_bh(&idev->lock);
396 read_unlock(&addrconf_lock);
397
398 notifier_call_chain(&inet6addr_chain,NETDEV_UP,ifa);
399
400 return ifa;
401 }
402
403 /* This function wants to get referenced ifp and releases it before return */
404
405 static void ipv6_del_addr(struct inet6_ifaddr *ifp)
406 {
407 struct inet6_ifaddr *ifa, **ifap;
408 struct inet6_dev *idev = ifp->idev;
409 int hash;
410
411 hash = ipv6_addr_hash(&ifp->addr);
412
413 ifp->dead = 1;
414
415 write_lock_bh(&addrconf_hash_lock);
416 for (ifap = &inet6_addr_lst[hash]; (ifa=*ifap) != NULL;
417 ifap = &ifa->lst_next) {
418 if (ifa == ifp) {
419 *ifap = ifa->lst_next;
420 __in6_ifa_put(ifp);
421 ifa->lst_next = NULL;
422 break;
423 }
424 }
425 write_unlock_bh(&addrconf_hash_lock);
426
427 write_lock_bh(&idev->lock);
428 for (ifap = &idev->addr_list; (ifa=*ifap) != NULL;
429 ifap = &ifa->if_next) {
430 if (ifa == ifp) {
431 *ifap = ifa->if_next;
432 __in6_ifa_put(ifp);
433 ifa->if_next = NULL;
434 break;
435 }
436 }
437 write_unlock_bh(&idev->lock);
438
439 ipv6_ifa_notify(RTM_DELADDR, ifp);
440
441 notifier_call_chain(&inet6addr_chain,NETDEV_DOWN,ifp);
442
443 addrconf_del_timer(ifp);
444
445 in6_ifa_put(ifp);
446 }
447
448 /*
449 * Choose an apropriate source address
450 * should do:
451 * i) get an address with an apropriate scope
452 * ii) see if there is a specific route for the destination and use
453 * an address of the attached interface
454 * iii) don't use deprecated addresses
455 */
456 int ipv6_get_saddr(struct dst_entry *dst,
457 struct in6_addr *daddr, struct in6_addr *saddr)
458 {
459 int scope;
460 struct inet6_ifaddr *ifp = NULL;
461 struct inet6_ifaddr *match = NULL;
462 struct net_device *dev = NULL;
463 struct inet6_dev *idev;
464 struct rt6_info *rt;
465 int err;
466
467 rt = (struct rt6_info *) dst;
468 if (rt)
469 dev = rt->rt6i_dev;
470
471 scope = ipv6_addr_scope(daddr);
472 if (rt && (rt->rt6i_flags & RTF_ALLONLINK)) {
473 /*
474 * route for the "all destinations on link" rule
475 * when no routers are present
476 */
477 scope = IFA_LINK;
478 }
479
480 /*
481 * known dev
482 * search dev and walk through dev addresses
483 */
484
485 if (dev) {
486 if (dev->flags & IFF_LOOPBACK)
487 scope = IFA_HOST;
488
489 read_lock(&addrconf_lock);
490 idev = __in6_dev_get(dev);
491 if (idev) {
492 read_lock_bh(&idev->lock);
493 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
494 if (ifp->scope == scope) {
495 if (!(ifp->flags & (IFA_F_DEPRECATED|IFA_F_TENTATIVE))) {
496 in6_ifa_hold(ifp);
497 read_unlock_bh(&idev->lock);
498 read_unlock(&addrconf_lock);
499 goto out;
500 }
501
502 if (!match && !(ifp->flags & IFA_F_TENTATIVE)) {
503 match = ifp;
504 in6_ifa_hold(ifp);
505 }
506 }
507 }
508 read_unlock_bh(&idev->lock);
509 }
510 read_unlock(&addrconf_lock);
511 }
512
513 if (scope == IFA_LINK)
514 goto out;
515
516 /*
517 * dev == NULL or search failed for specified dev
518 */
519
520 read_lock(&dev_base_lock);
521 read_lock(&addrconf_lock);
522 for (dev = dev_base; dev; dev=dev->next) {
523 idev = __in6_dev_get(dev);
524 if (idev) {
525 read_lock_bh(&idev->lock);
526 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
527 if (ifp->scope == scope) {
528 if (!(ifp->flags&(IFA_F_DEPRECATED|IFA_F_TENTATIVE))) {
529 in6_ifa_hold(ifp);
530 read_unlock_bh(&idev->lock);
531 goto out_unlock_base;
532 }
533
534 if (!match && !(ifp->flags&IFA_F_TENTATIVE)) {
535 match = ifp;
536 in6_ifa_hold(ifp);
537 }
538 }
539 }
540 read_unlock_bh(&idev->lock);
541 }
542 }
543
544 out_unlock_base:
545 read_unlock(&addrconf_lock);
546 read_unlock(&dev_base_lock);
547
548 out:
549 if (ifp == NULL) {
550 ifp = match;
551 match = NULL;
552 }
553
554 err = -EADDRNOTAVAIL;
555 if (ifp) {
556 ipv6_addr_copy(saddr, &ifp->addr);
557 err = 0;
558 in6_ifa_put(ifp);
559 }
560 if (match)
561 in6_ifa_put(match);
562
563 return err;
564 }
565
566 int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr)
567 {
568 struct inet6_dev *idev;
569 int err = -EADDRNOTAVAIL;
570
571 read_lock(&addrconf_lock);
572 if ((idev = __in6_dev_get(dev)) != NULL) {
573 struct inet6_ifaddr *ifp;
574
575 read_lock_bh(&idev->lock);
576 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
577 if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) {
578 ipv6_addr_copy(addr, &ifp->addr);
579 err = 0;
580 break;
581 }
582 }
583 read_unlock_bh(&idev->lock);
584 }
585 read_unlock(&addrconf_lock);
586 return err;
587 }
588
589 int ipv6_chk_addr(struct in6_addr *addr, struct net_device *dev)
590 {
591 struct inet6_ifaddr * ifp;
592 u8 hash = ipv6_addr_hash(addr);
593
594 read_lock_bh(&addrconf_hash_lock);
595 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
596 if (ipv6_addr_cmp(&ifp->addr, addr) == 0 &&
597 !(ifp->flags&IFA_F_TENTATIVE)) {
598 if (dev == NULL || ifp->idev->dev == dev ||
599 !(ifp->scope&(IFA_LINK|IFA_HOST)))
600 break;
601 }
602 }
603 read_unlock_bh(&addrconf_hash_lock);
604 return ifp != NULL;
605 }
606
607 struct inet6_ifaddr * ipv6_get_ifaddr(struct in6_addr *addr, struct net_device *dev)
608 {
609 struct inet6_ifaddr * ifp;
610 u8 hash = ipv6_addr_hash(addr);
611
612 read_lock_bh(&addrconf_hash_lock);
613 for(ifp = inet6_addr_lst[hash]; ifp; ifp=ifp->lst_next) {
614 if (ipv6_addr_cmp(&ifp->addr, addr) == 0) {
615 if (dev == NULL || ifp->idev->dev == dev ||
616 !(ifp->scope&(IFA_LINK|IFA_HOST))) {
617 in6_ifa_hold(ifp);
618 break;
619 }
620 }
621 }
622 read_unlock_bh(&addrconf_hash_lock);
623
624 return ifp;
625 }
626
627 /* Gets referenced address, destroys ifaddr */
628
629 void addrconf_dad_failure(struct inet6_ifaddr *ifp)
630 {
631 if (net_ratelimit())
632 printk(KERN_INFO "%s: duplicate address detected!\n", ifp->idev->dev->name);
633 if (ifp->flags&IFA_F_PERMANENT) {
634 spin_lock_bh(&ifp->lock);
635 addrconf_del_timer(ifp);
636 ifp->flags |= IFA_F_TENTATIVE;
637 spin_unlock_bh(&ifp->lock);
638 in6_ifa_put(ifp);
639 } else
640 ipv6_del_addr(ifp);
641 }
642
643
644 /* Join to solicited addr multicast group. */
645
646 static void addrconf_join_solict(struct net_device *dev, struct in6_addr *addr)
647 {
648 struct in6_addr maddr;
649
650 if (dev->flags&(IFF_LOOPBACK|IFF_NOARP))
651 return;
652
653 addrconf_addr_solict_mult(addr, &maddr);
654 ipv6_dev_mc_inc(dev, &maddr);
655 }
656
657 static void addrconf_leave_solict(struct net_device *dev, struct in6_addr *addr)
658 {
659 struct in6_addr maddr;
660
661 if (dev->flags&(IFF_LOOPBACK|IFF_NOARP))
662 return;
663
664 addrconf_addr_solict_mult(addr, &maddr);
665 ipv6_dev_mc_dec(dev, &maddr);
666 }
667
668
669 static int ipv6_generate_eui64(u8 *eui, struct net_device *dev)
670 {
671 switch (dev->type) {
672 case ARPHRD_ETHER:
673 case ARPHRD_FDDI:
674 case ARPHRD_IEEE802_TR:
675 if (dev->addr_len != ETH_ALEN)
676 return -1;
677 memcpy(eui, dev->dev_addr, 3);
678 memcpy(eui + 5, dev->dev_addr+3, 3);
679 eui[3] = 0xFF;
680 eui[4] = 0xFE;
681 eui[0] ^= 2;
682 return 0;
683 }
684 return -1;
685 }
686
687 static int ipv6_inherit_eui64(u8 *eui, struct inet6_dev *idev)
688 {
689 int err = -1;
690 struct inet6_ifaddr *ifp;
691
692 read_lock_bh(&idev->lock);
693 for (ifp=idev->addr_list; ifp; ifp=ifp->if_next) {
694 if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) {
695 memcpy(eui, ifp->addr.s6_addr+8, 8);
696 err = 0;
697 break;
698 }
699 }
700 read_unlock_bh(&idev->lock);
701 return err;
702 }
703
704 /*
705 * Add prefix route.
706 */
707
708 static void
709 addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev,
710 unsigned long expires, unsigned flags)
711 {
712 struct in6_rtmsg rtmsg;
713
714 memset(&rtmsg, 0, sizeof(rtmsg));
715 memcpy(&rtmsg.rtmsg_dst, pfx, sizeof(struct in6_addr));
716 rtmsg.rtmsg_dst_len = plen;
717 rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF;
718 rtmsg.rtmsg_ifindex = dev->ifindex;
719 rtmsg.rtmsg_info = expires;
720 rtmsg.rtmsg_flags = RTF_UP|flags;
721 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
722
723 /* Prevent useless cloning on PtP SIT.
724 This thing is done here expecting that the whole
725 class of non-broadcast devices need not cloning.
726 */
727 if (dev->type == ARPHRD_SIT && (dev->flags&IFF_POINTOPOINT))
728 rtmsg.rtmsg_flags |= RTF_NONEXTHOP;
729
730 ip6_route_add(&rtmsg);
731 }
732
733 /* Create "default" multicast route to the interface */
734
735 static void addrconf_add_mroute(struct net_device *dev)
736 {
737 struct in6_rtmsg rtmsg;
738
739 memset(&rtmsg, 0, sizeof(rtmsg));
740 ipv6_addr_set(&rtmsg.rtmsg_dst,
741 __constant_htonl(0xFF000000), 0, 0, 0);
742 rtmsg.rtmsg_dst_len = 8;
743 rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF;
744 rtmsg.rtmsg_ifindex = dev->ifindex;
745 rtmsg.rtmsg_flags = RTF_UP|RTF_ADDRCONF;
746 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
747 ip6_route_add(&rtmsg);
748 }
749
750 static void sit_route_add(struct net_device *dev)
751 {
752 struct in6_rtmsg rtmsg;
753
754 memset(&rtmsg, 0, sizeof(rtmsg));
755
756 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
757 rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF;
758
759 /* prefix length - 96 bytes "::d.d.d.d" */
760 rtmsg.rtmsg_dst_len = 96;
761 rtmsg.rtmsg_flags = RTF_UP|RTF_NONEXTHOP;
762 rtmsg.rtmsg_ifindex = dev->ifindex;
763
764 ip6_route_add(&rtmsg);
765 }
766
767 static void addrconf_add_lroute(struct net_device *dev)
768 {
769 struct in6_addr addr;
770
771 ipv6_addr_set(&addr, __constant_htonl(0xFE800000), 0, 0, 0);
772 addrconf_prefix_route(&addr, 10, dev, 0, RTF_ADDRCONF);
773 }
774
775 static struct inet6_dev *addrconf_add_dev(struct net_device *dev)
776 {
777 struct inet6_dev *idev;
778
779 ASSERT_RTNL();
780
781 if ((idev = ipv6_find_idev(dev)) == NULL)
782 return NULL;
783
784 /* Add default multicast route */
785 addrconf_add_mroute(dev);
786
787 /* Add link local route */
788 addrconf_add_lroute(dev);
789 return idev;
790 }
791
792 void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
793 {
794 struct prefix_info *pinfo;
795 struct rt6_info *rt;
796 __u32 valid_lft;
797 __u32 prefered_lft;
798 int addr_type;
799 unsigned long rt_expires;
800 struct inet6_dev *in6_dev;
801
802 pinfo = (struct prefix_info *) opt;
803
804 if (len < sizeof(struct prefix_info)) {
805 ADBG(("addrconf: prefix option too short\n"));
806 return;
807 }
808
809 /*
810 * Validation checks ([ADDRCONF], page 19)
811 */
812
813 addr_type = ipv6_addr_type(&pinfo->prefix);
814
815 if (addr_type & (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL))
816 return;
817
818 valid_lft = ntohl(pinfo->valid);
819 prefered_lft = ntohl(pinfo->prefered);
820
821 if (prefered_lft > valid_lft) {
822 if (net_ratelimit())
823 printk(KERN_WARNING "addrconf: prefix option has invalid lifetime\n");
824 return;
825 }
826
827 in6_dev = in6_dev_get(dev);
828
829 if (in6_dev == NULL) {
830 if (net_ratelimit())
831 printk(KERN_DEBUG "addrconf: device %s not configured\n", dev->name);
832 return;
833 }
834
835 /*
836 * Two things going on here:
837 * 1) Add routes for on-link prefixes
838 * 2) Configure prefixes with the auto flag set
839 */
840
841 /* Avoid arithemtic overflow. Really, we could
842 save rt_expires in seconds, likely valid_lft,
843 but it would require division in fib gc, that it
844 not good.
845 */
846 if (valid_lft >= 0x7FFFFFFF/HZ)
847 rt_expires = 0;
848 else
849 rt_expires = jiffies + valid_lft * HZ;
850
851 rt = rt6_lookup(&pinfo->prefix, NULL, dev->ifindex, 1);
852
853 if (rt && ((rt->rt6i_flags & (RTF_GATEWAY | RTF_DEFAULT)) == 0)) {
854 if (rt->rt6i_flags&RTF_EXPIRES) {
855 if (pinfo->onlink == 0 || valid_lft == 0) {
856 ip6_del_rt(rt);
857 rt = NULL;
858 } else {
859 rt->rt6i_expires = rt_expires;
860 }
861 }
862 } else if (pinfo->onlink && valid_lft) {
863 addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len,
864 dev, rt_expires, RTF_ADDRCONF|RTF_EXPIRES);
865 }
866 if (rt)
867 dst_release(&rt->u.dst);
868
869 /* Try to figure out our local address for this prefix */
870
871 if (pinfo->autoconf && in6_dev->cnf.autoconf) {
872 struct inet6_ifaddr * ifp;
873 struct in6_addr addr;
874 int plen;
875
876 plen = pinfo->prefix_len >> 3;
877
878 if (pinfo->prefix_len == 64) {
879 memcpy(&addr, &pinfo->prefix, 8);
880 if (ipv6_generate_eui64(addr.s6_addr + 8, dev) &&
881 ipv6_inherit_eui64(addr.s6_addr + 8, in6_dev)) {
882 in6_dev_put(in6_dev);
883 return;
884 }
885 goto ok;
886 }
887 if (net_ratelimit())
888 printk(KERN_DEBUG "IPv6 addrconf: prefix with wrong length %d\n",
889 pinfo->prefix_len);
890 in6_dev_put(in6_dev);
891 return;
892
893 ok:
894
895 ifp = ipv6_get_ifaddr(&addr, dev);
896
897 if (ifp == NULL && valid_lft) {
898 ifp = ipv6_add_addr(in6_dev, &addr, pinfo->prefix_len,
899 addr_type&IPV6_ADDR_SCOPE_MASK, 0);
900
901 if (ifp == NULL) {
902 in6_dev_put(in6_dev);
903 return;
904 }
905
906 addrconf_dad_start(ifp);
907 }
908
909 if (ifp && valid_lft == 0) {
910 ipv6_del_addr(ifp);
911 ifp = NULL;
912 }
913
914 if (ifp) {
915 int flags;
916
917 spin_lock(&ifp->lock);
918 ifp->valid_lft = valid_lft;
919 ifp->prefered_lft = prefered_lft;
920 ifp->tstamp = jiffies;
921 flags = ifp->flags;
922 ifp->flags &= ~IFA_F_DEPRECATED;
923 spin_unlock(&ifp->lock);
924
925 if (!(flags&IFA_F_TENTATIVE))
926 ipv6_ifa_notify((flags&IFA_F_DEPRECATED) ?
927 0 : RTM_NEWADDR, ifp);
928 in6_ifa_put(ifp);
929 }
930 }
931 in6_dev_put(in6_dev);
932 }
933
934 /*
935 * Set destination address.
936 * Special case for SIT interfaces where we create a new "virtual"
937 * device.
938 */
939 int addrconf_set_dstaddr(void *arg)
940 {
941 struct in6_ifreq ireq;
942 struct net_device *dev;
943 int err = -EINVAL;
944
945 rtnl_lock();
946
947 err = -EFAULT;
948 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
949 goto err_exit;
950
951 dev = __dev_get_by_index(ireq.ifr6_ifindex);
952
953 err = -ENODEV;
954 if (dev == NULL)
955 goto err_exit;
956
957 if (dev->type == ARPHRD_SIT) {
958 struct ifreq ifr;
959 mm_segment_t oldfs;
960 struct ip_tunnel_parm p;
961
962 err = -EADDRNOTAVAIL;
963 if (!(ipv6_addr_type(&ireq.ifr6_addr) & IPV6_ADDR_COMPATv4))
964 goto err_exit;
965
966 memset(&p, 0, sizeof(p));
967 p.iph.daddr = ireq.ifr6_addr.s6_addr32[3];
968 p.iph.saddr = 0;
969 p.iph.version = 4;
970 p.iph.ihl = 5;
971 p.iph.protocol = IPPROTO_IPV6;
972 p.iph.ttl = 64;
973 ifr.ifr_ifru.ifru_data = (void*)&p;
974
975 oldfs = get_fs(); set_fs(KERNEL_DS);
976 err = dev->do_ioctl(dev, &ifr, SIOCADDTUNNEL);
977 set_fs(oldfs);
978
979 if (err == 0) {
980 err = -ENOBUFS;
981 if ((dev = __dev_get_by_name(p.name)) == NULL)
982 goto err_exit;
983 err = dev_open(dev);
984 }
985 }
986
987 err_exit:
988 rtnl_unlock();
989 return err;
990 }
991
992 /*
993 * Manual configuration of address on an interface
994 */
995 static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen)
996 {
997 struct inet6_ifaddr *ifp;
998 struct inet6_dev *idev;
999 struct net_device *dev;
1000 int scope;
1001
1002 ASSERT_RTNL();
1003
1004 if ((dev = __dev_get_by_index(ifindex)) == NULL)
1005 return -ENODEV;
1006
1007 if (!(dev->flags&IFF_UP))
1008 return -ENETDOWN;
1009
1010 if ((idev = addrconf_add_dev(dev)) == NULL)
1011 return -ENOBUFS;
1012
1013 scope = ipv6_addr_scope(pfx);
1014
1015 if ((ifp = ipv6_add_addr(idev, pfx, plen, scope, IFA_F_PERMANENT)) != NULL) {
1016 addrconf_dad_start(ifp);
1017 in6_ifa_put(ifp);
1018 return 0;
1019 }
1020
1021 return -ENOBUFS;
1022 }
1023
1024 static int inet6_addr_del(int ifindex, struct in6_addr *pfx, int plen)
1025 {
1026 struct inet6_ifaddr *ifp;
1027 struct inet6_dev *idev;
1028 struct net_device *dev;
1029
1030 if ((dev = __dev_get_by_index(ifindex)) == NULL)
1031 return -ENODEV;
1032
1033 if ((idev = __in6_dev_get(dev)) == NULL)
1034 return -ENXIO;
1035
1036 read_lock_bh(&idev->lock);
1037 for (ifp = idev->addr_list; ifp; ifp=ifp->if_next) {
1038 if (ifp->prefix_len == plen &&
1039 (!memcmp(pfx, &ifp->addr, sizeof(struct in6_addr)))) {
1040 in6_ifa_hold(ifp);
1041 read_unlock_bh(&idev->lock);
1042
1043 ipv6_del_addr(ifp);
1044
1045 /* If the last address is deleted administratively,
1046 disable IPv6 on this interface.
1047 */
1048 if (idev->addr_list == NULL)
1049 addrconf_ifdown(idev->dev, 1);
1050 return 0;
1051 }
1052 }
1053 read_unlock_bh(&idev->lock);
1054 return -EADDRNOTAVAIL;
1055 }
1056
1057
1058 int addrconf_add_ifaddr(void *arg)
1059 {
1060 struct in6_ifreq ireq;
1061 int err;
1062
1063 if (!capable(CAP_NET_ADMIN))
1064 return -EPERM;
1065
1066 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
1067 return -EFAULT;
1068
1069 rtnl_lock();
1070 err = inet6_addr_add(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen);
1071 rtnl_unlock();
1072 return err;
1073 }
1074
1075 int addrconf_del_ifaddr(void *arg)
1076 {
1077 struct in6_ifreq ireq;
1078 int err;
1079
1080 if (!capable(CAP_NET_ADMIN))
1081 return -EPERM;
1082
1083 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
1084 return -EFAULT;
1085
1086 rtnl_lock();
1087 err = inet6_addr_del(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen);
1088 rtnl_unlock();
1089 return err;
1090 }
1091
1092 static void sit_add_v4_addrs(struct inet6_dev *idev)
1093 {
1094 struct inet6_ifaddr * ifp;
1095 struct in6_addr addr;
1096 struct net_device *dev;
1097 int scope;
1098
1099 ASSERT_RTNL();
1100
1101 memset(&addr, 0, sizeof(struct in6_addr));
1102 memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4);
1103
1104 if (idev->dev->flags&IFF_POINTOPOINT) {
1105 addr.s6_addr32[0] = __constant_htonl(0xfe800000);
1106 scope = IFA_LINK;
1107 } else {
1108 scope = IPV6_ADDR_COMPATv4;
1109 }
1110
1111 if (addr.s6_addr32[3]) {
1112 ifp = ipv6_add_addr(idev, &addr, 128, scope, IFA_F_PERMANENT);
1113 if (ifp) {
1114 spin_lock_bh(&ifp->lock);
1115 ifp->flags &= ~IFA_F_TENTATIVE;
1116 spin_unlock_bh(&ifp->lock);
1117 ipv6_ifa_notify(RTM_NEWADDR, ifp);
1118 in6_ifa_put(ifp);
1119 }
1120 return;
1121 }
1122
1123 for (dev = dev_base; dev != NULL; dev = dev->next) {
1124 struct in_device * in_dev = __in_dev_get(dev);
1125 if (in_dev && (dev->flags & IFF_UP)) {
1126 struct in_ifaddr * ifa;
1127
1128 int flag = scope;
1129
1130 for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
1131 int plen;
1132
1133 addr.s6_addr32[3] = ifa->ifa_local;
1134
1135 if (ifa->ifa_scope == RT_SCOPE_LINK)
1136 continue;
1137 if (ifa->ifa_scope >= RT_SCOPE_HOST) {
1138 if (idev->dev->flags&IFF_POINTOPOINT)
1139 continue;
1140 flag |= IFA_HOST;
1141 }
1142 if (idev->dev->flags&IFF_POINTOPOINT)
1143 plen = 10;
1144 else
1145 plen = 96;
1146
1147 ifp = ipv6_add_addr(idev, &addr, plen, flag,
1148 IFA_F_PERMANENT);
1149 if (ifp) {
1150 spin_lock_bh(&ifp->lock);
1151 ifp->flags &= ~IFA_F_TENTATIVE;
1152 spin_unlock_bh(&ifp->lock);
1153 ipv6_ifa_notify(RTM_NEWADDR, ifp);
1154 in6_ifa_put(ifp);
1155 }
1156 }
1157 }
1158 }
1159 }
1160
1161 static void init_loopback(struct net_device *dev)
1162 {
1163 struct in6_addr addr;
1164 struct inet6_dev *idev;
1165 struct inet6_ifaddr * ifp;
1166
1167 /* ::1 */
1168
1169 ASSERT_RTNL();
1170
1171 memset(&addr, 0, sizeof(struct in6_addr));
1172 addr.s6_addr[15] = 1;
1173
1174 if ((idev = ipv6_find_idev(dev)) == NULL) {
1175 printk(KERN_DEBUG "init loopback: add_dev failed\n");
1176 return;
1177 }
1178
1179 ifp = ipv6_add_addr(idev, &addr, 128, IFA_HOST, IFA_F_PERMANENT);
1180 if (ifp) {
1181 spin_lock_bh(&ifp->lock);
1182 ifp->flags &= ~IFA_F_TENTATIVE;
1183 spin_unlock_bh(&ifp->lock);
1184 ipv6_ifa_notify(RTM_NEWADDR, ifp);
1185 in6_ifa_put(ifp);
1186 }
1187 }
1188
1189 static void addrconf_add_linklocal(struct inet6_dev *idev, struct in6_addr *addr)
1190 {
1191 struct inet6_ifaddr * ifp;
1192
1193 ifp = ipv6_add_addr(idev, addr, 10, IFA_LINK, IFA_F_PERMANENT);
1194 if (ifp) {
1195 addrconf_dad_start(ifp);
1196 in6_ifa_put(ifp);
1197 }
1198 }
1199
1200 static void addrconf_dev_config(struct net_device *dev)
1201 {
1202 struct in6_addr addr;
1203 struct inet6_dev * idev;
1204
1205 ASSERT_RTNL();
1206
1207 if ((dev->type != ARPHRD_ETHER) &&
1208 (dev->type != ARPHRD_FDDI) &&
1209 (dev->type != ARPHRD_IEEE802_TR)) {
1210 /* Alas, we support only Ethernet autoconfiguration. */
1211 return;
1212 }
1213
1214 idev = addrconf_add_dev(dev);
1215 if (idev == NULL)
1216 return;
1217
1218 memset(&addr, 0, sizeof(struct in6_addr));
1219
1220 addr.s6_addr[0] = 0xFE;
1221 addr.s6_addr[1] = 0x80;
1222
1223 if (ipv6_generate_eui64(addr.s6_addr + 8, dev) == 0)
1224 addrconf_add_linklocal(idev, &addr);
1225 }
1226
1227 static void addrconf_sit_config(struct net_device *dev)
1228 {
1229 struct inet6_dev *idev;
1230
1231 ASSERT_RTNL();
1232
1233 /*
1234 * Configure the tunnel with one of our IPv4
1235 * addresses... we should configure all of
1236 * our v4 addrs in the tunnel
1237 */
1238
1239 if ((idev = ipv6_find_idev(dev)) == NULL) {
1240 printk(KERN_DEBUG "init sit: add_dev failed\n");
1241 return;
1242 }
1243
1244 sit_add_v4_addrs(idev);
1245
1246 if (dev->flags&IFF_POINTOPOINT) {
1247 addrconf_add_mroute(dev);
1248 addrconf_add_lroute(dev);
1249 } else
1250 sit_route_add(dev);
1251 }
1252
1253
1254 int addrconf_notify(struct notifier_block *this, unsigned long event,
1255 void * data)
1256 {
1257 struct net_device *dev;
1258
1259 dev = (struct net_device *) data;
1260
1261 switch(event) {
1262 case NETDEV_UP:
1263 switch(dev->type) {
1264 case ARPHRD_SIT:
1265 addrconf_sit_config(dev);
1266 break;
1267
1268 case ARPHRD_LOOPBACK:
1269 init_loopback(dev);
1270 break;
1271
1272 default:
1273 addrconf_dev_config(dev);
1274 break;
1275 };
1276 break;
1277
1278 case NETDEV_CHANGEMTU:
1279 if (dev->mtu >= IPV6_MIN_MTU) {
1280 struct inet6_dev *idev;
1281
1282 if ((idev = __in6_dev_get(dev)) == NULL)
1283 break;
1284 idev->cnf.mtu6 = dev->mtu;
1285 rt6_mtu_change(dev, dev->mtu);
1286 break;
1287 }
1288
1289 /* MTU falled under IPV6_MIN_MTU. Stop IPv6 on this interface. */
1290
1291 case NETDEV_DOWN:
1292 case NETDEV_UNREGISTER:
1293 /*
1294 * Remove all addresses from this interface.
1295 */
1296 addrconf_ifdown(dev, event != NETDEV_DOWN);
1297 break;
1298 case NETDEV_CHANGE:
1299 break;
1300 };
1301
1302 return NOTIFY_OK;
1303 }
1304
1305 static int addrconf_ifdown(struct net_device *dev, int how)
1306 {
1307 struct inet6_dev *idev;
1308 struct inet6_ifaddr *ifa, **bifa;
1309 int i;
1310
1311 ASSERT_RTNL();
1312
1313 rt6_ifdown(dev);
1314 neigh_ifdown(&nd_tbl, dev);
1315
1316 idev = __in6_dev_get(dev);
1317 if (idev == NULL)
1318 return -ENODEV;
1319
1320 /* Step 1: remove reference to ipv6 device from parent device.
1321 Do not dev_put!
1322 */
1323 if (how == 1) {
1324 write_lock_bh(&addrconf_lock);
1325 dev->ip6_ptr = NULL;
1326 idev->dead = 1;
1327 write_unlock_bh(&addrconf_lock);
1328 }
1329
1330 /* Step 2: clear hash table */
1331 for (i=0; i<IN6_ADDR_HSIZE; i++) {
1332 bifa = &inet6_addr_lst[i];
1333
1334 write_lock_bh(&addrconf_hash_lock);
1335 while ((ifa = *bifa) != NULL) {
1336 if (ifa->idev == idev) {
1337 *bifa = ifa->lst_next;
1338 ifa->lst_next = NULL;
1339 addrconf_del_timer(ifa);
1340 in6_ifa_put(ifa);
1341 continue;
1342 }
1343 bifa = &ifa->lst_next;
1344 }
1345 write_unlock_bh(&addrconf_hash_lock);
1346 }
1347
1348 /* Step 3: clear address list */
1349
1350 write_lock_bh(&idev->lock);
1351 while ((ifa = idev->addr_list) != NULL) {
1352 idev->addr_list = ifa->if_next;
1353 ifa->if_next = NULL;
1354 ifa->dead = 1;
1355 addrconf_del_timer(ifa);
1356 write_unlock_bh(&idev->lock);
1357
1358 ipv6_ifa_notify(RTM_DELADDR, ifa);
1359 in6_ifa_put(ifa);
1360
1361 write_lock_bh(&idev->lock);
1362 }
1363 write_unlock_bh(&idev->lock);
1364
1365 /* Step 4: Discard multicast list */
1366
1367 if (how == 1)
1368 ipv6_mc_destroy_dev(idev);
1369 else
1370 ipv6_mc_down(idev);
1371
1372 /* Shot the device (if unregistered) */
1373
1374 if (how == 1) {
1375 neigh_parms_release(&nd_tbl, idev->nd_parms);
1376 #ifdef CONFIG_SYSCTL
1377 addrconf_sysctl_unregister(&idev->cnf);
1378 #endif
1379 in6_dev_put(idev);
1380 }
1381 return 0;
1382 }
1383
1384 static void addrconf_rs_timer(unsigned long data)
1385 {
1386 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data;
1387
1388 if (ifp->idev->cnf.forwarding)
1389 goto out;
1390
1391 if (ifp->idev->if_flags & IF_RA_RCVD) {
1392 /*
1393 * Announcement received after solicitation
1394 * was sent
1395 */
1396 goto out;
1397 }
1398
1399 spin_lock(&ifp->lock);
1400 if (ifp->probes++ < ifp->idev->cnf.rtr_solicits) {
1401 struct in6_addr all_routers;
1402
1403 /* The wait after the last probe can be shorter */
1404 addrconf_mod_timer(ifp, AC_RS,
1405 (ifp->probes == ifp->idev->cnf.rtr_solicits) ?
1406 ifp->idev->cnf.rtr_solicit_delay :
1407 ifp->idev->cnf.rtr_solicit_interval);
1408 spin_unlock(&ifp->lock);
1409
1410 ipv6_addr_all_routers(&all_routers);
1411
1412 ndisc_send_rs(ifp->idev->dev, &ifp->addr, &all_routers);
1413 } else {
1414 struct in6_rtmsg rtmsg;
1415
1416 spin_unlock(&ifp->lock);
1417
1418 printk(KERN_DEBUG "%s: no IPv6 routers present\n",
1419 ifp->idev->dev->name);
1420
1421 memset(&rtmsg, 0, sizeof(struct in6_rtmsg));
1422 rtmsg.rtmsg_type = RTMSG_NEWROUTE;
1423 rtmsg.rtmsg_metric = IP6_RT_PRIO_ADDRCONF;
1424 rtmsg.rtmsg_flags = (RTF_ALLONLINK | RTF_ADDRCONF |
1425 RTF_DEFAULT | RTF_UP);
1426
1427 rtmsg.rtmsg_ifindex = ifp->idev->dev->ifindex;
1428
1429 ip6_route_add(&rtmsg);
1430 }
1431
1432 out:
1433 in6_ifa_put(ifp);
1434 }
1435
1436 /*
1437 * Duplicate Address Detection
1438 */
1439 static void addrconf_dad_start(struct inet6_ifaddr *ifp)
1440 {
1441 struct net_device *dev;
1442 unsigned long rand_num;
1443
1444 dev = ifp->idev->dev;
1445
1446 addrconf_join_solict(dev, &ifp->addr);
1447
1448 if (ifp->prefix_len != 128 && (ifp->flags&IFA_F_PERMANENT))
1449 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, 0, RTF_ADDRCONF);
1450
1451 net_srandom(ifp->addr.s6_addr32[3]);
1452 rand_num = net_random() % (ifp->idev->cnf.rtr_solicit_delay ? : 1);
1453
1454 spin_lock_bh(&ifp->lock);
1455
1456 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) ||
1457 !(ifp->flags&IFA_F_TENTATIVE)) {
1458 ifp->flags &= ~IFA_F_TENTATIVE;
1459 spin_unlock_bh(&ifp->lock);
1460
1461 addrconf_dad_completed(ifp);
1462 return;
1463 }
1464
1465 ifp->probes = ifp->idev->cnf.dad_transmits;
1466 addrconf_mod_timer(ifp, AC_DAD, rand_num);
1467
1468 spin_unlock_bh(&ifp->lock);
1469 }
1470
1471 static void addrconf_dad_timer(unsigned long data)
1472 {
1473 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data;
1474 struct in6_addr unspec;
1475 struct in6_addr mcaddr;
1476
1477 spin_lock_bh(&ifp->lock);
1478 if (ifp->probes == 0) {
1479 /*
1480 * DAD was successful
1481 */
1482
1483 ifp->flags &= ~IFA_F_TENTATIVE;
1484 spin_unlock_bh(&ifp->lock);
1485
1486 addrconf_dad_completed(ifp);
1487
1488 in6_ifa_put(ifp);
1489 return;
1490 }
1491
1492 ifp->probes--;
1493 addrconf_mod_timer(ifp, AC_DAD, ifp->idev->nd_parms->retrans_time);
1494 spin_unlock_bh(&ifp->lock);
1495
1496 /* send a neighbour solicitation for our addr */
1497 memset(&unspec, 0, sizeof(unspec));
1498 addrconf_addr_solict_mult(&ifp->addr, &mcaddr);
1499 ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &unspec);
1500
1501 in6_ifa_put(ifp);
1502 }
1503
1504 static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
1505 {
1506 struct net_device * dev = ifp->idev->dev;
1507
1508 /*
1509 * Configure the address for reception. Now it is valid.
1510 */
1511
1512 ipv6_ifa_notify(RTM_NEWADDR, ifp);
1513
1514 /* If added prefix is link local and forwarding is off,
1515 start sending router solicitations.
1516 */
1517
1518 if (ifp->idev->cnf.forwarding == 0 &&
1519 (dev->flags&IFF_LOOPBACK) == 0 &&
1520 (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) {
1521 struct in6_addr all_routers;
1522
1523 ipv6_addr_all_routers(&all_routers);
1524
1525 /*
1526 * If a host as already performed a random delay
1527 * [...] as part of DAD [...] there is no need
1528 * to delay again before sending the first RS
1529 */
1530 ndisc_send_rs(ifp->idev->dev, &ifp->addr, &all_routers);
1531
1532 spin_lock_bh(&ifp->lock);
1533 ifp->probes = 1;
1534 ifp->idev->if_flags |= IF_RS_SENT;
1535 addrconf_mod_timer(ifp, AC_RS, ifp->idev->cnf.rtr_solicit_interval);
1536 spin_unlock_bh(&ifp->lock);
1537 }
1538 }
1539
1540 #ifdef CONFIG_PROC_FS
1541 static int iface_proc_info(char *buffer, char **start, off_t offset,
1542 int length)
1543 {
1544 struct inet6_ifaddr *ifp;
1545 int i;
1546 int len = 0;
1547 off_t pos=0;
1548 off_t begin=0;
1549
1550 for (i=0; i < IN6_ADDR_HSIZE; i++) {
1551 read_lock_bh(&addrconf_hash_lock);
1552 for (ifp=inet6_addr_lst[i]; ifp; ifp=ifp->lst_next) {
1553 int j;
1554
1555 for (j=0; j<16; j++) {
1556 sprintf(buffer + len, "%02x",
1557 ifp->addr.s6_addr[j]);
1558 len += 2;
1559 }
1560
1561 len += sprintf(buffer + len,
1562 " %02x %02x %02x %02x %8s\n",
1563 ifp->idev->dev->ifindex,
1564 ifp->prefix_len,
1565 ifp->scope,
1566 ifp->flags,
1567 ifp->idev->dev->name);
1568 pos=begin+len;
1569 if(pos<offset) {
1570 len=0;
1571 begin=pos;
1572 }
1573 if(pos>offset+length) {
1574 read_unlock_bh(&addrconf_hash_lock);
1575 goto done;
1576 }
1577 }
1578 read_unlock_bh(&addrconf_hash_lock);
1579 }
1580
1581 done:
1582
1583 *start=buffer+(offset-begin);
1584 len-=(offset-begin);
1585 if(len>length)
1586 len=length;
1587 if(len<0)
1588 len=0;
1589 return len;
1590 }
1591
1592 #endif /* CONFIG_PROC_FS */
1593
1594 /*
1595 * Periodic address status verification
1596 */
1597
1598 void addrconf_verify(unsigned long foo)
1599 {
1600 struct inet6_ifaddr *ifp;
1601 unsigned long now = jiffies;
1602 int i;
1603
1604 for (i=0; i < IN6_ADDR_HSIZE; i++) {
1605
1606 restart:
1607 write_lock(&addrconf_hash_lock);
1608 for (ifp=inet6_addr_lst[i]; ifp; ifp=ifp->lst_next) {
1609 unsigned long age;
1610
1611 if (ifp->flags & IFA_F_PERMANENT)
1612 continue;
1613
1614 age = (now - ifp->tstamp) / HZ;
1615
1616 if (age > ifp->valid_lft) {
1617 in6_ifa_hold(ifp);
1618 write_unlock(&addrconf_hash_lock);
1619 ipv6_del_addr(ifp);
1620 goto restart;
1621 } else if (age > ifp->prefered_lft) {
1622 int deprecate = 0;
1623
1624 spin_lock(&ifp->lock);
1625 if (!(ifp->flags&IFA_F_DEPRECATED)) {
1626 deprecate = 1;
1627 ifp->flags |= IFA_F_DEPRECATED;
1628 }
1629 spin_unlock(&ifp->lock);
1630
1631 if (deprecate) {
1632 in6_ifa_hold(ifp);
1633 write_unlock(&addrconf_hash_lock);
1634
1635 ipv6_ifa_notify(0, ifp);
1636 in6_ifa_put(ifp);
1637 goto restart;
1638 }
1639 }
1640 }
1641 write_unlock(&addrconf_hash_lock);
1642 }
1643
1644 mod_timer(&addr_chk_timer, jiffies + ADDR_CHECK_FREQUENCY);
1645 }
1646
1647 #ifdef CONFIG_RTNETLINK
1648
1649 static int
1650 inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1651 {
1652 struct rtattr **rta = arg;
1653 struct ifaddrmsg *ifm = NLMSG_DATA(nlh);
1654 struct in6_addr *pfx;
1655
1656 pfx = NULL;
1657 if (rta[IFA_ADDRESS-1]) {
1658 if (RTA_PAYLOAD(rta[IFA_ADDRESS-1]) < sizeof(*pfx))
1659 return -EINVAL;
1660 pfx = RTA_DATA(rta[IFA_ADDRESS-1]);
1661 }
1662 if (rta[IFA_LOCAL-1]) {
1663 if (pfx && memcmp(pfx, RTA_DATA(rta[IFA_LOCAL-1]), sizeof(*pfx)))
1664 return -EINVAL;
1665 pfx = RTA_DATA(rta[IFA_LOCAL-1]);
1666 }
1667 if (pfx == NULL)
1668 return -EINVAL;
1669
1670 return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen);
1671 }
1672
1673 static int
1674 inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
1675 {
1676 struct rtattr **rta = arg;
1677 struct ifaddrmsg *ifm = NLMSG_DATA(nlh);
1678 struct in6_addr *pfx;
1679
1680 pfx = NULL;
1681 if (rta[IFA_ADDRESS-1]) {
1682 if (RTA_PAYLOAD(rta[IFA_ADDRESS-1]) < sizeof(*pfx))
1683 return -EINVAL;
1684 pfx = RTA_DATA(rta[IFA_ADDRESS-1]);
1685 }
1686 if (rta[IFA_LOCAL-1]) {
1687 if (pfx && memcmp(pfx, RTA_DATA(rta[IFA_LOCAL-1]), sizeof(*pfx)))
1688 return -EINVAL;
1689 pfx = RTA_DATA(rta[IFA_LOCAL-1]);
1690 }
1691 if (pfx == NULL)
1692 return -EINVAL;
1693
1694 return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen);
1695 }
1696
1697 static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa,
1698 u32 pid, u32 seq, int event)
1699 {
1700 struct ifaddrmsg *ifm;
1701 struct nlmsghdr *nlh;
1702 struct ifa_cacheinfo ci;
1703 unsigned char *b = skb->tail;
1704
1705 nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(*ifm));
1706 ifm = NLMSG_DATA(nlh);
1707 ifm->ifa_family = AF_INET6;
1708 ifm->ifa_prefixlen = ifa->prefix_len;
1709 ifm->ifa_flags = ifa->flags;
1710 ifm->ifa_scope = RT_SCOPE_UNIVERSE;
1711 if (ifa->scope&IFA_HOST)
1712 ifm->ifa_scope = RT_SCOPE_HOST;
1713 else if (ifa->scope&IFA_LINK)
1714 ifm->ifa_scope = RT_SCOPE_LINK;
1715 else if (ifa->scope&IFA_SITE)
1716 ifm->ifa_scope = RT_SCOPE_SITE;
1717 ifm->ifa_index = ifa->idev->dev->ifindex;
1718 RTA_PUT(skb, IFA_ADDRESS, 16, &ifa->addr);
1719 if (!(ifa->flags&IFA_F_PERMANENT)) {
1720 ci.ifa_prefered = ifa->prefered_lft;
1721 ci.ifa_valid = ifa->valid_lft;
1722 if (ci.ifa_prefered != 0xFFFFFFFF) {
1723 long tval = (jiffies - ifa->tstamp)/HZ;
1724 ci.ifa_prefered -= tval;
1725 if (ci.ifa_valid != 0xFFFFFFFF)
1726 ci.ifa_valid -= tval;
1727 }
1728 RTA_PUT(skb, IFA_CACHEINFO, sizeof(ci), &ci);
1729 }
1730 nlh->nlmsg_len = skb->tail - b;
1731 return skb->len;
1732
1733 nlmsg_failure:
1734 rtattr_failure:
1735 skb_trim(skb, b - skb->data);
1736 return -1;
1737 }
1738
1739 static int inet6_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
1740 {
1741 int idx, ip_idx;
1742 int s_idx, s_ip_idx;
1743 struct inet6_ifaddr *ifa;
1744
1745 s_idx = cb->args[0];
1746 s_ip_idx = ip_idx = cb->args[1];
1747
1748 for (idx=0; idx < IN6_ADDR_HSIZE; idx++) {
1749 if (idx < s_idx)
1750 continue;
1751 if (idx > s_idx)
1752 s_ip_idx = 0;
1753 read_lock_bh(&addrconf_hash_lock);
1754 for (ifa=inet6_addr_lst[idx], ip_idx = 0; ifa;
1755 ifa = ifa->lst_next, ip_idx++) {
1756 if (ip_idx < s_ip_idx)
1757 continue;
1758 if (inet6_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
1759 cb->nlh->nlmsg_seq, RTM_NEWADDR) <= 0) {
1760 read_unlock_bh(&addrconf_hash_lock);
1761 goto done;
1762 }
1763 }
1764 read_unlock_bh(&addrconf_hash_lock);
1765 }
1766 done:
1767 cb->args[0] = idx;
1768 cb->args[1] = ip_idx;
1769
1770 return skb->len;
1771 }
1772
1773 static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa)
1774 {
1775 struct sk_buff *skb;
1776 int size = NLMSG_SPACE(sizeof(struct ifaddrmsg)+128);
1777
1778 skb = alloc_skb(size, GFP_ATOMIC);
1779 if (!skb) {
1780 netlink_set_err(rtnl, 0, RTMGRP_IPV6_IFADDR, ENOBUFS);
1781 return;
1782 }
1783 if (inet6_fill_ifaddr(skb, ifa, 0, 0, event) < 0) {
1784 kfree_skb(skb);
1785 netlink_set_err(rtnl, 0, RTMGRP_IPV6_IFADDR, EINVAL);
1786 return;
1787 }
1788 NETLINK_CB(skb).dst_groups = RTMGRP_IPV6_IFADDR;
1789 netlink_broadcast(rtnl, skb, 0, RTMGRP_IPV6_IFADDR, GFP_ATOMIC);
1790 }
1791
1792 static struct rtnetlink_link inet6_rtnetlink_table[RTM_MAX-RTM_BASE+1] =
1793 {
1794 { NULL, NULL, },
1795 { NULL, NULL, },
1796 { NULL, NULL, },
1797 { NULL, NULL, },
1798
1799 { inet6_rtm_newaddr, NULL, },
1800 { inet6_rtm_deladdr, NULL, },
1801 { NULL, inet6_dump_ifaddr, },
1802 { NULL, NULL, },
1803
1804 { inet6_rtm_newroute, NULL, },
1805 { inet6_rtm_delroute, NULL, },
1806 { inet6_rtm_getroute, inet6_dump_fib, },
1807 { NULL, NULL, },
1808 };
1809 #endif
1810
1811 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
1812 {
1813 #ifdef CONFIG_RTNETLINK
1814 inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
1815 #endif
1816 switch (event) {
1817 case RTM_NEWADDR:
1818 ip6_rt_addr_add(&ifp->addr, ifp->idev->dev);
1819 break;
1820 case RTM_DELADDR:
1821 addrconf_leave_solict(ifp->idev->dev, &ifp->addr);
1822 if (!ipv6_chk_addr(&ifp->addr, ifp->idev->dev))
1823 ip6_rt_addr_del(&ifp->addr, ifp->idev->dev);
1824 break;
1825 }
1826 }
1827
1828 #ifdef CONFIG_SYSCTL
1829
1830 static
1831 int addrconf_sysctl_forward(ctl_table *ctl, int write, struct file * filp,
1832 void *buffer, size_t *lenp)
1833 {
1834 int *valp = ctl->data;
1835 int val = *valp;
1836 int ret;
1837
1838 ret = proc_dointvec(ctl, write, filp, buffer, lenp);
1839
1840 if (write && *valp != val && valp != &ipv6_devconf_dflt.forwarding) {
1841 struct inet6_dev *idev = NULL;
1842
1843 if (valp != &ipv6_devconf.forwarding) {
1844 struct net_device *dev = dev_get_by_index(ctl->ctl_name);
1845 if (dev) {
1846 idev = in6_dev_get(dev);
1847 dev_put(dev);
1848 }
1849 if (idev == NULL)
1850 return ret;
1851 } else
1852 ipv6_devconf_dflt.forwarding = ipv6_devconf.forwarding;
1853
1854 addrconf_forward_change(idev);
1855
1856 if (*valp)
1857 rt6_purge_dflt_routers(0);
1858 if (idev)
1859 in6_dev_put(idev);
1860 }
1861
1862 return ret;
1863 }
1864
1865 static struct addrconf_sysctl_table
1866 {
1867 struct ctl_table_header *sysctl_header;
1868 ctl_table addrconf_vars[11];
1869 ctl_table addrconf_dev[2];
1870 ctl_table addrconf_conf_dir[2];
1871 ctl_table addrconf_proto_dir[2];
1872 ctl_table addrconf_root_dir[2];
1873 } addrconf_sysctl = {
1874 NULL,
1875 {{NET_IPV6_FORWARDING, "forwarding",
1876 &ipv6_devconf.forwarding, sizeof(int), 0644, NULL,
1877 &addrconf_sysctl_forward},
1878
1879 {NET_IPV6_HOP_LIMIT, "hop_limit",
1880 &ipv6_devconf.hop_limit, sizeof(int), 0644, NULL,
1881 &proc_dointvec},
1882
1883 {NET_IPV6_MTU, "mtu",
1884 &ipv6_devconf.mtu6, sizeof(int), 0644, NULL,
1885 &proc_dointvec},
1886
1887 {NET_IPV6_ACCEPT_RA, "accept_ra",
1888 &ipv6_devconf.accept_ra, sizeof(int), 0644, NULL,
1889 &proc_dointvec},
1890
1891 {NET_IPV6_ACCEPT_REDIRECTS, "accept_redirects",
1892 &ipv6_devconf.accept_redirects, sizeof(int), 0644, NULL,
1893 &proc_dointvec},
1894
1895 {NET_IPV6_AUTOCONF, "autoconf",
1896 &ipv6_devconf.autoconf, sizeof(int), 0644, NULL,
1897 &proc_dointvec},
1898
1899 {NET_IPV6_DAD_TRANSMITS, "dad_transmits",
1900 &ipv6_devconf.dad_transmits, sizeof(int), 0644, NULL,
1901 &proc_dointvec},
1902
1903 {NET_IPV6_RTR_SOLICITS, "router_solicitations",
1904 &ipv6_devconf.rtr_solicits, sizeof(int), 0644, NULL,
1905 &proc_dointvec},
1906
1907 {NET_IPV6_RTR_SOLICIT_INTERVAL, "router_solicitation_interval",
1908 &ipv6_devconf.rtr_solicit_interval, sizeof(int), 0644, NULL,
1909 &proc_dointvec_jiffies},
1910
1911 {NET_IPV6_RTR_SOLICIT_DELAY, "router_solicitation_delay",
1912 &ipv6_devconf.rtr_solicit_delay, sizeof(int), 0644, NULL,
1913 &proc_dointvec_jiffies},
1914
1915 {0}},
1916
1917 {{NET_PROTO_CONF_ALL, "all", NULL, 0, 0555, addrconf_sysctl.addrconf_vars},{0}},
1918 {{NET_IPV6_CONF, "conf", NULL, 0, 0555, addrconf_sysctl.addrconf_dev},{0}},
1919 {{NET_IPV6, "ipv6", NULL, 0, 0555, addrconf_sysctl.addrconf_conf_dir},{0}},
1920 {{CTL_NET, "net", NULL, 0, 0555, addrconf_sysctl.addrconf_proto_dir},{0}}
1921 };
1922
1923 static void addrconf_sysctl_register(struct inet6_dev *idev, struct ipv6_devconf *p)
1924 {
1925 int i;
1926 struct net_device *dev = idev ? idev->dev : NULL;
1927 struct addrconf_sysctl_table *t;
1928
1929 t = kmalloc(sizeof(*t), GFP_KERNEL);
1930 if (t == NULL)
1931 return;
1932 memcpy(t, &addrconf_sysctl, sizeof(*t));
1933 for (i=0; i<sizeof(t->addrconf_vars)/sizeof(t->addrconf_vars[0])-1; i++) {
1934 t->addrconf_vars[i].data += (char*)p - (char*)&ipv6_devconf;
1935 t->addrconf_vars[i].de = NULL;
1936 }
1937 if (dev) {
1938 t->addrconf_dev[0].procname = dev->name;
1939 t->addrconf_dev[0].ctl_name = dev->ifindex;
1940 } else {
1941 t->addrconf_dev[0].procname = "default";
1942 t->addrconf_dev[0].ctl_name = NET_PROTO_CONF_DEFAULT;
1943 }
1944 t->addrconf_dev[0].child = t->addrconf_vars;
1945 t->addrconf_dev[0].de = NULL;
1946 t->addrconf_conf_dir[0].child = t->addrconf_dev;
1947 t->addrconf_conf_dir[0].de = NULL;
1948 t->addrconf_proto_dir[0].child = t->addrconf_conf_dir;
1949 t->addrconf_proto_dir[0].de = NULL;
1950 t->addrconf_root_dir[0].child = t->addrconf_proto_dir;
1951 t->addrconf_root_dir[0].de = NULL;
1952
1953 t->sysctl_header = register_sysctl_table(t->addrconf_root_dir, 0);
1954 if (t->sysctl_header == NULL)
1955 kfree(t);
1956 else
1957 p->sysctl = t;
1958 }
1959
1960 static void addrconf_sysctl_unregister(struct ipv6_devconf *p)
1961 {
1962 if (p->sysctl) {
1963 struct addrconf_sysctl_table *t = p->sysctl;
1964 p->sysctl = NULL;
1965 unregister_sysctl_table(t->sysctl_header);
1966 kfree(t);
1967 }
1968 }
1969
1970
1971 #endif
1972
1973 /*
1974 * Device notifier
1975 */
1976
1977 int register_inet6addr_notifier(struct notifier_block *nb)
1978 {
1979 return notifier_chain_register(&inet6addr_chain, nb);
1980 }
1981
1982 int unregister_inet6addr_notifier(struct notifier_block *nb)
1983 {
1984 return notifier_chain_unregister(&inet6addr_chain,nb);
1985 }
1986
1987 /*
1988 * Init / cleanup code
1989 */
1990
1991 void __init addrconf_init(void)
1992 {
1993 #ifdef MODULE
1994 struct net_device *dev;
1995
1996 /* This takes sense only during module load. */
1997 rtnl_lock();
1998 for (dev = dev_base; dev; dev = dev->next) {
1999 if (!(dev->flags&IFF_UP))
2000 continue;
2001
2002 switch (dev->type) {
2003 case ARPHRD_LOOPBACK:
2004 init_loopback(dev);
2005 break;
2006 case ARPHRD_ETHER:
2007 case ARPHRD_FDDI:
2008 case ARPHRD_IEEE802_TR:
2009 addrconf_dev_config(dev);
2010 break;
2011 default:;
2012 /* Ignore all other */
2013 }
2014 }
2015 rtnl_unlock();
2016 #endif
2017
2018 #ifdef CONFIG_PROC_FS
2019 proc_net_create("if_inet6", 0, iface_proc_info);
2020 #endif
2021
2022 addr_chk_timer.expires = jiffies + ADDR_CHECK_FREQUENCY;
2023 add_timer(&addr_chk_timer);
2024 #ifdef CONFIG_RTNETLINK
2025 rtnetlink_links[PF_INET6] = inet6_rtnetlink_table;
2026 #endif
2027 #ifdef CONFIG_SYSCTL
2028 addrconf_sysctl.sysctl_header =
2029 register_sysctl_table(addrconf_sysctl.addrconf_root_dir, 0);
2030 addrconf_sysctl_register(NULL, &ipv6_devconf_dflt);
2031 #endif
2032 }
2033
2034 #ifdef MODULE
2035 void addrconf_cleanup(void)
2036 {
2037 struct net_device *dev;
2038 struct inet6_dev *idev;
2039 struct inet6_ifaddr *ifa;
2040 int i;
2041
2042 #ifdef CONFIG_RTNETLINK
2043 rtnetlink_links[PF_INET6] = NULL;
2044 #endif
2045 #ifdef CONFIG_SYSCTL
2046 addrconf_sysctl_unregister(&ipv6_devconf_dflt);
2047 addrconf_sysctl_unregister(&ipv6_devconf);
2048 #endif
2049
2050 rtnl_lock();
2051
2052 /*
2053 * clean dev list.
2054 */
2055
2056 for (dev=dev_base; dev; dev=dev->next) {
2057 if ((idev = __in6_dev_get(dev)) == NULL)
2058 continue;
2059 addrconf_ifdown(dev, 1);
2060 }
2061
2062 /*
2063 * Check hash table.
2064 */
2065
2066 write_lock_bh(&addrconf_hash_lock);
2067 for (i=0; i < IN6_ADDR_HSIZE; i++) {
2068 for (ifa=inet6_addr_lst[i]; ifa; ) {
2069 struct inet6_ifaddr *bifa;
2070
2071 bifa = ifa;
2072 ifa = ifa->lst_next;
2073 printk(KERN_DEBUG "bug: IPv6 address leakage detected: ifa=%p\n", bifa);
2074 /* Do not free it; something is wrong.
2075 Now we can investigate it with debugger.
2076 */
2077 }
2078 }
2079 write_unlock_bh(&addrconf_hash_lock);
2080
2081 del_timer(&addr_chk_timer);
2082
2083 rtnl_unlock();
2084
2085 #ifdef CONFIG_PROC_FS
2086 proc_net_remove("if_inet6");
2087 #endif
2088 }
2089 #endif /* MODULE */
2090