[PATCH 1/2] interface-ip: use metric when looking for a route

luizluca at gmail.com luizluca at gmail.com
Mon Nov 22 18:04:51 PST 2021


From: Luiz Angelo Daros de Luca <luizluca at gmail.com>

When there were multiple routes with the same target but different
metrics, __find_ip_route_target was returning the first one,
independently of the metric.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca at gmail.com>
---
 interface-ip.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/interface-ip.c b/interface-ip.c
index 648f521..7b63ef9 100644
--- a/interface-ip.c
+++ b/interface-ip.c
@@ -234,7 +234,9 @@ __find_ip_route_target(struct interface_ip_settings *ip, union if_addr *a,
 		if (route->flags & DEVROUTE_TABLE)
 			continue;
 
-		if (!*res || route->mask > (*res)->mask)
+		if (!*res || route->mask > (*res)->mask ||
+	            ((route->mask == (*res)->mask) && (route->flags & DEVROUTE_METRIC)
+		     && (route->metric < (*res)->metric)))
 			*res = route;
 	}
 }
-- 
2.33.1




More information about the openwrt-devel mailing list