diff options
author | Yang Sun <sunytt@google.com> | 2024-04-20 00:29:34 +0800 |
---|---|---|
committer | Yang Sun <sunytt@google.com> | 2024-04-22 11:06:15 +0800 |
commit | c8442d07569808cf3eeecd9f15dbcd2b3c136dbc (patch) | |
tree | 990b9f1663860fb24730cf326d8cfbe6c99c625f | |
parent | 94da396cdc0514cf9c2f824dff321fd756a1aa3e (diff) | |
download | openthread-c8442d07569808cf3eeecd9f15dbcd2b3c136dbc.tar.gz |
[icmp] add `OT_ICMP6_ECHO_HANDLER_RLOC_ALOC_ONLY` to `otIcmp6EchoMode` (#10014)
When an icmp echo request is sent to rloc/aloc address of a Thread
device, OT replies to the packet. The packet is also passed to host
and the kernel may reply to the echo request. This would cause 2 echo
replies and may be confusing when testing packet loss rate by pinging
a rloc/aloc address.
Added OT_ICMP6_ECHO_HANDLER_RLOC_ALOC_ONLY to otIcmp6EchoMode to let
OT only handle echo request to rloc/aloc addresses, this is the
default mode in posix code. Set otIcmp6EchoMode to
OT_ICMP6_ECHO_HANDLER_DISABLED will help to avoid double ping replies
from both OT and host.
(cherry picked from commit 59572efb4e51c9b0218e840bad8c6dc7758dc3a0)
Bug: 333493455
Change-Id: If6cfdf187310d41d633199274b93d0f5c6488871
-rw-r--r-- | include/openthread/icmp6.h | 1 | ||||
-rw-r--r-- | include/openthread/instance.h | 2 | ||||
-rw-r--r-- | src/core/net/icmp6.cpp | 6 | ||||
-rw-r--r-- | src/lib/spinel/spinel.h | 2 | ||||
-rw-r--r-- | src/ncp/ncp_base.cpp | 2 | ||||
-rw-r--r-- | src/ncp/ncp_base_mtd.cpp | 6 |
6 files changed, 15 insertions, 4 deletions
diff --git a/include/openthread/icmp6.h b/include/openthread/icmp6.h index 32f8c6a1b..925871cda 100644 --- a/include/openthread/icmp6.h +++ b/include/openthread/icmp6.h @@ -144,6 +144,7 @@ typedef enum otIcmp6EchoMode OT_ICMP6_ECHO_HANDLER_UNICAST_ONLY = 1, ///< ICMPv6 Echo processing enabled only for unicast requests only OT_ICMP6_ECHO_HANDLER_MULTICAST_ONLY = 2, ///< ICMPv6 Echo processing enabled only for multicast requests only OT_ICMP6_ECHO_HANDLER_ALL = 3, ///< ICMPv6 Echo processing enabled for unicast and multicast requests + OT_ICMP6_ECHO_HANDLER_RLOC_ALOC_ONLY = 4, ///< ICMPv6 Echo processing enabled for RLOC/ALOC destinations only } otIcmp6EchoMode; /** diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 1ce766c02..a956397bb 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (402) +#define OPENTHREAD_API_VERSION (405) /** * @addtogroup api-instance diff --git a/src/core/net/icmp6.cpp b/src/core/net/icmp6.cpp index 5bcea06c0..3dba7ca96 100644 --- a/src/core/net/icmp6.cpp +++ b/src/core/net/icmp6.cpp @@ -171,6 +171,9 @@ bool Icmp::ShouldHandleEchoRequest(const MessageInfo &aMessageInfo) case OT_ICMP6_ECHO_HANDLER_ALL: rval = true; break; + case OT_ICMP6_ECHO_HANDLER_RLOC_ALOC_ONLY: + rval = aMessageInfo.GetSockAddr().GetIid().IsLocator(); + break; } return rval; @@ -184,8 +187,7 @@ Error Icmp::HandleEchoRequest(Message &aRequestMessage, const MessageInfo &aMess MessageInfo replyMessageInfo; uint16_t dataOffset; - // always handle Echo Request destined for RLOC or ALOC - VerifyOrExit(ShouldHandleEchoRequest(aMessageInfo) || aMessageInfo.GetSockAddr().GetIid().IsLocator()); + VerifyOrExit(ShouldHandleEchoRequest(aMessageInfo)); LogInfo("Received Echo Request"); diff --git a/src/lib/spinel/spinel.h b/src/lib/spinel/spinel.h index d91a039ac..c1865f373 100644 --- a/src/lib/spinel/spinel.h +++ b/src/lib/spinel/spinel.h @@ -607,6 +607,7 @@ typedef enum SPINEL_IPV6_ICMP_PING_OFFLOAD_UNICAST_ONLY = 1, SPINEL_IPV6_ICMP_PING_OFFLOAD_MULTICAST_ONLY = 2, SPINEL_IPV6_ICMP_PING_OFFLOAD_ALL = 3, + SPINEL_IPV6_ICMP_PING_OFFLOAD_RLOC_ALOC_ONLY = 4, } spinel_ipv6_icmp_ping_offload_mode_t; typedef enum @@ -3457,6 +3458,7 @@ enum * SPINEL_IPV6_ICMP_PING_OFFLOAD_UNICAST_ONLY = 1 * SPINEL_IPV6_ICMP_PING_OFFLOAD_MULTICAST_ONLY = 2 * SPINEL_IPV6_ICMP_PING_OFFLOAD_ALL = 3 + * SPINEL_IPV6_ICMP_PING_OFFLOAD_RLOC_ALOC_ONLY = 4 * * Default value is `NET_IPV6_ICMP_PING_OFFLOAD_DISABLED`. * diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index a1ad3adb3..96e362575 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -340,7 +340,7 @@ NcpBase::NcpBase(Instance *aInstance) #if OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE otUdpForwardSetForwarder(mInstance, &NcpBase::HandleUdpForwardStream, this); #endif - otIcmp6SetEchoMode(mInstance, OT_ICMP6_ECHO_HANDLER_DISABLED); + otIcmp6SetEchoMode(mInstance, OT_ICMP6_ECHO_HANDLER_RLOC_ALOC_ONLY); #if OPENTHREAD_FTD otThreadRegisterNeighborTableCallback(mInstance, &NcpBase::HandleNeighborTableChanged); #if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE diff --git a/src/ncp/ncp_base_mtd.cpp b/src/ncp/ncp_base_mtd.cpp index aa87efa51..227ce61ce 100644 --- a/src/ncp/ncp_base_mtd.cpp +++ b/src/ncp/ncp_base_mtd.cpp @@ -2072,6 +2072,9 @@ template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_IPV6_ICMP_PING_OFFLOA case OT_ICMP6_ECHO_HANDLER_ALL: mode = SPINEL_IPV6_ICMP_PING_OFFLOAD_ALL; break; + case OT_ICMP6_ECHO_HANDLER_RLOC_ALOC_ONLY: + mode = SPINEL_IPV6_ICMP_PING_OFFLOAD_RLOC_ALOC_ONLY; + break; }; return mEncoder.WriteUint8(mode); @@ -2099,6 +2102,9 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_IPV6_ICMP_PING_OFFLOA case SPINEL_IPV6_ICMP_PING_OFFLOAD_ALL: mode = OT_ICMP6_ECHO_HANDLER_ALL; break; + case SPINEL_IPV6_ICMP_PING_OFFLOAD_RLOC_ALOC_ONLY: + mode = OT_ICMP6_ECHO_HANDLER_RLOC_ALOC_ONLY; + break; }; otIcmp6SetEchoMode(mInstance, mode); |