Skip to content

Commit 302d201

Browse files
Guillaume Naultdavem330
authored andcommitted
bareudp: forbid mixing IP and MPLS in multiproto mode
In multiproto mode, bareudp_xmit() accepts sending multicast MPLS and IPv6 packets regardless of the bareudp ethertype. In practice, this let an IP tunnel send multicast MPLS packets, or an MPLS tunnel send IPv6 packets. We need to restrict the test further, so that the multiproto mode only enables * IPv6 for IPv4 tunnels, * or multicast MPLS for unicast MPLS tunnels. To improve clarity, the protocol validation is moved to its own function, where each logical test has its own condition. v2: s/ntohs/htons/ Fixes: 4b5f672 ("net: Special handling for IP & MPLS.") Signed-off-by: Guillaume Nault <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 706ec91 commit 302d201

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

drivers/net/bareudp.c

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,34 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
407407
return err;
408408
}
409409

410+
static bool bareudp_proto_valid(struct bareudp_dev *bareudp, __be16 proto)
411+
{
412+
if (bareudp->ethertype == proto)
413+
return true;
414+
415+
if (!bareudp->multi_proto_mode)
416+
return false;
417+
418+
if (bareudp->ethertype == htons(ETH_P_MPLS_UC) &&
419+
proto == htons(ETH_P_MPLS_MC))
420+
return true;
421+
422+
if (bareudp->ethertype == htons(ETH_P_IP) &&
423+
proto == htons(ETH_P_IPV6))
424+
return true;
425+
426+
return false;
427+
}
428+
410429
static netdev_tx_t bareudp_xmit(struct sk_buff *skb, struct net_device *dev)
411430
{
412431
struct bareudp_dev *bareudp = netdev_priv(dev);
413432
struct ip_tunnel_info *info = NULL;
414433
int err;
415434

416-
if (skb->protocol != bareudp->ethertype) {
417-
if (!bareudp->multi_proto_mode ||
418-
(skb->protocol != htons(ETH_P_MPLS_MC) &&
419-
skb->protocol != htons(ETH_P_IPV6))) {
420-
err = -EINVAL;
421-
goto tx_error;
422-
}
435+
if (!bareudp_proto_valid(bareudp, skb->protocol)) {
436+
err = -EINVAL;
437+
goto tx_error;
423438
}
424439

425440
info = skb_tunnel_info(skb);

0 commit comments

Comments
 (0)