]> git.meshlink.io Git - meshlink/commitdiff
Slightly relax the connection rate limit for a single address.
authorGuus Sliepen <guus@tinc-vpn.org>
Sun, 1 Sep 2013 22:11:04 +0000 (00:11 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 1 Sep 2013 22:11:04 +0000 (00:11 +0200)
The restriction of accepting only 1 connection per second from a single address
is a bit too much, especially if one wants to join a VPN using an invitation,
which requires two connections.

src/net_socket.c

index d0beb19f2ed20a603e4fc3625b9f2c8f2e351a38..ab3c17e02a110b41d9044cdc25c15c3c74ca4a0b 100644 (file)
@@ -602,10 +602,22 @@ void handle_new_meta_connection(void *data, int flags) {
                tarpit = -1;
        }
 
-       if(prev_time == now.tv_sec && !sockaddrcmp_noport(&sa, &prev_sa)) {
-               // if so, keep the connection open but ignore it completely.
-               tarpit = fd;
-               return;
+       if(!sockaddrcmp_noport(&sa, &prev_sa)) {
+               static int samehost_burst;
+               static int samehost_burst_time;
+
+               if(now.tv_sec - samehost_burst_time > samehost_burst)
+                       samehost_burst = 0;
+               else
+                       samehost_burst -= now.tv_sec - samehost_burst_time;
+
+               samehost_burst_time = now.tv_sec;
+               samehost_burst++;
+
+               if(samehost_burst > max_connection_burst) {
+                       tarpit = fd;
+                       return;
+               }
        }
 
        memcpy(&prev_sa, &sa, sizeof sa);