Add a NetDevice::SendFrom API, for sending packets with a custom source MAC address (a.k.a. MAC spoofing). Only implemented for CsmaNetDevice for now.

This commit is contained in:
Gustavo J. A. M. Carneiro
2008-07-04 18:03:26 +01:00
parent f3d8a5eb6d
commit df677111d4
9 changed files with 65 additions and 21 deletions

View File

@@ -173,6 +173,7 @@ CsmaNetDevice::SetBackoffParams (
void
CsmaNetDevice::AddHeader (
Ptr<Packet> 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> 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> packet,
const Address& dest,
uint16_t protocolNumber)
bool
CsmaNetDevice::Send (Ptr<Packet> packet,
const Address& dest,
uint16_t protocolNumber)
{
return SendFrom (packet, m_address, dest, protocolNumber);
}
bool
CsmaNetDevice::SendFrom (Ptr<Packet> 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

View File

@@ -250,6 +250,12 @@ public:
virtual bool Send (Ptr<Packet> packet, const Address& dest,
uint16_t protocolNumber);
/**
* Start sending a packet down the channel, with MAC spoofing
*/
virtual bool SendFrom (Ptr<Packet> 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<Packet> p, Mac48Address dest, uint16_t protocolNumber);
void AddHeader (Ptr<Packet> p, Mac48Address source, Mac48Address dest, uint16_t protocolNumber);
/**
* Removes, from a packet of data, all headers and trailers that

View File

@@ -434,6 +434,15 @@ PointToPointNetDevice::Send(
}
}
bool
PointToPointNetDevice::SendFrom (Ptr<Packet> packet,
const Address &source,
const Address &dest,
uint16_t protocolNumber)
{
return Send (packet, dest, protocolNumber);
}
Ptr<Node>
PointToPointNetDevice::GetNode (void) const
{

View File

@@ -167,8 +167,8 @@ public:
virtual bool IsPointToPoint (void) const;
virtual bool Send(Ptr<Packet> packet, const Address &dest,
uint16_t protocolNumber);
virtual bool Send(Ptr<Packet> packet, const Address &dest, uint16_t protocolNumber);
virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
virtual Ptr<Node> GetNode (void) const;
virtual void SetNode (Ptr<Node> node);

View File

@@ -283,6 +283,12 @@ WifiNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNu
m_mac->Enqueue (packet, realTo);
return true;
}
bool
WifiNetDevice::SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber)
{
NS_FATAL_ERROR ("WifiNetDevice::SendFrom not implemented.");
return false;
}
Ptr<Node>
WifiNetDevice::GetNode (void) const
{

View File

@@ -96,6 +96,7 @@ public:
virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const;
virtual bool IsPointToPoint (void) const;
virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
virtual bool SendFrom (Ptr<Packet> packet, const Address& src, const Address& dest, uint16_t protocolNumber);
virtual Ptr<Node> GetNode (void) const;
virtual void SetNode (Ptr<Node> node);
virtual bool NeedsArp (void) const;

View File

@@ -215,6 +215,20 @@ public:
* \return whether the Send operation succeeded
*/
virtual bool Send(Ptr<Packet> 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> packet, const Address& source, const Address& dest, uint16_t protocolNumber) = 0;
/**
* \returns the node base class which contains this network
* interface.

View File

@@ -151,6 +151,15 @@ SimpleNetDevice::Send(Ptr<Packet> packet, const Address& dest, uint16_t protocol
m_channel->Send (packet, protocolNumber, to, m_address, this);
return true;
}
bool
SimpleNetDevice::SendFrom(Ptr<Packet> 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<Node>
SimpleNetDevice::GetNode (void) const
{

View File

@@ -63,6 +63,7 @@ public:
virtual Address MakeMulticastAddress (Ipv4Address multicastGroup) const;
virtual bool IsPointToPoint (void) const;
virtual bool Send(Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
virtual bool SendFrom(Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
virtual Ptr<Node> GetNode (void) const;
virtual void SetNode (Ptr<Node> node);
virtual bool NeedsArp (void) const;