summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorRahat Mahmood <rahat@google.com>2019-08-01 13:57:41 -0700
committergVisor bot <gvisor-bot@google.com>2019-08-01 13:58:48 -0700
commit79511e8a50facd509b8180d0160762b510dd6196 (patch)
treeef7dbd6a36361a9e84a7287d6e54fcbae7a4edd6 /test
parent0a246fab80581351309cdfe39ffeeffa00f811b1 (diff)
Implement getsockopt(TCP_INFO).
Export some readily-available fields for TCP_INFO and stub out the rest. PiperOrigin-RevId: 261191548
Diffstat (limited to 'test')
-rw-r--r--test/syscalls/linux/socket_ip_tcp_generic.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/syscalls/linux/socket_ip_tcp_generic.cc b/test/syscalls/linux/socket_ip_tcp_generic.cc
index a43cf9bce..01987d2f0 100644
--- a/test/syscalls/linux/socket_ip_tcp_generic.cc
+++ b/test/syscalls/linux/socket_ip_tcp_generic.cc
@@ -697,5 +697,28 @@ TEST_P(TCPSocketPairTest, SetCongestionControlFailsForUnsupported) {
EXPECT_EQ(0, memcmp(got_cc, old_cc, sizeof(old_cc)));
}
+TEST_P(TCPSocketPairTest, GetSockOptTCPInfo) {
+ auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
+ struct tcp_info info;
+ socklen_t optlen = sizeof(info);
+ ASSERT_THAT(
+ getsockopt(sockets->first_fd(), SOL_TCP, TCP_INFO, &info, &optlen),
+ SyscallSucceedsWithValue(0));
+ EXPECT_EQ(optlen, sizeof(info));
+
+ EXPECT_EQ(info.tcpi_state, TCP_ESTABLISHED);
+
+ EXPECT_GT(info.tcpi_rto, 0);
+
+ // IPv4 MSS is 536 bytes by default, and IPv6 is 1220 bytes.
+ EXPECT_GE(info.tcpi_snd_mss, 536);
+ EXPECT_GE(info.tcpi_rcv_mss, 536);
+ EXPECT_GE(info.tcpi_advmss, 536);
+
+ // MTU is typically 1500 for ethernet, but this is highly protocol
+ // dependent. Opt for a safe lower bound.
+ EXPECT_GT(info.tcpi_pmtu, 500);
+}
+
} // namespace testing
} // namespace gvisor