best place to tap all packets?
Hi all,
I wish to capture *all* packets flowing through a Linux system in order to act upon it (delay, drop, inject additional packets).
For incoming packets, I need to simply record some accounting/control/state information from the packets and then send them on their way up the stack.
For outgoing packets, I need to queue them and then based on the control information that I have gathered, drop them, or release them or inject other packets into the outgoing queues.
Currently, I see the following choices:
1. Hack Netfilter to capture these packets and QUEUE/steal(STOLEN) them? Then process them in userspace and reinject them if necessary.
Q. What are the latencies experienced in transferring packets to userspace? Are there numbers available?
2. Create a custom 'slice' to capture packets:
- For incoming packets this might in net_bh() or maybe a new bottom half that is scheduled instead of net_bh from netif_rx(). This new BH will then call net_bh after it is done with its processing.
- For outgoing packets this could be one of the ip_*_output() routines in ip_output.c that would pass the packet to my code which would then pass them to ip_finish_output (or something similar) when the packet needs to be sent out.
Does anybody have any comments on this? I am concerned about the latencies involved in moving all packets to userspace using netfilter.
Q. Is it possible to queue packets inside the kernel some place using netfilter? Maybe my kernel module could then process these packets.
Q. Whats the best way to capture ARP packets?
Thanks for you time.
Regards,
Amit
Signature · 4 lines
---------------------------------------------------------------------- Amit Kucheria akucheria@<NOSPAM>metricsystems.com Metric Systems Corp. 2320 Cousteau Court, Suite 201, Vista, CA 92083 ----------------------------------------------------------------------
Quoted 5 lines · Amit Kucheria
Hi all,
I wish to capture *all* packets flowing through a Linux system in order to act upon it (delay, drop, inject additional packets).
Quoted 7 lines
For incoming packets, I need to simply record some accounting/control/state information from the packets and then send them on their way up the stack.
For outgoing packets, I need to queue them and then based on the control information that I have gathered, drop them, or release them or inject other packets into the outgoing queues.
so why don't you use the already existing framework of the 'tc' system in the linux kernel? You can implement new queue disciplines, etc.
Quoted 2 lines
1. Hack Netfilter to capture these packets and QUEUE/steal(STOLEN) them? Then process them in userspace and reinject them if necessary.
This is fine for low bandwidth. You don't want to do 100MBit with that mechanism.
Quoted 2 lines
Q. What are the latencies experienced in transferring packets to userspace? Are there numbers available?
huge, non-deterministic. You cannot tell how long it will take until your userspace process will be scheduled again, since this depends on what's going on elsewhere on that system.
Quoted 8 lines
2. Create a custom 'slice' to capture packets:
- For incoming packets this might innet_bh()or maybe a new bottom half that is scheduled instead ofnet_bhfromnetif_rx(). This new BH will then callnet_bhafter it is done with its processing.
- For outgoing packets this could be one of the ip_*_output() routines inip_output.cthat would pass the packet to my code which would then pass them toip_finish_output(or something similar) when the packet needs to be sent out.
again, why don't use the tc system?
Quoted 2 lines
Does anybody have any comments on this? I am concerned about the latencies involved in moving all packets to userspace using netfilter.
yes, I agree with this concern.
Quoted 2 lines
Q. Is it possible to queue packets inside the kernel some place using netfilter? Maybe my kernel module could then process these packets.
well, you can register a new queue handler with netfilter (ip_queue ist just _one_ possible queue handler implementation) that queues the packets in-kernel, and a kernel thread that works over that queue.
Quoted 1 line
Q. Whats the best way to capture ARP packets?
there are netfilter hooks in the ARP code... dunno whether this is the best way. At least it's a clean way.
Quoted 2 lines
Regards,
Amit
Signature · 5 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie