Commit graph

31 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
2adc3ab7e8 bundle_fragmenter: Always create new fragments with offset + length
Previously the fragmentation logic was very specific to uD3TN's
forwarding approach, modifying the original bundle in the process. With
BDMs supporting fragmentation we must make this more flexible. Thus, we
now pass an offset and length and always create a copy of the required
contents based on the original bundle.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +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
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
3cd89eb6a5 bundle, agents: Switch time unit to milliseconds
...to align with the general decision to make DTN timestamps
millisecond-based.

See: #53

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-11 16:59:13 +02:00
Felix Walter
4bf6888a03 bundle7: Calculate ipn EID size using 64 bit integers
The node and service number are 64 bit unsigned integers. This fixes the
validation and EID serialized size calculation and adds appropriate
tests to the serializer unit tests.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-11-21 09:41:03 +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
0625c07cbb
Merge branch 'feature/39-implement-bibe'
See !43
2022-01-26 21:04:34 +01:00
Tobias Nöthlich
4c871a28a3 Address potential memory leak in reports.c
There was an issue in reports.c, that an error at specific points in
the code could lead to already malloc'ed fields not being freed properly.

This commit fixes this issue by introducing the function
free_record_fields() which frees all potentially malloc'ed fields in
the bundle_administrative_records struct before the struct itself
is freed.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2022-01-26 21:04:02 +01:00
Felix Walter
26580de896 Remove the hal_time dependencies in bundle6 and bundle7
Based on a contribution by @mnitsch, 351e1dae9.

This removes `hal_*` dependencies in the bundle processing components,
with the goal that these parts can be re-used without depending on the
uD3TN core functions and underlying system state. The required variables
are passed as function arguments from the uD3TN core components.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-22 11:12:32 +01:00
Felix Walter
6e54d35fda Pass a proper sequence number upon local bundle creation
This adds the bundle sequence number as an argument to the bundle
creation functions and passes a sequence number which increases when
multiple bundles are generated by the application agent with the same
creation timestamp.

Fixes: #59

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2021-07-22 17:51:26 +02:00
Maximilian Nitsch
9e8a6d0f87 Add Bundle Age Extension Block
The Bundle Age block [...] contains the number of milliseconds
that have elapsed between the time the bundle was created and time at
which it was most recently forwarded. It is intended for use by nodes
lacking access to an accurate clock, to aid in determining the time at
which a bundle's lifetime expires. [...] If the bundle's creation time
is zero, then the bundle MUST contain exactly one (1) occurrence of this
type of block.[1]

In this implementation the age block is only evaluated if the creation
timestamp is 0. If a bundle age block exists, it will be updated
according to the specification, but an age block will never be
proactively inserted.

[1]: https://tools.ietf.org/html/draft-ietf-dtn-bpbis-30#section-4.4.2

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2021-07-22 16:33:52 +02:00
Maximilian Nitsch
2a981e86e2 Change DTN timestamp to milliseconds
To be compatible with the latest version of BPv7, the internal
representation of DTN timestamps, for both uD3TN and the Python library,
is changed to milliseconds.
For compatibility reasons, a conversion to seconds is performed during
the de-/serialization of BPv6.
Furthermore, additional test cases are added and the creation_time_ms of
the test bundle is set to a non-trivial timestamp.

Also, the Python functions for converting POSIX timestamps to DTN
timestamps are removed, as there is now a distinction between BPv6 and
BPv7 DTN timestamps. The conversion is now done in the corresponding BP
implementations themselves.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2021-01-14 14:42:55 +01:00
Felix Walter
7587d97b96 Fix indentation in function signatures returning ud3tn_result
The re-name to "enum ud3tn_result" broke the indentation in some
function signatures, which is fixed by this commit.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2020-11-18 12:31:38 +01:00
Felix Walter
490a312c84 Adapt mentions of uPCN to uD3TN in code files and headers
This updates all remaining references in the code to mention the new
name.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2020-11-17 15:51:10 +01:00
Felix Walter
288b99069c Replace enum upcn_result by enum ud3tn_result
This renames the enum and its two constants `UPCN_OK` and `UPCN_FAIL`
accordingly.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2020-11-17 15:51:10 +01:00
Felix Walter
fb4238a97d Adapt core include path from upcn/ to ud3tn/
This moves all headers from upcn/ to ud3tn/ and adapts the #include
statements accordingly.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2020-11-17 15:51:10 +01:00
Felix Walter
0ce4bee910
Initial import of uPCN v0.8.0 source code
This is the initial commit for uD3TN. uD3TN is a fork of uPCN v0.8.0,
which will be developed and maintained in a public Git repository.

For questions concerning the history of and code provided with uPCN,
please get in touch with us via: contact <at> d3tn <dot> com

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2020-11-14 11:56:40 +01:00