Bug 862 - NotifyInterfaceUp() Adds network route even when netmask is /32
NotifyInterfaceUp() Adds network route even when netmask is /32
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: routing
pre-release
All All
: P3 normal
Assigned To: Tom Henderson
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-04-06 04:45 UTC by Antti Mäkelä
Modified: 2010-04-16 19:05 UTC (History)
2 users (show)

See Also:


Attachments
Patch to fix the issue in static routing (1.06 KB, patch)
2010-04-06 04:59 UTC, Antti Mäkelä
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Mäkelä 2010-04-06 04:45:17 UTC
When configuring an interface with netmask of /32, (using with VirtualNetDevice and tunnels), and Ptr<Ipv4>->Setup(i) is called, this, in turn calls NotifyInterfaceUp() of all routing protocols.

In e.g. 

void
Ipv4StaticRouting::NotifyInterfaceUp (uint32_t i)
{
  NS_LOG_FUNCTION (this << i);
  // If interface address and network mask have been set, add a route
  // to the network of the interface (like e.g. ifconfig does on a
  // Linux box)
  for (uint32_t j = 0; j < m_ipv4->GetNAddresses (i); j++)
    {
      if (m_ipv4->GetAddress (i,j).GetLocal () != Ipv4Address () &&
          m_ipv4->GetAddress (i,j).GetMask () != Ipv4Mask ())
        {
          AddNetworkRouteTo (m_ipv4->GetAddress (i,j).GetLocal ().CombineMask (m
_ipv4->GetAddress (i,j).GetMask ()),
                             m_ipv4->GetAddress (i,j).GetMask (), i);
        }
    }
}

the network is added even when the mask is /32. This leads to same entry being in routing table twice (both the if-addr and as "network", even if the "network" size is /32!). 

Even in Linux, if you add an ip address with mask of 255.255.255.255, nothing gets added to routing table.

Proposed line to add:

if (m_ipv4->GetAddress (i,j).GetMask()==Ipv4Mask::GetOnes()) 
  { 
    return; 
  }

However, not submitting a patch yet - should this be added to ALL routing protocols, or perhaps just list-routing?

In Linux (just a quick test with my wireless interface that I'm not using right now, also omitting lines pertaining to my wired Internet connection). 

# ifconfig wlan up
# ifconfig wlan 4.4.4.4 netmask 255.255.255.255
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
# ifconfig wlan 4.4.4.4 netmask 255.255.255.0
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
4.4.4.0         0.0.0.0         255.255.255.0   U     0      0        0 wlan
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
Comment 1 Antti Mäkelä 2010-04-06 04:59:45 UTC
Created attachment 809 [details]
Patch to fix the issue in static routing

Well, here's an example how I fixed it with ipv4-static-routing.cc.
Comment 2 Tom Henderson 2010-04-06 08:43:22 UTC
> 
> However, not submitting a patch yet - should this be added to ALL routing
> protocols, or perhaps just list-routing?

I agree with the patch.  I believe that only Ipv4StaticRouting implements this type of behavior, since it is the only object that holds static or connected routes, so I would suggest that with our routing framework, it should just go to Ipv4StaticRouting.  If another standalone (i.e. for use outside of list routing context) routing protocol wants to provide connected routes, it should also implement it.  I think that only AODV right now is designed with this use in mind, and in that case, you probably don't want the connected routes anyway.
Comment 3 Tom Henderson 2010-04-07 11:15:33 UTC
I plan to push this during the current maintenance window if there are no other comments.
Comment 4 Tom Henderson 2010-04-16 19:05:49 UTC
changeset: 22d9d9d3c563