diff options
author | aleksej <aleksej.paschenko@gmail.com> | 2019-10-27 15:14:35 +0300 |
---|---|---|
committer | aleksej <aleksej.paschenko@gmail.com> | 2019-10-27 15:28:15 +0300 |
commit | 352ae1022ce19de28fc72e034cc469872ad79d06 (patch) | |
tree | daab172474c8a917a589a2142fc66ae9cba272c3 /test/syscalls/linux | |
parent | 1c480abc39b9957606ff8bf125a5c253ad8a76cb (diff) |
Add /proc/sys/net/ipv4/ip_forward
Diffstat (limited to 'test/syscalls/linux')
-rw-r--r-- | test/syscalls/linux/proc_net.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/test/syscalls/linux/proc_net.cc b/test/syscalls/linux/proc_net.cc index 65bad06d4..897cf4950 100644 --- a/test/syscalls/linux/proc_net.cc +++ b/test/syscalls/linux/proc_net.cc @@ -326,6 +326,42 @@ TEST(ProcNetSnmp, UdpIn) { EXPECT_EQ(oldInDatagrams, newInDatagrams - 1); } +TEST(ProcSysNetIpv4IpForward, Exists) { + auto fd = + ASSERT_NO_ERRNO_AND_VALUE(Open("/proc/sys/net/ipv4/ip_forward", O_RDWR)); +} + +TEST(ProcSysNetIpv4IpForward, DefaultValueEqZero) { + auto const fd = + ASSERT_NO_ERRNO_AND_VALUE(Open("/proc/sys/net/ipv4/ip_forward", O_RDWR)); + + char buf = 101; + EXPECT_THAT(PreadFd(fd.get(), &buf, sizeof(buf), 0), + SyscallSucceedsWithValue(sizeof(buf))); + + EXPECT_TRUE(buf == '0') << "unexpected ip_forward: " << buf; +} + +TEST(ProcSysNetIpv4IpForward, CanReadAndWrite) { + auto const fd = + ASSERT_NO_ERRNO_AND_VALUE(Open("/proc/sys/net/ipv4/ip_forward", O_RDWR)); + + char buf = 101; + EXPECT_THAT(PreadFd(fd.get(), &buf, sizeof(buf), 0), + SyscallSucceedsWithValue(sizeof(buf))); + + EXPECT_TRUE(buf == '0') << "unexpected ip_forward: " << buf; + + constexpr char to_write = '1'; + EXPECT_THAT(PwriteFd(fd.get(), &to_write, sizeof(to_write), 0), + SyscallSucceedsWithValue(sizeof(to_write))); + + buf = 101; + EXPECT_THAT(PreadFd(fd.get(), &buf, sizeof(buf), 0), + SyscallSucceedsWithValue(sizeof(buf))); + EXPECT_EQ(buf, to_write); +} + } // namespace } // namespace testing } // namespace gvisor |