Skip to content

Commit 1491607

Browse files
committed
libxdp: add device binding support
Kernel 6.3 supported for some NIC offloads for XDP programs. The feature in XDP is known to be XDP hints. XDP hints are only supported if the XDP program is bound to the NIC device using the BPF_F_XDP_DEV_BOUND_ONLY binding flag. The device binding flag is represented through `XDP_ATTACH_DEVBIND', a new attach flag for `xdp_program__attach`. Device binding is propagated to the dispatcher. Any subsequent programs attachments are rejected if they are different from the already running dispatcher on a network interface. The flag is recored using a new variable in `struct xdp_dispatcher_config`. Signed-off-by: Jalal Mostafa <[email protected]>
1 parent 47f5260 commit 1491607

File tree

5 files changed

+178
-34
lines changed

5 files changed

+178
-34
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ compile_commands.json
6666

6767
# BPF skeleton files
6868
*.skel.h
69+
70+
.vscode

headers/xdp/libxdp.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ extern "C" {
2323
#define XDP_BPFFS_MOUNT_ENVVAR "LIBXDP_BPFFS_AUTOMOUNT"
2424
#define XDP_OBJECT_ENVVAR "LIBXDP_OBJECT_PATH"
2525

26+
#define XDP_ATTACH_DEVBIND (1 << 0)
27+
#define XDP_ATTACH_FLAGS (XDP_ATTACH_DEVBIND)
28+
2629
enum xdp_attach_mode {
2730
XDP_MODE_UNSPEC = 0,
2831
XDP_MODE_NATIVE,
@@ -116,6 +119,7 @@ struct xdp_program *xdp_multiprog__hw_prog(const struct xdp_multiprog *mp);
116119
bool xdp_multiprog__is_legacy(const struct xdp_multiprog *mp);
117120
int xdp_multiprog__program_count(const struct xdp_multiprog *mp);
118121
bool xdp_multiprog__xdp_frags_support(const struct xdp_multiprog *mp);
122+
bool xdp_multiprog__xdp_dev_bound(const struct xdp_multiprog *mp);
119123

120124
/* Only following members can be set at once:
121125
*

headers/xdp/prog_dispatcher.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <linux/types.h>
77

88
#define XDP_METADATA_SECTION "xdp_metadata"
9-
#define XDP_DISPATCHER_VERSION 2
9+
#define XDP_DISPATCHER_VERSION 3
1010

1111
/* magic byte is 'X' + 'D' + 'P' (88+68+80=236) */
1212
#define XDP_DISPATCHER_MAGIC 236
@@ -29,6 +29,7 @@ struct xdp_dispatcher_config {
2929
__u32 chain_call_actions[MAX_DISPATCHER_ACTIONS];
3030
__u32 run_prios[MAX_DISPATCHER_ACTIONS];
3131
__u32 program_flags[MAX_DISPATCHER_ACTIONS];
32+
__u8 is_xdp_devbound; /* Whether this dispatcher is bounded to a device */
3233
};
3334

3435
#endif

0 commit comments

Comments
 (0)