Auf Branch develop
zum Commit vorgemerkte Änderungen: geändert: src/AbstractRouter.h neue Datei: src/ArpToNdpPacketHandler.cpp neue Datei: src/ArpToNdpPacketHandler.h neue Datei: src/INetworkInterfaceCard_t.h neue Datei: src/Ip4Packet_t.h geändert: src/Ip6Packet_t.h neue Datei: src/IpVersionRouter.cpp neue Datei: src/IpVersionRouter.h
This commit is contained in:
92
src/ArpToNdpPacketHandler.cpp
Normal file
92
src/ArpToNdpPacketHandler.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "ArpToNdpPacketHandler.h"
|
||||
#include <tins/ethernetII.h>
|
||||
#include <tins/arp.h>
|
||||
#include <tins/icmpv6.h>
|
||||
#include <tins/ipv6.h>
|
||||
#include <tins/ip_address.h>
|
||||
#include <tins/ipv6_address.h>
|
||||
#include "IpAddressTranslator.h"
|
||||
|
||||
ArpToNdpPacketHandler::ArpToNdpPacketHandler(const Tins::IPv6Address & newPrefix)
|
||||
{
|
||||
prefix = std::make_unique<Tins::IPv6Address>(newPrefix);
|
||||
ndpPrefix = std::make_unique<Tins::IPv6Address>("FF02:0:0:0:0:1:FF");
|
||||
ndpMask = std::make_unique<Tins::IPv4Address>("255.0.0.0");
|
||||
}
|
||||
|
||||
ArpToNdpPacketHandler::~ArpToNdpPacketHandler()
|
||||
{
|
||||
}
|
||||
|
||||
bool ArpToNdpPacketHandler::handle(IN const Tins::PDU & pdu, IN IPacketHandler * callBackHandler)
|
||||
{
|
||||
// callback handvet requeried
|
||||
if (callBackHandler == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// get ipv4 packet
|
||||
const Tins::ARP * arpPdu = pdu.find_pdu<Tins::ARP>();
|
||||
if(arpPdu == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// convert ipv4 addresses to ipv6 addresses
|
||||
uint32_t ndpMaskField = *ndpMask;
|
||||
uint32_t targetMaskield = arpPdu->target_ip_addr();
|
||||
uint32_t foo = ndpMaskField | targetMaskield;
|
||||
UPtrIPv6Address srcIp6Address = std::make_unique<Tins::IPv6Address>(*prefix);
|
||||
UPtrIPv6Address dstIp6Address = std::make_unique<Tins::IPv6Address>(*ndpPrefix);
|
||||
UPtrIPv6Address targetIp6Address = std::make_unique<Tins::IPv6Address>(*prefix);
|
||||
IpAddressTranslator::toIpv6Address(arpPdu->sender_ip_addr(), *srcIp6Address);
|
||||
IpAddressTranslator::toIpv6Address(Tins::IPv4Address(foo), *dstIp6Address);
|
||||
|
||||
// create ip4 pdu
|
||||
std::unique_ptr<const Tins::IPv6> ipv6Pdu = std::make_unique<const Tins::IPv6>(*dstIp6Address,*srcIp6Address);
|
||||
std::unique_ptr<Tins::ICMPv6> ndpPdu;
|
||||
|
||||
switch (arpPdu->opcode())
|
||||
{
|
||||
case Tins::ARP::REQUEST:
|
||||
ndpPdu = std::make_unique<Tins::ICMPv6>(Tins::ICMPv6::NEIGHBOUR_SOLICIT);
|
||||
break;
|
||||
case Tins::ARP::REPLY:
|
||||
ndpPdu = std::make_unique<Tins::ICMPv6>(Tins::ICMPv6::NEIGHBOUR_ADVERT);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
ndpPdu->target_addr(*targetIp6Address);
|
||||
// create forwarding frame
|
||||
std::unique_ptr<Tins::EthernetII> ptrForwardEthPdu = std::make_unique<Tins::EthernetII>();
|
||||
Tins::EthernetII & forwardEthPdu = *ptrForwardEthPdu;
|
||||
|
||||
// copy src and dst mac address
|
||||
const Tins::EthernetII * ethPdu = pdu.find_pdu<Tins::EthernetII>();
|
||||
if(ethPdu != nullptr)
|
||||
{
|
||||
// @todo to set multicast
|
||||
forwardEthPdu.src_addr(ethPdu->src_addr());
|
||||
forwardEthPdu.dst_addr(ethPdu->dst_addr());
|
||||
}
|
||||
|
||||
forwardEthPdu /= *ipv6Pdu;
|
||||
forwardEthPdu /= *ndpPdu;
|
||||
|
||||
|
||||
// forward frame
|
||||
return callBackHandler->handle(forwardEthPdu, this);
|
||||
}
|
||||
|
||||
const Tins::IPv6Address & ArpToNdpPacketHandler::getPrefix() const
|
||||
{
|
||||
return *prefix;
|
||||
}
|
||||
|
||||
void ArpToNdpPacketHandler::setPrefix(const Tins::IPv6Address & newPrefix)
|
||||
{
|
||||
*prefix = newPrefix;
|
||||
}
|
||||
Reference in New Issue
Block a user