mirror of
https://github.com/espressif/openthread.git
synced 2026-10-02 05:47:40 +00:00
Filter out ICMP Echo Requests when ICMP offload is enabled. (#447)
This commit is contained in:
@@ -412,7 +412,7 @@ int Message::Write(uint16_t aOffset, uint16_t aLength, const void *aBuf)
|
|||||||
return bytesCopied;
|
return bytesCopied;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Message::CopyTo(uint16_t aSourceOffset, uint16_t aDestinationOffset, uint16_t aLength, Message &aMessage)
|
int Message::CopyTo(uint16_t aSourceOffset, uint16_t aDestinationOffset, uint16_t aLength, Message &aMessage) const
|
||||||
{
|
{
|
||||||
uint16_t bytesCopied = 0;
|
uint16_t bytesCopied = 0;
|
||||||
uint16_t bytesToCopy;
|
uint16_t bytesToCopy;
|
||||||
|
|||||||
@@ -338,7 +338,7 @@ public:
|
|||||||
* @returns The number of bytes copied.
|
* @returns The number of bytes copied.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int CopyTo(uint16_t aSourceOffset, uint16_t aDestinationOffset, uint16_t aLength, Message &aMessage);
|
int CopyTo(uint16_t aSourceOffset, uint16_t aDestinationOffset, uint16_t aLength, Message &aMessage) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the datagram tag used for 6LoWPAN fragmentation.
|
* This method returns the datagram tag used for 6LoWPAN fragmentation.
|
||||||
|
|||||||
+30
-11
@@ -334,7 +334,7 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ip6::ProcessReceiveCallback(Message &aMessage)
|
void Ip6::ProcessReceiveCallback(const Message &aMessage, const MessageInfo &messageInfo, uint8_t aIpProto)
|
||||||
{
|
{
|
||||||
ThreadError error = kThreadError_None;
|
ThreadError error = kThreadError_None;
|
||||||
Message *messageCopy = NULL;
|
Message *messageCopy = NULL;
|
||||||
@@ -343,19 +343,38 @@ void Ip6::ProcessReceiveCallback(Message &aMessage)
|
|||||||
|
|
||||||
if (sIsReceiveIp6FilterEnabled)
|
if (sIsReceiveIp6FilterEnabled)
|
||||||
{
|
{
|
||||||
Header ip6;
|
|
||||||
aMessage.Read(0, sizeof(ip6), &ip6);
|
|
||||||
|
|
||||||
// do not pass messages sent to/from an RLOC
|
// do not pass messages sent to/from an RLOC
|
||||||
VerifyOrExit(!ip6.GetSource().IsRoutingLocator() && !ip6.GetDestination().IsRoutingLocator(), ;);
|
VerifyOrExit(!messageInfo.GetSockAddr().IsRoutingLocator() &&
|
||||||
|
!messageInfo.GetPeerAddr().IsRoutingLocator(), ;);
|
||||||
|
|
||||||
if (ip6.GetSource().IsLinkLocal() && ip6.GetNextHeader() == kProtoUdp)
|
switch (aIpProto)
|
||||||
{
|
{
|
||||||
UdpHeader udp;
|
case kProtoIcmp6:
|
||||||
aMessage.Read(sizeof(ip6), sizeof(udp), &udp);
|
if (Icmp::IsEchoEnabled())
|
||||||
|
{
|
||||||
|
IcmpHeader icmp;
|
||||||
|
aMessage.Read(aMessage.GetOffset(), sizeof(icmp), &icmp);
|
||||||
|
|
||||||
// do not pass MLE messages
|
// do not pass ICMP Echo Request messages
|
||||||
VerifyOrExit(udp.GetDestinationPort() != Mle::kUdpPort, ;);
|
VerifyOrExit(icmp.GetType() != IcmpHeader::kTypeEchoRequest, ;);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case kProtoUdp:
|
||||||
|
if (messageInfo.GetSockAddr().IsLinkLocal())
|
||||||
|
{
|
||||||
|
UdpHeader udp;
|
||||||
|
aMessage.Read(aMessage.GetOffset(), sizeof(udp), &udp);
|
||||||
|
|
||||||
|
// do not pass MLE messages
|
||||||
|
VerifyOrExit(udp.GetDestinationPort() != Mle::kUdpPort, ;);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,7 +479,7 @@ ThreadError Ip6::HandleDatagram(Message &message, Netif *netif, int8_t interface
|
|||||||
{
|
{
|
||||||
if (fromLocalHost == false)
|
if (fromLocalHost == false)
|
||||||
{
|
{
|
||||||
ProcessReceiveCallback(message);
|
ProcessReceiveCallback(message, messageInfo, nextHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
SuccessOrExit(error = HandlePayload(message, messageInfo, nextHeader));
|
SuccessOrExit(error = HandlePayload(message, messageInfo, nextHeader));
|
||||||
|
|||||||
@@ -623,7 +623,7 @@ public:
|
|||||||
static void SetForwardingEnabled(bool aEnable);
|
static void SetForwardingEnabled(bool aEnable);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void ProcessReceiveCallback(Message &aMessage);
|
static void ProcessReceiveCallback(const Message &aMessage, const MessageInfo &aMessageInfo, uint8_t aIpProto);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user