mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2025-07-12 10:44:58 +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:
committed by
Davide Beatrici
parent
828d3b2ffb
commit
59e1483dbf
@ -3119,6 +3119,9 @@ void PcMain(PC *pc)
|
||||
{"AccountImport", PcAccountImport},
|
||||
{"RemoteEnable", PcRemoteEnable},
|
||||
{"RemoteDisable", PcRemoteDisable},
|
||||
{"TUNDownOnDisconnectEnable", PcTunDownOnDisconnectEnable},
|
||||
{"TUNDownOnDisconnectDisable", PcTunDownOnDisconnectDisable},
|
||||
{"TUNDownOnDisconnectGet", PcTunDownOnDisconnectGet},
|
||||
{"KeepEnable", PcKeepEnable},
|
||||
{"KeepDisable", PcKeepDisable},
|
||||
{"KeepSet", PcKeepSet},
|
||||
@ -6641,6 +6644,136 @@ UINT PcRemoteDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Enable turning TUN interface up/down on client connect/disconnect
|
||||
UINT PcTunDownOnDisconnectEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
|
||||
{
|
||||
LIST *o;
|
||||
PC *pc = (PC *)param;
|
||||
UINT ret = ERR_NO_ERROR;
|
||||
CLIENT_CONFIG t;
|
||||
|
||||
// Get the parameter list
|
||||
o = ParseCommandList(c, cmd_name, str, NULL, 0);
|
||||
if (o == NULL)
|
||||
{
|
||||
return ERR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
// RPC call
|
||||
Zero(&t, sizeof(t));
|
||||
|
||||
ret = CcGetClientConfig(pc->RemoteClient, &t);
|
||||
|
||||
if (ret == ERR_NO_ERROR)
|
||||
{
|
||||
// Change the settings
|
||||
t.NicDownOnDisconnect = true;
|
||||
ret = CcSetClientConfig(pc->RemoteClient, &t);
|
||||
}
|
||||
|
||||
if (ret == ERR_NO_ERROR)
|
||||
{
|
||||
// Success
|
||||
}
|
||||
|
||||
if (ret != ERR_NO_ERROR)
|
||||
{
|
||||
// Error has occurred
|
||||
CmdPrintError(c, ret);
|
||||
}
|
||||
|
||||
// Release of the parameter list
|
||||
FreeParamValueList(o);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Disable turning TUN interface up/down on client connect/disconnect
|
||||
UINT PcTunDownOnDisconnectDisable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
|
||||
{
|
||||
LIST *o;
|
||||
PC *pc = (PC *)param;
|
||||
UINT ret = ERR_NO_ERROR;
|
||||
CLIENT_CONFIG t;
|
||||
|
||||
// Get the parameter list
|
||||
o = ParseCommandList(c, cmd_name, str, NULL, 0);
|
||||
if (o == NULL)
|
||||
{
|
||||
return ERR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
// RPC call
|
||||
Zero(&t, sizeof(t));
|
||||
|
||||
ret = CcGetClientConfig(pc->RemoteClient, &t);
|
||||
|
||||
if (ret == ERR_NO_ERROR)
|
||||
{
|
||||
// Change the settings
|
||||
t.NicDownOnDisconnect = false;
|
||||
ret = CcSetClientConfig(pc->RemoteClient, &t);
|
||||
}
|
||||
|
||||
if (ret == ERR_NO_ERROR)
|
||||
{
|
||||
// Success
|
||||
}
|
||||
|
||||
if (ret != ERR_NO_ERROR)
|
||||
{
|
||||
// Error has occurred
|
||||
CmdPrintError(c, ret);
|
||||
}
|
||||
|
||||
// Release of the parameter list
|
||||
FreeParamValueList(o);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Get status of turning TUN interface up/down on client connect/disconnect
|
||||
UINT PcTunDownOnDisconnectGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
|
||||
{
|
||||
LIST *o;
|
||||
PC *pc = (PC *)param;
|
||||
UINT ret = ERR_NO_ERROR;
|
||||
CLIENT_CONFIG t;
|
||||
|
||||
o = ParseCommandList(c, cmd_name, str, NULL, 0);
|
||||
if (o == NULL)
|
||||
{
|
||||
return ERR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
// RPC call
|
||||
Zero(&t, sizeof(t));
|
||||
|
||||
ret = CcGetClientConfig(pc->RemoteClient, &t);
|
||||
|
||||
if (ret == ERR_NO_ERROR)
|
||||
{
|
||||
wchar_t tmp[MAX_SIZE];
|
||||
CT *ct = CtNewStandard();
|
||||
|
||||
CtInsert(ct, _UU("CMD_TUNDownOnDisconnectGet_COLUMN1"),
|
||||
t.NicDownOnDisconnect ? _UU("SM_ACCESS_ENABLE") : _UU("SM_ACCESS_DISABLE"));
|
||||
|
||||
CtFree(ct, c);
|
||||
}
|
||||
|
||||
if (ret != ERR_NO_ERROR)
|
||||
{
|
||||
// Error has occurred
|
||||
CmdPrintError(c, ret);
|
||||
}
|
||||
|
||||
// Release of the parameter list
|
||||
FreeParamValueList(o);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Enable the maintenance function of the Internet connection
|
||||
UINT PcKeepEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
|
||||
{
|
||||
|
Reference in New Issue
Block a user