Skip to contentSkip to conversation

Changing packets with netfilter nf_hooks: can I avoid the forward hook?

DISCUSSION Mark Ryden 1 participant 1 message Jan 19, 2007 netfilter

lore
Share & tools
lore

Mark Ryden

author
#0 lore raw

Hello,
I had read the netfilter hacking HOWTO in:

(http://www.netfilter.org/documentation/HOWTO/netfilter-hacking-HOWTO-3.html).
I want to use the nf_hooks API for a simple purpose:

My goal is to catch all packets which are sent to machine A to some specified, known UDP port.
I want to send all these packets to a different machine, which we will call B; the IP of that machine is
also known beforehand. I also want to change that UDP port to a known port. I use successfully the PR_ROUTING hook to capture all packets which are destined to that UDP
specified port on machine A. Now, I can change the destination IP address of these captured packets to
machine B address (in the PRE_ROUTING hook function) and then catch them in a forward hook
,set the source IP address in the fw hook , and return NF_ACCPET so the packet will be sent.
My question is : is the forward hook a must? because as I understand , if I will set the
src address in the PRE_ROUTING hook to that of machine A (instead of the real source IP address)
and the destination address to the IP address of machine B, then it will enter the TCP/IP kernel stack, and this I want to avoid if possible (because we are talking about a very high load server and entering
the stack for a lot of packets has a high performance cost). So is there a way to send the packet out on the wire in the PRE_ROUTING hook so that it will not enter
the linux kernel networking stack?
Any help will be appreciated.

Mark