Avoid treating compressed MTU probes as having a negative length.
[tinc] / src / net_packet.c
index 6ce6431..9baaf4c 100644 (file)
@@ -152,12 +152,12 @@ 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*1000000L + rtt.tv_usec;
-               logger(DEBUG_TRAFFIC, LOG_INFO, "Got type %d UDP probe reply %d from %s (%s) rtt=%ld.%03ld", DATA(packet)[0], len, n->name, n->hostname, n->udp_ping_rtt/1000, n->udp_ping_rtt%1000);
+               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);
        }
@@ -462,7 +462,10 @@ static bool receive_udppacket(node_t *n, vpn_packet_t *inpkt) {
 
                inpkt = outpkt;
 
-               origlen -= MTU / 64 + 20;
+               if (origlen > MTU / 64 + 20)
+                       origlen -= MTU / 64 + 20;
+               else
+                       origlen = 0;
        }
 
        if(inpkt->len > n->maxrecentlen) {