Hello,
I modified squid to prevent that, when working as both Accelerator and
Proxy, and a host that uses squid as a Proxy requests a page that squid
accelerates, squid reconnects to itself so it uses two connections (one as
proxy and another as accelerator). This patch (for squid-1.0.8) reduces that
case to one connection doing all the work. I've been using it in my proxy for
a few weeks and works fine (last version I sent had a couple of bugs).
Javier Achirica
diff -c src.orig/icp.c src/icp.c
*** src.orig/icp.c Tue Aug 20 12:13:55 1996
--- src/icp.c Tue Aug 20 12:08:38 1996
***************
*** 1572,1577 ****
--- 1572,1606 ----
* if the request should be freed later. */
}
}
+ /* see if we running in AccelWithProxy, if so maybe a proxy request to the accel */
+ if (getAccelWithProxy() && (*request != '/')) {
+ int i, j;
+ request_t *req;
+ struct hostent *hp;
+
+ if ((req = urlParse(icpState->method, request)) == NULL) {
+ icpState->url = xcalloc(strlen(request) + 1, 1);
+ strcpy(icpState->url, request);
+ return 1;
+ }
+
+ if (req->protocol == PROTO_HTTP && req->port == getHttpPortNum() &&
+ (hp = ipcache_gethostbyname(req->host, IP_LOOKUP_IF_MISS)) != NULL) {
+ for (i = 0; i < num_local_addrs; i++)
+ for (j = 0; hp->h_addr_list[j]; j++)
+ if (((struct in_addr *)hp->h_addr_list[j])->s_addr == local_addrs[i].s_addr) {
+ i = num_local_addrs + 1;
+ break;
+ }
+ if (i > num_local_addrs) {
+ if (free_request)
+ safe_free(request);
+ request = xstrdup(req->urlpath);
+ free_request = 1;
+ }
+ }
+ put_free_request_t(req);
+ }
/* see if we running in httpd_accel_mode, if so got to convert it to URL */
if (httpd_accel_mode && *request == '/') {
if (!vhost_mode) {
diff -c src.orig/main.c src/main.c
*** src.orig/main.c Tue Aug 20 12:13:55 1996
--- src/main.c Tue Aug 20 12:08:39 1996
***************
*** 121,130 ****
--- 121,132 ----
int unbuffered_logs = 1; /* debug and hierarhcy unbuffered by default */
int shutdown_pending = 0; /* set by SIGTERM handler (shut_down()) */
int reread_pending = 0; /* set by SIGHUP handler */
+ int num_local_addrs = 0;
char version_string[] = SQUID_VERSION;
char appname[] = "squid";
char localhost[] = "127.0.0.1";
struct in_addr local_addr;
+ struct in_addr *local_addrs = NULL;
/* for error reporting from xmalloc and friends */
extern void (*failure_notify) _PARAMS((char *));
***************
*** 295,300 ****
--- 298,322 ----
debug(1, 1, "Accepting HTTP connections on FD %d.\n",
theHttpConnection);
+ if (getAccelWithProxy()) {
+ if (getTcpIncomingAddr().s_addr == INADDR_ANY) {
+ int i;
+ struct ifconf ifc;
+ char buff[1024];
+ ifc.ifc_len = sizeof(buff);
+ ifc.ifc_buf = buff;
+ if (ioctl(theHttpConnection, SIOCGIFCONF, &ifc) < 0)
+ fatal("Cannot get interface list");
+ num_local_addrs = ifc.ifc_len / sizeof(struct ifreq);
+ local_addrs = xmalloc (num_local_addrs * sizeof(struct in_addr));
+ for (i = 0; i < num_local_addrs; i++)
+ local_addrs[i] = ((struct sockaddr_in *)&ifc.ifc_req[i].ifr_addr)->sin_addr;
+ } else {
+ num_local_addrs = 1;
+ local_addrs = xmalloc(sizeof(struct in_addr));
+ local_addrs[0] = getTcpIncomingAddr();
+ }
+ }
if (!httpd_accel_mode || getAccelWithProxy()) {
if ((port = getIcpPortNum()) > 0) {
theInIcpConnection = comm_open(COMM_NONBLOCKING | COMM_DGRAM,
***************
*** 365,370 ****
--- 387,396 ----
0);
theInIcpConnection = -1;
}
+ if (getAccelWithProxy()) {
+ num_local_addrs = 0;
+ safe_free (local_addrs);
+ }
}
static void mainReinitialize()
diff -c src.orig/squid.h src/squid.h
*** src.orig/squid.h Tue Aug 20 12:13:56 1996
--- src/squid.h Tue Aug 20 12:12:30 1996
***************
*** 126,131 ****
--- 126,134 ----
#include <sys/select.h>
#endif
+ #include <sys/sockio.h>
+ #include <net/if.h>
+
#if defined(__STRICT_ANSI__)
#include <stdarg.h>
#else
***************
*** 248,258 ****
--- 251,263 ----
extern int opt_reload_hit_only; /* main.c */
extern int opt_dns_tests; /* main.c */
extern int opt_foreground_rebuild; /* main.c */
+ extern int num_local_addrs; /* main.c */
extern int opt_syslog_enable; /* main.c */
extern int vhost_mode; /* main.c */
extern char version_string[]; /* main.c */
extern char appname[]; /* main.c */
extern struct in_addr local_addr; /* main.c */
+ extern struct in_addr *local_addrs; /* main.c */
extern char localhost[];
Received on Tue Aug 20 1996 - 13:52:58 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:32:49 MST