]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
selftests/bpf: convert selftests using BTF-defined maps to new syntax
authorAndrii Nakryiko <andriin@fb.com>
Fri, 5 Jul 2019 15:50:11 +0000 (08:50 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 5 Jul 2019 20:52:25 +0000 (22:52 +0200)
Convert all the existing selftests that are already using BTF-defined
maps to use new syntax (with no static data initialization).

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
20 files changed:
tools/testing/selftests/bpf/progs/bpf_flow.c
tools/testing/selftests/bpf/progs/netcnt_prog.c
tools/testing/selftests/bpf/progs/socket_cookie_prog.c
tools/testing/selftests/bpf/progs/test_btf_newkv.c
tools/testing/selftests/bpf/progs/test_get_stack_rawtp.c
tools/testing/selftests/bpf/progs/test_global_data.c
tools/testing/selftests/bpf/progs/test_l4lb.c
tools/testing/selftests/bpf/progs/test_l4lb_noinline.c
tools/testing/selftests/bpf/progs/test_map_lock.c
tools/testing/selftests/bpf/progs/test_select_reuseport_kern.c
tools/testing/selftests/bpf/progs/test_send_signal_kern.c
tools/testing/selftests/bpf/progs/test_sock_fields_kern.c
tools/testing/selftests/bpf/progs/test_spin_lock.c
tools/testing/selftests/bpf/progs/test_stacktrace_build_id.c
tools/testing/selftests/bpf/progs/test_stacktrace_map.c
tools/testing/selftests/bpf/progs/test_tcp_estats.c
tools/testing/selftests/bpf/progs/test_tcpbpf_kern.c
tools/testing/selftests/bpf/progs/test_tcpnotify_kern.c
tools/testing/selftests/bpf/progs/test_xdp.c
tools/testing/selftests/bpf/progs/test_xdp_noinline.c

index 849f42e548b5daf2af4a9d10de3f997bf7fe0611..5ae485a6af3fc2ce2a8267f416b621eb5bec2c7a 100644 (file)
@@ -58,26 +58,18 @@ struct frag_hdr {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 key_size;
-       __u32 value_size;
-} jmp_table SEC(".maps") = {
-       .type = BPF_MAP_TYPE_PROG_ARRAY,
-       .max_entries = 8,
-       .key_size = sizeof(__u32),
-       .value_size = sizeof(__u32),
-};
+       __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
+       __uint(max_entries, 8);
+       __uint(key_size, sizeof(__u32));
+       __uint(value_size, sizeof(__u32));
+} jmp_table SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct bpf_flow_keys *value;
-} last_dissection SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, struct bpf_flow_keys);
+} last_dissection SEC(".maps");
 
 static __always_inline int export_flow_keys(struct bpf_flow_keys *keys,
                                            int ret)
index a25c82a5b7c868eed411d57d48d2a42f7c489350..38a997852cadb2cad2e094b8415d7527a2d0ab80 100644 (file)
 #define NS_PER_SEC     1000000000
 
 struct {
-       __u32 type;
-       struct bpf_cgroup_storage_key *key;
-       struct percpu_net_cnt *value;
-} percpu_netcnt SEC(".maps") = {
-       .type = BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
-};
+       __uint(type, BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE);
+       __type(key, struct bpf_cgroup_storage_key);
+       __type(value, struct percpu_net_cnt);
+} percpu_netcnt SEC(".maps");
 
 struct {
-       __u32 type;
-       struct bpf_cgroup_storage_key *key;
-       struct net_cnt *value;
-} netcnt SEC(".maps") = {
-       .type = BPF_MAP_TYPE_CGROUP_STORAGE,
-};
+       __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
+       __type(key, struct bpf_cgroup_storage_key);
+       __type(value, struct net_cnt);
+} netcnt SEC(".maps");
 
 SEC("cgroup/skb")
 int bpf_nextcnt(struct __sk_buff *skb)
index 6aabb681fb9a23e1e90fd73805f8f0d9547af688..e4440fdd94cbe7729b4e050c19a7ade8f34e9d74 100644 (file)
@@ -13,14 +13,11 @@ struct socket_cookie {
 };
 
 struct {
-       __u32 type;
-       __u32 map_flags;
-       int *key;
-       struct socket_cookie *value;
-} socket_cookies SEC(".maps") = {
-       .type = BPF_MAP_TYPE_SK_STORAGE,
-       .map_flags = BPF_F_NO_PREALLOC,
-};
+       __uint(type, BPF_MAP_TYPE_SK_STORAGE);
+       __uint(map_flags, BPF_F_NO_PREALLOC);
+       __type(key, int);
+       __type(value, struct socket_cookie);
+} socket_cookies SEC(".maps");
 
 SEC("cgroup/connect6")
 int set_cookie(struct bpf_sock_addr *ctx)
