1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-07-12 02:34:59 +03:00

Put TUN down on client disconnect.

On startup client creates TUN interface in UP state and kept it UP even
if connection to the server was lost. Creating interface in DOWN state,
turning it UP on successful (re-)connection to server and DOWN on either
disconnect or connection loss would enable DHCP client (say dhclient5)
to detect necessity for lease renewal.

Added a client configuration parameter to create TUN interface in DOWN
state and commands to enable, disable, and query the configuration
parameter.
Enabling the parameter causes client to put all unused TUN interfaces
DOWN, create new TUN interfaces in DOWN state, and turn TUN interfaces
corresponding to active sessions DOWN on connection loss or
disconnecting from server.
Disabling the parameter forces client to turn all TUN interfaces UP and
create new TUN interfaces in UP state.
Default value is 'Disable'.
This commit is contained in:
Joshua Perry
2018-08-05 17:35:57 +02:00
committed by Davide Beatrici
parent 828d3b2ffb
commit 59e1483dbf
16 changed files with 436 additions and 37 deletions

View File

@ -1381,6 +1381,13 @@ void CleanupSession(SESSION *s)
FreePacketAdapter(s->PacketAdapter);
}
#ifdef OS_UNIX
if (s->NicDownOnDisconnect != NULL && *s->NicDownOnDisconnect)
{
UnixVLanSetState(s->ClientOption->DeviceName, false);
}
#endif
if (s->OldTraffic != NULL)
{
FreeTraffic(s->OldTraffic);
@ -1529,6 +1536,13 @@ void ClientThread(THREAD *t, void *param)
CLog(s->Cedar->Client, "LC_CONNECT_ERROR", s->ClientOption->AccountName,
GetUniErrorStr(s->Err), s->Err);
#ifdef OS_UNIX
if (s->NicDownOnDisconnect != NULL && *s->NicDownOnDisconnect)
{
UnixVLanSetState(s->ClientOption->DeviceName, false);
}
#endif
if (s->LinkModeClient && s->Link != NULL)
{
HLog(s->Link->Hub, "LH_CONNECT_ERROR", s->ClientOption->AccountName,
@ -1953,7 +1967,7 @@ SESSION *NewRpcSessionEx2(CEDAR *cedar, CLIENT_OPTION *option, UINT *err, char *
}
// Create a client session
SESSION *NewClientSessionEx(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, PACKET_ADAPTER *pa, ACCOUNT *account)
SESSION *NewClientSessionEx(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, PACKET_ADAPTER *pa, ACCOUNT *account, bool *NicDownOnDisconnect)
{
SESSION *s;
THREAD *t;
@ -2081,6 +2095,8 @@ SESSION *NewClientSessionEx(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *au
s->ClientOption->NumRetry = 0;
}
s->NicDownOnDisconnect = NicDownOnDisconnect;
// Create a client thread
t = NewThread(ClientThread, (void *)s);
WaitThreadInit(t);
@ -2088,9 +2104,9 @@ SESSION *NewClientSessionEx(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *au
return s;
}
SESSION *NewClientSession(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, PACKET_ADAPTER *pa)
SESSION *NewClientSession(CEDAR *cedar, CLIENT_OPTION *option, CLIENT_AUTH *auth, PACKET_ADAPTER *pa, bool *NicDownOnDisconnect)
{
return NewClientSessionEx(cedar, option, auth, pa, NULL);
return NewClientSessionEx(cedar, option, auth, pa, NULL, NicDownOnDisconnect);
}
// Get the session from the 32bit session key