git: eb808098834b - stable/14 - route(8): fix `route not found` exit code and warn with netlink

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Mon, 01 Sep 2025 14:16:11 UTC
The branch stable/14 has been updated by zlei:

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

commit eb808098834bc0997fcbe7ca9d7ff12663eff9d0
Author:     R. Christian McDonald <rcm@rcm.sh>
AuthorDate: 2023-09-19 16:46:49 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2025-09-01 14:14:43 +0000

    route(8): fix `route not found` exit code and warn with netlink
    
    Fix route(8) incorrectly returning a zero exit code even when unable to
    find the specified route with route -n get <route>.
    
    PR:             274426
    Reviewed by:    kp
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D41882
    
    (cherry picked from commit 2a78083fc2a14af863afb098925b0682698a2838)
---
 sbin/route/route_netlink.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/sbin/route/route_netlink.c b/sbin/route/route_netlink.c
index 2870d256aadd..610918f51f30 100644
--- a/sbin/route/route_netlink.c
+++ b/sbin/route/route_netlink.c
@@ -271,22 +271,27 @@ rtmsg_nl_int(struct nl_helper *h, int cmd, int rtm_flags, int fib, int rtm_addrs
 
 		hdr = snl_read_reply(ss, hdr->nlmsg_seq);
 		if (nl_type == NL_RTM_GETROUTE) {
-			if (hdr->nlmsg_type == NL_RTM_NEWROUTE)
+			if (hdr->nlmsg_type == NL_RTM_NEWROUTE) {
 				print_getmsg(h, hdr, dst);
-			else {
-				snl_parse_errmsg(ss, hdr, &e);
-				if (e.error == ESRCH)
-					warn("route has not been found");
-				else
-					warn("message indicates error %d", e.error);
+				return (0);
 			}
-
-			return (0);
 		}
 
-		if (snl_parse_errmsg(ss, hdr, &e))
+		if (snl_parse_errmsg(ss, hdr, &e)) {
+			switch (e.error) {
+			case (ESRCH):
+				warnx("route has not been found");
+				break;
+			default:
+				if (e.error == 0)
+					break;
+				warnc(e.error, "message indicates error");
+			}
+
 			return (e.error);
+		}
 	}
+
 	return (EINVAL);
 }