X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/410c8acf139e945dce28bbc0c8b17dcfd0815643..3cdc3f3a27e8c4f4fe692009d868c773d298a68c:/tun-unet.c diff --git a/tun-unet.c b/tun-unet.c index d78c9a11..1cbdf2be 100644 --- a/tun-unet.c +++ b/tun-unet.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: tun-unet.c,v 1.1 2001/02/03 20:26:37 mdw Exp $ + * $Id$ * * Tunnel interface based on Linux Usernet * @@ -26,23 +26,20 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: tun-unet.c,v $ - * Revision 1.1 2001/02/03 20:26:37 mdw - * Initial checkin. - * - */ - /*----- Header files ------------------------------------------------------*/ #include "tripe.h" #include +#include #include /*----- Main code ---------------------------------------------------------*/ +#if TUN_TYPE != TUN_UNET +# error "Tunnel type mismatch: fix the Makefile" +#endif + /* --- @t_read@ --- * * * Arguments: @int fd@ = file descriptor to read @@ -54,7 +51,7 @@ * Use: Reads data from the tunnel. */ -void t_read(int fd, unsigned mode, void *v) +static void t_read(int fd, unsigned mode, void *v) { tunnel *t = v; ssize_t n; @@ -62,7 +59,7 @@ void t_read(int fd, unsigned mode, void *v) n = read(fd, buf_i, sizeof(buf_i)); if (n < 0) { - a_warn("tunnel read failed (%s): %s", tun_ifname(t), strerror(errno)); + a_warn("TUN %s read-error -- %s", tun_ifname(t), strerror(errno)); return; } IF_TRACING(T_TUNNEL, { @@ -101,9 +98,17 @@ void tun_init(void) int tun_create(tunnel *t, peer *p) { int fd; + int f; if ((fd = open("/dev/unet", O_RDWR)) < 0) { - a_warn("open `/dev/unet' failed: %s", strerror(errno)); + a_warn("TUN - open-error /dev/unet -- %s", strerror(errno)); + return (-1); + } + fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC); + if ((f = ioctl(fd, UNIOCGIFFLAGS)) < 0 || + ioctl(fd, UNIOCSIFFLAGS, f | IFF_POINTOPOINT)) { + a_warn("TUN - unet config-error -- %s", strerror(errno)); + close(fd); return (-1); } t->p = p; @@ -126,11 +131,11 @@ const char *tun_ifname(tunnel *t) static char b[UNET_NAMEMAX]; struct unet_info uni; if (ioctl(t->f.fd, UNIOCGINFO, &uni)) { - a_warn("ioctl(UNIOCGINFO) failed: %s", strerror(errno)); + a_warn("TUN - unet getinfo-error -- %s", strerror(errno)); return (""); } if (strlen(uni.uni_ifname) + 1 > sizeof(b)) { - a_warn("interface name too long!"); + a_warn("TUN - unet ifname-too-long"); return (""); } strcpy(b, uni.uni_ifname);