Revert "[RFCLAT#1] Move the raw socket creation from clatd to netd"
Revert submission 1902610-clat_move_raw_socket
Reason for revert: security patch (aosp/1903466) and clean up patch (aosp/1911234) have not merged yet
Reverted Changes:
I9b4ea3de7:[RFCLAT#1] Move the raw socket creation from clatd...
Ibc46981a8:[RFNETD#1] Move the raw socket creation from clatd...
Change-Id: Ic4fad13f522e06815168db4abbd047cf99956122
diff --git a/clatd.c b/clatd.c
index 4a34bf3..7ec3454 100644
--- a/clatd.c
+++ b/clatd.c
@@ -182,7 +182,19 @@
* tunnel - tun device data
* mark - the socket mark to use for the sending raw socket
*/
-void open_sockets(struct tun_data *tunnel) {
+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;
+
// 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);