diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 8ccb3c7ee..ca3cd124c 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -972,9 +972,7 @@ Error Ip6::PassToHost(OwnedPtr &aMessagePtr, Udp::Header udp; IgnoreError(aMessagePtr->Read(aMessagePtr->GetOffset(), udp)); - VerifyOrExit(Get().ShouldUsePlatformUdp(udp.GetDestinationPort()) && - !Get().IsPortInUse(udp.GetDestinationPort()), - error = kErrorNoRoute); + VerifyOrExit(!Get().IsPortInUse(udp.GetDestinationPort()), error = kErrorNoRoute); break; } diff --git a/src/core/net/udp6.cpp b/src/core/net/udp6.cpp index 15cf4e9c2..bbd91fe66 100644 --- a/src/core/net/udp6.cpp +++ b/src/core/net/udp6.cpp @@ -412,10 +412,6 @@ Error Udp::HandleMessage(Message &aMessage, MessageInfo &aMessageInfo) aMessageInfo.mPeerPort = udpHeader.GetSourcePort(); aMessageInfo.mSockPort = udpHeader.GetDestinationPort(); -#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE - VerifyOrExit(!ShouldUsePlatformUdp(aMessageInfo.mSockPort) || IsPortInUse(aMessageInfo.mSockPort)); -#endif - for (Receiver &receiver : mReceivers) { VerifyOrExit(!receiver.HandleMessage(aMessage, aMessageInfo)); @@ -458,28 +454,36 @@ bool Udp::IsPortInUse(uint16_t aPort) const return found; } +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE + bool Udp::ShouldUsePlatformUdp(uint16_t aPort) const { - return (aPort != Mle::kUdpPort && aPort != Tmf::kUdpPort + bool shouldUse = false; + + VerifyOrExit(aPort != Mle::kUdpPort); + VerifyOrExit(aPort != Tmf::kUdpPort); #if OPENTHREAD_CONFIG_DNSSD_SERVER_ENABLE && !OPENTHREAD_CONFIG_DNSSD_SERVER_BIND_UNSPECIFIED_NETIF - && aPort != Dns::ServiceDiscovery::Server::kPort + VerifyOrExit(aPort != Dns::ServiceDiscovery::Server::kPort); #endif #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE - && aPort != Get().GetUdpProxyPort() + VerifyOrExit(aPort != Get().GetUdpProxyPort()); #endif #if OPENTHREAD_FTD - && aPort != Get().GetJoinerUdpPort() + VerifyOrExit(aPort != Get().GetJoinerUdpPort()); #endif #if OPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE - && aPort != Dhcp6::kDhcpServerPort + VerifyOrExit(aPort != Dhcp6::kDhcpServerPort); #endif #if OPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE - && aPort != Dhcp6::kDhcpClientPort + VerifyOrExit(aPort != Dhcp6::kDhcpClientPort); #endif - ); + + shouldUse = true; + +exit: + return shouldUse; } -#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE bool Udp::ShouldUsePlatformUdp(const Udp::SocketHandle &aSocket) const { return (ShouldUsePlatformUdp(aSocket.mSockName.mPort) diff --git a/src/core/net/udp6.hpp b/src/core/net/udp6.hpp index 5225ee184..f8650699d 100644 --- a/src/core/net/udp6.hpp +++ b/src/core/net/udp6.hpp @@ -634,16 +634,6 @@ public: */ bool IsPortInUse(uint16_t aPort) const; - /** - * Returns whether a udp port belongs to the platform or the stack. - * - * @param[in] aPort The udp port - * - * @retval True when the port belongs to the platform. - * @retval False when the port belongs to the stack. - */ - bool ShouldUsePlatformUdp(uint16_t aPort) const; - private: static constexpr uint16_t kDynamicPortMin = 49152; // Service Name and Transport Protocol Port Number Registry static constexpr uint16_t kDynamicPortMax = 65535; // Service Name and Transport Protocol Port Number Registry @@ -657,6 +647,7 @@ private: void AddSocket(SocketHandle &aSocket); void RemoveSocket(SocketHandle &aSocket); #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE + bool ShouldUsePlatformUdp(uint16_t aPort) const; bool ShouldUsePlatformUdp(const SocketHandle &aSocket) const; #endif