Skip to content
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
6 changes: 5 additions & 1 deletion src/lib/efhw/af_xdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#define XDP_PROG_NAME "xdpsock"
#define BPF_FS_PATH "/sys/fs/bpf/"
#define XSKMAP_PIN_PREFIX BPF_FS_PATH "onload_xdp_xsk_"

static char *bpf_link_helper = NULL;
module_param(bpf_link_helper, charp, S_IRUGO | S_IWUSR);
Expand Down Expand Up @@ -953,6 +954,7 @@ __af_xdp_nic_init_hardware(struct efhw_nic *nic,
{
int map_fd, rc;
struct efhw_nic_af_xdp* xdp;
char map_path[sizeof(XSKMAP_PIN_PREFIX) + IFNAMSIZ];

xdp = kzalloc(sizeof(*xdp) +
nic->vi_lim * sizeof(struct efhw_af_xdp_vi) +
Expand All @@ -976,7 +978,9 @@ __af_xdp_nic_init_hardware(struct efhw_nic *nic,
goto fail_map;

/* Open a pre existing map if it exists, else create one */
map_fd = xdp_map_lookup(sys_call_area, BPF_FS_PATH "onload_xdp_xsk");
snprintf(map_path, sizeof(map_path), XSKMAP_PIN_PREFIX "%s",
nic->net_dev->name);
map_fd = xdp_map_lookup(sys_call_area, map_path);
if( map_fd >= 0 ) {
EFHW_NOTICE("%s: attaching to existing map", __func__);
goto has_map_and_bound_prog;
Expand Down
16 changes: 13 additions & 3 deletions src/tools/bpf_link_helper/xdp_onload_prepare.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <errno.h>
#include <error.h>
#include <linux/if_link.h>
#include <linux/limits.h>
#include <net/if.h>
#include <stdlib.h>

Expand All @@ -17,15 +18,18 @@

int main(int argc, char **argv)
{
int prog_fd, ifindex, map_path_len;
char map_path[PATH_MAX];
struct bpf_object *obj;
struct bpf_program *prog;
struct bpf_map *map_xsk;
int prog_fd, ifindex;
char *ifname;

if (argc != 3)
error(1, 0, "Usage: %s [ifname] [bpf_file]\n", argv[0]);

ifindex = if_nametoindex(argv[1]);
ifname = argv[1];
ifindex = if_nametoindex(ifname);
if (!ifindex)
error(1, errno, "if_nametoindex %s", argv[1]);

Expand Down Expand Up @@ -54,7 +58,13 @@ int main(int argc, char **argv)
if (bpf_xdp_attach(ifindex, prog_fd, XDP_FLAGS_DRV_MODE, NULL))
error(1, 0, "bpf_program__attach_xdp");

if (bpf_object__pin_maps(obj, "/sys/fs/bpf"))
map_path_len = snprintf(map_path, PATH_MAX, "/sys/fs/bpf/onload_xdp_xsk_%s", ifname);
if (map_path_len < 0)
error(1, errno, "map_path");
if (map_path_len >= PATH_MAX)
error(1, ENAMETOOLONG, "map_path");

if (bpf_map__pin(map_xsk, map_path))
error(1, 0, "bpf_object__pin_maps");

printf("OK\n");
Expand Down