git: dd235f097af4 - main - route(8): Add prefsrc option in netlink

Pouria Mousavizadeh Tehrani <[email protected]>
Newsgroups gmane.os.freebsd.devel.cvs.src
Message-ID <6a6917c5.1e42d.6373b3b9__48694.276732725$1785272311$gmane$org@gitrepo.freebsd.org>
The branch main has been updated by pouria:

URL: https://cgit.FreeBSD.org/src/commit/?id=dd235f097af48ba5bf4324362b4fae6e14e19dfa

commit dd235f097af48ba5bf4324362b4fae6e14e19dfa
Author:     Pouria Mousavizadeh Tehrani <[email protected]>
AuthorDate: 2026-07-17 12:06:46 +0000
Commit:     Pouria Mousavizadeh Tehrani <[email protected]>
CommitDate: 2026-07-28 20:54:37 +0000

    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
---
 sbin/route/keywords        | 1 +
 sbin/route/route.c         | 1 +
 sbin/route/route_netlink.c | 2 ++
 3 files changed, 4 insertions(+)

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;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.