Bug 942 - ipv4-raw-socket-impl should listen more than one protocol
ipv4-raw-socket-impl should listen more than one protocol
Status: RESOLVED INVALID
Product: ns-3
Classification: Unclassified
Component: internet
ns-3.8
Other Linux
: P5 enhancement
Assigned To: Josh Pelkey
: feature-request
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-06-13 11:07 UTC by arun.saini07
Modified: 2011-03-16 10:25 UTC (History)
3 users (show)

See Also:


Attachments
Required declaration in header file (1.92 KB, text/x-chdr)
2010-06-15 10:33 UTC, arun.saini07
Details
To enable RawSocket to ForwardUp number of protocols (7.60 KB, text/x-c++src)
2010-06-15 10:40 UTC, arun.saini07
Details
patch for Ipv4RawSocketImpl (1.44 KB, patch)
2010-06-20 12:13 UTC, arun.saini07
Details | Diff
example to test if rawsocket is receiving more than one protocol (7.23 KB, text/x-c++src)
2010-06-20 12:17 UTC, arun.saini07
Details

Note You need to log in before you can comment on or make changes to this bug.
Description arun.saini07 2010-06-13 11:07:23 UTC
As per current implementation in "src/internet-stack/ipv4-raw-socket-imple.cc"

**********************
bool 
Ipv4RawSocketImpl::ForwardUp (Ptr<const Packet> p, Ipv4Header ipHeader, Ptr<NetDevice> device)
{
  NS_LOG_FUNCTION (this << *p << ipHeader << device);
  if (m_shutdownRecv)
    {
      return false;
    }
  NS_LOG_LOGIC ("src = " << m_src << " dst = " << m_dst);
  
  if ((m_src == Ipv4Address::GetAny () || ipHeader.GetDestination () == m_src) &&
      (m_dst == Ipv4Address::GetAny () || ipHeader.GetSource () == m_dst) &&
      ipHeader.GetProtocol () == m_protocol)

*************************

When ForwardUp function is called during listening process of raw socket, it checks for a specific protocol received (ipHeader.GetProtocol () == m_protocol). Due to which raw socket cannot process ahead (or say cannot call NotifyDataRecv ();) for other packets received.

Lets consider a scenario, Where a node is listening on raw socket, intended to listen and analyze network traffic. In this case node must be able to listen every type of packet.
Comment 1 arun.saini07 2010-06-15 10:33:45 UTC
Created attachment 920 [details]
Required declaration in header file

Following lines are added.

void AddProtocol (uint16_t protocol);
bool CheckProtocols(uint16_t protocol);

std::vector<uint16_t> m_protocolList;
Comment 2 arun.saini07 2010-06-15 10:40:37 UTC
Created attachment 921 [details]
To enable RawSocket to ForwardUp number of protocols

Following functions are defined.

void Ipv4RawSocketImpl::AddProtocol(uint16_t protocol)....

bool Ipv4RawSocketImpl::CheckProtocols(uint16_t protocol)...


Following changes in function ForwardUp()

"CheckProtocols(ipHeader.GetProtocol())" 
and 
"ipHeader.GetProtocol () == 1"

  if ((m_src == Ipv4Address::GetAny () || ipHeader.GetDestination () == m_src) &&
      (m_dst == Ipv4Address::GetAny () || ipHeader.GetSource () == m_dst) && 
      CheckProtocols(ipHeader.GetProtocol()) ) 
//&& ipHeader.GetProtocol () == m_protocol)
    {
      Ptr<Packet> copy = p->Copy ();
      //if (m_protocol == 1)
	if (ipHeader.GetProtocol () == 1)
	{.....
Comment 3 arun.saini07 2010-06-20 12:13:58 UTC
Created attachment 925 [details]
patch for Ipv4RawSocketImpl
Comment 4 arun.saini07 2010-06-20 12:17:11 UTC
Created attachment 926 [details]
example to test if rawsocket is receiving more than one protocol
Comment 5 Josh Pelkey 2010-08-03 12:38:07 UTC
This one hasn't been pushed to ns-3-dev yet, right?
Comment 6 arun.saini07 2010-08-03 12:47:32 UTC
(In reply to comment #5)
> This one hasn't been pushed to ns-3-dev yet, right?

Patch had been submitted.
I Marked it RESOLVED for verification by QA. (http://www.nsnam.org/bugzilla/page.cgi?id=fields.html#status)
Comment 7 Josh Pelkey 2010-08-03 12:55:25 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > This one hasn't been pushed to ns-3-dev yet, right?
> 
> Patch had been submitted.
> I Marked it RESOLVED for verification by QA.
> (http://www.nsnam.org/bugzilla/page.cgi?id=fields.html#status)

I don't want to take this too far off track but Resolved/Fixed would mean that it's checked in.  I think it is best to leave it open until then, so it will show up when I search for all open bugs.
Comment 8 Josh Pelkey 2010-08-05 14:00:10 UTC
(In reply to comment #4)
> Created an attachment (id=926) [details]
> example to test if rawsocket is receiving more than one protocol

Could you instead create multiple raw sockets on a node and set their protocol numbers individually?  Then, rather than passing a socket to your app, you could pass a list of sockets.  Does this make sense?

The reason I am thinking this way is because I don't understand how a protocol list will work in ipv4-raw-socket-impl, given that a single protocol (m_protocol) is used for things like Ipv4RawSocketImpl::Send/SendTo.
Comment 9 Tom Henderson 2010-08-06 00:40:45 UTC
This is the socket type that this is trying to model:
http://linux.die.net/man/7/raw

Note:  "Receiving of all IP protocols via IPPROTO_RAW is not possible using raw sockets. "

Have a look at PacketSocket (src/node/packet-socket.h) which has a Bind(address) method that can be used to get all IP datagrams, I believe.
Comment 10 Josh Pelkey 2011-03-15 13:33:00 UTC
(In reply to comment #9)
> This is the socket type that this is trying to model:
> http://linux.die.net/man/7/raw
> 
> Note:  "Receiving of all IP protocols via IPPROTO_RAW is not possible using raw
> sockets. "
> 
> Have a look at PacketSocket (src/node/packet-socket.h) which has a
> Bind(address) method that can be used to get all IP datagrams, I believe.

Ok to mark resolved/invalid then?
Comment 11 Tom Henderson 2011-03-16 00:21:46 UTC
(In reply to comment #10)
> (In reply to comment #9)
> > This is the socket type that this is trying to model:
> > http://linux.die.net/man/7/raw
> > 
> > Note:  "Receiving of all IP protocols via IPPROTO_RAW is not possible using raw
> > sockets. "
> > 
> > Have a look at PacketSocket (src/node/packet-socket.h) which has a
> > Bind(address) method that can be used to get all IP datagrams, I believe.
> 
> Ok to mark resolved/invalid then?

I believe so.