All of lore.kernel.org
 help / color / mirror / Atom feed
* Obtain original address from redirected connection
@ 2006-05-02  5:54 Pedro Werneck
  2006-05-02  6:36 ` Petr Pisar
  2006-05-04 18:51 ` Pascal Hambourg
  0 siblings, 2 replies; 3+ messages in thread
From: Pedro Werneck @ 2006-05-02  5:54 UTC (permalink / raw)
  To: netfilter


Hi


I have a daemon, a sort of proxy, written in Python, who receives
redirected connections with a rule like this:

iptables -t nat -A PREROUTING -j DNAT -p TCP -s source --to-destination host:port

The problem is that I need access to the original destination address,
but I could not find a way to do that when I wrote the daemon. Someone
suggested me using ULOG and parsing the address from ulogd logfile, and
this worked for some time, but now I have several simmultaneous
connections to the daemon and things get out of sync very easily when
reading the file.

Someone suggested using SO_ORIGINAL_DST. The constant is not available
in Python socket module, so I used the value 80, from iptables_ipv4.h
headers. The problem now is that the getsockopt() call doesn't work with
any values for 'level' parameter. First I tried 0 and 6, but they give
the errors 'Invalid Argument' and 'Protocol not available' respectively.
Just for testing I tried all other values from /etc/protocols and they
give 'Operation Not Supported'.


Is it possible to do this with SO_ORIGINAL_DST, or is there any other
approach for obtaining the original address ?


Thanks for any help

-- 
Pedro Werneck


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Obtain original address from redirected connection
  2006-05-02  5:54 Obtain original address from redirected connection Pedro Werneck
@ 2006-05-02  6:36 ` Petr Pisar
  2006-05-04 18:51 ` Pascal Hambourg
  1 sibling, 0 replies; 3+ messages in thread
From: Petr Pisar @ 2006-05-02  6:36 UTC (permalink / raw)
  To: netfilter

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Pedro Werneck wrote:
> I have a daemon, a sort of proxy, written in Python, who receives
> redirected connections with a rule like this:
> 
> iptables -t nat -A PREROUTING -j DNAT -p TCP -s source --to-destination host:port
> 
> The problem is that I need access to the original destination address,
> but I could not find a way to do that when I wrote the daemon.
[...]
> Is it possible to do this with SO_ORIGINAL_DST, or is there any other
> approach for obtaining the original address ?
> 

SO_ORIGINAL_DST works only on local REDIRECT. If you do NAT and run
proxy on the same machine use REDIRECT instead. Otherwise you need an
silly side channel for delivering original address. (Maybe create IP
tunnel betwean NATing machine and proxy machine and then REDIRECT this
traffic on proxy machine.)

- -- Petr
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEVv3zuR4f4nEwzHIRArLeAKCAKSVvmKaQCe/pE5HDeHFc/Vw0swCfdy9Q
t8czUPh+btwIf1dEGKlp9/M=
=TbTl
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Obtain original address from redirected connection
  2006-05-02  5:54 Obtain original address from redirected connection Pedro Werneck
  2006-05-02  6:36 ` Petr Pisar
@ 2006-05-04 18:51 ` Pascal Hambourg
  1 sibling, 0 replies; 3+ messages in thread
From: Pascal Hambourg @ 2006-05-04 18:51 UTC (permalink / raw)
  To: netfilter

[Sorry for the late answer, I just subscribed to the list]

Hello,

Pedro Werneck wrote :
> 
> I have a daemon, a sort of proxy, written in Python, who receives
> redirected connections with a rule like this:
> 
> iptables -t nat -A PREROUTING -j DNAT -p TCP -s source --to-destination host:port
> 
> The problem is that I need access to the original destination address,

You can parse /proc/net/ip_conntrack on the NAT box, which contains the 
  list of the connections currently handled by conntrack/NAT. This is 
how Squid retrieves the original destination address when running in 
transparent mode.
Note : on "recent" kernels you need root privileges to read this file.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-05-04 18:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-02  5:54 Obtain original address from redirected connection Pedro Werneck
2006-05-02  6:36 ` Petr Pisar
2006-05-04 18:51 ` Pascal Hambourg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.