[CLATJ#15] ClatCoordinator: add socket filter to packet socket
Update our packet socket filter to reflect the new 464xlat IP address Bug: 212345928 Test: flash and boot Run "atest ClatCoordinatorTest" in a followup commit Change-Id: Ic50dc122731f311ad00ab8bff5472cb3bc41f5f1
This commit is contained in:
@@ -209,6 +209,30 @@ static void com_android_server_connectivity_ClatCoordinator_addAnycastSetsockopt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void com_android_server_connectivity_ClatCoordinator_configurePacketSocket(
|
||||||
|
JNIEnv* env, jobject clazz, jobject javaFd, jstring addr6, jint ifindex) {
|
||||||
|
ScopedUtfChars addrStr(env, addr6);
|
||||||
|
|
||||||
|
int sock = netjniutils::GetNativeFileDescriptor(env, javaFd);
|
||||||
|
if (sock < 0) {
|
||||||
|
jniThrowExceptionFmt(env, "java/io/IOException", "Invalid file descriptor");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
in6_addr addr;
|
||||||
|
if (inet_pton(AF_INET6, addrStr.c_str(), &addr) != 1) {
|
||||||
|
jniThrowExceptionFmt(env, "java/io/IOException", "Invalid IPv6 address %s",
|
||||||
|
addrStr.c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = net::clat::configure_packet_socket(sock, &addr, ifindex);
|
||||||
|
if (ret < 0) {
|
||||||
|
throwIOException(env, "configure packet socket failed", -ret);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* JNI registration.
|
* JNI registration.
|
||||||
*/
|
*/
|
||||||
@@ -229,6 +253,8 @@ static const JNINativeMethod gMethods[] = {
|
|||||||
(void*)com_android_server_connectivity_ClatCoordinator_openRawSocket6},
|
(void*)com_android_server_connectivity_ClatCoordinator_openRawSocket6},
|
||||||
{"addAnycastSetsockopt", "(Ljava/io/FileDescriptor;Ljava/lang/String;I)V",
|
{"addAnycastSetsockopt", "(Ljava/io/FileDescriptor;Ljava/lang/String;I)V",
|
||||||
(void*)com_android_server_connectivity_ClatCoordinator_addAnycastSetsockopt},
|
(void*)com_android_server_connectivity_ClatCoordinator_addAnycastSetsockopt},
|
||||||
|
{"configurePacketSocket", "(Ljava/io/FileDescriptor;Ljava/lang/String;I)V",
|
||||||
|
(void*)com_android_server_connectivity_ClatCoordinator_configurePacketSocket},
|
||||||
};
|
};
|
||||||
|
|
||||||
int register_android_server_connectivity_ClatCoordinator(JNIEnv* env) {
|
int register_android_server_connectivity_ClatCoordinator(JNIEnv* env) {
|
||||||
|
|||||||
@@ -154,6 +154,14 @@ public class ClatCoordinator {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
addAnycastSetsockopt(sock, v6, ifindex);
|
addAnycastSetsockopt(sock, v6, ifindex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configure packet socket.
|
||||||
|
*/
|
||||||
|
public void jniConfigurePacketSocket(@NonNull FileDescriptor sock, String v6, int ifindex)
|
||||||
|
throws IOException {
|
||||||
|
configurePacketSocket(sock, v6, ifindex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -289,6 +297,13 @@ public class ClatCoordinator {
|
|||||||
throw new IOException("add anycast sockopt failed: " + e);
|
throw new IOException("add anycast sockopt failed: " + e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update our packet socket filter to reflect the new 464xlat IP address.
|
||||||
|
try {
|
||||||
|
mDeps.jniConfigurePacketSocket(readSock6.getFileDescriptor(), v6, ifaceIndex);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IOException("configure packet socket failed: " + e);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: start clatd and returns local xlat464 v6 address.
|
// TODO: start clatd and returns local xlat464 v6 address.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -304,4 +319,6 @@ public class ClatCoordinator {
|
|||||||
private static native int openRawSocket6(int mark) throws IOException;
|
private static native int openRawSocket6(int mark) throws IOException;
|
||||||
private static native void addAnycastSetsockopt(FileDescriptor sock, String v6, int ifindex)
|
private static native void addAnycastSetsockopt(FileDescriptor sock, String v6, int ifindex)
|
||||||
throws IOException;
|
throws IOException;
|
||||||
|
private static native void configurePacketSocket(FileDescriptor sock, String v6, int ifindex)
|
||||||
|
throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user