From 93f6f05f493eee38be0ad731e985ca942e8b8d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=98=95?= Date: Thu, 25 Jan 2024 09:10:15 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E6=9B=B4=E6=96=B0SCG=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/include/scg-service.h | 3 ++ app/src/main/cpp/srcs/scc-service.cpp | 37 ++++++++++++----------- app/src/main/cpp/srcs/tunnel-proxy.cpp | 42 +++++++++++++------------- 3 files changed, 43 insertions(+), 39 deletions(-) diff --git a/app/src/main/cpp/include/scg-service.h b/app/src/main/cpp/include/scg-service.h index d507e7a..c9921e2 100644 --- a/app/src/main/cpp/include/scg-service.h +++ b/app/src/main/cpp/include/scg-service.h @@ -4,7 +4,10 @@ #pragma once #define ENABLE_UDP_PROXY_DEBUG (0) +#define SCG_HEAD_LENGTH (14) int get_scg_cur_vmid(); + const char *get_scg_proxy_ipaddr(); + unsigned short get_scg_proxy_port(); \ No newline at end of file diff --git a/app/src/main/cpp/srcs/scc-service.cpp b/app/src/main/cpp/srcs/scc-service.cpp index a58a877..13811b5 100644 --- a/app/src/main/cpp/srcs/scc-service.cpp +++ b/app/src/main/cpp/srcs/scc-service.cpp @@ -35,26 +35,27 @@ static void http_connected_cb(sion::Socket sock) { unsigned char *p; const unsigned int id = htonl(g_scgProxyCfg.curConnVmId); const auto svrId = static_cast(WG_CTRL_SCG_ID); - unsigned char scgProxy[] = {0x01, // VERSION - 0x00, // Length 0 - 0x0A, // Length 1 - 0xF0, // ++++++ INFO[0] TYPE - 0x04, // INFO[0] LENGTH - 0, // INFO[0] VMID[0] - 0, // INFO[0] VMID[1] - 0, // INFO[0] VMID[2] - 0, // INFO[0] VMID[3] - 0xF1, // INFO[1] TYPE - 0x00, // INFO[1] LENGTH 0 - 0x01, // INFO[1] LENGTH 1 - svrId}; // ------ INFO[1] SCG Service ID + unsigned char scgProxy[] = {0x01, // VERSION + 0x00, // Length 0 + SCG_HEAD_LENGTH - 3, // Length 1 + 0xF0, // ++++++ INFO[0] TYPE + 0x00, // INFO[0] LENGTH 0 + 0x04, // INFO[0] LENGTH 1 + 0, // INFO[0] VMID[0] + 0, // INFO[0] VMID[1] + 0, // INFO[0] VMID[2] + 0, // INFO[0] VMID[3] + 0xF1, // INFO[1] TYPE + 0x00, // INFO[1] LENGTH 0 + 0x01, // INFO[1] LENGTH 1 + svrId}; // ------ INFO[1] SCG Service ID p = scgProxy; memcpy(vmid, &id, 4); - scgProxy[5] = vmid[0]; - scgProxy[6] = vmid[1]; - scgProxy[7] = vmid[2]; - scgProxy[8] = vmid[3]; + scgProxy[6] = vmid[0]; + scgProxy[7] = vmid[1]; + scgProxy[8] = vmid[2]; + scgProxy[9] = vmid[3]; ret = send(sock, reinterpret_cast(p), sizeof(scgProxy), 0); @@ -90,7 +91,7 @@ int init_scgproxy_service(const char *pSCGIpAddr, int scgPort) { int ret; ANDROID_LOG(ANDROID_LOG_INFO, "SCGPROXY", "libsccproxy(%s) library information: (Build: %s %s GCC Ver:%s) With %u(bits) OS\n", - ENABLE_UDP_PROXY_DEBUG ? "DEBUG" : "RELEASE", __DATE__, __TIME__, __VERSION__, (unsigned int)(sizeof(int *) * 8)); + ENABLE_UDP_PROXY_DEBUG ? "DEBUG" : "RELEASE", __DATE__, __TIME__, __VERSION__, (unsigned int) (sizeof(int *) * 8)); memset(&g_scgProxyCfg, 0, sizeof(SCGPROXY_CONFIG)); diff --git a/app/src/main/cpp/srcs/tunnel-proxy.cpp b/app/src/main/cpp/srcs/tunnel-proxy.cpp index 9d35c2e..90d0828 100644 --- a/app/src/main/cpp/srcs/tunnel-proxy.cpp +++ b/app/src/main/cpp/srcs/tunnel-proxy.cpp @@ -18,7 +18,6 @@ #define UNUSED(x) UNUSED_##x __attribute__((__unused__)) #endif -#define SCG_UDP_HEAD_SIZE (13) #define SIG_CANCEL_SIGNAL SIGUSR1 typedef struct { @@ -142,28 +141,29 @@ static void *UDPProxyRecvThread(void *UNUSED(lpParameter)) { bool isRemoteInit = false; sockaddr_in localWgAddr{}; sockaddr_in scgAddr{}; - unsigned char recvBuf[1500 + SCG_UDP_HEAD_SIZE]; + unsigned char recvBuf[1500 + SCG_HEAD_LENGTH]; PSCG_PROXY_INFO pProxy = &g_scgProxyInfo; - char *pRecBuf = reinterpret_cast(&recvBuf[SCG_UDP_HEAD_SIZE]); + char *pRecBuf = reinterpret_cast(&recvBuf[SCG_HEAD_LENGTH]); scgAddr.sin_family = AF_INET; scgAddr.sin_port = htons(get_scg_proxy_port()); inet_pton(AF_INET, get_scg_proxy_ipaddr(), &scgAddr.sin_addr.s_addr); // 构建 SCG UDP 包头 - recvBuf[0] = 0x01; // VERSION - recvBuf[1] = 0x0A; // Length 0 - recvBuf[2] = 0x09; // Length 1 - recvBuf[3] = 0xF0; // ++++++ INFO[0] TYPE - recvBuf[4] = 0x04; // INFO[0] LENGTH - recvBuf[5] = 0; // INFO[0] VMID[0] - recvBuf[6] = 0; // INFO[0] VMID[1] - recvBuf[7] = 0; // INFO[0] VMID[2] - recvBuf[8] = 0; // INFO[0] VMID[3] - recvBuf[9] = 0xF1; // INFO[1] TYPE - recvBuf[10] = 0x00; // INFO[1] LENGTH 0 - recvBuf[11] = 0x01; // INFO[1] LENGTH 1 - recvBuf[12] = WG_TUNNEL_SCG_ID; // ------ INFO[1] SCG Service ID + recvBuf[0] = 0x01; // VERSION + recvBuf[1] = 0x00; // Length 0 + recvBuf[2] = SCG_HEAD_LENGTH - 3; // Length 1 + recvBuf[3] = 0xF0; // ++++++ INFO[0] TYPE + recvBuf[4] = 0x00; // INFO[0] LENGTH 0 + recvBuf[5] = 0x04; // INFO[0] LENGTH 1 + recvBuf[6] = 0; // INFO[0] VMID[0] + recvBuf[7] = 0; // INFO[0] VMID[1] + recvBuf[8] = 0; // INFO[0] VMID[2] + recvBuf[9] = 0; // INFO[0] VMID[3] + recvBuf[10] = 0xF1; // INFO[1] TYPE + recvBuf[11] = 0x00; // INFO[1] LENGTH 0 + recvBuf[12] = 0x01; // INFO[1] LENGTH 1 + recvBuf[13] = WG_TUNNEL_SCG_ID; // ------ INFO[1] SCG Service ID pProxy->exitNow = false; while (!pProxy->exitNow) { @@ -208,14 +208,14 @@ static void *UDPProxyRecvThread(void *UNUSED(lpParameter)) { } } - recvBuf[5] = vmid[0]; // INFO[0] VMID[0] - recvBuf[6] = vmid[1]; // INFO[0] VMID[1] - recvBuf[7] = vmid[2]; // INFO[0] VMID[2] - recvBuf[8] = vmid[3]; // INFO[0] VMID[3] + recvBuf[6] = vmid[0]; // INFO[0] VMID[0] + recvBuf[7] = vmid[1]; // INFO[0] VMID[1] + recvBuf[8] = vmid[2]; // INFO[0] VMID[2] + recvBuf[9] = vmid[3]; // INFO[0] VMID[3] // 增加SCG包头数据长度 #if !USED_DIRECT_PROXY - iRecvBytes += SCG_UDP_HEAD_SIZE; + iRecvBytes += SCG_HEAD_LENGTH; #else ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "Porxy Send Data Not Add SCG UDP HEAD\n"); #endif