bug 63: allow enabling or disabling ip forwarding on a per-interface basis

This commit is contained in:
Tom Henderson committed 2009-06-26 10:56:51 +02:00
1 parent 758be5cee1
commit b44b286f29
9 files changed
+95 -8

No files matched your search

+15
View File
@@ -56,6 +56,7 @@ Ipv4Interface::GetTypeId (void)
*/
Ipv4Interface::Ipv4Interface ()
: m_ifup (false),
m_forwarding (true),
m_metric (1),
m_node (0),
m_device (0),
@@ -160,6 +161,20 @@ Ipv4Interface::SetDown (void)
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)
{
+11
View File
@@ -105,6 +105,16 @@ public:
*/
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 @@ private:
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;
+33 -1
View File
@@ -251,6 +251,7 @@ Ipv4L3Protocol::AddInterface (Ptr<NetDevice> device)
Ptr<Ipv4Interface> interface = CreateObject<Ipv4Interface> ();
interface->SetNode (m_node);
interface->SetDevice (device);
interface->SetForwarding (m_ipForward);
return AddIpv4Interface (interface);
}
@@ -412,7 +413,7 @@ Ipv4L3Protocol::Receive( Ptr<NetDevice> device, Ptr<const Packet> p, uint16_t pr
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 @@ Ipv4L3Protocol::SetDown (uint32_t ifaceIndex)
}
}
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 @@ Ipv4L3Protocol::GetIpForward (void) const
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
+4
View File
@@ -152,6 +152,8 @@ public:
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 @@ private:
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;