route(8): Add metric argument

Add support for metric in route command.

Differential Revision: https://reviews.freebsd.org/D56335
This commit is contained in:
Pouria Mousavizadeh Tehrani
2026-05-03 00:52:17 +03:30
parent f15b8a8f1d
commit 2e2d402d06
3 changed files with 7 additions and 0 deletions
+1
View File
@@ -50,6 +50,7 @@ ssthresh
static
sticky
weight
metric
x25
xns
xresolve
+4
View File
@@ -813,6 +813,7 @@ set_metric(char *value, int key)
caseof(K_RTT, RTV_RTT, rmx_rtt);
caseof(K_RTTVAR, RTV_RTTVAR, rmx_rttvar);
caseof(K_WEIGHT, RTV_WEIGHT, rmx_weight);
caseof(K_METRIC, RTV_METRIC, rmx_metric);
}
rtm_inits |= flag;
if (lockrest || locking)
@@ -823,6 +824,8 @@ set_metric(char *value, int key)
*valp = strtol(value, &endptr, 0);
if (errno == 0 && *endptr != '\0')
errno = EINVAL;
if (flag & RTV_METRIC && *valp == RT_WILDCARD_METRIC)
err(EX_USAGE, "Metric can not be zero");
if (errno)
err(EX_USAGE, "%s", value);
if (flag & RTV_EXPIRE && (value[0] == '+' || value[0] == '-')) {
@@ -999,6 +1002,7 @@ newroute(int argc, char **argv)
case K_RTT:
case K_RTTVAR:
case K_WEIGHT:
case K_METRIC:
if (!--argc)
usage(NULL);
set_metric(*++argv, key);
+2
View File
@@ -270,6 +270,8 @@ rtmsg_nl_int(struct nl_helper *h, int cmd, int rtm_flags, int fib, int rtm_addrs
if (rt_metrics->rmx_expire > 0)
snl_add_msg_attr_u32(&nw, NL_RTA_EXPIRES, rt_metrics->rmx_expire);
if (rt_metrics->rmx_metric > 0)
snl_add_msg_attr_u32(&nw, NL_RTA_PRIORITY, rt_metrics->rmx_metric);
if (rt_metrics->rmx_weight > 0)
snl_add_msg_attr_u32(&nw, NL_RTA_WEIGHT, rt_metrics->rmx_weight);