Handling a protocol through SNAT
I'm trying to get a protocol that doesn't deal well with NATS to work through an iptables Masq/SNAT. I've solved a number of small problems already in user-space but I think I'm stuck with two main problems that might require a kernel module.
The next hurdle I'm facing is that one part of the protocol involves the servers sending a packet to the client on a port the client is listening on. The client doesn't normally send anything from that port.
I've modified the client to send a packet from that port to each server on startup to tickle the SNAT. However that only seems to be working for the last server it contacts. It seems the SNAT is only looking at the local port not the remote ip address and port. I need to allow all the servers to reach the client.
This seems like a bug in iptables that it isn't considering every flow independently. Two remote ip addresses can contact the same port independently and should be treated as separate flows, not be bucketed together.
Barring fixing this in iptables, how can I create a manual rule to forward all packets coming in on the port the client is listening on to the client regardless of which server it's being sent from? The next step would be to make a module that did that automatically, but a manual rule would make me happy for now.
Signature · 1 line
greg
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Greg Stark
Quoted 3 lines
Quoted 1 line
The client doesn't normally send anything from that port.
Can't you do DNAT for this? W
the port is a random high port allocated dynamically with bind
so you really need some kind of conntrack/nat helper module...
Quoted 6 lines
Quoted 2 lines
This is definitely wrong. We implement 'symmetric NAPT'. There has to
be something about your particular setup that gives you this impression.Hm, perhaps I jumped the gun when I noticed it worked for the "last" one. in fact it seems to work for all of them for a while and then stop for some. Are the default timeouts really short? Like a couple minutes?
once the connectioin is established, the timeout is 5 days. For further information on TCP timeouts, please see /usr/src/linux/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
We try to use the normal TCP stack timeouts, so for SYN_SENT it's 2 minutes, etc.
Quoted 5 lines
Quoted 2 lines
iptables -t nat -A PREROUTING -j DNAT -p tcp --dport XYZ --to-destination client:port
I tried this, I must be doing something wrong though because it doesn't seem to do anything at all. No packets get through.
Try to debug further. There is something about your setup. Look at the incoming packets with tcpdump. Try if you find corresponding conntrack entries in /proc/net/ip_conntrack, etc.
Quoted 5 lines
iptables -t nat -A PREROUTING -j DNAT -p tcp --dport 33384 --to-destination 10.4.0.2:33384
Btw, there is a small bug, iptables says "Bad IP address 10.4.2" if I use that form.
This is not a bug. 10.4.2 is not an ip address.
Quoted 1 line
greg
please 'cc' the list when replying to this mail.
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