Skip to content

Commit eb80809

Browse files
rcmcdonald91gmshake
authored andcommitted
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 2a78083)
1 parent 00d474e commit eb80809

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

sbin/route/route_netlink.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -271,22 +271,27 @@ rtmsg_nl_int(struct nl_helper *h, int cmd, int rtm_flags, int fib, int rtm_addrs
271271

272272
hdr = snl_read_reply(ss, hdr->nlmsg_seq);
273273
if (nl_type == NL_RTM_GETROUTE) {
274-
if (hdr->nlmsg_type == NL_RTM_NEWROUTE)
274+
if (hdr->nlmsg_type == NL_RTM_NEWROUTE) {
275275
print_getmsg(h, hdr, dst);
276-
else {
277-
snl_parse_errmsg(ss, hdr, &e);
278-
if (e.error == ESRCH)
279-
warn("route has not been found");
280-
else
281-
warn("message indicates error %d", e.error);
276+
return (0);
282277
}
283-
284-
return (0);
285278
}
286279

287-
if (snl_parse_errmsg(ss, hdr, &e))
280+
if (snl_parse_errmsg(ss, hdr, &e)) {
281+
switch (e.error) {
282+
case (ESRCH):
283+
warnx("route has not been found");
284+
break;
285+
default:
286+
if (e.error == 0)
287+
break;
288+
warnc(e.error, "message indicates error");
289+
}
290+
288291
return (e.error);
292+
}
289293
}
294+
290295
return (EINVAL);
291296
}
292297

0 commit comments

Comments
 (0)