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()
304 if (del_timer(&idev->rs_timer)) in addrconf_del_rs_timer()
310 if (cancel_delayed_work(&ifp->dad_work)) in addrconf_del_dad_work()
317 if (!timer_pending(&idev->rs_timer)) in addrconf_mod_rs_timer()
319 mod_timer(&idev->rs_timer, jiffies + when); in addrconf_mod_rs_timer()
326 if (mod_delayed_work(addrconf_wq, &ifp->dad_work, delay)) in addrconf_mod_dad_work()
334 idev->stats.ipv6 = alloc_percpu(struct ipstats_mib); in snmp6_alloc_dev()
335 if (!idev->stats.ipv6) in snmp6_alloc_dev()
340 addrconf_stats = per_cpu_ptr(idev->stats.ipv6, i); in snmp6_alloc_dev()
341 u64_stats_init(&addrconf_stats->syncp); in snmp6_alloc_dev()
345 idev->stats.icmpv6dev = kzalloc(sizeof(struct icmpv6_mib_device), in snmp6_alloc_dev()
347 if (!idev->stats.icmpv6dev) in snmp6_alloc_dev()
349 idev->stats.icmpv6msgdev = kzalloc(sizeof(struct icmpv6msg_mib_device), in snmp6_alloc_dev()
351 if (!idev->stats.icmpv6msgdev) in snmp6_alloc_dev()
357 kfree(idev->stats.icmpv6dev); in snmp6_alloc_dev()
359 free_percpu(idev->stats.ipv6); in snmp6_alloc_dev()
361 return -ENOMEM; in snmp6_alloc_dev()
367 int err = -ENOMEM; in ipv6_add_dev()
371 if (dev->mtu < IPV6_MIN_MTU) in ipv6_add_dev()
372 return ERR_PTR(-EINVAL); in ipv6_add_dev()
378 rwlock_init(&ndev->lock); in ipv6_add_dev()
379 ndev->dev = dev; in ipv6_add_dev()
380 INIT_LIST_HEAD(&ndev->addr_list); in ipv6_add_dev()
381 timer_setup(&ndev->rs_timer, addrconf_rs_timer, 0); in ipv6_add_dev()
382 memcpy(&ndev->cnf, dev_net(dev)->ipv6.devconf_dflt, sizeof(ndev->cnf)); in ipv6_add_dev()
384 if (ndev->cnf.stable_secret.initialized) in ipv6_add_dev()
385 ndev->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_STABLE_PRIVACY; in ipv6_add_dev()
387 ndev->cnf.mtu6 = dev->mtu; in ipv6_add_dev()
388 ndev->nd_parms = neigh_parms_alloc(dev, &nd_tbl); in ipv6_add_dev()
389 if (!ndev->nd_parms) { in ipv6_add_dev()
393 if (ndev->cnf.forwarding) in ipv6_add_dev()
401 neigh_parms_release(&nd_tbl, ndev->nd_parms); in ipv6_add_dev()
409 __func__, dev->name); in ipv6_add_dev()
414 refcount_set(&ndev->refcnt, 1); in ipv6_add_dev()
416 if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) in ipv6_add_dev()
417 ndev->cnf.accept_dad = -1; in ipv6_add_dev()
420 if (dev->type == ARPHRD_SIT && (dev->priv_flags & IFF_ISATAP)) { in ipv6_add_dev()
421 pr_info("%s: Disabled Multicast RS\n", dev->name); in ipv6_add_dev()
422 ndev->cnf.rtr_solicits = 0; in ipv6_add_dev()
426 INIT_LIST_HEAD(&ndev->tempaddr_list); in ipv6_add_dev()
427 ndev->desync_factor = U32_MAX; in ipv6_add_dev()
428 if ((dev->flags&IFF_LOOPBACK) || in ipv6_add_dev()
429 dev->type == ARPHRD_TUNNEL || in ipv6_add_dev()
430 dev->type == ARPHRD_TUNNEL6 || in ipv6_add_dev()
431 dev->type == ARPHRD_SIT || in ipv6_add_dev()
432 dev->type == ARPHRD_NONE) { in ipv6_add_dev()
433 ndev->cnf.use_tempaddr = -1; in ipv6_add_dev()
436 ndev->token = in6addr_any; in ipv6_add_dev()
439 ndev->if_flags |= IF_READY; in ipv6_add_dev()
442 ndev->tstamp = jiffies; in ipv6_add_dev()
450 rcu_assign_pointer(dev->ip6_ptr, ndev); in ipv6_add_dev()
452 /* Join interface-local all-node multicast group */ in ipv6_add_dev()
455 /* Join all-node multicast group */ in ipv6_add_dev()
458 /* Join all-router multicast group if forwarding is set */ in ipv6_add_dev()
459 if (ndev->cnf.forwarding && (dev->flags & IFF_MULTICAST)) in ipv6_add_dev()
465 neigh_parms_release(&nd_tbl, ndev->nd_parms); in ipv6_add_dev()
466 ndev->dead = 1; in ipv6_add_dev()
484 if (dev->flags&IFF_UP) in ipv6_find_idev()
525 return -EMSGSIZE; in inet6_netconf_fill_devconf()
531 ncm->ncm_family = AF_INET6; in inet6_netconf_fill_devconf()
540 nla_put_s32(skb, NETCONFA_FORWARDING, devconf->forwarding) < 0) in inet6_netconf_fill_devconf()
545 devconf->mc_forwarding) < 0) in inet6_netconf_fill_devconf()
549 nla_put_s32(skb, NETCONFA_PROXY_NEIGH, devconf->proxy_ndp) < 0) in inet6_netconf_fill_devconf()
554 devconf->ignore_routes_with_linkdown) < 0) in inet6_netconf_fill_devconf()
563 return -EMSGSIZE; in inet6_netconf_fill_devconf()
570 int err = -ENOBUFS; in inet6_netconf_notify_devconf()
579 /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */ in inet6_netconf_notify_devconf()
580 WARN_ON(err == -EMSGSIZE); in inet6_netconf_notify_devconf()
604 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(struct netconfmsg))) { in inet6_netconf_valid_get_req()
606 return -EINVAL; in inet6_netconf_valid_get_req()
629 return -EINVAL; in inet6_netconf_valid_get_req()
640 struct net *net = sock_net(in_skb->sk); in inet6_netconf_get_devconf()
654 return -EINVAL; in inet6_netconf_get_devconf()
656 err = -EINVAL; in inet6_netconf_get_devconf()
660 devconf = net->ipv6.devconf_all; in inet6_netconf_get_devconf()
663 devconf = net->ipv6.devconf_dflt; in inet6_netconf_get_devconf()
668 return -EINVAL; in inet6_netconf_get_devconf()
672 devconf = &in6_dev->cnf; in inet6_netconf_get_devconf()
676 err = -ENOBUFS; in inet6_netconf_get_devconf()
683 nlh->nlmsg_seq, RTM_NEWNETCONF, 0, in inet6_netconf_get_devconf()
686 /* -EMSGSIZE implies BUG in inet6_netconf_msgsize_devconf() */ in inet6_netconf_get_devconf()
687 WARN_ON(err == -EMSGSIZE); in inet6_netconf_get_devconf()
703 const struct nlmsghdr *nlh = cb->nlh; in inet6_netconf_dump_devconf()
704 struct net *net = sock_net(skb->sk); in inet6_netconf_dump_devconf()
711 if (cb->strict_check) { in inet6_netconf_dump_devconf()
712 struct netlink_ext_ack *extack = cb->extack; in inet6_netconf_dump_devconf()
715 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ncm))) { in inet6_netconf_dump_devconf()
717 return -EINVAL; in inet6_netconf_dump_devconf()
722 return -EINVAL; in inet6_netconf_dump_devconf()
726 s_h = cb->args[0]; in inet6_netconf_dump_devconf()
727 s_idx = idx = cb->args[1]; in inet6_netconf_dump_devconf()
731 head = &net->dev_index_head[h]; in inet6_netconf_dump_devconf()
733 cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ in inet6_netconf_dump_devconf()
734 net->dev_base_seq; in inet6_netconf_dump_devconf()
742 if (inet6_netconf_fill_devconf(skb, dev->ifindex, in inet6_netconf_dump_devconf()
743 &idev->cnf, in inet6_netconf_dump_devconf()
744 NETLINK_CB(cb->skb).portid, in inet6_netconf_dump_devconf()
745 nlh->nlmsg_seq, in inet6_netconf_dump_devconf()
760 net->ipv6.devconf_all, in inet6_netconf_dump_devconf()
761 NETLINK_CB(cb->skb).portid, in inet6_netconf_dump_devconf()
762 nlh->nlmsg_seq, in inet6_netconf_dump_devconf()
771 net->ipv6.devconf_dflt, in inet6_netconf_dump_devconf()
772 NETLINK_CB(cb->skb).portid, in inet6_netconf_dump_devconf()
773 nlh->nlmsg_seq, in inet6_netconf_dump_devconf()
781 cb->args[0] = h; in inet6_netconf_dump_devconf()
782 cb->args[1] = idx; in inet6_netconf_dump_devconf()
784 return skb->len; in inet6_netconf_dump_devconf()
795 dev = idev->dev; in dev_forward_change()
796 if (idev->cnf.forwarding) in dev_forward_change()
798 if (dev->flags & IFF_MULTICAST) { in dev_forward_change()
799 if (idev->cnf.forwarding) { in dev_forward_change()
810 list_for_each_entry(ifa, &idev->addr_list, if_list) { in dev_forward_change()
811 if (ifa->flags&IFA_F_TENTATIVE) in dev_forward_change()
813 if (idev->cnf.forwarding) in dev_forward_change()
820 dev->ifindex, &idev->cnf); in dev_forward_change()
832 int changed = (!idev->cnf.forwarding) ^ (!newf); in addrconf_forward_change()
833 idev->cnf.forwarding = newf; in addrconf_forward_change()
848 net = (struct net *)table->extra2; in addrconf_fixup_forwarding()
852 if (p == &net->ipv6.devconf_dflt->forwarding) { in addrconf_fixup_forwarding()
857 net->ipv6.devconf_dflt); in addrconf_fixup_forwarding()
862 if (p == &net->ipv6.devconf_all->forwarding) { in addrconf_fixup_forwarding()
863 int old_dflt = net->ipv6.devconf_dflt->forwarding; in addrconf_fixup_forwarding()
865 net->ipv6.devconf_dflt->forwarding = newf; in addrconf_fixup_forwarding()
870 net->ipv6.devconf_dflt); in addrconf_fixup_forwarding()
877 net->ipv6.devconf_all); in addrconf_fixup_forwarding()
879 dev_forward_change((struct inet6_dev *)table->extra1); in addrconf_fixup_forwarding()
895 int changed = (!idev->cnf.ignore_routes_with_linkdown) ^ (!newf); in addrconf_linkdown_change()
897 idev->cnf.ignore_routes_with_linkdown = newf; in addrconf_linkdown_change()
902 dev->ifindex, in addrconf_linkdown_change()
903 &idev->cnf); in addrconf_linkdown_change()
916 net = (struct net *)table->extra2; in addrconf_fixup_linkdown()
920 if (p == &net->ipv6.devconf_dflt->ignore_routes_with_linkdown) { in addrconf_fixup_linkdown()
926 net->ipv6.devconf_dflt); in addrconf_fixup_linkdown()
931 if (p == &net->ipv6.devconf_all->ignore_routes_with_linkdown) { in addrconf_fixup_linkdown()
932 net->ipv6.devconf_dflt->ignore_routes_with_linkdown = newf; in addrconf_fixup_linkdown()
939 net->ipv6.devconf_all); in addrconf_fixup_linkdown()
951 WARN_ON(!hlist_unhashed(&ifp->addr_lst)); in inet6_ifa_finish_destroy()
957 in6_dev_put(ifp->idev); in inet6_ifa_finish_destroy()
959 if (cancel_delayed_work(&ifp->dad_work)) in inet6_ifa_finish_destroy()
963 if (ifp->state != INET6_IFADDR_STATE_DEAD) { in inet6_ifa_finish_destroy()
975 int ifp_scope = ipv6_addr_src_scope(&ifp->addr); in ipv6_link_dev_addr()
978 * Each device address list is sorted in order of scope - in ipv6_link_dev_addr()
981 list_for_each(p, &idev->addr_list) { in ipv6_link_dev_addr()
984 if (ifp_scope >= ipv6_addr_src_scope(&ifa->addr)) in ipv6_link_dev_addr()
988 list_add_tail_rcu(&ifp->if_list, p); in ipv6_link_dev_addr()
1004 if (!net_eq(dev_net(ifp->idev->dev), net)) in ipv6_chk_same_addr()
1006 if (ipv6_addr_equal(&ifp->addr, addr)) { in ipv6_chk_same_addr()
1007 if (!dev || ifp->idev->dev == dev) in ipv6_chk_same_addr()
1016 unsigned int hash = inet6_addr_hash(dev_net(dev), &ifa->addr); in ipv6_add_addr_hash()
1022 if (ipv6_chk_same_addr(dev_net(dev), &ifa->addr, dev, hash)) { in ipv6_add_addr_hash()
1024 err = -EEXIST; in ipv6_add_addr_hash()
1026 hlist_add_head_rcu(&ifa->addr_lst, &inet6_addr_lst[hash]); in ipv6_add_addr_hash()
1041 int addr_type = ipv6_addr_type(cfg->pfx); in ipv6_add_addr()
1042 struct net *net = dev_net(idev->dev); in ipv6_add_addr()
1049 !(cfg->ifa_flags & IFA_F_MCAUTOJOIN)) || in ipv6_add_addr()
1050 (!(idev->dev->flags & IFF_LOOPBACK) && in ipv6_add_addr()
1051 !netif_is_l3_master(idev->dev) && in ipv6_add_addr()
1053 return ERR_PTR(-EADDRNOTAVAIL); in ipv6_add_addr()
1055 if (idev->dead) { in ipv6_add_addr()
1056 err = -ENODEV; /*XXX*/ in ipv6_add_addr()
1060 if (idev->cnf.disable_ipv6) { in ipv6_add_addr()
1061 err = -EACCES; in ipv6_add_addr()
1070 .i6vi_addr = *cfg->pfx, in ipv6_add_addr()
1083 err = -ENOBUFS; in ipv6_add_addr()
1087 f6i = addrconf_f6i_alloc(net, idev, cfg->pfx, false, gfp_flags); in ipv6_add_addr()
1094 if (net->ipv6.devconf_all->disable_policy || in ipv6_add_addr()
1095 idev->cnf.disable_policy) in ipv6_add_addr()
1096 f6i->dst_nopolicy = true; in ipv6_add_addr()
1098 neigh_parms_data_state_setall(idev->nd_parms); in ipv6_add_addr()
1100 ifa->addr = *cfg->pfx; in ipv6_add_addr()
1101 if (cfg->peer_pfx) in ipv6_add_addr()
1102 ifa->peer_addr = *cfg->peer_pfx; in ipv6_add_addr()
1104 spin_lock_init(&ifa->lock); in ipv6_add_addr()
1105 INIT_DELAYED_WORK(&ifa->dad_work, addrconf_dad_work); in ipv6_add_addr()
1106 INIT_HLIST_NODE(&ifa->addr_lst); in ipv6_add_addr()
1107 ifa->scope = cfg->scope; in ipv6_add_addr()
1108 ifa->prefix_len = cfg->plen; in ipv6_add_addr()
1109 ifa->rt_priority = cfg->rt_priority; in ipv6_add_addr()
1110 ifa->flags = cfg->ifa_flags; in ipv6_add_addr()
1112 if (!(cfg->ifa_flags & IFA_F_NODAD)) in ipv6_add_addr()
1113 ifa->flags |= IFA_F_TENTATIVE; in ipv6_add_addr()
1114 ifa->valid_lft = cfg->valid_lft; in ipv6_add_addr()
1115 ifa->prefered_lft = cfg->preferred_lft; in ipv6_add_addr()
1116 ifa->cstamp = ifa->tstamp = jiffies; in ipv6_add_addr()
1117 ifa->tokenized = false; in ipv6_add_addr()
1119 ifa->rt = f6i; in ipv6_add_addr()
1121 ifa->idev = idev; in ipv6_add_addr()
1125 refcount_set(&ifa->refcnt, 1); in ipv6_add_addr()
1129 err = ipv6_add_addr_hash(idev->dev, ifa); in ipv6_add_addr()
1135 write_lock(&idev->lock); in ipv6_add_addr()
1140 if (ifa->flags&IFA_F_TEMPORARY) { in ipv6_add_addr()
1141 list_add(&ifa->tmp_list, &idev->tempaddr_list); in ipv6_add_addr()
1146 write_unlock(&idev->lock); in ipv6_add_addr()
1156 if (ifa->idev) in ipv6_add_addr()
1157 in6_dev_put(ifa->idev); in ipv6_add_addr()
1167 CLEANUP_PREFIX_RT_NOP, /* no cleanup action for prefix route */
1168 CLEANUP_PREFIX_RT_DEL, /* delete the prefix route */
1169 CLEANUP_PREFIX_RT_EXPIRE, /* update the lifetime of the prefix route */
1173 * Check, whether the prefix for ifp would still need a prefix route
1194 struct inet6_dev *idev = ifp->idev; in check_cleanup_prefix_route()
1200 list_for_each_entry(ifa, &idev->addr_list, if_list) { in check_cleanup_prefix_route()
1203 if (ifa->prefix_len != ifp->prefix_len || in check_cleanup_prefix_route()
1204 !ipv6_prefix_equal(&ifa->addr, &ifp->addr, in check_cleanup_prefix_route()
1205 ifp->prefix_len)) in check_cleanup_prefix_route()
1207 if (ifa->flags & (IFA_F_PERMANENT | IFA_F_NOPREFIXROUTE)) in check_cleanup_prefix_route()
1212 spin_lock(&ifa->lock); in check_cleanup_prefix_route()
1214 lifetime = addrconf_timeout_fixup(ifa->valid_lft, HZ); in check_cleanup_prefix_route()
1220 if (time_before(*expires, ifa->tstamp + lifetime * HZ)) in check_cleanup_prefix_route()
1221 *expires = ifa->tstamp + lifetime * HZ; in check_cleanup_prefix_route()
1222 spin_unlock(&ifa->lock); in check_cleanup_prefix_route()
1234 f6i = addrconf_get_prefix_route(del_peer ? &ifp->peer_addr : &ifp->addr, in cleanup_prefix_route()
1235 ifp->prefix_len, in cleanup_prefix_route()
1236 ifp->idev->dev, 0, RTF_DEFAULT, true); in cleanup_prefix_route()
1239 ip6_del_rt(dev_net(ifp->idev->dev), f6i, false); in cleanup_prefix_route()
1241 if (!(f6i->fib6_flags & RTF_EXPIRES)) in cleanup_prefix_route()
1259 spin_lock_bh(&ifp->lock); in ipv6_del_addr()
1260 state = ifp->state; in ipv6_del_addr()
1261 ifp->state = INET6_IFADDR_STATE_DEAD; in ipv6_del_addr()
1262 spin_unlock_bh(&ifp->lock); in ipv6_del_addr()
1268 hlist_del_init_rcu(&ifp->addr_lst); in ipv6_del_addr()
1271 write_lock_bh(&ifp->idev->lock); in ipv6_del_addr()
1273 if (ifp->flags&IFA_F_TEMPORARY) { in ipv6_del_addr()
1274 list_del(&ifp->tmp_list); in ipv6_del_addr()
1275 if (ifp->ifpub) { in ipv6_del_addr()
1276 in6_ifa_put(ifp->ifpub); in ipv6_del_addr()
1277 ifp->ifpub = NULL; in ipv6_del_addr()
1282 if (ifp->flags & IFA_F_PERMANENT && !(ifp->flags & IFA_F_NOPREFIXROUTE)) in ipv6_del_addr()
1285 list_del_rcu(&ifp->if_list); in ipv6_del_addr()
1288 write_unlock_bh(&ifp->idev->lock); in ipv6_del_addr()
1309 struct inet6_dev *idev = ifp->idev; in ipv6_create_tempaddr()
1320 write_lock_bh(&idev->lock); in ipv6_create_tempaddr()
1324 if (idev->cnf.use_tempaddr <= 0) { in ipv6_create_tempaddr()
1325 write_unlock_bh(&idev->lock); in ipv6_create_tempaddr()
1328 ret = -1; in ipv6_create_tempaddr()
1331 spin_lock_bh(&ifp->lock); in ipv6_create_tempaddr()
1332 if (ifp->regen_count++ >= idev->cnf.regen_max_retry) { in ipv6_create_tempaddr()
1333 idev->cnf.use_tempaddr = -1; /*XXX*/ in ipv6_create_tempaddr()
1334 spin_unlock_bh(&ifp->lock); in ipv6_create_tempaddr()
1335 write_unlock_bh(&idev->lock); in ipv6_create_tempaddr()
1336 pr_warn("%s: regeneration time exceeded - disabled temporary address support\n", in ipv6_create_tempaddr()
1339 ret = -1; in ipv6_create_tempaddr()
1343 memcpy(addr.s6_addr, ifp->addr.s6_addr, 8); in ipv6_create_tempaddr()
1346 age = (now - ifp->tstamp) / HZ; in ipv6_create_tempaddr()
1348 regen_advance = idev->cnf.regen_max_retry * in ipv6_create_tempaddr()
1349 idev->cnf.dad_transmits * in ipv6_create_tempaddr()
1350 max(NEIGH_VAR(idev->nd_parms, RETRANS_TIME), HZ/100) / HZ; in ipv6_create_tempaddr()
1353 * idev->desync_factor if it's larger in ipv6_create_tempaddr()
1355 cnf_temp_preferred_lft = READ_ONCE(idev->cnf.temp_prefered_lft); in ipv6_create_tempaddr()
1357 idev->cnf.max_desync_factor, in ipv6_create_tempaddr()
1358 cnf_temp_preferred_lft - regen_advance); in ipv6_create_tempaddr()
1360 if (unlikely(idev->desync_factor > max_desync_factor)) { in ipv6_create_tempaddr()
1362 get_random_bytes(&idev->desync_factor, in ipv6_create_tempaddr()
1363 sizeof(idev->desync_factor)); in ipv6_create_tempaddr()
1364 idev->desync_factor %= max_desync_factor; in ipv6_create_tempaddr()
1366 idev->desync_factor = 0; in ipv6_create_tempaddr()
1371 cfg.valid_lft = min_t(__u32, ifp->valid_lft, in ipv6_create_tempaddr()
1372 idev->cnf.temp_valid_lft + age); in ipv6_create_tempaddr()
1373 cfg.preferred_lft = cnf_temp_preferred_lft + age - idev->desync_factor; in ipv6_create_tempaddr()
1374 cfg.preferred_lft = min_t(__u32, ifp->prefered_lft, cfg.preferred_lft); in ipv6_create_tempaddr()
1376 cfg.plen = ifp->prefix_len; in ipv6_create_tempaddr()
1377 tmp_tstamp = ifp->tstamp; in ipv6_create_tempaddr()
1378 spin_unlock_bh(&ifp->lock); in ipv6_create_tempaddr()
1380 write_unlock_bh(&idev->lock); in ipv6_create_tempaddr()
1389 age = (now - tmp_tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; in ipv6_create_tempaddr()
1393 ret = -1; in ipv6_create_tempaddr()
1399 if (ifp->flags & IFA_F_OPTIMISTIC) in ipv6_create_tempaddr()
1410 write_lock_bh(&idev->lock); in ipv6_create_tempaddr()
1414 spin_lock_bh(&ift->lock); in ipv6_create_tempaddr()
1415 ift->ifpub = ifp; in ipv6_create_tempaddr()
1416 ift->cstamp = now; in ipv6_create_tempaddr()
1417 ift->tstamp = tmp_tstamp; in ipv6_create_tempaddr()
1418 spin_unlock_bh(&ift->lock); in ipv6_create_tempaddr()
1479 if (!net->ipv6.devconf_all->optimistic_dad && !idev->cnf.optimistic_dad) in ipv6_use_optimistic_addr()
1481 if (!net->ipv6.devconf_all->use_optimistic && !idev->cnf.use_optimistic) in ipv6_use_optimistic_addr()
1496 if (!net->ipv6.devconf_all->optimistic_dad && !idev->cnf.optimistic_dad) in ipv6_allow_optimistic_dad()
1512 if (i <= score->rule) { in ipv6_get_saddr_eval()
1515 ret = score->scopedist; in ipv6_get_saddr_eval()
1518 ret = score->matchlen; in ipv6_get_saddr_eval()
1521 ret = !!test_bit(i, score->scorebits); in ipv6_get_saddr_eval()
1529 ret = !!score->ifa; in ipv6_get_saddr_eval()
1533 ret = ipv6_addr_equal(&score->ifa->addr, dst->addr); in ipv6_get_saddr_eval()
1540 * -1 | d 15 in ipv6_get_saddr_eval()
1541 * ---+--+-+---> scope in ipv6_get_saddr_eval()
1544 * B-d | \ in ipv6_get_saddr_eval()
1545 * | \ <- smaller scope is better if in ipv6_get_saddr_eval()
1546 * B-15 | \ if scope is enough for destination. in ipv6_get_saddr_eval()
1547 * | ret = B - scope (-1 <= scope >= d <= 15). in ipv6_get_saddr_eval()
1548 * d-C-1 | / in ipv6_get_saddr_eval()
1549 * |/ <- greater is better in ipv6_get_saddr_eval()
1550 * -C / if scope is not enough for destination. in ipv6_get_saddr_eval()
1551 * /| ret = scope - C (-1 <= d < scope <= 15). in ipv6_get_saddr_eval()
1553 * d - C - 1 < B -15 (for all -1 <= d <= 15). in ipv6_get_saddr_eval()
1554 * C > d + 14 - B >= 15 + 14 - B = 29 - B. in ipv6_get_saddr_eval()
1557 ret = __ipv6_addr_src_scope(score->addr_type); in ipv6_get_saddr_eval()
1558 if (ret >= dst->scope) in ipv6_get_saddr_eval()
1559 ret = -ret; in ipv6_get_saddr_eval()
1561 ret -= 128; /* 30 is enough */ in ipv6_get_saddr_eval()
1562 score->scopedist = ret; in ipv6_get_saddr_eval()
1569 if (!ipv6_use_optimistic_addr(net, score->ifa->idev)) in ipv6_get_saddr_eval()
1571 ret = ipv6_saddr_preferred(score->addr_type) || in ipv6_get_saddr_eval()
1572 !(score->ifa->flags & avoid); in ipv6_get_saddr_eval()
1579 int prefhome = !(dst->prefs & IPV6_PREFER_SRC_COA); in ipv6_get_saddr_eval()
1580 ret = !(score->ifa->flags & IFA_F_HOMEADDRESS) ^ prefhome; in ipv6_get_saddr_eval()
1586 ret = (!dst->ifindex || in ipv6_get_saddr_eval()
1587 dst->ifindex == score->ifa->idev->dev->ifindex); in ipv6_get_saddr_eval()
1592 &score->ifa->addr, score->addr_type, in ipv6_get_saddr_eval()
1593 score->ifa->idev->dev->ifindex) == dst->label; in ipv6_get_saddr_eval()
1600 int preftmp = dst->prefs & (IPV6_PREFER_SRC_PUBLIC|IPV6_PREFER_SRC_TMP) ? in ipv6_get_saddr_eval()
1601 !!(dst->prefs & IPV6_PREFER_SRC_TMP) : in ipv6_get_saddr_eval()
1602 score->ifa->idev->cnf.use_tempaddr >= 2; in ipv6_get_saddr_eval()
1603 ret = (!(score->ifa->flags & IFA_F_TEMPORARY)) ^ preftmp; in ipv6_get_saddr_eval()
1607 /* Rule 8-: Prefer ORCHID vs ORCHID or in ipv6_get_saddr_eval()
1608 * non-ORCHID vs non-ORCHID in ipv6_get_saddr_eval()
1610 ret = !(ipv6_addr_orchid(&score->ifa->addr) ^ in ipv6_get_saddr_eval()
1611 ipv6_addr_orchid(dst->addr)); in ipv6_get_saddr_eval()
1615 ret = ipv6_addr_diff(&score->ifa->addr, dst->addr); in ipv6_get_saddr_eval()
1616 if (ret > score->ifa->prefix_len) in ipv6_get_saddr_eval()
1617 ret = score->ifa->prefix_len; in ipv6_get_saddr_eval()
1618 score->matchlen = ret; in ipv6_get_saddr_eval()
1625 ret = !(score->ifa->flags & IFA_F_OPTIMISTIC); in ipv6_get_saddr_eval()
1633 __set_bit(i, score->scorebits); in ipv6_get_saddr_eval()
1634 score->rule = i; in ipv6_get_saddr_eval()
1645 struct ipv6_saddr_score *score = &scores[1 - hiscore_idx], *hiscore = &scores[hiscore_idx]; in __ipv6_dev_get_saddr()
1647 list_for_each_entry_rcu(score->ifa, &idev->addr_list, if_list) { in __ipv6_dev_get_saddr()
1651 * - Tentative Address (RFC2462 section 5.4) in __ipv6_dev_get_saddr()
1652 * - A tentative address is not considered in __ipv6_dev_get_saddr()
1655 * - Candidate Source Address (section 4) in __ipv6_dev_get_saddr()
1656 * - In any case, anycast addresses, multicast in __ipv6_dev_get_saddr()
1660 if ((score->ifa->flags & IFA_F_TENTATIVE) && in __ipv6_dev_get_saddr()
1661 (!(score->ifa->flags & IFA_F_OPTIMISTIC))) in __ipv6_dev_get_saddr()
1664 score->addr_type = __ipv6_addr_type(&score->ifa->addr); in __ipv6_dev_get_saddr()
1666 if (unlikely(score->addr_type == IPV6_ADDR_ANY || in __ipv6_dev_get_saddr()
1667 score->addr_type & IPV6_ADDR_MULTICAST)) { in __ipv6_dev_get_saddr()
1669 idev->dev->name); in __ipv6_dev_get_saddr()
1673 score->rule = -1; in __ipv6_dev_get_saddr()
1674 bitmap_zero(score->scorebits, IPV6_SADDR_RULE_MAX); in __ipv6_dev_get_saddr()
1684 score->scopedist > 0) { in __ipv6_dev_get_saddr()
1698 hiscore_idx = 1 - hiscore_idx; in __ipv6_dev_get_saddr()
1701 score->ifa = hiscore->ifa; in __ipv6_dev_get_saddr()
1748 dst.ifindex = dst_dev ? dst_dev->ifindex : 0; in ipv6_dev_get_saddr()
1753 scores[hiscore_idx].rule = -1; in ipv6_dev_get_saddr()
1759 * - multicast and link-local destination address, in ipv6_dev_get_saddr()
1764 * (- For site-local destination addresses, the in ipv6_dev_get_saddr()
1769 * - "It is RECOMMENDED that the candidate source addresses in ipv6_dev_get_saddr()
1778 (idev && idev->cnf.use_oif_addrs_only)) { in ipv6_dev_get_saddr()
1796 master_idx = master->ifindex; in ipv6_dev_get_saddr()
1821 if (!hiscore->ifa) in ipv6_dev_get_saddr()
1822 ret = -EADDRNOTAVAIL; in ipv6_dev_get_saddr()
1824 *saddr = hiscore->ifa->addr; in ipv6_dev_get_saddr()
1835 int err = -EADDRNOTAVAIL; in __ipv6_get_lladdr()
1837 list_for_each_entry_reverse(ifp, &idev->addr_list, if_list) { in __ipv6_get_lladdr()
1838 if (ifp->scope > IFA_LINK) in __ipv6_get_lladdr()
1840 if (ifp->scope == IFA_LINK && in __ipv6_get_lladdr()
1841 !(ifp->flags & banned_flags)) { in __ipv6_get_lladdr()
1842 *addr = ifp->addr; in __ipv6_get_lladdr()
1854 int err = -EADDRNOTAVAIL; in ipv6_get_lladdr()
1859 read_lock_bh(&idev->lock); in ipv6_get_lladdr()
1861 read_unlock_bh(&idev->lock); in ipv6_get_lladdr()
1873 list_for_each_entry_rcu(ifp, &idev->addr_list, if_list) in ipv6_count_addresses()
1913 ndev = ifp->idev->dev; in __ipv6_chk_addr_and_flags()
1923 ifp_flags = (ifp->flags&IFA_F_OPTIMISTIC) in __ipv6_chk_addr_and_flags()
1924 ? (ifp->flags&~IFA_F_TENTATIVE) in __ipv6_chk_addr_and_flags()
1925 : ifp->flags; in __ipv6_chk_addr_and_flags()
1926 if (ipv6_addr_equal(&ifp->addr, addr) && in __ipv6_chk_addr_and_flags()
1929 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict))) { in __ipv6_chk_addr_and_flags()
1962 list_for_each_entry_rcu(ifa, &idev->addr_list, if_list) { in ipv6_chk_custom_prefix()
1963 ret = ipv6_prefix_equal(addr, &ifa->addr, prefix_len); in ipv6_chk_custom_prefix()
1984 list_for_each_entry_rcu(ifa, &idev->addr_list, if_list) { in ipv6_chk_prefix()
1985 onlink = ipv6_prefix_equal(addr, &ifa->addr, in ipv6_chk_prefix()
1986 ifa->prefix_len); in ipv6_chk_prefix()
1997 * ipv6_dev_find - find the first device with a given source address.
2019 if (!net_eq(dev_net(ifp->idev->dev), net)) in ipv6_get_ifaddr()
2021 if (ipv6_addr_equal(&ifp->addr, addr)) { in ipv6_get_ifaddr()
2022 if (!dev || ifp->idev->dev == dev || in ipv6_get_ifaddr()
2023 !(ifp->scope&(IFA_LINK|IFA_HOST) || strict)) { in ipv6_get_ifaddr()
2040 ifp->flags |= IFA_F_DADFAILED; in addrconf_dad_stop()
2042 if (ifp->flags&IFA_F_TEMPORARY) { in addrconf_dad_stop()
2044 spin_lock_bh(&ifp->lock); in addrconf_dad_stop()
2045 ifpub = ifp->ifpub; in addrconf_dad_stop()
2048 spin_unlock_bh(&ifp->lock); in addrconf_dad_stop()
2052 spin_unlock_bh(&ifp->lock); in addrconf_dad_stop()
2055 } else if (ifp->flags&IFA_F_PERMANENT || !dad_failed) { in addrconf_dad_stop()
2056 spin_lock_bh(&ifp->lock); in addrconf_dad_stop()
2058 ifp->flags |= IFA_F_TENTATIVE; in addrconf_dad_stop()
2060 ifp->flags &= ~IFA_F_OPTIMISTIC; in addrconf_dad_stop()
2061 spin_unlock_bh(&ifp->lock); in addrconf_dad_stop()
2072 int err = -ENOENT; in addrconf_dad_end()
2074 spin_lock_bh(&ifp->lock); in addrconf_dad_end()
2075 if (ifp->state == INET6_IFADDR_STATE_DAD) { in addrconf_dad_end()
2076 ifp->state = INET6_IFADDR_STATE_POSTDAD; in addrconf_dad_end()
2079 spin_unlock_bh(&ifp->lock); in addrconf_dad_end()
2086 struct inet6_dev *idev = ifp->idev; in addrconf_dad_failure()
2087 struct net *net = dev_net(ifp->idev->dev); in addrconf_dad_failure()
2095 ifp->idev->dev->name, &ifp->addr, eth_hdr(skb)->h_source); in addrconf_dad_failure()
2097 spin_lock_bh(&ifp->lock); in addrconf_dad_failure()
2099 if (ifp->flags & IFA_F_STABLE_PRIVACY) { in addrconf_dad_failure()
2102 int retries = ifp->stable_privacy_retry + 1; in addrconf_dad_failure()
2105 .plen = ifp->prefix_len, in addrconf_dad_failure()
2106 .ifa_flags = ifp->flags, in addrconf_dad_failure()
2107 .valid_lft = ifp->valid_lft, in addrconf_dad_failure()
2108 .preferred_lft = ifp->prefered_lft, in addrconf_dad_failure()
2109 .scope = ifp->scope, in addrconf_dad_failure()
2112 if (retries > net->ipv6.sysctl.idgen_retries) { in addrconf_dad_failure()
2114 ifp->idev->dev->name); in addrconf_dad_failure()
2118 new_addr = ifp->addr; in addrconf_dad_failure()
2123 spin_unlock_bh(&ifp->lock); in addrconf_dad_failure()
2125 if (idev->cnf.max_addresses && in addrconf_dad_failure()
2127 idev->cnf.max_addresses) in addrconf_dad_failure()
2131 ifp->idev->dev->name); in addrconf_dad_failure()
2137 spin_lock_bh(&ifp2->lock); in addrconf_dad_failure()
2138 ifp2->stable_privacy_retry = retries; in addrconf_dad_failure()
2139 ifp2->state = INET6_IFADDR_STATE_PREDAD; in addrconf_dad_failure()
2140 spin_unlock_bh(&ifp2->lock); in addrconf_dad_failure()
2142 addrconf_mod_dad_work(ifp2, net->ipv6.sysctl.idgen_delay); in addrconf_dad_failure()
2145 spin_lock_bh(&ifp->lock); in addrconf_dad_failure()
2150 ifp->state = INET6_IFADDR_STATE_ERRDAD; in addrconf_dad_failure()
2151 spin_unlock_bh(&ifp->lock); in addrconf_dad_failure()
2163 if (dev->flags&(IFF_LOOPBACK|IFF_NOARP)) in addrconf_join_solict()
2175 if (idev->dev->flags&(IFF_LOOPBACK|IFF_NOARP)) in addrconf_leave_solict()
2187 if (ifp->prefix_len >= 127) /* RFC 6164 */ in addrconf_join_anycast()
2189 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len); in addrconf_join_anycast()
2192 __ipv6_dev_ac_inc(ifp->idev, &addr); in addrconf_join_anycast()
2200 if (ifp->prefix_len >= 127) /* RFC 6164 */ in addrconf_leave_anycast()
2202 ipv6_addr_prefix(&addr, &ifp->addr, ifp->prefix_len); in addrconf_leave_anycast()
2205 __ipv6_dev_ac_dec(ifp->idev, &addr); in addrconf_leave_anycast()
2210 switch (dev->addr_len) { in addrconf_ifid_6lowpan()
2212 memcpy(eui, dev->dev_addr, 3); in addrconf_ifid_6lowpan()
2215 memcpy(eui + 5, dev->dev_addr + 3, 3); in addrconf_ifid_6lowpan()
2218 memcpy(eui, dev->dev_addr, EUI64_ADDR_LEN); in addrconf_ifid_6lowpan()
2222 return -1; in addrconf_ifid_6lowpan()
2232 if (dev->addr_len != FWNET_ALEN) in addrconf_ifid_ieee1394()
2233 return -1; in addrconf_ifid_ieee1394()
2235 ha = (union fwnet_hwaddr *)dev->dev_addr; in addrconf_ifid_ieee1394()
2237 memcpy(eui, &ha->uc.uniq_id, sizeof(ha->uc.uniq_id)); in addrconf_ifid_ieee1394()
2244 /* XXX: inherit EUI-64 from other interface -- yoshfuji */ in addrconf_ifid_arcnet()
2245 if (dev->addr_len != ARCNET_ALEN) in addrconf_ifid_arcnet()
2246 return -1; in addrconf_ifid_arcnet()
2248 eui[7] = *(u8 *)dev->dev_addr; in addrconf_ifid_arcnet()
2254 if (dev->addr_len != INFINIBAND_ALEN) in addrconf_ifid_infiniband()
2255 return -1; in addrconf_ifid_infiniband()
2256 memcpy(eui, dev->dev_addr + 12, 8); in addrconf_ifid_infiniband()
2264 return -1; in __ipv6_isatap_ifid()
2280 if (dev->priv_flags & IFF_ISATAP) in addrconf_ifid_sit()
2281 return __ipv6_isatap_ifid(eui, *(__be32 *)dev->dev_addr); in addrconf_ifid_sit()
2282 return -1; in addrconf_ifid_sit()
2287 return __ipv6_isatap_ifid(eui, *(__be32 *)dev->dev_addr); in addrconf_ifid_gre()
2292 memcpy(eui, dev->perm_addr, 3); in addrconf_ifid_ip6tnl()
2293 memcpy(eui + 5, dev->perm_addr + 3, 3); in addrconf_ifid_ip6tnl()
2302 switch (dev->type) { in ipv6_generate_eui64()
2324 return -1; in ipv6_generate_eui64()
2329 int err = -1; in ipv6_inherit_eui64()
2332 read_lock_bh(&idev->lock); in ipv6_inherit_eui64()
2333 list_for_each_entry_reverse(ifp, &idev->addr_list, if_list) { in ipv6_inherit_eui64()
2334 if (ifp->scope > IFA_LINK) in ipv6_inherit_eui64()
2336 if (ifp->scope == IFA_LINK && !(ifp->flags&IFA_F_TENTATIVE)) { in ipv6_inherit_eui64()
2337 memcpy(eui, ifp->addr.s6_addr+8, 8); in ipv6_inherit_eui64()
2342 read_unlock_bh(&idev->lock); in ipv6_inherit_eui64()
2347 * draft-ietf-6man-rfc4941bis, Section 3.3.1
2353 get_random_bytes(&addr->s6_addr[8], 8); in ipv6_gen_rnd_iid()
2355 /* <draft-ietf-6man-rfc4941bis-08.txt>, Section 3.3.1: in ipv6_gen_rnd_iid()
2358 * - Reserved IPv6 Interface Identifers in ipv6_gen_rnd_iid()
2359 * - XXX: already assigned to an address on the device in ipv6_gen_rnd_iid()
2362 /* Subnet-router anycast: 0000:0000:0000:0000 */ in ipv6_gen_rnd_iid()
2363 if (!(addr->s6_addr32[2] | addr->s6_addr32[3])) in ipv6_gen_rnd_iid()
2366 /* IANA Ethernet block: 0200:5EFF:FE00:0000-0200:5EFF:FE00:5212 in ipv6_gen_rnd_iid()
2368 * IANA Ethernet block: 0200:5EFF:FE00:5214-0200:5EFF:FEFF:FFFF in ipv6_gen_rnd_iid()
2370 if (ntohl(addr->s6_addr32[2]) == 0x02005eff && in ipv6_gen_rnd_iid()
2371 (ntohl(addr->s6_addr32[3]) & 0Xff000000) == 0xfe000000) in ipv6_gen_rnd_iid()
2375 if (ntohl(addr->s6_addr32[2]) == 0xfdffffff && in ipv6_gen_rnd_iid()
2376 ntohl(addr->s6_addr32[3]) >= 0Xffffff80) in ipv6_gen_rnd_iid()
2381 * Add prefix route.
2392 .fc_ifindex = dev->ifindex, in addrconf_prefix_route()
2403 /* Prevent useless cloning on PtP SIT. in addrconf_prefix_route()
2405 class of non-broadcast devices need not cloning. in addrconf_prefix_route()
2408 if (dev->type == ARPHRD_SIT && (dev->flags & IFF_POINTOPOINT)) in addrconf_prefix_route()
2432 fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0, true); in addrconf_get_prefix_route()
2438 if (rt->nh) in addrconf_get_prefix_route()
2441 if (rt->fib6_nh->fib_nh_dev->ifindex != dev->ifindex) in addrconf_get_prefix_route()
2443 if (no_gw && rt->fib6_nh->fib_nh_gw_family) in addrconf_get_prefix_route()
2445 if ((rt->fib6_flags & flags) != flags) in addrconf_get_prefix_route()
2447 if ((rt->fib6_flags & noflags) != 0) in addrconf_get_prefix_route()
2459 /* Create "default" multicast route to the interface */
2466 .fc_ifindex = dev->ifindex, in addrconf_add_mroute()
2489 if (idev->cnf.disable_ipv6) in addrconf_add_dev()
2490 return ERR_PTR(-EACCES); in addrconf_add_dev()
2492 /* Add default multicast route */ in addrconf_add_dev()
2493 if (!(dev->flags & IFF_LOOPBACK) && !netif_is_l3_master(dev)) in addrconf_add_dev()
2507 read_lock_bh(&idev->lock); in manage_tempaddrs()
2509 list_for_each_entry(ift, &idev->tempaddr_list, tmp_list) { in manage_tempaddrs()
2512 if (ifp != ift->ifpub) in manage_tempaddrs()
2521 * (TEMP_PREFERRED_LIFETIME - DESYNC_FACTOR), respectively. in manage_tempaddrs()
2523 age = (now - ift->cstamp) / HZ; in manage_tempaddrs()
2524 max_valid = idev->cnf.temp_valid_lft - age; in manage_tempaddrs()
2528 max_prefered = idev->cnf.temp_prefered_lft - in manage_tempaddrs()
2529 idev->desync_factor - age; in manage_tempaddrs()
2539 spin_lock(&ift->lock); in manage_tempaddrs()
2540 flags = ift->flags; in manage_tempaddrs()
2541 ift->valid_lft = valid_lft; in manage_tempaddrs()
2542 ift->prefered_lft = prefered_lft; in manage_tempaddrs()
2543 ift->tstamp = now; in manage_tempaddrs()
2545 ift->flags &= ~IFA_F_DEPRECATED; in manage_tempaddrs()
2547 spin_unlock(&ift->lock); in manage_tempaddrs()
2552 if ((create || list_empty(&idev->tempaddr_list)) && in manage_tempaddrs()
2553 idev->cnf.use_tempaddr > 0) { in manage_tempaddrs()
2559 read_unlock_bh(&idev->lock); in manage_tempaddrs()
2562 read_unlock_bh(&idev->lock); in manage_tempaddrs()
2568 return idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_STABLE_PRIVACY || in is_addr_mode_generate_stable()
2569 idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_RANDOM; in is_addr_mode_generate_stable()
2583 int max_addresses = in6_dev->cnf.max_addresses; in addrconf_prefix_rcv_add_addr()
2586 .plen = pinfo->prefix_len, in addrconf_prefix_rcv_add_addr()
2594 if ((net->ipv6.devconf_all->optimistic_dad || in addrconf_prefix_rcv_add_addr()
2595 in6_dev->cnf.optimistic_dad) && in addrconf_prefix_rcv_add_addr()
2596 !net->ipv6.devconf_all->forwarding && sllao) in addrconf_prefix_rcv_add_addr()
2608 return -1; in addrconf_prefix_rcv_add_addr()
2611 spin_lock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2612 ifp->flags |= IFA_F_MANAGETEMPADDR; in addrconf_prefix_rcv_add_addr()
2613 ifp->cstamp = jiffies; in addrconf_prefix_rcv_add_addr()
2614 ifp->tokenized = tokenized; in addrconf_prefix_rcv_add_addr()
2615 spin_unlock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2625 spin_lock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2627 if (ifp->valid_lft > (now - ifp->tstamp) / HZ) in addrconf_prefix_rcv_add_addr()
2628 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ; in addrconf_prefix_rcv_add_addr()
2650 ifp->valid_lft = valid_lft; in addrconf_prefix_rcv_add_addr()
2651 ifp->prefered_lft = prefered_lft; in addrconf_prefix_rcv_add_addr()
2652 ifp->tstamp = now; in addrconf_prefix_rcv_add_addr()
2653 flags = ifp->flags; in addrconf_prefix_rcv_add_addr()
2654 ifp->flags &= ~IFA_F_DEPRECATED; in addrconf_prefix_rcv_add_addr()
2655 spin_unlock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2660 spin_unlock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2694 addr_type = ipv6_addr_type(&pinfo->prefix); in addrconf_prefix_rcv()
2699 valid_lft = ntohl(pinfo->valid); in addrconf_prefix_rcv()
2700 prefered_lft = ntohl(pinfo->prefered); in addrconf_prefix_rcv()
2711 dev->name); in addrconf_prefix_rcv()
2717 * 1) Add routes for on-link prefixes in addrconf_prefix_rcv()
2721 if (pinfo->onlink) { in addrconf_prefix_rcv()
2738 rt = addrconf_get_prefix_route(&pinfo->prefix, in addrconf_prefix_rcv()
2739 pinfo->prefix_len, in addrconf_prefix_rcv()
2745 /* Autoconf prefix route */ in addrconf_prefix_rcv()
2763 addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, in addrconf_prefix_rcv()
2772 if (pinfo->autoconf && in6_dev->cnf.autoconf) { in addrconf_prefix_rcv()
2776 if (pinfo->prefix_len == 64) { in addrconf_prefix_rcv()
2777 memcpy(&addr, &pinfo->prefix, 8); in addrconf_prefix_rcv()
2779 if (!ipv6_addr_any(&in6_dev->token)) { in addrconf_prefix_rcv()
2780 read_lock_bh(&in6_dev->lock); in addrconf_prefix_rcv()
2782 in6_dev->token.s6_addr + 8, 8); in addrconf_prefix_rcv()
2783 read_unlock_bh(&in6_dev->lock); in addrconf_prefix_rcv()
2799 pinfo->prefix_len); in addrconf_prefix_rcv()
2831 if (!(ipv6_addr_type(&ireq->ifr6_addr) & IPV6_ADDR_COMPATv4)) in addrconf_set_sit_dstaddr()
2832 return -EADDRNOTAVAIL; in addrconf_set_sit_dstaddr()
2834 p.iph.daddr = ireq->ifr6_addr.s6_addr32[3]; in addrconf_set_sit_dstaddr()
2840 if (!dev->netdev_ops->ndo_tunnel_ctl) in addrconf_set_sit_dstaddr()
2841 return -EOPNOTSUPP; in addrconf_set_sit_dstaddr()
2842 err = dev->netdev_ops->ndo_tunnel_ctl(dev, &p, SIOCADDTUNNEL); in addrconf_set_sit_dstaddr()
2848 return -ENOBUFS; in addrconf_set_sit_dstaddr()
2861 int err = -ENODEV; in addrconf_set_dstaddr()
2864 return -ENODEV; in addrconf_set_dstaddr()
2866 return -EFAULT; in addrconf_set_dstaddr()
2870 if (dev && dev->type == ARPHRD_SIT) in addrconf_set_dstaddr()
2909 if (cfg->plen > 128) in inet6_addr_add()
2910 return -EINVAL; in inet6_addr_add()
2913 if (!cfg->valid_lft || cfg->preferred_lft > cfg->valid_lft) in inet6_addr_add()
2914 return -EINVAL; in inet6_addr_add()
2916 if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR && cfg->plen != 64) in inet6_addr_add()
2917 return -EINVAL; in inet6_addr_add()
2921 return -ENODEV; in inet6_addr_add()
2927 if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) { in inet6_addr_add()
2928 int ret = ipv6_mc_config(net->ipv6.mc_autojoin_sk, in inet6_addr_add()
2929 true, cfg->pfx, ifindex); in inet6_addr_add()
2935 cfg->scope = ipv6_addr_scope(cfg->pfx); in inet6_addr_add()
2937 timeout = addrconf_timeout_fixup(cfg->valid_lft, HZ); in inet6_addr_add()
2940 cfg->valid_lft = timeout; in inet6_addr_add()
2945 cfg->ifa_flags |= IFA_F_PERMANENT; in inet6_addr_add()
2948 timeout = addrconf_timeout_fixup(cfg->preferred_lft, HZ); in inet6_addr_add()
2951 cfg->ifa_flags |= IFA_F_DEPRECATED; in inet6_addr_add()
2952 cfg->preferred_lft = timeout; in inet6_addr_add()
2957 if (!(cfg->ifa_flags & IFA_F_NOPREFIXROUTE)) { in inet6_addr_add()
2958 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, in inet6_addr_add()
2959 ifp->rt_priority, dev, expires, in inet6_addr_add()
2966 if (!(ifp->flags & (IFA_F_OPTIMISTIC | IFA_F_NODAD))) in inet6_addr_add()
2974 if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR) in inet6_addr_add()
2975 manage_tempaddrs(idev, ifp, cfg->valid_lft, in inet6_addr_add()
2976 cfg->preferred_lft, true, jiffies); in inet6_addr_add()
2980 } else if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) { in inet6_addr_add()
2981 ipv6_mc_config(net->ipv6.mc_autojoin_sk, false, in inet6_addr_add()
2982 cfg->pfx, ifindex); in inet6_addr_add()
2996 return -EINVAL; in inet6_addr_del()
3000 return -ENODEV; in inet6_addr_del()
3004 return -ENXIO; in inet6_addr_del()
3006 read_lock_bh(&idev->lock); in inet6_addr_del()
3007 list_for_each_entry(ifp, &idev->addr_list, if_list) { in inet6_addr_del()
3008 if (ifp->prefix_len == plen && in inet6_addr_del()
3009 ipv6_addr_equal(pfx, &ifp->addr)) { in inet6_addr_del()
3011 read_unlock_bh(&idev->lock); in inet6_addr_del()
3013 if (!(ifp->flags & IFA_F_TEMPORARY) && in inet6_addr_del()
3020 ipv6_mc_config(net->ipv6.mc_autojoin_sk, in inet6_addr_del()
3021 false, pfx, dev->ifindex); in inet6_addr_del()
3026 read_unlock_bh(&idev->lock); in inet6_addr_del()
3027 return -EADDRNOTAVAIL; in inet6_addr_del()
3041 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in addrconf_add_ifaddr()
3042 return -EPERM; in addrconf_add_ifaddr()
3045 return -EFAULT; in addrconf_add_ifaddr()
3061 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in addrconf_del_ifaddr()
3062 return -EPERM; in addrconf_del_ifaddr()
3065 return -EFAULT; in addrconf_del_ifaddr()
3089 spin_lock_bh(&ifp->lock); in add_addr()
3090 ifp->flags &= ~IFA_F_TENTATIVE; in add_addr()
3091 spin_unlock_bh(&ifp->lock); in add_addr()
3092 rt_genid_bump_ipv6(dev_net(idev->dev)); in add_addr()
3103 struct net *net = dev_net(idev->dev); in sit_add_v4_addrs()
3110 memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4); in sit_add_v4_addrs()
3112 if (idev->dev->flags&IFF_POINTOPOINT) { in sit_add_v4_addrs()
3113 if (idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_NONE) in sit_add_v4_addrs()
3127 addrconf_prefix_route(&addr, plen, 0, idev->dev, 0, pflags, in sit_add_v4_addrs()
3134 if (in_dev && (dev->flags & IFF_UP)) { in sit_add_v4_addrs()
3139 addr.s6_addr32[3] = ifa->ifa_local; in sit_add_v4_addrs()
3141 if (ifa->ifa_scope == RT_SCOPE_LINK) in sit_add_v4_addrs()
3143 if (ifa->ifa_scope >= RT_SCOPE_HOST) { in sit_add_v4_addrs()
3144 if (idev->dev->flags&IFF_POINTOPOINT) in sit_add_v4_addrs()
3150 addrconf_prefix_route(&addr, plen, 0, idev->dev, in sit_add_v4_addrs()
3189 if ((dev_net(idev->dev)->ipv6.devconf_all->optimistic_dad || in addrconf_add_linklocal()
3190 idev->cnf.optimistic_dad) && in addrconf_add_linklocal()
3191 !dev_net(idev->dev)->ipv6.devconf_all->forwarding) in addrconf_add_linklocal()
3197 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, 0, idev->dev, in addrconf_add_linklocal()
3241 struct net *net = dev_net(idev->dev); in ipv6_generate_stable_address()
3245 if (idev->cnf.stable_secret.initialized) in ipv6_generate_stable_address()
3246 secret = idev->cnf.stable_secret.secret; in ipv6_generate_stable_address()
3247 else if (net->ipv6.devconf_dflt->stable_secret.initialized) in ipv6_generate_stable_address()
3248 secret = net->ipv6.devconf_dflt->stable_secret.secret; in ipv6_generate_stable_address()
3250 return -1; in ipv6_generate_stable_address()
3258 memcpy(data.hwaddr, idev->dev->perm_addr, idev->dev->addr_len); in ipv6_generate_stable_address()
3259 data.prefix[0] = address->s6_addr32[0]; in ipv6_generate_stable_address()
3260 data.prefix[1] = address->s6_addr32[1]; in ipv6_generate_stable_address()
3274 if (dad_count > dev_net(idev->dev)->ipv6.sysctl.idgen_retries) in ipv6_generate_stable_address()
3275 return -1; in ipv6_generate_stable_address()
3285 struct ipv6_stable_secret *s = &idev->cnf.stable_secret; in ipv6_gen_mode_random_init()
3287 if (s->initialized) in ipv6_gen_mode_random_init()
3289 s = &idev->cnf.stable_secret; in ipv6_gen_mode_random_init()
3290 get_random_bytes(&s->secret, sizeof(s->secret)); in ipv6_gen_mode_random_init()
3291 s->initialized = true; in ipv6_gen_mode_random_init()
3299 if (netif_is_l3_master(idev->dev)) in addrconf_addr_gen()
3303 if (idev->dev->flags & IFF_SLAVE) in addrconf_addr_gen()
3308 switch (idev->cnf.addr_gen_mode) { in addrconf_addr_gen()
3317 addrconf_prefix_route(&addr, 64, 0, idev->dev, in addrconf_addr_gen()
3325 if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0) in addrconf_addr_gen()
3328 addrconf_prefix_route(&addr, 64, 0, idev->dev, in addrconf_addr_gen()
3344 if ((dev->type != ARPHRD_ETHER) && in addrconf_dev_config()
3345 (dev->type != ARPHRD_FDDI) && in addrconf_dev_config()
3346 (dev->type != ARPHRD_ARCNET) && in addrconf_dev_config()
3347 (dev->type != ARPHRD_INFINIBAND) && in addrconf_dev_config()
3348 (dev->type != ARPHRD_IEEE1394) && in addrconf_dev_config()
3349 (dev->type != ARPHRD_TUNNEL6) && in addrconf_dev_config()
3350 (dev->type != ARPHRD_6LOWPAN) && in addrconf_dev_config()
3351 (dev->type != ARPHRD_IP6GRE) && in addrconf_dev_config()
3352 (dev->type != ARPHRD_IPGRE) && in addrconf_dev_config()
3353 (dev->type != ARPHRD_TUNNEL) && in addrconf_dev_config()
3354 (dev->type != ARPHRD_NONE) && in addrconf_dev_config()
3355 (dev->type != ARPHRD_RAWIP)) { in addrconf_dev_config()
3358 if (!IS_ERR_OR_NULL(idev) && dev->flags & IFF_UP && in addrconf_dev_config()
3359 dev->flags & IFF_MULTICAST) in addrconf_dev_config()
3369 if (dev->type == ARPHRD_NONE && in addrconf_dev_config()
3370 idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_EUI64) in addrconf_dev_config()
3371 idev->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_RANDOM; in addrconf_dev_config()
3395 if (dev->priv_flags & IFF_ISATAP) { in addrconf_sit_config()
3402 if (dev->flags&IFF_POINTOPOINT) in addrconf_sit_config()
3421 if (dev->flags & IFF_POINTOPOINT) in addrconf_gre_config()
3430 /* !fib6_node means the host route was removed from the in fixup_permanent_addr()
3432 * case regenerate the host route. in fixup_permanent_addr()
3434 if (!ifp->rt || !ifp->rt->fib6_node) { in fixup_permanent_addr()
3437 f6i = addrconf_f6i_alloc(net, idev, &ifp->addr, false, in fixup_permanent_addr()
3442 /* ifp->rt can be accessed outside of rtnl */ in fixup_permanent_addr()
3443 spin_lock(&ifp->lock); in fixup_permanent_addr()
3444 prev = ifp->rt; in fixup_permanent_addr()
3445 ifp->rt = f6i; in fixup_permanent_addr()
3446 spin_unlock(&ifp->lock); in fixup_permanent_addr()
3451 if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) { in fixup_permanent_addr()
3452 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, in fixup_permanent_addr()
3453 ifp->rt_priority, idev->dev, 0, 0, in fixup_permanent_addr()
3457 if (ifp->state == INET6_IFADDR_STATE_PREDAD) in fixup_permanent_addr()
3472 write_lock_bh(&idev->lock); in addrconf_permanent_addr()
3474 list_for_each_entry_safe(ifp, tmp, &idev->addr_list, if_list) { in addrconf_permanent_addr()
3475 if ((ifp->flags & IFA_F_PERMANENT) && in addrconf_permanent_addr()
3477 write_unlock_bh(&idev->lock); in addrconf_permanent_addr()
3480 write_lock_bh(&idev->lock); in addrconf_permanent_addr()
3482 net_info_ratelimited("%s: Failed to add prefix route for address %pI6c; dropping\n", in addrconf_permanent_addr()
3483 idev->dev->name, &ifp->addr); in addrconf_permanent_addr()
3487 write_unlock_bh(&idev->lock); in addrconf_permanent_addr()
3503 if (!idev && dev->mtu >= IPV6_MIN_MTU) { in addrconf_notify()
3512 if (dev->mtu < IPV6_MIN_MTU) { in addrconf_notify()
3513 addrconf_ifdown(dev, dev != net->loopback_dev); in addrconf_notify()
3518 rt6_mtu_change(dev, dev->mtu); in addrconf_notify()
3519 idev->cnf.mtu6 = dev->mtu; in addrconf_notify()
3529 if (!(idev->if_flags & IF_READY)) in addrconf_notify()
3536 if (dev->flags & IFF_SLAVE) in addrconf_notify()
3539 if (idev && idev->cnf.disable_ipv6) in addrconf_notify()
3549 dev->name); in addrconf_notify()
3553 if (!idev && dev->mtu >= IPV6_MIN_MTU) in addrconf_notify()
3557 idev->if_flags |= IF_READY; in addrconf_notify()
3568 if (idev->if_flags & IF_READY) { in addrconf_notify()
3569 /* device is already configured - in addrconf_notify()
3576 if (change_info->flags_changed & IFF_NOARP) in addrconf_notify()
3581 idev->if_flags |= IF_READY; in addrconf_notify()
3585 dev->name); in addrconf_notify()
3590 switch (dev->type) { in addrconf_notify()
3622 if (idev->cnf.mtu6 != dev->mtu && in addrconf_notify()
3623 dev->mtu >= IPV6_MIN_MTU) { in addrconf_notify()
3624 rt6_mtu_change(dev, dev->mtu); in addrconf_notify()
3625 idev->cnf.mtu6 = dev->mtu; in addrconf_notify()
3627 idev->tstamp = jiffies; in addrconf_notify()
3634 if (dev->mtu < IPV6_MIN_MTU) in addrconf_notify()
3635 addrconf_ifdown(dev, dev != net->loopback_dev); in addrconf_notify()
3674 if (info->upper_dev && netif_is_l3_master(info->upper_dev)) in addrconf_notify()
3723 return -ENODEV; in addrconf_ifdown()
3730 idev->dead = 1; in addrconf_ifdown()
3733 RCU_INIT_POINTER(dev->ip6_ptr, NULL); in addrconf_ifdown()
3743 if (!unregister && !idev->cnf.disable_ipv6) { in addrconf_ifdown()
3745 int _keep_addr = net->ipv6.devconf_all->keep_addr_on_down; in addrconf_ifdown()
3748 _keep_addr = idev->cnf.keep_addr_on_down; in addrconf_ifdown()
3760 if (ifa->idev == idev) { in addrconf_ifdown()
3766 !(ifa->flags & IFA_F_PERMANENT) || in addrconf_ifdown()
3767 addr_is_local(&ifa->addr)) { in addrconf_ifdown()
3768 hlist_del_init_rcu(&ifa->addr_lst); in addrconf_ifdown()
3776 write_lock_bh(&idev->lock); in addrconf_ifdown()
3782 idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); in addrconf_ifdown()
3785 while (!list_empty(&idev->tempaddr_list)) { in addrconf_ifdown()
3786 ifa = list_first_entry(&idev->tempaddr_list, in addrconf_ifdown()
3788 list_del(&ifa->tmp_list); in addrconf_ifdown()
3789 write_unlock_bh(&idev->lock); in addrconf_ifdown()
3790 spin_lock_bh(&ifa->lock); in addrconf_ifdown()
3792 if (ifa->ifpub) { in addrconf_ifdown()
3793 in6_ifa_put(ifa->ifpub); in addrconf_ifdown()
3794 ifa->ifpub = NULL; in addrconf_ifdown()
3796 spin_unlock_bh(&ifa->lock); in addrconf_ifdown()
3798 write_lock_bh(&idev->lock); in addrconf_ifdown()
3801 list_for_each_entry_safe(ifa, tmp, &idev->addr_list, if_list) { in addrconf_ifdown()
3807 keep = keep_addr && (ifa->flags & IFA_F_PERMANENT) && in addrconf_ifdown()
3808 !addr_is_local(&ifa->addr); in addrconf_ifdown()
3810 write_unlock_bh(&idev->lock); in addrconf_ifdown()
3811 spin_lock_bh(&ifa->lock); in addrconf_ifdown()
3816 ifa->state = INET6_IFADDR_STATE_PREDAD; in addrconf_ifdown()
3817 if (!(ifa->flags & IFA_F_NODAD)) in addrconf_ifdown()
3818 ifa->flags |= IFA_F_TENTATIVE; in addrconf_ifdown()
3820 rt = ifa->rt; in addrconf_ifdown()
3821 ifa->rt = NULL; in addrconf_ifdown()
3823 state = ifa->state; in addrconf_ifdown()
3824 ifa->state = INET6_IFADDR_STATE_DEAD; in addrconf_ifdown()
3827 spin_unlock_bh(&ifa->lock); in addrconf_ifdown()
3836 if (idev->cnf.forwarding) in addrconf_ifdown()
3838 addrconf_leave_solict(ifa->idev, &ifa->addr); in addrconf_ifdown()
3841 write_lock_bh(&idev->lock); in addrconf_ifdown()
3843 list_del_rcu(&ifa->if_list); in addrconf_ifdown()
3848 write_unlock_bh(&idev->lock); in addrconf_ifdown()
3858 idev->tstamp = jiffies; in addrconf_ifdown()
3863 neigh_parms_release(&nd_tbl, idev->nd_parms); in addrconf_ifdown()
3873 struct net_device *dev = idev->dev; in addrconf_rs_timer()
3876 write_lock(&idev->lock); in addrconf_rs_timer()
3877 if (idev->dead || !(idev->if_flags & IF_READY)) in addrconf_rs_timer()
3884 if (idev->if_flags & IF_RA_RCVD) in addrconf_rs_timer()
3887 if (idev->rs_probes++ < idev->cnf.rtr_solicits || idev->cnf.rtr_solicits < 0) { in addrconf_rs_timer()
3888 write_unlock(&idev->lock); in addrconf_rs_timer()
3895 write_lock(&idev->lock); in addrconf_rs_timer()
3896 idev->rs_interval = rfc3315_s14_backoff_update( in addrconf_rs_timer()
3897 idev->rs_interval, idev->cnf.rtr_solicit_max_interval); in addrconf_rs_timer()
3899 addrconf_mod_rs_timer(idev, (idev->rs_probes == in addrconf_rs_timer()
3900 idev->cnf.rtr_solicits) ? in addrconf_rs_timer()
3901 idev->cnf.rtr_solicit_delay : in addrconf_rs_timer()
3902 idev->rs_interval); in addrconf_rs_timer()
3905 * Note: we do not support deprecated "all on-link" in addrconf_rs_timer()
3908 pr_debug("%s: no IPv6 routers present\n", idev->dev->name); in addrconf_rs_timer()
3912 write_unlock(&idev->lock); in addrconf_rs_timer()
3923 struct inet6_dev *idev = ifp->idev; in addrconf_dad_kick()
3926 if (ifp->flags & IFA_F_OPTIMISTIC) in addrconf_dad_kick()
3929 rand_num = prandom_u32() % (idev->cnf.rtr_solicit_delay ? : 1); in addrconf_dad_kick()
3932 if (idev->cnf.enhanced_dad || in addrconf_dad_kick()
3933 dev_net(idev->dev)->ipv6.devconf_all->enhanced_dad) { in addrconf_dad_kick()
3938 ifp->dad_nonce = nonce; in addrconf_dad_kick()
3939 ifp->dad_probes = idev->cnf.dad_transmits; in addrconf_dad_kick()
3945 struct inet6_dev *idev = ifp->idev; in addrconf_dad_begin()
3946 struct net_device *dev = idev->dev; in addrconf_dad_begin()
3950 addrconf_join_solict(dev, &ifp->addr); in addrconf_dad_begin()
3952 prandom_seed((__force u32) ifp->addr.s6_addr32[3]); in addrconf_dad_begin()
3954 read_lock_bh(&idev->lock); in addrconf_dad_begin()
3955 spin_lock(&ifp->lock); in addrconf_dad_begin()
3956 if (ifp->state == INET6_IFADDR_STATE_DEAD) in addrconf_dad_begin()
3960 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || in addrconf_dad_begin()
3961 (net->ipv6.devconf_all->accept_dad < 1 && in addrconf_dad_begin()
3962 idev->cnf.accept_dad < 1) || in addrconf_dad_begin()
3963 !(ifp->flags&IFA_F_TENTATIVE) || in addrconf_dad_begin()
3964 ifp->flags & IFA_F_NODAD) { in addrconf_dad_begin()
3967 if (ifp->flags & IFA_F_TENTATIVE && in addrconf_dad_begin()
3968 !(ifp->flags & IFA_F_OPTIMISTIC)) in addrconf_dad_begin()
3970 bump_id = ifp->flags & IFA_F_TENTATIVE; in addrconf_dad_begin()
3971 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); in addrconf_dad_begin()
3972 spin_unlock(&ifp->lock); in addrconf_dad_begin()
3973 read_unlock_bh(&idev->lock); in addrconf_dad_begin()
3979 if (!(idev->if_flags & IF_READY)) { in addrconf_dad_begin()
3980 spin_unlock(&ifp->lock); in addrconf_dad_begin()
3981 read_unlock_bh(&idev->lock); in addrconf_dad_begin()
3984 * - keep it tentative if it is a permanent address. in addrconf_dad_begin()
3985 * - otherwise, kill it. in addrconf_dad_begin()
3996 if (ifp->flags & IFA_F_OPTIMISTIC) { in addrconf_dad_begin()
3997 ip6_ins_rt(net, ifp->rt); in addrconf_dad_begin()
4008 spin_unlock(&ifp->lock); in addrconf_dad_begin()
4009 read_unlock_bh(&idev->lock); in addrconf_dad_begin()
4018 spin_lock_bh(&ifp->lock); in addrconf_dad_start()
4019 if (ifp->state != INET6_IFADDR_STATE_DEAD) { in addrconf_dad_start()
4020 ifp->state = INET6_IFADDR_STATE_PREDAD; in addrconf_dad_start()
4023 spin_unlock_bh(&ifp->lock); in addrconf_dad_start()
4034 struct inet6_dev *idev = ifp->idev; in addrconf_dad_work()
4046 spin_lock_bh(&ifp->lock); in addrconf_dad_work()
4047 if (ifp->state == INET6_IFADDR_STATE_PREDAD) { in addrconf_dad_work()
4049 ifp->state = INET6_IFADDR_STATE_DAD; in addrconf_dad_work()
4050 } else if (ifp->state == INET6_IFADDR_STATE_ERRDAD) { in addrconf_dad_work()
4052 ifp->state = INET6_IFADDR_STATE_POSTDAD; in addrconf_dad_work()
4054 if ((dev_net(idev->dev)->ipv6.devconf_all->accept_dad > 1 || in addrconf_dad_work()
4055 idev->cnf.accept_dad > 1) && in addrconf_dad_work()
4056 !idev->cnf.disable_ipv6 && in addrconf_dad_work()
4057 !(ifp->flags & IFA_F_STABLE_PRIVACY)) { in addrconf_dad_work()
4063 if (!ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) && in addrconf_dad_work()
4064 ipv6_addr_equal(&ifp->addr, &addr)) { in addrconf_dad_work()
4065 /* DAD failed for link-local based on MAC */ in addrconf_dad_work()
4066 idev->cnf.disable_ipv6 = 1; in addrconf_dad_work()
4069 ifp->idev->dev->name); in addrconf_dad_work()
4074 spin_unlock_bh(&ifp->lock); in addrconf_dad_work()
4083 addrconf_ifdown(idev->dev, false); in addrconf_dad_work()
4087 if (!ifp->dad_probes && addrconf_dad_end(ifp)) in addrconf_dad_work()
4090 write_lock_bh(&idev->lock); in addrconf_dad_work()
4091 if (idev->dead || !(idev->if_flags & IF_READY)) { in addrconf_dad_work()
4092 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4096 spin_lock(&ifp->lock); in addrconf_dad_work()
4097 if (ifp->state == INET6_IFADDR_STATE_DEAD) { in addrconf_dad_work()
4098 spin_unlock(&ifp->lock); in addrconf_dad_work()
4099 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4103 if (ifp->dad_probes == 0) { in addrconf_dad_work()
4110 if (ifp->flags & IFA_F_TENTATIVE && in addrconf_dad_work()
4111 !(ifp->flags & IFA_F_OPTIMISTIC)) in addrconf_dad_work()
4113 bump_id = ifp->flags & IFA_F_TENTATIVE; in addrconf_dad_work()
4114 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); in addrconf_dad_work()
4115 spin_unlock(&ifp->lock); in addrconf_dad_work()
4116 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4123 ifp->dad_probes--; in addrconf_dad_work()
4125 max(NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME), in addrconf_dad_work()
4127 spin_unlock(&ifp->lock); in addrconf_dad_work()
4128 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4131 addrconf_addr_solict_mult(&ifp->addr, &mcaddr); in addrconf_dad_work()
4132 ndisc_send_ns(ifp->idev->dev, &ifp->addr, &mcaddr, &in6addr_any, in addrconf_dad_work()
4133 ifp->dad_nonce); in addrconf_dad_work()
4139 /* ifp->idev must be at least read locked */
4143 struct inet6_dev *idev = ifp->idev; in ipv6_lonely_lladdr()
4145 list_for_each_entry_reverse(ifpiter, &idev->addr_list, if_list) { in ipv6_lonely_lladdr()
4146 if (ifpiter->scope > IFA_LINK) in ipv6_lonely_lladdr()
4148 if (ifp != ifpiter && ifpiter->scope == IFA_LINK && in ipv6_lonely_lladdr()
4149 (ifpiter->flags & (IFA_F_PERMANENT|IFA_F_TENTATIVE| in ipv6_lonely_lladdr()
4160 struct net_device *dev = ifp->idev->dev; in addrconf_dad_completed()
4176 read_lock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4177 send_mld = ifp->scope == IFA_LINK && ipv6_lonely_lladdr(ifp); in addrconf_dad_completed()
4179 ipv6_accept_ra(ifp->idev) && in addrconf_dad_completed()
4180 ifp->idev->cnf.rtr_solicits != 0 && in addrconf_dad_completed()
4181 (dev->flags&IFF_LOOPBACK) == 0; in addrconf_dad_completed()
4182 read_unlock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4188 ipv6_mc_dad_complete(ifp->idev); in addrconf_dad_completed()
4192 (ifp->idev->cnf.ndisc_notify || in addrconf_dad_completed()
4193 dev_net(dev)->ipv6.devconf_all->ndisc_notify)) { in addrconf_dad_completed()
4194 ndisc_send_na(dev, &in6addr_linklocal_allnodes, &ifp->addr, in addrconf_dad_completed()
4195 /*router=*/ !!ifp->idev->cnf.forwarding, in addrconf_dad_completed()
4210 write_lock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4211 spin_lock(&ifp->lock); in addrconf_dad_completed()
4212 ifp->idev->rs_interval = rfc3315_s14_backoff_init( in addrconf_dad_completed()
4213 ifp->idev->cnf.rtr_solicit_interval); in addrconf_dad_completed()
4214 ifp->idev->rs_probes = 1; in addrconf_dad_completed()
4215 ifp->idev->if_flags |= IF_RS_SENT; in addrconf_dad_completed()
4216 addrconf_mod_rs_timer(ifp->idev, ifp->idev->rs_interval); in addrconf_dad_completed()
4217 spin_unlock(&ifp->lock); in addrconf_dad_completed()
4218 write_unlock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4227 if (ifp->flags & IFA_F_TEMPORARY) in addrconf_dad_completed()
4235 read_lock_bh(&idev->lock); in addrconf_dad_run()
4236 list_for_each_entry(ifp, &idev->addr_list, if_list) { in addrconf_dad_run()
4237 spin_lock(&ifp->lock); in addrconf_dad_run()
4238 if ((ifp->flags & IFA_F_TENTATIVE && in addrconf_dad_run()
4239 ifp->state == INET6_IFADDR_STATE_DAD) || restart) { in addrconf_dad_run()
4241 ifp->state = INET6_IFADDR_STATE_PREDAD; in addrconf_dad_run()
4244 spin_unlock(&ifp->lock); in addrconf_dad_run()
4246 read_unlock_bh(&idev->lock); in addrconf_dad_run()
4258 struct if6_iter_state *state = seq->private; in if6_get_first()
4265 state->bucket = 0; in if6_get_first()
4266 state->offset = 0; in if6_get_first()
4269 for (; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) { in if6_get_first()
4270 hlist_for_each_entry_rcu(ifa, &inet6_addr_lst[state->bucket], in if6_get_first()
4272 if (!net_eq(dev_net(ifa->idev->dev), net)) in if6_get_first()
4275 if (p < state->offset) { in if6_get_first()
4283 state->offset = 0; in if6_get_first()
4292 struct if6_iter_state *state = seq->private; in if6_get_next()
4296 if (!net_eq(dev_net(ifa->idev->dev), net)) in if6_get_next()
4298 state->offset++; in if6_get_next()
4302 state->offset = 0; in if6_get_next()
4303 while (++state->bucket < IN6_ADDR_HSIZE) { in if6_get_next()
4305 &inet6_addr_lst[state->bucket], addr_lst) { in if6_get_next()
4306 if (!net_eq(dev_net(ifa->idev->dev), net)) in if6_get_next()
4341 &ifp->addr, in if6_seq_show()
4342 ifp->idev->dev->ifindex, in if6_seq_show()
4343 ifp->prefix_len, in if6_seq_show()
4344 ifp->scope, in if6_seq_show()
4345 (u8) ifp->flags, in if6_seq_show()
4346 ifp->idev->dev->name); in if6_seq_show()
4359 if (!proc_create_net("if_inet6", 0444, net->proc_net, &if6_seq_ops, in if6_proc_net_init()
4361 return -ENOMEM; in if6_proc_net_init()
4367 remove_proc_entry("if_inet6", net->proc_net); in if6_proc_net_exit()
4396 if (!net_eq(dev_net(ifp->idev->dev), net)) in ipv6_chk_home_addr()
4398 if (ipv6_addr_equal(&ifp->addr, addr) && in ipv6_chk_home_addr()
4399 (ifp->flags & IFA_F_HOMEADDRESS)) { in ipv6_chk_home_addr()
4436 if (!net_eq(dev_net(ifp->idev->dev), net)) in ipv6_chk_rpl_srh_loop()
4439 if (ipv6_addr_equal(&ifp->addr, addr)) { in ipv6_chk_rpl_srh_loop()
4487 * IFA_F_PERMANENT has a non-infinity life time. in addrconf_verify_rtnl()
4489 if ((ifp->flags & IFA_F_PERMANENT) && in addrconf_verify_rtnl()
4490 (ifp->prefered_lft == INFINITY_LIFE_TIME)) in addrconf_verify_rtnl()
4493 spin_lock(&ifp->lock); in addrconf_verify_rtnl()
4495 age = (now - ifp->tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; in addrconf_verify_rtnl()
4497 if (ifp->valid_lft != INFINITY_LIFE_TIME && in addrconf_verify_rtnl()
4498 age >= ifp->valid_lft) { in addrconf_verify_rtnl()
4499 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4503 } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) { in addrconf_verify_rtnl()
4504 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4506 } else if (age >= ifp->prefered_lft) { in addrconf_verify_rtnl()
4507 /* jiffies - ifp->tstamp > age >= ifp->prefered_lft */ in addrconf_verify_rtnl()
4510 if (!(ifp->flags&IFA_F_DEPRECATED)) { in addrconf_verify_rtnl()
4512 ifp->flags |= IFA_F_DEPRECATED; in addrconf_verify_rtnl()
4515 if ((ifp->valid_lft != INFINITY_LIFE_TIME) && in addrconf_verify_rtnl()
4516 (time_before(ifp->tstamp + ifp->valid_lft * HZ, next))) in addrconf_verify_rtnl()
4517 next = ifp->tstamp + ifp->valid_lft * HZ; in addrconf_verify_rtnl()
4519 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4528 } else if ((ifp->flags&IFA_F_TEMPORARY) && in addrconf_verify_rtnl()
4529 !(ifp->flags&IFA_F_TENTATIVE)) { in addrconf_verify_rtnl()
4530 unsigned long regen_advance = ifp->idev->cnf.regen_max_retry * in addrconf_verify_rtnl()
4531 ifp->idev->cnf.dad_transmits * in addrconf_verify_rtnl()
4532 max(NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME), HZ/100) / HZ; in addrconf_verify_rtnl()
4534 if (age >= ifp->prefered_lft - regen_advance) { in addrconf_verify_rtnl()
4535 struct inet6_ifaddr *ifpub = ifp->ifpub; in addrconf_verify_rtnl()
4536 if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) in addrconf_verify_rtnl()
4537 next = ifp->tstamp + ifp->prefered_lft * HZ; in addrconf_verify_rtnl()
4538 if (!ifp->regen_count && ifpub) { in addrconf_verify_rtnl()
4539 ifp->regen_count++; in addrconf_verify_rtnl()
4542 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4544 spin_lock(&ifpub->lock); in addrconf_verify_rtnl()
4545 ifpub->regen_count = 0; in addrconf_verify_rtnl()
4546 spin_unlock(&ifpub->lock); in addrconf_verify_rtnl()
4554 } else if (time_before(ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ, next)) in addrconf_verify_rtnl()
4555 next = ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ; in addrconf_verify_rtnl()
4556 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4558 /* ifp->prefered_lft <= ifp->valid_lft */ in addrconf_verify_rtnl()
4559 if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) in addrconf_verify_rtnl()
4560 next = ifp->tstamp + ifp->prefered_lft * HZ; in addrconf_verify_rtnl()
4561 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4579 mod_delayed_work(addrconf_wq, &addr_chk_work, next_sched - now); in addrconf_verify_rtnl()
4627 struct net *net = sock_net(skb->sk); in inet6_rtm_deladdr()
4642 return -EINVAL; in inet6_rtm_deladdr()
4644 ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags; in inet6_rtm_deladdr()
4649 return inet6_addr_del(net, ifm->ifa_index, ifa_flags, pfx, in inet6_rtm_deladdr()
4650 ifm->ifa_prefixlen); in inet6_rtm_deladdr()
4660 f6i = addrconf_get_prefix_route(modify_peer ? &ifp->peer_addr : &ifp->addr, in modify_prefix_route()
4661 ifp->prefix_len, in modify_prefix_route()
4662 ifp->idev->dev, 0, RTF_DEFAULT, true); in modify_prefix_route()
4664 return -ENOENT; in modify_prefix_route()
4666 prio = ifp->rt_priority ? : IP6_RT_PRIO_ADDRCONF; in modify_prefix_route()
4667 if (f6i->fib6_metric != prio) { in modify_prefix_route()
4669 ip6_del_rt(dev_net(ifp->idev->dev), f6i, false); in modify_prefix_route()
4672 addrconf_prefix_route(modify_peer ? &ifp->peer_addr : &ifp->addr, in modify_prefix_route()
4673 ifp->prefix_len, in modify_prefix_route()
4674 ifp->rt_priority, ifp->idev->dev, in modify_prefix_route()
4699 if (!cfg->valid_lft || cfg->preferred_lft > cfg->valid_lft) in inet6_addr_modify()
4700 return -EINVAL; in inet6_addr_modify()
4702 if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR && in inet6_addr_modify()
4703 (ifp->flags & IFA_F_TEMPORARY || ifp->prefix_len != 64)) in inet6_addr_modify()
4704 return -EINVAL; in inet6_addr_modify()
4706 if (!(ifp->flags & IFA_F_TENTATIVE) || ifp->flags & IFA_F_DADFAILED) in inet6_addr_modify()
4707 cfg->ifa_flags &= ~IFA_F_OPTIMISTIC; in inet6_addr_modify()
4709 timeout = addrconf_timeout_fixup(cfg->valid_lft, HZ); in inet6_addr_modify()
4712 cfg->valid_lft = timeout; in inet6_addr_modify()
4717 cfg->ifa_flags |= IFA_F_PERMANENT; in inet6_addr_modify()
4720 timeout = addrconf_timeout_fixup(cfg->preferred_lft, HZ); in inet6_addr_modify()
4723 cfg->ifa_flags |= IFA_F_DEPRECATED; in inet6_addr_modify()
4724 cfg->preferred_lft = timeout; in inet6_addr_modify()
4727 if (cfg->peer_pfx && in inet6_addr_modify()
4728 memcmp(&ifp->peer_addr, cfg->peer_pfx, sizeof(struct in6_addr))) { in inet6_addr_modify()
4729 if (!ipv6_addr_any(&ifp->peer_addr)) in inet6_addr_modify()
4734 spin_lock_bh(&ifp->lock); in inet6_addr_modify()
4735 was_managetempaddr = ifp->flags & IFA_F_MANAGETEMPADDR; in inet6_addr_modify()
4736 had_prefixroute = ifp->flags & IFA_F_PERMANENT && in inet6_addr_modify()
4737 !(ifp->flags & IFA_F_NOPREFIXROUTE); in inet6_addr_modify()
4738 ifp->flags &= ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | in inet6_addr_modify()
4741 ifp->flags |= cfg->ifa_flags; in inet6_addr_modify()
4742 ifp->tstamp = jiffies; in inet6_addr_modify()
4743 ifp->valid_lft = cfg->valid_lft; in inet6_addr_modify()
4744 ifp->prefered_lft = cfg->preferred_lft; in inet6_addr_modify()
4746 if (cfg->rt_priority && cfg->rt_priority != ifp->rt_priority) in inet6_addr_modify()
4747 ifp->rt_priority = cfg->rt_priority; in inet6_addr_modify()
4750 ifp->peer_addr = *cfg->peer_pfx; in inet6_addr_modify()
4752 spin_unlock_bh(&ifp->lock); in inet6_addr_modify()
4753 if (!(ifp->flags&IFA_F_TENTATIVE)) in inet6_addr_modify()
4756 if (!(cfg->ifa_flags & IFA_F_NOPREFIXROUTE)) { in inet6_addr_modify()
4757 int rc = -ENOENT; in inet6_addr_modify()
4762 /* prefix route could have been deleted; if so restore it */ in inet6_addr_modify()
4763 if (rc == -ENOENT) { in inet6_addr_modify()
4764 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, in inet6_addr_modify()
4765 ifp->rt_priority, ifp->idev->dev, in inet6_addr_modify()
4769 if (had_prefixroute && !ipv6_addr_any(&ifp->peer_addr)) in inet6_addr_modify()
4772 if (rc == -ENOENT && !ipv6_addr_any(&ifp->peer_addr)) { in inet6_addr_modify()
4773 addrconf_prefix_route(&ifp->peer_addr, ifp->prefix_len, in inet6_addr_modify()
4774 ifp->rt_priority, ifp->idev->dev, in inet6_addr_modify()
4781 write_lock_bh(&ifp->idev->lock); in inet6_addr_modify()
4783 write_unlock_bh(&ifp->idev->lock); in inet6_addr_modify()
4791 if (was_managetempaddr || ifp->flags & IFA_F_MANAGETEMPADDR) { in inet6_addr_modify()
4793 !(ifp->flags & IFA_F_MANAGETEMPADDR)) { in inet6_addr_modify()
4794 cfg->valid_lft = 0; in inet6_addr_modify()
4795 cfg->preferred_lft = 0; in inet6_addr_modify()
4797 manage_tempaddrs(ifp->idev, ifp, cfg->valid_lft, in inet6_addr_modify()
4798 cfg->preferred_lft, !was_managetempaddr, in inet6_addr_modify()
4811 struct net *net = sock_net(skb->sk); in inet6_rtm_newaddr()
4831 return -EINVAL; in inet6_rtm_newaddr()
4834 cfg.plen = ifm->ifa_prefixlen; in inet6_rtm_newaddr()
4845 cfg.valid_lft = ci->ifa_valid; in inet6_rtm_newaddr()
4846 cfg.preferred_lft = ci->ifa_prefered; in inet6_rtm_newaddr()
4849 dev = __dev_get_by_index(net, ifm->ifa_index); in inet6_rtm_newaddr()
4851 return -ENODEV; in inet6_rtm_newaddr()
4856 cfg.ifa_flags = ifm->ifa_flags; in inet6_rtm_newaddr()
4873 return -EINVAL; in inet6_rtm_newaddr()
4882 return inet6_addr_add(net, ifm->ifa_index, &cfg, extack); in inet6_rtm_newaddr()
4885 if (nlh->nlmsg_flags & NLM_F_EXCL || in inet6_rtm_newaddr()
4886 !(nlh->nlmsg_flags & NLM_F_REPLACE)) in inet6_rtm_newaddr()
4887 err = -EEXIST; in inet6_rtm_newaddr()
4902 ifm->ifa_family = AF_INET6; in put_ifaddrmsg()
4903 ifm->ifa_prefixlen = prefixlen; in put_ifaddrmsg()
4904 ifm->ifa_flags = flags; in put_ifaddrmsg()
4905 ifm->ifa_scope = scope; in put_ifaddrmsg()
4906 ifm->ifa_index = ifindex; in put_ifaddrmsg()
4966 nlh = nlmsg_put(skb, args->portid, args->seq, args->event, in inet6_fill_ifaddr()
4967 sizeof(struct ifaddrmsg), args->flags); in inet6_fill_ifaddr()
4969 return -EMSGSIZE; in inet6_fill_ifaddr()
4971 put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope), in inet6_fill_ifaddr()
4972 ifa->idev->dev->ifindex); in inet6_fill_ifaddr()
4974 if (args->netnsid >= 0 && in inet6_fill_ifaddr()
4975 nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) in inet6_fill_ifaddr()
4978 if (!((ifa->flags&IFA_F_PERMANENT) && in inet6_fill_ifaddr()
4979 (ifa->prefered_lft == INFINITY_LIFE_TIME))) { in inet6_fill_ifaddr()
4980 preferred = ifa->prefered_lft; in inet6_fill_ifaddr()
4981 valid = ifa->valid_lft; in inet6_fill_ifaddr()
4983 long tval = (jiffies - ifa->tstamp)/HZ; in inet6_fill_ifaddr()
4985 preferred -= tval; in inet6_fill_ifaddr()
4990 valid -= tval; in inet6_fill_ifaddr()
5000 if (!ipv6_addr_any(&ifa->peer_addr)) { in inet6_fill_ifaddr()
5001 if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 || in inet6_fill_ifaddr()
5002 nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->peer_addr) < 0) in inet6_fill_ifaddr()
5005 if (nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->addr) < 0) in inet6_fill_ifaddr()
5008 if (ifa->rt_priority && in inet6_fill_ifaddr()
5009 nla_put_u32(skb, IFA_RT_PRIORITY, ifa->rt_priority)) in inet6_fill_ifaddr()
5012 if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) in inet6_fill_ifaddr()
5015 if (nla_put_u32(skb, IFA_FLAGS, ifa->flags) < 0) in inet6_fill_ifaddr()
5023 return -EMSGSIZE; in inet6_fill_ifaddr()
5031 int ifindex = ifmca->idev->dev->ifindex; in inet6_fill_ifmcaddr()
5033 if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE) in inet6_fill_ifmcaddr()
5036 nlh = nlmsg_put(skb, args->portid, args->seq, args->event, in inet6_fill_ifmcaddr()
5037 sizeof(struct ifaddrmsg), args->flags); in inet6_fill_ifmcaddr()
5039 return -EMSGSIZE; in inet6_fill_ifmcaddr()
5041 if (args->netnsid >= 0 && in inet6_fill_ifmcaddr()
5042 nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) { in inet6_fill_ifmcaddr()
5044 return -EMSGSIZE; in inet6_fill_ifmcaddr()
5048 if (nla_put_in6_addr(skb, IFA_MULTICAST, &ifmca->mca_addr) < 0 || in inet6_fill_ifmcaddr()
5049 put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp, in inet6_fill_ifmcaddr()
5052 return -EMSGSIZE; in inet6_fill_ifmcaddr()
5062 struct net_device *dev = fib6_info_nh_dev(ifaca->aca_rt); in inet6_fill_ifacaddr()
5063 int ifindex = dev ? dev->ifindex : 1; in inet6_fill_ifacaddr()
5067 if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE) in inet6_fill_ifacaddr()
5070 nlh = nlmsg_put(skb, args->portid, args->seq, args->event, in inet6_fill_ifacaddr()
5071 sizeof(struct ifaddrmsg), args->flags); in inet6_fill_ifacaddr()
5073 return -EMSGSIZE; in inet6_fill_ifacaddr()
5075 if (args->netnsid >= 0 && in inet6_fill_ifacaddr()
5076 nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) { in inet6_fill_ifacaddr()
5078 return -EMSGSIZE; in inet6_fill_ifacaddr()
5082 if (nla_put_in6_addr(skb, IFA_ANYCAST, &ifaca->aca_addr) < 0 || in inet6_fill_ifacaddr()
5083 put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp, in inet6_fill_ifacaddr()
5086 return -EMSGSIZE; in inet6_fill_ifacaddr()
5103 read_lock_bh(&idev->lock); in in6_dump_addrs()
5104 switch (fillargs->type) { in in6_dump_addrs()
5107 fillargs->event = RTM_NEWADDR; in in6_dump_addrs()
5110 list_for_each_entry(ifa, &idev->addr_list, if_list) { in in6_dump_addrs()
5123 fillargs->event = RTM_GETMULTICAST; in in6_dump_addrs()
5126 for (ifmca = idev->mc_list; ifmca; in in6_dump_addrs()
5127 ifmca = ifmca->next, ip_idx++) { in in6_dump_addrs()
5136 fillargs->event = RTM_GETANYCAST; in in6_dump_addrs()
5138 for (ifaca = idev->ac_list; ifaca; in in6_dump_addrs()
5139 ifaca = ifaca->aca_next, ip_idx++) { in in6_dump_addrs()
5150 read_unlock_bh(&idev->lock); in in6_dump_addrs()
5151 cb->args[2] = ip_idx; in in6_dump_addrs()
5160 struct netlink_ext_ack *extack = cb->extack; in inet6_valid_dump_ifaddr_req()
5165 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in inet6_valid_dump_ifaddr_req()
5167 return -EINVAL; in inet6_valid_dump_ifaddr_req()
5171 if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) { in inet6_valid_dump_ifaddr_req()
5173 return -EINVAL; in inet6_valid_dump_ifaddr_req()
5176 fillargs->ifindex = ifm->ifa_index; in inet6_valid_dump_ifaddr_req()
5177 if (fillargs->ifindex) { in inet6_valid_dump_ifaddr_req()
5178 cb->answer_flags |= NLM_F_DUMP_FILTERED; in inet6_valid_dump_ifaddr_req()
5179 fillargs->flags |= NLM_F_DUMP_FILTERED; in inet6_valid_dump_ifaddr_req()
5194 fillargs->netnsid = nla_get_s32(tb[i]); in inet6_valid_dump_ifaddr_req()
5195 net = rtnl_get_net_ns_capable(sk, fillargs->netnsid); in inet6_valid_dump_ifaddr_req()
5197 fillargs->netnsid = -1; in inet6_valid_dump_ifaddr_req()
5204 return -EINVAL; in inet6_valid_dump_ifaddr_req()
5214 const struct nlmsghdr *nlh = cb->nlh; in inet6_dump_addr()
5216 .portid = NETLINK_CB(cb->skb).portid, in inet6_dump_addr()
5217 .seq = cb->nlh->nlmsg_seq, in inet6_dump_addr()
5219 .netnsid = -1, in inet6_dump_addr()
5222 struct net *net = sock_net(skb->sk); in inet6_dump_addr()
5231 s_h = cb->args[0]; in inet6_dump_addr()
5232 s_idx = idx = cb->args[1]; in inet6_dump_addr()
5233 s_ip_idx = cb->args[2]; in inet6_dump_addr()
5235 if (cb->strict_check) { in inet6_dump_addr()
5237 skb->sk, cb); in inet6_dump_addr()
5245 err = -ENODEV; in inet6_dump_addr()
5260 cb->seq = atomic_read(&tgt_net->ipv6.dev_addr_genid) ^ tgt_net->dev_base_seq; in inet6_dump_addr()
5263 head = &tgt_net->dev_index_head[h]; in inet6_dump_addr()
5282 cb->args[0] = h; in inet6_dump_addr()
5283 cb->args[1] = idx; in inet6_dump_addr()
5288 return skb->len ? : err; in inet6_dump_addr()
5321 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in inet6_rtm_valid_getaddr_req()
5323 return -EINVAL; in inet6_rtm_valid_getaddr_req()
5331 if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) { in inet6_rtm_valid_getaddr_req()
5333 return -EINVAL; in inet6_rtm_valid_getaddr_req()
5352 return -EINVAL; in inet6_rtm_valid_getaddr_req()
5362 struct net *net = sock_net(in_skb->sk); in inet6_rtm_getaddr()
5365 .seq = nlh->nlmsg_seq, in inet6_rtm_getaddr()
5368 .netnsid = -1, in inet6_rtm_getaddr()
5394 return -EINVAL; in inet6_rtm_getaddr()
5397 if (ifm->ifa_index) in inet6_rtm_getaddr()
5398 dev = dev_get_by_index(tgt_net, ifm->ifa_index); in inet6_rtm_getaddr()
5402 err = -EADDRNOTAVAIL; in inet6_rtm_getaddr()
5408 err = -ENOBUFS; in inet6_rtm_getaddr()
5414 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ in inet6_rtm_getaddr()
5415 WARN_ON(err == -EMSGSIZE); in inet6_rtm_getaddr()
5434 struct net *net = dev_net(ifa->idev->dev); in inet6_ifa_notify()
5440 .netnsid = -1, in inet6_ifa_notify()
5442 int err = -ENOBUFS; in inet6_ifa_notify()
5450 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ in inet6_ifa_notify()
5451 WARN_ON(err == -EMSGSIZE); in inet6_ifa_notify()
5468 array[DEVCONF_FORWARDING] = cnf->forwarding; in ipv6_store_devconf()
5469 array[DEVCONF_HOPLIMIT] = cnf->hop_limit; in ipv6_store_devconf()
5470 array[DEVCONF_MTU6] = cnf->mtu6; in ipv6_store_devconf()
5471 array[DEVCONF_ACCEPT_RA] = cnf->accept_ra; in ipv6_store_devconf()
5472 array[DEVCONF_ACCEPT_REDIRECTS] = cnf->accept_redirects; in ipv6_store_devconf()
5473 array[DEVCONF_AUTOCONF] = cnf->autoconf; in ipv6_store_devconf()
5474 array[DEVCONF_DAD_TRANSMITS] = cnf->dad_transmits; in ipv6_store_devconf()
5475 array[DEVCONF_RTR_SOLICITS] = cnf->rtr_solicits; in ipv6_store_devconf()
5477 jiffies_to_msecs(cnf->rtr_solicit_interval); in ipv6_store_devconf()
5479 jiffies_to_msecs(cnf->rtr_solicit_max_interval); in ipv6_store_devconf()
5481 jiffies_to_msecs(cnf->rtr_solicit_delay); in ipv6_store_devconf()
5482 array[DEVCONF_FORCE_MLD_VERSION] = cnf->force_mld_version; in ipv6_store_devconf()
5484 jiffies_to_msecs(cnf->mldv1_unsolicited_report_interval); in ipv6_store_devconf()
5486 jiffies_to_msecs(cnf->mldv2_unsolicited_report_interval); in ipv6_store_devconf()
5487 array[DEVCONF_USE_TEMPADDR] = cnf->use_tempaddr; in ipv6_store_devconf()
5488 array[DEVCONF_TEMP_VALID_LFT] = cnf->temp_valid_lft; in ipv6_store_devconf()
5489 array[DEVCONF_TEMP_PREFERED_LFT] = cnf->temp_prefered_lft; in ipv6_store_devconf()
5490 array[DEVCONF_REGEN_MAX_RETRY] = cnf->regen_max_retry; in ipv6_store_devconf()
5491 array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor; in ipv6_store_devconf()
5492 array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses; in ipv6_store_devconf()
5493 array[DEVCONF_ACCEPT_RA_DEFRTR] = cnf->accept_ra_defrtr; in ipv6_store_devconf()
5494 array[DEVCONF_ACCEPT_RA_MIN_HOP_LIMIT] = cnf->accept_ra_min_hop_limit; in ipv6_store_devconf()
5495 array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo; in ipv6_store_devconf()
5497 array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref; in ipv6_store_devconf()
5499 jiffies_to_msecs(cnf->rtr_probe_interval); in ipv6_store_devconf()
5501 array[DEVCONF_ACCEPT_RA_RT_INFO_MIN_PLEN] = cnf->accept_ra_rt_info_min_plen; in ipv6_store_devconf()
5502 array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen; in ipv6_store_devconf()
5505 array[DEVCONF_PROXY_NDP] = cnf->proxy_ndp; in ipv6_store_devconf()
5506 array[DEVCONF_ACCEPT_SOURCE_ROUTE] = cnf->accept_source_route; in ipv6_store_devconf()
5508 array[DEVCONF_OPTIMISTIC_DAD] = cnf->optimistic_dad; in ipv6_store_devconf()
5509 array[DEVCONF_USE_OPTIMISTIC] = cnf->use_optimistic; in ipv6_store_devconf()
5512 array[DEVCONF_MC_FORWARDING] = cnf->mc_forwarding; in ipv6_store_devconf()
5514 array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6; in ipv6_store_devconf()
5515 array[DEVCONF_ACCEPT_DAD] = cnf->accept_dad; in ipv6_store_devconf()
5516 array[DEVCONF_FORCE_TLLAO] = cnf->force_tllao; in ipv6_store_devconf()
5517 array[DEVCONF_NDISC_NOTIFY] = cnf->ndisc_notify; in ipv6_store_devconf()
5518 array[DEVCONF_SUPPRESS_FRAG_NDISC] = cnf->suppress_frag_ndisc; in ipv6_store_devconf()
5519 array[DEVCONF_ACCEPT_RA_FROM_LOCAL] = cnf->accept_ra_from_local; in ipv6_store_devconf()
5520 array[DEVCONF_ACCEPT_RA_MTU] = cnf->accept_ra_mtu; in ipv6_store_devconf()
5521 array[DEVCONF_IGNORE_ROUTES_WITH_LINKDOWN] = cnf->ignore_routes_with_linkdown; in ipv6_store_devconf()
5523 array[DEVCONF_USE_OIF_ADDRS_ONLY] = cnf->use_oif_addrs_only; in ipv6_store_devconf()
5524 array[DEVCONF_DROP_UNICAST_IN_L2_MULTICAST] = cnf->drop_unicast_in_l2_multicast; in ipv6_store_devconf()
5525 array[DEVCONF_DROP_UNSOLICITED_NA] = cnf->drop_unsolicited_na; in ipv6_store_devconf()
5526 array[DEVCONF_KEEP_ADDR_ON_DOWN] = cnf->keep_addr_on_down; in ipv6_store_devconf()
5527 array[DEVCONF_SEG6_ENABLED] = cnf->seg6_enabled; in ipv6_store_devconf()
5529 array[DEVCONF_SEG6_REQUIRE_HMAC] = cnf->seg6_require_hmac; in ipv6_store_devconf()
5531 array[DEVCONF_ENHANCED_DAD] = cnf->enhanced_dad; in ipv6_store_devconf()
5532 array[DEVCONF_ADDR_GEN_MODE] = cnf->addr_gen_mode; in ipv6_store_devconf()
5533 array[DEVCONF_DISABLE_POLICY] = cnf->disable_policy; in ipv6_store_devconf()
5534 array[DEVCONF_NDISC_TCLASS] = cnf->ndisc_tclass; in ipv6_store_devconf()
5535 array[DEVCONF_RPL_SEG_ENABLED] = cnf->rpl_seg_enabled; in ipv6_store_devconf()
5565 int pad = bytes - sizeof(u64) * ICMP6_MIB_MAX; in __snmp6_fill_statsdev()
5581 int pad = bytes - sizeof(u64) * IPSTATS_MIB_MAX; in __snmp6_fill_stats64()
5602 __snmp6_fill_stats64(stats, idev->stats.ipv6, bytes, in snmp6_fill_stats()
5606 __snmp6_fill_statsdev(stats, idev->stats.icmpv6dev->mibs, bytes); in snmp6_fill_stats()
5617 if (nla_put_u32(skb, IFLA_INET6_FLAGS, idev->if_flags)) in inet6_fill_ifla6_attrs()
5620 ci.tstamp = cstamp_delta(idev->tstamp); in inet6_fill_ifla6_attrs()
5621 ci.reachable_time = jiffies_to_msecs(idev->nd_parms->reachable_time); in inet6_fill_ifla6_attrs()
5622 ci.retrans_time = jiffies_to_msecs(NEIGH_VAR(idev->nd_parms, RETRANS_TIME)); in inet6_fill_ifla6_attrs()
5628 ipv6_store_devconf(&idev->cnf, nla_data(nla), nla_len(nla)); in inet6_fill_ifla6_attrs()
5630 /* XXX - MC not implemented */ in inet6_fill_ifla6_attrs()
5648 read_lock_bh(&idev->lock); in inet6_fill_ifla6_attrs()
5649 memcpy(nla_data(nla), idev->token.s6_addr, nla_len(nla)); in inet6_fill_ifla6_attrs()
5650 read_unlock_bh(&idev->lock); in inet6_fill_ifla6_attrs()
5652 if (nla_put_u8(skb, IFLA_INET6_ADDR_GEN_MODE, idev->cnf.addr_gen_mode)) in inet6_fill_ifla6_attrs()
5658 return -EMSGSIZE; in inet6_fill_ifla6_attrs()
5676 return -ENODATA; in inet6_fill_link_af()
5679 return -EMSGSIZE; in inet6_fill_link_af()
5687 struct net_device *dev = idev->dev; in inet6_set_iftoken()
5694 return -EINVAL; in inet6_set_iftoken()
5695 if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) in inet6_set_iftoken()
5696 return -EINVAL; in inet6_set_iftoken()
5698 return -EINVAL; in inet6_set_iftoken()
5699 if (idev->cnf.rtr_solicits == 0) in inet6_set_iftoken()
5700 return -EINVAL; in inet6_set_iftoken()
5702 write_lock_bh(&idev->lock); in inet6_set_iftoken()
5704 BUILD_BUG_ON(sizeof(token->s6_addr) != 16); in inet6_set_iftoken()
5705 memcpy(idev->token.s6_addr + 8, token->s6_addr + 8, 8); in inet6_set_iftoken()
5707 write_unlock_bh(&idev->lock); in inet6_set_iftoken()
5713 if (!idev->dead && (idev->if_flags & IF_READY) && in inet6_set_iftoken()
5724 write_lock_bh(&idev->lock); in inet6_set_iftoken()
5727 idev->if_flags |= IF_RS_SENT; in inet6_set_iftoken()
5728 idev->rs_interval = rfc3315_s14_backoff_init( in inet6_set_iftoken()
5729 idev->cnf.rtr_solicit_interval); in inet6_set_iftoken()
5730 idev->rs_probes = 1; in inet6_set_iftoken()
5731 addrconf_mod_rs_timer(idev, idev->rs_interval); in inet6_set_iftoken()
5735 list_for_each_entry(ifp, &idev->addr_list, if_list) { in inet6_set_iftoken()
5736 spin_lock(&ifp->lock); in inet6_set_iftoken()
5737 if (ifp->tokenized) { in inet6_set_iftoken()
5738 ifp->valid_lft = 0; in inet6_set_iftoken()
5739 ifp->prefered_lft = 0; in inet6_set_iftoken()
5741 spin_unlock(&ifp->lock); in inet6_set_iftoken()
5744 write_unlock_bh(&idev->lock); in inet6_set_iftoken()
5761 return -EINVAL; in check_addr_gen_mode()
5769 !idev->cnf.stable_secret.initialized && in check_stable_privacy()
5770 !net->ipv6.devconf_dflt->stable_secret.initialized) in check_stable_privacy()
5771 return -EINVAL; in check_stable_privacy()
5785 return -EAFNOSUPPORT; in inet6_validate_link_af()
5794 return -EINVAL; in inet6_validate_link_af()
5800 return -EINVAL; in inet6_validate_link_af()
5802 return -EINVAL; in inet6_validate_link_af()
5815 return -EAFNOSUPPORT; in inet6_set_link_af()
5818 return -EINVAL; in inet6_set_link_af()
5829 idev->cnf.addr_gen_mode = mode; in inet6_set_link_af()
5838 struct net_device *dev = idev->dev; in inet6_fill_ifinfo()
5845 return -EMSGSIZE; in inet6_fill_ifinfo()
5848 hdr->ifi_family = AF_INET6; in inet6_fill_ifinfo()
5849 hdr->__ifi_pad = 0; in inet6_fill_ifinfo()
5850 hdr->ifi_type = dev->type; in inet6_fill_ifinfo()
5851 hdr->ifi_index = dev->ifindex; in inet6_fill_ifinfo()
5852 hdr->ifi_flags = dev_get_flags(dev); in inet6_fill_ifinfo()
5853 hdr->ifi_change = 0; in inet6_fill_ifinfo()
5855 if (nla_put_string(skb, IFLA_IFNAME, dev->name) || in inet6_fill_ifinfo()
5856 (dev->addr_len && in inet6_fill_ifinfo()
5857 nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || in inet6_fill_ifinfo()
5858 nla_put_u32(skb, IFLA_MTU, dev->mtu) || in inet6_fill_ifinfo()
5859 (dev->ifindex != dev_get_iflink(dev) && in inet6_fill_ifinfo()
5862 netif_running(dev) ? dev->operstate : IF_OPER_DOWN)) in inet6_fill_ifinfo()
5877 return -EMSGSIZE; in inet6_fill_ifinfo()
5885 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in inet6_valid_dump_ifinfo()
5887 return -EINVAL; in inet6_valid_dump_ifinfo()
5892 return -EINVAL; in inet6_valid_dump_ifinfo()
5896 if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || in inet6_valid_dump_ifinfo()
5897 ifm->ifi_change || ifm->ifi_index) { in inet6_valid_dump_ifinfo()
5899 return -EINVAL; in inet6_valid_dump_ifinfo()
5907 struct net *net = sock_net(skb->sk); in inet6_dump_ifinfo()
5917 if (cb->strict_check) { in inet6_dump_ifinfo()
5918 int err = inet6_valid_dump_ifinfo(cb->nlh, cb->extack); in inet6_dump_ifinfo()
5924 s_h = cb->args[0]; in inet6_dump_ifinfo()
5925 s_idx = cb->args[1]; in inet6_dump_ifinfo()
5930 head = &net->dev_index_head[h]; in inet6_dump_ifinfo()
5938 NETLINK_CB(cb->skb).portid, in inet6_dump_ifinfo()
5939 cb->nlh->nlmsg_seq, in inet6_dump_ifinfo()
5948 cb->args[1] = idx; in inet6_dump_ifinfo()
5949 cb->args[0] = h; in inet6_dump_ifinfo()
5951 return skb->len; in inet6_dump_ifinfo()
5957 struct net *net = dev_net(idev->dev); in inet6_ifinfo_notify()
5958 int err = -ENOBUFS; in inet6_ifinfo_notify()
5966 /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */ in inet6_ifinfo_notify()
5967 WARN_ON(err == -EMSGSIZE); in inet6_ifinfo_notify()
5995 return -EMSGSIZE; in inet6_fill_prefix()
5998 pmsg->prefix_family = AF_INET6; in inet6_fill_prefix()
5999 pmsg->prefix_pad1 = 0; in inet6_fill_prefix()
6000 pmsg->prefix_pad2 = 0; in inet6_fill_prefix()
6001 pmsg->prefix_ifindex = idev->dev->ifindex; in inet6_fill_prefix()
6002 pmsg->prefix_len = pinfo->prefix_len; in inet6_fill_prefix()
6003 pmsg->prefix_type = pinfo->type; in inet6_fill_prefix()
6004 pmsg->prefix_pad3 = 0; in inet6_fill_prefix()
6005 pmsg->prefix_flags = 0; in inet6_fill_prefix()
6006 if (pinfo->onlink) in inet6_fill_prefix()
6007 pmsg->prefix_flags |= IF_PREFIX_ONLINK; in inet6_fill_prefix()
6008 if (pinfo->autoconf) in inet6_fill_prefix()
6009 pmsg->prefix_flags |= IF_PREFIX_AUTOCONF; in inet6_fill_prefix()
6011 if (nla_put(skb, PREFIX_ADDRESS, sizeof(pinfo->prefix), &pinfo->prefix)) in inet6_fill_prefix()
6013 ci.preferred_time = ntohl(pinfo->prefered); in inet6_fill_prefix()
6014 ci.valid_time = ntohl(pinfo->valid); in inet6_fill_prefix()
6022 return -EMSGSIZE; in inet6_fill_prefix()
6029 struct net *net = dev_net(idev->dev); in inet6_prefix_notify()
6030 int err = -ENOBUFS; in inet6_prefix_notify()
6038 /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */ in inet6_prefix_notify()
6039 WARN_ON(err == -EMSGSIZE); in inet6_prefix_notify()
6052 struct net *net = dev_net(ifp->idev->dev); in __ipv6_ifa_notify()
6062 * If the address was optimistic we inserted the route at the in __ipv6_ifa_notify()
6066 * host route, so nothing to insert. That will be fixed when in __ipv6_ifa_notify()
6069 if (ifp->rt && !rcu_access_pointer(ifp->rt->fib6_node)) { in __ipv6_ifa_notify()
6070 ip6_ins_rt(net, ifp->rt); in __ipv6_ifa_notify()
6071 } else if (!ifp->rt && (ifp->idev->dev->flags & IFF_UP)) { in __ipv6_ifa_notify()
6072 pr_warn("BUG: Address %pI6c on device %s is missing its host route.\n", in __ipv6_ifa_notify()
6073 &ifp->addr, ifp->idev->dev->name); in __ipv6_ifa_notify()
6076 if (ifp->idev->cnf.forwarding) in __ipv6_ifa_notify()
6078 if (!ipv6_addr_any(&ifp->peer_addr)) in __ipv6_ifa_notify()
6079 addrconf_prefix_route(&ifp->peer_addr, 128, in __ipv6_ifa_notify()
6080 ifp->rt_priority, ifp->idev->dev, in __ipv6_ifa_notify()
6084 if (ifp->idev->cnf.forwarding) in __ipv6_ifa_notify()
6086 addrconf_leave_solict(ifp->idev, &ifp->addr); in __ipv6_ifa_notify()
6087 if (!ipv6_addr_any(&ifp->peer_addr)) { in __ipv6_ifa_notify()
6090 rt = addrconf_get_prefix_route(&ifp->peer_addr, 128, in __ipv6_ifa_notify()
6091 ifp->idev->dev, 0, 0, in __ipv6_ifa_notify()
6096 if (ifp->rt) { in __ipv6_ifa_notify()
6097 ip6_del_rt(net, ifp->rt, false); in __ipv6_ifa_notify()
6098 ifp->rt = NULL; in __ipv6_ifa_notify()
6103 atomic_inc(&net->ipv6.dev_addr_genid); in __ipv6_ifa_notify()
6109 if (likely(ifp->idev->dead == 0)) in ipv6_ifa_notify()
6119 int *valp = ctl->data; in addrconf_sysctl_forward()
6126 * ctl->data points to idev->cnf.forwarding, we should in addrconf_sysctl_forward()
6144 struct inet6_dev *idev = ctl->extra1; in addrconf_sysctl_mtu()
6150 lctl.extra2 = idev ? &idev->dev->mtu : NULL; in addrconf_sysctl_mtu()
6159 if (!idev || !idev->dev) in dev_disable_change()
6162 netdev_notifier_info_init(&info, idev->dev); in dev_disable_change()
6163 if (idev->cnf.disable_ipv6) in dev_disable_change()
6177 int changed = (!idev->cnf.disable_ipv6) ^ (!newf); in addrconf_disable_change()
6178 idev->cnf.disable_ipv6 = newf; in addrconf_disable_change()
6193 net = (struct net *)table->extra2; in addrconf_disable_ipv6()
6197 if (p == &net->ipv6.devconf_dflt->disable_ipv6) { in addrconf_disable_ipv6()
6202 if (p == &net->ipv6.devconf_all->disable_ipv6) { in addrconf_disable_ipv6()
6203 net->ipv6.devconf_dflt->disable_ipv6 = newf; in addrconf_disable_ipv6()
6206 dev_disable_change((struct inet6_dev *)table->extra1); in addrconf_disable_ipv6()
6215 int *valp = ctl->data; in addrconf_sysctl_disable()
6222 * ctl->data points to idev->cnf.disable_ipv6, we should in addrconf_sysctl_disable()
6240 int *valp = ctl->data; in addrconf_sysctl_proxy_ndp()
6249 struct net *net = ctl->extra2; in addrconf_sysctl_proxy_ndp()
6254 if (valp == &net->ipv6.devconf_dflt->proxy_ndp) in addrconf_sysctl_proxy_ndp()
6258 net->ipv6.devconf_dflt); in addrconf_sysctl_proxy_ndp()
6259 else if (valp == &net->ipv6.devconf_all->proxy_ndp) in addrconf_sysctl_proxy_ndp()
6263 net->ipv6.devconf_all); in addrconf_sysctl_proxy_ndp()
6265 struct inet6_dev *idev = ctl->extra1; in addrconf_sysctl_proxy_ndp()
6269 idev->dev->ifindex, in addrconf_sysctl_proxy_ndp()
6270 &idev->cnf); in addrconf_sysctl_proxy_ndp()
6284 struct inet6_dev *idev = (struct inet6_dev *)ctl->extra1; in addrconf_sysctl_addr_gen_mode()
6285 struct net *net = (struct net *)ctl->extra2; in addrconf_sysctl_addr_gen_mode()
6289 .mode = ctl->mode, in addrconf_sysctl_addr_gen_mode()
6295 new_val = *((u32 *)ctl->data); in addrconf_sysctl_addr_gen_mode()
6303 ret = -EINVAL; in addrconf_sysctl_addr_gen_mode()
6309 ret = -EINVAL; in addrconf_sysctl_addr_gen_mode()
6313 if (idev->cnf.addr_gen_mode != new_val) { in addrconf_sysctl_addr_gen_mode()
6314 idev->cnf.addr_gen_mode = new_val; in addrconf_sysctl_addr_gen_mode()
6315 addrconf_dev_config(idev->dev); in addrconf_sysctl_addr_gen_mode()
6317 } else if (&net->ipv6.devconf_all->addr_gen_mode == ctl->data) { in addrconf_sysctl_addr_gen_mode()
6320 net->ipv6.devconf_dflt->addr_gen_mode = new_val; in addrconf_sysctl_addr_gen_mode()
6324 idev->cnf.addr_gen_mode != new_val) { in addrconf_sysctl_addr_gen_mode()
6325 idev->cnf.addr_gen_mode = new_val; in addrconf_sysctl_addr_gen_mode()
6326 addrconf_dev_config(idev->dev); in addrconf_sysctl_addr_gen_mode()
6331 *((u32 *)ctl->data) = new_val; in addrconf_sysctl_addr_gen_mode()
6348 struct net *net = ctl->extra2; in addrconf_sysctl_stable_secret()
6349 struct ipv6_stable_secret *secret = ctl->data; in addrconf_sysctl_stable_secret()
6351 if (&net->ipv6.devconf_all->stable_secret == ctl->data) in addrconf_sysctl_stable_secret()
6352 return -EIO; in addrconf_sysctl_stable_secret()
6360 if (!write && !secret->initialized) { in addrconf_sysctl_stable_secret()
6361 err = -EIO; in addrconf_sysctl_stable_secret()
6365 err = snprintf(str, sizeof(str), "%pI6", &secret->secret); in addrconf_sysctl_stable_secret()
6367 err = -EIO; in addrconf_sysctl_stable_secret()
6375 if (in6_pton(str, -1, addr.in6_u.u6_addr8, -1, NULL) != 1) { in addrconf_sysctl_stable_secret()
6376 err = -EIO; in addrconf_sysctl_stable_secret()
6380 secret->initialized = true; in addrconf_sysctl_stable_secret()
6381 secret->secret = addr; in addrconf_sysctl_stable_secret()
6383 if (&net->ipv6.devconf_dflt->stable_secret == ctl->data) { in addrconf_sysctl_stable_secret()
6390 idev->cnf.addr_gen_mode = in addrconf_sysctl_stable_secret()
6395 struct inet6_dev *idev = ctl->extra1; in addrconf_sysctl_stable_secret()
6397 idev->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_STABLE_PRIVACY; in addrconf_sysctl_stable_secret()
6412 int *valp = ctl->data; in addrconf_sysctl_ignore_routes_with_linkdown()
6418 /* ctl->data points to idev->cnf.ignore_routes_when_linkdown in addrconf_sysctl_ignore_routes_with_linkdown()
6438 rt->dst.flags |= DST_NOPOLICY; in addrconf_set_nopolicy()
6440 rt->dst.flags &= ~DST_NOPOLICY; in addrconf_set_nopolicy()
6449 read_lock_bh(&idev->lock); in addrconf_disable_policy_idev()
6450 list_for_each_entry(ifa, &idev->addr_list, if_list) { in addrconf_disable_policy_idev()
6451 spin_lock(&ifa->lock); in addrconf_disable_policy_idev()
6452 if (ifa->rt) { in addrconf_disable_policy_idev()
6454 struct fib6_nh *nh = ifa->rt->fib6_nh; in addrconf_disable_policy_idev()
6458 ifa->rt->dst_nopolicy = val ? true : false; in addrconf_disable_policy_idev()
6459 if (nh->rt6i_pcpu) { in addrconf_disable_policy_idev()
6463 rtp = per_cpu_ptr(nh->rt6i_pcpu, cpu); in addrconf_disable_policy_idev()
6469 spin_unlock(&ifa->lock); in addrconf_disable_policy_idev()
6471 read_unlock_bh(&idev->lock); in addrconf_disable_policy_idev()
6485 net = (struct net *)ctl->extra2; in addrconf_disable_policy()
6486 if (valp == &net->ipv6.devconf_dflt->disable_policy) { in addrconf_disable_policy()
6491 if (valp == &net->ipv6.devconf_all->disable_policy) { in addrconf_disable_policy()
6500 idev = (struct inet6_dev *)ctl->extra1; in addrconf_disable_policy()
6511 int *valp = ctl->data; in addrconf_sysctl_disable_policy()
6530 static int minus_one = -1;
6933 table[i].data += (char *)p - (char *)&ipv6_devconf; in __addrconf_sysctl_register()
6946 p->sysctl_header = register_net_sysctl(net, path, table); in __addrconf_sysctl_register()
6947 if (!p->sysctl_header) in __addrconf_sysctl_register()
6955 ifindex = idev->dev->ifindex; in __addrconf_sysctl_register()
6963 return -ENOBUFS; in __addrconf_sysctl_register()
6971 if (!p->sysctl_header) in __addrconf_sysctl_unregister()
6974 table = p->sysctl_header->ctl_table_arg; in __addrconf_sysctl_unregister()
6975 unregister_net_sysctl_table(p->sysctl_header); in __addrconf_sysctl_unregister()
6976 p->sysctl_header = NULL; in __addrconf_sysctl_unregister()
6986 if (!sysctl_dev_name_is_allowed(idev->dev->name)) in addrconf_sysctl_register()
6987 return -EINVAL; in addrconf_sysctl_register()
6989 err = neigh_sysctl_register(idev->dev, idev->nd_parms, in addrconf_sysctl_register()
6993 err = __addrconf_sysctl_register(dev_net(idev->dev), idev->dev->name, in addrconf_sysctl_register()
6994 idev, &idev->cnf); in addrconf_sysctl_register()
6996 neigh_sysctl_unregister(idev->nd_parms); in addrconf_sysctl_register()
7003 __addrconf_sysctl_unregister(dev_net(idev->dev), &idev->cnf, in addrconf_sysctl_unregister()
7004 idev->dev->ifindex); in addrconf_sysctl_unregister()
7005 neigh_sysctl_unregister(idev->nd_parms); in addrconf_sysctl_unregister()
7013 int err = -ENOMEM; in addrconf_init_net()
7034 memcpy(all, current->nsproxy->net_ns->ipv6.devconf_all, in addrconf_init_net()
7037 current->nsproxy->net_ns->ipv6.devconf_dflt, in addrconf_init_net()
7048 dflt->autoconf = ipv6_defaults.autoconf; in addrconf_init_net()
7049 dflt->disable_ipv6 = ipv6_defaults.disable_ipv6; in addrconf_init_net()
7051 dflt->stable_secret.initialized = false; in addrconf_init_net()
7052 all->stable_secret.initialized = false; in addrconf_init_net()
7054 net->ipv6.devconf_all = all; in addrconf_init_net()
7055 net->ipv6.devconf_dflt = dflt; in addrconf_init_net()
7083 __addrconf_sysctl_unregister(net, net->ipv6.devconf_dflt, in addrconf_exit_net()
7085 __addrconf_sysctl_unregister(net, net->ipv6.devconf_all, in addrconf_exit_net()
7088 kfree(net->ipv6.devconf_dflt); in addrconf_exit_net()
7089 kfree(net->ipv6.devconf_all); in addrconf_exit_net()
7127 err = -ENOMEM; in addrconf_init()
7133 * before it can bring up and give link-local addresses in addrconf_init()
7140 * give link-local addresses to all devices besides loopback_dev in addrconf_init()
7141 * first, then loopback_dev, which cases all the non-loopback_dev in addrconf_init()
7142 * devices to fail to get a link-local address. in addrconf_init()