Commit graph

272 commits

Author SHA1 Message Date
Maximilian Nitsch
4e125e3af7 fix: cppcheck warnings
Add command-line options for cppcheck to the CI job:

- `--suppress=constParameterCallback`

- `--check-level=exhaustive`

  information: Limiting analysis of branches.
  Use --check-level=exhaustive to analyze all branches.

- `--force`

  information: Too many #ifdef configurations - cppcheck only checks 12
  configurations. Use --force to check all configurations.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2026-05-20 17:57:53 +02:00
Maximilian Nitsch
611b67fb0e refactor: cleanup includes
Removes unused includes detected by the clangd LSP.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2026-05-20 16:16:35 +02:00
Felix Walter
a231ed5ed3 Pass timestamps in status reports
In outgoing status reports, previously, we did not send timestamps, even
in case they were requested for BPv7 bundles. This refactors the
corresponding functions to generate status reports, so we assign the
proper timestamp depending on the status flag.

Note that we never supported sending a status report capturing multiple
events at once -- only the BPv7 SR serializer supports the generation.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 19:22:45 +01:00
Felix Walter
32477818fa bundle6: Fix status report parser
Incoming status reports can contain multiple timestamps, depending on
which flags are set, as in BPv7. In outgoing bundles, we do not support
this, but we must support it when parsing received SRs.

The approach to parse the conditionally-present fields is to always fall
through all the `case` labels and only stop (+ parse) where we see the
corresponding flag. Otherwise we would need a big jump table for every
individual step (checking if any of the remaining flags is present). As
the `switch` construct already represents such an overall jump table, we
just leverage it (and tell the compiler that it is fine to fall through
there).

This also adds two functions to initialize AR and SR data structures, so
we do not miss initializing any fields (which we were, previously!) and
cause UB.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 19:22:45 +01:00
Felix Walter
224952ce40 bundle: Remove bundle_list
This is not needed anymore (was only used for custody stuff).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 19:22:45 +01:00
Felix Walter
d820d30395 bundle6, ud3tn: Remove custody signal handling
We never fully implemented custody and removed the corresponding
(prototypical) infrastructure long ago. We do not need to be able to
parse BPv6 custody signals.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 19:22:45 +01:00
Felix Walter
d939405870 bundle.h: Remove wrong comment
This has been changed before standardization of RFC9171: "report custody
acceptance" is 0x008000 (bit 15) in BPv6, which is reserved in BPv7.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 19:22:45 +01:00
Felix Walter
f32525679e bundle7: Remove unnecessary redundant method to free admin. records
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 19:22:45 +01:00
Felix Walter
e6ae7f718c CLA: Support cleanup if launch failed for all CLAs
Note that at the moment we cannot easily terminate the CLA tasks. Thus,
we return UD3TN_FAIL if any task is running and do not free resources in
that case. This is not important for the uD3TN daemon as all runing CLAs
are only terminated on process termination and the resources are then
deallocated by the system anyway.

Fixes: #192

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 19:13:12 +01:00
Felix Walter
5660d27471 bundle7: Add flag to validate if there is no BIB and no primary CRC
See: #267

This adds a compile-time flag to reject such bundles, if needed.

Making this part of the validation routines all the time breaks our
interoperability with DTN7 (at least in the configuration we are using
in our interop. test).

Note that we cannot currently check the security targets, which is an
unordered CBOR array part of the BIB payload data. Thus, bundles without
CRC and with a BIB targeting *any* block, even if this excludes the
primary block, will be accepted when the option is turned on. See
follow-up issue #273.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 18:58:07 +01:00
Felix Walter
fb64a992d7 bundle: Add BPSec block types
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 18:58:07 +01:00
Felix Walter
16a30db6a3 bundle7/parser: Check for invalid block array length
Checks the conditions from RFC 9171, 4.3.1 and 4.3.2

Closes: #261

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 18:58:07 +01:00
Felix Walter
6a16e94808 bundle: Switch all flags and length fields to 64bit and do not filter
- The standard defines 64 bits for all flags.
- Also see https://www.rfc-editor.org/rfc/rfc9171.html#section-4.2.3-6:
  "Bundle processing control flags that are unrecognized MUST be ignored,
  as future definitions of additional flags might not be integrated
  simultaneously into the Bundle Protocol implementations operating at
  all nodes."
