Skip to content

Commit be879f1

Browse files
authored
[nat64] remove support for ipv4only.arpa (openthread#11481)
Thread Specification is transitioning from RFC 7050 to RFC 8781 for discovering the NAT64 prefix. This commit removes RFC 7050 behavior.
1 parent ec2b0d4 commit be879f1

5 files changed

Lines changed: 12 additions & 232 deletions

File tree

src/posix/platform/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,9 @@ target_link_libraries(openthread-posix
174174
ot-posix-config
175175
$<$<NOT:$<BOOL:${OT_ANDROID_NDK}>>:util>
176176
$<$<STREQUAL:${CMAKE_SYSTEM_NAME},Linux>:rt>
177+
$<$<STREQUAL:${CMAKE_SYSTEM_NAME},Linux>:anl>
177178
)
178179

179-
option(OT_TARGET_OPENWRT "enable openthread posix for OpenWRT" OFF)
180-
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND NOT OT_TARGET_OPENWRT)
181-
target_compile_definitions(ot-posix-config
182-
INTERFACE "OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE=1"
183-
)
184-
target_link_libraries(openthread-posix PRIVATE anl)
185-
endif()
186-
187180
target_compile_definitions(openthread-posix
188181
PUBLIC
189182
${OT_PUBLIC_DEFINES}

src/posix/platform/infra_if.cpp

Lines changed: 3 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ otError otPlatInfraIfSendIcmp6Nd(uint32_t aInfraIfIndex,
102102
}
103103
#endif
104104

105-
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE && OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
105+
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE
106106
otError otPlatInfraIfDiscoverNat64Prefix(uint32_t aInfraIfIndex)
107107
{
108-
return ot::Posix::InfraNetif::Get().DiscoverNat64Prefix(aInfraIfIndex);
108+
OT_UNUSED_VARIABLE(aInfraIfIndex);
109+
return OT_ERROR_NOT_IMPLEMENTED;
109110
}
110111
#endif
111112

@@ -664,145 +665,6 @@ void InfraNetif::ReceiveIcmp6Message(void)
664665
}
665666
#endif // OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
666667

