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 <dsahern@gmail.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
David Ahern 2019-04-05 16:30:26 -07:00 committed by David S. Miller
parent 71df5777aa
commit bdf0046771
10 changed files with 35 additions and 38 deletions

View File

@ -4915,7 +4915,7 @@ static void mlxsw_sp_rt6_destroy(struct mlxsw_sp_rt6 *mlxsw_sp_rt6)
static bool mlxsw_sp_fib6_rt_can_mp(const struct fib6_info *rt) static bool mlxsw_sp_fib6_rt_can_mp(const struct fib6_info *rt)
{ {
/* RTF_CACHE routes are ignored */ /* RTF_CACHE routes are ignored */
return !(rt->fib6_flags & RTF_ADDRCONF) && rt->fib6_nh.fib_nh_has_gw; return !(rt->fib6_flags & RTF_ADDRCONF) && rt->fib6_nh.fib_nh_gw_family;
} }
static struct fib6_info * static struct fib6_info *
@ -5055,7 +5055,7 @@ static void mlxsw_sp_nexthop6_fini(struct mlxsw_sp *mlxsw_sp,
static bool mlxsw_sp_rt6_is_gateway(const struct mlxsw_sp *mlxsw_sp, static bool mlxsw_sp_rt6_is_gateway(const struct mlxsw_sp *mlxsw_sp,
const struct fib6_info *rt) const struct fib6_info *rt)
{ {
return rt->fib6_nh.fib_nh_has_gw || return rt->fib6_nh.fib_nh_gw_family ||
mlxsw_sp_nexthop6_ipip_type(mlxsw_sp, rt, NULL); mlxsw_sp_nexthop6_ipip_type(mlxsw_sp, rt, NULL);
} }

View File

@ -69,7 +69,7 @@ static inline bool rt6_need_strict(const struct in6_addr *daddr)
static inline bool rt6_qualify_for_ecmp(const struct fib6_info *f6i) static inline bool rt6_qualify_for_ecmp(const struct fib6_info *f6i)
{ {
return !(f6i->fib6_flags & (RTF_ADDRCONF|RTF_DYNAMIC)) && return !(f6i->fib6_flags & (RTF_ADDRCONF|RTF_DYNAMIC)) &&
f6i->fib6_nh.fib_nh_has_gw; f6i->fib6_nh.fib_nh_gw_family;
} }
void ip6_route_input(struct sk_buff *skb); void ip6_route_input(struct sk_buff *skb);

View File

@ -83,8 +83,8 @@ struct fib_nh_common {
struct lwtunnel_state *nhc_lwtstate; struct lwtunnel_state *nhc_lwtstate;
unsigned char nhc_scope; unsigned char nhc_scope;
u8 nhc_family; u8 nhc_family;
u8 nhc_has_gw:1, u8 nhc_gw_family;
unused:7;
union { union {
__be32 ipv4; __be32 ipv4;
struct in6_addr ipv6; struct in6_addr ipv6;
@ -112,8 +112,7 @@ struct fib_nh {
#define fib_nh_flags nh_common.nhc_flags #define fib_nh_flags nh_common.nhc_flags
#define fib_nh_lws nh_common.nhc_lwtstate #define fib_nh_lws nh_common.nhc_lwtstate
#define fib_nh_scope nh_common.nhc_scope #define fib_nh_scope nh_common.nhc_scope
#define fib_nh_family nh_common.nhc_family #define fib_nh_gw_family nh_common.nhc_gw_family
#define fib_nh_has_gw nh_common.nhc_has_gw
#define fib_nh_gw4 nh_common.nhc_gw.ipv4 #define fib_nh_gw4 nh_common.nhc_gw.ipv4
#define fib_nh_gw6 nh_common.nhc_gw.ipv6 #define fib_nh_gw6 nh_common.nhc_gw.ipv6
#define fib_nh_weight nh_common.nhc_weight #define fib_nh_weight nh_common.nhc_weight

View File

@ -69,13 +69,13 @@ TRACE_EVENT(fib_table_lookup,
__assign_str(name, dev ? dev->name : "-"); __assign_str(name, dev ? dev->name : "-");
if (nhc) { if (nhc) {
if (nhc->nhc_family == AF_INET) { if (nhc->nhc_gw_family == AF_INET) {
p32 = (__be32 *) __entry->gw4; p32 = (__be32 *) __entry->gw4;
*p32 = nhc->nhc_gw.ipv4; *p32 = nhc->nhc_gw.ipv4;
in6 = (struct in6_addr *)__entry->gw6; in6 = (struct in6_addr *)__entry->gw6;
*in6 = in6_zero; *in6 = in6_zero;
} else if (nhc->nhc_family == AF_INET6) { } else if (nhc->nhc_gw_family == AF_INET6) {
p32 = (__be32 *) __entry->gw4; p32 = (__be32 *) __entry->gw4;
*p32 = 0; *p32 = 0;

View File

@ -4639,7 +4639,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
return BPF_FIB_LKUP_RET_UNSUPP_LWT; return BPF_FIB_LKUP_RET_UNSUPP_LWT;
dev = nhc->nhc_dev; dev = nhc->nhc_dev;
if (nhc->nhc_has_gw) if (nhc->nhc_gw_family)
params->ipv4_dst = nhc->nhc_gw.ipv4; params->ipv4_dst = nhc->nhc_gw.ipv4;
params->rt_metric = res.fi->fib_priority; 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,
if (f6i->fib6_nh.fib_nh_lws) if (f6i->fib6_nh.fib_nh_lws)
return BPF_FIB_LKUP_RET_UNSUPP_LWT; return BPF_FIB_LKUP_RET_UNSUPP_LWT;
if (f6i->fib6_nh.fib_nh_has_gw) if (f6i->fib6_nh.fib_nh_gw_family)
*dst = f6i->fib6_nh.fib_nh_gw6; *dst = f6i->fib6_nh.fib_nh_gw6;
dev = f6i->fib6_nh.fib_nh_dev; dev = f6i->fib6_nh.fib_nh_dev;

View File

@ -513,7 +513,7 @@ int fib_nh_init(struct net *net, struct fib_nh *nh,
nh->fib_nh_oif = cfg->fc_oif; nh->fib_nh_oif = cfg->fc_oif;
if (cfg->fc_gw) { if (cfg->fc_gw) {
nh->fib_nh_gw4 = cfg->fc_gw; nh->fib_nh_gw4 = cfg->fc_gw;
nh->fib_nh_has_gw = 1; nh->fib_nh_gw_family = AF_INET;
} }
nh->fib_nh_flags = cfg->fc_flags; nh->fib_nh_flags = cfg->fc_flags;
@ -1238,7 +1238,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
"Route with host scope can not have multiple nexthops"); "Route with host scope can not have multiple nexthops");
goto err_inval; goto err_inval;
} }
if (nh->fib_nh_gw4) { if (nh->fib_nh_gw_family) {
NL_SET_ERR_MSG(extack, NL_SET_ERR_MSG(extack,
"Route with host scope can not have a gateway"); "Route with host scope can not have a gateway");
goto err_inval; goto err_inval;
@ -1341,18 +1341,15 @@ int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc,
rcu_read_unlock(); rcu_read_unlock();
} }
if (nhc->nhc_has_gw) { switch (nhc->nhc_gw_family) {
switch (nhc->nhc_family) { case AF_INET:
case AF_INET: if (nla_put_in_addr(skb, RTA_GATEWAY, nhc->nhc_gw.ipv4))
if (nla_put_in_addr(skb, RTA_GATEWAY, nhc->nhc_gw.ipv4)) goto nla_put_failure;
goto nla_put_failure; break;
break; case AF_INET6:
case AF_INET6: if (nla_put_in6_addr(skb, RTA_GATEWAY, &nhc->nhc_gw.ipv6) < 0)
if (nla_put_in6_addr(skb, RTA_GATEWAY, goto nla_put_failure;
&nhc->nhc_gw.ipv6) < 0) break;
goto nla_put_failure;
break;
}
} }
*flags |= (nhc->nhc_flags & RTNH_F_ONLINK); *flags |= (nhc->nhc_flags & RTNH_F_ONLINK);

View File

@ -1734,8 +1734,9 @@ static int __mkroute_input(struct sk_buff *skb,
do_cache = res->fi && !itag; do_cache = res->fi && !itag;
if (out_dev == in_dev && err && IN_DEV_TX_REDIRECTS(out_dev) && if (out_dev == in_dev && err && IN_DEV_TX_REDIRECTS(out_dev) &&
skb->protocol == htons(ETH_P_IP)) { skb->protocol == htons(ETH_P_IP)) {
__be32 gw = nhc->nhc_family == AF_INET ? nhc->nhc_gw.ipv4 : 0; __be32 gw;
gw = nhc->nhc_gw_family == AF_INET ? nhc->nhc_gw.ipv4 : 0;
if (IN_DEV_SHARED_MEDIA(out_dev) || if (IN_DEV_SHARED_MEDIA(out_dev) ||
inet_addr_onlink(out_dev, saddr, gw)) inet_addr_onlink(out_dev, saddr, gw))
IPCB(skb)->flags |= IPSKB_DOREDIRECT; IPCB(skb)->flags |= IPSKB_DOREDIRECT;
@ -2284,7 +2285,7 @@ static struct rtable *__mkroute_output(const struct fib_result *res,
} else { } else {
if (unlikely(fl4->flowi4_flags & if (unlikely(fl4->flowi4_flags &
FLOWI_FLAG_KNOWN_NH && FLOWI_FLAG_KNOWN_NH &&
!(nhc->nhc_has_gw && !(nhc->nhc_gw_family &&
nhc->nhc_scope == RT_SCOPE_LINK))) { nhc->nhc_scope == RT_SCOPE_LINK))) {
do_cache = false; do_cache = false;
goto add; goto add;

View File

@ -2421,7 +2421,7 @@ static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
for_each_fib6_node_rt_rcu(fn) { for_each_fib6_node_rt_rcu(fn) {
if (rt->fib6_nh.fib_nh_dev->ifindex != dev->ifindex) if (rt->fib6_nh.fib_nh_dev->ifindex != dev->ifindex)
continue; continue;
if (no_gw && rt->fib6_nh.fib_nh_has_gw) if (no_gw && rt->fib6_nh.fib_nh_gw_family)
continue; continue;
if ((rt->fib6_flags & flags) != flags) if ((rt->fib6_flags & flags) != flags)
continue; continue;

View File

@ -2304,7 +2304,7 @@ static int ipv6_route_seq_show(struct seq_file *seq, void *v)
#else #else
seq_puts(seq, "00000000000000000000000000000000 00 "); seq_puts(seq, "00000000000000000000000000000000 00 ");
#endif #endif
if (rt->fib6_nh.fib_nh_has_gw) { if (rt->fib6_nh.fib_nh_gw_family) {
flags |= RTF_GATEWAY; flags |= RTF_GATEWAY;
seq_printf(seq, "%pi6", &rt->fib6_nh.fib_nh_gw6); seq_printf(seq, "%pi6", &rt->fib6_nh.fib_nh_gw6);
} else { } else {

View File

@ -533,7 +533,7 @@ static void rt6_probe(struct fib6_info *rt)
* Router Reachability Probe MUST be rate-limited * Router Reachability Probe MUST be rate-limited
* to no more than one per minute. * to no more than one per minute.
*/ */
if (!rt || !rt->fib6_nh.fib_nh_has_gw) if (!rt || !rt->fib6_nh.fib_nh_gw_family)
return; return;
nh_gw = &rt->fib6_nh.fib_nh_gw6; 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)
struct neighbour *neigh; struct neighbour *neigh;
if (rt->fib6_flags & RTF_NONEXTHOP || if (rt->fib6_flags & RTF_NONEXTHOP ||
!rt->fib6_nh.fib_nh_has_gw) !rt->fib6_nh.fib_nh_gw_family)
return RT6_NUD_SUCCEED; return RT6_NUD_SUCCEED;
rcu_read_lock_bh(); rcu_read_lock_bh();
@ -769,7 +769,7 @@ static struct fib6_info *rt6_select(struct net *net, struct fib6_node *fn,
static bool rt6_is_gw_or_nonexthop(const struct fib6_info *rt) static bool rt6_is_gw_or_nonexthop(const struct fib6_info *rt)
{ {
return (rt->fib6_flags & RTF_NONEXTHOP) || rt->fib6_nh.fib_nh_has_gw; return (rt->fib6_flags & RTF_NONEXTHOP) || rt->fib6_nh.fib_nh_gw_family;
} }
#ifdef CONFIG_IPV6_ROUTE_INFO #ifdef CONFIG_IPV6_ROUTE_INFO
@ -975,7 +975,7 @@ static void ip6_rt_copy_init(struct rt6_info *rt, struct fib6_info *ort)
rt->rt6i_dst = ort->fib6_dst; rt->rt6i_dst = ort->fib6_dst;
rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL; rt->rt6i_idev = dev ? in6_dev_get(dev) : NULL;
rt->rt6i_flags = ort->fib6_flags; rt->rt6i_flags = ort->fib6_flags;
if (ort->fib6_nh.fib_nh_has_gw) { if (ort->fib6_nh.fib_nh_gw_family) {
rt->rt6i_gateway = ort->fib6_nh.fib_nh_gw6; rt->rt6i_gateway = ort->fib6_nh.fib_nh_gw6;
rt->rt6i_flags |= RTF_GATEWAY; rt->rt6i_flags |= RTF_GATEWAY;
} }
@ -1860,7 +1860,7 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
rcu_read_unlock(); rcu_read_unlock();
return rt; return rt;
} else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) && } else if (unlikely((fl6->flowi6_flags & FLOWI_FLAG_KNOWN_NH) &&
!f6i->fib6_nh.fib_nh_has_gw)) { !f6i->fib6_nh.fib_nh_gw_family)) {
/* Create a RTF_CACHE clone which will not be /* Create a RTF_CACHE clone which will not be
* owned by the fib6 tree. It is for the special case where * owned by the fib6 tree. It is for the special case where
* the daddr in the skb during the neighbor look-up is different * the daddr in the skb during the neighbor look-up is different
@ -2430,7 +2430,7 @@ restart:
continue; continue;
if (rt->fib6_flags & RTF_REJECT) if (rt->fib6_flags & RTF_REJECT)
break; break;
if (!rt->fib6_nh.fib_nh_has_gw) if (!rt->fib6_nh.fib_nh_gw_family)
continue; continue;
if (fl6->flowi6_oif != rt->fib6_nh.fib_nh_dev->ifindex) if (fl6->flowi6_oif != rt->fib6_nh.fib_nh_dev->ifindex)
continue; continue;
@ -2964,7 +2964,7 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,
goto out; goto out;
fib6_nh->fib_nh_gw6 = cfg->fc_gateway; fib6_nh->fib_nh_gw6 = cfg->fc_gateway;
fib6_nh->fib_nh_has_gw = 1; fib6_nh->fib_nh_gw_family = AF_INET6;
} }
err = -ENODEV; err = -ENODEV;
@ -3476,7 +3476,7 @@ static struct fib6_info *rt6_get_route_info(struct net *net,
if (rt->fib6_nh.fib_nh_dev->ifindex != ifindex) if (rt->fib6_nh.fib_nh_dev->ifindex != ifindex)
continue; continue;
if (!(rt->fib6_flags & RTF_ROUTEINFO) || if (!(rt->fib6_flags & RTF_ROUTEINFO) ||
!rt->fib6_nh.fib_nh_has_gw) !rt->fib6_nh.fib_nh_gw_family)
continue; continue;
if (!ipv6_addr_equal(&rt->fib6_nh.fib_nh_gw6, gwaddr)) if (!ipv6_addr_equal(&rt->fib6_nh.fib_nh_gw6, gwaddr))
continue; continue;
@ -3807,7 +3807,7 @@ static int fib6_clean_tohost(struct fib6_info *rt, void *arg)
struct in6_addr *gateway = (struct in6_addr *)arg; struct in6_addr *gateway = (struct in6_addr *)arg;
if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) && if (((rt->fib6_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) &&
rt->fib6_nh.fib_nh_has_gw && rt->fib6_nh.fib_nh_gw_family &&
ipv6_addr_equal(gateway, &rt->fib6_nh.fib_nh_gw6)) { ipv6_addr_equal(gateway, &rt->fib6_nh.fib_nh_gw6)) {
return -1; return -1;
} }