Lines Matching +full:route +full:- +full:ptp

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * FIB front-end.
14 * - respect outgoing interface
15 * - select from (probably) reachable routers (i.e.
17 * - always select the same router if it is (probably)
18 * reachable. otherwise, round-robin the list.
33 #include <linux/route.h>
78 RT6_NUD_FAIL_HARD = -3,
79 RT6_NUD_FAIL_PROBE = -2,
80 RT6_NUD_FAIL_DO_RR = -1,
138 rt->rt6i_uncached_list = ul; in rt6_uncached_list_add()
140 spin_lock_bh(&ul->lock); in rt6_uncached_list_add()
141 list_add_tail(&rt->rt6i_uncached, &ul->head); in rt6_uncached_list_add()
142 spin_unlock_bh(&ul->lock); in rt6_uncached_list_add()
147 if (!list_empty(&rt->rt6i_uncached)) { in rt6_uncached_list_del()
148 struct uncached_list *ul = rt->rt6i_uncached_list; in rt6_uncached_list_del()
149 struct net *net = dev_net(rt->dst.dev); in rt6_uncached_list_del()
151 spin_lock_bh(&ul->lock); in rt6_uncached_list_del()
152 list_del(&rt->rt6i_uncached); in rt6_uncached_list_del()
153 atomic_dec(&net->ipv6.rt6_stats->fib_rt_uncache); in rt6_uncached_list_del()
154 spin_unlock_bh(&ul->lock); in rt6_uncached_list_del()
160 struct net_device *loopback_dev = net->loopback_dev; in rt6_uncached_list_flush_dev()
170 spin_lock_bh(&ul->lock); in rt6_uncached_list_flush_dev()
171 list_for_each_entry(rt, &ul->head, rt6i_uncached) { in rt6_uncached_list_flush_dev()
172 struct inet6_dev *rt_idev = rt->rt6i_idev; in rt6_uncached_list_flush_dev()
173 struct net_device *rt_dev = rt->dst.dev; in rt6_uncached_list_flush_dev()
175 if (rt_idev->dev == dev) { in rt6_uncached_list_flush_dev()
176 rt->rt6i_idev = in6_dev_get(loopback_dev); in rt6_uncached_list_flush_dev()
181 rt->dst.dev = blackhole_netdev; in rt6_uncached_list_flush_dev()
182 dev_hold(rt->dst.dev); in rt6_uncached_list_flush_dev()
186 spin_unlock_bh(&ul->lock); in rt6_uncached_list_flush_dev()
197 return &ipv6_hdr(skb)->daddr; in choose_neigh_daddr()
224 dst->dev, skb, daddr); in ip6_dst_neigh_lookup()
229 struct net_device *dev = dst->dev; in ip6_confirm_neigh()
235 if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) in ip6_confirm_neigh()
265 return mtu ? : dst->dev->mtu; in ip6_blackhole_mtu()
292 [RTAX_HOPLIMIT - 1] = 0,
309 .error = -ENETUNREACH,
323 .error = -EACCES,
335 .error = -EINVAL,
346 struct dst_entry *dst = &rt->dst; in rt6_info_init()
348 memset(dst + 1, 0, sizeof(*rt) - sizeof(*dst)); in rt6_info_init()
349 INIT_LIST_HEAD(&rt->rt6i_uncached); in rt6_info_init()
356 struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev, in ip6_dst_alloc()
361 atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc); in ip6_dst_alloc()
377 idev = rt->rt6i_idev; in ip6_dst_destroy()
379 rt->rt6i_idev = NULL; in ip6_dst_destroy()
383 from = xchg((__force struct fib6_info **)&rt->from, NULL); in ip6_dst_destroy()
391 struct inet6_dev *idev = rt->rt6i_idev; in ip6_dst_ifdown()
393 dev_net(dev)->loopback_dev; in ip6_dst_ifdown()
395 if (idev && idev->dev != loopback_dev) { in ip6_dst_ifdown()
398 rt->rt6i_idev = loopback_idev; in ip6_dst_ifdown()
406 if (rt->rt6i_flags & RTF_EXPIRES) in __rt6_check_expired()
407 return time_after(jiffies, rt->dst.expires); in __rt6_check_expired()
416 from = rcu_dereference(rt->from); in rt6_check_expired()
418 if (rt->rt6i_flags & RTF_EXPIRES) { in rt6_check_expired()
419 if (time_after(jiffies, rt->dst.expires)) in rt6_check_expired()
422 return rt->dst.obsolete != DST_OBSOLETE_FORCE_CHK || in rt6_check_expired()
433 struct fib6_info *match = res->f6i; in fib6_select_path()
435 if (!match->nh && (!match->fib6_nsiblings || have_oif_match)) in fib6_select_path()
438 if (match->nh && have_oif_match && res->nh) in fib6_select_path()
442 * case it will always be non-zero. Otherwise now is the time to do it. in fib6_select_path()
444 if (!fl6->mp_hash && in fib6_select_path()
445 (!match->nh || nexthop_is_multipath(match->nh))) in fib6_select_path()
446 fl6->mp_hash = rt6_multipath_hash(net, fl6, skb, NULL); in fib6_select_path()
448 if (unlikely(match->nh)) { in fib6_select_path()
449 nexthop_path_fib6_result(res, fl6->mp_hash); in fib6_select_path()
453 if (fl6->mp_hash <= atomic_read(&match->fib6_nh->fib_nh_upper_bound)) in fib6_select_path()
456 list_for_each_entry_safe(sibling, next_sibling, &match->fib6_siblings, in fib6_select_path()
458 const struct fib6_nh *nh = sibling->fib6_nh; in fib6_select_path()
461 nh_upper_bound = atomic_read(&nh->fib_nh_upper_bound); in fib6_select_path()
462 if (fl6->mp_hash > nh_upper_bound) in fib6_select_path()
464 if (rt6_score_route(nh, sibling->fib6_flags, oif, strict) < 0) in fib6_select_path()
471 res->f6i = match; in fib6_select_path()
472 res->nh = match->fib6_nh; in fib6_select_path()
476 * Route lookup. rcu_read_lock() should be held.
484 if (nh->fib_nh_flags & RTNH_F_DEAD) in __rt6_device_match()
487 dev = nh->fib_nh_dev; in __rt6_device_match()
489 if (dev->ifindex == oif) in __rt6_device_match()
512 arg->nh = nh; in __rt6_nh_dev_match()
513 return __rt6_device_match(arg->net, nh, arg->saddr, arg->oif, in __rt6_nh_dev_match()
514 arg->flags); in __rt6_nh_dev_match()
542 struct fib6_info *f6i = res->f6i; in rt6_device_match()
547 if (unlikely(f6i->nh)) { in rt6_device_match()
548 nh = nexthop_fib6_nh(f6i->nh); in rt6_device_match()
549 if (nexthop_is_blackhole(f6i->nh)) in rt6_device_match()
552 nh = f6i->fib6_nh; in rt6_device_match()
554 if (!(nh->fib_nh_flags & RTNH_F_DEAD)) in rt6_device_match()
558 for (spf6i = f6i; spf6i; spf6i = rcu_dereference(spf6i->fib6_next)) { in rt6_device_match()
561 if (unlikely(spf6i->nh)) { in rt6_device_match()
562 nh = rt6_nh_dev_match(net, spf6i->nh, res, saddr, in rt6_device_match()
567 nh = spf6i->fib6_nh; in rt6_device_match()
572 res->f6i = spf6i; in rt6_device_match()
578 res->f6i = net->ipv6.fib6_null_entry; in rt6_device_match()
579 nh = res->f6i->fib6_nh; in rt6_device_match()
583 if (unlikely(f6i->nh)) { in rt6_device_match()
584 nh = nexthop_fib6_nh(f6i->nh); in rt6_device_match()
585 if (nexthop_is_blackhole(f6i->nh)) in rt6_device_match()
588 nh = f6i->fib6_nh; in rt6_device_match()
591 if (nh->fib_nh_flags & RTNH_F_DEAD) { in rt6_device_match()
592 res->f6i = net->ipv6.fib6_null_entry; in rt6_device_match()
593 nh = res->f6i->fib6_nh; in rt6_device_match()
596 res->nh = nh; in rt6_device_match()
597 res->fib6_type = res->f6i->fib6_type; in rt6_device_match()
598 res->fib6_flags = res->f6i->fib6_flags; in rt6_device_match()
602 res->fib6_flags |= RTF_REJECT; in rt6_device_match()
603 res->fib6_type = RTN_BLACKHOLE; in rt6_device_match()
604 res->nh = nh; in rt6_device_match()
620 addrconf_addr_solict_mult(&work->target, &mcaddr); in rt6_probe_deferred()
621 ndisc_send_ns(work->dev, &work->target, &mcaddr, NULL, 0); in rt6_probe_deferred()
622 dev_put(work->dev); in rt6_probe_deferred()
640 * Router Reachability Probe MUST be rate-limited in rt6_probe()
643 if (!fib6_nh->fib_nh_gw_family) in rt6_probe()
646 nh_gw = &fib6_nh->fib_nh_gw6; in rt6_probe()
647 dev = fib6_nh->fib_nh_dev; in rt6_probe()
649 last_probe = READ_ONCE(fib6_nh->last_probe); in rt6_probe()
653 if (neigh->nud_state & NUD_VALID) in rt6_probe()
656 write_lock(&neigh->lock); in rt6_probe()
657 if (!(neigh->nud_state & NUD_VALID) && in rt6_probe()
659 neigh->updated + idev->cnf.rtr_probe_interval)) { in rt6_probe()
664 write_unlock(&neigh->lock); in rt6_probe()
666 idev->cnf.rtr_probe_interval)) { in rt6_probe()
670 if (!work || cmpxchg(&fib6_nh->last_probe, in rt6_probe()
674 INIT_WORK(&work->work, rt6_probe_deferred); in rt6_probe()
675 work->target = *nh_gw; in rt6_probe()
677 work->dev = dev; in rt6_probe()
678 schedule_work(&work->work); in rt6_probe()
699 neigh = __ipv6_neigh_lookup_noref(fib6_nh->fib_nh_dev, in rt6_check_neigh()
700 &fib6_nh->fib_nh_gw6); in rt6_check_neigh()
702 read_lock(&neigh->lock); in rt6_check_neigh()
703 if (neigh->nud_state & NUD_VALID) in rt6_check_neigh()
706 else if (!(neigh->nud_state & NUD_FAILED)) in rt6_check_neigh()
711 read_unlock(&neigh->lock); in rt6_check_neigh()
726 if (!oif || nh->fib_nh_dev->ifindex == oif) in rt6_score_route()
735 !(fib6_flags & RTF_NONEXTHOP) && nh->fib_nh_gw_family) { in rt6_score_route()
750 if (nh->fib_nh_flags & RTNH_F_DEAD) in find_match()
753 if (ip6_ignore_linkdown(nh->fib_nh_dev) && in find_match()
754 nh->fib_nh_flags & RTNH_F_LINKDOWN && in find_match()
792 arg->nh = nh; in rt6_nh_find_match()
793 return find_match(nh, arg->flags, arg->oif, arg->strict, in rt6_nh_find_match()
794 arg->mpri, arg->do_rr); in rt6_nh_find_match()
806 f6i = rcu_dereference(f6i->fib6_next)) { in __find_rr_leaf()
810 if (cont && f6i->fib6_metric != metric) { in __find_rr_leaf()
818 if (unlikely(f6i->nh)) { in __find_rr_leaf()
820 .flags = f6i->fib6_flags, in __find_rr_leaf()
827 if (nexthop_is_blackhole(f6i->nh)) { in __find_rr_leaf()
828 res->fib6_flags = RTF_REJECT; in __find_rr_leaf()
829 res->fib6_type = RTN_BLACKHOLE; in __find_rr_leaf()
830 res->f6i = f6i; in __find_rr_leaf()
831 res->nh = nexthop_fib6_nh(f6i->nh); in __find_rr_leaf()
834 if (nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_find_match, in __find_rr_leaf()
840 nh = f6i->fib6_nh; in __find_rr_leaf()
841 if (find_match(nh, f6i->fib6_flags, oif, strict, in __find_rr_leaf()
846 res->f6i = f6i; in __find_rr_leaf()
847 res->nh = nh; in __find_rr_leaf()
848 res->fib6_flags = f6i->fib6_flags; in __find_rr_leaf()
849 res->fib6_type = f6i->fib6_type; in __find_rr_leaf()
858 u32 metric = rr_head->fib6_metric; in find_rr_leaf()
860 int mpri = -1; in find_rr_leaf()
868 if (res->f6i || !cont) in find_rr_leaf()
878 struct fib6_info *leaf = rcu_dereference(fn->leaf); in rt6_select()
884 res->f6i = NULL; in rt6_select()
886 if (!leaf || leaf == net->ipv6.fib6_null_entry) in rt6_select()
889 rt0 = rcu_dereference(fn->rr_ptr); in rt6_select()
894 * and fn->leaf does not points to its child's leaf in rt6_select()
898 key_plen = rt0->fib6_dst.plen; in rt6_select()
900 if (rt0->fib6_src.plen) in rt6_select()
901 key_plen = rt0->fib6_src.plen; in rt6_select()
903 if (fn->fn_bit != key_plen) in rt6_select()
908 struct fib6_info *next = rcu_dereference(rt0->fib6_next); in rt6_select()
910 /* no entries matched; do round-robin */ in rt6_select()
911 if (!next || next->fib6_metric != rt0->fib6_metric) in rt6_select()
915 spin_lock_bh(&leaf->fib6_table->tb6_lock); in rt6_select()
917 if (next->fib6_node) in rt6_select()
918 rcu_assign_pointer(fn->rr_ptr, next); in rt6_select()
919 spin_unlock_bh(&leaf->fib6_table->tb6_lock); in rt6_select()
924 if (!res->f6i) { in rt6_select()
925 res->f6i = net->ipv6.fib6_null_entry; in rt6_select()
926 res->nh = res->f6i->fib6_nh; in rt6_select()
927 res->fib6_flags = res->f6i->fib6_flags; in rt6_select()
928 res->fib6_type = res->f6i->fib6_type; in rt6_select()
934 return (res->f6i->fib6_flags & RTF_NONEXTHOP) || in rt6_is_gw_or_nonexthop()
935 res->nh->fib_nh_gw_family; in rt6_is_gw_or_nonexthop()
950 return -EINVAL; in rt6_route_rcv()
954 if (rinfo->length > 3) { in rt6_route_rcv()
955 return -EINVAL; in rt6_route_rcv()
956 } else if (rinfo->prefix_len > 128) { in rt6_route_rcv()
957 return -EINVAL; in rt6_route_rcv()
958 } else if (rinfo->prefix_len > 64) { in rt6_route_rcv()
959 if (rinfo->length < 2) { in rt6_route_rcv()
960 return -EINVAL; in rt6_route_rcv()
962 } else if (rinfo->prefix_len > 0) { in rt6_route_rcv()
963 if (rinfo->length < 1) { in rt6_route_rcv()
964 return -EINVAL; in rt6_route_rcv()
968 pref = rinfo->route_pref; in rt6_route_rcv()
970 return -EINVAL; in rt6_route_rcv()
972 lifetime = addrconf_timeout_fixup(ntohl(rinfo->lifetime), HZ); in rt6_route_rcv()
974 if (rinfo->length == 3) in rt6_route_rcv()
975 prefix = (struct in6_addr *)rinfo->prefix; in rt6_route_rcv()
979 (struct in6_addr *)rinfo->prefix, in rt6_route_rcv()
980 rinfo->prefix_len); in rt6_route_rcv()
984 if (rinfo->prefix_len == 0) in rt6_route_rcv()
987 rt = rt6_get_route_info(net, prefix, rinfo->prefix_len, in rt6_route_rcv()
996 rt = rt6_add_route_info(net, prefix, rinfo->prefix_len, gwaddr, in rt6_route_rcv()
999 rt->fib6_flags = RTF_ROUTEINFO | in rt6_route_rcv()
1000 (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); in rt6_route_rcv()
1021 struct net_device *dev = res->nh->fib_nh_dev; in ip6_rt_get_dev_rcu()
1023 if (res->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) { in ip6_rt_get_dev_rcu()
1024 /* for copies of local routes, dst->dev needs to be the in ip6_rt_get_dev_rcu()
1029 !rt6_need_strict(&res->f6i->fib6_dst.addr)) in ip6_rt_get_dev_rcu()
1032 dev = dev_net(dev)->loopback_dev; in ip6_rt_get_dev_rcu()
1048 [RTN_BLACKHOLE] = -EINVAL,
1049 [RTN_UNREACHABLE] = -EHOSTUNREACH,
1050 [RTN_PROHIBIT] = -EACCES,
1051 [RTN_THROW] = -EAGAIN,
1052 [RTN_NAT] = -EINVAL,
1053 [RTN_XRESOLVE] = -EINVAL,
1065 if (rt->dst_nocount) in fib6_info_dst_flags()
1067 if (rt->dst_nopolicy) in fib6_info_dst_flags()
1075 rt->dst.error = ip6_rt_type_to_error(fib6_type); in ip6_rt_init_dst_reject()
1079 rt->dst.output = dst_discard_out; in ip6_rt_init_dst_reject()
1080 rt->dst.input = dst_discard; in ip6_rt_init_dst_reject()
1083 rt->dst.output = ip6_pkt_prohibit_out; in ip6_rt_init_dst_reject()
1084 rt->dst.input = ip6_pkt_prohibit; in ip6_rt_init_dst_reject()
1089 rt->dst.output = ip6_pkt_discard_out; in ip6_rt_init_dst_reject()
1090 rt->dst.input = ip6_pkt_discard; in ip6_rt_init_dst_reject()
1097 struct fib6_info *f6i = res->f6i; in ip6_rt_init_dst()
1099 if (res->fib6_flags & RTF_REJECT) { in ip6_rt_init_dst()
1100 ip6_rt_init_dst_reject(rt, res->fib6_type); in ip6_rt_init_dst()
1104 rt->dst.error = 0; in ip6_rt_init_dst()
1105 rt->dst.output = ip6_output; in ip6_rt_init_dst()
1107 if (res->fib6_type == RTN_LOCAL || res->fib6_type == RTN_ANYCAST) { in ip6_rt_init_dst()
1108 rt->dst.input = ip6_input; in ip6_rt_init_dst()
1109 } else if (ipv6_addr_type(&f6i->fib6_dst.addr) & IPV6_ADDR_MULTICAST) { in ip6_rt_init_dst()
1110 rt->dst.input = ip6_mc_input; in ip6_rt_init_dst()
1112 rt->dst.input = ip6_forward; in ip6_rt_init_dst()
1115 if (res->nh->fib_nh_lws) { in ip6_rt_init_dst()
1116 rt->dst.lwtstate = lwtstate_get(res->nh->fib_nh_lws); in ip6_rt_init_dst()
1117 lwtunnel_set_redirect(&rt->dst); in ip6_rt_init_dst()
1120 rt->dst.lastuse = jiffies; in ip6_rt_init_dst()
1126 rt->rt6i_flags &= ~RTF_EXPIRES; in rt6_set_from()
1127 rcu_assign_pointer(rt->from, from); in rt6_set_from()
1128 ip_dst_init_metrics(&rt->dst, from->fib6_metrics); in rt6_set_from()
1134 const struct fib6_nh *nh = res->nh; in ip6_rt_copy_init()
1135 const struct net_device *dev = nh->fib_nh_dev; in ip6_rt_copy_init()
1136 struct fib6_info *f6i = res->f6i; in ip6_rt_copy_init()
1140 rt->rt6i_dst = f6i->fib6_dst; in ip6_rt_copy_init()
1141 rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL; in ip6_rt_copy_init()
1142 rt->rt6i_flags = res->fib6_flags; in ip6_rt_copy_init()
1143 if (nh->fib_nh_gw_family) { in ip6_rt_copy_init()
1144 rt->rt6i_gateway = nh->fib_nh_gw6; in ip6_rt_copy_init()
1145 rt->rt6i_flags |= RTF_GATEWAY; in ip6_rt_copy_init()
1149 rt->rt6i_src = f6i->fib6_src; in ip6_rt_copy_init()
1158 if (fn->fn_flags & RTN_TL_ROOT) in fib6_backtrack()
1160 pn = rcu_dereference(fn->parent); in fib6_backtrack()
1166 if (fn->fn_flags & RTN_RTINFO) in fib6_backtrack()
1175 if (dst_hold_safe(&rt->dst)) in ip6_hold_safe()
1178 rt = net->ipv6.ip6_null_entry; in ip6_hold_safe()
1179 dst_hold(&rt->dst); in ip6_hold_safe()
1190 struct net_device *dev = res->nh->fib_nh_dev; in ip6_create_rt_rcu()
1191 struct fib6_info *f6i = res->f6i; in ip6_create_rt_rcu()
1209 nrt = dev_net(dev)->ipv6.ip6_null_entry; in ip6_create_rt_rcu()
1210 dst_hold(&nrt->dst); in ip6_create_rt_rcu()
1224 if (fl6->flowi6_flags & FLOWI_FLAG_SKIP_NH_OIF) in ip6_pol_route_lookup()
1228 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in ip6_pol_route_lookup()
1230 res.f6i = rcu_dereference(fn->leaf); in ip6_pol_route_lookup()
1232 res.f6i = net->ipv6.fib6_null_entry; in ip6_pol_route_lookup()
1234 rt6_device_match(net, &res, &fl6->saddr, fl6->flowi6_oif, in ip6_pol_route_lookup()
1237 if (res.f6i == net->ipv6.fib6_null_entry) { in ip6_pol_route_lookup()
1238 fn = fib6_backtrack(fn, &fl6->saddr); in ip6_pol_route_lookup()
1242 rt = net->ipv6.ip6_null_entry; in ip6_pol_route_lookup()
1243 dst_hold(&rt->dst); in ip6_pol_route_lookup()
1249 fib6_select_path(net, &res, fl6, fl6->flowi6_oif, in ip6_pol_route_lookup()
1250 fl6->flowi6_oif != 0, skb, flags); in ip6_pol_route_lookup()
1253 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route_lookup()
1256 dst_use_noref(&rt->dst, jiffies); in ip6_pol_route_lookup()
1294 if (dst->error == 0) in rt6_lookup()
1303 /* ip6_ins_rt is called with FREE table->tb6_lock.
1304 * It takes new route entry, the addition fails by any reason the
1305 * route is released.
1315 table = rt->fib6_table; in __ip6_ins_rt()
1316 spin_lock_bh(&table->tb6_lock); in __ip6_ins_rt()
1317 err = fib6_add(&table->tb6_root, rt, info, extack); in __ip6_ins_rt()
1318 spin_unlock_bh(&table->tb6_lock); in __ip6_ins_rt()
1334 struct fib6_info *f6i = res->f6i; in ip6_rt_cache_alloc()
1339 * Clone the route. in ip6_rt_cache_alloc()
1353 rt->rt6i_flags |= RTF_CACHE; in ip6_rt_cache_alloc()
1354 rt->rt6i_dst.addr = *daddr; in ip6_rt_cache_alloc()
1355 rt->rt6i_dst.plen = 128; in ip6_rt_cache_alloc()
1358 if (f6i->fib6_dst.plen != 128 && in ip6_rt_cache_alloc()
1359 ipv6_addr_equal(&f6i->fib6_dst.addr, daddr)) in ip6_rt_cache_alloc()
1360 rt->rt6i_flags |= RTF_ANYCAST; in ip6_rt_cache_alloc()
1362 if (rt->rt6i_src.plen && saddr) { in ip6_rt_cache_alloc()
1363 rt->rt6i_src.addr = *saddr; in ip6_rt_cache_alloc()
1364 rt->rt6i_src.plen = 128; in ip6_rt_cache_alloc()
1374 struct fib6_info *f6i = res->f6i; in ip6_rt_pcpu_alloc()
1391 pcpu_rt->rt6i_flags |= RTF_PCPU; in ip6_rt_pcpu_alloc()
1393 if (f6i->nh) in ip6_rt_pcpu_alloc()
1394 pcpu_rt->sernum = rt_genid_ipv6(dev_net(dev)); in ip6_rt_pcpu_alloc()
1401 return rt6->sernum == rt_genid_ipv6(dev_net(rt6->dst.dev)); in rt6_is_valid()
1409 pcpu_rt = this_cpu_read(*res->nh->rt6i_pcpu); in rt6_get_pcpu_route()
1411 if (pcpu_rt && pcpu_rt->sernum && !rt6_is_valid(pcpu_rt)) { in rt6_get_pcpu_route()
1414 p = this_cpu_ptr(res->nh->rt6i_pcpu); in rt6_get_pcpu_route()
1417 dst_dev_put(&prev->dst); in rt6_get_pcpu_route()
1418 dst_release(&prev->dst); in rt6_get_pcpu_route()
1436 p = this_cpu_ptr(res->nh->rt6i_pcpu); in rt6_make_pcpu_route()
1440 if (res->f6i->fib6_destroying) { in rt6_make_pcpu_route()
1443 from = xchg((__force struct fib6_info **)&pcpu_rt->from, NULL); in rt6_make_pcpu_route()
1466 net = dev_net(rt6_ex->rt6i->dst.dev); in rt6_remove_exception()
1467 net->ipv6.rt6_stats->fib_rt_cache--; in rt6_remove_exception()
1472 from = xchg((__force struct fib6_info **)&rt6_ex->rt6i->from, NULL); in rt6_remove_exception()
1474 dst_dev_put(&rt6_ex->rt6i->dst); in rt6_remove_exception()
1476 hlist_del_rcu(&rt6_ex->hlist); in rt6_remove_exception()
1477 dst_release(&rt6_ex->rt6i->dst); in rt6_remove_exception()
1479 WARN_ON_ONCE(!bucket->depth); in rt6_remove_exception()
1480 bucket->depth--; in rt6_remove_exception()
1493 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_exception_remove_oldest()
1494 if (!oldest || time_before(rt6_ex->stamp, oldest->stamp)) in rt6_exception_remove_oldest()
1535 hlist_for_each_entry(rt6_ex, &(*bucket)->chain, hlist) { in __rt6_find_exception_spinlock()
1536 struct rt6_info *rt6 = rt6_ex->rt6i; in __rt6_find_exception_spinlock()
1537 bool matched = ipv6_addr_equal(daddr, &rt6->rt6i_dst.addr); in __rt6_find_exception_spinlock()
1541 matched = ipv6_addr_equal(saddr, &rt6->rt6i_src.addr); in __rt6_find_exception_spinlock()
1570 hlist_for_each_entry_rcu(rt6_ex, &(*bucket)->chain, hlist) { in __rt6_find_exception_rcu()
1571 struct rt6_info *rt6 = rt6_ex->rt6i; in __rt6_find_exception_rcu()
1572 bool matched = ipv6_addr_equal(daddr, &rt6->rt6i_dst.addr); in __rt6_find_exception_rcu()
1576 matched = ipv6_addr_equal(saddr, &rt6->rt6i_src.addr); in __rt6_find_exception_rcu()
1586 const struct fib6_nh *nh = res->nh; in fib6_mtu()
1589 if (res->f6i->fib6_pmtu) { in fib6_mtu()
1590 mtu = res->f6i->fib6_pmtu; in fib6_mtu()
1592 struct net_device *dev = nh->fib_nh_dev; in fib6_mtu()
1597 mtu = idev->cnf.mtu6; in fib6_mtu()
1603 return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu); in fib6_mtu()
1620 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in fib6_nh_get_excptn_bucket()
1623 bucket = rcu_dereference(nh->rt6i_exception_bucket); in fib6_nh_get_excptn_bucket()
1650 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in fib6_nh_excptn_bucket_set_flushed()
1656 rcu_assign_pointer(nh->rt6i_exception_bucket, bucket); in fib6_nh_excptn_bucket_set_flushed()
1662 struct net *net = dev_net(nrt->dst.dev); in rt6_insert_exception()
1664 struct fib6_info *f6i = res->f6i; in rt6_insert_exception()
1667 struct fib6_nh *nh = res->nh; in rt6_insert_exception()
1672 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in rt6_insert_exception()
1678 err = -ENOMEM; in rt6_insert_exception()
1681 rcu_assign_pointer(nh->rt6i_exception_bucket, bucket); in rt6_insert_exception()
1683 err = -EINVAL; in rt6_insert_exception()
1694 if (f6i->fib6_src.plen) in rt6_insert_exception()
1695 src_key = &nrt->rt6i_src.addr; in rt6_insert_exception()
1698 * Only insert this exception route if its mtu in rt6_insert_exception()
1701 if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(res)) { in rt6_insert_exception()
1702 err = -EINVAL; in rt6_insert_exception()
1706 rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr, in rt6_insert_exception()
1713 err = -ENOMEM; in rt6_insert_exception()
1716 rt6_ex->rt6i = nrt; in rt6_insert_exception()
1717 rt6_ex->stamp = jiffies; in rt6_insert_exception()
1718 hlist_add_head_rcu(&rt6_ex->hlist, &bucket->chain); in rt6_insert_exception()
1719 bucket->depth++; in rt6_insert_exception()
1720 net->ipv6.rt6_stats->fib_rt_cache++; in rt6_insert_exception()
1722 if (bucket->depth > FIB6_MAX_DEPTH) in rt6_insert_exception()
1728 /* Update fn->fn_sernum to invalidate all cached dst */ in rt6_insert_exception()
1730 spin_lock_bh(&f6i->fib6_table->tb6_lock); in rt6_insert_exception()
1732 spin_unlock_bh(&f6i->fib6_table->tb6_lock); in rt6_insert_exception()
1757 hlist_for_each_entry_safe(rt6_ex, tmp, &bucket->chain, hlist) { in fib6_nh_flush_exceptions()
1759 rcu_access_pointer(rt6_ex->rt6i->from) == from) in fib6_nh_flush_exceptions()
1762 WARN_ON_ONCE(!from && bucket->depth); in fib6_nh_flush_exceptions()
1780 if (f6i->nh) in rt6_flush_exceptions()
1781 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_flush_exceptions, in rt6_flush_exceptions()
1784 fib6_nh_flush_exceptions(f6i->fib6_nh, f6i); in rt6_flush_exceptions()
1806 * So we need to use f6i->fib6_src to redo lookup in rt6_find_cached_rt()
1809 * rt->rt6i_src is updated.) in rt6_find_cached_rt()
1811 if (res->f6i->fib6_src.plen) in rt6_find_cached_rt()
1815 bucket = fib6_nh_get_excptn_bucket(res->nh, NULL); in rt6_find_cached_rt()
1818 if (rt6_ex && !rt6_check_expired(rt6_ex->rt6i)) in rt6_find_cached_rt()
1819 ret = rt6_ex->rt6i; in rt6_find_cached_rt()
1823 if (!ret && src_key && src_key != &res->f6i->fib6_src.addr) { in rt6_find_cached_rt()
1824 src_key = &res->f6i->fib6_src.addr; in rt6_find_cached_rt()
1841 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_remove_exception()
1842 return -ENOENT; in fib6_nh_remove_exception()
1855 src_key = &rt->rt6i_src.addr; in fib6_nh_remove_exception()
1858 &rt->rt6i_dst.addr, in fib6_nh_remove_exception()
1864 err = -ENOENT; in fib6_nh_remove_exception()
1881 err = fib6_nh_remove_exception(nh, arg->plen, arg->rt); in rt6_nh_remove_exception_rt()
1892 from = rcu_dereference(rt->from); in rt6_remove_exception_rt()
1893 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_remove_exception_rt()
1894 return -EINVAL; in rt6_remove_exception_rt()
1896 if (from->nh) { in rt6_remove_exception_rt()
1899 .plen = from->fib6_src.plen in rt6_remove_exception_rt()
1904 rc = nexthop_for_each_fib6_nh(from->nh, in rt6_remove_exception_rt()
1907 return rc ? 0 : -ENOENT; in rt6_remove_exception_rt()
1910 return fib6_nh_remove_exception(from->fib6_nh, in rt6_remove_exception_rt()
1911 from->fib6_src.plen, rt); in rt6_remove_exception_rt()
1933 src_key = &rt->rt6i_src.addr; in fib6_nh_update_exception()
1935 rt6_ex = __rt6_find_exception_rcu(&bucket, &rt->rt6i_dst.addr, src_key); in fib6_nh_update_exception()
1937 rt6_ex->stamp = jiffies; in fib6_nh_update_exception()
1951 if (arg->dev != nh->fib_nh_dev || in fib6_nh_find_match()
1952 (arg->gw && !nh->fib_nh_gw_family) || in fib6_nh_find_match()
1953 (!arg->gw && nh->fib_nh_gw_family) || in fib6_nh_find_match()
1954 (arg->gw && !ipv6_addr_equal(arg->gw, &nh->fib_nh_gw6))) in fib6_nh_find_match()
1957 arg->match = nh; in fib6_nh_find_match()
1970 from = rcu_dereference(rt->from); in rt6_update_exception_stamp_rt()
1971 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_update_exception_stamp_rt()
1974 if (from->nh) { in rt6_update_exception_stamp_rt()
1976 .dev = rt->dst.dev, in rt6_update_exception_stamp_rt()
1977 .gw = &rt->rt6i_gateway, in rt6_update_exception_stamp_rt()
1980 nexthop_for_each_fib6_nh(from->nh, fib6_nh_find_match, &arg); in rt6_update_exception_stamp_rt()
1986 fib6_nh = from->fib6_nh; in rt6_update_exception_stamp_rt()
1988 fib6_nh_update_exception(fib6_nh, from->fib6_src.plen, rt); in rt6_update_exception_stamp_rt()
1996 /* If the new MTU is lower than the route PMTU, this new MTU will be the in rt6_mtu_change_route_allowed()
1997 * lowest MTU in the path: always allow updating the route PMTU to in rt6_mtu_change_route_allowed()
2000 * If the new MTU is higher, and the route PMTU is equal to the local in rt6_mtu_change_route_allowed()
2006 if (dst_mtu(&rt->dst) >= mtu) in rt6_mtu_change_route_allowed()
2009 if (dst_mtu(&rt->dst) == idev->cnf.mtu6) in rt6_mtu_change_route_allowed()
2027 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_exceptions_update_pmtu()
2028 struct rt6_info *entry = rt6_ex->rt6i; in rt6_exceptions_update_pmtu()
2031 * route), the metrics of its rt->from have already in rt6_exceptions_update_pmtu()
2034 if (dst_metric_raw(&entry->dst, RTAX_MTU) && in rt6_exceptions_update_pmtu()
2036 dst_metric_set(&entry->dst, RTAX_MTU, mtu); in rt6_exceptions_update_pmtu()
2052 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_exceptions_clean_tohost()
2060 &bucket->chain, hlist) { in fib6_nh_exceptions_clean_tohost()
2061 struct rt6_info *entry = rt6_ex->rt6i; in fib6_nh_exceptions_clean_tohost()
2063 if ((entry->rt6i_flags & RTF_CACHE_GATEWAY) == in fib6_nh_exceptions_clean_tohost()
2066 &entry->rt6i_gateway)) { in fib6_nh_exceptions_clean_tohost()
2082 struct rt6_info *rt = rt6_ex->rt6i; in rt6_age_examine_exception()
2084 /* we are pruning and obsoleting aged-out and non gateway exceptions in rt6_age_examine_exception()
2087 * EXPIRES exceptions - e.g. pmtu-generated ones are pruned when in rt6_age_examine_exception()
2090 if (!(rt->rt6i_flags & RTF_EXPIRES)) { in rt6_age_examine_exception()
2091 if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) { in rt6_age_examine_exception()
2096 } else if (time_after(jiffies, rt->dst.expires)) { in rt6_age_examine_exception()
2097 RT6_TRACE("purging expired route %p\n", rt); in rt6_age_examine_exception()
2102 if (rt->rt6i_flags & RTF_GATEWAY) { in rt6_age_examine_exception()
2106 neigh = __ipv6_neigh_lookup_noref(rt->dst.dev, &rt->rt6i_gateway); in rt6_age_examine_exception()
2108 neigh_flags = neigh->flags; in rt6_age_examine_exception()
2111 RT6_TRACE("purging route %p via non-router but gateway\n", in rt6_age_examine_exception()
2118 gc_args->more++; in rt6_age_examine_exception()
2130 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_age_exceptions()
2139 &bucket->chain, hlist) { in fib6_nh_age_exceptions()
2159 fib6_nh_age_exceptions(nh, arg->gc_args, arg->now); in rt6_nh_age_exceptions()
2167 if (f6i->nh) { in rt6_age_exceptions()
2173 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_age_exceptions, in rt6_age_exceptions()
2176 fib6_nh_age_exceptions(f6i->fib6_nh, gc_args, now); in rt6_age_exceptions()
2186 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in fib6_table_lookup()
2189 if (fl6->flowi6_flags & FLOWI_FLAG_SKIP_NH_OIF) in fib6_table_lookup()
2194 if (res->f6i == net->ipv6.fib6_null_entry) { in fib6_table_lookup()
2195 fn = fib6_backtrack(fn, &fl6->saddr); in fib6_table_lookup()
2199 /* also consider unreachable route */ in fib6_table_lookup()
2224 if (net->ipv6.devconf_all->forwarding == 0) in ip6_pol_route()
2230 if (res.f6i == net->ipv6.fib6_null_entry) in ip6_pol_route()
2236 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route()
2239 } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) && in ip6_pol_route()
2240 !res.nh->fib_nh_gw_family)) { in ip6_pol_route()
2243 * the daddr in the skb during the neighbor look-up is different in ip6_pol_route()
2244 * from the fl6->daddr used to look-up route here. in ip6_pol_route()
2246 rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL); in ip6_pol_route()
2255 atomic_inc(&net->ipv6.rt6_stats->fib_rt_uncache); in ip6_pol_route()
2272 rt = net->ipv6.ip6_null_entry; in ip6_pol_route()
2287 return ip6_pol_route(net, table, fl6->flowi6_iif, fl6, skb, flags); in ip6_pol_route_input()
2296 if (rt6_need_strict(&fl6->daddr) && dev->type != ARPHRD_PIMREG) in ip6_route_input_lookup()
2315 if (likely(outer_iph->nexthdr != IPPROTO_ICMPV6)) in ip6_multipath_l3_keys()
2323 if (!icmpv6_is_err(icmph->icmp6_type)) in ip6_multipath_l3_keys()
2336 keys->addrs.v6addrs.src = _flkeys->addrs.v6addrs.src; in ip6_multipath_l3_keys()
2337 keys->addrs.v6addrs.dst = _flkeys->addrs.v6addrs.dst; in ip6_multipath_l3_keys()
2338 keys->tags.flow_label = _flkeys->tags.flow_label; in ip6_multipath_l3_keys()
2339 keys->basic.ip_proto = _flkeys->basic.ip_proto; in ip6_multipath_l3_keys()
2341 keys->addrs.v6addrs.src = key_iph->saddr; in ip6_multipath_l3_keys()
2342 keys->addrs.v6addrs.dst = key_iph->daddr; in ip6_multipath_l3_keys()
2343 keys->tags.flow_label = ip6_flowlabel(key_iph); in ip6_multipath_l3_keys()
2344 keys->basic.ip_proto = key_iph->nexthdr; in ip6_multipath_l3_keys()
2362 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2363 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2365 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2373 /* short-circuit if we already have L4 hash present */ in rt6_multipath_hash()
2374 if (skb->l4_hash) in rt6_multipath_hash()
2384 hash_keys.addrs.v6addrs.src = flkeys->addrs.v6addrs.src; in rt6_multipath_hash()
2385 hash_keys.addrs.v6addrs.dst = flkeys->addrs.v6addrs.dst; in rt6_multipath_hash()
2386 hash_keys.ports.src = flkeys->ports.src; in rt6_multipath_hash()
2387 hash_keys.ports.dst = flkeys->ports.dst; in rt6_multipath_hash()
2388 hash_keys.basic.ip_proto = flkeys->basic.ip_proto; in rt6_multipath_hash()
2392 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2393 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2394 hash_keys.ports.src = fl6->fl6_sport; in rt6_multipath_hash()
2395 hash_keys.ports.dst = fl6->fl6_dport; in rt6_multipath_hash()
2396 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2411 if (flkeys->control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) { in rt6_multipath_hash()
2413 hash_keys.addrs.v4addrs.src = flkeys->addrs.v4addrs.src; in rt6_multipath_hash()
2414 hash_keys.addrs.v4addrs.dst = flkeys->addrs.v4addrs.dst; in rt6_multipath_hash()
2415 } else if (flkeys->control.addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) { in rt6_multipath_hash()
2417 hash_keys.addrs.v6addrs.src = flkeys->addrs.v6addrs.src; in rt6_multipath_hash()
2418 hash_keys.addrs.v6addrs.dst = flkeys->addrs.v6addrs.dst; in rt6_multipath_hash()
2419 hash_keys.tags.flow_label = flkeys->tags.flow_label; in rt6_multipath_hash()
2420 hash_keys.basic.ip_proto = flkeys->basic.ip_proto; in rt6_multipath_hash()
2429 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2430 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2432 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2445 struct net *net = dev_net(skb->dev); in ip6_route_input()
2449 .flowi6_iif = skb->dev->ifindex, in ip6_route_input()
2450 .daddr = iph->daddr, in ip6_route_input()
2451 .saddr = iph->saddr, in ip6_route_input()
2453 .flowi6_mark = skb->mark, in ip6_route_input()
2454 .flowi6_proto = iph->nexthdr, in ip6_route_input()
2459 if (tun_info && !(tun_info->mode & IP_TUNNEL_INFO_TX)) in ip6_route_input()
2460 fl6.flowi6_tun_key.tun_id = tun_info->key.tun_id; in ip6_route_input()
2468 skb_dst_set_noref(skb, ip6_route_input_lookup(net, skb->dev, in ip6_route_input()
2478 return ip6_pol_route(net, table, fl6->flowi6_oif, fl6, skb, flags); in ip6_pol_route_output()
2487 if (ipv6_addr_type(&fl6->daddr) & in ip6_route_output_flags_noref()
2497 fl6->flowi6_iif = LOOPBACK_IFINDEX; in ip6_route_output_flags_noref()
2500 any_src = ipv6_addr_any(&fl6->saddr); in ip6_route_output_flags_noref()
2501 if ((sk && sk->sk_bound_dev_if) || rt6_need_strict(&fl6->daddr) || in ip6_route_output_flags_noref()
2502 (fl6->flowi6_oif && any_src)) in ip6_route_output_flags_noref()
2508 flags |= rt6_srcprefs2flags(inet6_sk(sk)->srcprefs); in ip6_route_output_flags_noref()
2526 if (list_empty(&rt6->rt6i_uncached) && !dst_hold_safe(dst)) { in ip6_route_output_flags()
2527 dst = &net->ipv6.ip6_null_entry->dst; in ip6_route_output_flags()
2539 struct net_device *loopback_dev = net->loopback_dev; in ip6_blackhole_route()
2546 atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc); in ip6_blackhole_route()
2548 new = &rt->dst; in ip6_blackhole_route()
2549 new->__use = 1; in ip6_blackhole_route()
2550 new->input = dst_discard; in ip6_blackhole_route()
2551 new->output = dst_discard_out; in ip6_blackhole_route()
2553 dst_copy_metrics(new, &ort->dst); in ip6_blackhole_route()
2555 rt->rt6i_idev = in6_dev_get(loopback_dev); in ip6_blackhole_route()
2556 rt->rt6i_gateway = ort->rt6i_gateway; in ip6_blackhole_route()
2557 rt->rt6i_flags = ort->rt6i_flags & ~RTF_PCPU; in ip6_blackhole_route()
2559 memcpy(&rt->rt6i_dst, &ort->rt6i_dst, sizeof(struct rt6key)); in ip6_blackhole_route()
2561 memcpy(&rt->rt6i_src, &ort->rt6i_src, sizeof(struct rt6key)); in ip6_blackhole_route()
2566 return new ? new : ERR_PTR(-ENOMEM); in ip6_blackhole_route()
2599 return &rt->dst; in rt6_check()
2607 rt->dst.obsolete == DST_OBSOLETE_FORCE_CHK && in rt6_dst_from_check()
2609 return &rt->dst; in rt6_dst_from_check()
2622 if (rt->sernum) in ip6_dst_check()
2627 /* All IPV6 dsts are created with ->obsolete set to the value in ip6_dst_check()
2632 from = rcu_dereference(rt->from); in ip6_dst_check()
2634 if (from && (rt->rt6i_flags & RTF_PCPU || in ip6_dst_check()
2635 unlikely(!list_empty(&rt->rt6i_uncached)))) in ip6_dst_check()
2650 if (rt->rt6i_flags & RTF_CACHE) { in ip6_negative_advice()
2674 if (rt->rt6i_flags & RTF_CACHE) { in ip6_link_failure()
2680 from = rcu_dereference(rt->from); in ip6_link_failure()
2682 fn = rcu_dereference(from->fib6_node); in ip6_link_failure()
2683 if (fn && (rt->rt6i_flags & RTF_DEFAULT)) in ip6_link_failure()
2684 fn->fn_sernum = -1; in ip6_link_failure()
2693 if (!(rt0->rt6i_flags & RTF_EXPIRES)) { in rt6_update_expires()
2697 from = rcu_dereference(rt0->from); in rt6_update_expires()
2699 rt0->dst.expires = from->expires; in rt6_update_expires()
2703 dst_set_expires(&rt0->dst, timeout); in rt6_update_expires()
2704 rt0->rt6i_flags |= RTF_EXPIRES; in rt6_update_expires()
2709 struct net *net = dev_net(rt->dst.dev); in rt6_do_update_pmtu()
2711 dst_metric_set(&rt->dst, RTAX_MTU, mtu); in rt6_do_update_pmtu()
2712 rt->rt6i_flags |= RTF_MODIFIED; in rt6_do_update_pmtu()
2713 rt6_update_expires(rt, net->ipv6.sysctl.ip6_rt_mtu_expires); in rt6_do_update_pmtu()
2718 return !(rt->rt6i_flags & RTF_CACHE) && in rt6_cache_allowed_for_pmtu()
2719 (rt->rt6i_flags & RTF_PCPU || rcu_access_pointer(rt->from)); in rt6_cache_allowed_for_pmtu()
2735 daddr = &iph->daddr; in __ip6_rt_update_pmtu()
2736 saddr = &iph->saddr; in __ip6_rt_update_pmtu()
2738 daddr = &sk->sk_v6_daddr; in __ip6_rt_update_pmtu()
2739 saddr = &inet6_sk(sk)->saddr; in __ip6_rt_update_pmtu()
2755 /* update rt6_ex->stamp for cache */ in __ip6_rt_update_pmtu()
2756 if (rt6->rt6i_flags & RTF_CACHE) in __ip6_rt_update_pmtu()
2763 res.f6i = rcu_dereference(rt6->from); in __ip6_rt_update_pmtu()
2767 res.fib6_flags = res.f6i->fib6_flags; in __ip6_rt_update_pmtu()
2768 res.fib6_type = res.f6i->fib6_type; in __ip6_rt_update_pmtu()
2770 if (res.f6i->nh) { in __ip6_rt_update_pmtu()
2772 .dev = dst->dev, in __ip6_rt_update_pmtu()
2773 .gw = &rt6->rt6i_gateway, in __ip6_rt_update_pmtu()
2776 nexthop_for_each_fib6_nh(res.f6i->nh, in __ip6_rt_update_pmtu()
2780 * using the dst->dev + gw. Should be impossible. in __ip6_rt_update_pmtu()
2787 res.nh = res.f6i->fib6_nh; in __ip6_rt_update_pmtu()
2794 dst_release_immediate(&nrt6->dst); in __ip6_rt_update_pmtu()
2812 const struct ipv6hdr *iph = (struct ipv6hdr *) skb->data; in ip6_update_pmtu()
2816 .flowi6_mark = mark ? mark : IP6_REPLY_MARK(net, skb->mark), in ip6_update_pmtu()
2817 .daddr = iph->daddr, in ip6_update_pmtu()
2818 .saddr = iph->saddr, in ip6_update_pmtu()
2824 if (!dst->error) in ip6_update_pmtu()
2832 int oif = sk->sk_bound_dev_if; in ip6_sk_update_pmtu()
2835 if (!oif && skb->dev) in ip6_sk_update_pmtu()
2836 oif = l3mdev_master_ifindex(skb->dev); in ip6_sk_update_pmtu()
2838 ip6_update_pmtu(skb, sock_net(sk), mtu, oif, sk->sk_mark, sk->sk_uid); in ip6_sk_update_pmtu()
2841 if (!dst || !dst->obsolete || in ip6_sk_update_pmtu()
2842 dst->ops->check(dst, inet6_sk(sk)->dst_cookie)) in ip6_sk_update_pmtu()
2846 if (!sock_owned_by_user(sk) && !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) in ip6_sk_update_pmtu()
2860 ipv6_addr_equal(&fl6->daddr, &sk->sk_v6_daddr) ? in ip6_sk_dst_store_flow()
2861 &sk->sk_v6_daddr : NULL, in ip6_sk_dst_store_flow()
2863 ipv6_addr_equal(&fl6->saddr, &np->saddr) ? in ip6_sk_dst_store_flow()
2864 &np->saddr : in ip6_sk_dst_store_flow()
2874 const struct fib6_nh *nh = res->nh; in ip6_redirect_nh_match()
2876 if (nh->fib_nh_flags & RTNH_F_DEAD || !nh->fib_nh_gw_family || in ip6_redirect_nh_match()
2877 fl6->flowi6_oif != nh->fib_nh_dev->ifindex) in ip6_redirect_nh_match()
2885 if (!ipv6_addr_equal(gw, &nh->fib_nh_gw6)) { in ip6_redirect_nh_match()
2888 rt_cache = rt6_find_cached_rt(res, &fl6->daddr, &fl6->saddr); in ip6_redirect_nh_match()
2890 ipv6_addr_equal(gw, &rt_cache->rt6i_gateway)) { in ip6_redirect_nh_match()
2910 arg->res->nh = nh; in fib6_nh_redirect_match()
2911 return ip6_redirect_nh_match(arg->res, arg->fl6, arg->gw, arg->ret); in fib6_nh_redirect_match()
2932 .gw = &rdfl->gateway, in __ip6_route_redirect()
2941 if (fl6->flowi6_flags & FLOWI_FLAG_SKIP_NH_OIF) in __ip6_route_redirect()
2942 fl6->flowi6_oif = skb->dev->ifindex; in __ip6_route_redirect()
2944 /* Get the "current" route for this destination and in __ip6_route_redirect()
2955 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in __ip6_route_redirect()
2961 if (rt->fib6_flags & RTF_REJECT) in __ip6_route_redirect()
2963 if (unlikely(rt->nh)) { in __ip6_route_redirect()
2964 if (nexthop_is_blackhole(rt->nh)) in __ip6_route_redirect()
2966 /* on match, res->nh is filled in and potentially ret */ in __ip6_route_redirect()
2967 if (nexthop_for_each_fib6_nh(rt->nh, in __ip6_route_redirect()
2972 res.nh = rt->fib6_nh; in __ip6_route_redirect()
2973 if (ip6_redirect_nh_match(&res, fl6, &rdfl->gateway, in __ip6_route_redirect()
2980 rt = net->ipv6.fib6_null_entry; in __ip6_route_redirect()
2981 else if (rt->fib6_flags & RTF_REJECT) { in __ip6_route_redirect()
2982 ret = net->ipv6.ip6_null_entry; in __ip6_route_redirect()
2986 if (rt == net->ipv6.fib6_null_entry) { in __ip6_route_redirect()
2987 fn = fib6_backtrack(fn, &fl6->saddr); in __ip6_route_redirect()
2993 res.nh = rt->fib6_nh; in __ip6_route_redirect()
2998 res.fib6_flags = res.f6i->fib6_flags; in __ip6_route_redirect()
2999 res.fib6_type = res.f6i->fib6_type; in __ip6_route_redirect()
3027 const struct ipv6hdr *iph = (struct ipv6hdr *) skb->data; in ip6_redirect()
3033 .daddr = iph->daddr, in ip6_redirect()
3034 .saddr = iph->saddr, in ip6_redirect()
3039 dst = ip6_route_redirect(net, &fl6, skb, &ipv6_hdr(skb)->saddr); in ip6_redirect()
3053 .daddr = msg->dest, in ip6_redirect_no_header()
3054 .saddr = iph->daddr, in ip6_redirect_no_header()
3058 dst = ip6_route_redirect(net, &fl6, skb, &iph->saddr); in ip6_redirect_no_header()
3065 ip6_redirect(skb, sock_net(sk), sk->sk_bound_dev_if, sk->sk_mark, in ip6_sk_redirect()
3066 sk->sk_uid); in ip6_sk_redirect()
3072 struct net_device *dev = dst->dev; in ip6_default_advmss()
3076 mtu -= sizeof(struct ipv6hdr) + sizeof(struct tcphdr); in ip6_default_advmss()
3078 if (mtu < net->ipv6.sysctl.ip6_rt_min_advmss) in ip6_default_advmss()
3079 mtu = net->ipv6.sysctl.ip6_rt_min_advmss; in ip6_default_advmss()
3082 * Maximal non-jumbo IPv6 payload is IPV6_MAXPLEN and in ip6_default_advmss()
3083 * corresponding MSS is IPV6_MAXPLEN - tcp_header_size. in ip6_default_advmss()
3087 if (mtu > IPV6_MAXPLEN - sizeof(struct tcphdr)) in ip6_default_advmss()
3104 idev = __in6_dev_get(dst->dev); in ip6_mtu()
3106 mtu = idev->cnf.mtu6; in ip6_mtu()
3112 return mtu - lwtunnel_headroom(dst->lwtstate, mtu); in ip6_mtu()
3116 * 1. mtu on route is locked - use it
3127 const struct fib6_nh *nh = res->nh; in ip6_mtu_from_fib6()
3128 struct fib6_info *f6i = res->f6i; in ip6_mtu_from_fib6()
3134 mtu = f6i->fib6_pmtu; in ip6_mtu_from_fib6()
3141 mtu = dst_metric_raw(&rt->dst, RTAX_MTU); in ip6_mtu_from_fib6()
3143 struct net_device *dev = nh->fib_nh_dev; in ip6_mtu_from_fib6()
3147 if (idev && idev->cnf.mtu6 > mtu) in ip6_mtu_from_fib6()
3148 mtu = idev->cnf.mtu6; in ip6_mtu_from_fib6()
3153 return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu); in ip6_mtu_from_fib6()
3165 return ERR_PTR(-ENODEV); in icmp6_dst_alloc()
3170 dst = ERR_PTR(-ENOMEM); in icmp6_dst_alloc()
3174 rt->dst.input = ip6_input; in icmp6_dst_alloc()
3175 rt->dst.output = ip6_output; in icmp6_dst_alloc()
3176 rt->rt6i_gateway = fl6->daddr; in icmp6_dst_alloc()
3177 rt->rt6i_dst.addr = fl6->daddr; in icmp6_dst_alloc()
3178 rt->rt6i_dst.plen = 128; in icmp6_dst_alloc()
3179 rt->rt6i_idev = idev; in icmp6_dst_alloc()
3180 dst_metric_set(&rt->dst, RTAX_HOPLIMIT, 0); in icmp6_dst_alloc()
3186 atomic_inc(&net->ipv6.rt6_stats->fib_rt_uncache); in icmp6_dst_alloc()
3188 dst = xfrm_lookup(net, &rt->dst, flowi6_to_flowi(fl6), NULL, 0); in icmp6_dst_alloc()
3197 int rt_min_interval = net->ipv6.sysctl.ip6_rt_gc_min_interval; in ip6_dst_gc()
3198 int rt_max_size = net->ipv6.sysctl.ip6_rt_max_size; in ip6_dst_gc()
3199 int rt_elasticity = net->ipv6.sysctl.ip6_rt_gc_elasticity; in ip6_dst_gc()
3200 int rt_gc_timeout = net->ipv6.sysctl.ip6_rt_gc_timeout; in ip6_dst_gc()
3201 unsigned long rt_last_gc = net->ipv6.ip6_rt_last_gc; in ip6_dst_gc()
3212 net->ipv6.ip6_rt_gc_expire++; in ip6_dst_gc()
3213 fib6_run_gc(net->ipv6.ip6_rt_gc_expire, net, true); in ip6_dst_gc()
3215 if (entries < ops->gc_thresh) in ip6_dst_gc()
3216 net->ipv6.ip6_rt_gc_expire = rt_gc_timeout>>1; in ip6_dst_gc()
3218 net->ipv6.ip6_rt_gc_expire -= net->ipv6.ip6_rt_gc_expire>>rt_elasticity; in ip6_dst_gc()
3227 .flowi6_oif = cfg->fc_ifindex, in ip6_nh_lookup_table()
3229 .saddr = cfg->fc_prefsrc, in ip6_nh_lookup_table()
3236 return -EINVAL; in ip6_nh_lookup_table()
3238 if (!ipv6_addr_any(&cfg->fc_prefsrc)) in ip6_nh_lookup_table()
3243 err = fib6_table_lookup(net, table, cfg->fc_ifindex, &fl6, res, flags); in ip6_nh_lookup_table()
3244 if (!err && res->f6i != net->ipv6.fib6_null_entry) in ip6_nh_lookup_table()
3245 fib6_select_path(net, res, &fl6, cfg->fc_ifindex, in ip6_nh_lookup_table()
3246 cfg->fc_ifindex != 0, NULL, flags); in ip6_nh_lookup_table()
3257 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_route_check_nh_onlink()
3263 /* ignore match if it is the default route */ in ip6_route_check_nh_onlink()
3264 !ipv6_addr_any(&res.f6i->fib6_dst.addr) && in ip6_route_check_nh_onlink()
3265 (res.fib6_type != RTN_UNICAST || dev != res.nh->fib_nh_dev)) { in ip6_route_check_nh_onlink()
3268 err = -EINVAL; in ip6_route_check_nh_onlink()
3279 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_route_check_nh()
3283 int err = -EHOSTUNREACH; in ip6_route_check_nh()
3285 if (cfg->fc_table) { in ip6_route_check_nh()
3287 cfg->fc_table, flags, &res); in ip6_route_check_nh()
3289 * route. If a device is given, it must match the result. in ip6_route_check_nh()
3292 res.nh->fib_nh_gw_family || in ip6_route_check_nh()
3293 (dev && dev != res.nh->fib_nh_dev)) in ip6_route_check_nh()
3294 err = -EHOSTUNREACH; in ip6_route_check_nh()
3299 .flowi6_oif = cfg->fc_ifindex, in ip6_route_check_nh()
3303 err = fib6_lookup(net, cfg->fc_ifindex, &fl6, &res, flags); in ip6_route_check_nh()
3305 res.nh->fib_nh_gw_family) in ip6_route_check_nh()
3306 err = -EHOSTUNREACH; in ip6_route_check_nh()
3311 fib6_select_path(net, &res, &fl6, cfg->fc_ifindex, in ip6_route_check_nh()
3312 cfg->fc_ifindex != 0, NULL, flags); in ip6_route_check_nh()
3317 if (dev != res.nh->fib_nh_dev) in ip6_route_check_nh()
3318 err = -EHOSTUNREACH; in ip6_route_check_nh()
3320 *_dev = dev = res.nh->fib_nh_dev; in ip6_route_check_nh()
3332 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_validate_gw()
3337 int err = -EINVAL; in ip6_validate_gw()
3341 * will return already-added prefix route via interface that in ip6_validate_gw()
3342 * prefix route was assigned to, which might be non-loopback. in ip6_validate_gw()
3351 /* IPv6 strictly inhibits using not link-local in ip6_validate_gw()
3355 * (SIT, PtP, NBMA NOARP links) it is handy to allow in ip6_validate_gw()
3356 * some exceptions. --ANK in ip6_validate_gw()
3357 * We allow IPv4-mapped nexthops to support RFC4798-type in ip6_validate_gw()
3367 if (cfg->fc_flags & RTNH_F_ONLINK) in ip6_validate_gw()
3381 err = -EINVAL; in ip6_validate_gw()
3385 } else if (dev->flags & IFF_LOOPBACK) { in ip6_validate_gw()
3387 "Egress device can not be loopback device for this route"); in ip6_validate_gw()
3408 (dev && (dev->flags & IFF_LOOPBACK) && in fib6_is_reject()
3425 fib6_nh->fib_nh_family = AF_INET6; in fib6_nh_init()
3427 fib6_nh->last_probe = jiffies; in fib6_nh_init()
3429 if (cfg->fc_is_fdb) { in fib6_nh_init()
3430 fib6_nh->fib_nh_gw6 = cfg->fc_gateway; in fib6_nh_init()
3431 fib6_nh->fib_nh_gw_family = AF_INET6; in fib6_nh_init()
3435 err = -ENODEV; in fib6_nh_init()
3436 if (cfg->fc_ifindex) { in fib6_nh_init()
3437 dev = dev_get_by_index(net, cfg->fc_ifindex); in fib6_nh_init()
3445 if (cfg->fc_flags & RTNH_F_ONLINK) { in fib6_nh_init()
3452 if (!(dev->flags & IFF_UP)) { in fib6_nh_init()
3454 err = -ENETDOWN; in fib6_nh_init()
3458 fib6_nh->fib_nh_flags |= RTNH_F_ONLINK; in fib6_nh_init()
3461 fib6_nh->fib_nh_weight = 1; in fib6_nh_init()
3466 addr_type = ipv6_addr_type(&cfg->fc_dst); in fib6_nh_init()
3467 if (fib6_is_reject(cfg->fc_flags, dev, addr_type)) { in fib6_nh_init()
3469 if (dev != net->loopback_dev) { in fib6_nh_init()
3474 dev = net->loopback_dev; in fib6_nh_init()
3478 err = -ENODEV; in fib6_nh_init()
3485 if (cfg->fc_flags & RTF_GATEWAY) { in fib6_nh_init()
3490 fib6_nh->fib_nh_gw6 = cfg->fc_gateway; in fib6_nh_init()
3491 fib6_nh->fib_nh_gw_family = AF_INET6; in fib6_nh_init()
3494 err = -ENODEV; in fib6_nh_init()
3498 if (idev->cnf.disable_ipv6) { in fib6_nh_init()
3500 err = -EACCES; in fib6_nh_init()
3504 if (!(dev->flags & IFF_UP) && !cfg->fc_ignore_dev_down) { in fib6_nh_init()
3506 err = -ENETDOWN; in fib6_nh_init()
3510 if (!(cfg->fc_flags & (RTF_LOCAL | RTF_ANYCAST)) && in fib6_nh_init()
3512 fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib6_nh_init()
3514 err = fib_nh_common_init(net, &fib6_nh->nh_common, cfg->fc_encap, in fib6_nh_init()
3515 cfg->fc_encap_type, cfg, gfp_flags, extack); in fib6_nh_init()
3520 fib6_nh->rt6i_pcpu = alloc_percpu_gfp(struct rt6_info *, gfp_flags); in fib6_nh_init()
3521 if (!fib6_nh->rt6i_pcpu) { in fib6_nh_init()
3522 err = -ENOMEM; in fib6_nh_init()
3526 fib6_nh->fib_nh_dev = dev; in fib6_nh_init()
3527 fib6_nh->fib_nh_oif = dev->ifindex; in fib6_nh_init()
3534 lwtstate_put(fib6_nh->fib_nh_lws); in fib6_nh_init()
3535 fib6_nh->fib_nh_lws = NULL; in fib6_nh_init()
3552 rcu_assign_pointer(fib6_nh->rt6i_exception_bucket, NULL); in fib6_nh_release()
3558 if (fib6_nh->rt6i_pcpu) { in fib6_nh_release()
3565 ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu); in fib6_nh_release()
3568 dst_dev_put(&pcpu_rt->dst); in fib6_nh_release()
3569 dst_release(&pcpu_rt->dst); in fib6_nh_release()
3574 free_percpu(fib6_nh->rt6i_pcpu); in fib6_nh_release()
3577 fib_nh_common_release(&fib6_nh->nh_common); in fib6_nh_release()
3584 struct net *net = cfg->fc_nlinfo.nl_net; in ip6_route_info_create()
3589 int err = -EINVAL; in ip6_route_info_create()
3593 if (cfg->fc_flags & RTF_PCPU) { in ip6_route_info_create()
3599 if (cfg->fc_flags & RTF_CACHE) { in ip6_route_info_create()
3604 if (cfg->fc_type > RTN_MAX) { in ip6_route_info_create()
3605 NL_SET_ERR_MSG(extack, "Invalid route type"); in ip6_route_info_create()
3609 if (cfg->fc_dst_len > 128) { in ip6_route_info_create()
3613 if (cfg->fc_src_len > 128) { in ip6_route_info_create()
3618 if (cfg->fc_src_len) { in ip6_route_info_create()
3624 if (cfg->fc_nh_id) { in ip6_route_info_create()
3625 nh = nexthop_find_by_id(net, cfg->fc_nh_id); in ip6_route_info_create()
3635 err = -ENOBUFS; in ip6_route_info_create()
3636 if (cfg->fc_nlinfo.nlh && in ip6_route_info_create()
3637 !(cfg->fc_nlinfo.nlh->nlmsg_flags & NLM_F_CREATE)) { in ip6_route_info_create()
3638 table = fib6_get_table(net, cfg->fc_table); in ip6_route_info_create()
3640 pr_warn("NLM_F_CREATE should be specified when creating new route\n"); in ip6_route_info_create()
3641 table = fib6_new_table(net, cfg->fc_table); in ip6_route_info_create()
3644 table = fib6_new_table(net, cfg->fc_table); in ip6_route_info_create()
3650 err = -ENOMEM; in ip6_route_info_create()
3655 rt->fib6_metrics = ip_fib_metrics_init(net, cfg->fc_mx, cfg->fc_mx_len, in ip6_route_info_create()
3657 if (IS_ERR(rt->fib6_metrics)) { in ip6_route_info_create()
3658 err = PTR_ERR(rt->fib6_metrics); in ip6_route_info_create()
3660 rt->fib6_metrics = (struct dst_metrics *)&dst_default_metrics; in ip6_route_info_create()
3664 if (cfg->fc_flags & RTF_ADDRCONF) in ip6_route_info_create()
3665 rt->dst_nocount = true; in ip6_route_info_create()
3667 if (cfg->fc_flags & RTF_EXPIRES) in ip6_route_info_create()
3669 clock_t_to_jiffies(cfg->fc_expires)); in ip6_route_info_create()
3673 if (cfg->fc_protocol == RTPROT_UNSPEC) in ip6_route_info_create()
3674 cfg->fc_protocol = RTPROT_BOOT; in ip6_route_info_create()
3675 rt->fib6_protocol = cfg->fc_protocol; in ip6_route_info_create()
3677 rt->fib6_table = table; in ip6_route_info_create()
3678 rt->fib6_metric = cfg->fc_metric; in ip6_route_info_create()
3679 rt->fib6_type = cfg->fc_type ? : RTN_UNICAST; in ip6_route_info_create()
3680 rt->fib6_flags = cfg->fc_flags & ~RTF_GATEWAY; in ip6_route_info_create()
3682 ipv6_addr_prefix(&rt->fib6_dst.addr, &cfg->fc_dst, cfg->fc_dst_len); in ip6_route_info_create()
3683 rt->fib6_dst.plen = cfg->fc_dst_len; in ip6_route_info_create()
3686 ipv6_addr_prefix(&rt->fib6_src.addr, &cfg->fc_src, cfg->fc_src_len); in ip6_route_info_create()
3687 rt->fib6_src.plen = cfg->fc_src_len; in ip6_route_info_create()
3690 if (rt->fib6_src.plen) { in ip6_route_info_create()
3698 rt->nh = nh; in ip6_route_info_create()
3699 fib6_nh = nexthop_fib6_nh(rt->nh); in ip6_route_info_create()
3701 err = fib6_nh_init(net, rt->fib6_nh, cfg, gfp_flags, extack); in ip6_route_info_create()
3705 fib6_nh = rt->fib6_nh; in ip6_route_info_create()
3710 addr_type = ipv6_addr_type(&cfg->fc_dst); in ip6_route_info_create()
3711 if (fib6_is_reject(cfg->fc_flags, rt->fib6_nh->fib_nh_dev, in ip6_route_info_create()
3713 rt->fib6_flags = RTF_REJECT | RTF_NONEXTHOP; in ip6_route_info_create()
3716 if (!ipv6_addr_any(&cfg->fc_prefsrc)) { in ip6_route_info_create()
3717 struct net_device *dev = fib6_nh->fib_nh_dev; in ip6_route_info_create()
3719 if (!ipv6_chk_addr(net, &cfg->fc_prefsrc, dev, 0)) { in ip6_route_info_create()
3721 err = -EINVAL; in ip6_route_info_create()
3724 rt->fib6_prefsrc.addr = cfg->fc_prefsrc; in ip6_route_info_create()
3725 rt->fib6_prefsrc.plen = 128; in ip6_route_info_create()
3727 rt->fib6_prefsrc.plen = 0; in ip6_route_info_create()
3745 err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, extack); in ip6_route_add()
3753 struct net *net = info->nl_net; in __ip6_del_rt()
3757 if (rt == net->ipv6.fib6_null_entry) { in __ip6_del_rt()
3758 err = -ENOENT; in __ip6_del_rt()
3762 table = rt->fib6_table; in __ip6_del_rt()
3763 spin_lock_bh(&table->tb6_lock); in __ip6_del_rt()
3765 spin_unlock_bh(&table->tb6_lock); in __ip6_del_rt()
3784 struct nl_info *info = &cfg->fc_nlinfo; in __ip6_del_rt_siblings()
3785 struct net *net = info->nl_net; in __ip6_del_rt_siblings()
3788 int err = -ENOENT; in __ip6_del_rt_siblings()
3790 if (rt == net->ipv6.fib6_null_entry) in __ip6_del_rt_siblings()
3792 table = rt->fib6_table; in __ip6_del_rt_siblings()
3793 spin_lock_bh(&table->tb6_lock); in __ip6_del_rt_siblings()
3795 if (rt->fib6_nsiblings && cfg->fc_delete_all_nh) { in __ip6_del_rt_siblings()
3802 u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in __ip6_del_rt_siblings()
3806 info->portid, seq, 0) < 0) { in __ip6_del_rt_siblings()
3810 info->skip_notify = 1; in __ip6_del_rt_siblings()
3813 /* 'rt' points to the first sibling route. If it is not the in __ip6_del_rt_siblings()
3815 * we need to check if the last sibling has a next route or not in __ip6_del_rt_siblings()
3818 info->skip_notify_kernel = 1; in __ip6_del_rt_siblings()
3819 fn = rcu_dereference_protected(rt->fib6_node, in __ip6_del_rt_siblings()
3820 lockdep_is_held(&table->tb6_lock)); in __ip6_del_rt_siblings()
3821 if (rcu_access_pointer(fn->leaf) == rt) { in __ip6_del_rt_siblings()
3824 last_sibling = list_last_entry(&rt->fib6_siblings, in __ip6_del_rt_siblings()
3828 last_sibling->fib6_next, in __ip6_del_rt_siblings()
3829 lockdep_is_held(&table->tb6_lock)); in __ip6_del_rt_siblings()
3836 rt, rt->fib6_nsiblings, in __ip6_del_rt_siblings()
3840 &rt->fib6_siblings, in __ip6_del_rt_siblings()
3850 spin_unlock_bh(&table->tb6_lock); in __ip6_del_rt_siblings()
3855 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in __ip6_del_rt_siblings()
3856 info->nlh, gfp_any()); in __ip6_del_rt_siblings()
3863 int rc = -ESRCH; in __ip6_del_cached_rt()
3865 if (cfg->fc_ifindex && rt->dst.dev->ifindex != cfg->fc_ifindex) in __ip6_del_cached_rt()
3868 if (cfg->fc_flags & RTF_GATEWAY && in __ip6_del_cached_rt()
3869 !ipv6_addr_equal(&cfg->fc_gateway, &rt->rt6i_gateway)) in __ip6_del_cached_rt()
3886 rt_cache = rt6_find_cached_rt(&res, &cfg->fc_dst, &cfg->fc_src); in ip6_del_cached_rt()
3903 rc = ip6_del_cached_rt(arg->cfg, arg->f6i, nh); in fib6_nh_del_cached_rt()
3904 return rc != -ESRCH ? rc : 0; in fib6_nh_del_cached_rt()
3914 return nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_del_cached_rt, &arg); in ip6_del_cached_rt_nh()
3923 int err = -ESRCH; in ip6_route_del()
3925 table = fib6_get_table(cfg->fc_nlinfo.nl_net, cfg->fc_table); in ip6_route_del()
3933 fn = fib6_locate(&table->tb6_root, in ip6_route_del()
3934 &cfg->fc_dst, cfg->fc_dst_len, in ip6_route_del()
3935 &cfg->fc_src, cfg->fc_src_len, in ip6_route_del()
3936 !(cfg->fc_flags & RTF_CACHE)); in ip6_route_del()
3942 if (rt->nh && cfg->fc_nh_id && in ip6_route_del()
3943 rt->nh->id != cfg->fc_nh_id) in ip6_route_del()
3946 if (cfg->fc_flags & RTF_CACHE) { in ip6_route_del()
3949 if (rt->nh) { in ip6_route_del()
3951 } else if (cfg->fc_nh_id) { in ip6_route_del()
3954 nh = rt->fib6_nh; in ip6_route_del()
3957 if (rc != -ESRCH) { in ip6_route_del()
3964 if (cfg->fc_metric && cfg->fc_metric != rt->fib6_metric) in ip6_route_del()
3966 if (cfg->fc_protocol && in ip6_route_del()
3967 cfg->fc_protocol != rt->fib6_protocol) in ip6_route_del()
3970 if (rt->nh) { in ip6_route_del()
3975 return __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
3977 if (cfg->fc_nh_id) in ip6_route_del()
3980 nh = rt->fib6_nh; in ip6_route_del()
3981 if (cfg->fc_ifindex && in ip6_route_del()
3982 (!nh->fib_nh_dev || in ip6_route_del()
3983 nh->fib_nh_dev->ifindex != cfg->fc_ifindex)) in ip6_route_del()
3985 if (cfg->fc_flags & RTF_GATEWAY && in ip6_route_del()
3986 !ipv6_addr_equal(&cfg->fc_gateway, &nh->fib_nh_gw6)) in ip6_route_del()
3993 if (cfg->fc_flags & RTF_GATEWAY) in ip6_route_del()
3994 return __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
4016 optlen = skb_tail_pointer(skb) - skb_transport_header(skb); in rt6_do_redirect()
4017 optlen -= sizeof(*msg); in rt6_do_redirect()
4026 if (ipv6_addr_is_multicast(&msg->dest)) { in rt6_do_redirect()
4032 if (ipv6_addr_equal(&msg->dest, &msg->target)) { in rt6_do_redirect()
4034 } else if (ipv6_addr_type(&msg->target) != in rt6_do_redirect()
4036 net_dbg_ratelimited("rt6_do_redirect: target address is not link-local unicast\n"); in rt6_do_redirect()
4040 in6_dev = __in6_dev_get(skb->dev); in rt6_do_redirect()
4043 if (in6_dev->cnf.forwarding || !in6_dev->cnf.accept_redirects) in rt6_do_redirect()
4048 * first-hop router for the specified ICMP Destination Address. in rt6_do_redirect()
4051 if (!ndisc_parse_options(skb->dev, msg->opt, optlen, &ndopts)) { in rt6_do_redirect()
4059 skb->dev); in rt6_do_redirect()
4061 net_dbg_ratelimited("rt6_redirect: invalid link-layer address length\n"); in rt6_do_redirect()
4067 if (rt->rt6i_flags & RTF_REJECT) { in rt6_do_redirect()
4072 /* Redirect received -> path was valid. in rt6_do_redirect()
4074 * so that this nexthop apparently is reachable. --ANK in rt6_do_redirect()
4076 dst_confirm_neigh(&rt->dst, &ipv6_hdr(skb)->saddr); in rt6_do_redirect()
4078 neigh = __neigh_lookup(&nd_tbl, &msg->target, skb->dev, 1); in rt6_do_redirect()
4086 ndisc_update(skb->dev, neigh, lladdr, NUD_STALE, in rt6_do_redirect()
4094 res.f6i = rcu_dereference(rt->from); in rt6_do_redirect()
4098 if (res.f6i->nh) { in rt6_do_redirect()
4100 .dev = dst->dev, in rt6_do_redirect()
4101 .gw = &rt->rt6i_gateway, in rt6_do_redirect()
4104 nexthop_for_each_fib6_nh(res.f6i->nh, in rt6_do_redirect()
4108 * using the dst->dev. Should be impossible in rt6_do_redirect()
4114 res.nh = res.f6i->fib6_nh; in rt6_do_redirect()
4117 res.fib6_flags = res.f6i->fib6_flags; in rt6_do_redirect()
4118 res.fib6_type = res.f6i->fib6_type; in rt6_do_redirect()
4119 nrt = ip6_rt_cache_alloc(&res, &msg->dest, NULL); in rt6_do_redirect()
4123 nrt->rt6i_flags = RTF_GATEWAY|RTF_UP|RTF_DYNAMIC|RTF_CACHE; in rt6_do_redirect()
4125 nrt->rt6i_flags &= ~RTF_GATEWAY; in rt6_do_redirect()
4127 nrt->rt6i_gateway = *(struct in6_addr *)neigh->primary_key; in rt6_do_redirect()
4131 dst_release_immediate(&nrt->dst); in rt6_do_redirect()
4135 netevent.old = &rt->dst; in rt6_do_redirect()
4136 netevent.new = &nrt->dst; in rt6_do_redirect()
4137 netevent.daddr = &msg->dest; in rt6_do_redirect()
4153 int ifindex = dev->ifindex; in rt6_get_route_info()
4163 fn = fib6_locate(&table->tb6_root, prefix, prefixlen, NULL, 0, true); in rt6_get_route_info()
4169 if (rt->nh) in rt6_get_route_info()
4171 if (rt->fib6_nh->fib_nh_dev->ifindex != ifindex) in rt6_get_route_info()
4173 if (!(rt->fib6_flags & RTF_ROUTEINFO) || in rt6_get_route_info()
4174 !rt->fib6_nh->fib_nh_gw_family) in rt6_get_route_info()
4176 if (!ipv6_addr_equal(&rt->fib6_nh->fib_nh_gw6, gwaddr)) in rt6_get_route_info()
4195 .fc_ifindex = dev->ifindex, in rt6_add_route_info()
4210 /* We should treat it as a default route if prefix length is 0. */ in rt6_add_route_info()
4233 for_each_fib6_node_rt_rcu(&table->tb6_root) { in rt6_get_dflt_router()
4237 if (rt->nh) in rt6_get_dflt_router()
4240 nh = rt->fib6_nh; in rt6_get_dflt_router()
4241 if (dev == nh->fib_nh_dev && in rt6_get_dflt_router()
4242 ((rt->fib6_flags & (RTF_ADDRCONF | RTF_DEFAULT)) == (RTF_ADDRCONF | RTF_DEFAULT)) && in rt6_get_dflt_router()
4243 ipv6_addr_equal(&nh->fib_nh_gw6, addr)) in rt6_get_dflt_router()
4260 .fc_ifindex = dev->ifindex, in rt6_add_dflt_router()
4277 table->flags |= RT6_TABLE_HAS_DFLT_ROUTER; in rt6_add_dflt_router()
4290 for_each_fib6_node_rt_rcu(&table->tb6_root) { in __rt6_purge_dflt_routers()
4294 if (rt->fib6_flags & (RTF_DEFAULT | RTF_ADDRCONF) && in __rt6_purge_dflt_routers()
4295 (!idev || idev->cnf.accept_ra != 2) && in __rt6_purge_dflt_routers()
4304 table->flags &= ~RT6_TABLE_HAS_DFLT_ROUTER; in __rt6_purge_dflt_routers()
4316 head = &net->ipv6.fib_table_hash[h]; in rt6_purge_dflt_routers()
4318 if (table->flags & RT6_TABLE_HAS_DFLT_ROUTER) in rt6_purge_dflt_routers()
4331 .fc_table = l3mdev_fib_table_by_index(net, rtmsg->rtmsg_ifindex) ? in rtmsg_to_fib6_config()
4333 .fc_ifindex = rtmsg->rtmsg_ifindex, in rtmsg_to_fib6_config()
4334 .fc_metric = rtmsg->rtmsg_metric ? : IP6_RT_PRIO_USER, in rtmsg_to_fib6_config()
4335 .fc_expires = rtmsg->rtmsg_info, in rtmsg_to_fib6_config()
4336 .fc_dst_len = rtmsg->rtmsg_dst_len, in rtmsg_to_fib6_config()
4337 .fc_src_len = rtmsg->rtmsg_src_len, in rtmsg_to_fib6_config()
4338 .fc_flags = rtmsg->rtmsg_flags, in rtmsg_to_fib6_config()
4339 .fc_type = rtmsg->rtmsg_type, in rtmsg_to_fib6_config()
4343 .fc_dst = rtmsg->rtmsg_dst, in rtmsg_to_fib6_config()
4344 .fc_src = rtmsg->rtmsg_src, in rtmsg_to_fib6_config()
4345 .fc_gateway = rtmsg->rtmsg_gateway, in rtmsg_to_fib6_config()
4355 return -EINVAL; in ipv6_route_ioctl()
4356 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in ipv6_route_ioctl()
4357 return -EPERM; in ipv6_route_ioctl()
4381 struct net *net = dev_net(dst->dev); in ip6_pkt_drop()
4385 if (netif_is_l3_master(skb->dev) && in ip6_pkt_drop()
4386 dst->dev == net->loopback_dev) in ip6_pkt_drop()
4387 idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif)); in ip6_pkt_drop()
4393 type = ipv6_addr_type(&ipv6_hdr(skb)->daddr); in ip6_pkt_drop()
4405 if (netif_is_l3_master(skb->dev)) in ip6_pkt_drop()
4420 skb->dev = skb_dst(skb)->dev; in ip6_pkt_discard_out()
4431 skb->dev = skb_dst(skb)->dev; in ip6_pkt_prohibit_out()
4445 .fc_table = l3mdev_fib_table(idev->dev) ? : RT6_TABLE_LOCAL, in addrconf_f6i_alloc()
4446 .fc_ifindex = idev->dev->ifindex, in addrconf_f6i_alloc()
4466 f6i->dst_nocount = true; in addrconf_f6i_alloc()
4479 struct net_device *dev = ((struct arg_dev_net_ip *)arg)->dev; in fib6_remove_prefsrc()
4480 struct net *net = ((struct arg_dev_net_ip *)arg)->net; in fib6_remove_prefsrc()
4481 struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr; in fib6_remove_prefsrc()
4483 if (!rt->nh && in fib6_remove_prefsrc()
4484 ((void *)rt->fib6_nh->fib_nh_dev == dev || !dev) && in fib6_remove_prefsrc()
4485 rt != net->ipv6.fib6_null_entry && in fib6_remove_prefsrc()
4486 ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr)) { in fib6_remove_prefsrc()
4489 rt->fib6_prefsrc.plen = 0; in fib6_remove_prefsrc()
4497 struct net *net = dev_net(ifp->idev->dev); in rt6_remove_prefsrc()
4499 .dev = ifp->idev->dev, in rt6_remove_prefsrc()
4501 .addr = &ifp->addr, in rt6_remove_prefsrc()
4515 if (rt->nh) in fib6_clean_tohost()
4518 nh = rt->fib6_nh; in fib6_clean_tohost()
4519 if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) && in fib6_clean_tohost()
4520 nh->fib_nh_gw_family && ipv6_addr_equal(gateway, &nh->fib_nh_gw6)) in fib6_clean_tohost()
4521 return -1; in fib6_clean_tohost()
4524 * This is needed because cached route may have a different in fib6_clean_tohost()
4550 fn = rcu_dereference_protected(rt->fib6_node, in rt6_multipath_first_sibling()
4551 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4552 iter = rcu_dereference_protected(fn->leaf, in rt6_multipath_first_sibling()
4553 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4555 if (iter->fib6_metric == rt->fib6_metric && in rt6_multipath_first_sibling()
4558 iter = rcu_dereference_protected(iter->fib6_next, in rt6_multipath_first_sibling()
4559 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4568 if (rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD || in rt6_is_dead()
4569 (rt->fib6_nh->fib_nh_flags & RTNH_F_LINKDOWN && in rt6_is_dead()
4570 ip6_ignore_linkdown(rt->fib6_nh->fib_nh_dev))) in rt6_is_dead()
4582 total += rt->fib6_nh->fib_nh_weight; in rt6_multipath_total_weight()
4584 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) { in rt6_multipath_total_weight()
4586 total += iter->fib6_nh->fib_nh_weight; in rt6_multipath_total_weight()
4594 int upper_bound = -1; in rt6_upper_bound_set()
4597 *weight += rt->fib6_nh->fib_nh_weight; in rt6_upper_bound_set()
4599 total) - 1; in rt6_upper_bound_set()
4601 atomic_set(&rt->fib6_nh->fib_nh_upper_bound, upper_bound); in rt6_upper_bound_set()
4611 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_upper_bound_set()
4620 /* In case the entire multipath route was marked for flushing, in rt6_multipath_rebalance()
4622 * sibling route. in rt6_multipath_rebalance()
4624 if (!rt->fib6_nsiblings || rt->should_flush) in rt6_multipath_rebalance()
4642 struct net *net = dev_net(arg->dev); in fib6_ifup()
4644 if (rt != net->ipv6.fib6_null_entry && !rt->nh && in fib6_ifup()
4645 rt->fib6_nh->fib_nh_dev == arg->dev) { in fib6_ifup()
4646 rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags; in fib6_ifup()
4675 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_uses_dev()
4677 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_uses_dev()
4678 if (iter->fib6_nh->fib_nh_dev == dev) in rt6_multipath_uses_dev()
4688 rt->should_flush = 1; in rt6_multipath_flush()
4689 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_flush()
4690 iter->should_flush = 1; in rt6_multipath_flush()
4699 if (rt->fib6_nh->fib_nh_dev == down_dev || in rt6_multipath_dead_count()
4700 rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD) in rt6_multipath_dead_count()
4702 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_dead_count()
4703 if (iter->fib6_nh->fib_nh_dev == down_dev || in rt6_multipath_dead_count()
4704 iter->fib6_nh->fib_nh_flags & RTNH_F_DEAD) in rt6_multipath_dead_count()
4716 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_nh_flags_set()
4717 rt->fib6_nh->fib_nh_flags |= nh_flags; in rt6_multipath_nh_flags_set()
4718 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_nh_flags_set()
4719 if (iter->fib6_nh->fib_nh_dev == dev) in rt6_multipath_nh_flags_set()
4720 iter->fib6_nh->fib_nh_flags |= nh_flags; in rt6_multipath_nh_flags_set()
4727 const struct net_device *dev = arg->dev; in fib6_ifdown()
4730 if (rt == net->ipv6.fib6_null_entry || rt->nh) in fib6_ifdown()
4733 switch (arg->event) { in fib6_ifdown()
4735 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4737 if (rt->should_flush) in fib6_ifdown()
4738 return -1; in fib6_ifdown()
4739 if (!rt->fib6_nsiblings) in fib6_ifdown()
4740 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4745 if (rt->fib6_nsiblings + 1 == count) { in fib6_ifdown()
4747 return -1; in fib6_ifdown()
4754 return -2; in fib6_ifdown()
4756 if (rt->fib6_nh->fib_nh_dev != dev || in fib6_ifdown()
4757 rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) in fib6_ifdown()
4759 rt->fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib6_ifdown()
4777 if (net->ipv6.sysctl.skip_notify_on_dev_down) in rt6_sync_down_dev()
4799 struct fib6_info *f6i = arg->f6i; in fib6_nh_mtu_change()
4806 if (nh->fib_nh_dev == arg->dev) { in fib6_nh_mtu_change()
4807 struct inet6_dev *idev = __in6_dev_get(arg->dev); in fib6_nh_mtu_change()
4808 u32 mtu = f6i->fib6_pmtu; in fib6_nh_mtu_change()
4810 if (mtu >= arg->mtu || in fib6_nh_mtu_change()
4811 (mtu < arg->mtu && mtu == idev->cnf.mtu6)) in fib6_nh_mtu_change()
4812 fib6_metric_set(f6i, RTAX_MTU, arg->mtu); in fib6_nh_mtu_change()
4815 rt6_exceptions_update_pmtu(idev, nh, arg->mtu); in fib6_nh_mtu_change()
4833 idev = __in6_dev_get(arg->dev); in rt6_mtu_change_route()
4840 arg->f6i = f6i; in rt6_mtu_change_route()
4841 if (f6i->nh) { in rt6_mtu_change_route()
4843 return nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_mtu_change, in rt6_mtu_change_route()
4847 return fib6_nh_mtu_change(f6i->fib6_nh, arg); in rt6_mtu_change_route()
4896 err = -EINVAL; in rtm_to_fib6_config()
4900 .fc_table = rtm->rtm_table, in rtm_to_fib6_config()
4901 .fc_dst_len = rtm->rtm_dst_len, in rtm_to_fib6_config()
4902 .fc_src_len = rtm->rtm_src_len, in rtm_to_fib6_config()
4904 .fc_protocol = rtm->rtm_protocol, in rtm_to_fib6_config()
4905 .fc_type = rtm->rtm_type, in rtm_to_fib6_config()
4909 .fc_nlinfo.nl_net = sock_net(skb->sk), in rtm_to_fib6_config()
4912 if (rtm->rtm_type == RTN_UNREACHABLE || in rtm_to_fib6_config()
4913 rtm->rtm_type == RTN_BLACKHOLE || in rtm_to_fib6_config()
4914 rtm->rtm_type == RTN_PROHIBIT || in rtm_to_fib6_config()
4915 rtm->rtm_type == RTN_THROW) in rtm_to_fib6_config()
4916 cfg->fc_flags |= RTF_REJECT; in rtm_to_fib6_config()
4918 if (rtm->rtm_type == RTN_LOCAL) in rtm_to_fib6_config()
4919 cfg->fc_flags |= RTF_LOCAL; in rtm_to_fib6_config()
4921 if (rtm->rtm_flags & RTM_F_CLONED) in rtm_to_fib6_config()
4922 cfg->fc_flags |= RTF_CACHE; in rtm_to_fib6_config()
4924 cfg->fc_flags |= (rtm->rtm_flags & RTNH_F_ONLINK); in rtm_to_fib6_config()
4933 cfg->fc_nh_id = nla_get_u32(tb[RTA_NH_ID]); in rtm_to_fib6_config()
4937 cfg->fc_gateway = nla_get_in6_addr(tb[RTA_GATEWAY]); in rtm_to_fib6_config()
4938 cfg->fc_flags |= RTF_GATEWAY; in rtm_to_fib6_config()
4946 int plen = (rtm->rtm_dst_len + 7) >> 3; in rtm_to_fib6_config()
4951 nla_memcpy(&cfg->fc_dst, tb[RTA_DST], plen); in rtm_to_fib6_config()
4955 int plen = (rtm->rtm_src_len + 7) >> 3; in rtm_to_fib6_config()
4960 nla_memcpy(&cfg->fc_src, tb[RTA_SRC], plen); in rtm_to_fib6_config()
4964 cfg->fc_prefsrc = nla_get_in6_addr(tb[RTA_PREFSRC]); in rtm_to_fib6_config()
4967 cfg->fc_ifindex = nla_get_u32(tb[RTA_OIF]); in rtm_to_fib6_config()
4970 cfg->fc_metric = nla_get_u32(tb[RTA_PRIORITY]); in rtm_to_fib6_config()
4973 cfg->fc_mx = nla_data(tb[RTA_METRICS]); in rtm_to_fib6_config()
4974 cfg->fc_mx_len = nla_len(tb[RTA_METRICS]); in rtm_to_fib6_config()
4978 cfg->fc_table = nla_get_u32(tb[RTA_TABLE]); in rtm_to_fib6_config()
4981 cfg->fc_mp = nla_data(tb[RTA_MULTIPATH]); in rtm_to_fib6_config()
4982 cfg->fc_mp_len = nla_len(tb[RTA_MULTIPATH]); in rtm_to_fib6_config()
4984 err = lwtunnel_valid_encap_type_attr(cfg->fc_mp, in rtm_to_fib6_config()
4985 cfg->fc_mp_len, extack); in rtm_to_fib6_config()
4995 cfg->fc_flags |= RTF_PREF(pref); in rtm_to_fib6_config()
4999 cfg->fc_encap = tb[RTA_ENCAP]; in rtm_to_fib6_config()
5002 cfg->fc_encap_type = nla_get_u16(tb[RTA_ENCAP_TYPE]); in rtm_to_fib6_config()
5004 err = lwtunnel_valid_encap_type(cfg->fc_encap_type, extack); in rtm_to_fib6_config()
5013 cfg->fc_expires = jiffies_to_clock_t(timeout * HZ); in rtm_to_fib6_config()
5014 cfg->fc_flags |= RTF_EXPIRES; in rtm_to_fib6_config()
5035 int err = -EEXIST; in ip6_route_info_append()
5039 if (rt6_duplicate_nexthop(nh->fib6_info, rt)) in ip6_route_info_append()
5045 return -ENOMEM; in ip6_route_info_append()
5046 nh->fib6_info = rt; in ip6_route_info_append()
5047 memcpy(&nh->r_cfg, r_cfg, sizeof(*r_cfg)); in ip6_route_info_append()
5048 list_add_tail(&nh->next, rt6_nh_list); in ip6_route_info_append()
5058 /* if this is an APPEND route, then rt points to the first route in ip6_route_mpath_notify()
5059 * inserted and rt_last points to last route inserted. Userspace in ip6_route_mpath_notify()
5060 * wants a consistent dump of the route which starts at the first in ip6_route_mpath_notify()
5062 * the list, find the first sibling of the last route appended in ip6_route_mpath_notify()
5064 if ((nlflags & NLM_F_APPEND) && rt_last && rt_last->fib6_nsiblings) { in ip6_route_mpath_notify()
5065 rt = list_first_entry(&rt_last->fib6_siblings, in ip6_route_mpath_notify()
5082 fn = rcu_dereference(rt->fib6_node); in ip6_route_mpath_should_notify()
5086 leaf = rcu_dereference(fn->leaf); in ip6_route_mpath_should_notify()
5091 (rt_can_ecmp && rt->fib6_metric == leaf->fib6_metric && in ip6_route_mpath_should_notify()
5104 struct nl_info *info = &cfg->fc_nlinfo; in ip6_route_multipath_add()
5115 int replace = (cfg->fc_nlinfo.nlh && in ip6_route_multipath_add()
5116 (cfg->fc_nlinfo.nlh->nlmsg_flags & NLM_F_REPLACE)); in ip6_route_multipath_add()
5120 if (info->nlh && info->nlh->nlmsg_flags & NLM_F_APPEND) in ip6_route_multipath_add()
5123 remaining = cfg->fc_mp_len; in ip6_route_multipath_add()
5124 rtnh = (struct rtnexthop *)cfg->fc_mp; in ip6_route_multipath_add()
5131 if (rtnh->rtnh_ifindex) in ip6_route_multipath_add()
5132 r_cfg.fc_ifindex = rtnh->rtnh_ifindex; in ip6_route_multipath_add()
5149 r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK); in ip6_route_multipath_add()
5157 err = -EINVAL; in ip6_route_multipath_add()
5164 rt->fib6_nh->fib_nh_weight = rtnh->rtnh_hops + 1; in ip6_route_multipath_add()
5166 err = ip6_route_info_append(info->nl_net, &rt6_nh_list, in ip6_route_multipath_add()
5178 "Invalid nexthop configuration - no valid nexthops"); in ip6_route_multipath_add()
5179 return -EINVAL; in ip6_route_multipath_add()
5184 * the full route when done in ip6_route_multipath_add()
5186 info->skip_notify = 1; in ip6_route_multipath_add()
5191 info->skip_notify_kernel = 1; in ip6_route_multipath_add()
5195 err = __ip6_ins_rt(nh->fib6_info, info, extack); in ip6_route_multipath_add()
5196 fib6_info_release(nh->fib6_info); in ip6_route_multipath_add()
5199 /* save reference to last route successfully inserted */ in ip6_route_multipath_add()
5200 rt_last = nh->fib6_info; in ip6_route_multipath_add()
5202 /* save reference to first route for notification */ in ip6_route_multipath_add()
5204 rt_notif = nh->fib6_info; in ip6_route_multipath_add()
5207 /* nh->fib6_info is used or freed at this point, reset to NULL*/ in ip6_route_multipath_add()
5208 nh->fib6_info = NULL; in ip6_route_multipath_add()
5212 "multipath route replace failed (check consistency of installed routes)"); in ip6_route_multipath_add()
5217 /* Because each route is added like a single route we remove in ip6_route_multipath_add()
5224 cfg->fc_nlinfo.nlh->nlmsg_flags &= ~(NLM_F_EXCL | in ip6_route_multipath_add()
5226 cfg->fc_nlinfo.nlh->nlmsg_flags |= NLM_F_CREATE; in ip6_route_multipath_add()
5230 /* An in-kernel notification should only be sent in case the new in ip6_route_multipath_add()
5231 * multipath route is added as the first route in the node, or if in ip6_route_multipath_add()
5238 if (rt_notif->fib6_nsiblings != nhn - 1) in ip6_route_multipath_add()
5243 err = call_fib6_multipath_entry_notifiers(info->nl_net, in ip6_route_multipath_add()
5245 nhn - 1, extack); in ip6_route_multipath_add()
5253 /* success ... tell user about new route */ in ip6_route_multipath_add()
5269 ip6_route_del(&nh->r_cfg, extack); in ip6_route_multipath_add()
5274 if (nh->fib6_info) in ip6_route_multipath_add()
5275 fib6_info_release(nh->fib6_info); in ip6_route_multipath_add()
5276 list_del(&nh->next); in ip6_route_multipath_add()
5293 remaining = cfg->fc_mp_len; in ip6_route_multipath_del()
5294 rtnh = (struct rtnexthop *)cfg->fc_mp; in ip6_route_multipath_del()
5299 if (rtnh->rtnh_ifindex) in ip6_route_multipath_del()
5300 r_cfg.fc_ifindex = rtnh->rtnh_ifindex; in ip6_route_multipath_del()
5333 !nexthop_find_by_id(sock_net(skb->sk), cfg.fc_nh_id)) { in inet6_rtm_delroute()
5335 return -EINVAL; in inet6_rtm_delroute()
5374 if (nh->fib_nh_lws) { in rt6_nh_nlmsg_size()
5376 *nexthop_len += lwtunnel_get_encap_size(nh->fib_nh_lws); in rt6_nh_nlmsg_size()
5388 if (f6i->nh) { in rt6_nlmsg_size()
5390 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_nlmsg_size, in rt6_nlmsg_size()
5393 struct fib6_nh *nh = f6i->fib6_nh; in rt6_nlmsg_size()
5396 if (f6i->fib6_nsiblings) { in rt6_nlmsg_size()
5400 + lwtunnel_get_encap_size(nh->fib_nh_lws); in rt6_nlmsg_size()
5402 nexthop_len *= f6i->fib6_nsiblings; in rt6_nlmsg_size()
5404 nexthop_len += lwtunnel_get_encap_size(nh->fib_nh_lws); in rt6_nlmsg_size()
5441 if (fib_nexthop_info(skb, &fib6_nh->nh_common, AF_INET6, in rt6_fill_node_nexthop()
5449 return -EMSGSIZE; in rt6_fill_node_nexthop()
5468 return -EMSGSIZE; in rt6_fill_node()
5471 rt6_dst = &rt6->rt6i_dst; in rt6_fill_node()
5472 rt6_src = &rt6->rt6i_src; in rt6_fill_node()
5473 rt6_flags = rt6->rt6i_flags; in rt6_fill_node()
5475 rt6_dst = &rt->fib6_dst; in rt6_fill_node()
5476 rt6_src = &rt->fib6_src; in rt6_fill_node()
5477 rt6_flags = rt->fib6_flags; in rt6_fill_node()
5481 rtm->rtm_family = AF_INET6; in rt6_fill_node()
5482 rtm->rtm_dst_len = rt6_dst->plen; in rt6_fill_node()
5483 rtm->rtm_src_len = rt6_src->plen; in rt6_fill_node()
5484 rtm->rtm_tos = 0; in rt6_fill_node()
5485 if (rt->fib6_table) in rt6_fill_node()
5486 table = rt->fib6_table->tb6_id; in rt6_fill_node()
5489 rtm->rtm_table = table < 256 ? table : RT_TABLE_COMPAT; in rt6_fill_node()
5493 rtm->rtm_type = rt->fib6_type; in rt6_fill_node()
5494 rtm->rtm_flags = 0; in rt6_fill_node()
5495 rtm->rtm_scope = RT_SCOPE_UNIVERSE; in rt6_fill_node()
5496 rtm->rtm_protocol = rt->fib6_protocol; in rt6_fill_node()
5499 rtm->rtm_flags |= RTM_F_CLONED; in rt6_fill_node()
5504 rtm->rtm_dst_len = 128; in rt6_fill_node()
5505 } else if (rtm->rtm_dst_len) in rt6_fill_node()
5506 if (nla_put_in6_addr(skb, RTA_DST, &rt6_dst->addr)) in rt6_fill_node()
5512 rtm->rtm_src_len = 128; in rt6_fill_node()
5513 } else if (rtm->rtm_src_len && in rt6_fill_node()
5514 nla_put_in6_addr(skb, RTA_SRC, &rt6_src->addr)) in rt6_fill_node()
5519 if (ipv6_addr_is_multicast(&rt6_dst->addr)) { in rt6_fill_node()
5537 if (rt->fib6_prefsrc.plen) { in rt6_fill_node()
5539 saddr_buf = rt->fib6_prefsrc.addr; in rt6_fill_node()
5544 pmetrics = dst ? dst_metrics_ptr(dst) : rt->fib6_metrics->metrics; in rt6_fill_node()
5548 if (nla_put_u32(skb, RTA_PRIORITY, rt->fib6_metric)) in rt6_fill_node()
5556 nla_put_in6_addr(skb, RTA_GATEWAY, &rt6->rt6i_gateway)) in rt6_fill_node()
5559 if (dst->dev && nla_put_u32(skb, RTA_OIF, dst->dev->ifindex)) in rt6_fill_node()
5561 } else if (rt->fib6_nsiblings) { in rt6_fill_node()
5569 if (fib_add_nexthop(skb, &rt->fib6_nh->nh_common, in rt6_fill_node()
5570 rt->fib6_nh->fib_nh_weight, AF_INET6) < 0) in rt6_fill_node()
5574 &rt->fib6_siblings, fib6_siblings) { in rt6_fill_node()
5575 if (fib_add_nexthop(skb, &sibling->fib6_nh->nh_common, in rt6_fill_node()
5576 sibling->fib6_nh->fib_nh_weight, in rt6_fill_node()
5582 } else if (rt->nh) { in rt6_fill_node()
5583 if (nla_put_u32(skb, RTA_NH_ID, rt->nh->id)) in rt6_fill_node()
5586 if (nexthop_is_blackhole(rt->nh)) in rt6_fill_node()
5587 rtm->rtm_type = RTN_BLACKHOLE; in rt6_fill_node()
5589 if (net->ipv4.sysctl_nexthop_compat_mode && in rt6_fill_node()
5590 rt6_fill_node_nexthop(skb, rt->nh, &nh_flags) < 0) in rt6_fill_node()
5593 rtm->rtm_flags |= nh_flags; in rt6_fill_node()
5595 if (fib_nexthop_info(skb, &rt->fib6_nh->nh_common, AF_INET6, in rt6_fill_node()
5599 rtm->rtm_flags |= nh_flags; in rt6_fill_node()
5603 expires = dst ? dst->expires : rt->expires; in rt6_fill_node()
5604 expires -= jiffies; in rt6_fill_node()
5608 if (rt->offload) in rt6_fill_node()
5609 rtm->rtm_flags |= RTM_F_OFFLOAD; in rt6_fill_node()
5610 if (rt->trap) in rt6_fill_node()
5611 rtm->rtm_flags |= RTM_F_TRAP; in rt6_fill_node()
5614 if (rtnl_put_cacheinfo(skb, dst, 0, expires, dst ? dst->error : 0) < 0) in rt6_fill_node()
5626 return -EMSGSIZE; in rt6_fill_node()
5633 if (nh->fib_nh_dev == dev) in fib6_info_nh_uses_dev()
5642 if (f6i->nh) { in fib6_info_uses_dev()
5645 return !!nexthop_for_each_fib6_nh(f6i->nh, in fib6_info_uses_dev()
5650 if (f6i->fib6_nh->fib_nh_dev == dev) in fib6_info_uses_dev()
5653 if (f6i->fib6_nsiblings) { in fib6_info_uses_dev()
5657 &f6i->fib6_siblings, fib6_siblings) { in fib6_info_uses_dev()
5658 if (sibling->fib6_nh->fib_nh_dev == dev) in fib6_info_uses_dev()
5677 struct rt6_rtnl_dump_arg *dump = w->dump; in rt6_nh_dump_exceptions()
5687 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_nh_dump_exceptions()
5688 if (w->skip) { in rt6_nh_dump_exceptions()
5689 w->skip--; in rt6_nh_dump_exceptions()
5704 if (rt6_check_expired(rt6_ex->rt6i)) { in rt6_nh_dump_exceptions()
5705 w->count++; in rt6_nh_dump_exceptions()
5709 err = rt6_fill_node(dump->net, dump->skb, w->rt, in rt6_nh_dump_exceptions()
5710 &rt6_ex->rt6i->dst, NULL, NULL, 0, in rt6_nh_dump_exceptions()
5712 NETLINK_CB(dump->cb->skb).portid, in rt6_nh_dump_exceptions()
5713 dump->cb->nlh->nlmsg_seq, w->flags); in rt6_nh_dump_exceptions()
5717 w->count++; in rt6_nh_dump_exceptions()
5725 /* Return -1 if done with node, number of handled routes on partial dump */
5729 struct fib_dump_filter *filter = &arg->filter; in rt6_dump_route()
5731 struct net *net = arg->net; in rt6_dump_route()
5734 if (rt == net->ipv6.fib6_null_entry) in rt6_dump_route()
5735 return -1; in rt6_dump_route()
5737 if ((filter->flags & RTM_F_PREFIX) && in rt6_dump_route()
5738 !(rt->fib6_flags & RTF_PREFIX_RT)) { in rt6_dump_route()
5739 /* success since this is not a prefix route */ in rt6_dump_route()
5740 return -1; in rt6_dump_route()
5742 if (filter->filter_set && in rt6_dump_route()
5743 ((filter->rt_type && rt->fib6_type != filter->rt_type) || in rt6_dump_route()
5744 (filter->dev && !fib6_info_uses_dev(rt, filter->dev)) || in rt6_dump_route()
5745 (filter->protocol && rt->fib6_protocol != filter->protocol))) { in rt6_dump_route()
5746 return -1; in rt6_dump_route()
5749 if (filter->filter_set || in rt6_dump_route()
5750 !filter->dump_routes || !filter->dump_exceptions) { in rt6_dump_route()
5754 if (filter->dump_routes) { in rt6_dump_route()
5756 skip--; in rt6_dump_route()
5758 if (rt6_fill_node(net, arg->skb, rt, NULL, NULL, NULL, in rt6_dump_route()
5760 NETLINK_CB(arg->cb->skb).portid, in rt6_dump_route()
5761 arg->cb->nlh->nlmsg_seq, flags)) { in rt6_dump_route()
5768 if (filter->dump_exceptions) { in rt6_dump_route()
5777 if (rt->nh) { in rt6_dump_route()
5778 err = nexthop_for_each_fib6_nh(rt->nh, in rt6_dump_route()
5782 err = rt6_nh_dump_exceptions(rt->fib6_nh, &w); in rt6_dump_route()
5790 return -1; in rt6_dump_route()
5801 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*rtm))) { in inet6_rtm_valid_getroute_req()
5803 "Invalid header for get route request"); in inet6_rtm_valid_getroute_req()
5804 return -EINVAL; in inet6_rtm_valid_getroute_req()
5812 if ((rtm->rtm_src_len && rtm->rtm_src_len != 128) || in inet6_rtm_valid_getroute_req()
5813 (rtm->rtm_dst_len && rtm->rtm_dst_len != 128) || in inet6_rtm_valid_getroute_req()
5814 rtm->rtm_table || rtm->rtm_protocol || rtm->rtm_scope || in inet6_rtm_valid_getroute_req()
5815 rtm->rtm_type) { in inet6_rtm_valid_getroute_req()
5816 NL_SET_ERR_MSG_MOD(extack, "Invalid values in header for get route request"); in inet6_rtm_valid_getroute_req()
5817 return -EINVAL; in inet6_rtm_valid_getroute_req()
5819 if (rtm->rtm_flags & ~RTM_F_FIB_MATCH) { in inet6_rtm_valid_getroute_req()
5821 "Invalid flags for get route request"); in inet6_rtm_valid_getroute_req()
5822 return -EINVAL; in inet6_rtm_valid_getroute_req()
5830 if ((tb[RTA_SRC] && !rtm->rtm_src_len) || in inet6_rtm_valid_getroute_req()
5831 (tb[RTA_DST] && !rtm->rtm_dst_len)) { in inet6_rtm_valid_getroute_req()
5833 return -EINVAL; in inet6_rtm_valid_getroute_req()
5852 NL_SET_ERR_MSG_MOD(extack, "Unsupported attribute in get route request"); in inet6_rtm_valid_getroute_req()
5853 return -EINVAL; in inet6_rtm_valid_getroute_req()
5863 struct net *net = sock_net(in_skb->sk); in inet6_rtm_getroute()
5878 err = -EINVAL; in inet6_rtm_getroute()
5880 fl6.flowlabel = ip6_make_flowinfo(rtm->rtm_tos, 0); in inet6_rtm_getroute()
5881 fibmatch = !!(rtm->rtm_flags & RTM_F_FIB_MATCH); in inet6_rtm_getroute()
5935 err = -ENODEV; in inet6_rtm_getroute()
5955 if (rt->dst.error) { in inet6_rtm_getroute()
5956 err = rt->dst.error; in inet6_rtm_getroute()
5961 if (rt == net->ipv6.ip6_null_entry) { in inet6_rtm_getroute()
5962 err = rt->dst.error; in inet6_rtm_getroute()
5970 err = -ENOBUFS; in inet6_rtm_getroute()
5974 skb_dst_set(skb, &rt->dst); in inet6_rtm_getroute()
5977 from = rcu_dereference(rt->from); in inet6_rtm_getroute()
5983 nlh->nlmsg_seq, 0); in inet6_rtm_getroute()
5988 nlh->nlmsg_seq, 0); in inet6_rtm_getroute()
5990 err = -ENETUNREACH; in inet6_rtm_getroute()
6008 struct net *net = info->nl_net; in inet6_rt_notify()
6012 err = -ENOBUFS; in inet6_rt_notify()
6013 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in inet6_rt_notify()
6020 event, info->portid, seq, nlm_flags); in inet6_rt_notify()
6022 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ in inet6_rt_notify()
6023 WARN_ON(err == -EMSGSIZE); in inet6_rt_notify()
6027 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in inet6_rt_notify()
6028 info->nlh, gfp_any()); in inet6_rt_notify()
6038 u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in fib6_rt_update()
6040 int err = -ENOBUFS; in fib6_rt_update()
6042 /* call_fib6_entry_notifiers will be removed when in-kernel notifier in fib6_rt_update()
6052 RTM_NEWROUTE, info->portid, seq, NLM_F_REPLACE); in fib6_rt_update()
6054 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ in fib6_rt_update()
6055 WARN_ON(err == -EMSGSIZE); in fib6_rt_update()
6059 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in fib6_rt_update()
6060 info->nlh, gfp_any()); in fib6_rt_update()
6073 if (!(dev->flags & IFF_LOOPBACK)) in ip6_route_dev_notify()
6077 net->ipv6.fib6_null_entry->fib6_nh->fib_nh_dev = dev; in ip6_route_dev_notify()
6078 net->ipv6.ip6_null_entry->dst.dev = dev; in ip6_route_dev_notify()
6079 net->ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6081 net->ipv6.ip6_prohibit_entry->dst.dev = dev; in ip6_route_dev_notify()
6082 net->ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6083 net->ipv6.ip6_blk_hole_entry->dst.dev = dev; in ip6_route_dev_notify()
6084 net->ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6087 dev->reg_state != NETREG_UNREGISTERED) { in ip6_route_dev_notify()
6091 in6_dev_put_clear(&net->ipv6.ip6_null_entry->rt6i_idev); in ip6_route_dev_notify()
6093 in6_dev_put_clear(&net->ipv6.ip6_prohibit_entry->rt6i_idev); in ip6_route_dev_notify()
6094 in6_dev_put_clear(&net->ipv6.ip6_blk_hole_entry->rt6i_idev); in ip6_route_dev_notify()
6108 struct net *net = (struct net *)seq->private; in rt6_stats_seq_show()
6110 net->ipv6.rt6_stats->fib_nodes, in rt6_stats_seq_show()
6111 net->ipv6.rt6_stats->fib_route_nodes, in rt6_stats_seq_show()
6112 atomic_read(&net->ipv6.rt6_stats->fib_rt_alloc), in rt6_stats_seq_show()
6113 net->ipv6.rt6_stats->fib_rt_entries, in rt6_stats_seq_show()
6114 net->ipv6.rt6_stats->fib_rt_cache, in rt6_stats_seq_show()
6115 dst_entries_get_slow(&net->ipv6.ip6_dst_ops), in rt6_stats_seq_show()
6116 net->ipv6.rt6_stats->fib_discarded_routes); in rt6_stats_seq_show()
6131 return -EINVAL; in ipv6_sysctl_rtcache_flush()
6133 net = (struct net *)ctl->extra1; in ipv6_sysctl_rtcache_flush()
6134 delay = net->ipv6.sysctl.flush_delay; in ipv6_sysctl_rtcache_flush()
6235 table[0].data = &net->ipv6.sysctl.flush_delay; in ipv6_route_sysctl_init()
6237 table[1].data = &net->ipv6.ip6_dst_ops.gc_thresh; in ipv6_route_sysctl_init()
6238 table[2].data = &net->ipv6.sysctl.ip6_rt_max_size; in ipv6_route_sysctl_init()
6239 table[3].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; in ipv6_route_sysctl_init()
6240 table[4].data = &net->ipv6.sysctl.ip6_rt_gc_timeout; in ipv6_route_sysctl_init()
6241 table[5].data = &net->ipv6.sysctl.ip6_rt_gc_interval; in ipv6_route_sysctl_init()
6242 table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity; in ipv6_route_sysctl_init()
6243 table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires; in ipv6_route_sysctl_init()
6244 table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss; in ipv6_route_sysctl_init()
6245 table[9].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; in ipv6_route_sysctl_init()
6246 table[10].data = &net->ipv6.sysctl.skip_notify_on_dev_down; in ipv6_route_sysctl_init()
6249 if (net->user_ns != &init_user_ns) in ipv6_route_sysctl_init()
6259 int ret = -ENOMEM; in ip6_route_net_init()
6261 memcpy(&net->ipv6.ip6_dst_ops, &ip6_dst_ops_template, in ip6_route_net_init()
6262 sizeof(net->ipv6.ip6_dst_ops)); in ip6_route_net_init()
6264 if (dst_entries_init(&net->ipv6.ip6_dst_ops) < 0) in ip6_route_net_init()
6267 net->ipv6.fib6_null_entry = fib6_info_alloc(GFP_KERNEL, true); in ip6_route_net_init()
6268 if (!net->ipv6.fib6_null_entry) in ip6_route_net_init()
6270 memcpy(net->ipv6.fib6_null_entry, &fib6_null_entry_template, in ip6_route_net_init()
6271 sizeof(*net->ipv6.fib6_null_entry)); in ip6_route_net_init()
6273 net->ipv6.ip6_null_entry = kmemdup(&ip6_null_entry_template, in ip6_route_net_init()
6274 sizeof(*net->ipv6.ip6_null_entry), in ip6_route_net_init()
6276 if (!net->ipv6.ip6_null_entry) in ip6_route_net_init()
6278 net->ipv6.ip6_null_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6279 dst_init_metrics(&net->ipv6.ip6_null_entry->dst, in ip6_route_net_init()
6281 INIT_LIST_HEAD(&net->ipv6.ip6_null_entry->rt6i_uncached); in ip6_route_net_init()
6284 net->ipv6.fib6_has_custom_rules = false; in ip6_route_net_init()
6285 net->ipv6.ip6_prohibit_entry = kmemdup(&ip6_prohibit_entry_template, in ip6_route_net_init()
6286 sizeof(*net->ipv6.ip6_prohibit_entry), in ip6_route_net_init()
6288 if (!net->ipv6.ip6_prohibit_entry) in ip6_route_net_init()
6290 net->ipv6.ip6_prohibit_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6291 dst_init_metrics(&net->ipv6.ip6_prohibit_entry->dst, in ip6_route_net_init()
6293 INIT_LIST_HEAD(&net->ipv6.ip6_prohibit_entry->rt6i_uncached); in ip6_route_net_init()
6295 net->ipv6.ip6_blk_hole_entry = kmemdup(&ip6_blk_hole_entry_template, in ip6_route_net_init()
6296 sizeof(*net->ipv6.ip6_blk_hole_entry), in ip6_route_net_init()
6298 if (!net->ipv6.ip6_blk_hole_entry) in ip6_route_net_init()
6300 net->ipv6.ip6_blk_hole_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6301 dst_init_metrics(&net->ipv6.ip6_blk_hole_entry->dst, in ip6_route_net_init()
6303 INIT_LIST_HEAD(&net->ipv6.ip6_blk_hole_entry->rt6i_uncached); in ip6_route_net_init()
6305 net->ipv6.fib6_routes_require_src = 0; in ip6_route_net_init()
6309 net->ipv6.sysctl.flush_delay = 0; in ip6_route_net_init()
6310 net->ipv6.sysctl.ip6_rt_max_size = 4096; in ip6_route_net_init()
6311 net->ipv6.sysctl.ip6_rt_gc_min_interval = HZ / 2; in ip6_route_net_init()
6312 net->ipv6.sysctl.ip6_rt_gc_timeout = 60*HZ; in ip6_route_net_init()
6313 net->ipv6.sysctl.ip6_rt_gc_interval = 30*HZ; in ip6_route_net_init()
6314 net->ipv6.sysctl.ip6_rt_gc_elasticity = 9; in ip6_route_net_init()
6315 net->ipv6.sysctl.ip6_rt_mtu_expires = 10*60*HZ; in ip6_route_net_init()
6316 net->ipv6.sysctl.ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40; in ip6_route_net_init()
6317 net->ipv6.sysctl.skip_notify_on_dev_down = 0; in ip6_route_net_init()
6319 net->ipv6.ip6_rt_gc_expire = 30*HZ; in ip6_route_net_init()
6327 kfree(net->ipv6.ip6_prohibit_entry); in ip6_route_net_init()
6329 kfree(net->ipv6.ip6_null_entry); in ip6_route_net_init()
6332 kfree(net->ipv6.fib6_null_entry); in ip6_route_net_init()
6334 dst_entries_destroy(&net->ipv6.ip6_dst_ops); in ip6_route_net_init()
6341 kfree(net->ipv6.fib6_null_entry); in ip6_route_net_exit()
6342 kfree(net->ipv6.ip6_null_entry); in ip6_route_net_exit()
6344 kfree(net->ipv6.ip6_prohibit_entry); in ip6_route_net_exit()
6345 kfree(net->ipv6.ip6_blk_hole_entry); in ip6_route_net_exit()
6347 dst_entries_destroy(&net->ipv6.ip6_dst_ops); in ip6_route_net_exit()
6353 proc_create_net("ipv6_route", 0, net->proc_net, &ipv6_route_seq_ops, in ip6_route_net_init_late()
6355 proc_create_net_single("rt6_stats", 0444, net->proc_net, in ip6_route_net_init_late()
6364 remove_proc_entry("ipv6_route", net->proc_net); in ip6_route_net_exit_late()
6365 remove_proc_entry("rt6_stats", net->proc_net); in ip6_route_net_exit_late()
6379 return -ENOMEM; in ipv6_inetpeer_init()
6381 net->ipv6.peers = bp; in ipv6_inetpeer_init()
6387 struct inet_peer_base *bp = net->ipv6.peers; in ipv6_inetpeer_exit()
6389 net->ipv6.peers = NULL; in ipv6_inetpeer_exit()
6406 .priority = ADDRCONF_NOTIFY_PRIORITY - 10,
6414 init_net.ipv6.fib6_null_entry->fib6_nh->fib_nh_dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6415 init_net.ipv6.ip6_null_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6416 init_net.ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6418 init_net.ipv6.ip6_prohibit_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6419 init_net.ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6420 init_net.ipv6.ip6_blk_hole_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6421 init_net.ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6467 ret = -ENOMEM; in ip6_route_init()
6535 INIT_LIST_HEAD(&ul->head); in ip6_route_init()
6536 spin_lock_init(&ul->lock); in ip6_route_init()