From: Amos Jeffries Date: Sat, 9 May 2009 14:06:48 +0000 (+1200) Subject: Author: Mark Nottingham X-Git-Tag: SQUID_3_2_0_1~1015 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a8b1cdf660202ec210c00e5ee34aba26db9146be;p=thirdparty%2Fsquid.git Author: Mark Nottingham Bug 2627: HTCP Logging --- diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index 3719223fe0..ef571b758c 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -69,6 +69,13 @@ public: icp_opcode opcode; } icp; + class HtcpDetails { + public: + HtcpDetails() : opcode(NULL) {}; + + const char *opcode; + } htcp; + class CacheDetails { diff --git a/src/access_log.cc b/src/access_log.cc index 7ff76f26af..9b7525e2cf 100644 --- a/src/access_log.cc +++ b/src/access_log.cc @@ -1403,6 +1403,8 @@ accessLogLog(AccessLogEntry * al, ACLChecklist * checklist) if (al->icp.opcode) al->_private.method_str = icp_opcode_str[al->icp.opcode]; + else if (al->htcp.opcode) + al->_private.method_str = al->htcp.opcode; else al->_private.method_str = RequestMethodStr(al->http.method); diff --git a/src/htcp.cc b/src/htcp.cc index 8e16c6716f..c28412bd5d 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -45,6 +45,7 @@ #include "MemBuf.h" #include "http.h" #include "icmp/net_db.h" +#include "AccessLogEntry.h" typedef struct _Countstr Countstr; @@ -252,6 +253,7 @@ static void htcpFreeDetail(htcpDetail * s); static void htcpHandleMsg(char *buf, int sz, IpAddress &from); +static void htcpLogHtcp(IpAddress &, int, log_type, const char *); static void htcpHandleMon(htcpDataHeader *, char *buf, int sz, IpAddress &from); static void htcpHandleNop(htcpDataHeader *, char *buf, int sz, IpAddress &from); @@ -259,6 +261,7 @@ static void htcpHandleNop(htcpDataHeader *, char *buf, int sz, IpAddress &from); static void htcpHandleSet(htcpDataHeader *, char *buf, int sz, IpAddress &from); static void htcpHandleTst(htcpDataHeader *, char *buf, int sz, IpAddress &from); + static void htcpRecv(int fd, void *data); static void htcpSend(const char *buf, int len, IpAddress &to); @@ -1184,23 +1187,26 @@ htcpHandleTstRequest(htcpDataHeader * dhdr, char *buf, int sz, IpAddress &from) /* s is a new object */ s = htcpUnpackSpecifier(buf, sz); - s->setFrom (from); + s->setFrom(from); - s->setDataHeader (dhdr); + s->setDataHeader(dhdr); if (NULL == s) { debugs(31, 2, "htcpHandleTstRequest: htcpUnpackSpecifier failed"); + htcpLogHtcp(from, dhdr->opcode, LOG_UDP_INVALID, dash_str); return; } if (!s->request) { debugs(31, 2, "htcpHandleTstRequest: failed to parse request"); + htcpLogHtcp(from, dhdr->opcode, LOG_UDP_INVALID, dash_str); htcpFreeSpecifier(s); return; } if (!htcpAccessCheck(Config.accessList.htcp, s, from)) { debugs(31, 2, "htcpHandleTstRequest: Access denied"); + htcpLogHtcp(from, dhdr->opcode, LOG_UDP_DENIED, s->uri); htcpFreeSpecifier(s); return; } @@ -1213,10 +1219,13 @@ htcpHandleTstRequest(htcpDataHeader * dhdr, char *buf, int sz, IpAddress &from) void htcpSpecifier::checkedHit(StoreEntry *e) { - if (e) + if (e) { htcpTstReply(dhdr, e, this, from); /* hit */ - else + htcpLogHtcp(from, dhdr->opcode, LOG_UDP_HIT, uri); + } else { htcpTstReply(dhdr, NULL, NULL, from); /* cache miss */ + htcpLogHtcp(from, dhdr->opcode, LOG_UDP_MISS, uri); + } htcpFreeSpecifier(this); } @@ -1236,7 +1245,6 @@ htcpHandleSet(htcpDataHeader * hdr, char *buf, int sz, IpAddress &from) } static void - htcpHandleClr(htcpDataHeader * hdr, char *buf, int sz, IpAddress &from) { htcpSpecifier *s; @@ -1250,6 +1258,7 @@ htcpHandleClr(htcpDataHeader * hdr, char *buf, int sz, IpAddress &from) if (sz == 0) { debugs(31, 4, "htcpHandleClr: nothing to do"); + htcpLogHtcp(from, hdr->opcode, LOG_UDP_INVALID, dash_str); return; } @@ -1257,11 +1266,13 @@ htcpHandleClr(htcpDataHeader * hdr, char *buf, int sz, IpAddress &from) if (NULL == s) { debugs(31, 3, "htcpHandleClr: htcpUnpackSpecifier failed"); + htcpLogHtcp(from, hdr->opcode, LOG_UDP_INVALID, dash_str); return; } if (!htcpAccessCheck(Config.accessList.htcp_clr, s, from)) { debugs(31, 2, "htcpHandleClr: Access denied"); + htcpLogHtcp(from, hdr->opcode, LOG_UDP_DENIED, s->uri); htcpFreeSpecifier(s); return; } @@ -1277,10 +1288,12 @@ htcpHandleClr(htcpDataHeader * hdr, char *buf, int sz, IpAddress &from) case 1: htcpClrReply(hdr, 1, from); /* hit */ + htcpLogHtcp(from, hdr->opcode, LOG_UDP_HIT, s->uri); break; case 0: htcpClrReply(hdr, 0, from); /* miss */ + htcpLogHtcp(from, hdr->opcode, LOG_UDP_MISS, s->uri); break; default: @@ -1689,3 +1702,19 @@ htcpSocketClose(void) htcpOutSocket = -1; } } + +static void +htcpLogHtcp(IpAddress &caddr, int opcode, log_type logcode, const char *url) +{ + AccessLogEntry al; + if (LOG_TAG_NONE == logcode) + return; + if (!Config.onoff.log_udp) + return; + al.htcp.opcode = htcpOpcodeStr[opcode]; + al.url = url; + al.cache.caddr = caddr; + al.cache.code = logcode; + al.cache.msec = 0; + accessLogLog(&al, NULL); +} diff --git a/src/structs.h b/src/structs.h index e679e8f72e..e81dfdcfe4 100644 --- a/src/structs.h +++ b/src/structs.h @@ -837,8 +837,8 @@ struct peer { int counts[ICP_END+1]; u_short port; } icp; -#if USE_HTCP +#if USE_HTCP struct { double version; int counts[2];