summaryrefslogtreecommitdiff
path: root/include/net/xdp.h
diff options
context:
space:
mode:
authorLorenzo Bianconi <lorenzo@kernel.org>2022-01-21 11:09:54 +0100
committerAlexei Starovoitov <ast@kernel.org>2022-01-21 14:14:02 -0800
commit0165cc817075cf701e4289838f1d925ff1911b3e (patch)
tree4044357f657e7f6d79002a841e1a733384df07af /include/net/xdp.h
parente121d27083e38bfe6ca9494fbed039e69889d5c7 (diff)
bpf: introduce bpf_xdp_get_buff_len helper
Introduce bpf_xdp_get_buff_len helper in order to return the xdp buffer total size (linear and paged area) Acked-by: Toke Hoiland-Jorgensen <toke@redhat.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Link: https://lore.kernel.org/r/aac9ac3504c84026cf66a3c71b7c5ae89bc991be.1642758637.git.lorenzo@kernel.org Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include/net/xdp.h')
-rw-r--r--include/net/xdp.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 8463dea8b4db..52b593321956 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -145,6 +145,20 @@ xdp_get_shared_info_from_buff(struct xdp_buff *xdp)
return (struct skb_shared_info *)xdp_data_hard_end(xdp);
}
+static __always_inline unsigned int xdp_get_buff_len(struct xdp_buff *xdp)
+{
+ unsigned int len = xdp->data_end - xdp->data;
+ struct skb_shared_info *sinfo;
+
+ if (likely(!xdp_buff_has_frags(xdp)))
+ goto out;
+
+ sinfo = xdp_get_shared_info_from_buff(xdp);
+ len += sinfo->xdp_frags_size;
+out:
+ return len;
+}
+
struct xdp_frame {
void *data;
u16 len;