diff --git a/src/devices/csma/csma-net-device.cc b/src/devices/csma/csma-net-device.cc index 4c8371e36..5cf20ac52 100644 --- a/src/devices/csma/csma-net-device.cc +++ b/src/devices/csma/csma-net-device.cc @@ -173,6 +173,7 @@ CsmaNetDevice::SetBackoffParams ( void CsmaNetDevice::AddHeader ( Ptr p, + Mac48Address source, Mac48Address dest, uint16_t protocolNumber) { @@ -183,7 +184,6 @@ CsmaNetDevice::AddHeader ( return; } - Mac48Address source = Mac48Address::ConvertFrom (GetAddress ()); EthernetHeader header (false); header.SetSource (source); header.SetDestination (dest); @@ -491,17 +491,6 @@ CsmaNetDevice::Receive (Ptr packet) NS_LOG_LOGIC ("Pkt source is " << header.GetSource ()); NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ()); -// -// We never forward up packets that we sent. Real devices don't do this since -// their receivers are disabled during send, so we don't. Drop the packet -// silently (no tracing) since it would really never get here in a real device. -// - if (header.GetSource () == GetAddress ()) - { - NS_LOG_LOGIC ("Ignoring packet sourced by this device"); - return; - } - // // An IP host group address is mapped to an Ethernet multicast address // by placing the low-order 23-bits of the IP address into the low-order @@ -730,11 +719,19 @@ CsmaNetDevice::IsPointToPoint (void) const return false; } - bool -CsmaNetDevice::Send( - Ptr packet, - const Address& dest, - uint16_t protocolNumber) +bool +CsmaNetDevice::Send (Ptr packet, + const Address& dest, + uint16_t protocolNumber) +{ + return SendFrom (packet, m_address, dest, protocolNumber); +} + +bool +CsmaNetDevice::SendFrom (Ptr packet, + const Address& src, + const Address& dest, + uint16_t protocolNumber) { NS_LOG_FUNCTION_NOARGS (); NS_LOG_LOGIC ("p=" << packet); @@ -751,7 +748,8 @@ CsmaNetDevice::Send( } Mac48Address destination = Mac48Address::ConvertFrom (dest); - AddHeader (packet, destination, protocolNumber); + Mac48Address source = Mac48Address::ConvertFrom (src); + AddHeader (packet, source, destination, protocolNumber); // // Place the packet to be sent on the send queue diff --git a/src/devices/csma/csma-net-device.h b/src/devices/csma/csma-net-device.h index 6649c5991..bc7a205b3 100644 --- a/src/devices/csma/csma-net-device.h +++ b/src/devices/csma/csma-net-device.h @@ -250,6 +250,12 @@ public: virtual bool Send (Ptr packet, const Address& dest, uint16_t protocolNumber); + /** + * Start sending a packet down the channel, with MAC spoofing + */ + virtual bool SendFrom (Ptr packet, const Address& source, const Address& dest, + uint16_t protocolNumber); + /** * Get the node to which this device is attached. * @@ -307,7 +313,7 @@ protected: * \param protocolNumber In some protocols, identifies the type of * payload contained in this packet. */ - void AddHeader (Ptr p, Mac48Address dest, uint16_t protocolNumber); + void AddHeader (Ptr p, Mac48Address source, Mac48Address dest, uint16_t protocolNumber); /** * Removes, from a packet of data, all headers and trailers that diff --git a/src/devices/point-to-point/point-to-point-net-device.cc b/src/devices/point-to-point/point-to-point-net-device.cc index d7100177d..bdf424f3d 100644 --- a/src/devices/point-to-point/point-to-point-net-device.cc +++ b/src/devices/point-to-point/point-to-point-net-device.cc @@ -434,6 +434,15 @@ PointToPointNetDevice::Send( } } +bool +PointToPointNetDevice::SendFrom (Ptr packet, + const Address &source, + const Address &dest, + uint16_t protocolNumber) +{ + return Send (packet, dest, protocolNumber); +} + Ptr PointToPointNetDevice::GetNode (void) const { diff --git a/src/devices/point-to-point/point-to-point-net-device.h b/src/devices/point-to-point/point-to-point-net-device.h index 2cdadd122..604e7a625 100644 --- a/src/devices/point-to-point/point-to-point-net-device.h +++ b/src/devices/point-to-point/point-to-point-net-device.h @@ -167,8 +167,8 @@ public: virtual bool IsPointToPoint (void) const; - virtual bool Send(Ptr packet, const Address &dest, - uint16_t protocolNumber); + virtual bool Send(Ptr packet, const Address &dest, uint16_t protocolNumber); + virtual bool SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber); virtual Ptr GetNode (void) const; virtual void SetNode (Ptr node); diff --git a/src/devices/wifi/wifi-net-device.cc b/src/devices/wifi/wifi-net-device.cc index 44eb5acac..fd9c0fb09 100644 --- a/src/devices/wifi/wifi-net-device.cc +++ b/src/devices/wifi/wifi-net-device.cc @@ -283,6 +283,12 @@ WifiNetDevice::Send(Ptr packet, const Address& dest, uint16_t protocolNu m_mac->Enqueue (packet, realTo); return true; } +bool +WifiNetDevice::SendFrom (Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber) +{ + NS_FATAL_ERROR ("WifiNetDevice::SendFrom not implemented."); + return false; +} Ptr WifiNetDevice::GetNode (void) const { diff --git a/src/devices/wifi/wifi-net-device.h b/src/devices/wifi/wifi-net-device.h index b66cedc11..903538df0 100644 --- a/src/devices/wifi/wifi-net-device.h +++ b/src/devices/wifi/wifi-net-device.h @@ -96,6 +96,7 @@ public: virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const; virtual bool IsPointToPoint (void) const; virtual bool Send(Ptr packet, const Address& dest, uint16_t protocolNumber); + virtual bool SendFrom (Ptr packet, const Address& src, const Address& dest, uint16_t protocolNumber); virtual Ptr GetNode (void) const; virtual void SetNode (Ptr node); virtual bool NeedsArp (void) const; diff --git a/src/node/net-device.h b/src/node/net-device.h index 065b1c2c8..66b91de45 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -215,6 +215,20 @@ public: * \return whether the Send operation succeeded */ virtual bool Send(Ptr packet, const Address& dest, uint16_t protocolNumber) = 0; + /** + * \param packet packet sent from above down to Network Device + * \param source source mac address (so called "MAC spoofing") + * \param dest mac address of the destination (already resolved) + * \param protocolNumber identifies the type of payload contained in + * this packet. Used to call the right L3Protocol when the packet + * is received. + * + * Called from higher layer to send packet into Network Device + * with the specified source and destination Addresses. + * + * \return whether the Send operation succeeded + */ + virtual bool SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber) = 0; /** * \returns the node base class which contains this network * interface. diff --git a/src/node/simple-net-device.cc b/src/node/simple-net-device.cc index 5b30922d3..b3fbf26f5 100644 --- a/src/node/simple-net-device.cc +++ b/src/node/simple-net-device.cc @@ -151,6 +151,15 @@ SimpleNetDevice::Send(Ptr packet, const Address& dest, uint16_t protocol m_channel->Send (packet, protocolNumber, to, m_address, this); return true; } +bool +SimpleNetDevice::SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber) +{ + Mac48Address to = Mac48Address::ConvertFrom (dest); + Mac48Address from = Mac48Address::ConvertFrom (source); + m_channel->Send (packet, protocolNumber, to, from, this); + return true; +} + Ptr SimpleNetDevice::GetNode (void) const { diff --git a/src/node/simple-net-device.h b/src/node/simple-net-device.h index fb98e53d7..455717871 100644 --- a/src/node/simple-net-device.h +++ b/src/node/simple-net-device.h @@ -63,6 +63,7 @@ public: virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const; virtual bool IsPointToPoint (void) const; virtual bool Send(Ptr packet, const Address& dest, uint16_t protocolNumber); + virtual bool SendFrom(Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber); virtual Ptr GetNode (void) const; virtual void SetNode (Ptr node); virtual bool NeedsArp (void) const;