Commit graph

49 commits

Author SHA1 Message Date
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
Oleksandr Nazymko
2ee80187b8 Remove outdated README
This removes outdated README from `components/bundle7/` BPv7 implementation.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-12-19 14:04:25 +01:00
Felix Walter
bde39aac81 bundle7/reports: Use the proper test for BIBE draft v1 compatibility
See also the previous changes to application_agent.c. If this macro is
set to 0 in config.mk, we do not want to enable the compatibility
behavior.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-10-26 14:45:52 +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
de31d057ca Prevent side effects in macros
- Only access each argument once
- Use parentheses around macro arguments upon use

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-07-25 13:15:05 +02:00
Felix Walter
d9f1180836 bundle7: Suppress cppcheck false positive
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-06-08 10:47:47 +02:00
Felix Walter
63368aa8d8 bundle7/reports: Explicitly free if no bytes were written
This would be implicit behavior by `realloc` which we make explicit to
improve clarity of the code.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-06-08 10:47:47 +02:00
Felix Walter
089f2c2389 bundle7/serializer: Suppress cppcheck warning on self-assignment
The byte swap is required to derive the proper CRC, but cppcheck detects
it as unnecessary self-assignment.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-06-08 10:47:43 +02:00
Felix Walter
b4e3e5aae9 bundle7/parser: Add note why status is set to DONE even if CRC is invalid
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 09:14:37 +02:00
Felix Walter
112fc969a7 bundle7/parser: Remove unnecessary string duplication
This is a remnant from our "EID manager" with which we were trying to
reduce copies of strings in memory. This module has long been removed as
it lead to only small gains while complicating everything. However, it
seems that during the removal process we introduced an unnecessary
strdup() here, which is removed by this change.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 09:14:37 +02:00
Felix Walter
7ea821b67a bundle7/parser: Set parsed EID to NULL on error
If there is an error the parser will try to reset the "in-progress
bundle". If an EID field is set to *some* pointer (except NULL), it will
be free()'d, leading to a double free if the `parse_eid` operation fails.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 09:14:37 +02:00
Felix Walter
22b4d9d7db
Merge branch 'hotfix/clang-tidy-false-positives'
See !98
2023-05-12 08:30:25 +02:00
Felix Walter
424ea0e186 Remove comments to silence clang-tidy false positives
We disable the warning altogether via the proper commandline option.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-11 17:08:39 +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
f1c59a0024 bundle7: Silence occasional clang-tidy false positive
Every couple of tens to hundreds of builds, clang-tidy will issue a
warning of type `clang-analyzer-valist.Uninitialized` here. A `grep` on
the whole source tree shows no `va_list` being used anywhere near - the
`*printf` functions of `tinycbor` are not called by us.

Fixes: #117

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:25:13 +02:00
Felix Walter
b2ecb9a117 bundle7: Ensure that the currently-constructed block is never overwritten
It may be the case that `block_type` is invoked directly at a chunk
boundary, leading to it returning CborErrorUnexpectedEOF.
This ensures that the already-constructed block entry is reused when, in
this case, `block_type` is invoked again after filling up the chunk
buffer.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:07:16 +02:00
Felix Walter
8b0a5ed644 bundle7: Update tinycbor dependency
This also fixes some NULL pointer additions (UB).

Found by Clang's UB sanitizer.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:32:47 +02:00
Felix Walter
fcfadd058f bundle7: Fix handling of NULL buffers in parsers
Previously it was passed directly to the CBOR parser causing undefined
behavior.

Found by Clang's UB sanitizer.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:32:47 +02:00
Felix Walter
2fc9e11b7e bundle: Fix potential uint wrap-around in expiration time calculation
We were taking the current time value in milliseconds and sometimes
subtracting larger values from it. This cleans up the calculations to
always determine the expiration time as uint64_t and compare it against
the current uint64_t timestamp.

It further removes the unnecessary "current timestamp" parameter in
`bundle_get_expiration_time_s` (we now store the reception time with the
bundle, so, do not need this anymore) and avoids a integer wrap-around
case in the function.

Note that the current time cancels out in the age block-based
calculation as we can use the reception timestamp there and offset it by
the calculated relative remaining lifetime.

Found by Clang's UB sanitizer.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:31:17 +02:00
Felix Walter
7d97e0a4f8 bundle7/parser: Truncate to uint16 before implicit conversion
The function call argument is already a uint16.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:24:31 +02:00
Felix Walter
79aa631ac2 bundle7: Abort on errors in calculation of serialized size
This indicates a program bug and should trigger an assertion in debug
builds as it may otherwise lead to hard-to-debug issues.

Note that the parser already asserts EID validity, thus, this will never
be triggered for received bundles.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-11-22 08:09:48 +01:00
Felix Walter
7d646c1e50 bundle7: Allow "\0" as representation of the null EID
This is the equivalent of the CBOR encoding of dtn:none and, thus,
should be parsed properly.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-11-22 08:09:48 +01: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
Felix Walter
8bde2cad33 bundle7/eid: Fix ipn EID parsing for servicenum == 0
If the service number of a bundle7 EID was set to zero, this resulted in
an EID like "ipn:xxx." instead of "ipn:xxx.0", because the allocated
length was determined in the wrong manner for the special case of zero.

