1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-22 17:39:53 +03:00

Store interface metric separately as it mau change

This commit is contained in:
domosekai 2021-07-29 22:24:26 +08:00
parent dd9c3546f7
commit 9b3077d955
3 changed files with 10 additions and 25 deletions

View File

@ -162,7 +162,6 @@ void RouteTrackingMain(SESSION *s)
char ip_str2[64]; char ip_str2[64];
Copy(&e->DestIP, &nat_t_ip, sizeof(IP)); Copy(&e->DestIP, &nat_t_ip, sizeof(IP));
e->Metric = e->OldIfMetric;
IPToStr(ip_str, sizeof(ip_str), &e->DestIP); IPToStr(ip_str, sizeof(ip_str), &e->DestIP);
IPToStr(ip_str2, sizeof(ip_str2), &e->GatewayIP); IPToStr(ip_str2, sizeof(ip_str2), &e->GatewayIP);
@ -507,8 +506,6 @@ void RouteTrackingStart(SESSION *s)
Debug("GetBestRouteEntry() Succeed. [Gateway: %s]\n", tmp); Debug("GetBestRouteEntry() Succeed. [Gateway: %s]\n", tmp);
// Add a route // Add a route
e->Metric = e->OldIfMetric;
if (AddRouteEntryEx(e, &already_exists) == false) if (AddRouteEntryEx(e, &already_exists) == false)
{ {
FreeRouteEntry(e); FreeRouteEntry(e);
@ -570,8 +567,6 @@ void RouteTrackingStart(SESSION *s)
else else
{ {
// Add a route // Add a route
dns->Metric = dns->OldIfMetric;
if (AddRouteEntry(dns) == false) if (AddRouteEntry(dns) == false)
{ {
FreeRouteEntry(dns); FreeRouteEntry(dns);
@ -590,8 +585,6 @@ void RouteTrackingStart(SESSION *s)
if (route_to_real_server_global != NULL) if (route_to_real_server_global != NULL)
{ {
route_to_real_server_global->Metric = route_to_real_server_global->OldIfMetric;
if (AddRouteEntry(route_to_real_server_global) == false) if (AddRouteEntry(route_to_real_server_global) == false)
{ {
FreeRouteEntry(route_to_real_server_global); FreeRouteEntry(route_to_real_server_global);

View File

@ -9437,9 +9437,6 @@ void Win32RouteEntryToIpForwardRow2(void *ip_forward_row, ROUTE_ENTRY *entry)
r = (MIB_IPFORWARD_ROW2 *)ip_forward_row; r = (MIB_IPFORWARD_ROW2 *)ip_forward_row;
InitializeIpForwardEntry(r); InitializeIpForwardEntry(r);
MIB_IPINTERFACE_ROW *p;
p = ZeroMallocFast(sizeof(MIB_IPINTERFACE_ROW));
if (IsIP4(&entry->DestIP)) if (IsIP4(&entry->DestIP))
{ {
// IP address // IP address
@ -9450,8 +9447,6 @@ void Win32RouteEntryToIpForwardRow2(void *ip_forward_row, ROUTE_ENTRY *entry)
// Gateway IP address // Gateway IP address
r->NextHop.Ipv4.sin_family = AF_INET; r->NextHop.Ipv4.sin_family = AF_INET;
IPToInAddr(&r->NextHop.Ipv4.sin_addr, &entry->GatewayIP); IPToInAddr(&r->NextHop.Ipv4.sin_addr, &entry->GatewayIP);
// Interface
p->Family = AF_INET;
} }
else else
{ {
@ -9463,21 +9458,17 @@ void Win32RouteEntryToIpForwardRow2(void *ip_forward_row, ROUTE_ENTRY *entry)
// Gateway IP address // Gateway IP address
r->NextHop.Ipv6.sin6_family = AF_INET6; r->NextHop.Ipv6.sin6_family = AF_INET6;
IPToInAddr6(&r->NextHop.Ipv6.sin6_addr, &entry->GatewayIP); IPToInAddr6(&r->NextHop.Ipv6.sin6_addr, &entry->GatewayIP);
// Interface
p->Family = AF_INET6;
} }
// Metric // Metric offset
p->InterfaceIndex = entry->InterfaceID; if (entry->Metric >= entry->IfMetric)
if (GetIpInterfaceEntry(p) == NO_ERROR && entry->Metric >= p->Metric)
{ {
r->Metric = entry->Metric - p->Metric; r->Metric = entry->Metric - entry->IfMetric;
} }
else else
{ {
r->Metric = entry->Metric; r->Metric = 0;
} }
Free(p);
// Interface ID // Interface ID
r->InterfaceIndex = entry->InterfaceID; r->InterfaceIndex = entry->InterfaceID;
@ -9544,6 +9535,7 @@ void Win32IpForwardRow2ToRouteEntry(ROUTE_ENTRY *entry, void *ip_forward_row)
p->InterfaceIndex = r->InterfaceIndex; p->InterfaceIndex = r->InterfaceIndex;
if (GetIpInterfaceEntry(p) == NO_ERROR) if (GetIpInterfaceEntry(p) == NO_ERROR)
{ {
entry->IfMetric = p->Metric;
entry->Metric = r->Metric + p->Metric; entry->Metric = r->Metric + p->Metric;
} }
else else
@ -10243,8 +10235,8 @@ ROUTE_ENTRY *GetBestRouteEntryFromRouteTableEx(ROUTE_TABLE *table, IP *ip, UINT
Copy(&ret->GatewayIP, &tmp->GatewayIP, sizeof(IP)); Copy(&ret->GatewayIP, &tmp->GatewayIP, sizeof(IP));
ret->InterfaceID = tmp->InterfaceID; ret->InterfaceID = tmp->InterfaceID;
ret->LocalRouting = tmp->LocalRouting; ret->LocalRouting = tmp->LocalRouting;
ret->OldIfMetric = tmp->Metric; ret->Metric = tmp->Metric;
ret->Metric = 1; ret->IfMetric = tmp->IfMetric;
ret->PPPConnection = tmp->PPPConnection; ret->PPPConnection = tmp->PPPConnection;
} }
@ -10402,9 +10394,9 @@ void RouteToStr(char *str, UINT str_size, ROUTE_ENTRY *e)
IPToStr(dest_mask, sizeof(dest_mask), &e->DestMask); IPToStr(dest_mask, sizeof(dest_mask), &e->DestMask);
IPToStr(gateway_ip, sizeof(gateway_ip), &e->GatewayIP); IPToStr(gateway_ip, sizeof(gateway_ip), &e->GatewayIP);
Format(str, str_size, "%s/%s %s m=%u oif=%u if=%u lo=%u p=%u", Format(str, str_size, "%s/%s %s m=%u ifm=%u if=%u lo=%u p=%u",
dest_ip, dest_mask, gateway_ip, dest_ip, dest_mask, gateway_ip,
e->Metric, e->OldIfMetric, e->InterfaceID, e->Metric, e->IfMetric, e->InterfaceID,
e->LocalRouting, e->PPPConnection); e->LocalRouting, e->PPPConnection);
} }

View File

@ -285,7 +285,7 @@ struct ROUTE_ENTRY
bool LocalRouting; bool LocalRouting;
bool PPPConnection; bool PPPConnection;
UINT Metric; UINT Metric;
UINT OldIfMetric; UINT IfMetric;
UINT InterfaceID; UINT InterfaceID;
UINT64 InnerScore; UINT64 InnerScore;
}; };