1*1022b67bSRhys Rustad-Elliott // SPDX-License-Identifier: GPL-2.0-only
2*1022b67bSRhys Rustad-Elliott 
3*1022b67bSRhys Rustad-Elliott #include <linux/bpf.h>
4*1022b67bSRhys Rustad-Elliott #include <bpf/bpf_helpers.h>
5*1022b67bSRhys Rustad-Elliott 
6*1022b67bSRhys Rustad-Elliott struct inner_map {
7*1022b67bSRhys Rustad-Elliott 	__uint(type, BPF_MAP_TYPE_ARRAY);
8*1022b67bSRhys Rustad-Elliott 	__uint(max_entries, 5);
9*1022b67bSRhys Rustad-Elliott 	__type(key, int);
10*1022b67bSRhys Rustad-Elliott 	__type(value, int);
11*1022b67bSRhys Rustad-Elliott } inner_map1 SEC(".maps");
12*1022b67bSRhys Rustad-Elliott 
13*1022b67bSRhys Rustad-Elliott struct outer_map {
14*1022b67bSRhys Rustad-Elliott 	__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
15*1022b67bSRhys Rustad-Elliott 	__uint(max_entries, 3);
16*1022b67bSRhys Rustad-Elliott 	__type(key, int);
17*1022b67bSRhys Rustad-Elliott 	__array(values, struct inner_map);
18*1022b67bSRhys Rustad-Elliott } outer_map1 SEC(".maps") = {
19*1022b67bSRhys Rustad-Elliott 	.values = {
20*1022b67bSRhys Rustad-Elliott 		[2] = &inner_map1,
21*1022b67bSRhys Rustad-Elliott 	},
22*1022b67bSRhys Rustad-Elliott };
23*1022b67bSRhys Rustad-Elliott 
24*1022b67bSRhys Rustad-Elliott SEC("raw_tp/sys_enter")
handle__sys_enter(void * ctx)25*1022b67bSRhys Rustad-Elliott int handle__sys_enter(void *ctx)
26*1022b67bSRhys Rustad-Elliott {
27*1022b67bSRhys Rustad-Elliott 	int outer_key = 2, inner_key = 3;
28*1022b67bSRhys Rustad-Elliott 	int *val;
29*1022b67bSRhys Rustad-Elliott 	void *map;
30*1022b67bSRhys Rustad-Elliott 
31*1022b67bSRhys Rustad-Elliott 	map = bpf_map_lookup_elem(&outer_map1, &outer_key);
32*1022b67bSRhys Rustad-Elliott 	if (!map)
33*1022b67bSRhys Rustad-Elliott 		return 1;
34*1022b67bSRhys Rustad-Elliott 
35*1022b67bSRhys Rustad-Elliott 	val = bpf_map_lookup_elem(map, &inner_key);
36*1022b67bSRhys Rustad-Elliott 	if (!val)
37*1022b67bSRhys Rustad-Elliott 		return 1;
38*1022b67bSRhys Rustad-Elliott 
39*1022b67bSRhys Rustad-Elliott 	if (*val == 1)
40*1022b67bSRhys Rustad-Elliott 		*val = 2;
41*1022b67bSRhys Rustad-Elliott 
42*1022b67bSRhys Rustad-Elliott 	return 0;
43*1022b67bSRhys Rustad-Elliott }
44*1022b67bSRhys Rustad-Elliott 
45*1022b67bSRhys Rustad-Elliott char _license[] SEC("license") = "GPL";
46