From 24602949746ccf56f0ec6efca7732812020b5343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Wed, 8 Mar 2023 03:24:41 +0000 Subject: [PATCH] clat: use AF_PACKET/SOCK_RAW not SOCK_DGRAM sockets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This switches incoming packets from L3 to L2, ie. they now include the ethernet header for non-rawip cases (like wifi) Note: depends on userspace clatd change to offset packet processing index by tpacket_auxdata->tp_net L3 header offset, an increase in the read buffer size, and on change to use IPv6 header relative cBPF for ingress packet filtering! Test: TreeHugger, atest libclat_test, ping 1.1.1.1 on v6-only wifi Bug: 265591307 Signed-off-by: Maciej Żenczykowski Change-Id: Ie5893d18b0dd796751f95150680a0d4cd5f64c3c --- service/jni/com_android_server_connectivity_ClatCoordinator.cpp | 2 +- service/native/libs/libclat/clatutils_test.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/service/jni/com_android_server_connectivity_ClatCoordinator.cpp b/service/jni/com_android_server_connectivity_ClatCoordinator.cpp index 5b42659734..dae45f31c3 100644 --- a/service/jni/com_android_server_connectivity_ClatCoordinator.cpp +++ b/service/jni/com_android_server_connectivity_ClatCoordinator.cpp @@ -177,7 +177,7 @@ static jint com_android_server_connectivity_ClatCoordinator_openPacketSocket(JNI jobject clazz) { // Will eventually be bound to htons(ETH_P_IPV6) protocol, // but only after appropriate bpf filter is attached. - int sock = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, 0); + const int sock = socket(AF_PACKET, SOCK_RAW | SOCK_CLOEXEC, 0); if (sock < 0) { throwIOException(env, "packet socket failed", errno); return -1; diff --git a/service/native/libs/libclat/clatutils_test.cpp b/service/native/libs/libclat/clatutils_test.cpp index abd4e81f8f..f4f97dbdf9 100644 --- a/service/native/libs/libclat/clatutils_test.cpp +++ b/service/native/libs/libclat/clatutils_test.cpp @@ -165,7 +165,7 @@ TEST_F(ClatUtils, ConfigurePacketSocket) { TunInterface v6Iface; ASSERT_EQ(0, v6Iface.init()); - int s = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IPV6)); + const int s = socket(AF_PACKET, SOCK_RAW | SOCK_CLOEXEC, htons(ETH_P_IPV6)); EXPECT_LE(0, s); struct in6_addr addr6; EXPECT_EQ(1, inet_pton(AF_INET6, "2001:db8::f00", &addr6));