Commit graph

2277 commits

Author SHA1 Message Date
lemoer
532b9ca451 pong handler: fix incorrect calculation for rtt
Before this fix seconds were treated as milliseconds.

Example:

A ping of 1.001s resulted in current_rtt = 2 (ms)
where a ping of 0.999s resulted in current_rtt = 999 (ms).
2016-05-18 22:21:37 +02:00
lemoer
762dc69a59 pong handler: rtt and timestamps are always positive 2016-05-18 22:21:29 +02:00
lemoer
25317983c7 pong handler: add warning if we receive pong without ping 2016-05-18 21:22:03 +02:00
lemoer
8f21a5da81 pong handler: add sanity check for rtt 2016-05-18 21:20:47 +02:00
thorkill
9deb664a94 Added .dir-locals.el for the emacs devs 2016-05-18 21:02:24 +02:00
thorkill
a6543c144d Cleanup dynamically allocated buffer before use 2016-05-18 01:08:05 +02:00
thorkill
68beb519b4 Turn -Wformat to -Werror=format, got some wrong habits 2016-05-17 23:34:07 +02:00
thorkill
90c1341626 Initialize buffer for decryption - just in case 2016-05-17 23:06:53 +02:00
thorkill
3e9638b0cb msg buffer may contain random data - just clean it up 2016-05-17 22:55:16 +02:00
thorkill
ff8f57c130 Implemented SLPD information expiration and added support for port 2016-05-17 14:46:19 +02:00
lemoer
7b220b1464 Fix type conversation warnings for gcc in slpd. 2016-05-17 11:30:03 +02:00
thorkill
d28dece937 Proper length validation in handle_incoming_slpd_packet
- refactor and cleanup of unused variables
2016-05-17 11:12:55 +02:00
thorkill
4cb85c00a8 First attempt to sign and verify the SLPD data 2016-05-16 23:21:02 +02:00
thorkill
43ed440176 SLPD rewrite for IPv6 - IPv4 has been dropped
After first tests it came out, that RoadWarriors with multiple
active Interfaces hat problems with receiving on/ and sending SLPD
packets to specific interfaces.

Here the solution:
- Define SLPDInterface in your tinc.conf (multiple definitions are allowed)
  On those interfaces tincd will send and receive SLPD packetes
- You have to have IPv6 support on - link-local addresses configured
- tincd must listen on IPv6 on your SLPDInterfaces
- Define SLPDGroup to something like ff02::42:1
- Define SLPDPort for your group
- Define SLPDInterval to some sane number of seconds (0 is default,
meaning SLPD is disabled, 30 seconds should be enough for average
users)

SLPDGroup and SLPDPort should be unique for your network.

Fingerprinting, message signing is yet to be implemented.
Discovered address should also expire periodically.
2016-05-16 20:11:08 +02:00
thorkill
057ccb8da6 recvfrom return size_t not len 2016-05-15 19:12:41 +02:00
thorkill
e36af42ce4 Change type of the packet. 2016-05-15 18:48:24 +02:00
thorkill
99e0f5777c Small typo fix and set slpd sockt O_NONBLOCK 2016-05-15 17:24:07 +02:00
thorkill
756a6607e1 Silence log output 2016-05-15 00:39:18 +02:00
thorkill
cdd148204f Introduction to Simple Local Peer Discovery Protocol (SLPD)
Full functionality of tinc mesh relays on having at least one node,
accessible, with known address to which all other nodes must connect
in order to exchange information about other peers.

Sometimes, however, in smaller networks or if two or more peers are
located in the same LAN segment without access to any of the nodes with
known address, there is no way of establishing a functional mesh
without manually changing the configuration.

SLPD addresses this problem utilizing multicast groups and autoconnect.
- Node sends periodically simple message to multicast group
  (default 224.0.42.23 port 1655) in this format:
   "sLPD 0 1 nodename port publickey"

   "0 1" is the "major minior" version of the protocol

- Node listens to the multicast group for messages on all interfaces:
  - if the nodename is known and the publickey matches the
    node's public key the source address of the packet
    will be stored as learned ip address

- at this point setup_outgoing_connection() will be able to
  choose the learned ip for connect

Configarion example:
* Roadwarriors: SLPDInterval = 30
* Router on your home network or in your hackerspace:
 - It should broadcast only in the direction of the LAN thus you should
   set SLPDInterface = eth0 and SLPDInterval = 10
* Defaults:
 SLPDGroup = "224.0.42.23"
 SLPDPort = 1655
 SLPDInterval = 0 (means SLPD is disabled)

The check of the publickey is not implemented yet. IPv6 support
must be implemented. This is the first commit - highly experimental.
2016-05-15 00:24:35 +02:00
thorkill
4401c645ab Silence log messages on autoconnect 2016-05-14 23:21:36 +02:00
thorkill
39b23f7a11 Make edge update work when compiled with --disable-legacy 2016-05-14 23:18:44 +02:00
thorkill
ddc74678b2 Fixed log message - it is destination not source address 2016-05-12 13:16:01 +02:00
thorkill
0cf943753a Send PKT_PROBE only when handshake has been done already. 2016-05-12 11:20:41 +02:00
thorkill
3ec36e6432 We still need excessive sptps logging 2016-05-11 23:39:09 +02:00
thorkill
3558ab5499 Removed additional debug output 2016-05-11 23:39:03 +02:00
thorkill
ae199d9f2b Removed type check and debug output.
We will send PKT_PROBE in send_sptps_packet only if handshake has been completed.
2016-05-11 19:30:58 +02:00
thorkill
62064cc5ef Send PKT_PROBE only when handshake has been done already. 2016-05-11 19:30:07 +02:00
thorkill
a84019cf10 Split error handling for accurate log messages in sptps_verify_datagram
"Received short packet" was misleading.
2016-05-11 18:51:57 +02:00
thorkill
fe18e0ed29 Reverted changes to try_tx_sptps
- should fix the problem with unknown source
at the beginning of communication between nodes
2016-05-11 18:39:15 +02:00
thorkill
41e801cbbd Revert "Temporal fix for 'unknown source' and broken direct UDP links."
This reverts commit 157bc90e64.
2016-05-10 23:51:22 +02:00
thorkill
0e6265f546 Removed backtrace callback function 2016-05-10 13:43:25 +02:00
thorkill
bd95c231ce Merge branch 'thkr-1.1-20160510-fix-receive_tcppacket_sptps' into thkr-1.1-ponyhof 2016-05-10 12:01:06 +02:00
thorkill
dc8ee9e6d1 Prevent receive_tcppacket_sptps from forwarding data when we are in handshake phase with those nodes
Forwarding data to node which does not have vaildkey yet would destroy
the running handshake.
2016-05-10 11:43:14 +02:00
thorkill
73ae43199c Allow PKT_PROBE in sptps_send_record
sptps_send_record prevented PKT_PROBE to be send in send_sptps_packet.
This occurred mostly when data was on "the wire" for some subnet.
route() would then trigger try_tx/try_udp which would be dropped by
sptps_send_record producing annoying amount of "Handshake phase
not finished yet" log messages.
2016-05-10 00:43:43 +02:00
thorkill
c5f46d3efb Removed backtrace callback 2016-05-10 00:37:39 +02:00
thorkill
75bca2543d Tabs vs spaces cleanup. 2016-05-10 00:17:38 +02:00
thorkill
c7d838eb41 Fixed autoconnect after merge 2016-05-08 16:46:29 +02:00
thorkill
08f1fd2f8d Fixes after merge with guus/1.1 2016-05-08 16:14:20 +02:00
thorkill
e6b85158f0 Added symbols necessary to link with logger.o 2016-05-08 16:12:41 +02:00
thorkill
4be26caf4e Merge remote-tracking branch 'guus/1.1' into thkr-foor2Vup 2016-05-08 15:58:29 +02:00
Guus Sliepen
2055c3e21d AutoConnect now only chooses from nodes for which we know an address.
Based partially on work from Rafał Leśniak.
2016-04-30 20:11:55 +02:00
Guus Sliepen
8377d0b856 Fix BSD tun device support.
This was broken by a botched merge from the master branch in commit d7f6737.
2016-04-27 20:30:36 +02:00
Guus Sliepen
390d25f0b8 Releasing 1.1pre12. 2016-04-24 13:23:06 +02:00
Guus Sliepen
5a7c6546a4 Don't check file permissions on Windows during fsck. 2016-04-23 21:39:53 +02:00
Guus Sliepen
83fa44ce42 Fix starting tinc as a service on Windows.
Don't assume tincd.exe is in the working directory, especially now that
chdir() is called very early. We use GetModuleFileName() instead.
2016-04-23 21:32:42 +02:00
Guus Sliepen
9a66d7499a Fix a compiler warning on Windows. 2016-04-23 21:32:29 +02:00
Guus Sliepen
ab5f4cbdc6 Fix possible read of freed memory when verifying the signature of a file. 2016-04-23 17:28:30 +02:00
Guus Sliepen
76955a6c8b Have "tinc fsck" recognize Ed25519PublicKey statements. 2016-04-23 17:20:08 +02:00
Guus Sliepen
51a0dc5145 Fix the "network" command in tinc shell. 2016-04-17 18:11:04 +02:00
Guus Sliepen
b6b302cee9 Speed up AutoConnect at startup.
Call periodic_handler() immediately at startup. Also, don't try to
connect to ourself.
2016-04-17 17:06:11 +02:00
Guus Sliepen
f934417aa6 Don't call terminate_connection(myself->connection).
It doesn't do anything except give a confusing error message that we are
closing the connection to ourself. Replace it with connection_del().
This also fixes a double free.
2016-04-17 16:25:13 +02:00
Guus Sliepen
2213ecaea5 Handle special characters in sptps_test only if the --special option is given.
sptps_test treats lines starting with #, ^ and $ specially, in order to
test the SPTPS protocol. However, this should only be done if explicitly
requested, otherwise it can unexpectedly fail.
2016-04-17 16:01:49 +02:00
Guus Sliepen
c2dc3784f1 Add stricter checks for netnames.
When passing a NetName via an invitation, we don't allow any characters
that are unsafe (either because they could cause shells to expand things,
or because they are not allowed on some filesystems).

Also, warn when tinc is started with unsafe netnames.
2016-04-17 14:38:37 +02:00
Guus Sliepen
097c69fc6a Use ifconfig_header(). 2016-04-17 14:36:29 +02:00
Guus Sliepen
af9ee7ff00 Chdir() to the configuration directory instead of /. 2016-04-17 14:04:57 +02:00
Guus Sliepen
0b96b69672 Fix compiler warnings. 2016-04-17 13:55:36 +02:00
Guus Sliepen
a08860ff8c Fix gateway parsing in invitation files. 2016-04-17 13:55:18 +02:00
Guus Sliepen
6d04528966 Allow gateways to be specified for routes.
Also improve the variable names, and ensure the % symbols in
%INTERFACE% are properly quoted.
2016-04-17 13:23:01 +02:00
Guus Sliepen
03878f1215 Move some stray #includes. 2016-04-17 01:13:56 +02:00
Guus Sliepen
3273e32541 Generate a tinc-up script from an invitation.
This adds the ability for an invitation to provision an invitee with a
tinc-up script. This is quite strictly controlled; only address configuration
and routes are supported by adding "Ifconfig" and "Route" statements to
the invitation file. The "tinc join" command will generate a tinc-up script
from those statements, and will ask before enabling the tinc-up script.
2016-04-17 01:13:27 +02:00
Guus Sliepen
a31e1f03c4 Stop using SOL_TCP, SOL_IP and SOL_IPV6.
Instead, use IPPROTO_TCP, _IP and _IPv6. This fixes an issue on OS X where
it didn't create an UDP socket that listened on IPv4.
2016-04-15 16:56:56 +02:00
Guus Sliepen
a0a8f8f81f Fix crash at startup when Device is not specified on OS X. 2016-04-15 16:30:45 +02:00
Guus Sliepen
039d6d48af Fix some compiler warnings from MinGW. 2016-04-15 12:42:30 +02:00
Guus Sliepen
1f5c26102e Fix generation of version_git.h for some versions of BSD make.
In order to support VPATH builds, we have to use ${srcdir}/version.c as
the target for the rule that depends on the generation of version_git.h.
When not doing a VPATH build, ${srcdir} expands to ".", so the target
will be "./version.c". However, on some BSDs, make does not understand
that "./version.c" is the same as "version.c", and therefore it doesn't
trigger generating version_git.h when trying to build version.o. (It
works fine if you do a VPATH build, and OpenBSD's make does the right
thing in all cases.)

