[CLATJ#20] ClatdCoordinator: stop bpf for clat
Remove eBPF offload at clat stopping if possible. Bug: 212345928 Test: build only because need to test with clatd launched Change-Id: I6ace77694c0e6fe68d16e80e3c8198aa41385fd2
This commit is contained in:
@@ -74,6 +74,12 @@ public class ClatCoordinator {
|
||||
private final Dependencies mDeps;
|
||||
@Nullable
|
||||
private String mIface = null;
|
||||
@Nullable
|
||||
private String mNat64Prefix = null;
|
||||
@Nullable
|
||||
private String mXlatLocalAddress4 = null;
|
||||
@Nullable
|
||||
private String mXlatLocalAddress6 = null;
|
||||
private int mPid = INVALID_PID;
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -171,6 +177,14 @@ public class ClatCoordinator {
|
||||
@NonNull String v4, @NonNull String v6) throws IOException {
|
||||
return native_maybeStartBpf(tunfd, readsock6, writesock6, iface, pfx96, v4, v6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe stop bpf.
|
||||
*/
|
||||
public void maybeStopBpf(String iface, String pfx96, String v4, String v6, int pid)
|
||||
throws IOException {
|
||||
native_maybeStopBpf(iface, pfx96, v4, v6, pid);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -317,6 +331,10 @@ public class ClatCoordinator {
|
||||
try {
|
||||
mDeps.maybeStartBpf(tunFd.getFileDescriptor(), readSock6.getFileDescriptor(),
|
||||
writeSock6.getFileDescriptor(), iface, pfx96, v4, v6);
|
||||
mIface = iface;
|
||||
mNat64Prefix = pfx96;
|
||||
mXlatLocalAddress4 = v4;
|
||||
mXlatLocalAddress6 = v6;
|
||||
} catch (IOException e) {
|
||||
throw new IOException("Error start bpf on " + iface + ": " + e);
|
||||
}
|
||||
@@ -325,6 +343,22 @@ public class ClatCoordinator {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop clatd
|
||||
*/
|
||||
public void clatStop() throws IOException {
|
||||
mDeps.maybeStopBpf(mIface, mNat64Prefix, mXlatLocalAddress4, mXlatLocalAddress6,
|
||||
mPid /* unused */);
|
||||
// TODO: remove setIptablesDropRule
|
||||
|
||||
Log.i(TAG, "clatd on " + mIface + " stopped");
|
||||
|
||||
mIface = null;
|
||||
mNat64Prefix = null;
|
||||
mXlatLocalAddress4 = null;
|
||||
mXlatLocalAddress6 = null;
|
||||
}
|
||||
|
||||
private static native String native_selectIpv4Address(String v4addr, int prefixlen)
|
||||
throws IOException;
|
||||
private static native String native_generateIpv6Address(String iface, String v4,
|
||||
@@ -341,4 +375,6 @@ public class ClatCoordinator {
|
||||
private static native int native_maybeStartBpf(FileDescriptor tunfd, FileDescriptor readsock6,
|
||||
FileDescriptor writesock6, String iface, String pfx96, String v4, String v6)
|
||||
throws IOException;
|
||||
private static native void native_maybeStopBpf(String iface, String pfx96, String v4,
|
||||
String v6, int pid) throws IOException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user