[PATCH v2 15/16] tests: enhance AF_INET diag attributes test
JingPiao Chen
chenjingpiao at gmail.com
Sun Jun 18 05:18:42 UTC 2017
* tests/sock_diag_inet_attrs.c (test_inet_diag_meminfo,
test_inet_diag_vegasinfo, test_inet_diag_skmeminfo,
test_inet_diag_dctcpinfo, test_inet_diag_bbrinfo): New functions.
(main): Use them.
---
tests/sock_diag_inet_attrs.c | 537 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 537 insertions(+)
diff --git a/tests/sock_diag_inet_attrs.c b/tests/sock_diag_inet_attrs.c
index 43e9bc7..6403ac3 100644
--- a/tests/sock_diag_inet_attrs.c
+++ b/tests/sock_diag_inet_attrs.c
@@ -123,6 +123,538 @@ test_inet_diag_none(int fd)
nlh->nlmsg_len, sprintrc(rc));
}
+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;
+ void *const nlh0 = tail_alloc(NLMSG_SPACE(sizeof(*msg)));
+ long rc;
+
+ /* len < sizeof(*minfo) */
+ nla_len = NLA_HDRLEN + 2;
+ nlh = nlh0 - nla_len;
+ *nlh = (struct nlmsghdr) {
+ .nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_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, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ nlh->nlmsg_len, sprintrc(rc));
+
+ /* short read of inet_diag_meminfo */
+ nla_len = NLA_HDRLEN + sizeof(*minfo);
+ memmove(nlh0 - (nla_len - 1), nlh, NLMSG_SPACE(sizeof(*msg)));
+ nlh = nlh0 - (nla_len - 1);
+ nlh->nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len;
+
+ nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg));
+ *nla = (struct nlattr) {
+ .nla_len = nla_len,
+ .nla_type = INET_DIAG_MEMINFO
+ };
+
+ rc = sendto(fd, nlh, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ RTA_DATA(nla), nlh->nlmsg_len, sprintrc(rc));
+
+ /* inet_diag_meminfo */
+ nla_len = NLA_HDRLEN + sizeof(*minfo);
+ memmove(nlh0 - nla_len, nlh, NLMSG_SPACE(sizeof(*msg)));
+ nlh = nlh0 - nla_len;
+ nlh->nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len;
+
+ 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
+ };
+
+ rc = sendto(fd, nlh, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ 0xfadcacdb, 0xbdabcada, 0xbadbfafb, 0xfdacdadf,
+ nlh->nlmsg_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;
+ void *const nlh0 = tail_alloc(NLMSG_SPACE(sizeof(*msg)));
+ long rc;
+
+ /* len < sizeof(*vegas) */
+ nla_len = NLA_HDRLEN + 2;
+ nlh = nlh0 - nla_len;
+ *nlh = (struct nlmsghdr) {
+ .nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_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, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ nlh->nlmsg_len, sprintrc(rc));
+
+ /* short read of tcpvegas_info */
+ nla_len = NLA_HDRLEN + sizeof(*vegas);
+ memmove(nlh0 - (nla_len - 1), nlh, NLMSG_SPACE(sizeof(*msg)));
+ nlh = nlh0 - (nla_len - 1);
+ nlh->nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len;
+
+ nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg));
+ *nla = (struct nlattr) {
+ .nla_len = nla_len,
+ .nla_type = INET_DIAG_VEGASINFO
+ };
+
+ rc = sendto(fd, nlh, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ RTA_DATA(nla), nlh->nlmsg_len, sprintrc(rc));
+
+ /* tcpvegas_info */
+ nla_len = NLA_HDRLEN + sizeof(*vegas);
+ memmove(nlh0 - nla_len, nlh, NLMSG_SPACE(sizeof(*msg)));
+ nlh = nlh0 - nla_len;
+ nlh->nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len;
+
+ 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
+ };
+
+ rc = sendto(fd, nlh, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ 0xfadcacdb, 0xbdabcada, 0xbadbfafb, 0xfdacdadf,
+ nlh->nlmsg_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;
+ void *const nlh0 = tail_alloc(NLMSG_SPACE(sizeof(*msg)));
+ long rc;
+
+ nla_len = NLA_HDRLEN + sizeof(*mem) * 2;
+ nlh = nlh0 - nla_len;
+ *nlh = (struct nlmsghdr) {
+ .nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_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, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ 0xaffacbad, 0xffadbcab, nlh->nlmsg_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;
+ void *const nlh0 = tail_alloc(NLMSG_SPACE(sizeof(*msg)));
+ long rc;
+
+ /* len < sizeof(*dctcp) */
+ nla_len = NLA_HDRLEN + 2;
+ nlh = nlh0 - nla_len;
+ *nlh = (struct nlmsghdr) {
+ .nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_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, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ nlh->nlmsg_len, sprintrc(rc));
+
+ /* short read of tcp_dctcp_info */
+ nla_len = NLA_HDRLEN + sizeof(*dctcp);
+ memmove(nlh0 - (nla_len - 1), nlh, NLMSG_SPACE(sizeof(*msg)));
+ nlh = nlh0 - (nla_len - 1);
+ nlh->nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len;
+
+ nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg));
+ *nla = (struct nlattr) {
+ .nla_len = nla_len,
+ .nla_type = INET_DIAG_DCTCPINFO
+ };
+
+ rc = sendto(fd, nlh, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ RTA_DATA(nla), nlh->nlmsg_len, sprintrc(rc));
+
+ /* tcp_dctcp_info */
+ nla_len = NLA_HDRLEN + sizeof(*dctcp);
+ memmove(nlh0 - nla_len, nlh, NLMSG_SPACE(sizeof(*msg)));
+ nlh = nlh0 - nla_len;
+ nlh->nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len;
+
+ 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
+ };
+
+ rc = sendto(fd, nlh, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ 0xfdac, 0xfadc, 0xbdabcada, 0xbadbfafb, 0xfdacdadf,
+ nlh->nlmsg_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;
+ void *const nlh0 = tail_alloc(NLMSG_SPACE(sizeof(*msg)));
+ long rc;
+
+ /* len < sizeof(*bbf) */
+ nla_len = NLA_HDRLEN + 2;
+ nlh = nlh0 - nla_len;
+ *nlh = (struct nlmsghdr) {
+ .nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_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, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ nlh->nlmsg_len, sprintrc(rc));
+
+ /* short read of tcp_bbr_info */
+ nla_len = NLA_HDRLEN + sizeof(*bbr);
+ memmove(nlh0 - (nla_len - 1), nlh, NLMSG_SPACE(sizeof(*msg)));
+ nlh = nlh0 - (nla_len - 1);
+ nlh->nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len;
+
+ nla = (void *) nlh + NLMSG_SPACE(sizeof(*msg));
+ *nla = (struct nlattr) {
+ .nla_len = nla_len,
+ .nla_type = INET_DIAG_BBRINFO
+ };
+
+ rc = sendto(fd, nlh, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ RTA_DATA(nla), nlh->nlmsg_len, sprintrc(rc));
+
+ /* tcp_bbr_info */
+ nla_len = NLA_HDRLEN + sizeof(*bbr);
+ memmove(nlh0 - nla_len, nlh, NLMSG_SPACE(sizeof(*msg)));
+ nlh = nlh0 - nla_len;
+ nlh->nlmsg_len = NLMSG_SPACE(sizeof(*msg)) + nla_len;
+
+ 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
+ };
+
+ rc = sendto(fd, nlh, nlh->nlmsg_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, nlh->nlmsg_len, address, address, nla->nla_len,
+ 0xfdacdadf, 0xfadcacdb, 0xbdabcada, 0xbadbfafb, 0xfdacdadf,
+ nlh->nlmsg_len, sprintrc(rc));
+}
+
int main(void)
{
skip_if_unavailable("/proc/self/fd/");
@@ -130,6 +662,11 @@ int main(void)
int fd = create_nl_socket(NETLINK_SOCK_DIAG);
test_inet_diag_none(fd);
+ 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");
--
2.7.4
More information about the Strace-devel
mailing list