Merge remote-tracking branch 'volth/release-1.1pre16-rtt' into 1.1
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 13 Jun 2018 20:23:27 +0000 (22:23 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 13 Jun 2018 20:26:49 +0000 (22:26 +0200)
Also, reformat the code and fix a compiler warning.

Makefile.am
NEWS
src/info.c
src/net_packet.c
src/tincctl.c
test/Makefile.am
test/ping.test [deleted file]
test/pong.c [deleted file]

index a09ee4d..e69542e 100644 (file)
@@ -37,4 +37,4 @@ release:
        $(MAKE) dist
 
 astyle:
-       astyle --options=.astylerc -nQ src/*.[ch] src/*/*.[ch] test/*.[ch]
+       astyle --options=.astylerc -nQ src/*.[ch] src/*/*.[ch]
diff --git a/NEWS b/NEWS
index 135883b..57b5614 100644 (file)
--- a/NEWS
+++ b/NEWS
 * Fixed linking with libncurses on some distributions.
 * Automatically disable PMTUDiscovery when TCPOnly is enabled.
 * Fixed removing the tinc service on Windows in some situations.
+* Fixed the TAP-Win32 device locking up after waking up from suspend.
+
+Thanks to Todd C. Miller, Etienne Dechamps, Daniel Lublin,
+Gjergji Ramku, Mike Sullivan and Oliver Freyermuth for their
+contributions to this version of tinc.
 
 # Version 1.1pre15             September 2 2017
 
index 4ca67ec..f0dce8c 100644 (file)
@@ -145,8 +145,10 @@ static int info_node(int fd, const char *item) {
 
        if(status.udp_confirmed) {
                printf(" udp_confirmed");
-               if(udp_ping_rtt != -1)
-                       printf(" (rtt %ld.%03ld)", udp_ping_rtt / 1000, udp_ping_rtt % 1000);
+
+               if(udp_ping_rtt != -1) {
+                       printf(" (rtt %d.%03d)", udp_ping_rtt / 1000, udp_ping_rtt % 1000);
+               }
        }
 
        printf("\n");
index ee2b316..ebf2938 100644 (file)
@@ -152,11 +152,11 @@ static void udp_probe_h(node_t *n, vpn_packet_t *packet, length_t len) {
                len = ntohs(len16);
        }
 
-       if (n->udp_ping_sent.tv_sec != 0) { // a probe in flight
+       if(n->udp_ping_sent.tv_sec != 0) {  // a probe in flight
                gettimeofday(&now, NULL);
                struct timeval rtt;
                timersub(&now, &n->udp_ping_sent, &rtt);
-               n->udp_ping_rtt = rtt.tv_sec*1000000 + rtt.tv_usec;
+               n->udp_ping_rtt = rtt.tv_sec * 1000000 + rtt.tv_usec;
                logger(DEBUG_TRAFFIC, LOG_INFO, "Got type %d UDP probe reply %d from %s (%s) rtt=%d.%03d", DATA(packet)[0], len, n->name, n->hostname, n->udp_ping_rtt / 1000, n->udp_ping_rtt % 1000);
        } else {
                logger(DEBUG_TRAFFIC, LOG_INFO, "Got type %d UDP probe reply %d from %s (%s)", DATA(packet)[0], len, n->name, n->hostname);
index d8df67c..12e5ead 100644 (file)
@@ -1335,8 +1335,11 @@ static int cmd_dump(int argc, char *argv[]) {
 
                                printf("%s id %s at %s port %s cipher %d digest %d maclength %d compression %d options %x status %04x nexthop %s via %s distance %d pmtu %d (min %d max %d) rx %"PRIu64" %"PRIu64" tx %"PRIu64" %"PRIu64,
                                       node, id, host, port, cipher, digest, maclength, compression, options, status_int, nexthop, via, distance, pmtu, minmtu, maxmtu, in_packets, in_bytes, out_packets, out_bytes);
-                               if (udp_ping_rtt != -1)
+
+                               if(udp_ping_rtt != -1) {
                                        printf(" rtt %d.%03d", udp_ping_rtt / 1000, udp_ping_rtt % 1000);
+                               }
+
                                printf("\n");
                        }
                }
index a56b5c4..29b2c21 100644 (file)
@@ -7,7 +7,6 @@ TESTS = \
        invite-offline.test \
        invite-tinc-up.test \
        ns-ping.test \
-       ping.test \
        scripts.test \
        sptps-basic.test \
        variables.test
@@ -16,14 +15,9 @@ dist_check_SCRIPTS = $(TESTS)
 
 EXTRA_DIST = testlib.sh
 
-check_PROGRAMS = pong
-
-pong_SOURCES = pong.c
-
 AM_CFLAGS = -iquote.
 
 clean-local:
        -for pid in *.test.?/pid; do ../src/tinc --pidfile="$$pid" stop; done
        -killall ../src/sptps_test
-       -killall pong
        -rm -rf *.test.?
diff --git a/test/ping.test b/test/ping.test
deleted file mode 100755 (executable)
index 961b16f..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/bin/sh
-
-. "${0%/*}/testlib.sh"
-
-# Skip this test if we aren't root
-
-test "`id -u`" = "0" || exit 77
-
-# Initialize two nodes
-
-$tinc $c1 <<EOF
-init foo
-set Mode switch
-set Interface ping.test
-set Port 32573
-set Address localhost
-EOF
-
-cat >$d1/tinc-up <<EOF
-#!/bin/sh
-ifconfig \$INTERFACE up
-EOF
-
-$tinc $c2 <<EOF
-init bar
-set Mode switch
-set DeviceType multicast
-set Device 233.252.0.1 32754
-add ConnectTo foo
-EOF
-
-# Exchange configuration files
-
-$tinc $c1 export | $tinc $c2 exchange | $tinc $c1 import
-
-# Ensure we have a working multicast route
-
-ip route replace 233.252.0.0/16 dev lo
-
-# Start pong program in background
-
-./pong 233.252.0.1 32754 10.6.5.5 &
-pong=$!
-
-# Start tinc and try to ping
-
-$tinc $c1 start $r1
-$tinc $c2 start $r2
-
-sleep 1
-
-ping -r -I ping.test -c3 10.6.5.5
-
-# Clean up
-
-kill $pong
-$tinc $c2 stop
-$tinc $c1 stop
diff --git a/test/pong.c b/test/pong.c
deleted file mode 100644 (file)
index 43fd718..0000000
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
-    pong.c -- ICMP echo reply generator
-    Copyright (C) 2013-2017 Guus Sliepen <guus@tinc-vpn.org>
-
-    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
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License along
-    with this program; if not, write to the Free Software Foundation, Inc.,
-    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-
-#include "../src/system.h"
-
-#include "../src/ethernet.h"
-
-uint8_t mymac[6] = {6, 5, 5, 6, 5, 5};
-
-static ssize_t do_arp(uint8_t *buf, ssize_t len, struct sockaddr_in *in) {
-       struct ether_arp arp;
-       memcpy(&arp, buf + 14, sizeof(arp));
-
-       // Is it a valid ARP request?
-       if(ntohs(arp.arp_hrd) != ARPHRD_ETHER || ntohs(arp.arp_pro) != ETH_P_IP || arp.arp_hln != ETH_ALEN || arp.arp_pln != sizeof(in->sin_addr.s_addr) || ntohs(arp.arp_op) != ARPOP_REQUEST) {
-               return 0;
-       }
-
-       // Does it match our address?
-       if(memcmp(&in->sin_addr.s_addr, arp.arp_tpa, 4)) {
-               return 0;
-       }
-
-       // Swap addresses
-       memcpy(buf, buf + 6, 6);
-       memcpy(buf + 6, mymac, 6);
-
-       arp.arp_op = htons(ARPOP_REPLY);
-       memcpy(arp.arp_tpa, arp.arp_spa, sizeof(arp.arp_tpa));
-       memcpy(arp.arp_tha, arp.arp_sha, sizeof(arp.arp_tha));
-       memcpy(arp.arp_spa, &in->sin_addr.s_addr, sizeof(in->sin_addr.s_addr));
-       memcpy(arp.arp_sha, mymac, 6);
-
-       memcpy(buf + 14, &arp, sizeof(arp));
-
-       return len;
-}
-
-static ssize_t do_ipv4(uint8_t *buf, ssize_t len, struct sockaddr_in *in) {
-       struct ip ip;
-       struct icmp icmp;
-
-       // Does it match our address?
-       if(memcmp(buf, mymac, 6)) {
-               return 0;
-       }
-
-       memcpy(&ip, buf + 14, sizeof(ip));
-
-       if(memcmp(&ip.ip_dst, &in->sin_addr.s_addr, 4)) {
-               return 0;
-       }
-
-       // Is it an ICMP echo request?
-       if(ip.ip_p != IPPROTO_ICMP) {
-               return 0;
-       }
-
-       memcpy(&icmp, buf + 14 + sizeof(ip), sizeof(icmp));
-
-       if(icmp.icmp_type != ICMP_ECHO) {
-               return 0;
-       }
-
-       // Return an echo reply
-       memcpy(buf, buf + 6, 6);
-       memcpy(buf + 6, mymac, 6);
-
-       ip.ip_dst = ip.ip_src;
-       memcpy(&ip.ip_src, &in->sin_addr.s_addr, 4);
-
-       icmp.icmp_type = ICMP_ECHOREPLY;
-
-       memcpy(buf + 14, &ip, sizeof(ip));
-       memcpy(buf + 14 + sizeof(ip), &icmp, sizeof(icmp));
-
-       return len;
-}
-
-static ssize_t do_ipv6(uint8_t *buf, ssize_t len, struct sockaddr_in6 *in) {
-       return 0;
-}
-
-int main(int argc, char *argv[]) {
-       if(argc != 4) {
-               fprintf(stderr, "Usage: %s <multicast address> <port> <ping address>\n", argv[0]);
-               return 1;
-       }
-
-       struct addrinfo hints = {}, *ai = NULL;
-       hints.ai_socktype = SOCK_DGRAM;
-       hints.ai_flags = AI_ADDRCONFIG;
-
-       errno = ENOENT;
-
-       if(getaddrinfo(argv[1], argv[2], &hints, &ai) || !ai) {
-               fprintf(stderr, "Could not resolve %s port %s: %s\n", argv[1], argv[2], strerror(errno));
-               return 1;
-       }
-
-       int fd;
-       fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
-
-       if(!fd) {
-               fprintf(stderr, "Could not create socket: %s\n", strerror(errno));
-               return 1;
-       }
-
-       static const int one = 1;
-       setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one));
-
-       if(bind(fd, ai->ai_addr, ai->ai_addrlen)) {
-               fprintf(stderr, "Could not bind socket: %s\n", strerror(errno));
-               return 1;
-       }
-
-       switch(ai->ai_family) {
-       case AF_INET: {
-               struct ip_mreq mreq;
-               struct sockaddr_in in;
-               memcpy(&in, ai->ai_addr, sizeof(in));
-               mreq.imr_multiaddr.s_addr = in.sin_addr.s_addr;
-               mreq.imr_interface.s_addr = htonl(INADDR_ANY);
-
-               if(setsockopt(fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq))) {
-                       fprintf(stderr, "Cannot join multicast group: %s\n", strerror(errno));
-                       return 1;
-               }
-
-#ifdef IP_MULTICAST_LOOP
-               setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof(one));
-#endif
-       }
-       break;
-
-#ifdef IPV6_JOIN_GROUP
-
-       case AF_INET6: {
-               struct ipv6_mreq mreq;
-               struct sockaddr_in6 in6;
-               memcpy(&in6, ai->ai_addr, sizeof(in6));
-               memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof(mreq.ipv6mr_multiaddr));
-               mreq.ipv6mr_interface = in6.sin6_scope_id;
-
-               if(setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof(mreq))) {
-                       fprintf(stderr, "Cannot join multicast group: %s\n", strerror(errno));
-                       return 1;
-               }
-
-#ifdef IPV6_MULTICAST_LOOP
-               setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof(one));
-#endif
-       }
-       break;
-#endif
-
-       default:
-               fprintf(stderr, "Multicast for address family %x unsupported\n", ai->ai_family);
-               return 1;
-       }
-
-       errno = ENOENT;
-       struct addrinfo *ai2 = NULL;
-
-       if(getaddrinfo(argv[3], NULL, &hints, &ai2) || !ai2) {
-               fprintf(stderr, "Could not resolve %s: %s\n", argv[3], strerror(errno));
-               return 1;
-       }
-
-       while(true) {
-               uint8_t buf[10000];
-               struct sockaddr src;
-               socklen_t srclen;
-               ssize_t len = recvfrom(fd, buf, sizeof(buf), 0, &src, &srclen);
-
-               if(len <= 0) {
-                       break;
-               }
-
-               // Ignore short packets.
-               if(len < 14) {
-                       continue;
-               }
-
-               uint16_t type = buf[12] << 8 | buf[13];
-
-               if(ai2->ai_family == AF_INET && type == ETH_P_IP) {
-                       len = do_ipv4(buf, len, (struct sockaddr_in *)ai2->ai_addr);
-               } else if(ai2->ai_family == AF_INET && type == ETH_P_ARP) {
-                       len = do_arp(buf, len, (struct sockaddr_in *)ai2->ai_addr);
-               } else if(ai2->ai_family == AF_INET6 && type == ETH_P_IPV6) {
-                       len = do_ipv6(buf, len, (struct sockaddr_in6 *)ai2->ai_addr);
-               } else {
-                       continue;
-               }
-
-               if(len > 0) {
-                       sendto(fd, buf, len, 0, ai->ai_addr, ai->ai_addrlen);
-               }
-       }
-
-       return 0;
-}