From 136a444565cc56017d946c76c992db528afb384a Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Wed, 19 Sep 2018 00:29:50 +0800 Subject: [PATCH] [ip6] allow hop limit 0 (#3077) --- src/core/net/ip6.cpp | 4 ++-- src/core/net/ip6.hpp | 4 ++-- src/core/net/socket.hpp | 12 +++++++++++- src/core/openthread-core-default-config.h | 20 ++++++++++++++++++++ 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index ef8c7c54b..b06490a02 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -138,7 +138,7 @@ otError Ip6::AddTunneledMplOption(Message &aMessage, Header &aHeader, MessageInf messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(0x00fc); tunnelHeader.Init(); - tunnelHeader.SetHopLimit(static_cast(kDefaultHopLimit)); + tunnelHeader.SetHopLimit(kDefaultHopLimit); tunnelHeader.SetPayloadLength(aHeader.GetPayloadLength() + sizeof(tunnelHeader)); tunnelHeader.SetDestination(messageInfo.GetPeerAddr()); tunnelHeader.SetNextHeader(kProtoIp6); @@ -361,7 +361,7 @@ otError Ip6::SendDatagram(Message &aMessage, MessageInfo &aMessageInfo, IpProto header.Init(); header.SetPayloadLength(payloadLength); header.SetNextHeader(aIpProto); - header.SetHopLimit(aMessageInfo.mHopLimit ? aMessageInfo.mHopLimit : static_cast(kDefaultHopLimit)); + header.SetHopLimit(aMessageInfo.mHopLimit); if (aMessageInfo.GetSockAddr().IsUnspecified() || aMessageInfo.GetSockAddr().IsMulticast()) { diff --git a/src/core/net/ip6.hpp b/src/core/net/ip6.hpp index 2f0b7f052..a81c87341 100644 --- a/src/core/net/ip6.hpp +++ b/src/core/net/ip6.hpp @@ -103,8 +103,8 @@ class Ip6 : public InstanceLocator public: enum { - kDefaultHopLimit = 64, - kMaxDatagramLength = 1280, + kDefaultHopLimit = OPENTHREAD_CONFIG_IPV6_DEFAULT_HOP_LIMIT, + kMaxDatagramLength = OPENTHREAD_CONFIG_IPV6_DEFAULT_MAX_DATAGRAM, }; /** diff --git a/src/core/net/socket.hpp b/src/core/net/socket.hpp index 7f365ca6b..c7b93406e 100644 --- a/src/core/net/socket.hpp +++ b/src/core/net/socket.hpp @@ -59,7 +59,11 @@ public: * This constructor initializes the object. * */ - MessageInfo(void) { memset(this, 0, sizeof(*this)); } + MessageInfo(void) + { + memset(this, 0, sizeof(*this)); + mHopLimit = kDefaultHopLimit; + } /** * This method returns a reference to the local socket address. @@ -180,6 +184,12 @@ public: * */ void SetLinkInfo(const void *aLinkInfo) { mLinkInfo = aLinkInfo; } + +private: + enum + { + kDefaultHopLimit = OPENTHREAD_CONFIG_IPV6_DEFAULT_HOP_LIMIT, + }; }; /** diff --git a/src/core/openthread-core-default-config.h b/src/core/openthread-core-default-config.h index ab893c82d..9d04eba0d 100644 --- a/src/core/openthread-core-default-config.h +++ b/src/core/openthread-core-default-config.h @@ -1830,4 +1830,24 @@ #ifndef OPENTHREAD_CONFIG_DEFAULT_SED_DATAGRAM_COUNT #define OPENTHREAD_CONFIG_DEFAULT_SED_DATAGRAM_COUNT 1 #endif + +/** + * @def OPENTHREAD_CONFIG_IPV6_DEFAULT_HOP_LIMIT + * + * This setting configures the default hop limit of IPv6. + * + */ +#ifndef OPENTHREAD_CONFIG_IPV6_DEFAULT_HOP_LIMIT +#define OPENTHREAD_CONFIG_IPV6_DEFAULT_HOP_LIMIT 64 +#endif + +/** + * @def OPENTHREAD_CONFIG_IPV6_DEFAULT_MAX_DATAGRAM + * + * This setting configures the max datagram length of IPv6. + * + */ +#ifndef OPENTHREAD_CONFIG_IPV6_DEFAULT_MAX_DATAGRAM +#define OPENTHREAD_CONFIG_IPV6_DEFAULT_MAX_DATAGRAM 1280 +#endif #endif // OPENTHREAD_CORE_DEFAULT_CONFIG_H_