netfilter hook forward packets
I'm writing a simple netfilter hook module to redirect the traffic thru a tunnel between 2 machines (B and C)
Assume that i dont want to config netfilter/iptable to do anything.
The path looks like:
Assume on A, i add a route to forward packet (from A<->D) to B
and on D, i add a route to forward packet (from A<->D) to C
My module will be running on machines B and C.
Here are the steps what i do in my module (running on B and C)
On machine B:
1. capture packet at NF_IP_PRE_ROUTING
2. receive packet from A->D
3. append one more ip/tcp headers from B->C to the packet
4. send it out
On machine C:
after i receive the packet, i will
5. remove the external ip/tcp headers
6. send it out to D
My question is at steps 3 and 5, after append/remove the packet and recalc the checksum, do i have to do something else relate to the socket/sock owner?
How to do steps 4 and 6 to send packet out?
Thank you very much for any help
Are you going to do the whole processing (appending headers and removing them) in the module or you plan to get it all out via sockets (on B and C)? Also, what kind of encapsulation do you think about? Remember, more complicated protocols mean more processing needed from your module. I think that IP over IP would be enough in most cases.
Hi Mara, thanks for quick response,
Yes, i plan to do the whole thing in the module (kernel 2.4 netfilter hook). No user level program involved.
My task is provide a tunnel between B and C.
that will include:
-get the packet
-expand the packet by adding 2 more headers [IP header|TCP header][orginal ip packet]
-send the new one out
Assume I have enough information to fill up those extra headers (ips,ports,seq,ack...)
I just don't know what functions should I call in my module in order to send the packet out on the wire.
I know I have to do something like:
-create new skb (skb_copy_expand, skb_put...)
-fill up headers
after this, what else should I do ? do i have to call skb_set_owner_w or something else related to skb->sk and skb->dev ?
and which function to send out the packet ?
THanks again. Please provide me some help.
You don't have to use any specific function to send it. You'll probably write a target. It doesn't really matter. What matters is the result (code) returned by your functions.
You just need to fill the packet (and the checksums). No need to run more things, with an exception, of course, when you need a specific thing done.
BTW In 2.6 there's ipt_REDIRECT. It may be interesting for you.
|All times are GMT -5. The time now is 08:06 PM.|