X-Git-Url: http://git.meshlink.io/?p=meshlink;a=blobdiff_plain;f=src%2Fnet_packet.c;h=ce1eb62680bd1c25fcb2038dc50892069ab21cce;hp=b32c78f7d467456166e9551ca211242a651361f7;hb=af60e5f5164b28495c4a441f38c86e8f6b184a38;hpb=5b5e1456905850d03638621328dff994876458c2 diff --git a/src/net_packet.c b/src/net_packet.c index b32c78f7..ce1eb626 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -305,7 +305,7 @@ static void send_sptps_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t * return; } -static void choose_udp_address(meshlink_handle_t *mesh, const node_t *n, const sockaddr_t **sa, int *sock) { +static void choose_udp_address(meshlink_handle_t *mesh, const node_t *n, const sockaddr_t **sa, int *sock, sockaddr_t *sa_buf) { /* Latest guess */ *sa = &n->address; *sock = n->sock; @@ -330,6 +330,22 @@ static void choose_udp_address(meshlink_handle_t *mesh, const node_t *n, const s goto check_socket; } + /* Else, if we have a canonical address, try this once every batch */ + if(mesh->udp_choice == 1 && n->canonical_address) { + char *host = xstrdup(n->canonical_address); + char *port = strchr(host, ' '); + + if(port) { + *port++ = 0; + *sa_buf = str2sockaddr_random(mesh, host, port); + *sa = sa_buf; + free(host); + goto check_socket; + } + + free(host); + } + /* Otherwise, address are found in edges to this node. So we pick a random edge and a random socket. */ @@ -422,13 +438,14 @@ bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len) { /* Otherwise, send the packet via UDP */ + sockaddr_t sa_buf; const sockaddr_t *sa; int sock; if(to->status.broadcast) { choose_broadcast_address(mesh, to, &sa, &sock); } else { - choose_udp_address(mesh, to, &sa, &sock); + choose_udp_address(mesh, to, &sa, &sock, &sa_buf); } if(sendto(mesh->listen_socket[sock].udp.fd, data, len, 0, &sa->sa, SALEN(sa->sa)) < 0 && !sockwouldblock(sockerrno)) {