[PATCH v2 5/7] tests: check decoding of ndmsg netlink attributes

JingPiao Chen chenjingpiao at gmail.com
Tue Aug 29 07:45:21 UTC 2017


* tests/nlattr_ndmsg.c: Include <netinet/in.h> and <arpa/inet.h>.
(NDA_PORT): New macro.
(main): Check decoding of NDA_DST, NDA_CACHEINFO and NDA_PORT.
---
 tests/nlattr_ndmsg.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/tests/nlattr_ndmsg.c b/tests/nlattr_ndmsg.c
index 67aee88..8538a82 100644
--- a/tests/nlattr_ndmsg.c
+++ b/tests/nlattr_ndmsg.c
@@ -29,12 +29,16 @@
 #include "tests.h"
 
 #include <stdio.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 #include "test_nlattr.h"
 #ifdef HAVE_LINUX_NEIGHBOUR_H
 # include <linux/neighbour.h>
 #endif
 #include <linux/rtnetlink.h>
 
+#define NDA_PORT 6
+
 static void
 init_ndmsg(struct nlmsghdr *const nlh, const unsigned int msg_len)
 {
@@ -87,6 +91,33 @@ main(void)
 		     4, pattern, 4,
 		     print_quoted_hex(pattern, 4));
 
+	TEST_NLATTR(fd, nlh0, hdrlen,
+		    init_ndmsg, print_ndmsg,
+		    NDA_DST, 4, pattern, 4,
+		    print_quoted_hex(pattern, 4));
+
+	static const struct nda_cacheinfo ci = {
+		.ndm_confirmed = 0xabcdedad,
+		.ndm_used = 0xbcdaedad,
+		.ndm_updated = 0xcdbadeda,
+		.ndm_refcnt = 0xdeadbeda
+	};
+
+	TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+			   init_ndmsg, print_ndmsg,
+			   NDA_CACHEINFO, pattern, ci,
+			   PRINT_FIELD_U("{", ci, ndm_confirmed);
+			   PRINT_FIELD_U(", ", ci, ndm_used);
+			   PRINT_FIELD_U(", ", ci, ndm_updated);
+			   PRINT_FIELD_U(", ", ci, ndm_refcnt);
+			   printf("}"));
+
+	const uint16_t port = 0xabcd;
+	TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+			   init_ndmsg, print_ndmsg,
+			   NDA_PORT, pattern, port,
+			   printf("htons(%u)", ntohs(port)));
+
 	puts("+++ exited with 0 +++");
 	return 0;
 }
-- 
2.7.4





More information about the Strace-devel mailing list