From e4459509aaf53e7e4a60127dedf2d88cfbb94267 Mon Sep 17 00:00:00 2001 From: Andrey Mazo Date: Tue, 22 Dec 2009 18:34:48 +0300 Subject: [PATCH] Bug 782: CreateTap () requires IP address in modes other than CONFIGURE_LOCAL. --- src/devices/tap-bridge/tap-bridge.cc | 40 +++++++++++++++++++++------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/devices/tap-bridge/tap-bridge.cc b/src/devices/tap-bridge/tap-bridge.cc index 80d18bd58..4d323afe0 100644 --- a/src/devices/tap-bridge/tap-bridge.cc +++ b/src/devices/tap-bridge/tap-bridge.cc @@ -357,6 +357,7 @@ TapBridge::CreateTap (void) // // We want to get as much of this stuff automagically as possible. // + // For CONFIGURE_LOCAL mode only: // is the IP address we are going to set in the newly // created Tap device on the Linux host. At the point in the simulation // where devices are coming up, we should have all of our IP addresses @@ -364,20 +365,39 @@ TapBridge::CreateTap (void) // the new Tap device from the IP address associated with the bridged // net device. // + + bool wantIp = (m_mode == CONFIGURE_LOCAL); + Ptr nd = GetBridgedNetDevice (); Ptr n = nd->GetNode (); Ptr ipv4 = n->GetObject (); - uint32_t index = ipv4->GetInterfaceForDevice (nd); - if (ipv4->GetNAddresses (index) > 1) - { - NS_LOG_WARN ("Underlying bridged NetDevice has multiple IP addresses; using first one."); - } - Ipv4Address ipv4Address = ipv4->GetAddress (index, 0).GetLocal (); - // - // The net mask is sitting right there next to the ipv4 address. - // - Ipv4Mask ipv4Mask = ipv4->GetAddress (index, 0).GetMask (); + if (wantIp + && (ipv4 == 0) + && m_tapIp.IsBroadcast () + && m_tapNetmask.IsEqual (Ipv4Mask::GetOnes ())) + { + NS_FATAL_ERROR ("TapBridge::CreateTap(): Tap device IP configuration requested but neither IP address nor IP netmask is provided"); + } + + // Some stub values to make tap-creator happy + Ipv4Address ipv4Address ("255.255.255.255"); + Ipv4Mask ipv4Mask ("255.255.255.255"); + + if (ipv4 != 0) + { + uint32_t index = ipv4->GetInterfaceForDevice (nd); + if (ipv4->GetNAddresses (index) > 1) + { + NS_LOG_WARN ("Underlying bridged NetDevice has multiple IP addresses; using first one."); + } + ipv4Address = ipv4->GetAddress (index, 0).GetLocal (); + + // + // The net mask is sitting right there next to the ipv4 address. + // + ipv4Mask = ipv4->GetAddress (index, 0).GetMask (); + } // // The MAC address should also already be assigned and waiting for us in