1BPFTOOL-NET(8) BPFTOOL-NET(8)
2
3
4
6 bpftool-net - tool for inspection of netdev/tc related bpf prog attach‐
7 ments
8
10 bpftool [OPTIONS] net COMMAND
11
12 OPTIONS := { { -j | --json } [{ -p | --pretty }] | { -d | --debug }
13 | { -l | --legacy } }
14
15 COMMANDS := { show | list | attach | detach | help }
16
18 bpftool net { show | list } [ dev NAME ]
19 bpftool net attach ATTACH_TYPE PROG dev NAME [ overwrite ]
20 bpftool net detach ATTACH_TYPE dev NAME
21 bpftool net help
22
23 PROG := { id PROG_ID | pinned FILE | tag PROG_TAG }
24 ATTACH_TYPE := { xdp | xdpgeneric | xdpdrv | xdpoffload }
25
26
28 bpftool net { show | list } [ dev NAME ]
29 List bpf program attachments in the kernel networking subsys‐
30 tem.
31
32 Currently, only device driver xdp attachments and tc filter
33 classification/action attachments are implemented, i.e., for
34 program types BPF_PROG_TYPE_SCHED_CLS,
35 BPF_PROG_TYPE_SCHED_ACT and BPF_PROG_TYPE_XDP. For programs
36 attached to a particular cgroup, e.g.,
37 BPF_PROG_TYPE_CGROUP_SKB, BPF_PROG_TYPE_CGROUP_SOCK,
38 BPF_PROG_TYPE_SOCK_OPS and BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
39 users can use bpftool cgroup to dump cgroup attachments. For
40 sk_{filter, skb, msg, reuseport} and lwt/seg6 bpf programs,
41 users should consult other tools, e.g., iproute2.
42
43 The current output will start with all xdp program attach‐
44 ments, followed by all tc class/qdisc bpf program attach‐
45 ments. Both xdp programs and tc programs are ordered based on
46 ifindex number. If multiple bpf programs attached to the same
47 networking device through tc filter, the order will be first
48 all bpf programs attached to tc classes, then all bpf pro‐
49 grams attached to non clsact qdiscs, and finally all bpf pro‐
50 grams attached to root and clsact qdisc.
51
52 bpftool net attach ATTACH_TYPE PROG dev NAME [ overwrite ]
53 Attach bpf program PROG to network interface NAME with type
54 specified by ATTACH_TYPE. Previously attached bpf program can
55 be replaced by the command used with overwrite option. Cur‐
56 rently, only XDP-related modes are supported for ATTACH_TYPE.
57
58 ATTACH_TYPE can be of: xdp - try native XDP and fallback to
59 generic XDP if NIC driver does not support it; xdpgeneric -
60 Generic XDP. runs at generic XDP hook when packet already en‐
61 ters receive path as skb; xdpdrv - Native XDP. runs earliest
62 point in driver's receive path; xdpoffload - Offload XDP.
63 runs directly on NIC on each packet reception;
64
65 bpftool net detach ATTACH_TYPE dev NAME
66 Detach bpf program attached to network interface NAME with
67 type specified by ATTACH_TYPE. To detach bpf program, same
68 ATTACH_TYPE previously used for attach must be specified.
69 Currently, only XDP-related modes are supported for AT‐
70 TACH_TYPE.
71
72 bpftool net help
73 Print short help message.
74
76 -h, --help
77 Print short help message (similar to bpftool help).
78
79 -V, --version
80 Print bpftool's version number (similar to bpftool version),
81 the number of the libbpf version in use, and optional fea‐
82 tures that were included when bpftool was compiled. Optional
83 features include linking against libbfd to provide the disas‐
84 sembler for JIT-ted programs (bpftool prog dump jited) and
85 usage of BPF skeletons (some features like bpftool prog pro‐
86 file or showing pids associated to BPF objects may rely on
87 it).
88
89 -j, --json
90 Generate JSON output. For commands that cannot produce JSON,
91 this option has no effect.
92
93 -p, --pretty
94 Generate human-readable JSON output. Implies -j.
95
96 -d, --debug
97 Print all logs available, even debug-level information. This
98 includes logs from libbpf as well as from the verifier, when
99 attempting to load programs.
100
101 -l, --legacy
102 Use legacy libbpf mode which has more relaxed BPF program re‐
103 quirements. By default, bpftool has more strict requirements
104 about section names, changes pinning logic and doesn't sup‐
105 port some of the older non-BTF map declarations.
106
107 See
108 https://github.com/libbpf/libbpf/wiki/Libbpf:-the-road-to-v1.0
109 for details.
110
112 # bpftool net
113
114
115 xdp:
116 eth0(2) driver id 198
117
118 tc:
119 eth0(2) htb name prefix_matcher.o:[cls_prefix_matcher_htb] id 111727 act []
120 eth0(2) clsact/ingress fbflow_icmp id 130246 act []
121 eth0(2) clsact/egress prefix_matcher.o:[cls_prefix_matcher_clsact] id 111726
122 eth0(2) clsact/egress cls_fg_dscp id 108619 act []
123 eth0(2) clsact/egress fbflow_egress id 130245
124
125 # bpftool -jp net
126
127
128 [{
129 "xdp": [{
130 "devname": "eth0",
131 "ifindex": 2,
132 "mode": "driver",
133 "id": 198
134 }
135 ],
136 "tc": [{
137 "devname": "eth0",
138 "ifindex": 2,
139 "kind": "htb",
140 "name": "prefix_matcher.o:[cls_prefix_matcher_htb]",
141 "id": 111727,
142 "act": []
143 },{
144 "devname": "eth0",
145 "ifindex": 2,
146 "kind": "clsact/ingress",
147 "name": "fbflow_icmp",
148 "id": 130246,
149 "act": []
150 },{
151 "devname": "eth0",
152 "ifindex": 2,
153 "kind": "clsact/egress",
154 "name": "prefix_matcher.o:[cls_prefix_matcher_clsact]",
155 "id": 111726,
156 },{
157 "devname": "eth0",
158 "ifindex": 2,
159 "kind": "clsact/egress",
160 "name": "cls_fg_dscp",
161 "id": 108619,
162 "act": []
163 },{
164 "devname": "eth0",
165 "ifindex": 2,
166 "kind": "clsact/egress",
167 "name": "fbflow_egress",
168 "id": 130245,
169 }
170 ]
171 }
172 ]
173
174 # bpftool net attach xdpdrv id 16 dev enp6s0np0
175 # bpftool net
176
177
178 xdp:
179 enp6s0np0(4) driver id 16
180
181 # bpftool net attach xdpdrv id 16 dev enp6s0np0
182 # bpftool net attach xdpdrv id 20 dev enp6s0np0 overwrite
183 # bpftool net
184
185
186 xdp:
187 enp6s0np0(4) driver id 20
188
189 # bpftool net attach xdpdrv id 16 dev enp6s0np0
190 # bpftool net detach xdpdrv dev enp6s0np0
191 # bpftool net
192
193
194 xdp:
195
197 bpf(2), bpf-helpers(7), bpftool(8), bpftool-btf(8),
198 bpftool-cgroup(8), bpftool-feature(8), bpftool-gen(8),
199 bpftool-iter(8), bpftool-link(8), bpftool-map(8), bpftool-perf(8),
200 bpftool-prog(8), bpftool-struct_ops(8)
201
202
203
204
205 BPFTOOL-NET(8)