-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mohamed Mahmoud <[email protected]>
- Loading branch information
1 parent
1f2c3f7
commit 033563e
Showing
3 changed files
with
108 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
#define _GNU_SOURCE | ||
|
||
#include <errno.h> | ||
#include <linux/err.h> | ||
#include <net/if.h> | ||
#include <pthread.h> | ||
#include <stdbool.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/resource.h> | ||
#include <unistd.h> | ||
|
||
#include "test_utils.h" | ||
|
||
#include <xdp/libxdp.h> | ||
#include <bpf/libbpf.h> | ||
|
||
|
||
static void usage(char *progname) | ||
{ | ||
fprintf(stderr, "Usage: %s <ifname>\n", progname); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
static int check_link_detach(int ifindex) { | ||
struct bpf_object *obj_prog = NULL; | ||
struct bpf_program *prog; | ||
struct xdp_multiprog *mp; | ||
|
||
int ret, link; | ||
|
||
obj_prog = bpf_object__open("xdp_pass.o"); | ||
if (!obj_prog) { | ||
ret = -errno; | ||
goto out; | ||
} | ||
prog = bpf_object__find_program_by_name(obj_prog, "xdp_pass"); | ||
if (!prog) { | ||
ret = -errno; | ||
goto out; | ||
} | ||
|
||
link = bpf_link_create(bpf_program__fd(prog), 0, 0, NULL); | ||
if (link < 0) { | ||
ret = -errno; | ||
fprintf(stderr, "Couldn't create link: %s\n", strerror(-ret)); | ||
goto out; | ||
} | ||
mp = xdp_multiprog__get_from_ifindex(ifindex); | ||
ret = libxdp_get_error(mp); | ||
if (ret) { | ||
fprintf(stderr, "Couldn't get multiprog on ifindex %d: %s\n", | ||
ifindex, strerror(-ret)); | ||
goto out; | ||
} | ||
|
||
ret = xdp_multiprog__detach(mp); | ||
out: | ||
bpf_object__close(obj_prog); | ||
return ret; | ||
} | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; | ||
int ifindex; | ||
|
||
if (setrlimit(RLIMIT_MEMLOCK, &r)) { | ||
fprintf(stderr, "ERROR: setrlimit(RLIMIT_MEMLOCK) \"%s\"\n", | ||
strerror(errno)); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
char *envval; | ||
|
||
envval = secure_getenv("VERBOSE_TESTS"); | ||
|
||
silence_libbpf_logging(); | ||
if (envval && envval[0] == '1') | ||
verbose_libxdp_logging(); | ||
else | ||
silence_libxdp_logging(); | ||
|
||
if (argc != 2) | ||
usage(argv[0]); | ||
|
||
ifindex = if_nametoindex(argv[1]); | ||
if (!ifindex) { | ||
fprintf(stderr, "Interface '%s' not found.\n", argv[1]); | ||
usage(argv[0]); | ||
} | ||
|
||
return check_link_detach(ifindex); | ||
} |