Skip to content

Commit bdf0046

Browse files
dsaherndavem330
authored andcommitted
net: Replace nhc_has_gw with nhc_gw_family
Allow the gateway in a fib_nh_common to be from a different address family than the outer fib{6}_nh. To that end, replace nhc_has_gw with nhc_gw_family and update users of nhc_has_gw to check nhc_gw_family. Now nhc_family is used to know if the nh_common is part of a fib_nh or fib6_nh (used for container_of to get to route family specific data), and nhc_gw_family represents the address family for the gateway. Signed-off-by: David Ahern <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 71df577 commit bdf0046

File tree

10 files changed

+35
-38
lines changed

10 files changed

+35
-38
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4915,7 +4915,7 @@ static void mlxsw_sp_rt6_destroy(struct mlxsw_sp_rt6 *mlxsw_sp_rt6)
49154915
static bool mlxsw_sp_fib6_rt_can_mp(const struct fib6_info *rt)
49164916
{
49174917
/* RTF_CACHE routes are ignored */
4918-
return !(rt->fib6_flags & RTF_ADDRCONF) && rt->fib6_nh.fib_nh_has_gw;
4918+
return !(rt->fib6_flags & RTF_ADDRCONF) && rt->fib6_nh.fib_nh_gw_family;
49194919
}
49204920

