Add an IPC that writes to the tcp_{rmem, wmem}
The system server is controlling the tcp buffer now by writing to
/sys/kernel/ipv4/tcp_{rmem,wmem}_{min,def,max}. Those files are
basically the same as /proc/sys/net/ipv4/tcp_{rmem,wmem} except those
latter ones contain all three values in one file. Netd can directly write
to those files instead of depending on the android specific implementation.
Test: netd_integration_test
Bug: 118572798
Change-Id: I588b48be29ecf61fd5bbf94f97f63738be4eae25
diff --git a/tests/binder_test.cpp b/tests/binder_test.cpp
index 1cac36f..801226d 100644
--- a/tests/binder_test.cpp
+++ b/tests/binder_test.cpp
@@ -77,6 +77,7 @@
using android::base::StartsWith;
using android::base::StringPrintf;
using android::base::Trim;
+using android::base::WriteStringToFile;
using android::bpf::hasBpfSupport;
using android::net::INetd;
using android::net::InterfaceConfigurationParcel;
@@ -2745,3 +2746,44 @@
EXPECT_TRUE(status.isOk()) << status.exceptionMessage();
expectNatDisable();
}
+
+namespace {
+
+using TripleInt = std::array<int, 3>;
+
+TripleInt readProcFileToTripleInt(const std::string& path) {
+ std::string valueString;
+ int min, def, max;
+ EXPECT_TRUE(ReadFileToString(path, &valueString));
+ EXPECT_EQ(3, sscanf(valueString.c_str(), "%d %d %d", &min, &def, &max));
+ return {min, def, max};
+}
+
+void updateAndCheckTcpBuffer(sp<INetd>& netd, TripleInt& rmemValues, TripleInt& wmemValues) {
+ std::string testRmemValues =
+ StringPrintf("%u %u %u", rmemValues[0], rmemValues[1], rmemValues[2]);
+ std::string testWmemValues =
+ StringPrintf("%u %u %u", wmemValues[0], wmemValues[1], wmemValues[2]);
+ EXPECT_TRUE(netd->setTcpRWmemorySize(testRmemValues, testWmemValues).isOk());
+
+ TripleInt newRmemValues = readProcFileToTripleInt(TCP_RMEM_PROC_FILE);
+ TripleInt newWmemValues = readProcFileToTripleInt(TCP_WMEM_PROC_FILE);
+
+ for (int i = 0; i < 3; i++) {
+ SCOPED_TRACE(StringPrintf("tcp_mem value %d should be equal", i));
+ EXPECT_EQ(rmemValues[i], newRmemValues[i]);
+ EXPECT_EQ(wmemValues[i], newWmemValues[i]);
+ }
+}
+
+} // namespace
+
+TEST_F(BinderTest, TcpBufferSet) {
+ TripleInt rmemValue = readProcFileToTripleInt(TCP_RMEM_PROC_FILE);
+ TripleInt testRmemValue{rmemValue[0] + 42, rmemValue[1] + 42, rmemValue[2] + 42};
+ TripleInt wmemValue = readProcFileToTripleInt(TCP_WMEM_PROC_FILE);
+ TripleInt testWmemValue{wmemValue[0] + 42, wmemValue[1] + 42, wmemValue[2] + 42};
+
+ updateAndCheckTcpBuffer(mNetd, testRmemValue, testWmemValue);
+ updateAndCheckTcpBuffer(mNetd, rmemValue, wmemValue);
+}