Lines Matching +full:route +full:- +full:ptp
1 // SPDX-License-Identifier: GPL-2.0-or-later
53 #include <linux/route.h>
100 return (cstamp - INITIAL_JIFFIES) * 100UL / HZ; in cstamp_delta()
315 if (del_timer(&idev->rs_timer)) in addrconf_del_rs_timer()
321 if (cancel_delayed_work(&ifp->dad_work)) in addrconf_del_dad_work()
328 if (!mod_timer(&idev->rs_timer, jiffies + when)) in addrconf_mod_rs_timer()
336 if (mod_delayed_work(addrconf_wq, &ifp->dad_work, delay)) in addrconf_mod_dad_work()
344 idev->stats.ipv6 = alloc_percpu_gfp(struct ipstats_mib, GFP_KERNEL_ACCOUNT); in snmp6_alloc_dev()
345 if (!idev->stats.ipv6) in snmp6_alloc_dev()
350 addrconf_stats = per_cpu_ptr(idev->stats.ipv6, i); in snmp6_alloc_dev()
351 u64_stats_init(&addrconf_stats->syncp); in snmp6_alloc_dev()
355 idev->stats.icmpv6dev = kzalloc(sizeof(struct icmpv6_mib_device), in snmp6_alloc_dev()
357 if (!idev->stats.icmpv6dev) in snmp6_alloc_dev()
359 idev->stats.icmpv6msgdev = kzalloc(sizeof(struct icmpv6msg_mib_device), in snmp6_alloc_dev()
361 if (!idev->stats.icmpv6msgdev) in snmp6_alloc_dev()
367 kfree(idev->stats.icmpv6dev); in snmp6_alloc_dev()
369 free_percpu(idev->stats.ipv6); in snmp6_alloc_dev()
371 return -ENOMEM; in snmp6_alloc_dev()
377 int err = -ENOMEM; in ipv6_add_dev()
381 if (dev->mtu < IPV6_MIN_MTU && dev != blackhole_netdev) in ipv6_add_dev()
382 return ERR_PTR(-EINVAL); in ipv6_add_dev()
388 rwlock_init(&ndev->lock); in ipv6_add_dev()
389 ndev->dev = dev; in ipv6_add_dev()
390 INIT_LIST_HEAD(&ndev->addr_list); in ipv6_add_dev()
391 timer_setup(&ndev->rs_timer, addrconf_rs_timer, 0); in ipv6_add_dev()
392 memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf)); in ipv6_add_dev()
394 if (ndev->cnf.stable_secret.initialized) in ipv6_add_dev()
395 ndev->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_STABLE_PRIVACY; in ipv6_add_dev()
397 ndev->cnf.mtu6 = dev->mtu; in ipv6_add_dev()
398 ndev->ra_mtu = 0; in ipv6_add_dev()
399 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl); in ipv6_add_dev()
400 if (!ndev->nd_parms) { in ipv6_add_dev()
404 if (ndev->cnf.forwarding) in ipv6_add_dev()
407 netdev_hold(dev, &ndev->dev_tracker, GFP_KERNEL); in ipv6_add_dev()
412 neigh_parms_release(&nd_tbl, ndev->nd_parms); in ipv6_add_dev()
413 netdev_put(dev, &ndev->dev_tracker); in ipv6_add_dev()
421 __func__, dev->name); in ipv6_add_dev()
426 refcount_set(&ndev->refcnt, 1); in ipv6_add_dev()
428 if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) in ipv6_add_dev()
429 ndev->cnf.accept_dad = -1; in ipv6_add_dev()
432 if (dev->type == ARPHRD_SIT && (dev->priv_flags & IFF_ISATAP)) { in ipv6_add_dev()
433 pr_info("%s: Disabled Multicast RS\n", dev->name); in ipv6_add_dev()
434 ndev->cnf.rtr_solicits = 0; in ipv6_add_dev()
438 INIT_LIST_HEAD(&ndev->tempaddr_list); in ipv6_add_dev()
439 ndev->desync_factor = U32_MAX; in ipv6_add_dev()
440 if ((dev->flags&IFF_LOOPBACK) || in ipv6_add_dev()
441 dev->type == ARPHRD_TUNNEL || in ipv6_add_dev()
442 dev->type == ARPHRD_TUNNEL6 || in ipv6_add_dev()
443 dev->type == ARPHRD_SIT || in ipv6_add_dev()
444 dev->type == ARPHRD_NONE) { in ipv6_add_dev()
445 ndev->cnf.use_tempaddr = -1; in ipv6_add_dev()
448 ndev->token = in6addr_any; in ipv6_add_dev()
451 ndev->if_flags |= IF_READY; in ipv6_add_dev()
454 ndev->tstamp = jiffies; in ipv6_add_dev()
464 rcu_assign_pointer(dev->ip6_ptr, ndev); in ipv6_add_dev()
467 /* Join interface-local all-node multicast group */ in ipv6_add_dev()
470 /* Join all-node multicast group */ in ipv6_add_dev()
473 /* Join all-router multicast group if forwarding is set */ in ipv6_add_dev()
474 if (ndev->cnf.forwarding && (dev->flags & IFF_MULTICAST)) in ipv6_add_dev()
480 neigh_parms_release(&nd_tbl, ndev->nd_parms); in ipv6_add_dev()
481 ndev->dead = 1; in ipv6_add_dev()
499 if (dev->flags&IFF_UP) in ipv6_find_idev()
540 return -EMSGSIZE; in inet6_netconf_fill_devconf()
546 ncm->ncm_family = AF_INET6; in inet6_netconf_fill_devconf()
556 READ_ONCE(devconf->forwarding)) < 0) in inet6_netconf_fill_devconf()
561 atomic_read(&devconf->mc_forwarding)) < 0) in inet6_netconf_fill_devconf()
566 READ_ONCE(devconf->proxy_ndp)) < 0) in inet6_netconf_fill_devconf()
571 READ_ONCE(devconf->ignore_routes_with_linkdown)) < 0) in inet6_netconf_fill_devconf()
580 return -EMSGSIZE; in inet6_netconf_fill_devconf()
587 int err = -ENOBUFS; in inet6_netconf_notify_devconf()
596 /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */ in inet6_netconf_notify_devconf()
597 WARN_ON(err == -EMSGSIZE); in inet6_netconf_notify_devconf()
621 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(struct netconfmsg))) { in inet6_netconf_valid_get_req()
623 return -EINVAL; in inet6_netconf_valid_get_req()
646 return -EINVAL; in inet6_netconf_valid_get_req()
657 struct net *net = sock_net(in_skb->sk); in inet6_netconf_get_devconf()
671 return -EINVAL; in inet6_netconf_get_devconf()
673 err = -EINVAL; in inet6_netconf_get_devconf()
677 devconf = net->ipv6.devconf_all; in inet6_netconf_get_devconf()
680 devconf = net->ipv6.devconf_dflt; in inet6_netconf_get_devconf()
685 return -EINVAL; in inet6_netconf_get_devconf()
689 devconf = &in6_dev->cnf; in inet6_netconf_get_devconf()
693 err = -ENOBUFS; in inet6_netconf_get_devconf()
700 nlh->nlmsg_seq, RTM_NEWNETCONF, 0, in inet6_netconf_get_devconf()
703 /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */ in inet6_netconf_get_devconf()
704 WARN_ON(err == -EMSGSIZE); in inet6_netconf_get_devconf()
720 u32 res = atomic_read(&net->ipv6.dev_addr_genid) + in inet6_base_seq()
721 READ_ONCE(net->dev_base_seq); in inet6_base_seq()
734 const struct nlmsghdr *nlh = cb->nlh; in inet6_netconf_dump_devconf()
735 struct net *net = sock_net(skb->sk); in inet6_netconf_dump_devconf()
739 } *ctx = (void *)cb->ctx; in inet6_netconf_dump_devconf()
744 if (cb->strict_check) { in inet6_netconf_dump_devconf()
745 struct netlink_ext_ack *extack = cb->extack; in inet6_netconf_dump_devconf()
748 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ncm))) { in inet6_netconf_dump_devconf()
750 return -EINVAL; in inet6_netconf_dump_devconf()
755 return -EINVAL; in inet6_netconf_dump_devconf()
760 for_each_netdev_dump(net, dev, ctx->ifindex) { in inet6_netconf_dump_devconf()
764 err = inet6_netconf_fill_devconf(skb, dev->ifindex, in inet6_netconf_dump_devconf()
765 &idev->cnf, in inet6_netconf_dump_devconf()
766 NETLINK_CB(cb->skb).portid, in inet6_netconf_dump_devconf()
767 nlh->nlmsg_seq, in inet6_netconf_dump_devconf()
774 if (ctx->all_default == 0) { in inet6_netconf_dump_devconf()
776 net->ipv6.devconf_all, in inet6_netconf_dump_devconf()
777 NETLINK_CB(cb->skb).portid, in inet6_netconf_dump_devconf()
778 nlh->nlmsg_seq, in inet6_netconf_dump_devconf()
783 ctx->all_default++; in inet6_netconf_dump_devconf()
785 if (ctx->all_default == 1) { in inet6_netconf_dump_devconf()
787 net->ipv6.devconf_dflt, in inet6_netconf_dump_devconf()
788 NETLINK_CB(cb->skb).portid, in inet6_netconf_dump_devconf()
789 nlh->nlmsg_seq, in inet6_netconf_dump_devconf()
794 ctx->all_default++; in inet6_netconf_dump_devconf()
810 dev = idev->dev; in dev_forward_change()
811 if (idev->cnf.forwarding) in dev_forward_change()
813 if (dev->flags & IFF_MULTICAST) { in dev_forward_change()
814 if (idev->cnf.forwarding) { in dev_forward_change()
825 read_lock_bh(&idev->lock); in dev_forward_change()
826 list_for_each_entry(ifa, &idev->addr_list, if_list) { in dev_forward_change()
827 if (ifa->flags&IFA_F_TENTATIVE) in dev_forward_change()
829 list_add_tail(&ifa->if_list_aux, &tmp_addr_list); in dev_forward_change()
831 read_unlock_bh(&idev->lock); in dev_forward_change()
836 list_del(&ifa->if_list_aux); in dev_forward_change()
837 if (idev->cnf.forwarding) in dev_forward_change()
845 dev->ifindex, &idev->cnf); in dev_forward_change()
857 int changed = (!idev->cnf.forwarding) ^ (!newf); in addrconf_forward_change()
859 WRITE_ONCE(idev->cnf.forwarding, newf); in addrconf_forward_change()
874 net = (struct net *)table->extra2; in addrconf_fixup_forwarding()
878 if (p == &net->ipv6.devconf_dflt->forwarding) { in addrconf_fixup_forwarding()
883 net->ipv6.devconf_dflt); in addrconf_fixup_forwarding()
888 if (p == &net->ipv6.devconf_all->forwarding) { in addrconf_fixup_forwarding()
889 int old_dflt = net->ipv6.devconf_dflt->forwarding; in addrconf_fixup_forwarding()
891 WRITE_ONCE(net->ipv6.devconf_dflt->forwarding, newf); in addrconf_fixup_forwarding()
896 net->ipv6.devconf_dflt); in addrconf_fixup_forwarding()
903 net->ipv6.devconf_all); in addrconf_fixup_forwarding()
905 dev_forward_change((struct inet6_dev *)table->extra1); in addrconf_fixup_forwarding()
921 int changed = (!idev->cnf.ignore_routes_with_linkdown) ^ (!newf); in addrconf_linkdown_change()
923 WRITE_ONCE(idev->cnf.ignore_routes_with_linkdown, newf); in addrconf_linkdown_change()
928 dev->ifindex, in addrconf_linkdown_change()
929 &idev->cnf); in addrconf_linkdown_change()
942 net = (struct net *)table->extra2; in addrconf_fixup_linkdown()
946 if (p == &net->ipv6.devconf_dflt->ignore_routes_with_linkdown) { in addrconf_fixup_linkdown()
952 net->ipv6.devconf_dflt); in addrconf_fixup_linkdown()
957 if (p == &net->ipv6.devconf_all->ignore_routes_with_linkdown) { in addrconf_fixup_linkdown()
958 WRITE_ONCE(net->ipv6.devconf_dflt->ignore_routes_with_linkdown, newf); in addrconf_fixup_linkdown()
965 net->ipv6.devconf_all); in addrconf_fixup_linkdown()
977 WARN_ON(!hlist_unhashed(&ifp->addr_lst)); in inet6_ifa_finish_destroy()
983 in6_dev_put(ifp->idev); in inet6_ifa_finish_destroy()
985 if (cancel_delayed_work(&ifp->dad_work)) in inet6_ifa_finish_destroy()
989 if (ifp->state != INET6_IFADDR_STATE_DEAD) { in inet6_ifa_finish_destroy()
1001 int ifp_scope = ipv6_addr_src_scope(&ifp->addr); in ipv6_link_dev_addr()
1004 * Each device address list is sorted in order of scope - in ipv6_link_dev_addr()
1007 list_for_each(p, &idev->addr_list) { in ipv6_link_dev_addr()
1010 if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr)) in ipv6_link_dev_addr()
1014 list_add_tail_rcu(&ifp->if_list, p); in ipv6_link_dev_addr()
1029 hlist_for_each_entry(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) { in ipv6_chk_same_addr()
1030 if (ipv6_addr_equal(&ifp->addr, addr)) { in ipv6_chk_same_addr()
1031 if (!dev || ifp->idev->dev == dev) in ipv6_chk_same_addr()
1041 unsigned int hash = inet6_addr_hash(net, &ifa->addr); in ipv6_add_addr_hash()
1044 spin_lock_bh(&net->ipv6.addrconf_hash_lock); in ipv6_add_addr_hash()
1047 if (ipv6_chk_same_addr(net, &ifa->addr, dev, hash)) { in ipv6_add_addr_hash()
1049 err = -EEXIST; in ipv6_add_addr_hash()
1051 hlist_add_head_rcu(&ifa->addr_lst, &net->ipv6.inet6_addr_lst[hash]); in ipv6_add_addr_hash()
1054 spin_unlock_bh(&net->ipv6.addrconf_hash_lock); in ipv6_add_addr_hash()
1066 int addr_type = ipv6_addr_type(cfg->pfx); in ipv6_add_addr()
1067 struct net *net = dev_net(idev->dev); in ipv6_add_addr()
1074 return ERR_PTR(-EADDRNOTAVAIL); in ipv6_add_addr()
1076 !(cfg->ifa_flags & IFA_F_MCAUTOJOIN)) { in ipv6_add_addr()
1078 return ERR_PTR(-EADDRNOTAVAIL); in ipv6_add_addr()
1079 } else if (!(idev->dev->flags & IFF_LOOPBACK) && in ipv6_add_addr()
1080 !netif_is_l3_master(idev->dev) && in ipv6_add_addr()
1083 return ERR_PTR(-EADDRNOTAVAIL); in ipv6_add_addr()
1086 if (idev->dead) { in ipv6_add_addr()
1088 err = -ENODEV; in ipv6_add_addr()
1092 if (idev->cnf.disable_ipv6) { in ipv6_add_addr()
1094 err = -EACCES; in ipv6_add_addr()
1103 .i6vi_addr = *cfg->pfx, in ipv6_add_addr()
1116 err = -ENOBUFS; in ipv6_add_addr()
1120 f6i = addrconf_f6i_alloc(net, idev, cfg->pfx, false, gfp_flags, extack); in ipv6_add_addr()
1127 neigh_parms_data_state_setall(idev->nd_parms); in ipv6_add_addr()
1129 ifa->addr = *cfg->pfx; in ipv6_add_addr()
1130 if (cfg->peer_pfx) in ipv6_add_addr()
1131 ifa->peer_addr = *cfg->peer_pfx; in ipv6_add_addr()
1133 spin_lock_init(&ifa->lock); in ipv6_add_addr()
1134 INIT_DELAYED_WORK(&ifa->dad_work, addrconf_dad_work); in ipv6_add_addr()
1135 INIT_HLIST_NODE(&ifa->addr_lst); in ipv6_add_addr()
1136 ifa->scope = cfg->scope; in ipv6_add_addr()
1137 ifa->prefix_len = cfg->plen; in ipv6_add_addr()
1138 ifa->rt_priority = cfg->rt_priority; in ipv6_add_addr()
1139 ifa->flags = cfg->ifa_flags; in ipv6_add_addr()
1140 ifa->ifa_proto = cfg->ifa_proto; in ipv6_add_addr()
1142 if (!(cfg->ifa_flags & IFA_F_NODAD)) in ipv6_add_addr()
1143 ifa->flags |= IFA_F_TENTATIVE; in ipv6_add_addr()
1144 ifa->valid_lft = cfg->valid_lft; in ipv6_add_addr()
1145 ifa->prefered_lft = cfg->preferred_lft; in ipv6_add_addr()
1146 ifa->cstamp = ifa->tstamp = jiffies; in ipv6_add_addr()
1147 ifa->tokenized = false; in ipv6_add_addr()
1149 ifa->rt = f6i; in ipv6_add_addr()
1151 ifa->idev = idev; in ipv6_add_addr()
1155 refcount_set(&ifa->refcnt, 1); in ipv6_add_addr()
1159 err = ipv6_add_addr_hash(idev->dev, ifa); in ipv6_add_addr()
1165 write_lock_bh(&idev->lock); in ipv6_add_addr()
1170 if (ifa->flags&IFA_F_TEMPORARY) { in ipv6_add_addr()
1171 list_add(&ifa->tmp_list, &idev->tempaddr_list); in ipv6_add_addr()
1176 write_unlock_bh(&idev->lock); in ipv6_add_addr()
1186 if (ifa->idev) in ipv6_add_addr()
1187 in6_dev_put(ifa->idev); in ipv6_add_addr()
1197 CLEANUP_PREFIX_RT_NOP, /* no cleanup action for prefix route */
1198 CLEANUP_PREFIX_RT_DEL, /* delete the prefix route */
1199 CLEANUP_PREFIX_RT_EXPIRE, /* update the lifetime of the prefix route */
1203 * Check, whether the prefix for ifp would still need a prefix route
1224 struct inet6_dev *idev = ifp->idev; in check_cleanup_prefix_route()
1230 list_for_each_entry(ifa, &idev->addr_list, if_list) { in check_cleanup_prefix_route()
1233 if (ifa->prefix_len != ifp->prefix_len || in check_cleanup_prefix_route()
1234 !ipv6_prefix_equal(&ifa->addr, &ifp->addr, in check_cleanup_prefix_route()
1235 ifp->prefix_len)) in check_cleanup_prefix_route()
1237 if (ifa->flags & (IFA_F_PERMANENT | IFA_F_NOPREFIXROUTE)) in check_cleanup_prefix_route()
1242 spin_lock(&ifa->lock); in check_cleanup_prefix_route()
1244 lifetime = addrconf_timeout_fixup(ifa->valid_lft, HZ); in check_cleanup_prefix_route()
1250 if (time_before(*expires, ifa->tstamp + lifetime * HZ)) in check_cleanup_prefix_route()
1251 *expires = ifa->tstamp + lifetime * HZ; in check_cleanup_prefix_route()
1252 spin_unlock(&ifa->lock); in check_cleanup_prefix_route()
1265 f6i = addrconf_get_prefix_route(del_peer ? &ifp->peer_addr : &ifp->addr, in cleanup_prefix_route()
1266 ifp->prefix_len, in cleanup_prefix_route()
1267 ifp->idev->dev, 0, RTF_DEFAULT, true); in cleanup_prefix_route()
1270 ip6_del_rt(dev_net(ifp->idev->dev), f6i, false); in cleanup_prefix_route()
1272 if (!(f6i->fib6_flags & RTF_EXPIRES)) { in cleanup_prefix_route()
1273 table = f6i->fib6_table; in cleanup_prefix_route()
1274 spin_lock_bh(&table->tb6_lock); in cleanup_prefix_route()
1279 spin_unlock_bh(&table->tb6_lock); in cleanup_prefix_route()
1292 struct net *net = dev_net(ifp->idev->dev); in ipv6_del_addr()
1298 spin_lock_bh(&ifp->lock); in ipv6_del_addr()
1299 state = ifp->state; in ipv6_del_addr()
1300 ifp->state = INET6_IFADDR_STATE_DEAD; in ipv6_del_addr()
1301 spin_unlock_bh(&ifp->lock); in ipv6_del_addr()
1306 spin_lock_bh(&net->ipv6.addrconf_hash_lock); in ipv6_del_addr()
1307 hlist_del_init_rcu(&ifp->addr_lst); in ipv6_del_addr()
1308 spin_unlock_bh(&net->ipv6.addrconf_hash_lock); in ipv6_del_addr()
1310 write_lock_bh(&ifp->idev->lock); in ipv6_del_addr()
1312 if (ifp->flags&IFA_F_TEMPORARY) { in ipv6_del_addr()
1313 list_del(&ifp->tmp_list); in ipv6_del_addr()
1314 if (ifp->ifpub) { in ipv6_del_addr()
1315 in6_ifa_put(ifp->ifpub); in ipv6_del_addr()
1316 ifp->ifpub = NULL; in ipv6_del_addr()
1321 if (ifp->flags & IFA_F_PERMANENT && !(ifp->flags & IFA_F_NOPREFIXROUTE)) in ipv6_del_addr()
1324 list_del_rcu(&ifp->if_list); in ipv6_del_addr()
1327 write_unlock_bh(&ifp->idev->lock); in ipv6_del_addr()
1348 return READ_ONCE(idev->cnf.regen_min_advance) + in ipv6_get_regen_advance()
1349 READ_ONCE(idev->cnf.regen_max_retry) * in ipv6_get_regen_advance()
1350 READ_ONCE(idev->cnf.dad_transmits) * in ipv6_get_regen_advance()
1351 max(NEIGH_VAR(idev->nd_parms, RETRANS_TIME), HZ/100) / HZ; in ipv6_get_regen_advance()
1356 struct inet6_dev *idev = ifp->idev; in ipv6_create_tempaddr()
1368 write_lock_bh(&idev->lock); in ipv6_create_tempaddr()
1372 if (READ_ONCE(idev->cnf.use_tempaddr) <= 0) { in ipv6_create_tempaddr()
1373 write_unlock_bh(&idev->lock); in ipv6_create_tempaddr()
1376 ret = -1; in ipv6_create_tempaddr()
1379 spin_lock_bh(&ifp->lock); in ipv6_create_tempaddr()
1380 if (ifp->regen_count++ >= READ_ONCE(idev->cnf.regen_max_retry)) { in ipv6_create_tempaddr()
1381 WRITE_ONCE(idev->cnf.use_tempaddr, -1); /*XXX*/ in ipv6_create_tempaddr()
1382 spin_unlock_bh(&ifp->lock); in ipv6_create_tempaddr()
1383 write_unlock_bh(&idev->lock); in ipv6_create_tempaddr()
1384 pr_warn("%s: regeneration time exceeded - disabled temporary address support\n", in ipv6_create_tempaddr()
1387 ret = -1; in ipv6_create_tempaddr()
1391 memcpy(addr.s6_addr, ifp->addr.s6_addr, 8); in ipv6_create_tempaddr()
1394 age = (now - ifp->tstamp) / HZ; in ipv6_create_tempaddr()
1399 * idev->desync_factor if it's larger in ipv6_create_tempaddr()
1401 cnf_temp_preferred_lft = READ_ONCE(idev->cnf.temp_prefered_lft); in ipv6_create_tempaddr()
1403 READ_ONCE(idev->cnf.max_desync_factor), in ipv6_create_tempaddr()
1404 cnf_temp_preferred_lft - regen_advance); in ipv6_create_tempaddr()
1406 if (unlikely(idev->desync_factor > max_desync_factor)) { in ipv6_create_tempaddr()
1408 get_random_bytes(&idev->desync_factor, in ipv6_create_tempaddr()
1409 sizeof(idev->desync_factor)); in ipv6_create_tempaddr()
1410 idev->desync_factor %= max_desync_factor; in ipv6_create_tempaddr()
1412 idev->desync_factor = 0; in ipv6_create_tempaddr()
1416 if_public_preferred_lft = ifp->prefered_lft; in ipv6_create_tempaddr()
1419 cfg.valid_lft = min_t(__u32, ifp->valid_lft, in ipv6_create_tempaddr()
1420 READ_ONCE(idev->cnf.temp_valid_lft) + age); in ipv6_create_tempaddr()
1421 cfg.preferred_lft = cnf_temp_preferred_lft + age - idev->desync_factor; in ipv6_create_tempaddr()
1425 cfg.plen = ifp->prefix_len; in ipv6_create_tempaddr()
1426 tmp_tstamp = ifp->tstamp; in ipv6_create_tempaddr()
1427 spin_unlock_bh(&ifp->lock); in ipv6_create_tempaddr()
1429 write_unlock_bh(&idev->lock); in ipv6_create_tempaddr()
1446 * of the public address or TEMP_PREFERRED_LIFETIME - in ipv6_create_tempaddr()
1451 * ifp->prefered_lft. in ipv6_create_tempaddr()
1456 age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; in ipv6_create_tempaddr()
1463 ret = -1; in ipv6_create_tempaddr()
1470 if (ifp->flags & IFA_F_OPTIMISTIC) in ipv6_create_tempaddr()
1481 write_lock_bh(&idev->lock); in ipv6_create_tempaddr()
1485 spin_lock_bh(&ift->lock); in ipv6_create_tempaddr()
1486 ift->ifpub = ifp; in ipv6_create_tempaddr()
1487 ift->cstamp = now; in ipv6_create_tempaddr()
1488 ift->tstamp = tmp_tstamp; in ipv6_create_tempaddr()
1489 spin_unlock_bh(&ift->lock); in ipv6_create_tempaddr()
1550 if (!READ_ONCE(net->ipv6.devconf_all->optimistic_dad) && in ipv6_use_optimistic_addr()
1551 !READ_ONCE(idev->cnf.optimistic_dad)) in ipv6_use_optimistic_addr()
1553 if (!READ_ONCE(net->ipv6.devconf_all->use_optimistic) && in ipv6_use_optimistic_addr()
1554 !READ_ONCE(idev->cnf.use_optimistic)) in ipv6_use_optimistic_addr()
1569 if (!READ_ONCE(net->ipv6.devconf_all->optimistic_dad) && in ipv6_allow_optimistic_dad()
1570 !READ_ONCE(idev->cnf.optimistic_dad)) in ipv6_allow_optimistic_dad()
1586 if (i <= score->rule) { in ipv6_get_saddr_eval()
1589 ret = score->scopedist; in ipv6_get_saddr_eval()
1592 ret = score->matchlen; in ipv6_get_saddr_eval()
1595 ret = !!test_bit(i, score->scorebits); in ipv6_get_saddr_eval()
1603 ret = !!score->ifa; in ipv6_get_saddr_eval()
1607 ret = ipv6_addr_equal(&score->ifa->addr, dst->addr); in ipv6_get_saddr_eval()
1614 * -1 | d 15 in ipv6_get_saddr_eval()
1615 * ---+--+-+---> scope in ipv6_get_saddr_eval()
1618 * B-d | \ in ipv6_get_saddr_eval()
1619 * | \ <- smaller scope is better if in ipv6_get_saddr_eval()
1620 * B-15 | \ if scope is enough for destination. in ipv6_get_saddr_eval()
1621 * | ret = B - scope (-1 <= scope >= d <= 15). in ipv6_get_saddr_eval()
1622 * d-C-1 | / in ipv6_get_saddr_eval()
1623 * |/ <- greater is better in ipv6_get_saddr_eval()
1624 * -C / if scope is not enough for destination. in ipv6_get_saddr_eval()
1625 * /| ret = scope - C (-1 <= d < scope <= 15). in ipv6_get_saddr_eval()
1627 * d - C - 1 < B -15 (for all -1 <= d <= 15). in ipv6_get_saddr_eval()
1628 * C > d + 14 - B >= 15 + 14 - B = 29 - B. in ipv6_get_saddr_eval()
1631 ret = __ipv6_addr_src_scope(score->addr_type); in ipv6_get_saddr_eval()
1632 if (ret >= dst->scope) in ipv6_get_saddr_eval()
1633 ret = -ret; in ipv6_get_saddr_eval()
1635 ret -= 128; /* 30 is enough */ in ipv6_get_saddr_eval()
1636 score->scopedist = ret; in ipv6_get_saddr_eval()
1643 if (!ipv6_use_optimistic_addr(net, score->ifa->idev)) in ipv6_get_saddr_eval()
1645 ret = ipv6_saddr_preferred(score->addr_type) || in ipv6_get_saddr_eval()
1646 !(score->ifa->flags & avoid); in ipv6_get_saddr_eval()
1653 int prefhome = !(dst->prefs & IPV6_PREFER_SRC_COA); in ipv6_get_saddr_eval()
1654 ret = !(score->ifa->flags & IFA_F_HOMEADDRESS) ^ prefhome; in ipv6_get_saddr_eval()
1660 ret = (!dst->ifindex || in ipv6_get_saddr_eval()
1661 dst->ifindex == score->ifa->idev->dev->ifindex); in ipv6_get_saddr_eval()
1666 &score->ifa->addr, score->addr_type, in ipv6_get_saddr_eval()
1667 score->ifa->idev->dev->ifindex) == dst->label; in ipv6_get_saddr_eval()
1674 int preftmp = dst->prefs & (IPV6_PREFER_SRC_PUBLIC|IPV6_PREFER_SRC_TMP) ? in ipv6_get_saddr_eval()
1675 !!(dst->prefs & IPV6_PREFER_SRC_TMP) : in ipv6_get_saddr_eval()
1676 READ_ONCE(score->ifa->idev->cnf.use_tempaddr) >= 2; in ipv6_get_saddr_eval()
1677 ret = (!(score->ifa->flags & IFA_F_TEMPORARY)) ^ preftmp; in ipv6_get_saddr_eval()
1681 /* Rule 8-: Prefer ORCHID vs ORCHID or in ipv6_get_saddr_eval()
1682 * non-ORCHID vs non-ORCHID in ipv6_get_saddr_eval()
1684 ret = !(ipv6_addr_orchid(&score->ifa->addr) ^ in ipv6_get_saddr_eval()
1685 ipv6_addr_orchid(dst->addr)); in ipv6_get_saddr_eval()
1689 ret = ipv6_addr_diff(&score->ifa->addr, dst->addr); in ipv6_get_saddr_eval()
1690 if (ret > score->ifa->prefix_len) in ipv6_get_saddr_eval()
1691 ret = score->ifa->prefix_len; in ipv6_get_saddr_eval()
1692 score->matchlen = ret; in ipv6_get_saddr_eval()
1699 ret = !(score->ifa->flags & IFA_F_OPTIMISTIC); in ipv6_get_saddr_eval()
1707 __set_bit(i, score->scorebits); in ipv6_get_saddr_eval()
1708 score->rule = i; in ipv6_get_saddr_eval()
1719 struct ipv6_saddr_score *score = &scores[1 - hiscore_idx], *hiscore = &scores[hiscore_idx]; in __ipv6_dev_get_saddr()
1721 list_for_each_entry_rcu(score->ifa, &idev->addr_list, if_list) { in __ipv6_dev_get_saddr()
1725 * - Tentative Address (RFC2462 section 5.4) in __ipv6_dev_get_saddr()
1726 * - A tentative address is not considered in __ipv6_dev_get_saddr()
1729 * - Candidate Source Address (section 4) in __ipv6_dev_get_saddr()
1730 * - In any case, anycast addresses, multicast in __ipv6_dev_get_saddr()
1734 if ((score->ifa->flags & IFA_F_TENTATIVE) && in __ipv6_dev_get_saddr()
1735 (!(score->ifa->flags & IFA_F_OPTIMISTIC))) in __ipv6_dev_get_saddr()
1738 score->addr_type = __ipv6_addr_type(&score->ifa->addr); in __ipv6_dev_get_saddr()
1740 if (unlikely(score->addr_type == IPV6_ADDR_ANY || in __ipv6_dev_get_saddr()
1741 score->addr_type & IPV6_ADDR_MULTICAST)) { in __ipv6_dev_get_saddr()
1743 idev->dev->name); in __ipv6_dev_get_saddr()
1747 score->rule = -1; in __ipv6_dev_get_saddr()
1748 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX); in __ipv6_dev_get_saddr()
1758 score->scopedist > 0) { in __ipv6_dev_get_saddr()
1772 hiscore_idx = 1 - hiscore_idx; in __ipv6_dev_get_saddr()
1775 score->ifa = hiscore->ifa; in __ipv6_dev_get_saddr()
1822 dst.ifindex = dst_dev ? dst_dev->ifindex : 0; in ipv6_dev_get_saddr()
1827 scores[hiscore_idx].rule = -1; in ipv6_dev_get_saddr()
1833 * - multicast and link-local destination address, in ipv6_dev_get_saddr()
1838 * (- For site-local destination addresses, the in ipv6_dev_get_saddr()
1843 * - "It is RECOMMENDED that the candidate source addresses in ipv6_dev_get_saddr()
1852 (idev && READ_ONCE(idev->cnf.use_oif_addrs_only))) { in ipv6_dev_get_saddr()
1870 master_idx = master->ifindex; in ipv6_dev_get_saddr()
1896 if (!hiscore->ifa) in ipv6_dev_get_saddr()
1897 ret = -EADDRNOTAVAIL; in ipv6_dev_get_saddr()
1899 *saddr = hiscore->ifa->addr; in ipv6_dev_get_saddr()
1910 int err = -EADDRNOTAVAIL; in __ipv6_get_lladdr()
1912 list_for_each_entry_reverse(ifp, &idev->addr_list, if_list) { in __ipv6_get_lladdr()
1913 if (ifp->scope > IFA_LINK) in __ipv6_get_lladdr()
1915 if (ifp->scope == IFA_LINK && in __ipv6_get_lladdr()
1916 !(ifp->flags & banned_flags)) { in __ipv6_get_lladdr()
1917 *addr = ifp->addr; in __ipv6_get_lladdr()
1929 int err = -EADDRNOTAVAIL; in ipv6_get_lladdr()
1934 read_lock_bh(&idev->lock); in ipv6_get_lladdr()
1936 read_unlock_bh(&idev->lock); in ipv6_get_lladdr()
1948 list_for_each_entry_rcu(ifp, &idev->addr_list, if_list) in ipv6_count_addresses()
1987 hlist_for_each_entry_rcu(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) { in __ipv6_chk_addr_and_flags()
1988 ndev = ifp->idev->dev; in __ipv6_chk_addr_and_flags()
1996 ifp_flags = (ifp->flags&IFA_F_OPTIMISTIC) in __ipv6_chk_addr_and_flags()
1997 ? (ifp->flags&~IFA_F_TENTATIVE) in __ipv6_chk_addr_and_flags()
1998 : ifp->flags; in __ipv6_chk_addr_and_flags()
1999 if (ipv6_addr_equal(&ifp->addr, addr) && in __ipv6_chk_addr_and_flags()
2002 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) { in __ipv6_chk_addr_and_flags()
2035 list_for_each_entry_rcu(ifa, &idev->addr_list, if_list) { in ipv6_chk_custom_prefix()
2036 ret = ipv6_prefix_equal(addr, &ifa->addr, prefix_len); in ipv6_chk_custom_prefix()
2057 list_for_each_entry_rcu(ifa, &idev->addr_list, if_list) { in ipv6_chk_prefix()
2058 onlink = ipv6_prefix_equal(addr, &ifa->addr, in ipv6_chk_prefix()
2059 ifa->prefix_len); in ipv6_chk_prefix()
2070 * ipv6_dev_find - find the first device with a given source address.
2092 hlist_for_each_entry_rcu(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) { in ipv6_get_ifaddr()
2093 if (ipv6_addr_equal(&ifp->addr, addr)) { in ipv6_get_ifaddr()
2094 if (!dev || ifp->idev->dev == dev || in ipv6_get_ifaddr()
2095 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) { in ipv6_get_ifaddr()
2113 ifp->flags |= IFA_F_DADFAILED; in addrconf_dad_stop()
2115 if (ifp->flags&IFA_F_TEMPORARY) { in addrconf_dad_stop()
2117 spin_lock_bh(&ifp->lock); in addrconf_dad_stop()
2118 ifpub = ifp->ifpub; in addrconf_dad_stop()
2121 spin_unlock_bh(&ifp->lock); in addrconf_dad_stop()
2125 spin_unlock_bh(&ifp->lock); in addrconf_dad_stop()
2128 } else if (ifp->flags&IFA_F_PERMANENT || !dad_failed) { in addrconf_dad_stop()
2129 spin_lock_bh(&ifp->lock); in addrconf_dad_stop()
2131 ifp->flags |= IFA_F_TENTATIVE; in addrconf_dad_stop()
2133 ifp->flags &= ~IFA_F_OPTIMISTIC; in addrconf_dad_stop()
2134 spin_unlock_bh(&ifp->lock); in addrconf_dad_stop()
2145 int err = -ENOENT; in addrconf_dad_end()
2147 spin_lock_bh(&ifp->lock); in addrconf_dad_end()
2148 if (ifp->state == INET6_IFADDR_STATE_DAD) { in addrconf_dad_end()
2149 ifp->state = INET6_IFADDR_STATE_POSTDAD; in addrconf_dad_end()
2152 spin_unlock_bh(&ifp->lock); in addrconf_dad_end()
2159 struct inet6_dev *idev = ifp->idev; in addrconf_dad_failure()
2160 struct net *net = dev_net(idev->dev); in addrconf_dad_failure()
2169 ifp->idev->dev->name, &ifp->addr, eth_hdr(skb)->h_source); in addrconf_dad_failure()
2171 spin_lock_bh(&ifp->lock); in addrconf_dad_failure()
2173 if (ifp->flags & IFA_F_STABLE_PRIVACY) { in addrconf_dad_failure()
2176 int retries = ifp->stable_privacy_retry + 1; in addrconf_dad_failure()
2179 .plen = ifp->prefix_len, in addrconf_dad_failure()
2180 .ifa_flags = ifp->flags, in addrconf_dad_failure()
2181 .valid_lft = ifp->valid_lft, in addrconf_dad_failure()
2182 .preferred_lft = ifp->prefered_lft, in addrconf_dad_failure()
2183 .scope = ifp->scope, in addrconf_dad_failure()
2186 if (retries > net->ipv6.sysctl.idgen_retries) { in addrconf_dad_failure()
2188 ifp->idev->dev->name); in addrconf_dad_failure()
2192 new_addr = ifp->addr; in addrconf_dad_failure()
2197 spin_unlock_bh(&ifp->lock); in addrconf_dad_failure()
2199 max_addresses = READ_ONCE(idev->cnf.max_addresses); in addrconf_dad_failure()
2205 ifp->idev->dev->name); in addrconf_dad_failure()
2211 spin_lock_bh(&ifp2->lock); in addrconf_dad_failure()
2212 ifp2->stable_privacy_retry = retries; in addrconf_dad_failure()
2213 ifp2->state = INET6_IFADDR_STATE_PREDAD; in addrconf_dad_failure()
2214 spin_unlock_bh(&ifp2->lock); in addrconf_dad_failure()
2216 addrconf_mod_dad_work(ifp2, net->ipv6.sysctl.idgen_delay); in addrconf_dad_failure()
2219 spin_lock_bh(&ifp->lock); in addrconf_dad_failure()
2224 ifp->state = INET6_IFADDR_STATE_ERRDAD; in addrconf_dad_failure()
2225 spin_unlock_bh(&ifp->lock); in addrconf_dad_failure()
2237 if (dev->flags&(IFF_LOOPBACK|IFF_NOARP)) in addrconf_join_solict()
2249 if (idev->dev->flags&(IFF_LOOPBACK|IFF_NOARP)) in addrconf_leave_solict()
2261 if (ifp->prefix_len >= 127) /* RFC 6164 */ in addrconf_join_anycast()
2263 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len); in addrconf_join_anycast()
2266 __ipv6_dev_ac_inc(ifp->idev, &addr); in addrconf_join_anycast()
2274 if (ifp->prefix_len >= 127) /* RFC 6164 */ in addrconf_leave_anycast()
2276 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len); in addrconf_leave_anycast()
2279 __ipv6_dev_ac_dec(ifp->idev, &addr); in addrconf_leave_anycast()
2284 switch (dev->addr_len) { in addrconf_ifid_6lowpan()
2286 memcpy(eui, dev->dev_addr, 3); in addrconf_ifid_6lowpan()
2289 memcpy(eui + 5, dev->dev_addr + 3, 3); in addrconf_ifid_6lowpan()
2292 memcpy(eui, dev->dev_addr, EUI64_ADDR_LEN); in addrconf_ifid_6lowpan()
2296 return -1; in addrconf_ifid_6lowpan()
2306 if (dev->addr_len != FWNET_ALEN) in addrconf_ifid_ieee1394()
2307 return -1; in addrconf_ifid_ieee1394()
2309 ha = (const union fwnet_hwaddr *)dev->dev_addr; in addrconf_ifid_ieee1394()
2311 memcpy(eui, &ha->uc.uniq_id, sizeof(ha->uc.uniq_id)); in addrconf_ifid_ieee1394()
2318 /* XXX: inherit EUI-64 from other interface -- yoshfuji */ in addrconf_ifid_arcnet()
2319 if (dev->addr_len != ARCNET_ALEN) in addrconf_ifid_arcnet()
2320 return -1; in addrconf_ifid_arcnet()
2322 eui[7] = *(u8 *)dev->dev_addr; in addrconf_ifid_arcnet()
2328 if (dev->addr_len != INFINIBAND_ALEN) in addrconf_ifid_infiniband()
2329 return -1; in addrconf_ifid_infiniband()
2330 memcpy(eui, dev->dev_addr + 12, 8); in addrconf_ifid_infiniband()
2338 return -1; in __ipv6_isatap_ifid()
2354 if (dev->priv_flags & IFF_ISATAP) in addrconf_ifid_sit()
2355 return __ipv6_isatap_ifid(eui, *(__be32 *)dev->dev_addr); in addrconf_ifid_sit()
2356 return -1; in addrconf_ifid_sit()
2361 return __ipv6_isatap_ifid(eui, *(__be32 *)dev->dev_addr); in addrconf_ifid_gre()
2366 memcpy(eui, dev->perm_addr, 3); in addrconf_ifid_ip6tnl()
2367 memcpy(eui + 5, dev->perm_addr + 3, 3); in addrconf_ifid_ip6tnl()
2376 switch (dev->type) { in ipv6_generate_eui64()
2398 return -1; in ipv6_generate_eui64()
2403 int err = -1; in ipv6_inherit_eui64()
2406 read_lock_bh(&idev->lock); in ipv6_inherit_eui64()
2407 list_for_each_entry_reverse(ifp, &idev->addr_list, if_list) { in ipv6_inherit_eui64()
2408 if (ifp->scope > IFA_LINK) in ipv6_inherit_eui64()
2410 if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) { in ipv6_inherit_eui64()
2411 memcpy(eui, ifp->addr.s6_addr+8, 8); in ipv6_inherit_eui64()
2416 read_unlock_bh(&idev->lock); in ipv6_inherit_eui64()
2421 * draft-ietf-6man-rfc4941bis, Section 3.3.1
2427 get_random_bytes(&addr->s6_addr[8], 8); in ipv6_gen_rnd_iid()
2429 /* <draft-ietf-6man-rfc4941bis-08.txt>, Section 3.3.1: in ipv6_gen_rnd_iid()
2432 * - Reserved IPv6 Interface Identifiers in ipv6_gen_rnd_iid()
2433 * - XXX: already assigned to an address on the device in ipv6_gen_rnd_iid()
2436 /* Subnet-router anycast: 0000:0000:0000:0000 */ in ipv6_gen_rnd_iid()
2437 if (!(addr->s6_addr32[2] | addr->s6_addr32[3])) in ipv6_gen_rnd_iid()
2440 /* IANA Ethernet block: 0200:5EFF:FE00:0000-0200:5EFF:FE00:5212 in ipv6_gen_rnd_iid()
2442 * IANA Ethernet block: 0200:5EFF:FE00:5214-0200:5EFF:FEFF:FFFF in ipv6_gen_rnd_iid()
2444 if (ntohl(addr->s6_addr32[2]) == 0x02005eff && in ipv6_gen_rnd_iid()
2445 (ntohl(addr->s6_addr32[3]) & 0Xff000000) == 0xfe000000) in ipv6_gen_rnd_iid()
2449 if (ntohl(addr->s6_addr32[2]) == 0xfdffffff && in ipv6_gen_rnd_iid()
2450 ntohl(addr->s6_addr32[3]) >= 0Xffffff80) in ipv6_gen_rnd_iid()
2455 * Add prefix route.
2466 .fc_ifindex = dev->ifindex, in addrconf_prefix_route()
2477 /* Prevent useless cloning on PtP SIT. in addrconf_prefix_route()
2479 class of non-broadcast devices need not cloning. in addrconf_prefix_route()
2482 if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT)) in addrconf_prefix_route()
2506 fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0, true); in addrconf_get_prefix_route()
2512 if (rt->nh) in addrconf_get_prefix_route()
2515 if (rt->fib6_nh->fib_nh_dev->ifindex != dev->ifindex) in addrconf_get_prefix_route()
2517 if (no_gw && rt->fib6_nh->fib_nh_gw_family) in addrconf_get_prefix_route()
2519 if ((rt->fib6_flags & flags) != flags) in addrconf_get_prefix_route()
2521 if ((rt->fib6_flags & noflags) != 0) in addrconf_get_prefix_route()
2533 /* Create "default" multicast route to the interface */
2540 .fc_ifindex = dev->ifindex, in addrconf_add_mroute()
2563 if (idev->cnf.disable_ipv6) in addrconf_add_dev()
2564 return ERR_PTR(-EACCES); in addrconf_add_dev()
2566 /* Add default multicast route */ in addrconf_add_dev()
2567 if (!(dev->flags & IFF_LOOPBACK) && !netif_is_l3_master(dev)) in addrconf_add_dev()
2581 read_lock_bh(&idev->lock); in manage_tempaddrs()
2583 list_for_each_entry(ift, &idev->tempaddr_list, tmp_list) { in manage_tempaddrs()
2586 if (ifp != ift->ifpub) in manage_tempaddrs()
2595 * (TEMP_PREFERRED_LIFETIME - DESYNC_FACTOR), respectively. in manage_tempaddrs()
2597 age = (now - ift->cstamp) / HZ; in manage_tempaddrs()
2598 max_valid = READ_ONCE(idev->cnf.temp_valid_lft) - age; in manage_tempaddrs()
2602 max_prefered = READ_ONCE(idev->cnf.temp_prefered_lft) - in manage_tempaddrs()
2603 idev->desync_factor - age; in manage_tempaddrs()
2613 spin_lock(&ift->lock); in manage_tempaddrs()
2614 flags = ift->flags; in manage_tempaddrs()
2615 ift->valid_lft = valid_lft; in manage_tempaddrs()
2616 ift->prefered_lft = prefered_lft; in manage_tempaddrs()
2617 ift->tstamp = now; in manage_tempaddrs()
2619 ift->flags &= ~IFA_F_DEPRECATED; in manage_tempaddrs()
2621 spin_unlock(&ift->lock); in manage_tempaddrs()
2632 if (list_empty(&idev->tempaddr_list) && (valid_lft || prefered_lft)) in manage_tempaddrs()
2635 if (create && READ_ONCE(idev->cnf.use_tempaddr) > 0) { in manage_tempaddrs()
2639 read_unlock_bh(&idev->lock); in manage_tempaddrs()
2642 read_unlock_bh(&idev->lock); in manage_tempaddrs()
2648 return idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_STABLE_PRIVACY || in is_addr_mode_generate_stable()
2649 idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_RANDOM; in is_addr_mode_generate_stable()
2663 int max_addresses = READ_ONCE(in6_dev->cnf.max_addresses); in addrconf_prefix_rcv_add_addr()
2666 .plen = pinfo->prefix_len, in addrconf_prefix_rcv_add_addr()
2675 if ((READ_ONCE(net->ipv6.devconf_all->optimistic_dad) || in addrconf_prefix_rcv_add_addr()
2676 READ_ONCE(in6_dev->cnf.optimistic_dad)) && in addrconf_prefix_rcv_add_addr()
2677 !net->ipv6.devconf_all->forwarding && sllao) in addrconf_prefix_rcv_add_addr()
2689 return -1; in addrconf_prefix_rcv_add_addr()
2692 spin_lock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2693 ifp->flags |= IFA_F_MANAGETEMPADDR; in addrconf_prefix_rcv_add_addr()
2694 ifp->cstamp = jiffies; in addrconf_prefix_rcv_add_addr()
2695 ifp->tokenized = tokenized; in addrconf_prefix_rcv_add_addr()
2696 spin_unlock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2706 spin_lock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2708 if (ifp->valid_lft > (now - ifp->tstamp) / HZ) in addrconf_prefix_rcv_add_addr()
2709 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ; in addrconf_prefix_rcv_add_addr()
2725 if (update_lft && !READ_ONCE(in6_dev->cnf.ra_honor_pio_life)) { in addrconf_prefix_rcv_add_addr()
2732 ifp->valid_lft = valid_lft; in addrconf_prefix_rcv_add_addr()
2733 ifp->prefered_lft = prefered_lft; in addrconf_prefix_rcv_add_addr()
2734 WRITE_ONCE(ifp->tstamp, now); in addrconf_prefix_rcv_add_addr()
2735 flags = ifp->flags; in addrconf_prefix_rcv_add_addr()
2736 ifp->flags &= ~IFA_F_DEPRECATED; in addrconf_prefix_rcv_add_addr()
2737 spin_unlock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2742 spin_unlock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2778 addr_type = ipv6_addr_type(&pinfo->prefix); in addrconf_prefix_rcv()
2783 valid_lft = ntohl(pinfo->valid); in addrconf_prefix_rcv()
2784 prefered_lft = ntohl(pinfo->prefered); in addrconf_prefix_rcv()
2795 dev->name); in addrconf_prefix_rcv()
2799 if (valid_lft != 0 && valid_lft < in6_dev->cnf.accept_ra_min_lft) in addrconf_prefix_rcv()
2804 * 1) Add routes for on-link prefixes in addrconf_prefix_rcv()
2808 if (pinfo->onlink) { in addrconf_prefix_rcv()
2825 rt = addrconf_get_prefix_route(&pinfo->prefix, in addrconf_prefix_rcv()
2826 pinfo->prefix_len, in addrconf_prefix_rcv()
2832 /* Autoconf prefix route */ in addrconf_prefix_rcv()
2837 table = rt->fib6_table; in addrconf_prefix_rcv()
2838 spin_lock_bh(&table->tb6_lock); in addrconf_prefix_rcv()
2849 spin_unlock_bh(&table->tb6_lock); in addrconf_prefix_rcv()
2859 addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, in addrconf_prefix_rcv()
2868 ignore_autoconf = READ_ONCE(in6_dev->cnf.ra_honor_pio_pflag) && pinfo->preferpd; in addrconf_prefix_rcv()
2869 if (pinfo->autoconf && in6_dev->cnf.autoconf && !ignore_autoconf) { in addrconf_prefix_rcv()
2873 if (pinfo->prefix_len == 64) { in addrconf_prefix_rcv()
2874 memcpy(&addr, &pinfo->prefix, 8); in addrconf_prefix_rcv()
2876 if (!ipv6_addr_any(&in6_dev->token)) { in addrconf_prefix_rcv()
2877 read_lock_bh(&in6_dev->lock); in addrconf_prefix_rcv()
2879 in6_dev->token.s6_addr + 8, 8); in addrconf_prefix_rcv()
2880 read_unlock_bh(&in6_dev->lock); in addrconf_prefix_rcv()
2896 pinfo->prefix_len); in addrconf_prefix_rcv()
2928 if (!(ipv6_addr_type(&ireq->ifr6_addr) & IPV6_ADDR_COMPATv4)) in addrconf_set_sit_dstaddr()
2929 return -EADDRNOTAVAIL; in addrconf_set_sit_dstaddr()
2931 p.iph.daddr = ireq->ifr6_addr.s6_addr32[3]; in addrconf_set_sit_dstaddr()
2937 if (!dev->netdev_ops->ndo_tunnel_ctl) in addrconf_set_sit_dstaddr()
2938 return -EOPNOTSUPP; in addrconf_set_sit_dstaddr()
2939 err = dev->netdev_ops->ndo_tunnel_ctl(dev, &p, SIOCADDTUNNEL); in addrconf_set_sit_dstaddr()
2945 return -ENOBUFS; in addrconf_set_sit_dstaddr()
2958 int err = -ENODEV; in addrconf_set_dstaddr()
2961 return -ENODEV; in addrconf_set_dstaddr()
2963 return -EFAULT; in addrconf_set_dstaddr()
2967 if (dev && dev->type == ARPHRD_SIT) in addrconf_set_dstaddr()
3006 if (cfg->plen > 128) { in inet6_addr_add()
3008 return -EINVAL; in inet6_addr_add()
3012 if (!cfg->valid_lft || cfg->preferred_lft > cfg->valid_lft) { in inet6_addr_add()
3014 return -EINVAL; in inet6_addr_add()
3017 if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR && cfg->plen != 64) { in inet6_addr_add()
3019 return -EINVAL; in inet6_addr_add()
3024 return -ENODEV; in inet6_addr_add()
3032 if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) { in inet6_addr_add()
3033 int ret = ipv6_mc_config(net->ipv6.mc_autojoin_sk, in inet6_addr_add()
3034 true, cfg->pfx, ifindex); in inet6_addr_add()
3042 cfg->scope = ipv6_addr_scope(cfg->pfx); in inet6_addr_add()
3044 timeout = addrconf_timeout_fixup(cfg->valid_lft, HZ); in inet6_addr_add()
3047 cfg->valid_lft = timeout; in inet6_addr_add()
3052 cfg->ifa_flags |= IFA_F_PERMANENT; in inet6_addr_add()
3055 timeout = addrconf_timeout_fixup(cfg->preferred_lft, HZ); in inet6_addr_add()
3058 cfg->ifa_flags |= IFA_F_DEPRECATED; in inet6_addr_add()
3059 cfg->preferred_lft = timeout; in inet6_addr_add()
3064 if (!(cfg->ifa_flags & IFA_F_NOPREFIXROUTE)) { in inet6_addr_add()
3065 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, in inet6_addr_add()
3066 ifp->rt_priority, dev, expires, in inet6_addr_add()
3073 if (!(ifp->flags & (IFA_F_OPTIMISTIC | IFA_F_NODAD))) in inet6_addr_add()
3081 if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR) in inet6_addr_add()
3082 manage_tempaddrs(idev, ifp, cfg->valid_lft, in inet6_addr_add()
3083 cfg->preferred_lft, true, jiffies); in inet6_addr_add()
3087 } else if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) { in inet6_addr_add()
3088 ipv6_mc_config(net->ipv6.mc_autojoin_sk, false, in inet6_addr_add()
3089 cfg->pfx, ifindex); in inet6_addr_add()
3105 return -EINVAL; in inet6_addr_del()
3111 return -ENODEV; in inet6_addr_del()
3117 return -ENXIO; in inet6_addr_del()
3120 read_lock_bh(&idev->lock); in inet6_addr_del()
3121 list_for_each_entry(ifp, &idev->addr_list, if_list) { in inet6_addr_del()
3122 if (ifp->prefix_len == plen && in inet6_addr_del()
3123 ipv6_addr_equal(pfx, &ifp->addr)) { in inet6_addr_del()
3125 read_unlock_bh(&idev->lock); in inet6_addr_del()
3127 if (!(ifp->flags & IFA_F_TEMPORARY) && in inet6_addr_del()
3134 ipv6_mc_config(net->ipv6.mc_autojoin_sk, in inet6_addr_del()
3135 false, pfx, dev->ifindex); in inet6_addr_del()
3140 read_unlock_bh(&idev->lock); in inet6_addr_del()
3143 return -EADDRNOTAVAIL; in inet6_addr_del()
3157 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in addrconf_add_ifaddr()
3158 return -EPERM; in addrconf_add_ifaddr()
3161 return -EFAULT; in addrconf_add_ifaddr()
3177 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in addrconf_del_ifaddr()
3178 return -EPERM; in addrconf_del_ifaddr()
3181 return -EFAULT; in addrconf_del_ifaddr()
3206 spin_lock_bh(&ifp->lock); in add_addr()
3207 ifp->flags &= ~IFA_F_TENTATIVE; in add_addr()
3208 spin_unlock_bh(&ifp->lock); in add_addr()
3209 rt_genid_bump_ipv6(dev_net(idev->dev)); in add_addr()
3220 struct net *net = dev_net(idev->dev); in add_v4_addrs()
3228 if (idev->dev->addr_len == sizeof(struct in6_addr)) in add_v4_addrs()
3229 offset = sizeof(struct in6_addr) - 4; in add_v4_addrs()
3230 memcpy(&addr.s6_addr32[3], idev->dev->dev_addr + offset, 4); in add_v4_addrs()
3232 if (!(idev->dev->flags & IFF_POINTOPOINT) && idev->dev->type == ARPHRD_SIT) { in add_v4_addrs()
3237 if (idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_NONE) in add_v4_addrs()
3247 addrconf_prefix_route(&addr, plen, 0, idev->dev, 0, pflags, in add_v4_addrs()
3254 if (in_dev && (dev->flags & IFF_UP)) { in add_v4_addrs()
3259 addr.s6_addr32[3] = ifa->ifa_local; in add_v4_addrs()
3261 if (ifa->ifa_scope == RT_SCOPE_LINK) in add_v4_addrs()
3263 if (ifa->ifa_scope >= RT_SCOPE_HOST) { in add_v4_addrs()
3264 if (idev->dev->flags&IFF_POINTOPOINT) in add_v4_addrs()
3271 addrconf_prefix_route(&addr, plen, 0, idev->dev, in add_v4_addrs()
3311 if ((READ_ONCE(dev_net(idev->dev)->ipv6.devconf_all->optimistic_dad) || in addrconf_add_linklocal()
3312 READ_ONCE(idev->cnf.optimistic_dad)) && in addrconf_add_linklocal()
3313 !dev_net(idev->dev)->ipv6.devconf_all->forwarding) in addrconf_add_linklocal()
3319 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, 0, idev->dev, in addrconf_add_linklocal()
3363 struct net *net = dev_net(idev->dev); in ipv6_generate_stable_address()
3367 if (idev->cnf.stable_secret.initialized) in ipv6_generate_stable_address()
3368 secret = idev->cnf.stable_secret.secret; in ipv6_generate_stable_address()
3369 else if (net->ipv6.devconf_dflt->stable_secret.initialized) in ipv6_generate_stable_address()
3370 secret = net->ipv6.devconf_dflt->stable_secret.secret; in ipv6_generate_stable_address()
3372 return -1; in ipv6_generate_stable_address()
3380 memcpy(data.hwaddr, idev->dev->perm_addr, idev->dev->addr_len); in ipv6_generate_stable_address()
3381 data.prefix[0] = address->s6_addr32[0]; in ipv6_generate_stable_address()
3382 data.prefix[1] = address->s6_addr32[1]; in ipv6_generate_stable_address()
3396 if (dad_count > dev_net(idev->dev)->ipv6.sysctl.idgen_retries) in ipv6_generate_stable_address()
3397 return -1; in ipv6_generate_stable_address()
3407 struct ipv6_stable_secret *s = &idev->cnf.stable_secret; in ipv6_gen_mode_random_init()
3409 if (s->initialized) in ipv6_gen_mode_random_init()
3411 s = &idev->cnf.stable_secret; in ipv6_gen_mode_random_init()
3412 get_random_bytes(&s->secret, sizeof(s->secret)); in ipv6_gen_mode_random_init()
3413 s->initialized = true; in ipv6_gen_mode_random_init()
3421 if (netif_is_l3_master(idev->dev)) in addrconf_addr_gen()
3425 if (idev->dev->priv_flags & IFF_NO_ADDRCONF) in addrconf_addr_gen()
3430 switch (idev->cnf.addr_gen_mode) { in addrconf_addr_gen()
3439 addrconf_prefix_route(&addr, 64, 0, idev->dev, in addrconf_addr_gen()
3447 if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0) in addrconf_addr_gen()
3450 addrconf_prefix_route(&addr, 64, 0, idev->dev, in addrconf_addr_gen()
3466 if ((dev->type != ARPHRD_ETHER) && in addrconf_dev_config()
3467 (dev->type != ARPHRD_FDDI) && in addrconf_dev_config()
3468 (dev->type != ARPHRD_ARCNET) && in addrconf_dev_config()
3469 (dev->type != ARPHRD_INFINIBAND) && in addrconf_dev_config()
3470 (dev->type != ARPHRD_IEEE1394) && in addrconf_dev_config()
3471 (dev->type != ARPHRD_TUNNEL6) && in addrconf_dev_config()
3472 (dev->type != ARPHRD_6LOWPAN) && in addrconf_dev_config()
3473 (dev->type != ARPHRD_TUNNEL) && in addrconf_dev_config()
3474 (dev->type != ARPHRD_NONE) && in addrconf_dev_config()
3475 (dev->type != ARPHRD_RAWIP)) { in addrconf_dev_config()
3478 if (!IS_ERR_OR_NULL(idev) && dev->flags & IFF_UP && in addrconf_dev_config()
3479 dev->flags & IFF_MULTICAST) in addrconf_dev_config()
3489 if (dev->type == ARPHRD_NONE && in addrconf_dev_config()
3490 idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_EUI64) in addrconf_dev_config()
3491 WRITE_ONCE(idev->cnf.addr_gen_mode, in addrconf_dev_config()
3516 if (dev->priv_flags & IFF_ISATAP) { in addrconf_sit_config()
3523 if (dev->flags&IFF_POINTOPOINT) in addrconf_sit_config()
3541 if (dev->type == ARPHRD_ETHER) { in addrconf_gre_config()
3548 if (dev->flags & IFF_POINTOPOINT) in addrconf_gre_config()
3555 switch (dev->type) { in addrconf_init_auto_addrs()
3581 /* !fib6_node means the host route was removed from the in fixup_permanent_addr()
3583 * case regenerate the host route. in fixup_permanent_addr()
3585 if (!ifp->rt || !ifp->rt->fib6_node) { in fixup_permanent_addr()
3588 f6i = addrconf_f6i_alloc(net, idev, &ifp->addr, false, in fixup_permanent_addr()
3593 /* ifp->rt can be accessed outside of rtnl */ in fixup_permanent_addr()
3594 spin_lock(&ifp->lock); in fixup_permanent_addr()
3595 prev = ifp->rt; in fixup_permanent_addr()
3596 ifp->rt = f6i; in fixup_permanent_addr()
3597 spin_unlock(&ifp->lock); in fixup_permanent_addr()
3602 if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) { in fixup_permanent_addr()
3603 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, in fixup_permanent_addr()
3604 ifp->rt_priority, idev->dev, 0, 0, in fixup_permanent_addr()
3608 if (ifp->state == INET6_IFADDR_STATE_PREDAD) in fixup_permanent_addr()
3623 write_lock_bh(&idev->lock); in addrconf_permanent_addr()
3625 list_for_each_entry_safe(ifp, tmp, &idev->addr_list, if_list) { in addrconf_permanent_addr()
3626 if ((ifp->flags & IFA_F_PERMANENT) && in addrconf_permanent_addr()
3628 write_unlock_bh(&idev->lock); in addrconf_permanent_addr()
3631 write_lock_bh(&idev->lock); in addrconf_permanent_addr()
3633 net_info_ratelimited("%s: Failed to add prefix route for address %pI6c; dropping\n", in addrconf_permanent_addr()
3634 idev->dev->name, &ifp->addr); in addrconf_permanent_addr()
3638 write_unlock_bh(&idev->lock); in addrconf_permanent_addr()
3654 if (!idev && dev->mtu >= IPV6_MIN_MTU) { in addrconf_notify()
3663 if (dev->mtu < IPV6_MIN_MTU) { in addrconf_notify()
3664 addrconf_ifdown(dev, dev != net->loopback_dev); in addrconf_notify()
3669 rt6_mtu_change(dev, dev->mtu); in addrconf_notify()
3670 WRITE_ONCE(idev->cnf.mtu6, dev->mtu); in addrconf_notify()
3680 if (!(idev->if_flags & IF_READY)) in addrconf_notify()
3687 if (idev && idev->cnf.disable_ipv6) in addrconf_notify()
3690 if (dev->priv_flags & IFF_NO_ADDRCONF) { in addrconf_notify()
3692 dev->flags & IFF_UP && dev->flags & IFF_MULTICAST) in addrconf_notify()
3704 dev->name); in addrconf_notify()
3708 if (!idev && dev->mtu >= IPV6_MIN_MTU) in addrconf_notify()
3712 idev->if_flags |= IF_READY; in addrconf_notify()
3723 if (idev->if_flags & IF_READY) { in addrconf_notify()
3724 /* device is already configured - in addrconf_notify()
3731 if (change_info->flags_changed & IFF_NOARP) in addrconf_notify()
3736 idev->if_flags |= IF_READY; in addrconf_notify()
3740 dev->name); in addrconf_notify()
3759 if (idev->cnf.mtu6 != dev->mtu && in addrconf_notify()
3760 dev->mtu >= IPV6_MIN_MTU) { in addrconf_notify()
3761 rt6_mtu_change(dev, dev->mtu); in addrconf_notify()
3762 WRITE_ONCE(idev->cnf.mtu6, dev->mtu); in addrconf_notify()
3764 WRITE_ONCE(idev->tstamp, jiffies); in addrconf_notify()
3771 if (dev->mtu < IPV6_MIN_MTU) in addrconf_notify()
3772 addrconf_ifdown(dev, dev != net->loopback_dev); in addrconf_notify()
3811 if (info->upper_dev && netif_is_l3_master(info->upper_dev)) in addrconf_notify()
3862 return -ENODEV; in addrconf_ifdown()
3869 idev->dead = 1; in addrconf_ifdown()
3872 RCU_INIT_POINTER(dev->ip6_ptr, NULL); in addrconf_ifdown()
3882 if (!unregister && !idev->cnf.disable_ipv6) { in addrconf_ifdown()
3884 int _keep_addr = READ_ONCE(net->ipv6.devconf_all->keep_addr_on_down); in addrconf_ifdown()
3887 _keep_addr = READ_ONCE(idev->cnf.keep_addr_on_down); in addrconf_ifdown()
3894 struct hlist_head *h = &net->ipv6.inet6_addr_lst[i]; in addrconf_ifdown()
3896 spin_lock_bh(&net->ipv6.addrconf_hash_lock); in addrconf_ifdown()
3899 if (ifa->idev == idev) { in addrconf_ifdown()
3905 !(ifa->flags & IFA_F_PERMANENT) || in addrconf_ifdown()
3906 addr_is_local(&ifa->addr)) { in addrconf_ifdown()
3907 hlist_del_init_rcu(&ifa->addr_lst); in addrconf_ifdown()
3912 spin_unlock_bh(&net->ipv6.addrconf_hash_lock); in addrconf_ifdown()
3915 write_lock_bh(&idev->lock); in addrconf_ifdown()
3922 was_ready = idev->if_flags & IF_READY; in addrconf_ifdown()
3924 idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); in addrconf_ifdown()
3927 while (!list_empty(&idev->tempaddr_list)) { in addrconf_ifdown()
3928 ifa = list_first_entry(&idev->tempaddr_list, in addrconf_ifdown()
3930 list_del(&ifa->tmp_list); in addrconf_ifdown()
3931 write_unlock_bh(&idev->lock); in addrconf_ifdown()
3932 spin_lock_bh(&ifa->lock); in addrconf_ifdown()
3934 if (ifa->ifpub) { in addrconf_ifdown()
3935 in6_ifa_put(ifa->ifpub); in addrconf_ifdown()
3936 ifa->ifpub = NULL; in addrconf_ifdown()
3938 spin_unlock_bh(&ifa->lock); in addrconf_ifdown()
3940 write_lock_bh(&idev->lock); in addrconf_ifdown()
3943 list_for_each_entry(ifa, &idev->addr_list, if_list) in addrconf_ifdown()
3944 list_add_tail(&ifa->if_list_aux, &tmp_addr_list); in addrconf_ifdown()
3945 write_unlock_bh(&idev->lock); in addrconf_ifdown()
3953 list_del(&ifa->if_list_aux); in addrconf_ifdown()
3957 keep = keep_addr && (ifa->flags & IFA_F_PERMANENT) && in addrconf_ifdown()
3958 !addr_is_local(&ifa->addr); in addrconf_ifdown()
3960 spin_lock_bh(&ifa->lock); in addrconf_ifdown()
3965 ifa->state = INET6_IFADDR_STATE_PREDAD; in addrconf_ifdown()
3966 if (!(ifa->flags & IFA_F_NODAD)) in addrconf_ifdown()
3967 ifa->flags |= IFA_F_TENTATIVE; in addrconf_ifdown()
3969 rt = ifa->rt; in addrconf_ifdown()
3970 ifa->rt = NULL; in addrconf_ifdown()
3972 state = ifa->state; in addrconf_ifdown()
3973 ifa->state = INET6_IFADDR_STATE_DEAD; in addrconf_ifdown()
3976 spin_unlock_bh(&ifa->lock); in addrconf_ifdown()
3985 if (idev->cnf.forwarding) in addrconf_ifdown()
3987 addrconf_leave_solict(ifa->idev, &ifa->addr); in addrconf_ifdown()
3991 write_lock_bh(&idev->lock); in addrconf_ifdown()
3992 list_del_rcu(&ifa->if_list); in addrconf_ifdown()
3993 write_unlock_bh(&idev->lock); in addrconf_ifdown()
4006 WRITE_ONCE(idev->tstamp, jiffies); in addrconf_ifdown()
4007 idev->ra_mtu = 0; in addrconf_ifdown()
4012 neigh_parms_release(&nd_tbl, idev->nd_parms); in addrconf_ifdown()
4022 struct net_device *dev = idev->dev; in addrconf_rs_timer()
4026 write_lock(&idev->lock); in addrconf_rs_timer()
4027 if (idev->dead || !(idev->if_flags & IF_READY)) in addrconf_rs_timer()
4034 if (idev->if_flags & IF_RA_RCVD) in addrconf_rs_timer()
4037 rtr_solicits = READ_ONCE(idev->cnf.rtr_solicits); in addrconf_rs_timer()
4039 if (idev->rs_probes++ < rtr_solicits || rtr_solicits < 0) { in addrconf_rs_timer()
4040 write_unlock(&idev->lock); in addrconf_rs_timer()
4047 write_lock(&idev->lock); in addrconf_rs_timer()
4048 idev->rs_interval = rfc3315_s14_backoff_update( in addrconf_rs_timer()
4049 idev->rs_interval, in addrconf_rs_timer()
4050 READ_ONCE(idev->cnf.rtr_solicit_max_interval)); in addrconf_rs_timer()
4052 addrconf_mod_rs_timer(idev, (idev->rs_probes == in addrconf_rs_timer()
4053 READ_ONCE(idev->cnf.rtr_solicits)) ? in addrconf_rs_timer()
4054 READ_ONCE(idev->cnf.rtr_solicit_delay) : in addrconf_rs_timer()
4055 idev->rs_interval); in addrconf_rs_timer()
4058 * Note: we do not support deprecated "all on-link" in addrconf_rs_timer()
4061 pr_debug("%s: no IPv6 routers present\n", idev->dev->name); in addrconf_rs_timer()
4065 write_unlock(&idev->lock); in addrconf_rs_timer()
4075 struct inet6_dev *idev = ifp->idev; in addrconf_dad_kick()
4079 if (ifp->flags & IFA_F_OPTIMISTIC) in addrconf_dad_kick()
4083 READ_ONCE(idev->cnf.rtr_solicit_delay) ? : 1); in addrconf_dad_kick()
4086 if (READ_ONCE(idev->cnf.enhanced_dad) || in addrconf_dad_kick()
4087 READ_ONCE(dev_net(idev->dev)->ipv6.devconf_all->enhanced_dad)) { in addrconf_dad_kick()
4092 ifp->dad_nonce = nonce; in addrconf_dad_kick()
4093 ifp->dad_probes = READ_ONCE(idev->cnf.dad_transmits); in addrconf_dad_kick()
4099 struct inet6_dev *idev = ifp->idev; in addrconf_dad_begin()
4100 struct net_device *dev = idev->dev; in addrconf_dad_begin()
4104 addrconf_join_solict(dev, &ifp->addr); in addrconf_dad_begin()
4106 read_lock_bh(&idev->lock); in addrconf_dad_begin()
4107 spin_lock(&ifp->lock); in addrconf_dad_begin()
4108 if (ifp->state == INET6_IFADDR_STATE_DEAD) in addrconf_dad_begin()
4112 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || in addrconf_dad_begin()
4113 (READ_ONCE(net->ipv6.devconf_all->accept_dad) < 1 && in addrconf_dad_begin()
4114 READ_ONCE(idev->cnf.accept_dad) < 1) || in addrconf_dad_begin()
4115 !(ifp->flags&IFA_F_TENTATIVE) || in addrconf_dad_begin()
4116 ifp->flags & IFA_F_NODAD) { in addrconf_dad_begin()
4119 if (ifp->flags & IFA_F_TENTATIVE && in addrconf_dad_begin()
4120 !(ifp->flags & IFA_F_OPTIMISTIC)) in addrconf_dad_begin()
4122 bump_id = ifp->flags & IFA_F_TENTATIVE; in addrconf_dad_begin()
4123 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); in addrconf_dad_begin()
4124 spin_unlock(&ifp->lock); in addrconf_dad_begin()
4125 read_unlock_bh(&idev->lock); in addrconf_dad_begin()
4131 if (!(idev->if_flags & IF_READY)) { in addrconf_dad_begin()
4132 spin_unlock(&ifp->lock); in addrconf_dad_begin()
4133 read_unlock_bh(&idev->lock); in addrconf_dad_begin()
4136 * - keep it tentative if it is a permanent address. in addrconf_dad_begin()
4137 * - otherwise, kill it. in addrconf_dad_begin()
4148 if (ifp->flags & IFA_F_OPTIMISTIC) { in addrconf_dad_begin()
4149 ip6_ins_rt(net, ifp->rt); in addrconf_dad_begin()
4160 spin_unlock(&ifp->lock); in addrconf_dad_begin()
4161 read_unlock_bh(&idev->lock); in addrconf_dad_begin()
4170 spin_lock_bh(&ifp->lock); in addrconf_dad_start()
4171 if (ifp->state != INET6_IFADDR_STATE_DEAD) { in addrconf_dad_start()
4172 ifp->state = INET6_IFADDR_STATE_PREDAD; in addrconf_dad_start()
4175 spin_unlock_bh(&ifp->lock); in addrconf_dad_start()
4186 struct inet6_dev *idev = ifp->idev; in addrconf_dad_work()
4198 spin_lock_bh(&ifp->lock); in addrconf_dad_work()
4199 if (ifp->state == INET6_IFADDR_STATE_PREDAD) { in addrconf_dad_work()
4201 ifp->state = INET6_IFADDR_STATE_DAD; in addrconf_dad_work()
4202 } else if (ifp->state == INET6_IFADDR_STATE_ERRDAD) { in addrconf_dad_work()
4204 ifp->state = INET6_IFADDR_STATE_POSTDAD; in addrconf_dad_work()
4206 if ((READ_ONCE(dev_net(idev->dev)->ipv6.devconf_all->accept_dad) > 1 || in addrconf_dad_work()
4207 READ_ONCE(idev->cnf.accept_dad) > 1) && in addrconf_dad_work()
4208 !idev->cnf.disable_ipv6 && in addrconf_dad_work()
4209 !(ifp->flags & IFA_F_STABLE_PRIVACY)) { in addrconf_dad_work()
4215 if (!ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) && in addrconf_dad_work()
4216 ipv6_addr_equal(&ifp->addr, &addr)) { in addrconf_dad_work()
4217 /* DAD failed for link-local based on MAC */ in addrconf_dad_work()
4218 WRITE_ONCE(idev->cnf.disable_ipv6, 1); in addrconf_dad_work()
4221 ifp->idev->dev->name); in addrconf_dad_work()
4226 spin_unlock_bh(&ifp->lock); in addrconf_dad_work()
4235 addrconf_ifdown(idev->dev, false); in addrconf_dad_work()
4239 if (!ifp->dad_probes && addrconf_dad_end(ifp)) in addrconf_dad_work()
4242 write_lock_bh(&idev->lock); in addrconf_dad_work()
4243 if (idev->dead || !(idev->if_flags & IF_READY)) { in addrconf_dad_work()
4244 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4248 spin_lock(&ifp->lock); in addrconf_dad_work()
4249 if (ifp->state == INET6_IFADDR_STATE_DEAD) { in addrconf_dad_work()
4250 spin_unlock(&ifp->lock); in addrconf_dad_work()
4251 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4255 if (ifp->dad_probes == 0) { in addrconf_dad_work()
4262 if (ifp->flags & IFA_F_TENTATIVE && in addrconf_dad_work()
4263 !(ifp->flags & IFA_F_OPTIMISTIC)) in addrconf_dad_work()
4265 bump_id = ifp->flags & IFA_F_TENTATIVE; in addrconf_dad_work()
4266 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); in addrconf_dad_work()
4267 spin_unlock(&ifp->lock); in addrconf_dad_work()
4268 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4275 ifp->dad_probes--; in addrconf_dad_work()
4277 max(NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME), in addrconf_dad_work()
4279 spin_unlock(&ifp->lock); in addrconf_dad_work()
4280 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4283 addrconf_addr_solict_mult(&ifp->addr, &mcaddr); in addrconf_dad_work()
4284 ndisc_send_ns(ifp->idev->dev, &ifp->addr, &mcaddr, &in6addr_any, in addrconf_dad_work()
4285 ifp->dad_nonce); in addrconf_dad_work()
4291 /* ifp->idev must be at least read locked */
4295 struct inet6_dev *idev = ifp->idev; in ipv6_lonely_lladdr()
4297 list_for_each_entry_reverse(ifpiter, &idev->addr_list, if_list) { in ipv6_lonely_lladdr()
4298 if (ifpiter->scope > IFA_LINK) in ipv6_lonely_lladdr()
4300 if (ifp != ifpiter && ifpiter->scope == IFA_LINK && in ipv6_lonely_lladdr()
4301 (ifpiter->flags & (IFA_F_PERMANENT|IFA_F_TENTATIVE| in ipv6_lonely_lladdr()
4312 struct net_device *dev = ifp->idev->dev; in addrconf_dad_completed()
4328 read_lock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4329 send_mld = ifp->scope == IFA_LINK && ipv6_lonely_lladdr(ifp); in addrconf_dad_completed()
4331 ipv6_accept_ra(ifp->idev) && in addrconf_dad_completed()
4332 READ_ONCE(ifp->idev->cnf.rtr_solicits) != 0 && in addrconf_dad_completed()
4333 (dev->flags & IFF_LOOPBACK) == 0 && in addrconf_dad_completed()
4334 (dev->type != ARPHRD_TUNNEL) && in addrconf_dad_completed()
4336 read_unlock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4342 ipv6_mc_dad_complete(ifp->idev); in addrconf_dad_completed()
4346 (READ_ONCE(ifp->idev->cnf.ndisc_notify) || in addrconf_dad_completed()
4347 READ_ONCE(dev_net(dev)->ipv6.devconf_all->ndisc_notify))) { in addrconf_dad_completed()
4348 ndisc_send_na(dev, &in6addr_linklocal_allnodes, &ifp->addr, in addrconf_dad_completed()
4349 /*router=*/ !!ifp->idev->cnf.forwarding, in addrconf_dad_completed()
4364 write_lock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4365 spin_lock(&ifp->lock); in addrconf_dad_completed()
4366 ifp->idev->rs_interval = rfc3315_s14_backoff_init( in addrconf_dad_completed()
4367 READ_ONCE(ifp->idev->cnf.rtr_solicit_interval)); in addrconf_dad_completed()
4368 ifp->idev->rs_probes = 1; in addrconf_dad_completed()
4369 ifp->idev->if_flags |= IF_RS_SENT; in addrconf_dad_completed()
4370 addrconf_mod_rs_timer(ifp->idev, ifp->idev->rs_interval); in addrconf_dad_completed()
4371 spin_unlock(&ifp->lock); in addrconf_dad_completed()
4372 write_unlock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4381 if (ifp->flags & IFA_F_TEMPORARY) in addrconf_dad_completed()
4389 read_lock_bh(&idev->lock); in addrconf_dad_run()
4390 list_for_each_entry(ifp, &idev->addr_list, if_list) { in addrconf_dad_run()
4391 spin_lock(&ifp->lock); in addrconf_dad_run()
4392 if ((ifp->flags & IFA_F_TENTATIVE && in addrconf_dad_run()
4393 ifp->state == INET6_IFADDR_STATE_DAD) || restart) { in addrconf_dad_run()
4395 ifp->state = INET6_IFADDR_STATE_PREDAD; in addrconf_dad_run()
4398 spin_unlock(&ifp->lock); in addrconf_dad_run()
4400 read_unlock_bh(&idev->lock); in addrconf_dad_run()
4412 struct if6_iter_state *state = seq->private; in if6_get_first()
4419 state->bucket = 0; in if6_get_first()
4420 state->offset = 0; in if6_get_first()
4423 for (; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) { in if6_get_first()
4424 hlist_for_each_entry_rcu(ifa, &net->ipv6.inet6_addr_lst[state->bucket], in if6_get_first()
4427 if (p < state->offset) { in if6_get_first()
4435 state->offset = 0; in if6_get_first()
4444 struct if6_iter_state *state = seq->private; in if6_get_next()
4448 state->offset++; in if6_get_next()
4452 state->offset = 0; in if6_get_next()
4453 while (++state->bucket < IN6_ADDR_HSIZE) { in if6_get_next()
4455 &net->ipv6.inet6_addr_lst[state->bucket], addr_lst) { in if6_get_next()
4489 &ifp->addr, in if6_seq_show()
4490 ifp->idev->dev->ifindex, in if6_seq_show()
4491 ifp->prefix_len, in if6_seq_show()
4492 ifp->scope, in if6_seq_show()
4493 (u8) ifp->flags, in if6_seq_show()
4494 ifp->idev->dev->name); in if6_seq_show()
4507 if (!proc_create_net("if_inet6", 0444, net->proc_net, &if6_seq_ops, in if6_proc_net_init()
4509 return -ENOMEM; in if6_proc_net_init()
4515 remove_proc_entry("if_inet6", net->proc_net); in if6_proc_net_exit()
4543 hlist_for_each_entry_rcu(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) { in ipv6_chk_home_addr()
4544 if (ipv6_addr_equal(&ifp->addr, addr) && in ipv6_chk_home_addr()
4545 (ifp->flags & IFA_F_HOMEADDRESS)) { in ipv6_chk_home_addr()
4581 hlist_for_each_entry_rcu(ifp, &net->ipv6.inet6_addr_lst[hash], addr_lst) { in ipv6_chk_rpl_srh_loop()
4583 if (ipv6_addr_equal(&ifp->addr, addr)) { in ipv6_chk_rpl_srh_loop()
4622 cancel_delayed_work(&net->ipv6.addr_chk_work); in addrconf_verify_rtnl()
4626 hlist_for_each_entry_rcu_bh(ifp, &net->ipv6.inet6_addr_lst[i], addr_lst) { in addrconf_verify_rtnl()
4631 * IFA_F_PERMANENT has a non-infinity life time. in addrconf_verify_rtnl()
4633 if ((ifp->flags & IFA_F_PERMANENT) && in addrconf_verify_rtnl()
4634 (ifp->prefered_lft == INFINITY_LIFE_TIME)) in addrconf_verify_rtnl()
4637 spin_lock(&ifp->lock); in addrconf_verify_rtnl()
4639 age = (now - ifp->tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; in addrconf_verify_rtnl()
4641 if ((ifp->flags&IFA_F_TEMPORARY) && in addrconf_verify_rtnl()
4642 !(ifp->flags&IFA_F_TENTATIVE) && in addrconf_verify_rtnl()
4643 ifp->prefered_lft != INFINITY_LIFE_TIME && in addrconf_verify_rtnl()
4644 !ifp->regen_count && ifp->ifpub) { in addrconf_verify_rtnl()
4645 /* This is a non-regenerated temporary addr. */ in addrconf_verify_rtnl()
4647 unsigned long regen_advance = ipv6_get_regen_advance(ifp->idev); in addrconf_verify_rtnl()
4649 if (age + regen_advance >= ifp->prefered_lft) { in addrconf_verify_rtnl()
4650 struct inet6_ifaddr *ifpub = ifp->ifpub; in addrconf_verify_rtnl()
4651 if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) in addrconf_verify_rtnl()
4652 next = ifp->tstamp + ifp->prefered_lft * HZ; in addrconf_verify_rtnl()
4654 ifp->regen_count++; in addrconf_verify_rtnl()
4657 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4659 spin_lock(&ifpub->lock); in addrconf_verify_rtnl()
4660 ifpub->regen_count = 0; in addrconf_verify_rtnl()
4661 spin_unlock(&ifpub->lock); in addrconf_verify_rtnl()
4668 } else if (time_before(ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ, next)) in addrconf_verify_rtnl()
4669 next = ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ; in addrconf_verify_rtnl()
4672 if (ifp->valid_lft != INFINITY_LIFE_TIME && in addrconf_verify_rtnl()
4673 age >= ifp->valid_lft) { in addrconf_verify_rtnl()
4674 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4680 } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) { in addrconf_verify_rtnl()
4681 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4683 } else if (age >= ifp->prefered_lft) { in addrconf_verify_rtnl()
4684 /* jiffies - ifp->tstamp > age >= ifp->prefered_lft */ in addrconf_verify_rtnl()
4687 if (!(ifp->flags&IFA_F_DEPRECATED)) { in addrconf_verify_rtnl()
4689 ifp->flags |= IFA_F_DEPRECATED; in addrconf_verify_rtnl()
4692 if ((ifp->valid_lft != INFINITY_LIFE_TIME) && in addrconf_verify_rtnl()
4693 (time_before(ifp->tstamp + ifp->valid_lft * HZ, next))) in addrconf_verify_rtnl()
4694 next = ifp->tstamp + ifp->valid_lft * HZ; in addrconf_verify_rtnl()
4696 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4706 /* ifp->prefered_lft <= ifp->valid_lft */ in addrconf_verify_rtnl()
4707 if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) in addrconf_verify_rtnl()
4708 next = ifp->tstamp + ifp->prefered_lft * HZ; in addrconf_verify_rtnl()
4709 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4727 mod_delayed_work(addrconf_wq, &net->ipv6.addr_chk_work, next_sched - now); in addrconf_verify_rtnl()
4743 mod_delayed_work(addrconf_wq, &net->ipv6.addr_chk_work, 0); in addrconf_verify()
4779 struct net *net = sock_net(skb->sk); in inet6_rtm_deladdr()
4794 return -EINVAL; in inet6_rtm_deladdr()
4796 ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags; in inet6_rtm_deladdr()
4801 return inet6_addr_del(net, ifm->ifa_index, ifa_flags, pfx, in inet6_rtm_deladdr()
4802 ifm->ifa_prefixlen, extack); in inet6_rtm_deladdr()
4813 f6i = addrconf_get_prefix_route(modify_peer ? &ifp->peer_addr : &ifp->addr, in modify_prefix_route()
4814 ifp->prefix_len, in modify_prefix_route()
4815 ifp->idev->dev, 0, RTF_DEFAULT, true); in modify_prefix_route()
4817 return -ENOENT; in modify_prefix_route()
4819 prio = ifp->rt_priority ? : IP6_RT_PRIO_ADDRCONF; in modify_prefix_route()
4820 if (f6i->fib6_metric != prio) { in modify_prefix_route()
4822 ip6_del_rt(dev_net(ifp->idev->dev), f6i, false); in modify_prefix_route()
4825 addrconf_prefix_route(modify_peer ? &ifp->peer_addr : &ifp->addr, in modify_prefix_route()
4826 ifp->prefix_len, in modify_prefix_route()
4827 ifp->rt_priority, ifp->idev->dev, in modify_prefix_route()
4830 table = f6i->fib6_table; in modify_prefix_route()
4831 spin_lock_bh(&table->tb6_lock); in modify_prefix_route()
4841 spin_unlock_bh(&table->tb6_lock); in modify_prefix_route()
4861 if (!cfg->valid_lft || cfg->preferred_lft > cfg->valid_lft) in inet6_addr_modify()
4862 return -EINVAL; in inet6_addr_modify()
4864 if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR && in inet6_addr_modify()
4865 (ifp->flags & IFA_F_TEMPORARY || ifp->prefix_len != 64)) in inet6_addr_modify()
4866 return -EINVAL; in inet6_addr_modify()
4868 if (!(ifp->flags & IFA_F_TENTATIVE) || ifp->flags & IFA_F_DADFAILED) in inet6_addr_modify()
4869 cfg->ifa_flags &= ~IFA_F_OPTIMISTIC; in inet6_addr_modify()
4871 timeout = addrconf_timeout_fixup(cfg->valid_lft, HZ); in inet6_addr_modify()
4874 cfg->valid_lft = timeout; in inet6_addr_modify()
4879 cfg->ifa_flags |= IFA_F_PERMANENT; in inet6_addr_modify()
4882 timeout = addrconf_timeout_fixup(cfg->preferred_lft, HZ); in inet6_addr_modify()
4885 cfg->ifa_flags |= IFA_F_DEPRECATED; in inet6_addr_modify()
4886 cfg->preferred_lft = timeout; in inet6_addr_modify()
4889 if (cfg->peer_pfx && in inet6_addr_modify()
4890 memcmp(&ifp->peer_addr, cfg->peer_pfx, sizeof(struct in6_addr))) { in inet6_addr_modify()
4891 if (!ipv6_addr_any(&ifp->peer_addr)) in inet6_addr_modify()
4896 spin_lock_bh(&ifp->lock); in inet6_addr_modify()
4897 was_managetempaddr = ifp->flags & IFA_F_MANAGETEMPADDR; in inet6_addr_modify()
4898 had_prefixroute = ifp->flags & IFA_F_PERMANENT && in inet6_addr_modify()
4899 !(ifp->flags & IFA_F_NOPREFIXROUTE); in inet6_addr_modify()
4900 ifp->flags &= ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | in inet6_addr_modify()
4903 ifp->flags |= cfg->ifa_flags; in inet6_addr_modify()
4904 WRITE_ONCE(ifp->tstamp, jiffies); in inet6_addr_modify()
4905 WRITE_ONCE(ifp->valid_lft, cfg->valid_lft); in inet6_addr_modify()
4906 WRITE_ONCE(ifp->prefered_lft, cfg->preferred_lft); in inet6_addr_modify()
4907 WRITE_ONCE(ifp->ifa_proto, cfg->ifa_proto); in inet6_addr_modify()
4909 if (cfg->rt_priority && cfg->rt_priority != ifp->rt_priority) in inet6_addr_modify()
4910 WRITE_ONCE(ifp->rt_priority, cfg->rt_priority); in inet6_addr_modify()
4913 ifp->peer_addr = *cfg->peer_pfx; in inet6_addr_modify()
4915 spin_unlock_bh(&ifp->lock); in inet6_addr_modify()
4916 if (!(ifp->flags&IFA_F_TENTATIVE)) in inet6_addr_modify()
4919 if (!(cfg->ifa_flags & IFA_F_NOPREFIXROUTE)) { in inet6_addr_modify()
4920 int rc = -ENOENT; in inet6_addr_modify()
4925 /* prefix route could have been deleted; if so restore it */ in inet6_addr_modify()
4926 if (rc == -ENOENT) { in inet6_addr_modify()
4927 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, in inet6_addr_modify()
4928 ifp->rt_priority, ifp->idev->dev, in inet6_addr_modify()
4932 if (had_prefixroute && !ipv6_addr_any(&ifp->peer_addr)) in inet6_addr_modify()
4935 if (rc == -ENOENT && !ipv6_addr_any(&ifp->peer_addr)) { in inet6_addr_modify()
4936 addrconf_prefix_route(&ifp->peer_addr, ifp->prefix_len, in inet6_addr_modify()
4937 ifp->rt_priority, ifp->idev->dev, in inet6_addr_modify()
4944 write_lock_bh(&ifp->idev->lock); in inet6_addr_modify()
4946 write_unlock_bh(&ifp->idev->lock); in inet6_addr_modify()
4954 if (was_managetempaddr || ifp->flags & IFA_F_MANAGETEMPADDR) { in inet6_addr_modify()
4956 !(ifp->flags & IFA_F_MANAGETEMPADDR)) { in inet6_addr_modify()
4957 cfg->valid_lft = 0; in inet6_addr_modify()
4958 cfg->preferred_lft = 0; in inet6_addr_modify()
4960 manage_tempaddrs(ifp->idev, ifp, cfg->valid_lft, in inet6_addr_modify()
4961 cfg->preferred_lft, !was_managetempaddr, in inet6_addr_modify()
4974 struct net *net = sock_net(skb->sk); in inet6_rtm_newaddr()
4994 return -EINVAL; in inet6_rtm_newaddr()
4997 cfg.plen = ifm->ifa_prefixlen; in inet6_rtm_newaddr()
5011 cfg.valid_lft = ci->ifa_valid; in inet6_rtm_newaddr()
5012 cfg.preferred_lft = ci->ifa_prefered; in inet6_rtm_newaddr()
5015 dev = __dev_get_by_index(net, ifm->ifa_index); in inet6_rtm_newaddr()
5018 return -ENODEV; in inet6_rtm_newaddr()
5024 cfg.ifa_flags = ifm->ifa_flags; in inet6_rtm_newaddr()
5041 return -EINVAL; in inet6_rtm_newaddr()
5050 return inet6_addr_add(net, ifm->ifa_index, &cfg, extack); in inet6_rtm_newaddr()
5053 if (nlh->nlmsg_flags & NLM_F_EXCL || in inet6_rtm_newaddr()
5054 !(nlh->nlmsg_flags & NLM_F_REPLACE)) { in inet6_rtm_newaddr()
5056 err = -EEXIST; in inet6_rtm_newaddr()
5072 ifm->ifa_family = AF_INET6; in put_ifaddrmsg()
5073 ifm->ifa_prefixlen = prefixlen; in put_ifaddrmsg()
5074 ifm->ifa_flags = flags; in put_ifaddrmsg()
5075 ifm->ifa_scope = scope; in put_ifaddrmsg()
5076 ifm->ifa_index = ifindex; in put_ifaddrmsg()
5140 nlh = nlmsg_put(skb, args->portid, args->seq, args->event, in inet6_fill_ifaddr()
5141 sizeof(struct ifaddrmsg), args->flags); in inet6_fill_ifaddr()
5143 return -EMSGSIZE; in inet6_fill_ifaddr()
5145 flags = READ_ONCE(ifa->flags); in inet6_fill_ifaddr()
5146 put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope), in inet6_fill_ifaddr()
5147 ifa->idev->dev->ifindex); in inet6_fill_ifaddr()
5149 if (args->netnsid >= 0 && in inet6_fill_ifaddr()
5150 nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) in inet6_fill_ifaddr()
5153 preferred = READ_ONCE(ifa->prefered_lft); in inet6_fill_ifaddr()
5154 valid = READ_ONCE(ifa->valid_lft); in inet6_fill_ifaddr()
5159 long tval = (jiffies - READ_ONCE(ifa->tstamp)) / HZ; in inet6_fill_ifaddr()
5162 preferred -= tval; in inet6_fill_ifaddr()
5167 valid -= tval; in inet6_fill_ifaddr()
5177 if (!ipv6_addr_any(&ifa->peer_addr)) { in inet6_fill_ifaddr()
5178 if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 || in inet6_fill_ifaddr()
5179 nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->peer_addr) < 0) in inet6_fill_ifaddr()
5182 if (nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->addr) < 0) in inet6_fill_ifaddr()
5186 priority = READ_ONCE(ifa->rt_priority); in inet6_fill_ifaddr()
5190 if (put_cacheinfo(skb, ifa->cstamp, READ_ONCE(ifa->tstamp), in inet6_fill_ifaddr()
5197 proto = READ_ONCE(ifa->ifa_proto); in inet6_fill_ifaddr()
5206 return -EMSGSIZE; in inet6_fill_ifaddr()
5213 int ifindex = ifmca->idev->dev->ifindex; in inet6_fill_ifmcaddr()
5217 if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE) in inet6_fill_ifmcaddr()
5220 nlh = nlmsg_put(skb, args->portid, args->seq, args->event, in inet6_fill_ifmcaddr()
5221 sizeof(struct ifaddrmsg), args->flags); in inet6_fill_ifmcaddr()
5223 return -EMSGSIZE; in inet6_fill_ifmcaddr()
5225 if (args->netnsid >= 0 && in inet6_fill_ifmcaddr()
5226 nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) { in inet6_fill_ifmcaddr()
5228 return -EMSGSIZE; in inet6_fill_ifmcaddr()
5232 if (nla_put_in6_addr(skb, IFA_MULTICAST, &ifmca->mca_addr) < 0 || in inet6_fill_ifmcaddr()
5233 put_cacheinfo(skb, ifmca->mca_cstamp, READ_ONCE(ifmca->mca_tstamp), in inet6_fill_ifmcaddr()
5236 return -EMSGSIZE; in inet6_fill_ifmcaddr()
5247 struct net_device *dev = fib6_info_nh_dev(ifaca->aca_rt); in inet6_fill_ifacaddr()
5248 int ifindex = dev ? dev->ifindex : 1; in inet6_fill_ifacaddr()
5252 if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE) in inet6_fill_ifacaddr()
5255 nlh = nlmsg_put(skb, args->portid, args->seq, args->event, in inet6_fill_ifacaddr()
5256 sizeof(struct ifaddrmsg), args->flags); in inet6_fill_ifacaddr()
5258 return -EMSGSIZE; in inet6_fill_ifacaddr()
5260 if (args->netnsid >= 0 && in inet6_fill_ifacaddr()
5261 nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) { in inet6_fill_ifacaddr()
5263 return -EMSGSIZE; in inet6_fill_ifacaddr()
5267 if (nla_put_in6_addr(skb, IFA_ANYCAST, &ifaca->aca_addr) < 0 || in inet6_fill_ifacaddr()
5268 put_cacheinfo(skb, ifaca->aca_cstamp, READ_ONCE(ifaca->aca_tstamp), in inet6_fill_ifacaddr()
5271 return -EMSGSIZE; in inet6_fill_ifacaddr()
5288 switch (fillargs->type) { in in6_dump_addrs()
5291 fillargs->event = RTM_NEWADDR; in in6_dump_addrs()
5294 list_for_each_entry_rcu(ifa, &idev->addr_list, if_list) { in in6_dump_addrs()
5307 fillargs->event = RTM_GETMULTICAST; in in6_dump_addrs()
5310 for (ifmca = rcu_dereference(idev->mc_list); in in6_dump_addrs()
5312 ifmca = rcu_dereference(ifmca->next), ip_idx++) { in in6_dump_addrs()
5321 fillargs->event = RTM_GETANYCAST; in in6_dump_addrs()
5323 for (ifaca = rcu_dereference(idev->ac_list); ifaca; in in6_dump_addrs()
5324 ifaca = rcu_dereference(ifaca->aca_next), ip_idx++) { in in6_dump_addrs()
5344 struct netlink_ext_ack *extack = cb->extack; in inet6_valid_dump_ifaddr_req()
5349 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in inet6_valid_dump_ifaddr_req()
5351 return -EINVAL; in inet6_valid_dump_ifaddr_req()
5355 if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) { in inet6_valid_dump_ifaddr_req()
5357 return -EINVAL; in inet6_valid_dump_ifaddr_req()
5360 fillargs->ifindex = ifm->ifa_index; in inet6_valid_dump_ifaddr_req()
5361 if (fillargs->ifindex) { in inet6_valid_dump_ifaddr_req()
5362 cb->answer_flags |= NLM_F_DUMP_FILTERED; in inet6_valid_dump_ifaddr_req()
5363 fillargs->flags |= NLM_F_DUMP_FILTERED; in inet6_valid_dump_ifaddr_req()
5378 fillargs->netnsid = nla_get_s32(tb[i]); in inet6_valid_dump_ifaddr_req()
5379 net = rtnl_get_net_ns_capable(sk, fillargs->netnsid); in inet6_valid_dump_ifaddr_req()
5381 fillargs->netnsid = -1; in inet6_valid_dump_ifaddr_req()
5388 return -EINVAL; in inet6_valid_dump_ifaddr_req()
5398 struct net *tgt_net = sock_net(skb->sk); in inet6_dump_addr()
5399 const struct nlmsghdr *nlh = cb->nlh; in inet6_dump_addr()
5401 .portid = NETLINK_CB(cb->skb).portid, in inet6_dump_addr()
5402 .seq = cb->nlh->nlmsg_seq, in inet6_dump_addr()
5404 .netnsid = -1, in inet6_dump_addr()
5410 } *ctx = (void *)cb->ctx; in inet6_dump_addr()
5416 if (cb->strict_check) { in inet6_dump_addr()
5418 skb->sk, cb); in inet6_dump_addr()
5426 err = -ENODEV; in inet6_dump_addr()
5432 &ctx->ip_idx, in inet6_dump_addr()
5438 cb->seq = inet6_base_seq(tgt_net); in inet6_dump_addr()
5439 for_each_netdev_dump(tgt_net, dev, ctx->ifindex) { in inet6_dump_addr()
5443 err = in6_dump_addrs(idev, skb, cb, &ctx->ip_idx, in inet6_dump_addr()
5486 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in inet6_rtm_valid_getaddr_req()
5488 return -EINVAL; in inet6_rtm_valid_getaddr_req()
5496 if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) { in inet6_rtm_valid_getaddr_req()
5498 return -EINVAL; in inet6_rtm_valid_getaddr_req()
5517 return -EINVAL; in inet6_rtm_valid_getaddr_req()
5527 struct net *tgt_net = sock_net(in_skb->sk); in inet6_rtm_getaddr()
5530 .seq = nlh->nlmsg_seq, in inet6_rtm_getaddr()
5533 .netnsid = -1, in inet6_rtm_getaddr()
5558 err = -EINVAL; in inet6_rtm_getaddr()
5562 if (ifm->ifa_index) in inet6_rtm_getaddr()
5563 dev = dev_get_by_index(tgt_net, ifm->ifa_index); in inet6_rtm_getaddr()
5567 err = -EADDRNOTAVAIL; in inet6_rtm_getaddr()
5573 err = -ENOBUFS; in inet6_rtm_getaddr()
5579 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ in inet6_rtm_getaddr()
5580 WARN_ON(err == -EMSGSIZE); in inet6_rtm_getaddr()
5598 struct net *net = dev_net(ifa->idev->dev); in inet6_ifa_notify()
5604 .netnsid = -1, in inet6_ifa_notify()
5606 int err = -ENOBUFS; in inet6_ifa_notify()
5614 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ in inet6_ifa_notify()
5615 WARN_ON(err == -EMSGSIZE); in inet6_ifa_notify()
5631 array[DEVCONF_FORWARDING] = READ_ONCE(cnf->forwarding); in ipv6_store_devconf()
5632 array[DEVCONF_HOPLIMIT] = READ_ONCE(cnf->hop_limit); in ipv6_store_devconf()
5633 array[DEVCONF_MTU6] = READ_ONCE(cnf->mtu6); in ipv6_store_devconf()
5634 array[DEVCONF_ACCEPT_RA] = READ_ONCE(cnf->accept_ra); in ipv6_store_devconf()
5635 array[DEVCONF_ACCEPT_REDIRECTS] = READ_ONCE(cnf->accept_redirects); in ipv6_store_devconf()
5636 array[DEVCONF_AUTOCONF] = READ_ONCE(cnf->autoconf); in ipv6_store_devconf()
5637 array[DEVCONF_DAD_TRANSMITS] = READ_ONCE(cnf->dad_transmits); in ipv6_store_devconf()
5638 array[DEVCONF_RTR_SOLICITS] = READ_ONCE(cnf->rtr_solicits); in ipv6_store_devconf()
5640 jiffies_to_msecs(READ_ONCE(cnf->rtr_solicit_interval)); in ipv6_store_devconf()
5642 jiffies_to_msecs(READ_ONCE(cnf->rtr_solicit_max_interval)); in ipv6_store_devconf()
5644 jiffies_to_msecs(READ_ONCE(cnf->rtr_solicit_delay)); in ipv6_store_devconf()
5645 array[DEVCONF_FORCE_MLD_VERSION] = READ_ONCE(cnf->force_mld_version); in ipv6_store_devconf()
5647 jiffies_to_msecs(READ_ONCE(cnf->mldv1_unsolicited_report_interval)); in ipv6_store_devconf()
5649 jiffies_to_msecs(READ_ONCE(cnf->mldv2_unsolicited_report_interval)); in ipv6_store_devconf()
5650 array[DEVCONF_USE_TEMPADDR] = READ_ONCE(cnf->use_tempaddr); in ipv6_store_devconf()
5651 array[DEVCONF_TEMP_VALID_LFT] = READ_ONCE(cnf->temp_valid_lft); in ipv6_store_devconf()
5652 array[DEVCONF_TEMP_PREFERED_LFT] = READ_ONCE(cnf->temp_prefered_lft); in ipv6_store_devconf()
5653 array[DEVCONF_REGEN_MAX_RETRY] = READ_ONCE(cnf->regen_max_retry); in ipv6_store_devconf()
5654 array[DEVCONF_MAX_DESYNC_FACTOR] = READ_ONCE(cnf->max_desync_factor); in ipv6_store_devconf()
5655 array[DEVCONF_MAX_ADDRESSES] = READ_ONCE(cnf->max_addresses); in ipv6_store_devconf()
5656 array[DEVCONF_ACCEPT_RA_DEFRTR] = READ_ONCE(cnf->accept_ra_defrtr); in ipv6_store_devconf()
5657 array[DEVCONF_RA_DEFRTR_METRIC] = READ_ONCE(cnf->ra_defrtr_metric); in ipv6_store_devconf()
5659 READ_ONCE(cnf->accept_ra_min_hop_limit); in ipv6_store_devconf()
5660 array[DEVCONF_ACCEPT_RA_PINFO] = READ_ONCE(cnf->accept_ra_pinfo); in ipv6_store_devconf()
5662 array[DEVCONF_ACCEPT_RA_RTR_PREF] = READ_ONCE(cnf->accept_ra_rtr_pref); in ipv6_store_devconf()
5664 jiffies_to_msecs(READ_ONCE(cnf->rtr_probe_interval)); in ipv6_store_devconf()
5667 READ_ONCE(cnf->accept_ra_rt_info_min_plen); in ipv6_store_devconf()
5669 READ_ONCE(cnf->accept_ra_rt_info_max_plen); in ipv6_store_devconf()
5672 array[DEVCONF_PROXY_NDP] = READ_ONCE(cnf->proxy_ndp); in ipv6_store_devconf()
5674 READ_ONCE(cnf->accept_source_route); in ipv6_store_devconf()
5676 array[DEVCONF_OPTIMISTIC_DAD] = READ_ONCE(cnf->optimistic_dad); in ipv6_store_devconf()
5677 array[DEVCONF_USE_OPTIMISTIC] = READ_ONCE(cnf->use_optimistic); in ipv6_store_devconf()
5680 array[DEVCONF_MC_FORWARDING] = atomic_read(&cnf->mc_forwarding); in ipv6_store_devconf()
5682 array[DEVCONF_DISABLE_IPV6] = READ_ONCE(cnf->disable_ipv6); in ipv6_store_devconf()
5683 array[DEVCONF_ACCEPT_DAD] = READ_ONCE(cnf->accept_dad); in ipv6_store_devconf()
5684 array[DEVCONF_FORCE_TLLAO] = READ_ONCE(cnf->force_tllao); in ipv6_store_devconf()
5685 array[DEVCONF_NDISC_NOTIFY] = READ_ONCE(cnf->ndisc_notify); in ipv6_store_devconf()
5687 READ_ONCE(cnf->suppress_frag_ndisc); in ipv6_store_devconf()
5689 READ_ONCE(cnf->accept_ra_from_local); in ipv6_store_devconf()
5690 array[DEVCONF_ACCEPT_RA_MTU] = READ_ONCE(cnf->accept_ra_mtu); in ipv6_store_devconf()
5692 READ_ONCE(cnf->ignore_routes_with_linkdown); in ipv6_store_devconf()
5694 array[DEVCONF_USE_OIF_ADDRS_ONLY] = READ_ONCE(cnf->use_oif_addrs_only); in ipv6_store_devconf()
5696 READ_ONCE(cnf->drop_unicast_in_l2_multicast); in ipv6_store_devconf()
5697 array[DEVCONF_DROP_UNSOLICITED_NA] = READ_ONCE(cnf->drop_unsolicited_na); in ipv6_store_devconf()
5698 array[DEVCONF_KEEP_ADDR_ON_DOWN] = READ_ONCE(cnf->keep_addr_on_down); in ipv6_store_devconf()
5699 array[DEVCONF_SEG6_ENABLED] = READ_ONCE(cnf->seg6_enabled); in ipv6_store_devconf()
5701 array[DEVCONF_SEG6_REQUIRE_HMAC] = READ_ONCE(cnf->seg6_require_hmac); in ipv6_store_devconf()
5703 array[DEVCONF_ENHANCED_DAD] = READ_ONCE(cnf->enhanced_dad); in ipv6_store_devconf()
5704 array[DEVCONF_ADDR_GEN_MODE] = READ_ONCE(cnf->addr_gen_mode); in ipv6_store_devconf()
5705 array[DEVCONF_DISABLE_POLICY] = READ_ONCE(cnf->disable_policy); in ipv6_store_devconf()
5706 array[DEVCONF_NDISC_TCLASS] = READ_ONCE(cnf->ndisc_tclass); in ipv6_store_devconf()
5707 array[DEVCONF_RPL_SEG_ENABLED] = READ_ONCE(cnf->rpl_seg_enabled); in ipv6_store_devconf()
5708 array[DEVCONF_IOAM6_ENABLED] = READ_ONCE(cnf->ioam6_enabled); in ipv6_store_devconf()
5709 array[DEVCONF_IOAM6_ID] = READ_ONCE(cnf->ioam6_id); in ipv6_store_devconf()
5710 array[DEVCONF_IOAM6_ID_WIDE] = READ_ONCE(cnf->ioam6_id_wide); in ipv6_store_devconf()
5712 READ_ONCE(cnf->ndisc_evict_nocarrier); in ipv6_store_devconf()
5714 READ_ONCE(cnf->accept_untracked_na); in ipv6_store_devconf()
5715 array[DEVCONF_ACCEPT_RA_MIN_LFT] = READ_ONCE(cnf->accept_ra_min_lft); in ipv6_store_devconf()
5746 int pad = bytes - sizeof(u64) * ICMP6_MIB_MAX; in __snmp6_fill_statsdev()
5762 int pad = bytes - sizeof(u64) * IPSTATS_MIB_MAX; in __snmp6_fill_stats64()
5783 __snmp6_fill_stats64(stats, idev->stats.ipv6, bytes, in snmp6_fill_stats()
5787 __snmp6_fill_statsdev(stats, idev->stats.icmpv6dev->mibs, bytes); in snmp6_fill_stats()
5799 if (nla_put_u32(skb, IFLA_INET6_FLAGS, READ_ONCE(idev->if_flags))) in inet6_fill_ifla6_attrs()
5802 ci.tstamp = cstamp_delta(READ_ONCE(idev->tstamp)); in inet6_fill_ifla6_attrs()
5803 ci.reachable_time = jiffies_to_msecs(idev->nd_parms->reachable_time); in inet6_fill_ifla6_attrs()
5804 ci.retrans_time = jiffies_to_msecs(NEIGH_VAR(idev->nd_parms, RETRANS_TIME)); in inet6_fill_ifla6_attrs()
5810 ipv6_store_devconf(&idev->cnf, nla_data(nla), nla_len(nla)); in inet6_fill_ifla6_attrs()
5812 /* XXX - MC not implemented */ in inet6_fill_ifla6_attrs()
5830 read_lock_bh(&idev->lock); in inet6_fill_ifla6_attrs()
5831 memcpy(nla_data(nla), idev->token.s6_addr, nla_len(nla)); in inet6_fill_ifla6_attrs()
5832 read_unlock_bh(&idev->lock); in inet6_fill_ifla6_attrs()
5835 READ_ONCE(idev->cnf.addr_gen_mode))) in inet6_fill_ifla6_attrs()
5838 ra_mtu = READ_ONCE(idev->ra_mtu); in inet6_fill_ifla6_attrs()
5845 return -EMSGSIZE; in inet6_fill_ifla6_attrs()
5863 return -ENODATA; in inet6_fill_link_af()
5866 return -EMSGSIZE; in inet6_fill_link_af()
5875 struct net_device *dev = idev->dev; in inet6_set_iftoken()
5882 return -EINVAL; in inet6_set_iftoken()
5884 if (dev->flags & IFF_LOOPBACK) { in inet6_set_iftoken()
5886 return -EINVAL; in inet6_set_iftoken()
5889 if (dev->flags & IFF_NOARP) { in inet6_set_iftoken()
5892 return -EINVAL; in inet6_set_iftoken()
5898 return -EINVAL; in inet6_set_iftoken()
5901 if (READ_ONCE(idev->cnf.rtr_solicits) == 0) { in inet6_set_iftoken()
5904 return -EINVAL; in inet6_set_iftoken()
5907 write_lock_bh(&idev->lock); in inet6_set_iftoken()
5909 BUILD_BUG_ON(sizeof(token->s6_addr) != 16); in inet6_set_iftoken()
5910 memcpy(idev->token.s6_addr + 8, token->s6_addr + 8, 8); in inet6_set_iftoken()
5912 write_unlock_bh(&idev->lock); in inet6_set_iftoken()
5918 if (!idev->dead && (idev->if_flags & IF_READY) && in inet6_set_iftoken()
5929 write_lock_bh(&idev->lock); in inet6_set_iftoken()
5932 idev->if_flags |= IF_RS_SENT; in inet6_set_iftoken()
5933 idev->rs_interval = rfc3315_s14_backoff_init( in inet6_set_iftoken()
5934 READ_ONCE(idev->cnf.rtr_solicit_interval)); in inet6_set_iftoken()
5935 idev->rs_probes = 1; in inet6_set_iftoken()
5936 addrconf_mod_rs_timer(idev, idev->rs_interval); in inet6_set_iftoken()
5940 list_for_each_entry(ifp, &idev->addr_list, if_list) { in inet6_set_iftoken()
5941 spin_lock(&ifp->lock); in inet6_set_iftoken()
5942 if (ifp->tokenized) { in inet6_set_iftoken()
5943 ifp->valid_lft = 0; in inet6_set_iftoken()
5944 ifp->prefered_lft = 0; in inet6_set_iftoken()
5946 spin_unlock(&ifp->lock); in inet6_set_iftoken()
5949 write_unlock_bh(&idev->lock); in inet6_set_iftoken()
5969 return -EINVAL; in check_addr_gen_mode()
5977 !idev->cnf.stable_secret.initialized && in check_stable_privacy()
5978 !net->ipv6.devconf_dflt->stable_secret.initialized) in check_stable_privacy()
5979 return -EINVAL; in check_stable_privacy()
5994 return -EAFNOSUPPORT; in inet6_validate_link_af()
6003 return -EINVAL; in inet6_validate_link_af()
6009 return -EINVAL; in inet6_validate_link_af()
6011 return -EINVAL; in inet6_validate_link_af()
6025 return -EAFNOSUPPORT; in inet6_set_link_af()
6028 return -EINVAL; in inet6_set_link_af()
6040 WRITE_ONCE(idev->cnf.addr_gen_mode, mode); in inet6_set_link_af()
6049 struct net_device *dev = idev->dev; in inet6_fill_ifinfo()
6057 return -EMSGSIZE; in inet6_fill_ifinfo()
6060 hdr->ifi_family = AF_INET6; in inet6_fill_ifinfo()
6061 hdr->__ifi_pad = 0; in inet6_fill_ifinfo()
6062 hdr->ifi_type = dev->type; in inet6_fill_ifinfo()
6063 ifindex = READ_ONCE(dev->ifindex); in inet6_fill_ifinfo()
6064 hdr->ifi_index = ifindex; in inet6_fill_ifinfo()
6065 hdr->ifi_flags = dev_get_flags(dev); in inet6_fill_ifinfo()
6066 hdr->ifi_change = 0; in inet6_fill_ifinfo()
6069 if (nla_put_string(skb, IFLA_IFNAME, dev->name) || in inet6_fill_ifinfo()
6070 (dev->addr_len && in inet6_fill_ifinfo()
6071 nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || in inet6_fill_ifinfo()
6072 nla_put_u32(skb, IFLA_MTU, READ_ONCE(dev->mtu)) || in inet6_fill_ifinfo()
6076 netif_running(dev) ? READ_ONCE(dev->operstate) : IF_OPER_DOWN)) in inet6_fill_ifinfo()
6091 return -EMSGSIZE; in inet6_fill_ifinfo()
6099 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in inet6_valid_dump_ifinfo()
6101 return -EINVAL; in inet6_valid_dump_ifinfo()
6106 return -EINVAL; in inet6_valid_dump_ifinfo()
6110 if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || in inet6_valid_dump_ifinfo()
6111 ifm->ifi_change || ifm->ifi_index) { in inet6_valid_dump_ifinfo()
6113 return -EINVAL; in inet6_valid_dump_ifinfo()
6121 struct net *net = sock_net(skb->sk); in inet6_dump_ifinfo()
6124 } *ctx = (void *)cb->ctx; in inet6_dump_ifinfo()
6132 if (cb->strict_check) { in inet6_dump_ifinfo()
6133 err = inet6_valid_dump_ifinfo(cb->nlh, cb->extack); in inet6_dump_ifinfo()
6141 for_each_netdev_dump(net, dev, ctx->ifindex) { in inet6_dump_ifinfo()
6146 NETLINK_CB(cb->skb).portid, in inet6_dump_ifinfo()
6147 cb->nlh->nlmsg_seq, in inet6_dump_ifinfo()
6160 struct net *net = dev_net(idev->dev); in inet6_ifinfo_notify()
6161 int err = -ENOBUFS; in inet6_ifinfo_notify()
6169 /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */ in inet6_ifinfo_notify()
6170 WARN_ON(err == -EMSGSIZE); in inet6_ifinfo_notify()
6197 return -EMSGSIZE; in inet6_fill_prefix()
6200 pmsg->prefix_family = AF_INET6; in inet6_fill_prefix()
6201 pmsg->prefix_pad1 = 0; in inet6_fill_prefix()
6202 pmsg->prefix_pad2 = 0; in inet6_fill_prefix()
6203 pmsg->prefix_ifindex = idev->dev->ifindex; in inet6_fill_prefix()
6204 pmsg->prefix_len = pinfo->prefix_len; in inet6_fill_prefix()
6205 pmsg->prefix_type = pinfo->type; in inet6_fill_prefix()
6206 pmsg->prefix_pad3 = 0; in inet6_fill_prefix()
6207 pmsg->prefix_flags = pinfo->flags; in inet6_fill_prefix()
6209 if (nla_put(skb, PREFIX_ADDRESS, sizeof(pinfo->prefix), &pinfo->prefix)) in inet6_fill_prefix()
6211 ci.preferred_time = ntohl(pinfo->prefered); in inet6_fill_prefix()
6212 ci.valid_time = ntohl(pinfo->valid); in inet6_fill_prefix()
6220 return -EMSGSIZE; in inet6_fill_prefix()
6227 struct net *net = dev_net(idev->dev); in inet6_prefix_notify()
6228 int err = -ENOBUFS; in inet6_prefix_notify()
6236 /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */ in inet6_prefix_notify()
6237 WARN_ON(err == -EMSGSIZE); in inet6_prefix_notify()
6249 struct net *net = dev_net(ifp->idev->dev); in __ipv6_ifa_notify()
6259 * If the address was optimistic we inserted the route at the in __ipv6_ifa_notify()
6263 * host route, so nothing to insert. That will be fixed when in __ipv6_ifa_notify()
6266 if (ifp->rt && !rcu_access_pointer(ifp->rt->fib6_node)) { in __ipv6_ifa_notify()
6267 ip6_ins_rt(net, ifp->rt); in __ipv6_ifa_notify()
6268 } else if (!ifp->rt && (ifp->idev->dev->flags & IFF_UP)) { in __ipv6_ifa_notify()
6269 pr_warn("BUG: Address %pI6c on device %s is missing its host route.\n", in __ipv6_ifa_notify()
6270 &ifp->addr, ifp->idev->dev->name); in __ipv6_ifa_notify()
6273 if (ifp->idev->cnf.forwarding) in __ipv6_ifa_notify()
6275 if (!ipv6_addr_any(&ifp->peer_addr)) in __ipv6_ifa_notify()
6276 addrconf_prefix_route(&ifp->peer_addr, 128, in __ipv6_ifa_notify()
6277 ifp->rt_priority, ifp->idev->dev, in __ipv6_ifa_notify()
6281 if (ifp->idev->cnf.forwarding) in __ipv6_ifa_notify()
6283 addrconf_leave_solict(ifp->idev, &ifp->addr); in __ipv6_ifa_notify()
6284 if (!ipv6_addr_any(&ifp->peer_addr)) { in __ipv6_ifa_notify()
6287 rt = addrconf_get_prefix_route(&ifp->peer_addr, 128, in __ipv6_ifa_notify()
6288 ifp->idev->dev, 0, 0, in __ipv6_ifa_notify()
6293 if (ifp->rt) { in __ipv6_ifa_notify()
6294 ip6_del_rt(net, ifp->rt, false); in __ipv6_ifa_notify()
6295 ifp->rt = NULL; in __ipv6_ifa_notify()
6300 atomic_inc(&net->ipv6.dev_addr_genid); in __ipv6_ifa_notify()
6305 if (likely(ifp->idev->dead == 0)) in ipv6_ifa_notify()
6314 int *valp = ctl->data; in addrconf_sysctl_forward()
6321 * ctl->data points to idev->cnf.forwarding, we should in addrconf_sysctl_forward()
6339 struct inet6_dev *idev = ctl->extra1; in addrconf_sysctl_mtu()
6345 lctl.extra2 = idev ? &idev->dev->mtu : NULL; in addrconf_sysctl_mtu()
6354 if (!idev || !idev->dev) in dev_disable_change()
6357 netdev_notifier_info_init(&info, idev->dev); in dev_disable_change()
6358 if (idev->cnf.disable_ipv6) in dev_disable_change()
6372 int changed = (!idev->cnf.disable_ipv6) ^ (!newf); in addrconf_disable_change()
6374 WRITE_ONCE(idev->cnf.disable_ipv6, newf); in addrconf_disable_change()
6383 struct net *net = (struct net *)table->extra2; in addrconf_disable_ipv6()
6386 if (p == &net->ipv6.devconf_dflt->disable_ipv6) { in addrconf_disable_ipv6()
6397 if (p == &net->ipv6.devconf_all->disable_ipv6) { in addrconf_disable_ipv6()
6398 WRITE_ONCE(net->ipv6.devconf_dflt->disable_ipv6, newf); in addrconf_disable_ipv6()
6401 dev_disable_change((struct inet6_dev *)table->extra1); in addrconf_disable_ipv6()
6410 int *valp = ctl->data; in addrconf_sysctl_disable()
6417 * ctl->data points to idev->cnf.disable_ipv6, we should in addrconf_sysctl_disable()
6435 int *valp = ctl->data; in addrconf_sysctl_proxy_ndp()
6444 struct net *net = ctl->extra2; in addrconf_sysctl_proxy_ndp()
6449 if (valp == &net->ipv6.devconf_dflt->proxy_ndp) in addrconf_sysctl_proxy_ndp()
6453 net->ipv6.devconf_dflt); in addrconf_sysctl_proxy_ndp()
6454 else if (valp == &net->ipv6.devconf_all->proxy_ndp) in addrconf_sysctl_proxy_ndp()
6458 net->ipv6.devconf_all); in addrconf_sysctl_proxy_ndp()
6460 struct inet6_dev *idev = ctl->extra1; in addrconf_sysctl_proxy_ndp()
6464 idev->dev->ifindex, in addrconf_sysctl_proxy_ndp()
6465 &idev->cnf); in addrconf_sysctl_proxy_ndp()
6479 struct inet6_dev *idev = (struct inet6_dev *)ctl->extra1; in addrconf_sysctl_addr_gen_mode()
6480 struct net *net = (struct net *)ctl->extra2; in addrconf_sysctl_addr_gen_mode()
6484 .mode = ctl->mode, in addrconf_sysctl_addr_gen_mode()
6490 new_val = *((u32 *)ctl->data); in addrconf_sysctl_addr_gen_mode()
6498 ret = -EINVAL; in addrconf_sysctl_addr_gen_mode()
6504 ret = -EINVAL; in addrconf_sysctl_addr_gen_mode()
6508 if (idev->cnf.addr_gen_mode != new_val) { in addrconf_sysctl_addr_gen_mode()
6509 WRITE_ONCE(idev->cnf.addr_gen_mode, new_val); in addrconf_sysctl_addr_gen_mode()
6510 addrconf_init_auto_addrs(idev->dev); in addrconf_sysctl_addr_gen_mode()
6512 } else if (&net->ipv6.devconf_all->addr_gen_mode == ctl->data) { in addrconf_sysctl_addr_gen_mode()
6515 WRITE_ONCE(net->ipv6.devconf_dflt->addr_gen_mode, new_val); in addrconf_sysctl_addr_gen_mode()
6519 idev->cnf.addr_gen_mode != new_val) { in addrconf_sysctl_addr_gen_mode()
6520 WRITE_ONCE(idev->cnf.addr_gen_mode, in addrconf_sysctl_addr_gen_mode()
6522 addrconf_init_auto_addrs(idev->dev); in addrconf_sysctl_addr_gen_mode()
6527 WRITE_ONCE(*((u32 *)ctl->data), new_val); in addrconf_sysctl_addr_gen_mode()
6544 struct net *net = ctl->extra2; in addrconf_sysctl_stable_secret()
6545 struct ipv6_stable_secret *secret = ctl->data; in addrconf_sysctl_stable_secret()
6547 if (&net->ipv6.devconf_all->stable_secret == ctl->data) in addrconf_sysctl_stable_secret()
6548 return -EIO; in addrconf_sysctl_stable_secret()
6556 if (!write && !secret->initialized) { in addrconf_sysctl_stable_secret()
6557 err = -EIO; in addrconf_sysctl_stable_secret()
6561 err = snprintf(str, sizeof(str), "%pI6", &secret->secret); in addrconf_sysctl_stable_secret()
6563 err = -EIO; in addrconf_sysctl_stable_secret()
6571 if (in6_pton(str, -1, addr.in6_u.u6_addr8, -1, NULL) != 1) { in addrconf_sysctl_stable_secret()
6572 err = -EIO; in addrconf_sysctl_stable_secret()
6576 secret->initialized = true; in addrconf_sysctl_stable_secret()
6577 secret->secret = addr; in addrconf_sysctl_stable_secret()
6579 if (&net->ipv6.devconf_dflt->stable_secret == ctl->data) { in addrconf_sysctl_stable_secret()
6586 WRITE_ONCE(idev->cnf.addr_gen_mode, in addrconf_sysctl_stable_secret()
6591 struct inet6_dev *idev = ctl->extra1; in addrconf_sysctl_stable_secret()
6593 WRITE_ONCE(idev->cnf.addr_gen_mode, in addrconf_sysctl_stable_secret()
6609 int *valp = ctl->data; in addrconf_sysctl_ignore_routes_with_linkdown()
6615 /* ctl->data points to idev->cnf.ignore_routes_when_linkdown in addrconf_sysctl_ignore_routes_with_linkdown()
6635 rt->dst.flags |= DST_NOPOLICY; in addrconf_set_nopolicy()
6637 rt->dst.flags &= ~DST_NOPOLICY; in addrconf_set_nopolicy()
6646 read_lock_bh(&idev->lock); in addrconf_disable_policy_idev()
6647 list_for_each_entry(ifa, &idev->addr_list, if_list) { in addrconf_disable_policy_idev()
6648 spin_lock(&ifa->lock); in addrconf_disable_policy_idev()
6649 if (ifa->rt) { in addrconf_disable_policy_idev()
6651 struct fib6_nh *nh = ifa->rt->fib6_nh; in addrconf_disable_policy_idev()
6655 ifa->rt->dst_nopolicy = val ? true : false; in addrconf_disable_policy_idev()
6656 if (nh->rt6i_pcpu) { in addrconf_disable_policy_idev()
6660 rtp = per_cpu_ptr(nh->rt6i_pcpu, cpu); in addrconf_disable_policy_idev()
6666 spin_unlock(&ifa->lock); in addrconf_disable_policy_idev()
6668 read_unlock_bh(&idev->lock); in addrconf_disable_policy_idev()
6674 struct net *net = (struct net *)ctl->extra2; in addrconf_disable_policy()
6677 if (valp == &net->ipv6.devconf_dflt->disable_policy) { in addrconf_disable_policy()
6687 if (valp == &net->ipv6.devconf_all->disable_policy) { in addrconf_disable_policy()
6696 idev = (struct inet6_dev *)ctl->extra1; in addrconf_disable_policy()
6707 int *valp = ctl->data; in addrconf_sysctl_disable_policy()
6726 static int minus_one = -1;
7211 table[i].data += (char *)p - (char *)&ipv6_devconf; in __addrconf_sysctl_register()
7224 p->sysctl_header = register_net_sysctl_sz(net, path, table, in __addrconf_sysctl_register()
7226 if (!p->sysctl_header) in __addrconf_sysctl_register()
7234 ifindex = idev->dev->ifindex; in __addrconf_sysctl_register()
7242 return -ENOBUFS; in __addrconf_sysctl_register()
7250 if (!p->sysctl_header) in __addrconf_sysctl_unregister()
7253 table = p->sysctl_header->ctl_table_arg; in __addrconf_sysctl_unregister()
7254 unregister_net_sysctl_table(p->sysctl_header); in __addrconf_sysctl_unregister()
7255 p->sysctl_header = NULL; in __addrconf_sysctl_unregister()
7265 if (!sysctl_dev_name_is_allowed(idev->dev->name)) in addrconf_sysctl_register()
7266 return -EINVAL; in addrconf_sysctl_register()
7268 err = neigh_sysctl_register(idev->dev, idev->nd_parms, in addrconf_sysctl_register()
7272 err = __addrconf_sysctl_register(dev_net(idev->dev), idev->dev->name, in addrconf_sysctl_register()
7273 idev, &idev->cnf); in addrconf_sysctl_register()
7275 neigh_sysctl_unregister(idev->nd_parms); in addrconf_sysctl_register()
7282 __addrconf_sysctl_unregister(dev_net(idev->dev), &idev->cnf, in addrconf_sysctl_unregister()
7283 idev->dev->ifindex); in addrconf_sysctl_unregister()
7284 neigh_sysctl_unregister(idev->nd_parms); in addrconf_sysctl_unregister()
7292 int err = -ENOMEM; in addrconf_init_net()
7295 spin_lock_init(&net->ipv6.addrconf_hash_lock); in addrconf_init_net()
7296 INIT_DEFERRABLE_WORK(&net->ipv6.addr_chk_work, addrconf_verify_work); in addrconf_init_net()
7297 net->ipv6.inet6_addr_lst = kcalloc(IN6_ADDR_HSIZE, in addrconf_init_net()
7300 if (!net->ipv6.inet6_addr_lst) in addrconf_init_net()
7320 memcpy(all, current->nsproxy->net_ns->ipv6.devconf_all, in addrconf_init_net()
7323 current->nsproxy->net_ns->ipv6.devconf_dflt, in addrconf_init_net()
7334 dflt->autoconf = ipv6_defaults.autoconf; in addrconf_init_net()
7335 dflt->disable_ipv6 = ipv6_defaults.disable_ipv6; in addrconf_init_net()
7337 dflt->stable_secret.initialized = false; in addrconf_init_net()
7338 all->stable_secret.initialized = false; in addrconf_init_net()
7340 net->ipv6.devconf_all = all; in addrconf_init_net()
7341 net->ipv6.devconf_dflt = dflt; in addrconf_init_net()
7359 net->ipv6.devconf_dflt = NULL; in addrconf_init_net()
7363 net->ipv6.devconf_all = NULL; in addrconf_init_net()
7365 kfree(net->ipv6.inet6_addr_lst); in addrconf_init_net()
7375 __addrconf_sysctl_unregister(net, net->ipv6.devconf_dflt, in addrconf_exit_net()
7377 __addrconf_sysctl_unregister(net, net->ipv6.devconf_all, in addrconf_exit_net()
7380 kfree(net->ipv6.devconf_dflt); in addrconf_exit_net()
7381 net->ipv6.devconf_dflt = NULL; in addrconf_exit_net()
7382 kfree(net->ipv6.devconf_all); in addrconf_exit_net()
7383 net->ipv6.devconf_all = NULL; in addrconf_exit_net()
7385 cancel_delayed_work_sync(&net->ipv6.addr_chk_work); in addrconf_exit_net()
7390 WARN_ON_ONCE(!hlist_empty(&net->ipv6.inet6_addr_lst[i])); in addrconf_exit_net()
7392 kfree(net->ipv6.inet6_addr_lst); in addrconf_exit_net()
7393 net->ipv6.inet6_addr_lst = NULL; in addrconf_exit_net()
7432 err = -ENOMEM; in addrconf_init()