Commit graph

2277 commits

Author SHA1 Message Date
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
thorkill
044fc684d0 Initialize variables in route.c 2015-06-30 19:33:22 +02:00
thorkill
6b3b90a7b1 Initialize variables in protocol_subnet.c 2015-06-30 19:29:44 +02:00
thorkill
932dc76f43 Initialize variables in protocol_edge.c 2015-06-30 19:28:11 +02:00
thorkill
fb1a8fd631 Initialize variables in protocol.c 2015-06-30 19:26:42 +02:00
thorkill
0bd116195a Initialize variables in node.c 2015-06-30 19:24:27 +02:00
thorkill
d803ac93dc Initialize variables in netutl.c 2015-06-30 19:23:15 +02:00
thorkill
e2245da720 Initialize addrinfo hint 2015-06-30 19:20:57 +02:00
thorkill
94b9723917 Initialize sock 2015-06-30 19:19:30 +02:00
thorkill
c17cb1a0f2 Proper initialization of subnet 2015-06-30 19:15:43 +02:00
thorkill
7ed725888b Do not exit on unused-parameters 2015-06-30 19:15:22 +02:00
thorkill
78be3b19de Fixed signal_t initialization 2015-06-30 19:14:54 +02:00
thorkill
8f5a59a027 Included missing names.h 2015-06-30 19:11:45 +02:00
thorkill
3dc9542ec2 Disable -fno-strict-overflow and enable some -Werror= 2015-06-30 19:06:17 +02:00
thorkill
daf99058e3 Moved few config parameters to make lib usage possible. 2015-06-30 18:43:37 +02:00
thorkill
6633bf52e3 First working version 2015-06-30 18:36:57 +02:00
thorkill
6d9853618a Working on libs 2015-06-30 18:36:46 +02:00
thorkill
6b62992c25 Revert "Silence most noisy sources of memory leakage."
This reverts commit 408fb3b011.
2015-06-30 18:10:38 +02:00
thorkill
c53a9719d5 Revert "s_errno was nerver used"
This reverts commit 157ee90568.
2015-06-30 18:10:23 +02:00
thorkill
d661be413f Revert "Proper variable initialization"
This reverts commit bf91a8a340.
2015-06-30 18:10:20 +02:00
thorkill
54b8bc6e86 Revert "Type mismatch and debug_t is always >= 0"
This reverts commit 62dc7b6fe5.
2015-06-30 18:10:18 +02:00
thorkill
8a39621c64 Revert "make usage of function parameters"
This reverts commit 8108b0d5eb.
2015-06-30 18:10:16 +02:00
thorkill
f5f35bd148 Revert "initialize variables used in conditional jumps"
This reverts commit f89b38947a.
2015-06-30 18:10:10 +02:00
thorkill
104017df7a Revert "Added UNUSED macro to silnce unused-parameter warnings"
This reverts commit 8d4b974dda.
2015-06-30 18:10:07 +02:00
thorkill
c68aa9d5cc Revert "explicit middle parameter definition"
This reverts commit 0ef605d864.
2015-06-30 18:10:05 +02:00
thorkill
ce7b019067 Revert "Added type casting from debug_t to int"
This reverts commit 3bfb343b85.
2015-06-30 18:10:02 +02:00
thorkill
d7c623b8c7 Revert "Changed int size into size_t"
This reverts commit f755d57f4e.
2015-06-30 18:10:00 +02:00
thorkill
5dac5eb451 Revert "Marked unused parameters"
This reverts commit 3a61d104d4.
2015-06-30 18:09:50 +02:00
thorkill
3eb3cc7898 Revert "Type casting fixes"
This reverts commit dbfc168fa4.
2015-06-30 18:09:17 +02:00
thorkill
01098e2078 Revert "Fixing implicit conversion changes to signedness"
This reverts commit 7099a4437e.
2015-06-30 18:09:11 +02:00
thorkill
4f82a6359f Revert "Proper struct initialization"
This reverts commit bc8dbfc9fd.
2015-06-30 18:09:07 +02:00
thorkill
84ede57e52 Revert "fixed initialization of pollfd"
This reverts commit 319e0ac8ce.
2015-06-30 18:09:02 +02:00
thorkill
fe99eb02df Revert "Still hunting down uninitialized variables"
This reverts commit 46b9578cad.
2015-06-30 18:08:31 +02:00
thorkill
46b9578cad Still hunting down uninitialized variables 2015-06-30 02:04:16 +02:00
thorkill
319e0ac8ce fixed initialization of pollfd 2015-06-29 23:40:33 +02:00
thorkill
bc8dbfc9fd Proper struct initialization
Detected by clang -Wmissing-field-initializers
2015-06-29 23:32:34 +02:00
thorkill
7099a4437e Fixing implicit conversion changes to signedness
- format string
- function parameters
- logging
2015-06-29 23:32:26 +02:00
thorkill
dbfc168fa4 Type casting fixes 2015-06-29 16:19:23 +02:00
thorkill
3a61d104d4 Marked unused parameters 2015-06-29 16:19:19 +02:00
thorkill
f755d57f4e Changed int size into size_t 2015-06-29 16:19:15 +02:00
thorkill
3bfb343b85 Added type casting from debug_t to int 2015-06-29 16:19:11 +02:00
thorkill
0ef605d864 explicit middle parameter definition
error: use of GNU ?: conditional expression extension, omitting middle operand [-Werror,-Wgnu-conditional-omitted-operand]
2015-06-29 16:19:03 +02:00
thorkill
8d4b974dda Added UNUSED macro to silnce unused-parameter warnings 2015-06-29 16:18:52 +02:00
thorkill
f89b38947a initialize variables used in conditional jumps
Errors detected by clang -Wconditional-uninitialized.
2015-06-29 16:18:39 +02:00
thorkill
8108b0d5eb make usage of function parameters 2015-06-29 16:18:30 +02:00
thorkill
62dc7b6fe5 Type mismatch and debug_t is always >= 0
- Proper function definitions
2015-06-29 16:18:20 +02:00
thorkill
bf91a8a340 Proper variable initialization 2015-06-29 16:18:11 +02:00
thorkill
157ee90568 s_errno was nerver used 2015-06-29 16:18:02 +02:00
thorkill
da1a77998c Removed double break; 2015-06-29 16:17:53 +02:00
thorkill
408fb3b011 Silence most noisy sources of memory leakage.
==27135== Use of uninitialised value of size 8
==27135==    at 0x57BE17B: BN_num_bits_word (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x57BE205: BN_num_bits (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x57BADF7: BN_div (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x57C48FC: BN_mod_inverse (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x57C3647: BN_BLINDING_create_param (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x5812D44: RSA_setup_blinding (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x58095CB: rsa_get_blinding (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x580A64F: RSA_eay_private_decrypt (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x4E5D9BC: rsa_private_decrypt (rsa.c:97)
==27135==    by 0x4E51E1B: metakey_h (protocol_auth.c:524)
==27135==    by 0x4E505FD: receive_request (protocol.c:136)
==27135==    by 0x4E46002: receive_meta (meta.c:290)
==27135==  Uninitialised value was created by a heap allocation
==27135==    at 0x4C29F90: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==27135==    by 0x575DCD7: CRYPTO_malloc (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x57C24E1: BN_rand (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x57C216F: bn_rand_range (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x57C3630: BN_BLINDING_create_param (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x5812D44: RSA_setup_blinding (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x58095CB: rsa_get_blinding (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x580A64F: RSA_eay_private_decrypt (in /usr/lib/libcrypto.so.1.0.0)
==27135==    by 0x4E5D9BC: rsa_private_decrypt (rsa.c:97)
==27135==    by 0x4E51E1B: metakey_h (protocol_auth.c:524)
==27135==    by 0x4E505FD: receive_request (protocol.c:136)
==27135==    by 0x4E46002: receive_meta (meta.c:290)
2015-06-28 00:40:31 +02:00
Etienne Dechamps
7aca0be0f9 Protect against callbacks removing items from the io tree.
The definition of the splay_each() macro is somewhat complicated for
syntactic reasons. Here's what it does in a more readable way:

  for (splay_node_t* node = tree->head; node;) {
    type* item = node->data;
    splay_node_t* next = node->next;

    // RUN USER BLOCK with (item)

    node = next;
  }

list_each() works in the same way. Since node->next is saved before the
user block runs, this construct supports removing the current item from
within the user block. However, what it does *not* support is removing
*other items* from within the user block, especially the next item.
Indeed, that will invalide the next pointer in the above loop and
therefore result in an invalid pointer dereference.

Unfortunately, there is at least one code path where that unsupported
operation happens. It is located in ack_h(), where the authentication
protocol code detects a double connection (i.e. being connected to
another node twice). Running in the context of a socket read event, this
code will happily terminate the *other* metaconnection, resulting in its
socket being removed from the io tree. If, by misfortune, this other
metaconnection happened to have the next socket FD number (which is
quite possible due to FD reuse - albeit unlikely), and was part of the
io tree (which is quite likely because if that connection is stuck, it
will most likely have pending writes) then this will result in the next
pending io item being destroyed. Invalid pointer dereference ensues.

I did a quick audit of other uses of splay_each() and list_each() and
I believe this is the only scenario in which this "next pointer
invalidation" problem can occur in practice. While this bug has been
there since at least 6bc5d626a8 (November
2012), if not sooner, it happens quite rarely due to the very specific
set of conditions required to trigger it. Nevertheless, it does manage
to crash my central production nodes every other week or so.
2015-06-26 20:11:31 +02:00
Guus Sliepen
d150e82b94 Fix crash is sptps_logger().
Unfortunately, sptps_logger() cannot know if s->handle is pointing to a
connection_t or a node_t. But it needs to print name and hostname in
both cases. So make sure both types have name and hostname fields at the
start with the same offset.
2015-06-26 20:11:31 +02:00
Guus Sliepen
8960694e51 Fix alignment of output of sptps_speed. 2015-06-26 20:11:31 +02:00
Guus Sliepen
06a7c60db7 Fix receiving SPTPS data in sptps_speed and sptps_test.
The sptps_receive_data() was changed in commit d237efd to only process
one SPTPS record from a stream input. So now we have to put a loop
around it to ensure we process everything.
2015-06-26 20:11:30 +02:00
Guus Sliepen
479a10b484 Fix warnings about missing return value checks.
In some harmless places, checks for the return value of ECDSA and RSA
key generation and verification was omitted. Add them to keep the
compiler happy and to warn end users in case something is wrong.
2015-06-26 20:11:30 +02:00
thorkill
8e3edeec3d Reverted error messages to original one 2015-06-26 17:13:52 +02:00
Etienne Dechamps
ebffa40aa7 Protect against callbacks removing items from the io tree.
The definition of the splay_each() macro is somewhat complicated for
syntactic reasons. Here's what it does in a more readable way:

  for (splay_node_t* node = tree->head; node;) {
    type* item = node->data;
    splay_node_t* next = node->next;

    // RUN USER BLOCK with (item)

    node = next;
  }

list_each() works in the same way. Since node->next is saved before the
user block runs, this construct supports removing the current item from
within the user block. However, what it does *not* support is removing
*other items* from within the user block, especially the next item.
Indeed, that will invalide the next pointer in the above loop and
therefore result in an invalid pointer dereference.

Unfortunately, there is at least one code path where that unsupported
operation happens. It is located in ack_h(), where the authentication
protocol code detects a double connection (i.e. being connected to
another node twice). Running in the context of a socket read event, this
code will happily terminate the *other* metaconnection, resulting in its
socket being removed from the io tree. If, by misfortune, this other
metaconnection happened to have the next socket FD number (which is
quite possible due to FD reuse - albeit unlikely), and was part of the
io tree (which is quite likely because if that connection is stuck, it
will most likely have pending writes) then this will result in the next
pending io item being destroyed. Invalid pointer dereference ensues.

I did a quick audit of other uses of splay_each() and list_each() and
I believe this is the only scenario in which this "next pointer
invalidation" problem can occur in practice. While this bug has been
there since at least 6bc5d626a8 (November
2012), if not sooner, it happens quite rarely due to the very specific
set of conditions required to trigger it. Nevertheless, it does manage
to crash my central production nodes every other week or so.
2015-06-20 14:09:00 +01:00
Guus Sliepen
45a46f068c Fix crash is sptps_logger().
Unfortunately, sptps_logger() cannot know if s->handle is pointing to a
connection_t or a node_t. But it needs to print name and hostname in
both cases. So make sure both types have name and hostname fields at the
start with the same offset.
2015-06-10 23:42:17 +02:00
thorkill
7941f68ab0 removed debug output in sptps.c 2015-06-08 13:03:41 +02:00
Guus Sliepen
bfe231b977 Fix alignment of output of sptps_speed. 2015-06-07 23:20:14 +02:00
Guus Sliepen
a797b4a192 Fix receiving SPTPS data in sptps_speed and sptps_test.
The sptps_receive_data() was changed in commit d237efd to only process
one SPTPS record from a stream input. So now we have to put a loop
around it to ensure we process everything.
2015-06-07 23:17:54 +02:00
Guus Sliepen
d8d1ab4ee1 Fix warnings about missing return value checks.
In some harmless places, checks for the return value of ECDSA and RSA
key generation and verification was omitted. Add them to keep the
compiler happy and to warn end users in case something is wrong.
2015-06-07 22:50:05 +02:00
thorkill
e0221cc00d Merge branch '1.1' of github.com:gsliepen/tinc into thkr-1.1-ponyhof 2015-06-06 01:50:28 +02:00
Guus Sliepen
84ecc972e5 Fix missing return value caused by the previous commit. 2015-05-31 23:51:39 +02:00
Etienne Dechamps
eca357ed91 Don't try to relay packets to unreachable nodes.
It is not unusual for tinc to receive SPTPS packets to be relayed to
nodes that just became unreachable, due to state propagation delays in
the metagraph.

Unfortunately, the current code doesn't handle that situation correctly,
and still tries to relay the packet to the unreachable node. This
typically ends up segfaulting.

This commit fixes the issue by checking for reachability before relaying
the packet.
2015-05-31 20:19:48 +01:00
thorkill
9bf36c8666 Merge branch '1.1' of github.com:gsliepen/tinc into thkr-1.1-ponyhof 2015-05-26 12:57:15 +02:00
Etienne Dechamps
9e3adef5cb Fix invalid pointer use in get_my_hostname().
clang-3.7 warnings surfaced an actual bug:

invitation.c:185:5: error: address of array 'filename' will always evaluate to 'true'
      [-Werror,-Wpointer-bool-conversion]
        if(filename) {
        ~~ ^~~~~~~~

The regression was introduced in 3ccdf50beb.
2015-05-24 09:49:16 +01:00
Etienne Dechamps
7fcfbe2bd2 Fix wrong format string type in send_sptps_tcppacket().
This issue was found through a clang-3.7 warning:

protocol_misc.c:167:46: error: format specifies type 'short' but the argument has type 'int'
      [-Werror,-Wformat]
        if(!send_request(c, "%d %hd", SPTPS_PACKET, len))
                                ~~~                 ^~~
                                %d
2015-05-24 09:45:09 +01:00
Etienne Dechamps
3e61c7233b Don't set up an ongoing connection to myself.
It is entirely possible that the configuration file could contain a
ConnectTo statement refering to its own name; that's a reasonable
scenario when one deploys semi-automatically generated tinc.conf files.

Amusingly, tinc does not like that at all, and actually sets up an
outgoing_t structure to myself (which obviously makes no sense). This is
mostly benign, though it does result in non-sensical "Already connected
to myself" messages every retry interval.

However, that also makes things blow up in close_network_connections(),
because there we delete the entire outgoing list and *then* the myself
node, which still has a reference to the freshly deleted outgoing
structure. Boom.
2015-05-23 17:33:32 +01:00
Etienne Dechamps
8587e8c0d9 Fix crashes when trying unreachable nodes.
timeout_handler() calls try_tx(c->node) when c->edge exists.
Unfortunately, the existence of c->edge is not enough to conclude that
the node is reachable.

In fact, during connection establishment, there is a short period of
time where we create an edge for the node at the other end of the
metaconnection, but we don't have one from the other side yet.
Unfortunately, if timeout_handler() runs during that short time
window, it will call try_tx() on an unreachable node, which makes
things explode because that function is not prepared to handle that
case.

A typical symptom of this race condition is a hard SEGFAULT while trying
to send packets using metaconnections that don't exist, due to
n->nexthop containing garbage.

This patch fixes the issue by making try_tx() check for reachability,
and then making all code paths use try_tx() instead of the more
specialized methods so that they go through the check.

This regression was introduced in
eb7a0db18e.
2015-05-23 10:24:00 +01:00
Guus Sliepen
537a936671 Update copyright notices. 2015-05-21 11:09:01 +02:00
Guus Sliepen
0a786ffbb9 Set the CLOEXEC flag on the umbilical socket. 2015-05-21 11:06:38 +02:00
Guus Sliepen
87e0952773 Use socketpair() instead of pipe() for the umbilical.
This prepares for a possible conversion of the umbilical socket to a
control socket.
2015-05-20 21:28:54 +02:00
Guus Sliepen
19e0d449eb Don't write log messages to the umbilical pipe if we don't detach.
If we run in the foreground and are started by the CLI, this would
otherwise cause the first few log messages to appear twice.
2015-05-20 21:25:06 +02:00
Guus Sliepen
11868b890d Ensure "tinc start" knows if the daemon really started succesfully.
We do this by creating an umbilical between the CLI and the daemon. The
daemon pipes log messages to the CLI until it starts the main loop. The
daemon then cuts the umbilical. The CLI copies all the received log
messages to stderr, and the last byte indicates whether the daemon
started succesfully or not, so the CLI can exit with a useful exit code.
2015-05-20 16:59:43 +02:00
thorkill
26c7ff7fdd fixed conflict in src/sptps.c 2015-05-20 14:34:10 +02:00
Guus Sliepen
7f96ef081d Fix check for LOCALSTATEDIR accessibility for the CLI.
The CLI does not need write access to the directory where the PID file
is stored, it just needs to be able to read the PID file.
2015-05-20 11:11:12 +02:00
Guus Sliepen
3ccdf50beb Allocate temporary filenames on the stack.
This gets rid of xasprintf() in a number of places, and removes the need
to free() the temporary strings. A few potential memory leaks have been
fixed.
2015-05-20 00:58:00 +02:00
Guus Sliepen
58e8f598f3 Allow dumping a list of outstanding invitations.
This dumps the name of the invitation file, as well as the name of the
node that is being invited. This can make it easier to find the
invitation file belonging to a given node.
2015-05-20 00:12:01 +02:00
Guus Sliepen
7c8f54cdb2 Add "list" as an alias for "dump" in the CLI. 2015-05-20 00:02:53 +02:00
Guus Sliepen
69ba5f621e Quit with an error message if ioctl(TUNSETIFF) fails.
It is possible that opening /dev/net/tun works but that interface
creation itself fails, for example if a non-root user tries to create a
new interface, or if the desired interface is already opened by another
process. In this case, the ioctl() fails, but we actually silently
ignored this condition.
2015-05-19 22:26:32 +02:00
thorkill
587e177dc3 Fixed format-warnings 2015-05-19 22:21:25 +02:00
Guus Sliepen
60fbdb3f2c If LOCALSTATEDIR is inaccessible, store the pid and socket files in the configuration directory.
The compile time local state directory is usually /var or
/usr/local/var. If this is not accessible for some reason, for example
because someone ./configured tinc without --localstatedir and
/usr/local/var does not exist, or if tinc is started by a non-root user,
then tinc will fall back to the directory where tinc.conf is stored.
A warning is logged when this happens.
2015-05-19 22:17:18 +02:00
Guus Sliepen
dece2db78e Don't log seqno failures in sptps_verify_datagram().
This function is not used for normal traffic, only when a packet from an
unknown source is received and we need to check against candidates. No
failures should be logger in this case; if the packet is really not
valid this will be logged by handle_incoming_vpn_data().
2015-05-19 21:32:30 +02:00
Guus Sliepen
a752211801 Add source of SPTPS errors to log messages. 2015-05-19 21:23:35 +02:00
thorkill
ef4a0848ca Merge branch '1.1' of github.com:gsliepen/tinc into thkr-1.1-ponyhof 2015-05-19 17:59:03 +02:00
Guus Sliepen
d89f37eb17 Add newline at end of precomp_data.h and sc.h. 2015-05-19 14:25:20 +02:00
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
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