!25 add sysctl to change opcode dynamic
From: @sunsuwan Reviewed-by: @xiexiuqi, @far_beyond, @jia_zhenyuan Signed-off-by: @xiexiuqi
This commit is contained in:
commit
86d962a487
159
0006-add-sysctl-to-change-opcode-dynamic.patch
Normal file
159
0006-add-sysctl-to-change-opcode-dynamic.patch
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
From 3f288faeec7a7345b59dfa9cbecf8507008c8a6b Mon Sep 17 00:00:00 2001
|
||||||
|
From: gaoxingwang <gxw94linux@163.com>
|
||||||
|
Date: Tue, 1 Nov 2022 11:14:05 +0800
|
||||||
|
Subject: [PATCH] add sysctl to change opcode dynamic
|
||||||
|
|
||||||
|
---
|
||||||
|
src/toa.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
|
||||||
|
src/toa.h | 3 ---
|
||||||
|
2 files changed, 54 insertions(+), 8 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/src/toa.c b/src/toa.c
|
||||||
|
index 931607d..2de3442 100644
|
||||||
|
--- a/src/toa.c
|
||||||
|
+++ b/src/toa.c
|
||||||
|
@@ -15,12 +15,16 @@
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
+#include <net/net_namespace.h>
|
||||||
|
#include "toa.h"
|
||||||
|
/*
|
||||||
|
* TOA: Address is a new TCP Option
|
||||||
|
* Address include ip+port, Now support IPV4 and IPV6
|
||||||
|
*/
|
||||||
|
|
||||||
|
+static unsigned int sysctl_toa_opcode_v4 = 254;
|
||||||
|
+static unsigned int sysctl_toa_opcode_v6 = 254;
|
||||||
|
+
|
||||||
|
#if defined(CONFIG_ARM64)
|
||||||
|
/*
|
||||||
|
* ARM64 interface
|
||||||
|
@@ -436,7 +440,7 @@ static void *get_toa_data(int af, struct sk_buff *skb, int *nat64)
|
||||||
|
if (opsize > length)
|
||||||
|
/* don't parse partial options */
|
||||||
|
return NULL;
|
||||||
|
- if (TCPOPT_TOA == opcode &&
|
||||||
|
+ if (sysctl_toa_opcode_v4 == opcode &&
|
||||||
|
TCPOLEN_IP4_TOA == opsize) {
|
||||||
|
|
||||||
|
struct toa_ip4_data tdata;
|
||||||
|
@@ -479,7 +483,7 @@ static void *get_toa_data(int af, struct sk_buff *skb, int *nat64)
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (defined(TOA_IPV6_ENABLE) || defined(TOA_NAT64_ENABLE))
|
||||||
|
- if (TCPOPT_TOA == opcode &&
|
||||||
|
+ if (sysctl_toa_opcode_v6 == opcode &&
|
||||||
|
TCPOLEN_IP6_TOA == opsize) {
|
||||||
|
struct toa_ip6_data *ptr_toa_ip6;
|
||||||
|
struct toa_ip6_entry *ptr_toa_entry =
|
||||||
|
@@ -552,7 +556,7 @@ inet_getname_toa(struct socket *sock, struct sockaddr *uaddr,
|
||||||
|
if (sk_data_ready_addr == (unsigned long) sk->sk_data_ready &&
|
||||||
|
!sock_flag(sk, SOCK_NAT64)) {
|
||||||
|
memcpy(&tdata, &sk->sk_user_data, sizeof(tdata));
|
||||||
|
- if (TCPOPT_TOA == tdata.opcode &&
|
||||||
|
+ if (sysctl_toa_opcode_v4 == tdata.opcode &&
|
||||||
|
TCPOLEN_IP4_TOA == tdata.opsize) {
|
||||||
|
TOA_INC_STATS(ext_stats, GETNAME_TOA_OK_CNT);
|
||||||
|
TOA_DBG("inet_getname_toa: set new sockaddr, ip "
|
||||||
|
@@ -639,7 +643,7 @@ inet64_getname_toa(struct sock *sk, int cmd, void __user *user, int *len)
|
||||||
|
ptr_ip6_entry = sk->sk_user_data;
|
||||||
|
ptr_ip6_data = &ptr_ip6_entry->toa_data;
|
||||||
|
|
||||||
|
- if (TCPOPT_TOA == ptr_ip6_data->opcode &&
|
||||||
|
+ if (sysctl_toa_opcode_v6 == ptr_ip6_data->opcode &&
|
||||||
|
TCPOLEN_IP6_TOA == ptr_ip6_data->opsize) {
|
||||||
|
TOA_INC_STATS(ext_stats, GETNAME_TOA_OK_CNT);
|
||||||
|
TOA_DBG("inet64_getname_toa: set new sockaddr, ip "
|
||||||
|
@@ -720,7 +724,7 @@ inet6_getname_toa(struct socket *sock, struct sockaddr *uaddr,
|
||||||
|
struct toa_ip6_data* ptr_ip6_data = &ptr_ip6_entry->toa_data;
|
||||||
|
|
||||||
|
if (sk == ptr_ip6_entry->sk &&
|
||||||
|
- TCPOPT_TOA == ptr_ip6_data->opcode &&
|
||||||
|
+ sysctl_toa_opcode_v6 == ptr_ip6_data->opcode &&
|
||||||
|
TCPOLEN_IP6_TOA == ptr_ip6_data->opsize) {
|
||||||
|
TOA_INC_STATS(ext_stats, GETNAME_TOA_OK_CNT);
|
||||||
|
TOA_DBG("inet6_getname_toa: set new sockaddr, ip "
|
||||||
|
@@ -1124,6 +1128,38 @@ static void proc_net_remove(struct net *net, const char *name)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
+static unsigned int byte_min = 0;
|
||||||
|
+static unsigned int byte_max = 255;
|
||||||
|
+static struct ctl_table toa_v4_sysctl_table[] = {
|
||||||
|
+ {
|
||||||
|
+ .procname = "toa_opcode_v4",
|
||||||
|
+ .data = &sysctl_toa_opcode_v4,
|
||||||
|
+ .maxlen = sizeof(unsigned int),
|
||||||
|
+ .mode = 0644,
|
||||||
|
+ .proc_handler = proc_dointvec_minmax,
|
||||||
|
+ .extra1 = &byte_min,
|
||||||
|
+ .extra2 = &byte_max,
|
||||||
|
+ },
|
||||||
|
+ {
|
||||||
|
+ },
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+static struct ctl_table toa_v6_sysctl_table[] = {
|
||||||
|
+ {
|
||||||
|
+ .procname = "toa_opcode_v6",
|
||||||
|
+ .data = &sysctl_toa_opcode_v6,
|
||||||
|
+ .maxlen = sizeof(unsigned int),
|
||||||
|
+ .mode = 0644,
|
||||||
|
+ .proc_handler = proc_dointvec_minmax,
|
||||||
|
+ .extra1 = &byte_min,
|
||||||
|
+ .extra2 = &byte_max,
|
||||||
|
+ },
|
||||||
|
+ {
|
||||||
|
+ },
|
||||||
|
+};
|
||||||
|
+static struct ctl_table_header *toa_v4_sysctl_header = NULL;
|
||||||
|
+static struct ctl_table_header *toa_v6_sysctl_header = NULL;
|
||||||
|
+
|
||||||
|
/* module init */
|
||||||
|
static int __init
|
||||||
|
toa_init(void)
|
||||||
|
@@ -1140,6 +1176,16 @@ toa_init(void)
|
||||||
|
|
||||||
|
TOA_INFO("TOA " TOA_VERSION " by qlb of iqiyi.\n");
|
||||||
|
|
||||||
|
+ toa_v4_sysctl_header = register_net_sysctl(&init_net, "net/ipv4", toa_v4_sysctl_table);
|
||||||
|
+ if (NULL == toa_v4_sysctl_header) {
|
||||||
|
+ TOA_INFO("register toa v4 sysctl failed\n");
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ toa_v6_sysctl_header = register_net_sysctl(&init_net, "net/ipv6", toa_v6_sysctl_table);
|
||||||
|
+ if (NULL == toa_v4_sysctl_header) {
|
||||||
|
+ TOA_INFO("register toa v6 sysctl failed\n");
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
/* alloc statistics array for toa */
|
||||||
|
ext_stats = alloc_percpu(struct toa_stat_mib);
|
||||||
|
if (NULL == ext_stats)
|
||||||
|
@@ -1215,6 +1261,9 @@ toa_exit(void)
|
||||||
|
unregister_kprobe(&kp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
+ unregister_sysctl_table(toa_v4_sysctl_header);
|
||||||
|
+ unregister_sysctl_table(toa_v6_sysctl_header);
|
||||||
|
+
|
||||||
|
proc_net_remove(&init_net, "toa_stats");
|
||||||
|
if (NULL != ext_stats) {
|
||||||
|
free_percpu(ext_stats);
|
||||||
|
diff --git a/src/toa.h b/src/toa.h
|
||||||
|
index 64095c3..6c64c61 100644
|
||||||
|
--- a/src/toa.h
|
||||||
|
+++ b/src/toa.h
|
||||||
|
@@ -61,9 +61,6 @@
|
||||||
|
printk(KERN_INFO "TOA: " msg); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
-
|
||||||
|
-#define TCPOPT_TOA 254
|
||||||
|
-
|
||||||
|
/* MUST be 4n !!!! */
|
||||||
|
#define TCPOLEN_IP4_TOA 8 /* |opcode|size|ip+port| = 1 + 1 + 6 */
|
||||||
|
#define TCPOLEN_IP6_TOA 20 /* |opcode|size|ip_of_v6+port| = 1 + 1 + 18 */
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
6
toa.spec
6
toa.spec
@ -5,7 +5,7 @@
|
|||||||
Name: TCP_option_address
|
Name: TCP_option_address
|
||||||
Summary: Intel(R) Ethernet Adaptive Virtual Function Driver
|
Summary: Intel(R) Ethernet Adaptive Virtual Function Driver
|
||||||
Version: 1.0.0
|
Version: 1.0.0
|
||||||
Release: 4
|
Release: 5
|
||||||
#Release: 0.%{krelver}
|
#Release: 0.%{krelver}
|
||||||
Vendor: Huawei
|
Vendor: Huawei
|
||||||
License: GPL-2.0
|
License: GPL-2.0
|
||||||
@ -17,6 +17,7 @@ Patch0002: 0002-fix-build-error.patch
|
|||||||
Patch0003: 0003-patch-for-5_10.patch
|
Patch0003: 0003-patch-for-5_10.patch
|
||||||
Patch0004: 0004-fix-crash.patch
|
Patch0004: 0004-fix-crash.patch
|
||||||
Patch0005: 0005-support-ipv6-from-iqiyi.patch
|
Patch0005: 0005-support-ipv6-from-iqiyi.patch
|
||||||
|
Patch0006: 0006-add-sysctl-to-change-opcode-dynamic.patch
|
||||||
|
|
||||||
Requires: kernel, findutils, gawk, bash
|
Requires: kernel, findutils, gawk, bash
|
||||||
|
|
||||||
@ -106,6 +107,9 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Nov 1 2022 sunsuwan<sunsuwan3@huawei.com> - 1.0.0-5
|
||||||
|
- add sysctl to change opcode dynamic
|
||||||
|
|
||||||
* Mon Oct 31 2022 sunsuwan<sunsuwan3@huawei.com> - 1.0.0-4
|
* Mon Oct 31 2022 sunsuwan<sunsuwan3@huawei.com> - 1.0.0-4
|
||||||
- support ipv6 from iqiyi
|
- support ipv6 from iqiyi
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user