Always keep UDP mappings alive for nodes that also have a meta-connection.
[tinc] / src / net_packet.c
index 456b43d..99063ac 100644 (file)
@@ -97,10 +97,16 @@ static void udp_probe_timeout_handler(void *data) {
 
 static void udp_probe_h(node_t *n, vpn_packet_t *packet, length_t len) {
        if(!DATA(packet)[0]) {
-               logger(DEBUG_TRAFFIC, LOG_INFO, "Got UDP probe request %d from %s (%s)", packet->len, n->name, n->hostname);
-
                /* It's a probe request, send back a reply */
 
+               if(!n->status.sptps && !n->status.validkey) {
+                       // But not if we don't have his key.
+                       logger(DEBUG_TRAFFIC, LOG_INFO, "Got UDP probe request from %s (%s) but we don't have his key yet", n->name, n->hostname);
+                       return;
+               }
+
+               logger(DEBUG_TRAFFIC, LOG_INFO, "Got UDP probe request %d from %s (%s)", packet->len, n->name, n->hostname);
+
                /* Type 2 probe replies were introduced in protocol 17.3 */
                if ((n->options >> 24) >= 3) {
                        uint8_t *data = DATA(packet);
@@ -1081,7 +1087,7 @@ static void try_mtu(node_t *n) {
    idle.
 */
 
-static void try_tx_sptps(node_t *n) {
+static void try_tx_sptps(node_t *n, bool mtu) {
        /* If n is a TCP-only neighbor, we'll only use "cleartext" PACKET
           messages anyway, so there's no need for SPTPS at all. */
 
@@ -1104,13 +1110,14 @@ static void try_tx_sptps(node_t *n) {
        /* If we do have a relay, try everything with that one instead. */
 
        if(via != n)
-               return try_tx_sptps(via);
+               return try_tx_sptps(via, mtu);
 
        try_udp(n);
-       try_mtu(n);
+       if(mtu)
+               try_mtu(n);
 }
 
-static void try_tx_legacy(node_t *n) {
+static void try_tx_legacy(node_t *n, bool mtu) {
        /* Does he have our key? If not, send one. */
 
        if(!n->status.validkey_in)
@@ -1127,7 +1134,15 @@ static void try_tx_legacy(node_t *n) {
        }
 
        try_udp(n);
-       try_mtu(n);
+       if(mtu)
+               try_mtu(n);
+}
+
+void try_tx(node_t *n, bool mtu) {
+       if(n->status.sptps)
+               try_tx_sptps(n, mtu);
+       else
+               try_tx_legacy(n, mtu);
 }
 
 void send_packet(node_t *n, vpn_packet_t *packet) {
@@ -1160,7 +1175,7 @@ void send_packet(node_t *n, vpn_packet_t *packet) {
 
        if(n->status.sptps) {
                send_sptps_packet(n, packet);
-               try_tx_sptps(n);
+               try_tx_sptps(n, true);
                return;
        }
 
@@ -1180,7 +1195,7 @@ void send_packet(node_t *n, vpn_packet_t *packet) {
        }
 
        send_udppacket(via, packet);
-       try_tx_legacy(via);
+       try_tx_legacy(via, true);
 }
 
 void broadcast_packet(const node_t *from, vpn_packet_t *packet) {