chiark / gitweb /
server/{keyexch.c,keyset.c}: Move timing parameters to tripe.h.
[tripe] / server / tun-bsd.c
index 200b5d9325a65fecf3c9d1a831b533ee10079bb2..2c872997f7a79e82ea70b522f24814060f86f1e8 100644 (file)
@@ -59,7 +59,8 @@ static void t_read(int fd, unsigned mode, void *v)
 
   n = read(fd, buf_i, sizeof(buf_i));
   if (n < 0) {
-    a_warn("TUN", "%s", p_ifname(t->p), "read-error", "?ERRNO", A_END);
+    a_warn("TUN", "%s", p_ifname(t->p), "bsd",
+          "read-error", "?ERRNO", A_END);
     return;
   }
   IF_TRACING(T_TUNNEL, {
@@ -82,43 +83,6 @@ static void t_read(int fd, unsigned mode, void *v)
 
 static void t_init(void) { return; }
 
-/* --- @t_open@ --- *
- *
- * Arguments:  @char **ifn@ = where to put the interface name
- *
- * Returns:    A file descriptor, or @-1@ on failure.
- *
- * Use:                Opens a tunnel device.  This will run with root privileges
- *             even if the rest of the server has dropped them.
- */
-
-static int t_open(char **ifn)
-{
-  int fd;
-  unsigned n;
-  char buf[16];
-
-  n = 0;
-  for (;;) {
-    sprintf(buf, "/dev/tun%u", n);
-    if ((fd = open(buf, O_RDWR)) >= 0)
-      break;
-    switch (errno) {
-      case EBUSY:
-       T( trace(T_TUNNEL, "tunnel device %u busy: skipping", n); )
-       break;
-      case ENOENT:
-       a_warn("TUN", "-", "bsd", "no-tunnel-devices", A_END);
-       return (-1);
-      default:
-       a_warn("TUN", "-", "open-error", "%s", buf, "?ERRNO", A_END);
-       break;
-    }
-    n++;
-  }
-  return (fd);
-}
-
 /* --- @t_create@ --- *
  *
  * Arguments:  @peer *p@ = pointer to peer block
@@ -159,7 +123,7 @@ static void t_inject(tunnel *t, buf *b)
     trace(T_TUNNEL, "tun-bsd: inject decrypted packet");
     trace_block(T_PACKET, "tun-bsd: packet contents", BBASE(b), BLEN(b));
   })
-  write(t->f.fd, BBASE(b), BLEN(b));
+  IGNORE(write(t->f.fd, BBASE(b), BLEN(b)));
 }
 
 /* --- @t_destroy@ --- *
@@ -176,8 +140,8 @@ static void t_destroy(tunnel *t)
 
 const tunnel_ops tun_bsd = {
   "bsd",
+  TUNF_PRIVOPEN,
   t_init,
-  t_open,
   t_create,
   0,
   t_inject,