]> git.meshlink.io Git - meshlink/log
meshlink
23 months agoMove the public header files into their own directory.
Guus Sliepen [Sun, 11 Dec 2022 15:21:56 +0000 (16:21 +0100)]
Move the public header files into their own directory.

This now also calls target_include_directories() to add the public
header directory to the search path.

23 months agoInitial support for CMake.
Guus Sliepen [Sun, 11 Dec 2022 11:47:47 +0000 (12:47 +0100)]
Initial support for CMake.

This supports building and installing the library, as well as running
part of the test suite (blackbox tests are not built yet). So far it has
only been tested on Linux.

2 years agoNever automatically try to bind to ports >= 32768.
Guus Sliepen [Tue, 8 Nov 2022 21:13:42 +0000 (22:13 +0100)]
Never automatically try to bind to ports >= 32768.

RFC 6335 says operating systems should use ports 49152-65535 for
ephemeral ports. However, Linux and several other operating systems use
32768-65535 by default. Make sure we don't bind in that range, as a
single outgoing TCP connection that uses the same port for the local end
as MeshLink wants to use for the listening port can cause problems.

2 years agoAdd a test for the discovery algorithm.
Guus Sliepen [Sun, 6 Nov 2022 22:50:18 +0000 (23:50 +0100)]
Add a test for the discovery algorithm.

Create two nodes and link them, then change their ports and check if
they can still find each other.

2 years agoAdd a test for changing ports and handling of port conflicts.
Guus Sliepen [Sun, 6 Nov 2022 22:18:22 +0000 (23:18 +0100)]
Add a test for changing ports and handling of port conflicts.

2 years agoCheck send buffer instead of receive buffer size when calling channel_poll().
Guus Sliepen [Wed, 28 Sep 2022 09:12:41 +0000 (11:12 +0200)]
Check send buffer instead of receive buffer size when calling channel_poll().

3 years agoAdd a callback that notifies when the MeshLink thread starts and stops.
Guus Sliepen [Sun, 3 Oct 2021 13:40:45 +0000 (15:40 +0200)]
Add a callback that notifies when the MeshLink thread starts and stops.

This callback is called from within the MeshLink thread, right after it
starts and right before it stops.

3 years agoAccount for SPTPS overhead.
Guus Sliepen [Fri, 8 Oct 2021 18:54:45 +0000 (20:54 +0200)]
Account for SPTPS overhead.

3 years agoAdd missing metering testcases.
Guus Sliepen [Sun, 26 Sep 2021 22:19:38 +0000 (00:19 +0200)]
Add missing metering testcases.

3 years agoAdd extra metering scenarios.
Guus Sliepen [Mon, 20 Sep 2021 20:08:48 +0000 (22:08 +0200)]
Add extra metering scenarios.

3 years agoAdd a metering test. feature/improved-counters test/metering-better-pmtu
Guus Sliepen [Thu, 9 Sep 2021 18:11:16 +0000 (20:11 +0200)]
Add a metering test.

This checks bandwidth usage for several minutes while doing PMTU probing,
being idle, and transferring data over a channel via a relay.

3 years agoImproved node traffic counters.
Guus Sliepen [Sun, 8 Aug 2021 20:18:46 +0000 (22:18 +0200)]
Improved node traffic counters.

Drop counters for packets, keep byte counters. But distinguish between
application data (channel traffic) and meta-data (including UDP probes).
Also track how much data we forward for other nodes.

The counters can be read by devtool_get_node_status(), and a new function
devtool_reset_node_counters() has been added that will zero the counters.

3 years agoAdd meshlink_get_node_tiny(). feature/tiny-support
Guus Sliepen [Mon, 2 Aug 2021 23:09:45 +0000 (01:09 +0200)]
Add meshlink_get_node_tiny().

This allows querying if a node is connected using the tiny MeshLink
version.

3 years agoHandle raw packets from tiny peers.
Guus Sliepen [Tue, 22 Jun 2021 19:44:01 +0000 (21:44 +0200)]
Handle raw packets from tiny peers.

Tiny peers don't support UTCP channels, but send raw packets directly over
the meta connection.

