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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
This commit remedies code smells introduced by implementing the BIBE
convergence layer adapter.
Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
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>
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>
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>
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>
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>