From 9ece2f9ded8c65c7f20826f2ec9ae1f0527bdd7c Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 31 Oct 2019 20:46:36 +0100 Subject: [PATCH] Try to get a new reflexive UDP address if UDP probes failed. If we are sending data to a node, but we don't have working UDP, it could be because we don't have a good reflexive UDP address. Send a dummy ANS_KEY once in a while as long as we still want to exchange data. --- src/net_packet.c | 7 +++++++ src/node.h | 1 + src/protocol_key.c | 26 ++++++++++++++------------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/net_packet.c b/src/net_packet.c index 53228369..0510b54b 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -102,6 +102,12 @@ static void send_mtu_probe_handler(event_loop_t *loop, void *data) { } if(n->mtuprobes == 31) { + if(!n->minmtu && n->status.want_udp) { + /* Send a dummy ANS_KEY to try to update the reflexive UDP address */ + send_request(mesh, n->nexthop->connection, NULL, "%d %s %s . -1 -1 -1 0", ANS_KEY, mesh->self->name, n->name); + n->status.want_udp = false; + } + timeout = mesh->dev_class_traits[n->devclass].pinginterval; goto end; } else if(n->mtuprobes == 32) { @@ -472,6 +478,7 @@ void send_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet) { n->out_packets++; n->out_bytes += packet->len; + n->status.want_udp = true; send_sptps_packet(mesh, n, packet); return; diff --git a/src/node.h b/src/node.h index 50ee141c..28464520 100644 --- a/src/node.h +++ b/src/node.h @@ -37,6 +37,7 @@ typedef struct node_status_t { uint16_t destroyed: 1; /* 1 if the node is being destroyed, deallocate channels when any callback is triggered */ uint16_t duplicate: 1; /* 1 if the node is duplicate, ie. multiple nodes using the same Name are online */ uint16_t dirty: 1; /* 1 if the configuration of the node is dirty and needs to be written out */ + uint16_t want_udp: 1; /* 1 if we want working UDP because we have data to send */ } node_status_t; typedef struct node_t { diff --git a/src/protocol_key.c b/src/protocol_key.c index 1d708e4a..f912c0fb 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -338,22 +338,24 @@ bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { return send_request(mesh, to->nexthop->connection, NULL, "%s", request); } - /* Don't use key material until every check has passed. */ - from->status.validkey = false; + /* Process SPTPS data if present */ - /* Compression is not supported. */ - if(compression != 0) { - logger(mesh, MESHLINK_ERROR, "Node %s uses bogus compression level!", from->name); - return true; - } + if(*key != '.') { + /* Don't use key material until every check has passed. */ + from->status.validkey = false; - /* SPTPS or old-style key exchange? */ + /* Compression is not supported. */ + if(compression != 0) { + logger(mesh, MESHLINK_ERROR, "Node %s uses bogus compression level!", from->name); + return true; + } - char buf[strlen(key)]; - int len = b64decode(key, buf, strlen(key)); + char buf[strlen(key)]; + int len = b64decode(key, buf, strlen(key)); - if(!len || !sptps_receive_data(&from->sptps, buf, len)) { - logger(mesh, MESHLINK_ERROR, "Error processing SPTPS data from %s", from->name); + if(!len || !sptps_receive_data(&from->sptps, buf, len)) { + logger(mesh, MESHLINK_ERROR, "Error processing SPTPS data from %s", from->name); + } } if(from->status.validkey) { -- 2.39.2