]> granicus.if.org Git - strace/commitdiff
tests: check decoding of new FRA_* netlink attributes
authorEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 23 May 2018 16:56:32 +0000 (18:56 +0200)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 30 May 2018 20:50:29 +0000 (20:50 +0000)
* configure.ac (AC_CHECK_TYPES): Check for struct fib_rule_port_range
in <linux/fib_rules.h>.
* tests/nlattr_fib_rule_hdr.c: Include <linux/in.h>.
(FRA_PROTOCOL, FRA_IP_PROTO, FRA_SPORT_RANGE, FRA_DPORT_RANGE): New
macro constants.
[!HAVE_STRUCT_FIB_RULE_PORT_RANGE] (struct fib_rule_port_range): New
type.
(main): Check decoding of new FRA_* netlink attributes.

Co-Authored-by: Dmitry V. Levin <ldv@altlinux.org>
configure.ac
tests/nlattr_fib_rule_hdr.c

index 231a861b3e3a95037b39658835af4157e84e6f80..9f13fc7933c98df55333df2dc63c030f792b03a6 100644 (file)
@@ -519,7 +519,10 @@ AC_CHECK_TYPES(m4_normalize([
 
 AC_CHECK_TYPES([struct tc_sizespec],,, [#include <linux/pkt_sched.h>])
 
-AC_CHECK_TYPES([struct fib_rule_uid_range],,, [#include <linux/fib_rules.h>])
+AC_CHECK_TYPES(m4_normalize([
+       struct fib_rule_uid_range,
+       struct fib_rule_port_range
+]),,, [#include <linux/fib_rules.h>])
 
 AC_CHECK_TYPES([struct statfs], [
        AC_CHECK_MEMBERS(m4_normalize([
index a8242d033ead3abbbc77d9d86d34c9608c743422..e68bf887e79d88694b0552920df046c0ab5a8cc9 100644 (file)
 # include <inttypes.h>
 # include "test_nlattr.h"
 # include <linux/fib_rules.h>
+# include <linux/in.h>
 # include <linux/ip.h>
 # include <linux/rtnetlink.h>
 
 #define FRA_TUN_ID 12
 #define FRA_TABLE 15
 #define FRA_UID_RANGE 20
+#define FRA_PROTOCOL 21
+#define FRA_IP_PROTO 22
+#define FRA_SPORT_RANGE 23
+#define FRA_DPORT_RANGE 24
+
+# ifndef HAVE_STRUCT_FIB_RULE_PORT_RANGE
+struct fib_rule_port_range {
+       uint16_t start;
+       uint16_t end;
+};
+# endif /* HAVE_STRUCT_FIB_RULE_PORT_RANGE */
 
 static void
 init_rtmsg(struct nlmsghdr *const nlh, const unsigned int msg_len)
@@ -125,6 +137,62 @@ main(void)
                           printf("htobe64(%" PRIu64 ")", be64toh(tun_id)));
 #endif
 
+       uint8_t proto;
+
+       static const struct {
+               uint8_t arg;
+               const char *str;
+       } proto_args[] = {
+               { ARG_STR(RTPROT_UNSPEC) },
+               { 5, "0x5 /* RTPROT_??? */" },
+               { 17, "RTPROT_MROUTED" },
+               { 42, "RTPROT_BABEL" },
+               { 43, "0x2b /* RTPROT_??? */" },
+               { ARG_STR(0xde) " /* RTPROT_??? */" },
+       };
+
+       for (unsigned i = 0; i < ARRAY_SIZE(proto_args); i++) {
+               proto = proto_args[i].arg;
+               TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+                                  init_rtmsg, print_rtmsg,
+                                  FRA_PROTOCOL, pattern, proto,
+                                  printf("%s", proto_args[i].str));
+       }
+
+       static const struct {
+               uint8_t arg;
+               const char *str;
+       } ipproto_args[] = {
+               { ARG_STR(IPPROTO_TCP) },
+               { 254, "0xfe /* IPPROTO_??? */" },
+               { ARG_STR(IPPROTO_RAW) },
+       };
+
+       for (unsigned i = 0; i < ARRAY_SIZE(ipproto_args); i++) {
+               proto = ipproto_args[i].arg;
+               TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+                                  init_rtmsg, print_rtmsg,
+                                  FRA_IP_PROTO, pattern, proto,
+                                  printf("%s", ipproto_args[i].str));
+       }
+
+       static const struct fib_rule_port_range prange = {
+               .start = 0xabcd,
+               .end = 0xfeed,
+       };
+       TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+                          init_rtmsg, print_rtmsg,
+                          FRA_SPORT_RANGE, pattern, prange,
+                          PRINT_FIELD_U("{", prange, start);
+                          PRINT_FIELD_U(", ", prange, end);
+                          printf("}"));
+       TEST_NLATTR_OBJECT(fd, nlh0, hdrlen,
+                          init_rtmsg, print_rtmsg,
+                          FRA_DPORT_RANGE, pattern, prange,
+                          PRINT_FIELD_U("{", prange, start);
+                          PRINT_FIELD_U(", ", prange, end);
+                          printf("}"));
+
        puts("+++ exited with 0 +++");
        return 0;
 }