From: phk Date: Mon, 3 Apr 2006 11:05:53 +0000 (+0000) Subject: Segregate http header fields into a separate structure, we will X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec3a8da3fa49e19abc913c220f5bdb9776c696eb;p=varnish Segregate http header fields into a separate structure, we will reuse them a few places by the looks of it. Add VCA_UNKNOWNHDR (=10) fields for unknown HTTP headers. If more headers arrive than that, they're lost (and logged as such). git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@97 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_backend.c b/varnish-cache/bin/varnishd/cache_backend.c index d8f1efb6..db8ed424 100644 --- a/varnish-cache/bin/varnishd/cache_backend.c +++ b/varnish-cache/bin/varnishd/cache_backend.c @@ -152,17 +152,17 @@ VBE_Pass(struct sess *sp) sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); assert(sb != NULL); - sbuf_cat(sb, sp->req); + sbuf_cat(sb, sp->http.req); sbuf_cat(sb, " "); - sbuf_cat(sb, sp->url); + sbuf_cat(sb, sp->http.url); sbuf_cat(sb, " "); - sbuf_cat(sb, sp->proto); + sbuf_cat(sb, sp->http.proto); sbuf_cat(sb, "\r\n"); #define HTTPH(a, b, c, d, e, f, g) \ do { \ - if (c && sp->b != NULL) { \ + if (c && sp->http.b != NULL) { \ sbuf_cat(sb, a ": "); \ - sbuf_cat(sb, sp->b); \ + sbuf_cat(sb, sp->http.b); \ sbuf_cat(sb, "\r\n"); \ } \ } while (0); diff --git a/varnish-cache/bin/varnishd/cache_httpd.c b/varnish-cache/bin/varnishd/cache_httpd.c index c05cea9f..5c74b020 100644 --- a/varnish-cache/bin/varnishd/cache_httpd.c +++ b/varnish-cache/bin/varnishd/cache_httpd.c @@ -22,30 +22,30 @@ HttpdAnalyze(struct sess *sp) sp->handling = HND_Unclass; /* First, isolate and possibly identify request type */ - sp->req = sp->rcv; + sp->http.req = sp->rcv; for (p = sp->rcv; isalpha(*p); p++) ; - VSLR(SLT_Request, sp->fd, sp->req, p); + VSLR(SLT_Request, sp->fd, sp->http.req, p); *p++ = '\0'; /* Next find the URI */ while (isspace(*p)) p++; - sp->url = p; + sp->http.url = p; while (!isspace(*p)) p++; - VSLR(SLT_URL, sp->fd, sp->url, p); + VSLR(SLT_URL, sp->fd, sp->http.url, p); *p++ = '\0'; /* Finally, look for protocol, if any */ while (isspace(*p) && *p != '\n') p++; - sp->proto = p; + sp->http.proto = p; if (*p != '\n') { while (!isspace(*p)) p++; } - VSLR(SLT_Protocol, sp->fd, sp->proto, p); + VSLR(SLT_Protocol, sp->fd, sp->http.proto, p); *p++ = '\0'; while (isspace(*p) && *p != '\n') @@ -55,9 +55,7 @@ HttpdAnalyze(struct sess *sp) if (*p == '\r') p++; -#define HTTPH(a, b, c, d, e, f, g) sp->b = NULL; -#include "http_headers.h" -#undef HTTPH + memset(&sp->http, 0, sizeof sp->http); for (; p < sp->rcv + sp->rcv_len; p = r) { q = strchr(p, '\n'); @@ -72,7 +70,7 @@ HttpdAnalyze(struct sess *sp) if (!strncasecmp(p, a, strlen(a))) { \ for (p += strlen(a); p < q && isspace(*p); p++) \ continue; \ - sp->b = p; \ + sp->http.b = p; \ VSLR(SLT_##b, sp->fd, p, q); \ continue; \ } @@ -81,7 +79,11 @@ HttpdAnalyze(struct sess *sp) #include "http_headers.h" #undef HTTPH #undef W - VSLR(SLT_H_Unknown, sp->fd, p, q); + if (sp->http.nuhdr < VCA_UNKNOWNHDR) { + sp->http.uhdr[sp->http.nuhdr++] = p; + VSLR(SLT_HD_Unknown, sp->fd, p, q); + } else { + VSLR(SLT_HD_Lost, sp->fd, p, q); + } } - } diff --git a/varnish-cache/bin/varnishd/cache_pipe.c b/varnish-cache/bin/varnishd/cache_pipe.c index d15590d5..0da549de 100644 --- a/varnish-cache/bin/varnishd/cache_pipe.c +++ b/varnish-cache/bin/varnishd/cache_pipe.c @@ -55,19 +55,19 @@ PipeSession(struct sess *sp) sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND); assert(sb != NULL); - sbuf_cat(sb, sp->req); + sbuf_cat(sb, sp->http.req); sbuf_cat(sb, " "); - sbuf_cat(sb, sp->url); - if (sp->proto != NULL) { + sbuf_cat(sb, sp->http.url); + if (sp->http.proto != NULL) { sbuf_cat(sb, " "); - sbuf_cat(sb, sp->proto); + sbuf_cat(sb, sp->http.proto); } sbuf_cat(sb, "\r\n"); #define HTTPH(a, b, c, d, e, f, g) \ do { \ - if (sp->b != NULL) { \ + if (sp->http.b != NULL) { \ sbuf_cat(sb, a ": "); \ - sbuf_cat(sb, sp->b); \ + sbuf_cat(sb, sp->http.b); \ sbuf_cat(sb, "\r\n"); \ } \ } while (0); diff --git a/varnish-cache/include/shmlog_tags.h b/varnish-cache/include/shmlog_tags.h index 2522e9e4..83b779d8 100644 --- a/varnish-cache/include/shmlog_tags.h +++ b/varnish-cache/include/shmlog_tags.h @@ -13,7 +13,8 @@ SLTM(ClientAddr) SLTM(Request) SLTM(URL) SLTM(Protocol) -SLTM(H_Unknown) +SLTM(HD_Unknown) +SLTM(HD_Lost) #define HTTPH(a, b, c, d, e, f, g) SLTM(b) #include "http_headers.h" #undef HTTPH diff --git a/varnish-cache/include/vcl_lang.h b/varnish-cache/include/vcl_lang.h index dad14f8b..a57f3a0b 100644 --- a/varnish-cache/include/vcl_lang.h +++ b/varnish-cache/include/vcl_lang.h @@ -22,6 +22,18 @@ struct vcl_acl { #define VCA_RXBUFSIZE 1024 #define VCA_ADDRBUFSIZE 32 +#define VCA_UNKNOWNHDR 10 + +struct httphdr { + const char *req; + const char *url; + const char *proto; +#define HTTPH(a, b, c, d, e, f, g) const char *b; +#include +#undef HTTPH + const char *uhdr[VCA_UNKNOWNHDR]; + unsigned nuhdr; +}; struct sess { int fd; @@ -34,12 +46,7 @@ struct sess { unsigned rcv_len; /* HTTP request info, points into rcv */ - const char *req; - const char *url; - const char *proto; -#define HTTPH(a, b, c, d, e, f, g) const char *b; -#include -#undef HTTPH + struct httphdr http; enum { HND_Unclass, diff --git a/varnish-cache/lib/libvcl/vcl_fixed_token.c b/varnish-cache/lib/libvcl/vcl_fixed_token.c index 8323fe71..f21c63e4 100644 --- a/varnish-cache/lib/libvcl/vcl_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcl_fixed_token.c @@ -403,18 +403,9 @@ vcl_output_lang_h(FILE *f) fputs("\n", f); fputs("#define VCA_RXBUFSIZE 1024\n", f); fputs("#define VCA_ADDRBUFSIZE 32\n", f); + fputs("#define VCA_UNKNOWNHDR 10\n", f); fputs("\n", f); - fputs("struct sess {\n", f); - fputs(" int fd;\n", f); - fputs("\n", f); - fputs(" /* formatted ascii client address */\n", f); - fputs(" char addr[VCA_ADDRBUFSIZE];\n", f); - fputs("\n", f); - fputs(" /* Receive buffer for HTTP header */\n", f); - fputs(" char rcv[VCA_RXBUFSIZE + 1];\n", f); - fputs(" unsigned rcv_len;\n", f); - fputs("\n", f); - fputs(" /* HTTP request info, points into rcv */\n", f); + fputs("struct httphdr {\n", f); fputs(" const char *req;\n", f); fputs(" const char *url;\n", f); fputs(" const char *proto;\n", f); @@ -455,6 +446,22 @@ vcl_output_lang_h(FILE *f) fputs("HTTPH(\"TE\", H_TE, 0, 0, 0, 0, 0)\n", f); fputs("HTTPH(\"User-Agent\", H_User_Agent, 1, 0, 0, 0, 0)\n", f); fputs("#undef HTTPH\n", f); + fputs(" const char *uhdr[VCA_UNKNOWNHDR];\n", f); + fputs(" unsigned nuhdr;\n", f); + fputs("};\n", f); + fputs("\n", f); + fputs("struct sess {\n", f); + fputs(" int fd;\n", f); + fputs("\n", f); + fputs(" /* formatted ascii client address */\n", f); + fputs(" char addr[VCA_ADDRBUFSIZE];\n", f); + fputs("\n", f); + fputs(" /* Receive buffer for HTTP header */\n", f); + fputs(" char rcv[VCA_RXBUFSIZE + 1];\n", f); + fputs(" unsigned rcv_len;\n", f); + fputs("\n", f); + fputs(" /* HTTP request info, points into rcv */\n", f); + fputs(" struct httphdr http;\n", f); fputs("\n", f); fputs(" enum {\n", f); fputs(" HND_Unclass,\n", f);