forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples/bpf: Add XDP_SHARED_UMEM support to xdpsock
Add support for the XDP_SHARED_UMEM mode to the xdpsock sample application. As libbpf does not have a built in XDP program for this mode, we use an explicitly loaded XDP program. This also serves as an example on how to write your own XDP program that can route to an AF_XDP socket. Signed-off-by: Magnus Karlsson <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Tested-by: William Tu <[email protected]> Acked-by: Jonathan Lemon <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
- Loading branch information
1 parent
cbf0740
commit 2e5d72c
Showing
4 changed files
with
135 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 | ||
* | ||
* Copyright(c) 2019 Intel Corporation. | ||
*/ | ||
|
||
#ifndef XDPSOCK_H_ | ||
#define XDPSOCK_H_ | ||
|
||
#define MAX_SOCKS 4 | ||
|
||
#endif /* XDPSOCK_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <linux/bpf.h> | ||
#include "bpf_helpers.h" | ||
#include "xdpsock.h" | ||
|
||
/* This XDP program is only needed for the XDP_SHARED_UMEM mode. | ||
* If you do not use this mode, libbpf can supply an XDP program for you. | ||
*/ | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_XSKMAP); | ||
__uint(max_entries, MAX_SOCKS); | ||
__uint(key_size, sizeof(int)); | ||
__uint(value_size, sizeof(int)); | ||
} xsks_map SEC(".maps"); | ||
|
||
static unsigned int rr; | ||
|
||
SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx) | ||
{ | ||
rr = (rr + 1) & (MAX_SOCKS - 1); | ||
|
||
return bpf_redirect_map(&xsks_map, rr, XDP_DROP); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters