From: wessels <> Date: Tue, 31 Mar 1998 10:57:14 +0000 (+0000) Subject: added x-forwarded-for and via header database X-Git-Tag: SQUID_3_0_PRE1~3689 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d21f1c548ce335c24516cf0980323cbf11ef64df;p=thirdparty%2Fsquid.git added x-forwarded-for and via header database --- diff --git a/src/access_log.cc b/src/access_log.cc index 1379ee5368..9940a8af1d 100644 --- a/src/access_log.cc +++ b/src/access_log.cc @@ -1,7 +1,7 @@ /* - * $Id: access_log.cc,v 1.23 1998/02/24 21:17:01 wessels Exp $ + * $Id: access_log.cc,v 1.24 1998/03/31 03:57:14 wessels Exp $ * * DEBUG: section 46 Access Log * AUTHOR: Duane Wessels @@ -61,7 +61,22 @@ const char *log_tags[] = "LOG_TYPE_MAX" }; -#define MAX_LINELEN (4096) +#if FORW_VIA_DB +typedef struct { + char *key; + void *next; + int n; +} fvdb_entry; +static hash_table *via_table = NULL; +static hash_table *forw_table = NULL; +static void fvdbInit(void); +static void fvdbDumpTable(StoreEntry *e, hash_table *hash); +static void fvdbCount(hash_table *hash, const char *key); +static OBJH fvdbDumpVia; +static OBJH fvdbDumpForw; +static FREE fvdbFreeEntry; +static void fvdbClear(void); +#endif static int LogfileStatus = LOG_DISABLE; static int LogfileFD = -1; @@ -260,6 +275,9 @@ accessLogRotate(void) LOCAL_ARRAY(char, to, MAXPATHLEN); char *fname = NULL; struct stat sb; +#if FORW_VIA_DB + fvdbClear(); +#endif if ((fname = LogfileName) == NULL) return; #ifdef S_ISREG @@ -316,6 +334,9 @@ accessLogInit(void) { assert(sizeof(log_tags) == (LOG_TYPE_MAX + 1) * sizeof(char *)); accessLogOpen(Config.Log.access); +#if FORW_VIA_DB + fvdbInit(); +#endif } const char * @@ -331,3 +352,85 @@ accessLogTime(time_t t) } return buf; } + + +#if FORW_VIA_DB + +static void +fvdbInit(void) +{ + via_table = hash_create((HASHCMP *) strcmp, 977, hash4); + forw_table = hash_create((HASHCMP *) strcmp, 977, hash4); + cachemgrRegister("via_headers", "Via Request Headers", fvdbDumpVia, 0); + cachemgrRegister("forw_headers", "X-Forwarded-For Request Headers", + fvdbDumpForw, 0); +} + +static void +fvdbCount(hash_table *hash, const char *key) +{ + fvdb_entry *fv; + if (NULL == hash) + return; + fv = hash_lookup(hash, key); + if (NULL == fv) { + fv = xcalloc(1, sizeof(fvdb_entry)); + fv->key = xstrdup(key); + hash_join(hash, (hash_link *) fv); + } + fv->n++; +} + +void +fvdbCountVia(const char *key) +{ + fvdbCount(via_table, key); +} + +void +fvdbCountForw(const char *key) +{ + fvdbCount(forw_table, key); +} + +static void +fvdbDumpTable(StoreEntry *e, hash_table *hash) +{ + hash_link *h; + fvdb_entry *fv; + if (hash == NULL) + return; + for (h = hash_first(hash); h != NULL; h = hash_next(hash)) { + fv = (fvdb_entry *) h; + storeAppendPrintf(e, "%9d %s\n", fv->n, fv->key); + } +} + +static void +fvdbDumpVia(StoreEntry *e) +{ + fvdbDumpTable(e, via_table); +} + +static void +fvdbDumpForw(StoreEntry *e) +{ + fvdbDumpTable(e, forw_table); +} + +static +void fvdbFreeEntry(void *data) +{ + fvdb_entry *fv = data; + xfree(fv->key); + xfree(fv); +} + +static void +fvdbClear(void) +{ + hashFreeItems(via_table, fvdbFreeEntry); + hashFreeItems(forw_table, fvdbFreeEntry); +} + +#endif diff --git a/src/client_side.cc b/src/client_side.cc index 27818278af..4f329f4cb4 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.239 1998/03/30 06:56:24 rousskov Exp $ + * $Id: client_side.cc,v 1.240 1998/03/31 03:57:15 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -653,7 +653,7 @@ clientParseRequestHeaders(clientHttpRequest * http) if (!strcasecmp(t, "Keep-Alive")) EBIT_SET(request->flags, REQ_PROXY_KEEPALIVE); } - if ((t = mime_get_header(request_hdr, "Via"))) + if ((t = mime_get_header(request_hdr, "Via"))) { if (strstr(t, ThisCache)) { if (!http->accel) { debug(33, 1) ("WARNING: Forwarding loop detected for '%s'\n", @@ -662,9 +662,17 @@ clientParseRequestHeaders(clientHttpRequest * http) } EBIT_SET(request->flags, REQ_LOOPDETECT); } +#if FORW_VIA_DB + fvdbCountVia(t); +#endif + } #if USE_USERAGENT_LOG if ((t = mime_get_header(request_hdr, "User-Agent"))) logUserAgent(fqdnFromAddr(http->conn->peer.sin_addr), t); +#endif +#if FORW_VIA_DB + if ((t = mime_get_header(request_hdr, "X-Forwarded-For"))) + fvdbCountForw(t); #endif request->max_age = -1; if ((t = mime_get_header(request_hdr, "Cache-control"))) { @@ -2195,3 +2203,4 @@ clientHttpConnectionsClose(void) } NHttpSockets = 0; } + diff --git a/src/protos.h b/src/protos.h index 02a6fdc01d..7a1ba448eb 100644 --- a/src/protos.h +++ b/src/protos.h @@ -6,6 +6,10 @@ extern void accessLogClose(void); extern void accessLogInit(void); extern const char *accessLogTime(time_t); extern void hierarchyNote(HierarchyLogEntry *, hier_code, icp_ping_data *, const char *); +#if FORW_VIA_DB +extern void fvdbCountVia(const char *key); +extern void fvdbCountForw(const char *key); +#endif extern aclCheck_t *aclChecklistCreate(const struct _acl_access *, request_t *,