Add a cache of recently seen addresses.
[tinc] / src / net_packet.c
index 1aa881c..7bd619f 100644 (file)
@@ -30,6 +30,7 @@
 #include LZO1X_H
 #endif
 
+#include "address_cache.h"
 #include "cipher.h"
 #include "conf.h"
 #include "connection.h"
@@ -153,7 +154,13 @@ static void udp_probe_h(node_t *n, vpn_packet_t *packet, length_t len) {
        /* It's a valid reply: now we know bidirectional communication
           is possible using the address and socket that the reply
           packet used. */
-       n->status.udp_confirmed = true;
+       if(!n->status.udp_confirmed) {
+               n->status.udp_confirmed = true;
+               fprintf(stderr, "Updating address cache...\n");
+               if (!n->address_cache)
+                       n->address_cache = open_address_cache(n);
+               reset_address_cache(n->address_cache, &n->address);
+       }
 
        // Reset the UDP ping timer.
        n->udp_ping_sent = now;
@@ -773,7 +780,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
                listen_socket[sock].priority = origpriority;
 
                switch(sa->sa.sa_family) {
-#if defined(IPPROTO_IP) && defined(IP_TOS)
+#if defined(IP_TOS)
 
                case AF_INET:
                        logger(DEBUG_TRAFFIC, LOG_DEBUG, "Setting IPv4 outgoing packet priority to %d", origpriority);
@@ -784,7 +791,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
 
                        break;
 #endif
-#if defined(IPPROTO_IPV6) & defined(IPV6_TCLASS)
+#if defined(IPV6_TCLASS)
 
                case AF_INET6:
                        logger(DEBUG_TRAFFIC, LOG_DEBUG, "Setting IPv6 outgoing packet priority to %d", origpriority);
@@ -929,7 +936,7 @@ bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t
                if(!from->status.validkey) {
                        from->status.validkey = true;
                        from->status.waitingforkey = false;
-                       logger(DEBUG_META, LOG_INFO, "SPTPS key exchange with %s (%s) succesful", from->name, from->hostname);
+                       logger(DEBUG_META, LOG_INFO, "SPTPS key exchange with %s (%s) successful", from->name, from->hostname);
                }
 
                return true;