Commit graph

2665 commits

Author SHA1 Message Date
Guus Sliepen
d8a3a182de Fix src/Makefile.am for *BSD.
Apparently the BSDs don't like $(srcdir) but want to see ${srcdir} in
their rules.
2015-05-19 14:09:53 +02:00
Guus Sliepen
96a323e16a Remove info-in-builddir option from AM_INIT_AUTOMAKE().
This option is not supported by older, but still widely used versions of
automake. The drawback is that when doing multiple VPATH builds in a
row, the info manual may mention incorrect paths, but it doesn't affect
the executables at all.
2015-05-19 13:31:26 +02:00
Sven-Haegar Koch
51b5aab9b0 Fix check for public key in invite-join.test.
Small fix to test/invite-join.test, comparing no-longer-existing
ECDSAPublicKey does not make sense.
2015-05-19 13:30:42 +02:00
Etienne Dechamps
a196e9b0fd Fix direct UDP communciation with pre-relaying 1.1 nodes.
try_tx_sptps() gives up on UDP communication if the recipient doesn't
support relaying. This is too restrictive - we only need the other node
to support relaying if we actually want to relay through them. If the
packet is sent directly, it's fine to send it to an old pre-node-IDs
tinc-1.1 node.
2015-05-18 21:08:43 +01:00
Etienne Dechamps
fef29d0193 Don't parse node IDs if the sending node doesn't support them.
Currently, tinc tries to parse node IDs for all SPTPS packets, including
ones sent from older, pre-node-IDs tinc-1.1 nodes, and therefore doesn't
recognize packets from these nodes. This commit fixes that.

It also makes code slightly clearer by reducing the amount of fiddling
around packet offset/length.
2015-05-18 20:56:16 +01:00
Etienne Dechamps
643149b449 Fix SPTPS condition in try_harder().
A condition in try_harder() is always evaluating to false when talking
to a SPTPS node because n->status.validkey_in is always false in that
case. Fix the condition so that the SPTPS status is correctly checked.

This prevented recent tinc-1.1 nodes from talking to older, pre-node-ID
tinc-1.1 nodes.

The regression was introduced in
6056f1c13b.
2015-05-18 20:38:01 +01:00
Etienne Dechamps
01d2519862 Don't pollute the system header directory namespace.
Since commit 13f9bc1ff1, tinc passes the
-I. option to the preprocessor so that version_git.h can be found during
out-of-tree ("VPATH") builds.

The problem is, this option also affects the directory search for files
included *from* system headers. For example, on MinGW, unistd.h contains
the following line:

  #include <process.h>

Which, due to -I. putting the tinc directory at the head of the search
order, results in tinc's process.h being included instead of the file
from MinGW. Hilarity ensues.

This commit fixes the issue by using -iquote, which doesn't affect
system headers.
2015-05-17 22:40:48 +01:00
Etienne Dechamps
c1154bf696 Make sure the MIN() macro is defined.
On MinGW this is not automatically the case, thereby breaking the build.
2015-05-17 22:21:11 +01:00
thorkill
23eff91634 resolved conflict 2015-05-17 23:13:43 +02:00
thorkill
b1aefcd8d0 extended logging in sptps 2015-05-17 23:12:27 +02:00
Guus Sliepen
5c32bd1578 Merge remote-tracking branches 'dechamps/sptpsrestart' and 'dechamps/keychanged' into 1.1 2015-05-17 21:07:45 +02:00
Etienne Dechamps
2cb216d83d Don't send KEY_CHANGED messages if we don't support the legacy protocol.
KEY_CHANGED messages are only useful to invalidate keys for non-SPTPS nodes;
SPTPS nodes use a different internal mechanism (forced KEX) for that purpose.
Therefore, if we know we can't talk to legacy nodes, there's no point in
sending them these messages.
2015-05-17 19:27:20 +01:00
Etienne Dechamps
1a7a9078c0 Proactively restart the SPTPS tunnel if we get receive errors.
There are a number of ways a SPTPS tunnel can get into a corrupt state.
For example, during key regeneration, the KEX and SIG messages from
other nodes might arrive out of order, which confuses the hell out of
the SPTPS code. Another possible scenario is not noticing another node
crashed and restarted because there was no point in time where the node
was seen completely disconnected from *all* nodes; this could result in
using the wrong (old) key. There are probably other scenarios which have
not even been considered yet. Distributed systems are hard.

