Commit graph

1465 commits

Author SHA1 Message Date
Guus Sliepen
a717b9bcfb Add option to dump only a list of reachable nodes. 2012-12-03 13:08:03 +01:00
Guus Sliepen
75c619e372 More fixes for Windows.
In particular, Windows does support many of the timer* macros, except timeradd
and timersub.
2012-12-03 10:41:28 +01:00
Guus Sliepen
d53384c2de Fix compiler error on Windows. 2012-12-03 09:08:21 +01:00
Guus Sliepen
76816e119b Fix crash in timeout handling. 2012-12-03 09:07:23 +01:00
Guus Sliepen
d19b006065 Set a node's pointers to zero before trying to insert it into a tree. 2012-12-03 09:02:08 +01:00
Guus Sliepen
d2b19be1a0 Fix use of unitialised values in hash tables.
Not only was Valgrind unhappy about it, it could also result in cache misses.
2012-11-29 14:35:08 +01:00
Guus Sliepen
d9c70767aa Fix check for expired events.
This would trigger a infinite loop if a timeout expired and the next timeout
was not expired yet, but less than 1 second from being expired.
2012-11-29 14:32:12 +01:00
Guus Sliepen
8825cddd0d Allow multiple timeouts to expire at the exact same time. 2012-11-29 12:37:04 +01:00
Guus Sliepen
6bc5d626a8 Drop libevent and use our own event handling again.
There are several reasons for this:

- MacOS/X doesn't support polling the tap device using kqueue, requiring a
  workaround to fall back to select().
- On Windows only sockets are properly handled, therefore tinc uses a second
  thread that does a blocking ReadFile() on the TAP-Win32/64 device. However,
  this does not mix well with libevent.
- Libevent, event just the core, is quite large, and although it is easy to get
  and install on many platforms, it can be a burden.
- Libev is more lightweight and seems technically superior, but it doesn't
  abstract away all the platform differences (for example, async events are not
  supported on Windows).
