Skip to content

Expose netdev in XDP progs with BTF_ID

John Fastabend bpf llvm netdev oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 16 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2bpf: expose net_device from xdp for metadatainclude/uapi/linux/bpf.h net/core/filter.c tools/include/uapi/linux/bpf.h+21 -016 replies
2/2bpf: add selftest to read xdp_md fieldstools/testing/selftests/bpf/prog_tests/xdp_md.c tools/testing/selftests/bpf/progs/test_xdp_md.c+60 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [0/2 bpf-next] Expose netdev in XDP progs with BTF_ID

In one of our network monitoring tools we collect metadata about the interfaces. This is done in a map and then userspace can read the stats out as needed. Currently, this is done through kprobes but it causes unnecessary overhead (we have an XDP program running and its slower than XDP anyways) and extra complexity as we have two programs instead of one. The main hook we use to chase down the needed data is the net_device. From this we can get the name of the interface, its network namespace (and eventually pod in K8s world), qdisc information, etc.

Because some of the data is per packet data, e.g. getting a unique key for the ifindex+inum, we can't simply do it with an iterator.

Patch1 exposes the net_device in the xdp_md and patch 2 adds some tests to walk the net_device to report name, ifindex, and inum.

John Fastabend (2):
bpf: expose net_device from xdp for additional metadata
bpf: add selftest to read xdp_md fields

 include/uapi/linux/bpf.h                      |  1 +
 net/core/filter.c                             | 19 ++++++++++
 tools/include/uapi/linux/bpf.h                |  1 +
 .../testing/selftests/bpf/prog_tests/xdp_md.c | 35 +++++++++++++++++++
 .../testing/selftests/bpf/progs/test_xdp_md.c | 25 +++++++++++++
 5 files changed, 81 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_md.c
 create mode 100644 tools/testing/selftests/bpf/progs/test_xdp_md.c
Signature · 1 line
2.33.0