Commit graph

558 commits

Author SHA1 Message Date
Felix Walter
40d685ad3e CLA: RX: Prevent infinite loop in buffer_read
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>
2023-05-16 11:34:14 +02:00
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
4462cc7108
Merge branch 'hotfix/dynamic-library-linking-argument-order-issue'
See !112
2023-05-15 17:11:17 +02:00
Felix Walter
2889a17f23 mk: Simplify passing linker flags and pass them in correct order
On some systems (incl. our x86_64 Debian based CI), the change of the
linker argument order in 602c4ce0 broke the build, as the flag was then
passed after the library options (i.e. `-lc -lm -lpthread`).

This change removes the modifications to the `LDFLAGS` and `LDFLAGS_PRE`
variables in `build.mk` by making use of the `LDFLAGS_EXECUTABLE` and
`LDFLAGS_LIB` variables directly in dedicated linker commands.

An additional variable `LDFLAGS_PRE_LIB` is introduced for adding
preceding flags specifically for the library build (as `LDFLAGS_PRE` is
not touched anymore in `build.mk`).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 15:26:57 +02:00
Felix Walter
1c6d91a1a0
Merge branch 'hotfix/mac-osx-compatibility'
See !105
2023-05-15 14:20:52 +02:00
Felix Walter
13fb85b60e
Merge branch 'feature/static-library'
See !76
2023-05-15 14:20:22 +02:00
Felix Walter
cee2701dc7
Merge branch 'feature/test-aap-bundle-send-recv'
See !109
2023-05-15 13:47:44 +02:00
Felix Walter
8d647bbca0 README.md: Add a section on building the libraries
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 12:03:35 +02:00
Felix Walter
fe0404671d test/integration: Apply suggestion to make usage of TCP default socket easier
See https://gitlab.com/d3tn/ud3tn/-/merge_requests/109#note_1389996506

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:42:39 +02:00
Felix Walter
769b1b0abe python-ud3tn-utils: Document functions handling the bundle ID
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:40:47 +02:00
Felix Walter
c641197313 test/integration: Also test AAP bundle ID encoding
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:40:47 +02:00
Felix Walter
fd4fe60fe4 test/integration: Add test for aap send/recv with bundle ID check
This is basically an extended `aap_test.py` as part of the integration
tests, which verifies the received AAP messages and also checks the
returned bundle ID if it contains a well-formed timestamp and sequence
number.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:40:47 +02:00
Felix Walter
f81c96834e platform/hal_semaphore: Use defined constant instead of magic number
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:39:29 +02:00
Felix Walter
dc6f5c5887 contact_manager: Make assumption about maximum delay constant explicit
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>
2023-05-15 11:39:29 +02:00
Felix Walter
1a0eca1587 platform/hal_semaphore: Reduce inline #ifdefs
This provides dedicated `hal_semaphore` functions for Apple and
non-Apple platforms.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:39:29 +02:00
Felix Walter
94bd34ea65 contact_manager: Add assertion for contact time calculation
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>
2023-05-15 11:39:29 +02:00
Felix Walter
6880b22b90 hal_semaphore/hal_queue: Accept 64-bit timestamps as delay
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>
2023-05-15 11:39:29 +02:00
Felix Walter
7f322764e9 hal_semaphore: Fix determination of timestamp for sem_trywait
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>
2023-05-15 11:39:29 +02:00
Felix Walter
15f2748207 simple_queue: Deallocate pop and push semaphore on queue deletion
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:39:29 +02:00
Felix Walter
a5313fc9ac Revert "mk: Pass -pie flag only to linker"
This reverts commit 340e69165dd89bab9af9d607dda7ca3d8cb6b828.

Breaks build on some Linux with clang.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:39:29 +02:00
Felix Walter
35b295e8dd mk: Only add the unittest libs and includes to testud3tn
This is just a cleanup change - we do not want to include that stuff in
our main library and executable.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:39:29 +02:00
Felix Walter
62d563449f test: Remove the Unity wrappers for memory allocation functions
This adds a custom header that does explicitly not include the Unity
wrappers for malloc, free, etc. by defining the guard used by that header
file. This way we can remove the wrappers provided via the linker
altogether.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:39:29 +02:00
Felix Walter
c40fa97226 mk: Add a warning that testud3tn does not build on MacOS
The `--wrap` option is not present in the Darwin linker. Thus, we cannot
build the tests on MacOS.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:01:34 +02:00
Felix Walter
adb80c8938 simple_queue: Remove queueItemsWaiting
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>
2023-05-15 11:01:34 +02:00
Felix Walter
52b1fa41e8 mk: Use -all_load linker flag instead of --whole-archive on MacOS
The latter is not supported there, but we need to include everything
from all static archives provided to the linker, so we use -all_load as
per the Darwin linker docs.

See: https://gcc.gnu.org/onlinedocs/gcc-3.3.6/gcc/Darwin-Options.html
See: https://github.com/bioinformatics-centre/kaiju/issues/30

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:01:34 +02:00
Felix Walter
e94481e0d2 mk: Pass -pie flag only to linker
clang will otherwise warn on MacOS that the flag is unused during
compilation.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:01:34 +02:00
Felix Walter
ee101e80dc mk: Make linker groups conditional based on detected OS
The MacOS linker does not support linker groups, but the GNU / Linux
linker requires them in our case.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:01:34 +02:00
Felix Walter
1e8d86548c hal: Add a hal_semaphore implementation that works on MacOS
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>
2023-05-15 11:01:34 +02:00
Felix Walter
f07262b909 Rename fallthrough macro to fallthrough_ok to prevent conflict
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>
2023-05-15 11:01:34 +02:00
Felix Walter
03aaf723c4 application_agent: Conditionally enable _DARWIN_C_SOURCE on Apple
We use `MSG_DONTWAIT` in the app. agent, see #126.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:01:34 +02:00
Felix Walter
da5242cc3b CLA: TCP: Conditionally define constants not present on Mac
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>
2023-05-15 11:01:34 +02:00
Felix Walter
602c4ce00a mk: Only link dynamic library with --whole-archive
For the executable we should not use this option as it unnecessarily
increases binary size.

There might also be incompatibilities with Mac, see #126

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:01:34 +02:00
Felix Walter
e58181818e mk: Do not output map file during linking
This was only necessary for STM32 and it seems that there are
compatibility issues with LLVM on Mac.

See: #126

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-15 11:01:34 +02:00
Felix Walter
6112e9669c
Merge branch 'hotfix/parser-issues'
See !108
2023-05-15 10:43:20 +02:00
Felix Walter
6b88cbc673
Merge branch 'feature/add-bundle-unit-tests'
See !102
2023-05-15 10:43:02 +02:00
Felix Walter
ee0c75c237
Merge branch 'hotfix/47-no-contact-interval-check-in-config-parser'
See !15
2023-05-15 10:39:17 +02:00
Oleksandr Nazymko
691d10ede2 Fix bug in bundle.c
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>
2023-05-15 08:52:29 +02:00
Oleksandr Nazymko
51fa02b77c Add unit tests for bundle operations
This adds unit tests for the functions in `components/ud3tn/bundle.c`.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-05-15 08:46:46 +02:00
Felix Walter
62cadd3719 Move the node_prepare_and_verify to router_task
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>
2023-05-12 11:59:43 +02:00
Felix Walter
5c879eedca
Merge branch 'feature/add-coverage-report-option'
See !103
2023-05-12 11:36:49 +02:00
Oleksandr Nazymko
06b937452c Add code coverage report
This integrates code coverage report into gitlab CI. Also adds an option for generating code coverage
report after running unit tests to the Makefile.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-05-12 11:30:27 +02:00
Felix Walter
7539d07fc0 Makefile: Build libraries as well by default
A simple call of `make` will now also build the libraries.

Please note:
We have a quite specific way to re-execute `make` inside the Makefile with
a specific `PLATFORM` set. If we specify multiple targets outside of
this, `make` will execute itself twice concurrently if a `-j` option is
set, leading to race conditions. Thus, we add a new `posix-all` target
that is used to invoke the "inner" `make` process with the proper
`posix` and `posix-lib` targets.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 10:44:10 +02:00
Felix Walter
6f0de0c7f0 mk: Also build a static library
This combines the static libraries into one libud3tn.a that can be used
for static linking. It shall be noted that we are using a "thin" archive
(containing symlinks) for maximum compatibility - e.g., the ARM version
of ar does not support conversion and we cannot always assume libtool to
be present. The main objective is to build a library usable for linking
it into uD3TN-NG.

See: https://stackoverflow.com/a/23621751

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-12 10:44:10 +02:00
Marius Feldmann
11b0d49796 Validate contact intervals in RoutingTable
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>
2023-05-12 10:43:43 +02:00
Felix Walter
eb0dc27e77
Merge branch 'hotfix/sanitizer-flags'
See !110, !83
2023-05-12 10:35:07 +02:00
Felix Walter
8a523d47fd
Merge branch 'feature/remove-dangerous-functions'
See !106
2023-05-12 10:20:43 +02:00
Felix Walter
ec35a3d094
Merge branch 'feature/remove-unnecessary-external-libs'
See !107
2023-05-12 10:20:15 +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