- Similar for blocks:
  https://www.rfc-editor.org/rfc/rfc9171.html#section-4.2.4-2
- The primary block length is calculated internally based on the bundle
  length -- to prevent overflow, we use 64 bit here as well. (We might
  introduce additional checks in the future, but the input being CBOR
  with the validations in the BPv7 parser should already work to
  only allow a "sane" primary block length. For BPv6 we enforce still
  parsing only 16 bits for it.)
- Also define a bit mask for BPv6 flags (`BP_V6_FLAGS`)

Closes: #247, #237

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 18:58:07 +01:00
Felix Walter
e1eeb61489 Merge branch '269-cpp-compat' into 'master'
aap2_client: Make compatible with C++

Closes #269

See merge request d3tn/ud3tn!251
2026-03-19 13:57:07 +01:00
Felix Walter
81b7060ba5 cla_mtcp: Enable ION interoperability
ION uses a 32-bit unsigned integer length field as header for the MTCP
packets. To be compatible with that, we add a compile-time setting
`CLA_MTCP_ION_STCP_COMPATIBILITY`.

Closes: #202

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-19 07:57:21 +01:00
Felix Walter
4d4317ea51 aap2_client: Make compatible with C++
* _Static_assert is C-specific, but we have static_assert
* ensure C linkage

Closes: #269

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-18 10:04:09 +01:00
Felix Walter
95097f0fc1 test/unit, hal_platform: Fix leak reported in release mode
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-03-18 09:57:10 +01:00
Felix Walter
f4206db121 eid: Implement support for ipn 3-element string representation
This extends the conversion and validation functions for ipn EID strings
to implement support for the RFC9758 3-element format.

The only point that changes behavioral-wise by default is that now
`eid_to_string` returns the "ipn:a.n.s" for all EIDs with FQNN > 2^32-1,
except if the new compile-time configuration option
`EID_IPN_FORCE_2_ELEMENT` is enabled.

This also introduces a variant of `eid_to_string` with a second argument
to enforce the use of the 2-element format, which is used in the BPv6
implementation for constructing outgoing bundles (there is no 3-element
format in BPv6).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
74a487ca06 eid.h: Rename ipn node_number -> fully_qualified_node_number
This avoids confusion with the new "node number", as RFC9758 also calls
the lower 32 bits (assigned by the allocator).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
6786c01d38 eid.h: Revert union approach and use explicit accessors
Type punning via unions in C is not portable as the order of the inner
struct members depends on the endianness of the platform.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
b9c16af743 eid.h: Implement data structure for RFC9758 3-element format
This adds an anonymous union for decomposing the node number into an
allocater ID plus an assigned node number as per RFC9758.

NOTE that this is partially reverted in the following commit and is kept
for reference that we considered and abandoned the union approach.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
ef8129dd88 eid: Harmonize function argument names for EID-string functions
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
fa3b346a55 eid: Harmonize function names
Some older functions have not been renamed previously to simplify the
review of the "struct eid" change. This adapts the remaining EID-string
handling functions to have consistent naming and return types with the
other EID-related functions and make them more intuitive to use.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
6f3aef6019 eid: Handle ipn EIDs with zero node number and nonzero service number
We handle these EIDs gracefully: we consider them as the null endpoint
and set the service number to zero when reading them from a string.
When parsing and serializing BPv7 bundles, the EIDs are kept unchanged.
In the case of BPv6 bundles, they will be normalized when the dict is
rewritten on serialization (this is done anyway).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
3a9928df93 Make EID a data structure
- A new `struct eid` is introduced, which can represent EIDs in a
  scheme-based  manner; specifically, this means that `ipn` EIDs are
  now represented as tuples of two 64-bit integers and the `dtn` null
  endpoint is now represented as a `NULL` pointer (similar to the CBOR
  representation in RFC 9171).
- We assume that any `struct eid` instance has been validated before,
  e.g. by decoding a string via `eid_from_string`.
- Note that the FIB is still using the (normalized) string format of
  node IDs. It performs a lookup in a hash table anyway and, later, we
  plan to support EID patterns (current IETF draft).
- Changes to parsers and serializers:
  - The BPv7 parser validates EIDs separately from `eid_from_string`.
    This is intentional: No full normalizationis performed for incoming
    bundles; as long as the EID is valid, it is passed through, to
    prevent changes to the immutable (as per RFC9171) primary block.
    This means that, e.g., there are two representations of the null
    endpoint (`dtn:none` and `ipn:0.0`), which are kept as such now.
  - The BPv6 parser and serializer will rewrite the primary block of
    passing bundles -- they do this anyway as the "dictionary" is
    re-constructed by the serializer.
  - Dedicated string representations of the EIDs (`source_str`, etc.)
    are added to the bundle struct on reception (`cla_contact_tx_task`)
    and creation -- this is done for convenience when processing the
    bundle further (especially to still be able to print log messages
    referring to the EIDs in the BP and so on). We may remove it in the
    future to reduce the number of EID-to-string conversions.
- Other changes:
  - Some terminology is cleaned up in the process: e.g., variables
    referring to the local administrative endpoint identifier are
    renamed as such. The previously-used terms "local node ID" or,
    worse, "local EID" are inaccurate -- according to the standards,
    any locally registered singleton EID is a node ID of the local
    bundle node.
  - In some places, log messages are harmonized (e.g. by always using
    quotes around EIDs and no quotes for agent sink IDs). Sometimes,
    EIDs were printed in logs which have been removed now to prevent
    an unnecessary EID-to-string conversion.
  - `aap2_agent`: the manual deallocation of string parts of the AAP2
    message is now replaced by a less fragile `pb_release` in most
    cases.
  - `bundle.h`: `struct endpoint_list` is replaced in BPv6 by a
    `struct eid_list` containing the new `struct eid`; the DFCF
    ("compat") router still uses the old variant with strings
  - `init`: `preprocess_local_eid` is simplified and moved to
    `cmdline.c`. It now uses `eid_from_string`, which tolerates missing
    trailing slashes for `dtn`. Also, we do not support `ipn:x` without
    service number anymore on the command line, as it is an invalid
    format and only makes the coe more complex.

It is recommended to review the changes to `ud3tn/eid.[c|h]` and the
associated unit tests (`test_eid.c`) first, to get an overall idea of
the added and adapted functionality plus the expected behaviors. Before
reviewing the individual changes to all functions dealing with EIDs, it
is also advisable to take a quick look at the other associated
(following) commits.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
4aa3c76f78 bundle7: Remove unneeded function bundle7_eid_get_max_serialized_size
This function duplicated functionality from bundle7_eid_sizeof (and
improperly represented the IPN Null Endpoint) + was untested. Thus, we
remove it and replace uses with bundle7_eid_sizeof().

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
a5429fcf11 bundle6: Drop unused function bundle6_get_dict_length
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
57f8c35e62 Fix some new clang-tidy complaints
Newer versions check that enums indeed declare every value that is
assigned to variables with the given type.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2026-02-03 09:22:53 +01:00
Felix Walter
4b82854901 aap2_client: Move Unified API backend code to upstream
This removes the Unified-API-specific code from the AAP2 client. As
dicussed in !238, it fits better in the upstream repo.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-11-13 16:59:33 +01:00
Felix Walter
f684fabc5a aap2_client: Make type of keepalive timeout consistent with AAP2
AAP2 uses uint32, so we do, too. This moves the check for a negative
value to the UAPI backend implementation.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-11-13 16:59:33 +01:00
Felix Walter
6b45ef66b2 aap2_util: Fix inconsistencies in docstrings
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-11-13 16:59:33 +01:00
Felix Walter
a6c5378cd4 Implement AAP 2 C client and Unibo compatibility layer
This implements an AAP 2 C client based on the Unified API code for the
µD3TN AAP 2 interface. The implementation consists of two parts; a
generic AAP 2 client (aap2_client.c) and a Unified API compatibility
layer (aap2_unified_api_backend.c). The core difference between the two
is that the Unified API compatibility layer automatically creates two
sockets (a sending and a receiving one) and generates a common AAP 2
secret shared between the two. Moreover, the generic client offers some
additional AAP 2 options that are not available in Unified API. Thus,
the generic client features slightly higher flexibility and is intended
as the default solution when developing applications that only need to
interact with µD3TN.

The following design considerations for the generic AAP 2 client are
noteworthy:

- The client struct is an opaque object that is fully managed inside the
  generic AAP 2 client implementation. This way, we have full
  flexibility for adaptations in the future.
- Inspired by the Unibo code, the `aap2_client_register` and send/recv
  functions use dedicated spec structs, which are more extensible than
  using individual function arguments (fields can be added flexibly).
- Support for timeout and keepalive is added where applicable to enable
  recognition of broken TCP connections and keep firewalls happy.
- Log messages typically use the "debug" level, except if they indicate
  a broken connection ("warn") or a danger to overall continued program
  execution ("error").

The generic AAP 2 client contains some minor bits from the original
Unified API client code:

- The `receive_payload` was mostly moved to the generic part, only
  adding special handling for (valid) zero-length payloads.

The Unified API compatibility layer was implemented based on the
original Unified API code, adapting it to make use of the generic AAP 2
client implementation.

The following changes to the coding style were performed to adapt it to
µD3TNs style guidelines (Linux kernel coding style):

- use tabs according to the Linux kernel style guide
  (`ERROR:CODE_INDENT`, `WARNING:SPACE_BEFORE_TAB`, `WARNING:LEADING_SPACE`)
- add some spaces after declarations (`WARNING:LINE_SPACING`)
- do not assign inside if statements (`ERROR:ASSIGN_IN_IF`)
- use parentheses for `sizeof` everywhere (`WARNING:SIZEOF_PARENTHESIS`)
- adapt indent (`ERROR:SWITCH_CASE_INDENT_LEVEL`)
- remove trailing whitespace (`ERROR:TRAILING_WHITESPACE`)
- adapt function declarations
- adapt block comment style (`WARNING:BLOCK_COMMENT_STYLE`)
- use `__func__` instead of `__FUNCTION__` (`WARNING:USE_FUNC`)
- remove unnecessary braces (`WARNING:BRACES`)
- put opening brace after declarations of e.g. `enum`
  (`ERROR:OPEN_BRACE`)
- make pointer `*` location consistent (`ERROR:POINTER_LOCATION`)
- use memcpy and snprintf instead of string functions such as str(n)cpy

The following additional changes to the original Unified API code were
performed:

- removal of legacy and deprecated code (commented check in
  `ud3tn_free_payload`, function `ud3tn_ping_aap`)
- removal of status report features/stubs: the actual integration was
  not implemented; we can add it back in the future when support for
  decoding status reports in the generic portion is implemented
- re-implement ping feature based on AAP 2 keepalive mechanism: the
  generic client features a keepalive method, which we can use in the
  Undified API compatibility layer
- adaptation of all `DEBUG_*` log statements to the corresponding µD3TN
  `LOG[F]_*` macros
2025-10-22 16:28:49 +02:00
Felix Walter
fcd54de8bc aap2_agent: Move common functions to utility module
This means that functions that will be reused in the AAP2 client are
moved to a common `aap2_util` file. Slight adaptations to the naming of
individual functions are made as they are not `static` anymore. This
also adds handling for the status report ADU flag in
`aap2_get_adu_flags`, which was missing beforehand.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-10-22 15:41:56 +02:00
Felix Walter
7170d2e325 eid: Implement function to get the EID prefix
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-10-22 15:41:56 +02:00
Felix Walter
9995b426ae Add a test for the previous node block creation
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-09-21 15:34:30 +02:00
Felix Walter
5b5b4c7e5d bundle7, tx: Move creation of block entry to lib
By this we can test the function in a unit test.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-09-21 15:08:13 +02:00
Felix Walter
e819f8723b bundle7, tx: Implement creation of BPv7 previous node block
RFC9171 specifies this as a "SHOULD", so we should support it.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-09-16 17:17:51 +02:00
Felix Walter
4c274787cf Use BIBE AR type code 64443 by default
See: https://datatracker.ietf.org/doc/html/draft-ietf-dtn-bibect-05

Closes: #260

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-09-05 10:57:59 +02:00
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
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
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
4a2f10aecb bundle: Remove BUNDLE_FLAG_REPORT_STATUS_TIME from SR flags
It only controls how status reports should look like, not which status
reports are requested. We only want to check for the latter. ION appears
to always set this flag.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 13:14:27 +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
f94bcddc39 bundle7: Fix include guard C&P issue
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2025-06-05 10:43:26 +02:00
Felix Walter
6b99068daf aap2: Change default TCP port to 4244
The defaults for the AAP and AAP 2.0 TCP ports were the same. Thus, if
we specify a TCP host for both, µD3TN will terminate on startup as the
port is already in use by one agent but it tries to bind to it with
both.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-11-16 13:31:40 +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
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
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