index 28c16bb583b6e8f2d8c14834354f0ec98a793b84..5ee3622ddebb698d6461ab400e3a8685cee523b6 100644 (file)
@@ -21,14 +21,11 @@ struct bpf_map_def SEC("maps") btf_map_legacy = {
 BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts);
 
 struct {
-       int *key;
-       struct ipv_counts *value;
-       unsigned int type;
-       unsigned int max_entries;
-} btf_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 4,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 4);
+       __type(key, int);
+       __type(value, struct ipv_counts);
+} btf_map SEC(".maps");
 
 struct dummy_tracepoint_args {
        unsigned long long pad;
index aaa6ec250e153309094aaf50b65fd364e44a8936..d06b47a090972922eba7062cb3e75633e21efbd2 100644 (file)
@@ -16,26 +16,18 @@ struct stack_trace_t {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 key_size;
-       __u32 value_size;
-} perfmap SEC(".maps") = {
-       .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
-       .max_entries = 2,
-       .key_size = sizeof(int),
-       .value_size = sizeof(__u32),
-};
+       __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
+       __uint(max_entries, 2);
+       __uint(key_size, sizeof(int));
+       __uint(value_size, sizeof(__u32));
+} perfmap SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct stack_trace_t *value;
-} stackdata_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_PERCPU_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, struct stack_trace_t);
+} stackdata_map SEC(".maps");
 
 /* Allocate per-cpu space twice the needed. For the code below
  *   usize = bpf_get_stack(ctx, raw_data, max_len, BPF_F_USER_STACK);
@@ -56,14 +48,11 @@ struct {
  * This is an acceptable workaround since there is one entry here.
  */
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
+       __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, __u32);
        __u64 (*value)[2 * MAX_STACK_RAWTP];
-} rawdata_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_PERCPU_ARRAY,
-       .max_entries = 1,
-};
+} rawdata_map SEC(".maps");
 
 SEC("tracepoint/raw_syscalls/sys_enter")
 int bpf_prog1(void *ctx)
index 866cc7ddbe431d80792c224088b7a3becce41fe2..32a6073acb9900be48e750eb69089d9a9f519fa9 100644 (file)
@@ -8,24 +8,18 @@
 #include "bpf_helpers.h"
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u64 *value;
-} result_number SEC(".maps") = {
-       .type           = BPF_MAP_TYPE_ARRAY,
-       .max_entries    = 11,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 11);
+       __type(key, __u32);
+       __type(value, __u64);
+} result_number SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 5);
+       __type(key, __u32);
        const char (*value)[32];
-} result_string SEC(".maps") = {
-       .type           = BPF_MAP_TYPE_ARRAY,
-       .max_entries    = 5,
-};
+} result_string SEC(".maps");
 
 struct foo {
        __u8  a;
@@ -34,14 +28,11 @@ struct foo {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct foo *value;
-} result_struct SEC(".maps") = {
-       .type           = BPF_MAP_TYPE_ARRAY,
-       .max_entries    = 5,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 5);
+       __type(key, __u32);
+       __type(value, struct foo);
+} result_struct SEC(".maps");
 
 /* Relocation tests for __u64s. */
 static       __u64 num0;
index 848cbb90f581d041e273be7e5ac2e1d48bde4aed..1d652ee8e73d7f35344fc3698070281e75f65400 100644 (file)
@@ -170,54 +170,39 @@ struct eth_hdr {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       struct vip *key;
-       struct vip_meta *value;
-} vip_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_HASH,
-       .max_entries = MAX_VIPS,
-};
+       __uint(type, BPF_MAP_TYPE_HASH);
+       __uint(max_entries, MAX_VIPS);
+       __type(key, struct vip);
+       __type(value, struct vip_meta);
+} vip_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u32 *value;
-} ch_rings SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = CH_RINGS_SIZE,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, CH_RINGS_SIZE);
+       __type(key, __u32);
+       __type(value, __u32);
+} ch_rings SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct real_definition *value;
-} reals SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = MAX_REALS,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, MAX_REALS);
+       __type(key, __u32);
+       __type(value, struct real_definition);
+} reals SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct vip_stats *value;
-} stats SEC(".maps") = {
-       .type = BPF_MAP_TYPE_PERCPU_ARRAY,
-       .max_entries = MAX_VIPS,
-};
+       __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+       __uint(max_entries, MAX_VIPS);
+       __type(key, __u32);
+       __type(value, struct vip_stats);
+} stats SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct ctl_value *value;
-} ctl_array SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = CTL_MAP_SIZE,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, CTL_MAP_SIZE);
+       __type(key, __u32);
+       __type(value, struct ctl_value);
+} ctl_array SEC(".maps");
 
 static __always_inline __u32 get_packet_hash(struct packet_description *pckt,
                                             bool ipv6)
