X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=tun.c;h=3db998f37fcd24d05b910d84111ea779fd9b4fbd;hp=7d1053a1915bfc3239ff9a07a686ef1fc99353f1;hb=090dbeef60c7e578950c3dbe807a9e2ea7e24875;hpb=baab3a63ada033b2b9eed46807b2e88536612bbc diff --git a/tun.c b/tun.c index 7d1053a..3db998f 100644 --- a/tun.c +++ b/tun.c @@ -3,6 +3,7 @@ #include "netlink.h" #include #include +#include #include #include #include @@ -134,11 +135,27 @@ static void tun_afterpoll(void *sst, struct pollfd *fds, int nfds) static void tun_deliver_to_kernel(void *sst, struct buffer_if *buf) { struct tun *st=sst; + ssize_t rc; BUF_ASSERT_USED(buf); - /* No error checking, because we'd just throw the packet away - anyway if it didn't work. */ - write(st->fd,buf->start,buf->size); + + /* Log errors, so we can tell what's going on, but only once a + minute, so we don't flood the logs. Short writes count as + errors. */ + rc = write(st->fd,buf->start,buf->size); + if(rc != buf->size) { + static struct timeval last_report; + if(tv_now_global.tv_sec >= last_report.tv_sec + 60) { + if(rc < 0) + Message(M_WARNING, + "failed to deliver packet to tun device: %s\n", + strerror(errno)); + else + Message(M_WARNING, + "truncated packet delivered to tun device\n"); + last_report = tv_now_global; + } + } BUF_FREE(buf); }