1 #include "../../include/bpf_api.h"
2
3 #define MAP_INNER_ID 42
4
5 struct bpf_elf_map __section_maps map_inner = {
6 .type = BPF_MAP_TYPE_ARRAY,
7 .size_key = sizeof(uint32_t),
8 .size_value = sizeof(uint32_t),
9 .id = MAP_INNER_ID,
10 .inner_idx = 0,
11 .pinning = PIN_GLOBAL_NS,
12 .max_elem = 1,
13 };
14
15 struct bpf_elf_map __section_maps map_outer = {
16 .type = BPF_MAP_TYPE_ARRAY_OF_MAPS,
17 .size_key = sizeof(uint32_t),
18 .size_value = sizeof(uint32_t),
19 .inner_id = MAP_INNER_ID,
20 .pinning = PIN_GLOBAL_NS,
21 .max_elem = 1,
22 };
23
24 __section("egress")
emain(struct __sk_buff * skb)25 int emain(struct __sk_buff *skb)
26 {
27 struct bpf_elf_map *map_inner;
28 int key = 0, *val;
29
30 map_inner = map_lookup_elem(&map_outer, &key);
31 if (map_inner) {
32 val = map_lookup_elem(map_inner, &key);
33 if (val)
34 lock_xadd(val, 1);
35 }
36
37 return BPF_H_DEFAULT;
38 }
39
40 __section("ingress")
imain(struct __sk_buff * skb)41 int imain(struct __sk_buff *skb)
42 {
43 struct bpf_elf_map *map_inner;
44 int key = 0, *val;
45
46 map_inner = map_lookup_elem(&map_outer, &key);
47 if (map_inner) {
48 val = map_lookup_elem(map_inner, &key);
49 if (val)
50 printt("map val: %d\n", *val);
51 }
52
53 return BPF_H_DEFAULT;
54 }
55
56 BPF_LICENSE("GPL");
57