]> git.ipfire.org Git - thirdparty/squid.git/blame - src/client_db.cc
increase debug level on host hopping debug message
[thirdparty/squid.git] / src / client_db.cc
CommitLineData
8eb58c9c 1
516350ca 2/*
f5b8bbc4 3 * $Id: client_db.cc,v 1.19 1997/10/25 17:22:35 wessels Exp $
516350ca 4 *
f43e2ec2 5 * DEBUG: section 0 Client Database
516350ca 6 * AUTHOR: Duane Wessels
7 *
8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
9 * --------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
13 * National Laboratory for Applied Network Research and funded by
14 * the National Science Foundation.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 *
30 */
31
c41d4b6d 32#include "squid.h"
33
34typedef struct _client_info {
35 char *key;
36 struct client_info *next;
37 struct in_addr addr;
985b7fb7 38 struct {
9b312a19 39 int result_hist[LOG_TYPE_MAX];
985b7fb7 40 int n_requests;
41 } Http, Icp;
c41d4b6d 42} ClientInfo;
43
365e5b34 44static hash_table *client_table = NULL;
f5b8bbc4 45static ClientInfo *clientdbAdd(struct in_addr addr);
c41d4b6d 46
47static ClientInfo *
48clientdbAdd(struct in_addr addr)
49{
50 ClientInfo *c;
51 c = xcalloc(1, sizeof(ClientInfo));
52 c->key = xstrdup(inet_ntoa(addr));
53 c->addr = addr;
54 hash_join(client_table, (hash_link *) c);
55 meta_data.client_info++;
56 return c;
57}
58
59void
60clientdbInit(void)
61{
19054954 62 if (client_table)
63 return;
603a02fd 64 client_table = hash_create((HASHCMP *) strcmp, 229, hash_string);
c41d4b6d 65 client_info_sz = sizeof(ClientInfo);
66}
67
68void
812ed90c 69clientdbUpdate(struct in_addr addr, log_type log_type, protocol_t p)
c41d4b6d 70{
429fdbec 71 char *key;
72 ClientInfo *c;
17a0a4ee 73 if (!Config.onoff.client_db)
429fdbec 74 return;
75 key = inet_ntoa(addr);
76 c = (ClientInfo *) hash_lookup(client_table, key);
c41d4b6d 77 if (c == NULL)
78 c = clientdbAdd(addr);
79 if (c == NULL)
80 debug_trap("clientdbUpdate: Failed to add entry");
812ed90c 81 if (p == PROTO_HTTP) {
985b7fb7 82 c->Http.n_requests++;
83 c->Http.result_hist[log_type]++;
812ed90c 84 } else if (p == PROTO_ICP) {
985b7fb7 85 c->Icp.n_requests++;
86 c->Icp.result_hist[log_type]++;
87 }
c41d4b6d 88}
89
90int
91clientdbDeniedPercent(struct in_addr addr)
92{
429fdbec 93 char *key;
7fdce58c 94 int n = 100;
429fdbec 95 ClientInfo *c;
17a0a4ee 96 if (!Config.onoff.client_db)
429fdbec 97 return 0;
98 key = inet_ntoa(addr);
99 c = (ClientInfo *) hash_lookup(client_table, key);
c41d4b6d 100 if (c == NULL)
101 return 0;
985b7fb7 102 if (c->Icp.n_requests > 100)
103 n = c->Icp.n_requests;
0ed39362 104 return 100 * c->Icp.result_hist[LOG_UDP_DENIED] / n;
c41d4b6d 105}
106
8eb58c9c 107void
c41d4b6d 108clientdbDump(StoreEntry * sentry)
109{
110 ClientInfo *c;
111 log_type l;
112 storeAppendPrintf(sentry, "{Cache Clients:\n");
113 c = (ClientInfo *) hash_first(client_table);
114 while (c) {
115 storeAppendPrintf(sentry, "{Address: %s}\n", c->key);
116 storeAppendPrintf(sentry, "{Name: %s}\n", fqdnFromAddr(c->addr));
c41d4b6d 117 storeAppendPrintf(sentry, "{ ICP Requests %d}\n",
985b7fb7 118 c->Icp.n_requests);
9b312a19 119 for (l = LOG_TAG_NONE; l < LOG_TYPE_MAX; l++) {
985b7fb7 120 if (c->Icp.result_hist[l] == 0)
121 continue;
122 storeAppendPrintf(sentry,
123 "{ %-20.20s %7d %3d%%}\n",
124 log_tags[l],
125 c->Icp.result_hist[l],
126 percent(c->Icp.result_hist[l], c->Icp.n_requests));
127 }
128 storeAppendPrintf(sentry, "{ HTTP Requests %d}\n",
129 c->Http.n_requests);
9b312a19 130 for (l = LOG_TAG_NONE; l < LOG_TYPE_MAX; l++) {
985b7fb7 131 if (c->Http.result_hist[l] == 0)
c41d4b6d 132 continue;
133 storeAppendPrintf(sentry,
134 "{ %-20.20s %7d %3d%%}\n",
135 log_tags[l],
985b7fb7 136 c->Http.result_hist[l],
137 percent(c->Http.result_hist[l], c->Http.n_requests));
c41d4b6d 138 }
7fdce58c 139 storeAppendPrintf(sentry, "{}\n");
c41d4b6d 140 c = (ClientInfo *) hash_next(client_table);
141 }
142 storeAppendPrintf(sentry, close_bracket);
143}