From 888761561967892b991985d2f5407681977351d1 Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Fri, 19 Feb 2021 20:27:29 +0100 Subject: [PATCH] internet: fix valgrind errors in b5c4f68f --- src/internet/model/ipv4-static-routing.cc | 36 +++++++++++++---------- src/internet/model/ipv4-static-routing.h | 2 +- src/internet/model/ipv6-static-routing.cc | 33 +++++++++++---------- src/internet/model/ipv6-static-routing.h | 2 +- 4 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/internet/model/ipv4-static-routing.cc b/src/internet/model/ipv4-static-routing.cc index 41144c40d..a34736475 100644 --- a/src/internet/model/ipv4-static-routing.cc +++ b/src/internet/model/ipv4-static-routing.cc @@ -67,14 +67,16 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, uint32_t metric) { NS_LOG_FUNCTION (this << network << " " << networkMask << " " << nextHop << " " << interface << " " << metric); - Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry (); - *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network, - networkMask, - nextHop, - interface); + + Ipv4RoutingTableEntry route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network, + networkMask, + nextHop, + interface); + if (!LookupRoute (route, metric)) { - m_networkRoutes.push_back (make_pair (route,metric)); + Ipv4RoutingTableEntry *routePtr = new Ipv4RoutingTableEntry (route); + m_networkRoutes.push_back (make_pair (routePtr, metric)); } } @@ -85,13 +87,15 @@ Ipv4StaticRouting::AddNetworkRouteTo (Ipv4Address network, uint32_t metric) { NS_LOG_FUNCTION (this << network << " " << networkMask << " " << interface << " " << metric); - Ipv4RoutingTableEntry *route = new Ipv4RoutingTableEntry (); - *route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network, - networkMask, - interface); + + Ipv4RoutingTableEntry route = Ipv4RoutingTableEntry::CreateNetworkRouteTo (network, + networkMask, + interface); if (!LookupRoute (route, metric)) { - m_networkRoutes.push_back (make_pair (route,metric)); + Ipv4RoutingTableEntry *routePtr = new Ipv4RoutingTableEntry (route); + + m_networkRoutes.push_back (make_pair (routePtr, metric)); } } @@ -226,16 +230,16 @@ Ipv4StaticRouting::RemoveMulticastRoute (uint32_t index) } bool -Ipv4StaticRouting::LookupRoute (Ipv4RoutingTableEntry *route, uint32_t metric) +Ipv4StaticRouting::LookupRoute (const Ipv4RoutingTableEntry &route, uint32_t metric) { for (NetworkRoutesI j = m_networkRoutes.begin (); j != m_networkRoutes.end (); j++) { Ipv4RoutingTableEntry* rtentry = j->first; - if (rtentry->GetDest () == route->GetDest () && - rtentry->GetDestNetworkMask () == route->GetDestNetworkMask () && - rtentry->GetGateway () == route->GetGateway () && - rtentry->GetInterface () == route->GetInterface () && + if (rtentry->GetDest () == route.GetDest () && + rtentry->GetDestNetworkMask () == route.GetDestNetworkMask () && + rtentry->GetGateway () == route.GetGateway () && + rtentry->GetInterface () == route.GetInterface () && j->second == metric) { return true; diff --git a/src/internet/model/ipv4-static-routing.h b/src/internet/model/ipv4-static-routing.h index 472878a8c..66322af64 100644 --- a/src/internet/model/ipv4-static-routing.h +++ b/src/internet/model/ipv4-static-routing.h @@ -382,7 +382,7 @@ private: * \param metric metric of route * \return true if the route/metric is already in the forwarding table */ - bool LookupRoute (Ipv4RoutingTableEntry *route, uint32_t metric); + bool LookupRoute (const Ipv4RoutingTableEntry &route, uint32_t metric); /** * \brief Lookup in the forwarding table for destination. diff --git a/src/internet/model/ipv6-static-routing.cc b/src/internet/model/ipv6-static-routing.cc index 3004162b7..4a068c550 100644 --- a/src/internet/model/ipv6-static-routing.cc +++ b/src/internet/model/ipv6-static-routing.cc @@ -149,11 +149,13 @@ void Ipv6StaticRouting::AddHostRouteTo (Ipv6Address dst, uint32_t interface, uin void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, Ipv6Address nextHop, uint32_t interface, uint32_t metric) { NS_LOG_FUNCTION (this << network << networkPrefix << nextHop << interface << metric); - Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry (); - *route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, nextHop, interface); + + Ipv6RoutingTableEntry route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, nextHop, interface); + if (!LookupRoute (route, metric)) { - m_networkRoutes.push_back (std::make_pair (route, metric)); + Ipv6RoutingTableEntry* routePtr = new Ipv6RoutingTableEntry (route); + m_networkRoutes.push_back (std::make_pair (routePtr, metric)); } } @@ -165,22 +167,23 @@ void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix netwo NS_LOG_WARN ("Ipv6StaticRouting::AddNetworkRouteTo - Next hop should be link-local"); } - Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry (); - *route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, nextHop, interface, prefixToUse); + Ipv6RoutingTableEntry route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, nextHop, interface, prefixToUse); if (!LookupRoute (route, metric)) { - m_networkRoutes.push_back (std::make_pair (route, metric)); + Ipv6RoutingTableEntry* routePtr = new Ipv6RoutingTableEntry (route); + m_networkRoutes.push_back (std::make_pair (routePtr, metric)); } } void Ipv6StaticRouting::AddNetworkRouteTo (Ipv6Address network, Ipv6Prefix networkPrefix, uint32_t interface, uint32_t metric) { NS_LOG_FUNCTION (this << network << networkPrefix << interface); - Ipv6RoutingTableEntry* route = new Ipv6RoutingTableEntry (); - *route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, interface); + + Ipv6RoutingTableEntry route = Ipv6RoutingTableEntry::CreateNetworkRouteTo (network, networkPrefix, interface); if (!LookupRoute (route, metric)) { - m_networkRoutes.push_back (std::make_pair (route, metric)); + Ipv6RoutingTableEntry* routePtr = new Ipv6RoutingTableEntry (route); + m_networkRoutes.push_back (std::make_pair (routePtr, metric)); } } @@ -290,17 +293,17 @@ bool Ipv6StaticRouting::HasNetworkDest (Ipv6Address network, uint32_t interfaceI return false; } -bool Ipv6StaticRouting::LookupRoute (Ipv6RoutingTableEntry *route, uint32_t metric) +bool Ipv6StaticRouting::LookupRoute (const Ipv6RoutingTableEntry &route, uint32_t metric) { for (NetworkRoutesI j = m_networkRoutes.begin (); j != m_networkRoutes.end (); j++) { Ipv6RoutingTableEntry* rtentry = j->first; - if (rtentry->GetDest () == route->GetDest () && - rtentry->GetDestNetworkPrefix () == route->GetDestNetworkPrefix () && - rtentry->GetGateway () == route->GetGateway () && - rtentry->GetInterface () == route->GetInterface () && - rtentry->GetPrefixToUse () == route->GetPrefixToUse () && + if (rtentry->GetDest () == route.GetDest () && + rtentry->GetDestNetworkPrefix () == route.GetDestNetworkPrefix () && + rtentry->GetGateway () == route.GetGateway () && + rtentry->GetInterface () == route.GetInterface () && + rtentry->GetPrefixToUse () == route.GetPrefixToUse () && j->second == metric) { return true; diff --git a/src/internet/model/ipv6-static-routing.h b/src/internet/model/ipv6-static-routing.h index 3f341747f..822b9ad0e 100644 --- a/src/internet/model/ipv6-static-routing.h +++ b/src/internet/model/ipv6-static-routing.h @@ -270,7 +270,7 @@ private: * \param metric metric of route * \return true if the route/metric is already in the forwarding table */ - bool LookupRoute (Ipv6RoutingTableEntry *route, uint32_t metric); + bool LookupRoute (const Ipv6RoutingTableEntry &route, uint32_t metric); /** * \brief Lookup in the forwarding table for destination.