3 years agoHandle connections from nodes using MeshLink-tiny.
Guus Sliepen [Tue, 22 Jun 2021 19:41:52 +0000 (21:41 +0200)]
Handle connections from nodes using MeshLink-tiny.

Add a new flags field to the ID request. Currently this is only set by tiny
nodes. If we see the peer set it, don't send our edges to the peer, and
don't forward any information from other nodes.

3 years agoUse multicast to respond to mDNS requests.
Guus Sliepen [Thu, 27 May 2021 21:37:58 +0000 (23:37 +0200)]
Use multicast to respond to mDNS requests.

On macOS, it seems unicast responses are not received if another process
is also listening on the same port. Try to use multicast for response
packets instead, if we can discovery the interface of the incoming
request.

3 years agoSilence warnings about printing function pointers.
Guus Sliepen [Sun, 6 Jun 2021 23:00:11 +0000 (01:00 +0200)]
Silence warnings about printing function pointers.

Cast function pointers first to intptr_t, then to void *. This silences
a warning from GCC that we are not actually allowed to print function
pointers using %p, which is not an issue on the platforms we support.

3 years agoIgnore ADD_EDGE messages we know are outdated. fix/spurious-channel-closure
Guus Sliepen [Sun, 30 May 2021 20:34:12 +0000 (22:34 +0200)]
Ignore ADD_EDGE messages we know are outdated.

A node reconnecting after a network error might send outdated ADD_EDGE
messages. If we see this for an edge we own, we send back a correction.
However, if we don't own the edge but we are one of the edges endpoints,
we ignore it and let the other side, which is the owner, take care of
sending a correction.

This change avoids us from incorrectly learning an old session ID for a
node, which might cause channels to that node to be closed prematurely.

3 years agoAdd log messages for all API entry points with effects.
Guus Sliepen [Sun, 23 May 2021 16:18:29 +0000 (18:18 +0200)]
Add log messages for all API entry points with effects.

At MESHLINK_DEBUG level, log all API entry points except the
meshlink_get_*() functions.

3 years agoLog the amount of metadata received at DEBUG level.
Guus Sliepen [Fri, 7 May 2021 09:08:26 +0000 (11:08 +0200)]
Log the amount of metadata received at DEBUG level.

3 years agoImprove logging of connection attemps.
Guus Sliepen [Wed, 5 May 2021 18:13:44 +0000 (20:13 +0200)]
Improve logging of connection attemps.

Ensure all causes for a connection to be activated or terminated are
logged at INFO level or higher. But remove the "Closing connection with"
message for connections that were never activated.

3 years agoFix potential incorrect destruction of channels.
Guus Sliepen [Tue, 4 May 2021 19:51:50 +0000 (21:51 +0200)]
Fix potential incorrect destruction of channels.

utcp_abort_all_connections() was called when a node is blacklisted or a
a node reconnects with a different session ID. In both cases, all active
channels should be closed. However, utcp_abort_all_connections() also freed
the UTCP connection object, which would cause a double free when the
application freed the corresponding meshlink_channel object.

Rename utcp_abort_all_connections() to utcp_reset_all_connections(), and
have it not invalidate any handles.

3 years agoFix uninitialized data being passed to sendmsg().
Guus Sliepen [Tue, 4 May 2021 19:53:27 +0000 (21:53 +0200)]
Fix uninitialized data being passed to sendmsg().

Found by Valgrind.

3 years agoFix several memory leaks.
Guus Sliepen [Tue, 4 May 2021 19:52:55 +0000 (21:52 +0200)]
Fix several memory leaks.

Found by the AddressSanitizer.

3 years agoClear send and receive buffers before channel close/error callbacks.
Guus Sliepen [Thu, 29 Apr 2021 16:59:18 +0000 (18:59 +0200)]
Clear send and receive buffers before channel close/error callbacks.

When there is an error that would cause the poll callback to be called
with length zero, make sure we drop the buffers first, so that calls to
meshlink_channel_get_sendq() will also return zero. This allows poll
callbacks that wait for the send buffer to be emptied to work correctly.

3 years agoAdd back the AC_PROG_CC_C99 check.
Guus Sliepen [Fri, 23 Apr 2021 16:19:59 +0000 (18:19 +0200)]
Add back the AC_PROG_CC_C99 check.

This macro is deprecated in 2.70 and will cause a warning to be
generated, but it is still necessary when using autoconf 2.69 in
combination with a compiler that does not enable C99 features by
default.

3 years agoAdd a test case for meshlink_channel_abort() in combination with AIO.
Guus Sliepen [Fri, 23 Apr 2021 15:58:19 +0000 (17:58 +0200)]
Add a test case for meshlink_channel_abort() in combination with AIO.

3 years agoEnsure aux field is initialized in RST packets.
Guus Sliepen [Fri, 23 Apr 2021 15:55:03 +0000 (17:55 +0200)]
Ensure aux field is initialized in RST packets.

The aux field was left uninitialized. This didn't cause any harm, but
was caught by valgrind.

3 years agoAdd meshlink_channel_abort().
Guus Sliepen [Fri, 23 Apr 2021 07:30:18 +0000 (09:30 +0200)]
Add meshlink_channel_abort().

This is similar to meshlink_channel_close(), but resets the UTCP channel
instead of doing a normal FIN shutdown. It will also drop the send and
receive buffers.

3 years agoFix a potential segmentation fault when log level is set to DEBUG.
Guus Sliepen [Thu, 22 Apr 2021 22:47:15 +0000 (00:47 +0200)]
Fix a potential segmentation fault when log level is set to DEBUG.

3 years agoIncrease DNS resolution timeout during join to 30 seconds
varun-elear [Wed, 21 Apr 2021 10:36:42 +0000 (16:06 +0530)]
Increase DNS resolution timeout during join to 30 seconds

3 years agoFix a compile error on macOS when using an older version of autoconf.
Guus Sliepen [Sun, 18 Apr 2021 14:43:17 +0000 (16:43 +0200)]
Fix a compile error on macOS when using an older version of autoconf.

With autoconf 2.69, the USE_SYSTEM_EXTENSIONS macro did not enable
_DARWIN_C_SOURCE, which could cause a compile error. This is fixed in
autoconf 2.71, but in order to provide some backwards compatibility, we
manually enable _DARWIN_C_SOURCE for now.

3 years agoFix a compiler warning.
Guus Sliepen [Thu, 15 Apr 2021 18:40:22 +0000 (20:40 +0200)]
Fix a compiler warning.

3 years agoFix compiler warnings about comparing signed and unsigned sizes. feature/catta-replacement
Guus Sliepen [Mon, 5 Apr 2021 20:33:45 +0000 (22:33 +0200)]
Fix compiler warnings about comparing signed and unsigned sizes.

3 years agoMove noinst_PROGRAMS to EXTRA_PROGRAMS.
Guus Sliepen [Mon, 5 Apr 2021 20:31:15 +0000 (22:31 +0200)]
Move noinst_PROGRAMS to EXTRA_PROGRAMS.

The main product is the library, example programs should not be built by
default. Move them to EXTRA_PROGRAMS so they can still be built with a
manual make command.

3 years agoAlso add framework options when $host_os contains ios.
Guus Sliepen [Mon, 5 Apr 2021 20:29:53 +0000 (22:29 +0200)]
Also add framework options when $host_os contains ios.

3 years agoUse SCNetworkReachability on macOS and iOS to detect network changes.
Guus Sliepen [Fri, 2 Apr 2021 19:04:07 +0000 (21:04 +0200)]
Use SCNetworkReachability on macOS and iOS to detect network changes.

Unfortunately, using SCDynamicStore*() functions to monitor network changes
is not supported in iOS. Instead, we now use SCNetworkReachability*()
functions which are supported on both macOS and iOS.

3 years agoFix a compiler warning.
Guus Sliepen [Fri, 2 Apr 2021 19:00:36 +0000 (21:00 +0200)]
Fix a compiler warning.

Clang doesn't like trailing commas in enums when compiling C++ code if no
-std= flag is passed.

3 years agoFix warnings from autoconf 2.71.
Guus Sliepen [Fri, 2 Apr 2021 18:59:13 +0000 (20:59 +0200)]
Fix warnings from autoconf 2.71.

This fixes the use of deprecated functions. Also bump the minimum required
version of autoconf to 2.69.

