Skip to contentSkip to conversation

DNATing packets sent to the NATing box

DISCUSSION [email protected] 3 participants 5 messages Dec 14, 2003 – Dec 21, 2003

lore
Share & tools
lore
#0 lore raw

I've a system that at its core has an UDP proxy that's the performance bottleneck. I wanted to use the DNAT kernel facilities to replace my code with the very tuned one on netfilter.

I'm adding a rule that says something like this:

/sbin/iptables -t nat -A PREROUTING -d myip -p udp -m udp --dport 5000 -j DNAT

		--to-destination otherip:18918

but the rule never see the packets (they never got to the chain)

I assume that it's because I've a socket listening on udp:5000, and it seems reasonable what's happening... I'd like to add a PREPREROUTING chain that is processed before deciding if the packet is for a local socket, can somebody give me a hint on where to look for it?

Saludos,
HoraPe
---
Horacio J. Peña
[email protected]
[email protected]

#1 lore raw
Quoted 8 lines · On Sat, 2003-12-13 at 19:52, [email protected] wrote:

I've a system that at its core has an UDP proxy that's the performance bottleneck. I wanted to use the DNAT kernel facilities to replace my code with the very tuned one on netfilter.

I'm adding a rule that says something like this:

/sbin/iptables -t nat -A PREROUTING -d myip -p udp -m udp --dport 5000 -j DNAT

		--to-destination otherip:18918

Try:

/sbin/iptables -t nat -A PREROUTING -d myip -p udp --dport 5000 -j DNAT --to otherip:18918

And ensure you are letting traffic for -d otherip -p udp --dport 18918 through FORWARD chain.

Quoted 3 lines

but the rule never see the packets (they never got to the chain)

I assume that it's because I've a socket listening on udp:5000, and it seems

Nope.

Quoted 3 lines

reasonable what's happening... I'd like to add a PREPREROUTING chain that is processed before deciding if the packet is for a local socket, can somebody give me a hint on where to look for it?

If it's for local, it can be seen in Mangle Prerouting, then Nat Prerouting, then Mangle Input, then Filter Input.

Quoted 5 lines

Saludos,
HoraPe
---
Horacio J. Pea
[email protected]

[email protected]

j

#2 lore raw
In reply to [email protected]
Quoted 9 lines · On Sunday 14 December 2003 12:52 am, [email protected] wrote:

I've a system that at its core has an UDP proxy that's the performance bottleneck. I wanted to use the DNAT kernel facilities to replace my code with the very tuned one on netfilter.

I'm adding a rule that says something like this:

/sbin/iptables -t nat -A PREROUTING -d myip -p udp -m udp --dport 5000 -j DNAT --to-destination otherip:18918

Quoted 6 lines

but the rule never see the packets (they never got to the chain)

I assume that it's because I've a socket listening on udp:5000, and it seems reasonable what's happening... I'd like to add a PREPREROUTING chain that is processed before deciding if the packet is for a local socket, can somebody give me a hint on where to look for it?

PREROUTING works exactly as the name suggests - it is applied to packets before the routing decision is made about whether they are local, or being
routed through the box. Therefore you *can* use the PREROUTING chain to
divert packets which would otherwise be accepted locally, so that they go to another machine, or else divert packets which would have gone somewhere else, so that they are accepted locally.

You say the rule never sees the packets... how do you know this? Are you
looking at the packet / byte counters, and they stay at zero all the time?

You also say you have a local process listening on port 5000 - is that getting any packets and responding to them, even with above rule in place?

Antony.

Signature · 6 lines
The first fifty percent of an engineering project takes ninety percent of the 
time, and the remaining fifty percent takes another ninety percent of the 
time.

                                                     Please reply to the list;
                                                           please don't CC me.
#3 lore raw
Quoted 23 lines
Quoted 9 lines

I've a system that at its core has an UDP proxy that's the performance bottleneck. I wanted to use the DNAT kernel facilities to replace my code with the very tuned one on netfilter.

I'm adding a rule that says something like this:

/sbin/iptables -t nat -A PREROUTING -d myip -p udp -m udp --dport 5000 -j DNAT --to-destination otherip:18918

Quoted 6 lines

but the rule never see the packets (they never got to the chain)

I assume that it's because I've a socket listening on udp:5000, and it seems reasonable what's happening... I'd like to add a PREPREROUTING chain that is processed before deciding if the packet is for a local socket, can somebody give me a hint on where to look for it?

PREROUTING works exactly as the name suggests - it is applied to packets before the routing decision is made about whether they are local, or being
routed through the box. Therefore you *can* use the PREROUTING chain to
divert packets which would otherwise be accepted locally, so that they go to another machine, or else divert packets which would have gone somewhere else, so that they are accepted locally.

Quoted 2 lines

You say the rule never sees the packets... how do you know this? Are you
looking at the packet / byte counters, and they stay at zero all the time?

Yes, and I've added a rule like this:

/sbin/iptables -t nat -A PREROUTING -j LOG and don't see the packets.

Quoted 2 lines

You also say you have a local process listening on port 5000 - is that getting any packets and responding to them, even with above rule in place?

Yes, it continues getting the packets.

Saludos,
HoraPe
---
Horacio J. Peña
[email protected]
[email protected]

#4 lore raw
In reply to [email protected]
Quoted 6 lines

I've a system that at its core has an UDP proxy that's the performance bottleneck. I wanted to use the DNAT kernel facilities to replace my code with the very tuned one on netfilter.

I'm adding a rule that says something like this:
/sbin/iptables -t nat -A PREROUTING -d myip -p udp -m udp --dport 5000 -j DNAT

Quoted 7 lines
		--to-destination otherip:18918

but the rule never see the packets (they never got to the chain)

I assume that it's because I've a socket listening on udp:5000, and it seems reasonable what's happening... I'd like to add a PREPREROUTING chain that is processed before deciding if the packet is for a local socket, can somebody give me a hint on where to look for it?

Thanks to everybody who helped. I've just wrote a new mangle target that does the translation and it's working great.

Saludos,
HoraPe
---
Horacio J. Peña
[email protected]
[email protected]