[ip6] allow hoplimit 0 (#4370)

This commit is contained in:
Rongli Sun
2019-12-10 08:51:26 -08:00
committed by Jonathan Hui
parent 3244d7a644
commit b77c244290
3 changed files with 28 additions and 8 deletions
+10 -7
View File
@@ -139,13 +139,16 @@ typedef struct otSockAddr
*/
typedef struct otMessageInfo
{
otIp6Address mSockAddr; ///< The local IPv6 address.
otIp6Address mPeerAddr; ///< The peer IPv6 address.
uint16_t mSockPort; ///< The local transport-layer port.
uint16_t mPeerPort; ///< The peer transport-layer port.
const void * mLinkInfo; ///< A pointer to link-specific information.
uint8_t mHopLimit; ///< The IPv6 hop limit.
bool mIsHostInterface : 1; ///< TRUE if packets sent/received via host interface, FALSE otherwise.
otIp6Address mSockAddr; ///< The local IPv6 address.
otIp6Address mPeerAddr; ///< The peer IPv6 address.
uint16_t mSockPort; ///< The local transport-layer port.
uint16_t mPeerPort; ///< The peer transport-layer port.
const void * mLinkInfo; ///< A pointer to link-specific information.
uint8_t mHopLimit; ///< The IPv6 Hop Limit value. Only applies if `mAllowZeroHopLimit` is FALSE.
///< If `0`, IPv6 Hop Limit is default value `OPENTHREAD_CONFIG_IP6_HOP_LIMIT_DEFAULT`.
///< Otherwise, specifies the IPv6 Hop Limit.
bool mIsHostInterface : 1; ///< TRUE if packets sent/received via host interface, FALSE otherwise.
bool mAllowZeroHopLimit : 1; ///< TRUE to allow IPv6 Hop Limit 0 in `mHopLimit`, FALSE otherwise.
} otMessageInfo;
/**
+9 -1
View File
@@ -460,7 +460,15 @@ otError Ip6::SendDatagram(Message &aMessage, MessageInfo &aMessageInfo, IpProto
header.SetDscp(PriorityToDscp(aMessage.GetPriority()));
header.SetPayloadLength(payloadLength);
header.SetNextHeader(aIpProto);
header.SetHopLimit(aMessageInfo.mHopLimit ? aMessageInfo.mHopLimit : static_cast<uint8_t>(kDefaultHopLimit));
if (aMessageInfo.GetHopLimit() != 0 || aMessageInfo.ShouldAllowZeroHopLimit())
{
header.SetHopLimit(aMessageInfo.GetHopLimit());
}
else
{
header.SetHopLimit(static_cast<uint8_t>(kDefaultHopLimit));
}
if (aMessageInfo.GetSockAddr().IsUnspecified() || aMessageInfo.GetSockAddr().IsMulticast())
{
+9
View File
@@ -182,6 +182,15 @@ public:
*/
bool IsHostInterface(void) const { return mIsHostInterface; }
/**
* This method indicates whether or not to apply hop limit 0.
*
* @retval TRUE if applying hop limit 0 when `mHopLimit` field is 0.
* @retval FALSE if applying default `OPENTHREAD_CONFIG_IP6_HOP_LIMIT_DEFAULT` when `mHopLimit` field is 0.
*
*/
bool ShouldAllowZeroHopLimit(void) const { return mAllowZeroHopLimit; }
/**
* This method sets whether the peer is via the host interface.
*