[PATCH 05/27] netlink: add basic attribute parser of fib_rule_hdr of NETLINK_ROUTE

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


* rtnl_rule.c: Include "nlattr.h" and "xlat/rtnl_rule_attrs.h".
(decode_fib_rule_hdr): Call decode_nlattr.
* xlat/rtnl_rule_attrs.in: New file.

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

diff --git a/rtnl_rule.c b/rtnl_rule.c
index b3e6d52..5a1dd28 100644
--- a/rtnl_rule.c
+++ b/rtnl_rule.c
@@ -30,6 +30,7 @@
 #include "defs.h"
 
 #include "netlink_route.h"
+#include "nlattr.h"
 #include "print_fields.h"
 
 #include "netlink.h"
@@ -40,6 +41,7 @@
 
 #include "xlat/fib_rule_actions.h"
 #include "xlat/fib_rule_flags.h"
+#include "xlat/rtnl_rule_attrs.h"
 
 DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr)
 {
@@ -49,7 +51,8 @@ DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr)
 	 * struct fib_rule_hdr.
 	 */
 	struct rtmsg msg = { .rtm_family = family };
-	const size_t offset = sizeof(msg.rtm_family);
+	size_t offset = sizeof(msg.rtm_family);
+	bool decode_nla = false;
 
 	tprints("{family=");
 	printxval(addrfams, msg.rtm_family, "AF_???");
@@ -71,8 +74,16 @@ DECL_NETLINK_ROUTE_DECODER(decode_fib_rule_hdr)
 			tprints(", flags=");
 			printflags(fib_rule_flags, msg.rtm_flags,
 				   "FIB_RULE_???");
+			decode_nla = true;
 		}
 	} else
 		tprints("...");
 	tprints("}");
+
+	offset = NLMSG_ALIGN(sizeof(msg));
+	if (decode_nla && len > offset) {
+		tprints(", ");
+		decode_nlattr(tcp, addr + offset, len - offset,
+			      rtnl_rule_attrs, "FRA_???", NULL, 0, NULL);
+	}
 }
diff --git a/xlat/rtnl_rule_attrs.in b/xlat/rtnl_rule_attrs.in
new file mode 100644
index 0000000..971f118
--- /dev/null
+++ b/xlat/rtnl_rule_attrs.in
@@ -0,0 +1,21 @@
+FRA_UNSPEC		0
+FRA_DST			1
+FRA_SRC			2
+FRA_IIFNAME		3
+FRA_GOTO		4
+FRA_UNUSED2		5
+FRA_PRIORITY		6
+FRA_UNUSED3		7
+FRA_UNUSED4		8
+FRA_UNUSED5		9
+FRA_FWMARK		10
+FRA_FLOW		11
+FRA_TUN_ID		12
+FRA_SUPPRESS_IFGROUP	13
+FRA_SUPPRESS_PREFIXLEN	14
+FRA_TABLE		15
+FRA_FWMASK		16
+FRA_OIFNAME		17
+FRA_PAD			18
+FRA_L3MDEV		19
+FRA_UID_RANGE		20
-- 
2.7.4





More information about the Strace-devel mailing list