The trick is to have version.c depend on ${srcdir}/version.c. Of course,
Linux's make knows this is nonsense and will complain about a circular
dependency, so add this rule only on BSD platforms.
2016-04-15 12:30:01 +02:00
Guus Sliepen
0037ec7cb3 Fix a non-working cast to get rid of a compiler warning. 2016-04-15 12:29:31 +02:00
Guus Sliepen
25bcdad878 Don't use HAVE_SYSTEM, the autoconf check was removed. 2016-04-15 11:38:56 +02:00
Guus Sliepen
cd5f222cc4 Remove use of strcpy() and sprintf().
Even though they were safe, compilers like to warn about them nowadays.
2016-04-15 11:25:18 +02:00
Guus Sliepen
d4410d0cce Don't assume sa.sa_family is a short int.
Because FreeBSD's compiler complained about it.
2016-04-15 11:10:50 +02:00
Guus Sliepen
d704a89ecc Add version_git.h and sample-config.tar.gz to CLEANFILES. 2016-04-15 11:00:14 +02:00
Guus Sliepen
d10834e920 Remove support for Windows 2000 and anything that doesn't support getaddrinfo(). 2016-04-14 23:32:50 +02:00
Guus Sliepen
ed09fa4e03 Fix version_get.h generation on BSD.
It doesn't like .PHONY rules that are actually doing stuff. So make a really
phony rule that does nothing and depend in it in the version_git.h rule.
2016-04-14 23:01:18 +02:00
Guus Sliepen
2802b3a497 Fix typo in Makefile.am. 2016-04-14 22:59:42 +02:00
Guus Sliepen
46ebfbb6eb Use getcwd() instead of get_current_dir_name(). 2016-04-14 17:29:25 +02:00
Guus Sliepen
b5b04910b9 Replace usleep() with nanosleep(). 2016-04-14 17:21:47 +02:00
Guus Sliepen
491839a81a Fix compiling under MinGW. 2016-04-14 17:05:10 +02:00
Guus Sliepen
34ea20af73 Remove checks for headers and functions that are in C99. 2016-04-14 17:03:01 +02:00
Guus Sliepen
9ba3e95a9a Remove elliptic curve stubs from gcrypt/, add PRF implementation. 2016-04-11 15:27:08 +02:00
Guus Sliepen
20dd1c21dc Really don't compile getopt*.c if the system provides getopt_long(). 2016-04-11 15:20:32 +02:00
Guus Sliepen
9527622abc Enable silent builds by default.
Cleaner build messages make it easier to spot compiler warnings and errors.
Use make V=1 to get the verbose output back.

# Conflicts:
#	configure.ac
#	doc/Makefile.am
2016-04-11 15:07:23 +02:00
Guus Sliepen
d7f6737cfc Update support for BSD tun/tap devices, add support for OS X utun interfaces. 2016-04-11 14:49:51 +02:00
Guus Sliepen
2a7871990b Update "now" after connect() when making outgoing connections.
It could be that address resolution takes a long time, don't let that
count against a connection. This is especially important when using a
nameserver from the VPN.

# Conflicts:
#	src/net_socket.c
2016-04-10 17:49:23 +02:00
Guus Sliepen
cadbf587a0 Never call putenv() with data on the stack.
Even though we are using putenv() here to remove items from the
environment, there is no guarantee that putenv() doesn't add the
argument to the environment anyway. In that case, we have to make sure
that it doesn't go away. We also don't want a memory leak, so keep a
list of things we unputenv()ed around, so we can reuse things.

Thanks to Poul-Henning Kamp for pointing out this problem.

# Conflicts:
#	src/process.c
2016-04-10 17:42:23 +02:00
Guus Sliepen
0e8e53b4ce Fix --logfile without a filename on Windows.
On Windows, the log filename now defaults to "tinc.log" in the same
directory as tinc.conf.

# Conflicts:
#	src/tincd.c
2016-04-10 17:28:42 +02:00
Guus Sliepen
c544e5e8fe Support ToS/DiffServ for IPv6 meta and UDP connections.
Also remember ToS/DiffServ priority for each socket individually. This
is a port of commits c72e237 and 042a6c1.
2016-04-10 17:24:55 +02:00
Guus Sliepen
e355088535 Use iface instead of interface.
This was accidentally added in commit 2f03a5d.
2016-04-10 17:01:52 +02:00
Guus Sliepen
9f0fb224a6 Don't compile getopt*.c if the system provides getopt_long().
# Conflicts:
#	configure.ac
#	src/Makefile.am
#	src/tincd.c
2016-04-10 16:47:32 +02:00
LunarShaddow
e44c337eae re-arrange include sequence to avoid a mingw introduced bug.
refers: https://www.cygwin.com/ml/cygwin/2012-12/msg00194.html

# Conflicts:
#	src/cygwin/device.c
2016-03-07 21:54:13 +01:00
LunarShaddow
af83d0b9e8 fix typo 2016-03-07 21:51:44 +01:00
Guus Sliepen
bf50b3502a Fix for botched cherry-pick commit 60fb230. 2016-02-28 16:38:49 +01:00
Guus Sliepen
1ceea259c3 Add warnings for bad combinations of Device and Interface.
On Linux, the name of the tun/tap interface can be set freely. However,
on most other operating systems, tinc cannot change the name of the
interface. In those situations, it is possible to specify a Device and
an Interface that conflict with each other. On BSD, this can cause
$INTERFACE to be set incorrectly, on Windows, this results in a
potentially unreliable way in which a TAP-Win32 interface is selected.

