[PATCH 13/27] netlink: add basic attribute parser of br_port_msg of NETLINK_ROUTE

JingPiao Chen chenjingpiao at gmail.com
Tue Aug 15 04:41:21 UTC 2017


* rtnl_mdb.c: Include "netlink.h", "nlattr.h"
and "xlat/rtnl_mdb_attrs.h".
(decode_br_port_msg): Call decode_nlattr.
* xlat/rtnl_mdb_attrs.in: New file.

Co-authored-by: Fabien Siron <fabien.siron at epita.fr>
---
 rtnl_mdb.c             | 15 ++++++++++++++-
 xlat/rtnl_mdb_attrs.in |  3 +++
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 xlat/rtnl_mdb_attrs.in

diff --git a/rtnl_mdb.c b/rtnl_mdb.c
index f0171fb..ebe737d 100644
--- a/rtnl_mdb.c
+++ b/rtnl_mdb.c
@@ -32,15 +32,20 @@
 #ifdef HAVE_STRUCT_BR_PORT_MSG
 
 # include "netlink_route.h"
+# include "nlattr.h"
 # include "print_fields.h"
 
 # include <netinet/in.h>
 # include <linux/if_bridge.h>
+# include "netlink.h"
+
+# include "xlat/rtnl_mdb_attrs.h"
 
 DECL_NETLINK_ROUTE_DECODER(decode_br_port_msg)
 {
 	struct br_port_msg bpm = { .family = family };
-	const size_t offset = sizeof(bpm.family);
+	size_t offset = sizeof(bpm.family);
+	bool decode_nla = false;
 
 	PRINT_FIELD_XVAL("{", bpm, family, addrfams, "AF_???");
 
@@ -50,10 +55,18 @@ DECL_NETLINK_ROUTE_DECODER(decode_br_port_msg)
 					 sizeof(bpm) - offset,
 					 (void *) &bpm + offset)) {
 			PRINT_FIELD_IFINDEX("", bpm, ifindex);
+			decode_nla = true;
 		}
 	} else
 		tprints("...");
 	tprints("}");
+
+	offset = NLMSG_ALIGN(sizeof(bpm));
+	if (decode_nla && len > offset) {
+		tprints(", ");
+		decode_nlattr(tcp, addr + offset, len - offset,
+			      rtnl_mdb_attrs, "MDBA_???", NULL, 0, NULL);
+	}
 }
 
 #endif
diff --git a/xlat/rtnl_mdb_attrs.in b/xlat/rtnl_mdb_attrs.in
new file mode 100644
index 0000000..b804662
--- /dev/null
+++ b/xlat/rtnl_mdb_attrs.in
@@ -0,0 +1,3 @@
+MDBA_UNSPEC		0
+MDBA_MDB		1
+MDBA_ROUTER		2
-- 
2.7.4





More information about the Strace-devel mailing list