Mostly by using void pointers for opaque objects and removing unused variables.
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);
-}
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);
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:
#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;
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;
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!");
return true;
}
- if(!data)
+ if(!request)
return true;
/* Are we receiving a TCPpacket? */
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) {
#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 *);
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 *);
}
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;
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;
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;
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;
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!");
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;
/* Open sockets */
mesh->listen_sockets = 0;
- int cfgs = 0;
if(!add_listen_address(mesh, address, NULL))
return false;
/* Setup sockets */
static void configure_tcp(connection_t *c) {
- int option;
-
#ifdef O_NONBLOCK
int flags = fcntl(c->socket, F_GETFL);
int nfd;
char *addrstr;
int option;
- char *iface;
nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP);
static void free_past_request(past_request_t *r) {
if(r->request)
- free(r->request);
+ free((void *)r->request);
free(r);
}
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;
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);
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;
to create node_t and edge_t structures. */
struct timeval now;
- bool choice;
/* Estimate weight */
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,
#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);
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;
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,
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);
}
// 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
}
}
// 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);
}
// 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)
}
// 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");
}
// 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");
}
// 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");
#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;
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
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;
}
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)
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)
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];
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));
}
}
-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;
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);
}
#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);