diff options
author | Ken Chen <cken@google.com> | 2021-10-28 09:54:46 +0800 |
---|---|---|
committer | Ken Chen <cken@google.com> | 2022-01-26 08:06:34 +0800 |
commit | ebdeba8f1c64e6321f10461aa5ff1273a721b2f5 (patch) | |
tree | 0d1f60f4bc5f3783db2d80ce1bfb86df70305a23 /server/main.cpp | |
parent | 87c43762d2396e5bb637c2a1b932d3259d72e79c (diff) | |
download | netd-ebdeba8f1c64e6321f10461aa5ff1273a721b2f5.tar.gz |
[NETD-BPF#18] Mainline part of bpf code from netd
1. Add libnetd_updatable.so in com.android.tethering. The library is
loaded by netd. Currently, it mainly targets on a few functions which
access BPF maps. The functionality may extend in the future.
2. Attach gcroup progs from libnetd_updatable.so.
3. Move (privileged)TagSocket and untagSocket implementation to mainline
module. Combine privilegedTagSocket and untagSocket into a single
function.
4. Split related unit tests from netd_unit_test to
libnetd_updatable_unit_test as well.
Bug: 202086915
Test: cd system/netd; atest
Test: cd packages/modules/Connectivity/netd; atest
Change-Id: I6afe3eee0fbe7c5141bd9e1c24c756f7edc9db4f
Diffstat (limited to 'server/main.cpp')
-rw-r--r-- | server/main.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/server/main.cpp b/server/main.cpp index f462c0aa..f287665b 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -34,8 +34,8 @@ #include <binder/IPCThreadState.h> #include <binder/IServiceManager.h> -#include <bpf/WaitForProgsLoaded.h> #include <netdutils/Stopwatch.h> +#include <processgroup/processgroup.h> #include "Controllers.h" #include "FwmarkServer.h" @@ -47,6 +47,7 @@ #include "NetlinkManager.h" #include "Process.h" +#include "NetdUpdatablePublic.h" #include "netd_resolv/resolv.h" using android::IPCThreadState; @@ -85,7 +86,7 @@ void logCallback(const char* msg) { int tagSocketCallback(int sockFd, uint32_t tag, uid_t uid, pid_t) { // Workaround for secureVPN with VpnIsolation enabled, refer to b/159994981 for details. if (tag == TAG_SYSTEM_DNS) uid = AID_DNS; - return gCtls->trafficCtrl.privilegedTagSocket(sockFd, tag, uid); + return libnetd_updatable_tagSocket(sockFd, tag, uid, AID_DNS); } bool evaluateDomainNameCallback(const android_net_context&, const char* /*name*/) { @@ -123,9 +124,17 @@ int main() { gLog.info("setCloseOnExec(%s)", sock); } - // Make sure BPF programs are loaded before doing anything - android::bpf::waitForProgsLoaded(); - gLog.info("BPF programs are loaded"); + std::string cg2_path; + if (!CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, &cg2_path)) { + ALOGE("Failed to find cgroup v2 root %s", strerror(errno)); + exit(1); + } + + if (libnetd_updatable_init(cg2_path.c_str())) { + ALOGE("libnetd_updatable_init failed"); + exit(1); + } + gLog.info("libnetd_updatable_init success"); NetlinkManager *nm = NetlinkManager::Instance(); if (nm == nullptr) { |