]> git.meshlink.io Git - meshlink/blobdiff - src/pmtu.c
Fix PMTU test case.
[meshlink] / src / pmtu.c
index 770f18280759c1ae8aa352cd10c52477384e5152..36152cffec2af6d8d23a61f32d5a8fa7ffa202c9 100644 (file)
@@ -91,8 +91,16 @@ static void udp_probe_timeout_handler(event_loop_t *loop, void *data) {
        logger(mesh, MESHLINK_INFO, "Too much time has elapsed since last UDP ping response from %s, stopping UDP communication", n->name);
        n->status.udp_confirmed = false;
        n->mtuprobes = 0;
+       n->udpprobes = 0;
        n->minmtu = 0;
        n->maxmtu = MTU;
+
+       // If we also have a meta-connection to this node, send a PING on it as well
+       connection_t *c = n->connection;
+
+       if(c && !c->status.pinged) {
+               send_ping(mesh, c);
+       }
 }
 
 static void send_udp_probe_reply(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet, uint16_t len) {
@@ -154,6 +162,8 @@ void udp_probe_h(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet, uint1
                n->status.udp_confirmed = true;
        }
 
+       n->udpprobes = 0;
+
        // Reset the UDP ping timer.
 
        timeout_del(&mesh->loop, &n->udp_ping_timeout);
@@ -176,12 +186,12 @@ void udp_probe_h(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet, uint1
 
        /* If applicable, raise the minimum supported PMTU */
 
-       try_fix_mtu(mesh, n);
-
        if(n->minmtu < len) {
                n->minmtu = len;
                update_node_pmtu(mesh, n);
        }
+
+       try_fix_mtu(mesh, n);
 }
 
 static void send_udp_probe_packet(meshlink_handle_t *mesh, node_t *n, int len) {
@@ -212,17 +222,25 @@ static void send_udp_probe_packet(meshlink_handle_t *mesh, node_t *n, int len) {
 static void try_udp(meshlink_handle_t *mesh, node_t *n) {
        /* Probe request */
 
+       if(n->udpprobes < -3) {
+               /* We lost three UDP probes, UDP status is no longer unconfirmed */
+               udp_probe_timeout_handler(&mesh->loop, n);
+       }
+
        struct timespec elapsed;
-       timespec_sub(&mesh->loop.now, &n->last_udp_probe_sent, &elapsed);
 
-       int interval = n->status.udp_confirmed ? 10 : 2;
+       timespec_sub(&mesh->loop.now, &n->last_udp_probe_sent, &elapsed);
 
-       logger(mesh, MESHLINK_DEBUG, "try_udp(%s) %d %d\n", n->name, (int)elapsed.tv_sec, interval);
+       int interval = (n->status.udp_confirmed && n->udpprobes >= 0) ? 10 : 2;
 
        if(elapsed.tv_sec >= interval) {
                n->last_udp_probe_sent = mesh->loop.now;
                send_udp_probe_packet(mesh, n, MIN_PROBE_SIZE);
 
+               if(n->status.udp_confirmed) {
+                       n->udpprobes--;
+               }
+
                if(!n->status.udp_confirmed && n->prevedge) {
                        n->status.broadcast = true;
                        send_udp_probe_packet(mesh, n, MIN_PROBE_SIZE);
@@ -300,8 +318,6 @@ static uint16_t choose_initial_maxmtu(meshlink_handle_t *mesh, node_t *n) {
 */
 
 static void try_pmtu(meshlink_handle_t *mesh, node_t *n) {
-       logger(mesh, MESHLINK_DEBUG, "try_pmtu(%s) %d %d\n", n->name, n->mtuprobes, n->status.udp_confirmed);
-
        if(!n->status.udp_confirmed) {
                n->mtuprobes = 0;
                n->minmtu = 0;
@@ -336,8 +352,6 @@ static void try_pmtu(meshlink_handle_t *mesh, node_t *n) {
 
        n->last_mtu_probe_sent = mesh->loop.now;
 
-       try_fix_mtu(mesh, n);
-
        if(n->mtuprobes < -3) {
                /* We lost three PMTU probes, restart discovery */
                logger(mesh, MESHLINK_INFO, "Decrease in PMTU to %s detected, restarting PMTU discovery", n->name);
@@ -377,6 +391,8 @@ static void try_pmtu(meshlink_handle_t *mesh, node_t *n) {
                send_udp_probe_packet(mesh, n, len);
                n->mtuprobes++;
        }
+
+       try_fix_mtu(mesh, n);
 }
 
 /* Keep the connection to the given node alive.
@@ -384,8 +400,6 @@ static void try_pmtu(meshlink_handle_t *mesh, node_t *n) {
  */
 
 void keepalive(meshlink_handle_t *mesh, node_t *n, bool traffic) {
-       logger(mesh, MESHLINK_DEBUG, "keepalive(%s) %d %d\n", n->name, n->status.reachable, n->status.validkey);
-
        if(!n->status.reachable || !n->status.validkey) {
                return;
        }