aboutsummaryrefslogtreecommitdiff
path: root/sbin/route/route_netlink.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/route/route_netlink.c')
-rw-r--r--sbin/route/route_netlink.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/sbin/route/route_netlink.c b/sbin/route/route_netlink.c
index 0dbd90151e10..ba22a2ec1e22 100644
--- a/sbin/route/route_netlink.c
+++ b/sbin/route/route_netlink.c
@@ -266,27 +266,32 @@ rtmsg_nl_int(struct nl_helper *h, int cmd, int rtm_flags, int fib, int rtm_addrs
if (rt_metrics->rmx_weight > 0)
snl_add_msg_attr_u32(&nw, NL_RTA_WEIGHT, rt_metrics->rmx_weight);
- if (snl_finalize_msg(&nw) && snl_send_message(ss, hdr)) {
+ if ((hdr = snl_finalize_msg(&nw)) && snl_send_message(ss, hdr)) {
struct snl_errmsg_data e = {};
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);
}
@@ -314,7 +319,7 @@ get_ifdata(struct nl_helper *h, uint32_t ifindex, struct snl_parsed_link_simple
struct ifinfomsg *ifmsg = snl_reserve_msg_object(&nw, struct ifinfomsg);
if (ifmsg != NULL)
ifmsg->ifi_index = ifindex;
- if (!snl_finalize_msg(&nw) || !snl_send_message(ss, hdr))
+ if (! (hdr = snl_finalize_msg(&nw)) || !snl_send_message(ss, hdr))
return;
hdr = snl_read_reply(ss, hdr->nlmsg_seq);
@@ -584,7 +589,7 @@ print_nlmsg_link(struct nl_helper *h, struct nlmsghdr *hdr,
printf("iface#%u %s ", l.ifi_index, l.ifla_ifname);
printf("admin %s ", (l.ifi_flags & IFF_UP) ? "UP" : "DOWN");
- if (l.ifla_operstate < NL_ARRAY_LEN(operstate))
+ if (l.ifla_operstate < nitems(operstate))
printf("oper %s ", operstate[l.ifla_operstate]);
if (l.ifla_mtu > 0)
printf("mtu %u ", l.ifla_mtu);
@@ -663,7 +668,7 @@ print_nlmsg_neigh(struct nl_helper *h, struct nlmsghdr *hdr,
struct snl_parsed_link_simple link = {};
get_ifdata(h, attrs.nda_ifindex, &link);
- for (unsigned int i = 0; i < NL_ARRAY_LEN(nudstate); i++) {
+ for (unsigned int i = 0; i < nitems(nudstate); i++) {
if ((1 << i) & attrs.ndm_state) {
printf("state %s ", nudstate[i]);
break;
@@ -733,6 +738,7 @@ print_nlmsg(struct nl_helper *h, struct nlmsghdr *hdr, struct snl_msg_info *cinf
print_nlmsg_generic(h, hdr, cinfo);
}
+ fflush(stdout);
snl_clear_lb(&h->ss_cmd);
}
@@ -763,7 +769,7 @@ monitor_nl(int fib)
socklen_t optlen = sizeof(optval);
setsockopt(ss_event.fd, SOL_NETLINK, NETLINK_MSG_INFO, &optval, optlen);
- for (unsigned int i = 0; i < NL_ARRAY_LEN(groups); i++) {
+ for (unsigned int i = 0; i < nitems(groups); i++) {
int error;
int optval = groups[i];
socklen_t optlen = sizeof(optval);
@@ -817,7 +823,7 @@ flushroute_one(struct nl_helper *h, struct snl_parsed_route *r)
snl_add_msg_attr_u32(&nw, RTA_TABLE, r->rta_table);
snl_add_msg_attr_ip(&nw, RTA_DST, r->rta_dst);
- if (!snl_finalize_msg(&nw) || !snl_send_message(ss, hdr))
+ if (! (hdr = snl_finalize_msg(&nw)) || !snl_send_message(ss, hdr))
return (ENOMEM);
if (!snl_read_reply_code(ss, hdr->nlmsg_seq, &e)) {
@@ -864,7 +870,7 @@ flushroutes_fib_nl(int fib, int af)
rtm->rtm_family = af;
snl_add_msg_attr_u32(&nw, RTA_TABLE, fib);
- if (!snl_finalize_msg(&nw) || !snl_send_message(&ss, hdr)) {
+ if (! (hdr = snl_finalize_msg(&nw)) || !snl_send_message(&ss, hdr)) {
snl_free(&ss);
return (EINVAL);
}