Commit graph

62 commits

Author SHA1 Message Date
Felix Walter
fb2d0b021c cla, mk: Fix disabling SQLite functionality
Previously it was not possible to disable SQLite because of a linker
error. Also, `sqlite3.h` was always required to be present. This adds
an example to `config.mk.example` and fixes both issues.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 17:03:39 +02:00
Felix Walter
553cb23bdd Fix constParameter and constVariable warnings by cppcheck
This improves const correctness, at least for pointers (making the
pointed-to data const where possible).

Some suppressions are added for false positive warnings, such as in
`simple_queue.c` where an arithmethic operation is used on the pointer
to calculate a non-const pointer that is returned (thus, the passed
pointer should also not point to const).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:13:21 +02:00
Felix Walter
3068d695cd CLA: Report synchronous link status updates synchronously
This fixes another potential deadlock: The BP calls the "start contact"
function of a CLA, which in turn discovers that the link is already
active and attempts to put a notification of link establishment into the
BP queue, which may be full and is not consumed as this is running in
the BP thread.

The solution here adds an extended return value for the start and end
contact functions in the CLA interface, enabling them to indicate to the
BP whether a link change has been initiated (and will be performed
asynchronously), is not necessary (the state is already the intended
one), or was performed synchronously.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-30 11:07:36 +02:00
Felix Walter
9412a45256 CLA: Remove unused planned definition of cla_destroy
We have implemented `cla_terminate` that fulfils the planned purpose of
`cla_destroy`.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-30 08:55:36 +02:00
Felix Walter
ee59a74443 aap2, cla, cmdline: Pass maximum bundle size to BDM
We should be able to honor the fragmentation threshold again. This
passes the maximum bundle size variable to the AAPv2 agent. The value is
determined as the minimum of all maximum bundle sizes reported by the
CLAs and the one specified on the command line, with the special case
of the value 0, which means a maximum bundle size of 2^64 ("unlimited").

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-07-04 16:00:30 +02:00
Felix Walter
3fc93b6507 aap2: Pass the next-hop node ID and CLA address to the BDM
When transmission had been attempted and generated a "TX
success/failure" result, the BDM will need the information which
transmission is affected by the generated dispatch. Additionally, the
term "DispatchRequest" is imprecise, as uD3TN does not require the BDM
to dispatch the bundle in any case (it can do so, but especially after
TX success/failure, oftentimes, it is intended to just proceed with
normal bundle processing).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-25 10:25:12 +02:00
Felix Walter
4de60633ba cla: Increase default CONTACT_TX_TASK_QUEUE_LENGTH to 100
Some CLAs may block sending to the underlying layer, e.g., the storage
CLA may wait for the DB to become ready. This increases the default
queue length to prevent blocking the BP in such cases.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 11:16:07 +02:00
Felix Walter
8aaf458a1f cla_sqlite: Set busy timeout to 100 ms
Read transactions need a short, blocking, lock for the database, during
which no write transaction can be started - this means the interaction
of the agent, TX, and RX tasks may block each other if anything takes
longer than 1 ms. Thus, we increase the timeout for blocking locks to
100 ms to significantly reduce that probability.

See: https://www.sqlite.org/src/doc/204dbc15a682125c/doc/wal-lock.md

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 11:16:07 +02:00
Felix Walter
38d5d7d96f cla_sqlite: Register and create FIB entry on launch
This is required to allow bundles being forwarded to storage by
specifying the storage node (a configuration parameter) as next hop.

The CLA initialization is modified slightly to register the CLA before
executing `cla_launch` to ensure that the bundle processor knows about
it when it is executed.

This also moves the Sqlite CLA initialization to the `sqlite_launch`
function because the CLA has to be known ("registered") before we send
a signal to the BP (which is done during link creation).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
6d2f204af5 Replace integrated next-hop forwarding with AAP 2.0
This adds functionality to dispatch bundles and control the FIB to AAP
2.0 and the bundle processor, replacing the old "router" completely.
AAP 2.0 is extended slightly to enable fragmentation.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-17 13:33:32 +02:00
Felix Walter
332323bed3 Adapt license of new files to AGPL-3.0
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-03 13:45:19 +02:00
Maximilian Nitsch
55f762b804 SQLiteCLA: Use WAL journal mode and a busy timeout instead of retries
https://www.sqlite.org/wal.html
https://www.sqlite.org/src/doc/204dbc15a682125c/doc/wal-lock.md

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-06-03 13:41:58 +02:00
Maximilian Nitsch
6a0a453b2f SQLiteCLA+Agent: Retry SQL statements if BUSY or LOCKED
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-06-03 13:41:58 +02:00
Maximilian Nitsch
b7ce5ef89b SQLiteCLA+Agent: Extend StorageCall Protobuf definition
- Introduces a CompoundBundleId to filter exactly one bundle
- Filter bundles either by their ID or selected metadata
- Transfer the entire StorageCall object to the CLA via the agent queue

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-06-03 13:41:58 +02:00
Maximilian Nitsch
4fa34c69b3 SQLiteCLA+Agent: Execute select statement in CLA
To eliminate potential race conditions where rows are deleted before the
CLA processes them, the select statement is moved from the agent to the
CLA and everything is wrapped in a transaction to read all or nothing.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-06-03 13:41:58 +02:00
Maximilian Nitsch
589db818ae 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-06-03 13:41:58 +02:00
Maximilian Nitsch
de33e8cc51 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-06-03 13:41:58 +02:00
Maximilian Nitsch
218246e789 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-06-03 13:41:58 +02:00
Maximilian Nitsch
21face2000 cla: Add return values to CLA transmission functions
To indicate errors during the execution of the CLA transmission
functions, return values are added and checked by the TX task.
2024-06-03 13:41:58 +02:00
Maximilian Nitsch
cfb8bc17fe 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-06-03 13:41:58 +02: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
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
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
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
f2fc65c33f
Merge branch 'feature/fuzzer-binary'
See !91
2023-07-14 10:09:47 +02:00
Felix Walter
99d3cf5ec1 cla_tcp_util: Include sys/socket.h for struct sockaddr
See !115, appears the include was missing.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-06-06 13:01:04 +02:00
Felix Walter
e16ec4c579 Enable building a BPv7 decoder binary
This adds a target `data-decoder` which builds a binary to decode a
specified binary file using uD3TN's parsing logic (based on the CLA RX
subsystem) and print details about it. In this first version only the
decoding of BPv7 bundles is implemented.

This binary can be used, e.g., for fuzz testing.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-16 11:34:14 +02:00
Felix Walter
1237eaa2db Remove heap-allocated Task_t
`hal_task_create` returned a reference to the new task allocated on the
heap via `malloc`. We commonly used the pattern to `free` this reference
from the new thread which, however, could result in race conditions and
other synchronization issues. We added a fix using a semaphore in the
application agent, but this would have been needed in other places (CLA,
...) as well. As we do not make use of the task reference anywhere
besides in the CLA for error handling, we can remove the heap-allocated
value altogether and replace it with an `enum ud3tn_result` to simplify
things and circumvent the named synchronization issues.

In the case of the CLA function `cla_link_init`, logic is introduced to
request the RX task to exit immediately in case the TX task cannot be
launched.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:23:55 +02:00
Felix Walter
af462184b3 CLA: Synchronize access to link parameter data structure
The primary issue that was also identified by Clang's thread sanitizer
was that we were accessing fields like `link->active` from multiple
threads concurrently. See [1], especially under optimizations such a
variable cannot be used to tell other threads when to terminate.

The primary fix here is to introduce a guarding mutex (binary semaphore)
around the "link parameters" data structures in all connection-oriented
CLAs. The mutex is only locked when working with the structure and
should always be unlocked when a blocking operation (e.g., `accept()`,
`send()`, `recv()`) is executed. To achieve this, we sometimes store the
return value of such functions in a temporary variable before re-locking
the mutex and adapting the param struct.

The `cla_link_wait_cleanup` routine is split in two parts so that during
the "wait" operation the mutex can be unlocked and when cleaning up the
link (consequently needing to update and drop resources from the link
parameters) it can be locked.

The "serializer functions" (`*_begin_packet`, `*_send_packet_data`,
`*_end_packet`) do not need to ckech for `link->active` anymore (which
is removed) as it is made sure to terminate the TX task invoking the
serializer before invalidating the link structures. If anything is
invalidated by the OS (e.g., by the TCP connection breaking), an error
will occur in these functions and propagate to the TX task, leading to a
call to the `cla_disconnect_handler`, in turn tearing down the link, but
the link parameters will be 100% valid the whole time.

Additionally, to notify the RX task when it should exit, another semaphore
is introduced. The TX task already has a thread-safe queue to send a
notification to it to terminate, removing the need for another check.

The locking of the "param hash table", where the "link parameters" are
stored is revised such that it is always locked while changes occur to
it or the values stored inside it (as long as they are not locked
themselves by the specific param semaphore.

[1] https://github.com/google/sanitizers/wiki/ThreadSanitizerPopularDataRaces

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:07:13 +02:00
Felix Walter
2b3a76c409 cla_bibe: Fix out-of-bound write
The BIBE CLA allocated a buffer the size of sizeof(struct aap_message)
but then serialized an AAP message into it. It should have used
aap_get_serialized_size(), though, this change directly removes the
unnecessary buffer in between and directly writes out the data.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 11:10:24 +02:00
Felix Walter
69eab551ab Transmit the whole list of bundles in the TX queue
This reduces the number of queue sends as the whole bundle list is
transmitted by the CM to the TX task which then consumes it iteratively.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 21:02:38 +01:00
Felix Walter
93a58ed387 Merge Bundle Processor and Router Task
This refactors the Router Task into synchronous functions called by the
BP, preventing the need of circular notifications between them.
The router queue is replaced by new signals in the BP queue.

This additionally removes the global state in the bundle processor.

Closes: #11

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 21:02:36 +01:00
Felix Walter
f8395e8d94 router: Remove probabilities and struct routed_bundle
The probability-based routing was never used productively. It implied
that we store all the contacts for which a bundle was scheduled (as
there may be more than one) and keep it, doing reference counting before
we drop the data structure, and so on. This change removes everything
probability-related. The field in the config commands is kept to ensure
backwards compatibility if this is specified.

The removal of struct routed_bundle allows for a major simplification of
all routing-related code.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:59:43 +01:00
Felix Walter
3ade800bd5 Always spawn an RX task in TCP CLAs
We need to recv() on the TCP socket to detect it when the connection is
closed or reset.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:56:39 +01:00
Felix Walter
6663ac4f8f CLA: Allow unidirectional links and specify directions upon link init
Some CLAs such as MTCP use unidirectional links. In these cases, we
should not start a TX _and_ RX task. This adds two parameters to
cla_link_init to specify the direction(s) used by the created link.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:56:39 +01:00
Felix Walter
db293b5020 CLA: Report proper CLA address to router
Previously we did not include the CLA name. This also removes the
unnecessary `cla_type` field in the struct, whose value can easily be
obtained by the `cla_name_get()` function.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:36:49 +01:00
Felix Walter
4d8bbd9a8e CLA: Communicate CLA address in link up/down signals
This informs the router also of the address of the connected peer in the
relevant signals issued by the CLA subsystem to the router task

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:36:49 +01:00
Felix Walter
d8fef5c776 TCPSPP: Ensure the maximum SPP size is never exceeded
This will abort execution in case the CLA attempts to issue an SPP
packet larger than the maximum SPP size. For this purpose a
configuration parameter is added that may be adapted to the connected
communication subsystem. The router ensures that this should not occur,
but we add an additional safety check as some CCSDS engines may be
placed into an invalid state in case they are confronted with too large
SPP packets, which must not occur in productive environments.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-11-24 20:28:14 +01:00
Marius Feldmann
691b7c3172 Remove STM32/FreeRTOS support from uD3TN
Former releases of uD3TN have included support for STM32/FreeRTOS.
Having this support from the first moment on was a good thing in
order to optimize for platforms with limited resources. As this
platform is not used in current uD3TN setups and as it results in quite
some maintenance work, it is removed with this commit. The removed parts
cover the implementation itself, tests, tools, documentation, parts of
the build/make scripts as well as licensing information.

Signed-off-by: Marius Feldmann <marius.feldmann@d3tn.com>
2022-03-22 00:05:13 +01:00
Georg Alexander Murzik
298431c68f Insert SPDX license expression comments into our .c, .h, .py, and .sh code
ud3tn is available under multiple licenses and we want to reflect this in
our source code. But which license information should appear first and how
can we manage this efficiently in the future? The Linux Kernel uses SPDX
expressions instead of boilerplate sections. This seems to be a great
approach, so we do the same here.

Signed-off-by: Georg Alexander Murzik <georg.murzik@d3tn.com>
2022-02-20 16:24:38 +01:00
Felix Walter
2c22cd215f CLA: BIBE: Fix memory leak in bibe_begin_packet
In `bibe_begin_packet` another occasion of using `strdup` combined with
`strtok` was found that did not properly `free` the result of `strdup`.
This uses `strchr` instead to get the latter part of the CLA address
string, containing the next-hop EID.

This further checks the provided next-hop EID is valid upon obtaining
a TX queue. By that, the contact manager can properly return an error in
case the EID is invalid.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:04:02 +01:00
Felix Walter
a17d432cbb CLA: BIBE: Manage the AAP parser in BIBE-specific structures
This is not needed by other CLAs, thus, should be moved to BIBE-specific
data structures.

Additionally, the "bibe_parser" is not used anywhere (leftover from a
previous change?) and is removed in the course of this change.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:04:02 +01:00
Tobias Nöthlich
e411bfea10 Rename struct header to bibe_header
This commit renames the struct containing the BIBE header to bibe_header
to reduce ambiguousness.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2022-01-26 21:04:02 +01:00
Felix Walter
be19d40290 Apply the suggested changes to the order of include statements in bibe_proto.h.
Triggered by @noethlich, see !43

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:03:28 +01:00
Tobias Nöthlich
1e1f24b2d3 Fix stylecheck errors and warnings
This commit remedies code smells introduced by implementing the BIBE
convergence layer adapter.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-29 13:07:12 +01:00
Tobias Nöthlich
a960a744a6 Implement BIBE header encoding and transmission
While receiving and parsing BIBE bundles via the BIBE CLA was already
working, transmitting BIBE messages required the encoding of the BPDU,
the administrative record and the enclosing AAP SENDBIBE message
before transmission.

This commit adds this functionality, to allow the BIBE CLA to transmit
and receive bundles as needed.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-29 11:45:38 +01:00
Tobias Nöthlich
a3f43b90a9 Add processing of cla_addr parameter to cla_bibe.c
As the cla_addr parameter contains the EID of the next hop of a BIBE
bundle, it needs to be processed in the cla_bibe.c file.

This commit adds the necessary operations to retrieve the EID from the
cla_addr string. It also adds the necessary function calls for
encoding the BIBE header.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-29 11:20:34 +01:00