-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toke Høiland-Jørgensen says: ==================== This series adds support for atomically replacing the XDP program loaded on an interface. This is achieved by means of a new netlink attribute that can specify the expected previous program to replace on the interface. If set, the kernel will compare this "expected fd" attribute with the program currently loaded on the interface, and reject the operation if it does not match. With this primitive, userspace applications can avoid stepping on each other's toes when simultaneously updating the loaded XDP program. Changelog: v4: - Switch back to passing FD instead of ID (Andrii) - Rename flag to XDP_FLAGS_REPLACE (for consistency with other similar uses) v3: - Pass existing ID instead of FD (Jakub) - Use opts struct for new libbpf function (Andrii) v2: - Fix checkpatch nits and add .strict_start_type to netlink policy (Jakub) ==================== Signed-off-by: Alexei Starovoitov <ast@kernel.org>
- Loading branch information
Showing
9 changed files
with
146 additions
and
9 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
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
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
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
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,62 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
#include <test_progs.h> | ||
|
||
#define IFINDEX_LO 1 | ||
#define XDP_FLAGS_REPLACE (1U << 4) | ||
|
||
void test_xdp_attach(void) | ||
{ | ||
struct bpf_object *obj1, *obj2, *obj3; | ||
const char *file = "./test_xdp.o"; | ||
int err, fd1, fd2, fd3; | ||
__u32 duration = 0; | ||
DECLARE_LIBBPF_OPTS(bpf_xdp_set_link_opts, opts, | ||
.old_fd = -1); | ||
|
||
err = bpf_prog_load(file, BPF_PROG_TYPE_XDP, &obj1, &fd1); | ||
if (CHECK_FAIL(err)) | ||
return; | ||
err = bpf_prog_load(file, BPF_PROG_TYPE_XDP, &obj2, &fd2); | ||
if (CHECK_FAIL(err)) | ||
goto out_1; | ||
err = bpf_prog_load(file, BPF_PROG_TYPE_XDP, &obj3, &fd3); | ||
if (CHECK_FAIL(err)) | ||
goto out_2; | ||
|
||
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd1, XDP_FLAGS_REPLACE, | ||
&opts); | ||
if (CHECK(err, "load_ok", "initial load failed")) | ||
goto out_close; | ||
|
||
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd2, XDP_FLAGS_REPLACE, | ||
&opts); | ||
if (CHECK(!err, "load_fail", "load with expected id didn't fail")) | ||
goto out; | ||
|
||
opts.old_fd = fd1; | ||
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd2, 0, &opts); | ||
if (CHECK(err, "replace_ok", "replace valid old_fd failed")) | ||
goto out; | ||
|
||
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, fd3, 0, &opts); | ||
if (CHECK(!err, "replace_fail", "replace invalid old_fd didn't fail")) | ||
goto out; | ||
|
||
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, 0, &opts); | ||
if (CHECK(!err, "remove_fail", "remove invalid old_fd didn't fail")) | ||
goto out; | ||
|
||
opts.old_fd = fd2; | ||
err = bpf_set_link_xdp_fd_opts(IFINDEX_LO, -1, 0, &opts); | ||
if (CHECK(err, "remove_ok", "remove valid old_fd failed")) | ||
goto out; | ||
|
||
out: | ||
bpf_set_link_xdp_fd(IFINDEX_LO, -1, 0); | ||
out_close: | ||
bpf_object__close(obj3); | ||
out_2: | ||
bpf_object__close(obj2); | ||
out_1: | ||
bpf_object__close(obj1); | ||
} |