From 8addcc0f6360cc3762e9ef27437ded250e785da3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Mon, 8 Apr 2019 17:46:48 -0700 Subject: clatd: change to pass in tun filedescriptor via command line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test: atest clatd_test, built and installed on aosp_blueline device connected to ipv6-only wifi network: ping 8.8.8.8 still works and it is via v4-wlan0 clat tun interface Bug: 65674744 Bug: 131268436 Signed-off-by: Maciej Żenczykowski Change-Id: I8c9e235e9a5bf1a1436e8dc3af8d0aa86f6dc1a5 Merged-In: I8c9e235e9a5bf1a1436e8dc3af8d0aa86f6dc1a5 (cherry picked from commit 716518d9b9ca52182498b1d7ed0f0ed8ab42cbe1) --- tun.c | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) (limited to 'tun.c') diff --git a/tun.c b/tun.c index 7ecbf2c..e2f1342 100644 --- a/tun.c +++ b/tun.c @@ -21,20 +21,19 @@ #include #include #include -#include #include #include "common.h" /* function: tun_open - * tries to open the tunnel device + * tries to open the tunnel device in non-blocking mode */ int tun_open() { int fd; - fd = open("/dev/tun", O_RDWR | O_CLOEXEC); + fd = open("/dev/tun", O_RDWR | O_NONBLOCK | O_CLOEXEC); if (fd < 0) { - fd = open("/dev/net/tun", O_RDWR | O_CLOEXEC); + fd = open("/dev/net/tun", O_RDWR | O_NONBLOCK | O_CLOEXEC); } return fd; @@ -65,25 +64,3 @@ int tun_alloc(char *dev, int fd, size_t len) { strlcpy(dev, ifr.ifr_name, len); return 0; } - -/* function: set_nonblocking - * sets a filedescriptor to non-blocking mode - * fd - the filedescriptor - * returns: 0 on success, -1 on failure - */ -int set_nonblocking(int fd) { - int flags = fcntl(fd, F_GETFL); - if (flags == -1) { - return flags; - } - return fcntl(fd, F_SETFL, flags | O_NONBLOCK); -} - -/* function: send_tun - * sends a clat_packet to a tun interface - * fd - the tun filedescriptor - * out - the packet to send - * iov_len - the number of entries in the clat_packet - * returns: number of bytes read on success, -1 on failure - */ -int send_tun(int fd, clat_packet out, int iov_len) { return writev(fd, out, iov_len); } -- cgit v1.2.3