]> git.meshlink.io Git - meshlink/commitdiff
Ensure exported host files have a port in the canonical address.
authorGuus Sliepen <guus@meshlink.io>
Thu, 16 Apr 2020 00:08:38 +0000 (02:08 +0200)
committerGuus Sliepen <guus@meshlink.io>
Thu, 16 Apr 2020 00:12:04 +0000 (02:12 +0200)
src/meshlink.c
src/net_socket.c

index 32d10447aa57f755fe5531c7f8596feb528336a2..b85795d465e3c64c59bc6c0990f3deb60dfd3f86 100644 (file)
@@ -2424,13 +2424,20 @@ bool meshlink_set_canonical_address(meshlink_handle_t *mesh, meshlink_node_t *no
        }
 
        if(!is_valid_hostname(address)) {
-               logger(mesh, MESHLINK_DEBUG, "Invalid character in address: %s\n", address);
+               logger(mesh, MESHLINK_DEBUG, "Invalid character in address: %s", address);
+               meshlink_errno = MESHLINK_EINVAL;
+               return false;
+       }
+
+       if((node_t *)node != mesh->self && !port) {
+               logger(mesh, MESHLINK_DEBUG, "Missing port number!");
                meshlink_errno = MESHLINK_EINVAL;
                return false;
+
        }
 
        if(port && !is_valid_port(port)) {
-               logger(mesh, MESHLINK_DEBUG, "Invalid character in port: %s\n", address);
+               logger(mesh, MESHLINK_DEBUG, "Invalid character in port: %s", address);
                meshlink_errno = MESHLINK_EINVAL;
                return false;
        }
@@ -3042,7 +3049,15 @@ char *meshlink_export(meshlink_handle_t *mesh) {
        packmsg_add_int32(&out, mesh->self->devclass);
        packmsg_add_bool(&out, mesh->self->status.blacklisted);
        packmsg_add_bin(&out, ecdsa_get_public_key(mesh->private_key), 32);
-       packmsg_add_str(&out, mesh->self->canonical_address ? mesh->self->canonical_address : "");
+
+       if(mesh->self->canonical_address && !strchr(mesh->self->canonical_address, ' ')) {
+               char *canonical_address = NULL;
+               xasprintf(&canonical_address, "%s %s", mesh->self->canonical_address, mesh->myport);
+               packmsg_add_str(&out, canonical_address);
+               free(canonical_address);
+       } else {
+               packmsg_add_str(&out, mesh->self->canonical_address ? mesh->self->canonical_address : "");
+       }
 
        uint32_t count = 0;
 
index 8b293d5d548904002fe7e15749bf938fcb478f3f..51a79c1d4cf54569aa74bdb37f34c297ea306ef0 100644 (file)
@@ -283,12 +283,14 @@ static bool get_next_outgoing_address(meshlink_handle_t *mesh, outgoing_t *outgo
                        if(port) {
                                *port++ = 0;
                                port = xstrdup(port);
+                               adns_queue(mesh, address, port, canonical_resolve_cb, outgoing->node, 2);
+                               return false;
                        } else {
-                               port = xstrdup(mesh->myport);
+                               logger(mesh, MESHLINK_ERROR, "Canonical address for %s is missing port number", n->name);
+                               free(address);
+                               outgoing->state = OUTGOING_RECENT;
                        }
 
-                       adns_queue(mesh, address, port, canonical_resolve_cb, outgoing->node, 2);
-                       return false;
                } else {
                        outgoing->state = OUTGOING_RECENT;
                }