Skip to content

Commit db53cd3

Browse files
dsahernkuba-moo
authored andcommitted
net: Handle l3mdev in ip_tunnel_init_flow
Ido reported that the commit referenced in the Fixes tag broke a gre use case with dummy devices. Add a check to ip_tunnel_init_flow to see if the oif is an l3mdev port and if so set the oif to 0 to avoid the oif comparison in fib_lookup_good_nhc. Fixes: 40867d7 ("net: Add l3mdev index to flow struct and avoid oif reset for port devices") Reported-by: Ido Schimmel <[email protected]> Signed-off-by: David Ahern <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 83daab0 commit db53cd3

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ mlxsw_sp_span_gretap4_route(const struct net_device *to_dev,
423423

424424
parms = mlxsw_sp_ipip_netdev_parms4(to_dev);
425425
ip_tunnel_init_flow(&fl4, parms.iph.protocol, *daddrp, *saddrp,
426-
0, 0, parms.link, tun->fwmark, 0);
426+
0, 0, dev_net(to_dev), parms.link, tun->fwmark, 0);
427427

428428
rt = ip_route_output_key(tun->net, &fl4);
429429
if (IS_ERR(rt))

include/net/ip_tunnels.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,18 @@ static inline __be32 tunnel_id_to_key32(__be64 tun_id)
243243
static inline void ip_tunnel_init_flow(struct flowi4 *fl4,
244244
int proto,
245245
__be32 daddr, __be32 saddr,
246-
__be32 key, __u8 tos, int oif,
246+
__be32 key, __u8 tos,
247+
struct net *net, int oif,
247248
__u32 mark, __u32 tun_inner_hash)
248249
{
249250
memset(fl4, 0, sizeof(*fl4));
250-
fl4->flowi4_oif = oif;
251+
252+
if (oif) {
253+
fl4->flowi4_l3mdev = l3mdev_master_upper_ifindex_by_index_rcu(net, oif);
254+
/* Legacy VRF/l3mdev use case */
255+
fl4->flowi4_oif = fl4->flowi4_l3mdev ? 0 : oif;
256+
}
257+
251258
fl4->daddr = daddr;
252259
fl4->saddr = saddr;
253260
fl4->flowi4_tos = tos;

net/ipv4/ip_gre.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,8 @@ static int gre_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
605605
key = &info->key;
606606
ip_tunnel_init_flow(&fl4, IPPROTO_GRE, key->u.ipv4.dst, key->u.ipv4.src,
607607
tunnel_id_to_key32(key->tun_id),
608-
key->tos & ~INET_ECN_MASK, 0, skb->mark,
609-
skb_get_hash(skb));
608+
key->tos & ~INET_ECN_MASK, dev_net(dev), 0,
609+
skb->mark, skb_get_hash(skb));
610610
rt = ip_route_output_key(dev_net(dev), &fl4);
611611
if (IS_ERR(rt))
612612
return PTR_ERR(rt);

net/ipv4/ip_tunnel.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ static int ip_tunnel_bind_dev(struct net_device *dev)
294294

295295
ip_tunnel_init_flow(&fl4, iph->protocol, iph->daddr,
296296
iph->saddr, tunnel->parms.o_key,
297-
RT_TOS(iph->tos), tunnel->parms.link,
298-
tunnel->fwmark, 0);
297+
RT_TOS(iph->tos), dev_net(dev),
298+
tunnel->parms.link, tunnel->fwmark, 0);
299299
rt = ip_route_output_key(tunnel->net, &fl4);
300300

301301
if (!IS_ERR(rt)) {
@@ -570,7 +570,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
570570
}
571571
ip_tunnel_init_flow(&fl4, proto, key->u.ipv4.dst, key->u.ipv4.src,
572572
tunnel_id_to_key32(key->tun_id), RT_TOS(tos),
573-
0, skb->mark, skb_get_hash(skb));
573+
dev_net(dev), 0, skb->mark, skb_get_hash(skb));
574574
if (tunnel->encap.type != TUNNEL_ENCAP_NONE)
575575
goto tx_error;
576576

@@ -726,7 +726,8 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
726726
}
727727

728728
ip_tunnel_init_flow(&fl4, protocol, dst, tnl_params->saddr,
729-
tunnel->parms.o_key, RT_TOS(tos), tunnel->parms.link,
729+
tunnel->parms.o_key, RT_TOS(tos),
730+
dev_net(dev), tunnel->parms.link,
730731
tunnel->fwmark, skb_get_hash(skb));
731732

732733
if (ip_tunnel_encap(skb, tunnel, &protocol, &fl4) < 0)

0 commit comments

Comments
 (0)