1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-09-20 02:09:25 +03:00

Rename "OpenVPN_UdpPortList" to "PortsUDP", store ports in a LIST

Now that Proto supports UDP, the server can handle multiple protocols on each UDP port.

The UDP ports are specified by the "OpenVPN_UdpPortList" configuration setting, because:

- OpenVPN is currently the only UDP protocol supported by SoftEther VPN to allow a custom port number.
- Before Proto was introduced, a unified interface for the protocols didn't exist; each protocol implementation had to create its own listener.

In preparation for the upcoming WireGuard implementation, this commit renames "OpenVPN_UdpPortList" to "PortsUDP", which should clarify that the setting is global.

The change is reflected in the code. Also, the ports are now stored in a LIST rather than a string. The conversion between string and LIST only happens when loading/saving the configuration.

The default UDP ports are now the same as the TCP ones (443, 992, 1194, 5555).
This commit is contained in:
Davide Beatrici
2020-05-19 04:24:05 +02:00
parent 60cc784aee
commit c4ec63fe32
11 changed files with 54 additions and 67 deletions

View File

@ -2123,7 +2123,7 @@ UINT StMakeOpenVpnConfigFile(ADMIN *a, RPC_READ_LOG_FILE *t)
return ERR_OPENVPN_IS_NOT_ENABLED;
}
port_list = StrToIntList(config.OpenVPNPortList, true);
port_list = s->PortsUDP;
FreeRpcReadLogFile(t);
Zero(t, sizeof(RPC_READ_LOG_FILE));
@ -2358,8 +2358,6 @@ UINT StMakeOpenVpnConfigFile(ADMIN *a, RPC_READ_LOG_FILE *t)
Free(zero_buffer);
}
FreeStrList(port_list);
FreeZipPacker(p);
return ERR_NO_ERROR;
@ -10059,7 +10057,6 @@ void InOpenVpnSstpConfig(OPENVPN_SSTP_CONFIG *t, PACK *p)
t->EnableOpenVPN = PackGetBool(p, "EnableOpenVPN");
t->EnableSSTP = PackGetBool(p, "EnableSSTP");
PackGetStr(p, "OpenVPNPortList", t->OpenVPNPortList, sizeof(t->OpenVPNPortList));
t->OpenVPNObfuscation= PackGetBool(p, "OpenVPNObfuscation");
PackGetStr(p, "OpenVPNObfuscationMask", t->OpenVPNObfuscationMask, sizeof(t->OpenVPNObfuscationMask));
}
@ -10073,7 +10070,6 @@ void OutOpenVpnSstpConfig(PACK *p, OPENVPN_SSTP_CONFIG *t)
PackAddBool(p, "EnableOpenVPN", t->EnableOpenVPN);
PackAddBool(p, "EnableSSTP", t->EnableSSTP);
PackAddStr(p, "OpenVPNPortList", t->OpenVPNPortList);
PackAddBool(p, "OpenVPNObfuscation", t->OpenVPNObfuscation);
PackAddStr(p, "OpenVPNObfuscationMask", t->OpenVPNObfuscationMask);
}

View File

@ -21631,7 +21631,6 @@ UINT PsOpenVpnEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
{
// "name", prompt_proc, prompt_param, eval_proc, eval_param
{"[yes|no]", CmdPrompt, _UU("CMD_OpenVpnEnable_Prompt_[yes|no]"), CmdEvalNotEmpty, NULL},
{"PORTS", CmdPrompt, _UU("CMD_OpenVpnEnable_Prompt_PORTS"), CmdEvalNotEmpty, NULL},
};
o = ParseCommandList(c, cmd_name, str, args, sizeof(args) / sizeof(args[0]));
@ -21654,7 +21653,6 @@ UINT PsOpenVpnEnable(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
}
t.EnableOpenVPN = GetParamYes(o, "[yes|no]");
StrCpy(t.OpenVPNPortList, sizeof(t.OpenVPNPortList), GetParamStr(o, "PORTS"));
// RPC call
ret = ScSetOpenVpnSstpConfig(ps->Rpc, &t);
@ -21700,14 +21698,10 @@ UINT PsOpenVpnGet(CONSOLE *c, char *cmd_name, wchar_t *str, void *param)
}
else
{
wchar_t tmp[MAX_PATH];
CT *ct = CtNewStandard();
CtInsert(ct, _UU("CMD_OpenVpnGet_PRINT_Enabled"), _UU(t.EnableOpenVPN ? "SEC_YES" : "SEC_NO"));
StrToUni(tmp, sizeof(tmp), t.OpenVPNPortList);
CtInsert(ct, _UU("CMD_OpenVpnGet_PRINT_Ports"), tmp);
CtFree(ct, c);
}

