add tests for icmp handler
This commit is contained in:
@@ -29,15 +29,18 @@ bool Icmp4ToIcmp6PacketHandler::handle(IN const Tins::PDU & pdu, IN IPacketHandl
|
||||
// create icmp6 pdu
|
||||
const Tins::ICMP::Flags type = icmpv4Pdu->type();
|
||||
std::unique_ptr<Tins::ICMPv6> icmpv6Pdu;
|
||||
switch (type) {
|
||||
case Tins::ICMP::Flags::ECHO_REPLY:
|
||||
icmpv6Pdu = std::make_unique<Tins::ICMPv6>(Tins::ICMPv6::ECHO_REQUEST);
|
||||
break;
|
||||
case Tins::ICMP::Flags::ECHO_REQUEST:
|
||||
icmpv6Pdu = std::make_unique<Tins::ICMPv6>(Tins::ICMPv6::ECHO_REPLY);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
switch (type)
|
||||
{
|
||||
case Tins::ICMP::Flags::ECHO_REPLY:
|
||||
icmpv6Pdu = std::make_unique<Tins::ICMPv6>(Tins::ICMPv6::ECHO_REPLY);
|
||||
break;
|
||||
|
||||
case Tins::ICMP::Flags::ECHO_REQUEST:
|
||||
icmpv6Pdu = std::make_unique<Tins::ICMPv6>(Tins::ICMPv6::ECHO_REQUEST);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
icmpv6Pdu->identifier(icmpv4Pdu->id());
|
||||
@@ -45,13 +48,13 @@ bool Icmp4ToIcmp6PacketHandler::handle(IN const Tins::PDU & pdu, IN IPacketHandl
|
||||
icmpv6Pdu->code(0);
|
||||
|
||||
// replace icmp4 with icmp6 content, adress translation will bo den by Ip4ToIp6PacketHandler
|
||||
const Tins::IP * ipPdu = pdu.find_pdu<Tins::IP>();
|
||||
Tins::PDU * clonePdu = pdu.clone();
|
||||
Tins::IP * ipPdu = clonePdu->find_pdu<Tins::IP>();
|
||||
if(ipPdu == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Tins::IP * cloneIpPdu = ipPdu->clone();
|
||||
cloneIpPdu->inner_pdu(*icmpv6Pdu);
|
||||
return Ip4ToIp6PacketHandler::handle(*cloneIpPdu, callBackHandler);
|
||||
ipPdu->inner_pdu(*icmpv6Pdu);
|
||||
return Ip4ToIp6PacketHandler::handle(*clonePdu, callBackHandler);
|
||||
}
|
||||
|
||||
@@ -31,18 +31,22 @@ bool Icmp6ToIcmp4PacketHandler::handle(IN const Tins::PDU & pdu, IN IPacketHandl
|
||||
// create icmp6 pdu
|
||||
const Tins::ICMPv6::Types type = icmpv6Pdu->type();
|
||||
std::unique_ptr<Tins::ICMP> icmpv4Pdu;
|
||||
switch (type) {
|
||||
case Tins::ICMPv6::ECHO_REPLY:
|
||||
icmpv4Pdu = std::make_unique<Tins::ICMP>(Tins::ICMP::Flags::ECHO_REQUEST);
|
||||
break;
|
||||
case Tins::ICMPv6::ECHO_REQUEST:
|
||||
icmpv4Pdu = std::make_unique<Tins::ICMP>(Tins::ICMP::Flags::ECHO_REPLY);
|
||||
break;
|
||||
case Tins::ICMPv6::NEIGHBOUR_SOLICIT:
|
||||
case Tins::ICMPv6::NEIGHBOUR_ADVERT:
|
||||
return ndpToArpHandler->handle(pdu, callBackHandler);
|
||||
default:
|
||||
return false;
|
||||
switch (type)
|
||||
{
|
||||
case Tins::ICMPv6::ECHO_REPLY:
|
||||
icmpv4Pdu = std::make_unique<Tins::ICMP>(Tins::ICMP::Flags::ECHO_REPLY);
|
||||
break;
|
||||
|
||||
case Tins::ICMPv6::ECHO_REQUEST:
|
||||
icmpv4Pdu = std::make_unique<Tins::ICMP>(Tins::ICMP::Flags::ECHO_REQUEST);
|
||||
break;
|
||||
|
||||
case Tins::ICMPv6::NEIGHBOUR_SOLICIT:
|
||||
case Tins::ICMPv6::NEIGHBOUR_ADVERT:
|
||||
return ndpToArpHandler->handle(pdu, callBackHandler);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
icmpv4Pdu->id(icmpv6Pdu->identifier());
|
||||
@@ -50,13 +54,13 @@ bool Icmp6ToIcmp4PacketHandler::handle(IN const Tins::PDU & pdu, IN IPacketHandl
|
||||
icmpv4Pdu->code(0);
|
||||
|
||||
// replace icmp4 with icmp6 content, adress translation will bo den by Ip4ToIp6PacketHandler
|
||||
const Tins::IPv6 * ipv6Pdu = pdu.find_pdu<Tins::IPv6>();
|
||||
Tins::PDU * clonePdu = pdu.clone();
|
||||
Tins::IPv6 * ipv6Pdu = clonePdu->find_pdu<Tins::IPv6>();
|
||||
if(ipv6Pdu == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Tins::IPv6 * cloneIpv6Pdu = ipv6Pdu->clone();
|
||||
cloneIpv6Pdu->inner_pdu(*icmpv4Pdu);
|
||||
return Ip6ToIp4PacketHandler::handle(*cloneIpv6Pdu, callBackHandler);
|
||||
ipv6Pdu->inner_pdu(*icmpv4Pdu);
|
||||
return Ip6ToIp4PacketHandler::handle(*clonePdu, callBackHandler);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user