index c63ecf3ca573bfc5180676ec22f3a6adfac18153..2e4efe70b1e57bf546e6c601c46ce708e1e36c47 100644 (file)
@@ -166,54 +166,39 @@ struct eth_hdr {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       struct vip *key;
-       struct vip_meta *value;
-} vip_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_HASH,
-       .max_entries = MAX_VIPS,
-};
+       __uint(type, BPF_MAP_TYPE_HASH);
+       __uint(max_entries, MAX_VIPS);
+       __type(key, struct vip);
+       __type(value, struct vip_meta);
+} vip_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u32 *value;
-} ch_rings SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = CH_RINGS_SIZE,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, CH_RINGS_SIZE);
+       __type(key, __u32);
+       __type(value, __u32);
+} ch_rings SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct real_definition *value;
-} reals SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = MAX_REALS,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, MAX_REALS);
+       __type(key, __u32);
+       __type(value, struct real_definition);
+} reals SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct vip_stats *value;
-} stats SEC(".maps") = {
-       .type = BPF_MAP_TYPE_PERCPU_ARRAY,
-       .max_entries = MAX_VIPS,
-};
+       __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+       __uint(max_entries, MAX_VIPS);
+       __type(key, __u32);
+       __type(value, struct vip_stats);
+} stats SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct ctl_value *value;
-} ctl_array SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = CTL_MAP_SIZE,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, CTL_MAP_SIZE);
+       __type(key, __u32);
+       __type(value, struct ctl_value);
+} ctl_array SEC(".maps");
 
 static __u32 get_packet_hash(struct packet_description *pckt,
                             bool ipv6)
index 40d9c28533931dc6f2c4af938857e25ee53bd3ac..bb7ce35f691b388a71f6735ed0780ec808e34f91 100644 (file)
@@ -12,14 +12,11 @@ struct hmap_elem {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct hmap_elem *value;
-} hash_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_HASH,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_HASH);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, struct hmap_elem);
+} hash_map SEC(".maps");
 
 struct array_elem {
        struct bpf_spin_lock lock;
@@ -27,14 +24,11 @@ struct array_elem {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       int *key;
-       struct array_elem *value;
-} array_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, int);
+       __type(value, struct array_elem);
+} array_map SEC(".maps");
 
 SEC("map_lock_demo")
 int bpf_map_lock_test(struct __sk_buff *skb)
index 435a9527733e20f0273f46ec3ab7ae5a77ca23c3..ea7d84f01235283880d3e5246085499f1afd5b73 100644 (file)
@@ -22,56 +22,39 @@ int _version SEC("version") = 1;
 #endif
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 key_size;
-       __u32 value_size;
-} outer_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
-       .max_entries = 1,
-       .key_size = sizeof(__u32),
-       .value_size = sizeof(__u32),
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
+       __uint(max_entries, 1);
+       __uint(key_size, sizeof(__u32));
+       __uint(value_size, sizeof(__u32));
+} outer_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u32 *value;
-} result_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = NR_RESULTS,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, NR_RESULTS);
+       __type(key, __u32);
+       __type(value, __u32);
+} result_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       int *value;
-} tmp_index_ovr_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, int);
+} tmp_index_ovr_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u32 *value;
-} linum_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, __u32);
+} linum_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct data_check *value;
-} data_check_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, struct data_check);
+} data_check_map SEC(".maps");
 
 #define GOTO_DONE(_result) ({                  \
        result = (_result);                     \
index 6ac68be5d68ba15c2aeeda0d43b92ac5b5ded4db..0e6be01157e682d91bc0da1e16bc5bdfef6912f8 100644 (file)
@@ -5,24 +5,18 @@
 #include "bpf_helpers.h"
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u64 *value;
-} info_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, __u64);
+} info_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u64 *value;
-} status_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, __u64);
+} status_map SEC(".maps");
 
 SEC("send_signal_demo")
 int bpf_send_signal_test(void *ctx)
index c3d383d650cb12c45613c9f8bdc39022c7097688..a47b003623efb41deea171aa3049468cb1a1863c 100644 (file)
@@ -28,44 +28,32 @@ enum bpf_linum_array_idx {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct sockaddr_in6 *value;
-} addr_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = __NR_BPF_ADDR_ARRAY_IDX,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, __NR_BPF_ADDR_ARRAY_IDX);
+       __type(key, __u32);
+       __type(value, struct sockaddr_in6);
+} addr_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct bpf_sock *value;
-} sock_result_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = __NR_BPF_RESULT_ARRAY_IDX,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, __NR_BPF_RESULT_ARRAY_IDX);
+       __type(key, __u32);
+       __type(value, struct bpf_sock);
+} sock_result_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct bpf_tcp_sock *value;
-} tcp_sock_result_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = __NR_BPF_RESULT_ARRAY_IDX,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, __NR_BPF_RESULT_ARRAY_IDX);
+       __type(key, __u32);
+       __type(value, struct bpf_tcp_sock);
+} tcp_sock_result_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u32 *value;
-} linum_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = __NR_BPF_LINUM_ARRAY_IDX,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, __NR_BPF_LINUM_ARRAY_IDX);
+       __type(key, __u32);
+       __type(value, __u32);
+} linum_map SEC(".maps");
 
 struct bpf_spinlock_cnt {
        struct bpf_spin_lock lock;
@@ -73,24 +61,18 @@ struct bpf_spinlock_cnt {
 };
 
 struct {
-       __u32 type;
-       __u32 map_flags;
-       int *key;
-       struct bpf_spinlock_cnt *value;
-} sk_pkt_out_cnt SEC(".maps") = {
-       .type = BPF_MAP_TYPE_SK_STORAGE,
-       .map_flags = BPF_F_NO_PREALLOC,
-};
+       __uint(type, BPF_MAP_TYPE_SK_STORAGE);
+       __uint(map_flags, BPF_F_NO_PREALLOC);
+       __type(key, int);
+       __type(value, struct bpf_spinlock_cnt);
+} sk_pkt_out_cnt SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 map_flags;
-       int *key;
-       struct bpf_spinlock_cnt *value;
-} sk_pkt_out_cnt10 SEC(".maps") = {
-       .type = BPF_MAP_TYPE_SK_STORAGE,
-       .map_flags = BPF_F_NO_PREALLOC,
-};
+       __uint(type, BPF_MAP_TYPE_SK_STORAGE);
+       __uint(map_flags, BPF_F_NO_PREALLOC);
+       __type(key, int);
+       __type(value, struct bpf_spinlock_cnt);
+} sk_pkt_out_cnt10 SEC(".maps");
 
 static bool is_loopback6(__u32 *a6)
 {
index 0a77ae36d98174b0657c19e4f8ae16c132da1b2c..a43b999c8da2ef1b584e35ae91d1d60b445d628e 100644 (file)
@@ -11,14 +11,11 @@ struct hmap_elem {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       int *key;
-       struct hmap_elem *value;
-} hmap SEC(".maps") = {
-       .type = BPF_MAP_TYPE_HASH,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_HASH);
+       __uint(max_entries, 1);
+       __type(key, int);
+       __type(value, struct hmap_elem);
+} hmap SEC(".maps");
 
 struct cls_elem {
        struct bpf_spin_lock lock;
@@ -26,12 +23,10 @@ struct cls_elem {
 };
 
 struct {
-       __u32 type;
-       struct bpf_cgroup_storage_key *key;
-       struct cls_elem *value;
-} cls_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_CGROUP_STORAGE,
-};
+       __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
+       __type(key, struct bpf_cgroup_storage_key);
+       __type(value, struct cls_elem);
+} cls_map SEC(".maps");
 
 struct bpf_vqueue {
        struct bpf_spin_lock lock;
@@ -42,14 +37,11 @@ struct bpf_vqueue {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       int *key;
-       struct bpf_vqueue *value;
-} vqueue SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, int);
+       __type(value, struct bpf_vqueue);
+} vqueue SEC(".maps");
 
 #define CREDIT_PER_NS(delta, rate) (((delta) * rate) >> 20)
 
