aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPouria Mousavizadeh Tehrani <pouria@FreeBSD.org>2026-07-17 12:06:46 +0000
committerPouria Mousavizadeh Tehrani <pouria@FreeBSD.org>2026-07-28 20:54:37 +0000
commitdd235f097af48ba5bf4324362b4fae6e14e19dfa (patch)
tree7db222a6ea3bd8611e1f0a78f2d3a17ddc4ecce3
parentbe5994cdfbe2fab4c038a534fbff27e49bbb7a7b (diff)
route(8): Add prefsrc option in netlink
Add prefsrc option that is frequently used on unnumbered interfaces or L3 multi-homed network hosts. This option uses RTA_PREFSRC. Now you can add a static route by specifying the prefsrc option with the loopback IP. PR: 285422 Reviewed by: glebius Differential Revision: https://reviews.freebsd.org/D58294
-rw-r--r--sbin/route/keywords1
-rw-r--r--sbin/route/route.c1
-rw-r--r--sbin/route/route_netlink.c2
3 files changed, 4 insertions, 0 deletions
diff --git a/sbin/route/keywords b/sbin/route/keywords
index 3dbfcd187773..faf30f8adb14 100644
--- a/sbin/route/keywords
+++ b/sbin/route/keywords
@@ -36,6 +36,7 @@ nostatic
nostick
osi
prefixlen
+prefsrc
proto1
proto2
proxy
diff --git a/sbin/route/route.c b/sbin/route/route.c
index 84c520bd4f39..e4f15aab91b6 100644
--- a/sbin/route/route.c
+++ b/sbin/route/route.c
@@ -946,6 +946,7 @@ newroute(int argc, char **argv)
errx(EX_USAGE,
"invalid fib number: %s", *argv);
break;
+ case K_PREFSRC:
case K_IFA:
if (!--argc)
usage(NULL);
diff --git a/sbin/route/route_netlink.c b/sbin/route/route_netlink.c
index 0d4420767082..a412265b6feb 100644
--- a/sbin/route/route_netlink.c
+++ b/sbin/route/route_netlink.c
@@ -174,6 +174,7 @@ rtmsg_nl_int(struct nl_helper *h, int cmd, int rtm_flags, int fib, int rtm_addrs
struct sockaddr *dst = get_addr(so, rtm_addrs, RTAX_DST);
struct sockaddr *mask = get_addr(so, rtm_addrs, RTAX_NETMASK);
struct sockaddr *gw = get_addr(so, rtm_addrs, RTAX_GATEWAY);
+ struct sockaddr *prefsrc = get_addr(so, rtm_addrs, RTAX_IFA);
if (dst == NULL)
return (EINVAL);
@@ -225,6 +226,7 @@ rtmsg_nl_int(struct nl_helper *h, int cmd, int rtm_flags, int fib, int rtm_addrs
rtm->rtm_flags = RTM_F_PREFIX;
snl_add_msg_attr_ip(&nw, RTA_DST, dst);
+ snl_add_msg_attr_ip(&nw, RTA_PREFSRC, prefsrc);
snl_add_msg_attr_u32(&nw, RTA_TABLE, fib);
uint32_t rta_oif = 0;