Commit graph

33 commits

Author SHA1 Message Date
Felix Walter
e16ec4c579 Enable building a BPv7 decoder binary
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>
2023-05-16 11:34:14 +02:00
Felix Walter
1237eaa2db Remove heap-allocated Task_t
`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>
2023-05-10 17:23:55 +02:00
Felix Walter
af462184b3 CLA: Synchronize access to link parameter data structure
The primary issue that was also identified by Clang's thread sanitizer
was that we were accessing fields like `link->active` from multiple
threads concurrently. See [1], especially under optimizations such a
variable cannot be used to tell other threads when to terminate.

The primary fix here is to introduce a guarding mutex (binary semaphore)
around the "link parameters" data structures in all connection-oriented
CLAs. The mutex is only locked when working with the structure and
should always be unlocked when a blocking operation (e.g., `accept()`,
`send()`, `recv()`) is executed. To achieve this, we sometimes store the
return value of such functions in a temporary variable before re-locking
the mutex and adapting the param struct.

The `cla_link_wait_cleanup` routine is split in two parts so that during
the "wait" operation the mutex can be unlocked and when cleaning up the
link (consequently needing to update and drop resources from the link
parameters) it can be locked.

The "serializer functions" (`*_begin_packet`, `*_send_packet_data`,
`*_end_packet`) do not need to ckech for `link->active` anymore (which
is removed) as it is made sure to terminate the TX task invoking the
serializer before invalidating the link structures. If anything is
invalidated by the OS (e.g., by the TCP connection breaking), an error
will occur in these functions and propagate to the TX task, leading to a
call to the `cla_disconnect_handler`, in turn tearing down the link, but
the link parameters will be 100% valid the whole time.

Additionally, to notify the RX task when it should exit, another semaphore
is introduced. The TX task already has a thread-safe queue to send a
notification to it to terminate, removing the need for another check.

The locking of the "param hash table", where the "link parameters" are
stored is revised such that it is always locked while changes occur to
it or the values stored inside it (as long as they are not locked
themselves by the specific param semaphore.

[1] https://github.com/google/sanitizers/wiki/ThreadSanitizerPopularDataRaces

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:07:13 +02:00
Felix Walter
2b3a76c409 cla_bibe: Fix out-of-bound write
The BIBE CLA allocated a buffer the size of sizeof(struct aap_message)
but then serialized an AAP message into it. It should have used
aap_get_serialized_size(), though, this change directly removes the
unnecessary buffer in between and directly writes out the data.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 11:10:24 +02:00
Felix Walter
69eab551ab Transmit the whole list of bundles in the TX queue
This reduces the number of queue sends as the whole bundle list is
transmitted by the CM to the TX task which then consumes it iteratively.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 21:02:38 +01:00
Felix Walter
93a58ed387 Merge Bundle Processor and Router Task
This refactors the Router Task into synchronous functions called by the
BP, preventing the need of circular notifications between them.
The router queue is replaced by new signals in the BP queue.

This additionally removes the global state in the bundle processor.

Closes: #11

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 21:02:36 +01:00
Felix Walter
f8395e8d94 router: Remove probabilities and struct routed_bundle
The probability-based routing was never used productively. It implied
that we store all the contacts for which a bundle was scheduled (as
there may be more than one) and keep it, doing reference counting before
we drop the data structure, and so on. This change removes everything
probability-related. The field in the config commands is kept to ensure
backwards compatibility if this is specified.

The removal of struct routed_bundle allows for a major simplification of
all routing-related code.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:59:43 +01:00
Felix Walter
3ade800bd5 Always spawn an RX task in TCP CLAs
We need to recv() on the TCP socket to detect it when the connection is
closed or reset.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:56:39 +01:00
Felix Walter
6663ac4f8f CLA: Allow unidirectional links and specify directions upon link init
Some CLAs such as MTCP use unidirectional links. In these cases, we
should not start a TX _and_ RX task. This adds two parameters to
cla_link_init to specify the direction(s) used by the created link.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:56:39 +01:00
Felix Walter
db293b5020 CLA: Report proper CLA address to router
Previously we did not include the CLA name. This also removes the
unnecessary `cla_type` field in the struct, whose value can easily be
obtained by the `cla_name_get()` function.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:36:49 +01:00
Felix Walter
4d8bbd9a8e CLA: Communicate CLA address in link up/down signals
This informs the router also of the address of the connected peer in the
relevant signals issued by the CLA subsystem to the router task

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 20:36:49 +01:00
Felix Walter
d8fef5c776 TCPSPP: Ensure the maximum SPP size is never exceeded
This will abort execution in case the CLA attempts to issue an SPP
packet larger than the maximum SPP size. For this purpose a
configuration parameter is added that may be adapted to the connected
communication subsystem. The router ensures that this should not occur,
but we add an additional safety check as some CCSDS engines may be
placed into an invalid state in case they are confronted with too large
SPP packets, which must not occur in productive environments.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-11-24 20:28:14 +01:00
Marius Feldmann
691b7c3172 Remove STM32/FreeRTOS support from uD3TN
Former releases of uD3TN have included support for STM32/FreeRTOS.
Having this support from the first moment on was a good thing in
order to optimize for platforms with limited resources. As this
platform is not used in current uD3TN setups and as it results in quite
some maintenance work, it is removed with this commit. The removed parts
cover the implementation itself, tests, tools, documentation, parts of
the build/make scripts as well as licensing information.

Signed-off-by: Marius Feldmann <marius.feldmann@d3tn.com>
2022-03-22 00:05:13 +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
2c22cd215f CLA: BIBE: Fix memory leak in bibe_begin_packet
In `bibe_begin_packet` another occasion of using `strdup` combined with
`strtok` was found that did not properly `free` the result of `strdup`.
This uses `strchr` instead to get the latter part of the CLA address
string, containing the next-hop EID.

This further checks the provided next-hop EID is valid upon obtaining
a TX queue. By that, the contact manager can properly return an error in
case the EID is invalid.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:04:02 +01:00
Felix Walter
a17d432cbb CLA: BIBE: Manage the AAP parser in BIBE-specific structures
This is not needed by other CLAs, thus, should be moved to BIBE-specific
data structures.

Additionally, the "bibe_parser" is not used anywhere (leftover from a
previous change?) and is removed in the course of this change.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:04:02 +01:00
Tobias Nöthlich
e411bfea10 Rename struct header to bibe_header
This commit renames the struct containing the BIBE header to bibe_header
to reduce ambiguousness.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2022-01-26 21:04:02 +01:00
Felix Walter
be19d40290 Apply the suggested changes to the order of include statements in bibe_proto.h.
Triggered by @noethlich, see !43

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-01-26 21:03:28 +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
a960a744a6 Implement BIBE header encoding and transmission
While receiving and parsing BIBE bundles via the BIBE CLA was already
working, transmitting BIBE messages required the encoding of the BPDU,
the administrative record and the enclosing AAP SENDBIBE message
before transmission.

This commit adds this functionality, to allow the BIBE CLA to transmit
and receive bundles as needed.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-29 11:45:38 +01:00
Tobias Nöthlich
a3f43b90a9 Add processing of cla_addr parameter to cla_bibe.c
As the cla_addr parameter contains the EID of the next hop of a BIBE
bundle, it needs to be processed in the cla_bibe.c file.

This commit adds the necessary operations to retrieve the EID from the
cla_addr string. It also adds the necessary function calls for
encoding the BIBE header.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-29 11:20:34 +01:00
Tobias Nöthlich
9310ea3125 Add cla_addr parameter to cla_contact_tx_task_command
In order to be able to pass the CLA address to the begin_packet method
of a given CLA, it has to be available within the cla_contact_tx_task.

This commit adds the CLA address to the tx task comman, thus making it
available when calling a given CLA's begin_packet method.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-29 11:06:21 +01:00
Tobias Nöthlich
79aa116de9 Add cla_addr to CLA begin_packet function
As the BIBE CLA will need the EID of the next hop to properly address
the generated AAP message, the cla_addr parameter was added to the
begin_packet() method of all CLAs.

Specifically for the BIBE CLA, the cla_addr parameter will contain the
EID of the next hop the bundle will take from the lower layer. For the
other CLAs the cla_addr parameter will remain unchanged.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-29 10:56:57 +01:00
Tobias Nöthlich
264f978a46 Add first iteration of the BIBE CLA
This commit adds the first iteration of the BIBE CLA to µD3TN.
For now the BIBE CLA can connect to another µD3TN instance using the
same aap_config.py script the other CLAs also use, register itself as
an application on said other instance and receive messages addressed to
the "bibe" endpoint on the lower layer instance. These messages get sent
to the upper layer (the µD3TN instance the BIBE CLA runs on) via AAP
RECVBIBE messages. The BIBE CLA parses these messages, retrieves the
encapsulated bundle and informs the bundle processor of the incoming
bundle.

So far the reception aspect of the CLA is implemented and working.
Transmission of bundles using the BIBE CLA is not yet supported.

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-12 14:33:00 +01:00
Tobias Nöthlich
7cf69dfe34 Prepare cla_contact_rx_task for inclusion of BIBE
Until now, the cla_contact_rx_task only processed bundles (v6 and v7).
As the BIBE CLA will receive AAP messages from the lower layer, handling
AAP messages in the cla_contact_rx_task becomes a necessity.

This commit prepares the rx task for the inclusion of the BIBE CLA by
adding the cla_payload_type PAYLOAD_AAP and by adding an aap_parser to
the rx_task_data struct. It furthermore implements the check whether an
incoming message is an AAP meesage, by checking whether the first 4 bits
of an incoming message evaluate to the AAP version number (0x1).

Signed-off-by: Tobias Nöthlich <tobias.noethlich@d3tn.com>
2021-11-12 09:56:03 +01:00
Felix Walter
2825595506
Merge branch 'hotfix/67-tcpspp-apid-filtering'
See !32
2021-08-09 16:51:38 +02:00
Felix Walter
fb7667e631 CLA: Make it possible to add an RX read timeout
This adds a compile-time option to add a timeout for reading bytes from
the CLA. If this timeout is exceeded after a CLA read operation, all
parsers will be reset before the received bytes are fed to them.
This feature can be used if it is expected that corrupted or invalid
packets will be received on long-living links, leading to invalid parser
states and no proper processing of valid incoming data.

To enable, compile via:

    make posix CFLAGS="-DCLA_RX_READ_TIMEOUT=<timeout_in_milliseconds>"

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2021-07-30 17:19:55 +02:00
Felix Walter
37a132f7ce CLA: tcpspp: Drop SPP packets destined for another APID
This implements a special "blackhole parser", which reads all bytes
destined for another APID, but does not process them further. This way,
we always achieve a sane parser state if SPP packets to other APIDs (and
not containing bundle data) can be received as well.

Fixes: #67

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2021-07-30 16:57:58 +02:00
Felix Walter
c96f66e481 cla_tcp_common: Always close() TCP sockets on disconnect
In the case of a graceful disconnect of the other peer or if an error
was encountered during recv() or send(), cla_disconnect_handler() is
called on the cla_link. However, the existing handler did not close()
the TCP socket. This led to an exhaustion of file descriptors after many
connections.

This commit adds a TCP-specific disconnect handler which calls close()
on the socket to release the associated resources.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2020-11-19 10:16:48 +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
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