~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/client_db.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2009-09-24 14:51:06 UTC
  • mfrom: (1.1.12 upstream)
  • mto: (20.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20090924145106-38jgrzmj0d73pha5
Tags: 3.1.0.13-1
* Upload to experimental

* New upstream release
  - Fixes Follow-X-Forwarded-For support (Closes: #523943)
  - Adds IPv6 support (Closes: #432351)

* debian/rules
  - Removed obsolete configuration options
  - Enable db and radius basic authentication modules

* debian/patches/01-cf.data.debian
  - Adapted to new upstream version

* debian/patches/02-makefile-defaults
  - Adapted to new upstream version

* debian/{squid.postinst,squid.rc,README.Debian,watch}
  - Updated references to squid 3.1

* debian/squid3.install
  - Install CSS file for error pages
  - Install manual pages for new authentication modules

* debian/squid3-common.install
  - Install documented version of configuration file in /usr/share/doc/squid3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
1
/*
3
 
 * $Id: client_db.cc,v 1.71 2007/09/21 11:41:52 amosjeffries Exp $
 
2
 * $Id$
4
3
 *
5
4
 * DEBUG: section 0     Client Database
6
5
 * AUTHOR: Duane Wessels
21
20
 *  it under the terms of the GNU General Public License as published by
22
21
 *  the Free Software Foundation; either version 2 of the License, or
23
22
 *  (at your option) any later version.
24
 
 *  
 
23
 *
25
24
 *  This program is distributed in the hope that it will be useful,
26
25
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
26
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28
27
 *  GNU General Public License for more details.
29
 
 *  
 
28
 *
30
29
 *  You should have received a copy of the GNU General Public License
31
30
 *  along with this program; if not, write to the Free Software
32
31
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
36
35
#include "squid.h"
37
36
#include "event.h"
38
37
#include "CacheManager.h"
 
38
#include "ClientInfo.h"
39
39
#include "SquidTime.h"
40
40
#include "Store.h"
41
41
 
42
42
 
43
43
static hash_table *client_table = NULL;
44
44
 
45
 
static ClientInfo *clientdbAdd(struct IN_ADDR addr);
 
45
static ClientInfo *clientdbAdd(const IpAddress &addr);
46
46
static FREE clientdbFreeItem;
47
47
static void clientdbStartGC(void);
48
48
static void clientdbScheduledGC(void *);
56
56
 
57
57
static ClientInfo *
58
58
 
59
 
clientdbAdd(struct IN_ADDR addr)
 
59
clientdbAdd(const IpAddress &addr)
60
60
{
61
61
    ClientInfo *c;
 
62
    char *buf = new char[MAX_IPSTRLEN];
62
63
    c = (ClientInfo *)memAllocate(MEM_CLIENT_INFO);
63
 
    c->hash.key = xstrdup(inet_ntoa(addr));
 
64
    c->hash.key = addr.NtoA(buf,MAX_IPSTRLEN);
64
65
    c->addr = addr;
65
66
    hash_join(client_table, &c->hash);
66
67
    statCounter.client_http.clients++;
67
68
 
68
 
    if ((statCounter.client_http.clients > max_clients) && !cleanup_running && cleanup_scheduled < 2)
69
 
    {
 
69
    if ((statCounter.client_http.clients > max_clients) && !cleanup_running && cleanup_scheduled < 2) {
70
70
        cleanup_scheduled++;
71
71
        eventAdd("client_db garbage collector", clientdbScheduledGC, NULL, 90, 0);
72
72
    }
74
74
    return c;
75
75
}
76
76
 
 
77
static void
 
78
clientdbRegisterWithCacheManager(void)
 
79
{
 
80
    CacheManager::GetInstance()->
 
81
    registerAction("client_list", "Cache Client List", clientdbDump, 0, 1);
 
82
}
 
83
 
77
84
void
78
85
clientdbInit(void)
79
86
{
 
87
    clientdbRegisterWithCacheManager();
 
88
 
80
89
    if (client_table)
81
90
        return;
82
91
 
83
92
    client_table = hash_create((HASHCMP *) strcmp, CLIENT_DB_HASH_SIZE, hash_string);
84
 
}
85
 
 
86
 
void
87
 
clientdbRegisterWithCacheManager(CacheManager & manager)
88
 
{
89
 
    manager.registerAction("client_list",
90
 
                           "Cache Client List",
91
 
                           clientdbDump,
92
 
                           0, 1);
93
 
}
94
 
 
95
 
void
96
 
 
97
 
clientdbUpdate(struct IN_ADDR addr, log_type ltype, protocol_t p, size_t size)
98
 
{
99
 
    char *key;
 
93
 
 
94
}
 
95
 
 
96
void
 
97
clientdbUpdate(const IpAddress &addr, log_type ltype, protocol_t p, size_t size)
 
98
{
 
99
    char key[MAX_IPSTRLEN];
100
100
    ClientInfo *c;
101
101
 
102
102
    if (!Config.onoff.client_db)
103
103
        return;
104
104
 
105
 
    key = inet_ntoa(addr);
 
105
    addr.NtoA(key,MAX_IPSTRLEN);
106
106
 
107
107
    c = (ClientInfo *) hash_lookup(client_table, key);
108
108
 
112
112
    if (c == NULL)
113
113
        debug_trap("clientdbUpdate: Failed to add entry");
114
114
 
115
 
    if (p == PROTO_HTTP)
116
 
    {
 
115
    if (p == PROTO_HTTP) {
117
116
        c->Http.n_requests++;
118
117
        c->Http.result_hist[ltype]++;
119
118
        kb_incr(&c->Http.kbytes_out, size);
120
119
 
121
120
        if (logTypeIsATcpHit(ltype))
122
121
            kb_incr(&c->Http.hit_kbytes_out, size);
123
 
    } else if (p == PROTO_ICP)
124
 
    {
 
122
    } else if (p == PROTO_ICP) {
125
123
        c->Icp.n_requests++;
126
124
        c->Icp.result_hist[ltype]++;
127
125
        kb_incr(&c->Icp.kbytes_out, size);
140
138
 * -1.  To get the current value, simply call with delta = 0.
141
139
 */
142
140
int
143
 
 
144
 
clientdbEstablished(struct IN_ADDR addr, int delta)
 
141
clientdbEstablished(const IpAddress &addr, int delta)
145
142
{
146
 
    char *key;
 
143
    char key[MAX_IPSTRLEN];
147
144
    ClientInfo *c;
148
145
 
149
146
    if (!Config.onoff.client_db)
150
147
        return 0;
151
148
 
152
 
    key = inet_ntoa(addr);
 
149
    addr.NtoA(key,MAX_IPSTRLEN);
153
150
 
154
151
    c = (ClientInfo *) hash_lookup(client_table, key);
155
152
 
156
 
    if (c == NULL)
 
153
    if (c == NULL) {
157
154
        c = clientdbAdd(addr);
 
155
    }
158
156
 
159
157
    if (c == NULL)
160
158
        debug_trap("clientdbUpdate: Failed to add entry");
167
165
#define CUTOFF_SECONDS 3600
168
166
int
169
167
 
170
 
clientdbCutoffDenied(struct IN_ADDR addr)
 
168
clientdbCutoffDenied(const IpAddress &addr)
171
169
{
172
 
    char *key;
 
170
    char key[MAX_IPSTRLEN];
173
171
    int NR;
174
172
    int ND;
175
173
    double p;
178
176
    if (!Config.onoff.client_db)
179
177
        return 0;
180
178
 
181
 
    key = inet_ntoa(addr);
 
179
    addr.NtoA(key,MAX_IPSTRLEN);
182
180
 
183
181
    c = (ClientInfo *) hash_lookup(client_table, key);
184
182
 
231
229
    return aLogType;
232
230
}
233
231
 
234
 
 
235
232
void
236
233
clientdbDump(StoreEntry * sentry)
237
234
{
 
235
    const char *name;
238
236
    ClientInfo *c;
239
237
    log_type l;
240
238
    int icp_total = 0;
246
244
 
247
245
    while ((c = (ClientInfo *) hash_next(client_table))) {
248
246
        storeAppendPrintf(sentry, "Address: %s\n", hashKeyStr(&c->hash));
249
 
        storeAppendPrintf(sentry, "Name:    %s\n", fqdnFromAddr(c->addr));
 
247
        if ( (name = fqdncache_gethostbyaddr(c->addr, 0)) ) {
 
248
            storeAppendPrintf(sentry, "Name:    %s\n", name);
 
249
        }
250
250
        storeAppendPrintf(sentry, "Currently established connections: %d\n",
251
251
                          c->n_established);
252
252
        storeAppendPrintf(sentry, "    ICP  Requests %d\n",
384
384
 
385
385
#if SQUID_SNMP
386
386
 
387
 
struct in_addr*
388
 
client_entry(struct IN_ADDR *current)
 
387
IpAddress *
 
388
client_entry(IpAddress *current)
389
389
{
390
390
    ClientInfo *c = NULL;
391
 
    char *key;
 
391
    char key[MAX_IPSTRLEN];
392
392
 
393
 
    if (current)
394
 
    {
395
 
        key = inet_ntoa(*current);
 
393
    if (current) {
 
394
        current->NtoA(key,MAX_IPSTRLEN);
396
395
        hash_first(client_table);
397
 
 
398
396
        while ((c = (ClientInfo *) hash_next(client_table))) {
399
397
            if (!strcmp(key, hashKeyStr(&c->hash)))
400
398
                break;
401
399
        }
402
400
 
403
401
        c = (ClientInfo *) hash_next(client_table);
404
 
    } else
405
 
    {
 
402
    } else {
406
403
        hash_first(client_table);
407
404
        c = (ClientInfo *) hash_next(client_table);
408
405
    }
423
420
    static char key[16];
424
421
    ClientInfo *c = NULL;
425
422
    int aggr = 0;
 
423
 
426
424
    log_type l;
427
425
    *ErrP = SNMP_ERR_NOERROR;
428
426
    debugs(49, 6, "snmp_meshCtblFn: Current : ");
429
427
    snmpDebugOid(6, Var->name, Var->name_length);
 
428
    /* FIXME INET6 : This must implement the key for IPv6 address */
430
429
    snprintf(key, sizeof(key), "%d.%d.%d.%d", Var->name[LEN_SQ_NET + 3], Var->name[LEN_SQ_NET + 4],
431
430
             Var->name[LEN_SQ_NET + 5], Var->name[LEN_SQ_NET + 6]);
432
431
    debugs(49, 5, "snmp_meshCtblFn: [" << key << "] requested!");
440
439
 
441
440
    switch (Var->name[LEN_SQ_NET + 2]) {
442
441
 
443
 
    case MESH_CTBL_ADDR:
 
442
    case MESH_CTBL_ADDR_TYPE: {
 
443
        int ival;
 
444
        ival = c->addr.IsIPv4() ? INETADDRESSTYPE_IPV4 : INETADDRESSTYPE_IPV6 ;
444
445
        Answer = snmp_var_new_integer(Var->name, Var->name_length,
445
 
                                      (snint) c->addr.s_addr,
446
 
                                      SMI_IPADDRESS);
447
 
        break;
 
446
                                      ival, SMI_INTEGER);
 
447
    }
 
448
    break;
448
449
 
 
450
    case MESH_CTBL_ADDR: {
 
451
        Answer = snmp_var_new(Var->name, Var->name_length);
 
452
        // InetAddress doesn't have its own ASN.1 type,
 
453
        // like IpAddr does (SMI_IPADDRESS)
 
454
        // See: rfc4001.txt
 
455
        Answer->type = ASN_OCTET_STR;
 
456
        char client[MAX_IPSTRLEN];
 
457
        c->addr.NtoA(client,MAX_IPSTRLEN);
 
458
        Answer->val_len = strlen(client);
 
459
        Answer->val.string =  (u_char *) xstrdup(client);
 
460
    }
 
461
    break;
449
462
    case MESH_CTBL_HTBYTES:
450
463
        Answer = snmp_var_new_integer(Var->name, Var->name_length,
451
464
                                      (snint) c->Http.kbytes_out.kb,