From: Erik Conijn Date: Sun, 10 May 2026 09:01:10 +0000 (+0200) Subject: wireguard: add metric to routes X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=67ee9cf19dd6dc4e4d846da2ac97afaf745103da;p=thirdparty%2Fopenwrt.git wireguard: add metric to routes maintainer: Felix Fietkau The metric field is not used when wireGuard routes are created. See: https://github.com/openwrt/openwrt/issues/23199 This patch is aimed at adding the metric field in the config to the created routes for WireGuard if the metric field is not empty and not 0 Compile tested: X86, Openwrt-main Run tested: X86 Please have a look and consider implementing Signed-off-by: Erik Conijn Link: https://github.com/openwrt/openwrt/pull/23280 Signed-off-by: Robert Marko --- diff --git a/package/network/utils/wireguard-tools/files/wireguard.uc b/package/network/utils/wireguard-tools/files/wireguard.uc index 9f99904812f..2f3c69049e9 100644 --- a/package/network/utils/wireguard-tools/files/wireguard.uc +++ b/package/network/utils/wireguard-tools/files/wireguard.uc @@ -111,6 +111,8 @@ function proto_setup(proto) { if (config.fwmark) wg_config += sprintf('FwMark=%s\n', config.fwmark); + let metric = int(config.metric); + let ipv4_routes = []; let ipv6_routes = []; @@ -136,6 +138,8 @@ function proto_setup(proto) { for (let allowed_ip in allowed_list) { let addr_info = parse_address(allowed_ip); let route = { target: addr_info.address, netmask: '' + addr_info.mask }; + if (metric) + route.metric = metric; if (addr_info.family == 6) push(ipv6_routes, route); else