Commit graph

2277 commits

Author SHA1 Message Date
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
thorkill
f75e6f61f2 Do not access e->to->prevedge if not defined
In some cases - mostly when e->to == myself the prevedge is set to NULL,
causing invalid memory access. In rare cases this may lead to malformed mst
or segfaults.
2015-07-19 22:33:43 +02:00
thorkill
6dbcd4eb3d Do not access e->to->prevedge if not defined
In some cases - mostly when e->to == myself the prevedge is set to NULL,
causing invalid memory access. In rare cases this may lead to malformed mst
or segfaults.
2015-07-19 18:54:08 +02:00
thorkill
bc747f8146 Merged changes with origin/1.1 2015-07-17 15:36:00 +02:00
thorkill
b68eaa7ce4 merged with origin/1.1 2015-07-17 00:29:46 +02:00
thorkill
bf35e29e48 Changed log level 2015-07-14 14:29:44 +02:00
thorkill
3a99a76fa5 Do not forward multicast packets to prevent packet loops 2015-07-14 12:13:15 +02:00
thorkill
e282ed443f Define proper multicast subnets 2015-07-14 12:13:09 +02:00
Guus Sliepen
9ca1750245 Fix the PRF function when compiling without OpenSSL. 2015-07-12 16:31:32 +02:00
thorkill
3c54765bcd Prevent tinc from forgeting e->local_address
If ADD_EDGE came from tinc version 1.0.x local_address.sa.sa_family is set to 0.
If it came from tinc version 1.1.x forwarded for older verion it will be 255 - AF_UNKNOWN.
2015-07-12 13:32:38 +02:00
thorkill
1e7ef38198 Make sure we do not allocate new edge when talking to old nodes and the same edge already exists
When tinc gets ADD_EDGE from older versions it will allocate
new edge in protocol_edge.c:189 due to missed case in lines 149-171 where
local_address is not defined.
2015-07-12 13:31:07 +02:00
Guus Sliepen
7b831804aa Make subnet caches static. 2015-07-12 13:08:34 +02:00
thorkill
322ffadac4 Included missing names.h 2015-07-12 13:06:38 +02:00
Guus Sliepen
97457716d7 Remove unused code that caused warnings about an uninitialized variable. 2015-07-12 12:55:13 +02:00
thorkill
b22b9d4389 Removed double break; 2015-07-12 12:39:36 +02:00
Guus Sliepen
b396585383 Fix undefined behaviour when left-shifting signed integers.
Found by -fsanitize=undefined.
2015-07-12 12:33:07 +02:00
thorkill
ce1c957e87 Added information about current node in tinc's top
The information is of grate value when monitoring multiple
nodes in one window. Without it the user is forced to quit top, exit tinc
and go back to shell to refresh his memory about which node is in
what window.
2015-07-10 23:57:20 +02:00
thorkill
970283c148 Still working on ConnectTo outgoing connections 2015-07-10 02:18:06 +02:00
thorkill
85bf50612b Fixed typo in if statement 2015-07-10 02:05:22 +02:00
thorkill
6c6675e72a Do not cancel outgoing reconnects to nodes defined with ConnectTo 2015-07-10 02:01:06 +02:00
thorkill
76d278a5c0 Set keep_it flag on outgoing connections which are set by ConnectTo 2015-07-10 01:44:49 +02:00
thorkill
606948116d Do not disconnect random hosts which are explicit set with ConnectTo 2015-07-10 01:43:24 +02:00
thorkill
bdab2e15f6 Make changes to edge more verbose 2015-07-10 01:09:51 +02:00
thorkill
ab3c7dded0 Yet another attempt to make edge update work as expected 2015-07-10 00:48:41 +02:00
thorkill
c18771a96d Make informative logs about edge changes 2015-07-09 23:49:52 +02:00
thorkill
f93352b095 Prevent packet loops when ICMP6 router solicitation packets are sent to tinc device
When tincd setups it's network device some operating systems send router
solicitation packets from local scope ip addresses. tincd forwards it
then to his neighbors then those nodes follow the same routine fowarding it
to the next hops. I may happen that an loop will occur consuming large amount
of bandwith. Constrains: Mode = Router, Broadcast = mst.

Reproduction: ping6 -c 1  ff02::2%<tincd interface>
Sending one packet will, depending on your setup, generate about 3k packets.

Proposed solution in this commit: enable StrictSubnets, tincd will reject such
packets due to unknown subnet.

