linux transproxy patches for squid, determining tcp_outgoing_address

From: Lennert Buytenhek <buytenh@dont-contact.us>
Date: Mon, 3 Nov 2003 11:35:11 -0500

Hi,

Earlier this year, I suggested it would be possible to automatically
determine tcp_outgoing_address in the transparent proxy patches for
squid, reducing the number of tunables. I then suggested to do it the
way I described in the quoted email below.

There is an easier way, however. Just create a UDP socket, and connect()
it to any random IP address (not zero). Then use getsockname(), which
will return the local IP address that will be used to connect to the
earlier-specified IP. This works on linux at least. Felt really
stupid when I found this out.

Not sure if this was addressed yet. FYI.

cheers,
Lennert

On Fri, Apr 25, 2003 at 11:47:22AM -0400, Lennert Buytenhek wrote:

[snip]
> - It is possible to automatically determine tcp_outgoing_address by
> doing an rtnetlink routing table lookup for the target IP address,
> and then using the 'src' RT attribute from the returned route.
>
> mara% /sbin/ip addr
> 1: lo: <LOOPBACK,UP> mtu 16436 qdisc noqueue
> link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
> inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
> 2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast qlen 100
> link/ether 00:02:1e:f2:96:41 brd ff:ff:ff:ff:ff:ff
> inet 132.229.231.13/22 brd 132.229.231.255 scope global eth0
> mara% /sbin/ip route get 132.229.8.6
> 132.229.8.6 via 132.229.231.1 dev eth0 src 132.229.231.13
> cache mtu 1500 advmss 1460
>
> I can provide sample code if needed.

[snip]
Received on Mon Nov 03 2003 - 10:59:27 MST

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:20:46 MST