* tests/nlattr_inet_diag.c: New file. * tests/gen_tests.in (nlattr_inet_diag): New entry. * tests/pure_executables.list: Add nlattr_inet_diag. * tests/.gitignore: Likewise. --- tests/.gitignore | 1 + tests/gen_tests.in | 1 + tests/nlattr_inet_diag.c | 727 ++++++++++++++++++++++++++++++++++++++++++++ tests/pure_executables.list | 1 + 4 files changed, 730 insertions(+) create mode 100644 tests/nlattr_inet_diag.c
diff --git a/tests/.gitignore b/tests/.gitignore index fc6c82d..af7cad7 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -210,6 +210,7 @@ netlink_unix_diag netlink_xfrm newfstatat nlattr +nlattr_inet_diag nsyscalls old_mmap oldfstat diff --git a/tests/gen_tests.in b/tests/gen_tests.in index 275d308..ad7d0b8 100644 --- a/tests/gen_tests.in +++ b/tests/gen_tests.in @@ -193,6 +193,7 @@ netlink_selinux +netlink_sock_diag.test netlink_xfrm +netlink_sock_diag.test newfstatat -a32 -v -P stat.sample -P /dev/full nlattr +netlink_sock_diag.test +nlattr_inet_diag +netlink_sock_diag.test old_mmap -a11 -e trace=mmap oldfstat -a18 -v -P stat.sample oldlstat -a32 -v -P stat.sample -P /dev/full diff --git a/tests/nlattr_inet_diag.c b/tests/nlattr_inet_diag.c new file mode 100644 index 0000000..ef0000c --- /dev/null +++ b/tests/nlattr_inet_diag.c @@ -0,0 +1,727 @@ +/* + * Copyright (c) 2017 JingPiao Chen <chenjingp...@gmail.com> + * Copyright (c) 2017 The strace developers. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "tests.h" +#include <stdio.h> +#include <string.h> +#include <sys/socket.h> +#include <netinet/tcp.h> +#include <arpa/inet.h> +#include <linux/inet_diag.h> +#include <linux/netlink.h> +#include <linux/rtnetlink.h> +#include <linux/sock_diag.h> + +#if !defined NETLINK_SOCK_DIAG && defined NETLINK_INET_DIAG +# define NETLINK_SOCK_DIAG NETLINK_INET_DIAG +#endif + +#define INIT_STRUCT(type, name, ...) \ + do { \ + type tmp = { __VA_ARGS__ }; \ + memcpy(name, &tmp, sizeof(tmp)); \ + } while (0) + +static void +test_inet_diag_meminfo(const int fd) +{ + const char address[] = "12.34.56.78"; + struct nlmsghdr *nlh; + struct inet_diag_msg *msg; + struct nlattr *nla; + struct inet_diag_meminfo *minfo; + int nla_len; + unsigned msg_len; + void *const nlh0 = tail_alloc(NLMSG_SPACE(sizeof(*msg))); + long rc; + + /* len < sizeof(*minfo) */ + nla_len = NLA_HDRLEN + 2; + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - nla_len; + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_MEMINFO + }; + memcpy(RTA_DATA(nla), "12", 2); + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_MEMINFO}" + ", \"12\"}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + msg_len, sprintrc(rc)); + + /* short read of inet_diag_meminfo */ + nla_len = NLA_HDRLEN + sizeof(*minfo); + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - (nla_len - 1); + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_MEMINFO + }; + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_MEMINFO}" + ", %p}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + RTA_DATA(nla), msg_len, sprintrc(rc)); + + /* inet_diag_meminfo */ + nla_len = NLA_HDRLEN + sizeof(*minfo); + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - nla_len; + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_MEMINFO + }; + minfo = RTA_DATA(nla); + *minfo = (struct inet_diag_meminfo) { + .idiag_rmem = 0xfadcacdb, + .idiag_wmem = 0xbdabcada, + .idiag_fmem = 0xbadbfafb, + .idiag_tmem = 0xfdacdadf + }; + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_MEMINFO}" + ", {idiag_rmem=%u, idiag_wmem=%u, idiag_fmem=%u, idiag_tmem=%u}}}" + ", %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + 0xfadcacdb, 0xbdabcada, 0xbadbfafb, 0xfdacdadf, + msg_len, sprintrc(rc)); +} + +static void +test_inet_diag_vegasinfo(const int fd) +{ + const char address[] = "12.34.56.78"; + struct nlmsghdr *nlh; + struct inet_diag_msg *msg; + struct nlattr *nla; + struct tcpvegas_info *vegas; + int nla_len; + unsigned msg_len; + void *const nlh0 = tail_alloc(NLMSG_SPACE(sizeof(*msg))); + long rc; + + /* len < sizeof(*vegas) */ + nla_len = NLA_HDRLEN + 2; + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - nla_len; + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_VEGASINFO + }; + memcpy(RTA_DATA(nla), "12", 2); + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_VEGASINFO}" + ", \"12\"}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + msg_len, sprintrc(rc)); + + /* short read of tcpvegas_info */ + nla_len = NLA_HDRLEN + sizeof(*vegas); + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - (nla_len - 1); + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_VEGASINFO + }; + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_VEGASINFO}" + ", %p}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + RTA_DATA(nla), msg_len, sprintrc(rc)); + + /* tcpvegas_info */ + nla_len = NLA_HDRLEN + sizeof(*vegas); + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - nla_len; + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_VEGASINFO + }; + vegas = RTA_DATA(nla); + *vegas = (struct tcpvegas_info) { + .tcpv_enabled = 0xfadcacdb, + .tcpv_rttcnt = 0xbdabcada, + .tcpv_rtt = 0xbadbfafb, + .tcpv_minrtt = 0xfdacdadf + }; + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_VEGASINFO}" + ", {tcpv_enabled=%u, tcpv_rttcnt=%u, tcpv_rtt=%u" + ", tcpv_minrtt=%u}}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + 0xfadcacdb, 0xbdabcada, 0xbadbfafb, 0xfdacdadf, + msg_len, sprintrc(rc)); +} + +static void +test_inet_diag_skmeminfo(const int fd) +{ + const char address[] = "12.34.56.78"; + struct nlmsghdr *nlh; + struct inet_diag_msg *msg; + struct nlattr *nla; + uint32_t *mem; + int nla_len; + unsigned msg_len; + void *const nlh0 = tail_alloc(NLMSG_SPACE(sizeof(*msg))); + long rc; + + nla_len = NLA_HDRLEN + sizeof(*mem) * 2; + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - nla_len; + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_SKMEMINFO + }; + mem = RTA_DATA(nla); + mem[0] = 0xaffacbad; + mem[1] = 0xffadbcab; + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_SKMEMINFO}" + ", [%u, %u]}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + 0xaffacbad, 0xffadbcab, msg_len, sprintrc(rc)); +} + +static void +test_inet_diag_dctcpinfo(const int fd) +{ + const char address[] = "12.34.56.78"; + struct nlmsghdr *nlh; + struct inet_diag_msg *msg; + struct nlattr *nla; + struct tcp_dctcp_info *dctcp; + int nla_len; + unsigned msg_len; + void *const nlh0 = tail_alloc(NLMSG_SPACE(sizeof(*msg))); + long rc; + + /* len < sizeof(*dctcp) */ + nla_len = NLA_HDRLEN + 2; + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - nla_len; + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_DCTCPINFO + }; + memcpy(RTA_DATA(nla), "12", 2); + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_DCTCPINFO}" + ", \"12\"}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + msg_len, sprintrc(rc)); + + /* short read of tcp_dctcp_info */ + nla_len = NLA_HDRLEN + sizeof(*dctcp); + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - (nla_len - 1); + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_DCTCPINFO + }; + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_DCTCPINFO}" + ", %p}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + RTA_DATA(nla), msg_len, sprintrc(rc)); + + /* tcp_dctcp_info */ + nla_len = NLA_HDRLEN + sizeof(*dctcp); + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - nla_len; + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_DCTCPINFO + }; + dctcp = RTA_DATA(nla); + *dctcp = (struct tcp_dctcp_info) { + .dctcp_enabled = 0xfdac, + .dctcp_ce_state = 0xfadc, + .dctcp_alpha = 0xbdabcada, + .dctcp_ab_ecn = 0xbadbfafb, + .dctcp_ab_tot = 0xfdacdadf + }; + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_DCTCPINFO}" + ", {dctcp_enabled=%u, dctcp_ce_state=%u" + ", dctcp_alpha=%u, dctcp_ab_ecn=%u, dctcp_ab_tot=%u}}}" + ", %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + 0xfdac, 0xfadc, 0xbdabcada, 0xbadbfafb, 0xfdacdadf, + msg_len, sprintrc(rc)); +} + +static void +test_inet_diag_bbrinfo(const int fd) +{ + const char address[] = "12.34.56.78"; + struct nlmsghdr *nlh; + struct inet_diag_msg *msg; + struct nlattr *nla; + struct tcp_bbr_info *bbr; + int nla_len; + unsigned msg_len; + void *const nlh0 = tail_alloc(NLMSG_SPACE(sizeof(*msg))); + long rc; + + /* len < sizeof(*bbf) */ + nla_len = NLA_HDRLEN + 2; + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - nla_len; + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_BBRINFO + }; + memcpy(RTA_DATA(nla), "12", 2); + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_BBRINFO}" + ", \"12\"}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + msg_len, sprintrc(rc)); + + /* short read of tcp_bbr_info */ + nla_len = NLA_HDRLEN + sizeof(*bbr); + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - (nla_len - 1); + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_BBRINFO + }; + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_BBRINFO}" + ", %p}}, %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + RTA_DATA(nla), msg_len, sprintrc(rc)); + + /* tcp_bbr_info */ + nla_len = NLA_HDRLEN + sizeof(*bbr); + msg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len; + nlh = nlh0 - nla_len; + INIT_STRUCT(struct nlmsghdr, nlh, + .nlmsg_len = msg_len, + .nlmsg_type = SOCK_DIAG_BY_FAMILY, + .nlmsg_flags = NLM_F_DUMP + ); + + msg = NLMSG_DATA(nlh); + *msg = (struct inet_diag_msg) { + .idiag_family = AF_INET, + .idiag_state = TCP_LISTEN, + }; + + nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg)); + *nla = (struct nlattr) { + .nla_len = nla_len, + .nla_type = INET_DIAG_BBRINFO + }; + bbr = RTA_DATA(nla); + *bbr = (struct tcp_bbr_info) { + .bbr_bw_lo = 0xfdacdadf, + .bbr_bw_hi = 0xfadcacdb, + .bbr_min_rtt = 0xbdabcada, + .bbr_pacing_gain = 0xbadbfafb, + .bbr_cwnd_gain = 0xfdacdadf + }; + + if (!inet_pton(AF_INET, address, msg->id.idiag_src)) + perror_msg_and_skip("sendto"); + if (!inet_pton(AF_INET, address, msg->id.idiag_dst)) + perror_msg_and_skip("sendto"); + + rc = sendto(fd, nlh, msg_len, MSG_DONTWAIT, NULL, 0); + + printf("sendto(%d, {{len=%u, type=SOCK_DIAG_BY_FAMILY" + ", flags=NLM_F_DUMP, seq=0, pid=0}, {idiag_family=AF_INET" + ", idiag_state=TCP_LISTEN, idiag_timer=0, idiag_retrans=0" + ", id={idiag_sport=htons(0), idiag_dport=htons(0)" + ", inet_pton(AF_INET, \"%s\", &idiag_src)" + ", inet_pton(AF_INET, \"%s\", &idiag_dst)" + ", idiag_if=0, idiag_cookie=[0, 0]}, idiag_expires=0" + ", idiag_rqueue=0, idiag_wqueue=0, idiag_uid=0" + ", idiag_inode=0}, {{nla_len=%u, nla_type=INET_DIAG_BBRINFO}" + ", {bbr_bw_lo=%#x, bbr_bw_hi=%#x, bbr_min_rtt=%u" + ", bbr_pacing_gain=%u, bbr_cwnd_gain=%u}}}" + ", %u, MSG_DONTWAIT, NULL, 0) = %s\n", + fd, msg_len, address, address, nla->nla_len, + 0xfdacdadf, 0xfadcacdb, 0xbdabcada, 0xbadbfafb, 0xfdacdadf, + msg_len, sprintrc(rc)); +} + +int main(void) +{ + skip_if_unavailable("/proc/self/fd/"); + + int fd = create_nl_socket(NETLINK_SOCK_DIAG); + + test_inet_diag_meminfo(fd); + test_inet_diag_vegasinfo(fd); + test_inet_diag_skmeminfo(fd); + test_inet_diag_dctcpinfo(fd); + test_inet_diag_bbrinfo(fd); + + printf("+++ exited with 0 +++\n"); + + return 0; +} diff --git a/tests/pure_executables.list b/tests/pure_executables.list index b0c52c6..9bbbac7 100755 --- a/tests/pure_executables.list +++ b/tests/pure_executables.list @@ -175,6 +175,7 @@ netlink_sock_diag netlink_xfrm newfstatat nlattr +nlattr_inet_diag old_mmap oldfstat oldlstat -- 2.7.4 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel