Commit graph

2743 commits

Author SHA1 Message Date
Guus Sliepen
fd1cff6df2 Fix receiving UDP packets from tinc 1.0.x nodes.
In try_mac(), the wrong offsets were used into the packet buffer,
causing the digest verification to always fail.
2015-05-15 00:21:48 +02:00
Guus Sliepen
44e9f1e1d8 Fix invitations.
These were broken due to a change in behaviour of sptps_receive_data()
introduced in commit d237efd325.
2015-05-13 14:28:28 +02:00
thorkill
35af740537 Merge branch '1.1' of github.com:gsliepen/tinc into thkr-1.1-ponyhof 2015-05-12 17:28:29 +02:00
thorkill
2189232b79 Init avg. RTT based on weight 2015-05-12 17:23:28 +02:00
Etienne Dechamps
7e6b2dd1ea Introduce raw TCP SPTPS packet transport.
Currently, SPTPS packets are transported over TCP metaconnections using
extended REQ_KEY requests, in order for the packets to pass through
tinc-1.0 nodes unaltered. Unfortunately, this method presents two
significant downsides:

 - An already encrypted SPTPS packet is decrypted and then encrypted
   again every time it passes through a node, since it is transported
   over the SPTPS channels of the metaconnections. This
   double-encryption is unnecessary and wastes CPU cycles.

 - More importantly, the only way to transport binary data over
   standard metaconnection messages such as REQ_KEY is to encode it
   in base64, which has a 33% encoding overhead. This wastes 25% of the
   network bandwidth.

This commit introduces a new protocol message, SPTPS_PACKET, which can
be used to transport SPTPS packets over a TCP metaconnection in an
efficient way. The new message is appropriately protected through a
minor protocol version increment, and extended REQ_KEY messages are
still used with nodes that do not support the new message, as well as
for the intial handshake packets, for which efficiency is not a concern.

The way SPTPS_PACKET works is very similar to how the traditional PACKET
message works: after the SPTPS_PACKET message, the raw binary packet is
sent directly over the metaconnection. There is one important
difference, however: in the case of SPTPS_PACKET, the packet is sent
directly over the TCP stream completely bypassing the SPTPS channel of
the metaconnection itself for maximum efficiency. This is secure because
the SPTPS packet that is being sent is already encrypted with an
end-to-end key.
2015-05-10 21:08:57 +01:00
Etienne Dechamps
d237efd325 Only read one record at a time in sptps_receive_data().
sptps_receive_data() always consumes the entire buffer passed to it,
which is somewhat inflexible. This commit improves the interface so that
sptps_receive_data() consumes at most one record. The goal is to allow
non-SPTPS stuff to be interleaved with SPTPS records in a single TCP
stream.
2015-05-10 21:08:57 +01:00
Etienne Dechamps
de14308840 Rename REQ_SPTPS to SPTPS_PACKET.
REQ_SPTPS implies the message has an ANS_ counterpart (like REQ_KEY,
ANS_KEY), but it doesn't. Therefore dropping the REQ_ seems more
appropriate, and we add a _PACKET suffix to reduce the likelihood of
naming conflicts.
2015-05-10 21:08:57 +01:00
Etienne Dechamps
10c1f60c64 Try to use UDP to relay SPTPS packets received over TCP.
Currently, when tinc receives a SPTPS packet over TCP via the REQ_KEY
encapsulation mechanism, it forwards it like any other TCP request. This
is inefficient, because even though we received the packet over TCP,
we might have an UDP link with the next hop, which means the packet
could be sent over UDP.

This commit removes that limitation by making sure SPTPS data packets
received through REQ_KEY requests are not forwarded as-is but passed
to send_sptps_data() instead, thereby using the same code path as if
the packet was received over UDP.
2015-05-10 21:08:57 +01:00
Etienne Dechamps
1296f715b5 Expose the raw SPTPS send interface from net_packet.
net_packet doesn't actually use send_sptps_data(); it only uses
send_sptps_data_priv(). In addition, the only user of send_sptps_data()
is protocol_key. Therefore it makes sense to expose
send_sptps_data_priv() directly, and move send_sptps_data() (which is
basically just boilerplate) as a local function in protocol_key.
2015-05-10 21:08:57 +01:00
Etienne Dechamps
8e43a2fc74 Use the correct originator node when relaying SPTPS UDP packets.
Currently, when relaying SPTPS UDP packets, the code uses the direct
sender as the originator, instead of preserving the original source ID.

