addrconf.c (5f0e5afa0de4522abb3ea7d1369039b94e740ec5) | addrconf.c (8965779d2c0e6ab246c82a405236b1fb2adae6b2) |
---|---|
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 * --- 239 unchanged lines hidden (view full) --- 248const struct in6_addr in6addr_sitelocal_allrouters = IN6ADDR_SITELOCAL_ALLROUTERS_INIT; 249 250/* Check if a valid qdisc is available */ 251static inline bool addrconf_qdisc_ok(const struct net_device *dev) 252{ 253 return !qdisc_tx_is_noop(dev); 254} 255 | 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 * --- 239 unchanged lines hidden (view full) --- 248const struct in6_addr in6addr_sitelocal_allrouters = IN6ADDR_SITELOCAL_ALLROUTERS_INIT; 249 250/* Check if a valid qdisc is available */ 251static inline bool addrconf_qdisc_ok(const struct net_device *dev) 252{ 253 return !qdisc_tx_is_noop(dev); 254} 255 |
256static void addrconf_del_timer(struct inet6_ifaddr *ifp) | 256static void addrconf_del_rs_timer(struct inet6_dev *idev) |
257{ | 257{ |
258 if (del_timer(&ifp->timer)) | 258 if (del_timer(&idev->rs_timer)) 259 __in6_dev_put(idev); 260} 261 262static void addrconf_del_dad_timer(struct inet6_ifaddr *ifp) 263{ 264 if (del_timer(&ifp->dad_timer)) |
259 __in6_ifa_put(ifp); 260} 261 | 265 __in6_ifa_put(ifp); 266} 267 |
262enum addrconf_timer_t { 263 AC_NONE, 264 AC_DAD, 265 AC_RS, 266}; | 268static void addrconf_mod_rs_timer(struct inet6_dev *idev, 269 unsigned long when) 270{ 271 if (!timer_pending(&idev->rs_timer)) 272 in6_dev_hold(idev); 273 mod_timer(&idev->rs_timer, jiffies + when); 274} |
267 | 275 |
268static void addrconf_mod_timer(struct inet6_ifaddr *ifp, 269 enum addrconf_timer_t what, 270 unsigned long when) | 276static void addrconf_mod_dad_timer(struct inet6_ifaddr *ifp, 277 unsigned long when) |
271{ | 278{ |
272 if (!del_timer(&ifp->timer)) | 279 if (!timer_pending(&ifp->dad_timer)) |
273 in6_ifa_hold(ifp); | 280 in6_ifa_hold(ifp); |
274 275 switch (what) { 276 case AC_DAD: 277 ifp->timer.function = addrconf_dad_timer; 278 break; 279 case AC_RS: 280 ifp->timer.function = addrconf_rs_timer; 281 break; 282 default: 283 break; 284 } 285 ifp->timer.expires = jiffies + when; 286 add_timer(&ifp->timer); | 281 mod_timer(&ifp->dad_timer, jiffies + when); |
287} 288 289static int snmp6_alloc_dev(struct inet6_dev *idev) 290{ 291 if (snmp_mib_init((void __percpu **)idev->stats.ipv6, 292 sizeof(struct ipstats_mib), 293 __alignof__(struct ipstats_mib)) < 0) 294 goto err_ip; --- 26 unchanged lines hidden (view full) --- 321/* Nobody refers to this device, we may destroy it. */ 322 323void in6_dev_finish_destroy(struct inet6_dev *idev) 324{ 325 struct net_device *dev = idev->dev; 326 327 WARN_ON(!list_empty(&idev->addr_list)); 328 WARN_ON(idev->mc_list != NULL); | 282} 283 284static int snmp6_alloc_dev(struct inet6_dev *idev) 285{ 286 if (snmp_mib_init((void __percpu **)idev->stats.ipv6, 287 sizeof(struct ipstats_mib), 288 __alignof__(struct ipstats_mib)) < 0) 289 goto err_ip; --- 26 unchanged lines hidden (view full) --- 316/* Nobody refers to this device, we may destroy it. */ 317 318void in6_dev_finish_destroy(struct inet6_dev *idev) 319{ 320 struct net_device *dev = idev->dev; 321 322 WARN_ON(!list_empty(&idev->addr_list)); 323 WARN_ON(idev->mc_list != NULL); |
324 WARN_ON(timer_pending(&idev->rs_timer)); |
|
329 330#ifdef NET_REFCNT_DEBUG 331 pr_debug("%s: %s\n", __func__, dev ? dev->name : "NIL"); 332#endif 333 dev_put(dev); 334 if (!idev->dead) { 335 pr_warn("Freeing alive inet6 device %p\n", idev); 336 return; --- 15 unchanged lines hidden (view full) --- 352 ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL); 353 354 if (ndev == NULL) 355 return NULL; 356 357 rwlock_init(&ndev->lock); 358 ndev->dev = dev; 359 INIT_LIST_HEAD(&ndev->addr_list); | 325 326#ifdef NET_REFCNT_DEBUG 327 pr_debug("%s: %s\n", __func__, dev ? dev->name : "NIL"); 328#endif 329 dev_put(dev); 330 if (!idev->dead) { 331 pr_warn("Freeing alive inet6 device %p\n", idev); 332 return; --- 15 unchanged lines hidden (view full) --- 348 ndev = kzalloc(sizeof(struct inet6_dev), GFP_KERNEL); 349 350 if (ndev == NULL) 351 return NULL; 352 353 rwlock_init(&ndev->lock); 354 ndev->dev = dev; 355 INIT_LIST_HEAD(&ndev->addr_list); |
360 | 356 setup_timer(&ndev->rs_timer, addrconf_rs_timer, 357 (unsigned long)ndev); |
361 memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf)); 362 ndev->cnf.mtu6 = dev->mtu; 363 ndev->cnf.sysctl = NULL; 364 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl); 365 if (ndev->nd_parms == NULL) { 366 kfree(ndev); 367 return NULL; 368 } --- 402 unchanged lines hidden (view full) --- 771 WARN_ON(!hlist_unhashed(&ifp->addr_lst)); 772 773#ifdef NET_REFCNT_DEBUG 774 pr_debug("%s\n", __func__); 775#endif 776 777 in6_dev_put(ifp->idev); 778 | 358 memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf)); 359 ndev->cnf.mtu6 = dev->mtu; 360 ndev->cnf.sysctl = NULL; 361 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl); 362 if (ndev->nd_parms == NULL) { 363 kfree(ndev); 364 return NULL; 365 } --- 402 unchanged lines hidden (view full) --- 768 WARN_ON(!hlist_unhashed(&ifp->addr_lst)); 769 770#ifdef NET_REFCNT_DEBUG 771 pr_debug("%s\n", __func__); 772#endif 773 774 in6_dev_put(ifp->idev); 775 |
779 if (del_timer(&ifp->timer)) | 776 if (del_timer(&ifp->dad_timer)) |
780 pr_notice("Timer is still running, when freeing ifa=%p\n", ifp); 781 782 if (ifp->state != INET6_IFADDR_STATE_DEAD) { 783 pr_warn("Freeing alive inet6 address %p\n", ifp); 784 return; 785 } 786 ip6_rt_put(ifp->rt); 787 --- 76 unchanged lines hidden (view full) --- 864 err = PTR_ERR(rt); 865 goto out; 866 } 867 868 ifa->addr = *addr; 869 870 spin_lock_init(&ifa->lock); 871 spin_lock_init(&ifa->state_lock); | 777 pr_notice("Timer is still running, when freeing ifa=%p\n", ifp); 778 779 if (ifp->state != INET6_IFADDR_STATE_DEAD) { 780 pr_warn("Freeing alive inet6 address %p\n", ifp); 781 return; 782 } 783 ip6_rt_put(ifp->rt); 784 --- 76 unchanged lines hidden (view full) --- 861 err = PTR_ERR(rt); 862 goto out; 863 } 864 865 ifa->addr = *addr; 866 867 spin_lock_init(&ifa->lock); 868 spin_lock_init(&ifa->state_lock); |
872 init_timer(&ifa->timer); | 869 setup_timer(&ifa->dad_timer, addrconf_dad_timer, 870 (unsigned long)ifa); |
873 INIT_HLIST_NODE(&ifa->addr_lst); | 871 INIT_HLIST_NODE(&ifa->addr_lst); |
874 ifa->timer.data = (unsigned long) ifa; | |
875 ifa->scope = scope; 876 ifa->prefix_len = pfxlen; 877 ifa->flags = flags | IFA_F_TENTATIVE; 878 ifa->cstamp = ifa->tstamp = jiffies; 879 ifa->tokenized = false; 880 881 ifa->rt = rt; 882 --- 106 unchanged lines hidden (view full) --- 989 expires = ifa->tstamp + lifetime * HZ; 990 spin_unlock(&ifa->lock); 991 } 992 } 993 } 994 } 995 write_unlock_bh(&idev->lock); 996 | 872 ifa->scope = scope; 873 ifa->prefix_len = pfxlen; 874 ifa->flags = flags | IFA_F_TENTATIVE; 875 ifa->cstamp = ifa->tstamp = jiffies; 876 ifa->tokenized = false; 877 878 ifa->rt = rt; 879 --- 106 unchanged lines hidden (view full) --- 986 expires = ifa->tstamp + lifetime * HZ; 987 spin_unlock(&ifa->lock); 988 } 989 } 990 } 991 } 992 write_unlock_bh(&idev->lock); 993 |
997 addrconf_del_timer(ifp); | 994 addrconf_del_dad_timer(ifp); |
998 999 ipv6_ifa_notify(RTM_DELADDR, ifp); 1000 1001 inet6addr_notifier_call_chain(NETDEV_DOWN, ifp); 1002 1003 /* 1004 * Purge or update corresponding prefix 1005 * --- 115 unchanged lines hidden (view full) --- 1121 1122 addr_flags = IFA_F_TEMPORARY; 1123 /* set in addrconf_prefix_rcv() */ 1124 if (ifp->flags & IFA_F_OPTIMISTIC) 1125 addr_flags |= IFA_F_OPTIMISTIC; 1126 1127 ift = !max_addresses || 1128 ipv6_count_addresses(idev) < max_addresses ? | 995 996 ipv6_ifa_notify(RTM_DELADDR, ifp); 997 998 inet6addr_notifier_call_chain(NETDEV_DOWN, ifp); 999 1000 /* 1001 * Purge or update corresponding prefix 1002 * --- 115 unchanged lines hidden (view full) --- 1118 1119 addr_flags = IFA_F_TEMPORARY; 1120 /* set in addrconf_prefix_rcv() */ 1121 if (ifp->flags & IFA_F_OPTIMISTIC) 1122 addr_flags |= IFA_F_OPTIMISTIC; 1123 1124 ift = !max_addresses || 1125 ipv6_count_addresses(idev) < max_addresses ? |
1129 ipv6_add_addr(idev, &addr, tmp_plen, 1130 ipv6_addr_type(&addr)&IPV6_ADDR_SCOPE_MASK, | 1126 ipv6_add_addr(idev, &addr, tmp_plen, ipv6_addr_scope(&addr), |
1131 addr_flags) : NULL; 1132 if (IS_ERR_OR_NULL(ift)) { 1133 in6_ifa_put(ifp); 1134 in6_dev_put(idev); 1135 pr_info("%s: retry temporary address regeneration\n", __func__); 1136 tmpaddr = &addr; 1137 write_lock(&idev->lock); 1138 goto retry; --- 304 unchanged lines hidden (view full) --- 1443 return -EADDRNOTAVAIL; 1444 1445 *saddr = hiscore->ifa->addr; 1446 in6_ifa_put(hiscore->ifa); 1447 return 0; 1448} 1449EXPORT_SYMBOL(ipv6_dev_get_saddr); 1450 | 1127 addr_flags) : NULL; 1128 if (IS_ERR_OR_NULL(ift)) { 1129 in6_ifa_put(ifp); 1130 in6_dev_put(idev); 1131 pr_info("%s: retry temporary address regeneration\n", __func__); 1132 tmpaddr = &addr; 1133 write_lock(&idev->lock); 1134 goto retry; --- 304 unchanged lines hidden (view full) --- 1439 return -EADDRNOTAVAIL; 1440 1441 *saddr = hiscore->ifa->addr; 1442 in6_ifa_put(hiscore->ifa); 1443 return 0; 1444} 1445EXPORT_SYMBOL(ipv6_dev_get_saddr); 1446 |
1447int __ipv6_get_lladdr(struct inet6_dev *idev, struct in6_addr *addr, 1448 unsigned char banned_flags) 1449{ 1450 struct inet6_ifaddr *ifp; 1451 int err = -EADDRNOTAVAIL; 1452 1453 list_for_each_entry(ifp, &idev->addr_list, if_list) { 1454 if (ifp->scope == IFA_LINK && 1455 !(ifp->flags & banned_flags)) { 1456 *addr = ifp->addr; 1457 err = 0; 1458 break; 1459 } 1460 } 1461 return err; 1462} 1463 |
|
1451int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr, 1452 unsigned char banned_flags) 1453{ 1454 struct inet6_dev *idev; 1455 int err = -EADDRNOTAVAIL; 1456 1457 rcu_read_lock(); 1458 idev = __in6_dev_get(dev); 1459 if (idev) { | 1464int ipv6_get_lladdr(struct net_device *dev, struct in6_addr *addr, 1465 unsigned char banned_flags) 1466{ 1467 struct inet6_dev *idev; 1468 int err = -EADDRNOTAVAIL; 1469 1470 rcu_read_lock(); 1471 idev = __in6_dev_get(dev); 1472 if (idev) { |
1460 struct inet6_ifaddr *ifp; 1461 | |
1462 read_lock_bh(&idev->lock); | 1473 read_lock_bh(&idev->lock); |
1463 list_for_each_entry(ifp, &idev->addr_list, if_list) { 1464 if (ifp->scope == IFA_LINK && 1465 !(ifp->flags & banned_flags)) { 1466 *addr = ifp->addr; 1467 err = 0; 1468 break; 1469 } 1470 } | 1474 err = __ipv6_get_lladdr(idev, addr, banned_flags); |
1471 read_unlock_bh(&idev->lock); 1472 } 1473 rcu_read_unlock(); 1474 return err; 1475} 1476 1477static int ipv6_count_addresses(struct inet6_dev *idev) 1478{ --- 97 unchanged lines hidden (view full) --- 1576} 1577 1578/* Gets referenced address, destroys ifaddr */ 1579 1580static void addrconf_dad_stop(struct inet6_ifaddr *ifp, int dad_failed) 1581{ 1582 if (ifp->flags&IFA_F_PERMANENT) { 1583 spin_lock_bh(&ifp->lock); | 1475 read_unlock_bh(&idev->lock); 1476 } 1477 rcu_read_unlock(); 1478 return err; 1479} 1480 1481static int ipv6_count_addresses(struct inet6_dev *idev) 1482{ --- 97 unchanged lines hidden (view full) --- 1580} 1581 1582/* Gets referenced address, destroys ifaddr */ 1583 1584static void addrconf_dad_stop(struct inet6_ifaddr *ifp, int dad_failed) 1585{ 1586 if (ifp->flags&IFA_F_PERMANENT) { 1587 spin_lock_bh(&ifp->lock); |
1584 addrconf_del_timer(ifp); | 1588 addrconf_del_dad_timer(ifp); |
1585 ifp->flags |= IFA_F_TENTATIVE; 1586 if (dad_failed) 1587 ifp->flags |= IFA_F_DADFAILED; 1588 spin_unlock_bh(&ifp->lock); 1589 if (dad_failed) 1590 ipv6_ifa_notify(0, ifp); 1591 in6_ifa_put(ifp); 1592#ifdef CONFIG_IPV6_PRIVACY --- 804 unchanged lines hidden (view full) --- 2397 rtnl_unlock(); 2398 return err; 2399} 2400 2401/* 2402 * Manual configuration of address on an interface 2403 */ 2404static int inet6_addr_add(struct net *net, int ifindex, const struct in6_addr *pfx, | 1589 ifp->flags |= IFA_F_TENTATIVE; 1590 if (dad_failed) 1591 ifp->flags |= IFA_F_DADFAILED; 1592 spin_unlock_bh(&ifp->lock); 1593 if (dad_failed) 1594 ipv6_ifa_notify(0, ifp); 1595 in6_ifa_put(ifp); 1596#ifdef CONFIG_IPV6_PRIVACY --- 804 unchanged lines hidden (view full) --- 2401 rtnl_unlock(); 2402 return err; 2403} 2404 2405/* 2406 * Manual configuration of address on an interface 2407 */ 2408static int inet6_addr_add(struct net *net, int ifindex, const struct in6_addr *pfx, |
2409 const struct in6_addr *peer_pfx, |
|
2405 unsigned int plen, __u8 ifa_flags, __u32 prefered_lft, 2406 __u32 valid_lft) 2407{ 2408 struct inet6_ifaddr *ifp; 2409 struct inet6_dev *idev; 2410 struct net_device *dev; 2411 int scope; 2412 u32 flags; --- 39 unchanged lines hidden (view full) --- 2452 2453 ifp = ipv6_add_addr(idev, pfx, plen, scope, ifa_flags); 2454 2455 if (!IS_ERR(ifp)) { 2456 spin_lock_bh(&ifp->lock); 2457 ifp->valid_lft = valid_lft; 2458 ifp->prefered_lft = prefered_lft; 2459 ifp->tstamp = jiffies; | 2410 unsigned int plen, __u8 ifa_flags, __u32 prefered_lft, 2411 __u32 valid_lft) 2412{ 2413 struct inet6_ifaddr *ifp; 2414 struct inet6_dev *idev; 2415 struct net_device *dev; 2416 int scope; 2417 u32 flags; --- 39 unchanged lines hidden (view full) --- 2457 2458 ifp = ipv6_add_addr(idev, pfx, plen, scope, ifa_flags); 2459 2460 if (!IS_ERR(ifp)) { 2461 spin_lock_bh(&ifp->lock); 2462 ifp->valid_lft = valid_lft; 2463 ifp->prefered_lft = prefered_lft; 2464 ifp->tstamp = jiffies; |
2465 if (peer_pfx) 2466 ifp->peer_addr = *peer_pfx; |
|
2460 spin_unlock_bh(&ifp->lock); 2461 2462 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, 2463 expires, flags); 2464 /* 2465 * Note that section 3.1 of RFC 4429 indicates 2466 * that the Optimistic flag should not be set for 2467 * manually configured addresses --- 27 unchanged lines hidden (view full) --- 2495 read_lock_bh(&idev->lock); 2496 list_for_each_entry(ifp, &idev->addr_list, if_list) { 2497 if (ifp->prefix_len == plen && 2498 ipv6_addr_equal(pfx, &ifp->addr)) { 2499 in6_ifa_hold(ifp); 2500 read_unlock_bh(&idev->lock); 2501 2502 ipv6_del_addr(ifp); | 2467 spin_unlock_bh(&ifp->lock); 2468 2469 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, 2470 expires, flags); 2471 /* 2472 * Note that section 3.1 of RFC 4429 indicates 2473 * that the Optimistic flag should not be set for 2474 * manually configured addresses --- 27 unchanged lines hidden (view full) --- 2502 read_lock_bh(&idev->lock); 2503 list_for_each_entry(ifp, &idev->addr_list, if_list) { 2504 if (ifp->prefix_len == plen && 2505 ipv6_addr_equal(pfx, &ifp->addr)) { 2506 in6_ifa_hold(ifp); 2507 read_unlock_bh(&idev->lock); 2508 2509 ipv6_del_addr(ifp); |
2503 2504 /* If the last address is deleted administratively, 2505 disable IPv6 on this interface. 2506 */ 2507 if (list_empty(&idev->addr_list)) 2508 addrconf_ifdown(idev->dev, 1); | |
2509 return 0; 2510 } 2511 } 2512 read_unlock_bh(&idev->lock); 2513 return -EADDRNOTAVAIL; 2514} 2515 2516 --- 4 unchanged lines hidden (view full) --- 2521 2522 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) 2523 return -EPERM; 2524 2525 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) 2526 return -EFAULT; 2527 2528 rtnl_lock(); | 2510 return 0; 2511 } 2512 } 2513 read_unlock_bh(&idev->lock); 2514 return -EADDRNOTAVAIL; 2515} 2516 2517 --- 4 unchanged lines hidden (view full) --- 2522 2523 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) 2524 return -EPERM; 2525 2526 if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq))) 2527 return -EFAULT; 2528 2529 rtnl_lock(); |
2529 err = inet6_addr_add(net, ireq.ifr6_ifindex, &ireq.ifr6_addr, | 2530 err = inet6_addr_add(net, ireq.ifr6_ifindex, &ireq.ifr6_addr, NULL, |
2530 ireq.ifr6_prefixlen, IFA_F_PERMANENT, 2531 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME); 2532 rtnl_unlock(); 2533 return err; 2534} 2535 2536int addrconf_del_ifaddr(struct net *net, void __user *arg) 2537{ --- 215 unchanged lines hidden (view full) --- 2753#endif 2754 2755#if IS_ENABLED(CONFIG_NET_IPGRE) 2756static void addrconf_gre_config(struct net_device *dev) 2757{ 2758 struct inet6_dev *idev; 2759 struct in6_addr addr; 2760 | 2531 ireq.ifr6_prefixlen, IFA_F_PERMANENT, 2532 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME); 2533 rtnl_unlock(); 2534 return err; 2535} 2536 2537int addrconf_del_ifaddr(struct net *net, void __user *arg) 2538{ --- 215 unchanged lines hidden (view full) --- 2754#endif 2755 2756#if IS_ENABLED(CONFIG_NET_IPGRE) 2757static void addrconf_gre_config(struct net_device *dev) 2758{ 2759 struct inet6_dev *idev; 2760 struct in6_addr addr; 2761 |
2761 pr_info("%s(%s)\n", __func__, dev->name); 2762 | |
2763 ASSERT_RTNL(); 2764 2765 if ((idev = ipv6_find_idev(dev)) == NULL) { 2766 pr_debug("%s: add_dev failed\n", __func__); 2767 return; 2768 } 2769 2770 ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0); --- 50 unchanged lines hidden (view full) --- 2821 if (IS_ERR(idev)) { 2822 pr_debug("init ip6-ip6: add_dev failed\n"); 2823 return; 2824 } 2825 ip6_tnl_add_linklocal(idev); 2826} 2827 2828static int addrconf_notify(struct notifier_block *this, unsigned long event, | 2762 ASSERT_RTNL(); 2763 2764 if ((idev = ipv6_find_idev(dev)) == NULL) { 2765 pr_debug("%s: add_dev failed\n", __func__); 2766 return; 2767 } 2768 2769 ipv6_addr_set(&addr, htonl(0xFE800000), 0, 0, 0); --- 50 unchanged lines hidden (view full) --- 2820 if (IS_ERR(idev)) { 2821 pr_debug("init ip6-ip6: add_dev failed\n"); 2822 return; 2823 } 2824 ip6_tnl_add_linklocal(idev); 2825} 2826 2827static int addrconf_notify(struct notifier_block *this, unsigned long event, |
2829 void *data) | 2828 void *ptr) |
2830{ | 2829{ |
2831 struct net_device *dev = (struct net_device *) data; | 2830 struct net_device *dev = netdev_notifier_info_to_dev(ptr); |
2832 struct inet6_dev *idev = __in6_dev_get(dev); 2833 int run_pending = 0; 2834 int err; 2835 2836 switch (event) { 2837 case NETDEV_REGISTER: 2838 if (!idev && dev->mtu >= IPV6_MIN_MTU) { 2839 idev = ipv6_add_dev(dev); --- 191 unchanged lines hidden (view full) --- 3031 for (i = 0; i < IN6_ADDR_HSIZE; i++) { 3032 struct hlist_head *h = &inet6_addr_lst[i]; 3033 3034 spin_lock_bh(&addrconf_hash_lock); 3035 restart: 3036 hlist_for_each_entry_rcu(ifa, h, addr_lst) { 3037 if (ifa->idev == idev) { 3038 hlist_del_init_rcu(&ifa->addr_lst); | 2831 struct inet6_dev *idev = __in6_dev_get(dev); 2832 int run_pending = 0; 2833 int err; 2834 2835 switch (event) { 2836 case NETDEV_REGISTER: 2837 if (!idev && dev->mtu >= IPV6_MIN_MTU) { 2838 idev = ipv6_add_dev(dev); --- 191 unchanged lines hidden (view full) --- 3030 for (i = 0; i < IN6_ADDR_HSIZE; i++) { 3031 struct hlist_head *h = &inet6_addr_lst[i]; 3032 3033 spin_lock_bh(&addrconf_hash_lock); 3034 restart: 3035 hlist_for_each_entry_rcu(ifa, h, addr_lst) { 3036 if (ifa->idev == idev) { 3037 hlist_del_init_rcu(&ifa->addr_lst); |
3039 addrconf_del_timer(ifa); | 3038 addrconf_del_dad_timer(ifa); |
3040 goto restart; 3041 } 3042 } 3043 spin_unlock_bh(&addrconf_hash_lock); 3044 } 3045 3046 write_lock_bh(&idev->lock); 3047 | 3039 goto restart; 3040 } 3041 } 3042 spin_unlock_bh(&addrconf_hash_lock); 3043 } 3044 3045 write_lock_bh(&idev->lock); 3046 |
3047 addrconf_del_rs_timer(idev); 3048 |
|
3048 /* Step 2: clear flags for stateless addrconf */ 3049 if (!how) 3050 idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); 3051 3052#ifdef CONFIG_IPV6_PRIVACY 3053 if (how && del_timer(&idev->regen_timer)) 3054 in6_dev_put(idev); 3055 --- 13 unchanged lines hidden (view full) --- 3069 in6_ifa_put(ifa); 3070 write_lock_bh(&idev->lock); 3071 } 3072#endif 3073 3074 while (!list_empty(&idev->addr_list)) { 3075 ifa = list_first_entry(&idev->addr_list, 3076 struct inet6_ifaddr, if_list); | 3049 /* Step 2: clear flags for stateless addrconf */ 3050 if (!how) 3051 idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); 3052 3053#ifdef CONFIG_IPV6_PRIVACY 3054 if (how && del_timer(&idev->regen_timer)) 3055 in6_dev_put(idev); 3056 --- 13 unchanged lines hidden (view full) --- 3070 in6_ifa_put(ifa); 3071 write_lock_bh(&idev->lock); 3072 } 3073#endif 3074 3075 while (!list_empty(&idev->addr_list)) { 3076 ifa = list_first_entry(&idev->addr_list, 3077 struct inet6_ifaddr, if_list); |
3077 addrconf_del_timer(ifa); | 3078 addrconf_del_dad_timer(ifa); |
3078 3079 list_del(&ifa->if_list); 3080 3081 write_unlock_bh(&idev->lock); 3082 3083 spin_lock_bh(&ifa->state_lock); 3084 state = ifa->state; 3085 ifa->state = INET6_IFADDR_STATE_DEAD; --- 25 unchanged lines hidden (view full) --- 3111 neigh_ifdown(&nd_tbl, dev); 3112 in6_dev_put(idev); 3113 } 3114 return 0; 3115} 3116 3117static void addrconf_rs_timer(unsigned long data) 3118{ | 3079 3080 list_del(&ifa->if_list); 3081 3082 write_unlock_bh(&idev->lock); 3083 3084 spin_lock_bh(&ifa->state_lock); 3085 state = ifa->state; 3086 ifa->state = INET6_IFADDR_STATE_DEAD; --- 25 unchanged lines hidden (view full) --- 3112 neigh_ifdown(&nd_tbl, dev); 3113 in6_dev_put(idev); 3114 } 3115 return 0; 3116} 3117 3118static void addrconf_rs_timer(unsigned long data) 3119{ |
3119 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data; 3120 struct inet6_dev *idev = ifp->idev; | 3120 struct inet6_dev *idev = (struct inet6_dev *)data; 3121 struct in6_addr lladdr; |
3121 | 3122 |
3122 read_lock(&idev->lock); | 3123 write_lock(&idev->lock); |
3123 if (idev->dead || !(idev->if_flags & IF_READY)) 3124 goto out; 3125 3126 if (!ipv6_accept_ra(idev)) 3127 goto out; 3128 3129 /* Announcement received after solicitation was sent */ 3130 if (idev->if_flags & IF_RA_RCVD) 3131 goto out; 3132 | 3124 if (idev->dead || !(idev->if_flags & IF_READY)) 3125 goto out; 3126 3127 if (!ipv6_accept_ra(idev)) 3128 goto out; 3129 3130 /* Announcement received after solicitation was sent */ 3131 if (idev->if_flags & IF_RA_RCVD) 3132 goto out; 3133 |
3133 spin_lock(&ifp->lock); 3134 if (ifp->probes++ < idev->cnf.rtr_solicits) { 3135 /* The wait after the last probe can be shorter */ 3136 addrconf_mod_timer(ifp, AC_RS, 3137 (ifp->probes == idev->cnf.rtr_solicits) ? 3138 idev->cnf.rtr_solicit_delay : 3139 idev->cnf.rtr_solicit_interval); 3140 spin_unlock(&ifp->lock); | 3134 if (idev->rs_probes++ < idev->cnf.rtr_solicits) { 3135 if (!__ipv6_get_lladdr(idev, &lladdr, IFA_F_TENTATIVE)) 3136 ndisc_send_rs(idev->dev, &lladdr, 3137 &in6addr_linklocal_allrouters); 3138 else 3139 goto out; |
3141 | 3140 |
3142 ndisc_send_rs(idev->dev, &ifp->addr, &in6addr_linklocal_allrouters); | 3141 /* The wait after the last probe can be shorter */ 3142 addrconf_mod_rs_timer(idev, (idev->rs_probes == 3143 idev->cnf.rtr_solicits) ? 3144 idev->cnf.rtr_solicit_delay : 3145 idev->cnf.rtr_solicit_interval); |
3143 } else { | 3146 } else { |
3144 spin_unlock(&ifp->lock); | |
3145 /* 3146 * Note: we do not support deprecated "all on-link" 3147 * assumption any longer. 3148 */ 3149 pr_debug("%s: no IPv6 routers present\n", idev->dev->name); 3150 } 3151 3152out: | 3147 /* 3148 * Note: we do not support deprecated "all on-link" 3149 * assumption any longer. 3150 */ 3151 pr_debug("%s: no IPv6 routers present\n", idev->dev->name); 3152 } 3153 3154out: |
3153 read_unlock(&idev->lock); 3154 in6_ifa_put(ifp); | 3155 write_unlock(&idev->lock); 3156 in6_dev_put(idev); |
3155} 3156 3157/* 3158 * Duplicate Address Detection 3159 */ 3160static void addrconf_dad_kick(struct inet6_ifaddr *ifp) 3161{ 3162 unsigned long rand_num; 3163 struct inet6_dev *idev = ifp->idev; 3164 3165 if (ifp->flags & IFA_F_OPTIMISTIC) 3166 rand_num = 0; 3167 else 3168 rand_num = net_random() % (idev->cnf.rtr_solicit_delay ? : 1); 3169 | 3157} 3158 3159/* 3160 * Duplicate Address Detection 3161 */ 3162static void addrconf_dad_kick(struct inet6_ifaddr *ifp) 3163{ 3164 unsigned long rand_num; 3165 struct inet6_dev *idev = ifp->idev; 3166 3167 if (ifp->flags & IFA_F_OPTIMISTIC) 3168 rand_num = 0; 3169 else 3170 rand_num = net_random() % (idev->cnf.rtr_solicit_delay ? : 1); 3171 |
3170 ifp->probes = idev->cnf.dad_transmits; 3171 addrconf_mod_timer(ifp, AC_DAD, rand_num); | 3172 ifp->dad_probes = idev->cnf.dad_transmits; 3173 addrconf_mod_dad_timer(ifp, rand_num); |
3172} 3173 3174static void addrconf_dad_start(struct inet6_ifaddr *ifp) 3175{ 3176 struct inet6_dev *idev = ifp->idev; 3177 struct net_device *dev = idev->dev; 3178 3179 addrconf_join_solict(dev, &ifp->addr); --- 44 unchanged lines hidden (view full) --- 3224} 3225 3226static void addrconf_dad_timer(unsigned long data) 3227{ 3228 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data; 3229 struct inet6_dev *idev = ifp->idev; 3230 struct in6_addr mcaddr; 3231 | 3174} 3175 3176static void addrconf_dad_start(struct inet6_ifaddr *ifp) 3177{ 3178 struct inet6_dev *idev = ifp->idev; 3179 struct net_device *dev = idev->dev; 3180 3181 addrconf_join_solict(dev, &ifp->addr); --- 44 unchanged lines hidden (view full) --- 3226} 3227 3228static void addrconf_dad_timer(unsigned long data) 3229{ 3230 struct inet6_ifaddr *ifp = (struct inet6_ifaddr *) data; 3231 struct inet6_dev *idev = ifp->idev; 3232 struct in6_addr mcaddr; 3233 |
3232 if (!ifp->probes && addrconf_dad_end(ifp)) | 3234 if (!ifp->dad_probes && addrconf_dad_end(ifp)) |
3233 goto out; 3234 | 3235 goto out; 3236 |
3235 read_lock(&idev->lock); | 3237 write_lock(&idev->lock); |
3236 if (idev->dead || !(idev->if_flags & IF_READY)) { | 3238 if (idev->dead || !(idev->if_flags & IF_READY)) { |
3237 read_unlock(&idev->lock); | 3239 write_unlock(&idev->lock); |
3238 goto out; 3239 } 3240 3241 spin_lock(&ifp->lock); 3242 if (ifp->state == INET6_IFADDR_STATE_DEAD) { 3243 spin_unlock(&ifp->lock); | 3240 goto out; 3241 } 3242 3243 spin_lock(&ifp->lock); 3244 if (ifp->state == INET6_IFADDR_STATE_DEAD) { 3245 spin_unlock(&ifp->lock); |
3244 read_unlock(&idev->lock); | 3246 write_unlock(&idev->lock); |
3245 goto out; 3246 } 3247 | 3247 goto out; 3248 } 3249 |
3248 if (ifp->probes == 0) { | 3250 if (ifp->dad_probes == 0) { |
3249 /* 3250 * DAD was successful 3251 */ 3252 3253 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); 3254 spin_unlock(&ifp->lock); | 3251 /* 3252 * DAD was successful 3253 */ 3254 3255 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); 3256 spin_unlock(&ifp->lock); |
3255 read_unlock(&idev->lock); | 3257 write_unlock(&idev->lock); |
3256 3257 addrconf_dad_completed(ifp); 3258 3259 goto out; 3260 } 3261 | 3258 3259 addrconf_dad_completed(ifp); 3260 3261 goto out; 3262 } 3263 |
3262 ifp->probes--; 3263 addrconf_mod_timer(ifp, AC_DAD, ifp->idev->nd_parms->retrans_time); | 3264 ifp->dad_probes--; 3265 addrconf_mod_dad_timer(ifp, ifp->idev->nd_parms->retrans_time); |
3264 spin_unlock(&ifp->lock); | 3266 spin_unlock(&ifp->lock); |
3265 read_unlock(&idev->lock); | 3267 write_unlock(&idev->lock); |
3266 3267 /* send a neighbour solicitation for our addr */ 3268 addrconf_addr_solict_mult(&ifp->addr, &mcaddr); 3269 ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &in6addr_any); 3270out: 3271 in6_ifa_put(ifp); 3272} 3273 3274static void addrconf_dad_completed(struct inet6_ifaddr *ifp) 3275{ 3276 struct net_device *dev = ifp->idev->dev; | 3268 3269 /* send a neighbour solicitation for our addr */ 3270 addrconf_addr_solict_mult(&ifp->addr, &mcaddr); 3271 ndisc_send_ns(ifp->idev->dev, NULL, &ifp->addr, &mcaddr, &in6addr_any); 3272out: 3273 in6_ifa_put(ifp); 3274} 3275 3276static void addrconf_dad_completed(struct inet6_ifaddr *ifp) 3277{ 3278 struct net_device *dev = ifp->idev->dev; |
3279 struct in6_addr lladdr; 3280 bool send_rs, send_mld; |
|
3277 | 3281 |
3282 addrconf_del_dad_timer(ifp); 3283 |
|
3278 /* 3279 * Configure the address for reception. Now it is valid. 3280 */ 3281 3282 ipv6_ifa_notify(RTM_NEWADDR, ifp); 3283 3284 /* If added prefix is link local and we are prepared to process 3285 router advertisements, start sending router solicitations. 3286 */ 3287 | 3284 /* 3285 * Configure the address for reception. Now it is valid. 3286 */ 3287 3288 ipv6_ifa_notify(RTM_NEWADDR, ifp); 3289 3290 /* If added prefix is link local and we are prepared to process 3291 router advertisements, start sending router solicitations. 3292 */ 3293 |
3288 if (ipv6_accept_ra(ifp->idev) && 3289 ifp->idev->cnf.rtr_solicits > 0 && 3290 (dev->flags&IFF_LOOPBACK) == 0 && 3291 (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) { | 3294 read_lock_bh(&ifp->idev->lock); 3295 spin_lock(&ifp->lock); 3296 send_mld = ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL && 3297 ifp->idev->valid_ll_addr_cnt == 1; 3298 send_rs = send_mld && 3299 ipv6_accept_ra(ifp->idev) && 3300 ifp->idev->cnf.rtr_solicits > 0 && 3301 (dev->flags&IFF_LOOPBACK) == 0; 3302 spin_unlock(&ifp->lock); 3303 read_unlock_bh(&ifp->idev->lock); 3304 3305 /* While dad is in progress mld report's source address is in6_addrany. 3306 * Resend with proper ll now. 3307 */ 3308 if (send_mld) 3309 ipv6_mc_dad_complete(ifp->idev); 3310 3311 if (send_rs) { |
3292 /* 3293 * If a host as already performed a random delay 3294 * [...] as part of DAD [...] there is no need 3295 * to delay again before sending the first RS 3296 */ | 3312 /* 3313 * If a host as already performed a random delay 3314 * [...] as part of DAD [...] there is no need 3315 * to delay again before sending the first RS 3316 */ |
3297 ndisc_send_rs(ifp->idev->dev, &ifp->addr, &in6addr_linklocal_allrouters); | 3317 if (ipv6_get_lladdr(dev, &lladdr, IFA_F_TENTATIVE)) 3318 return; 3319 ndisc_send_rs(dev, &lladdr, &in6addr_linklocal_allrouters); |
3298 | 3320 |
3299 spin_lock_bh(&ifp->lock); 3300 ifp->probes = 1; | 3321 write_lock_bh(&ifp->idev->lock); 3322 spin_lock(&ifp->lock); 3323 ifp->idev->rs_probes = 1; |
3301 ifp->idev->if_flags |= IF_RS_SENT; | 3324 ifp->idev->if_flags |= IF_RS_SENT; |
3302 addrconf_mod_timer(ifp, AC_RS, ifp->idev->cnf.rtr_solicit_interval); 3303 spin_unlock_bh(&ifp->lock); | 3325 addrconf_mod_rs_timer(ifp->idev, 3326 ifp->idev->cnf.rtr_solicit_interval); 3327 spin_unlock(&ifp->lock); 3328 write_unlock_bh(&ifp->idev->lock); |
3304 } 3305} 3306 3307static void addrconf_dad_run(struct inet6_dev *idev) 3308{ 3309 struct inet6_ifaddr *ifp; 3310 3311 read_lock_bh(&idev->lock); --- 295 unchanged lines hidden (view full) --- 3607 now, next, next_sec, next_sched)); 3608 3609 addr_chk_timer.expires = next_sched; 3610 add_timer(&addr_chk_timer); 3611 spin_unlock(&addrconf_verify_lock); 3612 rcu_read_unlock_bh(); 3613} 3614 | 3329 } 3330} 3331 3332static void addrconf_dad_run(struct inet6_dev *idev) 3333{ 3334 struct inet6_ifaddr *ifp; 3335 3336 read_lock_bh(&idev->lock); --- 295 unchanged lines hidden (view full) --- 3632 now, next, next_sec, next_sched)); 3633 3634 addr_chk_timer.expires = next_sched; 3635 add_timer(&addr_chk_timer); 3636 spin_unlock(&addrconf_verify_lock); 3637 rcu_read_unlock_bh(); 3638} 3639 |
3615static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local) | 3640static struct in6_addr *extract_addr(struct nlattr *addr, struct nlattr *local, 3641 struct in6_addr **peer_pfx) |
3616{ 3617 struct in6_addr *pfx = NULL; 3618 | 3642{ 3643 struct in6_addr *pfx = NULL; 3644 |
3645 *peer_pfx = NULL; 3646 |
|
3619 if (addr) 3620 pfx = nla_data(addr); 3621 3622 if (local) { 3623 if (pfx && nla_memcmp(local, pfx, sizeof(*pfx))) | 3647 if (addr) 3648 pfx = nla_data(addr); 3649 3650 if (local) { 3651 if (pfx && nla_memcmp(local, pfx, sizeof(*pfx))) |
3624 pfx = NULL; 3625 else 3626 pfx = nla_data(local); | 3652 *peer_pfx = pfx; 3653 pfx = nla_data(local); |
3627 } 3628 3629 return pfx; 3630} 3631 3632static const struct nla_policy ifa_ipv6_policy[IFA_MAX+1] = { 3633 [IFA_ADDRESS] = { .len = sizeof(struct in6_addr) }, 3634 [IFA_LOCAL] = { .len = sizeof(struct in6_addr) }, 3635 [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) }, 3636}; 3637 3638static int 3639inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh) 3640{ 3641 struct net *net = sock_net(skb->sk); 3642 struct ifaddrmsg *ifm; 3643 struct nlattr *tb[IFA_MAX+1]; | 3654 } 3655 3656 return pfx; 3657} 3658 3659static const struct nla_policy ifa_ipv6_policy[IFA_MAX+1] = { 3660 [IFA_ADDRESS] = { .len = sizeof(struct in6_addr) }, 3661 [IFA_LOCAL] = { .len = sizeof(struct in6_addr) }, 3662 [IFA_CACHEINFO] = { .len = sizeof(struct ifa_cacheinfo) }, 3663}; 3664 3665static int 3666inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh) 3667{ 3668 struct net *net = sock_net(skb->sk); 3669 struct ifaddrmsg *ifm; 3670 struct nlattr *tb[IFA_MAX+1]; |
3644 struct in6_addr *pfx; | 3671 struct in6_addr *pfx, *peer_pfx; |
3645 int err; 3646 3647 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); 3648 if (err < 0) 3649 return err; 3650 3651 ifm = nlmsg_data(nlh); | 3672 int err; 3673 3674 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); 3675 if (err < 0) 3676 return err; 3677 3678 ifm = nlmsg_data(nlh); |
3652 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]); | 3679 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer_pfx); |
3653 if (pfx == NULL) 3654 return -EINVAL; 3655 3656 return inet6_addr_del(net, ifm->ifa_index, pfx, ifm->ifa_prefixlen); 3657} 3658 3659static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags, 3660 u32 prefered_lft, u32 valid_lft) --- 41 unchanged lines hidden (view full) --- 3702} 3703 3704static int 3705inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh) 3706{ 3707 struct net *net = sock_net(skb->sk); 3708 struct ifaddrmsg *ifm; 3709 struct nlattr *tb[IFA_MAX+1]; | 3680 if (pfx == NULL) 3681 return -EINVAL; 3682 3683 return inet6_addr_del(net, ifm->ifa_index, pfx, ifm->ifa_prefixlen); 3684} 3685 3686static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags, 3687 u32 prefered_lft, u32 valid_lft) --- 41 unchanged lines hidden (view full) --- 3729} 3730 3731static int 3732inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh) 3733{ 3734 struct net *net = sock_net(skb->sk); 3735 struct ifaddrmsg *ifm; 3736 struct nlattr *tb[IFA_MAX+1]; |
3710 struct in6_addr *pfx; | 3737 struct in6_addr *pfx, *peer_pfx; |
3711 struct inet6_ifaddr *ifa; 3712 struct net_device *dev; 3713 u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME; 3714 u8 ifa_flags; 3715 int err; 3716 3717 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); 3718 if (err < 0) 3719 return err; 3720 3721 ifm = nlmsg_data(nlh); | 3738 struct inet6_ifaddr *ifa; 3739 struct net_device *dev; 3740 u32 valid_lft = INFINITY_LIFE_TIME, preferred_lft = INFINITY_LIFE_TIME; 3741 u8 ifa_flags; 3742 int err; 3743 3744 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); 3745 if (err < 0) 3746 return err; 3747 3748 ifm = nlmsg_data(nlh); |
3722 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]); | 3749 pfx = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer_pfx); |
3723 if (pfx == NULL) 3724 return -EINVAL; 3725 3726 if (tb[IFA_CACHEINFO]) { 3727 struct ifa_cacheinfo *ci; 3728 3729 ci = nla_data(tb[IFA_CACHEINFO]); 3730 valid_lft = ci->ifa_valid; --- 11 unchanged lines hidden (view full) --- 3742 ifa_flags = ifm->ifa_flags & (IFA_F_NODAD | IFA_F_HOMEADDRESS); 3743 3744 ifa = ipv6_get_ifaddr(net, pfx, dev, 1); 3745 if (ifa == NULL) { 3746 /* 3747 * It would be best to check for !NLM_F_CREATE here but 3748 * userspace alreay relies on not having to provide this. 3749 */ | 3750 if (pfx == NULL) 3751 return -EINVAL; 3752 3753 if (tb[IFA_CACHEINFO]) { 3754 struct ifa_cacheinfo *ci; 3755 3756 ci = nla_data(tb[IFA_CACHEINFO]); 3757 valid_lft = ci->ifa_valid; --- 11 unchanged lines hidden (view full) --- 3769 ifa_flags = ifm->ifa_flags & (IFA_F_NODAD | IFA_F_HOMEADDRESS); 3770 3771 ifa = ipv6_get_ifaddr(net, pfx, dev, 1); 3772 if (ifa == NULL) { 3773 /* 3774 * It would be best to check for !NLM_F_CREATE here but 3775 * userspace alreay relies on not having to provide this. 3776 */ |
3750 return inet6_addr_add(net, ifm->ifa_index, pfx, | 3777 return inet6_addr_add(net, ifm->ifa_index, pfx, peer_pfx, |
3751 ifm->ifa_prefixlen, ifa_flags, 3752 preferred_lft, valid_lft); 3753 } 3754 3755 if (nlh->nlmsg_flags & NLM_F_EXCL || 3756 !(nlh->nlmsg_flags & NLM_F_REPLACE)) 3757 err = -EEXIST; 3758 else --- 40 unchanged lines hidden (view full) --- 3799 return RT_SCOPE_SITE; 3800 else 3801 return RT_SCOPE_UNIVERSE; 3802} 3803 3804static inline int inet6_ifaddr_msgsize(void) 3805{ 3806 return NLMSG_ALIGN(sizeof(struct ifaddrmsg)) | 3778 ifm->ifa_prefixlen, ifa_flags, 3779 preferred_lft, valid_lft); 3780 } 3781 3782 if (nlh->nlmsg_flags & NLM_F_EXCL || 3783 !(nlh->nlmsg_flags & NLM_F_REPLACE)) 3784 err = -EEXIST; 3785 else --- 40 unchanged lines hidden (view full) --- 3826 return RT_SCOPE_SITE; 3827 else 3828 return RT_SCOPE_UNIVERSE; 3829} 3830 3831static inline int inet6_ifaddr_msgsize(void) 3832{ 3833 return NLMSG_ALIGN(sizeof(struct ifaddrmsg)) |
3834 + nla_total_size(16) /* IFA_LOCAL */ |
|
3807 + nla_total_size(16) /* IFA_ADDRESS */ 3808 + nla_total_size(sizeof(struct ifa_cacheinfo)); 3809} 3810 3811static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa, 3812 u32 portid, u32 seq, int event, unsigned int flags) 3813{ 3814 struct nlmsghdr *nlh; --- 22 unchanged lines hidden (view full) --- 3837 valid = 0; 3838 } 3839 } 3840 } else { 3841 preferred = INFINITY_LIFE_TIME; 3842 valid = INFINITY_LIFE_TIME; 3843 } 3844 | 3835 + nla_total_size(16) /* IFA_ADDRESS */ 3836 + nla_total_size(sizeof(struct ifa_cacheinfo)); 3837} 3838 3839static int inet6_fill_ifaddr(struct sk_buff *skb, struct inet6_ifaddr *ifa, 3840 u32 portid, u32 seq, int event, unsigned int flags) 3841{ 3842 struct nlmsghdr *nlh; --- 22 unchanged lines hidden (view full) --- 3865 valid = 0; 3866 } 3867 } 3868 } else { 3869 preferred = INFINITY_LIFE_TIME; 3870 valid = INFINITY_LIFE_TIME; 3871 } 3872 |
3845 if (nla_put(skb, IFA_ADDRESS, 16, &ifa->addr) < 0 || 3846 put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) { 3847 nlmsg_cancel(skb, nlh); 3848 return -EMSGSIZE; 3849 } | 3873 if (!ipv6_addr_any(&ifa->peer_addr)) { 3874 if (nla_put(skb, IFA_LOCAL, 16, &ifa->addr) < 0 || 3875 nla_put(skb, IFA_ADDRESS, 16, &ifa->peer_addr) < 0) 3876 goto error; 3877 } else 3878 if (nla_put(skb, IFA_ADDRESS, 16, &ifa->addr) < 0) 3879 goto error; |
3850 | 3880 |
3881 if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) 3882 goto error; 3883 |
|
3851 return nlmsg_end(skb, nlh); | 3884 return nlmsg_end(skb, nlh); |
3885 3886error: 3887 nlmsg_cancel(skb, nlh); 3888 return -EMSGSIZE; |
|
3852} 3853 3854static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca, 3855 u32 portid, u32 seq, int event, u16 flags) 3856{ 3857 struct nlmsghdr *nlh; 3858 u8 scope = RT_SCOPE_UNIVERSE; 3859 int ifindex = ifmca->idev->dev->ifindex; --- 183 unchanged lines hidden (view full) --- 4043 return inet6_dump_addr(skb, cb, type); 4044} 4045 4046static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr *nlh) 4047{ 4048 struct net *net = sock_net(in_skb->sk); 4049 struct ifaddrmsg *ifm; 4050 struct nlattr *tb[IFA_MAX+1]; | 3889} 3890 3891static int inet6_fill_ifmcaddr(struct sk_buff *skb, struct ifmcaddr6 *ifmca, 3892 u32 portid, u32 seq, int event, u16 flags) 3893{ 3894 struct nlmsghdr *nlh; 3895 u8 scope = RT_SCOPE_UNIVERSE; 3896 int ifindex = ifmca->idev->dev->ifindex; --- 183 unchanged lines hidden (view full) --- 4080 return inet6_dump_addr(skb, cb, type); 4081} 4082 4083static int inet6_rtm_getaddr(struct sk_buff *in_skb, struct nlmsghdr *nlh) 4084{ 4085 struct net *net = sock_net(in_skb->sk); 4086 struct ifaddrmsg *ifm; 4087 struct nlattr *tb[IFA_MAX+1]; |
4051 struct in6_addr *addr = NULL; | 4088 struct in6_addr *addr = NULL, *peer; |
4052 struct net_device *dev = NULL; 4053 struct inet6_ifaddr *ifa; 4054 struct sk_buff *skb; 4055 int err; 4056 4057 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); 4058 if (err < 0) 4059 goto errout; 4060 | 4089 struct net_device *dev = NULL; 4090 struct inet6_ifaddr *ifa; 4091 struct sk_buff *skb; 4092 int err; 4093 4094 err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv6_policy); 4095 if (err < 0) 4096 goto errout; 4097 |
4061 addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL]); | 4098 addr = extract_addr(tb[IFA_ADDRESS], tb[IFA_LOCAL], &peer); |
4062 if (addr == NULL) { 4063 err = -EINVAL; 4064 goto errout; 4065 } 4066 4067 ifm = nlmsg_data(nlh); 4068 if (ifm->ifa_index) 4069 dev = __dev_get_by_index(net, ifm->ifa_index); --- 262 unchanged lines hidden (view full) --- 4332 * of this. Otherwise, we need to request our rs here. 4333 */ 4334 ndisc_send_rs(dev, &ll_addr, &in6addr_linklocal_allrouters); 4335 update_rs = true; 4336 } 4337 4338 write_lock_bh(&idev->lock); 4339 | 4099 if (addr == NULL) { 4100 err = -EINVAL; 4101 goto errout; 4102 } 4103 4104 ifm = nlmsg_data(nlh); 4105 if (ifm->ifa_index) 4106 dev = __dev_get_by_index(net, ifm->ifa_index); --- 262 unchanged lines hidden (view full) --- 4369 * of this. Otherwise, we need to request our rs here. 4370 */ 4371 ndisc_send_rs(dev, &ll_addr, &in6addr_linklocal_allrouters); 4372 update_rs = true; 4373 } 4374 4375 write_lock_bh(&idev->lock); 4376 |
4340 if (update_rs) | 4377 if (update_rs) { |
4341 idev->if_flags |= IF_RS_SENT; | 4378 idev->if_flags |= IF_RS_SENT; |
4379 idev->rs_probes = 1; 4380 addrconf_mod_rs_timer(idev, idev->cnf.rtr_solicit_interval); 4381 } |
|
4342 4343 /* Well, that's kinda nasty ... */ 4344 list_for_each_entry(ifp, &idev->addr_list, if_list) { 4345 spin_lock(&ifp->lock); 4346 if (ifp->tokenized) { 4347 ifp->valid_lft = 0; 4348 ifp->prefered_lft = 0; 4349 } 4350 spin_unlock(&ifp->lock); 4351 } 4352 4353 write_unlock_bh(&idev->lock); | 4382 4383 /* Well, that's kinda nasty ... */ 4384 list_for_each_entry(ifp, &idev->addr_list, if_list) { 4385 spin_lock(&ifp->lock); 4386 if (ifp->tokenized) { 4387 ifp->valid_lft = 0; 4388 ifp->prefered_lft = 0; 4389 } 4390 spin_unlock(&ifp->lock); 4391 } 4392 4393 write_unlock_bh(&idev->lock); |
4394 addrconf_verify(0); |
|
4354 return 0; 4355} 4356 4357static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla) 4358{ 4359 int err = -EINVAL; 4360 struct inet6_dev *idev = __in6_dev_get(dev); 4361 struct nlattr *tb[IFLA_INET6_MAX + 1]; --- 181 unchanged lines hidden (view full) --- 4543 } 4544 rtnl_notify(skb, net, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC); 4545 return; 4546errout: 4547 if (err < 0) 4548 rtnl_set_sk_err(net, RTNLGRP_IPV6_PREFIX, err); 4549} 4550 | 4395 return 0; 4396} 4397 4398static int inet6_set_link_af(struct net_device *dev, const struct nlattr *nla) 4399{ 4400 int err = -EINVAL; 4401 struct inet6_dev *idev = __in6_dev_get(dev); 4402 struct nlattr *tb[IFLA_INET6_MAX + 1]; --- 181 unchanged lines hidden (view full) --- 4584 } 4585 rtnl_notify(skb, net, 0, RTNLGRP_IPV6_PREFIX, NULL, GFP_ATOMIC); 4586 return; 4587errout: 4588 if (err < 0) 4589 rtnl_set_sk_err(net, RTNLGRP_IPV6_PREFIX, err); 4590} 4591 |
4592static void update_valid_ll_addr_cnt(struct inet6_ifaddr *ifp, int count) 4593{ 4594 write_lock_bh(&ifp->idev->lock); 4595 spin_lock(&ifp->lock); 4596 if (((ifp->flags & (IFA_F_PERMANENT|IFA_F_TENTATIVE|IFA_F_OPTIMISTIC| 4597 IFA_F_DADFAILED)) == IFA_F_PERMANENT) && 4598 (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL)) 4599 ifp->idev->valid_ll_addr_cnt += count; 4600 WARN_ON(ifp->idev->valid_ll_addr_cnt < 0); 4601 spin_unlock(&ifp->lock); 4602 write_unlock_bh(&ifp->idev->lock); 4603} 4604 |
|
4551static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) 4552{ 4553 struct net *net = dev_net(ifp->idev->dev); 4554 4555 inet6_ifa_notify(event ? : RTM_NEWADDR, ifp); 4556 4557 switch (event) { 4558 case RTM_NEWADDR: | 4605static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) 4606{ 4607 struct net *net = dev_net(ifp->idev->dev); 4608 4609 inet6_ifa_notify(event ? : RTM_NEWADDR, ifp); 4610 4611 switch (event) { 4612 case RTM_NEWADDR: |
4613 update_valid_ll_addr_cnt(ifp, 1); 4614 |
|
4559 /* 4560 * If the address was optimistic 4561 * we inserted the route at the start of 4562 * our DAD process, so we don't need 4563 * to do it again 4564 */ 4565 if (!(ifp->rt->rt6i_node)) 4566 ip6_ins_rt(ifp->rt); 4567 if (ifp->idev->cnf.forwarding) 4568 addrconf_join_anycast(ifp); | 4615 /* 4616 * If the address was optimistic 4617 * we inserted the route at the start of 4618 * our DAD process, so we don't need 4619 * to do it again 4620 */ 4621 if (!(ifp->rt->rt6i_node)) 4622 ip6_ins_rt(ifp->rt); 4623 if (ifp->idev->cnf.forwarding) 4624 addrconf_join_anycast(ifp); |
4625 if (!ipv6_addr_any(&ifp->peer_addr)) 4626 addrconf_prefix_route(&ifp->peer_addr, 128, 4627 ifp->idev->dev, 0, 0); |
|
4569 break; 4570 case RTM_DELADDR: | 4628 break; 4629 case RTM_DELADDR: |
4630 update_valid_ll_addr_cnt(ifp, -1); 4631 |
|
4571 if (ifp->idev->cnf.forwarding) 4572 addrconf_leave_anycast(ifp); 4573 addrconf_leave_solict(ifp->idev, &ifp->addr); | 4632 if (ifp->idev->cnf.forwarding) 4633 addrconf_leave_anycast(ifp); 4634 addrconf_leave_solict(ifp->idev, &ifp->addr); |
4635 if (!ipv6_addr_any(&ifp->peer_addr)) { 4636 struct rt6_info *rt; 4637 struct net_device *dev = ifp->idev->dev; 4638 4639 rt = rt6_lookup(dev_net(dev), &ifp->peer_addr, NULL, 4640 dev->ifindex, 1); 4641 if (rt) { 4642 dst_hold(&rt->dst); 4643 if (ip6_del_rt(rt)) 4644 dst_free(&rt->dst); 4645 } 4646 } |
|
4574 dst_hold(&ifp->rt->dst); 4575 4576 if (ip6_del_rt(ifp->rt)) 4577 dst_free(&ifp->rt->dst); 4578 break; 4579 } 4580 atomic_inc(&net->ipv6.dev_addr_genid); 4581} --- 4 unchanged lines hidden (view full) --- 4586 if (likely(ifp->idev->dead == 0)) 4587 __ipv6_ifa_notify(event, ifp); 4588 rcu_read_unlock_bh(); 4589} 4590 4591#ifdef CONFIG_SYSCTL 4592 4593static | 4647 dst_hold(&ifp->rt->dst); 4648 4649 if (ip6_del_rt(ifp->rt)) 4650 dst_free(&ifp->rt->dst); 4651 break; 4652 } 4653 atomic_inc(&net->ipv6.dev_addr_genid); 4654} --- 4 unchanged lines hidden (view full) --- 4659 if (likely(ifp->idev->dead == 0)) 4660 __ipv6_ifa_notify(event, ifp); 4661 rcu_read_unlock_bh(); 4662} 4663 4664#ifdef CONFIG_SYSCTL 4665 4666static |
4594int addrconf_sysctl_forward(ctl_table *ctl, int write, | 4667int addrconf_sysctl_forward(struct ctl_table *ctl, int write, |
4595 void __user *buffer, size_t *lenp, loff_t *ppos) 4596{ 4597 int *valp = ctl->data; 4598 int val = *valp; 4599 loff_t pos = *ppos; | 4668 void __user *buffer, size_t *lenp, loff_t *ppos) 4669{ 4670 int *valp = ctl->data; 4671 int val = *valp; 4672 loff_t pos = *ppos; |
4600 ctl_table lctl; | 4673 struct ctl_table lctl; |
4601 int ret; 4602 4603 /* 4604 * ctl->data points to idev->cnf.forwarding, we should 4605 * not modify it until we get the rtnl lock. 4606 */ 4607 lctl = *ctl; 4608 lctl.data = &val; --- 4 unchanged lines hidden (view full) --- 4613 ret = addrconf_fixup_forwarding(ctl, valp, val); 4614 if (ret) 4615 *ppos = pos; 4616 return ret; 4617} 4618 4619static void dev_disable_change(struct inet6_dev *idev) 4620{ | 4674 int ret; 4675 4676 /* 4677 * ctl->data points to idev->cnf.forwarding, we should 4678 * not modify it until we get the rtnl lock. 4679 */ 4680 lctl = *ctl; 4681 lctl.data = &val; --- 4 unchanged lines hidden (view full) --- 4686 ret = addrconf_fixup_forwarding(ctl, valp, val); 4687 if (ret) 4688 *ppos = pos; 4689 return ret; 4690} 4691 4692static void dev_disable_change(struct inet6_dev *idev) 4693{ |
4694 struct netdev_notifier_info info; 4695 |
|
4621 if (!idev || !idev->dev) 4622 return; 4623 | 4696 if (!idev || !idev->dev) 4697 return; 4698 |
4699 netdev_notifier_info_init(&info, idev->dev); |
|
4624 if (idev->cnf.disable_ipv6) | 4700 if (idev->cnf.disable_ipv6) |
4625 addrconf_notify(NULL, NETDEV_DOWN, idev->dev); | 4701 addrconf_notify(NULL, NETDEV_DOWN, &info); |
4626 else | 4702 else |
4627 addrconf_notify(NULL, NETDEV_UP, idev->dev); | 4703 addrconf_notify(NULL, NETDEV_UP, &info); |
4628} 4629 4630static void addrconf_disable_change(struct net *net, __s32 newf) 4631{ 4632 struct net_device *dev; 4633 struct inet6_dev *idev; 4634 4635 rcu_read_lock(); --- 32 unchanged lines hidden (view full) --- 4668 } else if ((!newf) ^ (!old)) 4669 dev_disable_change((struct inet6_dev *)table->extra1); 4670 4671 rtnl_unlock(); 4672 return 0; 4673} 4674 4675static | 4704} 4705 4706static void addrconf_disable_change(struct net *net, __s32 newf) 4707{ 4708 struct net_device *dev; 4709 struct inet6_dev *idev; 4710 4711 rcu_read_lock(); --- 32 unchanged lines hidden (view full) --- 4744 } else if ((!newf) ^ (!old)) 4745 dev_disable_change((struct inet6_dev *)table->extra1); 4746 4747 rtnl_unlock(); 4748 return 0; 4749} 4750 4751static |
4676int addrconf_sysctl_disable(ctl_table *ctl, int write, | 4752int addrconf_sysctl_disable(struct ctl_table *ctl, int write, |
4677 void __user *buffer, size_t *lenp, loff_t *ppos) 4678{ 4679 int *valp = ctl->data; 4680 int val = *valp; 4681 loff_t pos = *ppos; | 4753 void __user *buffer, size_t *lenp, loff_t *ppos) 4754{ 4755 int *valp = ctl->data; 4756 int val = *valp; 4757 loff_t pos = *ppos; |
4682 ctl_table lctl; | 4758 struct ctl_table lctl; |
4683 int ret; 4684 4685 /* 4686 * ctl->data points to idev->cnf.disable_ipv6, we should 4687 * not modify it until we get the rtnl lock. 4688 */ 4689 lctl = *ctl; 4690 lctl.data = &val; --- 5 unchanged lines hidden (view full) --- 4696 if (ret) 4697 *ppos = pos; 4698 return ret; 4699} 4700 4701static struct addrconf_sysctl_table 4702{ 4703 struct ctl_table_header *sysctl_header; | 4759 int ret; 4760 4761 /* 4762 * ctl->data points to idev->cnf.disable_ipv6, we should 4763 * not modify it until we get the rtnl lock. 4764 */ 4765 lctl = *ctl; 4766 lctl.data = &val; --- 5 unchanged lines hidden (view full) --- 4772 if (ret) 4773 *ppos = pos; 4774 return ret; 4775} 4776 4777static struct addrconf_sysctl_table 4778{ 4779 struct ctl_table_header *sysctl_header; |
4704 ctl_table addrconf_vars[DEVCONF_MAX+1]; | 4780 struct ctl_table addrconf_vars[DEVCONF_MAX+1]; |
4705} addrconf_sysctl __read_mostly = { 4706 .sysctl_header = NULL, 4707 .addrconf_vars = { 4708 { 4709 .procname = "forwarding", 4710 .data = &ipv6_devconf.forwarding, 4711 .maxlen = sizeof(int), 4712 .mode = 0644, --- 470 unchanged lines hidden --- | 4781} addrconf_sysctl __read_mostly = { 4782 .sysctl_header = NULL, 4783 .addrconf_vars = { 4784 { 4785 .procname = "forwarding", 4786 .data = &ipv6_devconf.forwarding, 4787 .maxlen = sizeof(int), 4788 .mode = 0644, --- 470 unchanged lines hidden --- |