--- a/src/internet-stack/ipv4-interface.cc Fri Jun 26 10:48:35 2009 +0200
+++ b/src/internet-stack/ipv4-interface.cc Fri Jun 26 10:56:51 2009 +0200
@@ -56,6 +56,7 @@
*/
Ipv4Interface::Ipv4Interface ()
: m_ifup (false),
+ m_forwarding (true),
m_metric (1),
m_node (0),
m_device (0),
@@ -160,6 +161,20 @@
m_ifup = false;
}
+bool
+Ipv4Interface::IsForwarding (void) const
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ return m_forwarding;
+}
+
+void
+Ipv4Interface::SetForwarding (bool val)
+{
+ NS_LOG_FUNCTION_NOARGS ();
+ m_forwarding = val;
+}
+
void
Ipv4Interface::Send (Ptr<Packet> p, Ipv4Address dest)
{
--- a/src/internet-stack/ipv4-interface.h Fri Jun 26 10:48:35 2009 +0200
+++ b/src/internet-stack/ipv4-interface.h Fri Jun 26 10:56:51 2009 +0200
@@ -106,6 +106,16 @@
void SetDown (void);
/**
+ * \returns true if this interface is enabled for IP forwarding of input datagrams
+ */
+ bool IsForwarding (void) const;
+
+ /**
+ * \param val Whether to enable or disable IP forwarding for input datagrams
+ */
+ void SetForwarding (bool val);
+
+ /**
* \param p packet to send
* \param dest next hop address of packet.
*
@@ -146,6 +156,7 @@
typedef std::list<Ipv4InterfaceAddress>::iterator Ipv4InterfaceAddressListI;
bool m_ifup;
+ bool m_forwarding; // IN_DEV_FORWARD
uint16_t m_metric;
Ipv4InterfaceAddressList m_ifaddrs;
Ptr<Node> m_node;
--- a/src/internet-stack/ipv4-l3-protocol.cc Fri Jun 26 10:48:35 2009 +0200
+++ b/src/internet-stack/ipv4-l3-protocol.cc Fri Jun 26 10:56:51 2009 +0200
@@ -251,6 +251,7 @@
Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
interface->SetNode (m_node);
interface->SetDevice (device);
+ interface->SetForwarding (m_ipForward);
return AddIpv4Interface (interface);
}
@@ -412,7 +413,7 @@
MakeCallback (&Ipv4L3Protocol::IpForward, this),
MakeCallback (&Ipv4L3Protocol::IpMulticastForward, this),
MakeCallback (&Ipv4L3Protocol::LocalDeliver, this),
- MakeNullCallback <void, Ptr<const Packet>, const Ipv4Header &> ()
+ MakeCallback (&Ipv4L3Protocol::RouteInputError, this)
);
}
@@ -845,16 +846,39 @@
}
}
+bool
+Ipv4L3Protocol::IsForwarding (uint32_t i) const
+{
+ NS_LOG_FUNCTION (this << i);
+ Ptr<Ipv4Interface> interface = GetInterface (i);
+ NS_LOG_LOGIC ("Forwarding state: " << interface->IsForwarding ());
+ return interface->IsForwarding ();
+}
+
+void
+Ipv4L3Protocol::SetForwarding (uint32_t i, bool val)
+{
+ NS_LOG_FUNCTION (this << i);
+ Ptr<Ipv4Interface> interface = GetInterface (i);
+ interface->SetForwarding (val);
+}
+
Ptr<NetDevice>
Ipv4L3Protocol::GetNetDevice (uint32_t i)
{
+ NS_LOG_FUNCTION (this << i);
return GetInterface (i)-> GetDevice ();
}
void
Ipv4L3Protocol::SetIpForward (bool forward)
{
+ NS_LOG_FUNCTION (this << forward);
m_ipForward = forward;
+ for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); i != m_interfaces.end (); i++)
+ {
+ (*i)->SetForwarding (forward);
+ }
}
bool
@@ -863,5 +887,13 @@
return m_ipForward;
}
+void
+Ipv4L3Protocol::RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno)
+{
+ NS_LOG_FUNCTION (this << p << ipHeader << sockErrno);
+ NS_LOG_LOGIC ("Route input failure-- dropping packet to " << ipHeader << " with errno " << sockErrno);
+ m_dropTrace (p);
+}
+
}//namespace ns3
--- a/src/internet-stack/ipv4-l3-protocol.h Fri Jun 26 10:48:35 2009 +0200
+++ b/src/internet-stack/ipv4-l3-protocol.h Fri Jun 26 10:56:51 2009 +0200
@@ -152,6 +152,8 @@
bool IsUp (uint32_t i) const;
void SetUp (uint32_t i);
void SetDown (uint32_t i);
+ bool IsForwarding (uint32_t i) const;
+ void SetForwarding (uint32_t i, bool val);
Ptr<NetDevice> GetNetDevice (uint32_t i);
@@ -198,6 +200,8 @@
const Ipv4Header &header);
void LocalDeliver (Ptr<const Packet> p, Ipv4Header const&ip, uint32_t iif);
+ void RouteInputError (Ptr<const Packet> p, const Ipv4Header & ipHeader, Socket::SocketErrno sockErrno);
+
uint32_t AddIpv4Interface (Ptr<Ipv4Interface> interface);
void SetupLoopback (void);
Ptr<Icmpv4L4Protocol> GetIcmp (void) const;
--- a/src/node/ipv4-routing-protocol.h Fri Jun 26 10:48:35 2009 +0200
+++ b/src/node/ipv4-routing-protocol.h Fri Jun 26 10:56:51 2009 +0200
@@ -51,7 +51,7 @@
typedef Callback<void, Ptr<Ipv4Route>, Ptr<const Packet>, const Ipv4Header &> UnicastForwardCallback;
typedef Callback<void, Ptr<Ipv4MulticastRoute>, Ptr<const Packet>, const Ipv4Header &> MulticastForwardCallback;
typedef Callback<void, Ptr<const Packet>, const Ipv4Header &, uint32_t > LocalDeliverCallback;
- typedef Callback<void, Ptr<const Packet>, const Ipv4Header &> ErrorCallback;
+ typedef Callback<void, Ptr<const Packet>, const Ipv4Header &, Socket::SocketErrno > ErrorCallback;
/**
* \brief Query routing cache for an existing route, for an outbound packet
--- a/src/node/ipv4.cc Fri Jun 26 10:48:35 2009 +0200
+++ b/src/node/ipv4.cc Fri Jun 26 10:56:51 2009 +0200
@@ -32,7 +32,7 @@
{
static TypeId tid = TypeId ("ns3::Ipv4")
.SetParent<Object> ()
- .AddAttribute ("IpForward", "If enabled, node can act as unicast router.",
+ .AddAttribute ("IpForward", "Globally enable or disable IP forwarding for all current and future Ipv4 devices.",
BooleanValue (true),
MakeBooleanAccessor (&Ipv4::SetIpForward,
&Ipv4::GetIpForward),
--- a/src/node/ipv4.h Fri Jun 26 10:48:35 2009 +0200
+++ b/src/node/ipv4.h Fri Jun 26 10:56:51 2009 +0200
@@ -235,6 +235,20 @@
*/
virtual void SetDown (uint32_t interface) = 0;
+ /**
+ * \param interface Interface number of Ipv4 interface
+ * \returns true if IP forwarding enabled for input datagrams on this device
+ */
+ virtual bool IsForwarding (uint32_t interface) const = 0;
+
+ /**
+ * \param interface Interface number of Ipv4 interface
+ * \param val Value to set the forwarding flag
+ *
+ * If set to true, IP forwarding is enabled for input datagrams on this device
+ */
+ virtual void SetForwarding (uint32_t interface, bool val) = 0;
+
static const uint32_t IF_ANY = 0xffffffff;
private:
--- a/src/routing/global-routing/global-router-interface.cc Fri Jun 26 10:48:35 2009 +0200
+++ b/src/routing/global-routing/global-router-interface.cc Fri Jun 26 10:56:51 2009 +0200
@@ -605,19 +605,20 @@
// associated with a bridge. We are only going to involve devices with
// IP addresses in routing.
//
- bool isIp = false;
+ bool isForwarding = false;
for (uint32_t j = 0; j < ipv4Local->GetNInterfaces (); ++j )
{
- if (ipv4Local->GetNetDevice (j) == ndLocal && ipv4Local->IsUp (j))
+ if (ipv4Local->GetNetDevice (j) == ndLocal && ipv4Local->IsUp (j) &&
+ ipv4Local->IsForwarding (j))
{
- isIp = true;
+ isForwarding = true;
break;
}
}
- if (!isIp)
+ if (!isForwarding)
{
- NS_LOG_LOGIC ("Net device " << ndLocal << "has no IP interface, skipping");
+ NS_LOG_LOGIC ("Net device " << ndLocal << "has no IP interface or is not enabled for forwarding, skipping");
continue;
}
@@ -630,6 +631,7 @@
// If the device is a point to point link, we treat it separately. In
// that case, there may be zero, one, or two link records added.
//
+
if (ndLocal->IsBroadcast () && !ndLocal->IsPointToPoint () )
{
NS_LOG_LOGIC ("Broadcast link");
--- a/src/routing/list-routing/ipv4-list-routing.cc Fri Jun 26 10:48:35 2009 +0200
+++ b/src/routing/list-routing/ipv4-list-routing.cc Fri Jun 26 10:56:51 2009 +0200
@@ -104,6 +104,8 @@
NS_LOG_LOGIC ("RouteInput logic for node: " << m_ipv4->GetObject<Node> ()->GetId ());
NS_ASSERT (m_ipv4 != 0);
+ // Check if input device supports IP
+ NS_ASSERT (m_ipv4->GetInterfaceForDevice (idev) >= 0);
uint32_t iif = m_ipv4->GetInterfaceForDevice (idev);
// Multicast recognition; handle local delivery here
@@ -177,6 +179,13 @@
NS_LOG_LOGIC ("Address "<< addr << " not a match");
}
}
+ // Check if input device supports IP forwarding
+ if (m_ipv4->IsForwarding (iif) == false)
+ {
+ NS_LOG_LOGIC ("Forwarding disabled for this interface");
+ ecb (p, header, Socket::ERROR_NOROUTETOHOST);
+ return false;
+ }
// Next, try to find a route
for (Ipv4RoutingProtocolList::const_iterator rprotoIter =
m_routingProtocols.begin ();