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