BPF List
 help / color / mirror / Atom feed
From: John Fastabend <john.fastabend@gmail.com>
To: hawk@kernel.org, daniel@iogearbox.net, kuba@kernel.org,
	davem@davemloft.net, ast@kernel.org
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
	john.fastabend@gmail.com, sdf@google.com
Subject: [0/2 bpf-next] Expose netdev in XDP progs with BTF_ID
Date: Wed,  9 Nov 2022 13:52:40 -0800	[thread overview]
Message-ID: <20221109215242.1279993-1-john.fastabend@gmail.com> (raw)

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

-- 
2.33.0


             reply	other threads:[~2022-11-09 21:53 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09 21:52 John Fastabend [this message]
2022-11-09 21:52 ` [1/2 bpf-next] bpf: expose net_device from xdp for metadata John Fastabend
2022-11-10  1:37   ` Yonghong Song
2022-11-10  2:17     ` John Fastabend
2022-11-10 12:45       ` Toke Høiland-Jørgensen
2022-11-10 16:53         ` Yonghong Song
2022-11-10 17:02         ` John Fastabend
2022-11-11 10:51           ` Jesper Dangaard Brouer
2022-11-11 15:15             ` Yonghong Song
2022-11-10 16:46       ` Yonghong Song
2022-11-10 22:58         ` John Fastabend
2022-11-10 23:11           ` John Fastabend
2022-11-11  6:34             ` Yonghong Song
2022-11-13 18:27               ` John Fastabend
2022-11-14 16:51                 ` Yonghong Song
2022-11-14 18:23                   ` John Fastabend
2022-11-16 19:46                     ` Jakub Kicinski
2022-11-11  6:28           ` Yonghong Song
2022-11-11  1:13   ` kernel test robot
2022-11-09 21:52 ` [2/2 bpf-next] bpf: add selftest to read xdp_md fields John Fastabend

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221109215242.1279993-1-john.fastabend@gmail.com \
    --to=john.fastabend@gmail.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=hawk@kernel.org \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=sdf@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox