Skip to content

Commit 4cc6930

Browse files
committed
update new os patch for new kernel adapt
Signed-off-by: lec-bit <glfhmzmy@126.com>
1 parent e368968 commit 4cc6930

9 files changed

+153
-688
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
From 03cea45be513a52a0c57c022594d6a5e98450642 Mon Sep 17 00:00:00 2001
2+
From: zhangmingyi <zhangmingyi@huawei.com>
3+
Date: Thu, 9 Jan 2025 07:27:31 +0000
4+
Subject: [PATCH 1/2] add helper strnstr strncmp parse_header_msg
5+
6+
User messages need to be parsed when the bpf link establishment
7+
is delayed. add three helper func to parse and operate str.
8+
9+
Signed-off-by: zhangmingyi <zhangmingyi@huawei.com>
10+
---
11+
include/uapi/linux/bpf.h | 3 ++
12+
net/core/filter.c | 67 ++++++++++++++++++++++++++++++++++
13+
tools/include/uapi/linux/bpf.h | 3 ++
14+
3 files changed, 73 insertions(+)
15+
16+
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
17+
index fcda8b986..bd2235fc4 100644
18+
--- a/include/uapi/linux/bpf.h
19+
+++ b/include/uapi/linux/bpf.h
20+
@@ -4051,6 +4051,9 @@ union bpf_attr {
21+
FN(cpumask_op), \
22+
FN(cpus_share_cache), \
23+
FN(is_local_ipaddr), \
24+
+ FN(km_header_strnstr), \
25+
+ FN(km_header_strncmp), \
26+
+ FN(parse_header_msg), \
27+
/* */
28+
29+
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
30+
diff --git a/net/core/filter.c b/net/core/filter.c
31+
index 431e778bb..4a5d944c9 100644
32+
--- a/net/core/filter.c
33+
+++ b/net/core/filter.c
34+
@@ -6986,6 +6986,67 @@ const struct bpf_func_proto bpf_sock_ops_get_sk_rx_dst_proto = {
35+
};
36+
37+
#endif /* CONFIG_INET */
38+
+typedef int (*bpf_parse_protocol_func)(struct bpf_sock_addr_kern* ctx);
39+
+bpf_parse_protocol_func parse_protocol_func = NULL;
40+
+EXPORT_SYMBOL(parse_protocol_func);
41+
+
42+
+typedef int (*bpf_km_header_strnstr_func)(struct bpf_sock_addr_kern *ctx, const char *key, int key_sz, const char *subptr, int subptr_sz);
43+
+bpf_km_header_strnstr_func km_header_strnstr_func = NULL;
44+
+EXPORT_SYMBOL(km_header_strnstr_func);
45+
+
46+
+typedef int (*bpf_km_header_strncmp_func)(const char *key, int key_sz, const char *target, int target_sz, int opt);
47+
+bpf_km_header_strncmp_func km_header_strncmp_func = NULL;
48+
+EXPORT_SYMBOL(km_header_strncmp_func);
49+
+
50+
+BPF_CALL_1(bpf_parse_header_msg, struct bpf_sock_addr_kern *, ctx)
51+
+{
52+
+ if (!parse_protocol_func)
53+
+ return -ENOTSUPP;
54+
+ return parse_protocol_func(ctx);
55+
+}
56+
+
57+
+static const struct bpf_func_proto bpf_parse_header_msg_proto = {
58+
+ .func = bpf_parse_header_msg,
59+
+ .gpl_only = false,
60+
+ .ret_type = RET_INTEGER,
61+
+ .arg1_type = ARG_PTR_TO_CTX,
62+
+};
63+
+
64+
+BPF_CALL_5(bpf_km_header_strnstr, struct bpf_sock_addr_kern *, ctx, const char *, key, int , key_sz, const char *, subptr, int, subptr_sz)
65+
+{
66+
+ if (!km_header_strnstr_func)
67+
+ return -ENOTSUPP;
68+
+ return km_header_strnstr_func(ctx, key, key_sz, subptr, subptr_sz);
69+
+}
70+
+
71+
+static const struct bpf_func_proto bpf_km_header_strnstr_proto = {
72+
+ .func = bpf_km_header_strnstr,
73+
+ .gpl_only = false,
74+
+ .ret_type = RET_INTEGER,
75+
+ .arg1_type = ARG_PTR_TO_CTX,
76+
+ .arg2_type = ARG_PTR_TO_MEM | MEM_RDONLY,
77+
+ .arg3_type = ARG_CONST_SIZE,
78+
+ .arg4_type = ARG_PTR_TO_MEM | MEM_RDONLY,
79+
+ .arg5_type = ARG_CONST_SIZE,
80+
+};
81+
+
82+
+BPF_CALL_5(bpf_km_header_strncmp, const char *, key, int , key_sz, const char *, target, int, target_sz, int, opt)
83+
+{
84+
+ if (!km_header_strncmp_func)
85+
+ return -ENOTSUPP;
86+
+ return km_header_strncmp_func(key, key_sz, target, target_sz, opt);
87+
+}
88+
+
89+
+static const struct bpf_func_proto bpf_km_header_strncmp_proto = {
90+
+ .func = bpf_km_header_strncmp,
91+
+ .gpl_only = false,
92+
+ .ret_type = RET_INTEGER,
93+
+ .arg1_type = ARG_PTR_TO_MEM | MEM_RDONLY,
94+
+ .arg2_type = ARG_CONST_SIZE,
95+
+ .arg3_type = ARG_PTR_TO_MEM | MEM_RDONLY,
96+
+ .arg4_type = ARG_CONST_SIZE,
97+
+ .arg5_type = ARG_ANYTHING,
98+
+};
99+
100+
bool bpf_helper_changes_pkt_data(void *func)
101+
{
102+
@@ -7139,6 +7200,12 @@ sock_addr_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
103+
default:
104+
return NULL;
105+
}
106+
+ case BPF_FUNC_parse_header_msg:
107+
+ return &bpf_parse_header_msg_proto;
108+
+ case BPF_FUNC_km_header_strnstr:
109+
+ return &bpf_km_header_strnstr_proto;
110+
+ case BPF_FUNC_km_header_strncmp:
111+
+ return &bpf_km_header_strncmp_proto;
112+
default:
113+
return bpf_sk_base_func_proto(func_id);
114+
}
115+
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
116+
index 588750c46..63069c2a8 100644
117+
--- a/tools/include/uapi/linux/bpf.h
118+
+++ b/tools/include/uapi/linux/bpf.h
119+
@@ -4051,6 +4051,9 @@ union bpf_attr {
120+
FN(cpumask_op), \
121+
FN(cpus_share_cache), \
122+
FN(is_local_ipaddr), \
123+
+ FN(km_header_strnstr), \
124+
+ FN(km_header_strncmp), \
125+
+ FN(parse_header_msg), \
126+
/* */
127+
128+
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
129+
--
130+
2.33.0

kernel/patches/5.10.0/0001-bpf-sockmap-add-extra-return-value-for-sockops.patch

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
From 2b40ef8d75316e6fb005ac8c3844b3b096850b07 Mon Sep 17 00:00:00 2001
2-
From: kongweibin <kongweibin2@huawei.com>
3-
Date: Fri, 13 Oct 2023 18:06:31 +0800
4-
Subject: [PATCH 3/8] ipv4, bpf: Introduced to support the ULP to modify
1+
From 0436456007494da206743fcbcee0a9e23188af32 Mon Sep 17 00:00:00 2001
2+
From: zhangmingyi <zhangmingyi@huawei.com>
3+
Date: Thu, 9 Jan 2025 07:29:35 +0000
4+
Subject: [PATCH 2/2] add TCP_ULP support in bpf_get/set_sockopt
55

66
Currently, the ebpf program can distinguish sockets according to
77
the address accessed by the client, and use the ULP framework to
88
modify the matched sockets to delay link establishment.
99

10-
Signed-off-by: kongweibin <kongweibin2@huawei.com>
10+
Signed-off-by: zhangmingyi <zhangmingyi@huawei.com>
1111
---
12-
net/core/filter.c | 6 +++++++
13-
1 file changed, 6 insertions(+)
12+
net/core/filter.c | 14 ++++++++++++++++++++
13+
1 file changed, 14 insertions(+)
1414

1515
diff --git a/net/core/filter.c b/net/core/filter.c
16-
index c36dbcee6..6a0fdc5ce 100644
16+
index 2f56d21c9..789dc1c85 100644
1717
--- a/net/core/filter.c
1818
+++ b/net/core/filter.c
1919
@@ -4838,6 +4838,12 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname,
@@ -29,6 +29,20 @@ index c36dbcee6..6a0fdc5ce 100644
2929
} else {
3030
struct inet_connection_sock *icsk = inet_csk(sk);
3131
struct tcp_sock *tp = tcp_sk(sk);
32+
@@ -5042,6 +5048,14 @@ static int _bpf_getsockopt(struct sock *sk, int level, int optname,
33+
goto err_clear;
34+
memcpy(optval, tp->saved_syn->data, optlen);
35+
break;
36+
+ case TCP_ULP:
37+
+ icsk = inet_csk(sk);
38+
+ if (!icsk->icsk_ulp_ops || optlen <= 1) {
39+
+ goto err_clear;
40+
+ }
41+
+ strncpy(optval, icsk->icsk_ulp_ops->name, optlen);
42+
+ optval[optlen - 1] = 0;
43+
+ break;
44+
default:
45+
goto err_clear;
46+
}
3247
--
3348
2.33.0
34-

kernel/patches/5.10.0/0002-net-ipv4-A-new-bit-is-added-to-indicate-whether-to-d.patch

Lines changed: 0 additions & 54 deletions
This file was deleted.

kernel/patches/5.10.0/0004-net-bpf-Add-a-writeable_tracepoint-to-inet_stream_co.patch

Lines changed: 0 additions & 58 deletions
This file was deleted.

kernel/patches/5.10.0/0005-bpf-Introduces-a-new-state-to-identify-the-location-.patch

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)