Commit graph

44 commits

Author SHA1 Message Date
Felix Walter
972d62f9d8 hal_task: Add hal_task_wait function to join threads
This enables us to wait for threads to exit cleanly.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2024-06-21 10:36:30 +02:00
Maximilian Nitsch
16f7214215 simple_queue: Add NULL pointer checks to queueCreate() and queueDelete()
- queueCreate: return NULL if malloc() failed
- queueDelete: no-op if queue is NULL

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-06-03 13:41:58 +02:00
Maximilian Nitsch
36b92c5e41 hal_task: Replace sigaction exit handler by sigwait
In order to properly clean up all resources allocated by threads, we
need to join the non-detached threads. This is not possible within the
`sigaction` exit handler function. For this reason, the termination
logic is changed to use `sigwait`.

In addition, SIGALRM is added to the list of handled signals and
SIGUSR1, SIGUSR2 are ignored.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-01-26 14:28:50 +01:00
Maximilian Nitsch
3935a15441 hal_task: Make detached threads optional
Adds a parameter to the `hal_task_create()` function to allow
non-detached threads and a second parameter to pass the thread
identifier.

Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
2024-01-23 15:25:59 +01:00
Felix Walter
5f5269ec1a
Merge branch 'feature/162-clean-up-hal-task'
See !150
2023-12-20 16:25:50 +01:00
Felix Walter
7fcdeab31d Remove hal_config headers
They are unnecessary now. We should do platform-specific definitions
centrally via config.mk as well.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 10:32:48 +01:00
Felix Walter
75edf0cbd7 hal_config: Remove LINUX_SPECIFIC_API switch
We only used it for thread naming - the hal_platform malloc analysis
support was removed a long time ago. As we do not really need thread
naming and removed it when cleaning up hal_task, we do not need this
define anymore.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 10:32:48 +01:00
Felix Walter
47194d21ac hal_task: Remove unused parameters
This removes the parameters for task name, priority, and stack size,
which were mostly relevant for FreeRTOS on STM32.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 10:32:48 +01:00
Felix Walter
0742de7ba9 hal_io: Print log level when printing system errors
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 10:06:48 +01:00
Felix Walter
9917bab703 hal_io: Implement log levels for LOG_ERRNO
This enables us to use log levels for `LOG_ERRNO`. The default is the
"warning" level so that we do not need to adjust all calls. The levels
for connection establishment and receiving from sockets are adjusted to
"info" such that common cases like unreachable peers do not
unnecessarily clutter the logs.

Fixes: #172

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-12-20 10:04:17 +01:00
Felix Walter
6525a453ba Adjust all logging calls to include a log level
Rules that have been applied:

- ERROR: Anything that is or may be problematic for the program to
  continue running.
- WARN: Anything abnormal but definitely not critical for program
  continuation, especially issues encountered when interacting with
  clients (e.g. AAP).
- INFO: All state changes not corresponding to the "normal" processing of
  individual data or messages/bundles, as well as further informative and
  helpful messages. Includea errors that occur during normal data
  processing.
- DEBUG: Messages to trace what happens with individual bundles and
  other fine-grained information about internal processes.

At the moment, `LOG_ERRNO` always emits messages with the "ERROR" level.
We might want to change this in the future to better differentiate WARN
and ERROR in this regard also.

Closes: #140
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-24 14:50:25 +01:00
Felix Walter
7b7ff98a2d cmdline, config.mk.example: Make it clear that log level 4 is debug-only
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
8dbbb9d692 hal_io: Add LOG(F)_INFO to explicitly log with "INFO" level
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
f02fdc042d hal_io: Protect logging via mutex
This resolves the race condition documented in #139.
The log macros now each call only a single function which locks
a binary semaphore during execution.

Fixes: #139

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-16 14:20:04 +01:00
Felix Walter
485a06b381 AAP, AAP2: Move common socket handling parts to dedicated module
There is some common functionality that should not be copied.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-11-09 14:33:48 +01:00
Felix Walter
c945da6bf6 hal_config.h: Allow for changing AAP and Linux-spefific defs
For two settings previously defined in `hal_config.h` it makes sense to
make them changeable via `config.mk`. The AAP setting is moved to the
appropriate header and the Linux-specific APU define gets a guard so it
can be changed at compile time.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-10-25 15:56:53 +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
95b8a36fd2 hal_io: Do not reuse macro argument
This may lead to side effects (discovery by the style checker).

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-07-28 15:04:50 +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
Oleksandr Nazymko
bfa565d420 Enable debug log statements in debug build only
This removes the `DEBUG` log statements when compiling with `type=release`
for better performance.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-14 14:20:11 +02:00
Oleksandr Nazymko
da35fa6e6d Pass log level to init.c and adjust log message format
This adds log level to `ud3tn_cmdline_options` struct so that command line parser passes the value to `init.c` and has no side effects. Also adjusts log message format
for printing out current log level.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-14 14:09:08 +02:00
Oleksandr Nazymko
b7bf3ef9a5 Add generic log function
This adds generic log function `LOGF_GENERIC` which accepts logging level as argument. Also adds different log messages for different logging levels.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-10 11:23:55 +02:00
Oleksandr Nazymko
e0d5ae89a4 Add cli parameter for logging level
This adds cli parameter `-L` which can specify logging level for program.

Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
2023-07-10 11:04:33 +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
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
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
00d5d2d050 external, hal: Remove unused crypto (HMAC, SHA2) and JSON functions
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>
2023-05-12 09:12:30 +02:00
Felix Walter
379f09d7af hal_time, agents: Remove the function to set the system time
This should be a function offered by the operating system, not by a
userland process like uD3TN.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-11 16:59:13 +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
69e4095dcb Remove hal_random
The test was returning indeterministic errors and we did not even use
the function anymore.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 17:23:55 +02:00
Felix Walter
65d7582a88 Provide LOGERROR() macro for errno logging and remove strerror
`strerror()` is not thread-safe, thus, we have to use an alternative. If
we want to prevent allocating a temporary buffer (e.g., for
`strerror_r`), we need to use `perror()`. To allow writing stored
`errno` values, the function sets `errno` from an argument passed to it,
which should be safe according to the manual.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:37:02 +02:00
Felix Walter
e27c157107 hal_platform: Remove unnecessary platform-dependent functions
This removes some functions solely useful for the STM32, debugging and
error handling with these boards. When doing a future uC port, we should
move such functions to the platform-specific part.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 15:07:16 +02:00
Felix Walter
e31a865bf8 hal_semaphore: Supply proper function to check if blocked
The previous polling method was not clean in that it left the semaphore
locked and did not return whether the operation was successful or not.
This adds a more descriptive and correct method to chieve the goal of
checking the semaphore's status.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:37:11 +02:00
Felix Walter
baf1aac4c2 hal_io: Forward all logs to stderr and make it line-buffered
This switches all log messages to `stderr`, which is intended for
diagnostic purposes (i.e., matches the intent of our log messages). This
makes it easy to distinguish the log output from actual output (which
the uD3TN daemon does not have, but a program based on libud3tn might).

This also flushes stderr after every log message (i.e., makes it
line-buffered) to prevent delays when outputting the logs.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:32:56 +02:00
Felix Walter
dd6d34d707 hal_time: Make time functions thread-safe
Do not return a reference to a non-thread-safe global variable:
ctime() is not thread safe. As we only use the function in logging, we
can directly print the return value, protected by a mutex.

This also adapts the tests and makes the initialization routine always
run. To use the system time again, UINT64_MAX can be passed.

Found by Clang's thread (data race) sanitizer.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2023-05-10 14:32:47 +02:00
Felix Walter
6279aa633d Remove Router Optimizer
The "Router Optimizer" was a task that re-ordered bundles according to
the stated priority. As this was only supported for BPv6 and can be
easily exploited by a sender by always stating the highest priority for
their bundles, it is considered unnecessary for future versions of
uD3TN.

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-12-07 17:42:21 +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
de21a0f5ea simple_queue: Adapt license notice
As we are moving to `BSD-3-Clause OR Apache-2.0`, this needs to be
adapted as well. (We got the permission of Robert to publish his code
under the new licensing scheme.)

Signed-off-by: Felix Walter <felix.walter@d3tn.com>
2022-02-19 23:42:22 +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