Commit graph

169 commits

Author SHA1 Message Date
Maximilian Nitsch
35369c18ce fix: CLA_SQLITE_AGENT_QUEUE_LENGTH 2024-04-16 13:13:08 +02:00
Maximilian Nitsch
50fcf70a75 cla/cla_contact_rx_task: Exclude SQLiteCLA from EID spoofing detection
If bundles that were created by the μD3TN instance itself are stored in
the database via the SQLiteCLA and are received again at a later point
in time, μD3TN recognizes that the source node ID matches its own and
EID spoofing is detected.

This commit adds an exception to perform EID spoofing detection only for
packets that were not received by the SQLiteCLA.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-04-15 11:05:21 +02:00
Maximilian Nitsch
bc54b1323c sqlite_agent: Add an agent to interact with the SQLiteCLA
The SQLiteAgent enables SQLiteCLA to read packages from the database and
return them to μD3TN. For this purpose, the SQLiteAgent writes commands
to the queue that SQLiteCLA is waiting for.

The SQLiteAgent itself can be controlled by protobuf messages that
describe which action is to be applied to which set of bundles.

Currently the operations "Push" and "Delete" are implemented and a
filter based on a destination EID pattern.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-04-15 11:05:20 +02:00
Maximilian Nitsch
649c38fc67 cla_sqlite: Implementation of the SQLite-based storage back-end
The SQLiteCLA makes it possible to write bundles, that are to be sent
via this CLA, to an SQLite database in order to persist them over a
longer period of time and also a restart of μD3TN.

The bundles are saved together with selected metadata (source EID,
destination EID, creation timestamp) in the "bundles" table. A
combination of source EID and creation timestamp is used as the primary
key.

To return bundles to μD3TN, they are read from the database and injected
via the cla_read() function, just like other CLAs that receive bundles.
To trigger this, commands are read from a queue that specify which
bundles are to be read from the database.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-04-15 10:37:45 +02:00
Maximilian Nitsch
81354633bf cla_sqlite: Add SQLite-based storage CLA skeleton
In order to prepare the implementation of a SQLite-based storage CLA, a
basic structure of this CLA with empty functions is created and
adjustments are made to the configuration/initialization functions and
the build system.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-02-26 10:31:40 +01:00
Maximilian Nitsch
c56a1acbe4 cla: Pass a pointer to the bundle to the cla_begin_packet function
Some CLAs may require access to the bundle meta data to perform actions.
Instead of parsing the raw bytes back to a bundle object, a pointer is
passed to the cla_begin_packet function.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-02-12 13:30:32 +01:00
Maximilian Nitsch
e2cb2a12a2 CLA: Terminate all CLAs gracefully
To enable CLA implementers to properly clean up the allocated resources,
a virtual function `cla_terminate` is added to the CLA interface, which
is called at process termination for all registered CLAs.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-01-26 14:28:51 +01:00
Maximilian Nitsch
36b92c5e41 hal_task: Replace sigaction exit handler by sigwait
In order to properly clean up all resources allocated by threads, we
need to join the non-detached threads. This is not possible within the
`sigaction` exit handler function. For this reason, the termination
logic is changed to use `sigwait`.

In addition, SIGALRM is added to the list of handled signals and
SIGUSR1, SIGUSR2 are ignored.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-01-26 14:28:50 +01:00
Maximilian Nitsch
3935a15441 hal_task: Make detached threads optional
Adds a parameter to the `hal_task_create()` function to allow
non-detached threads and a second parameter to pass the thread
identifier.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-01-23 15:25:59 +01:00
Felix Walter
0173d67ac6 CLA: Store rate limiting config per contact/link task
This moves the rate limiting configuration from the general TCP CLA
config (which is per-CLA instance) to the link task parameters. This
way, rate limiting is per contact and not per CLA, which is important
for multi-connection CLAs.

Fixes: #177

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-21 08:47:52 +01:00
Felix Walter
5f5269ec1a
Merge branch 'feature/162-clean-up-hal-task'
See !150
2023-12-20 16:25:50 +01:00
Felix Walter
2601666049
Merge branch 'feature/172-log-errno-log-levels'
See !149
2023-12-20 16:25:38 +01:00
Felix Walter
7fcdeab31d Remove hal_config headers
They are unnecessary now. We should do platform-specific definitions
centrally via config.mk as well.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 10:32:48 +01:00
Felix Walter
75edf0cbd7 hal_config: Remove LINUX_SPECIFIC_API switch
We only used it for thread naming - the hal_platform malloc analysis
support was removed a long time ago. As we do not really need thread
naming and removed it when cleaning up hal_task, we do not need this
define anymore.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 10:32:48 +01:00
Felix Walter
47194d21ac hal_task: Remove unused parameters
This removes the parameters for task name, priority, and stack size,
which were mostly relevant for FreeRTOS on STM32.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 10:32:48 +01:00
Felix Walter
0742de7ba9 hal_io: Print log level when printing system errors
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 10:06:48 +01:00
Felix Walter
9917bab703 hal_io: Implement log levels for LOG_ERRNO
This enables us to use log levels for `LOG_ERRNO`. The default is the
"warning" level so that we do not need to adjust all calls. The levels
for connection establishment and receiving from sockets are adjusted to
"info" such that common cases like unreachable peers do not
unnecessarily clutter the logs.

