1 // SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
4 * AF_XDP user-space access library.
6 * Copyright(c) 2018 - 2019 Intel Corporation.
8 * Author(s): Magnus Karlsson <magnus.karlsson@intel.com>
15 #include <arpa/inet.h>
16 #include <asm/barrier.h>
17 #include <linux/compiler.h>
18 #include <linux/ethtool.h>
19 #include <linux/filter.h>
20 #include <linux/if_ether.h>
21 #include <linux/if_packet.h>
22 #include <linux/if_xdp.h>
23 #include <linux/kernel.h>
24 #include <linux/list.h>
25 #include <linux/sockios.h>
27 #include <sys/ioctl.h>
29 #include <sys/socket.h>
30 #include <sys/types.h>
34 #include "libbpf_internal.h"
50 struct xsk_ring_prod *fill_save;
51 struct xsk_ring_cons *comp_save;
53 struct xsk_umem_config config;
56 struct list_head ctx_list;
57 bool rx_ring_setup_done;
58 bool tx_ring_setup_done;
62 struct xsk_ring_prod *fill;
63 struct xsk_ring_cons *comp;
65 struct xsk_umem *umem;
68 struct list_head list;
71 char ifname[IFNAMSIZ];
75 struct xsk_ring_cons *rx;
76 struct xsk_ring_prod *tx;
79 struct xsk_socket_config config;
84 bool xdp_prog_attached;
89 /* Up until and including Linux 5.3 */
90 struct xdp_ring_offset_v1 {
96 /* Up until and including Linux 5.3 */
97 struct xdp_mmap_offsets_v1 {
98 struct xdp_ring_offset_v1 rx;
99 struct xdp_ring_offset_v1 tx;
100 struct xdp_ring_offset_v1 fr;
101 struct xdp_ring_offset_v1 cr;
104 int xsk_umem__fd(const struct xsk_umem *umem)
106 return umem ? umem->fd : -EINVAL;
109 int xsk_socket__fd(const struct xsk_socket *xsk)
111 return xsk ? xsk->fd : -EINVAL;
114 static bool xsk_page_aligned(void *buffer)
116 unsigned long addr = (unsigned long)buffer;
118 return !(addr & (getpagesize() - 1));
121 static void xsk_set_umem_config(struct xsk_umem_config *cfg,
122 const struct xsk_umem_config *usr_cfg)
125 cfg->fill_size = XSK_RING_PROD__DEFAULT_NUM_DESCS;
126 cfg->comp_size = XSK_RING_CONS__DEFAULT_NUM_DESCS;
127 cfg->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
128 cfg->frame_headroom = XSK_UMEM__DEFAULT_FRAME_HEADROOM;
129 cfg->flags = XSK_UMEM__DEFAULT_FLAGS;
133 cfg->fill_size = usr_cfg->fill_size;
134 cfg->comp_size = usr_cfg->comp_size;
135 cfg->frame_size = usr_cfg->frame_size;
136 cfg->frame_headroom = usr_cfg->frame_headroom;
137 cfg->flags = usr_cfg->flags;
140 static int xsk_set_xdp_socket_config(struct xsk_socket_config *cfg,
141 const struct xsk_socket_config *usr_cfg)
144 cfg->rx_size = XSK_RING_CONS__DEFAULT_NUM_DESCS;
145 cfg->tx_size = XSK_RING_PROD__DEFAULT_NUM_DESCS;
146 cfg->libbpf_flags = 0;
152 if (usr_cfg->libbpf_flags & ~XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD)
155 cfg->rx_size = usr_cfg->rx_size;
156 cfg->tx_size = usr_cfg->tx_size;
157 cfg->libbpf_flags = usr_cfg->libbpf_flags;
158 cfg->xdp_flags = usr_cfg->xdp_flags;
159 cfg->bind_flags = usr_cfg->bind_flags;
164 static void xsk_mmap_offsets_v1(struct xdp_mmap_offsets *off)
166 struct xdp_mmap_offsets_v1 off_v1;
168 /* getsockopt on a kernel <= 5.3 has no flags fields.
169 * Copy over the offsets to the correct places in the >=5.4 format
170 * and put the flags where they would have been on that kernel.
172 memcpy(&off_v1, off, sizeof(off_v1));
174 off->rx.producer = off_v1.rx.producer;
175 off->rx.consumer = off_v1.rx.consumer;
176 off->rx.desc = off_v1.rx.desc;
177 off->rx.flags = off_v1.rx.consumer + sizeof(__u32);
179 off->tx.producer = off_v1.tx.producer;
180 off->tx.consumer = off_v1.tx.consumer;
181 off->tx.desc = off_v1.tx.desc;
182 off->tx.flags = off_v1.tx.consumer + sizeof(__u32);
184 off->fr.producer = off_v1.fr.producer;
185 off->fr.consumer = off_v1.fr.consumer;
186 off->fr.desc = off_v1.fr.desc;
187 off->fr.flags = off_v1.fr.consumer + sizeof(__u32);
189 off->cr.producer = off_v1.cr.producer;
190 off->cr.consumer = off_v1.cr.consumer;
191 off->cr.desc = off_v1.cr.desc;
192 off->cr.flags = off_v1.cr.consumer + sizeof(__u32);
195 static int xsk_get_mmap_offsets(int fd, struct xdp_mmap_offsets *off)
200 optlen = sizeof(*off);
201 err = getsockopt(fd, SOL_XDP, XDP_MMAP_OFFSETS, off, &optlen);
205 if (optlen == sizeof(*off))
208 if (optlen == sizeof(struct xdp_mmap_offsets_v1)) {
209 xsk_mmap_offsets_v1(off);
216 static int xsk_create_umem_rings(struct xsk_umem *umem, int fd,
217 struct xsk_ring_prod *fill,
218 struct xsk_ring_cons *comp)
220 struct xdp_mmap_offsets off;
224 err = setsockopt(fd, SOL_XDP, XDP_UMEM_FILL_RING,
225 &umem->config.fill_size,
226 sizeof(umem->config.fill_size));
230 err = setsockopt(fd, SOL_XDP, XDP_UMEM_COMPLETION_RING,
231 &umem->config.comp_size,
232 sizeof(umem->config.comp_size));
236 err = xsk_get_mmap_offsets(fd, &off);
240 map = mmap(NULL, off.fr.desc + umem->config.fill_size * sizeof(__u64),
241 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd,
242 XDP_UMEM_PGOFF_FILL_RING);
243 if (map == MAP_FAILED)
246 fill->mask = umem->config.fill_size - 1;
247 fill->size = umem->config.fill_size;
248 fill->producer = map + off.fr.producer;
249 fill->consumer = map + off.fr.consumer;
250 fill->flags = map + off.fr.flags;
251 fill->ring = map + off.fr.desc;
252 fill->cached_cons = umem->config.fill_size;
254 map = mmap(NULL, off.cr.desc + umem->config.comp_size * sizeof(__u64),
255 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE, fd,
256 XDP_UMEM_PGOFF_COMPLETION_RING);
257 if (map == MAP_FAILED) {
262 comp->mask = umem->config.comp_size - 1;
263 comp->size = umem->config.comp_size;
264 comp->producer = map + off.cr.producer;
265 comp->consumer = map + off.cr.consumer;
266 comp->flags = map + off.cr.flags;
267 comp->ring = map + off.cr.desc;
272 munmap(map, off.fr.desc + umem->config.fill_size * sizeof(__u64));
276 int xsk_umem__create_v0_0_4(struct xsk_umem **umem_ptr, void *umem_area,
277 __u64 size, struct xsk_ring_prod *fill,
278 struct xsk_ring_cons *comp,
279 const struct xsk_umem_config *usr_config)
281 struct xdp_umem_reg mr;
282 struct xsk_umem *umem;
285 if (!umem_area || !umem_ptr || !fill || !comp)
287 if (!size && !xsk_page_aligned(umem_area))
290 umem = calloc(1, sizeof(*umem));
294 umem->fd = socket(AF_XDP, SOCK_RAW, 0);
300 umem->umem_area = umem_area;
301 INIT_LIST_HEAD(&umem->ctx_list);
302 xsk_set_umem_config(&umem->config, usr_config);
304 memset(&mr, 0, sizeof(mr));
305 mr.addr = (uintptr_t)umem_area;
307 mr.chunk_size = umem->config.frame_size;
308 mr.headroom = umem->config.frame_headroom;
309 mr.flags = umem->config.flags;
311 err = setsockopt(umem->fd, SOL_XDP, XDP_UMEM_REG, &mr, sizeof(mr));
317 err = xsk_create_umem_rings(umem, umem->fd, fill, comp);
321 umem->fill_save = fill;
322 umem->comp_save = comp;
333 struct xsk_umem_config_v1 {
337 __u32 frame_headroom;
340 int xsk_umem__create_v0_0_2(struct xsk_umem **umem_ptr, void *umem_area,
341 __u64 size, struct xsk_ring_prod *fill,
342 struct xsk_ring_cons *comp,
343 const struct xsk_umem_config *usr_config)
345 struct xsk_umem_config config;
347 memcpy(&config, usr_config, sizeof(struct xsk_umem_config_v1));
350 return xsk_umem__create_v0_0_4(umem_ptr, umem_area, size, fill, comp,
353 COMPAT_VERSION(xsk_umem__create_v0_0_2, xsk_umem__create, LIBBPF_0.0.2)
354 DEFAULT_VERSION(xsk_umem__create_v0_0_4, xsk_umem__create, LIBBPF_0.0.4)
356 static int xsk_load_xdp_prog(struct xsk_socket *xsk)
358 static const int log_buf_size = 16 * 1024;
359 struct xsk_ctx *ctx = xsk->ctx;
360 char log_buf[log_buf_size];
363 /* This is the C-program:
364 * SEC("xdp_sock") int xdp_sock_prog(struct xdp_md *ctx)
366 * int ret, index = ctx->rx_queue_index;
368 * // A set entry here means that the correspnding queue_id
369 * // has an active AF_XDP socket bound to it.
370 * ret = bpf_redirect_map(&xsks_map, index, XDP_PASS);
374 * // Fallback for pre-5.3 kernels, not supporting default
375 * // action in the flags parameter.
376 * if (bpf_map_lookup_elem(&xsks_map, &index))
377 * return bpf_redirect_map(&xsks_map, index, 0);
381 struct bpf_insn prog[] = {
382 /* r2 = *(u32 *)(r1 + 16) */
383 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_1, 16),
384 /* *(u32 *)(r10 - 4) = r2 */
385 BPF_STX_MEM(BPF_W, BPF_REG_10, BPF_REG_2, -4),
387 BPF_LD_MAP_FD(BPF_REG_1, ctx->xsks_map_fd),
389 BPF_MOV64_IMM(BPF_REG_3, 2),
390 /* call bpf_redirect_map */
391 BPF_EMIT_CALL(BPF_FUNC_redirect_map),
392 /* if w0 != 0 goto pc+13 */
393 BPF_JMP32_IMM(BPF_JSGT, BPF_REG_0, 0, 13),
395 BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
397 BPF_ALU64_IMM(BPF_ADD, BPF_REG_2, -4),
399 BPF_LD_MAP_FD(BPF_REG_1, ctx->xsks_map_fd),
400 /* call bpf_map_lookup_elem */
401 BPF_EMIT_CALL(BPF_FUNC_map_lookup_elem),
403 BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
405 BPF_MOV64_IMM(BPF_REG_0, 2),
406 /* if r1 == 0 goto pc+5 */
407 BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 0, 5),
408 /* r2 = *(u32 *)(r10 - 4) */
409 BPF_LDX_MEM(BPF_W, BPF_REG_2, BPF_REG_10, -4),
411 BPF_LD_MAP_FD(BPF_REG_1, ctx->xsks_map_fd),
413 BPF_MOV64_IMM(BPF_REG_3, 0),
414 /* call bpf_redirect_map */
415 BPF_EMIT_CALL(BPF_FUNC_redirect_map),
416 /* The jumps are to this instruction */
419 size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);
421 prog_fd = bpf_load_program(BPF_PROG_TYPE_XDP, prog, insns_cnt,
422 "LGPL-2.1 or BSD-2-Clause", 0, log_buf,
425 pr_warn("BPF log buffer:\n%s", log_buf);
429 err = bpf_set_link_xdp_fd(xsk->ctx->ifindex, prog_fd,
430 xsk->config.xdp_flags);
436 ctx->prog_fd = prog_fd;
440 static int xsk_get_max_queues(struct xsk_socket *xsk)
442 struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
443 struct xsk_ctx *ctx = xsk->ctx;
444 struct ifreq ifr = {};
447 fd = socket(AF_INET, SOCK_DGRAM, 0);
451 ifr.ifr_data = (void *)&channels;
452 memcpy(ifr.ifr_name, ctx->ifname, IFNAMSIZ - 1);
453 ifr.ifr_name[IFNAMSIZ - 1] = '\0';
454 err = ioctl(fd, SIOCETHTOOL, &ifr);
455 if (err && errno != EOPNOTSUPP) {
461 /* If the device says it has no channels, then all traffic
462 * is sent to a single stream, so max queues = 1.
466 /* Take the max of rx, tx, combined. Drivers return
467 * the number of channels in different ways.
469 ret = max(channels.max_rx, channels.max_tx);
470 ret = max(ret, (int)channels.max_combined);
478 static int xsk_create_bpf_maps(struct xsk_socket *xsk)
480 struct xsk_ctx *ctx = xsk->ctx;
484 max_queues = xsk_get_max_queues(xsk);
488 fd = bpf_create_map_name(BPF_MAP_TYPE_XSKMAP, "xsks_map",
489 sizeof(int), sizeof(int), max_queues, 0);
493 ctx->xsks_map_fd = fd;
498 static void xsk_delete_bpf_maps(struct xsk_socket *xsk)
500 struct xsk_ctx *ctx = xsk->ctx;
502 bpf_map_delete_elem(ctx->xsks_map_fd, &ctx->queue_id);
503 close(ctx->xsks_map_fd);
506 static int xsk_lookup_bpf_maps(struct xsk_socket *xsk)
508 __u32 i, *map_ids, num_maps, prog_len = sizeof(struct bpf_prog_info);
509 __u32 map_len = sizeof(struct bpf_map_info);
510 struct bpf_prog_info prog_info = {};
511 struct xsk_ctx *ctx = xsk->ctx;
512 struct bpf_map_info map_info;
515 err = bpf_obj_get_info_by_fd(ctx->prog_fd, &prog_info, &prog_len);
519 num_maps = prog_info.nr_map_ids;
521 map_ids = calloc(prog_info.nr_map_ids, sizeof(*map_ids));
525 memset(&prog_info, 0, prog_len);
526 prog_info.nr_map_ids = num_maps;
527 prog_info.map_ids = (__u64)(unsigned long)map_ids;
529 err = bpf_obj_get_info_by_fd(ctx->prog_fd, &prog_info, &prog_len);
533 ctx->xsks_map_fd = -1;
535 for (i = 0; i < prog_info.nr_map_ids; i++) {
536 fd = bpf_map_get_fd_by_id(map_ids[i]);
540 memset(&map_info, 0, map_len);
541 err = bpf_obj_get_info_by_fd(fd, &map_info, &map_len);
547 if (!strncmp(map_info.name, "xsks_map", sizeof(map_info.name))) {
548 ctx->xsks_map_fd = fd;
556 if (ctx->xsks_map_fd == -1)
564 static int xsk_set_bpf_maps(struct xsk_socket *xsk)
566 struct xsk_ctx *ctx = xsk->ctx;
568 return bpf_map_update_elem(ctx->xsks_map_fd, &ctx->queue_id,
572 static int xsk_setup_xdp_prog(struct xsk_socket *xsk)
574 struct xsk_ctx *ctx = xsk->ctx;
578 err = bpf_get_link_xdp_id(ctx->ifindex, &prog_id,
579 xsk->config.xdp_flags);
584 err = xsk_create_bpf_maps(xsk);
588 err = xsk_load_xdp_prog(xsk);
590 xsk_delete_bpf_maps(xsk);
594 ctx->prog_fd = bpf_prog_get_fd_by_id(prog_id);
595 if (ctx->prog_fd < 0)
597 err = xsk_lookup_bpf_maps(xsk);
605 err = xsk_set_bpf_maps(xsk);
607 xsk_delete_bpf_maps(xsk);
615 static struct xsk_ctx *xsk_get_ctx(struct xsk_umem *umem, int ifindex,
620 if (list_empty(&umem->ctx_list))
623 list_for_each_entry(ctx, &umem->ctx_list, list) {
624 if (ctx->ifindex == ifindex && ctx->queue_id == queue_id) {
633 static void xsk_put_ctx(struct xsk_ctx *ctx, bool unmap)
635 struct xsk_umem *umem = ctx->umem;
636 struct xdp_mmap_offsets off;
645 err = xsk_get_mmap_offsets(umem->fd, &off);
649 munmap(ctx->fill->ring - off.fr.desc, off.fr.desc + umem->config.fill_size *
651 munmap(ctx->comp->ring - off.cr.desc, off.cr.desc + umem->config.comp_size *
655 list_del(&ctx->list);
659 static struct xsk_ctx *xsk_create_ctx(struct xsk_socket *xsk,
660 struct xsk_umem *umem, int ifindex,
661 const char *ifname, __u32 queue_id,
662 struct xsk_ring_prod *fill,
663 struct xsk_ring_cons *comp)
668 ctx = calloc(1, sizeof(*ctx));
672 if (!umem->fill_save) {
673 err = xsk_create_umem_rings(umem, xsk->fd, fill, comp);
678 } else if (umem->fill_save != fill || umem->comp_save != comp) {
679 /* Copy over rings to new structs. */
680 memcpy(fill, umem->fill_save, sizeof(*fill));
681 memcpy(comp, umem->comp_save, sizeof(*comp));
684 ctx->ifindex = ifindex;
687 ctx->queue_id = queue_id;
688 memcpy(ctx->ifname, ifname, IFNAMSIZ - 1);
689 ctx->ifname[IFNAMSIZ - 1] = '\0';
693 list_add(&ctx->list, &umem->ctx_list);
697 int xsk_socket__create_shared(struct xsk_socket **xsk_ptr,
699 __u32 queue_id, struct xsk_umem *umem,
700 struct xsk_ring_cons *rx,
701 struct xsk_ring_prod *tx,
702 struct xsk_ring_prod *fill,
703 struct xsk_ring_cons *comp,
704 const struct xsk_socket_config *usr_config)
706 bool unmap, rx_setup_done = false, tx_setup_done = false;
707 void *rx_map = NULL, *tx_map = NULL;
708 struct sockaddr_xdp sxdp = {};
709 struct xdp_mmap_offsets off;
710 struct xsk_socket *xsk;
714 if (!umem || !xsk_ptr || !(rx || tx))
717 unmap = umem->fill_save != fill;
719 xsk = calloc(1, sizeof(*xsk));
723 err = xsk_set_xdp_socket_config(&xsk->config, usr_config);
727 xsk->outstanding_tx = 0;
728 ifindex = if_nametoindex(ifname);
734 if (umem->refcount++ > 0) {
735 xsk->fd = socket(AF_XDP, SOCK_RAW, 0);
742 rx_setup_done = umem->rx_ring_setup_done;
743 tx_setup_done = umem->tx_ring_setup_done;
746 ctx = xsk_get_ctx(umem, ifindex, queue_id);
748 if (!fill || !comp) {
753 ctx = xsk_create_ctx(xsk, umem, ifindex, ifname, queue_id,
762 if (rx && !rx_setup_done) {
763 err = setsockopt(xsk->fd, SOL_XDP, XDP_RX_RING,
764 &xsk->config.rx_size,
765 sizeof(xsk->config.rx_size));
770 if (xsk->fd == umem->fd)
771 umem->rx_ring_setup_done = true;
773 if (tx && !tx_setup_done) {
774 err = setsockopt(xsk->fd, SOL_XDP, XDP_TX_RING,
775 &xsk->config.tx_size,
776 sizeof(xsk->config.tx_size));
781 if (xsk->fd == umem->fd)
782 umem->tx_ring_setup_done = true;
785 err = xsk_get_mmap_offsets(xsk->fd, &off);
792 rx_map = mmap(NULL, off.rx.desc +
793 xsk->config.rx_size * sizeof(struct xdp_desc),
794 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE,
795 xsk->fd, XDP_PGOFF_RX_RING);
796 if (rx_map == MAP_FAILED) {
801 rx->mask = xsk->config.rx_size - 1;
802 rx->size = xsk->config.rx_size;
803 rx->producer = rx_map + off.rx.producer;
804 rx->consumer = rx_map + off.rx.consumer;
805 rx->flags = rx_map + off.rx.flags;
806 rx->ring = rx_map + off.rx.desc;
807 rx->cached_prod = *rx->producer;
808 rx->cached_cons = *rx->consumer;
813 tx_map = mmap(NULL, off.tx.desc +
814 xsk->config.tx_size * sizeof(struct xdp_desc),
815 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_POPULATE,
816 xsk->fd, XDP_PGOFF_TX_RING);
817 if (tx_map == MAP_FAILED) {
822 tx->mask = xsk->config.tx_size - 1;
823 tx->size = xsk->config.tx_size;
824 tx->producer = tx_map + off.tx.producer;
825 tx->consumer = tx_map + off.tx.consumer;
826 tx->flags = tx_map + off.tx.flags;
827 tx->ring = tx_map + off.tx.desc;
828 tx->cached_prod = *tx->producer;
829 /* cached_cons is r->size bigger than the real consumer pointer
830 * See xsk_prod_nb_free
832 tx->cached_cons = *tx->consumer + xsk->config.tx_size;
836 sxdp.sxdp_family = PF_XDP;
837 sxdp.sxdp_ifindex = ctx->ifindex;
838 sxdp.sxdp_queue_id = ctx->queue_id;
839 if (umem->refcount > 1) {
840 sxdp.sxdp_flags |= XDP_SHARED_UMEM;
841 sxdp.sxdp_shared_umem_fd = umem->fd;
843 sxdp.sxdp_flags = xsk->config.bind_flags;
846 err = bind(xsk->fd, (struct sockaddr *)&sxdp, sizeof(sxdp));
852 if (!(xsk->config.libbpf_flags & XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD)) {
853 err = xsk_setup_xdp_prog(xsk);
859 umem->fill_save = NULL;
860 umem->comp_save = NULL;
865 munmap(tx_map, off.tx.desc +
866 xsk->config.tx_size * sizeof(struct xdp_desc));
869 munmap(rx_map, off.rx.desc +
870 xsk->config.rx_size * sizeof(struct xdp_desc));
872 xsk_put_ctx(ctx, unmap);
874 if (--umem->refcount)
881 int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
882 __u32 queue_id, struct xsk_umem *umem,
883 struct xsk_ring_cons *rx, struct xsk_ring_prod *tx,
884 const struct xsk_socket_config *usr_config)
889 return xsk_socket__create_shared(xsk_ptr, ifname, queue_id, umem,
890 rx, tx, umem->fill_save,
891 umem->comp_save, usr_config);
894 int xsk_umem__delete(struct xsk_umem *umem)
896 struct xdp_mmap_offsets off;
905 err = xsk_get_mmap_offsets(umem->fd, &off);
906 if (!err && umem->fill_save && umem->comp_save) {
907 munmap(umem->fill_save->ring - off.fr.desc,
908 off.fr.desc + umem->config.fill_size * sizeof(__u64));
909 munmap(umem->comp_save->ring - off.cr.desc,
910 off.cr.desc + umem->config.comp_size * sizeof(__u64));
919 void xsk_socket__delete(struct xsk_socket *xsk)
921 size_t desc_sz = sizeof(struct xdp_desc);
922 struct xdp_mmap_offsets off;
923 struct xsk_umem *umem;
933 if (ctx->refcount == 1) {
934 xsk_delete_bpf_maps(xsk);
938 xsk_put_ctx(ctx, true);
940 err = xsk_get_mmap_offsets(xsk->fd, &off);
943 munmap(xsk->rx->ring - off.rx.desc,
944 off.rx.desc + xsk->config.rx_size * desc_sz);
947 munmap(xsk->tx->ring - off.tx.desc,
948 off.tx.desc + xsk->config.tx_size * desc_sz);
953 /* Do not close an fd that also has an associated umem connected
956 if (xsk->fd != umem->fd)