From d807d8d491abd12c74f39dfe0c0660f7a4413310 Mon Sep 17 00:00:00 2001 From: Buke Po Date: Sat, 17 Jun 2017 14:58:13 +0800 Subject: [PATCH] Fix multicast from Ncp Host going back to host (#1910) * fix multicast from Ncp Host going back to host * rename SendFromNcpHost to SendRaw --- src/core/api/ip6_api.cpp | 4 ++-- src/core/net/ip6.cpp | 31 ++++++++++++++++++++++++++----- src/core/net/ip6.hpp | 12 ++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/src/core/api/ip6_api.cpp b/src/core/api/ip6_api.cpp index 29d72fb68..b9d08ca89 100644 --- a/src/core/api/ip6_api.cpp +++ b/src/core/api/ip6_api.cpp @@ -162,8 +162,8 @@ otError otIp6Send(otInstance *aInstance, otMessage *aMessage) otLogFuncEntry(); - error = aInstance->mIp6.HandleDatagram(*static_cast(aMessage), NULL, - aInstance->mThreadNetif.GetInterfaceId(), NULL, true); + error = aInstance->mIp6.SendRaw(*static_cast(aMessage), + aInstance->mThreadNetif.GetInterfaceId()); otLogFuncExitErr(error); diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 4a062c29d..9a6d213c8 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -654,6 +654,32 @@ exit: return error; } +otError Ip6::SendRaw(Message &aMessage, int8_t aInterfaceId) +{ + otError error = OT_ERROR_NONE; + Header header; + MessageInfo messageInfo; + + // check aMessage length + VerifyOrExit(aMessage.Read(0, sizeof(header), &header) == sizeof(header), error = OT_ERROR_DROP); + + messageInfo.SetPeerAddr(header.GetSource()); + messageInfo.SetSockAddr(header.GetDestination()); + messageInfo.SetInterfaceId(aInterfaceId); + messageInfo.SetHopLimit(header.GetHopLimit()); + messageInfo.SetLinkInfo(NULL); + + if (header.GetDestination().IsMulticast()) + { + SuccessOrExit(error = InsertMplOption(aMessage, header, messageInfo)); + } + + error = HandleDatagram(aMessage, NULL, aInterfaceId, NULL, true); + +exit: + return error; +} + otError Ip6::HandleDatagram(Message &aMessage, Netif *aNetif, int8_t aInterfaceId, const void *aLinkMessageInfo, bool aFromNcpHost) { @@ -711,11 +737,6 @@ otError Ip6::HandleDatagram(Message &aMessage, Netif *aNetif, int8_t aInterfaceI else { forward = true; - - if (aFromNcpHost) - { - SuccessOrExit(error = InsertMplOption(aMessage, header, messageInfo)); - } } } else diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index df02371f1..615e751b1 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -132,6 +132,18 @@ public: */ otError SendDatagram(Message &aMessage, MessageInfo &aMessageInfo, IpProto aIpProto); + /** + * This method sends a raw IPv6 datagram with a fully formed IPv6 header. + * + * @param[in] aMessage A reference to the message. + * @param[in] aInterfaceId The interface identifier of the network interface that received the message. + * + * @retval OT_ERROR_NONE Successfully processed the message. + * @retval OT_ERROR_DROP Message processing failed and the message should be dropped. + * + */ + otError SendRaw(Message &aMessage, int8_t aInterfaceId); + /** * This method processes a received IPv6 datagram. *