WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / test_map_in_map.c
blob1cfeb940cf9fb259da3eb9fa864465b21e72794d
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2018 Facebook */
3 #include <stddef.h>
4 #include <linux/bpf.h>
5 #include <linux/types.h>
6 #include <bpf/bpf_helpers.h>
8 struct {
9 __uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
10 __uint(max_entries, 1);
11 __uint(map_flags, 0);
12 __uint(key_size, sizeof(__u32));
13 /* must be sizeof(__u32) for map in map */
14 __uint(value_size, sizeof(__u32));
15 } mim_array SEC(".maps");
17 struct {
18 __uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
19 __uint(max_entries, 1);
20 __uint(map_flags, 0);
21 __uint(key_size, sizeof(int));
22 /* must be sizeof(__u32) for map in map */
23 __uint(value_size, sizeof(__u32));
24 } mim_hash SEC(".maps");
26 SEC("xdp_mimtest")
27 int xdp_mimtest0(struct xdp_md *ctx)
29 int value = 123;
30 int *value_p;
31 int key = 0;
32 void *map;
34 map = bpf_map_lookup_elem(&mim_array, &key);
35 if (!map)
36 return XDP_DROP;
38 bpf_map_update_elem(map, &key, &value, 0);
39 value_p = bpf_map_lookup_elem(map, &key);
40 if (!value_p || *value_p != 123)
41 return XDP_DROP;
43 map = bpf_map_lookup_elem(&mim_hash, &key);
44 if (!map)
45 return XDP_DROP;
47 bpf_map_update_elem(map, &key, &value, 0);
49 return XDP_PASS;
52 int _version SEC("version") = 1;
53 char _license[] SEC("license") = "GPL";