squid outgoing ip patch


Thanks for visiting! If you're new here, you may want to subscribe to my RSS feed. This blog posts regular information about web development, unix/linux, How-tos and patches. Go ahead, subscribe to my feed! You can also receive updates via email, instant messenger, skype or tweeter.

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

 

  • Digg
  • Reddit
  • del.icio.us
  • Slashdot
  • Spurl
  • StumbleUpon
  • Furl
  • description
  • Netscape
  • NewsVine
  • Technorati
  • YahooMyWeb
  • Simpy
If you enjoyed this post, you should subscribe to my full RSS Feeds

close Reblog this comment
blog comments powered by Disqus

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License

Technology Blogs - Blog Top Sites Search For Blogs, Submit Blogs, The Ultimate Blog Directory Blogarama - The Blog Directory 5starsblog Computers Blogs - Blog Flare blog search directory gob BlogHop