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

Cedar: Add "DefaultGateway" and "DefaultSubnet" virtual hub options

WireGuard does not provide any configuration messages, meaning that we cannot push the IP address we receive from the DHCP server to the client.

In order to overcome the limitation we don't perform any DHCP operations and instead just extract the source IP address from the first IPv4 packet we receive in the tunnel.

The gateway address and the subnet mask can be set using the new "SetStaticNetwork" command. The values can be retrieved using "OptionsGet".

In future we will add a "allowed source IP addresses" function, similar to what the original WireGuard implementation provides.

================================================================================

SetStaticNetwork command - Set Virtual Hub static IPv4 network parameters
Help for command "SetStaticNetwork"

Purpose:
  Set Virtual Hub static IPv4 network parameters

Description:
  Set the static IPv4 network parameters for the Virtual Hub. They are used when DHCP is not available (e.g. WireGuard sessions).
  You can get the current settings by using the OptionsGet command.

Usage:
  SetStaticNetwork [/GATEWAY:gateway] [/SUBNET:subnet]

Parameters:
  /GATEWAY - Specify the IP address of the gateway that will be used for internet communication.
  /SUBNET  - Specify the subnet mask, required to determine the size of the local VPN network.
This commit is contained in:
Davide Beatrici
2020-09-01 03:04:14 +02:00
parent decfcecc97
commit afe576dcdc
14 changed files with 171 additions and 10 deletions

View File

@ -9061,9 +9061,12 @@ UINT StGetHub(ADMIN *a, RPC_CREATE_HUB *t)
{
StrCpy(t->HubName, sizeof(t->HubName), h->Name);
t->Online = h->Offline ? false : true;
t->HubType = h->Type;
t->HubOption.DefaultGateway = h->Option->DefaultGateway;
t->HubOption.DefaultSubnet = h->Option->DefaultSubnet;
t->HubOption.MaxSession = h->Option->MaxSession;
t->HubOption.NoEnum = h->Option->NoEnum;
t->HubType = h->Type;
}
Unlock(h->lock);
@ -9090,7 +9093,6 @@ UINT StSetHub(ADMIN *a, RPC_CREATE_HUB *t)
return ERR_INVALID_PARAMETER;
}
CHECK_RIGHT;
NO_SUPPORT_FOR_BRIDGE;
@ -9175,8 +9177,12 @@ UINT StSetHub(ADMIN *a, RPC_CREATE_HUB *t)
else
{
h->Type = t->HubType;
h->Option->DefaultGateway = t->HubOption.DefaultGateway;
h->Option->DefaultSubnet = t->HubOption.DefaultSubnet;
h->Option->MaxSession = t->HubOption.MaxSession;
h->Option->NoEnum = t->HubOption.NoEnum;
if (IsZero(t->HashedPassword, sizeof(t->HashedPassword)) == false &&
IsZero(t->SecurePassword, sizeof(t->SecurePassword)) == false)
{
@ -9234,8 +9240,6 @@ UINT StCreateHub(ADMIN *a, RPC_CREATE_HUB *t)
return ERR_NOT_FARM_CONTROLLER;
}
if (IsEmptyStr(t->HubName) || IsSafeStr(t->HubName) == false)
{
return ERR_INVALID_PARAMETER;
@ -9279,6 +9283,8 @@ UINT StCreateHub(ADMIN *a, RPC_CREATE_HUB *t)
// Create a hub object
Zero(&o, sizeof(o));
o.DefaultGateway = t->HubOption.DefaultGateway;
o.DefaultSubnet = t->HubOption.DefaultSubnet;
o.MaxSession = t->HubOption.MaxSession;
o.NoEnum = t->HubOption.NoEnum;
@ -12885,6 +12891,8 @@ void InRpcHubOption(RPC_HUB_OPTION *t, PACK *p)
}
Zero(t, sizeof(RPC_HUB_OPTION));
t->DefaultGateway = PackGetInt(p, "DefaultGateway");
t->DefaultSubnet = PackGetInt(p, "DefaultSubnet");
t->MaxSession = PackGetInt(p, "MaxSession");
t->NoEnum = PackGetBool(p, "NoEnum");
}
@ -12896,6 +12904,8 @@ void OutRpcHubOption(PACK *p, RPC_HUB_OPTION *t)
return;
}
PackAddInt(p, "DefaultGateway", t->DefaultGateway);
PackAddInt(p, "DefaultSubnet", t->DefaultSubnet);
PackAddInt(p, "MaxSession", t->MaxSession);
PackAddBool(p, "NoEnum", t->NoEnum);
}

View File

@ -229,6 +229,8 @@ struct RPC_KEY_PAIR
// HUB option
struct RPC_HUB_OPTION
{
UINT DefaultGateway; // Default gateway address
UINT DefaultSubnet; // Default subnet mask
UINT MaxSession; // Maximum number of sessions
bool NoEnum; // Not listed
};

View File

