Lines Matching +full:bp +full:- +full:disabled +full:- +full:ports

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->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_move(&rt->dst.rt_uncached, in rt6_uncached_list_flush_dev()
192 &ul->quarantine); in rt6_uncached_list_flush_dev()
194 spin_unlock_bh(&ul->lock); in rt6_uncached_list_flush_dev()
205 return &ipv6_hdr(skb)->daddr; in choose_neigh_daddr()
232 dst->dev, skb, daddr); in ip6_dst_neigh_lookup()
237 struct net_device *dev = dst->dev; in ip6_confirm_neigh()
243 if (dev->flags & (IFF_NOARP | IFF_LOOPBACK)) in ip6_confirm_neigh()
282 [RTAX_HOPLIMIT - 1] = 0,
299 .error = -ENETUNREACH,
313 .error = -EACCES,
325 .error = -EINVAL,
343 struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev, in ip6_dst_alloc()
348 atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc); in ip6_dst_alloc()
364 idev = rt->rt6i_idev; in ip6_dst_destroy()
366 rt->rt6i_idev = NULL; in ip6_dst_destroy()
370 from = xchg((__force struct fib6_info **)&rt->from, NULL); in ip6_dst_destroy()
377 struct inet6_dev *idev = rt->rt6i_idev; in ip6_dst_ifdown()
379 if (idev && idev->dev != blackhole_netdev) { in ip6_dst_ifdown()
383 rt->rt6i_idev = blackhole_idev; in ip6_dst_ifdown()
391 if (rt->rt6i_flags & RTF_EXPIRES) in __rt6_check_expired()
392 return time_after(jiffies, rt->dst.expires); in __rt6_check_expired()
401 from = rcu_dereference(rt->from); in rt6_check_expired()
403 if (rt->rt6i_flags & RTF_EXPIRES) { in rt6_check_expired()
404 if (time_after(jiffies, rt->dst.expires)) in rt6_check_expired()
407 return rt->dst.obsolete != DST_OBSOLETE_FORCE_CHK || in rt6_check_expired()
418 struct fib6_info *match = res->f6i; in fib6_select_path()
420 if (!match->nh && (!match->fib6_nsiblings || have_oif_match)) in fib6_select_path()
423 if (match->nh && have_oif_match && res->nh) in fib6_select_path()
427 IP6CB(skb)->flags |= IP6SKB_MULTIPATH; in fib6_select_path()
430 * case it will always be non-zero. Otherwise now is the time to do it. in fib6_select_path()
432 if (!fl6->mp_hash && in fib6_select_path()
433 (!match->nh || nexthop_is_multipath(match->nh))) in fib6_select_path()
434 fl6->mp_hash = rt6_multipath_hash(net, fl6, skb, NULL); in fib6_select_path()
436 if (unlikely(match->nh)) { in fib6_select_path()
437 nexthop_path_fib6_result(res, fl6->mp_hash); in fib6_select_path()
441 if (fl6->mp_hash <= atomic_read(&match->fib6_nh->fib_nh_upper_bound)) in fib6_select_path()
444 list_for_each_entry_safe(sibling, next_sibling, &match->fib6_siblings, in fib6_select_path()
446 const struct fib6_nh *nh = sibling->fib6_nh; in fib6_select_path()
449 nh_upper_bound = atomic_read(&nh->fib_nh_upper_bound); in fib6_select_path()
450 if (fl6->mp_hash > nh_upper_bound) in fib6_select_path()
452 if (rt6_score_route(nh, sibling->fib6_flags, oif, strict) < 0) in fib6_select_path()
459 res->f6i = match; in fib6_select_path()
460 res->nh = match->fib6_nh; in fib6_select_path()
472 if (nh->fib_nh_flags & RTNH_F_DEAD) in __rt6_device_match()
475 dev = nh->fib_nh_dev; in __rt6_device_match()
477 if (dev->ifindex == oif) in __rt6_device_match()
500 arg->nh = nh; in __rt6_nh_dev_match()
501 return __rt6_device_match(arg->net, nh, arg->saddr, arg->oif, in __rt6_nh_dev_match()
502 arg->flags); in __rt6_nh_dev_match()
530 struct fib6_info *f6i = res->f6i; in rt6_device_match()
535 if (unlikely(f6i->nh)) { in rt6_device_match()
536 nh = nexthop_fib6_nh(f6i->nh); in rt6_device_match()
537 if (nexthop_is_blackhole(f6i->nh)) in rt6_device_match()
540 nh = f6i->fib6_nh; in rt6_device_match()
542 if (!(nh->fib_nh_flags & RTNH_F_DEAD)) in rt6_device_match()
546 for (spf6i = f6i; spf6i; spf6i = rcu_dereference(spf6i->fib6_next)) { in rt6_device_match()
549 if (unlikely(spf6i->nh)) { in rt6_device_match()
550 nh = rt6_nh_dev_match(net, spf6i->nh, res, saddr, in rt6_device_match()
555 nh = spf6i->fib6_nh; in rt6_device_match()
560 res->f6i = spf6i; in rt6_device_match()
566 res->f6i = net->ipv6.fib6_null_entry; in rt6_device_match()
567 nh = res->f6i->fib6_nh; in rt6_device_match()
571 if (unlikely(f6i->nh)) { in rt6_device_match()
572 nh = nexthop_fib6_nh(f6i->nh); in rt6_device_match()
573 if (nexthop_is_blackhole(f6i->nh)) in rt6_device_match()
576 nh = f6i->fib6_nh; in rt6_device_match()
579 if (nh->fib_nh_flags & RTNH_F_DEAD) { in rt6_device_match()
580 res->f6i = net->ipv6.fib6_null_entry; in rt6_device_match()
581 nh = res->f6i->fib6_nh; in rt6_device_match()
584 res->nh = nh; in rt6_device_match()
585 res->fib6_type = res->f6i->fib6_type; in rt6_device_match()
586 res->fib6_flags = res->f6i->fib6_flags; in rt6_device_match()
590 res->fib6_flags |= RTF_REJECT; in rt6_device_match()
591 res->fib6_type = RTN_BLACKHOLE; in rt6_device_match()
592 res->nh = nh; in rt6_device_match()
609 addrconf_addr_solict_mult(&work->target, &mcaddr); in rt6_probe_deferred()
610 ndisc_send_ns(work->dev, &work->target, &mcaddr, NULL, 0); in rt6_probe_deferred()
611 netdev_put(work->dev, &work->dev_tracker); in rt6_probe_deferred()
629 * Router Reachability Probe MUST be rate-limited in rt6_probe()
632 if (!fib6_nh->fib_nh_gw_family) in rt6_probe()
635 nh_gw = &fib6_nh->fib_nh_gw6; in rt6_probe()
636 dev = fib6_nh->fib_nh_dev; in rt6_probe()
638 last_probe = READ_ONCE(fib6_nh->last_probe); in rt6_probe()
642 if (READ_ONCE(neigh->nud_state) & NUD_VALID) in rt6_probe()
645 write_lock_bh(&neigh->lock); in rt6_probe()
646 if (!(neigh->nud_state & NUD_VALID) && in rt6_probe()
648 neigh->updated + idev->cnf.rtr_probe_interval)) { in rt6_probe()
653 write_unlock_bh(&neigh->lock); in rt6_probe()
655 idev->cnf.rtr_probe_interval)) { in rt6_probe()
659 if (!work || cmpxchg(&fib6_nh->last_probe, in rt6_probe()
663 INIT_WORK(&work->work, rt6_probe_deferred); in rt6_probe()
664 work->target = *nh_gw; in rt6_probe()
665 netdev_hold(dev, &work->dev_tracker, GFP_ATOMIC); in rt6_probe()
666 work->dev = dev; in rt6_probe()
667 schedule_work(&work->work); in rt6_probe()
688 neigh = __ipv6_neigh_lookup_noref(fib6_nh->fib_nh_dev, in rt6_check_neigh()
689 &fib6_nh->fib_nh_gw6); in rt6_check_neigh()
691 u8 nud_state = READ_ONCE(neigh->nud_state); in rt6_check_neigh()
715 if (!oif || nh->fib_nh_dev->ifindex == oif) in rt6_score_route()
724 !(fib6_flags & RTF_NONEXTHOP) && nh->fib_nh_gw_family) { in rt6_score_route()
739 if (nh->fib_nh_flags & RTNH_F_DEAD) in find_match()
742 if (ip6_ignore_linkdown(nh->fib_nh_dev) && in find_match()
743 nh->fib_nh_flags & RTNH_F_LINKDOWN && in find_match()
781 arg->nh = nh; in rt6_nh_find_match()
782 return find_match(nh, arg->flags, arg->oif, arg->strict, in rt6_nh_find_match()
783 arg->mpri, arg->do_rr); in rt6_nh_find_match()
795 f6i = rcu_dereference(f6i->fib6_next)) { in __find_rr_leaf()
799 if (cont && f6i->fib6_metric != metric) { in __find_rr_leaf()
807 if (unlikely(f6i->nh)) { in __find_rr_leaf()
809 .flags = f6i->fib6_flags, in __find_rr_leaf()
816 if (nexthop_is_blackhole(f6i->nh)) { in __find_rr_leaf()
817 res->fib6_flags = RTF_REJECT; in __find_rr_leaf()
818 res->fib6_type = RTN_BLACKHOLE; in __find_rr_leaf()
819 res->f6i = f6i; in __find_rr_leaf()
820 res->nh = nexthop_fib6_nh(f6i->nh); in __find_rr_leaf()
823 if (nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_find_match, in __find_rr_leaf()
829 nh = f6i->fib6_nh; in __find_rr_leaf()
830 if (find_match(nh, f6i->fib6_flags, oif, strict, in __find_rr_leaf()
835 res->f6i = f6i; in __find_rr_leaf()
836 res->nh = nh; in __find_rr_leaf()
837 res->fib6_flags = f6i->fib6_flags; in __find_rr_leaf()
838 res->fib6_type = f6i->fib6_type; in __find_rr_leaf()
847 u32 metric = rr_head->fib6_metric; in find_rr_leaf()
849 int mpri = -1; in find_rr_leaf()
857 if (res->f6i || !cont) in find_rr_leaf()
867 struct fib6_info *leaf = rcu_dereference(fn->leaf); in rt6_select()
873 res->f6i = NULL; in rt6_select()
875 if (!leaf || leaf == net->ipv6.fib6_null_entry) in rt6_select()
878 rt0 = rcu_dereference(fn->rr_ptr); in rt6_select()
883 * and fn->leaf does not points to its child's leaf in rt6_select()
887 key_plen = rt0->fib6_dst.plen; in rt6_select()
889 if (rt0->fib6_src.plen) in rt6_select()
890 key_plen = rt0->fib6_src.plen; in rt6_select()
892 if (fn->fn_bit != key_plen) in rt6_select()
897 struct fib6_info *next = rcu_dereference(rt0->fib6_next); in rt6_select()
899 /* no entries matched; do round-robin */ in rt6_select()
900 if (!next || next->fib6_metric != rt0->fib6_metric) in rt6_select()
904 spin_lock_bh(&leaf->fib6_table->tb6_lock); in rt6_select()
906 if (next->fib6_node) in rt6_select()
907 rcu_assign_pointer(fn->rr_ptr, next); in rt6_select()
908 spin_unlock_bh(&leaf->fib6_table->tb6_lock); in rt6_select()
913 if (!res->f6i) { in rt6_select()
914 res->f6i = net->ipv6.fib6_null_entry; in rt6_select()
915 res->nh = res->f6i->fib6_nh; in rt6_select()
916 res->fib6_flags = res->f6i->fib6_flags; in rt6_select()
917 res->fib6_type = res->f6i->fib6_type; in rt6_select()
923 return (res->f6i->fib6_flags & RTF_NONEXTHOP) || in rt6_is_gw_or_nonexthop()
924 res->nh->fib_nh_gw_family; in rt6_is_gw_or_nonexthop()
939 return -EINVAL; in rt6_route_rcv()
943 if (rinfo->length > 3) { in rt6_route_rcv()
944 return -EINVAL; in rt6_route_rcv()
945 } else if (rinfo->prefix_len > 128) { in rt6_route_rcv()
946 return -EINVAL; in rt6_route_rcv()
947 } else if (rinfo->prefix_len > 64) { in rt6_route_rcv()
948 if (rinfo->length < 2) { in rt6_route_rcv()
949 return -EINVAL; in rt6_route_rcv()
951 } else if (rinfo->prefix_len > 0) { in rt6_route_rcv()
952 if (rinfo->length < 1) { in rt6_route_rcv()
953 return -EINVAL; in rt6_route_rcv()
957 pref = rinfo->route_pref; in rt6_route_rcv()
959 return -EINVAL; in rt6_route_rcv()
961 lifetime = addrconf_timeout_fixup(ntohl(rinfo->lifetime), HZ); in rt6_route_rcv()
963 if (rinfo->length == 3) in rt6_route_rcv()
964 prefix = (struct in6_addr *)rinfo->prefix; in rt6_route_rcv()
968 (struct in6_addr *)rinfo->prefix, in rt6_route_rcv()
969 rinfo->prefix_len); in rt6_route_rcv()
973 if (rinfo->prefix_len == 0) in rt6_route_rcv()
976 rt = rt6_get_route_info(net, prefix, rinfo->prefix_len, in rt6_route_rcv()
985 rt = rt6_add_route_info(net, prefix, rinfo->prefix_len, gwaddr, in rt6_route_rcv()
988 rt->fib6_flags = RTF_ROUTEINFO | in rt6_route_rcv()
989 (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); in rt6_route_rcv()
1010 struct net_device *dev = res->nh->fib_nh_dev; in ip6_rt_get_dev_rcu()
1012 if (res->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) { in ip6_rt_get_dev_rcu()
1013 /* for copies of local routes, dst->dev needs to be the in ip6_rt_get_dev_rcu()
1018 !rt6_need_strict(&res->f6i->fib6_dst.addr)) in ip6_rt_get_dev_rcu()
1021 dev = dev_net(dev)->loopback_dev; in ip6_rt_get_dev_rcu()
1037 [RTN_BLACKHOLE] = -EINVAL,
1038 [RTN_UNREACHABLE] = -EHOSTUNREACH,
1039 [RTN_PROHIBIT] = -EACCES,
1040 [RTN_THROW] = -EAGAIN,
1041 [RTN_NAT] = -EINVAL,
1042 [RTN_XRESOLVE] = -EINVAL,
1054 if (rt->dst_nocount) in fib6_info_dst_flags()
1056 if (rt->dst_nopolicy) in fib6_info_dst_flags()
1064 rt->dst.error = ip6_rt_type_to_error(fib6_type); in ip6_rt_init_dst_reject()
1068 rt->dst.output = dst_discard_out; in ip6_rt_init_dst_reject()
1069 rt->dst.input = dst_discard; in ip6_rt_init_dst_reject()
1072 rt->dst.output = ip6_pkt_prohibit_out; in ip6_rt_init_dst_reject()
1073 rt->dst.input = ip6_pkt_prohibit; in ip6_rt_init_dst_reject()
1078 rt->dst.output = ip6_pkt_discard_out; in ip6_rt_init_dst_reject()
1079 rt->dst.input = ip6_pkt_discard; in ip6_rt_init_dst_reject()
1086 struct fib6_info *f6i = res->f6i; in ip6_rt_init_dst()
1088 if (res->fib6_flags & RTF_REJECT) { in ip6_rt_init_dst()
1089 ip6_rt_init_dst_reject(rt, res->fib6_type); in ip6_rt_init_dst()
1093 rt->dst.error = 0; in ip6_rt_init_dst()
1094 rt->dst.output = ip6_output; in ip6_rt_init_dst()
1096 if (res->fib6_type == RTN_LOCAL || res->fib6_type == RTN_ANYCAST) { in ip6_rt_init_dst()
1097 rt->dst.input = ip6_input; in ip6_rt_init_dst()
1098 } else if (ipv6_addr_type(&f6i->fib6_dst.addr) & IPV6_ADDR_MULTICAST) { in ip6_rt_init_dst()
1099 rt->dst.input = ip6_mc_input; in ip6_rt_init_dst()
1101 rt->dst.input = ip6_forward; in ip6_rt_init_dst()
1104 if (res->nh->fib_nh_lws) { in ip6_rt_init_dst()
1105 rt->dst.lwtstate = lwtstate_get(res->nh->fib_nh_lws); in ip6_rt_init_dst()
1106 lwtunnel_set_redirect(&rt->dst); in ip6_rt_init_dst()
1109 rt->dst.lastuse = jiffies; in ip6_rt_init_dst()
1115 rt->rt6i_flags &= ~RTF_EXPIRES; in rt6_set_from()
1116 rcu_assign_pointer(rt->from, from); in rt6_set_from()
1117 ip_dst_init_metrics(&rt->dst, from->fib6_metrics); in rt6_set_from()
1123 const struct fib6_nh *nh = res->nh; in ip6_rt_copy_init()
1124 const struct net_device *dev = nh->fib_nh_dev; in ip6_rt_copy_init()
1125 struct fib6_info *f6i = res->f6i; in ip6_rt_copy_init()
1129 rt->rt6i_dst = f6i->fib6_dst; in ip6_rt_copy_init()
1130 rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL; in ip6_rt_copy_init()
1131 rt->rt6i_flags = res->fib6_flags; in ip6_rt_copy_init()
1132 if (nh->fib_nh_gw_family) { in ip6_rt_copy_init()
1133 rt->rt6i_gateway = nh->fib_nh_gw6; in ip6_rt_copy_init()
1134 rt->rt6i_flags |= RTF_GATEWAY; in ip6_rt_copy_init()
1138 rt->rt6i_src = f6i->fib6_src; in ip6_rt_copy_init()
1147 if (fn->fn_flags & RTN_TL_ROOT) in fib6_backtrack()
1149 pn = rcu_dereference(fn->parent); in fib6_backtrack()
1155 if (fn->fn_flags & RTN_RTINFO) in fib6_backtrack()
1164 if (dst_hold_safe(&rt->dst)) in ip6_hold_safe()
1167 rt = net->ipv6.ip6_null_entry; in ip6_hold_safe()
1168 dst_hold(&rt->dst); in ip6_hold_safe()
1179 struct net_device *dev = res->nh->fib_nh_dev; in ip6_create_rt_rcu()
1180 struct fib6_info *f6i = res->f6i; in ip6_create_rt_rcu()
1198 nrt = dev_net(dev)->ipv6.ip6_null_entry; in ip6_create_rt_rcu()
1199 dst_hold(&nrt->dst); in ip6_create_rt_rcu()
1214 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in ip6_pol_route_lookup()
1216 res.f6i = rcu_dereference(fn->leaf); in ip6_pol_route_lookup()
1218 res.f6i = net->ipv6.fib6_null_entry; in ip6_pol_route_lookup()
1220 rt6_device_match(net, &res, &fl6->saddr, fl6->flowi6_oif, in ip6_pol_route_lookup()
1223 if (res.f6i == net->ipv6.fib6_null_entry) { in ip6_pol_route_lookup()
1224 fn = fib6_backtrack(fn, &fl6->saddr); in ip6_pol_route_lookup()
1228 rt = net->ipv6.ip6_null_entry; in ip6_pol_route_lookup()
1229 dst_hold(&rt->dst); in ip6_pol_route_lookup()
1235 fib6_select_path(net, &res, fl6, fl6->flowi6_oif, in ip6_pol_route_lookup()
1236 fl6->flowi6_oif != 0, skb, flags); in ip6_pol_route_lookup()
1239 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route_lookup()
1242 dst_use_noref(&rt->dst, jiffies); in ip6_pol_route_lookup()
1280 if (dst->error == 0) in rt6_lookup()
1289 /* ip6_ins_rt is called with FREE table->tb6_lock.
1301 table = rt->fib6_table; in __ip6_ins_rt()
1302 spin_lock_bh(&table->tb6_lock); in __ip6_ins_rt()
1303 err = fib6_add(&table->tb6_root, rt, info, extack); in __ip6_ins_rt()
1304 spin_unlock_bh(&table->tb6_lock); in __ip6_ins_rt()
1320 struct fib6_info *f6i = res->f6i; in ip6_rt_cache_alloc()
1339 rt->rt6i_flags |= RTF_CACHE; in ip6_rt_cache_alloc()
1340 rt->rt6i_dst.addr = *daddr; in ip6_rt_cache_alloc()
1341 rt->rt6i_dst.plen = 128; in ip6_rt_cache_alloc()
1344 if (f6i->fib6_dst.plen != 128 && in ip6_rt_cache_alloc()
1345 ipv6_addr_equal(&f6i->fib6_dst.addr, daddr)) in ip6_rt_cache_alloc()
1346 rt->rt6i_flags |= RTF_ANYCAST; in ip6_rt_cache_alloc()
1348 if (rt->rt6i_src.plen && saddr) { in ip6_rt_cache_alloc()
1349 rt->rt6i_src.addr = *saddr; in ip6_rt_cache_alloc()
1350 rt->rt6i_src.plen = 128; in ip6_rt_cache_alloc()
1360 struct fib6_info *f6i = res->f6i; in ip6_rt_pcpu_alloc()
1377 pcpu_rt->rt6i_flags |= RTF_PCPU; in ip6_rt_pcpu_alloc()
1379 if (f6i->nh) in ip6_rt_pcpu_alloc()
1380 pcpu_rt->sernum = rt_genid_ipv6(dev_net(dev)); in ip6_rt_pcpu_alloc()
1387 return rt6->sernum == rt_genid_ipv6(dev_net(rt6->dst.dev)); in rt6_is_valid()
1395 pcpu_rt = this_cpu_read(*res->nh->rt6i_pcpu); in rt6_get_pcpu_route()
1397 if (pcpu_rt && pcpu_rt->sernum && !rt6_is_valid(pcpu_rt)) { in rt6_get_pcpu_route()
1400 p = this_cpu_ptr(res->nh->rt6i_pcpu); in rt6_get_pcpu_route()
1403 dst_dev_put(&prev->dst); in rt6_get_pcpu_route()
1404 dst_release(&prev->dst); in rt6_get_pcpu_route()
1422 p = this_cpu_ptr(res->nh->rt6i_pcpu); in rt6_make_pcpu_route()
1426 if (res->f6i->fib6_destroying) { in rt6_make_pcpu_route()
1429 from = xchg((__force struct fib6_info **)&pcpu_rt->from, NULL); in rt6_make_pcpu_route()
1452 net = dev_net(rt6_ex->rt6i->dst.dev); in rt6_remove_exception()
1453 net->ipv6.rt6_stats->fib_rt_cache--; in rt6_remove_exception()
1458 from = xchg((__force struct fib6_info **)&rt6_ex->rt6i->from, NULL); in rt6_remove_exception()
1460 dst_dev_put(&rt6_ex->rt6i->dst); in rt6_remove_exception()
1462 hlist_del_rcu(&rt6_ex->hlist); in rt6_remove_exception()
1463 dst_release(&rt6_ex->rt6i->dst); in rt6_remove_exception()
1465 WARN_ON_ONCE(!bucket->depth); in rt6_remove_exception()
1466 bucket->depth--; in rt6_remove_exception()
1479 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_exception_remove_oldest()
1480 if (!oldest || time_before(rt6_ex->stamp, oldest->stamp)) in rt6_exception_remove_oldest()
1528 hlist_for_each_entry(rt6_ex, &(*bucket)->chain, hlist) { in __rt6_find_exception_spinlock()
1529 struct rt6_info *rt6 = rt6_ex->rt6i; in __rt6_find_exception_spinlock()
1530 bool matched = ipv6_addr_equal(daddr, &rt6->rt6i_dst.addr); in __rt6_find_exception_spinlock()
1534 matched = ipv6_addr_equal(saddr, &rt6->rt6i_src.addr); in __rt6_find_exception_spinlock()
1563 hlist_for_each_entry_rcu(rt6_ex, &(*bucket)->chain, hlist) { in __rt6_find_exception_rcu()
1564 struct rt6_info *rt6 = rt6_ex->rt6i; in __rt6_find_exception_rcu()
1565 bool matched = ipv6_addr_equal(daddr, &rt6->rt6i_dst.addr); in __rt6_find_exception_rcu()
1569 matched = ipv6_addr_equal(saddr, &rt6->rt6i_src.addr); in __rt6_find_exception_rcu()
1579 const struct fib6_nh *nh = res->nh; in fib6_mtu()
1582 if (res->f6i->fib6_pmtu) { in fib6_mtu()
1583 mtu = res->f6i->fib6_pmtu; in fib6_mtu()
1585 struct net_device *dev = nh->fib_nh_dev; in fib6_mtu()
1590 mtu = idev->cnf.mtu6; in fib6_mtu()
1596 return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu); in fib6_mtu()
1613 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in fib6_nh_get_excptn_bucket()
1616 bucket = rcu_dereference(nh->rt6i_exception_bucket); in fib6_nh_get_excptn_bucket()
1643 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in fib6_nh_excptn_bucket_set_flushed()
1649 rcu_assign_pointer(nh->rt6i_exception_bucket, bucket); in fib6_nh_excptn_bucket_set_flushed()
1655 struct net *net = dev_net(nrt->dst.dev); in rt6_insert_exception()
1657 struct fib6_info *f6i = res->f6i; in rt6_insert_exception()
1660 struct fib6_nh *nh = res->nh; in rt6_insert_exception()
1666 bucket = rcu_dereference_protected(nh->rt6i_exception_bucket, in rt6_insert_exception()
1672 err = -ENOMEM; in rt6_insert_exception()
1675 rcu_assign_pointer(nh->rt6i_exception_bucket, bucket); in rt6_insert_exception()
1677 err = -EINVAL; in rt6_insert_exception()
1688 if (f6i->fib6_src.plen) in rt6_insert_exception()
1689 src_key = &nrt->rt6i_src.addr; in rt6_insert_exception()
1695 if (dst_metric_raw(&nrt->dst, RTAX_MTU) >= fib6_mtu(res)) { in rt6_insert_exception()
1696 err = -EINVAL; in rt6_insert_exception()
1700 rt6_ex = __rt6_find_exception_spinlock(&bucket, &nrt->rt6i_dst.addr, in rt6_insert_exception()
1707 err = -ENOMEM; in rt6_insert_exception()
1710 rt6_ex->rt6i = nrt; in rt6_insert_exception()
1711 rt6_ex->stamp = jiffies; in rt6_insert_exception()
1712 hlist_add_head_rcu(&rt6_ex->hlist, &bucket->chain); in rt6_insert_exception()
1713 bucket->depth++; in rt6_insert_exception()
1714 net->ipv6.rt6_stats->fib_rt_cache++; in rt6_insert_exception()
1718 while (bucket->depth > max_depth) in rt6_insert_exception()
1724 /* Update fn->fn_sernum to invalidate all cached dst */ in rt6_insert_exception()
1726 spin_lock_bh(&f6i->fib6_table->tb6_lock); in rt6_insert_exception()
1728 spin_unlock_bh(&f6i->fib6_table->tb6_lock); in rt6_insert_exception()
1753 hlist_for_each_entry_safe(rt6_ex, tmp, &bucket->chain, hlist) { in fib6_nh_flush_exceptions()
1755 rcu_access_pointer(rt6_ex->rt6i->from) == from) in fib6_nh_flush_exceptions()
1758 WARN_ON_ONCE(!from && bucket->depth); in fib6_nh_flush_exceptions()
1776 if (f6i->nh) in rt6_flush_exceptions()
1777 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_flush_exceptions, in rt6_flush_exceptions()
1780 fib6_nh_flush_exceptions(f6i->fib6_nh, f6i); in rt6_flush_exceptions()
1802 * So we need to use f6i->fib6_src to redo lookup in rt6_find_cached_rt()
1805 * rt->rt6i_src is updated.) in rt6_find_cached_rt()
1807 if (res->f6i->fib6_src.plen) in rt6_find_cached_rt()
1811 bucket = fib6_nh_get_excptn_bucket(res->nh, NULL); in rt6_find_cached_rt()
1814 if (rt6_ex && !rt6_check_expired(rt6_ex->rt6i)) in rt6_find_cached_rt()
1815 ret = rt6_ex->rt6i; in rt6_find_cached_rt()
1819 if (!ret && src_key && src_key != &res->f6i->fib6_src.addr) { in rt6_find_cached_rt()
1820 src_key = &res->f6i->fib6_src.addr; in rt6_find_cached_rt()
1837 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_remove_exception()
1838 return -ENOENT; in fib6_nh_remove_exception()
1851 src_key = &rt->rt6i_src.addr; in fib6_nh_remove_exception()
1854 &rt->rt6i_dst.addr, in fib6_nh_remove_exception()
1860 err = -ENOENT; in fib6_nh_remove_exception()
1877 err = fib6_nh_remove_exception(nh, arg->plen, arg->rt); in rt6_nh_remove_exception_rt()
1888 from = rcu_dereference(rt->from); in rt6_remove_exception_rt()
1889 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_remove_exception_rt()
1890 return -EINVAL; in rt6_remove_exception_rt()
1892 if (from->nh) { in rt6_remove_exception_rt()
1895 .plen = from->fib6_src.plen in rt6_remove_exception_rt()
1900 rc = nexthop_for_each_fib6_nh(from->nh, in rt6_remove_exception_rt()
1903 return rc ? 0 : -ENOENT; in rt6_remove_exception_rt()
1906 return fib6_nh_remove_exception(from->fib6_nh, in rt6_remove_exception_rt()
1907 from->fib6_src.plen, rt); in rt6_remove_exception_rt()
1929 src_key = &rt->rt6i_src.addr; in fib6_nh_update_exception()
1931 rt6_ex = __rt6_find_exception_rcu(&bucket, &rt->rt6i_dst.addr, src_key); in fib6_nh_update_exception()
1933 rt6_ex->stamp = jiffies; in fib6_nh_update_exception()
1947 if (arg->dev != nh->fib_nh_dev || in fib6_nh_find_match()
1948 (arg->gw && !nh->fib_nh_gw_family) || in fib6_nh_find_match()
1949 (!arg->gw && nh->fib_nh_gw_family) || in fib6_nh_find_match()
1950 (arg->gw && !ipv6_addr_equal(arg->gw, &nh->fib_nh_gw6))) in fib6_nh_find_match()
1953 arg->match = nh; in fib6_nh_find_match()
1966 from = rcu_dereference(rt->from); in rt6_update_exception_stamp_rt()
1967 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_update_exception_stamp_rt()
1970 if (from->nh) { in rt6_update_exception_stamp_rt()
1972 .dev = rt->dst.dev, in rt6_update_exception_stamp_rt()
1973 .gw = &rt->rt6i_gateway, in rt6_update_exception_stamp_rt()
1976 nexthop_for_each_fib6_nh(from->nh, fib6_nh_find_match, &arg); in rt6_update_exception_stamp_rt()
1982 fib6_nh = from->fib6_nh; in rt6_update_exception_stamp_rt()
1984 fib6_nh_update_exception(fib6_nh, from->fib6_src.plen, rt); in rt6_update_exception_stamp_rt()
2002 if (dst_mtu(&rt->dst) >= mtu) in rt6_mtu_change_route_allowed()
2005 if (dst_mtu(&rt->dst) == idev->cnf.mtu6) in rt6_mtu_change_route_allowed()
2023 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_exceptions_update_pmtu()
2024 struct rt6_info *entry = rt6_ex->rt6i; in rt6_exceptions_update_pmtu()
2027 * route), the metrics of its rt->from have already in rt6_exceptions_update_pmtu()
2030 if (dst_metric_raw(&entry->dst, RTAX_MTU) && in rt6_exceptions_update_pmtu()
2032 dst_metric_set(&entry->dst, RTAX_MTU, mtu); in rt6_exceptions_update_pmtu()
2048 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_exceptions_clean_tohost()
2056 &bucket->chain, hlist) { in fib6_nh_exceptions_clean_tohost()
2057 struct rt6_info *entry = rt6_ex->rt6i; in fib6_nh_exceptions_clean_tohost()
2059 if ((entry->rt6i_flags & RTF_CACHE_GATEWAY) == in fib6_nh_exceptions_clean_tohost()
2062 &entry->rt6i_gateway)) { in fib6_nh_exceptions_clean_tohost()
2078 struct rt6_info *rt = rt6_ex->rt6i; in rt6_age_examine_exception()
2080 /* we are pruning and obsoleting aged-out and non gateway exceptions in rt6_age_examine_exception()
2083 * EXPIRES exceptions - e.g. pmtu-generated ones are pruned when in rt6_age_examine_exception()
2086 if (!(rt->rt6i_flags & RTF_EXPIRES)) { in rt6_age_examine_exception()
2087 if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) { in rt6_age_examine_exception()
2092 } else if (time_after(jiffies, rt->dst.expires)) { in rt6_age_examine_exception()
2098 if (rt->rt6i_flags & RTF_GATEWAY) { in rt6_age_examine_exception()
2101 neigh = __ipv6_neigh_lookup_noref(rt->dst.dev, &rt->rt6i_gateway); in rt6_age_examine_exception()
2103 if (!(neigh && (neigh->flags & NTF_ROUTER))) { in rt6_age_examine_exception()
2104 RT6_TRACE("purging route %p via non-router but gateway\n", in rt6_age_examine_exception()
2111 gc_args->more++; in rt6_age_examine_exception()
2123 if (!rcu_access_pointer(nh->rt6i_exception_bucket)) in fib6_nh_age_exceptions()
2132 &bucket->chain, hlist) { in fib6_nh_age_exceptions()
2152 fib6_nh_age_exceptions(nh, arg->gc_args, arg->now); in rt6_nh_age_exceptions()
2160 if (f6i->nh) { in rt6_age_exceptions()
2166 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_age_exceptions, in rt6_age_exceptions()
2169 fib6_nh_age_exceptions(f6i->fib6_nh, gc_args, now); in rt6_age_exceptions()
2179 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in fib6_table_lookup()
2184 if (res->f6i == net->ipv6.fib6_null_entry) { in fib6_table_lookup()
2185 fn = fib6_backtrack(fn, &fl6->saddr); in fib6_table_lookup()
2214 if (net->ipv6.devconf_all->forwarding == 0) in ip6_pol_route()
2220 if (res.f6i == net->ipv6.fib6_null_entry) in ip6_pol_route()
2226 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route()
2229 } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) && in ip6_pol_route()
2230 !res.nh->fib_nh_gw_family)) { in ip6_pol_route()
2233 * the daddr in the skb during the neighbor look-up is different in ip6_pol_route()
2234 * from the fl6->daddr used to look-up route here. in ip6_pol_route()
2236 rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL); in ip6_pol_route()
2261 rt = net->ipv6.ip6_null_entry; in ip6_pol_route()
2276 return ip6_pol_route(net, table, fl6->flowi6_iif, fl6, skb, flags); in ip6_pol_route_input()
2285 if (rt6_need_strict(&fl6->daddr) && dev->type != ARPHRD_PIMREG) in ip6_route_input_lookup()
2304 if (likely(outer_iph->nexthdr != IPPROTO_ICMPV6)) in ip6_multipath_l3_keys()
2312 if (!icmpv6_is_err(icmph->icmp6_type)) in ip6_multipath_l3_keys()
2325 keys->addrs.v6addrs.src = _flkeys->addrs.v6addrs.src; in ip6_multipath_l3_keys()
2326 keys->addrs.v6addrs.dst = _flkeys->addrs.v6addrs.dst; in ip6_multipath_l3_keys()
2327 keys->tags.flow_label = _flkeys->tags.flow_label; in ip6_multipath_l3_keys()
2328 keys->basic.ip_proto = _flkeys->basic.ip_proto; in ip6_multipath_l3_keys()
2330 keys->addrs.v6addrs.src = key_iph->saddr; in ip6_multipath_l3_keys()
2331 keys->addrs.v6addrs.dst = key_iph->daddr; in ip6_multipath_l3_keys()
2332 keys->tags.flow_label = ip6_flowlabel(key_iph); in ip6_multipath_l3_keys()
2333 keys->basic.ip_proto = key_iph->nexthdr; in ip6_multipath_l3_keys()
2360 hash_keys.ports.src = keys.ports.src; in rt6_multipath_custom_hash_outer()
2362 hash_keys.ports.dst = keys.ports.dst; in rt6_multipath_custom_hash_outer()
2410 hash_keys.ports.src = keys.ports.src; in rt6_multipath_custom_hash_inner()
2412 hash_keys.ports.dst = keys.ports.dst; in rt6_multipath_custom_hash_inner()
2441 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_custom_hash_fl6()
2443 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_custom_hash_fl6()
2445 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_custom_hash_fl6()
2449 hash_keys.ports.src = fl6->fl6_sport; in rt6_multipath_custom_hash_fl6()
2451 hash_keys.ports.dst = fl6->fl6_dport; in rt6_multipath_custom_hash_fl6()
2470 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2471 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2473 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2482 /* short-circuit if we already have L4 hash present */ in rt6_multipath_hash()
2483 if (skb->l4_hash) in rt6_multipath_hash()
2493 hash_keys.addrs.v6addrs.src = flkeys->addrs.v6addrs.src; in rt6_multipath_hash()
2494 hash_keys.addrs.v6addrs.dst = flkeys->addrs.v6addrs.dst; in rt6_multipath_hash()
2495 hash_keys.ports.src = flkeys->ports.src; in rt6_multipath_hash()
2496 hash_keys.ports.dst = flkeys->ports.dst; in rt6_multipath_hash()
2497 hash_keys.basic.ip_proto = flkeys->basic.ip_proto; in rt6_multipath_hash()
2501 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2502 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2503 hash_keys.ports.src = fl6->fl6_sport; in rt6_multipath_hash()
2504 hash_keys.ports.dst = fl6->fl6_dport; in rt6_multipath_hash()
2505 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2521 if (flkeys->control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) { in rt6_multipath_hash()
2523 hash_keys.addrs.v4addrs.src = flkeys->addrs.v4addrs.src; in rt6_multipath_hash()
2524 hash_keys.addrs.v4addrs.dst = flkeys->addrs.v4addrs.dst; in rt6_multipath_hash()
2525 } else if (flkeys->control.addr_type == FLOW_DISSECTOR_KEY_IPV6_ADDRS) { in rt6_multipath_hash()
2527 hash_keys.addrs.v6addrs.src = flkeys->addrs.v6addrs.src; in rt6_multipath_hash()
2528 hash_keys.addrs.v6addrs.dst = flkeys->addrs.v6addrs.dst; in rt6_multipath_hash()
2529 hash_keys.tags.flow_label = flkeys->tags.flow_label; in rt6_multipath_hash()
2530 hash_keys.basic.ip_proto = flkeys->basic.ip_proto; in rt6_multipath_hash()
2539 hash_keys.addrs.v6addrs.src = fl6->saddr; in rt6_multipath_hash()
2540 hash_keys.addrs.v6addrs.dst = fl6->daddr; in rt6_multipath_hash()
2542 hash_keys.basic.ip_proto = fl6->flowi6_proto; in rt6_multipath_hash()
2561 struct net *net = dev_net(skb->dev); in ip6_route_input()
2565 .flowi6_iif = skb->dev->ifindex, in ip6_route_input()
2566 .daddr = iph->daddr, in ip6_route_input()
2567 .saddr = iph->saddr, in ip6_route_input()
2569 .flowi6_mark = skb->mark, in ip6_route_input()
2570 .flowi6_proto = iph->nexthdr, in ip6_route_input()
2575 if (tun_info && !(tun_info->mode & IP_TUNNEL_INFO_TX)) in ip6_route_input()
2576 fl6.flowi6_tun_key.tun_id = tun_info->key.tun_id; in ip6_route_input()
2584 skb_dst_set_noref(skb, ip6_route_input_lookup(net, skb->dev, in ip6_route_input()
2594 return ip6_pol_route(net, table, fl6->flowi6_oif, fl6, skb, flags); in ip6_pol_route_output()
2604 if (ipv6_addr_type(&fl6->daddr) & in ip6_route_output_flags_noref()
2614 fl6->flowi6_iif = LOOPBACK_IFINDEX; in ip6_route_output_flags_noref()
2617 any_src = ipv6_addr_any(&fl6->saddr); in ip6_route_output_flags_noref()
2618 if ((sk && sk->sk_bound_dev_if) || rt6_need_strict(&fl6->daddr) || in ip6_route_output_flags_noref()
2619 (fl6->flowi6_oif && any_src)) in ip6_route_output_flags_noref()
2625 flags |= rt6_srcprefs2flags(inet6_sk(sk)->srcprefs); in ip6_route_output_flags_noref()
2642 if (list_empty(&rt6->dst.rt_uncached) && !dst_hold_safe(dst)) { in ip6_route_output_flags()
2643 dst = &net->ipv6.ip6_null_entry->dst; in ip6_route_output_flags()
2655 struct net_device *loopback_dev = net->loopback_dev; in ip6_blackhole_route()
2662 atomic_inc(&net->ipv6.rt6_stats->fib_rt_alloc); in ip6_blackhole_route()
2664 new = &rt->dst; in ip6_blackhole_route()
2665 new->__use = 1; in ip6_blackhole_route()
2666 new->input = dst_discard; in ip6_blackhole_route()
2667 new->output = dst_discard_out; in ip6_blackhole_route()
2669 dst_copy_metrics(new, &ort->dst); in ip6_blackhole_route()
2671 rt->rt6i_idev = in6_dev_get(loopback_dev); in ip6_blackhole_route()
2672 rt->rt6i_gateway = ort->rt6i_gateway; in ip6_blackhole_route()
2673 rt->rt6i_flags = ort->rt6i_flags & ~RTF_PCPU; in ip6_blackhole_route()
2675 memcpy(&rt->rt6i_dst, &ort->rt6i_dst, sizeof(struct rt6key)); in ip6_blackhole_route()
2677 memcpy(&rt->rt6i_src, &ort->rt6i_src, sizeof(struct rt6key)); in ip6_blackhole_route()
2682 return new ? new : ERR_PTR(-ENOMEM); in ip6_blackhole_route()
2715 return &rt->dst; in rt6_check()
2723 rt->dst.obsolete == DST_OBSOLETE_FORCE_CHK && in rt6_dst_from_check()
2725 return &rt->dst; in rt6_dst_from_check()
2739 if (rt->sernum) in ip6_dst_check()
2744 /* All IPV6 dsts are created with ->obsolete set to the value in ip6_dst_check()
2749 from = rcu_dereference(rt->from); in ip6_dst_check()
2751 if (from && (rt->rt6i_flags & RTF_PCPU || in ip6_dst_check()
2752 unlikely(!list_empty(&rt->dst.rt_uncached)))) in ip6_dst_check()
2768 if (rt->rt6i_flags & RTF_CACHE) { in ip6_negative_advice()
2792 if (rt->rt6i_flags & RTF_CACHE) { in ip6_link_failure()
2798 from = rcu_dereference(rt->from); in ip6_link_failure()
2800 fn = rcu_dereference(from->fib6_node); in ip6_link_failure()
2801 if (fn && (rt->rt6i_flags & RTF_DEFAULT)) in ip6_link_failure()
2802 WRITE_ONCE(fn->fn_sernum, -1); in ip6_link_failure()
2811 if (!(rt0->rt6i_flags & RTF_EXPIRES)) { in rt6_update_expires()
2815 from = rcu_dereference(rt0->from); in rt6_update_expires()
2817 rt0->dst.expires = from->expires; in rt6_update_expires()
2821 dst_set_expires(&rt0->dst, timeout); in rt6_update_expires()
2822 rt0->rt6i_flags |= RTF_EXPIRES; in rt6_update_expires()
2827 struct net *net = dev_net(rt->dst.dev); in rt6_do_update_pmtu()
2829 dst_metric_set(&rt->dst, RTAX_MTU, mtu); in rt6_do_update_pmtu()
2830 rt->rt6i_flags |= RTF_MODIFIED; in rt6_do_update_pmtu()
2831 rt6_update_expires(rt, net->ipv6.sysctl.ip6_rt_mtu_expires); in rt6_do_update_pmtu()
2836 return !(rt->rt6i_flags & RTF_CACHE) && in rt6_cache_allowed_for_pmtu()
2837 (rt->rt6i_flags & RTF_PCPU || rcu_access_pointer(rt->from)); in rt6_cache_allowed_for_pmtu()
2853 daddr = &iph->daddr; in __ip6_rt_update_pmtu()
2854 saddr = &iph->saddr; in __ip6_rt_update_pmtu()
2856 daddr = &sk->sk_v6_daddr; in __ip6_rt_update_pmtu()
2857 saddr = &inet6_sk(sk)->saddr; in __ip6_rt_update_pmtu()
2873 /* update rt6_ex->stamp for cache */ in __ip6_rt_update_pmtu()
2874 if (rt6->rt6i_flags & RTF_CACHE) in __ip6_rt_update_pmtu()
2881 res.f6i = rcu_dereference(rt6->from); in __ip6_rt_update_pmtu()
2885 res.fib6_flags = res.f6i->fib6_flags; in __ip6_rt_update_pmtu()
2886 res.fib6_type = res.f6i->fib6_type; in __ip6_rt_update_pmtu()
2888 if (res.f6i->nh) { in __ip6_rt_update_pmtu()
2890 .dev = dst->dev, in __ip6_rt_update_pmtu()
2891 .gw = &rt6->rt6i_gateway, in __ip6_rt_update_pmtu()
2894 nexthop_for_each_fib6_nh(res.f6i->nh, in __ip6_rt_update_pmtu()
2898 * using the dst->dev + gw. Should be impossible. in __ip6_rt_update_pmtu()
2905 res.nh = res.f6i->fib6_nh; in __ip6_rt_update_pmtu()
2912 dst_release_immediate(&nrt6->dst); in __ip6_rt_update_pmtu()
2930 const struct ipv6hdr *iph = (struct ipv6hdr *) skb->data; in ip6_update_pmtu()
2934 .flowi6_mark = mark ? mark : IP6_REPLY_MARK(net, skb->mark), in ip6_update_pmtu()
2935 .daddr = iph->daddr, in ip6_update_pmtu()
2936 .saddr = iph->saddr, in ip6_update_pmtu()
2942 if (!dst->error) in ip6_update_pmtu()
2950 int oif = sk->sk_bound_dev_if; in ip6_sk_update_pmtu()
2953 if (!oif && skb->dev) in ip6_sk_update_pmtu()
2954 oif = l3mdev_master_ifindex(skb->dev); in ip6_sk_update_pmtu()
2956 ip6_update_pmtu(skb, sock_net(sk), mtu, oif, READ_ONCE(sk->sk_mark), in ip6_sk_update_pmtu()
2957 sk->sk_uid); in ip6_sk_update_pmtu()
2960 if (!dst || !dst->obsolete || in ip6_sk_update_pmtu()
2961 dst->ops->check(dst, inet6_sk(sk)->dst_cookie)) in ip6_sk_update_pmtu()
2965 if (!sock_owned_by_user(sk) && !ipv6_addr_v4mapped(&sk->sk_v6_daddr)) in ip6_sk_update_pmtu()
2979 ipv6_addr_equal(&fl6->daddr, &sk->sk_v6_daddr) ? in ip6_sk_dst_store_flow()
2980 &sk->sk_v6_daddr : NULL, in ip6_sk_dst_store_flow()
2982 ipv6_addr_equal(&fl6->saddr, &np->saddr) ? in ip6_sk_dst_store_flow()
2983 &np->saddr : in ip6_sk_dst_store_flow()
2993 const struct fib6_nh *nh = res->nh; in ip6_redirect_nh_match()
2995 if (nh->fib_nh_flags & RTNH_F_DEAD || !nh->fib_nh_gw_family || in ip6_redirect_nh_match()
2996 fl6->flowi6_oif != nh->fib_nh_dev->ifindex) in ip6_redirect_nh_match()
3004 if (!ipv6_addr_equal(gw, &nh->fib_nh_gw6)) { in ip6_redirect_nh_match()
3007 rt_cache = rt6_find_cached_rt(res, &fl6->daddr, &fl6->saddr); in ip6_redirect_nh_match()
3009 ipv6_addr_equal(gw, &rt_cache->rt6i_gateway)) { in ip6_redirect_nh_match()
3029 arg->res->nh = nh; in fib6_nh_redirect_match()
3030 return ip6_redirect_nh_match(arg->res, arg->fl6, arg->gw, arg->ret); in fib6_nh_redirect_match()
3051 .gw = &rdfl->gateway, in __ip6_route_redirect()
3068 fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); in __ip6_route_redirect()
3074 if (rt->fib6_flags & RTF_REJECT) in __ip6_route_redirect()
3076 if (unlikely(rt->nh)) { in __ip6_route_redirect()
3077 if (nexthop_is_blackhole(rt->nh)) in __ip6_route_redirect()
3079 /* on match, res->nh is filled in and potentially ret */ in __ip6_route_redirect()
3080 if (nexthop_for_each_fib6_nh(rt->nh, in __ip6_route_redirect()
3085 res.nh = rt->fib6_nh; in __ip6_route_redirect()
3086 if (ip6_redirect_nh_match(&res, fl6, &rdfl->gateway, in __ip6_route_redirect()
3093 rt = net->ipv6.fib6_null_entry; in __ip6_route_redirect()
3094 else if (rt->fib6_flags & RTF_REJECT) { in __ip6_route_redirect()
3095 ret = net->ipv6.ip6_null_entry; in __ip6_route_redirect()
3099 if (rt == net->ipv6.fib6_null_entry) { in __ip6_route_redirect()
3100 fn = fib6_backtrack(fn, &fl6->saddr); in __ip6_route_redirect()
3106 res.nh = rt->fib6_nh; in __ip6_route_redirect()
3111 res.fib6_flags = res.f6i->fib6_flags; in __ip6_route_redirect()
3112 res.fib6_type = res.f6i->fib6_type; in __ip6_route_redirect()
3140 const struct ipv6hdr *iph = (struct ipv6hdr *) skb->data; in ip6_redirect()
3146 .daddr = iph->daddr, in ip6_redirect()
3147 .saddr = iph->saddr, in ip6_redirect()
3152 dst = ip6_route_redirect(net, &fl6, skb, &ipv6_hdr(skb)->saddr); in ip6_redirect()
3166 .daddr = msg->dest, in ip6_redirect_no_header()
3167 .saddr = iph->daddr, in ip6_redirect_no_header()
3171 dst = ip6_route_redirect(net, &fl6, skb, &iph->saddr); in ip6_redirect_no_header()
3178 ip6_redirect(skb, sock_net(sk), sk->sk_bound_dev_if, in ip6_sk_redirect()
3179 READ_ONCE(sk->sk_mark), sk->sk_uid); in ip6_sk_redirect()
3185 struct net_device *dev = dst->dev; in ip6_default_advmss()
3189 mtu -= sizeof(struct ipv6hdr) + sizeof(struct tcphdr); in ip6_default_advmss()
3191 if (mtu < net->ipv6.sysctl.ip6_rt_min_advmss) in ip6_default_advmss()
3192 mtu = net->ipv6.sysctl.ip6_rt_min_advmss; in ip6_default_advmss()
3195 * Maximal non-jumbo IPv6 payload is IPV6_MAXPLEN and in ip6_default_advmss()
3196 * corresponding MSS is IPV6_MAXPLEN - tcp_header_size. in ip6_default_advmss()
3200 if (mtu > IPV6_MAXPLEN - sizeof(struct tcphdr)) in ip6_default_advmss()
3212 * 1. mtu on route is locked - use it
3223 const struct fib6_nh *nh = res->nh; in ip6_mtu_from_fib6()
3224 struct fib6_info *f6i = res->f6i; in ip6_mtu_from_fib6()
3230 mtu = f6i->fib6_pmtu; in ip6_mtu_from_fib6()
3237 mtu = dst_metric_raw(&rt->dst, RTAX_MTU); in ip6_mtu_from_fib6()
3239 struct net_device *dev = nh->fib_nh_dev; in ip6_mtu_from_fib6()
3243 if (idev && idev->cnf.mtu6 > mtu) in ip6_mtu_from_fib6()
3244 mtu = idev->cnf.mtu6; in ip6_mtu_from_fib6()
3249 return mtu - lwtunnel_headroom(nh->fib_nh_lws, mtu); in ip6_mtu_from_fib6()
3261 return ERR_PTR(-ENODEV); in icmp6_dst_alloc()
3266 dst = ERR_PTR(-ENOMEM); in icmp6_dst_alloc()
3270 rt->dst.input = ip6_input; in icmp6_dst_alloc()
3271 rt->dst.output = ip6_output; in icmp6_dst_alloc()
3272 rt->rt6i_gateway = fl6->daddr; in icmp6_dst_alloc()
3273 rt->rt6i_dst.addr = fl6->daddr; in icmp6_dst_alloc()
3274 rt->rt6i_dst.plen = 128; in icmp6_dst_alloc()
3275 rt->rt6i_idev = idev; in icmp6_dst_alloc()
3276 dst_metric_set(&rt->dst, RTAX_HOPLIMIT, 0); in icmp6_dst_alloc()
3283 dst = xfrm_lookup(net, &rt->dst, flowi6_to_flowi(fl6), NULL, 0); in icmp6_dst_alloc()
3292 int rt_min_interval = net->ipv6.sysctl.ip6_rt_gc_min_interval; in ip6_dst_gc()
3293 int rt_elasticity = net->ipv6.sysctl.ip6_rt_gc_elasticity; in ip6_dst_gc()
3294 int rt_gc_timeout = net->ipv6.sysctl.ip6_rt_gc_timeout; in ip6_dst_gc()
3295 unsigned long rt_last_gc = net->ipv6.ip6_rt_last_gc; in ip6_dst_gc()
3302 fib6_run_gc(atomic_inc_return(&net->ipv6.ip6_rt_gc_expire), net, true); in ip6_dst_gc()
3304 if (entries < ops->gc_thresh) in ip6_dst_gc()
3305 atomic_set(&net->ipv6.ip6_rt_gc_expire, rt_gc_timeout >> 1); in ip6_dst_gc()
3307 val = atomic_read(&net->ipv6.ip6_rt_gc_expire); in ip6_dst_gc()
3308 atomic_set(&net->ipv6.ip6_rt_gc_expire, val - (val >> rt_elasticity)); in ip6_dst_gc()
3316 .flowi6_oif = cfg->fc_ifindex, in ip6_nh_lookup_table()
3318 .saddr = cfg->fc_prefsrc, in ip6_nh_lookup_table()
3325 return -EINVAL; in ip6_nh_lookup_table()
3327 if (!ipv6_addr_any(&cfg->fc_prefsrc)) in ip6_nh_lookup_table()
3332 err = fib6_table_lookup(net, table, cfg->fc_ifindex, &fl6, res, flags); in ip6_nh_lookup_table()
3333 if (!err && res->f6i != net->ipv6.fib6_null_entry) in ip6_nh_lookup_table()
3334 fib6_select_path(net, res, &fl6, cfg->fc_ifindex, in ip6_nh_lookup_table()
3335 cfg->fc_ifindex != 0, NULL, flags); in ip6_nh_lookup_table()
3346 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_route_check_nh_onlink()
3353 !ipv6_addr_any(&res.f6i->fib6_dst.addr) && in ip6_route_check_nh_onlink()
3354 (res.fib6_type != RTN_UNICAST || dev != res.nh->fib_nh_dev)) { in ip6_route_check_nh_onlink()
3357 err = -EINVAL; in ip6_route_check_nh_onlink()
3369 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_route_check_nh()
3373 int err = -EHOSTUNREACH; in ip6_route_check_nh()
3375 if (cfg->fc_table) { in ip6_route_check_nh()
3377 cfg->fc_table, flags, &res); in ip6_route_check_nh()
3382 res.nh->fib_nh_gw_family || in ip6_route_check_nh()
3383 (dev && dev != res.nh->fib_nh_dev)) in ip6_route_check_nh()
3384 err = -EHOSTUNREACH; in ip6_route_check_nh()
3389 .flowi6_oif = cfg->fc_ifindex, in ip6_route_check_nh()
3393 err = fib6_lookup(net, cfg->fc_ifindex, &fl6, &res, flags); in ip6_route_check_nh()
3395 res.nh->fib_nh_gw_family) in ip6_route_check_nh()
3396 err = -EHOSTUNREACH; in ip6_route_check_nh()
3401 fib6_select_path(net, &res, &fl6, cfg->fc_ifindex, in ip6_route_check_nh()
3402 cfg->fc_ifindex != 0, NULL, flags); in ip6_route_check_nh()
3407 if (dev != res.nh->fib_nh_dev) in ip6_route_check_nh()
3408 err = -EHOSTUNREACH; in ip6_route_check_nh()
3410 *_dev = dev = res.nh->fib_nh_dev; in ip6_route_check_nh()
3424 const struct in6_addr *gw_addr = &cfg->fc_gateway; in ip6_validate_gw()
3429 int err = -EINVAL; in ip6_validate_gw()
3433 * will return already-added prefix route via interface that in ip6_validate_gw()
3434 * prefix route was assigned to, which might be non-loopback. in ip6_validate_gw()
3443 /* IPv6 strictly inhibits using not link-local in ip6_validate_gw()
3448 * some exceptions. --ANK in ip6_validate_gw()
3449 * We allow IPv4-mapped nexthops to support RFC4798-type in ip6_validate_gw()
3459 if (cfg->fc_flags & RTNH_F_ONLINK) in ip6_validate_gw()
3474 err = -EINVAL; in ip6_validate_gw()
3478 } else if (dev->flags & IFF_LOOPBACK) { in ip6_validate_gw()
3501 (dev && (dev->flags & IFF_LOOPBACK) && in fib6_is_reject()
3513 netdevice_tracker *dev_tracker = &fib6_nh->fib_nh_dev_tracker; in fib6_nh_init()
3519 fib6_nh->fib_nh_family = AF_INET6; in fib6_nh_init()
3521 fib6_nh->last_probe = jiffies; in fib6_nh_init()
3523 if (cfg->fc_is_fdb) { in fib6_nh_init()
3524 fib6_nh->fib_nh_gw6 = cfg->fc_gateway; in fib6_nh_init()
3525 fib6_nh->fib_nh_gw_family = AF_INET6; in fib6_nh_init()
3529 err = -ENODEV; in fib6_nh_init()
3530 if (cfg->fc_ifindex) { in fib6_nh_init()
3531 dev = netdev_get_by_index(net, cfg->fc_ifindex, in fib6_nh_init()
3540 if (cfg->fc_flags & RTNH_F_ONLINK) { in fib6_nh_init()
3547 if (!(dev->flags & IFF_UP)) { in fib6_nh_init()
3549 err = -ENETDOWN; in fib6_nh_init()
3553 fib6_nh->fib_nh_flags |= RTNH_F_ONLINK; in fib6_nh_init()
3556 fib6_nh->fib_nh_weight = 1; in fib6_nh_init()
3561 addr_type = ipv6_addr_type(&cfg->fc_dst); in fib6_nh_init()
3562 if (fib6_is_reject(cfg->fc_flags, dev, addr_type)) { in fib6_nh_init()
3564 if (dev != net->loopback_dev) { in fib6_nh_init()
3569 dev = net->loopback_dev; in fib6_nh_init()
3573 err = -ENODEV; in fib6_nh_init()
3580 if (cfg->fc_flags & RTF_GATEWAY) { in fib6_nh_init()
3586 fib6_nh->fib_nh_gw6 = cfg->fc_gateway; in fib6_nh_init()
3587 fib6_nh->fib_nh_gw_family = AF_INET6; in fib6_nh_init()
3590 err = -ENODEV; in fib6_nh_init()
3594 if (idev->cnf.disable_ipv6) { in fib6_nh_init()
3595 NL_SET_ERR_MSG(extack, "IPv6 is disabled on nexthop device"); in fib6_nh_init()
3596 err = -EACCES; in fib6_nh_init()
3600 if (!(dev->flags & IFF_UP) && !cfg->fc_ignore_dev_down) { in fib6_nh_init()
3602 err = -ENETDOWN; in fib6_nh_init()
3606 if (!(cfg->fc_flags & (RTF_LOCAL | RTF_ANYCAST)) && in fib6_nh_init()
3608 fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib6_nh_init()
3610 err = fib_nh_common_init(net, &fib6_nh->nh_common, cfg->fc_encap, in fib6_nh_init()
3611 cfg->fc_encap_type, cfg, gfp_flags, extack); in fib6_nh_init()
3616 fib6_nh->rt6i_pcpu = alloc_percpu_gfp(struct rt6_info *, gfp_flags); in fib6_nh_init()
3617 if (!fib6_nh->rt6i_pcpu) { in fib6_nh_init()
3618 err = -ENOMEM; in fib6_nh_init()
3622 fib6_nh->fib_nh_dev = dev; in fib6_nh_init()
3623 fib6_nh->fib_nh_oif = dev->ifindex; in fib6_nh_init()
3630 lwtstate_put(fib6_nh->fib_nh_lws); in fib6_nh_init()
3631 fib6_nh->fib_nh_lws = NULL; in fib6_nh_init()
3647 rcu_assign_pointer(fib6_nh->rt6i_exception_bucket, NULL); in fib6_nh_release()
3654 free_percpu(fib6_nh->rt6i_pcpu); in fib6_nh_release()
3656 fib_nh_common_release(&fib6_nh->nh_common); in fib6_nh_release()
3663 if (!fib6_nh->rt6i_pcpu) in fib6_nh_release_dsts()
3669 ppcpu_rt = per_cpu_ptr(fib6_nh->rt6i_pcpu, cpu); in fib6_nh_release_dsts()
3672 dst_dev_put(&pcpu_rt->dst); in fib6_nh_release_dsts()
3673 dst_release(&pcpu_rt->dst); in fib6_nh_release_dsts()
3682 struct net *net = cfg->fc_nlinfo.nl_net; in ip6_route_info_create()
3687 int err = -EINVAL; in ip6_route_info_create()
3691 if (cfg->fc_flags & RTF_PCPU) { in ip6_route_info_create()
3697 if (cfg->fc_flags & RTF_CACHE) { in ip6_route_info_create()
3702 if (cfg->fc_type > RTN_MAX) { in ip6_route_info_create()
3707 if (cfg->fc_dst_len > 128) { in ip6_route_info_create()
3711 if (cfg->fc_src_len > 128) { in ip6_route_info_create()
3716 if (cfg->fc_src_len) { in ip6_route_info_create()
3722 if (cfg->fc_nh_id) { in ip6_route_info_create()
3723 nh = nexthop_find_by_id(net, cfg->fc_nh_id); in ip6_route_info_create()
3733 err = -ENOBUFS; in ip6_route_info_create()
3734 if (cfg->fc_nlinfo.nlh && in ip6_route_info_create()
3735 !(cfg->fc_nlinfo.nlh->nlmsg_flags & NLM_F_CREATE)) { in ip6_route_info_create()
3736 table = fib6_get_table(net, cfg->fc_table); in ip6_route_info_create()
3739 table = fib6_new_table(net, cfg->fc_table); in ip6_route_info_create()
3742 table = fib6_new_table(net, cfg->fc_table); in ip6_route_info_create()
3748 err = -ENOMEM; in ip6_route_info_create()
3753 rt->fib6_metrics = ip_fib_metrics_init(net, cfg->fc_mx, cfg->fc_mx_len, in ip6_route_info_create()
3755 if (IS_ERR(rt->fib6_metrics)) { in ip6_route_info_create()
3756 err = PTR_ERR(rt->fib6_metrics); in ip6_route_info_create()
3758 rt->fib6_metrics = (struct dst_metrics *)&dst_default_metrics; in ip6_route_info_create()
3762 if (cfg->fc_flags & RTF_ADDRCONF) in ip6_route_info_create()
3763 rt->dst_nocount = true; in ip6_route_info_create()
3765 if (cfg->fc_flags & RTF_EXPIRES) in ip6_route_info_create()
3767 clock_t_to_jiffies(cfg->fc_expires)); in ip6_route_info_create()
3771 if (cfg->fc_protocol == RTPROT_UNSPEC) in ip6_route_info_create()
3772 cfg->fc_protocol = RTPROT_BOOT; in ip6_route_info_create()
3773 rt->fib6_protocol = cfg->fc_protocol; in ip6_route_info_create()
3775 rt->fib6_table = table; in ip6_route_info_create()
3776 rt->fib6_metric = cfg->fc_metric; in ip6_route_info_create()
3777 rt->fib6_type = cfg->fc_type ? : RTN_UNICAST; in ip6_route_info_create()
3778 rt->fib6_flags = cfg->fc_flags & ~RTF_GATEWAY; in ip6_route_info_create()
3780 ipv6_addr_prefix(&rt->fib6_dst.addr, &cfg->fc_dst, cfg->fc_dst_len); in ip6_route_info_create()
3781 rt->fib6_dst.plen = cfg->fc_dst_len; in ip6_route_info_create()
3784 ipv6_addr_prefix(&rt->fib6_src.addr, &cfg->fc_src, cfg->fc_src_len); in ip6_route_info_create()
3785 rt->fib6_src.plen = cfg->fc_src_len; in ip6_route_info_create()
3788 if (rt->fib6_src.plen) { in ip6_route_info_create()
3796 rt->nh = nh; in ip6_route_info_create()
3797 fib6_nh = nexthop_fib6_nh(rt->nh); in ip6_route_info_create()
3799 err = fib6_nh_init(net, rt->fib6_nh, cfg, gfp_flags, extack); in ip6_route_info_create()
3803 fib6_nh = rt->fib6_nh; in ip6_route_info_create()
3808 addr_type = ipv6_addr_type(&cfg->fc_dst); in ip6_route_info_create()
3809 if (fib6_is_reject(cfg->fc_flags, rt->fib6_nh->fib_nh_dev, in ip6_route_info_create()
3811 rt->fib6_flags = RTF_REJECT | RTF_NONEXTHOP; in ip6_route_info_create()
3814 if (!ipv6_addr_any(&cfg->fc_prefsrc)) { in ip6_route_info_create()
3815 struct net_device *dev = fib6_nh->fib_nh_dev; in ip6_route_info_create()
3817 if (!ipv6_chk_addr(net, &cfg->fc_prefsrc, dev, 0)) { in ip6_route_info_create()
3819 err = -EINVAL; in ip6_route_info_create()
3822 rt->fib6_prefsrc.addr = cfg->fc_prefsrc; in ip6_route_info_create()
3823 rt->fib6_prefsrc.plen = 128; in ip6_route_info_create()
3825 rt->fib6_prefsrc.plen = 0; in ip6_route_info_create()
3832 ip_fib_metrics_put(rt->fib6_metrics); in ip6_route_info_create()
3847 err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, extack); in ip6_route_add()
3855 struct net *net = info->nl_net; in __ip6_del_rt()
3859 if (rt == net->ipv6.fib6_null_entry) { in __ip6_del_rt()
3860 err = -ENOENT; in __ip6_del_rt()
3864 table = rt->fib6_table; in __ip6_del_rt()
3865 spin_lock_bh(&table->tb6_lock); in __ip6_del_rt()
3867 spin_unlock_bh(&table->tb6_lock); in __ip6_del_rt()
3886 struct nl_info *info = &cfg->fc_nlinfo; in __ip6_del_rt_siblings()
3887 struct net *net = info->nl_net; in __ip6_del_rt_siblings()
3890 int err = -ENOENT; in __ip6_del_rt_siblings()
3892 if (rt == net->ipv6.fib6_null_entry) in __ip6_del_rt_siblings()
3894 table = rt->fib6_table; in __ip6_del_rt_siblings()
3895 spin_lock_bh(&table->tb6_lock); in __ip6_del_rt_siblings()
3897 if (rt->fib6_nsiblings && cfg->fc_delete_all_nh) { in __ip6_del_rt_siblings()
3904 u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in __ip6_del_rt_siblings()
3908 info->portid, seq, 0) < 0) { in __ip6_del_rt_siblings()
3912 info->skip_notify = 1; in __ip6_del_rt_siblings()
3920 info->skip_notify_kernel = 1; in __ip6_del_rt_siblings()
3921 fn = rcu_dereference_protected(rt->fib6_node, in __ip6_del_rt_siblings()
3922 lockdep_is_held(&table->tb6_lock)); in __ip6_del_rt_siblings()
3923 if (rcu_access_pointer(fn->leaf) == rt) { in __ip6_del_rt_siblings()
3926 last_sibling = list_last_entry(&rt->fib6_siblings, in __ip6_del_rt_siblings()
3930 last_sibling->fib6_next, in __ip6_del_rt_siblings()
3931 lockdep_is_held(&table->tb6_lock)); in __ip6_del_rt_siblings()
3938 rt, rt->fib6_nsiblings, in __ip6_del_rt_siblings()
3942 &rt->fib6_siblings, in __ip6_del_rt_siblings()
3952 spin_unlock_bh(&table->tb6_lock); in __ip6_del_rt_siblings()
3957 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in __ip6_del_rt_siblings()
3958 info->nlh, gfp_any()); in __ip6_del_rt_siblings()
3965 int rc = -ESRCH; in __ip6_del_cached_rt()
3967 if (cfg->fc_ifindex && rt->dst.dev->ifindex != cfg->fc_ifindex) in __ip6_del_cached_rt()
3970 if (cfg->fc_flags & RTF_GATEWAY && in __ip6_del_cached_rt()
3971 !ipv6_addr_equal(&cfg->fc_gateway, &rt->rt6i_gateway)) in __ip6_del_cached_rt()
3988 rt_cache = rt6_find_cached_rt(&res, &cfg->fc_dst, &cfg->fc_src); in ip6_del_cached_rt()
4005 rc = ip6_del_cached_rt(arg->cfg, arg->f6i, nh); in fib6_nh_del_cached_rt()
4006 return rc != -ESRCH ? rc : 0; in fib6_nh_del_cached_rt()
4016 return nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_del_cached_rt, &arg); in ip6_del_cached_rt_nh()
4025 int err = -ESRCH; in ip6_route_del()
4027 table = fib6_get_table(cfg->fc_nlinfo.nl_net, cfg->fc_table); in ip6_route_del()
4035 fn = fib6_locate(&table->tb6_root, in ip6_route_del()
4036 &cfg->fc_dst, cfg->fc_dst_len, in ip6_route_del()
4037 &cfg->fc_src, cfg->fc_src_len, in ip6_route_del()
4038 !(cfg->fc_flags & RTF_CACHE)); in ip6_route_del()
4044 if (rt->nh && cfg->fc_nh_id && in ip6_route_del()
4045 rt->nh->id != cfg->fc_nh_id) in ip6_route_del()
4048 if (cfg->fc_flags & RTF_CACHE) { in ip6_route_del()
4051 if (rt->nh) { in ip6_route_del()
4053 } else if (cfg->fc_nh_id) { in ip6_route_del()
4056 nh = rt->fib6_nh; in ip6_route_del()
4059 if (rc != -ESRCH) { in ip6_route_del()
4066 if (cfg->fc_metric && cfg->fc_metric != rt->fib6_metric) in ip6_route_del()
4068 if (cfg->fc_protocol && in ip6_route_del()
4069 cfg->fc_protocol != rt->fib6_protocol) in ip6_route_del()
4072 if (rt->nh) { in ip6_route_del()
4077 return __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
4079 if (cfg->fc_nh_id) in ip6_route_del()
4082 nh = rt->fib6_nh; in ip6_route_del()
4083 if (cfg->fc_ifindex && in ip6_route_del()
4084 (!nh->fib_nh_dev || in ip6_route_del()
4085 nh->fib_nh_dev->ifindex != cfg->fc_ifindex)) in ip6_route_del()
4087 if (cfg->fc_flags & RTF_GATEWAY && in ip6_route_del()
4088 !ipv6_addr_equal(&cfg->fc_gateway, &nh->fib_nh_gw6)) in ip6_route_del()
4095 if (cfg->fc_flags & RTF_GATEWAY) in ip6_route_del()
4096 return __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
4118 optlen = skb_tail_pointer(skb) - skb_transport_header(skb); in rt6_do_redirect()
4119 optlen -= sizeof(*msg); in rt6_do_redirect()
4128 if (ipv6_addr_is_multicast(&msg->dest)) { in rt6_do_redirect()
4134 if (ipv6_addr_equal(&msg->dest, &msg->target)) { in rt6_do_redirect()
4136 } else if (ipv6_addr_type(&msg->target) != in rt6_do_redirect()
4138 net_dbg_ratelimited("rt6_do_redirect: target address is not link-local unicast\n"); in rt6_do_redirect()
4142 in6_dev = __in6_dev_get(skb->dev); in rt6_do_redirect()
4145 if (in6_dev->cnf.forwarding || !in6_dev->cnf.accept_redirects) in rt6_do_redirect()
4150 * first-hop router for the specified ICMP Destination Address. in rt6_do_redirect()
4153 if (!ndisc_parse_options(skb->dev, msg->opt, optlen, &ndopts)) { in rt6_do_redirect()
4161 skb->dev); in rt6_do_redirect()
4163 net_dbg_ratelimited("rt6_redirect: invalid link-layer address length\n"); in rt6_do_redirect()
4169 if (rt->rt6i_flags & RTF_REJECT) { in rt6_do_redirect()
4174 /* Redirect received -> path was valid. in rt6_do_redirect()
4176 * so that this nexthop apparently is reachable. --ANK in rt6_do_redirect()
4178 dst_confirm_neigh(&rt->dst, &ipv6_hdr(skb)->saddr); in rt6_do_redirect()
4180 neigh = __neigh_lookup(&nd_tbl, &msg->target, skb->dev, 1); in rt6_do_redirect()
4188 ndisc_update(skb->dev, neigh, lladdr, NUD_STALE, in rt6_do_redirect()
4196 res.f6i = rcu_dereference(rt->from); in rt6_do_redirect()
4200 if (res.f6i->nh) { in rt6_do_redirect()
4202 .dev = dst->dev, in rt6_do_redirect()
4203 .gw = &rt->rt6i_gateway, in rt6_do_redirect()
4206 nexthop_for_each_fib6_nh(res.f6i->nh, in rt6_do_redirect()
4210 * using the dst->dev. Should be impossible in rt6_do_redirect()
4216 res.nh = res.f6i->fib6_nh; in rt6_do_redirect()
4219 res.fib6_flags = res.f6i->fib6_flags; in rt6_do_redirect()
4220 res.fib6_type = res.f6i->fib6_type; in rt6_do_redirect()
4221 nrt = ip6_rt_cache_alloc(&res, &msg->dest, NULL); in rt6_do_redirect()
4225 nrt->rt6i_flags = RTF_GATEWAY|RTF_UP|RTF_DYNAMIC|RTF_CACHE; in rt6_do_redirect()
4227 nrt->rt6i_flags &= ~RTF_GATEWAY; in rt6_do_redirect()
4229 nrt->rt6i_gateway = *(struct in6_addr *)neigh->primary_key; in rt6_do_redirect()
4233 dst_release_immediate(&nrt->dst); in rt6_do_redirect()
4237 netevent.old = &rt->dst; in rt6_do_redirect()
4238 netevent.new = &nrt->dst; in rt6_do_redirect()
4239 netevent.daddr = &msg->dest; in rt6_do_redirect()
4255 int ifindex = dev->ifindex; in rt6_get_route_info()
4265 fn = fib6_locate(&table->tb6_root, prefix, prefixlen, NULL, 0, true); in rt6_get_route_info()
4271 if (rt->nh) in rt6_get_route_info()
4273 if (rt->fib6_nh->fib_nh_dev->ifindex != ifindex) in rt6_get_route_info()
4275 if (!(rt->fib6_flags & RTF_ROUTEINFO) || in rt6_get_route_info()
4276 !rt->fib6_nh->fib_nh_gw_family) in rt6_get_route_info()
4278 if (!ipv6_addr_equal(&rt->fib6_nh->fib_nh_gw6, gwaddr)) in rt6_get_route_info()
4297 .fc_ifindex = dev->ifindex, in rt6_add_route_info()
4335 for_each_fib6_node_rt_rcu(&table->tb6_root) { in rt6_get_dflt_router()
4339 if (rt->nh) in rt6_get_dflt_router()
4342 nh = rt->fib6_nh; in rt6_get_dflt_router()
4343 if (dev == nh->fib_nh_dev && in rt6_get_dflt_router()
4344 ((rt->fib6_flags & (RTF_ADDRCONF | RTF_DEFAULT)) == (RTF_ADDRCONF | RTF_DEFAULT)) && in rt6_get_dflt_router()
4345 ipv6_addr_equal(&nh->fib_nh_gw6, addr)) in rt6_get_dflt_router()
4363 .fc_ifindex = dev->ifindex, in rt6_add_dflt_router()
4380 table->flags |= RT6_TABLE_HAS_DFLT_ROUTER; in rt6_add_dflt_router()
4393 for_each_fib6_node_rt_rcu(&table->tb6_root) { in __rt6_purge_dflt_routers()
4397 if (rt->fib6_flags & (RTF_DEFAULT | RTF_ADDRCONF) && in __rt6_purge_dflt_routers()
4398 (!idev || idev->cnf.accept_ra != 2) && in __rt6_purge_dflt_routers()
4407 table->flags &= ~RT6_TABLE_HAS_DFLT_ROUTER; in __rt6_purge_dflt_routers()
4419 head = &net->ipv6.fib_table_hash[h]; in rt6_purge_dflt_routers()
4421 if (table->flags & RT6_TABLE_HAS_DFLT_ROUTER) in rt6_purge_dflt_routers()
4434 .fc_table = l3mdev_fib_table_by_index(net, rtmsg->rtmsg_ifindex) ? in rtmsg_to_fib6_config()
4436 .fc_ifindex = rtmsg->rtmsg_ifindex, in rtmsg_to_fib6_config()
4437 .fc_metric = rtmsg->rtmsg_metric ? : IP6_RT_PRIO_USER, in rtmsg_to_fib6_config()
4438 .fc_expires = rtmsg->rtmsg_info, in rtmsg_to_fib6_config()
4439 .fc_dst_len = rtmsg->rtmsg_dst_len, in rtmsg_to_fib6_config()
4440 .fc_src_len = rtmsg->rtmsg_src_len, in rtmsg_to_fib6_config()
4441 .fc_flags = rtmsg->rtmsg_flags, in rtmsg_to_fib6_config()
4442 .fc_type = rtmsg->rtmsg_type, in rtmsg_to_fib6_config()
4446 .fc_dst = rtmsg->rtmsg_dst, in rtmsg_to_fib6_config()
4447 .fc_src = rtmsg->rtmsg_src, in rtmsg_to_fib6_config()
4448 .fc_gateway = rtmsg->rtmsg_gateway, in rtmsg_to_fib6_config()
4458 return -EINVAL; in ipv6_route_ioctl()
4459 if (!ns_capable(net->user_ns, CAP_NET_ADMIN)) in ipv6_route_ioctl()
4460 return -EPERM; in ipv6_route_ioctl()
4484 struct net *net = dev_net(dst->dev); in ip6_pkt_drop()
4489 if (netif_is_l3_master(skb->dev) || in ip6_pkt_drop()
4490 dst->dev == net->loopback_dev) in ip6_pkt_drop()
4491 idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif)); in ip6_pkt_drop()
4497 type = ipv6_addr_type(&ipv6_hdr(skb)->daddr); in ip6_pkt_drop()
4512 if (netif_is_l3_master(skb->dev)) in ip6_pkt_drop()
4527 skb->dev = skb_dst(skb)->dev; in ip6_pkt_discard_out()
4538 skb->dev = skb_dst(skb)->dev; in ip6_pkt_prohibit_out()
4553 .fc_table = l3mdev_fib_table(idev->dev) ? : RT6_TABLE_LOCAL, in addrconf_f6i_alloc()
4554 .fc_ifindex = idev->dev->ifindex, in addrconf_f6i_alloc()
4574 f6i->dst_nocount = true; in addrconf_f6i_alloc()
4577 (net->ipv6.devconf_all->disable_policy || in addrconf_f6i_alloc()
4578 idev->cnf.disable_policy)) in addrconf_f6i_alloc()
4579 f6i->dst_nopolicy = true; in addrconf_f6i_alloc()
4593 struct net *net = ((struct arg_dev_net_ip *)arg)->net; in fib6_remove_prefsrc()
4594 struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr; in fib6_remove_prefsrc()
4596 if (!rt->nh && in fib6_remove_prefsrc()
4597 rt != net->ipv6.fib6_null_entry && in fib6_remove_prefsrc()
4598 ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr) && in fib6_remove_prefsrc()
4599 !ipv6_chk_addr(net, addr, rt->fib6_nh->fib_nh_dev, 0)) { in fib6_remove_prefsrc()
4602 rt->fib6_prefsrc.plen = 0; in fib6_remove_prefsrc()
4610 struct net *net = dev_net(ifp->idev->dev); in rt6_remove_prefsrc()
4613 .addr = &ifp->addr, in rt6_remove_prefsrc()
4627 if (rt->nh) in fib6_clean_tohost()
4630 nh = rt->fib6_nh; in fib6_clean_tohost()
4631 if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) && in fib6_clean_tohost()
4632 nh->fib_nh_gw_family && ipv6_addr_equal(gateway, &nh->fib_nh_gw6)) in fib6_clean_tohost()
4633 return -1; in fib6_clean_tohost()
4662 fn = rcu_dereference_protected(rt->fib6_node, in rt6_multipath_first_sibling()
4663 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4664 iter = rcu_dereference_protected(fn->leaf, in rt6_multipath_first_sibling()
4665 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4667 if (iter->fib6_metric == rt->fib6_metric && in rt6_multipath_first_sibling()
4670 iter = rcu_dereference_protected(iter->fib6_next, in rt6_multipath_first_sibling()
4671 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4680 if (rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD || in rt6_is_dead()
4681 (rt->fib6_nh->fib_nh_flags & RTNH_F_LINKDOWN && in rt6_is_dead()
4682 ip6_ignore_linkdown(rt->fib6_nh->fib_nh_dev))) in rt6_is_dead()
4694 total += rt->fib6_nh->fib_nh_weight; in rt6_multipath_total_weight()
4696 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) { in rt6_multipath_total_weight()
4698 total += iter->fib6_nh->fib_nh_weight; in rt6_multipath_total_weight()
4706 int upper_bound = -1; in rt6_upper_bound_set()
4709 *weight += rt->fib6_nh->fib_nh_weight; in rt6_upper_bound_set()
4711 total) - 1; in rt6_upper_bound_set()
4713 atomic_set(&rt->fib6_nh->fib_nh_upper_bound, upper_bound); in rt6_upper_bound_set()
4723 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_upper_bound_set()
4736 if (!rt->fib6_nsiblings || rt->should_flush) in rt6_multipath_rebalance()
4754 struct net *net = dev_net(arg->dev); in fib6_ifup()
4756 if (rt != net->ipv6.fib6_null_entry && !rt->nh && in fib6_ifup()
4757 rt->fib6_nh->fib_nh_dev == arg->dev) { in fib6_ifup()
4758 rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags; in fib6_ifup()
4787 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_uses_dev()
4789 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_uses_dev()
4790 if (iter->fib6_nh->fib_nh_dev == dev) in rt6_multipath_uses_dev()
4800 rt->should_flush = 1; in rt6_multipath_flush()
4801 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_flush()
4802 iter->should_flush = 1; in rt6_multipath_flush()
4811 if (rt->fib6_nh->fib_nh_dev == down_dev || in rt6_multipath_dead_count()
4812 rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD) in rt6_multipath_dead_count()
4814 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_dead_count()
4815 if (iter->fib6_nh->fib_nh_dev == down_dev || in rt6_multipath_dead_count()
4816 iter->fib6_nh->fib_nh_flags & RTNH_F_DEAD) in rt6_multipath_dead_count()
4828 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_nh_flags_set()
4829 rt->fib6_nh->fib_nh_flags |= nh_flags; in rt6_multipath_nh_flags_set()
4830 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_nh_flags_set()
4831 if (iter->fib6_nh->fib_nh_dev == dev) in rt6_multipath_nh_flags_set()
4832 iter->fib6_nh->fib_nh_flags |= nh_flags; in rt6_multipath_nh_flags_set()
4839 const struct net_device *dev = arg->dev; in fib6_ifdown()
4842 if (rt == net->ipv6.fib6_null_entry || rt->nh) in fib6_ifdown()
4845 switch (arg->event) { in fib6_ifdown()
4847 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4849 if (rt->should_flush) in fib6_ifdown()
4850 return -1; in fib6_ifdown()
4851 if (!rt->fib6_nsiblings) in fib6_ifdown()
4852 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4857 if (rt->fib6_nsiblings + 1 == count) { in fib6_ifdown()
4859 return -1; in fib6_ifdown()
4866 return -2; in fib6_ifdown()
4868 if (rt->fib6_nh->fib_nh_dev != dev || in fib6_ifdown()
4869 rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) in fib6_ifdown()
4871 rt->fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib6_ifdown()
4889 if (net->ipv6.sysctl.skip_notify_on_dev_down) in rt6_sync_down_dev()
4911 struct fib6_info *f6i = arg->f6i; in fib6_nh_mtu_change()
4918 if (nh->fib_nh_dev == arg->dev) { in fib6_nh_mtu_change()
4919 struct inet6_dev *idev = __in6_dev_get(arg->dev); in fib6_nh_mtu_change()
4920 u32 mtu = f6i->fib6_pmtu; in fib6_nh_mtu_change()
4922 if (mtu >= arg->mtu || in fib6_nh_mtu_change()
4923 (mtu < arg->mtu && mtu == idev->cnf.mtu6)) in fib6_nh_mtu_change()
4924 fib6_metric_set(f6i, RTAX_MTU, arg->mtu); in fib6_nh_mtu_change()
4927 rt6_exceptions_update_pmtu(idev, nh, arg->mtu); in fib6_nh_mtu_change()
4945 idev = __in6_dev_get(arg->dev); in rt6_mtu_change_route()
4952 arg->f6i = f6i; in rt6_mtu_change_route()
4953 if (f6i->nh) { in rt6_mtu_change_route()
4955 return nexthop_for_each_fib6_nh(f6i->nh, fib6_nh_mtu_change, in rt6_mtu_change_route()
4959 return fib6_nh_mtu_change(f6i->fib6_nh, arg); in rt6_mtu_change_route()
5008 err = -EINVAL; in rtm_to_fib6_config()
5011 if (rtm->rtm_tos) { in rtm_to_fib6_config()
5018 .fc_table = rtm->rtm_table, in rtm_to_fib6_config()
5019 .fc_dst_len = rtm->rtm_dst_len, in rtm_to_fib6_config()
5020 .fc_src_len = rtm->rtm_src_len, in rtm_to_fib6_config()
5022 .fc_protocol = rtm->rtm_protocol, in rtm_to_fib6_config()
5023 .fc_type = rtm->rtm_type, in rtm_to_fib6_config()
5027 .fc_nlinfo.nl_net = sock_net(skb->sk), in rtm_to_fib6_config()
5030 if (rtm->rtm_type == RTN_UNREACHABLE || in rtm_to_fib6_config()
5031 rtm->rtm_type == RTN_BLACKHOLE || in rtm_to_fib6_config()
5032 rtm->rtm_type == RTN_PROHIBIT || in rtm_to_fib6_config()
5033 rtm->rtm_type == RTN_THROW) in rtm_to_fib6_config()
5034 cfg->fc_flags |= RTF_REJECT; in rtm_to_fib6_config()
5036 if (rtm->rtm_type == RTN_LOCAL) in rtm_to_fib6_config()
5037 cfg->fc_flags |= RTF_LOCAL; in rtm_to_fib6_config()
5039 if (rtm->rtm_flags & RTM_F_CLONED) in rtm_to_fib6_config()
5040 cfg->fc_flags |= RTF_CACHE; in rtm_to_fib6_config()
5042 cfg->fc_flags |= (rtm->rtm_flags & RTNH_F_ONLINK); in rtm_to_fib6_config()
5051 cfg->fc_nh_id = nla_get_u32(tb[RTA_NH_ID]); in rtm_to_fib6_config()
5055 cfg->fc_gateway = nla_get_in6_addr(tb[RTA_GATEWAY]); in rtm_to_fib6_config()
5056 cfg->fc_flags |= RTF_GATEWAY; in rtm_to_fib6_config()
5064 int plen = (rtm->rtm_dst_len + 7) >> 3; in rtm_to_fib6_config()
5069 nla_memcpy(&cfg->fc_dst, tb[RTA_DST], plen); in rtm_to_fib6_config()
5073 int plen = (rtm->rtm_src_len + 7) >> 3; in rtm_to_fib6_config()
5078 nla_memcpy(&cfg->fc_src, tb[RTA_SRC], plen); in rtm_to_fib6_config()
5082 cfg->fc_prefsrc = nla_get_in6_addr(tb[RTA_PREFSRC]); in rtm_to_fib6_config()
5085 cfg->fc_ifindex = nla_get_u32(tb[RTA_OIF]); in rtm_to_fib6_config()
5088 cfg->fc_metric = nla_get_u32(tb[RTA_PRIORITY]); in rtm_to_fib6_config()
5091 cfg->fc_mx = nla_data(tb[RTA_METRICS]); in rtm_to_fib6_config()
5092 cfg->fc_mx_len = nla_len(tb[RTA_METRICS]); in rtm_to_fib6_config()
5096 cfg->fc_table = nla_get_u32(tb[RTA_TABLE]); in rtm_to_fib6_config()
5099 cfg->fc_mp = nla_data(tb[RTA_MULTIPATH]); in rtm_to_fib6_config()
5100 cfg->fc_mp_len = nla_len(tb[RTA_MULTIPATH]); in rtm_to_fib6_config()
5102 err = lwtunnel_valid_encap_type_attr(cfg->fc_mp, in rtm_to_fib6_config()
5103 cfg->fc_mp_len, extack); in rtm_to_fib6_config()
5113 cfg->fc_flags |= RTF_PREF(pref); in rtm_to_fib6_config()
5117 cfg->fc_encap = tb[RTA_ENCAP]; in rtm_to_fib6_config()
5120 cfg->fc_encap_type = nla_get_u16(tb[RTA_ENCAP_TYPE]); in rtm_to_fib6_config()
5122 err = lwtunnel_valid_encap_type(cfg->fc_encap_type, extack); in rtm_to_fib6_config()
5131 cfg->fc_expires = jiffies_to_clock_t(timeout * HZ); in rtm_to_fib6_config()
5132 cfg->fc_flags |= RTF_EXPIRES; in rtm_to_fib6_config()
5153 int err = -EEXIST; in ip6_route_info_append()
5157 if (rt6_duplicate_nexthop(nh->fib6_info, rt)) in ip6_route_info_append()
5163 return -ENOMEM; in ip6_route_info_append()
5164 nh->fib6_info = rt; in ip6_route_info_append()
5165 memcpy(&nh->r_cfg, r_cfg, sizeof(*r_cfg)); in ip6_route_info_append()
5166 list_add_tail(&nh->next, rt6_nh_list); in ip6_route_info_append()
5182 if ((nlflags & NLM_F_APPEND) && rt_last && rt_last->fib6_nsiblings) { in ip6_route_mpath_notify()
5183 rt = list_first_entry(&rt_last->fib6_siblings, in ip6_route_mpath_notify()
5200 fn = rcu_dereference(rt->fib6_node); in ip6_route_mpath_should_notify()
5204 leaf = rcu_dereference(fn->leaf); in ip6_route_mpath_should_notify()
5209 (rt_can_ecmp && rt->fib6_metric == leaf->fib6_metric && in ip6_route_mpath_should_notify()
5223 return -EINVAL; in fib6_gw_from_attr()
5235 struct nl_info *info = &cfg->fc_nlinfo; in ip6_route_multipath_add()
5246 int replace = (cfg->fc_nlinfo.nlh && in ip6_route_multipath_add()
5247 (cfg->fc_nlinfo.nlh->nlmsg_flags & NLM_F_REPLACE)); in ip6_route_multipath_add()
5251 if (info->nlh && info->nlh->nlmsg_flags & NLM_F_APPEND) in ip6_route_multipath_add()
5254 remaining = cfg->fc_mp_len; in ip6_route_multipath_add()
5255 rtnh = (struct rtnexthop *)cfg->fc_mp; in ip6_route_multipath_add()
5262 if (rtnh->rtnh_ifindex) in ip6_route_multipath_add()
5263 r_cfg.fc_ifindex = rtnh->rtnh_ifindex; in ip6_route_multipath_add()
5288 r_cfg.fc_flags |= (rtnh->rtnh_flags & RTNH_F_ONLINK); in ip6_route_multipath_add()
5296 err = -EINVAL; in ip6_route_multipath_add()
5303 rt->fib6_nh->fib_nh_weight = rtnh->rtnh_hops + 1; in ip6_route_multipath_add()
5305 err = ip6_route_info_append(info->nl_net, &rt6_nh_list, in ip6_route_multipath_add()
5317 "Invalid nexthop configuration - no valid nexthops"); in ip6_route_multipath_add()
5318 return -EINVAL; in ip6_route_multipath_add()
5325 info->skip_notify = 1; in ip6_route_multipath_add()
5330 info->skip_notify_kernel = 1; in ip6_route_multipath_add()
5334 err = __ip6_ins_rt(nh->fib6_info, info, extack); in ip6_route_multipath_add()
5335 fib6_info_release(nh->fib6_info); in ip6_route_multipath_add()
5339 rt_last = nh->fib6_info; in ip6_route_multipath_add()
5343 rt_notif = nh->fib6_info; in ip6_route_multipath_add()
5346 /* nh->fib6_info is used or freed at this point, reset to NULL*/ in ip6_route_multipath_add()
5347 nh->fib6_info = NULL; in ip6_route_multipath_add()
5363 if (cfg->fc_nlinfo.nlh) { in ip6_route_multipath_add()
5364 cfg->fc_nlinfo.nlh->nlmsg_flags &= ~(NLM_F_EXCL | in ip6_route_multipath_add()
5366 cfg->fc_nlinfo.nlh->nlmsg_flags |= NLM_F_CREATE; in ip6_route_multipath_add()
5371 /* An in-kernel notification should only be sent in case the new in ip6_route_multipath_add()
5379 if (rt_notif->fib6_nsiblings != nhn - 1) in ip6_route_multipath_add()
5384 err = call_fib6_multipath_entry_notifiers(info->nl_net, in ip6_route_multipath_add()
5386 nhn - 1, extack); in ip6_route_multipath_add()
5410 ip6_route_del(&nh->r_cfg, extack); in ip6_route_multipath_add()
5415 if (nh->fib6_info) in ip6_route_multipath_add()
5416 fib6_info_release(nh->fib6_info); in ip6_route_multipath_add()
5417 list_del(&nh->next); in ip6_route_multipath_add()
5434 remaining = cfg->fc_mp_len; in ip6_route_multipath_del()
5435 rtnh = (struct rtnexthop *)cfg->fc_mp; in ip6_route_multipath_del()
5440 if (rtnh->rtnh_ifindex) in ip6_route_multipath_del()
5441 r_cfg.fc_ifindex = rtnh->rtnh_ifindex; in ip6_route_multipath_del()
5481 !nexthop_find_by_id(sock_net(skb->sk), cfg.fc_nh_id)) { in inet6_rtm_delroute()
5483 return -EINVAL; in inet6_rtm_delroute()
5522 if (nh->fib_nh_lws) { in rt6_nh_nlmsg_size()
5524 *nexthop_len += lwtunnel_get_encap_size(nh->fib_nh_lws); in rt6_nh_nlmsg_size()
5536 if (f6i->nh) { in rt6_nlmsg_size()
5538 nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_nlmsg_size, in rt6_nlmsg_size()
5542 struct fib6_nh *nh = f6i->fib6_nh; in rt6_nlmsg_size()
5545 if (f6i->fib6_nsiblings) { in rt6_nlmsg_size()
5549 &f6i->fib6_siblings, fib6_siblings) { in rt6_nlmsg_size()
5550 rt6_nh_nlmsg_size(sibling->fib6_nh, &nexthop_len); in rt6_nlmsg_size()
5553 nexthop_len += lwtunnel_get_encap_size(nh->fib_nh_lws); in rt6_nlmsg_size()
5590 if (fib_nexthop_info(skb, &fib6_nh->nh_common, AF_INET6, in rt6_fill_node_nexthop()
5598 return -EMSGSIZE; in rt6_fill_node_nexthop()
5617 return -EMSGSIZE; in rt6_fill_node()
5620 rt6_dst = &rt6->rt6i_dst; in rt6_fill_node()
5621 rt6_src = &rt6->rt6i_src; in rt6_fill_node()
5622 rt6_flags = rt6->rt6i_flags; in rt6_fill_node()
5624 rt6_dst = &rt->fib6_dst; in rt6_fill_node()
5625 rt6_src = &rt->fib6_src; in rt6_fill_node()
5626 rt6_flags = rt->fib6_flags; in rt6_fill_node()
5630 rtm->rtm_family = AF_INET6; in rt6_fill_node()
5631 rtm->rtm_dst_len = rt6_dst->plen; in rt6_fill_node()
5632 rtm->rtm_src_len = rt6_src->plen; in rt6_fill_node()
5633 rtm->rtm_tos = 0; in rt6_fill_node()
5634 if (rt->fib6_table) in rt6_fill_node()
5635 table = rt->fib6_table->tb6_id; in rt6_fill_node()
5638 rtm->rtm_table = table < 256 ? table : RT_TABLE_COMPAT; in rt6_fill_node()
5642 rtm->rtm_type = rt->fib6_type; in rt6_fill_node()
5643 rtm->rtm_flags = 0; in rt6_fill_node()
5644 rtm->rtm_scope = RT_SCOPE_UNIVERSE; in rt6_fill_node()
5645 rtm->rtm_protocol = rt->fib6_protocol; in rt6_fill_node()
5648 rtm->rtm_flags |= RTM_F_CLONED; in rt6_fill_node()
5653 rtm->rtm_dst_len = 128; in rt6_fill_node()
5654 } else if (rtm->rtm_dst_len) in rt6_fill_node()
5655 if (nla_put_in6_addr(skb, RTA_DST, &rt6_dst->addr)) in rt6_fill_node()
5661 rtm->rtm_src_len = 128; in rt6_fill_node()
5662 } else if (rtm->rtm_src_len && in rt6_fill_node()
5663 nla_put_in6_addr(skb, RTA_SRC, &rt6_src->addr)) in rt6_fill_node()
5668 if (ipv6_addr_is_multicast(&rt6_dst->addr)) { in rt6_fill_node()
5686 if (rt->fib6_prefsrc.plen) { in rt6_fill_node()
5688 saddr_buf = rt->fib6_prefsrc.addr; in rt6_fill_node()
5693 pmetrics = dst ? dst_metrics_ptr(dst) : rt->fib6_metrics->metrics; in rt6_fill_node()
5697 if (nla_put_u32(skb, RTA_PRIORITY, rt->fib6_metric)) in rt6_fill_node()
5705 nla_put_in6_addr(skb, RTA_GATEWAY, &rt6->rt6i_gateway)) in rt6_fill_node()
5708 if (dst->dev && nla_put_u32(skb, RTA_OIF, dst->dev->ifindex)) in rt6_fill_node()
5711 if (dst->lwtstate && in rt6_fill_node()
5712 lwtunnel_fill_encap(skb, dst->lwtstate, RTA_ENCAP, RTA_ENCAP_TYPE) < 0) in rt6_fill_node()
5714 } else if (rt->fib6_nsiblings) { in rt6_fill_node()
5722 if (fib_add_nexthop(skb, &rt->fib6_nh->nh_common, in rt6_fill_node()
5723 rt->fib6_nh->fib_nh_weight, AF_INET6, in rt6_fill_node()
5728 &rt->fib6_siblings, fib6_siblings) { in rt6_fill_node()
5729 if (fib_add_nexthop(skb, &sibling->fib6_nh->nh_common, in rt6_fill_node()
5730 sibling->fib6_nh->fib_nh_weight, in rt6_fill_node()
5736 } else if (rt->nh) { in rt6_fill_node()
5737 if (nla_put_u32(skb, RTA_NH_ID, rt->nh->id)) in rt6_fill_node()
5740 if (nexthop_is_blackhole(rt->nh)) in rt6_fill_node()
5741 rtm->rtm_type = RTN_BLACKHOLE; in rt6_fill_node()
5743 if (READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode) && in rt6_fill_node()
5744 rt6_fill_node_nexthop(skb, rt->nh, &nh_flags) < 0) in rt6_fill_node()
5747 rtm->rtm_flags |= nh_flags; in rt6_fill_node()
5749 if (fib_nexthop_info(skb, &rt->fib6_nh->nh_common, AF_INET6, in rt6_fill_node()
5753 rtm->rtm_flags |= nh_flags; in rt6_fill_node()
5757 expires = dst ? dst->expires : rt->expires; in rt6_fill_node()
5758 expires -= jiffies; in rt6_fill_node()
5762 if (READ_ONCE(rt->offload)) in rt6_fill_node()
5763 rtm->rtm_flags |= RTM_F_OFFLOAD; in rt6_fill_node()
5764 if (READ_ONCE(rt->trap)) in rt6_fill_node()
5765 rtm->rtm_flags |= RTM_F_TRAP; in rt6_fill_node()
5766 if (READ_ONCE(rt->offload_failed)) in rt6_fill_node()
5767 rtm->rtm_flags |= RTM_F_OFFLOAD_FAILED; in rt6_fill_node()
5770 if (rtnl_put_cacheinfo(skb, dst, 0, expires, dst ? dst->error : 0) < 0) in rt6_fill_node()
5782 return -EMSGSIZE; in rt6_fill_node()
5789 if (nh->fib_nh_dev == dev) in fib6_info_nh_uses_dev()
5798 if (f6i->nh) { in fib6_info_uses_dev()
5801 return !!nexthop_for_each_fib6_nh(f6i->nh, in fib6_info_uses_dev()
5806 if (f6i->fib6_nh->fib_nh_dev == dev) in fib6_info_uses_dev()
5809 if (f6i->fib6_nsiblings) { in fib6_info_uses_dev()
5813 &f6i->fib6_siblings, fib6_siblings) { in fib6_info_uses_dev()
5814 if (sibling->fib6_nh->fib_nh_dev == dev) in fib6_info_uses_dev()
5833 struct rt6_rtnl_dump_arg *dump = w->dump; in rt6_nh_dump_exceptions()
5843 hlist_for_each_entry(rt6_ex, &bucket->chain, hlist) { in rt6_nh_dump_exceptions()
5844 if (w->skip) { in rt6_nh_dump_exceptions()
5845 w->skip--; in rt6_nh_dump_exceptions()
5860 if (rt6_check_expired(rt6_ex->rt6i)) { in rt6_nh_dump_exceptions()
5861 w->count++; in rt6_nh_dump_exceptions()
5865 err = rt6_fill_node(dump->net, dump->skb, w->rt, in rt6_nh_dump_exceptions()
5866 &rt6_ex->rt6i->dst, NULL, NULL, 0, in rt6_nh_dump_exceptions()
5868 NETLINK_CB(dump->cb->skb).portid, in rt6_nh_dump_exceptions()
5869 dump->cb->nlh->nlmsg_seq, w->flags); in rt6_nh_dump_exceptions()
5873 w->count++; in rt6_nh_dump_exceptions()
5881 /* Return -1 if done with node, number of handled routes on partial dump */
5885 struct fib_dump_filter *filter = &arg->filter; in rt6_dump_route()
5887 struct net *net = arg->net; in rt6_dump_route()
5890 if (rt == net->ipv6.fib6_null_entry) in rt6_dump_route()
5891 return -1; in rt6_dump_route()
5893 if ((filter->flags & RTM_F_PREFIX) && in rt6_dump_route()
5894 !(rt->fib6_flags & RTF_PREFIX_RT)) { in rt6_dump_route()
5896 return -1; in rt6_dump_route()
5898 if (filter->filter_set && in rt6_dump_route()
5899 ((filter->rt_type && rt->fib6_type != filter->rt_type) || in rt6_dump_route()
5900 (filter->dev && !fib6_info_uses_dev(rt, filter->dev)) || in rt6_dump_route()
5901 (filter->protocol && rt->fib6_protocol != filter->protocol))) { in rt6_dump_route()
5902 return -1; in rt6_dump_route()
5905 if (filter->filter_set || in rt6_dump_route()
5906 !filter->dump_routes || !filter->dump_exceptions) { in rt6_dump_route()
5910 if (filter->dump_routes) { in rt6_dump_route()
5912 skip--; in rt6_dump_route()
5914 if (rt6_fill_node(net, arg->skb, rt, NULL, NULL, NULL, in rt6_dump_route()
5916 NETLINK_CB(arg->cb->skb).portid, in rt6_dump_route()
5917 arg->cb->nlh->nlmsg_seq, flags)) { in rt6_dump_route()
5924 if (filter->dump_exceptions) { in rt6_dump_route()
5933 if (rt->nh) { in rt6_dump_route()
5934 err = nexthop_for_each_fib6_nh(rt->nh, in rt6_dump_route()
5938 err = rt6_nh_dump_exceptions(rt->fib6_nh, &w); in rt6_dump_route()
5946 return -1; in rt6_dump_route()
5957 if (nlh->nlmsg_len < nlmsg_msg_size(sizeof(*rtm))) { in inet6_rtm_valid_getroute_req()
5960 return -EINVAL; in inet6_rtm_valid_getroute_req()
5968 if ((rtm->rtm_src_len && rtm->rtm_src_len != 128) || in inet6_rtm_valid_getroute_req()
5969 (rtm->rtm_dst_len && rtm->rtm_dst_len != 128) || in inet6_rtm_valid_getroute_req()
5970 rtm->rtm_table || rtm->rtm_protocol || rtm->rtm_scope || in inet6_rtm_valid_getroute_req()
5971 rtm->rtm_type) { in inet6_rtm_valid_getroute_req()
5973 return -EINVAL; in inet6_rtm_valid_getroute_req()
5975 if (rtm->rtm_flags & ~RTM_F_FIB_MATCH) { in inet6_rtm_valid_getroute_req()
5978 return -EINVAL; in inet6_rtm_valid_getroute_req()
5986 if ((tb[RTA_SRC] && !rtm->rtm_src_len) || in inet6_rtm_valid_getroute_req()
5987 (tb[RTA_DST] && !rtm->rtm_dst_len)) { in inet6_rtm_valid_getroute_req()
5989 return -EINVAL; in inet6_rtm_valid_getroute_req()
6009 return -EINVAL; in inet6_rtm_valid_getroute_req()
6019 struct net *net = sock_net(in_skb->sk); in inet6_rtm_getroute()
6034 err = -EINVAL; in inet6_rtm_getroute()
6036 fl6.flowlabel = ip6_make_flowinfo(rtm->rtm_tos, 0); in inet6_rtm_getroute()
6037 fibmatch = !!(rtm->rtm_flags & RTM_F_FIB_MATCH); in inet6_rtm_getroute()
6091 err = -ENODEV; in inet6_rtm_getroute()
6111 if (rt->dst.error) { in inet6_rtm_getroute()
6112 err = rt->dst.error; in inet6_rtm_getroute()
6117 if (rt == net->ipv6.ip6_null_entry) { in inet6_rtm_getroute()
6118 err = rt->dst.error; in inet6_rtm_getroute()
6126 err = -ENOBUFS; in inet6_rtm_getroute()
6130 skb_dst_set(skb, &rt->dst); in inet6_rtm_getroute()
6133 from = rcu_dereference(rt->from); in inet6_rtm_getroute()
6139 nlh->nlmsg_seq, 0); in inet6_rtm_getroute()
6144 nlh->nlmsg_seq, 0); in inet6_rtm_getroute()
6146 err = -ENETUNREACH; in inet6_rtm_getroute()
6164 struct net *net = info->nl_net; in inet6_rt_notify()
6168 err = -ENOBUFS; in inet6_rt_notify()
6169 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in inet6_rt_notify()
6176 event, info->portid, seq, nlm_flags); in inet6_rt_notify()
6178 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ in inet6_rt_notify()
6179 WARN_ON(err == -EMSGSIZE); in inet6_rt_notify()
6183 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in inet6_rt_notify()
6184 info->nlh, gfp_any()); in inet6_rt_notify()
6194 u32 seq = info->nlh ? info->nlh->nlmsg_seq : 0; in fib6_rt_update()
6196 int err = -ENOBUFS; in fib6_rt_update()
6203 RTM_NEWROUTE, info->portid, seq, NLM_F_REPLACE); in fib6_rt_update()
6205 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ in fib6_rt_update()
6206 WARN_ON(err == -EMSGSIZE); in fib6_rt_update()
6210 rtnl_notify(skb, net, info->portid, RTNLGRP_IPV6_ROUTE, in fib6_rt_update()
6211 info->nlh, gfp_any()); in fib6_rt_update()
6224 if (READ_ONCE(f6i->offload) == offload && in fib6_info_hw_flags_set()
6225 READ_ONCE(f6i->trap) == trap && in fib6_info_hw_flags_set()
6226 READ_ONCE(f6i->offload_failed) == offload_failed) in fib6_info_hw_flags_set()
6229 WRITE_ONCE(f6i->offload, offload); in fib6_info_hw_flags_set()
6230 WRITE_ONCE(f6i->trap, trap); in fib6_info_hw_flags_set()
6233 if (net->ipv6.sysctl.fib_notify_on_flag_change == 2 && in fib6_info_hw_flags_set()
6234 READ_ONCE(f6i->offload_failed) == offload_failed) in fib6_info_hw_flags_set()
6237 WRITE_ONCE(f6i->offload_failed, offload_failed); in fib6_info_hw_flags_set()
6239 if (!rcu_access_pointer(f6i->fib6_node)) in fib6_info_hw_flags_set()
6245 if (!net->ipv6.sysctl.fib_notify_on_flag_change) in fib6_info_hw_flags_set()
6250 err = -ENOBUFS; in fib6_info_hw_flags_set()
6257 /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ in fib6_info_hw_flags_set()
6258 WARN_ON(err == -EMSGSIZE); in fib6_info_hw_flags_set()
6277 if (!(dev->flags & IFF_LOOPBACK)) in ip6_route_dev_notify()
6281 net->ipv6.fib6_null_entry->fib6_nh->fib_nh_dev = dev; in ip6_route_dev_notify()
6282 net->ipv6.ip6_null_entry->dst.dev = dev; in ip6_route_dev_notify()
6283 net->ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6285 net->ipv6.ip6_prohibit_entry->dst.dev = dev; in ip6_route_dev_notify()
6286 net->ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6287 net->ipv6.ip6_blk_hole_entry->dst.dev = dev; in ip6_route_dev_notify()
6288 net->ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(dev); in ip6_route_dev_notify()
6291 dev->reg_state != NETREG_UNREGISTERED) { in ip6_route_dev_notify()
6295 in6_dev_put_clear(&net->ipv6.ip6_null_entry->rt6i_idev); in ip6_route_dev_notify()
6297 in6_dev_put_clear(&net->ipv6.ip6_prohibit_entry->rt6i_idev); in ip6_route_dev_notify()
6298 in6_dev_put_clear(&net->ipv6.ip6_blk_hole_entry->rt6i_idev); in ip6_route_dev_notify()
6312 struct net *net = (struct net *)seq->private; in rt6_stats_seq_show()
6314 net->ipv6.rt6_stats->fib_nodes, in rt6_stats_seq_show()
6315 net->ipv6.rt6_stats->fib_route_nodes, in rt6_stats_seq_show()
6316 atomic_read(&net->ipv6.rt6_stats->fib_rt_alloc), in rt6_stats_seq_show()
6317 net->ipv6.rt6_stats->fib_rt_entries, in rt6_stats_seq_show()
6318 net->ipv6.rt6_stats->fib_rt_cache, in rt6_stats_seq_show()
6319 dst_entries_get_slow(&net->ipv6.ip6_dst_ops), in rt6_stats_seq_show()
6320 net->ipv6.rt6_stats->fib_discarded_routes); in rt6_stats_seq_show()
6335 return -EINVAL; in ipv6_sysctl_rtcache_flush()
6337 net = (struct net *)ctl->extra1; in ipv6_sysctl_rtcache_flush()
6338 delay = net->ipv6.sysctl.flush_delay; in ipv6_sysctl_rtcache_flush()
6439 table[0].data = &net->ipv6.sysctl.ip6_rt_max_size; in ipv6_route_sysctl_init()
6440 table[1].data = &net->ipv6.ip6_dst_ops.gc_thresh; in ipv6_route_sysctl_init()
6441 table[2].data = &net->ipv6.sysctl.flush_delay; in ipv6_route_sysctl_init()
6443 table[3].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; in ipv6_route_sysctl_init()
6444 table[4].data = &net->ipv6.sysctl.ip6_rt_gc_timeout; in ipv6_route_sysctl_init()
6445 table[5].data = &net->ipv6.sysctl.ip6_rt_gc_interval; in ipv6_route_sysctl_init()
6446 table[6].data = &net->ipv6.sysctl.ip6_rt_gc_elasticity; in ipv6_route_sysctl_init()
6447 table[7].data = &net->ipv6.sysctl.ip6_rt_mtu_expires; in ipv6_route_sysctl_init()
6448 table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss; in ipv6_route_sysctl_init()
6449 table[9].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; in ipv6_route_sysctl_init()
6450 table[10].data = &net->ipv6.sysctl.skip_notify_on_dev_down; in ipv6_route_sysctl_init()
6453 if (net->user_ns != &init_user_ns) in ipv6_route_sysctl_init()
6463 if (net->user_ns != &init_user_ns) in ipv6_route_sysctl_table_size()
6472 int ret = -ENOMEM; in ip6_route_net_init()
6474 memcpy(&net->ipv6.ip6_dst_ops, &ip6_dst_ops_template, in ip6_route_net_init()
6475 sizeof(net->ipv6.ip6_dst_ops)); in ip6_route_net_init()
6477 if (dst_entries_init(&net->ipv6.ip6_dst_ops) < 0) in ip6_route_net_init()
6480 net->ipv6.fib6_null_entry = fib6_info_alloc(GFP_KERNEL, true); in ip6_route_net_init()
6481 if (!net->ipv6.fib6_null_entry) in ip6_route_net_init()
6483 memcpy(net->ipv6.fib6_null_entry, &fib6_null_entry_template, in ip6_route_net_init()
6484 sizeof(*net->ipv6.fib6_null_entry)); in ip6_route_net_init()
6486 net->ipv6.ip6_null_entry = kmemdup(&ip6_null_entry_template, in ip6_route_net_init()
6487 sizeof(*net->ipv6.ip6_null_entry), in ip6_route_net_init()
6489 if (!net->ipv6.ip6_null_entry) in ip6_route_net_init()
6491 net->ipv6.ip6_null_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6492 dst_init_metrics(&net->ipv6.ip6_null_entry->dst, in ip6_route_net_init()
6494 INIT_LIST_HEAD(&net->ipv6.ip6_null_entry->dst.rt_uncached); in ip6_route_net_init()
6497 net->ipv6.fib6_has_custom_rules = false; in ip6_route_net_init()
6498 net->ipv6.ip6_prohibit_entry = kmemdup(&ip6_prohibit_entry_template, in ip6_route_net_init()
6499 sizeof(*net->ipv6.ip6_prohibit_entry), in ip6_route_net_init()
6501 if (!net->ipv6.ip6_prohibit_entry) in ip6_route_net_init()
6503 net->ipv6.ip6_prohibit_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6504 dst_init_metrics(&net->ipv6.ip6_prohibit_entry->dst, in ip6_route_net_init()
6506 INIT_LIST_HEAD(&net->ipv6.ip6_prohibit_entry->dst.rt_uncached); in ip6_route_net_init()
6508 net->ipv6.ip6_blk_hole_entry = kmemdup(&ip6_blk_hole_entry_template, in ip6_route_net_init()
6509 sizeof(*net->ipv6.ip6_blk_hole_entry), in ip6_route_net_init()
6511 if (!net->ipv6.ip6_blk_hole_entry) in ip6_route_net_init()
6513 net->ipv6.ip6_blk_hole_entry->dst.ops = &net->ipv6.ip6_dst_ops; in ip6_route_net_init()
6514 dst_init_metrics(&net->ipv6.ip6_blk_hole_entry->dst, in ip6_route_net_init()
6516 INIT_LIST_HEAD(&net->ipv6.ip6_blk_hole_entry->dst.rt_uncached); in ip6_route_net_init()
6518 net->ipv6.fib6_routes_require_src = 0; in ip6_route_net_init()
6522 net->ipv6.sysctl.flush_delay = 0; in ip6_route_net_init()
6523 net->ipv6.sysctl.ip6_rt_max_size = INT_MAX; in ip6_route_net_init()
6524 net->ipv6.sysctl.ip6_rt_gc_min_interval = HZ / 2; in ip6_route_net_init()
6525 net->ipv6.sysctl.ip6_rt_gc_timeout = 60*HZ; in ip6_route_net_init()
6526 net->ipv6.sysctl.ip6_rt_gc_interval = 30*HZ; in ip6_route_net_init()
6527 net->ipv6.sysctl.ip6_rt_gc_elasticity = 9; in ip6_route_net_init()
6528 net->ipv6.sysctl.ip6_rt_mtu_expires = 10*60*HZ; in ip6_route_net_init()
6529 net->ipv6.sysctl.ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40; in ip6_route_net_init()
6530 net->ipv6.sysctl.skip_notify_on_dev_down = 0; in ip6_route_net_init()
6532 atomic_set(&net->ipv6.ip6_rt_gc_expire, 30*HZ); in ip6_route_net_init()
6540 kfree(net->ipv6.ip6_prohibit_entry); in ip6_route_net_init()
6542 kfree(net->ipv6.ip6_null_entry); in ip6_route_net_init()
6545 kfree(net->ipv6.fib6_null_entry); in ip6_route_net_init()
6547 dst_entries_destroy(&net->ipv6.ip6_dst_ops); in ip6_route_net_init()
6554 kfree(net->ipv6.fib6_null_entry); in ip6_route_net_exit()
6555 kfree(net->ipv6.ip6_null_entry); in ip6_route_net_exit()
6557 kfree(net->ipv6.ip6_prohibit_entry); in ip6_route_net_exit()
6558 kfree(net->ipv6.ip6_blk_hole_entry); in ip6_route_net_exit()
6560 dst_entries_destroy(&net->ipv6.ip6_dst_ops); in ip6_route_net_exit()
6566 if (!proc_create_net("ipv6_route", 0, net->proc_net, in ip6_route_net_init_late()
6569 return -ENOMEM; in ip6_route_net_init_late()
6571 if (!proc_create_net_single("rt6_stats", 0444, net->proc_net, in ip6_route_net_init_late()
6573 remove_proc_entry("ipv6_route", net->proc_net); in ip6_route_net_init_late()
6574 return -ENOMEM; in ip6_route_net_init_late()
6583 remove_proc_entry("ipv6_route", net->proc_net); in ip6_route_net_exit_late()
6584 remove_proc_entry("rt6_stats", net->proc_net); in ip6_route_net_exit_late()
6595 struct inet_peer_base *bp = kmalloc(sizeof(*bp), GFP_KERNEL); in ipv6_inetpeer_init() local
6597 if (!bp) in ipv6_inetpeer_init()
6598 return -ENOMEM; in ipv6_inetpeer_init()
6599 inet_peer_base_init(bp); in ipv6_inetpeer_init()
6600 net->ipv6.peers = bp; in ipv6_inetpeer_init()
6606 struct inet_peer_base *bp = net->ipv6.peers; in ipv6_inetpeer_exit() local
6608 net->ipv6.peers = NULL; in ipv6_inetpeer_exit()
6609 inetpeer_invalidate_tree(bp); in ipv6_inetpeer_exit()
6610 kfree(bp); in ipv6_inetpeer_exit()
6625 .priority = ADDRCONF_NOTIFY_PRIORITY - 10,
6633 init_net.ipv6.fib6_null_entry->fib6_nh->fib_nh_dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6634 init_net.ipv6.ip6_null_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6635 init_net.ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6637 init_net.ipv6.ip6_prohibit_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6638 init_net.ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6639 init_net.ipv6.ip6_blk_hole_entry->dst.dev = init_net.loopback_dev; in ip6_route_init_special_entries()
6640 init_net.ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(init_net.loopback_dev); in ip6_route_init_special_entries()
6686 ret = -ENOMEM; in ip6_route_init()
6754 INIT_LIST_HEAD(&ul->head); in ip6_route_init()
6755 INIT_LIST_HEAD(&ul->quarantine); in ip6_route_init()
6756 spin_lock_init(&ul->lock); in ip6_route_init()