From: Martin Mares Date: Thu, 19 Jun 2003 11:17:10 +0000 (+0000) Subject: Added tracking of cache control fields. X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=67fd236a140f14a5818c502aa0cadaf7fb4bb914;p=netgrind.git Added tracking of cache control fields. --- diff --git a/netgrind/http.c b/netgrind/http.c index 3aafc56..b90c893 100644 --- a/netgrind/http.c +++ b/netgrind/http.c @@ -80,6 +80,30 @@ static byte *http_lookup_hdr(list *l, byte *name) return NULL; } +static uns find_token(byte *hay, byte *needle) +{ + if (!hay) + return 0; + while (*hay) + { + if (*hay == ' ' || *hay == '\t' || *hay == ',') + hay++; + else + { + byte *h = hay; + while (*hay && *hay != ',' && *hay != ' ' && *hay != '\t') + hay++; + uns old = *hay; + *hay = 0; + uns found = !strcasecmp(h, needle); + *hay = old; + if (found) + return 1; + } + } + return 0; +} + static void http_report(struct flow *f, struct http_state *s, u64 when, byte *reason) { byte *method, *url, *x, *y, *stat; @@ -125,6 +149,39 @@ static void http_report(struct flow *f, struct http_state *s, u64 when, byte *re url = alloca(7 + strlen(x) + strlen(y) + 1); sprintf(url, "http://%s%s", x, y); } + char *ffor = http_lookup_hdr(&s->req_headers, "X-Forwarded-For:"); + + /* Find out cacheability */ + byte *rq_pragma = http_lookup_hdr(&s->req_headers, "Pragma:"); + byte *rp_pragma = http_lookup_hdr(&s->resp_headers, "Pragma:"); + byte *rq_cc = http_lookup_hdr(&s->req_headers, "Cache-control:"); + byte *rp_cc = http_lookup_hdr(&s->resp_headers, "Cache-control:"); + byte *rp_cache = http_lookup_hdr(&s->resp_headers, "X-Cache:"); + uns rq_cflag, rp_cflag, rp_hit; + if (find_token(rq_pragma, "no-cache") || find_token(rq_cc, "no-cache")) + rq_cflag = 'N'; + else if (find_token(rq_cc, "max-age=0") || find_token(rq_cc, "must-revalidate")) + rq_cflag = 'R'; + else + rq_cflag = '.'; + if (find_token(rp_pragma, "no-cache") || find_token(rp_cc, "no-cache")) + rp_cflag = 'N'; + else if (find_token(rp_cc, "private")) + rp_cflag = 'P'; + else if (find_token(rp_cc, "no-store")) + rp_cflag = 'S'; + else if (find_token(rp_cc, "must-revalidate")) + rp_cflag = 'R'; + else + rp_cflag = '.'; + if (!rp_cache) + rp_hit = '.'; + else if (!strncmp(rp_cache, "HIT ", 4)) + rp_hit = '+'; + else if (!strncmp(rp_cache, "MISS ", 5)) + rp_hit = '-'; + else + rp_hit = '?'; byte stamp[TIMESTAMP_LEN], src[22], dst[22]; sprintf(src, "%d.%d.%d.%d:%d", IPQUAD(f->saddr), ntohs(f->sport)); @@ -133,10 +190,11 @@ static void http_report(struct flow *f, struct http_state *s, u64 when, byte *re u64 ttotal = when - s->req_start_time; u64 tresp = (s->resp_line ? (s->resp_start_time - s->req_start_time) : 0); if (!http_counter++) - printf("# timestamp source destination result que length total time wait time method URL\n"); - /* 2003-06-06 22:53:38.642 81.27.194.19:1175 205.217.153.53:80 200 0 14030 0.957 0.444 GET http://... */ - printf("%s %-21s %-21s %-3s %3d %8d %6d.%03d %6d.%03d %s %s\n", - stamp, src, dst, reason, + printf("# timestamp source destination forwarded-for res cac que length total time wait time method URL\n"); + /* 2003-06-06 22:53:38.642 81.27.194.19:1175 205.217.153.53:80 123.123.123.123 200 ... 0 14030 0.957 0.444 GET http://... */ + printf("%s %-21s %-21s %-15s %-3s %c%c%c %3d %8d %6d.%03d %6d.%03d %s %s\n", + stamp, src, dst, (ffor ? : "-"), reason, + rq_cflag, rp_cflag, rp_hit, s->req_counter, s->body_total_size, (uns)(ttotal/1000000), (uns)(ttotal%1000000)/1000,