[RFCLAT#1] Move the raw socket creation from clatd to netd
This is a preparation for reducing the clatd required capability.
Function change:
Opening raw socket in open_sockets() is moved to ClatdController
Argument change:
-w [write socket file descriptor number] (added)
Test: manual test
1. Connect to ipv6-only wifi.
2. Try a IPv4 traffic.
$ ping 8.8.8.8
Change-Id: I9b4ea3de76dffd98cbab37c4091ad1a7e688dbc2
diff --git a/clatd.c b/clatd.c
index 7ec3454..4a34bf3 100644
--- a/clatd.c
+++ b/clatd.c
@@ -182,19 +182,7 @@
* tunnel - tun device data
* mark - the socket mark to use for the sending raw socket
*/
-void open_sockets(struct tun_data *tunnel, uint32_t mark) {
- int rawsock = socket(AF_INET6, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, IPPROTO_RAW);
- if (rawsock < 0) {
- logmsg(ANDROID_LOG_FATAL, "raw socket failed: %s", strerror(errno));
- exit(1);
- }
-
- if (mark != MARK_UNSET && setsockopt(rawsock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)) < 0) {
- logmsg(ANDROID_LOG_ERROR, "could not set mark on raw socket: %s", strerror(errno));
- }
-
- tunnel->write_fd6 = rawsock;
-
+void open_sockets(struct tun_data *tunnel) {
// Will eventually be bound to htons(ETH_P_IPV6) protocol,
// but only after appropriate bpf filter is attached.
tunnel->read_fd6 = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, 0);