mirror of
https://github.com/espressif/openthread.git
synced 2026-08-27 20:39:54 +00:00
[meshcop] fix UDP proxy (#6396)
The MeshCoP UDP Proxy packets should not be sent/received with platform UDP.
This commit is contained in:
@@ -185,6 +185,9 @@ void BorderAgent::HandleCoapResponse(ForwardContext &aForwardContext, const Coap
|
||||
IgnoreError(Get<Mle::MleRouter>().GetCommissionerAloc(mCommissionerAloc.GetAddress(), sessionId));
|
||||
Get<ThreadNetif>().AddUnicastAddress(mCommissionerAloc);
|
||||
IgnoreError(Get<Ip6::Udp>().AddReceiver(mUdpReceiver));
|
||||
|
||||
otLogInfoMeshCoP("commissioner accepted: session ID=%d, ALOC=%s", sessionId,
|
||||
mCommissionerAloc.GetAddress().ToString().AsCString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,6 +288,7 @@ BorderAgent::BorderAgent(Instance &aInstance)
|
||||
, mUdpReceiver(BorderAgent::HandleUdpReceive, this)
|
||||
, mTimer(aInstance, HandleTimeout)
|
||||
, mState(kStateStopped)
|
||||
, mUdpProxyPort(0)
|
||||
{
|
||||
mCommissionerAloc.InitAsThreadOriginRealmLocalScope();
|
||||
}
|
||||
@@ -325,14 +329,18 @@ void BorderAgent::HandleProxyTransmit(const Coap::Message &aMessage)
|
||||
SuccessOrExit(error = message->SetLength(tlv.GetUdpLength()));
|
||||
aMessage.CopyTo(offset + sizeof(tlv), 0, tlv.GetUdpLength(), *message);
|
||||
|
||||
messageInfo.SetSockPort(tlv.GetSourcePort() != 0 ? tlv.GetSourcePort() : Get<Ip6::Udp>().GetEphemeralPort());
|
||||
VerifyOrExit(tlv.GetSourcePort() > 0 && tlv.GetDestinationPort() > 0, error = kErrorDrop);
|
||||
|
||||
messageInfo.SetSockPort(tlv.GetSourcePort());
|
||||
messageInfo.SetSockAddr(mCommissionerAloc.GetAddress());
|
||||
messageInfo.SetPeerPort(tlv.GetDestinationPort());
|
||||
|
||||
SuccessOrExit(error = Tlv::Find<Ip6AddressTlv>(aMessage, messageInfo.GetPeerAddr()));
|
||||
|
||||
SuccessOrExit(error = Get<Ip6::Udp>().SendDatagram(*message, messageInfo, Ip6::kProtoUdp));
|
||||
otLogInfoMeshCoP("Proxy transmit sent");
|
||||
mUdpProxyPort = tlv.GetSourcePort();
|
||||
|
||||
otLogInfoMeshCoP("Proxy transmit sent to %s", messageInfo.GetPeerAddr().ToString().AsCString());
|
||||
|
||||
exit:
|
||||
FreeMessageOnError(message, error);
|
||||
@@ -557,7 +565,8 @@ void BorderAgent::HandleConnected(bool aConnected)
|
||||
otLogInfoMeshCoP("Commissioner disconnected");
|
||||
IgnoreError(Get<Ip6::Udp>().RemoveReceiver(mUdpReceiver));
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mCommissionerAloc);
|
||||
mState = kStateStarted;
|
||||
mState = kStateStarted;
|
||||
mUdpProxyPort = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,7 +594,8 @@ Error BorderAgent::Start(void)
|
||||
|
||||
Get<Tmf::TmfAgent>().AddResource(mRelayReceive);
|
||||
|
||||
mState = kStateStarted;
|
||||
mState = kStateStarted;
|
||||
mUdpProxyPort = 0;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
@@ -629,7 +639,8 @@ Error BorderAgent::Stop(void)
|
||||
|
||||
coaps.Stop();
|
||||
|
||||
mState = kStateStopped;
|
||||
mState = kStateStopped;
|
||||
mUdpProxyPort = 0;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
@@ -106,6 +106,15 @@ public:
|
||||
*/
|
||||
void ApplyMeshLocalPrefix(void);
|
||||
|
||||
/**
|
||||
* This method returns the UDP Proxy port to which the commissioner is currently
|
||||
* bound.
|
||||
*
|
||||
* @returns The current UDP Proxy port or 0 if no Proxy Transmit has been received yet.
|
||||
*
|
||||
*/
|
||||
uint16_t GetUdpProxyPort(void) const { return mUdpProxyPort; }
|
||||
|
||||
private:
|
||||
class ForwardContext : public InstanceLocatorInit
|
||||
{
|
||||
@@ -187,6 +196,7 @@ private:
|
||||
|
||||
TimerMilli mTimer;
|
||||
State mState;
|
||||
uint16_t mUdpProxyPort;
|
||||
};
|
||||
|
||||
} // namespace MeshCoP
|
||||
|
||||
@@ -448,7 +448,8 @@ void DatasetManager::SendGetResponse(const Coap::Message & aRequest,
|
||||
|
||||
SuccessOrExit(error = Get<Tmf::TmfAgent>().SendMessage(*message, aMessageInfo));
|
||||
|
||||
otLogInfoMeshCoP("sent dataset get response");
|
||||
otLogInfoMeshCoP("sent %s dataset get response to %s", (GetType() == Dataset::kActive ? "active" : "pending"),
|
||||
aMessageInfo.GetPeerAddr().ToString().AsCString());
|
||||
|
||||
exit:
|
||||
FreeMessageOnError(message, error);
|
||||
|
||||
@@ -421,7 +421,7 @@ public:
|
||||
bool IsAnycastLocator(void) const;
|
||||
|
||||
/**
|
||||
* This method indicates whether or not the Interface Identifier (IID) matches a Service Anycast Locator (ALOC).
|
||||
* This method indicates whether or not the Interface Identifier (IID) matches a Service Anycast Locator (ALOC).
|
||||
*
|
||||
* In addition to checking that the IID matches the locator pattern (`0000:00ff:fe00:xxxx`), this method also
|
||||
* checks that the locator value is a valid Service ALOC16 (0xfc10 – 0xfc2f).
|
||||
|
||||
@@ -527,6 +527,9 @@ exit:
|
||||
bool Udp::ShouldUsePlatformUdp(uint16_t aPort) const
|
||||
{
|
||||
return (aPort != Mle::kUdpPort && aPort != Tmf::kUdpPort
|
||||
#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE
|
||||
&& aPort != Get<MeshCoP::BorderAgent>().GetUdpProxyPort()
|
||||
#endif
|
||||
#if OPENTHREAD_FTD
|
||||
&& aPort != Get<MeshCoP::JoinerRouter>().GetJoinerUdpPort()
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user