From c63f0e286cf33dc9528b3383fe94f7d23c31e0aa Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Wed, 3 Feb 2016 22:14:12 +0100 Subject: [PATCH] internet: (fixes #2273) WeakEs model should be enforced in Static and Global routing --- RELEASE_NOTES | 1 + src/internet/model/ipv4-global-routing.cc | 58 ++++++----------------- src/internet/model/ipv4-static-routing.cc | 54 +++++++-------------- 3 files changed, 32 insertions(+), 81 deletions(-) diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 0342d1dc4..d217f5cde 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -91,6 +91,7 @@ Bugs fixed - Bug 2266 - NixRouting info are not copied during a packet fragmentation. - Bug 2267 - Wrong channel bandwidth value in pcap files - Bug 2272 - SixLowPan NetDevice can not send uncompressed packets larger than 802.15.4 MTU +- Bug 2273 - WeakEs model should be enforced in Static and Global routing - Bug 2279 - Ipv[4,6]L3Protocol::GetInterfaceForDevice speedup. - Bug 2286 - Support for SLL header (de)serialization. diff --git a/src/internet/model/ipv4-global-routing.cc b/src/internet/model/ipv4-global-routing.cc index cbc8e42ed..191258912 100644 --- a/src/internet/model/ipv4-global-routing.cc +++ b/src/internet/model/ipv4-global-routing.cc @@ -489,53 +489,25 @@ Ipv4GlobalRouting::RouteInput (Ptr p, const Ipv4Header &header, P NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0); uint32_t iif = m_ipv4->GetInterfaceForDevice (idev); - if (header.GetDestination ().IsMulticast ()) + if (m_ipv4->IsDestinationAddress (header.GetDestination (), iif)) { - NS_LOG_LOGIC ("Multicast destination-- returning false"); - return false; // Let other routing protocols try to handle this - } - - if (header.GetDestination ().IsBroadcast ()) - { - NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)"); - /// \todo Local Deliver for broadcast - /// \todo Forward broadcast - } - - /// \todo Configurable option to enable \RFC{1222} Strong End System Model - // Right now, we will be permissive and allow a source to send us - // a packet to one of our other interface addresses; that is, the - // destination unicast address does not match one of the iif addresses, - // but we check our other interfaces. This could be an option - // (to remove the outer loop immediately below and just check iif). - for (uint32_t j = 0; j < m_ipv4->GetNInterfaces (); j++) - { - for (uint32_t i = 0; i < m_ipv4->GetNAddresses (j); i++) + if (!lcb.IsNull ()) { - Ipv4InterfaceAddress iaddr = m_ipv4->GetAddress (j, i); - Ipv4Address addr = iaddr.GetLocal (); - if (addr.IsEqual (header.GetDestination ())) - { - if (j == iif) - { - NS_LOG_LOGIC ("For me (destination " << addr << " match)"); - } - else - { - NS_LOG_LOGIC ("For me (destination " << addr << " match) on another interface " << header.GetDestination ()); - } - lcb (p, header, iif); - return true; - } - if (header.GetDestination ().IsEqual (iaddr.GetBroadcast ())) - { - NS_LOG_LOGIC ("For me (interface broadcast address)"); - lcb (p, header, iif); - return true; - } - NS_LOG_LOGIC ("Address "<< addr << " not a match"); + NS_LOG_LOGIC ("Local delivery to " << header.GetDestination ()); + lcb (p, header, iif); + return true; + } + else + { + // The local delivery callback is null. This may be a multicast + // or broadcast packet, so return false so that another + // multicast routing protocol can handle it. It should be possible + // to extend this to explicitly check whether it is a unicast + // packet, and invoke the error callback if so + return false; } } + // Check if input device supports IP forwarding if (m_ipv4->IsForwarding (iif) == false) { diff --git a/src/internet/model/ipv4-static-routing.cc b/src/internet/model/ipv4-static-routing.cc index ba7379ded..8563a241b 100644 --- a/src/internet/model/ipv4-static-routing.cc +++ b/src/internet/model/ipv4-static-routing.cc @@ -499,7 +499,7 @@ Ipv4StaticRouting::RouteInput (Ptr p, const Ipv4Header &ipHeader, uint32_t iif = m_ipv4->GetInterfaceForDevice (idev); // Multicast recognition; handle local delivery here - // + if (ipHeader.GetDestination ().IsMulticast ()) { NS_LOG_LOGIC ("Multicast destination"); @@ -518,48 +518,26 @@ Ipv4StaticRouting::RouteInput (Ptr p, const Ipv4Header &ipHeader, return false; // Let other routing protocols try to handle this } } - if (ipHeader.GetDestination ().IsBroadcast ()) - { - NS_LOG_LOGIC ("For me (Ipv4Addr broadcast address)"); - /// \todo Local Deliver for broadcast - /// \todo Forward broadcast - } - NS_LOG_LOGIC ("Unicast destination"); - /// \todo Configurable option to enable \RFC{1222} Strong End System Model - // Right now, we will be permissive and allow a source to send us - // a packet to one of our other interface addresses; that is, the - // destination unicast address does not match one of the iif addresses, - // but we check our other interfaces. This could be an option - // (to remove the outer loop immediately below and just check iif). - for (uint32_t j = 0; j < m_ipv4->GetNInterfaces (); j++) + if (m_ipv4->IsDestinationAddress (ipHeader.GetDestination (), iif)) { - for (uint32_t i = 0; i < m_ipv4->GetNAddresses (j); i++) + if (!lcb.IsNull ()) { - Ipv4InterfaceAddress iaddr = m_ipv4->GetAddress (j, i); - Ipv4Address addr = iaddr.GetLocal (); - if (addr.IsEqual (ipHeader.GetDestination ())) - { - if (j == iif) - { - NS_LOG_LOGIC ("For me (destination " << addr << " match)"); - } - else - { - NS_LOG_LOGIC ("For me (destination " << addr << " match) on another interface " << ipHeader.GetDestination ()); - } - lcb (p, ipHeader, iif); - return true; - } - if (ipHeader.GetDestination ().IsEqual (iaddr.GetBroadcast ())) - { - NS_LOG_LOGIC ("For me (interface broadcast address)"); - lcb (p, ipHeader, iif); - return true; - } - NS_LOG_LOGIC ("Address "<< addr << " not a match"); + NS_LOG_LOGIC ("Local delivery to " << ipHeader.GetDestination ()); + lcb (p, ipHeader, iif); + return true; + } + else + { + // The local delivery callback is null. This may be a multicast + // or broadcast packet, so return false so that another + // multicast routing protocol can handle it. It should be possible + // to extend this to explicitly check whether it is a unicast + // packet, and invoke the error callback if so + return false; } } + // Check if input device supports IP forwarding if (m_ipv4->IsForwarding (iif) == false) {