Lines Matching refs:nh
70 int nhsel; const struct fib_nh *nh; \
71 for (nhsel = 0, nh = (fi)->fib_nh; \
73 nh++, nhsel++)
86 int nhsel; const struct fib_nh *nh = (fi)->fib_nh; \
237 if (fi->nh) { in free_fib_info_rcu()
238 nexthop_put(fi->nh); in free_fib_info_rcu()
272 if (fi->nh) { in fib_release_info()
292 if (fi->nh || ofi->nh) in nh_comp()
293 return nexthop_cmp(fi->nh, ofi->nh) ? 0 : -1; in nh_comp()
301 if (nh->fib_nh_oif != onh->fib_nh_oif || in nh_comp()
302 nh->fib_nh_gw_family != onh->fib_nh_gw_family || in nh_comp()
303 nh->fib_nh_scope != onh->fib_nh_scope || in nh_comp()
305 nh->fib_nh_weight != onh->fib_nh_weight || in nh_comp()
308 nh->nh_tclassid != onh->nh_tclassid || in nh_comp()
310 lwtunnel_cmp_encap(nh->fib_nh_lws, onh->fib_nh_lws) || in nh_comp()
311 ((nh->fib_nh_flags ^ onh->fib_nh_flags) & ~RTNH_COMPARE_MASK)) in nh_comp()
314 if (nh->fib_nh_gw_family == AF_INET && in nh_comp()
315 nh->fib_nh_gw4 != onh->fib_nh_gw4) in nh_comp()
318 if (nh->fib_nh_gw_family == AF_INET6 && in nh_comp()
319 ipv6_addr_cmp(&nh->fib_nh_gw6, &onh->fib_nh_gw6)) in nh_comp()
365 if (fi->nh) { in fib_info_hashfn()
366 val ^= fib_devindex_hashfn(fi->nh->id); in fib_info_hashfn()
369 val ^= fib_devindex_hashfn(nh->fib_nh_oif); in fib_info_hashfn()
394 if (!fi->nh || fi->nh->id != cfg->fc_nh_id) in fib_find_info_nh()
445 struct fib_nh *nh; in ip_fib_check_default() local
451 hlist_for_each_entry(nh, head, nh_hash) { in ip_fib_check_default()
452 if (nh->fib_nh_dev == dev && in ip_fib_check_default()
453 nh->fib_nh_gw4 == gw && in ip_fib_check_default()
454 !(nh->fib_nh_flags & RTNH_F_DEAD)) { in ip_fib_check_default()
478 if (fi->nh) in fib_nlmsg_size()
622 int fib_nh_init(struct net *net, struct fib_nh *nh, in fib_nh_init() argument
628 nh->fib_nh_family = AF_INET; in fib_nh_init()
630 err = fib_nh_common_init(net, &nh->nh_common, cfg->fc_encap, in fib_nh_init()
635 nh->fib_nh_oif = cfg->fc_oif; in fib_nh_init()
636 nh->fib_nh_gw_family = cfg->fc_gw_family; in fib_nh_init()
638 nh->fib_nh_gw4 = cfg->fc_gw4; in fib_nh_init()
640 nh->fib_nh_gw6 = cfg->fc_gw6; in fib_nh_init()
642 nh->fib_nh_flags = cfg->fc_flags; in fib_nh_init()
645 nh->nh_tclassid = cfg->fc_flow; in fib_nh_init()
646 if (nh->nh_tclassid) in fib_nh_init()
650 nh->fib_nh_weight = nh_weight; in fib_nh_init()
697 struct fib_nh *nh; in fib_get_nhs() local
772 nh = fib_info_nh(fi, 0); in fib_get_nhs()
773 if (cfg->fc_oif && nh->fib_nh_oif != cfg->fc_oif) { in fib_get_nhs()
779 if (cfg->fc_gw_family != nh->fib_nh_gw_family || in fib_get_nhs()
781 nh->fib_nh_gw4 != cfg->fc_gw4) || in fib_get_nhs()
783 ipv6_addr_cmp(&nh->fib_nh_gw6, &cfg->fc_gw6))) { in fib_get_nhs()
790 if (cfg->fc_flow && nh->nh_tclassid != cfg->fc_flow) { in fib_get_nhs()
812 if (nh->fib_nh_flags & RTNH_F_DEAD) in fib_rebalance()
815 if (ip_ignore_linkdown(nh->fib_nh_dev) && in fib_rebalance()
816 nh->fib_nh_flags & RTNH_F_LINKDOWN) in fib_rebalance()
819 total += nh->fib_nh_weight; in fib_rebalance()
857 const struct fib_nh *nh, in fib_encap_match() argument
870 result = lwtunnel_cmp_encap(lwtstate, nh->fib_nh_lws); in fib_encap_match()
889 if (fi->nh && cfg->fc_nh_id == fi->nh->id) in fib_nh_match()
894 if (fi->nh) { in fib_nh_match()
901 struct fib_nh *nh; in fib_nh_match() local
903 nh = fib_info_nh(fi, 0); in fib_nh_match()
906 cfg->fc_encap, nh, cfg, extack)) in fib_nh_match()
911 cfg->fc_flow != nh->nh_tclassid) in fib_nh_match()
914 if ((cfg->fc_oif && cfg->fc_oif != nh->fib_nh_oif) || in fib_nh_match()
916 cfg->fc_gw_family != nh->fib_nh_gw_family)) in fib_nh_match()
920 cfg->fc_gw4 != nh->fib_nh_gw4) in fib_nh_match()
924 ipv6_addr_cmp(&cfg->fc_gw6, &nh->fib_nh_gw6)) in fib_nh_match()
943 if (rtnh->rtnh_ifindex && rtnh->rtnh_ifindex != nh->fib_nh_oif) in fib_nh_match()
966 if (nh->fib_nh_gw_family != AF_INET || in fib_nh_match()
967 gw != nh->fib_nh_gw4) in fib_nh_match()
976 switch (nh->fib_nh_gw_family) { in fib_nh_match()
979 cfg2.fc_gw4 != nh->fib_nh_gw4) in fib_nh_match()
985 &nh->fib_nh_gw6)) in fib_nh_match()
998 if (nla_get_u32(nla) != nh->nh_tclassid) in fib_nh_match()
1051 static int fib_check_nh_v6_gw(struct net *net, struct fib_nh *nh, in fib_check_nh_v6_gw() argument
1056 .fc_flags = nh->fib_nh_flags | RTF_GATEWAY, in fib_check_nh_v6_gw()
1057 .fc_ifindex = nh->fib_nh_oif, in fib_check_nh_v6_gw()
1058 .fc_gateway = nh->fib_nh_gw6, in fib_check_nh_v6_gw()
1065 nh->fib_nh_dev = fib6_nh.fib_nh_dev; in fib_check_nh_v6_gw()
1066 netdev_hold(nh->fib_nh_dev, &nh->fib_nh_dev_tracker, in fib_check_nh_v6_gw()
1068 nh->fib_nh_oif = nh->fib_nh_dev->ifindex; in fib_check_nh_v6_gw()
1069 nh->fib_nh_scope = RT_SCOPE_LINK; in fib_check_nh_v6_gw()
1120 static int fib_check_nh_v4_gw(struct net *net, struct fib_nh *nh, u32 table, in fib_check_nh_v4_gw() argument
1127 if (nh->fib_nh_flags & RTNH_F_ONLINK) { in fib_check_nh_v4_gw()
1134 dev = __dev_get_by_index(net, nh->fib_nh_oif); in fib_check_nh_v4_gw()
1143 addr_type = inet_addr_type_dev_table(net, dev, nh->fib_nh_gw4); in fib_check_nh_v4_gw()
1149 nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib_check_nh_v4_gw()
1150 nh->fib_nh_dev = dev; in fib_check_nh_v4_gw()
1151 netdev_hold(dev, &nh->fib_nh_dev_tracker, GFP_ATOMIC); in fib_check_nh_v4_gw()
1152 nh->fib_nh_scope = RT_SCOPE_LINK; in fib_check_nh_v4_gw()
1159 .daddr = nh->fib_nh_gw4, in fib_check_nh_v4_gw()
1161 .flowi4_oif = nh->fib_nh_oif, in fib_check_nh_v4_gw()
1197 nh->fib_nh_scope = res.scope; in fib_check_nh_v4_gw()
1198 nh->fib_nh_oif = FIB_RES_OIF(res); in fib_check_nh_v4_gw()
1199 nh->fib_nh_dev = dev = FIB_RES_DEV(res); in fib_check_nh_v4_gw()
1205 netdev_hold(dev, &nh->fib_nh_dev_tracker, GFP_ATOMIC); in fib_check_nh_v4_gw()
1207 nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib_check_nh_v4_gw()
1214 static int fib_check_nh_nongw(struct net *net, struct fib_nh *nh, in fib_check_nh_nongw() argument
1220 if (nh->fib_nh_flags & (RTNH_F_PERVASIVE | RTNH_F_ONLINK)) { in fib_check_nh_nongw()
1229 in_dev = inetdev_by_index(net, nh->fib_nh_oif); in fib_check_nh_nongw()
1238 nh->fib_nh_dev = in_dev->dev; in fib_check_nh_nongw()
1239 netdev_hold(nh->fib_nh_dev, &nh->fib_nh_dev_tracker, GFP_ATOMIC); in fib_check_nh_nongw()
1240 nh->fib_nh_scope = RT_SCOPE_HOST; in fib_check_nh_nongw()
1241 if (!netif_carrier_ok(nh->fib_nh_dev)) in fib_check_nh_nongw()
1242 nh->fib_nh_flags |= RTNH_F_LINKDOWN; in fib_check_nh_nongw()
1249 int fib_check_nh(struct net *net, struct fib_nh *nh, u32 table, u8 scope, in fib_check_nh() argument
1254 if (nh->fib_nh_gw_family == AF_INET) in fib_check_nh()
1255 err = fib_check_nh_v4_gw(net, nh, table, scope, extack); in fib_check_nh()
1256 else if (nh->fib_nh_gw_family == AF_INET6) in fib_check_nh()
1257 err = fib_check_nh_v6_gw(net, nh, table, extack); in fib_check_nh()
1259 err = fib_check_nh_nongw(net, nh, extack); in fib_check_nh()
1327 struct fib_nh *nh; in fib_info_update_nhc_saddr() local
1333 nh = container_of(nhc, struct fib_nh, nh_common); in fib_info_update_nhc_saddr()
1334 saddr = inet_select_addr(nh->fib_nh_dev, nh->fib_nh_gw4, scope); in fib_info_update_nhc_saddr()
1336 WRITE_ONCE(nh->nh_saddr, saddr); in fib_info_update_nhc_saddr()
1337 WRITE_ONCE(nh->nh_saddr_genid, atomic_read(&net->ipv4.dev_addr_genid)); in fib_info_update_nhc_saddr()
1350 struct fib_nh *nh; in fib_result_prefsrc() local
1352 nh = container_of(nhc, struct fib_nh, nh_common); in fib_result_prefsrc()
1353 if (READ_ONCE(nh->nh_saddr_genid) == in fib_result_prefsrc()
1355 return READ_ONCE(nh->nh_saddr); in fib_result_prefsrc()
1390 struct nexthop *nh = NULL; in fib_create_info() local
1419 nh = nexthop_find_by_id(net, cfg->fc_nh_id); in fib_create_info()
1420 if (!nh) { in fib_create_info()
1480 if (nh) { in fib_create_info()
1481 if (!nexthop_get(nh)) { in fib_create_info()
1486 fi->nh = nh; in fib_create_info()
1529 if (fi->nh) { in fib_create_info()
1530 err = fib_check_nexthop(fi->nh, cfg->fc_scope, extack); in fib_create_info()
1534 struct fib_nh *nh = fi->fib_nh; in fib_create_info() local
1542 if (nh->fib_nh_gw_family) { in fib_create_info()
1547 nh->fib_nh_scope = RT_SCOPE_NOWHERE; in fib_create_info()
1548 nh->fib_nh_dev = dev_get_by_index(net, nh->fib_nh_oif); in fib_create_info()
1550 if (!nh->fib_nh_dev) in fib_create_info()
1552 netdev_tracker_alloc(nh->fib_nh_dev, &nh->fib_nh_dev_tracker, in fib_create_info()
1575 if (!fi->nh) { in fib_create_info()
1608 if (fi->nh) { in fib_create_info()
1609 list_add(&fi->nh_list, &nh->fi_list); in fib_create_info()
1749 if (unlikely(fi->nh)) { in fib_add_multipath()
1750 if (nexthop_mpath_fill_node(skb, fi->nh, AF_INET) < 0) in fib_add_multipath()
1758 nh_tclassid = nh->nh_tclassid; in fib_add_multipath()
1760 if (fib_add_nexthop(skb, &nh->nh_common, nh->fib_nh_weight, in fib_add_multipath()
1822 if (fi->nh) { in fib_dump_info()
1823 if (nla_put_u32(skb, RTA_NH_ID, fi->nh->id)) in fib_dump_info()
1825 if (nexthop_is_blackhole(fi->nh)) in fib_dump_info()
1841 struct fib_nh *nh; in fib_dump_info() local
1843 nh = container_of(nhc, struct fib_nh, nh_common); in fib_dump_info()
1844 if (nh->nh_tclassid && in fib_dump_info()
1845 nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid)) in fib_dump_info()
1901 static int call_fib_nh_notifiers(struct fib_nh *nh, in call_fib_nh_notifiers() argument
1904 bool ignore_link_down = ip_ignore_linkdown(nh->fib_nh_dev); in call_fib_nh_notifiers()
1906 .fib_nh = nh, in call_fib_nh_notifiers()
1911 if (nh->fib_nh_flags & RTNH_F_DEAD) in call_fib_nh_notifiers()
1913 if (ignore_link_down && nh->fib_nh_flags & RTNH_F_LINKDOWN) in call_fib_nh_notifiers()
1915 return call_fib4_notifiers(dev_net(nh->fib_nh_dev), event_type, in call_fib_nh_notifiers()
1918 if ((ignore_link_down && nh->fib_nh_flags & RTNH_F_LINKDOWN) || in call_fib_nh_notifiers()
1919 (nh->fib_nh_flags & RTNH_F_DEAD)) in call_fib_nh_notifiers()
1920 return call_fib4_notifiers(dev_net(nh->fib_nh_dev), in call_fib_nh_notifiers()
1971 struct fib_nh *nh; in fib_sync_mtu() local
1973 hlist_for_each_entry(nh, head, nh_hash) { in fib_sync_mtu()
1974 if (nh->fib_nh_dev == dev) in fib_sync_mtu()
1975 fib_nhc_update_mtu(&nh->nh_common, dev->mtu, orig_mtu); in fib_sync_mtu()
1992 struct fib_nh *nh; in fib_sync_down_dev() local
1998 hlist_for_each_entry(nh, head, nh_hash) { in fib_sync_down_dev()
1999 struct fib_info *fi = nh->nh_parent; in fib_sync_down_dev()
2003 if (nh->fib_nh_dev != dev || fi == prev_fi) in fib_sync_down_dev()
2140 struct fib_nh *nh; in fib_sync_up() local
2157 hlist_for_each_entry(nh, head, nh_hash) { in fib_sync_up()
2158 struct fib_info *fi = nh->nh_parent; in fib_sync_up()
2162 if (nh->fib_nh_dev != dev || fi == prev_fi) in fib_sync_up()
2195 static bool fib_good_nh(const struct fib_nh *nh) in fib_good_nh() argument
2199 if (nh->fib_nh_scope == RT_SCOPE_LINK) { in fib_good_nh()
2204 if (likely(nh->fib_nh_gw_family == AF_INET)) in fib_good_nh()
2205 n = __ipv4_neigh_lookup_noref(nh->fib_nh_dev, in fib_good_nh()
2206 (__force u32)nh->fib_nh_gw4); in fib_good_nh()
2207 else if (nh->fib_nh_gw_family == AF_INET6) in fib_good_nh()
2208 n = __ipv6_neigh_lookup_noref_stub(nh->fib_nh_dev, in fib_good_nh()
2209 &nh->fib_nh_gw6); in fib_good_nh()
2227 if (unlikely(res->fi->nh)) { in fib_select_multipath()