OCT 1. 更新SCG协议

This commit is contained in:
黄昕 2024-01-25 09:10:15 +08:00
parent a5d0c64e86
commit 93f6f05f49
3 changed files with 43 additions and 39 deletions

View File

@ -4,7 +4,10 @@
#pragma once #pragma once
#define ENABLE_UDP_PROXY_DEBUG (0) #define ENABLE_UDP_PROXY_DEBUG (0)
#define SCG_HEAD_LENGTH (14)
int get_scg_cur_vmid(); int get_scg_cur_vmid();
const char *get_scg_proxy_ipaddr(); const char *get_scg_proxy_ipaddr();
unsigned short get_scg_proxy_port(); unsigned short get_scg_proxy_port();

View File

@ -35,26 +35,27 @@ static void http_connected_cb(sion::Socket sock) {
unsigned char *p; unsigned char *p;
const unsigned int id = htonl(g_scgProxyCfg.curConnVmId); const unsigned int id = htonl(g_scgProxyCfg.curConnVmId);
const auto svrId = static_cast<unsigned char>(WG_CTRL_SCG_ID); const auto svrId = static_cast<unsigned char>(WG_CTRL_SCG_ID);
unsigned char scgProxy[] = {0x01, // VERSION unsigned char scgProxy[] = {0x01, // VERSION
0x00, // Length 0 0x00, // Length 0
0x0A, // Length 1 SCG_HEAD_LENGTH - 3, // Length 1
0xF0, // ++++++ INFO[0] TYPE 0xF0, // ++++++ INFO[0] TYPE
0x04, // INFO[0] LENGTH 0x00, // INFO[0] LENGTH 0
0, // INFO[0] VMID[0] 0x04, // INFO[0] LENGTH 1
0, // INFO[0] VMID[1] 0, // INFO[0] VMID[0]
0, // INFO[0] VMID[2] 0, // INFO[0] VMID[1]
0, // INFO[0] VMID[3] 0, // INFO[0] VMID[2]
0xF1, // INFO[1] TYPE 0, // INFO[0] VMID[3]
0x00, // INFO[1] LENGTH 0 0xF1, // INFO[1] TYPE
0x01, // INFO[1] LENGTH 1 0x00, // INFO[1] LENGTH 0
svrId}; // ------ INFO[1] SCG Service ID 0x01, // INFO[1] LENGTH 1
svrId}; // ------ INFO[1] SCG Service ID
p = scgProxy; p = scgProxy;
memcpy(vmid, &id, 4); memcpy(vmid, &id, 4);
scgProxy[5] = vmid[0]; scgProxy[6] = vmid[0];
scgProxy[6] = vmid[1]; scgProxy[7] = vmid[1];
scgProxy[7] = vmid[2]; scgProxy[8] = vmid[2];
scgProxy[8] = vmid[3]; scgProxy[9] = vmid[3];
ret = send(sock, reinterpret_cast<const char *>(p), sizeof(scgProxy), 0); ret = send(sock, reinterpret_cast<const char *>(p), sizeof(scgProxy), 0);
@ -90,7 +91,7 @@ int init_scgproxy_service(const char *pSCGIpAddr, int scgPort) {
int ret; int ret;
ANDROID_LOG(ANDROID_LOG_INFO, "SCGPROXY", "libsccproxy(%s) library information: (Build: %s %s GCC Ver:%s) With %u(bits) OS\n", 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)); memset(&g_scgProxyCfg, 0, sizeof(SCGPROXY_CONFIG));

View File

