[PATCH 4/8] tests: check decoding of fib_rule_hdr netlink attributes

JingPiao Chen chenjingpiao at gmail.com
Sun Aug 27 17:44:39 UTC 2017


* tests/nlattr_fib_rule_hdr.c: Include <inttypes.h>.
(FRA_TUN_ID, FRA_UID_RANGE): New macros.
(main): Check decoding of FRA_DST, FRA_UID_RANGE and FRA_TUN_ID.
---
 tests/nlattr_fib_rule_hdr.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/tests/nlattr_fib_rule_hdr.c b/tests/nlattr_fib_rule_hdr.c
index 5bb9d53..9278f0d 100644
--- a/tests/nlattr_fib_rule_hdr.c
+++ b/tests/nlattr_fib_rule_hdr.c
@@ -31,11 +31,15 @@
 #ifdef HAVE_LINUX_FIB_RULES_H
 
 # include <stdio.h>
+# include <inttypes.h>
 # include "test_nlattr.h"
 # include <linux/fib_rules.h>
 # include <linux/ip.h>
 # include <linux/rtnetlink.h>
 
+#define FRA_TUN_ID 12
+#define FRA_UID_RANGE 20
+
 static void
 init_rtmsg(struct nlmsghdr *const nlh, const unsigned int msg_len)
 {
@@ -89,6 +93,29 @@ main(void)
 		     4, pattern, 4,
 		     print_quoted_hex(pattern, 4));
 
+	TEST_NLATTR(fd, nlh0, hdrlen,
+		    init_rtmsg, print_rtmsg,
+		    FRA_DST, 4, pattern, 4,
+		    print_quoted_hex(pattern, 4));
+
+#ifdef HAVE_STRUCT_FIB_RULE_UID_RANGE
+	static const struct fib_rule_uid_range range = {
+		.start = 0xabcdedad,
+		.end = 0xbcdeadba
+	};
+	TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+			   init_rtmsg, print_rtmsg,
+			   FRA_UID_RANGE, pattern, range,
+			   PRINT_FIELD_U("{", range, start);
+			   PRINT_FIELD_U(", ", range, end);
+			   printf("}"));
+#endif
+	const uint64_t tun_id = 0xabcdcdbeedabadef;
+	TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+			   init_rtmsg, print_rtmsg,
+			   FRA_TUN_ID, pattern, tun_id,
+			   printf("htobe64(%" PRIu64 ")", be64toh(tun_id)));
+
 	puts("+++ exited with 0 +++");
 	return 0;
 }
-- 
2.7.4





More information about the Strace-devel mailing list