Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vagrant VM support and XDP_USE_NEED_WAKEUP for advanced03 #70

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions advanced03-AF_XDP/af_xdp_kern.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0 */

#include <linux/bpf.h>
#include <linux/version.h>

#include "bpf_helpers.h"

Expand All @@ -18,6 +19,17 @@ struct bpf_map_def SEC("maps") xdp_stats_map = {
.max_entries = 64,
};

#if LINUX_VERSION_CODE < KERNEL_VERSION(5,3,0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not the right approach to check against a kernel version.
(Because distros will backport changes)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but due to the lack of any run-time checks, what would you suggest?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead we have to write a bpf probe that can detect this (like bpftool does).
@tohojo have added a configure script in his XDP-tools repo.
In this case, we likely need to confine the check to the advanced03-AF_XDP/ directory, and we can likely add it as part of the Makefile.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configure script just sets some variables; so we can do that in the top-level and only react to them in advanced03. I've been meaning to port over some of the build stuff I did in xdp-tools to this repo anyway, so this sounds like a way forward :)


/* Kernel version before 5.3 needed an additional map */
struct bpf_map_def SEC("maps") qidconf_map = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this map referred to anywhere; how is it actually used on those old kernels?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this is part of the older libbpf installing int

.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(int),
.value_size = sizeof(int),
.max_entries = 64,
};
#endif

SEC("xdp_sock")
int xdp_sock_prog(struct xdp_md *ctx)
{
Expand Down
27 changes: 26 additions & 1 deletion advanced03-AF_XDP/af_xdp_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <unistd.h>

#include <sys/resource.h>
#include <sys/utsname.h>

#include <bpf/bpf.h>
#include <bpf/xsk.h>
Expand Down Expand Up @@ -534,6 +535,29 @@ int main(int argc, char **argv)
struct xsk_socket_info *xsk_socket;
struct bpf_object *bpf_obj = NULL;
pthread_t stats_poll_thread;
struct utsname uname_info;
unsigned int major, minor, revision;

/* Some basic version checking for AF_XDP */
if (uname(&uname_info) == -1) {
fprintf(stderr, "ERROR: failed calling uname(): %s\n",
strerror(errno));
exit(EXIT_FAILURE);
}
if (sscanf(uname_info.release, "%u.%u.%u-",
&major, &minor, &revision) != 3) {
fprintf(stderr, "ERROR: failed to extract Kernel version\n");
exit(EXIT_FAILURE);
}
if (major < 5 || (major == 5 && minor < 2)) {
printf("WARNING: For AF_XDP you need at least an upstream "
"kernel of 5.2!\n");
}
if (major == 5 && minor == 2) {
printf("WARNING: Although AF_XDP is supported in upstream "
"kernel 5.2, due to known libbpf issues it's "
"recommended to use at least version 5.3!\n");
}

/* Global shutdown handler */
signal(SIGINT, exit_application);
Expand Down Expand Up @@ -602,7 +626,8 @@ int main(int argc, char **argv)
/* Open and configure the AF_XDP (xsk) socket */
xsk_socket = xsk_configure_socket(&cfg, umem);
if (xsk_socket == NULL) {
fprintf(stderr, "ERROR: Can't setup AF_XDP socket \"%s\"\n",
fprintf(stderr, "ERROR: Can't setup AF_XDP socket \"%s\"\n"
"Make sure Kernel is build with CONFIG_XDP_SOCKETS=y\n",
strerror(errno));
exit(EXIT_FAILURE);
}
Expand Down