Quit when there are too many consecutive errors on the tun/tap device.
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 2 Nov 2010 13:18:35 +0000 (14:18 +0100)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 2 Nov 2010 13:18:35 +0000 (14:18 +0100)
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

index ee58ac0..bed779a 100644 (file)
--- 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 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)) {
 
        /* 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);
                        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;
+                       }
                }
        }
 
                }
        }