4
4
#include "map_structs.h"
5
5
#include <bpf/bpf_helpers.h>
6
6
7
+ #define PIN_BY_NAME 1
8
+
9
+ // NOTE(vadorovsky): The bpf_map_def struct from libbpf doesn't contain the
10
+ // `pinning` field. Aya uses it (for pinning maps, obviously). This kind of
11
+ // structure is used also in Cilium and even in few selftests in the kernel
12
+ // tree[1].
13
+ //
14
+ // [0] https://github.com/cilium/cilium/blob/v1.11.1/bpf/include/bpf/loader.h#L19-L29
15
+ // [1] https://elixir.bootlin.com/linux/v5.16.8/source/samples/bpf/tc_l2_redirect_kern.c#L23
16
+ /*
17
+ * bpf_elf_map - description of BPF map attributes. Saved in the ELF object.
18
+ */
19
+ struct bpf_elf_map {
20
+ u32 type ;
21
+ u32 key_size ;
22
+ u32 value_size ;
23
+ u32 max_entries ;
24
+ u32 flags ;
25
+ u32 id ;
26
+ u32 pinning ;
27
+ };
28
+
7
29
/*
8
30
* containers - BPF map containing the info about a policy which should be
9
31
* enforced on the given container.
10
32
*/
11
- struct bpf_map_def SEC ("maps/containers" ) containers = {
33
+ struct bpf_elf_map SEC ("maps/containers" ) containers = {
12
34
.type = BPF_MAP_TYPE_HASH ,
13
35
.max_entries = PID_MAX_LIMIT ,
14
36
.key_size = sizeof (struct container_id ),
15
37
.value_size = sizeof (struct container ),
38
+ .pinning = PIN_BY_NAME ,
16
39
};
17
40
18
41
/*
19
42
* processes - BPF map which maps the PID to a container it belongs to. The
20
43
* value of this map, which represents the container, is a key of `containers`
21
44
* BPF map, so it can be used immediately for lookups in `containers` map.
22
45
*/
23
- struct bpf_map_def SEC ("maps/processes" ) processes = {
46
+ struct bpf_elf_map SEC ("maps/processes" ) processes = {
24
47
.type = BPF_MAP_TYPE_HASH ,
25
48
.max_entries = PID_MAX_LIMIT ,
26
49
.key_size = sizeof (pid_t ),
27
50
.value_size = sizeof (struct process ),
51
+ .pinning = PIN_BY_NAME ,
28
52
};
29
53
30
54
/*
@@ -33,11 +57,12 @@ struct bpf_map_def SEC("maps/processes") processes = {
33
57
* paths used by default by container runtimes, not paths mounted with the -v
34
58
* option.
35
59
*/
36
- struct bpf_map_def SEC ("maps/ap_mnt_restr" ) ap_mnt_restr = {
60
+ struct bpf_elf_map SEC ("maps/ap_mnt_restr" ) ap_mnt_restr = {
37
61
.type = BPF_MAP_TYPE_HASH ,
38
62
.max_entries = PATH_MAX_LIMIT ,
39
63
.key_size = sizeof (u32 ),
40
64
.value_size = sizeof (struct accessed_path ),
65
+ .pinning = PIN_BY_NAME ,
41
66
};
42
67
43
68
/*
@@ -46,55 +71,60 @@ struct bpf_map_def SEC("maps/ap_mnt_restr") ap_mnt_restr = {
46
71
* used by default by container runtimes and paths we allow to mount with -v
47
72
* option.
48
73
*/
49
- struct bpf_map_def SEC ("maps/ap_mnt_base" ) ap_mnt_base = {
74
+ struct bpf_elf_map SEC ("maps/ap_mnt_base" ) ap_mnt_base = {
50
75
.type = BPF_MAP_TYPE_HASH ,
51
76
.max_entries = PATH_MAX_LIMIT ,
52
77
.key_size = sizeof (u32 ),
53
78
.value_size = sizeof (struct accessed_path ),
79
+ .pinning = PIN_BY_NAME ,
54
80
};
55
81
56
82
/*
57
83
* ap_acc_restr - BPF map which contains the path prefixes allowed to access
58
84
* (open, create, delete, move etc.) inside filesystems of restricted
59
85
* containers.
60
86
*/
61
- struct bpf_map_def SEC ("maps/ap_acc_restr" ) ap_acc_restr = {
87
+ struct bpf_elf_map SEC ("maps/ap_acc_restr" ) ap_acc_restr = {
62
88
.type = BPF_MAP_TYPE_HASH ,
63
89
.max_entries = PATH_MAX_LIMIT ,
64
90
.key_size = sizeof (u32 ),
65
91
.value_size = sizeof (struct accessed_path ),
92
+ .pinning = PIN_BY_NAME ,
66
93
};
67
94
68
95
/*
69
96
* ap_acc_base - BPF map which contains the path prefixes allowed to access
70
97
* (open, create, delete, move etc.) inside filesystems of baseline containers.
71
98
*/
72
- struct bpf_map_def SEC ("maps/ap_acc_base" ) ap_acc_base = {
99
+ struct bpf_elf_map SEC ("maps/ap_acc_base" ) ap_acc_base = {
73
100
.type = BPF_MAP_TYPE_HASH ,
74
101
.max_entries = PATH_MAX_LIMIT ,
75
102
.key_size = sizeof (u32 ),
76
103
.value_size = sizeof (struct accessed_path ),
104
+ .pinning = PIN_BY_NAME ,
77
105
};
78
106
79
107
/*
80
108
* dp_acc_restr - BPF map which contains the path prefixes denied to access
81
109
* (open, create, delete, move etc.) inside filesystems of restricted
82
110
* containers.
83
111
*/
84
- struct bpf_map_def SEC ("maps/dp_acc_restr" ) dp_acc_restr = {
112
+ struct bpf_elf_map SEC ("maps/dp_acc_restr" ) dp_acc_restr = {
85
113
.type = BPF_MAP_TYPE_HASH ,
86
114
.max_entries = PATH_MAX_LIMIT ,
87
115
.key_size = sizeof (u32 ),
88
116
.value_size = sizeof (struct accessed_path ),
117
+ .pinning = PIN_BY_NAME ,
89
118
};
90
119
91
120
/*
92
121
* dp_acc_base - BPF map which contains the path prefixes denied to access
93
122
* (open, create, delete, move etc.) inside filesystems of baseline containers.
94
123
*/
95
- struct bpf_map_def SEC ("maps/dp_acc_base" ) dp_acc_base = {
124
+ struct bpf_elf_map SEC ("maps/dp_acc_base" ) dp_acc_base = {
96
125
.type = BPF_MAP_TYPE_HASH ,
97
126
.max_entries = PATH_MAX_LIMIT ,
98
127
.key_size = sizeof (u32 ),
99
128
.value_size = sizeof (struct accessed_path ),
129
+ .pinning = PIN_BY_NAME ,
100
130
};
0 commit comments