Merge branch 'master' of git://tinc-vpn.org/tinc into 1.1
authorGuus Sliepen <guus@tinc-vpn.org>
Mon, 6 Jun 2011 18:42:15 +0000 (20:42 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Mon, 6 Jun 2011 18:42:15 +0000 (20:42 +0200)
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

34 files changed:
AUTHORS
NEWS
THANKS
configure.in
doc/tinc.texi
doc/tincd.8.in
m4/openssl.m4
src/bsd/device.c
src/conf.c
src/connection.c
src/connection.h
src/cygwin/device.c
src/dummy/device.c
src/graph.c
src/graph.h
src/linux/device.c
src/logger.c
src/logger.h
src/mingw/device.c
src/net.c
src/net.h
src/net_packet.c
src/node.h
src/process.c
src/protocol.c
src/protocol.h
src/protocol_misc.c
src/raw_socket/device.c
src/solaris/device.c
src/tincd.c
src/uml_socket/device.c
src/utils.c
src/utils.h
src/vde/device.c

diff --git a/AUTHORS b/AUTHORS
index e418996..af11393 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -11,6 +11,7 @@ Significant contributions from:
 - Julien Muchembled <jm@jmuchemb.eu>
 - Timothy Redaelli <timothy@redaelli.eu>
 - Brandon Black <blblack@gmail.com>
+- Loïc Grenié <loic.grenie@gmail.com>
 
 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 c48a0e8..1a12155 100644 (file)
--- 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 dc1297b..4a6eae2 100644 (file)
--- 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
index 22e5fb1..0e12a36 100644 (file)
@@ -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"]
 )
 
index 7fc8909..7878db5 100644 (file)
@@ -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
 
index a210979..0e790e0 100644 (file)
@@ -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.
index 59f0d45..254ea4f 100644 (file)
@@ -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],
   )
index d647734..9c3009d 100644 (file)
@@ -22,6 +22,7 @@
 #include "system.h"
 
 #include "conf.h"
+#include "device.h"
 #include "logger.h"
 #include "net.h"
 #include "route.h"
index 593cd0c..099b77d 100644 (file)
@@ -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"
index 5beea4d..62bfccb 100644 (file)
@@ -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"
index a7db40a..75015ff 100644 (file)
@@ -48,7 +48,6 @@ typedef struct connection_status_t {
 } connection_status_t;
 
 #include "edge.h"
-#include "list.h"
 #include "net.h"
 #include "node.h"
 
index 5c227fd..a4ab938 100644 (file)
@@ -24,6 +24,7 @@
 #include <w32api/winioctl.h>
 
 #include "conf.h"
+#include "device.h"
 #include "logger.h"
 #include "net.h"
 #include "route.h"
index c84e899..25a38f2 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "system.h"
 
+#include "device.h"
 #include "logger.h"
 #include "net.h"
 
index 28be9d5..bb55dfd 100644 (file)
@@ -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);
index c8d5fda..fb41096 100644 (file)
@@ -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__ */
index f95410c..d36f3f6 100644 (file)
@@ -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"
index 4c0d231..08f9795 100644 (file)
@@ -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);
index 9c20ead..ff2cb34 100644 (file)
@@ -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);
 
index aeffdc3..bdca842 100644 (file)
@@ -24,6 +24,7 @@
 #include <winioctl.h>
 
 #include "conf.h"
+#include "device.h"
 #include "logger.h"
 #include "net.h"
 #include "route.h"
index 67603f7..b299bf1 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -3,6 +3,7 @@
     Copyright (C) 1998-2005 Ivo Timmermans,
                   2000-2011 Guus Sliepen <guus@tinc-vpn.org>
                   2006      Scott Lamb <slamb@slamb.org>
+                 2011      Loïc Grenié <loic.grenie@gmail.com>
 
     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 {
index 3a37fe1..b24d2d4 100644 (file)
--- 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)
index 1af5026..3627f31 100644 (file)
@@ -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;
                }
index 4173737..2f08186 100644 (file)
@@ -25,7 +25,6 @@
 #include "cipher.h"
 #include "connection.h"
 #include "digest.h"
-#include "list.h"
 #include "subnet.h"
 
 typedef struct node_status_t {
index 8c6679b..ee5fce9 100644 (file)
@@ -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"
index fd90894..650c512 100644 (file)
@@ -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++;
index 29c4ab1..f1c2a20 100644 (file)
@@ -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  */
 
index 4ca1585..225d7b4 100644 (file)
@@ -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. */
 
index 66d6348..410e46e 100644 (file)
@@ -23,6 +23,7 @@
 #include <netpacket/packet.h>
 
 #include "conf.h"
+#include "device.h"
 #include "net.h"
 #include "logger.h"
 #include "utils.h"
index 37c95c7..eac267a 100644 (file)
@@ -26,6 +26,7 @@
 #include <net/if_tun.h>
 
 #include "conf.h"
+#include "device.h"
 #include "logger.h"
 #include "net.h"
 #include "utils.h"
index 704e96e..23845ff 100644 (file)
@@ -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
index e9b0766..d8f13a5 100644 (file)
@@ -23,6 +23,7 @@
 #include <sys/un.h>
 
 #include "conf.h"
+#include "device.h"
 #include "net.h"
 #include "logger.h"
 #include "utils.h"
index 4aed59f..6ea904a 100644 (file)
@@ -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;
index fddb8a6..6f00e5a 100644 (file)
@@ -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__ */
index 6148ccb..63171f9 100644 (file)
@@ -22,6 +22,7 @@
 #include <libvdeplug_dyn.h>
 
 #include "conf.h"
+#include "device.h"
 #include "net.h"
 #include "logger.h"
 #include "utils.h"