3 years agoCheck if SO_REUSEPORT is defined before using it.
Guus Sliepen [Wed, 17 Mar 2021 19:20:32 +0000 (20:20 +0100)]
Check if SO_REUSEPORT is defined before using it.

3 years agoRemove the catta submodule.
Guus Sliepen [Thu, 4 Mar 2021 16:12:32 +0000 (17:12 +0100)]
Remove the catta submodule.

3 years agoAdd meshlink_hint_network_change().
Guus Sliepen [Tue, 26 Jan 2021 21:55:21 +0000 (22:55 +0100)]
Add meshlink_hint_network_change().

This is intended to be used when there is no way for MeshLink to get
notifications of local network changes. It forces MeshLink to scan all
network interfaces for changes in up/down status and new/removed addresses,
and will immediately check if all connections to other nodes are still
alive.

3 years agoHandle network change detection on macOS and iOS.
Guus Sliepen [Sun, 18 Oct 2020 20:50:50 +0000 (22:50 +0200)]
Handle network change detection on macOS and iOS.

Apple has no usable PFROUTE sockets anymore, instead network change
detection should be done via SystemConfiguration callbacks. However,
actually parsing the messages is very annoying in C, so we only use it to
get notified of changes, we use getifaddrs() to get the actual list of
network interfaces and addresses.

The only issue is that interface up/down state changes do not result in a
notification, only interface and address addition/removal.

3 years agoImproved mDNS compliance.
Guus Sliepen [Tue, 18 Aug 2020 22:35:31 +0000 (00:35 +0200)]
Improved mDNS compliance.

Split the mDNS packets into separate request and response packets, and only
send responses when we receive a valid request.

It's now possible to find local MeshLink nodes using tools like dns-sd and
avahi-browse, if told to explicitly search for the _appname._tcp service.

3 years agoSet SO_REUSEPORT on the multicast sockets.
Guus Sliepen [Thu, 13 Aug 2020 21:29:06 +0000 (23:29 +0200)]
Set SO_REUSEPORT on the multicast sockets.

On Linux this doesn't make any difference, but on macOS this is required
if any other process has already opened an mDNS multicast socket locally,
otherwise bind() will fail.

3 years agoAdd local discovery support for macOS.
Guus Sliepen [Thu, 13 Aug 2020 20:48:06 +0000 (22:48 +0200)]
Add local discovery support for macOS.

This implements the pfroute counterpart to Linux's netlink interface.
Pfroute doesn't allow easy querying the current interfaces and addresses,
so we use getifaddrs() for that.

3 years agoFix outgoing connection attempts after local discovery.
Guus Sliepen [Mon, 13 Jul 2020 20:31:46 +0000 (22:31 +0200)]
Fix outgoing connection attempts after local discovery.

We were trying the wrong port due to a forgotten byteswap. Also, if no
address was known at all for a node, there might be an outgoing structure
for it that would never be retried.

3 years agoRemove debug messages.
Guus Sliepen [Sun, 12 Jul 2020 21:01:06 +0000 (23:01 +0200)]
Remove debug messages.

3 years agoWhen receiving an mDNS request, send a unicast response back.
Guus Sliepen [Sun, 12 Jul 2020 20:45:37 +0000 (22:45 +0200)]
When receiving an mDNS request, send a unicast response back.

3 years agoGroup discovery related variables together.
Guus Sliepen [Sun, 12 Jul 2020 19:45:10 +0000 (21:45 +0200)]
Group discovery related variables together.

3 years agoResend mDNS packets on all known addresses if meshlink_reset_timers() is called.
Guus Sliepen [Sun, 12 Jul 2020 19:36:53 +0000 (21:36 +0200)]
Resend mDNS packets on all known addresses if meshlink_reset_timers() is called.

3 years agoEnsure we compile discovery.c unconditionally.
Guus Sliepen [Sun, 12 Jul 2020 19:36:12 +0000 (21:36 +0200)]
Ensure we compile discovery.c unconditionally.

3 years agoDon't link with Catta anymore.
Guus Sliepen [Sun, 12 Jul 2020 19:11:32 +0000 (21:11 +0200)]
Don't link with Catta anymore.

