From 46917d0895fb0fb1df9b3c1575ccd467b4a1f860 Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 08:41:46 -0700 Subject: [PATCH 01/11] libnetlink: Convert GETADDR dumps to use rtnl_addrdump_req Add rtnl_addrdump_req for address dumps using the proper ifaddrmsg as the header. Convert existing RTM_GETADDR dumps to use it. Signed-off-by: David Ahern --- include/libnetlink.h | 4 ++++ ip/ipaddress.c | 6 +++--- lib/libnetlink.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/libnetlink.h b/include/libnetlink.h index 9d9249e6..2d9f6190 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -46,6 +46,10 @@ int rtnl_open_byproto(struct rtnl_handle *rth, unsigned int subscriptions, __attribute__((warn_unused_result)); void rtnl_close(struct rtnl_handle *rth); + +int rtnl_addrdump_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)); int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int fam, int type, diff --git a/ip/ipaddress.c b/ip/ipaddress.c index 8dc6c32f..f29480ce 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -1698,7 +1698,7 @@ static int ipaddr_flush(void) filter.flushe = sizeof(flushb); while ((max_flush_loops == 0) || (round < max_flush_loops)) { - if (rtnl_wilddump_request(&rth, filter.family, RTM_GETADDR) < 0) { + if (rtnl_addrdump_req(&rth, filter.family) < 0) { perror("Cannot send dump request"); exit(1); } @@ -1790,7 +1790,7 @@ int ip_linkaddr_list(int family, req_filter_fn_t filter_fn, } if (ainfo) { - if (rtnl_wilddump_request(&rth, family, RTM_GETADDR) < 0) { + if (rtnl_addrdump_req(&rth, family) < 0) { perror("Cannot send dump request"); return 1; } @@ -1915,7 +1915,7 @@ static int ipaddr_list_flush_or_save(int argc, char **argv, int action) if (ipadd_save_prep()) exit(1); - if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETADDR) < 0) { + if (rtnl_addrdump_req(&rth, preferred_family) < 0) { perror("Cannot send dump request"); exit(1); } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index f18dceac..749cf4fb 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -199,6 +199,22 @@ int rtnl_open(struct rtnl_handle *rth, unsigned int subscriptions) return rtnl_open_byproto(rth, subscriptions, NETLINK_ROUTE); } +int rtnl_addrdump_req(struct rtnl_handle *rth, int family) +{ + struct { + struct nlmsghdr nlh; + struct ifaddrmsg ifm; + } req = { + .nlh.nlmsg_len = sizeof(req), + .nlh.nlmsg_type = RTM_GETADDR, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ifm.ifa_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); From bfb27dfaac37098659f83cc1d7c7b9e3d5a12814 Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 08:46:31 -0700 Subject: [PATCH 02/11] 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 --- include/libnetlink.h | 2 ++ ip/ipmroute.c | 2 +- ip/iproute.c | 4 ++-- lib/libnetlink.c | 16 ++++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) 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); From 393600231aac32a4e05a4c4c25b0d5b3d0acd17c Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 10:43:15 -0700 Subject: [PATCH 03/11] libnetlink: Convert GETADDRLABEL dumps to use rtnl_addrlbldump_req Add rtnl_addrlbldump_req for address label dumps using the proper ifaddrlblmsg as the header. Convert existing RTM_GETADDRALBEL dumps to use it. Signed-off-by: David Ahern --- include/libnetlink.h | 2 ++ ip/ipaddrlabel.c | 4 ++-- lib/libnetlink.c | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/libnetlink.h b/include/libnetlink.h index a60af316..bacaec82 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_addrlbldump_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)); diff --git a/ip/ipaddrlabel.c b/ip/ipaddrlabel.c index 2f79c56d..845fe4c5 100644 --- a/ip/ipaddrlabel.c +++ b/ip/ipaddrlabel.c @@ -118,7 +118,7 @@ static int ipaddrlabel_list(int argc, char **argv) return -1; } - if (rtnl_wilddump_request(&rth, af, RTM_GETADDRLABEL) < 0) { + if (rtnl_addrlbldump_req(&rth, af) < 0) { perror("Cannot send dump request"); return 1; } @@ -237,7 +237,7 @@ static int ipaddrlabel_flush(int argc, char **argv) return -1; } - if (rtnl_wilddump_request(&rth, af, RTM_GETADDRLABEL) < 0) { + if (rtnl_addrlbldump_req(&rth, af) < 0) { perror("Cannot send dump request"); return -1; } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index fda5309c..fb5f1714 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "libnetlink.h" @@ -215,6 +216,22 @@ int rtnl_addrdump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } +int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family) +{ + struct { + struct nlmsghdr nlh; + struct ifaddrlblmsg ifal; + } req = { + .nlh.nlmsg_len = sizeof(req), + .nlh.nlmsg_type = RTM_GETADDRLABEL, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ifal.ifal_family = family, + }; + + return send(rth->fd, &req, sizeof(req), 0); +} + int rtnl_routedump_req(struct rtnl_handle *rth, int family) { struct { From 9dbe6df411e58bbbd17f13e17a80fc3adb912318 Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 10:44:18 -0700 Subject: [PATCH 04/11] libnetlink: Convert GETMDB dumps to use rtnl_mdbdump_req Add rtnl_mdbdump_req for mdb dumps using the proper br_port_msg as the header. Convert existing RTM_GETMDB dumps to use it. Signed-off-by: David Ahern --- bridge/mdb.c | 2 +- include/libnetlink.h | 2 ++ lib/libnetlink.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bridge/mdb.c b/bridge/mdb.c index 841a3612..03fcc91f 100644 --- a/bridge/mdb.c +++ b/bridge/mdb.c @@ -293,7 +293,7 @@ static int mdb_show(int argc, char **argv) new_json_obj(json); /* get mdb entries*/ - if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETMDB) < 0) { + if (rtnl_mdbdump_req(&rth, PF_BRIDGE) < 0) { perror("Cannot send dump request"); return -1; } diff --git a/include/libnetlink.h b/include/libnetlink.h index bacaec82..8f2b2935 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -53,6 +53,8 @@ int rtnl_addrlbldump_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_mdbdump_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/lib/libnetlink.c b/lib/libnetlink.c index fb5f1714..51ea457c 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "libnetlink.h" @@ -248,6 +249,22 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } +int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) +{ + struct { + struct nlmsghdr nlh; + struct br_port_msg bpm; + } req = { + .nlh.nlmsg_len = sizeof(req), + .nlh.nlmsg_type = RTM_GETMDB, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .bpm.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); From ddee16bc966c2e021e2584bf3102e003a9ad093b Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 09:29:29 -0700 Subject: [PATCH 05/11] libnetlink: Convert GETNETCONF dumps to use rtnl_netconfdump_req Add rtnl_netconfdump_req for netconf dumps using the proper netconfmsg as the header. Convert existing RTM_GETNETCONF dumps to use it. Signed-off-by: David Ahern --- include/libnetlink.h | 2 ++ ip/ipnetconf.c | 3 +-- lib/libnetlink.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/libnetlink.h b/include/libnetlink.h index 8f2b2935..7e9ef640 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -55,6 +55,8 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); +int rtnl_netconfdump_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/ipnetconf.c b/ip/ipnetconf.c index 04c4d608..21822e36 100644 --- a/ip/ipnetconf.c +++ b/ip/ipnetconf.c @@ -210,8 +210,7 @@ static int do_show(int argc, char **argv) } else { rth.flags = RTNL_HANDLE_F_SUPPRESS_NLERR; dump: - if (rtnl_wilddump_request(&rth, filter.family, - RTM_GETNETCONF) < 0) { + if (rtnl_netconfdump_req(&rth, filter.family) < 0) { perror("Cannot send dump request"); exit(1); } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 51ea457c..e5cb275f 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -265,6 +265,22 @@ int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } +int rtnl_netconfdump_req(struct rtnl_handle *rth, int family) +{ + struct { + struct nlmsghdr nlh; + struct netconfmsg ncm; + } req = { + .nlh.nlmsg_len = sizeof(req), + .nlh.nlmsg_type = RTM_GETNETCONF, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ncm.ncm_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); From b05d9a3d5866219b3c772256dc215bb04e65baa5 Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 09:34:57 -0700 Subject: [PATCH 06/11] libnetlink: Convert GETRULE dumps to use rtnl_ruledump_req Add rtnl_ruledump_req for fib fule dumps using the proper fib_rule_hdr as the header. Convert existing RTM_GETRULE dumps to use it. Signed-off-by: David Ahern --- include/libnetlink.h | 2 ++ ip/iprule.c | 2 +- lib/libnetlink.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/libnetlink.h b/include/libnetlink.h index 7e9ef640..5f6bbe55 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -53,6 +53,8 @@ int rtnl_addrlbldump_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_ruledump_req(struct rtnl_handle *rth, int family) + __attribute__((warn_unused_result)); int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); int rtnl_netconfdump_req(struct rtnl_handle *rth, int family) diff --git a/ip/iprule.c b/ip/iprule.c index 744d6d88..60fd4c7e 100644 --- a/ip/iprule.c +++ b/ip/iprule.c @@ -615,7 +615,7 @@ static int iprule_list_flush_or_save(int argc, char **argv, int action) argc--; argv++; } - if (rtnl_wilddump_request(&rth, af, RTM_GETRULE) < 0) { + if (rtnl_ruledump_req(&rth, af) < 0) { perror("Cannot send dump request"); return 1; } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index e5cb275f..89e4d6a2 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -249,6 +250,22 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } +int rtnl_ruledump_req(struct rtnl_handle *rth, int family) +{ + struct { + struct nlmsghdr nlh; + struct fib_rule_hdr frh; + } req = { + .nlh.nlmsg_len = sizeof(req), + .nlh.nlmsg_type = RTM_GETRULE, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .frh.family = family + }; + + return send(rth->fd, &req, sizeof(req), 0); +} + int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) { struct { From 9e0ab19c4d80cb4270fbc0f90634dfbc83b9cdc3 Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 09:42:40 -0700 Subject: [PATCH 07/11] libnetlink: Convert GETNEIGH dumps to use rtnl_neighdump_req Add rtnl_neighdump_req for neighbor dumps using the proper ndmsg as the header. Convert existing rtnl_wilddump_request for RTM_GETNEIGH to use it. Signed-off-by: David Ahern --- include/libnetlink.h | 2 ++ lib/libnetlink.c | 16 ++++++++++++++++ misc/arpd.c | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/libnetlink.h b/include/libnetlink.h index 5f6bbe55..e22ccbb8 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -55,6 +55,8 @@ int rtnl_routedump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); int rtnl_ruledump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); +int rtnl_neighdump_req(struct rtnl_handle *rth, int family) + __attribute__((warn_unused_result)); int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); int rtnl_netconfdump_req(struct rtnl_handle *rth, int family) diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 89e4d6a2..fd0f95a2 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -266,6 +266,22 @@ int rtnl_ruledump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } +int rtnl_neighdump_req(struct rtnl_handle *rth, int family) +{ + struct { + struct nlmsghdr nlh; + struct ndmsg ndm; + } req = { + .nlh.nlmsg_len = sizeof(req), + .nlh.nlmsg_type = RTM_GETNEIGH, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ndm.ndm_family = family, + }; + + return send(rth->fd, &req, sizeof(req), 0); +} + int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) { struct { diff --git a/misc/arpd.c b/misc/arpd.c index 67d86b67..ce7c0997 100644 --- a/misc/arpd.c +++ b/misc/arpd.c @@ -424,7 +424,7 @@ static int do_one_request(struct nlmsghdr *n) static void load_initial_table(void) { - if (rtnl_wilddump_request(&rth, AF_INET, RTM_GETNEIGH) < 0) { + if (rtnl_neighdump_req(&rth, AF_INET) < 0) { perror("dump request failed"); exit(1); } From ff41db8a7574876e181654b3bbdb11df92e46bad Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 09:47:41 -0700 Subject: [PATCH 08/11] libnetlink: Convert GETNEIGHTBL dumps to use rtnl_neightbldump_req Add rtnl_neightbldump_req for neighbor table dumps using the proper ndtmsg as the header. Convert existing RTM_GETNEIGHTBL dumps to use it. Signed-off-by: David Ahern --- include/libnetlink.h | 2 ++ ip/ipntable.c | 2 +- lib/libnetlink.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/libnetlink.h b/include/libnetlink.h index e22ccbb8..5ccc421b 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -57,6 +57,8 @@ int rtnl_ruledump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); int rtnl_neighdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); +int rtnl_neightbldump_req(struct rtnl_handle *rth, int family) + __attribute__((warn_unused_result)); int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); int rtnl_netconfdump_req(struct rtnl_handle *rth, int family) diff --git a/ip/ipntable.c b/ip/ipntable.c index dd4f7c2e..ce3f4614 100644 --- a/ip/ipntable.c +++ b/ip/ipntable.c @@ -658,7 +658,7 @@ static int ipntable_show(int argc, char **argv) argc--; argv++; } - if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETNEIGHTBL) < 0) { + if (rtnl_neightbldump_req(&rth, preferred_family) < 0) { perror("Cannot send dump request"); exit(1); } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index fd0f95a2..c28047e4 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -282,6 +282,22 @@ int rtnl_neighdump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } +int rtnl_neightbldump_req(struct rtnl_handle *rth, int family) +{ + struct { + struct nlmsghdr nlh; + struct ndtmsg ndtmsg; + } req = { + .nlh.nlmsg_len = sizeof(req), + .nlh.nlmsg_type = RTM_GETNEIGHTBL, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .ndtmsg.ndtm_family = family, + }; + + return send(rth->fd, &req, sizeof(req), 0); +} + int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) { struct { From efb0b383d98840a9caf8e0f44de18d496251c374 Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 09:51:08 -0700 Subject: [PATCH 09/11] libnetlink: Convert GETNSID dumps to use rtnl_nsiddump_req Add rtnl_nsiddump_req for namespace id dumps using the proper rtgenmsg as the header. Convert existing RTM_GETNSID dumps to use it. Signed-off-by: David Ahern --- include/libnetlink.h | 2 ++ ip/ipnetns.c | 2 +- lib/libnetlink.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/libnetlink.h b/include/libnetlink.h index 5ccc421b..f22c92ac 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -63,6 +63,8 @@ int rtnl_mdbdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); int rtnl_netconfdump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); +int rtnl_nsiddump_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/ipnetns.c b/ip/ipnetns.c index 368be0cb..e8500c77 100644 --- a/ip/ipnetns.c +++ b/ip/ipnetns.c @@ -346,7 +346,7 @@ static int netns_list_id(int argc, char **argv) return -ENOTSUP; } - if (rtnl_wilddump_request(&rth, AF_UNSPEC, RTM_GETNSID) < 0) { + if (rtnl_nsiddump_req(&rth, AF_UNSPEC) < 0) { perror("Cannot send dump request"); exit(1); } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index c28047e4..2dd14ac5 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -330,6 +330,22 @@ int rtnl_netconfdump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } +int rtnl_nsiddump_req(struct rtnl_handle *rth, int family) +{ + struct { + struct nlmsghdr nlh; + struct rtgenmsg rtm; + } req = { + .nlh.nlmsg_len = sizeof(req), + .nlh.nlmsg_type = RTM_GETNSID, + .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, + .nlh.nlmsg_seq = rth->dump = ++rth->seq, + .rtm.rtgen_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); From 31ae2912f71e8ade59856e7533be9819b29d896d Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 09:56:57 -0700 Subject: [PATCH 10/11] libnetlink: Rename rtnl_wilddump_* to rtnl_linkdump_* Rename rtnl_wilddump_req_filter to rtnl_linkdump_req_filter, rtnl_wilddump_request to rtnl_linkdump_req and rtnl_wilddump_req_filter_fn to rtnl_linkdump_req_filter_fn. In all cases drop the type argument which at this point is only RTM_GETLINK and hardcode in the functions. Signed-off-by: David Ahern --- bridge/link.c | 4 ++-- bridge/vlan.c | 2 +- include/libnetlink.h | 7 +++---- ip/ipaddress.c | 4 ++-- ip/iptoken.c | 2 +- ip/iptuntap.c | 2 +- ip/rtmon.c | 2 +- ip/tunnel.c | 2 +- lib/libnetlink.c | 12 ++++++------ lib/ll_map.c | 2 +- misc/ifstat.c | 2 +- 11 files changed, 20 insertions(+), 21 deletions(-) diff --git a/bridge/link.c b/bridge/link.c index 85570263..09df489b 100644 --- a/bridge/link.c +++ b/bridge/link.c @@ -502,7 +502,7 @@ static int brlink_show(int argc, char **argv) } if (show_details) { - if (rtnl_wilddump_req_filter(&rth, PF_BRIDGE, RTM_GETLINK, + if (rtnl_linkdump_req_filter(&rth, PF_BRIDGE, (compress_vlans ? RTEXT_FILTER_BRVLAN_COMPRESSED : RTEXT_FILTER_BRVLAN)) < 0) { @@ -510,7 +510,7 @@ static int brlink_show(int argc, char **argv) exit(1); } } else { - if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETLINK) < 0) { + if (rtnl_linkdump_req(&rth, PF_BRIDGE) < 0) { perror("Cannon send dump request"); exit(1); } diff --git a/bridge/vlan.c b/bridge/vlan.c index bdce55ae..59ed1964 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -575,7 +575,7 @@ static int vlan_show(int argc, char **argv) new_json_obj(json); if (!show_stats) { - if (rtnl_wilddump_req_filter(&rth, PF_BRIDGE, RTM_GETLINK, + if (rtnl_linkdump_req_filter(&rth, PF_BRIDGE, (compress_vlans ? RTEXT_FILTER_BRVLAN_COMPRESSED : RTEXT_FILTER_BRVLAN)) < 0) { diff --git a/include/libnetlink.h b/include/libnetlink.h index f22c92ac..410c441b 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -66,15 +66,14 @@ int rtnl_netconfdump_req(struct rtnl_handle *rth, int family) int rtnl_nsiddump_req(struct rtnl_handle *rth, int family) __attribute__((warn_unused_result)); -int rtnl_wilddump_request(struct rtnl_handle *rth, int fam, int type) +int rtnl_linkdump_req(struct rtnl_handle *rth, int fam) __attribute__((warn_unused_result)); -int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int fam, int type, - __u32 filt_mask) +int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask) __attribute__((warn_unused_result)); typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen); -int rtnl_wilddump_req_filter_fn(struct rtnl_handle *rth, int fam, int type, +int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int fam, req_filter_fn_t fn) __attribute__((warn_unused_result)); int rtnl_wilddump_stats_req_filter(struct rtnl_handle *rth, int fam, int type, diff --git a/ip/ipaddress.c b/ip/ipaddress.c index f29480ce..c0c1fbbe 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -1778,7 +1778,7 @@ static int iplink_filter_req(struct nlmsghdr *nlh, int reqlen) int ip_linkaddr_list(int family, req_filter_fn_t filter_fn, struct nlmsg_chain *linfo, struct nlmsg_chain *ainfo) { - if (rtnl_wilddump_req_filter_fn(&rth, preferred_family, RTM_GETLINK, + if (rtnl_linkdump_req_filter_fn(&rth, preferred_family, filter_fn) < 0) { perror("Cannot send dump request"); return 1; @@ -2031,7 +2031,7 @@ void ipaddr_get_vf_rate(int vfnum, int *min, int *max, const char *dev) exit(1); } - if (rtnl_wilddump_request(&rth, AF_UNSPEC, RTM_GETLINK) < 0) { + if (rtnl_linkdump_req(&rth, AF_UNSPEC) < 0) { perror("Cannot send dump request"); exit(1); } diff --git a/ip/iptoken.c b/ip/iptoken.c index fb64da4e..8605e75c 100644 --- a/ip/iptoken.c +++ b/ip/iptoken.c @@ -109,7 +109,7 @@ static int iptoken_list(int argc, char **argv) argc--; argv++; } - if (rtnl_wilddump_request(&rth, af, RTM_GETLINK) < 0) { + if (rtnl_linkdump_req(&rth, af) < 0) { perror("Cannot send dump request"); return -1; } diff --git a/ip/iptuntap.c b/ip/iptuntap.c index 58996e6c..8c84e620 100644 --- a/ip/iptuntap.c +++ b/ip/iptuntap.c @@ -459,7 +459,7 @@ static int print_tuntap(const struct sockaddr_nl *who, static int do_show(int argc, char **argv) { - if (rtnl_wilddump_req_filter_fn(&rth, AF_UNSPEC, RTM_GETLINK, + if (rtnl_linkdump_req_filter_fn(&rth, AF_UNSPEC, tuntap_filter_req) < 0) { perror("Cannot send dump request\n"); return -1; diff --git a/ip/rtmon.c b/ip/rtmon.c index 0e795f74..7d2405d7 100644 --- a/ip/rtmon.c +++ b/ip/rtmon.c @@ -163,7 +163,7 @@ main(int argc, char **argv) if (rtnl_open(&rth, groups) < 0) exit(1); - if (rtnl_wilddump_request(&rth, AF_UNSPEC, RTM_GETLINK) < 0) { + if (rtnl_linkdump_req(&rth, AF_UNSPEC) < 0) { perror("Cannot send dump request"); exit(1); } diff --git a/ip/tunnel.c b/ip/tunnel.c index 79de7f24..20fe6d7d 100644 --- a/ip/tunnel.c +++ b/ip/tunnel.c @@ -392,7 +392,7 @@ static int print_nlmsg_tunnel(const struct sockaddr_nl *who, int do_tunnels_list(struct tnl_print_nlmsg_info *info) { - if (rtnl_wilddump_request(&rth, preferred_family, RTM_GETLINK) < 0) { + if (rtnl_linkdump_req(&rth, preferred_family) < 0) { perror("Cannot send dump request\n"); return -1; } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 2dd14ac5..73d720f4 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -346,12 +346,12 @@ int rtnl_nsiddump_req(struct rtnl_handle *rth, int family) return send(rth->fd, &req, sizeof(req), 0); } -int rtnl_wilddump_request(struct rtnl_handle *rth, int family, int type) +int rtnl_linkdump_req(struct rtnl_handle *rth, int family) { - return rtnl_wilddump_req_filter(rth, family, type, RTEXT_FILTER_VF); + return rtnl_linkdump_req_filter(rth, family, RTEXT_FILTER_VF); } -int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int family, int type, +int rtnl_linkdump_req_filter(struct rtnl_handle *rth, int family, __u32 filt_mask) { struct { @@ -362,7 +362,7 @@ int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int family, int type, __u32 ext_filter_mask; } req = { .nlh.nlmsg_len = sizeof(req), - .nlh.nlmsg_type = type, + .nlh.nlmsg_type = RTM_GETLINK, .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, .nlh.nlmsg_seq = rth->dump = ++rth->seq, .ifm.ifi_family = family, @@ -374,7 +374,7 @@ int rtnl_wilddump_req_filter(struct rtnl_handle *rth, int family, int type, return send(rth->fd, &req, sizeof(req), 0); } -int rtnl_wilddump_req_filter_fn(struct rtnl_handle *rth, int family, int type, +int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int family, req_filter_fn_t filter_fn) { struct { @@ -383,7 +383,7 @@ int rtnl_wilddump_req_filter_fn(struct rtnl_handle *rth, int family, int type, char buf[1024]; } req = { .nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)), - .nlh.nlmsg_type = type, + .nlh.nlmsg_type = RTM_GETLINK, .nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST, .nlh.nlmsg_seq = rth->dump = ++rth->seq, .ifm.ifi_family = family, diff --git a/lib/ll_map.c b/lib/ll_map.c index 0afe6897..32c8e442 100644 --- a/lib/ll_map.c +++ b/lib/ll_map.c @@ -218,7 +218,7 @@ void ll_init_map(struct rtnl_handle *rth) if (initialized) return; - if (rtnl_wilddump_request(rth, AF_UNSPEC, RTM_GETLINK) < 0) { + if (rtnl_linkdump_req(rth, AF_UNSPEC) < 0) { perror("Cannot send dump request"); exit(1); } diff --git a/misc/ifstat.c b/misc/ifstat.c index 50b906e8..6e70e1eb 100644 --- a/misc/ifstat.c +++ b/misc/ifstat.c @@ -214,7 +214,7 @@ static void load_info(void) exit(1); } } else { - if (rtnl_wilddump_request(&rth, AF_INET, RTM_GETLINK) < 0) { + if (rtnl_linkdump_req(&rth, AF_INET) < 0) { perror("Cannot send dump request"); exit(1); } From 56eeeda9782193ed5abd6b29383b3c746d88a988 Mon Sep 17 00:00:00 2001 From: David Ahern Date: Sat, 29 Sep 2018 10:12:59 -0700 Subject: [PATCH 11/11] libnetlink: Rename rtnl_wilddump_stats_req_filter to rtnl_statsdump_req_filter rtnl_wilddump_stats_req_filter only takes RTM_GETSTATS as the type argument so rename to rtnl_statsdump_req_filter for consistency with other request functions and hardcode the type argument. Signed-off-by: David Ahern --- bridge/vlan.c | 8 ++------ include/libnetlink.h | 3 +-- ip/iplink.c | 4 +--- ip/iplink_xstats.c | 4 +--- lib/libnetlink.c | 5 ++--- misc/ifstat.c | 4 ++-- 6 files changed, 9 insertions(+), 19 deletions(-) diff --git a/bridge/vlan.c b/bridge/vlan.c index 59ed1964..239907bd 100644 --- a/bridge/vlan.c +++ b/bridge/vlan.c @@ -603,9 +603,7 @@ static int vlan_show(int argc, char **argv) __u32 filt_mask; filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS); - if (rtnl_wilddump_stats_req_filter(&rth, AF_UNSPEC, - RTM_GETSTATS, - filt_mask) < 0) { + if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) { perror("Cannont send dump request"); exit(1); } @@ -619,9 +617,7 @@ static int vlan_show(int argc, char **argv) } filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS_SLAVE); - if (rtnl_wilddump_stats_req_filter(&rth, AF_UNSPEC, - RTM_GETSTATS, - filt_mask) < 0) { + if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) { perror("Cannont send slave dump request"); exit(1); } diff --git a/include/libnetlink.h b/include/libnetlink.h index 410c441b..8e411ebc 100644 --- a/include/libnetlink.h +++ b/include/libnetlink.h @@ -76,8 +76,7 @@ typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen); int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int fam, req_filter_fn_t fn) __attribute__((warn_unused_result)); -int rtnl_wilddump_stats_req_filter(struct rtnl_handle *rth, int fam, int type, - __u32 filt_mask) +int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask) __attribute__((warn_unused_result)); int rtnl_dump_request(struct rtnl_handle *rth, int type, void *req, int len) diff --git a/ip/iplink.c b/ip/iplink.c index d99c49ed..50ccb49a 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -1601,9 +1601,7 @@ static int iplink_afstats(int argc, char **argv) } } - if (rtnl_wilddump_stats_req_filter(&rth, AF_UNSPEC, - RTM_GETSTATS, - filt_mask) < 0) { + if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) { perror("Cannont send dump request"); return 1; } diff --git a/ip/iplink_xstats.c b/ip/iplink_xstats.c index 10f953bc..908d9228 100644 --- a/ip/iplink_xstats.c +++ b/ip/iplink_xstats.c @@ -65,9 +65,7 @@ int iplink_ifla_xstats(int argc, char **argv) else filt_mask = IFLA_STATS_FILTER_BIT(IFLA_STATS_LINK_XSTATS); - if (rtnl_wilddump_stats_req_filter(&rth, AF_UNSPEC, - RTM_GETSTATS, - filt_mask) < 0) { + if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, filt_mask) < 0) { perror("Cannont send dump request"); return -1; } diff --git a/lib/libnetlink.c b/lib/libnetlink.c index 73d720f4..f8b8fbfd 100644 --- a/lib/libnetlink.c +++ b/lib/libnetlink.c @@ -400,8 +400,7 @@ int rtnl_linkdump_req_filter_fn(struct rtnl_handle *rth, int family, return send(rth->fd, &req, req.nlh.nlmsg_len, 0); } -int rtnl_wilddump_stats_req_filter(struct rtnl_handle *rth, int fam, int type, - __u32 filt_mask) +int rtnl_statsdump_req_filter(struct rtnl_handle *rth, int fam, __u32 filt_mask) { struct { struct nlmsghdr nlh; @@ -410,7 +409,7 @@ int rtnl_wilddump_stats_req_filter(struct rtnl_handle *rth, int fam, int type, memset(&req, 0, sizeof(req)); req.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct if_stats_msg)); - req.nlh.nlmsg_type = type; + req.nlh.nlmsg_type = RTM_GETSTATS; req.nlh.nlmsg_flags = NLM_F_DUMP|NLM_F_REQUEST; req.nlh.nlmsg_pid = 0; req.nlh.nlmsg_seq = rth->dump = ++rth->seq; diff --git a/misc/ifstat.c b/misc/ifstat.c index 6e70e1eb..3a0e780f 100644 --- a/misc/ifstat.c +++ b/misc/ifstat.c @@ -203,8 +203,8 @@ static void load_info(void) if (is_extended) { ll_init_map(&rth); filter_mask = IFLA_STATS_FILTER_BIT(filter_type); - if (rtnl_wilddump_stats_req_filter(&rth, AF_UNSPEC, RTM_GETSTATS, - filter_mask) < 0) { + if (rtnl_statsdump_req_filter(&rth, AF_UNSPEC, + filter_mask) < 0) { perror("Cannot send dump request"); exit(1); }