Merge branch 'tincstart' of https://github.com/dechamps/tinc into 1.1
authorGuus Sliepen <guus@tinc-vpn.org>
Sat, 12 Jul 2014 20:22:31 +0000 (22:22 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sat, 12 Jul 2014 20:22:31 +0000 (22:22 +0200)
doc/tinc.conf.5.in
src/device.h
src/mingw/device.c
src/net_packet.c
src/process.c
src/process.h
src/script.c
src/sptps.c
src/tincd.c
src/top.c

index 771a25f..9d9bf76 100644 (file)
@@ -121,6 +121,8 @@ will automatically set up meta connections to other nodes,
 without requiring
 .Va ConnectTo
 variables.
+.Pp
+Note: it is not possible to connect to nodes using zero (system-assigned) ports in this way.
 .It Va BindToAddress Li = Ar address Op Ar port
 This is the same as
 .Va ListenAddress ,
@@ -340,6 +342,14 @@ To only listen on a specific port but not on a specific address, use
 .Li *
 for the
 .Ar address .
+.Pp
+If
+.Ar port
+is set to zero, it will be randomly assigned by the system. This is useful to randomize source ports of UDP packets, which can improve UDP hole punching reliability. In this case it is recommended to set
+.Va AddressFamily
+as well, otherwise
+.Nm tinc
+will assign different ports to different address families but other nodes can only know of one.
 .It Va LocalDiscovery Li = yes | no Pq yes
 When enabled,
 .Nm tinc
@@ -549,6 +559,14 @@ The port number on which this tinc daemon is listening for incoming connections,
 which is used if no port number is specified in an
 .Va Address
 statement.
+.Pp
+If this is set to zero, the port will be randomly assigned by the system. This is useful to randomize source ports of UDP packets, which can improve UDP hole punching reliability. When setting
+.Va Port
+to zero it is recommended to set
+.Va AddressFamily
+as well, otherwise
+.Nm tinc
+will assign different ports to different address families but other nodes can only know of one.
 .It Va PublicKey Li = Ar key Bq obsolete
 The public RSA key of this tinc daemon.
 It will be used to cryptographically verify it's identity and to set up a secure connection.
index ad91a0e..8046a25 100644 (file)
@@ -27,11 +27,6 @@ extern int device_fd;
 extern char *device;
 extern char *iface;
 
-extern uint64_t device_in_packets;
-extern uint64_t device_in_bytes;
-extern uint64_t device_out_packets;
-extern uint64_t device_out_bytes;
-
 typedef struct devops_t {
        bool (*setup)(void);
        void (*close)(void);
index 33b13da..b6dffbc 100644 (file)
@@ -43,9 +43,6 @@ char *device = NULL;
 char *iface = NULL;
 static char *device_info = NULL;
 
-static uint64_t device_total_in = 0;
-static uint64_t device_total_out = 0;
-
 extern char *myport;
 
 static void device_issue_read() {
@@ -60,7 +57,7 @@ static void device_issue_read() {
        }
 }
 
-static void device_handle_read(void *data) {
+static void device_handle_read(void *data, int flags) {
        ResetEvent(device_read_overlapped.hEvent);
 
        DWORD len;
@@ -89,7 +86,6 @@ static bool setup_device(void) {
        bool found = false;
 
        int err;
-       HANDLE thread;
 
        get_config_string(lookup_config(config_tree, "Device"), &device);
        get_config_string(lookup_config(config_tree, "Interface"), &iface);
@@ -235,8 +231,6 @@ static bool write_packet(vpn_packet_t *packet) {
                return false;
        }
 
-       device_total_out += packet->len;
-
        return true;
 }
 
index 31c19b7..4ec70fa 100644 (file)
@@ -628,8 +628,8 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) {
        size_t outlen;
 #if defined(SOL_IP) && defined(IP_TOS)
        static int priority = 0;
-#endif
        int origpriority = origpkt->priority;
+#endif
 
        if(!n->status.reachable) {
                logger(DEBUG_TRAFFIC, LOG_INFO, "Trying to send UDP packet to unreachable node %s (%s)", n->name, n->hostname);
index 9f99a94..6135efb 100644 (file)
@@ -109,7 +109,7 @@ static bool install_service(void) {
        return true;
 }
 
-static io_t stop_io;
+io_t stop_io;
 
 DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) {
        switch(request) {
@@ -135,17 +135,9 @@ DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) {
        return NO_ERROR;
 }
 
-static void stop_handler(void *data, int flags) {
-       event_exit();
-}
-
 VOID WINAPI run_service(DWORD argc, LPTSTR* argv) {
        extern int main2(int argc, char **argv);
 
-       io_add_event(&stop_io, stop_handler, NULL, WSACreateEvent());
-       if (stop_io.event == FALSE)
-               abort();
-
        status.dwServiceType = SERVICE_WIN32;
        status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
        status.dwWin32ExitCode = 0;
@@ -172,9 +164,6 @@ VOID WINAPI run_service(DWORD argc, LPTSTR* argv) {
                SetServiceStatus(statushandle, &status);
        }
 
-       if (WSACloseEvent(stop_io.event) == FALSE)
-               abort();
-       io_del(&stop_io);
        return;
 }
 
index 4cdf711..ce2daed 100644 (file)
@@ -29,6 +29,7 @@ extern bool detach(void);
 extern bool kill_other(int);
 
 #ifdef HAVE_MINGW
+extern io_t stop_io;
 extern bool init_service(void);
 #endif
 
index 9a43d53..6389cb4 100644 (file)
@@ -49,7 +49,7 @@ bool execute_script(const char *name, char **envp) {
                        if(q) {
                                memcpy(ext, p, q - p);
                                ext[q - p] = 0;
-                               *q++;
+                               q++;
                        } else {
                                strcpy(ext, p);
                        }
index 3fbd854..e9ce94a 100644 (file)
@@ -431,13 +431,12 @@ bool sptps_verify_datagram(sptps_t *s, const char *data, size_t len) {
        uint32_t seqno;
        memcpy(&seqno, data, 4);
        seqno = ntohl(seqno);
+       if (!sptps_check_seqno(s, seqno, false))
+               return false;
 
        char buffer[len];
        size_t outlen;
-       if(!chacha_poly1305_decrypt(s->incipher, seqno, data + 4, len - 4, buffer, &outlen))
-               return false;
-
-       return sptps_check_seqno(s, seqno, false);
+       return chacha_poly1305_decrypt(s->incipher, seqno, data + 4, len - 4, buffer, &outlen);
 }
 
 // Receive incoming data, datagram version.
index 9f83a3c..748fe13 100644 (file)
@@ -49,6 +49,7 @@
 #include "control.h"
 #include "crypto.h"
 #include "device.h"
+#include "event.h"
 #include "logger.h"
 #include "names.h"
 #include "net.h"
@@ -303,6 +304,17 @@ static bool drop_privs(void) {
 
 #ifdef HAVE_MINGW
 # define setpriority(level) !SetPriorityClass(GetCurrentProcess(), (level))
+
+static void stop_handler(void *data, int flags) {
+       event_exit();
+}
+
+static BOOL WINAPI console_ctrl_handler(DWORD type) {
+       logger(DEBUG_ALWAYS, LOG_NOTICE, "Got console shutdown request");
+       if (WSASetEvent(stop_io.event) == FALSE)
+               abort();
+       return TRUE;
+}
 #else
 # define NORMAL_PRIORITY_CLASS 0
 # define BELOW_NORMAL_PRIORITY_CLASS 10
@@ -371,10 +383,21 @@ int main(int argc, char **argv) {
 #endif
 
 #ifdef HAVE_MINGW
-       if(!do_detach || !init_service())
-               return main2(argc, argv);
-       else
-               return 1;
+       io_add_event(&stop_io, stop_handler, NULL, WSACreateEvent());
+       if (stop_io.event == FALSE)
+               abort();
+
+       int result;
+       if(!do_detach || !init_service()) {
+               SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
+               result = main2(argc, argv);
+       } else
+               result = 1;
+
+       if (WSACloseEvent(stop_io.event) == FALSE)
+               abort();
+       io_del(&stop_io);
+       return result;
 }
 
 int main2(int argc, char **argv) {
index 2824261..40b8047 100644 (file)
--- a/src/top.c
+++ b/src/top.c
@@ -21,6 +21,7 @@
 
 #ifdef HAVE_CURSES
 
+#undef KEY_EVENT  /* There are conflicting declarations for KEY_EVENT in Windows wincon.h and curses.h. */
 #include <curses.h>
 
 #include "control_common.h"