[posix] add unified platform API for setting NAT64 CIDR during runtime (#8947)

We should notice that the default CIDR (`192.168.255.0/24`) is not
safe to use, however, in most cases, the CIDR used can only be
determined during runtime since the single binary might be distributed
to BRs in different network conditions. And we cannot conclude an
always safe CIDR in all conditions.

This commit will emit an event when NAT64 CIDR is changed. So the
platform driver can update the route for NAT64.
This commit is contained in:
Song GUO
2023-05-30 23:16:43 -07:00
committed by GitHub
parent fa81b21f4c
commit 9c7e679ed1
8 changed files with 145 additions and 52 deletions
+13
View File
@@ -413,6 +413,19 @@ class OtbrDocker:
def nat64_set_enabled(self, enable):
return self.call_dbus_method('io.openthread.BorderRouter', 'SetNat64Enabled', enable)
@property
def nat64_cidr(self):
self.send_command('nat64 cidr')
cidr = self._expect_command_output()[0].strip()
return ipaddress.IPv4Network(cidr, strict=False)
@nat64_cidr.setter
def nat64_cidr(self, cidr: ipaddress.IPv4Network):
if not isinstance(cidr, ipaddress.IPv4Network):
raise ValueError("cidr is expected to be an instance of ipaddress.IPv4Network")
self.send_command(f'nat64 cidr {cidr}')
self._expect_done()
@property
def nat64_state(self):
state = self.get_dbus_property('Nat64State')