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
|
diff --git a/ebpf/tcpoptions/tcp.c b/ebpf/tcpoptions/tcp.c
index d61db80..955487d 100644
--- a/ebpf/tcpoptions/tcp.c
+++ b/ebpf/tcpoptions/tcp.c
@@ -29,11 +14,12 @@ __check(void *data, void *data_end, int length)
}
__noinline int
-option_parser(struct xdp_md *xdp)
+option_parser(struct xdp_md *xdp, __u8 offset)
{
int ret = 0;
barrier_var(ret);
+ barrier_var(offset);
return xdp ? 1 : ret;
}
@@ -41,23 +27,20 @@ static void
__parse_options(struct xdp_md *xdp, struct tcphdr *tcph)
{
int length = (tcph->doff << 2) - sizeof(struct tcphdr);
-
- __u32 *offset = get_buf();
- if (!offset)
- return;
+ __u8 offset;
/* Initialize offset to tcp options part. */
- *offset = (void *) (tcph + 1) - ctx_ptr(xdp, data);;
+ offset = (void *) (tcph + 1) - ctx_ptr(xdp, data);;
for (int i = 0; i < ((1<<4 /* bits number of doff */)<<2)-sizeof(struct tcphdr); i++) {
if (length <= 0)
break;
- int ret = option_parser(xdp);
+ int ret = option_parser(xdp, offset);
if (ret <= 0)
break;
- *offset += ret;
+ offset += ret;
length -= ret;
}
}
diff --git a/ebpf/tcpoptions/topt.c b/ebpf/tcpoptions/topt.c
index 216d363..76265fc 100644
--- a/ebpf/tcpoptions/topt.c
+++ b/ebpf/tcpoptions/topt.c
@@ -55,21 +55,6 @@ static volatile const __u32 TARGET_OPVAL_LEN = 0; // including the suffix '\0'
#define TCPOLEN_MARK 255
-struct {
- __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
- __type(key, int);
- __type(value, __u32);
- __uint(max_entries, 1);
-} buf SEC(".maps");
-
-static __always_inline __u32 *
-get_buf(void)
-{
- int key = 0;
-
- return bpf_map_lookup_elem(&buf, &key);
-}
-
struct tcp_option {
__u8 opsize;
char opname[35];
@@ -155,7 +140,7 @@ modify_option(void *data, void *data_end, __u8 opsize)
}
static int
-parse_option(struct xdp_md *xdp, __u8 /* should not be __u32 */ offset)
+parse_option(struct xdp_md *xdp, __u8 offset)
{
void *data = ctx_ptr(xdp, data) + offset;
void *data_end = ctx_ptr(xdp, data_end);
@@ -242,11 +227,7 @@ parse_option(struct xdp_md *xdp, __u8 /* should not be __u32 */ offset)
}
SEC("freplace/option_parser")
-int topt(struct xdp_md *xdp)
+int topt(struct xdp_md *xdp, __u8 offset)
{
- __u32 *offset = get_buf();
- if (!offset)
- return -1;
-
- return parse_option(xdp, *offset);
+ return parse_option(xdp, offset);
}
|