Lines Matching +full:use +full:- +full:rtm

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.
79 RT6_NUD_FAIL_HARD = -3,
80 RT6_NUD_FAIL_PROBE = -2,
81 RT6_NUD_FAIL_DO_RR = -1,
142 rt->dst.rt_uncached_list = ul; in rt6_uncached_list_add()
144 spin_lock_bh(&ul->lock); in rt6_uncached_list_add()
145 list_add_tail(&rt->dst.rt_uncached, &ul->head); in rt6_uncached_list_add()
146 spin_unlock_bh(&ul->lock); in rt6_uncached_list_add()
151 if (!list_empty(&rt->dst.rt_uncached)) { in rt6_uncached_list_del()
152 struct uncached_list *ul = rt->dst.rt_uncached_list; in rt6_uncached_list_del()
154 spin_lock_bh(&ul->lock); in rt6_uncached_list_del()
155 list_del_init(&rt->dst.rt_uncached); in rt6_uncached_list_del()
156 spin_unlock_bh(&ul->lock); in rt6_uncached_list_del()
168 if (list_empty(&ul->head)) in rt6_uncached_list_flush_dev()
171 spin_lock_bh(&ul->lock); in rt6_uncached_list_flush_dev()
172 list_for_each_entry_safe(rt, safe, &ul->head, dst.rt_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()
177 if (rt_idev && rt_idev->dev == dev) { in rt6_uncached_list_flush_dev()
178 rt->rt6i_idev = in6_dev_get(blackhole_netdev); in rt6_uncached_list_flush_dev()
184 rt->dst.dev = blackhole_netdev; in rt6_uncached_list_flush_dev()
186 &rt->dst.dev_tracker, in rt6_uncached_list_flush_dev()
191 list_del_init(&rt->dst.rt_uncached); in rt6_uncached_list_flush_dev()
193 spin_unlock_bh(&ul->lock); in rt6_uncached_list_flush_dev()
204 return &ipv6_hdr(skb)->daddr; in choose_neigh_daddr()
231 dst->dev, skb, daddr); in ip6_dst_neigh_lookup()
237 struct net_device *dev = dst->dev; in ip6_confirm_neigh()
242 if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) in ip6_confirm_neigh()
281 [RTAX_HOPLIMIT - 1] = 0,
298 .error = -ENETUNREACH,
312 .error = -EACCES,
324 .error = -EINVAL,
342 struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev, in ip6_dst_alloc()
347 atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc); in ip6_dst_alloc()
363 idev = rt->rt6i_idev; in ip6_dst_destroy()
365 rt->rt6i_idev = NULL; in ip6_dst_destroy()
369 from = unrcu_pointer(xchg(&rt->from, NULL)); in ip6_dst_destroy()
376 struct inet6_dev *idev = rt->rt6i_idev; in ip6_dst_ifdown()
378 if (idev && idev->dev != blackhole_netdev) { in ip6_dst_ifdown()
382 rt->rt6i_idev = blackhole_idev; in ip6_dst_ifdown()
390 if (rt->rt6i_flags & RTF_EXPIRES) in __rt6_check_expired()
391 return time_after(jiffies, rt->dst.expires); in __rt6_check_expired()
400 from = rcu_dereference(rt->from); in rt6_check_expired()
402 if (rt->rt6i_flags & RTF_EXPIRES) { in rt6_check_expired()
403 if (time_after(jiffies, rt->dst.expires)) in rt6_check_expired()
406 return rt->dst.obsolete != DST_OBSOLETE_FORCE_CHK || in rt6_check_expired()
417 struct fib6_info *match = res->f6i; in fib6_select_path()
419 if (!match->nh && (!match->fib6_nsiblings || have_oif_match)) in fib6_select_path()
422 if (match->nh && have_oif_match && res->nh) in fib6_select_path()
426 IP6CB(skb)->flags |= IP6SKB_MULTIPATH; in fib6_select_path()
429 * case it will always be non-zero. Otherwise now is the time to do it. in fib6_select_path()
431 if (!fl6->mp_hash && in fib6_select_path()
432 (!match->nh || nexthop_is_multipath(match->nh))) in fib6_select_path()
433 fl6->mp_hash = rt6_multipath_hash(net, fl6, skb, NULL); in fib6_select_path()
435 if (unlikely(match->nh)) { in fib6_select_path()
436 nexthop_path_fib6_result(res, fl6->mp_hash); in fib6_select_path()
440 if (fl6->mp_hash <= atomic_read(&match->fib6_nh->fib_nh_upper_bound)) in fib6_select_path()
443 list_for_each_entry_safe(sibling, next_sibling, &match->fib6_siblings, in fib6_select_path()
445 const struct fib6_nh *nh = sibling->fib6_nh; in fib6_select_path()
448 nh_upper_bound = atomic_read(&nh->fib_nh_upper_bound); in fib6_select_path()
449 if (fl6->mp_hash > nh_upper_bound) in fib6_select_path()
451 if (rt6_score_route(nh, sibling->fib6_flags, oif, strict) < 0) in fib6_select_path()
458 res->f6i = match; in fib6_select_path()
459 res->nh = match->fib6_nh; in fib6_select_path()
471 if (nh->fib_nh_flags & RTNH_F_DEAD) in __rt6_device_match()
474 dev = nh->fib_nh_dev; in __rt6_device_match()
476 if (dev->ifindex == oif) in __rt6_device_match()
499 arg->nh = nh; in __rt6_nh_dev_match()
500 return __rt6_device_match(arg->net, nh, arg->saddr, arg->oif, in __rt6_nh_dev_match()
501 arg->flags); in __rt6_nh_dev_match()
529 struct fib6_info *f6i = res->f6i; in rt6_device_match()
534 if (unlikely(f6i->nh)) { in rt6_device_match()
535 nh = nexthop_fib6_nh(f6i->nh); in rt6_device_match()
536 if (nexthop_is_blackhole(f6i->nh)) in rt6_device_match()
539 nh = f6i->fib6_nh; in rt6_device_match()
541 if (!(nh->fib_nh_flags & RTNH_F_DEAD)) in rt6_device_match()
545 for (spf6i = f6i; spf6i; spf6i = rcu_dereference(spf6i->fib6_next)) { in rt6_device_match()
548 if (unlikely(spf6i->nh)) { in rt6_device_match()
549 nh = rt6_nh_dev_match(net, spf6i->nh, res, saddr, in rt6_device_match()
554 nh = spf6i->fib6_nh; in rt6_device_match()
559 res->f6i = spf6i; in rt6_device_match()
565 res->f6i = net->ipv6.fib6_null_entry; in rt6_device_match()
566 nh = res->f6i->fib6_nh; in rt6_device_match()
570 if (unlikely(f6i->nh)) { in rt6_device_match()
571 nh = nexthop_fib6_nh(f6i->nh); in rt6_device_match()
572 if (nexthop_is_blackhole(f6i->nh)) in rt6_device_match()
575 nh = f6i->fib6_nh; in rt6_device_match()
578 if (nh->fib_nh_flags & RTNH_F_DEAD) { in rt6_device_match()
579 res->f6i = net->ipv6.fib6_null_entry; in rt6_device_match()
580 nh = res->f6i->fib6_nh; in rt6_device_match()
583 res->nh = nh; in rt6_device_match()
584 res->fib6_type = res->f6i->fib6_type; in rt6_device_match()
585 res->fib6_flags = res->f6i->fib6_flags; in rt6_device_match()
589 res->fib6_flags |= RTF_REJECT; in rt6_device_match()
590 res->fib6_type = RTN_BLACKHOLE; in rt6_device_match()
591 res->nh = nh; in rt6_device_match()
608 addrconf_addr_solict_mult(&work->target, &mcaddr); in rt6_probe_deferred()
609 ndisc_send_ns(work->dev, &work->target, &mcaddr, NULL, 0); in rt6_probe_deferred()
610 netdev_put(work->dev, &work->dev_tracker); in rt6_probe_deferred()
628 * Router Reachability Probe MUST be rate-limited in rt6_probe()
631 if (!fib6_nh->fib_nh_gw_family) in rt6_probe()
634 nh_gw = &fib6_nh->fib_nh_gw6; in rt6_probe()
635 dev = fib6_nh->fib_nh_dev; in rt6_probe()
637 last_probe = READ_ONCE(fib6_nh->last_probe); in rt6_probe()
643 if (READ_ONCE(neigh->nud_state) & NUD_VALID) in rt6_probe()
646 write_lock_bh(&neigh->lock); in rt6_probe()
647 if (!(neigh->nud_state & NUD_VALID) && in rt6_probe()
649 neigh->updated + in rt6_probe()
650 READ_ONCE(idev->cnf.rtr_probe_interval))) { in rt6_probe()
655 write_unlock_bh(&neigh->lock); in rt6_probe()
657 READ_ONCE(idev->cnf.rtr_probe_interval))) { in rt6_probe()
661 if (!work || cmpxchg(&fib6_nh->last_probe, in rt6_probe()
665 INIT_WORK(&work->work, rt6_probe_deferred); in rt6_probe()
666 work->target = *nh_gw; in rt6_probe()
667 netdev_hold(dev, &work->dev_tracker, GFP_ATOMIC); in rt6_probe()
668 work->dev = dev; in rt6_probe()
669 schedule_work(&work->work); in rt6_probe()
690 neigh = __ipv6_neigh_lookup_noref(fib6_nh->fib_nh_dev, in rt6_check_neigh()
691 &fib6_nh->fib_nh_gw6); in rt6_check_neigh()
693 u8 nud_state = READ_ONCE(neigh->nud_state); in rt6_check_neigh()
717 if (!oif || nh->fib_nh_dev->ifindex == oif) in rt6_score_route()
726 !(fib6_flags & RTF_NONEXTHOP) && nh->fib_nh_gw_family) { in rt6_score_route()
741 if (nh->fib_nh_flags & RTNH_F_DEAD) in find_match()
744 if (ip6_ignore_linkdown(nh->fib_nh_dev) && in find_match()
745 nh->fib_nh_flags & RTNH_F_LINKDOWN && in find_match()
783 arg->nh = nh; in rt6_nh_find_match()
784 return find_match(nh, arg->flags, arg->oif, arg->strict, in rt6_nh_find_match()
785 arg->mpri, arg->do_rr); in rt6_nh_find_match()
797 f6i = rcu_dereference(f6i->fib6_next)) { in __find_rr_leaf()
801 if (cont && f6i->fib6_metric != metric) { in __find_rr_leaf()
809 if (unlikely(f6i->nh)) { in __find_rr_leaf()
811 .flags = f6i->fib6_flags, in __find_rr_leaf()
818 if (nexthop_is_blackhole(f6i->nh)) { in __find_rr_leaf()
819 res->fib6_flags = RTF_REJECT; in __find_rr_leaf()
820 res->fib6_type = RTN_BLACKHOLE; in __find_rr_leaf()
821 res->f6i = f6i; in __find_rr_leaf()
822 res->nh = nexthop_fib6_nh(f6i->nh); in __find_rr_leaf()
825 if (nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_find_match, in __find_rr_leaf()
831 nh = f6i->fib6_nh; in __find_rr_leaf()
832 if (find_match(nh, f6i->fib6_flags, oif, strict, in __find_rr_leaf()
837 res->f6i = f6i; in __find_rr_leaf()
838 res->nh = nh; in __find_rr_leaf()
839 res->fib6_flags = f6i->fib6_flags; in __find_rr_leaf()
840 res->fib6_type = f6i->fib6_type; in __find_rr_leaf()
849 u32 metric = rr_head->fib6_metric; in find_rr_leaf()
851 int mpri = -1; in find_rr_leaf()
859 if (res->f6i || !cont) in find_rr_leaf()
869 struct fib6_info *leaf = rcu_dereference(fn->leaf); in rt6_select()
875 res->f6i = NULL; in rt6_select()
877 if (!leaf || leaf == net->ipv6.fib6_null_entry) in rt6_select()
880 rt0 = rcu_dereference(fn->rr_ptr); in rt6_select()
885 * and fn->leaf does not points to its child's leaf in rt6_select()
889 key_plen = rt0->fib6_dst.plen; in rt6_select()
891 if (rt0->fib6_src.plen) in rt6_select()
892 key_plen = rt0->fib6_src.plen; in rt6_select()
894 if (fn->fn_bit != key_plen) in rt6_select()
899 struct fib6_info *next = rcu_dereference(rt0->fib6_next); in rt6_select()
901 /* no entries matched; do round-robin */ in rt6_select()
902 if (!next || next->fib6_metric != rt0->fib6_metric) in rt6_select()
906 spin_lock_bh(&leaf->fib6_table->tb6_lock); in rt6_select()
908 if (next->fib6_node) in rt6_select()
909 rcu_assign_pointer(fn->rr_ptr, next); in rt6_select()
910 spin_unlock_bh(&leaf->fib6_table->tb6_lock); in rt6_select()
915 if (!res->f6i) { in rt6_select()
916 res->f6i = net->ipv6.fib6_null_entry; in rt6_select()
917 res->nh = res->f6i->fib6_nh; in rt6_select()
918 res->fib6_flags = res->f6i->fib6_flags; in rt6_select()
919 res->fib6_type = res->f6i->fib6_type; in rt6_select()
925 return (res->f6i->fib6_flags & RTF_NONEXTHOP) || in rt6_is_gw_or_nonexthop()
926 res->nh->fib_nh_gw_family; in rt6_is_gw_or_nonexthop()
942 return -EINVAL; in rt6_route_rcv()
946 if (rinfo->length > 3) { in rt6_route_rcv()
947 return -EINVAL; in rt6_route_rcv()
948 } else if (rinfo->prefix_len > 128) { in rt6_route_rcv()
949 return -EINVAL; in rt6_route_rcv()
950 } else if (rinfo->prefix_len > 64) { in rt6_route_rcv()
951 if (rinfo->length < 2) { in rt6_route_rcv()
952 return -EINVAL; in rt6_route_rcv()
954 } else if (rinfo->prefix_len > 0) { in rt6_route_rcv()
955 if (rinfo->length < 1) { in rt6_route_rcv()
956 return -EINVAL; in rt6_route_rcv()
960 pref = rinfo->route_pref; in rt6_route_rcv()
962 return -EINVAL; in rt6_route_rcv()
964 lifetime = addrconf_timeout_fixup(ntohl(rinfo->lifetime), HZ); in rt6_route_rcv()
966 if (rinfo->length == 3) in rt6_route_rcv()
967 prefix = (struct in6_addr *)rinfo->prefix; in rt6_route_rcv()
971 (struct in6_addr *)rinfo->prefix, in rt6_route_rcv()
972 rinfo->prefix_len); in rt6_route_rcv()
976 if (rinfo->prefix_len == 0) in rt6_route_rcv()
979 rt = rt6_get_route_info(net, prefix, rinfo->prefix_len, in rt6_route_rcv()
988 rt = rt6_add_route_info(net, prefix, rinfo->prefix_len, gwaddr, in rt6_route_rcv()
991 rt->fib6_flags = RTF_ROUTEINFO | in rt6_route_rcv()
992 (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); in rt6_route_rcv()
995 table = rt->fib6_table; in rt6_route_rcv()
996 spin_lock_bh(&table->tb6_lock); in rt6_route_rcv()
1006 spin_unlock_bh(&table->tb6_lock); in rt6_route_rcv()
1021 struct net_device *dev = res->nh->fib_nh_dev; in ip6_rt_get_dev_rcu()
1023 if (res->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) { in ip6_rt_get_dev_rcu()
1024 /* for copies of local routes, dst->dev needs to be the in ip6_rt_get_dev_rcu()
1029 !rt6_need_strict(&res->f6i->fib6_dst.addr)) in ip6_rt_get_dev_rcu()
1032 dev = dev_net(dev)->loopback_dev; in ip6_rt_get_dev_rcu()
1048 [RTN_BLACKHOLE] = -EINVAL,
1049 [RTN_UNREACHABLE] = -EHOSTUNREACH,
1050 [RTN_PROHIBIT] = -EACCES,
1051 [RTN_THROW] = -EAGAIN,
1052 [RTN_NAT] = -EINVAL,
1053 [RTN_XRESOLVE] = -EINVAL,
1065 if (rt->dst_nocount) in fib6_info_dst_flags()
1067 if (rt->dst_nopolicy) in fib6_info_dst_flags()
1075 rt->dst.error = ip6_rt_type_to_error(fib6_type); in ip6_rt_init_dst_reject()
1079 rt->dst.output = dst_discard_out; in ip6_rt_init_dst_reject()
1080 rt->dst.input = dst_discard; in ip6_rt_init_dst_reject()
1083 rt->dst.output = ip6_pkt_prohibit_out; in ip6_rt_init_dst_reject()
1084 rt->dst.input = ip6_pkt_prohibit; in ip6_rt_init_dst_reject()
1089 rt->dst.output = ip6_pkt_discard_out; in ip6_rt_init_dst_reject()
1090 rt->dst.input = ip6_pkt_discard; in ip6_rt_init_dst_reject()
1097 struct fib6_info *f6i = res->f6i; in ip6_rt_init_dst()
1099 if (res->fib6_flags & RTF_REJECT) { in ip6_rt_init_dst()
1100 ip6_rt_init_dst_reject(rt, res->fib6_type); in ip6_rt_init_dst()
1104 rt->dst.error = 0; in ip6_rt_init_dst()
1105 rt->dst.output = ip6_output; in ip6_rt_init_dst()
1107 if (res->fib6_type == RTN_LOCAL || res->fib6_type == RTN_ANYCAST) { in ip6_rt_init_dst()
1108 rt->dst.input = ip6_input; in ip6_rt_init_dst()
1109 } else if (ipv6_addr_type(&f6i->fib6_dst.addr) & IPV6_ADDR_MULTICAST) { in ip6_rt_init_dst()
1110 rt->dst.input = ip6_mc_input; in ip6_rt_init_dst()
1112 rt->dst.input = ip6_forward; in ip6_rt_init_dst()
1115 if (res->nh->fib_nh_lws) { in ip6_rt_init_dst()
1116 rt->dst.lwtstate = lwtstate_get(res->nh->fib_nh_lws); in ip6_rt_init_dst()
1117 lwtunnel_set_redirect(&rt->dst); in ip6_rt_init_dst()
1120 rt->dst.lastuse = jiffies; in ip6_rt_init_dst()
1126 rt->rt6i_flags &= ~RTF_EXPIRES; in rt6_set_from()
1127 rcu_assign_pointer(rt->from, from); in rt6_set_from()
1128 ip_dst_init_metrics(&rt->dst, from->fib6_metrics); in rt6_set_from()
1134 const struct fib6_nh *nh = res->nh; in ip6_rt_copy_init()
1135 const struct net_device *dev = nh->fib_nh_dev; in ip6_rt_copy_init()
1136 struct fib6_info *f6i = res->f6i; in ip6_rt_copy_init()
1140 rt->rt6i_dst = f6i->fib6_dst; in ip6_rt_copy_init()
1141 rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL; in ip6_rt_copy_init()
1142 rt->rt6i_flags = res->fib6_flags; in ip6_rt_copy_init()
1143 if (nh->fib_nh_gw_family) { in ip6_rt_copy_init()
1144 rt->rt6i_gateway = nh->fib_nh_gw6; in ip6_rt_copy_init()
1145 rt->rt6i_flags |= RTF_GATEWAY; in ip6_rt_copy_init()
1149 rt->rt6i_src = f6i->fib6_src; in ip6_rt_copy_init()
1158 if (fn->fn_flags & RTN_TL_ROOT) in fib6_backtrack()
1160 pn = rcu_dereference(fn->parent); in fib6_backtrack()
1166 if (fn->fn_flags & RTN_RTINFO) in fib6_backtrack()
1175 if (dst_hold_safe(&rt->dst)) in ip6_hold_safe()
1178 rt = net->ipv6.ip6_null_entry; in ip6_hold_safe()
1179 dst_hold(&rt->dst); in ip6_hold_safe()
1190 struct net_device *dev = res->nh->fib_nh_dev; in ip6_create_rt_rcu()
1191 struct fib6_info *f6i = res->f6i; in ip6_create_rt_rcu()
1209 nrt = dev_net(dev)->ipv6.ip6_null_entry; in ip6_create_rt_rcu()
1210 dst_hold(&nrt->dst); in ip6_create_rt_rcu()
1225 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in ip6_pol_route_lookup()
1227 res.f6i = rcu_dereference(fn->leaf); in ip6_pol_route_lookup()
1229 res.f6i = net->ipv6.fib6_null_entry; in ip6_pol_route_lookup()
1231 rt6_device_match(net, &res, &fl6->saddr, fl6->flowi6_oif, in ip6_pol_route_lookup()
1234 if (res.f6i == net->ipv6.fib6_null_entry) { in ip6_pol_route_lookup()
1235 fn = fib6_backtrack(fn, &fl6->saddr); in ip6_pol_route_lookup()
1239 rt = net->ipv6.ip6_null_entry; in ip6_pol_route_lookup()
1240 dst_hold(&rt->dst); in ip6_pol_route_lookup()
1246 fib6_select_path(net, &res, fl6, fl6->flowi6_oif, in ip6_pol_route_lookup()
1247 fl6->flowi6_oif != 0, skb, flags); in ip6_pol_route_lookup()
1250 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route_lookup()
1253 dst_use_noref(&rt->dst, jiffies); in ip6_pol_route_lookup()
1291 if (dst->error == 0) in rt6_lookup()
1300 /* ip6_ins_rt is called with FREE table->tb6_lock.
1312 table = rt->fib6_table; in __ip6_ins_rt()
1313 spin_lock_bh(&table->tb6_lock); in __ip6_ins_rt()
1314 err = fib6_add(&table->tb6_root, rt, info, extack); in __ip6_ins_rt()
1315 spin_unlock_bh(&table->tb6_lock); in __ip6_ins_rt()
1331 struct fib6_info *f6i = res->f6i; in ip6_rt_cache_alloc()
1350 rt->rt6i_flags |= RTF_CACHE; in ip6_rt_cache_alloc()
1351 rt->rt6i_dst.addr = *daddr; in ip6_rt_cache_alloc()
1352 rt->rt6i_dst.plen = 128; in ip6_rt_cache_alloc()
1355 if (f6i->fib6_dst.plen != 128 && in ip6_rt_cache_alloc()
1356 ipv6_addr_equal(&f6i->fib6_dst.addr, daddr)) in ip6_rt_cache_alloc()
1357 rt->rt6i_flags |= RTF_ANYCAST; in ip6_rt_cache_alloc()
1359 if (rt->rt6i_src.plen && saddr) { in ip6_rt_cache_alloc()
1360 rt->rt6i_src.addr = *saddr; in ip6_rt_cache_alloc()
1361 rt->rt6i_src.plen = 128; in ip6_rt_cache_alloc()
1371 struct fib6_info *f6i = res->f6i; in ip6_rt_pcpu_alloc()
1388 pcpu_rt->rt6i_flags |= RTF_PCPU; in ip6_rt_pcpu_alloc()
1390 if (f6i->nh) in ip6_rt_pcpu_alloc()
1391 pcpu_rt->sernum = rt_genid_ipv6(dev_net(dev)); in ip6_rt_pcpu_alloc()
1398 return rt6->sernum == rt_genid_ipv6(dev_net(rt6->dst.dev)); in rt6_is_valid()
1406 pcpu_rt = this_cpu_read(*res->nh->rt6i_pcpu); in rt6_get_pcpu_route()
1408 if (pcpu_rt && pcpu_rt->sernum && !rt6_is_valid(pcpu_rt)) { in rt6_get_pcpu_route()
1411 p = this_cpu_ptr(res->nh->rt6i_pcpu); in rt6_get_pcpu_route()
1415 dst_dev_put(&prev->dst); in rt6_get_pcpu_route()
1416 dst_release(&prev->dst); in rt6_get_pcpu_route()
1434 p = this_cpu_ptr(res->nh->rt6i_pcpu); in rt6_make_pcpu_route()
1438 if (res->f6i->fib6_destroying) { in rt6_make_pcpu_route()
1441 from = unrcu_pointer(xchg(&pcpu_rt->from, NULL)); in rt6_make_pcpu_route()
1464 net = dev_net(rt6_ex->rt6i->dst.dev); in rt6_remove_exception()
1465 net->ipv6.rt6_stats->fib_rt_cache--; in rt6_remove_exception()
1470 from = unrcu_pointer(xchg(&rt6_ex->rt6i->from, NULL)); in rt6_remove_exception()
1472 dst_dev_put(&rt6_ex->rt6i->dst); in rt6_remove_exception()
1474 hlist_del_rcu(&rt6_ex->hlist); in rt6_remove_exception()
1475 dst_release(&rt6_ex->rt6i->dst); in rt6_remove_exception()
1477 WARN_ON_ONCE(!bucket->depth); in rt6_remove_exception()
1478 bucket->depth--; in rt6_remove_exception()
1491 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_exception_remove_oldest()
1492 if (!oldest || time_before(rt6_ex->stamp, oldest->stamp)) in rt6_exception_remove_oldest()
1540 hlist_for_each_entry(rt6_ex, &(*bucket)->chain, hlist) { in __rt6_find_exception_spinlock()
1541 struct rt6_info *rt6 = rt6_ex->rt6i; in __rt6_find_exception_spinlock()
1542 bool matched = ipv6_addr_equal(daddr, &rt6->rt6i_dst.addr); in __rt6_find_exception_spinlock()
1546 matched = ipv6_addr_equal(saddr, &rt6->rt6i_src.addr); in __rt6_find_exception_spinlock()
1575 hlist_for_each_entry_rcu(rt6_ex, &(*bucket)->chain, hlist) { in __rt6_find_exception_rcu()
1576 struct rt6_info *rt6 = rt6_ex->rt6i; in __rt6_find_exception_rcu()
1577 bool matched = ipv6_addr_equal(daddr, &rt6->rt6i_dst.addr); in __rt6_find_exception_rcu()
1581 matched = ipv6_addr_equal(saddr, &rt6->rt6i_src.addr); in __rt6_find_exception_rcu()
1591 const struct fib6_nh *nh = res->nh; in fib6_mtu()
1594 if (res->f6i->fib6_pmtu) { in fib6_mtu()
1595 mtu = res->f6i->fib6_pmtu; in fib6_mtu()
1597 struct net_device *dev = nh->fib_nh_dev; in fib6_mtu()
1602 mtu = READ_ONCE(idev->cnf.mtu6); in fib6_mtu()
1608 return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu); in fib6_mtu()
1625 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in fib6_nh_get_excptn_bucket()
1628 bucket = rcu_dereference(nh->rt6i_exception_bucket); in fib6_nh_get_excptn_bucket()
1655 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in fib6_nh_excptn_bucket_set_flushed()
1661 rcu_assign_pointer(nh->rt6i_exception_bucket, bucket); in fib6_nh_excptn_bucket_set_flushed()
1667 struct net *net = dev_net(nrt->dst.dev); in rt6_insert_exception()
1669 struct fib6_info *f6i = res->f6i; in rt6_insert_exception()
1672 struct fib6_nh *nh = res->nh; in rt6_insert_exception()
1678 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in rt6_insert_exception()
1684 err = -ENOMEM; in rt6_insert_exception()
1687 rcu_assign_pointer(nh->rt6i_exception_bucket, bucket); in rt6_insert_exception()
1689 err = -EINVAL; in rt6_insert_exception()
1700 if (f6i->fib6_src.plen) in rt6_insert_exception()
1701 src_key = &nrt->rt6i_src.addr; in rt6_insert_exception()
1707 if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(res)) { in rt6_insert_exception()
1708 err = -EINVAL; in rt6_insert_exception()
1712 rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr, in rt6_insert_exception()
1719 err = -ENOMEM; in rt6_insert_exception()
1722 rt6_ex->rt6i = nrt; in rt6_insert_exception()
1723 rt6_ex->stamp = jiffies; in rt6_insert_exception()
1724 hlist_add_head_rcu(&rt6_ex->hlist, &bucket->chain); in rt6_insert_exception()
1725 bucket->depth++; in rt6_insert_exception()
1726 net->ipv6.rt6_stats->fib_rt_cache++; in rt6_insert_exception()
1730 while (bucket->depth > max_depth) in rt6_insert_exception()
1736 /* Update fn->fn_sernum to invalidate all cached dst */ in rt6_insert_exception()
1738 spin_lock_bh(&f6i->fib6_table->tb6_lock); in rt6_insert_exception()
1740 spin_unlock_bh(&f6i->fib6_table->tb6_lock); in rt6_insert_exception()
1765 hlist_for_each_entry_safe(rt6_ex, tmp, &bucket->chain, hlist) { in fib6_nh_flush_exceptions()
1767 rcu_access_pointer(rt6_ex->rt6i->from) == from) in fib6_nh_flush_exceptions()
1770 WARN_ON_ONCE(!from && bucket->depth); in fib6_nh_flush_exceptions()
1788 if (f6i->nh) in rt6_flush_exceptions()
1789 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_flush_exceptions, in rt6_flush_exceptions()
1792 fib6_nh_flush_exceptions(f6i->fib6_nh, f6i); in rt6_flush_exceptions()
1814 * So we need to use f6i->fib6_src to redo lookup in rt6_find_cached_rt()
1817 * rt->rt6i_src is updated.) in rt6_find_cached_rt()
1819 if (res->f6i->fib6_src.plen) in rt6_find_cached_rt()
1823 bucket = fib6_nh_get_excptn_bucket(res->nh, NULL); in rt6_find_cached_rt()
1826 if (rt6_ex && !rt6_check_expired(rt6_ex->rt6i)) in rt6_find_cached_rt()
1827 ret = rt6_ex->rt6i; in rt6_find_cached_rt()
1830 /* Use fib6_src as src_key and redo lookup */ in rt6_find_cached_rt()
1831 if (!ret && src_key && src_key != &res->f6i->fib6_src.addr) { in rt6_find_cached_rt()
1832 src_key = &res->f6i->fib6_src.addr; in rt6_find_cached_rt()
1849 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_remove_exception()
1850 return -ENOENT; in fib6_nh_remove_exception()
1863 src_key = &rt->rt6i_src.addr; in fib6_nh_remove_exception()
1866 &rt->rt6i_dst.addr, in fib6_nh_remove_exception()
1872 err = -ENOENT; in fib6_nh_remove_exception()
1889 err = fib6_nh_remove_exception(nh, arg->plen, arg->rt); in rt6_nh_remove_exception_rt()
1900 from = rcu_dereference(rt->from); in rt6_remove_exception_rt()
1901 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_remove_exception_rt()
1902 return -EINVAL; in rt6_remove_exception_rt()
1904 if (from->nh) { in rt6_remove_exception_rt()
1907 .plen = from->fib6_src.plen in rt6_remove_exception_rt()
1912 rc = nexthop_for_each_fib6_nh(from->nh, in rt6_remove_exception_rt()
1915 return rc ? 0 : -ENOENT; in rt6_remove_exception_rt()
1918 return fib6_nh_remove_exception(from->fib6_nh, in rt6_remove_exception_rt()
1919 from->fib6_src.plen, rt); in rt6_remove_exception_rt()
1941 src_key = &rt->rt6i_src.addr; in fib6_nh_update_exception()
1943 rt6_ex = __rt6_find_exception_rcu(&bucket, &rt->rt6i_dst.addr, src_key); in fib6_nh_update_exception()
1945 rt6_ex->stamp = jiffies; in fib6_nh_update_exception()
1959 if (arg->dev != nh->fib_nh_dev || in fib6_nh_find_match()
1960 (arg->gw && !nh->fib_nh_gw_family) || in fib6_nh_find_match()
1961 (!arg->gw && nh->fib_nh_gw_family) || in fib6_nh_find_match()
1962 (arg->gw && !ipv6_addr_equal(arg->gw, &nh->fib_nh_gw6))) in fib6_nh_find_match()
1965 arg->match = nh; in fib6_nh_find_match()
1978 from = rcu_dereference(rt->from); in rt6_update_exception_stamp_rt()
1979 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_update_exception_stamp_rt()
1982 if (from->nh) { in rt6_update_exception_stamp_rt()
1984 .dev = rt->dst.dev, in rt6_update_exception_stamp_rt()
1985 .gw = &rt->rt6i_gateway, in rt6_update_exception_stamp_rt()
1988 nexthop_for_each_fib6_nh(from->nh, fib6_nh_find_match, &arg); in rt6_update_exception_stamp_rt()
1994 fib6_nh = from->fib6_nh; in rt6_update_exception_stamp_rt()
1996 fib6_nh_update_exception(fib6_nh, from->fib6_src.plen, rt); in rt6_update_exception_stamp_rt()
2014 if (dst_mtu(&rt->dst) >= mtu) in rt6_mtu_change_route_allowed()
2017 if (dst_mtu(&rt->dst) == idev->cnf.mtu6) in rt6_mtu_change_route_allowed()
2035 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_exceptions_update_pmtu()
2036 struct rt6_info *entry = rt6_ex->rt6i; in rt6_exceptions_update_pmtu()
2039 * route), the metrics of its rt->from have already in rt6_exceptions_update_pmtu()
2042 if (dst_metric_raw(&entry->dst, RTAX_MTU) && in rt6_exceptions_update_pmtu()
2044 dst_metric_set(&entry->dst, RTAX_MTU, mtu); in rt6_exceptions_update_pmtu()
2060 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_exceptions_clean_tohost()
2068 &bucket->chain, hlist) { in fib6_nh_exceptions_clean_tohost()
2069 struct rt6_info *entry = rt6_ex->rt6i; in fib6_nh_exceptions_clean_tohost()
2071 if ((entry->rt6i_flags & RTF_CACHE_GATEWAY) == in fib6_nh_exceptions_clean_tohost()
2074 &entry->rt6i_gateway)) { in fib6_nh_exceptions_clean_tohost()
2090 struct rt6_info *rt = rt6_ex->rt6i; in rt6_age_examine_exception()
2092 /* we are pruning and obsoleting aged-out and non gateway exceptions in rt6_age_examine_exception()
2095 * EXPIRES exceptions - e.g. pmtu-generated ones are pruned when in rt6_age_examine_exception()
2098 if (!(rt->rt6i_flags & RTF_EXPIRES)) { in rt6_age_examine_exception()
2099 if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) { in rt6_age_examine_exception()
2104 } else if (time_after(jiffies, rt->dst.expires)) { in rt6_age_examine_exception()
2110 if (rt->rt6i_flags & RTF_GATEWAY) { in rt6_age_examine_exception()
2113 neigh = __ipv6_neigh_lookup_noref(rt->dst.dev, &rt->rt6i_gateway); in rt6_age_examine_exception()
2115 if (!(neigh && (neigh->flags & NTF_ROUTER))) { in rt6_age_examine_exception()
2116 pr_debug("purging route %p via non-router but gateway\n", in rt6_age_examine_exception()
2123 gc_args->more++; in rt6_age_examine_exception()
2135 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_age_exceptions()
2144 &bucket->chain, hlist) { in fib6_nh_age_exceptions()
2164 fib6_nh_age_exceptions(nh, arg->gc_args, arg->now); in rt6_nh_age_exceptions()
2172 if (f6i->nh) { in rt6_age_exceptions()
2178 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_age_exceptions, in rt6_age_exceptions()
2181 fib6_nh_age_exceptions(f6i->fib6_nh, gc_args, now); in rt6_age_exceptions()
2191 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in fib6_table_lookup()
2196 if (res->f6i == net->ipv6.fib6_null_entry) { in fib6_table_lookup()
2197 fn = fib6_backtrack(fn, &fl6->saddr); in fib6_table_lookup()
2226 if (READ_ONCE(net->ipv6.devconf_all->forwarding) == 0) in ip6_pol_route()
2232 if (res.f6i == net->ipv6.fib6_null_entry) in ip6_pol_route()
2238 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route()
2241 } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) && in ip6_pol_route()
2242 !res.nh->fib_nh_gw_family)) { in ip6_pol_route()
2245 * the daddr in the skb during the neighbor look-up is different in ip6_pol_route()
2246 * from the fl6->daddr used to look-up route here. in ip6_pol_route()
2248 rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL); in ip6_pol_route()
2273 rt = net->ipv6.ip6_null_entry; in ip6_pol_route()
2288 return ip6_pol_route(net, table, fl6->flowi6_iif, fl6, skb, flags); in ip6_pol_route_input()
2297 if (rt6_need_strict(&fl6->daddr) && dev->type != ARPHRD_PIMREG) in ip6_route_input_lookup()
2316 if (likely(outer_iph->nexthdr != IPPROTO_ICMPV6)) in ip6_multipath_l3_keys()
2324 if (!icmpv6_is_err(icmph->icmp6_type)) in ip6_multipath_l3_keys()
2337 keys->addrs.v6addrs.src = _flkeys->addrs.v6addrs.src; in ip6_multipath_l3_keys()
2338 keys->addrs.v6addrs.dst = _flkeys->addrs.v6addrs.dst; in ip6_multipath_l3_keys()
2339 keys->tags.flow_label = _flkeys->tags.flow_label; in ip6_multipath_l3_keys()
2340 keys->basic.ip_proto = _flkeys->basic.ip_proto; in ip6_multipath_l3_keys()
2342 keys->addrs.v6addrs.src = key_iph->saddr; in ip6_multipath_l3_keys()
2343 keys->addrs.v6addrs.dst = key_iph->daddr; in ip6_multipath_l3_keys()
2344 keys->tags.flow_label = ip6_flowlabel(key_iph); in ip6_multipath_l3_keys()
2345 keys->basic.ip_proto = key_iph->nexthdr; in ip6_multipath_l3_keys()
2453 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_custom_hash_fl6()
2455 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_custom_hash_fl6()
2457 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_custom_hash_fl6()
2461 hash_keys.ports.src = fl6->fl6_sport; in rt6_multipath_custom_hash_fl6()
2463 hash_keys.ports.dst = fl6->fl6_dport; in rt6_multipath_custom_hash_fl6()
2482 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2483 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2485 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2494 /* short-circuit if we already have L4 hash present */ in rt6_multipath_hash()
2495 if (skb->l4_hash) in rt6_multipath_hash()
2505 hash_keys.addrs.v6addrs.src = flkeys->addrs.v6addrs.src; in rt6_multipath_hash()
2506 hash_keys.addrs.v6addrs.dst = flkeys->addrs.v6addrs.dst; in rt6_multipath_hash()
2507 hash_keys.ports.src = flkeys->ports.src; in rt6_multipath_hash()
2508 hash_keys.ports.dst = flkeys->ports.dst; in rt6_multipath_hash()
2509 hash_keys.basic.ip_proto = flkeys->basic.ip_proto; in rt6_multipath_hash()
2513 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2514 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2515 hash_keys.ports.src = fl6->fl6_sport; in rt6_multipath_hash()
2516 hash_keys.ports.dst = fl6->fl6_dport; in rt6_multipath_hash()
2517 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2533 if (flkeys->control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) { in rt6_multipath_hash()
2535 hash_keys.addrs.v4addrs.src = flkeys->addrs.v4addrs.src; in rt6_multipath_hash()
2536 hash_keys.addrs.v4addrs.dst = flkeys->addrs.v4addrs.dst; in rt6_multipath_hash()
2537 } else if (flkeys->control.addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) { in rt6_multipath_hash()
2539 hash_keys.addrs.v6addrs.src = flkeys->addrs.v6addrs.src; in rt6_multipath_hash()
2540 hash_keys.addrs.v6addrs.dst = flkeys->addrs.v6addrs.dst; in rt6_multipath_hash()
2541 hash_keys.tags.flow_label = flkeys->tags.flow_label; in rt6_multipath_hash()
2542 hash_keys.basic.ip_proto = flkeys->basic.ip_proto; in rt6_multipath_hash()
2551 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2552 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2554 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2573 struct net *net = dev_net(skb->dev); in ip6_route_input()
2577 .flowi6_iif = skb->dev->ifindex, in ip6_route_input()
2578 .daddr = iph->daddr, in ip6_route_input()
2579 .saddr = iph->saddr, in ip6_route_input()
2581 .flowi6_mark = skb->mark, in ip6_route_input()
2582 .flowi6_proto = iph->nexthdr, in ip6_route_input()
2587 if (tun_info && !(tun_info->mode & IP_TUNNEL_INFO_TX)) in ip6_route_input()
2588 fl6.flowi6_tun_key.tun_id = tun_info->key.tun_id; in ip6_route_input()
2596 skb_dst_set_noref(skb, ip6_route_input_lookup(net, skb->dev, in ip6_route_input()
2606 return ip6_pol_route(net, table, fl6->flowi6_oif, fl6, skb, flags); in ip6_pol_route_output()
2616 if (ipv6_addr_type(&fl6->daddr) & in ip6_route_output_flags_noref()
2626 fl6->flowi6_iif = LOOPBACK_IFINDEX; in ip6_route_output_flags_noref()
2629 any_src = ipv6_addr_any(&fl6->saddr); in ip6_route_output_flags_noref()
2630 if ((sk && sk->sk_bound_dev_if) || rt6_need_strict(&fl6->daddr) || in ip6_route_output_flags_noref()
2631 (fl6->flowi6_oif && any_src)) in ip6_route_output_flags_noref()
2637 flags |= rt6_srcprefs2flags(READ_ONCE(inet6_sk(sk)->srcprefs)); in ip6_route_output_flags_noref()
2654 if (list_empty(&rt6->dst.rt_uncached) && !dst_hold_safe(dst)) { in ip6_route_output_flags()
2655 dst = &net->ipv6.ip6_null_entry->dst; in ip6_route_output_flags()
2667 struct net_device *loopback_dev = net->loopback_dev; in ip6_blackhole_route()
2674 atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc); in ip6_blackhole_route()
2676 new = &rt->dst; in ip6_blackhole_route()
2677 new->__use = 1; in ip6_blackhole_route()
2678 new->input = dst_discard; in ip6_blackhole_route()
2679 new->output = dst_discard_out; in ip6_blackhole_route()
2681 dst_copy_metrics(new, &ort->dst); in ip6_blackhole_route()
2683 rt->rt6i_idev = in6_dev_get(loopback_dev); in ip6_blackhole_route()
2684 rt->rt6i_gateway = ort->rt6i_gateway; in ip6_blackhole_route()
2685 rt->rt6i_flags = ort->rt6i_flags & ~RTF_PCPU; in ip6_blackhole_route()
2687 memcpy(&rt->rt6i_dst, &ort->rt6i_dst, sizeof(struct rt6key)); in ip6_blackhole_route()
2689 memcpy(&rt->rt6i_src, &ort->rt6i_src, sizeof(struct rt6key)); in ip6_blackhole_route()
2694 return new ? new : ERR_PTR(-ENOMEM); in ip6_blackhole_route()
2727 return &rt->dst; in rt6_check()
2735 rt->dst.obsolete == DST_OBSOLETE_FORCE_CHK && in rt6_dst_from_check()
2737 return &rt->dst; in rt6_dst_from_check()
2751 if (rt->sernum) in ip6_dst_check()
2756 /* All IPV6 dsts are created with ->obsolete set to the value in ip6_dst_check()
2761 from = rcu_dereference(rt->from); in ip6_dst_check()
2763 if (from && (rt->rt6i_flags & RTF_PCPU || in ip6_dst_check()
2764 unlikely(!list_empty(&rt->dst.rt_uncached)))) in ip6_dst_check()
2780 if (rt->rt6i_flags & RTF_CACHE) { in ip6_negative_advice()
2804 if (rt->rt6i_flags & RTF_CACHE) { in ip6_link_failure()
2810 from = rcu_dereference(rt->from); in ip6_link_failure()
2812 fn = rcu_dereference(from->fib6_node); in ip6_link_failure()
2813 if (fn && (rt->rt6i_flags & RTF_DEFAULT)) in ip6_link_failure()
2814 WRITE_ONCE(fn->fn_sernum, -1); in ip6_link_failure()
2823 if (!(rt0->rt6i_flags & RTF_EXPIRES)) { in rt6_update_expires()
2827 from = rcu_dereference(rt0->from); in rt6_update_expires()
2829 rt0->dst.expires = from->expires; in rt6_update_expires()
2833 dst_set_expires(&rt0->dst, timeout); in rt6_update_expires()
2834 rt0->rt6i_flags |= RTF_EXPIRES; in rt6_update_expires()
2839 struct net *net = dev_net(rt->dst.dev); in rt6_do_update_pmtu()
2841 dst_metric_set(&rt->dst, RTAX_MTU, mtu); in rt6_do_update_pmtu()
2842 rt->rt6i_flags |= RTF_MODIFIED; in rt6_do_update_pmtu()
2843 rt6_update_expires(rt, net->ipv6.sysctl.ip6_rt_mtu_expires); in rt6_do_update_pmtu()
2848 return !(rt->rt6i_flags & RTF_CACHE) && in rt6_cache_allowed_for_pmtu()
2849 (rt->rt6i_flags & RTF_PCPU || rcu_access_pointer(rt->from)); in rt6_cache_allowed_for_pmtu()
2865 daddr = &iph->daddr; in __ip6_rt_update_pmtu()
2866 saddr = &iph->saddr; in __ip6_rt_update_pmtu()
2868 daddr = &sk->sk_v6_daddr; in __ip6_rt_update_pmtu()
2869 saddr = &inet6_sk(sk)->saddr; in __ip6_rt_update_pmtu()
2885 /* update rt6_ex->stamp for cache */ in __ip6_rt_update_pmtu()
2886 if (rt6->rt6i_flags & RTF_CACHE) in __ip6_rt_update_pmtu()
2893 res.f6i = rcu_dereference(rt6->from); in __ip6_rt_update_pmtu()
2897 res.fib6_flags = res.f6i->fib6_flags; in __ip6_rt_update_pmtu()
2898 res.fib6_type = res.f6i->fib6_type; in __ip6_rt_update_pmtu()
2900 if (res.f6i->nh) { in __ip6_rt_update_pmtu()
2902 .dev = dst->dev, in __ip6_rt_update_pmtu()
2903 .gw = &rt6->rt6i_gateway, in __ip6_rt_update_pmtu()
2906 nexthop_for_each_fib6_nh(res.f6i->nh, in __ip6_rt_update_pmtu()
2910 * using the dst->dev + gw. Should be impossible. in __ip6_rt_update_pmtu()
2917 res.nh = res.f6i->fib6_nh; in __ip6_rt_update_pmtu()
2924 dst_release_immediate(&nrt6->dst); in __ip6_rt_update_pmtu()
2942 const struct ipv6hdr *iph = (struct ipv6hdr *) skb->data; in ip6_update_pmtu()
2946 .flowi6_mark = mark ? mark : IP6_REPLY_MARK(net, skb->mark), in ip6_update_pmtu()
2947 .daddr = iph->daddr, in ip6_update_pmtu()
2948 .saddr = iph->saddr, in ip6_update_pmtu()
2954 if (!dst->error) in ip6_update_pmtu()
2962 int oif = sk->sk_bound_dev_if; in ip6_sk_update_pmtu()
2965 if (!oif && skb->dev) in ip6_sk_update_pmtu()
2966 oif = l3mdev_master_ifindex(skb->dev); in ip6_sk_update_pmtu()
2968 ip6_update_pmtu(skb, sock_net(sk), mtu, oif, READ_ONCE(sk->sk_mark), in ip6_sk_update_pmtu()
2969 sk->sk_uid); in ip6_sk_update_pmtu()
2972 if (!dst || !dst->obsolete || in ip6_sk_update_pmtu()
2973 dst->ops->check(dst, inet6_sk(sk)->dst_cookie)) in ip6_sk_update_pmtu()
2977 if (!sock_owned_by_user(sk) && !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) in ip6_sk_update_pmtu()
2991 ipv6_addr_equal(&fl6->daddr, &sk->sk_v6_daddr) ? in ip6_sk_dst_store_flow()
2992 &sk->sk_v6_daddr : NULL, in ip6_sk_dst_store_flow()
2994 ipv6_addr_equal(&fl6->saddr, &np->saddr) ? in ip6_sk_dst_store_flow()
2995 &np->saddr : in ip6_sk_dst_store_flow()
3005 const struct fib6_nh *nh = res->nh; in ip6_redirect_nh_match()
3007 if (nh->fib_nh_flags & RTNH_F_DEAD || !nh->fib_nh_gw_family || in ip6_redirect_nh_match()
3008 fl6->flowi6_oif != nh->fib_nh_dev->ifindex) in ip6_redirect_nh_match()
3016 if (!ipv6_addr_equal(gw, &nh->fib_nh_gw6)) { in ip6_redirect_nh_match()
3019 rt_cache = rt6_find_cached_rt(res, &fl6->daddr, &fl6->saddr); in ip6_redirect_nh_match()
3021 ipv6_addr_equal(gw, &rt_cache->rt6i_gateway)) { in ip6_redirect_nh_match()
3041 arg->res->nh = nh; in fib6_nh_redirect_match()
3042 return ip6_redirect_nh_match(arg->res, arg->fl6, arg->gw, arg->ret); in fib6_nh_redirect_match()
3063 .gw = &rdfl->gateway, in __ip6_route_redirect()
3080 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in __ip6_route_redirect()
3086 if (rt->fib6_flags & RTF_REJECT) in __ip6_route_redirect()
3088 if (unlikely(rt->nh)) { in __ip6_route_redirect()
3089 if (nexthop_is_blackhole(rt->nh)) in __ip6_route_redirect()
3091 /* on match, res->nh is filled in and potentially ret */ in __ip6_route_redirect()
3092 if (nexthop_for_each_fib6_nh(rt->nh, in __ip6_route_redirect()
3097 res.nh = rt->fib6_nh; in __ip6_route_redirect()
3098 if (ip6_redirect_nh_match(&res, fl6, &rdfl->gateway, in __ip6_route_redirect()
3105 rt = net->ipv6.fib6_null_entry; in __ip6_route_redirect()
3106 else if (rt->fib6_flags & RTF_REJECT) { in __ip6_route_redirect()
3107 ret = net->ipv6.ip6_null_entry; in __ip6_route_redirect()
3111 if (rt == net->ipv6.fib6_null_entry) { in __ip6_route_redirect()
3112 fn = fib6_backtrack(fn, &fl6->saddr); in __ip6_route_redirect()
3118 res.nh = rt->fib6_nh; in __ip6_route_redirect()
3123 res.fib6_flags = res.f6i->fib6_flags; in __ip6_route_redirect()
3124 res.fib6_type = res.f6i->fib6_type; in __ip6_route_redirect()
3152 const struct ipv6hdr *iph = (struct ipv6hdr *) skb->data; in ip6_redirect()
3158 .daddr = iph->daddr, in ip6_redirect()
3159 .saddr = iph->saddr, in ip6_redirect()
3164 dst = ip6_route_redirect(net, &fl6, skb, &ipv6_hdr(skb)->saddr); in ip6_redirect()
3178 .daddr = msg->dest, in ip6_redirect_no_header()
3179 .saddr = iph->daddr, in ip6_redirect_no_header()
3183 dst = ip6_route_redirect(net, &fl6, skb, &iph->saddr); in ip6_redirect_no_header()
3190 ip6_redirect(skb, sock_net(sk), sk->sk_bound_dev_if, in ip6_sk_redirect()
3191 READ_ONCE(sk->sk_mark), sk->sk_uid); in ip6_sk_redirect()
3197 struct net_device *dev = dst->dev; in ip6_default_advmss()
3201 mtu -= sizeof(struct ipv6hdr) + sizeof(struct tcphdr); in ip6_default_advmss()
3203 if (mtu < net->ipv6.sysctl.ip6_rt_min_advmss) in ip6_default_advmss()
3204 mtu = net->ipv6.sysctl.ip6_rt_min_advmss; in ip6_default_advmss()
3207 * Maximal non-jumbo IPv6 payload is IPV6_MAXPLEN and in ip6_default_advmss()
3208 * corresponding MSS is IPV6_MAXPLEN - tcp_header_size. in ip6_default_advmss()
3212 if (mtu > IPV6_MAXPLEN - sizeof(struct tcphdr)) in ip6_default_advmss()
3224 * 1. mtu on route is locked - use it
3235 const struct fib6_nh *nh = res->nh; in ip6_mtu_from_fib6()
3236 struct fib6_info *f6i = res->f6i; in ip6_mtu_from_fib6()
3242 mtu = f6i->fib6_pmtu; in ip6_mtu_from_fib6()
3249 mtu = dst_metric_raw(&rt->dst, RTAX_MTU); in ip6_mtu_from_fib6()
3251 struct net_device *dev = nh->fib_nh_dev; in ip6_mtu_from_fib6()
3256 mtu = max_t(u32, mtu, READ_ONCE(idev->cnf.mtu6)); in ip6_mtu_from_fib6()
3261 return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu); in ip6_mtu_from_fib6()
3273 return ERR_PTR(-ENODEV); in icmp6_dst_alloc()
3278 dst = ERR_PTR(-ENOMEM); in icmp6_dst_alloc()
3282 rt->dst.input = ip6_input; in icmp6_dst_alloc()
3283 rt->dst.output = ip6_output; in icmp6_dst_alloc()
3284 rt->rt6i_gateway = fl6->daddr; in icmp6_dst_alloc()
3285 rt->rt6i_dst.addr = fl6->daddr; in icmp6_dst_alloc()
3286 rt->rt6i_dst.plen = 128; in icmp6_dst_alloc()
3287 rt->rt6i_idev = idev; in icmp6_dst_alloc()
3288 dst_metric_set(&rt->dst, RTAX_HOPLIMIT, 0); in icmp6_dst_alloc()
3295 dst = xfrm_lookup(net, &rt->dst, flowi6_to_flowi(fl6), NULL, 0); in icmp6_dst_alloc()
3304 int rt_min_interval = net->ipv6.sysctl.ip6_rt_gc_min_interval; in ip6_dst_gc()
3305 int rt_elasticity = net->ipv6.sysctl.ip6_rt_gc_elasticity; in ip6_dst_gc()
3306 int rt_gc_timeout = net->ipv6.sysctl.ip6_rt_gc_timeout; in ip6_dst_gc()
3307 unsigned long rt_last_gc = net->ipv6.ip6_rt_last_gc; in ip6_dst_gc()
3314 fib6_run_gc(atomic_inc_return(&net->ipv6.ip6_rt_gc_expire), net, true); in ip6_dst_gc()
3316 if (entries < ops->gc_thresh) in ip6_dst_gc()
3317 atomic_set(&net->ipv6.ip6_rt_gc_expire, rt_gc_timeout >> 1); in ip6_dst_gc()
3319 val = atomic_read(&net->ipv6.ip6_rt_gc_expire); in ip6_dst_gc()
3320 atomic_set(&net->ipv6.ip6_rt_gc_expire, val - (val >> rt_elasticity)); in ip6_dst_gc()
3328 .flowi6_oif = cfg->fc_ifindex, in ip6_nh_lookup_table()
3330 .saddr = cfg->fc_prefsrc, in ip6_nh_lookup_table()
3337 return -EINVAL; in ip6_nh_lookup_table()
3339 if (!ipv6_addr_any(&cfg->fc_prefsrc)) in ip6_nh_lookup_table()
3344 err = fib6_table_lookup(net, table, cfg->fc_ifindex, &fl6, res, flags); in ip6_nh_lookup_table()
3345 if (!err && res->f6i != net->ipv6.fib6_null_entry) in ip6_nh_lookup_table()
3346 fib6_select_path(net, res, &fl6, cfg->fc_ifindex, in ip6_nh_lookup_table()
3347 cfg->fc_ifindex != 0, NULL, flags); in ip6_nh_lookup_table()
3358 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_route_check_nh_onlink()
3365 !ipv6_addr_any(&res.f6i->fib6_dst.addr) && in ip6_route_check_nh_onlink()
3366 (res.fib6_type != RTN_UNICAST || dev != res.nh->fib_nh_dev)) { in ip6_route_check_nh_onlink()
3369 err = -EINVAL; in ip6_route_check_nh_onlink()
3381 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_route_check_nh()
3385 int err = -EHOSTUNREACH; in ip6_route_check_nh()
3387 if (cfg->fc_table) { in ip6_route_check_nh()
3389 cfg->fc_table, flags, &res); in ip6_route_check_nh()
3394 res.nh->fib_nh_gw_family || in ip6_route_check_nh()
3395 (dev && dev != res.nh->fib_nh_dev)) in ip6_route_check_nh()
3396 err = -EHOSTUNREACH; in ip6_route_check_nh()
3401 .flowi6_oif = cfg->fc_ifindex, in ip6_route_check_nh()
3405 err = fib6_lookup(net, cfg->fc_ifindex, &fl6, &res, flags); in ip6_route_check_nh()
3407 res.nh->fib_nh_gw_family) in ip6_route_check_nh()
3408 err = -EHOSTUNREACH; in ip6_route_check_nh()
3413 fib6_select_path(net, &res, &fl6, cfg->fc_ifindex, in ip6_route_check_nh()
3414 cfg->fc_ifindex != 0, NULL, flags); in ip6_route_check_nh()
3419 if (dev != res.nh->fib_nh_dev) in ip6_route_check_nh()
3420 err = -EHOSTUNREACH; in ip6_route_check_nh()
3422 *_dev = dev = res.nh->fib_nh_dev; in ip6_route_check_nh()
3436 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_validate_gw()
3441 int err = -EINVAL; in ip6_validate_gw()
3445 * will return already-added prefix route via interface that in ip6_validate_gw()
3446 * prefix route was assigned to, which might be non-loopback. in ip6_validate_gw()
3455 /* IPv6 strictly inhibits using not link-local in ip6_validate_gw()
3460 * some exceptions. --ANK in ip6_validate_gw()
3461 * We allow IPv4-mapped nexthops to support RFC4798-type in ip6_validate_gw()
3471 if (cfg->fc_flags & RTNH_F_ONLINK) in ip6_validate_gw()
3486 err = -EINVAL; in ip6_validate_gw()
3490 } else if (dev->flags & IFF_LOOPBACK) { in ip6_validate_gw()
3513 (dev && (dev->flags & IFF_LOOPBACK) && in fib6_is_reject()
3525 netdevice_tracker *dev_tracker = &fib6_nh->fib_nh_dev_tracker; in fib6_nh_init()
3531 fib6_nh->fib_nh_family = AF_INET6; in fib6_nh_init()
3533 fib6_nh->last_probe = jiffies; in fib6_nh_init()
3535 if (cfg->fc_is_fdb) { in fib6_nh_init()
3536 fib6_nh->fib_nh_gw6 = cfg->fc_gateway; in fib6_nh_init()
3537 fib6_nh->fib_nh_gw_family = AF_INET6; in fib6_nh_init()
3541 err = -ENODEV; in fib6_nh_init()
3542 if (cfg->fc_ifindex) { in fib6_nh_init()
3543 dev = netdev_get_by_index(net, cfg->fc_ifindex, in fib6_nh_init()
3552 if (cfg->fc_flags & RTNH_F_ONLINK) { in fib6_nh_init()
3559 if (!(dev->flags & IFF_UP)) { in fib6_nh_init()
3561 err = -ENETDOWN; in fib6_nh_init()
3565 fib6_nh->fib_nh_flags |= RTNH_F_ONLINK; in fib6_nh_init()
3568 fib6_nh->fib_nh_weight = 1; in fib6_nh_init()
3573 addr_type = ipv6_addr_type(&cfg->fc_dst); in fib6_nh_init()
3574 if (fib6_is_reject(cfg->fc_flags, dev, addr_type)) { in fib6_nh_init()
3576 if (dev != net->loopback_dev) { in fib6_nh_init()
3581 dev = net->loopback_dev; in fib6_nh_init()
3585 err = -ENODEV; in fib6_nh_init()
3592 if (cfg->fc_flags & RTF_GATEWAY) { in fib6_nh_init()
3598 fib6_nh->fib_nh_gw6 = cfg->fc_gateway; in fib6_nh_init()
3599 fib6_nh->fib_nh_gw_family = AF_INET6; in fib6_nh_init()
3602 err = -ENODEV; in fib6_nh_init()
3606 if (!idev || idev->cnf.disable_ipv6) { in fib6_nh_init()
3608 err = -EACCES; in fib6_nh_init()
3612 if (!(dev->flags & IFF_UP) && !cfg->fc_ignore_dev_down) { in fib6_nh_init()
3614 err = -ENETDOWN; in fib6_nh_init()
3618 if (!(cfg->fc_flags & (RTF_LOCAL | RTF_ANYCAST)) && in fib6_nh_init()
3620 fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib6_nh_init()
3622 err = fib_nh_common_init(net, &fib6_nh->nh_common, cfg->fc_encap, in fib6_nh_init()
3623 cfg->fc_encap_type, cfg, gfp_flags, extack); in fib6_nh_init()
3628 fib6_nh->rt6i_pcpu = alloc_percpu_gfp(struct rt6_info *, gfp_flags); in fib6_nh_init()
3629 if (!fib6_nh->rt6i_pcpu) { in fib6_nh_init()
3630 err = -ENOMEM; in fib6_nh_init()
3634 fib6_nh->fib_nh_dev = dev; in fib6_nh_init()
3635 fib6_nh->fib_nh_oif = dev->ifindex; in fib6_nh_init()
3642 lwtstate_put(fib6_nh->fib_nh_lws); in fib6_nh_init()
3643 fib6_nh->fib_nh_lws = NULL; in fib6_nh_init()
3659 rcu_assign_pointer(fib6_nh->rt6i_exception_bucket, NULL); in fib6_nh_release()
3666 free_percpu(fib6_nh->rt6i_pcpu); in fib6_nh_release()
3668 fib_nh_common_release(&fib6_nh->nh_common); in fib6_nh_release()
3675 if (!fib6_nh->rt6i_pcpu) in fib6_nh_release_dsts()
3681 ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu); in fib6_nh_release_dsts()
3684 dst_dev_put(&pcpu_rt->dst); in fib6_nh_release_dsts()
3685 dst_release(&pcpu_rt->dst); in fib6_nh_release_dsts()
3694 struct net *net = cfg->fc_nlinfo.nl_net; in ip6_route_info_create()
3699 int err = -EINVAL; in ip6_route_info_create()
3703 if (cfg->fc_flags & RTF_PCPU) { in ip6_route_info_create()
3709 if (cfg->fc_flags & RTF_CACHE) { in ip6_route_info_create()
3714 if (cfg->fc_type > RTN_MAX) { in ip6_route_info_create()
3719 if (cfg->fc_dst_len > 128) { in ip6_route_info_create()
3723 if (cfg->fc_src_len > 128) { in ip6_route_info_create()
3728 if (cfg->fc_src_len) { in ip6_route_info_create()
3734 if (cfg->fc_nh_id) { in ip6_route_info_create()
3735 nh = nexthop_find_by_id(net, cfg->fc_nh_id); in ip6_route_info_create()
3745 err = -ENOBUFS; in ip6_route_info_create()
3746 if (cfg->fc_nlinfo.nlh && in ip6_route_info_create()
3747 !(cfg->fc_nlinfo.nlh->nlmsg_flags & NLM_F_CREATE)) { in ip6_route_info_create()
3748 table = fib6_get_table(net, cfg->fc_table); in ip6_route_info_create()
3751 table = fib6_new_table(net, cfg->fc_table); in ip6_route_info_create()
3754 table = fib6_new_table(net, cfg->fc_table); in ip6_route_info_create()
3760 err = -ENOMEM; in ip6_route_info_create()
3765 rt->fib6_metrics = ip_fib_metrics_init(cfg->fc_mx, cfg->fc_mx_len, in ip6_route_info_create()
3767 if (IS_ERR(rt->fib6_metrics)) { in ip6_route_info_create()
3768 err = PTR_ERR(rt->fib6_metrics); in ip6_route_info_create()
3770 rt->fib6_metrics = (struct dst_metrics *)&dst_default_metrics; in ip6_route_info_create()
3774 if (cfg->fc_flags & RTF_ADDRCONF) in ip6_route_info_create()
3775 rt->dst_nocount = true; in ip6_route_info_create()
3777 if (cfg->fc_flags & RTF_EXPIRES) in ip6_route_info_create()
3779 clock_t_to_jiffies(cfg->fc_expires)); in ip6_route_info_create()
3781 if (cfg->fc_protocol == RTPROT_UNSPEC) in ip6_route_info_create()
3782 cfg->fc_protocol = RTPROT_BOOT; in ip6_route_info_create()
3783 rt->fib6_protocol = cfg->fc_protocol; in ip6_route_info_create()
3785 rt->fib6_table = table; in ip6_route_info_create()
3786 rt->fib6_metric = cfg->fc_metric; in ip6_route_info_create()
3787 rt->fib6_type = cfg->fc_type ? : RTN_UNICAST; in ip6_route_info_create()
3788 rt->fib6_flags = cfg->fc_flags & ~RTF_GATEWAY; in ip6_route_info_create()
3790 ipv6_addr_prefix(&rt->fib6_dst.addr, &cfg->fc_dst, cfg->fc_dst_len); in ip6_route_info_create()
3791 rt->fib6_dst.plen = cfg->fc_dst_len; in ip6_route_info_create()
3794 ipv6_addr_prefix(&rt->fib6_src.addr, &cfg->fc_src, cfg->fc_src_len); in ip6_route_info_create()
3795 rt->fib6_src.plen = cfg->fc_src_len; in ip6_route_info_create()
3798 if (rt->fib6_src.plen) { in ip6_route_info_create()
3806 rt->nh = nh; in ip6_route_info_create()
3807 fib6_nh = nexthop_fib6_nh(rt->nh); in ip6_route_info_create()
3809 err = fib6_nh_init(net, rt->fib6_nh, cfg, gfp_flags, extack); in ip6_route_info_create()
3813 fib6_nh = rt->fib6_nh; in ip6_route_info_create()
3818 addr_type = ipv6_addr_type(&cfg->fc_dst); in ip6_route_info_create()
3819 if (fib6_is_reject(cfg->fc_flags, rt->fib6_nh->fib_nh_dev, in ip6_route_info_create()
3821 rt->fib6_flags = RTF_REJECT | RTF_NONEXTHOP; in ip6_route_info_create()
3824 if (!ipv6_addr_any(&cfg->fc_prefsrc)) { in ip6_route_info_create()
3825 struct net_device *dev = fib6_nh->fib_nh_dev; in ip6_route_info_create()
3827 if (!ipv6_chk_addr(net, &cfg->fc_prefsrc, dev, 0)) { in ip6_route_info_create()
3829 err = -EINVAL; in ip6_route_info_create()
3832 rt->fib6_prefsrc.addr = cfg->fc_prefsrc; in ip6_route_info_create()
3833 rt->fib6_prefsrc.plen = 128; in ip6_route_info_create()
3835 rt->fib6_prefsrc.plen = 0; in ip6_route_info_create()
3842 ip_fib_metrics_put(rt->fib6_metrics); in ip6_route_info_create()
3857 err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, extack); in ip6_route_add()
3865 struct net *net = info->nl_net; in __ip6_del_rt()
3869 if (rt == net->ipv6.fib6_null_entry) { in __ip6_del_rt()
3870 err = -ENOENT; in __ip6_del_rt()
3874 table = rt->fib6_table; in __ip6_del_rt()
3875 spin_lock_bh(&table->tb6_lock); in __ip6_del_rt()
3877 spin_unlock_bh(&table->tb6_lock); in __ip6_del_rt()
3896 struct nl_info *info = &cfg->fc_nlinfo; in __ip6_del_rt_siblings()
3897 struct net *net = info->nl_net; in __ip6_del_rt_siblings()
3900 int err = -ENOENT; in __ip6_del_rt_siblings()
3902 if (rt == net->ipv6.fib6_null_entry) in __ip6_del_rt_siblings()
3904 table = rt->fib6_table; in __ip6_del_rt_siblings()
3905 spin_lock_bh(&table->tb6_lock); in __ip6_del_rt_siblings()
3907 if (rt->fib6_nsiblings && cfg->fc_delete_all_nh) { in __ip6_del_rt_siblings()
3914 u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in __ip6_del_rt_siblings()
3918 info->portid, seq, 0) < 0) { in __ip6_del_rt_siblings()
3922 info->skip_notify = 1; in __ip6_del_rt_siblings()
3930 info->skip_notify_kernel = 1; in __ip6_del_rt_siblings()
3931 fn = rcu_dereference_protected(rt->fib6_node, in __ip6_del_rt_siblings()
3932 lockdep_is_held(&table->tb6_lock)); in __ip6_del_rt_siblings()
3933 if (rcu_access_pointer(fn->leaf) == rt) { in __ip6_del_rt_siblings()
3936 last_sibling = list_last_entry(&rt->fib6_siblings, in __ip6_del_rt_siblings()
3940 last_sibling->fib6_next, in __ip6_del_rt_siblings()
3941 lockdep_is_held(&table->tb6_lock)); in __ip6_del_rt_siblings()
3948 rt, rt->fib6_nsiblings, in __ip6_del_rt_siblings()
3952 &rt->fib6_siblings, in __ip6_del_rt_siblings()
3962 spin_unlock_bh(&table->tb6_lock); in __ip6_del_rt_siblings()
3967 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in __ip6_del_rt_siblings()
3968 info->nlh, gfp_any()); in __ip6_del_rt_siblings()
3975 int rc = -ESRCH; in __ip6_del_cached_rt()
3977 if (cfg->fc_ifindex && rt->dst.dev->ifindex != cfg->fc_ifindex) in __ip6_del_cached_rt()
3980 if (cfg->fc_flags & RTF_GATEWAY && in __ip6_del_cached_rt()
3981 !ipv6_addr_equal(&cfg->fc_gateway, &rt->rt6i_gateway)) in __ip6_del_cached_rt()
3998 rt_cache = rt6_find_cached_rt(&res, &cfg->fc_dst, &cfg->fc_src); in ip6_del_cached_rt()
4015 rc = ip6_del_cached_rt(arg->cfg, arg->f6i, nh); in fib6_nh_del_cached_rt()
4016 return rc != -ESRCH ? rc : 0; in fib6_nh_del_cached_rt()
4026 return nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_del_cached_rt, &arg); in ip6_del_cached_rt_nh()
4035 int err = -ESRCH; in ip6_route_del()
4037 table = fib6_get_table(cfg->fc_nlinfo.nl_net, cfg->fc_table); in ip6_route_del()
4045 fn = fib6_locate(&table->tb6_root, in ip6_route_del()
4046 &cfg->fc_dst, cfg->fc_dst_len, in ip6_route_del()
4047 &cfg->fc_src, cfg->fc_src_len, in ip6_route_del()
4048 !(cfg->fc_flags & RTF_CACHE)); in ip6_route_del()
4054 if (rt->nh && cfg->fc_nh_id && in ip6_route_del()
4055 rt->nh->id != cfg->fc_nh_id) in ip6_route_del()
4058 if (cfg->fc_flags & RTF_CACHE) { in ip6_route_del()
4061 if (rt->nh) { in ip6_route_del()
4063 } else if (cfg->fc_nh_id) { in ip6_route_del()
4066 nh = rt->fib6_nh; in ip6_route_del()
4069 if (rc != -ESRCH) { in ip6_route_del()
4076 if (cfg->fc_metric && cfg->fc_metric != rt->fib6_metric) in ip6_route_del()
4078 if (cfg->fc_protocol && in ip6_route_del()
4079 cfg->fc_protocol != rt->fib6_protocol) in ip6_route_del()
4082 if (rt->nh) { in ip6_route_del()
4087 return __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
4089 if (cfg->fc_nh_id) in ip6_route_del()
4092 nh = rt->fib6_nh; in ip6_route_del()
4093 if (cfg->fc_ifindex && in ip6_route_del()
4094 (!nh->fib_nh_dev || in ip6_route_del()
4095 nh->fib_nh_dev->ifindex != cfg->fc_ifindex)) in ip6_route_del()
4097 if (cfg->fc_flags & RTF_GATEWAY && in ip6_route_del()
4098 !ipv6_addr_equal(&cfg->fc_gateway, &nh->fib_nh_gw6)) in ip6_route_del()
4105 if (cfg->fc_flags & RTF_GATEWAY) in ip6_route_del()
4106 return __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
4128 optlen = skb_tail_pointer(skb) - skb_transport_header(skb); in rt6_do_redirect()
4129 optlen -= sizeof(*msg); in rt6_do_redirect()
4138 if (ipv6_addr_is_multicast(&msg->dest)) { in rt6_do_redirect()
4144 if (ipv6_addr_equal(&msg->dest, &msg->target)) { in rt6_do_redirect()
4146 } else if (ipv6_addr_type(&msg->target) != in rt6_do_redirect()
4148 net_dbg_ratelimited("rt6_do_redirect: target address is not link-local unicast\n"); in rt6_do_redirect()
4152 in6_dev = __in6_dev_get(skb->dev); in rt6_do_redirect()
4155 if (READ_ONCE(in6_dev->cnf.forwarding) || in rt6_do_redirect()
4156 !READ_ONCE(in6_dev->cnf.accept_redirects)) in rt6_do_redirect()
4161 * first-hop router for the specified ICMP Destination Address. in rt6_do_redirect()
4164 if (!ndisc_parse_options(skb->dev, msg->opt, optlen, &ndopts)) { in rt6_do_redirect()
4172 skb->dev); in rt6_do_redirect()
4174 net_dbg_ratelimited("rt6_redirect: invalid link-layer address length\n"); in rt6_do_redirect()
4180 if (rt->rt6i_flags & RTF_REJECT) { in rt6_do_redirect()
4185 /* Redirect received -> path was valid. in rt6_do_redirect()
4187 * so that this nexthop apparently is reachable. --ANK in rt6_do_redirect()
4189 dst_confirm_neigh(&rt->dst, &ipv6_hdr(skb)->saddr); in rt6_do_redirect()
4191 neigh = __neigh_lookup(&nd_tbl, &msg->target, skb->dev, 1); in rt6_do_redirect()
4199 ndisc_update(skb->dev, neigh, lladdr, NUD_STALE, in rt6_do_redirect()
4207 res.f6i = rcu_dereference(rt->from); in rt6_do_redirect()
4211 if (res.f6i->nh) { in rt6_do_redirect()
4213 .dev = dst->dev, in rt6_do_redirect()
4214 .gw = &rt->rt6i_gateway, in rt6_do_redirect()
4217 nexthop_for_each_fib6_nh(res.f6i->nh, in rt6_do_redirect()
4221 * using the dst->dev. Should be impossible in rt6_do_redirect()
4227 res.nh = res.f6i->fib6_nh; in rt6_do_redirect()
4230 res.fib6_flags = res.f6i->fib6_flags; in rt6_do_redirect()
4231 res.fib6_type = res.f6i->fib6_type; in rt6_do_redirect()
4232 nrt = ip6_rt_cache_alloc(&res, &msg->dest, NULL); in rt6_do_redirect()
4236 nrt->rt6i_flags = RTF_GATEWAY|RTF_UP|RTF_DYNAMIC|RTF_CACHE; in rt6_do_redirect()
4238 nrt->rt6i_flags &= ~RTF_GATEWAY; in rt6_do_redirect()
4240 nrt->rt6i_gateway = *(struct in6_addr *)neigh->primary_key; in rt6_do_redirect()
4244 dst_release_immediate(&nrt->dst); in rt6_do_redirect()
4248 netevent.old = &rt->dst; in rt6_do_redirect()
4249 netevent.new = &nrt->dst; in rt6_do_redirect()
4250 netevent.daddr = &msg->dest; in rt6_do_redirect()
4266 int ifindex = dev->ifindex; in rt6_get_route_info()
4276 fn = fib6_locate(&table->tb6_root, prefix, prefixlen, NULL, 0, true); in rt6_get_route_info()
4281 /* these routes do not use nexthops */ in rt6_get_route_info()
4282 if (rt->nh) in rt6_get_route_info()
4284 if (rt->fib6_nh->fib_nh_dev->ifindex != ifindex) in rt6_get_route_info()
4286 if (!(rt->fib6_flags & RTF_ROUTEINFO) || in rt6_get_route_info()
4287 !rt->fib6_nh->fib_nh_gw_family) in rt6_get_route_info()
4289 if (!ipv6_addr_equal(&rt->fib6_nh->fib_nh_gw6, gwaddr)) in rt6_get_route_info()
4308 .fc_ifindex = dev->ifindex, in rt6_add_route_info()
4346 for_each_fib6_node_rt_rcu(&table->tb6_root) { in rt6_get_dflt_router()
4349 /* RA routes do not use nexthops */ in rt6_get_dflt_router()
4350 if (rt->nh) in rt6_get_dflt_router()
4353 nh = rt->fib6_nh; in rt6_get_dflt_router()
4354 if (dev == nh->fib_nh_dev && in rt6_get_dflt_router()
4355 ((rt->fib6_flags & (RTF_ADDRCONF | RTF_DEFAULT)) == (RTF_ADDRCONF | RTF_DEFAULT)) && in rt6_get_dflt_router()
4356 ipv6_addr_equal(&nh->fib_nh_gw6, addr)) in rt6_get_dflt_router()
4375 .fc_ifindex = dev->ifindex, in rt6_add_dflt_router()
4393 table->flags |= RT6_TABLE_HAS_DFLT_ROUTER; in rt6_add_dflt_router()
4406 for_each_fib6_node_rt_rcu(&table->tb6_root) { in __rt6_purge_dflt_routers()
4410 if (rt->fib6_flags & (RTF_DEFAULT | RTF_ADDRCONF) && in __rt6_purge_dflt_routers()
4411 (!idev || idev->cnf.accept_ra != 2) && in __rt6_purge_dflt_routers()
4420 table->flags &= ~RT6_TABLE_HAS_DFLT_ROUTER; in __rt6_purge_dflt_routers()
4432 head = &net->ipv6.fib_table_hash[h]; in rt6_purge_dflt_routers()
4434 if (table->flags & RT6_TABLE_HAS_DFLT_ROUTER) in rt6_purge_dflt_routers()
4447 .fc_table = l3mdev_fib_table_by_index(net, rtmsg->rtmsg_ifindex) ? in rtmsg_to_fib6_config()
4449 .fc_ifindex = rtmsg->rtmsg_ifindex, in rtmsg_to_fib6_config()
4450 .fc_metric = rtmsg->rtmsg_metric, in rtmsg_to_fib6_config()
4451 .fc_expires = rtmsg->rtmsg_info, in rtmsg_to_fib6_config()
4452 .fc_dst_len = rtmsg->rtmsg_dst_len, in rtmsg_to_fib6_config()
4453 .fc_src_len = rtmsg->rtmsg_src_len, in rtmsg_to_fib6_config()
4454 .fc_flags = rtmsg->rtmsg_flags, in rtmsg_to_fib6_config()
4455 .fc_type = rtmsg->rtmsg_type, in rtmsg_to_fib6_config()
4459 .fc_dst = rtmsg->rtmsg_dst, in rtmsg_to_fib6_config()
4460 .fc_src = rtmsg->rtmsg_src, in rtmsg_to_fib6_config()
4461 .fc_gateway = rtmsg->rtmsg_gateway, in rtmsg_to_fib6_config()
4471 return -EINVAL; in ipv6_route_ioctl()
4472 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in ipv6_route_ioctl()
4473 return -EPERM; in ipv6_route_ioctl()
4500 struct net *net = dev_net(dst->dev); in ip6_pkt_drop()
4505 if (netif_is_l3_master(skb->dev) || in ip6_pkt_drop()
4506 dst->dev == net->loopback_dev) in ip6_pkt_drop()
4507 idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif)); in ip6_pkt_drop()
4513 type = ipv6_addr_type(&ipv6_hdr(skb)->daddr); in ip6_pkt_drop()
4528 if (netif_is_l3_master(skb->dev)) in ip6_pkt_drop()
4543 skb->dev = skb_dst(skb)->dev; in ip6_pkt_discard_out()
4554 skb->dev = skb_dst(skb)->dev; in ip6_pkt_prohibit_out()
4569 .fc_table = l3mdev_fib_table(idev->dev) ? : RT6_TABLE_LOCAL, in addrconf_f6i_alloc()
4570 .fc_ifindex = idev->dev->ifindex, in addrconf_f6i_alloc()
4590 f6i->dst_nocount = true; in addrconf_f6i_alloc()
4593 (READ_ONCE(net->ipv6.devconf_all->disable_policy) || in addrconf_f6i_alloc()
4594 READ_ONCE(idev->cnf.disable_policy))) in addrconf_f6i_alloc()
4595 f6i->dst_nopolicy = true; in addrconf_f6i_alloc()
4609 struct net *net = ((struct arg_dev_net_ip *)arg)->net; in fib6_remove_prefsrc()
4610 struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr; in fib6_remove_prefsrc()
4612 if (!rt->nh && in fib6_remove_prefsrc()
4613 rt != net->ipv6.fib6_null_entry && in fib6_remove_prefsrc()
4614 ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr) && in fib6_remove_prefsrc()
4615 !ipv6_chk_addr(net, addr, rt->fib6_nh->fib_nh_dev, 0)) { in fib6_remove_prefsrc()
4618 rt->fib6_prefsrc.plen = 0; in fib6_remove_prefsrc()
4626 struct net *net = dev_net(ifp->idev->dev); in rt6_remove_prefsrc()
4629 .addr = &ifp->addr, in rt6_remove_prefsrc()
4642 /* RA routes do not use nexthops */ in fib6_clean_tohost()
4643 if (rt->nh) in fib6_clean_tohost()
4646 nh = rt->fib6_nh; in fib6_clean_tohost()
4647 if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) && in fib6_clean_tohost()
4648 nh->fib_nh_gw_family && ipv6_addr_equal(gateway, &nh->fib_nh_gw6)) in fib6_clean_tohost()
4649 return -1; in fib6_clean_tohost()
4678 fn = rcu_dereference_protected(rt->fib6_node, in rt6_multipath_first_sibling()
4679 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4680 iter = rcu_dereference_protected(fn->leaf, in rt6_multipath_first_sibling()
4681 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4683 if (iter->fib6_metric == rt->fib6_metric && in rt6_multipath_first_sibling()
4686 iter = rcu_dereference_protected(iter->fib6_next, in rt6_multipath_first_sibling()
4687 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4696 if (rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD || in rt6_is_dead()
4697 (rt->fib6_nh->fib_nh_flags & RTNH_F_LINKDOWN && in rt6_is_dead()
4698 ip6_ignore_linkdown(rt->fib6_nh->fib_nh_dev))) in rt6_is_dead()
4710 total += rt->fib6_nh->fib_nh_weight; in rt6_multipath_total_weight()
4712 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) { in rt6_multipath_total_weight()
4714 total += iter->fib6_nh->fib_nh_weight; in rt6_multipath_total_weight()
4722 int upper_bound = -1; in rt6_upper_bound_set()
4725 *weight += rt->fib6_nh->fib_nh_weight; in rt6_upper_bound_set()
4727 total) - 1; in rt6_upper_bound_set()
4729 atomic_set(&rt->fib6_nh->fib_nh_upper_bound, upper_bound); in rt6_upper_bound_set()
4739 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_upper_bound_set()
4752 if (!rt->fib6_nsiblings || rt->should_flush) in rt6_multipath_rebalance()
4770 struct net *net = dev_net(arg->dev); in fib6_ifup()
4772 if (rt != net->ipv6.fib6_null_entry && !rt->nh && in fib6_ifup()
4773 rt->fib6_nh->fib_nh_dev == arg->dev) { in fib6_ifup()
4774 rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags; in fib6_ifup()
4803 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_uses_dev()
4805 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_uses_dev()
4806 if (iter->fib6_nh->fib_nh_dev == dev) in rt6_multipath_uses_dev()
4816 rt->should_flush = 1; in rt6_multipath_flush()
4817 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_flush()
4818 iter->should_flush = 1; in rt6_multipath_flush()
4827 if (rt->fib6_nh->fib_nh_dev == down_dev || in rt6_multipath_dead_count()
4828 rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD) in rt6_multipath_dead_count()
4830 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_dead_count()
4831 if (iter->fib6_nh->fib_nh_dev == down_dev || in rt6_multipath_dead_count()
4832 iter->fib6_nh->fib_nh_flags & RTNH_F_DEAD) in rt6_multipath_dead_count()
4844 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_nh_flags_set()
4845 rt->fib6_nh->fib_nh_flags |= nh_flags; in rt6_multipath_nh_flags_set()
4846 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_nh_flags_set()
4847 if (iter->fib6_nh->fib_nh_dev == dev) in rt6_multipath_nh_flags_set()
4848 iter->fib6_nh->fib_nh_flags |= nh_flags; in rt6_multipath_nh_flags_set()
4855 const struct net_device *dev = arg->dev; in fib6_ifdown()
4858 if (rt == net->ipv6.fib6_null_entry || rt->nh) in fib6_ifdown()
4861 switch (arg->event) { in fib6_ifdown()
4863 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4865 if (rt->should_flush) in fib6_ifdown()
4866 return -1; in fib6_ifdown()
4867 if (!rt->fib6_nsiblings) in fib6_ifdown()
4868 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4873 if (rt->fib6_nsiblings + 1 == count) { in fib6_ifdown()
4875 return -1; in fib6_ifdown()
4882 return -2; in fib6_ifdown()
4884 if (rt->fib6_nh->fib_nh_dev != dev || in fib6_ifdown()
4885 rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) in fib6_ifdown()
4887 rt->fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib6_ifdown()
4905 if (net->ipv6.sysctl.skip_notify_on_dev_down) in rt6_sync_down_dev()
4927 struct fib6_info *f6i = arg->f6i; in fib6_nh_mtu_change()
4934 if (nh->fib_nh_dev == arg->dev) { in fib6_nh_mtu_change()
4935 struct inet6_dev *idev = __in6_dev_get(arg->dev); in fib6_nh_mtu_change()
4936 u32 mtu = f6i->fib6_pmtu; in fib6_nh_mtu_change()
4938 if (mtu >= arg->mtu || in fib6_nh_mtu_change()
4939 (mtu < arg->mtu && mtu == idev->cnf.mtu6)) in fib6_nh_mtu_change()
4940 fib6_metric_set(f6i, RTAX_MTU, arg->mtu); in fib6_nh_mtu_change()
4943 rt6_exceptions_update_pmtu(idev, nh, arg->mtu); in fib6_nh_mtu_change()
4957 We still use this lock to block changes in rt6_mtu_change_route()
4961 idev = __in6_dev_get(arg->dev); in rt6_mtu_change_route()
4968 arg->f6i = f6i; in rt6_mtu_change_route()
4969 if (f6i->nh) { in rt6_mtu_change_route()
4971 return nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_mtu_change, in rt6_mtu_change_route()
4975 return fib6_nh_mtu_change(f6i->fib6_nh, arg); in rt6_mtu_change_route()
5014 struct rtmsg *rtm; in rtm_to_fib6_config() local
5019 err = nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX, in rtm_to_fib6_config()
5024 err = -EINVAL; in rtm_to_fib6_config()
5025 rtm = nlmsg_data(nlh); in rtm_to_fib6_config()
5027 if (rtm->rtm_tos) { in rtm_to_fib6_config()
5034 .fc_table = rtm->rtm_table, in rtm_to_fib6_config()
5035 .fc_dst_len = rtm->rtm_dst_len, in rtm_to_fib6_config()
5036 .fc_src_len = rtm->rtm_src_len, in rtm_to_fib6_config()
5038 .fc_protocol = rtm->rtm_protocol, in rtm_to_fib6_config()
5039 .fc_type = rtm->rtm_type, in rtm_to_fib6_config()
5043 .fc_nlinfo.nl_net = sock_net(skb->sk), in rtm_to_fib6_config()
5046 if (rtm->rtm_type == RTN_UNREACHABLE || in rtm_to_fib6_config()
5047 rtm->rtm_type == RTN_BLACKHOLE || in rtm_to_fib6_config()
5048 rtm->rtm_type == RTN_PROHIBIT || in rtm_to_fib6_config()
5049 rtm->rtm_type == RTN_THROW) in rtm_to_fib6_config()
5050 cfg->fc_flags |= RTF_REJECT; in rtm_to_fib6_config()
5052 if (rtm->rtm_type == RTN_LOCAL) in rtm_to_fib6_config()
5053 cfg->fc_flags |= RTF_LOCAL; in rtm_to_fib6_config()
5055 if (rtm->rtm_flags & RTM_F_CLONED) in rtm_to_fib6_config()
5056 cfg->fc_flags |= RTF_CACHE; in rtm_to_fib6_config()
5058 cfg->fc_flags |= (rtm->rtm_flags & RTNH_F_ONLINK); in rtm_to_fib6_config()
5067 cfg->fc_nh_id = nla_get_u32(tb[RTA_NH_ID]); in rtm_to_fib6_config()
5071 cfg->fc_gateway = nla_get_in6_addr(tb[RTA_GATEWAY]); in rtm_to_fib6_config()
5072 cfg->fc_flags |= RTF_GATEWAY; in rtm_to_fib6_config()
5080 int plen = (rtm->rtm_dst_len + 7) >> 3; in rtm_to_fib6_config()
5085 nla_memcpy(&cfg->fc_dst, tb[RTA_DST], plen); in rtm_to_fib6_config()
5089 int plen = (rtm->rtm_src_len + 7) >> 3; in rtm_to_fib6_config()
5094 nla_memcpy(&cfg->fc_src, tb[RTA_SRC], plen); in rtm_to_fib6_config()
5098 cfg->fc_prefsrc = nla_get_in6_addr(tb[RTA_PREFSRC]); in rtm_to_fib6_config()
5101 cfg->fc_ifindex = nla_get_u32(tb[RTA_OIF]); in rtm_to_fib6_config()
5104 cfg->fc_metric = nla_get_u32(tb[RTA_PRIORITY]); in rtm_to_fib6_config()
5107 cfg->fc_mx = nla_data(tb[RTA_METRICS]); in rtm_to_fib6_config()
5108 cfg->fc_mx_len = nla_len(tb[RTA_METRICS]); in rtm_to_fib6_config()
5112 cfg->fc_table = nla_get_u32(tb[RTA_TABLE]); in rtm_to_fib6_config()
5115 cfg->fc_mp = nla_data(tb[RTA_MULTIPATH]); in rtm_to_fib6_config()
5116 cfg->fc_mp_len = nla_len(tb[RTA_MULTIPATH]); in rtm_to_fib6_config()
5118 err = lwtunnel_valid_encap_type_attr(cfg->fc_mp, in rtm_to_fib6_config()
5119 cfg->fc_mp_len, extack); in rtm_to_fib6_config()
5129 cfg->fc_flags |= RTF_PREF(pref); in rtm_to_fib6_config()
5133 cfg->fc_encap = tb[RTA_ENCAP]; in rtm_to_fib6_config()
5136 cfg->fc_encap_type = nla_get_u16(tb[RTA_ENCAP_TYPE]); in rtm_to_fib6_config()
5138 err = lwtunnel_valid_encap_type(cfg->fc_encap_type, extack); in rtm_to_fib6_config()
5147 cfg->fc_expires = jiffies_to_clock_t(timeout * HZ); in rtm_to_fib6_config()
5148 cfg->fc_flags |= RTF_EXPIRES; in rtm_to_fib6_config()
5169 int err = -EEXIST; in ip6_route_info_append()
5173 if (rt6_duplicate_nexthop(nh->fib6_info, rt)) in ip6_route_info_append()
5179 return -ENOMEM; in ip6_route_info_append()
5180 nh->fib6_info = rt; in ip6_route_info_append()
5181 memcpy(&nh->r_cfg, r_cfg, sizeof(*r_cfg)); in ip6_route_info_append()
5182 list_add_tail(&nh->next, rt6_nh_list); in ip6_route_info_append()
5198 if ((nlflags & NLM_F_APPEND) && rt_last && rt_last->fib6_nsiblings) { in ip6_route_mpath_notify()
5199 rt = list_first_entry(&rt_last->fib6_siblings, in ip6_route_mpath_notify()
5216 fn = rcu_dereference(rt->fib6_node); in ip6_route_mpath_should_notify()
5220 leaf = rcu_dereference(fn->leaf); in ip6_route_mpath_should_notify()
5225 (rt_can_ecmp && rt->fib6_metric == leaf->fib6_metric && in ip6_route_mpath_should_notify()
5239 return -EINVAL; in fib6_gw_from_attr()
5251 struct nl_info *info = &cfg->fc_nlinfo; in ip6_route_multipath_add()
5262 int replace = (cfg->fc_nlinfo.nlh && in ip6_route_multipath_add()
5263 (cfg->fc_nlinfo.nlh->nlmsg_flags & NLM_F_REPLACE)); in ip6_route_multipath_add()
5267 if (info->nlh && info->nlh->nlmsg_flags & NLM_F_APPEND) in ip6_route_multipath_add()
5270 remaining = cfg->fc_mp_len; in ip6_route_multipath_add()
5271 rtnh = (struct rtnexthop *)cfg->fc_mp; in ip6_route_multipath_add()
5278 if (rtnh->rtnh_ifindex) in ip6_route_multipath_add()
5279 r_cfg.fc_ifindex = rtnh->rtnh_ifindex; in ip6_route_multipath_add()
5304 r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK); in ip6_route_multipath_add()
5312 err = -EINVAL; in ip6_route_multipath_add()
5319 rt->fib6_nh->fib_nh_weight = rtnh->rtnh_hops + 1; in ip6_route_multipath_add()
5321 err = ip6_route_info_append(info->nl_net, &rt6_nh_list, in ip6_route_multipath_add()
5333 "Invalid nexthop configuration - no valid nexthops"); in ip6_route_multipath_add()
5334 return -EINVAL; in ip6_route_multipath_add()
5341 info->skip_notify = 1; in ip6_route_multipath_add()
5346 info->skip_notify_kernel = 1; in ip6_route_multipath_add()
5350 err = __ip6_ins_rt(nh->fib6_info, info, extack); in ip6_route_multipath_add()
5360 rt_last = nh->fib6_info; in ip6_route_multipath_add()
5364 rt_notif = nh->fib6_info; in ip6_route_multipath_add()
5373 if (cfg->fc_nlinfo.nlh) { in ip6_route_multipath_add()
5374 cfg->fc_nlinfo.nlh->nlmsg_flags &= ~(NLM_F_EXCL | in ip6_route_multipath_add()
5376 cfg->fc_nlinfo.nlh->nlmsg_flags |= NLM_F_CREATE; in ip6_route_multipath_add()
5381 /* An in-kernel notification should only be sent in case the new in ip6_route_multipath_add()
5389 if (rt_notif->fib6_nsiblings != nhn - 1) in ip6_route_multipath_add()
5394 err = call_fib6_multipath_entry_notifiers(info->nl_net, in ip6_route_multipath_add()
5396 nhn - 1, extack); in ip6_route_multipath_add()
5420 ip6_route_del(&nh->r_cfg, extack); in ip6_route_multipath_add()
5425 fib6_info_release(nh->fib6_info); in ip6_route_multipath_add()
5426 list_del(&nh->next); in ip6_route_multipath_add()
5443 remaining = cfg->fc_mp_len; in ip6_route_multipath_del()
5444 rtnh = (struct rtnexthop *)cfg->fc_mp; in ip6_route_multipath_del()
5449 if (rtnh->rtnh_ifindex) in ip6_route_multipath_del()
5450 r_cfg.fc_ifindex = rtnh->rtnh_ifindex; in ip6_route_multipath_del()
5490 !nexthop_find_by_id(sock_net(skb->sk), cfg.fc_nh_id)) { in inet6_rtm_delroute()
5492 return -EINVAL; in inet6_rtm_delroute()
5531 if (nh->fib_nh_lws) { in rt6_nh_nlmsg_size()
5533 *nexthop_len += lwtunnel_get_encap_size(nh->fib_nh_lws); in rt6_nh_nlmsg_size()
5545 if (f6i->nh) { in rt6_nlmsg_size()
5547 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_nlmsg_size, in rt6_nlmsg_size()
5551 struct fib6_nh *nh = f6i->fib6_nh; in rt6_nlmsg_size()
5554 if (f6i->fib6_nsiblings) { in rt6_nlmsg_size()
5558 &f6i->fib6_siblings, fib6_siblings) { in rt6_nlmsg_size()
5559 rt6_nh_nlmsg_size(sibling->fib6_nh, &nexthop_len); in rt6_nlmsg_size()
5562 nexthop_len += lwtunnel_get_encap_size(nh->fib_nh_lws); in rt6_nlmsg_size()
5599 if (fib_nexthop_info(skb, &fib6_nh->nh_common, AF_INET6, in rt6_fill_node_nexthop()
5607 return -EMSGSIZE; in rt6_fill_node_nexthop()
5621 struct rtmsg *rtm; in rt6_fill_node() local
5624 nlh = nlmsg_put(skb, portid, seq, type, sizeof(*rtm), flags); in rt6_fill_node()
5626 return -EMSGSIZE; in rt6_fill_node()
5629 rt6_dst = &rt6->rt6i_dst; in rt6_fill_node()
5630 rt6_src = &rt6->rt6i_src; in rt6_fill_node()
5631 rt6_flags = rt6->rt6i_flags; in rt6_fill_node()
5633 rt6_dst = &rt->fib6_dst; in rt6_fill_node()
5634 rt6_src = &rt->fib6_src; in rt6_fill_node()
5635 rt6_flags = rt->fib6_flags; in rt6_fill_node()
5638 rtm = nlmsg_data(nlh); in rt6_fill_node()
5639 rtm->rtm_family = AF_INET6; in rt6_fill_node()
5640 rtm->rtm_dst_len = rt6_dst->plen; in rt6_fill_node()
5641 rtm->rtm_src_len = rt6_src->plen; in rt6_fill_node()
5642 rtm->rtm_tos = 0; in rt6_fill_node()
5643 if (rt->fib6_table) in rt6_fill_node()
5644 table = rt->fib6_table->tb6_id; in rt6_fill_node()
5647 rtm->rtm_table = table < 256 ? table : RT_TABLE_COMPAT; in rt6_fill_node()
5651 rtm->rtm_type = rt->fib6_type; in rt6_fill_node()
5652 rtm->rtm_flags = 0; in rt6_fill_node()
5653 rtm->rtm_scope = RT_SCOPE_UNIVERSE; in rt6_fill_node()
5654 rtm->rtm_protocol = rt->fib6_protocol; in rt6_fill_node()
5657 rtm->rtm_flags |= RTM_F_CLONED; in rt6_fill_node()
5662 rtm->rtm_dst_len = 128; in rt6_fill_node()
5663 } else if (rtm->rtm_dst_len) in rt6_fill_node()
5664 if (nla_put_in6_addr(skb, RTA_DST, &rt6_dst->addr)) in rt6_fill_node()
5670 rtm->rtm_src_len = 128; in rt6_fill_node()
5671 } else if (rtm->rtm_src_len && in rt6_fill_node()
5672 nla_put_in6_addr(skb, RTA_SRC, &rt6_src->addr)) in rt6_fill_node()
5677 if (ipv6_addr_is_multicast(&rt6_dst->addr)) { in rt6_fill_node()
5678 int err = ip6mr_get_route(net, skb, rtm, portid); in rt6_fill_node()
5695 if (rt->fib6_prefsrc.plen) { in rt6_fill_node()
5697 saddr_buf = rt->fib6_prefsrc.addr; in rt6_fill_node()
5702 pmetrics = dst ? dst_metrics_ptr(dst) : rt->fib6_metrics->metrics; in rt6_fill_node()
5706 if (nla_put_u32(skb, RTA_PRIORITY, rt->fib6_metric)) in rt6_fill_node()
5714 nla_put_in6_addr(skb, RTA_GATEWAY, &rt6->rt6i_gateway)) in rt6_fill_node()
5717 if (dst->dev && nla_put_u32(skb, RTA_OIF, dst->dev->ifindex)) in rt6_fill_node()
5720 if (dst->lwtstate && in rt6_fill_node()
5721 lwtunnel_fill_encap(skb, dst->lwtstate, RTA_ENCAP, RTA_ENCAP_TYPE) < 0) in rt6_fill_node()
5723 } else if (rt->fib6_nsiblings) { in rt6_fill_node()
5731 if (fib_add_nexthop(skb, &rt->fib6_nh->nh_common, in rt6_fill_node()
5732 rt->fib6_nh->fib_nh_weight, AF_INET6, in rt6_fill_node()
5737 &rt->fib6_siblings, fib6_siblings) { in rt6_fill_node()
5738 if (fib_add_nexthop(skb, &sibling->fib6_nh->nh_common, in rt6_fill_node()
5739 sibling->fib6_nh->fib_nh_weight, in rt6_fill_node()
5745 } else if (rt->nh) { in rt6_fill_node()
5746 if (nla_put_u32(skb, RTA_NH_ID, rt->nh->id)) in rt6_fill_node()
5749 if (nexthop_is_blackhole(rt->nh)) in rt6_fill_node()
5750 rtm->rtm_type = RTN_BLACKHOLE; in rt6_fill_node()
5752 if (READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode) && in rt6_fill_node()
5753 rt6_fill_node_nexthop(skb, rt->nh, &nh_flags) < 0) in rt6_fill_node()
5756 rtm->rtm_flags |= nh_flags; in rt6_fill_node()
5758 if (fib_nexthop_info(skb, &rt->fib6_nh->nh_common, AF_INET6, in rt6_fill_node()
5762 rtm->rtm_flags |= nh_flags; in rt6_fill_node()
5766 expires = dst ? dst->expires : rt->expires; in rt6_fill_node()
5767 expires -= jiffies; in rt6_fill_node()
5771 if (READ_ONCE(rt->offload)) in rt6_fill_node()
5772 rtm->rtm_flags |= RTM_F_OFFLOAD; in rt6_fill_node()
5773 if (READ_ONCE(rt->trap)) in rt6_fill_node()
5774 rtm->rtm_flags |= RTM_F_TRAP; in rt6_fill_node()
5775 if (READ_ONCE(rt->offload_failed)) in rt6_fill_node()
5776 rtm->rtm_flags |= RTM_F_OFFLOAD_FAILED; in rt6_fill_node()
5779 if (rtnl_put_cacheinfo(skb, dst, 0, expires, dst ? dst->error : 0) < 0) in rt6_fill_node()
5791 return -EMSGSIZE; in rt6_fill_node()
5798 if (nh->fib_nh_dev == dev) in fib6_info_nh_uses_dev()
5807 if (f6i->nh) { in fib6_info_uses_dev()
5810 return !!nexthop_for_each_fib6_nh(f6i->nh, in fib6_info_uses_dev()
5815 if (f6i->fib6_nh->fib_nh_dev == dev) in fib6_info_uses_dev()
5818 if (f6i->fib6_nsiblings) { in fib6_info_uses_dev()
5822 &f6i->fib6_siblings, fib6_siblings) { in fib6_info_uses_dev()
5823 if (sibling->fib6_nh->fib_nh_dev == dev) in fib6_info_uses_dev()
5842 struct rt6_rtnl_dump_arg *dump = w->dump; in rt6_nh_dump_exceptions()
5852 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_nh_dump_exceptions()
5853 if (w->skip) { in rt6_nh_dump_exceptions()
5854 w->skip--; in rt6_nh_dump_exceptions()
5869 if (rt6_check_expired(rt6_ex->rt6i)) { in rt6_nh_dump_exceptions()
5870 w->count++; in rt6_nh_dump_exceptions()
5874 err = rt6_fill_node(dump->net, dump->skb, w->rt, in rt6_nh_dump_exceptions()
5875 &rt6_ex->rt6i->dst, NULL, NULL, 0, in rt6_nh_dump_exceptions()
5877 NETLINK_CB(dump->cb->skb).portid, in rt6_nh_dump_exceptions()
5878 dump->cb->nlh->nlmsg_seq, w->flags); in rt6_nh_dump_exceptions()
5882 w->count++; in rt6_nh_dump_exceptions()
5890 /* Return -1 if done with node, number of handled routes on partial dump */
5894 struct fib_dump_filter *filter = &arg->filter; in rt6_dump_route()
5896 struct net *net = arg->net; in rt6_dump_route()
5899 if (rt == net->ipv6.fib6_null_entry) in rt6_dump_route()
5900 return -1; in rt6_dump_route()
5902 if ((filter->flags & RTM_F_PREFIX) && in rt6_dump_route()
5903 !(rt->fib6_flags & RTF_PREFIX_RT)) { in rt6_dump_route()
5905 return -1; in rt6_dump_route()
5907 if (filter->filter_set && in rt6_dump_route()
5908 ((filter->rt_type && rt->fib6_type != filter->rt_type) || in rt6_dump_route()
5909 (filter->dev && !fib6_info_uses_dev(rt, filter->dev)) || in rt6_dump_route()
5910 (filter->protocol && rt->fib6_protocol != filter->protocol))) { in rt6_dump_route()
5911 return -1; in rt6_dump_route()
5914 if (filter->filter_set || in rt6_dump_route()
5915 !filter->dump_routes || !filter->dump_exceptions) { in rt6_dump_route()
5919 if (filter->dump_routes) { in rt6_dump_route()
5921 skip--; in rt6_dump_route()
5923 if (rt6_fill_node(net, arg->skb, rt, NULL, NULL, NULL, in rt6_dump_route()
5925 NETLINK_CB(arg->cb->skb).portid, in rt6_dump_route()
5926 arg->cb->nlh->nlmsg_seq, flags)) { in rt6_dump_route()
5933 if (filter->dump_exceptions) { in rt6_dump_route()
5942 if (rt->nh) { in rt6_dump_route()
5943 err = nexthop_for_each_fib6_nh(rt->nh, in rt6_dump_route()
5947 err = rt6_nh_dump_exceptions(rt->fib6_nh, &w); in rt6_dump_route()
5955 return -1; in rt6_dump_route()
5963 struct rtmsg *rtm; in inet6_rtm_valid_getroute_req() local
5966 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*rtm))) { in inet6_rtm_valid_getroute_req()
5969 return -EINVAL; in inet6_rtm_valid_getroute_req()
5973 return nlmsg_parse_deprecated(nlh, sizeof(*rtm), tb, RTA_MAX, in inet6_rtm_valid_getroute_req()
5976 rtm = nlmsg_data(nlh); in inet6_rtm_valid_getroute_req()
5977 if ((rtm->rtm_src_len && rtm->rtm_src_len != 128) || in inet6_rtm_valid_getroute_req()
5978 (rtm->rtm_dst_len && rtm->rtm_dst_len != 128) || in inet6_rtm_valid_getroute_req()
5979 rtm->rtm_table || rtm->rtm_protocol || rtm->rtm_scope || in inet6_rtm_valid_getroute_req()
5980 rtm->rtm_type) { in inet6_rtm_valid_getroute_req()
5982 return -EINVAL; in inet6_rtm_valid_getroute_req()
5984 if (rtm->rtm_flags & ~RTM_F_FIB_MATCH) { in inet6_rtm_valid_getroute_req()
5987 return -EINVAL; in inet6_rtm_valid_getroute_req()
5990 err = nlmsg_parse_deprecated_strict(nlh, sizeof(*rtm), tb, RTA_MAX, in inet6_rtm_valid_getroute_req()
5995 if ((tb[RTA_SRC] && !rtm->rtm_src_len) || in inet6_rtm_valid_getroute_req()
5996 (tb[RTA_DST] && !rtm->rtm_dst_len)) { in inet6_rtm_valid_getroute_req()
5998 return -EINVAL; in inet6_rtm_valid_getroute_req()
6018 return -EINVAL; in inet6_rtm_valid_getroute_req()
6028 struct net *net = sock_net(in_skb->sk); in inet6_rtm_getroute()
6035 struct rtmsg *rtm; in inet6_rtm_getroute() local
6043 err = -EINVAL; in inet6_rtm_getroute()
6044 rtm = nlmsg_data(nlh); in inet6_rtm_getroute()
6045 fl6.flowlabel = ip6_make_flowinfo(rtm->rtm_tos, 0); in inet6_rtm_getroute()
6046 fibmatch = !!(rtm->rtm_flags & RTM_F_FIB_MATCH); in inet6_rtm_getroute()
6100 err = -ENODEV; in inet6_rtm_getroute()
6120 if (rt->dst.error) { in inet6_rtm_getroute()
6121 err = rt->dst.error; in inet6_rtm_getroute()
6126 if (rt == net->ipv6.ip6_null_entry) { in inet6_rtm_getroute()
6127 err = rt->dst.error; in inet6_rtm_getroute()
6135 err = -ENOBUFS; in inet6_rtm_getroute()
6139 skb_dst_set(skb, &rt->dst); in inet6_rtm_getroute()
6142 from = rcu_dereference(rt->from); in inet6_rtm_getroute()
6148 nlh->nlmsg_seq, 0); in inet6_rtm_getroute()
6153 nlh->nlmsg_seq, 0); in inet6_rtm_getroute()
6155 err = -ENETUNREACH; in inet6_rtm_getroute()
6173 struct net *net = info->nl_net; in inet6_rt_notify()
6177 err = -ENOBUFS; in inet6_rt_notify()
6178 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in inet6_rt_notify()
6185 event, info->portid, seq, nlm_flags); in inet6_rt_notify()
6187 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ in inet6_rt_notify()
6188 WARN_ON(err == -EMSGSIZE); in inet6_rt_notify()
6192 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in inet6_rt_notify()
6193 info->nlh, gfp_any()); in inet6_rt_notify()
6202 u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in fib6_rt_update()
6204 int err = -ENOBUFS; in fib6_rt_update()
6211 RTM_NEWROUTE, info->portid, seq, NLM_F_REPLACE); in fib6_rt_update()
6213 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ in fib6_rt_update()
6214 WARN_ON(err == -EMSGSIZE); in fib6_rt_update()
6218 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in fib6_rt_update()
6219 info->nlh, gfp_any()); in fib6_rt_update()
6231 if (READ_ONCE(f6i->offload) == offload && in fib6_info_hw_flags_set()
6232 READ_ONCE(f6i->trap) == trap && in fib6_info_hw_flags_set()
6233 READ_ONCE(f6i->offload_failed) == offload_failed) in fib6_info_hw_flags_set()
6236 WRITE_ONCE(f6i->offload, offload); in fib6_info_hw_flags_set()
6237 WRITE_ONCE(f6i->trap, trap); in fib6_info_hw_flags_set()
6240 if (net->ipv6.sysctl.fib_notify_on_flag_change == 2 && in fib6_info_hw_flags_set()
6241 READ_ONCE(f6i->offload_failed) == offload_failed) in fib6_info_hw_flags_set()
6244 WRITE_ONCE(f6i->offload_failed, offload_failed); in fib6_info_hw_flags_set()
6246 if (!rcu_access_pointer(f6i->fib6_node)) in fib6_info_hw_flags_set()
6252 if (!net->ipv6.sysctl.fib_notify_on_flag_change) in fib6_info_hw_flags_set()
6257 err = -ENOBUFS; in fib6_info_hw_flags_set()
6264 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ in fib6_info_hw_flags_set()
6265 WARN_ON(err == -EMSGSIZE); in fib6_info_hw_flags_set()
6284 if (!(dev->flags & IFF_LOOPBACK)) in ip6_route_dev_notify()
6288 net->ipv6.fib6_null_entry->fib6_nh->fib_nh_dev = dev; in ip6_route_dev_notify()
6289 net->ipv6.ip6_null_entry->dst.dev = dev; in ip6_route_dev_notify()
6290 net->ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6292 net->ipv6.ip6_prohibit_entry->dst.dev = dev; in ip6_route_dev_notify()
6293 net->ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6294 net->ipv6.ip6_blk_hole_entry->dst.dev = dev; in ip6_route_dev_notify()
6295 net->ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6298 dev->reg_state != NETREG_UNREGISTERED) { in ip6_route_dev_notify()
6302 in6_dev_put_clear(&net->ipv6.ip6_null_entry->rt6i_idev); in ip6_route_dev_notify()
6304 in6_dev_put_clear(&net->ipv6.ip6_prohibit_entry->rt6i_idev); in ip6_route_dev_notify()
6305 in6_dev_put_clear(&net->ipv6.ip6_blk_hole_entry->rt6i_idev); in ip6_route_dev_notify()
6319 struct net *net = (struct net *)seq->private; in rt6_stats_seq_show()
6321 net->ipv6.rt6_stats->fib_nodes, in rt6_stats_seq_show()
6322 net->ipv6.rt6_stats->fib_route_nodes, in rt6_stats_seq_show()
6323 atomic_read(&net->ipv6.rt6_stats->fib_rt_alloc), in rt6_stats_seq_show()
6324 net->ipv6.rt6_stats->fib_rt_entries, in rt6_stats_seq_show()
6325 net->ipv6.rt6_stats->fib_rt_cache, in rt6_stats_seq_show()
6326 dst_entries_get_slow(&net->ipv6.ip6_dst_ops), in rt6_stats_seq_show()
6327 net->ipv6.rt6_stats->fib_discarded_routes); in rt6_stats_seq_show()
6342 return -EINVAL; in ipv6_sysctl_rtcache_flush()
6348 net = (struct net *)ctl->extra1; in ipv6_sysctl_rtcache_flush()
6349 delay = net->ipv6.sysctl.flush_delay; in ipv6_sysctl_rtcache_flush()
6445 table[0].data = &net->ipv6.sysctl.ip6_rt_max_size; in ipv6_route_sysctl_init()
6446 table[1].data = &net->ipv6.ip6_dst_ops.gc_thresh; in ipv6_route_sysctl_init()
6447 table[2].data = &net->ipv6.sysctl.flush_delay; in ipv6_route_sysctl_init()
6449 table[3].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; in ipv6_route_sysctl_init()
6450 table[4].data = &net->ipv6.sysctl.ip6_rt_gc_timeout; in ipv6_route_sysctl_init()
6451 table[5].data = &net->ipv6.sysctl.ip6_rt_gc_interval; in ipv6_route_sysctl_init()
6452 table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity; in ipv6_route_sysctl_init()
6453 table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires; in ipv6_route_sysctl_init()
6454 table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss; in ipv6_route_sysctl_init()
6455 table[9].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; in ipv6_route_sysctl_init()
6456 table[10].data = &net->ipv6.sysctl.skip_notify_on_dev_down; in ipv6_route_sysctl_init()
6465 if (net->user_ns != &init_user_ns) in ipv6_route_sysctl_table_size()
6474 int ret = -ENOMEM; in ip6_route_net_init()
6476 memcpy(&net->ipv6.ip6_dst_ops, &ip6_dst_ops_template, in ip6_route_net_init()
6477 sizeof(net->ipv6.ip6_dst_ops)); in ip6_route_net_init()
6479 if (dst_entries_init(&net->ipv6.ip6_dst_ops) < 0) in ip6_route_net_init()
6482 net->ipv6.fib6_null_entry = fib6_info_alloc(GFP_KERNEL, true); in ip6_route_net_init()
6483 if (!net->ipv6.fib6_null_entry) in ip6_route_net_init()
6485 memcpy(net->ipv6.fib6_null_entry, &fib6_null_entry_template, in ip6_route_net_init()
6486 sizeof(*net->ipv6.fib6_null_entry)); in ip6_route_net_init()
6488 net->ipv6.ip6_null_entry = kmemdup(&ip6_null_entry_template, in ip6_route_net_init()
6489 sizeof(*net->ipv6.ip6_null_entry), in ip6_route_net_init()
6491 if (!net->ipv6.ip6_null_entry) in ip6_route_net_init()
6493 net->ipv6.ip6_null_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6494 dst_init_metrics(&net->ipv6.ip6_null_entry->dst, in ip6_route_net_init()
6496 INIT_LIST_HEAD(&net->ipv6.ip6_null_entry->dst.rt_uncached); in ip6_route_net_init()
6499 net->ipv6.fib6_has_custom_rules = false; in ip6_route_net_init()
6500 net->ipv6.ip6_prohibit_entry = kmemdup(&ip6_prohibit_entry_template, in ip6_route_net_init()
6501 sizeof(*net->ipv6.ip6_prohibit_entry), in ip6_route_net_init()
6503 if (!net->ipv6.ip6_prohibit_entry) in ip6_route_net_init()
6505 net->ipv6.ip6_prohibit_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6506 dst_init_metrics(&net->ipv6.ip6_prohibit_entry->dst, in ip6_route_net_init()
6508 INIT_LIST_HEAD(&net->ipv6.ip6_prohibit_entry->dst.rt_uncached); in ip6_route_net_init()
6510 net->ipv6.ip6_blk_hole_entry = kmemdup(&ip6_blk_hole_entry_template, in ip6_route_net_init()
6511 sizeof(*net->ipv6.ip6_blk_hole_entry), in ip6_route_net_init()
6513 if (!net->ipv6.ip6_blk_hole_entry) in ip6_route_net_init()
6515 net->ipv6.ip6_blk_hole_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6516 dst_init_metrics(&net->ipv6.ip6_blk_hole_entry->dst, in ip6_route_net_init()
6518 INIT_LIST_HEAD(&net->ipv6.ip6_blk_hole_entry->dst.rt_uncached); in ip6_route_net_init()
6520 net->ipv6.fib6_routes_require_src = 0; in ip6_route_net_init()
6524 net->ipv6.sysctl.flush_delay = 0; in ip6_route_net_init()
6525 net->ipv6.sysctl.ip6_rt_max_size = INT_MAX; in ip6_route_net_init()
6526 net->ipv6.sysctl.ip6_rt_gc_min_interval = HZ / 2; in ip6_route_net_init()
6527 net->ipv6.sysctl.ip6_rt_gc_timeout = 60*HZ; in ip6_route_net_init()
6528 net->ipv6.sysctl.ip6_rt_gc_interval = 30*HZ; in ip6_route_net_init()
6529 net->ipv6.sysctl.ip6_rt_gc_elasticity = 9; in ip6_route_net_init()
6530 net->ipv6.sysctl.ip6_rt_mtu_expires = 10*60*HZ; in ip6_route_net_init()
6531 net->ipv6.sysctl.ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40; in ip6_route_net_init()
6532 net->ipv6.sysctl.skip_notify_on_dev_down = 0; in ip6_route_net_init()
6534 atomic_set(&net->ipv6.ip6_rt_gc_expire, 30*HZ); in ip6_route_net_init()
6542 kfree(net->ipv6.ip6_prohibit_entry); in ip6_route_net_init()
6544 kfree(net->ipv6.ip6_null_entry); in ip6_route_net_init()
6547 kfree(net->ipv6.fib6_null_entry); in ip6_route_net_init()
6549 dst_entries_destroy(&net->ipv6.ip6_dst_ops); in ip6_route_net_init()
6556 kfree(net->ipv6.fib6_null_entry); in ip6_route_net_exit()
6557 kfree(net->ipv6.ip6_null_entry); in ip6_route_net_exit()
6559 kfree(net->ipv6.ip6_prohibit_entry); in ip6_route_net_exit()
6560 kfree(net->ipv6.ip6_blk_hole_entry); in ip6_route_net_exit()
6562 dst_entries_destroy(&net->ipv6.ip6_dst_ops); in ip6_route_net_exit()
6568 if (!proc_create_net("ipv6_route", 0, net->proc_net, in ip6_route_net_init_late()
6571 return -ENOMEM; in ip6_route_net_init_late()
6573 if (!proc_create_net_single("rt6_stats", 0444, net->proc_net, in ip6_route_net_init_late()
6575 remove_proc_entry("ipv6_route", net->proc_net); in ip6_route_net_init_late()
6576 return -ENOMEM; in ip6_route_net_init_late()
6585 remove_proc_entry("ipv6_route", net->proc_net); in ip6_route_net_exit_late()
6586 remove_proc_entry("rt6_stats", net->proc_net); in ip6_route_net_exit_late()
6600 return -ENOMEM; in ipv6_inetpeer_init()
6602 net->ipv6.peers = bp; in ipv6_inetpeer_init()
6608 struct inet_peer_base *bp = net->ipv6.peers; in ipv6_inetpeer_exit()
6610 net->ipv6.peers = NULL; in ipv6_inetpeer_exit()
6627 .priority = ADDRCONF_NOTIFY_PRIORITY - 10,
6635 init_net.ipv6.fib6_null_entry->fib6_nh->fib_nh_dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6636 init_net.ipv6.ip6_null_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6637 init_net.ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6639 init_net.ipv6.ip6_prohibit_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6640 init_net.ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6641 init_net.ipv6.ip6_blk_hole_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6642 init_net.ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6688 ret = -ENOMEM; in ip6_route_init()
6756 INIT_LIST_HEAD(&ul->head); in ip6_route_init()
6757 spin_lock_init(&ul->lock); in ip6_route_init()