From: Guus Sliepen Date: Sun, 11 Jan 2015 12:53:16 +0000 (+0100) Subject: Only send small packets during UDP probes. X-Git-Tag: release-1.1pre12~215 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=ce7079f4af3157eaef514d6d160933a016b2ab62;p=tinc Only send small packets during UDP probes. We are trying to decouple UDP probing from MTU probing, so only send very small packets during UDP probing. This significantly reduces the amount of traffic sent (54 to 67 bytes per probe instead of 1500 bytes). This means the MTU probing code takes over sending PMTU sized probes, but this commit does not take care of detecting PMTU decreases. --- diff --git a/src/net_packet.c b/src/net_packet.c index 99063ac2..76b3c5e9 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -52,6 +52,11 @@ #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif +/* The minimum size of a probe is 14 bytes, but since we normally use CBC mode + encryption, we can add a few extra random bytes without increasing the + resulting packet size. */ +#define MIN_PROBE_SIZE 18 + int keylifetime = 0; #ifdef HAVE_LZO static char lzo_wrkmem[LZO1X_999_MEM_COMPRESS > LZO1X_1_MEM_COMPRESS ? LZO1X_999_MEM_COMPRESS : LZO1X_1_MEM_COMPRESS]; @@ -116,7 +121,7 @@ static void udp_probe_h(node_t *n, vpn_packet_t *packet, length_t len) { gettimeofday(&now, NULL); uint32_t sec = htonl(now.tv_sec); memcpy(data, &sec, 4); data += 4; uint32_t usec = htonl(now.tv_usec); memcpy(data, &usec, 4); data += 4; - packet->len = 14; // Minimum size for any probe packet. + packet->len = MIN_PROBE_SIZE; } else { /* Legacy protocol: n won't understand type 2 probe replies. */ DATA(packet)[0] = 1; @@ -882,12 +887,12 @@ 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) { - send_udp_probe_packet(n, MAX(n->minmtu, 16)); + 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; - send_udp_probe_packet(n, 16); + send_udp_probe_packet(n, MIN_PROBE_SIZE); n->status.send_locally = false; } } @@ -1007,8 +1012,9 @@ static void try_mtu(node_t *n) { try_fix_mtu(n); if(n->mtuprobes < 0) { - /* After the initial discovery, we only send one >maxmtu probe - to detect PMTU increases. */ + /* After the initial discovery, we only send one maxmtu and one + maxmtu+1 probe to detect PMTU increases. */ + send_udp_probe_packet(n, n->maxmtu); if(n->maxmtu + 1 < MTU) send_udp_probe_packet(n, n->maxmtu + 1); } else {