Commit graph

506 commits

Author SHA1 Message Date
Felix Walter
42d312d958 Merge branch '15-207-improve-contact-plan-handling-in-bdm' into 'master'
Improve contact plan handling in DFCF BDM and tools

Closes #207, #15, and #238

See merge request d3tn/ud3tn!199
2025-06-06 10:11:05 +02:00
Felix Walter
b63d36edc4 bundle_processor: Allow local destination as report-to EID
There are many use cases where status reports generated locally should
be delivered locally.

Note: As the bundles now need to be passed to `bundle_dispatch`, it would
have been needed to remove the `const` qualifier of that method, as it
mutates the BP state (for checking for duplicates and adding bundle fragments
to the reassembly list). To prevent this from being necessary, an alternative
function is introduced that does not perform such a check and does not
support fragments.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 17:14:02 +02:00
Felix Walter
973f35d132 Implement status report support in AAP 2.0
This enables AAP 2.0 clients to receive status reports with a new ADU
flag (as we already deliver BIBE bundles). Moreover, it allows clients
to set a report-to EID and sets all of the status report flags on newly
created bundles in case a report-to EID is provided.

Closes: #241

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 17:13:17 +02:00
Felix Walter
030b0bf75a routing/compat: Implement JSON configuration parser
This adds the JSON parser logic as an alternative to the custom legacy
format and also adds necessary tests.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 17:03:39 +02:00
Felix Walter
868bac67b6 router_agent, mk: Add stub of JSON configuration feature
This adds a function to decode JSON configuration via Jansson to the
router agent. The JSON functionality and, thus, the dependency on
Jansson, can be disabled during the build process by setting the
`DISABLE_JSON` compile-time flag (see `config.mk.example` for details).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 17:03:39 +02:00
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
a727b308cc bundle7/parser: Enforce version field to be set to 7
See: #243
Closes: #243

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 10:42:16 +02:00
Felix Walter
2fee3f101d aap2: Check string fields in incoming messages for NULL value
The EIDs and CLA addresses sent by the client may be empty, in which
case they will be assigned a NULL value. We must not use them in this
case. This also adds a second check in the bundle create functions so it
is ensured they never operate on NULL values.

Fixes: #240

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-04-14 08:59:36 +02:00
Felix Walter
064892126d bundle6: Fix calculation of primary block length field
As per RFC 5050, Section 4.5.1, this field must represent the *remaining*
length of the primary block, not the total length.

Fixes: #236

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-12-03 11:22:39 +01:00
Felix Walter
0ed7013162 bundle7/eid: Prevent potential double-free of EID string
On specific CBOR decoding errors we called `free()` on the created EID
buffer but did not reset the pointer to `NULL`, which is expected by the
calling context. This means that a parser reset will double-free the
pointer.

Fixes: #233

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-11-16 13:40:43 +01:00
Felix Walter
59ebc0d67d aap2_agent: Extend liveliness check to improve TCP support
If a TCP connection breaks under Linux, the result of `poll` will
indicate that there is data to read, despite a call to `recv` will read
zero bytes and, thus, indicate connection closure. As we are not calling
`recv` in case of a subscribing client, this condition led to the client
connection being considered alive even though it was not.

The check is extended to invoke `recv` on the socket, though, just to
check and report an issue if there is actual data to be read (which
would be an AAP 2.0 protocol violation for subscribing clients). All
subscribing client connections for which `poll` reports either an error
or data to be read at the time of the liveliness check will be closed
by the agent afterwards. This ensures that new clients can register.

It should be noted that it is anyways recommended to set a keepalive
interval when using TCP as a transpport for AAP 2.0.

Closes: #229

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-11-04 17:00:44 +01:00
Felix Walter
f553848633 bundle7: Limit allowed values for bundle block type and fix assertion
Previously the conversion to `enum bundle_block_type` could result in an
unsigned integer overflow, triggering the assertion in rare cases.

This change 1. adapts the assertion such that the check is performed
using the correct data type and 2. introduces a range check for the
bundle block type (only type codes 0-255 are defined).

Closes: #227

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-10-22 09:44:55 +02:00
Felix Walter
056142de6d cmdline, docs: Warn about potentially insecure AAP TCP arguments
As AAP does not provide TLS support, a user exposing it on a TCP socket
should know what they are doing and set up appropriate firewall rules.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-10-02 07:49:46 +02:00
Felix Walter
db7ff27ff4 cmdline: Documentation fixes related to AAP v1 arguments
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-10-02 07:49:46 +02:00
Felix Walter
17bd09a84b cmdline, docs: Enable TCP support for AAP 2.0
This allows for using AAP 2.0 over TCP, which the Python tools support
already. Note that the user must make sure that the socket is not
exposed externally.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-10-02 07:49:46 +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
9ed31716d3
Merge branch 'v0.14-doc-updates'
See !195
2024-09-19 13:09:05 +02:00
Felix Walter
0b4550f765 cmdline: Rename eid to node-id
This was confusing users. We are adding a detailed explanation in the
man page and informing in the help text that the parameter refers to the
administrative endpoint of uD3TN.

Fixes: #213

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-13 15:18:03 +02:00
Felix Walter
58aee16e7d routing/compat: Set pointer to previous element properly
Previously we did not update the pointer to the previous element when
*not* removing the current element. This may result in memory being
leaked if the following element is removed and the removal code assumes
that it is the first element in the list, setting the list head to the
element that follows.

The update of `prev->next` is removed as it should be set properly
anyway.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:16:22 +02:00
Felix Walter
c4d794fd63 bundle6/reports: Fix final status update in admin. record parser
We must break out of the `switch` statement there to keep the parser
status set to `PARSER_STATUS_DONE`. Somehow we even managed to
explicitly acknowledge the accidental fallthrough in uPCN v0.6.0.

We need tests for this. See: #219

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:16:22 +02:00
Felix Walter
cb06c1a646 bundle7: Fix shadowFunction warnings by cppcheck
Sometimes we had local variables named the same as functions.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:15:34 +02:00
Felix Walter
9533f72f91 routing/compat: Remove unused struct
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:15:34 +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
b58f137313 Fix unsignedLessThanZero warning by cppcheck
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:13:21 +02:00
Felix Walter
1148c912a0 bundle6: Remove unused struct
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:13:21 +02:00
Felix Walter
d12f6b7214 Fix badBitmaskCheck warnings by cppcheck
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:13:10 +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
daf80c7155 routing/compat: Handle NULL pointers in release builds
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:12:43 +02:00
Felix Walter
96be0594ff routing/compat: Address memleaks pointed out by clang-tidy
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-09-11 10:12:43 +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
Maximilian Nitsch
4b145c847e contact_manager: Add new contacts to the current_contacts when processing added_contacts
To prevent additional occupancy of a `contact_info_list` entry, new
contacts are first added to the list of added contacts and only later
shifted to the list of all current_contacts.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-09-02 10:13:28 +02:00
Maximilian Nitsch
86d29433f2 contact_manager: Use linked list for added and removed contacts
In addition to the previous commit, the local variables `added_contacts`
and `removed_contacts` are now also represented by a linked list to
eliminate limitations of a static array.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-08-30 16:26:04 +02:00
Maximilian Nitsch
cf0a43cb11 contact_manager: Use linked list for current_contacts
To eliminate the limitation of a statically allocated array to store
current contacts its replaced by a linked list.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-08-30 16:20:10 +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
69ea89474d BP: Do not drop all nodes in FIB if no concrete CLA address is present
Sometimes we use CLA addresses such as "smtcp:" or "tcpclv3:", without
an actual next-hop address on the CL. In this case, we do not drop all
FIB entries referencing the "generic" CLA link if a FIB request for
deleting an entry is received.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-23 11:59:18 +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
00e4602dbd aap2, agent_manager: Do not warn on double de-registration
If an agent finds out it has a broken connection (the client
disconnected) on a liveliness check (e.g., if another client wants to
register the same agent ID), the agent manager will de-register it, as
it needs to register the new agent immediately and there is a race
condition otherwise. In this case, a warning was shown that should
however only be a debug information.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-09 15:01:46 +02:00
Felix Walter
6775fd8782 aap1: Set admin. config flag on all bundles if no BDM secret set
This makes aap-config / aap_config.py (AAPv1) work again in the default
configuration (debug build, default BDM, no secret set). This way,
pre-existing documentation (YouTube videos, ...) stays usable.

The security properties will not be impacted by this change as AAPv2
clients will be able to do administrative actions anyways if no secret
is set.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-09 15:01:46 +02:00
Felix Walter
a34a785d39 aap2: Properly differentiate connection closure from Protobuf error
This adds a check for detecting EOF and differentiate such an "error"
from actual Protobuf decoding errors so people do not get confusing
log messages.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-08-09 15:01:46 +02:00
Felix Walter
b01d74bb21
Merge branch 'fix/docs'
See !182
2024-07-15 23:01:49 +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
281b3ec248 config_parser: Remove unused parser stage
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-07-15 00:46:14 +02:00
Felix Walter
ccbeac91f3 Unify and document compile-time options of compat. router
This prefixes all compile-time options of the compat. router with
`ROUTER_` and adds them to config.mk.example so they can be easily
discovered and adapted.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-07-15 00:46:14 +02:00
Felix Walter
87be9749af Re-integrate v0.13.0 routing code as "integrated default BDM"
This makes µD3TN behave the same as v0.13.0 when executed without an
additional commandline argument. A new commandline argument `-d` /
`--external-dispatch` is added, which enables the use of external BDMs.
The default forwarding implementation is now again provided using the
v0.13 code, extracted from e1621765a4 and
adapted to the new agent-based forwarding implementation.

Central changes to the old code include:

- A new "Routing Agent" that handles incoming configuration commands,
  FIB updates, and BDM dispatch requests.
- The use of the BDM authorization flag to authorize contact
  configuration commands.
- The Contact Manager now only triggers the creation and removal of
  links / FIB entries; bundle dispatch is triggered through the FIB and
  BDM callback functions of the Routing Agent.
- The fragmentation logic is adapted to store the original bundle along
  with an offset and length value, instead of pre-creating and storing
  the fragments.
- The bundle re-scheduling logic integrated into the Routing Agent is
  simplified and does not support changing the fragmentation parameters.
  A new function is added to the Router that searches for a new route
  for such fragments that were already scheduled at some point,
  considering them as un-fragmentable bundle with overridden fragment
  offset and length.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-07-15 00:46:14 +02:00