#include <linux/ethtool.h>
#include <linux/sockios.h>
#include "af_xdp_deps.h"
-#include <bpf/bpf.h>
#include <rte_ethdev.h>
#include <ethdev_driver.h>
static int
load_custom_xdp_prog(const char *prog_path, int if_index, struct bpf_map **map)
{
- int ret, prog_fd = -1;
+ int ret, prog_fd;
struct bpf_object *obj;
- ret = bpf_prog_load(prog_path, BPF_PROG_TYPE_XDP, &obj, &prog_fd);
- if (ret) {
+ prog_fd = load_program(prog_path, &obj);
+ if (prog_fd < 0) {
AF_XDP_LOG(ERR, "Failed to load program %s\n", prog_path);
- return ret;
+ return -1;
}
/*
return -ENOMEM;
txq->umem = rxq->umem;
+#if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
+ ret = rte_pktmbuf_alloc_bulk(rxq->umem->mb_pool, fq_bufs, reserve_size);
+ if (ret) {
+ AF_XDP_LOG(DEBUG, "Failed to get enough buffers for fq.\n");
+ goto out_umem;
+ }
+#endif
+
+ ret = reserve_fill_queue(rxq->umem, reserve_size, fq_bufs, &rxq->fq);
+ if (ret) {
+ AF_XDP_LOG(ERR, "Failed to reserve fill queue.\n");
+ goto out_umem;
+ }
+
cfg.rx_size = ring_size;
cfg.tx_size = ring_size;
cfg.libbpf_flags = 0;
if (ret) {
AF_XDP_LOG(ERR, "Failed to load custom XDP program %s\n",
internals->prog_path);
- goto err;
+ goto out_umem;
}
internals->custom_prog_configured = 1;
cfg.libbpf_flags = XSK_LIBBPF_FLAGS__INHIBIT_PROG_LOAD;
if (ret) {
AF_XDP_LOG(ERR, "Failed to create xsk socket.\n");
- goto err;
+ goto out_umem;
}
/* insert the xsk into the xsks_map */
&rxq->xsk_queue_idx, &fd, 0);
if (err) {
AF_XDP_LOG(ERR, "Failed to insert xsk in map.\n");
- goto err;
+ goto out_xsk;
}
}
-#if defined(XDP_UMEM_UNALIGNED_CHUNK_FLAG)
- ret = rte_pktmbuf_alloc_bulk(rxq->umem->mb_pool, fq_bufs, reserve_size);
- if (ret) {
- AF_XDP_LOG(DEBUG, "Failed to get enough buffers for fq.\n");
- goto err;
- }
-#endif
-
if (rxq->busy_budget) {
ret = configure_preferred_busy_poll(rxq);
if (ret) {
AF_XDP_LOG(ERR, "Failed configure busy polling.\n");
- goto err;
+ goto out_xsk;
}
}
- ret = reserve_fill_queue(rxq->umem, reserve_size, fq_bufs, &rxq->fq);
- if (ret) {
- xsk_socket__delete(rxq->xsk);
- AF_XDP_LOG(ERR, "Failed to reserve fill queue.\n");
- goto err;
- }
-
return 0;
-err:
+out_xsk:
+ xsk_socket__delete(rxq->xsk);
+out_umem:
if (__atomic_sub_fetch(&rxq->umem->refcnt, 1, __ATOMIC_ACQUIRE) == 0)
xdp_umem_destroy(rxq->umem);