1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-07-06 07:44:57 +03:00

Merge pull request #1867 from hiura2023/master

Bind outgoing connection to a specific IP address
This commit is contained in:
Ilya Shipitsin
2023-09-10 17:18:31 +02:00
committed by GitHub
16 changed files with 575 additions and 32 deletions

View File

@ -6150,6 +6150,8 @@ void CmImportAccountMainEx(HWND hWnd, wchar_t *filename, bool overwrite)
t->ClientOption->RequireMonitorMode = old_option->RequireMonitorMode;
t->ClientOption->RequireBridgeRoutingMode = old_option->RequireBridgeRoutingMode;
t->ClientOption->DisableQoS = old_option->DisableQoS;
t->ClientOption->BindLocalIP = old_option->BindLocalIP;// Source IP address for outgoing connection
t->ClientOption->BindLocalPort = old_option->BindLocalPort;// Source port number for outgoing connection
// Inherit the authentication data
CiFreeClientAuth(t->ClientAuth);
@ -6456,9 +6458,55 @@ void CmDetailDlgUpdate(HWND hWnd, CM_ACCOUNT *a)
Disable(hWnd, R_BRIDGE);
Disable(hWnd, R_MONITOR);
Disable(hWnd, R_NO_ROUTING);
#if TYPE_BINDLOCALIP
Disable(hWnd, E_BIND_LOCALIP);// Source IP address for outgoing connection
Disable(hWnd, E_BIND_LOCALPORT);// Source port number for outgoing connection
#endif
}
}
#if TYPE_BINDLOCALIP
// Set the value of the IP type
void SetIp(HWND hWnd, UINT id, IP* ip)
{
char tmp[MAX_SIZE];
// Validate arguments
if (hWnd == NULL || ip == NULL)
{
return;
}
IPToStr(tmp, sizeof(tmp), ip);
SetTextA(hWnd, id, tmp);
}
// Get an IP address
bool GetIp(HWND hWnd, UINT id, IP* ip)
{
char tmp[MAX_SIZE];
// Validate arguments
if (hWnd == NULL || ip == NULL)
{
return false;
}
Zero(ip, sizeof(IP));
if (GetTxtA(hWnd, id, tmp, sizeof(tmp)) == false)
{
return false;
}
if (StrToIP(ip, tmp) == false)
{
return false;
}
return true;
}
#endif
// Advanced Settings dialog procedure
UINT CmDetailDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param)
{
@ -6495,6 +6543,11 @@ UINT CmDetailDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *pa
Check(hWnd, R_NO_ROUTING, a->ClientOption->NoRoutingTracking);
Check(hWnd, R_DISABLE_QOS, a->ClientOption->DisableQoS);
Check(hWnd, R_DISABLE_UDP, a->ClientOption->NoUdpAcceleration);
#if TYPE_BINDLOCALIP
SetIp(hWnd, E_BIND_LOCALIP, &a->ClientOption->BindLocalIP);// Source IP address for outgoing connection
SetIntEx(hWnd, E_BIND_LOCALPORT, a->ClientOption->BindLocalPort);// Source port number for outgoing connection
//Disable(hWnd, E_BIND_LOCALPORT); // You can not edit
#endif
// Select the Connection Mode
if (a->LinkMode == false)
@ -6542,6 +6595,20 @@ UINT CmDetailDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *pa
Focus(hWnd, E_INTERVAL);
break;
}
#if TYPE_BINDLOCALIP
// Source IP address for outgoing connection
IP tmpIP;
if (GetIp(hWnd, E_BIND_LOCALIP, &tmpIP) == false)
{
FocusEx(hWnd, E_BIND_LOCALIP);
break;
}
// Source port number for outgoing connection
if ((GetInt(hWnd, E_BIND_LOCALPORT) < 0) || (GetInt(hWnd, E_BIND_LOCALPORT) > 65535)){
FocusEx(hWnd, E_BIND_LOCALPORT);
break;
}
#endif
a->ClientOption->MaxConnection = num;
a->ClientOption->AdditionalConnectionInterval = GetInt(hWnd, E_INTERVAL);
@ -6559,6 +6626,10 @@ UINT CmDetailDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *pa
a->ClientOption->NoRoutingTracking = IsChecked(hWnd, R_NO_ROUTING);
a->ClientOption->DisableQoS = IsChecked(hWnd, R_DISABLE_QOS);
a->ClientOption->NoUdpAcceleration = IsChecked(hWnd, R_DISABLE_UDP);
#if TYPE_BINDLOCALIP
a->ClientOption->BindLocalIP = tmpIP;// Source IP address for outgoing connection
a->ClientOption->BindLocalPort = GetInt(hWnd, E_BIND_LOCALPORT);// Source port number for outgoing connection
#endif
if (a->LinkMode)
{

View File

@ -4345,6 +4345,9 @@ void InRpcClientOption(CLIENT_OPTION *c, PACK *p)
PackGetStr(p, "CustomHttpHeader", c->CustomHttpHeader, sizeof(c->CustomHttpHeader));
PackGetStr(p, "HubName", c->HubName, sizeof(c->HubName));
PackGetStr(p, "DeviceName", c->DeviceName, sizeof(c->DeviceName));
PackGetIp(p, "BindLocalIP", &c->BindLocalIP);// Source IP address for outgoing connection
c->BindLocalPort = PackGetInt(p, "BindLocalPort");// Source port nubmer for outgoing connection
c->UseEncrypt = PackGetInt(p, "UseEncrypt") ? true : false;
c->UseCompress = PackGetInt(p, "UseCompress") ? true : false;
c->HalfConnection = PackGetInt(p, "HalfConnection") ? true : false;
@ -4405,6 +4408,8 @@ void OutRpcClientOption(PACK *p, CLIENT_OPTION *c)
PackAddBool(p, "FromAdminPack", c->FromAdminPack);
PackAddBool(p, "NoUdpAcceleration", c->NoUdpAcceleration);
PackAddData(p, "HostUniqueKey", c->HostUniqueKey, SHA1_SIZE);
PackAddIp(p, "BindLocalIP", &c->BindLocalIP);// Source IP address for outgoing connection
PackAddInt(p, "BindLocalPort", c->BindLocalPort);// Source port number for outgoing connection
}
// CLIENT_AUTH
@ -9299,7 +9304,9 @@ CLIENT_OPTION *CiLoadClientOption(FOLDER *f)
o->DisableQoS = CfgGetBool(f, "DisableQoS");
o->FromAdminPack = CfgGetBool(f, "FromAdminPack");
o->NoUdpAcceleration = CfgGetBool(f, "NoUdpAcceleration");
CfgGetIp(f, "BindLocalIP", &o->BindLocalIP);// Source IP address for outgoing connection
o->BindLocalPort = CfgGetInt(f, "BindLocalPort");// Source port number for outgoing connection
b = CfgGetBuf(f, "HostUniqueKey");
if (b != NULL)
{
@ -9853,6 +9860,8 @@ void CiWriteClientOption(FOLDER *f, CLIENT_OPTION *o)
CfgAddBool(f, "RequireBridgeRoutingMode", o->RequireBridgeRoutingMode);
CfgAddBool(f, "DisableQoS", o->DisableQoS);
CfgAddBool(f, "NoUdpAcceleration", o->NoUdpAcceleration);
CfgAddIp(f, "BindLocalIP", &o->BindLocalIP);// Source IP address for outgoing connection
CfgAddInt(f, "BindLocalPort", o->BindLocalPort);// Source port number for outgoing connection
if (o->FromAdminPack)
{

View File

@ -58,6 +58,7 @@ struct RC4_KEY_PAIR
UCHAR ServerToClientKey[16];
UCHAR ClientToServerKey[16];
};
#define TYPE_BINDLOCALIP 1 // Enable HMI user to edit Source IP address & Source port number for outgoing connection
// Client Options
// Do not change item size or order and only add new items at the end!
@ -106,6 +107,8 @@ struct CLIENT_OPTION
UCHAR HostUniqueKey[SHA1_SIZE]; // Host unique key
char CustomHttpHeader[HTTP_CUSTOM_HEADER_MAX_SIZE]; // Custom HTTP proxy header
char HintStr[MAX_HOST_NAME_LEN + 1]; // Hint string for NAT-T
IP BindLocalIP; // Source IP address for outgoing connection
UINT BindLocalPort; // Source port number for outgoing connection
};
// Client authentication data

