Packets from bottom of TCP/IP stack direct to application bypassing stack

Packets from bottom of TCP/IP stack direct to application bypassing stack

Post by Andre » Wed, 09 Jun 2004 16:24:44



Hello Everyone

I am working on a ADSL modem and have the following situation that I
would like to have some advice on.

I need to filter out some packages in the lower level of the network
stack. There are 2 types of packages: [eth | ppp | ip | udp] and [eth
| ip | udp], the data in these packages are the same and they can be
identified with the first 16 bits in the UDP data.

I have manage to catch these packages in the /net/core/dev.c file and
function netif_rx(...) with the 16 bit ID so I have the packages.

Now for my question: How do I in an easy way get these packages
directly to my application without using the network stack. I need
BOTH of these packages to reach there and if I use socket the one with
PPP get thrown away somewhere and that is not so good.

I know this is not a very specific question and a little vague but
some advice and pointers would be appreciated.

Regards
Andreas

 
 
 

Packets from bottom of TCP/IP stack direct to application bypassing stack

Post by Cameron Ker » Wed, 09 Jun 2004 16:12:51



> I am working on a ADSL modem and have the following situation that I
> would like to have some advice on.

Are you writing a driver for said modem? If so, are you wanting to write
the driver in user-space or kernel-space?

You may like to check out the speedtouch.sf.net website and see how they
have gone about it, as they have two driver versions, on is user-space,
the other kernel-space. The user-space version also runs on FreeBSD,
IIRC.

Quote:> I need to filter out some packages in the lower level of the network
> stack.

You mean packets, not packages.

Quote:> There are 2 types of packages: [eth | ppp | ip | udp] and [eth
> | ip | udp], the data in these packages are the same and they can be
> identified with the first 16 bits in the UDP data.

So you're dealing with PPPoE (PPP over Ethernet)???

Quote:> Now for my question: How do I in an easy way get these packages
> directly to my application without using the network stack.
> I need BOTH of these packages to reach there and if I use socket the
> one with PPP get thrown away somewhere and that is not so good.

Assuming you want to do this the user-space way (not as a kernel
driver), then the following ought to do. This will give your application
the full frame, as is recieved at the datalink layer.

It sounds like you want to be using Raw sockets (previously, PF_PACKET
sockets were used for this, though I believe that is now deprecated
under Linux). That would recieve all packets, so you would probably also
want a BPF packet filter attached to select only the packets you are
interested in.

Naturally, the program would require root permissions to create such
sockets.

Quote:> I know this is not a very specific question and a little vague but
> some advice and pointers would be appreciated.

No problem, though I don't know how to go about using BPF packet filters
attached to sockets.

Perhaps if you give a much more detailed overview of what you are trying
to achieve, I could help you more.

--
Cameron Kerr

Empowered by Perl!

 
 
 

Packets from bottom of TCP/IP stack direct to application bypassing stack

Post by Andre » Thu, 10 Jun 2004 21:19:23




> > I am working on a ADSL modem and have the following situation that I
> > would like to have some advice on.

> Are you writing a driver for said modem? If so, are you wanting to write
> the driver in user-space or kernel-space?

> You may like to check out the speedtouch.sf.net website and see how they
> have gone about it, as they have two driver versions, on is user-space,
> the other kernel-space. The user-space version also runs on FreeBSD,
> IIRC.

> > I need to filter out some packages in the lower level of the network
> > stack.

> You mean packets, not packages.

> > There are 2 types of packages: [eth | ppp | ip | udp] and [eth
> > | ip | udp], the data in these packages are the same and they can be
> > identified with the first 16 bits in the UDP data.

> So you're dealing with PPPoE (PPP over Ethernet)???

> > Now for my question: How do I in an easy way get these packages
> > directly to my application without using the network stack.
> > I need BOTH of these packages to reach there and if I use socket the
> > one with PPP get thrown away somewhere and that is not so good.

> Assuming you want to do this the user-space way (not as a kernel
> driver), then the following ought to do. This will give your application
> the full frame, as is recieved at the datalink layer.

> It sounds like you want to be using Raw sockets (previously, PF_PACKET
> sockets were used for this, though I believe that is now deprecated
> under Linux). That would recieve all packets, so you would probably also
> want a BPF packet filter attached to select only the packets you are
> interested in.

> Naturally, the program would require root permissions to create such
> sockets.

> > I know this is not a very specific question and a little vague but
> > some advice and pointers would be appreciated.

> No problem, though I don't know how to go about using BPF packet filters
> attached to sockets.

> Perhaps if you give a much more detailed overview of what you are trying
> to achieve, I could help you more.

Hello Cameron

Yes I am dealing with PPPoE and PPPoA.

Yes, packets and not packages:)

My product is an ADSL modem(embedded with 1 MB flash and slow CPU:)
and want have a control application running on the modem. This
application will at request send status and configuration to the host
application running on Windows or MAC which monitors and displays
current settings. This communication is done by IP/UDP socket which
are broadcasted from the host and unicasted back.

When the modem is in router mode and PPPoE/A it all works fine since
the modem itself packets the data into a PPP frame before pushing it
out on the WAN side i.e all data between host and modem are IP and
UDP/TCP based. However when setting the modem in bridge mode the user
will need a PPPoE client on the host(MAC or PC) to connect to the ISP.
Now a windows machine will send out 2 packages when the host
application does a request for modem status:

1) eth | ppp | ip | udp (unicast, to the ISP) PPP client does this.
2) eth | ip | udp (broadcast) as before when in route mode.

These packages are identical execpt for the ppp frame and
broadcast/unicast. My control application will only pick up one which
is 2) since it uses a IP/UDP socket and this is no problem.

But when running the host application on a MAC its a different story,
it will only send out 1 packet:
1) eth | ppp | ip | udp (unicast, to the ISP) PPP client does this.
and this will not be received by the control application since it uses
a IP/UDP socket and dont accept any PPP stuff.

Now both of these packets are received somewhere in in the
stack/drivers and I can get both 1 and 2 of them in
        int netif_rx(struct sk_buff *skb) in /net/core/dev.c
Now I want to get them directly up to my application and by passing
the stack.

I have looked at some packet filters like libpcap used in TCPDUMP and
it works fine. However I feel that there is to much overhead using
these filters, what they do is use RAW socket and process the packets
according to rules provided to them. I can just do that myself with:
        sk = socket(PF_INET, SOCK_PACKET, htons(ETH_P_ALL));
and I have it all and can just throw away what I do not need. However
all the work is already beeing done in the stack anyway and I dont
want to do any redundant work. I have the packages in:
        int netif_rx(struct sk_buff *skb) in /net/core/dev.c
Now I just want them into my application without to much hazzle. Maybe
export a structure/linked list to my application from the kernel or
something. I am not really sure how to do this and if its the right
approach.

Once again:
I know this is not a very specific question and a little vague but
some advice and pointers would be appreciated.

Regards
Andreas

 
 
 

1. Is the TCP/IP stack processed in BOTTOM HALF context?

I am doing some research on the Linux TCP/IP stack.  I am using Linux
2.4.7.  I was wondering if the TCP/IP stack is processed in bottom
half context.  If so... who controls when the bottom half should be
scheduled?  how do I know when the bottom half is processed (ie.
specifically what function is called to indicate that the bottom half
has finished?)

Americo

2. How to reset modem on HP-UX?

3. what does this log mean?

4. Q: Bypass TCP/IP stack in RedHat 6.1

5. Help! - Best way to clone Linux systems for 40+ PC QA lab rolll-out...

6. Advice requested: Porting Linux TCP/IP stack to application space

7. RPM not working under RedHat 4.0

8. TCP/IP stack 'xerox' packets?

9. how to remove atcp/ip stack and add a third party stack in linux

10. How to tell an application to use a custom tcp/ip stack instead of tcp/ip stack from linux?

11. tcp / ip stack and ip forwarding questions

12. Looking for TCP stack that runs in application space