Merge changes from topic "configure_bpf_for_clat"
* changes: [CLATJ#20] ClatdCoordinator: stop bpf for clat [CLATJ#19] ClatdCoordinator: configure bpf for clat [CLATJ#18] libclat: move clat tc and bpf utilis from netd [CLATJ#17] bpf_connectivity_headers visible to libclat
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
|
||||
@@ -162,6 +168,23 @@ public class ClatCoordinator {
|
||||
throws IOException {
|
||||
native_configurePacketSocket(sock, v6, ifindex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maybe start bpf.
|
||||
*/
|
||||
public int maybeStartBpf(@NonNull FileDescriptor tunfd, @NonNull FileDescriptor readsock6,
|
||||
@NonNull FileDescriptor writesock6, @NonNull String iface, @NonNull String pfx96,
|
||||
@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
|
||||
@@ -304,10 +327,38 @@ public class ClatCoordinator {
|
||||
throw new IOException("configure packet socket failed: " + e);
|
||||
}
|
||||
|
||||
// [5] Maybe start bpf.
|
||||
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);
|
||||
}
|
||||
|
||||
// TODO: start clatd and returns local xlat464 v6 address.
|
||||
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,
|
||||
@@ -321,4 +372,9 @@ public class ClatCoordinator {
|
||||
int ifindex) throws IOException;
|
||||
private static native void native_configurePacketSocket(FileDescriptor sock, String v6,
|
||||
int ifindex) throws IOException;
|
||||
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