2012-11-29 12:28:23 +01:00
Guus Sliepen
d30b9e1272 Ensure MTU probe replies are sent back the same way they came in.
Also sprinkle some comments over mtu_probe_h().
2012-11-19 14:20:50 +01:00
Guus Sliepen
3c1b704733 Improve UDP address selection.
We don't need to search the whole edge tree, we can use the node's own edge
tree since each edge has a pointer to its reverse. Also, we do need to make
sure we try the reflexive address often.
2012-11-19 13:50:17 +01:00
Guus Sliepen
f57129ce34 Try all known addresses of node during PMTU discovery, now also for SPTPS. 2012-11-17 22:48:06 +01:00
Guus Sliepen
30404650b2 Choose a suitable socket when updating a node's UDP address. 2012-11-17 22:14:52 +01:00
Guus Sliepen
8f9ee89522 Also don't use poll() on MacOS/X. 2012-11-15 11:24:18 +01:00
Guus Sliepen
8a77df9e28 Disable support for kqueue on MacOS/X.
Apparently MacOS/X doesn't support kqueue events on character devices.
2012-11-15 11:13:40 +01:00
Guus Sliepen
e8bf81794f Send broadcast packets using a random socket, and properly support IPv6.
Before it would always use the first socket, and always send an IPv4 broadcast packet. That
works fine in a lot of situations, but it is better to try all sockets, and to send IPv6 packets
on IPv6 sockets. This is especially important for users that are on IPv6-only networks or that
have multiple physical network interfaces, although in the latter case it probably requires
them to use the ListenAddress variable to create a separate socket for each interface.
2012-11-13 15:05:41 +01:00
Guus Sliepen
0870c7c32c Don't take the address of a variable whose scope is about to disappear. 2012-11-13 15:01:43 +01:00
Guus Sliepen
0ee139e914 Make sure PMTU discovery works in switch mode with VLAN tags.
Before, when tinc saw a packet larger than the PMTU with a VLAN tag, it would
not know what to do with it, and would just forward it via TCP. Now, tinc
handles 802.1q packets correctly, as long as there is only one tag.
2012-11-10 23:55:56 +01:00
Guus Sliepen
ade4fccad6 Using alloca() for a constant sized buffer is very silly.
Cppcheck said using alloca() in the 21st century is silly anyway.
2012-11-10 23:13:05 +01:00
Guus Sliepen
b355476e91 Fix potential buffer overflow reading the PID file.
Found by cppcheck.
2012-11-10 23:09:31 +01:00
Guus Sliepen
edc08b73a9 Slightly randomize all timeouts. 2012-10-21 17:45:16 +02:00
Guus Sliepen
717ea66d7b Add the AutoConnect option.
When set to a non-zero value, tinc will try to maintain exactly that number of
meta connections to other nodes.  If there are not enough connections, it will
periodically try to set up an outgoing connection to a random node.  If there
are too many connections, it will periodically try to remove an outgoing
connection.
2012-10-21 17:35:13 +02:00
Guus Sliepen
1f8b70efa0 Keep track of the number of nodes in a tree. 2012-10-21 17:34:53 +02:00
Guus Sliepen
3254e75afe Fix a few compiler errors/warnings. 2012-10-14 19:21:13 +02:00
Guus Sliepen
70a1a5594a Update copyright notices. 2012-10-14 17:42:49 +02:00
Guus Sliepen
4200a378c4 Fix compile error on Windows. 2012-10-14 16:39:16 +02:00
Guus Sliepen
368727c3da tincctl: add node colors and edge weight to graph dump. 2012-10-14 16:12:17 +02:00
Guus Sliepen
40ed0c07dd Log more messages using logger(). 2012-10-14 15:37:24 +02:00
Guus Sliepen
b234304b66 Make sure the ReplayWindow option works for SPTPS as well. 2012-10-14 14:48:35 +02:00
Guus Sliepen
ee1d655f2f Only log success of initial datagram SPTPS handshake. 2012-10-14 14:45:27 +02:00
Guus Sliepen
44a24f63ac Fix handling of initial datagram SPTPS packet.
Only the very first packet of an SPTPS session should be send with REQ_KEY,
this signals the peer to abort any previous session and start a new one as
well.
2012-10-14 14:33:54 +02:00
Sven-Haegar Koch
ec1f7e525d sptps.c: Add missing newline to log message. 2012-10-12 17:19:56 +02:00
Guus Sliepen
94ec8d34db Strip newline from incoming SPTPS requests.
Most of the code doesn't care whether requests are terminated with a newline or
not, except that when requests are forwarded, it is assumed they do not have
one and a newline is added.  When a node using SPTPS receives a request from
another SPTPS-using node, and forwards it to a non-SPTPS-using node, this will
result in two consecutive newlines, which the latter node will see as an empty,
and thus invalid, request.
2012-10-11 22:47:13 +02:00
Guus Sliepen
45944e4514 Clear status and options fields of unreachable nodes. 2012-10-11 22:21:30 +02:00
Guus Sliepen
d917c8cb6b Fix whitespace. 2012-10-10 17:17:49 +02:00
Guus Sliepen
58f4b845b9 Try all known addresses of node during the PMTU discovery phase.
This helps in situations where some nodes have IPv6 and others have not.
2012-10-10 14:46:22 +02:00
Guus Sliepen
0ed0cc6f9c Fix hash functions for keys whose size is not divisible by 4. 2012-10-09 17:49:09 +02:00
Guus Sliepen
d1ec010660 Fix memory leaks found by valgrind. 2012-10-09 16:27:28 +02:00
Guus Sliepen
72642b40b3 Clear Ethernet header when reading packets from a tun device.
This fixes a warning from valgrind about uninitialized bytes, which were being
sent to other nodes.
2012-10-09 15:52:58 +02:00
Guus Sliepen
b346338f9c Remove unused variables, fix some #includes. 2012-10-09 13:28:09 +02:00
Guus Sliepen
f62b4a9134 Fix deleting connections from the connection list. 2012-10-09 13:23:12 +02:00
Guus Sliepen
0b8b23e0dd C99 extravaganza. 2012-10-08 00:35:38 +02:00
Guus Sliepen
ff306f0cda Replace the connection_tree with a connection_list.
The tree functions were never used on the connection_tree, a list is more appropriate.
Also be more paranoid about connections disappearing while traversing the list.
2012-10-07 21:59:53 +02:00
Guus Sliepen
ce059e36fd Refactor outgoing connection handling.
Struct outgoing_ts and connection_ts were depending too much on each other,
causing lots of problems, especially the reuse of a connection_t. Now, whenever
a connection is closed it is immediately removed from the list of connections
and destroyed.
2012-10-07 21:02:40 +02:00
Guus Sliepen
d93a37928b Fix warnings from cppcheck. 2012-10-07 17:53:23 +02:00
Guus Sliepen
5d0812d492 Remove a debug message. 2012-10-07 14:06:47 +02:00
Guus Sliepen
c2a9ed9e98 Handle packets encrypted via SPTPS that need to be forwarded via TCP. 2012-10-07 14:03:50 +02:00
Guus Sliepen
bb6b97ce34 Make datagram SPTPS key exchange more robust.
Similar to old style key exchange requests, keep track of whether a key
exchange is already in progress and how long it took. If no key is known yet
or if key exchange takes too long, (re)start a new key exchange.
2012-10-07 13:31:19 +02:00
Guus Sliepen
b99af2f813 Useful error messages when writing to a meta connection fails. 2012-10-07 11:45:54 +02:00
Guus Sliepen
e053713465 When terminating, keep control connections open until the end.
This ensures all device files and listening sockets have been closed before
tincctl gets notified of tincd's termination.
2012-10-06 21:16:17 +02:00
Guus Sliepen
86116bb022 Clear connection options and status fields in free_connection_partially().
Most fields should be zero when reusing a connection. In particular, when an
outgoing connection to a node which is reachable on more than one address is
made, the second connection to that node will have status.encryptout set but
outctx will be NULL, causing a NULL pointer dereference when
EVP_EncryptUpdate() is called in send_meta() when it shouldn't.
2012-10-06 21:15:19 +02:00
Guus Sliepen
ef9358c0d6 Improve starting/stopping tincd using tincctl.
When starting tincd, tincctl now strips non-options from the command line, and
sets argv[0] to the name of the tincd command instead of copying its own
command name.

