From: Guus Sliepen Date: Mon, 6 Jun 2011 18:42:15 +0000 (+0200) Subject: Merge branch 'master' of git://tinc-vpn.org/tinc into 1.1 X-Git-Tag: import-tinc-1.1~486 X-Git-Url: http://git.meshlink.io/?p=meshlink;a=commitdiff_plain;h=33f241d97852d7a171f1aaf1bda7f66356ff889e;hp=601f3b2dd746ff5726eca256861f2ecf662b3a55 Merge branch 'master' of git://tinc-vpn.org/tinc into 1.1 Conflicts: NEWS configure.in doc/tincd.8.in lib/pidfile.c lib/pidfile.h lib/xalloc.h lib/xmalloc.c src/conf.c src/conf.h src/connection.c src/connection.h src/event.c src/graph.c src/graph.h src/net.c src/net.h src/node.h src/openssl/crypto.c src/process.c src/protocol.c src/protocol_key.c src/route.c --- diff --git a/AUTHORS b/AUTHORS index e4189967..af113938 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,6 +11,7 @@ Significant contributions from: - Julien Muchembled - Timothy Redaelli - Brandon Black +- Loïc Grenié These files are from other sources: * lib/pidfile.h and lib/pidfile.c are by Martin Schulze, taken from diff --git a/NEWS b/NEWS index c48a0e80..1a121551 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ Version 1.1-cvs Work in progress * Use splay trees instead of AVL trees. + * Fix ProcessPriority option under Windows. + Version 1.0.14 May 8 2011 * Fixed reading configuration files that do not end with a newline. Again. diff --git a/THANKS b/THANKS index dc1297b3..4a6eae20 100644 --- a/THANKS +++ b/THANKS @@ -19,6 +19,7 @@ We would like to thank the following people for their contributions to tinc: * Jeroen Ubbink * Jerome Etienne * Julien Muchembled +* Loïc Grenié * Lubomír Bulej * Mads Kiilerich * Marc A. Lehmann diff --git a/configure.in b/configure.in index 22e5fb1f..0e12a365 100644 --- a/configure.in +++ b/configure.in @@ -127,7 +127,7 @@ AC_CHECK_TYPES([socklen_t, struct ether_header, struct arphdr, struct ether_arp, dnl Checks for library functions. AC_TYPE_SIGNAL -AC_CHECK_FUNCS([asprintf daemon fchmod flock ftime fork get_current_dir_name gettimeofday mlockall putenv random select strdup strerror strsignal strtol system time usleep unsetenv vsyslog writev], +AC_CHECK_FUNCS([asprintf daemon fchmod flock ftime fork get_current_dir_name gettimeofday mlockall pselect putenv random select strdup strerror strsignal strtol system time usleep unsetenv vsyslog writev], [], [], [#include "have.h"] ) diff --git a/doc/tinc.texi b/doc/tinc.texi index 7fc8909f..7878db56 100644 --- a/doc/tinc.texi +++ b/doc/tinc.texi @@ -1636,6 +1636,8 @@ You can also send the following signals to a running tincd process: Partially rereads configuration files. Connections to hosts whose host config file are removed are closed. New outgoing connections specified in @file{tinc.conf} will be made. +If the --logfile option is used, this will also close and reopen the log file, +useful when log rotation is used. @end table diff --git a/doc/tincd.8.in b/doc/tincd.8.in index a210979e..0e790e03 100644 --- a/doc/tincd.8.in +++ b/doc/tincd.8.in @@ -101,6 +101,19 @@ Connections to hosts whose host config file are removed are closed. New outgoing connections specified in .Pa tinc.conf will be made. +If the +.Fl -logfile +option is used, this will also close and reopen the log file, +useful when log rotation is used. +.It INT +Temporarily increases debug level to 5. +Send this signal again to revert to the original level. +.It USR1 +Dumps the connection list to syslog. +.It USR2 +Dumps virtual network device statistics, all known nodes, edges and subnets to syslog. +.It WINCH +Purges all information remembered about unreachable nodes. .El .Sh DEBUG LEVELS The tinc daemon can send a lot of messages to the syslog. diff --git a/m4/openssl.m4 b/m4/openssl.m4 index 59f0d450..254ea4ff 100644 --- a/m4/openssl.m4 +++ b/m4/openssl.m4 @@ -2,6 +2,20 @@ dnl Check to find the OpenSSL headers/libraries AC_DEFUN([tinc_OPENSSL], [ + case $host_os in + *mingw*) + ;; + *) + AC_CHECK_FUNC(dlopen, + [], + [AC_CHECK_LIB(dl, dlopen, + [LIBS="$LIBS -ldl"], + [AC_MSG_ERROR([OpenSSL depends on libdl.]); break] + )] + ) + ;; + esac + AC_ARG_WITH(openssl, AS_HELP_STRING([--with-openssl=DIR], [OpenSSL base directory, or:]), [openssl="$withval" @@ -31,20 +45,6 @@ AC_DEFUN([tinc_OPENSSL], [AC_MSG_ERROR([OpenSSL libraries not found.])] ) -case $host_os in - *mingw*) - ;; - *) - AC_CHECK_FUNC(dlopen, - [], - [AC_CHECK_LIB(dl, dlopen, - [LIBS="$LIBS -ldl"], - [AC_MSG_ERROR([OpenSSL depends on libdl.]); break] - )] - ) - ;; -esac - AC_CHECK_FUNCS([RAND_pseudo_bytes EVP_EncryptInit_ex], , [AC_MSG_ERROR([Missing OpenSSL functionality, make sure you have installed the latest version.]); break], ) diff --git a/src/bsd/device.c b/src/bsd/device.c index d647734e..9c3009d5 100644 --- a/src/bsd/device.c +++ b/src/bsd/device.c @@ -22,6 +22,7 @@ #include "system.h" #include "conf.h" +#include "device.h" #include "logger.h" #include "net.h" #include "route.h" diff --git a/src/conf.c b/src/conf.c index 593cd0c2..099b77da 100644 --- a/src/conf.c +++ b/src/conf.c @@ -26,6 +26,7 @@ #include "splay_tree.h" #include "connection.h" #include "conf.h" +#include "list.h" #include "logger.h" #include "netutl.h" /* for str2address */ #include "protocol.h" diff --git a/src/connection.c b/src/connection.c index 5beea4d9..62bfccb6 100644 --- a/src/connection.c +++ b/src/connection.c @@ -27,8 +27,6 @@ #include "control_common.h" #include "list.h" #include "logger.h" -#include "net.h" /* Don't ask. */ -#include "netutl.h" #include "subnet.h" #include "utils.h" #include "xalloc.h" diff --git a/src/connection.h b/src/connection.h index a7db40aa..75015ffe 100644 --- a/src/connection.h +++ b/src/connection.h @@ -48,7 +48,6 @@ typedef struct connection_status_t { } connection_status_t; #include "edge.h" -#include "list.h" #include "net.h" #include "node.h" diff --git a/src/cygwin/device.c b/src/cygwin/device.c index 5c227fd7..a4ab938c 100644 --- a/src/cygwin/device.c +++ b/src/cygwin/device.c @@ -24,6 +24,7 @@ #include #include "conf.h" +#include "device.h" #include "logger.h" #include "net.h" #include "route.h" diff --git a/src/dummy/device.c b/src/dummy/device.c index c84e899b..25a38f2d 100644 --- a/src/dummy/device.c +++ b/src/dummy/device.c @@ -19,6 +19,7 @@ #include "system.h" +#include "device.h" #include "logger.h" #include "net.h" diff --git a/src/graph.c b/src/graph.c index 28be9d5f..bb55dfdc 100644 --- a/src/graph.c +++ b/src/graph.c @@ -49,6 +49,7 @@ #include "connection.h" #include "device.h" #include "edge.h" +#include "graph.h" #include "logger.h" #include "netutl.h" #include "node.h" @@ -183,9 +184,6 @@ static void sssp_dijkstra(void) { n->address is set to the e->address of the edge left of n to n. We are currently examining the edge e right of n from n: - - If e->reverse->address != n->address, then e->to is probably - not reachable for the nodes left of n. We do as if the indirectdata - flag is set on edge e. - If edge e provides for better reachability of e->to, update e->to. */ @@ -203,27 +201,8 @@ static void sssp_dijkstra(void) { e->to->via = indirect ? n->via : e->to; e->to->options = e->options; - if(sockaddrcmp(&e->to->address, &e->address)) { - node = splay_unlink(node_udp_tree, e->to); - sockaddrfree(&e->to->address); - sockaddrcpy(&e->to->address, &e->address); - - if(e->to->hostname) - free(e->to->hostname); - - e->to->hostname = sockaddr2hostname(&e->to->address); - - if(node) - splay_insert_node(node_udp_tree, node); - - if(e->to->options & OPTION_PMTU_DISCOVERY) { - e->to->mtuprobes = 0; - e->to->minmtu = 0; - e->to->maxmtu = MTU; - if(e->to->status.validkey) - send_mtu_probe(e->to); - } - } + if(e->to->address.sa.sa_family == AF_UNSPEC && e->address.sa.sa_family != AF_UNKNOWN) + update_node_udp(e->to, &e->address); ifdebug(SCARY_THINGS) logger(LOG_DEBUG, " Updating edge %s - %s weight %d distance %d", e->from->name, e->to->name, e->weight, e->to->distance); diff --git a/src/graph.h b/src/graph.h index c8d5fda6..fb410961 100644 --- a/src/graph.h +++ b/src/graph.h @@ -22,7 +22,6 @@ #define __TINC_GRAPH_H__ extern void graph(void); -extern void mst_kruskal(void); -extern void sssp_bfs(void); +extern void dump_graph(void); #endif /* __TINC_GRAPH_H__ */ diff --git a/src/linux/device.c b/src/linux/device.c index f95410c6..d36f3f67 100644 --- a/src/linux/device.c +++ b/src/linux/device.c @@ -24,6 +24,7 @@ #define DEFAULT_DEVICE "/dev/net/tun" #include "conf.h" +#include "device.h" #include "logger.h" #include "net.h" #include "route.h" diff --git a/src/logger.c b/src/logger.c index 4c0d2312..08f97954 100644 --- a/src/logger.c +++ b/src/logger.c @@ -44,14 +44,18 @@ void openlogger(const char *ident, logmode_t mode) { case LOGMODE_FILE: logpid = getpid(); logfile = fopen(logfilename, "a"); - if(!logfile) + if(!logfile) { + fprintf(stderr, "Could not open log file %s: %s\n", logfilename, strerror(errno)); logmode = LOGMODE_NULL; + } break; case LOGMODE_SYSLOG: #ifdef HAVE_MINGW loghandle = RegisterEventSource(NULL, logident); - if(!loghandle) + if(!loghandle) { + fprintf(stderr, "Could not open log handle!"); logmode = LOGMODE_NULL; + } break; #else #ifdef HAVE_SYSLOG_H @@ -64,8 +68,24 @@ void openlogger(const char *ident, logmode_t mode) { } } +void reopenlogger() { + if(logmode != LOGMODE_FILE) + return; + + fflush(logfile); + FILE *newfile = fopen(logfilename, "a"); + if(!newfile) { + logger(LOG_ERR, "Unable to reopen log file %s: %s\n", logfilename, strerror(errno)); + return; + } + fclose(logfile); + logfile = newfile; +} + void logger(int priority, const char *format, ...) { va_list ap; + char timestr[32] = ""; + time_t now; va_start(ap, format); @@ -76,7 +96,9 @@ void logger(int priority, const char *format, ...) { fflush(stderr); break; case LOGMODE_FILE: - fprintf(logfile, "%ld %s[%ld]: ", time(NULL), logident, (long)logpid); + now = time(NULL); + strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now)); + fprintf(logfile, "%s %s[%ld]: ", timestr, logident, (long)logpid); vfprintf(logfile, format, ap); fprintf(logfile, "\n"); fflush(logfile); diff --git a/src/logger.h b/src/logger.h index 9c20eada..ff2cb345 100644 --- a/src/logger.h +++ b/src/logger.h @@ -47,6 +47,7 @@ enum { extern debug_t debug_level; extern void openlogger(const char *, logmode_t); +extern void reopenlogger(void); extern void logger(int, const char *, ...) __attribute__ ((__format__(printf, 2, 3))); extern void closelogger(void); diff --git a/src/mingw/device.c b/src/mingw/device.c index aeffdc36..bdca8424 100644 --- a/src/mingw/device.c +++ b/src/mingw/device.c @@ -24,6 +24,7 @@ #include #include "conf.h" +#include "device.h" #include "logger.h" #include "net.h" #include "route.h" diff --git a/src/net.c b/src/net.c index 67603f7d..b299bf18 100644 --- a/src/net.c +++ b/src/net.c @@ -3,6 +3,7 @@ Copyright (C) 1998-2005 Ivo Timmermans, 2000-2011 Guus Sliepen 2006 Scott Lamb + 2011 Loïc Grenié 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 @@ -166,14 +167,14 @@ static void timeout_handler(int fd, short events, void *event) { next = node->next; c = node->data; - if(c->last_ping_time + pingtimeout < now) { + if(c->last_ping_time + pingtimeout <= now) { if(c->status.active) { if(c->status.pinged) { ifdebug(CONNECTIONS) logger(LOG_INFO, "%s (%s) didn't respond to PING in %ld seconds", c->name, c->hostname, now - c->last_ping_time); terminate_connection(c, true); continue; - } else if(c->last_ping_time + pinginterval < now) { + } else if(c->last_ping_time + pinginterval <= now) { send_ping(c); } } else { diff --git a/src/net.h b/src/net.h index 3a37fe17..b24d2d4d 100644 --- a/src/net.h +++ b/src/net.h @@ -132,7 +132,7 @@ extern void handle_new_meta_connection(int, short, void *); extern int setup_listen_socket(const sockaddr_t *); extern int setup_vpn_in_socket(const sockaddr_t *); extern void send_packet(struct node_t *, vpn_packet_t *); -extern void receive_tcppacket(struct connection_t *, char *, int); +extern void receive_tcppacket(struct connection_t *, const char *, int); extern void broadcast_packet(const struct node_t *, vpn_packet_t *); extern bool setup_network(void); extern void setup_outgoing_connection(struct outgoing_t *); @@ -145,11 +145,11 @@ extern bool read_rsa_public_key(struct connection_t *); extern void send_mtu_probe(struct node_t *); extern void handle_device_data(int, short, void *); extern void handle_meta_connection_data(int, short, void *); -extern void regenerate_key(); +extern void regenerate_key(void); extern void purge(void); extern void retry(void); extern int reload_configuration(void); -extern void load_all_subnets(); +extern void load_all_subnets(void); #ifndef HAVE_MINGW #define closesocket(s) close(s) diff --git a/src/net_packet.c b/src/net_packet.c index 1af5026a..3627f31d 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -45,7 +45,6 @@ #include "device.h" #include "ethernet.h" #include "graph.h" -#include "list.h" #include "logger.h" #include "net.h" #include "netutl.h" @@ -357,7 +356,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) { receive_packet(n, inpkt); } -void receive_tcppacket(connection_t *c, char *buffer, int len) { +void receive_tcppacket(connection_t *c, const char *buffer, int len) { vpn_packet_t outpkt; outpkt.len = len; @@ -398,7 +397,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { "No valid key known yet for %s (%s), forwarding via TCP", n->name, n->hostname); - if(n->last_req_key + 10 < now) { + if(n->last_req_key + 10 <= now) { send_req_key(n); n->last_req_key = now; } diff --git a/src/node.h b/src/node.h index 41737372..2f081863 100644 --- a/src/node.h +++ b/src/node.h @@ -25,7 +25,6 @@ #include "cipher.h" #include "connection.h" #include "digest.h" -#include "list.h" #include "subnet.h" typedef struct node_status_t { diff --git a/src/process.c b/src/process.c index 8c6679b8..ee5fce97 100644 --- a/src/process.c +++ b/src/process.c @@ -26,6 +26,7 @@ #include "device.h" #include "edge.h" #include "logger.h" +#include "net.h" #include "node.h" #include "process.h" #include "subnet.h" diff --git a/src/protocol.c b/src/protocol.c index fd908949..650c5129 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -205,7 +205,7 @@ static void age_past_requests(int fd, short events, void *data) { next = node->next; p = node->data; - if(p->firstseen + pinginterval < now) + if(p->firstseen + pinginterval <= now) splay_delete_node(past_request_tree, node), deleted++; else left++; diff --git a/src/protocol.h b/src/protocol.h index 29c4ab1c..f1c2a206 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -96,10 +96,10 @@ extern bool send_add_subnet(struct connection_t *, const struct subnet_t *); extern bool send_del_subnet(struct connection_t *, const struct subnet_t *); extern bool send_add_edge(struct connection_t *, const struct edge_t *); extern bool send_del_edge(struct connection_t *, const struct edge_t *); -extern void send_key_changed(); +extern void send_key_changed(void); extern bool send_req_key(struct node_t *); extern bool send_ans_key(struct node_t *); -extern bool send_tcppacket(struct connection_t *, struct vpn_packet_t *); +extern bool send_tcppacket(struct connection_t *, const struct vpn_packet_t *); /* Request handlers */ diff --git a/src/protocol_misc.c b/src/protocol_misc.c index 4ca15853..225d7b4e 100644 --- a/src/protocol_misc.c +++ b/src/protocol_misc.c @@ -115,7 +115,7 @@ bool pong_h(connection_t *c, char *request) { /* Sending and receiving packets via TCP */ -bool send_tcppacket(connection_t *c, 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. We use a very simple Random Early Drop algorithm. */ diff --git a/src/raw_socket/device.c b/src/raw_socket/device.c index 66d63487..410e46e4 100644 --- a/src/raw_socket/device.c +++ b/src/raw_socket/device.c @@ -23,6 +23,7 @@ #include #include "conf.h" +#include "device.h" #include "net.h" #include "logger.h" #include "utils.h" diff --git a/src/solaris/device.c b/src/solaris/device.c index 37c95c7b..eac267ad 100644 --- a/src/solaris/device.c +++ b/src/solaris/device.c @@ -26,6 +26,7 @@ #include #include "conf.h" +#include "device.h" #include "logger.h" #include "net.h" #include "utils.h" diff --git a/src/tincd.c b/src/tincd.c index 704e96e3..23845fff 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -339,7 +339,7 @@ static bool drop_privs(void) { } #ifdef HAVE_MINGW -# define setpriority(level) SetPriorityClass(GetCurrentProcess(), (level)) +# define setpriority(level) !SetPriorityClass(GetCurrentProcess(), (level)) #else # define NORMAL_PRIORITY_CLASS 0 # define BELOW_NORMAL_PRIORITY_CLASS 10 diff --git a/src/uml_socket/device.c b/src/uml_socket/device.c index e9b07663..d8f13a55 100644 --- a/src/uml_socket/device.c +++ b/src/uml_socket/device.c @@ -23,6 +23,7 @@ #include #include "conf.h" +#include "device.h" #include "net.h" #include "logger.h" #include "utils.h" diff --git a/src/utils.c b/src/utils.c index 4aed59f5..6ea904a5 100644 --- a/src/utils.c +++ b/src/utils.c @@ -67,7 +67,7 @@ const char *winerror(int err) { } #endif -unsigned int bitfield_to_int(void *bitfield, size_t size) { +unsigned int bitfield_to_int(const void *bitfield, size_t size) { unsigned int value = 0; if(size > sizeof value) size = sizeof value; diff --git a/src/utils.h b/src/utils.h index fddb8a67..6f00e5a2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -42,6 +42,6 @@ extern const char *winerror(int); #define sockinuse(x) ((x) == EADDRINUSE) #endif -extern unsigned int bitfield_to_int(void *bitfield, size_t size); +extern unsigned int bitfield_to_int(const void *bitfield, size_t size); #endif /* __TINC_UTILS_H__ */ diff --git a/src/vde/device.c b/src/vde/device.c index 6148ccbe..63171f9a 100644 --- a/src/vde/device.c +++ b/src/vde/device.c @@ -22,6 +22,7 @@ #include #include "conf.h" +#include "device.h" #include "net.h" #include "logger.h" #include "utils.h"