From: David Ahern <dsah...@gmail.com>

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 <dsah...@gmail.com>
---
 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 841a36123050..03fcc91f0219 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 bacaec8216f7..8f2b2935074a 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 fb5f1714c2d8..51ea457cd31a 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -23,6 +23,7 @@
 #include <time.h>
 #include <sys/uio.h>
 #include <linux/if_addrlabel.h>
+#include <linux/if_bridge.h>
 
 #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);
-- 
2.11.0

Reply via email to