diff --git a/src/internet/model/rip.cc b/src/internet/model/rip.cc index a7c077455..3eaa28cf3 100644 --- a/src/internet/model/rip.cc +++ b/src/internet/model/rip.cc @@ -205,7 +205,7 @@ Ptr Rip::RouteOutput (Ptr p, const Ipv4Header &header, Ptr p, const Ipv4Header &header, Ptr rtentry = Lookup (header.GetDestination ()); + Ptr rtentry = Lookup (header.GetDestination (), false); if (rtentry != 0) { @@ -582,8 +582,7 @@ void Rip::DoDispose () Ipv4RoutingProtocol::DoDispose (); } - -Ptr Rip::Lookup (Ipv4Address dst, Ptr interface) +Ptr Rip::Lookup (Ipv4Address dst, bool setSource, Ptr interface) { NS_LOG_FUNCTION (this << dst << interface); @@ -633,13 +632,16 @@ Ptr Rip::Lookup (Ipv4Address dst, Ptr interface) uint32_t interfaceIdx = route->GetInterface (); rtentry = Create (); - 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 ()); diff --git a/src/internet/model/rip.h b/src/internet/model/rip.h index 30f555e2c..f526fe8ce 100644 --- a/src/internet/model/rip.h +++ b/src/internet/model/rip.h @@ -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 Lookup (Ipv4Address dest, Ptr = 0); + Ptr Lookup (Ipv4Address dest, bool setSource, Ptr = 0); /** * Receive and process unicast packet