• Home
  • Raw
  • Download

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>
79 RT6_NUD_FAIL_HARD = -3,
80 RT6_NUD_FAIL_PROBE = -2,
81 RT6_NUD_FAIL_DO_RR = -1,
139 rt->rt6i_uncached_list = ul; in rt6_uncached_list_add()
141 spin_lock_bh(&ul->lock); in rt6_uncached_list_add()
142 list_add_tail(&rt->rt6i_uncached, &ul->head); in rt6_uncached_list_add()
143 spin_unlock_bh(&ul->lock); in rt6_uncached_list_add()
148 if (!list_empty(&rt->rt6i_uncached)) { in rt6_uncached_list_del()
149 struct uncached_list *ul = rt->rt6i_uncached_list; in rt6_uncached_list_del()
150 struct net *net = dev_net(rt->dst.dev); in rt6_uncached_list_del()
152 spin_lock_bh(&ul->lock); in rt6_uncached_list_del()
153 list_del(&rt->rt6i_uncached); in rt6_uncached_list_del()
154 atomic_dec(&net->ipv6.rt6_stats->fib_rt_uncache); in rt6_uncached_list_del()
155 spin_unlock_bh(&ul->lock); in rt6_uncached_list_del()
161 struct net_device *loopback_dev = net->loopback_dev; in rt6_uncached_list_flush_dev()
171 spin_lock_bh(&ul->lock); in rt6_uncached_list_flush_dev()
172 list_for_each_entry(rt, &ul->head, rt6i_uncached) { in rt6_uncached_list_flush_dev()
173 struct inet6_dev *rt_idev = rt->rt6i_idev; in rt6_uncached_list_flush_dev()
174 struct net_device *rt_dev = rt->dst.dev; in rt6_uncached_list_flush_dev()
176 if (rt_idev->dev == dev) { in rt6_uncached_list_flush_dev()
177 rt->rt6i_idev = in6_dev_get(loopback_dev); in rt6_uncached_list_flush_dev()
182 rt->dst.dev = blackhole_netdev; in rt6_uncached_list_flush_dev()
183 dev_hold(rt->dst.dev); in rt6_uncached_list_flush_dev()
187 spin_unlock_bh(&ul->lock); in rt6_uncached_list_flush_dev()
198 return &ipv6_hdr(skb)->daddr; in choose_neigh_daddr()
225 dst->dev, skb, daddr); in ip6_dst_neigh_lookup()
230 struct net_device *dev = dst->dev; in ip6_confirm_neigh()
236 if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) in ip6_confirm_neigh()
275 [RTAX_HOPLIMIT - 1] = 0,
292 .error = -ENETUNREACH,
306 .error = -EACCES,
318 .error = -EINVAL,
329 struct dst_entry *dst = &rt->dst; in rt6_info_init()
331 memset(dst + 1, 0, sizeof(*rt) - sizeof(*dst)); in rt6_info_init()
332 INIT_LIST_HEAD(&rt->rt6i_uncached); in rt6_info_init()
339 struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev, in ip6_dst_alloc()
344 atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc); in ip6_dst_alloc()
360 idev = rt->rt6i_idev; in ip6_dst_destroy()
362 rt->rt6i_idev = NULL; in ip6_dst_destroy()
366 from = xchg((__force struct fib6_info **)&rt->from, NULL); in ip6_dst_destroy()
374 struct inet6_dev *idev = rt->rt6i_idev; in ip6_dst_ifdown()
376 dev_net(dev)->loopback_dev; in ip6_dst_ifdown()
378 if (idev && idev->dev != loopback_dev) { in ip6_dst_ifdown()
381 rt->rt6i_idev = loopback_idev; in ip6_dst_ifdown()
389 if (rt->rt6i_flags & RTF_EXPIRES) in __rt6_check_expired()
390 return time_after(jiffies, rt->dst.expires); in __rt6_check_expired()
399 from = rcu_dereference(rt->from); in rt6_check_expired()
401 if (rt->rt6i_flags & RTF_EXPIRES) { in rt6_check_expired()
402 if (time_after(jiffies, rt->dst.expires)) in rt6_check_expired()
405 return rt->dst.obsolete != DST_OBSOLETE_FORCE_CHK || in rt6_check_expired()
416 struct fib6_info *match = res->f6i; in fib6_select_path()
418 if (!match->nh && (!match->fib6_nsiblings || have_oif_match)) in fib6_select_path()
421 if (match->nh && have_oif_match && res->nh) in fib6_select_path()
425 * case it will always be non-zero. Otherwise now is the time to do it. in fib6_select_path()
427 if (!fl6->mp_hash && in fib6_select_path()
428 (!match->nh || nexthop_is_multipath(match->nh))) in fib6_select_path()
429 fl6->mp_hash = rt6_multipath_hash(net, fl6, skb, NULL); in fib6_select_path()
431 if (unlikely(match->nh)) { in fib6_select_path()
432 nexthop_path_fib6_result(res, fl6->mp_hash); in fib6_select_path()
436 if (fl6->mp_hash <= atomic_read(&match->fib6_nh->fib_nh_upper_bound)) in fib6_select_path()
439 list_for_each_entry_safe(sibling, next_sibling, &match->fib6_siblings, in fib6_select_path()
441 const struct fib6_nh *nh = sibling->fib6_nh; in fib6_select_path()
444 nh_upper_bound = atomic_read(&nh->fib_nh_upper_bound); in fib6_select_path()
445 if (fl6->mp_hash > nh_upper_bound) in fib6_select_path()
447 if (rt6_score_route(nh, sibling->fib6_flags, oif, strict) < 0) in fib6_select_path()
454 res->f6i = match; in fib6_select_path()
455 res->nh = match->fib6_nh; in fib6_select_path()
459 * Route lookup. rcu_read_lock() should be held.
467 if (nh->fib_nh_flags & RTNH_F_DEAD) in __rt6_device_match()
470 dev = nh->fib_nh_dev; in __rt6_device_match()
472 if (dev->ifindex == oif) in __rt6_device_match()
495 arg->nh = nh; in __rt6_nh_dev_match()
496 return __rt6_device_match(arg->net, nh, arg->saddr, arg->oif, in __rt6_nh_dev_match()
497 arg->flags); in __rt6_nh_dev_match()
525 struct fib6_info *f6i = res->f6i; in rt6_device_match()
530 if (unlikely(f6i->nh)) { in rt6_device_match()
531 nh = nexthop_fib6_nh(f6i->nh); in rt6_device_match()
532 if (nexthop_is_blackhole(f6i->nh)) in rt6_device_match()
535 nh = f6i->fib6_nh; in rt6_device_match()
537 if (!(nh->fib_nh_flags & RTNH_F_DEAD)) in rt6_device_match()
541 for (spf6i = f6i; spf6i; spf6i = rcu_dereference(spf6i->fib6_next)) { in rt6_device_match()
544 if (unlikely(spf6i->nh)) { in rt6_device_match()
545 nh = rt6_nh_dev_match(net, spf6i->nh, res, saddr, in rt6_device_match()
550 nh = spf6i->fib6_nh; in rt6_device_match()
555 res->f6i = spf6i; in rt6_device_match()
561 res->f6i = net->ipv6.fib6_null_entry; in rt6_device_match()
562 nh = res->f6i->fib6_nh; in rt6_device_match()
566 if (unlikely(f6i->nh)) { in rt6_device_match()
567 nh = nexthop_fib6_nh(f6i->nh); in rt6_device_match()
568 if (nexthop_is_blackhole(f6i->nh)) in rt6_device_match()
571 nh = f6i->fib6_nh; in rt6_device_match()
574 if (nh->fib_nh_flags & RTNH_F_DEAD) { in rt6_device_match()
575 res->f6i = net->ipv6.fib6_null_entry; in rt6_device_match()
576 nh = res->f6i->fib6_nh; in rt6_device_match()
579 res->nh = nh; in rt6_device_match()
580 res->fib6_type = res->f6i->fib6_type; in rt6_device_match()
581 res->fib6_flags = res->f6i->fib6_flags; in rt6_device_match()
585 res->fib6_flags |= RTF_REJECT; in rt6_device_match()
586 res->fib6_type = RTN_BLACKHOLE; in rt6_device_match()
587 res->nh = nh; in rt6_device_match()
603 addrconf_addr_solict_mult(&work->target, &mcaddr); in rt6_probe_deferred()
604 ndisc_send_ns(work->dev, &work->target, &mcaddr, NULL, 0); in rt6_probe_deferred()
605 dev_put(work->dev); in rt6_probe_deferred()
623 * Router Reachability Probe MUST be rate-limited in rt6_probe()
626 if (!fib6_nh->fib_nh_gw_family) in rt6_probe()
629 nh_gw = &fib6_nh->fib_nh_gw6; in rt6_probe()
630 dev = fib6_nh->fib_nh_dev; in rt6_probe()
632 last_probe = READ_ONCE(fib6_nh->last_probe); in rt6_probe()
636 if (neigh->nud_state & NUD_VALID) in rt6_probe()
639 write_lock(&neigh->lock); in rt6_probe()
640 if (!(neigh->nud_state & NUD_VALID) && in rt6_probe()
642 neigh->updated + idev->cnf.rtr_probe_interval)) { in rt6_probe()
647 write_unlock(&neigh->lock); in rt6_probe()
649 idev->cnf.rtr_probe_interval)) { in rt6_probe()
653 if (!work || cmpxchg(&fib6_nh->last_probe, in rt6_probe()
657 INIT_WORK(&work->work, rt6_probe_deferred); in rt6_probe()
658 work->target = *nh_gw; in rt6_probe()
660 work->dev = dev; in rt6_probe()
661 schedule_work(&work->work); in rt6_probe()
682 neigh = __ipv6_neigh_lookup_noref(fib6_nh->fib_nh_dev, in rt6_check_neigh()
683 &fib6_nh->fib_nh_gw6); in rt6_check_neigh()
685 read_lock(&neigh->lock); in rt6_check_neigh()
686 if (neigh->nud_state & NUD_VALID) in rt6_check_neigh()
689 else if (!(neigh->nud_state & NUD_FAILED)) in rt6_check_neigh()
694 read_unlock(&neigh->lock); in rt6_check_neigh()
709 if (!oif || nh->fib_nh_dev->ifindex == oif) in rt6_score_route()
718 !(fib6_flags & RTF_NONEXTHOP) && nh->fib_nh_gw_family) { in rt6_score_route()
733 if (nh->fib_nh_flags & RTNH_F_DEAD) in find_match()
736 if (ip6_ignore_linkdown(nh->fib_nh_dev) && in find_match()
737 nh->fib_nh_flags & RTNH_F_LINKDOWN && in find_match()
775 arg->nh = nh; in rt6_nh_find_match()
776 return find_match(nh, arg->flags, arg->oif, arg->strict, in rt6_nh_find_match()
777 arg->mpri, arg->do_rr); in rt6_nh_find_match()
789 f6i = rcu_dereference(f6i->fib6_next)) { in __find_rr_leaf()
793 if (cont && f6i->fib6_metric != metric) { in __find_rr_leaf()
801 if (unlikely(f6i->nh)) { in __find_rr_leaf()
803 .flags = f6i->fib6_flags, in __find_rr_leaf()
810 if (nexthop_is_blackhole(f6i->nh)) { in __find_rr_leaf()
811 res->fib6_flags = RTF_REJECT; in __find_rr_leaf()
812 res->fib6_type = RTN_BLACKHOLE; in __find_rr_leaf()
813 res->f6i = f6i; in __find_rr_leaf()
814 res->nh = nexthop_fib6_nh(f6i->nh); in __find_rr_leaf()
817 if (nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_find_match, in __find_rr_leaf()
823 nh = f6i->fib6_nh; in __find_rr_leaf()
824 if (find_match(nh, f6i->fib6_flags, oif, strict, in __find_rr_leaf()
829 res->f6i = f6i; in __find_rr_leaf()
830 res->nh = nh; in __find_rr_leaf()
831 res->fib6_flags = f6i->fib6_flags; in __find_rr_leaf()
832 res->fib6_type = f6i->fib6_type; in __find_rr_leaf()
841 u32 metric = rr_head->fib6_metric; in find_rr_leaf()
843 int mpri = -1; in find_rr_leaf()
851 if (res->f6i || !cont) in find_rr_leaf()
861 struct fib6_info *leaf = rcu_dereference(fn->leaf); in rt6_select()
867 res->f6i = NULL; in rt6_select()
869 if (!leaf || leaf == net->ipv6.fib6_null_entry) in rt6_select()
872 rt0 = rcu_dereference(fn->rr_ptr); in rt6_select()
877 * and fn->leaf does not points to its child's leaf in rt6_select()
881 key_plen = rt0->fib6_dst.plen; in rt6_select()
883 if (rt0->fib6_src.plen) in rt6_select()
884 key_plen = rt0->fib6_src.plen; in rt6_select()
886 if (fn->fn_bit != key_plen) in rt6_select()
891 struct fib6_info *next = rcu_dereference(rt0->fib6_next); in rt6_select()
893 /* no entries matched; do round-robin */ in rt6_select()
894 if (!next || next->fib6_metric != rt0->fib6_metric) in rt6_select()
898 spin_lock_bh(&leaf->fib6_table->tb6_lock); in rt6_select()
900 if (next->fib6_node) in rt6_select()
901 rcu_assign_pointer(fn->rr_ptr, next); in rt6_select()
902 spin_unlock_bh(&leaf->fib6_table->tb6_lock); in rt6_select()
907 if (!res->f6i) { in rt6_select()
908 res->f6i = net->ipv6.fib6_null_entry; in rt6_select()
909 res->nh = res->f6i->fib6_nh; in rt6_select()
910 res->fib6_flags = res->f6i->fib6_flags; in rt6_select()
911 res->fib6_type = res->f6i->fib6_type; in rt6_select()
917 return (res->f6i->fib6_flags & RTF_NONEXTHOP) || in rt6_is_gw_or_nonexthop()
918 res->nh->fib_nh_gw_family; in rt6_is_gw_or_nonexthop()
933 return -EINVAL; in rt6_route_rcv()
937 if (rinfo->length > 3) { in rt6_route_rcv()
938 return -EINVAL; in rt6_route_rcv()
939 } else if (rinfo->prefix_len > 128) { in rt6_route_rcv()
940 return -EINVAL; in rt6_route_rcv()
941 } else if (rinfo->prefix_len > 64) { in rt6_route_rcv()
942 if (rinfo->length < 2) { in rt6_route_rcv()
943 return -EINVAL; in rt6_route_rcv()
945 } else if (rinfo->prefix_len > 0) { in rt6_route_rcv()
946 if (rinfo->length < 1) { in rt6_route_rcv()
947 return -EINVAL; in rt6_route_rcv()
951 pref = rinfo->route_pref; in rt6_route_rcv()
953 return -EINVAL; in rt6_route_rcv()
955 lifetime = addrconf_timeout_fixup(ntohl(rinfo->lifetime), HZ); in rt6_route_rcv()
957 if (rinfo->length == 3) in rt6_route_rcv()
958 prefix = (struct in6_addr *)rinfo->prefix; in rt6_route_rcv()
962 (struct in6_addr *)rinfo->prefix, in rt6_route_rcv()
963 rinfo->prefix_len); in rt6_route_rcv()
967 if (rinfo->prefix_len == 0) in rt6_route_rcv()
970 rt = rt6_get_route_info(net, prefix, rinfo->prefix_len, in rt6_route_rcv()
979 rt = rt6_add_route_info(net, prefix, rinfo->prefix_len, gwaddr, in rt6_route_rcv()
982 rt->fib6_flags = RTF_ROUTEINFO | in rt6_route_rcv()
983 (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); in rt6_route_rcv()
1004 struct net_device *dev = res->nh->fib_nh_dev; in ip6_rt_get_dev_rcu()
1006 if (res->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) { in ip6_rt_get_dev_rcu()
1007 /* for copies of local routes, dst->dev needs to be the in ip6_rt_get_dev_rcu()
1012 !rt6_need_strict(&res->f6i->fib6_dst.addr)) in ip6_rt_get_dev_rcu()
1015 dev = dev_net(dev)->loopback_dev; in ip6_rt_get_dev_rcu()
1031 [RTN_BLACKHOLE] = -EINVAL,
1032 [RTN_UNREACHABLE] = -EHOSTUNREACH,
1033 [RTN_PROHIBIT] = -EACCES,
1034 [RTN_THROW] = -EAGAIN,
1035 [RTN_NAT] = -EINVAL,
1036 [RTN_XRESOLVE] = -EINVAL,
1048 if (rt->dst_nocount) in fib6_info_dst_flags()
1050 if (rt->dst_nopolicy) in fib6_info_dst_flags()
1058 rt->dst.error = ip6_rt_type_to_error(fib6_type); in ip6_rt_init_dst_reject()
1062 rt->dst.output = dst_discard_out; in ip6_rt_init_dst_reject()
1063 rt->dst.input = dst_discard; in ip6_rt_init_dst_reject()
1066 rt->dst.output = ip6_pkt_prohibit_out; in ip6_rt_init_dst_reject()
1067 rt->dst.input = ip6_pkt_prohibit; in ip6_rt_init_dst_reject()
1072 rt->dst.output = ip6_pkt_discard_out; in ip6_rt_init_dst_reject()
1073 rt->dst.input = ip6_pkt_discard; in ip6_rt_init_dst_reject()
1080 struct fib6_info *f6i = res->f6i; in ip6_rt_init_dst()
1082 if (res->fib6_flags & RTF_REJECT) { in ip6_rt_init_dst()
1083 ip6_rt_init_dst_reject(rt, res->fib6_type); in ip6_rt_init_dst()
1087 rt->dst.error = 0; in ip6_rt_init_dst()
1088 rt->dst.output = ip6_output; in ip6_rt_init_dst()
1090 if (res->fib6_type == RTN_LOCAL || res->fib6_type == RTN_ANYCAST) { in ip6_rt_init_dst()
1091 rt->dst.input = ip6_input; in ip6_rt_init_dst()
1092 } else if (ipv6_addr_type(&f6i->fib6_dst.addr) & IPV6_ADDR_MULTICAST) { in ip6_rt_init_dst()
1093 rt->dst.input = ip6_mc_input; in ip6_rt_init_dst()
1095 rt->dst.input = ip6_forward; in ip6_rt_init_dst()
1098 if (res->nh->fib_nh_lws) { in ip6_rt_init_dst()
1099 rt->dst.lwtstate = lwtstate_get(res->nh->fib_nh_lws); in ip6_rt_init_dst()
1100 lwtunnel_set_redirect(&rt->dst); in ip6_rt_init_dst()
1103 rt->dst.lastuse = jiffies; in ip6_rt_init_dst()
1109 rt->rt6i_flags &= ~RTF_EXPIRES; in rt6_set_from()
1110 rcu_assign_pointer(rt->from, from); in rt6_set_from()
1111 ip_dst_init_metrics(&rt->dst, from->fib6_metrics); in rt6_set_from()
1117 const struct fib6_nh *nh = res->nh; in ip6_rt_copy_init()
1118 const struct net_device *dev = nh->fib_nh_dev; in ip6_rt_copy_init()
1119 struct fib6_info *f6i = res->f6i; in ip6_rt_copy_init()
1123 rt->rt6i_dst = f6i->fib6_dst; in ip6_rt_copy_init()
1124 rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL; in ip6_rt_copy_init()
1125 rt->rt6i_flags = res->fib6_flags; in ip6_rt_copy_init()
1126 if (nh->fib_nh_gw_family) { in ip6_rt_copy_init()
1127 rt->rt6i_gateway = nh->fib_nh_gw6; in ip6_rt_copy_init()
1128 rt->rt6i_flags |= RTF_GATEWAY; in ip6_rt_copy_init()
1132 rt->rt6i_src = f6i->fib6_src; in ip6_rt_copy_init()
1141 if (fn->fn_flags & RTN_TL_ROOT) in fib6_backtrack()
1143 pn = rcu_dereference(fn->parent); in fib6_backtrack()
1149 if (fn->fn_flags & RTN_RTINFO) in fib6_backtrack()
1158 if (dst_hold_safe(&rt->dst)) in ip6_hold_safe()
1161 rt = net->ipv6.ip6_null_entry; in ip6_hold_safe()
1162 dst_hold(&rt->dst); in ip6_hold_safe()
1173 struct net_device *dev = res->nh->fib_nh_dev; in ip6_create_rt_rcu()
1174 struct fib6_info *f6i = res->f6i; in ip6_create_rt_rcu()
1192 nrt = dev_net(dev)->ipv6.ip6_null_entry; in ip6_create_rt_rcu()
1193 dst_hold(&nrt->dst); in ip6_create_rt_rcu()
1207 if (fl6->flowi6_flags & FLOWI_FLAG_SKIP_NH_OIF) in ip6_pol_route_lookup()
1211 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in ip6_pol_route_lookup()
1213 res.f6i = rcu_dereference(fn->leaf); in ip6_pol_route_lookup()
1215 res.f6i = net->ipv6.fib6_null_entry; in ip6_pol_route_lookup()
1217 rt6_device_match(net, &res, &fl6->saddr, fl6->flowi6_oif, in ip6_pol_route_lookup()
1220 if (res.f6i == net->ipv6.fib6_null_entry) { in ip6_pol_route_lookup()
1221 fn = fib6_backtrack(fn, &fl6->saddr); in ip6_pol_route_lookup()
1225 rt = net->ipv6.ip6_null_entry; in ip6_pol_route_lookup()
1226 dst_hold(&rt->dst); in ip6_pol_route_lookup()
1232 fib6_select_path(net, &res, fl6, fl6->flowi6_oif, in ip6_pol_route_lookup()
1233 fl6->flowi6_oif != 0, skb, flags); in ip6_pol_route_lookup()
1236 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route_lookup()
1239 dst_use_noref(&rt->dst, jiffies); in ip6_pol_route_lookup()
1277 if (dst->error == 0) in rt6_lookup()
1286 /* ip6_ins_rt is called with FREE table->tb6_lock.
1287 * It takes new route entry, the addition fails by any reason the
1288 * route is released.
1298 table = rt->fib6_table; in __ip6_ins_rt()
1299 spin_lock_bh(&table->tb6_lock); in __ip6_ins_rt()
1300 err = fib6_add(&table->tb6_root, rt, info, extack); in __ip6_ins_rt()
1301 spin_unlock_bh(&table->tb6_lock); in __ip6_ins_rt()
1317 struct fib6_info *f6i = res->f6i; in ip6_rt_cache_alloc()
1322 * Clone the route. in ip6_rt_cache_alloc()
1336 rt->rt6i_flags |= RTF_CACHE; in ip6_rt_cache_alloc()
1337 rt->rt6i_dst.addr = *daddr; in ip6_rt_cache_alloc()
1338 rt->rt6i_dst.plen = 128; in ip6_rt_cache_alloc()
1341 if (f6i->fib6_dst.plen != 128 && in ip6_rt_cache_alloc()
1342 ipv6_addr_equal(&f6i->fib6_dst.addr, daddr)) in ip6_rt_cache_alloc()
1343 rt->rt6i_flags |= RTF_ANYCAST; in ip6_rt_cache_alloc()
1345 if (rt->rt6i_src.plen && saddr) { in ip6_rt_cache_alloc()
1346 rt->rt6i_src.addr = *saddr; in ip6_rt_cache_alloc()
1347 rt->rt6i_src.plen = 128; in ip6_rt_cache_alloc()
1357 struct fib6_info *f6i = res->f6i; in ip6_rt_pcpu_alloc()
1374 pcpu_rt->rt6i_flags |= RTF_PCPU; in ip6_rt_pcpu_alloc()
1376 if (f6i->nh) in ip6_rt_pcpu_alloc()
1377 pcpu_rt->sernum = rt_genid_ipv6(dev_net(dev)); in ip6_rt_pcpu_alloc()
1384 return rt6->sernum == rt_genid_ipv6(dev_net(rt6->dst.dev)); in rt6_is_valid()
1392 pcpu_rt = this_cpu_read(*res->nh->rt6i_pcpu); in rt6_get_pcpu_route()
1394 if (pcpu_rt && pcpu_rt->sernum && !rt6_is_valid(pcpu_rt)) { in rt6_get_pcpu_route()
1397 p = this_cpu_ptr(res->nh->rt6i_pcpu); in rt6_get_pcpu_route()
1400 dst_dev_put(&prev->dst); in rt6_get_pcpu_route()
1401 dst_release(&prev->dst); in rt6_get_pcpu_route()
1419 p = this_cpu_ptr(res->nh->rt6i_pcpu); in rt6_make_pcpu_route()
1423 if (res->f6i->fib6_destroying) { in rt6_make_pcpu_route()
1426 from = xchg((__force struct fib6_info **)&pcpu_rt->from, NULL); in rt6_make_pcpu_route()
1449 net = dev_net(rt6_ex->rt6i->dst.dev); in rt6_remove_exception()
1450 net->ipv6.rt6_stats->fib_rt_cache--; in rt6_remove_exception()
1455 from = xchg((__force struct fib6_info **)&rt6_ex->rt6i->from, NULL); in rt6_remove_exception()
1457 dst_dev_put(&rt6_ex->rt6i->dst); in rt6_remove_exception()
1459 hlist_del_rcu(&rt6_ex->hlist); in rt6_remove_exception()
1460 dst_release(&rt6_ex->rt6i->dst); in rt6_remove_exception()
1462 WARN_ON_ONCE(!bucket->depth); in rt6_remove_exception()
1463 bucket->depth--; in rt6_remove_exception()
1476 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_exception_remove_oldest()
1477 if (!oldest || time_before(rt6_ex->stamp, oldest->stamp)) in rt6_exception_remove_oldest()
1525 hlist_for_each_entry(rt6_ex, &(*bucket)->chain, hlist) { in __rt6_find_exception_spinlock()
1526 struct rt6_info *rt6 = rt6_ex->rt6i; in __rt6_find_exception_spinlock()
1527 bool matched = ipv6_addr_equal(daddr, &rt6->rt6i_dst.addr); in __rt6_find_exception_spinlock()
1531 matched = ipv6_addr_equal(saddr, &rt6->rt6i_src.addr); in __rt6_find_exception_spinlock()
1560 hlist_for_each_entry_rcu(rt6_ex, &(*bucket)->chain, hlist) { in __rt6_find_exception_rcu()
1561 struct rt6_info *rt6 = rt6_ex->rt6i; in __rt6_find_exception_rcu()
1562 bool matched = ipv6_addr_equal(daddr, &rt6->rt6i_dst.addr); in __rt6_find_exception_rcu()
1566 matched = ipv6_addr_equal(saddr, &rt6->rt6i_src.addr); in __rt6_find_exception_rcu()
1576 const struct fib6_nh *nh = res->nh; in fib6_mtu()
1579 if (res->f6i->fib6_pmtu) { in fib6_mtu()
1580 mtu = res->f6i->fib6_pmtu; in fib6_mtu()
1582 struct net_device *dev = nh->fib_nh_dev; in fib6_mtu()
1587 mtu = idev->cnf.mtu6; in fib6_mtu()
1593 return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu); in fib6_mtu()
1610 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in fib6_nh_get_excptn_bucket()
1613 bucket = rcu_dereference(nh->rt6i_exception_bucket); in fib6_nh_get_excptn_bucket()
1640 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in fib6_nh_excptn_bucket_set_flushed()
1646 rcu_assign_pointer(nh->rt6i_exception_bucket, bucket); in fib6_nh_excptn_bucket_set_flushed()
1652 struct net *net = dev_net(nrt->dst.dev); in rt6_insert_exception()
1654 struct fib6_info *f6i = res->f6i; in rt6_insert_exception()
1657 struct fib6_nh *nh = res->nh; in rt6_insert_exception()
1663 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in rt6_insert_exception()
1669 err = -ENOMEM; in rt6_insert_exception()
1672 rcu_assign_pointer(nh->rt6i_exception_bucket, bucket); in rt6_insert_exception()
1674 err = -EINVAL; in rt6_insert_exception()
1685 if (f6i->fib6_src.plen) in rt6_insert_exception()
1686 src_key = &nrt->rt6i_src.addr; in rt6_insert_exception()
1689 * Only insert this exception route if its mtu in rt6_insert_exception()
1692 if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(res)) { in rt6_insert_exception()
1693 err = -EINVAL; in rt6_insert_exception()
1697 rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr, in rt6_insert_exception()
1704 err = -ENOMEM; in rt6_insert_exception()
1707 rt6_ex->rt6i = nrt; in rt6_insert_exception()
1708 rt6_ex->stamp = jiffies; in rt6_insert_exception()
1709 hlist_add_head_rcu(&rt6_ex->hlist, &bucket->chain); in rt6_insert_exception()
1710 bucket->depth++; in rt6_insert_exception()
1711 net->ipv6.rt6_stats->fib_rt_cache++; in rt6_insert_exception()
1715 while (bucket->depth > max_depth) in rt6_insert_exception()
1721 /* Update fn->fn_sernum to invalidate all cached dst */ in rt6_insert_exception()
1723 spin_lock_bh(&f6i->fib6_table->tb6_lock); in rt6_insert_exception()
1725 spin_unlock_bh(&f6i->fib6_table->tb6_lock); in rt6_insert_exception()
1750 hlist_for_each_entry_safe(rt6_ex, tmp, &bucket->chain, hlist) { in fib6_nh_flush_exceptions()
1752 rcu_access_pointer(rt6_ex->rt6i->from) == from) in fib6_nh_flush_exceptions()
1755 WARN_ON_ONCE(!from && bucket->depth); in fib6_nh_flush_exceptions()
1773 if (f6i->nh) in rt6_flush_exceptions()
1774 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_flush_exceptions, in rt6_flush_exceptions()
1777 fib6_nh_flush_exceptions(f6i->fib6_nh, f6i); in rt6_flush_exceptions()
1799 * So we need to use f6i->fib6_src to redo lookup in rt6_find_cached_rt()
1802 * rt->rt6i_src is updated.) in rt6_find_cached_rt()
1804 if (res->f6i->fib6_src.plen) in rt6_find_cached_rt()
1808 bucket = fib6_nh_get_excptn_bucket(res->nh, NULL); in rt6_find_cached_rt()
1811 if (rt6_ex && !rt6_check_expired(rt6_ex->rt6i)) in rt6_find_cached_rt()
1812 ret = rt6_ex->rt6i; in rt6_find_cached_rt()
1816 if (!ret && src_key && src_key != &res->f6i->fib6_src.addr) { in rt6_find_cached_rt()
1817 src_key = &res->f6i->fib6_src.addr; in rt6_find_cached_rt()
1834 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_remove_exception()
1835 return -ENOENT; in fib6_nh_remove_exception()
1848 src_key = &rt->rt6i_src.addr; in fib6_nh_remove_exception()
1851 &rt->rt6i_dst.addr, in fib6_nh_remove_exception()
1857 err = -ENOENT; in fib6_nh_remove_exception()
1874 err = fib6_nh_remove_exception(nh, arg->plen, arg->rt); in rt6_nh_remove_exception_rt()
1885 from = rcu_dereference(rt->from); in rt6_remove_exception_rt()
1886 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_remove_exception_rt()
1887 return -EINVAL; in rt6_remove_exception_rt()
1889 if (from->nh) { in rt6_remove_exception_rt()
1892 .plen = from->fib6_src.plen in rt6_remove_exception_rt()
1897 rc = nexthop_for_each_fib6_nh(from->nh, in rt6_remove_exception_rt()
1900 return rc ? 0 : -ENOENT; in rt6_remove_exception_rt()
1903 return fib6_nh_remove_exception(from->fib6_nh, in rt6_remove_exception_rt()
1904 from->fib6_src.plen, rt); in rt6_remove_exception_rt()
1926 src_key = &rt->rt6i_src.addr; in fib6_nh_update_exception()
1928 rt6_ex = __rt6_find_exception_rcu(&bucket, &rt->rt6i_dst.addr, src_key); in fib6_nh_update_exception()
1930 rt6_ex->stamp = jiffies; in fib6_nh_update_exception()
1944 if (arg->dev != nh->fib_nh_dev || in fib6_nh_find_match()
1945 (arg->gw && !nh->fib_nh_gw_family) || in fib6_nh_find_match()
1946 (!arg->gw && nh->fib_nh_gw_family) || in fib6_nh_find_match()
1947 (arg->gw && !ipv6_addr_equal(arg->gw, &nh->fib_nh_gw6))) in fib6_nh_find_match()
1950 arg->match = nh; in fib6_nh_find_match()
1963 from = rcu_dereference(rt->from); in rt6_update_exception_stamp_rt()
1964 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_update_exception_stamp_rt()
1967 if (from->nh) { in rt6_update_exception_stamp_rt()
1969 .dev = rt->dst.dev, in rt6_update_exception_stamp_rt()
1970 .gw = &rt->rt6i_gateway, in rt6_update_exception_stamp_rt()
1973 nexthop_for_each_fib6_nh(from->nh, fib6_nh_find_match, &arg); in rt6_update_exception_stamp_rt()
1979 fib6_nh = from->fib6_nh; in rt6_update_exception_stamp_rt()
1981 fib6_nh_update_exception(fib6_nh, from->fib6_src.plen, rt); in rt6_update_exception_stamp_rt()
1989 /* If the new MTU is lower than the route PMTU, this new MTU will be the in rt6_mtu_change_route_allowed()
1990 * lowest MTU in the path: always allow updating the route PMTU to in rt6_mtu_change_route_allowed()
1993 * If the new MTU is higher, and the route PMTU is equal to the local in rt6_mtu_change_route_allowed()
1999 if (dst_mtu(&rt->dst) >= mtu) in rt6_mtu_change_route_allowed()
2002 if (dst_mtu(&rt->dst) == idev->cnf.mtu6) in rt6_mtu_change_route_allowed()
2020 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_exceptions_update_pmtu()
2021 struct rt6_info *entry = rt6_ex->rt6i; in rt6_exceptions_update_pmtu()
2024 * route), the metrics of its rt->from have already in rt6_exceptions_update_pmtu()
2027 if (dst_metric_raw(&entry->dst, RTAX_MTU) && in rt6_exceptions_update_pmtu()
2029 dst_metric_set(&entry->dst, RTAX_MTU, mtu); in rt6_exceptions_update_pmtu()
2045 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_exceptions_clean_tohost()
2053 &bucket->chain, hlist) { in fib6_nh_exceptions_clean_tohost()
2054 struct rt6_info *entry = rt6_ex->rt6i; in fib6_nh_exceptions_clean_tohost()
2056 if ((entry->rt6i_flags & RTF_CACHE_GATEWAY) == in fib6_nh_exceptions_clean_tohost()
2059 &entry->rt6i_gateway)) { in fib6_nh_exceptions_clean_tohost()
2075 struct rt6_info *rt = rt6_ex->rt6i; in rt6_age_examine_exception()
2077 /* we are pruning and obsoleting aged-out and non gateway exceptions in rt6_age_examine_exception()
2080 * EXPIRES exceptions - e.g. pmtu-generated ones are pruned when in rt6_age_examine_exception()
2083 if (!(rt->rt6i_flags & RTF_EXPIRES)) { in rt6_age_examine_exception()
2084 if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) { in rt6_age_examine_exception()
2089 } else if (time_after(jiffies, rt->dst.expires)) { in rt6_age_examine_exception()
2090 RT6_TRACE("purging expired route %p\n", rt); in rt6_age_examine_exception()
2095 if (rt->rt6i_flags & RTF_GATEWAY) { in rt6_age_examine_exception()
2099 neigh = __ipv6_neigh_lookup_noref(rt->dst.dev, &rt->rt6i_gateway); in rt6_age_examine_exception()
2101 neigh_flags = neigh->flags; in rt6_age_examine_exception()
2104 RT6_TRACE("purging route %p via non-router but gateway\n", in rt6_age_examine_exception()
2111 gc_args->more++; in rt6_age_examine_exception()
2123 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_age_exceptions()
2132 &bucket->chain, hlist) { in fib6_nh_age_exceptions()
2152 fib6_nh_age_exceptions(nh, arg->gc_args, arg->now); in rt6_nh_age_exceptions()
2160 if (f6i->nh) { in rt6_age_exceptions()
2166 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_age_exceptions, in rt6_age_exceptions()
2169 fib6_nh_age_exceptions(f6i->fib6_nh, gc_args, now); in rt6_age_exceptions()
2179 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in fib6_table_lookup()
2182 if (fl6->flowi6_flags & FLOWI_FLAG_SKIP_NH_OIF) in fib6_table_lookup()
2187 if (res->f6i == net->ipv6.fib6_null_entry) { in fib6_table_lookup()
2188 fn = fib6_backtrack(fn, &fl6->saddr); in fib6_table_lookup()
2192 /* also consider unreachable route */ in fib6_table_lookup()
2217 if (net->ipv6.devconf_all->forwarding == 0) in ip6_pol_route()
2223 if (res.f6i == net->ipv6.fib6_null_entry) in ip6_pol_route()
2229 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route()
2232 } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) && in ip6_pol_route()
2233 !res.nh->fib_nh_gw_family)) { in ip6_pol_route()
2236 * the daddr in the skb during the neighbor look-up is different in ip6_pol_route()
2237 * from the fl6->daddr used to look-up route here. in ip6_pol_route()
2239 rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL); in ip6_pol_route()
2248 atomic_inc(&net->ipv6.rt6_stats->fib_rt_uncache); in ip6_pol_route()
2265 rt = net->ipv6.ip6_null_entry; in ip6_pol_route()
2280 return ip6_pol_route(net, table, fl6->flowi6_iif, fl6, skb, flags); in ip6_pol_route_input()
2289 if (rt6_need_strict(&fl6->daddr) && dev->type != ARPHRD_PIMREG) in ip6_route_input_lookup()
2308 if (likely(outer_iph->nexthdr != IPPROTO_ICMPV6)) in ip6_multipath_l3_keys()
2316 if (!icmpv6_is_err(icmph->icmp6_type)) in ip6_multipath_l3_keys()
2329 keys->addrs.v6addrs.src = _flkeys->addrs.v6addrs.src; in ip6_multipath_l3_keys()
2330 keys->addrs.v6addrs.dst = _flkeys->addrs.v6addrs.dst; in ip6_multipath_l3_keys()
2331 keys->tags.flow_label = _flkeys->tags.flow_label; in ip6_multipath_l3_keys()
2332 keys->basic.ip_proto = _flkeys->basic.ip_proto; in ip6_multipath_l3_keys()
2334 keys->addrs.v6addrs.src = key_iph->saddr; in ip6_multipath_l3_keys()
2335 keys->addrs.v6addrs.dst = key_iph->daddr; in ip6_multipath_l3_keys()
2336 keys->tags.flow_label = ip6_flowlabel(key_iph); in ip6_multipath_l3_keys()
2337 keys->basic.ip_proto = key_iph->nexthdr; in ip6_multipath_l3_keys()
2355 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2356 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2358 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2366 /* short-circuit if we already have L4 hash present */ in rt6_multipath_hash()
2367 if (skb->l4_hash) in rt6_multipath_hash()
2377 hash_keys.addrs.v6addrs.src = flkeys->addrs.v6addrs.src; in rt6_multipath_hash()
2378 hash_keys.addrs.v6addrs.dst = flkeys->addrs.v6addrs.dst; in rt6_multipath_hash()
2379 hash_keys.ports.src = flkeys->ports.src; in rt6_multipath_hash()
2380 hash_keys.ports.dst = flkeys->ports.dst; in rt6_multipath_hash()
2381 hash_keys.basic.ip_proto = flkeys->basic.ip_proto; in rt6_multipath_hash()
2385 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2386 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2387 hash_keys.ports.src = fl6->fl6_sport; in rt6_multipath_hash()
2388 hash_keys.ports.dst = fl6->fl6_dport; in rt6_multipath_hash()
2389 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2404 if (flkeys->control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) { in rt6_multipath_hash()
2406 hash_keys.addrs.v4addrs.src = flkeys->addrs.v4addrs.src; in rt6_multipath_hash()
2407 hash_keys.addrs.v4addrs.dst = flkeys->addrs.v4addrs.dst; in rt6_multipath_hash()
2408 } else if (flkeys->control.addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) { in rt6_multipath_hash()
2410 hash_keys.addrs.v6addrs.src = flkeys->addrs.v6addrs.src; in rt6_multipath_hash()
2411 hash_keys.addrs.v6addrs.dst = flkeys->addrs.v6addrs.dst; in rt6_multipath_hash()
2412 hash_keys.tags.flow_label = flkeys->tags.flow_label; in rt6_multipath_hash()
2413 hash_keys.basic.ip_proto = flkeys->basic.ip_proto; in rt6_multipath_hash()
2422 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2423 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2425 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2438 struct net *net = dev_net(skb->dev); in ip6_route_input()
2442 .flowi6_iif = skb->dev->ifindex, in ip6_route_input()
2443 .daddr = iph->daddr, in ip6_route_input()
2444 .saddr = iph->saddr, in ip6_route_input()
2446 .flowi6_mark = skb->mark, in ip6_route_input()
2447 .flowi6_proto = iph->nexthdr, in ip6_route_input()
2452 if (tun_info && !(tun_info->mode & IP_TUNNEL_INFO_TX)) in ip6_route_input()
2453 fl6.flowi6_tun_key.tun_id = tun_info->key.tun_id; in ip6_route_input()
2461 skb_dst_set_noref(skb, ip6_route_input_lookup(net, skb->dev, in ip6_route_input()
2471 return ip6_pol_route(net, table, fl6->flowi6_oif, fl6, skb, flags); in ip6_pol_route_output()
2480 if (ipv6_addr_type(&fl6->daddr) & in ip6_route_output_flags_noref()
2490 fl6->flowi6_iif = LOOPBACK_IFINDEX; in ip6_route_output_flags_noref()
2493 any_src = ipv6_addr_any(&fl6->saddr); in ip6_route_output_flags_noref()
2494 if ((sk && sk->sk_bound_dev_if) || rt6_need_strict(&fl6->daddr) || in ip6_route_output_flags_noref()
2495 (fl6->flowi6_oif && any_src)) in ip6_route_output_flags_noref()
2501 flags |= rt6_srcprefs2flags(inet6_sk(sk)->srcprefs); in ip6_route_output_flags_noref()
2519 if (list_empty(&rt6->rt6i_uncached) && !dst_hold_safe(dst)) { in ip6_route_output_flags()
2520 dst = &net->ipv6.ip6_null_entry->dst; in ip6_route_output_flags()
2532 struct net_device *loopback_dev = net->loopback_dev; in ip6_blackhole_route()
2539 atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc); in ip6_blackhole_route()
2541 new = &rt->dst; in ip6_blackhole_route()
2542 new->__use = 1; in ip6_blackhole_route()
2543 new->input = dst_discard; in ip6_blackhole_route()
2544 new->output = dst_discard_out; in ip6_blackhole_route()
2546 dst_copy_metrics(new, &ort->dst); in ip6_blackhole_route()
2548 rt->rt6i_idev = in6_dev_get(loopback_dev); in ip6_blackhole_route()
2549 rt->rt6i_gateway = ort->rt6i_gateway; in ip6_blackhole_route()
2550 rt->rt6i_flags = ort->rt6i_flags & ~RTF_PCPU; in ip6_blackhole_route()
2552 memcpy(&rt->rt6i_dst, &ort->rt6i_dst, sizeof(struct rt6key)); in ip6_blackhole_route()
2554 memcpy(&rt->rt6i_src, &ort->rt6i_src, sizeof(struct rt6key)); in ip6_blackhole_route()
2559 return new ? new : ERR_PTR(-ENOMEM); in ip6_blackhole_route()
2592 return &rt->dst; in rt6_check()
2600 rt->dst.obsolete == DST_OBSOLETE_FORCE_CHK && in rt6_dst_from_check()
2602 return &rt->dst; in rt6_dst_from_check()
2615 if (rt->sernum) in ip6_dst_check()
2620 /* All IPV6 dsts are created with ->obsolete set to the value in ip6_dst_check()
2625 from = rcu_dereference(rt->from); in ip6_dst_check()
2627 if (from && (rt->rt6i_flags & RTF_PCPU || in ip6_dst_check()
2628 unlikely(!list_empty(&rt->rt6i_uncached)))) in ip6_dst_check()
2643 if (rt->rt6i_flags & RTF_CACHE) { in ip6_negative_advice()
2667 if (rt->rt6i_flags & RTF_CACHE) { in ip6_link_failure()
2673 from = rcu_dereference(rt->from); in ip6_link_failure()
2675 fn = rcu_dereference(from->fib6_node); in ip6_link_failure()
2676 if (fn && (rt->rt6i_flags & RTF_DEFAULT)) in ip6_link_failure()
2677 WRITE_ONCE(fn->fn_sernum, -1); in ip6_link_failure()
2686 if (!(rt0->rt6i_flags & RTF_EXPIRES)) { in rt6_update_expires()
2690 from = rcu_dereference(rt0->from); in rt6_update_expires()
2692 rt0->dst.expires = from->expires; in rt6_update_expires()
2696 dst_set_expires(&rt0->dst, timeout); in rt6_update_expires()
2697 rt0->rt6i_flags |= RTF_EXPIRES; in rt6_update_expires()
2702 struct net *net = dev_net(rt->dst.dev); in rt6_do_update_pmtu()
2704 dst_metric_set(&rt->dst, RTAX_MTU, mtu); in rt6_do_update_pmtu()
2705 rt->rt6i_flags |= RTF_MODIFIED; in rt6_do_update_pmtu()
2706 rt6_update_expires(rt, net->ipv6.sysctl.ip6_rt_mtu_expires); in rt6_do_update_pmtu()
2711 return !(rt->rt6i_flags & RTF_CACHE) && in rt6_cache_allowed_for_pmtu()
2712 (rt->rt6i_flags & RTF_PCPU || rcu_access_pointer(rt->from)); in rt6_cache_allowed_for_pmtu()
2728 daddr = &iph->daddr; in __ip6_rt_update_pmtu()
2729 saddr = &iph->saddr; in __ip6_rt_update_pmtu()
2731 daddr = &sk->sk_v6_daddr; in __ip6_rt_update_pmtu()
2732 saddr = &inet6_sk(sk)->saddr; in __ip6_rt_update_pmtu()
2748 /* update rt6_ex->stamp for cache */ in __ip6_rt_update_pmtu()
2749 if (rt6->rt6i_flags & RTF_CACHE) in __ip6_rt_update_pmtu()
2756 res.f6i = rcu_dereference(rt6->from); in __ip6_rt_update_pmtu()
2760 res.fib6_flags = res.f6i->fib6_flags; in __ip6_rt_update_pmtu()
2761 res.fib6_type = res.f6i->fib6_type; in __ip6_rt_update_pmtu()
2763 if (res.f6i->nh) { in __ip6_rt_update_pmtu()
2765 .dev = dst->dev, in __ip6_rt_update_pmtu()
2766 .gw = &rt6->rt6i_gateway, in __ip6_rt_update_pmtu()
2769 nexthop_for_each_fib6_nh(res.f6i->nh, in __ip6_rt_update_pmtu()
2773 * using the dst->dev + gw. Should be impossible. in __ip6_rt_update_pmtu()
2780 res.nh = res.f6i->fib6_nh; in __ip6_rt_update_pmtu()
2787 dst_release_immediate(&nrt6->dst); in __ip6_rt_update_pmtu()
2805 const struct ipv6hdr *iph = (struct ipv6hdr *) skb->data; in ip6_update_pmtu()
2809 .flowi6_mark = mark ? mark : IP6_REPLY_MARK(net, skb->mark), in ip6_update_pmtu()
2810 .daddr = iph->daddr, in ip6_update_pmtu()
2811 .saddr = iph->saddr, in ip6_update_pmtu()
2817 if (!dst->error) in ip6_update_pmtu()
2825 int oif = sk->sk_bound_dev_if; in ip6_sk_update_pmtu()
2828 if (!oif && skb->dev) in ip6_sk_update_pmtu()
2829 oif = l3mdev_master_ifindex(skb->dev); in ip6_sk_update_pmtu()
2831 ip6_update_pmtu(skb, sock_net(sk), mtu, oif, sk->sk_mark, sk->sk_uid); in ip6_sk_update_pmtu()
2834 if (!dst || !dst->obsolete || in ip6_sk_update_pmtu()
2835 dst->ops->check(dst, inet6_sk(sk)->dst_cookie)) in ip6_sk_update_pmtu()
2839 if (!sock_owned_by_user(sk) && !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) in ip6_sk_update_pmtu()
2853 ipv6_addr_equal(&fl6->daddr, &sk->sk_v6_daddr) ? in ip6_sk_dst_store_flow()
2854 &sk->sk_v6_daddr : NULL, in ip6_sk_dst_store_flow()
2856 ipv6_addr_equal(&fl6->saddr, &np->saddr) ? in ip6_sk_dst_store_flow()
2857 &np->saddr : in ip6_sk_dst_store_flow()
2867 const struct fib6_nh *nh = res->nh; in ip6_redirect_nh_match()
2869 if (nh->fib_nh_flags & RTNH_F_DEAD || !nh->fib_nh_gw_family || in ip6_redirect_nh_match()
2870 fl6->flowi6_oif != nh->fib_nh_dev->ifindex) in ip6_redirect_nh_match()
2878 if (!ipv6_addr_equal(gw, &nh->fib_nh_gw6)) { in ip6_redirect_nh_match()
2881 rt_cache = rt6_find_cached_rt(res, &fl6->daddr, &fl6->saddr); in ip6_redirect_nh_match()
2883 ipv6_addr_equal(gw, &rt_cache->rt6i_gateway)) { in ip6_redirect_nh_match()
2903 arg->res->nh = nh; in fib6_nh_redirect_match()
2904 return ip6_redirect_nh_match(arg->res, arg->fl6, arg->gw, arg->ret); in fib6_nh_redirect_match()
2925 .gw = &rdfl->gateway, in __ip6_route_redirect()
2934 if (fl6->flowi6_flags & FLOWI_FLAG_SKIP_NH_OIF) in __ip6_route_redirect()
2935 fl6->flowi6_oif = skb->dev->ifindex; in __ip6_route_redirect()
2937 /* Get the "current" route for this destination and in __ip6_route_redirect()
2948 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in __ip6_route_redirect()
2954 if (rt->fib6_flags & RTF_REJECT) in __ip6_route_redirect()
2956 if (unlikely(rt->nh)) { in __ip6_route_redirect()
2957 if (nexthop_is_blackhole(rt->nh)) in __ip6_route_redirect()
2959 /* on match, res->nh is filled in and potentially ret */ in __ip6_route_redirect()
2960 if (nexthop_for_each_fib6_nh(rt->nh, in __ip6_route_redirect()
2965 res.nh = rt->fib6_nh; in __ip6_route_redirect()
2966 if (ip6_redirect_nh_match(&res, fl6, &rdfl->gateway, in __ip6_route_redirect()
2973 rt = net->ipv6.fib6_null_entry; in __ip6_route_redirect()
2974 else if (rt->fib6_flags & RTF_REJECT) { in __ip6_route_redirect()
2975 ret = net->ipv6.ip6_null_entry; in __ip6_route_redirect()
2979 if (rt == net->ipv6.fib6_null_entry) { in __ip6_route_redirect()
2980 fn = fib6_backtrack(fn, &fl6->saddr); in __ip6_route_redirect()
2986 res.nh = rt->fib6_nh; in __ip6_route_redirect()
2991 res.fib6_flags = res.f6i->fib6_flags; in __ip6_route_redirect()
2992 res.fib6_type = res.f6i->fib6_type; in __ip6_route_redirect()
3020 const struct ipv6hdr *iph = (struct ipv6hdr *) skb->data; in ip6_redirect()
3026 .daddr = iph->daddr, in ip6_redirect()
3027 .saddr = iph->saddr, in ip6_redirect()
3032 dst = ip6_route_redirect(net, &fl6, skb, &ipv6_hdr(skb)->saddr); in ip6_redirect()
3046 .daddr = msg->dest, in ip6_redirect_no_header()
3047 .saddr = iph->daddr, in ip6_redirect_no_header()
3051 dst = ip6_route_redirect(net, &fl6, skb, &iph->saddr); in ip6_redirect_no_header()
3058 ip6_redirect(skb, sock_net(sk), sk->sk_bound_dev_if, sk->sk_mark, in ip6_sk_redirect()
3059 sk->sk_uid); in ip6_sk_redirect()
3065 struct net_device *dev = dst->dev; in ip6_default_advmss()
3069 mtu -= sizeof(struct ipv6hdr) + sizeof(struct tcphdr); in ip6_default_advmss()
3071 if (mtu < net->ipv6.sysctl.ip6_rt_min_advmss) in ip6_default_advmss()
3072 mtu = net->ipv6.sysctl.ip6_rt_min_advmss; in ip6_default_advmss()
3075 * Maximal non-jumbo IPv6 payload is IPV6_MAXPLEN and in ip6_default_advmss()
3076 * corresponding MSS is IPV6_MAXPLEN - tcp_header_size. in ip6_default_advmss()
3080 if (mtu > IPV6_MAXPLEN - sizeof(struct tcphdr)) in ip6_default_advmss()
3097 idev = __in6_dev_get(dst->dev); in ip6_mtu()
3099 mtu = idev->cnf.mtu6; in ip6_mtu()
3105 return mtu - lwtunnel_headroom(dst->lwtstate, mtu); in ip6_mtu()
3109 * 1. mtu on route is locked - use it
3120 const struct fib6_nh *nh = res->nh; in ip6_mtu_from_fib6()
3121 struct fib6_info *f6i = res->f6i; in ip6_mtu_from_fib6()
3127 mtu = f6i->fib6_pmtu; in ip6_mtu_from_fib6()
3134 mtu = dst_metric_raw(&rt->dst, RTAX_MTU); in ip6_mtu_from_fib6()
3136 struct net_device *dev = nh->fib_nh_dev; in ip6_mtu_from_fib6()
3140 if (idev && idev->cnf.mtu6 > mtu) in ip6_mtu_from_fib6()
3141 mtu = idev->cnf.mtu6; in ip6_mtu_from_fib6()
3146 return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu); in ip6_mtu_from_fib6()
3158 return ERR_PTR(-ENODEV); in icmp6_dst_alloc()
3163 dst = ERR_PTR(-ENOMEM); in icmp6_dst_alloc()
3167 rt->dst.input = ip6_input; in icmp6_dst_alloc()
3168 rt->dst.output = ip6_output; in icmp6_dst_alloc()
3169 rt->rt6i_gateway = fl6->daddr; in icmp6_dst_alloc()
3170 rt->rt6i_dst.addr = fl6->daddr; in icmp6_dst_alloc()
3171 rt->rt6i_dst.plen = 128; in icmp6_dst_alloc()
3172 rt->rt6i_idev = idev; in icmp6_dst_alloc()
3173 dst_metric_set(&rt->dst, RTAX_HOPLIMIT, 0); in icmp6_dst_alloc()
3179 atomic_inc(&net->ipv6.rt6_stats->fib_rt_uncache); in icmp6_dst_alloc()
3181 dst = xfrm_lookup(net, &rt->dst, flowi6_to_flowi(fl6), NULL, 0); in icmp6_dst_alloc()
3190 int rt_min_interval = net->ipv6.sysctl.ip6_rt_gc_min_interval; in ip6_dst_gc()
3191 int rt_max_size = net->ipv6.sysctl.ip6_rt_max_size; in ip6_dst_gc()
3192 int rt_elasticity = net->ipv6.sysctl.ip6_rt_gc_elasticity; in ip6_dst_gc()
3193 int rt_gc_timeout = net->ipv6.sysctl.ip6_rt_gc_timeout; in ip6_dst_gc()
3194 unsigned long rt_last_gc = net->ipv6.ip6_rt_last_gc; in ip6_dst_gc()
3205 net->ipv6.ip6_rt_gc_expire++; in ip6_dst_gc()
3206 fib6_run_gc(net->ipv6.ip6_rt_gc_expire, net, true); in ip6_dst_gc()
3208 if (entries < ops->gc_thresh) in ip6_dst_gc()
3209 net->ipv6.ip6_rt_gc_expire = rt_gc_timeout>>1; in ip6_dst_gc()
3211 net->ipv6.ip6_rt_gc_expire -= net->ipv6.ip6_rt_gc_expire>>rt_elasticity; in ip6_dst_gc()
3220 .flowi6_oif = cfg->fc_ifindex, in ip6_nh_lookup_table()
3222 .saddr = cfg->fc_prefsrc, in ip6_nh_lookup_table()
3229 return -EINVAL; in ip6_nh_lookup_table()
3231 if (!ipv6_addr_any(&cfg->fc_prefsrc)) in ip6_nh_lookup_table()
3236 err = fib6_table_lookup(net, table, cfg->fc_ifindex, &fl6, res, flags); in ip6_nh_lookup_table()
3237 if (!err && res->f6i != net->ipv6.fib6_null_entry) in ip6_nh_lookup_table()
3238 fib6_select_path(net, res, &fl6, cfg->fc_ifindex, in ip6_nh_lookup_table()
3239 cfg->fc_ifindex != 0, NULL, flags); in ip6_nh_lookup_table()
3250 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_route_check_nh_onlink()
3256 /* ignore match if it is the default route */ in ip6_route_check_nh_onlink()
3257 !ipv6_addr_any(&res.f6i->fib6_dst.addr) && in ip6_route_check_nh_onlink()
3258 (res.fib6_type != RTN_UNICAST || dev != res.nh->fib_nh_dev)) { in ip6_route_check_nh_onlink()
3261 err = -EINVAL; in ip6_route_check_nh_onlink()
3272 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_route_check_nh()
3276 int err = -EHOSTUNREACH; in ip6_route_check_nh()
3278 if (cfg->fc_table) { in ip6_route_check_nh()
3280 cfg->fc_table, flags, &res); in ip6_route_check_nh()
3282 * route. If a device is given, it must match the result. in ip6_route_check_nh()
3285 res.nh->fib_nh_gw_family || in ip6_route_check_nh()
3286 (dev && dev != res.nh->fib_nh_dev)) in ip6_route_check_nh()
3287 err = -EHOSTUNREACH; in ip6_route_check_nh()
3292 .flowi6_oif = cfg->fc_ifindex, in ip6_route_check_nh()
3296 err = fib6_lookup(net, cfg->fc_ifindex, &fl6, &res, flags); in ip6_route_check_nh()
3298 res.nh->fib_nh_gw_family) in ip6_route_check_nh()
3299 err = -EHOSTUNREACH; in ip6_route_check_nh()
3304 fib6_select_path(net, &res, &fl6, cfg->fc_ifindex, in ip6_route_check_nh()
3305 cfg->fc_ifindex != 0, NULL, flags); in ip6_route_check_nh()
3310 if (dev != res.nh->fib_nh_dev) in ip6_route_check_nh()
3311 err = -EHOSTUNREACH; in ip6_route_check_nh()
3313 *_dev = dev = res.nh->fib_nh_dev; in ip6_route_check_nh()
3325 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_validate_gw()
3330 int err = -EINVAL; in ip6_validate_gw()
3334 * will return already-added prefix route via interface that in ip6_validate_gw()
3335 * prefix route was assigned to, which might be non-loopback. in ip6_validate_gw()
3344 /* IPv6 strictly inhibits using not link-local in ip6_validate_gw()
3348 * (SIT, PtP, NBMA NOARP links) it is handy to allow in ip6_validate_gw()
3349 * some exceptions. --ANK in ip6_validate_gw()
3350 * We allow IPv4-mapped nexthops to support RFC4798-type in ip6_validate_gw()
3360 if (cfg->fc_flags & RTNH_F_ONLINK) in ip6_validate_gw()
3374 err = -EINVAL; in ip6_validate_gw()
3378 } else if (dev->flags & IFF_LOOPBACK) { in ip6_validate_gw()
3380 "Egress device can not be loopback device for this route"); in ip6_validate_gw()
3401 (dev && (dev->flags & IFF_LOOPBACK) && in fib6_is_reject()
3418 fib6_nh->fib_nh_family = AF_INET6; in fib6_nh_init()
3420 fib6_nh->last_probe = jiffies; in fib6_nh_init()
3422 if (cfg->fc_is_fdb) { in fib6_nh_init()
3423 fib6_nh->fib_nh_gw6 = cfg->fc_gateway; in fib6_nh_init()
3424 fib6_nh->fib_nh_gw_family = AF_INET6; in fib6_nh_init()
3428 err = -ENODEV; in fib6_nh_init()
3429 if (cfg->fc_ifindex) { in fib6_nh_init()
3430 dev = dev_get_by_index(net, cfg->fc_ifindex); in fib6_nh_init()
3438 if (cfg->fc_flags & RTNH_F_ONLINK) { in fib6_nh_init()
3445 if (!(dev->flags & IFF_UP)) { in fib6_nh_init()
3447 err = -ENETDOWN; in fib6_nh_init()
3451 fib6_nh->fib_nh_flags |= RTNH_F_ONLINK; in fib6_nh_init()
3454 fib6_nh->fib_nh_weight = 1; in fib6_nh_init()
3459 addr_type = ipv6_addr_type(&cfg->fc_dst); in fib6_nh_init()
3460 if (fib6_is_reject(cfg->fc_flags, dev, addr_type)) { in fib6_nh_init()
3462 if (dev != net->loopback_dev) { in fib6_nh_init()
3467 dev = net->loopback_dev; in fib6_nh_init()
3471 err = -ENODEV; in fib6_nh_init()
3478 if (cfg->fc_flags & RTF_GATEWAY) { in fib6_nh_init()
3483 fib6_nh->fib_nh_gw6 = cfg->fc_gateway; in fib6_nh_init()
3484 fib6_nh->fib_nh_gw_family = AF_INET6; in fib6_nh_init()
3487 err = -ENODEV; in fib6_nh_init()
3491 if (idev->cnf.disable_ipv6) { in fib6_nh_init()
3493 err = -EACCES; in fib6_nh_init()
3497 if (!(dev->flags & IFF_UP) && !cfg->fc_ignore_dev_down) { in fib6_nh_init()
3499 err = -ENETDOWN; in fib6_nh_init()
3503 if (!(cfg->fc_flags & (RTF_LOCAL | RTF_ANYCAST)) && in fib6_nh_init()
3505 fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib6_nh_init()
3507 err = fib_nh_common_init(net, &fib6_nh->nh_common, cfg->fc_encap, in fib6_nh_init()
3508 cfg->fc_encap_type, cfg, gfp_flags, extack); in fib6_nh_init()
3513 fib6_nh->rt6i_pcpu = alloc_percpu_gfp(struct rt6_info *, gfp_flags); in fib6_nh_init()
3514 if (!fib6_nh->rt6i_pcpu) { in fib6_nh_init()
3515 err = -ENOMEM; in fib6_nh_init()
3519 fib6_nh->fib_nh_dev = dev; in fib6_nh_init()
3520 fib6_nh->fib_nh_oif = dev->ifindex; in fib6_nh_init()
3527 lwtstate_put(fib6_nh->fib_nh_lws); in fib6_nh_init()
3528 fib6_nh->fib_nh_lws = NULL; in fib6_nh_init()
3545 rcu_assign_pointer(fib6_nh->rt6i_exception_bucket, NULL); in fib6_nh_release()
3551 if (fib6_nh->rt6i_pcpu) { in fib6_nh_release()
3558 ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu); in fib6_nh_release()
3561 dst_dev_put(&pcpu_rt->dst); in fib6_nh_release()
3562 dst_release(&pcpu_rt->dst); in fib6_nh_release()
3567 free_percpu(fib6_nh->rt6i_pcpu); in fib6_nh_release()
3570 fib_nh_common_release(&fib6_nh->nh_common); in fib6_nh_release()
3577 if (!fib6_nh->rt6i_pcpu) in fib6_nh_release_dsts()
3583 ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu); in fib6_nh_release_dsts()
3586 dst_dev_put(&pcpu_rt->dst); in fib6_nh_release_dsts()
3587 dst_release(&pcpu_rt->dst); in fib6_nh_release_dsts()
3596 struct net *net = cfg->fc_nlinfo.nl_net; in ip6_route_info_create()
3601 int err = -EINVAL; in ip6_route_info_create()
3605 if (cfg->fc_flags & RTF_PCPU) { in ip6_route_info_create()
3611 if (cfg->fc_flags & RTF_CACHE) { in ip6_route_info_create()
3616 if (cfg->fc_type > RTN_MAX) { in ip6_route_info_create()
3617 NL_SET_ERR_MSG(extack, "Invalid route type"); in ip6_route_info_create()
3621 if (cfg->fc_dst_len > 128) { in ip6_route_info_create()
3625 if (cfg->fc_src_len > 128) { in ip6_route_info_create()
3630 if (cfg->fc_src_len) { in ip6_route_info_create()
3636 if (cfg->fc_nh_id) { in ip6_route_info_create()
3637 nh = nexthop_find_by_id(net, cfg->fc_nh_id); in ip6_route_info_create()
3647 err = -ENOBUFS; in ip6_route_info_create()
3648 if (cfg->fc_nlinfo.nlh && in ip6_route_info_create()
3649 !(cfg->fc_nlinfo.nlh->nlmsg_flags & NLM_F_CREATE)) { in ip6_route_info_create()
3650 table = fib6_get_table(net, cfg->fc_table); in ip6_route_info_create()
3652 pr_warn("NLM_F_CREATE should be specified when creating new route\n"); in ip6_route_info_create()
3653 table = fib6_new_table(net, cfg->fc_table); in ip6_route_info_create()
3656 table = fib6_new_table(net, cfg->fc_table); in ip6_route_info_create()
3662 err = -ENOMEM; in ip6_route_info_create()
3667 rt->fib6_metrics = ip_fib_metrics_init(net, cfg->fc_mx, cfg->fc_mx_len, in ip6_route_info_create()
3669 if (IS_ERR(rt->fib6_metrics)) { in ip6_route_info_create()
3670 err = PTR_ERR(rt->fib6_metrics); in ip6_route_info_create()
3672 rt->fib6_metrics = (struct dst_metrics *)&dst_default_metrics; in ip6_route_info_create()
3676 if (cfg->fc_flags & RTF_ADDRCONF) in ip6_route_info_create()
3677 rt->dst_nocount = true; in ip6_route_info_create()
3679 if (cfg->fc_flags & RTF_EXPIRES) in ip6_route_info_create()
3681 clock_t_to_jiffies(cfg->fc_expires)); in ip6_route_info_create()
3685 if (cfg->fc_protocol == RTPROT_UNSPEC) in ip6_route_info_create()
3686 cfg->fc_protocol = RTPROT_BOOT; in ip6_route_info_create()
3687 rt->fib6_protocol = cfg->fc_protocol; in ip6_route_info_create()
3689 rt->fib6_table = table; in ip6_route_info_create()
3690 rt->fib6_metric = cfg->fc_metric; in ip6_route_info_create()
3691 rt->fib6_type = cfg->fc_type ? : RTN_UNICAST; in ip6_route_info_create()
3692 rt->fib6_flags = cfg->fc_flags & ~RTF_GATEWAY; in ip6_route_info_create()
3694 ipv6_addr_prefix(&rt->fib6_dst.addr, &cfg->fc_dst, cfg->fc_dst_len); in ip6_route_info_create()
3695 rt->fib6_dst.plen = cfg->fc_dst_len; in ip6_route_info_create()
3698 ipv6_addr_prefix(&rt->fib6_src.addr, &cfg->fc_src, cfg->fc_src_len); in ip6_route_info_create()
3699 rt->fib6_src.plen = cfg->fc_src_len; in ip6_route_info_create()
3702 if (rt->fib6_src.plen) { in ip6_route_info_create()
3710 rt->nh = nh; in ip6_route_info_create()
3711 fib6_nh = nexthop_fib6_nh(rt->nh); in ip6_route_info_create()
3713 err = fib6_nh_init(net, rt->fib6_nh, cfg, gfp_flags, extack); in ip6_route_info_create()
3717 fib6_nh = rt->fib6_nh; in ip6_route_info_create()
3722 addr_type = ipv6_addr_type(&cfg->fc_dst); in ip6_route_info_create()
3723 if (fib6_is_reject(cfg->fc_flags, rt->fib6_nh->fib_nh_dev, in ip6_route_info_create()
3725 rt->fib6_flags = RTF_REJECT | RTF_NONEXTHOP; in ip6_route_info_create()
3728 if (!ipv6_addr_any(&cfg->fc_prefsrc)) { in ip6_route_info_create()
3729 struct net_device *dev = fib6_nh->fib_nh_dev; in ip6_route_info_create()
3731 if (!ipv6_chk_addr(net, &cfg->fc_prefsrc, dev, 0)) { in ip6_route_info_create()
3733 err = -EINVAL; in ip6_route_info_create()
3736 rt->fib6_prefsrc.addr = cfg->fc_prefsrc; in ip6_route_info_create()
3737 rt->fib6_prefsrc.plen = 128; in ip6_route_info_create()
3739 rt->fib6_prefsrc.plen = 0; in ip6_route_info_create()
3746 ip_fib_metrics_put(rt->fib6_metrics); in ip6_route_info_create()
3761 err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, extack); in ip6_route_add()
3769 struct net *net = info->nl_net; in __ip6_del_rt()
3773 if (rt == net->ipv6.fib6_null_entry) { in __ip6_del_rt()
3774 err = -ENOENT; in __ip6_del_rt()
3778 table = rt->fib6_table; in __ip6_del_rt()
3779 spin_lock_bh(&table->tb6_lock); in __ip6_del_rt()
3781 spin_unlock_bh(&table->tb6_lock); in __ip6_del_rt()
3800 struct nl_info *info = &cfg->fc_nlinfo; in __ip6_del_rt_siblings()
3801 struct net *net = info->nl_net; in __ip6_del_rt_siblings()
3804 int err = -ENOENT; in __ip6_del_rt_siblings()
3806 if (rt == net->ipv6.fib6_null_entry) in __ip6_del_rt_siblings()
3808 table = rt->fib6_table; in __ip6_del_rt_siblings()
3809 spin_lock_bh(&table->tb6_lock); in __ip6_del_rt_siblings()
3811 if (rt->fib6_nsiblings && cfg->fc_delete_all_nh) { in __ip6_del_rt_siblings()
3818 u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in __ip6_del_rt_siblings()
3822 info->portid, seq, 0) < 0) { in __ip6_del_rt_siblings()
3826 info->skip_notify = 1; in __ip6_del_rt_siblings()
3829 /* 'rt' points to the first sibling route. If it is not the in __ip6_del_rt_siblings()
3831 * we need to check if the last sibling has a next route or not in __ip6_del_rt_siblings()
3834 info->skip_notify_kernel = 1; in __ip6_del_rt_siblings()
3835 fn = rcu_dereference_protected(rt->fib6_node, in __ip6_del_rt_siblings()
3836 lockdep_is_held(&table->tb6_lock)); in __ip6_del_rt_siblings()
3837 if (rcu_access_pointer(fn->leaf) == rt) { in __ip6_del_rt_siblings()
3840 last_sibling = list_last_entry(&rt->fib6_siblings, in __ip6_del_rt_siblings()
3844 last_sibling->fib6_next, in __ip6_del_rt_siblings()
3845 lockdep_is_held(&table->tb6_lock)); in __ip6_del_rt_siblings()
3852 rt, rt->fib6_nsiblings, in __ip6_del_rt_siblings()
3856 &rt->fib6_siblings, in __ip6_del_rt_siblings()
3866 spin_unlock_bh(&table->tb6_lock); in __ip6_del_rt_siblings()
3871 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in __ip6_del_rt_siblings()
3872 info->nlh, gfp_any()); in __ip6_del_rt_siblings()
3879 int rc = -ESRCH; in __ip6_del_cached_rt()
3881 if (cfg->fc_ifindex && rt->dst.dev->ifindex != cfg->fc_ifindex) in __ip6_del_cached_rt()
3884 if (cfg->fc_flags & RTF_GATEWAY && in __ip6_del_cached_rt()
3885 !ipv6_addr_equal(&cfg->fc_gateway, &rt->rt6i_gateway)) in __ip6_del_cached_rt()
3902 rt_cache = rt6_find_cached_rt(&res, &cfg->fc_dst, &cfg->fc_src); in ip6_del_cached_rt()
3919 rc = ip6_del_cached_rt(arg->cfg, arg->f6i, nh); in fib6_nh_del_cached_rt()
3920 return rc != -ESRCH ? rc : 0; in fib6_nh_del_cached_rt()
3930 return nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_del_cached_rt, &arg); in ip6_del_cached_rt_nh()
3939 int err = -ESRCH; in ip6_route_del()
3941 table = fib6_get_table(cfg->fc_nlinfo.nl_net, cfg->fc_table); in ip6_route_del()
3949 fn = fib6_locate(&table->tb6_root, in ip6_route_del()
3950 &cfg->fc_dst, cfg->fc_dst_len, in ip6_route_del()
3951 &cfg->fc_src, cfg->fc_src_len, in ip6_route_del()
3952 !(cfg->fc_flags & RTF_CACHE)); in ip6_route_del()
3958 if (rt->nh && cfg->fc_nh_id && in ip6_route_del()
3959 rt->nh->id != cfg->fc_nh_id) in ip6_route_del()
3962 if (cfg->fc_flags & RTF_CACHE) { in ip6_route_del()
3965 if (rt->nh) { in ip6_route_del()
3967 } else if (cfg->fc_nh_id) { in ip6_route_del()
3970 nh = rt->fib6_nh; in ip6_route_del()
3973 if (rc != -ESRCH) { in ip6_route_del()
3980 if (cfg->fc_metric && cfg->fc_metric != rt->fib6_metric) in ip6_route_del()
3982 if (cfg->fc_protocol && in ip6_route_del()
3983 cfg->fc_protocol != rt->fib6_protocol) in ip6_route_del()
3986 if (rt->nh) { in ip6_route_del()
3991 return __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
3993 if (cfg->fc_nh_id) in ip6_route_del()
3996 nh = rt->fib6_nh; in ip6_route_del()
3997 if (cfg->fc_ifindex && in ip6_route_del()
3998 (!nh->fib_nh_dev || in ip6_route_del()
3999 nh->fib_nh_dev->ifindex != cfg->fc_ifindex)) in ip6_route_del()
4001 if (cfg->fc_flags & RTF_GATEWAY && in ip6_route_del()
4002 !ipv6_addr_equal(&cfg->fc_gateway, &nh->fib_nh_gw6)) in ip6_route_del()
4009 if (cfg->fc_flags & RTF_GATEWAY) in ip6_route_del()
4010 return __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
4032 optlen = skb_tail_pointer(skb) - skb_transport_header(skb); in rt6_do_redirect()
4033 optlen -= sizeof(*msg); in rt6_do_redirect()
4042 if (ipv6_addr_is_multicast(&msg->dest)) { in rt6_do_redirect()
4048 if (ipv6_addr_equal(&msg->dest, &msg->target)) { in rt6_do_redirect()
4050 } else if (ipv6_addr_type(&msg->target) != in rt6_do_redirect()
4052 net_dbg_ratelimited("rt6_do_redirect: target address is not link-local unicast\n"); in rt6_do_redirect()
4056 in6_dev = __in6_dev_get(skb->dev); in rt6_do_redirect()
4059 if (in6_dev->cnf.forwarding || !in6_dev->cnf.accept_redirects) in rt6_do_redirect()
4064 * first-hop router for the specified ICMP Destination Address. in rt6_do_redirect()
4067 if (!ndisc_parse_options(skb->dev, msg->opt, optlen, &ndopts)) { in rt6_do_redirect()
4075 skb->dev); in rt6_do_redirect()
4077 net_dbg_ratelimited("rt6_redirect: invalid link-layer address length\n"); in rt6_do_redirect()
4083 if (rt->rt6i_flags & RTF_REJECT) { in rt6_do_redirect()
4088 /* Redirect received -> path was valid. in rt6_do_redirect()
4090 * so that this nexthop apparently is reachable. --ANK in rt6_do_redirect()
4092 dst_confirm_neigh(&rt->dst, &ipv6_hdr(skb)->saddr); in rt6_do_redirect()
4094 neigh = __neigh_lookup(&nd_tbl, &msg->target, skb->dev, 1); in rt6_do_redirect()
4102 ndisc_update(skb->dev, neigh, lladdr, NUD_STALE, in rt6_do_redirect()
4110 res.f6i = rcu_dereference(rt->from); in rt6_do_redirect()
4114 if (res.f6i->nh) { in rt6_do_redirect()
4116 .dev = dst->dev, in rt6_do_redirect()
4117 .gw = &rt->rt6i_gateway, in rt6_do_redirect()
4120 nexthop_for_each_fib6_nh(res.f6i->nh, in rt6_do_redirect()
4124 * using the dst->dev. Should be impossible in rt6_do_redirect()
4130 res.nh = res.f6i->fib6_nh; in rt6_do_redirect()
4133 res.fib6_flags = res.f6i->fib6_flags; in rt6_do_redirect()
4134 res.fib6_type = res.f6i->fib6_type; in rt6_do_redirect()
4135 nrt = ip6_rt_cache_alloc(&res, &msg->dest, NULL); in rt6_do_redirect()
4139 nrt->rt6i_flags = RTF_GATEWAY|RTF_UP|RTF_DYNAMIC|RTF_CACHE; in rt6_do_redirect()
4141 nrt->rt6i_flags &= ~RTF_GATEWAY; in rt6_do_redirect()
4143 nrt->rt6i_gateway = *(struct in6_addr *)neigh->primary_key; in rt6_do_redirect()
4147 dst_release_immediate(&nrt->dst); in rt6_do_redirect()
4151 netevent.old = &rt->dst; in rt6_do_redirect()
4152 netevent.new = &nrt->dst; in rt6_do_redirect()
4153 netevent.daddr = &msg->dest; in rt6_do_redirect()
4169 int ifindex = dev->ifindex; in rt6_get_route_info()
4179 fn = fib6_locate(&table->tb6_root, prefix, prefixlen, NULL, 0, true); in rt6_get_route_info()
4185 if (rt->nh) in rt6_get_route_info()
4187 if (rt->fib6_nh->fib_nh_dev->ifindex != ifindex) in rt6_get_route_info()
4189 if (!(rt->fib6_flags & RTF_ROUTEINFO) || in rt6_get_route_info()
4190 !rt->fib6_nh->fib_nh_gw_family) in rt6_get_route_info()
4192 if (!ipv6_addr_equal(&rt->fib6_nh->fib_nh_gw6, gwaddr)) in rt6_get_route_info()
4211 .fc_ifindex = dev->ifindex, in rt6_add_route_info()
4226 /* We should treat it as a default route if prefix length is 0. */ in rt6_add_route_info()
4249 for_each_fib6_node_rt_rcu(&table->tb6_root) { in rt6_get_dflt_router()
4253 if (rt->nh) in rt6_get_dflt_router()
4256 nh = rt->fib6_nh; in rt6_get_dflt_router()
4257 if (dev == nh->fib_nh_dev && in rt6_get_dflt_router()
4258 ((rt->fib6_flags & (RTF_ADDRCONF | RTF_DEFAULT)) == (RTF_ADDRCONF | RTF_DEFAULT)) && in rt6_get_dflt_router()
4259 ipv6_addr_equal(&nh->fib_nh_gw6, addr)) in rt6_get_dflt_router()
4276 .fc_ifindex = dev->ifindex, in rt6_add_dflt_router()
4293 table->flags |= RT6_TABLE_HAS_DFLT_ROUTER; in rt6_add_dflt_router()
4306 for_each_fib6_node_rt_rcu(&table->tb6_root) { in __rt6_purge_dflt_routers()
4310 if (rt->fib6_flags & (RTF_DEFAULT | RTF_ADDRCONF) && in __rt6_purge_dflt_routers()
4311 (!idev || idev->cnf.accept_ra != 2) && in __rt6_purge_dflt_routers()
4320 table->flags &= ~RT6_TABLE_HAS_DFLT_ROUTER; in __rt6_purge_dflt_routers()
4332 head = &net->ipv6.fib_table_hash[h]; in rt6_purge_dflt_routers()
4334 if (table->flags & RT6_TABLE_HAS_DFLT_ROUTER) in rt6_purge_dflt_routers()
4347 .fc_table = l3mdev_fib_table_by_index(net, rtmsg->rtmsg_ifindex) ? in rtmsg_to_fib6_config()
4349 .fc_ifindex = rtmsg->rtmsg_ifindex, in rtmsg_to_fib6_config()
4350 .fc_metric = rtmsg->rtmsg_metric ? : IP6_RT_PRIO_USER, in rtmsg_to_fib6_config()
4351 .fc_expires = rtmsg->rtmsg_info, in rtmsg_to_fib6_config()
4352 .fc_dst_len = rtmsg->rtmsg_dst_len, in rtmsg_to_fib6_config()
4353 .fc_src_len = rtmsg->rtmsg_src_len, in rtmsg_to_fib6_config()
4354 .fc_flags = rtmsg->rtmsg_flags, in rtmsg_to_fib6_config()
4355 .fc_type = rtmsg->rtmsg_type, in rtmsg_to_fib6_config()
4359 .fc_dst = rtmsg->rtmsg_dst, in rtmsg_to_fib6_config()
4360 .fc_src = rtmsg->rtmsg_src, in rtmsg_to_fib6_config()
4361 .fc_gateway = rtmsg->rtmsg_gateway, in rtmsg_to_fib6_config()
4371 return -EINVAL; in ipv6_route_ioctl()
4372 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in ipv6_route_ioctl()
4373 return -EPERM; in ipv6_route_ioctl()
4397 struct net *net = dev_net(dst->dev); in ip6_pkt_drop()
4401 if (netif_is_l3_master(skb->dev) && in ip6_pkt_drop()
4402 dst->dev == net->loopback_dev) in ip6_pkt_drop()
4403 idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif)); in ip6_pkt_drop()
4409 type = ipv6_addr_type(&ipv6_hdr(skb)->daddr); in ip6_pkt_drop()
4421 if (netif_is_l3_master(skb->dev)) in ip6_pkt_drop()
4436 skb->dev = skb_dst(skb)->dev; in ip6_pkt_discard_out()
4447 skb->dev = skb_dst(skb)->dev; in ip6_pkt_prohibit_out()
4461 .fc_table = l3mdev_fib_table(idev->dev) ? : RT6_TABLE_LOCAL, in addrconf_f6i_alloc()
4462 .fc_ifindex = idev->dev->ifindex, in addrconf_f6i_alloc()
4482 f6i->dst_nocount = true; in addrconf_f6i_alloc()
4495 struct net_device *dev = ((struct arg_dev_net_ip *)arg)->dev; in fib6_remove_prefsrc()
4496 struct net *net = ((struct arg_dev_net_ip *)arg)->net; in fib6_remove_prefsrc()
4497 struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr; in fib6_remove_prefsrc()
4499 if (!rt->nh && in fib6_remove_prefsrc()
4500 ((void *)rt->fib6_nh->fib_nh_dev == dev || !dev) && in fib6_remove_prefsrc()
4501 rt != net->ipv6.fib6_null_entry && in fib6_remove_prefsrc()
4502 ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr)) { in fib6_remove_prefsrc()
4505 rt->fib6_prefsrc.plen = 0; in fib6_remove_prefsrc()
4513 struct net *net = dev_net(ifp->idev->dev); in rt6_remove_prefsrc()
4515 .dev = ifp->idev->dev, in rt6_remove_prefsrc()
4517 .addr = &ifp->addr, in rt6_remove_prefsrc()
4531 if (rt->nh) in fib6_clean_tohost()
4534 nh = rt->fib6_nh; in fib6_clean_tohost()
4535 if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) && in fib6_clean_tohost()
4536 nh->fib_nh_gw_family && ipv6_addr_equal(gateway, &nh->fib_nh_gw6)) in fib6_clean_tohost()
4537 return -1; in fib6_clean_tohost()
4540 * This is needed because cached route may have a different in fib6_clean_tohost()
4566 fn = rcu_dereference_protected(rt->fib6_node, in rt6_multipath_first_sibling()
4567 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4568 iter = rcu_dereference_protected(fn->leaf, in rt6_multipath_first_sibling()
4569 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4571 if (iter->fib6_metric == rt->fib6_metric && in rt6_multipath_first_sibling()
4574 iter = rcu_dereference_protected(iter->fib6_next, in rt6_multipath_first_sibling()
4575 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4584 if (rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD || in rt6_is_dead()
4585 (rt->fib6_nh->fib_nh_flags & RTNH_F_LINKDOWN && in rt6_is_dead()
4586 ip6_ignore_linkdown(rt->fib6_nh->fib_nh_dev))) in rt6_is_dead()
4598 total += rt->fib6_nh->fib_nh_weight; in rt6_multipath_total_weight()
4600 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) { in rt6_multipath_total_weight()
4602 total += iter->fib6_nh->fib_nh_weight; in rt6_multipath_total_weight()
4610 int upper_bound = -1; in rt6_upper_bound_set()
4613 *weight += rt->fib6_nh->fib_nh_weight; in rt6_upper_bound_set()
4615 total) - 1; in rt6_upper_bound_set()
4617 atomic_set(&rt->fib6_nh->fib_nh_upper_bound, upper_bound); in rt6_upper_bound_set()
4627 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_upper_bound_set()
4636 /* In case the entire multipath route was marked for flushing, in rt6_multipath_rebalance()
4638 * sibling route. in rt6_multipath_rebalance()
4640 if (!rt->fib6_nsiblings || rt->should_flush) in rt6_multipath_rebalance()
4658 struct net *net = dev_net(arg->dev); in fib6_ifup()
4660 if (rt != net->ipv6.fib6_null_entry && !rt->nh && in fib6_ifup()
4661 rt->fib6_nh->fib_nh_dev == arg->dev) { in fib6_ifup()
4662 rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags; in fib6_ifup()
4691 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_uses_dev()
4693 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_uses_dev()
4694 if (iter->fib6_nh->fib_nh_dev == dev) in rt6_multipath_uses_dev()
4704 rt->should_flush = 1; in rt6_multipath_flush()
4705 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_flush()
4706 iter->should_flush = 1; in rt6_multipath_flush()
4715 if (rt->fib6_nh->fib_nh_dev == down_dev || in rt6_multipath_dead_count()
4716 rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD) in rt6_multipath_dead_count()
4718 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_dead_count()
4719 if (iter->fib6_nh->fib_nh_dev == down_dev || in rt6_multipath_dead_count()
4720 iter->fib6_nh->fib_nh_flags & RTNH_F_DEAD) in rt6_multipath_dead_count()
4732 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_nh_flags_set()
4733 rt->fib6_nh->fib_nh_flags |= nh_flags; in rt6_multipath_nh_flags_set()
4734 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_nh_flags_set()
4735 if (iter->fib6_nh->fib_nh_dev == dev) in rt6_multipath_nh_flags_set()
4736 iter->fib6_nh->fib_nh_flags |= nh_flags; in rt6_multipath_nh_flags_set()
4743 const struct net_device *dev = arg->dev; in fib6_ifdown()
4746 if (rt == net->ipv6.fib6_null_entry || rt->nh) in fib6_ifdown()
4749 switch (arg->event) { in fib6_ifdown()
4751 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4753 if (rt->should_flush) in fib6_ifdown()
4754 return -1; in fib6_ifdown()
4755 if (!rt->fib6_nsiblings) in fib6_ifdown()
4756 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4761 if (rt->fib6_nsiblings + 1 == count) { in fib6_ifdown()
4763 return -1; in fib6_ifdown()
4770 return -2; in fib6_ifdown()
4772 if (rt->fib6_nh->fib_nh_dev != dev || in fib6_ifdown()
4773 rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) in fib6_ifdown()
4775 rt->fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib6_ifdown()
4793 if (net->ipv6.sysctl.skip_notify_on_dev_down) in rt6_sync_down_dev()
4815 struct fib6_info *f6i = arg->f6i; in fib6_nh_mtu_change()
4822 if (nh->fib_nh_dev == arg->dev) { in fib6_nh_mtu_change()
4823 struct inet6_dev *idev = __in6_dev_get(arg->dev); in fib6_nh_mtu_change()
4824 u32 mtu = f6i->fib6_pmtu; in fib6_nh_mtu_change()
4826 if (mtu >= arg->mtu || in fib6_nh_mtu_change()
4827 (mtu < arg->mtu && mtu == idev->cnf.mtu6)) in fib6_nh_mtu_change()
4828 fib6_metric_set(f6i, RTAX_MTU, arg->mtu); in fib6_nh_mtu_change()
4831 rt6_exceptions_update_pmtu(idev, nh, arg->mtu); in fib6_nh_mtu_change()
4849 idev = __in6_dev_get(arg->dev); in rt6_mtu_change_route()
4856 arg->f6i = f6i; in rt6_mtu_change_route()
4857 if (f6i->nh) { in rt6_mtu_change_route()
4859 return nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_mtu_change, in rt6_mtu_change_route()
4863 return fib6_nh_mtu_change(f6i->fib6_nh, arg); in rt6_mtu_change_route()
4912 err = -EINVAL; in rtm_to_fib6_config()
4916 .fc_table = rtm->rtm_table, in rtm_to_fib6_config()
4917 .fc_dst_len = rtm->rtm_dst_len, in rtm_to_fib6_config()
4918 .fc_src_len = rtm->rtm_src_len, in rtm_to_fib6_config()
4920 .fc_protocol = rtm->rtm_protocol, in rtm_to_fib6_config()
4921 .fc_type = rtm->rtm_type, in rtm_to_fib6_config()
4925 .fc_nlinfo.nl_net = sock_net(skb->sk), in rtm_to_fib6_config()
4928 if (rtm->rtm_type == RTN_UNREACHABLE || in rtm_to_fib6_config()
4929 rtm->rtm_type == RTN_BLACKHOLE || in rtm_to_fib6_config()
4930 rtm->rtm_type == RTN_PROHIBIT || in rtm_to_fib6_config()
4931 rtm->rtm_type == RTN_THROW) in rtm_to_fib6_config()
4932 cfg->fc_flags |= RTF_REJECT; in rtm_to_fib6_config()
4934 if (rtm->rtm_type == RTN_LOCAL) in rtm_to_fib6_config()
4935 cfg->fc_flags |= RTF_LOCAL; in rtm_to_fib6_config()
4937 if (rtm->rtm_flags & RTM_F_CLONED) in rtm_to_fib6_config()
4938 cfg->fc_flags |= RTF_CACHE; in rtm_to_fib6_config()
4940 cfg->fc_flags |= (rtm->rtm_flags & RTNH_F_ONLINK); in rtm_to_fib6_config()
4949 cfg->fc_nh_id = nla_get_u32(tb[RTA_NH_ID]); in rtm_to_fib6_config()
4953 cfg->fc_gateway = nla_get_in6_addr(tb[RTA_GATEWAY]); in rtm_to_fib6_config()
4954 cfg->fc_flags |= RTF_GATEWAY; in rtm_to_fib6_config()
4962 int plen = (rtm->rtm_dst_len + 7) >> 3; in rtm_to_fib6_config()
4967 nla_memcpy(&cfg->fc_dst, tb[RTA_DST], plen); in rtm_to_fib6_config()
4971 int plen = (rtm->rtm_src_len + 7) >> 3; in rtm_to_fib6_config()
4976 nla_memcpy(&cfg->fc_src, tb[RTA_SRC], plen); in rtm_to_fib6_config()
4980 cfg->fc_prefsrc = nla_get_in6_addr(tb[RTA_PREFSRC]); in rtm_to_fib6_config()
4983 cfg->fc_ifindex = nla_get_u32(tb[RTA_OIF]); in rtm_to_fib6_config()
4986 cfg->fc_metric = nla_get_u32(tb[RTA_PRIORITY]); in rtm_to_fib6_config()
4989 cfg->fc_mx = nla_data(tb[RTA_METRICS]); in rtm_to_fib6_config()
4990 cfg->fc_mx_len = nla_len(tb[RTA_METRICS]); in rtm_to_fib6_config()
4994 cfg->fc_table = nla_get_u32(tb[RTA_TABLE]); in rtm_to_fib6_config()
4997 cfg->fc_mp = nla_data(tb[RTA_MULTIPATH]); in rtm_to_fib6_config()
4998 cfg->fc_mp_len = nla_len(tb[RTA_MULTIPATH]); in rtm_to_fib6_config()
5000 err = lwtunnel_valid_encap_type_attr(cfg->fc_mp, in rtm_to_fib6_config()
5001 cfg->fc_mp_len, extack); in rtm_to_fib6_config()
5011 cfg->fc_flags |= RTF_PREF(pref); in rtm_to_fib6_config()
5015 cfg->fc_encap = tb[RTA_ENCAP]; in rtm_to_fib6_config()
5018 cfg->fc_encap_type = nla_get_u16(tb[RTA_ENCAP_TYPE]); in rtm_to_fib6_config()
5020 err = lwtunnel_valid_encap_type(cfg->fc_encap_type, extack); in rtm_to_fib6_config()
5029 cfg->fc_expires = jiffies_to_clock_t(timeout * HZ); in rtm_to_fib6_config()
5030 cfg->fc_flags |= RTF_EXPIRES; in rtm_to_fib6_config()
5051 int err = -EEXIST; in ip6_route_info_append()
5055 if (rt6_duplicate_nexthop(nh->fib6_info, rt)) in ip6_route_info_append()
5061 return -ENOMEM; in ip6_route_info_append()
5062 nh->fib6_info = rt; in ip6_route_info_append()
5063 memcpy(&nh->r_cfg, r_cfg, sizeof(*r_cfg)); in ip6_route_info_append()
5064 list_add_tail(&nh->next, rt6_nh_list); in ip6_route_info_append()
5074 /* if this is an APPEND route, then rt points to the first route in ip6_route_mpath_notify()
5075 * inserted and rt_last points to last route inserted. Userspace in ip6_route_mpath_notify()
5076 * wants a consistent dump of the route which starts at the first in ip6_route_mpath_notify()
5078 * the list, find the first sibling of the last route appended in ip6_route_mpath_notify()
5080 if ((nlflags & NLM_F_APPEND) && rt_last && rt_last->fib6_nsiblings) { in ip6_route_mpath_notify()
5081 rt = list_first_entry(&rt_last->fib6_siblings, in ip6_route_mpath_notify()
5098 fn = rcu_dereference(rt->fib6_node); in ip6_route_mpath_should_notify()
5102 leaf = rcu_dereference(fn->leaf); in ip6_route_mpath_should_notify()
5107 (rt_can_ecmp && rt->fib6_metric == leaf->fib6_metric && in ip6_route_mpath_should_notify()
5121 return -EINVAL; in fib6_gw_from_attr()
5133 struct nl_info *info = &cfg->fc_nlinfo; in ip6_route_multipath_add()
5144 int replace = (cfg->fc_nlinfo.nlh && in ip6_route_multipath_add()
5145 (cfg->fc_nlinfo.nlh->nlmsg_flags & NLM_F_REPLACE)); in ip6_route_multipath_add()
5149 if (info->nlh && info->nlh->nlmsg_flags & NLM_F_APPEND) in ip6_route_multipath_add()
5152 remaining = cfg->fc_mp_len; in ip6_route_multipath_add()
5153 rtnh = (struct rtnexthop *)cfg->fc_mp; in ip6_route_multipath_add()
5160 if (rtnh->rtnh_ifindex) in ip6_route_multipath_add()
5161 r_cfg.fc_ifindex = rtnh->rtnh_ifindex; in ip6_route_multipath_add()
5186 r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK); in ip6_route_multipath_add()
5194 err = -EINVAL; in ip6_route_multipath_add()
5201 rt->fib6_nh->fib_nh_weight = rtnh->rtnh_hops + 1; in ip6_route_multipath_add()
5203 err = ip6_route_info_append(info->nl_net, &rt6_nh_list, in ip6_route_multipath_add()
5215 "Invalid nexthop configuration - no valid nexthops"); in ip6_route_multipath_add()
5216 return -EINVAL; in ip6_route_multipath_add()
5221 * the full route when done in ip6_route_multipath_add()
5223 info->skip_notify = 1; in ip6_route_multipath_add()
5228 info->skip_notify_kernel = 1; in ip6_route_multipath_add()
5232 err = __ip6_ins_rt(nh->fib6_info, info, extack); in ip6_route_multipath_add()
5233 fib6_info_release(nh->fib6_info); in ip6_route_multipath_add()
5236 /* save reference to last route successfully inserted */ in ip6_route_multipath_add()
5237 rt_last = nh->fib6_info; in ip6_route_multipath_add()
5239 /* save reference to first route for notification */ in ip6_route_multipath_add()
5241 rt_notif = nh->fib6_info; in ip6_route_multipath_add()
5244 /* nh->fib6_info is used or freed at this point, reset to NULL*/ in ip6_route_multipath_add()
5245 nh->fib6_info = NULL; in ip6_route_multipath_add()
5249 "multipath route replace failed (check consistency of installed routes)"); in ip6_route_multipath_add()
5254 /* Because each route is added like a single route we remove in ip6_route_multipath_add()
5261 if (cfg->fc_nlinfo.nlh) { in ip6_route_multipath_add()
5262 cfg->fc_nlinfo.nlh->nlmsg_flags &= ~(NLM_F_EXCL | in ip6_route_multipath_add()
5264 cfg->fc_nlinfo.nlh->nlmsg_flags |= NLM_F_CREATE; in ip6_route_multipath_add()
5269 /* An in-kernel notification should only be sent in case the new in ip6_route_multipath_add()
5270 * multipath route is added as the first route in the node, or if in ip6_route_multipath_add()
5277 if (rt_notif->fib6_nsiblings != nhn - 1) in ip6_route_multipath_add()
5282 err = call_fib6_multipath_entry_notifiers(info->nl_net, in ip6_route_multipath_add()
5284 nhn - 1, extack); in ip6_route_multipath_add()
5292 /* success ... tell user about new route */ in ip6_route_multipath_add()
5308 ip6_route_del(&nh->r_cfg, extack); in ip6_route_multipath_add()
5313 if (nh->fib6_info) in ip6_route_multipath_add()
5314 fib6_info_release(nh->fib6_info); in ip6_route_multipath_add()
5315 list_del(&nh->next); in ip6_route_multipath_add()
5332 remaining = cfg->fc_mp_len; in ip6_route_multipath_del()
5333 rtnh = (struct rtnexthop *)cfg->fc_mp; in ip6_route_multipath_del()
5338 if (rtnh->rtnh_ifindex) in ip6_route_multipath_del()
5339 r_cfg.fc_ifindex = rtnh->rtnh_ifindex; in ip6_route_multipath_del()
5379 !nexthop_find_by_id(sock_net(skb->sk), cfg.fc_nh_id)) { in inet6_rtm_delroute()
5381 return -EINVAL; in inet6_rtm_delroute()
5420 if (nh->fib_nh_lws) { in rt6_nh_nlmsg_size()
5422 *nexthop_len += lwtunnel_get_encap_size(nh->fib_nh_lws); in rt6_nh_nlmsg_size()
5434 if (f6i->nh) { in rt6_nlmsg_size()
5436 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_nlmsg_size, in rt6_nlmsg_size()
5439 struct fib6_nh *nh = f6i->fib6_nh; in rt6_nlmsg_size()
5442 if (f6i->fib6_nsiblings) { in rt6_nlmsg_size()
5446 + lwtunnel_get_encap_size(nh->fib_nh_lws); in rt6_nlmsg_size()
5448 nexthop_len *= f6i->fib6_nsiblings; in rt6_nlmsg_size()
5450 nexthop_len += lwtunnel_get_encap_size(nh->fib_nh_lws); in rt6_nlmsg_size()
5487 if (fib_nexthop_info(skb, &fib6_nh->nh_common, AF_INET6, in rt6_fill_node_nexthop()
5495 return -EMSGSIZE; in rt6_fill_node_nexthop()
5514 return -EMSGSIZE; in rt6_fill_node()
5517 rt6_dst = &rt6->rt6i_dst; in rt6_fill_node()
5518 rt6_src = &rt6->rt6i_src; in rt6_fill_node()
5519 rt6_flags = rt6->rt6i_flags; in rt6_fill_node()
5521 rt6_dst = &rt->fib6_dst; in rt6_fill_node()
5522 rt6_src = &rt->fib6_src; in rt6_fill_node()
5523 rt6_flags = rt->fib6_flags; in rt6_fill_node()
5527 rtm->rtm_family = AF_INET6; in rt6_fill_node()
5528 rtm->rtm_dst_len = rt6_dst->plen; in rt6_fill_node()
5529 rtm->rtm_src_len = rt6_src->plen; in rt6_fill_node()
5530 rtm->rtm_tos = 0; in rt6_fill_node()
5531 if (rt->fib6_table) in rt6_fill_node()
5532 table = rt->fib6_table->tb6_id; in rt6_fill_node()
5535 rtm->rtm_table = table < 256 ? table : RT_TABLE_COMPAT; in rt6_fill_node()
5539 rtm->rtm_type = rt->fib6_type; in rt6_fill_node()
5540 rtm->rtm_flags = 0; in rt6_fill_node()
5541 rtm->rtm_scope = RT_SCOPE_UNIVERSE; in rt6_fill_node()
5542 rtm->rtm_protocol = rt->fib6_protocol; in rt6_fill_node()
5545 rtm->rtm_flags |= RTM_F_CLONED; in rt6_fill_node()
5550 rtm->rtm_dst_len = 128; in rt6_fill_node()
5551 } else if (rtm->rtm_dst_len) in rt6_fill_node()
5552 if (nla_put_in6_addr(skb, RTA_DST, &rt6_dst->addr)) in rt6_fill_node()
5558 rtm->rtm_src_len = 128; in rt6_fill_node()
5559 } else if (rtm->rtm_src_len && in rt6_fill_node()
5560 nla_put_in6_addr(skb, RTA_SRC, &rt6_src->addr)) in rt6_fill_node()
5565 if (ipv6_addr_is_multicast(&rt6_dst->addr)) { in rt6_fill_node()
5583 if (rt->fib6_prefsrc.plen) { in rt6_fill_node()
5585 saddr_buf = rt->fib6_prefsrc.addr; in rt6_fill_node()
5590 pmetrics = dst ? dst_metrics_ptr(dst) : rt->fib6_metrics->metrics; in rt6_fill_node()
5594 if (nla_put_u32(skb, RTA_PRIORITY, rt->fib6_metric)) in rt6_fill_node()
5602 nla_put_in6_addr(skb, RTA_GATEWAY, &rt6->rt6i_gateway)) in rt6_fill_node()
5605 if (dst->dev && nla_put_u32(skb, RTA_OIF, dst->dev->ifindex)) in rt6_fill_node()
5607 } else if (rt->fib6_nsiblings) { in rt6_fill_node()
5615 if (fib_add_nexthop(skb, &rt->fib6_nh->nh_common, in rt6_fill_node()
5616 rt->fib6_nh->fib_nh_weight, AF_INET6, in rt6_fill_node()
5621 &rt->fib6_siblings, fib6_siblings) { in rt6_fill_node()
5622 if (fib_add_nexthop(skb, &sibling->fib6_nh->nh_common, in rt6_fill_node()
5623 sibling->fib6_nh->fib_nh_weight, in rt6_fill_node()
5629 } else if (rt->nh) { in rt6_fill_node()
5630 if (nla_put_u32(skb, RTA_NH_ID, rt->nh->id)) in rt6_fill_node()
5633 if (nexthop_is_blackhole(rt->nh)) in rt6_fill_node()
5634 rtm->rtm_type = RTN_BLACKHOLE; in rt6_fill_node()
5636 if (net->ipv4.sysctl_nexthop_compat_mode && in rt6_fill_node()
5637 rt6_fill_node_nexthop(skb, rt->nh, &nh_flags) < 0) in rt6_fill_node()
5640 rtm->rtm_flags |= nh_flags; in rt6_fill_node()
5642 if (fib_nexthop_info(skb, &rt->fib6_nh->nh_common, AF_INET6, in rt6_fill_node()
5646 rtm->rtm_flags |= nh_flags; in rt6_fill_node()
5650 expires = dst ? dst->expires : rt->expires; in rt6_fill_node()
5651 expires -= jiffies; in rt6_fill_node()
5655 if (rt->offload) in rt6_fill_node()
5656 rtm->rtm_flags |= RTM_F_OFFLOAD; in rt6_fill_node()
5657 if (rt->trap) in rt6_fill_node()
5658 rtm->rtm_flags |= RTM_F_TRAP; in rt6_fill_node()
5661 if (rtnl_put_cacheinfo(skb, dst, 0, expires, dst ? dst->error : 0) < 0) in rt6_fill_node()
5673 return -EMSGSIZE; in rt6_fill_node()
5680 if (nh->fib_nh_dev == dev) in fib6_info_nh_uses_dev()
5689 if (f6i->nh) { in fib6_info_uses_dev()
5692 return !!nexthop_for_each_fib6_nh(f6i->nh, in fib6_info_uses_dev()
5697 if (f6i->fib6_nh->fib_nh_dev == dev) in fib6_info_uses_dev()
5700 if (f6i->fib6_nsiblings) { in fib6_info_uses_dev()
5704 &f6i->fib6_siblings, fib6_siblings) { in fib6_info_uses_dev()
5705 if (sibling->fib6_nh->fib_nh_dev == dev) in fib6_info_uses_dev()
5724 struct rt6_rtnl_dump_arg *dump = w->dump; in rt6_nh_dump_exceptions()
5734 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_nh_dump_exceptions()
5735 if (w->skip) { in rt6_nh_dump_exceptions()
5736 w->skip--; in rt6_nh_dump_exceptions()
5751 if (rt6_check_expired(rt6_ex->rt6i)) { in rt6_nh_dump_exceptions()
5752 w->count++; in rt6_nh_dump_exceptions()
5756 err = rt6_fill_node(dump->net, dump->skb, w->rt, in rt6_nh_dump_exceptions()
5757 &rt6_ex->rt6i->dst, NULL, NULL, 0, in rt6_nh_dump_exceptions()
5759 NETLINK_CB(dump->cb->skb).portid, in rt6_nh_dump_exceptions()
5760 dump->cb->nlh->nlmsg_seq, w->flags); in rt6_nh_dump_exceptions()
5764 w->count++; in rt6_nh_dump_exceptions()
5772 /* Return -1 if done with node, number of handled routes on partial dump */
5776 struct fib_dump_filter *filter = &arg->filter; in rt6_dump_route()
5778 struct net *net = arg->net; in rt6_dump_route()
5781 if (rt == net->ipv6.fib6_null_entry) in rt6_dump_route()
5782 return -1; in rt6_dump_route()
5784 if ((filter->flags & RTM_F_PREFIX) && in rt6_dump_route()
5785 !(rt->fib6_flags & RTF_PREFIX_RT)) { in rt6_dump_route()
5786 /* success since this is not a prefix route */ in rt6_dump_route()
5787 return -1; in rt6_dump_route()
5789 if (filter->filter_set && in rt6_dump_route()
5790 ((filter->rt_type && rt->fib6_type != filter->rt_type) || in rt6_dump_route()
5791 (filter->dev && !fib6_info_uses_dev(rt, filter->dev)) || in rt6_dump_route()
5792 (filter->protocol && rt->fib6_protocol != filter->protocol))) { in rt6_dump_route()
5793 return -1; in rt6_dump_route()
5796 if (filter->filter_set || in rt6_dump_route()
5797 !filter->dump_routes || !filter->dump_exceptions) { in rt6_dump_route()
5801 if (filter->dump_routes) { in rt6_dump_route()
5803 skip--; in rt6_dump_route()
5805 if (rt6_fill_node(net, arg->skb, rt, NULL, NULL, NULL, in rt6_dump_route()
5807 NETLINK_CB(arg->cb->skb).portid, in rt6_dump_route()
5808 arg->cb->nlh->nlmsg_seq, flags)) { in rt6_dump_route()
5815 if (filter->dump_exceptions) { in rt6_dump_route()
5824 if (rt->nh) { in rt6_dump_route()
5825 err = nexthop_for_each_fib6_nh(rt->nh, in rt6_dump_route()
5829 err = rt6_nh_dump_exceptions(rt->fib6_nh, &w); in rt6_dump_route()
5837 return -1; in rt6_dump_route()
5848 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*rtm))) { in inet6_rtm_valid_getroute_req()
5850 "Invalid header for get route request"); in inet6_rtm_valid_getroute_req()
5851 return -EINVAL; in inet6_rtm_valid_getroute_req()
5859 if ((rtm->rtm_src_len && rtm->rtm_src_len != 128) || in inet6_rtm_valid_getroute_req()
5860 (rtm->rtm_dst_len && rtm->rtm_dst_len != 128) || in inet6_rtm_valid_getroute_req()
5861 rtm->rtm_table || rtm->rtm_protocol || rtm->rtm_scope || in inet6_rtm_valid_getroute_req()
5862 rtm->rtm_type) { in inet6_rtm_valid_getroute_req()
5863 NL_SET_ERR_MSG_MOD(extack, "Invalid values in header for get route request"); in inet6_rtm_valid_getroute_req()
5864 return -EINVAL; in inet6_rtm_valid_getroute_req()
5866 if (rtm->rtm_flags & ~RTM_F_FIB_MATCH) { in inet6_rtm_valid_getroute_req()
5868 "Invalid flags for get route request"); in inet6_rtm_valid_getroute_req()
5869 return -EINVAL; in inet6_rtm_valid_getroute_req()
5877 if ((tb[RTA_SRC] && !rtm->rtm_src_len) || in inet6_rtm_valid_getroute_req()
5878 (tb[RTA_DST] && !rtm->rtm_dst_len)) { in inet6_rtm_valid_getroute_req()
5880 return -EINVAL; in inet6_rtm_valid_getroute_req()
5899 NL_SET_ERR_MSG_MOD(extack, "Unsupported attribute in get route request"); in inet6_rtm_valid_getroute_req()
5900 return -EINVAL; in inet6_rtm_valid_getroute_req()
5910 struct net *net = sock_net(in_skb->sk); in inet6_rtm_getroute()
5925 err = -EINVAL; in inet6_rtm_getroute()
5927 fl6.flowlabel = ip6_make_flowinfo(rtm->rtm_tos, 0); in inet6_rtm_getroute()
5928 fibmatch = !!(rtm->rtm_flags & RTM_F_FIB_MATCH); in inet6_rtm_getroute()
5982 err = -ENODEV; in inet6_rtm_getroute()
6002 if (rt->dst.error) { in inet6_rtm_getroute()
6003 err = rt->dst.error; in inet6_rtm_getroute()
6008 if (rt == net->ipv6.ip6_null_entry) { in inet6_rtm_getroute()
6009 err = rt->dst.error; in inet6_rtm_getroute()
6017 err = -ENOBUFS; in inet6_rtm_getroute()
6021 skb_dst_set(skb, &rt->dst); in inet6_rtm_getroute()
6024 from = rcu_dereference(rt->from); in inet6_rtm_getroute()
6030 nlh->nlmsg_seq, 0); in inet6_rtm_getroute()
6035 nlh->nlmsg_seq, 0); in inet6_rtm_getroute()
6037 err = -ENETUNREACH; in inet6_rtm_getroute()
6055 struct net *net = info->nl_net; in inet6_rt_notify()
6059 err = -ENOBUFS; in inet6_rt_notify()
6060 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in inet6_rt_notify()
6067 event, info->portid, seq, nlm_flags); in inet6_rt_notify()
6069 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ in inet6_rt_notify()
6070 WARN_ON(err == -EMSGSIZE); in inet6_rt_notify()
6074 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in inet6_rt_notify()
6075 info->nlh, gfp_any()); in inet6_rt_notify()
6085 u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in fib6_rt_update()
6087 int err = -ENOBUFS; in fib6_rt_update()
6089 /* call_fib6_entry_notifiers will be removed when in-kernel notifier in fib6_rt_update()
6099 RTM_NEWROUTE, info->portid, seq, NLM_F_REPLACE); in fib6_rt_update()
6101 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ in fib6_rt_update()
6102 WARN_ON(err == -EMSGSIZE); in fib6_rt_update()
6106 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in fib6_rt_update()
6107 info->nlh, gfp_any()); in fib6_rt_update()
6120 if (!(dev->flags & IFF_LOOPBACK)) in ip6_route_dev_notify()
6124 net->ipv6.fib6_null_entry->fib6_nh->fib_nh_dev = dev; in ip6_route_dev_notify()
6125 net->ipv6.ip6_null_entry->dst.dev = dev; in ip6_route_dev_notify()
6126 net->ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6128 net->ipv6.ip6_prohibit_entry->dst.dev = dev; in ip6_route_dev_notify()
6129 net->ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6130 net->ipv6.ip6_blk_hole_entry->dst.dev = dev; in ip6_route_dev_notify()
6131 net->ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6134 dev->reg_state != NETREG_UNREGISTERED) { in ip6_route_dev_notify()
6138 in6_dev_put_clear(&net->ipv6.ip6_null_entry->rt6i_idev); in ip6_route_dev_notify()
6140 in6_dev_put_clear(&net->ipv6.ip6_prohibit_entry->rt6i_idev); in ip6_route_dev_notify()
6141 in6_dev_put_clear(&net->ipv6.ip6_blk_hole_entry->rt6i_idev); in ip6_route_dev_notify()
6155 struct net *net = (struct net *)seq->private; in rt6_stats_seq_show()
6157 net->ipv6.rt6_stats->fib_nodes, in rt6_stats_seq_show()
6158 net->ipv6.rt6_stats->fib_route_nodes, in rt6_stats_seq_show()
6159 atomic_read(&net->ipv6.rt6_stats->fib_rt_alloc), in rt6_stats_seq_show()
6160 net->ipv6.rt6_stats->fib_rt_entries, in rt6_stats_seq_show()
6161 net->ipv6.rt6_stats->fib_rt_cache, in rt6_stats_seq_show()
6162 dst_entries_get_slow(&net->ipv6.ip6_dst_ops), in rt6_stats_seq_show()
6163 net->ipv6.rt6_stats->fib_discarded_routes); in rt6_stats_seq_show()
6178 return -EINVAL; in ipv6_sysctl_rtcache_flush()
6180 net = (struct net *)ctl->extra1; in ipv6_sysctl_rtcache_flush()
6181 delay = net->ipv6.sysctl.flush_delay; in ipv6_sysctl_rtcache_flush()
6282 table[0].data = &net->ipv6.sysctl.flush_delay; in ipv6_route_sysctl_init()
6284 table[1].data = &net->ipv6.ip6_dst_ops.gc_thresh; in ipv6_route_sysctl_init()
6285 table[2].data = &net->ipv6.sysctl.ip6_rt_max_size; in ipv6_route_sysctl_init()
6286 table[3].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; in ipv6_route_sysctl_init()
6287 table[4].data = &net->ipv6.sysctl.ip6_rt_gc_timeout; in ipv6_route_sysctl_init()
6288 table[5].data = &net->ipv6.sysctl.ip6_rt_gc_interval; in ipv6_route_sysctl_init()
6289 table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity; in ipv6_route_sysctl_init()
6290 table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires; in ipv6_route_sysctl_init()
6291 table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss; in ipv6_route_sysctl_init()
6292 table[9].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; in ipv6_route_sysctl_init()
6293 table[10].data = &net->ipv6.sysctl.skip_notify_on_dev_down; in ipv6_route_sysctl_init()
6296 if (net->user_ns != &init_user_ns) in ipv6_route_sysctl_init()
6306 int ret = -ENOMEM; in ip6_route_net_init()
6308 memcpy(&net->ipv6.ip6_dst_ops, &ip6_dst_ops_template, in ip6_route_net_init()
6309 sizeof(net->ipv6.ip6_dst_ops)); in ip6_route_net_init()
6311 if (dst_entries_init(&net->ipv6.ip6_dst_ops) < 0) in ip6_route_net_init()
6314 net->ipv6.fib6_null_entry = fib6_info_alloc(GFP_KERNEL, true); in ip6_route_net_init()
6315 if (!net->ipv6.fib6_null_entry) in ip6_route_net_init()
6317 memcpy(net->ipv6.fib6_null_entry, &fib6_null_entry_template, in ip6_route_net_init()
6318 sizeof(*net->ipv6.fib6_null_entry)); in ip6_route_net_init()
6320 net->ipv6.ip6_null_entry = kmemdup(&ip6_null_entry_template, in ip6_route_net_init()
6321 sizeof(*net->ipv6.ip6_null_entry), in ip6_route_net_init()
6323 if (!net->ipv6.ip6_null_entry) in ip6_route_net_init()
6325 net->ipv6.ip6_null_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6326 dst_init_metrics(&net->ipv6.ip6_null_entry->dst, in ip6_route_net_init()
6328 INIT_LIST_HEAD(&net->ipv6.ip6_null_entry->rt6i_uncached); in ip6_route_net_init()
6331 net->ipv6.fib6_has_custom_rules = false; in ip6_route_net_init()
6332 net->ipv6.ip6_prohibit_entry = kmemdup(&ip6_prohibit_entry_template, in ip6_route_net_init()
6333 sizeof(*net->ipv6.ip6_prohibit_entry), in ip6_route_net_init()
6335 if (!net->ipv6.ip6_prohibit_entry) in ip6_route_net_init()
6337 net->ipv6.ip6_prohibit_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6338 dst_init_metrics(&net->ipv6.ip6_prohibit_entry->dst, in ip6_route_net_init()
6340 INIT_LIST_HEAD(&net->ipv6.ip6_prohibit_entry->rt6i_uncached); in ip6_route_net_init()
6342 net->ipv6.ip6_blk_hole_entry = kmemdup(&ip6_blk_hole_entry_template, in ip6_route_net_init()
6343 sizeof(*net->ipv6.ip6_blk_hole_entry), in ip6_route_net_init()
6345 if (!net->ipv6.ip6_blk_hole_entry) in ip6_route_net_init()
6347 net->ipv6.ip6_blk_hole_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6348 dst_init_metrics(&net->ipv6.ip6_blk_hole_entry->dst, in ip6_route_net_init()
6350 INIT_LIST_HEAD(&net->ipv6.ip6_blk_hole_entry->rt6i_uncached); in ip6_route_net_init()
6352 net->ipv6.fib6_routes_require_src = 0; in ip6_route_net_init()
6356 net->ipv6.sysctl.flush_delay = 0; in ip6_route_net_init()
6357 net->ipv6.sysctl.ip6_rt_max_size = 4096; in ip6_route_net_init()
6358 net->ipv6.sysctl.ip6_rt_gc_min_interval = HZ / 2; in ip6_route_net_init()
6359 net->ipv6.sysctl.ip6_rt_gc_timeout = 60*HZ; in ip6_route_net_init()
6360 net->ipv6.sysctl.ip6_rt_gc_interval = 30*HZ; in ip6_route_net_init()
6361 net->ipv6.sysctl.ip6_rt_gc_elasticity = 9; in ip6_route_net_init()
6362 net->ipv6.sysctl.ip6_rt_mtu_expires = 10*60*HZ; in ip6_route_net_init()
6363 net->ipv6.sysctl.ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40; in ip6_route_net_init()
6364 net->ipv6.sysctl.skip_notify_on_dev_down = 0; in ip6_route_net_init()
6366 net->ipv6.ip6_rt_gc_expire = 30*HZ; in ip6_route_net_init()
6374 kfree(net->ipv6.ip6_prohibit_entry); in ip6_route_net_init()
6376 kfree(net->ipv6.ip6_null_entry); in ip6_route_net_init()
6379 kfree(net->ipv6.fib6_null_entry); in ip6_route_net_init()
6381 dst_entries_destroy(&net->ipv6.ip6_dst_ops); in ip6_route_net_init()
6388 kfree(net->ipv6.fib6_null_entry); in ip6_route_net_exit()
6389 kfree(net->ipv6.ip6_null_entry); in ip6_route_net_exit()
6391 kfree(net->ipv6.ip6_prohibit_entry); in ip6_route_net_exit()
6392 kfree(net->ipv6.ip6_blk_hole_entry); in ip6_route_net_exit()
6394 dst_entries_destroy(&net->ipv6.ip6_dst_ops); in ip6_route_net_exit()
6400 proc_create_net("ipv6_route", 0, net->proc_net, &ipv6_route_seq_ops, in ip6_route_net_init_late()
6402 proc_create_net_single("rt6_stats", 0444, net->proc_net, in ip6_route_net_init_late()
6411 remove_proc_entry("ipv6_route", net->proc_net); in ip6_route_net_exit_late()
6412 remove_proc_entry("rt6_stats", net->proc_net); in ip6_route_net_exit_late()
6426 return -ENOMEM; in ipv6_inetpeer_init()
6428 net->ipv6.peers = bp; in ipv6_inetpeer_init()
6434 struct inet_peer_base *bp = net->ipv6.peers; in ipv6_inetpeer_exit()
6436 net->ipv6.peers = NULL; in ipv6_inetpeer_exit()
6453 .priority = ADDRCONF_NOTIFY_PRIORITY - 10,
6461 init_net.ipv6.fib6_null_entry->fib6_nh->fib_nh_dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6462 init_net.ipv6.ip6_null_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6463 init_net.ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6465 init_net.ipv6.ip6_prohibit_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6466 init_net.ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6467 init_net.ipv6.ip6_blk_hole_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6468 init_net.ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6514 ret = -ENOMEM; in ip6_route_init()
6582 INIT_LIST_HEAD(&ul->head); in ip6_route_init()
6583 spin_lock_init(&ul->lock); in ip6_route_init()