netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC v1] net: xdp: allow for layer 3 packets in generic skb handler
@ 2020-04-27  1:10 Jason A. Donenfeld
  2020-04-27  7:20 ` Toke Høiland-Jørgensen
  0 siblings, 1 reply; 27+ messages in thread
From: Jason A. Donenfeld @ 2020-04-27  1:10 UTC (permalink / raw)
  To: netdev; +Cc: Jason A. Donenfeld, Toke Høiland-Jørgensen

A user reported a few days ago that packets from wireguard were possibly
ignored by XDP [1]. We haven't heard back from the original reporter to
receive more info, so this here is mostly speculative. Successfully nerd
sniped, Toke and I started poking around. Toke noticed that the generic
skb xdp handler path seems to assume that packets will always have an
ethernet header, which really isn't always the case for layer 3 packets,
which are produced by multiple drivers. This patch is untested, but I
wanted to gauge interest in this approach: if the mac_len is 0, then we
assume that it's a layer 3 packet, and figure out skb->protocol from
looking at the IP header. This patch also adds some stricter testing
around mac_len before we assume that it's an ethhdr.

[1] https://lore.kernel.org/wireguard/M5WzVK5--3-2@tuta.io/

Cc: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 net/core/dev.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 522288177bbd..1c4b0af09be2 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -4551,9 +4551,11 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
 	xdp->data_hard_start = skb->data - skb_headroom(skb);
 	orig_data_end = xdp->data_end;
 	orig_data = xdp->data;
-	eth = (struct ethhdr *)xdp->data;
-	orig_bcast = is_multicast_ether_addr_64bits(eth->h_dest);
-	orig_eth_type = eth->h_proto;
+	if (mac_len == sizeof(struct ethhdr)) {
+		eth = (struct ethhdr *)xdp->data;
+		orig_bcast = is_multicast_ether_addr_64bits(eth->h_dest);
+		orig_eth_type = eth->h_proto;
+	}
 
 	rxqueue = netif_get_rxqueue(skb);
 	xdp->rxq = &rxqueue->xdp_rxq;
@@ -4583,11 +4585,24 @@ static u32 netif_receive_generic_xdp(struct sk_buff *skb,
 	}
 
 	/* check if XDP changed eth hdr such SKB needs update */
-	eth = (struct ethhdr *)xdp->data;
-	if ((orig_eth_type != eth->h_proto) ||
-	    (orig_bcast != is_multicast_ether_addr_64bits(eth->h_dest))) {
-		__skb_push(skb, ETH_HLEN);
-		skb->protocol = eth_type_trans(skb, skb->dev);
+	if (mac_len == 0) {
+		switch (ip_hdr(skb)->version) {
+		case 4:
+			skb->protocol = htons(ETH_P_IP);
+			break;
+		case 6:
+			skb->protocol = htons(ETH_P_IPV6);
+			break;
+		default:
+			goto do_drop;
+		}
+	} else if (mac_len == sizeof(struct ethhdr)) {
+		eth = (struct ethhdr *)xdp->data;
+		if ((orig_eth_type != eth->h_proto) ||
+		    (orig_bcast != is_multicast_ether_addr_64bits(eth->h_dest))) {
+			__skb_push(skb, ETH_HLEN);
+			skb->protocol = eth_type_trans(skb, skb->dev);
+		}
 	}
 
 	switch (act) {
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2020-04-28 17:03 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27  1:10 [PATCH RFC v1] net: xdp: allow for layer 3 packets in generic skb handler Jason A. Donenfeld
2020-04-27  7:20 ` Toke Høiland-Jørgensen
2020-04-27 10:05   ` Jason A. Donenfeld
2020-04-27 10:22     ` [PATCH RFC v2] " Jason A. Donenfeld
2020-04-27 11:16       ` Toke Høiland-Jørgensen
2020-04-27 14:45       ` David Ahern
2020-04-27 19:58         ` Jason A. Donenfeld
2020-04-27 20:08           ` Toke Høiland-Jørgensen
2020-04-27 20:10             ` Jason A. Donenfeld
2020-04-27 20:42               ` [PATCH net v3] net: xdp: account " Jason A. Donenfeld
2020-04-27 20:52                 ` Jakub Kicinski
2020-04-27 20:57                   ` Jason A. Donenfeld
2020-04-27 21:00                   ` Jakub Kicinski
2020-04-27 21:08                     ` Jason A. Donenfeld
2020-04-27 21:19                       ` Jakub Kicinski
2020-04-27 21:14                     ` Toke Høiland-Jørgensen
2020-04-27 21:31                       ` Jakub Kicinski
2020-04-27 23:00                         ` Jason A. Donenfeld
2020-04-27 23:45                           ` Jason A. Donenfeld
2020-04-28  0:15                             ` Jakub Kicinski
2020-04-28  0:17                               ` Jason A. Donenfeld
2020-04-28  0:40                                 ` Jakub Kicinski
2020-04-28  9:27                         ` Toke Høiland-Jørgensen
2020-04-28 16:51                           ` Jakub Kicinski
2020-04-28 17:03                             ` Alexei Starovoitov
2020-04-27 21:00                 ` Toke Høiland-Jørgensen
2020-04-27 10:30     ` [PATCH RFC v1] net: xdp: allow " Toke Høiland-Jørgensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).