[meshcop] fix UDP proxy (#6396)

The MeshCoP UDP Proxy packets should not be sent/received with
platform UDP.
This commit is contained in:
kangping
2021-04-05 22:31:43 -07:00
committed by GitHub
parent 5bc74b7113
commit fa09e8a75d
5 changed files with 32 additions and 7 deletions
+16 -5
View File
@@ -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;
+10
View File
@@ -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
+2 -1
View File
@@ -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);
+1 -1
View File
@@ -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).
+3
View File
@@ -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