This wouldn't cause any issues in most cases because the originator and
the sender are the same in simple one-hop relay chains, but this will
break as soon as there is more than one relay.
2015-05-10 18:46:47 +01:00
Etienne Dechamps
9d223cb7e7 When relaying, send probes to the destination, not the source.
This seems to be a typo from c23e50385d.
Achievement unlocked: got a one-line commit wrong.
2015-05-10 18:37:30 +01:00
Etienne Dechamps
13f9bc1ff1 Add support for out-of-tree ("VPATH") builds.
This fixes some issues with the build system when building out of tree.

With this commit, it is now possible to do the following:

    $ cd /tmp/build
    $ /path/to/tinc/configure
    $ make
2015-05-09 16:41:48 +01:00
Etienne Dechamps
462e9892ae Remove explicit distribution rules for m4 scripts.
It turns out Automake is smart enough to include these files in the
distribution by itself.
2015-05-09 16:17:39 +01:00
Guus Sliepen
362b791764 Really remove "release-" from the git-derived version string. 2015-05-09 15:41:37 +02:00
Etienne Dechamps
b109e8b164 Use git describe to populate autoconf's VERSION.
This uses the output of "git describe" directly in configure.ac to
determine the version number to use, instead of hardcoding it.

With this change, current version information is completely removed
from the codebase itself, and is always fetched on-the-fly from git as
the single source of truth.

In order to ensure make dist always uses the current version number in
the contents of the packaged configure script as well as the package
name, a dependency is added to the dist target such that autoconf is
always run before dist to regenerate the version number. If this wasn't
the case, make dist would use the version number from when autoconf was
originally run, not the version number that make dist is running from.
That said, errors from that rule are ignored so that people can still
run make dist without a working autoconf.

In addition, the NEWS check is dropped, as it would then become annoying
because it would force make dist users to always have a line for the
current commit in the NEWS file.
2015-05-09 12:14:31 +01:00
Pierre Emeriaud
1c77069064 Fix typo in tincctl help. 2015-05-09 00:03:51 +02:00
Guus Sliepen
54554cc276 Don't include build-time generated version_git.h in the tarball. 2015-05-05 23:05:22 +02:00
Guus Sliepen
c46bdbde18 Remove "release-" from displayed git version.
Also make sure that version_git.h is only written to if the "git
describe" command succeeds.
2015-05-05 23:03:41 +02:00
Etienne Dechamps
120e0567cb Use git description as the tinc version.
Instead of using the hardcoded version number in configure.ac, this
makes tinc use the live version reported by "git describe",
queried on-the-fly during the build process and regenerated for every
build.

This makes tinc version output more useful, as tinc will now display the
number of commits since the last tag as well as the commit the binary is
built from, following the format described in git-describe(1).

Here's an example of tincd --version output:

  tinc version release-1.1pre10-48-gc149315 (built Jun 29 2014 15:21:10, protocol 17.3)

When building directly from a release tag, this will look like the following:

  tinc version release-1.1pre10 (built Jun 29 2014 15:21:10, protocol 17.3)

(Note that the format is slightly different - because of the way the
tags are named, it says "release-1.1pre10" instead of just "1.1pre10")

If git describe fails (for example when building from a release
tarball), the build automatically falls back to the autoconf-provided
VERSION macro (i.e. the old behavior).
2015-05-04 21:38:23 +01:00
thorkill
bb2084da59 Merge branch '1.1' of github.com:gsliepen/tinc into thkr-1.1-ponyhof 2015-04-24 23:52:45 +02:00
Guus Sliepen
95594f4738 Fix typo 0fda572c88 that prevented some errors from being logged. 2015-04-24 23:51:29 +02:00
thorkill
9e0c4a7349 Merge branch '1.1' of github.com:gsliepen/tinc into thkr-1.1-ponyhof
,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
2015-04-24 23:47:25 +02:00
Guus Sliepen
0fda572c88 Don't log an error message when receiving a TERMREQ. 2015-04-24 23:43:58 +02:00
Guus Sliepen
ea1e815223 Fix a possible segmentation fault during key upgrades.
read_rsa_public_key() was bailing out early if the given node already has an Ed25519 key, and
returned true even though c->rsa was NULL. The early bailout code isn't necessary anymore, so just
remove it.
2015-04-24 23:43:19 +02:00
Guus Sliepen
2059814238 Allow one-sided upgrades to Ed25519.
This deals with the case where one node knows the Ed25519 key of another node, but not the other
way around. This was blocked by an overly paranoid check in id_h(). The upgrade_h() function already
handled this case, and the node that already knows the other's Ed25519 key checks that it has not
been changed, otherwise the connection will be aborted.
2015-04-24 23:40:20 +02:00
thorkill
1c41100737 added test for deadlock scenario while upgrading to 1.1 2015-04-24 22:04:03 +02:00
thorkill
50bf9b5a1a It seems that this patch is needed. Strange things happens.
Revert "Want to test old version with latest patches."

This reverts commit fcc0c2239f.
2015-04-24 18:07:12 +02:00
thorkill
fcc0c2239f Want to test old version with latest patches.
Revert "Temporal fix for broken hopes."

This reverts commit df42bc3621.
2015-04-24 17:47:04 +02:00
thorkill
655d8a0f67 Removed debug output 2015-04-16 10:55:50 +02:00
thorkill
0fc873a161 Merge branch '1.1' into thkr-1.1-ponyhof 2015-04-16 10:44:01 +02:00
Guus Sliepen
3def9d2ad8 Merge remote-tracking branch 'dechamps/wintapver' into 1.1 2015-04-12 15:43:05 +02:00
Guus Sliepen
95921696a4 Always call res_init() before getaddrinfo().
Unfortunately, glibc assumes that /etc/resolv.conf is a static file that
never changes. Even on servers, /etc/resolv.conf might be a dynamically
generated file, and we never know when it changes. So just call
res_init() every time, so glibc uses up-to-date nameserver information.

Conflicts:
	src/have.h
	src/net.c
	src/net_setup.c
2015-04-12 15:42:48 +02:00
Guus Sliepen
f500a3d4e6 Merge remote-tracking branch 'dechamps/windevice' into 1.1 2015-04-12 15:36:50 +02:00
Guus Sliepen
417981462a Merge remote-tracking branch 'dechamps/winmtu' into 1.1 2015-04-12 15:35:50 +02:00
Guus Sliepen
11effab85b Merge remote-tracking branch 'dechamps/fsckwin' into 1.1 2015-04-12 15:35:37 +02:00
Guus Sliepen
9e71b74ed8 Merge remote-tracking branch 'dechamps/staticfix' into 1.1 2015-04-12 15:34:50 +02:00
thorkill
0cd387fd90 This commit implements average RTT estimation based on PING-PONG between active TCP connections.
Average RTT can be used to update edge weight and propagate it to the network.
tinc dump edges has been also extended to give the current RTT.
New edge weight will change only if the config has EdgeUpdateInterval set to other value than 0.

- Ignore local configuration for editors
- Extended manpage with informations about EdgeUpdateInterval
- Added clone_edge and fixed potential segfault when b->from not defined
- Compute avg_rtt based on the time values we got back in PONG
- Add avg_rtt on dump edge
- Send current time on PING and return it on PONG
- Changed last_ping_time to struct timeval
- Extended edge_t with avg_rtt
2015-04-11 15:27:28 +02:00
thorkill
9910f8f2d1 Fixed a SIGABRT in send_ans_key().
In some cases the remote host does not know our key but we have got theirs.
So we send him our key but send_ans_key() aborted on this point.
2015-04-04 20:16:42 +02:00
thorkill
df42bc3621 Temporal fix for broken hopes. 2015-03-18 15:45:52 +01:00
thorkill
157bc90e64 Temporal fix for 'unknown source' and broken direct UDP links. 2015-03-18 14:54:45 +01:00
Etienne Dechamps
0c010ff9fe Warn about performance if using TAP-Windows >=9.21.
Testing has revealed that the newer series of Windows TAP drivers (i.e.
9.0.0.21 and later, also known as NDIS6, tap-windows6) suffer from
serious performance issues in the write path. Write operations seems to
take a very long time to complete, resulting in massive packet loss even
for throughputs as low as 10 Mbit/s.

I've made some attempts to alleviate the problem using parellelism. By
using custom code that allows up to 256 write operations at the same
time the results are much better, but it's still about 2 times worse
than the traditional 9.0.0.9 driver.

We need to investigate more and file a bug against tap-windows6, but in
the mean time, let's inform the user that he might not want to use the
latest drivers.
2015-03-15 18:37:58 +00:00
Etienne Dechamps
0f328d9d28 Log TAP-Windows driver version on startup.
This is generally useful. We've seen issues that are specific to some
version of these drivers (especially the newer 9.0.0.21 version), so
it's relevant to log it, especially since that means it will be
copy-pasted by people posting their logs asking for help.
2015-03-15 18:36:37 +00:00
Etienne Dechamps
7027bba541 Increase the ReplayWindow default from 16 to 32.
As a rule, it seems reasonable to make sure that tinc operates correctly
on at least 1G links, since these are pretty common. However, I have
observed replay window issues when operating at speeds of 600 Mbit/s and
above, especially when the receiving end is a Windows system (not sure
why). This commit increases the default so that this won't occur on
fresh setups.
2015-03-15 18:04:58 +00:00
Etienne Dechamps
94f49a163a Set the default for UDPRcvBuf and UDPSndBuf to 1M.
It may not be obvious, but due to the way tinc operates (single-threaded
control loop with no intermediate packet buffer), UDP send and receive
buffers can have a massive impact on performance. It is therefore of
paramount importance that the buffers be large enough to prevent packet
drops that could occur while tinc is processing a packet.