3 years agoSend and receive multicast mDNS packets.
Guus Sliepen [Sun, 12 Jul 2020 15:31:40 +0000 (17:31 +0200)]
Send and receive multicast mDNS packets.

We don't actually support the full mDNS spec, we just send something that
passes for a valid mDNS packet, and expect other nodes to send packets back
with exactly the same format. All other mDNS packets will be ignored.

3 years agoKeep track of interfaces and local addresses.
Guus Sliepen [Fri, 10 Jul 2020 20:16:12 +0000 (22:16 +0200)]
Keep track of interfaces and local addresses.

3 years agoParse Netlink NEW/DELLINK and NEW/DELADDR messages.
Guus Sliepen [Sat, 27 Jun 2020 21:19:17 +0000 (23:19 +0200)]
Parse Netlink NEW/DELLINK and NEW/DELADDR messages.

Parse link and address information. Also send GETLINK and GETADDR
messages to the Netlink socket, so we get the current state of the
interfaces and addresses.

3 years agoMonitor a Netlink socket on Linux.
Guus Sliepen [Sat, 27 Jun 2020 17:01:34 +0000 (19:01 +0200)]
Monitor a Netlink socket on Linux.

3 years agoMonitor a PFROUTE socket on *BSD and macOS.
Guus Sliepen [Thu, 18 Jun 2020 20:41:12 +0000 (22:41 +0200)]
Monitor a PFROUTE socket on *BSD and macOS.

Catta is not handling network changes correctly on *BSD and macOS. In
particular, after the initial startup, interfaces that go up and down
do not cause a callback to be generated, so MeshLink is not notified of
the changes.

To ensure MeshLink responds rapidly to network changes on these
platforms, we open a PFROUTE socket and monitor it ourself. We only
check the message type, and don't track exactly what addresses get added
or removed.

3 years agoFix buffer shrinking logic in UTCP.
Guus Sliepen [Thu, 15 Apr 2021 17:50:20 +0000 (19:50 +0200)]
Fix buffer shrinking logic in UTCP.

Don't set the maximum size to low values; keep it at the minimum of the
previous size or of the default maximum size. If it is set to something
smaller than one MTU, this would prevent receiving packets from the
peer, and channel traffic would not progress and not close properly.

We also don't move memory when shrinking the internal buffer, so we
should keep the size large enough so the last byte in the buffer is
covered when the offset is non-zero.

3 years agoReduce UTCP memory usage.
Guus Sliepen [Sat, 10 Apr 2021 22:36:30 +0000 (00:36 +0200)]
Reduce UTCP memory usage.

Don't allocate a send buffer by default, since an application might only
want to receive data. Also try to shrink the send and receive buffers on
channel close, or even free them if the buffers are empty.

3 years agoFix compilation error on macOS.
Guus Sliepen [Fri, 9 Apr 2021 18:39:34 +0000 (20:39 +0200)]
Fix compilation error on macOS.

For some reason, macOS doesn't define asprintf() if you #define both
_GNU_SOURCE and _POSIX_C_SOURCE but no other feature macros.

3 years agoMake sure we #define _POSIX_C_SOURCE.
Guus Sliepen [Fri, 9 Apr 2021 18:15:56 +0000 (20:15 +0200)]
Make sure we #define _POSIX_C_SOURCE.

Some functions, such as clock_gettime(), officially require _POSIX_C_SOURCE
to be set to a minimum version in order to be usable.

3 years agoEnsure we don't use external buffers after a channel is closed.
Guus Sliepen [Thu, 8 Apr 2021 20:11:01 +0000 (22:11 +0200)]
Ensure we don't use external buffers after a channel is closed.

3 years agoFix a memory leak.
Guus Sliepen [Thu, 8 Apr 2021 20:09:45 +0000 (22:09 +0200)]
Fix a memory leak.

3 years agoAdd missing #include in test/utils.h.
Guus Sliepen [Wed, 24 Mar 2021 19:18:04 +0000 (20:18 +0100)]
Add missing #include in test/utils.h.

3 years agoFix potential channel buffer corruption when using an application-provided buffer.
Guus Sliepen [Wed, 17 Mar 2021 20:19:45 +0000 (21:19 +0100)]
Fix potential channel buffer corruption when using an application-provided buffer.

