Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <daniel@iogearbox.net>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://lore.kernel.org/r/20231024214904.29825-6-daniel@iogearbox.net
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>

authored by

Daniel Borkmann and committed by
Martin KaFai Lau
bec981a4 92a85e18

+10 -5
+4 -4
tools/bpf/bpftool/Documentation/bpftool-net.rst
··· 37 37 **bpftool net { show | list }** [ **dev** *NAME* ] 38 38 List bpf program attachments in the kernel networking subsystem. 39 39 40 - Currently, device driver xdp attachments, tcx and old-style tc 40 + Currently, device driver xdp attachments, tcx, netkit and old-style tc 41 41 classifier/action attachments, flow_dissector as well as netfilter 42 42 attachments are implemented, i.e., for 43 43 program types **BPF_PROG_TYPE_XDP**, **BPF_PROG_TYPE_SCHED_CLS**, ··· 52 52 bpf programs, users should consult other tools, e.g., iproute2. 53 53 54 54 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 57 57 ordered based on ifindex number. If multiple bpf programs attached 58 58 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 60 60 attached to non clsact qdiscs, and finally all bpf programs attached 61 61 to root and clsact qdisc. 62 62
+6 -1
tools/bpf/bpftool/net.c
··· 79 79 static const char * const attach_loc_strings[] = { 80 80 [BPF_TCX_INGRESS] = "tcx/ingress", 81 81 [BPF_TCX_EGRESS] = "tcx/egress", 82 + [BPF_NETKIT_PRIMARY] = "netkit/primary", 83 + [BPF_NETKIT_PEER] = "netkit/peer", 82 84 }; 83 85 84 86 const size_t net_attach_type_size = ARRAY_SIZE(attach_type_strings); ··· 508 506 { 509 507 __show_dev_tc_bpf(dev, BPF_TCX_INGRESS); 510 508 __show_dev_tc_bpf(dev, BPF_TCX_EGRESS); 509 + 510 + __show_dev_tc_bpf(dev, BPF_NETKIT_PRIMARY); 511 + __show_dev_tc_bpf(dev, BPF_NETKIT_PEER); 511 512 } 512 513 513 514 static int show_dev_tc_bpf_classic(int sock, unsigned int nl_pid, ··· 931 926 " ATTACH_TYPE := { xdp | xdpgeneric | xdpdrv | xdpoffload }\n" 932 927 " " HELP_SPEC_OPTIONS " }\n" 933 928 "\n" 934 - "Note: Only xdp, tcx, tc, flow_dissector and netfilter attachments\n" 929 + "Note: Only xdp, tcx, tc, netkit, flow_dissector and netfilter attachments\n" 935 930 " are currently supported.\n" 936 931 " For progs attached to cgroups, use \"bpftool cgroup\"\n" 937 932 " to dump program attachments. For program types\n"