From: Guus Sliepen Date: Wed, 14 May 2014 21:36:24 +0000 (+0200) Subject: Ensure everything compiles with -Wall without giving warnings. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=2cfd1205dc9c6e9d42cc569f415afe13f52357ec;p=meshlink Ensure everything compiles with -Wall without giving warnings. Mostly by using void pointers for opaque objects and removing unused variables. --- diff --git a/src/logger.c b/src/logger.c index 5f3bbbbf..ea29e3f6 100644 --- a/src/logger.c +++ b/src/logger.c @@ -40,13 +40,3 @@ void logger(int level, int priority, const char *format, ...) { fprintf(stderr, "%s\n", message); } - -// TODO: make sure this gets used somewhere -static void sptps_logger(sptps_t *s, int s_errno, const char *format, va_list ap) { - char message[1024] = ""; - int len = vsnprintf(message, sizeof message, format, ap); - if(len > 0 && len < sizeof message && message[len - 1] == '\n') - message[len - 1] = 0; - - fprintf(stderr, "%s\n", message); -} diff --git a/src/meshlink.c b/src/meshlink.c index 62eda6da..2aa79def 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -549,7 +549,7 @@ static bool finalize_join(meshlink_handle_t *mesh) { return true; } -static bool invitation_send(void *handle, uint8_t type, const char *data, size_t len) { +static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) { meshlink_handle_t* mesh = handle; while(len) { int result = send(mesh->sock, data, len, 0); @@ -563,7 +563,7 @@ static bool invitation_send(void *handle, uint8_t type, const char *data, size_t return true; } -static bool invitation_receive(void *handle, uint8_t type, const char *msg, uint16_t len) { +static bool invitation_receive(void *handle, uint8_t type, const void *msg, uint16_t len) { meshlink_handle_t* mesh = handle; switch(type) { case SPTPS_HANDSHAKE: diff --git a/src/meta.c b/src/meta.c index e31c171c..c402919b 100644 --- a/src/meta.c +++ b/src/meta.c @@ -28,7 +28,7 @@ #include "utils.h" #include "xalloc.h" -bool send_meta_sptps(void *handle, uint8_t type, const char *buffer, size_t length) { +bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t length) { connection_t *c = handle; meshlink_handle_t *mesh = c->mesh; @@ -37,7 +37,7 @@ bool send_meta_sptps(void *handle, uint8_t type, const char *buffer, size_t leng abort(); } - buffer_add(&c->outbuf, buffer, length); + buffer_add(&c->outbuf, (const char *)buffer, length); io_set(&mesh->loop, &c->io, IO_READ | IO_WRITE); return true; @@ -67,9 +67,10 @@ void broadcast_meta(meshlink_handle_t *mesh, connection_t *from, const char *buf send_meta(mesh, c, buffer, length); } -bool receive_meta_sptps(void *handle, uint8_t type, const char *data, uint16_t length) { +bool receive_meta_sptps(void *handle, uint8_t type, const void *data, uint16_t length) { connection_t *c = handle; meshlink_handle_t *mesh = c->mesh; + char *request = (char *)data; if(!c) { logger(DEBUG_ALWAYS, LOG_ERR, "receive_meta_sptps() called with NULL pointer!"); @@ -83,7 +84,7 @@ bool receive_meta_sptps(void *handle, uint8_t type, const char *data, uint16_t l return true; } - if(!data) + if(!request) return true; /* Are we receiving a TCPpacket? */ @@ -91,19 +92,19 @@ bool receive_meta_sptps(void *handle, uint8_t type, const char *data, uint16_t l if(c->tcplen) { if(length != c->tcplen) return false; - receive_tcppacket(mesh, c, data, length); + receive_tcppacket(mesh, c, request, length); c->tcplen = 0; return true; } /* Change newline to null byte, just like non-SPTPS requests */ - if(data[length - 1] == '\n') - ((char *)data)[length - 1] = 0; + if(request[length - 1] == '\n') + request[length - 1] = 0; /* Otherwise we are waiting for a request */ - return receive_request(mesh, c, data); + return receive_request(mesh, c, request); } bool receive_meta(meshlink_handle_t *mesh, connection_t *c) { diff --git a/src/meta.h b/src/meta.h index 00cdc175..5aae67dd 100644 --- a/src/meta.h +++ b/src/meta.h @@ -23,8 +23,8 @@ #include "connection.h" extern bool send_meta(struct meshlink_handle *mesh, struct connection_t *, const char *, int); -extern bool send_meta_sptps(void *, uint8_t, const char *, size_t); -extern bool receive_meta_sptps(void *, uint8_t, const char *, uint16_t); +extern bool send_meta_sptps(void *, uint8_t, const void *, size_t); +extern bool receive_meta_sptps(void *, uint8_t, const void *, uint16_t); extern void broadcast_meta(struct meshlink_handle *mesh, struct connection_t *, const char *, int); extern bool receive_meta(struct meshlink_handle *mesh, struct connection_t *); diff --git a/src/net.h b/src/net.h index 1c590b72..2f3a93ac 100644 --- a/src/net.h +++ b/src/net.h @@ -88,8 +88,8 @@ extern bool do_outgoing_connection(struct meshlink_handle *mesh, struct outgoing extern void handle_new_meta_connection(struct event_loop_t *loop, void *, int); extern int setup_listen_socket(const sockaddr_t *); extern int setup_vpn_in_socket(struct meshlink_handle *mesh, const sockaddr_t *); -extern bool send_sptps_data(void *handle, uint8_t type, const char *data, size_t len); -extern bool receive_sptps_record(void *handle, uint8_t type, const char *data, uint16_t len); +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 *); diff --git a/src/net_packet.c b/src/net_packet.c index 978915c3..f3809e87 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -440,14 +440,6 @@ static void choose_broadcast_address(meshlink_handle_t *mesh, const node_t *n, c } static void send_udppacket(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *origpkt) { - vpn_packet_t pkt1, pkt2; - vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 }; - vpn_packet_t *inpkt = origpkt; - int nextpkt = 0; - vpn_packet_t *outpkt; - int origlen = origpkt->len; - size_t outlen; - if(!n->status.reachable) { logger(DEBUG_TRAFFIC, LOG_INFO, "Trying to send UDP packet to unreachable node %s (%s)", n->name, n->hostname); return; @@ -456,7 +448,7 @@ static void send_udppacket(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *ori return send_sptps_packet(mesh, n, origpkt); } -bool send_sptps_data(void *handle, uint8_t type, const char *data, size_t len) { +bool send_sptps_data(void *handle, uint8_t type, const void *data, size_t len) { node_t *to = handle; meshlink_handle_t *mesh = to->mesh; @@ -500,7 +492,7 @@ bool send_sptps_data(void *handle, uint8_t type, const char *data, size_t len) { return true; } -bool receive_sptps_record(void *handle, uint8_t type, const char *data, uint16_t len) { +bool receive_sptps_record(void *handle, uint8_t type, const void *data, uint16_t len) { node_t *from = handle; meshlink_handle_t *mesh = from->mesh; @@ -557,8 +549,6 @@ bool receive_sptps_record(void *handle, uint8_t type, const char *data, uint16_t send a packet to the given vpn ip. */ void send_packet(meshlink_handle_t *mesh, node_t *n, vpn_packet_t *packet) { - node_t *via; - if(n == mesh->self) { n->out_packets++; n->out_bytes += packet->len; diff --git a/src/net_setup.c b/src/net_setup.c index 69b6e86a..e8ed9487 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -265,9 +265,8 @@ static bool add_listen_address(meshlink_handle_t *mesh, char *address, bool bind Configure node_t mesh->self and set up the local sockets (listen only) */ bool setup_myself(meshlink_handle_t *mesh) { - char *name, *hostname, *cipher, *digest, *type; + char *name; char *address = NULL; - bool port_specified = false; if(!(name = get_name(mesh))) { logger(DEBUG_ALWAYS, LOG_ERR, "Name for tinc daemon required!"); @@ -282,8 +281,6 @@ bool setup_myself(meshlink_handle_t *mesh) { if(!get_config_string(lookup_config(mesh->config, "Port"), &mesh->myport)) mesh->myport = xstrdup("655"); - else - port_specified = true; mesh->self->connection->options = 0; mesh->self->connection->protocol_major = PROT_MAJOR; @@ -333,7 +330,6 @@ bool setup_myself(meshlink_handle_t *mesh) { /* Open sockets */ mesh->listen_sockets = 0; - int cfgs = 0; if(!add_listen_address(mesh, address, NULL)) return false; diff --git a/src/net_socket.c b/src/net_socket.c index 16019545..c6fc1242 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -43,8 +43,6 @@ int max_connection_burst = 100; /* Setup sockets */ static void configure_tcp(connection_t *c) { - int option; - #ifdef O_NONBLOCK int flags = fcntl(c->socket, F_GETFL); @@ -102,7 +100,6 @@ int setup_listen_socket(const sockaddr_t *sa) { int nfd; char *addrstr; int option; - char *iface; nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP); diff --git a/src/protocol.c b/src/protocol.c index 4018ef0e..a279833b 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -156,7 +156,7 @@ static int past_request_compare(const past_request_t *a, const past_request_t *b static void free_past_request(past_request_t *r) { if(r->request) - free(r->request); + free((void *)r->request); free(r); } diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 908f5656..9bd5ffca 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -135,7 +135,7 @@ bool send_id(meshlink_handle_t *mesh, connection_t *c) { return send_request(mesh, c, "%d %s %d.%d", ID, mesh->self->connection->name, mesh->self->connection->protocol_major, minor); } -static bool finalize_invitation(meshlink_handle_t *mesh, connection_t *c, const char *data, uint16_t len) { +static bool finalize_invitation(meshlink_handle_t *mesh, connection_t *c, const void *data, uint16_t len) { if(strchr(data, '\n')) { logger(DEBUG_ALWAYS, LOG_ERR, "Received invalid key from invited node %s (%s)!\n", c->name, c->hostname); return false; @@ -155,7 +155,7 @@ static bool finalize_invitation(meshlink_handle_t *mesh, connection_t *c, const return false; } - fprintf(f, "ECDSAPublicKey = %s\n", data); + fprintf(f, "ECDSAPublicKey = %s\n", (const char *)data); fclose(f); logger(DEBUG_CONNECTIONS, LOG_INFO, "Key succesfully received from %s (%s)", c->name, c->hostname); @@ -169,7 +169,7 @@ static bool finalize_invitation(meshlink_handle_t *mesh, connection_t *c, const return true; } -static bool receive_invitation_sptps(void *handle, uint8_t type, const char *data, uint16_t len) { +static bool receive_invitation_sptps(void *handle, uint8_t type, const void *data, uint16_t len) { connection_t *c = handle; meshlink_handle_t *mesh = c->mesh; @@ -357,7 +357,6 @@ bool send_ack(meshlink_handle_t *mesh, connection_t *c) { to create node_t and edge_t structures. */ struct timeval now; - bool choice; /* Estimate weight */ @@ -384,10 +383,9 @@ static void send_everything(meshlink_handle_t *mesh, connection_t *c) { bool ack_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { char hisport[MAX_STRING_SIZE]; char *hisaddress; - int weight, mtu; + int weight; uint32_t options; node_t *n; - bool choice; if(sscanf(request, "%*d " MAX_STRING " %d %x", hisport, &weight, &options) != 3) { logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "ACK", c->name, diff --git a/src/protocol_key.c b/src/protocol_key.c index b1be1866..0746e1c2 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -31,8 +31,6 @@ #include "utils.h" #include "xalloc.h" -static bool mykeyused = false; - void send_key_changed(meshlink_handle_t *mesh) { send_request(mesh, mesh->everyone, "%d %x %s", KEY_CHANGED, rand(), mesh->self->name); @@ -71,7 +69,7 @@ bool key_changed_h(meshlink_handle_t *mesh, connection_t *c, const char *request return true; } -static bool send_initial_sptps_data(void *handle, uint8_t type, const char *data, size_t len) { +static bool send_initial_sptps_data(void *handle, uint8_t type, const void *data, size_t len) { node_t *to = handle; meshlink_handle_t *mesh = to->mesh; to->sptps.send_data = send_sptps_data; @@ -244,7 +242,7 @@ bool ans_key_h(meshlink_handle_t *mesh, connection_t *c, const char *request) { char key[MAX_STRING_SIZE]; char address[MAX_STRING_SIZE] = ""; char port[MAX_STRING_SIZE] = ""; - int cipher, digest, maclength, compression, keylen; + int cipher, digest, maclength, compression; node_t *from, *to; if(sscanf(request, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d "MAX_STRING" "MAX_STRING, diff --git a/src/route.c b/src/route.c index daf8a154..de81c2b6 100644 --- a/src/route.c +++ b/src/route.c @@ -43,7 +43,7 @@ void route(meshlink_handle_t *mesh, node_t *source, vpn_packet_t *packet) { node_t *owner = NULL; node_t *via = NULL; meshlink_packethdr_t *hdr = (meshlink_packethdr_t *) packet->data; - owner = lookup_node(mesh, hdr->destination); + owner = lookup_node(mesh, (char *)hdr->destination); logger(DEBUG_TRAFFIC, LOG_WARNING, "Routing packet from: %s . To: %s \n", hdr->source, hdr->destination); diff --git a/src/sptps.c b/src/sptps.c index 133f2b7e..e03b18a8 100644 --- a/src/sptps.c +++ b/src/sptps.c @@ -80,7 +80,7 @@ static void warning(sptps_t *s, const char *format, ...) { } // Send a record (datagram version, accepts all record types, handles encryption and authentication). -static bool send_record_priv_datagram(sptps_t *s, uint8_t type, const char *data, uint16_t len) { +static bool send_record_priv_datagram(sptps_t *s, uint8_t type, const void *data, uint16_t len) { char buffer[len + 21UL]; // Create header with sequence number, length and record type @@ -101,7 +101,7 @@ static bool send_record_priv_datagram(sptps_t *s, uint8_t type, const char *data } } // Send a record (private version, accepts all record types, handles encryption and authentication). -static bool send_record_priv(sptps_t *s, uint8_t type, const char *data, uint16_t len) { +static bool send_record_priv(sptps_t *s, uint8_t type, const void *data, uint16_t len) { if(s->datagram) return send_record_priv_datagram(s, type, data, len); @@ -126,7 +126,7 @@ static bool send_record_priv(sptps_t *s, uint8_t type, const char *data, uint16_ } // Send an application record. -bool sptps_send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len) { +bool sptps_send_record(sptps_t *s, uint8_t type, const void *data, uint16_t len) { // Sanity checks: application cannot send data before handshake is finished, // and only record types 0..127 are allowed. if(!s->outstate) @@ -370,7 +370,7 @@ static bool receive_handshake(sptps_t *s, const char *data, uint16_t len) { } // Check datagram for valid HMAC -bool sptps_verify_datagram(sptps_t *s, const char *data, size_t len) { +bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len) { if(!s->instate || len < 21) return error(s, EIO, "Received short packet"); @@ -380,7 +380,9 @@ bool sptps_verify_datagram(sptps_t *s, const char *data, size_t len) { } // Receive incoming data, datagram version. -static bool sptps_receive_data_datagram(sptps_t *s, const char *data, size_t len) { +static bool sptps_receive_data_datagram(sptps_t *s, const void *vdata, size_t len) { + const char *data = vdata; + if(len < (s->instate ? 21 : 5)) return error(s, EIO, "Received short packet"); @@ -467,7 +469,7 @@ static bool sptps_receive_data_datagram(sptps_t *s, const char *data, size_t len } // Receive incoming data. Check if it contains a complete record, if so, handle it. -bool sptps_receive_data(sptps_t *s, const char *data, size_t len) { +bool sptps_receive_data(sptps_t *s, const void *data, size_t len) { if(!s->state) return error(s, EIO, "Invalid session state zero"); diff --git a/src/sptps.h b/src/sptps.h index 9754811c..ab163442 100644 --- a/src/sptps.h +++ b/src/sptps.h @@ -39,8 +39,8 @@ #define SPTPS_SIG 3 // Waiting for a SIGnature record #define SPTPS_ACK 4 // Waiting for an ACKnowledgement record -typedef bool (*send_data_t)(void *handle, uint8_t type, const char *data, size_t len); -typedef bool (*receive_record_t)(void *handle, uint8_t type, const char *data, uint16_t len); +typedef bool (*send_data_t)(void *handle, uint8_t type, const void *data, size_t len); +typedef bool (*receive_record_t)(void *handle, uint8_t type, const void *data, uint16_t len); typedef struct sptps { bool initiator; @@ -83,9 +83,9 @@ extern void sptps_log_stderr(sptps_t *s, int s_errno, const char *format, va_lis extern void (*sptps_log)(sptps_t *s, int s_errno, const char *format, va_list ap); extern bool sptps_start(sptps_t *s, void *handle, bool initiator, bool datagram, ecdsa_t *mykey, ecdsa_t *hiskey, const char *label, size_t labellen, send_data_t send_data, receive_record_t receive_record); extern bool sptps_stop(sptps_t *s); -extern bool sptps_send_record(sptps_t *s, uint8_t type, const char *data, uint16_t len); -extern bool sptps_receive_data(sptps_t *s, const char *data, size_t len); +extern bool sptps_send_record(sptps_t *s, uint8_t type, const void *data, uint16_t len); +extern bool sptps_receive_data(sptps_t *s, const void *data, size_t len); extern bool sptps_force_kex(sptps_t *s); -extern bool sptps_verify_datagram(sptps_t *s, const char *data, size_t len); +extern bool sptps_verify_datagram(sptps_t *s, const void *data, size_t len); #endif diff --git a/src/sptps_speed.c b/src/sptps_speed.c index 50db8b10..19ac6263 100644 --- a/src/sptps_speed.c +++ b/src/sptps_speed.c @@ -34,13 +34,13 @@ bool send_meta(void *c, const char *msg , int len) { return false; } char *logfilename = NULL; struct timeval now; -static bool send_data(void *handle, uint8_t type, const char *data, size_t len) { +static bool send_data(void *handle, uint8_t type, const void *data, size_t len) { int fd = *(int *)handle; send(fd, data, len, 0); return true; } -static bool receive_record(void *handle, uint8_t type, const char *data, uint16_t len) { +static bool receive_record(void *handle, uint8_t type, const void *data, uint16_t len) { return true; } diff --git a/src/sptps_test.c b/src/sptps_test.c index e9cab253..550e0db2 100644 --- a/src/sptps_test.c +++ b/src/sptps_test.c @@ -45,7 +45,7 @@ static bool writeonly; static int in = 0; static int out = 1; -static bool send_data(void *handle, uint8_t type, const char *data, size_t len) { +static bool send_data(void *handle, uint8_t type, const void *data, size_t len) { char hex[len * 2 + 1]; bin2hex(data, hex, len); if(verbose) @@ -56,7 +56,7 @@ static bool send_data(void *handle, uint8_t type, const char *data, size_t len) return true; } -static bool receive_record(void *handle, uint8_t type, const char *data, uint16_t len) { +static bool receive_record(void *handle, uint8_t type, const void *data, uint16_t len) { if(verbose) fprintf(stderr, "Received type %d record of %hu bytes:\n", type, len); if(!writeonly) diff --git a/src/utils.c b/src/utils.c index 5111fe1d..e45e5942 100644 --- a/src/utils.c +++ b/src/utils.c @@ -51,14 +51,16 @@ static int charhex2bin(char c) { return toupper(c) - 'A' + 10; } -int hex2bin(const char *src, char *dst, int length) { +int hex2bin(const char *src, void *vdst, int length) { + uint8_t *dst = vdst; int i; for(i = 0; i < length && isxdigit(src[i * 2]) && isxdigit(src[i * 2 + 1]); i++) dst[i] = charhex2bin(src[i * 2]) * 16 + charhex2bin(src[i * 2 + 1]); return i; } -int bin2hex(const char *src, char *dst, int length) { +int bin2hex(const void *vsrc, char *dst, int length) { + const uint8_t *src = vsrc; for(int i = length - 1; i >= 0; i--) { dst[i * 2 + 1] = hexadecimals[(unsigned char) src[i] & 15]; dst[i * 2] = hexadecimals[(unsigned char) src[i] >> 4]; @@ -67,10 +69,10 @@ int bin2hex(const char *src, char *dst, int length) { return length * 2; } -int b64decode(const char *src, char *dst, int length) { +int b64decode(const char *src, void *dst, int length) { int i; uint32_t triplet = 0; - unsigned char *udst = (unsigned char *)dst; + unsigned char *udst = dst; for(i = 0; i < length / 3 * 4 && src[i]; i++) { triplet |= base64_decode[src[i] & 0xff] << (6 * (i & 3)); @@ -98,9 +100,9 @@ int b64decode(const char *src, char *dst, int length) { } } -static int b64encode_internal(const char *src, char *dst, int length, const char *alphabet) { +static int b64encode_internal(const void *src, char *dst, int length, const char *alphabet) { uint32_t triplet; - const unsigned char *usrc = (unsigned char *)src; + const unsigned char *usrc = src; int si = length / 3 * 3; int di = length / 3 * 4; @@ -139,11 +141,11 @@ static int b64encode_internal(const char *src, char *dst, int length, const char return length; } -int b64encode(const char *src, char *dst, int length) { +int b64encode(const void *src, char *dst, int length) { return b64encode_internal(src, dst, length, base64_original); } -int b64encode_urlsafe(const char *src, char *dst, int length) { +int b64encode_urlsafe(const void *src, char *dst, int length) { return b64encode_internal(src, dst, length, base64_urlsafe); } diff --git a/src/utils.h b/src/utils.h index b2a90e73..c0e20e0b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -20,12 +20,12 @@ #ifndef __TINC_UTILS_H__ #define __TINC_UTILS_H__ -extern int hex2bin(const char *src, char *dst, int length); -extern int bin2hex(const char *src, char *dst, int length); +extern int hex2bin(const char *src, void *dst, int length); +extern int bin2hex(const void *src, char *dst, int length); -extern int b64encode(const char *src, char *dst, int length); -extern int b64encode_urlsafe(const char *src, char *dst, int length); -extern int b64decode(const char *src, char *dst, int length); +extern int b64encode(const void *src, char *dst, int length); +extern int b64encode_urlsafe(const void *src, char *dst, int length); +extern int b64decode(const char *src, void *dst, int length); #ifdef HAVE_MINGW extern const char *winerror(int);