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

libxdp: Use opts-style API to create umem in libxdp tests #461

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 19 additions & 11 deletions lib/libxdp/tests/test_xsk_non_privileged.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ static void run_non_privileged_preconfig(const char *ifname,

static struct xsk_umem *create_umem_non_privileged(int sock_fd)
{
struct xsk_umem_config config = {
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
};
struct xsk_umem *umem = NULL;
struct xsk_ring_cons cq;
struct xsk_ring_prod fq;
Expand All @@ -107,16 +102,29 @@ static struct xsk_umem *create_umem_non_privileged(int sock_fd)
}

/* This variant requires CAP_NET_RAW, so should fail. */
if (!xsk_umem__create(&umem, b, UMEM_SIZE,
&fq, &cq, &config) || umem) {
perror("xsk_umem__create succeeded");
DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts_cap,
.size = UMEM_SIZE,
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
);
umem = xsk_umem__create_opts(b, &fq, &cq, &opts_cap);
if (umem) {
perror("xsk_umem__create_opts succeeded");
exit(EXIT_FAILURE);
}

/* This variant shouldn't need any capabilities, so should pass. */
if (xsk_umem__create_with_fd(&umem, sock_fd, b, UMEM_SIZE,
&fq, &cq, &config) || !umem) {
perror("xsk_umem__create_with_fd failed");
DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts,
.fd = sock_fd,
.size = UMEM_SIZE,
.fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
.frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE,
);
umem = xsk_umem__create_opts(b, &fq, &cq, &opts);
if (!umem) {
perror("xsk_umem__create_opts failed");
exit(EXIT_FAILURE);
}

Expand Down
11 changes: 6 additions & 5 deletions lib/libxdp/tests/test_xsk_refcnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,17 @@ static struct xsk_socket_info *xsks[MAX_NUM_QUEUES];
static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
{
struct xsk_umem_info *umem;
int ret;

umem = calloc(1, sizeof(*umem));
if (!umem)
exit(EXIT_FAILURE);

ret = xsk_umem__create(&umem->umem, buffer, size, &umem->fq, &umem->cq,
NULL);
if (ret)
exit(ret);
DECLARE_LIBXDP_OPTS(xsk_umem_opts, opts,
.size = size,
);
umem->umem = xsk_umem__create_opts(buffer, &umem->fq, &umem->cq, &opts);
if (!umem->umem)
exit(errno);

umem->buffer = buffer;
return umem;
Expand Down