Commit graph

176 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
37ec79e249 bundle: Implement dedicated bundle validation before further processing
This adds a `bundle_is_valid` function checking for further MUST
constraints defined by the spec., which further processing inside uD3TN
may depend on.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 11:05:47 +02:00
Felix Walter
c4b43163fb cla_sqlite, sqlite_agent: Fix memory leak of prepared statement on error
We must finalize the prepared statements and not just reset them.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-30 15:54:28 +02:00
Felix Walter
7943778193 cla_sqlite: Return success if bundle already exists in storage
This blocks the use of the persistent storage with our BDM: If we
restart µD3TN and the BDM after a bundle has been stored, then
reconfigure the contacts, and afterwards recall the stored bundles via
`aap2-storage-agent`, the BDM will try to store the bundles again after
they have been (re)scheduled and the storage CLA will report a
"transmission failure". See #210 why we should rather indicate success
here.

This checks the return value of `sqlite3_step` and, if it is
`SQLITE_CONSTRAINT`, returns success ("done") in the `cla_begin_packet`
handler. This way, the BDM received the proper notification that
everything is fine and continues sending the bundle after the contact
has started.

Closes: #210

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-27 12:58:48 +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
742d0d3c5f Fix variableScope warnings by cppcheck
This reduces the scope of several variables.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:12:44 +02:00
Felix Walter
c965894a27 style: Add blank linkes after all declarations
For consistency and to silence the stylecheck (`WARNING:LINE_SPACING`).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:10:43 +02:00
Felix Walter
10179edff4
Merge branch 'hotfix/205-aap2-can-lock-up-bp'
See !192
2024-08-30 14:21:15 +02:00
Felix Walter
8f442b8f6b Adjust log levels of some common unimportant messages to DEBUG
Three messages that are printed quite often but are barely relevant,
either because there is another INFO-level message about the same thing
and they only confirm processing or because the behavior can be expected
anyway, are downgraded to DEBUG level, so they are not shown by default
and disabled in release builds.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-30 13:58:43 +02:00
Felix Walter
c2d3f5982c CLA: MTCP: Fix race condition deleting from hash table
The MTCP CLA drops a link parameter data structure from its hash table
in case it intends to create a new link and there is an existing one in
the process of being torn down (while the associated task is cleaning up
resources). In this case it might happen that the entry is removed by
`mtcp_start_scheduled_contact`, a new entry is created by
`launch_connection_management_task`, and this new entry is removed again
by the termination code in `mtcp_link_management_task`, "leaking" the
link management task and making it uncontrolled.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-30 11:07:36 +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
788e47fe64 CLA: Report disconnection to BP in dedicated thread
This moves the information about a disconnected CLA link from the
`cla_end_scheduled_contact` implementation (in MTCP) to the generic
`cla_link_cleanup` routine that is typically executed in a dedicated
link management thread.

This prevents the call to `cla_end_scheduled_contact` from putting
something in the BP queue which may be blocked by the BP being busy
calling `cla_end_scheduled_contact`.

Fixes: #205

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-30 08:36:07 +02:00
Felix Walter
78bef1a089 Refactor FIB: Separate node entry from CLA link
The FIB fulfils two purposes: 1) map node IDs to next-hop CLA addresses
and 2) store the current status of a link associated with a given CLA
address.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-23 11:59:02 +02:00
Felix Walter
a83098f9fe CLA: Disallow CLA addresses without colon
Allowing both "cla:" and "cla" may lead to issues for single-connection
CLAs (those that do not use CLA-specific addresses): the FIB may contain
entries for both and only one may be marked as "up" if both forms are
used interchangeably.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-07-15 00:46:14 +02:00
Felix Walter
6838078139 cla: Report 0 if the max. bundle size is unlimited
We now treat this value specifically and it is easier to handle in AAPv2
as Protobuf will not transmit fields that have been assigned their
default value (0 in this case).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-07-04 16:00:30 +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
5779598f32 CLA: RX: Drop EID spoofing detection
It is not necessary anymore to secure our configuration. Loops in DTNs
should be allowed and only be controlled through the bundle lifetime.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-26 13:32:28 +02:00
Felix Walter
2f17075ff3
Merge branch 'feature/sqlite-in-memory-db'
See !174
2024-06-26 10:04:30 +02:00
Maximilian Nitsch
ed6bdcbf96 SQLiteCLA: Support volatile in-memory database
Adds support for a volatile in-memory database by enabling support for
URI-based database file names. Since the in-memory DB can only be
accessed within the process, the integration tests are changed so that
external SQL queries are only performed when a persistent DB file is
used.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-06-26 09:28:45 +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
d238804c6a
Merge branch 'hotfix/bundle-serializer-result'
See !167
2024-06-25 10:20:59 +02:00
Felix Walter
7b686802b9 cla: TX: Remove FIXME comment
We now take the result into account.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-24 14:31:54 +02:00
Felix Walter
7b959e4cb8 aap2, FIB: Implement direct dispatch
This adds a "flags" field to the FIB link, allowing for configuring a
link for "direct dispatch", i.e., to make it usable without first
contacting a BDM. It is important to make this optional as otherwise
contact-based routing and QoS could not be implemented properly via a
BDM.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 12:39:59 +02:00
Felix Walter
e8a319a277 TX: Allow the bundle serializers to indicate failure if CLA fails
If the write method of the CLA fails, the serailizers will now return
early and this failure is handled properly by the TX task.

In the case of the BPv6 serializer, we add the necessary flow control to
the `write_bytes` macro, to prevent needing a conditional for every
write* or serialize* statement.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 12:38:15 +02:00
Felix Walter
b07407112a sqlite: Remove destination EID from compund bundle ID
It is not part of the unique bundle identifier as per RFC 9171.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
392b05494e agent_manager, cla: Increase log level of common conditions
Conditions such as no FIB handler being present are totally normal in
most cases and do not need to be reported as warnings.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
3672bc0832 cla_tcp_util: Return an error on EAGAIN and EWOULDBLOCK
This means that either the socket was marked nonblocking, in which case
we would do busy waiting, or a set receive timeout was exceeded, in
which case we also want to return the error.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
7f0c58fcd5 cla_bibe: Provide full CLA address to BP in all cases
The BIBE CLA address contains the lower-layer destination EID.
Previously we were reporting link changes for the `cla_sock_addr`,
leading to inconsistent FIB entries.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
c45ba840c7 cla_bibe: Fix use-after-free
The CLA is not expected to keep a pointer to the EID, which it did.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Felix Walter
e57668eb4d cla: TX: Fix UB by calling CLA send function with correct type
We were calling it though a function pointer with a void* as first
argument, despite we pass a struct cla_link*. This is UB, correctly
reported by the sanitizer, though only reported in the case of the new
storage CLA.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +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
271ff4aa4f agent_manager: Extend by FIB and BDM mgmt., simplify, make testable
- Implement management of FIB and BDM agents:
  * add administrative secret which is required for registering FIB and
    BDM agents
  * allow registering reverse-direction agents for TX/RX of ADUs when
    passing the admin secret
  * add cmdline option to pass the admin secret via an env variable
  * make administrative secret optional in debug builds
- Register agents by number, as FIB and BDM agents may not have a sink
  ID. Numbers are allocated by the agent_register function.
- Remove global state, add function to de-allocate everything.
- Add comprehensive unit tests.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-17 13:33:31 +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
71793d520d SQLiteCLA: Clean-up sqlite_init()
- Use only one goto-label
- Remove the bundle_processor_inform() call, as this is already done in
  cla_link_init()
- Move the sqlite_link_init() call to the end of the function to perform
  the registration of the CLA as the last step

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-06-03 13:41:58 +02:00
Maximilian Nitsch
f22162952f SQLiteAgent: Clean-up on termination
Frees the allocated memory and closes the database connection on exit.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-06-03 13:41:58 +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
0a856a1379 SQLiteCLA: SELECT bundles by CompoundBundleId
Depending on the selected bundle_filter, bundles can now be looped back
using either a metadata filter or a unique CompoundBundleId.

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
50787b60cb SQLiteCLA: Use multiple connections and transactions
To prevent race conditions between the different threads, each thread
uses its own database connections and all statements are wrapped in
transactions to ensure that they are either executed completely or not
at all.

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
1321c59c22 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-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
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