Fix whitespace.

This commit is contained in:
Guus Sliepen 2012-10-10 17:17:49 +02:00
parent 58f4b845b9
commit d917c8cb6b
73 changed files with 474 additions and 478 deletions

View file

@ -78,7 +78,7 @@ static bool setup_device(void) {
if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) { if(get_config_string(lookup_config(config_tree, "DeviceType"), &type)) {
if(!strcasecmp(type, "tun")) if(!strcasecmp(type, "tun"))
/* use default */; /* use default */;
#ifdef HAVE_TUNEMU #ifdef HAVE_TUNEMU
else if(!strcasecmp(type, "tunemu")) else if(!strcasecmp(type, "tunemu"))
device_type = DEVICE_TYPE_TUNEMU; device_type = DEVICE_TYPE_TUNEMU;
@ -102,7 +102,7 @@ static bool setup_device(void) {
#ifdef HAVE_TUNEMU #ifdef HAVE_TUNEMU
case DEVICE_TYPE_TUNEMU: { case DEVICE_TYPE_TUNEMU: {
char dynamic_name[256] = ""; char dynamic_name[256] = "";
device_fd = tunemu_open(dynamic_name); device_fd = tunemu_open(dynamic_name);
} }
break; break;
#endif #endif
@ -124,7 +124,7 @@ static bool setup_device(void) {
device_type = DEVICE_TYPE_TUN; device_type = DEVICE_TYPE_TUN;
case DEVICE_TYPE_TUN: case DEVICE_TYPE_TUN:
#ifdef TUNSIFHEAD #ifdef TUNSIFHEAD
{ {
const int zero = 0; const int zero = 0;
if(ioctl(device_fd, TUNSIFHEAD, &zero, sizeof zero) == -1) { if(ioctl(device_fd, TUNSIFHEAD, &zero, sizeof zero) == -1) {
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "ioctl", strerror(errno)); logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "ioctl", strerror(errno));
@ -173,12 +173,12 @@ static bool setup_device(void) {
iface = xstrdup(ifr.ifr_name); iface = xstrdup(ifr.ifr_name);
} }
} }
#endif #endif
break; break;
#ifdef HAVE_TUNEMU #ifdef HAVE_TUNEMU
case DEVICE_TYPE_TUNEMU: case DEVICE_TYPE_TUNEMU:
device_info = "BSD tunemu device"; device_info = "BSD tunemu device";
break; break;
#endif #endif
} }
@ -288,7 +288,7 @@ static bool read_packet(vpn_packet_t *packet) {
default: default:
return false; return false;
} }
device_total_in += packet->len; device_total_in += packet->len;
logger(DEBUG_TRAFFIC, LOG_DEBUG, "Read packet of %d bytes from %s", logger(DEBUG_TRAFFIC, LOG_DEBUG, "Read packet of %d bytes from %s",
@ -314,7 +314,7 @@ static bool write_packet(vpn_packet_t *packet) {
u_int32_t type; u_int32_t type;
struct iovec vector[2] = {{&type, sizeof type}, {packet->data + 14, packet->len - 14}}; struct iovec vector[2] = {{&type, sizeof type}, {packet->data + 14, packet->len - 14}};
int af; int af;
af = (packet->data[12] << 8) + packet->data[13]; af = (packet->data[12] << 8) + packet->data[13];
switch (af) { switch (af) {
@ -338,7 +338,7 @@ static bool write_packet(vpn_packet_t *packet) {
} }
break; break;
} }
case DEVICE_TYPE_TAP: case DEVICE_TYPE_TAP:
if(write(device_fd, packet->data, packet->len) < 0) { if(write(device_fd, packet->data, packet->len) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "Error while writing to %s %s: %s", device_info, logger(DEBUG_ALWAYS, LOG_ERR, "Error while writing to %s %s: %s", device_info,

View file

@ -1,20 +1,20 @@
/* /*
* tunemu - Tun device emulation for Darwin * tunemu - Tun device emulation for Darwin
* Copyright (C) 2009 Friedrich Schöller <friedrich.schoeller@gmail.com> * Copyright (C) 2009 Friedrich Schöller <friedrich.schoeller@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "tunemu.h" #include "tunemu.h"
@ -36,18 +36,18 @@
#define PPPPROTO_CTL 1 #define PPPPROTO_CTL 1
#define PPP_IP 0x21 #define PPP_IP 0x21
#define PPP_IPV6 0x57 #define PPP_IPV6 0x57
#define SC_LOOP_TRAFFIC 0x00000200 #define SC_LOOP_TRAFFIC 0x00000200
#define PPPIOCNEWUNIT _IOWR('t', 62, int) #define PPPIOCNEWUNIT _IOWR('t', 62, int)
#define PPPIOCSFLAGS _IOW('t', 89, int) #define PPPIOCSFLAGS _IOW('t', 89, int)
#define PPPIOCSNPMODE _IOW('t', 75, struct npioctl) #define PPPIOCSNPMODE _IOW('t', 75, struct npioctl)
#define PPPIOCATTCHAN _IOW('t', 56, int) #define PPPIOCATTCHAN _IOW('t', 56, int)
#define PPPIOCGCHAN _IOR('t', 55, int) #define PPPIOCGCHAN _IOR('t', 55, int)
#define PPPIOCCONNECT _IOW('t', 58, int) #define PPPIOCCONNECT _IOW('t', 58, int)
#define PPPIOCGUNIT _IOR('t', 86, int) #define PPPIOCGUNIT _IOR('t', 86, int)
struct sockaddr_ppp struct sockaddr_ppp
{ {

View file

@ -1,20 +1,20 @@
/* /*
* tunemu - Tun device emulation for Darwin * tunemu - Tun device emulation for Darwin
* Copyright (C) 2009 Friedrich Schöller <friedrich.schoeller@gmail.com> * Copyright (C) 2009 Friedrich Schöller <friedrich.schoeller@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#ifndef TUNEMU_H #ifndef TUNEMU_H

View file

@ -57,7 +57,7 @@ char *buffer_prepare(buffer_t *buffer, int size) {
} }
// Copy data into the buffer. // 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, int size) {
memcpy(buffer_prepare(buffer, size), data, size); memcpy(buffer_prepare(buffer, size), data, size);
} }

View file

@ -4,7 +4,7 @@
1998-2005 Ivo Timmermans 1998-2005 Ivo Timmermans
2000-2012 Guus Sliepen <guus@tinc-vpn.org> 2000-2012 Guus Sliepen <guus@tinc-vpn.org>
2010-2011 Julien Muchembled <jm@jmuchemb.eu> 2010-2011 Julien Muchembled <jm@jmuchemb.eu>
2000 Cris van Pelt 2000 Cris van Pelt
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -28,18 +28,18 @@
#include "conf.h" #include "conf.h"
#include "list.h" #include "list.h"
#include "logger.h" #include "logger.h"
#include "netutl.h" /* for str2address */ #include "netutl.h" /* for str2address */
#include "protocol.h" #include "protocol.h"
#include "utils.h" /* for cp */ #include "utils.h" /* for cp */
#include "xalloc.h" #include "xalloc.h"
splay_tree_t *config_tree; splay_tree_t *config_tree;
int pinginterval = 0; /* seconds between pings */ int pinginterval = 0; /* seconds between pings */
int pingtimeout = 0; /* seconds to wait for response */ int pingtimeout = 0; /* seconds to wait for response */
char *confbase = NULL; /* directory in which all config files are */ char *confbase = NULL; /* directory in which all config files are */
char *netname = NULL; /* name of the vpn network */ char *netname = NULL; /* name of the vpn network */
list_t *cmdline_conf = NULL; /* global/host configuration values given at the command line */ list_t *cmdline_conf = NULL; /* global/host configuration values given at the command line */
static int config_compare(const config_t *a, const config_t *b) { static int config_compare(const config_t *a, const config_t *b) {
@ -236,8 +236,9 @@ static char *readline(FILE * fp, char *buf, size_t buflen) {
if(!newline) if(!newline)
return buf; return buf;
*newline = '\0'; /* kill newline */ /* kill newline and carriage return if necessary */
if(newline > p && newline[-1] == '\r') /* and carriage return if necessary */ *newline = '\0';
if(newline > p && newline[-1] == '\r')
newline[-1] = '\0'; newline[-1] = '\0';
return buf; return buf;
@ -321,7 +322,7 @@ bool read_config_file(splay_tree_t *config_tree, const char *fname) {
ignore = false; ignore = false;
continue; continue;
} }
if(!strncmp(line, "-----BEGIN", 10)) { if(!strncmp(line, "-----BEGIN", 10)) {
ignore = true; ignore = true;
continue; continue;
@ -376,9 +377,8 @@ bool read_server_config(void) {
xasprintf(&fname, "%s" SLASH "tinc.conf", confbase); xasprintf(&fname, "%s" SLASH "tinc.conf", confbase);
x = read_config_file(config_tree, fname); x = read_config_file(config_tree, fname);
if(!x) { /* System error: complain */ if(!x)
logger(DEBUG_ALWAYS, LOG_ERR, "Failed to read `%s': %s", fname, strerror(errno)); logger(DEBUG_ALWAYS, LOG_ERR, "Failed to read `%s': %s", fname, strerror(errno));
}
free(fname); free(fname);

View file

@ -63,4 +63,4 @@ extern bool read_server_config(void);
extern bool read_host_config(splay_tree_t *, const char *); extern bool read_host_config(splay_tree_t *, const char *);
extern bool append_config_file(const char *, const char *, const char *); extern bool append_config_file(const char *, const char *, const char *);
#endif /* __TINC_CONF_H__ */ #endif /* __TINC_CONF_H__ */

View file

@ -31,7 +31,7 @@
#include "utils.h" #include "utils.h"
#include "xalloc.h" #include "xalloc.h"
list_t *connection_list; /* Meta connections */ list_t *connection_list;
connection_t *everyone; connection_t *everyone;
void init_connections(void) { void init_connections(void) {
@ -67,7 +67,7 @@ void free_connection(connection_t *c) {
buffer_clear(&c->inbuf); buffer_clear(&c->inbuf);
buffer_clear(&c->outbuf); buffer_clear(&c->outbuf);
if(event_initialized(&c->inevent)) if(event_initialized(&c->inevent))
event_del(&c->inevent); event_del(&c->inevent);

View file

@ -28,25 +28,25 @@
#include "list.h" #include "list.h"
#include "sptps.h" #include "sptps.h"
#define OPTION_INDIRECT 0x0001 #define OPTION_INDIRECT 0x0001
#define OPTION_TCPONLY 0x0002 #define OPTION_TCPONLY 0x0002
#define OPTION_PMTU_DISCOVERY 0x0004 #define OPTION_PMTU_DISCOVERY 0x0004
#define OPTION_CLAMP_MSS 0x0008 #define OPTION_CLAMP_MSS 0x0008
#define OPTION_VERSION(x) ((x) >> 24) /* Top 8 bits are for protocol minor version */ #define OPTION_VERSION(x) ((x) >> 24) /* Top 8 bits are for protocol minor version */
typedef struct connection_status_t { typedef struct connection_status_t {
unsigned int pinged:1; /* sent ping */ unsigned int pinged:1; /* sent ping */
unsigned int active:1; /* 1 if active.. */ unsigned int active:1; /* 1 if active.. */
unsigned int connecting:1; /* 1 if we are waiting for a non-blocking connect() to finish */ unsigned int connecting:1; /* 1 if we are waiting for a non-blocking connect() to finish */
unsigned int unused_termreq:1; /* the termination of this connection was requested */ unsigned int unused_termreq:1; /* the termination of this connection was requested */
unsigned int remove_unused:1; /* Set to 1 if you want this connection removed */ unsigned int remove_unused:1; /* Set to 1 if you want this connection removed */
unsigned int timeout_unused:1; /* 1 if gotten timeout */ unsigned int timeout_unused:1; /* 1 if gotten timeout */
unsigned int encryptout:1; /* 1 if we can encrypt outgoing traffic */ unsigned int encryptout:1; /* 1 if we can encrypt outgoing traffic */
unsigned int decryptin:1; /* 1 if we have to decrypt incoming traffic */ unsigned int decryptin:1; /* 1 if we have to decrypt incoming traffic */
unsigned int mst:1; /* 1 if this connection is part of a minimum spanning tree */ unsigned int mst:1; /* 1 if this connection is part of a minimum spanning tree */
unsigned int control:1; /* 1 if this is a control connection */ unsigned int control:1; /* 1 if this is a control connection */
unsigned int pcap:1; /* 1 if this is a control connection requesting packet capture */ unsigned int pcap:1; /* 1 if this is a control connection requesting packet capture */
unsigned int log:1; /* 1 if this is a control connection requesting log dump */ unsigned int log:1; /* 1 if this is a control connection requesting log dump */
unsigned int unused:20; unsigned int unused:20;
} connection_status_t; } connection_status_t;
@ -56,27 +56,27 @@ typedef struct connection_status_t {
#include "node.h" #include "node.h"
typedef struct connection_t { typedef struct connection_t {
char *name; /* name he claims to have */ char *name; /* name he claims to have */
union sockaddr_t address; /* his real (internet) ip */ union sockaddr_t address; /* his real (internet) ip */
char *hostname; /* the hostname of its real ip */ char *hostname; /* the hostname of its real ip */
int protocol_major; /* used protocol */ int protocol_major; /* used protocol */
int protocol_minor; /* used protocol */ int protocol_minor; /* used protocol */
int socket; /* socket used for this connection */ int socket; /* socket used for this connection */
uint32_t options; /* options for this connection */ uint32_t options; /* options for this connection */
connection_status_t status; /* status info */ connection_status_t status; /* status info */
int estimated_weight; /* estimation for the weight of the edge for this connection */ int estimated_weight; /* estimation for the weight of the edge for this connection */
struct timeval start; /* time this connection was started, used for above estimation */ struct timeval start; /* time this connection was started, used for above estimation */
struct outgoing_t *outgoing; /* used to keep track of outgoing connections */ struct outgoing_t *outgoing; /* used to keep track of outgoing connections */
struct node_t *node; /* node associated with the other end */ struct node_t *node; /* node associated with the other end */
struct edge_t *edge; /* edge associated with this connection */ struct edge_t *edge; /* edge associated with this connection */
rsa_t rsa; /* his public RSA key */ rsa_t rsa; /* his public RSA key */
ecdsa_t ecdsa; /* his public ECDSA key */ ecdsa_t ecdsa; /* his public ECDSA key */
cipher_t incipher; /* Cipher he will use to send data to us */ cipher_t incipher; /* Cipher he will use to send data to us */
cipher_t outcipher; /* Cipher we will use to send data to him */ cipher_t outcipher; /* Cipher we will use to send data to him */
digest_t indigest; digest_t indigest;
digest_t outdigest; digest_t outdigest;
sptps_t sptps; sptps_t sptps;
@ -86,18 +86,18 @@ typedef struct connection_t {
int incompression; int incompression;
int outcompression; int outcompression;
char *hischallenge; /* The challenge we sent to him */ char *hischallenge; /* The challenge we sent to him */
struct buffer_t inbuf; struct buffer_t inbuf;
struct buffer_t outbuf; struct buffer_t outbuf;
struct event inevent; /* input event on this metadata connection */ struct event inevent; /* input event on this metadata connection */
struct event outevent; /* output event on this metadata connection */ struct event outevent; /* output event on this metadata connection */
int tcplen; /* length of incoming TCPpacket */ int tcplen; /* length of incoming TCPpacket */
int allow_request; /* defined if there's only one request possible */ int allow_request; /* defined if there's only one request possible */
time_t last_ping_time; /* last time we saw some activity from the other end or pinged them */ time_t last_ping_time; /* last time we saw some activity from the other end or pinged them */
splay_tree_t *config_tree; /* Pointer to configuration tree belonging to him */ splay_tree_t *config_tree; /* Pointer to configuration tree belonging to him */
} connection_t; } connection_t;
extern list_t *connection_list; extern list_t *connection_list;
@ -111,4 +111,4 @@ extern void connection_add(connection_t *);
extern void connection_del(connection_t *); extern void connection_del(connection_t *);
extern bool dump_connections(struct connection_t *); extern bool dump_connections(struct connection_t *);
#endif /* __TINC_CONNECTION_H__ */ #endif /* __TINC_CONNECTION_H__ */

View file

@ -63,7 +63,7 @@ bool control_h(connection_t *c, const char *request) {
case REQ_DUMP_NODES: case REQ_DUMP_NODES:
return dump_nodes(c); return dump_nodes(c);
case REQ_DUMP_EDGES: case REQ_DUMP_EDGES:
return dump_edges(c); return dump_edges(c);

View file

@ -77,7 +77,7 @@ static bool setup_device(void) {
snprintf(regpath, sizeof regpath, "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid); snprintf(regpath, sizeof regpath, "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &key2)) if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &key2))
continue; continue;
len = sizeof adaptername; len = sizeof adaptername;
@ -127,7 +127,7 @@ static bool setup_device(void) {
iface = xstrdup(adaptername); iface = xstrdup(adaptername);
snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, device); snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, device);
/* Now we are going to open this device twice: once for reading and once for writing. /* Now we are going to open this device twice: once for reading and once for writing.
We do this because apparently it isn't possible to check for activity in the select() loop. We do this because apparently it isn't possible to check for activity in the select() loop.
Furthermore I don't really know how to do it the "Windows" way. */ Furthermore I don't really know how to do it the "Windows" way. */
@ -138,9 +138,9 @@ static bool setup_device(void) {
} }
/* The parent opens the tap device for writing. */ /* The parent opens the tap device for writing. */
device_handle = CreateFile(tapname, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM , 0); device_handle = CreateFile(tapname, GENERIC_WRITE, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM , 0);
if(device_handle == INVALID_HANDLE_VALUE) { if(device_handle == INVALID_HANDLE_VALUE) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not open Windows tap device %s (%s) for writing: %s", device, iface, winerror(GetLastError())); logger(DEBUG_ALWAYS, LOG_ERR, "Could not open Windows tap device %s (%s) for writing: %s", device, iface, winerror(GetLastError()));
return false; return false;
@ -171,7 +171,7 @@ static bool setup_device(void) {
if(!reader_pid) { if(!reader_pid) {
/* The child opens the tap device for reading, blocking. /* The child opens the tap device for reading, blocking.
It passes everything it reads to the socket. */ It passes everything it reads to the socket. */
char buf[MTU]; char buf[MTU];
long inlen; long inlen;
@ -233,7 +233,7 @@ static bool read_packet(vpn_packet_t *packet) {
device, strerror(errno)); device, strerror(errno));
return false; return false;
} }
packet->len = inlen; packet->len = inlen;
device_total_in += packet->len; device_total_in += packet->len;

View file

@ -48,4 +48,4 @@ extern const devops_t uml_devops;
extern const devops_t vde_devops; extern const devops_t vde_devops;
extern devops_t devops; extern devops_t devops;
#endif /* __TINC_DEVICE_H__ */ #endif /* __TINC_DEVICE_H__ */

View file

@ -25,7 +25,7 @@
#ifndef HAVE_DAEMON #ifndef HAVE_DAEMON
/* /*
Replacement for the daemon() function. Replacement for the daemon() function.
The daemon() function is for programs wishing to detach themselves The daemon() function is for programs wishing to detach themselves
from the controlling terminal and run in the background as system from the controlling terminal and run in the background as system
daemons. daemons.
@ -104,14 +104,14 @@ char *get_current_dir_name(void) {
size = 100; size = 100;
buf = xmalloc(size); buf = xmalloc(size);
errno = 0; /* Success */ errno = 0; /* Success */
r = getcwd(buf, size); r = getcwd(buf, size);
/* getcwd returns NULL and sets errno to ERANGE if the bufferspace /* getcwd returns NULL and sets errno to ERANGE if the bufferspace
is insufficient to contain the entire working directory. */ is insufficient to contain the entire working directory. */
while(r == NULL && errno == ERANGE) { while(r == NULL && errno == ERANGE) {
free(buf); free(buf);
size <<= 1; /* double the size */ size <<= 1; /* double the size */
buf = xmalloc(size); buf = xmalloc(size);
r = getcwd(buf, size); r = getcwd(buf, size);
} }

View file

@ -45,4 +45,4 @@ extern int gettimeofday(struct timeval *, void *);
extern int usleep(long long usec); extern int usleep(long long usec);
#endif #endif
#endif /* __DROPIN_H__ */ #endif /* __DROPIN_H__ */

View file

@ -29,7 +29,7 @@
#include "utils.h" #include "utils.h"
#include "xalloc.h" #include "xalloc.h"
splay_tree_t *edge_weight_tree; /* Tree with all edges, sorted on weight */ splay_tree_t *edge_weight_tree;
static int edge_compare(const edge_t *a, const edge_t *b) { static int edge_compare(const edge_t *a, const edge_t *b) {
return strcmp(a->to->name, b->to->name); return strcmp(a->to->name, b->to->name);
@ -99,7 +99,7 @@ void edge_del(edge_t *e) {
edge_t *lookup_edge(node_t *from, node_t *to) { edge_t *lookup_edge(node_t *from, node_t *to) {
edge_t v; edge_t v;
v.from = from; v.from = from;
v.to = to; v.to = to;

View file

@ -31,14 +31,14 @@ typedef struct edge_t {
struct node_t *to; struct node_t *to;
sockaddr_t address; sockaddr_t address;
uint32_t options; /* options turned on for this edge */ uint32_t options; /* options turned on for this edge */
int weight; /* weight of this edge */ int weight; /* weight of this edge */
struct connection_t *connection; /* connection associated with this edge, if available */ struct connection_t *connection; /* connection associated with this edge, if available */
struct edge_t *reverse; /* edge in the opposite direction, if available */ struct edge_t *reverse; /* edge in the opposite direction, if available */
} edge_t; } edge_t;
extern splay_tree_t *edge_weight_tree; /* Tree with all known edges sorted on weight */ extern splay_tree_t *edge_weight_tree; /* Tree with all known edges sorted on weight */
extern void init_edges(void); extern void init_edges(void);
extern void exit_edges(void); extern void exit_edges(void);
@ -51,4 +51,4 @@ extern void edge_del(edge_t *);
extern edge_t *lookup_edge(struct node_t *, struct node_t *); extern edge_t *lookup_edge(struct node_t *, struct node_t *);
extern bool dump_edges(struct connection_t *); extern bool dump_edges(struct connection_t *);
#endif /* __TINC_EDGE_H__ */ #endif /* __TINC_EDGE_H__ */

View file

@ -54,17 +54,17 @@ struct arphdr {
uint16_t ar_hrd; uint16_t ar_hrd;
uint16_t ar_pro; uint16_t ar_pro;
uint8_t ar_hln; uint8_t ar_hln;
uint8_t ar_pln; uint8_t ar_pln;
uint16_t ar_op; uint16_t ar_op;
} __attribute__ ((__packed__)); } __attribute__ ((__packed__));
#define ARPOP_REQUEST 1 #define ARPOP_REQUEST 1
#define ARPOP_REPLY 2 #define ARPOP_REPLY 2
#define ARPOP_RREQUEST 3 #define ARPOP_RREQUEST 3
#define ARPOP_RREPLY 4 #define ARPOP_RREPLY 4
#define ARPOP_InREQUEST 8 #define ARPOP_InREQUEST 8
#define ARPOP_InREPLY 9 #define ARPOP_InREPLY 9
#define ARPOP_NAK 10 #define ARPOP_NAK 10
#endif #endif
#ifndef HAVE_STRUCT_ETHER_ARP #ifndef HAVE_STRUCT_ETHER_ARP

View file

@ -7,13 +7,13 @@
/* for old netdb.h */ /* for old netdb.h */
#ifndef EAI_NODATA #ifndef EAI_NODATA
#define EAI_NODATA 1 #define EAI_NODATA 1
#endif #endif
#ifndef EAI_MEMORY #ifndef EAI_MEMORY
#define EAI_MEMORY 2 #define EAI_MEMORY 2
#endif #endif
#ifndef EAI_FAMILY #ifndef EAI_FAMILY
#define EAI_FAMILY 3 #define EAI_FAMILY 3
#endif #endif

View file

@ -29,7 +29,7 @@ char *gai_strerror(int ecode) {
default: default:
return "Unknown error"; return "Unknown error";
} }
} }
#endif /* !HAVE_GAI_STRERROR */ #endif /* !HAVE_GAI_STRERROR */
#if !HAVE_DECL_FREEADDRINFO #if !HAVE_DECL_FREEADDRINFO
@ -49,14 +49,14 @@ static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) {
struct addrinfo *ai; struct addrinfo *ai;
ai = xmalloc_and_zero(sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); ai = xmalloc_and_zero(sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
ai->ai_addr = (struct sockaddr *)(ai + 1); ai->ai_addr = (struct sockaddr *)(ai + 1);
ai->ai_addrlen = sizeof(struct sockaddr_in); ai->ai_addrlen = sizeof(struct sockaddr_in);
ai->ai_addr->sa_family = ai->ai_family = AF_INET; ai->ai_addr->sa_family = ai->ai_family = AF_INET;
((struct sockaddr_in *)(ai)->ai_addr)->sin_port = port; ((struct sockaddr_in *)(ai)->ai_addr)->sin_port = port;
((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr; ((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr;
return ai; return ai;
} }
@ -77,12 +77,12 @@ int getaddrinfo(const char *hostname, const char *servname, const struct addrinf
*res = malloc_ai(port, htonl(0x00000000)); *res = malloc_ai(port, htonl(0x00000000));
return 0; return 0;
} }
if (!hostname) { if (!hostname) {
*res = malloc_ai(port, htonl(0x7f000001)); *res = malloc_ai(port, htonl(0x7f000001));
return 0; return 0;
} }
hp = gethostbyname(hostname); hp = gethostbyname(hostname);
if(!hp || !hp->h_addr_list || !hp->h_addr_list[0]) if(!hp || !hp->h_addr_list || !hp->h_addr_list[0])

View file

@ -15,25 +15,24 @@
#endif #endif
#ifndef AI_NUMERICHOST #ifndef AI_NUMERICHOST
#define AI_NUMERICHOST 4 #define AI_NUMERICHOST 4
#endif #endif
#ifndef HAVE_STRUCT_ADDRINFO #ifndef HAVE_STRUCT_ADDRINFO
struct addrinfo { struct addrinfo {
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
int ai_family; /* PF_xxx */ int ai_family; /* PF_xxx */
int ai_socktype; /* SOCK_xxx */ int ai_socktype; /* SOCK_xxx */
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
size_t ai_addrlen; /* length of ai_addr */ size_t ai_addrlen; /* length of ai_addr */
char *ai_canonname; /* canonical name for hostname */ char *ai_canonname; /* canonical name for hostname */
struct sockaddr *ai_addr; /* binary address */ struct sockaddr *ai_addr; /* binary address */
struct addrinfo *ai_next; /* next structure in linked list */ struct addrinfo *ai_next; /* next structure in linked list */
}; };
#endif /* !HAVE_STRUCT_ADDRINFO */ #endif /* !HAVE_STRUCT_ADDRINFO */
#if !HAVE_DECL_GETADDRINFO #if !HAVE_DECL_GETADDRINFO
int getaddrinfo(const char *hostname, const char *servname, int getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res);
const struct addrinfo *hints, struct addrinfo **res);
#endif /* !HAVE_GETADDRINFO */ #endif /* !HAVE_GETADDRINFO */
#if !HAVE_DECL_GAI_STRERROR #if !HAVE_DECL_GAI_STRERROR

View file

@ -41,10 +41,10 @@ int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t host
} }
hp = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr), AF_INET); hp = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr), AF_INET);
if(!hp || !hp->h_name || !hp->h_name[0]) if(!hp || !hp->h_name || !hp->h_name[0])
return EAI_NODATA; return EAI_NODATA;
len = snprintf(host, hostlen, "%s", hp->h_name); len = snprintf(host, hostlen, "%s", hp->h_name);
if(len < 0 || len >= hostlen) if(len < 0 || len >= hostlen)
return EAI_MEMORY; return EAI_MEMORY;

View file

@ -2,8 +2,7 @@
#define _FAKE_GETNAMEINFO_H #define _FAKE_GETNAMEINFO_H
#if !HAVE_DECL_GETNAMEINFO #if !HAVE_DECL_GETNAMEINFO
int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags);
size_t hostlen, char *serv, size_t servlen, int flags);
#endif /* !HAVE_GETNAMEINFO */ #endif /* !HAVE_GETNAMEINFO */
#ifndef NI_MAXSERV #ifndef NI_MAXSERV

View file

@ -212,7 +212,7 @@ bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *ou
else else
pad[i] = padbyte; pad[i] = padbyte;
} }
if(oneshot) if(oneshot)
gcry_cipher_setiv(cipher->handle, cipher->key + cipher->keylen, cipher->blklen); gcry_cipher_setiv(cipher->handle, cipher->key + cipher->keylen, cipher->blklen);

View file

@ -85,7 +85,7 @@ static bool digest_open(digest_t *digest, int algo, int maclength) {
digest->maclength = len; digest->maclength = len;
else else
digest->maclength = maclength; digest->maclength = maclength;
digest->algo = algo; digest->algo = algo;
digest->hmac = NULL; digest->hmac = NULL;

View file

@ -148,7 +148,7 @@ static size_t ber_read_len(unsigned char **p, size_t *buflen) {
return *(*p)++; return *(*p)++;
} }
} }
static bool ber_read_sequence(unsigned char **p, size_t *buflen, size_t *result) { static bool ber_read_sequence(unsigned char **p, size_t *buflen, size_t *result) {
int tag = ber_read_id(p, buflen); int tag = ber_read_id(p, buflen);
@ -173,7 +173,7 @@ static bool ber_read_mpi(unsigned char **p, size_t *buflen, gcry_mpi_t *mpi) {
if(mpi) if(mpi)
err = gcry_mpi_scan(mpi, GCRYMPI_FMT_USG, *p, len, NULL); err = gcry_mpi_scan(mpi, GCRYMPI_FMT_USG, *p, len, NULL);
*p += len; *p += len;
*buflen -= len; *buflen -= len;

View file

@ -125,13 +125,13 @@ static void sssp_bfs(void) {
/* Loop while todo_list is filled */ /* Loop while todo_list is filled */
for list_each(node_t, n, todo_list) { /* "n" is the node from which we start */ for list_each(node_t, n, todo_list) { /* "n" is the node from which we start */
logger(DEBUG_SCARY_THINGS, LOG_DEBUG, " Examining edges from %s", n->name); logger(DEBUG_SCARY_THINGS, LOG_DEBUG, " Examining edges from %s", n->name);
if(n->distance < 0) if(n->distance < 0)
abort(); abort();
for splay_each(edge_t, e, n->edge_tree) { /* "e" is the edge connected to "from" */ for splay_each(edge_t, e, n->edge_tree) { /* "e" is the edge connected to "from" */
if(!e->reverse) if(!e->reverse)
continue; continue;

View file

@ -38,4 +38,4 @@ extern void *hash_search_or_insert(hash_t *, const void *key, const void *value)
extern void hash_clear(hash_t *); extern void hash_clear(hash_t *);
extern void hash_resize(hash_t *, size_t n); extern void hash_resize(hash_t *, size_t n);
#endif /* __TINC_HASH_H__ */ #endif /* __TINC_HASH_H__ */

View file

@ -28,9 +28,9 @@
void logger(int level, int priority, const char *format, ...) { void logger(int level, int priority, const char *format, ...) {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
vfprintf(stderr, format, ap); vfprintf(stderr, format, ap);
va_end(ap); va_end(ap);
} }
char *strip_weight(char *netstr) { char *strip_weight(char *netstr) {
@ -56,7 +56,7 @@ static int info_node(int fd, const char *item) {
char via[4096]; char via[4096];
char nexthop[4096]; char nexthop[4096];
int code, req, cipher, digest, maclength, compression, distance; int code, req, cipher, digest, maclength, compression, distance;
short int pmtu, minmtu, maxmtu; short int pmtu, minmtu, maxmtu;
unsigned int options; unsigned int options;
node_status_t status; node_status_t status;
long int last_state_change; long int last_state_change;
@ -87,7 +87,7 @@ static int info_node(int fd, const char *item) {
if(sscanf(line, "%d %d %s", &code, &req, node) == 2) if(sscanf(line, "%d %d %s", &code, &req, node) == 2)
break; break;
} }
printf("Node: %s\n", item); printf("Node: %s\n", item);
printf("Address: %s port %s\n", host, port); printf("Address: %s port %s\n", host, port);

View file

@ -72,7 +72,7 @@ struct ip {
#endif #endif
uint8_t ip_tos; uint8_t ip_tos;
uint16_t ip_len; uint16_t ip_len;
uint16_t ip_id; uint16_t ip_id;
uint16_t ip_off; uint16_t ip_off;
#define IP_RF 0x8000 #define IP_RF 0x8000
#define IP_DF 0x4000 #define IP_DF 0x4000

View file

@ -54,9 +54,9 @@ struct sockaddr_in6 {
#ifndef IN6_IS_ADDR_V4MAPPED #ifndef IN6_IS_ADDR_V4MAPPED
#define IN6_IS_ADDR_V4MAPPED(a) \ #define IN6_IS_ADDR_V4MAPPED(a) \
((((__const uint32_t *) (a))[0] == 0) \ ((((__const uint32_t *) (a))[0] == 0) \
&& (((__const uint32_t *) (a))[1] == 0) \ && (((__const uint32_t *) (a))[1] == 0) \
&& (((__const uint32_t *) (a))[2] == htonl (0xffff))) && (((__const uint32_t *) (a))[2] == htonl (0xffff)))
#endif #endif
#ifndef HAVE_STRUCT_IP6_HDR #ifndef HAVE_STRUCT_IP6_HDR

View file

@ -120,7 +120,7 @@ static void close_device(void) {
static bool read_packet(vpn_packet_t *packet) { static bool read_packet(vpn_packet_t *packet) {
int inlen; int inlen;
switch(device_type) { switch(device_type) {
case DEVICE_TYPE_TUN: case DEVICE_TYPE_TUN:
inlen = read(device_fd, packet->data + 10, MTU - 10); inlen = read(device_fd, packet->data + 10, MTU - 10);

View file

@ -81,4 +81,4 @@ extern void list_foreach_node(list_t *, list_action_node_t);
#define list_each(type, item, list) (type *item = (type *)1; item; item = NULL) for(list_node_t *node = (list)->head, *next; item = node ? node->data : NULL, next = node ? node->next : NULL, node; node = next) #define list_each(type, item, list) (type *item = (type *)1; item; item = NULL) for(list_node_t *node = (list)->head, *next; item = node ? node->data : NULL, next = node ? node->next : NULL, node; node = next)
#endif /* __TINC_LIST_H__ */ #endif /* __TINC_LIST_H__ */

View file

@ -40,7 +40,7 @@ bool logcontrol = false;
void openlogger(const char *ident, logmode_t mode) { void openlogger(const char *ident, logmode_t mode) {
logident = ident; logident = ident;
logmode = mode; logmode = mode;
switch(mode) { switch(mode) {
case LOGMODE_STDERR: case LOGMODE_STDERR:
logpid = getpid(); logpid = getpid();

View file

@ -2,16 +2,16 @@
#define __TINC_LOGGER_H__ #define __TINC_LOGGER_H__
typedef enum debug_t { typedef enum debug_t {
DEBUG_NOTHING = 0, /* Quiet mode, only show starting/stopping of the daemon */ DEBUG_NOTHING = 0, /* Quiet mode, only show starting/stopping of the daemon */
DEBUG_ALWAYS = 0, DEBUG_ALWAYS = 0,
DEBUG_CONNECTIONS = 1, /* Show (dis)connects of other tinc daemons via TCP */ DEBUG_CONNECTIONS = 1, /* Show (dis)connects of other tinc daemons via TCP */
DEBUG_ERROR = 2, /* Show error messages received from other hosts */ DEBUG_ERROR = 2, /* Show error messages received from other hosts */
DEBUG_STATUS = 2, /* Show status messages received from other hosts */ DEBUG_STATUS = 2, /* Show status messages received from other hosts */
DEBUG_PROTOCOL = 3, /* Show the requests that are sent/received */ DEBUG_PROTOCOL = 3, /* Show the requests that are sent/received */
DEBUG_META = 4, /* Show contents of every request that is sent/received */ DEBUG_META = 4, /* Show contents of every request that is sent/received */
DEBUG_TRAFFIC = 5, /* Show network traffic information */ DEBUG_TRAFFIC = 5, /* Show network traffic information */
DEBUG_PACKET = 6, /* Show contents of each packet that is being sent/received */ DEBUG_PACKET = 6, /* Show contents of each packet that is being sent/received */
DEBUG_SCARY_THINGS = 10 /* You have been warned */ DEBUG_SCARY_THINGS = 10 /* You have been warned */
} debug_t; } debug_t;
typedef enum logmode_t { typedef enum logmode_t {

View file

@ -189,7 +189,7 @@ bool receive_meta(connection_t *c) {
logger(DEBUG_CONNECTIONS, LOG_ERR, "Proxy request rejected"); logger(DEBUG_CONNECTIONS, LOG_ERR, "Proxy request rejected");
return false; return false;
} }
} else } else
receive_tcppacket(c, tcpbuffer, c->tcplen); receive_tcppacket(c, tcpbuffer, c->tcplen);
c->tcplen = 0; c->tcplen = 0;
continue; continue;

View file

@ -29,4 +29,4 @@ extern bool receive_meta_sptps(void *, uint8_t, const char *, uint16_t);
extern void broadcast_meta(struct connection_t *, const char *, int); extern void broadcast_meta(struct connection_t *, const char *, int);
extern bool receive_meta(struct connection_t *); extern bool receive_meta(struct connection_t *);
#endif /* __TINC_META_H__ */ #endif /* __TINC_META_H__ */

View file

@ -118,7 +118,7 @@ static bool setup_device(void) {
snprintf(regpath, sizeof regpath, "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid); snprintf(regpath, sizeof regpath, "%s\\%s\\Connection", NETWORK_CONNECTIONS_KEY, adapterid);
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &key2)) if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &key2))
continue; continue;
len = sizeof adaptername; len = sizeof adaptername;
@ -172,7 +172,7 @@ static bool setup_device(void) {
snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, device); snprintf(tapname, sizeof tapname, USERMODEDEVICEDIR "%s" TAPSUFFIX, device);
device_handle = CreateFile(tapname, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0); device_handle = CreateFile(tapname, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_OVERLAPPED, 0);
} }
if(device_handle == INVALID_HANDLE_VALUE) { if(device_handle == INVALID_HANDLE_VALUE) {
logger(DEBUG_ALWAYS, LOG_ERR, "%s (%s) is not a usable Windows tap device: %s", device, iface, winerror(GetLastError())); logger(DEBUG_ALWAYS, LOG_ERR, "%s (%s) is not a usable Windows tap device: %s", device, iface, winerror(GetLastError()));
return false; return false;

View file

@ -130,7 +130,7 @@ static bool setup_device(void) {
#endif #endif
} break; } break;
#endif #endif
default: default:
logger(DEBUG_ALWAYS, LOG_ERR, "Multicast for address family %hx unsupported", ai->ai_family); logger(DEBUG_ALWAYS, LOG_ERR, "Multicast for address family %hx unsupported", ai->ai_family);
goto error; goto error;

View file

@ -3,7 +3,7 @@
Copyright (C) 1998-2005 Ivo Timmermans, Copyright (C) 1998-2005 Ivo Timmermans,
2000-2012 Guus Sliepen <guus@tinc-vpn.org> 2000-2012 Guus Sliepen <guus@tinc-vpn.org>
2006 Scott Lamb <slamb@slamb.org> 2006 Scott Lamb <slamb@slamb.org>
2011 Loïc Grenié <loic.grenie@gmail.com> 2011 Loïc Grenié <loic.grenie@gmail.com>
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -239,9 +239,9 @@ int reload_configuration(void) {
read_config_options(config_tree, NULL); read_config_options(config_tree, NULL);
xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, myself->name); xasprintf(&fname, "%s" SLASH "hosts" SLASH "%s", confbase, myself->name);
read_config_file(config_tree, fname); read_config_file(config_tree, fname);
free(fname); free(fname);
/* Parse some options that are allowed to be changed while tinc is running */ /* Parse some options that are allowed to be changed while tinc is running */
@ -306,7 +306,7 @@ int reload_configuration(void) {
} }
/* Try to make outgoing connections */ /* Try to make outgoing connections */
try_outgoing_connections(); try_outgoing_connections();
/* Close connections to hosts that have a changed or deleted host config file */ /* Close connections to hosts that have a changed or deleted host config file */

View file

@ -26,15 +26,18 @@
#include "digest.h" #include "digest.h"
#ifdef ENABLE_JUMBOGRAMS #ifdef ENABLE_JUMBOGRAMS
#define MTU 9018 /* 9000 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */ #define MTU 9018 /* 9000 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */
#else #else
#define MTU 1518 /* 1500 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */ #define MTU 1518 /* 1500 bytes payload + 14 bytes ethernet header + 4 bytes VLAN tag */
#endif #endif
#define MAXSIZE (MTU + 4 + CIPHER_MAX_BLOCK_SIZE + DIGEST_MAX_SIZE + MTU/64 + 20) /* MTU + seqno + padding + HMAC + compressor overhead */ /* MAXSIZE is the maximum size of an encapsulated packet: MTU + seqno + padding + HMAC + compressor overhead */
#define MAXBUFSIZE ((MAXSIZE > 2048 ? MAXSIZE : 2048) + 128) /* Enough room for a request with a MAXSIZEd packet or a 8192 bits RSA key */ #define MAXSIZE (MTU + 4 + CIPHER_MAX_BLOCK_SIZE + DIGEST_MAX_SIZE + MTU/64 + 20)
#define MAXSOCKETS 8 /* Probably overkill... */ /* MAXBUFSIZE is the maximum size of a request: enough for a MAXSIZEd packet or a 8192 bits RSA key */
#define MAXBUFSIZE ((MAXSIZE > 2048 ? MAXSIZE : 2048) + 128)
#define MAXSOCKETS 8 /* Probably overkill... */
typedef struct mac_t { typedef struct mac_t {
uint8_t x[6]; uint8_t x[6];
@ -77,9 +80,9 @@ typedef union sockaddr_t {
#endif #endif
typedef struct vpn_packet_t { typedef struct vpn_packet_t {
length_t len; /* the actual number of bytes in the `data' field */ length_t len; /* the actual number of bytes in the `data' field */
int priority; /* priority or TOS */ int priority; /* priority or TOS */
uint32_t seqno; /* 32 bits sequence number (network byte order of course) */ uint32_t seqno; /* 32 bits sequence number (network byte order of course) */
uint8_t data[MAXSIZE]; uint8_t data[MAXSIZE];
} vpn_packet_t; } vpn_packet_t;
@ -194,4 +197,4 @@ extern void load_all_subnets(void);
extern CRITICAL_SECTION mutex; extern CRITICAL_SECTION mutex;
#endif #endif
#endif /* __TINC_NET_H__ */ #endif /* __TINC_NET_H__ */

View file

@ -80,7 +80,7 @@ bool localdiscovery = false;
static void send_mtu_probe_handler(int fd, short events, void *data) { static void send_mtu_probe_handler(int fd, short events, void *data) {
node_t *n = data; node_t *n = data;
int timeout = 1; int timeout = 1;
n->mtuprobes++; n->mtuprobes++;
if(!n->status.reachable || !n->status.validkey) { if(!n->status.reachable || !n->status.validkey) {
@ -135,7 +135,7 @@ static void send_mtu_probe_handler(int fd, short events, void *data) {
if(len < 64) if(len < 64)
len = 64; len = 64;
vpn_packet_t packet; vpn_packet_t packet;
memset(packet.data, 0, 14); memset(packet.data, 0, 14);
randomize(packet.data + 14, len - 14); randomize(packet.data + 14, len - 14);
@ -212,7 +212,7 @@ static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t l
return -1; return -1;
#endif #endif
} }
return -1; return -1;
} }
@ -294,7 +294,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
if(digest_active(&n->indigest)) { if(digest_active(&n->indigest)) {
inpkt->len -= n->indigest.maclength; inpkt->len -= n->indigest.maclength;
if(!digest_verify(&n->indigest, &inpkt->seqno, inpkt->len, (const char *)&inpkt->seqno + inpkt->len)) { if(!digest_verify(&n->indigest, &inpkt->seqno, inpkt->len, (const char *)&inpkt->seqno + inpkt->len)) {
logger(DEBUG_TRAFFIC, LOG_DEBUG, "Got unauthenticated packet from %s (%s)", n->name, n->hostname); logger(DEBUG_TRAFFIC, LOG_DEBUG, "Got unauthenticated packet from %s (%s)", n->name, n->hostname);
return; return;
} }
@ -309,7 +309,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
logger(DEBUG_TRAFFIC, LOG_DEBUG, "Error decrypting packet from %s (%s)", n->name, n->hostname); logger(DEBUG_TRAFFIC, LOG_DEBUG, "Error decrypting packet from %s (%s)", n->name, n->hostname);
return; return;
} }
outpkt->len = outlen; outpkt->len = outlen;
inpkt = outpkt; inpkt = outpkt;
} }
@ -328,12 +328,12 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
return; return;
} }
logger(DEBUG_ALWAYS, LOG_WARNING, "Lost %d packets from %s (%s)", logger(DEBUG_ALWAYS, LOG_WARNING, "Lost %d packets from %s (%s)",
inpkt->seqno - n->received_seqno - 1, n->name, n->hostname); inpkt->seqno - n->received_seqno - 1, n->name, n->hostname);
memset(n->late, 0, replaywin); memset(n->late, 0, replaywin);
} else if (inpkt->seqno <= n->received_seqno) { } else if (inpkt->seqno <= n->received_seqno) {
if((n->received_seqno >= replaywin * 8 && inpkt->seqno <= n->received_seqno - replaywin * 8) || !(n->late[(inpkt->seqno / 8) % replaywin] & (1 << inpkt->seqno % 8))) { if((n->received_seqno >= replaywin * 8 && inpkt->seqno <= n->received_seqno - replaywin * 8) || !(n->late[(inpkt->seqno / 8) % replaywin] & (1 << inpkt->seqno % 8))) {
logger(DEBUG_ALWAYS, LOG_WARNING, "Got late or replayed packet from %s (%s), seqno %d, last received %d", logger(DEBUG_ALWAYS, LOG_WARNING, "Got late or replayed packet from %s (%s), seqno %d, last received %d",
n->name, n->hostname, inpkt->seqno, n->received_seqno); n->name, n->hostname, inpkt->seqno, n->received_seqno);
return; return;
} }
} else { } else {
@ -348,7 +348,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
if(inpkt->seqno > n->received_seqno) if(inpkt->seqno > n->received_seqno)
n->received_seqno = inpkt->seqno; n->received_seqno = inpkt->seqno;
if(n->received_seqno > MAX_SEQNO) if(n->received_seqno > MAX_SEQNO)
regenerate_key(); regenerate_key();
@ -361,7 +361,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
if((outpkt->len = uncompress_packet(outpkt->data, inpkt->data, inpkt->len, n->incompression)) < 0) { if((outpkt->len = uncompress_packet(outpkt->data, inpkt->data, inpkt->len, n->incompression)) < 0) {
logger(DEBUG_TRAFFIC, LOG_ERR, "Error while uncompressing packet from %s (%s)", logger(DEBUG_TRAFFIC, LOG_ERR, "Error while uncompressing packet from %s (%s)",
n->name, n->hostname); n->name, n->hostname);
return; return;
} }
@ -607,7 +607,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
&& listen_socket[n->sock].sa.sa.sa_family == AF_INET) { && listen_socket[n->sock].sa.sa.sa_family == AF_INET) {
priority = origpriority; priority = origpriority;
logger(DEBUG_TRAFFIC, LOG_DEBUG, "Setting outgoing packet priority to %d", priority); logger(DEBUG_TRAFFIC, LOG_DEBUG, "Setting outgoing packet priority to %d", priority);
if(setsockopt(listen_socket[n->sock].udp, SOL_IP, IP_TOS, &priority, sizeof(priority))) /* SO_PRIORITY doesn't seem to work */ if(setsockopt(listen_socket[n->sock].udp, SOL_IP, IP_TOS, &priority, sizeof(priority))) /* SO_PRIORITY doesn't seem to work */
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setsockopt", strerror(errno)); logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setsockopt", strerror(errno));
} }
#endif #endif
@ -795,7 +795,7 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) {
send_packet(myself, packet); send_packet(myself, packet);
// In TunnelServer mode, do not forward broadcast packets. // In TunnelServer mode, do not forward broadcast packets.
// The MST might not be valid and create loops. // The MST might not be valid and create loops.
if(tunnelserver || broadcast_mode == BMODE_NONE) if(tunnelserver || broadcast_mode == BMODE_NONE)
return; return;
@ -813,7 +813,7 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) {
break; break;
// In direct mode, we send copies to each node we know of. // In direct mode, we send copies to each node we know of.
// However, this only reaches nodes that can be reached in a single hop. // However, this only reaches nodes that can be reached in a single hop.
// We don't have enough information to forward broadcast packets in this case. // We don't have enough information to forward broadcast packets in this case.
case BMODE_DIRECT: case BMODE_DIRECT:
if(from != myself) if(from != myself)
@ -877,7 +877,7 @@ void handle_incoming_vpn_data(int sock, short events, void *data) {
pkt.len = len; pkt.len = len;
sockaddrunmap(&from); /* Some braindead IPv6 implementations do stupid things. */ sockaddrunmap(&from); /* Some braindead IPv6 implementations do stupid things. */
n = lookup_node_udp(&from); n = lookup_node_udp(&from);

View file

@ -167,7 +167,7 @@ bool read_rsa_public_key(connection_t *c) {
result = rsa_read_pem_public_key(&c->rsa, fp); result = rsa_read_pem_public_key(&c->rsa, fp);
fclose(fp); fclose(fp);
if(!result) if(!result)
logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA public key file `%s' failed: %s", fname, strerror(errno)); logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA public key file `%s' failed: %s", fname, strerror(errno));
free(fname); free(fname);
return result; return result;
@ -207,7 +207,7 @@ static bool read_ecdsa_private_key(void) {
result = ecdsa_read_pem_private_key(&myself->connection->ecdsa, fp); result = ecdsa_read_pem_private_key(&myself->connection->ecdsa, fp);
fclose(fp); fclose(fp);
if(!result) if(!result)
logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno)); logger(DEBUG_ALWAYS, LOG_ERR, "Reading ECDSA private key file `%s' failed: %s", fname, strerror(errno));
free(fname); free(fname);
return result; return result;
@ -263,7 +263,7 @@ static bool read_rsa_private_key(void) {
result = rsa_read_pem_private_key(&myself->connection->rsa, fp); result = rsa_read_pem_private_key(&myself->connection->rsa, fp);
fclose(fp); fclose(fp);
if(!result) if(!result)
logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA private key file `%s' failed: %s", fname, strerror(errno)); logger(DEBUG_ALWAYS, LOG_ERR, "Reading RSA private key file `%s' failed: %s", fname, strerror(errno));
free(fname); free(fname);
return result; return result;
@ -398,7 +398,7 @@ bool setup_myself_reloadable(void) {
scriptinterpreter = NULL; scriptinterpreter = NULL;
get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &scriptinterpreter); get_config_string(lookup_config(config_tree, "ScriptsInterpreter"), &scriptinterpreter);
free(scriptextension); free(scriptextension);
if(!get_config_string(lookup_config(config_tree, "ScriptsExtension"), &scriptextension)) if(!get_config_string(lookup_config(config_tree, "ScriptsExtension"), &scriptextension))
#ifdef HAVE_MINGW #ifdef HAVE_MINGW
@ -480,7 +480,7 @@ bool setup_myself_reloadable(void) {
get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly); get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly);
get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery); get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery);
if(get_config_string(lookup_config(config_tree, "Mode"), &rmode)) { if(get_config_string(lookup_config(config_tree, "Mode"), &rmode)) {
if(!strcasecmp(rmode, "router")) if(!strcasecmp(rmode, "router"))
routing_mode = RMODE_ROUTER; routing_mode = RMODE_ROUTER;
@ -807,7 +807,7 @@ static bool setup_myself(void) {
listen_socket[i].tcp = i + 3; listen_socket[i].tcp = i + 3;
#ifdef FD_CLOEXEC #ifdef FD_CLOEXEC
fcntl(i + 3, F_SETFD, FD_CLOEXEC); fcntl(i + 3, F_SETFD, FD_CLOEXEC);
#endif #endif
listen_socket[i].udp = setup_vpn_in_socket(&sa); listen_socket[i].udp = setup_vpn_in_socket(&sa);

View file

@ -555,7 +555,7 @@ void handle_new_meta_connection(int sock, short events, void *data) {
event_set(&c->inevent, c->socket, EV_READ | EV_PERSIST, handle_meta_connection_data, c); event_set(&c->inevent, c->socket, EV_READ | EV_PERSIST, handle_meta_connection_data, c);
event_set(&c->outevent, c->socket, EV_WRITE | EV_PERSIST, handle_meta_write, c); event_set(&c->outevent, c->socket, EV_WRITE | EV_PERSIST, handle_meta_write, c);
event_add(&c->inevent, NULL); event_add(&c->inevent, NULL);
configure_tcp(c); configure_tcp(c);
connection_add(c); connection_add(c);

View file

@ -100,7 +100,7 @@ void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr) {
scopeid = strchr(address, '%'); scopeid = strchr(address, '%');
if(scopeid) if(scopeid)
*scopeid = '\0'; /* Descope. */ *scopeid = '\0'; /* Descope. */
if(addrstr) if(addrstr)
*addrstr = xstrdup(address); *addrstr = xstrdup(address);
@ -218,7 +218,7 @@ void sockaddrfree(sockaddr_t *a) {
free(a->unknown.port); free(a->unknown.port);
} }
} }
void sockaddrunmap(sockaddr_t *sa) { void sockaddrunmap(sockaddr_t *sa) {
if(sa->sa.sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sa->in6.sin6_addr)) { if(sa->sa.sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&sa->in6.sin6_addr)) {
sa->in.sin_addr.s_addr = ((uint32_t *) & sa->in6.sin6_addr)[3]; sa->in.sin_addr.s_addr = ((uint32_t *) & sa->in6.sin6_addr)[3];

View file

@ -35,4 +35,4 @@ extern void sockaddrunmap(sockaddr_t *);
extern void sockaddrfree(sockaddr_t *); extern void sockaddrfree(sockaddr_t *);
extern void sockaddrcpy(sockaddr_t *, const sockaddr_t *); extern void sockaddrcpy(sockaddr_t *, const sockaddr_t *);
#endif /* __TINC_NETUTL_H__ */ #endif /* __TINC_NETUTL_H__ */

View file

@ -30,7 +30,7 @@
#include "utils.h" #include "utils.h"
#include "xalloc.h" #include "xalloc.h"
splay_tree_t *node_tree; /* Known nodes, sorted by name */ splay_tree_t *node_tree;
static hash_t *node_udp_cache; static hash_t *node_udp_cache;
node_t *myself; node_t *myself;
@ -80,7 +80,7 @@ void free_node(node_t *n) {
if(timeout_initialized(&n->mtuevent)) if(timeout_initialized(&n->mtuevent))
event_del(&n->mtuevent); event_del(&n->mtuevent);
if(n->hostname) if(n->hostname)
free(n->hostname); free(n->hostname);

View file

@ -28,62 +28,62 @@
#include "subnet.h" #include "subnet.h"
typedef struct node_status_t { typedef struct node_status_t {
unsigned int unused_active:1; /* 1 if active (not used for nodes) */ unsigned int unused_active:1; /* 1 if active (not used for nodes) */
unsigned int validkey:1; /* 1 if we currently have a valid key for him */ unsigned int validkey:1; /* 1 if we currently have a valid key for him */
unsigned int waitingforkey:1; /* 1 if we already sent out a request */ unsigned int waitingforkey:1; /* 1 if we already sent out a request */
unsigned int visited:1; /* 1 if this node has been visited by one of the graph algorithms */ unsigned int visited:1; /* 1 if this node has been visited by one of the graph algorithms */
unsigned int reachable:1; /* 1 if this node is reachable in the graph */ unsigned int reachable:1; /* 1 if this node is reachable in the graph */
unsigned int indirect:1; /* 1 if this node is not directly reachable by us */ unsigned int indirect:1; /* 1 if this node is not directly reachable by us */
unsigned int sptps:1; /* 1 if this node supports SPTPS */ unsigned int sptps:1; /* 1 if this node supports SPTPS */
unsigned int udp_confirmed:1; /* 1 if the address is one that we received UDP traffic on */ unsigned int udp_confirmed:1; /* 1 if the address is one that we received UDP traffic on */
unsigned int unused:24; unsigned int unused:24;
} node_status_t; } node_status_t;
typedef struct node_t { typedef struct node_t {
char *name; /* name of this node */ char *name; /* name of this node */
uint32_t options; /* options turned on for this node */ uint32_t options; /* options turned on for this node */
int sock; /* Socket to use for outgoing UDP packets */ int sock; /* Socket to use for outgoing UDP packets */
sockaddr_t address; /* his real (internet) ip to send UDP packets to */ sockaddr_t address; /* his real (internet) ip to send UDP packets to */
char *hostname; /* the hostname of its real ip */ char *hostname; /* the hostname of its real ip */
node_status_t status; node_status_t status;
time_t last_state_change; time_t last_state_change;
time_t last_req_key; time_t last_req_key;
ecdsa_t ecdsa; /* His public ECDSA key */ ecdsa_t ecdsa; /* His public ECDSA key */
sptps_t sptps; sptps_t sptps;
cipher_t incipher; /* Cipher for UDP packets */ cipher_t incipher; /* Cipher for UDP packets */
digest_t indigest; /* Digest for UDP packets */ digest_t indigest; /* Digest for UDP packets */
cipher_t outcipher; /* Cipher for UDP packets */ cipher_t outcipher; /* Cipher for UDP packets */
digest_t outdigest; /* Digest for UDP packets */ digest_t outdigest; /* Digest for UDP packets */
int incompression; /* Compressionlevel, 0 = no compression */ int incompression; /* Compressionlevel, 0 = no compression */
int outcompression; /* Compressionlevel, 0 = no compression */ int outcompression; /* Compressionlevel, 0 = no compression */
int distance; int distance;
struct node_t *nexthop; /* nearest node from us to him */ struct node_t *nexthop; /* nearest node from us to him */
struct edge_t *prevedge; /* nearest node from him to us */ struct edge_t *prevedge; /* nearest node from him to us */
struct node_t *via; /* next hop for UDP packets */ struct node_t *via; /* next hop for UDP packets */
splay_tree_t *subnet_tree; /* Pointer to a tree of subnets belonging to this node */ splay_tree_t *subnet_tree; /* Pointer to a tree of subnets belonging to this node */
splay_tree_t *edge_tree; /* Edges with this node as one of the endpoints */ splay_tree_t *edge_tree; /* Edges with this node as one of the endpoints */
struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */ struct connection_t *connection; /* Connection associated with this node (if a direct connection exists) */
uint32_t sent_seqno; /* Sequence number last sent to this node */ uint32_t sent_seqno; /* Sequence number last sent to this node */
uint32_t received_seqno; /* Sequence number last received from this node */ uint32_t received_seqno; /* Sequence number last received from this node */
uint32_t farfuture; /* Packets in a row that have arrived from the far future */ uint32_t farfuture; /* Packets in a row that have arrived from the far future */
unsigned char* late; /* Bitfield marking late packets */ unsigned char* late; /* Bitfield marking late packets */
length_t mtu; /* Maximum size of packets to send to this node */ length_t mtu; /* Maximum size of packets to send to this node */
length_t minmtu; /* Probed minimum MTU */ length_t minmtu; /* Probed minimum MTU */
length_t maxmtu; /* Probed maximum MTU */ length_t maxmtu; /* Probed maximum MTU */
int mtuprobes; /* Number of probes */ int mtuprobes; /* Number of probes */
struct event mtuevent; /* Probe event */ struct event mtuevent; /* Probe event */
uint64_t in_packets; uint64_t in_packets;
uint64_t in_bytes; uint64_t in_bytes;
@ -106,4 +106,4 @@ extern bool dump_nodes(struct connection_t *);
extern bool dump_traffic(struct connection_t *); extern bool dump_traffic(struct connection_t *);
extern void update_node_udp(node_t *, const sockaddr_t *); extern void update_node_udp(node_t *, const sockaddr_t *);
#endif /* __TINC_NODE_H__ */ #endif /* __TINC_NODE_H__ */

View file

@ -143,7 +143,7 @@ bool cipher_counter_xor(cipher_t *cipher, const void *indata, size_t inlen, void
unsigned char *out = outdata; unsigned char *out = outdata;
while(inlen--) { while(inlen--) {
// Encrypt the new counter value if we need it // Encrypt the new counter value if we need it
if(!cipher->counter->n) { if(!cipher->counter->n) {
int len; int len;
if(!EVP_EncryptUpdate(&cipher->ctx, cipher->counter->block, &len, cipher->counter->counter, cipher->cipher->block_size)) { if(!EVP_EncryptUpdate(&cipher->ctx, cipher->counter->block, &len, cipher->counter->counter, cipher->cipher->block_size)) {

View file

@ -26,12 +26,12 @@
#include "crypto.h" #include "crypto.h"
void crypto_init(void) { void crypto_init(void) {
RAND_load_file("/dev/urandom", 1024); RAND_load_file("/dev/urandom", 1024);
ENGINE_load_builtin_engines(); ENGINE_load_builtin_engines();
ENGINE_register_all_complete(); ENGINE_register_all_complete();
OpenSSL_add_all_algorithms(); OpenSSL_add_all_algorithms();
} }
void crypto_exit(void) { void crypto_exit(void) {

View file

@ -41,7 +41,7 @@ bool ecdh_generate_public(ecdh_t *ecdh, void *pubkey) {
logger(DEBUG_ALWAYS, LOG_ERR, "Generating EC key failed: %s", ERR_error_string(ERR_get_error(), NULL)); logger(DEBUG_ALWAYS, LOG_ERR, "Generating EC key failed: %s", ERR_error_string(ERR_get_error(), NULL));
return false; return false;
} }
const EC_POINT *point = EC_KEY_get0_public_key(*ecdh); const EC_POINT *point = EC_KEY_get0_public_key(*ecdh);
if(!point) { if(!point) {
EC_KEY_free(*ecdh); EC_KEY_free(*ecdh);

View file

@ -34,7 +34,7 @@ bool ecdsa_set_base64_public_key(ecdsa_t *ecdsa, const char *p) {
logger(DEBUG_ALWAYS, LOG_DEBUG, "EC_KEY_new_by_curve_name failed: %s", ERR_error_string(ERR_get_error(), NULL)); logger(DEBUG_ALWAYS, LOG_DEBUG, "EC_KEY_new_by_curve_name failed: %s", ERR_error_string(ERR_get_error(), NULL));
return false; return false;
} }
int len = strlen(p); int len = strlen(p);
unsigned char pubkey[len / 4 * 3 + 3]; unsigned char pubkey[len / 4 * 3 + 3];
const unsigned char *ppubkey = pubkey; const unsigned char *ppubkey = pubkey;
@ -77,7 +77,7 @@ bool ecdsa_read_pem_private_key(ecdsa_t *ecdsa, FILE *fp) {
if(*ecdsa) if(*ecdsa)
return true; return true;
logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read ECDSA private key: %s", ERR_error_string(ERR_get_error(), NULL)); logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read ECDSA private key: %s", ERR_error_string(ERR_get_error(), NULL));
return false; return false;
} }

View file

@ -30,7 +30,7 @@
static bool prf_xor(int nid, const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, ssize_t outlen) { static bool prf_xor(int nid, const char *secret, size_t secretlen, char *seed, size_t seedlen, char *out, ssize_t outlen) {
digest_t digest; digest_t digest;
if(!digest_open_by_nid(&digest, nid, -1)) if(!digest_open_by_nid(&digest, nid, -1))
return false; return false;

View file

@ -54,7 +54,7 @@ bool rsa_read_pem_public_key(rsa_t *rsa, FILE *fp) {
if(*rsa) if(*rsa)
return true; return true;
*rsa = PEM_read_RSA_PUBKEY(fp, rsa, NULL, NULL); *rsa = PEM_read_RSA_PUBKEY(fp, rsa, NULL, NULL);
if(*rsa) if(*rsa)
@ -69,7 +69,7 @@ bool rsa_read_pem_private_key(rsa_t *rsa, FILE *fp) {
if(*rsa) if(*rsa)
return true; return true;
logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA private key: %s", ERR_error_string(ERR_get_error(), NULL)); logger(DEBUG_ALWAYS, LOG_ERR, "Unable to read RSA private key: %s", ERR_error_string(ERR_get_error(), NULL));
return false; return false;
} }
@ -83,7 +83,7 @@ bool rsa_public_encrypt(rsa_t *rsa, void *in, size_t len, void *out) {
return true; return true;
logger(DEBUG_ALWAYS, LOG_ERR, "Unable to perform RSA encryption: %s", ERR_error_string(ERR_get_error(), NULL)); logger(DEBUG_ALWAYS, LOG_ERR, "Unable to perform RSA encryption: %s", ERR_error_string(ERR_get_error(), NULL));
return false; return false;
} }
bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) { bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) {
@ -91,7 +91,7 @@ bool rsa_private_decrypt(rsa_t *rsa, void *in, size_t len, void *out) {
return true; return true;
logger(DEBUG_ALWAYS, LOG_ERR, "Unable to perform RSA decryption: %s", ERR_error_string(ERR_get_error(), NULL)); logger(DEBUG_ALWAYS, LOG_ERR, "Unable to perform RSA decryption: %s", ERR_error_string(ERR_get_error(), NULL));
return false; return false;
} }
bool rsa_active(rsa_t *rsa) { bool rsa_active(rsa_t *rsa) {

View file

@ -75,10 +75,10 @@ static bool install_service(void) {
for(char **argp = g_argv + 1; *argp; argp++) { for(char **argp = g_argv + 1; *argp; argp++) {
char &space = strchr(*argp, ' '); char &space = strchr(*argp, ' ');
strncat(command, " ", sizeof command - strlen(command)); strncat(command, " ", sizeof command - strlen(command));
if(space) if(space)
strncat(command, "\"", sizeof command - strlen(command)); strncat(command, "\"", sizeof command - strlen(command));
strncat(command, *argp, sizeof command - strlen(command)); strncat(command, *argp, sizeof command - strlen(command));
if(space) if(space)
@ -88,7 +88,7 @@ static bool install_service(void) {
service = CreateService(manager, identname, identname, service = CreateService(manager, identname, identname,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
command, NULL, NULL, NULL, NULL, NULL); command, NULL, NULL, NULL, NULL, NULL);
if(!service) { if(!service) {
DWORD lasterror = GetLastError(); DWORD lasterror = GetLastError();
logger(DEBUG_ALWAYS, LOG_ERR, "Could not create %s service: %s", identname, winerror(lasterror)); logger(DEBUG_ALWAYS, LOG_ERR, "Could not create %s service: %s", identname, winerror(lasterror));
@ -128,8 +128,8 @@ DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) {
} }
event_loopexit(NULL); event_loopexit(NULL);
status.dwWaitHint = 30000; status.dwWaitHint = 30000;
status.dwCurrentState = SERVICE_STOP_PENDING; status.dwCurrentState = SERVICE_STOP_PENDING;
SetServiceStatus(statushandle, &status); SetServiceStatus(statushandle, &status);
return NO_ERROR; return NO_ERROR;
} }
@ -139,31 +139,31 @@ VOID WINAPI run_service(DWORD argc, LPTSTR* argv) {
extern int main2(int argc, char **argv); extern int main2(int argc, char **argv);
status.dwServiceType = SERVICE_WIN32; status.dwServiceType = SERVICE_WIN32;
status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN; status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
status.dwWin32ExitCode = 0; status.dwWin32ExitCode = 0;
status.dwServiceSpecificExitCode = 0; status.dwServiceSpecificExitCode = 0;
status.dwCheckPoint = 0; status.dwCheckPoint = 0;
statushandle = RegisterServiceCtrlHandlerEx(identname, controlhandler, NULL); statushandle = RegisterServiceCtrlHandlerEx(identname, controlhandler, NULL);
if (!statushandle) { if (!statushandle) {
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "RegisterServiceCtrlHandlerEx", winerror(GetLastError())); logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "RegisterServiceCtrlHandlerEx", winerror(GetLastError()));
err = 1; err = 1;
} else { } else {
status.dwWaitHint = 30000; status.dwWaitHint = 30000;
status.dwCurrentState = SERVICE_START_PENDING; status.dwCurrentState = SERVICE_START_PENDING;
SetServiceStatus(statushandle, &status); SetServiceStatus(statushandle, &status);
status.dwWaitHint = 0; status.dwWaitHint = 0;
status.dwCurrentState = SERVICE_RUNNING; status.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus(statushandle, &status); SetServiceStatus(statushandle, &status);
err = main2(argc, argv); err = main2(argc, argv);
status.dwWaitHint = 0; status.dwWaitHint = 0;
status.dwCurrentState = SERVICE_STOPPED; status.dwCurrentState = SERVICE_STOPPED;
//status.dwWin32ExitCode = err; //status.dwWin32ExitCode = err;
SetServiceStatus(statushandle, &status); SetServiceStatus(statushandle, &status);
} }
@ -240,7 +240,7 @@ bool execute_script(const char *name, char **envp) {
#ifdef HAVE_PUTENV #ifdef HAVE_PUTENV
/* Set environment */ /* Set environment */
for(int i = 0; envp[i]; i++) for(int i = 0; envp[i]; i++)
putenv(envp[i]); putenv(envp[i]);
#endif #endif
@ -269,17 +269,17 @@ bool execute_script(const char *name, char **envp) {
#ifdef WEXITSTATUS #ifdef WEXITSTATUS
if(status != -1) { if(status != -1) {
if(WIFEXITED(status)) { /* Child exited by itself */ if(WIFEXITED(status)) { /* Child exited by itself */
if(WEXITSTATUS(status)) { if(WEXITSTATUS(status)) {
logger(DEBUG_ALWAYS, LOG_ERR, "Script %s exited with non-zero status %d", logger(DEBUG_ALWAYS, LOG_ERR, "Script %s exited with non-zero status %d",
name, WEXITSTATUS(status)); name, WEXITSTATUS(status));
return false; return false;
} }
} else if(WIFSIGNALED(status)) { /* Child was killed by a signal */ } else if(WIFSIGNALED(status)) { /* Child was killed by a signal */
logger(DEBUG_ALWAYS, LOG_ERR, "Script %s was killed by signal %d (%s)", logger(DEBUG_ALWAYS, LOG_ERR, "Script %s was killed by signal %d (%s)",
name, WTERMSIG(status), strsignal(WTERMSIG(status))); name, WTERMSIG(status), strsignal(WTERMSIG(status)));
return false; return false;
} else { /* Something strange happened */ } else { /* Something strange happened */
logger(DEBUG_ALWAYS, LOG_ERR, "Script %s terminated abnormally", name); logger(DEBUG_ALWAYS, LOG_ERR, "Script %s terminated abnormally", name);
return false; return false;
} }

View file

@ -33,4 +33,4 @@ extern bool kill_other(int);
extern bool init_service(void); extern bool init_service(void);
#endif #endif
#endif /* __TINC_PROCESS_H__ */ #endif /* __TINC_PROCESS_H__ */

View file

@ -35,7 +35,7 @@
/* Request numbers */ /* Request numbers */
typedef enum request_t { typedef enum request_t {
ALL = -1, /* Guardian for allow_request */ ALL = -1, /* Guardian for allow_request */
ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK, ID = 0, METAKEY, CHALLENGE, CHAL_REPLY, ACK,
STATUS, ERROR, TERMREQ, STATUS, ERROR, TERMREQ,
PING, PONG, PING, PONG,
@ -48,7 +48,7 @@ typedef enum request_t {
REQ_PUBKEY, ANS_PUBKEY, REQ_PUBKEY, ANS_PUBKEY,
REQ_SPTPS, REQ_SPTPS,
REQ_PACKET, REQ_PACKET,
LAST /* Guardian for the highest request number */ LAST /* Guardian for the highest request number */
} request_t; } request_t;
typedef struct past_request_t { typedef struct past_request_t {
@ -128,4 +128,4 @@ extern bool ans_key_h(struct connection_t *, const char *);
extern bool tcppacket_h(struct connection_t *, const char *); extern bool tcppacket_h(struct connection_t *, const char *);
extern bool control_h(struct connection_t *, const char *); extern bool control_h(struct connection_t *, const char *);
#endif /* __TINC_PROTOCOL_H__ */ #endif /* __TINC_PROTOCOL_H__ */

View file

@ -162,8 +162,8 @@ bool id_h(connection_t *c, const char *request) {
c->allow_request = CONTROL; c->allow_request = CONTROL;
c->last_ping_time = time(NULL) + 3600; c->last_ping_time = time(NULL) + 3600;
free(c->name); free(c->name);
c->name = xstrdup("<control>"); c->name = xstrdup("<control>");
return send_request(c, "%d %d %d", ACK, TINC_CTL_VERSION_CURRENT, getpid()); return send_request(c, "%d %d %d", ACK, TINC_CTL_VERSION_CURRENT, getpid());
} }
@ -248,7 +248,7 @@ bool send_metakey(connection_t *c) {
if(!cipher_open_blowfish_ofb(&c->outcipher)) if(!cipher_open_blowfish_ofb(&c->outcipher))
return false; return false;
if(!digest_open_sha1(&c->outdigest, -1)) if(!digest_open_sha1(&c->outdigest, -1))
return false; return false;
@ -302,7 +302,7 @@ bool send_metakey(connection_t *c) {
cipher_get_nid(&c->outcipher), cipher_get_nid(&c->outcipher),
digest_get_nid(&c->outdigest), c->outmaclength, digest_get_nid(&c->outdigest), c->outmaclength,
c->outcompression, hexkey); c->outcompression, hexkey);
c->status.encryptout = true; c->status.encryptout = true;
return result; return result;
} }

View file

@ -230,7 +230,7 @@ bool del_edge_h(connection_t *c, const char *request) {
logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself", logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself",
"DEL_EDGE", c->name, c->hostname); "DEL_EDGE", c->name, c->hostname);
contradicting_del_edge++; contradicting_del_edge++;
send_add_edge(c, e); /* Send back a correction */ send_add_edge(c, e); /* Send back a correction */
return true; return true;
} }

View file

@ -102,14 +102,14 @@ bool send_req_key(node_t *to) {
send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, to->name, REQ_PUBKEY); send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, to->name, REQ_PUBKEY);
return true; return true;
} }
char label[25 + strlen(myself->name) + strlen(to->name)]; char label[25 + strlen(myself->name) + strlen(to->name)];
snprintf(label, sizeof label, "tinc UDP key expansion %s %s", myself->name, to->name); snprintf(label, sizeof label, "tinc UDP key expansion %s %s", myself->name, to->name);
sptps_stop(&to->sptps); sptps_stop(&to->sptps);
to->status.validkey = false; to->status.validkey = false;
to->status.waitingforkey = true; to->status.waitingforkey = true;
to->last_req_key = time(NULL); to->last_req_key = time(NULL);
to->incompression = myself->incompression; to->incompression = myself->incompression;
return sptps_start(&to->sptps, to, true, true, myself->connection->ecdsa, to->ecdsa, label, sizeof label, send_initial_sptps_data, receive_sptps_record); return sptps_start(&to->sptps, to, true, true, myself->connection->ecdsa, to->ecdsa, label, sizeof label, send_initial_sptps_data, receive_sptps_record);
} }
return send_request(to->nexthop->connection, "%d %s %s", REQ_KEY, myself->name, to->name); return send_request(to->nexthop->connection, "%d %s %s", REQ_KEY, myself->name, to->name);
@ -166,7 +166,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, in
from->status.validkey = false; from->status.validkey = false;
from->status.waitingforkey = true; from->status.waitingforkey = true;
from->last_req_key = time(NULL); from->last_req_key = time(NULL);
sptps_start(&from->sptps, from, false, true, myself->connection->ecdsa, from->ecdsa, label, sizeof label, send_sptps_data, receive_sptps_record); sptps_start(&from->sptps, from, false, true, myself->connection->ecdsa, from->ecdsa, label, sizeof label, send_sptps_data, receive_sptps_record);
sptps_receive_data(&from->sptps, buf, len); sptps_receive_data(&from->sptps, buf, len);
return true; return true;
} }
@ -228,7 +228,7 @@ bool req_key_h(connection_t *c, const char *request) {
/* Check if this key request is for us */ /* Check if this key request is for us */
if(to == myself) { /* Yes */ if(to == myself) { /* Yes */
/* Is this an extended REQ_KEY message? */ /* Is this an extended REQ_KEY message? */
if(experimental && reqno) if(experimental && reqno)
return req_key_ext_h(c, request, from, reqno); return req_key_ext_h(c, request, from, reqno);
@ -288,8 +288,8 @@ bool ans_key_h(connection_t *c, const char *request) {
char from_name[MAX_STRING_SIZE]; char from_name[MAX_STRING_SIZE];
char to_name[MAX_STRING_SIZE]; char to_name[MAX_STRING_SIZE];
char key[MAX_STRING_SIZE]; char key[MAX_STRING_SIZE];
char address[MAX_STRING_SIZE] = ""; char address[MAX_STRING_SIZE] = "";
char port[MAX_STRING_SIZE] = ""; char port[MAX_STRING_SIZE] = "";
int cipher, digest, maclength, compression, keylen; int cipher, digest, maclength, compression, keylen;
node_t *from, *to; node_t *from, *to;

View file

@ -123,7 +123,7 @@ bool pong_h(connection_t *c, const char *request) {
bool send_tcppacket(connection_t *c, const vpn_packet_t *packet) { bool send_tcppacket(connection_t *c, const vpn_packet_t *packet) {
/* If there already is a lot of data in the outbuf buffer, discard this 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. */ We use a very simple Random Early Drop algorithm. */
if(2.0 * c->outbuf.len / (float)maxoutbufsize - 1 > (float)rand()/(float)RAND_MAX) if(2.0 * c->outbuf.len / (float)maxoutbufsize - 1 > (float)rand()/(float)RAND_MAX)
return true; return true;

View file

@ -189,7 +189,7 @@ bool del_subnet_h(connection_t *c, const char *request) {
if(tunnelserver && owner != myself && owner != c->node) { if(tunnelserver && owner != myself && owner != c->node) {
/* in case of tunnelserver, ignore indirect subnet deletion */ /* in case of tunnelserver, ignore indirect subnet deletion */
logger(DEBUG_PROTOCOL, LOG_WARNING, "Ignoring indirect %s from %s (%s) for %s", logger(DEBUG_PROTOCOL, LOG_WARNING, "Ignoring indirect %s from %s (%s) for %s",
"DEL_SUBNET", c->name, c->hostname, subnetstr); "DEL_SUBNET", c->name, c->hostname, subnetstr);
return true; return true;
} }

View file

@ -71,7 +71,7 @@ static uint16_t inet_checksum(void *data, int len, uint16_t prevsum) {
checksum += *p++; checksum += *p++;
len -= 2; len -= 2;
} }
if(len) if(len)
checksum += *(uint8_t *)p; checksum += *(uint8_t *)p;
@ -85,7 +85,7 @@ static bool ratelimit(int frequency) {
static time_t lasttime = 0; static time_t lasttime = 0;
static int count = 0; static int count = 0;
time_t now = time(NULL); time_t now = time(NULL);
if(lasttime == now) { if(lasttime == now) {
if(count >= frequency) if(count >= frequency)
return true; return true;
@ -162,7 +162,7 @@ static void clamp_mss(const node_t *source, const node_t *via, vpn_packet_t *pac
if(oldmss <= newmss) if(oldmss <= newmss)
break; break;
logger(DEBUG_TRAFFIC, LOG_INFO, "Clamping MSS of packet from %s to %s to %d", source->name, via->name, newmss); logger(DEBUG_TRAFFIC, LOG_INFO, "Clamping MSS of packet from %s to %s to %d", source->name, via->name, newmss);
/* Update the MSS value and the checksum */ /* Update the MSS value and the checksum */
@ -184,7 +184,7 @@ static void swap_mac_addresses(vpn_packet_t *packet) {
memcpy(&packet->data[0], &packet->data[6], sizeof tmp); memcpy(&packet->data[0], &packet->data[6], sizeof tmp);
memcpy(&packet->data[6], &tmp, sizeof tmp); memcpy(&packet->data[6], &tmp, sizeof tmp);
} }
static void age_subnets(int fd, short events, void *data) { static void age_subnets(int fd, short events, void *data) {
bool left = false; bool left = false;
time_t now = time(NULL); time_t now = time(NULL);
@ -250,14 +250,14 @@ static void learn_mac(mac_t *address) {
static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) { static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) {
struct ip ip = {0}; struct ip ip = {0};
struct icmp icmp = {0}; struct icmp icmp = {0};
struct in_addr ip_src; struct in_addr ip_src;
struct in_addr ip_dst; struct in_addr ip_dst;
uint32_t oldlen; uint32_t oldlen;
if(ratelimit(3)) if(ratelimit(3))
return; return;
/* Swap Ethernet source and destination addresses */ /* Swap Ethernet source and destination addresses */
swap_mac_addresses(packet); swap_mac_addresses(packet);
@ -267,7 +267,7 @@ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
memcpy(&ip, packet->data + ether_size, ip_size); memcpy(&ip, packet->data + ether_size, ip_size);
/* Remember original source and destination */ /* Remember original source and destination */
ip_src = ip.ip_src; ip_src = ip.ip_src;
ip_dst = ip.ip_dst; ip_dst = ip.ip_dst;
@ -278,13 +278,13 @@ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
if(oldlen >= IP_MSS - ip_size - icmp_size) if(oldlen >= IP_MSS - ip_size - icmp_size)
oldlen = IP_MSS - ip_size - icmp_size; oldlen = IP_MSS - ip_size - icmp_size;
/* Copy first part of original contents to ICMP message */ /* Copy first part of original contents to ICMP message */
memmove(packet->data + ether_size + ip_size + icmp_size, packet->data + ether_size, oldlen); memmove(packet->data + ether_size + ip_size + icmp_size, packet->data + ether_size, oldlen);
/* Fill in IPv4 header */ /* Fill in IPv4 header */
ip.ip_v = 4; ip.ip_v = 4;
ip.ip_hl = ip_size / 4; ip.ip_hl = ip_size / 4;
ip.ip_tos = 0; ip.ip_tos = 0;
@ -298,13 +298,13 @@ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
ip.ip_dst = ip_src; ip.ip_dst = ip_src;
ip.ip_sum = inet_checksum(&ip, ip_size, ~0); ip.ip_sum = inet_checksum(&ip, ip_size, ~0);
/* Fill in ICMP header */ /* Fill in ICMP header */
icmp.icmp_type = type; icmp.icmp_type = type;
icmp.icmp_code = code; icmp.icmp_code = code;
icmp.icmp_cksum = 0; icmp.icmp_cksum = 0;
icmp.icmp_cksum = inet_checksum(&icmp, icmp_size, ~0); icmp.icmp_cksum = inet_checksum(&icmp, icmp_size, ~0);
icmp.icmp_cksum = inet_checksum(packet->data + ether_size + ip_size + icmp_size, oldlen, icmp.icmp_cksum); icmp.icmp_cksum = inet_checksum(packet->data + ether_size + ip_size + icmp_size, oldlen, icmp.icmp_cksum);
@ -312,7 +312,7 @@ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
memcpy(packet->data + ether_size, &ip, ip_size); memcpy(packet->data + ether_size, &ip, ip_size);
memcpy(packet->data + ether_size + ip_size, &icmp, icmp_size); memcpy(packet->data + ether_size + ip_size, &icmp, icmp_size);
packet->len = ether_size + ip_size + icmp_size + oldlen; packet->len = ether_size + ip_size + icmp_size + oldlen;
send_packet(source, packet); send_packet(source, packet);
@ -326,13 +326,13 @@ static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet) {
int len, maxlen, todo; int len, maxlen, todo;
uint8_t *offset; uint8_t *offset;
uint16_t ip_off, origf; uint16_t ip_off, origf;
memcpy(&ip, packet->data + ether_size, ip_size); memcpy(&ip, packet->data + ether_size, ip_size);
fragment.priority = packet->priority; fragment.priority = packet->priority;
if(ip.ip_hl != ip_size / 4) if(ip.ip_hl != ip_size / 4)
return; return;
todo = ntohs(ip.ip_len) - ip_size; todo = ntohs(ip.ip_len) - ip_size;
if(ether_size + ip_size + todo != packet->len) { if(ether_size + ip_size + todo != packet->len) {
@ -347,7 +347,7 @@ static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet) {
ip_off = ntohs(ip.ip_off); ip_off = ntohs(ip.ip_off);
origf = ip_off & ~IP_OFFMASK; origf = ip_off & ~IP_OFFMASK;
ip_off &= IP_OFFMASK; ip_off &= IP_OFFMASK;
while(todo) { while(todo) {
len = todo > maxlen ? maxlen : todo; len = todo > maxlen ? maxlen : todo;
memcpy(fragment.data + ether_size + ip_size, offset, len); memcpy(fragment.data + ether_size + ip_size, offset, len);
@ -365,7 +365,7 @@ static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet) {
send_packet(dest, &fragment); send_packet(dest, &fragment);
ip_off += len / 8; ip_off += len / 8;
} }
} }
static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) { static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) {
@ -387,7 +387,7 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) {
route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_NET_UNKNOWN); route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_NET_UNKNOWN);
return; return;
} }
if(subnet->owner == source) { if(subnet->owner == source) {
logger(DEBUG_TRAFFIC, LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname); logger(DEBUG_TRAFFIC, LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname);
return; return;
@ -408,7 +408,7 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) {
logger(DEBUG_TRAFFIC, LOG_ERR, "Routing loop for packet from %s (%s)!", source->name, source->hostname); logger(DEBUG_TRAFFIC, LOG_ERR, "Routing loop for packet from %s (%s)!", source->name, source->hostname);
return; return;
} }
if(directonly && subnet->owner != via) if(directonly && subnet->owner != via)
return route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_NET_ANO); return route_ipv4_unreachable(source, packet, ICMP_DEST_UNREACH, ICMP_NET_ANO);
@ -425,7 +425,7 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) {
} }
clamp_mss(source, via, packet); clamp_mss(source, via, packet);
send_packet(subnet->owner, packet); send_packet(subnet->owner, packet);
} }
@ -448,18 +448,18 @@ static void route_ipv4(node_t *source, vpn_packet_t *packet) {
static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) { static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t type, uint8_t code) {
struct ip6_hdr ip6; struct ip6_hdr ip6;
struct icmp6_hdr icmp6 = {0}; struct icmp6_hdr icmp6 = {0};
uint16_t checksum; uint16_t checksum;
struct { struct {
struct in6_addr ip6_src; /* source address */ struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* destination address */ struct in6_addr ip6_dst; /* destination address */
uint32_t length; uint32_t length;
uint32_t next; uint32_t next;
} pseudo; } pseudo;
if(ratelimit(3)) if(ratelimit(3))
return; return;
/* Swap Ethernet source and destination addresses */ /* Swap Ethernet source and destination addresses */
swap_mac_addresses(packet); swap_mac_addresses(packet);
@ -469,7 +469,7 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
memcpy(&ip6, packet->data + ether_size, ip6_size); memcpy(&ip6, packet->data + ether_size, ip6_size);
/* Remember original source and destination */ /* Remember original source and destination */
pseudo.ip6_src = ip6.ip6_dst; pseudo.ip6_src = ip6.ip6_dst;
pseudo.ip6_dst = ip6.ip6_src; pseudo.ip6_dst = ip6.ip6_src;
@ -477,16 +477,16 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
if(type == ICMP6_PACKET_TOO_BIG) if(type == ICMP6_PACKET_TOO_BIG)
icmp6.icmp6_mtu = htonl(pseudo.length); icmp6.icmp6_mtu = htonl(pseudo.length);
if(pseudo.length >= IP_MSS - ip6_size - icmp6_size) if(pseudo.length >= IP_MSS - ip6_size - icmp6_size)
pseudo.length = IP_MSS - ip6_size - icmp6_size; pseudo.length = IP_MSS - ip6_size - icmp6_size;
/* Copy first part of original contents to ICMP message */ /* Copy first part of original contents to ICMP message */
memmove(packet->data + ether_size + ip6_size + icmp6_size, packet->data + ether_size, pseudo.length); memmove(packet->data + ether_size + ip6_size + icmp6_size, packet->data + ether_size, pseudo.length);
/* Fill in IPv6 header */ /* Fill in IPv6 header */
ip6.ip6_flow = htonl(0x60000000UL); ip6.ip6_flow = htonl(0x60000000UL);
ip6.ip6_plen = htons(icmp6_size + pseudo.length); ip6.ip6_plen = htons(icmp6_size + pseudo.length);
ip6.ip6_nxt = IPPROTO_ICMPV6; ip6.ip6_nxt = IPPROTO_ICMPV6;
@ -495,18 +495,18 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
ip6.ip6_dst = pseudo.ip6_dst; ip6.ip6_dst = pseudo.ip6_dst;
/* Fill in ICMP header */ /* Fill in ICMP header */
icmp6.icmp6_type = type; icmp6.icmp6_type = type;
icmp6.icmp6_code = code; icmp6.icmp6_code = code;
icmp6.icmp6_cksum = 0; icmp6.icmp6_cksum = 0;
/* Create pseudo header */ /* Create pseudo header */
pseudo.length = htonl(icmp6_size + pseudo.length); pseudo.length = htonl(icmp6_size + pseudo.length);
pseudo.next = htonl(IPPROTO_ICMPV6); pseudo.next = htonl(IPPROTO_ICMPV6);
/* Generate checksum */ /* Generate checksum */
checksum = inet_checksum(&pseudo, sizeof pseudo, ~0); checksum = inet_checksum(&pseudo, sizeof pseudo, ~0);
checksum = inet_checksum(&icmp6, icmp6_size, checksum); checksum = inet_checksum(&icmp6, icmp6_size, checksum);
checksum = inet_checksum(packet->data + ether_size + ip6_size + icmp6_size, ntohl(pseudo.length) - icmp6_size, checksum); checksum = inet_checksum(packet->data + ether_size + ip6_size + icmp6_size, ntohl(pseudo.length) - icmp6_size, checksum);
@ -517,9 +517,9 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
memcpy(packet->data + ether_size, &ip6, ip6_size); memcpy(packet->data + ether_size, &ip6, ip6_size);
memcpy(packet->data + ether_size + ip6_size, &icmp6, icmp6_size); memcpy(packet->data + ether_size + ip6_size, &icmp6, icmp6_size);
packet->len = ether_size + ip6_size + ntohl(pseudo.length); packet->len = ether_size + ip6_size + ntohl(pseudo.length);
send_packet(source, packet); send_packet(source, packet);
} }
@ -559,12 +559,12 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) {
return route_ipv6_unreachable(source, packet, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN); return route_ipv6_unreachable(source, packet, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN);
via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via; via = (subnet->owner->via == myself) ? subnet->owner->nexthop : subnet->owner->via;
if(via == source) { if(via == source) {
logger(DEBUG_TRAFFIC, LOG_ERR, "Routing loop for packet from %s (%s)!", source->name, source->hostname); logger(DEBUG_TRAFFIC, LOG_ERR, "Routing loop for packet from %s (%s)!", source->name, source->hostname);
return; return;
} }
if(directonly && subnet->owner != via) if(directonly && subnet->owner != via)
return route_ipv6_unreachable(source, packet, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN); return route_ipv6_unreachable(source, packet, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADMIN);
@ -576,7 +576,7 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) {
} }
clamp_mss(source, via, packet); clamp_mss(source, via, packet);
send_packet(subnet->owner, packet); send_packet(subnet->owner, packet);
} }
@ -591,17 +591,17 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet) {
bool has_opt; bool has_opt;
struct { struct {
struct in6_addr ip6_src; /* source address */ struct in6_addr ip6_src;
struct in6_addr ip6_dst; /* destination address */ struct in6_addr ip6_dst;
uint32_t length; uint32_t length;
uint32_t next; uint32_t next;
} pseudo; } pseudo;
if(!checklength(source, packet, ether_size + ip6_size + ns_size)) if(!checklength(source, packet, ether_size + ip6_size + ns_size))
return; return;
has_opt = packet->len >= ether_size + ip6_size + ns_size + opt_size + ETH_ALEN; has_opt = packet->len >= ether_size + ip6_size + ns_size + opt_size + ETH_ALEN;
if(source != myself) { if(source != myself) {
logger(DEBUG_TRAFFIC, LOG_WARNING, "Got neighbor solicitation request from %s (%s) while in router mode!", source->name, source->hostname); logger(DEBUG_TRAFFIC, LOG_WARNING, "Got neighbor solicitation request from %s (%s) while in router mode!", source->name, source->hostname);
return; return;
@ -672,22 +672,22 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet) {
/* Check if it is for our own subnet */ /* Check if it is for our own subnet */
if(subnet->owner == myself) if(subnet->owner == myself)
return; /* silently ignore */ return; /* silently ignore */
/* Create neighbor advertation reply */ /* Create neighbor advertation reply */
memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN); /* copy destination address */ memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN); /* copy destination address */
packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */ packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */
ip6.ip6_dst = ip6.ip6_src; /* swap destination and source protocoll address */ ip6.ip6_dst = ip6.ip6_src; /* swap destination and source protocoll address */
ip6.ip6_src = ns.nd_ns_target; ip6.ip6_src = ns.nd_ns_target;
if(has_opt) if(has_opt)
memcpy(packet->data + ether_size + ip6_size + ns_size + opt_size, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */ memcpy(packet->data + ether_size + ip6_size + ns_size + opt_size, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */
ns.nd_ns_cksum = 0; ns.nd_ns_cksum = 0;
ns.nd_ns_type = ND_NEIGHBOR_ADVERT; ns.nd_ns_type = ND_NEIGHBOR_ADVERT;
ns.nd_ns_reserved = htonl(0x40000000UL); /* Set solicited flag */ ns.nd_ns_reserved = htonl(0x40000000UL); /* Set solicited flag */
opt.nd_opt_type = ND_OPT_TARGET_LINKADDR; opt.nd_opt_type = ND_OPT_TARGET_LINKADDR;
/* Create pseudo header */ /* Create pseudo header */
@ -782,17 +782,17 @@ static void route_arp(node_t *source, vpn_packet_t *packet) {
/* Check if it is for our own subnet */ /* Check if it is for our own subnet */
if(subnet->owner == myself) if(subnet->owner == myself)
return; /* silently ignore */ return; /* silently ignore */
memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN); /* copy destination address */ memcpy(packet->data, packet->data + ETH_ALEN, ETH_ALEN); /* copy destination address */
packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */ packet->data[ETH_ALEN * 2 - 1] ^= 0xFF; /* mangle source address so it looks like it's not from us */
memcpy(&addr, arp.arp_tpa, sizeof addr); /* save protocol addr */ memcpy(&addr, arp.arp_tpa, sizeof addr); /* save protocol addr */
memcpy(arp.arp_tpa, arp.arp_spa, sizeof addr); /* swap destination and source protocol address */ memcpy(arp.arp_tpa, arp.arp_spa, sizeof addr); /* swap destination and source protocol address */
memcpy(arp.arp_spa, &addr, sizeof addr); /* ... */ memcpy(arp.arp_spa, &addr, sizeof addr); /* ... */
memcpy(arp.arp_tha, arp.arp_sha, ETH_ALEN); /* set target hard/proto addr */ memcpy(arp.arp_tha, arp.arp_sha, ETH_ALEN); /* set target hard/proto addr */
memcpy(arp.arp_sha, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */ memcpy(arp.arp_sha, packet->data + ETH_ALEN, ETH_ALEN); /* add fake source hard addr */
arp.arp_op = htons(ARPOP_REPLY); arp.arp_op = htons(ARPOP_REPLY);
/* Copy structs on stack back to packet */ /* Copy structs on stack back to packet */
@ -838,7 +838,7 @@ static void route_mac(node_t *source, vpn_packet_t *packet) {
if(directonly && subnet->owner != via) if(directonly && subnet->owner != via)
return; return;
if(via && packet->len > via->mtu && via != myself) { if(via && packet->len > via->mtu && via != myself) {
logger(DEBUG_TRAFFIC, LOG_INFO, "Packet for %s (%s) length %d larger than MTU %d", subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu); logger(DEBUG_TRAFFIC, LOG_INFO, "Packet for %s (%s) length %d larger than MTU %d", subnet->owner->name, subnet->owner->hostname, packet->len, via->mtu);
uint16_t type = packet->data[12] << 8 | packet->data[13]; uint16_t type = packet->data[12] << 8 | packet->data[13];
@ -858,7 +858,7 @@ static void route_mac(node_t *source, vpn_packet_t *packet) {
} }
clamp_mss(source, via, packet); clamp_mss(source, via, packet);
send_packet(subnet->owner, packet); send_packet(subnet->owner, packet);
} }
@ -941,28 +941,26 @@ void route(node_t *source, vpn_packet_t *packet) {
if(!do_decrement_ttl(source, packet)) if(!do_decrement_ttl(source, packet))
return; return;
uint16_t type = packet->data[12] << 8 | packet->data[13];
switch (routing_mode) { switch (routing_mode) {
case RMODE_ROUTER: case RMODE_ROUTER:
{ switch (type) {
uint16_t type = packet->data[12] << 8 | packet->data[13]; case ETH_P_ARP:
route_arp(source, packet);
break;
switch (type) { case ETH_P_IP:
case ETH_P_ARP: route_ipv4(source, packet);
route_arp(source, packet); break;
break;
case ETH_P_IP: case ETH_P_IPV6:
route_ipv4(source, packet); route_ipv6(source, packet);
break; break;
case ETH_P_IPV6: default:
route_ipv6(source, packet); logger(DEBUG_TRAFFIC, LOG_WARNING, "Cannot route packet from %s (%s): unknown type %hx", source->name, source->hostname, type);
break; break;
default:
logger(DEBUG_TRAFFIC, LOG_WARNING, "Cannot route packet from %s (%s): unknown type %hx", source->name, source->hostname, type);
break;
}
} }
break; break;

View file

@ -1,7 +1,7 @@
/* /*
route.h -- header file for route.c route.h -- header file for route.c
Copyright (C) 2000-2005 Ivo Timmermans Copyright (C) 2000-2005 Ivo Timmermans
2000-2012 Guus Sliepen <guus@tinc-vpn.org> 2000-2012 Guus Sliepen <guus@tinc-vpn.org>
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -56,4 +56,4 @@ extern mac_t mymac;
extern void route(struct node_t *, struct vpn_packet_t *); extern void route(struct node_t *, struct vpn_packet_t *);
#endif /* __TINC_ROUTE_H__ */ #endif /* __TINC_ROUTE_H__ */

View file

@ -44,10 +44,10 @@ static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *r
rightbottom->left = child; rightbottom->left = child;
child->parent = rightbottom; child->parent = rightbottom;
rightbottom = child; rightbottom = child;
if((root->left = child->right)) if((root->left = child->right))
child->right->parent = root; child->right->parent = root;
child->right = root; child->right = root;
root->parent = child; root->parent = child;
@ -74,7 +74,7 @@ static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *r
rightbottom->left = root; rightbottom->left = root;
root->parent = rightbottom; root->parent = rightbottom;
rightbottom = root; rightbottom = root;
root->left = NULL; root->left = NULL;
child->parent = NULL; child->parent = NULL;
@ -88,10 +88,10 @@ static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *r
leftbottom->right = child; leftbottom->right = child;
child->parent = leftbottom; child->parent = leftbottom;
leftbottom = child; leftbottom = child;
if((root->right = child->left)) if((root->right = child->left))
child->left->parent = root; child->left->parent = root;
child->left = root; child->left = root;
root->parent = child; root->parent = child;
@ -158,14 +158,14 @@ static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *r
return tree->root; return tree->root;
} }
static void splay_bottom_up(splay_tree_t *tree, splay_node_t *node) { static void splay_bottom_up(splay_tree_t *tree, splay_node_t *node) {
splay_node_t *parent, *grandparent, *greatgrandparent; splay_node_t *parent, *grandparent, *greatgrandparent;
while((parent = node->parent)) { while((parent = node->parent)) {
if(!(grandparent = parent->parent)) { /* zig */ if(!(grandparent = parent->parent)) { /* zig */
if(node == parent->left) { if(node == parent->left) {
if((parent->left = node->right)) if((parent->left = node->right))
parent->left->parent = parent; parent->left->parent = parent;
node->right = parent; node->right = parent;
} else { } else {
@ -326,7 +326,7 @@ splay_node_t *splay_search_closest_node_nosplay(const splay_tree_t *tree, const
} else if(c > 0) { } else if(c > 0) {
if(node->right) if(node->right)
node = node->right; node = node->right;
else else
break; break;
} else { } else {
break; break;
@ -384,12 +384,12 @@ splay_node_t *splay_insert(splay_tree_t *tree, void *data) {
new = splay_alloc_node(); new = splay_alloc_node();
new->data = data; new->data = data;
if(result < 0) if(result < 0)
splay_insert_before(tree, closest, new); splay_insert_before(tree, closest, new);
else else
splay_insert_after(tree, closest, new); splay_insert_after(tree, closest, new);
} }
return new; return new;
} }
@ -402,7 +402,7 @@ splay_node_t *splay_insert_node(splay_tree_t *tree, splay_node_t *node) {
splay_insert_top(tree, node); splay_insert_top(tree, node);
else { else {
closest = splay_search_closest_node(tree, node->data, &result); closest = splay_search_closest_node(tree, node->data, &result);
if(!result) if(!result)
return NULL; return NULL;

View file

@ -508,7 +508,7 @@ bool sptps_receive_data(sptps_t *s, const char *data, size_t len) {
s->buflen += toread; s->buflen += toread;
len -= toread; len -= toread;
data += toread; data += toread;
// Exit early if we don't have the full length. // Exit early if we don't have the full length.
if(s->buflen < 6) if(s->buflen < 6)
return true; return true;

View file

@ -79,7 +79,7 @@ int main(int argc, char *argv[]) {
hint.ai_socktype = SOCK_STREAM; hint.ai_socktype = SOCK_STREAM;
hint.ai_protocol = IPPROTO_TCP; hint.ai_protocol = IPPROTO_TCP;
hint.ai_flags = initiator ? 0 : AI_PASSIVE; hint.ai_flags = initiator ? 0 : AI_PASSIVE;
if(getaddrinfo(initiator ? argv[3] : NULL, initiator ? argv[4] : argv[3], &hint, &ai) || !ai) { if(getaddrinfo(initiator ? argv[3] : NULL, initiator ? argv[4] : argv[3], &hint, &ai) || !ai) {
fprintf(stderr, "getaddrinfo() failed: %s\n", strerror(errno)); fprintf(stderr, "getaddrinfo() failed: %s\n", strerror(errno));
return 1; return 1;

View file

@ -27,7 +27,7 @@ typedef enum subnet_type_t {
SUBNET_MAC = 0, SUBNET_MAC = 0,
SUBNET_IPV4, SUBNET_IPV4,
SUBNET_IPV6, SUBNET_IPV6,
SUBNET_TYPES /* Guardian */ SUBNET_TYPES /* Guardian */
} subnet_type_t; } subnet_type_t;
typedef struct subnet_mac_t { typedef struct subnet_mac_t {
@ -47,11 +47,11 @@ typedef struct subnet_ipv6_t {
#include "node.h" #include "node.h"
typedef struct subnet_t { typedef struct subnet_t {
struct node_t *owner; /* the owner of this subnet */ struct node_t *owner; /* the owner of this subnet */
subnet_type_t type; /* subnet type (IPv4? IPv6? MAC? something even weirder?) */ subnet_type_t type; /* subnet type (IPv4? IPv6? MAC? something even weirder?) */
time_t expires; /* expiry time */ time_t expires; /* expiry time */
int weight; /* weight (higher value is higher priority) */ int weight; /* weight (higher value is higher priority) */
/* And now for the actual subnet: */ /* And now for the actual subnet: */
@ -89,4 +89,4 @@ extern subnet_t *lookup_subnet_ipv6(const ipv6_t *);
extern bool dump_subnets(struct connection_t *); extern bool dump_subnets(struct connection_t *);
extern void subnet_cache_flush(void); extern void subnet_cache_flush(void);
#endif /* __TINC_SUBNET_H__ */ #endif /* __TINC_SUBNET_H__ */

View file

@ -104,7 +104,7 @@ static int subnet_compare_mac(const subnet_t *a, const subnet_t *b) {
if(result) if(result)
return result; return result;
result = a->weight - b->weight; result = a->weight - b->weight;
if(result || !a->owner || !b->owner) if(result || !a->owner || !b->owner)
@ -125,7 +125,7 @@ static int subnet_compare_ipv4(const subnet_t *a, const subnet_t *b) {
if(result) if(result)
return result; return result;
result = a->weight - b->weight; result = a->weight - b->weight;
if(result || !a->owner || !b->owner) if(result || !a->owner || !b->owner)
@ -141,12 +141,12 @@ static int subnet_compare_ipv6(const subnet_t *a, const subnet_t *b) {
if(result) if(result)
return result; return result;
result = memcmp(&a->net.ipv6.address, &b->net.ipv6.address, sizeof(ipv6_t)); result = memcmp(&a->net.ipv6.address, &b->net.ipv6.address, sizeof(ipv6_t));
if(result) if(result)
return result; return result;
result = a->weight - b->weight; result = a->weight - b->weight;
if(result || !a->owner || !b->owner) if(result || !a->owner || !b->owner)

View file

@ -54,8 +54,8 @@ static bool show_help = false;
static bool show_version = false; static bool show_version = false;
static char *name = NULL; static char *name = NULL;
static char *identname = NULL; /* program name for syslog */ static char *identname = NULL; /* program name for syslog */
static char *pidfilename = NULL; /* pid file location */ static char *pidfilename = NULL; /* pid file location */
static char *confdir = NULL; static char *confdir = NULL;
static char controlcookie[1024]; static char controlcookie[1024];
char *netname = NULL; char *netname = NULL;
@ -163,34 +163,34 @@ static bool parse_options(int argc, char **argv) {
while((r = getopt_long(argc, argv, "c:n:Dd::Lo:RU:", long_options, &option_index)) != EOF) { while((r = getopt_long(argc, argv, "c:n:Dd::Lo:RU:", long_options, &option_index)) != EOF) {
switch (r) { switch (r) {
case 0: /* long option */ case 0: /* long option */
break; break;
case 'c': /* config file */ case 'c': /* config file */
confbase = xstrdup(optarg); confbase = xstrdup(optarg);
break; break;
case 'n': /* net name given */ case 'n': /* net name given */
netname = xstrdup(optarg); netname = xstrdup(optarg);
break; break;
case 1: /* show help */ case 1: /* show help */
show_help = true; show_help = true;
break; break;
case 2: /* show version */ case 2: /* show version */
show_version = true; show_version = true;
break; break;
case 5: /* open control socket here */ case 5: /* open control socket here */
pidfilename = xstrdup(optarg); pidfilename = xstrdup(optarg);
break; break;
case 6: case 6: /* force */
force = true; force = true;
break; break;
case '?': case '?': /* wrong options */
usage(true); usage(true);
return false; return false;
@ -199,15 +199,15 @@ static bool parse_options(int argc, char **argv) {
} }
} }
if(!netname && (netname = getenv("NETNAME"))) if(!netname && (netname = getenv("NETNAME")))
netname = xstrdup(netname); netname = xstrdup(netname);
/* netname "." is special: a "top-level name" */ /* netname "." is special: a "top-level name" */
if(netname && (!*netname || !strcmp(netname, "."))) { if(netname && (!*netname || !strcmp(netname, "."))) {
free(netname); free(netname);
netname = NULL; netname = NULL;
} }
if(netname && (strpbrk(netname, "\\/") || *netname == '.')) { if(netname && (strpbrk(netname, "\\/") || *netname == '.')) {
fprintf(stderr, "Invalid character in netname!\n"); fprintf(stderr, "Invalid character in netname!\n");
@ -332,7 +332,7 @@ static FILE *ask_and_open(const char *filename, const char *what, const char *mo
filename = buf2; filename = buf2;
} }
umask(0077); /* Disallow everything for group and other */ umask(0077); /* Disallow everything for group and other */
disable_old_keys(filename, what); disable_old_keys(filename, what);
@ -371,12 +371,12 @@ static bool ecdsa_keygen(bool ask) {
if(!f) if(!f)
return false; return false;
#ifdef HAVE_FCHMOD #ifdef HAVE_FCHMOD
/* Make it unreadable for others. */ /* Make it unreadable for others. */
fchmod(fileno(f), 0600); fchmod(fileno(f), 0600);
#endif #endif
ecdsa_write_pem_private_key(&key, f); ecdsa_write_pem_private_key(&key, f);
fclose(f); fclose(f);
@ -424,12 +424,12 @@ static bool rsa_keygen(int bits, bool ask) {
if(!f) if(!f)
return false; return false;
#ifdef HAVE_FCHMOD #ifdef HAVE_FCHMOD
/* Make it unreadable for others. */ /* Make it unreadable for others. */
fchmod(fileno(f), 0600); fchmod(fileno(f), 0600);
#endif #endif
rsa_write_pem_private_key(&key, f); rsa_write_pem_private_key(&key, f);
fclose(f); fclose(f);
@ -579,7 +579,7 @@ bool sendline(int fd, char *format, ...) {
blen -= result; blen -= result;
} }
return true; return true;
} }
static void pcap(int fd, FILE *out, int snaplen) { static void pcap(int fd, FILE *out, int snaplen) {
@ -781,7 +781,7 @@ static bool connect_tincd(bool verbose) {
} }
sendline(fd, "%d ^%s %d", ID, controlcookie, TINC_CTL_VERSION_CURRENT); sendline(fd, "%d ^%s %d", ID, controlcookie, TINC_CTL_VERSION_CURRENT);
if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &version, &pid) != 3 || code != 4 || version != TINC_CTL_VERSION_CURRENT) { if(!recvline(fd, line, sizeof line) || sscanf(line, "%d %d %d", &code, &version, &pid) != 3 || code != 4 || version != TINC_CTL_VERSION_CURRENT) {
if(verbose) if(verbose)
fprintf(stderr, "Could not fully establish control socket connection\n"); fprintf(stderr, "Could not fully establish control socket connection\n");
@ -839,7 +839,7 @@ static int cmd_start(int argc, char *argv[]) {
if(!pid) if(!pid)
exit(execvp(c, nargv)); exit(execvp(c, nargv));
free(nargv); free(nargv);
int status = -1; int status = -1;
@ -1312,14 +1312,14 @@ static int cmd_config(int argc, char *argv[]) {
char *value; char *value;
int len; int len;
len = strcspn(line, "\t ="); len = strcspn(line, "\t =");
value = line + len; value = line + len;
value += strspn(value, "\t "); value += strspn(value, "\t ");
if(*value == '=') { if(*value == '=') {
value++; value++;
value += strspn(value, "\t "); value += strspn(value, "\t ");
} }
line[len] = '\0'; line[len] = '\0';
variable = strchr(line, '.'); variable = strchr(line, '.');
if(variable) { if(variable) {
node = line; node = line;
@ -2153,7 +2153,7 @@ int main(int argc, char *argv[]) {
if(!parse_options(argc, argv)) if(!parse_options(argc, argv))
return 1; return 1;
make_names(); make_names();
if(show_version) { if(show_version) {

View file

@ -87,10 +87,10 @@ static const char *switchuser = NULL;
/* If nonzero, write log entries to a separate file. */ /* If nonzero, write log entries to a separate file. */
bool use_logfile = false; bool use_logfile = false;
char *identname = NULL; /* program name for syslog */ char *identname = NULL; /* program name for syslog */
char *logfilename = NULL; /* log file location */ char *logfilename = NULL; /* log file location */
char *pidfilename = NULL; char *pidfilename = NULL;
char **g_argv; /* a copy of the cmdline arguments */ char **g_argv; /* a copy of the cmdline arguments */
static int status = 1; static int status = 1;
@ -123,7 +123,7 @@ static void usage(bool status) {
program_name); program_name);
else { else {
printf("Usage: %s [option]...\n\n", program_name); printf("Usage: %s [option]...\n\n", program_name);
printf( " -c, --config=DIR Read configuration options from DIR.\n" printf( " -c, --config=DIR Read configuration options from DIR.\n"
" -D, --no-detach Don't fork and detach.\n" " -D, --no-detach Don't fork and detach.\n"
" -d, --debug[=LEVEL] Increase debug level or set it to LEVEL.\n" " -d, --debug[=LEVEL] Increase debug level or set it to LEVEL.\n"
" -n, --net=NETNAME Connect to net NETNAME.\n" " -n, --net=NETNAME Connect to net NETNAME.\n"
@ -133,7 +133,7 @@ static void usage(bool status) {
" --bypass-security Disables meta protocol security, for debugging.\n" " --bypass-security Disables meta protocol security, for debugging.\n"
" -o, --option[HOST.]KEY=VALUE Set global/host configuration value.\n" " -o, --option[HOST.]KEY=VALUE Set global/host configuration value.\n"
" -R, --chroot chroot to NET dir at startup.\n" " -R, --chroot chroot to NET dir at startup.\n"
" -U, --user=USER setuid to given USER at startup.\n" " --help Display this help and exit.\n" " -U, --user=USER setuid to given USER at startup.\n" " --help Display this help and exit.\n"
" --version Output version information and exit.\n\n"); " --version Output version information and exit.\n\n");
printf("Report bugs to tinc@tinc-vpn.org.\n"); printf("Report bugs to tinc@tinc-vpn.org.\n");
} }
@ -149,18 +149,18 @@ static bool parse_options(int argc, char **argv) {
while((r = getopt_long(argc, argv, "c:DLd::n:o:RU:", long_options, &option_index)) != EOF) { while((r = getopt_long(argc, argv, "c:DLd::n:o:RU:", long_options, &option_index)) != EOF) {
switch (r) { switch (r) {
case 0: /* long option */ case 0: /* long option */
break; break;
case 'c': /* config file */ case 'c': /* config file */
confbase = xstrdup(optarg); confbase = xstrdup(optarg);
break; break;
case 'D': /* no detach */ case 'D': /* no detach */
do_detach = false; do_detach = false;
break; break;
case 'L': /* no detach */ case 'L': /* no detach */
#ifndef HAVE_MLOCKALL #ifndef HAVE_MLOCKALL
logger(DEBUG_ALWAYS, LOG_ERR, "%s not supported on this platform", "mlockall()"); logger(DEBUG_ALWAYS, LOG_ERR, "%s not supported on this platform", "mlockall()");
return false; return false;
@ -169,55 +169,55 @@ static bool parse_options(int argc, char **argv) {
break; break;
#endif #endif
case 'd': /* inc debug level */ case 'd': /* inc debug level */
if(optarg) if(optarg)
debug_level = atoi(optarg); debug_level = atoi(optarg);
else else
debug_level++; debug_level++;
break; break;
case 'n': /* net name given */ case 'n': /* net name given */
netname = xstrdup(optarg); netname = xstrdup(optarg);
break; break;
case 'o': /* option */ case 'o': /* option */
cfg = parse_config_line(optarg, NULL, ++lineno); cfg = parse_config_line(optarg, NULL, ++lineno);
if (!cfg) if (!cfg)
return false; return false;
list_insert_tail(cmdline_conf, cfg); list_insert_tail(cmdline_conf, cfg);
break; break;
case 'R': /* chroot to NETNAME dir */ case 'R': /* chroot to NETNAME dir */
do_chroot = true; do_chroot = true;
break; break;
case 'U': /* setuid to USER */ case 'U': /* setuid to USER */
switchuser = optarg; switchuser = optarg;
break; break;
case 1: /* show help */ case 1: /* show help */
show_help = true; show_help = true;
break; break;
case 2: /* show version */ case 2: /* show version */
show_version = true; show_version = true;
break; break;
case 3: /* bypass security */ case 3: /* bypass security */
bypass_security = true; bypass_security = true;
break; break;
case 4: /* write log entries to a file */ case 4: /* write log entries to a file */
use_logfile = true; use_logfile = true;
if(optarg) if(optarg)
logfilename = xstrdup(optarg); logfilename = xstrdup(optarg);
break; break;
case 5: /* open control socket here */ case 5: /* open control socket here */
pidfilename = xstrdup(optarg); pidfilename = xstrdup(optarg);
break; break;
case '?': case '?': /* wrong options */
usage(true); usage(true);
return false; return false;
@ -336,7 +336,7 @@ static bool drop_privs(void) {
#endif #endif
} }
if (do_chroot) { if (do_chroot) {
tzset(); /* for proper timestamps in logs */ tzset(); /* for proper timestamps in logs */
if (chroot(confbase) != 0 || chdir("/") != 0) { if (chroot(confbase) != 0 || chdir("/") != 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s",
"chroot", strerror(errno)); "chroot", strerror(errno));
@ -369,7 +369,7 @@ int main(int argc, char **argv) {
if(!parse_options(argc, argv)) if(!parse_options(argc, argv))
return 1; return 1;
make_names(); make_names();
if(show_version) { if(show_version) {
@ -434,7 +434,7 @@ int main2(int argc, char **argv) {
InitializeCriticalSection(&mutex); InitializeCriticalSection(&mutex);
EnterCriticalSection(&mutex); EnterCriticalSection(&mutex);
#endif #endif
char *priority = NULL; char *priority = NULL;
if(!detach()) if(!detach())
return 1; return 1;
@ -469,30 +469,27 @@ int main2(int argc, char **argv) {
/* Change process priority */ /* Change process priority */
if(get_config_string(lookup_config(config_tree, "ProcessPriority"), &priority)) { if(get_config_string(lookup_config(config_tree, "ProcessPriority"), &priority)) {
if(!strcasecmp(priority, "Normal")) { if(!strcasecmp(priority, "Normal")) {
if (setpriority(NORMAL_PRIORITY_CLASS) != 0) { if (setpriority(NORMAL_PRIORITY_CLASS) != 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setpriority", strerror(errno));
"setpriority", strerror(errno)); goto end;
goto end; }
} } else if(!strcasecmp(priority, "Low")) {
} else if(!strcasecmp(priority, "Low")) { if (setpriority(BELOW_NORMAL_PRIORITY_CLASS) != 0) {
if (setpriority(BELOW_NORMAL_PRIORITY_CLASS) != 0) { logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setpriority", strerror(errno));
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", goto end;
"setpriority", strerror(errno)); }
goto end; } else if(!strcasecmp(priority, "High")) {
} if (setpriority(HIGH_PRIORITY_CLASS) != 0) {
} else if(!strcasecmp(priority, "High")) { logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "setpriority", strerror(errno));
if (setpriority(HIGH_PRIORITY_CLASS) != 0) { goto end;
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", }
"setpriority", strerror(errno)); } else {
goto end; logger(DEBUG_ALWAYS, LOG_ERR, "Invalid priority `%s`!", priority);
} goto end;
} else { }
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid priority `%s`!", priority); }
goto end;
}
}
/* drop privileges */ /* drop privileges */
if (!drop_privs()) if (!drop_privs())

View file

@ -156,7 +156,7 @@ static void redraw(void) {
for(int i = 0; i < n; i++) for(int i = 0; i < n; i++)
sorted[i]->i = i; sorted[i]->i = i;
int cmpfloat(float a, float b) { int cmpfloat(float a, float b) {
if(a < b) if(a < b)
return -1; return -1;

View file

@ -113,7 +113,7 @@ static bool setup_device(void) {
name.usecs = tv.tv_usec; name.usecs = tv.tv_usec;
data_sun.sun_family = AF_UNIX; data_sun.sun_family = AF_UNIX;
memcpy(&data_sun.sun_path, &name, sizeof name); memcpy(&data_sun.sun_path, &name, sizeof name);
if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof data_sun) < 0) { if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof data_sun) < 0) {
logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind data %s: %s", device_info, strerror(errno)); logger(DEBUG_ALWAYS, LOG_ERR, "Could not bind data %s: %s", device_info, strerror(errno));
running = false; running = false;

View file

@ -38,7 +38,7 @@ static int charb64decode(char c) {
return c - 'a' + 26; return c - 'a' + 26;
else if(c >= 'A') else if(c >= 'A')
return c - 'A'; return c - 'A';
else if(c >= '0') else if(c >= '0')
return c - '0' + 52; return c - '0' + 52;
else if(c == '+') else if(c == '+')
return 62; return 62;
@ -96,7 +96,7 @@ int b64encode(const char *src, char *dst, int length) {
int di = length / 3 * 4; int di = length / 3 * 4;
switch(length % 3) { switch(length % 3) {
case 2: case 2:
triplet = usrc[si] | usrc[si + 1] << 8; triplet = usrc[si] | usrc[si + 1] << 8;
dst[di] = base64imals[triplet & 63]; triplet >>= 6; dst[di] = base64imals[triplet & 63]; triplet >>= 6;
dst[di + 1] = base64imals[triplet & 63]; triplet >>= 6; dst[di + 1] = base64imals[triplet & 63]; triplet >>= 6;
@ -141,7 +141,7 @@ const char *winerror(int err) {
ptr = buf + sprintf(buf, "(%d) ", err); ptr = buf + sprintf(buf, "(%d) ", err);
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ptr, sizeof(buf) - (ptr - buf), NULL)) { NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), ptr, sizeof(buf) - (ptr - buf), NULL)) {
strncpy(buf, "(unable to format errormessage)", sizeof(buf)); strncpy(buf, "(unable to format errormessage)", sizeof(buf));
}; };

View file

@ -47,4 +47,4 @@ extern const char *winerror(int);
extern unsigned int bitfield_to_int(const void *bitfield, size_t size); extern unsigned int bitfield_to_int(const void *bitfield, size_t size);
#endif /* __TINC_UTILS_H__ */ #endif /* __TINC_UTILS_H__ */