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()
2488 if (idev->cnf.disable_ipv6) in addrconf_add_dev()
2489 return ERR_PTR(-EACCES); in addrconf_add_dev()
2491 /* Add default multicast route */ in addrconf_add_dev()
2492 if (!(dev->flags & IFF_LOOPBACK) && !netif_is_l3_master(dev)) in addrconf_add_dev()
2506 read_lock_bh(&idev->lock); in manage_tempaddrs()
2508 list_for_each_entry(ift, &idev->tempaddr_list, tmp_list) { in manage_tempaddrs()
2511 if (ifp != ift->ifpub) in manage_tempaddrs()
2520 * (TEMP_PREFERRED_LIFETIME - DESYNC_FACTOR), respectively. in manage_tempaddrs()
2522 age = (now - ift->cstamp) / HZ; in manage_tempaddrs()
2523 max_valid = idev->cnf.temp_valid_lft - age; in manage_tempaddrs()
2527 max_prefered = idev->cnf.temp_prefered_lft - in manage_tempaddrs()
2528 idev->desync_factor - age; in manage_tempaddrs()
2538 spin_lock(&ift->lock); in manage_tempaddrs()
2539 flags = ift->flags; in manage_tempaddrs()
2540 ift->valid_lft = valid_lft; in manage_tempaddrs()
2541 ift->prefered_lft = prefered_lft; in manage_tempaddrs()
2542 ift->tstamp = now; in manage_tempaddrs()
2544 ift->flags &= ~IFA_F_DEPRECATED; in manage_tempaddrs()
2546 spin_unlock(&ift->lock); in manage_tempaddrs()
2551 if ((create || list_empty(&idev->tempaddr_list)) && in manage_tempaddrs()
2552 idev->cnf.use_tempaddr > 0) { in manage_tempaddrs()
2558 read_unlock_bh(&idev->lock); in manage_tempaddrs()
2561 read_unlock_bh(&idev->lock); in manage_tempaddrs()
2567 return idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_STABLE_PRIVACY || in is_addr_mode_generate_stable()
2568 idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_RANDOM; in is_addr_mode_generate_stable()
2582 int max_addresses = in6_dev->cnf.max_addresses; in addrconf_prefix_rcv_add_addr()
2585 .plen = pinfo->prefix_len, in addrconf_prefix_rcv_add_addr()
2593 if ((net->ipv6.devconf_all->optimistic_dad || in addrconf_prefix_rcv_add_addr()
2594 in6_dev->cnf.optimistic_dad) && in addrconf_prefix_rcv_add_addr()
2595 !net->ipv6.devconf_all->forwarding && sllao) in addrconf_prefix_rcv_add_addr()
2607 return -1; in addrconf_prefix_rcv_add_addr()
2610 spin_lock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2611 ifp->flags |= IFA_F_MANAGETEMPADDR; in addrconf_prefix_rcv_add_addr()
2612 ifp->cstamp = jiffies; in addrconf_prefix_rcv_add_addr()
2613 ifp->tokenized = tokenized; in addrconf_prefix_rcv_add_addr()
2614 spin_unlock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2626 * (draft-gont-6man-slaac-renum-06, Section 4.2) in addrconf_prefix_rcv_add_addr()
2628 spin_lock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2630 if (ifp->valid_lft > (now - ifp->tstamp) / HZ) in addrconf_prefix_rcv_add_addr()
2631 stored_lft = ifp->valid_lft - (now - ifp->tstamp) / HZ; in addrconf_prefix_rcv_add_addr()
2636 ifp->valid_lft = valid_lft; in addrconf_prefix_rcv_add_addr()
2637 ifp->prefered_lft = prefered_lft; in addrconf_prefix_rcv_add_addr()
2638 ifp->tstamp = now; in addrconf_prefix_rcv_add_addr()
2639 flags = ifp->flags; in addrconf_prefix_rcv_add_addr()
2640 ifp->flags &= ~IFA_F_DEPRECATED; in addrconf_prefix_rcv_add_addr()
2641 spin_unlock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2646 spin_unlock_bh(&ifp->lock); in addrconf_prefix_rcv_add_addr()
2680 addr_type = ipv6_addr_type(&pinfo->prefix); in addrconf_prefix_rcv()
2685 valid_lft = ntohl(pinfo->valid); in addrconf_prefix_rcv()
2686 prefered_lft = ntohl(pinfo->prefered); in addrconf_prefix_rcv()
2697 dev->name); in addrconf_prefix_rcv()
2703 * 1) Add routes for on-link prefixes in addrconf_prefix_rcv()
2707 if (pinfo->onlink) { in addrconf_prefix_rcv()
2724 rt = addrconf_get_prefix_route(&pinfo->prefix, in addrconf_prefix_rcv()
2725 pinfo->prefix_len, in addrconf_prefix_rcv()
2731 /* Autoconf prefix route */ in addrconf_prefix_rcv()
2749 addrconf_prefix_route(&pinfo->prefix, pinfo->prefix_len, in addrconf_prefix_rcv()
2758 if (pinfo->autoconf && in6_dev->cnf.autoconf) { in addrconf_prefix_rcv()
2762 if (pinfo->prefix_len == 64) { in addrconf_prefix_rcv()
2763 memcpy(&addr, &pinfo->prefix, 8); in addrconf_prefix_rcv()
2765 if (!ipv6_addr_any(&in6_dev->token)) { in addrconf_prefix_rcv()
2766 read_lock_bh(&in6_dev->lock); in addrconf_prefix_rcv()
2768 in6_dev->token.s6_addr + 8, 8); in addrconf_prefix_rcv()
2769 read_unlock_bh(&in6_dev->lock); in addrconf_prefix_rcv()
2785 pinfo->prefix_len); in addrconf_prefix_rcv()
2817 if (!(ipv6_addr_type(&ireq->ifr6_addr) & IPV6_ADDR_COMPATv4)) in addrconf_set_sit_dstaddr()
2818 return -EADDRNOTAVAIL; in addrconf_set_sit_dstaddr()
2820 p.iph.daddr = ireq->ifr6_addr.s6_addr32[3]; in addrconf_set_sit_dstaddr()
2826 if (!dev->netdev_ops->ndo_tunnel_ctl) in addrconf_set_sit_dstaddr()
2827 return -EOPNOTSUPP; in addrconf_set_sit_dstaddr()
2828 err = dev->netdev_ops->ndo_tunnel_ctl(dev, &p, SIOCADDTUNNEL); in addrconf_set_sit_dstaddr()
2834 return -ENOBUFS; in addrconf_set_sit_dstaddr()
2847 int err = -ENODEV; in addrconf_set_dstaddr()
2850 return -ENODEV; in addrconf_set_dstaddr()
2852 return -EFAULT; in addrconf_set_dstaddr()
2856 if (dev && dev->type == ARPHRD_SIT) in addrconf_set_dstaddr()
2895 if (cfg->plen > 128) in inet6_addr_add()
2896 return -EINVAL; in inet6_addr_add()
2899 if (!cfg->valid_lft || cfg->preferred_lft > cfg->valid_lft) in inet6_addr_add()
2900 return -EINVAL; in inet6_addr_add()
2902 if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR && cfg->plen != 64) in inet6_addr_add()
2903 return -EINVAL; in inet6_addr_add()
2907 return -ENODEV; in inet6_addr_add()
2913 if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) { in inet6_addr_add()
2914 int ret = ipv6_mc_config(net->ipv6.mc_autojoin_sk, in inet6_addr_add()
2915 true, cfg->pfx, ifindex); in inet6_addr_add()
2921 cfg->scope = ipv6_addr_scope(cfg->pfx); in inet6_addr_add()
2923 timeout = addrconf_timeout_fixup(cfg->valid_lft, HZ); in inet6_addr_add()
2926 cfg->valid_lft = timeout; in inet6_addr_add()
2931 cfg->ifa_flags |= IFA_F_PERMANENT; in inet6_addr_add()
2934 timeout = addrconf_timeout_fixup(cfg->preferred_lft, HZ); in inet6_addr_add()
2937 cfg->ifa_flags |= IFA_F_DEPRECATED; in inet6_addr_add()
2938 cfg->preferred_lft = timeout; in inet6_addr_add()
2943 if (!(cfg->ifa_flags & IFA_F_NOPREFIXROUTE)) { in inet6_addr_add()
2944 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, in inet6_addr_add()
2945 ifp->rt_priority, dev, expires, in inet6_addr_add()
2952 if (!(ifp->flags & (IFA_F_OPTIMISTIC | IFA_F_NODAD))) in inet6_addr_add()
2960 if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR) in inet6_addr_add()
2961 manage_tempaddrs(idev, ifp, cfg->valid_lft, in inet6_addr_add()
2962 cfg->preferred_lft, true, jiffies); in inet6_addr_add()
2966 } else if (cfg->ifa_flags & IFA_F_MCAUTOJOIN) { in inet6_addr_add()
2967 ipv6_mc_config(net->ipv6.mc_autojoin_sk, false, in inet6_addr_add()
2968 cfg->pfx, ifindex); in inet6_addr_add()
2982 return -EINVAL; in inet6_addr_del()
2986 return -ENODEV; in inet6_addr_del()
2990 return -ENXIO; in inet6_addr_del()
2992 read_lock_bh(&idev->lock); in inet6_addr_del()
2993 list_for_each_entry(ifp, &idev->addr_list, if_list) { in inet6_addr_del()
2994 if (ifp->prefix_len == plen && in inet6_addr_del()
2995 ipv6_addr_equal(pfx, &ifp->addr)) { in inet6_addr_del()
2997 read_unlock_bh(&idev->lock); in inet6_addr_del()
2999 if (!(ifp->flags & IFA_F_TEMPORARY) && in inet6_addr_del()
3006 ipv6_mc_config(net->ipv6.mc_autojoin_sk, in inet6_addr_del()
3007 false, pfx, dev->ifindex); in inet6_addr_del()
3012 read_unlock_bh(&idev->lock); in inet6_addr_del()
3013 return -EADDRNOTAVAIL; in inet6_addr_del()
3027 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in addrconf_add_ifaddr()
3028 return -EPERM; in addrconf_add_ifaddr()
3031 return -EFAULT; in addrconf_add_ifaddr()
3047 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in addrconf_del_ifaddr()
3048 return -EPERM; in addrconf_del_ifaddr()
3051 return -EFAULT; in addrconf_del_ifaddr()
3075 spin_lock_bh(&ifp->lock); in add_addr()
3076 ifp->flags &= ~IFA_F_TENTATIVE; in add_addr()
3077 spin_unlock_bh(&ifp->lock); in add_addr()
3078 rt_genid_bump_ipv6(dev_net(idev->dev)); in add_addr()
3089 struct net *net = dev_net(idev->dev); in sit_add_v4_addrs()
3096 memcpy(&addr.s6_addr32[3], idev->dev->dev_addr, 4); in sit_add_v4_addrs()
3098 if (idev->dev->flags&IFF_POINTOPOINT) { in sit_add_v4_addrs()
3110 addrconf_prefix_route(&addr, plen, 0, idev->dev, 0, pflags, in sit_add_v4_addrs()
3117 if (in_dev && (dev->flags & IFF_UP)) { in sit_add_v4_addrs()
3122 addr.s6_addr32[3] = ifa->ifa_local; in sit_add_v4_addrs()
3124 if (ifa->ifa_scope == RT_SCOPE_LINK) in sit_add_v4_addrs()
3126 if (ifa->ifa_scope >= RT_SCOPE_HOST) { in sit_add_v4_addrs()
3127 if (idev->dev->flags&IFF_POINTOPOINT) in sit_add_v4_addrs()
3133 addrconf_prefix_route(&addr, plen, 0, idev->dev, in sit_add_v4_addrs()
3172 if ((dev_net(idev->dev)->ipv6.devconf_all->optimistic_dad || in addrconf_add_linklocal()
3173 idev->cnf.optimistic_dad) && in addrconf_add_linklocal()
3174 !dev_net(idev->dev)->ipv6.devconf_all->forwarding) in addrconf_add_linklocal()
3180 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, 0, idev->dev, in addrconf_add_linklocal()
3224 struct net *net = dev_net(idev->dev); in ipv6_generate_stable_address()
3228 if (idev->cnf.stable_secret.initialized) in ipv6_generate_stable_address()
3229 secret = idev->cnf.stable_secret.secret; in ipv6_generate_stable_address()
3230 else if (net->ipv6.devconf_dflt->stable_secret.initialized) in ipv6_generate_stable_address()
3231 secret = net->ipv6.devconf_dflt->stable_secret.secret; in ipv6_generate_stable_address()
3233 return -1; in ipv6_generate_stable_address()
3241 memcpy(data.hwaddr, idev->dev->perm_addr, idev->dev->addr_len); in ipv6_generate_stable_address()
3242 data.prefix[0] = address->s6_addr32[0]; in ipv6_generate_stable_address()
3243 data.prefix[1] = address->s6_addr32[1]; in ipv6_generate_stable_address()
3257 if (dad_count > dev_net(idev->dev)->ipv6.sysctl.idgen_retries) in ipv6_generate_stable_address()
3258 return -1; in ipv6_generate_stable_address()
3268 struct ipv6_stable_secret *s = &idev->cnf.stable_secret; in ipv6_gen_mode_random_init()
3270 if (s->initialized) in ipv6_gen_mode_random_init()
3272 s = &idev->cnf.stable_secret; in ipv6_gen_mode_random_init()
3273 get_random_bytes(&s->secret, sizeof(s->secret)); in ipv6_gen_mode_random_init()
3274 s->initialized = true; in ipv6_gen_mode_random_init()
3282 if (netif_is_l3_master(idev->dev)) in addrconf_addr_gen()
3286 if (idev->dev->flags & IFF_SLAVE) in addrconf_addr_gen()
3291 switch (idev->cnf.addr_gen_mode) { in addrconf_addr_gen()
3300 addrconf_prefix_route(&addr, 64, 0, idev->dev, in addrconf_addr_gen()
3308 if (ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) == 0) in addrconf_addr_gen()
3311 addrconf_prefix_route(&addr, 64, 0, idev->dev, in addrconf_addr_gen()
3327 if ((dev->type != ARPHRD_ETHER) && in addrconf_dev_config()
3328 (dev->type != ARPHRD_FDDI) && in addrconf_dev_config()
3329 (dev->type != ARPHRD_ARCNET) && in addrconf_dev_config()
3330 (dev->type != ARPHRD_INFINIBAND) && in addrconf_dev_config()
3331 (dev->type != ARPHRD_IEEE1394) && in addrconf_dev_config()
3332 (dev->type != ARPHRD_TUNNEL6) && in addrconf_dev_config()
3333 (dev->type != ARPHRD_6LOWPAN) && in addrconf_dev_config()
3334 (dev->type != ARPHRD_IP6GRE) && in addrconf_dev_config()
3335 (dev->type != ARPHRD_IPGRE) && in addrconf_dev_config()
3336 (dev->type != ARPHRD_TUNNEL) && in addrconf_dev_config()
3337 (dev->type != ARPHRD_NONE) && in addrconf_dev_config()
3338 (dev->type != ARPHRD_RAWIP)) { in addrconf_dev_config()
3341 if (!IS_ERR_OR_NULL(idev) && dev->flags & IFF_UP && in addrconf_dev_config()
3342 dev->flags & IFF_MULTICAST) in addrconf_dev_config()
3352 if (dev->type == ARPHRD_NONE && in addrconf_dev_config()
3353 idev->cnf.addr_gen_mode == IN6_ADDR_GEN_MODE_EUI64) in addrconf_dev_config()
3354 idev->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_RANDOM; in addrconf_dev_config()
3378 if (dev->priv_flags & IFF_ISATAP) { in addrconf_sit_config()
3385 if (dev->flags&IFF_POINTOPOINT) in addrconf_sit_config()
3404 if (dev->flags & IFF_POINTOPOINT) in addrconf_gre_config()
3413 /* !fib6_node means the host route was removed from the in fixup_permanent_addr()
3415 * case regenerate the host route. in fixup_permanent_addr()
3417 if (!ifp->rt || !ifp->rt->fib6_node) { in fixup_permanent_addr()
3420 f6i = addrconf_f6i_alloc(net, idev, &ifp->addr, false, in fixup_permanent_addr()
3425 /* ifp->rt can be accessed outside of rtnl */ in fixup_permanent_addr()
3426 spin_lock(&ifp->lock); in fixup_permanent_addr()
3427 prev = ifp->rt; in fixup_permanent_addr()
3428 ifp->rt = f6i; in fixup_permanent_addr()
3429 spin_unlock(&ifp->lock); in fixup_permanent_addr()
3434 if (!(ifp->flags & IFA_F_NOPREFIXROUTE)) { in fixup_permanent_addr()
3435 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, in fixup_permanent_addr()
3436 ifp->rt_priority, idev->dev, 0, 0, in fixup_permanent_addr()
3440 if (ifp->state == INET6_IFADDR_STATE_PREDAD) in fixup_permanent_addr()
3455 write_lock_bh(&idev->lock); in addrconf_permanent_addr()
3457 list_for_each_entry_safe(ifp, tmp, &idev->addr_list, if_list) { in addrconf_permanent_addr()
3458 if ((ifp->flags & IFA_F_PERMANENT) && in addrconf_permanent_addr()
3460 write_unlock_bh(&idev->lock); in addrconf_permanent_addr()
3463 write_lock_bh(&idev->lock); in addrconf_permanent_addr()
3465 net_info_ratelimited("%s: Failed to add prefix route for address %pI6c; dropping\n", in addrconf_permanent_addr()
3466 idev->dev->name, &ifp->addr); in addrconf_permanent_addr()
3470 write_unlock_bh(&idev->lock); in addrconf_permanent_addr()
3486 if (!idev && dev->mtu >= IPV6_MIN_MTU) { in addrconf_notify()
3495 if (dev->mtu < IPV6_MIN_MTU) { in addrconf_notify()
3496 addrconf_ifdown(dev, dev != net->loopback_dev); in addrconf_notify()
3501 rt6_mtu_change(dev, dev->mtu); in addrconf_notify()
3502 idev->cnf.mtu6 = dev->mtu; in addrconf_notify()
3512 if (!(idev->if_flags & IF_READY)) in addrconf_notify()
3519 if (dev->flags & IFF_SLAVE) in addrconf_notify()
3522 if (idev && idev->cnf.disable_ipv6) in addrconf_notify()
3532 dev->name); in addrconf_notify()
3536 if (!idev && dev->mtu >= IPV6_MIN_MTU) in addrconf_notify()
3540 idev->if_flags |= IF_READY; in addrconf_notify()
3551 if (idev->if_flags & IF_READY) { in addrconf_notify()
3552 /* device is already configured - in addrconf_notify()
3559 if (change_info->flags_changed & IFF_NOARP) in addrconf_notify()
3564 idev->if_flags |= IF_READY; in addrconf_notify()
3568 dev->name); in addrconf_notify()
3573 switch (dev->type) { in addrconf_notify()
3605 if (idev->cnf.mtu6 != dev->mtu && in addrconf_notify()
3606 dev->mtu >= IPV6_MIN_MTU) { in addrconf_notify()
3607 rt6_mtu_change(dev, dev->mtu); in addrconf_notify()
3608 idev->cnf.mtu6 = dev->mtu; in addrconf_notify()
3610 idev->tstamp = jiffies; in addrconf_notify()
3617 if (dev->mtu < IPV6_MIN_MTU) in addrconf_notify()
3618 addrconf_ifdown(dev, dev != net->loopback_dev); in addrconf_notify()
3657 if (info->upper_dev && netif_is_l3_master(info->upper_dev)) in addrconf_notify()
3706 return -ENODEV; in addrconf_ifdown()
3713 idev->dead = 1; in addrconf_ifdown()
3716 RCU_INIT_POINTER(dev->ip6_ptr, NULL); in addrconf_ifdown()
3726 if (!unregister && !idev->cnf.disable_ipv6) { in addrconf_ifdown()
3728 int _keep_addr = net->ipv6.devconf_all->keep_addr_on_down; in addrconf_ifdown()
3731 _keep_addr = idev->cnf.keep_addr_on_down; in addrconf_ifdown()
3743 if (ifa->idev == idev) { in addrconf_ifdown()
3749 !(ifa->flags & IFA_F_PERMANENT) || in addrconf_ifdown()
3750 addr_is_local(&ifa->addr)) { in addrconf_ifdown()
3751 hlist_del_init_rcu(&ifa->addr_lst); in addrconf_ifdown()
3759 write_lock_bh(&idev->lock); in addrconf_ifdown()
3765 idev->if_flags &= ~(IF_RS_SENT|IF_RA_RCVD|IF_READY); in addrconf_ifdown()
3768 while (!list_empty(&idev->tempaddr_list)) { in addrconf_ifdown()
3769 ifa = list_first_entry(&idev->tempaddr_list, in addrconf_ifdown()
3771 list_del(&ifa->tmp_list); in addrconf_ifdown()
3772 write_unlock_bh(&idev->lock); in addrconf_ifdown()
3773 spin_lock_bh(&ifa->lock); in addrconf_ifdown()
3775 if (ifa->ifpub) { in addrconf_ifdown()
3776 in6_ifa_put(ifa->ifpub); in addrconf_ifdown()
3777 ifa->ifpub = NULL; in addrconf_ifdown()
3779 spin_unlock_bh(&ifa->lock); in addrconf_ifdown()
3781 write_lock_bh(&idev->lock); in addrconf_ifdown()
3784 list_for_each_entry_safe(ifa, tmp, &idev->addr_list, if_list) { in addrconf_ifdown()
3790 keep = keep_addr && (ifa->flags & IFA_F_PERMANENT) && in addrconf_ifdown()
3791 !addr_is_local(&ifa->addr); in addrconf_ifdown()
3793 write_unlock_bh(&idev->lock); in addrconf_ifdown()
3794 spin_lock_bh(&ifa->lock); in addrconf_ifdown()
3799 ifa->state = INET6_IFADDR_STATE_PREDAD; in addrconf_ifdown()
3800 if (!(ifa->flags & IFA_F_NODAD)) in addrconf_ifdown()
3801 ifa->flags |= IFA_F_TENTATIVE; in addrconf_ifdown()
3803 rt = ifa->rt; in addrconf_ifdown()
3804 ifa->rt = NULL; in addrconf_ifdown()
3806 state = ifa->state; in addrconf_ifdown()
3807 ifa->state = INET6_IFADDR_STATE_DEAD; in addrconf_ifdown()
3810 spin_unlock_bh(&ifa->lock); in addrconf_ifdown()
3819 if (idev->cnf.forwarding) in addrconf_ifdown()
3821 addrconf_leave_solict(ifa->idev, &ifa->addr); in addrconf_ifdown()
3824 write_lock_bh(&idev->lock); in addrconf_ifdown()
3826 list_del_rcu(&ifa->if_list); in addrconf_ifdown()
3831 write_unlock_bh(&idev->lock); in addrconf_ifdown()
3841 idev->tstamp = jiffies; in addrconf_ifdown()
3846 neigh_parms_release(&nd_tbl, idev->nd_parms); in addrconf_ifdown()
3856 struct net_device *dev = idev->dev; in addrconf_rs_timer()
3859 write_lock(&idev->lock); in addrconf_rs_timer()
3860 if (idev->dead || !(idev->if_flags & IF_READY)) in addrconf_rs_timer()
3867 if (idev->if_flags & IF_RA_RCVD) in addrconf_rs_timer()
3870 if (idev->rs_probes++ < idev->cnf.rtr_solicits || idev->cnf.rtr_solicits < 0) { in addrconf_rs_timer()
3871 write_unlock(&idev->lock); in addrconf_rs_timer()
3878 write_lock(&idev->lock); in addrconf_rs_timer()
3879 idev->rs_interval = rfc3315_s14_backoff_update( in addrconf_rs_timer()
3880 idev->rs_interval, idev->cnf.rtr_solicit_max_interval); in addrconf_rs_timer()
3882 addrconf_mod_rs_timer(idev, (idev->rs_probes == in addrconf_rs_timer()
3883 idev->cnf.rtr_solicits) ? in addrconf_rs_timer()
3884 idev->cnf.rtr_solicit_delay : in addrconf_rs_timer()
3885 idev->rs_interval); in addrconf_rs_timer()
3888 * Note: we do not support deprecated "all on-link" in addrconf_rs_timer()
3891 pr_debug("%s: no IPv6 routers present\n", idev->dev->name); in addrconf_rs_timer()
3895 write_unlock(&idev->lock); in addrconf_rs_timer()
3906 struct inet6_dev *idev = ifp->idev; in addrconf_dad_kick()
3909 if (ifp->flags & IFA_F_OPTIMISTIC) in addrconf_dad_kick()
3912 rand_num = prandom_u32() % (idev->cnf.rtr_solicit_delay ? : 1); in addrconf_dad_kick()
3915 if (idev->cnf.enhanced_dad || in addrconf_dad_kick()
3916 dev_net(idev->dev)->ipv6.devconf_all->enhanced_dad) { in addrconf_dad_kick()
3921 ifp->dad_nonce = nonce; in addrconf_dad_kick()
3922 ifp->dad_probes = idev->cnf.dad_transmits; in addrconf_dad_kick()
3928 struct inet6_dev *idev = ifp->idev; in addrconf_dad_begin()
3929 struct net_device *dev = idev->dev; in addrconf_dad_begin()
3933 addrconf_join_solict(dev, &ifp->addr); in addrconf_dad_begin()
3935 prandom_seed((__force u32) ifp->addr.s6_addr32[3]); in addrconf_dad_begin()
3937 read_lock_bh(&idev->lock); in addrconf_dad_begin()
3938 spin_lock(&ifp->lock); in addrconf_dad_begin()
3939 if (ifp->state == INET6_IFADDR_STATE_DEAD) in addrconf_dad_begin()
3943 if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) || in addrconf_dad_begin()
3944 (net->ipv6.devconf_all->accept_dad < 1 && in addrconf_dad_begin()
3945 idev->cnf.accept_dad < 1) || in addrconf_dad_begin()
3946 !(ifp->flags&IFA_F_TENTATIVE) || in addrconf_dad_begin()
3947 ifp->flags & IFA_F_NODAD) { in addrconf_dad_begin()
3950 if (ifp->flags & IFA_F_TENTATIVE && in addrconf_dad_begin()
3951 !(ifp->flags & IFA_F_OPTIMISTIC)) in addrconf_dad_begin()
3953 bump_id = ifp->flags & IFA_F_TENTATIVE; in addrconf_dad_begin()
3954 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); in addrconf_dad_begin()
3955 spin_unlock(&ifp->lock); in addrconf_dad_begin()
3956 read_unlock_bh(&idev->lock); in addrconf_dad_begin()
3962 if (!(idev->if_flags & IF_READY)) { in addrconf_dad_begin()
3963 spin_unlock(&ifp->lock); in addrconf_dad_begin()
3964 read_unlock_bh(&idev->lock); in addrconf_dad_begin()
3967 * - keep it tentative if it is a permanent address. in addrconf_dad_begin()
3968 * - otherwise, kill it. in addrconf_dad_begin()
3979 if (ifp->flags & IFA_F_OPTIMISTIC) { in addrconf_dad_begin()
3980 ip6_ins_rt(net, ifp->rt); in addrconf_dad_begin()
3991 spin_unlock(&ifp->lock); in addrconf_dad_begin()
3992 read_unlock_bh(&idev->lock); in addrconf_dad_begin()
4001 spin_lock_bh(&ifp->lock); in addrconf_dad_start()
4002 if (ifp->state != INET6_IFADDR_STATE_DEAD) { in addrconf_dad_start()
4003 ifp->state = INET6_IFADDR_STATE_PREDAD; in addrconf_dad_start()
4006 spin_unlock_bh(&ifp->lock); in addrconf_dad_start()
4017 struct inet6_dev *idev = ifp->idev; in addrconf_dad_work()
4029 spin_lock_bh(&ifp->lock); in addrconf_dad_work()
4030 if (ifp->state == INET6_IFADDR_STATE_PREDAD) { in addrconf_dad_work()
4032 ifp->state = INET6_IFADDR_STATE_DAD; in addrconf_dad_work()
4033 } else if (ifp->state == INET6_IFADDR_STATE_ERRDAD) { in addrconf_dad_work()
4035 ifp->state = INET6_IFADDR_STATE_POSTDAD; in addrconf_dad_work()
4037 if ((dev_net(idev->dev)->ipv6.devconf_all->accept_dad > 1 || in addrconf_dad_work()
4038 idev->cnf.accept_dad > 1) && in addrconf_dad_work()
4039 !idev->cnf.disable_ipv6 && in addrconf_dad_work()
4040 !(ifp->flags & IFA_F_STABLE_PRIVACY)) { in addrconf_dad_work()
4046 if (!ipv6_generate_eui64(addr.s6_addr + 8, idev->dev) && in addrconf_dad_work()
4047 ipv6_addr_equal(&ifp->addr, &addr)) { in addrconf_dad_work()
4048 /* DAD failed for link-local based on MAC */ in addrconf_dad_work()
4049 idev->cnf.disable_ipv6 = 1; in addrconf_dad_work()
4052 ifp->idev->dev->name); in addrconf_dad_work()
4057 spin_unlock_bh(&ifp->lock); in addrconf_dad_work()
4066 addrconf_ifdown(idev->dev, false); in addrconf_dad_work()
4070 if (!ifp->dad_probes && addrconf_dad_end(ifp)) in addrconf_dad_work()
4073 write_lock_bh(&idev->lock); in addrconf_dad_work()
4074 if (idev->dead || !(idev->if_flags & IF_READY)) { in addrconf_dad_work()
4075 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4079 spin_lock(&ifp->lock); in addrconf_dad_work()
4080 if (ifp->state == INET6_IFADDR_STATE_DEAD) { in addrconf_dad_work()
4081 spin_unlock(&ifp->lock); in addrconf_dad_work()
4082 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4086 if (ifp->dad_probes == 0) { in addrconf_dad_work()
4093 if (ifp->flags & IFA_F_TENTATIVE && in addrconf_dad_work()
4094 !(ifp->flags & IFA_F_OPTIMISTIC)) in addrconf_dad_work()
4096 bump_id = ifp->flags & IFA_F_TENTATIVE; in addrconf_dad_work()
4097 ifp->flags &= ~(IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|IFA_F_DADFAILED); in addrconf_dad_work()
4098 spin_unlock(&ifp->lock); in addrconf_dad_work()
4099 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4106 ifp->dad_probes--; in addrconf_dad_work()
4108 max(NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME), in addrconf_dad_work()
4110 spin_unlock(&ifp->lock); in addrconf_dad_work()
4111 write_unlock_bh(&idev->lock); in addrconf_dad_work()
4114 addrconf_addr_solict_mult(&ifp->addr, &mcaddr); in addrconf_dad_work()
4115 ndisc_send_ns(ifp->idev->dev, &ifp->addr, &mcaddr, &in6addr_any, in addrconf_dad_work()
4116 ifp->dad_nonce); in addrconf_dad_work()
4122 /* ifp->idev must be at least read locked */
4126 struct inet6_dev *idev = ifp->idev; in ipv6_lonely_lladdr()
4128 list_for_each_entry_reverse(ifpiter, &idev->addr_list, if_list) { in ipv6_lonely_lladdr()
4129 if (ifpiter->scope > IFA_LINK) in ipv6_lonely_lladdr()
4131 if (ifp != ifpiter && ifpiter->scope == IFA_LINK && in ipv6_lonely_lladdr()
4132 (ifpiter->flags & (IFA_F_PERMANENT|IFA_F_TENTATIVE| in ipv6_lonely_lladdr()
4143 struct net_device *dev = ifp->idev->dev; in addrconf_dad_completed()
4159 read_lock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4160 send_mld = ifp->scope == IFA_LINK && ipv6_lonely_lladdr(ifp); in addrconf_dad_completed()
4162 ipv6_accept_ra(ifp->idev) && in addrconf_dad_completed()
4163 ifp->idev->cnf.rtr_solicits != 0 && in addrconf_dad_completed()
4164 (dev->flags&IFF_LOOPBACK) == 0; in addrconf_dad_completed()
4165 read_unlock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4171 ipv6_mc_dad_complete(ifp->idev); in addrconf_dad_completed()
4175 (ifp->idev->cnf.ndisc_notify || in addrconf_dad_completed()
4176 dev_net(dev)->ipv6.devconf_all->ndisc_notify)) { in addrconf_dad_completed()
4177 ndisc_send_na(dev, &in6addr_linklocal_allnodes, &ifp->addr, in addrconf_dad_completed()
4178 /*router=*/ !!ifp->idev->cnf.forwarding, in addrconf_dad_completed()
4193 write_lock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4194 spin_lock(&ifp->lock); in addrconf_dad_completed()
4195 ifp->idev->rs_interval = rfc3315_s14_backoff_init( in addrconf_dad_completed()
4196 ifp->idev->cnf.rtr_solicit_interval); in addrconf_dad_completed()
4197 ifp->idev->rs_probes = 1; in addrconf_dad_completed()
4198 ifp->idev->if_flags |= IF_RS_SENT; in addrconf_dad_completed()
4199 addrconf_mod_rs_timer(ifp->idev, ifp->idev->rs_interval); in addrconf_dad_completed()
4200 spin_unlock(&ifp->lock); in addrconf_dad_completed()
4201 write_unlock_bh(&ifp->idev->lock); in addrconf_dad_completed()
4210 if (ifp->flags & IFA_F_TEMPORARY) in addrconf_dad_completed()
4218 read_lock_bh(&idev->lock); in addrconf_dad_run()
4219 list_for_each_entry(ifp, &idev->addr_list, if_list) { in addrconf_dad_run()
4220 spin_lock(&ifp->lock); in addrconf_dad_run()
4221 if ((ifp->flags & IFA_F_TENTATIVE && in addrconf_dad_run()
4222 ifp->state == INET6_IFADDR_STATE_DAD) || restart) { in addrconf_dad_run()
4224 ifp->state = INET6_IFADDR_STATE_PREDAD; in addrconf_dad_run()
4227 spin_unlock(&ifp->lock); in addrconf_dad_run()
4229 read_unlock_bh(&idev->lock); in addrconf_dad_run()
4241 struct if6_iter_state *state = seq->private; in if6_get_first()
4248 state->bucket = 0; in if6_get_first()
4249 state->offset = 0; in if6_get_first()
4252 for (; state->bucket < IN6_ADDR_HSIZE; ++state->bucket) { in if6_get_first()
4253 hlist_for_each_entry_rcu(ifa, &inet6_addr_lst[state->bucket], in if6_get_first()
4255 if (!net_eq(dev_net(ifa->idev->dev), net)) in if6_get_first()
4258 if (p < state->offset) { in if6_get_first()
4266 state->offset = 0; in if6_get_first()
4275 struct if6_iter_state *state = seq->private; in if6_get_next()
4279 if (!net_eq(dev_net(ifa->idev->dev), net)) in if6_get_next()
4281 state->offset++; in if6_get_next()
4285 state->offset = 0; in if6_get_next()
4286 while (++state->bucket < IN6_ADDR_HSIZE) { in if6_get_next()
4288 &inet6_addr_lst[state->bucket], addr_lst) { in if6_get_next()
4289 if (!net_eq(dev_net(ifa->idev->dev), net)) in if6_get_next()
4324 &ifp->addr, in if6_seq_show()
4325 ifp->idev->dev->ifindex, in if6_seq_show()
4326 ifp->prefix_len, in if6_seq_show()
4327 ifp->scope, in if6_seq_show()
4328 (u8) ifp->flags, in if6_seq_show()
4329 ifp->idev->dev->name); in if6_seq_show()
4342 if (!proc_create_net("if_inet6", 0444, net->proc_net, &if6_seq_ops, in if6_proc_net_init()
4344 return -ENOMEM; in if6_proc_net_init()
4350 remove_proc_entry("if_inet6", net->proc_net); in if6_proc_net_exit()
4379 if (!net_eq(dev_net(ifp->idev->dev), net)) in ipv6_chk_home_addr()
4381 if (ipv6_addr_equal(&ifp->addr, addr) && in ipv6_chk_home_addr()
4382 (ifp->flags & IFA_F_HOMEADDRESS)) { in ipv6_chk_home_addr()
4419 if (!net_eq(dev_net(ifp->idev->dev), net)) in ipv6_chk_rpl_srh_loop()
4422 if (ipv6_addr_equal(&ifp->addr, addr)) { in ipv6_chk_rpl_srh_loop()
4470 * IFA_F_PERMANENT has a non-infinity life time. in addrconf_verify_rtnl()
4472 if ((ifp->flags & IFA_F_PERMANENT) && in addrconf_verify_rtnl()
4473 (ifp->prefered_lft == INFINITY_LIFE_TIME)) in addrconf_verify_rtnl()
4476 spin_lock(&ifp->lock); in addrconf_verify_rtnl()
4478 age = (now - ifp->tstamp + ADDRCONF_TIMER_FUZZ_MINUS) / HZ; in addrconf_verify_rtnl()
4480 if (ifp->valid_lft != INFINITY_LIFE_TIME && in addrconf_verify_rtnl()
4481 age >= ifp->valid_lft) { in addrconf_verify_rtnl()
4482 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4486 } else if (ifp->prefered_lft == INFINITY_LIFE_TIME) { in addrconf_verify_rtnl()
4487 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4489 } else if (age >= ifp->prefered_lft) { in addrconf_verify_rtnl()
4490 /* jiffies - ifp->tstamp > age >= ifp->prefered_lft */ in addrconf_verify_rtnl()
4493 if (!(ifp->flags&IFA_F_DEPRECATED)) { in addrconf_verify_rtnl()
4495 ifp->flags |= IFA_F_DEPRECATED; in addrconf_verify_rtnl()
4498 if ((ifp->valid_lft != INFINITY_LIFE_TIME) && in addrconf_verify_rtnl()
4499 (time_before(ifp->tstamp + ifp->valid_lft * HZ, next))) in addrconf_verify_rtnl()
4500 next = ifp->tstamp + ifp->valid_lft * HZ; in addrconf_verify_rtnl()
4502 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4511 } else if ((ifp->flags&IFA_F_TEMPORARY) && in addrconf_verify_rtnl()
4512 !(ifp->flags&IFA_F_TENTATIVE)) { in addrconf_verify_rtnl()
4513 unsigned long regen_advance = ifp->idev->cnf.regen_max_retry * in addrconf_verify_rtnl()
4514 ifp->idev->cnf.dad_transmits * in addrconf_verify_rtnl()
4515 max(NEIGH_VAR(ifp->idev->nd_parms, RETRANS_TIME), HZ/100) / HZ; in addrconf_verify_rtnl()
4517 if (age >= ifp->prefered_lft - regen_advance) { in addrconf_verify_rtnl()
4518 struct inet6_ifaddr *ifpub = ifp->ifpub; in addrconf_verify_rtnl()
4519 if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) in addrconf_verify_rtnl()
4520 next = ifp->tstamp + ifp->prefered_lft * HZ; in addrconf_verify_rtnl()
4521 if (!ifp->regen_count && ifpub) { in addrconf_verify_rtnl()
4522 ifp->regen_count++; in addrconf_verify_rtnl()
4525 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4527 spin_lock(&ifpub->lock); in addrconf_verify_rtnl()
4528 ifpub->regen_count = 0; in addrconf_verify_rtnl()
4529 spin_unlock(&ifpub->lock); in addrconf_verify_rtnl()
4537 } else if (time_before(ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ, next)) in addrconf_verify_rtnl()
4538 next = ifp->tstamp + ifp->prefered_lft * HZ - regen_advance * HZ; in addrconf_verify_rtnl()
4539 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4541 /* ifp->prefered_lft <= ifp->valid_lft */ in addrconf_verify_rtnl()
4542 if (time_before(ifp->tstamp + ifp->prefered_lft * HZ, next)) in addrconf_verify_rtnl()
4543 next = ifp->tstamp + ifp->prefered_lft * HZ; in addrconf_verify_rtnl()
4544 spin_unlock(&ifp->lock); in addrconf_verify_rtnl()
4562 mod_delayed_work(addrconf_wq, &addr_chk_work, next_sched - now); in addrconf_verify_rtnl()
4610 struct net *net = sock_net(skb->sk); in inet6_rtm_deladdr()
4625 return -EINVAL; in inet6_rtm_deladdr()
4627 ifa_flags = tb[IFA_FLAGS] ? nla_get_u32(tb[IFA_FLAGS]) : ifm->ifa_flags; in inet6_rtm_deladdr()
4632 return inet6_addr_del(net, ifm->ifa_index, ifa_flags, pfx, in inet6_rtm_deladdr()
4633 ifm->ifa_prefixlen); in inet6_rtm_deladdr()
4643 f6i = addrconf_get_prefix_route(modify_peer ? &ifp->peer_addr : &ifp->addr, in modify_prefix_route()
4644 ifp->prefix_len, in modify_prefix_route()
4645 ifp->idev->dev, 0, RTF_DEFAULT, true); in modify_prefix_route()
4647 return -ENOENT; in modify_prefix_route()
4649 prio = ifp->rt_priority ? : IP6_RT_PRIO_ADDRCONF; in modify_prefix_route()
4650 if (f6i->fib6_metric != prio) { in modify_prefix_route()
4652 ip6_del_rt(dev_net(ifp->idev->dev), f6i, false); in modify_prefix_route()
4655 addrconf_prefix_route(modify_peer ? &ifp->peer_addr : &ifp->addr, in modify_prefix_route()
4656 ifp->prefix_len, in modify_prefix_route()
4657 ifp->rt_priority, ifp->idev->dev, in modify_prefix_route()
4682 if (!cfg->valid_lft || cfg->preferred_lft > cfg->valid_lft) in inet6_addr_modify()
4683 return -EINVAL; in inet6_addr_modify()
4685 if (cfg->ifa_flags & IFA_F_MANAGETEMPADDR && in inet6_addr_modify()
4686 (ifp->flags & IFA_F_TEMPORARY || ifp->prefix_len != 64)) in inet6_addr_modify()
4687 return -EINVAL; in inet6_addr_modify()
4689 if (!(ifp->flags & IFA_F_TENTATIVE) || ifp->flags & IFA_F_DADFAILED) in inet6_addr_modify()
4690 cfg->ifa_flags &= ~IFA_F_OPTIMISTIC; in inet6_addr_modify()
4692 timeout = addrconf_timeout_fixup(cfg->valid_lft, HZ); in inet6_addr_modify()
4695 cfg->valid_lft = timeout; in inet6_addr_modify()
4700 cfg->ifa_flags |= IFA_F_PERMANENT; in inet6_addr_modify()
4703 timeout = addrconf_timeout_fixup(cfg->preferred_lft, HZ); in inet6_addr_modify()
4706 cfg->ifa_flags |= IFA_F_DEPRECATED; in inet6_addr_modify()
4707 cfg->preferred_lft = timeout; in inet6_addr_modify()
4710 if (cfg->peer_pfx && in inet6_addr_modify()
4711 memcmp(&ifp->peer_addr, cfg->peer_pfx, sizeof(struct in6_addr))) { in inet6_addr_modify()
4712 if (!ipv6_addr_any(&ifp->peer_addr)) in inet6_addr_modify()
4717 spin_lock_bh(&ifp->lock); in inet6_addr_modify()
4718 was_managetempaddr = ifp->flags & IFA_F_MANAGETEMPADDR; in inet6_addr_modify()
4719 had_prefixroute = ifp->flags & IFA_F_PERMANENT && in inet6_addr_modify()
4720 !(ifp->flags & IFA_F_NOPREFIXROUTE); in inet6_addr_modify()
4721 ifp->flags &= ~(IFA_F_DEPRECATED | IFA_F_PERMANENT | IFA_F_NODAD | in inet6_addr_modify()
4724 ifp->flags |= cfg->ifa_flags; in inet6_addr_modify()
4725 ifp->tstamp = jiffies; in inet6_addr_modify()
4726 ifp->valid_lft = cfg->valid_lft; in inet6_addr_modify()
4727 ifp->prefered_lft = cfg->preferred_lft; in inet6_addr_modify()
4729 if (cfg->rt_priority && cfg->rt_priority != ifp->rt_priority) in inet6_addr_modify()
4730 ifp->rt_priority = cfg->rt_priority; in inet6_addr_modify()
4733 ifp->peer_addr = *cfg->peer_pfx; in inet6_addr_modify()
4735 spin_unlock_bh(&ifp->lock); in inet6_addr_modify()
4736 if (!(ifp->flags&IFA_F_TENTATIVE)) in inet6_addr_modify()
4739 if (!(cfg->ifa_flags & IFA_F_NOPREFIXROUTE)) { in inet6_addr_modify()
4740 int rc = -ENOENT; in inet6_addr_modify()
4745 /* prefix route could have been deleted; if so restore it */ in inet6_addr_modify()
4746 if (rc == -ENOENT) { in inet6_addr_modify()
4747 addrconf_prefix_route(&ifp->addr, ifp->prefix_len, in inet6_addr_modify()
4748 ifp->rt_priority, ifp->idev->dev, in inet6_addr_modify()
4752 if (had_prefixroute && !ipv6_addr_any(&ifp->peer_addr)) in inet6_addr_modify()
4755 if (rc == -ENOENT && !ipv6_addr_any(&ifp->peer_addr)) { in inet6_addr_modify()
4756 addrconf_prefix_route(&ifp->peer_addr, ifp->prefix_len, in inet6_addr_modify()
4757 ifp->rt_priority, ifp->idev->dev, in inet6_addr_modify()
4764 write_lock_bh(&ifp->idev->lock); in inet6_addr_modify()
4766 write_unlock_bh(&ifp->idev->lock); in inet6_addr_modify()
4774 if (was_managetempaddr || ifp->flags & IFA_F_MANAGETEMPADDR) { in inet6_addr_modify()
4776 !(ifp->flags & IFA_F_MANAGETEMPADDR)) { in inet6_addr_modify()
4777 cfg->valid_lft = 0; in inet6_addr_modify()
4778 cfg->preferred_lft = 0; in inet6_addr_modify()
4780 manage_tempaddrs(ifp->idev, ifp, cfg->valid_lft, in inet6_addr_modify()
4781 cfg->preferred_lft, !was_managetempaddr, in inet6_addr_modify()
4794 struct net *net = sock_net(skb->sk); in inet6_rtm_newaddr()
4814 return -EINVAL; in inet6_rtm_newaddr()
4817 cfg.plen = ifm->ifa_prefixlen; in inet6_rtm_newaddr()
4828 cfg.valid_lft = ci->ifa_valid; in inet6_rtm_newaddr()
4829 cfg.preferred_lft = ci->ifa_prefered; in inet6_rtm_newaddr()
4832 dev = __dev_get_by_index(net, ifm->ifa_index); in inet6_rtm_newaddr()
4834 return -ENODEV; in inet6_rtm_newaddr()
4839 cfg.ifa_flags = ifm->ifa_flags; in inet6_rtm_newaddr()
4856 return -EINVAL; in inet6_rtm_newaddr()
4865 return inet6_addr_add(net, ifm->ifa_index, &cfg, extack); in inet6_rtm_newaddr()
4868 if (nlh->nlmsg_flags & NLM_F_EXCL || in inet6_rtm_newaddr()
4869 !(nlh->nlmsg_flags & NLM_F_REPLACE)) in inet6_rtm_newaddr()
4870 err = -EEXIST; in inet6_rtm_newaddr()
4885 ifm->ifa_family = AF_INET6; in put_ifaddrmsg()
4886 ifm->ifa_prefixlen = prefixlen; in put_ifaddrmsg()
4887 ifm->ifa_flags = flags; in put_ifaddrmsg()
4888 ifm->ifa_scope = scope; in put_ifaddrmsg()
4889 ifm->ifa_index = ifindex; in put_ifaddrmsg()
4949 nlh = nlmsg_put(skb, args->portid, args->seq, args->event, in inet6_fill_ifaddr()
4950 sizeof(struct ifaddrmsg), args->flags); in inet6_fill_ifaddr()
4952 return -EMSGSIZE; in inet6_fill_ifaddr()
4954 put_ifaddrmsg(nlh, ifa->prefix_len, ifa->flags, rt_scope(ifa->scope), in inet6_fill_ifaddr()
4955 ifa->idev->dev->ifindex); in inet6_fill_ifaddr()
4957 if (args->netnsid >= 0 && in inet6_fill_ifaddr()
4958 nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) in inet6_fill_ifaddr()
4961 if (!((ifa->flags&IFA_F_PERMANENT) && in inet6_fill_ifaddr()
4962 (ifa->prefered_lft == INFINITY_LIFE_TIME))) { in inet6_fill_ifaddr()
4963 preferred = ifa->prefered_lft; in inet6_fill_ifaddr()
4964 valid = ifa->valid_lft; in inet6_fill_ifaddr()
4966 long tval = (jiffies - ifa->tstamp)/HZ; in inet6_fill_ifaddr()
4968 preferred -= tval; in inet6_fill_ifaddr()
4973 valid -= tval; in inet6_fill_ifaddr()
4983 if (!ipv6_addr_any(&ifa->peer_addr)) { in inet6_fill_ifaddr()
4984 if (nla_put_in6_addr(skb, IFA_LOCAL, &ifa->addr) < 0 || in inet6_fill_ifaddr()
4985 nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->peer_addr) < 0) in inet6_fill_ifaddr()
4988 if (nla_put_in6_addr(skb, IFA_ADDRESS, &ifa->addr) < 0) in inet6_fill_ifaddr()
4991 if (ifa->rt_priority && in inet6_fill_ifaddr()
4992 nla_put_u32(skb, IFA_RT_PRIORITY, ifa->rt_priority)) in inet6_fill_ifaddr()
4995 if (put_cacheinfo(skb, ifa->cstamp, ifa->tstamp, preferred, valid) < 0) in inet6_fill_ifaddr()
4998 if (nla_put_u32(skb, IFA_FLAGS, ifa->flags) < 0) in inet6_fill_ifaddr()
5006 return -EMSGSIZE; in inet6_fill_ifaddr()
5014 int ifindex = ifmca->idev->dev->ifindex; in inet6_fill_ifmcaddr()
5016 if (ipv6_addr_scope(&ifmca->mca_addr) & IFA_SITE) in inet6_fill_ifmcaddr()
5019 nlh = nlmsg_put(skb, args->portid, args->seq, args->event, in inet6_fill_ifmcaddr()
5020 sizeof(struct ifaddrmsg), args->flags); in inet6_fill_ifmcaddr()
5022 return -EMSGSIZE; in inet6_fill_ifmcaddr()
5024 if (args->netnsid >= 0 && in inet6_fill_ifmcaddr()
5025 nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) { in inet6_fill_ifmcaddr()
5027 return -EMSGSIZE; in inet6_fill_ifmcaddr()
5031 if (nla_put_in6_addr(skb, IFA_MULTICAST, &ifmca->mca_addr) < 0 || in inet6_fill_ifmcaddr()
5032 put_cacheinfo(skb, ifmca->mca_cstamp, ifmca->mca_tstamp, in inet6_fill_ifmcaddr()
5035 return -EMSGSIZE; in inet6_fill_ifmcaddr()
5045 struct net_device *dev = fib6_info_nh_dev(ifaca->aca_rt); in inet6_fill_ifacaddr()
5046 int ifindex = dev ? dev->ifindex : 1; in inet6_fill_ifacaddr()
5050 if (ipv6_addr_scope(&ifaca->aca_addr) & IFA_SITE) in inet6_fill_ifacaddr()
5053 nlh = nlmsg_put(skb, args->portid, args->seq, args->event, in inet6_fill_ifacaddr()
5054 sizeof(struct ifaddrmsg), args->flags); in inet6_fill_ifacaddr()
5056 return -EMSGSIZE; in inet6_fill_ifacaddr()
5058 if (args->netnsid >= 0 && in inet6_fill_ifacaddr()
5059 nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid)) { in inet6_fill_ifacaddr()
5061 return -EMSGSIZE; in inet6_fill_ifacaddr()
5065 if (nla_put_in6_addr(skb, IFA_ANYCAST, &ifaca->aca_addr) < 0 || in inet6_fill_ifacaddr()
5066 put_cacheinfo(skb, ifaca->aca_cstamp, ifaca->aca_tstamp, in inet6_fill_ifacaddr()
5069 return -EMSGSIZE; in inet6_fill_ifacaddr()
5086 read_lock_bh(&idev->lock); in in6_dump_addrs()
5087 switch (fillargs->type) { in in6_dump_addrs()
5090 fillargs->event = RTM_NEWADDR; in in6_dump_addrs()
5093 list_for_each_entry(ifa, &idev->addr_list, if_list) { in in6_dump_addrs()
5106 fillargs->event = RTM_GETMULTICAST; in in6_dump_addrs()
5109 for (ifmca = idev->mc_list; ifmca; in in6_dump_addrs()
5110 ifmca = ifmca->next, ip_idx++) { in in6_dump_addrs()
5119 fillargs->event = RTM_GETANYCAST; in in6_dump_addrs()
5121 for (ifaca = idev->ac_list; ifaca; in in6_dump_addrs()
5122 ifaca = ifaca->aca_next, ip_idx++) { in in6_dump_addrs()
5133 read_unlock_bh(&idev->lock); in in6_dump_addrs()
5134 cb->args[2] = ip_idx; in in6_dump_addrs()
5143 struct netlink_ext_ack *extack = cb->extack; in inet6_valid_dump_ifaddr_req()
5148 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in inet6_valid_dump_ifaddr_req()
5150 return -EINVAL; in inet6_valid_dump_ifaddr_req()
5154 if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) { in inet6_valid_dump_ifaddr_req()
5156 return -EINVAL; in inet6_valid_dump_ifaddr_req()
5159 fillargs->ifindex = ifm->ifa_index; in inet6_valid_dump_ifaddr_req()
5160 if (fillargs->ifindex) { in inet6_valid_dump_ifaddr_req()
5161 cb->answer_flags |= NLM_F_DUMP_FILTERED; in inet6_valid_dump_ifaddr_req()
5162 fillargs->flags |= NLM_F_DUMP_FILTERED; in inet6_valid_dump_ifaddr_req()
5177 fillargs->netnsid = nla_get_s32(tb[i]); in inet6_valid_dump_ifaddr_req()
5178 net = rtnl_get_net_ns_capable(sk, fillargs->netnsid); in inet6_valid_dump_ifaddr_req()
5180 fillargs->netnsid = -1; in inet6_valid_dump_ifaddr_req()
5187 return -EINVAL; in inet6_valid_dump_ifaddr_req()
5197 const struct nlmsghdr *nlh = cb->nlh; in inet6_dump_addr()
5199 .portid = NETLINK_CB(cb->skb).portid, in inet6_dump_addr()
5200 .seq = cb->nlh->nlmsg_seq, in inet6_dump_addr()
5202 .netnsid = -1, in inet6_dump_addr()
5205 struct net *net = sock_net(skb->sk); in inet6_dump_addr()
5214 s_h = cb->args[0]; in inet6_dump_addr()
5215 s_idx = idx = cb->args[1]; in inet6_dump_addr()
5216 s_ip_idx = cb->args[2]; in inet6_dump_addr()
5218 if (cb->strict_check) { in inet6_dump_addr()
5220 skb->sk, cb); in inet6_dump_addr()
5228 err = -ENODEV; in inet6_dump_addr()
5243 cb->seq = atomic_read(&tgt_net->ipv6.dev_addr_genid) ^ tgt_net->dev_base_seq; in inet6_dump_addr()
5246 head = &tgt_net->dev_index_head[h]; in inet6_dump_addr()
5265 cb->args[0] = h; in inet6_dump_addr()
5266 cb->args[1] = idx; in inet6_dump_addr()
5271 return skb->len ? : err; in inet6_dump_addr()
5304 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in inet6_rtm_valid_getaddr_req()
5306 return -EINVAL; in inet6_rtm_valid_getaddr_req()
5314 if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) { in inet6_rtm_valid_getaddr_req()
5316 return -EINVAL; in inet6_rtm_valid_getaddr_req()
5335 return -EINVAL; in inet6_rtm_valid_getaddr_req()
5345 struct net *net = sock_net(in_skb->sk); in inet6_rtm_getaddr()
5348 .seq = nlh->nlmsg_seq, in inet6_rtm_getaddr()
5351 .netnsid = -1, in inet6_rtm_getaddr()
5377 return -EINVAL; in inet6_rtm_getaddr()
5380 if (ifm->ifa_index) in inet6_rtm_getaddr()
5381 dev = dev_get_by_index(tgt_net, ifm->ifa_index); in inet6_rtm_getaddr()
5385 err = -EADDRNOTAVAIL; in inet6_rtm_getaddr()
5391 err = -ENOBUFS; in inet6_rtm_getaddr()
5397 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ in inet6_rtm_getaddr()
5398 WARN_ON(err == -EMSGSIZE); in inet6_rtm_getaddr()
5417 struct net *net = dev_net(ifa->idev->dev); in inet6_ifa_notify()
5423 .netnsid = -1, in inet6_ifa_notify()
5425 int err = -ENOBUFS; in inet6_ifa_notify()
5433 /* -EMSGSIZE implies BUG in inet6_ifaddr_msgsize() */ in inet6_ifa_notify()
5434 WARN_ON(err == -EMSGSIZE); in inet6_ifa_notify()
5451 array[DEVCONF_FORWARDING] = cnf->forwarding; in ipv6_store_devconf()
5452 array[DEVCONF_HOPLIMIT] = cnf->hop_limit; in ipv6_store_devconf()
5453 array[DEVCONF_MTU6] = cnf->mtu6; in ipv6_store_devconf()
5454 array[DEVCONF_ACCEPT_RA] = cnf->accept_ra; in ipv6_store_devconf()
5455 array[DEVCONF_ACCEPT_REDIRECTS] = cnf->accept_redirects; in ipv6_store_devconf()
5456 array[DEVCONF_AUTOCONF] = cnf->autoconf; in ipv6_store_devconf()
5457 array[DEVCONF_DAD_TRANSMITS] = cnf->dad_transmits; in ipv6_store_devconf()
5458 array[DEVCONF_RTR_SOLICITS] = cnf->rtr_solicits; in ipv6_store_devconf()
5460 jiffies_to_msecs(cnf->rtr_solicit_interval); in ipv6_store_devconf()
5462 jiffies_to_msecs(cnf->rtr_solicit_max_interval); in ipv6_store_devconf()
5464 jiffies_to_msecs(cnf->rtr_solicit_delay); in ipv6_store_devconf()
5465 array[DEVCONF_FORCE_MLD_VERSION] = cnf->force_mld_version; in ipv6_store_devconf()
5467 jiffies_to_msecs(cnf->mldv1_unsolicited_report_interval); in ipv6_store_devconf()
5469 jiffies_to_msecs(cnf->mldv2_unsolicited_report_interval); in ipv6_store_devconf()
5470 array[DEVCONF_USE_TEMPADDR] = cnf->use_tempaddr; in ipv6_store_devconf()
5471 array[DEVCONF_TEMP_VALID_LFT] = cnf->temp_valid_lft; in ipv6_store_devconf()
5472 array[DEVCONF_TEMP_PREFERED_LFT] = cnf->temp_prefered_lft; in ipv6_store_devconf()
5473 array[DEVCONF_REGEN_MAX_RETRY] = cnf->regen_max_retry; in ipv6_store_devconf()
5474 array[DEVCONF_MAX_DESYNC_FACTOR] = cnf->max_desync_factor; in ipv6_store_devconf()
5475 array[DEVCONF_MAX_ADDRESSES] = cnf->max_addresses; in ipv6_store_devconf()
5476 array[DEVCONF_ACCEPT_RA_DEFRTR] = cnf->accept_ra_defrtr; in ipv6_store_devconf()
5477 array[DEVCONF_ACCEPT_RA_MIN_HOP_LIMIT] = cnf->accept_ra_min_hop_limit; in ipv6_store_devconf()
5478 array[DEVCONF_ACCEPT_RA_PINFO] = cnf->accept_ra_pinfo; in ipv6_store_devconf()
5480 array[DEVCONF_ACCEPT_RA_RTR_PREF] = cnf->accept_ra_rtr_pref; in ipv6_store_devconf()
5482 jiffies_to_msecs(cnf->rtr_probe_interval); in ipv6_store_devconf()
5484 array[DEVCONF_ACCEPT_RA_RT_INFO_MIN_PLEN] = cnf->accept_ra_rt_info_min_plen; in ipv6_store_devconf()
5485 array[DEVCONF_ACCEPT_RA_RT_INFO_MAX_PLEN] = cnf->accept_ra_rt_info_max_plen; in ipv6_store_devconf()
5488 array[DEVCONF_PROXY_NDP] = cnf->proxy_ndp; in ipv6_store_devconf()
5489 array[DEVCONF_ACCEPT_SOURCE_ROUTE] = cnf->accept_source_route; in ipv6_store_devconf()
5491 array[DEVCONF_OPTIMISTIC_DAD] = cnf->optimistic_dad; in ipv6_store_devconf()
5492 array[DEVCONF_USE_OPTIMISTIC] = cnf->use_optimistic; in ipv6_store_devconf()
5495 array[DEVCONF_MC_FORWARDING] = cnf->mc_forwarding; in ipv6_store_devconf()
5497 array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6; in ipv6_store_devconf()
5498 array[DEVCONF_ACCEPT_DAD] = cnf->accept_dad; in ipv6_store_devconf()
5499 array[DEVCONF_FORCE_TLLAO] = cnf->force_tllao; in ipv6_store_devconf()
5500 array[DEVCONF_NDISC_NOTIFY] = cnf->ndisc_notify; in ipv6_store_devconf()
5501 array[DEVCONF_SUPPRESS_FRAG_NDISC] = cnf->suppress_frag_ndisc; in ipv6_store_devconf()
5502 array[DEVCONF_ACCEPT_RA_FROM_LOCAL] = cnf->accept_ra_from_local; in ipv6_store_devconf()
5503 array[DEVCONF_ACCEPT_RA_MTU] = cnf->accept_ra_mtu; in ipv6_store_devconf()
5504 array[DEVCONF_IGNORE_ROUTES_WITH_LINKDOWN] = cnf->ignore_routes_with_linkdown; in ipv6_store_devconf()
5506 array[DEVCONF_USE_OIF_ADDRS_ONLY] = cnf->use_oif_addrs_only; in ipv6_store_devconf()
5507 array[DEVCONF_DROP_UNICAST_IN_L2_MULTICAST] = cnf->drop_unicast_in_l2_multicast; in ipv6_store_devconf()
5508 array[DEVCONF_DROP_UNSOLICITED_NA] = cnf->drop_unsolicited_na; in ipv6_store_devconf()
5509 array[DEVCONF_KEEP_ADDR_ON_DOWN] = cnf->keep_addr_on_down; in ipv6_store_devconf()
5510 array[DEVCONF_SEG6_ENABLED] = cnf->seg6_enabled; in ipv6_store_devconf()
5512 array[DEVCONF_SEG6_REQUIRE_HMAC] = cnf->seg6_require_hmac; in ipv6_store_devconf()
5514 array[DEVCONF_ENHANCED_DAD] = cnf->enhanced_dad; in ipv6_store_devconf()
5515 array[DEVCONF_ADDR_GEN_MODE] = cnf->addr_gen_mode; in ipv6_store_devconf()
5516 array[DEVCONF_DISABLE_POLICY] = cnf->disable_policy; in ipv6_store_devconf()
5517 array[DEVCONF_NDISC_TCLASS] = cnf->ndisc_tclass; in ipv6_store_devconf()
5518 array[DEVCONF_RPL_SEG_ENABLED] = cnf->rpl_seg_enabled; in ipv6_store_devconf()
5548 int pad = bytes - sizeof(u64) * ICMP6_MIB_MAX; in __snmp6_fill_statsdev()
5564 int pad = bytes - sizeof(u64) * IPSTATS_MIB_MAX; in __snmp6_fill_stats64()
5585 __snmp6_fill_stats64(stats, idev->stats.ipv6, bytes, in snmp6_fill_stats()
5589 __snmp6_fill_statsdev(stats, idev->stats.icmpv6dev->mibs, bytes); in snmp6_fill_stats()
5600 if (nla_put_u32(skb, IFLA_INET6_FLAGS, idev->if_flags)) in inet6_fill_ifla6_attrs()
5603 ci.tstamp = cstamp_delta(idev->tstamp); in inet6_fill_ifla6_attrs()
5604 ci.reachable_time = jiffies_to_msecs(idev->nd_parms->reachable_time); in inet6_fill_ifla6_attrs()
5605 ci.retrans_time = jiffies_to_msecs(NEIGH_VAR(idev->nd_parms, RETRANS_TIME)); in inet6_fill_ifla6_attrs()
5611 ipv6_store_devconf(&idev->cnf, nla_data(nla), nla_len(nla)); in inet6_fill_ifla6_attrs()
5613 /* XXX - MC not implemented */ in inet6_fill_ifla6_attrs()
5631 read_lock_bh(&idev->lock); in inet6_fill_ifla6_attrs()
5632 memcpy(nla_data(nla), idev->token.s6_addr, nla_len(nla)); in inet6_fill_ifla6_attrs()
5633 read_unlock_bh(&idev->lock); in inet6_fill_ifla6_attrs()
5635 if (nla_put_u8(skb, IFLA_INET6_ADDR_GEN_MODE, idev->cnf.addr_gen_mode)) in inet6_fill_ifla6_attrs()
5641 return -EMSGSIZE; in inet6_fill_ifla6_attrs()
5659 return -ENODATA; in inet6_fill_link_af()
5662 return -EMSGSIZE; in inet6_fill_link_af()
5670 struct net_device *dev = idev->dev; in inet6_set_iftoken()
5677 return -EINVAL; in inet6_set_iftoken()
5678 if (dev->flags & (IFF_LOOPBACK | IFF_NOARP)) in inet6_set_iftoken()
5679 return -EINVAL; in inet6_set_iftoken()
5681 return -EINVAL; in inet6_set_iftoken()
5682 if (idev->cnf.rtr_solicits == 0) in inet6_set_iftoken()
5683 return -EINVAL; in inet6_set_iftoken()
5685 write_lock_bh(&idev->lock); in inet6_set_iftoken()
5687 BUILD_BUG_ON(sizeof(token->s6_addr) != 16); in inet6_set_iftoken()
5688 memcpy(idev->token.s6_addr + 8, token->s6_addr + 8, 8); in inet6_set_iftoken()
5690 write_unlock_bh(&idev->lock); in inet6_set_iftoken()
5696 if (!idev->dead && (idev->if_flags & IF_READY) && in inet6_set_iftoken()
5707 write_lock_bh(&idev->lock); in inet6_set_iftoken()
5710 idev->if_flags |= IF_RS_SENT; in inet6_set_iftoken()
5711 idev->rs_interval = rfc3315_s14_backoff_init( in inet6_set_iftoken()
5712 idev->cnf.rtr_solicit_interval); in inet6_set_iftoken()
5713 idev->rs_probes = 1; in inet6_set_iftoken()
5714 addrconf_mod_rs_timer(idev, idev->rs_interval); in inet6_set_iftoken()
5718 list_for_each_entry(ifp, &idev->addr_list, if_list) { in inet6_set_iftoken()
5719 spin_lock(&ifp->lock); in inet6_set_iftoken()
5720 if (ifp->tokenized) { in inet6_set_iftoken()
5721 ifp->valid_lft = 0; in inet6_set_iftoken()
5722 ifp->prefered_lft = 0; in inet6_set_iftoken()
5724 spin_unlock(&ifp->lock); in inet6_set_iftoken()
5727 write_unlock_bh(&idev->lock); in inet6_set_iftoken()
5744 return -EINVAL; in check_addr_gen_mode()
5752 !idev->cnf.stable_secret.initialized && in check_stable_privacy()
5753 !net->ipv6.devconf_dflt->stable_secret.initialized) in check_stable_privacy()
5754 return -EINVAL; in check_stable_privacy()
5768 return -EAFNOSUPPORT; in inet6_validate_link_af()
5777 return -EINVAL; in inet6_validate_link_af()
5783 return -EINVAL; in inet6_validate_link_af()
5785 return -EINVAL; in inet6_validate_link_af()
5798 return -EAFNOSUPPORT; in inet6_set_link_af()
5812 idev->cnf.addr_gen_mode = mode; in inet6_set_link_af()
5821 struct net_device *dev = idev->dev; in inet6_fill_ifinfo()
5828 return -EMSGSIZE; in inet6_fill_ifinfo()
5831 hdr->ifi_family = AF_INET6; in inet6_fill_ifinfo()
5832 hdr->__ifi_pad = 0; in inet6_fill_ifinfo()
5833 hdr->ifi_type = dev->type; in inet6_fill_ifinfo()
5834 hdr->ifi_index = dev->ifindex; in inet6_fill_ifinfo()
5835 hdr->ifi_flags = dev_get_flags(dev); in inet6_fill_ifinfo()
5836 hdr->ifi_change = 0; in inet6_fill_ifinfo()
5838 if (nla_put_string(skb, IFLA_IFNAME, dev->name) || in inet6_fill_ifinfo()
5839 (dev->addr_len && in inet6_fill_ifinfo()
5840 nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) || in inet6_fill_ifinfo()
5841 nla_put_u32(skb, IFLA_MTU, dev->mtu) || in inet6_fill_ifinfo()
5842 (dev->ifindex != dev_get_iflink(dev) && in inet6_fill_ifinfo()
5845 netif_running(dev) ? dev->operstate : IF_OPER_DOWN)) in inet6_fill_ifinfo()
5860 return -EMSGSIZE; in inet6_fill_ifinfo()
5868 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*ifm))) { in inet6_valid_dump_ifinfo()
5870 return -EINVAL; in inet6_valid_dump_ifinfo()
5875 return -EINVAL; in inet6_valid_dump_ifinfo()
5879 if (ifm->__ifi_pad || ifm->ifi_type || ifm->ifi_flags || in inet6_valid_dump_ifinfo()
5880 ifm->ifi_change || ifm->ifi_index) { in inet6_valid_dump_ifinfo()
5882 return -EINVAL; in inet6_valid_dump_ifinfo()
5890 struct net *net = sock_net(skb->sk); in inet6_dump_ifinfo()
5900 if (cb->strict_check) { in inet6_dump_ifinfo()
5901 int err = inet6_valid_dump_ifinfo(cb->nlh, cb->extack); in inet6_dump_ifinfo()
5907 s_h = cb->args[0]; in inet6_dump_ifinfo()
5908 s_idx = cb->args[1]; in inet6_dump_ifinfo()
5913 head = &net->dev_index_head[h]; in inet6_dump_ifinfo()
5921 NETLINK_CB(cb->skb).portid, in inet6_dump_ifinfo()
5922 cb->nlh->nlmsg_seq, in inet6_dump_ifinfo()
5931 cb->args[1] = idx; in inet6_dump_ifinfo()
5932 cb->args[0] = h; in inet6_dump_ifinfo()
5934 return skb->len; in inet6_dump_ifinfo()
5940 struct net *net = dev_net(idev->dev); in inet6_ifinfo_notify()
5941 int err = -ENOBUFS; in inet6_ifinfo_notify()
5949 /* -EMSGSIZE implies BUG in inet6_if_nlmsg_size() */ in inet6_ifinfo_notify()
5950 WARN_ON(err == -EMSGSIZE); in inet6_ifinfo_notify()
5978 return -EMSGSIZE; in inet6_fill_prefix()
5981 pmsg->prefix_family = AF_INET6; in inet6_fill_prefix()
5982 pmsg->prefix_pad1 = 0; in inet6_fill_prefix()
5983 pmsg->prefix_pad2 = 0; in inet6_fill_prefix()
5984 pmsg->prefix_ifindex = idev->dev->ifindex; in inet6_fill_prefix()
5985 pmsg->prefix_len = pinfo->prefix_len; in inet6_fill_prefix()
5986 pmsg->prefix_type = pinfo->type; in inet6_fill_prefix()
5987 pmsg->prefix_pad3 = 0; in inet6_fill_prefix()
5988 pmsg->prefix_flags = 0; in inet6_fill_prefix()
5989 if (pinfo->onlink) in inet6_fill_prefix()
5990 pmsg->prefix_flags |= IF_PREFIX_ONLINK; in inet6_fill_prefix()
5991 if (pinfo->autoconf) in inet6_fill_prefix()
5992 pmsg->prefix_flags |= IF_PREFIX_AUTOCONF; in inet6_fill_prefix()
5994 if (nla_put(skb, PREFIX_ADDRESS, sizeof(pinfo->prefix), &pinfo->prefix)) in inet6_fill_prefix()
5996 ci.preferred_time = ntohl(pinfo->prefered); in inet6_fill_prefix()
5997 ci.valid_time = ntohl(pinfo->valid); in inet6_fill_prefix()
6005 return -EMSGSIZE; in inet6_fill_prefix()
6012 struct net *net = dev_net(idev->dev); in inet6_prefix_notify()
6013 int err = -ENOBUFS; in inet6_prefix_notify()
6021 /* -EMSGSIZE implies BUG in inet6_prefix_nlmsg_size() */ in inet6_prefix_notify()
6022 WARN_ON(err == -EMSGSIZE); in inet6_prefix_notify()
6035 struct net *net = dev_net(ifp->idev->dev); in __ipv6_ifa_notify()
6045 * If the address was optimistic we inserted the route at the in __ipv6_ifa_notify()
6049 * host route, so nothing to insert. That will be fixed when in __ipv6_ifa_notify()
6052 if (ifp->rt && !rcu_access_pointer(ifp->rt->fib6_node)) { in __ipv6_ifa_notify()
6053 ip6_ins_rt(net, ifp->rt); in __ipv6_ifa_notify()
6054 } else if (!ifp->rt && (ifp->idev->dev->flags & IFF_UP)) { in __ipv6_ifa_notify()
6055 pr_warn("BUG: Address %pI6c on device %s is missing its host route.\n", in __ipv6_ifa_notify()
6056 &ifp->addr, ifp->idev->dev->name); in __ipv6_ifa_notify()
6059 if (ifp->idev->cnf.forwarding) in __ipv6_ifa_notify()
6061 if (!ipv6_addr_any(&ifp->peer_addr)) in __ipv6_ifa_notify()
6062 addrconf_prefix_route(&ifp->peer_addr, 128, in __ipv6_ifa_notify()
6063 ifp->rt_priority, ifp->idev->dev, in __ipv6_ifa_notify()
6067 if (ifp->idev->cnf.forwarding) in __ipv6_ifa_notify()
6069 addrconf_leave_solict(ifp->idev, &ifp->addr); in __ipv6_ifa_notify()
6070 if (!ipv6_addr_any(&ifp->peer_addr)) { in __ipv6_ifa_notify()
6073 rt = addrconf_get_prefix_route(&ifp->peer_addr, 128, in __ipv6_ifa_notify()
6074 ifp->idev->dev, 0, 0, in __ipv6_ifa_notify()
6079 if (ifp->rt) { in __ipv6_ifa_notify()
6080 ip6_del_rt(net, ifp->rt, false); in __ipv6_ifa_notify()
6081 ifp->rt = NULL; in __ipv6_ifa_notify()
6086 atomic_inc(&net->ipv6.dev_addr_genid); in __ipv6_ifa_notify()
6092 if (likely(ifp->idev->dead == 0)) in ipv6_ifa_notify()
6102 int *valp = ctl->data; in addrconf_sysctl_forward()
6109 * ctl->data points to idev->cnf.forwarding, we should in addrconf_sysctl_forward()
6127 struct inet6_dev *idev = ctl->extra1; in addrconf_sysctl_mtu()
6133 lctl.extra2 = idev ? &idev->dev->mtu : NULL; in addrconf_sysctl_mtu()
6142 if (!idev || !idev->dev) in dev_disable_change()
6145 netdev_notifier_info_init(&info, idev->dev); in dev_disable_change()
6146 if (idev->cnf.disable_ipv6) in dev_disable_change()
6160 int changed = (!idev->cnf.disable_ipv6) ^ (!newf); in addrconf_disable_change()
6161 idev->cnf.disable_ipv6 = newf; in addrconf_disable_change()
6176 net = (struct net *)table->extra2; in addrconf_disable_ipv6()
6180 if (p == &net->ipv6.devconf_dflt->disable_ipv6) { in addrconf_disable_ipv6()
6185 if (p == &net->ipv6.devconf_all->disable_ipv6) { in addrconf_disable_ipv6()
6186 net->ipv6.devconf_dflt->disable_ipv6 = newf; in addrconf_disable_ipv6()
6189 dev_disable_change((struct inet6_dev *)table->extra1); in addrconf_disable_ipv6()
6198 int *valp = ctl->data; in addrconf_sysctl_disable()
6205 * ctl->data points to idev->cnf.disable_ipv6, we should in addrconf_sysctl_disable()
6223 int *valp = ctl->data; in addrconf_sysctl_proxy_ndp()
6232 struct net *net = ctl->extra2; in addrconf_sysctl_proxy_ndp()
6237 if (valp == &net->ipv6.devconf_dflt->proxy_ndp) in addrconf_sysctl_proxy_ndp()
6241 net->ipv6.devconf_dflt); in addrconf_sysctl_proxy_ndp()
6242 else if (valp == &net->ipv6.devconf_all->proxy_ndp) in addrconf_sysctl_proxy_ndp()
6246 net->ipv6.devconf_all); in addrconf_sysctl_proxy_ndp()
6248 struct inet6_dev *idev = ctl->extra1; in addrconf_sysctl_proxy_ndp()
6252 idev->dev->ifindex, in addrconf_sysctl_proxy_ndp()
6253 &idev->cnf); in addrconf_sysctl_proxy_ndp()
6267 struct inet6_dev *idev = (struct inet6_dev *)ctl->extra1; in addrconf_sysctl_addr_gen_mode()
6268 struct net *net = (struct net *)ctl->extra2; in addrconf_sysctl_addr_gen_mode()
6272 .mode = ctl->mode, in addrconf_sysctl_addr_gen_mode()
6278 new_val = *((u32 *)ctl->data); in addrconf_sysctl_addr_gen_mode()
6286 ret = -EINVAL; in addrconf_sysctl_addr_gen_mode()
6292 ret = -EINVAL; in addrconf_sysctl_addr_gen_mode()
6296 if (idev->cnf.addr_gen_mode != new_val) { in addrconf_sysctl_addr_gen_mode()
6297 idev->cnf.addr_gen_mode = new_val; in addrconf_sysctl_addr_gen_mode()
6298 addrconf_dev_config(idev->dev); in addrconf_sysctl_addr_gen_mode()
6300 } else if (&net->ipv6.devconf_all->addr_gen_mode == ctl->data) { in addrconf_sysctl_addr_gen_mode()
6303 net->ipv6.devconf_dflt->addr_gen_mode = new_val; in addrconf_sysctl_addr_gen_mode()
6307 idev->cnf.addr_gen_mode != new_val) { in addrconf_sysctl_addr_gen_mode()
6308 idev->cnf.addr_gen_mode = new_val; in addrconf_sysctl_addr_gen_mode()
6309 addrconf_dev_config(idev->dev); in addrconf_sysctl_addr_gen_mode()
6314 *((u32 *)ctl->data) = new_val; in addrconf_sysctl_addr_gen_mode()
6331 struct net *net = ctl->extra2; in addrconf_sysctl_stable_secret()
6332 struct ipv6_stable_secret *secret = ctl->data; in addrconf_sysctl_stable_secret()
6334 if (&net->ipv6.devconf_all->stable_secret == ctl->data) in addrconf_sysctl_stable_secret()
6335 return -EIO; in addrconf_sysctl_stable_secret()
6343 if (!write && !secret->initialized) { in addrconf_sysctl_stable_secret()
6344 err = -EIO; in addrconf_sysctl_stable_secret()
6348 err = snprintf(str, sizeof(str), "%pI6", &secret->secret); in addrconf_sysctl_stable_secret()
6350 err = -EIO; in addrconf_sysctl_stable_secret()
6358 if (in6_pton(str, -1, addr.in6_u.u6_addr8, -1, NULL) != 1) { in addrconf_sysctl_stable_secret()
6359 err = -EIO; in addrconf_sysctl_stable_secret()
6363 secret->initialized = true; in addrconf_sysctl_stable_secret()
6364 secret->secret = addr; in addrconf_sysctl_stable_secret()
6366 if (&net->ipv6.devconf_dflt->stable_secret == ctl->data) { in addrconf_sysctl_stable_secret()
6373 idev->cnf.addr_gen_mode = in addrconf_sysctl_stable_secret()
6378 struct inet6_dev *idev = ctl->extra1; in addrconf_sysctl_stable_secret()
6380 idev->cnf.addr_gen_mode = IN6_ADDR_GEN_MODE_STABLE_PRIVACY; in addrconf_sysctl_stable_secret()
6395 int *valp = ctl->data; in addrconf_sysctl_ignore_routes_with_linkdown()
6401 /* ctl->data points to idev->cnf.ignore_routes_when_linkdown in addrconf_sysctl_ignore_routes_with_linkdown()
6421 rt->dst.flags |= DST_NOPOLICY; in addrconf_set_nopolicy()
6423 rt->dst.flags &= ~DST_NOPOLICY; in addrconf_set_nopolicy()
6432 read_lock_bh(&idev->lock); in addrconf_disable_policy_idev()
6433 list_for_each_entry(ifa, &idev->addr_list, if_list) { in addrconf_disable_policy_idev()
6434 spin_lock(&ifa->lock); in addrconf_disable_policy_idev()
6435 if (ifa->rt) { in addrconf_disable_policy_idev()
6437 struct fib6_nh *nh = ifa->rt->fib6_nh; in addrconf_disable_policy_idev()
6441 ifa->rt->dst_nopolicy = val ? true : false; in addrconf_disable_policy_idev()
6442 if (nh->rt6i_pcpu) { in addrconf_disable_policy_idev()
6446 rtp = per_cpu_ptr(nh->rt6i_pcpu, cpu); in addrconf_disable_policy_idev()
6452 spin_unlock(&ifa->lock); in addrconf_disable_policy_idev()
6454 read_unlock_bh(&idev->lock); in addrconf_disable_policy_idev()
6468 net = (struct net *)ctl->extra2; in addrconf_disable_policy()
6469 if (valp == &net->ipv6.devconf_dflt->disable_policy) { in addrconf_disable_policy()
6474 if (valp == &net->ipv6.devconf_all->disable_policy) { in addrconf_disable_policy()
6483 idev = (struct inet6_dev *)ctl->extra1; in addrconf_disable_policy()
6494 int *valp = ctl->data; in addrconf_sysctl_disable_policy()
6513 static int minus_one = -1;
6916 table[i].data += (char *)p - (char *)&ipv6_devconf; in __addrconf_sysctl_register()
6929 p->sysctl_header = register_net_sysctl(net, path, table); in __addrconf_sysctl_register()
6930 if (!p->sysctl_header) in __addrconf_sysctl_register()
6938 ifindex = idev->dev->ifindex; in __addrconf_sysctl_register()
6946 return -ENOBUFS; in __addrconf_sysctl_register()
6954 if (!p->sysctl_header) in __addrconf_sysctl_unregister()
6957 table = p->sysctl_header->ctl_table_arg; in __addrconf_sysctl_unregister()
6958 unregister_net_sysctl_table(p->sysctl_header); in __addrconf_sysctl_unregister()
6959 p->sysctl_header = NULL; in __addrconf_sysctl_unregister()
6969 if (!sysctl_dev_name_is_allowed(idev->dev->name)) in addrconf_sysctl_register()
6970 return -EINVAL; in addrconf_sysctl_register()
6972 err = neigh_sysctl_register(idev->dev, idev->nd_parms, in addrconf_sysctl_register()
6976 err = __addrconf_sysctl_register(dev_net(idev->dev), idev->dev->name, in addrconf_sysctl_register()
6977 idev, &idev->cnf); in addrconf_sysctl_register()
6979 neigh_sysctl_unregister(idev->nd_parms); in addrconf_sysctl_register()
6986 __addrconf_sysctl_unregister(dev_net(idev->dev), &idev->cnf, in addrconf_sysctl_unregister()
6987 idev->dev->ifindex); in addrconf_sysctl_unregister()
6988 neigh_sysctl_unregister(idev->nd_parms); in addrconf_sysctl_unregister()
6996 int err = -ENOMEM; in addrconf_init_net()
7017 memcpy(all, current->nsproxy->net_ns->ipv6.devconf_all, in addrconf_init_net()
7020 current->nsproxy->net_ns->ipv6.devconf_dflt, in addrconf_init_net()
7031 dflt->autoconf = ipv6_defaults.autoconf; in addrconf_init_net()
7032 dflt->disable_ipv6 = ipv6_defaults.disable_ipv6; in addrconf_init_net()
7034 dflt->stable_secret.initialized = false; in addrconf_init_net()
7035 all->stable_secret.initialized = false; in addrconf_init_net()
7037 net->ipv6.devconf_all = all; in addrconf_init_net()
7038 net->ipv6.devconf_dflt = dflt; in addrconf_init_net()
7066 __addrconf_sysctl_unregister(net, net->ipv6.devconf_dflt, in addrconf_exit_net()
7068 __addrconf_sysctl_unregister(net, net->ipv6.devconf_all, in addrconf_exit_net()
7071 kfree(net->ipv6.devconf_dflt); in addrconf_exit_net()
7072 kfree(net->ipv6.devconf_all); in addrconf_exit_net()
7110 err = -ENOMEM; in addrconf_init()
7116 * before it can bring up and give link-local addresses in addrconf_init()
7123 * give link-local addresses to all devices besides loopback_dev in addrconf_init()
7124 * first, then loopback_dev, which cases all the non-loopback_dev in addrconf_init()
7125 * devices to fail to get a link-local address. in addrconf_init()