Search code examples
linuxsquid

squid tcp_outgoing_address fails with "(22) Invalid argument"


Hello for all you people,

I am setting in Squid-Proxy two outputs internet. Below is a "diagram" of the final result I want to get:

SERVER1: SQUID SERVER
SERVER2: Internet2

 :: Client :: ----- SERVER1 ---> INTERNET (MODEM)
                        v
                        |
                        | -----> SERVER2 ----> INTERNET (MODEM 2)

I've configured in squid.conf the following lines:

acl route_alt dstdomain .whatismyip.com
tcp_outgoing_address <IP_SERVER2> route_alt

Restarting Squid and trying to access the site, returns me the following error: "(99) Can not assign requested address"

So googling, I found and did the following: echo 1> / proc/sys/net/ipv4/ip_nonlocal_bind

Now trying to access the site, returns me the following error: "(22) Invalid argument"

These errors, only "(99) Can not assign requested address" shows me in /var/log/squid/cache.log. The other did not find it anywhere.

Strace'ing I found the following:

connect(267, {sa_family=AF_INET, sin_port=htons(80),
sin_addr=inet_addr("72.233.89.199")}, 16) = -1 EINVAL (Invalid
argument)

Squid version is 3.1.19 Linux version: Fedora 15 64 bits kernel version: 2.6.38.6-26.rc1

Any help is appreciate.

Thanks


Solution

  • tcp_outgoing_address must be used to specify the local IP for outgoing connections, you can't use foreign IPs there. If you want to control the routing with Squid you should do this:

    First, you need an additional IP address in SERVER1 to use for the communication via SERVER2. Then add in squid.conf:

    tcp_outgoing_address IP2_SERVER1 ACL
    

    After that you have to configure routing:

    ip rule add table 100 from IP2_SERVER1
    ip route add table 100 default via IP_SERVER2
    

    The last two lines set the routing when the packets have IP2_SERVER1 as source.