Commit graph

1738 commits

Author SHA1 Message Date
Guus Sliepen
23a22ea1ce Fix compiler warnings. 2014-07-08 14:20:01 +02:00
Etienne Dechamps
163773d710 Fix event loop io tree inconsistency on Windows.
On Windows, the event loop io tree uses the Windows Event handle to
differentiate between io_t objects. Unfortunately, there is a bug in
the io_add_event() function (introduced in
2f9a1d4ab5) as it sets the event after
inserting the object into the tree, resulting in objects appearing in
io_tree out of order.

This can lead to crashes on Windows as the event loop is unable to
determine which events fired.
2014-07-06 12:43:22 +01:00
Etienne Dechamps
fcf5b53e78 Make sure myport is set correctly when running with Port = 0.
Setting the Port configuration variable to zero can be used to make tinc
listen on a system-assigned port. Unfortunately, in this scenario myport
will be zero, which means that tinc won't transmit its actual UDP
listening port to other nodes. This breaks UDP hole punching and local
discovery.
2014-07-06 10:55:23 +01:00
Etienne Dechamps
c786ed1168 Fix tinc event loop reentrancy from timeout handlers.
Commit 611217c96e introduced a regression
because it accidentally reordered the timeout handler calls and the
fdset setup code. This means that any io_add(), io_del() or io_set()
calls in timeout handlers would be ignored in the current event loop
iteration, resulting in erratic behavior.

The most visible symptom is when a metaconnection timeout occurs and the
connection is closed; the timeout handler closes the socket but it still
ends up in the select() call, typically resulting in the following
crash:

    Error while waiting for input: Bad file descriptor
2014-07-06 09:41:30 +01:00
Etienne Dechamps
d0d01a4448 Canonicalize IPv6 addresses as per RFC 5952 before printing them.
Currently we don't do any shortening on IPv6 addresses (aside from
removing trailing zeroes) before printing them. This commit makes
textual addresses smaller by shortening them according to the rules
described in RFC 5952. This is also the canonical textual representation
for IPv6 addresses, thus making them easier to compare.
2014-07-05 20:00:50 +01:00
Etienne Dechamps
dec0400714 Don't print subnet prefix lengths and weights for one-host subnets.
This commit suppresses subnet prefix length output (/xx) for subnets
that only contain one address (/32 for IPv4, /128 for IPv6). It also
suppresses weight information if the subnet is using the default
weight. This improves readability of net2str() output in the majority
of cases.
2014-07-05 20:00:50 +01:00
Etienne Dechamps
dc55691ca7 When printing MAC addresses, always use trailing zeroes.
tinc currently prints MAC addresses without trailing zeroes, for example:

    1:2:3:4:5:6

This looks weird and is inconsistent with how MAC addresses are
displayed everywhere else. This commit adds trailing zeroes, so the
above address will be printed as the following:

    01:02:03:04:05:06
2014-07-05 20:00:50 +01:00
Etienne Dechamps
3d730a40a4 Rewrite, fix and improve str2net().
This is a complete rewrite of the str2net() function. Besides
refactoring duplicate code, this new code brings the following fixes
and improvements:

 - Fixes handling of leading/trailing double colon in IPv6 addresses.
   For example, with the previous code the address
   2001:0db8:85a3:0000:0000:8a2e:0370:: is interpreted as a MAC address,
   and ::0db8:85a3:0000:0000:8a2e:0370:7334 is rejected.

 - Catches more invalid cases, such as garbage at the end of the string.

 - Adds support for dotted quad notation in IPv6 (e.g. ::1.2.3.4).

See RFC 4291, section 2.2 for details on the textual format of IPv6
addresses.
2014-07-05 20:00:50 +01:00
Etienne Dechamps
e024b7a2c5 Use git description as the tinc version.
Instead of using a 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 provides several advantages:
 - Less redundancy: git is now the source of truth for version
   information, no need to store it in the repository itself.
 - Simpler release process: just creating a git tag automatically
   updates the version. No need to change files.
 - More useful version information: 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 would 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")
2014-06-29 16:57:19 +01:00
Etienne Dechamps
aec82bb1c9 Regenerate build date and time every time tinc is built.
This prevents the date and time shown in version information from
getting stale because of partial builds. With these changes, date and
time information is written to a dedicated object file that gets rebuilt
every time make is run, even if there are no changes.
2014-06-29 16:48:57 +01:00
Etienne Dechamps
116f2ed27a Make IPv4 multicast space 224.0.0.0/4 broadcast by default.
We already do this for IPv6 multicast space (ff00::/8), so why not
extend it to IPv4.
2014-06-29 16:48:57 +01:00
Etienne Dechamps
46a5aa0d67 Make broadcast addresses configurable.
This adds a new option, BroadcastSubnet, that allows the user to
declare broadcast subnets, i.e. subnets which are considered broadcast
addresses by the tinc routing layer. Previously only the global IPv4
and IPv6 broadcast addresses were supported by virtue of being
hardcoded.

This is useful when using tinc in router mode with Ethernet virtual
devices, as it can be used to provide broadcast support for a local
broadcast address (e.g. 10.42.255.255) instead of just the global
address (255.255.255.255).

This is implemented by removing hardcoded broadcast addresses and
introducing "broadcast subnets", which are subnets with a NULL owner.
By default, behavior is unchanged; this is accomplished by adding
the global broadcast addresses for Ethernet, IPv4 and IPv6 at start
time.
2014-06-29 16:48:57 +01:00
Etienne Dechamps
b54fde6747 Implement sptps_verify_datagram().
Implementation of sptps_verify_datagram() was left as a TODO. This
causes problems when using SPTPS in tinc, because this function is
used in try_mac(), which itself is used in try_harder() to locate
nodes sending UDP packets from unexpected addresses. In the current
state this function always returns true, resulting in UDP addresses
of random nodes getting changed which makes UDP communication
fragile and unreliable. In addition, this makes UDP communication
impossible through port translation and local discovery.

This commit adds the missing implementation, thus fixing the issue.
2014-06-29 16:48:57 +01:00
Etienne Dechamps
498f1b1d58 Enable LocalDiscovery by default.
Recent improvements to the local discovery mechanism makes it cheaper,
more network-friendly, and now it cannot make things worse (as opposed
to the old mechanism). Thus there is no reason not to enable it by
default.
2014-06-29 11:24:36 +01:00
Etienne Dechamps
4159108971 Remove broadcast-based local discovery mechanism.
The new local address based local discovery mechanism is technically
superior to the old broadcast-based one. In fact, the old algorithm
can technically make things worse by e.g. sending broadcasts over the
VPN itself and then selecting the VPN address as the node's UDP
address. This cannot happen with the new mechanism.

Note that this means old nodes that don't send their local addresses in
ADD_EDGE messages can't be discovered, because there is no address to
send discovery packets to. Old nodes can still discover new nodes by
sending them broadcasts, though.
2014-06-29 11:24:36 +01:00
Etienne Dechamps
e16ade874d Use edge local addresses for local discovery.
This introduces a new way of doing local discovery: when tinc has
local address information for the recipient node, it will send local
discovery packets directly to the local address of that node, instead
of using broadcast packets.

This new way of doing local discovery provides numerous advantages compared to
using broadcasts:

 - No broadcast packets "polluting" the local network;

 - Reliable even if the sending host has multiple network interfaces (in
   contrast, broadcasts will only be sent through one unpredictable
   interface)

 - Works even if the two hosts are not on the same broadcast domain. One
   example is a large LAN where the two hosts might be on different local
   subnets. In fact, thanks to UDP hole punching this might even work if
   there is a NAT sitting in the middle of the LAN between the two nodes!

 - Sometimes a node is reachable through its "normal" address, and via a
   local subnet as well. One might think the local subnet is the best route
   to the node in this case, but more often than not it's actually worse -
   one example is where the local segment is a third party VPN running in
   parallel, or ironically it can be the local segment formed by the tinc
   VPN itself! Because this new algorithm only checks the addresses for
   which an edge is already established, it is less likely to fall into
   these traps.
2014-06-29 11:23:32 +01:00
Etienne Dechamps
bfce56d473 Add local address information to edges.
In addition to the remote address, each edge now stores the local address from
the point of view of the "from" node. This information is then made available
to other nodes through a backwards-compatible extension to ADD_EDGE messages.

This information can be used in future code to improve packet routing.
2014-06-29 11:23:14 +01:00
Guus Sliepen
762db91ef7 Give getsockopt() a reference to a socklen_t. 2014-06-28 21:54:34 +02:00
Guus Sliepen
e57daac63b Merge branch 'winevents-clean' of https://github.com/dechamps/tinc into 1.1 2014-06-28 21:49:55 +02:00
Etienne Dechamps
313a752cb5 Remove the TAP-Win32 reader thread.
tinc is using a separate thread to read from the TAP device on Windows.
The rationale was that the notification mechanism for packets arriving
on the virtual network device is based on Win32 events, and the event
loop did not support listening to these events.

Thanks to recent improvements, this event loop limitation has been
lifted. Therefore we can get rid of the separate thread and simply add
the Win32 "incoming packet" event to the event loop, just like a socket.
The result is cleaner code that's easier to reason about.
2014-06-28 20:00:05 +01:00
Etienne Dechamps
ffbc99558c Use a Windows event to stop tinc when running as a service.
Currently, when the tinc service handler callback (which runs in a
separate thread) receives a service shutdown request, it calls
event_exit() to request the event loop to exit.

This approach has a few issues:

 - The event loop will only notice the exit request when the next event
   fires. This slows down tinc service shutdown. In some extreme cases
   (DeviceStandby enabled, long PingTimeout and no connections),
   shutdown can take ages.

 - Strictly speaking, because of the absence of memory barriers, there
   is no guarantee that the event loop will even notice an exit request
   coming from another thread. I suppose marking the "running" variable
   as "volatile" is supposed to alleviate that, but it's unclear whether
   that provides any guarantees with modern systems and compilers.

This commit fixes the issue by leveraging the new event loop Windows
interface, using a custom Windows event that is manually set when
shutdown is requested.
2014-06-28 20:00:05 +01:00
Etienne Dechamps
2f9a1d4ab5 Make the event loop expose a Windows event interface.
This allows event loop users to specify Win32 events to wait on,
thus making the event loop more flexible.
2014-06-28 20:00:01 +01:00
Etienne Dechamps
611217c96e Use native Windows events for the event loop.
This commit changes the event loop to use WSAEventSelect() and
WSAWaitForMultipleEvents() on Windows. This paves the way for making the
event loop more flexible on Windows by introducing the required
infrastructure to make the event loop wait on any Win32 event.

This commit only affects the internal implementation of the event
module. Externally visible behavior remains strictly unchanged (for
now).
2014-06-28 18:45:13 +01:00
Etienne Dechamps
cc284e7c5d Fix connection event error handling.
Commit 86a99c6b99 changed the way we
handle connection events to protect against spurious event loop
callbacks. Unfortunately, it turns out that calling connect() twice on
the same socket results in different behaviors depending on the platform
(even though it seems well defined in POSIX). On Windows this resulted
in the connection handling code being unable to react to connection
errors (such as connection refused), always hitting the timeout; on
Linux this resulted in spurious error messages about connect() returning
success.

In POSIX and on Linux, using connect() on a socket where the previous
attempt failed will attempt to connect again, resulting in unnecessary
network activity. Using getsockopt(SO_ERROR) before connect() solves
that, but introduces a race condition if a connection failure happens
between the two calls.

For this reason, this commit switches from connect() to a zero-sized
send() call, which is more consistent (though not completely, see the
truth table in the comments) and simpler to use for that purpose. Note
that Windows explictly support empty send() calls; POSIX says nothing
on the subject, but testing shows it works at least on Linux.

(Surprisingly enough, Windows seems more POSIX-compliant than Linux on
this one!)
2014-06-28 14:04:43 +01:00
Etienne Dechamps
86a99c6b99 Protect against spurious connection events.
The event loop does not guarantee that spurious write I/O events do not
happen; in fact, they are guaranteed to happen on Windows when
event_flush_output() is called. Because handle_meta_io() does not check
for spurious events, a metaconnection socket might appear connected even
though it's not, and will fail immediately when sending the ID request.

This commit fixes this issue by making handle_meta_io() check the
connection status before assuming the socket is connected. It seems that
the only reliable way to do that is to try to call connect() again and
look at the error code, which will be EISCONN if the socket is
connected, or EALREADY if it's not.
2014-06-27 19:39:30 +01:00
Etienne Dechamps
0c026f3c6d Fix errno references when handling socket errors.
When using socket functions, "sockerrno" is supposed to be used to
retrieve the error code as opposed to "errno", so that it is translated
to the correct call on Windows (WSAGetLastError() - Windows does not
update errno on socket errors). Unfortunately, the use of sockerrno is
inconsistent throughout the tinc codebase, as errno is often used
incorrectly on socket-related calls.

This commit fixes these oversights, which improves socket error
handling on Windows.
2014-06-26 20:42:40 +01:00
Etienne Dechamps
058473dc8d Fix Windows includes.
These Windows include lines are capitalized, which causes the build to fail
when cross-compiling from Linux to Windows using MinGW as the MinGW headers
are entirely lower case.
2014-06-22 18:45:49 +01:00
Guus Sliepen
b24faf3cbe Remove the warnings when IP_DONTFRAGMENT/IPV6-DONTFRAG is not supported.
There is nothing we can do about it, and tinc will run fine anyway.
2014-06-22 17:22:15 +02:00
Armin Fisslthaler
e76df30cb2 reload /etc/resolv.conf in SIGALRM handler 2014-06-22 17:20:55 +02:00
Etienne Dechamps
132bdb77a0 Make DeviceStandby control network interface link status on Windows.
Besides controlling when tinc-up and tinc-down get called, this commit makes
DeviceStandby control when the virtual network interface "cable" is "plugged"
on Windows. This is more user-friendly as the status of the tinc network can
be seen just by looking at the state of the network interface, and it makes
Windows behave better when isolated.
2014-06-22 15:04:15 +01:00
Etienne Dechamps
bd451cfe15 Add DeviceStandby option to only enable the device when nodes are reachable.
This adds a new DeviceStandby option; when it is disabled (the default),
behavior is unchanged. If it is enabled, tinc-up will not be called during
tinc initialization, but will instead be deferred until the first node is
reachable, and it will be closed as soon as no nodes are reachable.

This is useful because it means the device won't be set up until we are fairly
sure there is something listening on the other side. This is more user-friendly,
as one can check on the status of the tinc network connection just by checking
the status of the network interface. Besides, it prevents the OS from thinking
it is connected to some network when it is in fact completely isolated.
2014-06-22 15:04:15 +01:00
Etienne Dechamps
f0885b8d2f Cleanly remove the device FD from the event loop before closing it. 2014-06-22 15:03:53 +01:00
Etienne Dechamps
ed1d0878af Make device close cleaner. 2014-06-22 14:01:30 +02:00
Etienne Dechamps
6382608653 Move Solaris if_fd to local scope.
This variable is never used outside of setup_device(), therefore there is no
reason to declare it in global scope.
2014-06-22 14:01:01 +02:00
Guus Sliepen
31c6899398 Unconditionally return non-zero exit code when "tinc del" does not find the requested variable. 2014-06-15 12:19:10 +02:00
Guus Sliepen
1ce0f76139 Return non-zero exit code when "tinc get" does not find the requested variable. 2014-06-15 12:14:01 +02:00
Guus Sliepen
ef5e8b6920 Fix base64 decoding of Ed25519 keys. 2014-06-03 11:02:58 +02:00
Guus Sliepen
b0d80c7f28 Allow Cipher and Digest "none".
This is for backwards compatibility with tinc 1.0, it has no effect on
the SPTPS protocol.
2014-05-18 21:51:42 +02:00
Guus Sliepen
666718998e Implement a PEM-like format for Ed25519 keys.
We don't require compatibility with any other software, but we do want Ed25519 keys to work
the same as RSA keys for now.
2014-05-18 20:49:35 +02:00
Guus Sliepen
f0e7e6b03e Rename ECDSA to Ed25519. 2014-05-18 20:47:04 +02:00
Guus Sliepen
35437a50e2 Add sanity checks when generating new RSA keys.
The key size should be a multiple of 8 bits, and it should be between 1024 and
8192 bits.
2014-05-13 20:33:20 +02:00
Guus Sliepen
66f325f467 Fix PMTU discovery via datagram SPTPS.
In send_sptps_data(), the len variable contains the length of the whole
datagram that needs to be sent to the peer, including the overhead from SPTPS
itself.
2014-05-12 15:57:40 +02:00
Guus Sliepen
c35bfa18ec Fix a crash when we have a malformed public ECDSA key of another node. 2014-05-12 15:56:29 +02:00
Guus Sliepen
c32fcdfc1d Add missing closedir(). 2014-05-12 14:35:56 +02:00
Guus Sliepen
75e5b2e906 Use void pointers to opaque buffers. 2014-05-12 14:35:12 +02:00
Guus Sliepen
332b55d472 Change AutoConnect from int to bool.
The proper value is 3, not 2 or 4, and 5 is right out. So just hardcode this value,
and only have the option to turn AutoConnect on or off.
2014-05-06 14:11:55 +02:00
Guus Sliepen
27acb5d047 Fix compiler warnings. 2014-05-06 13:01:48 +02:00
Guus Sliepen
bc33a073d8 Nexthop calculation should always use the shortest path.
When tinc runs the graph algorithms and updates the nexthop and via pointers,
it uses a breadth-first search, but it can sometimes revisit nodes that have
already been visited if the previous path is marked as being indirect, and
there is a longer path that is "direct". The via pointer should be updated in
this case, because this points to the closest hop to the destination that can
be reached directly. However, the nexthop pointer should not be updated.

This fixes a bug where there could potentially be a routing loop if a node in
the graph has an edge with the indirect flag set, and some other edge without
that flag, the indirect edge is part of the minimum spanning tree, and a
broadcast packet is being sent.
2014-05-06 12:58:25 +02:00
Saverio Proto
b6e2b416bf Fix typo in comment 2014-05-05 15:23:25 +02:00
Guus Sliepen
18698c4e12 Put brackets around IPv6 addresses in invitation URL, even if there is no port number. 2014-04-25 17:00:55 +02:00
Guus Sliepen
475088ed77 sptps_test: allow using a tun device instead of stdio. 2014-04-15 17:26:08 +02:00
Guus Sliepen
2980173ee7 Use the ChaCha-Poly1305 cipher for the SPTPS protocol.
The main reason to switch from AES-256-GCM to ChaCha-Poly1305 is to remove a
dependency on OpenSSL, whose behaviour of the AES-256-GCM decryption function
changes between versions. The source code for ChaCha-Pol1305 is small and in
the public domain, and can therefore be easily included in tinc itself.
Moreover, it is very fast even without using any optimized assembler, easily
outperforming AES-256-GCM on platforms that don't have special AES instructions
in hardware.
2014-04-14 21:43:45 +02:00
Guus Sliepen
49e3baec20 Merge branch '1.1-ed25519' into 1.1 2014-04-14 20:50:16 +02:00
Guus Sliepen
37b729d7fd Properly initialize buffers.
Valgrind complained about use of uninitialized data.
2014-04-13 12:09:48 +02:00
Guus Sliepen
2f01744f82 Use Ed25519 keys.
This uses the portable Ed25519 library made by Orson Peters, which in turn uses
the reference implementation made by Daniel J. Bernstein.

This implementation also allows Ed25519 keys to be used for key exchange, so
there is no need to add a separate implementation of Curve25519.
2014-04-06 22:47:26 +02:00
Guus Sliepen
d6734a2da4 Fix return value of b64encode(). 2014-04-06 22:46:06 +02:00
Guus Sliepen
f134bd0c9c Handle a disconnecting tincd better.
- Try to prevent SIGPIPE from being sent for errors sending to the control
  socket. We don't outright block the SIGPIPE signal because we still want the
  tinc CLI to exit when its output is actually sent to a real (broken) pipe.

- Don't call exit() from top(), and properly detect when the control socket is
  closed by the tincd.
2014-03-09 15:32:10 +01:00
Guus Sliepen
09e000ba54 Rewind the file before trying to use PEM_read_RSA_PUBKEY(). 2014-02-26 17:27:57 +01:00
Guus Sliepen
44c7f554c7 Add "network" command to list or switch networks. 2014-02-26 11:04:42 +01:00
Guus Sliepen
9f7e2dffb2 Really fix compiling under Windows. 2014-02-07 23:05:33 +01:00
Guus Sliepen
cdda0388a8 Fix compiling for Windows. 2014-02-07 21:14:41 +01:00
Guus Sliepen
06a4a8c153 Update copyright notices. 2014-02-07 20:38:48 +01:00
Guus Sliepen
ac7f82cb23 Handle errors from TAP-Win32/64 adapter in a better way.
Before, the tapreader thread would just exit immediately after encountering the
first error, without notifying the main thread. Now, the tapreader thead never
exits itself, but tells the main thread to stop when more than ten errors are
encountered in a row.
2014-02-07 19:55:31 +01:00
Guus Sliepen
e717e424c2 Use addresses learned from other nodes when making outgoing connections.
Before, when making a meta-connection to a node (either because of a ConnectTo
or because AutoConnect is set), tinc required one or more Address statements
in the corresponding host config file. However, tinc learns addresses from
other nodes that it uses for UDP connections. We can use those just as well for
TCP connections.
2014-01-30 17:10:30 +01:00
Guus Sliepen
995444c4f9 Document Weight and also allow it to be set from tinc.conf. 2014-01-29 17:32:18 +01:00
Guus Sliepen
2e318f3799 Don't ask questions if we are not running interactively.
When creating invitations or using them to join a VPN, and the tinc command is
not run interactively (ie, when stdin and stdout are not connected or
redirected to/from a file), don't ask questions. If normally tinc would ask for
a confirmation, just assume the default answer instead. If tinc really needs
some input, just print an error message instead.