Future work: check scope of the ip address and make decisions about forwarding
based on Mode tincd is configured to work.
2015-07-09 22:19:26 +02:00
thorkill
49cc329cf9 Reverted changes on EDGE_ADD update if weight differs 2015-07-09 17:33:17 +02:00
thorkill
0c30f9f0f1 Revert "Forward edge information"
This reverts commit 24af5b94a7.
2015-07-09 17:16:07 +02:00
thorkill
24af5b94a7 Forward edge information 2015-07-09 17:09:35 +02:00
thorkill
5cb5ab3412 Fix memory leak in setup_outgoing_connection
Do not allocate new configuration for outgoing connection if it's already initialized.
2015-07-09 01:04:57 +02:00
thorkill
1f2e14df8c merged with thkr-1.1-fix-0004 2015-07-08 00:44:08 +02:00
thorkill
5f6613e36f Attempt to fix the heap-use-after-free error in mst_kruskal
For some reason the edges ware removed in one direction resulting in e->reverse
point into invalid memory.

Do not insert edge into edge_weight_tree if not needed.
2015-07-08 00:36:22 +02:00
thorkill
06d4eac9ac Prevent tinc from forgeting e->local_address
If ADD_EDGE came from tinc version 1.0.x local_address.sa.sa_family is set to 0.
If it came from tinc version 1.1.x forwarded for older verion it will be 255 - AF_UNKNOWN.
2015-07-07 23:51:56 +02:00
thorkill
5ae403f9e6 Make sure we do not allocate new edge when talking to old nodes and the same edge already exists
When tinc gets ADD_EDGE from older versions it will allocate
new edge in protocol_edge.c:189 due to missed case in lines 149-171 where
local_address is not defined.
2015-07-07 23:51:43 +02:00
thorkill
de8b7a8dfb Prevent tinc from forgeting e->local_address
If ADD_EDGE came from tinc version 1.0.x local_address.sa.sa_family is set to 0.
If it came from tinc version 1.1.x forwarded for older verion it will be 255 - AF_UNKNOWN.
2015-07-07 23:14:08 +02:00
thorkill
e0d14e978f Make sure we do not allocate new edge when talking to old nodes and the same edge already exists
When tinc gets ADD_EDGE from older versions it will allocate
new edge in protocol_edge.c:189 due to missed case in lines 149-171 where
local_address is not defined.
2015-07-07 21:19:26 +02:00
thorkill
80ccfb2894 Update weight if needed at the beginning 2015-07-07 20:50:53 +02:00
thorkill
78d0342a12 Update weight on reverse edge too 2015-07-07 20:49:16 +02:00
thorkill
0c334bb077 Do not insert edge into edge_weight_tree if not needed 2015-07-07 20:37:17 +02:00
thorkill
bb3fd0a985 Make usage of weight 2015-07-07 20:35:52 +02:00
thorkill
d49fd87dbc Attempt to fix the heap-use-after-free error in mst_kruskal
For some reason the edges ware removed in one direction resulting in e->reverse
point into invalid memory.
2015-07-07 00:05:58 +02:00
thorkill
77eac310c5 Revert "Set edge->reverse to NULL before we free it"
This reverts commit eda9f0ea8e.
2015-07-06 01:54:01 +02:00
thorkill
8dcd2a9995 Do not delete edges which differ only by weight
Added special case where we get weight update from other node.
Previous version called edge_del() which caused segmentation
faults in mst_kruskal.
2015-07-06 01:52:40 +02:00
thorkill
38c42fb973 Move the edge weight update handling to edge.c 2015-07-06 01:50:31 +02:00
thorkill
7c85db5421 Introducing new function for edge weight update 2015-07-06 01:49:45 +02:00
thorkill
b7820caf03 removed edge_clone() 2015-07-06 01:49:03 +02:00
thorkill
eda9f0ea8e Set edge->reverse to NULL before we free it 2015-07-06 01:04:11 +02:00
thorkill
e51dd1b196 Changed the name of edge from node to oldnode 2015-07-06 00:42:59 +02:00
thorkill
7dc8c736bc list_each shadowed node
move it into the loop
2015-07-05 22:32:32 +02:00
thorkill
841ca358e0 Forgot to set node->data 2015-07-05 21:58:27 +02:00
thorkill
25ad32d206 Use usage of splay_node_t 2015-07-05 21:41:49 +02:00
thorkill
bebe8e6808 Fixed edge->reverse corruption resulting in a segfault in graph()
Thanks to Guus for helping us with this one.
2015-07-05 20:54:32 +02:00
thorkill
82706970cf Removed unused declaration in bind_to_intercface() 2015-07-05 00:32:11 +02:00
thorkill
614a03c886 Do not try to zero memory on unitialized hash 2015-07-05 00:31:39 +02:00
thorkill
aea7938f19 Added sanity check in test in sssp_bfs() 2015-07-05 00:31:01 +02:00
thorkill
837469c747 Add small jitter to keyexpire_handle and edgeupdate_handler 2015-07-05 00:16:02 +02:00
thorkill
d172f2db29 Merge with guus patch for exit_edges() 2015-07-05 00:15:04 +02:00
thorkill
aa9994e49e Cleanup after merge 2015-07-04 18:52:16 +02:00
thorkill
dc5491a59e Merge branch '1.1' of github.com:gsliepen/tinc into thkr-1.1-ponyhof 2015-07-04 18:45:43 +02:00
Guus Sliepen
de7d9ee437 Call sockaddrfree(&e->local_address) in free_edge() instead of exit_edges().
The proper place to clean up resources of objects is in their
destructor. This makes sure proper cleanup when edge_del() is called as
well. At exit, free_edge() is called on all edges by free_edge_tree(),
which is called by exit_nodes().
2015-07-04 17:53:11 +02:00
Guus Sliepen
36cec9af88 Coalesce two if statements that check for the same thing. 2015-07-04 17:51:05 +02:00
Jo-Philipp Wich
14ccf50954 fix musl compatibility
Let configure include sys/if_tun.h when testing for netinet/if_ether.h
to detect the Kernel/libc header conflict on musl.

