If bundles that were created by the μD3TN instance itself are stored in
the database via the SQLiteCLA and are received again at a later point
in time, μD3TN recognizes that the source node ID matches its own and
EID spoofing is detected.
This commit adds an exception to perform EID spoofing detection only for
packets that were not received by the SQLiteCLA.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
The SQLiteAgent enables SQLiteCLA to read packages from the database and
return them to μD3TN. For this purpose, the SQLiteAgent writes commands
to the queue that SQLiteCLA is waiting for.
The SQLiteAgent itself can be controlled by protobuf messages that
describe which action is to be applied to which set of bundles.
Currently the operations "Push" and "Delete" are implemented and a
filter based on a destination EID pattern.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
The SQLiteCLA makes it possible to write bundles, that are to be sent
via this CLA, to an SQLite database in order to persist them over a
longer period of time and also a restart of μD3TN.
The bundles are saved together with selected metadata (source EID,
destination EID, creation timestamp) in the "bundles" table. A
combination of source EID and creation timestamp is used as the primary
key.
To return bundles to μD3TN, they are read from the database and injected
via the cla_read() function, just like other CLAs that receive bundles.
To trigger this, commands are read from a queue that specify which
bundles are to be read from the database.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
In order to prepare the implementation of a SQLite-based storage CLA, a
basic structure of this CLA with empty functions is created and
adjustments are made to the configuration/initialization functions and
the build system.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
Some CLAs may require access to the bundle meta data to perform actions.
Instead of parsing the raw bytes back to a bundle object, a pointer is
passed to the cla_begin_packet function.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
To enable CLA implementers to properly clean up the allocated resources,
a virtual function `cla_terminate` is added to the CLA interface, which
is called at process termination for all registered CLAs.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
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>
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>
This moves the rate limiting configuration from the general TCP CLA
config (which is per-CLA instance) to the link task parameters. This
way, rate limiting is per contact and not per CLA, which is important
for multi-connection CLAs.
Fixes: #177
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
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>
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>
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>
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>
As we are ensuring that retries happen with a delay in between we can
infinitely retry connections during a contact. This ensures we can
establish a connection even if the peer becomes available significantly
later than the contact starts on our side. The setting can be configured
in `config.mk`.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
uD3TN can continue to run in this case, just without the given CLA. This
introduces a compile-time switch to select whether we want to kill uD3TN
in case a CLA finally fails.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This removes existing dedicated rate limiting logic for connection attempts
in favor of the time-based detection and implements a maximum number for
retry attempts in the latter.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This checks the time the given CLA tried to connect beforehand and
delays the next connection attempt in case the last attempt was more
recent than `CLA_TCP_RETRY_INTERVAL_MS`.
Fixes: #44
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
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>
This reduced unnecessary clutter by default if we do not want to debug
uD3TN. Should also slightly increase performance by issuing less
`printf` statements.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
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>
If there is already an agent registered for the other direction of
communication, registration will fail as long as the provided secrets do
not match.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This simplifies the function signatures and enables easy extension
without adapting them in the future.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This prevents the need for passing unset fields as NULL and removes the
need to change the function signature everytime the structs are
extended.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
We specify AAP 2.0 to be an RPC protocol whereas the direction of calls
can be switched during configuration. Each call needs to be answered.
This change adds the answer for bundle reception by a client.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This is a "meta-agent" based on the current AAPv1 implementation
(`application_agent.c`), which runs the new AAP2 protocol that is
implemented via Protobuf (using NanoPB). Please refer to the
corresponding design documents for further information on the protocol
itself.
Beside the on-wire encoding and future extension capabilities, the primary
difference from AAPv1 to AAP2 is that a connection is now a
unidirectional RPC-like channel. This ensures that acknowledgments
cannot be easily get out of order and makes client implementations
simpler. However, it also means that now a shared secret needs to be
passed by clients to enable registering for the same agent ID.
The following limitations of this first implementation are present:
- Only sending and receiving ADUs is supported.
- The shared secret is not checked - any app can register for the same
agent ID as long as no other app has yet registered for the requested
direction (subscribe or non-subscribe).
- Only one client per direction is supported at the moment. (It is at
least planned to support multiplke subscribers for an agent ID.)
- The server does not expect acknowledgments from clients when they
receive ADUs.
- The keepalive mechanism is not implemented.
In general, this reflects the feature set of AAPv1, but with massive
extension opportunities.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This adds a second type of agent registration for agents that do not
receive any bundles or events. It is the first step toward splitting all
agent registrations in two parts, depending on the direction of data
flow. In the future, a shared secret will need to be provided to ensure
that an agent is authorized for a given registered agent ID.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
All supported EID schemes currently have the "agent ID" (i.e., the `dtn`
demux part or the `ipn` service number) right at the end of the EID.
Thus, we can provide a function to return a pointer to it for quickly
and efficiently working with the agent ID.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This adds the Nanopb library as submodule under `external/` and adds
corresponding build configuration to the Makefiles. Additionally, a
Protobuf stub for AAP 2.0 is included along with a `make` target to
build the corresponding C language files (`aap2-proto-headers`).
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
We want to be able to use POSIX extensions such as `strdup` and should
not define this in every individual source file. It is similar to the
definition of which C standard to use and should thus be defined in the
makefiles.
We use the X/Open feature test macro to include all needed functionality
also under other platforms such as BSD.
See also: https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
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>
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 adds trailing parts to the "local EID" specified on the command line
when required, so the user interface is more tolerant to abbreviated
representations such as 'dtn://node.dtn' and 'ipn:1'.
Closes: #129
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This is a safeguard against potential buffer/int overflows. Realistically,
we should never see such long EIDs.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
It is better to do that explicitly and the macros were reusing the macro
arguments, which may lead to side effects. We were using this in only
one place which is substituted by an explicit loop to free the list.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This removes the `DEBUG` log statements when compiling with `type=release`
for better performance.
Signed-off-by: Oleksandr Nazymko <oleksandr.nazymko@d3tn.com>
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>