From f79cc0e0bba16a3aa42a5fa13098cda714623205 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Mon, 2 Oct 2017 22:25:19 +0200 Subject: [PATCH] Fix compiling with -Wall -W. --- src/buffer.c | 14 ++++++------ src/buffer.h | 14 ++++++------ src/devtools.c | 6 ++--- src/discovery.c | 7 ++++++ src/ed25519/ecdsa.c | 3 ++- src/event.c | 4 +++- src/list.h | 2 +- src/logger.c | 4 ++-- src/meshlink.c | 21 +++++++++++++----- src/meta.c | 9 +++----- src/net.c | 14 ++++++------ src/net.h | 1 - src/net_packet.c | 54 +++++++++------------------------------------ src/net_setup.c | 8 +++---- src/net_socket.c | 14 +++++++----- src/netutl.c | 8 +++---- src/protocol.c | 5 +++-- src/protocol.h | 5 ----- src/protocol_auth.c | 3 ++- src/protocol_key.c | 10 ++++++--- src/protocol_misc.c | 46 ++++++++------------------------------ src/splay_tree.c | 4 ++-- src/splay_tree.h | 2 +- src/sptps.c | 12 ++++++++-- src/utcp | 2 +- 25 files changed, 119 insertions(+), 153 deletions(-) diff --git a/src/buffer.c b/src/buffer.c index 1cc3986c..ccef7279 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1,6 +1,6 @@ /* buffer.c -- buffer management - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,7 +22,7 @@ #include "buffer.h" #include "xalloc.h" -void buffer_compact(buffer_t *buffer, int maxsize) { +void buffer_compact(buffer_t *buffer, size_t maxsize) { if(buffer->len >= maxsize || buffer->offset / 7 > buffer->len / 8) { memmove(buffer->data, buffer->data + buffer->offset, buffer->len - buffer->offset); buffer->len -= buffer->offset; @@ -32,7 +32,7 @@ void buffer_compact(buffer_t *buffer, int maxsize) { // Make sure we can add size bytes to the buffer, and return a pointer to the start of those bytes. -char *buffer_prepare(buffer_t *buffer, int size) { +char *buffer_prepare(buffer_t *buffer, size_t size) { if(!buffer->data) { buffer->maxlen = size; buffer->data = xmalloc(size); @@ -58,13 +58,13 @@ char *buffer_prepare(buffer_t *buffer, int size) { // Copy data into the buffer. -void buffer_add(buffer_t *buffer, const char *data, int size) { +void buffer_add(buffer_t *buffer, const char *data, size_t size) { memcpy(buffer_prepare(buffer, size), data, size); } // Remove given number of bytes from the buffer, return a pointer to the start of them. -static char *buffer_consume(buffer_t *buffer, int size) { +static char *buffer_consume(buffer_t *buffer, size_t size) { char *start = buffer->data + buffer->offset; buffer->offset += size; @@ -85,14 +85,14 @@ char *buffer_readline(buffer_t *buffer) { if(!newline) return NULL; - int len = newline + 1 - (buffer->data + buffer->offset); + size_t len = newline + 1 - (buffer->data + buffer->offset); *newline = 0; return buffer_consume(buffer, len); } // Check if we have enough bytes in the buffer, and if so, return a pointer to the start of them. -char *buffer_read(buffer_t *buffer, int size) { +char *buffer_read(buffer_t *buffer, size_t size) { if(buffer->len - buffer->offset < size) return NULL; diff --git a/src/buffer.h b/src/buffer.h index 493d3293..ba6647ed 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -22,16 +22,16 @@ typedef struct buffer_t { char *data; - int maxlen; - int len; - int offset; + size_t maxlen; + size_t len; + size_t offset; } buffer_t; -extern void buffer_compact(buffer_t *buffer, int maxsize); -extern char *buffer_prepare(buffer_t *buffer, int size); -extern void buffer_add(buffer_t *buffer, const char *data, int size); +extern void buffer_compact(buffer_t *buffer, size_t maxsize); +extern char *buffer_prepare(buffer_t *buffer, size_t size); +extern void buffer_add(buffer_t *buffer, const char *data, size_t size); extern char *buffer_readline(buffer_t *buffer); -extern char *buffer_read(buffer_t *buffer, int size); +extern char *buffer_read(buffer_t *buffer, size_t size); extern void buffer_clear(buffer_t *buffer); #endif diff --git a/src/devtools.c b/src/devtools.c index c1578e65..a8fc56b8 100644 --- a/src/devtools.c +++ b/src/devtools.c @@ -42,19 +42,19 @@ devtool_edge_t *devtool_get_all_edges(meshlink_handle_t *mesh, devtool_edge_t *e pthread_mutex_lock(&(mesh->mesh_mutex)); devtool_edge_t *result = NULL; - int result_size = 0; + unsigned int result_size = 0; result_size = mesh->edges->count / 2; // if result is smaller than edges, we have to dealloc all the excess devtool_edge_t - if(result_size > *nmemb) + if((size_t)result_size > *nmemb) result = realloc(edges, result_size * sizeof(*result)); else result = edges; if(result) { devtool_edge_t *p = result; - int n = 0; + unsigned int n = 0; for splay_each(edge_t, e, mesh->edges) { // skip edges that do not represent a two-directional connection diff --git a/src/discovery.c b/src/discovery.c index 0ef1001d..5b83862d 100644 --- a/src/discovery.c +++ b/src/discovery.c @@ -28,6 +28,8 @@ static void generate_rand_string(char *buffer, size_t size) { } static void discovery_entry_group_callback(CattaServer *server, CattaSEntryGroup *group, CattaEntryGroupState state, void *userdata) { + (void)server; + (void)group; meshlink_handle_t *mesh = userdata; // asserts @@ -128,6 +130,7 @@ done: } static void discovery_server_callback(CattaServer *server, CattaServerState state, void *userdata) { + (void)server; meshlink_handle_t *mesh = userdata; // asserts @@ -193,6 +196,8 @@ static void discovery_server_callback(CattaServer *server, CattaServerState stat } static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfIndex interface_, CattaProtocol protocol, CattaResolverEvent event, const char *name, const char *type, const char *domain, const char *host_name, const CattaAddress *address, uint16_t port, CattaStringList *txt, CattaLookupResultFlags flags, void *userdata) { + (void)interface_; + (void)protocol; meshlink_handle_t *mesh = userdata; // asserts @@ -306,6 +311,8 @@ static void discovery_resolve_callback(CattaSServiceResolver *resolver, CattaIfI } static void discovery_browse_callback(CattaSServiceBrowser *browser, CattaIfIndex interface_, CattaProtocol protocol, CattaBrowserEvent event, const char *name, const char *type, const char *domain, CattaLookupResultFlags flags, void *userdata) { + (void)browser; + (void)flags; meshlink_handle_t *mesh = userdata; // asserts diff --git a/src/ed25519/ecdsa.c b/src/ed25519/ecdsa.c index a63dedab..2606a21e 100644 --- a/src/ed25519/ecdsa.c +++ b/src/ed25519/ecdsa.c @@ -1,6 +1,6 @@ /* ecdsa.c -- ECDSA key handling - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -79,6 +79,7 @@ ecdsa_t *ecdsa_read_pem_private_key(FILE *fp) { } size_t ecdsa_size(ecdsa_t *ecdsa) { + (void)ecdsa; return 64; } diff --git a/src/event.c b/src/event.c index 6ca44d48..54d69658 100644 --- a/src/event.c +++ b/src/event.c @@ -1,6 +1,6 @@ /* event.c -- I/O, timeout and signal event handling - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -133,6 +133,8 @@ static int signal_compare(const signal_t *a, const signal_t *b) { } static void signalio_handler(event_loop_t *loop, void *data, int flags) { + (void)data; + (void)flags; unsigned char signum; if(read(loop->pipefd[0], &signum, 1) != 1) return; diff --git a/src/list.h b/src/list.h index 254fbffd..186e0ad6 100644 --- a/src/list.h +++ b/src/list.h @@ -35,7 +35,7 @@ typedef void (*list_action_node_t)(const list_node_t *); typedef struct list_t { list_node_t *head; list_node_t *tail; - int count; + unsigned int count; /* Callbacks */ diff --git a/src/logger.c b/src/logger.c index f77252bd..97fddecd 100644 --- a/src/logger.c +++ b/src/logger.c @@ -1,6 +1,6 @@ /* logger.c -- logging code - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,7 +40,7 @@ void logger(meshlink_handle_t *mesh, meshlink_log_level_t level, const char *for int len = vsnprintf(message, sizeof(message), format, ap); va_end(ap); - if(len > 0 && len < sizeof(message) && message[len - 1] == '\n') + if(len > 0 && (size_t)len < sizeof(message) && message[len - 1] == '\n') message[len - 1] = 0; if(mesh) diff --git a/src/meshlink.c b/src/meshlink.c index e70ac5f6..094d4983 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -310,7 +310,7 @@ static char *get_line(const char **data) { static char line[1024]; const char *end = strchr(*data, '\n'); - size_t len = end ? end - *data : strlen(*data); + size_t len = end ? (size_t)(end - *data) : strlen(*data); if(len >= sizeof(line)) { logger(NULL, MESHLINK_ERROR, "Maximum line length exceeded!\n"); return NULL; @@ -553,6 +553,7 @@ static bool finalize_join(meshlink_handle_t *mesh) { } static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) { + (void)type; meshlink_handle_t *mesh = handle; while(len) { int result = send(mesh->sock, data, len, 0); @@ -611,7 +612,7 @@ static bool recvline(meshlink_handle_t *mesh, size_t len) { mesh->blen += result; } - if(newline - mesh->buffer >= len) + if((size_t)(newline - mesh->buffer) >= len) return false; len = newline - mesh->buffer; @@ -633,7 +634,7 @@ static bool sendline(int fd, char *format, ...) { blen = vsnprintf(buffer, sizeof(buffer), format, ap); va_end(ap); - if(blen < 1 || blen >= sizeof(buffer)) + if(blen < 1 || (size_t)blen >= sizeof(buffer)) return false; buffer[blen] = '\n'; @@ -666,7 +667,7 @@ static const char *errstr[] = { }; const char *meshlink_strerror(meshlink_errno_t err) { - if(err < 0 || err >= sizeof(errstr) / sizeof(*errstr)) + if((int)err < 0 || err >= sizeof(errstr) / sizeof(*errstr)) return "Invalid error code"; return errstr[err]; } @@ -726,6 +727,7 @@ static bool ecdsa_keygen(meshlink_handle_t *mesh) { } static struct timeval idle(event_loop_t *loop, void *data) { + (void)loop; meshlink_handle_t *mesh = data; struct timeval t, tmin = {3600, 0}; for splay_each(node_t, n, mesh->nodes) { @@ -872,7 +874,7 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const c usingname = true; } - if(devclass < 0 || devclass > _DEV_CLASS_MAX) { + if((int)devclass < 0 || devclass > _DEV_CLASS_MAX) { logger(NULL, MESHLINK_ERROR, "Invalid devclass given!\n"); meshlink_errno = MESHLINK_EINVAL; return NULL; @@ -1227,6 +1229,7 @@ bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const } void meshlink_send_from_queue(event_loop_t *loop, meshlink_handle_t *mesh) { + (void)loop; vpn_packet_t *packet = meshlink_queue_pop(&mesh->outpacketqueue); if(!packet) return; @@ -2100,6 +2103,7 @@ void meshlink_hint_address(meshlink_handle_t *mesh, meshlink_node_t *node, const } static bool channel_pre_accept(struct utcp *utcp, uint16_t port) { + (void)port; node_t *n = utcp->priv; meshlink_handle_t *mesh = n->mesh; return mesh->channel_accept_cb; @@ -2137,7 +2141,7 @@ static void channel_accept(struct utcp_connection *utcp_connection, uint16_t por static ssize_t channel_send(struct utcp *utcp, const void *data, size_t len) { node_t *n = utcp->priv; meshlink_handle_t *mesh = n->mesh; - return meshlink_send(mesh, (meshlink_node_t *)n, data, len) ? len : -1; + return meshlink_send(mesh, (meshlink_node_t *)n, data, len) ? (ssize_t)len : -1; } void meshlink_set_channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_receive_cb_t cb) { @@ -2150,6 +2154,7 @@ void meshlink_set_channel_receive_cb(meshlink_handle_t *mesh, meshlink_channel_t } static void channel_receive(meshlink_handle_t *mesh, meshlink_node_t *source, const void *data, size_t len) { + (void)mesh; node_t *n = (node_t *)source; if(!n->utcp) abort(); @@ -2167,6 +2172,7 @@ static void channel_poll(struct utcp_connection *connection, size_t len) { } void meshlink_set_channel_poll_cb(meshlink_handle_t *mesh, meshlink_channel_t *channel, meshlink_channel_poll_cb_t cb) { + (void)mesh; channel->poll_cb = cb; utcp_set_poll_cb(channel->c, cb ? channel_poll : NULL); } @@ -2188,6 +2194,9 @@ void meshlink_set_channel_accept_cb(meshlink_handle_t *mesh, meshlink_channel_ac } meshlink_channel_t *meshlink_channel_open_ex(meshlink_handle_t *mesh, meshlink_node_t *node, uint16_t port, meshlink_channel_receive_cb_t cb, const void *data, size_t len, uint32_t flags) { + if(data || len) + abort(); // TODO: handle non-NULL data + if(!mesh || !node) { meshlink_errno = MESHLINK_EINVAL; return NULL; diff --git a/src/meta.c b/src/meta.c index 2d308403..fe213643 100644 --- a/src/meta.c +++ b/src/meta.c @@ -1,6 +1,6 @@ /* meta.c -- handle the meta communication - Copyright (C) 2014 Guus Sliepen , + Copyright (C) 2014-2017 Guus Sliepen , This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ #include "xalloc.h" bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t length) { + (void)type; connection_t *c = handle; meshlink_handle_t *mesh = c->mesh; @@ -89,11 +90,7 @@ bool receive_meta_sptps(void *handle, uint8_t type, const void *data, uint16_t l /* Are we receiving a TCPpacket? */ if(c->tcplen) { - if(length != c->tcplen) - return false; - receive_tcppacket(mesh, c, request, length); - c->tcplen = 0; - return true; + abort(); // TODO: get rid of tcplen altogether } /* Change newline to null byte, just like non-SPTPS requests */ diff --git a/src/net.c b/src/net.c index c0ed9849..69462d5c 100644 --- a/src/net.c +++ b/src/net.c @@ -1,6 +1,6 @@ /* net.c -- most of the network code - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ #include #if !defined(min) -static const int min(int a, int b) { +static inline int min(int a, int b) { return a < b ? a : b; } #endif @@ -344,7 +344,7 @@ static void periodic_handler(event_loop_t *loop, void *data) { // get cur_connects - int cur_connects = 0; + unsigned int cur_connects = 0; for list_each(connection_t, c, mesh->connections) { if(c->status.active) @@ -358,8 +358,8 @@ static void periodic_handler(event_loop_t *loop, void *data) { assert(mesh->devclass >= 0 && mesh->devclass <= _DEV_CLASS_MAX); - int min_connects = dev_class_traits[mesh->devclass].min_connects; - int max_connects = dev_class_traits[mesh->devclass].max_connects; + unsigned int min_connects = dev_class_traits[mesh->devclass].min_connects; + unsigned int max_connects = dev_class_traits[mesh->devclass].max_connects; logger(mesh, MESHLINK_DEBUG, "* min_connects = %d", min_connects); logger(mesh, MESHLINK_DEBUG, "* max_connects = %d", max_connects); @@ -393,7 +393,7 @@ static void periodic_handler(event_loop_t *loop, void *data) { if(!connect_to && min_connects <= cur_connects && cur_connects < max_connects) { unsigned int connects = 0; - for(int devclass = 0; devclass <= mesh->devclass; ++devclass) { + for(unsigned int devclass = 0; devclass <= mesh->devclass; ++devclass) { for list_each(connection_t, c, mesh->connections) { if(c->status.active && c->node && c->node->devclass == devclass) connects += 1; @@ -476,7 +476,7 @@ static void periodic_handler(event_loop_t *loop, void *data) { if(min_connects < cur_connects /*&& cur_connects <= max_connects*/) { unsigned int connects = 0; - for(int devclass = 0; devclass <= mesh->devclass; ++devclass) { + for(unsigned int devclass = 0; devclass <= mesh->devclass; ++devclass) { for list_each(connection_t, c, mesh->connections) { if(c->status.active && c->node && c->node->devclass == devclass) connects += 1; diff --git a/src/net.h b/src/net.h index fa34dcf7..afefa17b 100644 --- a/src/net.h +++ b/src/net.h @@ -91,7 +91,6 @@ extern int setup_vpn_in_socket(struct meshlink_handle *mesh, const sockaddr_t *) extern bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len); extern bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len); extern void send_packet(struct meshlink_handle *mesh, struct node_t *, struct vpn_packet_t *); -extern void receive_tcppacket(struct meshlink_handle *mesh, struct connection_t *, const char *, int); extern void broadcast_packet(struct meshlink_handle *mesh, const struct node_t *, struct vpn_packet_t *); extern char *get_name(struct meshlink_handle *mesh); extern void load_all_nodes(struct meshlink_handle *mesh); diff --git a/src/net_packet.c b/src/net_packet.c index 0ab5b7fa..96f16d57 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -1,6 +1,6 @@ /* net_packet.c -- Handles in- and outgoing VPN packets - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -195,14 +195,6 @@ static void mtu_probe_h(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet } } -static uint16_t compress_packet(uint8_t *dest, const uint8_t *source, uint16_t len, int level) { - abort(); -} - -static uint16_t uncompress_packet(uint8_t *dest, const uint8_t *source, uint16_t len, int level) { - abort(); -} - /* VPN packet I/O */ static void receive_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet) { @@ -219,6 +211,7 @@ static void receive_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *pac } static bool try_mac(meshlink_handle_t *mesh, node_t *n, const vpn_packet_t *inpkt) { + (void)mesh; return sptps_verify_datagram(&n->sptps, inpkt->data, inpkt->len); } @@ -234,19 +227,6 @@ static void receive_udppacket(meshlink_handle_t *mesh, node_t *n, vpn_packet_t * sptps_receive_data(&n->sptps, inpkt->data, inpkt->len); } -void receive_tcppacket(meshlink_handle_t *mesh, connection_t *c, const char *buffer, int len) { - vpn_packet_t outpkt; - - if(len > sizeof(outpkt).data) - return; - - outpkt.len = len; - outpkt.tcp = true; - memcpy(outpkt.data, buffer, len); - - receive_packet(mesh, c->node, &outpkt); -} - 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", n->name); @@ -269,17 +249,9 @@ static void send_sptps_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t * return; } - vpn_packet_t outpkt; - 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", n->name); - else if(len < origpkt->len) { - outpkt.len = len; - origpkt = &outpkt; - type |= PKT_COMPRESSED; - } + logger(mesh, MESHLINK_ERROR, "Error while compressing packet to %s", n->name); + return; } sptps_send_record(&n->sptps, type, origpkt->data, origpkt->len); @@ -463,18 +435,13 @@ bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t } if(type & PKT_COMPRESSED) { - uint16_t ulen = uncompress_packet(inpkt.data, (const uint8_t *)data, len, from->incompression); - if(ulen < 0) - return false; - else - inpkt.len = ulen; - if(inpkt.len > MAXSIZE) - abort(); - } else { - memcpy(inpkt.data, data, len); - inpkt.len = len; + logger(mesh, MESHLINK_ERROR, "Error while decompressing packet from %s", from->name); + return false; } + memcpy(inpkt.data, data, len); // TODO: get rid of memcpy + inpkt.len = len; + receive_packet(mesh, from, &inpkt); return true; } @@ -548,11 +515,12 @@ static node_t *try_harder(meshlink_handle_t *mesh, const sockaddr_t *from, const } void handle_incoming_vpn_data(event_loop_t *loop, void *data, int flags) { + (void)flags; meshlink_handle_t *mesh = loop->data; listen_socket_t *ls = data; vpn_packet_t pkt; char *hostname; - sockaddr_t from = {{0}}; + sockaddr_t from = {}; socklen_t fromlen = sizeof(from); node_t *n; int len; diff --git a/src/net_setup.c b/src/net_setup.c index 96be9df3..37644c44 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -1,6 +1,6 @@ /* net_setup.c -- Setup. - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -136,7 +136,7 @@ bool node_read_devclass(meshlink_handle_t *mesh, node_t *n) { free(p); } - if(n->devclass < 0 || n->devclass > _DEV_CLASS_MAX) + if((int)n->devclass < 0 || n->devclass > _DEV_CLASS_MAX) n->devclass = _DEV_CLASS_MAX; exit: @@ -146,7 +146,7 @@ exit: bool node_write_devclass(meshlink_handle_t *mesh, node_t *n) { - if(n->devclass < 0 || n->devclass > _DEV_CLASS_MAX) + if((int)n->devclass < 0 || n->devclass > _DEV_CLASS_MAX) return false; bool result = false; @@ -252,7 +252,7 @@ static bool add_listen_address(meshlink_handle_t *mesh, char *address, bool bind *address = 0; } - struct addrinfo *ai, hint = {0}; + struct addrinfo *ai, hint = {}; hint.ai_family = addressfamily; hint.ai_socktype = SOCK_STREAM; hint.ai_protocol = IPPROTO_TCP; diff --git a/src/net_socket.c b/src/net_socket.c index a74db196..97c42fc2 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -1,6 +1,6 @@ /* net_socket.c -- Handle various kinds of sockets. - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -311,13 +311,14 @@ static void handle_meta_write(meshlink_handle_t *mesh, connection_t *c) { 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) + if(!errno || errno == EPIPE) { logger(mesh, MESHLINK_INFO, "Connection closed by %s", c->name); - else if(sockwouldblock(sockerrno)) { - logger(mesh, MESHLINK_DEBUG, "Sending %d bytes to %s would block", c->outbuf.len - c->outbuf.offset, c->name); + } else if(sockwouldblock(sockerrno)) { + logger(mesh, MESHLINK_DEBUG, "Sending %lu bytes to %s would block", (unsigned long)(c->outbuf.len - c->outbuf.offset), c->name); return; - } else - logger(mesh, MESHLINK_ERROR, "Could not send %d bytes of data to %s: %s", c->outbuf.len - c->outbuf.offset, c->name, strerror(errno)); + } else { + logger(mesh, MESHLINK_ERROR, "Could not send %lu bytes of data to %s: %s", (unsigned long)(c->outbuf.len - c->outbuf.offset), c->name, strerror(errno)); + } terminate_connection(mesh, c, c->status.active); return; @@ -564,6 +565,7 @@ void setup_outgoing_connection(meshlink_handle_t *mesh, outgoing_t *outgoing) { new connection */ void handle_new_meta_connection(event_loop_t *loop, void *data, int flags) { + (void)flags; meshlink_handle_t *mesh = loop->data; listen_socket_t *l = data; connection_t *c; diff --git a/src/netutl.c b/src/netutl.c index 983ad914..75950f05 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -1,6 +1,6 @@ /* netutl.c -- some supporting network utility code - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,7 +32,7 @@ bool hostnames = false; Return NULL on failure. */ struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) { - struct addrinfo *ai, hint = {0}; + struct addrinfo *ai, hint = {}; int err; hint.ai_family = addressfamily; @@ -49,8 +49,8 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock } sockaddr_t str2sockaddr(const char *address, const char *port) { - struct addrinfo *ai, hint = {0}; - sockaddr_t result = {{0}}; + struct addrinfo *ai, hint = {}; + sockaddr_t result = {}; int err; hint.ai_family = AF_UNSPEC; diff --git a/src/protocol.c b/src/protocol.c index fb0aa9ca..08226f67 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -1,6 +1,6 @@ /* protocol.c -- handle the meta-protocol, basic functions - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -158,6 +158,7 @@ static void free_past_request(past_request_t *r) { } static void age_past_requests(event_loop_t *loop, void *data) { + (void)data; meshlink_handle_t *mesh = loop->data; int left = 0, deleted = 0; @@ -178,7 +179,7 @@ static void age_past_requests(event_loop_t *loop, void *data) { } bool seen_request(meshlink_handle_t *mesh, const char *request) { - past_request_t *new, p = {NULL}; + past_request_t *new, p = {}; p.request = request; diff --git a/src/protocol.h b/src/protocol.h index 0070cd02..48bdd864 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -83,17 +83,12 @@ extern bool seen_request(struct meshlink_handle *mesh, const char *); extern bool send_id(struct meshlink_handle *mesh, struct connection_t *); extern bool send_ack(struct meshlink_handle *mesh, struct connection_t *); -extern bool send_status(struct meshlink_handle *mesh, struct connection_t *, int, const char *); -extern bool send_error(struct meshlink_handle *mesh, struct connection_t *, int, const char *); -extern bool send_termreq(struct meshlink_handle *mesh, struct connection_t *); extern bool send_ping(struct meshlink_handle *mesh, struct connection_t *); extern bool send_pong(struct meshlink_handle *mesh, struct connection_t *); extern bool send_add_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *); extern bool send_del_edge(struct meshlink_handle *mesh, struct connection_t *, const struct edge_t *); extern void send_key_changed(struct meshlink_handle *mesh); extern bool send_req_key(struct meshlink_handle *mesh, struct node_t *); -extern bool send_ans_key(struct meshlink_handle *mesh, struct node_t *); -extern bool send_tcppacket(struct meshlink_handle *mesh, struct connection_t *, const struct vpn_packet_t *); /* Request handlers */ diff --git a/src/protocol_auth.c b/src/protocol_auth.c index ca042e12..69507b77 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -1,6 +1,6 @@ /* protocol_auth.c -- handle the meta-protocol, authentication - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -138,6 +138,7 @@ bool send_id(meshlink_handle_t *mesh, connection_t *c) { } static bool finalize_invitation(meshlink_handle_t *mesh, connection_t *c, const void *data, uint16_t len) { + (void)len; if(strchr(data, '\n')) { logger(mesh, MESHLINK_ERROR, "Received invalid key from invited node %s!\n", c->name); return false; diff --git a/src/protocol_key.c b/src/protocol_key.c index 6384eb39..5f1be34e 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -1,6 +1,6 @@ /* protocol_key.c -- handle the meta-protocol, key exchange - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -68,6 +68,7 @@ bool key_changed_h(meshlink_handle_t *mesh, connection_t *c, const char *request } static bool send_initial_sptps_data(void *handle, uint8_t type, const void *data, size_t len) { + (void)type; node_t *to = handle; meshlink_handle_t *mesh = to->mesh; to->sptps.send_data = send_sptps_data; @@ -99,6 +100,7 @@ bool send_req_key(meshlink_handle_t *mesh, node_t *to) { /* REQ_KEY is overloaded to allow arbitrary requests to be routed between two nodes. */ static bool req_key_ext_h(meshlink_handle_t *mesh, connection_t *c, const char *request, node_t *from, int reqno) { + (void)c; switch(reqno) { case REQ_PUBKEY: { char *pubkey = ecdsa_get_base64_public_key(mesh->self->connection->ecdsa); @@ -219,8 +221,8 @@ bool req_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { if(reqno) return req_key_ext_h(mesh, c, request, from, reqno); - /* No, just send our key back */ - send_ans_key(mesh, from); + /* This should never happen. Ignore it, unless it came directly from the connected peer, in which case we disconnect. */ + return from->connection != c; } else { if(!to->status.reachable) { logger(mesh, MESHLINK_WARNING, "Got %s from %s destination %s which is not reachable", @@ -235,6 +237,8 @@ bool req_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { } bool send_ans_key(meshlink_handle_t *mesh, node_t *to) { + (void)mesh; + (void)to; abort(); } diff --git a/src/protocol_misc.c b/src/protocol_misc.c index 8948bb2e..5ec01d92 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -1,6 +1,6 @@ /* protocol_misc.c -- handle the meta-protocol, miscellaneous functions - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,13 +33,6 @@ int maxoutbufsize = 0; /* Status and error notification routines */ -bool send_status(meshlink_handle_t *mesh, connection_t *c, int statusno, const char *statusstring) { - if(!statusstring) - statusstring = "Status"; - - return send_request(mesh, c, "%d %d %s", STATUS, statusno, statusstring); -} - bool status_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { int statusno; char statusstring[MAX_STRING_SIZE]; @@ -54,13 +47,6 @@ bool status_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { return true; } -bool send_error(meshlink_handle_t *mesh, connection_t *c, int err, const char *errstring) { - if(!errstring) - errstring = "Error"; - - return send_request(mesh, c, "%d %d %s", ERROR, err, errstring); -} - bool error_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { int err; char errorstring[MAX_STRING_SIZE]; @@ -75,11 +61,10 @@ bool error_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { return false; } -bool send_termreq(meshlink_handle_t *mesh, connection_t *c) { - return send_request(mesh, c, "%d", TERMREQ); -} - bool termreq_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { + (void)mesh; + (void)c; + (void)request; return false; } @@ -91,6 +76,7 @@ bool send_ping(meshlink_handle_t *mesh, connection_t *c) { } bool ping_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { + (void)request; return send_pong(mesh, c); } @@ -99,6 +85,8 @@ bool send_pong(meshlink_handle_t *mesh, connection_t *c) { } bool pong_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { + (void)mesh; + (void)request; c->status.pinged = false; /* Succesful connection, reset timeout if this is an outgoing connection. */ @@ -117,19 +105,6 @@ bool pong_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { /* Sending and receiving packets via TCP */ -bool send_tcppacket(meshlink_handle_t *mesh, connection_t *c, const vpn_packet_t *packet) { - /* If there already is a lot of data in the outbuf buffer, discard this packet. - We use a very simple Random Early Drop algorithm. */ - - if(2.0 * c->outbuf.len / (float)maxoutbufsize - 1 > (float)rand() / (float)RAND_MAX) - return true; - - if(!send_request(mesh, c, "%d %hd", PACKET, packet->len)) - return false; - - return send_meta(mesh, c, (char *)packet->data, packet->len); -} - bool tcppacket_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { short int len; @@ -138,9 +113,6 @@ bool tcppacket_h(meshlink_handle_t *mesh, connection_t *c, const char *request) return false; } - /* Set reqlen to len, this will tell receive_meta() that a tcppacket is coming. */ - - c->tcplen = len; - - return true; + // This should never happen with MeshLink. + return false; } diff --git a/src/splay_tree.c b/src/splay_tree.c index d84948ed..b9130d6b 100644 --- a/src/splay_tree.c +++ b/src/splay_tree.c @@ -1,6 +1,6 @@ /* splay_tree.c -- splay tree and linked list convenience - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ /* Splay operation */ static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *result) { - splay_node_t left = {NULL}, right = {NULL}; + splay_node_t left = {}, right = {}; splay_node_t *leftbottom = &left, *rightbottom = &right, *child, *grandchild; splay_node_t *root = tree->root; int c; diff --git a/src/splay_tree.h b/src/splay_tree.h index f1ff7db9..b6727908 100644 --- a/src/splay_tree.h +++ b/src/splay_tree.h @@ -57,7 +57,7 @@ typedef struct splay_tree_t { splay_compare_t compare; splay_action_t delete; - int count; + unsigned int count; } splay_tree_t; diff --git a/src/sptps.c b/src/sptps.c index 50958ec6..01fb438f 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -1,6 +1,6 @@ /* sptps.c -- Simple Peer-to-Peer Security - Copyright (C) 2014 Guus Sliepen + Copyright (C) 2014-2017 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -50,9 +50,15 @@ unsigned int sptps_replaywin = 32; */ void sptps_log_quiet(sptps_t *s, int s_errno, const char *format, va_list ap) { + (void)s; + (void)s_errno; + (void)format; + (void)ap; } void sptps_log_stderr(sptps_t *s, int s_errno, const char *format, va_list ap) { + (void)s; + (void)s_errno; vfprintf(stderr, format, ap); fputc('\n', stderr); } @@ -227,6 +233,7 @@ static bool send_ack(sptps_t *s) { // Receive an ACKnowledgement record. static bool receive_ack(sptps_t *s, const char *data, uint16_t len) { + (void)data; if(len) return error(s, EIO, "Invalid ACK record length"); @@ -335,6 +342,7 @@ static bool receive_handshake(sptps_t *s, const char *data, uint16_t len) { // We receive a secondary KEX request, first respond by sending our own. if(!send_kex(s)) return false; + // fallthrough case SPTPS_KEX: // We have sent our KEX request, we expect our peer to sent one as well. if(!receive_kex(s, data, len)) @@ -439,7 +447,7 @@ static bool sptps_receive_data_datagram(sptps_t *s, const void *vdata, size_t le return error(s, EIO, "Received late or replayed packet, seqno %d, last received %d\n", seqno, s->inseqno); } else { // We missed some packets. Mark them in the bitmap as being late. - for(int i = s->inseqno; i < seqno; i++) + for(uint32_t i = s->inseqno; i < seqno; i++) s->late[(i / 8) % s->replaywin] |= 1 << i % 8; } } diff --git a/src/utcp b/src/utcp index 1d8aa0d5..558c6d18 160000 --- a/src/utcp +++ b/src/utcp @@ -1 +1 @@ -Subproject commit 1d8aa0d5a55bb871ce56bca355ade80b08a7c1e5 +Subproject commit 558c6d183e2a580b811c5603dd48c33b01a3dc7e -- 2.39.2