# Conflicts:
#	src/bsd/device.c
2016-02-28 16:37:52 +01:00
Guus Sliepen
4d7469e0da Fix forwarding of edge updates.
Commit e4670fc accidentily prevented ADD_EDGE messages from propagating
in some cases.
2016-02-28 16:31:31 +01:00
Guus Sliepen
60fb2308e5 Improve performance of edge updates. 2016-02-28 16:29:51 +01:00
Vittorio Gambaletta (VittGam)
994adadf27 Remove forward declaration for do_decrement_ttl.
Signed-off-by: Vittorio Gambaletta <openwrt@vittgam.net>

# Conflicts:
#	src/route.c
2016-02-28 16:24:12 +01:00
Vittorio Gambaletta (VittGam)
0f3ae1a9f2 s/broadcast_packet_helper/route_broadcast/
Signed-off-by: Vittorio Gambaletta <openwrt@vittgam.net>

# Conflicts:
#	src/route.c
2016-02-28 16:19:00 +01:00
Vittorio Gambaletta (VittGam)
496f775568 Fix DecrementTTL option for packets destined to the local node.
Signed-off-by: Vittorio Gambaletta <openwrt@vittgam.net>

# Conflicts:
#	src/route.c
2016-02-28 16:17:23 +01:00
Vittorio Gambaletta (VittGam)
17e54ea0be Try to reply with node address only when decrementing the TTL.
Signed-off-by: Vittorio Gambaletta <openwrt@vittgam.net>
2016-02-28 15:58:47 +01:00
Vittorio Gambaletta (VittGam)
92203bdbcb Fix source IP address for ICMP unreachable packets generated by tinc.
Try to send ICMP unreachable replies from an address assigned to the
local machine, instead of the destination address of the original
packet.

The address is found by looking up the route towards the sender of
the packet that generated the error; in usual configurations, this
is the tinc interface.

This also fixes the traceroute display in mtr when using the
DecrementTTL option.

Signed-off-by: Vittorio Gambaletta <openwrt@vittgam.net>

# Conflicts:
#	src/route.c
2016-02-28 15:58:25 +01:00
Vittorio Gambaletta (VittGam)
a8a3a2c8ce Fix DecrementTTL option.
The option was not actually working, as it could be seen on traceroute or mtr.

The problem is that it was checking if the TTL was < 1 (so equal to 0) before decrementing it.

This meant that a packet with a TTL of 1 was being sent with a TTL of 0 on the VPN, instead of being discarded with the ICMP error message.

Signed-off-by: Vittorio Gambaletta <openwrt@vittgam.net>

