diff options
| author | Pouria Mousavizadeh Tehrani <pouria@FreeBSD.org> | 2026-05-02 21:22:17 +0000 |
|---|---|---|
| committer | Pouria Mousavizadeh Tehrani <pouria@FreeBSD.org> | 2026-05-20 20:55:08 +0000 |
| commit | 2e2d402d061dc0d091308c477ab800b3eda007ad (patch) | |
| tree | 9ef9af376c49773b736a2e95fb949c488e8e2559 | |
| parent | f15b8a8f1de1c1d879afe9296eb3d998c64469c6 (diff) | |
route(8): Add metric argument
Add support for metric in route command.
Differential Revision: https://reviews.freebsd.org/D56335
| -rw-r--r-- | sbin/route/keywords | 1 | ||||
| -rw-r--r-- | sbin/route/route.c | 4 | ||||
| -rw-r--r-- | sbin/route/route_netlink.c | 2 |
3 files changed, 7 insertions, 0 deletions
diff --git a/sbin/route/keywords b/sbin/route/keywords index cbd8799ffb6b..3dbfcd187773 100644 --- a/sbin/route/keywords +++ b/sbin/route/keywords @@ -50,6 +50,7 @@ ssthresh static sticky weight +metric x25 xns xresolve diff --git a/sbin/route/route.c b/sbin/route/route.c index f0d9515f9892..84c520bd4f39 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -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); diff --git a/sbin/route/route_netlink.c b/sbin/route/route_netlink.c index 20c82c25f5cf..051662688047 100644 --- a/sbin/route/route_netlink.c +++ b/sbin/route/route_netlink.c @@ -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); |
