-
Notifications
You must be signed in to change notification settings - Fork 2
/
map_definition.go
456 lines (398 loc) · 19.2 KB
/
map_definition.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
package gobpfld
import (
"fmt"
"unsafe"
"github.com/dylandreimerink/gobpfld/bpfsys"
"github.com/dylandreimerink/gobpfld/bpftypes"
"github.com/dylandreimerink/gobpfld/kernelsupport"
)
// bpfMapDefSize is the size of BPFMapDef in bytes
var bpfMapDefSize = int(unsafe.Sizeof(BPFMapDef{}))
type BPFMapDef struct {
// Type describes map type this map is
Type bpftypes.BPFMapType
// KeySize is the size of the map key in bytes
KeySize uint32
// ValueSize is the size of the map value in bytes
ValueSize uint32
// MaxEntries is the maximum amount of entries in a map. Depending on the map type and flags, memory for all of
// these entries might be allocated on map creation or dynamically when inserting.
MaxEntries uint32
// Flags can be used to ask the kernel for special behavior, not all flags are allowed on all map types.
Flags bpftypes.BPFMapFlags
}
// Equal checks if two map definitions are functionally identical
func (def BPFMapDef) Equal(other BPFMapDef) bool {
return def.Type == other.Type &&
def.KeySize == other.KeySize &&
def.ValueSize == other.ValueSize &&
def.MaxEntries == other.MaxEntries &&
def.Flags == other.Flags
}
// Validate checks if the map definition is valid, the kernel also does these checks but if the kernel finds an error
// it doesn't return a nice error message. This give a better user experience.
func (def BPFMapDef) Validate() error {
if kfeat, found := mapTypeToKFeature[def.Type]; found {
if !kernelsupport.CurrentFeatures.Map.Has(kfeat) {
return fmt.Errorf("map type '%s' not supported: %s", def.Type, bpfsys.ErrNotSupported)
}
}
if err := def.validateSizes(); err != nil {
return err
}
if err := def.validateFlags(); err != nil {
return err
}
switch def.Type {
case bpftypes.BPF_MAP_TYPE_STACK_TRACE:
// TODO value_size % 8 == 0
// TODO stack build id check https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/stackmap.c#L108
case bpftypes.BPF_MAP_TYPE_DEVMAP, bpftypes.BPF_MAP_TYPE_DEVMAP_HASH:
// TODO check value_size, which is dependant on host architecture
case bpftypes.BPF_MAP_TYPE_SOCKMAP:
// TODO check value_size, which is dependant on host architecture
case bpftypes.BPF_MAP_TYPE_CPUMAP:
// TODO check value_size, which is dependant on host architecture
case bpftypes.BPF_MAP_TYPE_CGROUP_STORAGE, bpftypes.BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
bpftypes.BPF_MAP_TYPE_INODE_STORAGE, bpftypes.BPF_MAP_TYPE_TASK_STORAGE:
// TODO check key_size
case bpftypes.BPF_MAP_TYPE_REUSEPORT_SOCKARRAY:
// TODO check value size
case bpftypes.BPF_MAP_TYPE_STRUCT_OPS:
// TODO check key size
case bpftypes.BPF_MAP_TYPE_RINGBUF:
// TODO max_entries is a power of 2 and page aligned
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/ringbuf.c#L154
}
return nil
}
func (def BPFMapDef) validateFlags() error {
requiredFlags := map[bpftypes.BPFMapType][]bpftypes.BPFMapFlags{
bpftypes.BPF_MAP_TYPE_LPM_TRIE: {
bpftypes.BPFMapFlagsNoPreAlloc,
},
}
if rFlags, ok := requiredFlags[def.Type]; ok {
for _, requiredFlag := range rFlags {
if def.Flags&requiredFlag == 0 {
return fmt.Errorf("maps of type %s must have the the %s flag set, map has the following flags set: %s",
def.Type, requiredFlag, def.Flags)
}
}
}
permittedFlags := map[bpftypes.BPFMapType]bpftypes.BPFMapFlags{
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/hashtab.c#L369
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/hashtab.c#L17
bpftypes.BPF_MAP_TYPE_HASH: bpftypes.BPFMapFlagsNoPreAlloc |
bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg |
bpftypes.BPFMapFlagsZeroSeed,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L631
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L17
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L51
bpftypes.BPF_MAP_TYPE_ARRAY: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsMMapable |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg |
bpftypes.BPFMapFlagsInnerMap,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L1046
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L668
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L59
bpftypes.BPF_MAP_TYPE_PROG_ARRAY: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L1153
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L668
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L59
bpftypes.BPF_MAP_TYPE_PERF_EVENT_ARRAY: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/hashtab.c#L369
bpftypes.BPF_MAP_TYPE_PERCPU_HASH: bpftypes.BPFMapFlagsNoPreAlloc |
bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg |
bpftypes.BPFMapFlagsZeroSeed,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L654
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L17
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L59
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L64
bpftypes.BPF_MAP_TYPE_PERCPU_ARRAY: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/stackmap.c#L16
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/stackmap.c#L89
bpftypes.BPF_MAP_TYPE_STACK_TRACE: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsStackBuildID,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L1190
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L668
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L59
bpftypes.BPF_MAP_TYPE_CGROUP_ARRAY: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/hashtab.c#L369
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/hashtab.c#L404
bpftypes.BPF_MAP_TYPE_LRU_HASH: bpftypes.BPFMapFlagsNoCommonLRU |
bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg |
bpftypes.BPFMapFlagsZeroSeed,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/hashtab.c#L369
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/hashtab.c#L404
bpftypes.BPF_MAP_TYPE_LRU_PERCPU_HASH: bpftypes.BPFMapFlagsNoCommonLRU |
bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg |
bpftypes.BPFMapFlagsZeroSeed,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/lpm_trie.c#L537
bpftypes.BPF_MAP_TYPE_LPM_TRIE: bpftypes.BPFMapFlagsNoPreAlloc |
bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L1276
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L668
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L59
bpftypes.BPF_MAP_TYPE_ARRAY_OF_MAPS: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L1046
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L668
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/arraymap.c#L59
bpftypes.BPF_MAP_TYPE_HASH_OF_MAPS: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly,
bpftypes.BPF_MAP_TYPE_DEVMAP: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly,
bpftypes.BPF_MAP_TYPE_SOCKMAP: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly,
bpftypes.BPF_MAP_TYPE_CPUMAP: bpftypes.BPFMapFlagsNUMANode,
bpftypes.BPF_MAP_TYPE_XSKMAP: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly,
// bpftypes.BPF_MAP_TYPE_SOCKHASH:
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/local_storage.c#L18
bpftypes.BPF_MAP_TYPE_CGROUP_STORAGE: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/reuseport_array.c#L43
bpftypes.BPF_MAP_TYPE_REUSEPORT_SOCKARRAY: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsMMapable |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg |
bpftypes.BPFMapFlagsInnerMap,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/local_storage.c#L18
bpftypes.BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/queue_stack_maps.c#L13
bpftypes.BPF_MAP_TYPE_QUEUE: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/queue_stack_maps.c#L13
bpftypes.BPF_MAP_TYPE_STACK: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg,
// bpftypes.BPF_MAP_TYPE_SK_STORAGE:
bpftypes.BPF_MAP_TYPE_DEVMAP_HASH: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly,
// https://elixir.bootlin.com/linux/v5.11.15/source/kernel/bpf/bpf_struct_ops.c#L540
bpftypes.BPF_MAP_TYPE_STRUCT_OPS: 0,
bpftypes.BPF_MAP_TYPE_RINGBUF: bpftypes.BPFMapFlagsNUMANode,
bpftypes.BPF_MAP_TYPE_INODE_STORAGE: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg,
bpftypes.BPF_MAP_TYPE_TASK_STORAGE: bpftypes.BPFMapFlagsNUMANode |
bpftypes.BPFMapFlagsReadOnly |
bpftypes.BPFMapFlagsWriteOnly |
bpftypes.BPFMapFlagsReadOnlyProg |
bpftypes.BPFMapFlagsWriteOnlyProg,
}
if pFlags, ok := permittedFlags[def.Type]; ok {
// For each flag that exists
for f := bpftypes.BPFMapFlags(1); f < bpftypes.BPFMapFlagsMax; f = f << 1 {
// If this flag is in the def and it is not permitted
if def.Flags&f > 0 && f&pFlags == 0 {
return fmt.Errorf(
"maps of type %s may not have the %s flag set, "+
"map has the following flags set: %s, "+
"only the following flags are allowed: %s",
def.Type, f, def.Flags, pFlags)
}
}
// If both the program read-only and write-only flags are set
if def.Flags&(bpftypes.BPFMapFlagsReadOnlyProg|bpftypes.BPFMapFlagsWriteOnlyProg) ==
(bpftypes.BPFMapFlagsReadOnlyProg | bpftypes.BPFMapFlagsWriteOnlyProg) {
return fmt.Errorf(
"the %s and %s flags are mutually exclusive",
bpftypes.BPFMapFlagsReadOnlyProg,
bpftypes.BPFMapFlagsWriteOnlyProg,
)
}
}
return nil
}
func (def BPFMapDef) validateSizes() error {
keySizes := map[bpftypes.BPFMapType]uint32{
bpftypes.BPF_MAP_TYPE_ARRAY: 4,
bpftypes.BPF_MAP_TYPE_PROG_ARRAY: 4,
bpftypes.BPF_MAP_TYPE_PERF_EVENT_ARRAY: 4,
bpftypes.BPF_MAP_TYPE_PERCPU_ARRAY: 4,
bpftypes.BPF_MAP_TYPE_STACK_TRACE: 4,
bpftypes.BPF_MAP_TYPE_CGROUP_ARRAY: 4,
bpftypes.BPF_MAP_TYPE_ARRAY_OF_MAPS: 4,
bpftypes.BPF_MAP_TYPE_DEVMAP: 4,
bpftypes.BPF_MAP_TYPE_SOCKMAP: 4,
bpftypes.BPF_MAP_TYPE_CPUMAP: 4,
bpftypes.BPF_MAP_TYPE_XSKMAP: 4,
bpftypes.BPF_MAP_TYPE_REUSEPORT_SOCKARRAY: 4,
bpftypes.BPF_MAP_TYPE_QUEUE: 0,
bpftypes.BPF_MAP_TYPE_STACK: 0,
bpftypes.BPF_MAP_TYPE_DEVMAP_HASH: 4,
bpftypes.BPF_MAP_TYPE_RINGBUF: 0,
}
if exactSize, ok := keySizes[def.Type]; ok && exactSize != def.KeySize {
return fmt.Errorf("maps of type %s must always have a key size of %d bytes, "+
"key size of this map is %d bytes", def.Type, exactSize, def.KeySize)
}
minKeySizes := map[bpftypes.BPFMapType]uint32{
bpftypes.BPF_MAP_TYPE_HASH: 1,
bpftypes.BPF_MAP_TYPE_PERCPU_HASH: 1,
bpftypes.BPF_MAP_TYPE_LRU_HASH: 1,
bpftypes.BPF_MAP_TYPE_LRU_PERCPU_HASH: 1,
bpftypes.BPF_MAP_TYPE_LPM_TRIE: 6,
}
if minSize, ok := minKeySizes[def.Type]; ok && def.KeySize < minSize {
return fmt.Errorf("maps of type %s must have a key size of at least %d bytes, "+
"key size of this map is %d bytes", def.Type, minSize, def.KeySize)
}
exactValueSizes := map[bpftypes.BPFMapType]uint32{
bpftypes.BPF_MAP_TYPE_PROG_ARRAY: 4,
bpftypes.BPF_MAP_TYPE_PERF_EVENT_ARRAY: 4,
bpftypes.BPF_MAP_TYPE_CGROUP_ARRAY: 4,
bpftypes.BPF_MAP_TYPE_ARRAY_OF_MAPS: 4,
bpftypes.BPF_MAP_TYPE_HASH_OF_MAPS: 4,
bpftypes.BPF_MAP_TYPE_XSKMAP: 4,
bpftypes.BPF_MAP_TYPE_RINGBUF: 0,
}
if exactSize, ok := exactValueSizes[def.Type]; ok && exactSize != def.ValueSize {
return fmt.Errorf("maps of type %s must always have a value size of %d bytes, "+
"value size of this map is %d bytes", def.Type, exactSize, def.ValueSize)
}
minValueSizes := map[bpftypes.BPFMapType]uint32{
bpftypes.BPF_MAP_TYPE_HASH: 1,
bpftypes.BPF_MAP_TYPE_ARRAY: 1,
bpftypes.BPF_MAP_TYPE_PERCPU_HASH: 1,
bpftypes.BPF_MAP_TYPE_PERCPU_ARRAY: 1,
bpftypes.BPF_MAP_TYPE_STACK_TRACE: 8,
bpftypes.BPF_MAP_TYPE_LRU_HASH: 1,
bpftypes.BPF_MAP_TYPE_LRU_PERCPU_HASH: 1,
bpftypes.BPF_MAP_TYPE_LPM_TRIE: 1,
bpftypes.BPF_MAP_TYPE_CGROUP_STORAGE: 1,
bpftypes.BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE: 1,
bpftypes.BPF_MAP_TYPE_QUEUE: 1,
bpftypes.BPF_MAP_TYPE_STACK: 1,
bpftypes.BPF_MAP_TYPE_INODE_STORAGE: 1,
bpftypes.BPF_MAP_TYPE_TASK_STORAGE: 1,
}
if minSize, ok := minValueSizes[def.Type]; ok && def.ValueSize < minSize {
return fmt.Errorf("maps of type %s must have a value size of at least %d bytes, "+
"value size of this map is %d bytes", def.Type, minSize, def.ValueSize)
}
minEntries := map[bpftypes.BPFMapType]uint32{
bpftypes.BPF_MAP_TYPE_HASH: 1,
bpftypes.BPF_MAP_TYPE_ARRAY: 1,
bpftypes.BPF_MAP_TYPE_PROG_ARRAY: 1,
bpftypes.BPF_MAP_TYPE_PERF_EVENT_ARRAY: 1,
bpftypes.BPF_MAP_TYPE_PERCPU_HASH: 1,
bpftypes.BPF_MAP_TYPE_PERCPU_ARRAY: 1,
bpftypes.BPF_MAP_TYPE_CGROUP_ARRAY: 1,
bpftypes.BPF_MAP_TYPE_LRU_HASH: 1,
bpftypes.BPF_MAP_TYPE_LRU_PERCPU_HASH: 1,
bpftypes.BPF_MAP_TYPE_ARRAY_OF_MAPS: 1,
bpftypes.BPF_MAP_TYPE_DEVMAP: 1,
bpftypes.BPF_MAP_TYPE_SOCKMAP: 1,
bpftypes.BPF_MAP_TYPE_CPUMAP: 1,
bpftypes.BPF_MAP_TYPE_REUSEPORT_SOCKARRAY: 1,
bpftypes.BPF_MAP_TYPE_DEVMAP_HASH: 1,
bpftypes.BPF_MAP_TYPE_STRUCT_OPS: 1,
}
if minEntries, ok := minEntries[def.Type]; ok && def.MaxEntries < minEntries {
return fmt.Errorf("maps of type %s must have a max_entries number of at least %d, "+
"max_entries of this map is %d", def.Type, minEntries, def.MaxEntries)
}
maxEntries := map[bpftypes.BPFMapType]uint32{
bpftypes.BPF_MAP_TYPE_CGROUP_STORAGE: 0,
bpftypes.BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE: 0,
bpftypes.BPF_MAP_TYPE_STRUCT_OPS: 1,
bpftypes.BPF_MAP_TYPE_INODE_STORAGE: 0,
bpftypes.BPF_MAP_TYPE_TASK_STORAGE: 0,
}
if maxEntries, ok := maxEntries[def.Type]; ok && def.MaxEntries > maxEntries {
return fmt.Errorf("maps of type %s must have a max_entries number of at most %d, "+
"max_entries of this map is %d", def.Type, maxEntries, def.MaxEntries)
}
return nil
}
var mapTypeToKFeature = map[bpftypes.BPFMapType]kernelsupport.MapSupport{
bpftypes.BPF_MAP_TYPE_HASH: kernelsupport.KFeatMapHash,
bpftypes.BPF_MAP_TYPE_ARRAY: kernelsupport.KFeatMapArray,
bpftypes.BPF_MAP_TYPE_PROG_ARRAY: kernelsupport.KFeatMapTailCall,
bpftypes.BPF_MAP_TYPE_PERF_EVENT_ARRAY: kernelsupport.KFeatMapPerfEvent,
bpftypes.BPF_MAP_TYPE_PERCPU_HASH: kernelsupport.KFeatMapPerCPUHash,
bpftypes.BPF_MAP_TYPE_PERCPU_ARRAY: kernelsupport.KFeatMapPerCPUArray,
bpftypes.BPF_MAP_TYPE_STACK_TRACE: kernelsupport.KFeatMapStackTrace,
bpftypes.BPF_MAP_TYPE_CGROUP_ARRAY: kernelsupport.KFeatMapCGroupArray,
bpftypes.BPF_MAP_TYPE_LRU_HASH: kernelsupport.KFeatMapLRUHash,
bpftypes.BPF_MAP_TYPE_LRU_PERCPU_HASH: kernelsupport.KFeatMapLRUPerCPUHash,
bpftypes.BPF_MAP_TYPE_LPM_TRIE: kernelsupport.KFeatMapLPMTrie,
bpftypes.BPF_MAP_TYPE_ARRAY_OF_MAPS: kernelsupport.KFeatMapArrayOfMaps,
bpftypes.BPF_MAP_TYPE_HASH_OF_MAPS: kernelsupport.KFeatMapHashOfMaps,
bpftypes.BPF_MAP_TYPE_DEVMAP: kernelsupport.KFeatMapNetdevArray,
bpftypes.BPF_MAP_TYPE_SOCKMAP: kernelsupport.KFeatMapSocketArray,
bpftypes.BPF_MAP_TYPE_CPUMAP: kernelsupport.KFeatMapCPU,
bpftypes.BPF_MAP_TYPE_XSKMAP: kernelsupport.KFeatMapAFXDP,
bpftypes.BPF_MAP_TYPE_SOCKHASH: kernelsupport.KFeatMapSocketHash,
bpftypes.BPF_MAP_TYPE_CGROUP_STORAGE: kernelsupport.KFeatMapCGroupStorage,
bpftypes.BPF_MAP_TYPE_REUSEPORT_SOCKARRAY: kernelsupport.KFeatMapReuseportSocketArray,
bpftypes.BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE: kernelsupport.KFeatMapPerCPUCGroupStorage,
bpftypes.BPF_MAP_TYPE_QUEUE: kernelsupport.KFeatMapQueue,
bpftypes.BPF_MAP_TYPE_STACK: kernelsupport.KFeatMapStack,
bpftypes.BPF_MAP_TYPE_SK_STORAGE: kernelsupport.KFeatMapSocketLocalStorage,
bpftypes.BPF_MAP_TYPE_DEVMAP_HASH: kernelsupport.KFeatMapNetdevHash,
bpftypes.BPF_MAP_TYPE_STRUCT_OPS: kernelsupport.KFeatMapStructOps,
bpftypes.BPF_MAP_TYPE_RINGBUF: kernelsupport.KFeatMapRingBuffer,
bpftypes.BPF_MAP_TYPE_INODE_STORAGE: kernelsupport.KFeatMapINodeStorage,
bpftypes.BPF_MAP_TYPE_TASK_STORAGE: kernelsupport.KFeatMapTaskStorage,
}