When stopping a running tincd, tincctl now waits for it to terminate.
2012-10-06 17:45:03 +02:00
Guus Sliepen
47f33e07ff Fix off-by-one error.
Apart from writing 1 byte beyond an array allocated on the stack, this slipped
an unitialized byte in the seed used for key generation.
2012-10-06 16:53:43 +02:00
Guus Sliepen
20b441a6de Libreadline might depend on libcurses. 2012-10-01 10:42:13 +02:00
Guus Sliepen
3887e6dcb5 Remove abort() call that accidentily sneaked into commit dd1b69e. 2012-10-01 10:39:15 +02:00
Guus Sliepen
0b0949e5bb Make sure sptps_test compiles without -flto. 2012-10-01 10:36:23 +02:00
Guus Sliepen
b381acd60d Remove unused function declaration. 2012-09-30 23:12:43 +02:00
Guus Sliepen
dd1b69e31f Fix not reading Port statement from host config file. 2012-09-30 22:43:48 +02:00
Guus Sliepen
6dfdb32361 Merge branch 'master' into 1.1
Conflicts:
	lib/utils.c
	src/net_setup.c
	src/process.c
	src/protocol_auth.c
	src/protocol_key.c
	src/utils.h
2012-09-30 15:00:47 +02:00
Guus Sliepen
c4940a5c88 Add strict checks to hex to binary conversions.
The main goal is to catch misuse of the obsolete PrivateKey and PublicKey
statements.
2012-09-30 13:45:47 +02:00
Guus Sliepen
3bd810ea79 Attribution for Martin Schürrer. 2012-09-30 13:45:39 +02:00
Martin Schürrer
5a161e86cf Output details of encryption errors 2012-09-30 02:04:55 +02:00
Guus Sliepen
9e76c464b2 Remove some debugging messages. 2012-09-28 17:51:48 +02:00
Guus Sliepen
e971130b60 Make tincctl robust against dropped control connections. 2012-09-28 17:36:25 +02:00
Guus Sliepen
c5325ffdd1 Correctly add/remove outgoing connections when reloading configuration. 2012-09-28 17:05:01 +02:00
Guus Sliepen
f70cbc9d3e Comment out old public/private keys when generating new ones. 2012-09-27 15:45:02 +02:00
Guus Sliepen
1f312137d5 Allow dumping either directed or undirected graphs.
Internally, tinc maintains a directed graph of the meta connections between
nodes. However, this causes graphviz to draw two lines between nodes, which is
not always desirable. The "dump graph" command now defaults to dumping an
undirected graph, the "dump digraph" command will dump a directed graph.
2012-09-26 23:52:36 +02:00
Guus Sliepen
d6388d782e Let tincctl parse and format dumps.
At the moment it just reproduces the old format.
2012-09-26 23:18:32 +02:00
Guus Sliepen
9ade39b7d5 Keep last known address and time since reachability changed.
This allows tincctl info to show since when a node is online or offline.
2012-09-26 22:20:43 +02:00
Guus Sliepen
1e5deec973 Remove remnants of Ethertap and old TUNSETIFF ioctl(). 2012-09-25 22:28:08 +02:00
Guus Sliepen
66e702d90d Attribution for Vil Brekin and some code style cleanups. 2012-09-24 14:02:07 +02:00
Vilbrekin
afe4bf62ec Use __ANDROID__ define rather than dirty hard-code to allow android NDK cross-compilation. 2012-09-24 13:55:29 +02:00
Vilbrekin
f2570c1b7f Replace hard-code with new ScriptsInterpreter configuration property.
This new setting allows choosing a custom script interpreter used for the various tinc callbacks.
If none is specified, the script itself is called as executable (as before).
This is particularly useful when storing tinc configuration and script on a mount point with no-exec attribute.
2012-09-24 13:55:24 +02:00
Vilbrekin
8a6f278fd2 Basic patch for android cross-compilation.
Commented non-existing functions in android NDK.
Prefix scripts execution with shell binary to allow execution on no-exec mount points.
Everyything is currently hard coded, while it should use pre-compiler variables...
2012-09-24 13:53:11 +02:00
Guus Sliepen
2dc8deb104 Ensure sptps_test compiles with -flto. 2012-09-13 21:35:29 +02:00
Guus Sliepen
90f1cba1fd Replace node_udp_tree with a hash table. 2012-09-05 13:05:48 +02:00
Guus Sliepen
4c05afd19a Use hash tables to lookup owners of addresses. 2012-09-05 12:45:36 +02:00
Guus Sliepen
6b6a025488 Add a simple hash table implementation. 2012-09-05 12:44:41 +02:00
Guus Sliepen
e9de08be0d Remove newlines at end of log messages. 2012-09-04 14:21:50 +02:00
Guus Sliepen
05dac63dbc Remove some debug messages. 2012-09-04 14:16:05 +02:00
Guus Sliepen
742f7bb04e Properly handle SPTPS packets with stripped Ethernet headers. 2012-08-30 14:21:23 +02:00
Guus Sliepen
d74b81b61e Fix node name check for "connect" and "disconnect" commands. 2012-08-30 14:00:34 +02:00
Guus Sliepen
5567c0d410 Quit when "exit" or "quit" commands are used in tincctl's shell. 2012-08-05 17:25:31 +02:00
Guus Sliepen
d18519ae21 Fix segfault when using tincctl's shell without readline. 2012-08-05 17:03:57 +02:00
Guus Sliepen
e29e0fee88 Make sure the top command can be used more than once in tincctl's shell. 2012-08-03 14:17:02 +02:00
Guus Sliepen
a57db1dfe0 Fork when using the "start" command in tincctl.
This allows the command to be given in its shell without immediatly exiting tincctl.
2012-08-03 14:15:50 +02:00
Guus Sliepen
36c6afede3 Add readline completion for tincctl config and tincctl info. 2012-08-03 13:23:07 +02:00
Guus Sliepen
8af2f3f5a4 Optionally compress and/or strip Ethernet header from SPTPS packets. 2012-08-02 17:44:59 +02:00
Guus Sliepen
73348be58e Have tincctl act as a shell when no command is given.
By default it uses readline to read commands. If the input and output are not a
tty, no prompt is shown.
2012-08-02 17:24:42 +02:00
Guus Sliepen
91937812bd Clear struct sptps before reusing it. 2012-08-02 17:23:51 +02:00
Guus Sliepen
6396f42d74 Stricter checks for netname and node names.
- Node names should not be empty.
- Net names should not contain slashes or start with a dot, because they are
  used in pathnames.
