Improve recently seen address cache
[tinc] / src / net_packet.c
index 5bdcb1a..0b95a93 100644 (file)
@@ -53,6 +53,7 @@
 #include "protocol.h"
 #include "route.h"
 #include "utils.h"
+#include "random.h"
 
 /* The minimum size of a probe is 14 bytes, but since we normally use CBC mode
    encryption, we can add a few extra random bytes without increasing the
@@ -199,7 +200,10 @@ static void udp_probe_h(node_t *n, vpn_packet_t *packet, length_t len) {
                        n->address_cache = open_address_cache(n);
                }
 
-               reset_address_cache(n->address_cache, &n->address);
+               if(n->connection && n->connection->edge) {
+                       reset_address_cache(n->address_cache);
+                       add_recent_address(n->address_cache, &n->connection->edge->address);
+               }
        }
 
        // Reset the UDP ping timer.
@@ -1257,7 +1261,7 @@ static length_t choose_initial_maxmtu(node_t *n) {
 
        if(connect(sock, &sa->sa, SALEN(sa->sa))) {
                logger(DEBUG_TRAFFIC, LOG_ERR, "Connecting MTU assessment socket for %s (%s) failed: %s", n->name, n->hostname, sockstrerror(sockerrno));
-               close(sock);
+               closesocket(sock);
                return MTU;
        }
 
@@ -1266,11 +1270,11 @@ static length_t choose_initial_maxmtu(node_t *n) {
 
        if(getsockopt(sock, IPPROTO_IP, IP_MTU, (void *)&ip_mtu, &ip_mtu_len)) {
                logger(DEBUG_TRAFFIC, LOG_ERR, "getsockopt(IP_MTU) on %s (%s) failed: %s", n->name, n->hostname, sockstrerror(sockerrno));
-               close(sock);
+               closesocket(sock);
                return MTU;
        }
 
-       close(sock);
+       closesocket(sock);
 
        if(ip_mtu < MINMTU) {
                logger(DEBUG_TRAFFIC, LOG_ERR, "getsockopt(IP_MTU) on %s (%s) returned absurdly small value: %d", n->name, n->hostname, ip_mtu);
@@ -1642,6 +1646,7 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) {
 
                break;
 
+       case BMODE_NONE:
        default:
                break;
        }