1 .. SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
6 -------------------------------------------------------------------------------
7 tool for inspection of netdev/tc related bpf prog attachments
8 -------------------------------------------------------------------------------
12 .. include:: substitutions.rst
17 **bpftool** [*OPTIONS*] **net** *COMMAND*
19 *OPTIONS* := { |COMMON_OPTIONS| }
22 { **show** | **list** | **attach** | **detach** | **help** }
27 | **bpftool** **net** { **show** | **list** } [ **dev** *NAME* ]
28 | **bpftool** **net attach** *ATTACH_TYPE* *PROG* **dev** *NAME* [ **overwrite** ]
29 | **bpftool** **net detach** *ATTACH_TYPE* **dev** *NAME*
30 | **bpftool** **net help**
32 | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
33 | *ATTACH_TYPE* := { **xdp** | **xdpgeneric** | **xdpdrv** | **xdpoffload** }
37 **bpftool net { show | list }** [ **dev** *NAME* ]
38 List bpf program attachments in the kernel networking subsystem.
40 Currently, only device driver xdp attachments and tc filter
41 classification/action attachments are implemented, i.e., for
42 program types **BPF_PROG_TYPE_SCHED_CLS**,
43 **BPF_PROG_TYPE_SCHED_ACT** and **BPF_PROG_TYPE_XDP**.
44 For programs attached to a particular cgroup, e.g.,
45 **BPF_PROG_TYPE_CGROUP_SKB**, **BPF_PROG_TYPE_CGROUP_SOCK**,
46 **BPF_PROG_TYPE_SOCK_OPS** and **BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
47 users can use **bpftool cgroup** to dump cgroup attachments.
48 For sk_{filter, skb, msg, reuseport} and lwt/seg6
49 bpf programs, users should consult other tools, e.g., iproute2.
51 The current output will start with all xdp program attachments, followed by
52 all tc class/qdisc bpf program attachments. Both xdp programs and
53 tc programs are ordered based on ifindex number. If multiple bpf
54 programs attached to the same networking device through **tc filter**,
55 the order will be first all bpf programs attached to tc classes, then
56 all bpf programs attached to non clsact qdiscs, and finally all
57 bpf programs attached to root and clsact qdisc.
59 **bpftool** **net attach** *ATTACH_TYPE* *PROG* **dev** *NAME* [ **overwrite** ]
60 Attach bpf program *PROG* to network interface *NAME* with
61 type specified by *ATTACH_TYPE*. Previously attached bpf program
62 can be replaced by the command used with **overwrite** option.
63 Currently, only XDP-related modes are supported for *ATTACH_TYPE*.
65 *ATTACH_TYPE* can be of:
66 **xdp** - try native XDP and fallback to generic XDP if NIC driver does not support it;
67 **xdpgeneric** - Generic XDP. runs at generic XDP hook when packet already enters receive path as skb;
68 **xdpdrv** - Native XDP. runs earliest point in driver's receive path;
69 **xdpoffload** - Offload XDP. runs directly on NIC on each packet reception;
71 **bpftool** **net detach** *ATTACH_TYPE* **dev** *NAME*
72 Detach bpf program attached to network interface *NAME* with
73 type specified by *ATTACH_TYPE*. To detach bpf program, same
74 *ATTACH_TYPE* previously used for attach must be specified.
75 Currently, only XDP-related modes are supported for *ATTACH_TYPE*.
78 Print short help message.
82 .. include:: common_options.rst
95 eth0(2) htb name prefix_matcher.o:[cls_prefix_matcher_htb] id 111727 act []
96 eth0(2) clsact/ingress fbflow_icmp id 130246 act []
97 eth0(2) clsact/egress prefix_matcher.o:[cls_prefix_matcher_clsact] id 111726
98 eth0(2) clsact/egress cls_fg_dscp id 108619 act []
99 eth0(2) clsact/egress fbflow_egress id 130245
102 | **# bpftool -jp net**
118 "name": "prefix_matcher.o:[cls_prefix_matcher_htb]",
124 "kind": "clsact/ingress",
125 "name": "fbflow_icmp",
131 "kind": "clsact/egress",
132 "name": "prefix_matcher.o:[cls_prefix_matcher_clsact]",
137 "kind": "clsact/egress",
138 "name": "cls_fg_dscp",
144 "kind": "clsact/egress",
145 "name": "fbflow_egress",
153 | **# bpftool net attach xdpdrv id 16 dev enp6s0np0**
159 enp6s0np0(4) driver id 16
162 | **# bpftool net attach xdpdrv id 16 dev enp6s0np0**
163 | **# bpftool net attach xdpdrv id 20 dev enp6s0np0 overwrite**
169 enp6s0np0(4) driver id 20
172 | **# bpftool net attach xdpdrv id 16 dev enp6s0np0**
173 | **# bpftool net detach xdpdrv dev enp6s0np0**