Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IPv6] [FIX] Send packet to correct MAC address instead of sending it to the MAC broadcast address #1007

Closed
Closed
12 changes: 9 additions & 3 deletions src/inet/networklayer/icmpv6/Ipv6NeighbourDiscovery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,13 @@ void Ipv6NeighbourDiscovery::reachabilityConfirmed(const Ipv6Address& neighbour,

cMessage *msg = nce->nudTimeoutEvent;
if (msg != nullptr) {
EV_INFO << "NUD in progress. Cancelling NUD Timer\n";
bubble("Reachability Confirmed via NUD.");
EV_INFO << "NUD in progress. Cancelling NUD Timer because TCP ACK received from neighbour.\n";
bubble("Reachability Confirmed via NUD. Received TCP ACK.");
cancelAndDelete(msg);
nce->nudTimeoutEvent = nullptr;
EV_INFO << "Set Neighbour Cache Entry state to REACHABLE\n";
nce->reachabilityExpires = simTime() + ift->getInterfaceById(interfaceId)->getProtocolData<Ipv6InterfaceData>()->_getReachableTime();
nce->reachabilityState = Ipv6NeighbourCache::REACHABLE;
}

// TODO (see header file for description)
Expand Down Expand Up @@ -479,7 +482,7 @@ void Ipv6NeighbourDiscovery::initiateNeighbourUnreachabilityDetection(Neighbour
ASSERT(nce->reachabilityState == Ipv6NeighbourCache::STALE);
ASSERT(nce->nudTimeoutEvent == nullptr);
const Key *nceKey = nce->nceKey;
EV_INFO << "Initiating Neighbour Unreachability Detection";
EV_INFO << "Initiating Neighbour Unreachability Detection.\n";
NetworkInterface *ie = ift->getInterfaceById(nceKey->interfaceID);
EV_INFO << "Setting NCE state to DELAY.\n";
/*The first time a node sends a packet to a neighbor whose entry is
Expand Down Expand Up @@ -2091,6 +2094,9 @@ void Ipv6NeighbourDiscovery::sendSolicitedNa(Packet *packet, const Ipv6Neighbour
auto naPacket = new Packet("NApacket");
Icmpv6::insertCrc(crcMode, na, packet);
naPacket->insertAtFront(na);

EV_INFO << "Sending solicited NA to " << naDestAddr << "\n";

sendPacketToIpv6Module(naPacket, naDestAddr, myIPv6Addr, ie->getInterfaceId());
}

Expand Down
30 changes: 28 additions & 2 deletions src/inet/networklayer/ipv6/Ipv6.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,34 @@ void Ipv6::datagramLocalOut(Packet *packet, const NetworkInterface *destIE, Ipv6
{
const auto& ipv6Header = packet->peekAtFront<Ipv6Header>();
// route packet
if (destIE != nullptr)
fragmentPostRouting(packet, destIE, MacAddress::BROADCAST_ADDRESS, true); // FIXME what MAC address to use?
if (destIE != nullptr) {
Ipv6Address destAddress = ipv6Header->getDestAddress();
MacAddress macAddr = MacAddress::UNSPECIFIED_ADDRESS;
if (!destAddress.isMulticast()) {
EV_INFO << "next hop for " << destAddress << " is " << requestedNextHopAddress << ", interface " << destIE->getInterfaceName() << "\n";

macAddr = nd->resolveNeighbour(requestedNextHopAddress, destIE->getInterfaceId()); // might initiate NUD
if (macAddr.isUnspecified()) {
if (!destIE->isPointToPoint()) {
EV_INFO << "no link-layer address for next hop yet, passing datagram to Neighbour Discovery module\n";
Ipv6NdControlInfo *ctrl = new Ipv6NdControlInfo();
ctrl->setFromHL(true);
ctrl->setNextHop(requestedNextHopAddress);
ctrl->setInterfaceId(destIE->getInterfaceId());
packet->cMessage::setControlInfo(ctrl);
send(packet, "ndOut");
return;
}
}
else
EV_DETAIL << "link-layer address: " << macAddr << "\n";
}
else
macAddr = ipv6Header->getDestAddress().mapToMulticastMacAddress();

// send out datagram
fragmentPostRouting(packet, destIE, macAddr, true);
}
else if (!ipv6Header->getDestAddress().isMulticast())
routePacket(packet, destIE, nullptr, requestedNextHopAddress, true);
else
Expand Down
12 changes: 12 additions & 0 deletions src/inet/transportlayer/tcp/TcpConnectionBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include "inet/transportlayer/tcp/TcpSackRexmitQueue.h"
#include "inet/transportlayer/tcp/TcpSendQueue.h"
#include "inet/transportlayer/tcp_common/TcpHeader.h"
#ifdef INET_WITH_IPv6
#include "inet/linklayer/common/InterfaceTag_m.h"
#include "inet/networklayer/icmpv6/Ipv6NeighbourDiscovery.h"
#endif

namespace inet {
namespace tcp {
Expand Down Expand Up @@ -206,6 +210,14 @@ bool TcpConnection::processTCPSegment(Packet *tcpSegment, const Ptr<const TcpHea
// first do actions
TcpEventCode event = process_RCV_SEGMENT(tcpSegment, tcpHeader, segSrcAddr, segDestAddr);

#ifdef INET_WITH_IPv6
if(event == TCP_E_RCV_ACK || event == TCP_E_RCV_SYN_ACK) {
auto nd = dynamic_cast<Ipv6NeighbourDiscovery *>(findModuleByPath("^.^.ipv6.neighbourDiscovery"));
if(nd !=nullptr)
nd->reachabilityConfirmed(segSrcAddr.toIpv6(), tcpSegment->getTag<InterfaceInd>()->getInterfaceId());
}
#endif

// then state transitions
return performStateTransition(event);
}
Expand Down
Loading