From 732a14164fbfa417b433cc7f6545b5542dcfa523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Thu, 14 Mar 2024 00:17:18 -0700 Subject: [PATCH] NetBpfLoad: rework mainline bpf execution codepath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (for now for better testing we don't make V special) Test: TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: Id2835bd393c0ec9e1710644681bc5aab0d7d2aae --- netbpfload/NetBpfLoad.cpp | 25 ++++++++--------- netbpfload/netbpfload.mainline.rc | 10 ++++++- netd/BpfHandler.cpp | 27 +++++++++++++++++++ ...id_server_connectivity_ClatCoordinator.cpp | 7 ++++- 4 files changed, 55 insertions(+), 14 deletions(-) diff --git a/netbpfload/NetBpfLoad.cpp b/netbpfload/NetBpfLoad.cpp index 9651a3b29c..83bb98c875 100644 --- a/netbpfload/NetBpfLoad.cpp +++ b/netbpfload/NetBpfLoad.cpp @@ -257,12 +257,6 @@ int main(int argc, char** argv, char * const envp[]) { logTetheringApexVersion(); - if (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 - } - if (!isAtLeastT) { ALOGE("Impossible - not reachable on Android 60) delay = 60; + if (base::WaitForProperty("init.svc.bpfloader", "stopped", std::chrono::seconds(delay)) + && !access("/sys/fs/bpf/netd_shared", F_OK)) + return; + ALOGW("Waited %ds for init.svc.bpfloader=stopped, still waiting...", delay); + } +} + Status BpfHandler::init(const char* cg2_path) { // Make sure BPF programs are loaded before doing anything + ALOGI("Waiting for BPF programs"); + + if (true || !modules::sdklevel::IsAtLeastV()) { + waitForNetProgsLoaded(); + ALOGI("Networking BPF programs are loaded"); + + if (!base::SetProperty("ctl.start", "mdnsd_loadbpf")) { + ALOGE("Failed to set property ctl.start=mdnsd_loadbpf, see dmesg for reason."); + abort(); + } + + ALOGI("Waiting for remaining BPF programs"); + } + android::bpf::waitForProgsLoaded(); ALOGI("BPF programs are loaded"); diff --git a/service/jni/com_android_server_connectivity_ClatCoordinator.cpp b/service/jni/com_android_server_connectivity_ClatCoordinator.cpp index c125bd6479..4214bc9a15 100644 --- a/service/jni/com_android_server_connectivity_ClatCoordinator.cpp +++ b/service/jni/com_android_server_connectivity_ClatCoordinator.cpp @@ -113,7 +113,12 @@ static void verifyClatPerms() { if (!modules::sdklevel::IsAtLeastT()) return; V("/sys/fs/bpf", S_IFDIR|S_ISVTX|0777, ROOT, ROOT, "fs_bpf", DIR); - V("/sys/fs/bpf/net_shared", S_IFDIR|S_ISVTX|0777, ROOT, ROOT, "fs_bpf_net_shared", DIR); + + if (false && modules::sdklevel::IsAtLeastV()) { + V("/sys/fs/bpf/net_shared", S_IFDIR|01777, ROOT, ROOT, "fs_bpf_net_shared", DIR); + } else { + V("/sys/fs/bpf/net_shared", S_IFDIR|01777, SYSTEM, SYSTEM, "fs_bpf_net_shared", DIR); + } // pre-U we do not have selinux privs to getattr on bpf maps/progs // so while the below *should* be as listed, we have no way to actually verify