Merge "remove BpfNetMaps.cpp" into main

This commit is contained in:
Maciej Żenczykowski 2023-11-09 03:04:22 +00:00 • committed by Gerrit Code Review
commit 73943e8eaa
4 changed files with 20 additions and 55 deletions

View file

@ -114,7 +114,6 @@ cc_library_shared {
],
srcs: [
":services.connectivity-netstats-jni-sources",
"jni/com_android_server_BpfNetMaps.cpp",
"jni/com_android_server_connectivity_ClatCoordinator.cpp",
"jni/com_android_server_ServiceManagerWrapper.cpp",
"jni/com_android_server_TestNetworkService.cpp",

View file

@ -1,44 +0,0 @@
/*
* Copyright (C) 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "bpf/BpfUtils.h"
#include <jni.h>
#include <nativehelper/JNIHelp.h>
namespace android {
static jint native_synchronizeKernelRCU(JNIEnv* env, jobject self) {
return -bpf::synchronizeKernelRCU();
}
/*
* JNI registration.
*/
// clang-format off
static const JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
{"native_synchronizeKernelRCU", "()I",
(void*)native_synchronizeKernelRCU},
};
// clang-format on
int register_com_android_server_BpfNetMaps(JNIEnv* env) {
return jniRegisterNativeMethods(env, "android/net/connectivity/com/android/server/BpfNetMaps",
gMethods, NELEM(gMethods));
}
}; // namespace android

View file

@ -22,7 +22,6 @@
namespace android {
int register_com_android_server_TestNetworkService(JNIEnv* env);
int register_com_android_server_BpfNetMaps(JNIEnv* env);
int register_com_android_server_connectivity_ClatCoordinator(JNIEnv* env);
int register_android_server_net_NetworkStatsFactory(JNIEnv* env);
int register_android_server_net_NetworkStatsService(JNIEnv* env);
@ -44,10 +43,6 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void*) {
}
if (android::modules::sdklevel::IsAtLeastT()) {
if (register_com_android_server_BpfNetMaps(env) < 0) {
return JNI_ERR;
}
if (register_com_android_server_connectivity_ClatCoordinator(env) < 0) {
return JNI_ERR;
}

View file

@ -45,6 +45,8 @@ import static android.system.OsConstants.EINVAL;
import static android.system.OsConstants.ENODEV;
import static android.system.OsConstants.ENOENT;
import static android.system.OsConstants.EOPNOTSUPP;
import static android.system.OsConstants.SOCK_RAW;
import static android.system.OsConstants.SOCK_CLOEXEC;
import static com.android.server.ConnectivityStatsLog.NETWORK_BPF_MAP_INFO;
@ -324,10 +326,26 @@ public class BpfNetMaps {
}
/**
* Call synchronize_rcu()
* Synchronously call in to kernel to synchronize_rcu()
*/
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
public int synchronizeKernelRCU() {
return native_synchronizeKernelRCU();
// See p/m/C's staticlibs/native/bpf_headers/include/bpf/BpfUtils.h
// for equivalent C implementation of this function.
try {
// When closing socket, kernel calls synchronize_rcu()
// from pf_key's sock_release().
// Constants from //bionic/libc/include/sys/socket.h: AF_KEY=15
// and kernel's include/uapi/linux/pfkeyv2.h: PF_KEY_V2=2
Os.close(Os.socket(15 /*PF_KEY*/, SOCK_RAW | SOCK_CLOEXEC, 2));
} catch (ErrnoException e) {
// socket() can only fail due to lack of privs (selinux) or OOM,
// close() always succeeds, but may return a pending error,
// however on a freshly opened socket that cannot happen.
// As such this failing is basically a build configuration error.
return -e.errno;
}
return 0;
}
/**
@ -1061,7 +1079,4 @@ public class BpfNetMaps {
pw.decreaseIndent();
}
}
@RequiresApi(Build.VERSION_CODES.TIRAMISU)
private static native int native_synchronizeKernelRCU();
}