Leaving that value to the OS default could be reasonable if we weren't
relying on it so much. Instead, this makes performance somewhat
unpredictable.

In practice, the worst case scenario occurs on Windows, where Microsoft
had the brillant idea of making the buffers 8K in size by default, no
matter what the link speed is. Considering that 8K flies past in a
matter of microseconds on >1G links, this is extremely inappropriate. On
these systems, changing the buffer size to 1M results in *obscene*
raw throughput improvements; I have observed a 10X jump from 40 Mbit/s
to 400 Mbit/s on my system.

In this commit, we stop trusting the OS to get this right and we use a
fixed 1M value instead, which should be enough for <=1G links.
2015-03-15 18:04:55 +00:00
Etienne Dechamps
89715454c0 Fix Windows device asynchronous write behavior.
Write operations to the Windows device do not necessarily complete
immediately; in fact, with the latest TAP-Win32 drivers, this never
seems to be the case.

write_packet() does not handle that case correctly, because the
OVERLAPPED structure and the packet data go out of scope before the
write operation completes, resulting in race conditions.

This commit fixes the issue by making sure these data structures are
kept in global scope, and by dropping any packets that may arrive while
the previous write operation is still pending.
2015-03-15 10:34:40 +00:00
Etienne Dechamps
675142c7d8 When disabling the Windows device, wait for pending reads to complete.
On Windows, when disabling the device, tinc uses the CancelIo() to
cancel the pending read operation, and then proceeds to delete the event
handle immediately.

This assumes that CancelIo() blocks until the pending read request is
completely torn down and no references to it remain. While MSDN is not
completely clear on that subject, it does suggest that this is not the
case:

  http://msdn.microsoft.com/en-us/library/windows/desktop/aa363791.aspx
  If the function succeeds [...] the cancel operation for all pending
  I/O operations issued by the calling thread for the specified file
  handle was successfully requested.

This implies that cancellation was merely "requested", and that there
are no guarantees as to the state of the operation when CancelIo()
returns. Therefore, care must be taken not to close event handles
prematurely.

While I'm no aware of this potential race condition causing any problems
in practice, I don't want to take any chances.
2015-03-15 10:32:18 +00:00
Etienne Dechamps
176ee01526 Make sure packet header structures are correctly packed on Windows.
Modern versions of GCC handle structure packing differently when
compiling for Windows, as reported in the following GCC bug report:

  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991

In practice, this affects tinc because it uses packed structs as a
convenient way to populate packet headers. "struct ip" is especially
affected - on Linux, sizeof(struct ip) returns 20 as expected, while on
Windows, it returns 24 because of the broken alignment.

This in turn completely breaks code that has to populate an IP header.
Specifically, this breaks route_ipv4_unreachable() which is responsible,
among other things, for the generation of ICMP Fragmentation Needed
messages. On Windows, these messages are corrupted beyond hope because
of this alignment issue. For TCP connections that are established
before tinc obtains a fix on the MTU (and thus are not MSS clamped),
this can result in massive disruption.

This commit fixes the issue by forcing GCC to use standard alignment
for all packed structures in the tinc codebase instead of the MSVC
alignment.
2015-03-15 10:12:18 +00:00
Etienne Dechamps
43b41e9095 Fix HAVE_DECL_RES_INIT conditionals.
HAVE_DECL_RES_INIT is generated using AC_CHECK_DECLS. tinc checks this
symbol using #ifdef, which is wrong because (according to autoconf docs)
the symbol is always defined, it's just set to zero if the check failed.

This broke the Windows build starting from
0b310bf406, because it introduced this
conditional in code that's not excluded from the Windows build.
2015-03-14 16:22:26 +00:00
Etienne Dechamps
4989362300 Fix invalid getuid() call on Windows.
This is breaking the Windows build. Regression was introduced in
268e3ffca7.
2015-03-14 16:07:54 +00:00
Etienne Dechamps
fa432426df Don't send UDP probes past static relays.
Ironically, commit 0f8e2cc78c introduced
a regression on its own, since it accidently removed a return statement
that prevented try_tx_sptps() from sending UDP/MTU probes to nodes that
are past static relays.
2015-03-14 14:04:50 +00:00