1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2025-07-07 16:25:01 +03:00

Change IP structure so that IPv4 addresses are stored in RFC3493 format

In addition to saving 4 bytes for each instantiation, this change makes IP-related operations faster and clearer.

https://tools.ietf.org/html/rfc3493.html#section-3.7
This commit is contained in:
Davide Beatrici
2021-04-07 21:24:55 +02:00
parent 01663f836d
commit 1708998a11
21 changed files with 295 additions and 403 deletions

View File

@ -2117,7 +2117,7 @@ bool ServerAccept(CONNECTION *c)
if (is_empty_password)
{
const SOCK *s = c->FirstSock;
if (s != NULL && s->RemoteIP.addr[0] != 127)
if (s != NULL && IsLocalHostIP(&s->RemoteIP) == false)
{
if (StrCmpi(username, ADMINISTRATOR_USERNAME) == 0 || GetHubAdminOption(hub, "deny_empty_password") != 0)
{
@ -3834,7 +3834,7 @@ void CreateNodeInfo(NODE_INFO *info, CONNECTION *c)
}
else
{
Copy(info->ClientIpAddress6, c->FirstSock->LocalIP.ipv6_addr, sizeof(info->ClientIpAddress6));
Copy(info->ClientIpAddress6, c->FirstSock->LocalIP.address, sizeof(info->ClientIpAddress6));
}
// Client port number
info->ClientPort = Endian32(c->FirstSock->LocalPort);
@ -3850,7 +3850,7 @@ void CreateNodeInfo(NODE_INFO *info, CONNECTION *c)
}
else
{
Copy(info->ServerIpAddress6, ip.ipv6_addr, sizeof(info->ServerIpAddress6));
Copy(info->ServerIpAddress6, ip.address, sizeof(info->ServerIpAddress6));
}
}
// Server port number
@ -3868,7 +3868,7 @@ void CreateNodeInfo(NODE_INFO *info, CONNECTION *c)
}
else
{
Copy(&info->ProxyIpAddress6, c->FirstSock->RemoteIP.ipv6_addr, sizeof(info->ProxyIpAddress6));
Copy(&info->ProxyIpAddress6, c->FirstSock->RemoteIP.address, sizeof(info->ProxyIpAddress6));
}
info->ProxyPort = Endian32(c->FirstSock->RemotePort);
@ -5674,25 +5674,18 @@ bool ClientUploadAuth(CONNECTION *c)
// UDP acceleration function using flag
if (o->NoUdpAcceleration == false && c->Session->UdpAccel != NULL)
{
IP my_ip;
Zero(&my_ip, sizeof(my_ip));
PackAddBool(p, "use_udp_acceleration", true);
PackAddInt(p, "udp_acceleration_version", c->Session->UdpAccel->Version);
Copy(&my_ip, &c->Session->UdpAccel->MyIp, sizeof(IP));
if (IsLocalHostIP(&my_ip))
IP my_ip;
if (IsLocalHostIP(&c->Session->UdpAccel->MyIp) == false)
{
if (IsIP4(&my_ip))
{
ZeroIP4(&my_ip);
}
else
{
ZeroIP6(&my_ip);
}
Copy(&my_ip, &c->Session->UdpAccel->MyIp, sizeof(my_ip));
}
else
{
Zero(&my_ip, sizeof(my_ip));
}
PackAddIp(p, "udp_acceleration_client_ip", &my_ip);
@ -6058,7 +6051,7 @@ bool ServerDownloadSignature(CONNECTION *c, char **error_detail_str)
}
if (c->FirstSock->RemoteIP.addr[0] == 127)
if (IsLocalHostIP(&c->FirstSock->RemoteIP))
{
if (StrCmpi(h->Target, HTTP_SAITAMA) == 0)
{