Lines Matching full:rt
111 struct fib6_info *rt, struct dst_entry *dst,
138 void rt6_uncached_list_add(struct rt6_info *rt) in rt6_uncached_list_add() argument
142 rt->dst.rt_uncached_list = ul; in rt6_uncached_list_add()
145 list_add_tail(&rt->dst.rt_uncached, &ul->head); in rt6_uncached_list_add()
149 void rt6_uncached_list_del(struct rt6_info *rt) in rt6_uncached_list_del() argument
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()
155 list_del_init(&rt->dst.rt_uncached); in rt6_uncached_list_del()
166 struct rt6_info *rt, *safe; in rt6_uncached_list_flush_dev() local
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()
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()
228 const struct rt6_info *rt = dst_rt6_info(dst); in ip6_dst_neigh_lookup() local
230 return ip6_neigh_lookup(rt6_nexthop(rt, &in6addr_any), in ip6_dst_neigh_lookup()
236 const struct rt6_info *rt = dst_rt6_info(dst); in ip6_confirm_neigh() local
239 daddr = choose_neigh_daddr(rt6_nexthop(rt, &in6addr_any), NULL, daddr); in ip6_confirm_neigh()
333 static void rt6_info_init(struct rt6_info *rt) in rt6_info_init() argument
335 memset_after(rt, 0, dst); in rt6_info_init()
342 struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev, in ip6_dst_alloc() local
345 if (rt) { in ip6_dst_alloc()
346 rt6_info_init(rt); in ip6_dst_alloc()
350 return rt; in ip6_dst_alloc()
356 struct rt6_info *rt = dst_rt6_info(dst); in ip6_dst_destroy() local
361 rt6_uncached_list_del(rt); in ip6_dst_destroy()
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()
375 struct rt6_info *rt = dst_rt6_info(dst); in ip6_dst_ifdown() local
376 struct inet6_dev *idev = rt->rt6i_idev; in ip6_dst_ifdown()
383 rt->rt6i_idev = blackhole_idev; in ip6_dst_ifdown()
387 from = unrcu_pointer(xchg(&rt->from, NULL)); in ip6_dst_ifdown()
391 static bool __rt6_check_expired(const struct rt6_info *rt) in __rt6_check_expired() argument
393 if (rt->rt6i_flags & RTF_EXPIRES) in __rt6_check_expired()
394 return time_after(jiffies, rt->dst.expires); in __rt6_check_expired()
399 static bool rt6_check_expired(const struct rt6_info *rt) in rt6_check_expired() argument
403 from = rcu_dereference(rt->from); in rt6_check_expired()
405 if (rt->rt6i_flags & RTF_EXPIRES) { in rt6_check_expired()
406 if (time_after(jiffies, rt->dst.expires)) in rt6_check_expired()
409 return rt->dst.obsolete != DST_OBSOLETE_FORCE_CHK || in rt6_check_expired()
416 rt6_multipath_first_sibling_rcu(const struct fib6_info *rt) in rt6_multipath_first_sibling_rcu() argument
421 fn = rcu_dereference(rt->fib6_node); in rt6_multipath_first_sibling_rcu()
429 if (iter->fib6_metric == rt->fib6_metric && in rt6_multipath_first_sibling_rcu()
976 struct fib6_info *rt; in rt6_route_rcv() local
1014 rt = rt6_get_dflt_router(net, gwaddr, dev); in rt6_route_rcv()
1016 rt = rt6_get_route_info(net, prefix, rinfo->prefix_len, in rt6_route_rcv()
1019 if (rt && !lifetime) { in rt6_route_rcv()
1020 ip6_del_rt(net, rt, false); in rt6_route_rcv()
1021 rt = NULL; in rt6_route_rcv()
1024 if (!rt && lifetime) in rt6_route_rcv()
1025 rt = rt6_add_route_info(net, prefix, rinfo->prefix_len, gwaddr, in rt6_route_rcv()
1027 else if (rt) in rt6_route_rcv()
1028 rt->fib6_flags = RTF_ROUTEINFO | in rt6_route_rcv()
1029 (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); in rt6_route_rcv()
1031 if (rt) { in rt6_route_rcv()
1032 table = rt->fib6_table; in rt6_route_rcv()
1036 fib6_clean_expires(rt); in rt6_route_rcv()
1037 fib6_remove_gc_list(rt); in rt6_route_rcv()
1039 fib6_set_expires(rt, jiffies + HZ * lifetime); in rt6_route_rcv()
1040 fib6_add_gc_list(rt); in rt6_route_rcv()
1045 fib6_info_release(rt); in rt6_route_rcv()
1098 static unsigned short fib6_info_dst_flags(struct fib6_info *rt) in fib6_info_dst_flags() argument
1102 if (rt->dst_nocount) in fib6_info_dst_flags()
1104 if (rt->dst_nopolicy) in fib6_info_dst_flags()
1110 static void ip6_rt_init_dst_reject(struct rt6_info *rt, u8 fib6_type) in ip6_rt_init_dst_reject() argument
1112 rt->dst.error = ip6_rt_type_to_error(fib6_type); in ip6_rt_init_dst_reject()
1116 rt->dst.output = dst_discard_out; in ip6_rt_init_dst_reject()
1117 rt->dst.input = dst_discard; in ip6_rt_init_dst_reject()
1120 rt->dst.output = ip6_pkt_prohibit_out; in ip6_rt_init_dst_reject()
1121 rt->dst.input = ip6_pkt_prohibit; in ip6_rt_init_dst_reject()
1126 rt->dst.output = ip6_pkt_discard_out; in ip6_rt_init_dst_reject()
1127 rt->dst.input = ip6_pkt_discard; in ip6_rt_init_dst_reject()
1132 static void ip6_rt_init_dst(struct rt6_info *rt, const struct fib6_result *res) in ip6_rt_init_dst() argument
1137 ip6_rt_init_dst_reject(rt, res->fib6_type); in ip6_rt_init_dst()
1141 rt->dst.error = 0; in ip6_rt_init_dst()
1142 rt->dst.output = ip6_output; in ip6_rt_init_dst()
1145 rt->dst.input = ip6_input; in ip6_rt_init_dst()
1147 rt->dst.input = ip6_mc_input; in ip6_rt_init_dst()
1149 rt->dst.input = ip6_forward; in ip6_rt_init_dst()
1153 rt->dst.lwtstate = lwtstate_get(res->nh->fib_nh_lws); in ip6_rt_init_dst()
1154 lwtunnel_set_redirect(&rt->dst); in ip6_rt_init_dst()
1157 rt->dst.lastuse = jiffies; in ip6_rt_init_dst()
1161 static void rt6_set_from(struct rt6_info *rt, struct fib6_info *from) in rt6_set_from() argument
1163 rt->rt6i_flags &= ~RTF_EXPIRES; in rt6_set_from()
1164 rcu_assign_pointer(rt->from, from); in rt6_set_from()
1165 ip_dst_init_metrics(&rt->dst, from->fib6_metrics); in rt6_set_from()
1169 static void ip6_rt_copy_init(struct rt6_info *rt, const struct fib6_result *res) in ip6_rt_copy_init() argument
1175 ip6_rt_init_dst(rt, res); in ip6_rt_copy_init()
1177 rt->rt6i_dst = f6i->fib6_dst; in ip6_rt_copy_init()
1178 rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL; in ip6_rt_copy_init()
1179 rt->rt6i_flags = res->fib6_flags; in ip6_rt_copy_init()
1181 rt->rt6i_gateway = nh->fib_nh_gw6; in ip6_rt_copy_init()
1182 rt->rt6i_flags |= RTF_GATEWAY; in ip6_rt_copy_init()
1184 rt6_set_from(rt, f6i); in ip6_rt_copy_init()
1186 rt->rt6i_src = f6i->fib6_src; in ip6_rt_copy_init()
1210 struct rt6_info *rt = *prt; in ip6_hold_safe() local
1212 if (dst_hold_safe(&rt->dst)) in ip6_hold_safe()
1215 rt = net->ipv6.ip6_null_entry; in ip6_hold_safe()
1216 dst_hold(&rt->dst); in ip6_hold_safe()
1218 rt = NULL; in ip6_hold_safe()
1220 *prt = rt; in ip6_hold_safe()
1259 struct rt6_info *rt; in ip6_pol_route_lookup() local
1276 rt = net->ipv6.ip6_null_entry; in ip6_pol_route_lookup()
1277 dst_hold(&rt->dst); in ip6_pol_route_lookup()
1287 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route_lookup()
1288 if (rt) { in ip6_pol_route_lookup()
1289 if (ip6_hold_safe(net, &rt)) in ip6_pol_route_lookup()
1290 dst_use_noref(&rt->dst, jiffies); in ip6_pol_route_lookup()
1293 rt = ip6_create_rt_rcu(&res); in ip6_pol_route_lookup()
1301 return rt; in ip6_pol_route_lookup()
1343 static int __ip6_ins_rt(struct fib6_info *rt, struct nl_info *info, in __ip6_ins_rt() argument
1349 table = rt->fib6_table; in __ip6_ins_rt()
1351 err = fib6_add(&table->tb6_root, rt, info, extack); in __ip6_ins_rt()
1357 int ip6_ins_rt(struct net *net, struct fib6_info *rt) in ip6_ins_rt() argument
1361 return __ip6_ins_rt(rt, &info, NULL); in ip6_ins_rt()
1370 struct rt6_info *rt; in ip6_rt_cache_alloc() local
1380 rt = ip6_dst_alloc(dev_net(dev), dev, 0); in ip6_rt_cache_alloc()
1381 if (!rt) { in ip6_rt_cache_alloc()
1386 ip6_rt_copy_init(rt, res); in ip6_rt_cache_alloc()
1387 rt->rt6i_flags |= RTF_CACHE; in ip6_rt_cache_alloc()
1388 rt->rt6i_dst.addr = *daddr; in ip6_rt_cache_alloc()
1389 rt->rt6i_dst.plen = 128; in ip6_rt_cache_alloc()
1394 rt->rt6i_flags |= RTF_ANYCAST; in ip6_rt_cache_alloc()
1396 if (rt->rt6i_src.plen && saddr) { in ip6_rt_cache_alloc()
1397 rt->rt6i_src.addr = *saddr; in ip6_rt_cache_alloc()
1398 rt->rt6i_src.plen = 128; in ip6_rt_cache_alloc()
1403 return rt; in ip6_rt_cache_alloc()
1555 /* Helper function to find the cached rt in the hash table
1588 /* Helper function to find the cached rt in the hash table
1832 /* Find cached rt in the hash table inside passed in rt
1854 * rt->rt6i_src is updated.) in rt6_find_cached_rt()
1877 /* Remove the passed in cached rt from the hash table that contains it */
1879 const struct rt6_info *rt) in fib6_nh_remove_exception() argument
1900 src_key = &rt->rt6i_src.addr; in fib6_nh_remove_exception()
1903 &rt->rt6i_dst.addr, in fib6_nh_remove_exception()
1917 struct rt6_info *rt; member
1926 err = fib6_nh_remove_exception(nh, arg->plen, arg->rt); in rt6_nh_remove_exception_rt()
1933 static int rt6_remove_exception_rt(struct rt6_info *rt) in rt6_remove_exception_rt() argument
1937 from = rcu_dereference(rt->from); in rt6_remove_exception_rt()
1938 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_remove_exception_rt()
1943 .rt = rt, in rt6_remove_exception_rt()
1956 from->fib6_src.plen, rt); in rt6_remove_exception_rt()
1959 /* Find rt6_ex which contains the passed in rt cache and
1963 const struct rt6_info *rt) in fib6_nh_update_exception() argument
1978 src_key = &rt->rt6i_src.addr; in fib6_nh_update_exception()
1980 rt6_ex = __rt6_find_exception_rcu(&bucket, &rt->rt6i_dst.addr, src_key); in fib6_nh_update_exception()
2008 static void rt6_update_exception_stamp_rt(struct rt6_info *rt) in rt6_update_exception_stamp_rt() argument
2015 from = rcu_dereference(rt->from); in rt6_update_exception_stamp_rt()
2016 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_update_exception_stamp_rt()
2021 .dev = rt->dst.dev, in rt6_update_exception_stamp_rt()
2022 .gw = &rt->rt6i_gateway, in rt6_update_exception_stamp_rt()
2033 fib6_nh_update_exception(fib6_nh, from->fib6_src.plen, rt); in rt6_update_exception_stamp_rt()
2039 struct rt6_info *rt, int mtu) in rt6_mtu_change_route_allowed() argument
2051 if (dst_mtu(&rt->dst) >= mtu) in rt6_mtu_change_route_allowed()
2054 if (dst_mtu(&rt->dst) == idev->cnf.mtu6) in rt6_mtu_change_route_allowed()
2076 * route), the metrics of its rt->from have already in rt6_exceptions_update_pmtu()
2127 struct rt6_info *rt = rt6_ex->rt6i; in rt6_age_examine_exception() local
2135 if (!(rt->rt6i_flags & RTF_EXPIRES)) { in rt6_age_examine_exception()
2136 if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) { in rt6_age_examine_exception()
2137 pr_debug("aging clone %p\n", rt); in rt6_age_examine_exception()
2141 } else if (time_after(jiffies, rt->dst.expires)) { in rt6_age_examine_exception()
2142 pr_debug("purging expired route %p\n", rt); in rt6_age_examine_exception()
2147 if (rt->rt6i_flags & RTF_GATEWAY) { in rt6_age_examine_exception()
2150 neigh = __ipv6_neigh_lookup_noref(rt->dst.dev, &rt->rt6i_gateway); in rt6_age_examine_exception()
2154 rt); in rt6_age_examine_exception()
2255 struct rt6_info *rt = NULL; in ip6_pol_route() local
2275 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route()
2276 if (rt) { in ip6_pol_route()
2285 rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL); in ip6_pol_route()
2287 if (rt) { in ip6_pol_route()
2293 rt6_uncached_list_add(rt); in ip6_pol_route()
2296 return rt; in ip6_pol_route()
2301 rt = rt6_get_pcpu_route(&res); in ip6_pol_route()
2303 if (!rt) in ip6_pol_route()
2304 rt = rt6_make_pcpu_route(net, &res); in ip6_pol_route()
2309 if (!rt) in ip6_pol_route()
2310 rt = net->ipv6.ip6_null_entry; in ip6_pol_route()
2312 ip6_hold_safe(net, &rt); in ip6_pol_route()
2315 return rt; in ip6_pol_route()
2710 struct rt6_info *rt, *ort = dst_rt6_info(dst_orig); in ip6_blackhole_route() local
2714 rt = dst_alloc(&ip6_dst_blackhole_ops, loopback_dev, in ip6_blackhole_route()
2716 if (rt) { in ip6_blackhole_route()
2717 rt6_info_init(rt); in ip6_blackhole_route()
2720 new = &rt->dst; in ip6_blackhole_route()
2727 rt->rt6i_idev = in6_dev_get(loopback_dev); in ip6_blackhole_route()
2728 rt->rt6i_gateway = ort->rt6i_gateway; in ip6_blackhole_route()
2729 rt->rt6i_flags = ort->rt6i_flags & ~RTF_PCPU; in ip6_blackhole_route()
2731 memcpy(&rt->rt6i_dst, &ort->rt6i_dst, sizeof(struct rt6key)); in ip6_blackhole_route()
2733 memcpy(&rt->rt6i_src, &ort->rt6i_src, sizeof(struct rt6key)); in ip6_blackhole_route()
2758 static struct dst_entry *rt6_check(struct rt6_info *rt, in rt6_check() argument
2768 if (rt6_check_expired(rt)) in rt6_check()
2771 return &rt->dst; in rt6_check()
2774 static struct dst_entry *rt6_dst_from_check(struct rt6_info *rt, in rt6_dst_from_check() argument
2778 if (!__rt6_check_expired(rt) && in rt6_dst_from_check()
2779 rt->dst.obsolete == DST_OBSOLETE_FORCE_CHK && in rt6_dst_from_check()
2781 return &rt->dst; in rt6_dst_from_check()
2791 struct rt6_info *rt; in ip6_dst_check() local
2793 rt = dst_rt6_info(dst); in ip6_dst_check()
2795 if (rt->sernum) in ip6_dst_check()
2796 return rt6_is_valid(rt) ? dst : NULL; in ip6_dst_check()
2805 from = rcu_dereference(rt->from); in ip6_dst_check()
2807 if (from && (rt->rt6i_flags & RTF_PCPU || in ip6_dst_check()
2808 unlikely(!list_empty(&rt->dst.rt_uncached)))) in ip6_dst_check()
2809 dst_ret = rt6_dst_from_check(rt, from, cookie); in ip6_dst_check()
2811 dst_ret = rt6_check(rt, from, cookie); in ip6_dst_check()
2822 struct rt6_info *rt = dst_rt6_info(dst); in ip6_negative_advice() local
2824 if (rt->rt6i_flags & RTF_CACHE) { in ip6_negative_advice()
2826 if (rt6_check_expired(rt)) { in ip6_negative_advice()
2827 /* rt/dst can not be destroyed yet, in ip6_negative_advice()
2831 rt6_remove_exception_rt(rt); in ip6_negative_advice()
2841 struct rt6_info *rt; in ip6_link_failure() local
2845 rt = dst_rt6_info(skb_dst(skb)); in ip6_link_failure()
2846 if (rt) { in ip6_link_failure()
2848 if (rt->rt6i_flags & RTF_CACHE) { in ip6_link_failure()
2849 rt6_remove_exception_rt(rt); in ip6_link_failure()
2854 from = rcu_dereference(rt->from); in ip6_link_failure()
2857 if (fn && (rt->rt6i_flags & RTF_DEFAULT)) in ip6_link_failure()
2881 static void rt6_do_update_pmtu(struct rt6_info *rt, u32 mtu) in rt6_do_update_pmtu() argument
2883 struct net *net = dev_net(rt->dst.dev); in rt6_do_update_pmtu()
2885 dst_metric_set(&rt->dst, RTAX_MTU, mtu); in rt6_do_update_pmtu()
2886 rt->rt6i_flags |= RTF_MODIFIED; in rt6_do_update_pmtu()
2887 rt6_update_expires(rt, net->ipv6.sysctl.ip6_rt_mtu_expires); in rt6_do_update_pmtu()
2890 static bool rt6_cache_allowed_for_pmtu(const struct rt6_info *rt) in rt6_cache_allowed_for_pmtu() argument
2892 return !(rt->rt6i_flags & RTF_CACHE) && in rt6_cache_allowed_for_pmtu()
2893 (rt->rt6i_flags & RTF_PCPU || rcu_access_pointer(rt->from)); in rt6_cache_allowed_for_pmtu()
3110 struct fib6_info *rt; in __ip6_route_redirect() local
3127 res.f6i = rt; in __ip6_route_redirect()
3128 if (fib6_check_expired(rt)) in __ip6_route_redirect()
3130 if (rt->fib6_flags & RTF_REJECT) in __ip6_route_redirect()
3132 if (unlikely(rt->nh)) { in __ip6_route_redirect()
3133 if (nexthop_is_blackhole(rt->nh)) in __ip6_route_redirect()
3136 if (nexthop_for_each_fib6_nh(rt->nh, in __ip6_route_redirect()
3141 res.nh = rt->fib6_nh; in __ip6_route_redirect()
3148 if (!rt) in __ip6_route_redirect()
3149 rt = net->ipv6.fib6_null_entry; in __ip6_route_redirect()
3150 else if (rt->fib6_flags & RTF_REJECT) { in __ip6_route_redirect()
3155 if (rt == net->ipv6.fib6_null_entry) { in __ip6_route_redirect()
3161 res.f6i = rt; in __ip6_route_redirect()
3162 res.nh = rt->fib6_nh; in __ip6_route_redirect()
3287 struct rt6_info *rt; in ip6_mtu_from_fib6() local
3296 rt = rt6_find_cached_rt(res, daddr, saddr); in ip6_mtu_from_fib6()
3297 if (unlikely(rt)) { in ip6_mtu_from_fib6()
3298 mtu = dst_metric_raw(&rt->dst, RTAX_MTU); in ip6_mtu_from_fib6()
3317 struct rt6_info *rt; in icmp6_dst_alloc() local
3324 rt = ip6_dst_alloc(net, dev, 0); in icmp6_dst_alloc()
3325 if (unlikely(!rt)) { in icmp6_dst_alloc()
3331 rt->dst.input = ip6_input; in icmp6_dst_alloc()
3332 rt->dst.output = ip6_output; in icmp6_dst_alloc()
3333 rt->rt6i_gateway = fl6->daddr; in icmp6_dst_alloc()
3334 rt->rt6i_dst.addr = fl6->daddr; in icmp6_dst_alloc()
3335 rt->rt6i_dst.plen = 128; in icmp6_dst_alloc()
3336 rt->rt6i_idev = idev; in icmp6_dst_alloc()
3337 dst_metric_set(&rt->dst, RTAX_HOPLIMIT, 0); in icmp6_dst_alloc()
3342 rt6_uncached_list_add(rt); in icmp6_dst_alloc()
3344 dst = xfrm_lookup(net, &rt->dst, flowi6_to_flowi(fl6), NULL, 0); in icmp6_dst_alloc()
3793 struct fib6_info *rt; in ip6_route_info_create() local
3811 rt = fib6_info_alloc(gfp_flags, !cfg->fc_nh_id); in ip6_route_info_create()
3812 if (!rt) { in ip6_route_info_create()
3817 rt->fib6_metrics = ip_fib_metrics_init(cfg->fc_mx, cfg->fc_mx_len, in ip6_route_info_create()
3819 if (IS_ERR(rt->fib6_metrics)) { in ip6_route_info_create()
3820 err = PTR_ERR(rt->fib6_metrics); in ip6_route_info_create()
3825 rt->dst_nocount = true; in ip6_route_info_create()
3828 fib6_set_expires(rt, jiffies + in ip6_route_info_create()
3834 rt->fib6_protocol = cfg->fc_protocol; in ip6_route_info_create()
3835 rt->fib6_table = table; in ip6_route_info_create()
3836 rt->fib6_metric = cfg->fc_metric; in ip6_route_info_create()
3837 rt->fib6_type = cfg->fc_type ? : RTN_UNICAST; in ip6_route_info_create()
3838 rt->fib6_flags = cfg->fc_flags & ~RTF_GATEWAY; in ip6_route_info_create()
3840 ipv6_addr_prefix(&rt->fib6_dst.addr, &cfg->fc_dst, cfg->fc_dst_len); in ip6_route_info_create()
3841 rt->fib6_dst.plen = cfg->fc_dst_len; in ip6_route_info_create()
3844 ipv6_addr_prefix(&rt->fib6_src.addr, &cfg->fc_src, cfg->fc_src_len); in ip6_route_info_create()
3845 rt->fib6_src.plen = cfg->fc_src_len; in ip6_route_info_create()
3847 return rt; in ip6_route_info_create()
3849 kfree(rt); in ip6_route_info_create()
3854 static int ip6_route_info_create_nh(struct fib6_info *rt, in ip6_route_info_create_nh() argument
3885 rt->nh = nh; in ip6_route_info_create_nh()
3886 fib6_nh = nexthop_fib6_nh(rt->nh); in ip6_route_info_create_nh()
3892 err = fib6_nh_init(net, rt->fib6_nh, cfg, gfp_flags, extack); in ip6_route_info_create_nh()
3896 fib6_nh = rt->fib6_nh; in ip6_route_info_create_nh()
3902 if (fib6_is_reject(cfg->fc_flags, rt->fib6_nh->fib_nh_dev, in ip6_route_info_create_nh()
3904 rt->fib6_flags = RTF_REJECT | RTF_NONEXTHOP; in ip6_route_info_create_nh()
3915 rt->fib6_prefsrc.addr = cfg->fc_prefsrc; in ip6_route_info_create_nh()
3916 rt->fib6_prefsrc.plen = 128; in ip6_route_info_create_nh()
3921 fib6_info_release(rt); in ip6_route_info_create_nh()
3925 ip_fib_metrics_put(rt->fib6_metrics); in ip6_route_info_create_nh()
3926 kfree(rt); in ip6_route_info_create_nh()
3933 struct fib6_info *rt; in ip6_route_add() local
3940 rt = ip6_route_info_create(cfg, gfp_flags, extack); in ip6_route_add()
3941 if (IS_ERR(rt)) in ip6_route_add()
3942 return PTR_ERR(rt); in ip6_route_add()
3944 err = ip6_route_info_create_nh(rt, cfg, gfp_flags, extack); in ip6_route_add()
3948 err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, extack); in ip6_route_add()
3949 fib6_info_release(rt); in ip6_route_add()
3954 static int __ip6_del_rt(struct fib6_info *rt, struct nl_info *info) in __ip6_del_rt() argument
3960 if (rt == net->ipv6.fib6_null_entry) { in __ip6_del_rt()
3965 table = rt->fib6_table; in __ip6_del_rt()
3967 err = fib6_del(rt, info); in __ip6_del_rt()
3971 fib6_info_release(rt); in __ip6_del_rt()
3975 int ip6_del_rt(struct net *net, struct fib6_info *rt, bool skip_notify) in ip6_del_rt() argument
3982 return __ip6_del_rt(rt, &info); in ip6_del_rt()
3985 static int __ip6_del_rt_siblings(struct fib6_info *rt, struct fib6_config *cfg) in __ip6_del_rt_siblings() argument
3993 if (rt == net->ipv6.fib6_null_entry) in __ip6_del_rt_siblings()
3995 table = rt->fib6_table; in __ip6_del_rt_siblings()
3998 if (rt->fib6_nsiblings && cfg->fc_delete_all_nh) { in __ip6_del_rt_siblings()
4003 skb = nlmsg_new(rt6_nlmsg_size(rt), gfp_any()); in __ip6_del_rt_siblings()
4007 if (rt6_fill_node(net, skb, rt, NULL, in __ip6_del_rt_siblings()
4016 /* 'rt' points to the first sibling route. If it is not the in __ip6_del_rt_siblings()
4022 fn = rcu_dereference_protected(rt->fib6_node, in __ip6_del_rt_siblings()
4024 if (rcu_access_pointer(fn->leaf) == rt) { in __ip6_del_rt_siblings()
4027 last_sibling = list_last_entry(&rt->fib6_siblings, in __ip6_del_rt_siblings()
4039 rt, rt->fib6_nsiblings, in __ip6_del_rt_siblings()
4043 &rt->fib6_siblings, in __ip6_del_rt_siblings()
4051 err = fib6_del(rt, info); in __ip6_del_rt_siblings()
4055 fib6_info_release(rt); in __ip6_del_rt_siblings()
4064 static int __ip6_del_cached_rt(struct rt6_info *rt, struct fib6_config *cfg) in __ip6_del_cached_rt() argument
4068 if (cfg->fc_ifindex && rt->dst.dev->ifindex != cfg->fc_ifindex) in __ip6_del_cached_rt()
4072 !ipv6_addr_equal(&cfg->fc_gateway, &rt->rt6i_gateway)) in __ip6_del_cached_rt()
4075 rc = rt6_remove_exception_rt(rt); in __ip6_del_cached_rt()
4080 static int ip6_del_cached_rt(struct fib6_config *cfg, struct fib6_info *rt, in ip6_del_cached_rt() argument
4084 .f6i = rt, in ip6_del_cached_rt()
4124 struct fib6_info *rt; in ip6_route_del() local
4145 if (rt->nh && cfg->fc_nh_id && in ip6_route_del()
4146 rt->nh->id != cfg->fc_nh_id) in ip6_route_del()
4152 if (rt->nh) { in ip6_route_del()
4153 rc = ip6_del_cached_rt_nh(cfg, rt); in ip6_route_del()
4157 nh = rt->fib6_nh; in ip6_route_del()
4158 rc = ip6_del_cached_rt(cfg, rt, nh); in ip6_route_del()
4167 if (cfg->fc_metric && cfg->fc_metric != rt->fib6_metric) in ip6_route_del()
4170 cfg->fc_protocol != rt->fib6_protocol) in ip6_route_del()
4173 if (rt->nh) { in ip6_route_del()
4174 if (!fib6_info_hold_safe(rt)) in ip6_route_del()
4177 err = __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
4183 nh = rt->fib6_nh; in ip6_route_del()
4191 if (!fib6_info_hold_safe(rt)) in ip6_route_del()
4196 err = __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
4198 err = __ip6_del_rt_siblings(rt, cfg); in ip6_route_del()
4210 struct rt6_info *rt, *nrt = NULL; in rt6_do_redirect() local
4270 rt = dst_rt6_info(dst); in rt6_do_redirect()
4271 if (rt->rt6i_flags & RTF_REJECT) { in rt6_do_redirect()
4280 dst_confirm_neigh(&rt->dst, &ipv6_hdr(skb)->saddr); in rt6_do_redirect()
4298 res.f6i = rcu_dereference(rt->from); in rt6_do_redirect()
4305 .gw = &rt->rt6i_gateway, in rt6_do_redirect()
4339 netevent.old = &rt->dst; in rt6_do_redirect()
4359 struct fib6_info *rt = NULL; in rt6_get_route_info() local
4373 if (rt->nh) in rt6_get_route_info()
4375 if (rt->fib6_nh->fib_nh_dev->ifindex != ifindex) in rt6_get_route_info()
4377 if (!(rt->fib6_flags & RTF_ROUTEINFO) || in rt6_get_route_info()
4378 !rt->fib6_nh->fib_nh_gw_family) in rt6_get_route_info()
4380 if (!ipv6_addr_equal(&rt->fib6_nh->fib_nh_gw6, gwaddr)) in rt6_get_route_info()
4382 if (!fib6_info_hold_safe(rt)) in rt6_get_route_info()
4388 return rt; in rt6_get_route_info()
4429 struct fib6_info *rt; in rt6_get_dflt_router() local
4441 if (rt->nh) in rt6_get_dflt_router()
4444 nh = rt->fib6_nh; in rt6_get_dflt_router()
4446 ((rt->fib6_flags & (RTF_ADDRCONF | RTF_DEFAULT)) == (RTF_ADDRCONF | RTF_DEFAULT)) && in rt6_get_dflt_router()
4450 if (rt && !fib6_info_hold_safe(rt)) in rt6_get_dflt_router()
4451 rt = NULL; in rt6_get_dflt_router()
4453 return rt; in rt6_get_dflt_router()
4493 struct fib6_info *rt; in __rt6_purge_dflt_routers() local
4498 struct net_device *dev = fib6_info_nh_dev(rt); in __rt6_purge_dflt_routers()
4501 if (rt->fib6_flags & (RTF_DEFAULT | RTF_ADDRCONF) && in __rt6_purge_dflt_routers()
4503 fib6_info_hold_safe(rt)) { in __rt6_purge_dflt_routers()
4505 ip6_del_rt(net, rt, false); in __rt6_purge_dflt_routers()
4703 static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg) in fib6_remove_prefsrc() argument
4708 if (!rt->nh && in fib6_remove_prefsrc()
4709 rt != net->ipv6.fib6_null_entry && in fib6_remove_prefsrc()
4710 ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr) && in fib6_remove_prefsrc()
4711 !ipv6_chk_addr(net, addr, rt->fib6_nh->fib_nh_dev, 0)) { in fib6_remove_prefsrc()
4714 rt->fib6_prefsrc.plen = 0; in fib6_remove_prefsrc()
4733 static int fib6_clean_tohost(struct fib6_info *rt, void *arg) in fib6_clean_tohost() argument
4739 if (rt->nh) in fib6_clean_tohost()
4742 nh = rt->fib6_nh; in fib6_clean_tohost()
4743 if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) && in fib6_clean_tohost()
4769 static struct fib6_info *rt6_multipath_first_sibling(const struct fib6_info *rt) in rt6_multipath_first_sibling() argument
4774 fn = rcu_dereference_protected(rt->fib6_node, in rt6_multipath_first_sibling()
4775 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4777 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4779 if (iter->fib6_metric == rt->fib6_metric && in rt6_multipath_first_sibling()
4783 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4790 static bool rt6_is_dead(const struct fib6_info *rt) in rt6_is_dead() argument
4792 if (rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD || in rt6_is_dead()
4793 (rt->fib6_nh->fib_nh_flags & RTNH_F_LINKDOWN && in rt6_is_dead()
4794 ip6_ignore_linkdown(rt->fib6_nh->fib_nh_dev))) in rt6_is_dead()
4800 static int rt6_multipath_total_weight(const struct fib6_info *rt) in rt6_multipath_total_weight() argument
4805 if (!rt6_is_dead(rt)) in rt6_multipath_total_weight()
4806 total += rt->fib6_nh->fib_nh_weight; in rt6_multipath_total_weight()
4808 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) { in rt6_multipath_total_weight()
4816 static void rt6_upper_bound_set(struct fib6_info *rt, int *weight, int total) in rt6_upper_bound_set() argument
4820 if (!rt6_is_dead(rt)) { in rt6_upper_bound_set()
4821 *weight += rt->fib6_nh->fib_nh_weight; in rt6_upper_bound_set()
4825 atomic_set(&rt->fib6_nh->fib_nh_upper_bound, upper_bound); in rt6_upper_bound_set()
4828 static void rt6_multipath_upper_bound_set(struct fib6_info *rt, int total) in rt6_multipath_upper_bound_set() argument
4833 rt6_upper_bound_set(rt, &weight, total); in rt6_multipath_upper_bound_set()
4835 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_upper_bound_set()
4839 void rt6_multipath_rebalance(struct fib6_info *rt) in rt6_multipath_rebalance() argument
4848 if (!rt->fib6_nsiblings || rt->should_flush) in rt6_multipath_rebalance()
4855 first = rt6_multipath_first_sibling(rt); in rt6_multipath_rebalance()
4863 static int fib6_ifup(struct fib6_info *rt, void *p_arg) in fib6_ifup() argument
4868 if (rt != net->ipv6.fib6_null_entry && !rt->nh && in fib6_ifup()
4869 rt->fib6_nh->fib_nh_dev == arg->dev) { in fib6_ifup()
4870 rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags; in fib6_ifup()
4871 fib6_update_sernum_upto_root(net, rt); in fib6_ifup()
4872 rt6_multipath_rebalance(rt); in fib6_ifup()
4894 static bool rt6_multipath_uses_dev(const struct fib6_info *rt, in rt6_multipath_uses_dev() argument
4899 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_uses_dev()
4901 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_uses_dev()
4908 static void rt6_multipath_flush(struct fib6_info *rt) in rt6_multipath_flush() argument
4912 rt->should_flush = 1; in rt6_multipath_flush()
4913 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_flush()
4917 static unsigned int rt6_multipath_dead_count(const struct fib6_info *rt, in rt6_multipath_dead_count() argument
4923 if (rt->fib6_nh->fib_nh_dev == down_dev || in rt6_multipath_dead_count()
4924 rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD) in rt6_multipath_dead_count()
4926 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_dead_count()
4934 static void rt6_multipath_nh_flags_set(struct fib6_info *rt, in rt6_multipath_nh_flags_set() argument
4940 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_nh_flags_set()
4941 rt->fib6_nh->fib_nh_flags |= nh_flags; in rt6_multipath_nh_flags_set()
4942 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_nh_flags_set()
4947 /* called with write lock held for table with rt */
4948 static int fib6_ifdown(struct fib6_info *rt, void *p_arg) in fib6_ifdown() argument
4954 if (rt == net->ipv6.fib6_null_entry || rt->nh) in fib6_ifdown()
4959 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4961 if (rt->should_flush) in fib6_ifdown()
4963 if (!rt->fib6_nsiblings) in fib6_ifdown()
4964 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4965 if (rt6_multipath_uses_dev(rt, dev)) { in fib6_ifdown()
4968 count = rt6_multipath_dead_count(rt, dev); in fib6_ifdown()
4969 if (rt->fib6_nsiblings + 1 == count) { in fib6_ifdown()
4970 rt6_multipath_flush(rt); in fib6_ifdown()
4973 rt6_multipath_nh_flags_set(rt, dev, RTNH_F_DEAD | in fib6_ifdown()
4975 fib6_update_sernum(net, rt); in fib6_ifdown()
4976 rt6_multipath_rebalance(rt); in fib6_ifdown()
4980 if (rt->fib6_nh->fib_nh_dev != dev || in fib6_ifdown()
4981 rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) in fib6_ifdown()
4983 rt->fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib6_ifdown()
4984 rt6_multipath_rebalance(rt); in fib6_ifdown()
5314 struct fib6_info *rt, in ip6_route_info_append() argument
5321 if (rt6_duplicate_nexthop(nh->fib6_info, rt)) in ip6_route_info_append()
5329 nh->fib6_info = rt; in ip6_route_info_append()
5336 static void ip6_route_mpath_notify(struct fib6_info *rt, in ip6_route_mpath_notify() argument
5341 /* if this is an APPEND route, then rt points to the first route in ip6_route_mpath_notify()
5350 rt = list_first_or_null_rcu(&rt_last->fib6_siblings, in ip6_route_mpath_notify()
5355 if (rt) in ip6_route_mpath_notify()
5356 inet6_rt_notify(RTM_NEWROUTE, rt, info, nlflags); in ip6_route_mpath_notify()
5361 static bool ip6_route_mpath_should_notify(const struct fib6_info *rt) in ip6_route_mpath_should_notify() argument
5363 bool rt_can_ecmp = rt6_qualify_for_ecmp(rt); in ip6_route_mpath_should_notify()
5369 fn = rcu_dereference(rt->fib6_node); in ip6_route_mpath_should_notify()
5377 if (rt == leaf || in ip6_route_mpath_should_notify()
5378 (rt_can_ecmp && rt->fib6_metric == leaf->fib6_metric && in ip6_route_mpath_should_notify()
5397 struct fib6_info *rt; in ip6_route_multipath_add() local
5444 rt = ip6_route_info_create(&r_cfg, GFP_KERNEL, extack); in ip6_route_multipath_add()
5445 if (IS_ERR(rt)) { in ip6_route_multipath_add()
5446 err = PTR_ERR(rt); in ip6_route_multipath_add()
5447 rt = NULL; in ip6_route_multipath_add()
5451 err = ip6_route_info_create_nh(rt, &r_cfg, GFP_KERNEL, extack); in ip6_route_multipath_add()
5453 rt = NULL; in ip6_route_multipath_add()
5457 rt->fib6_nh->fib_nh_weight = rtnh->rtnh_hops + 1; in ip6_route_multipath_add()
5459 err = ip6_route_info_append(&rt6_nh_list, rt, &r_cfg); in ip6_route_multipath_add()
5461 fib6_info_release(rt); in ip6_route_multipath_add()
5745 struct fib6_info *rt, struct dst_entry *dst, in rt6_fill_node() argument
5767 rt6_dst = &rt->fib6_dst; in rt6_fill_node()
5768 rt6_src = &rt->fib6_src; in rt6_fill_node()
5769 rt6_flags = rt->fib6_flags; in rt6_fill_node()
5777 if (rt->fib6_table) in rt6_fill_node()
5778 table = rt->fib6_table->tb6_id; in rt6_fill_node()
5785 rtm->rtm_type = rt->fib6_type; in rt6_fill_node()
5788 rtm->rtm_protocol = rt->fib6_protocol; in rt6_fill_node()
5824 if (ip6_route_get_saddr(net, rt, dest, 0, 0, &saddr_buf) == 0 && in rt6_fill_node()
5829 if (rt->fib6_prefsrc.plen) { in rt6_fill_node()
5831 saddr_buf = rt->fib6_prefsrc.addr; in rt6_fill_node()
5836 pmetrics = dst ? dst_metrics_ptr(dst) : rt->fib6_metrics->metrics; in rt6_fill_node()
5840 if (nla_put_u32(skb, RTA_PRIORITY, rt->fib6_metric)) in rt6_fill_node()
5857 } else if (rt->fib6_nsiblings) { in rt6_fill_node()
5865 if (fib_add_nexthop(skb, &rt->fib6_nh->nh_common, in rt6_fill_node()
5866 rt->fib6_nh->fib_nh_weight, AF_INET6, in rt6_fill_node()
5872 list_for_each_entry_rcu(sibling, &rt->fib6_siblings, in rt6_fill_node()
5886 } else if (rt->nh) { in rt6_fill_node()
5887 if (nla_put_u32(skb, RTA_NH_ID, rt->nh->id)) in rt6_fill_node()
5890 if (nexthop_is_blackhole(rt->nh)) in rt6_fill_node()
5894 rt6_fill_node_nexthop(skb, rt->nh, &nh_flags) < 0) in rt6_fill_node()
5899 if (fib_nexthop_info(skb, &rt->fib6_nh->nh_common, AF_INET6, in rt6_fill_node()
5907 expires = dst ? dst->expires : rt->expires; in rt6_fill_node()
5912 if (READ_ONCE(rt->offload)) in rt6_fill_node()
5914 if (READ_ONCE(rt->trap)) in rt6_fill_node()
5916 if (READ_ONCE(rt->offload_failed)) in rt6_fill_node()
5974 struct fib6_info *rt; member
6015 err = rt6_fill_node(dump->net, dump->skb, w->rt, in rt6_nh_dump_exceptions()
6032 int rt6_dump_route(struct fib6_info *rt, void *p_arg, unsigned int skip) in rt6_dump_route() argument
6040 if (rt == net->ipv6.fib6_null_entry) in rt6_dump_route()
6044 !(rt->fib6_flags & RTF_PREFIX_RT)) { in rt6_dump_route()
6049 ((filter->rt_type && rt->fib6_type != filter->rt_type) || in rt6_dump_route()
6050 (filter->dev && !fib6_info_uses_dev(rt, filter->dev)) || in rt6_dump_route()
6051 (filter->protocol && rt->fib6_protocol != filter->protocol))) { in rt6_dump_route()
6064 if (rt6_fill_node(net, arg->skb, rt, NULL, NULL, NULL, in rt6_dump_route()
6076 .rt = rt, in rt6_dump_route()
6083 if (rt->nh) { in rt6_dump_route()
6084 err = nexthop_for_each_fib6_nh(rt->nh, in rt6_dump_route()
6088 err = rt6_nh_dump_exceptions(rt->fib6_nh, &w); in rt6_dump_route()
6182 struct rt6_info *rt; in inet6_rtm_getroute() local
6271 rt = dst_rt6_info(dst); in inet6_rtm_getroute()
6272 if (rt->dst.error) { in inet6_rtm_getroute()
6273 err = rt->dst.error; in inet6_rtm_getroute()
6274 ip6_rt_put(rt); in inet6_rtm_getroute()
6278 if (rt == net->ipv6.ip6_null_entry) { in inet6_rtm_getroute()
6279 err = rt->dst.error; in inet6_rtm_getroute()
6280 ip6_rt_put(rt); in inet6_rtm_getroute()
6286 ip6_rt_put(rt); in inet6_rtm_getroute()
6291 skb_dst_set(skb, &rt->dst); in inet6_rtm_getroute()
6294 from = rcu_dereference(rt->from); in inet6_rtm_getroute()
6321 void inet6_rt_notify(int event, struct fib6_info *rt, struct nl_info *info, in inet6_rt_notify() argument
6334 skb = nlmsg_new(rt6_nlmsg_size(rt), GFP_ATOMIC); in inet6_rt_notify()
6338 err = rt6_fill_node(net, skb, rt, NULL, NULL, NULL, 0, in inet6_rt_notify()
6357 void fib6_rt_update(struct net *net, struct fib6_info *rt, in fib6_rt_update() argument
6364 skb = nlmsg_new(rt6_nlmsg_size(rt), gfp_any()); in fib6_rt_update()
6368 err = rt6_fill_node(net, skb, rt, NULL, NULL, NULL, 0, in fib6_rt_update()
6806 DEFINE_BPF_ITER_FUNC(ipv6_route, struct bpf_iter_meta *meta, struct fib6_info *rt)
6822 { offsetof(struct bpf_iter__ipv6_route, rt),