addrconf.c (8cad95f56f63a63abab0ff0cb451c0bdd5a885dc) | addrconf.c (0aef78aa7b39829a2a46c1c0e6e96276d744e07a) |
---|---|
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 * --- 156 unchanged lines hidden (view full) --- 165 166static void addrconf_join_anycast(struct inet6_ifaddr *ifp); 167static void addrconf_leave_anycast(struct inet6_ifaddr *ifp); 168 169static void addrconf_type_change(struct net_device *dev, 170 unsigned long event); 171static int addrconf_ifdown(struct net_device *dev, int how); 172 | 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 * --- 156 unchanged lines hidden (view full) --- 165 166static void addrconf_join_anycast(struct inet6_ifaddr *ifp); 167static void addrconf_leave_anycast(struct inet6_ifaddr *ifp); 168 169static void addrconf_type_change(struct net_device *dev, 170 unsigned long event); 171static int addrconf_ifdown(struct net_device *dev, int how); 172 |
173static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, | 173static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, |
174 int plen, 175 const struct net_device *dev, 176 u32 flags, u32 noflags); 177 178static void addrconf_dad_start(struct inet6_ifaddr *ifp); 179static void addrconf_dad_work(struct work_struct *w); 180static void addrconf_dad_completed(struct inet6_ifaddr *ifp, bool bump_id, 181 bool send_na); --- 729 unchanged lines hidden (view full) --- 911 if (cancel_delayed_work(&ifp->dad_work)) 912 pr_notice("delayed DAD work was pending while freeing ifa=%p\n", 913 ifp); 914 915 if (ifp->state != INET6_IFADDR_STATE_DEAD) { 916 pr_warn("Freeing alive inet6 address %p\n", ifp); 917 return; 918 } | 174 int plen, 175 const struct net_device *dev, 176 u32 flags, u32 noflags); 177 178static void addrconf_dad_start(struct inet6_ifaddr *ifp); 179static void addrconf_dad_work(struct work_struct *w); 180static void addrconf_dad_completed(struct inet6_ifaddr *ifp, bool bump_id, 181 bool send_na); --- 729 unchanged lines hidden (view full) --- 911 if (cancel_delayed_work(&ifp->dad_work)) 912 pr_notice("delayed DAD work was pending while freeing ifa=%p\n", 913 ifp); 914 915 if (ifp->state != INET6_IFADDR_STATE_DEAD) { 916 pr_warn("Freeing alive inet6 address %p\n", ifp); 917 return; 918 } |
919 ip6_rt_put(ifp->rt); | |
920 921 kfree_rcu(ifp, rcu); 922} 923 924static void 925ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) 926{ 927 struct list_head *p; --- 62 unchanged lines hidden (view full) --- 990ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, 991 const struct in6_addr *peer_addr, int pfxlen, 992 int scope, u32 flags, u32 valid_lft, u32 prefered_lft, 993 bool can_block, struct netlink_ext_ack *extack) 994{ 995 gfp_t gfp_flags = can_block ? GFP_KERNEL : GFP_ATOMIC; 996 struct net *net = dev_net(idev->dev); 997 struct inet6_ifaddr *ifa = NULL; | 919 920 kfree_rcu(ifp, rcu); 921} 922 923static void 924ipv6_link_dev_addr(struct inet6_dev *idev, struct inet6_ifaddr *ifp) 925{ 926 struct list_head *p; --- 62 unchanged lines hidden (view full) --- 989ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr, 990 const struct in6_addr *peer_addr, int pfxlen, 991 int scope, u32 flags, u32 valid_lft, u32 prefered_lft, 992 bool can_block, struct netlink_ext_ack *extack) 993{ 994 gfp_t gfp_flags = can_block ? GFP_KERNEL : GFP_ATOMIC; 995 struct net *net = dev_net(idev->dev); 996 struct inet6_ifaddr *ifa = NULL; |
998 struct rt6_info *rt = NULL; | 997 struct fib6_info *f6i = NULL; |
999 int err = 0; 1000 int addr_type = ipv6_addr_type(addr); 1001 1002 if (addr_type == IPV6_ADDR_ANY || 1003 addr_type & IPV6_ADDR_MULTICAST || 1004 (!(idev->dev->flags & IFF_LOOPBACK) && 1005 addr_type & IPV6_ADDR_LOOPBACK)) 1006 return ERR_PTR(-EADDRNOTAVAIL); --- 25 unchanged lines hidden (view full) --- 1032 } 1033 1034 ifa = kzalloc(sizeof(*ifa), gfp_flags); 1035 if (!ifa) { 1036 err = -ENOBUFS; 1037 goto out; 1038 } 1039 | 998 int err = 0; 999 int addr_type = ipv6_addr_type(addr); 1000 1001 if (addr_type == IPV6_ADDR_ANY || 1002 addr_type & IPV6_ADDR_MULTICAST || 1003 (!(idev->dev->flags & IFF_LOOPBACK) && 1004 addr_type & IPV6_ADDR_LOOPBACK)) 1005 return ERR_PTR(-EADDRNOTAVAIL); --- 25 unchanged lines hidden (view full) --- 1031 } 1032 1033 ifa = kzalloc(sizeof(*ifa), gfp_flags); 1034 if (!ifa) { 1035 err = -ENOBUFS; 1036 goto out; 1037 } 1038 |
1040 rt = addrconf_dst_alloc(idev, addr, false); 1041 if (IS_ERR(rt)) { 1042 err = PTR_ERR(rt); 1043 rt = NULL; | 1039 f6i = addrconf_f6i_alloc(net, idev, addr, false, gfp_flags); 1040 if (IS_ERR(f6i)) { 1041 err = PTR_ERR(f6i); 1042 f6i = NULL; |
1044 goto out; 1045 } 1046 1047 if (net->ipv6.devconf_all->disable_policy || 1048 idev->cnf.disable_policy) | 1043 goto out; 1044 } 1045 1046 if (net->ipv6.devconf_all->disable_policy || 1047 idev->cnf.disable_policy) |
1049 rt->dst.flags |= DST_NOPOLICY; | 1048 f6i->dst_nopolicy = true; |
1050 1051 neigh_parms_data_state_setall(idev->nd_parms); 1052 1053 ifa->addr = *addr; 1054 if (peer_addr) 1055 ifa->peer_addr = *peer_addr; 1056 1057 spin_lock_init(&ifa->lock); --- 5 unchanged lines hidden (view full) --- 1063 /* No need to add the TENTATIVE flag for addresses with NODAD */ 1064 if (!(flags & IFA_F_NODAD)) 1065 ifa->flags |= IFA_F_TENTATIVE; 1066 ifa->valid_lft = valid_lft; 1067 ifa->prefered_lft = prefered_lft; 1068 ifa->cstamp = ifa->tstamp = jiffies; 1069 ifa->tokenized = false; 1070 | 1049 1050 neigh_parms_data_state_setall(idev->nd_parms); 1051 1052 ifa->addr = *addr; 1053 if (peer_addr) 1054 ifa->peer_addr = *peer_addr; 1055 1056 spin_lock_init(&ifa->lock); --- 5 unchanged lines hidden (view full) --- 1062 /* No need to add the TENTATIVE flag for addresses with NODAD */ 1063 if (!(flags & IFA_F_NODAD)) 1064 ifa->flags |= IFA_F_TENTATIVE; 1065 ifa->valid_lft = valid_lft; 1066 ifa->prefered_lft = prefered_lft; 1067 ifa->cstamp = ifa->tstamp = jiffies; 1068 ifa->tokenized = false; 1069 |
1071 ifa->rt = rt; | 1070 ifa->rt = f6i; |
1072 1073 ifa->idev = idev; 1074 in6_dev_hold(idev); 1075 1076 /* For caller */ 1077 refcount_set(&ifa->refcnt, 1); 1078 1079 rcu_read_lock_bh(); --- 17 unchanged lines hidden (view full) --- 1097 in6_ifa_hold(ifa); 1098 write_unlock(&idev->lock); 1099 1100 rcu_read_unlock_bh(); 1101 1102 inet6addr_notifier_call_chain(NETDEV_UP, ifa); 1103out: 1104 if (unlikely(err < 0)) { | 1071 1072 ifa->idev = idev; 1073 in6_dev_hold(idev); 1074 1075 /* For caller */ 1076 refcount_set(&ifa->refcnt, 1); 1077 1078 rcu_read_lock_bh(); --- 17 unchanged lines hidden (view full) --- 1096 in6_ifa_hold(ifa); 1097 write_unlock(&idev->lock); 1098 1099 rcu_read_unlock_bh(); 1100 1101 inet6addr_notifier_call_chain(NETDEV_UP, ifa); 1102out: 1103 if (unlikely(err < 0)) { |
1105 if (rt) 1106 ip6_rt_put(rt); | 1104 fib6_info_release(f6i); 1105 |
1107 if (ifa) { 1108 if (ifa->idev) 1109 in6_dev_put(ifa->idev); 1110 kfree(ifa); 1111 } 1112 ifa = ERR_PTR(err); 1113 } 1114 --- 59 unchanged lines hidden (view full) --- 1174 } 1175 1176 return action; 1177} 1178 1179static void 1180cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_rt) 1181{ | 1106 if (ifa) { 1107 if (ifa->idev) 1108 in6_dev_put(ifa->idev); 1109 kfree(ifa); 1110 } 1111 ifa = ERR_PTR(err); 1112 } 1113 --- 59 unchanged lines hidden (view full) --- 1173 } 1174 1175 return action; 1176} 1177 1178static void 1179cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_rt) 1180{ |
1182 struct rt6_info *rt; | 1181 struct fib6_info *f6i; |
1183 | 1182 |
1184 rt = addrconf_get_prefix_route(&ifp->addr, | 1183 f6i = addrconf_get_prefix_route(&ifp->addr, |
1185 ifp->prefix_len, 1186 ifp->idev->dev, 1187 0, RTF_GATEWAY | RTF_DEFAULT); | 1184 ifp->prefix_len, 1185 ifp->idev->dev, 1186 0, RTF_GATEWAY | RTF_DEFAULT); |
1188 if (rt) { | 1187 if (f6i) { |
1189 if (del_rt) | 1188 if (del_rt) |
1190 ip6_del_rt(rt); | 1189 ip6_del_rt(dev_net(ifp->idev->dev), f6i); |
1191 else { | 1190 else { |
1192 if (!(rt->rt6i_flags & RTF_EXPIRES)) 1193 rt6_set_expires(rt, expires); 1194 ip6_rt_put(rt); | 1191 if (!(f6i->fib6_flags & RTF_EXPIRES)) 1192 fib6_set_expires(f6i, expires); 1193 fib6_info_release(f6i); |
1195 } 1196 } 1197} 1198 1199 1200/* This function wants to get referenced ifp and releases it before return */ 1201 1202static void ipv6_del_addr(struct inet6_ifaddr *ifp) --- 1112 unchanged lines hidden (view full) --- 2315} 2316 2317/* 2318 * Add prefix route. 2319 */ 2320 2321static void 2322addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev, | 1194 } 1195 } 1196} 1197 1198 1199/* This function wants to get referenced ifp and releases it before return */ 1200 1201static void ipv6_del_addr(struct inet6_ifaddr *ifp) --- 1112 unchanged lines hidden (view full) --- 2314} 2315 2316/* 2317 * Add prefix route. 2318 */ 2319 2320static void 2321addrconf_prefix_route(struct in6_addr *pfx, int plen, struct net_device *dev, |
2323 unsigned long expires, u32 flags) | 2322 unsigned long expires, u32 flags, gfp_t gfp_flags) |
2324{ 2325 struct fib6_config cfg = { 2326 .fc_table = l3mdev_fib_table(dev) ? : RT6_TABLE_PREFIX, 2327 .fc_metric = IP6_RT_PRIO_ADDRCONF, 2328 .fc_ifindex = dev->ifindex, 2329 .fc_expires = expires, 2330 .fc_dst_len = plen, 2331 .fc_flags = RTF_UP | flags, 2332 .fc_nlinfo.nl_net = dev_net(dev), 2333 .fc_protocol = RTPROT_KERNEL, | 2323{ 2324 struct fib6_config cfg = { 2325 .fc_table = l3mdev_fib_table(dev) ? : RT6_TABLE_PREFIX, 2326 .fc_metric = IP6_RT_PRIO_ADDRCONF, 2327 .fc_ifindex = dev->ifindex, 2328 .fc_expires = expires, 2329 .fc_dst_len = plen, 2330 .fc_flags = RTF_UP | flags, 2331 .fc_nlinfo.nl_net = dev_net(dev), 2332 .fc_protocol = RTPROT_KERNEL, |
2333 .fc_type = RTN_UNICAST, |
|
2334 }; 2335 2336 cfg.fc_dst = *pfx; 2337 2338 /* Prevent useless cloning on PtP SIT. 2339 This thing is done here expecting that the whole 2340 class of non-broadcast devices need not cloning. 2341 */ 2342#if IS_ENABLED(CONFIG_IPV6_SIT) 2343 if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT)) 2344 cfg.fc_flags |= RTF_NONEXTHOP; 2345#endif 2346 | 2334 }; 2335 2336 cfg.fc_dst = *pfx; 2337 2338 /* Prevent useless cloning on PtP SIT. 2339 This thing is done here expecting that the whole 2340 class of non-broadcast devices need not cloning. 2341 */ 2342#if IS_ENABLED(CONFIG_IPV6_SIT) 2343 if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT)) 2344 cfg.fc_flags |= RTF_NONEXTHOP; 2345#endif 2346 |
2347 ip6_route_add(&cfg, NULL); | 2347 ip6_route_add(&cfg, gfp_flags, NULL); |
2348} 2349 2350 | 2348} 2349 2350 |
2351static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, | 2351static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, |
2352 int plen, 2353 const struct net_device *dev, 2354 u32 flags, u32 noflags) 2355{ 2356 struct fib6_node *fn; | 2352 int plen, 2353 const struct net_device *dev, 2354 u32 flags, u32 noflags) 2355{ 2356 struct fib6_node *fn; |
2357 struct rt6_info *rt = NULL; | 2357 struct fib6_info *rt = NULL; |
2358 struct fib6_table *table; 2359 u32 tb_id = l3mdev_fib_table(dev) ? : RT6_TABLE_PREFIX; 2360 2361 table = fib6_get_table(dev_net(dev), tb_id); 2362 if (!table) 2363 return NULL; 2364 2365 rcu_read_lock(); 2366 fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0, true); 2367 if (!fn) 2368 goto out; 2369 2370 for_each_fib6_node_rt_rcu(fn) { | 2358 struct fib6_table *table; 2359 u32 tb_id = l3mdev_fib_table(dev) ? : RT6_TABLE_PREFIX; 2360 2361 table = fib6_get_table(dev_net(dev), tb_id); 2362 if (!table) 2363 return NULL; 2364 2365 rcu_read_lock(); 2366 fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0, true); 2367 if (!fn) 2368 goto out; 2369 2370 for_each_fib6_node_rt_rcu(fn) { |
2371 if (rt->dst.dev->ifindex != dev->ifindex) | 2371 if (rt->fib6_nh.nh_dev->ifindex != dev->ifindex) |
2372 continue; | 2372 continue; |
2373 if ((rt->rt6i_flags & flags) != flags) | 2373 if ((rt->fib6_flags & flags) != flags) |
2374 continue; | 2374 continue; |
2375 if ((rt->rt6i_flags & noflags) != 0) | 2375 if ((rt->fib6_flags & noflags) != 0) |
2376 continue; | 2376 continue; |
2377 if (!dst_hold_safe(&rt->dst)) 2378 rt = NULL; | 2377 fib6_info_hold(rt); |
2379 break; 2380 } 2381out: 2382 rcu_read_unlock(); 2383 return rt; 2384} 2385 2386 2387/* Create "default" multicast route to the interface */ 2388 2389static void addrconf_add_mroute(struct net_device *dev) 2390{ 2391 struct fib6_config cfg = { 2392 .fc_table = l3mdev_fib_table(dev) ? : RT6_TABLE_LOCAL, 2393 .fc_metric = IP6_RT_PRIO_ADDRCONF, 2394 .fc_ifindex = dev->ifindex, 2395 .fc_dst_len = 8, 2396 .fc_flags = RTF_UP, | 2378 break; 2379 } 2380out: 2381 rcu_read_unlock(); 2382 return rt; 2383} 2384 2385 2386/* Create "default" multicast route to the interface */ 2387 2388static void addrconf_add_mroute(struct net_device *dev) 2389{ 2390 struct fib6_config cfg = { 2391 .fc_table = l3mdev_fib_table(dev) ? : RT6_TABLE_LOCAL, 2392 .fc_metric = IP6_RT_PRIO_ADDRCONF, 2393 .fc_ifindex = dev->ifindex, 2394 .fc_dst_len = 8, 2395 .fc_flags = RTF_UP, |
2396 .fc_type = RTN_UNICAST, |
|
2397 .fc_nlinfo.nl_net = dev_net(dev), 2398 }; 2399 2400 ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0); 2401 | 2397 .fc_nlinfo.nl_net = dev_net(dev), 2398 }; 2399 2400 ipv6_addr_set(&cfg.fc_dst, htonl(0xFF000000), 0, 0, 0); 2401 |
2402 ip6_route_add(&cfg, NULL); | 2402 ip6_route_add(&cfg, GFP_ATOMIC, NULL); |
2403} 2404 2405static struct inet6_dev *addrconf_add_dev(struct net_device *dev) 2406{ 2407 struct inet6_dev *idev; 2408 2409 ASSERT_RTNL(); 2410 --- 113 unchanged lines hidden (view full) --- 2524 pinfo->prefix_len, 2525 addr_type&IPV6_ADDR_SCOPE_MASK, 2526 addr_flags, valid_lft, 2527 prefered_lft, false, NULL); 2528 2529 if (IS_ERR_OR_NULL(ifp)) 2530 return -1; 2531 | 2403} 2404 2405static struct inet6_dev *addrconf_add_dev(struct net_device *dev) 2406{ 2407 struct inet6_dev *idev; 2408 2409 ASSERT_RTNL(); 2410 --- 113 unchanged lines hidden (view full) --- 2524 pinfo->prefix_len, 2525 addr_type&IPV6_ADDR_SCOPE_MASK, 2526 addr_flags, valid_lft, 2527 prefered_lft, false, NULL); 2528 2529 if (IS_ERR_OR_NULL(ifp)) 2530 return -1; 2531 |
2532 update_lft = 0; | |
2533 create = 1; 2534 spin_lock_bh(&ifp->lock); 2535 ifp->flags |= IFA_F_MANAGETEMPADDR; 2536 ifp->cstamp = jiffies; 2537 ifp->tokenized = tokenized; 2538 spin_unlock_bh(&ifp->lock); 2539 addrconf_dad_start(ifp); 2540 } --- 5 unchanged lines hidden (view full) --- 2546 2547 /* update lifetime (RFC2462 5.5.3 e) */ 2548 spin_lock_bh(&ifp->lock); 2549 now = jiffies; 2550 if (ifp->valid_lft > (now - ifp->tstamp) / HZ) 2551 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ; 2552 else 2553 stored_lft = 0; | 2532 create = 1; 2533 spin_lock_bh(&ifp->lock); 2534 ifp->flags |= IFA_F_MANAGETEMPADDR; 2535 ifp->cstamp = jiffies; 2536 ifp->tokenized = tokenized; 2537 spin_unlock_bh(&ifp->lock); 2538 addrconf_dad_start(ifp); 2539 } --- 5 unchanged lines hidden (view full) --- 2545 2546 /* update lifetime (RFC2462 5.5.3 e) */ 2547 spin_lock_bh(&ifp->lock); 2548 now = jiffies; 2549 if (ifp->valid_lft > (now - ifp->tstamp) / HZ) 2550 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ; 2551 else 2552 stored_lft = 0; |
2554 if (!update_lft && !create && stored_lft) { | 2553 if (!create && stored_lft) { |
2555 const u32 minimum_lft = min_t(u32, 2556 stored_lft, MIN_VALID_LIFETIME); 2557 valid_lft = max(valid_lft, minimum_lft); 2558 2559 /* RFC4862 Section 5.5.3e: 2560 * "Note that the preferred lifetime of the 2561 * corresponding address is always reset to 2562 * the Preferred Lifetime in the received --- 74 unchanged lines hidden (view full) --- 2637 2638 /* 2639 * Two things going on here: 2640 * 1) Add routes for on-link prefixes 2641 * 2) Configure prefixes with the auto flag set 2642 */ 2643 2644 if (pinfo->onlink) { | 2554 const u32 minimum_lft = min_t(u32, 2555 stored_lft, MIN_VALID_LIFETIME); 2556 valid_lft = max(valid_lft, minimum_lft); 2557 2558 /* RFC4862 Section 5.5.3e: 2559 * "Note that the preferred lifetime of the 2560 * corresponding address is always reset to 2561 * the Preferred Lifetime in the received --- 74 unchanged lines hidden (view full) --- 2636 2637 /* 2638 * Two things going on here: 2639 * 1) Add routes for on-link prefixes 2640 * 2) Configure prefixes with the auto flag set 2641 */ 2642 2643 if (pinfo->onlink) { |
2645 struct rt6_info *rt; | 2644 struct fib6_info *rt; |
2646 unsigned long rt_expires; 2647 2648 /* Avoid arithmetic overflow. Really, we could 2649 * save rt_expires in seconds, likely valid_lft, 2650 * but it would require division in fib gc, that it 2651 * not good. 2652 */ 2653 if (HZ > USER_HZ) --- 8 unchanged lines hidden (view full) --- 2662 pinfo->prefix_len, 2663 dev, 2664 RTF_ADDRCONF | RTF_PREFIX_RT, 2665 RTF_GATEWAY | RTF_DEFAULT); 2666 2667 if (rt) { 2668 /* Autoconf prefix route */ 2669 if (valid_lft == 0) { | 2645 unsigned long rt_expires; 2646 2647 /* Avoid arithmetic overflow. Really, we could 2648 * save rt_expires in seconds, likely valid_lft, 2649 * but it would require division in fib gc, that it 2650 * not good. 2651 */ 2652 if (HZ > USER_HZ) --- 8 unchanged lines hidden (view full) --- 2661 pinfo->prefix_len, 2662 dev, 2663 RTF_ADDRCONF | RTF_PREFIX_RT, 2664 RTF_GATEWAY | RTF_DEFAULT); 2665 2666 if (rt) { 2667 /* Autoconf prefix route */ 2668 if (valid_lft == 0) { |
2670 ip6_del_rt(rt); | 2669 ip6_del_rt(net, rt); |
2671 rt = NULL; 2672 } else if (addrconf_finite_timeout(rt_expires)) { 2673 /* not infinity */ | 2670 rt = NULL; 2671 } else if (addrconf_finite_timeout(rt_expires)) { 2672 /* not infinity */ |
2674 rt6_set_expires(rt, jiffies + rt_expires); | 2673 fib6_set_expires(rt, jiffies + rt_expires); |
2675 } else { | 2674 } else { |
2676 rt6_clean_expires(rt); | 2675 fib6_clean_expires(rt); |
2677 } 2678 } else if (valid_lft) { 2679 clock_t expires = 0; 2680 int flags = RTF_ADDRCONF | RTF_PREFIX_RT; 2681 if (addrconf_finite_timeout(rt_expires)) { 2682 /* not infinity */ 2683 flags |= RTF_EXPIRES; 2684 expires = jiffies_to_clock_t(rt_expires); 2685 } 2686 addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, | 2676 } 2677 } else if (valid_lft) { 2678 clock_t expires = 0; 2679 int flags = RTF_ADDRCONF | RTF_PREFIX_RT; 2680 if (addrconf_finite_timeout(rt_expires)) { 2681 /* not infinity */ 2682 flags |= RTF_EXPIRES; 2683 expires = jiffies_to_clock_t(rt_expires); 2684 } 2685 addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, |
2687 dev, expires, flags); | 2686 dev, expires, flags, GFP_ATOMIC); |
2688 } | 2687 } |
2689 ip6_rt_put(rt); | 2688 fib6_info_release(rt); |
2690 } 2691 2692 /* Try to figure out our local address for this prefix */ 2693 2694 if (pinfo->autoconf && in6_dev->cnf.autoconf) { 2695 struct in6_addr addr; 2696 bool tokenized = false, dev_addr_generated = false; 2697 --- 196 unchanged lines hidden (view full) --- 2894 } 2895 2896 ifp = ipv6_add_addr(idev, pfx, peer_pfx, plen, scope, ifa_flags, 2897 valid_lft, prefered_lft, true, extack); 2898 2899 if (!IS_ERR(ifp)) { 2900 if (!(ifa_flags & IFA_F_NOPREFIXROUTE)) { 2901 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, | 2689 } 2690 2691 /* Try to figure out our local address for this prefix */ 2692 2693 if (pinfo->autoconf && in6_dev->cnf.autoconf) { 2694 struct in6_addr addr; 2695 bool tokenized = false, dev_addr_generated = false; 2696 --- 196 unchanged lines hidden (view full) --- 2893 } 2894 2895 ifp = ipv6_add_addr(idev, pfx, peer_pfx, plen, scope, ifa_flags, 2896 valid_lft, prefered_lft, true, extack); 2897 2898 if (!IS_ERR(ifp)) { 2899 if (!(ifa_flags & IFA_F_NOPREFIXROUTE)) { 2900 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, dev, |
2902 expires, flags); | 2901 expires, flags, GFP_KERNEL); |
2903 } 2904 | 2902 } 2903 |
2904 /* Send a netlink notification if DAD is enabled and 2905 * optimistic flag is not set 2906 */ 2907 if (!(ifp->flags & (IFA_F_OPTIMISTIC | IFA_F_NODAD))) 2908 ipv6_ifa_notify(0, ifp); |
|
2905 /* 2906 * Note that section 3.1 of RFC 4429 indicates 2907 * that the Optimistic flag should not be set for 2908 * manually configured addresses 2909 */ 2910 addrconf_dad_start(ifp); 2911 if (ifa_flags & IFA_F_MANAGETEMPADDR) 2912 manage_tempaddrs(idev, ifp, valid_lft, prefered_lft, --- 129 unchanged lines hidden (view full) --- 3042 } else { 3043 scope = IPV6_ADDR_COMPATv4; 3044 plen = 96; 3045 pflags |= RTF_NONEXTHOP; 3046 } 3047 3048 if (addr.s6_addr32[3]) { 3049 add_addr(idev, &addr, plen, scope); | 2909 /* 2910 * Note that section 3.1 of RFC 4429 indicates 2911 * that the Optimistic flag should not be set for 2912 * manually configured addresses 2913 */ 2914 addrconf_dad_start(ifp); 2915 if (ifa_flags & IFA_F_MANAGETEMPADDR) 2916 manage_tempaddrs(idev, ifp, valid_lft, prefered_lft, --- 129 unchanged lines hidden (view full) --- 3046 } else { 3047 scope = IPV6_ADDR_COMPATv4; 3048 plen = 96; 3049 pflags |= RTF_NONEXTHOP; 3050 } 3051 3052 if (addr.s6_addr32[3]) { 3053 add_addr(idev, &addr, plen, scope); |
3050 addrconf_prefix_route(&addr, plen, idev->dev, 0, pflags); | 3054 addrconf_prefix_route(&addr, plen, idev->dev, 0, pflags, 3055 GFP_ATOMIC); |
3051 return; 3052 } 3053 3054 for_each_netdev(net, dev) { 3055 struct in_device *in_dev = __in_dev_get_rtnl(dev); 3056 if (in_dev && (dev->flags & IFF_UP)) { 3057 struct in_ifaddr *ifa; 3058 --- 8 unchanged lines hidden (view full) --- 3067 if (ifa->ifa_scope >= RT_SCOPE_HOST) { 3068 if (idev->dev->flags&IFF_POINTOPOINT) 3069 continue; 3070 flag |= IFA_HOST; 3071 } 3072 3073 add_addr(idev, &addr, plen, flag); 3074 addrconf_prefix_route(&addr, plen, idev->dev, 0, | 3056 return; 3057 } 3058 3059 for_each_netdev(net, dev) { 3060 struct in_device *in_dev = __in_dev_get_rtnl(dev); 3061 if (in_dev && (dev->flags & IFF_UP)) { 3062 struct in_ifaddr *ifa; 3063 --- 8 unchanged lines hidden (view full) --- 3072 if (ifa->ifa_scope >= RT_SCOPE_HOST) { 3073 if (idev->dev->flags&IFF_POINTOPOINT) 3074 continue; 3075 flag |= IFA_HOST; 3076 } 3077 3078 add_addr(idev, &addr, plen, flag); 3079 addrconf_prefix_route(&addr, plen, idev->dev, 0, |
3075 pflags); | 3080 pflags, GFP_ATOMIC); |
3076 } 3077 } 3078 } 3079} 3080#endif 3081 3082static void init_loopback(struct net_device *dev) 3083{ --- 23 unchanged lines hidden (view full) --- 3107 idev->cnf.optimistic_dad) && 3108 !dev_net(idev->dev)->ipv6.devconf_all->forwarding) 3109 addr_flags |= IFA_F_OPTIMISTIC; 3110#endif 3111 3112 ifp = ipv6_add_addr(idev, addr, NULL, 64, IFA_LINK, addr_flags, 3113 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME, true, NULL); 3114 if (!IS_ERR(ifp)) { | 3081 } 3082 } 3083 } 3084} 3085#endif 3086 3087static void init_loopback(struct net_device *dev) 3088{ --- 23 unchanged lines hidden (view full) --- 3112 idev->cnf.optimistic_dad) && 3113 !dev_net(idev->dev)->ipv6.devconf_all->forwarding) 3114 addr_flags |= IFA_F_OPTIMISTIC; 3115#endif 3116 3117 ifp = ipv6_add_addr(idev, addr, NULL, 64, IFA_LINK, addr_flags, 3118 INFINITY_LIFE_TIME, INFINITY_LIFE_TIME, true, NULL); 3119 if (!IS_ERR(ifp)) { |
3115 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, 0, 0); | 3120 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, idev->dev, 3121 0, 0, GFP_ATOMIC); |
3116 addrconf_dad_start(ifp); 3117 in6_ifa_put(ifp); 3118 } 3119} 3120EXPORT_SYMBOL_GPL(addrconf_add_linklocal); 3121 3122static bool ipv6_reserved_interfaceid(struct in6_addr address) 3123{ --- 98 unchanged lines hidden (view full) --- 3222 case IN6_ADDR_GEN_MODE_RANDOM: 3223 ipv6_gen_mode_random_init(idev); 3224 /* fallthrough */ 3225 case IN6_ADDR_GEN_MODE_STABLE_PRIVACY: 3226 if (!ipv6_generate_stable_address(&addr, 0, idev)) 3227 addrconf_add_linklocal(idev, &addr, 3228 IFA_F_STABLE_PRIVACY); 3229 else if (prefix_route) | 3122 addrconf_dad_start(ifp); 3123 in6_ifa_put(ifp); 3124 } 3125} 3126EXPORT_SYMBOL_GPL(addrconf_add_linklocal); 3127 3128static bool ipv6_reserved_interfaceid(struct in6_addr address) 3129{ --- 98 unchanged lines hidden (view full) --- 3228 case IN6_ADDR_GEN_MODE_RANDOM: 3229 ipv6_gen_mode_random_init(idev); 3230 /* fallthrough */ 3231 case IN6_ADDR_GEN_MODE_STABLE_PRIVACY: 3232 if (!ipv6_generate_stable_address(&addr, 0, idev)) 3233 addrconf_add_linklocal(idev, &addr, 3234 IFA_F_STABLE_PRIVACY); 3235 else if (prefix_route) |
3230 addrconf_prefix_route(&addr, 64, idev->dev, 0, 0); | 3236 addrconf_prefix_route(&addr, 64, idev->dev, 3237 0, 0, GFP_KERNEL); |
3231 break; 3232 case IN6_ADDR_GEN_MODE_EUI64: 3233 /* addrconf_add_linklocal also adds a prefix_route and we 3234 * only need to care about prefix routes if ipv6_generate_eui64 3235 * couldn't generate one. 3236 */ 3237 if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0) 3238 addrconf_add_linklocal(idev, &addr, 0); 3239 else if (prefix_route) | 3238 break; 3239 case IN6_ADDR_GEN_MODE_EUI64: 3240 /* addrconf_add_linklocal also adds a prefix_route and we 3241 * only need to care about prefix routes if ipv6_generate_eui64 3242 * couldn't generate one. 3243 */ 3244 if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0) 3245 addrconf_add_linklocal(idev, &addr, 0); 3246 else if (prefix_route) |
3240 addrconf_prefix_route(&addr, 64, idev->dev, 0, 0); | 3247 addrconf_prefix_route(&addr, 64, idev->dev, 3248 0, 0, GFP_KERNEL); |
3241 break; 3242 case IN6_ADDR_GEN_MODE_NONE: 3243 default: 3244 /* will not add any link local address */ 3245 break; 3246 } 3247} 3248 --- 75 unchanged lines hidden (view full) --- 3324 } 3325 3326 addrconf_addr_gen(idev, true); 3327 if (dev->flags & IFF_POINTOPOINT) 3328 addrconf_add_mroute(dev); 3329} 3330#endif 3331 | 3249 break; 3250 case IN6_ADDR_GEN_MODE_NONE: 3251 default: 3252 /* will not add any link local address */ 3253 break; 3254 } 3255} 3256 --- 75 unchanged lines hidden (view full) --- 3332 } 3333 3334 addrconf_addr_gen(idev, true); 3335 if (dev->flags & IFF_POINTOPOINT) 3336 addrconf_add_mroute(dev); 3337} 3338#endif 3339 |
3332static int fixup_permanent_addr(struct inet6_dev *idev, | 3340static int fixup_permanent_addr(struct net *net, 3341 struct inet6_dev *idev, |
3333 struct inet6_ifaddr *ifp) 3334{ | 3342 struct inet6_ifaddr *ifp) 3343{ |
3335 /* !rt6i_node means the host route was removed from the | 3344 /* !fib6_node means the host route was removed from the |
3336 * FIB, for example, if 'lo' device is taken down. In that 3337 * case regenerate the host route. 3338 */ | 3345 * FIB, for example, if 'lo' device is taken down. In that 3346 * case regenerate the host route. 3347 */ |
3339 if (!ifp->rt || !ifp->rt->rt6i_node) { 3340 struct rt6_info *rt, *prev; | 3348 if (!ifp->rt || !ifp->rt->fib6_node) { 3349 struct fib6_info *f6i, *prev; |
3341 | 3350 |
3342 rt = addrconf_dst_alloc(idev, &ifp->addr, false); 3343 if (IS_ERR(rt)) 3344 return PTR_ERR(rt); | 3351 f6i = addrconf_f6i_alloc(net, idev, &ifp->addr, false, 3352 GFP_ATOMIC); 3353 if (IS_ERR(f6i)) 3354 return PTR_ERR(f6i); |
3345 3346 /* ifp->rt can be accessed outside of rtnl */ 3347 spin_lock(&ifp->lock); 3348 prev = ifp->rt; | 3355 3356 /* ifp->rt can be accessed outside of rtnl */ 3357 spin_lock(&ifp->lock); 3358 prev = ifp->rt; |
3349 ifp->rt = rt; | 3359 ifp->rt = f6i; |
3350 spin_unlock(&ifp->lock); 3351 | 3360 spin_unlock(&ifp->lock); 3361 |
3352 ip6_rt_put(prev); | 3362 fib6_info_release(prev); |
3353 } 3354 3355 if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) { 3356 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, | 3363 } 3364 3365 if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) { 3366 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, |
3357 idev->dev, 0, 0); | 3367 idev->dev, 0, 0, GFP_ATOMIC); |
3358 } 3359 3360 if (ifp->state == INET6_IFADDR_STATE_PREDAD) 3361 addrconf_dad_start(ifp); 3362 3363 return 0; 3364} 3365 | 3368 } 3369 3370 if (ifp->state == INET6_IFADDR_STATE_PREDAD) 3371 addrconf_dad_start(ifp); 3372 3373 return 0; 3374} 3375 |
3366static void addrconf_permanent_addr(struct net_device *dev) | 3376static void addrconf_permanent_addr(struct net *net, struct net_device *dev) |
3367{ 3368 struct inet6_ifaddr *ifp, *tmp; 3369 struct inet6_dev *idev; 3370 3371 idev = __in6_dev_get(dev); 3372 if (!idev) 3373 return; 3374 3375 write_lock_bh(&idev->lock); 3376 3377 list_for_each_entry_safe(ifp, tmp, &idev->addr_list, if_list) { 3378 if ((ifp->flags & IFA_F_PERMANENT) && | 3377{ 3378 struct inet6_ifaddr *ifp, *tmp; 3379 struct inet6_dev *idev; 3380 3381 idev = __in6_dev_get(dev); 3382 if (!idev) 3383 return; 3384 3385 write_lock_bh(&idev->lock); 3386 3387 list_for_each_entry_safe(ifp, tmp, &idev->addr_list, if_list) { 3388 if ((ifp->flags & IFA_F_PERMANENT) && |
3379 fixup_permanent_addr(idev, ifp) < 0) { | 3389 fixup_permanent_addr(net, idev, ifp) < 0) { |
3380 write_unlock_bh(&idev->lock); 3381 in6_ifa_hold(ifp); 3382 ipv6_del_addr(ifp); 3383 write_lock_bh(&idev->lock); 3384 3385 net_info_ratelimited("%s: Failed to add prefix route for address %pI6c; dropping\n", 3386 idev->dev->name, &ifp->addr); 3387 } --- 52 unchanged lines hidden (view full) --- 3440 if (dev->flags & IFF_SLAVE) 3441 break; 3442 3443 if (idev && idev->cnf.disable_ipv6) 3444 break; 3445 3446 if (event == NETDEV_UP) { 3447 /* restore routes for permanent addresses */ | 3390 write_unlock_bh(&idev->lock); 3391 in6_ifa_hold(ifp); 3392 ipv6_del_addr(ifp); 3393 write_lock_bh(&idev->lock); 3394 3395 net_info_ratelimited("%s: Failed to add prefix route for address %pI6c; dropping\n", 3396 idev->dev->name, &ifp->addr); 3397 } --- 52 unchanged lines hidden (view full) --- 3450 if (dev->flags & IFF_SLAVE) 3451 break; 3452 3453 if (idev && idev->cnf.disable_ipv6) 3454 break; 3455 3456 if (event == NETDEV_UP) { 3457 /* restore routes for permanent addresses */ |
3448 addrconf_permanent_addr(dev); | 3458 addrconf_permanent_addr(net, dev); |
3449 3450 if (!addrconf_link_ready(dev)) { 3451 /* device is not ready yet. */ 3452 pr_info("ADDRCONF(NETDEV_UP): %s: link is not ready\n", 3453 dev->name); 3454 break; 3455 } 3456 --- 150 unchanged lines hidden (view full) --- 3607} 3608 3609static int addrconf_ifdown(struct net_device *dev, int how) 3610{ 3611 unsigned long event = how ? NETDEV_UNREGISTER : NETDEV_DOWN; 3612 struct net *net = dev_net(dev); 3613 struct inet6_dev *idev; 3614 struct inet6_ifaddr *ifa, *tmp; | 3459 3460 if (!addrconf_link_ready(dev)) { 3461 /* device is not ready yet. */ 3462 pr_info("ADDRCONF(NETDEV_UP): %s: link is not ready\n", 3463 dev->name); 3464 break; 3465 } 3466 --- 150 unchanged lines hidden (view full) --- 3617} 3618 3619static int addrconf_ifdown(struct net_device *dev, int how) 3620{ 3621 unsigned long event = how ? NETDEV_UNREGISTER : NETDEV_DOWN; 3622 struct net *net = dev_net(dev); 3623 struct inet6_dev *idev; 3624 struct inet6_ifaddr *ifa, *tmp; |
3615 int _keep_addr; 3616 bool keep_addr; | 3625 bool keep_addr = false; |
3617 int state, i; 3618 3619 ASSERT_RTNL(); 3620 3621 rt6_disable_ip(dev, event); 3622 3623 idev = __in6_dev_get(dev); 3624 if (!idev) --- 9 unchanged lines hidden (view full) --- 3634 /* protected by rtnl_lock */ 3635 RCU_INIT_POINTER(dev->ip6_ptr, NULL); 3636 3637 /* Step 1.5: remove snmp6 entry */ 3638 snmp6_unregister_dev(idev); 3639 3640 } 3641 | 3626 int state, i; 3627 3628 ASSERT_RTNL(); 3629 3630 rt6_disable_ip(dev, event); 3631 3632 idev = __in6_dev_get(dev); 3633 if (!idev) --- 9 unchanged lines hidden (view full) --- 3643 /* protected by rtnl_lock */ 3644 RCU_INIT_POINTER(dev->ip6_ptr, NULL); 3645 3646 /* Step 1.5: remove snmp6 entry */ 3647 snmp6_unregister_dev(idev); 3648 3649 } 3650 |
3642 /* aggregate the system setting and interface setting */ 3643 _keep_addr = net->ipv6.devconf_all->keep_addr_on_down; 3644 if (!_keep_addr) 3645 _keep_addr = idev->cnf.keep_addr_on_down; 3646 | |
3647 /* combine the user config with event to determine if permanent 3648 * addresses are to be removed from address hash table 3649 */ | 3651 /* combine the user config with event to determine if permanent 3652 * addresses are to be removed from address hash table 3653 */ |
3650 keep_addr = !(how || _keep_addr <= 0 || idev->cnf.disable_ipv6); | 3654 if (!how && !idev->cnf.disable_ipv6) { 3655 /* aggregate the system setting and interface setting */ 3656 int _keep_addr = net->ipv6.devconf_all->keep_addr_on_down; |
3651 | 3657 |
3658 if (!_keep_addr) 3659 _keep_addr = idev->cnf.keep_addr_on_down; 3660 3661 keep_addr = (_keep_addr > 0); 3662 } 3663 |
|
3652 /* Step 2: clear hash table */ 3653 for (i = 0; i < IN6_ADDR_HSIZE; i++) { 3654 struct hlist_head *h = &inet6_addr_lst[i]; 3655 3656 spin_lock_bh(&addrconf_hash_lock); 3657restart: 3658 hlist_for_each_entry_rcu(ifa, h, addr_lst) { 3659 if (ifa->idev == idev) { --- 32 unchanged lines hidden (view full) --- 3692 in6_ifa_put(ifa->ifpub); 3693 ifa->ifpub = NULL; 3694 } 3695 spin_unlock_bh(&ifa->lock); 3696 in6_ifa_put(ifa); 3697 write_lock_bh(&idev->lock); 3698 } 3699 | 3664 /* Step 2: clear hash table */ 3665 for (i = 0; i < IN6_ADDR_HSIZE; i++) { 3666 struct hlist_head *h = &inet6_addr_lst[i]; 3667 3668 spin_lock_bh(&addrconf_hash_lock); 3669restart: 3670 hlist_for_each_entry_rcu(ifa, h, addr_lst) { 3671 if (ifa->idev == idev) { --- 32 unchanged lines hidden (view full) --- 3704 in6_ifa_put(ifa->ifpub); 3705 ifa->ifpub = NULL; 3706 } 3707 spin_unlock_bh(&ifa->lock); 3708 in6_ifa_put(ifa); 3709 write_lock_bh(&idev->lock); 3710 } 3711 |
3700 /* re-combine the user config with event to determine if permanent 3701 * addresses are to be removed from the interface list 3702 */ 3703 keep_addr = (!how && _keep_addr > 0 && !idev->cnf.disable_ipv6); 3704 | |
3705 list_for_each_entry_safe(ifa, tmp, &idev->addr_list, if_list) { | 3712 list_for_each_entry_safe(ifa, tmp, &idev->addr_list, if_list) { |
3706 struct rt6_info *rt = NULL; | 3713 struct fib6_info *rt = NULL; |
3707 bool keep; 3708 3709 addrconf_del_dad_work(ifa); 3710 3711 keep = keep_addr && (ifa->flags & IFA_F_PERMANENT) && 3712 !addr_is_local(&ifa->addr); 3713 3714 write_unlock_bh(&idev->lock); --- 11 unchanged lines hidden (view full) --- 3726 } else { 3727 state = ifa->state; 3728 ifa->state = INET6_IFADDR_STATE_DEAD; 3729 } 3730 3731 spin_unlock_bh(&ifa->lock); 3732 3733 if (rt) | 3714 bool keep; 3715 3716 addrconf_del_dad_work(ifa); 3717 3718 keep = keep_addr && (ifa->flags & IFA_F_PERMANENT) && 3719 !addr_is_local(&ifa->addr); 3720 3721 write_unlock_bh(&idev->lock); --- 11 unchanged lines hidden (view full) --- 3733 } else { 3734 state = ifa->state; 3735 ifa->state = INET6_IFADDR_STATE_DEAD; 3736 } 3737 3738 spin_unlock_bh(&ifa->lock); 3739 3740 if (rt) |
3734 ip6_del_rt(rt); | 3741 ip6_del_rt(net, rt); |
3735 3736 if (state != INET6_IFADDR_STATE_DEAD) { 3737 __ipv6_ifa_notify(RTM_DELADDR, ifa); 3738 inet6addr_notifier_call_chain(NETDEV_DOWN, ifa); 3739 } else { 3740 if (idev->cnf.forwarding) 3741 addrconf_leave_anycast(ifa); 3742 addrconf_leave_solict(ifa->idev, &ifa->addr); --- 101 unchanged lines hidden (view full) --- 3844 addrconf_mod_dad_work(ifp, rand_num); 3845} 3846 3847static void addrconf_dad_begin(struct inet6_ifaddr *ifp) 3848{ 3849 struct inet6_dev *idev = ifp->idev; 3850 struct net_device *dev = idev->dev; 3851 bool bump_id, notify = false; | 3742 3743 if (state != INET6_IFADDR_STATE_DEAD) { 3744 __ipv6_ifa_notify(RTM_DELADDR, ifa); 3745 inet6addr_notifier_call_chain(NETDEV_DOWN, ifa); 3746 } else { 3747 if (idev->cnf.forwarding) 3748 addrconf_leave_anycast(ifa); 3749 addrconf_leave_solict(ifa->idev, &ifa->addr); --- 101 unchanged lines hidden (view full) --- 3851 addrconf_mod_dad_work(ifp, rand_num); 3852} 3853 3854static void addrconf_dad_begin(struct inet6_ifaddr *ifp) 3855{ 3856 struct inet6_dev *idev = ifp->idev; 3857 struct net_device *dev = idev->dev; 3858 bool bump_id, notify = false; |
3859 struct net *net; |
|
3852 3853 addrconf_join_solict(dev, &ifp->addr); 3854 3855 prandom_seed((__force u32) ifp->addr.s6_addr32[3]); 3856 3857 read_lock_bh(&idev->lock); 3858 spin_lock(&ifp->lock); 3859 if (ifp->state == INET6_IFADDR_STATE_DEAD) 3860 goto out; 3861 | 3860 3861 addrconf_join_solict(dev, &ifp->addr); 3862 3863 prandom_seed((__force u32) ifp->addr.s6_addr32[3]); 3864 3865 read_lock_bh(&idev->lock); 3866 spin_lock(&ifp->lock); 3867 if (ifp->state == INET6_IFADDR_STATE_DEAD) 3868 goto out; 3869 |
3870 net = dev_net(dev); |
|
3862 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || | 3871 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || |
3863 (dev_net(dev)->ipv6.devconf_all->accept_dad < 1 && | 3872 (net->ipv6.devconf_all->accept_dad < 1 && |
3864 idev->cnf.accept_dad < 1) || 3865 !(ifp->flags&IFA_F_TENTATIVE) || 3866 ifp->flags & IFA_F_NODAD) { 3867 bool send_na = false; 3868 3869 if (ifp->flags & IFA_F_TENTATIVE && 3870 !(ifp->flags & IFA_F_OPTIMISTIC)) 3871 send_na = true; --- 19 unchanged lines hidden (view full) --- 3891 return; 3892 } 3893 3894 /* 3895 * Optimistic nodes can start receiving 3896 * Frames right away 3897 */ 3898 if (ifp->flags & IFA_F_OPTIMISTIC) { | 3873 idev->cnf.accept_dad < 1) || 3874 !(ifp->flags&IFA_F_TENTATIVE) || 3875 ifp->flags & IFA_F_NODAD) { 3876 bool send_na = false; 3877 3878 if (ifp->flags & IFA_F_TENTATIVE && 3879 !(ifp->flags & IFA_F_OPTIMISTIC)) 3880 send_na = true; --- 19 unchanged lines hidden (view full) --- 3900 return; 3901 } 3902 3903 /* 3904 * Optimistic nodes can start receiving 3905 * Frames right away 3906 */ 3907 if (ifp->flags & IFA_F_OPTIMISTIC) { |
3899 ip6_ins_rt(ifp->rt); 3900 if (ipv6_use_optimistic_addr(dev_net(dev), idev)) { | 3908 ip6_ins_rt(net, ifp->rt); 3909 if (ipv6_use_optimistic_addr(net, idev)) { |
3901 /* Because optimistic nodes can use this address, 3902 * notify listeners. If DAD fails, RTM_DELADDR is sent. 3903 */ 3904 notify = true; 3905 } 3906 } 3907 3908 addrconf_dad_kick(ifp); --- 649 unchanged lines hidden (view full) --- 4558 ifp->valid_lft = valid_lft; 4559 ifp->prefered_lft = prefered_lft; 4560 4561 spin_unlock_bh(&ifp->lock); 4562 if (!(ifp->flags&IFA_F_TENTATIVE)) 4563 ipv6_ifa_notify(0, ifp); 4564 4565 if (!(ifa_flags & IFA_F_NOPREFIXROUTE)) { | 3910 /* Because optimistic nodes can use this address, 3911 * notify listeners. If DAD fails, RTM_DELADDR is sent. 3912 */ 3913 notify = true; 3914 } 3915 } 3916 3917 addrconf_dad_kick(ifp); --- 649 unchanged lines hidden (view full) --- 4567 ifp->valid_lft = valid_lft; 4568 ifp->prefered_lft = prefered_lft; 4569 4570 spin_unlock_bh(&ifp->lock); 4571 if (!(ifp->flags&IFA_F_TENTATIVE)) 4572 ipv6_ifa_notify(0, ifp); 4573 4574 if (!(ifa_flags & IFA_F_NOPREFIXROUTE)) { |
4566 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, ifp->idev->dev, 4567 expires, flags); | 4575 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, 4576 ifp->idev->dev, expires, flags, 4577 GFP_KERNEL); |
4568 } else if (had_prefixroute) { 4569 enum cleanup_prefix_rt_t action; 4570 unsigned long rt_expires; 4571 4572 write_lock_bh(&ifp->idev->lock); 4573 action = check_cleanup_prefix_route(ifp, &rt_expires); 4574 write_unlock_bh(&ifp->idev->lock); 4575 --- 223 unchanged lines hidden (view full) --- 4799 4800 nlmsg_end(skb, nlh); 4801 return 0; 4802} 4803 4804static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca, 4805 u32 portid, u32 seq, int event, unsigned int flags) 4806{ | 4578 } else if (had_prefixroute) { 4579 enum cleanup_prefix_rt_t action; 4580 unsigned long rt_expires; 4581 4582 write_lock_bh(&ifp->idev->lock); 4583 action = check_cleanup_prefix_route(ifp, &rt_expires); 4584 write_unlock_bh(&ifp->idev->lock); 4585 --- 223 unchanged lines hidden (view full) --- 4809 4810 nlmsg_end(skb, nlh); 4811 return 0; 4812} 4813 4814static int inet6_fill_ifacaddr(struct sk_buff *skb, struct ifacaddr6 *ifaca, 4815 u32 portid, u32 seq, int event, unsigned int flags) 4816{ |
4817 struct net_device *dev = fib6_info_nh_dev(ifaca->aca_rt); 4818 int ifindex = dev ? dev->ifindex : 1; |
|
4807 struct nlmsghdr *nlh; 4808 u8 scope = RT_SCOPE_UNIVERSE; | 4819 struct nlmsghdr *nlh; 4820 u8 scope = RT_SCOPE_UNIVERSE; |
4809 int ifindex = ifaca->aca_idev->dev->ifindex; | |
4810 4811 if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE) 4812 scope = RT_SCOPE_SITE; 4813 4814 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags); 4815 if (!nlh) 4816 return -EMSGSIZE; 4817 --- 206 unchanged lines hidden (view full) --- 5024} 5025 5026static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa) 5027{ 5028 struct sk_buff *skb; 5029 struct net *net = dev_net(ifa->idev->dev); 5030 int err = -ENOBUFS; 5031 | 4821 4822 if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE) 4823 scope = RT_SCOPE_SITE; 4824 4825 nlh = nlmsg_put(skb, portid, seq, event, sizeof(struct ifaddrmsg), flags); 4826 if (!nlh) 4827 return -EMSGSIZE; 4828 --- 206 unchanged lines hidden (view full) --- 5035} 5036 5037static void inet6_ifa_notify(int event, struct inet6_ifaddr *ifa) 5038{ 5039 struct sk_buff *skb; 5040 struct net *net = dev_net(ifa->idev->dev); 5041 int err = -ENOBUFS; 5042 |
5032 /* Don't send DELADDR notification for TENTATIVE address, 5033 * since NEWADDR notification is sent only after removing 5034 * TENTATIVE flag, if DAD has not failed. 5035 */ 5036 if (ifa->flags & IFA_F_TENTATIVE && !(ifa->flags & IFA_F_DADFAILED) && 5037 event == RTM_DELADDR) 5038 return; 5039 | |
5040 skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC); 5041 if (!skb) 5042 goto errout; 5043 5044 err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0); 5045 if (err < 0) { 5046 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ 5047 WARN_ON(err == -EMSGSIZE); --- 554 unchanged lines hidden (view full) --- 5602 switch (event) { 5603 case RTM_NEWADDR: 5604 /* 5605 * If the address was optimistic 5606 * we inserted the route at the start of 5607 * our DAD process, so we don't need 5608 * to do it again 5609 */ | 5043 skb = nlmsg_new(inet6_ifaddr_msgsize(), GFP_ATOMIC); 5044 if (!skb) 5045 goto errout; 5046 5047 err = inet6_fill_ifaddr(skb, ifa, 0, 0, event, 0); 5048 if (err < 0) { 5049 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ 5050 WARN_ON(err == -EMSGSIZE); --- 554 unchanged lines hidden (view full) --- 5605 switch (event) { 5606 case RTM_NEWADDR: 5607 /* 5608 * If the address was optimistic 5609 * we inserted the route at the start of 5610 * our DAD process, so we don't need 5611 * to do it again 5612 */ |
5610 if (!rcu_access_pointer(ifp->rt->rt6i_node)) 5611 ip6_ins_rt(ifp->rt); | 5613 if (!rcu_access_pointer(ifp->rt->fib6_node)) 5614 ip6_ins_rt(net, ifp->rt); |
5612 if (ifp->idev->cnf.forwarding) 5613 addrconf_join_anycast(ifp); 5614 if (!ipv6_addr_any(&ifp->peer_addr)) 5615 addrconf_prefix_route(&ifp->peer_addr, 128, | 5615 if (ifp->idev->cnf.forwarding) 5616 addrconf_join_anycast(ifp); 5617 if (!ipv6_addr_any(&ifp->peer_addr)) 5618 addrconf_prefix_route(&ifp->peer_addr, 128, |
5616 ifp->idev->dev, 0, 0); | 5619 ifp->idev->dev, 0, 0, 5620 GFP_ATOMIC); |
5617 break; 5618 case RTM_DELADDR: 5619 if (ifp->idev->cnf.forwarding) 5620 addrconf_leave_anycast(ifp); 5621 addrconf_leave_solict(ifp->idev, &ifp->addr); 5622 if (!ipv6_addr_any(&ifp->peer_addr)) { | 5621 break; 5622 case RTM_DELADDR: 5623 if (ifp->idev->cnf.forwarding) 5624 addrconf_leave_anycast(ifp); 5625 addrconf_leave_solict(ifp->idev, &ifp->addr); 5626 if (!ipv6_addr_any(&ifp->peer_addr)) { |
5623 struct rt6_info *rt; | 5627 struct fib6_info *rt; |
5624 5625 rt = addrconf_get_prefix_route(&ifp->peer_addr, 128, 5626 ifp->idev->dev, 0, 0); 5627 if (rt) | 5628 5629 rt = addrconf_get_prefix_route(&ifp->peer_addr, 128, 5630 ifp->idev->dev, 0, 0); 5631 if (rt) |
5628 ip6_del_rt(rt); | 5632 ip6_del_rt(net, rt); |
5629 } 5630 if (ifp->rt) { | 5633 } 5634 if (ifp->rt) { |
5631 if (dst_hold_safe(&ifp->rt->dst)) 5632 ip6_del_rt(ifp->rt); | 5635 ip6_del_rt(net, ifp->rt); 5636 ifp->rt = NULL; |
5633 } 5634 rt_genid_bump_ipv6(net); 5635 break; 5636 } 5637 atomic_inc(&net->ipv6.dev_addr_genid); 5638} 5639 5640static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) --- 330 unchanged lines hidden (view full) --- 5971void addrconf_disable_policy_idev(struct inet6_dev *idev, int val) 5972{ 5973 struct inet6_ifaddr *ifa; 5974 5975 read_lock_bh(&idev->lock); 5976 list_for_each_entry(ifa, &idev->addr_list, if_list) { 5977 spin_lock(&ifa->lock); 5978 if (ifa->rt) { | 5637 } 5638 rt_genid_bump_ipv6(net); 5639 break; 5640 } 5641 atomic_inc(&net->ipv6.dev_addr_genid); 5642} 5643 5644static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) --- 330 unchanged lines hidden (view full) --- 5975void addrconf_disable_policy_idev(struct inet6_dev *idev, int val) 5976{ 5977 struct inet6_ifaddr *ifa; 5978 5979 read_lock_bh(&idev->lock); 5980 list_for_each_entry(ifa, &idev->addr_list, if_list) { 5981 spin_lock(&ifa->lock); 5982 if (ifa->rt) { |
5979 struct rt6_info *rt = ifa->rt; | 5983 struct fib6_info *rt = ifa->rt; |
5980 int cpu; 5981 5982 rcu_read_lock(); | 5984 int cpu; 5985 5986 rcu_read_lock(); |
5983 addrconf_set_nopolicy(ifa->rt, val); | 5987 ifa->rt->dst_nopolicy = val ? true : false; |
5984 if (rt->rt6i_pcpu) { 5985 for_each_possible_cpu(cpu) { 5986 struct rt6_info **rtp; 5987 5988 rtp = per_cpu_ptr(rt->rt6i_pcpu, cpu); 5989 addrconf_set_nopolicy(*rtp, val); 5990 } 5991 } --- 759 unchanged lines hidden --- | 5988 if (rt->rt6i_pcpu) { 5989 for_each_possible_cpu(cpu) { 5990 struct rt6_info **rtp; 5991 5992 rtp = per_cpu_ptr(rt->rt6i_pcpu, cpu); 5993 addrconf_set_nopolicy(*rtp, val); 5994 } 5995 } --- 759 unchanged lines hidden --- |