[master] fcd46ae Distinguish between headers we receive (VSL_BogoHeader) and headers we generate (VSL_LostHeader).
Poul-Henning Kamp
phk at varnish-cache.org
Mon Jan 14 14:55:41 CET 2013
commit fcd46ae397d7cb18b7cad9cb2067b25813a1230a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Jan 14 13:54:25 2013 +0000
Distinguish between headers we receive (VSL_BogoHeader) and headers
we generate (VSL_LostHeader).
Add counters for requests received with 400, 413 and 417 errors.
Inspired by: patch from Lasse
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 91ab200..eb5ad7e 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -518,8 +518,7 @@ http_dissect_hdrs(struct http *hp, char *p, const struct http_conn *htc)
}
if (q - p > htc->maxhdr) {
- VSC_C_main->losthdr++;
- VSLb(hp->vsl, SLT_LostHeader, "%.*s",
+ VSLb(hp->vsl, SLT_BogoHeader, "%.*s",
(int)(q - p > 20 ? 20 : q - p), p);
return (413);
}
@@ -544,8 +543,7 @@ http_dissect_hdrs(struct http *hp, char *p, const struct http_conn *htc)
http_VSLH(hp, hp->nhd);
hp->nhd++;
} else {
- VSC_C_main->losthdr++;
- VSLb(hp->vsl, SLT_LostHeader, "%.*s",
+ VSLb(hp->vsl, SLT_BogoHeader, "%.*s",
(int)(q - p > 20 ? 20 : q - p), p);
return (413);
}
@@ -558,10 +556,20 @@ http_dissect_hdrs(struct http *hp, char *p, const struct http_conn *htc)
*/
static uint16_t
-http_splitline(struct http *hp,
- const struct http_conn *htc, int h1, int h2, int h3)
+http_splitline(struct http *hp, const struct http_conn *htc, int req)
{
char *p, *q;
+ int h1, h2, h3;
+
+ if (req) {
+ h1 = HTTP_HDR_METHOD;
+ h2 = HTTP_HDR_URL;
+ h3 = HTTP_HDR_PROTO;
+ } else {
+ h1 = HTTP_HDR_PROTO;
+ h2 = HTTP_HDR_STATUS;
+ h3 = HTTP_HDR_RESPONSE;
+ }
CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
@@ -663,8 +671,7 @@ http_DissectRequest(struct req *req)
hp = req->http;
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
- retval = http_splitline(hp, htc,
- HTTP_HDR_METHOD, HTTP_HDR_URL, HTTP_HDR_PROTO);
+ retval = http_splitline(hp, htc, 1);
if (retval != 0) {
VSLbt(req->vsl, SLT_HttpGarbage, htc->rxbuf);
return (retval);
@@ -686,8 +693,7 @@ http_DissectResponse(struct http *hp, const struct http_conn *htc)
CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
- if (http_splitline(hp, htc,
- HTTP_HDR_PROTO, HTTP_HDR_STATUS, HTTP_HDR_RESPONSE))
+ if (http_splitline(hp, htc, 0))
retval = 503;
if (retval == 0 && memcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.", 7))
diff --git a/bin/varnishd/cache/cache_http1_fsm.c b/bin/varnishd/cache/cache_http1_fsm.c
index e6b12ee..87771d5 100644
--- a/bin/varnishd/cache/cache_http1_fsm.c
+++ b/bin/varnishd/cache/cache_http1_fsm.c
@@ -262,11 +262,10 @@ http1_dissect(struct worker *wrk, struct req *req)
/* If we could not even parse the request, just close */
if (req->err_code == 400) {
+ wrk->stats.client_req_400++;
SES_Close(req->sp, SC_RX_JUNK);
return (1);
}
-
- wrk->stats.client_req++;
req->acct_req.req++;
req->ws_req = WS_Snapshot(req->ws);
@@ -275,12 +274,17 @@ http1_dissect(struct worker *wrk, struct req *req)
/* XXX: Expect headers are a mess */
if (req->err_code == 0 && http_GetHdr(req->http, H_Expect, &p)) {
if (strcasecmp(p, "100-continue")) {
+ wrk->stats.client_req_417++;
req->err_code = 417;
} else if (strlen(r) != write(req->sp->fd, r, strlen(r))) {
SES_Close(req->sp, SC_REM_CLOSE);
return (1);
}
- }
+ } else if (req->err_code == 413)
+ wrk->stats.client_req_413++;
+ else
+ wrk->stats.client_req++;
+
http_Unset(req->http, H_Expect);
/* XXX: pull in req-body and make it available instead. */
req->reqbodydone = 0;
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 2966d09..ebb784d 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -216,7 +216,7 @@ tweak_bool(struct cli *cli, const struct parspec *par, const char *arg)
*dest = 1;
else {
VCLI_Out(cli,
- mode ?
+ mode ?
"use \"on\" or \"off\"\n" :
"use \"true\" or \"false\"\n");
VCLI_SetResult(cli, CLIS_PARAM);
diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h
index 133025e..c266f50 100644
--- a/include/tbl/vsc_f_main.h
+++ b/include/tbl/vsc_f_main.h
@@ -90,11 +90,29 @@ VSC_F(sess_fail, uint64_t, 1, 'c',
/*---------------------------------------------------------------------*/
+VSC_F(client_req_400, uint64_t, 1, 'a',
+ "Client requests received, subject to 400 errors",
+ "400 means we couldn't make sense of the request, it was"
+ " malformed in some drastic way."
+)
+
+VSC_F(client_req_413, uint64_t, 1, 'a',
+ "Client requests received, subject to 413 errors",
+ "413 means that HTTP headers execeeded length or count limits."
+)
+
+VSC_F(client_req_417, uint64_t, 1, 'a',
+ "Client requests received, subject to 417 errors",
+ "417 means that something went wrong with an Expect: header."
+)
+
VSC_F(client_req, uint64_t, 1, 'a',
- "Client requests received",
+ "Good Client requests received",
""
)
+/*---------------------------------------------------------------------*/
+
VSC_F(cache_hit, uint64_t, 1, 'a',
"Cache hits",
"Count of cache hits. "
@@ -110,6 +128,7 @@ VSC_F(cache_hitpass, uint64_t, 1, 'a',
" cached in it self. This counts how many times the cached "
" decision is being used."
)
+
VSC_F(cache_miss, uint64_t, 1, 'a',
"Cache misses",
"Count of misses"
@@ -117,6 +136,8 @@ VSC_F(cache_miss, uint64_t, 1, 'a',
" backend before delivering it to the backend."
)
+/*---------------------------------------------------------------------*/
+
VSC_F(backend_conn, uint64_t, 0, 'a',
"Backend conn. success",
""
diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h
index bdf840d..3f43bc1 100644
--- a/include/tbl/vsl_tags.h
+++ b/include/tbl/vsl_tags.h
@@ -130,7 +130,11 @@ SLTM(FetchError, "Error while fetching object", "")
#include "tbl/vsl_tags_http.h"
#undef SLTH
-SLTM(LostHeader, "", "")
+SLTM(BogoHeader, "Bogus HTTP received",
+ "Contains the first 20 characters of received HTTP headers we could"
+ " not make sense of. Applies to both req.http and beres.http."
+)
+SLTM(LostHeader, "Failed attempt to set HTTP header", "")
SLTM(TTL, "TTL set on object", "")
SLTM(Fetch_Body, "Body fetched from backend", "")
More information about the varnish-commit
mailing list