When SPTPS got confused by a packet, it used to crash the entire
process; fortunately that was fixed by commit
2e7f68ad2b. However, the error handling
(or lack thereof) leaves a lot to be desired. Currently, when SPTPS
encounters an error when receiving a packet, it just shrugs it off and
continues as if nothing happened. The problem is, sometimes getting
receive errors mean the tunnel is completely stuck and will not recover
on its own. In that case, the node will become unreachable - possibly
indefinitely.

The goal of this commit is to improve SPTPS error handling by taking
proactive action when an incoming packet triggers a failure, which is
often an indicator that the tunnel is stuck in some way. When that
happens, we simply restart SPTPS entirely, which should make the tunnel
recover quickly.

To prevent "storms" where two buggy nodes flood each other with invalid
packets and therefore spend all their time negotiating new tunnels, we
limit the frequency at which tunnel restarts happen to ten seconds.

It is likely this commit will solve the "Invalid KEX record length
during key regeneration" issue that has been seen in the wild. It is
difficult to be sure though because we do not have a full understanding
of all the possible conditions that can trigger this problem.
2015-05-17 19:21:50 +01:00
Etienne Dechamps
aa52300b2b Trivial: make sptps_receive_data_datagram() a little more readable.
The new code updates variables as stuff is being consumed, so that the
reader doesn't have to do that in his head.
2015-05-17 17:52:15 +01:00
Guus Sliepen
30e839b0a1 Don't send local_address in ADD_EDGE messages if it's AF_UNSPEC. 2015-05-17 18:44:09 +02:00
Sven-Haegar Koch
23fda4db6d Let sockaddr2hostname() handle AF_UNSPEC addresses. 2015-05-17 18:43:34 +02:00
Etienne Dechamps
1e89a63f16 Prevent SPTPS key regeneration packets from entering an UDP relay path.
Commit 10c1f60c64 introduced a mechanism
by which a packet received by REQ_KEY could continue its journey over
UDP. This was based on the assumption that REQ_KEY messages would never
be used for handshake packets (which should never be sent over UDP,
because SPTPS currently doesn't handle lost handshake packets very
well).

Unfortunately, there is one case where handshake packets are sent using
REQ_KEY: when regenerating the SPTPS key for a pre-established channel.
With the current code, such packets risk getting relayed over UDP.

When processing a REQ_KEY message, it is impossible for the receiving
end to distinguish between a data SPTPS packet and a handshake packet,
because this information is stored in the type field which is encrypted
with the end-to-end key.

This commit fixes the issue by making tinc use ANS_KEY for all SPTPS
handshake messages. This works because ANS_KEY messages are never
forwarded using the SPTPS relay mechanisms, therefore they are
guaranteed to stick to TCP.
2015-05-17 17:09:56 +01:00
thorkill
69c0a5fe66 fixed conflict on src/net_packet.c 2015-05-17 00:27:21 +02:00
Guus Sliepen
eecfeadeb4 Let sockaddr2str() handle AF_UNSPEC addresses. 2015-05-16 02:01:54 +02:00
Guus Sliepen
613c121cdc Try all addresses for the hostname in an invitation URL. 2015-05-15 23:35:46 +02:00
Guus Sliepen
54a8bd78e3 Be more liberal accepting ADD_EDGE messages with conflicting local address information.
If the ADD_EDGE is for one of the edges we own, and if it is not the
same as we actually have, send a correcting ADD_EDGE back. Otherwise, if
the ADD_EDGE contains new information, update our idea of the local
address for that edge.

If the ADD_EDGE does not contain local address information, then we
never make a correction nor log a warning.
2015-05-15 23:08:53 +02:00
Guus Sliepen
8028e01100 Use AF_UNSPEC instead of AF_UNKNOWN for unspecified local address in add_edge_h().
AF_UNKNOWN is reserved for valid addresses that the local node cannot
parse, but remote nodes possibly can.
2015-05-15 23:01:06 +02:00
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