Skip to content

Commit

Permalink
[srp-client] exclude non-preferred addresses in AutoAddress mode (#…
Browse files Browse the repository at this point in the history
…9642)

This commit updates the `AutoAddress` mode in `Srp::Client` to
exclude any deprecated (non-preferred) address when registering
host addresses.

It also updates `test_srp_auto_host_address` to validate the new
behavior.
  • Loading branch information
abtink authored Nov 29, 2023
1 parent 63424e2 commit 85660ce
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 22 deletions.
2 changes: 1 addition & 1 deletion include/openthread/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (378)
#define OPENTHREAD_API_VERSION (379)

/**
* @addtogroup api-instance
Expand Down
8 changes: 4 additions & 4 deletions include/openthread/srp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ otError otSrpClientSetHostName(otInstance *aInstance, const char *aName);
/**
* 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).
* When enabled host IPv6 addresses are automatically set by SRP client using all the preferred unicast addresses on
* Thread netif excluding all link-local and mesh-local addresses. If there is no preferred 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 or marked as non-preferred).
*
* 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
Expand Down
2 changes: 1 addition & 1 deletion src/cli/README_SRP_CLIENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fd00:0:0:0:0:0:0:beef
Done
```

Enable auto host address mode. When enabled client will automatically use all Thread netif unicast addresses excluding all link-local and mesh-local addresses. If there is no valid address, then Mesh Local EID address is added. SRP client will automatically re-register if/when addresses on Thread netif get changed (e.g., new address is added or existing address is removed).
Enable auto host address mode. When enabled client will automatically use all preferred Thread netif unicast addresses excluding all link-local and mesh-local addresses. If there is no preferred address, then Mesh Local EID address is added. SRP client will automatically re-register if/when addresses on Thread netif get changed (e.g., new address is added or existing address is removed or marked as non-preferred).

```bash
> srp client host address auto
Expand Down
6 changes: 3 additions & 3 deletions src/cli/cli_srp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,12 @@ template <> otError SrpClient::Process<Cmd("host")>(Arg aArgs[])
* @endcode
* @cparam srp client host address [auto|@ca{address...}]
* * Use the `auto` parameter to enable auto host address mode.
* When enabled, the client automatically uses all Thread `netif`
* unicast addresses except for link-local and mesh-local
* When enabled, the client automatically uses all preferred Thread
* `netif` unicast addresses except for link-local and mesh-local
* addresses. If there is no valid address, the mesh local
* EID address gets added. The SRP client automatically
* re-registers if addresses on the Thread `netif` are
* added or removed.
* added or removed or marked as non-preferred.
* * Explicitly specify the list of host addresses, separating
* each address by a space. You can set this list while the client is
* running. This will also disable auto host address mode.
Expand Down
14 changes: 8 additions & 6 deletions src/core/net/srp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1240,21 +1240,23 @@ Error Client::AppendHostDescriptionInstruction(Message &aMessage, Info &aInfo)

if (mHostInfo.IsAutoAddressEnabled())
{
// Append all addresses on Thread netif excluding link-local and
// mesh-local addresses. If no address is appended, we include
// the mesh local address.
// Append all preferred addresses on Thread netif excluding link-local
// and mesh-local addresses. If no address is appended, we include
// the mesh local EID.

mAutoHostAddressAddedMeshLocal = true;

for (const Ip6::Netif::UnicastAddress &unicastAddress : Get<ThreadNetif>().GetUnicastAddresses())
{
if (unicastAddress.GetAddress().IsLinkLocal() ||
Get<Mle::Mle>().IsMeshLocalAddress(unicastAddress.GetAddress()))
const Ip6::Address &address = unicastAddress.GetAddress();

if (address.IsLinkLocal() || Get<Mle::Mle>().IsMeshLocalAddress(address) || !unicastAddress.mPreferred ||
!unicastAddress.mValid)
{
continue;
}

SuccessOrExit(error = AppendAaaaRecord(unicastAddress.GetAddress(), aMessage, aInfo));
SuccessOrExit(error = AppendAaaaRecord(address, aMessage, aInfo));
mAutoHostAddressAddedMeshLocal = false;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/scripts/thread-cert/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1880,8 +1880,8 @@ def del_ipmaddr(self, ipmaddr):
self.send_command(cmd)
self._expect_done()

def get_addrs(self):
self.send_command('ipaddr')
def get_addrs(self, verbose=False):
self.send_command('ipaddr' + (' -v' if verbose else ''))

return self._expect_results(r'\S+(:\S*)+')

Expand Down
25 changes: 20 additions & 5 deletions tests/scripts/thread-cert/test_srp_auto_host_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,19 @@ def test(self):
self.assertEqual(len(slaac_addr), 1)
self.check_registered_addresses(client, server)

#-------------------------------------------------------------------
# Add a non-preferred SLAAC on-mesh prefix and check that the
# set of registered addresses remains unchanged and that the
# non-preferred address is not registered by SRP client.

client.add_prefix('fd00:a:b:c::/64', 'aos')
client.register_netdata()
self.simulator.go(5)

slaac_addr = [addr.strip() for addr in client.get_addrs() if addr.strip().startswith('fd00:a:b:c:')]
self.assertEqual(len(slaac_addr), 1)
self.check_registered_addresses(client, server)

#-------------------------------------------------------------------
# Remove the on-mesh prefix (which will trigger an address to be
# removed) and check that the SRP client re-registered and updated
Expand Down Expand Up @@ -219,19 +232,21 @@ def check_registered_addresses(self, client, server):
# Check the host addresses on server to match client.

host_addresses = [addr.strip() for addr in server_host['addresses']]
client_addresses = [addr.strip() for addr in client.get_addrs()]

client_mleid = client.get_mleid()
client_addresses = [addr.split(' ')[0] for addr in client.get_addrs(verbose=True) if 'preferred:1' in addr]
client_addresses += [client_mleid]

# All registered addresses must be in client list of addresses.

for addr in host_addresses:
self.assertIn(addr, client_addresses)

# All addresses on client excluding link-local and mesh-local
# addresses must be seen on server side. But if there was
# no address, then mesh-local address should be the only
# All preferred addresses on client excluding link-local and
# mesh-local addresses must be seen on server side. But if there
# was no address, then mesh-local address should be the only
# one registered.

client_mleid = client.get_mleid()
checked_address = False

for addr in client_addresses:
Expand Down

0 comments on commit 85660ce

Please sign in to comment.