| @@ -216,6 +216,7 @@ static struct ipv6_devconf ipv6_devconf __read_mostly = { · 215 unmodified lines |
| 216 | }, | 216 | }, |
| 217 | .use_oif_addrs_only = 0, | 217 | .use_oif_addrs_only = 0, |
| 218 | .ignore_routes_with_linkdown = 0, | 218 | .ignore_routes_with_linkdown = 0, |
| | 219 | .keep_addr_on_down = 0, |
| 219 | }; | 220 | }; |
| 220 | | 221 | |
| 221 | static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { | 222 | static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { |
| @@ -260,6 +261,7 @@ static struct ipv6_devconf ipv6_devconf_dflt __read_mostly = { · 38 unmodified lines |
| 260 | }, | 261 | }, |
| 261 | .use_oif_addrs_only = 0, | 262 | .use_oif_addrs_only = 0, |
| 262 | .ignore_routes_with_linkdown = 0, | 263 | .ignore_routes_with_linkdown = 0, |
| | 264 | .keep_addr_on_down = 0, |
| 263 | }; | 265 | }; |
| 264 | | 266 | |
| 265 | /* Check if a valid qdisc is available */ | 267 | /* Check if a valid qdisc is available */ |
| @@ -3168,6 +3170,55 @@ static void addrconf_gre_config(struct net_device *dev) · 2902 unmodified lines |
| 3168 | } | 3170 | } |
| 3169 | #endif | 3171 | #endif |
| 3170 | | 3172 | |
| | 3173 | static int fixup_permanent_addr(struct inet6_dev *idev, |
| | 3174 | struct inet6_ifaddr *ifp) |
| | 3175 | { |
| | 3176 | if (!ifp->rt) { |
| | 3177 | struct rt6_info *rt; |
| | 3178 | |
| | 3179 | rt = addrconf_dst_alloc(idev, &ifp->addr, false); |
| | 3180 | if (unlikely(IS_ERR(rt))) |
| | 3181 | return PTR_ERR(rt); |
| | 3182 | |
| | 3183 | ifp->rt = rt; |
| | 3184 | } |
| | 3185 | |
| | 3186 | if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) { |
| | 3187 | addrconf_prefix_route(&ifp->addr, ifp->prefix_len, |
| | 3188 | idev->dev, 0, 0); |
| | 3189 | } |
| | 3190 | |
| | 3191 | addrconf_dad_start(ifp); |
| | 3192 | |
| | 3193 | return 0; |
| | 3194 | } |
| | 3195 | |
| | 3196 | static void addrconf_permanent_addr(struct net_device *dev) |
| | 3197 | { |
| | 3198 | struct inet6_ifaddr *ifp, *tmp; |
| | 3199 | struct inet6_dev *idev; |
| | 3200 | |
| | 3201 | idev = __in6_dev_get(dev); |
| | 3202 | if (!idev) |
| | 3203 | return; |
| | 3204 | |
| | 3205 | write_lock_bh(&idev->lock); |
| | 3206 | |
| | 3207 | list_for_each_entry_safe(ifp, tmp, &idev->addr_list, if_list) { |
| | 3208 | if ((ifp->flags & IFA_F_PERMANENT) && |
| | 3209 | fixup_permanent_addr(idev, ifp) < 0) { |
| | 3210 | write_unlock_bh(&idev->lock); |
| | 3211 | ipv6_del_addr(ifp); |
| | 3212 | write_lock_bh(&idev->lock); |
| | 3213 | |
| | 3214 | net_info_ratelimited("%s: Failed to add prefix route for address %pI6c; dropping\n", |
| | 3215 | idev->dev->name, &ifp->addr); |
| | 3216 | } |
| | 3217 | } |
| | 3218 | |
| | 3219 | write_unlock_bh(&idev->lock); |
| | 3220 | } |
| | 3221 | |
| 3171 | static int addrconf_notify(struct notifier_block *this, unsigned long event, | 3222 | static int addrconf_notify(struct notifier_block *this, unsigned long event, |
| 3172 | void *ptr) | 3223 | void *ptr) |
| 3173 | { | 3224 | { |
| @@ -3253,6 +3304,9 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event, · 79 unmodified lines |
| 3253 | run_pending = 1; | 3304 | run_pending = 1; |
| 3254 | } | 3305 | } |
| 3255 | | 3306 | |
| | 3307 | /* restore routes for permanent addresses */ |
| | 3308 | addrconf_permanent_addr(dev); |
| | 3309 | |
| 3256 | switch (dev->type) { | 3310 | switch (dev->type) { |
| 3257 | #if IS_ENABLED(CONFIG_IPV6_SIT) | 3311 | #if IS_ENABLED(CONFIG_IPV6_SIT) |
| 3258 | case ARPHRD_SIT: | 3312 | case ARPHRD_SIT: |
| @@ -3356,7 +3410,10 @@ static int addrconf_ifdown(struct net_device *dev, int how) · 97 unmodified lines |
| 3356 | { | 3410 | { |
| 3357 | struct net *net = dev_net(dev); | 3411 | struct net *net = dev_net(dev); |
| 3358 | struct inet6_dev *idev; | 3412 | struct inet6_dev *idev; |
| 3359 | struct inet6_ifaddr *ifa; | 3413 | struct inet6_ifaddr *ifa, *tmp; |
| | 3414 | struct list_head del_list; |
| | 3415 | int _keep_addr; |
| | 3416 | bool keep_addr; |
| 3360 | int state, i; | 3417 | int state, i; |
| 3361 | | 3418 | |
| 3362 | ASSERT_RTNL(); | 3419 | ASSERT_RTNL(); |
| @@ -3383,6 +3440,16 @@ static int addrconf_ifdown(struct net_device *dev, int how) · 20 unmodified lines |
| 3383 | | 3440 | |
| 3384 | } | 3441 | } |
| 3385 | | 3442 | |
| | 3443 | /* aggregate the system setting and interface setting */ |
| | 3444 | _keep_addr = net->ipv6.devconf_all->keep_addr_on_down; |
| | 3445 | if (!_keep_addr) |
| | 3446 | _keep_addr = idev->cnf.keep_addr_on_down; |
| | 3447 | |
| | 3448 | /* combine the user config with event to determine if permanent |
| | 3449 | * addresses are to be removed from address hash table |
| | 3450 | */ |
| | 3451 | keep_addr = !(how || _keep_addr <= 0); |
| | 3452 | |
| 3386 | /* Step 2: clear hash table */ | 3453 | /* Step 2: clear hash table */ |
| 3387 | for (i = 0; i < IN6_ADDR_HSIZE; i++) { | 3454 | for (i = 0; i < IN6_ADDR_HSIZE; i++) { |
| 3388 | struct hlist_head *h = &inet6_addr_lst[i]; | 3455 | struct hlist_head *h = &inet6_addr_lst[i]; |
| @@ -3391,9 +3458,15 @@ static int addrconf_ifdown(struct net_device *dev, int how) · 2 unmodified lines |
| 3391 | restart: | 3458 | restart: |
| 3392 | hlist_for_each_entry_rcu(ifa, h, addr_lst) { | 3459 | hlist_for_each_entry_rcu(ifa, h, addr_lst) { |
| 3393 | if (ifa->idev == idev) { | 3460 | if (ifa->idev == idev) { |
| 3394 | hlist_del_init_rcu(&ifa->addr_lst); | | |
| 3395 | addrconf_del_dad_work(ifa); | 3461 | addrconf_del_dad_work(ifa); |
| 3396 | goto restart; | 3462 | /* combined flag + permanent flag decide if |
| | 3463 | * address is retained on a down event |
| | 3464 | */ |
| | 3465 | if (!keep_addr || |
| | 3466 | !(ifa->flags & IFA_F_PERMANENT)) { |
| | 3467 | hlist_del_init_rcu(&ifa->addr_lst); |
| | 3468 | goto restart; |
| | 3469 | } |
| 3397 | } | 3470 | } |
| 3398 | } | 3471 | } |
| 3399 | spin_unlock_bh(&addrconf_hash_lock); | 3472 | spin_unlock_bh(&addrconf_hash_lock); |
| @@ -3427,31 +3500,53 @@ restart: · 27 unmodified lines |
| 3427 | write_lock_bh(&idev->lock); | 3500 | write_lock_bh(&idev->lock); |
| 3428 | } | 3501 | } |
| 3429 | | 3502 | |
| 3430 | while (!list_empty(&idev->addr_list)) { | 3503 | /* re-combine the user config with event to determine if permanent |
| 3431 | ifa = list_first_entry(&idev->addr_list, | 3504 | * addresses are to be removed from the interface list |
| 3432 | struct inet6_ifaddr, if_list); | 3505 | */ |
| 3433 | addrconf_del_dad_work(ifa); | 3506 | keep_addr = (!how && _keep_addr > 0); |
| 3434 | | 3507 | |
| 3435 | list_del(&ifa->if_list); | 3508 | INIT_LIST_HEAD(&del_list); |
| | 3509 | list_for_each_entry_safe(ifa, tmp, &idev->addr_list, if_list) { |
| | 3510 | addrconf_del_dad_work(ifa); |
| 3436 | | 3511 | |
| 3437 | write_unlock_bh(&idev->lock); | 3512 | write_unlock_bh(&idev->lock); |
| 3438 | | | |
| 3439 | spin_lock_bh(&ifa->lock); | 3513 | spin_lock_bh(&ifa->lock); |
| 3440 | state = ifa->state; | 3514 | |
| 3441 | ifa->state = INET6_IFADDR_STATE_DEAD; | 3515 | if (keep_addr && (ifa->flags & IFA_F_PERMANENT)) { |
| | 3516 | /* set state to skip the notifier below */ |
| | 3517 | state = INET6_IFADDR_STATE_DEAD; |
| | 3518 | ifa->state = 0; |
| | 3519 | if (!(ifa->flags & IFA_F_NODAD)) |
| | 3520 | ifa->flags |= IFA_F_TENTATIVE; |
| | 3521 | } else { |
| | 3522 | state = ifa->state; |
| | 3523 | ifa->state = INET6_IFADDR_STATE_DEAD; |
| | 3524 | |
| | 3525 | list_del(&ifa->if_list); |
| | 3526 | list_add(&ifa->if_list, &del_list); |
| | 3527 | } |
| | 3528 | |
| 3442 | spin_unlock_bh(&ifa->lock); | 3529 | spin_unlock_bh(&ifa->lock); |
| 3443 | | 3530 | |
| 3444 | if (state != INET6_IFADDR_STATE_DEAD) { | 3531 | if (state != INET6_IFADDR_STATE_DEAD) { |
| 3445 | __ipv6_ifa_notify(RTM_DELADDR, ifa); | 3532 | __ipv6_ifa_notify(RTM_DELADDR, ifa); |
| 3446 | inet6addr_notifier_call_chain(NETDEV_DOWN, ifa); | 3533 | inet6addr_notifier_call_chain(NETDEV_DOWN, ifa); |
| 3447 | } | 3534 | } |
| 3448 | in6_ifa_put(ifa); | | |
| 3449 | | 3535 | |
| 3450 | write_lock_bh(&idev->lock); | 3536 | write_lock_bh(&idev->lock); |
| 3451 | } | 3537 | } |
| 3452 | | 3538 | |
| 3453 | write_unlock_bh(&idev->lock); | 3539 | write_unlock_bh(&idev->lock); |
| 3454 | | 3540 | |
| | 3541 | /* now clean up addresses to be removed */ |
| | 3542 | while (!list_empty(&del_list)) { |
| | 3543 | ifa = list_first_entry(&del_list, |
| | 3544 | struct inet6_ifaddr, if_list); |
| | 3545 | list_del(&ifa->if_list); |
| | 3546 | |
| | 3547 | in6_ifa_put(ifa); |
| | 3548 | } |
| | 3549 | |
| 3455 | /* Step 5: Discard anycast and multicast list */ | 3550 | /* Step 5: Discard anycast and multicast list */ |
| 3456 | if (how) { | 3551 | if (how) { |
| 3457 | ipv6_ac_destroy_dev(idev); | 3552 | ipv6_ac_destroy_dev(idev); |
| @@ -4716,6 +4811,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf, · 1258 unmodified lines |
| 4716 | array[DEVCONF_USE_OIF_ADDRS_ONLY] = cnf->use_oif_addrs_only; | 4811 | array[DEVCONF_USE_OIF_ADDRS_ONLY] = cnf->use_oif_addrs_only; |
| 4717 | array[DEVCONF_DROP_UNICAST_IN_L2_MULTICAST] = cnf->drop_unicast_in_l2_multicast; | 4812 | array[DEVCONF_DROP_UNICAST_IN_L2_MULTICAST] = cnf->drop_unicast_in_l2_multicast; |
| 4718 | array[DEVCONF_DROP_UNSOLICITED_NA] = cnf->drop_unsolicited_na; | 4813 | array[DEVCONF_DROP_UNSOLICITED_NA] = cnf->drop_unsolicited_na; |
| | 4814 | array[DEVCONF_KEEP_ADDR_ON_DOWN] = cnf->keep_addr_on_down; |
| 4719 | } | 4815 | } |
| 4720 | | 4816 | |
| 4721 | static inline size_t inet6_ifla6_size(void) | 4817 | static inline size_t inet6_ifla6_size(void) |
| @@ -5197,10 +5293,12 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) · 475 unmodified lines |
| 5197 | if (rt) | 5293 | if (rt) |
| 5198 | ip6_del_rt(rt); | 5294 | ip6_del_rt(rt); |
| 5199 | } | 5295 | } |
| 5200 | dst_hold(&ifp->rt->dst); | 5296 | if (ifp->rt) { |
| 5201 | | 5297 | dst_hold(&ifp->rt->dst); |
| 5202 | ip6_del_rt(ifp->rt); | | |
| 5203 | | 5298 | |
| | 5299 | ip6_del_rt(ifp->rt); |
| | 5300 | ifp->rt = NULL; |
| | 5301 | } |
| 5204 | rt_genid_bump_ipv6(net); | 5302 | rt_genid_bump_ipv6(net); |
| 5205 | break; | 5303 | break; |
| 5206 | } | 5304 | } |
| @@ -5803,6 +5901,14 @@ static struct addrconf_sysctl_table · 596 unmodified lines |
| 5803 | .mode = 0644, | 5901 | .mode = 0644, |
| 5804 | .proc_handler = proc_dointvec, | 5902 | .proc_handler = proc_dointvec, |
| 5805 | }, | 5903 | }, |
| | 5904 | { |
| | 5905 | .procname = "keep_addr_on_down", |
| | 5906 | .data = &ipv6_devconf.keep_addr_on_down, |
| | 5907 | .maxlen = sizeof(int), |
| | 5908 | .mode = 0644, |
| | 5909 | .proc_handler = proc_dointvec, |
| | 5910 | |
| | 5911 | }, |
| 5806 | { | 5912 | { |
| 5807 | /* sentinel */ | 5913 | /* sentinel */ |
| 5808 | } | 5914 | } |