Skip to content

Commit 62712a5

Browse files
committed
bpf: declare maps with __type for key and value
Using __type(key, type) instead of __uint(key_size, sizeof(type)), and similarly for value, adds BTF information on the map which can be useful. When using 'bpftool map dump' with the BTF information, the formatting is then correct according to the types. This patch is the result of running: find bpf -type f -exec sed -i -E 's/__uint\(value_size,\s*sizeof\(([^)]+)\)\)/__type(value, \1)/g' {} + find bpf -type f -exec sed -i -E 's/__uint\(key_size,\s*sizeof\(([^)]+)\)\)/__type(key, \1)/g' {} + Some __uint(value_size were kept because they did not use sizeof but literal integers. Signed-off-by: Mahe Tardy <[email protected]>
1 parent 675036f commit 62712a5

11 files changed

+34
-34
lines changed

bpf/process/addr_lpm_maps.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct addr4_lpm_trie {
1414
struct {
1515
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
1616
__uint(max_entries, ADDR_LPM_MAPS_OUTER_MAX_ENTRIES);
17-
__uint(key_size, sizeof(__u32));
17+
__type(key, __u32);
1818
__array(
1919
values, struct {
2020
__uint(type, BPF_MAP_TYPE_LPM_TRIE);
@@ -33,7 +33,7 @@ struct addr6_lpm_trie {
3333
struct {
3434
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
3535
__uint(max_entries, ADDR_LPM_MAPS_OUTER_MAX_ENTRIES);
36-
__uint(key_size, sizeof(__u32));
36+
__type(key, __u32);
3737
__array(
3838
values, struct {
3939
__uint(type, BPF_MAP_TYPE_LPM_TRIE);

bpf/process/argfilter_maps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
struct {
1010
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
1111
__uint(max_entries, ARGFILTER_MAPS_OUTER_MAX_ENTRIES);
12-
__uint(key_size, sizeof(__u32));
12+
__type(key, __u32);
1313
__array(
1414
values, struct {
1515
__uint(type, BPF_MAP_TYPE_HASH);

bpf/process/bpf_execve_event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int execve_send(void *ctx);
2323
struct {
2424
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
2525
__uint(max_entries, 2);
26-
__uint(key_size, sizeof(__u32));
26+
__type(key, __u32);
2727
__array(values, int(void *));
2828
} execve_calls SEC(".maps") = {
2929
.values = {

bpf/process/bpf_generic_kprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int generic_kprobe_output(void *ctx);
2626
struct {
2727
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
2828
__uint(max_entries, 13);
29-
__uint(key_size, sizeof(__u32));
29+
__type(key, __u32);
3030
__array(values, int(void *));
3131
} kprobe_calls SEC(".maps") = {
3232
.values = {

bpf/process/bpf_generic_lsm_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int generic_lsm_actions(void *ctx);
2727
struct {
2828
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
2929
__uint(max_entries, 13);
30-
__uint(key_size, sizeof(__u32));
30+
__type(key, __u32);
3131
__array(values, int(void *));
3232
} lsm_calls SEC(".maps") = {
3333
.values = {

bpf/process/bpf_generic_retkprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int generic_retkprobe_output(struct pt_regs *ctx);
2424
struct {
2525
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
2626
__uint(max_entries, 6);
27-
__uint(key_size, sizeof(__u32));
27+
__type(key, __u32);
2828
__array(values, int(struct pt_regs *));
2929
} retkprobe_calls SEC(".maps") = {
3030
.values = {

bpf/process/bpf_generic_tracepoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int generic_tracepoint_output(void *ctx);
2525
struct {
2626
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
2727
__uint(max_entries, 13);
28-
__uint(key_size, sizeof(__u32));
28+
__type(key, __u32);
2929
__array(values, int(void *));
3030
} tp_calls SEC(".maps") = {
3131
.values = {

bpf/process/bpf_generic_uprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int generic_uprobe_output(void *ctx);
2525
struct {
2626
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
2727
__uint(max_entries, 13);
28-
__uint(key_size, sizeof(__u32));
28+
__type(key, __u32);
2929
__array(values, int(void *));
3030
} uprobe_calls SEC(".maps") = {
3131
.values = {

bpf/process/policy_filter.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
struct {
1515
__uint(type, BPF_MAP_TYPE_LRU_HASH);
1616
__uint(max_entries, POLICY_FILTER_MAX_NAMESPACES);
17-
__uint(key_size, sizeof(u64));
18-
__uint(value_size, sizeof(u64));
17+
__type(key, u64);
18+
__type(value, u64);
1919
} tg_cgroup_namespace_map SEC(".maps");
2020

2121
struct {
2222
__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
2323
__uint(max_entries, POLICY_FILTER_MAX_POLICIES);
24-
__uint(key_size, sizeof(u32)); /* policy id */
24+
__type(key, u32); /* policy id */
2525
__array(
2626
values, struct {
2727
__uint(type, BPF_MAP_TYPE_HASH);
@@ -38,7 +38,7 @@ struct {
3838
struct {
3939
__uint(type, BPF_MAP_TYPE_HASH_OF_MAPS);
4040
__uint(max_entries, POLICY_FILTER_MAX_CGROUP_IDS);
41-
__uint(key_size, sizeof(__u64)); /* cgroup id */
41+
__type(key, __u64); /* cgroup id */
4242
__array(
4343
values, struct {
4444
__uint(type, BPF_MAP_TYPE_HASH);

bpf/process/string_maps.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
struct {
6666
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
6767
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
68-
__uint(key_size, sizeof(__u32));
68+
__type(key, __u32);
6969
__array(
7070
values, struct {
7171
__uint(type, BPF_MAP_TYPE_HASH);
@@ -78,7 +78,7 @@ struct {
7878
struct {
7979
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
8080
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
81-
__uint(key_size, sizeof(__u32));
81+
__type(key, __u32);
8282
__array(
8383
values, struct {
8484
__uint(type, BPF_MAP_TYPE_HASH);
@@ -91,7 +91,7 @@ struct {
9191
struct {
9292
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
9393
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
94-
__uint(key_size, sizeof(__u32));
94+
__type(key, __u32);
9595
__array(
9696
values, struct {
9797
__uint(type, BPF_MAP_TYPE_HASH);
@@ -104,7 +104,7 @@ struct {
104104
struct {
105105
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
106106
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
107-
__uint(key_size, sizeof(__u32));
107+
__type(key, __u32);
108108
__array(
109109
values, struct {
110110
__uint(type, BPF_MAP_TYPE_HASH);
@@ -117,7 +117,7 @@ struct {
117117
struct {
118118
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
119119
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
120-
__uint(key_size, sizeof(__u32));
120+
__type(key, __u32);
121121
__array(
122122
values, struct {
123123
__uint(type, BPF_MAP_TYPE_HASH);
@@ -130,7 +130,7 @@ struct {
130130
struct {
131131
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
132132
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
133-
__uint(key_size, sizeof(__u32));
133+
__type(key, __u32);
134134
__array(
135135
values, struct {
136136
__uint(type, BPF_MAP_TYPE_HASH);
@@ -143,7 +143,7 @@ struct {
143143
struct {
144144
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
145145
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
146-
__uint(key_size, sizeof(__u32));
146+
__type(key, __u32);
147147
__array(
148148
values, struct {
149149
__uint(type, BPF_MAP_TYPE_HASH);
@@ -156,7 +156,7 @@ struct {
156156
struct {
157157
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
158158
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
159-
__uint(key_size, sizeof(__u32));
159+
__type(key, __u32);
160160
__array(
161161
values, struct {
162162
__uint(type, BPF_MAP_TYPE_HASH);
@@ -170,7 +170,7 @@ struct {
170170
struct {
171171
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
172172
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
173-
__uint(key_size, sizeof(__u32));
173+
__type(key, __u32);
174174
__array(
175175
values, struct {
176176
__uint(type, BPF_MAP_TYPE_HASH);
@@ -183,7 +183,7 @@ struct {
183183
struct {
184184
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
185185
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
186-
__uint(key_size, sizeof(__u32));
186+
__type(key, __u32);
187187
__array(
188188
values, struct {
189189
__uint(type, BPF_MAP_TYPE_HASH);
@@ -196,7 +196,7 @@ struct {
196196
struct {
197197
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
198198
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
199-
__uint(key_size, sizeof(__u32));
199+
__type(key, __u32);
200200
__array(
201201
values, struct {
202202
__uint(type, BPF_MAP_TYPE_HASH);
@@ -210,14 +210,14 @@ struct {
210210
struct {
211211
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
212212
__uint(max_entries, 1);
213-
__uint(key_size, sizeof(__u32));
213+
__type(key, __u32);
214214
__uint(value_size, STRING_MAPS_HEAP_SIZE);
215215
} string_maps_heap SEC(".maps");
216216

217217
struct {
218218
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
219219
__uint(max_entries, 1);
220-
__uint(key_size, sizeof(__u32));
220+
__type(key, __u32);
221221
__uint(value_size, STRING_MAPS_HEAP_SIZE);
222222
} string_maps_ro_zero SEC(".maps");
223223

@@ -231,7 +231,7 @@ struct string_prefix_lpm_trie {
231231
struct {
232232
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
233233
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
234-
__uint(key_size, sizeof(__u32));
234+
__type(key, __u32);
235235
__array(
236236
values, struct {
237237
__uint(type, BPF_MAP_TYPE_LPM_TRIE);
@@ -245,8 +245,8 @@ struct {
245245
struct {
246246
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
247247
__uint(max_entries, 1);
248-
__uint(key_size, sizeof(__u32));
249-
__uint(value_size, sizeof(struct string_prefix_lpm_trie));
248+
__type(key, __u32);
249+
__type(value, struct string_prefix_lpm_trie);
250250
} string_prefix_maps_heap SEC(".maps");
251251

252252
#define STRING_POSTFIX_MAX_LENGTH 128
@@ -265,7 +265,7 @@ struct string_postfix_lpm_trie {
265265
struct {
266266
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
267267
__uint(max_entries, STRING_MAPS_OUTER_MAX_ENTRIES);
268-
__uint(key_size, sizeof(__u32));
268+
__type(key, __u32);
269269
__array(
270270
values, struct {
271271
__uint(type, BPF_MAP_TYPE_LPM_TRIE);
@@ -279,8 +279,8 @@ struct {
279279
struct {
280280
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
281281
__uint(max_entries, 1);
282-
__uint(key_size, sizeof(__u32));
283-
__uint(value_size, sizeof(struct string_postfix_lpm_trie));
282+
__type(key, __u32);
283+
__type(value, struct string_postfix_lpm_trie);
284284
} string_postfix_maps_heap SEC(".maps");
285285

286286
#endif // STRING_MAPS_H__

0 commit comments

Comments
 (0)