doc: DEVMAPs and XDP_REDIRECT
Subsystems (4)
v6 cover doc: DEVMAPs and XDP_REDIRECT
From: Maryam Tahhan <[email protected]>
Add documentation for BPF_MAP_TYPE_DEVMAP andBPF_MAP_TYPE_DEVMAP_HASH including kernel version
introduced, usage and examples.
Add documentation that describes XDP_REDIRECT.
v5->v6:
- Separate Kernel BPF and userspace functions for devmaps.
- Include some packet/tracepoint debug info in the redirect documentation.
v4->v5:
- Remove unused 'index' variable in example.
v3->v4:
- Prepend supported map section for XDP_REDIRECT documentation.
v2->v3:
- Fixed indentations in usage section to exclude non note text.
- Replace links to selftest with actual paths.
v1->v2:
- Separate xdp_redirect documentation to its own file.
- Clean up and simplify examples and usage function descriptions.
Maryam Tahhan (1):
doc: DEVMAPs and XDP_REDIRECT
Documentation/bpf/index.rst | 1 + Documentation/bpf/map_devmap.rst | 221 +++++++++++++++++++++++++++++++ Documentation/bpf/redirect.rst | 82 ++++++++++++ net/core/filter.c | 8 +- 4 files changed, 310 insertions(+), 2 deletions(-) create mode 100644 Documentation/bpf/map_devmap.rst create mode 100644 Documentation/bpf/redirect.rst
Signature · 1 line
2.35.3
PATCH v6 1/1 doc: DEVMAPs and XDP_REDIRECT
From: Maryam Tahhan <[email protected]>
Add documentation for BPF_MAP_TYPE_DEVMAP andBPF_MAP_TYPE_DEVMAP_HASH including kernel version
introduced, usage and examples.
Add documentation that describes XDP_REDIRECT.
--- Documentation/bpf/index.rst | 1 + Documentation/bpf/map_devmap.rst | 221 +++++++++++++++++++++++++++++++ Documentation/bpf/redirect.rst | 81 +++++++++++ net/core/filter.c | 8 +- 4 files changed, 309 insertions(+), 2 deletions(-) create mode 100644 Documentation/bpf/map_devmap.rst create mode 100644 Documentation/bpf/redirect.rst
Documentation/bpf/index.rst +1 -0
@@ -29,6 +29,7 @@ that goes into great technical depth about the BPF Architecture. clang-notes linux-notes other + redirect .. only:: subproject and html
Documentation/bpf/map_devmap.rst new file +221 -0
221 lines not on this page · raw message
Documentation/bpf/redirect.rst new file +81 -0
81 lines not on this page · raw message
net/core/filter.c +6 -2
@@ -4104,7 +4104,10 @@ static const struct bpf_func_proto bpf_xdp_adjust_meta_proto = { .arg2_type = ARG_ANYTHING, }; -/* XDP_REDIRECT works by a three-step process, implemented in the functions +/** +* DOC: xdp redirect +* +* XDP_REDIRECT works by a three-step process, implemented in the functions * below: * * 1. The bpf_redirect() and bpf_redirect_map() helpers will lookup the target
@@ -4119,7 +4122,8 @@ static const struct bpf_func_proto bpf_xdp_adjust_meta_proto = {* 3. Before exiting its NAPI poll loop, the driver will call xdp_do_flush(), * which will flush all the different bulk queues, thus completing the * redirect. -* +*/ +/* * Pointers to the map entries will be kept around for this whole sequence of * steps, protected by RCU. However, there is no top-level rcu_read_lock() in * the core code; instead, the RCU protection relies on everything happening
Signature · 1 line
2.35.3
Quoted 9 lines · On 11/8/22 9:48 AM, [email protected] wrote:
From: Maryam Tahhan <[email protected]>
Add documentation for
BPF_MAP_TYPE_DEVMAPandBPF_MAP_TYPE_DEVMAP_HASHincluding kernel version
introduced, usage and examples.Add documentation that describes
XDP_REDIRECT.Signed-off-by Maryam Tahhan <[email protected]>
LGTM with a couple of nits below.
Quoted 21 lines
--- Documentation/bpf/index.rst | 1 + Documentation/bpf/map_devmap.rst | 221 +++++++++++++++++++++++++++++++ Documentation/bpf/redirect.rst | 81 +++++++++++ net/core/filter.c | 8 +- 4 files changed, 309 insertions(+), 2 deletions(-)create mode 100644
Documentation/bpf/map_devmap.rstcreate mode 100644Documentation/bpf/redirect.rstDocumentation/bpf/index.rst +1
-0@@ -29,6 +29,7 @@ that goes into great technical depth about the BPF Architecture. clang-notes linux-notes other + redirect .. only:: subproject and html
[...]
Documentation/bpf/index.rst
Quoted 11 lines
Documentation/bpf/index.rst +11
-0+ +User space +---------- + +The following code snippet shows how to update a devmap called ``tx_port``. + +.. code-block:: c + + int update_devmap(int ifindex, int redirect_ifindex) + { + int ret = -1;
There is no need to initialize the value to -1, the below is 'ret = ...'.
Quoted 8 lines
Documentation/bpf/index.rst +8
-0+ + ret = bpf_map_update_elem(bpf_map__fd(tx_port), &ifindex, &redirect_ifindex, 0); + if (ret < 0) { + fprintf(stderr, "Failed to update devmap_ value: %s\n", + strerror(errno)); + } + + return ret;
Documentation/bpf/index.rst
Quoted 10 lines
Documentation/bpf/index.rst +10
-0+ } + +The following code snippet shows how to update a hash_devmap called ``forward_map``. + +.. code-block:: c + + int update_devmap(int ifindex, int redirect_ifindex) + { + struct bpf_devmap_val devmap_val = { .ifindex = redirect_ifindex }; + int ret = -1;
same here, no need to have '-1'.
Quoted 9 lines
Documentation/bpf/index.rst +9
-0+ + ret = bpf_map_update_elem(bpf_map__fd(forward_map), &ifindex, &devmap_val, 0); + if (ret < 0) { + fprintf(stderr, "Failed to update devmap_ value: %s\n", + strerror(errno)); + } + return ret; + } +
[...]