[srp-client] add auto host address mode (#7655)

This commit adds a "auto host address mode" in SRP client. When
enabled, host IPv6 addresses are automatically set by SRP client
using all the unicast addresses on Thread netif excluding the
link-local and mesh-local addresses. If there is no valid address,
then Mesh Local EID address is added. The SRP client will
automatically re-register when/if addresses on Thread netif are
updated (e.g., new addresses are added or existing addresses are
removed).

This commit updates CLI to add support for new SRP client APIs related
to the new feature. It also adds `test_srp_auto_host_address` test to
cover the behavior of this feature.
This commit is contained in:
Abtin Keshavarzian
2022-06-02 15:32:08 -07:00
committed by GitHub
parent e83ecab395
commit 24d633d99d
11 changed files with 500 additions and 35 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (217)
#define OPENTHREAD_API_VERSION (218)
/**
* @addtogroup api-instance
+26 -1
View File
@@ -75,8 +75,9 @@ typedef enum
typedef struct otSrpClientHostInfo
{
const char * mName; ///< Host name (label) string (NULL if not yet set).
const otIp6Address * mAddresses; ///< Pointer to an array of host IPv6 addresses (NULL if not yet set).
const otIp6Address * mAddresses; ///< Array of host IPv6 addresses (NULL if not set or auto address is enabled).
uint8_t mNumAddresses; ///< Number of IPv6 addresses in `mAddresses` array.
bool mAutoAddress; ///< Indicates whether auto address mode is enabled or not.
otSrpClientItemState mState; ///< Host info state.
} otSrpClientHostInfo;
@@ -428,6 +429,27 @@ const otSrpClientHostInfo *otSrpClientGetHostInfo(otInstance *aInstance);
*/
otError otSrpClientSetHostName(otInstance *aInstance, const char *aName);
/**
* This function enables auto host address mode.
*
* When enabled host IPv6 addresses are automatically set by SRP client using all the unicast addresses on Thread netif
* excluding all link-local and mesh-local addresses. If there is no valid address, then Mesh Local EID address is
* added. The SRP client will automatically re-register when/if addresses on Thread netif are updated (new addresses
* are added or existing addresses are removed).
*
* The auto host address mode can be enabled before start or during operation of SRP client except when the host info
* is being removed (client is busy handling a remove request from an call to `otSrpClientRemoveHostAndServices()` and
* host info still being in either `STATE_TO_REMOVE` or `STATE_REMOVING` states).
*
* After auto host address mode is enabled, it can be disabled by a call to `otSrpClientSetHostAddresses()` which
* then explicitly sets the host addresses.
*
* @retval OT_ERROR_NONE Successfully enabled auto host address mode.
* @retval OT_ERROR_INVALID_STATE Host is being removed and therefore cannot enable auto host address mode.
*
*/
otError otSrpClientEnableAutoHostAddress(otInstance *aInstance);
/**
* This function sets/updates the list of host IPv6 address.
*
@@ -442,6 +464,9 @@ otError otSrpClientSetHostName(otInstance *aInstance, const char *aName);
* After a successful call to this function, `otSrpClientCallback` will be called to report the status of the address
* registration with SRP server.
*
* Calling this function disables auto host address mode if it was previously enabled from a successful call to
* `otSrpClientEnableAutoHostAddress()`.
*
* @param[in] aInstance A pointer to the OpenThread instance.
* @param[in] aIp6Addresses A pointer to the an array containing the host IPv6 addresses.
* @param[in] aNumAddresses The number of addresses in the @p aIp6Addresses array.