From 9b3077d955a735da7bf7501010a30067fd2d9904 Mon Sep 17 00:00:00 2001 From: domosekai <54519668+domosekai@users.noreply.github.com> Date: Thu, 29 Jul 2021 22:24:26 +0800 Subject: [PATCH] Store interface metric separately as it mau change --- src/Cedar/VLanWin32.c | 7 ------- src/Mayaqua/Network.c | 26 +++++++++----------------- src/Mayaqua/Network.h | 2 +- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/src/Cedar/VLanWin32.c b/src/Cedar/VLanWin32.c index 03b80e61..592fd595 100644 --- a/src/Cedar/VLanWin32.c +++ b/src/Cedar/VLanWin32.c @@ -162,7 +162,6 @@ void RouteTrackingMain(SESSION *s) char ip_str2[64]; Copy(&e->DestIP, &nat_t_ip, sizeof(IP)); - e->Metric = e->OldIfMetric; IPToStr(ip_str, sizeof(ip_str), &e->DestIP); IPToStr(ip_str2, sizeof(ip_str2), &e->GatewayIP); @@ -507,8 +506,6 @@ void RouteTrackingStart(SESSION *s) Debug("GetBestRouteEntry() Succeed. [Gateway: %s]\n", tmp); // Add a route - e->Metric = e->OldIfMetric; - if (AddRouteEntryEx(e, &already_exists) == false) { FreeRouteEntry(e); @@ -570,8 +567,6 @@ void RouteTrackingStart(SESSION *s) else { // Add a route - dns->Metric = dns->OldIfMetric; - if (AddRouteEntry(dns) == false) { FreeRouteEntry(dns); @@ -590,8 +585,6 @@ void RouteTrackingStart(SESSION *s) 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) { FreeRouteEntry(route_to_real_server_global); diff --git a/src/Mayaqua/Network.c b/src/Mayaqua/Network.c index d75ca04b..772c5a18 100644 --- a/src/Mayaqua/Network.c +++ b/src/Mayaqua/Network.c @@ -9437,9 +9437,6 @@ void Win32RouteEntryToIpForwardRow2(void *ip_forward_row, ROUTE_ENTRY *entry) r = (MIB_IPFORWARD_ROW2 *)ip_forward_row; InitializeIpForwardEntry(r); - MIB_IPINTERFACE_ROW *p; - p = ZeroMallocFast(sizeof(MIB_IPINTERFACE_ROW)); - if (IsIP4(&entry->DestIP)) { // IP address @@ -9450,8 +9447,6 @@ void Win32RouteEntryToIpForwardRow2(void *ip_forward_row, ROUTE_ENTRY *entry) // Gateway IP address r->NextHop.Ipv4.sin_family = AF_INET; IPToInAddr(&r->NextHop.Ipv4.sin_addr, &entry->GatewayIP); - // Interface - p->Family = AF_INET; } else { @@ -9463,21 +9458,17 @@ void Win32RouteEntryToIpForwardRow2(void *ip_forward_row, ROUTE_ENTRY *entry) // Gateway IP address r->NextHop.Ipv6.sin6_family = AF_INET6; IPToInAddr6(&r->NextHop.Ipv6.sin6_addr, &entry->GatewayIP); - // Interface - p->Family = AF_INET6; } - // Metric - p->InterfaceIndex = entry->InterfaceID; - if (GetIpInterfaceEntry(p) == NO_ERROR && entry->Metric >= p->Metric) + // Metric offset + if (entry->Metric >= entry->IfMetric) { - r->Metric = entry->Metric - p->Metric; + r->Metric = entry->Metric - entry->IfMetric; } else { - r->Metric = entry->Metric; + r->Metric = 0; } - Free(p); // Interface ID r->InterfaceIndex = entry->InterfaceID; @@ -9544,6 +9535,7 @@ void Win32IpForwardRow2ToRouteEntry(ROUTE_ENTRY *entry, void *ip_forward_row) p->InterfaceIndex = r->InterfaceIndex; if (GetIpInterfaceEntry(p) == NO_ERROR) { + entry->IfMetric = p->Metric; entry->Metric = r->Metric + p->Metric; } else @@ -10243,8 +10235,8 @@ ROUTE_ENTRY *GetBestRouteEntryFromRouteTableEx(ROUTE_TABLE *table, IP *ip, UINT Copy(&ret->GatewayIP, &tmp->GatewayIP, sizeof(IP)); ret->InterfaceID = tmp->InterfaceID; ret->LocalRouting = tmp->LocalRouting; - ret->OldIfMetric = tmp->Metric; - ret->Metric = 1; + ret->Metric = tmp->Metric; + ret->IfMetric = tmp->IfMetric; 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(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, - e->Metric, e->OldIfMetric, e->InterfaceID, + e->Metric, e->IfMetric, e->InterfaceID, e->LocalRouting, e->PPPConnection); } diff --git a/src/Mayaqua/Network.h b/src/Mayaqua/Network.h index f227cadd..bf58dceb 100644 --- a/src/Mayaqua/Network.h +++ b/src/Mayaqua/Network.h @@ -285,7 +285,7 @@ struct ROUTE_ENTRY bool LocalRouting; bool PPPConnection; UINT Metric; - UINT OldIfMetric; + UINT IfMetric; UINT InterfaceID; UINT64 InnerScore; };