diff --git a/src/core/api/ip6_api.cpp b/src/core/api/ip6_api.cpp index 6c12e64de..a72e64a01 100644 --- a/src/core/api/ip6_api.cpp +++ b/src/core/api/ip6_api.cpp @@ -100,7 +100,7 @@ otError otIp6UnsubscribeMulticastAddress(otInstance *aInstance, const otIp6Addre void otIp6SetReceiveCallback(otInstance *aInstance, otIp6ReceiveCallback aCallback, void *aCallbackContext) { - AsCoreType(aInstance).Get().SetReceiveDatagramCallback(aCallback, aCallbackContext); + AsCoreType(aInstance).Get().SetReceiveCallback(aCallback, aCallbackContext); } void otIp6SetAddressCallback(otInstance *aInstance, otIp6AddressCallback aCallback, void *aCallbackContext) diff --git a/src/core/api/nat64_api.cpp b/src/core/api/nat64_api.cpp index 6e6673398..bab32126e 100644 --- a/src/core/api/nat64_api.cpp +++ b/src/core/api/nat64_api.cpp @@ -61,7 +61,7 @@ otError otNat64Send(otInstance *aInstance, otMessage *aMessage) void otNat64SetReceiveIp4Callback(otInstance *aInstance, otNat64ReceiveIp4Callback aCallback, void *aContext) { - AsCoreType(aInstance).Get().SetNat64ReceiveIp4DatagramCallback(aCallback, aContext); + AsCoreType(aInstance).Get().SetNat64ReceiveIp4Callback(aCallback, aContext); } void otNat64InitAddressMappingIterator(otInstance *aInstance, otNat64AddressMappingIterator *aIterator) diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 4400d48da..c8f5ea803 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -49,7 +49,7 @@ RegisterLogModule("Ip6"); Ip6::Ip6(Instance &aInstance) : InstanceLocator(aInstance) - , mIsReceiveIp6FilterEnabled(false) + , mReceiveFilterEnabled(false) #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE , mTmfOriginFilterEnabled(true) #endif @@ -750,7 +750,7 @@ void Ip6::UpdateReassemblyList(void) for (Message &message : mReassemblyList) { - if (now - message.GetTimestamp() >= TimeMilli::SecToMsec(kIp6ReassemblyTimeout)) + if (now - message.GetTimestamp() >= TimeMilli::SecToMsec(kReassemblyTimeout)) { LogNote("Reassembly timeout."); SendIcmpError(message, Icmp::Header::kTypeTimeExceeded, Icmp::Header::kCodeFragmReasTimeEx); @@ -935,7 +935,7 @@ Error Ip6::PassToHost(OwnedPtr &aMessagePtr, VerifyOrExit(aMessagePtr->IsLoopbackToHostAllowed()); - VerifyOrExit(mReceiveIp6DatagramCallback.IsSet(), error = kErrorNoRoute); + VerifyOrExit(mReceiveCallback.IsSet(), error = kErrorNoRoute); // Do not pass IPv6 packets that exceed kMinimalMtu. VerifyOrExit(aMessagePtr->GetLength() <= kMinimalMtu, error = kErrorDrop); @@ -954,7 +954,7 @@ Error Ip6::PassToHost(OwnedPtr &aMessagePtr, VerifyOrExit(aReceive, error = kErrorDrop); } - if (mIsReceiveIp6FilterEnabled && aReceive) + if (mReceiveFilterEnabled && aReceive) { switch (aIpProto) { @@ -1007,9 +1007,9 @@ Error Ip6::PassToHost(OwnedPtr &aMessagePtr, ExitNow(error = kErrorDrop); case Nat64::Translator::kForward: - VerifyOrExit(mReceiveIp4DatagramCallback.IsSet(), error = kErrorNoRoute); + VerifyOrExit(mIp4ReceiveCallback.IsSet(), error = kErrorNoRoute); // Pass message to callback transferring its ownership. - mReceiveIp4DatagramCallback.Invoke(messagePtr.Release()); + mIp4ReceiveCallback.Invoke(messagePtr.Release()); ExitNow(); } #endif @@ -1032,7 +1032,7 @@ Error Ip6::PassToHost(OwnedPtr &aMessagePtr, #endif // Pass message to callback transferring its ownership. - mReceiveIp6DatagramCallback.Invoke(messagePtr.Release()); + mReceiveCallback.Invoke(messagePtr.Release()); exit: return error; @@ -1455,12 +1455,12 @@ exit: if (counter) { - counter->mPackets += 1; + counter->mPackets++; counter->mBytes += aMessageLength; } if (internetCounter) { - internetCounter->mPackets += 1; + internetCounter->mPackets++; internetCounter->mBytes += aMessageLength; } } diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index 310c00621..9e34cc61d 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -108,6 +108,8 @@ class Ip6 : public InstanceLocator, private NonCopyable friend class Mpl; public: + typedef otIp6ReceiveCallback ReceiveCallback; ///< IPv6 receive callback function pointer. + /** * Initializes the object. * @@ -206,60 +208,46 @@ public: Error HandleDatagram(OwnedPtr aMessagePtr, bool aIsReassembled = false); /** - * Registers a callback to provide received raw IPv6 datagrams. + * Sets the callback to provide received raw IPv6 datagrams. * - * By default, this callback does not pass Thread control traffic. See SetReceiveIp6FilterEnabled() to change + * By default, this callback does not pass Thread control traffic. See `SetReceiveIp6FilterEnabled()` to change * the Thread control traffic filter setting. * - * @param[in] aCallback A pointer to a function that is called when an IPv6 datagram is received - * or `nullptr` to disable the callback. - * @param[in] aCallbackContext A pointer to application-specific context. - * - * @sa IsReceiveIp6FilterEnabled - * @sa SetReceiveIp6FilterEnabled + * @param[in] aCallback The receive callback function. Can be `nullptr` to disable the callback. + * @param[in] aContext A pointer to application-specific context. */ - void SetReceiveDatagramCallback(otIp6ReceiveCallback aCallback, void *aCallbackContext) - { - mReceiveIp6DatagramCallback.Set(aCallback, aCallbackContext); - } + void SetReceiveCallback(ReceiveCallback aCallback, void *aContext) { mReceiveCallback.Set(aCallback, aContext); } #if OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE + typedef otNat64ReceiveIp4Callback Ip4ReceiveCallback; ///< NAT64 IPv4 receive callback function pointer. + /** - * Registers a callback to provide received translated IPv4 datagrams. + * Sets the callback to provide received translated IPv4 datagrams. * - * @param[in] aCallback A pointer to a function that is called when a translated IPv4 datagram is received - * or `nullptr` to disable the callback. - * @param[in] aCallbackContext A pointer to application-specific context. - * - * @sa SetReceiveDatagramCallback + * @param[in] aCallback The NAT64 IPv4 callbac, used when translated IPv4 datagram is received. + * @param[in] aContext A pointer to application-specific context. */ - void SetNat64ReceiveIp4DatagramCallback(otNat64ReceiveIp4Callback aCallback, void *aCallbackContext) + void SetNat64ReceiveIp4Callback(Ip4ReceiveCallback aCallback, void *aContext) { - mReceiveIp4DatagramCallback.Set(aCallback, aCallbackContext); + mIp4ReceiveCallback.Set(aCallback, aContext); } #endif /** * Indicates whether or not Thread control traffic is filtered out when delivering IPv6 datagrams - * via the callback specified in SetReceiveIp6DatagramCallback(). + * via the callback specified in `SetReceiveIp6Callback()`. * * @returns TRUE if Thread control traffic is filtered out, FALSE otherwise. - * - * @sa SetReceiveDatagramCallback - * @sa SetReceiveIp6FilterEnabled */ - bool IsReceiveIp6FilterEnabled(void) const { return mIsReceiveIp6FilterEnabled; } + bool IsReceiveIp6FilterEnabled(void) const { return mReceiveFilterEnabled; } /** * Sets whether or not Thread control traffic is filtered out when delivering IPv6 datagrams - * via the callback specified in SetReceiveIp6DatagramCallback(). + * via the callback specified in `SetReceiveIp6Callback()`. * * @param[in] aEnabled TRUE if Thread control traffic is filtered out, FALSE otherwise. - * - * @sa SetReceiveDatagramCallback - * @sa IsReceiveIp6FilterEnabled */ - void SetReceiveIp6FilterEnabled(bool aEnabled) { mIsReceiveIp6FilterEnabled = aEnabled; } + void SetReceiveIp6FilterEnabled(bool aEnabled) { mReceiveFilterEnabled = aEnabled; } /** * Performs default source address selection. @@ -349,8 +337,8 @@ public: #endif private: - static constexpr uint8_t kDefaultHopLimit = OPENTHREAD_CONFIG_IP6_HOP_LIMIT_DEFAULT; - static constexpr uint8_t kIp6ReassemblyTimeout = OPENTHREAD_CONFIG_IP6_REASSEMBLY_TIMEOUT; + static constexpr uint8_t kDefaultHopLimit = OPENTHREAD_CONFIG_IP6_HOP_LIMIT_DEFAULT; + static constexpr uint8_t kReassemblyTimeout = OPENTHREAD_CONFIG_IP6_REASSEMBLY_TIMEOUT; static constexpr uint16_t kMinimalMtu = 1280; @@ -396,33 +384,25 @@ private: using SendQueueTask = TaskletIn; - bool mIsReceiveIp6FilterEnabled; - + bool mReceiveFilterEnabled; #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - bool mTmfOriginFilterEnabled : 1; + bool mTmfOriginFilterEnabled; #endif - - Callback mReceiveIp6DatagramCallback; - + Callback mReceiveCallback; #if OPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE - Callback mReceiveIp4DatagramCallback; + Callback mIp4ReceiveCallback; #endif - PriorityQueue mSendQueue; SendQueueTask mSendQueueTask; - - Icmp mIcmp; - Udp mUdp; - Mpl mMpl; - + Icmp mIcmp; + Udp mUdp; + Mpl mMpl; #if OPENTHREAD_CONFIG_TCP_ENABLE Tcp mTcp; #endif - #if OPENTHREAD_CONFIG_IP6_FRAGMENTATION_ENABLE MessageQueue mReassemblyList; #endif - #if OPENTHREAD_CONFIG_IP6_BR_COUNTERS_ENABLE BrCounters mBrCounters; #endif