diff --git a/src/core/net/ip6_filter.cpp b/src/core/net/ip6_filter.cpp index c10835b9d..b5d9ef903 100644 --- a/src/core/net/ip6_filter.cpp +++ b/src/core/net/ip6_filter.cpp @@ -40,16 +40,16 @@ namespace Ip6 { RegisterLogModule("Ip6Filter"); -bool Filter::Accept(Message &aMessage) const +Error Filter::Apply(const Message &aMessage) const { - bool rval = false; + Error error = kErrorDrop; Headers headers; uint16_t dstPort; // Allow all received IPv6 datagrams with link security enabled if (aMessage.IsLinkSecurityEnabled()) { - ExitNow(rval = true); + ExitNow(error = kErrorNone); } SuccessOrExit(headers.ParseFrom(aMessage)); @@ -59,7 +59,7 @@ bool Filter::Accept(Message &aMessage) const // Allow all link-local IPv6 datagrams when Thread is not enabled if (Get().GetRole() == Mle::kRoleDisabled) { - ExitNow(rval = true); + ExitNow(error = kErrorNone); } dstPort = headers.GetDestinationPort(); @@ -70,7 +70,7 @@ bool Filter::Accept(Message &aMessage) const // Allow MLE traffic if (dstPort == Mle::kUdpPort) { - ExitNow(rval = true); + ExitNow(error = kErrorNone); } #if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE @@ -78,7 +78,7 @@ bool Filter::Accept(Message &aMessage) const if (Get().GetSecurityPolicy().mNativeCommissioningEnabled && dstPort == Get().GetUdpPort()) { - ExitNow(rval = true); + ExitNow(error = kErrorNone); } #endif break; @@ -92,10 +92,13 @@ bool Filter::Accept(Message &aMessage) const } // Check against allowed unsecure port list - rval = mUnsecurePorts.Contains(dstPort); + if (mUnsecurePorts.Contains(dstPort)) + { + error = kErrorNone; + } exit: - return rval; + return error; } Error Filter::UpdateUnsecurePorts(Action aAction, uint16_t aPort) diff --git a/src/core/net/ip6_filter.hpp b/src/core/net/ip6_filter.hpp index 58b1f39b0..3e00bfa00 100644 --- a/src/core/net/ip6_filter.hpp +++ b/src/core/net/ip6_filter.hpp @@ -70,14 +70,14 @@ public: } /** - * Indicates whether or not the IPv6 datagram passes the filter. + * Applies the filter to an IPv6 datagram to determine if it should be dropped. * * @param[in] aMessage The IPv6 datagram to process. * - * @retval TRUE Accept the IPv6 datagram. - * @retval FALSE Reject the IPv6 datagram. + * @retval kErrorNone The message is not filtered and should be accepted. + * @retval kErrorDrop The message matches the filter criteria and should be dropped. */ - bool Accept(Message &aMessage) const; + Error Apply(const Message &aMessage) const; /** * Adds a port to the allowed unsecured port list. diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 969d48926..95749b64d 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -1455,7 +1455,7 @@ void MeshForwarder::HandleFragment(RxInfo &aRxInfo) message->SetTimestampToNow(); message->UpdateLinkInfoFrom(aRxInfo.mLinkInfo); - VerifyOrExit(Get().Accept(*message), error = kErrorDrop); + SuccessOrExit(error = Get().Apply(*message)); #if OPENTHREAD_FTD CheckReachabilityToSendIcmpError(*message, aRxInfo.mMacAddrs); @@ -1603,7 +1603,7 @@ void MeshForwarder::HandleLowpanHc(RxInfo &aRxInfo) message->UpdateLinkInfoFrom(aRxInfo.mLinkInfo); - VerifyOrExit(Get().Accept(*message), error = kErrorDrop); + SuccessOrExit(error = Get().Apply(*message)); #if OPENTHREAD_FTD CheckReachabilityToSendIcmpError(*message, aRxInfo.mMacAddrs);