If data was still in MeshLink's internal buffer in a wrapped state, and
the application called meshlink_set_channel_*buf_storage(), the wrong
amount of data was copied into the new buffer.

3 years agoAllow sending up to 16 MiB in one go over a UDP channel. feature/huge-udp-channel-packets
Guus Sliepen [Thu, 3 Sep 2020 20:04:28 +0000 (22:04 +0200)]
Allow sending up to 16 MiB in one go over a UDP channel.

The application should set the channel send and receive buffers to be
able to hold the largest packet it expects to transmit and receive.

3 years agoAllow a different location for the lock file.
Guus Sliepen [Mon, 15 Feb 2021 22:48:09 +0000 (23:48 +0100)]
Allow a different location for the lock file.

In order to reduce the write load on the configuration directory as much as
possible, allow the location of the lock file to be set by the application
to somewhere outside the configuration directory. On Linux, it can be put
in /dev/shm.

3 years agoAdd missing config file update on receiving a proactive REQ_KEY request.
Guus Sliepen [Mon, 8 Feb 2021 17:14:38 +0000 (18:14 +0100)]
Add missing config file update on receiving a proactive REQ_KEY request.

A REQ_KEY request from a node that wants our key can contain their key as
well. The node status was not set to dirty in this case, which could
prevent their key from being written to disk with the default settings, but
this actually always forgot to write the key to disk with storage policy
set to KEYS_ONLY.

3 years agoImmediately write host config file when a new key is received.
Guus Sliepen [Fri, 5 Feb 2021 22:27:27 +0000 (23:27 +0100)]
Immediately write host config file when a new key is received.

When we receive a new public key, we should immediately call
node_write_config() to ensure it gets saved if the storage policy is
KEYS_ONLY.

3 years agoExpand the storage policy test to check for correctness during invitations.
Guus Sliepen [Thu, 4 Feb 2021 21:47:25 +0000 (22:47 +0100)]
Expand the storage policy test to check for correctness during invitations.

3 years agoDon't allow meshlink_join() when the storage policy is DISABLED.
Guus Sliepen [Thu, 4 Feb 2021 21:46:58 +0000 (22:46 +0100)]
Don't allow meshlink_join() when the storage policy is DISABLED.

It does not make sense to allow this, since we need to write host config
files during a join, otherwise MeshLink's directory would be left in an
invalid state.

3 years agoAdd a test for the various storage policies.
Guus Sliepen [Wed, 3 Feb 2021 22:31:18 +0000 (23:31 +0100)]
Add a test for the various storage policies.

3 years agoDon't clear node dirty flag in meshlink_stop().
Guus Sliepen [Wed, 3 Feb 2021 22:30:36 +0000 (23:30 +0100)]
Don't clear node dirty flag in meshlink_stop().

It's node_write_config() itself that should unset the dirty flag, depending
on the storage policy and if storage succeeded. Otherwise, we risk that
setting the storage policy back to ENABLED after calling meshlink_stop()
will not cause pending updates to be written out by meshlink_close().

3 years agoAdd meshlink_set_storage_policy().
Guus Sliepen [Fri, 29 Jan 2021 21:59:57 +0000 (22:59 +0100)]
Add meshlink_set_storage_policy().

This allows control over when MeshLink stores configuration files:

- MESHLINK_STORAGE_ENABLED: on all updates
- MESHLINK_STORAGE_KEYS_ONLY: only on new keys and black/whitelist updates
- MESHLINK_STORAGE_DISABLED: never

3 years agoAllow the application to provide channel send/receive buffers.
Guus Sliepen [Thu, 18 Feb 2021 19:57:23 +0000 (20:57 +0100)]
Allow the application to provide channel send/receive buffers.

This adds two new functions to allow the application to allocate send
and/or receive buffers for channels:

meshlink_set_channel_rcvbuf_storage(mesh, channel, buf, size)
meshlink_set_channel_sndbuf_storage(mesh, channel, buf, size)

3 years agoAdd meshlink_set_channel_flags().
Guus Sliepen [Tue, 23 Feb 2021 18:56:31 +0000 (19:56 +0100)]
Add meshlink_set_channel_flags().

