Previously it was not possible to disable SQLite because of a linker
error. Also, `sqlite3.h` was always required to be present. This adds
an example to `config.mk.example` and fixes both issues.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This adds a `bundle_is_valid` function checking for further MUST
constraints defined by the spec., which further processing inside uD3TN
may depend on.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This blocks the use of the persistent storage with our BDM: If we
restart µD3TN and the BDM after a bundle has been stored, then
reconfigure the contacts, and afterwards recall the stored bundles via
`aap2-storage-agent`, the BDM will try to store the bundles again after
they have been (re)scheduled and the storage CLA will report a
"transmission failure". See #210 why we should rather indicate success
here.
This checks the return value of `sqlite3_step` and, if it is
`SQLITE_CONSTRAINT`, returns success ("done") in the `cla_begin_packet`
handler. This way, the BDM received the proper notification that
everything is fine and continues sending the bundle after the contact
has started.
Closes: #210
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This improves const correctness, at least for pointers (making the
pointed-to data const where possible).
Some suppressions are added for false positive warnings, such as in
`simple_queue.c` where an arithmethic operation is used on the pointer
to calculate a non-const pointer that is returned (thus, the passed
pointer should also not point to const).
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Three messages that are printed quite often but are barely relevant,
either because there is another INFO-level message about the same thing
and they only confirm processing or because the behavior can be expected
anyway, are downgraded to DEBUG level, so they are not shown by default
and disabled in release builds.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The MTCP CLA drops a link parameter data structure from its hash table
in case it intends to create a new link and there is an existing one in
the process of being torn down (while the associated task is cleaning up
resources). In this case it might happen that the entry is removed by
`mtcp_start_scheduled_contact`, a new entry is created by
`launch_connection_management_task`, and this new entry is removed again
by the termination code in `mtcp_link_management_task`, "leaking" the
link management task and making it uncontrolled.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This fixes another potential deadlock: The BP calls the "start contact"
function of a CLA, which in turn discovers that the link is already
active and attempts to put a notification of link establishment into the
BP queue, which may be full and is not consumed as this is running in
the BP thread.
The solution here adds an extended return value for the start and end
contact functions in the CLA interface, enabling them to indicate to the
BP whether a link change has been initiated (and will be performed
asynchronously), is not necessary (the state is already the intended
one), or was performed synchronously.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This moves the information about a disconnected CLA link from the
`cla_end_scheduled_contact` implementation (in MTCP) to the generic
`cla_link_cleanup` routine that is typically executed in a dedicated
link management thread.
This prevents the call to `cla_end_scheduled_contact` from putting
something in the BP queue which may be blocked by the BP being busy
calling `cla_end_scheduled_contact`.
Fixes: #205
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The FIB fulfils two purposes: 1) map node IDs to next-hop CLA addresses
and 2) store the current status of a link associated with a given CLA
address.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Allowing both "cla:" and "cla" may lead to issues for single-connection
CLAs (those that do not use CLA-specific addresses): the FIB may contain
entries for both and only one may be marked as "up" if both forms are
used interchangeably.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
We now treat this value specifically and it is easier to handle in AAPv2
as Protobuf will not transmit fields that have been assigned their
default value (0 in this case).
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
We should be able to honor the fragmentation threshold again. This
passes the maximum bundle size variable to the AAPv2 agent. The value is
determined as the minimum of all maximum bundle sizes reported by the
CLAs and the one specified on the command line, with the special case
of the value 0, which means a maximum bundle size of 2^64 ("unlimited").
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
It is not necessary anymore to secure our configuration. Loops in DTNs
should be allowed and only be controlled through the bundle lifetime.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Adds support for a volatile in-memory database by enabling support for
URI-based database file names. Since the in-memory DB can only be
accessed within the process, the integration tests are changed so that
external SQL queries are only performed when a persistent DB file is
used.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
When transmission had been attempted and generated a "TX
success/failure" result, the BDM will need the information which
transmission is affected by the generated dispatch. Additionally, the
term "DispatchRequest" is imprecise, as uD3TN does not require the BDM
to dispatch the bundle in any case (it can do so, but especially after
TX success/failure, oftentimes, it is intended to just proceed with
normal bundle processing).
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This adds a "flags" field to the FIB link, allowing for configuring a
link for "direct dispatch", i.e., to make it usable without first
contacting a BDM. It is important to make this optional as otherwise
contact-based routing and QoS could not be implemented properly via a
BDM.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
If the write method of the CLA fails, the serailizers will now return
early and this failure is handled properly by the TX task.
In the case of the BPv6 serializer, we add the necessary flow control to
the `write_bytes` macro, to prevent needing a conditional for every
write* or serialize* statement.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
Conditions such as no FIB handler being present are totally normal in
most cases and do not need to be reported as warnings.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This means that either the socket was marked nonblocking, in which case
we would do busy waiting, or a set receive timeout was exceeded, in
which case we also want to return the error.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
The BIBE CLA address contains the lower-layer destination EID.
Previously we were reporting link changes for the `cla_sock_addr`,
leading to inconsistent FIB entries.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
We were calling it though a function pointer with a void* as first
argument, despite we pass a struct cla_link*. This is UB, correctly
reported by the sanitizer, though only reported in the case of the new
storage CLA.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This is required to allow bundles being forwarded to storage by
specifying the storage node (a configuration parameter) as next hop.
The CLA initialization is modified slightly to register the CLA before
executing `cla_launch` to ensure that the bundle processor knows about
it when it is executed.
This also moves the Sqlite CLA initialization to the `sqlite_launch`
function because the CLA has to be known ("registered") before we send
a signal to the BP (which is done during link creation).
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This adds functionality to dispatch bundles and control the FIB to AAP
2.0 and the bundle processor, replacing the old "router" completely.
AAP 2.0 is extended slightly to enable fragmentation.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
- Implement management of FIB and BDM agents:
* add administrative secret which is required for registering FIB and
BDM agents
* allow registering reverse-direction agents for TX/RX of ADUs when
passing the admin secret
* add cmdline option to pass the admin secret via an env variable
* make administrative secret optional in debug builds
- Register agents by number, as FIB and BDM agents may not have a sink
ID. Numbers are allocated by the agent_register function.
- Remove global state, add function to de-allocate everything.
- Add comprehensive unit tests.
Signed-off-by: Felix Walter <felix.walter@d3tn.com>
- Use only one goto-label
- Remove the bundle_processor_inform() call, as this is already done in
cla_link_init()
- Move the sqlite_link_init() call to the end of the function to perform
the registration of the CLA as the last step
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
Depending on the selected bundle_filter, bundles can now be looped back
using either a metadata filter or a unique CompoundBundleId.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
- Introduces a CompoundBundleId to filter exactly one bundle
- Filter bundles either by their ID or selected metadata
- Transfer the entire StorageCall object to the CLA via the agent queue
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
To eliminate potential race conditions where rows are deleted before the
CLA processes them, the select statement is moved from the agent to the
CLA and everything is wrapped in a transaction to read all or nothing.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
To prevent race conditions between the different threads, each thread
uses its own database connections and all statements are wrapped in
transactions to ensure that they are either executed completely or not
at all.
Signed-off-by: Maximilian Nitsch <maximilian.nitsch@d3tn.com>
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>
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>