From 79511e8a50facd509b8180d0160762b510dd6196 Mon Sep 17 00:00:00 2001 From: Rahat Mahmood Date: Thu, 1 Aug 2019 13:57:41 -0700 Subject: Implement getsockopt(TCP_INFO). Export some readily-available fields for TCP_INFO and stub out the rest. PiperOrigin-RevId: 261191548 --- test/syscalls/linux/socket_ip_tcp_generic.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'test/syscalls/linux') 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 -- cgit v1.2.3