From 03ef12cc799aed7bec3cde3a260b797632b087a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Sat, 10 Feb 2024 21:34:22 +0000 Subject: [PATCH] netbpfload: enable on U QPR2 (aka 24Q1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (this will land in M-2024-05 ie. May mainline tethering module) Test: TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: I250b691eb03751da05ce10d41d6721f4964dd1d5 --- netbpfload/Android.bp | 9 ++++----- netbpfload/NetBpfLoad.cpp | 30 ++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/netbpfload/Android.bp b/netbpfload/Android.bp index b5e4722ece..b71890ebd2 100644 --- a/netbpfload/Android.bp +++ b/netbpfload/Android.bp @@ -44,7 +44,7 @@ cc_binary { "com.android.tethering", "//apex_available:platform", ], - // really should be Android 14/U (34), but we cannot include binaries built + // really should be Android 13/T (33), but we cannot include binaries built // against newer sdk in the apex, which still targets 30(R): // module "netbpfload" variant "android_x86_apex30": should support // min_sdk_version(30) for "com.android.tethering": newer SDK(34). @@ -54,15 +54,14 @@ cc_binary { required: ["bpfloader"], } -// Versioned netbpfload init rc: init system will process it only on api V/35+ devices -// (TODO: consider reducing to T/33+ - adjust the comment up above in line 43 as well) -// Note: S[31] Sv2[32] T[33] U[34] V[35]) +// Versioned netbpfload init rc: init system will process it only on api T/33+ devices +// Note: R[30] S[31] Sv2[32] T[33] U[34] V[35]) // // For details of versioned rc files see: // https://android.googlesource.com/platform/system/core/+/HEAD/init/README.md#versioned-rc-files-within-apexs prebuilt_etc { name: "netbpfload.mainline.rc", src: "netbpfload.mainline.rc", - filename: "netbpfload.35rc", + filename: "netbpfload.33rc", installable: false, } diff --git a/netbpfload/NetBpfLoad.cpp b/netbpfload/NetBpfLoad.cpp index 3c5e4c30d0..2d8867e216 100644 --- a/netbpfload/NetBpfLoad.cpp +++ b/netbpfload/NetBpfLoad.cpp @@ -243,9 +243,15 @@ int main(int argc, char** argv, char * const envp[]) { const bool isAtLeastU = (device_api_level >= __ANDROID_API_U__); const bool isAtLeastV = (device_api_level >= __ANDROID_API_V__); - ALOGI("NetBpfLoad api:%d/%d kver:%07x platform:%d mainline:%d", + // last in U QPR2 beta1 + const bool has_platform_bpfloader_rc = exists("/system/etc/init/bpfloader.rc"); + // first in U QPR2 beta~2 + const bool has_platform_netbpfload_rc = exists("/system/etc/init/netbpfload.rc"); + + ALOGI("NetBpfLoad api:%d/%d kver:%07x platform:%d mainline:%d rc:%d%d", android_get_application_target_sdk_version(), device_api_level, - android::bpf::kernelVersion(), is_platform, is_mainline); + android::bpf::kernelVersion(), is_platform, is_mainline, + has_platform_bpfloader_rc, has_platform_netbpfload_rc); if (!is_platform && !is_mainline) { ALOGE("Unable to determine if we're platform or mainline netbpfload."); @@ -258,8 +264,28 @@ int main(int argc, char** argv, char * const envp[]) { ALOGW("exec '%s' fail: %d[%s]", apexNetBpfLoad, errno, strerror(errno)); } + if (!has_platform_bpfloader_rc && !has_platform_netbpfload_rc) { + ALOGE("Unable to find platform's bpfloader & netbpfload init scripts."); + return 1; + } + + if (has_platform_bpfloader_rc && has_platform_netbpfload_rc) { + ALOGE("Platform has *both* bpfloader & netbpfload init scripts."); + return 1; + } + logTetheringApexVersion(); + if (is_mainline && has_platform_bpfloader_rc && !has_platform_netbpfload_rc) { + // Tethering apex shipped initrc file causes us to reach here + // but we're not ready to correctly handle anything before U QPR2 + // in which the 'bpfloader' vs 'netbpfload' split happened + const char * args[] = { platformBpfLoader, NULL, }; + execve(args[0], (char**)args, envp); + ALOGE("exec '%s' fail: %d[%s]", platformBpfLoader, errno, strerror(errno)); + return 1; + } + if (isAtLeastT && !android::bpf::isAtLeastKernelVersion(4, 9, 0)) { ALOGE("Android T requires kernel 4.9."); return 1;