From a91bf2dfcd0f5857905e59da7d944654e0875503 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 2 Nov 2010 14:18:35 +0100 Subject: [PATCH] Quit when there are too many consecutive errors on the tun/tap device. Although transient errors sometimes happen on the tun/tap device (for example, if the kernel is temporarily out of buffer space), there are situations where the tun/tap device becomes permanently broken. Instead of endlessly spamming the syslog, we now sleep an increasing amount of time between consecutive read errors, and if reads still fail after 10 attempts (approximately 3 seconds), tinc will quit. --- src/net.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/net.c b/src/net.c index ee58ac0a..bed779a5 100644 --- a/src/net.c +++ b/src/net.c @@ -280,12 +280,21 @@ static void check_network_activity(fd_set * readset, fd_set * writeset) { int result, i; socklen_t len = sizeof(result); vpn_packet_t packet; + int errors = 0; /* check input from kernel */ if(device_fd >= 0 && FD_ISSET(device_fd, readset)) { if(read_packet(&packet)) { + errors = 0; packet.priority = 0; route(myself, &packet); + } else { + usleep(errors * 50000); + errors++; + if(errors > 10) { + logger(LOG_ERR, "Too many errors from %s, exiting!", device); + running = false; + } } } -- 2.39.5