squid outgoing ip patch
Some time ago a client of mine was running squid on a system with multiple interfaces and ips. He wanted a setup where squid would use the same ip on which it received the connection to create the connection to the destination server for fetching the content.
Let's say we have 3 ips 1.1.1.1, 1.1.1.2 and squid listens on both interfaces. Now if a client would connect to the proxy server on ip 1.1.1.1 and request google.com, squid will use 1.1.1.1 to make the connection to google. If the client will connect to 1.1.1.2 squid will use 1.1.1.2 to connect to the destination server.
One way to do this would be using acls and tcp_outgoing_address
acl_ip1 src 1.1.1.1
acl_ip2 src 1.1.1.2
tcp_outgoing_address 1.1.1.1 acl_ip1
tcp_outgoing_address 1.1.1.2 acl_ip2
This is easy to do if you have just a few ips, but if you have a few hundred ips you get tired of writing those rules, and even if you generate them with a script I don't think squid would really like that many configuration options. It will probably take a lot of time to parse them and probably the performance will suffer on high traffic servers.So I came up with a patch to squid's source code that does this automatically without any need for setting up acls and tcp_outgoing_address. You are still able to use tcp_outgoing_address after applying this patch, because the patch is active only for those connections where the acl of tcp_outgoing_address does not match.
The patch was created for squid 2.5, but I think it can be adapted for 2.6
And here is the actual patch ( gziped ) : squid outgoing ip patch
download it, go to squid source folder and then:
gunzip squid_outgoing_ippatch.gz patch -p1 < squid_outgoing_ippatch
If you enjoyed this post, you should subscribe to my full RSS Feeds













Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment