Skip to content

Commit 6ed5326

Browse files
committed
bpftool: Extend net dump with netkit progs
Add support to dump BPF programs on netkit via bpftool. This includes both the BPF link and attach ops programs. Dumped information contain the attach location, function entry name, program ID and link ID when applicable. Example with tc BPF link: # ./bpftool net xdp: tc: nk1(22) netkit/peer tc1 prog_id 43 link_id 12 [...] Example with json dump: # ./bpftool net --json | jq [ { "xdp": [], "tc": [ { "devname": "nk1", "ifindex": 18, "kind": "netkit/primary", "name": "tc1", "prog_id": 29, "prog_flags": [], "link_id": 8, "link_flags": [] } ], "flow_dissector": [], "netfilter": [] } ] Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Quentin Monnet <[email protected]>
1 parent 9724c5b commit 6ed5326

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

tools/bpf/bpftool/Documentation/bpftool-net.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ DESCRIPTION
3737
**bpftool net { show | list }** [ **dev** *NAME* ]
3838
List bpf program attachments in the kernel networking subsystem.
3939

40-
Currently, device driver xdp attachments, tcx and old-style tc
40+
Currently, device driver xdp attachments, tcx, netkit and old-style tc
4141
classifier/action attachments, flow_dissector as well as netfilter
4242
attachments are implemented, i.e., for
4343
program types **BPF_PROG_TYPE_XDP**, **BPF_PROG_TYPE_SCHED_CLS**,
@@ -52,11 +52,11 @@ DESCRIPTION
5252
bpf programs, users should consult other tools, e.g., iproute2.
5353

5454
The current output will start with all xdp program attachments, followed by
55-
all tcx, then tc class/qdisc bpf program attachments, then flow_dissector
56-
and finally netfilter programs. Both xdp programs and tcx/tc programs are
55+
all tcx, netkit, then tc class/qdisc bpf program attachments, then flow_dissector
56+
and finally netfilter programs. Both xdp programs and tcx/netkit/tc programs are
5757
ordered based on ifindex number. If multiple bpf programs attached
5858
to the same networking device through **tc**, the order will be first
59-
all bpf programs attached to tcx, then tc classes, then all bpf programs
59+
all bpf programs attached to tcx, netkit, then tc classes, then all bpf programs
6060
attached to non clsact qdiscs, and finally all bpf programs attached
6161
to root and clsact qdisc.
6262

tools/bpf/bpftool/net.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ static const char * const attach_type_strings[] = {
7979
static const char * const attach_loc_strings[] = {
8080
[BPF_TCX_INGRESS] = "tcx/ingress",
8181
[BPF_TCX_EGRESS] = "tcx/egress",
82+
[BPF_NETKIT_PRIMARY] = "netkit/primary",
83+
[BPF_NETKIT_PEER] = "netkit/peer",
8284
};
8385

8486
const size_t net_attach_type_size = ARRAY_SIZE(attach_type_strings);
@@ -506,6 +508,9 @@ static void show_dev_tc_bpf(struct ip_devname_ifindex *dev)
506508
{
507509
__show_dev_tc_bpf(dev, BPF_TCX_INGRESS);
508510
__show_dev_tc_bpf(dev, BPF_TCX_EGRESS);
511+
512+
__show_dev_tc_bpf(dev, BPF_NETKIT_PRIMARY);
513+
__show_dev_tc_bpf(dev, BPF_NETKIT_PEER);
509514
}
510515

511516
static int show_dev_tc_bpf_classic(int sock, unsigned int nl_pid,
@@ -926,7 +931,7 @@ static int do_help(int argc, char **argv)
926931
" ATTACH_TYPE := { xdp | xdpgeneric | xdpdrv | xdpoffload }\n"
927932
" " HELP_SPEC_OPTIONS " }\n"
928933
"\n"
929-
"Note: Only xdp, tcx, tc, flow_dissector and netfilter attachments\n"
934+
"Note: Only xdp, tcx, tc, netkit, flow_dissector and netfilter attachments\n"
930935
" are currently supported.\n"
931936
" For progs attached to cgroups, use \"bpftool cgroup\"\n"
932937
" to dump program attachments. For program types\n"

0 commit comments

Comments
 (0)