Turn on TCP keep-alives and TFO (if possible)
Test: as follows
- built
Bug: 34953048
Bug: 63449462
Bug: 64133961
Change-Id: Ia334b6a7e18174c8605de97702e444e4fe3049d6
diff --git a/tests/benchmarks/Android.mk b/tests/benchmarks/Android.mk
index c67d40e..fdc6e7c 100644
--- a/tests/benchmarks/Android.mk
+++ b/tests/benchmarks/Android.mk
@@ -23,7 +23,7 @@
LOCAL_CFLAGS += -Wno-varargs
EXTRA_LDLIBS := -lpthread
-LOCAL_SHARED_LIBRARIES += libbase libbinder liblog libnetd_client
+LOCAL_SHARED_LIBRARIES += libbase libbinder liblog libnetd_client libnetdutils
LOCAL_STATIC_LIBRARIES += libnetd_test_dnsresponder libutils
LOCAL_AIDL_INCLUDES := system/netd/server/binder
diff --git a/tests/dns_responder/Android.mk b/tests/dns_responder/Android.mk
index e50eff5..44c8249 100644
--- a/tests/dns_responder/Android.mk
+++ b/tests/dns_responder/Android.mk
@@ -23,7 +23,14 @@
LOCAL_CFLAGS += -Wno-varargs
EXTRA_LDLIBS := -lpthread
-LOCAL_SHARED_LIBRARIES += libbase libbinder libcrypto liblog libnetd_client libssl
+LOCAL_SHARED_LIBRARIES += \
+ libbase \
+ libbinder \
+ libcrypto \
+ liblog \
+ libnetd_client \
+ libssl \
+ libnetdutils
LOCAL_STATIC_LIBRARIES += libutils
LOCAL_AIDL_INCLUDES += \
diff --git a/tests/dns_responder/dns_responder.cpp b/tests/dns_responder/dns_responder.cpp
index 6c76956..bcea9a8 100644
--- a/tests/dns_responder/dns_responder.cpp
+++ b/tests/dns_responder/dns_responder.cpp
@@ -33,6 +33,9 @@
#define LOG_TAG "DNSResponder"
#include <log/log.h>
+#include <netdutils/SocketOption.h>
+
+using android::netdutils::enableSockopt;
namespace test {
@@ -592,9 +595,8 @@
for (const addrinfo* ai = ai_res ; ai ; ai = ai->ai_next) {
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (s < 0) continue;
- const int one = 1;
- setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one));
- setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
+ enableSockopt(s, SOL_SOCKET, SO_REUSEPORT);
+ enableSockopt(s, SOL_SOCKET, SO_REUSEADDR);
if (bind(s, ai->ai_addr, ai->ai_addrlen)) {
APLOGI("bind failed for socket %d", s);
close(s);
diff --git a/tests/dns_responder/dns_tls_frontend.cpp b/tests/dns_responder/dns_tls_frontend.cpp
index 6c29353..fea04c5 100644
--- a/tests/dns_responder/dns_tls_frontend.cpp
+++ b/tests/dns_responder/dns_tls_frontend.cpp
@@ -26,11 +26,13 @@
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/ssl.h>
+#include <unistd.h>
#define LOG_TAG "DnsTlsFrontend"
#include <log/log.h>
+#include <netdutils/SocketOption.h>
-#include <unistd.h>
+using android::netdutils::enableSockopt;
namespace {
@@ -204,9 +206,8 @@
for (const addrinfo* ai = frontend_ai_res ; ai ; ai = ai->ai_next) {
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (s < 0) continue;
- const int one = 1;
- setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one));
- setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
+ enableSockopt(s, SOL_SOCKET, SO_REUSEPORT);
+ enableSockopt(s, SOL_SOCKET, SO_REUSEADDR);
if (bind(s, ai->ai_addr, ai->ai_addrlen)) {
APLOGI("bind failed for socket %d", s);
close(s);
diff --git a/tests/netd_test.cpp b/tests/netd_test.cpp
index 8d77b99..3b77833 100644
--- a/tests/netd_test.cpp
+++ b/tests/netd_test.cpp
@@ -54,11 +54,13 @@
#include "android/net/INetd.h"
#include "android/net/metrics/INetdEventListener.h"
#include "binder/IServiceManager.h"
+#include "netdutils/SocketOption.h"
using android::base::StringPrintf;
using android::base::StringAppendF;
using android::net::ResolverStats;
using android::net::metrics::INetdEventListener;
+using android::netdutils::enableSockopt;
// Emulates the behavior of UnorderedElementsAreArray, which currently cannot be used.
// TODO: Use UnorderedElementsAreArray, which depends on being able to compile libgmock_host,
@@ -788,9 +790,8 @@
.sin_port = htons(853),
};
ASSERT_TRUE(inet_pton(AF_INET, listen_addr, &tlsServer.sin_addr));
- const int one = 1;
- setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one));
- setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
+ enableSockopt(s, SOL_SOCKET, SO_REUSEPORT);
+ enableSockopt(s, SOL_SOCKET, SO_REUSEADDR);
ASSERT_FALSE(bind(s, reinterpret_cast<struct sockaddr*>(&tlsServer), sizeof(tlsServer)));
ASSERT_FALSE(listen(s, 1));