Skip to content

Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic

Fixed batch error cause network issues

Sourav Kalalb4d11e02502d
diff --git a/Windows/src/ProxyBridge.c b/Windows/src/ProxyBridge.c
index d4b0a9d..1bf6899 100644
--- a/Windows/src/ProxyBridge.c
+++ b/Windows/src/ProxyBridge.c
@@ -12,15 +12,14 @@
#pragma comment(lib, "iphlpapi.lib")
#pragma comment(lib, "ws2_32.lib")
-#define MAXBUF 1500 // Optimized for typical MTU (WinDivert performance recommendation)
-#define PACKET_BATCH_SIZE 64 // Batch mode: process multiple packets per context switch
+#define MAXBUF 0xFFFF
#define LOCAL_PROXY_PORT 34010
#define LOCAL_UDP_RELAY_PORT 34011 // its running UDP port still make sure to not run on same port as TCP, opening same port and tcp and udp cause issue and handling port at relay server response injection
#define MAX_PROCESS_NAME 256
#define VERSION "3.1.0"
#define PID_CACHE_SIZE 1024
#define PID_CACHE_TTL_MS 1000
-#define NUM_PACKET_THREADS 4 // Multi-threading for parallel packet processing
+#define NUM_PACKET_THREADS 4
#define CONNECTION_HASH_SIZE 256
#define SOCKS5_BUFFER_SIZE 1024
#define HTTP_BUFFER_SIZE 1024
@@ -106,7 +105,6 @@ static BOOL running = FALSE;
static DWORD g_current_process_id = 0;
static BOOL g_traffic_logging_enabled = TRUE;
-static BOOL g_ipv6_warning_logged = FALSE;
static char g_proxy_host[256] = ""; // Can be IP address or hostname
static UINT16 g_proxy_port = 0;
@@ -267,23 +265,11 @@ static DWORD WINAPI packet_processor(LPVOID arg)
continue;
}
- PWINDIVERT_IPV6HDR ipv6_header = NULL;
- WinDivertHelperParsePacket(packet, packet_len, &ip_header, &ipv6_header, NULL,
+ WinDivertHelperParsePacket(packet, packet_len, &ip_header, NULL, NULL,
NULL, NULL, &tcp_header, &udp_header, NULL, NULL, NULL, NULL);
if (ip_header == NULL)
- {
- if (ipv6_header != NULL)
- {
- if (!g_ipv6_warning_logged)
- {
- log_message("IPv6 traffic detected but not supported. IPv6 connections will not be proxied.");
- g_ipv6_warning_logged = TRUE;
- }
- WinDivertSend(windivert_handle, packet, packet_len, NULL, &addr);
- }
continue;
- }
if (udp_header != NULL && tcp_header == NULL)
{
@@ -318,7 +304,7 @@ static DWORD WINAPI packet_processor(LPVOID arg)
UINT32 dest_ip = ip_header->DstAddr;
UINT16 dest_port = ntohs(udp_header->DstPort);
- // if no rule configured all connection direct with no checks avoid unwanted memory and processing which could delay
+ // if no rule configuree all connection direct with no checks avoid unwanted memory and pocessing whcich could delay
if (!g_has_active_rules && g_connection_callback == NULL)
{
// No rules and no logging - pass through immediately (no checksum needed for unmodified packets)
@@ -461,7 +447,7 @@ static DWORD WINAPI packet_processor(LPVOID arg)
UINT32 orig_dest_ip = ip_header->DstAddr;
UINT16 orig_dest_port = ntohs(tcp_header->DstPort);
- // avoid rule process and packet process if no rules
+ // avoid rule pocess and packet process if no rules
if (!g_has_active_rules && g_connection_callback == NULL)
{
WinDivertSend(windivert_handle, packet, packet_len, NULL, &addr);
@@ -532,14 +518,14 @@ static DWORD WINAPI packet_processor(LPVOID arg)
continue;
}
else if (action == RULE_ACTION_PROXY)
- {
- add_connection(src_port, src_ip, orig_dest_ip, orig_dest_port);
+ {
+ add_connection(src_port, src_ip, orig_dest_ip, orig_dest_port);
- UINT32 temp_addr = ip_header->DstAddr;
- tcp_header->DstPort = htons(g_local_relay_port);
- ip_header->DstAddr = ip_header->SrcAddr;
- ip_header->SrcAddr = temp_addr;
- addr.Outbound = FALSE;
+ UINT32 temp_addr = ip_header->DstAddr;
+ tcp_header->DstPort = htons(g_local_relay_port);
+ ip_header->DstAddr = ip_header->SrcAddr;
+ ip_header->SrcAddr = temp_addr;
+ addr.Outbound = FALSE;
}
}
}
@@ -1482,10 +1468,6 @@ static BOOL establish_udp_associate(void)
return FALSE;
}
- // RFC 1928: if server returns 0.0.0.0 as relay address, use the proxy server's IP
- if (socks5_udp_relay_addr.sin_addr.s_addr == INADDR_ANY)
- socks5_udp_relay_addr.sin_addr.s_addr = socks5_ip;
-
socks5_udp_socket = tcp_sock;
// ccreate UDP socket for sending to SOCKS5 proxy
@@ -2756,9 +2738,8 @@ PROXYBRIDGE_API BOOL ProxyBridge_Start(void)
return FALSE;
}
- // Performance optimization: larger queue to prevent packet drops under heavy load (>= 1Gbps)
- WinDivertSetParam(windivert_handle, WINDIVERT_PARAM_QUEUE_LENGTH, (UINT64)16384); // Doubled queue length
- WinDivertSetParam(windivert_handle, WINDIVERT_PARAM_QUEUE_TIME, (UINT64)2000); // 2 seconds max queue time
+ WinDivertSetParam(windivert_handle, WINDIVERT_PARAM_QUEUE_LENGTH, 8192);
+ WinDivertSetParam(windivert_handle, WINDIVERT_PARAM_QUEUE_TIME, 8); // 8ms for low latency
for (int i = 0; i < NUM_PACKET_THREADS; i++)
{