mirror of
https://github.com/SoftEtherVPN/SoftEtherVPN.git
synced 2024-11-23 01:49:53 +03:00
OpenVPN: hostname support
OpenVPN sends the default gateway's MAC address, if the option --push-peer-info is enabled. It also sends the client's environment variables whose names start with "UV_". This commit adds some lines of code in OvsBeginIPCAsyncConnectionIfEmpty(), in order to set the hostname to "UV_HOSTNAME"'s value, which is defined by the user on their device. In case "UV_HOSTNAME" is not available, "IV_HWADDR"'s value (the default gateway's MAC address) is used instead. OvsParseOptions() has been adapted into a new function called OvsParsePeerInfo(), in order to parse the peer info string.
This commit is contained in:
parent
1e8cf1dc5d
commit
3ceee41d33
@ -673,6 +673,7 @@ void OvsBeginIPCAsyncConnectionIfEmpty(OPENVPN_SERVER *s, OPENVPN_SESSION *se, O
|
|||||||
|
|
||||||
if (se->IpcAsync == NULL)
|
if (se->IpcAsync == NULL)
|
||||||
{
|
{
|
||||||
|
LIST *pi;
|
||||||
IPC_PARAM p;
|
IPC_PARAM p;
|
||||||
ETHERIP_ID id;
|
ETHERIP_ID id;
|
||||||
|
|
||||||
@ -702,6 +703,24 @@ void OvsBeginIPCAsyncConnectionIfEmpty(OPENVPN_SERVER *s, OPENVPN_SESSION *se, O
|
|||||||
StrCpy(p.CryptName, sizeof(p.CryptName), c->CipherEncrypt->Name);
|
StrCpy(p.CryptName, sizeof(p.CryptName), c->CipherEncrypt->Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OpenVPN sends the default gateway's MAC address,
|
||||||
|
// if the option --push-peer-info is enabled.
|
||||||
|
// It also sends all of the client's environment
|
||||||
|
// variables whose names start with "UV_".
|
||||||
|
pi = OvsParsePeerInfo(c->ClientKey.PeerInfo);
|
||||||
|
|
||||||
|
// Check presence of custom hostname
|
||||||
|
if (OvsHasOption(pi, "UV_HOSTNAME"))
|
||||||
|
{
|
||||||
|
StrCpy(p.ClientHostname, sizeof(p.ClientHostname), IniStrValue(pi, "UV_HOSTNAME"));
|
||||||
|
}
|
||||||
|
else // Use the default gateway's MAC address
|
||||||
|
{
|
||||||
|
StrCpy(p.ClientHostname, sizeof(p.ClientHostname), IniStrValue(pi, "IV_HWADDR"));
|
||||||
|
}
|
||||||
|
|
||||||
|
OvsFreeOptions(pi);
|
||||||
|
|
||||||
if (se->Mode == OPENVPN_MODE_L3)
|
if (se->Mode == OPENVPN_MODE_L3)
|
||||||
{
|
{
|
||||||
// L3 Mode
|
// L3 Mode
|
||||||
@ -1000,6 +1019,41 @@ LIST *OvsParseOptions(char *str)
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Parse the peer info string
|
||||||
|
LIST *OvsParsePeerInfo(char *str)
|
||||||
|
{
|
||||||
|
LIST *o = NewListFast(NULL);
|
||||||
|
TOKEN_LIST *t;
|
||||||
|
|
||||||
|
t = ParseTokenWithoutNullStr(str, "\n");
|
||||||
|
if (t != NULL)
|
||||||
|
{
|
||||||
|
UINT i;
|
||||||
|
|
||||||
|
for (i = 0;i < t->NumTokens;i++)
|
||||||
|
{
|
||||||
|
char key[MAX_SIZE];
|
||||||
|
char value[MAX_SIZE];
|
||||||
|
char *line = t->Token[i];
|
||||||
|
Trim(line);
|
||||||
|
|
||||||
|
if (GetKeyAndValue(line, key, sizeof(key), value, sizeof(value), "=\t"))
|
||||||
|
{
|
||||||
|
INI_ENTRY *e = ZeroMalloc(sizeof(INI_ENTRY));
|
||||||
|
|
||||||
|
e->Key = CopyStr(key);
|
||||||
|
e->Value = CopyStr(value);
|
||||||
|
|
||||||
|
Add(o, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FreeToken(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
// Release the option list
|
// Release the option list
|
||||||
void OvsFreeOptions(LIST *o)
|
void OvsFreeOptions(LIST *o)
|
||||||
{
|
{
|
||||||
|
@ -362,6 +362,7 @@ BUF *OvsBuildKeyMethod2(OPENVPN_KEY_METHOD_2 *d);
|
|||||||
void OvsWriteStringToBuf(BUF *b, char *str, UINT max_size);
|
void OvsWriteStringToBuf(BUF *b, char *str, UINT max_size);
|
||||||
|
|
||||||
LIST *OvsParseOptions(char *str);
|
LIST *OvsParseOptions(char *str);
|
||||||
|
LIST *OvsParsePeerInfo(char *str);
|
||||||
void OvsFreeOptions(LIST *o);
|
void OvsFreeOptions(LIST *o);
|
||||||
LIST *OvsNewOptions();
|
LIST *OvsNewOptions();
|
||||||
void OvsAddOption(LIST *o, char *key, char *value);
|
void OvsAddOption(LIST *o, char *key, char *value);
|
||||||
|
Loading…
Reference in New Issue
Block a user