Skip to content

Commit

Permalink
Add pin support for xsk map (iovisor#4061)
Browse files Browse the repository at this point in the history
Add pin support for xsk map.

Signed-off-by: Y7n05h <[email protected]>
  • Loading branch information
Y7n05h committed Jul 3, 2022
1 parent d81e56c commit 5370855
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/reference_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1145,9 +1145,9 @@ Examples in situ:
### 13. BPF_XSKMAP
Syntax: ```BPF_XSKMAP(name, size)```
Syntax: ```BPF_XSKMAP(name, size [, "/sys/fs/bpf/xyz"])```

This creates a xsk map named ```name``` with ```size``` entries. Each entry represents one NIC's queue id. This map is only used in XDP to redirect packet to an AF_XDP socket. If the AF_XDP socket is binded to a queue which is different than the current packet's queue id, the packet will be dropped. For kernel v5.3 and latter, `lookup` method is available and can be used to check whether and AF_XDP socket is available for the current packet's queue id. More details at [AF_XDP](https://www.kernel.org/doc/html/latest/networking/af_xdp.html).
This creates a xsk map named ```name``` with ```size``` entries and pin it to the bpffs as a FILE. Each entry represents one NIC's queue id. This map is only used in XDP to redirect packet to an AF_XDP socket. If the AF_XDP socket is binded to a queue which is different than the current packet's queue id, the packet will be dropped. For kernel v5.3 and latter, `lookup` method is available and can be used to check whether and AF_XDP socket is available for the current packet's queue id. More details at [AF_XDP](https://www.kernel.org/doc/html/latest/networking/af_xdp.html).

For example:
```C
Expand Down
8 changes: 6 additions & 2 deletions src/cc/export/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ struct _name##_table_t _name = { .max_entries = (_max_entries) }
#define BPF_CPUMAP(_name, _max_entries) \
BPF_XDP_REDIRECT_MAP("cpumap", u32, _name, _max_entries)

#define BPF_XSKMAP(_name, _max_entries) \
#define _BPF_XSKMAP(_name, _max_entries, _pinned) \
struct _name##_table_t { \
u32 key; \
int leaf; \
Expand All @@ -399,8 +399,12 @@ struct _name##_table_t { \
u64 (*redirect_map) (int, int); \
u32 max_entries; \
}; \
__attribute__((section("maps/xskmap"))) \
__attribute__((section("maps/xskmap" _pinned))) \
struct _name##_table_t _name = { .max_entries = (_max_entries) }
#define BPF_XSKMAP2(_name, _max_entries) _BPF_XSKMAP(_name, _max_entries, "")
#define BPF_XSKMAP3(_name, _max_entries, _pinned) _BPF_XSKMAP(_name, _max_entries, ":" _pinned)
#define BPF_XSKMAPX(_1, _2, _3, NAME, ...) NAME
#define BPF_XSKMAP(...) BPF_XSKMAPX(__VA_ARGS__, BPF_XSKMAP3, BPF_XSKMAP2)(__VA_ARGS__)

#define BPF_ARRAY_OF_MAPS(_name, _inner_map_name, _max_entries) \
BPF_TABLE("array_of_maps$" _inner_map_name, int, int, _name, _max_entries)
Expand Down

0 comments on commit 5370855

Please sign in to comment.