internet: Align RIPng and RIP implementations

This commit is contained in:
Tommaso Pecorella
2021-10-10 00:54:21 +02:00
parent db1fa07947
commit b7ddd9d3f5
2 changed files with 14 additions and 11 deletions

View File

@@ -205,7 +205,7 @@ Ptr<Ipv4Route> Rip::RouteOutput (Ptr<Packet> p, const Ipv4Header &header, Ptr<Ne
NS_LOG_LOGIC ("RouteOutput (): Multicast destination");
}
rtentry = Lookup (destination, oif);
rtentry = Lookup (destination, true, oif);
if (rtentry)
{
sockerr = Socket::ERROR_NOTERROR;
@@ -276,7 +276,7 @@ bool Rip::RouteInput (Ptr<const Packet> p, const Ipv4Header &header, Ptr<const N
}
// Next, try to find a route
NS_LOG_LOGIC ("Unicast destination");
Ptr<Ipv4Route> rtentry = Lookup (header.GetDestination ());
Ptr<Ipv4Route> rtentry = Lookup (header.GetDestination (), false);
if (rtentry != 0)
{
@@ -582,8 +582,7 @@ void Rip::DoDispose ()
Ipv4RoutingProtocol::DoDispose ();
}
Ptr<Ipv4Route> Rip::Lookup (Ipv4Address dst, Ptr<NetDevice> interface)
Ptr<Ipv4Route> Rip::Lookup (Ipv4Address dst, bool setSource, Ptr<NetDevice> interface)
{
NS_LOG_FUNCTION (this << dst << interface);
@@ -633,13 +632,16 @@ Ptr<Ipv4Route> Rip::Lookup (Ipv4Address dst, Ptr<NetDevice> interface)
uint32_t interfaceIdx = route->GetInterface ();
rtentry = Create<Ipv4Route> ();
if (route->GetDest ().IsAny ()) /* default route */
if (setSource)
{
rtentry->SetSource (m_ipv4->SourceAddressSelection (interfaceIdx, route->GetGateway ()));
}
else
{
rtentry->SetSource (m_ipv4->SourceAddressSelection (interfaceIdx, route->GetDest ()));
if (route->GetDest ().IsAny ()) /* default route */
{
rtentry->SetSource (m_ipv4->SourceAddressSelection (interfaceIdx, route->GetGateway ()));
}
else
{
rtentry->SetSource (m_ipv4->SourceAddressSelection (interfaceIdx, route->GetDest ()));
}
}
rtentry->SetDestination (route->GetDest ());

View File

@@ -305,10 +305,11 @@ private:
/**
* \brief Lookup in the forwarding table for destination.
* \param dest destination address
* \param setSource set source address in the route
* \param interface output interface if any (put 0 otherwise)
* \return Ipv4Route to route the packet to reach dest address
*/
Ptr<Ipv4Route> Lookup (Ipv4Address dest, Ptr<NetDevice> = 0);
Ptr<Ipv4Route> Lookup (Ipv4Address dest, bool setSource, Ptr<NetDevice> = 0);
/**
* Receive and process unicast packet