From: wessels <> Date: Tue, 5 Dec 2000 15:55:47 +0000 (+0000) Subject: parse_peer() was checking for a self-configured peer, but its not X-Git-Tag: SQUID_3_0_PRE1~1747 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b263bd3f0472e49f96355a92c37328e973b849d5;p=thirdparty%2Fsquid.git parse_peer() was checking for a self-configured peer, but its not safe to call getMyHostname() before we parsed the whole config file. Therefore, I moved this check into neighbors_open(). --- diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 4c06a59913..a59446588e 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,6 +1,6 @@ /* - * $Id: cache_cf.cc,v 1.358 2000/12/05 06:24:00 wessels Exp $ + * $Id: cache_cf.cc,v 1.359 2000/12/05 08:55:47 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -1028,8 +1028,6 @@ parse_peer(peer ** head) char *token = NULL; peer *p; int i; - sockaddr_in_list *s; - const char *me = getMyHostname(); p = memAllocate(MEM_PEER); p->http_port = CACHE_HTTP_PORT; p->icp.port = CACHE_ICP_PORT; @@ -1045,17 +1043,6 @@ parse_peer(peer ** head) p->http_port = (u_short) i; i = GetInteger(); p->icp.port = (u_short) i; - if (strcmp(p->host, me) == 0) { - for (s = Config.Sockaddr.http; s; s = s->next) { - if (p->http_port != ntohs(s->s.sin_port)) - continue; - debug(15, 1) ("parse_peer: Peer looks like myself: Ignoring %s %s/%d/%d\n", - neighborTypeStr(p), p->host, p->http_port, p->icp.port); - xfree(p->host); - memFree(p, MEM_PEER); - return; - } - } while ((token = strtok(NULL, w_space))) { if (!strcasecmp(token, "proxy-only")) { p->options.proxy_only = 1; diff --git a/src/neighbors.cc b/src/neighbors.cc index 7a742213f5..95d03ed857 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,6 +1,6 @@ /* - * $Id: neighbors.cc,v 1.289 2000/12/05 06:24:00 wessels Exp $ + * $Id: neighbors.cc,v 1.290 2000/12/05 08:55:47 wessels Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -351,9 +351,28 @@ neighbors_open(int fd) struct sockaddr_in name; socklen_t len = sizeof(struct sockaddr_in); struct servent *sep = NULL; + const char *me = getMyHostname(); + peer *this; + peer *next; memset(&name, '\0', sizeof(struct sockaddr_in)); if (getsockname(fd, (struct sockaddr *) &name, &len) < 0) debug(15, 1) ("getsockname(%d,%p,%p) failed.\n", fd, &name, &len); + for (this = Config.peers; this; this = next) { + sockaddr_in_list *s; + next = this->next; + if (0 != strcmp(this->host, me)) + continue; + for (s = Config.Sockaddr.http; s; s = s->next) { + if (this->http_port != ntohs(s->s.sin_port)) + continue; + debug(15, 1) ("WARNING: Peer looks like this host\n"); + debug(15, 1) (" Ignoring %s %s/%d/%d\n", + neighborTypeStr(this), this->host, this->http_port, + this->icp.port); + neighborRemove(this); + } + } + peerRefreshDNS((void *) 1); if (0 == echo_hdr.opcode) { echo_hdr.opcode = ICP_SECHO;