]> granicus.if.org Git - strace/commitdiff
tests: check decoding of fib_rule_hdr netlink attributes
authorJingPiao Chen <chenjingpiao@gmail.com>
Sun, 27 Aug 2017 16:37:33 +0000 (00:37 +0800)
committerJingPiao Chen <chenjingpiao@gmail.com>
Tue, 29 Aug 2017 07:15:04 +0000 (15:15 +0800)
* 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

index 5bb9d53fa4b5db746c99233bad0f76f1b8885ede..d7a48d6788ad43d31798bc9e5e230d17612e1ab1 100644 (file)
 #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,31 @@ 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
+#if defined HAVE_BE64TOH || defined be64toh
+       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)));
+#endif
+
        puts("+++ exited with 0 +++");
        return 0;
 }