From: wessels <> Date: Tue, 15 Oct 1996 10:57:52 +0000 (+0000) Subject: rearrange USE_ICMP defines X-Git-Tag: SQUID_3_0_PRE1~5652 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e97f40f4c3e673d5cbc1cd382a4b0c3044810c45;p=thirdparty%2Fsquid.git rearrange USE_ICMP defines --- diff --git a/src/icmp.cc b/src/icmp.cc index 6270652940..14ac4859b8 100644 --- a/src/icmp.cc +++ b/src/icmp.cc @@ -1,6 +1,6 @@ /* - * $Id: icmp.cc,v 1.20 1996/10/11 23:11:56 wessels Exp $ + * $Id: icmp.cc,v 1.21 1996/10/15 04:57:52 wessels Exp $ * * DEBUG: section 37 ICMP Routines * AUTHOR: Duane Wessels @@ -29,11 +29,14 @@ * */ -#if USE_ICMP #include "squid.h" #include "pinger.h" +int icmp_sock = -1; + +#if USE_ICMP + #define S_ICMP_ECHO 1 #define S_ICMP_ICP 2 #define S_ICMP_DOM 3 @@ -47,8 +50,6 @@ typedef struct _icmpQueueData { static icmpQueueData *IcmpQueueHead = NULL; -int icmp_sock = -1; - static void icmpRecv _PARAMS((int, void *)); static void icmpQueueSend _PARAMS((pingerEchoData * pkt, int len, @@ -56,88 +57,6 @@ static void icmpQueueSend _PARAMS((pingerEchoData * pkt, static void icmpSend _PARAMS((int fd, icmpQueueData * queue)); static void icmpHandleSourcePing _PARAMS((struct sockaddr_in * from, char *buf)); -void -icmpOpen(void) -{ - struct sockaddr_in S; - int namelen = sizeof(struct sockaddr_in); - pid_t pid; - int child_sock; - icmp_sock = comm_open(SOCK_DGRAM, - 0, - local_addr, - 0, - COMM_NONBLOCKING, - "ICMP Socket"); - if (icmp_sock < 0) { - debug(37, 0, "icmpOpen: icmp_sock: %s\n", xstrerror()); - return; - } - child_sock = comm_open(SOCK_DGRAM, - 0, - local_addr, - 0, - 0, - "ICMP Socket"); - if (child_sock < 0) { - debug(37, 0, "icmpOpen: child_sock: %s\n", xstrerror()); - return; - } - getsockname(icmp_sock, (struct sockaddr *) &S, &namelen); - if (comm_connect_addr(child_sock, &S) != COMM_OK) - fatal_dump(xstrerror()); - getsockname(child_sock, (struct sockaddr *) &S, &namelen); - if (comm_connect_addr(icmp_sock, &S) != COMM_OK) - fatal_dump(xstrerror()); - if ((pid = fork()) < 0) { - debug(29, 0, "icmpOpen: fork: %s\n", xstrerror()); - comm_close(icmp_sock); - comm_close(child_sock); - return; - } - if (pid == 0) { /* child */ - char *x = xcalloc(strlen(Config.debugOptions) + 32, 1); - sprintf(x, "SQUID_DEBUG=%s\n", Config.debugOptions); - putenv(x); - comm_close(icmp_sock); - dup2(child_sock, 0); - dup2(child_sock, 1); - comm_close(child_sock); - dup2(fileno(debug_log), 2); - fclose(debug_log); - enter_suid(); - execlp(Config.Program.pinger, "(pinger)", NULL); - debug(29, 0, "icmpOpen: %s: %s\n", Config.Program.pinger, xstrerror()); - _exit(1); - } - comm_close(child_sock); - commSetSelect(icmp_sock, - COMM_SELECT_READ, - (PF) icmpRecv, - (void *) -1, 0); - comm_set_fd_lifetime(icmp_sock, -1); - debug(29, 0, "Pinger socket opened on FD %d\n", icmp_sock); -} - -void -icmpClose(void) -{ - icmpQueueData *queue; - debug(29, 0, "Closing ICMP socket on FD %d\n", icmp_sock); - comm_close(icmp_sock); - commSetSelect(icmp_sock, - COMM_SELECT_READ, - NULL, - NULL, 0); - icmp_sock = -1; - while ((queue = IcmpQueueHead)) { - IcmpQueueHead = queue->next; - if (queue->free_func) - queue->free_func(queue->msg); - safe_free(queue); - } -} - static void icmpSendEcho(struct in_addr to, int opcode, char *payload, int len) { @@ -157,7 +76,6 @@ icmpRecv(int unused1, void *unused2) int n; pingerReplyData preply; static struct sockaddr_in F; - commSetSelect(icmp_sock, COMM_SELECT_READ, (PF) icmpRecv, @@ -191,7 +109,6 @@ icmpRecv(int unused1, void *unused2) } } - static void icmpQueueSend(pingerEchoData * pkt, int len, @@ -253,15 +170,50 @@ icmpSend(int fd, icmpQueueData * queue) } } +static void +icmpHandleSourcePing(struct sockaddr_in *from, char *buf) +{ + char *key; + StoreEntry *entry; + icp_common_t header; + char *url; + memcpy(&header, buf, sizeof(icp_common_t)); + url = buf + sizeof(icp_common_t); + if (neighbors_do_private_keys && header.reqnum) { + key = storeGeneratePrivateKey(url, METHOD_GET, header.reqnum); + } else { + key = storeGeneratePublicKey(url, METHOD_GET); + } + debug(37, 3, "icmpHandleSourcePing: from %s, key=%s\n", + inet_ntoa(from->sin_addr), + key); + if ((entry = storeGet(key)) == NULL) + return; + if (entry->lock_count == 0) + return; + /* call neighborsUdpAck even if ping_status != PING_WAITING */ + neighborsUdpAck(icmp_sock, + url, + &header, + from, + entry, + NULL, + 0); +} +#endif /* USE_ICMP */ + void icmpPing(struct in_addr to) { +#if USE_ICMP icmpSendEcho(to, S_ICMP_ECHO, NULL, 0); +#endif } void icmpSourcePing(struct in_addr to, icp_common_t * header, char *url) { +#if USE_ICMP char *payload; int len; int ulen; @@ -275,44 +227,100 @@ icmpSourcePing(struct in_addr to, icp_common_t * header, char *url) len += ulen + 1; icmpSendEcho(to, S_ICMP_ICP, payload, len); put_free_8k_page(payload); +#endif } void icmpDomainPing(struct in_addr to, char *domain) { +#if USE_ICMP debug(37, 3, "icmpDomainPing: '%s'\n", domain); icmpSendEcho(to, S_ICMP_DOM, domain, 0); +#endif } -static void -icmpHandleSourcePing(struct sockaddr_in *from, char *buf) +void +icmpOpen(void) { - char *key; - StoreEntry *entry; - icp_common_t header; - char *url; - memcpy(&header, buf, sizeof(icp_common_t)); - url = buf + sizeof(icp_common_t); - if (neighbors_do_private_keys && header.reqnum) { - key = storeGeneratePrivateKey(url, METHOD_GET, header.reqnum); - } else { - key = storeGeneratePublicKey(url, METHOD_GET); +#if USE_ICMP + struct sockaddr_in S; + int namelen = sizeof(struct sockaddr_in); + pid_t pid; + int child_sock; + icmp_sock = comm_open(SOCK_DGRAM, + 0, + local_addr, + 0, + COMM_NONBLOCKING, + "ICMP Socket"); + if (icmp_sock < 0) { + debug(37, 0, "icmpOpen: icmp_sock: %s\n", xstrerror()); + return; } - debug(37, 3, "icmpHandleSourcePing: from %s, key=%s\n", - inet_ntoa(from->sin_addr), - key); - if ((entry = storeGet(key)) == NULL) + child_sock = comm_open(SOCK_DGRAM, + 0, + local_addr, + 0, + 0, + "ICMP Socket"); + if (child_sock < 0) { + debug(37, 0, "icmpOpen: child_sock: %s\n", xstrerror()); return; - if (entry->lock_count == 0) + } + getsockname(icmp_sock, (struct sockaddr *) &S, &namelen); + if (comm_connect_addr(child_sock, &S) != COMM_OK) + fatal_dump(xstrerror()); + getsockname(child_sock, (struct sockaddr *) &S, &namelen); + if (comm_connect_addr(icmp_sock, &S) != COMM_OK) + fatal_dump(xstrerror()); + if ((pid = fork()) < 0) { + debug(29, 0, "icmpOpen: fork: %s\n", xstrerror()); + comm_close(icmp_sock); + comm_close(child_sock); return; - /* call neighborsUdpAck even if ping_status != PING_WAITING */ - neighborsUdpAck(icmp_sock, - url, - &header, - from, - entry, - NULL, - 0); + } + if (pid == 0) { /* child */ + char *x = xcalloc(strlen(Config.debugOptions) + 32, 1); + sprintf(x, "SQUID_DEBUG=%s\n", Config.debugOptions); + putenv(x); + comm_close(icmp_sock); + dup2(child_sock, 0); + dup2(child_sock, 1); + comm_close(child_sock); + dup2(fileno(debug_log), 2); + fclose(debug_log); + enter_suid(); + execlp(Config.Program.pinger, "(pinger)", NULL); + debug(29, 0, "icmpOpen: %s: %s\n", Config.Program.pinger, xstrerror()); + _exit(1); + } + comm_close(child_sock); + commSetSelect(icmp_sock, + COMM_SELECT_READ, + (PF) icmpRecv, + (void *) -1, 0); + comm_set_fd_lifetime(icmp_sock, -1); + debug(29, 0, "Pinger socket opened on FD %d\n", icmp_sock); +#endif } -#endif /* USE_ICMP */ +void +icmpClose(void) +{ +#if USE_ICMP + icmpQueueData *queue; + debug(29, 0, "Closing ICMP socket on FD %d\n", icmp_sock); + comm_close(icmp_sock); + commSetSelect(icmp_sock, + COMM_SELECT_READ, + NULL, + NULL, 0); + icmp_sock = -1; + while ((queue = IcmpQueueHead)) { + IcmpQueueHead = queue->next; + if (queue->free_func) + queue->free_func(queue->msg); + safe_free(queue); + } +#endif +} diff --git a/src/main.cc b/src/main.cc index 9ba0aa336e..c9d83b5be5 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,5 +1,5 @@ /* - * $Id: main.cc,v 1.95 1996/10/14 23:45:29 wessels Exp $ + * $Id: main.cc,v 1.96 1996/10/15 04:57:54 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -392,10 +392,8 @@ serverConnectionsOpen(void) } } clientdbInit(); -#if USE_ICMP icmpOpen(); netdbInit(); -#endif } void @@ -431,10 +429,8 @@ serverConnectionsClose(void) NULL, 0); theInIcpConnection = -1; } -#if USE_ICMP if (icmp_sock > -1) icmpClose(); -#endif } static void @@ -652,11 +648,13 @@ main(int argc, char **argv) for (;;) { if (rotate_pending) { ftpServerClose(); + icmpClose(); _db_rotate_log(); /* cache.log */ storeWriteCleanLog(); storeRotateLog(); /* store.log */ stat_rotate_log(); /* access.log */ (void) ftpInitialize(); + icmpOpen(); rotate_pending = 0; } if ((loop_delay = mainMaintenance()) < 0) diff --git a/src/neighbors.cc b/src/neighbors.cc index 4acf52f73a..4e2055060c 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,5 +1,5 @@ /* - * $Id: neighbors.cc,v 1.64 1996/10/14 00:28:34 wessels Exp $ + * $Id: neighbors.cc,v 1.65 1996/10/15 04:57:54 wessels Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -505,11 +505,9 @@ neighborsUdpPing(protodispatch_data * proto) debug(15, 6, "neighborsUdpPing: Source Ping: to %s for '%s'\n", host, url); echo_hdr.reqnum = reqnum; -#if USE_ICMP if (icmp_sock != -1) { icmpSourcePing(ia->in_addrs[ia->cur], &echo_hdr, url); } else { -#endif to_addr.sin_family = AF_INET; to_addr.sin_addr = ia->in_addrs[ia->cur]; to_addr.sin_port = htons(echo_port); @@ -521,9 +519,7 @@ neighborsUdpPing(protodispatch_data * proto) ICP_OP_SECHO, LOG_TAG_NONE, PROTO_NONE); -#if USE_ICMP } -#endif } else { debug(15, 6, "neighborsUdpPing: Source Ping: unknown host: %s\n", host); diff --git a/src/net_db.cc b/src/net_db.cc index f984cb8ba2..2909c54d35 100644 --- a/src/net_db.cc +++ b/src/net_db.cc @@ -1,8 +1,8 @@ -#if USE_ICMP - #include "squid.h" +#if USE_ICMP + #define NET_DB_TTL 300 #define NETDB_LOW_MARK 900 @@ -21,13 +21,6 @@ static void netdbHashLink _PARAMS((netdbEntry * n, char *hostname)); static void netdbHashUnlink _PARAMS((char *key)); static void netdbPurgeLRU _PARAMS((void)); -void -netdbInit(void) -{ - addr_table = hash_create((int (*)_PARAMS((char *, char *))) strcmp, 229, hash_string); - host_table = hash_create((int (*)_PARAMS((char *, char *))) strcmp, 467, hash_string); -} - static void netdbHashInsert(netdbEntry * n, struct in_addr addr) { @@ -123,7 +116,6 @@ netdbLRU(netdbEntry ** n1, netdbEntry ** n2) return (0); } - static void netdbPurgeLRU(void) { @@ -194,39 +186,6 @@ netdbSendPing(int fdunused, ipcache_addrs * ia, void *data) xfree(hostname); } -void -netdbPingSite(char *hostname) -{ - netdbEntry *n; - if ((n = netdbLookupHost(hostname)) != NULL) - if (n->next_ping_time > squid_curtime) - return; - ipcache_nbgethostbyname(hostname, - -1, - netdbSendPing, - (void *) xstrdup(hostname)); -} - -void -netdbHandlePingReply(struct sockaddr_in *from, int hops, int rtt) -{ - netdbEntry *n; - int N; - debug(37, 3, "netdbHandlePingReply: from %s\n", inet_ntoa(from->sin_addr)); - if ((n = netdbLookupAddr(from->sin_addr)) == NULL) - return; - N = ++n->n; - if (N > 100) - N = 100; - n->hops = ((n->hops * (N - 1)) + hops) / N; - n->rtt = ((n->rtt * (N - 1)) + rtt) / N; - n->pings_recv++; - debug(37, 3, "netdbHandlePingReply: %s; rtt=%5.1f hops=%4.1f\n", - n->network, - n->rtt, - n->hops); -} - static struct in_addr networkFromInaddr(struct in_addr a) { @@ -253,59 +212,60 @@ sortByHops(netdbEntry ** n1, netdbEntry ** n2) return 0; } +#endif /* USE_ICMP */ + +/* PUBLIC FUNCTIONS */ + void -netdbDump(StoreEntry * sentry) +netdbInit(void) +{ +#if USE_ICMP + addr_table = hash_create((int (*)_PARAMS((char *, char *))) strcmp, 229, hash_string); + host_table = hash_create((int (*)_PARAMS((char *, char *))) strcmp, 467, hash_string); +#endif +} + +void +netdbPingSite(char *hostname) { +#if USE_ICMP netdbEntry *n; - netdbEntry **list; - struct _net_db_name *x; - int k; - int i; - storeAppendPrintf(sentry, "{Network DB Statistics:\n"); - storeAppendPrintf(sentry, "{%-16.16s %9s %7s %5s %s}\n", - "Network", - "recv/sent", - "RTT", - "Hops", - "Hostnames"); - list = xcalloc(meta_data.netdb_addrs, sizeof(netdbEntry *)); - i = 0; - for (n = netdbGetFirst(addr_table); n; n = netdbGetNext(addr_table)) - *(list + i++) = n; - qsort((char *) list, - i, - sizeof(netdbEntry *), - (QS) sortByHops); - for (k = 0; k < i; k++) { - n = *(list + k); - storeAppendPrintf(sentry, "{%-16.16s %4d/%4d %7.1f %5.1f", - n->network, - n->pings_recv, - n->pings_sent, - n->rtt, - n->hops); - for (x = n->hosts; x; x = x->next) - storeAppendPrintf(sentry, " %s", x->name); - storeAppendPrintf(sentry, close_bracket); - } - storeAppendPrintf(sentry, close_bracket); - xfree(list); + if ((n = netdbLookupHost(hostname)) != NULL) + if (n->next_ping_time > squid_curtime) + return; + ipcache_nbgethostbyname(hostname, + -1, + netdbSendPing, + (void *) xstrdup(hostname)); +#endif } -int -netdbHops(struct in_addr addr) +void +netdbHandlePingReply(struct sockaddr_in *from, int hops, int rtt) { - netdbEntry *n = netdbLookupAddr(addr); - if (n && n->pings_recv) { - n->last_use_time = squid_curtime; - return (int) (n->hops + 0.5); - } - return 256; +#if USE_ICMP + netdbEntry *n; + int N; + debug(37, 3, "netdbHandlePingReply: from %s\n", inet_ntoa(from->sin_addr)); + if ((n = netdbLookupAddr(from->sin_addr)) == NULL) + return; + N = ++n->n; + if (N > 100) + N = 100; + n->hops = ((n->hops * (N - 1)) + hops) / N; + n->rtt = ((n->rtt * (N - 1)) + rtt) / N; + n->pings_recv++; + debug(37, 3, "netdbHandlePingReply: %s; rtt=%5.1f hops=%4.1f\n", + n->network, + n->rtt, + n->hops); +#endif } void netdbFreeMemory(void) { +#if USE_ICMP netdbEntry *n; netdbEntry **L1; hash_link *h; @@ -313,7 +273,6 @@ netdbFreeMemory(void) struct _net_db_name *x; int i = 0; int j; - L1 = xcalloc(meta_data.netdb_addrs, sizeof(netdbEntry *)); n = (netdbEntry *) hash_first(addr_table); while (n && i < meta_data.netdb_addrs) { @@ -330,7 +289,6 @@ netdbFreeMemory(void) xfree(n); } xfree(L1); - i = 0; L2 = xcalloc(meta_data.netdb_hosts, sizeof(hash_link *)); h = hash_first(host_table); @@ -345,9 +303,61 @@ netdbFreeMemory(void) xfree(h); } xfree(L2); - hashFreeMemory(addr_table); hashFreeMemory(host_table); +#endif } -#endif /* USE_ICMP */ +int +netdbHops(struct in_addr addr) +{ +#if USE_ICMP + netdbEntry *n = netdbLookupAddr(addr); + if (n && n->pings_recv) { + n->last_use_time = squid_curtime; + return (int) (n->hops + 0.5); + } +#endif + return 256; +} + +void +netdbDump(StoreEntry * sentry) +{ +#if USE_ICMP + netdbEntry *n; + netdbEntry **list; + struct _net_db_name *x; + int k; + int i; + storeAppendPrintf(sentry, "{Network DB Statistics:\n"); */ } */ + storeAppendPrintf(sentry, "{%-16.16s %9s %7s %5s %s}\n", + "Network", + "recv/sent", + "RTT", + "Hops", + "Hostnames"); + list = xcalloc(meta_data.netdb_addrs, sizeof(netdbEntry *)); + i = 0; + for (n = netdbGetFirst(addr_table); n; n = netdbGetNext(addr_table)) + *(list + i++) = n; + qsort((char *) list, + i, + sizeof(netdbEntry *), + (QS) sortByHops); + for (k = 0; k < i; k++) { + n = *(list + k); + storeAppendPrintf(sentry, "{%-16.16s %4d/%4d %7.1f %5.1f", /* } */ + n->network, + n->pings_recv, + n->pings_sent, + n->rtt, + n->hops); + for (x = n->hosts; x; x = x->next) + storeAppendPrintf(sentry, " %s", x->name); + storeAppendPrintf(sentry, close_bracket); + } + storeAppendPrintf(sentry, close_bracket); + xfree(list); +#endif +} diff --git a/src/stat.cc b/src/stat.cc index b7c4e8e9fe..6b1797c19e 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,6 +1,6 @@ /* - * $Id: stat.cc,v 1.86 1996/10/14 23:45:31 wessels Exp $ + * $Id: stat.cc,v 1.87 1996/10/15 04:57:57 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -378,10 +378,8 @@ stat_get(cacheinfo * obj, char *req, StoreEntry * sentry) httpReplyHeaderStats(sentry); } else if (strcmp(req, "filedescriptors") == 0) { statFiledescriptors(sentry); -#if USE_ICMP } else if (strcmp(req, "netdb") == 0) { netdbDump(sentry); -#endif } } @@ -644,10 +642,8 @@ memoryAccounted(void) request_pool.total_pages_allocated * request_pool.page_size + mem_obj_pool.total_pages_allocated * mem_obj_pool.page_size + meta_data.url_strings + -#if USE_ICMP meta_data.netdb_addrs * sizeof(netdbEntry) + meta_data.netdb_hosts * sizeof(struct _net_db_name) + -#endif meta_data.client_info * client_info_sz + meta_data.misc; } @@ -841,7 +837,6 @@ info_get(cacheinfo * obj, StoreEntry * sentry) disk_stats.total_pages_allocated * disk_stats.page_size >> 10, (disk_stats.total_pages_allocated - disk_stats.n_pages_in_use) * disk_stats.page_size >> 10); -#if USE_ICMP storeAppendPrintf(sentry, "{\t%-25.25s %7d x %4d bytes = %6d KB}\n", "NetDB Address Entries", meta_data.netdb_addrs, @@ -853,7 +848,7 @@ info_get(cacheinfo * obj, StoreEntry * sentry) meta_data.netdb_hosts, (int) sizeof(struct _net_db_name), (int) (meta_data.netdb_hosts * sizeof(struct _net_db_name) >> 10)); -#endif + storeAppendPrintf(sentry, "{\t%-25.25s %7d x %4d bytes = %6d KB}\n", "ClientDB Entries", meta_data.client_info, diff --git a/src/tools.cc b/src/tools.cc index dc982a98a7..ff3e21a46b 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -1,6 +1,6 @@ /* - * $Id: tools.cc,v 1.72 1996/10/13 06:19:52 wessels Exp $ + * $Id: tools.cc,v 1.73 1996/10/15 04:57:58 wessels Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -307,9 +307,7 @@ normal_shutdown(void) fdstatFreeMemory(); errorpageFreeMemory(); stmemFreeMemory(); -#if USE_ICMP netdbFreeMemory(); -#endif ipcacheFreeMemory(); fqdncacheFreeMemory(); debug(21, 0, "Squid Cache (Version %s): Exiting normally.\n",