Lines Matching full:rt
110 struct fib6_info *rt, struct dst_entry *dst,
137 void rt6_uncached_list_add(struct rt6_info *rt) in rt6_uncached_list_add() argument
141 rt->rt6i_uncached_list = ul; in rt6_uncached_list_add()
144 list_add_tail(&rt->rt6i_uncached, &ul->head); in rt6_uncached_list_add()
148 void rt6_uncached_list_del(struct rt6_info *rt) in rt6_uncached_list_del() argument
150 if (!list_empty(&rt->rt6i_uncached)) { in rt6_uncached_list_del()
151 struct uncached_list *ul = rt->rt6i_uncached_list; in rt6_uncached_list_del()
152 struct net *net = dev_net(rt->dst.dev); in rt6_uncached_list_del()
155 list_del(&rt->rt6i_uncached); in rt6_uncached_list_del()
171 struct rt6_info *rt; in rt6_uncached_list_flush_dev() local
174 list_for_each_entry(rt, &ul->head, rt6i_uncached) { in rt6_uncached_list_flush_dev()
175 struct inet6_dev *rt_idev = rt->rt6i_idev; in rt6_uncached_list_flush_dev()
176 struct net_device *rt_dev = rt->dst.dev; in rt6_uncached_list_flush_dev()
179 rt->rt6i_idev = in6_dev_get(loopback_dev); in rt6_uncached_list_flush_dev()
184 rt->dst.dev = blackhole_netdev; in rt6_uncached_list_flush_dev()
185 dev_hold(rt->dst.dev); in rt6_uncached_list_flush_dev()
224 const struct rt6_info *rt = container_of(dst, struct rt6_info, dst); in ip6_dst_neigh_lookup() local
226 return ip6_neigh_lookup(rt6_nexthop(rt, &in6addr_any), in ip6_dst_neigh_lookup()
233 struct rt6_info *rt = (struct rt6_info *)dst; in ip6_confirm_neigh() local
235 daddr = choose_neigh_daddr(rt6_nexthop(rt, &in6addr_any), NULL, daddr); in ip6_confirm_neigh()
329 static void rt6_info_init(struct rt6_info *rt) in rt6_info_init() argument
331 struct dst_entry *dst = &rt->dst; in rt6_info_init()
333 memset(dst + 1, 0, sizeof(*rt) - sizeof(*dst)); in rt6_info_init()
334 INIT_LIST_HEAD(&rt->rt6i_uncached); in rt6_info_init()
341 struct rt6_info *rt = dst_alloc(&net->ipv6.ip6_dst_ops, dev, in ip6_dst_alloc() local
344 if (rt) { in ip6_dst_alloc()
345 rt6_info_init(rt); in ip6_dst_alloc()
349 return rt; in ip6_dst_alloc()
355 struct rt6_info *rt = (struct rt6_info *)dst; in ip6_dst_destroy() local
360 rt6_uncached_list_del(rt); in ip6_dst_destroy()
362 idev = rt->rt6i_idev; in ip6_dst_destroy()
364 rt->rt6i_idev = NULL; in ip6_dst_destroy()
368 from = xchg((__force struct fib6_info **)&rt->from, NULL); in ip6_dst_destroy()
375 struct rt6_info *rt = (struct rt6_info *)dst; in ip6_dst_ifdown() local
376 struct inet6_dev *idev = rt->rt6i_idev; in ip6_dst_ifdown()
383 rt->rt6i_idev = loopback_idev; in ip6_dst_ifdown()
389 static bool __rt6_check_expired(const struct rt6_info *rt) in __rt6_check_expired() argument
391 if (rt->rt6i_flags & RTF_EXPIRES) in __rt6_check_expired()
392 return time_after(jiffies, rt->dst.expires); in __rt6_check_expired()
397 static bool rt6_check_expired(const struct rt6_info *rt) in rt6_check_expired() argument
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()
932 struct fib6_info *rt; in rt6_route_rcv() local
970 rt = rt6_get_dflt_router(net, gwaddr, dev); in rt6_route_rcv()
972 rt = rt6_get_route_info(net, prefix, rinfo->prefix_len, in rt6_route_rcv()
975 if (rt && !lifetime) { in rt6_route_rcv()
976 ip6_del_rt(net, rt, false); in rt6_route_rcv()
977 rt = NULL; in rt6_route_rcv()
980 if (!rt && lifetime) in rt6_route_rcv()
981 rt = rt6_add_route_info(net, prefix, rinfo->prefix_len, gwaddr, in rt6_route_rcv()
983 else if (rt) in rt6_route_rcv()
984 rt->fib6_flags = RTF_ROUTEINFO | in rt6_route_rcv()
985 (rt->fib6_flags & ~RTF_PREF_MASK) | RTF_PREF(pref); in rt6_route_rcv()
987 if (rt) { in rt6_route_rcv()
989 fib6_clean_expires(rt); in rt6_route_rcv()
991 fib6_set_expires(rt, jiffies + HZ * lifetime); in rt6_route_rcv()
993 fib6_info_release(rt); in rt6_route_rcv()
1046 static unsigned short fib6_info_dst_flags(struct fib6_info *rt) in fib6_info_dst_flags() argument
1050 if (rt->dst_nocount) in fib6_info_dst_flags()
1052 if (rt->dst_nopolicy) in fib6_info_dst_flags()
1058 static void ip6_rt_init_dst_reject(struct rt6_info *rt, u8 fib6_type) in ip6_rt_init_dst_reject() argument
1060 rt->dst.error = ip6_rt_type_to_error(fib6_type); in ip6_rt_init_dst_reject()
1064 rt->dst.output = dst_discard_out; in ip6_rt_init_dst_reject()
1065 rt->dst.input = dst_discard; in ip6_rt_init_dst_reject()
1068 rt->dst.output = ip6_pkt_prohibit_out; in ip6_rt_init_dst_reject()
1069 rt->dst.input = ip6_pkt_prohibit; in ip6_rt_init_dst_reject()
1074 rt->dst.output = ip6_pkt_discard_out; in ip6_rt_init_dst_reject()
1075 rt->dst.input = ip6_pkt_discard; in ip6_rt_init_dst_reject()
1080 static void ip6_rt_init_dst(struct rt6_info *rt, const struct fib6_result *res) in ip6_rt_init_dst() argument
1085 ip6_rt_init_dst_reject(rt, res->fib6_type); in ip6_rt_init_dst()
1089 rt->dst.error = 0; in ip6_rt_init_dst()
1090 rt->dst.output = ip6_output; in ip6_rt_init_dst()
1093 rt->dst.input = ip6_input; in ip6_rt_init_dst()
1095 rt->dst.input = ip6_mc_input; in ip6_rt_init_dst()
1097 rt->dst.input = ip6_forward; in ip6_rt_init_dst()
1101 rt->dst.lwtstate = lwtstate_get(res->nh->fib_nh_lws); in ip6_rt_init_dst()
1102 lwtunnel_set_redirect(&rt->dst); in ip6_rt_init_dst()
1105 rt->dst.lastuse = jiffies; in ip6_rt_init_dst()
1109 static void rt6_set_from(struct rt6_info *rt, struct fib6_info *from) in rt6_set_from() argument
1111 rt->rt6i_flags &= ~RTF_EXPIRES; in rt6_set_from()
1112 rcu_assign_pointer(rt->from, from); in rt6_set_from()
1113 ip_dst_init_metrics(&rt->dst, from->fib6_metrics); in rt6_set_from()
1117 static void ip6_rt_copy_init(struct rt6_info *rt, const struct fib6_result *res) in ip6_rt_copy_init() argument
1123 ip6_rt_init_dst(rt, res); in ip6_rt_copy_init()
1125 rt->rt6i_dst = f6i->fib6_dst; in ip6_rt_copy_init()
1126 rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL; in ip6_rt_copy_init()
1127 rt->rt6i_flags = res->fib6_flags; in ip6_rt_copy_init()
1129 rt->rt6i_gateway = nh->fib_nh_gw6; in ip6_rt_copy_init()
1130 rt->rt6i_flags |= RTF_GATEWAY; in ip6_rt_copy_init()
1132 rt6_set_from(rt, f6i); in ip6_rt_copy_init()
1134 rt->rt6i_src = f6i->fib6_src; in ip6_rt_copy_init()
1158 struct rt6_info *rt = *prt; in ip6_hold_safe() local
1160 if (dst_hold_safe(&rt->dst)) in ip6_hold_safe()
1163 rt = net->ipv6.ip6_null_entry; in ip6_hold_safe()
1164 dst_hold(&rt->dst); in ip6_hold_safe()
1166 rt = NULL; in ip6_hold_safe()
1168 *prt = rt; in ip6_hold_safe()
1207 struct rt6_info *rt; in ip6_pol_route_lookup() local
1227 rt = net->ipv6.ip6_null_entry; in ip6_pol_route_lookup()
1228 dst_hold(&rt->dst); in ip6_pol_route_lookup()
1238 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route_lookup()
1239 if (rt) { in ip6_pol_route_lookup()
1240 if (ip6_hold_safe(net, &rt)) in ip6_pol_route_lookup()
1241 dst_use_noref(&rt->dst, jiffies); in ip6_pol_route_lookup()
1244 rt = ip6_create_rt_rcu(&res); in ip6_pol_route_lookup()
1252 return rt; in ip6_pol_route_lookup()
1294 static int __ip6_ins_rt(struct fib6_info *rt, struct nl_info *info, in __ip6_ins_rt() argument
1300 table = rt->fib6_table; in __ip6_ins_rt()
1302 err = fib6_add(&table->tb6_root, rt, info, extack); in __ip6_ins_rt()
1308 int ip6_ins_rt(struct net *net, struct fib6_info *rt) in ip6_ins_rt() argument
1312 return __ip6_ins_rt(rt, &info, NULL); in ip6_ins_rt()
1321 struct rt6_info *rt; in ip6_rt_cache_alloc() local
1331 rt = ip6_dst_alloc(dev_net(dev), dev, 0); in ip6_rt_cache_alloc()
1332 if (!rt) { in ip6_rt_cache_alloc()
1337 ip6_rt_copy_init(rt, res); in ip6_rt_cache_alloc()
1338 rt->rt6i_flags |= RTF_CACHE; in ip6_rt_cache_alloc()
1339 rt->rt6i_dst.addr = *daddr; in ip6_rt_cache_alloc()
1340 rt->rt6i_dst.plen = 128; in ip6_rt_cache_alloc()
1345 rt->rt6i_flags |= RTF_ANYCAST; in ip6_rt_cache_alloc()
1347 if (rt->rt6i_src.plen && saddr) { in ip6_rt_cache_alloc()
1348 rt->rt6i_src.addr = *saddr; in ip6_rt_cache_alloc()
1349 rt->rt6i_src.plen = 128; in ip6_rt_cache_alloc()
1354 return rt; in ip6_rt_cache_alloc()
1508 /* Helper function to find the cached rt in the hash table
1541 /* Helper function to find the cached rt in the hash table
1782 /* Find cached rt in the hash table inside passed in rt
1804 * rt->rt6i_src is updated.) in rt6_find_cached_rt()
1827 /* Remove the passed in cached rt from the hash table that contains it */
1829 const struct rt6_info *rt) in fib6_nh_remove_exception() argument
1850 src_key = &rt->rt6i_src.addr; in fib6_nh_remove_exception()
1853 &rt->rt6i_dst.addr, in fib6_nh_remove_exception()
1867 struct rt6_info *rt; member
1876 err = fib6_nh_remove_exception(nh, arg->plen, arg->rt); in rt6_nh_remove_exception_rt()
1883 static int rt6_remove_exception_rt(struct rt6_info *rt) in rt6_remove_exception_rt() argument
1887 from = rcu_dereference(rt->from); in rt6_remove_exception_rt()
1888 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_remove_exception_rt()
1893 .rt = rt, in rt6_remove_exception_rt()
1906 from->fib6_src.plen, rt); in rt6_remove_exception_rt()
1909 /* Find rt6_ex which contains the passed in rt cache and
1913 const struct rt6_info *rt) in fib6_nh_update_exception() argument
1928 src_key = &rt->rt6i_src.addr; in fib6_nh_update_exception()
1930 rt6_ex = __rt6_find_exception_rcu(&bucket, &rt->rt6i_dst.addr, src_key); in fib6_nh_update_exception()
1958 static void rt6_update_exception_stamp_rt(struct rt6_info *rt) in rt6_update_exception_stamp_rt() argument
1965 from = rcu_dereference(rt->from); in rt6_update_exception_stamp_rt()
1966 if (!from || !(rt->rt6i_flags & RTF_CACHE)) in rt6_update_exception_stamp_rt()
1971 .dev = rt->dst.dev, in rt6_update_exception_stamp_rt()
1972 .gw = &rt->rt6i_gateway, in rt6_update_exception_stamp_rt()
1983 fib6_nh_update_exception(fib6_nh, from->fib6_src.plen, rt); in rt6_update_exception_stamp_rt()
1989 struct rt6_info *rt, int mtu) in rt6_mtu_change_route_allowed() argument
2001 if (dst_mtu(&rt->dst) >= mtu) in rt6_mtu_change_route_allowed()
2004 if (dst_mtu(&rt->dst) == idev->cnf.mtu6) in rt6_mtu_change_route_allowed()
2026 * route), the metrics of its rt->from have already in rt6_exceptions_update_pmtu()
2077 struct rt6_info *rt = rt6_ex->rt6i; in rt6_age_examine_exception() local
2085 if (!(rt->rt6i_flags & RTF_EXPIRES)) { in rt6_age_examine_exception()
2086 if (time_after_eq(now, rt->dst.lastuse + gc_args->timeout)) { in rt6_age_examine_exception()
2087 RT6_TRACE("aging clone %p\n", rt); in rt6_age_examine_exception()
2091 } else if (time_after(jiffies, rt->dst.expires)) { in rt6_age_examine_exception()
2092 RT6_TRACE("purging expired route %p\n", rt); in rt6_age_examine_exception()
2097 if (rt->rt6i_flags & RTF_GATEWAY) { in rt6_age_examine_exception()
2100 neigh = __ipv6_neigh_lookup_noref(rt->dst.dev, &rt->rt6i_gateway); in rt6_age_examine_exception()
2104 rt); in rt6_age_examine_exception()
2208 struct rt6_info *rt = NULL; in ip6_pol_route() local
2228 rt = rt6_find_cached_rt(&res, &fl6->daddr, &fl6->saddr); in ip6_pol_route()
2229 if (rt) { in ip6_pol_route()
2238 rt = ip6_rt_cache_alloc(&res, &fl6->daddr, NULL); in ip6_pol_route()
2240 if (rt) { in ip6_pol_route()
2246 rt6_uncached_list_add(rt); in ip6_pol_route()
2250 return rt; in ip6_pol_route()
2255 rt = rt6_get_pcpu_route(&res); in ip6_pol_route()
2257 if (!rt) in ip6_pol_route()
2258 rt = rt6_make_pcpu_route(net, &res); in ip6_pol_route()
2263 if (!rt) in ip6_pol_route()
2264 rt = net->ipv6.ip6_null_entry; in ip6_pol_route()
2266 ip6_hold_safe(net, &rt); in ip6_pol_route()
2269 return rt; in ip6_pol_route()
2657 struct rt6_info *rt, *ort = (struct rt6_info *) dst_orig; in ip6_blackhole_route() local
2661 rt = dst_alloc(&ip6_dst_blackhole_ops, loopback_dev, 1, in ip6_blackhole_route()
2663 if (rt) { in ip6_blackhole_route()
2664 rt6_info_init(rt); in ip6_blackhole_route()
2667 new = &rt->dst; in ip6_blackhole_route()
2674 rt->rt6i_idev = in6_dev_get(loopback_dev); in ip6_blackhole_route()
2675 rt->rt6i_gateway = ort->rt6i_gateway; in ip6_blackhole_route()
2676 rt->rt6i_flags = ort->rt6i_flags & ~RTF_PCPU; in ip6_blackhole_route()
2678 memcpy(&rt->rt6i_dst, &ort->rt6i_dst, sizeof(struct rt6key)); in ip6_blackhole_route()
2680 memcpy(&rt->rt6i_src, &ort->rt6i_src, sizeof(struct rt6key)); in ip6_blackhole_route()
2705 static struct dst_entry *rt6_check(struct rt6_info *rt, in rt6_check() argument
2715 if (rt6_check_expired(rt)) in rt6_check()
2718 return &rt->dst; in rt6_check()
2721 static struct dst_entry *rt6_dst_from_check(struct rt6_info *rt, in rt6_dst_from_check() argument
2725 if (!__rt6_check_expired(rt) && in rt6_dst_from_check()
2726 rt->dst.obsolete == DST_OBSOLETE_FORCE_CHK && in rt6_dst_from_check()
2728 return &rt->dst; in rt6_dst_from_check()
2738 struct rt6_info *rt; in ip6_dst_check() local
2740 rt = container_of(dst, struct rt6_info, dst); in ip6_dst_check()
2742 if (rt->sernum) in ip6_dst_check()
2743 return rt6_is_valid(rt) ? dst : NULL; in ip6_dst_check()
2752 from = rcu_dereference(rt->from); in ip6_dst_check()
2754 if (from && (rt->rt6i_flags & RTF_PCPU || in ip6_dst_check()
2755 unlikely(!list_empty(&rt->rt6i_uncached)))) in ip6_dst_check()
2756 dst_ret = rt6_dst_from_check(rt, from, cookie); in ip6_dst_check()
2758 dst_ret = rt6_check(rt, from, cookie); in ip6_dst_check()
2768 struct rt6_info *rt = (struct rt6_info *) dst; in ip6_negative_advice() local
2770 if (rt) { in ip6_negative_advice()
2771 if (rt->rt6i_flags & RTF_CACHE) { in ip6_negative_advice()
2773 if (rt6_check_expired(rt)) { in ip6_negative_advice()
2774 rt6_remove_exception_rt(rt); in ip6_negative_advice()
2788 struct rt6_info *rt; in ip6_link_failure() local
2792 rt = (struct rt6_info *) skb_dst(skb); in ip6_link_failure()
2793 if (rt) { in ip6_link_failure()
2795 if (rt->rt6i_flags & RTF_CACHE) { in ip6_link_failure()
2796 rt6_remove_exception_rt(rt); in ip6_link_failure()
2801 from = rcu_dereference(rt->from); in ip6_link_failure()
2804 if (fn && (rt->rt6i_flags & RTF_DEFAULT)) in ip6_link_failure()
2828 static void rt6_do_update_pmtu(struct rt6_info *rt, u32 mtu) in rt6_do_update_pmtu() argument
2830 struct net *net = dev_net(rt->dst.dev); in rt6_do_update_pmtu()
2832 dst_metric_set(&rt->dst, RTAX_MTU, mtu); in rt6_do_update_pmtu()
2833 rt->rt6i_flags |= RTF_MODIFIED; in rt6_do_update_pmtu()
2834 rt6_update_expires(rt, net->ipv6.sysctl.ip6_rt_mtu_expires); in rt6_do_update_pmtu()
2837 static bool rt6_cache_allowed_for_pmtu(const struct rt6_info *rt) in rt6_cache_allowed_for_pmtu() argument
2839 return !(rt->rt6i_flags & RTF_CACHE) && in rt6_cache_allowed_for_pmtu()
2840 (rt->rt6i_flags & RTF_PCPU || rcu_access_pointer(rt->from)); in rt6_cache_allowed_for_pmtu()
3056 struct fib6_info *rt; in __ip6_route_redirect() local
3079 res.f6i = rt; in __ip6_route_redirect()
3080 if (fib6_check_expired(rt)) in __ip6_route_redirect()
3082 if (rt->fib6_flags & RTF_REJECT) in __ip6_route_redirect()
3084 if (unlikely(rt->nh)) { in __ip6_route_redirect()
3085 if (nexthop_is_blackhole(rt->nh)) in __ip6_route_redirect()
3088 if (nexthop_for_each_fib6_nh(rt->nh, in __ip6_route_redirect()
3093 res.nh = rt->fib6_nh; in __ip6_route_redirect()
3100 if (!rt) in __ip6_route_redirect()
3101 rt = net->ipv6.fib6_null_entry; in __ip6_route_redirect()
3102 else if (rt->fib6_flags & RTF_REJECT) { in __ip6_route_redirect()
3107 if (rt == net->ipv6.fib6_null_entry) { in __ip6_route_redirect()
3113 res.f6i = rt; in __ip6_route_redirect()
3114 res.nh = rt->fib6_nh; in __ip6_route_redirect()
3234 struct rt6_info *rt; in ip6_mtu_from_fib6() local
3243 rt = rt6_find_cached_rt(res, daddr, saddr); in ip6_mtu_from_fib6()
3244 if (unlikely(rt)) { in ip6_mtu_from_fib6()
3245 mtu = dst_metric_raw(&rt->dst, RTAX_MTU); in ip6_mtu_from_fib6()
3264 struct rt6_info *rt; in icmp6_dst_alloc() local
3271 rt = ip6_dst_alloc(net, dev, 0); in icmp6_dst_alloc()
3272 if (unlikely(!rt)) { in icmp6_dst_alloc()
3278 rt->dst.input = ip6_input; in icmp6_dst_alloc()
3279 rt->dst.output = ip6_output; in icmp6_dst_alloc()
3280 rt->rt6i_gateway = fl6->daddr; in icmp6_dst_alloc()
3281 rt->rt6i_dst.addr = fl6->daddr; in icmp6_dst_alloc()
3282 rt->rt6i_dst.plen = 128; in icmp6_dst_alloc()
3283 rt->rt6i_idev = idev; in icmp6_dst_alloc()
3284 dst_metric_set(&rt->dst, RTAX_HOPLIMIT, 0); in icmp6_dst_alloc()
3289 rt6_uncached_list_add(rt); in icmp6_dst_alloc()
3292 dst = xfrm_lookup(net, &rt->dst, flowi6_to_flowi(fl6), NULL, 0); in icmp6_dst_alloc()
3688 struct fib6_info *rt = NULL; in ip6_route_info_create() local
3754 rt = fib6_info_alloc(gfp_flags, !nh); in ip6_route_info_create()
3755 if (!rt) in ip6_route_info_create()
3758 rt->fib6_metrics = ip_fib_metrics_init(net, cfg->fc_mx, cfg->fc_mx_len, in ip6_route_info_create()
3760 if (IS_ERR(rt->fib6_metrics)) { in ip6_route_info_create()
3761 err = PTR_ERR(rt->fib6_metrics); in ip6_route_info_create()
3763 rt->fib6_metrics = (struct dst_metrics *)&dst_default_metrics; in ip6_route_info_create()
3768 rt->dst_nocount = true; in ip6_route_info_create()
3771 fib6_set_expires(rt, jiffies + in ip6_route_info_create()
3774 fib6_clean_expires(rt); in ip6_route_info_create()
3778 rt->fib6_protocol = cfg->fc_protocol; in ip6_route_info_create()
3780 rt->fib6_table = table; in ip6_route_info_create()
3781 rt->fib6_metric = cfg->fc_metric; in ip6_route_info_create()
3782 rt->fib6_type = cfg->fc_type ? : RTN_UNICAST; in ip6_route_info_create()
3783 rt->fib6_flags = cfg->fc_flags & ~RTF_GATEWAY; in ip6_route_info_create()
3785 ipv6_addr_prefix(&rt->fib6_dst.addr, &cfg->fc_dst, cfg->fc_dst_len); in ip6_route_info_create()
3786 rt->fib6_dst.plen = cfg->fc_dst_len; in ip6_route_info_create()
3789 ipv6_addr_prefix(&rt->fib6_src.addr, &cfg->fc_src, cfg->fc_src_len); in ip6_route_info_create()
3790 rt->fib6_src.plen = cfg->fc_src_len; in ip6_route_info_create()
3793 if (rt->fib6_src.plen) { in ip6_route_info_create()
3801 rt->nh = nh; in ip6_route_info_create()
3802 fib6_nh = nexthop_fib6_nh(rt->nh); in ip6_route_info_create()
3804 err = fib6_nh_init(net, rt->fib6_nh, cfg, gfp_flags, extack); in ip6_route_info_create()
3808 fib6_nh = rt->fib6_nh; in ip6_route_info_create()
3814 if (fib6_is_reject(cfg->fc_flags, rt->fib6_nh->fib_nh_dev, in ip6_route_info_create()
3816 rt->fib6_flags = RTF_REJECT | RTF_NONEXTHOP; in ip6_route_info_create()
3827 rt->fib6_prefsrc.addr = cfg->fc_prefsrc; in ip6_route_info_create()
3828 rt->fib6_prefsrc.plen = 128; in ip6_route_info_create()
3830 rt->fib6_prefsrc.plen = 0; in ip6_route_info_create()
3832 return rt; in ip6_route_info_create()
3834 fib6_info_release(rt); in ip6_route_info_create()
3837 ip_fib_metrics_put(rt->fib6_metrics); in ip6_route_info_create()
3838 kfree(rt); in ip6_route_info_create()
3845 struct fib6_info *rt; in ip6_route_add() local
3848 rt = ip6_route_info_create(cfg, gfp_flags, extack); in ip6_route_add()
3849 if (IS_ERR(rt)) in ip6_route_add()
3850 return PTR_ERR(rt); in ip6_route_add()
3852 err = __ip6_ins_rt(rt, &cfg->fc_nlinfo, extack); in ip6_route_add()
3853 fib6_info_release(rt); in ip6_route_add()
3858 static int __ip6_del_rt(struct fib6_info *rt, struct nl_info *info) in __ip6_del_rt() argument
3864 if (rt == net->ipv6.fib6_null_entry) { in __ip6_del_rt()
3869 table = rt->fib6_table; in __ip6_del_rt()
3871 err = fib6_del(rt, info); in __ip6_del_rt()
3875 fib6_info_release(rt); in __ip6_del_rt()
3879 int ip6_del_rt(struct net *net, struct fib6_info *rt, bool skip_notify) in ip6_del_rt() argument
3886 return __ip6_del_rt(rt, &info); in ip6_del_rt()
3889 static int __ip6_del_rt_siblings(struct fib6_info *rt, struct fib6_config *cfg) in __ip6_del_rt_siblings() argument
3897 if (rt == net->ipv6.fib6_null_entry) in __ip6_del_rt_siblings()
3899 table = rt->fib6_table; in __ip6_del_rt_siblings()
3902 if (rt->fib6_nsiblings && cfg->fc_delete_all_nh) { in __ip6_del_rt_siblings()
3907 skb = nlmsg_new(rt6_nlmsg_size(rt), gfp_any()); in __ip6_del_rt_siblings()
3911 if (rt6_fill_node(net, skb, rt, NULL, in __ip6_del_rt_siblings()
3920 /* 'rt' points to the first sibling route. If it is not the in __ip6_del_rt_siblings()
3926 fn = rcu_dereference_protected(rt->fib6_node, in __ip6_del_rt_siblings()
3928 if (rcu_access_pointer(fn->leaf) == rt) { in __ip6_del_rt_siblings()
3931 last_sibling = list_last_entry(&rt->fib6_siblings, in __ip6_del_rt_siblings()
3943 rt, rt->fib6_nsiblings, in __ip6_del_rt_siblings()
3947 &rt->fib6_siblings, in __ip6_del_rt_siblings()
3955 err = fib6_del(rt, info); in __ip6_del_rt_siblings()
3959 fib6_info_release(rt); in __ip6_del_rt_siblings()
3968 static int __ip6_del_cached_rt(struct rt6_info *rt, struct fib6_config *cfg) in __ip6_del_cached_rt() argument
3972 if (cfg->fc_ifindex && rt->dst.dev->ifindex != cfg->fc_ifindex) in __ip6_del_cached_rt()
3976 !ipv6_addr_equal(&cfg->fc_gateway, &rt->rt6i_gateway)) in __ip6_del_cached_rt()
3979 rc = rt6_remove_exception_rt(rt); in __ip6_del_cached_rt()
3984 static int ip6_del_cached_rt(struct fib6_config *cfg, struct fib6_info *rt, in ip6_del_cached_rt() argument
3988 .f6i = rt, in ip6_del_cached_rt()
4028 struct fib6_info *rt; in ip6_route_del() local
4049 if (rt->nh && cfg->fc_nh_id && in ip6_route_del()
4050 rt->nh->id != cfg->fc_nh_id) in ip6_route_del()
4056 if (rt->nh) { in ip6_route_del()
4057 rc = ip6_del_cached_rt_nh(cfg, rt); in ip6_route_del()
4061 nh = rt->fib6_nh; in ip6_route_del()
4062 rc = ip6_del_cached_rt(cfg, rt, nh); in ip6_route_del()
4071 if (cfg->fc_metric && cfg->fc_metric != rt->fib6_metric) in ip6_route_del()
4074 cfg->fc_protocol != rt->fib6_protocol) in ip6_route_del()
4077 if (rt->nh) { in ip6_route_del()
4078 if (!fib6_info_hold_safe(rt)) in ip6_route_del()
4082 return __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
4087 nh = rt->fib6_nh; in ip6_route_del()
4095 if (!fib6_info_hold_safe(rt)) in ip6_route_del()
4101 return __ip6_del_rt(rt, &cfg->fc_nlinfo); in ip6_route_del()
4103 return __ip6_del_rt_siblings(rt, cfg); in ip6_route_del()
4114 struct rt6_info *rt, *nrt = NULL; in rt6_do_redirect() local
4173 rt = (struct rt6_info *) dst; in rt6_do_redirect()
4174 if (rt->rt6i_flags & RTF_REJECT) { in rt6_do_redirect()
4183 dst_confirm_neigh(&rt->dst, &ipv6_hdr(skb)->saddr); in rt6_do_redirect()
4201 res.f6i = rcu_dereference(rt->from); in rt6_do_redirect()
4208 .gw = &rt->rt6i_gateway, in rt6_do_redirect()
4242 netevent.old = &rt->dst; in rt6_do_redirect()
4262 struct fib6_info *rt = NULL; in rt6_get_route_info() local
4276 if (rt->nh) in rt6_get_route_info()
4278 if (rt->fib6_nh->fib_nh_dev->ifindex != ifindex) in rt6_get_route_info()
4280 if (!(rt->fib6_flags & RTF_ROUTEINFO) || in rt6_get_route_info()
4281 !rt->fib6_nh->fib_nh_gw_family) in rt6_get_route_info()
4283 if (!ipv6_addr_equal(&rt->fib6_nh->fib_nh_gw6, gwaddr)) in rt6_get_route_info()
4285 if (!fib6_info_hold_safe(rt)) in rt6_get_route_info()
4291 return rt; in rt6_get_route_info()
4332 struct fib6_info *rt; in rt6_get_dflt_router() local
4344 if (rt->nh) in rt6_get_dflt_router()
4347 nh = rt->fib6_nh; in rt6_get_dflt_router()
4349 ((rt->fib6_flags & (RTF_ADDRCONF | RTF_DEFAULT)) == (RTF_ADDRCONF | RTF_DEFAULT)) && in rt6_get_dflt_router()
4353 if (rt && !fib6_info_hold_safe(rt)) in rt6_get_dflt_router()
4354 rt = NULL; in rt6_get_dflt_router()
4356 return rt; in rt6_get_dflt_router()
4394 struct fib6_info *rt; in __rt6_purge_dflt_routers() local
4399 struct net_device *dev = fib6_info_nh_dev(rt); in __rt6_purge_dflt_routers()
4402 if (rt->fib6_flags & (RTF_DEFAULT | RTF_ADDRCONF) && in __rt6_purge_dflt_routers()
4404 fib6_info_hold_safe(rt)) { in __rt6_purge_dflt_routers()
4406 ip6_del_rt(net, rt, false); in __rt6_purge_dflt_routers()
4585 static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg) in fib6_remove_prefsrc() argument
4591 if (!rt->nh && in fib6_remove_prefsrc()
4592 ((void *)rt->fib6_nh->fib_nh_dev == dev || !dev) && in fib6_remove_prefsrc()
4593 rt != net->ipv6.fib6_null_entry && in fib6_remove_prefsrc()
4594 ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr)) { in fib6_remove_prefsrc()
4597 rt->fib6_prefsrc.plen = 0; in fib6_remove_prefsrc()
4617 static int fib6_clean_tohost(struct fib6_info *rt, void *arg) in fib6_clean_tohost() argument
4623 if (rt->nh) in fib6_clean_tohost()
4626 nh = rt->fib6_nh; in fib6_clean_tohost()
4627 if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) && in fib6_clean_tohost()
4653 static struct fib6_info *rt6_multipath_first_sibling(const struct fib6_info *rt) in rt6_multipath_first_sibling() argument
4658 fn = rcu_dereference_protected(rt->fib6_node, in rt6_multipath_first_sibling()
4659 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4661 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4663 if (iter->fib6_metric == rt->fib6_metric && in rt6_multipath_first_sibling()
4667 lockdep_is_held(&rt->fib6_table->tb6_lock)); in rt6_multipath_first_sibling()
4674 static bool rt6_is_dead(const struct fib6_info *rt) in rt6_is_dead() argument
4676 if (rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD || in rt6_is_dead()
4677 (rt->fib6_nh->fib_nh_flags & RTNH_F_LINKDOWN && in rt6_is_dead()
4678 ip6_ignore_linkdown(rt->fib6_nh->fib_nh_dev))) in rt6_is_dead()
4684 static int rt6_multipath_total_weight(const struct fib6_info *rt) in rt6_multipath_total_weight() argument
4689 if (!rt6_is_dead(rt)) in rt6_multipath_total_weight()
4690 total += rt->fib6_nh->fib_nh_weight; in rt6_multipath_total_weight()
4692 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) { in rt6_multipath_total_weight()
4700 static void rt6_upper_bound_set(struct fib6_info *rt, int *weight, int total) in rt6_upper_bound_set() argument
4704 if (!rt6_is_dead(rt)) { in rt6_upper_bound_set()
4705 *weight += rt->fib6_nh->fib_nh_weight; in rt6_upper_bound_set()
4709 atomic_set(&rt->fib6_nh->fib_nh_upper_bound, upper_bound); in rt6_upper_bound_set()
4712 static void rt6_multipath_upper_bound_set(struct fib6_info *rt, int total) in rt6_multipath_upper_bound_set() argument
4717 rt6_upper_bound_set(rt, &weight, total); in rt6_multipath_upper_bound_set()
4719 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_upper_bound_set()
4723 void rt6_multipath_rebalance(struct fib6_info *rt) in rt6_multipath_rebalance() argument
4732 if (!rt->fib6_nsiblings || rt->should_flush) in rt6_multipath_rebalance()
4739 first = rt6_multipath_first_sibling(rt); in rt6_multipath_rebalance()
4747 static int fib6_ifup(struct fib6_info *rt, void *p_arg) in fib6_ifup() argument
4752 if (rt != net->ipv6.fib6_null_entry && !rt->nh && in fib6_ifup()
4753 rt->fib6_nh->fib_nh_dev == arg->dev) { in fib6_ifup()
4754 rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags; in fib6_ifup()
4755 fib6_update_sernum_upto_root(net, rt); in fib6_ifup()
4756 rt6_multipath_rebalance(rt); in fib6_ifup()
4778 static bool rt6_multipath_uses_dev(const struct fib6_info *rt, in rt6_multipath_uses_dev() argument
4783 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_uses_dev()
4785 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_uses_dev()
4792 static void rt6_multipath_flush(struct fib6_info *rt) in rt6_multipath_flush() argument
4796 rt->should_flush = 1; in rt6_multipath_flush()
4797 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_flush()
4801 static unsigned int rt6_multipath_dead_count(const struct fib6_info *rt, in rt6_multipath_dead_count() argument
4807 if (rt->fib6_nh->fib_nh_dev == down_dev || in rt6_multipath_dead_count()
4808 rt->fib6_nh->fib_nh_flags & RTNH_F_DEAD) in rt6_multipath_dead_count()
4810 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_dead_count()
4818 static void rt6_multipath_nh_flags_set(struct fib6_info *rt, in rt6_multipath_nh_flags_set() argument
4824 if (rt->fib6_nh->fib_nh_dev == dev) in rt6_multipath_nh_flags_set()
4825 rt->fib6_nh->fib_nh_flags |= nh_flags; in rt6_multipath_nh_flags_set()
4826 list_for_each_entry(iter, &rt->fib6_siblings, fib6_siblings) in rt6_multipath_nh_flags_set()
4831 /* called with write lock held for table with rt */
4832 static int fib6_ifdown(struct fib6_info *rt, void *p_arg) in fib6_ifdown() argument
4838 if (rt == net->ipv6.fib6_null_entry || rt->nh) in fib6_ifdown()
4843 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4845 if (rt->should_flush) in fib6_ifdown()
4847 if (!rt->fib6_nsiblings) in fib6_ifdown()
4848 return rt->fib6_nh->fib_nh_dev == dev ? -1 : 0; in fib6_ifdown()
4849 if (rt6_multipath_uses_dev(rt, dev)) { in fib6_ifdown()
4852 count = rt6_multipath_dead_count(rt, dev); in fib6_ifdown()
4853 if (rt->fib6_nsiblings + 1 == count) { in fib6_ifdown()
4854 rt6_multipath_flush(rt); in fib6_ifdown()
4857 rt6_multipath_nh_flags_set(rt, dev, RTNH_F_DEAD | in fib6_ifdown()
4859 fib6_update_sernum(net, rt); in fib6_ifdown()
4860 rt6_multipath_rebalance(rt); in fib6_ifdown()
4864 if (rt->fib6_nh->fib_nh_dev != dev || in fib6_ifdown()
4865 rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST)) in fib6_ifdown()
4867 rt->fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib6_ifdown()
4868 rt6_multipath_rebalance(rt); in fib6_ifdown()
5139 struct fib6_info *rt, in ip6_route_info_append() argument
5147 if (rt6_duplicate_nexthop(nh->fib6_info, rt)) in ip6_route_info_append()
5154 nh->fib6_info = rt; in ip6_route_info_append()
5161 static void ip6_route_mpath_notify(struct fib6_info *rt, in ip6_route_mpath_notify() argument
5166 /* if this is an APPEND route, then rt points to the first route in ip6_route_mpath_notify()
5173 rt = list_first_entry(&rt_last->fib6_siblings, in ip6_route_mpath_notify()
5178 if (rt) in ip6_route_mpath_notify()
5179 inet6_rt_notify(RTM_NEWROUTE, rt, info, nlflags); in ip6_route_mpath_notify()
5182 static bool ip6_route_mpath_should_notify(const struct fib6_info *rt) in ip6_route_mpath_should_notify() argument
5184 bool rt_can_ecmp = rt6_qualify_for_ecmp(rt); in ip6_route_mpath_should_notify()
5190 fn = rcu_dereference(rt->fib6_node); in ip6_route_mpath_should_notify()
5198 if (rt == leaf || in ip6_route_mpath_should_notify()
5199 (rt_can_ecmp && rt->fib6_metric == leaf->fib6_metric && in ip6_route_mpath_should_notify()
5215 struct fib6_info *rt; in ip6_route_multipath_add() local
5258 rt = ip6_route_info_create(&r_cfg, GFP_KERNEL, extack); in ip6_route_multipath_add()
5259 if (IS_ERR(rt)) { in ip6_route_multipath_add()
5260 err = PTR_ERR(rt); in ip6_route_multipath_add()
5261 rt = NULL; in ip6_route_multipath_add()
5264 if (!rt6_qualify_for_ecmp(rt)) { in ip6_route_multipath_add()
5268 fib6_info_release(rt); in ip6_route_multipath_add()
5272 rt->fib6_nh->fib_nh_weight = rtnh->rtnh_hops + 1; in ip6_route_multipath_add()
5275 rt, &r_cfg); in ip6_route_multipath_add()
5277 fib6_info_release(rt); in ip6_route_multipath_add()
5563 struct fib6_info *rt, struct dst_entry *dst, in rt6_fill_node() argument
5585 rt6_dst = &rt->fib6_dst; in rt6_fill_node()
5586 rt6_src = &rt->fib6_src; in rt6_fill_node()
5587 rt6_flags = rt->fib6_flags; in rt6_fill_node()
5595 if (rt->fib6_table) in rt6_fill_node()
5596 table = rt->fib6_table->tb6_id; in rt6_fill_node()
5603 rtm->rtm_type = rt->fib6_type; in rt6_fill_node()
5606 rtm->rtm_protocol = rt->fib6_protocol; in rt6_fill_node()
5642 if (ip6_route_get_saddr(net, rt, dest, 0, &saddr_buf) == 0 && in rt6_fill_node()
5647 if (rt->fib6_prefsrc.plen) { in rt6_fill_node()
5649 saddr_buf = rt->fib6_prefsrc.addr; in rt6_fill_node()
5654 pmetrics = dst ? dst_metrics_ptr(dst) : rt->fib6_metrics->metrics; in rt6_fill_node()
5658 if (nla_put_u32(skb, RTA_PRIORITY, rt->fib6_metric)) in rt6_fill_node()
5675 } else if (rt->fib6_nsiblings) { in rt6_fill_node()
5683 if (fib_add_nexthop(skb, &rt->fib6_nh->nh_common, in rt6_fill_node()
5684 rt->fib6_nh->fib_nh_weight, AF_INET6, in rt6_fill_node()
5689 &rt->fib6_siblings, fib6_siblings) { in rt6_fill_node()
5697 } else if (rt->nh) { in rt6_fill_node()
5698 if (nla_put_u32(skb, RTA_NH_ID, rt->nh->id)) in rt6_fill_node()
5701 if (nexthop_is_blackhole(rt->nh)) in rt6_fill_node()
5705 rt6_fill_node_nexthop(skb, rt->nh, &nh_flags) < 0) in rt6_fill_node()
5710 if (fib_nexthop_info(skb, &rt->fib6_nh->nh_common, AF_INET6, in rt6_fill_node()
5718 expires = dst ? dst->expires : rt->expires; in rt6_fill_node()
5723 if (rt->offload) in rt6_fill_node()
5725 if (rt->trap) in rt6_fill_node()
5727 if (rt->offload_failed) in rt6_fill_node()
5785 struct fib6_info *rt; member
5826 err = rt6_fill_node(dump->net, dump->skb, w->rt, in rt6_nh_dump_exceptions()
5843 int rt6_dump_route(struct fib6_info *rt, void *p_arg, unsigned int skip) in rt6_dump_route() argument
5851 if (rt == net->ipv6.fib6_null_entry) in rt6_dump_route()
5855 !(rt->fib6_flags & RTF_PREFIX_RT)) { in rt6_dump_route()
5860 ((filter->rt_type && rt->fib6_type != filter->rt_type) || in rt6_dump_route()
5861 (filter->dev && !fib6_info_uses_dev(rt, filter->dev)) || in rt6_dump_route()
5862 (filter->protocol && rt->fib6_protocol != filter->protocol))) { in rt6_dump_route()
5875 if (rt6_fill_node(net, arg->skb, rt, NULL, NULL, NULL, in rt6_dump_route()
5887 .rt = rt, in rt6_dump_route()
5894 if (rt->nh) { in rt6_dump_route()
5895 err = nexthop_for_each_fib6_nh(rt->nh, in rt6_dump_route()
5899 err = rt6_nh_dump_exceptions(rt->fib6_nh, &w); in rt6_dump_route()
5985 struct rt6_info *rt; in inet6_rtm_getroute() local
6071 rt = container_of(dst, struct rt6_info, dst); in inet6_rtm_getroute()
6072 if (rt->dst.error) { in inet6_rtm_getroute()
6073 err = rt->dst.error; in inet6_rtm_getroute()
6074 ip6_rt_put(rt); in inet6_rtm_getroute()
6078 if (rt == net->ipv6.ip6_null_entry) { in inet6_rtm_getroute()
6079 err = rt->dst.error; in inet6_rtm_getroute()
6080 ip6_rt_put(rt); in inet6_rtm_getroute()
6086 ip6_rt_put(rt); in inet6_rtm_getroute()
6091 skb_dst_set(skb, &rt->dst); in inet6_rtm_getroute()
6094 from = rcu_dereference(rt->from); in inet6_rtm_getroute()
6121 void inet6_rt_notify(int event, struct fib6_info *rt, struct nl_info *info, in inet6_rt_notify() argument
6132 skb = nlmsg_new(rt6_nlmsg_size(rt), gfp_any()); in inet6_rt_notify()
6136 err = rt6_fill_node(net, skb, rt, NULL, NULL, NULL, 0, in inet6_rt_notify()
6152 void fib6_rt_update(struct net *net, struct fib6_info *rt, in fib6_rt_update() argument
6159 skb = nlmsg_new(rt6_nlmsg_size(rt), gfp_any()); in fib6_rt_update()
6163 err = rt6_fill_node(net, skb, rt, NULL, NULL, NULL, 0, in fib6_rt_update()
6591 DEFINE_BPF_ITER_FUNC(ipv6_route, struct bpf_iter_meta *meta, struct fib6_info *rt)
6607 { offsetof(struct bpf_iter__ipv6_route, rt),