View File

@ -33,8 +33,6 @@ void SiSetOpenVPNAndSSTPConfig(SERVER *s, OPENVPN_SSTP_CONFIG *c)
Lock(s->OpenVpnSstpConfigLock);
{
LIST *ports;
// Save the settings
if (s->Cedar->Bridge || s->ServerType != SERVER_TYPE_STANDALONE)
{
@ -47,12 +45,6 @@ void SiSetOpenVPNAndSSTPConfig(SERVER *s, OPENVPN_SSTP_CONFIG *c)
s->DisableOpenVPNServer = !c->EnableOpenVPN;
}
// TODO: Now that we have a unified protocol interface (Proto), the setting's name should be changed.
NormalizeIntListStr(s->OpenVpnServerUdpPorts, sizeof(s->OpenVpnServerUdpPorts), c->OpenVPNPortList, true, ", ");
ports = StrToIntList(s->OpenVpnServerUdpPorts, true);
ProtoSetUdpPorts(s->Proto, ports);
ReleaseIntList(ports);
s->Cedar->OpenVPNObfuscation = c->OpenVPNObfuscation;
StrCpy(s->Cedar->OpenVPNObfuscationMask, sizeof(s->Cedar->OpenVPNObfuscationMask), c->OpenVPNObfuscationMask);
}
@ -82,8 +74,6 @@ void SiGetOpenVPNAndSSTPConfig(SERVER *s, OPENVPN_SSTP_CONFIG *c)
c->EnableSSTP = true;
}
StrCpy(c->OpenVPNPortList, sizeof(c->OpenVPNPortList), s->OpenVpnServerUdpPorts);
c->OpenVPNObfuscation = s->Cedar->OpenVPNObfuscation;
StrCpy(c->OpenVPNObfuscationMask, sizeof(c->OpenVPNObfuscationMask), s->Cedar->OpenVPNObfuscationMask);
}
@ -2494,25 +2484,30 @@ void SiLoadInitialConfiguration(SERVER *s)
}
else
{
// Enable the SSTP and OpenVPN for default setting
OPENVPN_SSTP_CONFIG c;
Zero(&c, sizeof(c));
c.EnableOpenVPN = true;
c.EnableSSTP = true;
{
ToStr(c.OpenVPNPortList, OPENVPN_UDP_PORT);
}
// Enable SSTP and OpenVPN by default
c.EnableSSTP = true;
c.EnableOpenVPN = true;
c.OpenVPNObfuscation = false;
// Disable VPN-over-ICMP and VPN-over-DNS by default
s->EnableVpnOverIcmp = false;
s->EnableVpnOverDns = false;
SiSetOpenVPNAndSSTPConfig(s, &c);
{
// Enable VPN-over-ICMP" and VPN-over-DNS for default setting
s->EnableVpnOverIcmp = false;
s->EnableVpnOverDns = false;
LIST *ports = s->PortsUDP;
AddInt(ports, SERVER_DEF_PORTS_1);
AddInt(ports, SERVER_DEF_PORTS_2);
AddInt(ports, SERVER_DEF_PORTS_3);
AddInt(ports, SERVER_DEF_PORTS_4);
ProtoSetUdpPorts(s->Proto, ports);
}
}
@ -5946,19 +5941,36 @@ void SiLoadServerCfg(SERVER *s, FOLDER *f)
s->DisableOpenVPNServer = true;
}
// Read the OpenVPN Port List
if (CfgGetStr(f, "OpenVPN_UdpPortList", tmp, sizeof(tmp)) == false)
if (CfgGetStr(f, "PortsUDP", tmp, sizeof(tmp)))
{
UINT i;
TOKEN_LIST *tokens;
LIST *ports = s->PortsUDP;
for (i = 0; i < LIST_NUM(ports); ++i)
{
ToStr(tmp, OPENVPN_UDP_PORT);
Free(LIST_DATA(ports, i));
}
DeleteAll(ports);
NormalizeIntListStr(tmp, sizeof(tmp), tmp, true, ", ");
tokens = ParseTokenWithoutNullStr(tmp, ", ");
for (i = 0; i < tokens->NumTokens; ++i)
{
char *str = tokens->Token[i];
if (IsNum(str))
{
InsertIntDistinct(ports, ToInt(str));
}
}
FreeToken(tokens);
}
// Apply the configuration of SSTP and OpenVPN
Zero(&config, sizeof(config));
config.EnableOpenVPN = !s->DisableOpenVPNServer;
config.EnableSSTP = !s->DisableSSTPServer;
StrCpy(config.OpenVPNPortList, sizeof(config.OpenVPNPortList), tmp);
config.OpenVPNObfuscation = CfgGetBool(f, "OpenVPNObfuscation");
@ -6132,6 +6144,12 @@ void SiWriteServerCfg(FOLDER *f, SERVER *s)
CfgAddIp(f, "ListenIP", &s->ListenIP);
{
char str[MAX_SIZE];
IntListToStr(str, sizeof(str), s->PortsUDP, ", ");
CfgAddStr(f, "PortsUDP", str);
}
if (s->Logger != NULL)
{
CfgAddInt(f, "ServerLogSwitchType", s->Logger->SwitchType);
@ -6244,8 +6262,6 @@ void SiWriteServerCfg(FOLDER *f, SERVER *s)
SiGetOpenVPNAndSSTPConfig(s, &config);
CfgAddStr(f, "OpenVPN_UdpPortList", config.OpenVPNPortList);
CfgAddBool(f, "OpenVPNObfuscation", config.OpenVPNObfuscation);
CfgAddStr(f, "OpenVPNObfuscationMask", config.OpenVPNObfuscationMask);
}
@ -6862,6 +6878,8 @@ void SiCleanupServer(SERVER *s)
// Stop all listeners
SiStopAllListener(s);
ReleaseIntList(s->PortsUDP);
if (s->ServerType == SERVER_TYPE_FARM_CONTROLLER)
{
// In the case of farm controller
@ -10712,6 +10730,7 @@ SERVER *SiNewServerEx(bool bridge, bool in_client_inner_server, bool relay_serve
s->Cedar->CheckExpires = true;
s->ServerListenerList = NewList(CompareServerListener);
s->PortsUDP = NewIntList(true);
s->StartTime = SystemTime64();
s->TasksFromFarmControllerLock = NewLock();

View File

@ -147,7 +147,6 @@ struct SYSLOG_SETTING
struct OPENVPN_SSTP_CONFIG
{
bool EnableOpenVPN; // OpenVPN is enabled
char OpenVPNPortList[MAX_SIZE]; // OpenVPN UDP port number list
bool OpenVPNObfuscation; // OpenVPN: Obfuscation mode
char OpenVPNObfuscationMask[MAX_SIZE]; // OpenVPN: String (mask) for XOR obfuscation
bool EnableSSTP; // SSTP is enabled
@ -159,6 +158,7 @@ struct SERVER
UINT ServerType; // Type of server
UINT UpdatedServerType; // Type of updated server
LIST *ServerListenerList; // Server listener list
LIST *PortsUDP; // The ports used by Proto's UDP listener
UCHAR HashedPassword[SHA1_SIZE]; // Password
char ControllerName[MAX_HOST_NAME_LEN + 1]; // Controller name
UINT ControllerPort; // Controller port
@ -244,7 +244,6 @@ struct SERVER
PROTO *Proto; // Protocols handler
IPSEC_SERVER *IPsecServer; // IPsec server function
char OpenVpnServerUdpPorts[MAX_SIZE]; // UDP port list string
DDNS_CLIENT *DDnsClient; // DDNS client feature
LOCK *OpenVpnSstpConfigLock; // Lock OpenVPN and SSTP configuration