# Conflicts:
#	src/route.c
2016-02-28 15:54:33 +01:00
Guus Sliepen
ac9e32ff91 Use nostdinc instead of overriding DEFAULT_INCLUDES. 2016-02-28 15:48:19 +01:00
Guus Sliepen
d8ca00fe40 Add the ability to sign and verify files. 2016-01-27 00:09:29 +01:00
Guus Sliepen
420989e4c3 Only add a reflexive address when we're sure it's working. 2016-01-14 15:39:38 +01:00
thorkill
324c84aebd On FreeBSD backtrace() needs -lexecinfo 2015-12-10 23:33:15 +01:00
thorkill
371b3a2ba5 fix linking problem on FreeBSD 2015-12-10 23:17:13 +01:00
thorkill
eb84af49fa Make handle_incoming_vpn_packet compile 2015-12-10 17:26:18 +01:00
thorkill
07ec2d2eb2 Merge remote-tracking branch 'remotes/guus/1.1' into thkr-1.1-ponyhof 2015-12-10 17:08:29 +01:00
thorkill
1dd8033ea5 Added excessive debug output to sptps 2015-12-10 17:08:03 +01:00
Guus Sliepen
cda5a477c8 Use static buffers for recvmmsg(), initialize them only as needed.
As suggested by Michael Tokarev.
2015-12-10 16:45:05 +01:00
Guus Sliepen
e4fd81ed2d Add support for recvmmsg().
Based on a patch from Samuel Thibault and input from Michael Tokarev.
2015-12-10 16:36:10 +01:00
thorkill
42381038ba Forget nodes while forwarding subnet informations 2015-11-30 01:00:28 +01:00
thorkill
dff1743322 Do not forward informations about other nodes if they are not reachable and the last_state_change is larger than 2 x KeyExpire 2015-11-30 00:22:51 +01:00
thorkill
bdcbf10428 Lets send only nodes and edge info when n->last_state_change > 0 and this information is no older than 1 hour 2015-11-29 11:52:14 +01:00
thorkill
781dac00d5 Do not send informations about unreachable nodes - testing highly experimental, the problem is that once a node has been introduced to the network it will never be deleted until all tincd will be disabled in the whole network at once 2015-11-29 11:41:13 +01:00
thorkill
23c78217b1 Removed -fsanitize=undefined - I have missed it on last commit 2015-11-29 09:46:53 +01:00
thorkill
08f74b5603 Fix linker flags 2015-11-27 17:51:34 +01:00
Guus Sliepen
cef40b8b97 list_delete() already free()s the deleted element. 2015-11-26 11:29:54 +01:00
thorkill
519f06e281 Fix a segfault in setup_outgoing_connection() on outgoing removal 2015-11-24 17:25:53 +01:00
thorkill
2ec9f1124d Merged with guus/1.1 2015-11-24 17:01:11 +01:00
thorkill
f58e8679e7 Revert "Working on fix "stuck" outgoing connections."
This reverts commit 703ed7fff6.
2015-11-24 16:55:03 +01:00
Guus Sliepen
9fdf4278f8 Don't leave dead outgoing_t's in the outgoing_list.
If an outgoing connection cannot be made because no address is known for
it, it should be removed from the outgoing_list, otherwise it will
prevent it from being re-added later when we do know addresses for it.
2015-11-24 16:48:44 +01:00
Etienne Dechamps
c58eba587d Add upnp.h to tincd SOURCES.
This was missing from 513bffe1fe.
2015-11-22 23:03:03 +01:00
thorkill
703ed7fff6 Working on fix "stuck" outgoing connections.
This problem occurs on "road-warriors" when tincd setups
outgoing connections but you do not have any active uplink then
dns-lookups will fail and any following attempt to make outgoing
connections will keep failing forever.
2015-11-22 22:50:51 +01:00
Etienne Dechamps
613d586afd Don't unset validkey when receiving SPTPS handshakes over ANS_KEY.
This fixes a hairy race condition that was introduced in
1e89a63f16, which changed
the underlying transport of handshake packets from REQ_KEY to ANS_KEY.
Unfortunately, what I missed in that commit is, on the receiving side,
there is a slight difference between req_key_h() and ans_key_h():
indeed, the latter resets validkey to false.

The reason why this is not a problem during typical operation is
because the normal SPTPS key regeneration procedure looks like this:

    KEX ->
    <- KEX
    SIG ->
    <- SIG

All these messages are sent over ANS_KEY, therefore the receiving side
will unset validkey. However, that's typically not a problem in practice
because upon reception of the last message (SIG), SPTPS will call
sptps_receive_record(), which will set validkey to true again, and
everything works out fine in the end.

However, that was the *typical* scenario. Now let's assume that the
SPTPS channel is in active use at the same time key regeneration
happens. Specifically, let's assume a normal VPN data packet sneaks in
during the key regeneration procedure:

    KEX ->
    <- KEX
    <- (SPTPS packet, over TCP or UDP)
    <- KEX (wtf?)
    SIG -> (refused with Invalid packet seqno: XXX != 0)

At this point, both nodes are extremely confused and the SPTPS channel
becomes unusable with various errors being thrown on both sides. The
channel will stay down until automatic SPTPS channel restart kicks in
after 10 seconds.

(Note: the above is just an example - the race can occur on either side
whenever a packet is sent during the period of time between KEX and SIG
messages are received by the node sending the packet.)

I've seen this race occur in the wild - it is very likely to occur if
key regeneration occurs on a heavily loaded channel. It can be
reproduced fairly easily by setting KeyExpire to a short value (a few
seconds) and then running something like ping -f foobar -i 0.01.

The reason why this occurs is because tinc's TX code path triggers the
following:

 - send_packet()
 - try_tx()
 - try_tx_sptps()
 - validkey is false because we just received an ANS_KEY message
 - waitingforkey is false because it's not used for key regeneration
 - send_req_key()
 - SPTPS channel restart (sptps_stop(), sptps_start()).

Obviously, it all goes downhill from there and the two nodes get very
confused quickly (for example the seqno gets reset, hence the error
messages).

