internet: fix valgrind errors in b5c4f68f

This commit is contained in:
Tommaso Pecorella
2021-02-19 20:27:29 +01:00
parent b5c4f68f97
commit 8887615619
4 changed files with 40 additions and 33 deletions

View File

@@ -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;

View File

@@ -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.

View File

@@ -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;

View File

@@ -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.