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

@ -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
@ -178,7 +178,7 @@ static bool setup_device(void) {
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
} }

View file

@ -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

@ -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;
@ -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) {

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

@ -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;

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

@ -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);

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

@ -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

@ -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

@ -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

@ -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;

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

@ -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

@ -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

@ -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;

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,8 +239,8 @@ 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 */

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

@ -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;
} }
@ -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 {
@ -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

@ -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

@ -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);

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;

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

@ -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

@ -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());
} }

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,7 +102,7 @@ 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;
@ -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

@ -451,8 +451,8 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, uint8_t
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;
@ -591,8 +591,8 @@ 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;
@ -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 */
@ -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

@ -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

@ -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

@ -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);
@ -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;

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));
@ -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

@ -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__ */