Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 89b97607 authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by David S. Miller
Browse files

samples/bpf: add map_flags to bpf loader



note old loader is compatible with new kernel.
map_flags are optional

Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3622e7e4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ struct bpf_map_def {
	unsigned int key_size;
	unsigned int value_size;
	unsigned int max_entries;
	unsigned int map_flags;
};

static int (*bpf_skb_store_bytes)(void *ctx, int off, void *from, int len, int flags) =
+2 −1
Original line number Diff line number Diff line
@@ -157,7 +157,8 @@ static int load_maps(struct bpf_map_def *maps, int len)
		map_fd[i] = bpf_create_map(maps[i].type,
					   maps[i].key_size,
					   maps[i].value_size,
					   maps[i].max_entries);
					   maps[i].max_entries,
					   maps[i].map_flags);
		if (map_fd[i] < 0) {
			printf("failed to create a map: %d %s\n",
			       errno, strerror(errno));
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ static void usage(void)
static int bpf_map_create(void)
{
	return bpf_create_map(BPF_MAP_TYPE_ARRAY, sizeof(uint32_t),
			      sizeof(uint32_t), 1024);
			      sizeof(uint32_t), 1024, 0);
}

static int bpf_prog_create(const char *object)
+3 −2
Original line number Diff line number Diff line
@@ -19,13 +19,14 @@ static __u64 ptr_to_u64(void *ptr)
}

int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
		   int max_entries)
		   int max_entries, int map_flags)
{
	union bpf_attr attr = {
		.map_type = map_type,
		.key_size = key_size,
		.value_size = value_size,
		.max_entries = max_entries
		.max_entries = max_entries,
		.map_flags = map_flags,
	};

	return syscall(__NR_bpf, BPF_MAP_CREATE, &attr, sizeof(attr));
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
struct bpf_insn;

int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size,
		   int max_entries);
		   int max_entries, int map_flags);
int bpf_update_elem(int fd, void *key, void *value, unsigned long long flags);
int bpf_lookup_elem(int fd, void *key, void *value);
int bpf_delete_elem(int fd, void *key);
Loading