index fcf2280bb60c70bc1bb8c60b6820edcc2f45d465..bbfc8337b6f0e46eecf4281b20a82e7252f01690 100644 (file)
@@ -9,51 +9,36 @@
 #endif
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u32 *value;
-} control_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, __u32);
+} control_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u32 *value;
-} stackid_hmap SEC(".maps") = {
-       .type = BPF_MAP_TYPE_HASH,
-       .max_entries = 16384,
-};
+       __uint(type, BPF_MAP_TYPE_HASH);
+       __uint(max_entries, 16384);
+       __type(key, __u32);
+       __type(value, __u32);
+} stackid_hmap SEC(".maps");
 
 typedef struct bpf_stack_build_id stack_trace_t[PERF_MAX_STACK_DEPTH];
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 map_flags;
-       __u32 key_size;
-       __u32 value_size;
-} 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),
-};
+       __uint(type, BPF_MAP_TYPE_STACK_TRACE);
+       __uint(max_entries, 128);
+       __uint(map_flags, BPF_F_STACK_BUILD_ID);
+       __uint(key_size, sizeof(__u32));
+       __uint(value_size, sizeof(stack_trace_t));
+} stackmap SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 128);
+       __type(key, __u32);
        /* there seems to be a bug in kernel not handling typedef properly */
        struct bpf_stack_build_id (*value)[PERF_MAX_STACK_DEPTH];
-} stack_amap SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 128,
-};
+} stack_amap SEC(".maps");
 
 /* taken from /sys/kernel/debug/tracing/events/random/urandom_read/format */
 struct random_urandom_args {
index 7ad09adbf648793cb6a5ebaf2394ba0b696a3e36..803c15dc109d21ee18e16fb40378847c2e2bfd86 100644 (file)
@@ -9,48 +9,34 @@
 #endif
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u32 *value;
-} control_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 1,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 1);
+       __type(key, __u32);
+       __type(value, __u32);
+} control_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u32 *value;
-} stackid_hmap SEC(".maps") = {
-       .type = BPF_MAP_TYPE_HASH,
-       .max_entries = 16384,
-};
+       __uint(type, BPF_MAP_TYPE_HASH);
+       __uint(max_entries, 16384);
+       __type(key, __u32);
+       __type(value, __u32);
+} stackid_hmap SEC(".maps");
 
 typedef __u64 stack_trace_t[PERF_MAX_STACK_DEPTH];
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 key_size;
-       __u32 value_size;
-} stackmap SEC(".maps") = {
-       .type = BPF_MAP_TYPE_STACK_TRACE,
-       .max_entries = 16384,
-       .key_size = sizeof(__u32),
-       .value_size = sizeof(stack_trace_t),
-};
+       __uint(type, BPF_MAP_TYPE_STACK_TRACE);
+       __uint(max_entries, 16384);
+       __uint(key_size, sizeof(__u32));
+       __uint(value_size, sizeof(stack_trace_t));
+} stackmap SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 16384);
+       __type(key, __u32);
        __u64 (*value)[PERF_MAX_STACK_DEPTH];
-} stack_amap SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 16384,
-};
+} stack_amap SEC(".maps");
 
 /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */
 struct sched_switch_args {
index df98f7e32832b85edb91636812db5e70e59f3a7d..c8c595da38d417b8daccb2a0c5d1e49956a01b44 100644 (file)
@@ -149,14 +149,11 @@ struct tcp_estats_basic_event {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct tcp_estats_basic_event *value;
-} ev_record_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_HASH,
-       .max_entries = 1024,
-};
+       __uint(type, BPF_MAP_TYPE_HASH);
+       __uint(max_entries, 1024);
+       __type(key, __u32);
+       __type(value, struct tcp_estats_basic_event);
+} ev_record_map SEC(".maps");
 
 struct dummy_tracepoint_args {
        unsigned long long pad;
index 38e10c9fd99632fc6aa3432e30dc49a901a18a3e..2e233613d1fc04a8f75e1c9b76655db9d93e5df8 100644 (file)
 #include "test_tcpbpf.h"
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct tcpbpf_globals *value;
-} global_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 4,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 4);
+       __type(key, __u32);
+       __type(value, struct tcpbpf_globals);
+} global_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       int *value;
-} sockopt_results SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 2,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 2);
+       __type(key, __u32);
+       __type(value, int);
+} sockopt_results SEC(".maps");
 
 static inline void update_event_map(int event)
 {
index d073d37d4e2744979291809fbe059b0507226416..08346e7765d52c4b2bbb64d83f122ee9e749b7d4 100644 (file)
 #include "test_tcpnotify.h"
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct tcpnotify_globals *value;
-} global_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 4,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 4);
+       __type(key, __u32);
+       __type(value, struct tcpnotify_globals);
+} global_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 key_size;
-       __u32 value_size;
-} perf_event_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_PERF_EVENT_ARRAY,
-       .max_entries = 2,
-       .key_size = sizeof(int),
-       .value_size = sizeof(__u32),
-};
+       __uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
+       __uint(max_entries, 2);
+       __uint(key_size, sizeof(int));
+       __uint(value_size, sizeof(__u32));
+} perf_event_map SEC(".maps");
 
 int _version SEC("version") = 1;
 
