bpftool-net.rst (5773B)
1.. SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 3================ 4bpftool-net 5================ 6------------------------------------------------------------------------------- 7tool for inspection of netdev/tc 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* := 22 { **show** | **list** | **attach** | **detach** | **help** } 23 24NET COMMANDS 25============ 26 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** 31| 32| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* } 33| *ATTACH_TYPE* := { **xdp** | **xdpgeneric** | **xdpdrv** | **xdpoffload** } 34 35DESCRIPTION 36=========== 37 **bpftool net { show | list }** [ **dev** *NAME* ] 38 List bpf program attachments in the kernel networking subsystem. 39 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. 50 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. 58 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*. 64 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; 70 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*. 76 77 **bpftool net help** 78 Print short help message. 79 80OPTIONS 81======= 82 .. include:: common_options.rst 83 84EXAMPLES 85======== 86 87| **# bpftool net** 88 89:: 90 91 xdp: 92 eth0(2) driver id 198 93 94 tc: 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 100 101| 102| **# bpftool -jp net** 103 104:: 105 106 [{ 107 "xdp": [{ 108 "devname": "eth0", 109 "ifindex": 2, 110 "mode": "driver", 111 "id": 198 112 } 113 ], 114 "tc": [{ 115 "devname": "eth0", 116 "ifindex": 2, 117 "kind": "htb", 118 "name": "prefix_matcher.o:[cls_prefix_matcher_htb]", 119 "id": 111727, 120 "act": [] 121 },{ 122 "devname": "eth0", 123 "ifindex": 2, 124 "kind": "clsact/ingress", 125 "name": "fbflow_icmp", 126 "id": 130246, 127 "act": [] 128 },{ 129 "devname": "eth0", 130 "ifindex": 2, 131 "kind": "clsact/egress", 132 "name": "prefix_matcher.o:[cls_prefix_matcher_clsact]", 133 "id": 111726, 134 },{ 135 "devname": "eth0", 136 "ifindex": 2, 137 "kind": "clsact/egress", 138 "name": "cls_fg_dscp", 139 "id": 108619, 140 "act": [] 141 },{ 142 "devname": "eth0", 143 "ifindex": 2, 144 "kind": "clsact/egress", 145 "name": "fbflow_egress", 146 "id": 130245, 147 } 148 ] 149 } 150 ] 151 152| 153| **# bpftool net attach xdpdrv id 16 dev enp6s0np0** 154| **# bpftool net** 155 156:: 157 158 xdp: 159 enp6s0np0(4) driver id 16 160 161| 162| **# bpftool net attach xdpdrv id 16 dev enp6s0np0** 163| **# bpftool net attach xdpdrv id 20 dev enp6s0np0 overwrite** 164| **# bpftool net** 165 166:: 167 168 xdp: 169 enp6s0np0(4) driver id 20 170 171| 172| **# bpftool net attach xdpdrv id 16 dev enp6s0np0** 173| **# bpftool net detach xdpdrv dev enp6s0np0** 174| **# bpftool net** 175 176:: 177 178 xdp: