Commit Graph

21 Commits

Author SHA1 Message Date
Abtin Keshavarzian eba5bdc434 [nat64] use host ID tracking for IPv4 address allocation (#11909)
This change modifies the NAT64 translator to dynamically allocate IPv4
addresses by tracking a range of host IDs within the configured CIDR.
This approach replaces the pre-allocated `mIp4AddressPool`, making it
more memory-efficient by avoiding the storage of an entire address
array.

The translator now maintains `mMinHostId` and `mMaxHostId` derived
from the configured CIDR. When allocating an IPv4 address for a new
mapping:

- If `PORT_TRANSLATION_ENABLE` is enabled, addresses are assigned
  sequentially by cycling through the host ID range. Mappings can
  share an IPv4 address as they are distinguished by translated port
  numbers.

- If `PORT_TRANSLATION_ENABLE` is disabled, a 1-to-1 address mapping
  is used. The translator cycles through host IDs to find an unused
  IPv4 address. If all addresses are allocated, it attempts to free
  expired mappings before failing.

A new test case, `TestNat64CidrAddressReuse`, is added to validate the
address allocation and reuse logic. The test ensures that all
available addresses from a CIDR are used, new requests fail when the
pool is exhausted, and addresses are correctly reused after mappings
expire. It is run against multiple CIDR sizes (`/32`, `/31`, `/30`,
and `/27`) to verify behavior across various configurations.
2025-09-12 21:05:31 -07:00
Abtin Keshavarzian 588e93cd15 [linked-list] allow use of Matches() with variable number of arguments (#11065)
This commit updates `LinkedList` and `OwningList` to enhance
`FindMatching()`, `RemoveMatching()`, and related methods to use
`Matches()` with a variable number of arguments. The implementation
uses a variadic template function and forwarding references.
2024-12-23 18:23:06 -08:00
Abtin Keshavarzian c34484d335 [linked-list] remove unused method & rename FindMatchingWithPrev() (#11057)
This commit contains the following changes to `LinkedList`:

- Removes the `FindMatching()` version that searches within a given
  sub-section of the list, as this method is no longer needed.
- Renames the method that finds a matching entry and also returns the
  `prev` entry in the list to `FindMatchingWithPrev()`. This
  distinguishes it from other `FindMatching()` overloads and
  clarifies its purpose. This method is often used when the caller
  wants to find the matching entry and later remove it from the list.
2024-12-18 15:43:32 -08:00
Abtin Keshavarzian 226f239c5d [owning-list] add RemoveAndFreeAllMatching() to OwningList class (#10210)
This commit introduces a new method, `RemoveAndFreeAllMatching()`, to
the `OwningList<Type>` class. This method removes and frees all
entries in the list that match a given indicator. This is used to
simplify the native mDNS implementation. The unit test
`test_linked_list` is also updated to validate the newly added helper
method.
2024-05-08 11:32:42 -07:00
Abtin Keshavarzian 1528c8831d [core] define core/instance folder for instance modules (#9561)
This commit moves the `instance` module to a newly added folder
`core/instance` (from `core/common`.  Header file `extension.hpp`
and its example is also moved to the same folder.
2023-10-26 05:08:24 -07:00
Abtin Keshavarzian d3608df7d4 [srp-server] process completed update from proxy from taskelt (#9398)
This commit enhances `Srp::Server` to process and commit the completed
`UpdateMetadata` entries (signaled by the "proxy service handler"
calling `HandleServiceUpdateResult()`) from a `Tasklet`. This change
is helpful in the case where the `HandleServiceUpdateResult
()` callback is invoked directly from the "update service handler"
itself. While `Srp::Server` can handle this situation, the change
makes it easier for platform implementations of advertising proxy.

In particular, it addresses an issue with the `otbr` advertising proxy
implementation. This implementation can potentially access an already
freed `Host` object. This can happen because the implementation may
hold on to the `Host` object while iterating over its `Service`
entries as advertising an earlier `Service` of the same `Host` may
fail immediately and invoke the callback directly. This would then
cause the `Host` to be freed by `Srp::Server`.
2023-09-06 11:22:49 -07:00
Jonathan Hui 9c467a23ae [clang-format] apply v14 changes (#8490) 2022-12-07 16:23:20 -08:00
Abtin Keshavarzian 686c0de5fa [linked-list] fix OwningList::RemoveAllMatching() (#7231)
This commit fixes the `OwningList::RemoveAllMatching()` to use the
`LinkedList` one. It also updates unit test `test_linked_list` to
cover this method.
2021-12-14 18:37:22 -08:00
Abtin Keshavarzian 8650e15a37 [linked-list] add RemoveAllMatching() method (#7221)
This commit adds a new method `LinkedList::RemoveAllMatching()` which
removes all entries in the list matching a given entry indicator from
the list and adds them to a new "removed" list. A similar method is
also added in `OwningList`. This commit also updates the unit test
`test_linked_list` to validate the behavior of the new method.
2021-12-07 14:43:01 -08:00
Abtin Keshavarzian db9e430876 [common] adding OwningList (a linked list which owns its entries) (#7181)
This commit adds `OwningList<Type>`, a singly linked list which owns
its entries and frees them upon destruction of the list. This commit
also updates `test_linked_list` to validate the behavior of the new
class.
2021-11-22 21:41:56 -08:00
Abtin Keshavarzian 6895edda59 [linked-list] range-based for loop iteration over all entries (#6945)
This commit enables use of range-based `for` loop for iterating over
all the entries in a `LinkedList`. It adds private implementations of
`Iterator` and `ConstIterator` which inherit from `ItemPtrIterator`
and use the `GetNext()` to go to the next entry. The range-based
`for` loop practically acts as a syntactic sugar helping simplify the
code and does not add any code size (or any expected run-time)
overhead.
2021-08-23 14:50:14 -07:00
Abtin Keshavarzian 57d072d352 [test] enhance {Verify/Success}OrQuit() and their use in unit test (#6764)
This commit updates `VerifyOrQuit()` and `SuccessOrQuit()` macros to
include the failed condition in the error message that is printed on
a failure (in addition to function name and line number where the
error happened). This commit also changes the second parameter
(`aMessage`) to in these macros to be optional.

This commit also updates unit tests to remove the second `aMessage`
string in cases where the failure can be inferred from the condition
itself.
2021-06-28 11:38:10 -07:00
Abtin Keshavarzian 7dca56e982 [error] add 'ot::Error' and 'kError{Name}' for use by core modules (#6237)
This commit adds a new core header files `common/error.hpp` which
defines `ot::Error` (mirroring `otError`) and `kError{Name}` constants
(mirroring the public `OT_ERROR_{NAME}` definitions). The new (C++
style) definitions are used by core modules. This commit also moves
`otThreadErrorToString()` (from `logging.hpp` to `error.hpp`) and
renames it to `ErrorToString()` which is used as the internal (to
core) function to covert an `Error` to a string.
2021-03-15 21:07:07 -07:00
Abtin Keshavarzian 5ebd885996 [linked-list] add new template {Contains/Find/Remove}Matching() methods (#5174)
This commit adds new methods in `LinkedList` to search in the list for
an entry matching a given entry indicator (specified with a template
`Indicator` type). To use these methods, users are expected to provide
method `bool Matches(const Indicator &aIndicator) const` on the entry
`Type` itself (which is then used to match each entry in the list with
the indicator). This commit also changes the linked-list methods to
use `Find()` internally. Finally it updates the linked-list unit test
to cover behavior of the newly added methods.
2020-07-01 16:51:10 -07:00
Abtin Keshavarzian 0ae329c21d [linked-list] fix Find() when list is empty (#5164)
This commit fixes the `LinkedList::Find()` implementation when list is
empty. It also updates the unit test for linked-list to verify the
`Find()` (particularly when it is expected to fail and not find the
entry in the list).
2020-06-30 08:43:31 -07:00
Jonathan Hui 1326d64a64 [style] replace NULL with nullptr (#5109) 2020-06-17 22:44:54 -07:00
Abtin Keshavarzian 8a5f538e6f [linked-list] change PopAfter() parameter to be a pointer (#4599)
This commit changes `LinkedList::PopAfter()` method to accept a
pointer to a previous entry as a parameter. If the previous entry
pointer is NULL the entry at the head of the list is popped.
2020-03-31 12:11:24 -07:00
Jonathan Hui 28dd4475b7 [unit-test] fix 'va_start" undefiend behavior in test_linked_list.cpp (#4533)
Fixes passing an object of reference type to 'va_start' has undefined
behavior.
2020-02-07 22:51:48 -08:00
Abtin Keshavarzian 802c9dfcbc [linked-list] add Find() and GetTail() methods (#4388)
The `LinkedList::Find()` method searches for a given entry in the
linked list and if found returns a pointer to the previous entry
behind it. The `LinkedList::GetTail()` returns the tail of the list
(last entry in the list). This commit also updates the unit test
`test_linked_list` to verify the behavior of newly added methods.
2019-12-12 08:56:08 -08:00
Abtin Keshavarzian f10c6c36fd [unit-test] remove (unnecessary) ENABLE_TEST_MAIN definition (#4367) 2019-12-11 09:16:48 -08:00
Abtin Keshavarzian e17c82b0b9 [linked-list] adding LinkedList class (#4357)
This commit adds a linked list module which provides a template
implementation of a singly linked list. The new class is then used in
different core modules (netif (unicast/multicast addresses), UDP6
sockets/receiver, coap resources, etc). This commit also adds a
unit test `test_linked_list` for the linked list module.
2019-12-04 11:03:52 -08:00