]> git.pld-linux.org Git - packages/squid.git/blob - squid-2.5.STABLE6-client_db_gc.patch
- regarding http://securitytracker.com/alerts/2004/Dec/1012649.html
[packages/squid.git] / squid-2.5.STABLE6-client_db_gc.patch
1 Index: squid/src/client_db.c
2 diff -c squid/src/client_db.c:1.53 squid/src/client_db.c:1.53.2.1
3 *** squid/src/client_db.c:1.53  Fri Feb 23 13:59:50 2001
4 --- squid/src/client_db.c       Sat Jul 17 16:37:30 2004
5 ***************
6 *** 38,43 ****
7 --- 38,51 ----
8   static hash_table *client_table = NULL;
9   static ClientInfo *clientdbAdd(struct in_addr addr);
10   static FREE clientdbFreeItem;
11 + static void clientdbStartGC(void);
12
13 + static int max_clients = 32;
14 + static int cleanup_running = 0;
15 + static int cleanup_scheduled = 0;
16 + static int cleanup_removed;
17
18 + #define CLIENT_DB_HASH_SIZE 467
19   
20   static ClientInfo *
21   clientdbAdd(struct in_addr addr)
22 ***************
23 *** 48,53 ****
24 --- 56,63 ----
25       c->addr = addr;
26       hash_join(client_table, &c->hash);
27       statCounter.client_http.clients++;
28 +     if ((statCounter.client_http.clients > max_clients) && !cleanup_running)
29 +       clientdbStartGC();
30       return c;
31   }
32   
33 ***************
34 *** 56,62 ****
35   {
36       if (client_table)
37         return;
38 !     client_table = hash_create((HASHCMP *) strcmp, 467, hash_string);
39       cachemgrRegister("client_list",
40         "Cache Client List",
41         clientdbDump,
42 --- 66,72 ----
43   {
44       if (client_table)
45         return;
46 !     client_table = hash_create((HASHCMP *) strcmp, CLIENT_DB_HASH_SIZE, hash_string);
47       cachemgrRegister("client_list",
48         "Cache Client List",
49         clientdbDump,
50 ***************
51 *** 89,94 ****
52 --- 99,105 ----
53         if (LOG_UDP_HIT == ltype)
54             kb_incr(&c->Icp.hit_kbytes_out, size);
55       }
56 +     c->last_seen = squid_curtime;
57   }
58   
59   /*
60 ***************
61 *** 226,231 ****
62 --- 237,300 ----
63       client_table = NULL;
64   }
65   
66 + static void
67 + clientdbScheduledGC(void *unused)
68 + {
69 +     cleanup_scheduled = 0;
70 +     clientdbStartGC();
71 + }
72
73 + static void
74 + clientdbGC(void *unused)
75 + {
76 +     static int bucket = 0;
77 +     hash_link *link_next;
78
79 +     link_next = hash_get_bucket(client_table, bucket++);
80 +     while (link_next != NULL) {
81 +       ClientInfo *c = (ClientInfo *) link_next;
82 +       int age = squid_curtime - c->last_seen;
83 +       link_next = link_next->next;
84 +       if (c->n_established)
85 +           continue;
86
87 +       if (age < 24 * 3600 && c->Http.n_requests > 100)
88 +           continue;
89 +       if (age < 4 * 3600 && (c->Http.n_requests > 10 || c->Icp.n_requests > 10))
90 +           continue;
91 +       if (age < 5 * 60 && (c->Http.n_requests > 1 || c->Icp.n_requests > 1))
92 +           continue;
93 +       if (age < 60)
94 +           continue;
95 +       hash_remove_link(client_table, &c->hash);
96 +       clientdbFreeItem(c);
97 +       statCounter.client_http.clients--;
98 +       cleanup_removed++;
99 +     }
100
101 +     if (bucket < CLIENT_DB_HASH_SIZE)
102 +       eventAdd("client_db garbage collector", clientdbGC, NULL, 0.15, 0);
103 +     else {
104 +       bucket = 0;
105 +       cleanup_running = 0;
106 +       max_clients = statCounter.client_http.clients * 3 / 2;
107 +       if (!cleanup_scheduled) {
108 +           cleanup_scheduled = 1;
109 +           eventAdd("client_db garbage collector", clientdbScheduledGC, NULL, 6 * 3600, 0);
110 +       }
111 +       debug(49, 1) ("clientdbGC: Removed %d entries\n", cleanup_removed);
112 +     }
113 + }
114
115 + static void
116 + clientdbStartGC(void)
117 + {
118 +     max_clients = statCounter.client_http.clients;
119 +     cleanup_running = 1;
120 +     cleanup_removed = 0;
121 +     clientdbGC(NULL);
122 + }
123
124   #if SQUID_SNMP
125   struct in_addr *
126   client_entry(struct in_addr *current)
127 Index: squid/src/structs.h
128 diff -c squid/src/structs.h:1.408.2.24 squid/src/structs.h:1.408.2.25
129 *** squid/src/structs.h:1.408.2.24      Sun Apr 18 17:43:30 2004
130 --- squid/src/structs.h Sat Jul 17 16:37:30 2004
131 ***************
132 *** 1940,1945 ****
133 --- 1940,1946 ----
134         int n_denied;
135       } cutoff;
136       int n_established;                /* number of current established connections */
137 +     time_t last_seen;
138   };
139   
140   struct _CacheDigest {
This page took 0.041977 seconds and 3 git commands to generate.