[Openvpn-devel] metric: Enable support for route metric on FreeBSD

Message ID 20260805103633.91569-1-pouria@FreeBSD.org
State New
Headers
Series [Openvpn-devel] metric: Enable support for route metric on FreeBSD |

Commit Message

Pouria Mousavizadeh Tehrani Aug. 5, 2026, 10:36 a.m. UTC
  The route metric has been available since FreeBSD version 1600019.

Signed-off-by: Pouria Mousavizadeh Tehrani <pouria@FreeBSD.org>
---
 src/openvpn/route.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
  

Comments

Gert Doering Aug. 5, 2026, 12:46 p.m. UTC | #1
Hi,

On Wed, Aug 05, 2026 at 02:06:33PM +0330, Pouria Mousavizadeh Tehrani wrote:
> The route metric has been available since FreeBSD version 1600019.

Is there some documentation what this does?  As in, can you now install
two routes for the same prefix, with different metrics, and the one
with the "lowest metric wins"?

gert
  
Pouria Mousavizadeh Tehrani Aug. 5, 2026, 2:15 p.m. UTC | #2
Hi

On 8/5/26 16:16, Gert Doering wrote:
> Hi,
> 
> On Wed, Aug 05, 2026 at 02:06:33PM +0330, Pouria Mousavizadeh Tehrani wrote:
>> The route metric has been available since FreeBSD version 1600019.
> 
> Is there some documentation what this does?  As in, can you now install
> two routes for the same prefix, with different metrics, and the one
> with the "lowest metric wins"?

Yes, the route(8) manual is updated.
https://man.freebsd.org/cgi/man.cgi?query=route&sektion=8&manpath=freebsd-current

To answer your question:
```
% mdo route -n4 add -net 172.31.0.0/16 -gateway 192.168.1.1 -metric 10
add net 172.31.0.0: gateway 192.168.1.1
% mdo route -n4 add -net 172.31.0.0/16 -gateway 192.168.1.2 -metric 1
add net 172.31.0.0: gateway 192.168.1.2
% netstat -rn4W | grep 172.31.0.0
172.31.0.0/16 192.168.1.1 UGS 0 1500 bridge0 10
172.31.0.0/16 192.168.1.2 UGS 0 1500 bridge0  1
% route -n4 get 172.31.0.0
      route to: 172.31.0.0
   destination: 172.31.0.0
          mask: 255.255.0.0
       gateway: 192.168.1.2
...
```

> 
> gert

-- 
Pouria
  

Patch

diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index 8ea745d1..7b9e106b 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -1640,10 +1640,10 @@  add_route(struct route_ipv4 *r, const struct tuntap *tt, unsigned int flags,
 
     argv_printf(&argv, "%s add", ROUTE_PATH);
 
-#if 0
+#if __FreeBSD_version >= 1600019
     if (r->flags & RT_METRIC_DEFINED)
     {
-        argv_printf_cat(&argv, "-rtt %d", r->metric);
+        argv_printf_cat(&argv, "-metric %d", r->metric);
     }
 #endif
 
@@ -1946,6 +1946,13 @@  add_route_ipv6(struct route_ipv6 *r6, const struct tuntap *tt, unsigned int flag
         argv_printf_cat(&argv, "-iface %s", device);
     }
 
+#if defined(TARGET_FREEBSD) && __FreeBSD_version >= 1600019
+    if (r6->flags & RT_METRIC_DEFINED)
+    {
+        argv_printf_cat(&argv, "-metric %d", r6->metric);
+    }
+#endif
+
     argv_msg(D_ROUTE, &argv);
     bool ret = openvpn_execve_check(&argv, es, 0, "ERROR: *BSD route add -inet6 command failed");
     status = ret ? RTA_SUCCESS : RTA_ERROR;