From: Guus Sliepen Date: Tue, 2 Nov 2010 13:18:35 +0000 (+0100) Subject: Quit when there are too many consecutive errors on the tun/tap device. X-Git-Tag: release-1.0.14~37 X-Git-Url: https://git.librecmc.org/?p=oweals%2Ftinc.git;a=commitdiff_plain;h=a91bf2dfcd0f5857905e59da7d944654e0875503;hp=aca70cd3c3fe787e62c618849e43f67b3870ac20 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. --- diff --git a/src/net.c b/src/net.c index ee58ac0..bed779a 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; + } } }