Sometimes the parser does not read any data and goes into the error
state. In this case we get an infinite loop as `buffer_read` resets the
parsers but does not hand back control to the caller.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This adds a target `data-decoder` which builds a binary to decode a
specified binary file using uD3TN's parsing logic (based on the CLA RX
subsystem) and print details about it. In this first version only the
decoding of BPv7 bundles is implemented.
This binary can be used, e.g., for fuzz testing.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
If the implementation of `hal_queue` changes at some point, we want the
conversion from `uint64_t` to `int64_t` still to be safe here.
If the condition is always true, compiler optimizations will remove it
automatically.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
It is important that the "next contact time" always exceeds the current
timestamp. Otherwise, an infinite loop and DoS can occur.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Previously the maximum waiting time was just over 24 days. In a DTN
setup we may want to wait longer, e.g., for contacts to occur. This
allows for waiting about 292 years. If the provided delay exceeds this
threshold, an infinite delay is assumed.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The nanoseconds field in struct timespec must not exceed 1000 million,
i.e., one second. As we add to an absolute time we might exceed this in
some cases. Thus, we need to check for it and reflect the additional
second in the seconds field of struct timespec.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
We cannot easily support this on MacOS, but we do not use it except in
tests. Thus, remove it and make the tests only run on Linux and use
`sem_getvalue` directly.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Unnamed semaphores are unsupported there, which is why we were seeing
segfaults.
See also: https://stackoverflow.com/a/27847103
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
There is the compiler attribute `fallthrough` already. This
re-definition makes checking for it using __has_attribute impossible.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Some constants we use are not available when building on Mac, see #126.
- ENONET: Should not occur on these systems
- EHOSTDOWN: Should not occur on these systems
- NI_MAXHOST: Just a sensible default present on Linux, so we set our
sensible default.
- NI_MAXSERV: Same as the above.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This fixes a small bug in `bundle.c` in `bundle_dup` function which caused an endless loop.
Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
This removes the `hal_time` dependency of the `routing_table`, as it now
assumes that the provided `struct node` is ordered, free of conflicts,
and has valid contact timestamps. This is ensured by invoking
`node_prepare_and_verify` beforehand, in `router_process_command`.
The tests are updated accordingly.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
So far the contact interval check was done in the
config parser. As this is a semantical and not
syntactical check it is moved to the RoutingTable.
Modified @ 2022-12-21 by Felix Walter to adapt to new state of codebase,
adding the check to `node_prepare_and_verify` in `node.c` instead.
Closes: #47
Signed-off-by: Marius Feldmann <marius.feldmann@d3tn.com>
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>
This removes all external functions currently unused in uD3TN.
We may re-introduce esp. JSON at a later point in time, but should
include updated libraries anyway.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This function is dangerous: if the resulting string is longer than the
buffer, no null-termination is added to it. Also, it always fills the
remaining buffer length with zeroes.
snprintf is fast and can always be used as replacement (and sometimes
there are better substitutes).
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Commit b07a653389 was not properly
rebased, so it still used the old variable name `time`, not `time_ms`
that was introduced in 3cd89eb6a5.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This also adds a test for it, sending bundles from within ION to uD3TN
in the "minimal forwarding test".
Fixes: #7
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This allows us to specify a maximum number of bundles sent per second by
the CLA TX task.
We have to make the bundle transmission less "bursty" in case there is
no additional buffering on the lower layers. For example, if SPP data
received via the TCP socket are directly written to the onboard bus like
on the OPS-SAT.
This smoothes out waiting times by using a constant, pre-calculated
sleep in the TX task if compiled with CLA_TX_RATE_LIMIT defined.
Compile as follows:
make posix CFLAGS="-DCLA_TX_RATE_LIMIT=<max_bundles_per_second>"
whereas `<max_bundles_per_second>` is an integer number (range of
uint32_t, but not zero).
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
See the added description in the AAP documentation - this adds an
internal format to the 64 bit integer value returned as "bundle ID" in
the `SENDCONFIRM` AAP message to uniquely identify the created bundle in
conformance to RFC 9171.
Closes: #60
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This changes the "from" and "to" fields in the contact struct to
milliseconds-based timestamps and adapts all dependent code. The contact
data format is kept second-based for backward compatibility.
The commit also introduces a new function to work with millisecond
timestamps in the remaining capacity calculation and modifies the tests
related to the latter such that they do not need to change the timestamp.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This introduces a function to work with milliseconds-based timestamps
also in case of the expiration time.
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>
This removes the need to send them via the queue which might result in a
deadlock as described in #115. The bundle processor context is passed as
an opaque pointer that can be used for calling BP functions from agent
callbacks (which run inside the BP thread).
Fixes: #115
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This may cause a deadlock which we observed sometimes in the routing
integration test in CI as one slot in the BP queue is always needed to
finish processing the Bundle in the BP (that causes `agent_forward` in
this case).
This makes the config agent directly invoke the BP function.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
`hal_task_create` returned a reference to the new task allocated on the
heap via `malloc`. We commonly used the pattern to `free` this reference
from the new thread which, however, could result in race conditions and
other synchronization issues. We added a fix using a semaphore in the
application agent, but this would have been needed in other places (CLA,
...) as well. As we do not make use of the task reference anywhere
besides in the CLA for error handling, we can remove the heap-allocated
value altogether and replace it with an `enum ud3tn_result` to simplify
things and circumvent the named synchronization issues.
In the case of the CLA function `cla_link_init`, logic is introduced to
request the RX task to exit immediately in case the TX task cannot be
launched.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The `task` field in the communication task config was set by the main
task _after_ the creation of the comm. task. This may lead to
synchronization issues as the comm. task needs to access the field to
de-allocate it upon termination.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>