After this patch, configure will correctly detect netinet/if_ether.h as
unusable and the subsequent compilation will not attempt to use it.

Conflicts:
	src/have.h
2015-07-04 17:34:37 +02:00
Guus Sliepen
37588b8d5c Don't #include OpenSSL headers when compiling without OpenSSL. 2015-07-04 17:34:31 +02:00
thorkill
abb24e9d71 Cleanup local_address in protocol_edge.c
In line 131 local_address has been defined,
but the memory was never freed on return.
2015-07-04 03:24:13 +02:00
thorkill
92df36a610 Cleanup edges stored in edge_weight_tree on exit
protocol_edge.c: 131 defines local_address using str2sockaddr

str2sockaddr() allocates memory which has to be freed on exit.
2015-07-04 03:24:05 +02:00
thorkill
1140ca6d30 Fixed 2 leaks in setup_myself() 2015-07-04 03:23:58 +02:00
thorkill
e3ae318059 Cleanup local_address in protocol_edge.c
In line 131 local_address has been defined,
but the memory was never freed on return.
2015-07-04 03:21:01 +02:00
thorkill
d08c7cf4cf Cleanup edges stored in edge_weight_tree on exit
protocol_edge.c: 131 defines local_address using str2sockaddr

str2sockaddr() allocates memory which has to be freed on exit.
2015-07-04 02:39:12 +02:00
thorkill
6efd3ff302 Fixed 2 leaks in setup_myself() 2015-07-04 00:29:36 +02:00
thorkill
94703cdfa9 getopt.c fixes for unitialized parameters on FreeBSD 2015-07-02 21:48:15 +02:00
thorkill
ad58c0f65d Revert "Marked missing parameters in getopt.c on FreeBSD"
This reverts commit 5bba2cc066.
2015-07-02 21:45:43 +02:00
thorkill
5bba2cc066 Marked missing parameters in getopt.c on FreeBSD 2015-07-02 21:42:44 +02:00
thorkill
3f4855587c Marked unused parameter in net_socket.c
Found by clang on FreeBSD
2015-07-02 21:39:07 +02:00
thorkill
d2e038ab24 Makred unused parameter in net_packet.c
Found by clang -Wunused-parameter on FreeBSD
2015-07-02 21:37:33 +02:00
Florian Klink
0267aef826 setup_outgoing_connection: log to LOG_DEBUG on if no known address
With AutoConnect = yes, tinc tries to establish connections to known hosts.
However, you could have set no Address for this host, which is perfectly fine
(as long as there is at least one bootstrap node with an address or a local
discovered node already part of the network)

So log this to LOG_DEBUG
2015-07-02 21:22:53 +02:00
Florian Klink
91355b9ac5 (read|append)_config_file: log open errors as LOG_DEBUG
In a "decentrally managed vpn" it is very likely that host config
files for some reachable nodes do not exist. Currently, tinc
fills the logs with "Cannot open config file" messages.