2012-08-01 16:51:59 +02:00
Guus Sliepen
61006ced88 Add missing configuration variables. 2012-08-01 16:13:23 +02:00
Guus Sliepen
b0f3a76e9b Add the ability to query configuration variables to tincctl. 2012-08-01 15:53:20 +02:00
Guus Sliepen
a9caa2a6ea tincctl restart should work even if no tincd is running. 2012-08-01 15:15:37 +02:00
Guus Sliepen
07980b056c Try sending SIGTERM if we cannot connect to a tincd but we know its PID. 2012-08-01 15:14:48 +02:00
Guus Sliepen
7a71d48009 Use a status bit to track which nodes use SPTPS. 2012-07-31 21:43:49 +02:00
Guus Sliepen
6bc8df3e01 Add Brandon Black's replay window code to SPTPS. 2012-07-31 20:39:15 +02:00
Guus Sliepen
5ede437307 Handle SPTPS datagrams in try_mac(). 2012-07-31 20:36:35 +02:00
Guus Sliepen
aaff0ed089 Remove unused #include. 2012-07-31 20:29:13 +02:00
Guus Sliepen
153abaa4d9 Use datagram SPTPS for packet exchange between nodes.
When two nodes which support SPTPS want to send packets to each other, they now
always use SPTPS. The node initiating the SPTPS session send the first SPTPS
packet via an extended REQ_KEY messages. All other handshake messages are sent
using ANS_KEY messages. This ensures that intermediate nodes using an older
version of tinc can still help with NAT traversal. After the authentication
phase is over, SPTPS packets are sent via UDP, or are encapsulated in extended
REQ_KEY messages instead of PACKET messages.
2012-07-30 18:36:59 +02:00