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
|
// SPDX-License-Identifier: GPL-2.0
#include <vmlinux.h>
#include <bpf/bpf_helpers.h>
#include "bpf_misc.h"
#include "bpf_kfuncs.h"
char _license[] SEC("license") = "GPL";
struct inner_map {
__uint(type, BPF_MAP_TYPE_ARRAY);
__uint(max_entries, 1);
__type(key, int);
__type(value, int);
} inner_map SEC(".maps");
struct {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(max_entries, 1);
__type(key, int);
__array(values, struct inner_map);
} outer_map SEC(".maps") = {
.values = { [0] = &inner_map },
};
SEC("?tc")
__failure __msg("type=map_ptr_or_null expected=fp")
int mapofmaps_value_as_kfunc_mem_buf(struct __sk_buff *skb)
{
struct bpf_dynptr dptr;
__u32 key = 0;
void *inner;
char *p;
inner = bpf_map_lookup_elem(&outer_map, &key);
/* intentionally NOT NULL-checked: type is map_ptr_or_null */
bpf_dynptr_from_skb(skb, 0, &dptr);
/* arg3 is mem+size */
p = bpf_dynptr_slice(&dptr, 0, inner, 4);
if (p)
return p[0];
return 0;
}
SEC("?tc")
__failure __msg("type=map_ptr_or_null expected=fp")
int mapofmaps_value_as_helper_mem_buf(struct __sk_buff *skb)
{
__u32 key = 0;
void *inner;
inner = bpf_map_lookup_elem(&outer_map, &key);
/* intentionally NOT NULL-checked: type is map_ptr_or_null */
/* arg1 is mem+size */
return bpf_csum_diff(inner, 4, NULL, 0, 0) + skb->len;
}
SEC("?tc")
__failure __msg("type=map_ptr_or_null expected=fp")
int mapofmaps_value_as_helper_fixed_mem(struct __sk_buff *skb)
{
char th[sizeof(struct tcphdr)] = {};
__u32 key = 0;
void *inner;
inner = bpf_map_lookup_elem(&outer_map, &key);
/* intentionally NOT NULL-checked: type is map_ptr_or_null */
/* arg1 is fixed-sized mem */
return bpf_tcp_raw_check_syncookie_ipv4(inner, (void *)th);
}
|