Fixes: #172

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 10:04:17 +01:00
Felix Walter
c543afd3aa CLA: Make infinite retries the default
As we are ensuring that retries happen with a delay in between we can
infinitely retry connections during a contact. This ensures we can
establish a connection even if the peer becomes available significantly
later than the contact starts on our side. The setting can be configured
in `config.mk`.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 09:38:01 +01:00
Felix Walter
bcf6a49f43 CLA: Make abort() on final CLA link task termination optional
uD3TN can continue to run in this case, just without the given CLA. This
introduces a compile-time switch to select whether we want to kill uD3TN
in case a CLA finally fails.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 09:36:43 +01:00
Felix Walter
6e8f2d13eb CLA: Enable central rate limiting for all TCP CLAs
This removes existing dedicated rate limiting logic for connection attempts
in favor of the time-based detection and implements a maximum number for
retry attempts in the latter.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 09:25:59 +01:00
Felix Walter
5c8b92e7de CLA: Implement rate limiting for TCP connection attempts
This checks the time the given CLA tried to connect beforehand and
delays the next connection attempt in case the last attempt was more
recent than `CLA_TCP_RETRY_INTERVAL_MS`.

Fixes: #44

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 09:02:49 +01:00
Felix Walter
6525a453ba Adjust all logging calls to include a log level
Rules that have been applied:

- ERROR: Anything that is or may be problematic for the program to
  continue running.
- WARN: Anything abnormal but definitely not critical for program
  continuation, especially issues encountered when interacting with
  clients (e.g. AAP).
- INFO: All state changes not corresponding to the "normal" processing of
  individual data or messages/bundles, as well as further informative and
  helpful messages. Includea errors that occur during normal data
  processing.
- DEBUG: Messages to trace what happens with individual bundles and
  other fine-grained information about internal processes.

At the moment, `LOG_ERRNO` always emits messages with the "ERROR" level.
We might want to change this in the future to better differentiate WARN
and ERROR in this regard also.

Closes: #140
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-24 14:50:25 +01:00
Felix Walter
7b7ff98a2d cmdline, config.mk.example: Make it clear that log level 4 is debug-only
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
8dbbb9d692 hal_io: Add LOG(F)_INFO to explicitly log with "INFO" level
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
1b1285c126 cmdline: Set default log level for release builds to 2 (WARNING)
This reduced unnecessary clutter by default if we do not want to debug
uD3TN. Should also slightly increase performance by issuing less
`printf` statements.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
f02fdc042d hal_io: Protect logging via mutex
This resolves the race condition documented in #139.
The log macros now each call only a single function which locks
a binary semaphore during execution.

Fixes: #139

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
485a06b381 AAP, AAP2: Move common socket handling parts to dedicated module
There is some common functionality that should not be copied.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-09 14:33:48 +01:00
Felix Walter
536aee55fd aap2: Check secret for new agent registrations
If there is already an agent registered for the other direction of
communication, registration will fail as long as the provided secrets do
not match.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
144233985a agent_manager: Pass agent as struct
This simplifies the function signatures and enables easy extension
without adapting them in the future.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
4b5a6e2da3 bundle_processor: Pass signal and agent via struct
This prevents the need for passing unset fields as NULL and removes the
need to change the function signature everytime the structs are
extended.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
a0b2fe8909 aap2: Receive response from bundle subscribers
We specify AAP 2.0 to be an RPC protocol whereas the direction of calls
can be switched during configuration. Each call needs to be answered.
This change adds the answer for bundle reception by a client.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
bef31704c5 aap2: Add an AAP2 implementation matching the current AAP feature set
This is a "meta-agent" based on the current AAPv1 implementation
(`application_agent.c`), which runs the new AAP2 protocol that is
implemented via Protobuf (using NanoPB). Please refer to the
corresponding design documents for further information on the protocol
itself.

Beside the on-wire encoding and future extension capabilities, the primary
difference from AAPv1 to AAP2 is that a connection is now a
unidirectional RPC-like channel. This ensures that acknowledgments
cannot be easily get out of order and makes client implementations
simpler. However, it also means that now a shared secret needs to be
passed by clients to enable registering for the same agent ID.

The following limitations of this first implementation are present:
- Only sending and receiving ADUs is supported.
- The shared secret is not checked - any app can register for the same
  agent ID as long as no other app has yet registered for the requested
  direction (subscribe or non-subscribe).
- Only one client per direction is supported at the moment. (It is at
  least planned to support multiplke subscribers for an agent ID.)
- The server does not expect acknowledgments from clients when they
  receive ADUs.
- The keepalive mechanism is not implemented.

In general, this reflects the feature set of AAPv1, but with massive
extension opportunities.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
569bd18e76 bundle: Add creation timestamp to ADU metadata
We would like to propagate timestamp and sequence number to AAP 2
clients.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
78def25108 agent_manager, bundle_processor: Support registering RPC-only agents
This adds a second type of agent registration for agents that do not
receive any bundles or events. It is the first step toward splitting all
agent registrations in two parts, depending on the direction of data
flow. In the future, a shared secret will need to be provided to ensure
that an agent is authorized for a given registered agent ID.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
7afe93447f eid: Add a function to obtain a pointer to the agent ID
All supported EID schemes currently have the "agent ID" (i.e., the `dtn`
demux part or the `ipn` service number) right at the end of the EID.
Thus, we can provide a function to return a pointer to it for quickly
and efficiently working with the agent ID.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
1dd5961bc4 Add AAP 2.0 component stub with Protobuf support via Nanopb
This adds the Nanopb library as submodule under `external/` and adds
corresponding build configuration to the Makefiles. Additionally, a
Protobuf stub for AAP 2.0 is included along with a `make` target to
build the corresponding C language files (`aap2-proto-headers`).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-08 15:11:52 +01:00
Felix Walter
c75c544a11
Merge branch 'feature/106-config-via-build-system'
See !129
2023-10-27 08:40:16 +02:00
Felix Walter
08b4a1d34f Move definition of _POSIX_C_SOURCE and _DEFAULT_SOURCE to posix.mk
We want to be able to use POSIX extensions such as `strdup` and should
not define this in every individual source file. It is similar to the
definition of which C standard to use and should thus be defined in the
makefiles.

We use the X/Open feature test macro to include all needed functionality
also under other platforms such as BSD.

See also: https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-10-25 15:56:57 +02:00
Felix Walter
c945da6bf6 hal_config.h: Allow for changing AAP and Linux-spefific defs
For two settings previously defined in `hal_config.h` it makes sense to
make them changeable via `config.mk`. The AAP setting is moved to the
appropriate header and the Linux-specific APU define gets a guard so it
can be changed at compile time.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-10-25 15:56:53 +02:00
Felix Walter
26e91ad69e Remove config.h: Move all definitions to individual headers
This moves all definitions from config.h to individual header files and
makes them configurable (i.e., does not define when already defined).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-09-29 14:43:21 +02:00
Felix Walter
ee6288aa4f eid, cmdline: Support local node IDs without slash (dtn) or dot (ipn)
This adds trailing parts to the "local EID" specified on the command line
when required, so the user interface is more tolerant to abbreviated
representations such as 'dtn://node.dtn' and 'ipn:1'.

Closes: #129

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-09-27 17:36:32 +02:00
Felix Walter
9b5d82401f eid: Consider EIDs longer than INT16_MAX-1 invalid
This is a safeguard against potential buffer/int overflows. Realistically,
we should never see such long EIDs.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-09-27 17:24:29 +02:00
Felix Walter
95b8a36fd2 hal_io: Do not reuse macro argument
This may lead to side effects (discovery by the style checker).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-07-28 15:04:50 +02:00
Felix Walter
7330c79b52 style: Spacing, indentation, long lines, continuations
This harmonizes several style issues found by `checkpatch.pl` when using
strict mode.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-07-25 13:15:05 +02:00
Felix Walter
63218344e0 include: Prevent side-effects in macros
Wrap arguments and do not use them multiple times.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-07-25 13:15:05 +02:00
Felix Walter
75987092d2 common: Remove macros to free list
It is better to do that explicitly and the macros were reusing the macro
arguments, which may lead to side effects. We were using this in only
one place which is substituted by an explicit loop to free the list.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-07-25 13:15:05 +02:00
Felix Walter
59b9988587
Merge branch 'feature/add-log-levels'
See !123
2023-07-25 12:07:43 +02:00
Oleksandr Nazymko
bfa565d420 Enable debug log statements in debug build only
This removes the `DEBUG` log statements when compiling with `type=release`
for better performance.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-14 14:20:11 +02:00
Oleksandr Nazymko
da35fa6e6d Pass log level to init.c and adjust log message format
This adds log level to `ud3tn_cmdline_options` struct so that command line parser passes the value to `init.c` and has no side effects. Also adjusts log message format
for printing out current log level.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-14 14:09:08 +02:00
Felix Walter
f2fc65c33f
Merge branch 'feature/fuzzer-binary'
See !91
2023-07-14 10:09:47 +02:00