Commit e232cb6f authored by Daniel Borkmann's avatar Daniel Borkmann

Merge branch 'bpf-libbpf-int-btf-map'

Andrii Nakryiko says:

====================
This patch set implements an update to how BTF-defined maps are specified. The
change is in how integer attributes, e.g., type, max_entries, map_flags, are
specified: now they are captured as part of map definition struct's BTF type
information (using array dimension), eliminating the need for compile-time
data initialization and keeping all the metadata in one place.

All existing selftests that were using BTF-defined maps are updated, along
with some other selftests, that were switched to new syntax.

v4->v5:
- revert sample_map_ret0.c, which is loaded with iproute2 (kernel test robot);
v3->v4:
- add acks;
- fix int -> uint type in commit message;
v2->v3:
- rename __int into __uint (Yonghong);
v1->v2:
- split bpf_helpers.h change from libbpf change (Song).
====================
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parents c5f48c92 1639b17c
...@@ -1029,40 +1029,40 @@ static const struct btf_type *skip_mods_and_typedefs(const struct btf *btf, ...@@ -1029,40 +1029,40 @@ static const struct btf_type *skip_mods_and_typedefs(const struct btf *btf,
} }
} }
static bool get_map_field_int(const char *map_name, /*
const struct btf *btf, * Fetch integer attribute of BTF map definition. Such attributes are
* represented using a pointer to an array, in which dimensionality of array
* encodes specified integer value. E.g., int (*type)[BPF_MAP_TYPE_ARRAY];
* encodes `type => BPF_MAP_TYPE_ARRAY` key/value pair completely using BTF
* type definition, while using only sizeof(void *) space in ELF data section.
*/
static bool get_map_field_int(const char *map_name, const struct btf *btf,
const struct btf_type *def, const struct btf_type *def,
const struct btf_member *m, const struct btf_member *m, __u32 *res) {
const void *data, __u32 *res) {
const struct btf_type *t = skip_mods_and_typedefs(btf, m->type); const struct btf_type *t = skip_mods_and_typedefs(btf, m->type);
const char *name = btf__name_by_offset(btf, m->name_off); const char *name = btf__name_by_offset(btf, m->name_off);
__u32 int_info = *(const __u32 *)(const void *)(t + 1); const struct btf_array *arr_info;
const struct btf_type *arr_t;
if (BTF_INFO_KIND(t->info) != BTF_KIND_INT) { if (BTF_INFO_KIND(t->info) != BTF_KIND_PTR) {
pr_warning("map '%s': attr '%s': expected INT, got %u.\n", pr_warning("map '%s': attr '%s': expected PTR, got %u.\n",
map_name, name, BTF_INFO_KIND(t->info)); map_name, name, BTF_INFO_KIND(t->info));
return false; return false;
} }
if (t->size != 4 || BTF_INT_BITS(int_info) != 32 ||
BTF_INT_OFFSET(int_info)) { arr_t = btf__type_by_id(btf, t->type);
pr_warning("map '%s': attr '%s': expected 32-bit non-bitfield integer, " if (!arr_t) {
"got %u-byte (%d-bit) one with bit offset %d.\n", pr_warning("map '%s': attr '%s': type [%u] not found.\n",
map_name, name, t->size, BTF_INT_BITS(int_info), map_name, name, t->type);
BTF_INT_OFFSET(int_info));
return false;
}
if (BTF_INFO_KFLAG(def->info) && BTF_MEMBER_BITFIELD_SIZE(m->offset)) {
pr_warning("map '%s': attr '%s': bitfield is not supported.\n",
map_name, name);
return false; return false;
} }
if (m->offset % 32) { if (BTF_INFO_KIND(arr_t->info) != BTF_KIND_ARRAY) {
pr_warning("map '%s': attr '%s': unaligned fields are not supported.\n", pr_warning("map '%s': attr '%s': expected ARRAY, got %u.\n",
map_name, name); map_name, name, BTF_INFO_KIND(arr_t->info));
return false; return false;
} }
arr_info = (const void *)(arr_t + 1);
*res = *(const __u32 *)(data + m->offset / 8); *res = arr_info->nelems;
return true; return true;
} }
...@@ -1075,7 +1075,6 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1075,7 +1075,6 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
const struct btf_var_secinfo *vi; const struct btf_var_secinfo *vi;
const struct btf_var *var_extra; const struct btf_var *var_extra;
const struct btf_member *m; const struct btf_member *m;
const void *def_data;
const char *map_name; const char *map_name;
struct bpf_map *map; struct bpf_map *map;
int vlen, i; int vlen, i;
...@@ -1132,7 +1131,6 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1132,7 +1131,6 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
pr_debug("map '%s': at sec_idx %d, offset %zu.\n", pr_debug("map '%s': at sec_idx %d, offset %zu.\n",
map_name, map->sec_idx, map->sec_offset); map_name, map->sec_idx, map->sec_offset);
def_data = data->d_buf + vi->offset;
vlen = BTF_INFO_VLEN(def->info); vlen = BTF_INFO_VLEN(def->info);
m = (const void *)(def + 1); m = (const void *)(def + 1);
for (i = 0; i < vlen; i++, m++) { for (i = 0; i < vlen; i++, m++) {
...@@ -1145,19 +1143,19 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1145,19 +1143,19 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
} }
if (strcmp(name, "type") == 0) { if (strcmp(name, "type") == 0) {
if (!get_map_field_int(map_name, obj->btf, def, m, if (!get_map_field_int(map_name, obj->btf, def, m,
def_data, &map->def.type)) &map->def.type))
return -EINVAL; return -EINVAL;
pr_debug("map '%s': found type = %u.\n", pr_debug("map '%s': found type = %u.\n",
map_name, map->def.type); map_name, map->def.type);
} else if (strcmp(name, "max_entries") == 0) { } else if (strcmp(name, "max_entries") == 0) {
if (!get_map_field_int(map_name, obj->btf, def, m, if (!get_map_field_int(map_name, obj->btf, def, m,
def_data, &map->def.max_entries)) &map->def.max_entries))
return -EINVAL; return -EINVAL;
pr_debug("map '%s': found max_entries = %u.\n", pr_debug("map '%s': found max_entries = %u.\n",
map_name, map->def.max_entries); map_name, map->def.max_entries);
} else if (strcmp(name, "map_flags") == 0) { } else if (strcmp(name, "map_flags") == 0) {
if (!get_map_field_int(map_name, obj->btf, def, m, if (!get_map_field_int(map_name, obj->btf, def, m,
def_data, &map->def.map_flags)) &map->def.map_flags))
return -EINVAL; return -EINVAL;
pr_debug("map '%s': found map_flags = %u.\n", pr_debug("map '%s': found map_flags = %u.\n",
map_name, map->def.map_flags); map_name, map->def.map_flags);
...@@ -1165,7 +1163,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1165,7 +1163,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
__u32 sz; __u32 sz;
if (!get_map_field_int(map_name, obj->btf, def, m, if (!get_map_field_int(map_name, obj->btf, def, m,
def_data, &sz)) &sz))
return -EINVAL; return -EINVAL;
pr_debug("map '%s': found key_size = %u.\n", pr_debug("map '%s': found key_size = %u.\n",
map_name, sz); map_name, sz);
...@@ -1208,7 +1206,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, ...@@ -1208,7 +1206,7 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
__u32 sz; __u32 sz;
if (!get_map_field_int(map_name, obj->btf, def, m, if (!get_map_field_int(map_name, obj->btf, def, m,
def_data, &sz)) &sz))
return -EINVAL; return -EINVAL;
pr_debug("map '%s': found value_size = %u.\n", pr_debug("map '%s': found value_size = %u.\n",
map_name, sz); map_name, sz);
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
*/ */
#define SEC(NAME) __attribute__((section(NAME), used)) #define SEC(NAME) __attribute__((section(NAME), used))
#define __uint(name, val) int (*name)[val]
#define __type(name, val) val *name
/* helper macro to print out debug messages */ /* helper macro to print out debug messages */
#define bpf_printk(fmt, ...) \ #define bpf_printk(fmt, ...) \
({ \ ({ \
......
...@@ -58,26 +58,18 @@ struct frag_hdr { ...@@ -58,26 +58,18 @@ struct frag_hdr {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
__u32 max_entries; __uint(max_entries, 8);
__u32 key_size; __uint(key_size, sizeof(__u32));
__u32 value_size; __uint(value_size, sizeof(__u32));
} jmp_table SEC(".maps") = { } jmp_table SEC(".maps");
.type = BPF_MAP_TYPE_PROG_ARRAY,
.max_entries = 8,
.key_size = sizeof(__u32),
.value_size = sizeof(__u32),
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
struct bpf_flow_keys *value; __type(value, struct bpf_flow_keys);
} last_dissection SEC(".maps") = { } last_dissection SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 1,
};
static __always_inline int export_flow_keys(struct bpf_flow_keys *keys, static __always_inline int export_flow_keys(struct bpf_flow_keys *keys,
int ret) int ret)
......
...@@ -4,19 +4,19 @@ ...@@ -4,19 +4,19 @@
#include <linux/bpf.h> #include <linux/bpf.h>
#include "bpf_helpers.h" #include "bpf_helpers.h"
struct bpf_map_def SEC("maps") cg_ids = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(__u32), __uint(max_entries, 1);
.value_size = sizeof(__u64), __type(key, __u32);
.max_entries = 1, __type(value, __u64);
}; } cg_ids SEC(".maps");
struct bpf_map_def SEC("maps") pidmap = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(__u32), __uint(max_entries, 1);
.value_size = sizeof(__u32), __type(key, __u32);
.max_entries = 1, __type(value, __u32);
}; } pidmap SEC(".maps");
SEC("tracepoint/syscalls/sys_enter_nanosleep") SEC("tracepoint/syscalls/sys_enter_nanosleep")
int trace(void *ctx) int trace(void *ctx)
......
...@@ -11,20 +11,16 @@ ...@@ -11,20 +11,16 @@
#define NS_PER_SEC 1000000000 #define NS_PER_SEC 1000000000
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE);
struct bpf_cgroup_storage_key *key; __type(key, struct bpf_cgroup_storage_key);
struct percpu_net_cnt *value; __type(value, struct percpu_net_cnt);
} percpu_netcnt SEC(".maps") = { } percpu_netcnt SEC(".maps");
.type = BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
struct bpf_cgroup_storage_key *key; __type(key, struct bpf_cgroup_storage_key);
struct net_cnt *value; __type(value, struct net_cnt);
} netcnt SEC(".maps") = { } netcnt SEC(".maps");
.type = BPF_MAP_TYPE_CGROUP_STORAGE,
};
SEC("cgroup/skb") SEC("cgroup/skb")
int bpf_nextcnt(struct __sk_buff *skb) int bpf_nextcnt(struct __sk_buff *skb)
......
...@@ -58,14 +58,6 @@ typedef struct { ...@@ -58,14 +58,6 @@ typedef struct {
} Event; } Event;
struct bpf_elf_map {
__u32 type;
__u32 size_key;
__u32 size_value;
__u32 max_elem;
__u32 flags;
};
typedef int pid_t; typedef int pid_t;
typedef struct { typedef struct {
...@@ -118,47 +110,47 @@ static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData, ...@@ -118,47 +110,47 @@ static __always_inline bool get_frame_data(void *frame_ptr, PidData *pidData,
return true; return true;
} }
struct bpf_elf_map SEC("maps") pidmap = { struct {
.type = BPF_MAP_TYPE_HASH, __uint(type, BPF_MAP_TYPE_HASH);
.size_key = sizeof(int), __uint(max_entries, 1);
.size_value = sizeof(PidData), __type(key, int);
.max_elem = 1, __type(value, PidData);
}; } pidmap SEC(".maps");
struct bpf_elf_map SEC("maps") eventmap = { struct {
.type = BPF_MAP_TYPE_HASH, __uint(type, BPF_MAP_TYPE_HASH);
.size_key = sizeof(int), __uint(max_entries, 1);
.size_value = sizeof(Event), __type(key, int);
.max_elem = 1, __type(value, Event);
}; } eventmap SEC(".maps");
struct bpf_elf_map SEC("maps") symbolmap = { struct {
.type = BPF_MAP_TYPE_HASH, __uint(type, BPF_MAP_TYPE_HASH);
.size_key = sizeof(Symbol), __uint(max_entries, 1);
.size_value = sizeof(int), __type(key, Symbol);
.max_elem = 1, __type(value, int);
}; } symbolmap SEC(".maps");
struct bpf_elf_map SEC("maps") statsmap = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.size_key = sizeof(Stats), __uint(max_entries, 1);
.size_value = sizeof(int), __type(key, int);
.max_elem = 1, __type(value, Stats);
}; } statsmap SEC(".maps");
struct bpf_elf_map SEC("maps") perfmap = { struct {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
.size_key = sizeof(int), __uint(max_entries, 32);
.size_value = sizeof(int), __uint(key_size, sizeof(int));
.max_elem = 32, __uint(value_size, sizeof(int));
}; } perfmap SEC(".maps");
struct bpf_elf_map SEC("maps") stackmap = { struct {
.type = BPF_MAP_TYPE_STACK_TRACE, __uint(type, BPF_MAP_TYPE_STACK_TRACE);
.size_key = sizeof(int), __uint(max_entries, 1000);
.size_value = sizeof(long long) * 127, __uint(key_size, sizeof(int));
.max_elem = 1000, __uint(value_size, sizeof(long long) * 127);
}; } stackmap SEC(".maps");
static __always_inline int __on_event(struct pt_regs *ctx) static __always_inline int __on_event(struct pt_regs *ctx)
{ {
......
...@@ -13,14 +13,11 @@ struct socket_cookie { ...@@ -13,14 +13,11 @@ struct socket_cookie {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_SK_STORAGE);
__u32 map_flags; __uint(map_flags, BPF_F_NO_PREALLOC);
int *key; __type(key, int);
struct socket_cookie *value; __type(value, struct socket_cookie);
} socket_cookies SEC(".maps") = { } socket_cookies SEC(".maps");
.type = BPF_MAP_TYPE_SK_STORAGE,
.map_flags = BPF_F_NO_PREALLOC,
};
SEC("cgroup/connect6") SEC("cgroup/connect6")
int set_cookie(struct bpf_sock_addr *ctx) int set_cookie(struct bpf_sock_addr *ctx)
......
...@@ -4,33 +4,33 @@ ...@@ -4,33 +4,33 @@
int _version SEC("version") = 1; int _version SEC("version") = 1;
struct bpf_map_def SEC("maps") sock_map_rx = { struct {
.type = BPF_MAP_TYPE_SOCKMAP, __uint(type, BPF_MAP_TYPE_SOCKMAP);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map_rx SEC(".maps");
struct bpf_map_def SEC("maps") sock_map_tx = { struct {
.type = BPF_MAP_TYPE_SOCKMAP, __uint(type, BPF_MAP_TYPE_SOCKMAP);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map_tx SEC(".maps");
struct bpf_map_def SEC("maps") sock_map_msg = { struct {
.type = BPF_MAP_TYPE_SOCKMAP, __uint(type, BPF_MAP_TYPE_SOCKMAP);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map_msg SEC(".maps");
struct bpf_map_def SEC("maps") sock_map_break = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __type(key, int);
.max_entries = 20, __type(value, int);
}; } sock_map_break SEC(".maps");
SEC("sk_skb2") SEC("sk_skb2")
int bpf_prog2(struct __sk_buff *skb) int bpf_prog2(struct __sk_buff *skb)
......
...@@ -204,40 +204,40 @@ struct strobelight_bpf_sample { ...@@ -204,40 +204,40 @@ struct strobelight_bpf_sample {
char dummy_safeguard; char dummy_safeguard;
}; };
struct bpf_map_def SEC("maps") samples = { struct {
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY, __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 32);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 32, __uint(value_size, sizeof(int));
}; } samples SEC(".maps");
struct bpf_map_def SEC("maps") stacks_0 = { struct {
.type = BPF_MAP_TYPE_STACK_TRACE, __uint(type, BPF_MAP_TYPE_STACK_TRACE);
.key_size = sizeof(uint32_t), __uint(max_entries, 16);
.value_size = sizeof(uint64_t) * PERF_MAX_STACK_DEPTH, __uint(key_size, sizeof(uint32_t));
.max_entries = 16, __uint(value_size, sizeof(uint64_t) * PERF_MAX_STACK_DEPTH);
}; } stacks_0 SEC(".maps");
struct bpf_map_def SEC("maps") stacks_1 = { struct {
.type = BPF_MAP_TYPE_STACK_TRACE, __uint(type, BPF_MAP_TYPE_STACK_TRACE);
.key_size = sizeof(uint32_t), __uint(max_entries, 16);
.value_size = sizeof(uint64_t) * PERF_MAX_STACK_DEPTH, __uint(key_size, sizeof(uint32_t));
.max_entries = 16, __uint(value_size, sizeof(uint64_t) * PERF_MAX_STACK_DEPTH);
}; } stacks_1 SEC(".maps");
struct bpf_map_def SEC("maps") sample_heap = { struct {
.type = BPF_MAP_TYPE_PERCPU_ARRAY, __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
.key_size = sizeof(uint32_t), __uint(max_entries, 1);
.value_size = sizeof(struct strobelight_bpf_sample), __type(key, uint32_t);
.max_entries = 1, __type(value, struct strobelight_bpf_sample);
}; } sample_heap SEC(".maps");
struct bpf_map_def SEC("maps") strobemeta_cfgs = { struct {
.type = BPF_MAP_TYPE_PERCPU_ARRAY, __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
.key_size = sizeof(pid_t), __uint(max_entries, STROBE_MAX_CFGS);
.value_size = sizeof(struct strobemeta_cfg), __type(key, pid_t);
.max_entries = STROBE_MAX_CFGS, __type(value, struct strobemeta_cfg);
}; } strobemeta_cfgs SEC(".maps");
/* Type for the dtv. */ /* Type for the dtv. */
/* https://github.com/lattera/glibc/blob/master/nptl/sysdeps/x86_64/tls.h#L34 */ /* https://github.com/lattera/glibc/blob/master/nptl/sysdeps/x86_64/tls.h#L34 */
......
...@@ -21,14 +21,11 @@ struct bpf_map_def SEC("maps") btf_map_legacy = { ...@@ -21,14 +21,11 @@ struct bpf_map_def SEC("maps") btf_map_legacy = {
BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts); BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts);
struct { struct {
int *key; __uint(type, BPF_MAP_TYPE_ARRAY);
struct ipv_counts *value; __uint(max_entries, 4);
unsigned int type; __type(key, int);
unsigned int max_entries; __type(value, struct ipv_counts);
} btf_map SEC(".maps") = { } btf_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 4,
};
struct dummy_tracepoint_args { struct dummy_tracepoint_args {
unsigned long long pad; unsigned long long pad;
......
...@@ -16,26 +16,18 @@ struct stack_trace_t { ...@@ -16,26 +16,18 @@ struct stack_trace_t {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__u32 max_entries; __uint(max_entries, 2);
__u32 key_size; __uint(key_size, sizeof(int));
__u32 value_size; __uint(value_size, sizeof(__u32));
} perfmap SEC(".maps") = { } perfmap SEC(".maps");
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.max_entries = 2,
.key_size = sizeof(int),
.value_size = sizeof(__u32),
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
struct stack_trace_t *value; __type(value, struct stack_trace_t);
} stackdata_map SEC(".maps") = { } stackdata_map SEC(".maps");
.type = BPF_MAP_TYPE_PERCPU_ARRAY,
.max_entries = 1,
};
/* Allocate per-cpu space twice the needed. For the code below /* Allocate per-cpu space twice the needed. For the code below
* usize = bpf_get_stack(ctx, raw_data, max_len, BPF_F_USER_STACK); * usize = bpf_get_stack(ctx, raw_data, max_len, BPF_F_USER_STACK);
...@@ -56,14 +48,11 @@ struct { ...@@ -56,14 +48,11 @@ struct {
* This is an acceptable workaround since there is one entry here. * This is an acceptable workaround since there is one entry here.
*/ */
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
__u64 (*value)[2 * MAX_STACK_RAWTP]; __u64 (*value)[2 * MAX_STACK_RAWTP];
} rawdata_map SEC(".maps") = { } rawdata_map SEC(".maps");
.type = BPF_MAP_TYPE_PERCPU_ARRAY,
.max_entries = 1,
};
SEC("tracepoint/raw_syscalls/sys_enter") SEC("tracepoint/raw_syscalls/sys_enter")
int bpf_prog1(void *ctx) int bpf_prog1(void *ctx)
......
...@@ -8,24 +8,18 @@ ...@@ -8,24 +8,18 @@
#include "bpf_helpers.h" #include "bpf_helpers.h"
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 11);
__u32 *key; __type(key, __u32);
__u64 *value; __type(value, __u64);
} result_number SEC(".maps") = { } result_number SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 11,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 5);
__u32 *key; __type(key, __u32);
const char (*value)[32]; const char (*value)[32];
} result_string SEC(".maps") = { } result_string SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 5,
};
struct foo { struct foo {
__u8 a; __u8 a;
...@@ -34,14 +28,11 @@ struct foo { ...@@ -34,14 +28,11 @@ struct foo {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 5);
__u32 *key; __type(key, __u32);
struct foo *value; __type(value, struct foo);
} result_struct SEC(".maps") = { } result_struct SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 5,
};
/* Relocation tests for __u64s. */ /* Relocation tests for __u64s. */
static __u64 num0; static __u64 num0;
......
...@@ -170,54 +170,39 @@ struct eth_hdr { ...@@ -170,54 +170,39 @@ struct eth_hdr {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_HASH);
__u32 max_entries; __uint(max_entries, MAX_VIPS);
struct vip *key; __type(key, struct vip);
struct vip_meta *value; __type(value, struct vip_meta);
} vip_map SEC(".maps") = { } vip_map SEC(".maps");
.type = BPF_MAP_TYPE_HASH,
.max_entries = MAX_VIPS,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, CH_RINGS_SIZE);
__u32 *key; __type(key, __u32);
__u32 *value; __type(value, __u32);
} ch_rings SEC(".maps") = { } ch_rings SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = CH_RINGS_SIZE,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, MAX_REALS);
__u32 *key; __type(key, __u32);
struct real_definition *value; __type(value, struct real_definition);
} reals SEC(".maps") = { } reals SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = MAX_REALS,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__u32 max_entries; __uint(max_entries, MAX_VIPS);
__u32 *key; __type(key, __u32);
struct vip_stats *value; __type(value, struct vip_stats);
} stats SEC(".maps") = { } stats SEC(".maps");
.type = BPF_MAP_TYPE_PERCPU_ARRAY,
.max_entries = MAX_VIPS,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, CTL_MAP_SIZE);
__u32 *key; __type(key, __u32);
struct ctl_value *value; __type(value, struct ctl_value);
} ctl_array SEC(".maps") = { } ctl_array SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = CTL_MAP_SIZE,
};
static __always_inline __u32 get_packet_hash(struct packet_description *pckt, static __always_inline __u32 get_packet_hash(struct packet_description *pckt,
bool ipv6) bool ipv6)
......
...@@ -166,54 +166,39 @@ struct eth_hdr { ...@@ -166,54 +166,39 @@ struct eth_hdr {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_HASH);
__u32 max_entries; __uint(max_entries, MAX_VIPS);
struct vip *key; __type(key, struct vip);
struct vip_meta *value; __type(value, struct vip_meta);
} vip_map SEC(".maps") = { } vip_map SEC(".maps");
.type = BPF_MAP_TYPE_HASH,
.max_entries = MAX_VIPS,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, CH_RINGS_SIZE);
__u32 *key; __type(key, __u32);
__u32 *value; __type(value, __u32);
} ch_rings SEC(".maps") = { } ch_rings SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = CH_RINGS_SIZE,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, MAX_REALS);
__u32 *key; __type(key, __u32);
struct real_definition *value; __type(value, struct real_definition);
} reals SEC(".maps") = { } reals SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = MAX_REALS,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__u32 max_entries; __uint(max_entries, MAX_VIPS);
__u32 *key; __type(key, __u32);
struct vip_stats *value; __type(value, struct vip_stats);
} stats SEC(".maps") = { } stats SEC(".maps");
.type = BPF_MAP_TYPE_PERCPU_ARRAY,
.max_entries = MAX_VIPS,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, CTL_MAP_SIZE);
__u32 *key; __type(key, __u32);
struct ctl_value *value; __type(value, struct ctl_value);
} ctl_array SEC(".maps") = { } ctl_array SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = CTL_MAP_SIZE,
};
static __u32 get_packet_hash(struct packet_description *pckt, static __u32 get_packet_hash(struct packet_description *pckt,
bool ipv6) bool ipv6)
......
...@@ -5,23 +5,23 @@ ...@@ -5,23 +5,23 @@
#include <linux/types.h> #include <linux/types.h>
#include "bpf_helpers.h" #include "bpf_helpers.h"
struct bpf_map_def SEC("maps") mim_array = { struct {
.type = BPF_MAP_TYPE_ARRAY_OF_MAPS, __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
.key_size = sizeof(int), __uint(max_entries, 1);
__uint(map_flags, 0);
__uint(key_size, sizeof(__u32));
/* must be sizeof(__u32) for map in map */ /* must be sizeof(__u32) for map in map */
.value_size = sizeof(__u32), __uint(value_size, sizeof(__u32));
.max_entries = 1, } mim_array SEC(".maps");
.map_flags = 0,
}; struct {
__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
struct bpf_map_def SEC("maps") mim_hash = { __uint(max_entries, 1);
.type = BPF_MAP_TYPE_HASH_OF_MAPS, __uint(map_flags, 0);
.key_size = sizeof(int), __uint(key_size, sizeof(int));
/* must be sizeof(__u32) for map in map */ /* must be sizeof(__u32) for map in map */
.value_size = sizeof(__u32), __uint(value_size, sizeof(__u32));
.max_entries = 1, } mim_hash SEC(".maps");
.map_flags = 0,
};
SEC("xdp_mimtest") SEC("xdp_mimtest")
int xdp_mimtest0(struct xdp_md *ctx) int xdp_mimtest0(struct xdp_md *ctx)
......
...@@ -12,14 +12,11 @@ struct hmap_elem { ...@@ -12,14 +12,11 @@ struct hmap_elem {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_HASH);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
struct hmap_elem *value; __type(value, struct hmap_elem);
} hash_map SEC(".maps") = { } hash_map SEC(".maps");
.type = BPF_MAP_TYPE_HASH,
.max_entries = 1,
};
struct array_elem { struct array_elem {
struct bpf_spin_lock lock; struct bpf_spin_lock lock;
...@@ -27,14 +24,11 @@ struct array_elem { ...@@ -27,14 +24,11 @@ struct array_elem {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
int *key; __type(key, int);
struct array_elem *value; __type(value, struct array_elem);
} array_map SEC(".maps") = { } array_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 1,
};
SEC("map_lock_demo") SEC("map_lock_demo")
int bpf_map_lock_test(struct __sk_buff *skb) int bpf_map_lock_test(struct __sk_buff *skb)
......
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
int _version SEC("version") = 1; int _version SEC("version") = 1;
struct bpf_map_def SEC("maps") test_map_id = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(__u32), __uint(max_entries, 1);
.value_size = sizeof(__u64), __type(key, __u32);
.max_entries = 1, __type(value, __u64);
}; } test_map_id SEC(".maps");
SEC("test_obj_id_dummy") SEC("test_obj_id_dummy")
int test_obj_id(struct __sk_buff *skb) int test_obj_id(struct __sk_buff *skb)
......
...@@ -22,56 +22,39 @@ int _version SEC("version") = 1; ...@@ -22,56 +22,39 @@ int _version SEC("version") = 1;
#endif #endif
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__u32 max_entries; __uint(max_entries, 1);
__u32 key_size; __uint(key_size, sizeof(__u32));
__u32 value_size; __uint(value_size, sizeof(__u32));
} outer_map SEC(".maps") = { } outer_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
.max_entries = 1,
.key_size = sizeof(__u32),
.value_size = sizeof(__u32),
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, NR_RESULTS);
__u32 *key; __type(key, __u32);
__u32 *value; __type(value, __u32);
} result_map SEC(".maps") = { } result_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = NR_RESULTS,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
int *value; __type(value, int);
} tmp_index_ovr_map SEC(".maps") = { } tmp_index_ovr_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 1,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
__u32 *value; __type(value, __u32);
} linum_map SEC(".maps") = { } linum_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 1,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
struct data_check *value; __type(value, struct data_check);
} data_check_map SEC(".maps") = { } data_check_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 1,
};
#define GOTO_DONE(_result) ({ \ #define GOTO_DONE(_result) ({ \
result = (_result); \ result = (_result); \
......
...@@ -5,24 +5,18 @@ ...@@ -5,24 +5,18 @@
#include "bpf_helpers.h" #include "bpf_helpers.h"
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
__u64 *value; __type(value, __u64);
} info_map SEC(".maps") = { } info_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 1,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
__u64 *value; __type(value, __u64);
} status_map SEC(".maps") = { } status_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 1,
};
SEC("send_signal_demo") SEC("send_signal_demo")
int bpf_send_signal_test(void *ctx) int bpf_send_signal_test(void *ctx)
......
...@@ -28,44 +28,32 @@ enum bpf_linum_array_idx { ...@@ -28,44 +28,32 @@ enum bpf_linum_array_idx {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, __NR_BPF_ADDR_ARRAY_IDX);
__u32 *key; __type(key, __u32);
struct sockaddr_in6 *value; __type(value, struct sockaddr_in6);
} addr_map SEC(".maps") = { } addr_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = __NR_BPF_ADDR_ARRAY_IDX,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, __NR_BPF_RESULT_ARRAY_IDX);
__u32 *key; __type(key, __u32);
struct bpf_sock *value; __type(value, struct bpf_sock);
} sock_result_map SEC(".maps") = { } sock_result_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = __NR_BPF_RESULT_ARRAY_IDX,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, __NR_BPF_RESULT_ARRAY_IDX);
__u32 *key; __type(key, __u32);
struct bpf_tcp_sock *value; __type(value, struct bpf_tcp_sock);
} tcp_sock_result_map SEC(".maps") = { } tcp_sock_result_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = __NR_BPF_RESULT_ARRAY_IDX,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, __NR_BPF_LINUM_ARRAY_IDX);
__u32 *key; __type(key, __u32);
__u32 *value; __type(value, __u32);
} linum_map SEC(".maps") = { } linum_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = __NR_BPF_LINUM_ARRAY_IDX,
};
struct bpf_spinlock_cnt { struct bpf_spinlock_cnt {
struct bpf_spin_lock lock; struct bpf_spin_lock lock;
...@@ -73,24 +61,18 @@ struct bpf_spinlock_cnt { ...@@ -73,24 +61,18 @@ struct bpf_spinlock_cnt {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_SK_STORAGE);
__u32 map_flags; __uint(map_flags, BPF_F_NO_PREALLOC);
int *key; __type(key, int);
struct bpf_spinlock_cnt *value; __type(value, struct bpf_spinlock_cnt);
} sk_pkt_out_cnt SEC(".maps") = { } sk_pkt_out_cnt SEC(".maps");
.type = BPF_MAP_TYPE_SK_STORAGE,
.map_flags = BPF_F_NO_PREALLOC,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_SK_STORAGE);
__u32 map_flags; __uint(map_flags, BPF_F_NO_PREALLOC);
int *key; __type(key, int);
struct bpf_spinlock_cnt *value; __type(value, struct bpf_spinlock_cnt);
} sk_pkt_out_cnt10 SEC(".maps") = { } sk_pkt_out_cnt10 SEC(".maps");
.type = BPF_MAP_TYPE_SK_STORAGE,
.map_flags = BPF_F_NO_PREALLOC,
};
static bool is_loopback6(__u32 *a6) static bool is_loopback6(__u32 *a6)
{ {
......
...@@ -11,14 +11,11 @@ struct hmap_elem { ...@@ -11,14 +11,11 @@ struct hmap_elem {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_HASH);
__u32 max_entries; __uint(max_entries, 1);
int *key; __type(key, int);
struct hmap_elem *value; __type(value, struct hmap_elem);
} hmap SEC(".maps") = { } hmap SEC(".maps");
.type = BPF_MAP_TYPE_HASH,
.max_entries = 1,
};
struct cls_elem { struct cls_elem {
struct bpf_spin_lock lock; struct bpf_spin_lock lock;
...@@ -26,12 +23,10 @@ struct cls_elem { ...@@ -26,12 +23,10 @@ struct cls_elem {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
struct bpf_cgroup_storage_key *key; __type(key, struct bpf_cgroup_storage_key);
struct cls_elem *value; __type(value, struct cls_elem);
} cls_map SEC(".maps") = { } cls_map SEC(".maps");
.type = BPF_MAP_TYPE_CGROUP_STORAGE,
};
struct bpf_vqueue { struct bpf_vqueue {
struct bpf_spin_lock lock; struct bpf_spin_lock lock;
...@@ -42,14 +37,11 @@ struct bpf_vqueue { ...@@ -42,14 +37,11 @@ struct bpf_vqueue {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
int *key; __type(key, int);
struct bpf_vqueue *value; __type(value, struct bpf_vqueue);
} vqueue SEC(".maps") = { } vqueue SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 1,
};
#define CREDIT_PER_NS(delta, rate) (((delta) * rate) >> 20) #define CREDIT_PER_NS(delta, rate) (((delta) * rate) >> 20)
......
...@@ -9,51 +9,36 @@ ...@@ -9,51 +9,36 @@
#endif #endif
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
__u32 *value; __type(value, __u32);
} control_map SEC(".maps") = { } control_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 1,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_HASH);
__u32 max_entries; __uint(max_entries, 16384);
__u32 *key; __type(key, __u32);
__u32 *value; __type(value, __u32);
} stackid_hmap SEC(".maps") = { } stackid_hmap SEC(".maps");
.type = BPF_MAP_TYPE_HASH,
.max_entries = 16384,
};
typedef struct bpf_stack_build_id stack_trace_t[PERF_MAX_STACK_DEPTH]; typedef struct bpf_stack_build_id stack_trace_t[PERF_MAX_STACK_DEPTH];
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_STACK_TRACE);
__u32 max_entries; __uint(max_entries, 128);
__u32 map_flags; __uint(map_flags, BPF_F_STACK_BUILD_ID);
__u32 key_size; __uint(key_size, sizeof(__u32));
__u32 value_size; __uint(value_size, sizeof(stack_trace_t));
} stackmap SEC(".maps") = { } stackmap SEC(".maps");
.type = BPF_MAP_TYPE_STACK_TRACE,
.max_entries = 128,
.map_flags = BPF_F_STACK_BUILD_ID,
.key_size = sizeof(__u32),
.value_size = sizeof(stack_trace_t),
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 128);
__u32 *key; __type(key, __u32);
/* there seems to be a bug in kernel not handling typedef properly */ /* there seems to be a bug in kernel not handling typedef properly */
struct bpf_stack_build_id (*value)[PERF_MAX_STACK_DEPTH]; struct bpf_stack_build_id (*value)[PERF_MAX_STACK_DEPTH];
} stack_amap SEC(".maps") = { } stack_amap SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 128,
};
/* taken from /sys/kernel/debug/tracing/events/random/urandom_read/format */ /* taken from /sys/kernel/debug/tracing/events/random/urandom_read/format */
struct random_urandom_args { struct random_urandom_args {
......
...@@ -9,48 +9,34 @@ ...@@ -9,48 +9,34 @@
#endif #endif
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 1);
__u32 *key; __type(key, __u32);
__u32 *value; __type(value, __u32);
} control_map SEC(".maps") = { } control_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 1,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_HASH);
__u32 max_entries; __uint(max_entries, 16384);
__u32 *key; __type(key, __u32);
__u32 *value; __type(value, __u32);
} stackid_hmap SEC(".maps") = { } stackid_hmap SEC(".maps");
.type = BPF_MAP_TYPE_HASH,
.max_entries = 16384,
};
typedef __u64 stack_trace_t[PERF_MAX_STACK_DEPTH]; typedef __u64 stack_trace_t[PERF_MAX_STACK_DEPTH];
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_STACK_TRACE);
__u32 max_entries; __uint(max_entries, 16384);
__u32 key_size; __uint(key_size, sizeof(__u32));
__u32 value_size; __uint(value_size, sizeof(stack_trace_t));
} stackmap SEC(".maps") = { } stackmap SEC(".maps");
.type = BPF_MAP_TYPE_STACK_TRACE,
.max_entries = 16384,
.key_size = sizeof(__u32),
.value_size = sizeof(stack_trace_t),
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 16384);
__u32 *key; __type(key, __u32);
__u64 (*value)[PERF_MAX_STACK_DEPTH]; __u64 (*value)[PERF_MAX_STACK_DEPTH];
} stack_amap SEC(".maps") = { } stack_amap SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 16384,
};
/* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */ /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */
struct sched_switch_args { struct sched_switch_args {
......
...@@ -149,14 +149,11 @@ struct tcp_estats_basic_event { ...@@ -149,14 +149,11 @@ struct tcp_estats_basic_event {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_HASH);
__u32 max_entries; __uint(max_entries, 1024);
__u32 *key; __type(key, __u32);
struct tcp_estats_basic_event *value; __type(value, struct tcp_estats_basic_event);
} ev_record_map SEC(".maps") = { } ev_record_map SEC(".maps");
.type = BPF_MAP_TYPE_HASH,
.max_entries = 1024,
};
struct dummy_tracepoint_args { struct dummy_tracepoint_args {
unsigned long long pad; unsigned long long pad;
......
...@@ -15,24 +15,18 @@ ...@@ -15,24 +15,18 @@
#include "test_tcpbpf.h" #include "test_tcpbpf.h"
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 4);
__u32 *key; __type(key, __u32);
struct tcpbpf_globals *value; __type(value, struct tcpbpf_globals);
} global_map SEC(".maps") = { } global_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 4,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 2);
__u32 *key; __type(key, __u32);
int *value; __type(value, int);
} sockopt_results SEC(".maps") = { } sockopt_results SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 2,
};
static inline void update_event_map(int event) static inline void update_event_map(int event)
{ {
......
...@@ -15,26 +15,18 @@ ...@@ -15,26 +15,18 @@
#include "test_tcpnotify.h" #include "test_tcpnotify.h"
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 4);
__u32 *key; __type(key, __u32);
struct tcpnotify_globals *value; __type(value, struct tcpnotify_globals);
} global_map SEC(".maps") = { } global_map SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 4,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__u32 max_entries; __uint(max_entries, 2);
__u32 key_size; __uint(key_size, sizeof(int));
__u32 value_size; __uint(value_size, sizeof(__u32));
} perf_event_map SEC(".maps") = { } perf_event_map SEC(".maps");
.type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
.max_entries = 2,
.key_size = sizeof(int),
.value_size = sizeof(__u32),
};
int _version SEC("version") = 1; int _version SEC("version") = 1;
......
...@@ -23,24 +23,18 @@ ...@@ -23,24 +23,18 @@
int _version SEC("version") = 1; int _version SEC("version") = 1;
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__u32 max_entries; __uint(max_entries, 256);
__u32 *key; __type(key, __u32);
__u64 *value; __type(value, __u64);
} rxcnt SEC(".maps") = { } rxcnt SEC(".maps");
.type = BPF_MAP_TYPE_PERCPU_ARRAY,
.max_entries = 256,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_HASH);
__u32 max_entries; __uint(max_entries, MAX_IPTNL_ENTRIES);
struct vip *key; __type(key, struct vip);
struct iptnl_info *value; __type(value, struct iptnl_info);
} vip2tnl SEC(".maps") = { } vip2tnl SEC(".maps");
.type = BPF_MAP_TYPE_HASH,
.max_entries = MAX_IPTNL_ENTRIES,
};
static __always_inline void count_tx(__u32 protocol) static __always_inline void count_tx(__u32 protocol)
{ {
......
...@@ -18,19 +18,19 @@ ...@@ -18,19 +18,19 @@
int _version SEC("version") = 1; int _version SEC("version") = 1;
struct bpf_map_def SEC("maps") rxcnt = { struct {
.type = BPF_MAP_TYPE_PERCPU_ARRAY, __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
.key_size = sizeof(__u32), __uint(max_entries, 256);
.value_size = sizeof(__u64), __type(key, __u32);
.max_entries = 256, __type(value, __u64);
}; } rxcnt SEC(".maps");
struct bpf_map_def SEC("maps") vip2tnl = { struct {
.type = BPF_MAP_TYPE_HASH, __uint(type, BPF_MAP_TYPE_HASH);
.key_size = sizeof(struct vip), __uint(max_entries, MAX_IPTNL_ENTRIES);
.value_size = sizeof(struct iptnl_info), __type(key, struct vip);
.max_entries = MAX_IPTNL_ENTRIES, __type(value, struct iptnl_info);
}; } vip2tnl SEC(".maps");
static __always_inline void count_tx(__u32 protocol) static __always_inline void count_tx(__u32 protocol)
{ {
......
...@@ -164,66 +164,47 @@ struct lb_stats { ...@@ -164,66 +164,47 @@ struct lb_stats {
}; };
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_HASH);
__u32 max_entries; __uint(max_entries, 512);
struct vip_definition *key; __type(key, struct vip_definition);
struct vip_meta *value; __type(value, struct vip_meta);
} vip_map SEC(".maps") = { } vip_map SEC(".maps");
.type = BPF_MAP_TYPE_HASH,
.max_entries = 512,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_LRU_HASH);
__u32 max_entries; __uint(max_entries, 300);
__u32 map_flags; __uint(map_flags, 1U << 1);
struct flow_key *key; __type(key, struct flow_key);
struct real_pos_lru *value; __type(value, struct real_pos_lru);
} lru_cache SEC(".maps") = { } lru_cache SEC(".maps");
.type = BPF_MAP_TYPE_LRU_HASH,
.max_entries = 300,
.map_flags = 1U << 1,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 12 * 655);
__u32 *key; __type(key, __u32);
__u32 *value; __type(value, __u32);
} ch_rings SEC(".maps") = { } ch_rings SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 12 * 655,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 40);
__u32 *key; __type(key, __u32);
struct real_definition *value; __type(value, struct real_definition);
} reals SEC(".maps") = { } reals SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 40,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__u32 max_entries; __uint(max_entries, 515);
__u32 *key; __type(key, __u32);
struct lb_stats *value; __type(value, struct lb_stats);
} stats SEC(".maps") = { } stats SEC(".maps");
.type = BPF_MAP_TYPE_PERCPU_ARRAY,
.max_entries = 515,
};
struct { struct {
__u32 type; __uint(type, BPF_MAP_TYPE_ARRAY);
__u32 max_entries; __uint(max_entries, 16);
__u32 *key; __type(key, __u32);
struct ctl_value *value; __type(value, struct ctl_value);
} ctl_array SEC(".maps") = { } ctl_array SEC(".maps");
.type = BPF_MAP_TYPE_ARRAY,
.max_entries = 16,
};
struct eth_hdr { struct eth_hdr {
unsigned char eth_dest[6]; unsigned char eth_dest[6];
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
#include <linux/bpf.h> #include <linux/bpf.h>
#include "bpf_helpers.h" #include "bpf_helpers.h"
struct bpf_map_def SEC("maps") tx_port = { struct {
.type = BPF_MAP_TYPE_DEVMAP, __uint(type, BPF_MAP_TYPE_DEVMAP);
.key_size = sizeof(int), __uint(max_entries, 8);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 8, __uint(value_size, sizeof(int));
}; } tx_port SEC(".maps");
SEC("redirect_map_0") SEC("redirect_map_0")
int xdp_redirect_map_0(struct xdp_md *xdp) int xdp_redirect_map_0(struct xdp_md *xdp)
......
...@@ -17,12 +17,12 @@ ...@@ -17,12 +17,12 @@
#include "xdping.h" #include "xdping.h"
struct bpf_map_def SEC("maps") ping_map = { struct {
.type = BPF_MAP_TYPE_HASH, __uint(type, BPF_MAP_TYPE_HASH);
.key_size = sizeof(__u32), __uint(max_entries, 256);
.value_size = sizeof(struct pinginfo), __type(key, __u32);
.max_entries = 256, __type(value, struct pinginfo);
}; } ping_map SEC(".maps");
static __always_inline void swap_src_dst_mac(void *data) static __always_inline void swap_src_dst_mac(void *data)
{ {
......
...@@ -10,21 +10,21 @@ ...@@ -10,21 +10,21 @@
int _version SEC("version") = 1; int _version SEC("version") = 1;
struct bpf_map_def __attribute__ ((section("maps"), used)) map_in = { struct {
.type = MAP_TYPE, __uint(type, MAP_TYPE);
.key_size = 0, __uint(max_entries, 32);
.value_size = sizeof(__u32), __uint(map_flags, 0);
.max_entries = 32, __uint(key_size, 0);
.map_flags = 0, __uint(value_size, sizeof(__u32));
}; } map_in SEC(".maps");
struct bpf_map_def __attribute__ ((section("maps"), used)) map_out = { struct {
.type = MAP_TYPE, __uint(type, MAP_TYPE);
.key_size = 0, __uint(max_entries, 32);
.value_size = sizeof(__u32), __uint(map_flags, 0);
.max_entries = 32, __uint(key_size, 0);
.map_flags = 0, __uint(value_size, sizeof(__u32));
}; } map_out SEC(".maps");
SEC("test") SEC("test")
int _test(struct __sk_buff *skb) int _test(struct __sk_buff *skb)
......
...@@ -28,61 +28,61 @@ ...@@ -28,61 +28,61 @@
* are established and verdicts are decided. * are established and verdicts are decided.
*/ */
struct bpf_map_def SEC("maps") sock_map = { struct {
.type = TEST_MAP_TYPE, __uint(type, TEST_MAP_TYPE);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map SEC(".maps");
struct bpf_map_def SEC("maps") sock_map_txmsg = { struct {
.type = TEST_MAP_TYPE, __uint(type, TEST_MAP_TYPE);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map_txmsg SEC(".maps");
struct bpf_map_def SEC("maps") sock_map_redir = { struct {
.type = TEST_MAP_TYPE, __uint(type, TEST_MAP_TYPE);
.key_size = sizeof(int), __uint(max_entries, 20);
.value_size = sizeof(int), __uint(key_size, sizeof(int));
.max_entries = 20, __uint(value_size, sizeof(int));
}; } sock_map_redir SEC(".maps");
struct bpf_map_def SEC("maps") sock_apply_bytes = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 1);
.value_size = sizeof(int), __type(key, int);
.max_entries = 1 __type(value, int);
}; } sock_apply_bytes SEC(".maps");
struct bpf_map_def SEC("maps") sock_cork_bytes = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 1);
.value_size = sizeof(int), __type(key, int);
.max_entries = 1 __type(value, int);
}; } sock_cork_bytes SEC(".maps");
struct bpf_map_def SEC("maps") sock_bytes = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 6);
.value_size = sizeof(int), __type(key, int);
.max_entries = 6 __type(value, int);
}; } sock_bytes SEC(".maps");
struct bpf_map_def SEC("maps") sock_redir_flags = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 1);
.value_size = sizeof(int), __type(key, int);
.max_entries = 1 __type(value, int);
}; } sock_redir_flags SEC(".maps");
struct bpf_map_def SEC("maps") sock_skb_opts = { struct {
.type = BPF_MAP_TYPE_ARRAY, __uint(type, BPF_MAP_TYPE_ARRAY);
.key_size = sizeof(int), __uint(max_entries, 1);
.value_size = sizeof(int), __type(key, int);
.max_entries = 1 __type(value, int);
}; } sock_skb_opts SEC(".maps");
SEC("sk_skb1") SEC("sk_skb1")
int bpf_prog1(struct __sk_buff *skb) int bpf_prog1(struct __sk_buff *skb)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment