mirror of
https://github.com/espressif/openthread.git
synced 2026-09-04 08:10:11 +00:00
[udp] remove extra ShouldUsePlatformUdp() checks (#10962)
This commit removes the `ShouldUsePlatformUdp()` call in `Ip6::PassToHost()` and `Udp::HandleMessage()`. `ShouldUsePlatformUdp(port)` checks whether the port is NOT one of the port numbers used by the OT stack, such as the MLE port, TMF port, border agent port, or joiner port. This check is already covered by `Udp::IsPortInUse()`, which checks if there is a UDP socket bound to the given port. Applying such a filter in `Udp::HandleMessage()` seems to have been added by mistake, as it blocks the use of UDP receivers, which should be able to receive and process on any port, not just the ports where we have a socket bound.
This commit is contained in:
@@ -972,9 +972,7 @@ Error Ip6::PassToHost(OwnedPtr<Message> &aMessagePtr,
|
||||
Udp::Header udp;
|
||||
|
||||
IgnoreError(aMessagePtr->Read(aMessagePtr->GetOffset(), udp));
|
||||
VerifyOrExit(Get<Udp>().ShouldUsePlatformUdp(udp.GetDestinationPort()) &&
|
||||
!Get<Udp>().IsPortInUse(udp.GetDestinationPort()),
|
||||
error = kErrorNoRoute);
|
||||
VerifyOrExit(!Get<Udp>().IsPortInUse(udp.GetDestinationPort()), error = kErrorNoRoute);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
+16
-12
@@ -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<MeshCoP::BorderAgent>().GetUdpProxyPort()
|
||||
VerifyOrExit(aPort != Get<MeshCoP::BorderAgent>().GetUdpProxyPort());
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
&& aPort != Get<MeshCoP::JoinerRouter>().GetJoinerUdpPort()
|
||||
VerifyOrExit(aPort != Get<MeshCoP::JoinerRouter>().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)
|
||||
|
||||
+1
-10
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user