index ec3d2c1c8cf9ca4f9f6799dbd083721725c61cf2..0941c655b07bb13693675371332c2359e6c66127 100644 (file)
 int _version SEC("version") = 1;
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u64 *value;
-} rxcnt SEC(".maps") = {
-       .type = BPF_MAP_TYPE_PERCPU_ARRAY,
-       .max_entries = 256,
-};
+       __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+       __uint(max_entries, 256);
+       __type(key, __u32);
+       __type(value, __u64);
+} rxcnt SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       struct vip *key;
-       struct iptnl_info *value;
-} vip2tnl SEC(".maps") = {
-       .type = BPF_MAP_TYPE_HASH,
-       .max_entries = MAX_IPTNL_ENTRIES,
-};
+       __uint(type, BPF_MAP_TYPE_HASH);
+       __uint(max_entries, MAX_IPTNL_ENTRIES);
+       __type(key, struct vip);
+       __type(value, struct iptnl_info);
+} vip2tnl SEC(".maps");
 
 static __always_inline void count_tx(__u32 protocol)
 {
index d2eddb5553d1ea069b4d74a361050927dec44dc8..dad8a7e33eaa7d3bd71f0ff3911feb92fac3128c 100644 (file)
@@ -164,66 +164,47 @@ struct lb_stats {
 };
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       struct vip_definition *key;
-       struct vip_meta *value;
-} vip_map SEC(".maps") = {
-       .type = BPF_MAP_TYPE_HASH,
-       .max_entries = 512,
-};
+       __uint(type, BPF_MAP_TYPE_HASH);
+       __uint(max_entries, 512);
+       __type(key, struct vip_definition);
+       __type(value, struct vip_meta);
+} vip_map SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 map_flags;
-       struct flow_key *key;
-       struct real_pos_lru *value;
-} lru_cache SEC(".maps") = {
-       .type = BPF_MAP_TYPE_LRU_HASH,
-       .max_entries = 300,
-       .map_flags = 1U << 1,
-};
+       __uint(type, BPF_MAP_TYPE_LRU_HASH);
+       __uint(max_entries, 300);
+       __uint(map_flags, 1U << 1);
+       __type(key, struct flow_key);
+       __type(value, struct real_pos_lru);
+} lru_cache SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       __u32 *value;
-} ch_rings SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 12 * 655,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 12 * 655);
+       __type(key, __u32);
+       __type(value, __u32);
+} ch_rings SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct real_definition *value;
-} reals SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 40,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 40);
+       __type(key, __u32);
+       __type(value, struct real_definition);
+} reals SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct lb_stats *value;
-} stats SEC(".maps") = {
-       .type = BPF_MAP_TYPE_PERCPU_ARRAY,
-       .max_entries = 515,
-};
+       __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
+       __uint(max_entries, 515);
+       __type(key, __u32);
+       __type(value, struct lb_stats);
+} stats SEC(".maps");
 
 struct {
-       __u32 type;
-       __u32 max_entries;
-       __u32 *key;
-       struct ctl_value *value;
-} ctl_array SEC(".maps") = {
-       .type = BPF_MAP_TYPE_ARRAY,
-       .max_entries = 16,
-};
+       __uint(type, BPF_MAP_TYPE_ARRAY);
+       __uint(max_entries, 16);
+       __type(key, __u32);
+       __type(value, struct ctl_value);
+} ctl_array SEC(".maps");
 
 struct eth_hdr {
        unsigned char eth_dest[6];