--- a/src/internet-node/ipv4-l3-protocol.cc Thu Jun 14 13:09:56 2007 +0100 +++ a/src/internet-node/ipv4-l3-protocol.cc Fri Jun 15 14:25:26 2007 +0100 @@ -551,12 +568,39 @@ Ipv4L3Protocol::SetUp (uint32_t i) { Ipv4Interface *interface = GetInterface (i); interface->SetUp (); -} -void -Ipv4L3Protocol::SetDown (uint32_t i) -{ - Ipv4Interface *interface = GetInterface (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) + if ((interface->GetAddress ()) != (Ipv4Address ()) + && (interface->GetNetworkMask ()) != (Ipv4Mask ())) + { + AddNetworkRouteTo (interface->GetAddress ().CombineMask (interface->GetNetworkMask ()), + interface->GetNetworkMask (), i); + } +} +void +Ipv4L3Protocol::SetDown (uint32_t ifaceIndex) +{ + Ipv4Interface *interface = GetInterface (ifaceIndex); interface->SetDown (); + + // Remove all routes that are going through this interface + bool modified = true; + while (modified) + { + modified = false; + for (uint32_t i = 0; i < GetNRoutes (); i++) + { + Ipv4Route *route = GetRoute (i); + if (route->GetInterface () == ifaceIndex) + { + RemoveRoute (i); + modified = true; + break; + } + } + } }