tinc/src
Etienne Dechamps eeebff55c0 Use a splay tree for node UDP addresses in order to avoid collisions.
This commit replaces the node UDP address hash table "cache" with a
full-blown splay tree, aligning it with node_tree (name-indexed) and
node_id_tree (ID-indexed).

I'm doing this for two reasons. The first reason is to make sure we
don't suddenly degrade to O(n) performance when two "hot" nodes end up
in the same hash table bucket (collision).

The second, and most important, reason, has to do with the fact that
the hash table that was being used overrides elements that collide.
Indeed, it turns out that there is one scenario in which the contents of
node_udp_cache has *correctness* implications, not just performance
implications. This has to do with the way handle_incoming_vpn_data() is
implemented.

Assume the following topology:

  A <-> B <-> C

Now let's consider the perspective of tincd running on B, and let's
assume the following is true:

 - All nodes are using the 1.1 protocol with node IDs and relaying
   support.
 - Nodes A and C have UDP addresses that hash to the same value.
 - Node C "wins" in the node_udp_cache (i.e. it overwrites A in the
   cache).
 - Node A has a "dynamic" UDP address (i.e. an UDP address that has been
   detected dynamically and cannot be deduced from edge addresses).

Then, before this commit, A would be unable to relay packets through B.

This is because handle_incoming_vpn_data() will fall back to
try_harder(), which won't be able to match any edge addresses, doesn't
check the dynamic UDP addresses, and won't be able to match any keys
because this is a relayed packet which is encrypted with C's key, not
B's. As a result, tinc will fail to match the source of the packet and
will drop the packet with a "Received UDP packet from unknown source"
message.

I have seen this happen in the wild; it is actually quite likely to
occur when there are more than a handful of nodes because node_udp_cache
only has 256 buckets, making collisions quite likely. This problem is
quite severe because it can completely prevent all packet communication
between nodes - indeed, if node A tries to initiate some communication
with C, it will use relaying at first, until C responds and helps A
establish direct communication with it (e.g. hole punching). If relaying
is broken, C will not help establish direct communication, and as a
result no packets can make it through at all.

The bug can be reproduced fairly easily by reproducing the topology
above while changing the (hardcoded) node_udp_cache size to 1 to force a
collision. One will quickly observe various issues when trying to make A
talk to C. Setting IndirectData on B will make the issue even more
severe and prevent all communication.

Arguably, another way to fix this problem is to make try_harder()
compare the packet's source address to each node's dynamic UDP
addresses. However, I do not like this solution because if two "hot"
nodes are contending on the same hash bucket, try_harder() will be
called very often and packet routing performance will degrade closer to
O(N) (where N is the total number of nodes in the graph). Using a more
appropriate data structure fixes the bug without introducing this
performance problem.
2015-11-04 19:36:02 +00:00
..
bsd Add a variable offset to vpn_packet_t, drop sptps_packet_t. 2014-12-25 00:36:27 +01:00
chacha-poly1305 Use the ChaCha-Poly1305 cipher for the SPTPS protocol. 2014-04-14 21:43:45 +02:00
cygwin Add a variable offset to vpn_packet_t, drop sptps_packet_t. 2014-12-25 00:36:27 +01:00
ed25519 Avoid undefined behavior. 2015-10-26 13:46:30 +01:00
gcrypt Use conditional compilation for cryptographic functions. 2013-05-01 17:17:22 +02:00
linux Quit with an error message if ioctl(TUNSETIFF) fails. 2015-05-19 22:26:32 +02:00
mingw Merge remote-tracking branch 'dechamps/wintapver' into 1.1 2015-04-12 15:43:05 +02:00
nolegacy Fix the PRF function when compiling without OpenSSL. 2015-07-12 16:31:32 +02:00
openssl Correctly estimate the initial MTU for legacy packets. 2015-01-10 23:00:51 +01:00
solaris Add a variable offset to vpn_packet_t, drop sptps_packet_t. 2014-12-25 00:36:27 +01:00
buffer.c Fix whitespace. 2012-10-10 17:17:49 +02:00
buffer.h Always compact the buffer if it has reached MAXBUFSIZE. 2011-05-22 13:24:01 +02:00
cipher.h Correctly estimate the initial MTU for legacy packets. 2015-01-10 23:00:51 +01:00
conf.c (read|append)_config_file: log open errors as LOG_DEBUG 2015-07-02 21:22:47 +02:00
conf.h Releasing 1.1pre5. 2013-01-20 21:03:22 +01:00
connection.c Allow tinc to be compiled without OpenSSL. 2014-12-29 22:57:18 +01:00
connection.h Fix crash is sptps_logger(). 2015-06-10 23:42:17 +02:00
control.c Remove redundant connection_t::status.active field. 2014-07-12 14:21:48 +02:00
control.h Use the TCP socket infrastructure for control sockets. 2009-11-07 23:43:25 +01:00
control_common.h Update copyright notices. 2012-10-14 17:42:49 +02:00
crypto.h Add generic crypto headers. 2013-05-01 17:58:30 +02:00
device.h Remove unused device stats variables. 2014-07-12 13:34:19 +01:00
digest.h Allow tinc to be compiled without OpenSSL. 2014-12-29 22:57:18 +01:00
dropin.c Update copyright notices. 2013-08-13 20:38:57 +02:00
dropin.h Update copyright notices. 2013-08-13 20:38:57 +02:00
dummy_device.c Don't print device statistics when exiting tinc. 2013-12-08 20:23:44 +01:00
ecdh.h Use Ed25519 keys. 2014-04-06 22:47:26 +02:00
ecdsa.h Add __attribute__((warn_unused_result)) to crypto functions. 2013-05-10 20:23:01 +02:00
ecdsagen.h Add __attribute__((warn_unused_result)) to crypto functions. 2013-05-10 20:23:01 +02:00
edge.c Call sockaddrfree(&e->local_address) in free_edge() instead of exit_edges(). 2015-07-04 17:53:11 +02:00
edge.h Add local address information to edges. 2014-06-29 11:23:14 +01:00
ethernet.h Make sure packet header structures are correctly packed on Windows. 2015-03-15 10:12:18 +00:00
event.c Protect against callbacks removing items from the io tree. 2015-06-20 14:09:00 +01:00
event.h Remove the TAP-Win32 reader thread. 2014-06-28 20:00:05 +01:00
fake-gai-errnos.h Add missing definitions on Windows. 2013-07-17 18:00:40 +02:00
fake-getaddrinfo.c Rename xmalloc_and_zero() to xzalloc(). 2013-05-01 17:31:33 +02:00
fake-getaddrinfo.h Fix whitespace. 2012-10-10 17:17:49 +02:00
fake-getnameinfo.c Fix whitespace. 2012-10-10 17:17:49 +02:00
fake-getnameinfo.h Fix whitespace. 2012-10-10 17:17:49 +02:00
fsck.c Fix invalid getuid() call on Windows. 2015-03-14 16:07:54 +00:00
fsck.h Add the "fsck" command to the CLI. 2015-01-15 23:06:38 +01:00
getopt.c Use conditional compilation for device.c. 2013-05-01 12:20:06 +02:00
getopt.h Move source from lib/ to src/. 2009-12-31 13:19:13 +01:00
getopt1.c Use conditional compilation for device.c. 2013-05-01 12:20:06 +02:00
graph.c In sssp_bfs(), never try to update myself. 2015-07-22 14:33:56 +02:00
graph.h Update copyright notices. 2012-03-10 13:23:08 +01:00
hash.c Fix undefined behaviour when left-shifting signed integers. 2015-07-12 12:33:07 +02:00
hash.h Add an explicit hash_delete() function. 2014-12-07 22:10:16 +01:00
have.h fix musl compatibility 2015-07-04 17:34:37 +02:00
info.c Introduce node IDs. 2014-10-04 11:13:59 +01:00
info.h Add readline completion for tincctl config and tincctl info. 2012-08-03 13:23:07 +02:00
invitation.c Fix warnings about missing return value checks. 2015-06-07 22:50:05 +02:00
invitation.h Add an invitation protocol. 2013-05-29 18:31:10 +02:00
ipv4.h Make sure packet header structures are correctly packed on Windows. 2015-03-15 10:12:18 +00:00
ipv6.h Make sure packet header structures are correctly packed on Windows. 2015-03-15 10:12:18 +00:00
list.c Update copyright notices. 2013-08-13 20:38:57 +02:00
list.h Protect against callbacks removing items from the io tree. 2015-06-20 14:09:00 +01:00
logger.c Removed double break; 2015-07-12 12:39:36 +02:00
logger.h Ensure "tinc start" knows if the daemon really started succesfully. 2015-05-20 16:59:43 +02:00
Makefile.am Fix src/Makefile.am for *BSD. 2015-05-19 14:09:53 +02:00
meta.c Make sure the MIN() macro is defined. 2015-05-17 22:21:11 +01:00
meta.h Introduce raw TCP SPTPS packet transport. 2015-05-10 21:08:57 +01:00
multicast_device.c Add a variable offset to vpn_packet_t, drop sptps_packet_t. 2014-12-25 00:36:27 +01:00
names.c Included missing names.h 2015-07-12 13:06:38 +02:00
names.h Fix check for LOCALSTATEDIR accessibility for the CLI. 2015-05-20 11:11:12 +02:00
net.c Allocate temporary filenames on the stack. 2015-05-20 00:58:00 +02:00
net.h Introduce raw TCP SPTPS packet transport. 2015-05-10 21:08:57 +01:00
net_packet.c Fix missing return value caused by the previous commit. 2015-05-31 23:51:39 +02:00
net_setup.c Coalesce two if statements that check for the same thing. 2015-07-04 17:51:05 +02:00
net_socket.c setup_outgoing_connection: log to LOG_DEBUG on if no known address 2015-07-02 21:22:53 +02:00
netutl.c Let sockaddr2hostname() handle AF_UNSPEC addresses. 2015-05-17 18:43:34 +02:00
netutl.h Update copyright notices. 2013-08-13 20:38:57 +02:00
node.c Use a splay tree for node UDP addresses in order to avoid collisions. 2015-11-04 19:36:02 +00:00
node.h Fix struct node_status_t. 2015-09-25 10:05:24 +02:00
prf.h Add __attribute__((warn_unused_result)) to crypto functions. 2013-05-10 20:23:01 +02:00
process.c Use git description as the tinc version. 2015-05-04 21:38:23 +01:00
process.h Shutdown cleanly when receiving a Windows console shutdown request. 2014-07-12 17:47:01 +01:00
protocol.c Introduce raw TCP SPTPS packet transport. 2015-05-10 21:08:57 +01:00
protocol.h Introduce raw TCP SPTPS packet transport. 2015-05-10 21:08:57 +01:00
protocol_auth.c Allow one-sided upgrades to Ed25519. 2015-04-24 23:40:20 +02:00
protocol_edge.c Prevent tinc from forgeting e->local_address 2015-07-12 13:32:38 +02:00
protocol_key.c Merge remote-tracking branches 'dechamps/sptpsrestart' and 'dechamps/keychanged' into 1.1 2015-05-17 21:07:45 +02:00
protocol_misc.c Fix wrong format string type in send_sptps_tcppacket(). 2015-05-24 09:45:09 +01:00
protocol_subnet.c Update copyright notices. 2012-10-14 17:42:49 +02:00
raw_socket_device.c Add a variable offset to vpn_packet_t, drop sptps_packet_t. 2014-12-25 00:36:27 +01:00
route.c Fix invalid checksum generation. 2015-09-12 16:41:48 +02:00
route.h Fix whitespace. 2012-10-10 17:17:49 +02:00
rsa.h Add __attribute__((warn_unused_result)) to crypto functions. 2013-05-10 20:23:01 +02:00
rsagen.h Add __attribute__((warn_unused_result)) to crypto functions. 2013-05-10 20:23:01 +02:00
script.c Allocate temporary filenames on the stack. 2015-05-20 00:58:00 +02:00
script.h Use PATHEXT when checking for the presence of scripts on Windows. 2013-08-23 21:23:46 +02:00
splay_tree.c Update copyright notices. 2013-08-13 20:38:57 +02:00
splay_tree.h Protect against callbacks removing items from the io tree. 2015-06-20 14:09:00 +01:00
sptps.c Don't log seqno failures in sptps_verify_datagram(). 2015-05-19 21:32:30 +02:00
sptps.h Only read one record at a time in sptps_receive_data(). 2015-05-10 21:08:57 +01:00
sptps_keypair.c Fix warnings about missing return value checks. 2015-06-07 22:50:05 +02:00
sptps_speed.c Fix alignment of output of sptps_speed. 2015-06-07 23:20:14 +02:00
sptps_test.c Fix receiving SPTPS data in sptps_speed and sptps_test. 2015-06-07 23:17:54 +02:00
subnet.c Make subnet caches static. 2015-07-12 13:08:34 +02:00
subnet.h Update copyright notices. 2012-10-14 17:42:49 +02:00
subnet_parse.c Remove unused code that caused warnings about an uninitialized variable. 2015-07-12 12:55:13 +02:00
system.h Update copyright notices. 2013-08-13 20:38:57 +02:00
tincctl.c Fix a few memory leaks in the CLI found by AddressSanitizer. 2015-09-25 10:06:18 +02:00
tincctl.h Add the "fsck" command to the CLI. 2015-01-15 23:06:38 +01:00
tincd.c Update copyright notices. 2015-05-21 11:09:01 +02:00
top.c Resolve KEY_EVENT conflict between Windows and ncurses. 2014-07-12 13:34:19 +01:00
top.h Add top.h. 2011-05-16 09:48:19 +02:00
uml_device.c Add a variable offset to vpn_packet_t, drop sptps_packet_t. 2014-12-25 00:36:27 +01:00
utils.c Fix undefined HOST_NAME_MAX on Windows. 2014-08-31 13:59:30 +01:00
utils.h utils: Refactor check_id out of protocol for global access 2014-08-25 09:19:54 +02:00
vde_device.c Add a variable offset to vpn_packet_t, drop sptps_packet_t. 2014-12-25 00:36:27 +01:00
version.c Use git description as the tinc version. 2015-05-04 21:38:23 +01:00
version.h Use git description as the tinc version. 2015-05-04 21:38:23 +01:00
xalloc.h Don't use vasprintf() anymore on Windows. 2013-07-17 18:06:56 +02:00