[PATCH RFC bpf-next 29/52] net, xdp: try to fill skb fields when converting from an &xdp_frame

From: Alexander Lobakin
Date: Tue Jun 28 2022 - 15:56:55 EST


In __xdp_build_skb_from_frame(), if there's a metadata in front of
the data, check if it's a generic-compatible metadata and try to
populate the HW-originated skb fields: checksum status, hash etc.
As xdp_populate_skb_meta_generic() requires the skb->mac_header
to be set and valid, call the skb_reset_mac_header() first, as
skb->data at this point is pointing (sic!) to the MAC header.
The two most obvious users are cpumap and veth.

Signed-off-by: Alexander Lobakin <alexandr.lobakin@xxxxxxxxx>
---
net/bpf/core.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/net/bpf/core.c b/net/bpf/core.c
index 775f9648e8cf..d2d01b8e6441 100644
--- a/net/bpf/core.c
+++ b/net/bpf/core.c
@@ -659,8 +659,11 @@ struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,

skb_reserve(skb, headroom);
__skb_put(skb, xdpf->len);
- if (metasize)
+ if (metasize) {
+ skb_reset_mac_header(skb);
skb_metadata_set(skb, metasize);
+ xdp_populate_skb_meta_generic(skb);
+ }

if (unlikely(xdp_frame_has_frags(xdpf)))
xdp_update_skb_shared_info(skb, nr_frags,
@@ -671,12 +674,6 @@ struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
/* Essential SKB info: protocol and skb->dev */
skb->protocol = eth_type_trans(skb, dev);

- /* Optional SKB info, currently missing:
- * - HW checksum info (skb->ip_summed)
- * - HW RX hash (skb_set_hash)
- * - RX ring dev queue index (skb_record_rx_queue)
- */
-
/* Until page_pool get SKB return path, release DMA here */
xdp_release_frame(xdpf);

--
2.36.1