This commit fixes the issue by keeping validkey set when SPTPS data is
received over ANS_KEY messages.
2015-11-22 17:53:52 +00:00
Etienne Dechamps
0f6d34dc1b Try to ensure we build correctly against various libminiupnpc versions.
Unfortunately, libminiupnpc has a somewhat... "peculiar" approach to
backwards compatibility for their API, where they reserve the right to
make breaking changes when they feel like it, forcing users to resort
to #ifdefs to ensure they use the correct API. Sigh.

Previously, tinc would only build against API versions <= 13, because I
was doing my initial development using miniupnpc-1.9.20140610 which is
the version that ships with Debian. The changes in this commit are
required for tinc to build against more recent versions, from
1.9.20150730 to the latest one at the time of this commit, 1.9.20151026.
2015-11-21 16:18:01 +00:00
Etienne Dechamps
513bffe1fe Add UPnP support to tincd.
This commit makes tincd capable of discovering UPnP-IGD devices on the
local network, and add mappings (port redirects) for its TCP and/or UDP
port.

The goal is to improve reliability and performance of tinc with nodes
sitting behind home routers that support UPnP, by making it less reliant
on UDP Hole Punching, which is prone to failure when "hostile" NATs are
involved.

The way this is implemented is by leveraging the libminiupnpc library,
which we have just added a new dependency on. We use pthread to run the
UPnP client code in a dedicated thread; we can't use the tinc event loop
because libminiupnpc doesn't have a non-blocking API.
2015-11-21 16:17:59 +00:00
thorkill
dcf313cdbf Merge remote-tracking branch 'remotes/guus/1.1' into thkr-1.1-ponyhof 2015-11-07 23:21:18 +01:00
Etienne Dechamps
bdd84660c7 Make sure the packet source MAC address is always set.
When tinc is used in router mode with a TAP device, Ethernet (MAC)
headers are not present in packets flowing over the VPN; it is the
node's responsibility to fill out this header before handing the
packet over to the TAP interface (which expects such headers).

Currently, tinc fills out the destination MAC address of the packet
(otherwise the host would not recognize the packets, and nothing would
work), but it does not fill out the source MAC address. In practice this
doesn't seem to cause any real issues (the host doesn't care about the
source address), but it does look weird when looking at the packets with
a sniffer, and it also result in the following valgrind warning:

    ==13651== Syscall param write(buf) points to uninitialised byte(s)
    ==13651==    at 0x5C4B620: __write_nocancel (syscall-template.S:81)
    ==13651==    by 0x1445AA: write_packet (device.c:183)
    ==13651==    by 0x118C7C: send_packet (net_packet.c:1259)
    ==13651==    by 0x12B70A: route_ipv4 (route.c:443)
    ==13651==    by 0x12D5F8: route (route.c:971)
    ==13651==    by 0x1152BC: receive_packet (net_packet.c:250)
    ==13651==    by 0x117E1B: receive_sptps_record (net_packet.c:904)
    ==13651==    by 0x1309A8: sptps_receive_data_datagram (sptps.c:488)
    ==13651==    by 0x130A90: sptps_receive_data (sptps.c:508)
    ==13651==    by 0x115569: receive_udppacket (net_packet.c:286)
    ==13651==    by 0x119856: handle_incoming_vpn_data (net_packet.c:1499)
    ==13651==    by 0x10F3DA: event_loop (event.c:287)
    ==13651==  Address 0xffeffea3a is on thread 1's stack
    ==13651==  in frame #6, created by receive_sptps_record (net_packet.c:821)
    ==13651==

This commit fixes the issue by filling out the source MAC address. It is
generated by negating the last byte of the device MAC address, which is
consistent with what route_arp() does.

In addition, this commit stops route_arp() from filling out the Ethernet
header of the packet - this is the responsibility of send_packet(), not
route().
2015-11-07 11:59:16 +00:00
thorkill
e95c1a93a7 Merge with guus/1.1 2015-11-06 22:56:46 +01:00
Etienne Dechamps
684bd659ae Revert "Cache node IDs in a hash table for faster lookups."
This reverts commit c2319e90b1.