This also adds tests for the "zero" case and the case of UINT64_MAX.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-08-29 13:58:06 +02:00
Felix Walter
081871945f bundle_processor: Fix memleak and CBOR issue in BIBE AR handling
There were actually two issues here:
- The latter part of `adu.payload` was copied and the field just
  replaced by the copy (`buf`) without freeing the previous value.
- Always a constant length of 2 bytes were skipped, but one of the
  fields skipped is the record type code which is a CBOR unsigned
  integer with valid values up to 255, thus, _either_ one or two bytes
  long.

This adds a pointer to the first byte of record-specific data in the
parsed byte string and leverages its value to skip the correct amount of
bytes using `memmove`. (As we do not need the ADU afterwards, we can
destructively overwrite it and hand the remaining BPDU to the BIBE
agent.)

See: https://www.rfc-editor.org/rfc/rfc9171#name-administrative-records

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-08-26 12:41:01 +02: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
5ab7ce00d7 bundle7: Fix parsing and serialization of ipn EIDs with large integers
The BPv7 implementation was still using uin32_t for the node and service
numbers in ipn EIDs in several places.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:05:42 +01:00
Felix Walter
0625c07cbb
Merge branch 'feature/39-implement-bibe'
See !43
2022-01-26 21:04:34 +01:00
Tobias Nöthlich
49ecf30c3f Refactor BIBE processing on lower layer
With this commit, the lower layer no longer parses the BPDU before sending
it to the upper layer. This also removes the neccessity to re-serialize
the BPDU in the bundle_processor.c file. The lower layer does however
still check whether the BPDU is valid and discards it if it is
malformed in any way.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2022-01-26 21:04:02 +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
Tobias Nöthlich
aa384211f4 Move check for compatibility flag
As discussed, checking for the BIBE compatibility flag is not really
config and should instead be handled in the correspinding implementation
files.

This commit moves the check for the flag from the config.h file to
reports.c and bibe_proto.c.

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
Tobias Nöthlich
e7fa9ff420 Fix posix build errors
Declaring the array ar_bibe_bytes[ar_size] in the bibe_encode_header
function caused a warning, which when building with type=release gets
treated as an error.

This commit fixes this issue by allocating the buffer using malloc()
instead of declaring an array. It also fixes some oversights creating
type mismatches in bibe_proto.c and reports.c.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-12-10 14:51:14 +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
ca765ba8ad Ensure compatibility to first draft of BIBE
Some DTN implementations still run a BIBE implementation based on the
first draft of the BIBE specification. This means, that the BIBE
administrative records generated by these implementations still use
the typecode 7 instead of the more recent typecode 3.

This commit adds the CFLAG BIBE_CL_DRAFT_1_COMPATIBILITY, which sets
the BIBE administrative record type code used by µD3TN to 7, to allow
interoperability with DTNs using older BIBE implementations.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-29 11:55:18 +01:00
Tobias Nöthlich
22f4a43d62 Fix wrong payload in BIBE adu
So far the BIBE payload of the adu forwarded from the bundle processor
has been the whole administrative record instead of just the BPDU.

This commit remedies this oversight by discarding the administrative
record and just encoding and forwarding the BIBE PDU.

For the encoding to work flawlessly another value has been added to the
bibe_protocol_data_unit struct. The unsigned long payload_length stores
the length of the byte string comprising the encapsulated bundle, so
it's easier to calculate the size of the buffer needed for the cbor
operations.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-02 15:13:51 +01:00
Tobias Nöthlich
c320e6ae8b Add a BPDU parser to reports.c
Based on the specifications of draft-ietf-dtn-bibect-03 and using the
data structures added in earlier commits, a parser for Bundle-in-Bundle
Encapsulation Protocol Data Units has been implemented.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-10-25 15:51:14 +02:00
Felix Walter
fbd7819656 bundle7: Fix calculation of fragment header lengths
1) There was an obvious issue with the code here: We want to check that
   the bundle was NOT fragmented, thus, we have to negate the result of
   bundle_is_fragmented.

2) We under-estimated the possible size of bundle fragments if they have a
   fragment offset != 0 (the encoded fragment offset can occupy multiple
   bytes in this case). This uses a conservative estimation for allowing
   scheduling of the bundle such that contacts are never overbooked.

Fixes: #66

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2021-07-30 17:00:47 +02: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
3d82861fdc bundle7: Do not attempt to re-init parser before bulk read
For arbitrarily-long data such as block payload data, a "BULK_READ" operation
is requested, normally to be handled by the RX task. Though, sometimes we can
handle this on our own (if we have enough data in the current buffer).
Thus, we first check whether, given the bytes in the buffer, we can perform
the bulk read operation on our own. However, before doing this, we
sometimes attempted to re-initialize the TinyCBOR parser (in case
cbor_value_at_end returned true), which resulted in an error if the head
of the current buffer points to some binary data that is not valid
CBOR. With this change we always perform the "BULK_READ" first and
re-initialize the parser only after it is done.

Fixes: #49

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2020-12-11 20:57:02 +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