From: David Ahern Date: Sat, 29 Sep 2018 15:46:31 +0000 (-0700) Subject: libnetlink: Convert GETROUTE dumps to use rtnl_routedump_req X-Git-Tag: v5.0.0~138^2~9 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=bfb27dfaac37098659f83cc1d7c7b9e3d5a12814;p=mirror_iproute2.git libnetlink: Convert GETROUTE dumps to use rtnl_routedump_req Add rtnl_routedump_req for route dumps using the proper rtmsg as the header. Convert existing RTM_GETROUTE dumps to use it. Signed-off-by: David Ahern --- diff --git a/include/libnetlink.h b/include/libnetlink.h index 2d9f6190..a60af316 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -49,6 +49,8 @@ void rtnl_close(struct rtnl_handle *rth); int rtnl_addrdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); +int rtnl_routedump_req(struct rtnl_handle *rth, int family) + __attribute__((warn_unused_result)); int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) __attribute__((warn_unused_result)); diff --git a/ip/ipmroute.c b/ip/ipmroute.c index bc23cfea..c5dfa9cb 100644 --- a/ip/ipmroute.c +++ b/ip/ipmroute.c @@ -283,7 +283,7 @@ static int mroute_list(int argc, char **argv) filter.iif = idx; } - if (rtnl_wilddump_request(&rth, filter.af, RTM_GETROUTE) < 0) { + if (rtnl_routedump_req(&rth, filter.af) < 0) { perror("Cannot send dump request"); return 1; } diff --git a/ip/iproute.c b/ip/iproute.c index 398322fd..69963592 100644 --- a/ip/iproute.c +++ b/ip/iproute.c @@ -1645,7 +1645,7 @@ static int iproute_flush(int do_ipv6, rtnl_filter_t filter_fn) filter.flushe = sizeof(flushb); for (;;) { - if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) { + if (rtnl_routedump_req(&rth, do_ipv6) < 0) { perror("Cannot send dump request"); return -2; } @@ -1891,7 +1891,7 @@ static int iproute_list_flush_or_save(int argc, char **argv, int action) return iproute_flush(do_ipv6, filter_fn); if (!filter.cloned) { - if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) { + if (rtnl_routedump_req(&rth, do_ipv6) < 0) { perror("Cannot send dump request"); return -2; } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 749cf4fb..fda5309c 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -215,6 +215,22 @@ int rtnl_addrdump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } +int rtnl_routedump_req(struct rtnl_handle *rth, int family) +{ + struct { + struct nlmsghdr nlh; + struct rtmsg rtm; + } req = { + .nlh.nlmsg_len = sizeof(req), + .nlh.nlmsg_type = RTM_GETROUTE, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .rtm.rtm_family = family, + }; + + return send(rth->fd, &req, sizeof(req), 0); +} + int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) { return rtnl_wilddump_req_filter(rth, family, type, RTEXT_FILTER_VF);