Does iptable save original destination address so that application could retrieve it?
Hi, folks,
Iptables could be instructed to intercept packets arrived on specified network interface, change the destination port to a specified local port so that the traffic is directed to appropriate application. For example Squid asks iptables to intercept traffic for port 80, frox asks iptable to intercept traffic for port 21, ASSP asks iptable to intercept traffic for port 80. My question is how could those application know the source and destination IP address of the packet in order to forward them on? Does iptable save original source/destination address somewhere so that application could retrieve it?
The answer of this question is very important to me. Thanks in advance for any tip!
Grace
Quoted 3 lines · Grace Li
Iptables could be instructed to intercept packets arrived on specified network interface, change the destination port to a specified local port so that the traffic is directed to appropriate application.
Yes.
Quoted 3 lines
For example Squid asks iptables to intercept traffic for port 80 frox asks iptable to intercept traffic for port 21, ASSP asks iptable to intercept traffic for port 80.
Not exacly.. but yes all these accept having iptables send them redirected traffic. It is you who need to insert the iptables rule for doing so.
Quoted 4 lines
My question is how could those application know the source and destination IP address of the packet in order to forward them on? Does iptable save original source/destination address somewhere so that application could retrieve it?
It does, and applications can ask for the original address details with a getsockopt call. See the LINUX_NETFILTER version of the clientNatLookup call in IPInterception.cc from the Squid-3 source tree for an example. Probably documented somewhere also.. the squid clientNatLookup function returns 0 if the connection was intercepted, -1 if not (normal connection).
Regards
Henrik