How to duplicate packets in PRE_ROUTING hook and send it to multiple machines in simpe way
I want to send tcp packets received on IP1: P1 to different machines say IP2:P2, IP3:P3. I have a kernel module which uses PRE_ROUTING and POST_ROUTING.But i am not very clear about how can i make copies of each tcp packet that i recieve in PRE_ROUTING and send it to these machines __efficiently__ ??
How to make copies ?? skb_clone,pskb_copy,skb_copy ?? i will have to change ip header before sending to other machines so which functions to be used ??
Or can i do it in some otherway without making copies of packet.
How to send those packets out ?? Where do i need to add these packets ?? The linked list of packets to be sent out from device ?? Or do i have access to other data structures from the original packet which i intercepted at PRE_ROUTING and and use some information which is there to add myother packets so that they will aslo go out ??
--Rohit
P.S. I have very good reasons for duplicating these tcp packets , so why to do this is really not the question : )
Quoted 6 lines · Rohit
I want to send tcp packets received on IP1: P1 to different machines say IP2:P2, IP3:P3. I have a kernel module which uses
PRE_ROUTINGand POST_ROUTING.But i am not very clear about how can i make copies of each tcp packet that i recieve inPRE_ROUTINGand send it to these machines__efficiently__??
Take http://marc.info/?l=netfilter-devel&m=119601957530762&w=2
It's not perfect yet, but is reported to do its job.
I was wondering if i copy buffer from PRE_ROUTING and call okfn with new buffer , okfn being the function pointer passed to my hooking function @ PRE_ROUTING,will this work always.?? I tried this with test module and it was working.but i am not sure if it is going to work always and what can be the issues with this approach.
So code snippet looks like this.
struct sk_buff * packet2 = skb_copy(*pskb);
if(packet2){
modify_packet(packet2); //modify ip addr ,port etc.
okfn(packet2);
}
This does send packet out . Is this correct way to achieve this ?? Are there any security or accounting related things that i am missing here.
--Rohit
Quoted 12 lines · Jan Engelhardt
Quoted 6 lines · Rohit
I want to send tcp packets received on IP1: P1 to different machines say IP2:P2, IP3:P3. I have a kernel module which uses
PRE_ROUTINGand POST_ROUTING.But i am not very clear about how can i make copies of each tcp packet that i recieve inPRE_ROUTINGand send it to these machines__efficiently__??Take http://marc.info/?l=netfilter-devel&m=119601957530762&w=2
It's not perfect yet, but is reported to do its job.