From: Eugene Syromyatnikov Date: Wed, 23 May 2018 16:56:32 +0000 (+0200) Subject: tests: check decoding of new FRA_* netlink attributes X-Git-Tag: v4.23~81 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=245df3c44ba680e06b8caa388d37564d95196d0d;p=strace tests: check decoding of new FRA_* netlink attributes * configure.ac (AC_CHECK_TYPES): Check for struct fib_rule_port_range in . * tests/nlattr_fib_rule_hdr.c: Include . (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 --- diff --git a/configure.ac b/configure.ac index 231a861b..9f13fc79 100644 --- a/configure.ac +++ b/configure.ac @@ -519,7 +519,10 @@ AC_CHECK_TYPES(m4_normalize([ AC_CHECK_TYPES([struct tc_sizespec],,, [#include ]) -AC_CHECK_TYPES([struct fib_rule_uid_range],,, [#include ]) +AC_CHECK_TYPES(m4_normalize([ + struct fib_rule_uid_range, + struct fib_rule_port_range +]),,, [#include ]) AC_CHECK_TYPES([struct statfs], [ AC_CHECK_MEMBERS(m4_normalize([ diff --git a/tests/nlattr_fib_rule_hdr.c b/tests/nlattr_fib_rule_hdr.c index a8242d03..e68bf887 100644 --- a/tests/nlattr_fib_rule_hdr.c +++ b/tests/nlattr_fib_rule_hdr.c @@ -34,12 +34,24 @@ # include # include "test_nlattr.h" # include +# include # include # include #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; }