This allows changing some of the flags of a channel. Currently it can be
used to change MESHLINK_CHANNEL_NO_PARTIAL and MESHLINK_CHANNEL_DROP_LATE.

3 years agoAdd missing checks for NULL mesh pointers in the public API.
Guus Sliepen [Tue, 23 Feb 2021 18:55:01 +0000 (19:55 +0100)]
Add missing checks for NULL mesh pointers in the public API.

3 years agoAdd warning messages when checking for bad fds after select() returns an error.
Guus Sliepen [Sun, 21 Feb 2021 21:11:52 +0000 (22:11 +0100)]
Add warning messages when checking for bad fds after select() returns an error.

3 years agoNever call timeout_set() outside callbacks if no callback is set.
Guus Sliepen [Mon, 15 Feb 2021 21:16:04 +0000 (22:16 +0100)]
Never call timeout_set() outside callbacks if no callback is set.

We should never try to update a timer if it was never added to the event
loop. There were a few places that didn't have an explicit check to
prevent this from happening.

3 years agoTry to recover from select() returning an error.
Guus Sliepen [Tue, 9 Feb 2021 20:00:35 +0000 (21:00 +0100)]
Try to recover from select() returning an error.

If we get an error back from select(), it could be because one of the
filedescriptors is in a bad state. This shouldn't occur, but if it does,
just call all the registered I/O callbacks to have them check for errors.
Only quit the event loop if the error persists.

Also fix some I/O callbacks that didn't expect to be called when the
filedescriptor isn't signalled.

3 years agoFix a socket fd leak.
Guus Sliepen [Mon, 1 Feb 2021 13:07:54 +0000 (14:07 +0100)]
Fix a socket fd leak.

Due to a logic error, whenever an interface went down and up, one or
more socket fds could be leaked. A long running process on a roaming
device or an unstable network could therefore run out of fds.

3 years agoCheck the return value of catta_simple_poll_get().
Guus Sliepen [Mon, 25 Jan 2021 20:00:47 +0000 (21:00 +0100)]
Check the return value of catta_simple_poll_get().

This ensures we gracefully handle the case of Catta not being able to bind
to the NETLINK_ROUTE socket.

3 years agoUse AI_* instead of NI_* constants for getaddrinfo().
Guus Sliepen [Thu, 14 Jan 2021 21:10:45 +0000 (22:10 +0100)]
Use AI_* instead of NI_* constants for getaddrinfo().

3 years agoSend our canonical address to nodes we want to communicate with.
Guus Sliepen [Wed, 30 Dec 2020 13:55:35 +0000 (14:55 +0100)]
Send our canonical address to nodes we want to communicate with.

This ensures canonical addresses are propagated automatically, and can be
used when making meta and UDP connections.

3 years agoClean up the request jump table.
Guus Sliepen [Wed, 30 Dec 2020 13:53:46 +0000 (14:53 +0100)]
Clean up the request jump table.

Use C99 designated array initializers to ensure the jump table and list of
request names is kept in sync with the enums.

3 years agoUse the canonical address during UDP probes.
Guus Sliepen [Wed, 30 Dec 2020 13:50:56 +0000 (14:50 +0100)]
Use the canonical address during UDP probes.

It is possible that a node has a canonical address, but due to NAT or other
reasons, the meta-connections with that node use other addresses. If UDP is
only possible to the canonical address, then we need to include that during
the initial UDP probing phase.

3 years agoAdd missing calls to init_sync_flag() in test cases.
Guus Sliepen [Sun, 6 Dec 2020 15:18:18 +0000 (16:18 +0100)]
Add missing calls to init_sync_flag() in test cases.

3 years agoFix deleting configuration directories with hidden files.
Guus Sliepen [Sun, 6 Dec 2020 15:17:58 +0000 (16:17 +0100)]
Fix deleting configuration directories with hidden files.

We incorrectly skipped files starting with a dot when deleting directories.
This is a problem on macOS, which might add .DS_Store files.

4 years agoFix potential NULL pointer dereference.
Guus Sliepen [Sun, 22 Nov 2020 10:59:54 +0000 (11:59 +0100)]
Fix potential NULL pointer dereference.

