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.

1  2 
src/info.c
src/net_packet.c
src/tincctl.c

diff --combined src/info.c
@@@ -70,15 -70,17 +70,17 @@@ static int info_node(int fd, const cha
        } status_union;
        node_status_t status;
        long int last_state_change;
+       int udp_ping_rtt;
+       uint64_t in_packets, in_bytes, out_packets, out_bytes;
  
        while(recvline(fd, line, sizeof(line))) {
-               int n = sscanf(line, "%d %d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld", &code, &req, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_union.raw, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
+               int n = sscanf(line, "%d %d %4095s %4095s %4095s port %4095s %d %d %d %d %x %"PRIx32" %4095s %4095s %d %hd %hd %hd %ld %d %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &code, &req, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_union.raw, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change, &udp_ping_rtt, &in_packets, &in_bytes, &out_packets, &out_bytes);
  
                if(n == 2) {
                        break;
                }
  
-               if(n != 19) {
+               if(n != 24) {
                        fprintf(stderr, "Unable to parse node dump from tincd.\n");
                        return 1;
                }
  
        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");
                printf("none, forwarded via %s\n", nexthop);
        }
  
+       printf("RX:           %"PRIu64" packets  %"PRIu64" bytes\n", in_packets, in_bytes);
+       printf("TX:           %"PRIu64" packets  %"PRIu64" bytes\n", out_packets, out_bytes);
        // List edges
        printf("Edges:       ");
        sendline(fd, "%d %d %s", CONTROL, REQ_DUMP_EDGES, item);
diff --combined src/net_packet.c
@@@ -102,6 -102,7 +102,7 @@@ static void udp_probe_timeout_handler(v
  
        logger(DEBUG_TRAFFIC, LOG_INFO, "Too much time has elapsed since last UDP ping response from %s (%s), stopping UDP communication", n->name, n->hostname);
        n->status.udp_confirmed = false;
+       n->udp_ping_rtt = -1;
        n->maxrecentlen = 0;
        n->mtuprobes = 0;
        n->minmtu = 0;
@@@ -151,7 -152,15 +152,15 @@@ static void udp_probe_h(node_t *n, vpn_
                len = ntohs(len16);
        }
  
-       logger(DEBUG_TRAFFIC, LOG_INFO, "Got type %d UDP probe reply %d from %s (%s)", DATA(packet)[0], len, n->name, n->hostname);
 -      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);
+       }
  
        /* It's a valid reply: now we know bidirectional communication
           is possible using the address and socket that the reply
                reset_address_cache(n->address_cache, &n->address);
        }
  
-       // Reset the UDP ping timer.
-       n->udp_ping_sent = now;
+       // Reset the UDP ping timer. (no probe in flight)
+       n->udp_ping_sent.tv_sec = 0;
  
        if(udp_discovery) {
                timeout_del(&n->udp_ping_timeout);
@@@ -1119,8 -1128,9 +1128,9 @@@ static void try_udp(node_t *n) 
        int interval = n->status.udp_confirmed ? udp_discovery_keepalive_interval : udp_discovery_interval;
  
        if(ping_tx_elapsed.tv_sec >= interval) {
+               gettimeofday(&now, NULL);
+               n->udp_ping_sent = now; // a probe in flight
                send_udp_probe_packet(n, MIN_PROBE_SIZE);
-               n->udp_ping_sent = now;
  
                if(localdiscovery && !n->status.udp_confirmed && n->prevedge) {
                        n->status.send_locally = true;
diff --combined src/tincctl.c
@@@ -1298,12 -1298,14 +1298,14 @@@ static int cmd_dump(int argc, char *arg
                unsigned int options, status_int;
                node_status_t status;
                long int last_state_change;
+               int udp_ping_rtt;
+               uint64_t in_packets, in_bytes, out_packets, out_bytes;
  
                switch(req) {
                case REQ_DUMP_NODES: {
-                       int n = sscanf(line, "%*d %*d %4095s %4095s %4095s port %4095s %d %d %d %d %x %x %4095s %4095s %d %hd %hd %hd %ld", node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_int, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change);
+                       int n = sscanf(line, "%*d %*d %4095s %4095s %4095s port %4095s %d %d %d %d %x %x %4095s %4095s %d %hd %hd %hd %ld %d %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, node, id, host, port, &cipher, &digest, &maclength, &compression, &options, &status_int, nexthop, via, &distance, &pmtu, &minmtu, &maxmtu, &last_state_change, &udp_ping_rtt, &in_packets, &in_bytes, &out_packets, &out_bytes);
  
-                       if(n != 17) {
+                       if(n != 22) {
                                fprintf(stderr, "Unable to parse node dump from tincd: %s\n", line);
                                return 1;
                        }
                                        continue;
                                }
  
-                               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)\n",
-                                      node, id, host, port, cipher, digest, maclength, compression, options, status_int, nexthop, via, distance, pmtu, minmtu, maxmtu);
+                               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");
                        }
                }
                break;