View File

@ -6196,6 +6196,8 @@ SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect)
{
volatile bool *cancel_flag = NULL;
char hostname[MAX_HOST_NAME_LEN];
char localaddr[MAX_HOST_NAME_LEN];
bool save_resolved_ip = false;
CLIENT_OPTION *o;
SESSION *sess;
@ -6255,10 +6257,48 @@ SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect)
if (o->PortUDP == 0)
{
IP *localIP;
UINT localport;
// Top of Bind outgoing connection
// Decide the binding operation which is explicitly executed on the client-side
// In the case of first TCP/IP connection
if (additional_connect == false) {
if (sess->ClientOption->NoRoutingTracking == false) {
localIP = BIND_LOCALIP_NULL; // Specify not to bind
}
else {
Debug("ClientConnectGetSocket(): Using client option %r and %d for binding\n"
, sess->ClientOption->BindLocalIP, sess->ClientOption->BindLocalPort);
// Nonzero address is for source IP address to bind. Zero address is for dummy not to bind.
if (IsZeroIP(&sess->ClientOption->BindLocalIP) == true) {
localIP = BIND_LOCALIP_NULL;
}
else {
localIP = &sess->ClientOption->BindLocalIP;
}
}
}
// In the case of second and subsequent TCP/IP connections
else {
// Bind the socket to the actual local IP address of first TCP / IP connection
localIP = &sess->LocalIP_CacheForNextConnect;
//localIP = BIND_LOCALIP_NULL; // Specify not to bind for test
}
if (sess->ClientOption->BindLocalPort == 0) {
localport = BIND_LOCALPORT_NULL;
}
else {
localport = sess->ClientOption->BindLocalPort + Count(sess->Connection->CurrentNumConnection) - 1;
Debug("ClientConnectGetSocket(): Additional port number %u\n", localport);
}
// Bottom of Bind outgoing connection
// If additional_connect == false, enable trying to NAT-T connection
// If additional_connect == true, follow the IsRUDPSession setting in this session
// In additional connect or redirect we do not need ssl verification as the certificate is always compared with a saved one
sock = TcpIpConnectEx2(hostname, c->ServerPort,
sock = BindTcpIpConnectEx2(localIP, localport, hostname, c->ServerPort,
(bool *)cancel_flag, c->hWndForUI, &nat_t_err, (additional_connect ? (!sess->IsRUDPSession) : false),
true, ((additional_connect || c->UseTicket) ? NULL : sess->SslOption), &ssl_err, o->HintStr, &resolved_ip);
}
@ -6328,6 +6368,33 @@ SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect)
StrCpy(in.HttpCustomHeader, sizeof(in.HttpCustomHeader), o->CustomHttpHeader);
StrCpy(in.HttpUserAgent, sizeof(in.HttpUserAgent), c->Cedar->HttpUserAgent);
// Top of Bind outgoing connection
// In the case of first TCP/IP connection
if (additional_connect == false) {
if (sess->ClientOption->NoRoutingTracking == false) {
in.BindLocalIP = BIND_LOCALIP_NULL; // Specify not to bind
}
else {
if (IsZeroIP(&sess->ClientOption->BindLocalIP) == true) {
in.BindLocalIP = BIND_LOCALIP_NULL;
}
else {
in.BindLocalIP = &sess->ClientOption->BindLocalIP;
}
}
}
// In the case of second and subsequent TCP/IP connections
else {
in.BindLocalIP = &sess->LocalIP_CacheForNextConnect;
}
if (sess->ClientOption->BindLocalPort == 0) {
in.BindLocalPort = BIND_LOCALPORT_NULL;
}
else {
in.BindLocalPort = sess->ClientOption->BindLocalPort + Count(sess->Connection->CurrentNumConnection) - 1;
}
// Bottom of Bind outgoing connection
#ifdef OS_WIN32
in.Hwnd = c->hWndForUI;
#endif
@ -6338,13 +6405,16 @@ SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect)
switch (o->ProxyType)
{
case PROXY_HTTP:
ret = ProxyHttpConnect(&out, &in, cancel_flag);
// ret = ProxyHttpConnect(&out, &in, cancel_flag);
ret = BindProxyHttpConnect(&out, &in, cancel_flag); // Bind outgoing connection
break;
case PROXY_SOCKS:
ret = ProxySocks4Connect(&out, &in, cancel_flag);
// ret = ProxySocks4Connect(&out, &in, cancel_flag);
ret = BindProxySocks4Connect(&out, &in, cancel_flag); // Bind outgoing connection
break;
case PROXY_SOCKS5:
ret = ProxySocks5Connect(&out, &in, cancel_flag);
// ret = ProxySocks5Connect(&out, &in, cancel_flag);
ret = BindProxySocks5Connect(&out, &in, cancel_flag); // Bind outgoing connection
break;
default:
c->Err = ERR_INTERNAL_ERROR;
@ -6379,6 +6449,25 @@ SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect)
Debug("ClientConnectGetSocket(): Saved %s IP address %r for future connections.\n", hostname, &resolved_ip);
}
// Top of Bind outgoing connection
IPToStr(localaddr, sizeof(localaddr), &sock->LocalIP);
// In the case of first TCP/IP connection, save the local IP address
if (additional_connect == false) {
c->Session->LocalIP_CacheForNextConnect = sock->LocalIP;
Debug("ClientConnectGetSocket(): Saved local IP address %r for future connections.\n", &sock->LocalIP);
}
// In the case of second and subsequent TCP/IP connections, check to see whether or not the local IP address is same as the first one
else {
if (memcmp(sock->LocalIP.address, c->Session->LocalIP_CacheForNextConnect.address, sizeof(sock->LocalIP.address)) == 0) {
Debug("ClientConnectGetSocket(): Binded local IP address %s OK\n", localaddr);
}
else {
Debug("ClientConnectGetSocket(): Binded local IP address %s NG\n", localaddr);
}
}
// Bottom of Bind outgoing connection
return sock;
}
@ -6409,15 +6498,41 @@ UINT ProxyCodeToCedar(UINT code)
// TCP connection function
SOCK *TcpConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, IP *ret_ip)
{
return TcpConnectEx4(hostname, port, timeout, cancel_flag, hWnd, no_nat_t, nat_t_error_code, try_start_ssl, NULL, NULL, NULL, ret_ip);
return BindTcpConnectEx3(BIND_LOCALIP_NULL, BIND_LOCALPORT_NULL, hostname, port, timeout, cancel_flag, hWnd, no_nat_t, nat_t_error_code, try_start_ssl, ret_ip);
}
SOCK *TcpConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip)
SOCK *TcpConnectEx4(char * hostname, UINT port, UINT timeout, bool * cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip)
{
return BindTcpConnectEx4(BIND_LOCALIP_NULL, BIND_LOCALPORT_NULL, hostname, port, timeout, cancel_flag, hWnd, no_nat_t, nat_t_error_code, try_start_ssl, ssl_option, ssl_err, hint_str, ret_ip);
}
// Connect with TCP/IP
SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, IP *ret_ip)
{
return BindTcpIpConnectEx(BIND_LOCALIP_NULL, BIND_LOCALPORT_NULL, hostname, port, cancel_flag, hWnd, nat_t_error_code, no_nat_t, try_start_ssl, ret_ip);
}
SOCK *TcpIpConnectEx2(char * hostname, UINT port, bool * cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip)
{
return BindTcpIpConnectEx2(BIND_LOCALIP_NULL, BIND_LOCALPORT_NULL, hostname, port, cancel_flag, hWnd, nat_t_error_code, no_nat_t, try_start_ssl, ssl_option, ssl_err, hint_str, ret_ip);
}
// TCP connection function
//SOCK* TcpConnectEx3(char* hostname, UINT port, UINT timeout, bool* cancel_flag, void* hWnd, bool no_nat_t, UINT* nat_t_error_code, bool try_start_ssl, IP* ret_ip)
SOCK *BindTcpConnectEx3(IP *localIP, UINT localport, char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, IP *ret_ip)
{
// return TcpConnectEx4(hostname, port, timeout, cancel_flag, hWnd, no_nat_t, nat_t_error_code, try_start_ssl, NULL, NULL, NULL, ret_ip);
return BindTcpConnectEx4(localIP, localport, hostname, port, timeout, cancel_flag, hWnd, no_nat_t, nat_t_error_code, try_start_ssl, NULL, NULL, NULL, ret_ip);
}
//SOCK *TcpConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip)
SOCK *BindTcpConnectEx4(IP *localIP, UINT localport, char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip)
{
#ifdef OS_WIN32
if (hWnd == NULL)
{
#endif // OS_WIN32
return ConnectEx5(hostname, port, timeout, cancel_flag, (no_nat_t ? NULL : VPN_RUDP_SVC_NAME), nat_t_error_code, try_start_ssl, true, ssl_option, ssl_err, hint_str, ret_ip);
// return ConnectEx5(hostname, port, timeout, cancel_flag, (no_nat_t ? NULL : VPN_RUDP_SVC_NAME), nat_t_error_code, try_start_ssl, true, ssl_option, ssl_err, hint_str, ret_ip);
return BindConnectEx5(localIP, localport, hostname, port, timeout, cancel_flag, (no_nat_t ? NULL : VPN_RUDP_SVC_NAME), nat_t_error_code, try_start_ssl, true, ssl_option, ssl_err, hint_str, ret_ip);
#ifdef OS_WIN32
}
else
@ -6428,11 +6543,14 @@ SOCK *TcpConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag,
}
// Connect with TCP/IP
SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, IP *ret_ip)
//SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, IP *ret_ip)
SOCK *BindTcpIpConnectEx(IP *localIP, UINT localport, char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, IP *ret_ip)
{
return TcpIpConnectEx2(hostname, port, cancel_flag, hWnd, nat_t_error_code, no_nat_t, try_start_ssl, NULL, NULL, NULL, ret_ip);
// return TcpIpConnectEx2(hostname, port, cancel_flag, hWnd, nat_t_error_code, no_nat_t, try_start_ssl, NULL, NULL, NULL, ret_ip);
return BindTcpIpConnectEx2(localIP, localport, hostname, port, cancel_flag, hWnd, nat_t_error_code, no_nat_t, try_start_ssl, NULL, NULL, NULL, ret_ip);
}
SOCK *TcpIpConnectEx2(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip)
//SOCK *TcpIpConnectEx2(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip)
SOCK *BindTcpIpConnectEx2(IP *localIP, UINT localport, char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip)
{
SOCK *s = NULL;
UINT dummy_int = 0;
@ -6447,7 +6565,8 @@ SOCK *TcpIpConnectEx2(char *hostname, UINT port, bool *cancel_flag, void *hWnd,
return NULL;
}
s = TcpConnectEx4(hostname, port, 0, cancel_flag, hWnd, no_nat_t, nat_t_error_code, try_start_ssl, ssl_option, ssl_err, hint_str, ret_ip);
// s = TcpConnectEx4(hostname, port, 0, cancel_flag, hWnd, no_nat_t, nat_t_error_code, try_start_ssl, ssl_option, ssl_err, hint_str, ret_ip);
s = BindTcpConnectEx4(localIP, localport, hostname, port, 0, cancel_flag, hWnd, no_nat_t, nat_t_error_code, try_start_ssl, ssl_option, ssl_err, hint_str, ret_ip);
if (s == NULL)
{
return NULL;

View File

@ -115,6 +115,11 @@ bool ClientConnect(CONNECTION *c);
SOCK *ClientConnectToServer(CONNECTION *c);
SOCK *TcpIpConnectEx(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, IP *ret_ip);
SOCK *TcpIpConnectEx2(char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip);
// New function named with prefix "Bind" binds outgoing connection to a specific address. New one is wrapped in original one.
SOCK* BindTcpIpConnectEx(IP *localIP, UINT localport, char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, IP *ret_ip);
SOCK* BindTcpIpConnectEx2(IP *localIP, UINT localport, char *hostname, UINT port, bool *cancel_flag, void *hWnd, UINT *nat_t_error_code, bool no_nat_t, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip);
bool ClientUploadSignature(SOCK *s);
bool ClientDownloadHello(CONNECTION *c, SOCK *s);
bool ServerDownloadSignature(CONNECTION *c, char **error_detail_str);
@ -124,6 +129,10 @@ SOCK *ClientConnectGetSocket(CONNECTION *c, bool additional_connect);
SOCK *TcpConnectEx3(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, IP *ret_ip);
SOCK *TcpConnectEx4(char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip);
// New function named with prefix "Bind" binds outgoing connection to a specific address. New one is wrapped in original one.
SOCK* BindTcpConnectEx3(IP *localIP, UINT localport, char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, IP *ret_ip);
SOCK* BindTcpConnectEx4(IP *localIP, UINT localport, char *hostname, UINT port, UINT timeout, bool *cancel_flag, void *hWnd, bool no_nat_t, UINT *nat_t_error_code, bool try_start_ssl, SSL_VERIFY_OPTION *ssl_option, UINT *ssl_err, char *hint_str, IP *ret_ip);
UINT ProxyCodeToCedar(UINT code);
void InitProtocol();

View File

@ -41,7 +41,10 @@ typedef struct SETTING
char HubName[MAX_HUBNAME_LEN + 1]; // HUB name
UCHAR HashedPassword[SHA1_SIZE]; // Password
CLIENT_OPTION ClientOption; // Client Option
UCHAR Reserved[10240 - sizeof(UINT) * 8 - SHA1_SIZE - HTTP_CUSTOM_HEADER_MAX_SIZE - MAX_HOST_NAME_LEN - 1]; // Reserved area
#define SRC_SIZE (sizeof(IP) + sizeof(UINT)) // Source IP address & port number for outgoing connection
// UCHAR Reserved[10240 - sizeof(UINT) * 8 - SHA1_SIZE - HTTP_CUSTOM_HEADER_MAX_SIZE - MAX_HOST_NAME_LEN - 1]; // Reserved area
UCHAR Reserved[10240 - sizeof(UINT) * 8 - SHA1_SIZE - HTTP_CUSTOM_HEADER_MAX_SIZE - MAX_HOST_NAME_LEN - 1 - SRC_SIZE]; // Reserved area
} SETTING;
// Structure declaration

View File

@ -609,6 +609,24 @@ void SessionMain(SESSION *s)
WHERE;
}
}
// If all the specified number of tcp connections are not alive continuously, then terminate the session.
UINT num_tcp_conn = LIST_NUM(s->Connection->Tcp->TcpSockList);
UINT max_conn = s->ClientOption->MaxConnection;
if ((s->CurrentConnectionEstablishTime +
(UINT64)(s->ClientOption->AdditionalConnectionInterval * 1000 * 2 + CONNECTING_TIMEOUT * 2))
<= Tick64())
{
if (s->ClientOption->BindLocalPort != 0 || num_tcp_conn == 0)
{
timeouted = true;
WHERE;
}
}
//Debug("SessionMain(): The number of TCP connections short... Num_Tcp_Conn=%d Max_Conn=%d Curr_Conn_Time=%llu Tick64=%llu\n"
// , num_tcp_conn, max_conn, s->CurrentConnectionEstablishTime, Tick64());
}
}
@ -1430,6 +1448,7 @@ void ClientThread(THREAD *t, void *param)
while (true)
{
Zero(&s->ServerIP_CacheForNextConnect, sizeof(IP));
Zero(&s->LocalIP_CacheForNextConnect, sizeof(IP)); // Assigned by first outgoing connection
Zero(s->UnderlayProtocol, sizeof(s->UnderlayProtocol));
Zero(s->ProtocolDetails, sizeof(s->ProtocolDetails));

View File

@ -130,6 +130,7 @@ struct SESSION
UCHAR Padding[2];
IP ServerIP_CacheForNextConnect; // Server IP, cached for next connect
IP LocalIP_CacheForNextConnect; // Local IP, cached for next connect (2nd and subsequent), assigned by first outgoing connection
UINT64 CreatedTime; // Creation date and time
UINT64 LastCommTime; // Last communication date and time