* filtering packtes before OS takes care about them
@ 2005-02-28 16:16 Weber Matthias
2005-02-28 17:38 ` bert hubert
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Weber Matthias @ 2005-02-28 16:16 UTC (permalink / raw)
To: netdev
Hi,
i need a possibility to catch IP4 packets (from ethernet devices) before OS' netmodules (IP, UDP, TCP, ICMP, ARP, ROUTE, NETFILTER ...) takes care about them and
* to delete them from input buffer such that OS' netmodules can't receive them
* to modify packet headers and move packets to interface related output buffers
* to keep them in input buffers such that OS' netmodules can take care about them.
I would be thankfull for any hint, link or code example.
Bye
Matthias
--
Dipl.-Inf. Matthias Weber
Universität Erlangen-Nürnberg
Lehrstuhl für Fertigungsautomatisierung und Produktionssystematik Egerlandstraße 7-9
91058 Erlangen
Tel. :*49 9131/85-27702
Fax. :*49 9131/302528
www :www.faps.uni-erlangen.de
mailto:weber@faps.uni-erlangen.de
^ permalink raw reply [flat|nested] 14+ messages in thread* Re: filtering packtes before OS takes care about them
2005-02-28 16:16 filtering packtes before OS takes care about them Weber Matthias
@ 2005-02-28 17:38 ` bert hubert
2005-02-28 20:09 ` Asim Shankar
2005-03-01 17:20 ` Stephen Hemminger
2 siblings, 0 replies; 14+ messages in thread
From: bert hubert @ 2005-02-28 17:38 UTC (permalink / raw)
To: Weber Matthias; +Cc: netdev
On Mon, Feb 28, 2005 at 05:16:57PM +0100, Weber Matthias wrote:
> i need a possibility to catch IP4 packets (from ethernet devices) before
> OS' netmodules (IP, UDP, TCP, ICMP, ARP, ROUTE, NETFILTER ...) takes care
> about them and
Why? It helps if you tell us what you really want, or is this a research
project?
The earliest place I know of is with tc filter, but that is a netfilter
hook. So part of netfilter will "see" your code.
What you appear to be asking for is a packet filtering network adaptor?
These exist.
> * to modify packet headers and move packets to interface related output
> * buffers
Sure you want an operating system?
Good luck!
--
http://www.PowerDNS.com Open source, database driven DNS Software
http://netherlabs.nl Open and Closed source services
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: filtering packtes before OS takes care about them
2005-02-28 16:16 filtering packtes before OS takes care about them Weber Matthias
2005-02-28 17:38 ` bert hubert
@ 2005-02-28 20:09 ` Asim Shankar
2005-03-01 0:30 ` Pedro Fortuna
2005-03-05 14:08 ` Pedro Fortuna
2005-03-01 17:20 ` Stephen Hemminger
2 siblings, 2 replies; 14+ messages in thread
From: Asim Shankar @ 2005-02-28 20:09 UTC (permalink / raw)
To: Weber Matthias; +Cc: netdev
> i need a possibility to catch IP4 packets (from ethernet devices) before OS' netmodules (IP, UDP, TCP, ICMP, ARP, ROUTE, NETFILTER ...) takes care about them and
> * to delete them from input buffer such that OS' netmodules can't receive them
> * to modify packet headers and move packets to interface related output buffers
> * to keep them in input buffers such that OS' netmodules can take care about them.
You can process packets even before ip_rcv() gets them by registering
your own packet handler (struct packet_type) using dev_add_pack(). I
have a small sample at:
http://limnos.csrd.uiuc.edu/notes/code-samples/samples/kernel/packet_type/packet_type_test.c
This may not be the cleanest way, but it isn't that dirty either.
Also see:
http://www.phrack.org/show.php?p=55&a=12
-- Asim
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: filtering packtes before OS takes care about them
2005-02-28 20:09 ` Asim Shankar
@ 2005-03-01 0:30 ` Pedro Fortuna
2005-03-01 1:53 ` jamal
2005-03-01 3:35 ` Asim Shankar
2005-03-05 14:08 ` Pedro Fortuna
1 sibling, 2 replies; 14+ messages in thread
From: Pedro Fortuna @ 2005-03-01 0:30 UTC (permalink / raw)
To: netdev
Hello,
I was searching for something like this also.
In my case, I'll need to intercept all outgoing IP packets and change
them (including L2 frame) before they are passed to the network
interface driver.
The changes are:
-modify the ethertype number in the L2 frame (e.g. DIX frames) to a
private not used one
-complety modify the IP packet header and payload
After this, the packets are sent on their way (passed to the network driver)
The reverse operation is applied to incoming IP Packets in the destination host.
I didnt investigate the packet_type example you provided but I hope I
will be able to used for the purposes I explained.
Best Regards,
Pedro Fortuna
On Mon, 28 Feb 2005 14:09:56 -0600, Asim Shankar <asimshankar@gmail.com> wrote:
> > i need a possibility to catch IP4 packets (from ethernet devices) before OS' netmodules (IP, UDP, TCP, ICMP, ARP, ROUTE, NETFILTER ...) takes care about them and
> > * to delete them from input buffer such that OS' netmodules can't receive them
> > * to modify packet headers and move packets to interface related output buffers
> > * to keep them in input buffers such that OS' netmodules can take care about them.
>
> You can process packets even before ip_rcv() gets them by registering
> your own packet handler (struct packet_type) using dev_add_pack(). I
> have a small sample at:
> http://limnos.csrd.uiuc.edu/notes/code-samples/samples/kernel/packet_type/packet_type_test.c
> This may not be the cleanest way, but it isn't that dirty either.
>
> Also see:
> http://www.phrack.org/show.php?p=55&a=12
>
> -- Asim
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: filtering packtes before OS takes care about them
2005-03-01 0:30 ` Pedro Fortuna
@ 2005-03-01 1:53 ` jamal
2005-03-01 3:35 ` Asim Shankar
1 sibling, 0 replies; 14+ messages in thread
From: jamal @ 2005-03-01 1:53 UTC (permalink / raw)
To: Pedro Fortuna; +Cc: netdev
As Thomas was mentioning in other email; write an action to do this.
Attach on ingress qdisc filter/classifier like u32 to map the DIX and
then tell it to pass the packets to the action.
cheers,
jamal
On Mon, 2005-02-28 at 19:30, Pedro Fortuna wrote:
> Hello,
> I was searching for something like this also.
> In my case, I'll need to intercept all outgoing IP packets and change
> them (including L2 frame) before they are passed to the network
> interface driver.
> The changes are:
> -modify the ethertype number in the L2 frame (e.g. DIX frames) to a
> private not used one
> -complety modify the IP packet header and payload
> After this, the packets are sent on their way (passed to the network driver)
>
> The reverse operation is applied to incoming IP Packets in the destination host.
>
> I didnt investigate the packet_type example you provided but I hope I
> will be able to used for the purposes I explained.
>
> Best Regards,
> Pedro Fortuna
>
>
> On Mon, 28 Feb 2005 14:09:56 -0600, Asim Shankar <asimshankar@gmail.com> wrote:
> > > i need a possibility to catch IP4 packets (from ethernet devices) before OS' netmodules (IP, UDP, TCP, ICMP, ARP, ROUTE, NETFILTER ...) takes care about them and
> > > * to delete them from input buffer such that OS' netmodules can't receive them
> > > * to modify packet headers and move packets to interface related output buffers
> > > * to keep them in input buffers such that OS' netmodules can take care about them.
> >
> > You can process packets even before ip_rcv() gets them by registering
> > your own packet handler (struct packet_type) using dev_add_pack(). I
> > have a small sample at:
> > http://limnos.csrd.uiuc.edu/notes/code-samples/samples/kernel/packet_type/packet_type_test.c
> > This may not be the cleanest way, but it isn't that dirty either.
> >
> > Also see:
> > http://www.phrack.org/show.php?p=55&a=12
> >
> > -- Asim
> >
> >
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: filtering packtes before OS takes care about them
2005-03-01 0:30 ` Pedro Fortuna
2005-03-01 1:53 ` jamal
@ 2005-03-01 3:35 ` Asim Shankar
2005-03-01 16:33 ` Pedro Fortuna
1 sibling, 1 reply; 14+ messages in thread
From: Asim Shankar @ 2005-03-01 3:35 UTC (permalink / raw)
To: Pedro Fortuna; +Cc: netdev
> In my case, I'll need to intercept all outgoing IP packets and change
> them (including L2 frame) before they are passed to the network
> interface driver.
> The reverse operation is applied to incoming IP Packets in the destination host.
> I didnt investigate the packet_type example you provided but I hope I
> will be able to used for the purposes I explained.
If the type field of the struct packet_type you register ==
htons(ETH_P_ALL), then your packet handling function will be added to
the head of the ptype_all list.
As a result, it will see all incoming and outgoing packets - incoming
will be delivered to your function from netif_receive_skb() before the
IP/other packet handlers get to see it and outgoing packets will be
delivered from dev_queue_xmit() (which calls dev_queue_xmit_nit())
just before the packet is queued for sending by the NIC. This may work
for you.
I'm assuming all outgoing packets go through dev_queue_xmit(), though
that may not always be the case (someone more knowledgeable would have
to explain this).
Regards,
-- Asim
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: filtering packtes before OS takes care about them
2005-03-01 3:35 ` Asim Shankar
@ 2005-03-01 16:33 ` Pedro Fortuna
0 siblings, 0 replies; 14+ messages in thread
From: Pedro Fortuna @ 2005-03-01 16:33 UTC (permalink / raw)
To: netdev
This subject is rather new to me. Is there some literature about linux
kernel networking API that you would recommend?
thanks,
-Pedro Fortuna
On Mon, 28 Feb 2005 21:35:09 -0600, Asim Shankar <asimshankar@gmail.com> wrote:
> > In my case, I'll need to intercept all outgoing IP packets and change
> > them (including L2 frame) before they are passed to the network
> > interface driver.
> > The reverse operation is applied to incoming IP Packets in the destination host.
> > I didnt investigate the packet_type example you provided but I hope I
> > will be able to used for the purposes I explained.
>
> If the type field of the struct packet_type you register ==
> htons(ETH_P_ALL), then your packet handling function will be added to
> the head of the ptype_all list.
>
> As a result, it will see all incoming and outgoing packets - incoming
> will be delivered to your function from netif_receive_skb() before the
> IP/other packet handlers get to see it and outgoing packets will be
> delivered from dev_queue_xmit() (which calls dev_queue_xmit_nit())
> just before the packet is queued for sending by the NIC. This may work
> for you.
>
> I'm assuming all outgoing packets go through dev_queue_xmit(), though
> that may not always be the case (someone more knowledgeable would have
> to explain this).
>
> Regards,
>
> -- Asim
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: filtering packtes before OS takes care about them
2005-02-28 20:09 ` Asim Shankar
2005-03-01 0:30 ` Pedro Fortuna
@ 2005-03-05 14:08 ` Pedro Fortuna
2005-03-05 18:58 ` Asim Shankar
1 sibling, 1 reply; 14+ messages in thread
From: Pedro Fortuna @ 2005-03-05 14:08 UTC (permalink / raw)
To: Asim Shankar; +Cc: netdev
Asim,
I wasnt able to compile your packet_type_test.c :( I even tried your
scripts (i.e. make-native.sh and make-uml.sh), which seem to me that
proceeded to compile the example against the kernel source (which I
have installed and in place), but all I got was a huge list of errors
and warnings, and no .o compiled in the end.
./make-native.sh modules
./make-uml.sh modules
I used ubuntu 4.10 with kernel 2.6.8.1-3 and kernel source 2.6.8.1.
Any clues?
Thanks.
-Pedro Fortuna
On Mon, 28 Feb 2005 14:09:56 -0600, Asim Shankar <asimshankar@gmail.com> wrote:
> > i need a possibility to catch IP4 packets (from ethernet devices) before OS' netmodules (IP, UDP, TCP, ICMP, ARP, ROUTE, NETFILTER ...) takes care about them and
> > * to delete them from input buffer such that OS' netmodules can't receive them
> > * to modify packet headers and move packets to interface related output buffers
> > * to keep them in input buffers such that OS' netmodules can take care about them.
>
> You can process packets even before ip_rcv() gets them by registering
> your own packet handler (struct packet_type) using dev_add_pack(). I
> have a small sample at:
> http://limnos.csrd.uiuc.edu/notes/code-samples/samples/kernel/packet_type/packet_type_test.c
> This may not be the cleanest way, but it isn't that dirty either.
>
> Also see:
> http://www.phrack.org/show.php?p=55&a=12
>
> -- Asim
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: filtering packtes before OS takes care about them
2005-03-05 14:08 ` Pedro Fortuna
@ 2005-03-05 18:58 ` Asim Shankar
2005-03-05 19:36 ` Pedro Fortuna
0 siblings, 1 reply; 14+ messages in thread
From: Asim Shankar @ 2005-03-05 18:58 UTC (permalink / raw)
To: Pedro Fortuna; +Cc: netdev
> I wasnt able to compile your packet_type_test.c :
> all I got was a huge list of errors
> and warnings, and no .o compiled in the end.
Can you send the specific errors you got?
And is the kernel sources present in
/lib/modules/`uname -r`/build?
Regards,
-- Asim
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: filtering packtes before OS takes care about them
2005-03-05 18:58 ` Asim Shankar
@ 2005-03-05 19:36 ` Pedro Fortuna
[not found] ` <7bca1cb50503051729e3273d3@mail.gmail.com>
0 siblings, 1 reply; 14+ messages in thread
From: Pedro Fortuna @ 2005-03-05 19:36 UTC (permalink / raw)
To: Asim Shankar; +Cc: netdev
Hello Asim,
I tried again but this time in Fedora Core 3 (kernel 2.6.10-1.760_FC3)
and it went flawlessly.
I have a look into your example and also into the Phrack article you
mentioned and now I'm ready to begin some tests towards what I want to
implement.
It's absolutly clear you can fetch (and modify) packets before they
are delivered to the TCP/IP stack with a custom packet_type function,
but is it also possible to intercept just before they are passed to
the network driver?
Thanks,
-Pedro Fortuna
On Sat, 5 Mar 2005 12:58:23 -0600, Asim Shankar <asimshankar@gmail.com> wrote:
> > I wasnt able to compile your packet_type_test.c :
> > all I got was a huge list of errors
> > and warnings, and no .o compiled in the end.
>
> Can you send the specific errors you got?
> And is the kernel sources present in
> /lib/modules/`uname -r`/build?
>
> Regards,
>
> -- Asim
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: filtering packtes before OS takes care about them
2005-02-28 16:16 filtering packtes before OS takes care about them Weber Matthias
2005-02-28 17:38 ` bert hubert
2005-02-28 20:09 ` Asim Shankar
@ 2005-03-01 17:20 ` Stephen Hemminger
2 siblings, 0 replies; 14+ messages in thread
From: Stephen Hemminger @ 2005-03-01 17:20 UTC (permalink / raw)
To: Weber Matthias; +Cc: netdev
On Mon, 28 Feb 2005 17:16:57 +0100
"Weber Matthias" <weber@faps.uni-erlangen.de> wrote:
> Hi,
>
> i need a possibility to catch IP4 packets (from ethernet devices) before OS' netmodules (IP, UDP, TCP, ICMP, ARP, ROUTE, NETFILTER ...) takes care about them and
> * to delete them from input buffer such that OS' netmodules can't receive them
> * to modify packet headers and move packets to interface related output buffers
> * to keep them in input buffers such that OS' netmodules can take care about them.
>
> I would be thankfull for any hint, link or code example.
>
> Bye
> Matthias
If you need this as a "one off" type project, then another possibility is
to hook onto netif_rx with jprobe (part of the kprobe) to redirect traffic
to a local function first.
It wouldn't useable for a real production type protocol.
^ permalink raw reply [flat|nested] 14+ messages in thread
* AW: filtering packtes before OS takes care about them
@ 2005-02-28 18:59 Weber Matthias
2005-03-01 0:26 ` Thomas Graf
0 siblings, 1 reply; 14+ messages in thread
From: Weber Matthias @ 2005-02-28 18:59 UTC (permalink / raw)
To: bert hubert; +Cc: netdev
I need to develop a special gateway. It shall map exernal ips to internal ports and external ports to internal ips (kind of NAT but connections have to be established from external to internal network and vice versa!), so the sender,receveiver addresses and ports have to be changed off each package received. Afterwards these packets shall be resent via one (out of more) interfaces. Therefore kernel's IP stuff disturbs me, but because i want to use TCP/IP at the gateway itself too (the computer runs applications using IP), i still need it.
Thus the most easiest way should be to be the first one dealing those packets when they arrive. AFAIK before netfilter gets the packets the kernel's router already got them...
Hope i made may needs clear?
Thanks for help,
Matthias
-----Ursprüngliche Nachricht-----
Von: bert hubert [mailto:ahu@ds9a.nl]
Gesendet: Montag, 28. Februar 2005 18:38
An: Weber Matthias
Cc: netdev@oss.sgi.com
Betreff: Re: filtering packtes before OS takes care about them
On Mon, Feb 28, 2005 at 05:16:57PM +0100, Weber Matthias wrote:
> i need a possibility to catch IP4 packets (from ethernet devices)
> before OS' netmodules (IP, UDP, TCP, ICMP, ARP, ROUTE, NETFILTER ...)
> takes care about them and
Why? It helps if you tell us what you really want, or is this a research project?
The earliest place I know of is with tc filter, but that is a netfilter hook. So part of netfilter will "see" your code.
What you appear to be asking for is a packet filtering network adaptor?
These exist.
> * to modify packet headers and move packets to interface related
> output
> * buffers
Sure you want an operating system?
Good luck!
--
http://www.PowerDNS.com Open source, database driven DNS Software
http://netherlabs.nl Open and Closed source services
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: filtering packtes before OS takes care about them
2005-02-28 18:59 AW: " Weber Matthias
@ 2005-03-01 0:26 ` Thomas Graf
0 siblings, 0 replies; 14+ messages in thread
From: Thomas Graf @ 2005-03-01 0:26 UTC (permalink / raw)
To: Weber Matthias; +Cc: bert hubert, netdev
> I need to develop a special gateway. It shall map exernal ips to internal ports and external ports to internal ips (kind of NAT but connections have to be established from external to internal network and vice versa!), so the sender,receveiver addresses and ports have to be changed off each package received. Afterwards these packets shall be resent via one (out of more) interfaces. Therefore kernel's IP stuff disturbs me, but because i want to use TCP/IP at the gateway itself too (the computer runs applications using IP), i still need it.
I won't comment on the way you are about to solve your problem even if I
do think that it could be solved in a simpler way. In recent 2.6 kernels
the earliest filtering possibility is via the ingress qdisc right after
the skb has been received, see the ing_filter() call in netif_receive_skb(),
given you enable tc actions. Earlier kernels or if tc actions is not
enabled, the netfilter prerouting hook is used which gets invoked in the
ip code after some very basic sanity checks.
You can use the pedit action to modify the packet although the checksum
correction action is still missing which might bother you.
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2005-03-07 2:46 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-28 16:16 filtering packtes before OS takes care about them Weber Matthias
2005-02-28 17:38 ` bert hubert
2005-02-28 20:09 ` Asim Shankar
2005-03-01 0:30 ` Pedro Fortuna
2005-03-01 1:53 ` jamal
2005-03-01 3:35 ` Asim Shankar
2005-03-01 16:33 ` Pedro Fortuna
2005-03-05 14:08 ` Pedro Fortuna
2005-03-05 18:58 ` Asim Shankar
2005-03-05 19:36 ` Pedro Fortuna
[not found] ` <7bca1cb50503051729e3273d3@mail.gmail.com>
2005-03-06 2:04 ` Pedro Fortuna
2005-03-07 2:46 ` Pedro Fortuna
2005-03-01 17:20 ` Stephen Hemminger
-- strict thread matches above, loose matches on Subject: below --
2005-02-28 18:59 AW: " Weber Matthias
2005-03-01 0:26 ` Thomas Graf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).