[CLATJ#19] ClatdCoordinator: configure bpf for clat

Configure eBPF offload at clat starting if possible.

Bug: 212345928
Test: connect to ipv6 only network and check bpf entries
$adb shell dumpsys netd --short | grep Clat -A10
  ClatdController
    Trackers: iif[iface] nat64Prefix v6Addr -> v4Addr v4iif[v4iface] [fwmark]
    BPF ingress map: iif(iface) nat64Prefix v6Addr -> v4Addr oif(iface)
      47(wlan0) 64:ff9b::/96 2a00:79e1:abc:6f02:b7aa:ff3c:9220:595c -> 192.0.0.4 52(v4-wlan0)
    BPF egress map: iif(iface) v4Addr -> v6Addr nat64Prefix oif(iface)
      52(v4-wlan0) 192.0.0.4 -> 2a00:79e1:abc:6f02:b7aa:ff3c:9220:595c 64:ff9b::/96 47(wlan0) ether

Change-Id: I8ff77a2e3e86bfe6dbf43f4181414e444ba0da32
This commit is contained in:
Hungming Chen
2022-01-16 14:47:52 +08:00
parent 8ebdb6f1fe
commit b1d3ccbeb6
3 changed files with 91 additions and 0 deletions

View File

@@ -162,6 +162,15 @@ 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);
}
}
@VisibleForTesting
@@ -304,6 +313,14 @@ 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);
} catch (IOException e) {
throw new IOException("Error start bpf on " + iface + ": " + e);
}
// TODO: start clatd and returns local xlat464 v6 address.
return null;
}
@@ -321,4 +338,7 @@ 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;
}