In case an invitation is used for a VPN which uses a netname that is already in
use on the local host, tinc will store the configuration in a temporary
directory. Normally it asks for an alternative netname and then renames the
temporary directory, but when not run interactively, it now just prints the
location of the unchanged temporary directory.
2014-01-29 17:17:59 +01:00
Guus Sliepen
00398a60ec Add missing newlines when copying variables from tinc.conf to an invitation file. 2014-01-27 23:21:25 +01:00
Guus Sliepen
38adc8bf54 Add the ListenAddress option.
ListenAddress works the same as BindToAddress, except that from now on,
explicitly binding outgoing packets to the address of a socket is only done for
sockets specified with BindToAddress.
2014-01-20 21:19:13 +01:00
Florent Clairambault
c8543bbe6b Adding "conf.d" configuration dir support.
Any file matching the pattern /etc/tinc/$NETNAME/conf.d/*.conf will be
parsed after the tinc.conf file.
2013-12-29 23:11:54 +01:00
Guus Sliepen
53b00f8c1a Add our own autoconf check for libgcrypt.
This one doesn't require one to have libgcrypt installed while running
autoreconf, making life easier for people who compile tinc from git.
2013-12-10 11:18:04 +01:00
Guus Sliepen
ef8efdfff1 Remove erroneous warning about SPTPS being disabled. 2013-12-08 21:37:56 +01:00
Guus Sliepen
be1446f5d0 Don't print an error when no ECDSA key is known for a node using the legacy protocol. 2013-12-08 21:32:21 +01:00
Guus Sliepen
c151cfa2e9 Give full path to unconfigured tinc-up script. 2013-12-08 21:31:50 +01:00
Guus Sliepen
1b580b2a6b Allow running without ECDSA keys If ExperimentalProtocol is not explicitly set.
To make upgrading less painful, allow running tinc 1.1 without ECDSA keys
unless ExperimentalProtocol is explicitly set to yes.
2013-12-08 21:10:06 +01:00
Guus Sliepen
41583d5dcf Don't print device statistics when exiting tinc.
Much more detailed statistics are now kept per node, which can be queried at
any time, which makes the device statistics obsolete.
2013-12-08 20:23:44 +01:00
Guus Sliepen
b115de2199 Use hardcoded value for TUNNEWPPA if net/if_tun.h is missing on Solaris. 2013-12-07 22:54:02 +01:00
Guus Sliepen
cf9bea4e93 Avoid using a variable named "sun". Solaris doesn't like it. 2013-12-07 22:39:24 +01:00
Guus Sliepen
221f559bcf Stricter check for raw socket support. 2013-12-07 22:20:10 +01:00
Guus Sliepen
c1f7357e7d Include <limits.h> for PATH_MAX. 2013-12-07 22:19:39 +01:00
Guus Sliepen
c9bdac68e1 Update support for Solaris.
Adds support for the latest TAP driver from
http://www.whiteboard.ne.jp/~admin2/tuntap/, so tinc now also works in switch
mode on Solaris 11.
2013-12-07 21:52:41 +01:00
Guus Sliepen
06943e828c If no Port is specified, set myport to actual port of first listening socket.
If the Port statement is not used, there are two other ways to let tinc listen
on a non-default port: either by specifying one or more BindToAddress
statements including port numbers, or by starting it from systemd with socket
activation. Tinc announces its own port to other nodes, but before it only
announced what was set using the Port statement.
2013-12-05 15:01:30 +01:00
Guus Sliepen
51bddfd4dd Allow "none" for Cipher and Digest again. 2013-11-28 14:28:18 +01:00
Guus Sliepen
3d41e7d712 Make LocalDiscovery work for SPTPS packets. 2013-11-21 22:13:14 +01:00
Guus Sliepen
c1703ea917 Remove an unused variable. 2013-11-20 23:02:20 +01:00
Guus Sliepen
6168a9b6d5 Fix two warnings from Clang's static analyzer. 2013-11-15 15:32:53 +01:00
Guus Sliepen
29b42aa17e Fix sending bulk data starting with a newline. 2013-10-22 21:30:17 +02:00
Guus Sliepen
a5bcb29fdf Make sptps_test less verbose by default. 2013-10-22 21:19:41 +02:00
Guus Sliepen
7da999f4ae Clean up child processes from proxy type exec. 2013-10-18 16:58:47 +02:00
Guus Sliepen
9b2eaebdf6 Fix sending empty SPTPS records. 2013-10-15 14:09:42 +02:00
Guus Sliepen
0da0728088 Use AES-256-GCM for the SPTPS protocol.
It is faster than AES-256-CTR + HMAC-SHA256, especially on Intel chips with AES
and PCLMULQDQ instructions.
2013-10-13 01:02:52 +02:00
Guus Sliepen
68e3efe349 Fix segfault when Name = $HOST but $HOST is not set.
Conflicts:
	src/net_setup.c
2013-09-27 11:36:46 +02:00
Guus Sliepen
22d804d446 Link sptps_speed with -lrt.
This is necessary for clock_gettime() on older versions of libc.
2013-09-15 22:03:00 +02:00
Guus Sliepen
c621dd62c7 Don't leak memory during the key generation speed test. 2013-09-15 22:02:33 +02:00
Guus Sliepen
b7b68c3e97 Add a benchmark for the SPTPS protocol. 2013-09-15 17:35:55 +02:00
Guus Sliepen
87b017c710 Avoid using BIOs. 2013-09-15 16:21:25 +02:00
Guus Sliepen
e11daa2646 Don't try to mkdir(CONFDIR) if --config is used. 2013-09-08 15:03:06 +02:00
Guus Sliepen
fe1d0043c8 Don't return zero-length packets when receiving multicast loopback packets. 2013-09-05 17:41:05 +02:00
Guus Sliepen
6242b68242 Fix multicast device. 2013-09-05 14:51:13 +02:00
Guus Sliepen
09b5a3c020 Exit value 1 instead of a random non-zero value. 2013-09-05 14:50:10 +02:00
Guus Sliepen
796c14b75c Slightly relax the connection rate limit for a single address.
The restriction of accepting only 1 connection per second from a single address
is a bit too much, especially if one wants to join a VPN using an invitation,
which requires two connections.
2013-09-02 00:11:04 +02:00
Guus Sliepen
933f7f7526 Send a RELOAD to a running tincd when a new invitation key has been generated. 2013-09-01 22:59:51 +02:00
Guus Sliepen
09cd7ac62a Make sptps_test more easy to work with.
It now defers reading from stdin until after the authentication phase is
completed.  Furthermore, it supports the -q, -r, -w options similar to those of
Jürgen Nickelsen's socket.
2013-09-01 16:02:49 +02:00
Guus Sliepen
d01ab07f78 Allow testing the replay window with sptps_test. 2013-08-30 14:23:02 +02:00
Guus Sliepen
ccbf70b66f Fix the replay window in SPTPS. 2013-08-30 14:22:05 +02:00
Guus Sliepen
c7752ca73e Fix CTR mode. 2013-08-30 13:43:23 +02:00
Guus Sliepen
d0aa0817d2 Add an option to test datagram SPTPS with packet loss. 2013-08-30 13:04:14 +02:00
Guus Sliepen
5da0ebd421 When generating invitations, handle any order of Port and Adress statements. 2013-08-28 14:24:07 +02:00
Guus Sliepen
f0e11cd2c5 Call WSAStartup() in main().
The tinc utility defered calling WSAStartup() until it tried to connect to a
running tinc daemon. However, socket functions are now also used for other
things (like joining another VPN using an invitation). Now we just
unconditionally call WSAStartup() early in main().
2013-08-27 21:19:50 +02:00
Guus Sliepen
82575bd44d Tell invited node about Mode and Broadcast settings.
Since these settings really should be the same for all nodes in a VPN.
2013-08-24 00:48:24 +02:00
Guus Sliepen
57991e2642 Use PATHEXT when checking for the presence of scripts on Windows.
It seems like a lot of overhead to call access() for every possible extension
defined in PATHEXT, but apparently this is what Windows does itself too. At
least this avoids calling system() when the script one is looking for does not
exist at all.

Since the tinc utility also needs to call scripts, execute_script() is now
split off into its own source file.
2013-08-23 21:23:46 +02:00
Guus Sliepen
21184674b3 Execute scripts when invitations are created or accepted. 2013-08-21 00:24:55 +02:00
Guus Sliepen
9699f08afc Ensure the invitation filenames do not reveal the secret cookie.
Since filenames could potentially leak to unprivileged users (for example,
because of locatedb), it should not contain the cookie used for invitations.
Instead, tinc now uses the hash of the cookie and the invitation key as the
filename to store pending invitations in.
2013-08-20 23:09:36 +02:00
Guus Sliepen
5dec1c2571 Let a server explicitly send a notification when the invitation protocol succeeded. 2013-08-20 22:36:31 +02:00
Guus Sliepen
c798f73093 Use our own infrastructure for finding out the local node's externally visible host name. 2013-08-20 22:18:01 +02:00
Guus Sliepen
160b7cb5e3 Resolve the local host name before generating the invitation file. 2013-08-20 16:47:07 +02:00
Guus Sliepen
65f5e8fba4 Bind outgoing sockets again.
Commit cff5a84 removed the feature of binding outgoing TCP sockets to a local
address. We now call bind() again, but only if there is exactly one listening
socket with the same address family as the destination address of the outgoing
socket.
2013-08-18 23:55:40 +02:00
Guus Sliepen
0c54f36553 Remove broadcast of KEY_CHANGED message during tinc's initialization. 2013-08-18 22:43:55 +02:00
Guus Sliepen
09b0b49b98 Fix order of tincd's initialization.
The order in which tinc initialized things was not completely correct. Now, it
is done as follows:

- Load and parse configuration files.
- Create all TCP and UDP listening sockets.
- Create PID file and UNIX socket.
- Run the tinc-up script.
- Drop privileges.
- Start outgoing connections.
- Run the main loop.

The PID file can only be created correctly if the listening sockets have been
set up ,as it includes the address and port of the first listening socket. The
tinc-up script has to be run after the PID file and UNIX socket have been
created so it can change their permissions if necessary. Outgoing connections
should only be started right before the main loop, because this is not really
part of the initialization.
2013-08-18 22:35:27 +02:00
Guus Sliepen
8f84244458 Don't force a .bat extension for scripts under Windows. 2013-08-18 18:20:41 +02:00
Guus Sliepen
b180c1af99 Create UNIX socket at the same time as the PID file is created.
The PID file was created before tinc-up was called, but the UNIX socket was
created afterwards, which meant one could not change the UNIX socket's owner or
permissions from the tinc-up script.
2013-08-18 17:02:49 +02:00
Guus Sliepen
5e50a56dd9 Stop using EXTRA_DIST in src/Makefile.am.
Automake finds the files in the subdirectories of src/ now that they are
properly declared in the _SOURCES variables. Using EXTRA_DIST would now cause
.o files to be included in the tarball.
2013-08-14 16:17:12 +02:00
Guus Sliepen
6aa864baa6 Don't typedef the same struct in two header files.
Some (older?) versions of GCC don't like this.
2013-08-13 20:40:40 +02:00
Guus Sliepen
5e00a24e1f Update copyright notices. 2013-08-13 20:38:57 +02:00
Guus Sliepen
2df534808d Move .h files from noinst_HEADERS to tincd_SOURCES.
This is the recommended way according to the Automake manual.
2013-08-13 20:35:48 +02:00
Guus Sliepen
de8e6bf452 Don't echo broadcast packets back when Broadcast = direct. 2013-08-08 17:40:15 +02:00
Guus Sliepen
81c7120320 Fix a typo. 2013-08-02 23:51:55 +02:00
Guus Sliepen
76c90e1639 Non-zero exit code when reloading config file fails after SIGHUP.
When reloading the configuration file via the tinc command, the user will get
an error message if reloading has failed. However, no such warning exists when
sending a HUP signal. Previously, tincd would exit in both cases, but with a
zero exit code. Now it will exit with code 1 when reloading fails after a
SIGHUP, but tincd will keep running if it is signaled via the tinc command.
Instead, the tinc command will exit with a non-zero exit code.
2013-08-02 23:50:44 +02:00
Guus Sliepen
f3a2bed063 Really retry outgoing connections immediately if requested.
The retry() function would only abort connections that were in progress of
being made, it wouldn't reschedule the outgoing connections that had been
sleeping.
2013-08-02 20:53:54 +02:00
Guus Sliepen
1e7d1cd3c7 Clean up the SIGINT handler. 2013-08-02 20:50:19 +02:00
Guus Sliepen
a38e0d6213 Use umask() to set file and UNIX socket permissions without race conditions.
As mentioned by Erik Tews, calling fchmod() after fopen() leaves a small window
for exploits. As long as tinc is single-threaded, we can use umask() instead to
reduce file permissions. This also works when creating the AF_UNIX control socket.

The umask of the user running tinc(d) is used for most files, except for the
private keys, invitation files, PID file and control socket.
2013-08-02 19:28:34 +02:00
Guus Sliepen
a1f4f14c6c Defer handling netname conflicts when accepting an invitation.
In case no explicit netname of configuration directory is specified when
accepting an invitation, the netname specified in the invitation data is
used. However, this new netname is only known after making the connection
to the server. If the new netname conflicts with an existing one at the
client, we ask the user for a netname that doesn't conflict. However, we
should first finish accepting the invitation, so we don't run into the
problem that the server times out and cancels the invitation. So, we create
a random netname and store the files there, and only after we finish
accepting the invitation we ask the user for a better netname, and then
just rename the temporary directory to the final name.
2013-07-26 15:48:52 +02:00
Guus Sliepen
d47c79533f Make absolutely sure we can write config files before accepting an invitation. 2013-07-26 15:44:05 +02:00
Guus Sliepen
37cca72e6c Choose a different Port when 655 isn't available when doing "tinc join". 2013-07-26 14:53:36 +02:00
Guus Sliepen
8f2db4afdd Choose a different Port when 655 isn't available when doing "tinc init".
If port 655 cannot be bound to when using the init command, tinc will try to
find a random port number that can be bound to, and will add the appropriate
Port variable to its host config file. A warning will be printed as well.
2013-07-26 14:17:15 +02:00
Guus Sliepen
d6a67266c8 Don't forget the Port variable when creating an invitation URL. 2013-07-25 17:30:47 +02:00
Guus Sliepen
d1e01bc880 Allow control-C to stop tincd without stopping the tinc shell. 2013-07-25 17:30:47 +02:00
Guus Sliepen
d219fe2c09 Warn when incorrect use of add or set causes variables to be removed. 2013-07-25 17:30:47 +02:00
Guus Sliepen
e624969568 Fix compression when using the SPTPS protocol. 2013-07-24 20:48:31 +02:00
Guus Sliepen
5fca595b80 Honour umask, let temporary key files inherit original's permissions.
During the init command, tinc changed the umask to 077 when writing the public
and private key files, to prevent the temporary copies from being world
readable. However, subsequently created files would therefore also be
unreadable for others. Now we don't change the umask anymore, therefore
allowing the user to choose whether the files are world readable or not by
setting the umask as desired. The private key files are still made unreadable
for others of course. Temporary files now inherit the permissions of the
original, and the tinc-up script's permissions now also honour the umask.
2013-07-22 23:05:07 +02:00
Etienne Dechamps
ae85a02030 Further improve bandwidth estimation for type 2 MTU probe replies.
This patch adds timestamp information to type 2 MTU probe replies. This
timestamp can then be used by the recipient to estimate bandwidth more
accurately, as jitter in the RX direction won't affect the results.
2013-07-22 21:25:44 +01:00
Etienne Dechamps
e3c763eae8 Introduce lightweight PMTU probe replies.
When replying to a PMTU probe, tinc sends a packet with the same length
as the PMTU probe itself, which is usually large (~1450 bytes). This is
not necessary: the other node wants to know the size of the PMTU probes
that have been received, but encoding this information as the actual
reply length is probably the most inefficient way to do it. It doubles
the bandwidth usage of the PMTU discovery process, and makes it less
reliable since large packets are more likely to be dropped.

This patch introduces a new PMTU probe reply type, encoded as type "2"
in the first byte of the packet, that indicates that the length of the
PMTU probe that is being replied to is encoded in the next two bytes of
the packet. Thus reply packets are only 3 bytes long.

(This also protects against very broken networks that drop very small
packets - yes, I've seen it happen on a subnet of a national ISP - in
such a case the PMTU probe replies will be dropped, and tinc won't
enable UDP communication, which is a good thing.)

Because legacy nodes won't understand type 2 probe replies, the minor
protocol number is bumped to 3.

Note that this also improves bandwidth estimation, as it is able to
measure bandwidth in both directions independently (the node receiving
the replies is measuring in the TX direction) and the use of smaller
reply packets might decrease the influence of jitter.
2013-07-22 21:25:37 +01:00
Etienne Dechamps
e3a4672afb Disable PMTU discovery when TCPOnly is set.
Obviously, PMTU discovery doesn't make much sense when we know we'll be
using TCP anyway.
2013-07-21 00:36:28 +02:00
Guus Sliepen
b03bbaa385 Allow extra options to be passed to "tinc restart" again. 2013-07-21 00:20:54 +02:00
Guus Sliepen
e82bec6670 Forbid protocol version rollback.
When we know a node's ECDSA key, we only allow communication via the SPTPS
protocol.
2013-07-21 00:13:38 +02:00
Etienne Dechamps
51c1639884 Fix hash_function().
The hashing function that tinc uses is currently broken as it only looks
at the first 4 bytes of data.

This leads to interesting bugs, like the node UDP address cache being
subtly broken because two addresses with the same protocol and port (but
not the same IP address) will override each other. This is because
the first four bytes of sockaddr_in contains the IP protocol and port,
while the IP address itself is contained in the four remaining bytes
that are never used when the hash is computed.
2013-07-20 23:31:19 +02:00
Guus Sliepen
1828908148 Don't use vasprintf() anymore on Windows.
Windows doesn't actually support it, but MinGW provides it. However, with some versions of
MinGW it doesn't work correctly. Instead, we vsnprintf() to a local buffer and xstrdup() the
results.
2013-07-17 18:06:56 +02:00
Guus Sliepen
54127996ca Don't search in local directories for include files.
Tinc's source code doesn't rely on this anymore, and this gets rid of potential conflicts with
system headers.
2013-07-17 18:02:07 +02:00
Guus Sliepen
fb1e69072e Add missing definitions on Windows. 2013-07-17 18:00:40 +02:00
Guus Sliepen
918067f117 Fix warning "Both netname and configuration directory given" on Windows. 2013-07-15 14:48:43 +02:00
Etienne Dechamps
633b7cbb45 Fix combination of Mode = router and DeviceType = tap on Linux.
I believe I have found a bug in tinc on Linux when it is used with
Mode = router and DeviceType = tap. This combination is useful because
it allows global broadcast packets to be used in router mode. However,
when tinc receives a packet in this situation, it needs to make sure its
destination MAC address matches the address of the TAP adapter, which is
typically not the case since the sending node doesn't know the MAC
address of the recipient. Unfortunately, this is not the case on Linux,
which breaks connectivity.
2013-07-15 00:28:35 +02:00