This takes up memory and is only used for logging.
mesh->connections = list_alloc((list_action_t) free_connection);
mesh->everyone = new_connection();
mesh->everyone->name = xstrdup("mesh->everyone");
- mesh->everyone->hostname = xstrdup("BROADCAST");
}
void exit_connections(meshlink_handle_t *mesh) {
closesocket(c->socket);
free(c->name);
- free(c->hostname);
if(c->config_tree)
exit_configuration(&c->config_tree);
n->status.reachable = !n->status.reachable;
n->last_state_change = mesh->loop.now.tv_sec;
- if(n->status.reachable) {
- logger(mesh, MESHLINK_DEBUG, "Node %s (%s) became reachable",
- n->name, n->hostname);
- } else {
- logger(mesh, MESHLINK_DEBUG, "Node %s (%s) became unreachable",
- n->name, n->hostname);
- }
+ if(n->status.reachable)
+ logger(mesh, MESHLINK_DEBUG, "Node %s became reachable", n->name);
+ else
+ logger(mesh, MESHLINK_DEBUG, "Node %s became unreachable", n->name);
/* TODO: only clear status.validkey if node is unreachable? */
abort();
}
- logger(mesh, MESHLINK_DEBUG, "Sending %d bytes of metadata to %s (%s)", length,
- c->name, c->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Sending %d bytes of metadata to %s", length, c->name);
if(c->allow_request == ID) {
buffer_add(&c->outbuf, buffer, length);
if(inlen <= 0) {
if(!inlen || !errno) {
- logger(mesh, MESHLINK_INFO, "Connection closed by %s (%s)",
- c->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Connection closed by %s", c->name);
} else if(sockwouldblock(sockerrno))
return true;
else
- logger(mesh, MESHLINK_ERROR, "Metadata socket read error for %s (%s): %s",
- c->name, c->hostname, sockstrerror(sockerrno));
+ logger(mesh, MESHLINK_ERROR, "Metadata socket read error for %s: %s", c->name, sockstrerror(sockerrno));
return false;
}
}
if(c->inbuf.len >= sizeof(inbuf)) {
- logger(mesh, MESHLINK_ERROR, "Input buffer full for %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Input buffer full for %s", c->name);
return false;
} else
return true;
- Check if we need to retry making an outgoing connection
*/
void terminate_connection(meshlink_handle_t *mesh, connection_t *c, bool report) {
- logger(mesh, MESHLINK_INFO, "Closing connection with %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Closing connection with %s", c->name);
c->status.active = false;
if(c->last_ping_time + mesh->pingtimeout <= mesh->loop.now.tv_sec) {
if(c->status.active) {
if(c->status.pinged)
- logger(mesh, MESHLINK_INFO, "%s (%s) didn't respond to PING in %ld seconds", c->name, c->hostname, (long)mesh->loop.now.tv_sec - c->last_ping_time);
+ logger(mesh, MESHLINK_INFO, "%s didn't respond to PING in %ld seconds", c->name, (long)mesh->loop.now.tv_sec - c->last_ping_time);
else if(c->last_ping_time + mesh->pinginterval <= mesh->loop.now.tv_sec) {
send_ping(mesh, c);
continue;
continue;
} else {
if(c->status.connecting)
- logger(mesh, MESHLINK_WARNING, "Timeout while connecting to %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_WARNING, "Timeout while connecting to %s", c->name);
else
- logger(mesh, MESHLINK_WARNING, "Timeout from %s (%s) during authentication", c->name, c->hostname);
+ logger(mesh, MESHLINK_WARNING, "Timeout from %s during authentication", c->name);
}
terminate_connection(mesh, c, c->status.active);
}
n->mtuprobes++;
if(!n->status.reachable || !n->status.validkey) {
- logger(mesh, MESHLINK_INFO, "Trying to send MTU probe to unreachable or rekeying node %s (%s)", n->name, n->hostname);
+ logger(mesh, MESHLINK_INFO, "Trying to send MTU probe to unreachable or rekeying node %s", n->name);
n->mtuprobes = 0;
return;
}
goto end;
}
- logger(mesh, MESHLINK_INFO, "%s (%s) did not respond to UDP ping, restarting PMTU discovery", n->name, n->hostname);
+ logger(mesh, MESHLINK_INFO, "%s did not respond to UDP ping, restarting PMTU discovery", n->name);
n->status.udp_confirmed = false;
n->mtuprobes = 1;
n->minmtu = 0;
}
if(n->mtuprobes >= 10 && n->mtuprobes < 32 && !n->minmtu) {
- logger(mesh, MESHLINK_INFO, "No response to MTU probes from %s (%s)", n->name, n->hostname);
+ logger(mesh, MESHLINK_INFO, "No response to MTU probes from %s", n->name);
n->mtuprobes = 31;
}
else
n->maxmtu = n->minmtu;
n->mtu = n->minmtu;
- logger(mesh, MESHLINK_INFO, "Fixing MTU of %s (%s) to %d after %d probes", n->name, n->hostname, n->mtu, n->mtuprobes);
+ logger(mesh, MESHLINK_INFO, "Fixing MTU of %s to %d after %d probes", n->name, n->mtu, n->mtuprobes);
n->mtuprobes = 31;
}
packet.len = len;
n->status.broadcast = i >= 4 && n->mtuprobes <= 10 && n->prevedge;
- logger(mesh, MESHLINK_DEBUG, "Sending MTU probe length %d to %s (%s)", len, n->name, n->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Sending MTU probe length %d to %s", len, n->name);
send_udppacket(mesh, n, &packet);
}
}
static void mtu_probe_h(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet, uint16_t len) {
- logger(mesh, MESHLINK_DEBUG, "Got MTU probe length %d from %s (%s)", packet->len, n->name, n->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Got MTU probe length %d from %s", packet->len, n->name);
if(!packet->data[0]) {
/* It's a probe request, send back a reply */
if(n->mtuprobes > 30) {
if(len == n->maxmtu + 8) {
- logger(mesh, MESHLINK_INFO, "Increase in PMTU to %s (%s) detected, restarting PMTU discovery", n->name, n->hostname);
+ logger(mesh, MESHLINK_INFO, "Increase in PMTU to %s detected, restarting PMTU discovery", n->name);
n->maxmtu = MTU;
n->mtuprobes = 10;
return;
/* VPN packet I/O */
static void receive_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet) {
- logger(mesh, MESHLINK_DEBUG, "Received packet of %d bytes from %s (%s)",
- packet->len, n->name, n->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Received packet of %d bytes from %s", packet->len, n->name);
if(n->status.blacklisted)
logger(mesh, MESHLINK_WARNING, "Dropping packet from blacklisted node %s", n->name);
static void receive_udppacket(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *inpkt) {
if(!n->sptps.state) {
if(!n->status.waitingforkey) {
- logger(mesh, MESHLINK_DEBUG, "Got packet from %s (%s) but we haven't exchanged keys yet", n->name, n->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Got packet from %s but we haven't exchanged keys yet", n->name);
send_req_key(mesh, n);
} else
- logger(mesh, MESHLINK_DEBUG, "Got packet from %s (%s) but he hasn't got our key yet", n->name, n->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Got packet from %s but he hasn't got our key yet", n->name);
return;
}
sptps_receive_data(&n->sptps, inpkt->data, inpkt->len);
static void send_sptps_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *origpkt) {
if(!n->status.validkey) {
- logger(mesh, MESHLINK_INFO, "No valid key known yet for %s (%s)", n->name, n->hostname);
+ logger(mesh, MESHLINK_INFO, "No valid key known yet for %s", n->name);
if(!n->status.waitingforkey)
send_req_key(mesh, n);
else if(n->last_req_key + 10 < mesh->loop.now.tv_sec) {
if(n->outcompression) {
int len = compress_packet(outpkt.data, origpkt->data, origpkt->len, n->outcompression);
if(len < 0)
- logger(mesh, MESHLINK_ERROR, "Error while compressing packet to %s (%s)", n->name, n->hostname);
+ logger(mesh, MESHLINK_ERROR, "Error while compressing packet to %s", n->name);
else if(len < origpkt->len) {
outpkt.len = len;
origpkt = &outpkt;
static void send_udppacket(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *origpkt) {
if(!n->status.reachable) {
- logger(mesh, MESHLINK_INFO, "Trying to send UDP packet to unreachable node %s (%s)", n->name, n->hostname);
+ logger(mesh, MESHLINK_INFO, "Trying to send UDP packet to unreachable node %s", n->name);
return;
}
if(to->mtu >= len)
to->mtu = len - 1;
} else {
- logger(mesh, MESHLINK_WARNING, "Error sending UDP SPTPS packet to %s (%s): %s", to->name, to->hostname, sockstrerror(sockerrno));
+ logger(mesh, MESHLINK_WARNING, "Error sending UDP SPTPS packet to %s: %s", to->name, sockstrerror(sockerrno));
return false;
}
}
if(type == SPTPS_HANDSHAKE) {
if(!from->status.validkey) {
- logger(mesh, MESHLINK_INFO, "SPTPS key exchange with %s (%s) succesful", from->name, from->hostname);
+ logger(mesh, MESHLINK_INFO, "SPTPS key exchange with %s succesful", from->name);
from->status.validkey = true;
from->status.waitingforkey = false;
if(from->utcp)
}
if(len > MTU) {
- logger(mesh, MESHLINK_ERROR, "Packet from %s (%s) larger than maximum supported size (%d > %d)", from->name, from->hostname, len, MTU);
+ logger(mesh, MESHLINK_ERROR, "Packet from %s larger than maximum supported size (%d > %d)", from->name, len, MTU);
return false;
}
inpkt.probe = false;
if(type & ~(PKT_COMPRESSED)) {
- logger(mesh, MESHLINK_ERROR, "Unexpected SPTPS record type %d len %d from %s (%s)", type, len, from->name, from->hostname);
+ logger(mesh, MESHLINK_ERROR, "Unexpected SPTPS record type %d len %d from %s", type, len, from->name);
return false;
}
return;
}
- logger(mesh, MESHLINK_DEBUG, "Sending packet of %d bytes to %s (%s)",
- packet->len, n->name, n->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Sending packet of %d bytes to %s", packet->len, n->name);
if(!n->status.reachable) {
- logger(mesh, MESHLINK_WARNING, "Node %s (%s) is not reachable",
- n->name, n->hostname);
+ logger(mesh, MESHLINK_WARNING, "Node %s is not reachable", n->name);
return;
}
if(from != mesh->self)
send_packet(mesh, mesh->self, packet);
- logger(mesh, MESHLINK_INFO, "Broadcasting packet of %d bytes from %s (%s)",
- packet->len, from->name, from->hostname);
+ logger(mesh, MESHLINK_INFO, "Broadcasting packet of %d bytes from %s", packet->len, from->name);
for list_each(connection_t, c, mesh->connections)
if(c->status.active && c->status.mst && c != from->nexthop->connection)
return false;
}
- xasprintf(&mesh->self->hostname, "MYSELF port %s", mesh->myport);
- mesh->self->connection->hostname = xstrdup(mesh->self->hostname);
-
/* Done. */
mesh->last_config_check = mesh->loop.now.tv_sec;
int flags = fcntl(c->socket, F_GETFL);
if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0)
- logger(c->mesh, MESHLINK_ERROR, "fcntl for %s: %s", c->hostname, strerror(errno));
+ logger(c->mesh, MESHLINK_ERROR, "System call `%s' failed: %s", "fcntl", strerror(errno));
#elif defined(WIN32)
unsigned long arg = 1;
if(ioctlsocket(c->socket, FIONBIO, &arg) != 0)
- logger(c->mesh, MESHLINK_ERROR, "ioctlsocket for %s: %s", c->hostname, sockstrerror(sockerrno));
+ logger(c->mesh, MESHLINK_ERROR, "System call `%s' failed: %s", "ioctlsocket", sockstrerror(sockerrno));
#endif
#if defined(SOL_TCP) && defined(TCP_NODELAY)
}
void finish_connecting(meshlink_handle_t *mesh, connection_t *c) {
- logger(mesh, MESHLINK_INFO, "Connected to %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Connected to %s", c->name);
c->last_ping_time = mesh->loop.now.tv_sec;
c->status.connecting = false;
ssize_t outlen = send(c->socket, c->outbuf.data + c->outbuf.offset, c->outbuf.len - c->outbuf.offset, MSG_NOSIGNAL);
if(outlen <= 0) {
if(!errno || errno == EPIPE)
- logger(mesh, MESHLINK_INFO, "Connection closed by %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Connection closed by %s", c->name);
else if(sockwouldblock(sockerrno)) {
- logger(mesh, MESHLINK_DEBUG, "Sending %d bytes to %s (%s) would block", c->outbuf.len - c->outbuf.offset, c->name, c->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Sending %d bytes to %s would block", c->outbuf.len - c->outbuf.offset, c->name);
return;
} else
- logger(mesh, MESHLINK_ERROR, "Could not send %d bytes of data to %s (%s): %s", c->outbuf.len - c->outbuf.offset, c->name, c->hostname, strerror(errno));
+ logger(mesh, MESHLINK_ERROR, "Could not send %d bytes of data to %s: %s", c->outbuf.len - c->outbuf.offset, c->name, strerror(errno));
terminate_connection(mesh, c, c->status.active);
return;
if(!result)
finish_connecting(mesh, c);
else {
- logger(mesh, MESHLINK_DEBUG, "Error while connecting to %s (%s): %s", c->name, c->hostname, sockstrerror(result));
+ logger(mesh, MESHLINK_DEBUG, "Error while connecting to %s: %s", c->name, sockstrerror(result));
terminate_connection(mesh, c, false);
return;
}
memcpy(&c->address, outgoing->aip->ai_addr, outgoing->aip->ai_addrlen);
outgoing->aip = outgoing->aip->ai_next;
- c->hostname = sockaddr2hostname(&c->address);
+ char *hostname = sockaddr2hostname(&c->address);
- logger(mesh, MESHLINK_INFO, "Trying to connect to %s (%s)", outgoing->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Trying to connect to %s at %s", outgoing->name, hostname);
if(!mesh->proxytype) {
c->socket = socket(c->address.sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
proxyai = str2addrinfo(mesh->proxyhost, mesh->proxyport, SOCK_STREAM);
if(!proxyai) {
free_connection(c);
+ free(hostname);
goto begin;
}
logger(mesh, MESHLINK_INFO, "Using proxy at %s port %s", mesh->proxyhost, mesh->proxyport);
}
if(c->socket == -1) {
- logger(mesh, MESHLINK_ERROR, "Creating socket for %s failed: %s", c->hostname, sockstrerror(sockerrno));
+ logger(mesh, MESHLINK_ERROR, "Creating socket for %s at %s failed: %s", c->name, c->hostname, sockstrerror(sockerrno));
free_connection(c);
+ free(hostname);
goto begin;
}
+ free(hostname);
+
#ifdef FD_CLOEXEC
fcntl(c->socket, F_SETFD, FD_CLOEXEC);
#endif
}
if(result == -1 && !sockinprogress(sockerrno)) {
- logger(mesh, MESHLINK_ERROR, "Could not connect to %s (%s): %s", outgoing->name, c->hostname, sockstrerror(sockerrno));
+ logger(mesh, MESHLINK_ERROR, "Could not connect to %s: %s", outgoing->name, sockstrerror(sockerrno));
free_connection(c);
goto begin;
c->outcompression = mesh->self->connection->outcompression;
c->address = sa;
- c->hostname = sockaddr2hostname(&sa);
c->socket = fd;
c->last_ping_time = mesh->loop.now.tv_sec;
+ char *hostname = sockaddr2hostname(&sa);
logger(mesh, MESHLINK_INFO, "Connection from %s", c->hostname);
+ free(hostname);
io_add(&mesh->loop, &c->io, handle_meta_io, c, c->socket, IO_READ);
if(n->mtutimeout.cb)
abort();
- free(n->hostname);
free(n->name);
utcp_exit(n->utcp);
break;
}
}
+
hash_insert(mesh->node_udp_cache, sa, n);
- free(n->hostname);
- n->hostname = sockaddr2hostname(&n->address);
meshlink_hint_address(mesh, (meshlink_node_t *)n, &sa->sa);
- logger(mesh, MESHLINK_DEBUG, "UDP address of %s set to %s", n->name, n->hostname);
+
+ if(mesh->log_level >= MESHLINK_DEBUG) {
+ char *hostname = sockaddr2hostname(&n->address);
+ logger(mesh, MESHLINK_DEBUG, "UDP address of %s set to %s", n->name, hostname);
+ free(hostname);
+ }
}
}
int sock; /* Socket to use for outgoing UDP packets */
sockaddr_t address; /* his real (internet) ip to send UDP packets to */
- char *hostname; /* the hostname of its real ip */
node_status_t status;
time_t last_state_change;
va_end(args);
if(len < 0 || len > MAXBUFSIZE - 1) {
- logger(mesh, MESHLINK_ERROR, "Output buffer overflow while sending request to %s (%s)",
- c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Output buffer overflow while sending request to %s", c->name);
return false;
}
- logger(mesh, MESHLINK_DEBUG, "Sending %s to %s (%s): %s", request_name[atoi(request)], c->name, c->hostname, request);
+ logger(mesh, MESHLINK_DEBUG, "Sending %s to %s: %s", request_name[atoi(request)], c->name, request);
request[len++] = '\n';
}
void forward_request(meshlink_handle_t *mesh, connection_t *from, const char *request) {
- logger(mesh, MESHLINK_DEBUG, "Forwarding %s from %s (%s): %s", request_name[atoi(request)], from->name, from->hostname, request);
+ logger(mesh, MESHLINK_DEBUG, "Forwarding %s from %s: %s", request_name[atoi(request)], from->name, request);
// Create a temporary newline-terminated copy of the request
int len = strlen(request);
if(reqno || *request == '0') {
if((reqno < 0) || (reqno >= LAST) || !request_handlers[reqno]) {
- logger(mesh, MESHLINK_DEBUG, "Unknown request from %s (%s): %s", c->name, c->hostname, request);
+ logger(mesh, MESHLINK_DEBUG, "Unknown request from %s: %s", c->name, request);
return false;
} else
- logger(mesh, MESHLINK_DEBUG, "Got %s from %s (%s): %s", request_name[reqno], c->name, c->hostname, request);
+ logger(mesh, MESHLINK_DEBUG, "Got %s from %s: %s", request_name[reqno], c->name, request);
if((c->allow_request != ALL) && (c->allow_request != reqno)) {
- logger(mesh, MESHLINK_ERROR, "Unauthorized request from %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Unauthorized request from %s", c->name);
return false;
}
if(!request_handlers[reqno](mesh, c, request)) {
/* Something went wrong. Probably scriptkiddies. Terminate. */
- logger(mesh, MESHLINK_ERROR, "Error while processing %s from %s (%s)", request_name[reqno], c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Error while processing %s from %s", request_name[reqno], c->name);
return false;
}
} else {
- logger(mesh, MESHLINK_ERROR, "Bogus data received from %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Bogus data received from %s", c->name);
return false;
}
static bool finalize_invitation(meshlink_handle_t *mesh, connection_t *c, const void *data, uint16_t len) {
if(strchr(data, '\n')) {
- logger(mesh, MESHLINK_ERROR, "Received invalid key from invited node %s (%s)!\n", c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Received invalid key from invited node %s!\n", c->name);
return false;
}
char filename[PATH_MAX];
snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", mesh->confbase, c->name);
if(!access(filename, F_OK)) {
- logger(mesh, MESHLINK_ERROR, "Host config file for %s (%s) already exists!\n", c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Host config file for %s already exists!\n", c->name);
return false;
}
fprintf(f, "ECDSAPublicKey = %s\n", (const char *)data);
fclose(f);
- logger(mesh, MESHLINK_INFO, "Key succesfully received from %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Key succesfully received from %s", c->name);
//TODO: callback to application to inform of an accepted invitation
// Atomically rename the invitation file
if(rename(filename, usedname)) {
if(errno == ENOENT)
- logger(mesh, MESHLINK_ERROR, "Peer %s tried to use non-existing invitation %s\n", c->hostname, cookie);
+ logger(mesh, MESHLINK_ERROR, "Peer %s tried to use non-existing invitation %s\n", c->name, cookie);
else
logger(mesh, MESHLINK_ERROR, "Error trying to rename invitation %s\n", cookie);
return false;
c->status.invitation_used = true;
- logger(mesh, MESHLINK_INFO, "Invitation %s succesfully sent to %s (%s)", cookie, c->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Invitation %s succesfully sent to %s", cookie, c->name);
return true;
}
char name[MAX_STRING_SIZE];
if(sscanf(request, "%*d " MAX_STRING " %d.%d", name, &c->protocol_major, &c->protocol_minor) < 2) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ID", c->name,
- c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "ID", c->name);
return false;
}
if(name[0] == '?') {
if(!mesh->invitation_key) {
- logger(mesh, MESHLINK_ERROR, "Got invitation from %s but we don't have an invitation key", c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got invitation from %s but we don't have an invitation key", c->name);
return false;
}
c->ecdsa = ecdsa_set_base64_public_key(name + 1);
if(!c->ecdsa) {
- logger(mesh, MESHLINK_ERROR, "Got bad invitation from %s", c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad invitation from %s", c->name);
return false;
}
/* Check if identity is a valid name */
if(!check_id(name)) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ID", c->name,
- c->hostname, "invalid name");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ID", c->name, "invalid name");
return false;
}
if(c->outgoing) {
if(strcmp(c->name, name)) {
- logger(mesh, MESHLINK_ERROR, "Peer %s is %s instead of %s", c->hostname, name,
- c->name);
+ logger(mesh, MESHLINK_ERROR, "Peer is %s instead of %s", name, c->name);
return false;
}
} else {
/* Check if version matches */
if(c->protocol_major != mesh->self->connection->protocol_major) {
- logger(mesh, MESHLINK_ERROR, "Peer %s (%s) uses incompatible version %d.%d",
- c->name, c->hostname, c->protocol_major, c->protocol_minor);
+ logger(mesh, MESHLINK_ERROR, "Peer %s uses incompatible version %d.%d",
+ c->name, c->protocol_major, c->protocol_minor);
return false;
}
init_configuration(&c->config_tree);
if(!read_host_config(mesh, c->config_tree, c->name)) {
- logger(mesh, MESHLINK_ERROR, "Peer %s had unknown identity (%s)", c->hostname, c->name);
+ logger(mesh, MESHLINK_ERROR, "Peer %s has unknown identity", c->name);
return false;
}
}
read_ecdsa_public_key(mesh, c);
if(!ecdsa_active(c->ecdsa)) {
- logger(mesh, MESHLINK_ERROR, "No key known for peer %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "No key known for peer %s", c->name);
node_t *n = lookup_node(mesh, c->name);
if(n && !n->status.waitingforkey) {
- logger(mesh, MESHLINK_INFO, "Requesting key from peer %s (%s)", c->name, c->hostname);
+ logger(mesh, MESHLINK_INFO, "Requesting key from peer %s", c->name);
send_req_key(mesh, n);
}
/* Forbid version rollback for nodes whose ECDSA key we know */
if(ecdsa_active(c->ecdsa) && c->protocol_minor < 2) {
- logger(mesh, MESHLINK_ERROR, "Peer %s (%s) tries to roll back protocol version to %d.%d",
- c->name, c->hostname, c->protocol_major, c->protocol_minor);
+ logger(mesh, MESHLINK_ERROR, "Peer %s tries to roll back protocol version to %d.%d",
+ c->name, c->protocol_major, c->protocol_minor);
return false;
}
node_t *n;
if(sscanf(request, "%*d " MAX_STRING " %d %x", hisport, &devclass, &options) != 3) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ACK", c->name,
- c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "ACK", c->name);
return false;
}
if(devclass < 0 || devclass > _DEV_CLASS_MAX) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ACK", c->name,
- c->hostname, "devclass invalid");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ACK", c->name, "devclass invalid");
return false;
}
} else {
if(n->connection) {
/* Oh dear, we already have a connection to this node. */
- logger(mesh, MESHLINK_DEBUG, "Established a second connection with %s (%s), closing old connection", n->connection->name, n->connection->hostname);
+ logger(mesh, MESHLINK_DEBUG, "Established a second connection with %s, closing old connection", n->connection->name);
if(n->connection->outgoing) {
if(c->outgoing)
c->allow_request = ALL;
c->status.active = true;
- logger(mesh, MESHLINK_INFO, "Connection with %s (%s) activated", c->name,
- c->hostname);
+ logger(mesh, MESHLINK_INFO, "Connection with %s activated", c->name);
/* Send him everything we know */
if(sscanf(request, "%*d %*x "MAX_STRING" %d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %x %d",
from_name, &from_devclass, to_name, to_address, to_port, &to_devclass, &options, &weight) != 8) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ADD_EDGE", c->name,
- c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "ADD_EDGE", c->name);
return false;
}
/* Check if names are valid */
if(!check_id(from_name) || !check_id(to_name)) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name,
- c->hostname, "invalid name");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ADD_EDGE", c->name, "invalid name");
return false;
}
// Check if devclasses are valid
if(from_devclass < 0 || from_devclass > _DEV_CLASS_MAX) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name,
- c->hostname, "from devclass invalid");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ADD_EDGE", c->name, "from devclass invalid");
return false;
}
if(to_devclass < 0 || to_devclass > _DEV_CLASS_MAX) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ADD_EDGE", c->name,
- c->hostname, "to devclass invalid");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ADD_EDGE", c->name, "to devclass invalid");
return false;
}
if(e) {
if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) {
if(from == mesh->self) {
- logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) for ourself which does not match existing entry",
- "ADD_EDGE", c->name, c->hostname);
+ logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself which does not match existing entry",
+ "ADD_EDGE", c->name);
send_add_edge(mesh, c, e);
return true;
} else {
- logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) which does not match existing entry",
- "ADD_EDGE", c->name, c->hostname);
+ logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not match existing entry",
+ "ADD_EDGE", c->name);
edge_del(mesh, e);
graph(mesh);
}
} else
return true;
} else if(from == mesh->self) {
- logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) for ourself which does not exist",
- "ADD_EDGE", c->name, c->hostname);
+ logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself which does not exist",
+ "ADD_EDGE", c->name);
mesh->contradicting_add_edge++;
e = new_edge();
e->from = from;
node_t *from, *to;
if(sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING, from_name, to_name) != 2) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "DEL_EDGE", c->name,
- c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "DEL_EDGE", c->name);
return false;
}
/* Check if names are valid */
if(!check_id(from_name) || !check_id(to_name)) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "DEL_EDGE", c->name,
- c->hostname, "invalid name");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "DEL_EDGE", c->name, "invalid name");
return false;
}
to = lookup_node(mesh, to_name);
if(!from) {
- logger(mesh, MESHLINK_ERROR, "Got %s from %s (%s) which does not appear in the edge tree",
- "DEL_EDGE", c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got %s from %s which does not appear in the edge tree",
+ "DEL_EDGE", c->name);
return true;
}
if(!to) {
- logger(mesh, MESHLINK_ERROR, "Got %s from %s (%s) which does not appear in the edge tree",
- "DEL_EDGE", c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got %s from %s which does not appear in the edge tree",
+ "DEL_EDGE", c->name);
return true;
}
e = lookup_edge(from, to);
if(!e) {
- logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) which does not appear in the edge tree",
- "DEL_EDGE", c->name, c->hostname);
+ logger(mesh, MESHLINK_WARNING, "Got %s from %s which does not appear in the edge tree",
+ "DEL_EDGE", c->name);
return true;
}
if(e->from == mesh->self) {
- logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) for ourself",
- "DEL_EDGE", c->name, c->hostname);
+ logger(mesh, MESHLINK_WARNING, "Got %s from %s for ourself",
+ "DEL_EDGE", c->name);
mesh->contradicting_del_edge++;
send_add_edge(mesh, c, e); /* Send back a correction */
return true;
node_t *n;
if(sscanf(request, "%*d %*x " MAX_STRING, name) != 1) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "KEY_CHANGED",
- c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "KEY_CHANGED", c->name);
return false;
}
n = lookup_node(mesh, name);
if(!n) {
- logger(mesh, MESHLINK_ERROR, "Got %s from %s (%s) origin %s which does not exist",
- "KEY_CHANGED", c->name, c->hostname, name);
+ logger(mesh, MESHLINK_ERROR, "Got %s from %s origin %s which does not exist", "KEY_CHANGED", c->name, name);
return true;
}
bool send_req_key(meshlink_handle_t *mesh, node_t *to) {
if(!node_read_ecdsa_public_key(mesh, to)) {
- logger(mesh, MESHLINK_DEBUG, "No ECDSA key known for %s (%s)", to->name, to->hostname);
+ logger(mesh, MESHLINK_DEBUG, "No ECDSA key known for %s", to->name);
send_request(mesh, to->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, to->name, REQ_PUBKEY);
return true;
}
case ANS_PUBKEY: {
if(node_read_ecdsa_public_key(mesh, from)) {
- logger(mesh, MESHLINK_WARNING, "Got ANS_PUBKEY from %s (%s) even though we already have his pubkey", from->name, from->hostname);
+ logger(mesh, MESHLINK_WARNING, "Got ANS_PUBKEY from %s even though we already have his pubkey", from->name);
return true;
}
char pubkey[MAX_STRING_SIZE];
if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, pubkey) != 1 || !(from->ecdsa = ecdsa_set_base64_public_key(pubkey))) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ANS_PUBKEY", from->name, from->hostname, "invalid pubkey");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ANS_PUBKEY", from->name, "invalid pubkey");
return true;
}
- logger(mesh, MESHLINK_INFO, "Learned ECDSA public key from %s (%s)", from->name, from->hostname);
+ logger(mesh, MESHLINK_INFO, "Learned ECDSA public key from %s", from->name);
append_config_file(mesh, from->name, "ECDSAPublicKey", pubkey);
return true;
}
case REQ_KEY: {
if(!node_read_ecdsa_public_key(mesh, from)) {
- logger(mesh, MESHLINK_DEBUG, "No ECDSA key known for %s (%s)", from->name, from->hostname);
+ logger(mesh, MESHLINK_DEBUG, "No ECDSA key known for %s", from->name);
send_request(mesh, from->nexthop->connection, "%d %s %s %d", REQ_KEY, mesh->self->name, from->name, REQ_PUBKEY);
return true;
}
int len;
if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode(buf, buf, strlen(buf)))) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "REQ_SPTPS_START", from->name, from->hostname, "invalid SPTPS data");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "REQ_SPTPS_START", from->name, "invalid SPTPS data");
return true;
}
case REQ_SPTPS: {
if(!from->status.validkey) {
- logger(mesh, MESHLINK_ERROR, "Got REQ_SPTPS from %s (%s) but we don't have a valid key yet", from->name, from->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got REQ_SPTPS from %s but we don't have a valid key yet", from->name);
return true;
}
char buf[MAX_STRING_SIZE];
int len;
if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode(buf, buf, strlen(buf)))) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "REQ_SPTPS", from->name, from->hostname, "invalid SPTPS data");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "REQ_SPTPS", from->name, "invalid SPTPS data");
return true;
}
sptps_receive_data(&from->sptps, buf, len);
}
default:
- logger(mesh, MESHLINK_ERROR, "Unknown extended REQ_KEY request from %s (%s): %s", from->name, from->hostname, request);
+ logger(mesh, MESHLINK_ERROR, "Unknown extended REQ_KEY request from %s: %s", from->name, request);
return true;
}
}
int reqno = 0;
if(sscanf(request, "%*d " MAX_STRING " " MAX_STRING " %d", from_name, to_name, &reqno) < 2) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "REQ_KEY", c->name,
- c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "REQ_KEY", c->name);
return false;
}
if(!check_id(from_name) || !check_id(to_name)) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "REQ_KEY", c->name, c->hostname, "invalid name");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "REQ_KEY", c->name, "invalid name");
return false;
}
from = lookup_node(mesh, from_name);
if(!from) {
- logger(mesh, MESHLINK_ERROR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
- "REQ_KEY", c->name, c->hostname, from_name);
+ logger(mesh, MESHLINK_ERROR, "Got %s from %s origin %s which does not exist in our connection list",
+ "REQ_KEY", c->name, from_name);
return true;
}
to = lookup_node(mesh, to_name);
if(!to) {
- logger(mesh, MESHLINK_ERROR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
- "REQ_KEY", c->name, c->hostname, to_name);
+ logger(mesh, MESHLINK_ERROR, "Got %s from %s destination %s which does not exist in our connection list",
+ "REQ_KEY", c->name, to_name);
return true;
}
send_ans_key(mesh, from);
} else {
if(!to->status.reachable) {
- logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
- "REQ_KEY", c->name, c->hostname, to_name);
+ logger(mesh, MESHLINK_WARNING, "Got %s from %s destination %s which is not reachable",
+ "REQ_KEY", c->name, to_name);
return true;
}
if(sscanf(request, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d "MAX_STRING" "MAX_STRING,
from_name, to_name, key, &cipher, &digest, &maclength,
&compression, address, port) < 7) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ANS_KEY", c->name,
- c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "ANS_KEY", c->name);
return false;
}
if(!check_id(from_name) || !check_id(to_name)) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s): %s", "ANS_KEY", c->name, c->hostname, "invalid name");
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s: %s", "ANS_KEY", c->name, "invalid name");
return false;
}
from = lookup_node(mesh, from_name);
if(!from) {
- logger(mesh, MESHLINK_ERROR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
- "ANS_KEY", c->name, c->hostname, from_name);
+ logger(mesh, MESHLINK_ERROR, "Got %s from %s origin %s which does not exist in our connection list",
+ "ANS_KEY", c->name, from_name);
return true;
}
to = lookup_node(mesh, to_name);
if(!to) {
- logger(mesh, MESHLINK_ERROR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
- "ANS_KEY", c->name, c->hostname, to_name);
+ logger(mesh, MESHLINK_ERROR, "Got %s from %s destination %s which does not exist in our connection list",
+ "ANS_KEY", c->name, to_name);
return true;
}
if(to != mesh->self) {
if(!to->status.reachable) {
- logger(mesh, MESHLINK_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
- "ANS_KEY", c->name, c->hostname, to_name);
+ logger(mesh, MESHLINK_WARNING, "Got %s from %s destination %s which is not reachable",
+ "ANS_KEY", c->name, to_name);
return true;
}
/* Compression is not supported. */
if(compression != 0) {
- logger(mesh, MESHLINK_ERROR, "Node %s (%s) uses bogus compression level!", from->name, from->hostname);
+ logger(mesh, MESHLINK_ERROR, "Node %s uses bogus compression level!", from->name);
return true;
}
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 (%s)", from->name, from->hostname);
+ logger(mesh, MESHLINK_ERROR, "Error processing SPTPS data from %s", from->name);
if(from->status.validkey) {
if(*address && *port) {
char statusstring[MAX_STRING_SIZE];
if(sscanf(request, "%*d %d " MAX_STRING, &statusno, statusstring) != 2) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "STATUS",
- c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "STATUS", c->name);
return false;
}
- logger(mesh, MESHLINK_INFO, "Status message from %s (%s): %d: %s",
- c->name, c->hostname, statusno, statusstring);
+ logger(mesh, MESHLINK_INFO, "Status message from %s: %d: %s", c->name, statusno, statusstring);
return true;
}
char errorstring[MAX_STRING_SIZE];
if(sscanf(request, "%*d %d " MAX_STRING, &err, errorstring) != 2) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "ERROR",
- c->name, c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "ERROR", c->name);
return false;
}
- logger(mesh, MESHLINK_INFO, "Error message from %s (%s): %d: %s",
- c->name, c->hostname, err, errorstring);
+ logger(mesh, MESHLINK_INFO, "Error message from %s: %d: %s", c->name, err, errorstring);
return false;
}
short int len;
if(sscanf(request, "%*d %hd", &len) != 1) {
- logger(mesh, MESHLINK_ERROR, "Got bad %s from %s (%s)", "PACKET", c->name,
- c->hostname);
+ logger(mesh, MESHLINK_ERROR, "Got bad %s from %s", "PACKET", c->name);
return false;
}
static bool checklength(node_t *source, vpn_packet_t *packet, uint16_t length) {
if(packet->len < length) {
- logger(source->mesh, MESHLINK_WARNING, "Got too short packet from %s (%s)", source->name, source->hostname);
+ logger(source->mesh, MESHLINK_WARNING, "Got too short packet from %s", source->name);
return false;
} else
return true;
via = (owner->via == mesh->self) ? owner->nexthop : owner->via;
if(via == source) {
- logger(mesh, MESHLINK_ERROR, "Routing loop for packet from %s (%s)!", source->name, source->hostname);
+ logger(mesh, MESHLINK_ERROR, "Routing loop for packet from %s!", source->name);
return;
}