[PATCH 4/4] tests: add check for decoding of netfilter subsystem

Chen Jingpiao chenjingpiao at gmail.com
Thu Jan 18 14:02:47 UTC 2018


* tests/netlink_netfilter.c(test_nfgenmsg): Add check for decoding
of netfilter subsystem.
---
 tests/netlink_netfilter.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/tests/netlink_netfilter.c b/tests/netlink_netfilter.c
index e2cecd6..1d20320 100644
--- a/tests/netlink_netfilter.c
+++ b/tests/netlink_netfilter.c
@@ -158,9 +158,26 @@ test_nfgenmsg(const int fd)
 		     printf(", version=%#x /* NFNETLINK_??? */", msg.version);
 #  endif
 		     printf(", res_id=htons(%d)", NFNL_SUBSYS_NFTABLES));
+# endif /* NFNL_MSG_BATCH_BEGIN */
 
 	char str_buf[NLMSG_ALIGN(sizeof(msg)) + 4];
+	msg.res_id = htons(0xefab);
+	memcpy(str_buf, &msg, sizeof(msg));
+	memcpy(str_buf + NLMSG_ALIGN(sizeof(msg)), "1234", 4);
+	TEST_NETLINK_(fd, nlh0,
+		      0xffff, "0xff /* NFNL_SUBSYS_??? */<<8|0xff",
+		      NLM_F_REQUEST, "NLM_F_REQUEST",
+		      sizeof(str_buf), str_buf, sizeof(str_buf),
+		      printf("{nfgen_family=AF_UNIX");
+# ifdef NFNETLINK_V0
+		      printf(", version=NFNETLINK_V0");
+# else
+		      printf(", version=%#x /* NFNETLINK_??? */", msg.version);
+# endif
+		      printf(", res_id=htons(%d)"
+			     ", \"\\x31\\x32\\x33\\x34\"", 0xefab));
 
+# ifdef NFNL_MSG_BATCH_BEGIN
 	msg.res_id = htons(0xabcd);
 	memcpy(str_buf, &msg, sizeof(msg));
 	memcpy(str_buf + NLMSG_ALIGN(sizeof(msg)), "1234", 4);
@@ -177,6 +194,31 @@ test_nfgenmsg(const int fd)
 		     printf(", res_id=htons(%d)"
 			    ", \"\\x31\\x32\\x33\\x34\"", 0xabcd));
 # endif /* NFNL_MSG_BATCH_BEGIN */
+
+	static const struct nlattr nla = {
+		.nla_len = sizeof(nla),
+		.nla_type = 0x0bcd
+	};
+	char nla_buf[NLMSG_ALIGN(sizeof(msg)) + sizeof(nla)];
+
+	msg.res_id = htons(NFNL_SUBSYS_NFTABLES);
+	memcpy(nla_buf, &msg, sizeof(msg));
+	memcpy(nla_buf + NLMSG_ALIGN(sizeof(msg)), &nla, sizeof(nla));
+
+	TEST_NETLINK_(fd, nlh0,
+		      NFNL_SUBSYS_NFTABLES << 8 | 0xff,
+		      "NFNL_SUBSYS_NFTABLES<<8|0xff /* NFT_MSG_??? */",
+		      NLM_F_REQUEST, "NLM_F_REQUEST",
+		      sizeof(nla_buf), nla_buf, sizeof(nla_buf),
+		      printf("{nfgen_family=AF_UNIX");
+# ifdef NFNETLINK_V0
+		      printf(", version=NFNETLINK_V0");
+# else
+		      printf(", version=%#x /* NFNETLINK_??? */", msg.version);
+# endif
+		      printf(", res_id=htons(NFNL_SUBSYS_NFTABLES)"
+			     ", {nla_len=%d, nla_type=%#x}",
+			     nla.nla_len, nla.nla_type));
 }
 
 int main(void)
-- 
2.7.4





More information about the Strace-devel mailing list