[PATCH 04/27] netlink: add basic attribute parser of rtmsg of NETLINK_ROUTE

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


* rtnl_route.c: Include "nlattr.h" and "xlat/rtnl_route_attrs.h".
(decode_rtmsg): Call decode_nlattr.
* xlat/rtnl_route_attrs.in: New file.

Co-authored-by: Fabien Siron <fabien.siron at epita.fr>
---
 rtnl_route.c             | 13 ++++++++++++-
 xlat/rtnl_route_attrs.in | 27 +++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 1 deletion(-)
 create mode 100644 xlat/rtnl_route_attrs.in

diff --git a/rtnl_route.c b/rtnl_route.c
index f25d038..7b997f8 100644
--- a/rtnl_route.c
+++ b/rtnl_route.c
@@ -29,6 +29,7 @@
 
 #include "defs.h"
 #include "netlink_route.h"
+#include "nlattr.h"
 #include "print_fields.h"
 
 #include <linux/ip.h>
@@ -40,11 +41,13 @@
 #include "xlat/routing_protocols.h"
 #include "xlat/routing_table_ids.h"
 #include "xlat/routing_types.h"
+#include "xlat/rtnl_route_attrs.h"
 
 DECL_NETLINK_ROUTE_DECODER(decode_rtmsg)
 {
 	struct rtmsg rtmsg = { .rtm_family = family };
-	const size_t offset = sizeof(rtmsg.rtm_family);
+	size_t offset = sizeof(rtmsg.rtm_family);
+	bool decode_nla = false;
 
 	PRINT_FIELD_XVAL("{", rtmsg, rtm_family, addrfams, "AF_???");
 
@@ -67,8 +70,16 @@ DECL_NETLINK_ROUTE_DECODER(decode_rtmsg)
 					 routing_types, "RTN_???");
 			PRINT_FIELD_FLAGS(", ", rtmsg, rtm_flags,
 					  routing_flags, "RTM_F_???");
+			decode_nla = true;
 		}
 	} else
 		tprints("...");
 	tprints("}");
+
+	offset = NLMSG_ALIGN(sizeof(rtmsg));
+	if (decode_nla && len > offset) {
+		tprints(", ");
+		decode_nlattr(tcp, addr + offset, len - offset,
+			      rtnl_route_attrs, "RTA_???", NULL, 0, NULL);
+	}
 }
diff --git a/xlat/rtnl_route_attrs.in b/xlat/rtnl_route_attrs.in
new file mode 100644
index 0000000..f5fa559
--- /dev/null
+++ b/xlat/rtnl_route_attrs.in
@@ -0,0 +1,27 @@
+RTA_UNSPEC		0
+RTA_DST			1
+RTA_SRC			2
+RTA_IIF			3
+RTA_OIF			4
+RTA_GATEWAY		5
+RTA_PRIORITY		6
+RTA_PREFSRC		7
+RTA_METRICS		8
+RTA_MULTIPATH		9
+RTA_PROTOINFO		10
+RTA_FLOW		11
+RTA_CACHEINFO		12
+RTA_SESSION		13
+RTA_MP_ALGO		14
+RTA_TABLE		15
+RTA_MARK		16
+RTA_MFC_STATS		17
+RTA_VIA			18
+RTA_NEWDST		19
+RTA_PREF		20
+RTA_ENCAP_TYPE		21
+RTA_ENCAP		22
+RTA_EXPIRES		23
+RTA_PAD			24
+RTA_UID			25
+RTA_TTL_PROPAGATE	26
-- 
2.7.4





More information about the Strace-devel mailing list