49214921
static struct fib6_info *
@@ -5055,7 +5055,7 @@ static void mlxsw_sp_nexthop6_fini(struct mlxsw_sp *mlxsw_sp,
50555055
static bool mlxsw_sp_rt6_is_gateway(const struct mlxsw_sp *mlxsw_sp,
50565056
const struct fib6_info *rt)
50575057
{
5058-
return rt->fib6_nh.fib_nh_has_gw ||
5058+
return rt->fib6_nh.fib_nh_gw_family ||
50595059
mlxsw_sp_nexthop6_ipip_type(mlxsw_sp, rt, NULL);
50605060
}
50615061

include/net/ip6_route.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static inline bool rt6_need_strict(const struct in6_addr *daddr)
6969
static inline bool rt6_qualify_for_ecmp(const struct fib6_info *f6i)
7070
{
7171
return !(f6i->fib6_flags & (RTF_ADDRCONF|RTF_DYNAMIC)) &&
72-
f6i->fib6_nh.fib_nh_has_gw;
72+
f6i->fib6_nh.fib_nh_gw_family;
7373
}
7474

7575
void ip6_route_input(struct sk_buff *skb);

include/net/ip_fib.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ struct fib_nh_common {
8383
struct lwtunnel_state *nhc_lwtstate;
8484
unsigned char nhc_scope;
8585
u8 nhc_family;
86-
u8 nhc_has_gw:1,
87-
unused:7;
86+
u8 nhc_gw_family;
87+
8888
union {
8989
__be32 ipv4;
9090
struct in6_addr ipv6;
@@ -112,8 +112,7 @@ struct fib_nh {
112112
#define fib_nh_flags nh_common.nhc_flags
113113
#define fib_nh_lws nh_common.nhc_lwtstate
114114
#define fib_nh_scope nh_common.nhc_scope
115-
#define fib_nh_family nh_common.nhc_family
116-
#define fib_nh_has_gw nh_common.nhc_has_gw
115+
#define fib_nh_gw_family nh_common.nhc_gw_family
117116
#define fib_nh_gw4 nh_common.nhc_gw.ipv4
118117
#define fib_nh_gw6 nh_common.nhc_gw.ipv6
119118
#define fib_nh_weight nh_common.nhc_weight

include/trace/events/fib.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ TRACE_EVENT(fib_table_lookup,
6969
__assign_str(name, dev ? dev->name : "-");
7070

7171
if (nhc) {
72-
if (nhc->nhc_family == AF_INET) {
72+
if (nhc->nhc_gw_family == AF_INET) {
7373
p32 = (__be32 *) __entry->gw4;
7474
*p32 = nhc->nhc_gw.ipv4;
7575

7676
in6 = (struct in6_addr *)__entry->gw6;
7777
*in6 = in6_zero;
78-
} else if (nhc->nhc_family == AF_INET6) {
78+
} else if (nhc->nhc_gw_family == AF_INET6) {
7979
p32 = (__be32 *) __entry->gw4;
8080
*p32 = 0;
8181

net/core/filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4639,7 +4639,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
46394639
return BPF_FIB_LKUP_RET_UNSUPP_LWT;
46404640

46414641
dev = nhc->nhc_dev;
4642-
if (nhc->nhc_has_gw)
4642+
if (nhc->nhc_gw_family)
46434643
params->ipv4_dst = nhc->nhc_gw.ipv4;
46444644

46454645
params->rt_metric = res.fi->fib_priority;
@@ -4752,7 +4752,7 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
47524752
if (f6i->fib6_nh.fib_nh_lws)
47534753
return BPF_FIB_LKUP_RET_UNSUPP_LWT;
47544754

4755-
if (f6i->fib6_nh.fib_nh_has_gw)
4755+
if (f6i->fib6_nh.fib_nh_gw_family)
47564756
*dst = f6i->fib6_nh.fib_nh_gw6;
47574757

47584758
dev = f6i->fib6_nh.fib_nh_dev;

net/ipv4/fib_semantics.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ int fib_nh_init(struct net *net, struct fib_nh *nh,
513513
nh->fib_nh_oif = cfg->fc_oif;
514514
if (cfg->fc_gw) {
515515
nh->fib_nh_gw4 = cfg->fc_gw;
516-
nh->fib_nh_has_gw = 1;
516+
nh->fib_nh_gw_family = AF_INET;
517517
}
518518
nh->fib_nh_flags = cfg->fc_flags;
519519

@@ -1238,7 +1238,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
12381238
"Route with host scope can not have multiple nexthops");
12391239
goto err_inval;
12401240
}
1241-
if (nh->fib_nh_gw4) {
1241+
if (nh->fib_nh_gw_family) {
12421242
NL_SET_ERR_MSG(extack,
12431243
"Route with host scope can not have a gateway");
12441244
goto err_inval;
@@ -1341,18 +1341,15 @@ int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc,
13411341
rcu_read_unlock();
13421342
}
13431343

1344-
if (nhc->nhc_has_gw) {
1345-
switch (nhc->nhc_family) {
1346-
case AF_INET:
1347-
if (nla_put_in_addr(skb, RTA_GATEWAY, nhc->nhc_gw.ipv4))
1348-
goto nla_put_failure;
1349-
break;
1350-
case AF_INET6:
1351-
if (nla_put_in6_addr(skb, RTA_GATEWAY,
1352-
&nhc->nhc_gw.ipv6) < 0)
1353-
goto nla_put_failure;
1354-
break;
1355-
}
1344+
switch (nhc->nhc_gw_family) {
1345+
case AF_INET:
1346+
if (nla_put_in_addr(skb, RTA_GATEWAY, nhc->nhc_gw.ipv4))
1347+
goto nla_put_failure;
1348+
break;
1349+
case AF_INET6:
1350+
if (nla_put_in6_addr(skb, RTA_GATEWAY, &nhc->nhc_gw.ipv6) < 0)
1351+
goto nla_put_failure;
1352+
break;
13561353
}
13571354

13581355
*flags |= (nhc->nhc_flags & RTNH_F_ONLINK);

net/ipv4/route.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,8 +1734,9 @@ static int __mkroute_input(struct sk_buff *skb,
17341734
do_cache = res->fi && !itag;
17351735
if (out_dev == in_dev && err && IN_DEV_TX_REDIRECTS(out_dev) &&
17361736
skb->protocol == htons(ETH_P_IP)) {
1737-
__be32 gw = nhc->nhc_family == AF_INET ? nhc->nhc_gw.ipv4 : 0;
1737+
__be32 gw;
17381738

1739+
gw = nhc->nhc_gw_family == AF_INET ? nhc->nhc_gw.ipv4 : 0;
17391740
if (IN_DEV_SHARED_MEDIA(out_dev) ||
17401741
inet_addr_onlink(out_dev, saddr, gw))
17411742
IPCB(skb)->flags |= IPSKB_DOREDIRECT;
@@ -2284,7 +2285,7 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
22842285
} else {
22852286
if (unlikely(fl4->flowi4_flags &
22862287
FLOWI_FLAG_KNOWN_NH &&
2287-
!(nhc->nhc_has_gw &&
2288+
!(nhc->nhc_gw_family &&
22882289
nhc->nhc_scope == RT_SCOPE_LINK))) {
22892290
do_cache = false;
22902291
goto add;

net/ipv6/addrconf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,7 @@ static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
24212421
for_each_fib6_node_rt_rcu(fn) {
24222422
if (rt->fib6_nh.fib_nh_dev->ifindex != dev->ifindex)
24232423
continue;
2424-
if (no_gw && rt->fib6_nh.fib_nh_has_gw)
2424+
if (no_gw && rt->fib6_nh.fib_nh_gw_family)
24252425
continue;
24262426
if ((rt->fib6_flags & flags) != flags)
24272427
continue;

net/ipv6/ip6_fib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,7 @@ static int ipv6_route_seq_show(struct seq_file *seq, void *v)
23042304
#else
23052305
seq_puts(seq, "00000000000000000000000000000000 00 ");
23062306
#endif
2307-
if (rt->fib6_nh.fib_nh_has_gw) {
2307+
if (rt->fib6_nh.fib_nh_gw_family) {
23082308
flags |= RTF_GATEWAY;
23092309
seq_printf(seq, "%pi6", &rt->fib6_nh.fib_nh_gw6);
23102310
} else {

net/ipv6/route.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static void rt6_probe(struct fib6_info *rt)
533533
* Router Reachability Probe MUST be rate-limited
534534
* to no more than one per minute.
535535
*/
536-
if (!rt || !rt->fib6_nh.fib_nh_has_gw)
536+
if (!rt || !rt->fib6_nh.fib_nh_gw_family)
537537
return;
538538

539539
nh_gw = &rt->fib6_nh.fib_nh_gw6;
@@ -595,7 +595,7 @@ static inline enum rt6_nud_state rt6_check_neigh(struct fib6_info *rt)
595595
struct neighbour *neigh;
596596

597597
if (rt->fib6_flags & RTF_NONEXTHOP ||
598-
!rt->fib6_nh.fib_nh_has_gw)
598+
!rt->fib6_nh.fib_nh_gw_family)
599599
return RT6_NUD_SUCCEED;
600600

601601
rcu_read_lock_bh();
@@ -769,7 +769,7 @@ static struct fib6_info *rt6_select(struct net *net, struct fib6_node *fn,
769769

770770
static bool rt6_is_gw_or_nonexthop(const struct fib6_info *rt)
771771
{
772-
return (rt->fib6_flags & RTF_NONEXTHOP) || rt->fib6_nh.fib_nh_has_gw;
772+
return (rt->fib6_flags & RTF_NONEXTHOP) || rt->fib6_nh.fib_nh_gw_family;
773773
}
774774

775775
#ifdef CONFIG_IPV6_ROUTE_INFO
@@ -975,7 +975,7 @@ static void ip6_rt_copy_init(struct rt6_info *rt, struct fib6_info *ort)
975975
rt->rt6i_dst = ort->fib6_dst;
976976
rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL;
977977
rt->rt6i_flags = ort->fib6_flags;
978-
if (ort->fib6_nh.fib_nh_has_gw) {
978+
if (ort->fib6_nh.fib_nh_gw_family) {
979979
rt->rt6i_gateway = ort->fib6_nh.fib_nh_gw6;
980980
rt->rt6i_flags |= RTF_GATEWAY;
981981
}
@@ -1860,7 +1860,7 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
18601860
rcu_read_unlock();
18611861
return rt;
18621862
} else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) &&
1863-
!f6i->fib6_nh.fib_nh_has_gw)) {
1863+
!f6i->fib6_nh.fib_nh_gw_family)) {
18641864
/* Create a RTF_CACHE clone which will not be
18651865
* owned by the fib6 tree. It is for the special case where
18661866
* the daddr in the skb during the neighbor look-up is different
@@ -2430,7 +2430,7 @@ static struct rt6_info *__ip6_route_redirect(struct net *net,
24302430
continue;
24312431
if (rt->fib6_flags & RTF_REJECT)
24322432
break;
2433-
if (!rt->fib6_nh.fib_nh_has_gw)
2433+
if (!rt->fib6_nh.fib_nh_gw_family)
24342434
continue;
24352435
if (fl6->flowi6_oif != rt->fib6_nh.fib_nh_dev->ifindex)
24362436
continue;
@@ -2964,7 +2964,7 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
29642964
goto out;
29652965

29662966
fib6_nh->fib_nh_gw6 = cfg->fc_gateway;
2967-
fib6_nh->fib_nh_has_gw = 1;
2967+
fib6_nh->fib_nh_gw_family = AF_INET6;
29682968
}
29692969

29702970
err = -ENODEV;
@@ -3476,7 +3476,7 @@ static struct fib6_info *rt6_get_route_info(struct net *net,
34763476
if (rt->fib6_nh.fib_nh_dev->ifindex != ifindex)
34773477
continue;
34783478
if (!(rt->fib6_flags & RTF_ROUTEINFO) ||
3479-
!rt->fib6_nh.fib_nh_has_gw)
3479+
!rt->fib6_nh.fib_nh_gw_family)
34803480
continue;
34813481
if (!ipv6_addr_equal(&rt->fib6_nh.fib_nh_gw6, gwaddr))
34823482
continue;
@@ -3807,7 +3807,7 @@ static int fib6_clean_tohost(struct fib6_info *rt, void *arg)
38073807
struct in6_addr *gateway = (struct in6_addr *)arg;
38083808

38093809
if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) &&
3810-
rt->fib6_nh.fib_nh_has_gw &&
3810+
rt->fib6_nh.fib_nh_gw_family &&
38113811
ipv6_addr_equal(gateway, &rt->fib6_nh.fib_nh_gw6)) {
38123812
return -1;
38133813
}

0 commit comments

Comments
 (0)