It is possible that an attempt is made to forward a request to a node
that is not reachable via meta-connections. This would trigger an assert
in debug builds, or cause a segmentation fault in release builds. Add
checks before attempts to send a request to node->nexthop->connection.

4 years agoDon't try to renew SPTPS keys for unreachable nodes. fix/deterministic-sptps-reset
Guus Sliepen [Mon, 16 Nov 2020 19:57:46 +0000 (20:57 +0100)]
Don't try to renew SPTPS keys for unreachable nodes.

This caused other functions that incorrectly used status.validkey to check
if they could send data to a node to pass a NULL pointer to send_request(),
causing a crash about an hour after a node went offline.

4 years agoOnly reset UDP SPTPS sessions if the session ID changed.
Guus Sliepen [Tue, 10 Nov 2020 20:10:00 +0000 (21:10 +0100)]
Only reset UDP SPTPS sessions if the session ID changed.

Previously we reset the SPTPS session if we detected if a node was
unreachable. However, that node might not think it was unreachable,
leading to only one side to reset the SPTPS connection. This would then
take some time to resolve itself.

We already had code to detect whether a node was restarted, so we use
that to detect if, once a node becomes reachable again, it remembers the
old SPTPS session or whether we have to start a new one. This should be
deterministic and not depend on the exact timing of events.

4 years agoAlso send the blacklist notification when we already have a connection.
Guus Sliepen [Thu, 29 Oct 2020 22:38:22 +0000 (23:38 +0100)]
Also send the blacklist notification when we already have a connection.

Instead of just closing the connection, and having to wait for the
reconnection to happen to send the blacklist notification, we do it
immediately when meshlink_blacklist() is called.

4 years agoAdd a callback that notifies the application when it is blacklisted.
Guus Sliepen [Thu, 29 Oct 2020 22:30:41 +0000 (23:30 +0100)]
Add a callback that notifies the application when it is blacklisted.

If an outgoing connection is made to a node that blacklists the local node,
a callback can now be set that informs the application of it.

4 years agoFix Doxygen errors.
Guus Sliepen [Sun, 25 Oct 2020 21:20:43 +0000 (22:20 +0100)]
Fix Doxygen errors.

4 years agoAdd API functions to query the blacklist status of nodes.
Guus Sliepen [Sun, 25 Oct 2020 21:18:53 +0000 (22:18 +0100)]
Add API functions to query the blacklist status of nodes.

4 years agoCheck blacklist status before committing an invitation.
Guus Sliepen [Sun, 25 Oct 2020 21:17:29 +0000 (22:17 +0100)]
Check blacklist status before committing an invitation.

Although we delete invitation files when blacklisting a node, there is a
race condition where an invitation connection is created right before the
invitee is blacklisted. So check that the node is blacklisted right before
committing the node config file to disk.

4 years agoRemove invitation files when blacklisting or forgetting a node.
Guus Sliepen [Sun, 25 Oct 2020 21:15:04 +0000 (22:15 +0100)]
Remove invitation files when blacklisting or forgetting a node.

4 years agoWhen a new connection is activated, terminate any pending connections to the same...
Guus Sliepen [Sun, 11 Oct 2020 14:16:31 +0000 (16:16 +0200)]
When a new connection is activated, terminate any pending connections to the same peer.

This prevents issues mainly in the test suite where peers try to connect to
each other simultaneously, and have to terminate one of the connections.
Before both connections would succeed, and both would be terminated, leading
to a loop of reconnections until enough randomness got in to break the tie.

4 years agoDon't reset the UDP SPTPS session when a node becomes reachable.
Guus Sliepen [Sun, 11 Oct 2020 13:40:34 +0000 (15:40 +0200)]
Don't reset the UDP SPTPS session when a node becomes reachable.

Only do this when it becomes unreachable. This fixes an issue where right
after a meta-connection is established, the initiator sends a proactive
REQ_KEY, before the peer really becomes reachable according to the graph.
When the latter happened, it would reset the session so far, causing a new
REQ_KEY to be sent, which could cross the ANS_KEY from the peer. This would
resolve itself after a few seconds, but causes an unnecessary delay that is
easy to trigger.