]> granicus.if.org Git - strace/commitdiff
tests: check decoding of rtnetlink rule messages
authorJingPiao Chen <chenjingpiao@gmail.com>
Sun, 13 Aug 2017 02:22:24 +0000 (10:22 +0800)
committerDmitry V. Levin <ldv@altlinux.org>
Mon, 14 Aug 2017 01:07:07 +0000 (01:07 +0000)
* tests/netlink_route.c: Include <linux/fib_rules.h>.
(test_rtnl_rule): New function.
(main): Use it.

Co-authored-by: Fabien Siron <fabien.siron@epita.fr>
tests/netlink_route.c

index ff68579bbea67276b67c60707362676c5525ec32..9996f94842ace3605add7877d6b3eb52d7581b93 100644 (file)
@@ -32,6 +32,9 @@
 #include <unistd.h>
 #include <sys/socket.h>
 #include "test_netlink.h"
+#ifdef HAVE_LINUX_FIB_RULES_H
+# include <linux/fib_rules.h>
+#endif
 #ifdef HAVE_LINUX_IF_ADDR_H
 # include <linux/if_addr.h>
 #endif
@@ -263,6 +266,33 @@ test_rtnl_route(const int fd)
                             ", rtm_flags=RTM_F_NOTIFY}"));
 }
 
+#ifdef HAVE_LINUX_FIB_RULES_H
+static void
+test_rtnl_rule(const int fd)
+{
+       void *const nlh0 = tail_alloc(NLMSG_HDRLEN);
+       struct rtmsg msg = {
+               .rtm_family = AF_UNIX,
+               .rtm_dst_len = 0xaf,
+               .rtm_src_len = 0xda,
+               .rtm_tos = IPTOS_LOWDELAY,
+               .rtm_table = RT_TABLE_UNSPEC,
+               .rtm_type = FR_ACT_TO_TBL,
+               .rtm_flags = FIB_RULE_INVERT
+       };
+
+       TEST_NL_ROUTE(fd, nlh0, RTM_GETRULE, msg,
+                     printf("{family=AF_UNIX"),
+                     printf(", dst_len=%u, src_len=%u"
+                            ", tos=IPTOS_LOWDELAY"
+                            ", table=RT_TABLE_UNSPEC"
+                            ", action=FR_ACT_TO_TBL"
+                            ", flags=FIB_RULE_INVERT}",
+                            msg.rtm_dst_len,
+                            msg.rtm_src_len));
+}
+#endif
+
 int main(void)
 {
        skip_if_unavailable("/proc/self/fd/");
@@ -276,6 +306,9 @@ int main(void)
        test_rtnl_link(fd);
        test_rtnl_addr(fd);
        test_rtnl_route(fd);
+#ifdef HAVE_LINUX_FIB_RULES_H
+       test_rtnl_rule(fd);
+#endif
 
        printf("+++ exited with 0 +++\n");