diff --git a/src/devices/bridge/bridge-net-device.cc b/src/devices/bridge/bridge-net-device.cc index 8a558236b..958baf5c6 100644 --- a/src/devices/bridge/bridge-net-device.cc +++ b/src/devices/bridge/bridge-net-device.cc @@ -61,7 +61,7 @@ BridgeNetDevice::BridgeNetDevice () } void -BridgeNetDevice::ReceiveFromDevice (Ptr incomingPort, Ptr packet, uint16_t protocol, +BridgeNetDevice::ReceiveFromDevice (Ptr incomingPort, Ptr packet, uint16_t protocol, Address const &src, Address const &dst, PacketType packetType) { NS_LOG_FUNCTION_NOARGS (); @@ -97,7 +97,7 @@ BridgeNetDevice::ReceiveFromDevice (Ptr incomingPort, Ptr pac } void -BridgeNetDevice::ForwardUnicast (Ptr incomingPort, Ptr packet, +BridgeNetDevice::ForwardUnicast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst) { NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName () @@ -130,7 +130,7 @@ BridgeNetDevice::ForwardUnicast (Ptr incomingPort, Ptr packet } void -BridgeNetDevice::ForwardBroadcast (Ptr incomingPort, Ptr packet, +BridgeNetDevice::ForwardBroadcast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst) { NS_LOG_DEBUG ("LearningBridgeForward (incomingPort=" << incomingPort->GetName () diff --git a/src/devices/bridge/bridge-net-device.h b/src/devices/bridge/bridge-net-device.h index be44792d6..5b9716383 100644 --- a/src/devices/bridge/bridge-net-device.h +++ b/src/devices/bridge/bridge-net-device.h @@ -72,11 +72,11 @@ public: protected: virtual void DoDispose (void); - void ReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, + void ReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, Address const &source, Address const &destination, PacketType packetType); - void ForwardUnicast (Ptr incomingPort, Ptr packet, + void ForwardUnicast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst); - void ForwardBroadcast (Ptr incomingPort, Ptr packet, + void ForwardBroadcast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst); void Learn (Mac48Address source, Ptr port); Ptr GetLearnedState (Mac48Address source); diff --git a/src/internet-stack/arp-l3-protocol.cc b/src/internet-stack/arp-l3-protocol.cc index 7620b7046..43e597e62 100644 --- a/src/internet-stack/arp-l3-protocol.cc +++ b/src/internet-stack/arp-l3-protocol.cc @@ -117,11 +117,13 @@ ArpL3Protocol::FindCache (Ptr device) } void -ArpL3Protocol::Receive(Ptr device, Ptr packet, uint16_t protocol, const Address &from, +ArpL3Protocol::Receive(Ptr device, Ptr p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType) { NS_LOG_FUNCTION_NOARGS (); + Ptr packet = p->Copy (); + Ptr cache = FindCache (device); ArpHeader arp; packet->RemoveHeader (arp); diff --git a/src/internet-stack/arp-l3-protocol.h b/src/internet-stack/arp-l3-protocol.h index 61507a13b..289e2296f 100644 --- a/src/internet-stack/arp-l3-protocol.h +++ b/src/internet-stack/arp-l3-protocol.h @@ -54,7 +54,7 @@ public: /** * \brief Receive a packet */ - void Receive(Ptr device, Ptr p, uint16_t protocol, const Address &from, const Address &to, + void Receive(Ptr device, Ptr p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType); /** * \brief Perform an ARP lookup diff --git a/src/internet-stack/ipv4-l3-protocol.cc b/src/internet-stack/ipv4-l3-protocol.cc index 975071419..95d34d340 100644 --- a/src/internet-stack/ipv4-l3-protocol.cc +++ b/src/internet-stack/ipv4-l3-protocol.cc @@ -449,13 +449,15 @@ Ipv4L3Protocol::FindInterfaceForDevice (Ptr device) } void -Ipv4L3Protocol::Receive( Ptr device, Ptr packet, uint16_t protocol, const Address &from, +Ipv4L3Protocol::Receive( Ptr device, Ptr p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType) { - NS_LOG_FUNCTION (this << &device << packet << protocol << from); + NS_LOG_FUNCTION (this << &device << p << protocol << from); NS_LOG_LOGIC ("Packet from " << from << " received on node " << m_node->GetId ()); + Ptr packet = p->Copy (); + uint32_t index = 0; Ptr ipv4Interface; for (Ipv4InterfaceList::const_iterator i = m_interfaces.begin (); diff --git a/src/internet-stack/ipv4-l3-protocol.h b/src/internet-stack/ipv4-l3-protocol.h index e009d2f43..493be5610 100644 --- a/src/internet-stack/ipv4-l3-protocol.h +++ b/src/internet-stack/ipv4-l3-protocol.h @@ -83,7 +83,7 @@ public: * - implement a per-NetDevice ARP cache * - send back arp replies on the right device */ - void Receive( Ptr device, Ptr p, uint16_t protocol, const Address &from, + void Receive( Ptr device, Ptr p, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType); /** diff --git a/src/node/net-device.h b/src/node/net-device.h index b8f799ed3..863530024 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -274,7 +274,7 @@ public: * \returns true if the callback could handle the packet successfully, false * otherwise. */ - typedef Callback,Ptr,uint16_t,const Address &> ReceiveCallback; + typedef Callback,Ptr,uint16_t,const Address &> ReceiveCallback; /** * \param cb callback to invoke whenever a packet has been received and must @@ -296,7 +296,7 @@ public: * \returns true if the callback could handle the packet successfully, false * otherwise. */ - typedef Callback< bool, Ptr, Ptr, uint16_t, + typedef Callback< bool, Ptr, Ptr, uint16_t, const Address &, const Address &, PacketType > PromiscReceiveCallback; /** diff --git a/src/node/node.cc b/src/node/node.cc index 1ad596488..d752b4128 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -222,7 +222,7 @@ Node::UnregisterProtocolHandler (ProtocolHandler handler) } bool -Node::PromiscReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, +Node::PromiscReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType) { NS_LOG_FUNCTION(device->GetName ()); @@ -230,7 +230,7 @@ Node::PromiscReceiveFromDevice (Ptr device, Ptr packet, uint1 } bool -Node::NonPromiscReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, +Node::NonPromiscReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, const Address &from) { NS_LOG_FUNCTION(device->GetName ()); @@ -238,15 +238,11 @@ Node::NonPromiscReceiveFromDevice (Ptr device, Ptr packet, ui } bool -Node::ReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, +Node::ReceiveFromDevice (Ptr device, Ptr packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType, bool promiscuous) { NS_LOG_FUNCTION(device->GetName ()); bool found = false; - // if there are (potentially) multiple handlers, we need to copy the - // packet before passing it to each handler, because handlers may - // modify it. - bool copyNeeded = (m_handlers.size () > 1); for (ProtocolHandlerList::iterator i = m_handlers.begin (); i != m_handlers.end (); i++) @@ -259,7 +255,7 @@ Node::ReceiveFromDevice (Ptr device, Ptr packet, uint16_t pro { if (promiscuous == i->promiscuous) { - i->handler (device, (copyNeeded ? packet->Copy () : packet), protocol, from, to, packetType); + i->handler (device, packet->Copy (), protocol, from, to, packetType); found = true; } } diff --git a/src/node/node.h b/src/node/node.h index 5f09e66be..b740a175b 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -145,7 +145,7 @@ public: * this value is only valid for promiscuous mode * protocol handlers. */ - typedef Callback, Ptr,uint16_t,const Address &, + typedef Callback, Ptr,uint16_t,const Address &, const Address &, NetDevice::PacketType> ProtocolHandler; /** * \param handler the handler to register @@ -189,10 +189,10 @@ private: */ virtual void NotifyDeviceAdded (Ptr device); - bool NonPromiscReceiveFromDevice (Ptr device, Ptr, uint16_t protocol, const Address &from); - bool PromiscReceiveFromDevice (Ptr device, Ptr, uint16_t protocol, + bool NonPromiscReceiveFromDevice (Ptr device, Ptr, uint16_t protocol, const Address &from); + bool PromiscReceiveFromDevice (Ptr device, Ptr, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType); - bool ReceiveFromDevice (Ptr device, Ptr, uint16_t protocol, + bool ReceiveFromDevice (Ptr device, Ptr, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType, bool promisc); void Construct (void); diff --git a/src/node/packet-socket.cc b/src/node/packet-socket.cc index 05b8b14d9..0cfc3b514 100644 --- a/src/node/packet-socket.cc +++ b/src/node/packet-socket.cc @@ -344,7 +344,7 @@ PacketSocket::SendTo (Ptr p, uint32_t flags, const Address &address) } void -PacketSocket::ForwardUp (Ptr device, Ptr packet, +PacketSocket::ForwardUp (Ptr device, Ptr packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType) { @@ -369,7 +369,7 @@ PacketSocket::ForwardUp (Ptr device, Ptr packet, SocketAddressTag tag; tag.SetAddress (address); packet->AddTag (tag); - m_deliveryQueue.push (packet); + m_deliveryQueue.push (packet->Copy ()); m_rxAvailable += packet->GetSize (); NS_LOG_LOGIC ("UID is " << packet->GetUid() << " PacketSocket " << this); NotifyDataRecv (); diff --git a/src/node/packet-socket.h b/src/node/packet-socket.h index 3bfc4ae3c..1218de2c3 100644 --- a/src/node/packet-socket.h +++ b/src/node/packet-socket.h @@ -103,7 +103,7 @@ public: Address &fromAddress); private: - void ForwardUp (Ptr device, Ptr packet, + void ForwardUp (Ptr device, Ptr packet, uint16_t protocol, const Address &from, const Address &to, NetDevice::PacketType packetType); int DoBind (const PacketSocketAddress &address);