mirror of
https://github.com/espressif/openthread.git
synced 2026-09-12 04:00:10 +00:00
[nat64] fetch NAT64 prefix from infrastructure interface and advertise it to netdata (#7619)
This commit fetches the NAT64 prefix on infrastructure interface and advertise it to Network Data at medium preference. - Use `getaddrinfo_a()` function to asynchronously lookup the ipv6 address of the special domain `ipv4only.arpa`. The infrastructure NAT64 prefix is extracted from the domain answer. - `mInfraIfNat64PrefixStaleTimer` is scheduled to monitor the presence and change of infrastructure NAT64 prefix. - `EvaluateNat64Prefix` evaluates whether to advertise the infrastructure prefix or the local ULA prefix or neither. When there is a new infrastructure prefix, it will withdraw the legacy one and add the new one. When the infrastructure prefix no longer exists, it will withdraw the legacy one and add the local ULA prefix. When the infrastructure prefix presents again, it will add the infrastructure prefix and withdraw the local ULA prefix. New tests are added to test the scenarios when infrastructure NAT64 prefix exists. `DNS64` on OTBR is turned on to enable `bind9` with NAT64 prefix on infrastructure interface for these tests. `bind9` is explicitly turned off when testing local ULA prefix. Since bind9 is conflict with other components like dnssd, all nat64 tests are moved under /nat64 directory and configured separately. The case that two or more BRs have same infrastructure NAT64 prefix is not covered by this commit and will be followed up later.
This commit is contained in:
@@ -227,6 +227,23 @@ otError otBorderRoutingGetOnLinkPrefix(otInstance *aInstance, otIp6Prefix *aPref
|
||||
*/
|
||||
otError otBorderRoutingGetNat64Prefix(otInstance *aInstance, otIp6Prefix *aPrefix);
|
||||
|
||||
/**
|
||||
* Gets the currently favored NAT64 prefix.
|
||||
*
|
||||
* The favored NAT64 prefix can be discovered from infrastructure link or can be this device's local NAT64 prefix.
|
||||
*
|
||||
* @param[in] aInstance A pointer to an OpenThread instance.
|
||||
* @param[out] aPrefix A pointer to output the favored NAT64 prefix.
|
||||
* @param[out] aPreference A pointer to output the preference associated the favored prefix.
|
||||
*
|
||||
* @retval OT_ERROR_INVALID_STATE The Border Routing Manager is not initialized yet.
|
||||
* @retval OT_ERROR_NONE Successfully retrieved the favored NAT64 prefix.
|
||||
*
|
||||
*/
|
||||
otError otBorderRoutingGetFavoredNat64Prefix(otInstance * aInstance,
|
||||
otIp6Prefix * aPrefix,
|
||||
otRoutePreference *aPreference);
|
||||
|
||||
/**
|
||||
* This function initializes an `otBorderRoutingPrefixTableIterator`.
|
||||
*
|
||||
|
||||
@@ -53,7 +53,7 @@ extern "C" {
|
||||
* @note This number versions both OpenThread platform and user APIs.
|
||||
*
|
||||
*/
|
||||
#define OPENTHREAD_API_VERSION (233)
|
||||
#define OPENTHREAD_API_VERSION (234)
|
||||
|
||||
/**
|
||||
* @addtogroup api-instance
|
||||
|
||||
@@ -679,6 +679,16 @@ void otIp6PrefixToString(const otIp6Prefix *aPrefix, char *aBuffer, uint16_t aSi
|
||||
*/
|
||||
uint8_t otIp6PrefixMatch(const otIp6Address *aFirst, const otIp6Address *aSecond);
|
||||
|
||||
/**
|
||||
* This method gets a prefix with @p aLength from @p aAddress.
|
||||
*
|
||||
* @param[in] aAddress A pointer to an IPv6 address.
|
||||
* @param[in] aLength The length of prefix in bits.
|
||||
* @param[out] aPrefix A pointer to output the IPv6 prefix.
|
||||
*
|
||||
*/
|
||||
void otIp6GetPrefix(const otIp6Address *aAddress, uint8_t aLength, otIp6Prefix *aPrefix);
|
||||
|
||||
/**
|
||||
* This function indicates whether or not a given IPv6 address is the Unspecified Address.
|
||||
*
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#ifndef OPENTHREAD_NAT64_H_
|
||||
#define OPENTHREAD_NAT64_H_
|
||||
|
||||
#include <openthread/ip6.h>
|
||||
#include <openthread/message.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -87,6 +88,32 @@ typedef struct otIp4Cidr
|
||||
uint8_t mLength;
|
||||
} otIp4Cidr;
|
||||
|
||||
/**
|
||||
* Test if two IPv4 addresses are the same.
|
||||
*
|
||||
* @param[in] aFirst A pointer to the first IPv4 address to compare.
|
||||
* @param[in] aSecond A pointer to the second IPv4 address to compare.
|
||||
*
|
||||
* @retval TRUE The two IPv4 addresses are the same.
|
||||
* @retval FALSE The two IPv4 addresses are not the same.
|
||||
*
|
||||
*/
|
||||
bool otIp4IsAddressEqual(const otIp4Address *aFirst, const otIp4Address *aSecond);
|
||||
|
||||
/**
|
||||
* Set @p aIp4Address by performing NAT64 address translation from @p aIp6Address as specified
|
||||
* in RFC 6052.
|
||||
*
|
||||
* The NAT64 @p aPrefixLength MUST be one of the following values: 32, 40, 48, 56, 64, or 96, otherwise the behavior
|
||||
* of this method is undefined.
|
||||
*
|
||||
* @param[in] aPrefixLength The prefix length to use for IPv4/IPv6 translation.
|
||||
* @param[in] aIp6Address A pointer to an IPv6 address.
|
||||
* @param[out] aIp4Address A pointer to output the IPv4 address.
|
||||
*
|
||||
*/
|
||||
void otIp4ExtractFromIp6Address(uint8_t aPrefixLength, const otIp6Address *aIp6Address, otIp4Address *aIp4Address);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
||||
@@ -133,6 +133,35 @@ extern void otPlatInfraIfRecvIcmp6Nd(otInstance * aInstance,
|
||||
*/
|
||||
extern otError otPlatInfraIfStateChanged(otInstance *aInstance, uint32_t aInfraIfIndex, bool aIsRunning);
|
||||
|
||||
/**
|
||||
* Send a request to discover the NAT64 prefix on the infrastructure interface with @p aInfraIfIndex.
|
||||
*
|
||||
* OpenThread will call this method periodically to monitor the presence or change of NAT64 prefix.
|
||||
*
|
||||
* @param[in] aInfraIfIndex The index of the infrastructure interface to discover the NAT64 prefix.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully request NAT64 prefix discovery.
|
||||
* @retval OT_ERROR_FAILED Failed to request NAT64 prefix discovery.
|
||||
*
|
||||
*/
|
||||
otError otPlatInfraIfDiscoverNat64Prefix(uint32_t aInfraIfIndex);
|
||||
|
||||
/**
|
||||
* The infra interface driver calls this method to notify OpenThread that
|
||||
* the discovery of NAT64 prefix is done.
|
||||
*
|
||||
* This method is expected to be invoked after calling otPlatInfraIfDiscoverNat64Prefix.
|
||||
* If no NAT64 prefix is discovered, @p aIp6Prefix shall point to an empty prefix with zero length.
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
* @param[in] aInfraIfIndex The index of the infrastructure interface on which the NAT64 prefix is discovered.
|
||||
* @param[in] aIp6Prefix A pointer to NAT64 prefix.
|
||||
*
|
||||
*/
|
||||
extern void otPlatInfraIfDiscoverNat64PrefixDone(otInstance * aInstance,
|
||||
uint32_t aInfraIfIndex,
|
||||
const otIp6Prefix *aIp6Prefix);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user