From phk at FreeBSD.org Mon Mar 2 09:06:16 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 02 Mar 2015 10:06:16 +0100 Subject: [master] 2216efa Change calling convention to VSS_parse() to give it a mutable string into which pointers are returned. Message-ID: commit 2216efa1c001c78704a6dcf1c38258c8a3188908 Author: Poul-Henning Kamp Date: Mon Mar 2 09:05:31 2015 +0000 Change calling convention to VSS_parse() to give it a mutable string into which pointers are returned. This simplifies the code enough that FlexeLint doesn't get confused. diff --git a/bin/varnishtest/tests/v00038.vtc b/bin/varnishtest/tests/v00038.vtc index 7de4517..7fb006d 100644 --- a/bin/varnishtest/tests/v00038.vtc +++ b/bin/varnishtest/tests/v00038.vtc @@ -1,11 +1,17 @@ varnishtest "VCL compiler coverage test: vcc_backend.c" -varnish v1 -errvcl "IPv6 address [] wrong" { +varnish v1 -errvcl "IPv6 address lacks ']'" { backend b1 { .host = "[0:0:0:0"; } } +varnish v1 -errvcl "IPv6 address has wrong port separator" { + backend b1 { + .host = "[0:0:0:0]/0"; + } +} + varnish v1 -errvcl "with exactly three digits" { backend b1 { .host = "127.0.0.1"; diff --git a/include/vss.h b/include/vss.h index af41057..c015df5 100644 --- a/include/vss.h +++ b/include/vss.h @@ -29,7 +29,7 @@ /* vss.c */ struct vss_addr; -const char *VSS_parse(const char *str, char **addr, char **port); +const char *VSS_parse(char *str, char **addr, char **port); int VSS_resolve(const char *addr, const char *port, struct vss_addr ***ta); int VSS_bind(const struct vss_addr *addr); int VSS_listen(const struct vss_addr *addr, int depth); diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index 85b3d67..d5bc65f 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -72,43 +72,36 @@ struct vss_addr { */ const char * -VSS_parse(const char *str, char **addr, char **port) +VSS_parse(char *str, char **addr, char **port) { - const char *p; + char *p; *addr = *port = NULL; if (str[0] == '[') { /* IPv6 address of the form [::1]:80 */ - if ((p = strchr(str, ']')) == NULL || - p == str + 1 || - (p[1] != '\0' && p[1] != ':')) - return ("IPv6 address [] wrong."); - *addr = strdup(str + 1); - XXXAN(*addr); - (*addr)[p - (str + 1)] = '\0'; - if (p[1] == ':') { - *port = strdup(p + 2); - XXXAN(*port); - } + *addr = str + 1; + p = strchr(str, ']'); + if (p == NULL) + return ("IPv6 address lacks ']'"); + *p++ = '\0'; + if (*p == '\0') + return (NULL); + if (*p != ' ' && *p != ':') + return ("IPv6 address has wrong port separator"); } else { /* IPv4 address of the form 127.0.0.1:80, or non-numeric */ + *addr = str; p = strchr(str, ' '); if (p == NULL) p = strchr(str, ':'); - if (p == NULL) { - *addr = strdup(str); - XXXAN(*addr); - } else { - if (p > str) { - *addr = strdup(str); - XXXAN(*addr); - (*addr)[p - str] = '\0'; - } - *port = strdup(p + 1); - XXXAN(*port); - } + if (p == NULL) + return (NULL); + if (p == str) + *addr = NULL; } + *p++ = '\0'; + *port = p; return (NULL); } @@ -136,6 +129,7 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) struct vss_addr **va; int i, ret; long int ptst; + char *h; char *adp, *hop; *vap = NULL; @@ -143,23 +137,25 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; - if (VSS_parse(addr, &hop, &adp) != NULL) + h = strdup(addr); + AN(h); + if (VSS_parse(h, &hop, &adp) != NULL) { + free(h); return (0); + } if (adp == NULL) ret = getaddrinfo(addr, port, &hints, &res0); else { ptst = strtol(adp, NULL, 10); if (ptst < 0 || ptst > 65535) { - free(hop); - free(adp); + free(h); return(0); } ret = getaddrinfo(hop, adp, &hints, &res0); } - free(hop); - free(adp); + free(h); if (ret != 0) return (0); diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c index 800f3af..c9cc681 100644 --- a/lib/libvcc/vcc_backend.c +++ b/lib/libvcc/vcc_backend.c @@ -48,11 +48,14 @@ Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const char *port) { const char *ipv4, *ipv4a, *ipv6, *ipv6a, *pa; const char *err; + char *p; char *hop, *pop; AN(t_host->dec); - err = VSS_parse(t_host->dec, &hop, &pop); + p = TlDup(tl, t_host->dec); + AN(p); + err = VSS_parse(p, &hop, &pop); if (err != NULL) { VSB_printf(tl->sb, "Backend host '%.*s': %s\n", PF(t_host), err); From phk at FreeBSD.org Mon Mar 2 09:29:08 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 02 Mar 2015 10:29:08 +0100 Subject: [master] 5ec7935 Remove the VSC for number of vcls referencing a backend, it is always one now. Message-ID: commit 5ec7935bda68395c55b8a9d1b750b4eb9100c0b3 Author: Poul-Henning Kamp Date: Mon Mar 2 09:28:26 2015 +0000 Remove the VSC for number of vcls referencing a backend, it is always one now. Rename VBE_Drop() to VBE_DeleteBackend() diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 458eea7..3aad027 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -356,7 +356,7 @@ VRT_fini_vbe(VRT_CTX, struct director **dp, const struct vrt_backend *vrt) if (vrt->probe != NULL) VBP_Remove(be, vrt->probe); - VBE_Drop(be); + VBE_DeleteBackend(be); free(d->vcl_name); FREE_OBJ(d); } diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index 1a52232..72e57af 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -104,7 +104,7 @@ struct vbc { }; /* cache_backend_cfg.c */ -void VBE_Drop(struct backend *); +void VBE_DeleteBackend(struct backend *); unsigned VBE_Healthy(const struct backend *b, double *changed); struct backend *VBE_AddBackend(const struct vrt_backend *vb); diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index 9a80a4b..37431f5 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -55,13 +55,12 @@ static VTAILQ_HEAD(, backend) backends = VTAILQ_HEAD_INITIALIZER(backends); */ void -VBE_Drop(struct backend *b) +VBE_DeleteBackend(struct backend *b) { ASSERT_CLI(); CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - b->vsc->vcls--; VTAILQ_REMOVE(&backends, b, list); free(b->ipv4); free(b->ipv6); @@ -99,7 +98,6 @@ VBE_AddBackend(const struct vrt_backend *vb) vb->ipv6_addr == NULL ? "" : vb->ipv6_addr, vb->port); b->vsc = VSM_Alloc(sizeof *b->vsc, VSC_CLASS, VSC_type_vbe, buf); - b->vsc->vcls++; b->vcl_name = vb->vcl_name; REPLACE(b->display_name, buf); diff --git a/include/tbl/vsc_fields.h b/include/tbl/vsc_fields.h index 7b06a8c..b456d9f 100644 --- a/include/tbl/vsc_fields.h +++ b/include/tbl/vsc_fields.h @@ -179,10 +179,6 @@ VSC_F(g_smf_large, uint64_t, 0, 'g', 'i', info, #ifdef VSC_DO_VBE -VSC_F(vcls, uint64_t, 0, 'g', 'i', debug, - "VCL references", - "" -) VSC_F(happy, uint64_t, 0, 'b', 'b', info, "Happy health probes", "" From phk at FreeBSD.org Mon Mar 2 10:51:59 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 02 Mar 2015 11:51:59 +0100 Subject: [master] d00ca93 Put the loaded VCL name into the childs VCL_conf structure Message-ID: commit d00ca93a73904dda55637e7fac286ecb80c23628 Author: Poul-Henning Kamp Date: Mon Mar 2 09:53:41 2015 +0000 Put the loaded VCL name into the childs VCL_conf structure diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 2522b81..cee97e8 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -47,7 +47,6 @@ struct vcls { unsigned magic; #define VVCLS_MAGIC 0x214188f2 VTAILQ_ENTRY(vcls) list; - char *name; void *dlh; struct VCL_conf conf[1]; }; @@ -162,7 +161,7 @@ vcl_find(const char *name) VTAILQ_FOREACH(vcl, &vcl_head, list) { if (vcl->conf->discard) continue; - if (!strcmp(vcl->name, name)) + if (!strcmp(vcl->conf->loaded_name, name)) return (vcl); } return (NULL); @@ -202,6 +201,8 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) return (1); } memcpy(vcl->conf, cnf, sizeof *cnf); + vcl->conf->loaded_name = strdup(name); + XXXAN(vcl->conf->loaded_name); if (vcl->conf->magic != VCL_CONF_MAGIC) { VCLI_Out(cli, "Wrong VCL_CONF_MAGIC\n"); @@ -233,7 +234,6 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) return (1); } assert(hand == VCL_RET_OK); - REPLACE(vcl->name, name); VCLI_Out(cli, "Loaded \"%s\" as \"%s\"", fn , name); VTAILQ_INSERT_TAIL(&vcl_head, vcl, list); Lck_Lock(&vcl_mtx); @@ -267,7 +267,7 @@ VCL_Nuke(struct vcls *vcl) (void)vcl->conf->fini_func(&ctx); assert(hand == VCL_RET_OK); AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_FINI)); - free(vcl->name); + free(vcl->conf->loaded_name); (void)dlclose(vcl->dlh); FREE_OBJ(vcl); VSC_C_main->n_vcl--; @@ -308,7 +308,7 @@ ccf_config_list(struct cli *cli, const char * const *av, void *priv) VCLI_Out(cli, "%-10s %6u %s\n", flg, vcl->conf->busy, - vcl->name); + vcl->conf->loaded_name); } } diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index aafcfc0..438f9ad 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -988,6 +988,8 @@ struct VCL_conf { unsigned magic; #define VCL_CONF_MAGIC 0x7406c509 /* from /dev/random */ + char *loaded_name; + struct director **director; unsigned ndirector; struct vrt_ref *ref; From phk at FreeBSD.org Mon Mar 2 10:51:59 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 02 Mar 2015 11:51:59 +0100 Subject: [master] 919151c Make VCL_conf available during VCL events. Message-ID: commit 919151ca37a2050c6b7e016017201087404bde55 Author: Poul-Henning Kamp Date: Mon Mar 2 10:13:45 2015 +0000 Make VCL_conf available during VCL events. diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index cee97e8..9606361 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -215,6 +215,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) ctx.method = VCL_MET_INIT; ctx.handling = &hand; ctx.cli = cli; + ctx.vcl = vcl->conf; if (vcl->conf->event_vcl(&ctx, VCL_EVENT_INIT)) { VCLI_Out(cli, "VCL \"%s\" Failed to initialize", name); @@ -264,6 +265,7 @@ VCL_Nuke(struct vcls *vcl) VTAILQ_REMOVE(&vcl_head, vcl, list); ctx.method = VCL_MET_FINI; ctx.handling = &hand; + ctx.vcl = vcl->conf; (void)vcl->conf->fini_func(&ctx); assert(hand == VCL_RET_OK); AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_FINI)); From phk at FreeBSD.org Mon Mar 2 10:51:59 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 02 Mar 2015 11:51:59 +0100 Subject: [master] 6f99a39 Change the backend names to be . Message-ID: commit 6f99a39addd5ee0af02d1032c5eaf7a5fefba416 Author: Poul-Henning Kamp Date: Mon Mar 2 10:50:40 2015 +0000 Change the backend names to be . The backend matching function now uses shell-like glob'ing: backend.list * -> all backends in active vcl backend.list *.* -> all backends in all vcls backend.list *.foo -> all backends named 'foo' in all vcls backend.list bar.* -> all backends in the vcl named bar diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 3aad027..91a8939 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -38,6 +38,7 @@ #include "cache_backend.h" #include "cache_director.h" +#include "vcl.h" #include "vrt.h" #include "vtcp.h" @@ -294,8 +295,9 @@ VRT_init_vbe(VRT_CTX, struct director **dp, const struct vrt_backend *vrt) AN(dp); AZ(*dp); CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC); + CHECK_OBJ_NOTNULL(ctx->vcl, VCL_CONF_MAGIC); - be = VBE_AddBackend(vrt); + be = VBE_AddBackend(ctx->vcl->loaded_name, vrt); AN(be); ALLOC_OBJ(d, DIRECTOR_MAGIC); XXXAN(d); diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index 72e57af..87616db 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -104,9 +104,9 @@ struct vbc { }; /* cache_backend_cfg.c */ -void VBE_DeleteBackend(struct backend *); unsigned VBE_Healthy(const struct backend *b, double *changed); -struct backend *VBE_AddBackend(const struct vrt_backend *vb); +struct backend *VBE_AddBackend(const char *vcl, const struct vrt_backend *vb); +void VBE_DeleteBackend(struct backend *); /* cache_backend_poll.c */ void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p, diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index 37431f5..293f13e 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -33,6 +33,7 @@ #include "config.h" #include +#include #include #include @@ -41,7 +42,9 @@ #include "cache_backend.h" #include "vcli.h" #include "vcli_priv.h" +#include "vcl.h" #include "vsa.h" +#include "vsb.h" #include "vrt.h" #include "vtim.h" @@ -78,7 +81,7 @@ VBE_DeleteBackend(struct backend *b) */ struct backend * -VBE_AddBackend(const struct vrt_backend *vb) +VBE_AddBackend(const char *vcl, const struct vrt_backend *vb) { struct backend *b; char buf[128]; @@ -92,15 +95,12 @@ VBE_AddBackend(const struct vrt_backend *vb) XXXAN(b); Lck_New(&b->mtx, lck_backend); - bprintf(buf, "%s(%s,%s,%s)", - vb->vcl_name, - vb->ipv4_addr == NULL ? "" : vb->ipv4_addr, - vb->ipv6_addr == NULL ? "" : vb->ipv6_addr, vb->port); + bprintf(buf, "%s.%s", vcl, vb->vcl_name); + REPLACE(b->display_name, buf); b->vsc = VSM_Alloc(sizeof *b->vsc, VSC_CLASS, VSC_type_vbe, buf); b->vcl_name = vb->vcl_name; - REPLACE(b->display_name, buf); b->ipv4_addr = vb->ipv4_addr; b->ipv6_addr = vb->ipv6_addr; b->port = vb->port; @@ -149,7 +149,7 @@ vbe_str2adminhealth(const char *wstate) * * Return -1 on match-argument parse errors. * - * If the call-back function returns non-zero, the search is terminated + * If the call-back function returns negative, the search is terminated * and we relay that return value. * * Otherwise we return the number of matches. @@ -160,95 +160,38 @@ typedef int bf_func(struct cli *cli, struct backend *b, void *priv); static int backend_find(struct cli *cli, const char *matcher, bf_func *func, void *priv) { + int i, found = 0; + struct vsb *vsb; + struct VCL_conf *vcc = NULL; struct backend *b; - const char *s; - const char *name_b; - ssize_t name_l = 0; - const char *ip_b = NULL; - ssize_t ip_l = 0; - const char *port_b = NULL; - ssize_t port_l = 0; - int all, found = 0; - int i; - - name_b = matcher; - if (matcher != NULL) { - s = strchr(matcher,'('); - - if (s != NULL) - name_l = s - name_b; - else - name_l = strlen(name_b); - - if (s != NULL) { - s++; - while (isspace(*s)) - s++; - ip_b = s; - while (*s != '\0' && - *s != ')' && - *s != ':' && - !isspace(*s)) - s++; - ip_l = s - ip_b; - while (isspace(*s)) - s++; - if (*s == ':') { - s++; - while (isspace(*s)) - s++; - port_b = s; - while (*s != '\0' && *s != ')' && !isspace(*s)) - s++; - port_l = s - port_b; - } - while (isspace(*s)) - s++; - if (*s != ')') { - VCLI_Out(cli, - "Match string syntax error:" - " ')' not found."); - VCLI_SetResult(cli, CLIS_CANT); - return (-1); - } - s++; - while (isspace(*s)) - s++; - if (*s != '\0') { - VCLI_Out(cli, - "Match string syntax error:" - " junk after ')'"); - VCLI_SetResult(cli, CLIS_CANT); - return (-1); - } - } - } - for (all = 0; all < 2 && found == 0; all++) { - if (all == 0 && name_b == NULL) + VCL_Refresh(&vcc); + AN(vcc); + vsb = VSB_new_auto(); + AN(vsb); + if (matcher == NULL || *matcher == '\0' || !strcmp(matcher, "*")) { + // all backends in active VCL + VSB_printf(vsb, "%s.*", vcc->loaded_name); + } else if (strchr(matcher, '.') != NULL) { + // use pattern as is + VSB_cat(vsb, matcher); + } else { + // pattern applies to active vcl + VSB_printf(vsb, "%s.%s", vcc->loaded_name, matcher); + } + AZ(VSB_finish(vsb)); + VCLI_Out(cli, "Using pattern \"%s\"\n", VSB_data(vsb)); + VTAILQ_FOREACH(b, &backends, list) { + if (fnmatch(VSB_data(vsb), b->display_name, FNM_CASEFOLD)) continue; - VTAILQ_FOREACH(b, &backends, list) { - CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - if (port_b != NULL && - strncmp(b->port, port_b, port_l) != 0) - continue; - if (name_b != NULL && - strncmp(b->vcl_name, name_b, name_l) != 0) - continue; - if (all == 0 && b->vcl_name[name_l] != '\0') - continue; - if (ip_b != NULL && - (b->ipv4_addr == NULL || - strncmp(b->ipv4_addr, ip_b, ip_l)) && - (b->ipv6_addr == NULL || - strncmp(b->ipv6_addr, ip_b, ip_l))) - continue; - found++; - i = func(cli, b, priv); - if (i) - return (i); + found++; + i = func(cli, b, priv); + if (i < 0) { + found = i; + break; } } + VSB_delete(vsb); return (found); } diff --git a/bin/varnishtest/tests/c00048.vtc b/bin/varnishtest/tests/c00048.vtc index 2502275..03ac275 100644 --- a/bin/varnishtest/tests/c00048.vtc +++ b/bin/varnishtest/tests/c00048.vtc @@ -58,8 +58,8 @@ client c1 { varnish v1 -clierr 106 "backend.set_health s1 foo" varnish v1 -clierr 106 "backend.set_health s2 foo" varnish v1 -clierr 106 "backend.set_health s2 auto" -varnish v1 -cliok "backend.list (foo)" -varnish v1 -clierr 300 "backend.list (" -varnish v1 -clierr 300 {backend.list " ( : ) -"} -varnish v1 -cliok {backend.list "a ( b : c )"} +varnish v1 -cliok "vcl.list" +varnish v1 -cliok "backend.list *" +varnish v1 -cliok "backend.list *.foo" +varnish v1 -cliok "backend.list vcl1.*" From phk at FreeBSD.org Mon Mar 2 12:02:04 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 02 Mar 2015 13:02:04 +0100 Subject: [master] ec24a17 Don't fold case in fnmatch, Solaris doesn't have it. Message-ID: commit ec24a1714adae7fc725b211e3e5ee31d17d7b259 Author: Poul-Henning Kamp Date: Mon Mar 2 12:01:47 2015 +0000 Don't fold case in fnmatch, Solaris doesn't have it. diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index 293f13e..5d0bea2 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -182,7 +182,7 @@ backend_find(struct cli *cli, const char *matcher, bf_func *func, void *priv) AZ(VSB_finish(vsb)); VCLI_Out(cli, "Using pattern \"%s\"\n", VSB_data(vsb)); VTAILQ_FOREACH(b, &backends, list) { - if (fnmatch(VSB_data(vsb), b->display_name, FNM_CASEFOLD)) + if (fnmatch(VSB_data(vsb), b->display_name, 0)) continue; found++; i = func(cli, b, priv); From phk at FreeBSD.org Mon Mar 2 12:31:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 02 Mar 2015 13:31:35 +0100 Subject: [master] 6bd3d3b Update this test-case, since it breaks 4.0.3 but not -trunk Message-ID: commit 6bd3d3ba9c4aa062646646ff83854bdab20af054 Author: Poul-Henning Kamp Date: Mon Mar 2 12:29:34 2015 +0000 Update this test-case, since it breaks 4.0.3 but not -trunk diff --git a/bin/varnishtest/tests/r01602.vtc b/bin/varnishtest/tests/r01602.vtc index 4411304..efbe4a2 100644 --- a/bin/varnishtest/tests/r01602.vtc +++ b/bin/varnishtest/tests/r01602.vtc @@ -7,12 +7,17 @@ server s1 { rxreq expect req.url == "/foo" txresp -hdr "Content-Encoding: gzip" + rxreq + expect req.url == "/baz" + txresp -gzipbody {} + rxreq + expect req.url == "/quux" + txresp -status 204 -hdr "Content-Encoding: gzip" } -start varnish v1 -vcl+backend { sub vcl_backend_response { set beresp.do_esi = true; - set beresp.do_gzip = true; } } -start @@ -20,4 +25,7 @@ client c1 { txreq -url /bar -hdr "Accept-Encoding: gzip" rxresp expect resp.status == 200 + txreq -url /baz -hdr "Accept-Encoding: gzip" + rxresp + expect resp.status == 200 } -run From phk at FreeBSD.org Mon Mar 2 14:07:18 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 02 Mar 2015 15:07:18 +0100 Subject: [master] a61cf0d NUL terminate the ungzip'ed body so we can expect on it. Message-ID: commit a61cf0d1a693add65432d8a796a6630af0df5956 Author: Poul-Henning Kamp Date: Mon Mar 2 14:06:48 2015 +0000 NUL terminate the ungzip'ed body so we can expect on it. Fixes #1688 diff --git a/bin/varnishtest/tests/r01688.vtc b/bin/varnishtest/tests/r01688.vtc new file mode 100644 index 0000000..fd0373b --- /dev/null +++ b/bin/varnishtest/tests/r01688.vtc @@ -0,0 +1,45 @@ +varnishtest "ESI-included, compressed synthetic responses" + +server s1 { + rxreq + expect req.url == "/bar" + txresp -gzipbody {} + rxreq + expect req.url == "/baz" + txresp -gzipbody {} +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.url == "/foo" || req.url == "/quux") { + return(synth(998, "included synthetic reponse")); + } + } + + sub vcl_synth { + if (resp.status == 998) { + synthetic("this is the body of an included synthetic response"); + return(deliver); + } + } + + sub vcl_backend_response { + set beresp.do_esi = true; + } +} -start + +client c1 { + txreq -url /bar + rxresp + expect resp.status == 200 + delay .1 + expect resp.body == "this is the body of an included synthetic response" + + txreq -url /baz -hdr "Accept-Encoding: gzip" + timeout 2 + rxresp + expect resp.status == 200 + expect resp.http.Content-Encoding == "gzip" + gunzip + expect resp.body == "this is the body of an included synthetic response" +} -run diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index ba591ae..68aacde 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -633,6 +633,7 @@ cmd_http_gunzip_body(CMD_ARGS) assert(Z_OK == inflateInit2(&vz, 31)); i = inflate(&vz, Z_FINISH); + assert(vz.total_out < l); hp->bodyl = vz.total_out; memcpy(hp->body, p, hp->bodyl); free(p); @@ -653,6 +654,7 @@ cmd_http_gunzip_body(CMD_ARGS) "Gunzip error = %d (%s) in:%jd out:%jd", i, vz.msg, (intmax_t)vz.total_in, (intmax_t)vz.total_out); assert(Z_OK == inflateEnd(&vz)); + hp->body[hp->bodyl] = '\0'; } /********************************************************************** From phk at FreeBSD.org Mon Mar 2 22:43:02 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 02 Mar 2015 23:43:02 +0100 Subject: [master] bbac365 Try to improve the state-management for the backend waiters -- or failing that, try to get better diagnostics about what it does wrong... Message-ID: commit bbac365619c995096d6a690bf531227e095424d4 Author: Poul-Henning Kamp Date: Mon Mar 2 22:42:19 2015 +0000 Try to improve the state-management for the backend waiters -- or failing that, try to get better diagnostics about what it does wrong... diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index 87616db..2fa7694 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -95,9 +95,10 @@ struct vbc { uint8_t state; #define VBC_STATE_AVAIL (1<<0) #define VBC_STATE_USED (1<<1) -#define VBC_STATE_CLEANUP (1<<2) +#define VBC_STATE_STOLEN (1<<2) +#define VBC_STATE_CLEANUP (1<<3) uint8_t in_waiter; - uint8_t stolen; + uint8_t have_been_in_waiter; struct waited waited[1]; struct backend *backend; diff --git a/bin/varnishd/cache/cache_backend_tcp.c b/bin/varnishd/cache/cache_backend_tcp.c index e348823..d88a0cf 100644 --- a/bin/varnishd/cache/cache_backend_tcp.c +++ b/bin/varnishd/cache/cache_backend_tcp.c @@ -90,44 +90,40 @@ tcp_handle(struct waited *w, enum wait_event ev, double now) Lck_Lock(&tp->mtx); VSL(SLT_Debug, 0, - "------> Handler fd %d in_w %d state %d ev %d stolen %d", - vbc->fd, vbc->in_waiter, vbc->state, ev, vbc->stolen); + "------> Handler fd %d in_w %d state 0x%x ev %d have_been %d", + vbc->fd, vbc->in_waiter, vbc->state, ev, vbc->have_been_in_waiter); AN(vbc->in_waiter); switch(vbc->state) { - case VBC_STATE_AVAIL: - if (ev != WAITER_ACTION || !vbc->stolen) { - VSL(SLT_Debug, - 0, "------> Handler avail + !action -> close"); + case VBC_STATE_STOLEN: + vbc->state = VBC_STATE_AVAIL; + VTAILQ_REMOVE(&tp->connlist, vbc, list); + if (Wait_Enter(tp->waiter, vbc->waited)) { + VSL(SLT_Debug, 0, + "------> Handler stolen -> re-wait failed"); VTCP_close(&vbc->fd); - VTAILQ_REMOVE(&tp->connlist, vbc, list); tp->n_conn--; FREE_OBJ(vbc); } else { - VSL(SLT_Debug, 0, - "------> Handler avail + action -> re-wait"); - vbc->stolen = 0; - if (Wait_Enter(tp->waiter, vbc->waited)) { - VSL(SLT_Debug, 0, - "------> Handler avail + " - "!timeout -> re-wait failed"); - VTCP_close(&vbc->fd); - VTAILQ_REMOVE(&tp->connlist, vbc, list); - tp->n_conn--; - FREE_OBJ(vbc); - } + VTAILQ_INSERT_HEAD(&tp->connlist, vbc, list); } break; + case VBC_STATE_AVAIL: + VTCP_close(&vbc->fd); + VTAILQ_REMOVE(&tp->connlist, vbc, list); + tp->n_conn--; + FREE_OBJ(vbc); + break; case VBC_STATE_USED: - VSL(SLT_Debug, 0, "------> Handler used"); vbc->in_waiter = 0; + vbc->have_been_in_waiter = 1; break; case VBC_STATE_CLEANUP: - VSL(SLT_Debug, 0, "------> Handler cleanup"); VTCP_close(&vbc->fd); tp->n_kill--; VTAILQ_REMOVE(&tp->killlist, vbc, list); - FREE_OBJ(vbc); + memset(vbc, 0x11, sizeof *vbc); + free(vbc); break; default: WRONG("Wrong vbc state"); @@ -223,7 +219,8 @@ VBT_Rel(struct tcp_pool **tpp) tp->n_kill++; } else { VTCP_close(&vbc->fd); - FREE_OBJ(vbc); + memset(vbc, 0x22, sizeof *vbc); + free(vbc); } } while (tp->n_kill) { @@ -298,18 +295,23 @@ VBT_Recycle(struct tcp_pool *tp, struct vbc **vbcp) vbc->waited->ptr = vbc; vbc->waited->fd = vbc->fd; vbc->waited->idle = VTIM_real(); + vbc->state = VBC_STATE_AVAIL; VSL(SLT_Debug, 0, "------> Recycle fd %d Wait_Enter", vbc->fd); if (Wait_Enter(tp->waiter, vbc->waited)) { VTCP_close(&vbc->fd); - FREE_OBJ(vbc); + memset(vbc, 0x33, sizeof *vbc); + free(vbc); + vbc = NULL; + } else { + VTAILQ_INSERT_HEAD(&tp->connlist, vbc, list); } i = 1; + } else { + vbc->state = VBC_STATE_STOLEN; + VTAILQ_INSERT_TAIL(&tp->connlist, vbc, list); } if (vbc != NULL) { - vbc->state = VBC_STATE_AVAIL; - vbc->stolen = 1; - VTAILQ_INSERT_HEAD(&tp->connlist, vbc, list); tp->n_conn++; vbc->recycled = 1; } @@ -360,7 +362,8 @@ VBT_Close(struct tcp_pool *tp, struct vbc **vbcp) tp->n_kill++; } else { VTCP_close(&vbc->fd); - FREE_OBJ(vbc); + memset(vbc, 0x44, sizeof *vbc); + free(vbc); } Lck_Unlock(&tp->mtx); } @@ -381,8 +384,10 @@ VBT_Get(struct tcp_pool *tp, double tmo) if (vbc != NULL) { CHECK_OBJ_NOTNULL(vbc, VBC_MAGIC); - assert(vbc->state == VBC_STATE_AVAIL); - VSL(SLT_Debug, 0, "------> Steal fd %d", vbc->fd); + VSL(SLT_Debug, 0, "------> Steal fd %d state 0x%x", + vbc->fd, vbc->state); + assert(vbc->state == VBC_STATE_AVAIL || + vbc->state == VBC_STATE_STOLEN); VTAILQ_REMOVE(&tp->connlist, vbc, list); tp->n_conn--; From phk at FreeBSD.org Tue Mar 3 08:51:53 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 03 Mar 2015 09:51:53 +0100 Subject: [master] 63bf572 Make vdef.h part of the VCC output Message-ID: commit 63bf572edd04a45f6ee4f695d831c3e108a86de3 Author: Poul-Henning Kamp Date: Tue Mar 3 08:51:26 2015 +0000 Make vdef.h part of the VCC output diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 438f9ad..9c90a55 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -1153,6 +1153,7 @@ vcl_output_lang_h(struct vsb *sb) { """) +emit_file(fo, buildroot, "include/vdef.h") emit_file(fo, buildroot, "include/vcl.h") emit_file(fo, srcroot, "include/vrt.h") emit_file(fo, buildroot, "include/vrt_obj.h") diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c index 4ebe707..e210c42 100644 --- a/lib/libvcc/vcc_compile.c +++ b/lib/libvcc/vcc_compile.c @@ -632,8 +632,6 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp) /* Macro for accessing directors */ Fh(tl, 0, "#define VGCDIR(n) VCL_conf.director[VGC_backend_##n]\n"); - Fh(tl, 0, "#define __match_proto__(xxx) /*lint -e{818} */\n"); - /* Register and lex the main source */ VTAILQ_INSERT_TAIL(&tl->sources, sp, list); sp->idx = tl->nsources++; From phk at FreeBSD.org Tue Mar 3 10:06:13 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 03 Mar 2015 11:06:13 +0100 Subject: [master] 58b262f Add a callback facility to be notified about events in the expiry module. Message-ID: commit 58b262f1c8a2f2b5f9b3a977c7f7f799603820a1 Author: Poul-Henning Kamp Date: Tue Mar 3 10:05:19 2015 +0000 Add a callback facility to be notified about events in the expiry module. This is necessary for VMODs which implement secondary hash-keys. Patches from martin@ with some minor tweaking by me. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index fcb8c69..9b2aec0 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -778,14 +778,25 @@ void EXP_Clr(struct exp *e); double EXP_Ttl(const struct req *, const struct exp*); double EXP_When(const struct exp *exp); -void EXP_Insert(struct objcore *oc); -void EXP_Inject(struct objcore *oc, struct lru *lru); +void EXP_Insert(struct worker *wrk, struct objcore *oc); +void EXP_Inject(struct worker *wrk, struct objcore *oc, struct lru *lru); void EXP_Init(void); void EXP_Rearm(struct objcore *, double now, double ttl, double grace, double keep); void EXP_Touch(struct objcore *oc, double now); int EXP_NukeOne(struct worker *wrk, struct lru *lru); +enum exp_event_e { + EXP_INSERT, + EXP_INJECT, + EXP_REMOVE, +}; +typedef void exp_callback_f(struct worker *, struct objcore *, + enum exp_event_e, void *priv); + +uintptr_t EXP_Register_Callback(exp_callback_f *func, void *priv); +void EXP_Deregister_Callback(uintptr_t*); + /* cache_fetch.c */ enum vbf_fetch_mode_e { VBF_NORMAL = 0, diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c index 79a8d2f..0590343 100644 --- a/bin/varnishd/cache/cache_expire.c +++ b/bin/varnishd/cache/cache_expire.c @@ -41,6 +41,14 @@ #include "hash/hash_slinger.h" #include "vtim.h" +struct exp_callback { + unsigned magic; +#define EXP_CALLBACK_MAGIC 0xab956eb1 + exp_callback_f *func; + void *priv; + VTAILQ_ENTRY(exp_callback) list; +}; + struct exp_priv { unsigned magic; #define EXP_PRIV_MAGIC 0x9db22482 @@ -52,10 +60,33 @@ struct exp_priv { VTAILQ_HEAD(,objcore) inbox; struct binheap *heap; pthread_cond_t condvar; + + VTAILQ_HEAD(,exp_callback) ecb_list; + pthread_rwlock_t cb_rwl; }; static struct exp_priv *exphdl; +static void +exp_event(struct worker *wrk, struct objcore *oc, enum exp_event_e e) +{ + struct exp_callback *cb; + + /* + * Strictly speaking this is not atomic, but neither is VMOD + * loading in general, so this is a fair optimization + */ + if (VTAILQ_EMPTY(&exphdl->ecb_list)) + return; + + AZ(pthread_rwlock_rdlock(&exphdl->cb_rwl)); + VTAILQ_FOREACH(cb, &exphdl->ecb_list, list) { + CHECK_OBJ_NOTNULL(cb, EXP_CALLBACK_MAGIC); + cb->func(wrk, oc, e, cb->priv); + } + AZ(pthread_rwlock_unlock(&exphdl->cb_rwl)); +} + /*-------------------------------------------------------------------- * struct exp manipulations */ @@ -130,9 +161,10 @@ exp_mail_it(struct objcore *oc) */ void -EXP_Inject(struct objcore *oc, struct lru *lru) +EXP_Inject(struct worker *wrk, struct objcore *oc, struct lru *lru) { + CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); AZ(oc->exp_flags & (OC_EF_OFFLRU | OC_EF_INSERT | OC_EF_MOVE)); @@ -146,6 +178,8 @@ EXP_Inject(struct objcore *oc, struct lru *lru) oc->timer_when = EXP_When(&oc->exp); Lck_Unlock(&lru->mtx); + exp_event(wrk, oc, EXP_INJECT); + exp_mail_it(oc); } @@ -157,10 +191,11 @@ EXP_Inject(struct objcore *oc, struct lru *lru) */ void -EXP_Insert(struct objcore *oc) +EXP_Insert(struct worker *wrk, struct objcore *oc) { struct lru *lru; + CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); HSH_Ref(oc); @@ -177,6 +212,8 @@ EXP_Insert(struct objcore *oc) oc->exp_flags |= OC_EF_MOVE; Lck_Unlock(&lru->mtx); + exp_event(wrk, oc, EXP_INSERT); + exp_mail_it(oc); } @@ -344,6 +381,45 @@ EXP_NukeOne(struct worker *wrk, struct lru *lru) return (1); } +/*--------------------------------------------------------------------*/ + +uintptr_t +EXP_Register_Callback(exp_callback_f *func, void *priv) +{ + struct exp_callback *ecb; + + AN(func); + + ALLOC_OBJ(ecb, EXP_CALLBACK_MAGIC); + AN(ecb); + ecb->func = func; + ecb->priv = priv; + AZ(pthread_rwlock_wrlock(&exphdl->cb_rwl)); + VTAILQ_INSERT_TAIL(&exphdl->ecb_list, ecb, list); + AZ(pthread_rwlock_unlock(&exphdl->cb_rwl)); + return ((uintptr_t)ecb); +} + +void +EXP_Deregister_Callback(uintptr_t *handle) +{ + struct exp_callback *ecb; + + AN(handle); + AN(*handle); + AZ(pthread_rwlock_wrlock(&exphdl->cb_rwl)); + VTAILQ_FOREACH(ecb, &exphdl->ecb_list, list) { + CHECK_OBJ_NOTNULL(ecb, EXP_CALLBACK_MAGIC); + if ((uintptr_t)ecb == *handle) + break; + } + AN(ecb); + VTAILQ_REMOVE(&exphdl->ecb_list, ecb, list); + AZ(pthread_rwlock_unlock(&exphdl->cb_rwl)); + FREE_OBJ(ecb); + *handle = 0; +} + /*-------------------------------------------------------------------- * Handle stuff in the inbox */ @@ -385,6 +461,7 @@ exp_inbox(struct exp_priv *ep, struct objcore *oc, double now) binheap_delete(ep->heap, oc->timer_idx); } assert(oc->timer_idx == BINHEAP_NOIDX); + exp_event(ep->wrk, oc, EXP_REMOVE); (void)HSH_DerefObjCore(ep->wrk, &oc); return; } @@ -464,6 +541,7 @@ exp_expire(struct exp_priv *ep, double now) CHECK_OBJ_NOTNULL(oc->objhead, OBJHEAD_MAGIC); VSLb(&ep->vsl, SLT_ExpKill, "EXP_Expired x=%u t=%.0f", ObjGetXID(ep->wrk, oc), EXP_Ttl(NULL, &oc->exp) - now); + exp_event(ep->wrk, oc, EXP_REMOVE); (void)HSH_DerefObjCore(ep->wrk, &oc); return (0); } @@ -545,6 +623,8 @@ EXP_Init(void) Lck_New(&ep->mtx, lck_exp); AZ(pthread_cond_init(&ep->condvar, NULL)); VTAILQ_INIT(&ep->inbox); + AZ(pthread_rwlock_init(&ep->cb_rwl, NULL)); + VTAILQ_INIT(&ep->ecb_list); exphdl = ep; WRK_BgThread(&pt, "cache-timeout", exp_thread, ep); } diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index de35e8a..686d398 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -693,7 +693,7 @@ HSH_Unbusy(struct worker *wrk, struct objcore *oc) if (!(oc->flags & OC_F_PRIVATE)) { BAN_NewObjCore(oc); - EXP_Insert(oc); + EXP_Insert(wrk, oc); AN(oc->exp_flags & OC_EF_EXP); AN(oc->ban); } diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt index 408513a..1a34c01 100644 --- a/bin/varnishd/flint.lnt +++ b/bin/varnishd/flint.lnt @@ -111,6 +111,7 @@ -emacro(527, NEEDLESS_RETURN) // unreachable code -sem(EXP_Inject, custodial(1)) +-sem(HSH_Insert, custodial(3)) -sem(WS_Init, custodial(2)) -sem(http_Setup, custodial(2)) -sem(vfp_esi_end, custodial(2)) diff --git a/bin/varnishd/storage/storage_persistent_silo.c b/bin/varnishd/storage/storage_persistent_silo.c index 8d02ed3..8119aad 100644 --- a/bin/varnishd/storage/storage_persistent_silo.c +++ b/bin/varnishd/storage/storage_persistent_silo.c @@ -166,7 +166,7 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc, oc->ban = BAN_RefBan(oc, so->ban, sc->tailban); HSH_Insert(wrk, so->hash, oc); oc->exp = so->exp; - EXP_Inject(oc, sg->lru); + EXP_Inject(wrk, oc, sg->lru); sg->nobj++; } Pool_Sumstat(wrk); diff --git a/bin/varnishtest/tests/m00021.vtc b/bin/varnishtest/tests/m00021.vtc new file mode 100644 index 0000000..5db3362 --- /dev/null +++ b/bin/varnishtest/tests/m00021.vtc @@ -0,0 +1,49 @@ +varnishtest "Test expiry callbacks" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend {} -start + +varnish v1 -cliok "param.set debug +vclrel" + +logexpect l1 -v v1 -g raw { + expect * 0 Debug "exp_cb: registered" + expect * 0 Debug "exp_cb: event insert 0x[0-9a-f]+" + expect * 0 Debug "exp_cb: event remove 0x[0-9a-f]+" + expect * 0 Debug "exp_cb: deregistered" +} -start + +varnish v1 -vcl+backend { + import ${vmod_debug}; + + sub vcl_init { + debug.register_exp_callback(); + } + + sub vcl_recv { + if (req.method == "PURGE") { + return (purge); + } + } +} + +client c1 { + txreq + rxresp + expect resp.status == 200 + + txreq -req PURGE + rxresp +} -run +varnish v1 -expect n_object == 0 + +varnish v1 -vcl+backend {} +varnish v1 -cliok "vcl.discard vcl2" +varnish v1 -cliok "debug.vmod" +varnish v1 -cliok "vcl.list" +varnish v1 -expect vmods == 0 + +logexpect l1 -wait diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc index b5d108c..8e940f4 100644 --- a/lib/libvmod_debug/vmod.vcc +++ b/lib/libvmod_debug/vmod.vcc @@ -93,3 +93,7 @@ Encrypt the HTTP header with quad-ROT13 encryption, $Function STRING argtest(STRING one, REAL two=2, STRING three="3") $Function INT vre_limit() + +$Function VOID register_exp_callback(PRIV_VCL) + +Register the vmod to receive expiry callbacks diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c index b6736fb..9dcfb7d 100644 --- a/lib/libvmod_debug/vmod_debug.c +++ b/lib/libvmod_debug/vmod_debug.c @@ -36,6 +36,13 @@ #include "vrt.h" #include "vcc_if.h" +struct priv_vcl { + unsigned magic; +#define PRIV_VCL_MAGIC 0x8E62FA9D + char *foo; + uintptr_t exp_cb; +}; + VCL_VOID __match_proto__(td_debug_panic) vmod_panic(VRT_CTX, const char *str, ...) { @@ -65,16 +72,6 @@ vmod_author(VRT_CTX, VCL_ENUM id) WRONG("Illegal VMOD enum"); } -int -init_function(struct vmod_priv *priv, const struct VCL_conf *cfg) -{ - (void)cfg; - - priv->priv = strdup("FOO"); - priv->free = free; - return (0); -} - VCL_VOID __match_proto__(td_debug_test_priv_call) vmod_test_priv_call(VRT_CTX, struct vmod_priv *priv) { @@ -103,9 +100,13 @@ vmod_test_priv_task(VRT_CTX, struct vmod_priv *priv, VCL_STRING s) VCL_VOID __match_proto__(td_debug_test_priv_vcl) vmod_test_priv_vcl(VRT_CTX, struct vmod_priv *priv) { + struct priv_vcl *priv_vcl; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - assert(!strcmp(priv->priv, "FOO")); + AN(priv); + CAST_OBJ_NOTNULL(priv_vcl, priv->priv, PRIV_VCL_MAGIC); + AN(priv_vcl->foo); + assert(!strcmp(priv_vcl->foo, "FOO")); } VCL_BLOB @@ -175,3 +176,65 @@ vmod_vre_limit(VRT_CTX) (void)ctx; return (cache_param->vre_limits.match); } + +static void __match_proto__(exp_callback_f) +exp_cb(struct worker *wrk, struct objcore *oc, enum exp_event_e ev, void *priv) +{ + const struct priv_vcl *priv_vcl; + const char *what; + + CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); + CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); + CAST_OBJ_NOTNULL(priv_vcl, priv, PRIV_VCL_MAGIC); + switch (ev) { + case EXP_INSERT: what = "insert"; break; + case EXP_INJECT: what = "inject"; break; + case EXP_REMOVE: what = "remove"; break; + default: WRONG("Wrong exp_event"); + } + VSL(SLT_Debug, 0, "exp_cb: event %s %p", what, oc); +} + +VCL_VOID __match_proto__() +vmod_register_exp_callback(VRT_CTX, struct vmod_priv *priv) +{ + struct priv_vcl *priv_vcl; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + CAST_OBJ_NOTNULL(priv_vcl, priv->priv, PRIV_VCL_MAGIC); + AZ(priv_vcl->exp_cb); + priv_vcl->exp_cb = EXP_Register_Callback(exp_cb, priv_vcl); + VSL(SLT_Debug, 0, "exp_cb: registered"); +} + +static void __match_proto__(vmod_priv_free_f) +priv_vcl_free(void *priv) +{ + struct priv_vcl *priv_vcl; + + CAST_OBJ_NOTNULL(priv_vcl, priv, PRIV_VCL_MAGIC); + AN(priv_vcl->foo); + free(priv_vcl->foo); + if (priv_vcl->exp_cb != 0) { + EXP_Deregister_Callback(&priv_vcl->exp_cb); + VSL(SLT_Debug, 0, "exp_cb: deregistered"); + } + FREE_OBJ(priv_vcl); + AZ(priv_vcl); +} + +int __match_proto__(vmod_init_f) +init_function(struct vmod_priv *priv, const struct VCL_conf *cfg) +{ + struct priv_vcl *priv_vcl; + + (void)cfg; + + ALLOC_OBJ(priv_vcl, PRIV_VCL_MAGIC); + AN(priv_vcl); + priv_vcl->foo = strdup("FOO"); + AN(priv_vcl->foo); + priv->priv = priv_vcl; + priv->free = priv_vcl_free; + return (0); +} From phk at FreeBSD.org Tue Mar 3 10:18:28 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 03 Mar 2015 11:18:28 +0100 Subject: [master] 750e6a8 Remove some unneeded #includes Message-ID: commit 750e6a800b8eaf289f03e0a99bc20405acfce6d8 Author: Poul-Henning Kamp Date: Tue Mar 3 10:18:14 2015 +0000 Remove some unneeded #includes diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index 5d0bea2..a9fdd12 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -32,7 +32,6 @@ #include "config.h" -#include #include #include #include @@ -44,7 +43,6 @@ #include "vcli_priv.h" #include "vcl.h" #include "vsa.h" -#include "vsb.h" #include "vrt.h" #include "vtim.h" diff --git a/bin/varnishd/cache/cache_backend_tcp.c b/bin/varnishd/cache/cache_backend_tcp.c index d88a0cf..424f276 100644 --- a/bin/varnishd/cache/cache_backend_tcp.c +++ b/bin/varnishd/cache/cache_backend_tcp.c @@ -39,7 +39,6 @@ #include "cache.h" #include "cache_backend.h" -#include "vrt.h" #include "vtcp.h" #include "vsa.h" #include "waiter/waiter.h" diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index e1fa86f..9fd34dd 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -62,13 +62,10 @@ #include "config.h" -#include #include #include -#include #include "cache.h" -#include "storage/storage.h" #include "hash/hash_slinger.h" #include "vcli.h" diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c index 44997f1..2ba43fd 100644 --- a/bin/varnishd/cache/cache_busyobj.c +++ b/bin/varnishd/cache/cache_busyobj.c @@ -34,7 +34,6 @@ #include #include -#include #include "cache.h" From phk at FreeBSD.org Tue Mar 3 11:53:13 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 03 Mar 2015 12:53:13 +0100 Subject: [master] 2b0c4db Add a test-case to check the master process signal handling Message-ID: commit 2b0c4db89717f18e340617f2bc11221d29bbe449 Author: Poul-Henning Kamp Date: Tue Mar 3 11:52:51 2015 +0000 Add a test-case to check the master process signal handling diff --git a/bin/varnishtest/tests/b00044.vtc b/bin/varnishtest/tests/b00044.vtc new file mode 100644 index 0000000..5d02319 --- /dev/null +++ b/bin/varnishtest/tests/b00044.vtc @@ -0,0 +1,17 @@ +varnishtest "Test/coverage of varnish master signal handling" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { } -start + +client c1 { + txreq + rxresp +} -run + +server s1 -wait + +shell "kill -15 ${v1_pid}" diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index fbe59f8..9ec7683 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -384,7 +384,7 @@ varnish_launch(struct varnish *v) vsb = VSB_new_auto(); AN(vsb); VSB_printf(vsb, "cd ${pwd} &&"); - VSB_printf(vsb, " ${varnishd} -d -d -n %s", v->workdir); + VSB_printf(vsb, "exec ${varnishd} -d -d -n %s", v->workdir); VSB_printf(vsb, " -l 2m,1m,-"); VSB_printf(vsb, " -p auto_restart=off"); VSB_printf(vsb, " -p syslog_cli_traffic=off"); @@ -420,6 +420,7 @@ varnish_launch(struct varnish *v) exit(1); } else { vtc_log(v->vl, 3, "PID: %ld", (long)v->pid); + macro_def(v->vl, v->name, "pid", "%ld", (long)v->pid); } AZ(close(v->fds[0])); AZ(close(v->fds[3])); @@ -462,7 +463,6 @@ varnish_launch(struct varnish *v) vtc_log(v->vl, 3, "CLI connection fd = %d", v->cli_fd); assert(v->cli_fd >= 0); - /* Receive the banner or auth response */ u = varnish_ask_cli(v, NULL, &r); if (vtc_error) From phk at FreeBSD.org Tue Mar 3 13:26:28 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 03 Mar 2015 14:26:28 +0100 Subject: [master] d0fa72c Remove unnecessary #includes Message-ID: commit d0fa72c0906003b800634dba00384680de084b6c Author: Poul-Henning Kamp Date: Tue Mar 3 13:26:14 2015 +0000 Remove unnecessary #includes diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 3dc72ca..b05c43f 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -41,7 +41,6 @@ #include "config.h" -#include #include #include #include diff --git a/bin/varnishd/cache/cache_expire.c b/bin/varnishd/cache/cache_expire.c index 0590343..4db9537 100644 --- a/bin/varnishd/cache/cache_expire.c +++ b/bin/varnishd/cache/cache_expire.c @@ -32,7 +32,6 @@ #include "config.h" -#include #include #include "cache.h" diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index fbe19a6..664bf3d 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -29,15 +29,9 @@ #include "config.h" -#include -#include -#include -#include - #include "cache.h" #include "cache_director.h" #include "cache_filter.h" -#include "vend.h" #include "hash/hash_slinger.h" #include "vcl.h" #include "vtim.h" diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c index 8e5be9f..e7a06de 100644 --- a/bin/varnishd/cache/cache_fetch_proc.c +++ b/bin/varnishd/cache/cache_fetch_proc.c @@ -30,15 +30,11 @@ #include "config.h" #include -#include -#include #include #include "cache.h" #include "cache_filter.h" -#include "hash/hash_slinger.h" - #include "vcli_priv.h" static unsigned fetchfrag; diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c index 6cf6370..a71ef4a 100644 --- a/bin/varnishd/cache/cache_gzip.c +++ b/bin/varnishd/cache/cache_gzip.c @@ -38,14 +38,12 @@ #include "config.h" -#include #include #include "cache.h" #include "cache_filter.h" #include "vend.h" -#include "vend.h" #include "vgz.h" struct vgz { diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index 686d398..40412ee 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -52,7 +52,6 @@ #include "config.h" -#include #include #include diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c index b35b629..fa601fc 100644 --- a/bin/varnishd/cache/cache_lck.c +++ b/bin/varnishd/cache/cache_lck.c @@ -36,7 +36,6 @@ #include "config.h" #include -#include #include "cache.h" diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c index 79d1841..74e7c12 100644 --- a/bin/varnishd/cache/cache_mempool.c +++ b/bin/varnishd/cache/cache_mempool.c @@ -33,7 +33,6 @@ #include #include - #include "cache.h" #include "vtim.h" diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c index 95e3e75..c358e13 100644 --- a/bin/varnishd/cache/cache_pool.c +++ b/bin/varnishd/cache/cache_pool.c @@ -35,7 +35,6 @@ #include "config.h" -#include #include #include "cache.h" diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c index 9368c1d..921d449 100644 --- a/bin/varnishd/cache/cache_req_body.c +++ b/bin/varnishd/cache/cache_req_body.c @@ -30,7 +30,6 @@ #include "config.h" -#include #include #include "cache.h" diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index d78e24b..42f5230 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -38,7 +38,6 @@ #include "config.h" -#include #include #include diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c index 3d66fe5..d1ce206 100644 --- a/bin/varnishd/cache/cache_rfc2616.c +++ b/bin/varnishd/cache/cache_rfc2616.c @@ -29,7 +29,6 @@ #include "config.h" -#include #include #include "cache.h" diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 7992834..0f551da 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -40,7 +40,6 @@ #include "config.h" -#include #include #include diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index 96bbc65..cce45c6 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -30,7 +30,6 @@ */ #include "config.h" -#include #include #include diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c index 416f974..ce4eb53 100644 --- a/bin/varnishd/cache/cache_wrk.c +++ b/bin/varnishd/cache/cache_wrk.c @@ -31,7 +31,6 @@ #include "config.h" -#include #include #include diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 634bfe9..685f2e7 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -29,7 +29,6 @@ #include "config.h" -#include #include #include diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 84a8c16..b2b6470 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -33,7 +33,6 @@ #include "config.h" -#include #include #include #include diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c index 0120d13..436e2eb 100644 --- a/bin/varnishd/waiter/cache_waiter.c +++ b/bin/varnishd/waiter/cache_waiter.c @@ -33,7 +33,6 @@ #include #include #include -#include #include "cache/cache.h" diff --git a/bin/varnishd/waiter/cache_waiter_ports.c b/bin/varnishd/waiter/cache_waiter_ports.c index bcf3ea9..8d71ffe 100644 --- a/bin/varnishd/waiter/cache_waiter_ports.c +++ b/bin/varnishd/waiter/cache_waiter_ports.c @@ -35,7 +35,6 @@ #include -#include #include #include #include From phk at FreeBSD.org Tue Mar 3 13:28:40 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 03 Mar 2015 14:28:40 +0100 Subject: [master] c1f65aa Don't rely on %p format having 0x prefix Message-ID: commit c1f65aa14b06fc620ee005ea8aea53e2c6240a00 Author: Poul-Henning Kamp Date: Tue Mar 3 13:28:24 2015 +0000 Don't rely on %p format having 0x prefix diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c index 9dcfb7d..f102247 100644 --- a/lib/libvmod_debug/vmod_debug.c +++ b/lib/libvmod_debug/vmod_debug.c @@ -192,7 +192,8 @@ exp_cb(struct worker *wrk, struct objcore *oc, enum exp_event_e ev, void *priv) case EXP_REMOVE: what = "remove"; break; default: WRONG("Wrong exp_event"); } - VSL(SLT_Debug, 0, "exp_cb: event %s %p", what, oc); + VSL(SLT_Debug, 0, "exp_cb: event %s 0x%jx", what, + (intmax_t)(uintptr_t)oc); } VCL_VOID __match_proto__() From phk at FreeBSD.org Tue Mar 3 13:44:03 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 03 Mar 2015 14:44:03 +0100 Subject: [master] e25c648 Remove even more unneeded includes Message-ID: commit e25c6483872b4150ba200d1b011bc571a362102d Author: Poul-Henning Kamp Date: Tue Mar 3 13:38:18 2015 +0000 Remove even more unneeded includes diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 9b2aec0..9b408ac 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -34,6 +34,8 @@ */ #define VARNISH_CACHE_CHILD 1 +#include + #include "common/common.h" #include "vapi/vsl_int.h" @@ -44,7 +46,6 @@ #ifdef HAVE_PTHREAD_NP_H #include #endif -#include #include #include #include diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c index 9fd34dd..84f8aab 100644 --- a/bin/varnishd/cache/cache_ban.c +++ b/bin/varnishd/cache/cache_ban.c @@ -63,7 +63,6 @@ #include "config.h" #include -#include #include "cache.h" diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c index ce4eb53..c793176 100644 --- a/bin/varnishd/cache/cache_wrk.c +++ b/bin/varnishd/cache/cache_wrk.c @@ -31,7 +31,6 @@ #include "config.h" -#include #include #include "cache.h" diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c index 3264797..c6f2d6a 100644 --- a/bin/varnishd/cache/cache_ws.c +++ b/bin/varnishd/cache/cache_ws.c @@ -31,7 +31,6 @@ #include "config.h" #include -#include #include "cache.h" diff --git a/bin/varnishd/http1/cache_http1_line.c b/bin/varnishd/http1/cache_http1_line.c index 5601ddc..1308ee0 100644 --- a/bin/varnishd/http1/cache_http1_line.c +++ b/bin/varnishd/http1/cache_http1_line.c @@ -37,7 +37,6 @@ #include #include -#include #include #include "cache/cache.h" diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c index 491ed62..160cc35 100644 --- a/bin/varnishd/storage/storage_persistent.c +++ b/bin/varnishd/storage/storage_persistent.c @@ -41,7 +41,6 @@ #include #include #include -#include #include "cache/cache.h" #include "storage/storage.h" diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c index 436e2eb..acd6301 100644 --- a/bin/varnishd/waiter/cache_waiter.c +++ b/bin/varnishd/waiter/cache_waiter.c @@ -31,8 +31,6 @@ #include "config.h" #include #include -#include -#include #include "cache/cache.h" diff --git a/bin/varnishd/waiter/cache_waiter_kqueue.c b/bin/varnishd/waiter/cache_waiter_kqueue.c index 52633e2..8985c1a 100644 --- a/bin/varnishd/waiter/cache_waiter_kqueue.c +++ b/bin/varnishd/waiter/cache_waiter_kqueue.c @@ -39,7 +39,6 @@ #include #include -#include #include "cache/cache.h" From martin at varnish-software.com Tue Mar 3 14:34:19 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Tue, 03 Mar 2015 15:34:19 +0100 Subject: [master] 4b711ce Increase the sleep somewhat to make this test case more stable Message-ID: commit 4b711ce7eb57f899ebd534048d48c2edd09c02e4 Author: Martin Blix Grydeland Date: Tue Mar 3 15:33:57 2015 +0100 Increase the sleep somewhat to make this test case more stable diff --git a/bin/varnishtest/tests/r01030.vtc b/bin/varnishtest/tests/r01030.vtc index a84e3a5..302b918 100644 --- a/bin/varnishtest/tests/r01030.vtc +++ b/bin/varnishtest/tests/r01030.vtc @@ -42,7 +42,7 @@ client c1 { #delay 0.1 varnish v1 -expect bans_lurker_tests_tested == 0 -delay 1.0 +delay 1.5 varnish v1 -expect bans_lurker_tests_tested >= 1 varnish v1 -cliok "param.set ban_lurker_sleep 5.01" From phk at FreeBSD.org Tue Mar 3 15:18:17 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 03 Mar 2015 16:18:17 +0100 Subject: [master] 44ab551 More #include cleanups Message-ID: commit 44ab55141b4af1e5b518c38e4839b48dd0392b94 Author: Poul-Henning Kamp Date: Tue Mar 3 15:17:59 2015 +0000 More #include cleanups diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c index 39df537..821412c 100644 --- a/bin/varnishd/cache/cache_esi_deliver.c +++ b/bin/varnishd/cache/cache_esi_deliver.c @@ -31,7 +31,6 @@ #include "config.h" #include -#include #include "cache.h" #include "cache_filter.h" diff --git a/bin/varnishd/cache/cache_esi_parse.c b/bin/varnishd/cache/cache_esi_parse.c index b4beb75..53c46de 100644 --- a/bin/varnishd/cache/cache_esi_parse.c +++ b/bin/varnishd/cache/cache_esi_parse.c @@ -30,9 +30,6 @@ #include "config.h" -#include -#include - #include "cache.h" #include "cache_esi.h" diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c index e7a06de..5333c62 100644 --- a/bin/varnishd/cache/cache_fetch_proc.c +++ b/bin/varnishd/cache/cache_fetch_proc.c @@ -29,7 +29,6 @@ #include "config.h" -#include #include #include "cache.h" diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index bc88148..865a45a 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -35,7 +35,6 @@ #include #endif -#include #include // offsetof() #include #include diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c index 921d449..8d20c98 100644 --- a/bin/varnishd/cache/cache_req_body.c +++ b/bin/varnishd/cache/cache_req_body.c @@ -35,7 +35,6 @@ #include "cache.h" #include "cache_filter.h" #include "vtim.h" -#include "storage/storage.h" #include "hash/hash_slinger.h" /*---------------------------------------------------------------------- diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index 42f5230..b74c66b 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -38,9 +38,6 @@ #include "config.h" -#include -#include - #include "cache.h" #include "cache_director.h" diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c index 5fbf923..8f972f1 100644 --- a/bin/varnishd/cache/cache_vrt.c +++ b/bin/varnishd/cache/cache_vrt.c @@ -31,10 +31,6 @@ #include "config.h" - -#include -#include - #include "cache.h" #include "cache_director.h" diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c index a0a5185..9ece734 100644 --- a/bin/varnishd/cache/cache_vrt_priv.c +++ b/bin/varnishd/cache/cache_vrt_priv.c @@ -32,12 +32,10 @@ #include "config.h" -#include #include #include "cache.h" -#include "vcl.h" #include "vrt.h" struct vrt_priv { diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index cce45c6..a53c07a 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -30,9 +30,6 @@ */ #include "config.h" -#include -#include - #include "cache.h" #include "common/heritage.h" #include "hash/hash_slinger.h" From phk at FreeBSD.org Wed Mar 4 10:55:32 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 11:55:32 +0100 Subject: [master] 625e615 Split vapi/vsm_int.h into those (minor) bits which we have to reveal to vapi/vsm.h for it to work, and the truly private parts needed to implement things internally (vsm_priv.h) Message-ID: commit 625e61506820149c689ae4b8af0ebd447be7b77c Author: Poul-Henning Kamp Date: Wed Mar 4 10:54:03 2015 +0000 Split vapi/vsm_int.h into those (minor) bits which we have to reveal to vapi/vsm.h for it to work, and the truly private parts needed to implement things internally (vsm_priv.h) diff --git a/bin/varnishd/common/common_vsm.c b/bin/varnishd/common/common_vsm.c index 9d4863e..94c3e3c 100644 --- a/bin/varnishd/common/common_vsm.c +++ b/bin/varnishd/common/common_vsm.c @@ -42,7 +42,7 @@ #include "common.h" -#include "vapi/vsm_int.h" +#include "vsm_priv.h" #include "vmb.h" #include "vtim.h" diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c index 04634b8..837e165 100644 --- a/bin/varnishd/mgt/mgt_shmem.c +++ b/bin/varnishd/mgt/mgt_shmem.c @@ -45,7 +45,7 @@ #include "common/params.h" #include "flopen.h" -#include "vapi/vsm_int.h" +#include "vsm_priv.h" #include "vmb.h" #include "vfil.h" diff --git a/include/Makefile.am b/include/Makefile.am index bda6e37..ec6c2aa 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -79,6 +79,7 @@ nobase_noinst_HEADERS = \ vnum.h \ vpf.h \ vrnd.h \ + vsm_priv.h \ vsub.h \ vss.h \ vtcp.h \ diff --git a/include/vapi/vsm_int.h b/include/vapi/vsm_int.h index 11c40e4..4b84c44 100644 --- a/include/vapi/vsm_int.h +++ b/include/vapi/vsm_int.h @@ -26,71 +26,12 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * Define the layout of the shared memory log segment. + * Define the internal details which must be kept in sync between + * vsm_priv.h and vapi/vsm.h, and this file SHALL not be included + * from anywhere but those two files. * * NB: THIS IS NOT A PUBLIC API TO VARNISH! * - * There is a lot of diplomacy and protocol involved with the VSM segment - * since there is no way to (and no desire to!) lock between the readers - * and the writer. - * - * In particular we want the readers to seamlessly jump from one VSM instance - * to another when the child restarts. - * - * The VSM segment life-cycle is: - * - * Manager creates VSM file under temp name - * - * Temp VSM file is initialized such that VSM_head is consistent - * with a non-zero alloc_seq - * - * Manager renames Temp VSM file to correct filename as atomic - * operation. - * - * When manager abandons VSM file, alloc_seq is set to zero, which - * never happens in any other circumstances. - * - * If a manager is started and finds and old abandoned VSM segment - * it will zero the alloc_seq in it, before replacing the file. - * - * Subscribers will have to monitor three things to make sure they look at - * the right thing: The alloc_seq field, the age counter and the dev+inode - * of the path-name. The former check is by far the cheaper, the second - * can be used to check that Varnishd is still alive and the last check - * should only be employed when lack of activity in the VSM segment raises - * suspicion that something has happened. - * - * The allocations ("chunks") in the VSM forms a linked list, starting with - * VSM_head->first, with the first/next fields being byte offsets relative - * to the start of the VSM segment. - * - * The last chunk on the list, has next == 0. - * - * New chunks are appended to the list, no matter where in the VSM - * they happen to be allocated. - * - * Chunk allocation sequence is: - * Find free space - * Zero payload - * Init Chunk header - * Write memory barrier - * update hdr->first or $last->next pointer - * hdr->alloc_seq changes - * Write memory barrier - * - * Chunk contents should be designed so that zero bytes are not mistaken - * for valid contents. - * - * Chunk deallocation sequence is: - * update hdr->first or $prev->next pointer - * Write memory barrier - * this->len = 0 - * hdr->alloc_seq changes - * Write memory barrier - * - * The space occupied by the chunk is put on a cooling list and is not - * recycled for at least a minute. - * */ #ifndef VSM_INT_H_INCLUDED @@ -100,24 +41,4 @@ #define VSM_MARKER_LEN 8 #define VSM_IDENT_LEN 128 -struct VSM_chunk { -#define VSM_CHUNK_MARKER "VSMCHUNK" - char marker[VSM_MARKER_LEN]; - ssize_t len; /* Incl VSM_chunk */ - ssize_t next; /* Offset in shmem */ - char class[VSM_MARKER_LEN]; - char type[VSM_MARKER_LEN]; - char ident[VSM_IDENT_LEN]; -}; - -struct VSM_head { -#define VSM_HEAD_MARKER "VSMHEAD0" /* Incr. as version# */ - char marker[VSM_MARKER_LEN]; - ssize_t hdrsize; - ssize_t shm_size; - ssize_t first; /* Offset, first chunk */ - unsigned alloc_seq; - uint64_t age; -}; - #endif /* VSM_INT_H_INCLUDED */ diff --git a/include/vsm_priv.h b/include/vsm_priv.h new file mode 100644 index 0000000..0cc1a9f --- /dev/null +++ b/include/vsm_priv.h @@ -0,0 +1,121 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2014 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Define the layout of the shared memory log segment. + * + * NB: THIS IS NOT A PUBLIC API TO VARNISH! + * + * There is a lot of diplomacy and protocol involved with the VSM segment + * since there is no way to (and no desire to!) lock between the readers + * and the writer. + * + * In particular we want the readers to seamlessly jump from one VSM instance + * to another when the child restarts. + * + * The VSM segment life-cycle is: + * + * Manager creates VSM file under temp name + * + * Temp VSM file is initialized such that VSM_head is consistent + * with a non-zero alloc_seq + * + * Manager renames Temp VSM file to correct filename as atomic + * operation. + * + * When manager abandons VSM file, alloc_seq is set to zero, which + * never happens in any other circumstances. + * + * If a manager is started and finds and old abandoned VSM segment + * it will zero the alloc_seq in it, before replacing the file. + * + * Subscribers will have to monitor three things to make sure they look at + * the right thing: The alloc_seq field, the age counter and the dev+inode + * of the path-name. The former check is by far the cheaper, the second + * can be used to check that Varnishd is still alive and the last check + * should only be employed when lack of activity in the VSM segment raises + * suspicion that something has happened. + * + * The allocations ("chunks") in the VSM forms a linked list, starting with + * VSM_head->first, with the first/next fields being byte offsets relative + * to the start of the VSM segment. + * + * The last chunk on the list, has next == 0. + * + * New chunks are appended to the list, no matter where in the VSM + * they happen to be allocated. + * + * Chunk allocation sequence is: + * Find free space + * Zero payload + * Init Chunk header + * Write memory barrier + * update hdr->first or $last->next pointer + * hdr->alloc_seq changes + * Write memory barrier + * + * Chunk contents should be designed so that zero bytes are not mistaken + * for valid contents. + * + * Chunk deallocation sequence is: + * update hdr->first or $prev->next pointer + * Write memory barrier + * this->len = 0 + * hdr->alloc_seq changes + * Write memory barrier + * + * The space occupied by the chunk is put on a cooling list and is not + * recycled for at least a minute. + * + */ + +#ifndef VSM_PRIV_H_INCLUDED +#define VSM_PRIV_H_INCLUDED + +#include + +struct VSM_chunk { +#define VSM_CHUNK_MARKER "VSMCHUNK" + char marker[VSM_MARKER_LEN]; + ssize_t len; /* Incl VSM_chunk */ + ssize_t next; /* Offset in shmem */ + char class[VSM_MARKER_LEN]; + char type[VSM_MARKER_LEN]; + char ident[VSM_IDENT_LEN]; +}; + +struct VSM_head { +#define VSM_HEAD_MARKER "VSMHEAD0" /* Incr. as version# */ + char marker[VSM_MARKER_LEN]; + ssize_t hdrsize; + ssize_t shm_size; + ssize_t first; /* Offset, first chunk */ + unsigned alloc_seq; + uint64_t age; +}; + +#endif /* VSM_PRIV_H_INCLUDED */ diff --git a/lib/libvarnish/vin.c b/lib/libvarnish/vin.c index 4dba302..be5b0bd 100644 --- a/lib/libvarnish/vin.c +++ b/lib/libvarnish/vin.c @@ -37,7 +37,7 @@ #include #include -#include "vapi/vsm_int.h" +#include "vsm_priv.h" #include "vas.h" #include "vdef.h" #include "vin.h" diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c index 38dd5fb..6505704 100644 --- a/lib/libvarnishapi/vsc.c +++ b/lib/libvarnishapi/vsc.c @@ -44,7 +44,6 @@ #include "vapi/vsc.h" #include "vapi/vsm.h" -#include "vapi/vsm_int.h" #include "vqueue.h" #include "vsm_api.h" diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c index 949028f..92f65ac 100644 --- a/lib/libvarnishapi/vsl.c +++ b/lib/libvarnishapi/vsl.c @@ -47,7 +47,6 @@ #include "vapi/vsm.h" #include "vapi/vsl.h" -#include "vapi/vsm_int.h" #include "vbm.h" #include "vmb.h" #include "vre.h" diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index f05f184..2e4532e 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -47,7 +47,7 @@ #include "vas.h" #include "vapi/vsm.h" -#include "vapi/vsm_int.h" +#include "vsm_priv.h" #include "vtim.h" #include "vin.h" #include "vsb.h" From phk at FreeBSD.org Wed Mar 4 11:06:58 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 12:06:58 +0100 Subject: [master] 31a7949 Split truly private parts of vapi/vsl_int.h into vsl_priv.h Message-ID: commit 31a79493ab7c7a392509326127e81d3e29c13e48 Author: Poul-Henning Kamp Date: Wed Mar 4 11:02:50 2015 +0000 Split truly private parts of vapi/vsl_int.h into vsl_priv.h diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 9b408ac..8f58e00 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -38,7 +38,7 @@ #include "common/common.h" -#include "vapi/vsl_int.h" +#include "vsl_priv.h" #include diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c index d48f776..98c04aa 100644 --- a/bin/varnishd/cache/cache_shmlog.c +++ b/bin/varnishd/cache/cache_shmlog.c @@ -35,6 +35,7 @@ #include "cache.h" #include "common/heritage.h" +#include "vsl_priv.h" #include "vmb.h" #include "vtim.h" diff --git a/bin/varnishd/mgt/mgt_param_bits.c b/bin/varnishd/mgt/mgt_param_bits.c index 32a4593..627c7a9 100644 --- a/bin/varnishd/mgt/mgt_param_bits.c +++ b/bin/varnishd/mgt/mgt_param_bits.c @@ -39,7 +39,7 @@ #include "vav.h" -#include "vapi/vsl_int.h" +#include "vsl_priv.h" /*-------------------------------------------------------------------- */ diff --git a/include/Makefile.am b/include/Makefile.am index ec6c2aa..603a085 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -79,6 +79,7 @@ nobase_noinst_HEADERS = \ vnum.h \ vpf.h \ vrnd.h \ + vsl_priv.h \ vsm_priv.h \ vsub.h \ vss.h \ diff --git a/include/vapi/vsl_int.h b/include/vapi/vsl_int.h index 30692ba..a694341 100644 --- a/include/vapi/vsl_int.h +++ b/include/vapi/vsl_int.h @@ -27,15 +27,16 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * Define the layout of the shared memory log segment. + * Define the layout of the shared memory log segment, which must be kept + * in sync between vsl_priv.h and vapi/vsl.h. + * + * This file SHALL not be included from anywhere but those two files. * * NB: THIS IS NOT A PUBLIC API TO VARNISH! */ -#ifndef VAPI_VSL_FMT_H_INCLUDED -#define VAPI_VSL_FMT_H_INCLUDED - -#include "vapi/vsm_int.h" +#ifndef VAPI_VSL_INT_H_INCLUDED +#define VAPI_VSL_INT_H_INCLUDED #define VSL_CLASS "Log" #define VSL_SEGMENTS 8 @@ -43,17 +44,6 @@ /* * Shared memory log format * - * The segments array has index values providing safe entry points into - * the log, where each element N gives the index of the first log record - * in the Nth fraction of the log. An index value of -1 indicated that no - * log records in this fraction exists. - * - * The segment member shows the current segment where Varnish is currently - * appending log data. - * - * The seq member contains a non-zero seq number randomly initialized, - * which increases whenever writing the log starts from the front. - * * The log member points to an array of 32bit unsigned integers containing * log records. * @@ -69,15 +59,6 @@ * changing corresponding magic numbers in varnishd/cache/cache_shmlog.c */ -struct VSL_head { -#define VSL_HEAD_MARKER "VSLHEAD0" /* Incr. as version# */ - char marker[VSM_MARKER_LEN]; - volatile ssize_t segments[VSL_SEGMENTS]; - volatile unsigned segment; /* Current varnishd segment */ - volatile unsigned seq; /* Non-zero seq number */ - uint32_t log[]; -}; - #define VSL_CLIENTMARKER (1U<<30) #define VSL_BACKENDMARKER (1U<<31) #define VSL_IDENTMASK (~(3U<<30)) @@ -118,4 +99,4 @@ enum VSL_tag_e { #define SLT_F_UNUSED (1 << 0) #define SLT_F_BINARY (1 << 1) -#endif /* VAPI_VSL_FMT_H_INCLUDED */ +#endif /* VAPI_VSL_INT_H_INCLUDED */ diff --git a/include/vsl_priv.h b/include/vsl_priv.h new file mode 100644 index 0000000..d5643ed --- /dev/null +++ b/include/vsl_priv.h @@ -0,0 +1,71 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2014 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * Author: Martin Blix Grydeland + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Define the layout of the shared memory log segment. + * + * NB: THIS IS NOT A PUBLIC API TO VARNISH! + */ + +#ifndef VSL_PRIV_H_INCLUDED +#define VSL_PRIV_H_INCLUDED + +#include "vapi/vsl_int.h" +#include "vapi/vsm_int.h" + +#define VSL_CLASS "Log" +#define VSL_SEGMENTS 8 + +/* + * Shared memory log format + * + * The segments array has index values providing safe entry points into + * the log, where each element N gives the index of the first log record + * in the Nth fraction of the log. An index value of -1 indicated that no + * log records in this fraction exists. + * + * The segment member shows the current segment where Varnish is currently + * appending log data. + * + * The seq member contains a non-zero seq number randomly initialized, + * which increases whenever writing the log starts from the front. + * + * The format of the actual log is in vapi/vsl_int.h + * + */ + +struct VSL_head { +#define VSL_HEAD_MARKER "VSLHEAD0" /* Incr. as version# */ + char marker[VSM_MARKER_LEN]; + volatile ssize_t segments[VSL_SEGMENTS]; + volatile unsigned segment; /* Current varnishd segment */ + volatile unsigned seq; /* Non-zero seq number */ + uint32_t log[]; +}; + +#endif /* VSL_PRIV_H_INCLUDED */ diff --git a/lib/libvarnishapi/vsl_cursor.c b/lib/libvarnishapi/vsl_cursor.c index 7dcd7d5..22d68bf 100644 --- a/lib/libvarnishapi/vsl_cursor.c +++ b/lib/libvarnishapi/vsl_cursor.c @@ -41,9 +41,9 @@ #include "vas.h" #include "miniobj.h" -#include "vapi/vsm.h" #include "vsm_api.h" #include "vapi/vsl.h" +#include "vsl_priv.h" #include "vsl_api.h" struct vslc_vsm { From nils.goroll at uplex.de Wed Mar 4 11:22:09 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 04 Mar 2015 12:22:09 +0100 Subject: [master] 24f0f02 cast to %j type Message-ID: commit 24f0f02d6723affb15274bff0a215510060eb7ba Author: Nils Goroll Date: Wed Mar 4 11:40:38 2015 +0100 cast to %j type diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c index a71ef4a..652af2f 100644 --- a/bin/varnishd/cache/cache_gzip.c +++ b/bin/varnishd/cache/cache_gzip.c @@ -300,7 +300,7 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv, /* XXX: Zero is suspect: OA_GZIPBITS wasn't set */ if (u != 0) http_PrintfHeader(req->resp, - "Content-Length: %ju", u); + "Content-Length: %ju", (uintmax_t)u); } http_Unset(req->resp, H_Content_Encoding); return (0); From nils.goroll at uplex.de Wed Mar 4 12:27:27 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 04 Mar 2015 13:27:27 +0100 Subject: [master] 1996c83 vmods shouldn't require vsl_priv.h Message-ID: commit 1996c83a6fcdafbf6c2c41467c3206a240bb3cd6 Author: Nils Goroll Date: Wed Mar 4 13:27:14 2015 +0100 vmods shouldn't require vsl_priv.h diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 8f58e00..0e0ac6a 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -38,7 +38,8 @@ #include "common/common.h" -#include "vsl_priv.h" +#include "vapi/vsl_int.h" +#include "vapi/vsm_int.h" #include From phk at FreeBSD.org Wed Mar 4 12:32:55 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 13:32:55 +0100 Subject: [master] 47f8778 Remove unnecessary #include Message-ID: commit 47f8778f567759e431570f970ef311d889639f8b Author: Poul-Henning Kamp Date: Wed Mar 4 12:13:15 2015 +0000 Remove unnecessary #include diff --git a/include/vsb.h b/include/vsb.h index 0f1f2bd..b99e471 100644 --- a/include/vsb.h +++ b/include/vsb.h @@ -31,8 +31,6 @@ #ifndef VSB_H_INCLUDED #define VSB_H_INCLUDED -#include "vdef.h" - /* * Structure definition */ From phk at FreeBSD.org Wed Mar 4 12:32:55 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 13:32:55 +0100 Subject: [master] 7ec7248 Update comment to reflect slightly more complex reality for this file. Message-ID: commit 7ec7248229e8ad0304954329fd8a2372bb8057a3 Author: Poul-Henning Kamp Date: Wed Mar 4 12:32:23 2015 +0000 Update comment to reflect slightly more complex reality for this file. diff --git a/include/vapi/vsl_int.h b/include/vapi/vsl_int.h index a694341..e3046b2 100644 --- a/include/vapi/vsl_int.h +++ b/include/vapi/vsl_int.h @@ -27,12 +27,13 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * Define the layout of the shared memory log segment, which must be kept - * in sync between vsl_priv.h and vapi/vsl.h. + * Define the layout of the shared memory log segment. * - * This file SHALL not be included from anywhere but those two files. + * This file SHALL only be included from: + * bin/varnishd/cache/cache.h + * include/vsl_priv.h + * include/vapi/vsl.h * - * NB: THIS IS NOT A PUBLIC API TO VARNISH! */ #ifndef VAPI_VSL_INT_H_INCLUDED From phk at FreeBSD.org Wed Mar 4 12:44:38 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 13:44:38 +0100 Subject: [master] 2b1fc34 Don't include vsm.h just to get name of a struct. Message-ID: commit 2b1fc3449dd4d04cd6f73383fea47803ee90959e Author: Poul-Henning Kamp Date: Wed Mar 4 12:36:26 2015 +0000 Don't include vsm.h just to get name of a struct. diff --git a/include/vapi/vsl.h b/include/vapi/vsl.h index a4f1b27..8d5a2ef 100644 --- a/include/vapi/vsl.h +++ b/include/vapi/vsl.h @@ -36,9 +36,10 @@ #include -#include "vapi/vsm.h" #include "vapi/vsl_int.h" +struct VSM_data; + /* * enum VSL_tag_e enumerates the SHM log tags, where the identifiers are * "SLT_" + XML tag, as defined in tbl/vsl_tags.h. Use the macro SLT__MAX From phk at FreeBSD.org Wed Mar 4 12:44:38 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 13:44:38 +0100 Subject: [master] 8436dcf Remove unused #includes Message-ID: commit 8436dcffe007eadec29799fc63416603be129386 Author: Poul-Henning Kamp Date: Wed Mar 4 12:42:44 2015 +0000 Remove unused #includes diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c index cbf11d6..de1aa01 100644 --- a/bin/varnishtest/vtc_logexp.c +++ b/bin/varnishtest/vtc_logexp.c @@ -56,8 +56,6 @@ #include "vapi/vsm.h" #include "vapi/vsl.h" #include "vtim.h" -#include "vqueue.h" -#include "vas.h" #include "vre.h" #include "vtc.h" From phk at FreeBSD.org Wed Mar 4 12:44:38 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 13:44:38 +0100 Subject: [master] 6577473 include vdef.h here Message-ID: commit 6577473f7d983c3030e7333813e26d91a2a012fa Author: Poul-Henning Kamp Date: Wed Mar 4 12:44:14 2015 +0000 include vdef.h here diff --git a/lib/libvarnish/vsub.c b/lib/libvarnish/vsub.c index 767ec5a..71c9670 100644 --- a/lib/libvarnish/vsub.c +++ b/lib/libvarnish/vsub.c @@ -40,6 +40,7 @@ #include #include "vas.h" +#include "vdef.h" #include "vlu.h" #include "vsb.h" #include "vsub.h" From phk at FreeBSD.org Wed Mar 4 13:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 14:02:48 +0100 Subject: [master] 282d8fb Move vdef.h includes up to toplevel in all cases Message-ID: commit 282d8fbfb928f7d52d30a2d4542c763381c8551c Author: Poul-Henning Kamp Date: Wed Mar 4 12:56:28 2015 +0000 Move vdef.h includes up to toplevel in all cases diff --git a/bin/varnishlog/varnishlog.c b/bin/varnishlog/varnishlog.c index d73e45d..68a8f33 100644 --- a/bin/varnishlog/varnishlog.c +++ b/bin/varnishlog/varnishlog.c @@ -44,6 +44,7 @@ #include "vapi/vsl.h" #include "vapi/voptget.h" #include "vas.h" +#include "vdef.h" #include "vpf.h" #include "vsb.h" #include "vut.h" diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c index ce425eb..4549539 100644 --- a/bin/varnishncsa/varnishncsa.c +++ b/bin/varnishncsa/varnishncsa.c @@ -57,6 +57,7 @@ #include "vapi/vsl.h" #include "vapi/voptget.h" #include "vas.h" +#include "vdef.h" #include "vcs.h" #include "vnum.h" #include "vsb.h" diff --git a/bin/varnishtop/varnishtop.c b/bin/varnishtop/varnishtop.c index 15835cb..f9aaf47 100644 --- a/bin/varnishtop/varnishtop.c +++ b/bin/varnishtop/varnishtop.c @@ -49,6 +49,7 @@ #include "vapi/vsl.h" #include "vapi/voptget.h" #include "vas.h" +#include "vdef.h" #include "vcs.h" #include "vtree.h" #include "vsb.h" diff --git a/lib/libvarnish/vsb.c b/lib/libvarnish/vsb.c index 375a678..1332844 100644 --- a/lib/libvarnish/vsb.c +++ b/lib/libvarnish/vsb.c @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD: head/sys/kern/subr_vsb.c 222004 2011-05-17 06:36:32Z phk $") #include #include +#include "vdef.h" #include "vas.h" #include "vsb.h" diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c index a271561..71c8aa4 100644 --- a/lib/libvarnishapi/vsl_query.c +++ b/lib/libvarnishapi/vsl_query.c @@ -38,6 +38,7 @@ #include "miniobj.h" #include "vas.h" +#include "vdef.h" #include "vbm.h" #include "vnum.h" #include "vre.h" diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index 2e4532e..ebc742e 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -45,6 +45,7 @@ #include "miniobj.h" #include "vas.h" +#include "vdef.h" #include "vapi/vsm.h" #include "vsm_priv.h" diff --git a/lib/libvarnishapi/vxp.c b/lib/libvarnishapi/vxp.c index c16de97..bac2c3d 100644 --- a/lib/libvarnishapi/vxp.c +++ b/lib/libvarnishapi/vxp.c @@ -36,9 +36,10 @@ #include #include -#include "vsb.h" #include "vas.h" +#include "vdef.h" #include "miniobj.h" +#include "vsb.h" #include "vxp.h" diff --git a/lib/libvarnishapi/vxp_lexer.c b/lib/libvarnishapi/vxp_lexer.c index cb2bff9..8f6ef99 100644 --- a/lib/libvarnishapi/vxp_lexer.c +++ b/lib/libvarnishapi/vxp_lexer.c @@ -36,6 +36,7 @@ #include #include +#include "vdef.h" #include "vsb.h" #include "vas.h" diff --git a/lib/libvarnishapi/vxp_parse.c b/lib/libvarnishapi/vxp_parse.c index 13472a2..8e9632d 100644 --- a/lib/libvarnishapi/vxp_parse.c +++ b/lib/libvarnishapi/vxp_parse.c @@ -40,6 +40,7 @@ #include "miniobj.h" #include "vas.h" +#include "vdef.h" #include "vbm.h" #include "vnum.h" #include "vsb.h" From phk at FreeBSD.org Wed Mar 4 13:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 14:02:48 +0100 Subject: [master] 9ba0565 Rename __printflike to __v_printflike to make sure we have control over it with vdef.h. Message-ID: commit 9ba0565ee374a001bc2450827281880cc5cea4af Author: Poul-Henning Kamp Date: Wed Mar 4 13:02:06 2015 +0000 Rename __printflike to __v_printflike to make sure we have control over it with vdef.h. Confine __unused to include/vtree.h at the same time. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 0e0ac6a..46b410b 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -848,7 +848,7 @@ void HTTP_Encode(const struct http *fm, uint8_t *, unsigned len, unsigned how); int HTTP_Decode(struct http *to, const uint8_t *fm); void http_ForceHeader(struct http *to, const char *hdr, const char *val); void http_PrintfHeader(struct http *to, const char *fmt, ...) - __printflike(2, 3); + __v_printflike(2, 3); void http_TimeHeader(struct http *to, const char *fmt, double now); void http_SetHeader(struct http *to, const char *hdr); void http_SetH(const struct http *to, unsigned n, const char *fm); @@ -1029,10 +1029,10 @@ void VSL_End(struct vsl_log *vsl); void VSM_Free(void *ptr); #ifdef VSL_ENDMARKER void VSL(enum VSL_tag_e tag, uint32_t vxid, const char *fmt, ...) - __printflike(3, 4); + __v_printflike(3, 4); void VSLbv(struct vsl_log *, enum VSL_tag_e tag, const char *fmt, va_list va); void VSLb(struct vsl_log *, enum VSL_tag_e tag, const char *fmt, ...) - __printflike(3, 4); + __v_printflike(3, 4); void VSLbt(struct vsl_log *, enum VSL_tag_e tag, txt t); void VSLb_ts(struct vsl_log *, const char *event, double first, double *pprev, double now); @@ -1120,7 +1120,7 @@ void *WS_Alloc(struct ws *ws, unsigned bytes); void *WS_Copy(struct ws *ws, const void *str, int len); char *WS_Snapshot(struct ws *ws); int WS_Overflowed(const struct ws *ws); -void *WS_Printf(struct ws *ws, const char *fmt, ...) __printflike(2, 3); +void *WS_Printf(struct ws *ws, const char *fmt, ...) __v_printflike(2, 3); /* cache_rfc2616.c */ void RFC2616_Ttl(struct busyobj *, double now); diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h index e6d9274..bbc3f8e 100644 --- a/bin/varnishd/cache/cache_filter.h +++ b/bin/varnishd/cache/cache_filter.h @@ -80,7 +80,7 @@ int VFP_Open(struct vfp_ctx *bo); void VFP_Close(struct vfp_ctx *bo); enum vfp_status VFP_Suck(struct vfp_ctx *, void *p, ssize_t *lp); enum vfp_status VFP_Error(struct vfp_ctx *, const char *fmt, ...) - __printflike(2, 3); + __v_printflike(2, 3); /* cache_fetch_proc.c */ enum vfp_status VFP_GetStorage(struct vfp_ctx *, ssize_t *sz, uint8_t **ptr); diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index dc28a00..7d734ee 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -54,7 +54,7 @@ typedef void mgt_cli_close_f(void *priv); void mgt_cli_setup(int fdi, int fdo, int verbose, const char *ident, mgt_cli_close_f *close_func, void *priv); int mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...) - __printflike(3, 4); + __v_printflike(3, 4); void mgt_cli_start_child(int fdi, int fdo); void mgt_cli_stop_child(void); void mgt_cli_telnet(const char *T_arg); diff --git a/bin/varnishreplay/varnishreplay.c b/bin/varnishreplay/varnishreplay.c index 7fc24fe..4f7a2e9 100644 --- a/bin/varnishreplay/varnishreplay.c +++ b/bin/varnishreplay/varnishreplay.c @@ -172,7 +172,7 @@ static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; static void thread_log(int lvl, int errcode, const char *fmt, ...) - __printflike(3, 4); + __v_printflike(3, 4); static void thread_log(int lvl, int errcode, const char *fmt, ...) diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h index b877e26..d43a188 100644 --- a/bin/varnishtest/vtc.h +++ b/bin/varnishtest/vtc.h @@ -81,7 +81,7 @@ void vtc_loginit(char *buf, unsigned buflen); struct vtclog *vtc_logopen(const char *id); void vtc_logclose(struct vtclog *vl); void vtc_log(struct vtclog *vl, int lvl, const char *fmt, ...) - __printflike(3, 4); + __v_printflike(3, 4); void vtc_dump(struct vtclog *vl, int lvl, const char *pfx, const char *str, int len); void vtc_hexdump(struct vtclog *vl, int lvl, const char *pfx, @@ -93,8 +93,8 @@ int exec_file(const char *fn, const char *script, const char *tmpdir, void macro_undef(struct vtclog *vl, const char *instance, const char *name); void macro_def(struct vtclog *vl, const char *instance, const char *name, const char *fmt, ...) - __printflike(4, 5); + __v_printflike(4, 5); struct vsb *macro_expand(struct vtclog *vl, const char *text); void extmacro_def(const char *name, const char *fmt, ...) - __printflike(2, 3); + __v_printflike(2, 3); diff --git a/include/vcli_priv.h b/include/vcli_priv.h index 0129b83..2f98d7d 100644 --- a/include/vcli_priv.h +++ b/include/vcli_priv.h @@ -54,6 +54,6 @@ struct cli_proto { /* The implementation must provide these functions */ int VCLI_Overflow(struct cli *cli); void VCLI_Out(struct cli *cli, const char *fmt, ...) - __printflike(2, 3); + __v_printflike(2, 3); void VCLI_Quote(struct cli *cli, const char *str); void VCLI_SetResult(struct cli *cli, unsigned r); diff --git a/include/vdef.h b/include/vdef.h index 5845e2d..5d52ddb 100644 --- a/include/vdef.h +++ b/include/vdef.h @@ -59,20 +59,12 @@ # endif #endif -#ifndef __printflike -# if __GNUC_PREREQ(2, 95) || defined(__INTEL_COMPILER) -# define __printflike(f,a) __attribute__((format(printf, f, a))) -# else -# define __printflike(f,a) -# endif -#endif - -#ifndef __unused -# if __GNUC_PREREQ(2, 95) || defined(__INTEL_COMPILER) -# define __unused __attribute__((__unused__)) -# else -# define __unused -# endif +#ifdef __printflike +# define __v_printflike(f,a) __printflike(f,a) +#elif __GNUC_PREREQ(2, 95) || defined(__INTEL_COMPILER) +# define __v_printflike(f,a) __attribute__((format(printf, f, a))) +#else +# define __v_printflike(f,a) #endif /********************************************************************** diff --git a/include/vsb.h b/include/vsb.h index b99e471..4b0099f 100644 --- a/include/vsb.h +++ b/include/vsb.h @@ -63,10 +63,10 @@ void VSB_clear(struct vsb *); int VSB_bcat(struct vsb *, const void *, size_t); int VSB_cat(struct vsb *, const char *); int VSB_printf(struct vsb *, const char *, ...) - __printflike(2, 3); + __v_printflike(2, 3); #ifdef va_start int VSB_vprintf(struct vsb *, const char *, va_list) - __printflike(2, 0); + __v_printflike(2, 0); #endif int VSB_putc(struct vsb *, int); int VSB_error(const struct vsb *); diff --git a/include/vtree.h b/include/vtree.h index d251d62..04f551d 100644 --- a/include/vtree.h +++ b/include/vtree.h @@ -30,6 +30,10 @@ #ifndef _VTREE_H_ #define _VTREE_H_ +#ifndef __unused +define __unused __attribute__((__unused__)) +#endif + /* * This file defines data structures for different types of trees: * splay trees and red-black trees. diff --git a/include/vut.h b/include/vut.h index 0dc7482..bd093d1 100644 --- a/include/vut.h +++ b/include/vut.h @@ -65,7 +65,7 @@ struct VUT { extern struct VUT VUT; void VUT_Error(int status, const char *fmt, ...) - __printflike(2, 3); + __v_printflike(2, 3); int VUT_g_Arg(const char *arg); diff --git a/lib/libvarnishapi/vsl_api.h b/lib/libvarnishapi/vsl_api.h index 6dacff3..f3bd213 100644 --- a/lib/libvarnishapi/vsl_api.h +++ b/lib/libvarnishapi/vsl_api.h @@ -38,7 +38,7 @@ /*lint -esym(534, vsl_diag) */ int vsl_diag(struct VSL_data *vsl, const char *fmt, ...) - __printflike(2, 3); + __v_printflike(2, 3); void vsl_vbm_bitset(int bit, void *priv); void vsl_vbm_bitclr(int bit, void *priv); diff --git a/lib/libvarnishapi/vsm_api.h b/lib/libvarnishapi/vsm_api.h index 1d73773..ce4f954 100644 --- a/lib/libvarnishapi/vsm_api.h +++ b/lib/libvarnishapi/vsm_api.h @@ -57,5 +57,5 @@ struct VSM_data { }; int vsm_diag(struct VSM_data *vd, const char *fmt, ...) - __printflike(2, 3); + __v_printflike(2, 3); void VSC_Delete(struct VSM_data *vd); diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index 9bc102c..42f8c5c 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -256,11 +256,11 @@ struct inifin *New_IniFin(struct vcc *tl); * F -> Finish function */ void Fh(const struct vcc *tl, int indent, const char *fmt, ...) - __printflike(3, 4); + __v_printflike(3, 4); void Fc(const struct vcc *tl, int indent, const char *fmt, ...) - __printflike(3, 4); + __v_printflike(3, 4); void Fb(const struct vcc *tl, int indent, const char *fmt, ...) - __printflike(3, 4); + __v_printflike(3, 4); void EncToken(struct vsb *sb, const struct token *t); int IsMethod(const struct token *t); void *TlAlloc(struct vcc *tl, unsigned len); diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 7649e3e..957d017 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -247,7 +247,7 @@ vcc_new_expr(void) static struct expr * vcc_mk_expr(enum var_type fmt, const char *str, ...) - __printflike(2, 3); + __v_printflike(2, 3); static struct expr * vcc_mk_expr(enum var_type fmt, const char *str, ...) From phk at FreeBSD.org Wed Mar 4 13:08:39 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 14:08:39 +0100 Subject: [master] 84de64d typo Message-ID: commit 84de64d5e4b463536957dc046f752da62a9b4180 Author: Poul-Henning Kamp Date: Wed Mar 4 13:08:31 2015 +0000 typo diff --git a/include/vtree.h b/include/vtree.h index 04f551d..b88d9d2 100644 --- a/include/vtree.h +++ b/include/vtree.h @@ -31,7 +31,7 @@ #define _VTREE_H_ #ifndef __unused -define __unused __attribute__((__unused__)) +#define __unused __attribute__((__unused__)) #endif /* From nils.goroll at uplex.de Wed Mar 4 13:39:26 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 04 Mar 2015 14:39:26 +0100 Subject: [master] a7be4ff straighten VRB_Cache / VRT_CacheReqBody corner cases, improve test Message-ID: commit a7be4ff8d790c52402e3e98efec1154a4b9ae1b6 Author: Nils Goroll Date: Wed Mar 4 13:39:13 2015 +0100 straighten VRB_Cache / VRT_CacheReqBody corner cases, improve test - As VRB_Cache returns -1 upon error, so should VRT_CacheReqBody - 0 is a valid body size, so it shouldn't be used for signalling errors - VRB_Cache should return number of bytes when already cached - VRB_Cache: return -1 on insufficient bytes also diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c index 8d20c98..5c8f08c 100644 --- a/bin/varnishd/cache/cache_req_body.c +++ b/bin/varnishd/cache/cache_req_body.c @@ -199,7 +199,7 @@ VRB_Cache(struct req *req, ssize_t maxsize) assert (req->req_step == R_STP_RECV); switch(req->req_body_status) { case REQ_BODY_CACHED: - return (0); + return (req->req_bodybytes); case REQ_BODY_FAIL: return (-1); case REQ_BODY_NONE: @@ -279,5 +279,5 @@ VRB_Cache(struct req *req, ssize_t maxsize) req->req_body_status = REQ_BODY_FAIL; } VSLb_ts_req(req, "ReqBody", VTIM_real()); - return (vfps == VFP_END ? req->req_bodybytes : 0); + return (vfps == VFP_END ? req->req_bodybytes : -1); } diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c index 8f972f1..6148b2b 100644 --- a/bin/varnishd/cache/cache_vrt.c +++ b/bin/varnishd/cache/cache_vrt.c @@ -486,7 +486,7 @@ VRT_CacheReqBody(VRT_CTX, long long maxsize) if (ctx->method != VCL_MET_RECV) { VSLb(ctx->vsl, SLT_VCL_Error, "req.body can only be cached in vcl_recv{}"); - return (0); + return (-1); } return (VRB_Cache(ctx->req, maxsize)); } diff --git a/bin/varnishtest/tests/c00055.vtc b/bin/varnishtest/tests/c00055.vtc index ebac77e..5f525d0 100644 --- a/bin/varnishtest/tests/c00055.vtc +++ b/bin/varnishtest/tests/c00055.vtc @@ -10,20 +10,35 @@ server s1 { txresp -status 200 -hdr "Foo: Foo" -body "56" } -start -varnish v1 -vcl+backend { +varnish v1 -cliok "param.set vcc_allow_inline_c true" -vcl+backend { import ${vmod_std}; sub vcl_recv { std.cache_req_body(1KB); + C{ + const struct gethdr_s HDR_REQ_X_BodyBytes = + { HDR_REQ, "\014X-BodyBytes:"}; + VRT_SetHdr(ctx, &HDR_REQ_X_BodyBytes, + VRT_INT_string(ctx, VRT_CacheReqBody(ctx, 1024)), + vrt_magic_string_end); + }C return (pass); } sub vcl_deliver { if (resp.http.foo == "BAR") { return (restart); } + set resp.http.X-BodyBytes = req.http.X-BodyBytes; } } -start +# check log for the aborted POST +logexpect l1 -v v1 { + expect * 1006 Begin + expect * = FetchError "^straight insufficient bytes" + expect * = ReqHeader "^X-BodyBytes: -1" +} -start + varnish v1 -cliok "param.set debug +syncvsl" client c1 { @@ -31,6 +46,7 @@ client c1 { rxresp expect resp.http.Foo == "Foo" expect resp.bodylen == 2 + expect resp.http.X-BodyBytes == 3 } -run delay .1 @@ -51,4 +67,7 @@ client c1 { txreq -url "/is_varnish_still_running" rxresp expect resp.status == 200 + expect resp.http.X-BodyBytes == 0 } -run +varnish v1 -stop +logexpect l1 -wait From phk at FreeBSD.org Wed Mar 4 13:48:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 14:48:35 +0100 Subject: [master] 85bd7f3 Untangle nested includes Message-ID: commit 85bd7f37488b5aa624ab8ab7cdd8e41d217818db Author: Poul-Henning Kamp Date: Wed Mar 4 13:23:21 2015 +0000 Untangle nested includes diff --git a/bin/varnishd/cache/cache_vrt_re.c b/bin/varnishd/cache/cache_vrt_re.c index 15b11a5..d96c4f4 100644 --- a/bin/varnishd/cache/cache_vrt_re.c +++ b/bin/varnishd/cache/cache_vrt_re.c @@ -35,7 +35,6 @@ #include "cache.h" -#include "vre.h" #include "vrt.h" static void diff --git a/lib/libvarnishapi/generate.py b/lib/libvarnishapi/generate.py index 82f7c59..28aa8ae 100755 --- a/lib/libvarnishapi/generate.py +++ b/lib/libvarnishapi/generate.py @@ -190,6 +190,9 @@ fo.write(""" #include #include +#include "vqueue.h" +#include "vre.h" + #include "vxp.h" """) diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c index 92f65ac..5e12f0f 100644 --- a/lib/libvarnishapi/vsl.c +++ b/lib/libvarnishapi/vsl.c @@ -49,7 +49,6 @@ #include "vapi/vsl.h" #include "vbm.h" #include "vmb.h" -#include "vre.h" #include "vsb.h" #include "vsl_api.h" #include "vsm_api.h" diff --git a/lib/libvarnishapi/vsl_arg.c b/lib/libvarnishapi/vsl_arg.c index 4a9b897..a37a8ce 100644 --- a/lib/libvarnishapi/vsl_arg.c +++ b/lib/libvarnishapi/vsl_arg.c @@ -51,7 +51,6 @@ #include "vapi/vsm.h" #include "vbm.h" #include "vnum.h" -#include "vre.h" #include "vsl_api.h" #include "vsm_api.h" diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c index 71c8aa4..7b4d279 100644 --- a/lib/libvarnishapi/vsl_query.c +++ b/lib/libvarnishapi/vsl_query.c @@ -41,7 +41,6 @@ #include "vdef.h" #include "vbm.h" #include "vnum.h" -#include "vre.h" #include "vsb.h" #include "vapi/vsl.h" diff --git a/lib/libvarnishapi/vxp.c b/lib/libvarnishapi/vxp.c index bac2c3d..e877cae 100644 --- a/lib/libvarnishapi/vxp.c +++ b/lib/libvarnishapi/vxp.c @@ -39,6 +39,8 @@ #include "vas.h" #include "vdef.h" #include "miniobj.h" +#include "vqueue.h" +#include "vre.h" #include "vsb.h" #include "vxp.h" diff --git a/lib/libvarnishapi/vxp.h b/lib/libvarnishapi/vxp.h index eb21031..0589775 100644 --- a/lib/libvarnishapi/vxp.h +++ b/lib/libvarnishapi/vxp.h @@ -28,11 +28,6 @@ * */ -#include - -#include "vqueue.h" -#include "vre.h" - #include "vxp_tokens.h" #define isword(c) (isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-' || \ diff --git a/lib/libvarnishapi/vxp_lexer.c b/lib/libvarnishapi/vxp_lexer.c index 8f6ef99..59e6869 100644 --- a/lib/libvarnishapi/vxp_lexer.c +++ b/lib/libvarnishapi/vxp_lexer.c @@ -39,6 +39,8 @@ #include "vdef.h" #include "vsb.h" #include "vas.h" +#include "vqueue.h" +#include "vre.h" #include "vxp.h" From phk at FreeBSD.org Wed Mar 4 13:48:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 14:48:35 +0100 Subject: [master] c4e830a More #include untangling Message-ID: commit c4e830a07f7cc92fb86e037668ee40e4a93193b9 Author: Poul-Henning Kamp Date: Wed Mar 4 13:42:20 2015 +0000 More #include untangling diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c index 6505704..db721fe 100644 --- a/lib/libvarnishapi/vsc.c +++ b/lib/libvarnishapi/vsc.c @@ -33,18 +33,20 @@ #include #include -#include #include #include +#include #include #include -#include "miniobj.h" +#include "vdef.h" #include "vas.h" +#include "miniobj.h" +#include "vqueue.h" #include "vapi/vsc.h" #include "vapi/vsm.h" -#include "vqueue.h" + #include "vsm_api.h" enum { diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c index 5e12f0f..8bd6033 100644 --- a/lib/libvarnishapi/vsl.c +++ b/lib/libvarnishapi/vsl.c @@ -41,15 +41,19 @@ #include #include -#include "miniobj.h" -#include "vas.h" #include "vdef.h" +#include "vas.h" +#include "miniobj.h" -#include "vapi/vsm.h" -#include "vapi/vsl.h" #include "vbm.h" #include "vmb.h" +#include "vqueue.h" +#include "vre.h" #include "vsb.h" + +#include "vapi/vsm.h" +#include "vapi/vsl.h" + #include "vsl_api.h" #include "vsm_api.h" diff --git a/lib/libvarnishapi/vsl2rst.c b/lib/libvarnishapi/vsl2rst.c index c049fab..f443a91 100644 --- a/lib/libvarnishapi/vsl2rst.c +++ b/lib/libvarnishapi/vsl2rst.c @@ -29,8 +29,8 @@ #include "config.h" -#include #include +#include #include #include diff --git a/lib/libvarnishapi/vsl_api.h b/lib/libvarnishapi/vsl_api.h index f3bd213..584bc8c 100644 --- a/lib/libvarnishapi/vsl_api.h +++ b/lib/libvarnishapi/vsl_api.h @@ -29,11 +29,6 @@ * */ -#include "vdef.h" -#include "vqueue.h" -#include "vre.h" -#include "vapi/vsm.h" - #define VSL_FILE_ID "VSL" /*lint -esym(534, vsl_diag) */ diff --git a/lib/libvarnishapi/vsl_arg.c b/lib/libvarnishapi/vsl_arg.c index a37a8ce..229d9fc 100644 --- a/lib/libvarnishapi/vsl_arg.c +++ b/lib/libvarnishapi/vsl_arg.c @@ -36,21 +36,26 @@ #include #include #include +#include #include #include #include #include #include #include -#include -#include "miniobj.h" +#include "vdef.h" #include "vas.h" +#include "miniobj.h" -#include "vapi/vsl.h" -#include "vapi/vsm.h" #include "vbm.h" #include "vnum.h" +#include "vqueue.h" +#include "vre.h" + +#include "vapi/vsl.h" +#include "vapi/vsm.h" + #include "vsl_api.h" #include "vsm_api.h" diff --git a/lib/libvarnishapi/vsl_cursor.c b/lib/libvarnishapi/vsl_cursor.c index 22d68bf..ba6e7d2 100644 --- a/lib/libvarnishapi/vsl_cursor.c +++ b/lib/libvarnishapi/vsl_cursor.c @@ -29,22 +29,29 @@ * */ -#include +#include +#include #include #include -#include +#include #include -#include -#include #include -#include +#include +#include +#include "vdef.h" #include "vas.h" #include "miniobj.h" -#include "vsm_api.h" -#include "vapi/vsl.h" + +#include "vqueue.h" +#include "vre.h" #include "vsl_priv.h" + +#include "vapi/vsl.h" +#include "vapi/vsm.h" + #include "vsl_api.h" +#include "vsm_api.h" struct vslc_vsm { unsigned magic; diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c index 7f393b3..5189081 100644 --- a/lib/libvarnishapi/vsl_dispatch.c +++ b/lib/libvarnishapi/vsl_dispatch.c @@ -29,19 +29,23 @@ */ #include -#include -#include -#include #include #include +#include +#include +#include +#include "vdef.h" #include "vas.h" #include "miniobj.h" + #include "vqueue.h" -#include "vtree.h" +#include "vre.h" #include "vtim.h" +#include "vtree.h" #include "vapi/vsl.h" + #include "vsl_api.h" #define VTX_CACHE 10 diff --git a/lib/libvarnishapi/vsl_glob_test.c b/lib/libvarnishapi/vsl_glob_test.c index 6aac16a..bc5eee1 100644 --- a/lib/libvarnishapi/vsl_glob_test.c +++ b/lib/libvarnishapi/vsl_glob_test.c @@ -28,8 +28,8 @@ * Test what VSL_Name2Tag and VSL_Glob2Tags produces */ -#include #include +#include #include #include diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c index 7b4d279..435a351 100644 --- a/lib/libvarnishapi/vsl_query.c +++ b/lib/libvarnishapi/vsl_query.c @@ -28,22 +28,26 @@ * */ -#include #include +#include #include #include -#include #include +#include #include -#include "miniobj.h" -#include "vas.h" #include "vdef.h" +#include "vas.h" +#include "miniobj.h" + #include "vbm.h" #include "vnum.h" +#include "vqueue.h" +#include "vre.h" #include "vsb.h" #include "vapi/vsl.h" + #include "vsl_api.h" #include "vxp.h" diff --git a/lib/libvarnishapi/vsm.c b/lib/libvarnishapi/vsm.c index ebc742e..e805b1f 100644 --- a/lib/libvarnishapi/vsm.c +++ b/lib/libvarnishapi/vsm.c @@ -43,15 +43,17 @@ #include #include -#include "miniobj.h" -#include "vas.h" #include "vdef.h" +#include "vas.h" +#include "miniobj.h" -#include "vapi/vsm.h" -#include "vsm_priv.h" -#include "vtim.h" #include "vin.h" #include "vsb.h" +#include "vsm_priv.h" +#include "vtim.h" + +#include "vapi/vsm.h" + #include "vsm_api.h" #ifndef MAP_HASSEMAPHORE diff --git a/lib/libvarnishapi/vsm_api.h b/lib/libvarnishapi/vsm_api.h index ce4f954..7df8c88 100644 --- a/lib/libvarnishapi/vsm_api.h +++ b/lib/libvarnishapi/vsm_api.h @@ -28,8 +28,6 @@ * */ -#include - struct vsc; struct vsb; diff --git a/lib/libvarnishapi/vxp.c b/lib/libvarnishapi/vxp.c index e877cae..2e21b55 100644 --- a/lib/libvarnishapi/vxp.c +++ b/lib/libvarnishapi/vxp.c @@ -31,14 +31,15 @@ #include "config.h" #include +#include #include #include #include -#include -#include "vas.h" #include "vdef.h" +#include "vas.h" #include "miniobj.h" + #include "vqueue.h" #include "vre.h" #include "vsb.h" diff --git a/lib/libvarnishapi/vxp_lexer.c b/lib/libvarnishapi/vxp_lexer.c index 59e6869..c57318c 100644 --- a/lib/libvarnishapi/vxp_lexer.c +++ b/lib/libvarnishapi/vxp_lexer.c @@ -31,16 +31,17 @@ #include "config.h" #include +#include #include #include #include -#include #include "vdef.h" -#include "vsb.h" #include "vas.h" #include "vqueue.h" + #include "vre.h" +#include "vsb.h" #include "vxp.h" diff --git a/lib/libvarnishapi/vxp_parse.c b/lib/libvarnishapi/vxp_parse.c index 8e9632d..410fccb 100644 --- a/lib/libvarnishapi/vxp_parse.c +++ b/lib/libvarnishapi/vxp_parse.c @@ -33,20 +33,24 @@ #include #include #include +#include #include #include #include -#include -#include "miniobj.h" -#include "vas.h" #include "vdef.h" +#include "vas.h" +#include "miniobj.h" + #include "vbm.h" #include "vnum.h" +#include "vqueue.h" +#include "vre.h" #include "vsb.h" + #include "vapi/vsl.h" -#include "vsl_api.h" +#include "vsl_api.h" #include "vxp.h" static void vxp_expr_or(struct vxp *vxp, struct vex **pvex); diff --git a/lib/libvarnishapi/vxp_test.c b/lib/libvarnishapi/vxp_test.c index a4abf4a..970cb26 100644 --- a/lib/libvarnishapi/vxp_test.c +++ b/lib/libvarnishapi/vxp_test.c @@ -26,16 +26,18 @@ * SUCH DAMAGE. */ -#include -#include #include +#include +#include #include #include -#include "vxp.h" +#include "miniobj.h" #include "vas.h" + #include "vsb.h" -#include "miniobj.h" + +#include "vxp.h" static void usage(void) From phk at FreeBSD.org Wed Mar 4 13:48:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 14:48:35 +0100 Subject: [master] 3c3c6ab Untangle more nested includes Message-ID: commit 3c3c6ab60c0067a06bde1783563e6821e9650a67 Author: Poul-Henning Kamp Date: Wed Mar 4 13:47:46 2015 +0000 Untangle more nested includes diff --git a/bin/varnishhist/varnishhist.c b/bin/varnishhist/varnishhist.c index c364ad3..310eccc 100644 --- a/bin/varnishhist/varnishhist.c +++ b/bin/varnishhist/varnishhist.c @@ -46,6 +46,7 @@ #include #include +#include "vdef.h" #include "vcurses.h" #include "vapi/vsl.h" #include "vapi/vsm.h" diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index d8fc721..8002f95 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -82,7 +82,7 @@ SLTM(SessOpen, 0, "Client connection opened", * XXX: If we could, these three lines would have described the * XXX: 'reason' field below. #define SESS_CLOSE(nm, desc) " " #nm "\n\t" desc "\n\n" -#include +#include "tbl/sess_close.h" #undef SESS_CLOSE */ diff --git a/include/vapi/vsl.h b/include/vapi/vsl.h index 8d5a2ef..c202dfd 100644 --- a/include/vapi/vsl.h +++ b/include/vapi/vsl.h @@ -34,8 +34,6 @@ #ifndef VAPI_VSL_H_INCLUDED #define VAPI_VSL_H_INCLUDED -#include - #include "vapi/vsl_int.h" struct VSM_data; diff --git a/include/vcli_common.h b/include/vcli_common.h index fbb4e9f..8d0a623 100644 --- a/include/vcli_common.h +++ b/include/vcli_common.h @@ -28,8 +28,6 @@ * */ -#include "vdef.h" - struct vlu; struct VCLS; diff --git a/include/vut.h b/include/vut.h index bd093d1..6558227 100644 --- a/include/vut.h +++ b/include/vut.h @@ -29,8 +29,6 @@ * Common functions for the utilities */ -#include "vdef.h" - typedef int VUT_cb_f(void); struct VUT { diff --git a/lib/libvarnish/cli_common.c b/lib/libvarnish/cli_common.c index 74c966f..44a6869 100644 --- a/lib/libvarnish/cli_common.c +++ b/lib/libvarnish/cli_common.c @@ -43,8 +43,10 @@ #include #include -#include "miniobj.h" +#include "vdef.h" #include "vas.h" +#include "miniobj.h" + #include "vcli.h" #include "vcli_common.h" #include "vcli_priv.h" diff --git a/lib/libvarnish/cli_serve.c b/lib/libvarnish/cli_serve.c index 7b7d9d5..64fb7dd 100644 --- a/lib/libvarnish/cli_serve.c +++ b/lib/libvarnish/cli_serve.c @@ -41,8 +41,9 @@ #include #include -#include "miniobj.h" +#include "vdef.h" #include "vas.h" +#include "miniobj.h" #include "vav.h" #include "vcli.h" diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c index 5189081..0b9285c 100644 --- a/lib/libvarnishapi/vsl_dispatch.c +++ b/lib/libvarnishapi/vsl_dispatch.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c index 435a351..20ef8c2 100644 --- a/lib/libvarnishapi/vsl_query.c +++ b/lib/libvarnishapi/vsl_query.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/libvarnishtools/vut.c b/lib/libvarnishtools/vut.c index 1635ffe..6c4a683 100644 --- a/lib/libvarnishtools/vut.c +++ b/lib/libvarnishtools/vut.c @@ -41,6 +41,7 @@ #include #include "compat/daemon.h" +#include "vdef.h" #include "vpf.h" #include "vapi/vsm.h" #include "vapi/vsl.h" From nils.goroll at uplex.de Wed Mar 4 15:16:28 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 04 Mar 2015 16:16:28 +0100 Subject: [master] 49cd9e6 clear a ws overflow when resetting Message-ID: commit 49cd9e68a49f6ec7e8c937e2b48e379d68064c75 Author: Nils Goroll Date: Wed Mar 4 15:48:56 2015 +0100 clear a ws overflow when resetting diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c index c6f2d6a..d93aee4 100644 --- a/bin/varnishd/cache/cache_ws.c +++ b/bin/varnishd/cache/cache_ws.c @@ -93,6 +93,14 @@ WS_MarkOverflow(struct ws *ws) ws->id[0] &= ~0x40; // Cheasy toupper() } +static void +ws_ClearOverflow(struct ws *ws) +{ + CHECK_OBJ_NOTNULL(ws, WS_MAGIC); + + ws->id[0] |= 0x40; // Cheasy tolower() +} + /* * Reset a WS to start or a given pointer, likely from WS_Snapshot */ @@ -111,6 +119,7 @@ WS_Reset(struct ws *ws, char *p) assert(p < ws->e); ws->f = p; } + ws_ClearOverflow(ws); WS_Assert(ws); } From nils.goroll at uplex.de Wed Mar 4 15:16:28 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 04 Mar 2015 16:16:28 +0100 Subject: [master] ccf21a3 make VRB_Iterate return the length iterated over Message-ID: commit ccf21a3d0d997d396cb708ee84a2dd1b6d7d769a Author: Nils Goroll Date: Wed Mar 4 15:49:35 2015 +0100 make VRB_Iterate return the length iterated over diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 46b410b..d20222c 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -761,7 +761,7 @@ void V1P_Process(struct req *req, struct busyobj *bo, int fd); /* cache_req_body.c */ int VRB_Ignore(struct req *req); int VRB_Cache(struct req *req, ssize_t maxsize); -int VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv); +ssize_t VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv); void VRB_Free(struct req *req); /* cache_req_fsm.c [CNT] */ diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c index 5c8f08c..6e77bc8 100644 --- a/bin/varnishd/cache/cache_req_body.c +++ b/bin/varnishd/cache/cache_req_body.c @@ -42,13 +42,15 @@ * * This can be done exactly once if uncached, and multiple times if the * req.body is cached. + * + * return length or -1 on error */ -int +ssize_t VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv) { char buf[8192]; - ssize_t l; + ssize_t l, ll = 0; void *p; int i; struct vfp_ctx *vfc; @@ -65,11 +67,12 @@ VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv) AN(oi); do { ois = ObjIter(req->body_oc, oi, &p, &l); + ll += l; if (l > 0 && func(req, priv, p, l)) break; } while (ois == OIS_DATA); ObjIterEnd(req->body_oc, &oi); - return (ois == OIS_DONE ? 0 : -1); + return (ois == OIS_DONE ? ll : -1); case REQ_BODY_NONE: return (0); case REQ_BODY_WITH_LEN: @@ -116,14 +119,16 @@ VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv) vfps = VFP_Suck(vfc, buf, &l); if (vfps == VFP_ERROR) { req->req_body_status = REQ_BODY_FAIL; - l = -1; + ll = -1; break; } else if (l > 0) { req->req_bodybytes += l; req->acct.req_bodybytes += l; + ll += l; l = func(req, priv, buf, l); if (l) { req->req_body_status = REQ_BODY_FAIL; + ll = -1; break; } } @@ -131,7 +136,7 @@ VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv) VFP_Close(vfc); VSLb_ts_req(req, "ReqBody", VTIM_real()); - return (l); + return (ll); } /*---------------------------------------------------------------------- diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 685f2e7..d776430 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -77,7 +77,8 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) struct http *hp; enum http1_status_e hs; int retry = 1; - int i, j, first; + int j, first; + ssize_t i; struct http_conn *htc; int do_chunked = 0; @@ -129,7 +130,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) } j = V1L_FlushRelease(wrk); - if (j != 0 || i != 0) { + if (j != 0 || i < 0) { VSLb(bo->vsl, SLT_FetchError, "backend write error: %d (%s)", errno, strerror(errno)); VSLb_ts_busyobj(bo, "Bereq", W_TIM_real(wrk)); From phk at FreeBSD.org Wed Mar 4 15:23:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 16:23:35 +0100 Subject: [master] b096e4e Add three new feature checks: Message-ID: commit b096e4edad3584f8dd53eb445dec18654c8e262b Author: Poul-Henning Kamp Date: Wed Mar 4 15:21:30 2015 +0000 Add three new feature checks: root -- you must be root user_varnish -- system must have a "varnish" user group_varnish -- system must have a "varnish" group diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c index 5759d38..6abc7bb 100644 --- a/bin/varnishtest/vtc.c +++ b/bin/varnishtest/vtc.c @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include "vtc.h" @@ -515,6 +517,17 @@ cmd_feature(CMD_ARGS) if (!strcmp(av[i], "topbuild") && iflg) continue; + if (!strcmp(av[i], "root") && !geteuid()) + continue; + + if (!strcmp(av[i], "user_varnish") && + getpwnam("varnish") != NULL) + continue; + + if (!strcmp(av[i], "group_varnish") && + getgrnam("varnish") != NULL) + continue; + vtc_log(vl, 1, "SKIPPING test, missing feature: %s", av[i]); vtc_stop = 1; return; From phk at FreeBSD.org Wed Mar 4 15:23:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 16:23:35 +0100 Subject: [master] 4777ff3 Add a -jail argument to pass jail related command line arguments to varnishd. (special because -j must always be the very first argument) Message-ID: commit 4777ff30f84f29dd4362b04384eab50208e8c161 Author: Poul-Henning Kamp Date: Wed Mar 4 15:22:11 2015 +0000 Add a -jail argument to pass jail related command line arguments to varnishd. (special because -j must always be the very first argument) diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 9ec7683..5704288 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -68,6 +68,7 @@ struct varnish { int cli_fd; int vcl_nbr; char *workdir; + char *jail; struct VSM_data *vd; /* vsc use */ @@ -269,6 +270,8 @@ varnish_new(const char *name) AN(v); REPLACE(v->name, name); + REPLACE(v->jail, ""); + v->vl = vtc_logopen(name); AN(v->vl); @@ -384,7 +387,8 @@ varnish_launch(struct varnish *v) vsb = VSB_new_auto(); AN(vsb); VSB_printf(vsb, "cd ${pwd} &&"); - VSB_printf(vsb, "exec ${varnishd} -d -d -n %s", v->workdir); + VSB_printf(vsb, " exec ${varnishd} %s -d -d -n %s", + v->jail, v->workdir); VSB_printf(vsb, " -l 2m,1m,-"); VSB_printf(vsb, " -p auto_restart=off"); VSB_printf(vsb, " -p syslog_cli_traffic=off"); @@ -863,6 +867,13 @@ cmd_varnish(CMD_ARGS) for (; *av != NULL; av++) { if (vtc_error) break; + if (!strcmp(*av, "-jail")) { + AN(av[1]); + AZ(v->pid); + REPLACE(v->jail, av[1]); + av++; + continue; + } if (!strcmp(*av, "-arg")) { AN(av[1]); AZ(v->pid); From phk at FreeBSD.org Wed Mar 4 15:23:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 04 Mar 2015 16:23:35 +0100 Subject: [master] 21cd8ee Add a basic test case for unix jails Message-ID: commit 21cd8eed2f6c8b59d6a14a5a4bede98c699ed464 Author: Poul-Henning Kamp Date: Wed Mar 4 15:23:14 2015 +0000 Add a basic test case for unix jails diff --git a/bin/varnishtest/tests/README b/bin/varnishtest/tests/README index a504ec5..3d6fdca 100644 --- a/bin/varnishtest/tests/README +++ b/bin/varnishtest/tests/README @@ -19,6 +19,7 @@ Naming scheme id ~ [d] --> Director VMOD tests id ~ [e] --> ESI tests id ~ [g] --> GZIP tests + id ~ [j] --> JAIL tests id ~ [l] --> VSL tests id ~ [m] --> VMOD tests excluding director id ~ [p] --> Persistent tests diff --git a/bin/varnishtest/tests/j00000.vtc b/bin/varnishtest/tests/j00000.vtc new file mode 100644 index 0000000..f9ae253 --- /dev/null +++ b/bin/varnishtest/tests/j00000.vtc @@ -0,0 +1,21 @@ +varnishtest "Code coverage basic UNIX jail" + +feature user_varnish +feature group_varnish +feature root + +server s1 { + rxreq + txresp +} -start + +varnish v1 \ + -jail "-junix,user=varnish,ccgroup=varnish" \ + -vcl+backend { +} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run From nils.goroll at uplex.de Wed Mar 4 16:24:56 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 04 Mar 2015 17:24:56 +0100 Subject: [master] 6fd7f77 fix function name Message-ID: commit 6fd7f77d9b0a9dbe96da24c8a323586c1e52764a Author: Nils Goroll Date: Wed Mar 4 16:25:04 2015 +0100 fix function name diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c index 6e77bc8..c897153 100644 --- a/bin/varnishd/cache/cache_req_body.c +++ b/bin/varnishd/cache/cache_req_body.c @@ -213,7 +213,7 @@ VRB_Cache(struct req *req, ssize_t maxsize) case REQ_BODY_WITH_LEN: break; default: - WRONG("Wrong req_body_status in VRB_CacheReqBody()"); + WRONG("Wrong req_body_status in VRB_Cache()"); } CHECK_OBJ_NOTNULL(req->htc, HTTP_CONN_MAGIC); From nils.goroll at uplex.de Wed Mar 4 16:24:56 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 04 Mar 2015 17:24:56 +0100 Subject: [master] 16b84c2 use s?size_t for req_bodybytes and VRB_Cache Message-ID: commit 16b84c2a0c560da2765068dba1d4458b4706f586 Author: Nils Goroll Date: Wed Mar 4 16:49:59 2015 +0100 use s?size_t for req_bodybytes and VRB_Cache The VRT side of things still needs attention diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index d20222c..183fc7a 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -587,7 +587,7 @@ struct req { enum sess_close doclose; double d_ttl; - uint64_t req_bodybytes; /* Parsed req bodybytes */ + ssize_t req_bodybytes; /* Parsed req bodybytes */ uint16_t err_code; const char *err_reason; @@ -760,7 +760,7 @@ void V1P_Process(struct req *req, struct busyobj *bo, int fd); /* cache_req_body.c */ int VRB_Ignore(struct req *req); -int VRB_Cache(struct req *req, ssize_t maxsize); +ssize_t VRB_Cache(struct req *req, ssize_t maxsize); ssize_t VRB_Iterate(struct req *req, req_body_iter_f *func, void *priv); void VRB_Free(struct req *req); diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c index c897153..c73db54 100644 --- a/bin/varnishd/cache/cache_req_body.c +++ b/bin/varnishd/cache/cache_req_body.c @@ -191,7 +191,7 @@ VRB_Free(struct req *req) * off to prevent parallelism. */ -int +ssize_t VRB_Cache(struct req *req, ssize_t maxsize) { ssize_t l, yet; @@ -220,6 +220,7 @@ VRB_Cache(struct req *req, ssize_t maxsize) vfc = req->htc->vfc; if (req->htc->content_length > maxsize) { + // XXX #1664 req->req_body_status = REQ_BODY_FAIL; (void)VFP_Error(vfc, "Request body too big to cache"); return (-1); @@ -240,6 +241,7 @@ VRB_Cache(struct req *req, ssize_t maxsize) return (-1); } + AZ(req->req_bodybytes); AN(req->htc); yet = req->htc->content_length; if (yet < 0) @@ -265,7 +267,7 @@ VRB_Cache(struct req *req, ssize_t maxsize) VFP_Close(vfc); if (vfps == VFP_END) { - + assert(req->req_bodybytes >= 0); if (req->req_bodybytes != req->htc->content_length) { /* We must update also the "pristine" req.* copy */ http_Unset(req->http0, H_Content_Length); diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c index 6148b2b..6851bc0 100644 --- a/bin/varnishd/cache/cache_vrt.c +++ b/bin/varnishd/cache/cache_vrt.c @@ -475,6 +475,8 @@ VRT_ban_string(VRT_CTX, const char *str) /*-------------------------------------------------------------------- * + * XXX this really should be ssize_t VRT_CacheReqBody(VRT_CTX, size_t) + * - change with next VRT major bump */ int diff --git a/include/vrt.h b/include/vrt.h index 3e3589e..d5a579c 100644 --- a/include/vrt.h +++ b/include/vrt.h @@ -37,6 +37,9 @@ * Whenever something is added, increment MINOR version * Whenever something is deleted or changed in a way which is not * binary/load-time compatible, increment MAJOR version + * + * changes to consider with next VRT_MAJOR_VERSION bump: + * - cache_vrt.c: -> ssize_t VRT_CacheReqBody(VRT_CTX, size_t) */ #define VRT_MAJOR_VERSION 2U From nils.goroll at uplex.de Fri Mar 6 16:46:48 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 06 Mar 2015 17:46:48 +0100 Subject: [master] e155d2d More consistent naming auf client vs. backend IMS Tests Message-ID: commit e155d2df44720f12eaf559379ea02c6fe704adf0 Author: Nils Goroll Date: Fri Mar 6 17:46:26 2015 +0100 More consistent naming auf client vs. backend IMS Tests diff --git a/bin/varnishtest/tests/b00039.vtc b/bin/varnishtest/tests/b00039.vtc index cf1e9dc..d076290 100644 --- a/bin/varnishtest/tests/b00039.vtc +++ b/bin/varnishtest/tests/b00039.vtc @@ -1,4 +1,4 @@ -varnishtest "Test IMS" +varnishtest "Test Backend IMS" server s1 { rxreq diff --git a/bin/varnishtest/tests/c00008.vtc b/bin/varnishtest/tests/c00008.vtc index 09535c9..a654962 100644 --- a/bin/varnishtest/tests/c00008.vtc +++ b/bin/varnishtest/tests/c00008.vtc @@ -1,4 +1,4 @@ -varnishtest "Test If-Modified-Since" +varnishtest "Test Client IMS" server s1 { rxreq diff --git a/bin/varnishtest/tests/c00026.vtc b/bin/varnishtest/tests/c00026.vtc index 7840b48..d528c0b 100644 --- a/bin/varnishtest/tests/c00026.vtc +++ b/bin/varnishtest/tests/c00026.vtc @@ -1,4 +1,4 @@ -varnishtest "Test Combination of If-None-Match and If-Modified-Since" +varnishtest "Client IMS/INM: Test Combination of If-None-Match and If-Modified-Since" server s1 { rxreq diff --git a/bin/varnishtest/tests/c00060.vtc b/bin/varnishtest/tests/c00060.vtc index 1e6e734..8fdb04e 100644 --- a/bin/varnishtest/tests/c00060.vtc +++ b/bin/varnishtest/tests/c00060.vtc @@ -1,4 +1,4 @@ -varnishtest "IMS header merging" +varnishtest "Backend IMS header merging" server s1 { rxreq diff --git a/bin/varnishtest/tests/g00006.vtc b/bin/varnishtest/tests/g00006.vtc index 2400401..e0b9ea9 100644 --- a/bin/varnishtest/tests/g00006.vtc +++ b/bin/varnishtest/tests/g00006.vtc @@ -1,4 +1,4 @@ -varnishtest "IMS'ing g[un]zip'ed objects" +varnishtest "Backend IMS'ing g[un]zip'ed objects" server s1 { rxreq From phk at FreeBSD.org Sat Mar 7 13:32:39 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 07 Mar 2015 14:32:39 +0100 Subject: [master] 074ad32 Uninline VTCP_Check() Message-ID: commit 074ad32b563f2713e443ff54a02f8afe618665ae Author: Poul-Henning Kamp Date: Sat Mar 7 09:02:47 2015 +0000 Uninline VTCP_Check() diff --git a/include/vtcp.h b/include/vtcp.h index f4a9690..b49f3ae 100644 --- a/include/vtcp.h +++ b/include/vtcp.h @@ -35,25 +35,7 @@ struct suckaddr; #define VTCP_ADDRBUFSIZE 64 #define VTCP_PORTBUFSIZE 16 -static inline int -VTCP_Check(int a) -{ - if (a == 0) - return (1); - if (errno == ECONNRESET || errno == ENOTCONN) - return (1); -#if (defined (__SVR4) && defined (__sun)) || defined (__NetBSD__) - /* - * Solaris returns EINVAL if the other end unexepectedly reset the - * connection. - * This is a bug in Solaris and documented behaviour on NetBSD. - */ - if (errno == EINVAL || errno == ETIMEDOUT) - return (1); -#endif - return (0); -} - +int VTCP_Check(int a); #define VTCP_Assert(a) assert(VTCP_Check(a)) void VTCP_myname(int sock, char *abuf, unsigned alen, diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c index 1295cc9..bdee1c7 100644 --- a/lib/libvarnish/vtcp.c +++ b/lib/libvarnish/vtcp.c @@ -344,3 +344,26 @@ VTCP_check_hup(int sock) return (1); return (0); } + +/*-------------------------------------------------------------------- + * Check if a TCP syscall return value is fatal + */ + +int +VTCP_Check(int a) +{ + if (a == 0) + return (1); + if (errno == ECONNRESET || errno == ENOTCONN) + return (1); +#if (defined (__SVR4) && defined (__sun)) || defined (__NetBSD__) + /* + * Solaris returns EINVAL if the other end unexepectedly reset the + * connection. + * This is a bug in Solaris and documented behaviour on NetBSD. + */ + if (errno == EINVAL || errno == ETIMEDOUT) + return (1); +#endif + return (0); +} From phk at FreeBSD.org Sat Mar 7 13:32:39 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 07 Mar 2015 14:32:39 +0100 Subject: [master] 017278b Collect the management of listen/acceptor sockets in its own file. Message-ID: commit 017278babfc0eb458936a73feb5ee86d1fcc95bc Author: Poul-Henning Kamp Date: Sat Mar 7 09:22:43 2015 +0000 Collect the management of listen/acceptor sockets in its own file. diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am index aeef7c1..e619d33 100644 --- a/bin/varnishd/Makefile.am +++ b/bin/varnishd/Makefile.am @@ -62,6 +62,7 @@ varnishd_SOURCES = \ http1/cache_http1_pipe.c \ http1/cache_http1_proto.c \ http1/cache_http1_vfp.c \ + mgt/mgt_acceptor.c \ mgt/mgt_child.c \ mgt/mgt_cli.c \ mgt/mgt_jail.c \ diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 7d734ee..551c689 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -45,8 +45,8 @@ void MGT_Run(void); void mgt_stop_child(void); void mgt_got_fd(int fd); void MGT_Child_Cli_Fail(void); -int MGT_open_sockets(void); -void MGT_close_sockets(void); +int MAC_open_sockets(void); +void MAC_close_sockets(void); /* mgt_cli.c */ diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c new file mode 100644 index 0000000..6c2402f --- /dev/null +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -0,0 +1,184 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2014 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Acceptor socket management + */ + +#include "config.h" + +#include +#include +#include +#include +#include + +#include "mgt/mgt.h" +#include "mgt/mgt_param.h" +#include "common/heritage.h" +#include "common/params.h" + +#include "vav.h" +#include "vss.h" + +/*===================================================================== + * Open and close the accept sockets. + * + * (The child is priv-sep'ed, so it can't do it.) + */ + +int +MAC_open_sockets(void) +{ + struct listen_sock *ls; + int good = 0; + + VJ_master(JAIL_MASTER_HIGH); + VTAILQ_FOREACH(ls, &heritage.socks, list) { + if (ls->sock >= 0) { + good++; + continue; + } + ls->sock = VSS_bind(ls->addr); + if (ls->sock < 0) + continue; + + mgt_child_inherit(ls->sock, "sock"); + + good++; + } + VJ_master(JAIL_MASTER_LOW); + if (!good) + return (1); + return (0); +} + +/*--------------------------------------------------------------------*/ + +void +MAC_close_sockets(void) +{ + struct listen_sock *ls; + + VTAILQ_FOREACH(ls, &heritage.socks, list) { + if (ls->sock < 0) + continue; + mgt_child_inherit(ls->sock, NULL); + AZ(close(ls->sock)); + ls->sock = -1; + } +} + +/*--------------------------------------------------------------------*/ + +static void +clean_listen_sock_head(struct listen_sock_head *lsh) +{ + struct listen_sock *ls, *ls2; + + VTAILQ_FOREACH_SAFE(ls, lsh, list, ls2) { + CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC); + VTAILQ_REMOVE(lsh, ls, list); + free(ls->name); + free(ls->addr); + FREE_OBJ(ls); + } +} + +int +tweak_listen_address(struct vsb *vsb, const struct parspec *par, + const char *arg) +{ + char **av; + int i, retval = 0; + struct listen_sock *ls; + struct listen_sock_head lsh; + + (void)par; + if (arg == NULL) { + VSB_quote(vsb, mgt_param.listen_address, -1, 0); + return (0); + } + + av = VAV_Parse(arg, NULL, ARGV_COMMA); + if (av == NULL) { + VSB_printf(vsb, "Parse error: out of memory"); + return(-1); + } + if (av[0] != NULL) { + VSB_printf(vsb, "Parse error: %s", av[0]); + VAV_Free(av); + return(-1); + } + if (av[1] == NULL) { + VSB_printf(vsb, "Empty listen address"); + VAV_Free(av); + return(-1); + } + VTAILQ_INIT(&lsh); + for (i = 1; av[i] != NULL; i++) { + struct vss_addr **ta; + int j, n; + + n = VSS_resolve(av[i], "http", &ta); + if (n == 0) { + VSB_printf(vsb, "Invalid listen address "); + VSB_quote(vsb, av[i], -1, 0); + retval = -1; + break; + } + for (j = 0; j < n; ++j) { + ALLOC_OBJ(ls, LISTEN_SOCK_MAGIC); + AN(ls); + ls->sock = -1; + ls->addr = ta[j]; + ls->name = strdup(av[i]); + AN(ls->name); + VTAILQ_INSERT_TAIL(&lsh, ls, list); + } + free(ta); + } + VAV_Free(av); + if (retval) { + clean_listen_sock_head(&lsh); + return (-1); + } + + REPLACE(mgt_param.listen_address, arg); + + clean_listen_sock_head(&heritage.socks); + heritage.nsocks = 0; + + while (!VTAILQ_EMPTY(&lsh)) { + ls = VTAILQ_FIRST(&lsh); + VTAILQ_REMOVE(&lsh, ls, list); + CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC); + VTAILQ_INSERT_TAIL(&heritage.socks, ls, list); + heritage.nsocks++; + } + return (0); +} diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index c116c5f..ae9033d 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -52,7 +52,6 @@ #include "vcli_priv.h" #include "vev.h" #include "vlu.h" -#include "vss.h" #include "vtim.h" #include "mgt_cli.h" @@ -218,53 +217,6 @@ mgt_child_inherit(int fd, const char *what) } /*===================================================================== - * Open and close the accept sockets. - * - * (The child is priv-sep'ed, so it can't do it.) - */ - -int -MGT_open_sockets(void) -{ - struct listen_sock *ls; - int good = 0; - - VJ_master(JAIL_MASTER_HIGH); - VTAILQ_FOREACH(ls, &heritage.socks, list) { - if (ls->sock >= 0) { - good++; - continue; - } - ls->sock = VSS_bind(ls->addr); - if (ls->sock < 0) - continue; - - mgt_child_inherit(ls->sock, "sock"); - - good++; - } - VJ_master(JAIL_MASTER_LOW); - if (!good) - return (1); - return (0); -} - -/*--------------------------------------------------------------------*/ - -void -MGT_close_sockets(void) -{ - struct listen_sock *ls; - - VTAILQ_FOREACH(ls, &heritage.socks, list) { - if (ls->sock < 0) - continue; - mgt_child_inherit(ls->sock, NULL); - closex(&ls->sock); - } -} - -/*===================================================================== * Listen to stdout+stderr from the child */ @@ -351,7 +303,7 @@ mgt_launch_child(struct cli *cli) if (child_state != CH_STOPPED && child_state != CH_DIED) return; - if (MGT_open_sockets() != 0) { + if (MAC_open_sockets() != 0) { child_state = CH_STOPPED; if (cli != NULL) { VCLI_SetResult(cli, CLIS_CANT); @@ -442,7 +394,7 @@ mgt_launch_child(struct cli *cli) mgt_child_inherit(heritage.cli_out, NULL); closex(&heritage.cli_out); - MGT_close_sockets(); + MAC_close_sockets(); child_std_vlu = VLU_New(NULL, child_line, 0); AN(child_std_vlu); diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 896f2dd..2ea0cc6 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -629,9 +629,9 @@ main(int argc, char * const *argv) ARGV_ERR("-C only good with -b or -f\n"); if (!d_flag) { - if (MGT_open_sockets()) + if (MAC_open_sockets()) ARGV_ERR("Failed to open (any) accept sockets.\n"); - MGT_close_sockets(); + MAC_close_sockets(); if (b_arg == NULL && f_arg == NULL) { fprintf(stderr, diff --git a/bin/varnishd/mgt/mgt_param_tweak.c b/bin/varnishd/mgt/mgt_param_tweak.c index 3fe28dc..f75a5b5 100644 --- a/bin/varnishd/mgt/mgt_param_tweak.c +++ b/bin/varnishd/mgt/mgt_param_tweak.c @@ -40,14 +40,12 @@ #include #include "mgt/mgt.h" -#include "common/heritage.h" #include "common/params.h" #include "mgt/mgt_param.h" #include "waiter/waiter.h" #include "vav.h" #include "vnum.h" -#include "vss.h" /*-------------------------------------------------------------------- * Generic handling of double typed parameters @@ -365,96 +363,6 @@ tweak_vsl_reclen(struct vsb *vsb, const struct parspec *par, const char *arg) /*--------------------------------------------------------------------*/ -static void -clean_listen_sock_head(struct listen_sock_head *lsh) -{ - struct listen_sock *ls, *ls2; - - VTAILQ_FOREACH_SAFE(ls, lsh, list, ls2) { - CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC); - VTAILQ_REMOVE(lsh, ls, list); - free(ls->name); - free(ls->addr); - FREE_OBJ(ls); - } -} - -int -tweak_listen_address(struct vsb *vsb, const struct parspec *par, - const char *arg) -{ - char **av; - int i, retval = 0; - struct listen_sock *ls; - struct listen_sock_head lsh; - - (void)par; - if (arg == NULL) { - VSB_quote(vsb, mgt_param.listen_address, -1, 0); - return (0); - } - - av = VAV_Parse(arg, NULL, ARGV_COMMA); - if (av == NULL) { - VSB_printf(vsb, "Parse error: out of memory"); - return(-1); - } - if (av[0] != NULL) { - VSB_printf(vsb, "Parse error: %s", av[0]); - VAV_Free(av); - return(-1); - } - if (av[1] == NULL) { - VSB_printf(vsb, "Empty listen address"); - VAV_Free(av); - return(-1); - } - VTAILQ_INIT(&lsh); - for (i = 1; av[i] != NULL; i++) { - struct vss_addr **ta; - int j, n; - - n = VSS_resolve(av[i], "http", &ta); - if (n == 0) { - VSB_printf(vsb, "Invalid listen address "); - VSB_quote(vsb, av[i], -1, 0); - retval = -1; - break; - } - for (j = 0; j < n; ++j) { - ALLOC_OBJ(ls, LISTEN_SOCK_MAGIC); - AN(ls); - ls->sock = -1; - ls->addr = ta[j]; - ls->name = strdup(av[i]); - AN(ls->name); - VTAILQ_INSERT_TAIL(&lsh, ls, list); - } - free(ta); - } - VAV_Free(av); - if (retval) { - clean_listen_sock_head(&lsh); - return (-1); - } - - REPLACE(mgt_param.listen_address, arg); - - clean_listen_sock_head(&heritage.socks); - heritage.nsocks = 0; - - while (!VTAILQ_EMPTY(&lsh)) { - ls = VTAILQ_FIRST(&lsh); - VTAILQ_REMOVE(&lsh, ls, list); - CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC); - VTAILQ_INSERT_TAIL(&heritage.socks, ls, list); - heritage.nsocks++; - } - return (0); -} - -/*--------------------------------------------------------------------*/ - int tweak_string(struct vsb *vsb, const struct parspec *par, const char *arg) { From phk at FreeBSD.org Sat Mar 7 13:32:39 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 07 Mar 2015 14:32:39 +0100 Subject: [master] c3adc83 Rename VCL_EVENT_* to match the CLI commands Message-ID: commit c3adc837e39f9ff9a797e26d872b11f9ca235948 Author: Poul-Henning Kamp Date: Sat Mar 7 09:36:06 2015 +0000 Rename VCL_EVENT_* to match the CLI commands diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 9606361..a83d50c 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -217,9 +217,9 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) ctx.cli = cli; ctx.vcl = vcl->conf; - if (vcl->conf->event_vcl(&ctx, VCL_EVENT_INIT)) { + if (vcl->conf->event_vcl(&ctx, VCL_EVENT_LOAD)) { VCLI_Out(cli, "VCL \"%s\" Failed to initialize", name); - AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_FINI)); + AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_DISCARD)); (void)dlclose(vcl->dlh); FREE_OBJ(vcl); return (1); @@ -229,7 +229,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) VCLI_Out(cli, "VCL \"%s\" vcl_init{} failed", name); ctx.method = VCL_MET_FINI; (void)vcl->conf->fini_func(&ctx); - AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_FINI)); + AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_DISCARD)); (void)dlclose(vcl->dlh); FREE_OBJ(vcl); return (1); @@ -268,7 +268,7 @@ VCL_Nuke(struct vcls *vcl) ctx.vcl = vcl->conf; (void)vcl->conf->fini_func(&ctx); assert(hand == VCL_RET_OK); - AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_FINI)); + AZ(vcl->conf->event_vcl(&ctx, VCL_EVENT_DISCARD)); free(vcl->conf->loaded_name); (void)dlclose(vcl->dlh); FREE_OBJ(vcl); @@ -360,7 +360,7 @@ ccf_config_use(struct cli *cli, const char * const *av, void *priv) INIT_OBJ(&ctx, VRT_CTX_MAGIC); ctx.handling = &hand; ctx.cli = cli; - if (vcl->conf->event_vcl(&ctx, VCL_EVENT_ACTIVATE)) { + if (vcl->conf->event_vcl(&ctx, VCL_EVENT_USE)) { VCLI_Out(cli, "VCL \"%s\" Failed to activate", av[2]); VCLI_SetResult(cli, CLIS_CANT); return; diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 9c90a55..c3b9a13 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -946,9 +946,9 @@ struct cli; struct worker; enum vcl_event_e { - VCL_EVENT_INIT, - VCL_EVENT_ACTIVATE, - VCL_EVENT_FINI, + VCL_EVENT_LOAD, + VCL_EVENT_USE, + VCL_EVENT_DISCARD, }; typedef int vcl_event_f(VRT_CTX, enum vcl_event_e); diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c index c9cc681..6402994 100644 --- a/lib/libvcc/vcc_backend.c +++ b/lib/libvcc/vcc_backend.c @@ -434,7 +434,7 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be) "\tVRT_fini_vbe(ctx, &VGCDIR(%s), &vgc_dir_priv_%s);", vgcname, vgcname); VSB_printf(ifp->event, - "\tif (ev == VCL_EVENT_ACTIVATE)\n" + "\tif (ev == VCL_EVENT_USE)\n" "\t\tVRT_use_vbe(ctx, VGCDIR(%s), &vgc_dir_priv_%s);", vgcname, vgcname); tl->ndirector++; diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c index e210c42..40c3772 100644 --- a/lib/libvcc/vcc_compile.c +++ b/lib/libvcc/vcc_compile.c @@ -344,9 +344,9 @@ EmitInitFini(const struct vcc *tl) Fc(tl, 0, "\nstatic int\n"); Fc(tl, 0, "VGC_Event(VRT_CTX, enum vcl_event_e ev)\n"); Fc(tl, 0, "{\n"); - Fc(tl, 0, "\tif (ev == VCL_EVENT_INIT)\n"); + Fc(tl, 0, "\tif (ev == VCL_EVENT_LOAD)\n"); Fc(tl, 0, "\t\treturn(VGC_Init(ctx));\n"); - Fc(tl, 0, "\tif (ev == VCL_EVENT_FINI)\n"); + Fc(tl, 0, "\tif (ev == VCL_EVENT_DISCARD)\n"); Fc(tl, 0, "\t\treturn(VGC_Fini(ctx));\n"); Fc(tl, 0, "\t\n"); VTAILQ_FOREACH(p, &tl->inifin, list) { From phk at FreeBSD.org Sat Mar 7 13:32:39 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 07 Mar 2015 14:32:39 +0100 Subject: [master] c4102bc Add two new VCL events, WARM and COLD. Regularize the names in the generated code. Pass VCL events to backends. Message-ID: commit c4102bcfd459165a8658d091408055327d2cb24f Author: Poul-Henning Kamp Date: Sat Mar 7 10:04:35 2015 +0000 Add two new VCL events, WARM and COLD. Regularize the names in the generated code. Pass VCL events to backends. diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 91a8939..0785792 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -319,7 +319,8 @@ VRT_init_vbe(VRT_CTX, struct director **dp, const struct vrt_backend *vrt) } void -VRT_use_vbe(VRT_CTX, const struct director *d, const struct vrt_backend *vrt) +VRT_event_vbe(VRT_CTX, enum vcl_event_e ev, const struct director *d, + const struct vrt_backend *vrt) { struct backend *be; @@ -334,7 +335,8 @@ VRT_use_vbe(VRT_CTX, const struct director *d, const struct vrt_backend *vrt) if (vrt->probe == NULL) return; - VBP_Use(be, vrt->probe); + if (ev == VCL_EVENT_USE) + VBP_Use(be, vrt->probe); } void diff --git a/include/vrt.h b/include/vrt.h index d5a579c..60a0f14 100644 --- a/include/vrt.h +++ b/include/vrt.h @@ -233,7 +233,10 @@ void VRT_synth_page(VRT_CTX, const char *, ...); /* Backend related */ void VRT_init_vbe(VRT_CTX, struct director **, const struct vrt_backend *); -void VRT_use_vbe(VRT_CTX, const struct director *, const struct vrt_backend *); +#ifdef VCL_RET_MAX +void VRT_event_vbe(VRT_CTX, enum vcl_event_e, const struct director *, + const struct vrt_backend *); +#endif void VRT_fini_vbe(VRT_CTX, struct director **, const struct vrt_backend *); /* Suckaddr related */ diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index c3b9a13..448cec8 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -947,7 +947,9 @@ struct worker; enum vcl_event_e { VCL_EVENT_LOAD, + VCL_EVENT_WARM, VCL_EVENT_USE, + VCL_EVENT_COLD, VCL_EVENT_DISCARD, }; diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c index 6402994..29444a6 100644 --- a/lib/libvcc/vcc_backend.c +++ b/lib/libvcc/vcc_backend.c @@ -434,8 +434,7 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be) "\tVRT_fini_vbe(ctx, &VGCDIR(%s), &vgc_dir_priv_%s);", vgcname, vgcname); VSB_printf(ifp->event, - "\tif (ev == VCL_EVENT_USE)\n" - "\t\tVRT_use_vbe(ctx, VGCDIR(%s), &vgc_dir_priv_%s);", + "\tVRT_event_vbe(ctx, ev, VGCDIR(%s), &vgc_dir_priv_%s);", vgcname, vgcname); tl->ndirector++; } diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c index 40c3772..f651ed7 100644 --- a/lib/libvcc/vcc_compile.c +++ b/lib/libvcc/vcc_compile.c @@ -312,7 +312,7 @@ EmitInitFini(const struct vcc *tl) /* * INIT */ - Fc(tl, 0, "\nstatic int\nVGC_Init(VRT_CTX)\n{\n\n"); + Fc(tl, 0, "\nstatic int\nVGC_Load(VRT_CTX)\n{\n\n"); VTAILQ_FOREACH(p, &tl->inifin, list) { AZ(VSB_finish(p->ini)); if (VSB_len(p->ini)) @@ -326,7 +326,7 @@ EmitInitFini(const struct vcc *tl) /* * FINI */ - Fc(tl, 0, "\nstatic int\nVGC_Fini(VRT_CTX)\n{\n\n"); + Fc(tl, 0, "\nstatic int\nVGC_Discard(VRT_CTX)\n{\n\n"); VTAILQ_FOREACH_REVERSE(p, &tl->inifin, inifinhead, list) { AZ(VSB_finish(p->fin)); @@ -345,9 +345,9 @@ EmitInitFini(const struct vcc *tl) Fc(tl, 0, "VGC_Event(VRT_CTX, enum vcl_event_e ev)\n"); Fc(tl, 0, "{\n"); Fc(tl, 0, "\tif (ev == VCL_EVENT_LOAD)\n"); - Fc(tl, 0, "\t\treturn(VGC_Init(ctx));\n"); + Fc(tl, 0, "\t\treturn(VGC_Load(ctx));\n"); Fc(tl, 0, "\tif (ev == VCL_EVENT_DISCARD)\n"); - Fc(tl, 0, "\t\treturn(VGC_Fini(ctx));\n"); + Fc(tl, 0, "\t\treturn(VGC_Discard(ctx));\n"); Fc(tl, 0, "\t\n"); VTAILQ_FOREACH(p, &tl->inifin, list) { AZ(VSB_finish(p->event)); From phk at FreeBSD.org Sat Mar 7 13:32:39 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 07 Mar 2015 14:32:39 +0100 Subject: [master] 7507b29 Give vcl.load and vcl.inline a third argument which can be "auto", "cold" or "warm". Message-ID: commit 7507b29d037acbfee121cf1dd21ff4d8d150adaf Author: Poul-Henning Kamp Date: Sat Mar 7 11:38:58 2015 +0000 Give vcl.load and vcl.inline a third argument which can be "auto", "cold" or "warm". diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index e181f74..b44a85e 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -56,6 +56,7 @@ struct vclprog { char *name; char *fname; int active; + char state[8]; }; struct vcc_priv { @@ -86,7 +87,7 @@ static const char * const builtin_vcl = /*--------------------------------------------------------------------*/ static void -mgt_vcc_add(const char *name, const char *libfile) +mgt_vcc_add(const char *name, const char *libfile, const char *state) { struct vclprog *vp; @@ -94,6 +95,7 @@ mgt_vcc_add(const char *name, const char *libfile) XXXAN(vp); REPLACE(vp->name, name); REPLACE(vp->fname, libfile); + bprintf(vp->state, "%s", state); if (VTAILQ_EMPTY(&vclhead)) vp->active = 1; VTAILQ_INSERT_TAIL(&vclhead, vp, list); @@ -338,7 +340,7 @@ mgt_vcc_compile(struct vcc_priv *vp, struct vsb *sb, int C_flag) static void mgt_VccCompile(struct cli *cli, const char *vclname, const char *vclsrc, - int C_flag) + const char *state, int C_flag) { struct vcc_priv vp; struct vsb *sb; @@ -346,6 +348,17 @@ mgt_VccCompile(struct cli *cli, const char *vclname, const char *vclsrc, char *p; AN(cli); + + if (state == NULL) + state = "auto"; + + if (strcmp(state, "auto") && + strcmp(state, "cold") && strcmp(state, "warm")) { + VCLI_Out(cli, "State must be one of auto, cold or warm."); + VCLI_SetResult(cli, CLIS_PARAM); + return; + } + sb = VSB_new_auto(); XXXAN(sb); @@ -387,14 +400,14 @@ mgt_VccCompile(struct cli *cli, const char *vclname, const char *vclsrc, VCLI_Out(cli, "VCL compiled.\n"); if (child_pid < 0) { - mgt_vcc_add(vclname, vp.libfile); + mgt_vcc_add(vclname, vp.libfile, state); free(vp.libfile); return; } if (!mgt_cli_askchild(&status, &p, - "vcl.load %s %s\n", vclname, vp.libfile)) { - mgt_vcc_add(vclname, vp.libfile); + "vcl.load %s %s %s\n", vclname, vp.libfile, state)) { + mgt_vcc_add(vclname, vp.libfile, state); free(vp.libfile); free(p); return; @@ -417,7 +430,7 @@ mgt_vcc_default(struct cli *cli, const char *b_arg, const char *vclsrc, if (b_arg == NULL) { AN(vclsrc); - mgt_VccCompile(cli, "boot", vclsrc, C_flag); + mgt_VccCompile(cli, "boot", vclsrc, NULL, C_flag); return; } @@ -427,7 +440,7 @@ mgt_vcc_default(struct cli *cli, const char *b_arg, const char *vclsrc, "backend default {\n" " .host = \"%s\";\n" "}\n", b_arg); - mgt_VccCompile(cli, "boot", buf, C_flag); + mgt_VccCompile(cli, "boot", buf, NULL, C_flag); } /*--------------------------------------------------------------------*/ @@ -439,7 +452,7 @@ mgt_push_vcls_and_start(unsigned *status, char **p) VTAILQ_FOREACH(vp, &vclhead, list) { if (mgt_cli_askchild(status, p, - "vcl.load \"%s\" %s\n", vp->name, vp->fname)) + "vcl.load \"%s\" %s %s\n", vp->name, vp->fname, vp->state)) return (1); free(*p); if (!vp->active) @@ -500,7 +513,7 @@ mcf_vcl_inline(struct cli *cli, const char * const *av, void *priv) return; } - mgt_VccCompile(cli, av[2], av[3], 0); + mgt_VccCompile(cli, av[2], av[3], av[4], 0); } void @@ -524,7 +537,7 @@ mcf_vcl_load(struct cli *cli, const char * const *av, void *priv) return; } - mgt_VccCompile(cli, av[2], vcl, 0); + mgt_VccCompile(cli, av[2], vcl, av[4], 0); free(vcl); } From phk at FreeBSD.org Sat Mar 7 13:32:39 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 07 Mar 2015 14:32:39 +0100 Subject: [master] d30ea85 Also update the CLI command definitions Message-ID: commit d30ea85ffd586a9e1480de64e494a17a647e244f Author: Poul-Henning Kamp Date: Sat Mar 7 11:39:37 2015 +0000 Also update the CLI command definitions diff --git a/include/vcli.h b/include/vcli.h index 19dace3..5bc604c 100644 --- a/include/vcli.h +++ b/include/vcli.h @@ -60,15 +60,15 @@ #define CLI_VCL_LOAD \ "vcl.load", \ - "vcl.load ", \ + "vcl.load [*auto,cold,warm]", \ "\tCompile and load the VCL file under the name provided.", \ - 2, 2 + 2, 3 #define CLI_VCL_INLINE \ "vcl.inline", \ - "vcl.inline ", \ + "vcl.inline [*auto,cold,warm]", \ "\tCompile and load the VCL data under the name provided.", \ - 2, 2 + 2, 3 #define CLI_VCL_DISCARD \ "vcl.discard", \ From phk at FreeBSD.org Sat Mar 7 13:32:39 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 07 Mar 2015 14:32:39 +0100 Subject: [master] 1273785 Split the VCL list/state management from the VCC compiler execution. Message-ID: commit 12737854d2ec7cb5a6447346945c805b87c53a79 Author: Poul-Henning Kamp Date: Sat Mar 7 12:44:57 2015 +0000 Split the VCL list/state management from the VCC compiler execution. diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am index e619d33..94b6aa4 100644 --- a/bin/varnishd/Makefile.am +++ b/bin/varnishd/Makefile.am @@ -77,6 +77,7 @@ varnishd_SOURCES = \ mgt/mgt_pool.c \ mgt/mgt_shmem.c \ mgt/mgt_vcc.c \ + mgt/mgt_vcl.c \ storage/stevedore.c \ storage/stevedore_mgt.c \ storage/stevedore_utils.c \ diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 551c689..8428b55 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -141,7 +141,10 @@ void STV_Config(const char *spec); void STV_Config_Transient(void); /* mgt_vcc.c */ +char *mgt_VccCompile(struct cli *cli, const char *vclname, const char *vclsrc, int C_flag); void mgt_vcc_init(void); + +void mgt_vcl_init(void); void mgt_vcc_default(struct cli *, const char *b_arg, const char *vclsrc, int Cflag); int mgt_push_vcls_and_start(unsigned *status, char **p); diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 2ea0cc6..3a019de 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -615,6 +615,7 @@ main(int argc, char * const *argv) P_arg, strerror(errno)); mgt_vcc_init(); + mgt_vcl_init(); if (b_arg != NULL || f_arg != NULL) { mgt_vcc_default(cli, b_arg, vcl, C_flag); diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index b44a85e..e69d8bf 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -49,16 +49,6 @@ #include "vfil.h" #include "vsub.h" -#include "mgt_cli.h" - -struct vclprog { - VTAILQ_ENTRY(vclprog) list; - char *name; - char *fname; - int active; - char state[8]; -}; - struct vcc_priv { unsigned magic; #define VCC_PRIV_MAGIC 0x70080cb8 @@ -67,8 +57,6 @@ struct vcc_priv { char *libfile; }; -static VTAILQ_HEAD(, vclprog) vclhead = VTAILQ_HEAD_INITIALIZER(vclhead); - char *mgt_cc_cmd; const char *mgt_vcl_dir; const char *mgt_vmod_dir; @@ -84,66 +72,6 @@ static const char * const builtin_vcl = #include "builtin_vcl.h" "" ; -/*--------------------------------------------------------------------*/ - -static void -mgt_vcc_add(const char *name, const char *libfile, const char *state) -{ - struct vclprog *vp; - - vp = calloc(sizeof *vp, 1); - XXXAN(vp); - REPLACE(vp->name, name); - REPLACE(vp->fname, libfile); - bprintf(vp->state, "%s", state); - if (VTAILQ_EMPTY(&vclhead)) - vp->active = 1; - VTAILQ_INSERT_TAIL(&vclhead, vp, list); -} - -static void -mgt_vcc_del(struct vclprog *vp) -{ - VTAILQ_REMOVE(&vclhead, vp, list); - printf("unlink %s\n", vp->fname); - XXXAZ(unlink(vp->fname)); - free(vp->fname); - free(vp->name); - free(vp); -} - -static struct vclprog * -mgt_vcc_byname(const char *name) -{ - struct vclprog *vp; - - VTAILQ_FOREACH(vp, &vclhead, list) - if (!strcmp(name, vp->name)) - return (vp); - return (NULL); -} - - -static int -mgt_vcc_delbyname(const char *name) -{ - struct vclprog *vp; - - vp = mgt_vcc_byname(name); - if (vp != NULL) { - mgt_vcc_del(vp); - return (0); - } - return (1); -} - -int -mgt_has_vcl(void) -{ - - return (!VTAILQ_EMPTY(&vclhead)); -} - /*-------------------------------------------------------------------- * Invoke system VCC compiler in a sub-process */ @@ -338,27 +266,16 @@ mgt_vcc_compile(struct vcc_priv *vp, struct vsb *sb, int C_flag) /*--------------------------------------------------------------------*/ -static void +char * mgt_VccCompile(struct cli *cli, const char *vclname, const char *vclsrc, - const char *state, int C_flag) + int C_flag) { struct vcc_priv vp; struct vsb *sb; unsigned status; - char *p; AN(cli); - if (state == NULL) - state = "auto"; - - if (strcmp(state, "auto") && - strcmp(state, "cold") && strcmp(state, "warm")) { - VCLI_Out(cli, "State must be one of auto, cold or warm."); - VCLI_SetResult(cli, CLIS_PARAM); - return; - } - sb = VSB_new_auto(); XXXAN(sb); @@ -394,245 +311,21 @@ mgt_VccCompile(struct cli *cli, const char *vclname, const char *vclsrc, VCLI_Out(cli, "VCL compilation failed"); VCLI_SetResult(cli, CLIS_PARAM); } - return; + return(NULL); } VCLI_Out(cli, "VCL compiled.\n"); - if (child_pid < 0) { - mgt_vcc_add(vclname, vp.libfile, state); - free(vp.libfile); - return; - } - - if (!mgt_cli_askchild(&status, &p, - "vcl.load %s %s %s\n", vclname, vp.libfile, state)) { - mgt_vcc_add(vclname, vp.libfile, state); - free(vp.libfile); - free(p); - return; - } - - VCLI_Out(cli, "%s", p); - free(p); - VCLI_SetResult(cli, CLIS_PARAM); - (void)unlink(vp.libfile); - free(vp.libfile); + return (vp.libfile); } /*--------------------------------------------------------------------*/ void -mgt_vcc_default(struct cli *cli, const char *b_arg, const char *vclsrc, - int C_flag) -{ - char buf[BUFSIZ]; - - if (b_arg == NULL) { - AN(vclsrc); - mgt_VccCompile(cli, "boot", vclsrc, NULL, C_flag); - return; - } - - AZ(vclsrc); - bprintf(buf, - "vcl 4.0;\n" - "backend default {\n" - " .host = \"%s\";\n" - "}\n", b_arg); - mgt_VccCompile(cli, "boot", buf, NULL, C_flag); -} - -/*--------------------------------------------------------------------*/ - -int -mgt_push_vcls_and_start(unsigned *status, char **p) -{ - struct vclprog *vp; - - VTAILQ_FOREACH(vp, &vclhead, list) { - if (mgt_cli_askchild(status, p, - "vcl.load \"%s\" %s %s\n", vp->name, vp->fname, vp->state)) - return (1); - free(*p); - if (!vp->active) - continue; - if (mgt_cli_askchild(status, p, - "vcl.use \"%s\"\n", vp->name)) - return (1); - free(*p); - } - if (mgt_cli_askchild(status, p, "start\n")) - return (1); - free(*p); - *p = NULL; - return (0); -} - -/*--------------------------------------------------------------------*/ - -static void -mgt_vcc_atexit(void) -{ - struct vclprog *vp; - - if (getpid() != mgt_pid) - return; - while (1) { - vp = VTAILQ_FIRST(&vclhead); - if (vp == NULL) - break; - (void)unlink(vp->fname); - VTAILQ_REMOVE(&vclhead, vp, list); - } -} - -void mgt_vcc_init(void) { vcc = VCC_New(); AN(vcc); VCC_Builtin_VCL(vcc, builtin_vcl); - AZ(atexit(mgt_vcc_atexit)); -} - -/*--------------------------------------------------------------------*/ - -void -mcf_vcl_inline(struct cli *cli, const char * const *av, void *priv) -{ - struct vclprog *vp; - - (void)priv; - - vp = mgt_vcc_byname(av[2]); - if (vp != NULL) { - VCLI_Out(cli, "Already a VCL program named %s", av[2]); - VCLI_SetResult(cli, CLIS_PARAM); - return; - } - - mgt_VccCompile(cli, av[2], av[3], av[4], 0); -} - -void -mcf_vcl_load(struct cli *cli, const char * const *av, void *priv) -{ - char *vcl; - struct vclprog *vp; - - (void)priv; - vp = mgt_vcc_byname(av[2]); - if (vp != NULL) { - VCLI_Out(cli, "Already a VCL program named %s", av[2]); - VCLI_SetResult(cli, CLIS_PARAM); - return; - } - - vcl = VFIL_readfile(mgt_vcl_dir, av[3], NULL); - if (vcl == NULL) { - VCLI_Out(cli, "Cannot open '%s'", av[3]); - VCLI_SetResult(cli, CLIS_PARAM); - return; - } - - mgt_VccCompile(cli, av[2], vcl, av[4], 0); - free(vcl); -} - -static struct vclprog * -mcf_find_vcl(struct cli *cli, const char *name) -{ - struct vclprog *vp; - - vp = mgt_vcc_byname(name); - if (vp != NULL) - return (vp); - VCLI_SetResult(cli, CLIS_PARAM); - VCLI_Out(cli, "No configuration named %s known.", name); - return (NULL); -} - -void -mcf_vcl_use(struct cli *cli, const char * const *av, void *priv) -{ - unsigned status; - char *p = NULL; - struct vclprog *vp; - - (void)priv; - vp = mcf_find_vcl(cli, av[2]); - if (vp == NULL) - return; - if (vp->active != 0) - return; - if (child_pid >= 0 && - mgt_cli_askchild(&status, &p, "vcl.use %s\n", av[2])) { - VCLI_SetResult(cli, status); - VCLI_Out(cli, "%s", p); - } else { - VCLI_Out(cli, "VCL '%s' now active", av[2]); - vp->active = 2; - VTAILQ_FOREACH(vp, &vclhead, list) { - if (vp->active == 1) - vp->active = 0; - else if (vp->active == 2) - vp->active = 1; - } - } - free(p); -} - -void -mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv) -{ - unsigned status; - char *p = NULL; - struct vclprog *vp; - - (void)priv; - vp = mcf_find_vcl(cli, av[2]); - if (vp != NULL && vp->active) { - VCLI_SetResult(cli, CLIS_PARAM); - VCLI_Out(cli, "Cannot discard active VCL program\n"); - } else if (vp != NULL) { - if (child_pid >= 0 && - mgt_cli_askchild(&status, &p, - "vcl.discard %s\n", av[2])) { - VCLI_SetResult(cli, status); - VCLI_Out(cli, "%s", p); - } else { - AZ(mgt_vcc_delbyname(av[2])); - } - } - free(p); -} - -void -mcf_vcl_list(struct cli *cli, const char * const *av, void *priv) -{ - unsigned status; - char *p; - const char *flg; - struct vclprog *vp; - - (void)av; - (void)priv; - if (child_pid >= 0) { - if (!mgt_cli_askchild(&status, &p, "vcl.list\n")) { - VCLI_SetResult(cli, status); - VCLI_Out(cli, "%s", p); - } - free(p); - } else { - VTAILQ_FOREACH(vp, &vclhead, list) { - if (vp->active) { - flg = "active"; - } else - flg = "available"; - VCLI_Out(cli, "%-10s %6s %s\n", - flg, "N/A", vp->name); - } - } } diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c new file mode 100644 index 0000000..abd805a --- /dev/null +++ b/bin/varnishd/mgt/mgt_vcl.c @@ -0,0 +1,381 @@ +/*- + * Copyright (c) 2006 Verdens Gang AS + * Copyright (c) 2006-2015 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * VCL compiler stuff + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include + +#include "mgt/mgt.h" + +#include "vcl.h" +#include "vcli.h" +#include "vcli_priv.h" +#include "vfil.h" + +#include "mgt_cli.h" + +struct vclprog { + VTAILQ_ENTRY(vclprog) list; + char *name; + char *fname; + int active; + char state[8]; +}; + +static VTAILQ_HEAD(, vclprog) vclhead = VTAILQ_HEAD_INITIALIZER(vclhead); + + +/*--------------------------------------------------------------------*/ + +static void +mgt_vcc_add(const char *name, const char *libfile, const char *state) +{ + struct vclprog *vp; + + vp = calloc(sizeof *vp, 1); + XXXAN(vp); + REPLACE(vp->name, name); + REPLACE(vp->fname, libfile); + bprintf(vp->state, "%s", state); + if (VTAILQ_EMPTY(&vclhead)) + vp->active = 1; + VTAILQ_INSERT_TAIL(&vclhead, vp, list); +} + +static void +mgt_vcc_del(struct vclprog *vp) +{ + VTAILQ_REMOVE(&vclhead, vp, list); + printf("unlink %s\n", vp->fname); + XXXAZ(unlink(vp->fname)); + free(vp->fname); + free(vp->name); + free(vp); +} + +static struct vclprog * +mgt_vcc_byname(const char *name) +{ + struct vclprog *vp; + + VTAILQ_FOREACH(vp, &vclhead, list) + if (!strcmp(name, vp->name)) + return (vp); + return (NULL); +} + + +static int +mgt_vcc_delbyname(const char *name) +{ + struct vclprog *vp; + + vp = mgt_vcc_byname(name); + if (vp != NULL) { + mgt_vcc_del(vp); + return (0); + } + return (1); +} + +int +mgt_has_vcl(void) +{ + + return (!VTAILQ_EMPTY(&vclhead)); +} + +/*--------------------------------------------------------------------*/ + +static void +mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc, + const char *state, int C_flag) +{ + unsigned status; + char *lib, *p; + + AN(cli); + + if (state == NULL) + state = "auto"; + + if (strcmp(state, "auto") && + strcmp(state, "cold") && strcmp(state, "warm")) { + VCLI_Out(cli, "State must be one of auto, cold or warm."); + VCLI_SetResult(cli, CLIS_PARAM); + return; + } + + lib = mgt_VccCompile(cli, vclname, vclsrc, C_flag); + if (lib == NULL) + return; + + VCLI_Out(cli, "VCL compiled.\n"); + + if (child_pid < 0) { + mgt_vcc_add(vclname, lib, state); + free(lib); + return; + } + + if (!mgt_cli_askchild(&status, &p, + "vcl.load %s %s %s\n", vclname, lib, state)) { + mgt_vcc_add(vclname, lib, state); + free(lib); + free(p); + return; + } + + VCLI_Out(cli, "%s", p); + free(p); + VCLI_SetResult(cli, CLIS_PARAM); + (void)unlink(lib); + free(lib); +} + +/*--------------------------------------------------------------------*/ + +void +mgt_vcc_default(struct cli *cli, const char *b_arg, const char *vclsrc, + int C_flag) +{ + char buf[BUFSIZ]; + + if (b_arg == NULL) { + AN(vclsrc); + mgt_new_vcl(cli, "boot", vclsrc, NULL, C_flag); + return; + } + + AZ(vclsrc); + bprintf(buf, + "vcl 4.0;\n" + "backend default {\n" + " .host = \"%s\";\n" + "}\n", b_arg); + mgt_new_vcl(cli, "boot", buf, NULL, C_flag); +} + +/*--------------------------------------------------------------------*/ + +int +mgt_push_vcls_and_start(unsigned *status, char **p) +{ + struct vclprog *vp; + + VTAILQ_FOREACH(vp, &vclhead, list) { + if (mgt_cli_askchild(status, p, + "vcl.load \"%s\" %s %s\n", vp->name, vp->fname, vp->state)) + return (1); + free(*p); + if (!vp->active) + continue; + if (mgt_cli_askchild(status, p, + "vcl.use \"%s\"\n", vp->name)) + return (1); + free(*p); + } + if (mgt_cli_askchild(status, p, "start\n")) + return (1); + free(*p); + *p = NULL; + return (0); +} + +/*--------------------------------------------------------------------*/ + +static void +mgt_vcl_atexit(void) +{ + struct vclprog *vp; + + if (getpid() != mgt_pid) + return; + while (1) { + vp = VTAILQ_FIRST(&vclhead); + if (vp == NULL) + break; + (void)unlink(vp->fname); + VTAILQ_REMOVE(&vclhead, vp, list); + } +} + +void +mgt_vcl_init(void) +{ + + AZ(atexit(mgt_vcl_atexit)); +} + +/*--------------------------------------------------------------------*/ + +void +mcf_vcl_inline(struct cli *cli, const char * const *av, void *priv) +{ + struct vclprog *vp; + + (void)priv; + + vp = mgt_vcc_byname(av[2]); + if (vp != NULL) { + VCLI_Out(cli, "Already a VCL program named %s", av[2]); + VCLI_SetResult(cli, CLIS_PARAM); + return; + } + + mgt_new_vcl(cli, av[2], av[3], av[4], 0); +} + +void +mcf_vcl_load(struct cli *cli, const char * const *av, void *priv) +{ + char *vcl; + struct vclprog *vp; + + (void)priv; + vp = mgt_vcc_byname(av[2]); + if (vp != NULL) { + VCLI_Out(cli, "Already a VCL program named %s", av[2]); + VCLI_SetResult(cli, CLIS_PARAM); + return; + } + + vcl = VFIL_readfile(mgt_vcl_dir, av[3], NULL); + if (vcl == NULL) { + VCLI_Out(cli, "Cannot open '%s'", av[3]); + VCLI_SetResult(cli, CLIS_PARAM); + return; + } + + mgt_new_vcl(cli, av[2], vcl, av[4], 0); + free(vcl); +} + +static struct vclprog * +mcf_find_vcl(struct cli *cli, const char *name) +{ + struct vclprog *vp; + + vp = mgt_vcc_byname(name); + if (vp != NULL) + return (vp); + VCLI_SetResult(cli, CLIS_PARAM); + VCLI_Out(cli, "No configuration named %s known.", name); + return (NULL); +} + +void +mcf_vcl_use(struct cli *cli, const char * const *av, void *priv) +{ + unsigned status; + char *p = NULL; + struct vclprog *vp; + + (void)priv; + vp = mcf_find_vcl(cli, av[2]); + if (vp == NULL) + return; + if (vp->active != 0) + return; + if (child_pid >= 0 && + mgt_cli_askchild(&status, &p, "vcl.use %s\n", av[2])) { + VCLI_SetResult(cli, status); + VCLI_Out(cli, "%s", p); + } else { + VCLI_Out(cli, "VCL '%s' now active", av[2]); + vp->active = 2; + VTAILQ_FOREACH(vp, &vclhead, list) { + if (vp->active == 1) + vp->active = 0; + else if (vp->active == 2) + vp->active = 1; + } + } + free(p); +} + +void +mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv) +{ + unsigned status; + char *p = NULL; + struct vclprog *vp; + + (void)priv; + vp = mcf_find_vcl(cli, av[2]); + if (vp != NULL && vp->active) { + VCLI_SetResult(cli, CLIS_PARAM); + VCLI_Out(cli, "Cannot discard active VCL program\n"); + } else if (vp != NULL) { + if (child_pid >= 0 && + mgt_cli_askchild(&status, &p, + "vcl.discard %s\n", av[2])) { + VCLI_SetResult(cli, status); + VCLI_Out(cli, "%s", p); + } else { + AZ(mgt_vcc_delbyname(av[2])); + } + } + free(p); +} + +void +mcf_vcl_list(struct cli *cli, const char * const *av, void *priv) +{ + unsigned status; + char *p; + const char *flg; + struct vclprog *vp; + + (void)av; + (void)priv; + if (child_pid >= 0) { + if (!mgt_cli_askchild(&status, &p, "vcl.list\n")) { + VCLI_SetResult(cli, status); + VCLI_Out(cli, "%s", p); + } + free(p); + } else { + VTAILQ_FOREACH(vp, &vclhead, list) { + if (vp->active) { + flg = "active"; + } else + flg = "available"; + VCLI_Out(cli, "%-10s %6s %s\n", + flg, "N/A", vp->name); + } + } +} From phk at FreeBSD.org Sat Mar 7 13:32:39 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Sat, 07 Mar 2015 14:32:39 +0100 Subject: [master] b57ee0f Add vcl.state CLI command to force vcl state Message-ID: commit b57ee0f7fc28e653d4104b51375f34951a73a61c Author: Poul-Henning Kamp Date: Sat Mar 7 13:01:42 2015 +0000 Add vcl.state CLI command to force vcl state diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index 5267065..6af906f 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -96,6 +96,7 @@ static struct cli_proto cli_proto[] = { { CLI_VCL_LOAD, "", mcf_vcl_load, NULL }, { CLI_VCL_INLINE, "", mcf_vcl_inline, NULL }, { CLI_VCL_USE, "", mcf_vcl_use, NULL }, + { CLI_VCL_STATE, "", mcf_vcl_state, NULL }, { CLI_VCL_DISCARD, "", mcf_vcl_discard, NULL }, { CLI_VCL_LIST, "", mcf_vcl_list, NULL }, { CLI_PARAM_SHOW, "", mcf_param_show, NULL }, diff --git a/bin/varnishd/mgt/mgt_cli.h b/bin/varnishd/mgt/mgt_cli.h index 0782bf6..0210aa1 100644 --- a/bin/varnishd/mgt/mgt_cli.h +++ b/bin/varnishd/mgt/mgt_cli.h @@ -42,6 +42,7 @@ cli_func_t mcf_param_set; cli_func_t mcf_vcl_load; cli_func_t mcf_vcl_inline; cli_func_t mcf_vcl_use; +cli_func_t mcf_vcl_state; cli_func_t mcf_vcl_discard; cli_func_t mcf_vcl_list; diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c index abd805a..8de6583 100644 --- a/bin/varnishd/mgt/mgt_vcl.c +++ b/bin/varnishd/mgt/mgt_vcl.c @@ -298,6 +298,36 @@ mcf_find_vcl(struct cli *cli, const char *name) } void +mcf_vcl_state(struct cli *cli, const char * const *av, void *priv) +{ + struct vclprog *vp; + + (void)priv; + vp = mcf_find_vcl(cli, av[2]); + if (vp == NULL) + return; + + if (!strcmp(vp->state, av[3])) + return; + + if (!strcmp(av[3], "auto")) { + bprintf(vp->state, "%s", "auto"); + } else if (!strcmp(av[3], "cold")) { + if (vp->active) { + VCLI_Out(cli, "Cannot set active VCL cold."); + VCLI_SetResult(cli, CLIS_PARAM); + return; + } + bprintf(vp->state, "%s", "auto"); + } else if (!strcmp(av[3], "warm")) { + bprintf(vp->state, "%s", av[3]); + } else { + VCLI_Out(cli, "State must be one of auto, cold or warm."); + VCLI_SetResult(cli, CLIS_PARAM); + } +} + +void mcf_vcl_use(struct cli *cli, const char * const *av, void *priv) { unsigned status; @@ -374,8 +404,8 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv) flg = "active"; } else flg = "available"; - VCLI_Out(cli, "%-10s %6s %s\n", - flg, "N/A", vp->name); + VCLI_Out(cli, "%-10s %4s/? %6s %s\n", + flg, vp->state, "N/A", vp->name); } } } diff --git a/include/vcli.h b/include/vcli.h index 5bc604c..bd5d726 100644 --- a/include/vcli.h +++ b/include/vcli.h @@ -70,6 +70,12 @@ "\tCompile and load the VCL data under the name provided.", \ 2, 3 +#define CLI_VCL_STATE \ + "vcl.state", \ + "vcl.state [auto,cold,warm]", \ + "\tForce the state of the named configuration.", \ + 2, 2 + #define CLI_VCL_DISCARD \ "vcl.discard", \ "vcl.discard ", \ From phk at FreeBSD.org Mon Mar 9 09:29:33 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 10:29:33 +0100 Subject: [master] 61a7a50 Create the event base early enough that VCL stuff can use it Message-ID: commit 61a7a504a58eda7a623cd191f0551e0252e976e0 Author: Poul-Henning Kamp Date: Mon Mar 9 08:18:09 2015 +0000 Create the event base early enough that VCL stuff can use it diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 3a019de..7864a15 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -411,15 +411,10 @@ main(int argc, char * const *argv) assert(VTIM_parse("Sunday, 06-Nov-94 08:49:37 GMT") == 784111777); assert(VTIM_parse("Sun Nov 6 08:49:37 1994") == 784111777); - /* - * Check that our SHA256 works - */ + /* Check that our SHA256 works */ SHA256_Test(); - /* - * Create a cli for convenience in otherwise CLI functions - */ - + /* Create a cli for convenience in otherwise CLI functions */ INIT_OBJ(cli, CLI_MAGIC); cli[0].sb = VSB_new_auto(); XXXAN(cli[0].sb); @@ -427,7 +422,10 @@ main(int argc, char * const *argv) clilim = 32768; cli[0].limit = &clilim; + /* Various initializations */ VTAILQ_INIT(&heritage.socks); + mgt_evb = vev_new_base(); + AN(mgt_evb); init_params(cli); cli_check(cli); @@ -671,9 +669,6 @@ main(int argc, char * const *argv) mgt_pid = getpid(); /* daemon() changed this */ - mgt_evb = vev_new_base(); - XXXAN(mgt_evb); - if (d_flag) mgt_cli_setup(0, 1, 1, "debug", cli_stdin_close, NULL); From phk at FreeBSD.org Mon Mar 9 09:29:33 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 10:29:33 +0100 Subject: [master] 4ab1271 Add a dummy vcl.state CLI handler Message-ID: commit 4ab1271c729a43c5f771ddd36258276168c75e03 Author: Poul-Henning Kamp Date: Mon Mar 9 08:41:27 2015 +0000 Add a dummy vcl.state CLI handler diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index a83d50c..1b7e25e 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -326,6 +326,17 @@ ccf_config_load(struct cli *cli, const char * const *av, void *priv) } static void __match_proto__(cli_func_t) +ccf_config_state(struct cli *cli, const char * const *av, void *priv) +{ + + AZ(priv); + ASSERT_CLI(); + (void)cli; + (void)av; + return; +} + +static void __match_proto__(cli_func_t) ccf_config_discard(struct cli *cli, const char * const *av, void *priv) { struct vcls *vcl; @@ -488,10 +499,11 @@ VCL_##func##_method(struct VCL_conf *vcl, struct worker *wrk, \ /*--------------------------------------------------------------------*/ static struct cli_proto vcl_cmds[] = { - { CLI_VCL_LOAD, "i", ccf_config_load }, - { CLI_VCL_LIST, "i", ccf_config_list }, - { CLI_VCL_DISCARD, "i", ccf_config_discard }, - { CLI_VCL_USE, "i", ccf_config_use }, + { CLI_VCL_LOAD, "i", ccf_config_load }, + { CLI_VCL_LIST, "i", ccf_config_list }, + { CLI_VCL_STATE, "i", ccf_config_state }, + { CLI_VCL_DISCARD, "i", ccf_config_discard }, + { CLI_VCL_USE, "i", ccf_config_use }, { CLI_VCL_SHOW, "", ccf_config_show }, { NULL } }; From phk at FreeBSD.org Mon Mar 9 09:29:33 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 10:29:33 +0100 Subject: [master] 850d1a0 Add a vcl_cooldown parameter which controls when we switch deactivated VCLs to cold (if they're in "auto" mode). Message-ID: commit 850d1a06ca03235f5435a0a9dc60a304176f4046 Author: Poul-Henning Kamp Date: Mon Mar 9 08:41:51 2015 +0000 Add a vcl_cooldown parameter which controls when we switch deactivated VCLs to cold (if they're in "auto" mode). diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h index cdb8646..f5f9450 100644 --- a/bin/varnishd/common/params.h +++ b/bin/varnishd/common/params.h @@ -198,6 +198,8 @@ struct params { double critbit_cooloff; + double vcl_cooldown; + double shortlived; struct vre_limits vre_limits; diff --git a/bin/varnishd/mgt/mgt_param_tbl.c b/bin/varnishd/mgt/mgt_param_tbl.c index e57a68f..e705a47 100644 --- a/bin/varnishd/mgt/mgt_param_tbl.c +++ b/bin/varnishd/mgt/mgt_param_tbl.c @@ -532,7 +532,12 @@ struct parspec mgt_parspec[] = { 0, VARNISH_VMOD_DIR, NULL }, - + { "vcl_cooldown", tweak_timeout, &mgt_param.vcl_cooldown, + "0", NULL, + "How long time a VCL is kept warm after being replaced as the" + " active VCL. (Granularity approximately 30 seconds.)", + 0, + "600", "seconds" }, { "vcc_err_unref", tweak_bool, &mgt_vcc_err_unref, NULL, NULL, "Unreferenced VCL objects result in error.", From phk at FreeBSD.org Mon Mar 9 09:29:33 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 10:29:33 +0100 Subject: [master] db5fd14 Add the management process logic for handling VCL state. Message-ID: commit db5fd145c1fab360929cf5dec6133e5aed52af80 Author: Poul-Henning Kamp Date: Mon Mar 9 08:42:58 2015 +0000 Add the management process logic for handling VCL state. diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c index 8de6583..0c8dc08 100644 --- a/bin/varnishd/mgt/mgt_vcl.c +++ b/bin/varnishd/mgt/mgt_vcl.c @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * VCL compiler stuff + * VCL management stuff */ #include "config.h" @@ -39,11 +39,14 @@ #include #include "mgt/mgt.h" +#include "common/params.h" #include "vcl.h" #include "vcli.h" #include "vcli_priv.h" +#include "vev.h" #include "vfil.h" +#include "vtim.h" #include "mgt_cli.h" @@ -52,7 +55,9 @@ struct vclprog { char *name; char *fname; int active; + int warm; char state[8]; + double go_cold; }; static VTAILQ_HEAD(, vclprog) vclhead = VTAILQ_HEAD_INITIALIZER(vclhead); @@ -60,8 +65,8 @@ static VTAILQ_HEAD(, vclprog) vclhead = VTAILQ_HEAD_INITIALIZER(vclhead); /*--------------------------------------------------------------------*/ -static void -mgt_vcc_add(const char *name, const char *libfile, const char *state) +static struct vclprog * +mgt_vcl_add(const char *name, const char *libfile, const char *state) { struct vclprog *vp; @@ -69,14 +74,21 @@ mgt_vcc_add(const char *name, const char *libfile, const char *state) XXXAN(vp); REPLACE(vp->name, name); REPLACE(vp->fname, libfile); + if (strcmp(state, "cold")) + vp->warm = 1; + else + state = "auto"; + bprintf(vp->state, "%s", state); + if (VTAILQ_EMPTY(&vclhead)) vp->active = 1; VTAILQ_INSERT_TAIL(&vclhead, vp, list); + return (vp); } static void -mgt_vcc_del(struct vclprog *vp) +mgt_vcl_del(struct vclprog *vp) { VTAILQ_REMOVE(&vclhead, vp, list); printf("unlink %s\n", vp->fname); @@ -87,7 +99,7 @@ mgt_vcc_del(struct vclprog *vp) } static struct vclprog * -mgt_vcc_byname(const char *name) +mgt_vcl_byname(const char *name) { struct vclprog *vp; @@ -99,13 +111,13 @@ mgt_vcc_byname(const char *name) static int -mgt_vcc_delbyname(const char *name) +mgt_vcl_delbyname(const char *name) { struct vclprog *vp; - vp = mgt_vcc_byname(name); + vp = mgt_vcl_byname(name); if (vp != NULL) { - mgt_vcc_del(vp); + mgt_vcl_del(vp); return (0); } return (1); @@ -118,6 +130,29 @@ mgt_has_vcl(void) return (!VTAILQ_EMPTY(&vclhead)); } +static void +mgt_vcl_setstate(struct vclprog *vp, int warm) +{ + unsigned status; + char *p; + + if (vp->warm == warm) + return; + + vp->warm = warm; + + if (vp->warm == 0) + vp->go_cold = 0; + + if (child_pid < 0) + return; + + AZ(mgt_cli_askchild(&status, &p, "vcl.state %s %d%s\n", + vp->name, vp->warm, vp->state)); + + free(p); +} + /*--------------------------------------------------------------------*/ static void @@ -126,6 +161,7 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc, { unsigned status; char *lib, *p; + struct vclprog *vp; AN(cli); @@ -143,27 +179,22 @@ mgt_new_vcl(struct cli *cli, const char *vclname, const char *vclsrc, if (lib == NULL) return; - VCLI_Out(cli, "VCL compiled.\n"); + vp = mgt_vcl_add(vclname, lib, state); + free(lib); - if (child_pid < 0) { - mgt_vcc_add(vclname, lib, state); - free(lib); + if (child_pid < 0) return; - } - if (!mgt_cli_askchild(&status, &p, - "vcl.load %s %s %s\n", vclname, lib, state)) { - mgt_vcc_add(vclname, lib, state); - free(lib); + if (!mgt_cli_askchild(&status, &p, "vcl.load %s %s %d%s\n", + vp->name, vp->fname, vp->warm, vp->state)) { free(p); return; } + mgt_vcl_del(vp); VCLI_Out(cli, "%s", p); free(p); VCLI_SetResult(cli, CLIS_PARAM); - (void)unlink(lib); - free(lib); } /*--------------------------------------------------------------------*/ @@ -198,7 +229,8 @@ mgt_push_vcls_and_start(unsigned *status, char **p) VTAILQ_FOREACH(vp, &vclhead, list) { if (mgt_cli_askchild(status, p, - "vcl.load \"%s\" %s %s\n", vp->name, vp->fname, vp->state)) + "vcl.load \"%s\" %s %d%s\n", + vp->name, vp->fname, vp->warm, vp->state)) return (1); free(*p); if (!vp->active) @@ -217,31 +249,6 @@ mgt_push_vcls_and_start(unsigned *status, char **p) /*--------------------------------------------------------------------*/ -static void -mgt_vcl_atexit(void) -{ - struct vclprog *vp; - - if (getpid() != mgt_pid) - return; - while (1) { - vp = VTAILQ_FIRST(&vclhead); - if (vp == NULL) - break; - (void)unlink(vp->fname); - VTAILQ_REMOVE(&vclhead, vp, list); - } -} - -void -mgt_vcl_init(void) -{ - - AZ(atexit(mgt_vcl_atexit)); -} - -/*--------------------------------------------------------------------*/ - void mcf_vcl_inline(struct cli *cli, const char * const *av, void *priv) { @@ -249,7 +256,7 @@ mcf_vcl_inline(struct cli *cli, const char * const *av, void *priv) (void)priv; - vp = mgt_vcc_byname(av[2]); + vp = mgt_vcl_byname(av[2]); if (vp != NULL) { VCLI_Out(cli, "Already a VCL program named %s", av[2]); VCLI_SetResult(cli, CLIS_PARAM); @@ -266,7 +273,7 @@ mcf_vcl_load(struct cli *cli, const char * const *av, void *priv) struct vclprog *vp; (void)priv; - vp = mgt_vcc_byname(av[2]); + vp = mgt_vcl_byname(av[2]); if (vp != NULL) { VCLI_Out(cli, "Already a VCL program named %s", av[2]); VCLI_SetResult(cli, CLIS_PARAM); @@ -289,7 +296,7 @@ mcf_find_vcl(struct cli *cli, const char *name) { struct vclprog *vp; - vp = mgt_vcc_byname(name); + vp = mgt_vcl_byname(name); if (vp != NULL) return (vp); VCLI_SetResult(cli, CLIS_PARAM); @@ -319,8 +326,10 @@ mcf_vcl_state(struct cli *cli, const char * const *av, void *priv) return; } bprintf(vp->state, "%s", "auto"); + mgt_vcl_setstate(vp, 0); } else if (!strcmp(av[3], "warm")) { bprintf(vp->state, "%s", av[3]); + mgt_vcl_setstate(vp, 1); } else { VCLI_Out(cli, "State must be one of auto, cold or warm."); VCLI_SetResult(cli, CLIS_PARAM); @@ -332,7 +341,7 @@ mcf_vcl_use(struct cli *cli, const char * const *av, void *priv) { unsigned status; char *p = NULL; - struct vclprog *vp; + struct vclprog *vp, *vp2; (void)priv; vp = mcf_find_vcl(cli, av[2]); @@ -340,19 +349,21 @@ mcf_vcl_use(struct cli *cli, const char * const *av, void *priv) return; if (vp->active != 0) return; + mgt_vcl_setstate(vp, 1); if (child_pid >= 0 && mgt_cli_askchild(&status, &p, "vcl.use %s\n", av[2])) { VCLI_SetResult(cli, status); VCLI_Out(cli, "%s", p); } else { VCLI_Out(cli, "VCL '%s' now active", av[2]); - vp->active = 2; - VTAILQ_FOREACH(vp, &vclhead, list) { - if (vp->active == 1) - vp->active = 0; - else if (vp->active == 2) - vp->active = 1; + VTAILQ_FOREACH(vp2, &vclhead, list) { + if (vp2->active) { + vp2->active = 0; + vp2->go_cold = VTIM_mono(); + break; + } } + vp->active = 1; } free(p); } @@ -376,7 +387,7 @@ mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv) VCLI_SetResult(cli, status); VCLI_Out(cli, "%s", p); } else { - AZ(mgt_vcc_delbyname(av[2])); + AZ(mgt_vcl_delbyname(av[2])); } } free(p); @@ -404,8 +415,62 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv) flg = "active"; } else flg = "available"; - VCLI_Out(cli, "%-10s %4s/? %6s %s\n", - flg, vp->state, "N/A", vp->name); + VCLI_Out(cli, "%-10s %4s/%s %s\n", flg, vp->state, + vp->warm ? "warm" : "cold", vp->name); } } } + +/*--------------------------------------------------------------------*/ + +static int __match_proto__(vev_cb_f) +mgt_vcl_poker(const struct vev *e, int what) +{ + struct vclprog *vp; + double now = VTIM_mono(); + + (void)e; + (void)what; + VTAILQ_FOREACH(vp, &vclhead, list) { + if (vp->go_cold == 0) + continue; + if (strcmp(vp->state, "auto")) + continue; + if (vp->go_cold + mgt_param.vcl_cooldown < now) + mgt_vcl_setstate(vp, 0); + } + return (0); +} + +/*--------------------------------------------------------------------*/ + +static void +mgt_vcl_atexit(void) +{ + struct vclprog *vp; + + if (getpid() != mgt_pid) + return; + while (1) { + vp = VTAILQ_FIRST(&vclhead); + if (vp == NULL) + break; + (void)unlink(vp->fname); + VTAILQ_REMOVE(&vclhead, vp, list); + } +} + +void +mgt_vcl_init(void) +{ + struct vev *e; + + e = vev_new(); + AN(e); + e->timeout = 23; // random, prime + e->callback = mgt_vcl_poker; + e->name = "vcl poker"; + AZ(vev_add(mgt_evb, e)); + + AZ(atexit(mgt_vcl_atexit)); +} From phk at FreeBSD.org Mon Mar 9 09:29:33 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 10:29:33 +0100 Subject: [master] 0231323 Propagate the vcl state to the child process. Message-ID: commit 023132329dcb6f557bc971653571b2a082107e6e Author: Poul-Henning Kamp Date: Mon Mar 9 09:29:18 2015 +0000 Propagate the vcl state to the child process. diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 1b7e25e..0db8cd8 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -34,6 +34,7 @@ #include "config.h" #include +#include #include #include "cache.h" @@ -49,6 +50,8 @@ struct vcls { VTAILQ_ENTRY(vcls) list; void *dlh; struct VCL_conf conf[1]; + char state[8]; + int warm; }; /* @@ -58,7 +61,6 @@ struct vcls { static VTAILQ_HEAD(, vcls) vcl_head = VTAILQ_HEAD_INITIALIZER(vcl_head); - static struct lock vcl_mtx; static struct vcls *vcl_active; /* protected by vcl_mtx */ @@ -167,8 +169,16 @@ vcl_find(const char *name) return (NULL); } +static void +vcl_set_state(struct vcls *vcl, const char *state) +{ + + vcl->warm = state[0] == '1' ? 1 : 0; + bprintf(vcl->state, "%s", state + 1); +} + static int -VCL_Load(const char *fn, const char *name, struct cli *cli) +VCL_Load(struct cli *cli, const char *name, const char *fn, const char *state) { struct vcls *vcl; struct VCL_conf const *cnf; @@ -184,7 +194,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) } ALLOC_OBJ(vcl, VVCLS_MAGIC); - XXXAN(vcl); + AN(vcl); vcl->dlh = dlopen(fn, RTLD_NOW | RTLD_LOCAL); @@ -234,6 +244,7 @@ VCL_Load(const char *fn, const char *name, struct cli *cli) FREE_OBJ(vcl); return (1); } + vcl_set_state(vcl, state); assert(hand == VCL_RET_OK); VCLI_Out(cli, "Loaded \"%s\" as \"%s\"", fn , name); VTAILQ_INSERT_TAIL(&vcl_head, vcl, list); @@ -307,8 +318,9 @@ ccf_config_list(struct cli *cli, const char * const *av, void *priv) flg = "discarded"; } else flg = "available"; - VCLI_Out(cli, "%-10s %6u %s\n", + VCLI_Out(cli, "%-10s %4s/%s %6u %s\n", flg, + vcl->state, vcl->warm ? "warm" : "cold", vcl->conf->busy, vcl->conf->loaded_name); } @@ -320,7 +332,7 @@ ccf_config_load(struct cli *cli, const char * const *av, void *priv) AZ(priv); ASSERT_CLI(); - if (VCL_Load(av[3], av[2], cli)) + if (VCL_Load(cli, av[2], av[3], av[4])) VCLI_SetResult(cli, CLIS_PARAM); return; } @@ -328,12 +340,16 @@ ccf_config_load(struct cli *cli, const char * const *av, void *priv) static void __match_proto__(cli_func_t) ccf_config_state(struct cli *cli, const char * const *av, void *priv) { + struct vcls *vcl; + (void)cli; AZ(priv); ASSERT_CLI(); - (void)cli; - (void)av; - return; + AN(av[2]); + AN(av[3]); + vcl = vcl_find(av[2]); + AN(vcl); // MGT ensures this + vcl_set_state(vcl, av[3]); } static void __match_proto__(cli_func_t) diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c index 0c8dc08..1795777 100644 --- a/bin/varnishd/mgt/mgt_vcl.c +++ b/bin/varnishd/mgt/mgt_vcl.c @@ -54,14 +54,14 @@ struct vclprog { VTAILQ_ENTRY(vclprog) list; char *name; char *fname; - int active; int warm; char state[8]; double go_cold; }; static VTAILQ_HEAD(, vclprog) vclhead = VTAILQ_HEAD_INITIALIZER(vclhead); - +static struct vclprog *active_vcl; +static struct vev *e_poker; /*--------------------------------------------------------------------*/ @@ -81,8 +81,8 @@ mgt_vcl_add(const char *name, const char *libfile, const char *state) bprintf(vp->state, "%s", state); - if (VTAILQ_EMPTY(&vclhead)) - vp->active = 1; + if (active_vcl == NULL) + active_vcl = vp; VTAILQ_INSERT_TAIL(&vclhead, vp, list); return (vp); } @@ -134,8 +134,17 @@ static void mgt_vcl_setstate(struct vclprog *vp, int warm) { unsigned status; + double now; char *p; + if (warm == -1) { + now = VTIM_mono(); + warm = vp->warm; + if (vp->go_cold > 0 && !strcmp(vp->state, "auto") && + vp->go_cold + mgt_param.vcl_cooldown < now) + warm = 0; + } + if (vp->warm == warm) return; @@ -147,8 +156,11 @@ mgt_vcl_setstate(struct vclprog *vp, int warm) if (child_pid < 0) return; - AZ(mgt_cli_askchild(&status, &p, "vcl.state %s %d%s\n", - vp->name, vp->warm, vp->state)); + /* + * We ignore the result here so we don't croak if the child did. + */ + (void)mgt_cli_askchild(&status, &p, "vcl.state %s %d%s\n", + vp->name, vp->warm, vp->state); free(p); } @@ -227,19 +239,16 @@ mgt_push_vcls_and_start(unsigned *status, char **p) { struct vclprog *vp; + AN(active_vcl); VTAILQ_FOREACH(vp, &vclhead, list) { - if (mgt_cli_askchild(status, p, - "vcl.load \"%s\" %s %d%s\n", + if (mgt_cli_askchild(status, p, "vcl.load \"%s\" %s %d%s\n", vp->name, vp->fname, vp->warm, vp->state)) return (1); free(*p); - if (!vp->active) - continue; - if (mgt_cli_askchild(status, p, - "vcl.use \"%s\"\n", vp->name)) - return (1); - free(*p); } + if (mgt_cli_askchild(status, p, "vcl.use \"%s\"\n", active_vcl->name)) + return (1); + free(*p); if (mgt_cli_askchild(status, p, "start\n")) return (1); free(*p); @@ -319,9 +328,10 @@ mcf_vcl_state(struct cli *cli, const char * const *av, void *priv) if (!strcmp(av[3], "auto")) { bprintf(vp->state, "%s", "auto"); + mgt_vcl_setstate(vp, -1); } else if (!strcmp(av[3], "cold")) { - if (vp->active) { - VCLI_Out(cli, "Cannot set active VCL cold."); + if (vp == active_vcl) { + VCLI_Out(cli, "Cannot set the active VCL cold."); VCLI_SetResult(cli, CLIS_PARAM); return; } @@ -341,13 +351,13 @@ mcf_vcl_use(struct cli *cli, const char * const *av, void *priv) { unsigned status; char *p = NULL; - struct vclprog *vp, *vp2; + struct vclprog *vp; (void)priv; vp = mcf_find_vcl(cli, av[2]); if (vp == NULL) return; - if (vp->active != 0) + if (vp == active_vcl) return; mgt_vcl_setstate(vp, 1); if (child_pid >= 0 && @@ -356,14 +366,9 @@ mcf_vcl_use(struct cli *cli, const char * const *av, void *priv) VCLI_Out(cli, "%s", p); } else { VCLI_Out(cli, "VCL '%s' now active", av[2]); - VTAILQ_FOREACH(vp2, &vclhead, list) { - if (vp2->active) { - vp2->active = 0; - vp2->go_cold = VTIM_mono(); - break; - } - } - vp->active = 1; + if (active_vcl != NULL) + active_vcl->go_cold = VTIM_mono(); + active_vcl = vp; } free(p); } @@ -377,7 +382,7 @@ mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv) (void)priv; vp = mcf_find_vcl(cli, av[2]); - if (vp != NULL && vp->active) { + if (vp == active_vcl) { VCLI_SetResult(cli, CLIS_PARAM); VCLI_Out(cli, "Cannot discard active VCL program\n"); } else if (vp != NULL) { @@ -398,7 +403,6 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv) { unsigned status; char *p; - const char *flg; struct vclprog *vp; (void)av; @@ -411,12 +415,10 @@ mcf_vcl_list(struct cli *cli, const char * const *av, void *priv) free(p); } else { VTAILQ_FOREACH(vp, &vclhead, list) { - if (vp->active) { - flg = "active"; - } else - flg = "available"; - VCLI_Out(cli, "%-10s %4s/%s %s\n", flg, vp->state, - vp->warm ? "warm" : "cold", vp->name); + VCLI_Out(cli, "%-10s %4s/%s %6s %s\n", + vp == active_vcl ? "active" : "available", + vp->state, + vp->warm ? "warm" : "cold", "", vp->name); } } } @@ -427,18 +429,11 @@ static int __match_proto__(vev_cb_f) mgt_vcl_poker(const struct vev *e, int what) { struct vclprog *vp; - double now = VTIM_mono(); (void)e; (void)what; - VTAILQ_FOREACH(vp, &vclhead, list) { - if (vp->go_cold == 0) - continue; - if (strcmp(vp->state, "auto")) - continue; - if (vp->go_cold + mgt_param.vcl_cooldown < now) - mgt_vcl_setstate(vp, 0); - } + VTAILQ_FOREACH(vp, &vclhead, list) + mgt_vcl_setstate(vp, -1); return (0); } @@ -463,14 +458,13 @@ mgt_vcl_atexit(void) void mgt_vcl_init(void) { - struct vev *e; - - e = vev_new(); - AN(e); - e->timeout = 23; // random, prime - e->callback = mgt_vcl_poker; - e->name = "vcl poker"; - AZ(vev_add(mgt_evb, e)); + + e_poker = vev_new(); + AN(e_poker); + e_poker->timeout = 3; // random, prime + e_poker->callback = mgt_vcl_poker; + e_poker->name = "vcl poker"; + AZ(vev_add(mgt_evb, e_poker)); AZ(atexit(mgt_vcl_atexit)); } From daghf at varnish-software.com Mon Mar 9 10:08:49 2015 From: daghf at varnish-software.com (Dag Haavi Finstad) Date: Mon, 09 Mar 2015 11:08:49 +0100 Subject: [master] f573a08 Whitespace Message-ID: commit f573a08c5c0eb24baaa6ea378e47fe69b08224e7 Author: Dag Haavi Finstad Date: Mon Mar 9 11:08:44 2015 +0100 Whitespace diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 183fc7a..fd8291f 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -587,7 +587,7 @@ struct req { enum sess_close doclose; double d_ttl; - ssize_t req_bodybytes; /* Parsed req bodybytes */ + ssize_t req_bodybytes; /* Parsed req bodybytes */ uint16_t err_code; const char *err_reason; From phk at FreeBSD.org Mon Mar 9 10:49:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 11:49:35 +0100 Subject: [master] db01d1a Add an initial coverage test of vcl.state Message-ID: commit db01d1a202d4599c6b7d97be2c334850d37267d5 Author: Poul-Henning Kamp Date: Mon Mar 9 09:34:02 2015 +0000 Add an initial coverage test of vcl.state diff --git a/bin/varnishtest/tests/v00043.vcl b/bin/varnishtest/tests/v00043.vcl new file mode 100644 index 0000000..17e9798 --- /dev/null +++ b/bin/varnishtest/tests/v00043.vcl @@ -0,0 +1,23 @@ +varnishtest "vcl.state coverage tests" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend {} -start +varnish v1 -vcl+backend {} + +varnish v1 -cliok "param.set vcl_cooldown 5" + +varnish v1 -cliok "vcl.list" +varnish v1 -cliok "vcl.use vcl2" +varnish v1 -cliok "vcl.list" +delay 5 +varnish v1 -cliok "vcl.list" +varnish v1 -cliok "vcl.state vcl1 warm" +varnish v1 -cliok "vcl.list" +varnish v1 -cliok "vcl.use vcl1" +varnish v1 -cliok "vcl.use vcl2" +delay 5 +varnish v1 -cliok "vcl.list" From phk at FreeBSD.org Mon Mar 9 10:49:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 11:49:35 +0100 Subject: [master] f9fbfca Set VCL cold before discarding. Message-ID: commit f9fbfca607ef96a143f677a61d1c9930a6ae2af5 Author: Poul-Henning Kamp Date: Mon Mar 9 10:12:24 2015 +0000 Set VCL cold before discarding. diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c index 1795777..125f751 100644 --- a/bin/varnishd/mgt/mgt_vcl.c +++ b/bin/varnishd/mgt/mgt_vcl.c @@ -386,6 +386,7 @@ mcf_vcl_discard(struct cli *cli, const char * const *av, void *priv) VCLI_SetResult(cli, CLIS_PARAM); VCLI_Out(cli, "Cannot discard active VCL program\n"); } else if (vp != NULL) { + mgt_vcl_setstate(vp, 0); if (child_pid >= 0 && mgt_cli_askchild(&status, &p, "vcl.discard %s\n", av[2])) { From phk at FreeBSD.org Mon Mar 9 10:49:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 11:49:35 +0100 Subject: [master] 09628c7 Propagate warm/cold transitions to VCL_EVENTs Message-ID: commit 09628c73d2c2e6ff0ee9bad424d4f554a3819e54 Author: Poul-Henning Kamp Date: Mon Mar 9 10:34:04 2015 +0000 Propagate warm/cold transitions to VCL_EVENTs diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c index 0db8cd8..a5a7da4 100644 --- a/bin/varnishd/cache/cache_vcl.c +++ b/bin/varnishd/cache/cache_vcl.c @@ -172,9 +172,22 @@ vcl_find(const char *name) static void vcl_set_state(struct vcls *vcl, const char *state) { + struct vrt_ctx ctx; + int warm; + unsigned hand = 0; - vcl->warm = state[0] == '1' ? 1 : 0; + assert(state[0] == '0' || state[0] == '1'); + warm = state[0] == '1' ? 1 : 0; bprintf(vcl->state, "%s", state + 1); + if (warm == vcl->warm) + return; + + vcl->warm = warm; + + INIT_OBJ(&ctx, VRT_CTX_MAGIC); + ctx.handling = &hand; + (void)vcl->conf->event_vcl(&ctx, + vcl->warm ? VCL_EVENT_WARM : VCL_EVENT_COLD); } static int @@ -384,6 +397,7 @@ ccf_config_use(struct cli *cli, const char * const *av, void *priv) AZ(priv); vcl = vcl_find(av[2]); AN(vcl); // MGT ensures this + AN(vcl->warm); // MGT ensures this INIT_OBJ(&ctx, VRT_CTX_MAGIC); ctx.handling = &hand; ctx.cli = cli; From nils.goroll at uplex.de Mon Mar 9 13:37:18 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 09 Mar 2015 14:37:18 +0100 Subject: [master] 7acaae6 straighten the vmod PRIV_* doc Message-ID: commit 7acaae626e959330ecedb21bf1bf1a1d4aff49a9 Author: Nils Goroll Date: Mon Mar 9 14:36:50 2015 +0100 straighten the vmod PRIV_* doc diff --git a/doc/sphinx/reference/vmod.rst b/doc/sphinx/reference/vmod.rst index 9209c4c..e0a1d9a 100644 --- a/doc/sphinx/reference/vmod.rst +++ b/doc/sphinx/reference/vmod.rst @@ -234,28 +234,29 @@ It is often useful for library functions to maintain local state, this can be anything from a precompiled regexp to open file descriptors and vast data structures. -The VCL compiler supports three levels of private pointers, "per -call", "per VCL" and "per task". - -"per call" private pointers are useful to cache/store state relative -to the specific call or its arguments, for instance a compiled regular -expression specific to a regsub() statement or a simply caching the -last output of some expensive lookup. - -"per vcl" private pointers are useful for such global state that -applies to all calls in this VCL, for instance flags that determine -if regular expressions are case-sensitive in this vmod or similar. - -"per task" private pointers are useful for state that applies to calls -for either a specific request or a backend request. For instance this -can be the result of a parsed cookie specific to a client. Note that -"per task" contexts are separate for the client side and the backend -side, so use in ``vcl_backend_*`` will yield a different private pointer -from the one used on the client side. +The VCL compiler supports the following private pointers: + +* ``PRIV_CALL`` "per call" private pointers are useful to cache/store + state relative to the specific call or its arguments, for instance a + compiled regular expression specific to a regsub() statement or a + simply caching the last output of some expensive lookup. + +* ``PRIV_VCL`` "per vcl" private pointers are useful for such global + state that applies to all calls in this VCL, for instance flags that + determine if regular expressions are case-sensitive in this vmod or + similar. + +* ``PRIV_TASK`` "per task" private pointers are useful for state that + applies to calls for either a specific request or a backend + request. For instance this can be the result of a parsed cookie + specific to a client. Note that ``PRIV_TASK`` contexts are separate + for the client side and the backend side, so use in + ``vcl_backend_*`` will yield a different private pointer from the + one used on the client side. The way it works in the vmod code, is that a ``struct vmod_priv *`` is -passed to the functions where argument type PRIV_VCL, PRIV_CALL or -PRIV_TASK is specified. +passed to the functions where one of the ``PRIV_*`` argument types is +specified. This structure contains two members:: From nils.goroll at uplex.de Mon Mar 9 15:27:05 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 09 Mar 2015 16:27:05 +0100 Subject: [master] 2b907d8 Add linkage to the top request Message-ID: commit 2b907d8e8adca129d8d395a373d072e0615c148f Author: Nils Goroll Date: Mon Mar 9 15:19:50 2015 +0100 Add linkage to the top request diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index fd8291f..5dd6621 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -561,6 +561,7 @@ struct req { int restarts; int esi_level; + struct req *top; /* esi_level == 0 request */ #define REQ_FLAG(l, r, w, d) unsigned l:1; #include "tbl/req_flags.h" diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c index 821412c..01cbcc2 100644 --- a/bin/varnishd/cache/cache_esi_deliver.c +++ b/bin/varnishd/cache/cache_esi_deliver.c @@ -83,6 +83,13 @@ ved_include(struct req *preq, const char *src, const char *host) VSLb(preq->vsl, SLT_Link, "req %u esi", VXID(req->vsl->wid)); req->esi_level = preq->esi_level + 1; + if (preq->esi_level == 0) { + assert(preq->top == preq); + } else { + CHECK_OBJ_NOTNULL(preq->top, REQ_MAGIC); + req->top = preq->top; + } + HTTP_Copy(req->http0, preq->http0); req->http0->ws = req->ws; diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 0f551da..940d0c0 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -376,6 +376,7 @@ SES_GetReq(const struct worker *wrk, struct sess *sp) AN(req); req->magic = REQ_MAGIC; req->sp = sp; + req->top = req; // esi overrides e = (char*)req + sz; p = (char*)(req + 1); From nils.goroll at uplex.de Mon Mar 9 17:46:54 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 09 Mar 2015 18:46:54 +0100 Subject: [master] 70e143c Fix linkage to the top request Message-ID: commit 70e143c18a2ced2ba3bd117ad49115758c305707 Author: Nils Goroll Date: Mon Mar 9 18:44:47 2015 +0100 Fix linkage to the top request diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c index 01cbcc2..d9764be 100644 --- a/bin/varnishd/cache/cache_esi_deliver.c +++ b/bin/varnishd/cache/cache_esi_deliver.c @@ -83,12 +83,12 @@ ved_include(struct req *preq, const char *src, const char *host) VSLb(preq->vsl, SLT_Link, "req %u esi", VXID(req->vsl->wid)); req->esi_level = preq->esi_level + 1; - if (preq->esi_level == 0) { + if (preq->esi_level == 0) assert(preq->top == preq); - } else { + else CHECK_OBJ_NOTNULL(preq->top, REQ_MAGIC); - req->top = preq->top; - } + + req->top = preq->top; HTTP_Copy(req->http0, preq->http0); From phk at FreeBSD.org Mon Mar 9 19:57:47 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 20:57:47 +0100 Subject: [master] ba9a611 Collaps the backend TCP pools to only identify by {IPv4+IPv6} Message-ID: commit ba9a6117fe0a7ba2a0900b9466ad113500095a1b Author: Poul-Henning Kamp Date: Mon Mar 9 19:57:16 2015 +0000 Collaps the backend TCP pools to only identify by {IPv4+IPv6} diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index 2fa7694..b2bf2ca 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -116,7 +116,7 @@ void VBP_Remove(struct backend *b, struct vrt_backend_probe const *p); void VBP_Use(const struct backend *b, const struct vrt_backend_probe *p); void VBP_Summary(struct cli *cli, const struct vbp_target *vt); -struct tcp_pool *VBT_Ref(const char *name, const struct suckaddr *ip4, +struct tcp_pool *VBT_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6); void VBT_Rel(struct tcp_pool **tpp); int VBT_Open(const struct tcp_pool *tp, double tmo, const struct suckaddr **sa); diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index a9fdd12..fc619c0 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -103,8 +103,7 @@ VBE_AddBackend(const char *vcl, const struct vrt_backend *vb) b->ipv6_addr = vb->ipv6_addr; b->port = vb->port; - b->tcp_pool = VBT_Ref(vb->vcl_name, - vb->ipv4_suckaddr, vb->ipv6_suckaddr); + b->tcp_pool = VBT_Ref(vb->ipv4_suckaddr, vb->ipv6_suckaddr); /* * Copy over the sockaddrs diff --git a/bin/varnishd/cache/cache_backend_tcp.c b/bin/varnishd/cache/cache_backend_tcp.c index 424f276..5b73e57 100644 --- a/bin/varnishd/cache/cache_backend_tcp.c +++ b/bin/varnishd/cache/cache_backend_tcp.c @@ -131,21 +131,18 @@ tcp_handle(struct waited *w, enum wait_event ev, double now) } /*-------------------------------------------------------------------- - * Reference a TCP pool given by {name, ip4, ip6} triplet. Create if - * it doesn't exist already. + * Reference a TCP pool given by {ip4, ip6} pair. Create if it + * doesn't exist already. */ struct tcp_pool * -VBT_Ref(const char *name, const struct suckaddr *ip4, - const struct suckaddr *ip6) +VBT_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6) { struct tcp_pool *tp; ASSERT_CLI(); VTAILQ_FOREACH(tp, &pools, list) { assert(tp->refcnt > 0); - if (strcmp(tp->name, name)) - continue; if (ip4 == NULL) { if (tp->ip4 != NULL) continue; @@ -170,7 +167,6 @@ VBT_Ref(const char *name, const struct suckaddr *ip4, ALLOC_OBJ(tp, TCP_POOL_MAGIC); AN(tp); - REPLACE(tp->name, name); if (ip4 != NULL) tp->ip4 = VSA_Clone(ip4); if (ip6 != NULL) From phk at FreeBSD.org Mon Mar 9 20:57:21 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 21:57:21 +0100 Subject: [master] 36453ca Now that struct backend is no longer shared, we can dispose of an entire level of indirection in the backend probe code. Message-ID: commit 36453ca0d6168efb68567392d4f0b9295bf93451 Author: Poul-Henning Kamp Date: Mon Mar 9 20:56:51 2015 +0000 Now that struct backend is no longer shared, we can dispose of an entire level of indirection in the backend probe code. diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 0785792..762ea69 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -325,18 +325,13 @@ VRT_event_vbe(VRT_CTX, enum vcl_event_e ev, const struct director *d, struct backend *be; ASSERT_CLI(); + (void)ev; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC); CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC); assert(d->priv2 == vrt); CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC); - - if (vrt->probe == NULL) - return; - - if (ev == VCL_EVENT_USE) - VBP_Use(be, vrt->probe); } void @@ -358,7 +353,7 @@ VRT_fini_vbe(VRT_CTX, struct director **dp, const struct vrt_backend *vrt) CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC); if (vrt->probe != NULL) - VBP_Remove(be, vrt->probe); + VBP_Remove(be); VBE_DeleteBackend(be); free(d->vcl_name); diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index b2bf2ca..f1faa97 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -112,8 +112,7 @@ void VBE_DeleteBackend(struct backend *); /* cache_backend_poll.c */ void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p, const char *hosthdr); -void VBP_Remove(struct backend *b, struct vrt_backend_probe const *p); -void VBP_Use(const struct backend *b, const struct vrt_backend_probe *p); +void VBP_Remove(struct backend *b); void VBP_Summary(struct cli *cli, const struct vbp_target *vt); struct tcp_pool *VBT_Ref(const struct suckaddr *ip4, diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c index 9564e4f..21ae52b 100644 --- a/bin/varnishd/cache/cache_backend_poll.c +++ b/bin/varnishd/cache/cache_backend_poll.c @@ -53,26 +53,15 @@ /* Default averaging rate, we want something pretty responsive */ #define AVG_RATE 4 -struct vbp_vcl { - unsigned magic; -#define VBP_VCL_MAGIC 0x70829764 - - VTAILQ_ENTRY(vbp_vcl) list; - const struct vrt_backend_probe *probep; - struct vrt_backend_probe probe; - const char *hosthdr; -}; - struct vbp_target { unsigned magic; #define VBP_TARGET_MAGIC 0x6b7cb656 struct backend *backend; - VTAILQ_HEAD( ,vbp_vcl) vcls; struct vrt_backend_probe probe; + int stop; - struct vsb *vsb; char *req; int req_len; @@ -95,8 +84,6 @@ struct vbp_target { static VTAILQ_HEAD(, vbp_target) vbp_list = VTAILQ_HEAD_INITIALIZER(vbp_list); -static struct lock vbp_mtx; - /*-------------------------------------------------------------------- * Poke one backend, once, but possibly at both IPv4 and IPv6 addresses. * @@ -275,30 +262,6 @@ vbp_has_poked(struct vbp_target *vt) } /*-------------------------------------------------------------------- - * Build request from probe spec - */ - -static void -vbp_build_req(struct vsb *vsb, const struct vbp_vcl *vcl) -{ - - XXXAN(vsb); - XXXAN(vcl); - VSB_clear(vsb); - if(vcl->probe.request != NULL) { - VSB_cat(vsb, vcl->probe.request); - } else { - VSB_printf(vsb, "GET %s HTTP/1.1\r\n", - vcl->probe.url != NULL ? vcl->probe.url : "/"); - if (vcl->hosthdr != NULL) - VSB_printf(vsb, "Host: %s\r\n", vcl->hosthdr); - VSB_printf(vsb, "Connection: close\r\n"); - VSB_printf(vsb, "\r\n"); - } - AZ(VSB_finish(vsb)); -} - -/*-------------------------------------------------------------------- * One thread per backend to be poked. */ @@ -306,23 +269,13 @@ static void * vbp_wrk_poll_backend(void *priv) { struct vbp_target *vt; - struct vbp_vcl *vcl = NULL; THR_SetName("backend poll"); CAST_OBJ_NOTNULL(vt, priv, VBP_TARGET_MAGIC); while (!vt->stop) { - Lck_Lock(&vbp_mtx); - if (VTAILQ_FIRST(&vt->vcls) != vcl) { - vcl = VTAILQ_FIRST(&vt->vcls); - vbp_build_req(vt->vsb, vcl); - vt->probe = vcl->probe; - } - Lck_Unlock(&vbp_mtx); - - vt->req = VSB_data(vt->vsb); - vt->req_len = VSB_len(vt->vsb); + AN(vt->req); assert(vt->req_len > 0); vbp_start_poke(vt); @@ -410,41 +363,59 @@ static struct cli_proto debug_cmds[] = { }; /*-------------------------------------------------------------------- - * A new VCL wants to probe this backend, + * Build request from probe spec */ -static struct vbp_vcl * -vbp_new_vcl(const struct vrt_backend_probe *p, const char *hosthdr) +static void +vbp_build_req(struct vbp_target *vt, const char *hosthdr) { - struct vbp_vcl *vcl; - - ALLOC_OBJ(vcl, VBP_VCL_MAGIC); - XXXAN(vcl); - vcl->probep = p; - vcl->probe = *p; - vcl->hosthdr = hosthdr; - - /* - * Sanitize and insert defaults - * XXX: we could make these defaults parameters - */ - if (vcl->probe.timeout == 0.0) - vcl->probe.timeout = 2.0; - if (vcl->probe.interval == 0.0) - vcl->probe.interval = 5.0; - if (vcl->probe.window == 0) - vcl->probe.window = 8; - if (vcl->probe.threshold == 0) - vcl->probe.threshold = 3; - if (vcl->probe.exp_status == 0) - vcl->probe.exp_status = 200; - - if (vcl->probe.initial == ~0U) - vcl->probe.initial = vcl->probe.threshold - 1; - - if (vcl->probe.initial > vcl->probe.threshold) - vcl->probe.initial = vcl->probe.threshold; - return (vcl); + struct vsb *vsb; + + vsb = VSB_new_auto(); + AN(vsb); + VSB_clear(vsb); + if(vt->probe.request != NULL) { + VSB_cat(vsb, vt->probe.request); + } else { + VSB_printf(vsb, "GET %s HTTP/1.1\r\n", + vt->probe.url != NULL ? vt->probe.url : "/"); + if (hosthdr != NULL) + VSB_printf(vsb, "Host: %s\r\n", hosthdr); + VSB_printf(vsb, "Connection: close\r\n"); + VSB_printf(vsb, "\r\n"); + } + AZ(VSB_finish(vsb)); + vt->req = strdup(VSB_data(vsb)); + AN(vt->req); + vt->req_len = VSB_len(vsb); + VSB_delete(vsb); +} + +/*-------------------------------------------------------------------- + * Sanitize and set defaults + * XXX: we could make these defaults parameters + */ + +static void +vbp_set_defaults(struct vbp_target *vt) +{ + + if (vt->probe.timeout == 0.0) + vt->probe.timeout = 2.0; + if (vt->probe.interval == 0.0) + vt->probe.interval = 5.0; + if (vt->probe.window == 0) + vt->probe.window = 8; + if (vt->probe.threshold == 0) + vt->probe.threshold = 3; + if (vt->probe.exp_status == 0) + vt->probe.exp_status = 200; + + if (vt->probe.initial == ~0U) + vt->probe.initial = vt->probe.threshold - 1; + + if (vt->probe.initial > vt->probe.threshold) + vt->probe.initial = vt->probe.threshold; } /*-------------------------------------------------------------------- @@ -456,115 +427,54 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, const char *hosthdr) { struct vbp_target *vt; - struct vbp_vcl *vcl; - int startthread = 0; unsigned u; ASSERT_CLI(); CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); CHECK_OBJ_NOTNULL(p, VRT_BACKEND_PROBE_MAGIC); - if (b->probe == NULL) { - ALLOC_OBJ(vt, VBP_TARGET_MAGIC); - XXXAN(vt); - VTAILQ_INIT(&vt->vcls); - vt->backend = b; - vt->vsb = VSB_new_auto(); - XXXAN(vt->vsb); - b->probe = vt; - startthread = 1; - VTAILQ_INSERT_TAIL(&vbp_list, vt, list); - } else { - vt = b->probe; - } - - VTAILQ_FOREACH(vcl, &vt->vcls, list) - assert(vcl->probep != p); + AZ(b->probe); - vcl = vbp_new_vcl(p, hosthdr); - Lck_Lock(&vbp_mtx); - VTAILQ_INSERT_TAIL(&vt->vcls, vcl, list); - Lck_Unlock(&vbp_mtx); + ALLOC_OBJ(vt, VBP_TARGET_MAGIC); + XXXAN(vt); + vt->backend = b; + b->probe = vt; + VTAILQ_INSERT_TAIL(&vbp_list, vt, list); - if (startthread) { - vt->probe = vcl->probe; - for (u = 0; u < vcl->probe.initial; u++) { - vbp_start_poke(vt); - vt->happy |= 1; - vbp_has_poked(vt); - } - if (!vcl->probe.initial) - vbp_has_poked(vt); - AZ(pthread_create(&vt->thread, NULL, vbp_wrk_poll_backend, vt)); - } -} - -void -VBP_Use(const struct backend *b, const struct vrt_backend_probe *p) -{ - struct vbp_target *vt; - struct vbp_vcl *vcl; - - ASSERT_CLI(); - CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - CHECK_OBJ_NOTNULL(p, VRT_BACKEND_PROBE_MAGIC); - AN(b->probe); - vt = b->probe; + vt->probe = *p; - VTAILQ_FOREACH(vcl, &vt->vcls, list) { - if (vcl->probep != p) - continue; + vbp_set_defaults(vt); + vbp_build_req(vt, hosthdr); - Lck_Lock(&vbp_mtx); - VTAILQ_REMOVE(&vt->vcls, vcl, list); - VTAILQ_INSERT_HEAD(&vt->vcls, vcl, list); - Lck_Unlock(&vbp_mtx); - return; + for (u = 0; u < vt->probe.initial; u++) { + vbp_start_poke(vt); + vt->happy |= 1; + vbp_has_poked(vt); } + if (!vt->probe.initial) + vbp_has_poked(vt); + AZ(pthread_create(&vt->thread, NULL, vbp_wrk_poll_backend, vt)); } void -VBP_Remove(struct backend *b, struct vrt_backend_probe const *p) +VBP_Remove(struct backend *b) { struct vbp_target *vt; - struct vbp_vcl *vcl; void *ret; ASSERT_CLI(); - AN(p); CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - CHECK_OBJ_NOTNULL(p, VRT_BACKEND_PROBE_MAGIC); AN(b->probe); vt = b->probe; - VTAILQ_FOREACH(vcl, &vt->vcls, list) - if (vcl->probep == p) - break; - - AN(vcl); - - Lck_Lock(&vbp_mtx); - VTAILQ_REMOVE(&vt->vcls, vcl, list); - Lck_Unlock(&vbp_mtx); - - FREE_OBJ(vcl); - - if (!VTAILQ_EMPTY(&vt->vcls)) - return; - - /* No more polling for this backend */ - - b->healthy = 1; - vt->stop = 1; AZ(pthread_cancel(vt->thread)); AZ(pthread_join(vt->thread, &ret)); - b->healthy = 1; - VTAILQ_REMOVE(&vbp_list, vt, list); + b->healthy = 1; b->probe = NULL; - VSB_delete(vt->vsb); + free(vt->req); FREE_OBJ(vt); } @@ -576,6 +486,5 @@ void VBP_Init(void) { - Lck_New(&vbp_mtx, lck_vbp); CLI_AddFuncs(debug_cmds); } From phk at FreeBSD.org Mon Mar 9 22:35:10 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 23:35:10 +0100 Subject: [master] 026167d Get a ref on the tcp_pool of the backend we're probing for. Message-ID: commit 026167d90a0ce7fc0b0867063a4647002c7cab4f Author: Poul-Henning Kamp Date: Mon Mar 9 22:09:59 2015 +0000 Get a ref on the tcp_pool of the backend we're probing for. diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c index 21ae52b..e18a683 100644 --- a/bin/varnishd/cache/cache_backend_poll.c +++ b/bin/varnishd/cache/cache_backend_poll.c @@ -58,6 +58,7 @@ struct vbp_target { #define VBP_TARGET_MAGIC 0x6b7cb656 struct backend *backend; + struct tcp_pool *tcp_pool; struct vrt_backend_probe probe; @@ -108,7 +109,7 @@ vbp_poke(struct vbp_target *vt) t_start = t_now = VTIM_real(); t_end = t_start + vt->probe.timeout; - s = VBT_Open(bp->tcp_pool, t_end - t_now, &sa); + s = VBT_Open(vt->tcp_pool, t_end - t_now, &sa); if (s < 0) { /* Got no connection: failed */ return; @@ -441,6 +442,9 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, b->probe = vt; VTAILQ_INSERT_TAIL(&vbp_list, vt, list); + vt->tcp_pool = VBT_Ref(b->ipv4, b->ipv6); + AN(vt->tcp_pool); + vt->probe = *p; vbp_set_defaults(vt); @@ -464,16 +468,18 @@ VBP_Remove(struct backend *b) ASSERT_CLI(); CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - AN(b->probe); vt = b->probe; + CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC); vt->stop = 1; + AZ(pthread_cancel(vt->thread)); AZ(pthread_join(vt->thread, &ret)); VTAILQ_REMOVE(&vbp_list, vt, list); b->healthy = 1; b->probe = NULL; + VBT_Rel(&vt->tcp_pool); free(vt->req); FREE_OBJ(vt); } From phk at FreeBSD.org Mon Mar 9 22:35:10 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 09 Mar 2015 23:35:10 +0100 Subject: [master] a49d623 Give backend.list CLI command an optional "-p" flag which outputs detailed probing information. Message-ID: commit a49d6239a33315a54beff1fad787c87e192f0691 Author: Poul-Henning Kamp Date: Mon Mar 9 22:34:28 2015 +0000 Give backend.list CLI command an optional "-p" flag which outputs detailed probing information. Retire the "debug.health" CLI command. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 5dd6621..8817c3c 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -710,9 +710,6 @@ void VCA_FailSess(struct worker *w); /* cache_backend_cfg.c */ void VBE_InitCfg(void); -/* cache_backend_poll.c */ -void VBP_Init(void); - /* cache_ban.c */ struct ban *BAN_New(void); int BAN_AddTest(struct ban *, const char *, const char *, const char *); diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index f1faa97..584a6f1 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -113,7 +113,7 @@ void VBE_DeleteBackend(struct backend *); void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p, const char *hosthdr); void VBP_Remove(struct backend *b); -void VBP_Summary(struct cli *cli, const struct vbp_target *vt); +void VBP_Status(struct cli *cli, const struct backend *, int details); struct tcp_pool *VBT_Ref(const struct suckaddr *ip4, const struct suckaddr *ip6); diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index fc619c0..eb22855 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -177,7 +177,6 @@ backend_find(struct cli *cli, const char *matcher, bf_func *func, void *priv) VSB_printf(vsb, "%s.%s", vcc->loaded_name, matcher); } AZ(VSB_finish(vsb)); - VCLI_Out(cli, "Using pattern \"%s\"\n", VSB_data(vsb)); VTAILQ_FOREACH(b, &backends, list) { if (fnmatch(VSB_data(vsb), b->display_name, 0)) continue; @@ -197,15 +196,10 @@ backend_find(struct cli *cli, const char *matcher, bf_func *func, void *priv) static int __match_proto__() do_list(struct cli *cli, struct backend *b, void *priv) { - int *hdr; + int *probes; AN(priv); - hdr = priv; - if (!*hdr) { - VCLI_Out(cli, "%-30s %-10s %s", - "Backend name", "Admin", "Probe"); - *hdr = 1; - } + probes = priv; CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); VCLI_Out(cli, "\n%-30s", b->display_name); @@ -226,7 +220,7 @@ do_list(struct cli *cli, struct backend *b, void *priv) VCLI_Out(cli, " %s", "Healthy "); else VCLI_Out(cli, " %s", "Sick "); - VBP_Summary(cli, b->probe); + VBP_Status(cli, b, *probes); } /* XXX: report b->health_changed */ @@ -237,12 +231,24 @@ do_list(struct cli *cli, struct backend *b, void *priv) static void cli_backend_list(struct cli *cli, const char * const *av, void *priv) { - int hdr = 0; + int probes = 0; - (void)av; (void)priv; ASSERT_CLI(); - (void)backend_find(cli, av[2], do_list, &hdr); + if (av[2] != NULL && !strcmp(av[2], "-p")) { + av++; + probes = 1; + } else if (av[2] != NULL && av[2][0] == '-') { + VCLI_Out(cli, "Invalid flags %s", av[2]); + VCLI_SetResult(cli, CLIS_PARAM); + return; + } else if (av[3] != NULL) { + VCLI_Out(cli, "Too many arguments"); + VCLI_SetResult(cli, CLIS_PARAM); + return; + } + VCLI_Out(cli, "%-30s %-10s %s", "Backend name", "Admin", "Probe"); + (void)backend_find(cli, av[2], do_list, &probes); } /*---------------------------------------------------------------------*/ @@ -293,7 +299,7 @@ cli_backend_set_health(struct cli *cli, const char * const *av, void *priv) static struct cli_proto backend_cmds[] = { { "backend.list", "backend.list []", "\tList backends.", - 0, 1, "", cli_backend_list }, + 0, 2, "", cli_backend_list }, { "backend.set_health", "backend.set_health ", "\tSet health status on the backends.", diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c index e18a683..a3db64b 100644 --- a/bin/varnishd/cache/cache_backend_poll.c +++ b/bin/varnishd/cache/cache_backend_poll.c @@ -98,14 +98,10 @@ vbp_poke(struct vbp_target *vt) int s, tmo, i; double t_start, t_now, t_end; unsigned rlen, resp; - struct backend *bp; char buf[8192], *p; struct pollfd pfda[1], *pfd = pfda; const struct suckaddr *sa; - bp = vt->backend; - CHECK_OBJ_NOTNULL(bp, BACKEND_MAGIC); - t_start = t_now = VTIM_real(); t_end = t_start + vt->probe.timeout; @@ -293,20 +289,13 @@ vbp_wrk_poll_backend(void *priv) * Cli functions */ -void -VBP_Summary(struct cli *cli, const struct vbp_target *vt) -{ - - CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC); - VCLI_Out(cli, "%d/%d", vt->good, vt->probe.window); -} - static void vbp_bitmap(struct cli *cli, char c, uint64_t map, const char *lbl) { int i; uint64_t u = (1ULL << 63); + VCLI_Out(cli, " "); for (i = 0; i < 64; i++) { if (map & u) VCLI_Out(cli, "%c", c); @@ -323,18 +312,14 @@ static void vbp_health_one(struct cli *cli, const struct vbp_target *vt) { - VCLI_Out(cli, "Backend %s is %s\n", - vt->backend->vcl_name, - vt->backend->healthy ? "Healthy" : "Sick"); - VCLI_Out(cli, "Current states good: %2u threshold: %2u window: %2u\n", + VCLI_Out(cli, + " Current states good: %2u threshold: %2u window: %2u\n", vt->good, vt->probe.threshold, vt->probe.window); - VCLI_Out(cli, "Average responsetime of good probes: %.6f\n", vt->avg); VCLI_Out(cli, - "Oldest " - " Newest\n"); + " Average response time of good probes: %.6f\n", vt->avg); VCLI_Out(cli, - "=============================" - "===================================\n"); + " Oldest ======================" + "============================ Newest\n"); #define BITMAP(n, c, t, b) \ if ((vt->n != 0) || (b)) \ @@ -343,26 +328,23 @@ vbp_health_one(struct cli *cli, const struct vbp_target *vt) #undef BITMAP } -static void -vbp_health(struct cli *cli, const char * const *av, void *priv) +void +VBP_Status(struct cli *cli, const struct backend *be, int details) { struct vbp_target *vt; - ASSERT_CLI(); - (void)av; - (void)priv; - - VTAILQ_FOREACH(vt, &vbp_list, list) + CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); + vt = be->probe; + CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC); + VCLI_Out(cli, "%d/%d", vt->good, vt->probe.window); + if (details) { + VCLI_Out(cli, "\n"); vbp_health_one(cli, vt); + } else { + VCLI_Out(cli, "%d/%d", vt->good, vt->probe.window); + } } -static struct cli_proto debug_cmds[] = { - { "debug.health", "debug.health", - "\tDump backend health information.", - 0, 0, "d", vbp_health }, - { NULL } -}; - /*-------------------------------------------------------------------- * Build request from probe spec */ @@ -483,14 +465,3 @@ VBP_Remove(struct backend *b) free(vt->req); FREE_OBJ(vt); } - -/*-------------------------------------------------------------------- - * Initialize the backend probe subsystem - */ - -void -VBP_Init(void) -{ - - CLI_AddFuncs(debug_cmds); -} diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index b5f9b0b..1f2f48f 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -221,7 +221,6 @@ child_main(void) VBO_Init(); VBE_InitCfg(); - VBP_Init(); Pool_Init(); V1P_Init(); diff --git a/bin/varnishtest/tests/c00017.vtc b/bin/varnishtest/tests/c00017.vtc index 2ad090e..9342c53 100644 --- a/bin/varnishtest/tests/c00017.vtc +++ b/bin/varnishtest/tests/c00017.vtc @@ -40,4 +40,4 @@ varnish v1 -vcl { sema r1 sync 2 -varnish v1 -cli "debug.health" +varnish v1 -cli "backend.list -p" diff --git a/bin/varnishtest/tests/c00035.vtc b/bin/varnishtest/tests/c00035.vtc index 8b6bbea..5eab71d 100644 --- a/bin/varnishtest/tests/c00035.vtc +++ b/bin/varnishtest/tests/c00035.vtc @@ -30,7 +30,7 @@ varnish v1 -vcl { delay 1 varnish v1 -cliok "vcl.list" -varnish v1 -cliok "debug.health" +varnish v1 -cliok "backend.list -p" server s1 -break { rxreq diff --git a/bin/varnishtest/tests/v00014.vtc b/bin/varnishtest/tests/v00014.vtc index 6769a24..4a290b0 100644 --- a/bin/varnishtest/tests/v00014.vtc +++ b/bin/varnishtest/tests/v00014.vtc @@ -44,7 +44,7 @@ varnish v1 -vcl { } } -start -varnish v1 -cliok "backend.list" -cliok "debug.health" +varnish v1 -cliok "backend.list -p" client c1 { txreq From phk at FreeBSD.org Mon Mar 9 23:15:43 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 00:15:43 +0100 Subject: [master] d4ec606 Synchronize backend probe tear-down with a mutex. Message-ID: commit d4ec606cedaf607849e60cd878c79f96276cac54 Author: Poul-Henning Kamp Date: Mon Mar 9 23:15:25 2015 +0000 Synchronize backend probe tear-down with a mutex. diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index eb22855..da22175 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -68,6 +68,7 @@ VBE_DeleteBackend(struct backend *b) free(b->display_name); VSM_Free(b->vsc); VBT_Rel(&b->tcp_pool); + Lck_Delete(&b->mtx); FREE_OBJ(b); VSC_C_main->n_backend--; } diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c index a3db64b..0912557 100644 --- a/bin/varnishd/cache/cache_backend_poll.c +++ b/bin/varnishd/cache/cache_backend_poll.c @@ -57,12 +57,14 @@ struct vbp_target { unsigned magic; #define VBP_TARGET_MAGIC 0x6b7cb656 + struct lock mtx; + int stop; struct backend *backend; + struct tcp_pool *tcp_pool; struct vrt_backend_probe probe; - int stop; char *req; int req_len; @@ -235,27 +237,31 @@ vbp_has_poked(struct vbp_target *vt) } vt->good = j; - if (vt->good >= vt->probe.threshold) { - if (vt->backend->healthy) - logmsg = "Still healthy"; - else { - logmsg = "Back healthy"; - vt->backend->health_changed = VTIM_real(); + Lck_Lock(&vt->mtx); + if (vt->backend != NULL) { + if (vt->good >= vt->probe.threshold) { + if (vt->backend->healthy) + logmsg = "Still healthy"; + else { + logmsg = "Back healthy"; + vt->backend->health_changed = VTIM_real(); + } + vt->backend->healthy = 1; + } else { + if (vt->backend->healthy) { + logmsg = "Went sick"; + vt->backend->health_changed = VTIM_real(); + } else + logmsg = "Still sick"; + vt->backend->healthy = 0; } - vt->backend->healthy = 1; - } else { - if (vt->backend->healthy) { - logmsg = "Went sick"; - vt->backend->health_changed = VTIM_real(); - } else - logmsg = "Still sick"; - vt->backend->healthy = 0; + VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s", + vt->backend->vcl_name, logmsg, bits, + vt->good, vt->probe.threshold, vt->probe.window, + vt->last, vt->avg, vt->resp_buf); + vt->backend->vsc->happy = vt->happy; } - VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s", - vt->backend->vcl_name, logmsg, bits, - vt->good, vt->probe.threshold, vt->probe.window, - vt->last, vt->avg, vt->resp_buf); - vt->backend->vsc->happy = vt->happy; + Lck_Unlock(&vt->mtx); } /*-------------------------------------------------------------------- @@ -282,6 +288,11 @@ vbp_wrk_poll_backend(void *priv) if (!vt->stop) VTIM_sleep(vt->probe.interval); } + Lck_Delete(&vt->mtx); + VTAILQ_REMOVE(&vbp_list, vt, list); + VBT_Rel(&vt->tcp_pool); + free(vt->req); + FREE_OBJ(vt); return (NULL); } @@ -423,6 +434,7 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, vt->backend = b; b->probe = vt; VTAILQ_INSERT_TAIL(&vbp_list, vt, list); + Lck_New(&vt->mtx, lck_backend); vt->tcp_pool = VBT_Ref(b->ipv4, b->ipv6); AN(vt->tcp_pool); @@ -440,28 +452,24 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, if (!vt->probe.initial) vbp_has_poked(vt); AZ(pthread_create(&vt->thread, NULL, vbp_wrk_poll_backend, vt)); + AZ(pthread_detach(vt->thread)); } void -VBP_Remove(struct backend *b) +VBP_Remove(struct backend *be) { struct vbp_target *vt; - void *ret; ASSERT_CLI(); - CHECK_OBJ_NOTNULL(b, BACKEND_MAGIC); - vt = b->probe; + CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); + vt = be->probe; CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC); + Lck_Lock(&vt->mtx); vt->stop = 1; + vt->backend = NULL; + Lck_Unlock(&vt->mtx); - AZ(pthread_cancel(vt->thread)); - AZ(pthread_join(vt->thread, &ret)); - - VTAILQ_REMOVE(&vbp_list, vt, list); - b->healthy = 1; - b->probe = NULL; - VBT_Rel(&vt->tcp_pool); - free(vt->req); - FREE_OBJ(vt); + be->healthy = 1; + be->probe = NULL; } From phk at FreeBSD.org Mon Mar 9 23:34:49 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 00:34:49 +0100 Subject: [master] dbc39e9 Disable backend probes in cold vcls Message-ID: commit dbc39e9ff4728e6624dcc0ae6b310988d09cf9d1 Author: Poul-Henning Kamp Date: Mon Mar 9 23:34:36 2015 +0000 Disable backend probes in cold vcls diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index 762ea69..cc3da2e 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -332,6 +332,10 @@ VRT_event_vbe(VRT_CTX, enum vcl_event_e ev, const struct director *d, assert(d->priv2 == vrt); CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC); + if (be->probe != NULL && ev == VCL_EVENT_WARM) + VBP_Control(be, 0); + if (be->probe != NULL && ev == VCL_EVENT_COLD) + VBP_Control(be, 1); } void diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h index 584a6f1..48dffa4 100644 --- a/bin/varnishd/cache/cache_backend.h +++ b/bin/varnishd/cache/cache_backend.h @@ -113,6 +113,7 @@ void VBE_DeleteBackend(struct backend *); void VBP_Insert(struct backend *b, struct vrt_backend_probe const *p, const char *hosthdr); void VBP_Remove(struct backend *b); +void VBP_Control(const struct backend *b, int stop); void VBP_Status(struct cli *cli, const struct backend *, int details); struct tcp_pool *VBT_Ref(const struct suckaddr *ip4, diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c index 0912557..d4cca48 100644 --- a/bin/varnishd/cache/cache_backend_poll.c +++ b/bin/varnishd/cache/cache_backend_poll.c @@ -58,6 +58,7 @@ struct vbp_target { #define VBP_TARGET_MAGIC 0x6b7cb656 struct lock mtx; + int disable; int stop; struct backend *backend; @@ -259,7 +260,8 @@ vbp_has_poked(struct vbp_target *vt) vt->backend->vcl_name, logmsg, bits, vt->good, vt->probe.threshold, vt->probe.window, vt->last, vt->avg, vt->resp_buf); - vt->backend->vsc->happy = vt->happy; + if (!vt->disable) + vt->backend->vsc->happy = vt->happy; } Lck_Unlock(&vt->mtx); } @@ -281,9 +283,11 @@ vbp_wrk_poll_backend(void *priv) AN(vt->req); assert(vt->req_len > 0); - vbp_start_poke(vt); - vbp_poke(vt); - vbp_has_poked(vt); + if (!vt->disable) { + vbp_start_poke(vt); + vbp_poke(vt); + vbp_has_poked(vt); + } if (!vt->stop) VTIM_sleep(vt->probe.interval); @@ -413,6 +417,24 @@ vbp_set_defaults(struct vbp_target *vt) } /*-------------------------------------------------------------------- + */ + +void +VBP_Control(const struct backend *be, int stop) +{ + struct vbp_target *vt; + + ASSERT_CLI(); + CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); + vt = be->probe; + CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC); + + Lck_Lock(&vt->mtx); + vt->disable = stop; + Lck_Unlock(&vt->mtx); +} + +/*-------------------------------------------------------------------- * Insert/Remove/Use called from cache_backend.c */ From phk at FreeBSD.org Tue Mar 10 08:15:38 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 09:15:38 +0100 Subject: [master] 51c8c25 Speed up and simplify the varnish ${id} -expect VSC matching Message-ID: commit 51c8c25689841c1477c409e3f02051913b35220e Author: Poul-Henning Kamp Date: Tue Mar 10 08:15:07 2015 +0000 Speed up and simplify the varnish ${id} -expect VSC matching diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 5704288..da20964 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -731,39 +731,27 @@ varnish_vclbackend(struct varnish *v, const char *vcl) */ struct stat_priv { - char target[256]; + char target_type[256]; + char target_ident[256]; + char target_name[256]; uintmax_t val; + const struct varnish *v; }; static int do_stat_cb(void *priv, const struct VSC_point * const pt) { struct stat_priv *sp = priv; - const char *p = sp->target; - int i; if (pt == NULL) return(0); - if (strcmp(pt->section->type, "")) { - i = strlen(pt->section->type); - if (memcmp(pt->section->type, p, i)) - return (0); - p += i; - if (*p != '.') - return (0); - p++; - } - if (strcmp(pt->section->ident, "")) { - i = strlen(pt->section->ident); - if (memcmp(pt->section->ident, p, i)) - return (0); - p += i; - if (*p != '.') - return (0); - p++; - } - if (strcmp(pt->desc->name, p)) - return (0); + + if (strcmp(pt->section->type, sp->target_type)) + return(0); + if (strcmp(pt->section->ident, sp->target_ident)) + return(0); + if (strcmp(pt->desc->name, sp->target_name)) + return(0); AZ(strcmp(pt->desc->ctype, "uint64_t")); sp->val = *(const volatile uint64_t*)pt->ptr; @@ -775,15 +763,28 @@ varnish_expect(const struct varnish *v, char * const *av) { uint64_t ref; int good; char *p; + char *q; int i; - const char *prefix = ""; struct stat_priv sp; - if (NULL == strchr(av[0], '.')) - prefix = "MAIN."; - snprintf(sp.target, sizeof sp.target, "%s%s", prefix, av[0]); - sp.target[sizeof sp.target - 1] = '\0'; + p = strchr(av[0], '.'); + if (p == NULL) { + strcpy(sp.target_type, "MAIN"); + sp.target_ident[0] = '\0'; + bprintf(sp.target_name, "%s", av[0]); + } else { + bprintf(sp.target_type, "%.*s", (int)(p - av[0]), av[0]); + p++; + q = strrchr(p, '.'); + bprintf(sp.target_name, "%s", q + 1); + if (q == p) + sp.target_ident[0] = '\0'; + else + bprintf(sp.target_ident, "%.*s", (int)(q - p), p); + } + sp.val = 0; + sp.v = v; ref = 0; good = 0; for (i = 0; i < 10; i++, (void)usleep(100000)) { From phk at FreeBSD.org Tue Mar 10 08:31:23 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 09:31:23 +0100 Subject: [master] d2d9a68 Make it possible to expect that a VSC counter is not there by: Message-ID: commit d2d9a685c593d682880389cf85db7526c809b540 Author: Poul-Henning Kamp Date: Tue Mar 10 08:30:53 2015 +0000 Make it possible to expect that a VSC counter is not there by: varnish ${id} -expect !${vsc-identifier} diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index da20964..0473002 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -762,18 +762,24 @@ static void varnish_expect(const struct varnish *v, char * const *av) { uint64_t ref; int good; + char *r; char *p; char *q; - int i; + int i, not = 0; struct stat_priv sp; - p = strchr(av[0], '.'); + r = av[0]; + if (r[0] == '!') { + not = 1; + r++; + } + p = strchr(r, '.'); if (p == NULL) { strcpy(sp.target_type, "MAIN"); sp.target_ident[0] = '\0'; - bprintf(sp.target_name, "%s", av[0]); + bprintf(sp.target_name, "%s", r); } else { - bprintf(sp.target_type, "%.*s", (int)(p - av[0]), av[0]); + bprintf(sp.target_type, "%.*s", (int)(p - r), r); p++; q = strrchr(p, '.'); bprintf(sp.target_name, "%s", q + 1); @@ -801,6 +807,9 @@ varnish_expect(const struct varnish *v, char * const *av) { continue; } + if (not) + vtc_log(v->vl, 0, "Found (not expected): %s", av[0]+1); + good = 0; ref = strtoumax(av[2], &p, 0); if (ref == UINTMAX_MAX || *p) @@ -819,10 +828,17 @@ varnish_expect(const struct varnish *v, char * const *av) { } if (good == -1) { vtc_log(v->vl, 0, "VSM error: %s", VSM_Error(v->vd)); - VSM_ResetError(v->vd); - } else if (good == -2) { + } + if (good == -2) { + if (not) { + vtc_log(v->vl, 2, "not found (as expected): %s", + av[0] + 1); + return; + } vtc_log(v->vl, 0, "stats field %s unknown", av[0]); - } else if (good) { + } + + if (good == 1) { vtc_log(v->vl, 2, "as expected: %s (%ju) %s %s", av[0], sp.val, av[1], av[2]); } else { From phk at FreeBSD.org Tue Mar 10 09:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 10:02:48 +0100 Subject: [master] 2ea8f6d Remove surplus new-line Message-ID: commit 2ea8f6d5af5f317abff77d3cf0de5f28c09d8f8c Author: Poul-Henning Kamp Date: Tue Mar 10 08:40:03 2015 +0000 Remove surplus new-line diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index b05c43f..129e3bf 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -451,7 +451,7 @@ ccf_listen_address(struct cli *cli, const char * const *av, void *priv) if (ls->sock < 0) continue; VTCP_myname(ls->sock, h, sizeof h, p, sizeof p); - VCLI_Out(cli, "%s %s\n", h, p); + VCLI_Out(cli, "%s %s", h, p); } } From phk at FreeBSD.org Tue Mar 10 09:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 10:02:48 +0100 Subject: [master] ab9af46 Don't expect the surplus new-line just removed in cache_acceptor Message-ID: commit ab9af460bc2436e1bf9b9fd0bbdfcf2dc6885f4c Author: Poul-Henning Kamp Date: Tue Mar 10 08:49:46 2015 +0000 Don't expect the surplus new-line just removed in cache_acceptor diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 0473002..ca1ab0a 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -504,7 +504,7 @@ static void varnish_start(struct varnish *v) { enum VCLI_status_e u; - char *resp, *h, *p, *q; + char *resp, *h, *p; if (v->cli_fd < 0) varnish_launch(v); @@ -535,9 +535,6 @@ varnish_start(struct varnish *v) p = strchr(h, ' '); AN(p); *p++ = '\0'; - q = strchr(p, '\n'); - AN(q); - *q = '\0'; vtc_log(v->vl, 2, "Listen on %s %s", h, p); macro_def(v->vl, v->name, "addr", "%s", h); macro_def(v->vl, v->name, "port", "%s", p); From phk at FreeBSD.org Tue Mar 10 09:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 10:02:48 +0100 Subject: [master] 05f673a Withdraw backend VSC counters when VCL is cold Message-ID: commit 05f673a95e0b09053eb454f74b66aab1a251c21f Author: Poul-Henning Kamp Date: Tue Mar 10 09:02:29 2015 +0000 Withdraw backend VSC counters when VCL is cold diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c index cc3da2e..a02a7d8 100644 --- a/bin/varnishd/cache/cache_backend.c +++ b/bin/varnishd/cache/cache_backend.c @@ -332,10 +332,22 @@ VRT_event_vbe(VRT_CTX, enum vcl_event_e ev, const struct director *d, assert(d->priv2 == vrt); CAST_OBJ_NOTNULL(be, d->priv, BACKEND_MAGIC); + if (ev == VCL_EVENT_WARM) { + be->vsc = VSM_Alloc(sizeof *be->vsc, + VSC_CLASS, VSC_type_vbe, be->display_name); + AN(be->vsc); + } + if (be->probe != NULL && ev == VCL_EVENT_WARM) VBP_Control(be, 0); + if (be->probe != NULL && ev == VCL_EVENT_COLD) VBP_Control(be, 1); + + if (ev == VCL_EVENT_COLD) { + VSM_Free(be->vsc); + be->vsc = NULL; + } } void diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index da22175..e612982 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -66,7 +66,7 @@ VBE_DeleteBackend(struct backend *b) free(b->ipv4); free(b->ipv6); free(b->display_name); - VSM_Free(b->vsc); + AZ(b->vsc); VBT_Rel(&b->tcp_pool); Lck_Delete(&b->mtx); FREE_OBJ(b); @@ -97,8 +97,6 @@ VBE_AddBackend(const char *vcl, const struct vrt_backend *vb) bprintf(buf, "%s.%s", vcl, vb->vcl_name); REPLACE(b->display_name, buf); - b->vsc = VSM_Alloc(sizeof *b->vsc, VSC_CLASS, VSC_type_vbe, buf); - b->vcl_name = vb->vcl_name; b->ipv4_addr = vb->ipv4_addr; b->ipv6_addr = vb->ipv6_addr; diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c index d4cca48..ee3602b 100644 --- a/bin/varnishd/cache/cache_backend_poll.c +++ b/bin/varnishd/cache/cache_backend_poll.c @@ -260,8 +260,10 @@ vbp_has_poked(struct vbp_target *vt) vt->backend->vcl_name, logmsg, bits, vt->good, vt->probe.threshold, vt->probe.window, vt->last, vt->avg, vt->resp_buf); - if (!vt->disable) + if (!vt->disable) { + AN(vt->backend->vsc); vt->backend->vsc->happy = vt->happy; + } } Lck_Unlock(&vt->mtx); } @@ -457,6 +459,7 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, b->probe = vt; VTAILQ_INSERT_TAIL(&vbp_list, vt, list); Lck_New(&vt->mtx, lck_backend); + vt->disable = 1; vt->tcp_pool = VBT_Ref(b->ipv4, b->ipv6); AN(vt->tcp_pool); diff --git a/bin/varnishtest/tests/v00043.vcl b/bin/varnishtest/tests/v00043.vcl index 17e9798..6e38fe9 100644 --- a/bin/varnishtest/tests/v00043.vcl +++ b/bin/varnishtest/tests/v00043.vcl @@ -1,23 +1,56 @@ varnishtest "vcl.state coverage tests" -server s1 { +server s1 -repeat 20 { rxreq txresp + delay .2 + close } -start -varnish v1 -vcl+backend {} -start -varnish v1 -vcl+backend {} +varnish v1 -vcl { + backend default { + .host = "${s1_addr}"; + .probe = { .interval = 1s; .initial = 1;} + } +} -start -varnish v1 -cliok "param.set vcl_cooldown 5" +varnish v1 -cliok "param.set vcl_cooldown 3" -varnish v1 -cliok "vcl.list" -varnish v1 -cliok "vcl.use vcl2" -varnish v1 -cliok "vcl.list" -delay 5 -varnish v1 -cliok "vcl.list" -varnish v1 -cliok "vcl.state vcl1 warm" -varnish v1 -cliok "vcl.list" +# We only have one vcl yet +varnish v1 -expect VBE.vcl1.default.happy > 0 +varnish v1 -expect !VBE.vcl2.default.happy +varnish v1 -cliok "backend.list -p *.*" + +varnish v1 -vcl { + backend default { + .host = "${s1_addr}"; + .probe = { .interval = 1s; .initial = 1;} + } +} + +# Now we have two vcls (and run on the latest loaded) +varnish v1 -expect VBE.vcl1.default.happy > 0 +varnish v1 -expect VBE.vcl2.default.happy > 0 + +# Freeze the first VCL +varnish v1 -cliok "vcl.state vcl1 cold" +varnish v1 -expect !VBE.vcl1.default.happy + +# Set it auto should be a no-op +varnish v1 -cliok "vcl.state vcl1 auto" +varnish v1 -expect !VBE.vcl1.default.happy + +# Use it, and it should come alive varnish v1 -cliok "vcl.use vcl1" +varnish v1 -expect VBE.vcl1.default.happy > 0 +varnish v1 -expect VBE.vcl2.default.happy > 0 + +# and the unused one should go cold +delay 4 +varnish v1 -expect !VBE.vcl2.default.happy + +# Mark the used warm and use it the other +varnish v1 -cliok "vcl.state vcl1 warm" varnish v1 -cliok "vcl.use vcl2" -delay 5 -varnish v1 -cliok "vcl.list" +delay 4 +varnish v1 -expect VBE.vcl2.default.happy > 0 From phk at FreeBSD.org Tue Mar 10 09:05:32 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 10:05:32 +0100 Subject: [master] 8b86fad white space nit. Message-ID: commit 8b86fadc3678774061813799e7ae500c7138c22f Author: Poul-Henning Kamp Date: Tue Mar 10 09:05:24 2015 +0000 white space nit. diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index ca1ab0a..1cae1d1 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -785,7 +785,7 @@ varnish_expect(const struct varnish *v, char * const *av) { else bprintf(sp.target_ident, "%.*s", (int)(q - p), p); } - + sp.val = 0; sp.v = v; ref = 0; From phk at FreeBSD.org Tue Mar 10 09:31:05 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 10:31:05 +0100 Subject: [master] adf962f Don't emit the summary poll stats twice. Message-ID: commit adf962fa80b8504875a30b5afb8f8f529dc90cf3 Author: Poul-Henning Kamp Date: Tue Mar 10 09:30:49 2015 +0000 Don't emit the summary poll stats twice. diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c index ee3602b..055798f 100644 --- a/bin/varnishd/cache/cache_backend_poll.c +++ b/bin/varnishd/cache/cache_backend_poll.c @@ -357,8 +357,6 @@ VBP_Status(struct cli *cli, const struct backend *be, int details) if (details) { VCLI_Out(cli, "\n"); vbp_health_one(cli, vt); - } else { - VCLI_Out(cli, "%d/%d", vt->good, vt->probe.window); } } From phk at FreeBSD.org Tue Mar 10 09:52:08 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 10:52:08 +0100 Subject: [master] 0fc792a Be slightly less anal about the umask used to run CC Message-ID: commit 0fc792a66d8b0833d4ec7558e7001afd0940f274 Author: Poul-Henning Kamp Date: Tue Mar 10 09:51:51 2015 +0000 Be slightly less anal about the umask used to run CC diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index e69d8bf..b9a1406 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -162,7 +162,7 @@ run_cc(void *priv) VSB_putc(sb, '%'); AZ(VSB_finish(sb)); - (void)umask(0177); + (void)umask(077); (void)execl("/bin/sh", "/bin/sh", "-c", VSB_data(sb), (char*)0); VSB_delete(sb); // For flexelint } From fgsch at lodoss.net Tue Mar 10 10:21:51 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 10 Mar 2015 11:21:51 +0100 Subject: [3.0] 9190770 Make both pidfiles names match Message-ID: commit 9190770d54322567d3d4fa4b5bd0f1dc091c63c4 Author: Federico G. Schwindt Date: Tue Mar 10 10:09:48 2015 +0000 Make both pidfiles names match Fixes #1690 diff --git a/redhat/varnish.initrc b/redhat/varnish.initrc index 4afa6c5..b3426a8 100755 --- a/redhat/varnish.initrc +++ b/redhat/varnish.initrc @@ -6,7 +6,7 @@ # description: Varnish is a high-perfomance HTTP accelerator # processname: varnishd # config: /etc/sysconfig/varnish -# pidfile: /var/run/varnishd.pid +# pidfile: /var/run/varnish.pid ### BEGIN INIT INFO # Provides: varnish From arianna.aondio at varnish-software.com Tue Mar 10 10:33:02 2015 From: arianna.aondio at varnish-software.com (Arianna Aondio) Date: Tue, 10 Mar 2015 11:33:02 +0100 Subject: [master] cada828 Varnishncsa doesn't pick the first header's value, but the last one (more precise if a header is set more then once or overwritten). Message-ID: commit cada82833d07362a7fc908ea6e15373024c032a3 Author: Arianna Aondio Date: Tue Mar 10 11:28:30 2015 +0100 Varnishncsa doesn't pick the first header's value,but the last one (more precise if a header is set more then once or overwritten). Fixes #1683 diff --git a/bin/varnishncsa/varnishncsa.c b/bin/varnishncsa/varnishncsa.c index 4549539..ce30191 100644 --- a/bin/varnishncsa/varnishncsa.c +++ b/bin/varnishncsa/varnishncsa.c @@ -769,7 +769,7 @@ process_hdr(const struct watch_head *head, const char *b, const char *e) VTAILQ_FOREACH(w, head, list) { if (strncasecmp(b, w->key, w->keylen)) continue; - frag_line(0, b + w->keylen, e, &w->frag); + frag_line(1, b + w->keylen, e, &w->frag); } } From fgsch at lodoss.net Tue Mar 10 10:36:33 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 10 Mar 2015 11:36:33 +0100 Subject: [master] 55fe128 Make both pidfiles names match Message-ID: commit 55fe128363be72c6bf2491ea9349e4278d39a9a7 Author: Federico G. Schwindt Date: Tue Mar 10 10:11:15 2015 +0000 Make both pidfiles names match diff --git a/redhat/varnish.initrc b/redhat/varnish.initrc index 082c770..117e334 100755 --- a/redhat/varnish.initrc +++ b/redhat/varnish.initrc @@ -6,7 +6,7 @@ # description: Varnish is a high-perfomance HTTP accelerator # processname: varnishd # config: /etc/sysconfig/varnish -# pidfile: /var/run/varnishd.pid +# pidfile: /var/run/varnish.pid ### BEGIN INIT INFO # Provides: varnish From phk at FreeBSD.org Tue Mar 10 10:41:34 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 11:41:34 +0100 Subject: [master] f462efd Use backend display name in VSL message, and don't emit any for the .initial setup. Message-ID: commit f462efd91cf241b4facaa0cd2dab23a4517a0d0a Author: Poul-Henning Kamp Date: Tue Mar 10 10:15:19 2015 +0000 Use backend display name in VSL message, and don't emit any for the .initial setup. diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c index 055798f..b80e6c4 100644 --- a/bin/varnishd/cache/cache_backend_poll.c +++ b/bin/varnishd/cache/cache_backend_poll.c @@ -257,7 +257,7 @@ vbp_has_poked(struct vbp_target *vt) vt->backend->healthy = 0; } VSL(SLT_Backend_health, 0, "%s %s %s %u %u %u %.6f %.6f %s", - vt->backend->vcl_name, logmsg, bits, + vt->backend->display_name, logmsg, bits, vt->good, vt->probe.threshold, vt->probe.window, vt->last, vt->avg, vt->resp_buf); if (!vt->disable) { @@ -453,8 +453,6 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, ALLOC_OBJ(vt, VBP_TARGET_MAGIC); XXXAN(vt); - vt->backend = b; - b->probe = vt; VTAILQ_INSERT_TAIL(&vbp_list, vt, list); Lck_New(&vt->mtx, lck_backend); vt->disable = 1; @@ -467,13 +465,14 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, vbp_set_defaults(vt); vbp_build_req(vt, hosthdr); - for (u = 0; u < vt->probe.initial; u++) { + for (u = 1; u < vt->probe.initial; u++) { vbp_start_poke(vt); vt->happy |= 1; vbp_has_poked(vt); } - if (!vt->probe.initial) - vbp_has_poked(vt); + vt->backend = b; + b->probe = vt; + vbp_has_poked(vt); AZ(pthread_create(&vt->thread, NULL, vbp_wrk_poll_backend, vt)); AZ(pthread_detach(vt->thread)); } From phk at FreeBSD.org Tue Mar 10 10:41:34 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 11:41:34 +0100 Subject: [master] cf41aff Start the poll/probe thread first time the VCL goes warm. Message-ID: commit cf41aff80cb507e85fa1eb4cff882208ae133690 Author: Poul-Henning Kamp Date: Tue Mar 10 10:39:30 2015 +0000 Start the poll/probe thread first time the VCL goes warm. Fix off-by-one error just introduced for .initial setup. diff --git a/bin/varnishd/cache/cache_backend_poll.c b/bin/varnishd/cache/cache_backend_poll.c index b80e6c4..2a9a863 100644 --- a/bin/varnishd/cache/cache_backend_poll.c +++ b/bin/varnishd/cache/cache_backend_poll.c @@ -429,8 +429,16 @@ VBP_Control(const struct backend *be, int stop) vt = be->probe; CHECK_OBJ_NOTNULL(vt, VBP_TARGET_MAGIC); +VSL(SLT_Debug, 0, "VBP_CONTROL %d", stop); Lck_Lock(&vt->mtx); - vt->disable = stop; + if (vt->disable == -1 && !stop) { + vt->disable = stop; + AZ(pthread_create(&vt->thread, NULL, vbp_wrk_poll_backend, vt)); + AZ(pthread_detach(vt->thread)); + } else { + assert(vt->disable != -1); + vt->disable = stop; + } Lck_Unlock(&vt->mtx); } @@ -455,7 +463,7 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, XXXAN(vt); VTAILQ_INSERT_TAIL(&vbp_list, vt, list); Lck_New(&vt->mtx, lck_backend); - vt->disable = 1; + vt->disable = -1; vt->tcp_pool = VBT_Ref(b->ipv4, b->ipv6); AN(vt->tcp_pool); @@ -465,7 +473,9 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, vbp_set_defaults(vt); vbp_build_req(vt, hosthdr); - for (u = 1; u < vt->probe.initial; u++) { + for (u = 0; u < vt->probe.initial; u++) { + if (u) + vbp_has_poked(vt); vbp_start_poke(vt); vt->happy |= 1; vbp_has_poked(vt); @@ -473,8 +483,6 @@ VBP_Insert(struct backend *b, const struct vrt_backend_probe *p, vt->backend = b; b->probe = vt; vbp_has_poked(vt); - AZ(pthread_create(&vt->thread, NULL, vbp_wrk_poll_backend, vt)); - AZ(pthread_detach(vt->thread)); } void From phk at FreeBSD.org Tue Mar 10 10:41:34 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 11:41:34 +0100 Subject: [master] f578ea1 Allow 1KB in vtc_dump so backend poll info is complete Message-ID: commit f578ea1d0b2aca473040defdda8986af60de9444 Author: Poul-Henning Kamp Date: Tue Mar 10 10:40:31 2015 +0000 Allow 1KB in vtc_dump so backend poll info is complete diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c index e90b305..57ee43c 100644 --- a/bin/varnishtest/vtc_log.c +++ b/bin/varnishtest/vtc_log.c @@ -187,7 +187,7 @@ vtc_dump(struct vtclog *vl, int lvl, const char *pfx, const char *str, int len) if (len < 0) len = strlen(str); for (l = 0; l < len; l++, str++) { - if (l > 512 && olen != -2) { + if (l > 1024 && olen != -2) { VSB_printf(vl->vsb, "..."); break; } From phk at FreeBSD.org Tue Mar 10 10:41:34 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 11:41:34 +0100 Subject: [master] a7e7b65 Add a slight delay to stabilize this test. Message-ID: commit a7e7b6535ac6fb7bafc06e33fa12e802c4cb3b51 Author: Poul-Henning Kamp Date: Tue Mar 10 10:41:00 2015 +0000 Add a slight delay to stabilize this test. diff --git a/bin/varnishtest/tests/c00014.vtc b/bin/varnishtest/tests/c00014.vtc index 99f2dd7..ec8c9d8 100644 --- a/bin/varnishtest/tests/c00014.vtc +++ b/bin/varnishtest/tests/c00014.vtc @@ -27,7 +27,10 @@ client c1 { expect resp.bodylen == 12 expect resp.http.x-varnish == "1001" } -start + sema r1 sync 2 +delay .2 + client c2 { txreq -url "/foo" rxresp From phk at FreeBSD.org Tue Mar 10 10:41:34 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 11:41:34 +0100 Subject: [master] d09235e Adapt to new backend.list CLI command Message-ID: commit d09235eb9f7977cf2460963283346983ed75dfb9 Author: Poul-Henning Kamp Date: Tue Mar 10 10:41:12 2015 +0000 Adapt to new backend.list CLI command diff --git a/bin/varnishtest/tests/c00048.vtc b/bin/varnishtest/tests/c00048.vtc index 03ac275..4d96e29 100644 --- a/bin/varnishtest/tests/c00048.vtc +++ b/bin/varnishtest/tests/c00048.vtc @@ -25,9 +25,10 @@ varnish v1 -vcl { delay 1 -varnish v1 -cliok "backend.list" +varnish v1 -cliok "vcl.list" +varnish v1 -cliok "backend.list -p" varnish v1 -cliok "backend.set_health s1 auto" -varnish v1 -cliok "backend.list s" +varnish v1 -cliok "backend.list -p" client c1 { txreq @@ -35,9 +36,9 @@ client c1 { expect resp.status == 200 } -run -varnish v1 -cliok "backend.list (:)" +varnish v1 -cliok "backend.list" varnish v1 -cliok "backend.set_health s1 sick" -varnish v1 -cliok "backend.list (1:)" +varnish v1 -cliok "backend.list" client c1 { txreq From fgsch at lodoss.net Tue Mar 10 12:26:42 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 10 Mar 2015 13:26:42 +0100 Subject: [master] 30c88b2 Update docs after recent changes Message-ID: commit 30c88b252fe31aa4125a2194b98f22fad81a4580 Author: Federico G. Schwindt Date: Tue Mar 10 12:24:16 2015 +0000 Update docs after recent changes A few things still remaining. diff --git a/bin/varnishd/cache/cache_backend_cfg.c b/bin/varnishd/cache/cache_backend_cfg.c index e612982..08b58d3 100644 --- a/bin/varnishd/cache/cache_backend_cfg.c +++ b/bin/varnishd/cache/cache_backend_cfg.c @@ -296,7 +296,7 @@ cli_backend_set_health(struct cli *cli, const char * const *av, void *priv) /*---------------------------------------------------------------------*/ static struct cli_proto backend_cmds[] = { - { "backend.list", "backend.list []", + { "backend.list", "backend.list [-p] []", "\tList backends.", 0, 2, "", cli_backend_list }, { "backend.set_health", diff --git a/doc/sphinx/reference/varnish-cli.rst b/doc/sphinx/reference/varnish-cli.rst index d6df5e3..549f739 100644 --- a/doc/sphinx/reference/varnish-cli.rst +++ b/doc/sphinx/reference/varnish-cli.rst @@ -97,13 +97,13 @@ start stop Stop the Varnish cache process. -vcl.load +vcl.load [auto|cold|warm] Compile and load the VCL file under the name provided. -vcl.inline +vcl.inline [auto|cold|warm] Compile and load the VCL data under the name provided. -vcl.use +vcl.use [auto|cold|warm] Switch to the named configuration immediately. vcl.discard @@ -130,7 +130,7 @@ panic.clear storage.list List storage devices. -backend.list [] +backend.list [-p] [] List backends. backend.set_health @@ -138,7 +138,7 @@ backend.set_health State is any of auto, healthy or sick values. ban [&& ...] - All objects where the all the conditions match will be marked obsolete. + Mark obsolete all objects where all the conditions match. ban.list List the active bans. diff --git a/include/vcli.h b/include/vcli.h index bd5d726..32d3e70 100644 --- a/include/vcli.h +++ b/include/vcli.h @@ -47,9 +47,8 @@ #define CLI_BAN \ "ban", \ - "ban [&& ]...", \ - "\tAll objects where the all the conditions match will be " \ - "marked obsolete.", \ + "ban [&& ...]", \ + "\tMark obsolete all objects where all the conditions match.", \ 3, UINT_MAX #define CLI_BAN_LIST \ @@ -60,19 +59,19 @@ #define CLI_VCL_LOAD \ "vcl.load", \ - "vcl.load [*auto,cold,warm]", \ + "vcl.load [auto|cold|warm]", \ "\tCompile and load the VCL file under the name provided.", \ 2, 3 #define CLI_VCL_INLINE \ "vcl.inline", \ - "vcl.inline [*auto,cold,warm]", \ + "vcl.inline [auto|cold|warm]", \ "\tCompile and load the VCL data under the name provided.", \ 2, 3 #define CLI_VCL_STATE \ "vcl.state", \ - "vcl.state [auto,cold,warm]", \ + "vcl.state [auto|cold|warm]", \ "\tForce the state of the named configuration.", \ 2, 2 From fgsch at lodoss.net Tue Mar 10 16:54:49 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 10 Mar 2015 17:54:49 +0100 Subject: [master] 7af85ac Update urls Message-ID: commit 7af85ac4560f1bece609bb78926959ca3d242266 Author: Federico G. Schwindt Date: Tue Mar 10 14:07:29 2015 +0000 Update urls diff --git a/doc/changes.rst b/doc/changes.rst index 3b19c53..8b26297 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -464,13 +464,13 @@ Changes from 3.0.5 to 3.0.6rc1 (2014-06-24) - Stop handling gzip after gzip body end. Bug 1086_. - Document %D and %T for varnishncsa. -.. _1514: http://varnish-cache.org/trac/ticket/1514 -.. _1327: http://varnish-cache.org/trac/ticket/1327 -.. _1297: http://varnish-cache.org/trac/ticket/1297 -.. _1470: http://varnish-cache.org/trac/ticket/1470 -.. _1448: http://varnish-cache.org/trac/ticket/1448 -.. _1439: http://varnish-cache.org/trac/ticket/1439 -.. _1086: http://varnish-cache.org/trac/ticket/1086 +.. _1514: https://www.varnish-cache.org/trac/ticket/1514 +.. _1327: https://www.varnish-cache.org/trac/ticket/1327 +.. _1297: https://www.varnish-cache.org/trac/ticket/1297 +.. _1470: https://www.varnish-cache.org/trac/ticket/1470 +.. _1448: https://www.varnish-cache.org/trac/ticket/1448 +.. _1439: https://www.varnish-cache.org/trac/ticket/1439 +.. _1086: https://www.varnish-cache.org/trac/ticket/1086 ============================================= @@ -483,7 +483,7 @@ varnishd - Always check the local address of a socket. This avoids a crash if server.ip is accessed after a client has closed the connection. `Bug #1376` -.. _bug #1376: http://varnish-cache.org/trac/ticket/1376 +.. _bug #1376: https://www.varnish-cache.org/trac/ticket/1376 ================================ @@ -503,9 +503,9 @@ varnishd and things would go downhill from there. `Bug #1367` - Prettify backtraces on panic slightly. -.. _bug #1287: http://varnish-cache.org/trac/ticket/1287 -.. _bug #1272: http://varnish-cache.org/trac/ticket/1272 -.. _bug #1367: http://varnish-cache.org/trac/ticket/1367 +.. _bug #1287: https://www.varnish-cache.org/trac/ticket/1287 +.. _bug #1272: https://www.varnish-cache.org/trac/ticket/1272 +.. _bug #1367: https://www.varnish-cache.org/trac/ticket/1367 varnishlog ---------- @@ -514,14 +514,14 @@ varnishlog to lack of matches. Also, emit BackendXID to signify the start of a transaction. `Bug #1325` -.. _bug #1325: http://varnish-cache.org/trac/ticket/1325 +.. _bug #1325: https://www.varnish-cache.org/trac/ticket/1325 varnishadm ---------- - Handle input from stdin properly. `Bug #1314` -.. _bug #1314: http://varnish-cache.org/trac/ticket/1314 +.. _bug #1314: https://www.varnish-cache.org/trac/ticket/1314 ============================================= @@ -537,8 +537,8 @@ varnishd negatives. CVE-2013-4090. `Bug #1312` - Return an error if the client sends multiple Host headers. -.. _bug #1285: http://varnish-cache.org/trac/ticket/1285 -.. _bug #1312: http://varnish-cache.org/trac/ticket/1312 +.. _bug #1285: https://www.varnish-cache.org/trac/ticket/1285 +.. _bug #1312: https://www.varnish-cache.org/trac/ticket/1312 ================================ @@ -558,11 +558,11 @@ varnishd - Add support for banning on http.status. `Bug #1076` - Make hit-for-pass correctly prefer the transient storage. -.. _bug #1076: http://varnish-cache.org/trac/ticket/1076 -.. _bug #1184: http://varnish-cache.org/trac/ticket/1184 -.. _bug #1224: http://varnish-cache.org/trac/ticket/1224 -.. _bug #1261: http://varnish-cache.org/trac/ticket/1261 -.. _bug #1275: http://varnish-cache.org/trac/ticket/1275 +.. _bug #1076: https://www.varnish-cache.org/trac/ticket/1076 +.. _bug #1184: https://www.varnish-cache.org/trac/ticket/1184 +.. _bug #1224: https://www.varnish-cache.org/trac/ticket/1224 +.. _bug #1261: https://www.varnish-cache.org/trac/ticket/1261 +.. _bug #1275: https://www.varnish-cache.org/trac/ticket/1275 varnishlog @@ -571,7 +571,7 @@ varnishlog - If -m, but neither -b or -c is given, assume both. This filters out a lot of noise when -m is used to filter. `Bug #1071` -.. _bug #1071: http://varnish-cache.org/trac/ticket/1071 +.. _bug #1071: https://www.varnish-cache.org/trac/ticket/1071 varnishadm ---------- @@ -659,27 +659,27 @@ Varnishd - Better error reporting for some fetch errors. - Small performance optimizations. -.. _bug #897: http://varnish-cache.org/trac/ticket/897 -.. _bug #1023: http://varnish-cache.org/trac/ticket/1023 -.. _bug #1029: http://varnish-cache.org/trac/ticket/1029 -.. _bug #1023: http://varnish-cache.org/trac/ticket/1023 -.. _bug #1035: http://varnish-cache.org/trac/ticket/1035 -.. _bug #1037: http://varnish-cache.org/trac/ticket/1037 -.. _bug #1038: http://varnish-cache.org/trac/ticket/1038 -.. _bug #1043: http://varnish-cache.org/trac/ticket/1043 -.. _bug #1044: http://varnish-cache.org/trac/ticket/1044 -.. _bug #1047: http://varnish-cache.org/trac/ticket/1047 -.. _bug #1069: http://varnish-cache.org/trac/ticket/1069 -.. _bug #1073: http://varnish-cache.org/trac/ticket/1073 -.. _bug #1080: http://varnish-cache.org/trac/ticket/1080 -.. _bug #1091: http://varnish-cache.org/trac/ticket/1091 -.. _bug #1092: http://varnish-cache.org/trac/ticket/1092 -.. _bug #1100: http://varnish-cache.org/trac/ticket/1100 -.. _bug #1104: http://varnish-cache.org/trac/ticket/1104 -.. _bug #1109: http://varnish-cache.org/trac/ticket/1109 -.. _bug #1125: http://varnish-cache.org/trac/ticket/1125 -.. _bug #1126: http://varnish-cache.org/trac/ticket/1126 -.. _bug #1140: http://varnish-cache.org/trac/ticket/1140 +.. _bug #897: https://www.varnish-cache.org/trac/ticket/897 +.. _bug #1023: https://www.varnish-cache.org/trac/ticket/1023 +.. _bug #1029: https://www.varnish-cache.org/trac/ticket/1029 +.. _bug #1023: https://www.varnish-cache.org/trac/ticket/1023 +.. _bug #1035: https://www.varnish-cache.org/trac/ticket/1035 +.. _bug #1037: https://www.varnish-cache.org/trac/ticket/1037 +.. _bug #1038: https://www.varnish-cache.org/trac/ticket/1038 +.. _bug #1043: https://www.varnish-cache.org/trac/ticket/1043 +.. _bug #1044: https://www.varnish-cache.org/trac/ticket/1044 +.. _bug #1047: https://www.varnish-cache.org/trac/ticket/1047 +.. _bug #1069: https://www.varnish-cache.org/trac/ticket/1069 +.. _bug #1073: https://www.varnish-cache.org/trac/ticket/1073 +.. _bug #1080: https://www.varnish-cache.org/trac/ticket/1080 +.. _bug #1091: https://www.varnish-cache.org/trac/ticket/1091 +.. _bug #1092: https://www.varnish-cache.org/trac/ticket/1092 +.. _bug #1100: https://www.varnish-cache.org/trac/ticket/1100 +.. _bug #1104: https://www.varnish-cache.org/trac/ticket/1104 +.. _bug #1109: https://www.varnish-cache.org/trac/ticket/1109 +.. _bug #1125: https://www.varnish-cache.org/trac/ticket/1125 +.. _bug #1126: https://www.varnish-cache.org/trac/ticket/1126 +.. _bug #1140: https://www.varnish-cache.org/trac/ticket/1140 varnishncsa ----------- @@ -696,7 +696,7 @@ varnishtest - Make it possible to test for the absence of an HTTP header. `Bug #1062`_. - Log the full panic message instead of shortening it to 512 characters. -.. _bug #1062: http://varnish-cache.org/trac/ticket/1062 +.. _bug #1062: https://www.varnish-cache.org/trac/ticket/1062 varnishstat ----------- @@ -714,7 +714,7 @@ Other - Fix build on FreeBSD 10-current. - Fix libedit detection on \*BSD OSes. `Bug #1003`_. -.. _bug #1003: http://varnish-cache.org/trac/ticket/1003 +.. _bug #1003: https://www.varnish-cache.org/trac/ticket/1003 ============================================= @@ -778,13 +778,13 @@ Varnishd - `http_req_size` and `http_resp_size` have been increased to 8192 bytes. This better matches what other HTTPds have. `Bug #1016`_. -.. _bug #994: http://varnish-cache.org/trac/ticket/994 -.. _bug #992: http://varnish-cache.org/trac/ticket/992 -.. _bug #996: http://varnish-cache.org/trac/ticket/996 -.. _bug #1007: http://varnish-cache.org/trac/ticket/1007 -.. _bug #1008: http://varnish-cache.org/trac/ticket/1008 -.. _bug #1012: http://varnish-cache.org/trac/ticket/1012 -.. _bug #1016: http://varnish-cache.org/trac/ticket/1016 +.. _bug #994: https://www.varnish-cache.org/trac/ticket/994 +.. _bug #992: https://www.varnish-cache.org/trac/ticket/992 +.. _bug #996: https://www.varnish-cache.org/trac/ticket/996 +.. _bug #1007: https://www.varnish-cache.org/trac/ticket/1007 +.. _bug #1008: https://www.varnish-cache.org/trac/ticket/1008 +.. _bug #1012: https://www.varnish-cache.org/trac/ticket/1012 +.. _bug #1016: https://www.varnish-cache.org/trac/ticket/1016 VCL --- @@ -871,8 +871,8 @@ Varnishd object from the same backend unless health probes were enabled. This has been fixed and it will now retry a different backend. -.. _bug #965: http://varnish-cache.org/trac/ticket/965 -.. _bug #963: http://varnish-cache.org/trac/ticket/963 +.. _bug #965: https://www.varnish-cache.org/trac/ticket/965 +.. _bug #963: https://www.varnish-cache.org/trac/ticket/963 VCL --- @@ -883,7 +883,7 @@ VCL - The VCL compiler would fault if two IP comparisons were done on the same line. This now works correctly. `Bug #948`_. -.. _bug #948: http://varnish-cache.org/trac/ticket/948 +.. _bug #948: https://www.varnish-cache.org/trac/ticket/948 varnishncsa ----------- @@ -916,7 +916,7 @@ Other - The ABI of vmods are now checked. This will require a rebuild of all vmods against the new version of Varnish. -.. _bug #961: http://varnish-cache.org/trac/ticket/961 +.. _bug #961: https://www.varnish-cache.org/trac/ticket/961 ============================================= @@ -934,7 +934,7 @@ VCL - The `synthetic` keyword has now been properly marked as only available in `vcl_deliver`. `Bug #936`_. -.. _bug #936: http://varnish-cache.org/trac/ticket/936 +.. _bug #936: https://www.varnish-cache.org/trac/ticket/936 varnishadm ---------- @@ -944,7 +944,7 @@ varnishadm - Always exit if `varnishadm` can't connect to the backend for any reason. -.. _bug #935: http://varnish-cache.org/trac/ticket/935 +.. _bug #935: https://www.varnish-cache.org/trac/ticket/935 ===================================== @@ -966,7 +966,7 @@ Varnishd single-threaded so we do not want to do this work there in the first place. Use varnishstat instead. -.. _bug #908: http://varnish-cache.org/trac/ticket/908 +.. _bug #908: https://www.varnish-cache.org/trac/ticket/908 VCL --- @@ -985,7 +985,7 @@ VCL - Varnish is now stricter in enforcing no duplication of probes, backends and ACLs. -.. _bug #913: http://varnish-cache.org/trac/ticket/913 +.. _bug #913: https://www.varnish-cache.org/trac/ticket/913 varnishncsa ----------- @@ -1088,12 +1088,12 @@ Varnishd administrator errors when specifying the size of storage where the admin might have forgotten to specify units. -.. _bug #693: http://varnish-cache.org/trac/ticket/693 -.. _bug #683: http://varnish-cache.org/trac/ticket/683 -.. _bug #663: http://varnish-cache.org/trac/ticket/663 -.. _bug #880: http://varnish-cache.org/trac/ticket/880 -.. _bug #411: http://varnish-cache.org/trac/ticket/411 -.. _bug #693: http://varnish-cache.org/trac/ticket/693 +.. _bug #693: https://www.varnish-cache.org/trac/ticket/693 +.. _bug #683: https://www.varnish-cache.org/trac/ticket/683 +.. _bug #663: https://www.varnish-cache.org/trac/ticket/663 +.. _bug #880: https://www.varnish-cache.org/trac/ticket/880 +.. _bug #411: https://www.varnish-cache.org/trac/ticket/411 +.. _bug #693: https://www.varnish-cache.org/trac/ticket/693 Tools ----- @@ -1115,7 +1115,7 @@ varnishadm shared memory log file - add libedit support -.. _bug #875: http://varnish-cache.org/trac/ticket/875 +.. _bug #875: https://www.varnish-cache.org/trac/ticket/875 varnishstat *********** @@ -1135,8 +1135,8 @@ varnishncsa log formats are supported, as well as some Varnish-specific ones. See the documentation for further information. `Bug #712`_ and `bug #485`_ -.. _bug #712: http://varnish-cache.org/trac/ticket/712 -.. _bug #485: http://varnish-cache.org/trac/ticket/485 +.. _bug #712: https://www.varnish-cache.org/trac/ticket/712 +.. _bug #485: https://www.varnish-cache.org/trac/ticket/485 varnishtest *********** @@ -1211,9 +1211,9 @@ VCL - Add actual purge support. Doing ``purge`` will remove an object and all its variants. -.. _bug #481: http://varnish-cache.org/trac/ticket/481 -.. _bug #787: http://varnish-cache.org/trac/ticket/787 -.. _bug #782: http://varnish-cache.org/trac/ticket/782 +.. _bug #481: https://www.varnish-cache.org/trac/ticket/481 +.. _bug #787: https://www.varnish-cache.org/trac/ticket/787 +.. _bug #782: https://www.varnish-cache.org/trac/ticket/782 Libraries @@ -2087,7 +2087,7 @@ varnishd to POST. - Change how backends are defined, to a constant structural defintion - style. See http://varnish.projects.linpro.no/wiki/VclSyntaxChanges + style. See https://www.varnish-cache.org/wiki/VclSyntaxChanges for the details. - Add directors, which wrap backends. Currently, there's a random @@ -2198,18 +2198,18 @@ varnishd - When switching to a new VCL configuration, a race condition exists which may cause Varnish to reference a backend which no longer exists - (see `ticket #144 `_). + (see `ticket #144 `_). This race condition has not been entirely eliminated, but it should occur less frequently. - When dropping a TCP session before any requests were processed, an assertion would be triggered due to an uninitialized timestamp (see - `ticket #132 `_). The + `ticket #132 `_). The timestamp is now correctly initialized. - Varnish will now correctly generate a Date: header for every response instead of copying the one it got from the backend (see `ticket - #157 `_). + #157 `_). - Comparisons in VCL which involve a non-existent string (usually a header which is not present in the request or object being processed) @@ -2226,7 +2226,7 @@ varnishd end up with a reference to an address structure which no longer exists, resulting in a crash. This race condition has been somewhat mitigated, but not entirely eliminated (see `ticket - #144 `_.) + #144 `_.) - Varnish will now pass the correct protocol version in pipe mode: the backend will get what the client sent, and vice versa. @@ -2244,12 +2244,12 @@ varnishd serviced, resulting in a assertion failure and a crash when the worker thread later tried to delete the session. This should no longer happen (see `ticket - #162 `_.) + #162 `_.) - A mismatch between the recorded length of a cached object and the amount of data actually present in cache for that object can occasionally occur (see `ticket - #167 `_.) This has been + #167 `_.) This has been partially fixed, but may still occur for error pages generated by Varnish when a problem arises while retrieving an object from the backend. @@ -2552,7 +2552,7 @@ varnishd new VCL hooks have been added, though they aren't much use yet. The only real user-visible change should be that Varnish now handles persistent backend connections correctly (see `ticket - #56 `_). + #56 `_). - Support for multiple listen addresses has been added. @@ -2628,7 +2628,7 @@ varnishlog corresponding return from VCL. When two VCL calls were made in succession, varnishlog would incorrectly omit the newline between the two calls (see `ticket - #95 `_). + #95 `_). - New -D and -P command-line options have been added to daemonize and create a pidfile, respectively. diff --git a/doc/sphinx/index.rst b/doc/sphinx/index.rst index 1adb5fe..6b9716c 100644 --- a/doc/sphinx/index.rst +++ b/doc/sphinx/index.rst @@ -29,7 +29,7 @@ Conventions used in this manual include: `/usr/local/`, `varnishadm`, `sess_timeout` A utility, Varnish configurable parameter or path. - http://www.varnish-cache.org/ + https://www.varnish-cache.org/ A hyperlink. Longer listings like example command output and VCL look like this:: diff --git a/doc/sphinx/installation/help.rst b/doc/sphinx/installation/help.rst index 2d04c5f..14746e7 100644 --- a/doc/sphinx/installation/help.rst +++ b/doc/sphinx/installation/help.rst @@ -82,8 +82,8 @@ from people who forgot to check back on already opened Tickets. .. XXX: Not sure what you want with the last sentence above. benc -We instead track suggestions and feature ideas in our `"Shopping-List" wiki page`_, and through user -support via email and IRC. +We instead track suggestions and feature ideas in our `"Future_Feature" wiki page`_, +and through user support via email and IRC. Commercial Support ================== @@ -98,7 +98,7 @@ an email to phk at FreeBSD.org. UPLEX info at uplex.de -.. _mailman: http://lists.varnish-cache.org/mailman/listinfo -.. _pastebin: http://gist.github.com/ -.. _"Shopping-List" wiki page: http://varnish-cache.org/wiki/PostTwoShoppingList -.. _wiki: https://www.varnish-cache.org/trac +.. _mailman: https://www.varnish-cache.org/lists/mailman/listinfo +.. _pastebin: https://gist.github.com/ +.. _"Future_Feature" wiki page: https://www.varnish-cache.org/trac/wiki/Future_Feature +.. _wiki: https://www.varnish-cache.org/trac diff --git a/doc/sphinx/installation/install.rst b/doc/sphinx/installation/install.rst index fca2b18..f5886cb 100644 --- a/doc/sphinx/installation/install.rst +++ b/doc/sphinx/installation/install.rst @@ -33,7 +33,7 @@ Red Hat / CentOS We try to keep the latest version available as prebuilt RPMs (el5 and el6) on `repo.varnish-cache.org `_. See the online `Red Hat installation instructions -`_ for more information. +`_ for more information. Varnish is included in the `EPEL `_ repository, however due to @@ -50,8 +50,8 @@ Varnish up and running type ``sudo apt-get install varnish``. Please note that this might not be the latest version of Varnish. If you need a later version of Varnish, please follow the online installation instructions for `Debian -`_ or `Ubuntu -`_. +`_ or `Ubuntu +`_. Compiling Varnish from source diff --git a/doc/sphinx/phk/http20.rst b/doc/sphinx/phk/http20.rst index e2a6ed0..9860cab 100644 --- a/doc/sphinx/phk/http20.rst +++ b/doc/sphinx/phk/http20.rst @@ -305,7 +305,7 @@ Author of Varnish [1] http://trac.tools.ietf.org/wg/httpbis/trac/wiki/Http2CfI -[2] http://varnish-cache.org/ +[2] https://www.varnish-cache.org/ [3] Yes, I'm that old. diff --git a/doc/sphinx/users-guide/increasing-your-hitrate.rst b/doc/sphinx/users-guide/increasing-your-hitrate.rst index be76f2b..d55b50c 100644 --- a/doc/sphinx/users-guide/increasing-your-hitrate.rst +++ b/doc/sphinx/users-guide/increasing-your-hitrate.rst @@ -41,7 +41,7 @@ For more information on how `varnishlog` works please see :ref:`users-guide-logging` or man :ref:`ref-varnishlog`. For extended diagnostics headers, see -http://www.varnish-cache.org/trac/wiki/VCLExampleHitMissHeader +https://www.varnish-cache.org/trac/wiki/VCLExampleHitMissHeader Tool: lwp-request diff --git a/etc/devicedetect.vcl b/etc/devicedetect.vcl index 1606628..be311c5 100644 --- a/etc/devicedetect.vcl +++ b/etc/devicedetect.vcl @@ -22,7 +22,7 @@ # SUCH DAMAGE. # # detectdevice.vcl - regex based device detection for Varnish -# http://github.com/varnish/varnish-devicedetect/ +# https://github.com/varnish/varnish-devicedetect/ # # Author: Lasse Karstensen diff --git a/etc/example.vcl b/etc/example.vcl index eefdd9c..8302c26 100644 --- a/etc/example.vcl +++ b/etc/example.vcl @@ -6,7 +6,7 @@ # return statement. # # See the VCL chapters in the Users Guide at https://www.varnish-cache.org/docs/ -# and http://varnish-cache.org/trac/wiki/VCLExamples for more examples. +# and https://www.varnish-cache.org/trac/wiki/VCLExamples for more examples. # Marker to tell the VCL compiler that this VCL has been adapted to the # new 4.0 format. From phk at FreeBSD.org Tue Mar 10 19:29:17 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 10 Mar 2015 20:29:17 +0100 Subject: [master] acf8703 Add a facility for sending a string a number of times. Message-ID: commit acf8703d8d7e12c359aacb7b27fb1cf84f4bc43a Author: Poul-Henning Kamp Date: Tue Mar 10 19:28:54 2015 +0000 Add a facility for sending a string a number of times. diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index 68aacde..db0d265 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -997,6 +997,34 @@ cmd_http_send(CMD_ARGS) } /********************************************************************** + * Send a string many times + */ + +static void +cmd_http_send_n(CMD_ARGS) +{ + struct http *hp; + int i, n, l; + + (void)cmd; + (void)vl; + CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); + AN(av[1]); + AN(av[2]); + AZ(av[3]); + n = strtoul(av[1], NULL, 0); + vtc_dump(hp->vl, 4, "send_n", av[2], -1); + l = strlen(av[2]); + while (n--) { + i = write(hp->fd, av[2], l); + if (i != l) + vtc_log(hp->vl, hp->fatal, + "Write error in http_send(): %s", + strerror(errno)); + } +} + +/********************************************************************** * Send a hex string */ @@ -1260,6 +1288,7 @@ static const struct cmds http_cmds[] = { { "gunzip", cmd_http_gunzip_body }, { "expect", cmd_http_expect }, { "send", cmd_http_send }, + { "send_n", cmd_http_send_n }, { "sendhex", cmd_http_sendhex }, { "chunked", cmd_http_chunked }, { "chunkedlen", cmd_http_chunkedlen }, From nils.goroll at uplex.de Tue Mar 10 22:55:29 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Tue, 10 Mar 2015 23:55:29 +0100 Subject: [master] 780eace Add a flag to mark 304 backend response processing (aka Backend IMS/INM) Message-ID: commit 780eace6120c4a94a0620f70c8ed4e1386d7bf1f Author: Nils Goroll Date: Tue Mar 10 23:55:10 2015 +0100 Add a flag to mark 304 backend response processing (aka Backend IMS/INM) This is a compromise discussed at VDD15Q1 after a previous suggestion to expose the 304 response status directly to VCL. This way, VCL can differenciate between 200 and 304 responses, but simpler processing logic just checking for status 200 can be preserved where differenciating is not required. diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index 664bf3d..1c59ab5 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -254,7 +254,7 @@ vbf_stp_retry(struct worker *wrk, struct busyobj *bo) static enum fetch_step vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo) { - int i, do_ims = 0; + int i; double now; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); @@ -385,6 +385,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo) bo->fetch_objcore->exp.ttl = -1.; AZ(bo->do_esi); + AZ(bo->was_304); if (http_IsStatus(bo->beresp, 304)) { if (bo->stale_oc != NULL && @@ -401,7 +402,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo) http_Unset(bo->beresp, H_Content_Length); HTTP_Merge(bo->wrk, bo->stale_oc, bo->beresp); assert(http_IsStatus(bo->beresp, 200)); - do_ims = 1; + bo->was_304 = 1; } else if (!bo->do_pass) { /* * Backend sent unallowed 304 @@ -451,7 +452,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo) assert(wrk->handling == VCL_RET_DELIVER); - return (do_ims ? F_STP_CONDFETCH : F_STP_FETCH); + return (bo->was_304 ? F_STP_CONDFETCH : F_STP_FETCH); } /*-------------------------------------------------------------------- diff --git a/bin/varnishtest/tests/b00039.vtc b/bin/varnishtest/tests/b00039.vtc index d076290..397006d 100644 --- a/bin/varnishtest/tests/b00039.vtc +++ b/bin/varnishtest/tests/b00039.vtc @@ -13,6 +13,7 @@ varnish v1 -vcl+backend { set beresp.ttl = 2s; set beresp.grace = 20s; set beresp.keep = 1m; + set beresp.http.was-304 = beresp.was_304; } } -start @@ -21,6 +22,7 @@ client c1 { rxresp expect resp.status == 200 expect resp.body == "Geoff Rules" + expect resp.http.was-304 == "false" } -run delay 3 @@ -30,6 +32,7 @@ client c1 { rxresp expect resp.status == 200 expect resp.body == "Geoff Rules" + expect resp.http.was-304 == "false" } -run client c1 { @@ -37,4 +40,5 @@ client c1 { rxresp expect resp.status == 200 expect resp.body == "Geoff Rules" + expect resp.http.was-304 == "true" } -run diff --git a/doc/sphinx/users-guide/vcl-built-in-subs.rst b/doc/sphinx/users-guide/vcl-built-in-subs.rst index cd78355..8b00232 100644 --- a/doc/sphinx/users-guide/vcl-built-in-subs.rst +++ b/doc/sphinx/users-guide/vcl-built-in-subs.rst @@ -277,6 +277,25 @@ vcl_backend_response Called after the response headers have been successfully retrieved from the backend. +For a 304 response, varnish core code amends ``beresp`` before calling +`vcl_backend_response`: + +* If the gzip status changed, ``Content-Encoding`` is unset and any + ``Etag`` is weakened + +* Any headers not present in the 304 response are copied from the + existing cache object. ``Content-Length`` is copied if present in + the existing cache object and discarded otherwise. + +* The status gets set to 200. + +`beresp.was_304` marks that this conditional response processing has +happened. + +Note: Backend conditional requests are independend of client +conditional requests, so clients may receive 304 responses no matter +if a backend request was conditional. + The `vcl_backend_response` subroutine may terminate with calling ``return()`` with one of the following keywords: diff --git a/include/tbl/bo_flags.h b/include/tbl/bo_flags.h index bc01dbe..dac83b2 100644 --- a/include/tbl/bo_flags.h +++ b/include/tbl/bo_flags.h @@ -39,5 +39,6 @@ BO_FLAG(uncacheable, 0, 0, "") BO_FLAG(abandon, 0, 0, "") BO_FLAG(is_gzip, 0, 0, "") BO_FLAG(is_gunzip, 0, 0, "") +BO_FLAG(was_304, 1, 0, "") /*lint -restore */ diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 448cec8..871b8bc 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -461,6 +461,15 @@ sp_variables = [ cache. Defaults to false. """ ), + ('beresp.was_304', + 'BOOL', + ( 'backend_response', 'backend_error'), + ( ), """ + Boolean. If this is a successful 304 response to a + backend conditional request refreshing an existing + cache object. + """ + ), ('beresp.uncacheable', 'BOOL', ( 'backend_response', 'backend_error'), From phk at FreeBSD.org Wed Mar 11 08:41:42 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 09:41:42 +0100 Subject: [master] 95bf11c Also remove the pid-file when we stop because CLI on stdin closed. Message-ID: commit 95bf11c9dde1e57cdce2bfda1f1da18dff6e191d Author: Poul-Henning Kamp Date: Wed Mar 11 08:31:02 2015 +0000 Also remove the pid-file when we stop because CLI on stdin closed. diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 7864a15..b7fc72f 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -68,6 +68,8 @@ struct vsb *vident; struct VSC_C_mgt static_VSC_C_mgt; struct VSC_C_mgt *VSC_C_mgt; +static struct vpf_fh *pfh = NULL; + /*--------------------------------------------------------------------*/ static void @@ -286,6 +288,8 @@ cli_stdin_close(void *priv) if (d_flag) { mgt_stop_child(); mgt_cli_close_all(); + if (pfh != NULL) + (void)VPF_Remove(pfh); exit(0); } } @@ -376,7 +380,6 @@ main(int argc, char * const *argv) const char *T_arg = "localhost:0"; char *p, *vcl = NULL; struct cli cli[1]; - struct vpf_fh *pfh = NULL; char *dirname; char **av; unsigned clilim; From phk at FreeBSD.org Wed Mar 11 08:41:42 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 09:41:42 +0100 Subject: [master] 0c9897a An assert to guard against a problem spotted in 4.0 Message-ID: commit 0c9897a128a645c79cbaff5bfdd3c457f1ec691f Author: Poul-Henning Kamp Date: Wed Mar 11 08:37:08 2015 +0000 An assert to guard against a problem spotted in 4.0 diff --git a/bin/varnishd/http1/cache_http1_vfp.c b/bin/varnishd/http1/cache_http1_vfp.c index 5c712bd..70e0e03 100644 --- a/bin/varnishd/http1/cache_http1_vfp.c +++ b/bin/varnishd/http1/cache_http1_vfp.c @@ -55,6 +55,7 @@ v1f_read(const struct vfp_ctx *vc, struct http_conn *htc, void *d, size_t len) CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC); CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); + assert(len >= 0); l = 0; p = d; if (htc->pipeline_b) { From phk at FreeBSD.org Wed Mar 11 08:41:42 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 09:41:42 +0100 Subject: [master] 7dd4e73 Be consistent about signed-ness. Message-ID: commit 7dd4e7392918be36c01684d50de6c250f0341f9f Author: Poul-Henning Kamp Date: Wed Mar 11 08:41:18 2015 +0000 Be consistent about signed-ness. diff --git a/bin/varnishd/http1/cache_http1_vfp.c b/bin/varnishd/http1/cache_http1_vfp.c index 70e0e03..90ac22e 100644 --- a/bin/varnishd/http1/cache_http1_vfp.c +++ b/bin/varnishd/http1/cache_http1_vfp.c @@ -47,7 +47,7 @@ */ static ssize_t -v1f_read(const struct vfp_ctx *vc, struct http_conn *htc, void *d, size_t len) +v1f_read(const struct vfp_ctx *vc, struct http_conn *htc, void *d, ssize_t len) { ssize_t l; unsigned char *p; From phk at FreeBSD.org Wed Mar 11 09:31:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 10:31:46 +0100 Subject: [master] b8ee9ea Make this assert even more precise. Message-ID: commit b8ee9ea7aa2f9bfe2a341558e1b85efe9de14868 Author: Poul-Henning Kamp Date: Wed Mar 11 09:31:32 2015 +0000 Make this assert even more precise. diff --git a/bin/varnishd/http1/cache_http1_vfp.c b/bin/varnishd/http1/cache_http1_vfp.c index 90ac22e..99d87da 100644 --- a/bin/varnishd/http1/cache_http1_vfp.c +++ b/bin/varnishd/http1/cache_http1_vfp.c @@ -55,7 +55,7 @@ v1f_read(const struct vfp_ctx *vc, struct http_conn *htc, void *d, ssize_t len) CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC); CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); - assert(len >= 0); + assert(len > 0); l = 0; p = d; if (htc->pipeline_b) { From phk at FreeBSD.org Wed Mar 11 09:51:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 10:51:46 +0100 Subject: [master] c56b6ee Make it possible to test that a shell command fails with a specific wait/exit code. Message-ID: commit c56b6ee1877dfc7a1556c425473a55e2b2b69556 Author: Poul-Henning Kamp Date: Wed Mar 11 09:50:57 2015 +0000 Make it possible to test that a shell command fails with a specific wait/exit code. diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c index 6abc7bb..4cf7941 100644 --- a/bin/varnishtest/vtc.c +++ b/bin/varnishtest/vtc.c @@ -420,6 +420,30 @@ cmd_shell(CMD_ARGS) r = system(av[1]); AZ(WEXITSTATUS(r)); } +/********************************************************************** + * Shell command execution + */ + +static void +cmd_shell_err(CMD_ARGS) +{ + (void)priv; + (void)cmd; + int r; + + if (av == NULL) + return; + AN(av[1]); + AN(av[2]); + AZ(av[3]); + vtc_dump(vl, 4, "shell_err", av[2], -1); + r = system(av[2]); + vtc_log(vl, 4, "shell status: 0x%x", r); + if (strtol(av[1], NULL, 0) != r) + vtc_log(vl, 0, "Wrong shell status: 0x%x", r); + else + vtc_log(vl, 4, "Expected shell status: 0x%x", r); +} /********************************************************************** * Dump command arguments @@ -545,6 +569,7 @@ static const struct cmds cmds[] = { { "delay", cmd_delay }, { "varnishtest",cmd_varnishtest }, { "shell", cmd_shell }, + { "shell_err", cmd_shell_err }, { "sema", cmd_sema }, { "random", cmd_random }, { "feature", cmd_feature }, From phk at FreeBSD.org Wed Mar 11 09:51:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 10:51:46 +0100 Subject: [master] af8cc5b Add a testcase to see that PID file locking works Message-ID: commit af8cc5b9a55aa934c9d7d5a5dae9a18876df65ad Author: Poul-Henning Kamp Date: Wed Mar 11 09:51:25 2015 +0000 Add a testcase to see that PID file locking works diff --git a/bin/varnishtest/tests/b00045.vtc b/bin/varnishtest/tests/b00045.vtc new file mode 100644 index 0000000..a98abeb --- /dev/null +++ b/bin/varnishtest/tests/b00045.vtc @@ -0,0 +1,18 @@ +varnishtest "Check Pid file locking" + +server s1 { + rxreq + send "HTTP/1.1 200 OK\nContent-Length: dupa" + send_n 15865 "\n" +} -start + +varnish v1 -vcl+backend {} -start + +client c1 { + txreq + rxresp +} -run + +delay .2 + +shell_err 0x200 "${varnishd} -P ${tmpdir}/v1/varnishd.pid -b 127.0.0.1:80 -a :0 -n ${tmpdir} > /dev/null 2>&1" From arianna.aondio at varnish-software.com Wed Mar 11 09:54:45 2015 From: arianna.aondio at varnish-software.com (Arianna Aondio) Date: Wed, 11 Mar 2015 10:54:45 +0100 Subject: [master] d7695e4 If VRB_cache() is called with a POST body larger than the provided size limitation, the request fails and the connection is closed. Message-ID: commit d7695e488a003bd7b89279c50990864d4763dd8f Author: Arianna Aondio Date: Wed Mar 11 10:46:02 2015 +0100 If VRB_cache() is called with a POST body larger than the provided size limitation, the request fails and the connection is closed. Fixes #1664 diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c index c73db54..c3965ce 100644 --- a/bin/varnishd/cache/cache_req_body.c +++ b/bin/varnishd/cache/cache_req_body.c @@ -218,9 +218,10 @@ VRB_Cache(struct req *req, ssize_t maxsize) CHECK_OBJ_NOTNULL(req->htc, HTTP_CONN_MAGIC); vfc = req->htc->vfc; + VFP_Setup(vfc); + vfc->wrk = req->wrk; if (req->htc->content_length > maxsize) { - // XXX #1664 req->req_body_status = REQ_BODY_FAIL; (void)VFP_Error(vfc, "Request body too big to cache"); return (-1); @@ -230,9 +231,7 @@ VRB_Cache(struct req *req, ssize_t maxsize) AN(req->body_oc); XXXAN(STV_NewObject(req->body_oc, req->wrk, TRANSIENT_STORAGE, 8)); - VFP_Setup(vfc); vfc->http = req->http; - vfc->wrk = req->wrk; vfc->oc = req->body_oc; V1F_Setup_Fetch(vfc, req->htc); @@ -248,6 +247,12 @@ VRB_Cache(struct req *req, ssize_t maxsize) yet = 0; do { AZ(vfc->failed); + if (req->req_bodybytes > maxsize) { + req->req_body_status = REQ_BODY_FAIL; + (void)VFP_Error(vfc, "Request body too big to cache"); + VFP_Close(vfc); + return(-1); + } l = yet; if (VFP_GetStorage(vfc, &l, &ptr) != VFP_OK) break; diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index b74c66b..3ad045f 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -607,8 +607,10 @@ cnt_recv(struct worker *wrk, struct req *req) VCL_recv_method(req->vcl, wrk, req, NULL, req->http->ws); /* Attempts to cache req.body may fail */ - if (req->req_body_status == REQ_BODY_FAIL) + if (req->req_body_status == REQ_BODY_FAIL) { + req->doclose = SC_RX_BODY; return (REQ_FSM_DONE); + } recv_handling = wrk->handling; diff --git a/bin/varnishtest/tests/c00055.vtc b/bin/varnishtest/tests/c00055.vtc index 5f525d0..154c15c 100644 --- a/bin/varnishtest/tests/c00055.vtc +++ b/bin/varnishtest/tests/c00055.vtc @@ -69,5 +69,10 @@ client c1 { expect resp.status == 200 expect resp.http.X-BodyBytes == 0 } -run + +client c2 { + txreq -req POST -nolen -hdr "Content-Length: 1025" + expect_close +} -run varnish v1 -stop logexpect l1 -wait diff --git a/bin/varnishtest/tests/c00067.vtc b/bin/varnishtest/tests/c00067.vtc index 427042b..744cbcd 100644 --- a/bin/varnishtest/tests/c00067.vtc +++ b/bin/varnishtest/tests/c00067.vtc @@ -34,7 +34,7 @@ varnish v1 -vcl+backend { import ${vmod_std}; sub vcl_recv { - std.cache_req_body(1000B); + std.cache_req_body(110B); } } @@ -42,12 +42,6 @@ client c1 { txreq -req POST -nolen -hdr "Transfer-encoding: chunked" chunked {BLAS} delay .2 - chunkedlen 100 - delay .2 - chunked {TFOO} - delay .2 - chunkedlen 0 - rxresp - expect resp.status == 200 - expect resp.bodylen == 5 + chunkedlen 110 + expect_close } -run From phk at FreeBSD.org Wed Mar 11 10:03:07 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 11:03:07 +0100 Subject: [master] 47ef1a8 Oops, that was a bad VTC file to copy&paste from... Message-ID: commit 47ef1a84a62cb4f3f7094ae6e5b25cc7f9af5c02 Author: Poul-Henning Kamp Date: Wed Mar 11 10:02:35 2015 +0000 Oops, that was a bad VTC file to copy&paste from... diff --git a/bin/varnishtest/tests/b00045.vtc b/bin/varnishtest/tests/b00045.vtc index a98abeb..3518617 100644 --- a/bin/varnishtest/tests/b00045.vtc +++ b/bin/varnishtest/tests/b00045.vtc @@ -2,8 +2,7 @@ varnishtest "Check Pid file locking" server s1 { rxreq - send "HTTP/1.1 200 OK\nContent-Length: dupa" - send_n 15865 "\n" + txresp } -start varnish v1 -vcl+backend {} -start From nils.goroll at uplex.de Wed Mar 11 12:27:00 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 11 Mar 2015 13:27:00 +0100 Subject: [master] 43135bd cheesy speling Message-ID: commit 43135bdea4b40c2b68d0850b4446a6cc7f46d7ea Author: Nils Goroll Date: Wed Mar 11 13:26:56 2015 +0100 cheesy speling diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c index d93aee4..0b2d1b9 100644 --- a/bin/varnishd/cache/cache_ws.c +++ b/bin/varnishd/cache/cache_ws.c @@ -90,7 +90,7 @@ WS_MarkOverflow(struct ws *ws) { CHECK_OBJ_NOTNULL(ws, WS_MAGIC); - ws->id[0] &= ~0x40; // Cheasy toupper() + ws->id[0] &= ~0x40; // cheesy toupper() } static void @@ -98,7 +98,7 @@ ws_ClearOverflow(struct ws *ws) { CHECK_OBJ_NOTNULL(ws, WS_MAGIC); - ws->id[0] |= 0x40; // Cheasy tolower() + ws->id[0] |= 0x40; // cheesy tolower() } /* From martin at varnish-software.com Wed Mar 11 13:35:11 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Wed, 11 Mar 2015 14:35:11 +0100 Subject: [4.0] 36f01d5 Add a VDP_pretend_gzip for use with synth bodies in ESI includes with gzip Message-ID: commit 36f01d5b81ae449ecd532f1eafae32a11e8231c3 Author: Martin Blix Grydeland Date: Wed Mar 11 14:29:02 2015 +0100 Add a VDP_pretend_gzip for use with synth bodies in ESI includes with gzip Varnishtest: NUL terminate the ungzip'ed body so we can expect on it. Fixes #1688 diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 660d6b7..9727a52 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -982,6 +982,7 @@ enum vgzret_e VGZ_Gzip(struct vgz *, const void **, size_t *len, enum vgz_flag); enum vgzret_e VGZ_Gunzip(struct vgz *, const void **, size_t *len); enum vgzret_e VGZ_Destroy(struct vgz **); void VGZ_UpdateObj(const struct vgz*, struct object *); +vdp_bytes VDP_pretend_gzip; vdp_bytes VDP_gunzip; int VGZ_WrwInit(struct vgz *vg); diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c index bdbf229..670704a 100644 --- a/bin/varnishd/cache/cache_gzip.c +++ b/bin/varnishd/cache/cache_gzip.c @@ -43,6 +43,7 @@ #include "cache.h" +#include "vend.h" #include "vgz.h" struct vgz { @@ -280,6 +281,47 @@ VGZ_WrwInit(struct vgz *vg) } /*-------------------------------------------------------------------- + * VDP for pretend gzip + */ + +int __match_proto__(vdp_bytes) +VDP_pretend_gzip(struct req *req, enum vdp_action act, const void *ptr, + ssize_t len) +{ + uint8_t buf[5]; + const uint8_t *p; + uint16_t lx; + + CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + CHECK_OBJ_NOTNULL(req->wrk, WORKER_MAGIC); + + if (len == 0) { + assert(act > VDP_NULL); + return (VDP_bytes(req, act, ptr, len)); + } + + lx = 65535; + p = ptr; + while (len > 0) { + if (lx > len) + lx = (uint16_t)len; + buf[0] = 0; + vle16enc(buf + 1, lx); + vle16enc(buf + 3, ~lx); + if (VDP_bytes(req, VDP_NULL, buf, sizeof buf)) + return (-1); + if (VDP_bytes(req, VDP_FLUSH, p, lx)) + return (-1); + req->crc = crc32(req->crc, p, lx); + req->l_crc += lx; + len -= lx; + assert(len >= 0); + p += lx; + } + return (0); +} + +/*-------------------------------------------------------------------- * VDP for gunzip'ing */ diff --git a/bin/varnishd/cache/cache_http1_deliver.c b/bin/varnishd/cache/cache_http1_deliver.c index e0a9618..090d83d 100644 --- a/bin/varnishd/cache/cache_http1_deliver.c +++ b/bin/varnishd/cache/cache_http1_deliver.c @@ -394,6 +394,9 @@ V1D_Deliver_Synth(struct req *req) req->vdps[0] = v1d_bytes; req->vdp_nxt = 0; + if (req->gzip_resp) + req->vdps[++req->vdp_nxt] = VDP_pretend_gzip; + WRW_Reserve(req->wrk, &req->sp->fd, req->vsl, req->t_prev); /* @@ -411,11 +414,6 @@ V1D_Deliver_Synth(struct req *req) if (!req->wantbody) { /* This was a HEAD or conditional request */ -#if 0 - XXX: Missing pretend GZIP for esi-children - } else if (req->res_mode & RES_ESI_CHILD && req->gzip_resp) { - ESI_DeliverChild(req); -#endif } else { (void)VDP_bytes(req, VDP_FLUSH, VSB_data(req->synth_body), VSB_len(req->synth_body)); diff --git a/bin/varnishtest/tests/r01688.vtc b/bin/varnishtest/tests/r01688.vtc new file mode 100644 index 0000000..fd0373b --- /dev/null +++ b/bin/varnishtest/tests/r01688.vtc @@ -0,0 +1,45 @@ +varnishtest "ESI-included, compressed synthetic responses" + +server s1 { + rxreq + expect req.url == "/bar" + txresp -gzipbody {} + rxreq + expect req.url == "/baz" + txresp -gzipbody {} +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.url == "/foo" || req.url == "/quux") { + return(synth(998, "included synthetic reponse")); + } + } + + sub vcl_synth { + if (resp.status == 998) { + synthetic("this is the body of an included synthetic response"); + return(deliver); + } + } + + sub vcl_backend_response { + set beresp.do_esi = true; + } +} -start + +client c1 { + txreq -url /bar + rxresp + expect resp.status == 200 + delay .1 + expect resp.body == "this is the body of an included synthetic response" + + txreq -url /baz -hdr "Accept-Encoding: gzip" + timeout 2 + rxresp + expect resp.status == 200 + expect resp.http.Content-Encoding == "gzip" + gunzip + expect resp.body == "this is the body of an included synthetic response" +} -run diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index 8283c68..579b981 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -630,6 +630,7 @@ cmd_http_gunzip_body(CMD_ARGS) assert(Z_OK == inflateInit2(&vz, 31)); i = inflate(&vz, Z_FINISH); + assert(vz.total_out < l); hp->bodyl = vz.total_out; memcpy(hp->body, p, hp->bodyl); free(p); @@ -650,6 +651,7 @@ cmd_http_gunzip_body(CMD_ARGS) "Gunzip error = %d (%s) in:%jd out:%jd", i, vz.msg, (intmax_t)vz.total_in, (intmax_t)vz.total_out); assert(Z_OK == inflateEnd(&vz)); + hp->body[hp->bodyl] = '\0'; } /********************************************************************** From nils.goroll at uplex.de Wed Mar 11 14:52:43 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Wed, 11 Mar 2015 15:52:43 +0100 Subject: [master] aacdd6d Add PRIV_TOP for per "top request" / req->top state Message-ID: commit aacdd6dee06edbddfa12fa3a3cfcaf24a4354a86 Author: Nils Goroll Date: Wed Mar 11 15:52:39 2015 +0100 Add PRIV_TOP for per "top request" / req->top state diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c index 9ece734..a2052d4 100644 --- a/bin/varnishd/cache/cache_vrt_priv.c +++ b/bin/varnishd/cache/cache_vrt_priv.c @@ -122,6 +122,22 @@ VRT_priv_task(VRT_CTX, void *vmod_id) return (VRT_priv_dynamic(ctx, id, (uintptr_t)vmod_id)); } +struct vmod_priv * +VRT_priv_top(VRT_CTX, void *vmod_id) +{ + uintptr_t id; + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + if (ctx->req) { + CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); + CHECK_OBJ_NOTNULL(ctx->req->top, REQ_MAGIC); + id = (uintptr_t)&ctx->req->top->top; + } else { + return NULL; + } + return (VRT_priv_dynamic(ctx, id, (uintptr_t)vmod_id)); +} + /*-------------------------------------------------------------------- */ diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index b2b6470..866e914 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -160,6 +160,7 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req) req->restarts = 0; AZ(req->esi_level); + assert(req->top == req); if (req->vcl != NULL) { if (wrk->vcl != NULL) @@ -169,6 +170,8 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req) } VRTPRIV_dynamic_kill(sp->privs, (uintptr_t)req); + VRTPRIV_dynamic_kill(sp->privs, (uintptr_t)&req->top); + /* Charge and log byte counters */ AN(req->vsl->wid); CNT_AcctLogCharge(wrk->stats, req); diff --git a/bin/varnishtest/tests/v00043.vtc b/bin/varnishtest/tests/v00043.vtc new file mode 100644 index 0000000..ae562a7 --- /dev/null +++ b/bin/varnishtest/tests/v00043.vtc @@ -0,0 +1,70 @@ +varnishtest "Test PRIV_TOP" + +# same as v00042.vtc, but the priv remains the same across esi includes + +server s1 { + rxreq + expect req.url == "/a" + expect req.http.x0 == "/a0" + expect req.http.x1 == "/a0" + txresp -body { + + + } + + rxreq + expect req.url == "/foo" + expect req.http.x0 == "/a0" + expect req.http.x1 == "/a0" + txresp -body { + + + } + + rxreq + expect req.url == "/bar" + expect req.http.x0 == "/a0" + expect req.http.x1 == "/a0" + txresp + + rxreq + expect req.url == "/b" + expect req.http.x0 == "/b0" + expect req.http.x1 == "/b0" + + txresp +} -start + +varnish v1 -cliok "param.set debug +syncvsl" -vcl+backend { + import ${vmod_debug}; + + sub vcl_recv { + set req.http.x0 = debug.test_priv_top(req.url + req.esi_level); + } + + sub vcl_miss { + set req.http.x1 = debug.test_priv_top(""); + } + + sub vcl_backend_response { + set beresp.do_esi = true; + + } + + sub vcl_deliver { + set resp.http.x1 = debug.test_priv_top(""); + } +} -start + + +client c1 { + txreq -url /a + rxresp + expect resp.http.x1 == "/a0" + + txreq -url /b + rxresp + expect resp.http.x1 == "/b0" +} -run + +varnish v1 -expect s_req == 2 diff --git a/doc/sphinx/reference/vmod.rst b/doc/sphinx/reference/vmod.rst index e0a1d9a..14bb027 100644 --- a/doc/sphinx/reference/vmod.rst +++ b/doc/sphinx/reference/vmod.rst @@ -197,6 +197,9 @@ PRIV_CALL PRIV_TASK See below +PRIV_TOP + See below + VOID C-type: ``void`` @@ -254,6 +257,11 @@ The VCL compiler supports the following private pointers: ``vcl_backend_*`` will yield a different private pointer from the one used on the client side. +* ``PRIV_TOP`` "per top-request" private pointers live for the + duration of one request and all its ESI-includes. They are only + defined for the client side. When used from backend VCL subs, a NULL + pointer will be passed. + The way it works in the vmod code, is that a ``struct vmod_priv *`` is passed to the functions where one of the ``PRIV_*`` argument types is specified. diff --git a/include/vrt.h b/include/vrt.h index 60a0f14..e034f91 100644 --- a/include/vrt.h +++ b/include/vrt.h @@ -259,6 +259,7 @@ typedef int vmod_init_f(struct vmod_priv *, const struct VCL_conf *); void VRT_priv_fini(const struct vmod_priv *p); struct vmod_priv *VRT_priv_task(VRT_CTX, void *vmod_id); +struct vmod_priv *VRT_priv_top(VRT_CTX, void *vmod_id); /* Stevedore related functions */ int VRT_Stv(const char *nm); diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c index 957d017..6a03bff 100644 --- a/lib/libvcc/vcc_expr.c +++ b/lib/libvcc/vcc_expr.c @@ -557,6 +557,12 @@ vcc_priv_arg(struct vcc *tl, const char *p, const char *name) e2 = vcc_mk_expr(VOID, "VRT_priv_task(ctx, &VGC_vmod_%.*s)", (int) (r - name), name); + } else if (!strcmp(p, "PRIV_TOP")) { + r = strchr(name, '.'); + AN(r); + e2 = vcc_mk_expr(VOID, + "VRT_priv_top(ctx, &VGC_vmod_%.*s)", + (int) (r - name), name); } else { WRONG("Wrong PRIV_ type"); } diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py index dbd5051..1dd412d 100755 --- a/lib/libvcc/vmodtool.py +++ b/lib/libvcc/vmodtool.py @@ -59,6 +59,7 @@ ctypes = { 'PRIV_CALL': "struct vmod_priv *", 'PRIV_VCL': "struct vmod_priv *", 'PRIV_TASK': "struct vmod_priv *", + 'PRIV_TOP': "struct vmod_priv *", 'REAL': "VCL_REAL", 'STRING': "VCL_STRING", 'STRING_LIST': "const char *, ...", diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc index 8e940f4..434ee78 100644 --- a/lib/libvmod_debug/vmod.vcc +++ b/lib/libvmod_debug/vmod.vcc @@ -55,6 +55,10 @@ $Function STRING test_priv_task(PRIV_TASK, STRING) Test function for TASK private pointers +$Function STRING test_priv_top(PRIV_TOP, STRING) + +Test function for TOP private pointers + $Function BLOB str2blob(STRING src="foo") Turn a string into a blob diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c index f102247..6ef7c15 100644 --- a/lib/libvmod_debug/vmod_debug.c +++ b/lib/libvmod_debug/vmod_debug.c @@ -97,6 +97,18 @@ vmod_test_priv_task(VRT_CTX, struct vmod_priv *priv, VCL_STRING s) return (priv->priv); } +VCL_STRING __match_proto__(td_debug_test_priv_top) +vmod_test_priv_top(VRT_CTX, struct vmod_priv *priv, VCL_STRING s) +{ + + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); + if (priv->priv == NULL) { + priv->priv = strdup(s); + priv->free = free; + } + return (priv->priv); +} + VCL_VOID __match_proto__(td_debug_test_priv_vcl) vmod_test_priv_vcl(VRT_CTX, struct vmod_priv *priv) { From martin at varnish-software.com Wed Mar 11 15:23:16 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Wed, 11 Mar 2015 16:23:16 +0100 Subject: [4.0] fee7016 Deal with known zero length objects properly when handling do_gzip/do_gunzip Message-ID: commit fee70166ca0c520b2ce46f9dc540e5a6dd1f9063 Author: Martin Blix Grydeland Date: Wed Mar 11 16:21:39 2015 +0100 Deal with known zero length objects properly when handling do_gzip/do_gunzip Original patch: fgs Fixes: #1602 diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index 3308ae6..fbb7110 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -435,6 +435,9 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo) assert(wrk->handling == VCL_RET_DELIVER); + AN(bo->vbc); + est = V1F_Setup_Fetch(bo); + /* * The VCL variables beresp.do_g[un]zip tells us how we want the * object processed before it is stored. @@ -445,10 +448,18 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo) * "Content-Encoding: gzip" --> object is gzip'ed. * no Content-Encoding --> object is not gzip'ed. * anything else --> do nothing wrt gzip - * - * XXX: BS_NONE/cl==0 should avoid gzip/gunzip */ + /* + * If the length is known to be zero, it's not gziped and no + * action is needed. A similar issue exists for chunked encoding + * but we don't handle that. See #1320. + */ + if (est == 0) { + http_Unset(bo->beresp, H_Content_Encoding); + bo->do_gzip = bo->do_gunzip = 0; + } + /* We do nothing unless the param is set */ if (!cache_param->http_gzip_support) bo->do_gzip = bo->do_gunzip = 0; @@ -468,20 +479,6 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo) if (bo->do_gzip && !bo->is_gunzip) bo->do_gzip = 0; - AN(bo->vbc); - est = V1F_Setup_Fetch(bo); - - if (est == 0) { - /* - * If the length is known to be zero, it's not gziped. - * A similar issue exists for chunked encoding but we - * don't handle that. See #1320. - */ - http_Unset(bo->beresp, H_Content_Encoding); - bo->is_gzip = 0; - bo->is_gunzip = 1; - } - /* But we can't do both at the same time */ assert(bo->do_gzip == 0 || bo->do_gunzip == 0); diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c index b6d72dd..e0085a6 100644 --- a/bin/varnishd/cache/cache_http1_fetch.c +++ b/bin/varnishd/cache/cache_http1_fetch.c @@ -185,6 +185,8 @@ V1F_Setup_Fetch(struct busyobj *bo) case BS_CHUNKED: VFP_Push(bo, v1f_pull_chunked, -1); return (-1); + case BS_NONE: + return (0); default: break; } diff --git a/bin/varnishtest/tests/r01602.vtc b/bin/varnishtest/tests/r01602.vtc new file mode 100644 index 0000000..39d6f65 --- /dev/null +++ b/bin/varnishtest/tests/r01602.vtc @@ -0,0 +1,20 @@ +varnishtest "Content-Encoding gzip with no content" + +server s1 { + rxreq + txresp -gzipbody {} + rxreq + txresp -status 204 +} -start + +varnish v1 -vcl+backend { + sub vcl_backend_response { + set beresp.do_gzip = true; + set beresp.do_esi = true; + } +} -start + +client c1 { + txreq -hdr "Accept-Encoding: gzip" + rxresp +} -run From phk at FreeBSD.org Wed Mar 11 22:05:52 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 23:05:52 +0100 Subject: [master] 8c67935 Simplify the "server ${id} -listen" code path to avoid VSS_parse() Message-ID: commit 8c67935734301b7d842fdbee4e00c759c35cc70a Author: Poul-Henning Kamp Date: Wed Mar 11 20:10:40 2015 +0000 Simplify the "server ${id} -listen" code path to avoid VSS_parse() diff --git a/bin/varnishtest/vtc_server.c b/bin/varnishtest/vtc_server.c index 044b617..d34bfdb 100644 --- a/bin/varnishtest/vtc_server.c +++ b/bin/varnishtest/vtc_server.c @@ -56,8 +56,6 @@ struct server { int sock; char listen[256]; struct vss_addr **vss_addr; - char *addr; - char *port; char aaddr[32]; char aport[32]; @@ -125,10 +123,7 @@ server_new(const char *name) if (*s->name != 's') vtc_log(s->vl, 0, "Server name must start with 's'"); - s->addr = strdup("127.0.0.1"); - AN(s->addr); - s->port = strdup("0"); - AN(s->port); + bprintf(s->listen, "%s", "127.0.0.1 0"); s->repeat = 1; s->depth = 10; s->sock = -1; @@ -166,7 +161,7 @@ server_start(struct server *s) CHECK_OBJ_NOTNULL(s, SERVER_MAGIC); vtc_log(s->vl, 2, "Starting server"); if (s->sock < 0) { - naddr = VSS_resolve(s->addr, s->port, &s->vss_addr); + naddr = VSS_resolve(s->listen, "0", &s->vss_addr); if (naddr != 1) vtc_log(s->vl, 0, "Server s listen address not unique" @@ -179,11 +174,11 @@ server_start(struct server *s) macro_def(s->vl, s->name, "addr", "%s", s->aaddr); macro_def(s->vl, s->name, "port", "%s", s->aport); macro_def(s->vl, s->name, "sock", "%s %s", s->aaddr, s->aport); + /* Record the actual port, and reuse it on subsequent starts */ - if (!strcmp(s->port, "0")) - REPLACE(s->port, s->aport); + bprintf(s->listen, "%s %s", s->aaddr, s->aport); } - vtc_log(s->vl, 1, "Listen on %s %s", s->addr, s->port); + vtc_log(s->vl, 1, "Listen on %s", s->listen); s->run = 1; AZ(pthread_create(&s->tp, NULL, server_thread, s)); } @@ -313,7 +308,6 @@ cmd_server(CMD_ARGS) if (s->sock >= 0) VTCP_close(&s->sock); bprintf(s->listen, "%s", av[1]); - AZ(VSS_parse(s->listen, &s->addr, &s->port)); av++; continue; } From phk at FreeBSD.org Wed Mar 11 22:05:52 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 23:05:52 +0100 Subject: [master] ce4894b Use the VTCP version of the text format buffer sizes. Message-ID: commit ce4894b1d2b143fe46f9c81aeb512233891a565f Author: Poul-Henning Kamp Date: Wed Mar 11 22:02:31 2015 +0000 Use the VTCP version of the text format buffer sizes. diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 940d0c0..b374dce 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -156,8 +156,8 @@ ses_vsl_socket(struct sess *sp, const char *lsockname) { struct sockaddr_storage ss; socklen_t sl; - char laddr[ADDR_BUFSIZE]; - char lport[PORT_BUFSIZE]; + char laddr[VTCP_ADDRBUFSIZE]; + char lport[VTCP_PORTBUFSIZE]; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); AN(lsockname); diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h index de8d60c..6a3e67f 100644 --- a/bin/varnishd/common/common.h +++ b/bin/varnishd/common/common.h @@ -76,16 +76,6 @@ struct cli; */ #define __state_variable__(xxx) /*lint -esym(838,xxx) */ -/********************************************************************** - * NI_MAXHOST and less so NI_MAXSERV, are ridiculously large for numeric - * representations of TCP/IP socket addresses, so we use our own. - * ::INET6_ADDRSTRLEN is 46 - */ - -#define ADDR_BUFSIZE 48 -#define PORT_BUFSIZE 8 - - /**********************************************************************/ /* Name of transient storage */ From phk at FreeBSD.org Wed Mar 11 22:05:52 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 23:05:52 +0100 Subject: [master] 400744f Add a new VSS_resolver() function which feeds suckaddr's to a callback function. Message-ID: commit 400744f210b4a33b84849104ac8ba5e1047e45fd Author: Poul-Henning Kamp Date: Wed Mar 11 22:03:22 2015 +0000 Add a new VSS_resolver() function which feeds suckaddr's to a callback function. diff --git a/include/vss.h b/include/vss.h index c015df5..c65a18f 100644 --- a/include/vss.h +++ b/include/vss.h @@ -28,8 +28,14 @@ /* vss.c */ struct vss_addr; +struct suckaddr; const char *VSS_parse(char *str, char **addr, char **port); + +typedef int resolved_f(void *priv, const struct suckaddr *); +int VSS_resolver(const char *addr, const char *def_port, resolved_f *func, + void *priv, const char **err); + int VSS_resolve(const char *addr, const char *port, struct vss_addr ***ta); int VSS_bind(const struct vss_addr *addr); int VSS_listen(const struct vss_addr *addr, int depth); diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index d5bc65f..d88bb3e 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -44,6 +44,7 @@ #include #include "vas.h" +#include "vsa.h" #include "vss.h" #include "vtcp.h" @@ -106,6 +107,56 @@ VSS_parse(char *str, char **addr, char **port) } /* + * Look up an address, using a default port if provided, and call + * the callback function with the suckaddrs we find. + * If the callback function returns anything but zero, we terminate + * and pass that value. + */ + +int +VSS_resolver(const char *addr, const char *def_port, resolved_f *func, + void *priv, const char **err) +{ + struct addrinfo hints, *res0, *res; + struct suckaddr *vsa; + char *h; + char *adp, *hop; + int ret; + + *err = NULL; + h = strdup(addr); + AN(h); + *err = VSS_parse(h, &hop, &adp); + if (*err != NULL) { + free(h); + return (-1); + } + if (adp != NULL) + def_port = adp; + + memset(&hints, 0, sizeof hints); + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_PASSIVE; + ret = getaddrinfo(hop, def_port, &hints, &res0); + free(h); + if (ret != 0) { + *err = gai_strerror(ret); + return (-1); + } + for (res = res0; res != NULL; res = res->ai_next) { + vsa = VSA_Malloc(res->ai_addr, res->ai_addrlen); + if (vsa != NULL) { + ret = func(priv, vsa); + free(vsa); + if (ret) + break; + } + } + freeaddrinfo(res0); + return (ret); +} + +/* * For a given host and port, return a list of struct vss_addr, which * contains all the information necessary to open and bind a socket. One * vss_addr is returned for each distinct address returned by @@ -128,7 +179,6 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) struct addrinfo hints, *res0, *res; struct vss_addr **va; int i, ret; - long int ptst; char *h; char *adp, *hop; @@ -144,25 +194,15 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) return (0); } - if (adp == NULL) - ret = getaddrinfo(addr, port, &hints, &res0); - else { - ptst = strtol(adp, NULL, 10); - if (ptst < 0 || ptst > 65535) { - free(h); - return(0); - } - ret = getaddrinfo(hop, adp, &hints, &res0); - } - + ret = getaddrinfo(hop, adp == NULL ? port : adp, &hints, &res0); free(h); if (ret != 0) return (0); XXXAN(res0); - for (res = res0, i = 0; res != NULL; res = res->ai_next, ++i) - /* nothing */ ; + for (res = res0, i = 0; res != NULL; res = res->ai_next) + i++; if (i == 0) { freeaddrinfo(res0); return (0); From phk at FreeBSD.org Wed Mar 11 22:05:52 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 23:05:52 +0100 Subject: [master] d866395 Use the new VSS_resolver() function to handle IP's in VCC Message-ID: commit d86639568e660bbf272492659f85e271145903c6 Author: Poul-Henning Kamp Date: Wed Mar 11 22:04:01 2015 +0000 Use the new VSS_resolver() function to handle IP's in VCC diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c index 29444a6..2f167bf 100644 --- a/lib/libvcc/vcc_backend.c +++ b/lib/libvcc/vcc_backend.c @@ -35,8 +35,6 @@ #include "vcc_compile.h" -#include "vss.h" - /*-------------------------------------------------------------------- * Struct sockaddr is not really designed to be a compile time * initialized data structure, so we encode it as a byte-string @@ -44,27 +42,19 @@ */ static void -Emit_Sockaddr(struct vcc *tl, const struct token *t_host, const char *port) +Emit_Sockaddr(struct vcc *tl, const struct token *t_host, + const struct token *t_port) { const char *ipv4, *ipv4a, *ipv6, *ipv6a, *pa; - const char *err; - char *p; - char *hop, *pop; + char buf[256]; AN(t_host->dec); - p = TlDup(tl, t_host->dec); - AN(p); - err = VSS_parse(p, &hop, &pop); - if (err != NULL) { - VSB_printf(tl->sb, - "Backend host '%.*s': %s\n", PF(t_host), err); - vcc_ErrWhere(tl, t_host); - return; - } - Resolve_Sockaddr(tl, - hop != NULL ? hop : t_host->dec, - pop != NULL ? pop : port, + if (t_port != NULL) + bprintf(buf, "%s %s", t_host->dec, t_port->dec); + else + bprintf(buf, "%s", t_host->dec); + Resolve_Sockaddr(tl, buf, "http", &ipv4, &ipv4a, &ipv6, &ipv6a, &pa, 2, t_host, "Backend host"); ERRCHK(tl); if (ipv4 != NULL) { @@ -398,10 +388,7 @@ vcc_ParseHostDef(struct vcc *tl, const struct token *t_be) /* Check that the hostname makes sense */ assert(t_host != NULL); - if (t_port != NULL) - Emit_Sockaddr(tl, t_host, t_port->dec); - else - Emit_Sockaddr(tl, t_host, "80"); + Emit_Sockaddr(tl, t_host, t_port); ERRCHK(tl); ExpectErr(tl, '}'); diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index 42f8c5c..a4697a5 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -293,8 +293,8 @@ sym_wildcard_t vcc_Stv_Wildcard; /* vcc_utils.c */ const char *vcc_regexp(struct vcc *tl); -void Resolve_Sockaddr(struct vcc *tl, const char *host, const char *port, \ - const char **ipv4, const char **ipv4_ascii, const char **ipv6, \ +void Resolve_Sockaddr(struct vcc *tl, const char *host, const char *defport, + const char **ipv4, const char **ipv4_ascii, const char **ipv6, const char **ipv6_ascii, const char **p_ascii, int maxips, const struct token *t_err, const char *errid); diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c index f5908ad..fcbcb07 100644 --- a/lib/libvcc/vcc_utils.c +++ b/lib/libvcc/vcc_utils.c @@ -34,13 +34,14 @@ #include #include #include -#include #include "vcc_compile.h" #include "vre.h" #include "vrt.h" #include "vsa.h" +#include "vss.h" +#include "vtcp.h" /*--------------------------------------------------------------------*/ @@ -94,37 +95,38 @@ vcc_regexp(struct vcc *tl) * alignment. */ -static const char * -vcc_sockaddr(struct vcc *tl, const void *sa, unsigned sal) +static void +vcc_suckaddr(struct vcc *tl, const char *host, const struct suckaddr *vsa, + const char **ip, const char **ip_ascii, const char **p_ascii) { + char a[VTCP_ADDRBUFSIZE]; + char p[VTCP_PORTBUFSIZE]; const int sz = sizeof(unsigned long long); const unsigned n = (vsa_suckaddr_len + sz - 1) / sz; - unsigned len; unsigned long long b[n]; - struct suckaddr *sua; - char *p; + int len; + char *q; - AN(sa); - AN(sal); - - sua = VSA_Malloc(sa, sal); - AN(sua); + VTCP_name(vsa, a, sizeof a, p, sizeof p); + Fh(tl, 0, "\n/* \"%s\" -> %s */\n", host, a); + if (ip_ascii != NULL) + *ip_ascii = TlDup(tl, a); + if (p_ascii != NULL && *p_ascii == NULL) + *p_ascii = TlDup(tl, p); Fh(tl, 0, "static const unsigned long long"); Fh(tl, 0, " suckaddr_%u[%d] = {\n", tl->unique, n); - memcpy(b, sua, vsa_suckaddr_len); - free(sua); + memcpy(b, vsa, vsa_suckaddr_len); for (len = 0; len < n; len++) Fh(tl, 0, "%s 0x%0*llxLL", len ? ",\n" : "", sz * 2, b[len]); Fh(tl, 0, "\n};\n"); - p = TlAlloc(tl, 40); - AN(p); - sprintf(p, "(const void*)suckaddr_%u", tl->unique); - + q = TlAlloc(tl, 40); + AN(q); + sprintf(q, "(const void*)suckaddr_%u", tl->unique); + *ip = q; tl->unique++; - return (p); } /*-------------------------------------------------------------------- @@ -138,19 +140,57 @@ vcc_sockaddr(struct vcc *tl, const void *sa, unsigned sal) * For backends, we accept up to one IPv4 and one IPv6. */ -struct foo_proto { - const char *name; - int family; - struct sockaddr_storage sa; - socklen_t l; - const char **dst; - const char **dst_ascii; +struct rss { + unsigned magic; +#define RSS_MAGIC 0x11e966ab + + struct suckaddr *vsa4; + struct suckaddr *vsa6; }; +static int __match_proto__(resolved_f) +rs_callback(void *priv, const struct suckaddr *vsa) +{ + struct rss *rss; + int v; + + CAST_OBJ_NOTNULL(rss, priv, RSS_MAGIC); + assert(VSA_Sane(vsa)); + + v = VSA_Get_Proto(vsa); + if (v == AF_INET) { + if (rss->vsa4 == NULL) + rss->vsa4 = VSA_Clone(vsa); + else if (VSA_Compare(vsa, rss->vsa4)) + return (-2); + } else if (v == AF_INET6) { + if (rss->vsa6 == NULL) + rss->vsa6 = VSA_Clone(vsa); + else if (VSA_Compare(vsa, rss->vsa6)) + return (-2); + } else { + WRONG("Wrong protocol"); + } + return (0); +} + +static int __match_proto__(resolved_f) +rs_callback2(void *priv, const struct suckaddr *vsa) +{ + struct vcc *tl; + char a[VTCP_ADDRBUFSIZE]; + char p[VTCP_PORTBUFSIZE]; + + CAST_OBJ_NOTNULL(tl, priv, VCC_MAGIC); + VTCP_name(vsa, a, sizeof a, p, sizeof p); + VSB_printf(tl->sb, "\t%s:%s\n", a, p); + return (0); +} + void Resolve_Sockaddr(struct vcc *tl, const char *host, - const char *port, + const char *def_port, const char **ipv4, const char **ipv4_ascii, const char **ipv6, @@ -160,100 +200,63 @@ Resolve_Sockaddr(struct vcc *tl, const struct token *t_err, const char *errid) { - struct foo_proto protos[3], *pp; - struct addrinfo *res, *res0, *res1, hint; - int error, retval; - char hbuf[NI_MAXHOST]; + int error, retval = 0; + struct rss *rss; + const char *err; - memset(protos, 0, sizeof protos); - protos[0].name = "ipv4"; - protos[0].family = PF_INET; - protos[0].dst = ipv4; - protos[0].dst_ascii = ipv4_ascii; *ipv4 = NULL; - - protos[1].name = "ipv6"; - protos[1].family = PF_INET6; - protos[1].dst = ipv6; - protos[1].dst_ascii = ipv6_ascii; *ipv6 = NULL; + if (p_ascii != NULL) + *p_ascii = NULL; - retval = 0; - memset(&hint, 0, sizeof hint); - hint.ai_family = PF_UNSPEC; - hint.ai_socktype = SOCK_STREAM; + ALLOC_OBJ(rss, RSS_MAGIC); + AN(rss); - error = getaddrinfo(host, port, &hint, &res0); - if (error) { - VSB_printf(tl->sb, - "%s '%.*s' could not be resolved to an IP address:\n", - errid, PF(t_err)); + error = VSS_resolver(host, def_port, rs_callback, rss, &err); + if (err != NULL) { VSB_printf(tl->sb, + "%s '%.*s' could not be resolved to an IP address:\n" "\t%s\n" "(Sorry if that error message is gibberish.)\n", - gai_strerror(error)); + errid, PF(t_err), err); vcc_ErrWhere(tl, t_err); + free(rss->vsa4); + free(rss->vsa6); + FREE_OBJ(rss); return; } - - for (res = res0; res; res = res->ai_next) { - for (pp = protos; pp->name != NULL; pp++) - if (res->ai_family == pp->family) - break; - if (pp->name == NULL) { - /* Unknown proto, ignore */ - continue; - } - if (pp->l == res->ai_addrlen && - !memcmp(&pp->sa, res->ai_addr, pp->l)) { - /* - * Same address we already emitted. - * This can happen using /etc/hosts - */ - continue; - } - - if (pp->l != 0 || retval == maxips) { - VSB_printf(tl->sb, - "%s %.*s: resolves to too many addresses.\n" - "Only one IPv4 %s IPv6 are allowed.\n" - "Please specify which exact address " - "you want to use, we found all of these:\n", - errid, PF(t_err), - maxips > 1 ? "and one" : "or"); - for (res1 = res0; res1 != NULL; res1 = res1->ai_next) { - error = getnameinfo(res1->ai_addr, - res1->ai_addrlen, hbuf, sizeof hbuf, - NULL, 0, NI_NUMERICHOST); - AZ(error); - VSB_printf(tl->sb, "\t%s\n", hbuf); - } - freeaddrinfo(res0); - vcc_ErrWhere(tl, t_err); - return; - } - - pp->l = res->ai_addrlen; - assert(pp->l <= sizeof(struct sockaddr_storage)); - memcpy(&pp->sa, res->ai_addr, pp->l); - - error = getnameinfo(res->ai_addr, res->ai_addrlen, - hbuf, sizeof hbuf, NULL, 0, NI_NUMERICHOST); - AZ(error); - - Fh(tl, 0, "\n/* \"%s\" -> %s */\n", host, hbuf); - *(pp->dst) = vcc_sockaddr(tl, &pp->sa, pp->l); - if (pp->dst_ascii != NULL) - *pp->dst_ascii = TlDup(tl, hbuf); + if (rss->vsa4 != NULL) { + vcc_suckaddr(tl, host, rss->vsa4, ipv4, ipv4_ascii, p_ascii); + free(rss->vsa4); + retval++; + } + if (rss->vsa6 != NULL) { + vcc_suckaddr(tl, host, rss->vsa6, ipv6, ipv6_ascii, p_ascii); + free(rss->vsa6); retval++; } - if (p_ascii != NULL) { - error = getnameinfo(res0->ai_addr, - res0->ai_addrlen, NULL, 0, hbuf, sizeof hbuf, - NI_NUMERICSERV); - AZ(error); - *p_ascii = TlDup(tl, hbuf); + FREE_OBJ(rss); + if (error == -2 || retval > maxips) { + VSB_printf(tl->sb, + "%s %.*s: resolves to too many addresses.\n" + "Only one IPv4 %s IPv6 are allowed.\n" + "Please specify which exact address " + "you want to use, we found all of these:\n", + errid, PF(t_err), + maxips > 1 ? "and one" : "or"); + (void)VSS_resolver(host, def_port, rs_callback2, tl, &err); + if (err != NULL) { + VSB_printf(tl->sb, + "%s '%.*s' could not be resolved to an" + " IP address:\n" + "\t%s\n" + "(Sorry if that error message is gibberish.)\n", + errid, PF(t_err), err); + } + vcc_ErrWhere(tl, t_err); + return; } + AZ(error); if (retval == 0) { VSB_printf(tl->sb, "%s '%.*s': resolves to " From phk at FreeBSD.org Wed Mar 11 22:05:52 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 23:05:52 +0100 Subject: [master] a9ebb3b Make VSS_parse() static, as it is no longer, and should no longer be used outside vss.c Message-ID: commit a9ebb3b50c2339027197902cfc5199d40e0da20a Author: Poul-Henning Kamp Date: Wed Mar 11 22:05:07 2015 +0000 Make VSS_parse() static, as it is no longer, and should no longer be used outside vss.c diff --git a/include/vss.h b/include/vss.h index c65a18f..f3c040e 100644 --- a/include/vss.h +++ b/include/vss.h @@ -30,8 +30,6 @@ struct vss_addr; struct suckaddr; -const char *VSS_parse(char *str, char **addr, char **port); - typedef int resolved_f(void *priv, const struct suckaddr *); int VSS_resolver(const char *addr, const char *def_port, resolved_f *func, void *priv, const char **err); diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index d88bb3e..9614058 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -72,8 +72,8 @@ struct vss_addr { * See also RFC5952 */ -const char * -VSS_parse(char *str, char **addr, char **port) +static const char * +vss_parse(char *str, char **addr, char **port) { char *p; @@ -126,7 +126,7 @@ VSS_resolver(const char *addr, const char *def_port, resolved_f *func, *err = NULL; h = strdup(addr); AN(h); - *err = VSS_parse(h, &hop, &adp); + *err = vss_parse(h, &hop, &adp); if (*err != NULL) { free(h); return (-1); @@ -189,7 +189,7 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) h = strdup(addr); AN(h); - if (VSS_parse(h, &hop, &adp) != NULL) { + if (vss_parse(h, &hop, &adp) != NULL) { free(h); return (0); } From phk at FreeBSD.org Wed Mar 11 22:10:52 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 23:10:52 +0100 Subject: [master] 14d8ae3 Be a tiny bit more systematic about naming typedefs Message-ID: commit 14d8ae32bad474de3f8da94298fb627eaa75322d Author: Poul-Henning Kamp Date: Wed Mar 11 22:10:36 2015 +0000 Be a tiny bit more systematic about naming typedefs diff --git a/include/vss.h b/include/vss.h index f3c040e..c331de4 100644 --- a/include/vss.h +++ b/include/vss.h @@ -30,8 +30,8 @@ struct vss_addr; struct suckaddr; -typedef int resolved_f(void *priv, const struct suckaddr *); -int VSS_resolver(const char *addr, const char *def_port, resolved_f *func, +typedef int vss_resolved_f(void *priv, const struct suckaddr *); +int VSS_resolver(const char *addr, const char *def_port, vss_resolved_f *func, void *priv, const char **err); int VSS_resolve(const char *addr, const char *port, struct vss_addr ***ta); diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index 9614058..162153a 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -114,7 +114,7 @@ vss_parse(char *str, char **addr, char **port) */ int -VSS_resolver(const char *addr, const char *def_port, resolved_f *func, +VSS_resolver(const char *addr, const char *def_port, vss_resolved_f *func, void *priv, const char **err) { struct addrinfo hints, *res0, *res; diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c index fcbcb07..694294c 100644 --- a/lib/libvcc/vcc_utils.c +++ b/lib/libvcc/vcc_utils.c @@ -148,7 +148,7 @@ struct rss { struct suckaddr *vsa6; }; -static int __match_proto__(resolved_f) +static int __match_proto__(vss_resolved_f) rs_callback(void *priv, const struct suckaddr *vsa) { struct rss *rss; @@ -174,7 +174,7 @@ rs_callback(void *priv, const struct suckaddr *vsa) return (0); } -static int __match_proto__(resolved_f) +static int __match_proto__(vss_resolved_f) rs_callback2(void *priv, const struct suckaddr *vsa) { struct vcc *tl; From phk at FreeBSD.org Wed Mar 11 22:27:04 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 23:27:04 +0100 Subject: [master] 46bfa18 Split the -M event handler into the two different handlers it is. Message-ID: commit 46bfa18757feaaeddbcd1a81e471051e76f600c9 Author: Poul-Henning Kamp Date: Wed Mar 11 22:26:36 2015 +0000 Split the -M event handler into the two different handlers it is. diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index 6af906f..f1dfdec 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -578,40 +578,46 @@ Marg_closer(void *priv) M_fd = -1; } -static int -Marg_poker(const struct vev *e, int what) +static int __match_proto__(vev_cb_f) +Marg_connect(const struct vev *e, int what) { struct vsb *vsb; - int s, k; + int k; socklen_t l; - (void)what; /* XXX: ??? */ - - if (e == M_conn) { - /* Our connect(2) returned, check result */ - l = sizeof k; - AZ(getsockopt(M_fd, SOL_SOCKET, SO_ERROR, &k, &l)); - if (k) { - errno = k; - syslog(LOG_INFO, "Could not connect to CLI-master: %m"); - (void)close(M_fd); - M_fd = -1; - /* Try next address */ - if (++M_nxt >= M_nta) { - M_nxt = 0; - if (M_poll < 10) - M_poll *= 2; - } - return (1); + assert(e == M_conn); + (void)what; + + /* Our connect(2) returned, check result */ + l = sizeof k; + AZ(getsockopt(M_fd, SOL_SOCKET, SO_ERROR, &k, &l)); + if (k) { + errno = k; + syslog(LOG_INFO, "Could not connect to CLI-master: %m"); + (void)close(M_fd); + M_fd = -1; + /* Try next address */ + if (++M_nxt >= M_nta) { + M_nxt = 0; + if (M_poll < 10) + M_poll *= 2; } - vsb = sock_id("master", M_fd); - mgt_cli_setup(M_fd, M_fd, 0, VSB_data(vsb), Marg_closer, NULL); - VSB_delete(vsb); - M_poll = 1; return (1); } + vsb = sock_id("master", M_fd); + mgt_cli_setup(M_fd, M_fd, 0, VSB_data(vsb), Marg_closer, NULL); + VSB_delete(vsb); + M_poll = 1; + return (1); +} + +static int __match_proto__(vev_cb_f) +Marg_poker(const struct vev *e, int what) +{ + int s; assert(e == M_poker); + (void)what; M_poker->timeout = M_poll; /* XXX nasty ? */ if (M_fd >= 0) @@ -626,7 +632,7 @@ Marg_poker(const struct vev *e, int what) M_conn = vev_new(); AN(M_conn); - M_conn->callback = Marg_poker; + M_conn->callback = Marg_connect; M_conn->name = "-M connector"; M_conn->fd_flags = EV_WR; M_conn->fd = s; From phk at FreeBSD.org Wed Mar 11 22:53:01 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 23:53:01 +0100 Subject: [master] c69345a Make VTCP_Connect() able to support async connections where the calling code is responsible for poll(2)'ing the fd for connection completion. Message-ID: commit c69345aa9c31c6bf4b02a8250c3c3beb299f54b0 Author: Poul-Henning Kamp Date: Wed Mar 11 22:50:07 2015 +0000 Make VTCP_Connect() able to support async connections where the calling code is responsible for poll(2)'ing the fd for connection completion. diff --git a/include/vtcp.h b/include/vtcp.h index b49f3ae..3165364 100644 --- a/include/vtcp.h +++ b/include/vtcp.h @@ -51,6 +51,7 @@ int VTCP_check_hup(int sock); #ifdef SOL_SOCKET void VTCP_name(const struct suckaddr *addr, char *abuf, unsigned alen, char *pbuf, unsigned plen); +int VTCP_connected(int s); int VTCP_connect(const struct suckaddr *name, int msec); void VTCP_close(int *s); void VTCP_set_read_timeout(int s, double seconds); diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c index bdee1c7..be7f6e0 100644 --- a/lib/libvarnish/vtcp.c +++ b/lib/libvarnish/vtcp.c @@ -212,10 +212,30 @@ VTCP_nonblocking(int sock) */ int -VTCP_connect(const struct suckaddr *name, int msec) +VTCP_connected(int s) { - int s, i, k; + int k; socklen_t l; + + /* Find out if we got a connection */ + l = sizeof k; + AZ(getsockopt(s, SOL_SOCKET, SO_ERROR, &k, &l)); + + /* An error means no connection established */ + errno = k; + if (k) { + AZ(close(s)); + return (-1); + } + + (void)VTCP_blocking(s); + return (s); +} + +int +VTCP_connect(const struct suckaddr *name, int msec) +{ + int s, i; struct pollfd fds[1]; const struct sockaddr *sa; socklen_t sl; @@ -233,7 +253,7 @@ VTCP_connect(const struct suckaddr *name, int msec) return (s); /* Set the socket non-blocking */ - if (msec > 0) + if (msec != 0) (void)VTCP_nonblocking(s); i = connect(s, sa, sl); @@ -244,6 +264,14 @@ VTCP_connect(const struct suckaddr *name, int msec) return (-1); } + if (msec < 0) { + /* + * Caller is responsible for waiting and + * calling VTCP_connected + */ + return (s); + } + assert(msec > 0); /* Exercise our patience, polling for write */ fds[0].fd = s; @@ -258,19 +286,7 @@ VTCP_connect(const struct suckaddr *name, int msec) return (-1); } - /* Find out if we got a connection */ - l = sizeof k; - AZ(getsockopt(s, SOL_SOCKET, SO_ERROR, &k, &l)); - - /* An error means no connection established */ - errno = k; - if (k) { - AZ(close(s)); - return (-1); - } - - (void)VTCP_blocking(s); - return (s); + return (VTCP_connected(s)); } /*-------------------------------------------------------------------- From phk at FreeBSD.org Wed Mar 11 22:53:01 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 23:53:01 +0100 Subject: [master] 632fc50 Use VTCP_connect[ed]() instead of VSS_connect() Message-ID: commit 632fc5036f20fb452ba96f88b695ca42bc32aaed Author: Poul-Henning Kamp Date: Wed Mar 11 22:51:17 2015 +0000 Use VTCP_connect[ed]() instead of VSS_connect() diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index f1dfdec..53747ed 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -52,6 +52,7 @@ #include "vcli_serve.h" #include "vev.h" #include "vrnd.h" +#include "vsa.h" #include "vss.h" #include "vtcp.h" @@ -563,12 +564,20 @@ mgt_cli_telnet(const char *T_arg) /* Reverse CLI ("Master") connections --------------------------------*/ +struct m_addr { + unsigned magic; +#define M_ADDR_MAGIC 0xbc6217ed + struct suckaddr *sa; + VTAILQ_ENTRY(m_addr) list; +}; + static int M_fd = -1; static struct vev *M_poker, *M_conn; -static struct vss_addr **M_ta; -static int M_nta, M_nxt; static double M_poll = 0.1; +static VTAILQ_HEAD(,m_addr) m_addr_list = + VTAILQ_HEAD_INITIALIZER(m_addr_list); + static void Marg_closer(void *priv) { @@ -582,26 +591,20 @@ static int __match_proto__(vev_cb_f) Marg_connect(const struct vev *e, int what) { struct vsb *vsb; - int k; - socklen_t l; + struct m_addr *ma; assert(e == M_conn); (void)what; - /* Our connect(2) returned, check result */ - l = sizeof k; - AZ(getsockopt(M_fd, SOL_SOCKET, SO_ERROR, &k, &l)); - if (k) { - errno = k; + M_fd = VTCP_connected(M_fd); + if (M_fd < 0) { syslog(LOG_INFO, "Could not connect to CLI-master: %m"); - (void)close(M_fd); - M_fd = -1; - /* Try next address */ - if (++M_nxt >= M_nta) { - M_nxt = 0; - if (M_poll < 10) - M_poll *= 2; - } + ma = VTAILQ_FIRST(&m_addr_list); + AN(ma); + VTAILQ_REMOVE(&m_addr_list, ma, list); + VTAILQ_INSERT_TAIL(&m_addr_list, ma, list); + if (M_poll < 10) + M_poll++; return (1); } vsb = sock_id("master", M_fd); @@ -615,16 +618,20 @@ static int __match_proto__(vev_cb_f) Marg_poker(const struct vev *e, int what) { int s; + struct m_addr *ma; assert(e == M_poker); (void)what; M_poker->timeout = M_poll; /* XXX nasty ? */ - if (M_fd >= 0) + if (M_fd > 0) return (0); + ma = VTAILQ_FIRST(&m_addr_list); + AN(ma); + /* Try to connect asynchronously */ - s = VSS_connect(M_ta[M_nxt], 1); + s = VTCP_connect(ma->sa, -1); if (s < 0) return (0); @@ -641,17 +648,33 @@ Marg_poker(const struct vev *e, int what) return (0); } +static int __match_proto__(vss_resolved_f) +marg_cb(void *priv, const struct suckaddr *sa) +{ + struct m_addr *ma; + + (void)priv; + ALLOC_OBJ(ma, M_ADDR_MAGIC); + AN(ma); + ma->sa = VSA_Clone(sa); + VTAILQ_INSERT_TAIL(&m_addr_list, ma, list); + return(0); +} + void mgt_cli_master(const char *M_arg) { + const char *err; + int error; AN(M_arg); - M_nta = VSS_resolve(M_arg, NULL, &M_ta); - if (M_nta <= 0) { - fprintf(stderr, "Could resolve -M argument to address\n"); - exit(2); - } - M_nxt = 0; + + error = VSS_resolver(M_arg, NULL, marg_cb, NULL, &err); + if (err != NULL) + ARGV_ERR("Could resolve -M argument to address\n\t%s\n", err); + AZ(error); + if (VTAILQ_EMPTY(&m_addr_list)) + ARGV_ERR("Could not resolve -M argument to address\n"); AZ(M_poker); M_poker = vev_new(); AN(M_poker); From phk at FreeBSD.org Wed Mar 11 22:53:01 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 11 Mar 2015 23:53:01 +0100 Subject: [master] a4fdf38 Make VSS_connect() private to vss.c Message-ID: commit a4fdf38a91089f44dd93fb1faa32ebf5b26cfc7c Author: Poul-Henning Kamp Date: Wed Mar 11 22:52:52 2015 +0000 Make VSS_connect() private to vss.c diff --git a/include/vss.h b/include/vss.h index c331de4..1e1233c 100644 --- a/include/vss.h +++ b/include/vss.h @@ -37,5 +37,4 @@ int VSS_resolver(const char *addr, const char *def_port, vss_resolved_f *func, int VSS_resolve(const char *addr, const char *port, struct vss_addr ***ta); int VSS_bind(const struct vss_addr *addr); int VSS_listen(const struct vss_addr *addr, int depth); -int VSS_connect(const struct vss_addr *addr, int nonblock); int VSS_open(const char *str, double tmo); diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index 162153a..b837ac1 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -293,8 +293,8 @@ VSS_listen(const struct vss_addr *va, int depth) * Connect to the socket specified by the address info in va. * Return the socket. */ -int -VSS_connect(const struct vss_addr *va, int nonblock) +static int +vss_connect(const struct vss_addr *va, int nonblock) { int sd, i; @@ -328,7 +328,7 @@ VSS_open(const char *str, double tmo) nvaddr = VSS_resolve(str, NULL, &vaddr); for (n = 0; n < nvaddr; n++) { - retval = VSS_connect(vaddr[n], tmo != 0.0); + retval = vss_connect(vaddr[n], tmo != 0.0); if (retval >= 0 && tmo != 0.0) { pfd.fd = retval; pfd.events = POLLOUT; From phk at FreeBSD.org Wed Mar 11 23:12:00 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 00:12:00 +0100 Subject: [master] 194c072 Add a VTCP_open() function to replace VSS_open(). Message-ID: commit 194c072379b854073ada7564ac9df2f3eee821a8 Author: Poul-Henning Kamp Date: Wed Mar 11 23:08:04 2015 +0000 Add a VTCP_open() function to replace VSS_open(). libc should have had a function like this at least 25 years ago :-/ diff --git a/include/vtcp.h b/include/vtcp.h index 3165364..174975e 100644 --- a/include/vtcp.h +++ b/include/vtcp.h @@ -53,6 +53,8 @@ void VTCP_name(const struct suckaddr *addr, char *abuf, unsigned alen, char *pbuf, unsigned plen); int VTCP_connected(int s); int VTCP_connect(const struct suckaddr *name, int msec); +int VTCP_open(const char *addr, const char *def_port, double timeout, + const char **err); void VTCP_close(int *s); void VTCP_set_read_timeout(int s, double seconds); #endif diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c index be7f6e0..d3d34de 100644 --- a/lib/libvarnish/vtcp.c +++ b/lib/libvarnish/vtcp.c @@ -50,8 +50,10 @@ #include #include +#include "vdef.h" #include "vas.h" #include "vsa.h" +#include "vss.h" #include "vtcp.h" /*--------------------------------------------------------------------*/ @@ -326,6 +328,37 @@ VTCP_set_read_timeout(int s, double seconds) } /*-------------------------------------------------------------------- + */ + +static int __match_proto__(vss_resolved_f) +vtcp_open_callback(void *priv, const struct suckaddr *sa) +{ + double *p = priv; + + return (VTCP_connect(sa, (int)floor(*p * 1e3))); +} + +int +VTCP_open(const char *addr, const char *def_port, double timeout, + const char **errp) +{ + int error; + const char *err; + + if (errp != NULL) + *errp = NULL; + assert(timeout >= 0); + error = VSS_resolver(addr, def_port, vtcp_open_callback, + &timeout, &err); + if (err != NULL) { + if (errp != NULL) + *errp = err; + return (-1); + } + return (error); +} + +/*-------------------------------------------------------------------- * Set or reset SO_LINGER flag */ From phk at FreeBSD.org Wed Mar 11 23:12:00 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 00:12:00 +0100 Subject: [master] 01001b9 Use VTCP_open() instead of VSS_open() Message-ID: commit 01001b90e0799a3a2335b0717983eed352e8f9c3 Author: Poul-Henning Kamp Date: Wed Mar 11 23:08:57 2015 +0000 Use VTCP_open() instead of VSS_open() diff --git a/bin/varnishadm/varnishadm.c b/bin/varnishadm/varnishadm.c index b498efc..954a8be 100644 --- a/bin/varnishadm/varnishadm.c +++ b/bin/varnishadm/varnishadm.c @@ -63,7 +63,7 @@ #include "vas.h" #include "vcli.h" #include "vnum.h" -#include "vss.h" +#include "vtcp.h" #define RL_EXIT(status) \ do { \ @@ -101,10 +101,11 @@ cli_sock(const char *T_arg, const char *S_arg) unsigned status; char *answer = NULL; char buf[CLI_AUTH_RESPONSE_LEN + 1]; + const char *err; - sock = VSS_open(T_arg, timeout); + sock = VTCP_open(T_arg, NULL, timeout, &err); if (sock < 0) { - fprintf(stderr, "Connection failed (%s)\n", T_arg); + fprintf(stderr, "Connection failed (%s): %s\n", T_arg, err); return (-1); } diff --git a/bin/varnishtest/vtc_client.c b/bin/varnishtest/vtc_client.c index a273776..9403af2 100644 --- a/bin/varnishtest/vtc_client.c +++ b/bin/varnishtest/vtc_client.c @@ -74,6 +74,7 @@ client_thread(void *priv) struct vsb *vsb; char *p; char mabuf[32], mpbuf[32]; + const char *err; CAST_OBJ_NOTNULL(c, priv, CLIENT_MAGIC); AN(*c->connect); @@ -91,9 +92,10 @@ client_thread(void *priv) vtc_log(vl, 2, "Started (%u iterations)", c->repeat); for (u = 0; u < c->repeat; u++) { vtc_log(vl, 3, "Connect to %s", VSB_data(vsb)); - fd = VSS_open(VSB_data(vsb), 10.); + fd = VTCP_open(VSB_data(vsb), NULL, 10., &err); if (fd < 0) - vtc_log(c->vl, 0, "Failed to open %s", VSB_data(vsb)); + vtc_log(c->vl, 0, "Failed to open %s: %s", + VSB_data(vsb), err); assert(fd >= 0); VTCP_blocking(fd); VTCP_myname(fd, mabuf, sizeof mabuf, mpbuf, sizeof mpbuf); From phk at FreeBSD.org Wed Mar 11 23:12:00 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 00:12:00 +0100 Subject: [master] c99f522 Retire VSS_open Message-ID: commit c99f522fa084c3a9a4c97f59bb3dad688db4a7a6 Author: Poul-Henning Kamp Date: Wed Mar 11 23:09:53 2015 +0000 Retire VSS_open diff --git a/include/vss.h b/include/vss.h index 1e1233c..7b03943 100644 --- a/include/vss.h +++ b/include/vss.h @@ -37,4 +37,3 @@ int VSS_resolver(const char *addr, const char *def_port, vss_resolved_f *func, int VSS_resolve(const char *addr, const char *port, struct vss_addr ***ta); int VSS_bind(const struct vss_addr *addr); int VSS_listen(const struct vss_addr *addr, int depth); -int VSS_open(const char *str, double tmo); diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index b837ac1..3038f8c 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -288,61 +288,3 @@ VSS_listen(const struct vss_addr *va, int depth) } return (sd); } - -/* - * Connect to the socket specified by the address info in va. - * Return the socket. - */ -static int -vss_connect(const struct vss_addr *va, int nonblock) -{ - int sd, i; - - sd = socket(va->va_family, va->va_socktype, va->va_protocol); - if (sd < 0) { - if (errno != EPROTONOSUPPORT) - perror("socket()"); - return (-1); - } - if (nonblock) - (void)VTCP_nonblocking(sd); - i = connect(sd, (const void *)&va->va_addr, va->va_addrlen); - if (i == 0 || (nonblock && errno == EINPROGRESS)) - return (sd); - perror("connect()"); - (void)close(sd); - return (-1); -} - -/* - * And the totally brutal version: Give me connection to this address - */ - -int -VSS_open(const char *str, double tmo) -{ - int retval = -1; - int nvaddr, n, i; - struct vss_addr **vaddr; - struct pollfd pfd; - - nvaddr = VSS_resolve(str, NULL, &vaddr); - for (n = 0; n < nvaddr; n++) { - retval = vss_connect(vaddr[n], tmo != 0.0); - if (retval >= 0 && tmo != 0.0) { - pfd.fd = retval; - pfd.events = POLLOUT; - i = poll(&pfd, 1, tmo * 1e3); - if (i == 0 || pfd.revents != POLLOUT) { - (void)close(retval); - retval = -1; - } - } - if (retval >= 0) - break; - } - for (n = 0; n < nvaddr; n++) - free(vaddr[n]); - free(vaddr); - return (retval); -} From phk at FreeBSD.org Wed Mar 11 23:12:00 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 00:12:00 +0100 Subject: [master] 1809f70 Remove unnecessary #include Message-ID: commit 1809f707449070a9b96aecce4e8a75a5bdb50c64 Author: Poul-Henning Kamp Date: Wed Mar 11 23:11:51 2015 +0000 Remove unnecessary #include diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index 3038f8c..bd751bb 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -46,7 +46,6 @@ #include "vas.h" #include "vsa.h" #include "vss.h" -#include "vtcp.h" /* lightweight addrinfo */ struct vss_addr { From phk at FreeBSD.org Wed Mar 11 23:59:16 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 00:59:16 +0100 Subject: [master] b0234c6 Add VTCP_bind() and VTCP_listen() functions to replace the VSS_ditto Message-ID: commit b0234c6f4654be476c15b8c417a854c2a73d6b67 Author: Poul-Henning Kamp Date: Wed Mar 11 23:39:46 2015 +0000 Add VTCP_bind() and VTCP_listen() functions to replace the VSS_ditto diff --git a/include/vtcp.h b/include/vtcp.h index 174975e..8f25974 100644 --- a/include/vtcp.h +++ b/include/vtcp.h @@ -48,7 +48,7 @@ int VTCP_nonblocking(int sock); int VTCP_linger(int sock, int linger); int VTCP_check_hup(int sock); -#ifdef SOL_SOCKET +// #ifdef SOL_SOCKET void VTCP_name(const struct suckaddr *addr, char *abuf, unsigned alen, char *pbuf, unsigned plen); int VTCP_connected(int s); @@ -56,5 +56,7 @@ int VTCP_connect(const struct suckaddr *name, int msec); int VTCP_open(const char *addr, const char *def_port, double timeout, const char **err); void VTCP_close(int *s); +int VTCP_bind(const struct suckaddr *addr, const char **errp); +int VTCP_listen(const struct suckaddr *addr, int depth, const char **errp); void VTCP_set_read_timeout(int s, double seconds); -#endif +// #endif diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c index d3d34de..0a72c5b 100644 --- a/lib/libvarnish/vtcp.c +++ b/lib/libvarnish/vtcp.c @@ -359,6 +359,93 @@ VTCP_open(const char *addr, const char *def_port, double timeout, } /*-------------------------------------------------------------------- + * Given a struct suckaddr, open a socket of the appropriate type, and bind + * it to the requested address. + * + * If the address is an IPv6 address, the IPV6_V6ONLY option is set to + * avoid conflicts between INADDR_ANY and IN6ADDR_ANY. + */ + +int +VTCP_bind(const struct suckaddr *sa, const char **errp) +{ + int sd, val, e; + socklen_t sl; + const struct sockaddr *so; + int proto; + + if (errp != NULL) + *errp = NULL; + + proto = VSA_Get_Proto(sa); + sd = socket(proto, SOCK_STREAM, 0); + if (sd < 0) { + if (errp != NULL) + *errp = "socket(2)"; + return (-1); + } + val = 1; + if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof val) != 0) { + if (errp != NULL) + *errp = "setsockopt(SO_REUSEADDR, 1)"; + e = errno; + AZ(close(sd)); + errno = e; + return (-1); + } +#ifdef IPV6_V6ONLY + /* forcibly use separate sockets for IPv4 and IPv6 */ + val = 1; + if (proto == AF_INET6 && + setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof val) != 0) { + if (errp != NULL) + *errp = "setsockopt(IPV6_V6ONLY, 1)"; + e = errno; + AZ(close(sd)); + errno = e; + return (-1); + } +#endif + so = VSA_Get_Sockaddr(sa, &sl); + if (bind(sd, so, sl) != 0) { + if (errp != NULL) + *errp = "bind(2)"; + e = errno; + AZ(close(sd)); + errno = e; + return (-1); + } + return (sd); +} + +/*-------------------------------------------------------------------- + * Given a struct suckaddr, open a socket of the appropriate type, bind it + * to the requested address, and start listening. + */ + +int +VTCP_listen(const struct suckaddr *sa, int depth, const char **errp) +{ + int sd; + int e; + + if (errp != NULL) + *errp = NULL; + sd = VTCP_bind(sa, errp); + if (sd >= 0) { + if (listen(sd, depth) != 0) { + e = errno; + AZ(close(sd)); + errno = e; + if (errp != NULL) + *errp = "listen(2)"; + return (-1); + } + } + return (sd); +} + +/*-------------------------------------------------------------------- * Set or reset SO_LINGER flag */ From phk at FreeBSD.org Wed Mar 11 23:59:16 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 00:59:16 +0100 Subject: [master] 1aa928f Rewrite the mgt_acceptor code to use suckaddrs Message-ID: commit 1aa928fe2fe35eb7ce5e2d9c6e4585e8373f743a Author: Poul-Henning Kamp Date: Wed Mar 11 23:42:14 2015 +0000 Rewrite the mgt_acceptor code to use suckaddrs diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h index b62a6ca..0321e2b 100644 --- a/bin/varnishd/common/heritage.h +++ b/bin/varnishd/common/heritage.h @@ -30,6 +30,7 @@ */ struct vsm_sc; +struct suckaddr; struct listen_sock { unsigned magic; @@ -37,7 +38,7 @@ struct listen_sock { VTAILQ_ENTRY(listen_sock) list; int sock; char *name; - struct vss_addr *addr; + struct suckaddr *addr; }; VTAILQ_HEAD(listen_sock_head, listen_sock); diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index 6c2402f..310b614 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -31,6 +31,9 @@ #include "config.h" +#include +#include +#include #include #include #include @@ -43,7 +46,9 @@ #include "common/params.h" #include "vav.h" +#include "vsa.h" #include "vss.h" +#include "vtcp.h" /*===================================================================== * Open and close the accept sockets. @@ -63,7 +68,7 @@ MAC_open_sockets(void) good++; continue; } - ls->sock = VSS_bind(ls->addr); + ls->sock = VTCP_bind(ls->addr, NULL); if (ls->sock < 0) continue; @@ -109,14 +114,32 @@ clean_listen_sock_head(struct listen_sock_head *lsh) } } +static struct listen_sock_head lsh; + +static int __match_proto__(vss_resolver_f) +tla_callback(void *priv, const struct suckaddr *sa) +{ + struct listen_sock *ls; + + ALLOC_OBJ(ls, LISTEN_SOCK_MAGIC); + AN(ls); + ls->sock = -1; + ls->addr = VSA_Clone(sa); + AN(ls->addr); + ls->name = strdup(priv); + AN(ls->name); + VTAILQ_INSERT_TAIL(&lsh, ls, list); + return (0); +} + int tweak_listen_address(struct vsb *vsb, const struct parspec *par, const char *arg) { char **av; - int i, retval = 0; - struct listen_sock *ls; - struct listen_sock_head lsh; + int i, error; + const char *err; + struct listen_sock *ls; (void)par; if (arg == NULL) { @@ -141,31 +164,16 @@ tweak_listen_address(struct vsb *vsb, const struct parspec *par, } VTAILQ_INIT(&lsh); for (i = 1; av[i] != NULL; i++) { - struct vss_addr **ta; - int j, n; - - n = VSS_resolve(av[i], "http", &ta); - if (n == 0) { + error = VSS_resolver(av[i], "http", tla_callback, av[i], &err); + if (err != NULL) { VSB_printf(vsb, "Invalid listen address "); VSB_quote(vsb, av[i], -1, 0); - retval = -1; - break; - } - for (j = 0; j < n; ++j) { - ALLOC_OBJ(ls, LISTEN_SOCK_MAGIC); - AN(ls); - ls->sock = -1; - ls->addr = ta[j]; - ls->name = strdup(av[i]); - AN(ls->name); - VTAILQ_INSERT_TAIL(&lsh, ls, list); + VSB_printf(vsb, ": %s", err); + VAV_Free(av); + clean_listen_sock_head(&lsh); + return (-1); } - free(ta); - } - VAV_Free(av); - if (retval) { - clean_listen_sock_head(&lsh); - return (-1); + AZ(error); } REPLACE(mgt_param.listen_address, arg); From phk at FreeBSD.org Wed Mar 11 23:59:16 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 00:59:16 +0100 Subject: [master] ee0910a Privatize VSS_bind() Message-ID: commit ee0910af644a16c8ce3bf4111e80f8a275b16670 Author: Poul-Henning Kamp Date: Wed Mar 11 23:43:51 2015 +0000 Privatize VSS_bind() diff --git a/include/vss.h b/include/vss.h index 7b03943..9773bf4 100644 --- a/include/vss.h +++ b/include/vss.h @@ -35,5 +35,4 @@ int VSS_resolver(const char *addr, const char *def_port, vss_resolved_f *func, void *priv, const char **err); int VSS_resolve(const char *addr, const char *port, struct vss_addr ***ta); -int VSS_bind(const struct vss_addr *addr); int VSS_listen(const struct vss_addr *addr, int depth); diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index bd751bb..23fee9e 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -231,8 +231,8 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) * avoid conflicts between INADDR_ANY and IN6ADDR_ANY. */ -int -VSS_bind(const struct vss_addr *va) +static int +vss_bind(const struct vss_addr *va) { int sd, val; @@ -277,7 +277,7 @@ VSS_listen(const struct vss_addr *va, int depth) { int sd; - sd = VSS_bind(va); + sd = vss_bind(va); if (sd >= 0) { if (listen(sd, depth) != 0) { perror("listen()"); From phk at FreeBSD.org Wed Mar 11 23:59:16 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 00:59:16 +0100 Subject: [master] 4e2942a Rewrite CLI/Telnet in terms of suckaddrs Message-ID: commit 4e2942a6e2132fef3bbd9506a65d3f42d39a5963 Author: Poul-Henning Kamp Date: Wed Mar 11 23:58:59 2015 +0000 Rewrite CLI/Telnet in terms of suckaddrs diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index 53747ed..3920468 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -512,51 +512,51 @@ mgt_cli_secret(const char *S_arg) secret_file = S_arg; } -void -mgt_cli_telnet(const char *T_arg) +static int __match_proto__(vss_resolver_f) +mct_callback(void *priv, const struct suckaddr *sa) { - struct vss_addr **ta; - int i, n, sock, good; - struct telnet *tn; - struct vsb *vsb; + int sock; + struct vsb *vsb = priv; + const char *err; char abuf[VTCP_ADDRBUFSIZE]; char pbuf[VTCP_PORTBUFSIZE]; + struct telnet *tn; - AN(T_arg); - n = VSS_resolve(T_arg, NULL, &ta); - if (n == 0) { - REPORT(LOG_ERR, "-T %s Could not be resolved\n", T_arg); - exit(2); - } - good = 0; - vsb = VSB_new_auto(); - XXXAN(vsb); - for (i = 0; i < n; ++i) { - VJ_master(JAIL_MASTER_HIGH); - sock = VSS_listen(ta[i], 10); - VJ_master(JAIL_MASTER_LOW); - if (sock < 0) - continue; + VJ_master(JAIL_MASTER_HIGH); + sock = VTCP_listen(sa, 10, &err); + VJ_master(JAIL_MASTER_LOW); + if (sock > 0) { VTCP_myname(sock, abuf, sizeof abuf, pbuf, sizeof pbuf); VSB_printf(vsb, "%s %s\n", abuf, pbuf); - good++; tn = telnet_new(sock); tn->ev = vev_new(); - XXXAN(tn->ev); + AN(tn->ev); tn->ev->fd = sock; tn->ev->fd_flags = POLLIN; tn->ev->callback = telnet_accept; tn->ev->priv = tn; AZ(vev_add(mgt_evb, tn->ev)); - free(ta[i]); - ta[i] = NULL; - } - free(ta); - if (good == 0) { - REPORT(LOG_ERR, "-T %s could not be listened on.", T_arg); - exit(2); } + return (0); +} + +void +mgt_cli_telnet(const char *T_arg) +{ + int error; + const char *err; + struct vsb *vsb; + + AN(T_arg); + vsb = VSB_new_auto(); + AN(vsb); + error = VSS_resolver(T_arg, NULL, mct_callback, vsb, &err); + if (err != NULL) + ARGV_ERR("Could resolve -T argument to address\n\t%s\n", err); + AZ(error); AZ(VSB_finish(vsb)); + if (VSB_len(vsb) == 0) + ARGV_ERR("-T %s could not be listened on.", T_arg); /* Save in shmem */ mgt_SHM_static_alloc(VSB_data(vsb), VSB_len(vsb) + 1, "Arg", "-T", ""); VSB_delete(vsb); From phk at FreeBSD.org Thu Mar 12 00:06:52 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 01:06:52 +0100 Subject: [master] a1e20fa Probe TCP keepalive params using suckaddr Message-ID: commit a1e20face21ec6bf028c222bdb6075d42bd24a5e Author: Poul-Henning Kamp Date: Thu Mar 12 00:03:00 2015 +0000 Probe TCP keepalive params using suckaddr diff --git a/bin/varnishd/mgt/mgt_param_tcp.c b/bin/varnishd/mgt/mgt_param_tcp.c index 8f107e3..cfdfac8 100644 --- a/bin/varnishd/mgt/mgt_param_tcp.c +++ b/bin/varnishd/mgt/mgt_param_tcp.c @@ -47,6 +47,7 @@ #include "common/params.h" #include "vss.h" +#include "vtcp.h" #include "mgt/mgt_param.h" @@ -93,26 +94,28 @@ tcp_probe(int sock, int nam, const char *param, unsigned def) MCF_SetDefault(param, p); } -static void -tcp_keep_probes(void) +static int __match_proto__(vss_resolve_f) +tkp_callback(void *priv, const struct suckaddr *sa) { - int i, s; - struct vss_addr **ta = NULL; + int s; - /* Probe a dummy socket for default values */ - - i = VSS_resolve(":0", NULL, &ta); - if (i == 0) - return; // XXX: log - assert (i > 0); - s = VSS_listen(ta[0], 10); + (void)priv; + s = VTCP_listen(sa, 10, NULL); if (s >= 0) { tcp_probe(s, TCP_KEEPIDLE, "tcp_keepalive_time", 600); tcp_probe(s, TCP_KEEPCNT, "tcp_keepalive_probes", 5); tcp_probe(s, TCP_KEEPINTVL, "tcp_keepalive_intvl", 5); AZ(close(s)); + return (1); } - free(ta); + return (0); +} + +static void +tcp_keep_probes(void) +{ + /* Probe a dummy socket for default values */ + (void)VSS_resolver(":0", NULL, tkp_callback, NULL, NULL); } #endif From phk at FreeBSD.org Thu Mar 12 00:06:52 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 01:06:52 +0100 Subject: [master] 20ef818 Complain if we cannot probe TCP keepalive parameters. Message-ID: commit 20ef818a0a613bca6c0284781c596e35bb83807a Author: Poul-Henning Kamp Date: Thu Mar 12 00:06:37 2015 +0000 Complain if we cannot probe TCP keepalive parameters. diff --git a/bin/varnishd/mgt/mgt_param_tcp.c b/bin/varnishd/mgt/mgt_param_tcp.c index cfdfac8..9212989 100644 --- a/bin/varnishd/mgt/mgt_param_tcp.c +++ b/bin/varnishd/mgt/mgt_param_tcp.c @@ -114,8 +114,11 @@ tkp_callback(void *priv, const struct suckaddr *sa) static void tcp_keep_probes(void) { + const char *err; /* Probe a dummy socket for default values */ - (void)VSS_resolver(":0", NULL, tkp_callback, NULL, NULL); + (void)VSS_resolver(":0", NULL, tkp_callback, NULL, &err); + if (err != NULL) + ARGV_ERR("Could not probe TCP keepalives: %s", err); } #endif From phk at FreeBSD.org Thu Mar 12 00:36:50 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 01:36:50 +0100 Subject: [master] dc80d95 Add VTCP_listen_on() which resolves and listens on an address Message-ID: commit dc80d9507de53212bc862e90d5413f343ea2e595 Author: Poul-Henning Kamp Date: Thu Mar 12 00:28:50 2015 +0000 Add VTCP_listen_on() which resolves and listens on an address diff --git a/include/vtcp.h b/include/vtcp.h index 8f25974..641cc14 100644 --- a/include/vtcp.h +++ b/include/vtcp.h @@ -58,5 +58,7 @@ int VTCP_open(const char *addr, const char *def_port, double timeout, void VTCP_close(int *s); int VTCP_bind(const struct suckaddr *addr, const char **errp); int VTCP_listen(const struct suckaddr *addr, int depth, const char **errp); +int VTCP_listen_on(const char *addr, const char *def_port, int depth, + const char **errp); void VTCP_set_read_timeout(int s, double seconds); // #endif diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c index 0a72c5b..d59b214 100644 --- a/lib/libvarnish/vtcp.c +++ b/lib/libvarnish/vtcp.c @@ -445,6 +445,44 @@ VTCP_listen(const struct suckaddr *sa, int depth, const char **errp) return (sd); } +/*--------------------------------------------------------------------*/ + +struct helper { + int depth; + const char **errp; +}; + +static int __match_proto__(vss_resolved_f) +vtcp_lo_cb(void *priv, const struct suckaddr *sa) +{ + int sock; + struct helper *hp = priv; + + sock = VTCP_listen(sa, hp->depth, hp->errp); + if (sock > 0) { + *hp->errp = NULL; + return (sock); + } + AN(*hp->errp); + return (0); +} + +int +VTCP_listen_on(const char *addr, const char *def_port, int depth, + const char **errp) +{ + struct helper h; + int sock; + + h.depth = depth; + h.errp = errp; + + sock = VSS_resolver(addr, def_port, vtcp_lo_cb, &h, errp); + if (*errp != NULL) + return (-1); + return(sock); +} + /*-------------------------------------------------------------------- * Set or reset SO_LINGER flag */ From phk at FreeBSD.org Thu Mar 12 00:36:50 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 01:36:50 +0100 Subject: [master] 7b8e01e Rewrite the TCP_KEEPALIVE prober to use VTCP_listen_on() Message-ID: commit 7b8e01efca86c33eb294e460a5482a8cbcb945ac Author: Poul-Henning Kamp Date: Thu Mar 12 00:29:29 2015 +0000 Rewrite the TCP_KEEPALIVE prober to use VTCP_listen_on() diff --git a/bin/varnishd/mgt/mgt_param_tcp.c b/bin/varnishd/mgt/mgt_param_tcp.c index 9212989..fa9dabf 100644 --- a/bin/varnishd/mgt/mgt_param_tcp.c +++ b/bin/varnishd/mgt/mgt_param_tcp.c @@ -46,7 +46,6 @@ #include "mgt/mgt.h" #include "common/params.h" -#include "vss.h" #include "vtcp.h" #include "mgt/mgt_param.h" @@ -94,31 +93,20 @@ tcp_probe(int sock, int nam, const char *param, unsigned def) MCF_SetDefault(param, p); } -static int __match_proto__(vss_resolve_f) -tkp_callback(void *priv, const struct suckaddr *sa) -{ - int s; - - (void)priv; - s = VTCP_listen(sa, 10, NULL); - if (s >= 0) { - tcp_probe(s, TCP_KEEPIDLE, "tcp_keepalive_time", 600); - tcp_probe(s, TCP_KEEPCNT, "tcp_keepalive_probes", 5); - tcp_probe(s, TCP_KEEPINTVL, "tcp_keepalive_intvl", 5); - AZ(close(s)); - return (1); - } - return (0); -} - static void tcp_keep_probes(void) { const char *err; - /* Probe a dummy socket for default values */ - (void)VSS_resolver(":0", NULL, tkp_callback, NULL, &err); + int s; + + s = VTCP_listen_on(":0", NULL, 10, &err); if (err != NULL) ARGV_ERR("Could not probe TCP keepalives: %s", err); + assert(s > 0); + tcp_probe(s, TCP_KEEPIDLE, "tcp_keepalive_time", 600); + tcp_probe(s, TCP_KEEPCNT, "tcp_keepalive_probes", 5); + tcp_probe(s, TCP_KEEPINTVL, "tcp_keepalive_intvl", 5); + AZ(close(s)); } #endif From phk at FreeBSD.org Thu Mar 12 00:36:50 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 01:36:50 +0100 Subject: [master] 7e01e2c Use VTCP_listen_on() Message-ID: commit 7e01e2c00f8d7df937af2721d87eb374e825a3d8 Author: Poul-Henning Kamp Date: Thu Mar 12 00:30:03 2015 +0000 Use VTCP_listen_on() diff --git a/bin/varnishtest/vtc_server.c b/bin/varnishtest/vtc_server.c index d34bfdb..4088b85 100644 --- a/bin/varnishtest/vtc_server.c +++ b/bin/varnishtest/vtc_server.c @@ -156,19 +156,17 @@ server_delete(struct server *s) static void server_start(struct server *s) { - int naddr; + const char *err; CHECK_OBJ_NOTNULL(s, SERVER_MAGIC); vtc_log(s->vl, 2, "Starting server"); if (s->sock < 0) { - naddr = VSS_resolve(s->listen, "0", &s->vss_addr); - if (naddr != 1) + s->sock = VTCP_listen_on(s->listen, "0", s->depth, &err); + if (err != NULL) vtc_log(s->vl, 0, - "Server s listen address not unique" - " \"%s\" resolves to (%d) sockets", - s->listen, naddr); - s->sock = VSS_listen(s->vss_addr[0], s->depth); - assert(s->sock >= 0); + "Server s listen address cannot be resolved: %s", + err); + assert(s->sock > 0); VTCP_myname(s->sock, s->aaddr, sizeof s->aaddr, s->aport, sizeof s->aport); macro_def(s->vl, s->name, "addr", "%s", s->aaddr); diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 1cae1d1..13d00e5 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -371,6 +371,7 @@ varnish_launch(struct varnish *v) char abuf[128], pbuf[128]; struct pollfd fd[2]; enum VCLI_status_e u; + const char *err; char *r; v->vd = VSM_New(); @@ -378,7 +379,9 @@ varnish_launch(struct varnish *v) /* Create listener socket */ nap = VSS_resolve("127.0.0.1", "0", &ap); AN(nap); - v->cli_fd = VSS_listen(ap[0], 1); + v->cli_fd = VTCP_listen_on("127.0.0.1:0", NULL, 1, &err); + if (err != NULL) + vtc_log(v->vl, 0, "Create CLI listen socket failed: %s", err); assert(v->cli_fd > 0); VTCP_myname(v->cli_fd, abuf, sizeof abuf, pbuf, sizeof pbuf); From phk at FreeBSD.org Thu Mar 12 00:36:50 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 01:36:50 +0100 Subject: [master] ae91550 Retire VSS_listen() Message-ID: commit ae915507c3b8b1545bef497f635fc6c6f11eafd1 Author: Poul-Henning Kamp Date: Thu Mar 12 00:31:41 2015 +0000 Retire VSS_listen() diff --git a/include/vss.h b/include/vss.h index 9773bf4..5c3a22e 100644 --- a/include/vss.h +++ b/include/vss.h @@ -35,4 +35,3 @@ int VSS_resolver(const char *addr, const char *def_port, vss_resolved_f *func, void *priv, const char **err); int VSS_resolve(const char *addr, const char *port, struct vss_addr ***ta); -int VSS_listen(const struct vss_addr *addr, int depth); diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index 23fee9e..fb7856a 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -37,7 +37,6 @@ #include #include -#include #include #include #include @@ -222,68 +221,3 @@ VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) freeaddrinfo(res0); return (i); } - -/* - * Given a struct vss_addr, open a socket of the appropriate type, and bind - * it to the requested address. - * - * If the address is an IPv6 address, the IPV6_V6ONLY option is set to - * avoid conflicts between INADDR_ANY and IN6ADDR_ANY. - */ - -static int -vss_bind(const struct vss_addr *va) -{ - int sd, val; - - sd = socket(va->va_family, va->va_socktype, va->va_protocol); - if (sd < 0) { - perror("socket()"); - return (-1); - } - val = 1; - if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof val) != 0) { - perror("setsockopt(SO_REUSEADDR, 1)"); - (void)close(sd); - return (-1); - } -#ifdef IPV6_V6ONLY - /* forcibly use separate sockets for IPv4 and IPv6 */ - val = 1; - if (va->va_family == AF_INET6 && - setsockopt(sd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof val) != 0) { - perror("setsockopt(IPV6_V6ONLY, 1)"); - (void)close(sd); - return (-1); - } -#endif - if (bind(sd, (const void*)&va->va_addr, va->va_addrlen) != 0) { - perror("bind()"); - (void)close(sd); - return (-1); - } - return (sd); -} - -/* - * Given a struct vss_addr, open a socket of the appropriate type, bind it - * to the requested address, and start listening. - * - * If the address is an IPv6 address, the IPV6_V6ONLY option is set to - * avoid conflicts between INADDR_ANY and IN6ADDR_ANY. - */ -int -VSS_listen(const struct vss_addr *va, int depth) -{ - int sd; - - sd = vss_bind(va); - if (sd >= 0) { - if (listen(sd, depth) != 0) { - perror("listen()"); - (void)close(sd); - return (-1); - } - } - return (sd); -} From phk at FreeBSD.org Thu Mar 12 00:36:50 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 01:36:50 +0100 Subject: [master] d265cbb Remove dead code Message-ID: commit d265cbb3ede23c5475d8fcc178600453680b7064 Author: Poul-Henning Kamp Date: Thu Mar 12 00:32:43 2015 +0000 Remove dead code diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 13d00e5..e9c4b6a 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -366,8 +366,7 @@ static void varnish_launch(struct varnish *v) { struct vsb *vsb, *vsb1; - int i, nfd, nap; - struct vss_addr **ap; + int i, nfd; char abuf[128], pbuf[128]; struct pollfd fd[2]; enum VCLI_status_e u; @@ -377,8 +376,6 @@ varnish_launch(struct varnish *v) v->vd = VSM_New(); /* Create listener socket */ - nap = VSS_resolve("127.0.0.1", "0", &ap); - AN(nap); v->cli_fd = VTCP_listen_on("127.0.0.1:0", NULL, 1, &err); if (err != NULL) vtc_log(v->vl, 0, "Create CLI listen socket failed: %s", err); From phk at FreeBSD.org Thu Mar 12 00:36:50 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 01:36:50 +0100 Subject: [master] 7274e51 Remove unused struct member Message-ID: commit 7274e515ca46f8305bcaaf1b9ed3afbd7590ff77 Author: Poul-Henning Kamp Date: Thu Mar 12 00:35:52 2015 +0000 Remove unused struct member diff --git a/bin/varnishtest/vtc_server.c b/bin/varnishtest/vtc_server.c index 4088b85..4b353a4 100644 --- a/bin/varnishtest/vtc_server.c +++ b/bin/varnishtest/vtc_server.c @@ -55,7 +55,6 @@ struct server { int depth; int sock; char listen[256]; - struct vss_addr **vss_addr; char aaddr[32]; char aport[32]; From phk at FreeBSD.org Thu Mar 12 00:36:50 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 01:36:50 +0100 Subject: [master] 2b010c8 Retire VSS_resolve() Message-ID: commit 2b010c8fd49a5291dc635d7ad57f2a737b03bbdb Author: Poul-Henning Kamp Date: Thu Mar 12 00:36:02 2015 +0000 Retire VSS_resolve() diff --git a/include/vss.h b/include/vss.h index 5c3a22e..14b9356 100644 --- a/include/vss.h +++ b/include/vss.h @@ -27,11 +27,8 @@ */ /* vss.c */ -struct vss_addr; struct suckaddr; typedef int vss_resolved_f(void *priv, const struct suckaddr *); int VSS_resolver(const char *addr, const char *def_port, vss_resolved_f *func, void *priv, const char **err); - -int VSS_resolve(const char *addr, const char *port, struct vss_addr ***ta); diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index fb7856a..1077e25 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -46,15 +46,6 @@ #include "vsa.h" #include "vss.h" -/* lightweight addrinfo */ -struct vss_addr { - int va_family; - int va_socktype; - int va_protocol; - socklen_t va_addrlen; - struct sockaddr_storage va_addr; -}; - /*lint -esym(754, _storage) not ref */ /* @@ -153,71 +144,3 @@ VSS_resolver(const char *addr, const char *def_port, vss_resolved_f *func, freeaddrinfo(res0); return (ret); } - -/* - * For a given host and port, return a list of struct vss_addr, which - * contains all the information necessary to open and bind a socket. One - * vss_addr is returned for each distinct address returned by - * getaddrinfo(). - * - * The value pointed to by the tap parameter receives a pointer to an - * array of pointers to struct vss_addr. The caller is responsible for - * freeing each individual struct vss_addr as well as the array. - * - * The return value is the number of addresses resoved, or zero. - * - * If the addr argument contains a port specification, that takes - * precedence over the port argument. - * - * XXX: We need a function to free the allocated addresses. - */ -int -VSS_resolve(const char *addr, const char *port, struct vss_addr ***vap) -{ - struct addrinfo hints, *res0, *res; - struct vss_addr **va; - int i, ret; - char *h; - char *adp, *hop; - - *vap = NULL; - memset(&hints, 0, sizeof hints); - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - - h = strdup(addr); - AN(h); - if (vss_parse(h, &hop, &adp) != NULL) { - free(h); - return (0); - } - - ret = getaddrinfo(hop, adp == NULL ? port : adp, &hints, &res0); - free(h); - - if (ret != 0) - return (0); - - XXXAN(res0); - for (res = res0, i = 0; res != NULL; res = res->ai_next) - i++; - if (i == 0) { - freeaddrinfo(res0); - return (0); - } - va = calloc(i, sizeof *va); - XXXAN(va); - *vap = va; - for (res = res0, i = 0; res != NULL; res = res->ai_next, ++i) { - va[i] = calloc(1, sizeof(**va)); - XXXAN(va[i]); - va[i]->va_family = res->ai_family; - va[i]->va_socktype = res->ai_socktype; - va[i]->va_protocol = res->ai_protocol; - va[i]->va_addrlen = res->ai_addrlen; - xxxassert(va[i]->va_addrlen <= sizeof va[i]->va_addr); - memcpy(&va[i]->va_addr, res->ai_addr, va[i]->va_addrlen); - } - freeaddrinfo(res0); - return (i); -} From fgsch at lodoss.net Thu Mar 12 01:21:47 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Thu, 12 Mar 2015 02:21:47 +0100 Subject: [master] 8ac4832 One nitpick commit a day keeps the OCD away Message-ID: commit 8ac48328122bd4e8d47f80d3c01e6c45da2ca602 Author: Federico G. Schwindt Date: Wed Mar 11 16:23:09 2015 +0000 One nitpick commit a day keeps the OCD away diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c index a2052d4..b4676bc 100644 --- a/bin/varnishd/cache/cache_vrt_priv.c +++ b/bin/varnishd/cache/cache_vrt_priv.c @@ -132,10 +132,9 @@ VRT_priv_top(VRT_CTX, void *vmod_id) CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); CHECK_OBJ_NOTNULL(ctx->req->top, REQ_MAGIC); id = (uintptr_t)&ctx->req->top->top; - } else { - return NULL; + return (VRT_priv_dynamic(ctx, id, (uintptr_t)vmod_id)); } - return (VRT_priv_dynamic(ctx, id, (uintptr_t)vmod_id)); + return (NULL); } /*-------------------------------------------------------------------- diff --git a/lib/libvarnish/vtim.c b/lib/libvarnish/vtim.c index 2b37816..39f5115 100644 --- a/lib/libvarnish/vtim.c +++ b/lib/libvarnish/vtim.c @@ -81,11 +81,11 @@ static const char * const month_name[] = { }; static const int days_in_month[] = { - 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, + 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; static const int days_before_month[] = { - 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 + 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; /* @@ -269,9 +269,8 @@ VTIM_parse(const char *p) DIGIT(100, year); DIGIT(10, year); DIGIT(1, year); - } else if (!memcmp(p, - more_weekday[weekday], - strlen(more_weekday[weekday]))) { + } else if (!memcmp(p, more_weekday[weekday], + strlen(more_weekday[weekday]))) { /* RFC850 -- "Sunday, 06-Nov-94 08:49:37 GMT" */ p += strlen(more_weekday[weekday]); MUSTBE(','); @@ -302,7 +301,7 @@ VTIM_parse(const char *p) if (*p != '\0') FAIL(); - if (sec < 0 || sec > 60) // Leapseconds! + if (sec < 0 || sec > 60) /* Leapseconds! */ FAIL(); if (min < 0 || min > 59) FAIL(); @@ -321,7 +320,7 @@ VTIM_parse(const char *p) if (month == 2 && mday > 28 && !leap) FAIL(); - if (sec == 60) // Ignore Leapseconds + if (sec == 60) /* Ignore Leapseconds */ sec--; t = ((hour * 60.) + min) * 60. + sec; @@ -334,12 +333,12 @@ VTIM_parse(const char *p) d += (year % 100) * 365; /* There are 365 days in a year */ if ((year % 100) > 0) /* And a leap day every four years */ - d += (((year % 100) - 1)/4); + d += (((year % 100) - 1) / 4); d += ((year / 100) - 20) * /* Days relative to y2000 */ (100 * 365 + 24); /* 24 leapdays per year in a century */ - d += ((year-1) / 400) - 4; /* And one more every 400 years */ + d += ((year - 1) / 400) - 4; /* And one more every 400 years */ /* * Now check weekday, if we have one. From phk at FreeBSD.org Thu Mar 12 08:54:22 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 09:54:22 +0100 Subject: [master] 80d2036 Simplify to use only one VSS_resolver() call and one call-back. Message-ID: commit 80d20364692a644f2f1ede5bb713e6e91fbcb98a Author: Poul-Henning Kamp Date: Thu Mar 12 08:53:54 2015 +0000 Simplify to use only one VSS_resolver() call and one call-back. diff --git a/lib/libvcc/vcc_utils.c b/lib/libvcc/vcc_utils.c index 694294c..9e8ef9e 100644 --- a/lib/libvcc/vcc_utils.c +++ b/lib/libvcc/vcc_utils.c @@ -146,6 +146,9 @@ struct rss { struct suckaddr *vsa4; struct suckaddr *vsa6; + struct vsb *vsb; + int retval; + int wrong; }; static int __match_proto__(vss_resolved_f) @@ -153,40 +156,33 @@ rs_callback(void *priv, const struct suckaddr *vsa) { struct rss *rss; int v; + char a[VTCP_ADDRBUFSIZE]; + char p[VTCP_PORTBUFSIZE]; CAST_OBJ_NOTNULL(rss, priv, RSS_MAGIC); assert(VSA_Sane(vsa)); v = VSA_Get_Proto(vsa); + VTCP_name(vsa, a, sizeof a, p, sizeof p); + VSB_printf(rss->vsb, "\t%s:%s\n", a, p); if (v == AF_INET) { if (rss->vsa4 == NULL) rss->vsa4 = VSA_Clone(vsa); else if (VSA_Compare(vsa, rss->vsa4)) - return (-2); + rss->wrong++; + rss->retval++; } else if (v == AF_INET6) { if (rss->vsa6 == NULL) rss->vsa6 = VSA_Clone(vsa); else if (VSA_Compare(vsa, rss->vsa6)) - return (-2); + rss->wrong++; + rss->retval++; } else { WRONG("Wrong protocol"); } return (0); } -static int __match_proto__(vss_resolved_f) -rs_callback2(void *priv, const struct suckaddr *vsa) -{ - struct vcc *tl; - char a[VTCP_ADDRBUFSIZE]; - char p[VTCP_PORTBUFSIZE]; - - CAST_OBJ_NOTNULL(tl, priv, VCC_MAGIC); - VTCP_name(vsa, a, sizeof a, p, sizeof p); - VSB_printf(tl->sb, "\t%s:%s\n", a, p); - return (0); -} - void Resolve_Sockaddr(struct vcc *tl, const char *host, @@ -200,7 +196,7 @@ Resolve_Sockaddr(struct vcc *tl, const struct token *t_err, const char *errid) { - int error, retval = 0; + int error; struct rss *rss; const char *err; @@ -211,8 +207,11 @@ Resolve_Sockaddr(struct vcc *tl, ALLOC_OBJ(rss, RSS_MAGIC); AN(rss); + rss->vsb = VSB_new_auto(); + AN(rss->vsb); error = VSS_resolver(host, def_port, rs_callback, rss, &err); + AZ(VSB_finish(rss->vsb)); if (err != NULL) { VSB_printf(tl->sb, "%s '%.*s' could not be resolved to an IP address:\n" @@ -222,46 +221,37 @@ Resolve_Sockaddr(struct vcc *tl, vcc_ErrWhere(tl, t_err); free(rss->vsa4); free(rss->vsa6); + VSB_delete(rss->vsb); FREE_OBJ(rss); return; } + AZ(error); if (rss->vsa4 != NULL) { vcc_suckaddr(tl, host, rss->vsa4, ipv4, ipv4_ascii, p_ascii); free(rss->vsa4); - retval++; } if (rss->vsa6 != NULL) { vcc_suckaddr(tl, host, rss->vsa6, ipv6, ipv6_ascii, p_ascii); free(rss->vsa6); - retval++; } - FREE_OBJ(rss); - if (error == -2 || retval > maxips) { + if (rss->retval == 0) { + VSB_printf(tl->sb, + "%s '%.*s': resolves to " + "neither IPv4 nor IPv6 addresses.\n", + errid, PF(t_err) ); + vcc_ErrWhere(tl, t_err); + } + if (rss->wrong || rss->retval > maxips) { VSB_printf(tl->sb, "%s %.*s: resolves to too many addresses.\n" "Only one IPv4 %s IPv6 are allowed.\n" "Please specify which exact address " - "you want to use, we found all of these:\n", + "you want to use, we found all of these:\n%s", errid, PF(t_err), - maxips > 1 ? "and one" : "or"); - (void)VSS_resolver(host, def_port, rs_callback2, tl, &err); - if (err != NULL) { - VSB_printf(tl->sb, - "%s '%.*s' could not be resolved to an" - " IP address:\n" - "\t%s\n" - "(Sorry if that error message is gibberish.)\n", - errid, PF(t_err), err); - } - vcc_ErrWhere(tl, t_err); - return; - } - AZ(error); - if (retval == 0) { - VSB_printf(tl->sb, - "%s '%.*s': resolves to " - "neither IPv4 nor IPv6 addresses.\n", - errid, PF(t_err) ); + maxips > 1 ? "and one" : "or", + VSB_data(rss->vsb)); vcc_ErrWhere(tl, t_err); } + VSB_delete(rss->vsb); + FREE_OBJ(rss); } From phk at FreeBSD.org Thu Mar 12 09:04:09 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 10:04:09 +0100 Subject: [master] 0bec737 An assert to explain stuff to Coverity Message-ID: commit 0bec737bbb4cfd36c6dc5d84f94ceb3e603b6240 Author: Poul-Henning Kamp Date: Thu Mar 12 09:02:26 2015 +0000 An assert to explain stuff to Coverity diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index 3920468..7f754e1 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -525,6 +525,7 @@ mct_callback(void *priv, const struct suckaddr *sa) VJ_master(JAIL_MASTER_HIGH); sock = VTCP_listen(sa, 10, &err); VJ_master(JAIL_MASTER_LOW); + assert(sock != 0); // We know where stdin is if (sock > 0) { VTCP_myname(sock, abuf, sizeof abuf, pbuf, sizeof pbuf); VSB_printf(vsb, "%s %s\n", abuf, pbuf); From phk at FreeBSD.org Thu Mar 12 09:04:09 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 10:04:09 +0100 Subject: [master] a7c60c1 Fix insignificant resource leak spotted by coverity. Message-ID: commit a7c60c10d79e8b2926a06219f51da81d048383ef Author: Poul-Henning Kamp Date: Thu Mar 12 09:03:47 2015 +0000 Fix insignificant resource leak spotted by coverity. diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index 310b614..dae08f0 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -175,6 +175,7 @@ tweak_listen_address(struct vsb *vsb, const struct parspec *par, } AZ(error); } + VAV_Free(av); REPLACE(mgt_param.listen_address, arg); From phk at FreeBSD.org Thu Mar 12 10:54:34 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 11:54:34 +0100 Subject: [master] f155a96 Retire this test-case. Message-ID: commit f155a967437686141ae86d822e9932db34547399 Author: Poul-Henning Kamp Date: Thu Mar 12 10:53:58 2015 +0000 Retire this test-case. The listen_address parameter will be retired now anyway. diff --git a/bin/varnishtest/tests/r01035.vtc b/bin/varnishtest/tests/r01035.vtc deleted file mode 100644 index 4bcb735..0000000 --- a/bin/varnishtest/tests/r01035.vtc +++ /dev/null @@ -1,8 +0,0 @@ -varnishtest "Test case for #1035" - -varnish v1 -arg "-a 127.0.0.1:80 -b 127.0.0.1:8080" -varnish v1 -cliok "param.set listen_address 127.0.0.1:80" -varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:65540" -varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:65536" -varnish v1 -clierr 106 "param.set listen_address 127.0.0.1:-1" -varnish v1 -cliok "param.set listen_address 127.0.0.1:65535" From phk at FreeBSD.org Thu Mar 12 14:01:24 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 15:01:24 +0100 Subject: [master] 51082a7 Fix whitespace in error message Message-ID: commit 51082a7e7e52112998e23f447c3c88a202018e2a Author: Poul-Henning Kamp Date: Thu Mar 12 12:35:30 2015 +0000 Fix whitespace in error message diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c index 4d33fcb..4f6e5b8 100644 --- a/bin/varnishd/mgt/mgt_param.c +++ b/bin/varnishd/mgt/mgt_param.c @@ -416,7 +416,7 @@ mcf_wash_param(struct cli *cli, const struct parspec *pp, const char **val, AN(*val); VSB_clear(vsb); - VSB_printf(vsb, "FAILED to set %s for param %s:\n\t%s", + VSB_printf(vsb, "FAILED to set %s for param %s: %s\n", name, pp->name, *val); err = pp->func(vsb, pp, *val); AZ(VSB_finish(vsb)); @@ -452,11 +452,11 @@ MCF_InitParams(struct cli *cli) pp = parspecs[i]; if (pp->min != NULL) - mcf_wash_param(cli, pp, &pp->min, "Minimum", vsb); + mcf_wash_param(cli, pp, &pp->min, "minimum", vsb); if (pp->max != NULL) - mcf_wash_param(cli, pp, &pp->max, "Maximum", vsb); + mcf_wash_param(cli, pp, &pp->max, "maximum", vsb); AN(pp->def); - mcf_wash_param(cli, pp, &pp->def, "Default", vsb); + mcf_wash_param(cli, pp, &pp->def, "default", vsb); } VSB_delete(vsb); } From phk at FreeBSD.org Thu Mar 12 14:01:24 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 15:01:24 +0100 Subject: [master] 5808270 Add VTCP_my_suckaddr() function. Message-ID: commit 580827059eeb90e4cfb046ce161fc2716ee91793 Author: Poul-Henning Kamp Date: Thu Mar 12 12:53:26 2015 +0000 Add VTCP_my_suckaddr() function. diff --git a/include/vtcp.h b/include/vtcp.h index 641cc14..f00b44a 100644 --- a/include/vtcp.h +++ b/include/vtcp.h @@ -38,6 +38,7 @@ struct suckaddr; int VTCP_Check(int a); #define VTCP_Assert(a) assert(VTCP_Check(a)) +struct suckaddr *VTCP_my_suckaddr(int sock); void VTCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen); void VTCP_hisname(int sock, char *abuf, unsigned alen, diff --git a/lib/libvarnish/vtcp.c b/lib/libvarnish/vtcp.c index d59b214..a168c5f 100644 --- a/lib/libvarnish/vtcp.c +++ b/lib/libvarnish/vtcp.c @@ -102,6 +102,19 @@ VTCP_name(const struct suckaddr *addr, char *abuf, unsigned alen, /*--------------------------------------------------------------------*/ +struct suckaddr * +VTCP_my_suckaddr(int sock) +{ + struct sockaddr_storage addr_s; + socklen_t l; + + l = sizeof addr_s; + AZ(getsockname(sock, (void *)&addr_s, &l)); + return (VSA_Malloc(&addr_s, l)); +} + +/*--------------------------------------------------------------------*/ + void VTCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen) { From phk at FreeBSD.org Thu Mar 12 14:01:24 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 15:01:24 +0100 Subject: [master] e83eaaf Separate listen addresses by a newline Message-ID: commit e83eaaf56d437ee1b32b8a46495bf40ea465ec9a Author: Poul-Henning Kamp Date: Thu Mar 12 12:54:52 2015 +0000 Separate listen addresses by a newline diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 129e3bf..b05c43f 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -451,7 +451,7 @@ ccf_listen_address(struct cli *cli, const char * const *av, void *priv) if (ls->sock < 0) continue; VTCP_myname(ls->sock, h, sizeof h, p, sizeof p); - VCLI_Out(cli, "%s %s", h, p); + VCLI_Out(cli, "%s %s\n", h, p); } } diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index e9c4b6a..1b154b3 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -532,6 +532,9 @@ varnish_start(struct varnish *v) vtc_log(v->vl, 0, "CLI debug.listen_address command failed: %u %s", u, resp); h = resp; + p = strchr(h, '\n'); + if (p != NULL) + *p = '\0'; p = strchr(h, ' '); AN(p); *p++ = '\0'; From phk at FreeBSD.org Thu Mar 12 14:27:09 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 15:27:09 +0100 Subject: [master] 3b60931 Change shell_err to err_shell and make it work like varnish::err_cli with string expected to be present in stdout. Message-ID: commit 3b60931f49e10a7ea03988edbbe1b8be309a7226 Author: Poul-Henning Kamp Date: Thu Mar 12 14:25:52 2015 +0000 Change shell_err to err_shell and make it work like varnish::err_cli with string expected to be present in stdout. If stderr is to be checked add: "2>&1" to cmd string diff --git a/bin/varnishtest/tests/b00045.vtc b/bin/varnishtest/tests/b00045.vtc index 3518617..e1e524d 100644 --- a/bin/varnishtest/tests/b00045.vtc +++ b/bin/varnishtest/tests/b00045.vtc @@ -14,4 +14,5 @@ client c1 { delay .2 -shell_err 0x200 "${varnishd} -P ${tmpdir}/v1/varnishd.pid -b 127.0.0.1:80 -a :0 -n ${tmpdir} > /dev/null 2>&1" +err_shell {Could not open pid/lock} \ + "${varnishd} -P ${tmpdir}/v1/varnishd.pid -b 127.0.0.1:80 -a :0 -n ${tmpdir} 2>&1" diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c index 4cf7941..6f20ebe 100644 --- a/bin/varnishtest/vtc.c +++ b/bin/varnishtest/vtc.c @@ -420,29 +420,47 @@ cmd_shell(CMD_ARGS) r = system(av[1]); AZ(WEXITSTATUS(r)); } + /********************************************************************** * Shell command execution */ static void -cmd_shell_err(CMD_ARGS) +cmd_err_shell(CMD_ARGS) { (void)priv; (void)cmd; - int r; + struct vsb *vsb; + FILE *fp; + int r, c; if (av == NULL) return; AN(av[1]); AN(av[2]); AZ(av[3]); - vtc_dump(vl, 4, "shell_err", av[2], -1); - r = system(av[2]); - vtc_log(vl, 4, "shell status: 0x%x", r); - if (strtol(av[1], NULL, 0) != r) - vtc_log(vl, 0, "Wrong shell status: 0x%x", r); + vsb = VSB_new_auto(); + AN(vsb); + vtc_dump(vl, 4, "cmd", av[2], -1); + fp = popen(av[2], "r"); + if (fp == NULL) + vtc_log(vl, 0, "popen fails: %s", strerror(errno)); + do { + c = getc(fp); + if (c != EOF) + VSB_putc(vsb, c); + } while (c != EOF); + r = pclose(fp); + vtc_log(vl, 4, "Status = %d", r); + AZ(VSB_finish(vsb)); + vtc_dump(vl, 4, "stdout", VSB_data(vsb), VSB_len(vsb)); + if (strstr(VSB_data(vsb), av[1]) == NULL) + vtc_log(vl, 0, + "Did not find expected string: (\"%s\")", av[1]); else - vtc_log(vl, 4, "Expected shell status: 0x%x", r); + vtc_log(vl, 4, + "Found expected string: (\"%s\")", av[1]); + VSB_delete(vsb); } /********************************************************************** @@ -569,7 +587,7 @@ static const struct cmds cmds[] = { { "delay", cmd_delay }, { "varnishtest",cmd_varnishtest }, { "shell", cmd_shell }, - { "shell_err", cmd_shell_err }, + { "err_shell", cmd_err_shell }, { "sema", cmd_sema }, { "random", cmd_random }, { "feature", cmd_feature }, From phk at FreeBSD.org Thu Mar 12 15:02:21 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 12 Mar 2015 16:02:21 +0100 Subject: [master] 4666acd Eliminate use of $listen_address in these two tests. Message-ID: commit 4666acdf350d008ca7d4acce46b57362286ece26 Author: Poul-Henning Kamp Date: Thu Mar 12 15:02:03 2015 +0000 Eliminate use of $listen_address in these two tests. diff --git a/bin/varnishtest/tests/b00042.vtc b/bin/varnishtest/tests/b00042.vtc index 0c48a17..9fa143e 100644 --- a/bin/varnishtest/tests/b00042.vtc +++ b/bin/varnishtest/tests/b00042.vtc @@ -22,9 +22,6 @@ varnish v1 -clierr "106" "param.set workspace_thread 1x" varnish v1 -clierr "106" "param.set workspace_thread x" varnish v1 -clierr "106" "param.set user ///" varnish v1 -clierr "106" "param.set user ///" -varnish v1 -clierr "106" {param.set listen_address ""} -varnish v1 -clierr "106" {param.set listen_address "&&"} -varnish v1 -clierr "106" {param.set listen_address "\""} varnish v1 -clierr "106" {param.set pool_sess "\""} varnish v1 -clierr "200" {param.set thread_pool_max 110} varnish v1 -clierr "106" {param.set thread_pool_min 111} diff --git a/bin/varnishtest/tests/c00003.vtc b/bin/varnishtest/tests/c00003.vtc index 9e811b6..98573f3 100644 --- a/bin/varnishtest/tests/c00003.vtc +++ b/bin/varnishtest/tests/c00003.vtc @@ -1,20 +1,10 @@ -varnishtest "Check that we start if at least one listen address works" - -server s1 { - rxreq - txresp -hdr "Connection: close" -body "012345\n" -} -start +varnishtest "Check that we fail to start if any listen address does not work" # This requires non-local binds to be disabled. If you see this fail # and are on Linux, ensure /proc/net/ipv4/ip_nonlocal_bind is set to 0. -varnish v1 -cliok "param.set listen_address ${bad_ip}:0" -varnish v1 -vcl+backend {} -clierr 300 start -varnish v1 -cliok "param.set listen_address 127.0.0.1:0,${bad_ip}:9082" -varnish v1 -start +# All bad listen addresses +err_shell "Failed to open (any) accept sockets" {${varnishd} -a "${bad_ip}:0" -n ${tmpdir} 2>&1} -client c1 { - txreq -url "/" - rxresp - expect resp.status == 200 -} -run +# Just one bad listen addresses +# err_shell "Invalid listen address" {${varnishd} -a "127.0.0.1:0,${bad_ip}:0" -n ${tmpdir} 2>&1} From nils.goroll at uplex.de Thu Mar 12 18:04:35 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 12 Mar 2015 19:04:35 +0100 Subject: [master] 6676d90 Don't leave a varnish process running when listening to the bad_ip does succeed Message-ID: commit 6676d9036294f34148847b062451da624597e42e Author: Nils Goroll Date: Thu Mar 12 19:02:44 2015 +0100 Don't leave a varnish process running when listening to the bad_ip does succeed diff --git a/bin/varnishtest/tests/c00003.vtc b/bin/varnishtest/tests/c00003.vtc index 98573f3..12273f7 100644 --- a/bin/varnishtest/tests/c00003.vtc +++ b/bin/varnishtest/tests/c00003.vtc @@ -4,7 +4,7 @@ varnishtest "Check that we fail to start if any listen address does not work" # and are on Linux, ensure /proc/net/ipv4/ip_nonlocal_bind is set to 0. # All bad listen addresses -err_shell "Failed to open (any) accept sockets" {${varnishd} -a "${bad_ip}:0" -n ${tmpdir} 2>&1} +err_shell "Failed to open (any) accept sockets" {${varnishd} -F -a "${bad_ip}:0" -b 127.0.0.1:80 -n ${tmpdir} 2>&1 & pid=$! ; sleep 1 ; kill $pid ; wait } # Just one bad listen addresses -# err_shell "Invalid listen address" {${varnishd} -a "127.0.0.1:0,${bad_ip}:0" -n ${tmpdir} 2>&1} +# err_shell "Invalid listen address" {${varnishd} -F -a "127.0.0.1:0,${bad_ip}:0" -b 127.0.0.1:80 -n ${tmpdir} 2>&1 & pid=$! ; sleep 1 ; kill $pid ; wait } From nils.goroll at uplex.de Thu Mar 12 18:04:35 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Thu, 12 Mar 2015 19:04:35 +0100 Subject: [master] 8c7e459 yes, there are still systems around which cannot resolve service http by default Message-ID: commit 8c7e459dc19542646bba5ca5789bdf99dc5724d0 Author: Nils Goroll Date: Thu Mar 12 19:03:58 2015 +0100 yes, there are still systems around which cannot resolve service http by default diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index dae08f0..dba338e 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -164,7 +164,7 @@ tweak_listen_address(struct vsb *vsb, const struct parspec *par, } VTAILQ_INIT(&lsh); for (i = 1; av[i] != NULL; i++) { - error = VSS_resolver(av[i], "http", tla_callback, av[i], &err); + error = VSS_resolver(av[i], "80", tla_callback, av[i], &err); if (err != NULL) { VSB_printf(vsb, "Invalid listen address "); VSB_quote(vsb, av[i], -1, 0); diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c index 2f167bf..b937404 100644 --- a/lib/libvcc/vcc_backend.c +++ b/lib/libvcc/vcc_backend.c @@ -54,7 +54,7 @@ Emit_Sockaddr(struct vcc *tl, const struct token *t_host, bprintf(buf, "%s %s", t_host->dec, t_port->dec); else bprintf(buf, "%s", t_host->dec); - Resolve_Sockaddr(tl, buf, "http", + Resolve_Sockaddr(tl, buf, "80", &ipv4, &ipv4a, &ipv6, &ipv6a, &pa, 2, t_host, "Backend host"); ERRCHK(tl); if (ipv4 != NULL) { From arianna.aondio at varnish-software.com Fri Mar 13 11:58:50 2015 From: arianna.aondio at varnish-software.com (Arianna Aondio) Date: Fri, 13 Mar 2015 12:58:50 +0100 Subject: [master] f993d44 On retries a complete request is logged. Message-ID: commit f993d444e97b73536058db456cf2f4e7f2c11396 Author: Arianna Aondio Date: Fri Mar 13 12:54:29 2015 +0100 On retries a complete request is logged. Previously BereqMethod,BereqUrl,BereqProtocol and BereqHeader(s) were not logged. Fixes #1684 diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index 1c59ab5..f39fb81 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -243,6 +243,7 @@ vbf_stp_retry(struct worker *wrk, struct busyobj *bo) // XXX: BereqEnd + BereqAcct ? VSL_ChgId(bo->vsl, "bereq", "retry", VXID_Get(wrk, VSL_BACKENDMARKER)); VSLb_ts_busyobj(bo, "Start", bo->t_prev); + http_VSL_log(bo->bereq); return (F_STP_STARTFETCH); } @@ -269,6 +270,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo) AZ(bo->req); http_PrintfHeader(bo->bereq, "X-Varnish: %u", VXID(bo->vsl->wid)); + bo->bereq->nhd--; VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, bo->bereq->ws); From daghf at varnish-software.com Fri Mar 13 12:48:40 2015 From: daghf at varnish-software.com (Dag Haavi Finstad) Date: Fri, 13 Mar 2015 13:48:40 +0100 Subject: [master] 266c5f6 Make this test case less racy. Message-ID: commit 266c5f6dd2e9087db9855508ce21a92a8ad9fabd Author: Dag Haavi Finstad Date: Fri Mar 13 13:48:36 2015 +0100 Make this test case less racy. diff --git a/bin/varnishtest/tests/b00039.vtc b/bin/varnishtest/tests/b00039.vtc index 397006d..b9d40bf 100644 --- a/bin/varnishtest/tests/b00039.vtc +++ b/bin/varnishtest/tests/b00039.vtc @@ -35,6 +35,8 @@ client c1 { expect resp.http.was-304 == "false" } -run +delay 1 + client c1 { txreq rxresp From nils.goroll at uplex.de Fri Mar 13 13:30:06 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 14:30:06 +0100 Subject: [master] d79cdee create secret file before daemonizing so we have a chance to see an error Message-ID: commit d79cdeed1ae66e9035ad8b3cdd0ecbac1f291f19 Author: Nils Goroll Date: Fri Mar 13 14:28:45 2015 +0100 create secret file before daemonizing so we have a chance to see an error diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index b7fc72f..9493fe2 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -657,6 +657,10 @@ main(int argc, char * const *argv) AZ(VSB_finish(vident)); + if (S_arg == NULL) + S_arg = make_secret(dirname); + AN(S_arg); + if (!d_flag && !F_flag) AZ(varnish_daemon(1, 0)); @@ -675,10 +679,6 @@ main(int argc, char * const *argv) if (d_flag) mgt_cli_setup(0, 1, 1, "debug", cli_stdin_close, NULL); - if (S_arg == NULL) - S_arg = make_secret(dirname); - AN(S_arg); - if (*S_arg != '\0') mgt_cli_secret(S_arg); From arianna.aondio at varnish-software.com Fri Mar 13 14:11:57 2015 From: arianna.aondio at varnish-software.com (Arianna Aondio) Date: Fri, 13 Mar 2015 15:11:57 +0100 Subject: [master] 68fcec1 Use http_Unset for a header instead of moving backwards a pointer. Message-ID: commit 68fcec15bb781e8679f70ed5f50d3c4363fc74de Author: Arianna Aondio Date: Fri Mar 13 15:08:11 2015 +0100 Use http_Unset for a header instead of moving backwards a pointer. Provide test case for bug #1684. diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index f39fb81..71770b1 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -269,8 +269,10 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo) else AZ(bo->req); + if (bo->retries > 0) + http_Unset(bo->bereq, "\012X-Varnish:"); + http_PrintfHeader(bo->bereq, "X-Varnish: %u", VXID(bo->vsl->wid)); - bo->bereq->nhd--; VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, bo->bereq->ws); diff --git a/bin/varnishtest/tests/r01684.vtc b/bin/varnishtest/tests/r01684.vtc new file mode 100644 index 0000000..3e0e422 --- /dev/null +++ b/bin/varnishtest/tests/r01684.vtc @@ -0,0 +1,38 @@ +varnishtest "Regression test for #1684" +server s1 { + rxreq + txresp -hdr "foo: 1" + accept + rxreq + txresp -hdr "foo: 2" + accept + rxreq + txresp -hdr "foo: 3" +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { return (pass); } + sub vcl_backend_response { + set beresp.http.bar = bereq.retries; + if (beresp.http.foo != bereq.http.stop) { + return (retry); + } + } +} -start + +# check log for the aborted POST +logexpect l1 -v v1 { + expect * = BereqHeader "^X-Varnish:" + expect * = BereqUnset "^X-Varnish:" + expect * = BereqHeader "^X-Varnish" +} -start + +varnish v1 -cliok "param.set debug +syncvsl" +varnish v1 -cliok "param.set max_retries 2" + +client c1 { + txreq -hdr "stop: 3" + rxresp + expect resp.http.foo == 3 +} -run + From nils.goroll at uplex.de Fri Mar 13 14:37:47 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 15:37:47 +0100 Subject: [master] 3d0030d document jails Message-ID: commit 3d0030db04e179549cfa845524d98a9e92906925 Author: Nils Goroll Date: Fri Mar 13 15:37:20 2015 +0100 document jails diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 9493fe2..4ebc6b3 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -154,6 +154,10 @@ usage(void) fprintf(stderr, FMT, "", " -h classic,"); fprintf(stderr, FMT, "-i identity", "Identity of varnish instance"); fprintf(stderr, FMT, "-j jail[,jailoptions]", "Jail specification"); +#ifdef HAVE_SETPPRIV + fprintf(stderr, FMT, "", " -j solaris"); +#endif + fprintf(stderr, FMT, "", " -j unix[,user=][,ccgroup=]"); fprintf(stderr, FMT, "", " -j none"); fprintf(stderr, FMT, "-l shl,free,fill", "Size of shared memory file"); fprintf(stderr, FMT, "", " shl: space for SHL records [80m]"); diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 1856bcb..c75d32e 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -70,6 +70,44 @@ OPTIONS Specify the identity of the Varnish server. This can be accessed using server.identity from VCL +-j jail[,jailoptions] + Specify the jailing technology to use. + + Jails generalize over various options to reduce the + privileges of varnish sub-processes. They may have + specific options and may be platform specific. Available + jails are: + + * -j solaris + + Reduce privileges(5) for varnishd and sub-process to the + minimally required set. Only available on platforms + which have the setppriv(2) call. + + * -j unix[,user=][,ccgroup=] + + Default on all other platforms if `varnishd` is either + started with an effective uid of 0 (e.g. as root) or as + user ``varnish``. + + With the ``unix`` jail technology activated, varnish + will switch to an alternative user for subprocesses and + change the effective uid of the master process whenever + possible. + + The optional `user` argument specifies which alternative + user to use. It defauls to ``varnish`` + + The optional `ccgroup` argument specifies a group to add + to varnish subprocesses requiring access to a + c-compiler. There is no default. + + * -j none + + last resort jail choice: With jail technology ``none``, + varnish will run all processes with the privileges it + was started with. + -l shl[,free[,fill]] Specifies size of shmlog file. shl is the store for the shared memory log records [80M], free is the store for other @@ -293,7 +331,7 @@ The varnishd daemon was developed by Poul-Henning Kamp in cooperation with Verdens Gang AS and Varnish Software. This manual page was written by Dag-Erling Sm?rgrav with updates by -Stig Sandbeck Mathisen . +Stig Sandbeck Mathisen and others. COPYRIGHT From martin at varnish-software.com Fri Mar 13 15:00:32 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Fri, 13 Mar 2015 16:00:32 +0100 Subject: [4.0] 9d61ea4 Fail fetch on malformed Content-Length header Message-ID: commit 9d61ea4d722549a984d912603902fccfac473824 Author: Martin Blix Grydeland Date: Fri Mar 13 15:23:15 2015 +0100 Fail fetch on malformed Content-Length header Add a common content length parser that is being used by both client and backend side. Original patch by: fgs Fixes: #1691 diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 9727a52..4a74db0 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -208,7 +208,7 @@ struct http { * */ -typedef ssize_t htc_read(struct http_conn *, void *, size_t); +typedef ssize_t htc_read(struct http_conn *, void *, ssize_t); struct http_conn { unsigned magic; @@ -560,7 +560,7 @@ struct busyobj { struct pool_task fetch_task; - char *h_content_length; + ssize_t content_length; #define BO_FLAG(l, r, w, d) unsigned l:1; #include "tbl/bo_flags.h" @@ -1015,6 +1015,7 @@ int http_GetHdrData(const struct http *hp, const char *hdr, int http_GetHdrField(const struct http *hp, const char *hdr, const char *field, char **ptr); double http_GetHdrQ(const struct http *hp, const char *hdr, const char *field); +ssize_t http_GetContentLength(const struct http *hp); uint16_t http_GetStatus(const struct http *hp); void http_SetStatus(struct http *to, uint16_t status); const char *http_GetReq(const struct http *hp); @@ -1041,7 +1042,7 @@ void HTTP1_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *, unsigned maxbytes, unsigned maxhdr); enum htc_status_e HTTP1_Reinit(struct http_conn *htc); enum htc_status_e HTTP1_Rx(struct http_conn *htc); -ssize_t HTTP1_Read(struct http_conn *htc, void *d, size_t len); +ssize_t HTTP1_Read(struct http_conn *htc, void *d, ssize_t len); enum htc_status_e HTTP1_Complete(struct http_conn *htc); uint16_t HTTP1_DissectRequest(struct req *); uint16_t HTTP1_DissectResponse(struct http *sp, const struct http_conn *htc); diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c index c00f330..8fc3d16 100644 --- a/bin/varnishd/cache/cache_http.c +++ b/bin/varnishd/cache/cache_http.c @@ -488,6 +488,35 @@ http_GetHdrField(const struct http *hp, const char *hdr, return (i); } +/*--------------------------------------------------------------------*/ + +ssize_t +http_GetContentLength(const struct http *hp) +{ + ssize_t cl, cll; + char *b; + + CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); + + if (!http_GetHdr(hp, H_Content_Length, &b)) + return (-1); + cl = 0; + if (!vct_isdigit(*b)) + return (-2); + for (;vct_isdigit(*b); b++) { + cll = cl; + cl *= 10; + cl += *b - '0'; + if (cll != cl / 10) + return (-2); + } + while (vct_islws(*b)) + b++; + if (*b != '\0') + return (-2); + return (cl); +} + /*-------------------------------------------------------------------- * XXX: redo with http_GetHdrField() ? */ diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c index e0085a6..f71cfd4 100644 --- a/bin/varnishd/cache/cache_http1_fetch.c +++ b/bin/varnishd/cache/cache_http1_fetch.c @@ -43,29 +43,6 @@ #include "vtcp.h" #include "vtim.h" -/*-------------------------------------------------------------------- - * Convert a string to a size_t safely - */ - -static ssize_t -vbf_fetch_number(const char *nbr, int radix) -{ - uintmax_t cll; - ssize_t cl; - char *q; - - if (*nbr == '\0') - return (-1); - cll = strtoumax(nbr, &q, radix); - if (q == NULL || *q != '\0') - return (-1); - - cl = (ssize_t)cll; - if((uintmax_t)cl != cll) /* Protect against bogusly large values */ - return (-1); - return (cl); -} - /*--------------------------------------------------------------------*/ static enum vfp_status __match_proto__(vfp_pull_f) @@ -167,7 +144,6 @@ ssize_t V1F_Setup_Fetch(struct busyobj *bo) { struct http_conn *htc; - ssize_t cl; CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); htc = &bo->htc; @@ -176,13 +152,15 @@ V1F_Setup_Fetch(struct busyobj *bo) switch(htc->body_status) { case BS_EOF: + assert(bo->content_length == -1); VFP_Push(bo, v1f_pull_eof, 0); return(-1); case BS_LENGTH: - cl = vbf_fetch_number(bo->h_content_length, 10); - VFP_Push(bo, v1f_pull_straight, cl); - return (cl); + assert(bo->content_length > 0); + VFP_Push(bo, v1f_pull_straight, bo->content_length); + return (bo->content_length); case BS_CHUNKED: + assert(bo->content_length == -1); VFP_Push(bo, v1f_pull_chunked, -1); return (-1); case BS_NONE: diff --git a/bin/varnishd/cache/cache_http1_fsm.c b/bin/varnishd/cache/cache_http1_fsm.c index b398dc2..f1a6889 100644 --- a/bin/varnishd/cache/cache_http1_fsm.c +++ b/bin/varnishd/cache/cache_http1_fsm.c @@ -262,22 +262,22 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req) static enum req_body_state_e http1_req_body_status(struct req *req) { - char *ptr, *endp; + ssize_t cl; CHECK_OBJ_NOTNULL(req, REQ_MAGIC); - if (http_GetHdr(req->http, H_Content_Length, &ptr)) { - AN(ptr); - if (*ptr == '\0') - return (REQ_BODY_FAIL); - req->req_bodybytes = strtoul(ptr, &endp, 10); - if (*endp != '\0' && !vct_islws(*endp)) - return (REQ_BODY_FAIL); - if (req->req_bodybytes == 0) - return (REQ_BODY_NONE); + req->req_bodybytes = 0; + cl = http_GetContentLength(req->http); + if (cl == -2) + return (REQ_BODY_FAIL); + else if (cl == 0) + return (REQ_BODY_NONE); + else if (cl > 0) { + req->req_bodybytes = cl; req->h1.bytes_yet = req->req_bodybytes - req->h1.bytes_done; return (REQ_BODY_PRESENT); } + assert(cl == -1); /* No Content-Length header */ if (http_HdrIs(req->http, H_Transfer_Encoding, "chunked")) { req->chunk_ctr = -1; return (REQ_BODY_CHUNKED); diff --git a/bin/varnishd/cache/cache_http1_proto.c b/bin/varnishd/cache/cache_http1_proto.c index f0a1abc..ff58c69 100644 --- a/bin/varnishd/cache/cache_http1_proto.c +++ b/bin/varnishd/cache/cache_http1_proto.c @@ -191,14 +191,15 @@ HTTP1_Rx(struct http_conn *htc) * Read up to len bytes, returning pipelined data first. */ -ssize_t -HTTP1_Read(struct http_conn *htc, void *d, size_t len) +ssize_t __match_proto__(htc_read) +HTTP1_Read(struct http_conn *htc, void *d, ssize_t len) { size_t l; unsigned char *p; ssize_t i = 0; CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); + assert(len > 0); l = 0; p = d; if (htc->pipeline.b) { diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c index f03d32e..d05c823 100644 --- a/bin/varnishd/cache/cache_rfc2616.c +++ b/bin/varnishd/cache/cache_rfc2616.c @@ -188,6 +188,7 @@ enum body_status RFC2616_Body(struct busyobj *bo, struct dstat *stats) { struct http *hp; + ssize_t cl; char *b; hp = bo->beresp; @@ -199,6 +200,8 @@ RFC2616_Body(struct busyobj *bo, struct dstat *stats) else bo->should_close = 0; + bo->content_length = -1; + if (!strcasecmp(http_GetReq(bo->bereq), "head")) { /* * A HEAD request can never have a body in the reply, @@ -246,9 +249,18 @@ RFC2616_Body(struct busyobj *bo, struct dstat *stats) return (BS_ERROR); } - if (http_GetHdr(hp, H_Content_Length, &bo->h_content_length)) { - stats->fetch_length++; - return (BS_LENGTH); + cl = http_GetContentLength(hp); + if (cl == -2) + return (BS_ERROR); + if (cl >= 0) { + bo->content_length = cl; + if (cl == 0) { + stats->fetch_zero++; + return (BS_NONE); + } else { + stats->fetch_length++; + return (BS_LENGTH); + } } if (http_HdrIs(hp, H_Connection, "keep-alive")) { diff --git a/bin/varnishtest/tests/r01691.vtc b/bin/varnishtest/tests/r01691.vtc new file mode 100644 index 0000000..eb56079 --- /dev/null +++ b/bin/varnishtest/tests/r01691.vtc @@ -0,0 +1,21 @@ +varnishtest "Test bogus Content-Length header" + +server s1 { + rxreq + txresp -nolen -hdr "Content-Length: bogus" +} -start + +varnish v1 -vcl+backend { + +} -start + +logexpect l1 -v v1 { + expect * 1002 VCL_Error "Body cannot be fetched" +} -start + +client c1 { + txreq + rxresp +} -run + +logexpect l1 -wait From nils.goroll at uplex.de Fri Mar 13 15:05:18 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 16:05:18 +0100 Subject: [master] 284bebb fix RST for options Message-ID: commit 284bebbf7faf7dc7c4a949fd51cf563506286e7e Author: Nils Goroll Date: Fri Mar 13 15:56:30 2015 +0100 fix RST for options We need them angle brackets. http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#option-lists diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index c75d32e..9f192c8 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -27,7 +27,8 @@ satisfy future requests for the same document. OPTIONS ======= --a address[:port][,address[:port][...] +-a + Listen for client requests on the specified address and port. The address can be a host name (?localhost?), an IPv4 dotted-quad (?127.0.0.1?), or an IPv6 address @@ -38,7 +39,7 @@ OPTIONS listening addresses and ports can be specified as a whitespace or comma -separated list. --b host[:port] +-b Use the specified host as backend server. If port is not specified, the default is 8080. @@ -63,14 +64,14 @@ OPTIONS connections. This is a shortcut for specifying the group run-time parameter. --h type[,options] +-h Specifies the hash algorithm. See Hash Algorithms for a list of supported algorithms. -i identity Specify the identity of the Varnish server. This can be accessed using server.identity from VCL --j jail[,jailoptions] +-j Specify the jailing technology to use. Jails generalize over various options to reduce the @@ -78,44 +79,41 @@ OPTIONS specific options and may be platform specific. Available jails are: - * -j solaris - - Reduce privileges(5) for varnishd and sub-process to the - minimally required set. Only available on platforms - which have the setppriv(2) call. - - * -j unix[,user=][,ccgroup=] - - Default on all other platforms if `varnishd` is either - started with an effective uid of 0 (e.g. as root) or as - user ``varnish``. + -j solaris + Reduce privileges(5) for varnishd and sub-process to + the minimally required set. Only available on + platforms which have the setppriv(2) call. - With the ``unix`` jail technology activated, varnish - will switch to an alternative user for subprocesses and - change the effective uid of the master process whenever - possible. + -j + Default on all other platforms if `varnishd` is either + started with an fe + as user ``varnish``. - The optional `user` argument specifies which alternative - user to use. It defauls to ``varnish`` + With the ``unix`` jail technology activated, varnish + will switch to an alternative user for subprocesses + and change the effective uid of the master process + whenever possible. - The optional `ccgroup` argument specifies a group to add - to varnish subprocesses requiring access to a - c-compiler. There is no default. + The optional `user` argument specifies which + alternative user to use. It defauls to ``varnish`` - * -j none + The optional `ccgroup` argument specifies a group to + add to varnish subprocesses requiring access to a + c-compiler. There is no default. - last resort jail choice: With jail technology ``none``, - varnish will run all processes with the privileges it - was started with. + -j none + last resort jail choice: With jail technology + ``none``, varnish will run all processes with the + privileges it was started with. --l shl[,free[,fill]] +-l Specifies size of shmlog file. shl is the store for the shared memory log records [80M], free is the store for other allocations [1M] and fill determines how the log is [+]. Scaling suffixes like 'k', 'M' can be used up to (E)xabytes. Default is 80 Megabytes. --M address:port +-M Connect to this port and offer the command line interface. Think of it as a reverse shell. When running with -M and there is no backend defined the child process (the cache) will not start @@ -130,12 +128,12 @@ OPTIONS -P file Write the process's PID to the specified file. --p param=value +-p Set the parameter specified by param to the specified value. See Run-Time Parameters for a list of parameters. This option can be used multiple times to specify multiple parameters. --r param[,param...] +-r Make the listed parameters read only. This gives the system administrator a way to limit what the Varnish CLI can do. Consider making parameters such as *user*, *group*, *cc_command*, @@ -143,7 +141,7 @@ OPTIONS to escalate privileges from the CLI. Protecting *listen_address* may also be a good idea. --s [name=]type[,options] +-s <[name=]type[,options]> Use the specified storage backend. The storage backends can be one of the following: * malloc[,size] * file,path[,size[,granularity]] @@ -156,7 +154,7 @@ OPTIONS -S file Path to a file containing a secret used for authorizing access to the management port. --T address[:port] +-T Offer a management interface on the specified address and port. See Management Interface for a list of management commands. From nils.goroll at uplex.de Fri Mar 13 15:05:18 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 16:05:18 +0100 Subject: [master] 3e67d2a a little less indentation, a little more action please Message-ID: commit 3e67d2a329ed7b4015ea6a88f2b655a09c47e7a1 Author: Nils Goroll Date: Fri Mar 13 16:05:11 2015 +0100 a little less indentation, a little more action please diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 9f192c8..f4c825f 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -29,147 +29,176 @@ OPTIONS -a - Listen for client requests on the specified address and - port. The address can be a host name (?localhost?), an - IPv4 dotted-quad (?127.0.0.1?), or an IPv6 address - enclosed in square brackets (?[::1]?). If address is not - specified, varnishd will listen on all available IPv4 and - IPv6 interfaces. If port is not specified, the default - HTTP port as listed in /etc/services is used. Multiple - listening addresses and ports can be specified as a - whitespace or comma -separated list. + Listen for client requests on the specified address and port. The + address can be a host name (?localhost?), an IPv4 dotted-quad + (?127.0.0.1?), or an IPv6 address enclosed in square brackets + (?[::1]?). If address is not specified, varnishd will listen on all + available IPv4 and IPv6 interfaces. If port is not specified, the + default HTTP port as listed in /etc/services is used. Multiple + listening addresses and ports can be specified as a whitespace or + comma -separated list. -b - Use the specified host as backend server. If port is not - specified, the default is 8080. --C Print VCL code compiled to C language and exit. Specify the VCL file - to compile with the -f option. + Use the specified host as backend server. If port is not specified, + the default is 8080. --d Enables debugging mode: The parent process runs in the foreground - with a CLI connection on stdin/stdout, and the child - process must be started explicitly with a CLI command. - Terminating the parent process will also terminate the - child. +-C --f config Use the specified VCL configuration file instead of the - builtin default. See vcl(7) for details on VCL - syntax. When no configuration is supplied varnishd will - not start the cache process. + Print VCL code compiled to C language and exit. Specify the VCL file + to compile with the -f option. --F Run in the foreground. +-d --g group Specifies the name of an unprivileged group to which the - child process should switch before it starts accepting - connections. This is a shortcut for specifying the group - run-time parameter. + Enables debugging mode: The parent process runs in the foreground + with a CLI connection on stdin/stdout, and the child process must be + started explicitly with a CLI command. Terminating the parent + process will also terminate the child. + +-f config + + Use the specified VCL configuration file instead of the builtin + default. See vcl(7) for details on VCL syntax. When no + configuration is supplied varnishd will not start the cache process. + +-F + + Run in the foreground. + +-g group + + Specifies the name of an unprivileged group to which the child + process should switch before it starts accepting connections. This + is a shortcut for specifying the group run-time parameter. -h - Specifies the hash algorithm. See Hash Algorithms for a list of supported algorithms. + + Specifies the hash algorithm. See Hash Algorithms for a list of + supported algorithms. -i identity - Specify the identity of the Varnish server. This can be accessed using server.identity - from VCL + + Specify the identity of the Varnish server. This can be accessed + using server.identity from VCL -j - Specify the jailing technology to use. - Jails generalize over various options to reduce the - privileges of varnish sub-processes. They may have - specific options and may be platform specific. Available - jails are: + Specify the jailing technology to use. + + Jails generalize over various options to reduce the privileges of + varnish sub-processes. They may have specific options and may be + platform specific. Available jails are: - -j solaris - Reduce privileges(5) for varnishd and sub-process to - the minimally required set. Only available on - platforms which have the setppriv(2) call. + -j solaris - -j - Default on all other platforms if `varnishd` is either - started with an fe - as user ``varnish``. + Reduce privileges(5) for varnishd and sub-process to the minimally + required set. Only available on platforms which have the + setppriv(2) call. - With the ``unix`` jail technology activated, varnish - will switch to an alternative user for subprocesses - and change the effective uid of the master process - whenever possible. + -j - The optional `user` argument specifies which - alternative user to use. It defauls to ``varnish`` + Default on all other platforms if `varnishd` is either started + with an fe as user ``varnish``. - The optional `ccgroup` argument specifies a group to - add to varnish subprocesses requiring access to a - c-compiler. There is no default. + With the ``unix`` jail technology activated, varnish will switch + to an alternative user for subprocesses and change the effective + uid of the master process whenever possible. - -j none - last resort jail choice: With jail technology - ``none``, varnish will run all processes with the - privileges it was started with. + The optional `user` argument specifies which alternative user to + use. It defauls to ``varnish`` + + The optional `ccgroup` argument specifies a group to add to + varnish subprocesses requiring access to a c-compiler. There is no + default. + + -j none + + last resort jail choice: With jail technology ``none``, varnish + will run all processes with the privileges it was started with. -l - Specifies size of shmlog file. shl is the store for the - shared memory log records [80M], free is the store for other - allocations [1M] and fill determines how the log is [+]. - Scaling suffixes like 'k', 'M' can be used up to - (E)xabytes. Default is 80 Megabytes. + + Specifies size of shmlog file. shl is the store for the shared + memory log records [80M], free is the store for other allocations + [1M] and fill determines how the log is [+]. Scaling suffixes like + 'k', 'M' can be used up to (E)xabytes. Default is 80 Megabytes. -M - Connect to this port and offer the command line interface. - Think of it as a reverse shell. When running with -M and there is - no backend defined the child process (the cache) will not start - initially. --n name Specify the name for this instance. Amonst other things, this - name is used to construct the name of the directory in - which varnishd keeps temporary files and persistent state. - If the specified name begins with a forward slash, it is - interpreted as the absolute path to the directory which - should be used for this purpose. + Connect to this port and offer the command line interface. Think of + it as a reverse shell. When running with -M and there is no backend + defined the child process (the cache) will not start initially. --P file Write the process's PID to the specified file. +-n name + + Specify the name for this instance. Amonst other things, this name + is used to construct the name of the directory in which varnishd + keeps temporary files and persistent state. If the specified name + begins with a forward slash, it is interpreted as the absolute path + to the directory which should be used for this purpose. + +-P file + + Write the process's PID to the specified file. -p - Set the parameter specified by param to the specified value. See - Run-Time Parameters for a list of parameters. This option can be - used multiple times to specify multiple parameters. + + Set the parameter specified by param to the specified value. See + Run-Time Parameters for a list of parameters. This option can be + used multiple times to specify multiple parameters. -r - Make the listed parameters read only. This gives the - system administrator a way to limit what the Varnish CLI can do. - Consider making parameters such as *user*, *group*, *cc_command*, - *vcc_allow_inline_c* read only as these can potentially be used - to escalate privileges from the CLI. - Protecting *listen_address* may also be a good idea. + + Make the listed parameters read only. This gives the system + administrator a way to limit what the Varnish CLI can do. Consider + making parameters such as *user*, *group*, *cc_command*, + *vcc_allow_inline_c* read only as these can potentially be used to + escalate privileges from the CLI. Protecting *listen_address* may + also be a good idea. -s <[name=]type[,options]> - Use the specified storage backend. The storage backends can be one of the following: - * malloc[,size] - * file,path[,size[,granularity]] - * persistent,path,size - See Storage Types in the Users Guide for more information - on the various storage backends. This option can be used - multiple times to specify multiple storage files. Names - are referenced in logs, vcl, statistics, etc. + Use the specified storage backend. The storage backends can be one + of the following: + + -s + + -s + + -s --S file Path to a file containing a secret used for authorizing access to the management port. + See Storage Types in the Users Guide for more information on the + various storage backends. This option can be used multiple times to + specify multiple storage files. Names are referenced in logs, vcl, + statistics, etc. + +-S file + + Path to a file containing a secret used for authorizing access to + the management port. -T - Offer a management interface on the specified address and port. See Management - Interface for a list of management commands. --t ttl Specifies a hard minimum time to live for cached documents. This - is a shortcut for specifying the default_ttl run-time parameter. + Offer a management interface on the specified address and port. See + Management Interface for a list of management commands. + +-t ttl + + Specifies a hard minimum time to live for cached documents. This is + a shortcut for specifying the default_ttl run-time parameter. --u user Specifies the name of an unprivileged user to which the child - process should switch before it starts accepting - connections. This is a shortcut for specifying the user - runtime parameter. +-u user - If specifying both a user and a group, the user should be - specified first. + Specifies the name of an unprivileged user to which the child + process should switch before it starts accepting connections. This + is a shortcut for specifying the user runtime parameter. --V Display the version number and exit. + If specifying both a user and a group, the user should be specified + first. + +-V + + Display the version number and exit. Hash Algorithms @@ -177,64 +206,58 @@ Hash Algorithms The following hash algorithms are available: -critbit - A self-scaling tree structure. The default hash algorithm in - Varnish Cache 2.1 and onwards. In comparison to a more traditional - B tree the critbit tree is almost completely lockless. Do not - change this unless you are certain what you're doing. +-h critbit -simple_list - A simple doubly-linked list. Not recommended for production use. + self-scaling tree structure. The default hash algorithm in Varnish + Cache 2.1 and onwards. In comparison to a more traditional B tree + the critbit tree is almost completely lockless. Do not change this + unless you are certain what you're doing. -classic[,buckets] - A standard hash table. The hash key is the CRC32 of the object's - URL modulo the size of the hash table. Each table entry points to - a list of elements which share the same hash key. The buckets - parameter specifies the number of entries in the hash table. The - default is 16383. +-h simple_list + A simple doubly-linked list. Not recommended for production use. -Storage Types -------------- +-h -The following storage types are available: + A standard hash table. The hash key is the CRC32 of the object's URL + modulo the size of the hash table. Each table entry points to a + list of elements which share the same hash key. The buckets + parameter specifies the number of entries in the hash table. The + default is 16383. -malloc -~~~~~~ -syntax: malloc[,size] +Storage Types +------------- -malloc is a memory based backend. +The following storage types are available: -file -~~~~ +-s -syntax: file,path[,size[,granularity]] + malloc is a memory based backend. -The file backend stores data in a file on disk. The file will be -accessed using mmap. +-s -The path is mandatory. If path points to a directory, a temporary file -will be created in that directory and immediately unlinked. If path -points to a non-existing file, the file will be created. + The file backend stores data in a file on disk. The file will be + accessed using mmap. -If size is omitted, and path points to an existing file with a size -greater than zero, the size of that file will be used. If not, an -error is reported. + The path is mandatory. If path points to a directory, a temporary + file will be created in that directory and immediately unlinked. If + path points to a non-existing file, the file will be created. -Granularity sets the allocation block size. Defaults to the system -page size or the filesystem block size, whichever is larger. + If size is omitted, and path points to an existing file with a size + greater than zero, the size of that file will be used. If not, an + error is reported. -persistent (experimental) -~~~~~~~~~~~~~~~~~~~~~~~~~ + Granularity sets the allocation block size. Defaults to the system + page size or the filesystem block size, whichever is larger. -syntax: persistent,path,size +-s -Persistent storage. Varnish will store objects in a file in a manner -that will secure the survival of *most* of the objects in the event of -a planned or unplanned shutdown of Varnish. The persistent storage -backend has multiple issues with it and will likely be removed from a -future version of Varnish. + Persistent storage. Varnish will store objects in a file in a manner + that will secure the survival of *most* of the objects in the event + of a planned or unplanned shutdown of Varnish. The persistent + storage backend has multiple issues with it and will likely be + removed from a future version of Varnish. Management Interface From nils.goroll at uplex.de Fri Mar 13 15:30:50 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 16:30:50 +0100 Subject: [master] 377f04d restructure, improve references, other fixes Message-ID: commit 377f04d13429bf657faf3b3e1c66b30abf56720f Author: Nils Goroll Date: Fri Mar 13 16:30:41 2015 +0100 restructure, improve references, other fixes diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index f4c825f..6783df3 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -58,7 +58,7 @@ OPTIONS -f config Use the specified VCL configuration file instead of the builtin - default. See vcl(7) for details on VCL syntax. When no + default. See :ref:`users_vcl` for details on VCL syntax. When no configuration is supplied varnishd will not start the cache process. -F @@ -73,8 +73,8 @@ OPTIONS -h - Specifies the hash algorithm. See Hash Algorithms for a list of - supported algorithms. + Specifies the hash algorithm. See :ref:`ref-varnishd-opt_s` for a + list of supported algorithms. -i identity @@ -85,37 +85,6 @@ OPTIONS Specify the jailing technology to use. - Jails generalize over various options to reduce the privileges of - varnish sub-processes. They may have specific options and may be - platform specific. Available jails are: - - -j solaris - - Reduce privileges(5) for varnishd and sub-process to the minimally - required set. Only available on platforms which have the - setppriv(2) call. - - -j - - Default on all other platforms if `varnishd` is either started - with an fe as user ``varnish``. - - With the ``unix`` jail technology activated, varnish will switch - to an alternative user for subprocesses and change the effective - uid of the master process whenever possible. - - The optional `user` argument specifies which alternative user to - use. It defauls to ``varnish`` - - The optional `ccgroup` argument specifies a group to add to - varnish subprocesses requiring access to a c-compiler. There is no - default. - - -j none - - last resort jail choice: With jail technology ``none``, varnish - will run all processes with the privileges it was started with. - -l Specifies size of shmlog file. shl is the store for the shared @@ -144,8 +113,8 @@ OPTIONS -p Set the parameter specified by param to the specified value. See - Run-Time Parameters for a list of parameters. This option can be - used multiple times to specify multiple parameters. + :ref:`ref-varnishd-params` for a list of parameters. This option can + be used multiple times to specify multiple parameters. -r @@ -158,19 +127,10 @@ OPTIONS -s <[name=]type[,options]> - Use the specified storage backend. The storage backends can be one - of the following: + Use the specified storage backend, see :ref:`ref-varnishd-opt_s` - -s - - -s - - -s - - See Storage Types in the Users Guide for more information on the - various storage backends. This option can be used multiple times to - specify multiple storage files. Names are referenced in logs, vcl, - statistics, etc. + This option can be used multiple times to specify multiple storage + files. Names are referenced in logs, vcl, statistics, etc. -S file @@ -180,7 +140,7 @@ OPTIONS -T Offer a management interface on the specified address and port. See - Management Interface for a list of management commands. + :ref:`ref-varnishd-opt_T` for a list of management commands. -t ttl @@ -200,9 +160,10 @@ OPTIONS Display the version number and exit. +.. _opt_h: -Hash Algorithms ---------------- +Hash Algorithm Options +---------------------- The following hash algorithms are available: @@ -226,8 +187,10 @@ The following hash algorithms are available: default is 16383. -Storage Types -------------- +.. _ref-varnishd-opt_s: + +Storage Backend Options +----------------------- The following storage types are available: @@ -259,6 +222,43 @@ The following storage types are available: storage backend has multiple issues with it and will likely be removed from a future version of Varnish. +.. _ref-varnishd-opt_j: + +Jail Options +------------ + +Varnish jails are a generalization over various platform specific +methods to reduce the privileges of varnish processes. They may have +specific options. Available jails are: + +-j solaris + + Reduce privileges(5) for varnishd and sub-process to the minimally + required set. Only available on platforms which have the setppriv(2) + call. + +-j + + Default on all other platforms if `varnishd` is either started with + an effective uid of 0 ("as root") or as user ``varnish``. + + With the ``unix`` jail technology activated, varnish will switch to + an alternative user for subprocesses and change the effective uid of + the master process whenever possible. + + The optional `user` argument specifies which alternative user to + use. It defauls to ``varnish`` + + The optional `ccgroup` argument specifies a group to add to varnish + subprocesses requiring access to a c-compiler. There is no default. + +-j none + + last resort jail choice: With jail technology ``none``, varnish will + run all processes with the privileges it was started with. + + +.. _ref-varnishd-opt_T: Management Interface -------------------- @@ -270,49 +270,68 @@ is through varnishadm(1). The commands available are documented in varnish(7). -Run-Time Parameters -------------------- +.. _ref-varnishd-params: + +RUN TIME PARAMETERS +=================== + +Run Time Parameter Flags +------------------------ Runtime parameters are marked with shorthand flags to avoid repeating the same text over and over in the table below. The meaning of the flags are: -experimental - We have no solid information about good/bad/optimal values for - this parameter. Feedback with experience and observations are - most welcome. +* `experimental` + + We have no solid information about good/bad/optimal values for this + parameter. Feedback with experience and observations are most + welcome. + +* `delayed` + + This parameter can be changed on the fly, but will not take effect + immediately. + +* `restart` + + The worker process must be stopped and restarted, before this + parameter takes effect. + +* `reload` + + The VCL programs must be reloaded for this parameter to take effect. + +* `experimental` + + We're not really sure about this parameter, tell us what you find. + +* `wizard` -delayed - This parameter can be changed on the fly, but will not take - effect immediately. + Do not touch unless you *really* know what you're doing. -restart - The worker process must be stopped and restarted, before this - parameter takes effect. +* `only_root` -reload - The VCL programs must be reloaded for this parameter to take effect. + Only works if varnishd is running as root. -experimental - We're not really sure about this parameter, tell us what you find. +Default Value Exceptions on 32 bit Systems +------------------------------------------ -wizard - Do not touch unless you *really* know what you're doing. +Be aware that on 32 bit systems, certain default values are reduced +relative to the values listed below, in order to conserve VM space: -only_root - Only works if varnishd is running as root. +* workspace_client: 16k +* thread_pool_workspace: 16k +* http_resp_size: 8k +* http_req_size: 12k +* gzip_stack_buffer: 4k +* thread_pool_stack: 64k -Here is a list of all parameters, current as of last time we -remembered to update the manual page. This text is produced from the -same text you will find in the CLI if you use the param.show command, -so should there be a new parameter which is not listed here, you can -find the description using the CLI commands. +List of Parameters +------------------ -Be aware that on 32 bit systems, certain default values, such as -workspace_client (=16k), thread_pool_workspace (=16k), http_resp_size -(=8k), http_req_size (=12k), gzip_stack_buffer (=4k) and -thread_pool_stack (=64k) are reduced relative to the values listed -here, in order to conserve VM space. +This text is produced from the same text you will find in the CLI if +you use the param.show command: .. include:: ../include/params.rst From nils.goroll at uplex.de Fri Mar 13 16:37:09 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 17:37:09 +0100 Subject: [master] 9cd3bc0 This is how we get refernces working both with shinx and rst2(man|pdf) Message-ID: commit 9cd3bc0d7eca8a7fdb3ed7b259621ff662a2d6bc Author: Nils Goroll Date: Fri Mar 13 17:36:55 2015 +0100 This is how we get refernces working both with shinx and rst2(man|pdf) diff --git a/doc/README.WRITING_RST.rst b/doc/README.WRITING_RST.rst new file mode 100644 index 0000000..06e4a76 --- /dev/null +++ b/doc/README.WRITING_RST.rst @@ -0,0 +1,56 @@ +THINGS TO CONSIDER WHEN WRITING VARNISH RST DOCUMENTATION +========================================================= + +References are tricky +--------------------- + +To build html documentation, we want to create cross-document +cross-references using:: + + :ref:`reference name` + +Trouble is that ``rst2man`` and ``rst2pdf`` refuse to parse `ref` +roles (and wouldn't know where to create a link for cross-document +references anyway), so we need to do something of both: + +* set link targets on the top of documents ending up in man-pages + following the manpage naming scheme, e.g.:: + + .. _varnishd(1): + +* set link targets for imporant paramgraphs following the scheme + ref-`doc`-`section`, for instance:: + + .. _ref-varnishd-opt_T: + + These can be referenced from other documents making up the html + documentation, but not from documents creating man-pages. + +* in all documents which are used to create man-pages, add the + following definition at the top:: + + .. role:: ref(emphasis) + + This will allow the use of `ref` in a compatible manner, IF refences + follow the man-page naming scheme + +* to be compatible both with ``sphinx`` and ``rst2man``, use `implicit + link targets`_ only, like this one creating `References are + tricky`_:: + + `References are tricky`_ + +.. _implicit link targets: http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#implicit-hyperlink-targets + +HISTORY +======= + +This README was initially started by Nils Goroll. + +COPYRIGHT +========= + +This document is licensed under the same licence as Varnish +itself. See LICENCE for details. + +* Copyright 2014 UPLEX - Nils Goroll Systemoptimierung diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 6783df3..ac88478 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -1,4 +1,6 @@ -.. _ref-varnishd: +.. role:: ref(emphasis) + +.. _varnishd(1): ======== varnishd @@ -58,7 +60,7 @@ OPTIONS -f config Use the specified VCL configuration file instead of the builtin - default. See :ref:`users_vcl` for details on VCL syntax. When no + default. See :ref:`vcl(7)` for details on VCL syntax. When no configuration is supplied varnishd will not start the cache process. -F @@ -73,7 +75,7 @@ OPTIONS -h - Specifies the hash algorithm. See :ref:`ref-varnishd-opt_s` for a + Specifies the hash algorithm. See `Hash Algorithm Options`_ for a list of supported algorithms. -i identity @@ -112,9 +114,9 @@ OPTIONS -p - Set the parameter specified by param to the specified value. See - :ref:`ref-varnishd-params` for a list of parameters. This option can - be used multiple times to specify multiple parameters. + Set the parameter specified by param to the specified value, see + `List of Parameters`_ for details. This option can be used multiple + times to specify multiple parameters. -r @@ -127,7 +129,7 @@ OPTIONS -s <[name=]type[,options]> - Use the specified storage backend, see :ref:`ref-varnishd-opt_s` + Use the specified storage backend, see `Storage Backend Options`_. This option can be used multiple times to specify multiple storage files. Names are referenced in logs, vcl, statistics, etc. @@ -140,7 +142,7 @@ OPTIONS -T Offer a management interface on the specified address and port. See - :ref:`ref-varnishd-opt_T` for a list of management commands. + `Management Interface`_ for a list of management commands. -t ttl diff --git a/doc/sphinx/users-guide/compression.rst b/doc/sphinx/users-guide/compression.rst index 50c5c86..edd3c6f 100644 --- a/doc/sphinx/users-guide/compression.rst +++ b/doc/sphinx/users-guide/compression.rst @@ -11,7 +11,7 @@ be smart and do the sensible thing. If you don't want Varnish tampering with the encoding you can disable compression all together by setting the parameter `http_gzip_support` to -false. Please see man :ref:`ref-varnishd` for details. +false. Please see man :ref:`varnishd(1)` for details. Default behaviour ~~~~~~~~~~~~~~~~~ diff --git a/doc/sphinx/users-guide/index.rst b/doc/sphinx/users-guide/index.rst index e1c3e83..8716bad 100644 --- a/doc/sphinx/users-guide/index.rst +++ b/doc/sphinx/users-guide/index.rst @@ -20,7 +20,7 @@ following the major interfaces to Varnish as a service: respect to storage, sockets, security and how you can control and communicate with Varnish once it is running. -:ref:`users_vcl` is about getting Varnish to handle the +:ref:`vcl(7)` is about getting Varnish to handle the HTTP requests the way you want, what to cache, how to cache it, modifying HTTP headers etc. etc. diff --git a/doc/sphinx/users-guide/intro.rst b/doc/sphinx/users-guide/intro.rst index 927292a..99419ee 100644 --- a/doc/sphinx/users-guide/intro.rst +++ b/doc/sphinx/users-guide/intro.rst @@ -73,7 +73,7 @@ VCL code can be extended using external modules, called VMODs or even by inline C-code if you are brave, so in terms of what Varnish can do for your HTTP traffic, there really is no limit. -:ref:`users_vcl` describes VCL and what it can do in great detail. +:ref:`vcl(7)` describes VCL and what it can do in great detail. Varnish uses a segment of shared memory to report and log its activities and status. For each HTTP request, a number of very detailed records will diff --git a/doc/sphinx/users-guide/vcl.rst b/doc/sphinx/users-guide/vcl.rst index 86ed8cf..c03bee3 100644 --- a/doc/sphinx/users-guide/vcl.rst +++ b/doc/sphinx/users-guide/vcl.rst @@ -1,4 +1,4 @@ -.. _users_vcl: +.. _vcl(7): VCL - Varnish Configuration Language ------------------------------------ From nils.goroll at uplex.de Fri Mar 13 17:58:09 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 18:58:09 +0100 Subject: [master] 8f3caae maybe the amount of time going into this justifies leaving a trace Message-ID: commit 8f3caaef921cb7b986371fc6742db3395bca3dfd Author: Nils Goroll Date: Fri Mar 13 17:45:35 2015 +0100 maybe the amount of time going into this justifies leaving a trace diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index ac88478..591affa 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -373,7 +373,7 @@ The varnishd daemon was developed by Poul-Henning Kamp in cooperation with Verdens Gang AS and Varnish Software. This manual page was written by Dag-Erling Sm?rgrav with updates by -Stig Sandbeck Mathisen and others. +Stig Sandbeck Mathisen , Nils Goroll and others. COPYRIGHT From nils.goroll at uplex.de Fri Mar 13 17:58:09 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 18:58:09 +0100 Subject: [master] 65f76df nope, here users_vcl _was_ the right reference Message-ID: commit 65f76dfa7733c04be8692d999522b6799a25f325 Author: Nils Goroll Date: Fri Mar 13 17:59:52 2015 +0100 nope, here users_vcl _was_ the right reference diff --git a/doc/sphinx/users-guide/index.rst b/doc/sphinx/users-guide/index.rst index 8716bad..e1c3e83 100644 --- a/doc/sphinx/users-guide/index.rst +++ b/doc/sphinx/users-guide/index.rst @@ -20,7 +20,7 @@ following the major interfaces to Varnish as a service: respect to storage, sockets, security and how you can control and communicate with Varnish once it is running. -:ref:`vcl(7)` is about getting Varnish to handle the +:ref:`users_vcl` is about getting Varnish to handle the HTTP requests the way you want, what to cache, how to cache it, modifying HTTP headers etc. etc. diff --git a/doc/sphinx/users-guide/intro.rst b/doc/sphinx/users-guide/intro.rst index 99419ee..927292a 100644 --- a/doc/sphinx/users-guide/intro.rst +++ b/doc/sphinx/users-guide/intro.rst @@ -73,7 +73,7 @@ VCL code can be extended using external modules, called VMODs or even by inline C-code if you are brave, so in terms of what Varnish can do for your HTTP traffic, there really is no limit. -:ref:`vcl(7)` describes VCL and what it can do in great detail. +:ref:`users_vcl` describes VCL and what it can do in great detail. Varnish uses a segment of shared memory to report and log its activities and status. For each HTTP request, a number of very detailed records will diff --git a/doc/sphinx/users-guide/vcl.rst b/doc/sphinx/users-guide/vcl.rst index c03bee3..3528e7b 100644 --- a/doc/sphinx/users-guide/vcl.rst +++ b/doc/sphinx/users-guide/vcl.rst @@ -1,4 +1,5 @@ -.. _vcl(7): + +.. _users_vcl: VCL - Varnish Configuration Language ------------------------------------ From nils.goroll at uplex.de Fri Mar 13 17:58:09 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 18:58:09 +0100 Subject: [master] 969fa64 the explanation was not quite correct yet Message-ID: commit 969fa6401dae1b3a418034e44863774abf7ea172 Author: Nils Goroll Date: Fri Mar 13 18:05:45 2015 +0100 the explanation was not quite correct yet diff --git a/doc/README.WRITING_RST.rst b/doc/README.WRITING_RST.rst index 06e4a76..19e7fe6 100644 --- a/doc/README.WRITING_RST.rst +++ b/doc/README.WRITING_RST.rst @@ -9,9 +9,10 @@ cross-references using:: :ref:`reference name` -Trouble is that ``rst2man`` and ``rst2pdf`` refuse to parse `ref` -roles (and wouldn't know where to create a link for cross-document -references anyway), so we need to do something of both: +Trouble is that ``rst2man`` and ``rst2pdf`` working on individual +files cannot parse `ref` roles to anything outside the current rst +file, so we need to differenciate link targets depending on the kind +of documentation: * set link targets on the top of documents ending up in man-pages following the manpage naming scheme, e.g.:: @@ -24,19 +25,19 @@ references anyway), so we need to do something of both: .. _ref-varnishd-opt_T: These can be referenced from other documents making up the html - documentation, but not from documents creating man-pages. + documentation, but not from stand-alone documents (like man-pages). * in all documents which are used to create man-pages, add the following definition at the top:: .. role:: ref(emphasis) - This will allow the use of `ref` in a compatible manner, IF refences - follow the man-page naming scheme + This will allow the use of `ref` in a compatible manner, IF + references follow the man-page naming scheme * to be compatible both with ``sphinx`` and ``rst2man``, use `implicit - link targets`_ only, like this one creating `References are - tricky`_:: + link targets`_ in stand-alone documents, like this one creating + `References are tricky`_:: `References are tricky`_ From nils.goroll at uplex.de Fri Mar 13 17:58:09 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 18:58:09 +0100 Subject: [master] b3b122e doc: fix references (as described in doc/README.WRITING_RST.rst) Message-ID: commit b3b122e12afa75dfc8cad931fde57d94c34d3222 Author: Nils Goroll Date: Fri Mar 13 18:50:51 2015 +0100 doc: fix references (as described in doc/README.WRITING_RST.rst) diff --git a/doc/sphinx/installation/bugs.rst b/doc/sphinx/installation/bugs.rst index de433a1..b5fd756 100644 --- a/doc/sphinx/installation/bugs.rst +++ b/doc/sphinx/installation/bugs.rst @@ -92,7 +92,7 @@ general forms: .. (TODO: in the ws-size note above, mention which params to tweak) In your syslog it may all be joined into one single line, but if you -can reproduce the crash, do so while running `varnishd` manually: +can reproduce the crash, do so while running :ref:`varnishd(1)` manually: ``varnishd -d |& tee /tmp/_catch_bug`` @@ -127,8 +127,9 @@ If one or more threads are spinning, use ``strace`` or ``ktrace`` or ``truss`` the Varnish process issues. Be aware that this may generate a lot of very repetitive data, usually one second worth of data is more than enough. -Also, run ``varnishlog`` for a second, and collect the output -for us, and if ``varnishstat`` shows any activity, capture that also. +Also, run :ref:`varnishlog(1)` for a second, and collect the output +for us, and if :ref:`varnishstat(1)` shows any activity, capture that +also. When you have done this, kill the Varnish *child* process, and let the *master* process restart it. Remember to tell us if that does @@ -141,8 +142,8 @@ Varnish does something wrong ============================ These are the easy bugs: usually all we need from you is the relevant -transactions recorded with ``varnishlog`` and your explanation of -what is wrong about what Varnish does. +transactions recorded with :ref:`varnishlog(1)` and your explanation +of what is wrong about what Varnish does. Be aware, that often Varnish does exactly what you asked it to, rather than what you intended it to do. If it sounds like a bug that would diff --git a/doc/sphinx/phk/backends.rst b/doc/sphinx/phk/backends.rst index 9ab6123..952a791 100644 --- a/doc/sphinx/phk/backends.rst +++ b/doc/sphinx/phk/backends.rst @@ -87,8 +87,9 @@ is a wildcard-ish scheme, where you can write things like:: (Input very much welcome) The final question is if we use shortcut notation for output from -varnishd, and the answer is no, because we do not want the stats-counters -to change name because we load another VCL and suddenly need disabiguation. +:ref:`varnishd(1)`, and the answer is no, because we do not want the +stats-counters to change name because we load another VCL and suddenly +need disabiguation. Sharing Health Status diff --git a/doc/sphinx/reference/varnish-cli.rst b/doc/sphinx/reference/varnish-cli.rst index 549f739..663dcd2 100644 --- a/doc/sphinx/reference/varnish-cli.rst +++ b/doc/sphinx/reference/varnish-cli.rst @@ -1,3 +1,7 @@ +.. role:: ref(emphasis) + +.. _varnish-cli(7): + =========== varnish-cli =========== @@ -40,7 +44,7 @@ If you invoke varnishd(1) with -T, -M or -d the CLI will be available. In debug mode (-d) the CLI will be in the foreground, with -T you can connect to it with varnishadm or telnet and with -M varnishd will connect back to a listening service *pushing* the CLI to -that service. Please see varnishd(1) for details. +that service. Please see :ref:`varnishd(1)` for details. Syntax @@ -278,16 +282,16 @@ the backend contains "USERID=1663":: SEE ALSO ======== -* varnishd(1) -* vanrishadm(1) -* vcl(7) +* :ref:`varnishd(1)` +* :ref:`varnishadm(1)` +* :ref:`vcl(7)` HISTORY ======= The Varnish manual page was written by Per Buer in 2011. Some of the -text was taken from the Varnish Cache wiki, the varnishd(7) man page -or the Varnish source code. +text was taken from the Varnish Cache wiki, the :ref:`varnishd(1)` man +page or the Varnish source code. COPYRIGHT ========= diff --git a/doc/sphinx/reference/varnishadm.rst b/doc/sphinx/reference/varnishadm.rst index eedffbb..76f5d3f 100644 --- a/doc/sphinx/reference/varnishadm.rst +++ b/doc/sphinx/reference/varnishadm.rst @@ -1,4 +1,6 @@ -.. _ref-varnishadm: +.. role:: ref(emphasis) + +.. _varnishadm(1): ========== varnishadm @@ -43,13 +45,13 @@ OPTIONS -n name Connect to the instance of varnishd with this name. --T address:port +-T Connect to the management interface at the specified address and port. The syntax and operation of the actual CLI interface is described in -the varnish-cli(7) manual page. Parameteres are described in -varnishd(1) manual page. +the :ref:`varnish-cli(7)` manual page. Parameteres are described in +:ref:`varnishd(1)` manual page. Additionally, a summary of commands can be obtained by issuing the *help* command, and a summary of parameters can be obtained by issuing @@ -73,7 +75,7 @@ Some ways you can use varnishadm:: SEE ALSO ======== -* varnishd(1) +* :ref:`varnishd(1)` HISTORY ======= diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 591affa..90c4344 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -358,13 +358,13 @@ The `varnishd` master process may also OR its exit code SEE ALSO ======== -* varnish-cli(7) -* varnishlog(1) -* varnishhist(1) -* varnishncsa(1) -* varnishstat(1) -* varnishtop(1) -* vcl(7) +* :ref:`varnish-cli(7)` +* :ref:`varnishlog(1)` +* :ref:`varnishhist(1)` +* :ref:`varnishncsa(1)` +* :ref:`varnishstat(1)` +* :ref:`varnishtop(1)` +* :ref:`vcl(7)` HISTORY ======= diff --git a/doc/sphinx/reference/varnishhist.rst b/doc/sphinx/reference/varnishhist.rst index 7823421..6af9746 100644 --- a/doc/sphinx/reference/varnishhist.rst +++ b/doc/sphinx/reference/varnishhist.rst @@ -1,4 +1,6 @@ -.. _ref-varnishhist: +.. role:: ref(emphasis) + +.. _varnishhist(1): =========== varnishhist @@ -33,11 +35,11 @@ The following options are available: SEE ALSO ======== -* varnishd(1) -* varnishlog(1) -* varnishncsa(1) -* varnishstat(1) -* varnishtop(1) +* :ref:`varnishd(1)` +* :ref:`varnishlog(1)` +* :ref:`varnishncsa(1)` +* :ref:`varnishstat(1)` +* :ref:`varnishtop(1)` HISTORY ======= diff --git a/doc/sphinx/reference/varnishlog.rst b/doc/sphinx/reference/varnishlog.rst index 5e22411..e3ae098 100644 --- a/doc/sphinx/reference/varnishlog.rst +++ b/doc/sphinx/reference/varnishlog.rst @@ -1,4 +1,6 @@ -.. _ref-varnishlog: +.. role:: ref(emphasis) + +.. _varnishlog(1): ========== varnishlog @@ -36,13 +38,13 @@ SIGNALS SEE ALSO ======== -* varnishd(1) -* varnishhist(1) -* varnishncsa(1) -* varnishstat(1) -* varnishtop(1) -* vsl(7) -* vsl-query(7) +* :ref:`varnishd(1)` +* :ref:`varnishhist(1)` +* :ref:`varnishncsa(1)` +* :ref:`varnishstat(1)` +* :ref:`varnishtop(1)` +* :ref:`vsl(7)` +* :ref:`vsl-query(7)` HISTORY ======= diff --git a/doc/sphinx/reference/varnishncsa.rst b/doc/sphinx/reference/varnishncsa.rst index c0ab61f..3ab7759 100644 --- a/doc/sphinx/reference/varnishncsa.rst +++ b/doc/sphinx/reference/varnishncsa.rst @@ -1,4 +1,6 @@ -.. _ref-varnishncsa: +.. role:: ref(emphasis) + +.. _varnishncsa(1): =========== varnishncsa @@ -134,9 +136,9 @@ SIGUSR1 SEE ALSO ======== -varnishd(1) -varnishlog(1) -varnishstat(1) +:ref:`varnishd(1)` +:ref:`varnishlog(1)` +:ref:`varnishstat(1)` HISTORY ======= diff --git a/doc/sphinx/reference/varnishstat.rst b/doc/sphinx/reference/varnishstat.rst index c3aa20e..7570ef0 100644 --- a/doc/sphinx/reference/varnishstat.rst +++ b/doc/sphinx/reference/varnishstat.rst @@ -1,4 +1,6 @@ -.. _ref-varnishstat: +.. role:: ref(emphasis) + +.. _varnishstat(1): =========== varnishstat @@ -184,11 +186,11 @@ between each block of output. SEE ALSO ======== -* varnishd(1) -* varnishhist(1) -* varnishlog(1) -* varnishncsa(1) -* varnishtop(1) +* :ref:`varnishd(1)` +* :ref:`varnishhist(1)` +* :ref:`varnishlog(1)` +* :ref:`varnishncsa(1)` +* :ref:`varnishtop(1)` * curses(3) HISTORY diff --git a/doc/sphinx/reference/varnishtest.rst b/doc/sphinx/reference/varnishtest.rst index dd4aa83..f75a621 100644 --- a/doc/sphinx/reference/varnishtest.rst +++ b/doc/sphinx/reference/varnishtest.rst @@ -1,4 +1,6 @@ -.. _ref-varnishtest: +.. role:: ref(emphasis) + +.. _varnishtest(1): =========== varnishtest @@ -114,12 +116,12 @@ SEE ALSO ======== * varnishtest source code repository with tests -* varnishhist(1) -* varnishlog(1) -* varnishncsa(1) -* varnishstat(1) -* varnishtop(1) -* vcl(7) +* :ref:`varnishhist(1)` +* :ref:`varnishlog(1)` +* :ref:`varnishncsa(1)` +* :ref:`varnishstat(1)` +* :ref:`varnishtop(1)` +* :ref:`vcl(7)` HISTORY ======= diff --git a/doc/sphinx/reference/varnishtop.rst b/doc/sphinx/reference/varnishtop.rst index 9efce5b..2729966 100644 --- a/doc/sphinx/reference/varnishtop.rst +++ b/doc/sphinx/reference/varnishtop.rst @@ -1,4 +1,6 @@ -.. _ref-varnishtop: +.. role:: ref(emphasis) + +.. _varnishtop(1): ========== varnishtop @@ -19,7 +21,7 @@ varnishtop |synopsis| DESCRIPTION =========== -The varnishtop utility reads ``varnishd(1)`` shared memory logs and +The varnishtop utility reads :ref:`varnishd(1)` shared memory logs and presents a continuously updated list of the most commonly occurring log entries. With suitable filtering using the ``-I``, ``-i``, ``-X`` and ``-x`` options, it can be used to display a ranking of requested @@ -46,11 +48,11 @@ commonly used user agents:: SEE ALSO ======== -* varnishd(1) -* varnishhist(1) -* varnishlog(1) -* varnishncsa(1) -* varnishstat(1) +* :ref:`varnishd(1)` +* :ref:`varnishhist(1)` +* :ref:`varnishlog(1)` +* :ref:`varnishncsa(1)` +* :ref:`varnishstat(1)` HISTORY ======= diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst index 7c5b57b..88ac1fe 100644 --- a/doc/sphinx/reference/vcl.rst +++ b/doc/sphinx/reference/vcl.rst @@ -1,4 +1,6 @@ -.. _reference-vcl: +.. role:: ref(emphasis) + +.. _vcl(7): === VCL @@ -220,7 +222,7 @@ are available: Timeout between bytes. probe - Attach a probe to the backend. See Probes. + Attach a probe to the backend. See `Probes`_ max_connections Maximum number of open connections towards this backend. If @@ -228,7 +230,7 @@ are available: connections. Backends can be used with *directors*. Please see the -vmod_directors(3) man page for more information. +:ref:`vmod_directors(3)` man page for more information. .. _reference-vcl_probes: @@ -418,9 +420,9 @@ For examples, please see the online documentation. SEE ALSO ======== -* varnishd(1) -* vmod_directors(3) -* vmod_std(3) +* :ref:`varnishd(1)` +* :ref:`vmod_directors(3)` +* :ref:`vmod_std(3)` HISTORY ======= diff --git a/doc/sphinx/reference/vsl-query.rst b/doc/sphinx/reference/vsl-query.rst index 3315dd6..244a284 100644 --- a/doc/sphinx/reference/vsl-query.rst +++ b/doc/sphinx/reference/vsl-query.rst @@ -1,4 +1,6 @@ -.. _ref-vsl-query: +.. role:: ref(emphasis) + +.. _vsl-query(7): ========= vsl-query diff --git a/doc/sphinx/reference/vsl.rst b/doc/sphinx/reference/vsl.rst index af8ff14..f90571e 100644 --- a/doc/sphinx/reference/vsl.rst +++ b/doc/sphinx/reference/vsl.rst @@ -1,4 +1,6 @@ -.. _reference-vsl: +.. role:: ref(emphasis) + +.. _vsl(7): === VSL @@ -109,7 +111,8 @@ Martin Blix Grydeland. SEE ALSO ======== -* varnishlog(1) -* varnishhist(1) -* varnishncsa(1) -* varnishtop(1) + +* :ref:`varnishlog(1)` +* :ref:`varnishhist(1)` +* :ref:`varnishncsa(1)` +* :ref:`varnishtop(1)` diff --git a/doc/sphinx/tutorial/peculiarities.rst b/doc/sphinx/tutorial/peculiarities.rst index 085edfd..ca95e63 100644 --- a/doc/sphinx/tutorial/peculiarities.rst +++ b/doc/sphinx/tutorial/peculiarities.rst @@ -23,8 +23,8 @@ varnishadm ~~~~~~~~~~ Varnish Cache has an admin console. You can connect it it through the -``varnishadm`` command. In order to connect the user needs to be able to -read `/etc/varnish/secret` in order to authenticate. +:ref:`varnishadm(1)` command. In order to connect the user needs to be +able to read `/etc/varnish/secret` in order to authenticate. Once you've started the console you can do quite a few operations on Varnish, like stopping and starting the cache process, load VCL, @@ -39,11 +39,7 @@ varnishlog ~~~~~~~~~~ Varnish does not log to disk. Instead it logs to a chunk of memory. It -is actually streaming the logs. At any time you'll be able to connect to the -stream and see what is going on. Varnish logs quite a bit of +is actually streaming the logs. At any time you'll be able to connect +to the stream and see what is going on. Varnish logs quite a bit of information. You can have a look at the logstream with the command -``varnishlog``. - - - - +:ref:`varnishlog(1)`. diff --git a/doc/sphinx/users-guide/increasing-your-hitrate.rst b/doc/sphinx/users-guide/increasing-your-hitrate.rst index d55b50c..fe9219c 100644 --- a/doc/sphinx/users-guide/increasing-your-hitrate.rst +++ b/doc/sphinx/users-guide/increasing-your-hitrate.rst @@ -16,9 +16,10 @@ you should find useful to understand what is happening in your Varnish setup. Note that you need a tool to see the HTTP headers that fly between -Varnish and the backend. On the Varnish server, the easiest way to -do this is to use `varnishlog` and `varnishtop` but sometimes a -client-side tool makes sense. Here are the ones we commonly use. +Varnish and the backend. On the Varnish server, the easiest way to do +this is to use :ref:`varnishlog(1)` and :ref:`varnishtop(1)` but +sometimes a client-side tool makes sense. Here are the ones we +commonly use. Tool: varnishtop ~~~~~~~~~~~~~~~~ @@ -26,19 +27,19 @@ Tool: varnishtop You can use varnishtop to identify what URLs are hitting the backend the most. ``varnishtop -i BereqURL`` is an essential command, showing you the top requests Varnish is sending to the backend. You can see some -other examples of `varnishtop` usage in :ref:`users-guide-statistics`. +other examples of :ref:`varnishtop(1)` usage in :ref:`users-guide-statistics`. Tool: varnishlog ~~~~~~~~~~~~~~~~ When you have identified an URL which is frequently sent to the -backend you can use `varnishlog` to have a look at the request. -``varnishlog -q 'ReqURL ~ "^/foo/bar"'`` will show you the requests -coming from the client matching `/foo/bar`. +backend you can use :ref:`varnishlog(1)` to have a look at the +request. ``varnishlog -q 'ReqURL ~ "^/foo/bar"'`` will show you the +requests coming from the client matching `/foo/bar`. -For more information on how `varnishlog` works please see -:ref:`users-guide-logging` or man :ref:`ref-varnishlog`. +For more information on how :ref:`varnishlog(1)` works please see +:ref:`users-guide-logging` or then man page. For extended diagnostics headers, see https://www.varnish-cache.org/trac/wiki/VCLExampleHitMissHeader @@ -240,8 +241,8 @@ Age ~~~ Varnish adds an 'Age' header to indicate how long the object has been -kept inside Varnish. You can grep out 'Age' from `varnishlog` with -``varnishlog -I RespHeader:^Age``. +kept inside Varnish. You can grep out 'Age' from :ref:`varnishlog(1)` +with ``varnishlog -I RespHeader:^Age``. Pragma ~~~~~~ diff --git a/doc/sphinx/users-guide/operation-logging.rst b/doc/sphinx/users-guide/operation-logging.rst index d3e715c..fdbcf58 100644 --- a/doc/sphinx/users-guide/operation-logging.rst +++ b/doc/sphinx/users-guide/operation-logging.rst @@ -74,4 +74,4 @@ want to know are: .. XXX:Maybe a couple of sample commands here? benc -For more information on this topic please see :ref:`ref-varnishlog`. +For more information on this topic please see :ref:`varnishlog(1)`. diff --git a/doc/sphinx/users-guide/operation-statistics.rst b/doc/sphinx/users-guide/operation-statistics.rst index de25bd8..7a4827d 100644 --- a/doc/sphinx/users-guide/operation-statistics.rst +++ b/doc/sphinx/users-guide/operation-statistics.rst @@ -11,7 +11,7 @@ Varnish comes with a couple of nifty and very useful statistics generating tools varnishtop ~~~~~~~~~~ -The `varnishtop` utility reads the shared memory logs and presents a +The :ref:`varnishtop(1)` utility reads the shared memory logs and presents a continuously updated list of the most commonly occurring log entries. With suitable filtering using the -I, -i, -X and -x options, it can be @@ -23,34 +23,27 @@ the client. ``varnishtop -i BereqURL`` will show you what your backend is being asked the most. ``varnishtop -I ReqHeader:Accept-Encoding`` will show the most popular Accept-Encoding header the client are sending you. -For more information please see :ref:`ref-varnishtop`. - varnishhist ~~~~~~~~~~~ -The `varnishhist` utility reads `varnishd(1)` shared memory logs and -presents a continuously updated histogram showing the distribution of -the last N requests by their processing. +The :ref:`varnishhist(1)` utility reads :ref:`varnishd(1)` shared +memory logs and presents a continuously updated histogram showing the +distribution of the last N requests by their processing. .. XXX:1? benc The value of N and the vertical scale are displayed in the top left corner. The horizontal scale is logarithmic. Hits are marked with a pipe character ("|"), and misses are marked with a hash character ("#"). -For more information please see :ref:`ref-varnishhist`. - - varnishstat ~~~~~~~~~~~ Varnish has lots of counters. We count misses, hits, information about the storage, threads created, deleted objects. Just about -everything. `varnishstat` will dump these counters. This is useful when +everything. :ref:`varnishstat(1)` will dump these counters. This is useful when tuning Varnish. -There are programs that can poll `varnishstat` regularly and make nice -graphs of these counters. One such program is Munin. Munin can be -found at http://munin-monitoring.org/ . There is a plugin for munin in -the Varnish source code. - -For more information please see :ref:`ref-varnishstat`. +There are programs that can poll :ref:`varnishstat(1)` regularly and +make nice graphs of these counters. One such program is Munin. Munin +can be found at http://munin-monitoring.org/ . There is a plugin for +munin in the Varnish source code. diff --git a/doc/sphinx/users-guide/sizing-your-cache.rst b/doc/sphinx/users-guide/sizing-your-cache.rst index 90621f8..85023a6 100644 --- a/doc/sphinx/users-guide/sizing-your-cache.rst +++ b/doc/sphinx/users-guide/sizing-your-cache.rst @@ -13,10 +13,10 @@ Deciding on cache size can be a tricky task. A few things to consider: they are cheap to serve from the backend and you have a limited amount of memory. - * Watch the `n_lru_nuked` counter with :ref:`ref-varnishstat` or - some other tool. If you have a lot of LRU activity then your cache - is evicting objects due to space constraints and you should - consider increasing the size of the cache. + * Watch the `n_lru_nuked` counter with :ref:`varnishstat(1)` or some + other tool. If you have a lot of LRU activity then your cache is + evicting objects due to space constraints and you should consider + increasing the size of the cache. Be aware that every object that is stored also carries overhead that is kept outside the actually storage area. So, even if you specify ``-s diff --git a/doc/sphinx/users-guide/troubleshooting.rst b/doc/sphinx/users-guide/troubleshooting.rst index 4be7543..1b8d7a1 100644 --- a/doc/sphinx/users-guide/troubleshooting.rst +++ b/doc/sphinx/users-guide/troubleshooting.rst @@ -3,11 +3,13 @@ Troubleshooting Varnish ======================= -Sometimes Varnish misbehaves or rather behaves the way you told it to behave but not necessarily the way you want it to behave. In order for you to understand whats -going on there are a couple of places you can check. `varnishlog`, -`/var/log/syslog`, `/var/log/messages` are all good places where Varnish might -leave clues of whats going on. This section will guide you through -basic troubleshooting in Varnish. +Sometimes Varnish misbehaves or rather behaves the way you told it to +behave but not necessarily the way you want it to behave. In order for +you to understand whats going on there are a couple of places you can +check. :ref:`varnishlog(1)`, `/var/log/syslog`, `/var/log/messages` +are all good places where Varnish might leave clues of whats going +on. This section will guide you through basic troubleshooting in +Varnish. When Varnish won't start @@ -101,26 +103,26 @@ to get a stack trace of the thread that caused the segfault. Varnish gives me Guru meditation -------------------------------- -First find the relevant log entries in `varnishlog`. That will probably -give you a clue. Since `varnishlog` logs a lot of data it might be hard -to track the entries down. You can set `varnishlog` to log all your 503 -errors by issuing the following command:: +First find the relevant log entries in :ref:`varnishlog(1)`. That will +probably give you a clue. Since :ref:`varnishlog(1)` logs a lot of +data it might be hard to track the entries down. You can set +:ref:`varnishlog(1)` to log all your 503 errors by issuing the +following command:: $ varnishlog -q 'RespStatus == 503' -g request -If the error happened just a short time ago the transaction might still -be in the shared memory log segment. To get `varnishlog` to process the -whole shared memory log just add the '-d' parameter:: +If the error happened just a short time ago the transaction might +still be in the shared memory log segment. To get :ref:`varnishlog(1)` +to process the whole shared memory log just add the '-d' parameter:: $ varnishlog -d -q 'RespStatus == 503' -g request -Please see the `vsl-query` and `varnishlog` man pages for elaborations -on further filtering capabilities and explanation of the various -options. +Please see the :ref:`vsl-query(7)` and :ref:`varnishlog(1)` man pages +for elaborations on further filtering capabilities and explanation of +the various options. Varnish doesn't cache --------------------- See :ref:`users-guide-increasing_your_hitrate`. - diff --git a/doc/sphinx/users-guide/vcl-backends.rst b/doc/sphinx/users-guide/vcl-backends.rst index cd4b0d7..9ec1c82 100644 --- a/doc/sphinx/users-guide/vcl-backends.rst +++ b/doc/sphinx/users-guide/vcl-backends.rst @@ -186,7 +186,7 @@ poll will send a GET request to /. If 3 out of the last 5 polls succeeded the backend is considered healthy, otherwise it will be marked as sick. Refer to the :ref:`reference-vcl_probes` section in the -:ref:`reference-vcl` documentation for more information. +:ref:`vcl(7)` documentation for more information. Now we define the 'director':: diff --git a/doc/sphinx/users-guide/vcl-syntax.rst b/doc/sphinx/users-guide/vcl-syntax.rst index bc1a239..f4bc219 100644 --- a/doc/sphinx/users-guide/vcl-syntax.rst +++ b/doc/sphinx/users-guide/vcl-syntax.rst @@ -11,7 +11,7 @@ Note that VCL doesn't contain any loops or jump statements. This section provides an outline of the more important parts of the syntax. For a full documentation of VCL syntax please see -:ref:`reference-vcl` in the reference. +:ref:`vcl(7)` in the reference. Strings ~~~~~~~ @@ -60,10 +60,10 @@ Operators The following operators are available in VCL. See the examples further down for, uhm, examples. -= += Assignment operator. -== +== Comparison. ~ diff --git a/doc/sphinx/whats-new/upgrading.rst b/doc/sphinx/whats-new/upgrading.rst index 0e5b800..c882b29 100644 --- a/doc/sphinx/whats-new/upgrading.rst +++ b/doc/sphinx/whats-new/upgrading.rst @@ -243,7 +243,6 @@ Other changes New log filtering ~~~~~~~~~~~~~~~~~ -The logging framework has a new filtering language, which means -that the -m switch has been replaced with a new -q switch. -See :ref:`ref-vsl-query` for more information about the new -query language. +The logging framework has a new filtering language, which means that +the -m switch has been replaced with a new -q switch. See +:ref:`vsl-query(7)` for more information about the new query language. diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py index 1dd412d..bc4c3c4 100755 --- a/lib/libvcc/vmodtool.py +++ b/lib/libvcc/vmodtool.py @@ -309,7 +309,9 @@ class Vmod(object): self.doc_str.append(l) def doc_dump(self, fo, suf): + fo.write(".. role:: ref(emphasis)\n\n") i = "vmod_" + self.nam + fo.write(".. _" + i + "(" + self.sec + "):\n\n") fo.write("=" * len(i) + "\n") fo.write(i + "\n") fo.write("=" * len(i) + "\n") diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc index 93ef0b7..288a1ed 100644 --- a/lib/libvmod_std/vmod.vcc +++ b/lib/libvmod_std/vmod.vcc @@ -260,8 +260,8 @@ Example SEE ALSO ======== -* vcl(7) -* varnishd(1) +* :ref:`vsl(7)` +* :ref:`varnishd(1)` HISTORY ======= @@ -275,4 +275,3 @@ COPYRIGHT This document is licensed under the same licence as Varnish itself. See LICENCE for details. - From nils.goroll at uplex.de Fri Mar 13 19:02:29 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 20:02:29 +0100 Subject: [master] 6d03976 common jail_gen_e to keep things simple in the solaris jail Message-ID: commit 6d03976921c505e0e910fece2b4e98769ec3d189 Author: Nils Goroll Date: Fri Mar 13 19:47:46 2015 +0100 common jail_gen_e to keep things simple in the solaris jail diff --git a/bin/varnishd/mgt/mgt_jail_solaris.c b/bin/varnishd/mgt/mgt_jail_solaris.c index a603359..1ad6ce7 100644 --- a/bin/varnishd/mgt/mgt_jail_solaris.c +++ b/bin/varnishd/mgt/mgt_jail_solaris.c @@ -225,6 +225,33 @@ * the real thing */ +// XXX @phk can we merge jail_subproc_e and jail_master_e please? + +#define JAILG_SHIFT 16 + +enum jail_gen_e { + JAILG_SUBPROC_VCC = JAIL_SUBPROC_VCC, + JAILG_SUBPROC_CC = JAIL_SUBPROC_CC, + JAILG_SUBPROC_VCLLOAD = JAIL_SUBPROC_VCLLOAD, + JAILG_SUBPROC_WORKER = JAIL_SUBPROC_WORKER, + + JAILG_MASTER_LOW = JAIL_MASTER_LOW << JAILG_SHIFT, + JAILG_MASTER_HIGH = JAIL_MASTER_HIGH << JAILG_SHIFT +}; + +static inline enum jail_gen_e +jail_subproc_gen(enum jail_subproc_e e) +{ + assert(e < (1 << JAILG_SHIFT)); + return (enum jail_gen_e)e; +} + +static inline enum jail_gen_e +jail_master_gen(enum jail_master_e e) +{ + return (enum jail_gen_e)(e << JAILG_SHIFT); +} + static int __match_proto__(jail_init_f) vjs_init(char **args) { @@ -263,22 +290,22 @@ setppriv_check(int a) { #define setppriv_assert(a) assert(setppriv_check(a)) static void -vjs_add_inheritable(priv_set_t *pset, enum jail_subproc_e jse) +vjs_add_inheritable(priv_set_t *pset, enum jail_gen_e jge) { - switch (jse) { - case JAIL_SUBPROC_VCC: + switch (jge) { + case JAILG_SUBPROC_VCC: /* for /etc/resolv.conf and /etc/hosts */ priv_setop_assert(priv_addset(pset, "file_read")); break; - case JAIL_SUBPROC_CC: + case JAILG_SUBPROC_CC: priv_setop_assert(priv_addset(pset, PRIV_PROC_EXEC)); priv_setop_assert(priv_addset(pset, PRIV_PROC_FORK)); priv_setop_assert(priv_addset(pset, "file_read")); priv_setop_assert(priv_addset(pset, "file_write")); break; - case JAIL_SUBPROC_VCLLOAD: + case JAILG_SUBPROC_VCLLOAD: break; - case JAIL_SUBPROC_WORKER: + case JAILG_SUBPROC_WORKER: break; default: INCOMPL(); @@ -291,17 +318,17 @@ vjs_add_inheritable(priv_set_t *pset, enum jail_subproc_e jse) */ static void -vjs_add_effective(priv_set_t *pset, enum jail_subproc_e jse) +vjs_add_effective(priv_set_t *pset, enum jail_gen_e jge) { - switch (jse) { - case JAIL_SUBPROC_VCC: + switch (jge) { + case JAILG_SUBPROC_VCC: priv_setop_assert(priv_addset(pset, "file_write")); break; - case JAIL_SUBPROC_CC: + case JAILG_SUBPROC_CC: break; - case JAIL_SUBPROC_VCLLOAD: + case JAILG_SUBPROC_VCLLOAD: priv_setop_assert(priv_addset(pset, "file_read")); - case JAIL_SUBPROC_WORKER: + case JAILG_SUBPROC_WORKER: priv_setop_assert(priv_addset(pset, "net_access")); priv_setop_assert(priv_addset(pset, "file_read")); priv_setop_assert(priv_addset(pset, "file_write")); @@ -317,14 +344,14 @@ vjs_add_effective(priv_set_t *pset, enum jail_subproc_e jse) */ static void -vjs_add_permitted(priv_set_t *pset, enum jail_subproc_e jse) +vjs_add_permitted(priv_set_t *pset, enum jail_gen_e jge) { - switch (jse) { - case JAIL_SUBPROC_VCC: - case JAIL_SUBPROC_CC: - case JAIL_SUBPROC_VCLLOAD: + switch (jge) { + case JAILG_SUBPROC_VCC: + case JAILG_SUBPROC_CC: + case JAILG_SUBPROC_VCLLOAD: break; - case JAIL_SUBPROC_WORKER: + case JAILG_SUBPROC_WORKER: /* for raising limits in cache_waiter_ports.c */ AZ(priv_addset(pset, PRIV_SYS_RESOURCE)); break; @@ -338,9 +365,9 @@ vjs_add_permitted(priv_set_t *pset, enum jail_subproc_e jse) * will get waived in vjs_waive */ static void -vjs_add_initial(priv_set_t *pset, enum jail_subproc_e jse) +vjs_add_initial(priv_set_t *pset, enum jail_gen_e jge) { - (void)jse; + (void)jge; /* for setgid/setuid */ AZ(priv_addset(pset, PRIV_PROC_SETID)); @@ -356,7 +383,7 @@ vjs_add_initial(priv_set_t *pset, enum jail_subproc_e jse) */ static void -vjs_setup(enum jail_subproc_e jse) +vjs_setup(enum jail_gen_e jge) { priv_set_t *priv_all; @@ -370,10 +397,10 @@ vjs_setup(enum jail_subproc_e jse) priv_emptyset(priv_all); - vjs_add_inheritable(priv_all, jse); - vjs_add_effective(priv_all, jse); - vjs_add_permitted(priv_all, jse); - vjs_add_initial(priv_all, jse); + vjs_add_inheritable(priv_all, jge); + vjs_add_effective(priv_all, jge); + vjs_add_permitted(priv_all, jge); + vjs_add_initial(priv_all, jge); /* try to get all possible privileges, expect EPERM here */ setppriv_assert(setppriv(PRIV_ON, PRIV_PERMITTED, priv_all)); @@ -384,9 +411,9 @@ vjs_setup(enum jail_subproc_e jse) } static void -vjs_privsep(enum jail_subproc_e jse) +vjs_privsep(enum jail_gen_e jge) { - (void)jse; + (void)jge; if (priv_ineffect(PRIV_PROC_SETID)) { if (getgid() != mgt_param.gid) @@ -417,7 +444,7 @@ vjs_privsep(enum jail_subproc_e jse) */ static void -vjs_waive(enum jail_subproc_e jse) +vjs_waive(enum jail_gen_e jge) { priv_set_t *effective, *inheritable, *permitted; @@ -437,13 +464,13 @@ vjs_waive(enum jail_subproc_e jse) */ priv_emptyset(inheritable); - vjs_add_inheritable(inheritable, jse); + vjs_add_inheritable(inheritable, jge); priv_copyset(inheritable, effective); - vjs_add_effective(effective, jse); + vjs_add_effective(effective, jge); priv_copyset(effective, permitted); - vjs_add_permitted(permitted, jse); + vjs_add_permitted(permitted, jge); /* * invert the sets and clear privileges such that setppriv will always @@ -466,16 +493,23 @@ vjs_waive(enum jail_subproc_e jse) static void __match_proto__(jail_subproc_f) vjs_subproc(enum jail_subproc_e jse) { - vjs_setup(jse); - vjs_privsep(jse); - vjs_waive(jse); + enum jail_gen_e jge = jail_subproc_gen(jse); + vjs_setup(jge); + vjs_privsep(jge); + vjs_waive(jge); } -// XXX TODO static void __match_proto__(jail_master_f) vjs_master(enum jail_master_e jme) { - (void)jme; + enum jail_gen_e jge = jail_master_gen(jme); + (void)jge; +/* + if (jme == JAILG_MASTER_HIGH) + AZ(seteuid(0)); + else + AZ(seteuid(vju_uid)); +*/ } const struct jail_tech jail_tech_solaris = { @@ -483,6 +517,8 @@ const struct jail_tech jail_tech_solaris = { .name = "solaris", .init = vjs_init, .master = vjs_master, +// .make_workdir = vjs_make_workdir, +// .storage_file = vjs_storage_file, .subproc = vjs_subproc, }; From nils.goroll at uplex.de Fri Mar 13 19:02:29 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 20:02:29 +0100 Subject: [master] fac01a5 differenciate JAIL_MASTER_HIGH into _PRIVPORT and _STORAGE Message-ID: commit fac01a55b7123c963bc8e4f9f048244d309ebc3d Author: Nils Goroll Date: Fri Mar 13 20:01:56 2015 +0100 differenciate JAIL_MASTER_HIGH into _PRIVPORT and _STORAGE diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 8428b55..94eaef9 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -73,7 +73,8 @@ enum jail_subproc_e { enum jail_master_e { JAIL_MASTER_LOW, - JAIL_MASTER_HIGH, + JAIL_MASTER_STORAGE, + JAIL_MASTER_PRIVPORT, }; typedef int jail_init_f(char **); diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index dba338e..3d3908a 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -62,7 +62,7 @@ MAC_open_sockets(void) struct listen_sock *ls; int good = 0; - VJ_master(JAIL_MASTER_HIGH); + VJ_master(JAIL_MASTER_PRIVPORT); VTAILQ_FOREACH(ls, &heritage.socks, list) { if (ls->sock >= 0) { good++; diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index 7f754e1..7c395a6 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -522,7 +522,7 @@ mct_callback(void *priv, const struct suckaddr *sa) char pbuf[VTCP_PORTBUFSIZE]; struct telnet *tn; - VJ_master(JAIL_MASTER_HIGH); + VJ_master(JAIL_MASTER_PRIVPORT); sock = VTCP_listen(sa, 10, &err); VJ_master(JAIL_MASTER_LOW); assert(sock != 0); // We know where stdin is diff --git a/bin/varnishd/mgt/mgt_jail_solaris.c b/bin/varnishd/mgt/mgt_jail_solaris.c index 1ad6ce7..d213356 100644 --- a/bin/varnishd/mgt/mgt_jail_solaris.c +++ b/bin/varnishd/mgt/mgt_jail_solaris.c @@ -236,7 +236,8 @@ enum jail_gen_e { JAILG_SUBPROC_WORKER = JAIL_SUBPROC_WORKER, JAILG_MASTER_LOW = JAIL_MASTER_LOW << JAILG_SHIFT, - JAILG_MASTER_HIGH = JAIL_MASTER_HIGH << JAILG_SHIFT + JAILG_MASTER_STORAGE = JAIL_MASTER_STORAGE << JAILG_SHIFT + JAILG_MASTER_PRIVPORT = JAIL_MASTER_PRIVPORT << JAILG_SHIFT }; static inline enum jail_gen_e diff --git a/bin/varnishd/mgt/mgt_jail_unix.c b/bin/varnishd/mgt/mgt_jail_unix.c index 09d14f6..f54c4c0 100644 --- a/bin/varnishd/mgt/mgt_jail_unix.c +++ b/bin/varnishd/mgt/mgt_jail_unix.c @@ -138,7 +138,8 @@ vju_init(char **args) static void __match_proto__(jail_master_f) vju_master(enum jail_master_e jme) { - if (jme == JAIL_MASTER_HIGH) + if (jme == JAIL_MASTER_STORAGE || + jme == JAIL_MASTER_PRIVPORT) AZ(seteuid(0)); else AZ(seteuid(vju_uid)); @@ -209,7 +210,7 @@ vju_make_workdir(const char *dname) static void vju_storage_file(int fd) { - /* Called under JAIL_MASTER_HIGH */ + /* Called under JAIL_MASTER_STORAGE */ AZ(fchmod(fd, 0600)); AZ(fchown(fd, vju_uid, vju_gid)); diff --git a/bin/varnishd/storage/stevedore_utils.c b/bin/varnishd/storage/stevedore_utils.c index 5d29080..96e24cc 100644 --- a/bin/varnishd/storage/stevedore_utils.c +++ b/bin/varnishd/storage/stevedore_utils.c @@ -91,7 +91,7 @@ STV_GetFile(const char *fn, int *fdp, const char **fnp, const char *ctx) *fdp = -1; /* try to create a new file of this name */ - VJ_master(JAIL_MASTER_HIGH); + VJ_master(JAIL_MASTER_STORAGE); fd = open(fn, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE, 0600); if (fd >= 0) { VJ_storage_file(fd); From nils.goroll at uplex.de Fri Mar 13 19:30:56 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Fri, 13 Mar 2015 20:30:56 +0100 Subject: [master] 38dc438 missing comma Message-ID: commit 38dc438ae77a541b661eca4a61434ed2fbb1427d Author: Nils Goroll Date: Fri Mar 13 20:30:28 2015 +0100 missing comma diff --git a/bin/varnishd/mgt/mgt_jail_solaris.c b/bin/varnishd/mgt/mgt_jail_solaris.c index d213356..7d618aa 100644 --- a/bin/varnishd/mgt/mgt_jail_solaris.c +++ b/bin/varnishd/mgt/mgt_jail_solaris.c @@ -236,7 +236,7 @@ enum jail_gen_e { JAILG_SUBPROC_WORKER = JAIL_SUBPROC_WORKER, JAILG_MASTER_LOW = JAIL_MASTER_LOW << JAILG_SHIFT, - JAILG_MASTER_STORAGE = JAIL_MASTER_STORAGE << JAILG_SHIFT + JAILG_MASTER_STORAGE = JAIL_MASTER_STORAGE << JAILG_SHIFT, JAILG_MASTER_PRIVPORT = JAIL_MASTER_PRIVPORT << JAILG_SHIFT }; From phk at FreeBSD.org Mon Mar 16 08:14:25 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 09:14:25 +0100 Subject: [master] f10b6de Get this testcase running with the correct suffix. Message-ID: commit f10b6deca8852aecaf28ffbf7d11e76a39bba40f Author: Poul-Henning Kamp Date: Mon Mar 16 08:14:05 2015 +0000 Get this testcase running with the correct suffix. diff --git a/bin/varnishtest/tests/v00043.vcl b/bin/varnishtest/tests/v00043.vcl deleted file mode 100644 index 6e38fe9..0000000 --- a/bin/varnishtest/tests/v00043.vcl +++ /dev/null @@ -1,56 +0,0 @@ -varnishtest "vcl.state coverage tests" - -server s1 -repeat 20 { - rxreq - txresp - delay .2 - close -} -start - -varnish v1 -vcl { - backend default { - .host = "${s1_addr}"; - .probe = { .interval = 1s; .initial = 1;} - } -} -start - -varnish v1 -cliok "param.set vcl_cooldown 3" - -# We only have one vcl yet -varnish v1 -expect VBE.vcl1.default.happy > 0 -varnish v1 -expect !VBE.vcl2.default.happy -varnish v1 -cliok "backend.list -p *.*" - -varnish v1 -vcl { - backend default { - .host = "${s1_addr}"; - .probe = { .interval = 1s; .initial = 1;} - } -} - -# Now we have two vcls (and run on the latest loaded) -varnish v1 -expect VBE.vcl1.default.happy > 0 -varnish v1 -expect VBE.vcl2.default.happy > 0 - -# Freeze the first VCL -varnish v1 -cliok "vcl.state vcl1 cold" -varnish v1 -expect !VBE.vcl1.default.happy - -# Set it auto should be a no-op -varnish v1 -cliok "vcl.state vcl1 auto" -varnish v1 -expect !VBE.vcl1.default.happy - -# Use it, and it should come alive -varnish v1 -cliok "vcl.use vcl1" -varnish v1 -expect VBE.vcl1.default.happy > 0 -varnish v1 -expect VBE.vcl2.default.happy > 0 - -# and the unused one should go cold -delay 4 -varnish v1 -expect !VBE.vcl2.default.happy - -# Mark the used warm and use it the other -varnish v1 -cliok "vcl.state vcl1 warm" -varnish v1 -cliok "vcl.use vcl2" -delay 4 -varnish v1 -expect VBE.vcl2.default.happy > 0 diff --git a/bin/varnishtest/tests/v00044.vtc b/bin/varnishtest/tests/v00044.vtc new file mode 100644 index 0000000..7907e7e --- /dev/null +++ b/bin/varnishtest/tests/v00044.vtc @@ -0,0 +1,57 @@ +varnishtest "vcl.state coverage tests" + +server s1 -repeat 20 { + rxreq + txresp + delay .2 + close +} -start + +varnish v1 -vcl { + backend default { + .host = "${s1_addr}"; + .probe = { .interval = 1s; .initial = 1;} + } +} -start + +varnish v1 -cliok "param.set vcl_cooldown 3" + +# We only have one vcl yet +varnish v1 -expect VBE.vcl1.default.happy > 0 +varnish v1 -expect !VBE.vcl2.default.happy +varnish v1 -cliok "backend.list -p *.*" + +varnish v1 -vcl { + backend default { + .host = "${s1_addr}"; + .probe = { .interval = 1s; .initial = 1;} + } +} + +# Now we have two vcls (and run on the latest loaded) +varnish v1 -expect VBE.vcl1.default.happy > 0 +varnish v1 -expect VBE.vcl2.default.happy > 0 + +# Freeze the first VCL +varnish v1 -cliok "vcl.state vcl1 cold" +varnish v1 -expect !VBE.vcl1.default.happy + +# Set it auto should be a no-op +varnish v1 -cliok "vcl.state vcl1 auto" +varnish v1 -expect !VBE.vcl1.default.happy + +# Use it, and it should come alive +varnish v1 -cliok "vcl.use vcl1" +delay .4 +varnish v1 -expect VBE.vcl1.default.happy >= 0 +varnish v1 -expect VBE.vcl2.default.happy > 0 + +# and the unused one should go cold +delay 4 +varnish v1 -expect !VBE.vcl2.default.happy + +# Mark the used warm and use it the other +varnish v1 -cliok "vcl.state vcl1 warm" +varnish v1 -cliok "vcl.use vcl2" +delay 4 +varnish v1 -expect VBE.vcl2.default.happy >= 0 From phk at FreeBSD.org Mon Mar 16 08:55:34 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 09:55:34 +0100 Subject: [master] 6fb5763 Move the acceptor sockets open/bind test earlier. Message-ID: commit 6fb576391905f49a89402f26c5f446e532b46632 Author: Poul-Henning Kamp Date: Mon Mar 16 08:41:28 2015 +0000 Move the acceptor sockets open/bind test earlier. diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 4ebc6b3..325b88d 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -619,6 +619,10 @@ main(int argc, char * const *argv) ARGV_ERR("Could not open pid/lock (-P) file (%s): %s\n", P_arg, strerror(errno)); + if (MAC_open_sockets()) + ARGV_ERR("Failed to open (any) accept sockets.\n"); + MAC_close_sockets(); + mgt_vcc_init(); mgt_vcl_init(); @@ -635,10 +639,6 @@ main(int argc, char * const *argv) ARGV_ERR("-C only good with -b or -f\n"); if (!d_flag) { - if (MAC_open_sockets()) - ARGV_ERR("Failed to open (any) accept sockets.\n"); - MAC_close_sockets(); - if (b_arg == NULL && f_arg == NULL) { fprintf(stderr, "Warning: Neither -b nor -f given," From phk at FreeBSD.org Mon Mar 16 08:55:34 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 09:55:34 +0100 Subject: [master] 2f2edf0 Make the test fail on the -b argument, if the -a arguments dont. Message-ID: commit 2f2edf0f0963e22d16c827609a81877e33ca3f66 Author: Poul-Henning Kamp Date: Mon Mar 16 08:42:07 2015 +0000 Make the test fail on the -b argument, if the -a arguments dont. diff --git a/bin/varnishtest/tests/c00003.vtc b/bin/varnishtest/tests/c00003.vtc index 12273f7..b1ad7d8 100644 --- a/bin/varnishtest/tests/c00003.vtc +++ b/bin/varnishtest/tests/c00003.vtc @@ -4,7 +4,7 @@ varnishtest "Check that we fail to start if any listen address does not work" # and are on Linux, ensure /proc/net/ipv4/ip_nonlocal_bind is set to 0. # All bad listen addresses -err_shell "Failed to open (any) accept sockets" {${varnishd} -F -a "${bad_ip}:0" -b 127.0.0.1:80 -n ${tmpdir} 2>&1 & pid=$! ; sleep 1 ; kill $pid ; wait } +err_shell "Failed to open (any) accept sockets" {${varnishd} -F -a "${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } # Just one bad listen addresses -# err_shell "Invalid listen address" {${varnishd} -F -a "127.0.0.1:0,${bad_ip}:0" -b 127.0.0.1:80 -n ${tmpdir} 2>&1 & pid=$! ; sleep 1 ; kill $pid ; wait } +# err_shell "Invalid listen address" {${varnishd} -F -a "127.0.0.1:0,${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } From phk at FreeBSD.org Mon Mar 16 08:55:34 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 09:55:34 +0100 Subject: [master] 924f25b Only test acceptor sockets if not -C Message-ID: commit 924f25b189f5c2ff0ff082fd53059adc31418898 Author: Poul-Henning Kamp Date: Mon Mar 16 08:48:10 2015 +0000 Only test acceptor sockets if not -C diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index 325b88d..e4849b3 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -619,9 +619,11 @@ main(int argc, char * const *argv) ARGV_ERR("Could not open pid/lock (-P) file (%s): %s\n", P_arg, strerror(errno)); - if (MAC_open_sockets()) - ARGV_ERR("Failed to open (any) accept sockets.\n"); - MAC_close_sockets(); + if (!C_flag) { + if (MAC_open_sockets()) + ARGV_ERR("Failed to open (any) accept sockets.\n"); + MAC_close_sockets(); + } mgt_vcc_init(); mgt_vcl_init(); From phk at FreeBSD.org Mon Mar 16 08:55:34 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 09:55:34 +0100 Subject: [master] 011d4e2 Change these tests to use err_shell Message-ID: commit 011d4e2ced8536c687d37ef3c8eb9306f8fd6ba5 Author: Poul-Henning Kamp Date: Mon Mar 16 08:55:13 2015 +0000 Change these tests to use err_shell diff --git a/bin/varnishtest/tests/a00009.vtc b/bin/varnishtest/tests/a00009.vtc index e5abeb7..13bd015 100644 --- a/bin/varnishtest/tests/a00009.vtc +++ b/bin/varnishtest/tests/a00009.vtc @@ -3,7 +3,7 @@ varnishtest "Code coverage of VCL compiler and RSTdump etc" shell "${varnishd} -b 127.0.0.1:80 -C -n ${tmpdir} > /dev/null 2>&1" shell "${varnishd} -x dumprstparam > /dev/null 2>&1" shell "${varnishd} -x dumprstvsl > /dev/null 2>&1" -shell "! ${varnishd} -spersistent > /dev/null 2>&1" -shell "! ${varnishd} -jxyz > /dev/null 2>&1" -shell "! ${varnishd} -jnone -jxyz > /dev/null 2>&1" -shell "! ${varnishd} -d -jxyz > /dev/null 2>&1" +err_shell {-spersistent has been deprecated} "${varnishd} -spersistent 2>&1" +err_shell {Unknown jail method "xyz"} "${varnishd} -jxyz 2>&1" +err_shell {-j must be the first argument} "${varnishd} -jnone -jxyz 2>&1" +err_shell {-j must be the first argument} "${varnishd} -d -jxyz 2>&1" From phk at FreeBSD.org Mon Mar 16 09:12:47 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 10:12:47 +0100 Subject: [master] a519549 We only care if the variable exists, not about their value Message-ID: commit a51954903a6b121fea7f95b744fa8e3b45daa772 Author: Poul-Henning Kamp Date: Mon Mar 16 09:12:32 2015 +0000 We only care if the variable exists, not about their value diff --git a/bin/varnishtest/tests/v00044.vtc b/bin/varnishtest/tests/v00044.vtc index 7907e7e..19620a3 100644 --- a/bin/varnishtest/tests/v00044.vtc +++ b/bin/varnishtest/tests/v00044.vtc @@ -17,7 +17,7 @@ varnish v1 -vcl { varnish v1 -cliok "param.set vcl_cooldown 3" # We only have one vcl yet -varnish v1 -expect VBE.vcl1.default.happy > 0 +varnish v1 -expect VBE.vcl1.default.happy >= 0 varnish v1 -expect !VBE.vcl2.default.happy varnish v1 -cliok "backend.list -p *.*" @@ -29,8 +29,8 @@ varnish v1 -vcl { } # Now we have two vcls (and run on the latest loaded) -varnish v1 -expect VBE.vcl1.default.happy > 0 -varnish v1 -expect VBE.vcl2.default.happy > 0 +varnish v1 -expect VBE.vcl1.default.happy >= 0 +varnish v1 -expect VBE.vcl2.default.happy >= 0 # Freeze the first VCL varnish v1 -cliok "vcl.state vcl1 cold" @@ -44,7 +44,7 @@ varnish v1 -expect !VBE.vcl1.default.happy varnish v1 -cliok "vcl.use vcl1" delay .4 varnish v1 -expect VBE.vcl1.default.happy >= 0 -varnish v1 -expect VBE.vcl2.default.happy > 0 +varnish v1 -expect VBE.vcl2.default.happy >= 0 # and the unused one should go cold delay 4 From phk at FreeBSD.org Mon Mar 16 09:37:37 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 10:37:37 +0100 Subject: [master] b804d84 Try harder to stabilize this test Message-ID: commit b804d84e0e46a72a0aed90df4c93e38f4da8e776 Author: Poul-Henning Kamp Date: Mon Mar 16 09:37:24 2015 +0000 Try harder to stabilize this test diff --git a/bin/varnishtest/tests/v00044.vtc b/bin/varnishtest/tests/v00044.vtc index 19620a3..59c4c33 100644 --- a/bin/varnishtest/tests/v00044.vtc +++ b/bin/varnishtest/tests/v00044.vtc @@ -29,15 +29,18 @@ varnish v1 -vcl { } # Now we have two vcls (and run on the latest loaded) +delay .4 varnish v1 -expect VBE.vcl1.default.happy >= 0 varnish v1 -expect VBE.vcl2.default.happy >= 0 # Freeze the first VCL varnish v1 -cliok "vcl.state vcl1 cold" +delay .4 varnish v1 -expect !VBE.vcl1.default.happy # Set it auto should be a no-op varnish v1 -cliok "vcl.state vcl1 auto" +delay .4 varnish v1 -expect !VBE.vcl1.default.happy # Use it, and it should come alive From phk at FreeBSD.org Mon Mar 16 09:51:27 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 10:51:27 +0100 Subject: [master] 4defdfc Retire "listen_address" as a parameter you can set from CLI. Message-ID: commit 4defdfc18801d34e253b0a0d61511d037261689e Author: Poul-Henning Kamp Date: Mon Mar 16 09:51:02 2015 +0000 Retire "listen_address" as a parameter you can set from CLI. diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h index f5f9450..4c9c3ed 100644 --- a/bin/varnishd/common/params.h +++ b/bin/varnishd/common/params.h @@ -131,9 +131,6 @@ struct params { unsigned accept_filter; - /* Listen address */ - char *listen_address; - /* Listen depth */ unsigned listen_depth; diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 94eaef9..25737c2 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -39,6 +39,10 @@ extern struct vev_base *mgt_evb; extern unsigned d_flag; extern int exit_status; +/* mgt_acceptor.c */ + +void MAC_Arg(const char *); + /* mgt_child.c */ extern pid_t child_pid; void MGT_Run(void); diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index 3d3908a..ac1000d 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -41,9 +41,7 @@ #include #include "mgt/mgt.h" -#include "mgt/mgt_param.h" #include "common/heritage.h" -#include "common/params.h" #include "vav.h" #include "vsa.h" @@ -100,94 +98,67 @@ MAC_close_sockets(void) /*--------------------------------------------------------------------*/ -static void -clean_listen_sock_head(struct listen_sock_head *lsh) -{ - struct listen_sock *ls, *ls2; - - VTAILQ_FOREACH_SAFE(ls, lsh, list, ls2) { - CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC); - VTAILQ_REMOVE(lsh, ls, list); - free(ls->name); - free(ls->addr); - FREE_OBJ(ls); - } -} - -static struct listen_sock_head lsh; +struct mac_help { + unsigned magic; +#define MAC_HELP_MAGIC 0x1e00a9d9 + const char *name; + int good; + const char **err; +}; static int __match_proto__(vss_resolver_f) -tla_callback(void *priv, const struct suckaddr *sa) +mac_callback(void *priv, const struct suckaddr *sa) { + struct mac_help *mh; struct listen_sock *ls; + int sock; + + CAST_OBJ_NOTNULL(mh, priv, MAC_HELP_MAGIC); + sock = VTCP_bind(sa, NULL); + if (sock < 0) { + *(mh->err) = strerror(errno); + return (0); + } ALLOC_OBJ(ls, LISTEN_SOCK_MAGIC); AN(ls); - ls->sock = -1; - ls->addr = VSA_Clone(sa); + if (VSA_Port(sa) == 0) + ls->addr = VTCP_my_suckaddr(sock); + else + ls->addr = VSA_Clone(sa); AN(ls->addr); + AZ(close(sock)); + ls->sock = -1; ls->name = strdup(priv); AN(ls->name); - VTAILQ_INSERT_TAIL(&lsh, ls, list); + VTAILQ_INSERT_TAIL(&heritage.socks, ls, list); + mh->good++; return (0); } -int -tweak_listen_address(struct vsb *vsb, const struct parspec *par, - const char *arg) +void +MAC_Arg(const char *arg) { char **av; - int i, error; + struct mac_help *mh; const char *err; - struct listen_sock *ls; - - (void)par; - if (arg == NULL) { - VSB_quote(vsb, mgt_param.listen_address, -1, 0); - return (0); - } + int error; av = VAV_Parse(arg, NULL, ARGV_COMMA); - if (av == NULL) { - VSB_printf(vsb, "Parse error: out of memory"); - return(-1); - } - if (av[0] != NULL) { - VSB_printf(vsb, "Parse error: %s", av[0]); - VAV_Free(av); - return(-1); - } - if (av[1] == NULL) { - VSB_printf(vsb, "Empty listen address"); - VAV_Free(av); - return(-1); - } - VTAILQ_INIT(&lsh); - for (i = 1; av[i] != NULL; i++) { - error = VSS_resolver(av[i], "80", tla_callback, av[i], &err); - if (err != NULL) { - VSB_printf(vsb, "Invalid listen address "); - VSB_quote(vsb, av[i], -1, 0); - VSB_printf(vsb, ": %s", err); - VAV_Free(av); - clean_listen_sock_head(&lsh); - return (-1); - } - AZ(error); - } - VAV_Free(av); - - REPLACE(mgt_param.listen_address, arg); - - clean_listen_sock_head(&heritage.socks); - heritage.nsocks = 0; - - while (!VTAILQ_EMPTY(&lsh)) { - ls = VTAILQ_FIRST(&lsh); - VTAILQ_REMOVE(&lsh, ls, list); - CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC); - VTAILQ_INSERT_TAIL(&heritage.socks, ls, list); - heritage.nsocks++; - } - return (0); + if (av == NULL) + ARGV_ERR("Parse error: out of memory\n"); + if (av[0] != NULL) + ARGV_ERR("%s\n", av[0]); + if (av[2] != NULL) + ARGV_ERR("XXX: not yet\n"); + + ALLOC_OBJ(mh, MAC_HELP_MAGIC); + AN(mh); + mh->name = av[1]; + mh->err = &err; + error = VSS_resolver(av[1], "80", mac_callback, mh, &err); + if (mh->good == 0 || err != NULL) + ARGV_ERR("Could not open %s: %s\n", av[1], err); + AZ(error); + FREE_OBJ(mh); } diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index e4849b3..f6b34d2 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -457,8 +457,7 @@ main(int argc, char * const *argv) switch (o) { case 'a': - MCF_ParamSet(cli, "listen_address", optarg); - cli_check(cli); + MAC_Arg(optarg); break; case 'b': b_arg = optarg; @@ -619,12 +618,6 @@ main(int argc, char * const *argv) ARGV_ERR("Could not open pid/lock (-P) file (%s): %s\n", P_arg, strerror(errno)); - if (!C_flag) { - if (MAC_open_sockets()) - ARGV_ERR("Failed to open (any) accept sockets.\n"); - MAC_close_sockets(); - } - mgt_vcc_init(); mgt_vcl_init(); diff --git a/bin/varnishd/mgt/mgt_param.h b/bin/varnishd/mgt/mgt_param.h index 4550b92..58b2dd6 100644 --- a/bin/varnishd/mgt/mgt_param.h +++ b/bin/varnishd/mgt/mgt_param.h @@ -56,7 +56,6 @@ tweak_t tweak_bool; tweak_t tweak_bytes; tweak_t tweak_bytes_u; tweak_t tweak_double; -tweak_t tweak_listen_address; tweak_t tweak_poolparam; tweak_t tweak_string; tweak_t tweak_timeout; diff --git a/bin/varnishd/mgt/mgt_param_tbl.c b/bin/varnishd/mgt/mgt_param_tbl.c index e705a47..51120f6 100644 --- a/bin/varnishd/mgt/mgt_param_tbl.c +++ b/bin/varnishd/mgt/mgt_param_tbl.c @@ -242,13 +242,6 @@ struct parspec mgt_parspec[] = { MUST_RESTART, "on", "bool" }, #endif - { "listen_address", tweak_listen_address, NULL, - NULL, NULL, - "Whitespace separated list of network endpoints where " - "Varnish will accept requests.\n" - "Possible formats: host, host:port, :port", - MUST_RESTART, - ":80" }, { "listen_depth", tweak_uint, &mgt_param.listen_depth, "0", NULL, "Listen queue depth.", diff --git a/bin/varnishtest/tests/c00003.vtc b/bin/varnishtest/tests/c00003.vtc index b1ad7d8..8f31bb6 100644 --- a/bin/varnishtest/tests/c00003.vtc +++ b/bin/varnishtest/tests/c00003.vtc @@ -4,7 +4,7 @@ varnishtest "Check that we fail to start if any listen address does not work" # and are on Linux, ensure /proc/net/ipv4/ip_nonlocal_bind is set to 0. # All bad listen addresses -err_shell "Failed to open (any) accept sockets" {${varnishd} -F -a "${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } +err_shell "Could not open 192.0.2.255:0" {${varnishd} -F -a "${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } # Just one bad listen addresses -# err_shell "Invalid listen address" {${varnishd} -F -a "127.0.0.1:0,${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } +err_shell "Error: XXX: not yet" {${varnishd} -F -a "127.0.0.1:0,${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } diff --git a/bin/varnishtest/tests/v00010.vtc b/bin/varnishtest/tests/v00010.vtc index 30bae3a..2fb3511 100644 --- a/bin/varnishtest/tests/v00010.vtc +++ b/bin/varnishtest/tests/v00010.vtc @@ -39,9 +39,6 @@ varnish v1 -arg "-smalloc,1m" -vcl+backend { varnish v1 -cliok "param.set feature +no_coredump" -# Force the (random) port selected to be used again after restart. -varnish v1 -cliok "param.set listen_address ${v1_addr}:${v1_port}" - client c1 { txreq -url "/" rxresp From phk at FreeBSD.org Mon Mar 16 10:15:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 11:15:35 +0100 Subject: [master] 00ce8fc White space OCD. Message-ID: commit 00ce8fcf165be03514787e9d3e5abf8bd1536459 Author: Poul-Henning Kamp Date: Mon Mar 16 10:14:54 2015 +0000 White space OCD. diff --git a/bin/varnishtest/tests/r01684.vtc b/bin/varnishtest/tests/r01684.vtc index 3e0e422..f4eb71e 100644 --- a/bin/varnishtest/tests/r01684.vtc +++ b/bin/varnishtest/tests/r01684.vtc @@ -1,23 +1,23 @@ varnishtest "Regression test for #1684" server s1 { - rxreq - txresp -hdr "foo: 1" - accept - rxreq - txresp -hdr "foo: 2" - accept - rxreq - txresp -hdr "foo: 3" + rxreq + txresp -hdr "foo: 1" + accept + rxreq + txresp -hdr "foo: 2" + accept + rxreq + txresp -hdr "foo: 3" } -start varnish v1 -vcl+backend { - sub vcl_recv { return (pass); } - sub vcl_backend_response { - set beresp.http.bar = bereq.retries; - if (beresp.http.foo != bereq.http.stop) { - return (retry); - } - } + sub vcl_recv { return (pass); } + sub vcl_backend_response { + set beresp.http.bar = bereq.retries; + if (beresp.http.foo != bereq.http.stop) { + return (retry); + } + } } -start # check log for the aborted POST @@ -31,8 +31,7 @@ varnish v1 -cliok "param.set debug +syncvsl" varnish v1 -cliok "param.set max_retries 2" client c1 { - txreq -hdr "stop: 3" - rxresp - expect resp.http.foo == 3 + txreq -hdr "stop: 3" + rxresp + expect resp.http.foo == 3 } -run - diff --git a/bin/varnishtest/tests/v00044.vtc b/bin/varnishtest/tests/v00044.vtc index 59c4c33..1424689 100644 --- a/bin/varnishtest/tests/v00044.vtc +++ b/bin/varnishtest/tests/v00044.vtc @@ -51,7 +51,7 @@ varnish v1 -expect VBE.vcl2.default.happy >= 0 # and the unused one should go cold delay 4 -varnish v1 -expect !VBE.vcl2.default.happy +varnish v1 -expect !VBE.vcl2.default.happy # Mark the used warm and use it the other varnish v1 -cliok "vcl.state vcl1 warm" From phk at FreeBSD.org Mon Mar 16 10:15:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 11:15:35 +0100 Subject: [master] fde2d23 Make it a failure to not get all acceptor sockets on child start. Message-ID: commit fde2d23125673f7ead9d74abc436b8ee9c907ed9 Author: Poul-Henning Kamp Date: Mon Mar 16 10:15:05 2015 +0000 Make it a failure to not get all acceptor sockets on child start. diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index ac1000d..a49ec16 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include #include @@ -58,26 +58,23 @@ int MAC_open_sockets(void) { struct listen_sock *ls; - int good = 0; + int fail; VJ_master(JAIL_MASTER_PRIVPORT); VTAILQ_FOREACH(ls, &heritage.socks, list) { - if (ls->sock >= 0) { - good++; - continue; - } + assert(ls->sock < 0); ls->sock = VTCP_bind(ls->addr, NULL); if (ls->sock < 0) - continue; - + break; mgt_child_inherit(ls->sock, "sock"); - - good++; } + fail = errno; VJ_master(JAIL_MASTER_LOW); - if (!good) - return (1); - return (0); + if (ls == NULL) + return (0); + MAC_close_sockets(); + errno = fail; + return (-1); } /*--------------------------------------------------------------------*/ @@ -158,7 +155,7 @@ MAC_Arg(const char *arg) mh->err = &err; error = VSS_resolver(av[1], "80", mac_callback, mh, &err); if (mh->good == 0 || err != NULL) - ARGV_ERR("Could not open %s: %s\n", av[1], err); + ARGV_ERR("Could not bind to address %s: %s\n", av[1], err); AZ(error); FREE_OBJ(mh); } diff --git a/bin/varnishtest/tests/c00003.vtc b/bin/varnishtest/tests/c00003.vtc index 8f31bb6..d4ce742 100644 --- a/bin/varnishtest/tests/c00003.vtc +++ b/bin/varnishtest/tests/c00003.vtc @@ -4,7 +4,7 @@ varnishtest "Check that we fail to start if any listen address does not work" # and are on Linux, ensure /proc/net/ipv4/ip_nonlocal_bind is set to 0. # All bad listen addresses -err_shell "Could not open 192.0.2.255:0" {${varnishd} -F -a "${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } +err_shell "Could not bind to address 192.0.2.255:0" {${varnishd} -F -a "${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } # Just one bad listen addresses err_shell "Error: XXX: not yet" {${varnishd} -F -a "127.0.0.1:0,${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } From phk at FreeBSD.org Mon Mar 16 10:42:10 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 11:42:10 +0100 Subject: [master] a75ce8b Remove doc references to parameters which has been removed. Message-ID: commit a75ce8b7b94d93d0c09a9b3472fe9384652080f5 Author: Poul-Henning Kamp Date: Mon Mar 16 10:37:51 2015 +0000 Remove doc references to parameters which has been removed. diff --git a/doc/sphinx/reference/varnishd.rst b/doc/sphinx/reference/varnishd.rst index 90c4344..a9cf7d5 100644 --- a/doc/sphinx/reference/varnishd.rst +++ b/doc/sphinx/reference/varnishd.rst @@ -124,8 +124,7 @@ OPTIONS administrator a way to limit what the Varnish CLI can do. Consider making parameters such as *user*, *group*, *cc_command*, *vcc_allow_inline_c* read only as these can potentially be used to - escalate privileges from the CLI. Protecting *listen_address* may - also be a good idea. + escalate privileges from the CLI. -s <[name=]type[,options]> diff --git a/doc/sphinx/users-guide/run_security.rst b/doc/sphinx/users-guide/run_security.rst index 72f7bda..e34b0a7 100644 --- a/doc/sphinx/users-guide/run_security.rst +++ b/doc/sphinx/users-guide/run_security.rst @@ -156,12 +156,6 @@ interface. Pretty much any parameter can be used to totally mess up your HTTP service, but a few can do more damage than others: -.. XXX :ref:`ref_param_user` and :ref:`ref_param_group` -.. XXX Access to local system via VCL - -:ref:`ref_param_listen_address` - Trojan other TCP sockets, like `ssh` - :ref:`ref_param_cc_command` Execute arbitrary programs From phk at FreeBSD.org Mon Mar 16 10:42:10 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 11:42:10 +0100 Subject: [master] c62cb71 Don't undef the v1 listen socket macros now that Varnishd persists on using the same ones across restarts. Message-ID: commit c62cb719cdce16fc12a97ca361d319d9a2a27c3e Author: Poul-Henning Kamp Date: Mon Mar 16 10:38:49 2015 +0000 Don't undef the v1 listen socket macros now that Varnishd persists on using the same ones across restarts. diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 1b154b3..95086a9 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -557,9 +557,6 @@ varnish_stop(struct varnish *v) varnish_launch(v); if (vtc_error) return; - macro_undef(v->vl, v->name, "addr"); - macro_undef(v->vl, v->name, "port"); - macro_undef(v->vl, v->name, "sock"); vtc_log(v->vl, 2, "Stop"); (void)varnish_ask_cli(v, "stop", NULL); while (1) { From phk at FreeBSD.org Mon Mar 16 10:42:10 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 11:42:10 +0100 Subject: [master] a4a7384 Do not restart if we cannot get all our listen sockets, and add a test-case to cover this case. Message-ID: commit a4a7384e689835ca8c7b64f6f2bb13ce14828192 Author: Poul-Henning Kamp Date: Mon Mar 16 10:41:46 2015 +0000 Do not restart if we cannot get all our listen sockets, and add a test-case to cover this case. diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 25737c2..9c23cd7 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -42,6 +42,8 @@ extern int exit_status; /* mgt_acceptor.c */ void MAC_Arg(const char *); +int MAC_open_sockets(struct cli *); +void MAC_close_sockets(void); /* mgt_child.c */ extern pid_t child_pid; @@ -49,8 +51,6 @@ void MGT_Run(void); void mgt_stop_child(void); void mgt_got_fd(int fd); void MGT_Child_Cli_Fail(void); -int MAC_open_sockets(void); -void MAC_close_sockets(void); /* mgt_cli.c */ diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index a49ec16..faa90ff 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -44,6 +44,7 @@ #include "common/heritage.h" #include "vav.h" +#include "vcli_priv.h" #include "vsa.h" #include "vss.h" #include "vtcp.h" @@ -55,7 +56,7 @@ */ int -MAC_open_sockets(void) +MAC_open_sockets(struct cli *cli) { struct listen_sock *ls; int fail; @@ -73,6 +74,8 @@ MAC_open_sockets(void) if (ls == NULL) return (0); MAC_close_sockets(); + VCLI_Out(cli, "Could not get socket %s: %s\n", + ls->name, strerror(fail)); errno = fail; return (-1); } @@ -109,6 +112,8 @@ mac_callback(void *priv, const struct suckaddr *sa) struct mac_help *mh; struct listen_sock *ls; int sock; + char abuf[VTCP_ADDRBUFSIZE], pbuf[VTCP_PORTBUFSIZE]; + char nbuf[VTCP_ADDRBUFSIZE+VTCP_PORTBUFSIZE+2]; CAST_OBJ_NOTNULL(mh, priv, MAC_HELP_MAGIC); sock = VTCP_bind(sa, NULL); @@ -119,15 +124,23 @@ mac_callback(void *priv, const struct suckaddr *sa) ALLOC_OBJ(ls, LISTEN_SOCK_MAGIC); AN(ls); - if (VSA_Port(sa) == 0) + if (VSA_Port(sa) == 0) { + /* + * If the port number is zero, we adopt whatever port number + * this VTCP_bind() found us, as if specified by argument. + */ ls->addr = VTCP_my_suckaddr(sock); - else + VTCP_myname(sock, abuf, sizeof abuf, pbuf, sizeof pbuf); + bprintf(nbuf, "%s:%s", abuf, pbuf); + ls->name = strdup(nbuf); + } else { ls->addr = VSA_Clone(sa); + ls->name = strdup(mh->name); + } AN(ls->addr); + AN(ls->name); AZ(close(sock)); ls->sock = -1; - ls->name = strdup(priv); - AN(ls->name); VTAILQ_INSERT_TAIL(&heritage.socks, ls, list); mh->good++; return (0); diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index ae9033d..eca8af2 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -303,11 +303,10 @@ mgt_launch_child(struct cli *cli) if (child_state != CH_STOPPED && child_state != CH_DIED) return; - if (MAC_open_sockets() != 0) { + if (MAC_open_sockets(cli) != 0) { child_state = CH_STOPPED; if (cli != NULL) { VCLI_SetResult(cli, CLIS_CANT); - VCLI_Out(cli, "Could not open sockets"); return; } REPORT0(LOG_ERR, diff --git a/bin/varnishtest/tests/c00069.vtc b/bin/varnishtest/tests/c00069.vtc new file mode 100644 index 0000000..76c4b56 --- /dev/null +++ b/bin/varnishtest/tests/c00069.vtc @@ -0,0 +1,21 @@ +varnishtest "Test failure if our listen socket gets stolen" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -arg "-a :0" -vcl+backend {} -start + +client c1 { + txreq + rxresp + expect resp.status == 200 +} -run + +varnish v1 -stop + +# Now have another varnish steal the listen socket +varnish v2 -arg "-a ${v1_addr}:${v1_port}" -vcl+backend {} -start + +varnish v1 -clierr 300 "start" From phk at FreeBSD.org Mon Mar 16 10:47:39 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 11:47:39 +0100 Subject: [master] dc9dd43 Take another stab at stabilizing this test. Message-ID: commit dc9dd430c9816a6034299badc8996aaeb639163f Author: Poul-Henning Kamp Date: Mon Mar 16 10:47:22 2015 +0000 Take another stab at stabilizing this test. diff --git a/bin/varnishtest/tests/v00044.vtc b/bin/varnishtest/tests/v00044.vtc index 1424689..b89b73f 100644 --- a/bin/varnishtest/tests/v00044.vtc +++ b/bin/varnishtest/tests/v00044.vtc @@ -14,7 +14,7 @@ varnish v1 -vcl { } } -start -varnish v1 -cliok "param.set vcl_cooldown 3" +varnish v1 -cliok "param.set vcl_cooldown 1" # We only have one vcl yet varnish v1 -expect VBE.vcl1.default.happy >= 0 @@ -50,7 +50,7 @@ varnish v1 -expect VBE.vcl1.default.happy >= 0 varnish v1 -expect VBE.vcl2.default.happy >= 0 # and the unused one should go cold -delay 4 +delay 3 varnish v1 -expect !VBE.vcl2.default.happy # Mark the used warm and use it the other From phk at FreeBSD.org Mon Mar 16 12:16:07 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 13:16:07 +0100 Subject: [master] b31580e In the vtc_thread vtc_log(0) doesn't terminate, so add a return. Message-ID: commit b31580e848d5424f45db0e2ecc5ad27e5c4bb838 Author: Poul-Henning Kamp Date: Mon Mar 16 11:59:14 2015 +0000 In the vtc_thread vtc_log(0) doesn't terminate, so add a return. diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 95086a9..9f3a305 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -769,6 +769,10 @@ varnish_expect(const struct varnish *v, char * const *av) { if (r[0] == '!') { not = 1; r++; + AZ(av[1]); + } else { + AN(av[1]); + AN(av[2]); } p = strchr(r, '.'); if (p == NULL) { @@ -804,8 +808,10 @@ varnish_expect(const struct varnish *v, char * const *av) { continue; } - if (not) + if (not) { vtc_log(v->vl, 0, "Found (not expected): %s", av[0]+1); + return; + } good = 0; ref = strtoumax(av[2], &p, 0); From phk at FreeBSD.org Mon Mar 16 12:16:07 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 13:16:07 +0100 Subject: [master] c7c23d9 Run the vcl-cooldown poker at 45% of the vcl_cooldown interval. Message-ID: commit c7c23d97b59eb1e31d12ce4bb576ab1d82453850 Author: Poul-Henning Kamp Date: Mon Mar 16 12:15:27 2015 +0000 Run the vcl-cooldown poker at 45% of the vcl_cooldown interval. diff --git a/bin/varnishd/mgt/mgt_vcl.c b/bin/varnishd/mgt/mgt_vcl.c index 125f751..062c9ca 100644 --- a/bin/varnishd/mgt/mgt_vcl.c +++ b/bin/varnishd/mgt/mgt_vcl.c @@ -433,6 +433,7 @@ mgt_vcl_poker(const struct vev *e, int what) (void)e; (void)what; + e_poker->timeout = mgt_param.vcl_cooldown * .45; VTAILQ_FOREACH(vp, &vclhead, list) mgt_vcl_setstate(vp, -1); return (0); @@ -463,6 +464,7 @@ mgt_vcl_init(void) e_poker = vev_new(); AN(e_poker); e_poker->timeout = 3; // random, prime + e_poker->callback = mgt_vcl_poker; e_poker->name = "vcl poker"; AZ(vev_add(mgt_evb, e_poker)); From nils.goroll at uplex.de Mon Mar 16 12:36:32 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 16 Mar 2015 13:36:32 +0100 Subject: [master] 559ebaa SUBPROC_VCC doesn't fork, so why should it have anything in (I)nheritable? Message-ID: commit 559ebaa070564cd79adf4d1e99f73bf1fa49de57 Author: Nils Goroll Date: Fri Mar 13 20:36:20 2015 +0100 SUBPROC_VCC doesn't fork, so why should it have anything in (I)nheritable? diff --git a/bin/varnishd/mgt/mgt_jail_solaris.c b/bin/varnishd/mgt/mgt_jail_solaris.c index 7d618aa..6c88991 100644 --- a/bin/varnishd/mgt/mgt_jail_solaris.c +++ b/bin/varnishd/mgt/mgt_jail_solaris.c @@ -295,8 +295,6 @@ vjs_add_inheritable(priv_set_t *pset, enum jail_gen_e jge) { switch (jge) { case JAILG_SUBPROC_VCC: - /* for /etc/resolv.conf and /etc/hosts */ - priv_setop_assert(priv_addset(pset, "file_read")); break; case JAILG_SUBPROC_CC: priv_setop_assert(priv_addset(pset, PRIV_PROC_EXEC)); @@ -323,6 +321,9 @@ vjs_add_effective(priv_set_t *pset, enum jail_gen_e jge) { switch (jge) { case JAILG_SUBPROC_VCC: + // open vmods + priv_setop_assert(priv_addset(pset, "file_read")); + // write .c output priv_setop_assert(priv_addset(pset, "file_write")); break; case JAILG_SUBPROC_CC: From nils.goroll at uplex.de Mon Mar 16 12:36:32 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 16 Mar 2015 13:36:32 +0100 Subject: [master] 55be20d make the inheritable set independent, do away with the inheritable < effective construction rule Message-ID: commit 55be20df030ecf2f137195c7ec71372bbf105994 Author: Nils Goroll Date: Fri Mar 13 20:49:45 2015 +0100 make the inheritable set independent, do away with the inheritable < effective construction rule diff --git a/bin/varnishd/mgt/mgt_jail_solaris.c b/bin/varnishd/mgt/mgt_jail_solaris.c index 6c88991..362171c 100644 --- a/bin/varnishd/mgt/mgt_jail_solaris.c +++ b/bin/varnishd/mgt/mgt_jail_solaris.c @@ -311,11 +311,6 @@ vjs_add_inheritable(priv_set_t *pset, enum jail_gen_e jge) } } -/* - * effective is initialized from inheritable (see vjs_waive) - * so only additionally required privileges need to be added here - */ - static void vjs_add_effective(priv_set_t *pset, enum jail_gen_e jge) { @@ -327,6 +322,10 @@ vjs_add_effective(priv_set_t *pset, enum jail_gen_e jge) priv_setop_assert(priv_addset(pset, "file_write")); break; case JAILG_SUBPROC_CC: + priv_setop_assert(priv_addset(pset, PRIV_PROC_EXEC)); + priv_setop_assert(priv_addset(pset, PRIV_PROC_FORK)); + priv_setop_assert(priv_addset(pset, "file_read")); + priv_setop_assert(priv_addset(pset, "file_write")); break; case JAILG_SUBPROC_VCLLOAD: priv_setop_assert(priv_addset(pset, "file_read")); @@ -448,11 +447,12 @@ vjs_privsep(enum jail_gen_e jge) static void vjs_waive(enum jail_gen_e jge) { - priv_set_t *effective, *inheritable, *permitted; + priv_set_t *effective, *inheritable, *permitted, *limited; if (!(effective = priv_allocset()) || !(inheritable = priv_allocset()) || - !(permitted = priv_allocset())) { + !(permitted = priv_allocset()) || + !(limited = priv_allocset())) { REPORT(LOG_ERR, "Solaris Jail warning: " " vjs_waive - priv_allocset failed: errno=%d (%s)", @@ -461,35 +461,40 @@ vjs_waive(enum jail_gen_e jge) } /* - * simple scheme: - * (inheritable subset-of effective) subset-of permitted + * inheritable and effective are distinct sets + * effective is a subset of permitted + * limit is the union of all */ priv_emptyset(inheritable); vjs_add_inheritable(inheritable, jge); - priv_copyset(inheritable, effective); + priv_emptyset(effective); vjs_add_effective(effective, jge); priv_copyset(effective, permitted); vjs_add_permitted(permitted, jge); + priv_copyset(inheritable, limited); + priv_union(permitted, limited); /* * invert the sets and clear privileges such that setppriv will always * succeed */ - priv_inverse(inheritable); - priv_inverse(effective); + priv_inverse(limited); priv_inverse(permitted); + priv_inverse(effective); + priv_inverse(inheritable); - AZ(setppriv(PRIV_OFF, PRIV_LIMIT, permitted)); + AZ(setppriv(PRIV_OFF, PRIV_LIMIT, limited)); AZ(setppriv(PRIV_OFF, PRIV_PERMITTED, permitted)); AZ(setppriv(PRIV_OFF, PRIV_EFFECTIVE, effective)); AZ(setppriv(PRIV_OFF, PRIV_INHERITABLE, inheritable)); - priv_freeset(inheritable); - priv_freeset(effective); + priv_freeset(limited); priv_freeset(permitted); + priv_freeset(effective); + priv_freeset(inheritable); } static void __match_proto__(jail_subproc_f) From nils.goroll at uplex.de Mon Mar 16 12:49:03 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 16 Mar 2015 13:49:03 +0100 Subject: [master] ce8ce4b missing break statement Message-ID: commit ce8ce4bf796845067e55e746360f9787c3b4e197 Author: Nils Goroll Date: Mon Mar 16 13:47:04 2015 +0100 missing break statement Thank you, fgs diff --git a/bin/varnishd/mgt/mgt_jail_solaris.c b/bin/varnishd/mgt/mgt_jail_solaris.c index 362171c..8a8e971 100644 --- a/bin/varnishd/mgt/mgt_jail_solaris.c +++ b/bin/varnishd/mgt/mgt_jail_solaris.c @@ -329,6 +329,7 @@ vjs_add_effective(priv_set_t *pset, enum jail_gen_e jge) break; case JAILG_SUBPROC_VCLLOAD: priv_setop_assert(priv_addset(pset, "file_read")); + break; case JAILG_SUBPROC_WORKER: priv_setop_assert(priv_addset(pset, "net_access")); priv_setop_assert(priv_addset(pset, "file_read")); From nils.goroll at uplex.de Mon Mar 16 14:06:42 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 16 Mar 2015 15:06:42 +0100 Subject: [master] 3e53135 SC_ is for session close, so it imples SESS_ Message-ID: commit 3e53135cb4975ce2494d3923d07ee92c99754a49 Author: Nils Goroll Date: Mon Mar 16 15:06:29 2015 +0100 SC_ is for session close, so it imples SESS_ diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index b374dce..f6868e8 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -300,7 +300,7 @@ SES_Wait(struct sess *sp) sp->waited.idle = sp->t_idle; if (Wait_Enter(pp->http1_waiter, &sp->waited)) { VSC_C_main->sess_pipe_overflow++; - SES_Delete(sp, SC_SESS_PIPE_OVERFLOW, NAN); + SES_Delete(sp, SC_PIPE_OVERFLOW, NAN); } } diff --git a/include/tbl/sess_close.h b/include/tbl/sess_close.h index 8930b74..99b9f38 100644 --- a/include/tbl/sess_close.h +++ b/include/tbl/sess_close.h @@ -42,6 +42,6 @@ SESS_CLOSE(TX_ERROR, "Error transaction") SESS_CLOSE(TX_EOF, "EOF transmission") SESS_CLOSE(RESP_CLOSE, "Backend/VCL requested close") SESS_CLOSE(OVERLOAD, "Out of some resource") -SESS_CLOSE(SESS_PIPE_OVERFLOW, "Session pipe overflow") +SESS_CLOSE(PIPE_OVERFLOW, "Session pipe overflow") /*lint -restore */ From phk at FreeBSD.org Mon Mar 16 14:16:28 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 15:16:28 +0100 Subject: [master] ecae7e0 Drastically shorten the windows where we leave our sockets closed in order to prevent other processes from stealing them. Message-ID: commit ecae7e0919b8adea09c542774727c8b21c1b08ea Author: Poul-Henning Kamp Date: Mon Mar 16 14:15:35 2015 +0000 Drastically shorten the windows where we leave our sockets closed in order to prevent other processes from stealing them. (We have to close & reopen when the client dies, there is no unlisten(2)) diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h index 0321e2b..949853b 100644 --- a/bin/varnishd/common/heritage.h +++ b/bin/varnishd/common/heritage.h @@ -37,8 +37,8 @@ struct listen_sock { #define LISTEN_SOCK_MAGIC 0x999e4b57 VTAILQ_ENTRY(listen_sock) list; int sock; - char *name; - struct suckaddr *addr; + const char *name; + const struct suckaddr *addr; }; VTAILQ_HEAD(listen_sock_head, listen_sock); diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h index 9c23cd7..7f42f87 100644 --- a/bin/varnishd/mgt/mgt.h +++ b/bin/varnishd/mgt/mgt.h @@ -42,8 +42,8 @@ extern int exit_status; /* mgt_acceptor.c */ void MAC_Arg(const char *); -int MAC_open_sockets(struct cli *); -void MAC_close_sockets(void); +void MAC_reopen_sockets(struct cli *); +int MAC_sockets_ready(struct cli *); /* mgt_child.c */ extern pid_t child_pid; diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index faa90ff..1d9aa47 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -49,51 +49,62 @@ #include "vss.h" #include "vtcp.h" + +static int +mac_opensocket(struct listen_sock *ls, struct cli *cli) +{ + int fail; + + CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC); + if (ls->sock > 0) { + mgt_child_inherit(ls->sock, NULL); + AZ(close(ls->sock)); + } + ls->sock = VTCP_bind(ls->addr, NULL); + fail = errno; + if (ls->sock >= 0) + mgt_child_inherit(ls->sock, "sock"); + if (cli != NULL && ls->sock < 0) { + VCLI_Out(cli, "Could not get socket %s: %s\n", + ls->name, strerror(errno)); + } + return (fail); +} + /*===================================================================== - * Open and close the accept sockets. - * - * (The child is priv-sep'ed, so it can't do it.) + * Reopen the accept sockets to get rid of listen status. */ -int -MAC_open_sockets(struct cli *cli) +void +MAC_reopen_sockets(struct cli *cli) { struct listen_sock *ls; - int fail; VJ_master(JAIL_MASTER_PRIVPORT); - VTAILQ_FOREACH(ls, &heritage.socks, list) { - assert(ls->sock < 0); - ls->sock = VTCP_bind(ls->addr, NULL); - if (ls->sock < 0) - break; - mgt_child_inherit(ls->sock, "sock"); - } - fail = errno; + VTAILQ_FOREACH(ls, &heritage.socks, list) + (void)mac_opensocket(ls, cli); VJ_master(JAIL_MASTER_LOW); - if (ls == NULL) - return (0); - MAC_close_sockets(); - VCLI_Out(cli, "Could not get socket %s: %s\n", - ls->name, strerror(fail)); - errno = fail; - return (-1); } -/*--------------------------------------------------------------------*/ +/*===================================================================== + * Make sure we have all our sockets (and try once more to get them) + */ -void -MAC_close_sockets(void) +int +MAC_sockets_ready(struct cli *cli) { + int retval = 1; struct listen_sock *ls; + VJ_master(JAIL_MASTER_PRIVPORT); VTAILQ_FOREACH(ls, &heritage.socks, list) { if (ls->sock < 0) - continue; - mgt_child_inherit(ls->sock, NULL); - AZ(close(ls->sock)); - ls->sock = -1; + (void)mac_opensocket(ls, cli); + if (ls->sock < 0) + retval = 0; } + VJ_master(JAIL_MASTER_LOW); + return (retval); } /*--------------------------------------------------------------------*/ @@ -111,26 +122,29 @@ mac_callback(void *priv, const struct suckaddr *sa) { struct mac_help *mh; struct listen_sock *ls; - int sock; + int fail; char abuf[VTCP_ADDRBUFSIZE], pbuf[VTCP_PORTBUFSIZE]; char nbuf[VTCP_ADDRBUFSIZE+VTCP_PORTBUFSIZE+2]; CAST_OBJ_NOTNULL(mh, priv, MAC_HELP_MAGIC); - sock = VTCP_bind(sa, NULL); - if (sock < 0) { - *(mh->err) = strerror(errno); - return (0); - } ALLOC_OBJ(ls, LISTEN_SOCK_MAGIC); AN(ls); + ls->sock = -1; + ls->addr = sa; + fail = mac_opensocket(ls, NULL); + if (ls->sock < 0) { + *(mh->err) = strerror(fail); + FREE_OBJ(ls); + return (0); + } if (VSA_Port(sa) == 0) { /* * If the port number is zero, we adopt whatever port number * this VTCP_bind() found us, as if specified by argument. */ - ls->addr = VTCP_my_suckaddr(sock); - VTCP_myname(sock, abuf, sizeof abuf, pbuf, sizeof pbuf); + ls->addr = VTCP_my_suckaddr(ls->sock); + VTCP_myname(ls->sock, abuf, sizeof abuf, pbuf, sizeof pbuf); bprintf(nbuf, "%s:%s", abuf, pbuf); ls->name = strdup(nbuf); } else { @@ -139,8 +153,6 @@ mac_callback(void *priv, const struct suckaddr *sa) } AN(ls->addr); AN(ls->name); - AZ(close(sock)); - ls->sock = -1; VTAILQ_INSERT_TAIL(&heritage.socks, ls, list); mh->good++; return (0); diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index eca8af2..c8f92ea 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -303,7 +303,7 @@ mgt_launch_child(struct cli *cli) if (child_state != CH_STOPPED && child_state != CH_DIED) return; - if (MAC_open_sockets(cli) != 0) { + if (!MAC_sockets_ready(cli)) { child_state = CH_STOPPED; if (cli != NULL) { VCLI_SetResult(cli, CLIS_CANT); @@ -393,7 +393,7 @@ mgt_launch_child(struct cli *cli) mgt_child_inherit(heritage.cli_out, NULL); closex(&heritage.cli_out); - MAC_close_sockets(); + MAC_reopen_sockets(cli); child_std_vlu = VLU_New(NULL, child_line, 0); AN(child_std_vlu); From phk at FreeBSD.org Mon Mar 16 14:25:50 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 15:25:50 +0100 Subject: [master] df5ce64 Retire this test-case again, it fails after the change to socket (re)open code. Message-ID: commit df5ce641f9f529e1dc525d5d29aac8579fee082c Author: Poul-Henning Kamp Date: Mon Mar 16 14:25:31 2015 +0000 Retire this test-case again, it fails after the change to socket (re)open code. diff --git a/bin/varnishtest/tests/c00069.vtc b/bin/varnishtest/tests/c00069.vtc deleted file mode 100644 index 76c4b56..0000000 --- a/bin/varnishtest/tests/c00069.vtc +++ /dev/null @@ -1,21 +0,0 @@ -varnishtest "Test failure if our listen socket gets stolen" - -server s1 { - rxreq - txresp -} -start - -varnish v1 -arg "-a :0" -vcl+backend {} -start - -client c1 { - txreq - rxresp - expect resp.status == 200 -} -run - -varnish v1 -stop - -# Now have another varnish steal the listen socket -varnish v2 -arg "-a ${v1_addr}:${v1_port}" -vcl+backend {} -start - -varnish v1 -clierr 300 "start" From martin at varnish-software.com Mon Mar 16 15:10:51 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Mon, 16 Mar 2015 16:10:51 +0100 Subject: [3.0] 85e8468 Do not consider a CR by itself as a valid line terminator Message-ID: commit 85e8468bec9416bd7e16b0d80cb820ecd2b330c3 Author: Martin Blix Grydeland Date: Thu Mar 12 15:41:51 2015 +0100 Do not consider a CR by itself as a valid line terminator Varnish (prior to version 4.0) was not following the standard with regard to line separator. Spotted and analyzed by: R?gis Leroy [regilero] regis.leroy at makina-corpus.com diff --git a/bin/varnishd/cache_http.c b/bin/varnishd/cache_http.c index 605975b..5ab7bc0 100644 --- a/bin/varnishd/cache_http.c +++ b/bin/varnishd/cache_http.c @@ -502,7 +502,7 @@ http_dissect_hdrs(struct worker *w, struct http *hp, int fd, char *p, /* Find end of next header */ q = r = p; while (r < t.e) { - if (!vct_iscrlf(*r)) { + if (!vct_iscrlf(r)) { r++; continue; } @@ -611,8 +611,8 @@ http_splitline(struct worker *w, int fd, struct http *hp, /* Third field is optional and cannot contain CTL */ q = p; - if (!vct_iscrlf(*p)) { - for (; !vct_iscrlf(*p); p++) + if (!vct_iscrlf(p)) { + for (; !vct_iscrlf(p); p++) if (!vct_issep(*p) && vct_isctl(*p)) return (400); } diff --git a/bin/varnishtest/tests/b00040.vtc b/bin/varnishtest/tests/b00040.vtc new file mode 100644 index 0000000..3492570 --- /dev/null +++ b/bin/varnishtest/tests/b00040.vtc @@ -0,0 +1,24 @@ +varnishtest "Do not consider CR as a valid line separator" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_deliver { + if (req.http.foo) { + set resp.http.Foo = req.http.foo; + } + if (req.http.bar) { + set resp.http.Bar = req.http.bar; + } + } +} -start + +client c1 { + send "GET / HTTP/1.1\r\nFoo: foo\rBar: bar\r\n\r\n" + rxresp + expect resp.http.foo == "foo\rBar: bar" + expect resp.http.bar == "" +} -run diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index 5a947f1..dd2c804 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -283,17 +283,17 @@ http_splitheader(struct http *hp, int req) hh[n++] = p; while (!vct_islws(*p)) p++; - assert(!vct_iscrlf(*p)); + assert(!vct_iscrlf(p)); *p++ = '\0'; /* URL/STATUS */ while (vct_issp(*p)) /* XXX: H space only */ p++; - assert(!vct_iscrlf(*p)); + assert(!vct_iscrlf(p)); hh[n++] = p; while (!vct_islws(*p)) p++; - if (vct_iscrlf(*p)) { + if (vct_iscrlf(p)) { hh[n++] = NULL; q = p; p += vct_skipcrlf(p); @@ -304,7 +304,7 @@ http_splitheader(struct http *hp, int req) while (vct_issp(*p)) /* XXX: H space only */ p++; hh[n++] = p; - while (!vct_iscrlf(*p)) + while (!vct_iscrlf(p)) p++; q = p; p += vct_skipcrlf(p); @@ -314,10 +314,10 @@ http_splitheader(struct http *hp, int req) while (*p != '\0') { assert(n < MAX_HDR); - if (vct_iscrlf(*p)) + if (vct_iscrlf(p)) break; hh[n++] = p++; - while (*p != '\0' && !vct_iscrlf(*p)) + while (*p != '\0' && !vct_iscrlf(p)) p++; q = p; p += vct_skipcrlf(p); @@ -408,11 +408,11 @@ http_rxchunk(struct http *hp) } l = hp->prxbuf; (void)http_rxchar(hp, 2, 0); - if(!vct_iscrlf(hp->rxbuf[l])) + if(!vct_iscrlf(&hp->rxbuf[l])) vtc_log(hp->vl, hp->fatal, "Wrong chunk tail[0] = %02x", hp->rxbuf[l] & 0xff); - if(!vct_iscrlf(hp->rxbuf[l + 1])) + if(!vct_iscrlf(&hp->rxbuf[l + 1])) vtc_log(hp->vl, hp->fatal, "Wrong chunk tail[1] = %02x", hp->rxbuf[l + 1] & 0xff); diff --git a/include/vct.h b/include/vct.h index fb4c2af..8884755 100644 --- a/include/vct.h +++ b/include/vct.h @@ -54,7 +54,6 @@ vct_is(unsigned char x, uint16_t y) #define vct_issp(x) vct_is(x, VCT_SP) #define vct_ishex(x) vct_is(x, VCT_HEX) -#define vct_iscrlf(x) vct_is(x, VCT_CRLF) #define vct_islws(x) vct_is(x, VCT_LWS) #define vct_isctl(x) vct_is(x, VCT_CTL) #define vct_isdigit(x) vct_is(x, VCT_DIGIT) @@ -64,5 +63,7 @@ vct_is(unsigned char x, uint16_t y) #define vct_isxmlnamestart(x) vct_is(x, VCT_XMLNAMESTART) #define vct_isxmlname(x) vct_is(x, VCT_XMLNAMESTART | VCT_XMLNAME) +#define vct_iscrlf(p) (((p)[0] == '\r' && (p)[1] == '\n') || (p)[0] == '\n') + /* NB: VCT always operate in ASCII, don't replace 0x0d with \r etc. */ #define vct_skipcrlf(p) (p[0] == 0x0d && p[1] == 0x0a ? 2 : 1) From martin at varnish-software.com Mon Mar 16 15:10:51 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Mon, 16 Mar 2015 16:10:51 +0100 Subject: [3.0] 29870c8 Check for duplicate Content-Length headers in requests Message-ID: commit 29870c8fe95e4e8a672f6f28c5fbe692bea09e9c Author: Martin Blix Grydeland Date: Fri Mar 13 12:57:39 2015 +0100 Check for duplicate Content-Length headers in requests If a duplicate CL header is in the request, we fail the request with a 400 (Bad Request) Fix a test case that was sending duplicate CL by misstake and would not fail because of that. diff --git a/bin/varnishd/cache_http.c b/bin/varnishd/cache_http.c index 5ab7bc0..3680422 100644 --- a/bin/varnishd/cache_http.c +++ b/bin/varnishd/cache_http.c @@ -639,10 +639,12 @@ http_splitline(struct worker *w, int fd, struct http *hp, /*--------------------------------------------------------------------*/ static int -htc_request_check_host_hdr(struct http *hp) +htc_request_check_hdrs(struct sess *sp, struct http *hp) { int u; int seen_host = 0; + int seen_cl = 0; + for (u = HTTP_HDR_FIRST; u < hp->nhd; u++) { if (hp->hd[u].b == NULL) continue; @@ -650,10 +652,19 @@ htc_request_check_host_hdr(struct http *hp) AN(hp->hd[u].e); if (http_IsHdr(&hp->hd[u], H_Host)) { if (seen_host) { + WSP(sp, SLT_Error, "Duplicated Host header"); return (400); } seen_host = 1; } + if (http_IsHdr(&hp->hd[u], H_Content_Length)) { + if (seen_cl) { + WSP(sp, SLT_Error, + "Duplicated Content-Length header"); + return (400); + } + seen_cl = 1; + } } return (0); } @@ -698,11 +709,7 @@ http_DissectRequest(struct sess *sp) } http_ProtoVer(hp); - retval = htc_request_check_host_hdr(hp); - if (retval != 0) { - WSP(sp, SLT_Error, "Duplicated Host header"); - return (retval); - } + retval = htc_request_check_hdrs(sp, hp); return (retval); } diff --git a/bin/varnishtest/tests/b00041.vtc b/bin/varnishtest/tests/b00041.vtc new file mode 100644 index 0000000..292cea9 --- /dev/null +++ b/bin/varnishtest/tests/b00041.vtc @@ -0,0 +1,23 @@ +varnishtest "Fail request on duplicate Content-Length headers in requests" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_deliver { + if (req.http.foo) { + set resp.http.Foo = req.http.foo; + } + if (req.http.bar) { + set resp.http.Bar = req.http.bar; + } + } +} -start + +client c1 { + txreq -req POST -hdr "Content-Length: 5" -body "12345" + rxresp + expect resp.status == 400 +} -run diff --git a/bin/varnishtest/tests/r00102.vtc b/bin/varnishtest/tests/r00102.vtc index 6d2d8aa..7309762 100644 --- a/bin/varnishtest/tests/r00102.vtc +++ b/bin/varnishtest/tests/r00102.vtc @@ -17,14 +17,12 @@ varnish v1 -vcl+backend { client c1 { txreq -req POST -url "/" \ - -hdr "Content-Length: 10" \ -body "123456789\n" rxresp expect resp.status == 200 expect resp.http.X-Varnish == "1001" txreq -req POST -url "/" \ - -hdr "Content-Length: 10" \ -body "123456789\n" rxresp expect resp.status == 200 From martin at varnish-software.com Mon Mar 16 15:10:51 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Mon, 16 Mar 2015 16:10:51 +0100 Subject: [3.0] 7298173 Only emit passed Content_Length header when response mode is RES_LEN Message-ID: commit 72981734a141a0a52172b85bae55f8877f69ff42 Author: Martin Blix Grydeland Date: Mon Mar 16 11:49:11 2015 +0100 Only emit passed Content_Length header when response mode is RES_LEN Original patch and test case by: tnt Fixes: #1627 diff --git a/bin/varnishd/cache_response.c b/bin/varnishd/cache_response.c index 160dda7..e976297 100644 --- a/bin/varnishd/cache_response.c +++ b/bin/varnishd/cache_response.c @@ -351,9 +351,9 @@ RES_StreamStart(struct sess *sp) if (sp->wrk->res_mode & RES_GUNZIP) http_Unset(sp->wrk->resp, H_Content_Encoding); - if (!(sp->wrk->res_mode & RES_CHUNKED) && - sp->wrk->h_content_length != NULL) { - http_Unset(sp->wrk->resp, H_Content_Length); + http_Unset(sp->wrk->resp, H_Content_Length); + if (sp->wrk->res_mode & RES_LEN) { + AN(sp->wrk->h_content_length); http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Content-Length: %s", sp->wrk->h_content_length); } diff --git a/bin/varnishtest/tests/r01627.vtc b/bin/varnishtest/tests/r01627.vtc new file mode 100644 index 0000000..1cbc9dd --- /dev/null +++ b/bin/varnishtest/tests/r01627.vtc @@ -0,0 +1,21 @@ +varnishtest "Regression test for #1627: Wrong Content-Length for gzipped+streamed content with HTTP/1.0 client" + +server s1 { + rxreq + txresp -body {Testing} +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + set beresp.do_stream = true; + set beresp.do_gzip = true; + } +} -start + +client c1 { + txreq -proto "HTTP/1.0" -hdr "Accept-Encoding: gzip" + rxresp + expect resp.http.content-length == "" + gunzip + expect resp.bodylen == 7 +} -run From martin at varnish-software.com Mon Mar 16 15:11:00 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Mon, 16 Mar 2015 16:11:00 +0100 Subject: [4.0] bfceeca Bring in the http_CountHdr function from master Message-ID: commit bfceecad021075d6067b16107d93284b4674f2e2 Author: Martin Blix Grydeland Date: Mon Mar 16 14:22:39 2015 +0100 Bring in the http_CountHdr function from master Use this when checking for duplicate Host headers diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 4a74db0..0fb6206 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -1024,6 +1024,7 @@ int http_IsHdr(const txt *hh, const char *hdr); enum sess_close http_DoConnection(struct http *); void http_CopyHome(struct http *hp); void http_Unset(struct http *hp, const char *hdr); +unsigned http_CountHdr(const struct http *hp, const char *hdr); void http_CollectHdr(struct http *hp, const char *hdr); void http_VSL_log(const struct http *hp); void http_Merge(const struct http *fm, struct http *to, int not_ce); diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c index 8fc3d16..572d987 100644 --- a/bin/varnishd/cache/cache_http.c +++ b/bin/varnishd/cache/cache_http.c @@ -264,6 +264,26 @@ http_findhdr(const struct http *hp, unsigned l, const char *hdr) } /*-------------------------------------------------------------------- + * Count how many instances we have of this header + */ + +unsigned +http_CountHdr(const struct http *hp, const char *hdr) +{ + unsigned retval = 0; + unsigned u; + + CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC); + + for (u = HTTP_HDR_FIRST; u < hp->nhd; u++) { + Tcheck(hp->hd[u]); + if (http_IsHdr(&hp->hd[u], hdr)) + retval++; + } + return (retval); +} + +/*-------------------------------------------------------------------- * This function collapses multiple headerlines of the same name. * The lines are joined with a comma, according to [rfc2616, 4.2bot, p32] */ diff --git a/bin/varnishd/cache/cache_http1_proto.c b/bin/varnishd/cache/cache_http1_proto.c index ff58c69..2c4eab3 100644 --- a/bin/varnishd/cache/cache_http1_proto.c +++ b/bin/varnishd/cache/cache_http1_proto.c @@ -375,30 +375,6 @@ htc_splitline(struct http *hp, const struct http_conn *htc, const int *hf) /*--------------------------------------------------------------------*/ -static uint16_t -htc_request_check_host_hdr(const struct http *hp) -{ - int u; - int seen_host = 0; - for (u = HTTP_HDR_FIRST; u < hp->nhd; u++) { - if (hp->hd[u].b == NULL) - continue; - AN(hp->hd[u].b); - AN(hp->hd[u].e); - if (http_IsHdr(&hp->hd[u], H_Host)) { - if (seen_host) { - VSLb(hp->vsl, SLT_Error, - "Duplicated Host header"); - return (400); - } - seen_host = 1; - } - } - return (0); -} - -/*--------------------------------------------------------------------*/ - static void htc_proto_ver(struct http *hp) { @@ -435,9 +411,9 @@ HTTP1_DissectRequest(struct req *req) } htc_proto_ver(hp); - retval = htc_request_check_host_hdr(hp); - if (retval != 0) { - return (retval); + if (http_CountHdr(hp, H_Host) > 1) { + VSLb(hp->vsl, SLT_Error, "Duplicate Host header"); + return (400); } /* RFC2616, section 5.2, point 1 */ From martin at varnish-software.com Mon Mar 16 15:11:00 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Mon, 16 Mar 2015 16:11:00 +0100 Subject: [4.0] c0de2e8 Fail requests on duplicate CL headers Message-ID: commit c0de2e8b7b1bf3591ac995ce4e8d9a7607ddca58 Author: Martin Blix Grydeland Date: Mon Mar 16 15:20:42 2015 +0100 Fail requests on duplicate CL headers Fix up a test case that ended sending duplicate headers by misstake diff --git a/bin/varnishd/cache/cache_http1_proto.c b/bin/varnishd/cache/cache_http1_proto.c index 2c4eab3..7247fac 100644 --- a/bin/varnishd/cache/cache_http1_proto.c +++ b/bin/varnishd/cache/cache_http1_proto.c @@ -416,6 +416,11 @@ HTTP1_DissectRequest(struct req *req) return (400); } + if (http_CountHdr(hp, H_Content_Length) > 1) { + VSLb(hp->vsl, SLT_Error, "Duplicate Content-Length header"); + return (400); + } + /* RFC2616, section 5.2, point 1 */ if (!strncasecmp(hp->hd[HTTP_HDR_URL].b, "http://", 7)) { b = e = hp->hd[HTTP_HDR_URL].b + 7; diff --git a/bin/varnishtest/tests/b00043.vtc b/bin/varnishtest/tests/b00043.vtc new file mode 100644 index 0000000..6ff253b --- /dev/null +++ b/bin/varnishtest/tests/b00043.vtc @@ -0,0 +1,23 @@ +varnishtest "Fail request on duplicate Content-Length headers in requests" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_deliver { + if (req.http.foo) { + set resp.http.Foo = req.http.foo; + } + if (req.http.bar) { + set resp.http.Bar = req.http.bar; + } + } +} -start + +client c1 { + txreq -req POST -hdr "Content-Length: 5" -body "12345" + rxresp + expect resp.status == 400 +} -run diff --git a/bin/varnishtest/tests/r00102.vtc b/bin/varnishtest/tests/r00102.vtc index cf8a1bb..b8b56b3 100644 --- a/bin/varnishtest/tests/r00102.vtc +++ b/bin/varnishtest/tests/r00102.vtc @@ -17,14 +17,12 @@ varnish v1 -vcl+backend { client c1 { txreq -req POST -url "/" \ - -hdr "Content-Length: 10" \ -body "123456789\n" rxresp expect resp.status == 200 expect resp.http.X-Varnish == "1001" txreq -req POST -url "/" \ - -hdr "Content-Length: 10" \ -body "123456789\n" rxresp expect resp.status == 200 From nils.goroll at uplex.de Mon Mar 16 15:12:12 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 16 Mar 2015 16:12:12 +0100 Subject: [master] 6e3d77e prep field names for sess_close stats counters Message-ID: commit 6e3d77ed54900ccb98d42fabb646c4a3e993484b Author: Nils Goroll Date: Mon Mar 16 15:18:02 2015 +0100 prep field names for sess_close stats counters diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 8817c3c..6c46bea 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -86,7 +86,7 @@ enum req_body_state_e { enum sess_close { SC_NULL = 0, -#define SESS_CLOSE(nm, desc) SC_##nm, +#define SESS_CLOSE(nm, stat, desc) SC_##nm, #include "tbl/sess_close.h" #undef SESS_CLOSE }; diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 865a45a..f0c459d 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -101,7 +101,7 @@ sess_close_2str(enum sess_close sc, int want_desc) { switch (sc) { case SC_NULL: return(want_desc ? "(null)": "NULL"); -#define SESS_CLOSE(nm, desc) case SC_##nm: return(want_desc ? desc : #nm); +#define SESS_CLOSE(nm, s, desc) case SC_##nm: return(want_desc ? desc : #nm); #include "tbl/sess_close.h" #undef SESS_CLOSE diff --git a/include/tbl/sess_close.h b/include/tbl/sess_close.h index 99b9f38..f6e928d 100644 --- a/include/tbl/sess_close.h +++ b/include/tbl/sess_close.h @@ -29,19 +29,20 @@ /*lint -save -e525 -e539 */ -SESS_CLOSE(REM_CLOSE, "Client Closed") -SESS_CLOSE(REQ_CLOSE, "Client requested close") -SESS_CLOSE(REQ_HTTP10, "Proto < HTTP/1.1") -SESS_CLOSE(RX_BAD, "Received bad req/resp") -SESS_CLOSE(RX_BODY, "Failure receiving req.body") -SESS_CLOSE(RX_JUNK, "Received junk data") -SESS_CLOSE(RX_OVERFLOW, "Received buffer overflow") -SESS_CLOSE(RX_TIMEOUT, "Receive timeout") -SESS_CLOSE(TX_PIPE, "Piped transaction") -SESS_CLOSE(TX_ERROR, "Error transaction") -SESS_CLOSE(TX_EOF, "EOF transmission") -SESS_CLOSE(RESP_CLOSE, "Backend/VCL requested close") -SESS_CLOSE(OVERLOAD, "Out of some resource") -SESS_CLOSE(PIPE_OVERFLOW, "Session pipe overflow") +// enum sess_close SC.* stat Verbose error +SESS_CLOSE(REM_CLOSE, rem_close, "Client Closed") +SESS_CLOSE(REQ_CLOSE, req_close, "Client requested close") +SESS_CLOSE(REQ_HTTP10, req_http10, "Proto < HTTP/1.1") +SESS_CLOSE(RX_BAD, rx_bad, "Received bad req/resp") +SESS_CLOSE(RX_BODY, rx_body, "Failure receiving req.body") +SESS_CLOSE(RX_JUNK, rx_junk, "Received junk data") +SESS_CLOSE(RX_OVERFLOW, rx_overflow, "Received buffer overflow") +SESS_CLOSE(RX_TIMEOUT, rx_timeout, "Receive timeout") +SESS_CLOSE(TX_PIPE, tx_pipe, "Piped transaction") +SESS_CLOSE(TX_ERROR, tx_error, "Error transaction") +SESS_CLOSE(TX_EOF, tx_eof, "EOF transmission") +SESS_CLOSE(RESP_CLOSE, resp_close, "Backend/VCL requested close") +SESS_CLOSE(OVERLOAD, overload, "Out of some resource") +SESS_CLOSE(PIPE_OVERFLOW, pipe_overflow, "Session pipe overflow") /*lint -restore */ diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index 8002f95..0f9a56b 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -81,7 +81,7 @@ SLTM(SessOpen, 0, "Client connection opened", * XXX: in the middle of a macro invocation :-( * XXX: If we could, these three lines would have described the * XXX: 'reason' field below. -#define SESS_CLOSE(nm, desc) " " #nm "\n\t" desc "\n\n" +#define SESS_CLOSE(nm, s, desc) " " #nm "\n\t" desc "\n\n" #include "tbl/sess_close.h" #undef SESS_CLOSE */ From nils.goroll at uplex.de Mon Mar 16 15:12:12 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 16 Mar 2015 16:12:12 +0100 Subject: [master] 7d25d3a sync stats order in vsc_all.h and vsc2rst.c by vsc_types.h Message-ID: commit 7d25d3a1acc17814242ba5fbeb707988c418588a Author: Nils Goroll Date: Mon Mar 16 16:08:04 2015 +0100 sync stats order in vsc_all.h and vsc2rst.c by vsc_types.h diff --git a/include/tbl/vsc_all.h b/include/tbl/vsc_all.h index 53843c6..6cc1805 100644 --- a/include/tbl/vsc_all.h +++ b/include/tbl/vsc_all.h @@ -28,21 +28,21 @@ */ +VSC_DO(MAIN, main, VSC_type_main) +#include "tbl/vsc_f_main.h" +VSC_DONE(MAIN, main, VSC_type_main) + VSC_DO(MGT, mgt, VSC_type_mgt) #define VSC_DO_MGT #include "tbl/vsc_fields.h" #undef VSC_DO_MGT VSC_DONE(MGT, mgt, VSC_type_mgt) -VSC_DO(LCK, lck, VSC_type_lck) -#define VSC_DO_LCK +VSC_DO(MEMPOOL, mempool, VSC_type_mempool) +#define VSC_DO_MEMPOOL #include "tbl/vsc_fields.h" -#undef VSC_DO_LCK -VSC_DONE(LCK, lck, VSC_type_lck) - -VSC_DO(MAIN, main, VSC_type_main) -#include "tbl/vsc_f_main.h" -VSC_DONE(MAIN, main, VSC_type_main) +#undef VSC_DO_MEMPOOL +VSC_DONE(MEMPOOL, mempool, VSC_type_mempool) VSC_DO(SMA, sma, VSC_type_sma) #define VSC_DO_SMA @@ -62,8 +62,8 @@ VSC_DO(VBE, vbe, VSC_type_vbe) #undef VSC_DO_VBE VSC_DONE(VBE, vbe, VSC_type_vbe) -VSC_DO(MEMPOOL, mempool, VSC_type_mempool) -#define VSC_DO_MEMPOOL +VSC_DO(LCK, lck, VSC_type_lck) +#define VSC_DO_LCK #include "tbl/vsc_fields.h" -#undef VSC_DO_MEMPOOL -VSC_DONE(MEMPOOL, mempool, VSC_type_mempool) +#undef VSC_DO_LCK +VSC_DONE(LCK, lck, VSC_type_lck) diff --git a/man/vsc2rst.c b/man/vsc2rst.c index 66aaa30..d9ad471 100644 --- a/man/vsc2rst.c +++ b/man/vsc2rst.c @@ -66,43 +66,57 @@ int main(int argc, char **argv) #include "tbl/vsc_levels.h" P(""); - P("MAIN COUNTERS"); - P("============="); + P("MAIN COUNTERS (MAIN.*)"); + P("======================"); P(""); #include "tbl/vsc_f_main.h" + P("MANAGEMENT PROCESS COUNTERS (MGT.*)"); + P("==================================="); P(""); - P("LOCK COUNTERS"); - P("============="); +#define VSC_DO_MGT +#include "tbl/vsc_fields.h" +#undef VSC_DO_MGT + P(""); -#define VSC_DO_LCK + P("PER MEMORY POOL COUNTERS (MEMPOOL.*)"); + P("===================================="); + P(""); +#define VSC_DO_MEMPOOL #include "tbl/vsc_fields.h" -#undef VSC_DO_LCK +#undef VSC_DO_MEMPOOL P(""); - P("PER MALLOC STORAGE COUNTERS"); - P("==========================="); + P("PER MALLOC STORAGE COUNTERS (SMA.*)"); + P("==================================="); P(""); #define VSC_DO_SMA #include "tbl/vsc_fields.h" #undef VSC_DO_SMA P(""); - P("PER FILE STORAGE COUNTERS"); - P("========================="); + P("PER FILE STORAGE COUNTERS (SMF.*)"); + P("================================="); P(""); #define VSC_DO_SMF #include "tbl/vsc_fields.h" #undef VSC_DO_SMF P(""); - P("PER BACKEND COUNTERS"); - P("===================="); + P("PER BACKEND COUNTERS (VBE.*)"); + P("============================"); P(""); #define VSC_DO_VBE #include "tbl/vsc_fields.h" #undef VSC_DO_VBE + P(""); + P("LOCK COUNTERS (LCK.*)"); + P("====================="); + P(""); +#define VSC_DO_LCK +#include "tbl/vsc_fields.h" +#undef VSC_DO_LCK + return (0); } - From fgsch at lodoss.net Mon Mar 16 16:28:34 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 16 Mar 2015 17:28:34 +0100 Subject: [master] 8457ac6 Add some tests from the 4.0 branch Message-ID: commit 8457ac6ed4241742e813928cf02112f5b5fb7f36 Author: Federico G. Schwindt Date: Mon Mar 16 11:38:32 2015 +0000 Add some tests from the 4.0 branch diff --git a/bin/varnishtest/tests/r01637.vtc b/bin/varnishtest/tests/r01637.vtc new file mode 100644 index 0000000..1c7489c --- /dev/null +++ b/bin/varnishtest/tests/r01637.vtc @@ -0,0 +1,57 @@ +varnishtest "do_esi + do_gzip + out of storage: #1637" + +server s1 { + # First consume (almost) all of the storage + rxreq + expect req.url == /url1 + txresp -bodylen 260000 + + rxreq + expect req.url == /url2 + txresp -bodylen 260000 + + rxreq + expect req.url == /url3 + txresp -bodylen 260000 + + rxreq + expect req.url == /url4 + txresp -bodylen 260000 + + rxreq + expect req.url == /url5 + txresp -bodylen 9000 +} -start + +varnish v1 -arg "-smalloc,1M" -arg "-p nuke_limit=0 -p gzip_level=0" \ + -vcl+backend { + sub vcl_backend_response { + if (bereq.url == "/url5") { + set beresp.do_esi = true; + set beresp.do_gzip = true; + } + } +} -start + + +client c1 { + txreq -url /url1 + rxresp + expect resp.status == 200 + + txreq -url /url2 + rxresp + expect resp.status == 200 + + txreq -url /url3 + rxresp + expect resp.status == 200 + + txreq -url /url4 + rxresp + expect resp.status == 200 + + txreq -url /url5 + rxresp + expect resp.status == 503 +} -run diff --git a/bin/varnishtest/tests/r01660.vtc b/bin/varnishtest/tests/r01660.vtc new file mode 100644 index 0000000..1ce133c --- /dev/null +++ b/bin/varnishtest/tests/r01660.vtc @@ -0,0 +1,18 @@ +varnishtest "#1660: range and synth" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + return (synth(200, "OK")); + } +} -start + +client c1 { + txreq -hdr "Range: 0-1" + rxresp + expect resp.status == 200 +} -run diff --git a/bin/varnishtest/tests/r01691.vtc b/bin/varnishtest/tests/r01691.vtc new file mode 100644 index 0000000..71b6076 --- /dev/null +++ b/bin/varnishtest/tests/r01691.vtc @@ -0,0 +1,21 @@ +varnishtest "Test bogus Content-Length header" + +server s1 { + rxreq + txresp -nolen -hdr "Content-Length: bogus" +} -start + +varnish v1 -vcl+backend { + +} -start + +logexpect l1 -v v1 { + expect * 1002 Error "Body cannot be fetched" +} -start + +client c1 { + txreq + rxresp +} -run + +logexpect l1 -wait From nils.goroll at uplex.de Mon Mar 16 17:39:27 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 16 Mar 2015 18:39:27 +0100 Subject: [master] 0cbab46 session close reason accounting Message-ID: commit 0cbab464ab6479de2b2d686f562bc87064f15706 Author: Nils Goroll Date: Mon Mar 16 18:29:00 2015 +0100 session close reason accounting diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 6c46bea..0406d9e 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -86,7 +86,7 @@ enum req_body_state_e { enum sess_close { SC_NULL = 0, -#define SESS_CLOSE(nm, stat, desc) SC_##nm, +#define SESS_CLOSE(nm, stat, err, desc) SC_##nm, #include "tbl/sess_close.h" #undef SESS_CLOSE }; diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index f0c459d..1d2aa71 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -101,7 +101,8 @@ sess_close_2str(enum sess_close sc, int want_desc) { switch (sc) { case SC_NULL: return(want_desc ? "(null)": "NULL"); -#define SESS_CLOSE(nm, s, desc) case SC_##nm: return(want_desc ? desc : #nm); +#define SESS_CLOSE(nm, s, err, desc) \ + case SC_##nm: return(want_desc ? desc : #nm); #include "tbl/sess_close.h" #undef SESS_CLOSE diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index f6868e8..9e27b03 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -305,6 +305,30 @@ SES_Wait(struct sess *sp) } /*-------------------------------------------------------------------- + * Update sc_ counters by reason + * + * assuming that the approximation of non-atomic global counters is sufficient. + * if not: update to per-wrk + */ +static void +ses_close_acct(enum sess_close reason) +{ + assert(reason != SC_NULL); + switch (reason) { +#define SESS_CLOSE(reason, stat, err, desc) \ + case SC_ ## reason: \ + VSC_C_main->sc_ ## stat++; \ + if (err) \ + VSC_C_main->sess_closed_err++; \ + break; +#include "tbl/sess_close.h" +#undef SESS_CLOSE + default: + WRONG("Wrong event in ses_close_acct"); + } +} + +/*-------------------------------------------------------------------- * Close a sessions connection. * XXX: Technically speaking we should catch a t_end timestamp here * XXX: for SES_Delete() to use. @@ -320,6 +344,8 @@ SES_Close(struct sess *sp, enum sess_close reason) i = close(sp->fd); assert(i == 0 || errno != EBADF); /* XXX EINVAL seen */ sp->fd = -1; + if (reason != SC_NULL) + ses_close_acct(reason); } /*-------------------------------------------------------------------- diff --git a/include/tbl/sess_close.h b/include/tbl/sess_close.h index f6e928d..21c78ab 100644 --- a/include/tbl/sess_close.h +++ b/include/tbl/sess_close.h @@ -29,20 +29,20 @@ /*lint -save -e525 -e539 */ -// enum sess_close SC.* stat Verbose error -SESS_CLOSE(REM_CLOSE, rem_close, "Client Closed") -SESS_CLOSE(REQ_CLOSE, req_close, "Client requested close") -SESS_CLOSE(REQ_HTTP10, req_http10, "Proto < HTTP/1.1") -SESS_CLOSE(RX_BAD, rx_bad, "Received bad req/resp") -SESS_CLOSE(RX_BODY, rx_body, "Failure receiving req.body") -SESS_CLOSE(RX_JUNK, rx_junk, "Received junk data") -SESS_CLOSE(RX_OVERFLOW, rx_overflow, "Received buffer overflow") -SESS_CLOSE(RX_TIMEOUT, rx_timeout, "Receive timeout") -SESS_CLOSE(TX_PIPE, tx_pipe, "Piped transaction") -SESS_CLOSE(TX_ERROR, tx_error, "Error transaction") -SESS_CLOSE(TX_EOF, tx_eof, "EOF transmission") -SESS_CLOSE(RESP_CLOSE, resp_close, "Backend/VCL requested close") -SESS_CLOSE(OVERLOAD, overload, "Out of some resource") -SESS_CLOSE(PIPE_OVERFLOW, pipe_overflow, "Session pipe overflow") +// enum sess_close sc_* stat is_err Description +SESS_CLOSE(REM_CLOSE, rem_close, 0, "Client Closed") +SESS_CLOSE(REQ_CLOSE, req_close, 0, "Client requested close") +SESS_CLOSE(REQ_HTTP10, req_http10, 1, "Proto < HTTP/1.1") +SESS_CLOSE(RX_BAD, rx_bad, 1, "Received bad req/resp") +SESS_CLOSE(RX_BODY, rx_body, 1, "Failure receiving req.body") +SESS_CLOSE(RX_JUNK, rx_junk, 1, "Received junk data") +SESS_CLOSE(RX_OVERFLOW, rx_overflow, 1, "Received buffer overflow") +SESS_CLOSE(RX_TIMEOUT, rx_timeout, 1, "Receive timeout") +SESS_CLOSE(TX_PIPE, tx_pipe, 0, "Piped transaction") +SESS_CLOSE(TX_ERROR, tx_error, 1, "Error transaction") +SESS_CLOSE(TX_EOF, tx_eof, 0, "EOF transmission") +SESS_CLOSE(RESP_CLOSE, resp_close, 0, "Backend/VCL requested close") +SESS_CLOSE(OVERLOAD, overload, 1, "Out of some resource") +SESS_CLOSE(PIPE_OVERFLOW, pipe_overflow,1, "Session pipe overflow") /*lint -restore */ diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h index 94444d3..51ddb4f 100644 --- a/include/tbl/vsc_f_main.h +++ b/include/tbl/vsc_f_main.h @@ -388,6 +388,11 @@ VSC_F(sess_closed, uint64_t, 1, 'c', 'i', info, "Session Closed", "" ) +VSC_F(sess_closed_err, uint64_t, 0, 'c', 'i', info, + "Session Closed with error", + "Total number of sessions closed with errors." + " See sc_* diag counters for detailed breakdown" +) VSC_F(sess_pipeline, uint64_t, 1, 'c', 'i', info, "Session Pipeline", "" @@ -401,6 +406,23 @@ VSC_F(sess_herd, uint64_t, 1, 'c', 'i', diag, "" ) +#define SESS_CLOSE_ERR0 "OK " +#define SESS_CLOSE_ERR1 "Err " +#define SESS_CLOSE_ERROR0 "" +#define SESS_CLOSE_ERROR1 "Error " +#define SESS_CLOSE(r, f, e, s) \ +VSC_F(sc_ ## f, uint64_t, 0, 'c', 'i', diag, \ + "Session " SESS_CLOSE_ERR ## e #r, \ + "Number of session closes with " \ + SESS_CLOSE_ERROR ## e #r " (" s ")" \ +) +#include "tbl/sess_close.h" +#undef SESS_CLOSE +#undef SESS_CLOSE_ERROR1 +#undef SESS_CLOSE_ERROR0 +#undef SESS_CLOSE_ERR1 +#undef SESS_CLOSE_ERR0 + /*--------------------------------------------------------------------*/ VSC_F(shm_records, uint64_t, 0, 'c', 'i', diag, diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index 0f9a56b..7af249f 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -81,7 +81,7 @@ SLTM(SessOpen, 0, "Client connection opened", * XXX: in the middle of a macro invocation :-( * XXX: If we could, these three lines would have described the * XXX: 'reason' field below. -#define SESS_CLOSE(nm, s, desc) " " #nm "\n\t" desc "\n\n" +#define SESS_CLOSE(nm, s, err, desc) " " #nm "\n\t" desc "\n\n" #include "tbl/sess_close.h" #undef SESS_CLOSE */ From nils.goroll at uplex.de Mon Mar 16 17:39:28 2015 From: nils.goroll at uplex.de (Nils Goroll) Date: Mon, 16 Mar 2015 18:39:28 +0100 Subject: [master] d1bd9cb MAIN.sess_pipe_overflow is now MAIN.sc_pipe_overflow Message-ID: commit d1bd9cb053c465c7806c8fc8a3f23671cf494dba Author: Nils Goroll Date: Mon Mar 16 18:32:52 2015 +0100 MAIN.sess_pipe_overflow is now MAIN.sc_pipe_overflow diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 9e27b03..3a478a3 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -299,7 +299,6 @@ SES_Wait(struct sess *sp) sp->waited.ptr = sp; sp->waited.idle = sp->t_idle; if (Wait_Enter(pp->http1_waiter, &sp->waited)) { - VSC_C_main->sess_pipe_overflow++; SES_Delete(sp, SC_PIPE_OVERFLOW, NAN); } } diff --git a/include/tbl/vsc_f_main.h b/include/tbl/vsc_f_main.h index 51ddb4f..fc7d783 100644 --- a/include/tbl/vsc_f_main.h +++ b/include/tbl/vsc_f_main.h @@ -62,11 +62,6 @@ VSC_F(sess_fail, uint64_t, 1, 'c', 'i', info, " some resource like file descriptors." ) -VSC_F(sess_pipe_overflow, uint64_t, 1, 'c', 'i', info, - "Session pipe overflow", - "Count of sessions dropped due to the session pipe overflowing." -) - /*---------------------------------------------------------------------*/ VSC_F(client_req_400, uint64_t, 1, 'c', 'i', info, From phk at FreeBSD.org Mon Mar 16 20:20:24 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 21:20:24 +0100 Subject: [master] d9a700c Rewrite this slightly to avoid 16 "constant value boolean) warnings from FlexeLint. Message-ID: commit d9a700c2f9c9689e26ca6a0644eeae989d27a3c3 Author: Poul-Henning Kamp Date: Mon Mar 16 20:19:55 2015 +0000 Rewrite this slightly to avoid 16 "constant value boolean) warnings from FlexeLint. diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 3a478a3..0326036 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -309,22 +309,26 @@ SES_Wait(struct sess *sp) * assuming that the approximation of non-atomic global counters is sufficient. * if not: update to per-wrk */ + static void ses_close_acct(enum sess_close reason) { + int i = 0; + assert(reason != SC_NULL); switch (reason) { #define SESS_CLOSE(reason, stat, err, desc) \ case SC_ ## reason: \ VSC_C_main->sc_ ## stat++; \ - if (err) \ - VSC_C_main->sess_closed_err++; \ + i = err; \ break; #include "tbl/sess_close.h" #undef SESS_CLOSE default: WRONG("Wrong event in ses_close_acct"); } + if (i) + VSC_C_main->sess_closed_err++; } /*-------------------------------------------------------------------- From phk at FreeBSD.org Mon Mar 16 20:43:38 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 21:43:38 +0100 Subject: [master] 2673c16 A cast to tell Flexelint that we know what we're doing Message-ID: commit 2673c16a4b8aad5dd3b20dd0740d9ae917ab4520 Author: Poul-Henning Kamp Date: Mon Mar 16 20:26:09 2015 +0000 A cast to tell Flexelint that we know what we're doing diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index c8f92ea..a7daa8d 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -650,7 +650,7 @@ mgt_uptime(const struct vev *e, int what) (void)what; AN(VSC_C_mgt); VSC_C_mgt->uptime = static_VSC_C_mgt.uptime = - VTIM_real() - mgt_uptime_t0; + (uint64_t)(VTIM_real() - mgt_uptime_t0); if (heritage.vsm != NULL) VSM_common_ageupdate(heritage.vsm); return (0); From phk at FreeBSD.org Mon Mar 16 20:43:38 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 21:43:38 +0100 Subject: [master] 5c18588 Clip negative values before they do any damage. Message-ID: commit 5c185885b88b511db4f99e3f291985655d865202 Author: Poul-Henning Kamp Date: Mon Mar 16 20:42:44 2015 +0000 Clip negative values before they do any damage. diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c index 01f13e8..4777a5f 100644 --- a/lib/libvmod_std/vmod_std.c +++ b/lib/libvmod_std/vmod_std.c @@ -230,11 +230,14 @@ VCL_VOID __match_proto__(td_std_cache_req_body) vmod_cache_req_body(VRT_CTX, VCL_BYTES size) { int result; + ssize_t ss; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - result = VRT_CacheReqBody(ctx, size); - VSLb(ctx->vsl, SLT_Debug, "VRT_CacheReqBody(%zu): %d", - (size_t)size, result); + if (size < 0) + size = 0; + ss = (ssize_t)size; + result = VRT_CacheReqBody(ctx, ss); + VSLb(ctx->vsl, SLT_Debug, "VRT_CacheReqBody(%zd): %d", ss, result); } VCL_STRING __match_proto__(td_std_strstr) From phk at FreeBSD.org Mon Mar 16 20:43:38 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 21:43:38 +0100 Subject: [master] 4505710 Cast to annoy Flexelint a tiny bit less Message-ID: commit 4505710e80c59fb41e1c302592b3fa038746e111 Author: Poul-Henning Kamp Date: Mon Mar 16 20:43:00 2015 +0000 Cast to annoy Flexelint a tiny bit less diff --git a/bin/varnishd/common/common_vsm.c b/bin/varnishd/common/common_vsm.c index 94c3e3c..94d583d 100644 --- a/bin/varnishd/common/common_vsm.c +++ b/bin/varnishd/common/common_vsm.c @@ -388,5 +388,5 @@ VSM_common_ageupdate(const struct vsm_sc *sc) { CHECK_OBJ_NOTNULL(sc, VSM_SC_MAGIC); - sc->head->age = VTIM_mono() - sc->t0; + sc->head->age = (uint64_t)(VTIM_mono() - sc->t0); } From phk at FreeBSD.org Mon Mar 16 20:47:27 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 21:47:27 +0100 Subject: [master] 5bb3ee4 All transient files should go in tmpdir, not pwd Message-ID: commit 5bb3ee40af8a5b684b23704a0e31a439cab6280c Author: Poul-Henning Kamp Date: Mon Mar 16 20:45:38 2015 +0000 All transient files should go in tmpdir, not pwd diff --git a/bin/varnishtest/tests/c00053.vtc b/bin/varnishtest/tests/c00053.vtc index 76c9bd2..9b87fa1 100644 --- a/bin/varnishtest/tests/c00053.vtc +++ b/bin/varnishtest/tests/c00053.vtc @@ -1,14 +1,14 @@ -varnishtest "Test inclide vs. unsafe_path" +varnishtest "Test include vs. unsafe_path" server s1 { rxreq txresp -hdr "foo: bAr" -hdr "bar: fOo" -bodylen 4 } -start -shell "echo > ${pwd}/_.c00053" +shell "echo > ${tmpdir}/_.c00053" varnish v1 -vcl+backend { - include "${pwd}/_.c00053"; + include "${tmpdir}/_.c00053"; } varnish v1 -cliok "param.set vcc_unsafe_path off" @@ -17,13 +17,13 @@ varnish v1 -errvcl {Include path is unsafe} { backend default { .host = "${s1_sock}"; } - include "${pwd}/_.c00053"; + include "${tmpdir}/_.c00053"; } -varnish v1 -cliok "param.set vcl_dir ${pwd}" +varnish v1 -cliok "param.set vcl_dir ${tmpdir}" varnish v1 -vcl+backend { include "_.c00053"; } -shell "rm -f ${pwd}/_.c00053" +shell "rm -f ${tmpdir}/_.c00053" From phk at FreeBSD.org Mon Mar 16 20:58:18 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 21:58:18 +0100 Subject: [master] 92d5f76 More code coverage Message-ID: commit 92d5f769d5bae704a7a13c105e4b0a7ca3a33b17 Author: Poul-Henning Kamp Date: Mon Mar 16 20:56:07 2015 +0000 More code coverage diff --git a/bin/varnishtest/tests/v00038.vtc b/bin/varnishtest/tests/v00038.vtc index 7fb006d..39fde28 100644 --- a/bin/varnishtest/tests/v00038.vtc +++ b/bin/varnishtest/tests/v00038.vtc @@ -71,3 +71,18 @@ varnish v1 -errvcl "Expected '{' or name of probe, got" { .probe = "NONE"; } } + +varnish v1 -errvcl "Field 'port' redefined at:" { + backend b1 { + .host = "127.0.0.1"; + .port = "NONE"; + .port = "NONE"; + } +} + +varnish v1 -errvcl "Unknown field:" { + backend b1 { + .host = "127.0.0.1"; + .fourscoreandsevenyearsago = "NONE"; + } +} From phk at FreeBSD.org Mon Mar 16 20:58:18 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 16 Mar 2015 21:58:18 +0100 Subject: [master] 00e711c Even more code coverage Message-ID: commit 00e711c31254381fe1a0b4010eab0232d2be1913 Author: Poul-Henning Kamp Date: Mon Mar 16 20:57:45 2015 +0000 Even more code coverage diff --git a/bin/varnishtest/tests/v00038.vtc b/bin/varnishtest/tests/v00038.vtc index 39fde28..53ba0ea 100644 --- a/bin/varnishtest/tests/v00038.vtc +++ b/bin/varnishtest/tests/v00038.vtc @@ -86,3 +86,9 @@ varnish v1 -errvcl "Unknown field:" { .fourscoreandsevenyearsago = "NONE"; } } + +varnish v1 -errvcl "Mandatory field 'host' missing." { + backend b1 { + .port = "NONE"; + } +} From phk at FreeBSD.org Tue Mar 17 07:58:18 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 17 Mar 2015 08:58:18 +0100 Subject: [master] 0b46949 This cannot happen any more. Message-ID: commit 0b469498d4f0d8fc65ab6ae3f7e08d6655ae5b13 Author: Poul-Henning Kamp Date: Tue Mar 17 07:58:04 2015 +0000 This cannot happen any more. diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c index c358e13..8160092 100644 --- a/bin/varnishd/cache/cache_pool.c +++ b/bin/varnishd/cache/cache_pool.c @@ -213,12 +213,8 @@ pool_accept(struct worker *wrk, void *arg) while (1) { INIT_OBJ(wa, WRK_ACCEPT_MAGIC); - if (ps->lsock->sock < 0) { - /* Socket Shutdown */ - FREE_OBJ(ps); - WS_Release(wrk->aws, 0); - return; - } + assert(ps->lsock->sock > 0); // We know where stdin is + if (VCA_Accept(ps->lsock, wa) < 0) { wrk->stats->sess_fail++; /* We're going to pace in vca anyway... */ From phk at FreeBSD.org Tue Mar 17 08:24:35 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 17 Mar 2015 09:24:35 +0100 Subject: [master] 96f5732 Make worker threads able to call "next job". Message-ID: commit 96f5732ee2944af640a4d06a3ec91652f0bb4259 Author: Poul-Henning Kamp Date: Tue Mar 17 08:22:47 2015 +0000 Make worker threads able to call "next job". Use this to save a little bit of stack on common requests. Rename pool_func_t to task_func_t. Annotate the task functions with __match_proto__ diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 0406d9e..d176ef6 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -326,11 +326,11 @@ struct wrk_accept { /* Worker pool stuff -------------------------------------------------*/ -typedef void pool_func_t(struct worker *wrk, void *priv); +typedef void task_func_t(struct worker *wrk, void *priv); struct pool_task { VTAILQ_ENTRY(pool_task) list; - pool_func_t *func; + task_func_t *func; void *priv; }; @@ -1012,7 +1012,7 @@ void SES_DeletePool(struct sesspool *sp); int SES_ScheduleReq(struct req *); struct req *SES_GetReq(const struct worker *, struct sess *); void SES_ReleaseReq(struct req *); -pool_func_t SES_pool_accept_task; +task_func_t SES_pool_accept_task; /* cache_shmlog.c */ diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c index 71770b1..38703fe 100644 --- a/bin/varnishd/cache/cache_fetch.c +++ b/bin/varnishd/cache/cache_fetch.c @@ -875,7 +875,7 @@ vbf_stp_done(void) return (F_STP_DONE); } -static void +static void __match_proto__(task_func_t) vbf_fetch_thread(struct worker *wrk, void *priv) { struct busyobj *bo; diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c index 8160092..d1023f3 100644 --- a/bin/varnishd/cache/cache_pool.c +++ b/bin/varnishd/cache/cache_pool.c @@ -188,7 +188,7 @@ pool_getidleworker(struct pool *pp) * worker workspace. SES_pool_accept_task() knows about this. */ -static void +static void __match_proto__(task_func_t) pool_accept(struct worker *wrk, void *arg) { struct worker *wrk2; @@ -228,7 +228,8 @@ pool_accept(struct worker *wrk, void *arg) /* No idle threads, do it ourselves */ Lck_Unlock(&pp->mtx); AZ(Pool_Task(pp, &ps->task, POOL_QUEUE_BACK)); - SES_pool_accept_task(wrk, pp->sesspool); + wrk->task.func = SES_pool_accept_task; + wrk->task.priv = pp->sesspool; return; } VTAILQ_REMOVE(&pp->idle_queue, &wrk2->task, list); @@ -310,7 +311,7 @@ Pool_Task(struct pool *pp, struct pool_task *task, enum pool_how how) * Empty function used as a pointer value for the thread exit condition. */ -static void +static void __match_proto__(task_func_t) pool_kiss_of_death(struct worker *wrk, void *priv) { (void)wrk; @@ -321,7 +322,7 @@ pool_kiss_of_death(struct worker *wrk, void *priv) * Special function to summ stats */ -static void __match_proto__(pool_func_t) +static void __match_proto__(task_func_t) pool_stat_summ(struct worker *wrk, void *priv) { struct dstat *src; @@ -345,7 +346,7 @@ void Pool_Work_Thread(struct pool *pp, struct worker *wrk) { struct pool_task *tp; - struct pool_task tps; + struct pool_task tpx, tps; int i; CHECK_OBJ_NOTNULL(pp, POOL_MAGIC); @@ -394,7 +395,8 @@ Pool_Work_Thread(struct pool *pp, struct worker *wrk) if (i == ETIMEDOUT) VCL_Rel(&wrk->vcl); } while (wrk->task.func == NULL); - tp = &wrk->task; + tpx = wrk->task; + tp = &tpx; wrk->stats->summs++; } Lck_Unlock(&pp->mtx); @@ -402,8 +404,13 @@ Pool_Work_Thread(struct pool *pp, struct worker *wrk) if (tp->func == pool_kiss_of_death) break; - assert(wrk->pool == pp); - tp->func(wrk, tp->priv); + do { + memset(&wrk->task, 0, sizeof wrk->task); + assert(wrk->pool == pp); + tp->func(wrk, tp->priv); + tpx = wrk->task; + tp = &tpx; + } while (tp->func != NULL); /* cleanup for next task */ wrk->seen_methods = 0; @@ -588,10 +595,9 @@ pool_mkpool(unsigned pool_no) AZ(pthread_create(&pp->herder_thr, NULL, pool_herder, pp)); VTAILQ_FOREACH(ls, &heritage.socks, list) { - if (ls->sock < 0) - continue; + assert(ls->sock > 0); // We know where stdin is ALLOC_OBJ(ps, POOLSOCK_MAGIC); - XXXAN(ps); + AN(ps); ps->lsock = ls; ps->task.func = pool_accept; ps->task.priv = ps; diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 0326036..7542b0c 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -102,7 +102,7 @@ ses_new(struct sesspool *pp) * Process new/existing request on this session. */ -static void +static void __match_proto__(task_func_t) ses_req_pool_task(struct worker *wrk, void *arg) { struct req *req; @@ -125,7 +125,7 @@ ses_req_pool_task(struct worker *wrk, void *arg) * Allocate a request + vxid, call ses_req_pool_task() */ -static void +static void __match_proto__(task_func_t) ses_sess_pool_task(struct worker *wrk, void *arg) { struct req *req; @@ -138,7 +138,9 @@ ses_sess_pool_task(struct worker *wrk, void *arg) CHECK_OBJ_NOTNULL(req, REQ_MAGIC); sp->sess_step = S_STP_NEWREQ; - ses_req_pool_task(wrk, req); + + wrk->task.func = ses_req_pool_task; + wrk->task.priv = req; } /*-------------------------------------------------------------------- @@ -188,7 +190,7 @@ ses_vsl_socket(struct sess *sp, const char *lsockname) * Called from assigned worker thread */ -void +void __match_proto__(task_func_t) SES_pool_accept_task(struct worker *wrk, void *arg) { struct sesspool *pp; @@ -214,7 +216,8 @@ SES_pool_accept_task(struct worker *wrk, void *arg) lsockname = VCA_SetupSess(wrk, sp); ses_vsl_socket(sp, lsockname); - ses_sess_pool_task(wrk, sp); + wrk->task.func = ses_sess_pool_task; + wrk->task.priv = sp; } /*-------------------------------------------------------------------- From phk at FreeBSD.org Tue Mar 17 09:10:01 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 17 Mar 2015 10:10:01 +0100 Subject: [master] eff28c6 Generalize the "special" way we use to schedule accepted sockets onto a worker thread (falling back to the current (=acceptor) thread if the pool is empty. Message-ID: commit eff28c6dd923394a86ceb0429df6ed538028c9f3 Author: Poul-Henning Kamp Date: Tue Mar 17 09:09:20 2015 +0000 Generalize the "special" way we use to schedule accepted sockets onto a worker thread (falling back to the current (=acceptor) thread if the pool is empty. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index d176ef6..7317a74 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -322,6 +322,7 @@ struct wrk_accept { socklen_t acceptaddrlen; int acceptsock; struct listen_sock *acceptlsock; + struct sesspool *sesspool; }; /* Worker pool stuff -------------------------------------------------*/ diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c index d1023f3..689baf7 100644 --- a/bin/varnishd/cache/cache_pool.c +++ b/bin/varnishd/cache/cache_pool.c @@ -49,6 +49,7 @@ struct poolsock { #define POOLSOCK_MAGIC 0x1b0a2d38 struct listen_sock *lsock; struct pool_task task; + struct sesspool *sesspool; }; /* Number of work requests queued in excess of worker threads available */ @@ -178,6 +179,47 @@ pool_getidleworker(struct pool *pp) } /*-------------------------------------------------------------------- + * Special scheduling: If no thread can be found, the current thread + * will be prepared for rescheduling instead. + * The selected threads workspace is reserved and the argument put there. + * Return one if another thread was scheduled, otherwise zero. + */ + +static int +Pool_Task_Arg(struct worker *wrk, const void *arg, size_t arg_len) +{ + struct pool *pp; + struct worker *wrk2; + int retval; + + CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); + AN(arg); + AN(arg_len); + pp = wrk->pool; + CHECK_OBJ_NOTNULL(pp, POOL_MAGIC); + + Lck_Lock(&pp->mtx); + wrk2 = pool_getidleworker(pp); + if (wrk2 != NULL) { + VTAILQ_REMOVE(&pp->idle_queue, &wrk2->task, list); + retval = 1; + } else { + wrk2 = wrk; + retval = 0; + } + Lck_Unlock(&pp->mtx); + AZ(wrk2->task.func); + + assert(arg_len == WS_Reserve(wrk2->aws, arg_len)); + memcpy(wrk2->aws->f, arg, arg_len); + wrk2->task.func = SES_pool_accept_task; + wrk2->task.priv = wrk2->aws->f; + if (retval) + AZ(pthread_cond_signal(&wrk2->cond)); + return (retval); +} + +/*-------------------------------------------------------------------- * Nobody is accepting on this socket, so we do. * * As long as we can stick the accepted connection to another thread @@ -191,19 +233,13 @@ pool_getidleworker(struct pool *pp) static void __match_proto__(task_func_t) pool_accept(struct worker *wrk, void *arg) { - struct worker *wrk2; - struct wrk_accept *wa, *wa2; - struct pool *pp; + struct wrk_accept wa; struct poolsock *ps; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); - pp = wrk->pool; - CHECK_OBJ_NOTNULL(pp, POOL_MAGIC); CAST_OBJ_NOTNULL(ps, arg, POOLSOCK_MAGIC); CHECK_OBJ_NOTNULL(ps->lsock, LISTEN_SOCK_MAGIC); - assert(sizeof *wa == WS_Reserve(wrk->aws, sizeof *wa)); - wa = (void*)wrk->aws->f; /* Delay until we are ready (flag is set when all * initialization has finished) */ @@ -211,36 +247,22 @@ pool_accept(struct worker *wrk, void *arg) VTIM_sleep(.1); while (1) { - INIT_OBJ(wa, WRK_ACCEPT_MAGIC); + INIT_OBJ(&wa, WRK_ACCEPT_MAGIC); + wa.sesspool = ps->sesspool; assert(ps->lsock->sock > 0); // We know where stdin is - if (VCA_Accept(ps->lsock, wa) < 0) { + if (VCA_Accept(ps->lsock, &wa) < 0) { wrk->stats->sess_fail++; /* We're going to pace in vca anyway... */ (void)Pool_TrySumstat(wrk); continue; } - Lck_Lock(&pp->mtx); - wrk2 = pool_getidleworker(pp); - if (wrk2 == NULL) { - /* No idle threads, do it ourselves */ - Lck_Unlock(&pp->mtx); - AZ(Pool_Task(pp, &ps->task, POOL_QUEUE_BACK)); - wrk->task.func = SES_pool_accept_task; - wrk->task.priv = pp->sesspool; + if (!Pool_Task_Arg(wrk, &wa, sizeof wa)) { + AZ(Pool_Task(wrk->pool, &ps->task, POOL_QUEUE_BACK)); return; } - VTAILQ_REMOVE(&pp->idle_queue, &wrk2->task, list); - AZ(wrk2->task.func); - assert(sizeof *wa2 == WS_Reserve(wrk2->aws, sizeof *wa2)); - wa2 = (void*)wrk2->aws->f; - memcpy(wa2, wa, sizeof *wa); - wrk2->task.func = SES_pool_accept_task; - wrk2->task.priv = pp->sesspool; - Lck_Unlock(&pp->mtx); - AZ(pthread_cond_signal(&wrk2->cond)); /* * We were able to hand off, so release this threads VCL @@ -589,11 +611,12 @@ pool_mkpool(unsigned pool_no) VTAILQ_INIT(&pp->idle_queue); VTAILQ_INIT(&pp->front_queue); VTAILQ_INIT(&pp->back_queue); - pp->sesspool = SES_NewPool(pp, pool_no); - AN(pp->sesspool); AZ(pthread_cond_init(&pp->herder_cond, NULL)); AZ(pthread_create(&pp->herder_thr, NULL, pool_herder, pp)); + pp->sesspool = SES_NewPool(pp, pool_no); + AN(pp->sesspool); + VTAILQ_FOREACH(ls, &heritage.socks, list) { assert(ls->sock > 0); // We know where stdin is ALLOC_OBJ(ps, POOLSOCK_MAGIC); @@ -601,6 +624,7 @@ pool_mkpool(unsigned pool_no) ps->lsock = ls; ps->task.func = pool_accept; ps->task.priv = ps; + ps->sesspool = pp->sesspool; AZ(Pool_Task(pp, &ps->task, POOL_QUEUE_BACK)); } diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 7542b0c..56d760a 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -196,9 +196,11 @@ SES_pool_accept_task(struct worker *wrk, void *arg) struct sesspool *pp; struct sess *sp; const char *lsockname; + struct wrk_accept *wa; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); - CAST_OBJ_NOTNULL(pp, arg, SESSPOOL_MAGIC); + CAST_OBJ_NOTNULL(wa, arg, WRK_ACCEPT_MAGIC); + pp = wa->sesspool; /* Turn accepted socket into a session */ AN(wrk->aws->r); From phk at FreeBSD.org Tue Mar 17 09:50:22 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 17 Mar 2015 10:50:22 +0100 Subject: [master] 684467d Move all the acceptor related stuff out of cache_pool.c and into cache_acceptor.c where it belongs. Message-ID: commit 684467d905366baa6b68f8e071ced2ecbbe6f44c Author: Poul-Henning Kamp Date: Tue Mar 17 09:49:53 2015 +0000 Move all the acceptor related stuff out of cache_pool.c and into cache_acceptor.c where it belongs. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 7317a74..da5673e 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -704,9 +704,9 @@ struct sess { /* cache_acceptor.c */ void VCA_Init(void); void VCA_Shutdown(void); -int VCA_Accept(struct listen_sock *ls, struct wrk_accept *wa); const char *VCA_SetupSess(struct worker *w, struct sess *sp); void VCA_FailSess(struct worker *w); +void VCA_New_SessPool(struct pool *pp, struct sesspool *sp); /* cache_backend_cfg.c */ void VBE_InitCfg(void); @@ -987,10 +987,12 @@ const char *sess_close_2str(enum sess_close sc, int want_desc); /* cache_pool.c */ void Pool_Init(void); -void Pool_Accept(void); void Pool_Work_Thread(struct pool *, struct worker *w); int Pool_Task(struct pool *pp, struct pool_task *task, enum pool_how how); +int Pool_Task_Arg(struct worker *, task_func_t *, + const void *arg, size_t arg_len); void Pool_Sumstat(struct worker *w); +int Pool_TrySumstat(struct worker *wrk); void Pool_PurgeStat(unsigned nobj); #define V1L_IsReleased(w) ((w)->v1l == NULL) diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index b05c43f..05a1207 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -29,9 +29,6 @@ * This source file has the various trickery surrounding the accept/listen * sockets. * - * The actual acceptance is done from cache_pool.c, by calling - * into VCA_Accept() in this file. - * * Once the session is allocated we move into it with a call to * VCA_SetupSess(). * @@ -56,9 +53,17 @@ #include "vtim.h" static pthread_t VCA_thread; -static int hack_ready; static double vca_pace = 0.0; static struct lock pace_mtx; +static unsigned pool_accepting; + +struct poolsock { + unsigned magic; +#define POOLSOCK_MAGIC 0x1b0a2d38 + struct listen_sock *lsock; + struct pool_task task; + struct sesspool *sesspool; +}; /*-------------------------------------------------------------------- * TCP options we want to control @@ -269,49 +274,6 @@ vca_pace_good(void) } /*-------------------------------------------------------------------- - * Accept on a listen socket, and handle error returns. - * - * Called from a worker thread from a pool - */ - -int -VCA_Accept(struct listen_sock *ls, struct wrk_accept *wa) -{ - int i; - - CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC); - vca_pace_check(); - - while(!hack_ready) - (void)usleep(100*1000); - - wa->acceptaddrlen = sizeof wa->acceptaddr; - do { - i = accept(ls->sock, (void*)&wa->acceptaddr, - &wa->acceptaddrlen); - } while (i < 0 && errno == EAGAIN); - - if (i < 0) { - switch (errno) { - case ECONNABORTED: - break; - case EMFILE: - VSL(SLT_Debug, ls->sock, "Too many open files"); - vca_pace_bad(); - break; - default: - VSL(SLT_Debug, ls->sock, "Accept failed: %s", - strerror(errno)); - vca_pace_bad(); - break; - } - } - wa->acceptlsock = ls; - wa->acceptsock = i; - return (i); -} - -/*-------------------------------------------------------------------- * Fail a session * * This happens if we accept the socket, but cannot get a session @@ -365,6 +327,103 @@ VCA_SetupSess(struct worker *wrk, struct sess *sp) return (retval); } +/*-------------------------------------------------------------------- + * Nobody is accepting on this socket, so we do. + * + * As long as we can stick the accepted connection to another thread + * we do so, otherwise we put the socket back on the "BACK" queue + * and handle the new connection ourselves. + * + * We store data about the accept in reserved workspace on the reserved + * worker workspace. SES_pool_accept_task() knows about this. + */ + +static void __match_proto__(task_func_t) +vca_accept_task(struct worker *wrk, void *arg) +{ + struct wrk_accept wa; + struct poolsock *ps; + struct listen_sock *ls; + int i; + + CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); + CAST_OBJ_NOTNULL(ps, arg, POOLSOCK_MAGIC); + ls = ps->lsock; + CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC); + + /* Delay until we are ready (flag is set when all + * initialization has finished) */ + while (!pool_accepting) + VTIM_sleep(.1); + + while (1) { + INIT_OBJ(&wa, WRK_ACCEPT_MAGIC); + wa.sesspool = ps->sesspool; + wa.acceptlsock = ls; + + assert(ls->sock > 0); // We know where stdin is + + vca_pace_check(); + + wa.acceptaddrlen = sizeof wa.acceptaddr; + do { + i = accept(ls->sock, (void*)&wa.acceptaddr, + &wa.acceptaddrlen); + } while (i < 0 && errno == EAGAIN); + + if (i < 0) { + switch (errno) { + case ECONNABORTED: + break; + case EMFILE: + VSL(SLT_Debug, ls->sock, "Too many open files"); + vca_pace_bad(); + break; + default: + VSL(SLT_Debug, ls->sock, "Accept failed: %s", + strerror(errno)); + vca_pace_bad(); + break; + } + wrk->stats->sess_fail++; + (void)Pool_TrySumstat(wrk); + continue; + } + + wa.acceptsock = i; + + if (!Pool_Task_Arg(wrk, SES_pool_accept_task, &wa, sizeof wa)) { + AZ(Pool_Task(wrk->pool, &ps->task, POOL_QUEUE_BACK)); + return; + } + + /* + * We were able to hand off, so release this threads VCL + * reference (if any) so we don't hold on to discarded VCLs. + */ + if (wrk->vcl != NULL) + VCL_Rel(&wrk->vcl); + } +} + +void +VCA_New_SessPool(struct pool *pp, struct sesspool *sp) +{ + struct listen_sock *ls; + struct poolsock *ps; + + VTAILQ_FOREACH(ls, &heritage.socks, list) { + assert(ls->sock > 0); // We know where stdin is + ALLOC_OBJ(ps, POOLSOCK_MAGIC); + AN(ps); + ps->lsock = ls; + ps->task.func = vca_accept_task; + ps->task.priv = ps; + ps->sesspool = sp; + AZ(Pool_Task(pp, &ps->task, POOL_QUEUE_BACK)); + } +} + /*--------------------------------------------------------------------*/ static void * @@ -380,8 +439,7 @@ vca_acct(void *arg) (void)vca_tcp_opt_init(); VTAILQ_FOREACH(ls, &heritage.socks, list) { - if (ls->sock < 0) - continue; + assert (ls->sock > 0); // We know where stdin is AZ(listen(ls->sock, cache_param->listen_depth)); vca_tcp_opt_set(ls->sock, 1); if (cache_param->accept_filter) { @@ -393,18 +451,15 @@ vca_acct(void *arg) } } - hack_ready = 1; + pool_accepting = 1; need_test = 1; t0 = VTIM_real(); while (1) { (void)sleep(1); if (vca_tcp_opt_init()) { - VTAILQ_FOREACH(ls, &heritage.socks, list) { - if (ls->sock < 0) - continue; + VTAILQ_FOREACH(ls, &heritage.socks, list) vca_tcp_opt_set(ls->sock, 1); - } } now = VTIM_real(); VSC_C_main->uptime = (uint64_t)(now - t0); @@ -412,7 +467,6 @@ vca_acct(void *arg) NEEDLESS_RETURN(NULL); } - /*--------------------------------------------------------------------*/ static void @@ -444,7 +498,7 @@ ccf_listen_address(struct cli *cli, const char * const *av, void *priv) * a race where varnishtest::client would attempt to connect(2) * before listen(2) has been called. */ - while(!hack_ready) + while(!pool_accepting) (void)usleep(100*1000); VTAILQ_FOREACH(ls, &heritage.socks, list) { diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c index 1f2f48f..bfe99e3 100644 --- a/bin/varnishd/cache/cache_main.c +++ b/bin/varnishd/cache/cache_main.c @@ -245,8 +245,6 @@ child_main(void) if (FEATURE(FEATURE_WAIT_SILO)) SMP_Ready(); - Pool_Accept(); - CLI_Run(); BAN_Shutdown(); diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c index 689baf7..762685b 100644 --- a/bin/varnishd/cache/cache_pool.c +++ b/bin/varnishd/cache/cache_pool.c @@ -38,20 +38,11 @@ #include #include "cache.h" -#include "common/heritage.h" #include "vtim.h" VTAILQ_HEAD(taskhead, pool_task); -struct poolsock { - unsigned magic; -#define POOLSOCK_MAGIC 0x1b0a2d38 - struct listen_sock *lsock; - struct pool_task task; - struct sesspool *sesspool; -}; - /* Number of work requests queued in excess of worker threads available */ struct pool { @@ -78,7 +69,6 @@ struct pool { static struct lock pool_mtx; static pthread_t thr_pool_herder; -static unsigned pool_accepting = 0; static struct lock wstat_mtx; @@ -110,7 +100,7 @@ Pool_Sumstat(struct worker *wrk) memset(wrk->stats, 0, sizeof *wrk->stats); } -static int +int Pool_TrySumstat(struct worker *wrk) { if (Lck_Trylock(&wstat_mtx)) @@ -185,8 +175,9 @@ pool_getidleworker(struct pool *pp) * Return one if another thread was scheduled, otherwise zero. */ -static int -Pool_Task_Arg(struct worker *wrk, const void *arg, size_t arg_len) +int +Pool_Task_Arg(struct worker *wrk, task_func_t *func, + const void *arg, size_t arg_len) { struct pool *pp; struct worker *wrk2; @@ -212,7 +203,7 @@ Pool_Task_Arg(struct worker *wrk, const void *arg, size_t arg_len) assert(arg_len == WS_Reserve(wrk2->aws, arg_len)); memcpy(wrk2->aws->f, arg, arg_len); - wrk2->task.func = SES_pool_accept_task; + wrk2->task.func = func; wrk2->task.priv = wrk2->aws->f; if (retval) AZ(pthread_cond_signal(&wrk2->cond)); @@ -220,60 +211,6 @@ Pool_Task_Arg(struct worker *wrk, const void *arg, size_t arg_len) } /*-------------------------------------------------------------------- - * Nobody is accepting on this socket, so we do. - * - * As long as we can stick the accepted connection to another thread - * we do so, otherwise we put the socket back on the "BACK" queue - * and handle the new connection ourselves. - * - * We store data about the accept in reserved workspace on the reserved - * worker workspace. SES_pool_accept_task() knows about this. - */ - -static void __match_proto__(task_func_t) -pool_accept(struct worker *wrk, void *arg) -{ - struct wrk_accept wa; - struct poolsock *ps; - - CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); - CAST_OBJ_NOTNULL(ps, arg, POOLSOCK_MAGIC); - - CHECK_OBJ_NOTNULL(ps->lsock, LISTEN_SOCK_MAGIC); - - /* Delay until we are ready (flag is set when all - * initialization has finished) */ - while (!pool_accepting) - VTIM_sleep(.1); - - while (1) { - INIT_OBJ(&wa, WRK_ACCEPT_MAGIC); - wa.sesspool = ps->sesspool; - - assert(ps->lsock->sock > 0); // We know where stdin is - - if (VCA_Accept(ps->lsock, &wa) < 0) { - wrk->stats->sess_fail++; - /* We're going to pace in vca anyway... */ - (void)Pool_TrySumstat(wrk); - continue; - } - - if (!Pool_Task_Arg(wrk, &wa, sizeof wa)) { - AZ(Pool_Task(wrk->pool, &ps->task, POOL_QUEUE_BACK)); - return; - } - - /* - * We were able to hand off, so release this threads VCL - * reference (if any) so we don't hold on to discarded VCLs. - */ - if (wrk->vcl != NULL) - VCL_Rel(&wrk->vcl); - } -} - -/*-------------------------------------------------------------------- * Enter a new task to be done */ @@ -596,8 +533,6 @@ static struct pool * pool_mkpool(unsigned pool_no) { struct pool *pp; - struct listen_sock *ls; - struct poolsock *ps; ALLOC_OBJ(pp, POOL_MAGIC); if (pp == NULL) @@ -617,17 +552,6 @@ pool_mkpool(unsigned pool_no) pp->sesspool = SES_NewPool(pp, pool_no); AN(pp->sesspool); - VTAILQ_FOREACH(ls, &heritage.socks, list) { - assert(ls->sock > 0); // We know where stdin is - ALLOC_OBJ(ps, POOLSOCK_MAGIC); - AN(ps); - ps->lsock = ls; - ps->task.func = pool_accept; - ps->task.priv = ps; - ps->sesspool = pp->sesspool; - AZ(Pool_Task(pp, &ps->task, POOL_QUEUE_BACK)); - } - return (pp); } @@ -673,14 +597,6 @@ pool_poolherder(void *priv) /*--------------------------------------------------------------------*/ void -Pool_Accept(void) -{ - - ASSERT_CLI(); - pool_accepting = 1; -} - -void Pool_Init(void) { diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 56d760a..943e412 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -505,6 +505,8 @@ SES_NewPool(struct pool *wp, unsigned pool_no) pp->mpl_sess = MPL_New(nb, &cache_param->sess_pool, &cache_param->workspace_session); pp->http1_waiter = Wait_New(ses_handle, &cache_param->timeout_idle); + + VCA_New_SessPool(wp, pp); return (pp); } From lkarsten at varnish-software.com Tue Mar 17 10:18:07 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Tue, 17 Mar 2015 11:18:07 +0100 Subject: [3.0] 6b3a02f Avoid memory leak when adding bans. Message-ID: commit 6b3a02f274fa9ac413c06cd2e516117096e2ef1f Author: Lasse Karstensen Date: Tue Mar 17 11:05:33 2015 +0100 Avoid memory leak when adding bans. This is a backport of a88dbf913c7c264bb994f1fd5810e8a6ab27c3cc. diff --git a/bin/varnishd/cache_ban.c b/bin/varnishd/cache_ban.c index 4e4de57..ab7c0d9 100644 --- a/bin/varnishd/cache_ban.c +++ b/bin/varnishd/cache_ban.c @@ -294,6 +294,7 @@ ban_parse_regexp(struct cli *cli, const struct ban *b, const char *a3) rc = pcre_fullinfo(re, NULL, PCRE_INFO_SIZE, &sz); AZ(rc); ban_add_lump(b, re, sz); + pcre_free(re); return (0); } From phk at FreeBSD.org Tue Mar 17 10:19:28 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 17 Mar 2015 11:19:28 +0100 Subject: [master] 15ec79c Concentrate the acceptor-setup-session code. Message-ID: commit 15ec79cdd8b7e9c939b88364fa619c70840c184b Author: Poul-Henning Kamp Date: Tue Mar 17 10:19:10 2015 +0000 Concentrate the acceptor-setup-session code. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index da5673e..314e88c 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -311,20 +311,6 @@ struct vrt_privs { VTAILQ_HEAD(,vrt_priv) privs; }; -/*--------------------------------------------------------------------*/ - -struct wrk_accept { - unsigned magic; -#define WRK_ACCEPT_MAGIC 0x8c4b4d59 - - /* Accept stuff */ - struct sockaddr_storage acceptaddr; - socklen_t acceptaddrlen; - int acceptsock; - struct listen_sock *acceptlsock; - struct sesspool *sesspool; -}; - /* Worker pool stuff -------------------------------------------------*/ typedef void task_func_t(struct worker *wrk, void *priv); @@ -704,8 +690,6 @@ struct sess { /* cache_acceptor.c */ void VCA_Init(void); void VCA_Shutdown(void); -const char *VCA_SetupSess(struct worker *w, struct sess *sp); -void VCA_FailSess(struct worker *w); void VCA_New_SessPool(struct pool *pp, struct sesspool *sp); /* cache_backend_cfg.c */ @@ -1007,6 +991,7 @@ size_t V1L_Write(const struct worker *w, const void *ptr, ssize_t len); void VRG_dorange(struct req *req, struct busyobj *bo, const char *r); /* cache_session.c [SES] */ +struct sess *SES_New(struct sesspool *); void SES_Close(struct sess *sp, enum sess_close reason); void SES_Wait(struct sess *sp); void SES_Delete(struct sess *sp, enum sess_close reason, double now); @@ -1015,8 +1000,8 @@ void SES_DeletePool(struct sesspool *sp); int SES_ScheduleReq(struct req *); struct req *SES_GetReq(const struct worker *, struct sess *); void SES_ReleaseReq(struct req *); -task_func_t SES_pool_accept_task; - +void SES_vsl_socket(struct sess *sp, const char *lsockname); +void SES_sess_pool_task(struct worker *wrk, void *arg); /* cache_shmlog.c */ extern struct VSC_C_main *VSC_C_main; diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 05a1207..0b7d4aa 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -29,11 +29,6 @@ * This source file has the various trickery surrounding the accept/listen * sockets. * - * Once the session is allocated we move into it with a call to - * VCA_SetupSess(). - * - * If we fail to allocate a session we call VCA_FailSess() to clean up - * and initiate pacing. */ #include "config.h" @@ -57,6 +52,18 @@ static double vca_pace = 0.0; static struct lock pace_mtx; static unsigned pool_accepting; +struct wrk_accept { + unsigned magic; +#define WRK_ACCEPT_MAGIC 0x8c4b4d59 + + /* Accept stuff */ + struct sockaddr_storage acceptaddr; + socklen_t acceptaddrlen; + int acceptsock; + struct listen_sock *acceptlsock; + struct sesspool *sesspool; +}; + struct poolsock { unsigned magic; #define POOLSOCK_MAGIC 0x1b0a2d38 @@ -274,45 +281,48 @@ vca_pace_good(void) } /*-------------------------------------------------------------------- - * Fail a session + * The pool-task for a newly accepted session * - * This happens if we accept the socket, but cannot get a session - * structure. - * - * We consider this a DoS situation (false positive: Extremely popular - * busy objects) and silently close the connection with minimum effort - * and fuzz, rather than try to send an intelligent message back. + * Called from assigned worker thread */ -void -VCA_FailSess(struct worker *wrk) +static void __match_proto__(task_func_t) +vca_make_session(struct worker *wrk, void *arg) { + struct sesspool *pp; + struct sess *sp; + const char *lsockname; struct wrk_accept *wa; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); - CAST_OBJ_NOTNULL(wa, (void*)wrk->aws->f, WRK_ACCEPT_MAGIC); - AZ(close(wa->acceptsock)); - wrk->stats->sess_drop++; - vca_pace_bad(); - WS_Release(wrk->aws, 0); -} + CAST_OBJ_NOTNULL(wa, arg, WRK_ACCEPT_MAGIC); + pp = wa->sesspool; -/*-------------------------------------------------------------------- - * We have allocated a session, move our info into it. - */ + /* Turn accepted socket into a session */ + AN(wrk->aws->r); + sp = SES_New(pp); + if (sp == NULL) { + /* + * We consider this a DoS situation and silently close the + * connection with minimum effort and fuzz, rather than try + * to send an intelligent message back. + */ + AZ(close(wa->acceptsock)); + wrk->stats->sess_drop++; + vca_pace_bad(); + WS_Release(wrk->aws, 0); + return; + } + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + wrk->stats->s_sess++; -const char * -VCA_SetupSess(struct worker *wrk, struct sess *sp) -{ - struct wrk_accept *wa; - const char *retval; + sp->t_open = VTIM_real(); + sp->t_idle = sp->t_open; + sp->vxid = VXID_Get(wrk, VSL_CLIENTMARKER); - CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CAST_OBJ_NOTNULL(wa, (void*)wrk->aws->f, WRK_ACCEPT_MAGIC); sp->fd = wa->acceptsock; wa->acceptsock = -1; - retval = wa->acceptlsock->name; + lsockname = wa->acceptlsock->name; assert(wa->acceptaddrlen <= vsa_suckaddr_len); AN(VSA_Build(sess_remote_addr(sp), &wa->acceptaddr, wa->acceptaddrlen)); vca_pace_good(); @@ -324,18 +334,19 @@ VCA_SetupSess(struct worker *wrk, struct sess *sp) need_test = 0; } vca_tcp_opt_set(sp->fd, 0); - return (retval); + + SES_vsl_socket(sp, lsockname); + + wrk->task.func = SES_sess_pool_task; + wrk->task.priv = sp; } /*-------------------------------------------------------------------- - * Nobody is accepting on this socket, so we do. + * This function accepts on a single socket for a single session pool. * * As long as we can stick the accepted connection to another thread - * we do so, otherwise we put the socket back on the "BACK" queue + * we do so, otherwise we put the socket back on the "BACK" pool * and handle the new connection ourselves. - * - * We store data about the accept in reserved workspace on the reserved - * worker workspace. SES_pool_accept_task() knows about this. */ static void __match_proto__(task_func_t) @@ -361,8 +372,6 @@ vca_accept_task(struct worker *wrk, void *arg) wa.sesspool = ps->sesspool; wa.acceptlsock = ls; - assert(ls->sock > 0); // We know where stdin is - vca_pace_check(); wa.acceptaddrlen = sizeof wa.acceptaddr; @@ -392,7 +401,7 @@ vca_accept_task(struct worker *wrk, void *arg) wa.acceptsock = i; - if (!Pool_Task_Arg(wrk, SES_pool_accept_task, &wa, sizeof wa)) { + if (!Pool_Task_Arg(wrk, vca_make_session, &wa, sizeof wa)) { AZ(Pool_Task(wrk->pool, &ps->task, POOL_QUEUE_BACK)); return; } @@ -413,7 +422,6 @@ VCA_New_SessPool(struct pool *pp, struct sesspool *sp) struct poolsock *ps; VTAILQ_FOREACH(ls, &heritage.socks, list) { - assert(ls->sock > 0); // We know where stdin is ALLOC_OBJ(ps, POOLSOCK_MAGIC); AN(ps); ps->lsock = ls; @@ -451,9 +459,9 @@ vca_acct(void *arg) } } + need_test = 1; pool_accepting = 1; - need_test = 1; t0 = VTIM_real(); while (1) { (void)sleep(1); @@ -502,8 +510,6 @@ ccf_listen_address(struct cli *cli, const char * const *av, void *priv) (void)usleep(100*1000); VTAILQ_FOREACH(ls, &heritage.socks, list) { - if (ls->sock < 0) - continue; VTCP_myname(ls->sock, h, sizeof h, p, sizeof p); VCLI_Out(cli, "%s %s\n", h, p); } @@ -534,8 +540,6 @@ VCA_Shutdown(void) int i; VTAILQ_FOREACH(ls, &heritage.socks, list) { - if (ls->sock < 0) - continue; i = ls->sock; ls->sock = -1; (void)close(i); diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 1d2aa71..53d140c 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -589,7 +589,6 @@ cli_debug_sizeof(struct cli *cli, const char * const *av, void *priv) SZOF(struct http_conn); SZOF(struct acct_req); SZOF(struct worker); - SZOF(struct wrk_accept); SZOF(struct storage); SZOF(struct busyobj); SZOF(struct object); diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 943e412..6fd9a55 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -70,8 +70,8 @@ struct sesspool { * workspace */ -static struct sess * -ses_new(struct sesspool *pp) +struct sess * +SES_New(struct sesspool *pp) { struct sess *sp; unsigned sz; @@ -125,8 +125,8 @@ ses_req_pool_task(struct worker *wrk, void *arg) * Allocate a request + vxid, call ses_req_pool_task() */ -static void __match_proto__(task_func_t) -ses_sess_pool_task(struct worker *wrk, void *arg) +void __match_proto__(task_func_t) +SES_sess_pool_task(struct worker *wrk, void *arg) { struct req *req; struct sess *sp; @@ -153,8 +153,8 @@ ses_sess_pool_task(struct worker *wrk, void *arg) * */ -static void -ses_vsl_socket(struct sess *sp, const char *lsockname) +void +SES_vsl_socket(struct sess *sp, const char *lsockname) { struct sockaddr_storage ss; socklen_t sl; @@ -185,44 +185,6 @@ ses_vsl_socket(struct sess *sp, const char *lsockname) } /*-------------------------------------------------------------------- - * The pool-task for a newly accepted session - * - * Called from assigned worker thread - */ - -void __match_proto__(task_func_t) -SES_pool_accept_task(struct worker *wrk, void *arg) -{ - struct sesspool *pp; - struct sess *sp; - const char *lsockname; - struct wrk_accept *wa; - - CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); - CAST_OBJ_NOTNULL(wa, arg, WRK_ACCEPT_MAGIC); - pp = wa->sesspool; - - /* Turn accepted socket into a session */ - AN(wrk->aws->r); - sp = ses_new(pp); - if (sp == NULL) { - VCA_FailSess(wrk); - return; - } - wrk->stats->s_sess++; - - sp->t_open = VTIM_real(); - sp->t_idle = sp->t_open; - sp->vxid = VXID_Get(wrk, VSL_CLIENTMARKER); - - lsockname = VCA_SetupSess(wrk, sp); - ses_vsl_socket(sp, lsockname); - - wrk->task.func = ses_sess_pool_task; - wrk->task.priv = sp; -} - -/*-------------------------------------------------------------------- * Schedule a request back on a work-thread from its sessions pool * * This is used to reschedule requests waiting on busy objects @@ -271,7 +233,7 @@ ses_handle(struct waited *wp, enum wait_event ev, double now) pp = sp->sesspool; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); - sp->task.func = ses_sess_pool_task; + sp->task.func = SES_sess_pool_task; sp->task.priv = sp; if (Pool_Task(pp->pool, &sp->task, POOL_QUEUE_FRONT)) SES_Delete(sp, SC_OVERLOAD, now); From lkarsten at varnish-software.com Tue Mar 17 12:05:54 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Tue, 17 Mar 2015 13:05:54 +0100 Subject: [master] 5930380 Have the test case fail instead of time out. Message-ID: commit 5930380eb2c992e6038c684f3940bf124f505ced Author: Lasse Karstensen Date: Tue Mar 17 13:04:49 2015 +0100 Have the test case fail instead of time out. diff --git a/bin/varnishtest/tests/c00016.vtc b/bin/varnishtest/tests/c00016.vtc index 3e0b2be..0d285d9 100644 --- a/bin/varnishtest/tests/c00016.vtc +++ b/bin/varnishtest/tests/c00016.vtc @@ -25,7 +25,7 @@ client c1 { } -run client c1 { - txreq -hdr "foo: 1" -hdr "Age: 200" -hdr "Connection: Age" + txreq -url "/bar" -hdr "foo: 1" -hdr "Age: 200" -hdr "Connection: Age" rxresp expect resp.status == 400 } -run From lkarsten at varnish-software.com Tue Mar 17 12:07:11 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Tue, 17 Mar 2015 13:07:11 +0100 Subject: [master] 880bafc Correct timeout matching examples. Message-ID: commit 880bafc9a2823fc6c78a32e62cd7362008006ad1 Author: Lasse Karstensen Date: Tue Mar 17 13:06:43 2015 +0100 Correct timeout matching examples. diff --git a/doc/sphinx/reference/vsl-query.rst b/doc/sphinx/reference/vsl-query.rst index 244a284..11b40bd 100644 --- a/doc/sphinx/reference/vsl-query.rst +++ b/doc/sphinx/reference/vsl-query.rst @@ -222,10 +222,14 @@ QUERY EXPRESSION EXAMPLES not ReqHeader:cookie +* Client request where internal handling took more than 800ms.:: + + Timestamp:Process[2] > 0.8 + * Transaction group contains a request user-agent header that contains "iPod" and the request delivery time exceeds 1 second :: - ReqHeader:user-agent ~ "iPod" and ReqEnd[5] > 1. + ReqHeader:user-agent ~ "iPod" and Timestamp:Resp[2] > 1. * Transaction group contains a backend response status larger than or equal to 500 :: @@ -240,7 +244,7 @@ QUERY EXPRESSION EXAMPLES * Transactions that have had backend failures or long delivery time on their ESI subrequests. (Assumes request grouping mode). :: - BerespStatus >= 500 or {2+}ReqEnd[5] > 1. + BerespStatus >= 500 or {2+}Timestamp:Process[2] > 1. HISTORY ======= From phk at FreeBSD.org Tue Mar 17 12:56:50 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 17 Mar 2015 13:56:50 +0100 Subject: [master] 0bac500 Further compact the acceptor-session-creation code. Message-ID: commit 0bac50033599ecbb5efe1a6017732b33807cfd7e Author: Poul-Henning Kamp Date: Tue Mar 17 12:55:59 2015 +0000 Further compact the acceptor-session-creation code. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 314e88c..2e41149 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -1000,7 +1000,6 @@ void SES_DeletePool(struct sesspool *sp); int SES_ScheduleReq(struct req *); struct req *SES_GetReq(const struct worker *, struct sess *); void SES_ReleaseReq(struct req *); -void SES_vsl_socket(struct sess *sp, const char *lsockname); void SES_sess_pool_task(struct worker *wrk, void *arg); /* cache_shmlog.c */ diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 0b7d4aa..8bfda98 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -293,6 +293,11 @@ vca_make_session(struct worker *wrk, void *arg) struct sess *sp; const char *lsockname; struct wrk_accept *wa; + struct sockaddr_storage ss; + socklen_t sl; + char laddr[VTCP_ADDRBUFSIZE]; + char lport[VTCP_PORTBUFSIZE]; + CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(wa, arg, WRK_ACCEPT_MAGIC); @@ -323,6 +328,7 @@ vca_make_session(struct worker *wrk, void *arg) sp->fd = wa->acceptsock; wa->acceptsock = -1; lsockname = wa->acceptlsock->name; + AN(lsockname); assert(wa->acceptaddrlen <= vsa_suckaddr_len); AN(VSA_Build(sess_remote_addr(sp), &wa->acceptaddr, wa->acceptaddrlen)); vca_pace_good(); @@ -335,7 +341,24 @@ vca_make_session(struct worker *wrk, void *arg) } vca_tcp_opt_set(sp->fd, 0); - SES_vsl_socket(sp, lsockname); + AN(sp->addrs); + sl = sizeof ss; + AZ(getsockname(sp->fd, (void*)&ss, &sl)); + AN(VSA_Build(sess_local_addr(sp), &ss, sl)); + assert(VSA_Sane(sess_local_addr(sp))); + + VTCP_name(sess_remote_addr(sp), laddr, sizeof laddr, + lport, sizeof lport); + sp->client_addr_str = WS_Copy(sp->ws, laddr, -1); + AN(sp->client_addr_str); + sp->client_port_str = WS_Copy(sp->ws, lport, -1); + AN(sp->client_port_str); + VTCP_name(sess_local_addr(sp), laddr, sizeof laddr, + lport, sizeof lport); + VSL(SLT_Begin, sp->vxid, "sess 0 HTTP/1"); + VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s %.6f %d", + sp->client_addr_str, sp->client_port_str, lsockname, laddr, lport, + sp->t_open, sp->fd); wrk->task.func = SES_sess_pool_task; wrk->task.priv = sp; diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 6fd9a55..4a2e02f 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -47,7 +47,6 @@ #include "waiter/waiter.h" #include "vsa.h" -#include "vtcp.h" #include "vtim.h" /*--------------------------------------------------------------------*/ @@ -144,47 +143,6 @@ SES_sess_pool_task(struct worker *wrk, void *arg) } /*-------------------------------------------------------------------- - * VSL log the endpoints of the TCP connection. - * - * We use VSL() to get the sessions vxid and to make sure tha this - * VSL comes before anything else for this session. - * - * This is a separate procedure only to isolate the two stack buffers. - * - */ - -void -SES_vsl_socket(struct sess *sp, const char *lsockname) -{ - struct sockaddr_storage ss; - socklen_t sl; - char laddr[VTCP_ADDRBUFSIZE]; - char lport[VTCP_PORTBUFSIZE]; - - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - AN(lsockname); - - AN(sp->addrs); - sl = sizeof ss; - AZ(getsockname(sp->fd, (void*)&ss, &sl)); - AN(VSA_Build(sess_local_addr(sp), &ss, sl)); - assert(VSA_Sane(sess_local_addr(sp))); - - VTCP_name(sess_remote_addr(sp), laddr, sizeof laddr, - lport, sizeof lport); - sp->client_addr_str = WS_Copy(sp->ws, laddr, -1); - AN(sp->client_addr_str); - sp->client_port_str = WS_Copy(sp->ws, lport, -1); - AN(sp->client_port_str); - VTCP_name(sess_local_addr(sp), laddr, sizeof laddr, - lport, sizeof lport); - VSL(SLT_Begin, sp->vxid, "sess 0 HTTP/1"); - VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s %.6f %d", - sp->client_addr_str, sp->client_port_str, lsockname, laddr, lport, - sp->t_open, sp->fd); -} - -/*-------------------------------------------------------------------- * Schedule a request back on a work-thread from its sessions pool * * This is used to reschedule requests waiting on busy objects From martin at varnish-software.com Tue Mar 17 13:40:18 2015 From: martin at varnish-software.com (Martin Blix Grydeland) Date: Tue, 17 Mar 2015 14:40:18 +0100 Subject: [3.0] 3a99613 Be more consistent about per-hop/end-to-end headers. Message-ID: commit 3a99613fffc118e4295184d28c0cc509c2e249b1 Author: Martin Blix Grydeland Date: Tue Mar 17 14:39:42 2015 +0100 Be more consistent about per-hop/end-to-end headers. Conflicts: bin/varnishd/cache/cache_http.c bin/varnishd/http1/cache_http1_fsm.c Conflicts: bin/varnishd/cache/cache.h bin/varnishd/cache/cache_http.c bin/varnishd/cache/cache_http1_fsm.c include/tbl/sess_close.h diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h index be319df..f580c5a 100644 --- a/bin/varnishd/cache.h +++ b/bin/varnishd/cache.h @@ -773,7 +773,7 @@ int http_IsHdr(const txt *hh, const char *hdr); uint16_t http_DissectRequest(struct sess *sp); uint16_t http_DissectResponse(struct worker *w, const struct http_conn *htc, struct http *sp); -const char *http_DoConnection(const struct http *hp); +const char *http_DoConnection(struct http *hp, uint16_t *pstatus); void http_CopyHome(struct worker *w, int fd, const struct http *hp); void http_Unset(struct http *hp, const char *hdr); void http_CollectHdr(struct http *hp, const char *hdr); diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c index 22edb9b..969bf50 100644 --- a/bin/varnishd/cache_center.c +++ b/bin/varnishd/cache_center.c @@ -1517,7 +1517,14 @@ cnt_start(struct sess *sp) /* Catch original request, before modification */ HTTP_Copy(sp->http0, sp->http); - sp->doclose = http_DoConnection(sp->http); + sp->doclose = http_DoConnection(sp->http, &err_code); + if (err_code == 400) + (void)write(sp->fd, r_400, strlen(r_400)); + if (err_code != 0) { + sp->step = STP_DONE; + vca_close_session(sp, sp->doclose); + return (0); + } /* XXX: Handle TRACE & OPTIONS of Max-Forwards = 0 */ diff --git a/bin/varnishd/cache_http.c b/bin/varnishd/cache_http.c index 3680422..d180e79 100644 --- a/bin/varnishd/cache_http.c +++ b/bin/varnishd/cache_http.c @@ -413,12 +413,15 @@ http_GetHdrField(const struct http *hp, const char *hdr, */ const char * -http_DoConnection(const struct http *hp) +http_DoConnection(struct http *hp, uint16_t *p_err_code) { char *p, *q; const char *ret; unsigned u; + AN(p_err_code); + + http_CollectHdr(hp, H_Connection); if (!http_GetHdr(hp, H_Connection, &p)) { if (hp->protover < 11) return ("not HTTP/1.1"); @@ -437,6 +440,19 @@ http_DoConnection(const struct http *hp) u = pdiff(p, q); if (u == 5 && !strncasecmp(p, "close", u)) ret = "Connection: close"; + + /* Refuse removal of well-known-headers if they would pass. */ +/*lint -save -e506 */ +#define HTTPH(a,b,c,d,e,f,g) \ + if (!((e) & HTTPH_R_PASS) && \ + strlen(a) == u && !strncasecmp(a, p, u)) { \ + *p_err_code = 400; \ + return ("Bad request"); \ + } +#include "http_headers.h" +#undef HTTPH +/*lint -restore */ + u = http_findhdr(hp, u, p); if (u != 0) hp->hdf[u] |= HDF_FILTER; diff --git a/bin/varnishtest/tests/c00016.vtc b/bin/varnishtest/tests/c00016.vtc index 99e9c53..85f1b38 100644 --- a/bin/varnishtest/tests/c00016.vtc +++ b/bin/varnishtest/tests/c00016.vtc @@ -23,3 +23,9 @@ client c1 { rxresp expect req.http.Bar == } -run + +client c1 { + txreq -hdr "foo: 1" -hdr "Age: 200" -hdr "Connection: Age" + rxresp + expect resp.status == 400 +} -run From fgsch at lodoss.net Tue Mar 17 16:15:40 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 17 Mar 2015 17:15:40 +0100 Subject: [master] d92975c Add test for #1608 Message-ID: commit d92975ce999bb0af21a63c91a582fc48677650e9 Author: Federico G. Schwindt Date: Tue Mar 17 16:04:03 2015 +0000 Add test for #1608 We don't return 413/414 (yet?) but we have a specific counter for this now. Whether this is enough it's something we need to finalise. diff --git a/bin/varnishtest/tests/r01608.vtc b/bin/varnishtest/tests/r01608.vtc new file mode 100644 index 0000000..6486988 --- /dev/null +++ b/bin/varnishtest/tests/r01608.vtc @@ -0,0 +1,16 @@ +varnishtest "Increment counter if http_req_size is exhausted" + +server s1 { +} -start + +varnish v1 -arg "-p http_req_size=2048" -vcl+backend { +} -start + +client c1 { + send "GET /" + send_n 2048 "A" + send " HTTP/1.1\r\n\r\n" + expect_close +} -run + +varnish v1 -expect sc_rx_overflow == 1 From phk at FreeBSD.org Tue Mar 17 19:27:47 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 17 Mar 2015 20:27:47 +0100 Subject: [master] 56a073e Don't schedule req's using sess' task structure, that doesn't scale to parallism. Message-ID: commit 56a073e5b232b44664790e3069604ddb06557e47 Author: Poul-Henning Kamp Date: Tue Mar 17 19:27:17 2015 +0000 Don't schedule req's using sess' task structure, that doesn't scale to parallism. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 2e41149..1e43663 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -556,6 +556,7 @@ struct req { struct sess *sp; struct worker *wrk; + struct pool_task task; enum req_step req_step; VTAILQ_ENTRY(req) w_list; diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 4a2e02f..896f1b1 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -161,10 +161,10 @@ SES_ScheduleReq(struct req *req) CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); - sp->task.func = ses_req_pool_task; - sp->task.priv = req; + req->task.func = ses_req_pool_task; + req->task.priv = req; - return (Pool_Task(pp->pool, &sp->task, POOL_QUEUE_FRONT)); + return (Pool_Task(pp->pool, &req->task, POOL_QUEUE_FRONT)); } /*-------------------------------------------------------------------- From phk at FreeBSD.org Tue Mar 17 19:57:56 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 17 Mar 2015 20:57:56 +0100 Subject: [master] 606b6f0 But we can do without the struct pool_task in struct sess, because we can reserve the space on the workspace when needed. Message-ID: commit 606b6f0decf24276e88cdd395963dcd2caf34a40 Author: Poul-Henning Kamp Date: Tue Mar 17 19:57:18 2015 +0000 But we can do without the struct pool_task in struct sess, because we can reserve the space on the workspace when needed. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 1e43663..cceb572 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -657,7 +657,6 @@ struct sess { struct sesspool *sesspool; - struct pool_task task; struct waited waited; /* Session related fields ------------------------------------*/ diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 8bfda98..d382157 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -360,6 +360,8 @@ vca_make_session(struct worker *wrk, void *arg) sp->client_addr_str, sp->client_port_str, lsockname, laddr, lport, sp->t_open, sp->fd); + /* SES_sess_pool_task() must be sceduled with reserved WS */ + assert(8 == WS_Reserve(sp->ws, 8)); wrk->task.func = SES_sess_pool_task; wrk->task.priv = sp; } diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 896f1b1..724c9e1 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -132,6 +132,7 @@ SES_sess_pool_task(struct worker *wrk, void *arg) CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC); + WS_Release(sp->ws, 0); req = SES_GetReq(wrk, sp); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); @@ -176,10 +177,13 @@ ses_handle(struct waited *wp, enum wait_event ev, double now) { struct sess *sp; struct sesspool *pp; + struct pool_task *tp; CHECK_OBJ_NOTNULL(wp, WAITED_MAGIC); CAST_OBJ_NOTNULL(sp, wp->ptr, SESS_MAGIC); + AZ(sp->ws->r); + switch (ev) { case WAITER_TIMEOUT: SES_Delete(sp, SC_RX_TIMEOUT, now); @@ -191,9 +195,11 @@ ses_handle(struct waited *wp, enum wait_event ev, double now) pp = sp->sesspool; CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); - sp->task.func = SES_sess_pool_task; - sp->task.priv = sp; - if (Pool_Task(pp->pool, &sp->task, POOL_QUEUE_FRONT)) + assert(sizeof *tp == WS_Reserve(sp->ws, sizeof *tp)); + tp = (void*)sp->ws->f; + tp->func = SES_sess_pool_task; + tp->priv = sp; + if (Pool_Task(pp->pool, tp, POOL_QUEUE_FRONT)) SES_Delete(sp, SC_OVERLOAD, now); break; case WAITER_CLOSE: From phk at FreeBSD.org Tue Mar 17 20:21:12 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 17 Mar 2015 21:21:12 +0100 Subject: [master] d2ddc9a Minor polish Message-ID: commit d2ddc9a47e6a8ef56f37b818feee0ccf96e23f08 Author: Poul-Henning Kamp Date: Tue Mar 17 20:13:58 2015 +0000 Minor polish diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index d382157..2da2b10 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -298,7 +298,6 @@ vca_make_session(struct worker *wrk, void *arg) char laddr[VTCP_ADDRBUFSIZE]; char lport[VTCP_PORTBUFSIZE]; - CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(wa, arg, WRK_ACCEPT_MAGIC); pp = wa->sesspool; @@ -387,8 +386,6 @@ vca_accept_task(struct worker *wrk, void *arg) ls = ps->lsock; CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC); - /* Delay until we are ready (flag is set when all - * initialization has finished) */ while (!pool_accepting) VTIM_sleep(.1); @@ -427,6 +424,12 @@ vca_accept_task(struct worker *wrk, void *arg) wa.acceptsock = i; if (!Pool_Task_Arg(wrk, vca_make_session, &wa, sizeof wa)) { + /* + * We couldn't get another thread, so we will handle + * the request in this worker thread, but first we + * must reschedule the listening task so it will be + * taken up by another thread again. + */ AZ(Pool_Task(wrk->pool, &ps->task, POOL_QUEUE_BACK)); return; } @@ -440,6 +443,11 @@ vca_accept_task(struct worker *wrk, void *arg) } } +/*-------------------------------------------------------------------- + * Called when a worker and attached session pool is created, to + * allocate the tasks which will listen to sockets for that pool. + */ + void VCA_New_SessPool(struct pool *pp, struct sesspool *sp) { @@ -532,7 +540,7 @@ ccf_listen_address(struct cli *cli, const char * const *av, void *priv) * before listen(2) has been called. */ while(!pool_accepting) - (void)usleep(100*1000); + VTIM_sleep(.1); VTAILQ_FOREACH(ls, &heritage.socks, list) { VTCP_myname(ls->sock, h, sizeof h, p, sizeof p); diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 724c9e1..0d34de7 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -443,5 +443,7 @@ SES_DeletePool(struct sesspool *pp) CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); MPL_Destroy(&pp->mpl_sess); MPL_Destroy(&pp->mpl_req); + /* Delete session pool must stop acceptor threads */ + INCOMPL(); FREE_OBJ(pp); } From phk at FreeBSD.org Wed Mar 18 08:12:21 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 09:12:21 +0100 Subject: [master] 6cbbff0 Remove the debug.sizeof CLI hack. Message-ID: commit 6cbbff0ee6b9b67cba81d91fcae082fd14582799 Author: Poul-Henning Kamp Date: Wed Mar 18 08:11:33 2015 +0000 Remove the debug.sizeof CLI hack. Instead one can start gdb on the compiled binary and ask it: print sizeof(struct sess) $1 = 192 diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 53d140c..461bbb9 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -35,14 +35,11 @@ #include #endif -#include // offsetof() #include #include #include "cache.h" #include "cache_filter.h" -#include "hash/hash_slinger.h" // struct objhead -#include "vend.h" #include "common/heritage.h" #include "cache_backend.h" @@ -50,7 +47,6 @@ #include "vcl.h" #include "vcli_priv.h" #include "waiter/waiter.h" -#include "vsa.h" /* * The panic string is constructed in memory, then copied to the @@ -577,74 +573,6 @@ pan_ic(const char *func, const char *file, int line, const char *cond, /*--------------------------------------------------------------------*/ static void __match_proto__(cli_func_t) -cli_debug_sizeof(struct cli *cli, const char * const *av, void *priv) -{ - (void)av; - AZ(priv); - -#define SZOF(foo) VCLI_Out(cli, \ - "sizeof(%s) = %zd = 0x%zx\n", #foo, sizeof(foo), sizeof(foo)) - SZOF(struct ws); - SZOF(struct http); - SZOF(struct http_conn); - SZOF(struct acct_req); - SZOF(struct worker); - SZOF(struct storage); - SZOF(struct busyobj); - SZOF(struct object); - SZOF(struct objcore); - SZOF(struct objhead); - SZOF(struct sess); - SZOF(struct req); - SZOF(struct vbc); - SZOF(struct VSC_C_main); - SZOF(struct lock); - SZOF(struct dstat); - VCLI_Out(cli, "sizeof(struct suckaddr) = %d = 0x%x\n", - vsa_suckaddr_len, vsa_suckaddr_len); -#if 0 -#define OFOF(foo, bar) { foo __foo; VCLI_Out(cli, \ - "%-30s = 0x%4zx @ 0x%4zx\n", \ - #foo "." #bar, sizeof(__foo.bar), offsetof(foo, bar)); } -#if 0 - OFOF(struct objhead, magic); - OFOF(struct objhead, refcnt); - OFOF(struct objhead, mtx); - OFOF(struct objhead, objcs); - OFOF(struct objhead, digest); - OFOF(struct objhead, waitinglist); - OFOF(struct objhead, _u); -#endif -#if 0 - OFOF(struct http, magic); - OFOF(struct http, logtag); - OFOF(struct http, ws); - OFOF(struct http, hd); - OFOF(struct http, hdf); - OFOF(struct http, shd); - OFOF(struct http, nhd); - OFOF(struct http, status); - OFOF(struct http, protover); - OFOF(struct http, conds); -#endif -#if 0 - OFOF(struct storage, magic); - OFOF(struct storage, fd); - OFOF(struct storage, where); - OFOF(struct storage, list); - OFOF(struct storage, stevedore); - OFOF(struct storage, priv); - OFOF(struct storage, ptr); - OFOF(struct storage, len); - OFOF(struct storage, space); -#endif -#undef OFOF -#endif -} - -/*--------------------------------------------------------------------*/ - -static void __match_proto__(cli_func_t) ccf_panic(struct cli *cli, const char * const *av, void *priv) { @@ -657,9 +585,6 @@ ccf_panic(struct cli *cli, const char * const *av, void *priv) /*--------------------------------------------------------------------*/ static struct cli_proto debug_cmds[] = { - { "debug.sizeof", "debug.sizeof", - "\tDump sizeof various data structures.", - 0, 0, "d", cli_debug_sizeof }, { "debug.panic.worker", "debug.panic.worker", "\tPanic the worker process.", 0, 0, "d", ccf_panic }, From phk at FreeBSD.org Wed Mar 18 08:18:27 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 09:18:27 +0100 Subject: [master] 9a96a8f Remember to remove debug.sizeof here also Message-ID: commit 9a96a8fd42867cc3b574ca329cbd8b27228d2588 Author: Poul-Henning Kamp Date: Wed Mar 18 08:18:14 2015 +0000 Remember to remove debug.sizeof here also diff --git a/bin/varnishtest/tests/b00032.vtc b/bin/varnishtest/tests/b00032.vtc index 55ece76..a36634f 100644 --- a/bin/varnishtest/tests/b00032.vtc +++ b/bin/varnishtest/tests/b00032.vtc @@ -14,8 +14,6 @@ varnish v1 -cliok vcl.list varnish v1 -cliok start -varnish v1 -cliok debug.sizeof - varnish v1 -cliok "vcl.use vcl1" varnish v1 -clierr 106 "vcl.discard vcl1" From phk at FreeBSD.org Wed Mar 18 09:34:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 10:34:48 +0100 Subject: [master] 7066708 Introduce session attributes which we store as a 16 bit index into the session workspace to compress struct sess. Message-ID: commit 706670821741cbc552539cd511b5d25122ff3ae1 Author: Poul-Henning Kamp Date: Wed Mar 18 09:34:04 2015 +0000 Introduce session attributes which we store as a 16 bit index into the session workspace to compress struct sess. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index cceb572..e68a117 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -119,6 +119,7 @@ struct poolparam; struct req; struct sess; struct sesspool; +struct suckaddr; struct vbc; struct vrt_backend; struct vrt_priv; @@ -643,6 +644,14 @@ struct req { * works, is not realistic without a lot of code changes. */ + +enum sess_attr { +#define SESS_ATTR(UP, low, typ, len) SA_##UP, +#include "tbl/sess_attr.h" +#undef SESS_ATTR + SA_LAST +}; + struct sess { unsigned magic; #define SESS_MAGIC 0x2c2f9c5a @@ -663,15 +672,7 @@ struct sess { struct ws ws[1]; - /* - * This gets quite involved, but we don't want to waste space - * on up to 4 pointers of 8 bytes in struct sess. - */ - char *addrs; -#define sess_remote_addr(sp) \ - ((struct suckaddr *)(void*)((sp)->addrs)) -#define sess_local_addr(sp) \ - ((struct suckaddr *)(void*)((sp)->addrs + vsa_suckaddr_len)) + uint16_t sattr[SA_LAST]; /* formatted ascii client address */ char *client_addr_str; @@ -1002,6 +1003,12 @@ struct req *SES_GetReq(const struct worker *, struct sess *); void SES_ReleaseReq(struct req *); void SES_sess_pool_task(struct worker *wrk, void *arg); +#define SESS_ATTR(UP, low, typ, len) \ + int SES_Get_##low(const struct sess *sp, typ *dst); \ + void SES_Reserve_##low(struct sess *sp, typ *dst); +#include "tbl/sess_attr.h" +#undef SESS_ATTR + /* cache_shmlog.c */ extern struct VSC_C_main *VSC_C_main; void VSM_Init(void); diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 2da2b10..1408d1f 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -291,9 +291,9 @@ vca_make_session(struct worker *wrk, void *arg) { struct sesspool *pp; struct sess *sp; - const char *lsockname; struct wrk_accept *wa; struct sockaddr_storage ss; + struct suckaddr *sa; socklen_t sl; char laddr[VTCP_ADDRBUFSIZE]; char lport[VTCP_PORTBUFSIZE]; @@ -326,39 +326,44 @@ vca_make_session(struct worker *wrk, void *arg) sp->fd = wa->acceptsock; wa->acceptsock = -1; - lsockname = wa->acceptlsock->name; - AN(lsockname); - assert(wa->acceptaddrlen <= vsa_suckaddr_len); - AN(VSA_Build(sess_remote_addr(sp), &wa->acceptaddr, wa->acceptaddrlen)); - vca_pace_good(); - wrk->stats->sess_conn++; - WS_Release(wrk->aws, 0); - - if (need_test) { - vca_tcp_opt_test(sp->fd); - need_test = 0; - } - vca_tcp_opt_set(sp->fd, 0); - AN(sp->addrs); - sl = sizeof ss; - AZ(getsockname(sp->fd, (void*)&ss, &sl)); - AN(VSA_Build(sess_local_addr(sp), &ss, sl)); - assert(VSA_Sane(sess_local_addr(sp))); + assert(wa->acceptaddrlen <= vsa_suckaddr_len); + SES_Reserve_remote_addr(sp, &sa); + AN(VSA_Build(sa, &wa->acceptaddr, wa->acceptaddrlen)); + SES_Reserve_client_addr(sp, &sa); + AN(VSA_Build(sa, &wa->acceptaddr, wa->acceptaddrlen)); - VTCP_name(sess_remote_addr(sp), laddr, sizeof laddr, - lport, sizeof lport); + VTCP_name(sa, laddr, sizeof laddr, lport, sizeof lport); sp->client_addr_str = WS_Copy(sp->ws, laddr, -1); AN(sp->client_addr_str); sp->client_port_str = WS_Copy(sp->ws, lport, -1); AN(sp->client_port_str); - VTCP_name(sess_local_addr(sp), laddr, sizeof laddr, - lport, sizeof lport); + + sl = sizeof ss; + AZ(getsockname(sp->fd, (void*)&ss, &sl)); + SES_Reserve_local_addr(sp, &sa); + AN(VSA_Build(sa, &ss, sl)); + SES_Reserve_server_addr(sp, &sa); + AN(VSA_Build(sa, &ss, sl)); + + VTCP_name(sa, laddr, sizeof laddr, lport, sizeof lport); + VSL(SLT_Begin, sp->vxid, "sess 0 HTTP/1"); VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s %.6f %d", - sp->client_addr_str, sp->client_port_str, lsockname, laddr, lport, + sp->client_addr_str, sp->client_port_str, + wa->acceptlsock->name, laddr, lport, sp->t_open, sp->fd); + WS_Release(wrk->aws, 0); + + vca_pace_good(); + wrk->stats->sess_conn++; + + if (need_test) { + vca_tcp_opt_test(sp->fd); + need_test = 0; + } + vca_tcp_opt_set(sp->fd, 0); /* SES_sess_pool_task() must be sceduled with reserved WS */ assert(8 == WS_Reserve(sp->ws, 8)); wrk->task.func = SES_sess_pool_task; diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 0d34de7..9139c72 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -61,6 +61,58 @@ struct sesspool { struct waiter *http1_waiter; }; +/*--------------------------------------------------------------------*/ + +static int +ses_get_attr(const struct sess *sp, enum sess_attr a, void **dst) +{ + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + assert(a < SA_LAST); + AN(dst); + + if (sp->sattr[a] == 0xffff) { + *dst = NULL; + return (-1); + } else { + *dst = sp->ws->s + sp->sattr[a]; + return (0); + } +} + +static void +ses_reserve_attr(struct sess *sp, enum sess_attr a, void **dst, int sz) +{ + ssize_t o; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + assert(a < SA_LAST); + assert(sz >= 0); + AN(dst); + o = WS_Reserve(sp->ws, sz); + assert(o >= sz); + *dst = sp->ws->f; + o = sp->ws->f - sp->ws->s; + WS_Release(sp->ws, sz); + assert(o >= 0 && o <= 0xffff); + sp->sattr[a] = (uint16_t)o; +} + +#define SESS_ATTR(UP, low, typ, len) \ + int \ + SES_Get_##low(const struct sess *sp, typ *dst) \ + { \ + return (ses_get_attr(sp, SA_##UP, (void**)dst)); \ + } \ + \ + void \ + SES_Reserve_##low(struct sess *sp, typ *dst) \ + { \ + ses_reserve_attr(sp, SA_##UP, (void*)dst, len); \ + } + +#include "tbl/sess_attr.h" +#undef SESS_ATTR + /*-------------------------------------------------------------------- * Get a new session, preferably by recycling an already ready one * @@ -80,14 +132,13 @@ SES_New(struct sesspool *pp) sp = MPL_Get(pp->mpl_sess, &sz); sp->magic = SESS_MAGIC; sp->sesspool = pp; + memset(sp->sattr, 0xff, sizeof sp->sattr); e = (char*)sp + sz; p = (char*)(sp + 1); p = (void*)PRNDUP(p); assert(p < e); WS_Init(sp->ws, "ses", p, e - p); - sp->addrs = WS_Alloc(sp->ws, vsa_suckaddr_len * 2); - AN(sp->addrs); sp->t_open = NAN; sp->t_idle = NAN; @@ -444,6 +495,6 @@ SES_DeletePool(struct sesspool *pp) MPL_Destroy(&pp->mpl_sess); MPL_Destroy(&pp->mpl_req); /* Delete session pool must stop acceptor threads */ - INCOMPL(); FREE_OBJ(pp); + INCOMPL(); } diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index a53c07a..a9c30ee 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -37,7 +37,6 @@ #include "cache_director.h" #include "vrt.h" #include "vrt_obj.h" -#include "vsa.h" static char vrt_hostname[255] = ""; @@ -598,21 +597,25 @@ VRT_r_req_##field(VRT_CTX) \ VCL_IP VRT_r_client_ip(VRT_CTX) { + struct suckaddr *sa; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC); - return (sess_remote_addr(ctx->req->sp)); + AZ(SES_Get_remote_addr(ctx->req->sp, &sa)); + return (sa); } VCL_IP VRT_r_server_ip(VRT_CTX) { + struct suckaddr *sa; CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC); - return (sess_local_addr(ctx->req->sp)); + AZ(SES_Get_local_addr(ctx->req->sp, &sa)); + return (sa); } const char* diff --git a/include/Makefile.am b/include/Makefile.am index 603a085..1f116b6 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -16,6 +16,7 @@ nobase_pkginclude_HEADERS = \ tbl/obj_attr.h \ tbl/req_body.h \ tbl/req_flags.h \ + tbl/sess_attr.h \ tbl/sess_close.h \ tbl/steps.h \ tbl/symbol_kind.h \ diff --git a/include/tbl/sess_attr.h b/include/tbl/sess_attr.h new file mode 100644 index 0000000..db68fb6 --- /dev/null +++ b/include/tbl/sess_attr.h @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2015 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Session attributes should be stored as cheaply as possible in terms of + * memory. This stuff implements "small pointers", 16 bit offsets into + * the session workspace, for these bits. + */ + +/*lint -save -e525 -e539 */ + +// upper lower type len +SESS_ATTR(REMOTE_ADDR, remote_addr, struct suckaddr *, vsa_suckaddr_len) +SESS_ATTR(LOCAL_ADDR, local_addr, struct suckaddr *, vsa_suckaddr_len) +SESS_ATTR(CLIENT_ADDR, client_addr, struct suckaddr *, vsa_suckaddr_len) +SESS_ATTR(SERVER_ADDR, server_addr, struct suckaddr *, vsa_suckaddr_len) + +/*lint -restore */ From lkarsten at varnish-software.com Wed Mar 18 10:22:24 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Wed, 18 Mar 2015 11:22:24 +0100 Subject: [3.0] 2faf850 Prepare 3.0.7-rc1. Message-ID: commit 2faf850ad83f3389197d4e9e701a559316150abb Author: Lasse Karstensen Date: Wed Mar 18 11:22:01 2015 +0100 Prepare 3.0.7-rc1. diff --git a/LICENSE b/LICENSE index 67dc00a..dd1d14b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,5 @@ Copyright (c) 2006 Verdens Gang AS -Copyright (c) 2006-2014 Varnish Software AS +Copyright (c) 2006-2015 Varnish Software AS All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/configure.ac b/configure.ac index 3ad3f53..e2eb271 100644 --- a/configure.ac +++ b/configure.ac @@ -1,8 +1,8 @@ AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2006 Verdens Gang AS -Copyright (c) 2006-2014 Varnish Software AS]) +Copyright (c) 2006-2015 Varnish Software AS]) AC_REVISION([$Id$]) -AC_INIT([Varnish], [3.0.6], [varnish-dev at varnish-cache.org]) +AC_INIT([Varnish], [3.0.7-rc1], [varnish-dev at varnish-cache.org]) AC_CONFIG_SRCDIR(include/varnishapi.h) AM_CONFIG_HEADER(config.h) diff --git a/doc/changes.rst b/doc/changes.rst index e482183..fa57fb9 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -1,3 +1,28 @@ +============================================ +Changes from 3.0.6 to 3.0.7-rc1 (2015-03-18) +============================================ + +- Requests with multiple Content-Length headers will now fail. + +- Stop recognizing a single CR (\r) as a HTTP line separator. +This opened up a possible cache poisioning attack in stacked installations +where sslterminator/varnish/backend had different CR handling. + +- Improved error detection on master-child process communication, leading to +faster recovery (child restart) if communication looses sync. + +- Only emit passed Content_Length header when response mode is RES_LEN. Bug 1627_. + +- More robust handling of hop-by-hop headers. + +- [packaging] Coherent Redhat pidfile in init script. Bug 1690_. + +- Avoid memory leak when adding bans. + +.. _1627: http://varnish-cache.org/trac/ticket/1627 +.. _1690: http://varnish-cache.org/trac/ticket/1690 + + =========================================== Changes from 3.0.6rc1 to 3.0.6 (2014-10-16) =========================================== diff --git a/redhat/varnish.spec b/redhat/varnish.spec index 72d12be..e56a16c 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -1,9 +1,10 @@ +%define v_rc rc1 %define _use_internal_dependency_generator 0 %define __find_provides %{_builddir}/varnish-%{version}%{?v_rc:-%{?v_rc}}/redhat/find-provides Summary: High-performance HTTP accelerator Name: varnish -Version: 3.0.6 -Release: 1%{?dist} +Version: 3.0.7 +Release: 1%{?v_rc}%{?dist} License: BSD Group: System Environment/Daemons URL: https://www.varnish-cache.org/ From phk at FreeBSD.org Wed Mar 18 10:54:08 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 11:54:08 +0100 Subject: [master] e2da0a8 Move the string formattet client (really: remote) addresses to the new sess_attr facility Message-ID: commit e2da0a8ca1a3324e585fb38f88db4bcb4875ae2e Author: Poul-Henning Kamp Date: Wed Mar 18 10:50:59 2015 +0000 Move the string formattet client (really: remote) addresses to the new sess_attr facility diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index e68a117..1da6f63 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -674,10 +674,6 @@ struct sess { uint16_t sattr[SA_LAST]; - /* formatted ascii client address */ - char *client_addr_str; - char *client_port_str; - /* Timestamps, all on TIM_real() timescale */ double t_open; /* fd accepted */ double t_idle; /* fd accepted or resp sent */ @@ -1008,6 +1004,8 @@ void SES_sess_pool_task(struct worker *wrk, void *arg); void SES_Reserve_##low(struct sess *sp, typ *dst); #include "tbl/sess_attr.h" #undef SESS_ATTR +void SES_Set_String_Attr(struct sess *sp, enum sess_attr a, const char *src); +const char *SES_Get_String_Attr(const struct sess *sp, enum sess_attr a); /* cache_shmlog.c */ extern struct VSC_C_main *VSC_C_main; diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 1408d1f..62d8ad1 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -297,6 +297,8 @@ vca_make_session(struct worker *wrk, void *arg) socklen_t sl; char laddr[VTCP_ADDRBUFSIZE]; char lport[VTCP_PORTBUFSIZE]; + char raddr[VTCP_ADDRBUFSIZE]; + char rport[VTCP_PORTBUFSIZE]; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(wa, arg, WRK_ACCEPT_MAGIC); @@ -333,11 +335,9 @@ vca_make_session(struct worker *wrk, void *arg) SES_Reserve_client_addr(sp, &sa); AN(VSA_Build(sa, &wa->acceptaddr, wa->acceptaddrlen)); - VTCP_name(sa, laddr, sizeof laddr, lport, sizeof lport); - sp->client_addr_str = WS_Copy(sp->ws, laddr, -1); - AN(sp->client_addr_str); - sp->client_port_str = WS_Copy(sp->ws, lport, -1); - AN(sp->client_port_str); + VTCP_name(sa, raddr, sizeof raddr, rport, sizeof rport); + SES_Set_String_Attr(sp, SA_CLIENT_IP, raddr); + SES_Set_String_Attr(sp, SA_CLIENT_PORT, rport); sl = sizeof ss; AZ(getsockname(sp->fd, (void*)&ss, &sl)); @@ -350,8 +350,7 @@ vca_make_session(struct worker *wrk, void *arg) VSL(SLT_Begin, sp->vxid, "sess 0 HTTP/1"); VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s %.6f %d", - sp->client_addr_str, sp->client_port_str, - wa->acceptlsock->name, laddr, lport, + raddr, rport, wa->acceptlsock->name, laddr, lport, sp->t_open, sp->fd); WS_Release(wrk->aws, 0); diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 461bbb9..bdc3ad4 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -430,12 +430,15 @@ static void pan_sess(const struct sess *sp) { const char *stp; + char *ci; + char *cp; VSB_printf(pan_vsp, " sp = %p {\n", sp); VSB_printf(pan_vsp, " fd = %d, vxid = %u,\n", sp->fd, VXID(sp->vxid)); - VSB_printf(pan_vsp, " client = %s %s,\n", sp->client_addr_str, - sp->client_port_str); + AZ(SES_Get_client_ip(sp, &ci)); + AZ(SES_Get_client_port(sp, &cp)); + VSB_printf(pan_vsp, " client = %s %s,\n", ci, cp); switch (sp->sess_step) { #define SESS_STEP(l, u) case S_STP_##u: stp = "S_STP_" #u; break; #include "tbl/steps.h" diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c index 3ad045f..54c2b5c 100644 --- a/bin/varnishd/cache/cache_req_fsm.c +++ b/bin/varnishd/cache/cache_req_fsm.c @@ -559,6 +559,7 @@ cnt_recv(struct worker *wrk, struct req *req) unsigned recv_handling; struct SHA256Context sha256ctx; const char *xff; + char *ci, *cp; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); @@ -570,8 +571,9 @@ cnt_recv(struct worker *wrk, struct req *req) AZ(isnan(req->t_prev)); AZ(isnan(req->t_req)); - VSLb(req->vsl, SLT_ReqStart, "%s %s", - req->sp->client_addr_str, req->sp->client_port_str); + AZ(SES_Get_client_ip(req->sp, &ci)); + AZ(SES_Get_client_port(req->sp, &cp)); + VSLb(req->vsl, SLT_ReqStart, "%s %s", ci, cp); http_VSL_log(req->http); @@ -584,10 +586,9 @@ cnt_recv(struct worker *wrk, struct req *req) if (http_GetHdr(req->http, H_X_Forwarded_For, &xff)) { http_Unset(req->http, H_X_Forwarded_For); http_PrintfHeader(req->http, "X-Forwarded-For: %s, %s", - xff, req->sp->client_addr_str); + xff, ci); } else { - http_PrintfHeader(req->http, "X-Forwarded-For: %s", - req->sp->client_addr_str); + http_PrintfHeader(req->http, "X-Forwarded-For: %s", ci); } } diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 9139c72..6464b02 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -107,12 +107,51 @@ ses_reserve_attr(struct sess *sp, enum sess_attr a, void **dst, int sz) void \ SES_Reserve_##low(struct sess *sp, typ *dst) \ { \ + assert(len >= 0); \ ses_reserve_attr(sp, SA_##UP, (void*)dst, len); \ } #include "tbl/sess_attr.h" #undef SESS_ATTR +void +SES_Set_String_Attr(struct sess *sp, enum sess_attr a, const char *src) +{ + void *q; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + AN(src); + + switch (a) { +#define SESS_ATTR(UP, low, typ, len) case SA_##UP: assert(len < 0); break; +#include "tbl/sess_attr.h" +#undef SESS_ATTR + default: WRONG("wrong sess_attr"); + } + + ses_reserve_attr(sp, a, &q, strlen(src) + 1); + strcpy(q, src); +} + +const char * +SES_Get_String_Attr(const struct sess *sp, enum sess_attr a) +{ + void *q; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + + switch (a) { +#define SESS_ATTR(UP, low, typ, len) case SA_##UP: assert(len < 0); break; +#include "tbl/sess_attr.h" +#undef SESS_ATTR + default: WRONG("wrong sess_attr"); + } + + if (ses_get_attr(sp, a, &q) < 0) + return (NULL); + return (q); +} + /*-------------------------------------------------------------------- * Get a new session, preferably by recycling an already ready one * diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index a9c30ee..f896438 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -238,8 +238,7 @@ VRT_r_client_identity(VRT_CTX) CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); if (ctx->req->client_identity != NULL) return (ctx->req->client_identity); - else - return (ctx->req->sp->client_addr_str); + return(SES_Get_String_Attr(ctx->req->sp, SA_CLIENT_IP)); } void diff --git a/include/tbl/sess_attr.h b/include/tbl/sess_attr.h index db68fb6..fcdfec0 100644 --- a/include/tbl/sess_attr.h +++ b/include/tbl/sess_attr.h @@ -37,5 +37,7 @@ SESS_ATTR(REMOTE_ADDR, remote_addr, struct suckaddr *, vsa_suckaddr_len) SESS_ATTR(LOCAL_ADDR, local_addr, struct suckaddr *, vsa_suckaddr_len) SESS_ATTR(CLIENT_ADDR, client_addr, struct suckaddr *, vsa_suckaddr_len) SESS_ATTR(SERVER_ADDR, server_addr, struct suckaddr *, vsa_suckaddr_len) +SESS_ATTR(CLIENT_IP, client_ip, char *, -1) +SESS_ATTR(CLIENT_PORT, client_port, char *, -1) /*lint -restore */ From lkarsten at varnish-software.com Wed Mar 18 11:41:08 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Wed, 18 Mar 2015 12:41:08 +0100 Subject: [3.0] b0cf9e7 Changelog lint and formatting. Message-ID: commit b0cf9e789b5274cb7143cd4c887501d747bb40b3 Author: Lasse Karstensen Date: Wed Mar 18 12:00:13 2015 +0100 Changelog lint and formatting. diff --git a/doc/changes.rst b/doc/changes.rst index fa57fb9..810246f 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -5,11 +5,11 @@ Changes from 3.0.6 to 3.0.7-rc1 (2015-03-18) - Requests with multiple Content-Length headers will now fail. - Stop recognizing a single CR (\r) as a HTTP line separator. -This opened up a possible cache poisioning attack in stacked installations -where sslterminator/varnish/backend had different CR handling. + This opened up a possible cache poisioning attack in stacked installations + where sslterminator/varnish/backend had different CR handling. - Improved error detection on master-child process communication, leading to -faster recovery (child restart) if communication looses sync. + faster recovery (child restart) if communication loses sync. - Only emit passed Content_Length header when response mode is RES_LEN. Bug 1627_. From lkarsten at varnish-software.com Wed Mar 18 12:33:00 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Wed, 18 Mar 2015 13:33:00 +0100 Subject: [3.0] a1ddfd2 Improve language for bug 1627. Message-ID: commit a1ddfd24dd1560a103d943eb4a4734c6dc90a3e6 Author: Lasse Karstensen Date: Wed Mar 18 13:26:26 2015 +0100 Improve language for bug 1627. Author: scoof diff --git a/doc/changes.rst b/doc/changes.rst index 810246f..7105045 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -11,7 +11,8 @@ Changes from 3.0.6 to 3.0.7-rc1 (2015-03-18) - Improved error detection on master-child process communication, leading to faster recovery (child restart) if communication loses sync. -- Only emit passed Content_Length header when response mode is RES_LEN. Bug 1627_. +- Fix a corner-case where Content-Length was wrong for HTTP 1.0 clients, + when using gzip and streaming. Bug 1627_. - More robust handling of hop-by-hop headers. From phk at FreeBSD.org Wed Mar 18 14:06:04 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 15:06:04 +0100 Subject: [master] 7c145b2 Don't attempt to reopen sockets until child has died. Message-ID: commit 7c145b2004c496a32d0eb644b65cc4677b545e9f Author: Poul-Henning Kamp Date: Wed Mar 18 13:54:49 2015 +0000 Don't attempt to reopen sockets until child has died. diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index a7daa8d..2dfacf4 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -393,8 +393,6 @@ mgt_launch_child(struct cli *cli) mgt_child_inherit(heritage.cli_out, NULL); closex(&heritage.cli_out); - MAC_reopen_sockets(cli); - child_std_vlu = VLU_New(NULL, child_line, 0); AN(child_std_vlu); @@ -486,6 +484,8 @@ mgt_reap_child(void) fprintf(stderr, "WAIT 0x%jx\n", (uintmax_t)r); assert(r == child_pid); + MAC_reopen_sockets(NULL); + /* Compose obituary */ vsb = VSB_new_auto(); XXXAN(vsb); From phk at FreeBSD.org Wed Mar 18 14:06:05 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 15:06:05 +0100 Subject: [master] abcbc03 Don't call SES_NewPool() until there is at least one idle thread in the thread pool. Message-ID: commit abcbc03c888256f7dedd4a26bcec0b3278e45538 Author: Poul-Henning Kamp Date: Wed Mar 18 13:55:10 2015 +0000 Don't call SES_NewPool() until there is at least one idle thread in the thread pool. diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c index 762685b..c05d6c7 100644 --- a/bin/varnishd/cache/cache_pool.c +++ b/bin/varnishd/cache/cache_pool.c @@ -471,6 +471,7 @@ pool_herder(void *priv) pool_breed(pp); continue; } + assert(pp->nthr >= cache_param->wthread_min); if (pp->nthr > cache_param->wthread_min) { @@ -549,6 +550,9 @@ pool_mkpool(unsigned pool_no) AZ(pthread_cond_init(&pp->herder_cond, NULL)); AZ(pthread_create(&pp->herder_thr, NULL, pool_herder, pp)); + while (VTAILQ_EMPTY(&pp->idle_queue)) + usleep(10000); + pp->sesspool = SES_NewPool(pp, pool_no); AN(pp->sesspool); From phk at FreeBSD.org Wed Mar 18 14:06:05 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 15:06:05 +0100 Subject: [master] 194e3d6 Reuse addresses for local/server and remote/client until they differ Message-ID: commit 194e3d680db1425b9fba276aa881fc540d214bf4 Author: Poul-Henning Kamp Date: Wed Mar 18 14:05:41 2015 +0000 Reuse addresses for local/server and remote/client until they differ diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 62d8ad1..98e7351 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -332,8 +332,7 @@ vca_make_session(struct worker *wrk, void *arg) assert(wa->acceptaddrlen <= vsa_suckaddr_len); SES_Reserve_remote_addr(sp, &sa); AN(VSA_Build(sa, &wa->acceptaddr, wa->acceptaddrlen)); - SES_Reserve_client_addr(sp, &sa); - AN(VSA_Build(sa, &wa->acceptaddr, wa->acceptaddrlen)); + sp->sattr[SA_CLIENT_ADDR] = sp->sattr[SA_REMOTE_ADDR]; VTCP_name(sa, raddr, sizeof raddr, rport, sizeof rport); SES_Set_String_Attr(sp, SA_CLIENT_IP, raddr); @@ -343,8 +342,7 @@ vca_make_session(struct worker *wrk, void *arg) AZ(getsockname(sp->fd, (void*)&ss, &sl)); SES_Reserve_local_addr(sp, &sa); AN(VSA_Build(sa, &ss, sl)); - SES_Reserve_server_addr(sp, &sa); - AN(VSA_Build(sa, &ss, sl)); + sp->sattr[SA_SERVER_ADDR] = sp->sattr[SA_LOCAL_ADDR]; VTCP_name(sa, laddr, sizeof laddr, lport, sizeof lport); From lkarsten at varnish-software.com Wed Mar 18 15:37:38 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Wed, 18 Mar 2015 16:37:38 +0100 Subject: [master] ea4e783 Squash Debian/Ubuntu build warning. Message-ID: commit ea4e783fac24c23984a3b8bdbd8ea8a55f5ddcfe Author: Lasse Karstensen Date: Wed Mar 18 16:36:41 2015 +0100 Squash Debian/Ubuntu build warning. Debian (and Ubuntu) add --disable-maintainer-mode to configure when building packages, leading to a unrecognised argument warning. Adding AM_MAINTAINER_MODE disabled keeps the current behavior while removing the warning. diff --git a/configure.ac b/configure.ac index ada83df..fafe5e4 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,7 @@ OCFLAGS="$CFLAGS" AC_CANONICAL_SYSTEM AC_LANG(C) +AM_MAINTAINER_MODE([disable]) AM_INIT_AUTOMAKE([1.11 foreign color-tests parallel-tests]) AM_SILENT_RULES([yes]) AC_DISABLE_STATIC From lkarsten at varnish-software.com Wed Mar 18 15:37:58 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Wed, 18 Mar 2015 16:37:58 +0100 Subject: [4.0] 2a2c172 Squash Debian/Ubuntu build warning. Message-ID: commit 2a2c172e35e91690c312402c82bbff66a2dda241 Author: Lasse Karstensen Date: Wed Mar 18 16:36:41 2015 +0100 Squash Debian/Ubuntu build warning. Debian (and Ubuntu) add --disable-maintainer-mode to configure when building packages, leading to a unrecognised argument warning. Adding AM_MAINTAINER_MODE disabled keeps the current behavior while removing the warning. diff --git a/configure.ac b/configure.ac index bbe9da2..0eed0e9 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,7 @@ OCFLAGS="$CFLAGS" AC_CANONICAL_SYSTEM AC_LANG(C) +AM_MAINTAINER_MODE([disable]) AM_INIT_AUTOMAKE([1.11 foreign color-tests parallel-tests]) AM_SILENT_RULES([yes]) AC_DISABLE_STATIC From phk at FreeBSD.org Wed Mar 18 20:04:03 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 21:04:03 +0100 Subject: [master] 8ff2953 Introduce local.ip and remote.ip VCL variables. Message-ID: commit 8ff29534ba0154e883d18017105648d138264f83 Author: Poul-Henning Kamp Date: Wed Mar 18 20:02:59 2015 +0000 Introduce local.ip and remote.ip VCL variables. These reference the actual TCP connection, whereas client.ip and server.ip may (in a near future) talk about another TCP connection terminating in a proxy in front of Varnish. diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c index c05d6c7..2088d5d 100644 --- a/bin/varnishd/cache/cache_pool.c +++ b/bin/varnishd/cache/cache_pool.c @@ -551,7 +551,7 @@ pool_mkpool(unsigned pool_no) AZ(pthread_create(&pp->herder_thr, NULL, pool_herder, pp)); while (VTAILQ_EMPTY(&pp->idle_queue)) - usleep(10000); + (void)usleep(10000); pp->sesspool = SES_NewPool(pp, pool_no); AN(pp->sesspool); diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c index f896438..e900726 100644 --- a/bin/varnishd/cache/cache_vrt_var.c +++ b/bin/varnishd/cache/cache_vrt_var.c @@ -593,29 +593,26 @@ VRT_r_req_##field(VRT_CTX) \ /*--------------------------------------------------------------------*/ -VCL_IP -VRT_r_client_ip(VRT_CTX) -{ - struct suckaddr *sa; - - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); - CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC); - AZ(SES_Get_remote_addr(ctx->req->sp, &sa)); - return (sa); -} +#define GIP(fld) \ + VCL_IP \ + VRT_r_##fld##_ip(VRT_CTX) \ + { \ + struct suckaddr *sa; \ + \ + CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \ + CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \ + CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC); \ + AZ(SES_Get_##fld##_addr(ctx->req->sp, &sa)); \ + return (sa); \ + } -VCL_IP -VRT_r_server_ip(VRT_CTX) -{ - struct suckaddr *sa; +GIP(local) +GIP(remote) +GIP(client) +GIP(server) +#undef GIP - CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); - CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); - CHECK_OBJ_NOTNULL(ctx->req->sp, SESS_MAGIC); - AZ(SES_Get_local_addr(ctx->req->sp, &sa)); - return (sa); -} +/*--------------------------------------------------------------------*/ const char* VRT_r_server_identity(VRT_CTX) diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py index 871b8bc..19da0e0 100755 --- a/lib/libvcc/generate.py +++ b/lib/libvcc/generate.py @@ -157,6 +157,15 @@ returns =( # 'both' means all methods tagged "B" or "C" sp_variables = [ + ('remote.ip', + 'IP', + ( 'client',), + ( ), """ + The IP address of the other end of the TCP connection. + This can either be the clients IP, or the outgoing IP + of a proxy server. + """ + ), ('client.ip', 'IP', ( 'client',), @@ -172,6 +181,13 @@ sp_variables = [ in the client director. """ ), + ('local.ip', + 'IP', + ( 'client',), + ( ), """ + The IP address of the local end of the TCP connection. + """ + ), ('server.ip', 'IP', ( 'client',), From phk at FreeBSD.org Wed Mar 18 20:05:43 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 21:05:43 +0100 Subject: [master] 000819d Cover the execution of the local.ip and remote.ip VRT functions Message-ID: commit 000819d8105dfc5c8f3abb4a02f9bfb61a44f819 Author: Poul-Henning Kamp Date: Wed Mar 18 20:05:30 2015 +0000 Cover the execution of the local.ip and remote.ip VRT functions diff --git a/bin/varnishtest/tests/v00025.vtc b/bin/varnishtest/tests/v00025.vtc index ffd622b..fbb0fb8 100644 --- a/bin/varnishtest/tests/v00025.vtc +++ b/bin/varnishtest/tests/v00025.vtc @@ -22,6 +22,8 @@ varnish v1 -arg "-i J.F.Nobody" -vcl+backend { set resp.http.esi = req.esi; set resp.http.be = req.backend_hint; set resp.http.c_id = client.identity; + set resp.http.l_ip = local.ip; + set resp.http.r_ip = remote.ip; if (obj.uncacheable) { } } From phk at FreeBSD.org Wed Mar 18 21:00:32 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 22:00:32 +0100 Subject: [master] 6b47177 Remove the errno argument from our varnish-assert function, the intended purpose never materialized and it causes massive polution. Message-ID: commit 6b4717703ca5dc544d7964dd6b173d75fabbd12a Author: Poul-Henning Kamp Date: Wed Mar 18 20:36:54 2015 +0000 Remove the errno argument from our varnish-assert function, the intended purpose never materialized and it causes massive polution. diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index bdc3ad4..9615efe 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -491,12 +491,13 @@ pan_backtrace(void) static void __attribute__((__noreturn__)) pan_ic(const char *func, const char *file, int line, const char *cond, - int err, enum vas_e kind) + enum vas_e kind) { const char *q; struct req *req; struct busyobj *bo; struct sigaction sa; + int err = errno; AZ(pthread_mutex_lock(&panicstr_mtx)); /* Won't be released, we're going to die diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index 2dfacf4..e67b419 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -282,7 +282,6 @@ child_sigsegv_handler(int s, siginfo_t *si, void *c) __FILE__, __LINE__, buf, - errno, VAS_ASSERT); } diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c index 57ee43c..4a73ebd 100644 --- a/bin/varnishtest/vtc_log.c +++ b/bin/varnishtest/vtc_log.c @@ -289,11 +289,10 @@ vtc_hexdump(struct vtclog *vl, int lvl, const char *pfx, static void __attribute__((__noreturn__)) vtc_log_VAS_Fail(const char *func, const char *file, int line, - const char *cond, int err, enum vas_e why) + const char *cond, enum vas_e why) { struct vtclog *vl; - (void)err; (void)why; vl = pthread_getspecific(log_key); if (vl == NULL || vl->act) { diff --git a/include/vas.h b/include/vas.h index 246acc1..591d99e 100644 --- a/include/vas.h +++ b/include/vas.h @@ -46,8 +46,7 @@ enum vas_e { VAS_VCL, }; -typedef void vas_f(const char *, const char *, int, const char *, int, - enum vas_e); +typedef void vas_f(const char *, const char *, int, const char *, enum vas_e); extern vas_f *VAS_Fail __attribute__((__noreturn__)); @@ -58,7 +57,7 @@ extern vas_f *VAS_Fail __attribute__((__noreturn__)); do { \ if (!(e)) { \ VAS_Fail(__func__, __FILE__, __LINE__, \ - #e, errno, VAS_ASSERT); \ + #e, VAS_ASSERT); \ } \ } while (0) #endif @@ -67,7 +66,7 @@ do { \ do { \ if (!(e)) { \ VAS_Fail(__func__, __FILE__, __LINE__, \ - #e, errno, VAS_MISSING); \ + #e, VAS_MISSING); \ } \ } while (0) @@ -79,13 +78,13 @@ do { \ #define diagnostic(foo) assert(foo) #define WRONG(expl) \ do { \ - VAS_Fail(__func__, __FILE__, __LINE__, expl, errno, VAS_WRONG); \ + VAS_Fail(__func__, __FILE__, __LINE__, expl, VAS_WRONG); \ } while (0) #define INCOMPL() \ do { \ VAS_Fail(__func__, __FILE__, __LINE__, \ - "", errno, VAS_INCOMPLETE); \ + "", VAS_INCOMPLETE); \ } while (0) #endif diff --git a/lib/libvarnish/vas.c b/lib/libvarnish/vas.c index 9380b6c..2d810d2 100644 --- a/lib/libvarnish/vas.c +++ b/lib/libvarnish/vas.c @@ -31,6 +31,7 @@ #include "config.h" +#include #include #include #include @@ -39,8 +40,9 @@ static void __attribute__((__noreturn__)) VAS_Fail_default(const char *func, const char *file, int line, - const char *cond, int err, enum vas_e kind) + const char *cond, enum vas_e kind) { + int err = errno; if (kind == VAS_MISSING) { fprintf(stderr, diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c index 6ef7c15..ccdcab3 100644 --- a/lib/libvmod_debug/vmod_debug.c +++ b/lib/libvmod_debug/vmod_debug.c @@ -53,7 +53,7 @@ vmod_panic(VRT_CTX, const char *str, ...) va_start(ap, str); b = VRT_String(ctx->ws, "PANIC: ", str, ap); va_end(ap); - VAS_Fail("VCL", "", 0, b, 0, VAS_VCL); + VAS_Fail("VCL", "", 0, b, VAS_VCL); } VCL_STRING __match_proto__(td_debug_author) From phk at FreeBSD.org Wed Mar 18 21:00:32 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 22:00:32 +0100 Subject: [master] c24650d Remove a lot of includes no longer needed and delegate from central include files (like ) to specific source files. Message-ID: commit c24650d0f19faaa2f9c629c9d79ccebb940f585b Author: Poul-Henning Kamp Date: Wed Mar 18 20:59:39 2015 +0000 Remove a lot of includes no longer needed and delegate from central include files (like ) to specific source files. diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 98e7351..6d7c9c2 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -33,8 +33,10 @@ #include "config.h" -#include #include + +#include +#include #include #include diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c index 07d5503..0765302 100644 --- a/bin/varnishd/cache/cache_esi_fetch.c +++ b/bin/varnishd/cache/cache_esi_fetch.c @@ -30,6 +30,7 @@ #include "config.h" +#include #include #include "cache.h" diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c index fa601fc..5c094f1 100644 --- a/bin/varnishd/cache/cache_lck.c +++ b/bin/varnishd/cache/cache_lck.c @@ -35,6 +35,7 @@ #include "config.h" +#include #include #include "cache.h" diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c index 9615efe..35e738b 100644 --- a/bin/varnishd/cache/cache_panic.c +++ b/bin/varnishd/cache/cache_panic.c @@ -35,6 +35,7 @@ #include #endif +#include #include #include diff --git a/bin/varnishd/cache/cache_pool.c b/bin/varnishd/cache/cache_pool.c index 2088d5d..36668c1 100644 --- a/bin/varnishd/cache/cache_pool.c +++ b/bin/varnishd/cache/cache_pool.c @@ -35,6 +35,7 @@ #include "config.h" +#include #include #include "cache.h" diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 6464b02..79c8287 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -40,6 +40,7 @@ #include "config.h" +#include #include #include diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c index 98c04aa..2388969 100644 --- a/bin/varnishd/cache/cache_shmlog.c +++ b/bin/varnishd/cache/cache_shmlog.c @@ -29,6 +29,7 @@ #include "config.h" +#include #include #include diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h index 6a3e67f..843048e 100644 --- a/bin/varnishd/common/common.h +++ b/bin/varnishd/common/common.h @@ -28,7 +28,6 @@ * */ -#include #include #include diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index d776430..1cb7959 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -29,6 +29,7 @@ #include "config.h" +#include #include #include diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 866e914..4f1614c 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -33,6 +33,7 @@ #include "config.h" +#include #include #include #include diff --git a/bin/varnishd/http1/cache_http1_line.c b/bin/varnishd/http1/cache_http1_line.c index 1308ee0..a71e163 100644 --- a/bin/varnishd/http1/cache_http1_line.c +++ b/bin/varnishd/http1/cache_http1_line.c @@ -37,6 +37,7 @@ #include #include +#include #include #include "cache/cache.h" diff --git a/bin/varnishd/http1/cache_http1_vfp.c b/bin/varnishd/http1/cache_http1_vfp.c index 99d87da..f620937 100644 --- a/bin/varnishd/http1/cache_http1_vfp.c +++ b/bin/varnishd/http1/cache_http1_vfp.c @@ -35,6 +35,7 @@ #include "config.h" +#include #include #include "cache/cache.h" diff --git a/bin/varnishd/mgt/mgt_cli.c b/bin/varnishd/mgt/mgt_cli.c index 7c395a6..bf70e03 100644 --- a/bin/varnishd/mgt/mgt_cli.c +++ b/bin/varnishd/mgt/mgt_cli.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include diff --git a/bin/varnishd/mgt/mgt_jail_unix.c b/bin/varnishd/mgt/mgt_jail_unix.c index f54c4c0..7611365 100644 --- a/bin/varnishd/mgt/mgt_jail_unix.c +++ b/bin/varnishd/mgt/mgt_jail_unix.c @@ -30,9 +30,10 @@ #include "config.h" -#include +#include #include #include +#include #include #include #include diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c index f6b34d2..5ea594c 100644 --- a/bin/varnishd/mgt/mgt_main.c +++ b/bin/varnishd/mgt/mgt_main.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include diff --git a/bin/varnishd/mgt/mgt_shmem.c b/bin/varnishd/mgt/mgt_shmem.c index 837e165..66c87de 100644 --- a/bin/varnishd/mgt/mgt_shmem.c +++ b/bin/varnishd/mgt/mgt_shmem.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include diff --git a/bin/varnishd/mgt/mgt_vcc.c b/bin/varnishd/mgt/mgt_vcc.c index b9a1406..6e98c1f 100644 --- a/bin/varnishd/mgt/mgt_vcc.c +++ b/bin/varnishd/mgt/mgt_vcc.c @@ -32,6 +32,7 @@ #include "config.h" #include +#include #include #include #include diff --git a/bin/varnishd/storage/stevedore_utils.c b/bin/varnishd/storage/stevedore_utils.c index 96e24cc..80840cb 100644 --- a/bin/varnishd/storage/stevedore_utils.c +++ b/bin/varnishd/storage/stevedore_utils.c @@ -44,6 +44,7 @@ # include #endif +#include #include #include #include diff --git a/bin/varnishd/storage/storage_file.c b/bin/varnishd/storage/storage_file.c index 3886e9c..151f75e 100644 --- a/bin/varnishd/storage/storage_file.c +++ b/bin/varnishd/storage/storage_file.c @@ -33,6 +33,7 @@ #include +#include #include #include diff --git a/bin/varnishd/storage/storage_persistent_mgt.c b/bin/varnishd/storage/storage_persistent_mgt.c index 33f41e0..76d6436 100644 --- a/bin/varnishd/storage/storage_persistent_mgt.c +++ b/bin/varnishd/storage/storage_persistent_mgt.c @@ -37,6 +37,7 @@ #include +#include #include #include #include diff --git a/bin/varnishd/waiter/cache_waiter.c b/bin/varnishd/waiter/cache_waiter.c index acd6301..b005eb0 100644 --- a/bin/varnishd/waiter/cache_waiter.c +++ b/bin/varnishd/waiter/cache_waiter.c @@ -29,6 +29,8 @@ */ #include "config.h" + +#include #include #include diff --git a/bin/varnishreplay/varnishreplay.c b/bin/varnishreplay/varnishreplay.c index 4f7a2e9..12cdc0d 100644 --- a/bin/varnishreplay/varnishreplay.c +++ b/bin/varnishreplay/varnishreplay.c @@ -33,7 +33,6 @@ #include #include -#include #include #include #include diff --git a/bin/varnishstat/varnishstat.c b/bin/varnishstat/varnishstat.c index a65597e..3f8f9d0 100644 --- a/bin/varnishstat/varnishstat.c +++ b/bin/varnishstat/varnishstat.c @@ -34,7 +34,6 @@ #include -#include #include #include #include diff --git a/bin/varnishstat/varnishstat_curses.c b/bin/varnishstat/varnishstat_curses.c index 381621a..4637b61 100644 --- a/bin/varnishstat/varnishstat_curses.c +++ b/bin/varnishstat/varnishstat_curses.c @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c index 6f20ebe..756c616 100644 --- a/bin/varnishtest/vtc.c +++ b/bin/varnishtest/vtc.c @@ -32,6 +32,7 @@ #include #include +#include #include #include #include diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h index d43a188..29f275a 100644 --- a/bin/varnishtest/vtc.h +++ b/bin/varnishtest/vtc.h @@ -27,7 +27,6 @@ * */ -#include #include #include #include diff --git a/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c index db0d265..2b84b43 100644 --- a/bin/varnishtest/vtc_http.c +++ b/bin/varnishtest/vtc_http.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include diff --git a/bin/varnishtest/vtc_logexp.c b/bin/varnishtest/vtc_logexp.c index de1aa01..3afec94 100644 --- a/bin/varnishtest/vtc_logexp.c +++ b/bin/varnishtest/vtc_logexp.c @@ -51,7 +51,6 @@ #include #include #include -#include #include "vapi/vsm.h" #include "vapi/vsl.h" diff --git a/bin/varnishtest/vtc_main.c b/bin/varnishtest/vtc_main.c index 8b649d8..6a1da82 100644 --- a/bin/varnishtest/vtc_main.c +++ b/bin/varnishtest/vtc_main.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include diff --git a/lib/libvarnish/binary_heap.c b/lib/libvarnish/binary_heap.c index 491974b..664332b 100644 --- a/lib/libvarnish/binary_heap.c +++ b/lib/libvarnish/binary_heap.c @@ -35,7 +35,6 @@ #include "config.h" -#include #include #include #include diff --git a/lib/libvarnish/cli_auth.c b/lib/libvarnish/cli_auth.c index 08bbddc..a538f2b 100644 --- a/lib/libvarnish/cli_auth.c +++ b/lib/libvarnish/cli_auth.c @@ -30,7 +30,6 @@ #include -#include #include #include #include diff --git a/lib/libvarnish/vav.c b/lib/libvarnish/vav.c index 715e43c..bbbdaba 100644 --- a/lib/libvarnish/vav.c +++ b/lib/libvarnish/vav.c @@ -39,7 +39,6 @@ #include "config.h" #include -#include #include #include #include diff --git a/lib/libvarnish/vlu.c b/lib/libvarnish/vlu.c index 0673f10..1029cfd 100644 --- a/lib/libvarnish/vlu.c +++ b/lib/libvarnish/vlu.c @@ -29,7 +29,6 @@ #include "config.h" -#include #include #include #include diff --git a/lib/libvarnish/vmb.c b/lib/libvarnish/vmb.c index 692aab2..a3a7dea 100644 --- a/lib/libvarnish/vmb.c +++ b/lib/libvarnish/vmb.c @@ -28,7 +28,6 @@ #include "config.h" -#include #include #include diff --git a/lib/libvarnish/vnum.c b/lib/libvarnish/vnum.c index e620223..750ff77 100644 --- a/lib/libvarnish/vnum.c +++ b/lib/libvarnish/vnum.c @@ -31,7 +31,6 @@ #include "config.h" #include -#include #include #include #include diff --git a/lib/libvarnish/vre.c b/lib/libvarnish/vre.c index c7eccfa..cc5a615 100644 --- a/lib/libvarnish/vre.c +++ b/lib/libvarnish/vre.c @@ -28,7 +28,6 @@ #include "config.h" -#include #include #include diff --git a/lib/libvarnish/vrnd.c b/lib/libvarnish/vrnd.c index aa9e477..02f3970 100644 --- a/lib/libvarnish/vrnd.c +++ b/lib/libvarnish/vrnd.c @@ -29,7 +29,6 @@ #include "config.h" -#include #include #include #include diff --git a/lib/libvarnish/vsa.c b/lib/libvarnish/vsa.c index be0ebc4..43d9a86 100644 --- a/lib/libvarnish/vsa.c +++ b/lib/libvarnish/vsa.c @@ -33,7 +33,6 @@ #include "config.h" -#include #include #include #include diff --git a/lib/libvarnish/vsha256.c b/lib/libvarnish/vsha256.c index 90ac3ed..7e73710 100644 --- a/lib/libvarnish/vsha256.c +++ b/lib/libvarnish/vsha256.c @@ -39,7 +39,6 @@ # define VBIG_ENDIAN __BIG_ENDIAN #endif -#include #include #include diff --git a/lib/libvarnish/vss.c b/lib/libvarnish/vss.c index 1077e25..6d1b809 100644 --- a/lib/libvarnish/vss.c +++ b/lib/libvarnish/vss.c @@ -35,7 +35,6 @@ #include -#include #include #include #include diff --git a/lib/libvarnish/vtim.c b/lib/libvarnish/vtim.c index 39f5115..509ba9a 100644 --- a/lib/libvarnish/vtim.c +++ b/lib/libvarnish/vtim.c @@ -56,7 +56,6 @@ #include -#include #include #include #include diff --git a/lib/libvarnishapi/vsc.c b/lib/libvarnishapi/vsc.c index db721fe..2ec667c 100644 --- a/lib/libvarnishapi/vsc.c +++ b/lib/libvarnishapi/vsc.c @@ -33,7 +33,6 @@ #include #include -#include #include #include #include diff --git a/lib/libvarnishapi/vsl_arg.c b/lib/libvarnishapi/vsl_arg.c index 229d9fc..061c907 100644 --- a/lib/libvarnishapi/vsl_arg.c +++ b/lib/libvarnishapi/vsl_arg.c @@ -34,7 +34,6 @@ #include #include -#include #include #include #include diff --git a/lib/libvarnishapi/vsl_dispatch.c b/lib/libvarnishapi/vsl_dispatch.c index 0b9285c..732f8a6 100644 --- a/lib/libvarnishapi/vsl_dispatch.c +++ b/lib/libvarnishapi/vsl_dispatch.c @@ -28,7 +28,6 @@ * */ -#include #include #include #include diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c index 20ef8c2..e662bee 100644 --- a/lib/libvarnishapi/vsl_query.c +++ b/lib/libvarnishapi/vsl_query.c @@ -29,7 +29,6 @@ */ #include -#include #include #include #include diff --git a/lib/libvarnishapi/vxp.c b/lib/libvarnishapi/vxp.c index 2e21b55..47f4200 100644 --- a/lib/libvarnishapi/vxp.c +++ b/lib/libvarnishapi/vxp.c @@ -31,7 +31,6 @@ #include "config.h" #include -#include #include #include #include diff --git a/lib/libvarnishapi/vxp_lexer.c b/lib/libvarnishapi/vxp_lexer.c index c57318c..73846a8 100644 --- a/lib/libvarnishapi/vxp_lexer.c +++ b/lib/libvarnishapi/vxp_lexer.c @@ -31,7 +31,6 @@ #include "config.h" #include -#include #include #include #include diff --git a/lib/libvarnishapi/vxp_parse.c b/lib/libvarnishapi/vxp_parse.c index 410fccb..9559016 100644 --- a/lib/libvarnishapi/vxp_parse.c +++ b/lib/libvarnishapi/vxp_parse.c @@ -31,7 +31,6 @@ #include "config.h" #include -#include #include #include #include diff --git a/lib/libvarnishapi/vxp_test.c b/lib/libvarnishapi/vxp_test.c index 970cb26..d00d35f 100644 --- a/lib/libvarnishapi/vxp_test.c +++ b/lib/libvarnishapi/vxp_test.c @@ -26,7 +26,6 @@ * SUCH DAMAGE. */ -#include #include #include #include diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h index a4697a5..b2e15e3 100644 --- a/lib/libvcc/vcc_compile.h +++ b/lib/libvcc/vcc_compile.h @@ -30,7 +30,6 @@ #include -#include #include #include diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c index 4777a5f..097cd45 100644 --- a/lib/libvmod_std/vmod_std.c +++ b/lib/libvmod_std/vmod_std.c @@ -33,7 +33,6 @@ #include #include -#include #include #include #include diff --git a/lib/libvmod_std/vmod_std_fileread.c b/lib/libvmod_std/vmod_std_fileread.c index 0e37268..2d079a9 100644 --- a/lib/libvmod_std/vmod_std_fileread.c +++ b/lib/libvmod_std/vmod_std_fileread.c @@ -39,7 +39,6 @@ #include "config.h" -#include #include #include From phk at FreeBSD.org Wed Mar 18 21:31:37 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 18 Mar 2015 22:31:37 +0100 Subject: [master] dbf5d5d Add back an errno.h header Message-ID: commit dbf5d5dbc2cb6a56b5bcf612172cf53eb6306c8e Author: Poul-Henning Kamp Date: Wed Mar 18 21:31:23 2015 +0000 Add back an errno.h header diff --git a/bin/varnishd/mgt/mgt_jail_solaris.c b/bin/varnishd/mgt/mgt_jail_solaris.c index 8a8e971..16f3ccc 100644 --- a/bin/varnishd/mgt/mgt_jail_solaris.c +++ b/bin/varnishd/mgt/mgt_jail_solaris.c @@ -206,6 +206,7 @@ #ifdef HAVE_SETPPRIV +#include #include #include #include From phk at FreeBSD.org Thu Mar 19 12:06:09 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 19 Mar 2015 13:06:09 +0100 Subject: [master] 3a22b09 Better packing of struct waited. Message-ID: commit 3a22b09fecc2286ad026dadba5a3e5949b94312d Author: Poul-Henning Kamp Date: Thu Mar 19 09:50:58 2015 +0000 Better packing of struct waited. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 1da6f63..9453cbc 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -384,8 +384,8 @@ struct lru { struct waited { unsigned magic; #define WAITED_MAGIC 0x1743992d - VTAILQ_ENTRY(waited) list; int fd; + VTAILQ_ENTRY(waited) list; void *ptr; double idle; #if defined(HAVE_EPOLL_CTL) From phk at FreeBSD.org Thu Mar 19 12:06:09 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 19 Mar 2015 13:06:09 +0100 Subject: [master] fc8e57f Eliminate a unused field in struct sess Message-ID: commit fc8e57f6874fe4aa7d151dbe44412ce52e7af774 Author: Poul-Henning Kamp Date: Thu Mar 19 10:44:45 2015 +0000 Eliminate a unused field in struct sess diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 9453cbc..4ddf35a 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -659,7 +659,6 @@ struct sess { enum sess_step sess_step; struct lock mtx; int fd; - enum sess_close reason; uint32_t vxid; /* Cross references ------------------------------------------*/ diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 79c8287..d0f8fe7 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -365,7 +365,6 @@ SES_Close(struct sess *sp, enum sess_close reason) int i; assert(sp->fd >= 0); - sp->reason = reason; i = close(sp->fd); assert(i == 0 || errno != EBADF); /* XXX EINVAL seen */ sp->fd = -1; @@ -397,7 +396,7 @@ SES_Delete(struct sess *sp, enum sess_close reason, double now) assert(VTAILQ_EMPTY(&sp->privs->privs)); VSL(SLT_SessClose, sp->vxid, "%s %.3f", - sess_close_2str(sp->reason, 0), now - sp->t_open); + sess_close_2str(reason, 0), now - sp->t_open); VSL(SLT_End, sp->vxid, "%s", ""); Lck_Delete(&sp->mtx); From phk at FreeBSD.org Thu Mar 19 12:06:09 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Thu, 19 Mar 2015 13:06:09 +0100 Subject: [master] ba34fd3 Put a protocol prefix on enum sess_step. Message-ID: commit ba34fd3a05331fed7ccced94bf67621400881d97 Author: Poul-Henning Kamp Date: Thu Mar 19 10:54:30 2015 +0000 Put a protocol prefix on enum sess_step. In the future we will need to tell what protocol controls a give session, for instance when we come back from the waiter or waiting list. Rather than spend memory on a dedicated field for this, protocols will share the enum sess_step, and ranges will be used to dispatch to protocols. diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index d0f8fe7..31c2c40 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -228,7 +228,7 @@ SES_sess_pool_task(struct worker *wrk, void *arg) req = SES_GetReq(wrk, sp); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); - sp->sess_step = S_STP_NEWREQ; + sp->sess_step = S_STP_H1NEWREQ; wrk->task.func = ses_req_pool_task; wrk->task.priv = req; diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 4f1614c..a88e4ca 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -347,7 +347,7 @@ HTTP1_Session(struct worker *wrk, struct req *req) * or waiter, but we'd rather do the syscall in the worker thread. * On systems which return errors for ioctl, we close early */ - if (sp->sess_step == S_STP_NEWREQ && VTCP_blocking(sp->fd)) { + if (sp->sess_step == S_STP_H1NEWREQ && VTCP_blocking(sp->fd)) { if (errno == ECONNRESET) SES_Close(sp, SC_REM_CLOSE); else @@ -370,7 +370,7 @@ HTTP1_Session(struct worker *wrk, struct req *req) return; } - if (sp->sess_step == S_STP_NEWREQ) { + if (sp->sess_step == S_STP_H1NEWREQ) { req->htc->fd = sp->fd; HTTP1_RxInit(req->htc, req->ws, cache_param->http_req_size, cache_param->http_req_hdr_len); @@ -378,11 +378,11 @@ HTTP1_Session(struct worker *wrk, struct req *req) while (1) { assert( - sp->sess_step == S_STP_NEWREQ || + sp->sess_step == S_STP_H1NEWREQ || req->req_step == R_STP_LOOKUP || req->req_step == R_STP_RECV); - if (sp->sess_step == S_STP_WORKING) { + if (sp->sess_step == S_STP_H1WORKING) { if (req->req_step == R_STP_RECV) nxt = http1_dissect(wrk, req); if (nxt == REQ_FSM_MORE) @@ -395,10 +395,10 @@ HTTP1_Session(struct worker *wrk, struct req *req) case SESS_DONE_RET_GONE: return; case SESS_DONE_RET_WAIT: - sp->sess_step = S_STP_NEWREQ; + sp->sess_step = S_STP_H1NEWREQ; break; case SESS_DONE_RET_START: - sp->sess_step = S_STP_WORKING; + sp->sess_step = S_STP_H1WORKING; req->req_step = R_STP_RECV; break; default: @@ -406,11 +406,11 @@ HTTP1_Session(struct worker *wrk, struct req *req) } } - if (sp->sess_step == S_STP_NEWREQ) { + if (sp->sess_step == S_STP_H1NEWREQ) { nxt = http1_wait(sp, wrk, req); if (nxt != REQ_FSM_MORE) return; - sp->sess_step = S_STP_WORKING; + sp->sess_step = S_STP_H1WORKING; req->req_step = R_STP_RECV; } } diff --git a/include/tbl/steps.h b/include/tbl/steps.h index bb02fb4..534d9a3 100644 --- a/include/tbl/steps.h +++ b/include/tbl/steps.h @@ -31,8 +31,8 @@ /*lint -save -e525 -e539 */ #ifdef SESS_STEP -SESS_STEP(newreq, NEWREQ) -SESS_STEP(working, WORKING) +SESS_STEP(h1newreq, H1NEWREQ) +SESS_STEP(h1working, H1WORKING) #endif #ifdef REQ_STEP From phk at FreeBSD.org Mon Mar 23 07:46:40 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 08:46:40 +0100 Subject: [master] 5335c72 Have listen_socks tell what session step to go to after accept. Message-ID: commit 5335c72147f4123d969fefa340e36b5c34d84479 Author: Poul-Henning Kamp Date: Thu Mar 19 15:07:33 2015 +0000 Have listen_socks tell what session step to go to after accept. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 4ddf35a..26e2a5e 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -139,12 +139,6 @@ typedef struct { /*--------------------------------------------------------------------*/ -enum sess_step { -#define SESS_STEP(l, u) S_STP_##u, -#include "tbl/steps.h" -#undef SESS_STEP -}; - enum req_step { #define REQ_STEP(l, u, arg) R_STP_##u, #include "tbl/steps.h" diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h index 843048e..b268082 100644 --- a/bin/varnishd/common/common.h +++ b/bin/varnishd/common/common.h @@ -62,6 +62,12 @@ enum obj_flags { #undef OBJ_FLAG }; +enum sess_step { +#define SESS_STEP(l, u) S_STP_##u, +#include "tbl/steps.h" +#undef SESS_STEP +}; + struct cli; /********************************************************************** diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h index 949853b..c8f857b 100644 --- a/bin/varnishd/common/heritage.h +++ b/bin/varnishd/common/heritage.h @@ -39,6 +39,7 @@ struct listen_sock { int sock; const char *name; const struct suckaddr *addr; + enum sess_step first_step; }; VTAILQ_HEAD(listen_sock_head, listen_sock); diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index 1d9aa47..318d215 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -132,6 +132,7 @@ mac_callback(void *priv, const struct suckaddr *sa) AN(ls); ls->sock = -1; ls->addr = sa; + ls->first_step = S_STP_H1NEWSESS; fail = mac_opensocket(ls, NULL); if (ls->sock < 0) { *(mh->err) = strerror(fail); diff --git a/include/tbl/steps.h b/include/tbl/steps.h index 534d9a3..1e0b415 100644 --- a/include/tbl/steps.h +++ b/include/tbl/steps.h @@ -31,6 +31,7 @@ /*lint -save -e525 -e539 */ #ifdef SESS_STEP +SESS_STEP(h1newsess, H1NEWSESS) SESS_STEP(h1newreq, H1NEWREQ) SESS_STEP(h1working, H1WORKING) #endif From phk at FreeBSD.org Mon Mar 23 07:46:40 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 08:46:40 +0100 Subject: [master] 953da35 Also decorate listensock's with a protocol name we can use. Message-ID: commit 953da35369e781f987d34898a1a44f51cdc5c9d5 Author: Poul-Henning Kamp Date: Thu Mar 19 15:15:04 2015 +0000 Also decorate listensock's with a protocol name we can use. diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 6d7c9c2..c8ef147 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -296,6 +296,8 @@ vca_make_session(struct worker *wrk, void *arg) struct wrk_accept *wa; struct sockaddr_storage ss; struct suckaddr *sa; + enum sess_step first_step; + const char *proto_name; socklen_t sl; char laddr[VTCP_ADDRBUFSIZE]; char lport[VTCP_PORTBUFSIZE]; @@ -305,6 +307,8 @@ vca_make_session(struct worker *wrk, void *arg) CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(wa, arg, WRK_ACCEPT_MAGIC); pp = wa->sesspool; + first_step = wa->acceptlsock->first_step; + proto_name = wa->acceptlsock->proto_name; /* Turn accepted socket into a session */ AN(wrk->aws->r); @@ -348,7 +352,7 @@ vca_make_session(struct worker *wrk, void *arg) VTCP_name(sa, laddr, sizeof laddr, lport, sizeof lport); - VSL(SLT_Begin, sp->vxid, "sess 0 HTTP/1"); + VSL(SLT_Begin, sp->vxid, "sess 0 %s", proto_name); VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s %.6f %d", raddr, rport, wa->acceptlsock->name, laddr, lport, sp->t_open, sp->fd); @@ -363,6 +367,8 @@ vca_make_session(struct worker *wrk, void *arg) need_test = 0; } vca_tcp_opt_set(sp->fd, 0); + + assert(first_step == S_STP_H1NEWSESS); /* SES_sess_pool_task() must be sceduled with reserved WS */ assert(8 == WS_Reserve(sp->ws, 8)); wrk->task.func = SES_sess_pool_task; diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h index c8f857b..05f340a 100644 --- a/bin/varnishd/common/heritage.h +++ b/bin/varnishd/common/heritage.h @@ -40,6 +40,7 @@ struct listen_sock { const char *name; const struct suckaddr *addr; enum sess_step first_step; + const char *proto_name; }; VTAILQ_HEAD(listen_sock_head, listen_sock); diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index 318d215..238d351 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -133,6 +133,7 @@ mac_callback(void *priv, const struct suckaddr *sa) ls->sock = -1; ls->addr = sa; ls->first_step = S_STP_H1NEWSESS; + ls->proto_name = "HTTP/1"; fail = mac_opensocket(ls, NULL); if (ls->sock < 0) { *(mh->err) = strerror(fail); From phk at FreeBSD.org Mon Mar 23 07:46:40 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 08:46:40 +0100 Subject: [master] e83ea40 Make cache_session.c the "protocol-switch" of Varnish. Message-ID: commit e83ea40d0c89f121bd1f41855bc926064498a9ff Author: Poul-Henning Kamp Date: Mon Mar 23 07:45:36 2015 +0000 Make cache_session.c the "protocol-switch" of Varnish. Presently we have two switch points: Created/Waited session and Rescheduled (from waiting list) request. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 26e2a5e..8a3d759 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -987,10 +987,10 @@ void SES_Wait(struct sess *sp); void SES_Delete(struct sess *sp, enum sess_close reason, double now); struct sesspool *SES_NewPool(struct pool *pp, unsigned pool_no); void SES_DeletePool(struct sesspool *sp); -int SES_ScheduleReq(struct req *); +int SES_Reschedule_Req(struct req *); struct req *SES_GetReq(const struct worker *, struct sess *); void SES_ReleaseReq(struct req *); -void SES_sess_pool_task(struct worker *wrk, void *arg); +void SES_Proto_Sess(struct worker *wrk, void *arg); #define SESS_ATTR(UP, low, typ, len) \ int SES_Get_##low(const struct sess *sp, typ *dst); \ diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index c8ef147..94e00cf 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -368,10 +368,10 @@ vca_make_session(struct worker *wrk, void *arg) } vca_tcp_opt_set(sp->fd, 0); - assert(first_step == S_STP_H1NEWSESS); - /* SES_sess_pool_task() must be sceduled with reserved WS */ + xxxassert(first_step == S_STP_H1NEWSESS); + /* SES_Proto_Sess() must be sceduled with reserved WS */ assert(8 == WS_Reserve(sp->ws, 8)); - wrk->task.func = SES_sess_pool_task; + wrk->task.func = SES_Proto_Sess; wrk->task.priv = sp; } diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index 40412ee..b3d3ac8 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -533,7 +533,7 @@ hsh_rush(struct worker *wrk, struct objhead *oh) AZ(req->wrk); VTAILQ_REMOVE(&wl->list, req, w_list); DSL(DBG_WAITINGLIST, req->vsl->wid, "off waiting list"); - if (SES_ScheduleReq(req)) { + if (SES_Reschedule_Req(req)) { /* * In case of overloads, we ditch the entire * waiting list. diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 31c2c40..8dedfca 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -189,11 +189,11 @@ SES_New(struct sesspool *pp) } /*-------------------------------------------------------------------- - * Process new/existing request on this session. + * Call protocol for this request */ static void __match_proto__(task_func_t) -ses_req_pool_task(struct worker *wrk, void *arg) +ses_proto_req(struct worker *wrk, void *arg) { struct req *req; @@ -202,21 +202,30 @@ ses_req_pool_task(struct worker *wrk, void *arg) THR_SetRequest(req); AZ(wrk->aws->r); - wrk->lastused = NAN; - HTTP1_Session(wrk, req); + if (req->sp->sess_step < S_STP_H1_LAST) { + HTTP1_Session(wrk, req); + AZ(wrk->v1l); + } else { + WRONG("Wrong session step"); + } WS_Assert(wrk->aws); - AZ(wrk->v1l); if (DO_DEBUG(DBG_VCLREL) && wrk->vcl != NULL) VCL_Rel(&wrk->vcl); THR_SetRequest(NULL); } /*-------------------------------------------------------------------- - * Allocate a request + vxid, call ses_req_pool_task() + * Call protocol for this session (new or from waiter) + * + * When sessions are rescheduled from the waiter, a struct pool_task + * is put on the reserved session workspace (for reasons of memory + * conservation). This reservation is released as the first thing. + * The acceptor and any other code which schedules this function + * must obey this calling convention with a dummy reservation. */ void __match_proto__(task_func_t) -SES_sess_pool_task(struct worker *wrk, void *arg) +SES_Proto_Sess(struct worker *wrk, void *arg) { struct req *req; struct sess *sp; @@ -225,23 +234,25 @@ SES_sess_pool_task(struct worker *wrk, void *arg) CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC); WS_Release(sp->ws, 0); - req = SES_GetReq(wrk, sp); - CHECK_OBJ_NOTNULL(req, REQ_MAGIC); - - sp->sess_step = S_STP_H1NEWREQ; - - wrk->task.func = ses_req_pool_task; - wrk->task.priv = req; + if (sp->sess_step < S_STP_H1_LAST) { + req = SES_GetReq(wrk, sp); + CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + sp->sess_step = S_STP_H1NEWREQ; + wrk->task.func = ses_proto_req; + wrk->task.priv = req; + } else { + WRONG("Wrong session step"); + } } /*-------------------------------------------------------------------- - * Schedule a request back on a work-thread from its sessions pool + * Reschedule a request on a work-thread from its sessions pool * * This is used to reschedule requests waiting on busy objects */ int -SES_ScheduleReq(struct req *req) +SES_Reschedule_Req(struct req *req) { struct sess *sp; struct sesspool *pp; @@ -253,7 +264,7 @@ SES_ScheduleReq(struct req *req) CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); - req->task.func = ses_req_pool_task; + req->task.func = ses_proto_req; req->task.priv = req; return (Pool_Task(pp->pool, &req->task, POOL_QUEUE_FRONT)); @@ -288,7 +299,7 @@ ses_handle(struct waited *wp, enum wait_event ev, double now) AN(pp->pool); assert(sizeof *tp == WS_Reserve(sp->ws, sizeof *tp)); tp = (void*)sp->ws->f; - tp->func = SES_sess_pool_task; + tp->func = SES_Proto_Sess; tp->priv = sp; if (Pool_Task(pp->pool, tp, POOL_QUEUE_FRONT)) SES_Delete(sp, SC_OVERLOAD, now); diff --git a/include/tbl/steps.h b/include/tbl/steps.h index 1e0b415..e9a1b3d 100644 --- a/include/tbl/steps.h +++ b/include/tbl/steps.h @@ -34,6 +34,7 @@ SESS_STEP(h1newsess, H1NEWSESS) SESS_STEP(h1newreq, H1NEWREQ) SESS_STEP(h1working, H1WORKING) +SESS_STEP(h1_last, H1_LAST) #endif #ifdef REQ_STEP From lkarsten at varnish-software.com Mon Mar 23 11:55:32 2015 From: lkarsten at varnish-software.com (Lasse Karstensen) Date: Mon, 23 Mar 2015 12:55:32 +0100 Subject: [3.0] f544cd8 Prepare 3.0.7. Message-ID: commit f544cd8129e3a5b500ea4a706faf6cb4208ad983 Author: Lasse Karstensen Date: Mon Mar 23 12:55:24 2015 +0100 Prepare 3.0.7. diff --git a/configure.ac b/configure.ac index e2eb271..2586baa 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ(2.59) AC_COPYRIGHT([Copyright (c) 2006 Verdens Gang AS Copyright (c) 2006-2015 Varnish Software AS]) AC_REVISION([$Id$]) -AC_INIT([Varnish], [3.0.7-rc1], [varnish-dev at varnish-cache.org]) +AC_INIT([Varnish], [3.0.7], [varnish-dev at varnish-cache.org]) AC_CONFIG_SRCDIR(include/varnishapi.h) AM_CONFIG_HEADER(config.h) diff --git a/doc/changes.rst b/doc/changes.rst index 7105045..42f3d25 100644 --- a/doc/changes.rst +++ b/doc/changes.rst @@ -1,4 +1,10 @@ ============================================ +Changes from 3.0.7-rc1 to 3.0.7 (2015-03-23) +============================================ + +- No changes. + +============================================ Changes from 3.0.6 to 3.0.7-rc1 (2015-03-18) ============================================ diff --git a/redhat/varnish.spec b/redhat/varnish.spec index e56a16c..0f12773 100644 --- a/redhat/varnish.spec +++ b/redhat/varnish.spec @@ -1,4 +1,4 @@ -%define v_rc rc1 +# %Xdefine v_rc rc1 %define _use_internal_dependency_generator 0 %define __find_provides %{_builddir}/varnish-%{version}%{?v_rc:-%{?v_rc}}/redhat/find-provides Summary: High-performance HTTP accelerator From phk at FreeBSD.org Mon Mar 23 13:41:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 14:41:46 +0100 Subject: [master] 539961b Pass protocol info into DNS iterator Message-ID: commit 539961be785030c8c32901537b2047e1f4aa513b Author: Poul-Henning Kamp Date: Mon Mar 23 08:12:51 2015 +0000 Pass protocol info into DNS iterator diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index 238d351..a04bca0 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -115,6 +115,8 @@ struct mac_help { const char *name; int good; const char **err; + const char *proto_name; + enum sess_step first_step; }; static int __match_proto__(vss_resolver_f) @@ -132,8 +134,8 @@ mac_callback(void *priv, const struct suckaddr *sa) AN(ls); ls->sock = -1; ls->addr = sa; - ls->first_step = S_STP_H1NEWSESS; - ls->proto_name = "HTTP/1"; + ls->proto_name = mh->proto_name; + ls->first_step = mh->first_step; fail = mac_opensocket(ls, NULL); if (ls->sock < 0) { *(mh->err) = strerror(fail); @@ -180,6 +182,8 @@ MAC_Arg(const char *arg) AN(mh); mh->name = av[1]; mh->err = &err; + mh->first_step = S_STP_H1NEWSESS; + mh->proto_name = "HTTP/1"; error = VSS_resolver(av[1], "80", mac_callback, mh, &err); if (mh->good == 0 || err != NULL) ARGV_ERR("Could not bind to address %s: %s\n", av[1], err); From phk at FreeBSD.org Mon Mar 23 13:41:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 14:41:46 +0100 Subject: [master] 32ad286 Pick up first session step from acceptor socket. Message-ID: commit 32ad28690c2d44eab6b0faa20ca5253372b172ee Author: Poul-Henning Kamp Date: Mon Mar 23 09:38:35 2015 +0000 Pick up first session step from acceptor socket. Complain about unrecognized protocols. diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c index 94e00cf..0fb6349 100644 --- a/bin/varnishd/cache/cache_acceptor.c +++ b/bin/varnishd/cache/cache_acceptor.c @@ -296,8 +296,6 @@ vca_make_session(struct worker *wrk, void *arg) struct wrk_accept *wa; struct sockaddr_storage ss; struct suckaddr *sa; - enum sess_step first_step; - const char *proto_name; socklen_t sl; char laddr[VTCP_ADDRBUFSIZE]; char lport[VTCP_PORTBUFSIZE]; @@ -307,8 +305,6 @@ vca_make_session(struct worker *wrk, void *arg) CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CAST_OBJ_NOTNULL(wa, arg, WRK_ACCEPT_MAGIC); pp = wa->sesspool; - first_step = wa->acceptlsock->first_step; - proto_name = wa->acceptlsock->proto_name; /* Turn accepted socket into a session */ AN(wrk->aws->r); @@ -334,6 +330,7 @@ vca_make_session(struct worker *wrk, void *arg) sp->fd = wa->acceptsock; wa->acceptsock = -1; + sp->sess_step = wa->acceptlsock->first_step; assert(wa->acceptaddrlen <= vsa_suckaddr_len); SES_Reserve_remote_addr(sp, &sa); @@ -352,7 +349,7 @@ vca_make_session(struct worker *wrk, void *arg) VTCP_name(sa, laddr, sizeof laddr, lport, sizeof lport); - VSL(SLT_Begin, sp->vxid, "sess 0 %s", proto_name); + VSL(SLT_Begin, sp->vxid, "sess 0 %s", wa->acceptlsock->proto_name); VSL(SLT_SessOpen, sp->vxid, "%s %s %s %s %s %.6f %d", raddr, rport, wa->acceptlsock->name, laddr, lport, sp->t_open, sp->fd); @@ -368,7 +365,6 @@ vca_make_session(struct worker *wrk, void *arg) } vca_tcp_opt_set(sp->fd, 0); - xxxassert(first_step == S_STP_H1NEWSESS); /* SES_Proto_Sess() must be sceduled with reserved WS */ assert(8 == WS_Reserve(sp->ws, 8)); wrk->task.func = SES_Proto_Sess; diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index a04bca0..43e3430 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -175,15 +175,19 @@ MAC_Arg(const char *arg) ARGV_ERR("Parse error: out of memory\n"); if (av[0] != NULL) ARGV_ERR("%s\n", av[0]); - if (av[2] != NULL) - ARGV_ERR("XXX: not yet\n"); ALLOC_OBJ(mh, MAC_HELP_MAGIC); AN(mh); mh->name = av[1]; + + if (av[2] == NULL || !strcmp(av[2], "HTTP/1")) { + mh->first_step = S_STP_H1NEWSESS; + mh->proto_name = "HTTP/1"; + } else { + ARGV_ERR("Unknown protocol '%s'\n", av[2]); + } + mh->err = &err; - mh->first_step = S_STP_H1NEWSESS; - mh->proto_name = "HTTP/1"; error = VSS_resolver(av[1], "80", mac_callback, mh, &err); if (mh->good == 0 || err != NULL) ARGV_ERR("Could not bind to address %s: %s\n", av[1], err); diff --git a/bin/varnishtest/tests/c00003.vtc b/bin/varnishtest/tests/c00003.vtc index d4ce742..2acb66b 100644 --- a/bin/varnishtest/tests/c00003.vtc +++ b/bin/varnishtest/tests/c00003.vtc @@ -6,5 +6,5 @@ varnishtest "Check that we fail to start if any listen address does not work" # All bad listen addresses err_shell "Could not bind to address 192.0.2.255:0" {${varnishd} -F -a "${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } -# Just one bad listen addresses -err_shell "Error: XXX: not yet" {${varnishd} -F -a "127.0.0.1:0,${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } +# old style address list +err_shell "Unknown protocol" {${varnishd} -F -a "127.0.0.1:0,${bad_ip}:0" -b /// -n ${tmpdir} 2>&1 } From phk at FreeBSD.org Mon Mar 23 13:41:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 14:41:46 +0100 Subject: [master] 1dbd3c7 Insert an empty place-holder for the PROXY protocol. Message-ID: commit 1dbd3c746b63153176af7dc503f29e795db909f4 Author: Poul-Henning Kamp Date: Mon Mar 23 10:01:21 2015 +0000 Insert an empty place-holder for the PROXY protocol. diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am index 94b6aa4..3f817bd 100644 --- a/bin/varnishd/Makefile.am +++ b/bin/varnishd/Makefile.am @@ -78,6 +78,7 @@ varnishd_SOURCES = \ mgt/mgt_shmem.c \ mgt/mgt_vcc.c \ mgt/mgt_vcl.c \ + proxy/cache_proxy_proto.c \ storage/stevedore.c \ storage/stevedore_mgt.c \ storage/stevedore_utils.c \ diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 8a3d759..c39edc6 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -977,6 +977,9 @@ unsigned V1L_Flush(const struct worker *w); unsigned V1L_FlushRelease(struct worker *w); size_t V1L_Write(const struct worker *w, const void *ptr, ssize_t len); +/* cache_proxy.c [VPX] */ +task_func_t VPX_Proto_Sess; + /* cache_range.c [VRG] */ void VRG_dorange(struct req *req, struct busyobj *bo, const char *r); @@ -990,7 +993,7 @@ void SES_DeletePool(struct sesspool *sp); int SES_Reschedule_Req(struct req *); struct req *SES_GetReq(const struct worker *, struct sess *); void SES_ReleaseReq(struct req *); -void SES_Proto_Sess(struct worker *wrk, void *arg); +task_func_t SES_Proto_Sess; #define SESS_ATTR(UP, low, typ, len) \ int SES_Get_##low(const struct sess *sp, typ *dst); \ diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 8dedfca..792964b 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -240,6 +240,9 @@ SES_Proto_Sess(struct worker *wrk, void *arg) sp->sess_step = S_STP_H1NEWREQ; wrk->task.func = ses_proto_req; wrk->task.priv = req; + } else if (sp->sess_step < S_STP_PROXY_LAST) { + wrk->task.func = VPX_Proto_Sess; + wrk->task.priv = sp; } else { WRONG("Wrong session step"); } diff --git a/bin/varnishd/flint.sh b/bin/varnishd/flint.sh index 7a44dad..dfe59c2 100755 --- a/bin/varnishd/flint.sh +++ b/bin/varnishd/flint.sh @@ -20,11 +20,12 @@ flexelint \ -DVARNISH_VCL_DIR=\"foo\" \ cache/*.c \ common/*.c \ - storage/*.c \ - waiter/*.c \ hash/*.c \ http1/*.c \ mgt/*.c \ + proxy/*.c \ + storage/*.c \ + waiter/*.c \ ../../lib/libvarnish/*.c \ ../../lib/libvarnishcompat/execinfo.c \ ../../lib/libvcc/*.c \ diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c index 43e3430..404d3e7 100644 --- a/bin/varnishd/mgt/mgt_acceptor.c +++ b/bin/varnishd/mgt/mgt_acceptor.c @@ -183,6 +183,9 @@ MAC_Arg(const char *arg) if (av[2] == NULL || !strcmp(av[2], "HTTP/1")) { mh->first_step = S_STP_H1NEWSESS; mh->proto_name = "HTTP/1"; + } else if (!strcmp(av[2], "PROXY")) { + mh->first_step = S_STP_PROXYNEWSESS; + mh->proto_name = "PROXY"; } else { ARGV_ERR("Unknown protocol '%s'\n", av[2]); } diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c new file mode 100644 index 0000000..9f5ca90 --- /dev/null +++ b/bin/varnishd/proxy/cache_proxy_proto.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2015 Varnish Software AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include "config.h" + +#include "../cache/cache.h" + +void __match_proto__(task_func_t) +VPX_Proto_Sess(struct worker *wrk, void *priv) +{ + + (void)wrk; + (void)priv; + INCOMPL(); +} diff --git a/include/tbl/steps.h b/include/tbl/steps.h index e9a1b3d..50896b3 100644 --- a/include/tbl/steps.h +++ b/include/tbl/steps.h @@ -35,6 +35,9 @@ SESS_STEP(h1newsess, H1NEWSESS) SESS_STEP(h1newreq, H1NEWREQ) SESS_STEP(h1working, H1WORKING) SESS_STEP(h1_last, H1_LAST) + +SESS_STEP(proxynewsess, PROXYNEWSESS) +SESS_STEP(proxy_last, PROXY_LAST) #endif #ifdef REQ_STEP From phk at FreeBSD.org Mon Mar 23 13:41:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 14:41:46 +0100 Subject: [master] cba6253 Add -proto argument to specify listen protocols Message-ID: commit cba62530708ce89d56485ad54aab5baa6286a0d8 Author: Poul-Henning Kamp Date: Mon Mar 23 10:17:31 2015 +0000 Add -proto argument to specify listen protocols diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 9f3a305..1fbc473 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -69,6 +69,7 @@ struct varnish { int vcl_nbr; char *workdir; char *jail; + char *proto; struct VSM_data *vd; /* vsc use */ @@ -396,6 +397,8 @@ varnish_launch(struct varnish *v) VSB_printf(vsb, " -p thread_pool_min=10"); VSB_printf(vsb, " -p debug=+vtc_mode"); VSB_printf(vsb, " -a '%s'", "127.0.0.1:0"); + if (v->proto != NULL) + VSB_printf(vsb, ",%s", v->proto); VSB_printf(vsb, " -M '%s %s'", abuf, pbuf); VSB_printf(vsb, " -P %s/varnishd.pid", v->workdir); VSB_printf(vsb, " %s", VSB_data(v->args)); @@ -887,13 +890,6 @@ cmd_varnish(CMD_ARGS) for (; *av != NULL; av++) { if (vtc_error) break; - if (!strcmp(*av, "-jail")) { - AN(av[1]); - AZ(v->pid); - REPLACE(v->jail, av[1]); - av++; - continue; - } if (!strcmp(*av, "-arg")) { AN(av[1]); AZ(v->pid); @@ -908,12 +904,6 @@ cmd_varnish(CMD_ARGS) av++; continue; } - if (!strcmp(*av, "-cliok")) { - AN(av[1]); - varnish_cli(v, av[1], (unsigned)CLIS_OK); - av++; - continue; - } if (!strcmp(*av, "-clierr")) { AN(av[1]); AN(av[2]); @@ -921,13 +911,9 @@ cmd_varnish(CMD_ARGS) av += 2; continue; } - if (!strcmp(*av, "-start")) { - varnish_start(v); - continue; - } - if (!strcmp(*av, "-vcl+backend")) { + if (!strcmp(*av, "-cliok")) { AN(av[1]); - varnish_vclbackend(v, av[1]); + varnish_cli(v, av[1], (unsigned)CLIS_OK); av++; continue; } @@ -948,16 +934,46 @@ cmd_varnish(CMD_ARGS) av += 2; continue; } - if (!strcmp(*av, "-vcl")) { + if (!strcmp(*av, "-expect")) { + av++; + varnish_expect(v, av); + av += 2; + continue; + } + if (!strcmp(*av, "-jail")) { AN(av[1]); - varnish_vcl(v, av[1], CLIS_OK, NULL); + AZ(v->pid); + REPLACE(v->jail, av[1]); + av++; + continue; + } + if (!strcmp(*av, "-proto")) { + AN(av[1]); + AZ(v->pid); + REPLACE(v->proto, av[1]); av++; continue; } + if (!strcmp(*av, "-start")) { + varnish_start(v); + continue; + } if (!strcmp(*av, "-stop")) { varnish_stop(v); continue; } + if (!strcmp(*av, "-vcl")) { + AN(av[1]); + varnish_vcl(v, av[1], CLIS_OK, NULL); + av++; + continue; + } + if (!strcmp(*av, "-vcl+backend")) { + AN(av[1]); + varnish_vclbackend(v, av[1]); + av++; + continue; + } if (!strcmp(*av, "-wait-stopped")) { wait_stopped(v); continue; @@ -970,12 +986,6 @@ cmd_varnish(CMD_ARGS) varnish_wait(v); continue; } - if (!strcmp(*av, "-expect")) { - av++; - varnish_expect(v, av); - av += 2; - continue; - } vtc_log(v->vl, 0, "Unknown varnish argument: %s", *av); } } From phk at FreeBSD.org Mon Mar 23 13:41:46 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 14:41:46 +0100 Subject: [master] 6f39693 Move the primitives for buffered reads on sockets into cache_session.c (for lack of any better place) since they will become involved in protocol switching. Message-ID: commit 6f396932bbcdb1d33475b66f83bbb7288cf12aee Author: Poul-Henning Kamp Date: Mon Mar 23 11:01:45 2015 +0000 Move the primitives for buffered reads on sockets into cache_session.c (for lack of any better place) since they will become involved in protocol switching. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index c39edc6..6619c5a 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -853,19 +853,7 @@ enum sess_close http_DoConnection(struct http *hp); /* cache_http1_proto.c */ -enum http1_status_e { - HTTP1_ALL_WHITESPACE = -3, - HTTP1_OVERFLOW = -2, - HTTP1_ERROR_EOF = -1, - HTTP1_NEED_MORE = 0, - HTTP1_COMPLETE = 1 -}; - -void HTTP1_RxInit(struct http_conn *htc, struct ws *ws, - unsigned maxbytes, unsigned maxhdr); -enum http1_status_e HTTP1_Reinit(struct http_conn *htc); -enum http1_status_e HTTP1_Rx(struct http_conn *htc); -enum http1_status_e HTTP1_Complete(struct http_conn *htc); +enum htc_status_e HTTP1_Complete(struct http_conn *htc); uint16_t HTTP1_DissectRequest(struct http_conn *htc, struct http *hp); uint16_t HTTP1_DissectResponse(struct http *sp, struct http_conn *htc); unsigned HTTP1_Write(const struct worker *w, const struct http *hp, const int*); @@ -995,6 +983,19 @@ struct req *SES_GetReq(const struct worker *, struct sess *); void SES_ReleaseReq(struct req *); task_func_t SES_Proto_Sess; +enum htc_status_e { + HTC_S_EMPTY = -3, + HTC_S_OVERFLOW = -2, + HTC_S_EOF = -1, + HTC_S_OK = 0, + HTC_S_COMPLETE = 1 +}; + +void SES_RxInit(struct http_conn *htc, struct ws *ws, + unsigned maxbytes, unsigned maxhdr); +void SES_RxReInit(struct http_conn *htc); +enum htc_status_e SES_Rx(struct http_conn *htc); + #define SESS_ATTR(UP, low, typ, len) \ int SES_Get_##low(const struct sess *sp, typ *dst); \ void SES_Reserve_##low(struct sess *sp, typ *dst); diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 792964b..d7d77a7 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -153,6 +153,84 @@ SES_Get_String_Attr(const struct sess *sp, enum sess_attr a) return (q); } +/*--------------------------------------------------------------------*/ + +void +SES_RxInit(struct http_conn *htc, struct ws *ws, unsigned maxbytes, + unsigned maxhdr) +{ + + htc->magic = HTTP_CONN_MAGIC; + htc->ws = ws; + htc->maxbytes = maxbytes; + htc->maxhdr = maxhdr; + + (void)WS_Reserve(htc->ws, htc->maxbytes); + htc->rxbuf_b = ws->f; + htc->rxbuf_e = ws->f; + *htc->rxbuf_e = '\0'; + htc->pipeline_b = NULL; + htc->pipeline_e = NULL; +} + +/*-------------------------------------------------------------------- + * Start over, and recycle any pipelined input. + * The WS_Reset is safe, even though the pipelined input is stored in + * the ws somewhere, because WS_Reset only fiddles pointers. + */ + +void +SES_RxReInit(struct http_conn *htc) +{ + ssize_t l; + + CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); + (void)WS_Reserve(htc->ws, htc->maxbytes); + htc->rxbuf_b = htc->ws->f; + htc->rxbuf_e = htc->ws->f; + if (htc->pipeline_b != NULL) { + l = htc->pipeline_e - htc->pipeline_b; + assert(l > 0); + memmove(htc->rxbuf_b, htc->pipeline_b, l); + htc->rxbuf_e += l; + htc->pipeline_b = NULL; + htc->pipeline_e = NULL; + } + *htc->rxbuf_e = '\0'; +} + +/*-------------------------------------------------------------------- + * Receive more HTTP protocol bytes + */ + +enum htc_status_e +SES_Rx(struct http_conn *htc) +{ + int i; + + CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); + AN(htc->ws->r); + AZ(htc->pipeline_b); + AZ(htc->pipeline_e); + i = (htc->ws->r - htc->rxbuf_e) - 1; /* space for NUL */ + if (i <= 0) { + WS_ReleaseP(htc->ws, htc->rxbuf_b); + return (HTC_S_OVERFLOW); + } + i = read(htc->fd, htc->rxbuf_e, i); + if (i <= 0) { + /* + * We wouldn't come here if we had a complete HTTP header + * so consequently an EOF can not be OK + */ + WS_ReleaseP(htc->ws, htc->rxbuf_b); + return (HTC_S_EOF); + } + htc->rxbuf_e += i; + *htc->rxbuf_e = '\0'; + return (HTC_S_OK); +} + /*-------------------------------------------------------------------- * Get a new session, preferably by recycling an already ready one * diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 1cb7959..6308b8c 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -76,7 +76,7 @@ int V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) { struct http *hp; - enum http1_status_e hs; + enum htc_status_e hs; int retry = 1; int j, first; ssize_t i; @@ -144,7 +144,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) /* Receive response */ - HTTP1_RxInit(htc, bo->ws, cache_param->http_resp_size, + SES_RxInit(htc, bo->ws, cache_param->http_resp_size, cache_param->http_resp_hdr_len); CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); CHECK_OBJ_NOTNULL(bo->htc, HTTP_CONN_MAGIC); @@ -153,8 +153,10 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) first = 1; do { - hs = HTTP1_Rx(htc); - if (hs == HTTP1_OVERFLOW) { + hs = SES_Rx(htc); + if (hs == HTC_S_OK) + hs = HTTP1_Complete(htc); + if (hs == HTC_S_OVERFLOW) { bo->acct.beresp_hdrbytes += htc->rxbuf_e - htc->rxbuf_b; VSLb(bo->vsl, SLT_FetchError, @@ -163,7 +165,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) bo->doclose = SC_RX_OVERFLOW; return (-1); } - if (hs == HTTP1_ERROR_EOF) { + if (hs == HTC_S_EOF) { bo->acct.beresp_hdrbytes += htc->rxbuf_e - htc->rxbuf_b; VSLb(bo->vsl, SLT_FetchError, "http %sread error: EOF", @@ -177,7 +179,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) VTCP_set_read_timeout(htc->fd, htc->between_bytes_timeout); } - } while (hs != HTTP1_COMPLETE); + } while (hs != HTC_S_COMPLETE); bo->acct.beresp_hdrbytes += htc->rxbuf_e - htc->rxbuf_b; hp = bo->beresp; diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index a88e4ca..698dc79 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -56,7 +56,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) struct pollfd pfd[1]; double now, when; enum sess_close why = SC_NULL; - enum http1_status_e hs; + enum htc_status_e hs; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); @@ -80,10 +80,12 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) assert(j >= 0); now = VTIM_real(); if (j != 0) - hs = HTTP1_Rx(req->htc); + hs = SES_Rx(req->htc); else + hs = HTC_S_OK; // XXX HTC_S_TIMEOUT ? + if (hs == HTC_S_OK) hs = HTTP1_Complete(req->htc); - if (hs == HTTP1_COMPLETE) { + if (hs == HTC_S_COMPLETE) { /* Got it, run with it */ if (isnan(req->t_first)) req->t_first = now; @@ -92,13 +94,13 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) req->acct.req_hdrbytes += req->htc->rxbuf_e - req->htc->rxbuf_b; return (REQ_FSM_MORE); - } else if (hs == HTTP1_ERROR_EOF) { + } else if (hs == HTC_S_EOF) { why = SC_REM_CLOSE; break; - } else if (hs == HTTP1_OVERFLOW) { + } else if (hs == HTC_S_OVERFLOW) { why = SC_RX_OVERFLOW; break; - } else if (hs == HTTP1_ALL_WHITESPACE) { + } else if (hs == HTC_S_EMPTY) { /* Nothing but whitespace */ when = sp->t_idle + cache_param->timeout_idle; if (when < now) { @@ -208,7 +210,8 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req) WS_Reset(req->ws, NULL); WS_Reset(wrk->aws, NULL); - if (HTTP1_Reinit(req->htc) == HTTP1_COMPLETE) { + SES_RxReInit(req->htc); + if (HTTP1_Complete(req->htc) == HTC_S_COMPLETE) { AZ(req->vsl->wid); req->t_first = req->t_req = sp->t_idle; wrk->stats->sess_pipeline++; @@ -372,7 +375,7 @@ HTTP1_Session(struct worker *wrk, struct req *req) if (sp->sess_step == S_STP_H1NEWREQ) { req->htc->fd = sp->fd; - HTTP1_RxInit(req->htc, req->ws, + SES_RxInit(req->htc, req->ws, cache_param->http_req_size, cache_param->http_req_hdr_len); } diff --git a/bin/varnishd/http1/cache_http1_proto.c b/bin/varnishd/http1/cache_http1_proto.c index 15e4b77..28cbc0f 100644 --- a/bin/varnishd/http1/cache_http1_proto.c +++ b/bin/varnishd/http1/cache_http1_proto.c @@ -57,58 +57,11 @@ const int HTTP1_Resp[3] = { HTTP_HDR_PROTO, HTTP_HDR_STATUS, HTTP_HDR_REASON }; -/*--------------------------------------------------------------------*/ - -void -HTTP1_RxInit(struct http_conn *htc, struct ws *ws, unsigned maxbytes, - unsigned maxhdr) -{ - - htc->magic = HTTP_CONN_MAGIC; - htc->ws = ws; - htc->maxbytes = maxbytes; - htc->maxhdr = maxhdr; - - (void)WS_Reserve(htc->ws, htc->maxbytes); - htc->rxbuf_b = ws->f; - htc->rxbuf_e = ws->f; - *htc->rxbuf_e = '\0'; - htc->pipeline_b = NULL; - htc->pipeline_e = NULL; -} - -/*-------------------------------------------------------------------- - * Start over, and recycle any pipelined input. - * The WS_Reset is safe, even though the pipelined input is stored in - * the ws somewhere, because WS_Reset only fiddles pointers. - */ - -enum http1_status_e -HTTP1_Reinit(struct http_conn *htc) -{ - ssize_t l; - - CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); - (void)WS_Reserve(htc->ws, htc->maxbytes); - htc->rxbuf_b = htc->ws->f; - htc->rxbuf_e = htc->ws->f; - if (htc->pipeline_b != NULL) { - l = htc->pipeline_e - htc->pipeline_b; - assert(l > 0); - memmove(htc->rxbuf_b, htc->pipeline_b, l); - htc->rxbuf_e += l; - htc->pipeline_b = NULL; - htc->pipeline_e = NULL; - } - *htc->rxbuf_e = '\0'; - return (HTTP1_Complete(htc)); -} - /*-------------------------------------------------------------------- * Check if we have a complete HTTP request or response yet */ -enum http1_status_e +enum htc_status_e HTTP1_Complete(struct http_conn *htc) { char *p; @@ -127,12 +80,12 @@ HTTP1_Complete(struct http_conn *htc) /* All white space */ htc->rxbuf_e = htc->rxbuf_b; *htc->rxbuf_e = '\0'; - return (HTTP1_ALL_WHITESPACE); + return (HTC_S_EMPTY); } while (1) { p = strchr(p, '\n'); if (p == NULL) - return (HTTP1_NEED_MORE); + return (HTC_S_OK); p++; if (*p == '\r') p++; @@ -146,39 +99,7 @@ HTTP1_Complete(struct http_conn *htc) htc->pipeline_e = htc->rxbuf_e; htc->rxbuf_e = p; } - return (HTTP1_COMPLETE); -} - -/*-------------------------------------------------------------------- - * Receive more HTTP protocol bytes - */ - -enum http1_status_e -HTTP1_Rx(struct http_conn *htc) -{ - int i; - - CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); - AN(htc->ws->r); - AZ(htc->pipeline_b); - AZ(htc->pipeline_e); - i = (htc->ws->r - htc->rxbuf_e) - 1; /* space for NUL */ - if (i <= 0) { - WS_ReleaseP(htc->ws, htc->rxbuf_b); - return (HTTP1_OVERFLOW); - } - i = read(htc->fd, htc->rxbuf_e, i); - if (i <= 0) { - /* - * We wouldn't come here if we had a complete HTTP header - * so consequently an EOF can not be OK - */ - WS_ReleaseP(htc->ws, htc->rxbuf_b); - return (HTTP1_ERROR_EOF); - } - htc->rxbuf_e += i; - *htc->rxbuf_e = '\0'; - return (HTTP1_Complete(htc)); + return (HTC_S_COMPLETE); } /*-------------------------------------------------------------------- From phk at FreeBSD.org Mon Mar 23 13:41:47 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 14:41:47 +0100 Subject: [master] 76da770 Optimistically setup session file descriptor for HTC reception no matter what protocol, a request is quite likely to happen soon-ish. Message-ID: commit 76da77000c2114f9654942516218629bb948368a Author: Poul-Henning Kamp Date: Mon Mar 23 13:37:27 2015 +0000 Optimistically setup session file descriptor for HTC reception no matter what protocol, a request is quite likely to happen soon-ish. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 6619c5a..a26a383 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -982,6 +982,7 @@ int SES_Reschedule_Req(struct req *); struct req *SES_GetReq(const struct worker *, struct sess *); void SES_ReleaseReq(struct req *); task_func_t SES_Proto_Sess; +task_func_t SES_Proto_Req; enum htc_status_e { HTC_S_EMPTY = -3, diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index d7d77a7..2e7f784 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -48,6 +48,7 @@ #include "waiter/waiter.h" #include "vsa.h" +#include "vtcp.h" #include "vtim.h" /*--------------------------------------------------------------------*/ @@ -270,8 +271,8 @@ SES_New(struct sesspool *pp) * Call protocol for this request */ -static void __match_proto__(task_func_t) -ses_proto_req(struct worker *wrk, void *arg) +void __match_proto__(task_func_t) +SES_Proto_Req(struct worker *wrk, void *arg) { struct req *req; @@ -312,15 +313,24 @@ SES_Proto_Sess(struct worker *wrk, void *arg) CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC); WS_Release(sp->ws, 0); + /* + * Assume we're going to receive something that will likely + * involve a request... + */ + (void)VTCP_blocking(sp->fd); + req = SES_GetReq(wrk, sp); + CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + req->htc->fd = sp->fd; + SES_RxInit(req->htc, req->ws, + cache_param->http_req_size, cache_param->http_req_hdr_len); + if (sp->sess_step < S_STP_H1_LAST) { - req = SES_GetReq(wrk, sp); - CHECK_OBJ_NOTNULL(req, REQ_MAGIC); sp->sess_step = S_STP_H1NEWREQ; - wrk->task.func = ses_proto_req; + wrk->task.func = SES_Proto_Req; wrk->task.priv = req; } else if (sp->sess_step < S_STP_PROXY_LAST) { wrk->task.func = VPX_Proto_Sess; - wrk->task.priv = sp; + wrk->task.priv = req; } else { WRONG("Wrong session step"); } @@ -345,7 +355,7 @@ SES_Reschedule_Req(struct req *req) CHECK_OBJ_NOTNULL(pp, SESSPOOL_MAGIC); AN(pp->pool); - req->task.func = ses_proto_req; + req->task.func = SES_Proto_Req; req->task.priv = req; return (Pool_Task(pp->pool, &req->task, POOL_QUEUE_FRONT)); diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 698dc79..706f03f 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -373,12 +373,6 @@ HTTP1_Session(struct worker *wrk, struct req *req) return; } - if (sp->sess_step == S_STP_H1NEWREQ) { - req->htc->fd = sp->fd; - SES_RxInit(req->htc, req->ws, - cache_param->http_req_size, cache_param->http_req_hdr_len); - } - while (1) { assert( sp->sess_step == S_STP_H1NEWREQ || From fgsch at lodoss.net Mon Mar 23 15:57:26 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 23 Mar 2015 16:57:26 +0100 Subject: [master] 458b38e Add the SLT_F_BINARY flag to SLT_Hash Message-ID: commit 458b38e25bb1635bddacea4734a4d2a6567a02e7 Author: Federico G. Schwindt Date: Mon Mar 23 13:04:18 2015 +0000 Add the SLT_F_BINARY flag to SLT_Hash It might contain non-printable chars. diff --git a/include/tbl/vsl_tags.h b/include/tbl/vsl_tags.h index 7af249f..4080c5d 100644 --- a/include/tbl/vsl_tags.h +++ b/include/tbl/vsl_tags.h @@ -334,7 +334,7 @@ SLTM(ESI_xmlerror, 0, "ESI parser error or warning message", " The log record describes the problem encountered." ) -SLTM(Hash, 0, "Value added to hash", +SLTM(Hash, SLT_F_BINARY, "Value added to hash", "This value was added to the object lookup hash.\n\n" NODEF_NOTICE ) From fgsch at lodoss.net Mon Mar 23 15:57:26 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 23 Mar 2015 16:57:26 +0100 Subject: [master] 7cbfb2d Log hash_data() input when the Hash bit is set Message-ID: commit 7cbfb2d7f650538a01225329723ed51bc9f5db80 Author: Federico G. Schwindt Date: Mon Mar 23 12:39:19 2015 +0000 Log hash_data() input when the Hash bit is set Fixes #1693. diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c index b3d3ac8..ccd80ad 100644 --- a/bin/varnishd/cache/cache_hash.c +++ b/bin/varnishd/cache/cache_hash.c @@ -187,14 +187,15 @@ HSH_DeleteObjHead(struct worker *wrk, struct objhead *oh) } void -HSH_AddString(const struct req *req, const char *str) +HSH_AddString(struct req *req, const char *str) { CHECK_OBJ_NOTNULL(req, REQ_MAGIC); AN(req->sha256ctx); - if (str != NULL) + if (str != NULL) { SHA256_Update(req->sha256ctx, str, strlen(str)); - else + VSLb(req->vsl, SLT_Hash, "%s", str); + } else SHA256_Update(req->sha256ctx, &str, sizeof str); } diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c index 6851bc0..63d2502 100644 --- a/bin/varnishd/cache/cache_vrt.c +++ b/bin/varnishd/cache/cache_vrt.c @@ -271,7 +271,6 @@ VRT_hashdata(VRT_CTX, const char *str, ...) if (p == vrt_magic_string_end) break; HSH_AddString(ctx->req, p); - VSLb(ctx->vsl, SLT_Hash, "%s", str); } va_end(ap); /* diff --git a/bin/varnishd/hash/hash_slinger.h b/bin/varnishd/hash/hash_slinger.h index 189f938..6f546ff 100644 --- a/bin/varnishd/hash/hash_slinger.h +++ b/bin/varnishd/hash/hash_slinger.h @@ -67,7 +67,7 @@ enum lookup_e HSH_Lookup(struct req *, struct objcore **, struct objcore **, int wait_for_busy, int always_insert); void HSH_Ref(struct objcore *o); void HSH_Init(const struct hash_slinger *slinger); -void HSH_AddString(const struct req *, const char *str); +void HSH_AddString(struct req *, const char *str); void HSH_Insert(struct worker *, const void *hash, struct objcore *); void HSH_Purge(struct worker *, struct objhead *, double ttl, double grace, double keep); diff --git a/bin/varnishtest/tests/r01693.vtc b/bin/varnishtest/tests/r01693.vtc new file mode 100644 index 0000000..f16d620 --- /dev/null +++ b/bin/varnishtest/tests/r01693.vtc @@ -0,0 +1,27 @@ +varnishtest "Check hash is logged when the Hash bit is set" + +server s1 { + rxreq + txresp +} -start + +varnish v1 -arg "-p vsl_mask=+Hash" -vcl+backend { + sub vcl_hash { + hash_data("1" + req.http.foo + "3"); + } +} -start + +logexpect l1 -v v1 { + expect * 1001 Hash "1" + expect 0 1001 Hash "bar" + expect 0 1001 Hash "3" + expect 0 1001 Hash "/" + expect 0 1001 Hash "127.0.0.1" +} -start + +client c1 { + txreq -hdr "foo: bar" + rxresp +} -run + +logexpect l1 -wait From fgsch at lodoss.net Mon Mar 23 17:14:04 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 23 Mar 2015 18:14:04 +0100 Subject: [master] a64da71 Fix expect cases without ident Message-ID: commit a64da7176457e91d45b8ee4c264e3abec682122b Author: Federico G. Schwindt Date: Mon Mar 23 17:02:53 2015 +0000 Fix expect cases without ident diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c index 1fbc473..490171e 100644 --- a/bin/varnishtest/vtc_varnish.c +++ b/bin/varnishtest/vtc_varnish.c @@ -786,11 +786,13 @@ varnish_expect(const struct varnish *v, char * const *av) { bprintf(sp.target_type, "%.*s", (int)(p - r), r); p++; q = strrchr(p, '.'); - bprintf(sp.target_name, "%s", q + 1); - if (q == p) + if (q == NULL) { sp.target_ident[0] = '\0'; - else + bprintf(sp.target_name, "%s", p); + } else { bprintf(sp.target_ident, "%.*s", (int)(q - p), p); + bprintf(sp.target_name, "%s", q + 1); + } } sp.val = 0; From fgsch at lodoss.net Mon Mar 23 17:14:04 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Mon, 23 Mar 2015 18:14:04 +0100 Subject: [master] b3a74ff Allow to reset the child_panic counter Message-ID: commit b3a74ff9a50a7a658edbfce2860a598faa286ae4 Author: Federico G. Schwindt Date: Mon Mar 23 17:04:21 2015 +0000 Allow to reset the child_panic counter panic.clear gains a -z optional parameter. Fixes #1609. diff --git a/bin/varnishd/mgt/mgt_child.c b/bin/varnishd/mgt/mgt_child.c index e67b419..9ce3aaa 100644 --- a/bin/varnishd/mgt/mgt_child.c +++ b/bin/varnishd/mgt/mgt_child.c @@ -159,9 +159,17 @@ mcf_panic_show(struct cli *cli, const char * const *av, void *priv) void __match_proto__(cli_func_t) mcf_panic_clear(struct cli *cli, const char * const *av, void *priv) { - (void)av; (void)priv; + if (av[2] != NULL && strcmp(av[2], "-z")) { + VCLI_SetResult(cli, CLIS_PARAM); + VCLI_Out(cli, "Unknown parameter \"%s\".", av[2]); + return; + } else if (av[2] != NULL) { + VSC_C_mgt->child_panic = static_VSC_C_mgt.child_panic = 0; + if (child_panic == NULL) + return; + } if (child_panic == NULL) { VCLI_SetResult(cli, CLIS_CANT); VCLI_Out(cli, "No panic to clear"); diff --git a/bin/varnishtest/tests/v00010.vtc b/bin/varnishtest/tests/v00010.vtc index 2fb3511..7b0d57e 100644 --- a/bin/varnishtest/tests/v00010.vtc +++ b/bin/varnishtest/tests/v00010.vtc @@ -49,6 +49,7 @@ client c1 { varnish v1 -wait-stopped varnish v1 -cliok "panic.show" varnish v1 -cliok "panic.clear" +varnish v1 -expect MGT.child_panic == 1 varnish v1 -clierr 300 "panic.clear" varnish v1 -cliok "start" varnish v1 -wait-running @@ -65,7 +66,8 @@ client c1 { varnish v1 -wait-stopped varnish v1 -cliok "panic.show" -varnish v1 -cliok "panic.clear" +varnish v1 -cliok "panic.clear -z" +varnish v1 -expect MGT.child_panic == 0 varnish v1 -clierr 300 "panic.clear" varnish v1 -cliok "start" varnish v1 -wait-running @@ -78,3 +80,5 @@ client c1 { rxresp expect resp.http.foo == "foo" } -run + +varnish v1 -cliok "panic.clear -z" diff --git a/doc/sphinx/reference/varnish-cli.rst b/doc/sphinx/reference/varnish-cli.rst index 663dcd2..e400408 100644 --- a/doc/sphinx/reference/varnish-cli.rst +++ b/doc/sphinx/reference/varnish-cli.rst @@ -128,7 +128,7 @@ param.set panic.show Return the last panic, if any. -panic.clear +panic.clear [-z] Clear the last panic, if any. storage.list diff --git a/include/vcli.h b/include/vcli.h index 32d3e70..da61d30 100644 --- a/include/vcli.h +++ b/include/vcli.h @@ -167,9 +167,9 @@ #define CLI_PANIC_CLEAR \ "panic.clear", \ - "panic.clear", \ + "panic.clear [-z]", \ "\tClear the last panic, if any.", \ - 0, 0 + 0, 1 /* * Status/return codes in the CLI protocol From phk at FreeBSD.org Mon Mar 23 20:19:51 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 21:19:51 +0100 Subject: [master] 8e216d5 Make it the callers responsibility to release the workspace Message-ID: commit 8e216d58e83a65e9e3c85fbbaa0d6de2469cce20 Author: Poul-Henning Kamp Date: Mon Mar 23 20:19:31 2015 +0000 Make it the callers responsibility to release the workspace diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 2e7f784..ca0a539 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -214,19 +214,11 @@ SES_Rx(struct http_conn *htc) AZ(htc->pipeline_b); AZ(htc->pipeline_e); i = (htc->ws->r - htc->rxbuf_e) - 1; /* space for NUL */ - if (i <= 0) { - WS_ReleaseP(htc->ws, htc->rxbuf_b); + if (i <= 0) return (HTC_S_OVERFLOW); - } i = read(htc->fd, htc->rxbuf_e, i); - if (i <= 0) { - /* - * We wouldn't come here if we had a complete HTTP header - * so consequently an EOF can not be OK - */ - WS_ReleaseP(htc->ws, htc->rxbuf_b); + if (i <= 0) return (HTC_S_EOF); - } htc->rxbuf_e += i; *htc->rxbuf_e = '\0'; return (HTC_S_OK); diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 6308b8c..855268b 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -157,6 +157,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) if (hs == HTC_S_OK) hs = HTTP1_Complete(htc); if (hs == HTC_S_OVERFLOW) { + WS_ReleaseP(htc->ws, htc->rxbuf_b); bo->acct.beresp_hdrbytes += htc->rxbuf_e - htc->rxbuf_b; VSLb(bo->vsl, SLT_FetchError, @@ -166,6 +167,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) return (-1); } if (hs == HTC_S_EOF) { + WS_ReleaseP(htc->ws, htc->rxbuf_b); bo->acct.beresp_hdrbytes += htc->rxbuf_e - htc->rxbuf_b; VSLb(bo->vsl, SLT_FetchError, "http %sread error: EOF", diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 706f03f..75ab85a 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -95,9 +95,11 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) req->htc->rxbuf_e - req->htc->rxbuf_b; return (REQ_FSM_MORE); } else if (hs == HTC_S_EOF) { + WS_ReleaseP(req->htc->ws, req->htc->rxbuf_b); why = SC_REM_CLOSE; break; } else if (hs == HTC_S_OVERFLOW) { + WS_ReleaseP(req->htc->ws, req->htc->rxbuf_b); why = SC_RX_OVERFLOW; break; } else if (hs == HTC_S_EMPTY) { From phk at FreeBSD.org Mon Mar 23 21:32:12 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 22:32:12 +0100 Subject: [master] 9fec444 Give SES_Rx() a timeout argument, and take that bit of complexity out of http1_wait() Message-ID: commit 9fec4441ad54514be6cb06f80882cf148689aa13 Author: Poul-Henning Kamp Date: Mon Mar 23 21:31:20 2015 +0000 Give SES_Rx() a timeout argument, and take that bit of complexity out of http1_wait() diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index a26a383..15ac93e 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -985,17 +985,18 @@ task_func_t SES_Proto_Sess; task_func_t SES_Proto_Req; enum htc_status_e { - HTC_S_EMPTY = -3, + HTC_S_EMPTY = -4, + HTC_S_TIMEOUT = -3, HTC_S_OVERFLOW = -2, - HTC_S_EOF = -1, - HTC_S_OK = 0, + HTC_S_EOF = -1, + HTC_S_OK = 0, HTC_S_COMPLETE = 1 }; void SES_RxInit(struct http_conn *htc, struct ws *ws, unsigned maxbytes, unsigned maxhdr); void SES_RxReInit(struct http_conn *htc); -enum htc_status_e SES_Rx(struct http_conn *htc); +enum htc_status_e SES_Rx(struct http_conn *htc, double tmo); #define SESS_ATTR(UP, low, typ, len) \ int SES_Get_##low(const struct sess *sp, typ *dst); \ diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index ca0a539..b54fb0a 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -41,6 +41,7 @@ #include "config.h" #include +#include #include #include @@ -205,9 +206,10 @@ SES_RxReInit(struct http_conn *htc) */ enum htc_status_e -SES_Rx(struct http_conn *htc) +SES_Rx(struct http_conn *htc, double tmo) { - int i; + int i, j; + struct pollfd pfd[1]; CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC); AN(htc->ws->r); @@ -216,6 +218,17 @@ SES_Rx(struct http_conn *htc) i = (htc->ws->r - htc->rxbuf_e) - 1; /* space for NUL */ if (i <= 0) return (HTC_S_OVERFLOW); + if (tmo > 0.0) { + pfd[0].fd = htc->fd; + pfd[0].events = POLLIN; + pfd[0].revents = 0; + j = (int)floor(tmo * 1e3); + if (j == 0) + j++; + j = poll(pfd, 1, j); + if (j == 0) + return (HTC_S_TIMEOUT); + } i = read(htc->fd, htc->rxbuf_e, i); if (i <= 0) return (HTC_S_EOF); diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index 855268b..bae29c5 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -153,7 +153,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) first = 1; do { - hs = SES_Rx(htc); + hs = SES_Rx(htc, 0); if (hs == HTC_S_OK) hs = HTTP1_Complete(htc); if (hs == HTC_S_OVERFLOW) { diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 75ab85a..e17e2bd 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -34,7 +34,6 @@ #include "config.h" #include -#include #include #include @@ -52,8 +51,7 @@ static enum req_fsm_nxt http1_wait(struct sess *sp, struct worker *wrk, struct req *req) { - int j, tmo; - struct pollfd pfd[1]; + int tmo; double now, when; enum sess_close why = SC_NULL; enum htc_status_e hs; @@ -71,19 +69,11 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) assert(isnan(req->t_prev)); assert(isnan(req->t_req)); - tmo = (int)(1e3 * cache_param->timeout_linger); + tmo = (int)floor(1e3 * cache_param->timeout_linger); while (1) { - pfd[0].fd = sp->fd; - pfd[0].events = POLLIN; - pfd[0].revents = 0; - j = poll(pfd, 1, tmo); - assert(j >= 0); + hs = SES_Rx(req->htc, tmo * 1e3); now = VTIM_real(); - if (j != 0) - hs = SES_Rx(req->htc); - else - hs = HTC_S_OK; // XXX HTC_S_TIMEOUT ? - if (hs == HTC_S_OK) + if (hs == HTC_S_OK || hs == HTC_S_TIMEOUT) hs = HTTP1_Complete(req->htc); if (hs == HTC_S_COMPLETE) { /* Got it, run with it */ @@ -110,7 +100,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) break; } when = sp->t_idle + cache_param->timeout_linger; - tmo = (int)(1e3 * (when - now)); + tmo = (int)floor(1e3 * (when - now)); if (when < now || tmo == 0) { wrk->stats->sess_herd++; SES_ReleaseReq(req); @@ -126,7 +116,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) /* Record first byte received time stamp */ req->t_first = now; when = req->t_first + cache_param->timeout_req; - tmo = (int)(1e3 * (when - now)); + tmo = (int)floor(1e3 * (when - now)); if (when < now || tmo == 0) { why = SC_RX_TIMEOUT; break; From phk at FreeBSD.org Mon Mar 23 22:39:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Mon, 23 Mar 2015 23:39:48 +0100 Subject: [master] a0effd4 Simplify the timeout math a bit Message-ID: commit a0effd4d02f2b3ec188ab7b43b0014f66263c3b0 Author: Poul-Henning Kamp Date: Mon Mar 23 22:39:30 2015 +0000 Simplify the timeout math a bit diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index e17e2bd..0cddb2e 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -51,7 +51,7 @@ static enum req_fsm_nxt http1_wait(struct sess *sp, struct worker *wrk, struct req *req) { - int tmo; + double tmo; double now, when; enum sess_close why = SC_NULL; enum htc_status_e hs; @@ -69,9 +69,9 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) assert(isnan(req->t_prev)); assert(isnan(req->t_req)); - tmo = (int)floor(1e3 * cache_param->timeout_linger); + tmo = cache_param->timeout_linger; while (1) { - hs = SES_Rx(req->htc, tmo * 1e3); + hs = SES_Rx(req->htc, tmo); now = VTIM_real(); if (hs == HTC_S_OK || hs == HTC_S_TIMEOUT) hs = HTTP1_Complete(req->htc); @@ -100,8 +100,8 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) break; } when = sp->t_idle + cache_param->timeout_linger; - tmo = (int)floor(1e3 * (when - now)); - if (when < now || tmo == 0) { + tmo = when - now; + if (tmo <= 0) { wrk->stats->sess_herd++; SES_ReleaseReq(req); if (VTCP_nonblocking(sp->fd)) @@ -116,8 +116,8 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) /* Record first byte received time stamp */ req->t_first = now; when = req->t_first + cache_param->timeout_req; - tmo = (int)floor(1e3 * (when - now)); - if (when < now || tmo == 0) { + tmo = when - now; + if (tmo <= 0) { why = SC_RX_TIMEOUT; break; } From phk at FreeBSD.org Tue Mar 24 12:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 24 Mar 2015 13:02:48 +0100 Subject: [master] dedff8e Untangle code slightly. Message-ID: commit dedff8e11fdabe1f175451e7fdf2f93f8a56f882 Author: Poul-Henning Kamp Date: Tue Mar 24 08:54:23 2015 +0000 Untangle code slightly. diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 0cddb2e..60bec64 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -136,13 +136,7 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) * the client connection */ -enum http1_cleanup_ret { - SESS_DONE_RET_GONE, - SESS_DONE_RET_WAIT, - SESS_DONE_RET_START, -}; - -static enum http1_cleanup_ret +static int http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req) { @@ -196,25 +190,12 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req) AZ(req->vcl); SES_ReleaseReq(req); SES_Delete(sp, SC_NULL, NAN); - return (SESS_DONE_RET_GONE); + return (1); } WS_Reset(req->ws, NULL); WS_Reset(wrk->aws, NULL); - - SES_RxReInit(req->htc); - if (HTTP1_Complete(req->htc) == HTC_S_COMPLETE) { - AZ(req->vsl->wid); - req->t_first = req->t_req = sp->t_idle; - wrk->stats->sess_pipeline++; - req->acct.req_hdrbytes += - req->htc->rxbuf_e - req->htc->rxbuf_b; - return (SESS_DONE_RET_START); - } else { - if (req->htc->rxbuf_e != req->htc->rxbuf_b) - wrk->stats->sess_readahead++; - return (SESS_DONE_RET_WAIT); - } + return (0); } /*---------------------------------------------------------------------- @@ -329,7 +310,6 @@ HTTP1_Session(struct worker *wrk, struct req *req) { enum req_fsm_nxt nxt = REQ_FSM_MORE; struct sess *sp; - enum http1_cleanup_ret sdr; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(req, REQ_MAGIC); @@ -347,8 +327,7 @@ HTTP1_Session(struct worker *wrk, struct req *req) SES_Close(sp, SC_REM_CLOSE); else SES_Close(sp, SC_TX_ERROR); - sdr = http1_cleanup(sp, wrk, req); - assert(sdr == SESS_DONE_RET_GONE); + AN(http1_cleanup(sp, wrk, req)); return; } @@ -360,8 +339,7 @@ HTTP1_Session(struct worker *wrk, struct req *req) (void)HSH_DerefObjHead(wrk, &req->hash_objhead); AZ(req->hash_objhead); SES_Close(sp, SC_REM_CLOSE); - sdr = http1_cleanup(sp, wrk, req); - assert(sdr == SESS_DONE_RET_GONE); + AN(http1_cleanup(sp, wrk, req)); return; } @@ -379,19 +357,21 @@ HTTP1_Session(struct worker *wrk, struct req *req) if (nxt == REQ_FSM_DISEMBARK) return; assert(nxt == REQ_FSM_DONE); - sdr = http1_cleanup(sp, wrk, req); - switch (sdr) { - case SESS_DONE_RET_GONE: + if (http1_cleanup(sp, wrk, req)) return; - case SESS_DONE_RET_WAIT: - sp->sess_step = S_STP_H1NEWREQ; - break; - case SESS_DONE_RET_START: + SES_RxReInit(req->htc); + if (HTTP1_Complete(req->htc) == HTC_S_COMPLETE) { + AZ(req->vsl->wid); + req->t_first = req->t_req = sp->t_idle; + wrk->stats->sess_pipeline++; + req->acct.req_hdrbytes += + req->htc->rxbuf_e - req->htc->rxbuf_b; sp->sess_step = S_STP_H1WORKING; req->req_step = R_STP_RECV; - break; - default: - WRONG("Illegal enum http1_cleanup_ret"); + } else { + if (req->htc->rxbuf_e != req->htc->rxbuf_b) + wrk->stats->sess_readahead++; + sp->sess_step = S_STP_H1NEWREQ; } } From phk at FreeBSD.org Tue Mar 24 12:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 24 Mar 2015 13:02:48 +0100 Subject: [master] fb71118 Try to make the H1 state engine look more like one. Message-ID: commit fb711185114b2131a6e08d77e2bc6955e3c2f5d9 Author: Poul-Henning Kamp Date: Tue Mar 24 09:42:07 2015 +0000 Try to make the H1 state engine look more like one. diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 15ac93e..615b830 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -989,7 +989,7 @@ enum htc_status_e { HTC_S_TIMEOUT = -3, HTC_S_OVERFLOW = -2, HTC_S_EOF = -1, - HTC_S_OK = 0, + HTC_S_OK = 0, HTC_S_COMPLETE = 1 }; diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index b54fb0a..5ee4cfb 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -330,7 +330,6 @@ SES_Proto_Sess(struct worker *wrk, void *arg) cache_param->http_req_size, cache_param->http_req_hdr_len); if (sp->sess_step < S_STP_H1_LAST) { - sp->sess_step = S_STP_H1NEWREQ; wrk->task.func = SES_Proto_Req; wrk->task.priv = req; } else if (sp->sess_step < S_STP_PROXY_LAST) { diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 60bec64..2a3c3fb 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -331,31 +331,55 @@ HTTP1_Session(struct worker *wrk, struct req *req) return; } - /* - * Return from waitinglist. Check to see if the remote has left. - */ - if (req->req_step == R_STP_LOOKUP && VTCP_check_hup(sp->fd)) { - AN(req->hash_objhead); - (void)HSH_DerefObjHead(wrk, &req->hash_objhead); - AZ(req->hash_objhead); - SES_Close(sp, SC_REM_CLOSE); - AN(http1_cleanup(sp, wrk, req)); - return; - } while (1) { - assert( - sp->sess_step == S_STP_H1NEWREQ || - req->req_step == R_STP_LOOKUP || - req->req_step == R_STP_RECV); + switch (sp->sess_step) { + case S_STP_H1NEWSESS: + if (VTCP_blocking(sp->fd)) { + if (errno == ECONNRESET) + SES_Close(sp, SC_REM_CLOSE); + else + SES_Close(sp, SC_TX_ERROR); + AN(http1_cleanup(sp, wrk, req)); + return; + } + sp->sess_step = S_STP_H1NEWREQ; + break; + case S_STP_H1NEWREQ: + nxt = http1_wait(sp, wrk, req); + if (nxt != REQ_FSM_MORE) + return; + sp->sess_step = S_STP_H1WORKING; + req->req_step = R_STP_RECV; + break; + case S_STP_H1BUSY: + /* + * Return from waitinglist. + * Check to see if the remote has left. + */ + if (VTCP_check_hup(sp->fd)) { + AN(req->hash_objhead); + (void)HSH_DerefObjHead(wrk, &req->hash_objhead); + AZ(req->hash_objhead); + SES_Close(sp, SC_REM_CLOSE); + AN(http1_cleanup(sp, wrk, req)); + return; + } + sp->sess_step = S_STP_H1WORKING; + break; + case S_STP_H1WORKING: + assert( + req->req_step == R_STP_LOOKUP || + req->req_step == R_STP_RECV); - if (sp->sess_step == S_STP_H1WORKING) { if (req->req_step == R_STP_RECV) nxt = http1_dissect(wrk, req); if (nxt == REQ_FSM_MORE) nxt = CNT_Request(wrk, req); - if (nxt == REQ_FSM_DISEMBARK) + if (nxt == REQ_FSM_DISEMBARK) { + sp->sess_step = S_STP_H1BUSY; return; + } assert(nxt == REQ_FSM_DONE); if (http1_cleanup(sp, wrk, req)) return; @@ -373,14 +397,10 @@ HTTP1_Session(struct worker *wrk, struct req *req) wrk->stats->sess_readahead++; sp->sess_step = S_STP_H1NEWREQ; } + break; + default: + WRONG("Wrong H1 session state"); } - if (sp->sess_step == S_STP_H1NEWREQ) { - nxt = http1_wait(sp, wrk, req); - if (nxt != REQ_FSM_MORE) - return; - sp->sess_step = S_STP_H1WORKING; - req->req_step = R_STP_RECV; - } } } From phk at FreeBSD.org Tue Mar 24 12:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 24 Mar 2015 13:02:48 +0100 Subject: [master] 7bb2ddb And don't forget the new states Message-ID: commit 7bb2ddb15e30ebf44b164af79651950e2223ec20 Author: Poul-Henning Kamp Date: Tue Mar 24 09:42:31 2015 +0000 And don't forget the new states diff --git a/include/tbl/steps.h b/include/tbl/steps.h index 50896b3..5d93386 100644 --- a/include/tbl/steps.h +++ b/include/tbl/steps.h @@ -33,6 +33,7 @@ #ifdef SESS_STEP SESS_STEP(h1newsess, H1NEWSESS) SESS_STEP(h1newreq, H1NEWREQ) +SESS_STEP(h1busy, H1BUSY) SESS_STEP(h1working, H1WORKING) SESS_STEP(h1_last, H1_LAST) From phk at FreeBSD.org Tue Mar 24 12:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 24 Mar 2015 13:02:48 +0100 Subject: [master] 89ab873 Make http1_dissect() return a simple good/bad status. Message-ID: commit 89ab87370b41d4125e1cb1cf250df2709d856cb0 Author: Poul-Henning Kamp Date: Tue Mar 24 09:51:56 2015 +0000 Make http1_dissect() return a simple good/bad status. diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 2a3c3fb..ac76ca2 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -201,7 +201,7 @@ http1_cleanup(struct sess *sp, struct worker *wrk, struct req *req) /*---------------------------------------------------------------------- */ -static enum req_fsm_nxt +static int http1_dissect(struct worker *wrk, struct req *req) { const char *r_100 = "HTTP/1.1 100 Continue\r\n\r\n"; @@ -242,8 +242,8 @@ http1_dissect(struct worker *wrk, struct req *req) r = write(req->sp->fd, r_400, strlen(r_400)); if (r > 0) req->acct.resp_hdrbytes += r; - SES_Close(req->sp, SC_RX_JUNK); - return (REQ_FSM_DONE); + req->doclose = SC_RX_JUNK; + return (-1); } assert (req->req_body_status == REQ_BODY_INIT); @@ -267,15 +267,15 @@ http1_dissect(struct worker *wrk, struct req *req) r = write(req->sp->fd, r_417, strlen(r_417)); if (r > 0) req->acct.resp_hdrbytes += r; - SES_Close(req->sp, SC_RX_JUNK); - return (REQ_FSM_DONE); + req->doclose = SC_RX_JUNK; + return (-1); } r = write(req->sp->fd, r_100, strlen(r_100)); if (r > 0) req->acct.resp_hdrbytes += r; if (r != strlen(r_100)) { - SES_Close(req->sp, SC_REM_CLOSE); - return (REQ_FSM_DONE); + req->doclose = SC_REM_CLOSE; + return (-1); } http_Unset(req->http, H_Expect); } @@ -291,15 +291,14 @@ http1_dissect(struct worker *wrk, struct req *req) r = write(req->sp->fd, r_400, strlen(r_400)); if (r > 0) req->acct.resp_hdrbytes += r; - SES_Close(req->sp, req->doclose); - return (REQ_FSM_DONE); + return (-1); } assert(req->req_body_status != REQ_BODY_INIT); HTTP_Copy(req->http0, req->http); // For ESI & restart - return (REQ_FSM_MORE); + return (0); } /*---------------------------------------------------------------------- @@ -372,8 +371,14 @@ HTTP1_Session(struct worker *wrk, struct req *req) req->req_step == R_STP_LOOKUP || req->req_step == R_STP_RECV); - if (req->req_step == R_STP_RECV) - nxt = http1_dissect(wrk, req); + if (req->req_step == R_STP_RECV) { + if (http1_dissect(wrk, req)) { + SES_Close(req->sp, req->doclose); + nxt = REQ_FSM_DONE; + } else { + nxt = REQ_FSM_MORE; + } + } if (nxt == REQ_FSM_MORE) nxt = CNT_Request(wrk, req); if (nxt == REQ_FSM_DISEMBARK) { From phk at FreeBSD.org Tue Mar 24 12:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 24 Mar 2015 13:02:48 +0100 Subject: [master] a2d05b3 Now it is starting to look like a finite state engine... Message-ID: commit a2d05b3204cd8a7d5fdb4c36c998c30e5a5f074a Author: Poul-Henning Kamp Date: Tue Mar 24 10:04:10 2015 +0000 Now it is starting to look like a finite state engine... diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index ac76ca2..6f2bb68 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -349,7 +349,6 @@ HTTP1_Session(struct worker *wrk, struct req *req) if (nxt != REQ_FSM_MORE) return; sp->sess_step = S_STP_H1WORKING; - req->req_step = R_STP_RECV; break; case S_STP_H1BUSY: /* @@ -364,28 +363,25 @@ HTTP1_Session(struct worker *wrk, struct req *req) AN(http1_cleanup(sp, wrk, req)); return; } - sp->sess_step = S_STP_H1WORKING; + sp->sess_step = S_STP_H1PROC; break; case S_STP_H1WORKING: - assert( - req->req_step == R_STP_LOOKUP || - req->req_step == R_STP_RECV); - - if (req->req_step == R_STP_RECV) { - if (http1_dissect(wrk, req)) { - SES_Close(req->sp, req->doclose); - nxt = REQ_FSM_DONE; - } else { - nxt = REQ_FSM_MORE; - } + if (http1_dissect(wrk, req)) { + SES_Close(req->sp, req->doclose); + sp->sess_step = S_STP_H1CLEANUP; + break; } - if (nxt == REQ_FSM_MORE) - nxt = CNT_Request(wrk, req); - if (nxt == REQ_FSM_DISEMBARK) { + req->req_step = R_STP_RECV; + sp->sess_step = S_STP_H1PROC; + break; + case S_STP_H1PROC: + if (CNT_Request(wrk, req) == REQ_FSM_DISEMBARK) { sp->sess_step = S_STP_H1BUSY; return; } - assert(nxt == REQ_FSM_DONE); + sp->sess_step = S_STP_H1CLEANUP; + break; + case S_STP_H1CLEANUP: if (http1_cleanup(sp, wrk, req)) return; SES_RxReInit(req->htc); @@ -396,7 +392,6 @@ HTTP1_Session(struct worker *wrk, struct req *req) req->acct.req_hdrbytes += req->htc->rxbuf_e - req->htc->rxbuf_b; sp->sess_step = S_STP_H1WORKING; - req->req_step = R_STP_RECV; } else { if (req->htc->rxbuf_e != req->htc->rxbuf_b) wrk->stats->sess_readahead++; From phk at FreeBSD.org Tue Mar 24 12:02:48 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Tue, 24 Mar 2015 13:02:48 +0100 Subject: [master] c4a0eda ... and don't forget the two new states Message-ID: commit c4a0eda3ed4399ed7b953fe6c322c4506925206e Author: Poul-Henning Kamp Date: Tue Mar 24 10:09:53 2015 +0000 ... and don't forget the two new states diff --git a/include/tbl/steps.h b/include/tbl/steps.h index 5d93386..a5e618a 100644 --- a/include/tbl/steps.h +++ b/include/tbl/steps.h @@ -33,7 +33,9 @@ #ifdef SESS_STEP SESS_STEP(h1newsess, H1NEWSESS) SESS_STEP(h1newreq, H1NEWREQ) +SESS_STEP(h1proc, H1PROC) SESS_STEP(h1busy, H1BUSY) +SESS_STEP(h1cleanup, H1CLEANUP) SESS_STEP(h1working, H1WORKING) SESS_STEP(h1_last, H1_LAST) From fgsch at lodoss.net Tue Mar 24 14:26:04 2015 From: fgsch at lodoss.net (Federico G. Schwindt) Date: Tue, 24 Mar 2015 15:26:04 +0100 Subject: [master] 6ae8cca Make this test more robust Message-ID: commit 6ae8ccac4dcd27c7ec40f1255822f542d0933a94 Author: Federico G. Schwindt Date: Tue Mar 24 14:12:08 2015 +0000 Make this test more robust diff --git a/bin/varnishtest/tests/r01608.vtc b/bin/varnishtest/tests/r01608.vtc index 6486988..30a09fc 100644 --- a/bin/varnishtest/tests/r01608.vtc +++ b/bin/varnishtest/tests/r01608.vtc @@ -3,10 +3,11 @@ varnishtest "Increment counter if http_req_size is exhausted" server s1 { } -start -varnish v1 -arg "-p http_req_size=2048" -vcl+backend { +varnish v1 -arg "-p http_req_size=1024" -vcl+backend { } -start client c1 { + non-fatal send "GET /" send_n 2048 "A" send " HTTP/1.1\r\n\r\n" From phk at FreeBSD.org Wed Mar 25 12:32:01 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 25 Mar 2015 13:32:01 +0100 Subject: [master] 80dbd45 More untangling of sess/req interface Message-ID: commit 80dbd45892a787f6f105b62d755bac1955d72599 Author: Poul-Henning Kamp Date: Tue Mar 24 16:14:19 2015 +0000 More untangling of sess/req interface diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 6f2bb68..1976d6c 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -73,44 +73,18 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) while (1) { hs = SES_Rx(req->htc, tmo); now = VTIM_real(); - if (hs == HTC_S_OK || hs == HTC_S_TIMEOUT) - hs = HTTP1_Complete(req->htc); - if (hs == HTC_S_COMPLETE) { - /* Got it, run with it */ - if (isnan(req->t_first)) - req->t_first = now; - if (isnan(req->t_req)) - req->t_req = now; - req->acct.req_hdrbytes += - req->htc->rxbuf_e - req->htc->rxbuf_b; - return (REQ_FSM_MORE); - } else if (hs == HTC_S_EOF) { + if (hs == HTC_S_EOF) { WS_ReleaseP(req->htc->ws, req->htc->rxbuf_b); why = SC_REM_CLOSE; break; - } else if (hs == HTC_S_OVERFLOW) { + } + if (hs == HTC_S_OVERFLOW) { WS_ReleaseP(req->htc->ws, req->htc->rxbuf_b); why = SC_RX_OVERFLOW; break; - } else if (hs == HTC_S_EMPTY) { - /* Nothing but whitespace */ - when = sp->t_idle + cache_param->timeout_idle; - if (when < now) { - why = SC_RX_TIMEOUT; - break; - } - when = sp->t_idle + cache_param->timeout_linger; - tmo = when - now; - if (tmo <= 0) { - wrk->stats->sess_herd++; - SES_ReleaseReq(req); - if (VTCP_nonblocking(sp->fd)) - SES_Close(sp, SC_REM_CLOSE); - else - SES_Wait(sp); - return (REQ_FSM_DONE); - } - } else { + } + hs = HTTP1_Complete(req->htc); + if (hs == HTC_S_OK) { /* Working on it */ if (isnan(req->t_first)) /* Record first byte received time stamp */ @@ -121,7 +95,38 @@ http1_wait(struct sess *sp, struct worker *wrk, struct req *req) why = SC_RX_TIMEOUT; break; } + continue; } + if (hs == HTC_S_COMPLETE) { + /* Got it, run with it */ + if (isnan(req->t_first)) + req->t_first = now; + if (isnan(req->t_req)) + req->t_req = now; + req->acct.req_hdrbytes += + req->htc->rxbuf_e - req->htc->rxbuf_b; + return (REQ_FSM_MORE); + } + assert(hs == HTC_S_EMPTY); + /* Nothing but whitespace */ + when = sp->t_idle + cache_param->timeout_idle; + if (when < now) { + why = SC_RX_TIMEOUT; + break; + } + when = sp->t_idle + cache_param->timeout_linger; + tmo = when - now; + if (tmo > 0) + continue; + + wrk->stats->sess_herd++; + SES_ReleaseReq(req); + if (VTCP_nonblocking(sp->fd)) { + why = SC_REM_CLOSE; + break; + } + SES_Wait(sp); + return (REQ_FSM_DONE); } req->acct.req_hdrbytes += req->htc->rxbuf_e - req->htc->rxbuf_b; CNT_AcctLogCharge(wrk->stats, req); @@ -330,7 +335,6 @@ HTTP1_Session(struct worker *wrk, struct req *req) return; } - while (1) { switch (sp->sess_step) { case S_STP_H1NEWSESS: From phk at FreeBSD.org Wed Mar 25 12:32:01 2015 From: phk at FreeBSD.org (Poul-Henning Kamp) Date: Wed, 25 Mar 2015 13:32:01 +0100 Subject: [master] b1f8725 Turn the guts of http1_wait() into a more general and protocol independent SES_RxReq() function. Message-ID: commit b1f87256d1cfcc08442ab9518653a1a520f84bf7 Author: Poul-Henning Kamp Date: Wed Mar 25 12:30:39 2015 +0000 Turn the guts of http1_wait() into a more general and protocol independent SES_RxReq() function. Eliminate timeout_req and rely on timeout_idle to do the job. (Length of this timeout still under debate on -dev) diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h index 615b830..1db2fa5 100644 --- a/bin/varnishd/cache/cache.h +++ b/bin/varnishd/cache/cache.h @@ -677,6 +677,10 @@ struct sess { /* Prototypes etc ----------------------------------------------------*/ +/* Cross file typedefs */ + +typedef enum htc_status_e htc_complete_f(struct http_conn *); + /* cache_acceptor.c */ void VCA_Init(void); void VCA_Shutdown(void); @@ -853,7 +857,7 @@ enum sess_close http_DoConnection(struct http *hp); /* cache_http1_proto.c */ -enum htc_status_e HTTP1_Complete(struct http_conn *htc); +htc_complete_f HTTP1_Complete; uint16_t HTTP1_DissectRequest(struct http_conn *htc, struct http *hp); uint16_t HTTP1_DissectResponse(struct http *sp, struct http_conn *htc); unsigned HTTP1_Write(const struct worker *w, const struct http *hp, const int*); @@ -985,18 +989,22 @@ task_func_t SES_Proto_Sess; task_func_t SES_Proto_Req; enum htc_status_e { - HTC_S_EMPTY = -4, + HTC_S_CLOSE = -4, HTC_S_TIMEOUT = -3, HTC_S_OVERFLOW = -2, HTC_S_EOF = -1, - HTC_S_OK = 0, - HTC_S_COMPLETE = 1 + HTC_S_EMPTY = 0, + HTC_S_MORE = 1, + HTC_S_COMPLETE = 2, + HTC_S_IDLE = 3, }; void SES_RxInit(struct http_conn *htc, struct ws *ws, unsigned maxbytes, unsigned maxhdr); void SES_RxReInit(struct http_conn *htc); enum htc_status_e SES_Rx(struct http_conn *htc, double tmo); +enum htc_status_e SES_RxReq(const struct worker *, struct req *, + htc_complete_f *func); #define SESS_ATTR(UP, low, typ, len) \ int SES_Get_##low(const struct sess *sp, typ *dst); \ diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c index 5ee4cfb..e03f909 100644 --- a/bin/varnishd/cache/cache_session.c +++ b/bin/varnishd/cache/cache_session.c @@ -234,7 +234,65 @@ SES_Rx(struct http_conn *htc, double tmo) return (HTC_S_EOF); htc->rxbuf_e += i; *htc->rxbuf_e = '\0'; - return (HTC_S_OK); + return (HTC_S_MORE); +} + +/*---------------------------------------------------------------------- + * Receive a request/packet/whatever, with timeouts + */ + +enum htc_status_e +SES_RxReq(const struct worker *wrk, struct req *req, htc_complete_f *func) +{ + double tmo; + double now, when; + struct sess *sp; + enum htc_status_e hs; + + CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); + CHECK_OBJ_NOTNULL(req, REQ_MAGIC); + sp = req->sp; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + + AZ(isnan(sp->t_idle)); + assert(isnan(req->t_first)); + + when = sp->t_idle + cache_param->timeout_idle; + tmo = cache_param->timeout_linger; + while (1) { + hs = SES_Rx(req->htc, tmo); + now = VTIM_real(); + if (hs == HTC_S_EOF) { + WS_ReleaseP(req->htc->ws, req->htc->rxbuf_b); + return (HTC_S_CLOSE); + } + if (hs == HTC_S_OVERFLOW) { + WS_ReleaseP(req->htc->ws, req->htc->rxbuf_b); + return (HTC_S_OVERFLOW); + } + hs = func(req->htc); + if (hs == HTC_S_COMPLETE) { + /* Got it, run with it */ + if (isnan(req->t_first)) + req->t_first = now; + req->t_req = now; + return (HTC_S_COMPLETE); + } + if (when < now) + return (HTC_S_TIMEOUT); + if (hs == HTC_S_MORE) { + /* Working on it */ + if (isnan(req->t_first)) + req->t_first = now; + tmo = when - now; + continue; + } + assert(hs == HTC_S_EMPTY); + /* Nothing but whitespace */ + tmo = sp->t_idle + cache_param->timeout_linger - now; + if (tmo < 0) + return (HTC_S_IDLE); + } } /*-------------------------------------------------------------------- @@ -422,13 +480,16 @@ SES_Wait(struct sess *sp) * XXX: waiter_epoll prevents us from zeroing the struct because * XXX: it keeps state across calls. */ + if (VTCP_nonblocking(sp->fd)) { + SES_Delete(sp, SC_REM_CLOSE, NAN); + return; + } sp->waited.magic = WAITED_MAGIC; sp->waited.fd = sp->fd; sp->waited.ptr = sp; sp->waited.idle = sp->t_idle; - if (Wait_Enter(pp->http1_waiter, &sp->waited)) { + if (Wait_Enter(pp->http1_waiter, &sp->waited)) SES_Delete(sp, SC_PIPE_OVERFLOW, NAN); - } } /*-------------------------------------------------------------------- diff --git a/bin/varnishd/common/params.h b/bin/varnishd/common/params.h index 4c9c3ed..72b74d6 100644 --- a/bin/varnishd/common/params.h +++ b/bin/varnishd/common/params.h @@ -111,7 +111,6 @@ struct params { double timeout_linger; double timeout_idle; - double timeout_req; double pipe_timeout; double send_timeout; double idle_send_timeout; diff --git a/bin/varnishd/http1/cache_http1_fetch.c b/bin/varnishd/http1/cache_http1_fetch.c index bae29c5..7b108d2 100644 --- a/bin/varnishd/http1/cache_http1_fetch.c +++ b/bin/varnishd/http1/cache_http1_fetch.c @@ -154,7 +154,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, const char *def_host) first = 1; do { hs = SES_Rx(htc, 0); - if (hs == HTC_S_OK) + if (hs == HTC_S_MORE) hs = HTTP1_Complete(htc); if (hs == HTC_S_OVERFLOW) { WS_ReleaseP(htc->ws, htc->rxbuf_b); diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c index 1976d6c..0f1d46c 100644 --- a/bin/varnishd/http1/cache_http1_fsm.c +++ b/bin/varnishd/http1/cache_http1_fsm.c @@ -51,89 +51,39 @@ static enum req_fsm_nxt http1_wait(struct sess *sp, struct worker *wrk, struct req *req) { - double tmo; - double now, when; - enum sess_close why = SC_NULL; enum htc_status_e hs; - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); - CHECK_OBJ_NOTNULL(req, REQ_MAGIC); - - assert(req->sp == sp); - - AZ(req->vcl); - AZ(req->esi_level); - AZ(isnan(sp->t_idle)); - assert(isnan(req->t_first)); assert(isnan(req->t_prev)); assert(isnan(req->t_req)); + AZ(req->vcl); + AZ(req->esi_level); - tmo = cache_param->timeout_linger; - while (1) { - hs = SES_Rx(req->htc, tmo); - now = VTIM_real(); - if (hs == HTC_S_EOF) { - WS_ReleaseP(req->htc->ws, req->htc->rxbuf_b); - why = SC_REM_CLOSE; - break; - } - if (hs == HTC_S_OVERFLOW) { - WS_ReleaseP(req->htc->ws, req->htc->rxbuf_b); - why = SC_RX_OVERFLOW; - break; - } - hs = HTTP1_Complete(req->htc); - if (hs == HTC_S_OK) { - /* Working on it */ - if (isnan(req->t_first)) - /* Record first byte received time stamp */ - req->t_first = now; - when = req->t_first + cache_param->timeout_req; - tmo = when - now; - if (tmo <= 0) { - why = SC_RX_TIMEOUT; - break; - } - continue; - } - if (hs == HTC_S_COMPLETE) { - /* Got it, run with it */ - if (isnan(req->t_first)) - req->t_first = now; - if (isnan(req->t_req)) - req->t_req = now; - req->acct.req_hdrbytes += - req->htc->rxbuf_e - req->htc->rxbuf_b; - return (REQ_FSM_MORE); - } - assert(hs == HTC_S_EMPTY); - /* Nothing but whitespace */ - when = sp->t_idle + cache_param->timeout_idle; - if (when < now) { - why = SC_RX_TIMEOUT; - break; + hs = SES_RxReq(wrk, req, HTTP1_Complete); + if (hs < HTC_S_EMPTY) { + req->acct.req_hdrbytes += req->htc->rxbuf_e - req->htc->rxbuf_b; + CNT_AcctLogCharge(wrk->stats, req); + SES_ReleaseReq(req); + switch(hs) { + case HTC_S_CLOSE: SES_Delete(sp, SC_REM_CLOSE, 0.0); break; + case HTC_S_TIMEOUT: SES_Delete(sp, SC_RX_TIMEOUT, 0.0); break; + case HTC_S_OVERFLOW: SES_Delete(sp, SC_RX_OVERFLOW, 0.0); break; + case HTC_S_EOF: SES_Delete(sp, SC_REM_CLOSE, 0.0); break; + default: WRONG("htc_status (bad)"); } - when = sp->t_idle + cache_param->timeout_linger; - tmo = when - now; - if (tmo > 0) - continue; - + return (REQ_FSM_DONE); + } + if (hs == HTC_S_COMPLETE) { + req->acct.req_hdrbytes += + req->htc->rxbuf_e - req->htc->rxbuf_b; + return (REQ_FSM_MORE); + } + if (hs == HTC_S_IDLE) { wrk->stats->sess_herd++; SES_ReleaseReq(req); - if (VTCP_nonblocking(sp->fd)) { - why = SC_REM_CLOSE; - break; - } SES_Wait(sp); return (REQ_FSM_DONE); } - req->acct.req_hdrbytes += req->htc->rxbuf_e - req->htc->rxbuf_b; - CNT_AcctLogCharge(wrk->stats, req); - SES_ReleaseReq(req); - assert(why != SC_NULL); - SES_Delete(sp, why, now); - return (REQ_FSM_DONE); + WRONG("htc_status (nonbad)"); } /*---------------------------------------------------------------------- diff --git a/bin/varnishd/http1/cache_http1_proto.c b/bin/varnishd/http1/cache_http1_proto.c index 28cbc0f..c99ec30 100644 --- a/bin/varnishd/http1/cache_http1_proto.c +++ b/bin/varnishd/http1/cache_http1_proto.c @@ -61,7 +61,7 @@ const int HTTP1_Resp[3] = { * Check if we have a complete HTTP request or response yet */ -enum htc_status_e +enum htc_status_e __match_proto__(htc_complete_f) HTTP1_Complete(struct http_conn *htc) { char *p; @@ -85,7 +85,7 @@ HTTP1_Complete(struct http_conn *htc) while (1) { p = strchr(p, '\n'); if (p == NULL) - return (HTC_S_OK); + return (HTC_S_MORE); p++; if (*p == '\r') p++; diff --git a/bin/varnishd/mgt/mgt_param_tbl.c b/bin/varnishd/mgt/mgt_param_tbl.c index 51120f6..071d7ed 100644 --- a/bin/varnishd/mgt/mgt_param_tbl.c +++ b/bin/varnishd/mgt/mgt_param_tbl.c @@ -172,16 +172,10 @@ struct parspec mgt_parspec[] = { { "timeout_idle", tweak_timeout, &mgt_param.timeout_idle, "0", NULL, "Idle timeout for client connections.\n" - "A connection is considered idle, until we receive" - " a non-white-space character on it.", + "A connection is considered idle, until we have" + "received the full request headers.", 0, "5", "seconds" }, - { "timeout_req", tweak_timeout, &mgt_param.timeout_req, - "0", NULL, - "Max time to receive clients request headers, measured" - " from first non-white-space character to double CRNL.", - 0, - "2", "seconds" }, { "pipe_timeout", tweak_timeout, &mgt_param.pipe_timeout, "0", NULL, "Idle timeout for PIPE sessions. "