chiark / gitweb /
Import release 0.1.10
[secnet.git] / tun.c
diff --git a/tun.c b/tun.c
index 01c0cb8960f942d505ccf8d3bc3d1fd077d2717d..90b9161022abc0d5c268702733ee1db7190cfb92 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -12,7 +12,7 @@
 #include <linux/if_tun.h>
 #endif
 
-/* XXX where do we find if_tun on other platforms? */
+/* Where do we find if_tun on other platforms? */
 
 /* Connection to the kernel through the universal TUN/TAP driver */
 
@@ -48,6 +48,7 @@ static void tun_afterpoll(void *sst, struct pollfd *fds, int nfds,
     struct tun *st=sst;
     int l;
 
+    if (nfds==0) return;
     if (fds[0].revents&POLLERR) {
        printf("tun_afterpoll: hup!\n");
     }
@@ -63,20 +64,19 @@ static void tun_afterpoll(void *sst, struct pollfd *fds, int nfds,
        }
        if (l>0) {
            st->buff->size=l;
-           st->netlink_to_tunnel(&st->nl,NULL,st->buff);
+           st->netlink_to_tunnel(&st->nl,st->buff);
            BUF_ASSERT_FREE(st->buff);
        }
     }
 }
 
-static void tun_deliver_to_kernel(void *sst, void *cid,
-                                 struct buffer_if *buf)
+static void tun_deliver_to_kernel(void *sst, struct buffer_if *buf)
 {
     struct tun *st=sst;
 
     BUF_ASSERT_USED(buf);
-
-    /* No error checking, because we'd just throw the packet away anyway */
+    /* No error checking, because we'd just throw the packet away
+       anyway if it didn't work. */
     write(st->fd,buf->start,buf->size);
     BUF_FREE(buf);
 }
@@ -251,9 +251,6 @@ static list_t *tun_old_apply(closure_t *self, struct cloc loc, dict_t *context,
 
     st=safe_malloc(sizeof(*st),"tun_old_apply");
 
-    Message(M_WARNING,"the tun-old code has never been tested. Please report "
-           "success or failure to steve@greenend.org.uk\n");
-
     /* First parameter must be a dict */
     item=list_elem(args,0);
     if (!item || item->type!=t_dict)
@@ -263,7 +260,7 @@ static list_t *tun_old_apply(closure_t *self, struct cloc loc, dict_t *context,
 
     st->netlink_to_tunnel=
        netlink_init(&st->nl,st,loc,dict,
-                    "netlink-tun",NULL,tun_deliver_to_kernel);
+                    "netlink-tun",tun_set_route,tun_deliver_to_kernel);
 
     st->tun_old=True;
     st->device_path=dict_read_string(dict,"device",False,"tun-netlink",loc);