Skip to content

Commit

Permalink
libxdp: Use opts-style API to create XDP socket in libxdp tests
Browse files Browse the repository at this point in the history
Signed-off-by: Muyang Tian <[email protected]>
  • Loading branch information
tacslon committed Dec 14, 2024
1 parent 48e5941 commit e96a134
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
20 changes: 11 additions & 9 deletions lib/libxdp/tests/test_xsk_non_privileged.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,22 @@ static struct xsk_socket *create_xsk_non_privileged(const char *ifname,
struct xsk_umem *umem,
int queue_id)
{
struct xsk_socket_config cfg = {
struct xsk_socket *xsk = NULL;
struct xsk_ring_cons rx;
struct xsk_ring_prod tx;

DECLARE_LIBXDP_OPTS(xsk_socket_opts, opts,
.rx = &rx,
.tx = &tx,
.rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
.tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS,
.libxdp_flags = XSK_LIBXDP_FLAGS__INHIBIT_PROG_LOAD,
.bind_flags = XDP_USE_NEED_WAKEUP,
.xdp_flags = XDP_FLAGS_UPDATE_IF_NOEXIST,
};
struct xsk_socket *xsk = NULL;
struct xsk_ring_cons rx;
struct xsk_ring_prod tx;

if (xsk_socket__create(&xsk, ifname, queue_id,
umem, &rx, &tx, &cfg) || !xsk) {
perror("xsk_socket__create failed");
);
xsk = xsk_socket__create_opts(ifname, queue_id, umem, &opts);
if (!xsk) {
perror("xsk_socket__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 @@ -125,7 +125,6 @@ static struct xsk_umem_info *xsk_configure_umem(void *buffer, u64 size)
static struct xsk_socket_info *xsk_configure_socket(struct xsk_umem_info *umem,
unsigned int qid)
{
struct xsk_socket_config cfg = {};
struct xsk_socket_info *xsk;
struct xsk_ring_cons *rxr;

Expand All @@ -134,11 +133,13 @@ static struct xsk_socket_info *xsk_configure_socket(struct xsk_umem_info *umem,
exit(EXIT_FAILURE);

xsk->umem = umem;
cfg.rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS;

rxr = &xsk->rx;
xsk_socket__create(&xsk->xsk, opt_if, qid, umem->umem,
rxr, NULL, &cfg);

DECLARE_LIBXDP_OPTS(xsk_socket_opts, opts,
.rx = rxr,
.rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS,
);
xsk->xsk = xsk_socket__create_opts(opt_if, qid, umem->umem, &opts);

return xsk;
}
Expand Down

0 comments on commit e96a134

Please sign in to comment.