Merge "remove dead portions of BpfUtils.java" into main am: bee431759a
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2803204 Change-Id: Ib920e77884fb0d1d88d45c93a84cbd19b7244484 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
committed by
Automerger Merge Worker
commit
dbf8d3025e
@@ -1538,9 +1538,9 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
/**
|
/**
|
||||||
* Get BPF program Id from CGROUP. See {@link BpfUtils#getProgramId}.
|
* Get BPF program Id from CGROUP. See {@link BpfUtils#getProgramId}.
|
||||||
*/
|
*/
|
||||||
public int getBpfProgramId(final int attachType, @NonNull final String cgroupPath)
|
public int getBpfProgramId(final int attachType)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return BpfUtils.getProgramId(attachType, cgroupPath);
|
return BpfUtils.getProgramId(attachType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -3274,15 +3274,15 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
try {
|
try {
|
||||||
pw.print("CGROUP_INET_INGRESS: ");
|
pw.print("CGROUP_INET_INGRESS: ");
|
||||||
pw.println(mDeps.getBpfProgramId(BPF_CGROUP_INET_INGRESS, BpfUtils.CGROUP_PATH));
|
pw.println(mDeps.getBpfProgramId(BPF_CGROUP_INET_INGRESS));
|
||||||
pw.print("CGROUP_INET_EGRESS: ");
|
pw.print("CGROUP_INET_EGRESS: ");
|
||||||
pw.println(mDeps.getBpfProgramId(BPF_CGROUP_INET_EGRESS, BpfUtils.CGROUP_PATH));
|
pw.println(mDeps.getBpfProgramId(BPF_CGROUP_INET_EGRESS));
|
||||||
pw.print("CGROUP_INET_SOCK_CREATE: ");
|
pw.print("CGROUP_INET_SOCK_CREATE: ");
|
||||||
pw.println(mDeps.getBpfProgramId(BPF_CGROUP_INET_SOCK_CREATE, BpfUtils.CGROUP_PATH));
|
pw.println(mDeps.getBpfProgramId(BPF_CGROUP_INET_SOCK_CREATE));
|
||||||
pw.print("CGROUP_INET4_BIND: ");
|
pw.print("CGROUP_INET4_BIND: ");
|
||||||
pw.println(mDeps.getBpfProgramId(BPF_CGROUP_INET4_BIND, BpfUtils.CGROUP_PATH));
|
pw.println(mDeps.getBpfProgramId(BPF_CGROUP_INET4_BIND));
|
||||||
pw.print("CGROUP_INET6_BIND: ");
|
pw.print("CGROUP_INET6_BIND: ");
|
||||||
pw.println(mDeps.getBpfProgramId(BPF_CGROUP_INET6_BIND, BpfUtils.CGROUP_PATH));
|
pw.println(mDeps.getBpfProgramId(BPF_CGROUP_INET6_BIND));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
pw.println(" IOException");
|
pw.println(" IOException");
|
||||||
}
|
}
|
||||||
@@ -10816,7 +10816,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// If type can't be parsed, this throws NumberFormatException, which
|
// If type can't be parsed, this throws NumberFormatException, which
|
||||||
// is passed back to adb who prints it.
|
// is passed back to adb who prints it.
|
||||||
final int type = Integer.parseInt(getNextArg());
|
final int type = Integer.parseInt(getNextArg());
|
||||||
final int ret = BpfUtils.getProgramId(type, BpfUtils.CGROUP_PATH);
|
final int ret = BpfUtils.getProgramId(type);
|
||||||
pw.println(ret);
|
pw.println(ret);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,50 +40,19 @@ public class BpfUtils {
|
|||||||
// on T+ devices as well, but this is not guaranteed.
|
// on T+ devices as well, but this is not guaranteed.
|
||||||
public static final String CGROUP_PATH = "/sys/fs/cgroup/";
|
public static final String CGROUP_PATH = "/sys/fs/cgroup/";
|
||||||
|
|
||||||
/**
|
|
||||||
* Attach BPF program to CGROUP
|
|
||||||
*/
|
|
||||||
public static void attachProgram(int type, @NonNull String programPath,
|
|
||||||
@NonNull String cgroupPath, int flags) throws IOException {
|
|
||||||
native_attachProgramToCgroup(type, programPath, cgroupPath, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Detach BPF program from CGROUP
|
|
||||||
*/
|
|
||||||
public static void detachProgram(int type, @NonNull String cgroupPath)
|
|
||||||
throws IOException {
|
|
||||||
native_detachProgramFromCgroup(type, cgroupPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get BPF program Id from CGROUP.
|
* Get BPF program Id from CGROUP.
|
||||||
*
|
*
|
||||||
* Note: This requires a 4.19 kernel which is only guaranteed on V+.
|
* Note: This requires a 4.19 kernel which is only guaranteed on V+.
|
||||||
*
|
*
|
||||||
* @param attachType Bpf attach type. See bpf_attach_type in include/uapi/linux/bpf.h.
|
* @param attachType Bpf attach type. See bpf_attach_type in include/uapi/linux/bpf.h.
|
||||||
* @param cgroupPath Path of cgroup.
|
|
||||||
* @return Positive integer for a Program Id. 0 if no program is attached.
|
* @return Positive integer for a Program Id. 0 if no program is attached.
|
||||||
* @throws IOException if failed to open the cgroup directory or query bpf program.
|
* @throws IOException if failed to open the cgroup directory or query bpf program.
|
||||||
*/
|
*/
|
||||||
public static int getProgramId(int attachType, @NonNull String cgroupPath) throws IOException {
|
public static int getProgramId(int attachType) throws IOException {
|
||||||
return native_getProgramIdFromCgroup(attachType, cgroupPath);
|
return native_getProgramIdFromCgroup(attachType, CGROUP_PATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Detach single BPF program from CGROUP
|
|
||||||
*/
|
|
||||||
public static void detachSingleProgram(int type, @NonNull String programPath,
|
|
||||||
@NonNull String cgroupPath) throws IOException {
|
|
||||||
native_detachSingleProgramFromCgroup(type, programPath, cgroupPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static native boolean native_attachProgramToCgroup(int type, String programPath,
|
|
||||||
String cgroupPath, int flags) throws IOException;
|
|
||||||
private static native boolean native_detachProgramFromCgroup(int type, String cgroupPath)
|
|
||||||
throws IOException;
|
|
||||||
private static native boolean native_detachSingleProgramFromCgroup(int type,
|
|
||||||
String programPath, String cgroupPath) throws IOException;
|
|
||||||
private static native int native_getProgramIdFromCgroup(int type, String cgroupPath)
|
private static native int native_getProgramIdFromCgroup(int type, String cgroupPath)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,86 +30,6 @@ namespace android {
|
|||||||
|
|
||||||
using base::unique_fd;
|
using base::unique_fd;
|
||||||
|
|
||||||
// If attach fails throw error and return false.
|
|
||||||
static jboolean com_android_net_module_util_BpfUtil_attachProgramToCgroup(JNIEnv *env,
|
|
||||||
jclass clazz, jint type, jstring bpfProgPath, jstring cgroupPath, jint flags) {
|
|
||||||
|
|
||||||
ScopedUtfChars dirPath(env, cgroupPath);
|
|
||||||
unique_fd cg_fd(open(dirPath.c_str(), O_DIRECTORY | O_RDONLY | O_CLOEXEC));
|
|
||||||
if (cg_fd == -1) {
|
|
||||||
jniThrowExceptionFmt(env, "java/io/IOException",
|
|
||||||
"Failed to open the cgroup directory %s: %s",
|
|
||||||
dirPath.c_str(), strerror(errno));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedUtfChars bpfProg(env, bpfProgPath);
|
|
||||||
unique_fd bpf_fd(bpf::retrieveProgram(bpfProg.c_str()));
|
|
||||||
if (bpf_fd == -1) {
|
|
||||||
jniThrowExceptionFmt(env, "java/io/IOException",
|
|
||||||
"Failed to retrieve bpf program from %s: %s",
|
|
||||||
bpfProg.c_str(), strerror(errno));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (bpf::attachProgram((bpf_attach_type) type, bpf_fd, cg_fd, flags)) {
|
|
||||||
jniThrowExceptionFmt(env, "java/io/IOException",
|
|
||||||
"Failed to attach bpf program %s to %s: %s",
|
|
||||||
bpfProg.c_str(), dirPath.c_str(), strerror(errno));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If detach fails throw error and return false.
|
|
||||||
static jboolean com_android_net_module_util_BpfUtil_detachProgramFromCgroup(JNIEnv *env,
|
|
||||||
jclass clazz, jint type, jstring cgroupPath) {
|
|
||||||
|
|
||||||
ScopedUtfChars dirPath(env, cgroupPath);
|
|
||||||
unique_fd cg_fd(open(dirPath.c_str(), O_DIRECTORY | O_RDONLY | O_CLOEXEC));
|
|
||||||
if (cg_fd == -1) {
|
|
||||||
jniThrowExceptionFmt(env, "java/io/IOException",
|
|
||||||
"Failed to open the cgroup directory %s: %s",
|
|
||||||
dirPath.c_str(), strerror(errno));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bpf::detachProgram((bpf_attach_type) type, cg_fd)) {
|
|
||||||
jniThrowExceptionFmt(env, "Failed to detach bpf program from %s: %s",
|
|
||||||
dirPath.c_str(), strerror(errno));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If detach single program fails throw error and return false.
|
|
||||||
static jboolean com_android_net_module_util_BpfUtil_detachSingleProgramFromCgroup(JNIEnv *env,
|
|
||||||
jclass clazz, jint type, jstring bpfProgPath, jstring cgroupPath) {
|
|
||||||
|
|
||||||
ScopedUtfChars dirPath(env, cgroupPath);
|
|
||||||
unique_fd cg_fd(open(dirPath.c_str(), O_DIRECTORY | O_RDONLY | O_CLOEXEC));
|
|
||||||
if (cg_fd == -1) {
|
|
||||||
jniThrowExceptionFmt(env, "java/io/IOException",
|
|
||||||
"Failed to open the cgroup directory %s: %s",
|
|
||||||
dirPath.c_str(), strerror(errno));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
ScopedUtfChars bpfProg(env, bpfProgPath);
|
|
||||||
unique_fd bpf_fd(bpf::retrieveProgram(bpfProg.c_str()));
|
|
||||||
if (bpf_fd == -1) {
|
|
||||||
jniThrowExceptionFmt(env, "java/io/IOException",
|
|
||||||
"Failed to retrieve bpf program from %s: %s",
|
|
||||||
bpfProg.c_str(), strerror(errno));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (bpf::detachSingleProgram((bpf_attach_type) type, bpf_fd, cg_fd)) {
|
|
||||||
jniThrowExceptionFmt(env, "Failed to detach bpf program %s from %s: %s",
|
|
||||||
bpfProg.c_str(), dirPath.c_str(), strerror(errno));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static jint com_android_net_module_util_BpfUtil_getProgramIdFromCgroup(JNIEnv *env,
|
static jint com_android_net_module_util_BpfUtil_getProgramIdFromCgroup(JNIEnv *env,
|
||||||
jclass clazz, jint type, jstring cgroupPath) {
|
jclass clazz, jint type, jstring cgroupPath) {
|
||||||
|
|
||||||
@@ -138,12 +58,6 @@ static jint com_android_net_module_util_BpfUtil_getProgramIdFromCgroup(JNIEnv *e
|
|||||||
*/
|
*/
|
||||||
static const JNINativeMethod gMethods[] = {
|
static const JNINativeMethod gMethods[] = {
|
||||||
/* name, signature, funcPtr */
|
/* name, signature, funcPtr */
|
||||||
{ "native_attachProgramToCgroup", "(ILjava/lang/String;Ljava/lang/String;I)Z",
|
|
||||||
(void*) com_android_net_module_util_BpfUtil_attachProgramToCgroup },
|
|
||||||
{ "native_detachProgramFromCgroup", "(ILjava/lang/String;)Z",
|
|
||||||
(void*) com_android_net_module_util_BpfUtil_detachProgramFromCgroup },
|
|
||||||
{ "native_detachSingleProgramFromCgroup", "(ILjava/lang/String;Ljava/lang/String;)Z",
|
|
||||||
(void*) com_android_net_module_util_BpfUtil_detachSingleProgramFromCgroup },
|
|
||||||
{ "native_getProgramIdFromCgroup", "(ILjava/lang/String;)I",
|
{ "native_getProgramIdFromCgroup", "(ILjava/lang/String;)I",
|
||||||
(void*) com_android_net_module_util_BpfUtil_getProgramIdFromCgroup },
|
(void*) com_android_net_module_util_BpfUtil_getProgramIdFromCgroup },
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2299,7 +2299,7 @@ public class ConnectivityServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getBpfProgramId(final int attachType, @NonNull final String cgroupPath) {
|
public int getBpfProgramId(final int attachType) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user