This commit changes the log level to LOG_DEBUG so
syslog doesn't get filled by default.
2015-07-02 21:22:47 +02:00
thorkill
743671278f Attempt to track an segfault in mst_kruskal()
(gdb) bt
#0  mst_kruskal () at graph.c:107
#1  graph () at graph.c:302
#2  0x00007ffff7b509fe in del_edge_h (c=<optimized out>, request=<optimized out>) at protocol_edge.c:292
#3  0x00007ffff7b4de2e in receive_request (c=0x5555557e3ef0, request=0x555555800e13 "13 3fc17404 node1 node2") at protocol.c:136
#4  0x00007ffff7b43513 in receive_meta (c=0x5555557e3ef0) at meta.c:290
#5  0x00007ffff7b442d9 in handle_meta_connection_data (c=0x5555557e3ef0) at net.c:291
#6  0x00007ffff7b41391 in event_loop () at event.c:287
#7  0x00007ffff7b449b2 in main_loop () at net.c:469
#8  0x0000555555556716 in main (argc=<optimized out>, argv=<optimized out>) at tincd.c:480
2015-07-02 20:38:02 +02:00
thorkill
f1a9a40c90 Marked all unsued parameters found by -Werror=unused-parameter with UNUSED() 2015-07-02 18:37:08 +02:00
thorkill
1391b2d7dc Added -Werror=unused-parameter
In system.h UNUSED() macro has been defined which can be used to mark unsed parameters.
2015-07-02 18:35:57 +02:00
thorkill
50da19addf Removed unused variables.
Found using clang -Wunused-variable
2015-07-02 18:03:03 +02:00
thorkill
656af8fa07 Remove conflicting function definitions
- send_request
- send_meta
2015-07-02 17:51:46 +02:00
thorkill
9b3ff33dba Added missing function prototypes
Found by clang -Wmissing-prototypes
2015-07-02 17:43:51 +02:00
thorkill
78397eda9b Added extra check for edge->from and edge->to in edge_add
edge_add() and edge_del() assume, that from and to are always set.
This was triggered while working on cmocka test.
2015-07-02 00:02:05 +02:00
thorkill
536256b2da Added support for cmocka *alloc 2015-07-01 19:04:22 +02:00
thorkill
dca3558d05 Leave a notice in the log when aborting 2015-07-01 19:01:42 +02:00
thorkill
24cea32efb Fix memory leak in splay_delete_tree
Use splay_delete_node to properly decrease counters and release memory.
2015-07-01 16:57:05 +02:00
thorkill
faef01317b Do not free splay_tree when tree->count != 0 2015-07-01 16:56:07 +02:00
thorkill
278cd4d856 Added missing libchacha_poly1305 while linking sptps_* tools
- should work on gentoo and Arch Linux - AUR
2015-07-01 13:54:57 +02:00
thorkill
905572863c Added support for darwin
Darwin does not have -lrt
2015-07-01 11:18:29 +02:00
thorkill
fbb62fa80e Make proper checks in configure
now compiles with gcc 5.1.0
2015-06-30 23:20:31 +02:00
thorkill
c3f8a93d52 Define variables in getopt.h 2015-06-30 22:50:29 +02:00
thorkill
82300c623d Make sptps_speed and sptps_test compile
TODO: tests do not work
2015-06-30 22:49:11 +02:00
thorkill
4bfa726f8b Cleanup src/Makefile.am
Make it compile on FreeBSD
2015-06-30 22:48:15 +02:00
thorkill
f8154e3012 Initialize values in tincctl.c 2015-06-30 19:51:19 +02:00
thorkill
6a6113b366 Initialize variables in info.c 2015-06-30 19:48:49 +02:00
thorkill
84d34f4f35 Initialize variables in invitation.c 2015-06-30 19:46:14 +02:00
thorkill
8fb52e05f3 Define g_argv as static 2015-06-30 19:44:35 +02:00
thorkill
de9f04c30e Initialize variables in linux/device.c 2015-06-30 19:42:37 +02:00
thorkill
fb2942a249 Initialize result 2015-06-30 19:40:33 +02:00
thorkill
7a61acabea Added hash_t definitions 2015-06-30 19:39:11 +02:00
thorkill
9e0c77e21f Initialize variables in splay_tree.c - splay_top_down() 2015-06-30 19:35:13 +02:00