]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Fix PMTU test case.
[meshlink] / src / meshlink.c
index 71263b910696a4e9531672afec7c8252c4223b82..95880e31fbd91d70c509be18cc2cf3a1b32a088e 100644 (file)
@@ -30,6 +30,7 @@
 #include "node.h"
 #include "submesh.h"
 #include "packmsg.h"
+#include "pmtu.h"
 #include "prf.h"
 #include "protocol.h"
 #include "route.h"
@@ -1021,14 +1022,6 @@ static bool ecdsa_keygen(meshlink_handle_t *mesh) {
        return true;
 }
 
-static bool timespec_lt(const struct timespec *a, const struct timespec *b) {
-       if(a->tv_sec == b->tv_sec) {
-               return a->tv_nsec < b->tv_nsec;
-       } else {
-               return a->tv_sec < b->tv_sec;
-       }
-}
-
 static struct timespec idle(event_loop_t *loop, void *data) {
        (void)loop;
        meshlink_handle_t *mesh = data;
@@ -1723,11 +1716,19 @@ static void *meshlink_main_loop(void *arg) {
                abort();
        }
 
+       if(mesh->thread_status_cb) {
+               mesh->thread_status_cb(mesh, true);
+       }
+
        logger(mesh, MESHLINK_DEBUG, "Starting main_loop...\n");
        pthread_cond_broadcast(&mesh->cond);
        main_loop(mesh);
        logger(mesh, MESHLINK_DEBUG, "main_loop returned.\n");
 
+       if(mesh->thread_status_cb) {
+               mesh->thread_status_cb(mesh, false);
+       }
+
        pthread_mutex_unlock(&mesh->mutex);
 
        // Stop discovery
@@ -2166,6 +2167,22 @@ void meshlink_set_blacklisted_cb(struct meshlink_handle *mesh, meshlink_blacklis
        pthread_mutex_unlock(&mesh->mutex);
 }
 
+void meshlink_set_thread_status_cb(struct meshlink_handle *mesh, meshlink_thread_status_cb_t cb) {
+       logger(mesh, MESHLINK_DEBUG, "meshlink_set_thread_status_cb(%p)", (void *)(intptr_t)cb);
+
+       if(!mesh) {
+               meshlink_errno = MESHLINK_EINVAL;
+               return;
+       }
+
+       if(pthread_mutex_lock(&mesh->mutex) != 0) {
+               abort();
+       }
+
+       mesh->thread_status_cb = cb;
+       pthread_mutex_unlock(&mesh->mutex);
+}
+
 static bool prepare_packet(meshlink_handle_t *mesh, meshlink_node_t *destination, const void *data, size_t len, vpn_packet_t *packet) {
        meshlink_packethdr_t *hdr;
 
@@ -2184,7 +2201,6 @@ static bool prepare_packet(meshlink_handle_t *mesh, meshlink_node_t *destination
 
        // Prepare the packet
        packet->probe = false;
-       packet->tcp = false;
        packet->len = len + sizeof(*hdr);
 
        hdr = (meshlink_packethdr_t *)packet->data;
@@ -2270,8 +2286,6 @@ void meshlink_send_from_queue(event_loop_t *loop, void *data) {
 
        for(vpn_packet_t *packet; (packet = meshlink_queue_pop(&mesh->outpacketqueue));) {
                logger(mesh, MESHLINK_DEBUG, "Removing packet of %d bytes from packet queue", packet->len);
-               mesh->self->in_packets++;
-               mesh->self->in_bytes += packet->len;
                route(mesh, mesh->self, packet);
                free(packet);
        }
@@ -3618,6 +3632,7 @@ static bool blacklist(meshlink_handle_t *mesh, node_t *n) {
        n->mtu = 0;
        n->minmtu = 0;
        n->maxmtu = MTU;
+       n->udpprobes = 0;
        n->mtuprobes = 0;
        n->status.udp_confirmed = false;
 
@@ -4024,10 +4039,9 @@ static void channel_retransmit(struct utcp_connection *utcp_connection) {
        node_t *n = utcp_connection->utcp->priv;
        meshlink_handle_t *mesh = n->mesh;
 
-       if(n->mtuprobes == 31 && n->mtutimeout.cb) {
-               timeout_set(&mesh->loop, &n->mtutimeout, &(struct timespec) {
-                       0, 0
-               });
+       if(!n->udpprobes) {
+               timespec_clear(&n->last_udp_probe_sent);
+               keepalive(mesh, n, false);
        }
 }