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

This is a discussion on Packets from bottom of TCP/IP stack direct to application bypassing stack within the Linux Networking forums, part of the Linux Forums category; Andreas <andreas_lindell76@hotmail.com> wrote: > I am working on a ADSL modem and have the following situation ...


Go Back   Usenet Forums > Linux Forums > Linux Networking

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-08-2004
Cameron Kerr
 
Posts: n/a
Default Re: Packets from bottom of TCP/IP stack direct to application bypassing stack

Andreas <andreas_lindell76@hotmail.com> wrote:

> 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.

--
Cameron Kerr
cameron.kerr@paradise.net.nz : http://nzgeeks.org/cameron/
Empowered by Perl!
Reply With Quote
  #2 (permalink)  
Old 06-08-2004
Andreas
 
Posts: n/a
Default Packets from bottom of TCP/IP stack direct to application bypassing stack

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
Reply With Quote
  #3 (permalink)  
Old 06-09-2004
Andreas
 
Posts: n/a
Default Re: Packets from bottom of TCP/IP stack direct to application bypassing stack

Cameron Kerr <cameron.kerr@paradise.net.nz> wrote in message news:<40c566f1@news.maxnet.co.nz>...
> Andreas <andreas_lindell76@hotmail.com> wrote:
>
> > 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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 01:33 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0