git: 2a78083fc2a1 - main - route(8): fix `route not found` exit code and warn with netlink

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Tue, 19 Sep 2023 17:39:36 UTC
The branch main has been updated by kp:

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

commit 2a78083fc2a14af863afb098925b0682698a2838
Author:     R. Christian McDonald <rcm@rcm.sh>
AuthorDate: 2023-09-19 16:46:49 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2023-09-19 17:34:02 +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>.
    
    Reviewed by:    kp
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D41882
---
 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 0dbd90151e10..cad1c8030535 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);
 }