bpftool-net.rst 5.6 KB

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