667-
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE && OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
668-
const char InfraNetif::kWellKnownIpv4OnlyName[] = "ipv4only.arpa";
669-
const otIp4Address InfraNetif::kWellKnownIpv4OnlyAddress1 = {{{192, 0, 0, 170}}};
670-
const otIp4Address InfraNetif::kWellKnownIpv4OnlyAddress2 = {{{192, 0, 0, 171}}};
671-
const uint8_t InfraNetif::kValidNat64PrefixLength[] = {96, 64, 56, 48, 40, 32};
672-
673-
#ifdef __linux__
674-
void InfraNetif::DiscoverNat64PrefixDone(union sigval sv)
675-
{
676-
struct gaicb *req = (struct gaicb *)sv.sival_ptr;
677-
struct addrinfo *res = (struct addrinfo *)req->ar_result;
678-
679-
otIp6Prefix prefix = {};
680-
681-
VerifyOrExit((char *)req->ar_name == kWellKnownIpv4OnlyName);
682-
683-
LogInfo("Handling host address response for %s", kWellKnownIpv4OnlyName);
684-
685-
// We extract the first valid NAT64 prefix from the address look-up response.
686-
for (struct addrinfo *rp = res; rp != NULL && prefix.mLength == 0; rp = rp->ai_next)
687-
{
688-
struct sockaddr_in6 *ip6Addr;
689-
otIp6Address ip6Address;
690-
691-
if (rp->ai_family != AF_INET6)
692-
{
693-
continue;
694-
}
695-
696-
ip6Addr = reinterpret_cast<sockaddr_in6 *>(rp->ai_addr);
697-
memcpy(&ip6Address.mFields.m8, &ip6Addr->sin6_addr.s6_addr, OT_IP6_ADDRESS_SIZE);
698-
for (uint8_t length : kValidNat64PrefixLength)
699-
{
700-
otIp4Address ip4Address;
701-
702-
otIp4ExtractFromIp6Address(length, &ip6Address, &ip4Address);
703-
if (otIp4IsAddressEqual(&ip4Address, &kWellKnownIpv4OnlyAddress1) ||
704-
otIp4IsAddressEqual(&ip4Address, &kWellKnownIpv4OnlyAddress2))
705-
{
706-
// We check that the well-known IPv4 address is present only once in the IPv6 address.
707-
// In case another instance of the value is found for another prefix length, we ignore this address
708-
// and search for the other well-known IPv4 address (per RFC 7050 section 3).
709-
bool foundDuplicate = false;
710-
711-
for (uint8_t dupLength : kValidNat64PrefixLength)
712-
{
713-
otIp4Address dupIp4Address;
714-
715-
if (dupLength == length)
716-
{
717-
continue;
718-
}
719-
720-
otIp4ExtractFromIp6Address(dupLength, &ip6Address, &dupIp4Address);
721-
if (otIp4IsAddressEqual(&dupIp4Address, &ip4Address))
722-
{
723-
foundDuplicate = true;
724-
break;
725-
}
726-
}
727-
728-
if (!foundDuplicate)
729-
{
730-
otIp6GetPrefix(&ip6Address, length, &prefix);
731-
break;
732-
}
733-
}
734-
735-
if (prefix.mLength != 0)
736-
{
737-
break;
738-
}
739-
}
740-
}
741-
742-
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
743-
otPlatInfraIfDiscoverNat64PrefixDone(gInstance, Get().mInfraIfIndex, &prefix);
744-
#endif
745-
746-
exit:
747-
freeaddrinfo(res);
748-
freeaddrinfo((struct addrinfo *)req->ar_request);
749-
free(req);
750-
}
751-
#endif // #ifdef __linux__
752-
753-
otError InfraNetif::DiscoverNat64Prefix(uint32_t aInfraIfIndex)
754-
{
755-
#ifdef __linux__
756-
otError error = OT_ERROR_NONE;
757-
struct addrinfo *hints = nullptr;
758-
struct gaicb *reqs[1] = {nullptr};
759-
struct sigevent sig;
760-
int status;
761-
762-
VerifyOrExit(aInfraIfIndex == mInfraIfIndex, error = OT_ERROR_DROP);
763-
hints = (struct addrinfo *)malloc(sizeof(struct addrinfo));
764-
VerifyOrExit(hints != nullptr, error = OT_ERROR_NO_BUFS);
765-
memset(hints, 0, sizeof(struct addrinfo));
766-
hints->ai_family = AF_INET6;
767-
hints->ai_socktype = SOCK_STREAM;
768-
769-
reqs[0] = (struct gaicb *)malloc(sizeof(struct gaicb));
770-
VerifyOrExit(reqs[0] != nullptr, error = OT_ERROR_NO_BUFS);
771-
memset(reqs[0], 0, sizeof(struct gaicb));
772-
reqs[0]->ar_name = kWellKnownIpv4OnlyName;
773-
reqs[0]->ar_request = hints;
774-
775-
memset(&sig, 0, sizeof(struct sigevent));
776-
sig.sigev_notify = SIGEV_THREAD;
777-
sig.sigev_value.sival_ptr = reqs[0];
778-
sig.sigev_notify_function = &InfraNetif::DiscoverNat64PrefixDone;
779-
780-
status = getaddrinfo_a(GAI_NOWAIT, reqs, 1, &sig);
781-
782-
if (status != 0)
783-
{
784-
LogNote("getaddrinfo_a failed: %s", gai_strerror(status));
785-
ExitNow(error = OT_ERROR_FAILED);
786-
}
787-
LogInfo("getaddrinfo_a requested for %s", kWellKnownIpv4OnlyName);
788-
exit:
789-
if (error != OT_ERROR_NONE)
790-
{
791-
if (hints)
792-
{
793-
freeaddrinfo(hints);
794-
}
795-
free(reqs[0]);
796-
}
797-
return error;
798-
#else
799-
OT_UNUSED_VARIABLE(aInfraIfIndex);
800-
801-
return OT_ERROR_NOT_IMPLEMENTED;
802-
#endif // #ifdef __linux__
803-
}
804-
#endif // OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE && OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
805-
806668
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
807669
void InfraNetif::SetInfraNetifIcmp6SocketForBorderRouting(int aIcmp6Socket)
808670
{

src/posix/platform/infra_if.hpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -161,19 +161,6 @@ class InfraNetif : public Mainloop::Source, public Logger<InfraNetif>, private N
161161
const uint8_t *aBuffer,
162162
uint16_t aBufferLength);
163163

164-
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE && OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
165-
/**
166-
* Sends an asynchronous address lookup for the well-known host name "ipv4only.arpa"
167-
* to discover the NAT64 prefix.
168-
*
169-
* @param[in] aInfraIfIndex The index of the infrastructure interface the address look-up is sent to.
170-
*
171-
* @retval OT_ERROR_NONE Successfully request address look-up.
172-
* @retval OT_ERROR_FAILED Failed to request address look-up.
173-
*/
174-
otError DiscoverNat64Prefix(uint32_t aInfraIfIndex);
175-
#endif
176-
177164
/**
178165
* Gets the infrastructure network interface name.
179166
*
@@ -230,12 +217,6 @@ class InfraNetif : public Mainloop::Source, public Logger<InfraNetif>, private N
230217
void ReceiveNetLinkMessage(void);
231218
#endif
232219

233-
#if OPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE && OPENTHREAD_POSIX_CONFIG_NAT64_AIL_PREFIX_ENABLE
234-
#ifdef __linux__
235-
static void DiscoverNat64PrefixDone(union sigval sv);
236-
#endif // #ifdef __linux__
237-
#endif
238-
239220
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
240221
void SetInfraNetifIcmp6SocketForBorderRouting(int aIcmp6Socket);
241222
void ReceiveIcmp6Message(void);

tests/scripts/thread-cert/border_router/internet/test_multi_border_routers.py

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
BR2 = 3
5050
HOST = 4
5151

52-
OMR_PREFIX = "2000:0:1111:4444::/64"
53-
54-
NAT64_PREFIX_REFRESH_DELAY = 305
55-
5652
NAT64_STATE_DISABLED = 'disabled'
5753
NAT64_STATE_NOT_RUNNING = 'not_running'
5854
NAT64_STATE_IDLE = 'idle'
@@ -100,18 +96,14 @@ def test(self):
10096
# ensure NAT64 is enabled here.
10197
br1.nat64_set_enabled(True)
10298
self.simulator.go(config.LEADER_STARTUP_DELAY)
103-
br1.bash("service bind9 stop || true")
104-
self.simulator.go(NAT64_PREFIX_REFRESH_DELAY)
10599
self.assertEqual('leader', br1.get_state())
106100

107101
router.start()
108102
self.simulator.go(config.ROUTER_STARTUP_DELAY)
109103
self.assertEqual('router', router.get_state())
110104

111105
#
112-
# Case 1. BR2 with an infrastructure prefix joins the network later and
113-
# it will add the infrastructure nat64 prefix to Network Data.
114-
# Note: NAT64 translator will be bypassed.
106+
# Case 1. BR2 joins the network and it will not add its local nat64 prefix to Network Data.
115107
#
116108
br2.start()
117109
# When feature flag is enabled, NAT64 might be disabled by default. So
@@ -120,60 +112,9 @@ def test(self):
120112
self.simulator.go(config.BORDER_ROUTER_STARTUP_DELAY)
121113
self.assertEqual('router', br2.get_state())
122114

123-
br2.add_prefix(OMR_PREFIX)
124-
br2.register_netdata()
125115
self.simulator.go(10)
126-
127-
self.simulator.go(10)
128-
self.assertNotEqual(br1.get_br_favored_nat64_prefix(), br2.get_br_favored_nat64_prefix())
129116
br1_local_nat64_prefix = br1.get_br_nat64_prefix()
130117
br2_local_nat64_prefix = br2.get_br_nat64_prefix()
131-
self.assertNotEqual(br2_local_nat64_prefix, br2.get_br_favored_nat64_prefix())
132-
br2_infra_nat64_prefix = br2.get_br_favored_nat64_prefix()
133-
134-
self.assertEqual(len(br1.get_netdata_nat64_routes()), 1)
135-
nat64_prefix = br1.get_netdata_nat64_routes()[0]
136-
self.assertEqual(nat64_prefix, br2_infra_nat64_prefix)
137-
self.assertNotEqual(nat64_prefix, br1_local_nat64_prefix)
138-
self.assertDictIncludes(br1.nat64_state, {
139-
'PrefixManager': NAT64_STATE_IDLE,
140-
'Translator': NAT64_STATE_NOT_RUNNING
141-
})
142-
self.assertDictIncludes(br2.nat64_state, {
143-
'PrefixManager': NAT64_STATE_ACTIVE,
144-
'Translator': NAT64_STATE_NOT_RUNNING
145-
})
146-
147-
#
148-
# Case 2. Disable NAT64 on BR2.
149-
# BR1 will add its local nat64 prefix.
150-
#
151-
br2.nat64_set_enabled(False)
152-
self.simulator.go(10)
153-
154-
self.assertEqual(len(br1.get_netdata_nat64_routes()), 1)
155-
nat64_prefix = br1.get_netdata_nat64_routes()[0]
156-
self.assertEqual(nat64_prefix, br1_local_nat64_prefix)
157-
self.assertDictIncludes(br1.nat64_state, {
158-
'PrefixManager': NAT64_STATE_ACTIVE,
159-
'Translator': NAT64_STATE_ACTIVE
160-
})
161-
self.assertDictIncludes(br2.nat64_state, {
162-
'PrefixManager': NAT64_STATE_DISABLED,
163-
'Translator': NAT64_STATE_DISABLED
164-
})
165-
166-
#
167-
# Case 3. Re-enables BR2 with a local prefix and it will not add
168-
# its local nat64 prefix to Network Data.
169-
#
170-
br2.bash("service bind9 stop || true")
171-
self.simulator.go(5)
172-
br2.nat64_set_enabled(True)
173-
174-
self.simulator.go(10)
175-
self.assertEqual(br2_local_nat64_prefix, br2.get_br_favored_nat64_prefix())
176-
177118
self.assertEqual(len(br1.get_netdata_nat64_routes()), 1)
178119
nat64_prefix = br1.get_netdata_nat64_routes()[0]
179120
self.assertEqual(nat64_prefix, br1_local_nat64_prefix)
@@ -188,7 +129,7 @@ def test(self):
188129
})
189130

190131
#
191-
# Case 4. Disable NAT64 on BR1.
132+
# Case 2. Disable NAT64 on BR1.
192133
# BR1 withdraws its local prefix and BR2 advertises its local prefix.
193134
#
194135
br1.nat64_set_enabled(False)
@@ -208,7 +149,7 @@ def test(self):
208149
})
209150

210151
#
211-
# Case 5. Re-enable NAT64 on BR1.
152+
# Case 3. Re-enable NAT64 on BR1.
212153
# NAT64 prefix in Network Data is still BR2's local prefix.
213154
#
214155
br1.nat64_set_enabled(True)
@@ -228,7 +169,7 @@ def test(self):
228169
})
229170

230171
#
231-
# Case 6. Disable the routing manager should stop NAT64 prefix manager.
172+
# Case 4. Disable the routing manager should stop NAT64 prefix manager.
232173
#
233174
#
234175
br2.disable_br()
@@ -247,7 +188,7 @@ def test(self):
247188
})
248189

249190
#
250-
# Case 7. Enable the routing manager the BR should start NAT64 prefix manager if the prefix manager is enabled.
191+
# Case 5. Enable the routing manager the BR should start NAT64 prefix manager if the prefix manager is enabled.
251192
#
252193
#
253194
br2.enable_br()

tests/scripts/thread-cert/border_router/internet/test_with_infrastructure_prefix.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class Nat64SingleBorderRouter(thread_cert.TestCase):
7777
}
7878

7979
def test(self):
80+
# TODO: re-enable test when PREF64 capability is ready
81+
return
82+
8083
br = self.nodes[BR]
8184
router = self.nodes[ROUTER]
8285

0 commit comments

Comments
 (0)