@ -18,7 +18,6 @@
#define UNUSED(x) UNUSED_##x __attribute__((__unused__)) #define UNUSED(x) UNUSED_##x __attribute__((__unused__))
#endif #endif
#define SCG_UDP_HEAD_SIZE (13)
#define SIG_CANCEL_SIGNAL SIGUSR1 #define SIG_CANCEL_SIGNAL SIGUSR1
typedef struct { typedef struct {
@ -142,28 +141,29 @@ static void *UDPProxyRecvThread(void *UNUSED(lpParameter)) {
bool isRemoteInit = false; bool isRemoteInit = false;
sockaddr_in localWgAddr{}; sockaddr_in localWgAddr{};
sockaddr_in scgAddr{}; sockaddr_in scgAddr{};
unsigned char recvBuf[1500 + SCG_UDP_HEAD_SIZE]; unsigned char recvBuf[1500 + SCG_HEAD_LENGTH];
PSCG_PROXY_INFO pProxy = &g_scgProxyInfo; PSCG_PROXY_INFO pProxy = &g_scgProxyInfo;
char *pRecBuf = reinterpret_cast<char *>(&recvBuf[SCG_UDP_HEAD_SIZE]); char *pRecBuf = reinterpret_cast<char *>(&recvBuf[SCG_HEAD_LENGTH]);
scgAddr.sin_family = AF_INET; scgAddr.sin_family = AF_INET;
scgAddr.sin_port = htons(get_scg_proxy_port()); scgAddr.sin_port = htons(get_scg_proxy_port());
inet_pton(AF_INET, get_scg_proxy_ipaddr(), &scgAddr.sin_addr.s_addr); inet_pton(AF_INET, get_scg_proxy_ipaddr(), &scgAddr.sin_addr.s_addr);
// 构建 SCG UDP 包头 // 构建 SCG UDP 包头
recvBuf[0] = 0x01; // VERSION recvBuf[0] = 0x01; // VERSION
recvBuf[1] = 0x0A; // Length 0 recvBuf[1] = 0x00; // Length 0
recvBuf[2] = 0x09; // Length 1 recvBuf[2] = SCG_HEAD_LENGTH - 3; // Length 1
recvBuf[3] = 0xF0; // ++++++ INFO[0] TYPE recvBuf[3] = 0xF0; // ++++++ INFO[0] TYPE
recvBuf[4] = 0x04; // INFO[0] LENGTH recvBuf[4] = 0x00; // INFO[0] LENGTH 0
recvBuf[5] = 0; // INFO[0] VMID[0] recvBuf[5] = 0x04; // INFO[0] LENGTH 1
recvBuf[6] = 0; // INFO[0] VMID[1] recvBuf[6] = 0; // INFO[0] VMID[0]
recvBuf[7] = 0; // INFO[0] VMID[2] recvBuf[7] = 0; // INFO[0] VMID[1]
recvBuf[8] = 0; // INFO[0] VMID[3] recvBuf[8] = 0; // INFO[0] VMID[2]
recvBuf[9] = 0xF1; // INFO[1] TYPE recvBuf[9] = 0; // INFO[0] VMID[3]
recvBuf[10] = 0x00; // INFO[1] LENGTH 0 recvBuf[10] = 0xF1; // INFO[1] TYPE
recvBuf[11] = 0x01; // INFO[1] LENGTH 1 recvBuf[11] = 0x00; // INFO[1] LENGTH 0
recvBuf[12] = WG_TUNNEL_SCG_ID; // ------ INFO[1] SCG Service ID recvBuf[12] = 0x01; // INFO[1] LENGTH 1
recvBuf[13] = WG_TUNNEL_SCG_ID; // ------ INFO[1] SCG Service ID
pProxy->exitNow = false; pProxy->exitNow = false;
while (!pProxy->exitNow) { while (!pProxy->exitNow) {
@ -208,14 +208,14 @@ static void *UDPProxyRecvThread(void *UNUSED(lpParameter)) {
} }
} }
recvBuf[5] = vmid[0]; // INFO[0] VMID[0] recvBuf[6] = vmid[0]; // INFO[0] VMID[0]
recvBuf[6] = vmid[1]; // INFO[0] VMID[1] recvBuf[7] = vmid[1]; // INFO[0] VMID[1]
recvBuf[7] = vmid[2]; // INFO[0] VMID[2] recvBuf[8] = vmid[2]; // INFO[0] VMID[2]
recvBuf[8] = vmid[3]; // INFO[0] VMID[3] recvBuf[9] = vmid[3]; // INFO[0] VMID[3]
// 增加SCG包头数据长度 // 增加SCG包头数据长度
#if !USED_DIRECT_PROXY #if !USED_DIRECT_PROXY
iRecvBytes += SCG_UDP_HEAD_SIZE; iRecvBytes += SCG_HEAD_LENGTH;
#else #else
ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "Porxy Send Data Not Add SCG UDP HEAD\n"); ANDROID_LOG(ANDROID_LOG_WARN, "SCGPROXY", "Porxy Send Data Not Add SCG UDP HEAD\n");
#endif #endif