As a general principle, I do not believe it is worthwhile to cache
nodes. Sure, it brings lookup time down from O(log n) to O(1), but
considering that the scalability target of tinc is around 1000 nodes
and log2(1000) is 10, that looks like premature optimization; tree
lookups should already be very fast. Therefore, I believe it makes sense
to remove the cache as a code cleanup initiative.
2015-11-04 19:36:06 +00:00
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
Guus Sliepen
7a8515112a Avoid undefined behavior.
Left shifts of negative values is undefined in C. This happens a lot in
the Ed25519 code. Cast to unsigned first, then cast the result back to
signed where necessary.
2015-10-26 13:46:30 +01:00
Guus Sliepen
7306823843 Fix a few memory leaks in the CLI found by AddressSanitizer. 2015-09-25 10:06:18 +02:00
Guus Sliepen
543c0abbd9 Fix struct node_status_t.
Although not a problem for tinc internally, the size of the struct was 12
bytes instead of 4, causing some problems when interpreting the value
received from tincd by the CLI.
2015-09-25 10:05:24 +02:00
Nathan Stratton Treadway
ae89a25695 Fix invalid checksum generation.
Use equation 3 given in RFC 1624 and the UpdateTTL() example function given
RFC 1141.

# Conflicts:
#	src/route.c
2015-09-12 16:41:48 +02:00
hans
a9fb6db249 add malloc check
malloc can fail. check for errors or use xmalloc.
since this is bsd only, it is safe to use err and err.h.
2015-08-26 16:44:51 +02:00
hans
4710de8455 Activate fstack-protector-all on OpenBSD 2015-08-25 09:30:43 +02:00
hans
c9515a79de Make it build on openbsd.
Build on amd64 and sparc64.
2015-08-25 09:30:32 +02:00
thorkill
d9a8344467 Fix for unknown subnets
In a case where a node doesn't have AutoConnect = yes and StrictSubnet = yes
is set, the node would discard all ADD_SUBNET.
2015-07-26 15:14:40 +02:00
thorkill
af1213a7ae Revert "Do not recompile version if not needed"
This reverts commit 529576dad6.

This feature works only with gmake, BSD systems do not have
it and we do not want to force users to install it.
2015-07-26 12:22:22 +02:00
thorkill
529576dad6 Do not recompile version if not needed 2015-07-26 12:15:45 +02:00
thorkill
618ddadeab Fixed a segfault when all nodes available for autoconnect has been exhausted
In cases when tinc has all available nodes in outgoing connections and
can not establish those connection due to network outage periodic_handler()
would crash since tmp_node_tree->count is 0.

This commit adds also new flag node->status.has_cfg_address to prevent
update_udp_address() from removing this flag.

Fixed node_status_t->unused - 13 + 19 = 32
2015-07-23 20:46:20 +02:00
thorkill
f12d4a3e6d Merged load_all_subnets and load_all_nodes to make autoconnect and strictsubnets work faster
When AutoConnect is on tinc needs to know if nodes have Address to defined
in thier hosts files. Currently tinc parsed node's host files if StrictSubnet
was enabled. To reduce the parsing overhead I have merged load_all_subnets
with load_all_nodes, such that load_all_subnets has been removed and
load_all_nodes has if-statement extracting Subnet information from node's host
file.
2015-07-23 18:34:29 +02:00
thorkill
3c67735720 Make autoconnect faster
When AutoConnect is enabled tinc tries to connect to other nodes picking them at random.
This may be sane default behavior but it may take ages if only few nodes have
defined Address in thier config.

Proposed solution to this problem:
- Filter out nodes without known address in periodic_handler
  I have added new node->status.has_known_address bool
- On update_node_udp() update this flag
2015-07-23 18:02:30 +02:00
thorkill
d16a43c06c Revert "It seems that this patch is needed. Strange things happens."
This reverts commit 50bf9b5a1a.
2015-07-22 15:32:36 +02:00
Guus Sliepen
24c3bebc5c In sssp_bfs(), never try to update myself. 2015-07-22 15:32:36 +02:00
Guus Sliepen
56a8b90d86 In sssp_bfs(), never try to update myself. 2015-07-22 14:33:56 +02:00
thorkill
0842bc0ca5 Revert "Added missing check to e->to->prevedge"
This reverts commit 4077acd583.
2015-07-21 19:39:08 +02:00
thorkill
512c64980a Merge branch 'thkr-1.1-ponyhof' of github.com:thorkill/tinc into thkr-1.1-ponyhof 2015-07-21 10:11:36 +02:00
thorkill
4077acd583 Added missing check to e->to->prevedge 2015-07-21 10:10:37 +02:00
thorkill
1edf49be14 Reduce logger calls 2015-07-20 11:10:27 +02:00
thorkill
8c4cdfc37c Prevent update_node_udp from changing our udp address
Follup to 6dbcd4eb3d

- myself is always reachable
- do not call update_node_udp if e->to == myself
2015-07-20 08:19:37 +02:00