From 090dbeef60c7e578950c3dbe807a9e2ea7e24875 Mon Sep 17 00:00:00 2001 From: Richard Kettlewell Date: Mon, 11 Jul 2011 19:44:18 +0100 Subject: [PATCH] Log write failures on tun device. This is useful when debugging. Short writes count as failures The error reporting is rate limited to ensure that the logs are not flooded. Signed-off-by: Richard Kettlewell --- tun.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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); } -- 2.30.2