[CLATJ#13] ClatCoordinator: open raw socket

Move the raw socket initialization from netd to mainline because
mainline module is going to launch clatd. Need to provide raw
socket for writing local 464xlat IPv6 packets.

Bug: 212345928
Test: flash and boot
Run "atest ClatCoordinatorTest" in a followup commit.

Change-Id: I6d1da4f1b400eeed87771ae8197b0c58ec50804b
This commit is contained in:
Hungming Chen
2021-12-25 21:05:49 +08:00
parent 79d34befb1
commit d292f45e16
2 changed files with 42 additions and 0 deletions

View File

@@ -128,6 +128,13 @@ public class ClatCoordinator {
public int jniOpenPacketSocket() throws IOException {
return openPacketSocket();
}
/**
* Open IPv6 raw socket and set SO_MARK.
*/
public int jniOpenRawSocket6(int mark) throws IOException {
return openRawSocket6(mark);
}
}
@VisibleForTesting
@@ -241,6 +248,16 @@ public class ClatCoordinator {
throw new IOException("Open packet socket failed: " + e);
}
// Opens a raw socket with a given fwmark to send IPv6 packets in clatd.
final ParcelFileDescriptor writeSock6;
try {
// Use a JNI call to get native file descriptor instead of Os.socket(). See above
// reason why we use jniOpenPacketSocket6().
writeSock6 = mDeps.adoptFd(mDeps.jniOpenRawSocket6(fwmark));
} catch (IOException e) {
throw new IOException("Open raw socket failed: " + e);
}
// TODO: start clatd and returns local xlat464 v6 address.
return null;
}
@@ -253,4 +270,5 @@ public class ClatCoordinator {
private static native int detectMtu(String platSubnet, int platSuffix, int mark)
throws IOException;
private static native int openPacketSocket() throws IOException;
private static native int openRawSocket6(int mark) throws IOException;
}