1.. SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 3================ 4bpftool-net 5================ 6------------------------------------------------------------------------------- 7tool for inspection of networking related bpf prog attachments 8------------------------------------------------------------------------------- 9 10:Manual section: 8 11 12.. include:: substitutions.rst 13 14SYNOPSIS 15======== 16 17**bpftool** [*OPTIONS*] **net** *COMMAND* 18 19*OPTIONS* := { |COMMON_OPTIONS| } 20 21*COMMANDS* := { **show** | **list** | **attach** | **detach** | **help** } 22 23NET COMMANDS 24============ 25 26| **bpftool** **net** { **show** | **list** } [ **dev** *NAME* ] 27| **bpftool** **net attach** *ATTACH_TYPE* *PROG* **dev** *NAME* [ **overwrite** ] 28| **bpftool** **net detach** *ATTACH_TYPE* **dev** *NAME* 29| **bpftool** **net help** 30| 31| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *PROG_NAME* } 32| *ATTACH_TYPE* := { **xdp** | **xdpgeneric** | **xdpdrv** | **xdpoffload** } 33 34DESCRIPTION 35=========== 36bpftool net { show | list } [ dev *NAME* ] 37 List bpf program attachments in the kernel networking subsystem. 38 39 Currently, device driver xdp attachments, tcx, netkit and old-style tc 40 classifier/action attachments, flow_dissector as well as netfilter 41 attachments are implemented, i.e., for program types **BPF_PROG_TYPE_XDP**, 42 **BPF_PROG_TYPE_SCHED_CLS**, **BPF_PROG_TYPE_SCHED_ACT**, 43 **BPF_PROG_TYPE_FLOW_DISSECTOR**, **BPF_PROG_TYPE_NETFILTER**. 44 45 For programs attached to a particular cgroup, e.g., 46 **BPF_PROG_TYPE_CGROUP_SKB**, **BPF_PROG_TYPE_CGROUP_SOCK**, 47 **BPF_PROG_TYPE_SOCK_OPS** and **BPF_PROG_TYPE_CGROUP_SOCK_ADDR**, users 48 can use **bpftool cgroup** to dump cgroup attachments. For sk_{filter, skb, 49 msg, reuseport} and lwt/seg6 bpf programs, users should consult other 50 tools, e.g., iproute2. 51 52 The current output will start with all xdp program attachments, followed by 53 all tcx, netkit, then tc class/qdisc bpf program attachments, then 54 flow_dissector and finally netfilter programs. Both xdp programs and 55 tcx/netkit/tc programs are ordered based on ifindex number. If multiple bpf 56 programs attached to the same networking device through **tc**, the order 57 will be first all bpf programs attached to tcx, netkit, then tc classes, 58 then all bpf programs attached to non clsact qdiscs, and finally all bpf 59 programs attached to root and clsact qdisc. 60 61bpftool net attach *ATTACH_TYPE* *PROG* dev *NAME* [ overwrite ] 62 Attach bpf program *PROG* to network interface *NAME* with type specified 63 by *ATTACH_TYPE*. Previously attached bpf program can be replaced by the 64 command used with **overwrite** option. Currently, only XDP-related modes 65 are supported for *ATTACH_TYPE*. 66 67 *ATTACH_TYPE* can be of: 68 **xdp** - try native XDP and fallback to generic XDP if NIC driver does not support it; 69 **xdpgeneric** - Generic XDP. runs at generic XDP hook when packet already enters receive path as skb; 70 **xdpdrv** - Native XDP. runs earliest point in driver's receive path; 71 **xdpoffload** - Offload XDP. runs directly on NIC on each packet reception; 72 73bpftool net detach *ATTACH_TYPE* dev *NAME* 74 Detach bpf program attached to network interface *NAME* with type specified 75 by *ATTACH_TYPE*. To detach bpf program, same *ATTACH_TYPE* previously used 76 for attach must be specified. Currently, only XDP-related modes are 77 supported for *ATTACH_TYPE*. 78 79bpftool net help 80 Print short help message. 81 82OPTIONS 83======= 84.. include:: common_options.rst 85 86EXAMPLES 87======== 88 89| **# bpftool net** 90 91:: 92 93 xdp: 94 eth0(2) driver id 198 95 96 tc: 97 eth0(2) htb name prefix_matcher.o:[cls_prefix_matcher_htb] id 111727 act [] 98 eth0(2) clsact/ingress fbflow_icmp id 130246 act [] 99 eth0(2) clsact/egress prefix_matcher.o:[cls_prefix_matcher_clsact] id 111726 100 eth0(2) clsact/egress cls_fg_dscp id 108619 act [] 101 eth0(2) clsact/egress fbflow_egress id 130245 102 103| 104| **# bpftool -jp net** 105 106:: 107 108 [{ 109 "xdp": [{ 110 "devname": "eth0", 111 "ifindex": 2, 112 "mode": "driver", 113 "id": 198 114 } 115 ], 116 "tc": [{ 117 "devname": "eth0", 118 "ifindex": 2, 119 "kind": "htb", 120 "name": "prefix_matcher.o:[cls_prefix_matcher_htb]", 121 "id": 111727, 122 "act": [] 123 },{ 124 "devname": "eth0", 125 "ifindex": 2, 126 "kind": "clsact/ingress", 127 "name": "fbflow_icmp", 128 "id": 130246, 129 "act": [] 130 },{ 131 "devname": "eth0", 132 "ifindex": 2, 133 "kind": "clsact/egress", 134 "name": "prefix_matcher.o:[cls_prefix_matcher_clsact]", 135 "id": 111726, 136 },{ 137 "devname": "eth0", 138 "ifindex": 2, 139 "kind": "clsact/egress", 140 "name": "cls_fg_dscp", 141 "id": 108619, 142 "act": [] 143 },{ 144 "devname": "eth0", 145 "ifindex": 2, 146 "kind": "clsact/egress", 147 "name": "fbflow_egress", 148 "id": 130245, 149 } 150 ] 151 } 152 ] 153 154| 155| **# bpftool net attach xdpdrv id 16 dev enp6s0np0** 156| **# bpftool net** 157 158:: 159 160 xdp: 161 enp6s0np0(4) driver id 16 162 163| 164| **# bpftool net attach xdpdrv id 16 dev enp6s0np0** 165| **# bpftool net attach xdpdrv id 20 dev enp6s0np0 overwrite** 166| **# bpftool net** 167 168:: 169 170 xdp: 171 enp6s0np0(4) driver id 20 172 173| 174| **# bpftool net attach xdpdrv id 16 dev enp6s0np0** 175| **# bpftool net detach xdpdrv dev enp6s0np0** 176| **# bpftool net** 177 178:: 179 180 xdp: 181