Skip to content

Commit

Permalink
syscalls: minor refactor, adding coverage (envoyproxy#36075)
Browse files Browse the repository at this point in the history
minor refactor no longer fast-failing if the system can't create
sockets.

Risk Level: low
Testing: added tests, manually tested fd failure
Docs Changes: n/a
Release Notes: n/a

---------

Signed-off-by: Fredy Wijaya <fredyw@google.com>
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Co-authored-by: Fredy Wijaya <fredyw@google.com>
  • Loading branch information
alyssawilk and fredyw authored Sep 18, 2024
1 parent 88543c9 commit c9ae398
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
13 changes: 2 additions & 11 deletions source/common/api/posix/os_sys_calls_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,6 @@ bool OsSysCallsImpl::supportsUdpGro() const {
#else
static const bool is_supported = [] {
int fd = ::socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP);
if (fd < 0) {
return false;
}
int val = 1;
bool result = (0 == ::setsockopt(fd, IPPROTO_UDP, UDP_GRO, &val, sizeof(val)));
::close(fd);
Expand All @@ -127,9 +124,6 @@ bool OsSysCallsImpl::supportsUdpGso() const {
#else
static const bool is_supported = [] {
int fd = ::socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP);
if (fd < 0) {
return false;
}
int optval;
socklen_t optlen = sizeof(optval);
bool result = (0 <= ::getsockopt(fd, IPPROTO_UDP, UDP_SEGMENT, &optval, &optlen));
Expand Down Expand Up @@ -160,9 +154,6 @@ bool OsSysCallsImpl::supportsIpTransparent(Network::Address::IpVersion ip_versio
static constexpr auto transparent_supported = [](int family) {
auto opt_tp = family == AF_INET ? ENVOY_SOCKET_IP_TRANSPARENT : ENVOY_SOCKET_IPV6_TRANSPARENT;
int fd = ::socket(family, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP);
if (fd < 0) {
return false;
}
int val = 1;
bool result = (0 == ::setsockopt(fd, opt_tp.level(), opt_tp.option(), &val, sizeof(val)));
::close(fd);
Expand Down Expand Up @@ -348,9 +339,9 @@ SysCallBoolResult OsSysCallsImpl::socketTcpInfo([[maybe_unused]] os_fd_t sockfd,
tcp_info->tcpi_snd_cwnd = unix_tcp_info.tcpi_snd_cwnd * mss;
}
return {!SOCKET_FAILURE(result), !SOCKET_FAILURE(result) ? 0 : errno};
#endif

#else
return {false, EOPNOTSUPP};
#endif
}

bool OsSysCallsImpl::supportsGetifaddrs() const { return true; }
Expand Down
15 changes: 15 additions & 0 deletions test/common/api/os_sys_calls_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,19 @@ TEST(OsSyscallsTest, OpenPwritePreadFstatCloseStatUnlink) {
TestEnvironment::removePath(path);
}

TEST(OsSyscallsTest, SupportsIpTransparent) {
bool supported = Api::OsSysCallsSingleton::get().supportsIpTransparent(
TestEnvironment::getIpVersionsForTest()[0]);
EXPECT_FALSE(supported);
}

TEST(OsSyscallsTest, SupportsMptcp) {
bool supported = Api::OsSysCallsSingleton::get().supportsMptcp();
EXPECT_TRUE(supported);
}

TEST(OsSyscallsTest, IoCtlInvalidFd) {
EXPECT_NE(0, Api::OsSysCallsSingleton::get().ioctl(0, 0, nullptr, 0, nullptr, 0, nullptr).errno_);
}

} // namespace Envoy
2 changes: 0 additions & 2 deletions test/per_file_coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
# for existing directories with low coverage.
declare -a KNOWN_LOW_COVERAGE=(
"source/common:96.2"
"source/common/api:84.5" # flaky due to posix: be careful adjusting
"source/common/api/posix:83.8" # flaky (accept failover non-deterministic): be careful adjusting
"source/common/common/posix:96.2" # flaky due to posix: be careful adjusting
"source/common/config:96.1"
"source/common/crypto:95.5"
Expand Down

0 comments on commit c9ae398

Please sign in to comment.