@ -7493,6 +7493,7 @@ void PsMain(PS *ps)
{"Hub", PsHub},
{"Online", PsOnline},
{"Offline", PsOffline},
{"SetStaticNetwork", PsSetStaticNetwork},
{"SetMaxSession", PsSetMaxSession},
{"SetHubPassword", PsSetHubPassword},
{"SetEnumAllow", PsSetEnumAllow},
@ -11143,6 +11144,53 @@ UINT PsOffline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
return 0;
}
// Set the static IPv4 network parameters for the Virtual HUB
UINT PsSetStaticNetwork(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
{
LIST *o;
PS *ps = (PS *)param;
UINT ret = 0;
RPC_CREATE_HUB t;
PARAM args[] =
{
{"GATEWAY", CmdPrompt, _UU("CMD_SetStaticNetwork_Prompt_GATEWAY"), CmdEvalIp, NULL},
{"SUBNET", CmdPrompt, _UU("CMD_SetStaticNetwork_Prompt_SUBNET"), CmdEvalIp, NULL}
};
if (ps->HubName == NULL)
{
c->Write(c, _UU("CMD_Hub_Not_Selected"));
return ERR_INVALID_PARAMETER;
}
o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
if (o == NULL)
{
return ERR_INVALID_PARAMETER;
}
Zero(&t, sizeof(t));
StrCpy(t.HubName, sizeof(t.HubName), ps->HubName);
ret = ScGetHub(ps->Rpc, &t);
if (ret != ERR_NO_ERROR)
{
goto FINAL;
}
t.HubOption.DefaultGateway = StrToIP32(GetParamStr(o, "GATEWAY"));
t.HubOption.DefaultSubnet = StrToIP32(GetParamStr(o, "SUBNET"));
ret = ScSetHub(ps->Rpc, &t);
FINAL:
if (ret != ERR_NO_ERROR)
{
CmdPrintError(c, ret);
}
FreeParamValueList(o);
return ret;
}
// Set the maximum number of concurrent connecting sessions of the Virtual HUB
UINT PsSetMaxSession(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
{
@ -11420,6 +11468,12 @@ UINT PsOptionsGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
CtInsert(ct, _UU("CMD_OptionsGet_TYPE"), GetHubTypeStr(t.HubType));
IPToUniStr32(tmp, sizeof(tmp), t.HubOption.DefaultGateway);
CtInsert(ct, _UU("CMD_OptionsGet_GATEWAY"), tmp);
IPToUniStr32(tmp, sizeof(tmp), t.HubOption.DefaultSubnet);
CtInsert(ct, _UU("CMD_OptionsGet_SUBNET"), tmp);
CtFree(ct, c);
}

View File

@ -456,6 +456,7 @@ UINT PsHubList(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsHub(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsOnline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsOffline(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsSetStaticNetwork(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsSetMaxSession(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsSetHubPassword(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);
UINT PsSetEnumAllow(CONSOLE *c, char *cmd_name, wchar_t *str, void *param);

View File

@ -116,6 +116,8 @@ struct HUB_PA
struct HUB_OPTION
{
// Standard options
UINT DefaultGateway; // Used in IPC when DHCP cannot be used (e.g. WireGuard sessions)
UINT DefaultSubnet; // Used in IPC when DHCP cannot be used (e.g. WireGuard sessions)
UINT MaxSession; // Maximum number of simultaneous connections
bool NoEnum; // Excluded from the enumeration
// Advanced options

View File

@ -242,6 +242,7 @@ IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char
UINT layer)
{
IPC *ipc;
HUB *hub;
UINT dummy_int = 0;
SOCK *a;
SOCK *s;
@ -466,6 +467,13 @@ IPC *NewIPC(CEDAR *cedar, char *client_name, char *postfix, char *hubname, char
PackGetStr(p, "IpcHubName", ipc->HubName, sizeof(ipc->HubName));
Debug("IPC Hub Name: %s\n", ipc->HubName);
hub = GetHub(cedar, ipc->HubName);
if (hub != NULL)
{
UINTToIP(&ipc->DefaultGateway, hub->Option->DefaultGateway);
UINTToIP(&ipc->SubnetMask, hub->Option->DefaultSubnet);
}
MacToStr(macstr, sizeof(macstr), ipc->MacAddress);
Debug("IPC: Session = %s, Connection = %s, Mac = %s\n", ipc->SessionName, ipc->ConnectionName, macstr);

View File

@ -2279,6 +2279,8 @@ void SiSetDefaultHubOption(HUB_OPTION *o)
return;
}
o->DefaultGateway = SetIP32(192, 168, 30, 1);
o->DefaultSubnet = SetIP32(255, 255, 255, 0);
o->MaxSession = 0;
o->VlanTypeId = MAC_PROTO_TAGVLAN;
o->NoIPv6DefaultRouterInRAWhenIPv6 = true;
@ -3757,6 +3759,8 @@ void SiLoadHubOptionCfg(FOLDER *f, HUB_OPTION *o)
return;
}
o->DefaultGateway = CfgGetIp32(f, "DefaultGateway");
o->DefaultSubnet = CfgGetIp32(f, "DefaultSubnet");
o->MaxSession = CfgGetInt(f, "MaxSession");
o->NoArpPolling = CfgGetBool(f, "NoArpPolling");
o->NoIPv6AddrPolling = CfgGetBool(f, "NoIPv6AddrPolling");
@ -3904,6 +3908,8 @@ void SiWriteHubOptionCfg(FOLDER *f, HUB_OPTION *o)
return;
}
CfgAddIp32(f, "DefaultGateway", o->DefaultGateway);
CfgAddIp32(f, "DefaultSubnet", o->DefaultSubnet);
CfgAddInt(f, "MaxSession", o->MaxSession);
CfgAddBool(f, "NoArpPolling", o->NoArpPolling);
CfgAddBool(f, "NoIPv6AddrPolling", o->NoIPv6AddrPolling);