From phk at projects.linpro.no Sat Jan 10 22:11:26 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 10 Jan 2009 23:11:26 +0100 (CET) Subject: r3498 - in trunk/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090110221126.F11721EC1E7@projects.linpro.no> Author: phk Date: 2009-01-10 23:11:26 +0100 (Sat, 10 Jan 2009) New Revision: 3498 Added: trunk/varnish-cache/bin/varnishtest/tests/v00416.vtc Modified: trunk/varnish-cache/bin/varnishd/cache_http.c Log: If we get more HTTP headers than we have room for (default: 28) we used to ignore the rest. This is not a bright solution if crucial HTTP headers like "Content-Length" or "Transfer-Encoding" are last and get ignored. In general, it is highly suspect to randomly ignore HTTP headers, as opposed to deliberately ignoring them, either by having first looked at them and found them uninteresting, or by having looked for the headers we care about, and having not matched some others. Change too many headers to firm error condition: 400 if from the client, and 503 (like every other trouble) if from the backend. Fixes #416 Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2008-12-21 18:42:48 UTC (rev 3497) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2009-01-10 22:11:26 UTC (rev 3498) @@ -354,6 +354,7 @@ } else { VSL_stats->losthdr++; WSL(w, SLT_LostHeader, fd, "%.*s", q - p, p); + return (400); } } return (0); Added: trunk/varnish-cache/bin/varnishtest/tests/v00416.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00416.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/v00416.vtc 2009-01-10 22:11:26 UTC (rev 3498) @@ -0,0 +1,102 @@ +# $Id$ + +test "Regression test for #416: a surplus of HTTP headers" + +server s1 { + rxreq + txresp \ + -hdr hdr00=00 \ + -hdr hdr01=01 \ + -hdr hdr02=02 \ + -hdr hdr03=03 \ + -hdr hdr04=04 \ + -hdr hdr05=05 \ + -hdr hdr06=06 \ + -hdr hdr07=07 \ + -hdr hdr08=08 \ + -hdr hdr09=09 \ + -hdr hdr10=10 \ + -hdr hdr11=11 \ + -hdr hdr12=12 \ + -hdr hdr13=13 \ + -hdr hdr14=14 \ + -hdr hdr15=15 \ + -hdr hdr16=16 \ + -hdr hdr17=17 \ + -hdr hdr18=18 \ + -hdr hdr19=19 \ + -hdr hdr20=20 \ + -hdr hdr21=21 \ + -hdr hdr22=22 \ + -hdr hdr23=23 \ + -hdr hdr24=24 \ + -hdr hdr25=25 \ + -hdr hdr26=26 \ + -hdr hdr27=27 \ + -hdr hdr28=28 \ + -hdr hdr29=29 \ + -hdr hdr30=30 \ + -hdr hdr31=31 \ + -hdr hdr32=32 \ + -hdr hdr33=33 \ + -hdr hdr34=34 \ + -hdr hdr35=35 \ + -hdr hdr36=36 \ + -hdr hdr37=37 \ + -hdr hdr38=38 \ + -hdr hdr39=39 \ + -body "foo" +} -start + +varnish v1 -vcl+backend {} -start + +client c1 { + txreq \ + -hdr hdr00=00 \ + -hdr hdr01=01 \ + -hdr hdr02=02 \ + -hdr hdr03=03 \ + -hdr hdr04=04 \ + -hdr hdr05=05 \ + -hdr hdr06=06 \ + -hdr hdr07=07 \ + -hdr hdr08=08 \ + -hdr hdr09=09 \ + -hdr hdr10=10 \ + -hdr hdr11=11 \ + -hdr hdr12=12 \ + -hdr hdr13=13 \ + -hdr hdr14=14 \ + -hdr hdr15=15 \ + -hdr hdr16=16 \ + -hdr hdr17=17 \ + -hdr hdr18=18 \ + -hdr hdr19=19 \ + -hdr hdr20=20 \ + -hdr hdr21=21 \ + -hdr hdr22=22 \ + -hdr hdr23=23 \ + -hdr hdr24=24 \ + -hdr hdr25=25 \ + -hdr hdr26=26 \ + -hdr hdr27=27 \ + -hdr hdr28=28 \ + -hdr hdr29=29 \ + -hdr hdr30=30 \ + -hdr hdr31=31 \ + -hdr hdr32=32 \ + -hdr hdr33=33 \ + -hdr hdr34=34 \ + -hdr hdr35=35 \ + -hdr hdr36=36 \ + -hdr hdr37=37 \ + -hdr hdr38=38 \ + -hdr hdr39=39 + rxresp +} -run + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run From phk at projects.linpro.no Sat Jan 10 22:14:58 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 10 Jan 2009 23:14:58 +0100 (CET) Subject: r3499 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20090110221458.C72B11EC0F2@projects.linpro.no> Author: phk Date: 2009-01-10 23:14:58 +0100 (Sat, 10 Jan 2009) New Revision: 3499 Added: trunk/varnish-cache/bin/varnishtest/tests/r00416.vtc Removed: trunk/varnish-cache/bin/varnishtest/tests/v00416.vtc Log: This is a regression test Copied: trunk/varnish-cache/bin/varnishtest/tests/r00416.vtc (from rev 3498, trunk/varnish-cache/bin/varnishtest/tests/v00416.vtc) =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/r00416.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/r00416.vtc 2009-01-10 22:14:58 UTC (rev 3499) @@ -0,0 +1,102 @@ +# $Id$ + +test "Regression test for #416: a surplus of HTTP headers" + +server s1 { + rxreq + txresp \ + -hdr hdr00=00 \ + -hdr hdr01=01 \ + -hdr hdr02=02 \ + -hdr hdr03=03 \ + -hdr hdr04=04 \ + -hdr hdr05=05 \ + -hdr hdr06=06 \ + -hdr hdr07=07 \ + -hdr hdr08=08 \ + -hdr hdr09=09 \ + -hdr hdr10=10 \ + -hdr hdr11=11 \ + -hdr hdr12=12 \ + -hdr hdr13=13 \ + -hdr hdr14=14 \ + -hdr hdr15=15 \ + -hdr hdr16=16 \ + -hdr hdr17=17 \ + -hdr hdr18=18 \ + -hdr hdr19=19 \ + -hdr hdr20=20 \ + -hdr hdr21=21 \ + -hdr hdr22=22 \ + -hdr hdr23=23 \ + -hdr hdr24=24 \ + -hdr hdr25=25 \ + -hdr hdr26=26 \ + -hdr hdr27=27 \ + -hdr hdr28=28 \ + -hdr hdr29=29 \ + -hdr hdr30=30 \ + -hdr hdr31=31 \ + -hdr hdr32=32 \ + -hdr hdr33=33 \ + -hdr hdr34=34 \ + -hdr hdr35=35 \ + -hdr hdr36=36 \ + -hdr hdr37=37 \ + -hdr hdr38=38 \ + -hdr hdr39=39 \ + -body "foo" +} -start + +varnish v1 -vcl+backend {} -start + +client c1 { + txreq \ + -hdr hdr00=00 \ + -hdr hdr01=01 \ + -hdr hdr02=02 \ + -hdr hdr03=03 \ + -hdr hdr04=04 \ + -hdr hdr05=05 \ + -hdr hdr06=06 \ + -hdr hdr07=07 \ + -hdr hdr08=08 \ + -hdr hdr09=09 \ + -hdr hdr10=10 \ + -hdr hdr11=11 \ + -hdr hdr12=12 \ + -hdr hdr13=13 \ + -hdr hdr14=14 \ + -hdr hdr15=15 \ + -hdr hdr16=16 \ + -hdr hdr17=17 \ + -hdr hdr18=18 \ + -hdr hdr19=19 \ + -hdr hdr20=20 \ + -hdr hdr21=21 \ + -hdr hdr22=22 \ + -hdr hdr23=23 \ + -hdr hdr24=24 \ + -hdr hdr25=25 \ + -hdr hdr26=26 \ + -hdr hdr27=27 \ + -hdr hdr28=28 \ + -hdr hdr29=29 \ + -hdr hdr30=30 \ + -hdr hdr31=31 \ + -hdr hdr32=32 \ + -hdr hdr33=33 \ + -hdr hdr34=34 \ + -hdr hdr35=35 \ + -hdr hdr36=36 \ + -hdr hdr37=37 \ + -hdr hdr38=38 \ + -hdr hdr39=39 + rxresp +} -run + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run Property changes on: trunk/varnish-cache/bin/varnishtest/tests/r00416.vtc ___________________________________________________________________ Name: svn:mergeinfo + Deleted: trunk/varnish-cache/bin/varnishtest/tests/v00416.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/v00416.vtc 2009-01-10 22:11:26 UTC (rev 3498) +++ trunk/varnish-cache/bin/varnishtest/tests/v00416.vtc 2009-01-10 22:14:58 UTC (rev 3499) @@ -1,102 +0,0 @@ -# $Id$ - -test "Regression test for #416: a surplus of HTTP headers" - -server s1 { - rxreq - txresp \ - -hdr hdr00=00 \ - -hdr hdr01=01 \ - -hdr hdr02=02 \ - -hdr hdr03=03 \ - -hdr hdr04=04 \ - -hdr hdr05=05 \ - -hdr hdr06=06 \ - -hdr hdr07=07 \ - -hdr hdr08=08 \ - -hdr hdr09=09 \ - -hdr hdr10=10 \ - -hdr hdr11=11 \ - -hdr hdr12=12 \ - -hdr hdr13=13 \ - -hdr hdr14=14 \ - -hdr hdr15=15 \ - -hdr hdr16=16 \ - -hdr hdr17=17 \ - -hdr hdr18=18 \ - -hdr hdr19=19 \ - -hdr hdr20=20 \ - -hdr hdr21=21 \ - -hdr hdr22=22 \ - -hdr hdr23=23 \ - -hdr hdr24=24 \ - -hdr hdr25=25 \ - -hdr hdr26=26 \ - -hdr hdr27=27 \ - -hdr hdr28=28 \ - -hdr hdr29=29 \ - -hdr hdr30=30 \ - -hdr hdr31=31 \ - -hdr hdr32=32 \ - -hdr hdr33=33 \ - -hdr hdr34=34 \ - -hdr hdr35=35 \ - -hdr hdr36=36 \ - -hdr hdr37=37 \ - -hdr hdr38=38 \ - -hdr hdr39=39 \ - -body "foo" -} -start - -varnish v1 -vcl+backend {} -start - -client c1 { - txreq \ - -hdr hdr00=00 \ - -hdr hdr01=01 \ - -hdr hdr02=02 \ - -hdr hdr03=03 \ - -hdr hdr04=04 \ - -hdr hdr05=05 \ - -hdr hdr06=06 \ - -hdr hdr07=07 \ - -hdr hdr08=08 \ - -hdr hdr09=09 \ - -hdr hdr10=10 \ - -hdr hdr11=11 \ - -hdr hdr12=12 \ - -hdr hdr13=13 \ - -hdr hdr14=14 \ - -hdr hdr15=15 \ - -hdr hdr16=16 \ - -hdr hdr17=17 \ - -hdr hdr18=18 \ - -hdr hdr19=19 \ - -hdr hdr20=20 \ - -hdr hdr21=21 \ - -hdr hdr22=22 \ - -hdr hdr23=23 \ - -hdr hdr24=24 \ - -hdr hdr25=25 \ - -hdr hdr26=26 \ - -hdr hdr27=27 \ - -hdr hdr28=28 \ - -hdr hdr29=29 \ - -hdr hdr30=30 \ - -hdr hdr31=31 \ - -hdr hdr32=32 \ - -hdr hdr33=33 \ - -hdr hdr34=34 \ - -hdr hdr35=35 \ - -hdr hdr36=36 \ - -hdr hdr37=37 \ - -hdr hdr38=38 \ - -hdr hdr39=39 - rxresp -} -run - -client c1 { - txreq - rxresp - expect resp.status == 503 -} -run From phk at projects.linpro.no Sat Jan 10 22:27:39 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 10 Jan 2009 23:27:39 +0100 (CET) Subject: r3500 - in trunk/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090110222739.597B21EC0E0@projects.linpro.no> Author: phk Date: 2009-01-10 23:27:39 +0100 (Sat, 10 Jan 2009) New Revision: 3500 Added: trunk/varnish-cache/bin/varnishtest/tests/r00387.vtc Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c Log: Don't panic if the chunked header is ridiculously long, just fail the transaction. Fixes #387 Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2009-01-10 22:14:58 UTC (rev 3499) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2009-01-10 22:27:39 UTC (rev 3500) @@ -110,7 +110,8 @@ /* If we didn't succeed, add to buffer, try again */ if (q == NULL || q == buf || *q != '\n') { - xxxassert(be > bp); + if (bp >= be) + return (-1); /* * The semantics we need here is "read until you have * received at least one character, but feel free to Added: trunk/varnish-cache/bin/varnishtest/tests/r00387.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/r00387.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/r00387.vtc 2009-01-10 22:27:39 UTC (rev 3500) @@ -0,0 +1,22 @@ +# $Id$ + +test "Regression test for #387: too long chunk header" + +server s1 { + rxreq + send "HTTP/1.1 200 Ok\r\n" + send "Transfer-encoding: chunked\r\n" + send "\r\n" + send "004\r\n1234\r\n" + send "000000000000000000001\r\n@\r\n" + send "00000000\r\n" +} -start + +varnish v1 -vcl+backend {} -start + +client c1 { + txreq + rxresp + expect resp.status == 503 +} -run + From phk at projects.linpro.no Sat Jan 10 22:30:04 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 10 Jan 2009 23:30:04 +0100 (CET) Subject: r3501 - trunk/varnish-cache/bin/varnishd Message-ID: <20090110223004.D72DF1EC1E7@projects.linpro.no> Author: phk Date: 2009-01-10 23:30:04 +0100 (Sat, 10 Jan 2009) New Revision: 3501 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Don't panic if we fail to delete shared objects in atexit(). Fixes #376 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2009-01-10 22:27:39 UTC (rev 3500) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2009-01-10 22:30:04 UTC (rev 3501) @@ -436,7 +436,7 @@ vp = VTAILQ_FIRST(&vclhead); if (vp == NULL) break; - mgt_vcc_del(vp); + (void)unlink(vp->fname); } } From phk at projects.linpro.no Sat Jan 10 22:49:44 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 10 Jan 2009 23:49:44 +0100 (CET) Subject: r3502 - trunk/varnish-cache/bin/varnishd Message-ID: <20090110224944.C64761EC0F2@projects.linpro.no> Author: phk Date: 2009-01-10 23:49:44 +0100 (Sat, 10 Jan 2009) New Revision: 3502 Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c Log: Addendum to r3501: remove the file from the list. Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2009-01-10 22:30:04 UTC (rev 3501) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2009-01-10 22:49:44 UTC (rev 3502) @@ -437,6 +437,7 @@ if (vp == NULL) break; (void)unlink(vp->fname); + VTAILQ_REMOVE(&vclhead, vp, list); } } From phk at projects.linpro.no Mon Jan 12 12:57:31 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 12 Jan 2009 13:57:31 +0100 (CET) Subject: r3503 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20090112125731.09C4A1EC0E0@projects.linpro.no> Author: phk Date: 2009-01-12 13:57:30 +0100 (Mon, 12 Jan 2009) New Revision: 3503 Added: trunk/varnish-cache/bin/varnishtest/tests/c00020.vtc Log: Add a minimal testcase of critbit Added: trunk/varnish-cache/bin/varnishtest/tests/c00020.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00020.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/c00020.vtc 2009-01-12 12:57:30 UTC (rev 3503) @@ -0,0 +1,32 @@ +# $Id$ + +test "Test -h critbit a bit" + +server s1 { + rxreq + txresp -hdr "Connection: close" -body "012345\n" +} -start + +varnish v1 -arg "-hcritbit" -vcl+backend { } -start + +client c1 { + txreq -url "/" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1001" +} -run + +client c2 { + txreq -url "/" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1002 1001" +} -run + +varnish v1 -expect client_conn == 2 +varnish v1 -expect cache_hit == 1 +varnish v1 -expect cache_miss == 1 +varnish v1 -expect client_req == 2 +varnish v1 -expect s_sess == 2 +varnish v1 -expect s_req == 2 +varnish v1 -expect s_fetch == 1 From phk at projects.linpro.no Mon Jan 12 13:09:52 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 12 Jan 2009 14:09:52 +0100 (CET) Subject: r3504 - trunk/varnish-cache/bin/varnishd Message-ID: <20090112130952.2FD571EC2A4@projects.linpro.no> Author: phk Date: 2009-01-12 14:09:51 +0100 (Mon, 12 Jan 2009) New Revision: 3504 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/hash_classic.c trunk/varnish-cache/bin/varnishd/hash_critbit.c trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_param.c Log: Make SHA256 digest standard and use it in hash_classic.c Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-12 12:57:30 UTC (rev 3503) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-12 13:09:51 UTC (rev 3504) @@ -214,8 +214,7 @@ if (u) p += sizeof(const char *) - u; sp->hashptr = (void*)p; - if (params->hash_sha256) - SHA256_Init(sp->wrk->sha256ctx); + SHA256_Init(sp->wrk->sha256ctx); } void @@ -238,10 +237,8 @@ sp->hashptr[sp->ihashptr + 1] = str + l; sp->ihashptr += 2; sp->lhashptr += l + 1; - if (params->hash_sha256) { - SHA256_Update(sp->wrk->sha256ctx, str, l); - SHA256_Update(sp->wrk->sha256ctx, "#", 1); - } + SHA256_Update(sp->wrk->sha256ctx, str, l); + SHA256_Update(sp->wrk->sha256ctx, "#", 1); } struct object * @@ -260,10 +257,7 @@ h = sp->http; HSH_Prealloc(sp); - if (params->hash_sha256) { - SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); - /* WSP(sp, SLT_Debug, "SHA256: <%.32s>", sha256); */ - } + SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); if (sp->objhead != NULL) { CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC); Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_classic.c 2009-01-12 12:57:30 UTC (rev 3503) +++ trunk/varnish-cache/bin/varnishd/hash_classic.c 2009-01-12 13:09:51 UTC (rev 3504) @@ -120,19 +120,13 @@ struct objhead *oh; struct hcl_hd *hp; unsigned u1, digest; - unsigned u, v; int i; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC); - digest = ~0U; - for (u = 0; u < sp->ihashptr; u += 2) { - v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); - digest = crc32(digest, sp->hashptr[u], v); - } - digest ^= ~0U; - + assert(sizeof noh->digest > sizeof digest); + memcpy(&digest, noh->digest, sizeof digest); u1 = digest % hcl_nhash; hp = &hcl_head[u1]; Modified: trunk/varnish-cache/bin/varnishd/hash_critbit.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_critbit.c 2009-01-12 12:57:30 UTC (rev 3503) +++ trunk/varnish-cache/bin/varnishd/hash_critbit.c 2009-01-12 13:09:51 UTC (rev 3504) @@ -367,7 +367,6 @@ (void)oh; AZ(pthread_create(&tp, NULL, hcb_cleaner, NULL)); - assert(params->hash_sha256); assert(sizeof(struct hcb_y) <= sizeof(oh->u)); memset(&hcb_root, 0, sizeof hcb_root); hcb_build_bittbl(); @@ -402,7 +401,6 @@ struct objhead *oh; unsigned u; - assert(params->hash_sha256); oh = hcb_insert(&hcb_root, noh, 0); if (oh != NULL) { /* Assert that we didn't muck with the tree without lock */ Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2009-01-12 12:57:30 UTC (rev 3503) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2009-01-12 13:09:51 UTC (rev 3504) @@ -174,9 +174,6 @@ /* Default grace period */ unsigned default_grace; - /* Use sha256 hasing */ - unsigned hash_sha256; - /* Log hash string to shm */ unsigned log_hash; Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2009-01-12 12:57:30 UTC (rev 3503) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2009-01-12 13:09:51 UTC (rev 3504) @@ -710,10 +710,6 @@ "NB: Must be specified with -p to have effect.\n", 0, "8192", "bytes" }, - { "hash_sha256", tweak_bool, &master.hash_sha256, 0, 0, - "Use SHA256 compression of hash-strings", - 0, - "on", "bool" }, { "log_hashstring", tweak_bool, &master.log_hash, 0, 0, "Log the hash string to shared memory log.\n", 0, From phk at projects.linpro.no Mon Jan 12 13:13:59 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 12 Jan 2009 14:13:59 +0100 (CET) Subject: r3505 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20090112131359.CE7021EC0E0@projects.linpro.no> Author: phk Date: 2009-01-12 14:13:59 +0100 (Mon, 12 Jan 2009) New Revision: 3505 Modified: trunk/varnish-cache/bin/varnishtest/tests/c00020.vtc Log: Expand critbit test for more coverage Modified: trunk/varnish-cache/bin/varnishtest/tests/c00020.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00020.vtc 2009-01-12 13:09:51 UTC (rev 3504) +++ trunk/varnish-cache/bin/varnishtest/tests/c00020.vtc 2009-01-12 13:13:59 UTC (rev 3505) @@ -4,6 +4,7 @@ server s1 { rxreq + expect req.url == "/" txresp -hdr "Connection: close" -body "012345\n" } -start @@ -23,10 +24,38 @@ expect resp.http.X-Varnish == "1002 1001" } -run -varnish v1 -expect client_conn == 2 -varnish v1 -expect cache_hit == 1 -varnish v1 -expect cache_miss == 1 -varnish v1 -expect client_req == 2 -varnish v1 -expect s_sess == 2 -varnish v1 -expect s_req == 2 -varnish v1 -expect s_fetch == 1 +server s1 { + rxreq + expect req.url == "/foo" + txresp -body "012345\n" + rxreq + expect req.url == "/bar" + txresp -body "012345\n" +} -start + +client c2 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1003" + txreq -url "/" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1004 1001" + txreq -url "/bar" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1005" + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.X-Varnish == "1006 1003" +} -run + +varnish v1 -expect client_conn == 3 +varnish v1 -expect cache_hit == 3 +varnish v1 -expect cache_miss == 3 +varnish v1 -expect client_req == 6 +varnish v1 -expect s_sess == 3 +varnish v1 -expect s_req == 6 +varnish v1 -expect s_fetch == 3 From phk at projects.linpro.no Mon Jan 12 13:19:14 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 12 Jan 2009 14:19:14 +0100 (CET) Subject: r3506 - trunk/varnish-cache/bin/varnishd Message-ID: <20090112131914.E39E41EC2A4@projects.linpro.no> Author: phk Date: 2009-01-12 14:19:14 +0100 (Mon, 12 Jan 2009) New Revision: 3506 Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h Log: don't overload the waiting list (yet), I suspect it causes #414b Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-01-12 13:13:59 UTC (rev 3505) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-01-12 13:19:14 UTC (rev 3506) @@ -78,12 +78,17 @@ char *hash; unsigned hashlen; unsigned char digest[DIGEST_LEN]; +#ifdef NOT_YET union { VTAILQ_HEAD(, sess) __u_waitinglist; VTAILQ_ENTRY(objhead) __u_coollist; } __u; #define waitinglist __u.__u_waitinglist #define coollist __u.__u_coollist +#else + VTAILQ_HEAD(, sess) waitinglist; + VTAILQ_ENTRY(objhead) coollist; +#endif /*---------------------------------------------------- * The fields below are for the sole private use of From phk at projects.linpro.no Mon Jan 12 13:51:33 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 12 Jan 2009 14:51:33 +0100 (CET) Subject: r3507 - trunk/varnish-cache/bin/varnishd Message-ID: <20090112135133.E72FF1EC0E0@projects.linpro.no> Author: phk Date: 2009-01-12 14:51:33 +0100 (Mon, 12 Jan 2009) New Revision: 3507 Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/hash_classic.c trunk/varnish-cache/bin/varnishd/hash_simple_list.c trunk/varnish-cache/bin/varnishd/hash_slinger.h Log: Ditch HSH_Compare() and just check the digest with memcmp() Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-12 13:19:14 UTC (rev 3506) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-12 13:51:33 UTC (rev 3507) @@ -143,36 +143,6 @@ } } -int -HSH_Compare(const struct sess *sp, const struct objhead *oh) -{ - int i; - unsigned u, v; - const char *b; - - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_NOTNULL(sp->wrk, WORKER_MAGIC); - CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); - i = sp->lhashptr - oh->hashlen; - if (i) - return (i); - b = oh->hash; - for (u = 0; u < sp->ihashptr; u += 2) { - v = pdiff(sp->hashptr[u], sp->hashptr[u + 1]); - i = memcmp(sp->hashptr[u], b, v); - if (i) - return (i); - b += v; - i = '#' - *b++; - if (i) - return (i); - } - assert(*b == '\0'); - b++; - assert(b == oh->hash + oh->hashlen); - return (0); -} - void HSH_Copy(const struct sess *sp, struct objhead *oh) { Modified: trunk/varnish-cache/bin/varnishd/hash_classic.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_classic.c 2009-01-12 13:19:14 UTC (rev 3506) +++ trunk/varnish-cache/bin/varnishd/hash_classic.c 2009-01-12 13:51:33 UTC (rev 3507) @@ -132,15 +132,7 @@ Lck_Lock(&hp->mtx); VTAILQ_FOREACH(oh, &hp->head, hoh_list) { - if (sp->lhashptr < oh->hashlen) - continue; - if (sp->lhashptr > oh->hashlen) - break; - if (oh->hoh_digest < digest) - continue; - if (oh->hoh_digest > digest) - break; - i = HSH_Compare(sp, oh); + i = memcmp(oh->digest, noh->digest, sizeof oh->digest); if (i < 0) continue; if (i > 0) Modified: trunk/varnish-cache/bin/varnishd/hash_simple_list.c =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2009-01-12 13:19:14 UTC (rev 3506) +++ trunk/varnish-cache/bin/varnishd/hash_simple_list.c 2009-01-12 13:51:33 UTC (rev 3507) @@ -75,7 +75,7 @@ CHECK_OBJ_NOTNULL(noh, OBJHEAD_MAGIC); Lck_Lock(&hsl_mtx); VTAILQ_FOREACH(oh, &hsl_head, hoh_list) { - i = HSH_Compare(sp, oh); + i = memcmp(oh->digest, noh->digest, sizeof oh->digest); if (i < 0) continue; if (i > 0) Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-01-12 13:19:14 UTC (rev 3506) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-01-12 13:51:33 UTC (rev 3507) @@ -51,7 +51,6 @@ /* cache_hash.c */ void HSH_Prealloc(struct sess *sp); void HSH_Freestore(struct object *o); -int HSH_Compare(const struct sess *sp, const struct objhead *o); void HSH_Copy(const struct sess *sp, struct objhead *o); struct object *HSH_Lookup(struct sess *sp); void HSH_Unbusy(const struct sess *sp); From phk at projects.linpro.no Tue Jan 13 12:30:14 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 13 Jan 2009 13:30:14 +0100 (CET) Subject: r3508 - trunk/varnish-cache/bin/varnishd Message-ID: <20090113123014.A0B3B1EC38D@projects.linpro.no> Author: phk Date: 2009-01-13 13:30:14 +0100 (Tue, 13 Jan 2009) New Revision: 3508 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_hash.c Log: Change the way bans/purges are stored, so that each ban has a list of conditions to test. This paves the way for a much more expressive ban/purge syntax where things like: purge req.http.host ~ "web1.com" && req.url ~ "\.png" purge obj.age > 1w && obj.size > 1MB purge obj.http.set-cookie ~ "USER=838339" && req.url ~ "\.html" become possible. Not quite there yet though. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-01-12 13:51:33 UTC (rev 3507) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-01-13 12:30:14 UTC (rev 3508) @@ -422,7 +422,7 @@ void BAN_Init(void); void BAN_NewObj(struct object *o); void BAN_DestroyObj(struct object *o); -int BAN_CheckObject(struct object *o, const char *url, const char *hash); +int BAN_CheckObject(struct object *o, const struct sess *sp); /* cache_center.c [CNT] */ void CNT_Session(struct sess *sp); Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-12 13:51:33 UTC (rev 3507) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-13 12:30:14 UTC (rev 3508) @@ -29,6 +29,17 @@ * $Id$ * * Ban ("purge") processing + * + * A ban consists of a number of conditions (or tests), all of which must be + * satisfied. Here are some potential bans we could support: + * + * req.url == "/foo" + * req.url ~ ".iso" && obj.size > 10MB + * req.http.host ~ "web1.com" && obj.set-cookie ~ "USER=29293" + * + * We make the "&&" mandatory from the start, leaving the syntax space + * for latter handling of "||" as well. + * */ #include "config.h" @@ -43,7 +54,23 @@ #include "cli.h" #include "cli_priv.h" #include "cache.h" +#include "hash_slinger.h" +struct ban_test; + +/* A ban-testing function */ +typedef int ban_cond_f(const struct ban_test *bt, const struct object *o, const struct sess *sp); + +/* Each individual test to be performed on a ban */ +struct ban_test { + unsigned magic; +#define BAN_TEST_MAGIC 0x54feec67 + VTAILQ_ENTRY(ban_test) list; + int cost; + ban_cond_f *func; + regex_t re; +}; + struct ban { unsigned magic; #define BAN_MAGIC 0x700b08ea @@ -51,14 +78,104 @@ unsigned refcount; int flags; #define BAN_F_GONE (1 << 0) - regex_t regexp; char *ban; int hash; + VTAILQ_HEAD(,ban_test) tests; }; static VTAILQ_HEAD(banhead,ban) ban_head = VTAILQ_HEAD_INITIALIZER(ban_head); static struct lock ban_mtx; +/*-------------------------------------------------------------------- + * Manipulation of bans + */ + +static struct ban * +ban_new_ban(void) +{ + struct ban *b; + ALLOC_OBJ(b, BAN_MAGIC); + if (b == NULL) + return (b); + VTAILQ_INIT(&b->tests); + return (b); +} + +static struct ban_test * +ban_add_test(struct ban *b) +{ + struct ban_test *bt; + + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + ALLOC_OBJ(bt, BAN_TEST_MAGIC); + if (bt == NULL) + return (bt); + VTAILQ_INSERT_TAIL(&b->tests, bt, list); + return (bt); +} + +static void +ban_sort_by_cost(struct ban *b) +{ + struct ban_test *bt, *btn; + int i; + + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + + do { + i = 0; + VTAILQ_FOREACH(bt, &b->tests, list) { + btn = VTAILQ_NEXT(bt, list); + if (btn != NULL && btn->cost < bt->cost) { + VTAILQ_REMOVE(&b->tests, bt, list); + VTAILQ_INSERT_AFTER(&b->tests, btn, bt, list); + i++; + } + } + } while (i); +} + +static void +ban_free_ban(struct ban *b) +{ + struct ban_test *bt; + + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + while (!VTAILQ_EMPTY(&b->tests)) { + bt = VTAILQ_FIRST(&b->tests); + VTAILQ_REMOVE(&b->tests, bt, list); + FREE_OBJ(bt); + } + FREE_OBJ(b); +} + +/*-------------------------------------------------------------------- + * Test functions -- return 0 if the test does not match + */ + +static int +ban_cond_url_regexp(const struct ban_test *bt, const struct object *o, + const struct sess *sp) +{ + (void)o; + return (!regexec(&bt->re, sp->http->hd[HTTP_HDR_URL].b, 0, NULL, 0)); +} + +static int +ban_cond_hash_regexp(const struct ban_test *bt, const struct object *o, + const struct sess *sp) +{ + (void)sp; + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + CHECK_OBJ_NOTNULL(o->objhead, OBJHEAD_MAGIC); + AN(o->objhead->hash); + return (!regexec(&bt->re, o->objhead->hash, 0, NULL, 0)); +} + +/*-------------------------------------------------------------------- + */ + + /* * We maintain ban_start as a pointer to the first element of the list * as a separate variable from the VTAILQ, to avoid depending on the @@ -71,25 +188,41 @@ BAN_Add(struct cli *cli, const char *regexp, int hash) { struct ban *b, *bi, *be; + struct ban_test *bt; char buf[512]; unsigned pcount; int i; - ALLOC_OBJ(b, BAN_MAGIC); + b = ban_new_ban(); if (b == NULL) { cli_out(cli, "Out of Memory"); cli_result(cli, CLIS_CANT); return (-1); } - i = regcomp(&b->regexp, regexp, REG_EXTENDED | REG_ICASE | REG_NOSUB); + bt = ban_add_test(b); + if (bt == NULL) { + cli_out(cli, "Out of Memory"); + cli_result(cli, CLIS_CANT); + ban_free_ban(b); + return (-1); + } + + ban_sort_by_cost(b); + + if (hash) + bt->func = ban_cond_hash_regexp; + else + bt->func = ban_cond_url_regexp; + + i = regcomp(&bt->re, regexp, REG_EXTENDED | REG_ICASE | REG_NOSUB); if (i) { - (void)regerror(i, &b->regexp, buf, sizeof buf); - regfree(&b->regexp); + (void)regerror(i, &bt->re, buf, sizeof buf); + regfree(&bt->re); VSL(SLT_Debug, 0, "REGEX: <%s>", buf); cli_out(cli, "%s", buf); cli_result(cli, CLIS_PARAM); - FREE_OBJ(b); + ban_free_ban(b); return (-1); } b->hash = hash; @@ -169,21 +302,20 @@ b = NULL; } Lck_Unlock(&ban_mtx); - if (b != NULL) { - free(b->ban); - regfree(&b->regexp); - FREE_OBJ(b); - } + if (b != NULL) + ban_free_ban(b); } int -BAN_CheckObject(struct object *o, const char *url, const char *hash) +BAN_CheckObject(struct object *o, const struct sess *sp) { struct ban *b; + struct ban_test *bt; struct ban * volatile b0; unsigned tests; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o->ban, BAN_MAGIC); @@ -199,9 +331,14 @@ */ tests = 0; for (b = b0; b != o->ban; b = VTAILQ_NEXT(b, list)) { - tests++; - if (!(b->flags & BAN_F_GONE) && - !regexec(&b->regexp, b->hash ? hash : url, 0, NULL, 0)) + if (b->flags & BAN_F_GONE) + continue; + VTAILQ_FOREACH(bt, &b->tests, list) { + tests++; + if (bt->func(bt, o, sp)) + break; + } + if (bt != NULL) break; } @@ -226,7 +363,18 @@ * CLI functions to add bans */ +#if 0 static void +ccf_purge(struct cli *cli, const char * const *av, void *priv) +{ + + (void)priv; + (void)av; + (void)cli; +} +#endif + +static void ccf_purge_url(struct cli *cli, const char * const *av, void *priv) { @@ -277,6 +425,9 @@ { CLI_PURGE_URL, ccf_purge_url }, { CLI_PURGE_HASH, ccf_purge_hash }, +#if 0 + { CLI_PURGE, ccf_purge }, +#endif { CLI_PURGE_LIST, ccf_purge_list }, { NULL } }; Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-12 13:51:33 UTC (rev 3507) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-13 12:30:14 UTC (rev 3508) @@ -255,7 +255,7 @@ continue; if (o->ttl == 0) continue; - if (BAN_CheckObject(o, h->hd[HTTP_HDR_URL].b, oh->hash)) { + if (BAN_CheckObject(o, sp)) { o->ttl = 0; WSP(sp, SLT_ExpBan, "%u was banned", o->xid); EXP_Rearm(o); From phk at projects.linpro.no Tue Jan 13 14:05:54 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 13 Jan 2009 15:05:54 +0100 (CET) Subject: r3509 - trunk/varnish-cache/bin/varnishd Message-ID: <20090113140554.8AC541EC35F@projects.linpro.no> Author: phk Date: 2009-01-13 15:05:54 +0100 (Tue, 13 Jan 2009) New Revision: 3509 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c Log: Commit the old urge facilities to the new world order. Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-13 12:30:14 UTC (rev 3508) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-13 14:05:54 UTC (rev 3509) @@ -46,6 +46,7 @@ #include +#include #include #include #include @@ -67,6 +68,7 @@ #define BAN_TEST_MAGIC 0x54feec67 VTAILQ_ENTRY(ban_test) list; int cost; + char *test; ban_cond_f *func; regex_t re; }; @@ -78,8 +80,6 @@ unsigned refcount; int flags; #define BAN_F_GONE (1 << 0) - char *ban; - int hash; VTAILQ_HEAD(,ban_test) tests; }; @@ -144,11 +144,45 @@ while (!VTAILQ_EMPTY(&b->tests)) { bt = VTAILQ_FIRST(&b->tests); VTAILQ_REMOVE(&b->tests, bt, list); + free(bt->test); + regfree(&bt->re); FREE_OBJ(bt); } FREE_OBJ(b); } +/* + * Return zero of the two bans have the same components + * + * XXX: Looks too expensive for my taste. + */ + +static int +ban_compare(const struct ban *b1, const struct ban *b2) +{ + struct ban_test *bt1, *bt2; + int n, m; + + CHECK_OBJ_NOTNULL(b1, BAN_MAGIC); + CHECK_OBJ_NOTNULL(b2, BAN_MAGIC); + + n = 0; + VTAILQ_FOREACH(bt1, &b1->tests, list) { + n++; + VTAILQ_FOREACH(bt2, &b2->tests, list) + if (!strcmp(bt1->test, bt2->test)) + break; + if (bt2 == NULL) + return (1); + } + m = 0; + VTAILQ_FOREACH(bt2, &b2->tests, list) + m++; + if (m != n) + return (1); + return (0); +} + /*-------------------------------------------------------------------- * Test functions -- return 0 if the test does not match */ @@ -173,61 +207,78 @@ } /*-------------------------------------------------------------------- + * Parse and add a ban test specification */ - -/* - * We maintain ban_start as a pointer to the first element of the list - * as a separate variable from the VTAILQ, to avoid depending on the - * internals of the VTAILQ macros. We tacitly assume that a pointer - * write is always atomic in doing so. - */ -static struct ban * volatile ban_start; - -int -BAN_Add(struct cli *cli, const char *regexp, int hash) +static int +ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) { - struct ban *b, *bi, *be; struct ban_test *bt; char buf[512]; - unsigned pcount; int i; - b = ban_new_ban(); - if (b == NULL) { + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + bt = ban_add_test(b); + if (bt == NULL) { cli_out(cli, "Out of Memory"); cli_result(cli, CLIS_CANT); return (-1); } - bt = ban_add_test(b); - if (bt == NULL) { - cli_out(cli, "Out of Memory"); - cli_result(cli, CLIS_CANT); - ban_free_ban(b); + if (strcmp(a2, "~")) { + /* XXX: Add more conditionals */ + cli_out(cli, "expected \"~\" got \"%s\"", a2); + cli_result(cli, CLIS_PARAM); return (-1); } - ban_sort_by_cost(b); - - if (hash) - bt->func = ban_cond_hash_regexp; - else - bt->func = ban_cond_url_regexp; - - i = regcomp(&bt->re, regexp, REG_EXTENDED | REG_ICASE | REG_NOSUB); + i = regcomp(&bt->re, a3, REG_EXTENDED | REG_ICASE | REG_NOSUB); if (i) { (void)regerror(i, &bt->re, buf, sizeof buf); regfree(&bt->re); VSL(SLT_Debug, 0, "REGEX: <%s>", buf); cli_out(cli, "%s", buf); cli_result(cli, CLIS_PARAM); - ban_free_ban(b); return (-1); } - b->hash = hash; - b->ban = strdup(regexp); - AN(b->ban); + + if (!strcmp(a1, "req.url")) + bt->func = ban_cond_url_regexp; + else if (!strcmp(a1, "obj.hash")) + bt->func = ban_cond_hash_regexp; + else { + cli_out(cli, "unknown or unsupported field \"%s\"", a1); + cli_result(cli, CLIS_PARAM); + return (-1); + } + + /* XXX: proper quoting */ + asprintf(&bt->test, "%s %s \"%s\"", a1, a2, a3); + + return (0); +} + +/*-------------------------------------------------------------------- + */ + + +/* + * We maintain ban_start as a pointer to the first element of the list + * as a separate variable from the VTAILQ, to avoid depending on the + * internals of the VTAILQ macros. We tacitly assume that a pointer + * write is always atomic in doing so. + */ +static struct ban * volatile ban_start; + +static void +BAN_Insert(struct ban *b) +{ + struct ban *bi, *be; + unsigned pcount; + + CHECK_OBJ_NOTNULL(b, BAN_MAGIC); + ban_sort_by_cost(b); + Lck_Lock(&ban_mtx); VTAILQ_INSERT_HEAD(&ban_head, b, list); ban_start = b; @@ -242,7 +293,7 @@ Lck_Unlock(&ban_mtx); if (be == NULL) - return (0); + return; /* Hunt down duplicates, and mark them as gone */ bi = b; @@ -251,10 +302,8 @@ bi = VTAILQ_NEXT(bi, list); if (bi->flags & BAN_F_GONE) continue; - if (b->hash != bi->hash) + if (ban_compare(b, bi)) continue; - if (strcmp(b->ban, bi->ban)) - continue; bi->flags |= BAN_F_GONE; pcount++; } @@ -263,8 +312,6 @@ /* XXX: We should check if the tail can be removed */ VSL_stats->n_purge_dups += pcount; Lck_Unlock(&ban_mtx); - - return (0); } void @@ -363,37 +410,97 @@ * CLI functions to add bans */ -#if 0 static void ccf_purge(struct cli *cli, const char * const *av, void *priv) { + int narg, i; + struct ban *b; (void)priv; - (void)av; - (void)cli; + + /* First do some cheap checks on the arguments */ + for (narg = 0; av[narg + 2] != NULL; narg++) + continue; + if ((narg % 4) != 3) { + cli_out(cli, "Wrong number of arguments"); + cli_result(cli, CLIS_PARAM); + return; + } + for (i = 3; i < narg; i += 4) { + if (strcmp(av[i + 2], "&&")) { + cli_out(cli, "Found \"%s\" expected &&", av[i + 2]); + cli_result(cli, CLIS_PARAM); + return; + } + } + + b = ban_new_ban(); + if (b == NULL) { + cli_out(cli, "Out of Memory"); + cli_result(cli, CLIS_CANT); + return; + } + for (i = 0; i < narg; i += 4) + if (ban_parse_test(cli, b, av[i + 2], av[i + 3], av[i + 4])) { + ban_free_ban(b); + return; + } + BAN_Insert(b); } -#endif +int +BAN_Add(struct cli *cli, const char *regexp, int hash) +{ + const char *aav[6]; + + aav[0] = NULL; + aav[1] = "purge"; + if (hash) + aav[2] = "obj.hash"; + else + aav[2] = "req.url"; + aav[3] = "~"; + aav[4] = regexp; + aav[5] = NULL; + ccf_purge(cli, aav, NULL); + return (0); +} + static void ccf_purge_url(struct cli *cli, const char * const *av, void *priv) { + const char *aav[6]; (void)priv; - (void)BAN_Add(cli, av[2], 0); + aav[0] = NULL; + aav[1] = "purge"; + aav[2] = "req.url"; + aav[3] = "~"; + aav[4] = av[2]; + aav[5] = NULL; + ccf_purge(cli, aav, priv); } static void ccf_purge_hash(struct cli *cli, const char * const *av, void *priv) { + const char *aav[6]; (void)priv; - (void)BAN_Add(cli, av[2], 1); + aav[0] = NULL; + aav[1] = "purge"; + aav[2] = "obj.hash"; + aav[3] = "~"; + aav[4] = av[2]; + aav[5] = NULL; + ccf_purge(cli, aav, priv); } static void ccf_purge_list(struct cli *cli, const char * const *av, void *priv) { struct ban *b0; + struct ban_test *bt; (void)av; (void)priv; @@ -408,10 +515,10 @@ for (b0 = ban_start; b0 != NULL; b0 = VTAILQ_NEXT(b0, list)) { if (b0->refcount == 0 && VTAILQ_NEXT(b0, list) == NULL) break; - cli_out(cli, "%5u %d %s \"%s\"\n", - b0->refcount, b0->flags, - b0->hash ? "hash" : "url ", - b0->ban); + VTAILQ_FOREACH(bt, &b0->tests, list) + cli_out(cli, "%5u %d \"%s\"\n", + b0->refcount, b0->flags, + bt->test); } } @@ -425,9 +532,7 @@ { CLI_PURGE_URL, ccf_purge_url }, { CLI_PURGE_HASH, ccf_purge_hash }, -#if 0 { CLI_PURGE, ccf_purge }, -#endif { CLI_PURGE_LIST, ccf_purge_list }, { NULL } }; From phk at projects.linpro.no Tue Jan 13 14:18:09 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 13 Jan 2009 15:18:09 +0100 (CET) Subject: r3510 - trunk/varnish-cache/include Message-ID: <20090113141809.11E981EC38D@projects.linpro.no> Author: phk Date: 2009-01-13 15:18:08 +0100 (Tue, 13 Jan 2009) New Revision: 3510 Modified: trunk/varnish-cache/include/cli.h Log: Add CLI_PURGE definition Modified: trunk/varnish-cache/include/cli.h =================================================================== --- trunk/varnish-cache/include/cli.h 2009-01-13 14:05:54 UTC (rev 3509) +++ trunk/varnish-cache/include/cli.h 2009-01-13 14:18:08 UTC (rev 3510) @@ -74,6 +74,13 @@ "marked obsolete.", \ 1, 1 +#define CLI_PURGE \ + "purge", \ + "purge [&& ]...", \ + "\tAll objects where the all the conditions match will be " \ + "marked obsolete.", \ + 3, UINT_MAX + #define CLI_PURGE_LIST \ "purge.list", \ "purge.list", \ From phk at projects.linpro.no Tue Jan 13 14:18:55 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 13 Jan 2009 15:18:55 +0100 (CET) Subject: r3511 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20090113141855.09F9A1EC35F@projects.linpro.no> Author: phk Date: 2009-01-13 15:18:54 +0100 (Tue, 13 Jan 2009) New Revision: 3511 Added: trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc Log: Add testcase for cli:purge Added: trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-01-13 14:18:54 UTC (rev 3511) @@ -0,0 +1,41 @@ +# $Id: c00006.vtc 2906 2008-07-08 10:29:07Z phk $ + +test "Test banning a url with cli:purge" + +server s1 { + rxreq + expect req.url == "/foo" + txresp -body "1111\n" + rxreq + expect req.url == "/foo" + txresp -body "11111\n" +} -start + +varnish v1 -vcl+backend { } -start + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.content-length == 5 +} + +client c1 -run + +varnish v1 -clierr 104 "purge" +varnish v1 -clierr 104 "purge foo" +varnish v1 -clierr 104 "purge foo bar" +varnish v1 -clierr 106 "purge a b c && a" +varnish v1 -clierr 106 "purge a b c && a b" +varnish v1 -clierr 106 "purge a b c || a b c" +varnish v1 -cli "purge req.url ~ foo" +# varnish v1 -cli "purge req.url ~ foo && req.url ~ bar" + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.content-length == 6 +} + +client c1 -run From phk at projects.linpro.no Wed Jan 14 20:28:27 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 14 Jan 2009 21:28:27 +0100 (CET) Subject: r3512 - trunk/varnish-cache/bin/varnishd Message-ID: <20090114202827.A1AF41EC0E0@projects.linpro.no> Author: phk Date: 2009-01-14 21:28:27 +0100 (Wed, 14 Jan 2009) New Revision: 3512 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_pipe.c trunk/varnish-cache/bin/varnishd/cache_response.c trunk/varnish-cache/bin/varnishd/cache_session.c trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Originally we shaved 64 bytes from the session to the worker thread by keeping the current requests accounting stats in the worker thread. For reasons which will be explained in the next commit, this is no longer a good idea, and this commit moves these counters from the worker thread to the session at a slight but all in all trivial cost in memory footprint. Remove the call to SES_Charge() when we hit a busy object, it is not necessary to clean the worker thread counters here now. Move these counters from the worker thread to the see Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-01-13 14:18:54 UTC (rev 3511) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-01-14 20:28:27 UTC (rev 3512) @@ -199,7 +199,6 @@ struct VCL_conf *vcl; struct srcaddr *srcaddr; - struct acct acct; unsigned char *wlb, *wlp, *wle; unsigned wlr; @@ -370,6 +369,7 @@ struct workreq workreq; struct acct acct; + struct acct acct_req; /* pointers to hash string components */ unsigned nhashptr; Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-01-13 14:18:54 UTC (rev 3511) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-01-14 20:28:27 UTC (rev 3512) @@ -427,7 +427,7 @@ EXP_Insert(sp->obj); HSH_Unbusy(sp); } - sp->wrk->acct.fetch++; + sp->acct_req.fetch++; sp->step = STP_DELIVER; return (0); } @@ -457,7 +457,7 @@ /* Receive a HTTP protocol request */ HTC_Init(sp->htc, sp->ws, sp->fd); sp->wrk->lastused = sp->t_open; - sp->wrk->acct.sess++; + sp->acct_req.sess++; SES_RefSrcAddr(sp); do i = HTC_Rx(sp->htc); @@ -591,7 +591,6 @@ if (params->diag_bitmap & 0x20) WSP(sp, SLT_Debug, "on waiting list <%s>", sp->objhead->hash); - SES_Charge(sp); return (1); } @@ -721,7 +720,7 @@ return (0); } assert(sp->handling == VCL_RET_PASS); - sp->wrk->acct.pass++; + sp->acct_req.pass++; HSH_Prealloc(sp); sp->obj = sp->wrk->nobj; sp->wrk->nobj = NULL; @@ -763,7 +762,7 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); - sp->wrk->acct.pipe++; + sp->acct_req.pipe++; http_FilterHeader(sp, HTTPH_R_PIPE); VCL_pipe_method(sp); @@ -871,7 +870,7 @@ VSL_stats->client_req++; /* XXX not locked */ sp->t_req = TIM_real(); sp->wrk->lastused = sp->t_req; - sp->wrk->acct.req++; + sp->acct_req.req++; /* Assign XID and log */ sp->xid = ++xids; /* XXX not locked */ Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2009-01-13 14:18:54 UTC (rev 3511) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2009-01-14 20:28:27 UTC (rev 3512) @@ -84,10 +84,10 @@ TCP_blocking(vc->fd); WRW_Reserve(w, &vc->fd); - w->acct.hdrbytes += http_Write(w, bereq->http, 0); + sp->acct_req.hdrbytes += http_Write(w, bereq->http, 0); if (sp->htc->pipeline.b != NULL) - w->acct.bodybytes += + sp->acct_req.bodybytes += WRW_Write(w, sp->htc->pipeline.b, Tlen(sp->htc->pipeline)); if (WRW_FlushRelease(w)) { Modified: trunk/varnish-cache/bin/varnishd/cache_response.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_response.c 2009-01-13 14:18:54 UTC (rev 3511) +++ trunk/varnish-cache/bin/varnishd/cache_response.c 2009-01-14 20:28:27 UTC (rev 3512) @@ -140,7 +140,7 @@ WRW_Reserve(sp->wrk, &sp->fd); if (sp->esis == 0) - sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1); + sp->acct_req.hdrbytes += http_Write(sp->wrk, sp->http, 1); if (sp->wantbody && !VTAILQ_EMPTY(&sp->obj->esibits)) { if (WRW_FlushRelease(sp->wrk)) { @@ -161,7 +161,7 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(st, STORAGE_MAGIC); u += st->len; - sp->wrk->acct.bodybytes += st->len; + sp->acct_req.bodybytes += st->len; #ifdef SENDFILE_WORKS /* * XXX: the overhead of setting up sendfile is not Modified: trunk/varnish-cache/bin/varnishd/cache_session.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_session.c 2009-01-13 14:18:54 UTC (rev 3511) +++ trunk/varnish-cache/bin/varnishd/cache_session.c 2009-01-14 20:28:27 UTC (rev 3512) @@ -222,7 +222,7 @@ void SES_Charge(struct sess *sp) { - struct acct *a = &sp->wrk->acct; + struct acct *a = &sp->acct_req; struct acct b; ses_sum_acct(&sp->acct, a); Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-01-13 14:18:54 UTC (rev 3511) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-01-14 20:28:27 UTC (rev 3512) @@ -808,7 +808,7 @@ if (Tlen(eb->verbatim)) { if (sp->http->protover >= 1.1) (void)WRW_Write(sp->wrk, eb->chunk_length, -1); - sp->wrk->acct.bodybytes += WRW_Write(sp->wrk, + sp->acct_req.bodybytes += WRW_Write(sp->wrk, eb->verbatim.b, Tlen(eb->verbatim)); if (sp->http->protover >= 1.1) (void)WRW_Write(sp->wrk, "\r\n", -1); From phk at projects.linpro.no Wed Jan 14 20:40:54 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 14 Jan 2009 21:40:54 +0100 (CET) Subject: r3513 - trunk/varnish-cache/bin/varnishd Message-ID: <20090114204054.B880B1EC215@projects.linpro.no> Author: phk Date: 2009-01-14 21:40:54 +0100 (Wed, 14 Jan 2009) New Revision: 3513 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_hash.c Log: After HSH_Lookup() returns NULL indicating a busy object, we diddled the session a bit to transfer the per-request stats to the session counters with SES_Charge(). Not only was it inconsistent to charge accounting data in the middle of a request, it was also illegal because after the hash lock was released we no longer owned the session. Once a system is under sufficient load that there is a queue for the CPU, a race could happen where upon hitting a busy object, the hash lock was released, another thread would schedule, finish the busy object, start the sessions on the waiting list, finish off the request we had and then when we get the cpu again and access it, it's gone. The previous commit (r3512) eliminated the need to call SES_Charge, this commit removes the (option) shmlog message inside the hash lock thus, hopefully, eliminating the race that caused #418. Fixes: #418 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-01-14 20:28:27 UTC (rev 3512) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-01-14 20:40:54 UTC (rev 3513) @@ -584,13 +584,10 @@ if (o == NULL) { /* - * We hit a busy object, disembark worker thread and expect - * hash code to restart us, still in STP_LOOKUP, later. + * We lost the session to a busy object, disembark the + * worker thread. The hash code to restart the session, + * still in STP_LOOKUP, later when the busy object isn't. */ - assert(sp->objhead != NULL); - if (params->diag_bitmap & 0x20) - WSP(sp, SLT_Debug, - "on waiting list <%s>", sp->objhead->hash); return (1); } Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-14 20:28:27 UTC (rev 3512) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-14 20:40:54 UTC (rev 3513) @@ -298,6 +298,9 @@ /* There are one or more busy objects, wait for them */ if (sp->esis == 0) VTAILQ_INSERT_TAIL(&oh->waitinglist, sp, list); + if (params->diag_bitmap & 0x20) + WSP(sp, SLT_Debug, + "on waiting list <%s>", oh->hash); sp->objhead = oh; Lck_Unlock(&oh->mtx); return (NULL); From phk at projects.linpro.no Sun Jan 18 14:26:32 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 18 Jan 2009 15:26:32 +0100 (CET) Subject: r3514 - trunk/varnish-cache/bin/varnishd Message-ID: <20090118142632.DBC2B97B42@projects.linpro.no> Author: phk Date: 2009-01-18 15:26:32 +0100 (Sun, 18 Jan 2009) New Revision: 3514 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c Log: redo the purge.list function with proper locking Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-14 20:40:54 UTC (rev 3513) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 14:26:32 UTC (rev 3514) @@ -499,27 +499,30 @@ static void ccf_purge_list(struct cli *cli, const char * const *av, void *priv) { - struct ban *b0; + struct ban *b; struct ban_test *bt; (void)av; (void)priv; - /* - * XXX: Strictly speaking, this loop traversal is not lock-safe - * XXX: because we might inspect the last ban while it gets - * XXX: destroyed. To properly fix this, we would need to either - * XXX: hold the lock over the entire loop, or grab refcounts - * XXX: under lock for each element of the list. - * XXX: We do neither, and hope for the best. - */ - for (b0 = ban_start; b0 != NULL; b0 = VTAILQ_NEXT(b0, list)) { - if (b0->refcount == 0 && VTAILQ_NEXT(b0, list) == NULL) - break; - VTAILQ_FOREACH(bt, &b0->tests, list) - cli_out(cli, "%5u %d \"%s\"\n", - b0->refcount, b0->flags, - bt->test); + + Lck_Lock(&ban_mtx); + VTAILQ_LAST(&ban_head, banhead)->refcount++; + Lck_Unlock(&ban_mtx); + + VTAILQ_FOREACH(b, &ban_head, list) { + bt = VTAILQ_FIRST(&b->tests); + cli_out(cli, "%5u %4s\t%s\n", + b->refcount, b->flags ? "Gone" : "", bt->test); + do { + bt = VTAILQ_NEXT(bt, list); + if (bt != NULL) + cli_out(cli, "\t\t%s\n", bt->test); + } while (bt != NULL); } + + Lck_Lock(&ban_mtx); + VTAILQ_LAST(&ban_head, banhead)->refcount--; + Lck_Unlock(&ban_mtx); } static struct cli_proto ban_cmds[] = { From phk at projects.linpro.no Sun Jan 18 14:50:21 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 18 Jan 2009 15:50:21 +0100 (CET) Subject: r3515 - in trunk/varnish-cache: include lib/libvarnish Message-ID: <20090118145021.1E0B597B42@projects.linpro.no> Author: phk Date: 2009-01-18 15:50:20 +0100 (Sun, 18 Jan 2009) New Revision: 3515 Modified: trunk/varnish-cache/include/vsb.h trunk/varnish-cache/lib/libvarnish/cli_common.c trunk/varnish-cache/lib/libvarnish/vsb.c Log: Move the body of cli_quote() to vsb_quote() and give it a, presently unused, "how" argument flag. We currently have far too many "quote this string properly" implementations in varnish, hopefully, this will replace most of them. Once this stabilizes, vsb_quote() will be contributed back to FreeBSD. Modified: trunk/varnish-cache/include/vsb.h =================================================================== --- trunk/varnish-cache/include/vsb.h 2009-01-18 14:26:32 UTC (rev 3514) +++ trunk/varnish-cache/include/vsb.h 2009-01-18 14:50:20 UTC (rev 3515) @@ -77,6 +77,7 @@ int vsb_len(struct vsb *); int vsb_done(const struct vsb *); void vsb_delete(struct vsb *); +void vsb_quote(struct vsb *s, const char *p, int how); #ifdef __cplusplus }; #endif Modified: trunk/varnish-cache/lib/libvarnish/cli_common.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/cli_common.c 2009-01-18 14:26:32 UTC (rev 3514) +++ trunk/varnish-cache/lib/libvarnish/cli_common.c 2009-01-18 14:50:20 UTC (rev 3515) @@ -72,48 +72,8 @@ void cli_quote(struct cli *cli, const char *s) { - const char *q; - int quote = 0; - for (q = s; *q != '\0'; q++) { - if (!isgraph(*q) || *q == '"') { - quote++; - break; - } - } - if (!quote) { - (void)vsb_cat(cli->sb, s); - return; - } - (void)vsb_putc(cli->sb, '"'); - for (q = s; *q != '\0'; q++) { - switch (*q) { - case ' ': - (void)vsb_putc(cli->sb, *q); - break; - case '\\': - case '"': - (void)vsb_putc(cli->sb, '\\'); - (void)vsb_putc(cli->sb, *q); - break; - case '\n': - (void)vsb_cat(cli->sb, "\\n"); - break; - case '\r': - (void)vsb_cat(cli->sb, "\\r"); - break; - case '\t': - (void)vsb_cat(cli->sb, "\\t"); - break; - default: - if (isgraph(*q)) - (void)vsb_putc(cli->sb, *q); - else - (void)vsb_printf(cli->sb, "\\%o", *q); - break; - } - } - (void)vsb_putc(cli->sb, '"'); + vsb_quote(cli->sb, s, 0); } void Modified: trunk/varnish-cache/lib/libvarnish/vsb.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vsb.c 2009-01-18 14:26:32 UTC (rev 3514) +++ trunk/varnish-cache/lib/libvarnish/vsb.c 2009-01-18 14:50:20 UTC (rev 3515) @@ -476,3 +476,55 @@ return(VSB_ISFINISHED(s)); } + +/* + * Quote a string + */ +void +vsb_quote(struct vsb *s, const char *p, int how) +{ + const char *q; + int quote = 0; + + (void)how; /* For future enhancements */ + + for (q = p; *q != '\0'; q++) { + if (!isgraph(*q) || *q == '"') { + quote++; + break; + } + } + if (!quote) { + (void)vsb_cat(s, p); + return; + } + (void)vsb_putc(s, '"'); + for (q = p; *q != '\0'; q++) { + switch (*q) { + case ' ': + (void)vsb_putc(s, *q); + break; + case '\\': + case '"': + (void)vsb_putc(s, '\\'); + (void)vsb_putc(s, *q); + break; + case '\n': + (void)vsb_cat(s, "\\n"); + break; + case '\r': + (void)vsb_cat(s, "\\r"); + break; + case '\t': + (void)vsb_cat(s, "\\t"); + break; + default: + if (isgraph(*q)) + (void)vsb_putc(s, *q); + else + (void)vsb_printf(s, "\\%o", *q); + break; + } + } + (void)vsb_putc(s, '"'); +} From phk at projects.linpro.no Sun Jan 18 14:54:41 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 18 Jan 2009 15:54:41 +0100 (CET) Subject: r3516 - in trunk/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090118145441.82EA497B42@projects.linpro.no> Author: phk Date: 2009-01-18 15:54:41 +0100 (Sun, 18 Jan 2009) New Revision: 3516 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc Log: Properly quote the ban descriptions. Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 14:50:20 UTC (rev 3515) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 14:54:41 UTC (rev 3516) @@ -215,6 +215,7 @@ { struct ban_test *bt; char buf[512]; + struct vsb *sb; int i; CHECK_OBJ_NOTNULL(b, BAN_MAGIC); @@ -253,8 +254,15 @@ } /* XXX: proper quoting */ - asprintf(&bt->test, "%s %s \"%s\"", a1, a2, a3); - + sb = vsb_newauto(); + XXXAN(sb); + vsb_printf(sb, "%s %s ", a1, a2); + vsb_quote(sb, a3, 0); + vsb_finish(sb); + AZ(vsb_overflowed(sb)); + bt->test = strdup(vsb_data(sb)); + XXXAN(bt->test); + vsb_delete(sb); return (0); } Modified: trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-01-18 14:50:20 UTC (rev 3515) +++ trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-01-18 14:54:41 UTC (rev 3516) @@ -28,8 +28,8 @@ varnish v1 -clierr 106 "purge a b c && a" varnish v1 -clierr 106 "purge a b c && a b" varnish v1 -clierr 106 "purge a b c || a b c" -varnish v1 -cli "purge req.url ~ foo" -# varnish v1 -cli "purge req.url ~ foo && req.url ~ bar" +varnish v1 -cliok "purge req.url ~ foo && req.url ~ \"[ o]\"" +varnish v1 -cliok "purge.list" client c1 { txreq -url "/foo" From phk at projects.linpro.no Sun Jan 18 15:14:54 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 18 Jan 2009 16:14:54 +0100 (CET) Subject: r3517 - trunk/varnish-cache/bin/varnishd Message-ID: <20090118151454.D23A597B42@projects.linpro.no> Author: phk Date: 2009-01-18 16:14:54 +0100 (Sun, 18 Jan 2009) New Revision: 3517 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c Log: Don't list gone bans. Emit && \ for line continuation. Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 14:54:41 UTC (rev 3516) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 15:14:54 UTC (rev 3517) @@ -518,14 +518,16 @@ Lck_Unlock(&ban_mtx); VTAILQ_FOREACH(b, &ban_head, list) { + if (b->flags & BAN_F_GONE) + continue; bt = VTAILQ_FIRST(&b->tests); - cli_out(cli, "%5u %4s\t%s\n", - b->refcount, b->flags ? "Gone" : "", bt->test); + cli_out(cli, "%5u\t%s", b->refcount, bt->test); do { bt = VTAILQ_NEXT(bt, list); if (bt != NULL) - cli_out(cli, "\t\t%s\n", bt->test); + cli_out(cli, " && \\\n\t%s", bt->test); } while (bt != NULL); + cli_out(cli, "\n"); } Lck_Lock(&ban_mtx); From phk at projects.linpro.no Sun Jan 18 15:42:29 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 18 Jan 2009 16:42:29 +0100 (CET) Subject: r3518 - in trunk/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090118154229.A8D0697B42@projects.linpro.no> Author: phk Date: 2009-01-18 16:42:29 +0100 (Sun, 18 Jan 2009) New Revision: 3518 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc Log: Implement exact matching and negatives for bans. You can now purge using these four conditionals: purge req.url == "/diediedie.html" purge req.url != "/index.html" purge req.url !~ "\.html$" purge req.url ~ "\.jpg$" Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 15:14:54 UTC (rev 3517) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 15:42:29 UTC (rev 3518) @@ -70,7 +70,11 @@ int cost; char *test; ban_cond_f *func; + int flags; +#define BAN_T_REGEXP (1 << 0) +#define BAN_T_NOT (1 << 1) regex_t re; + char *dst; }; struct ban { @@ -145,7 +149,10 @@ bt = VTAILQ_FIRST(&b->tests); VTAILQ_REMOVE(&b->tests, bt, list); free(bt->test); - regfree(&bt->re); + if (bt->flags & BAN_T_REGEXP) + regfree(&bt->re); + if (bt->dst != NULL) + free(bt->dst); FREE_OBJ(bt); } FREE_OBJ(b); @@ -188,22 +195,38 @@ */ static int -ban_cond_url_regexp(const struct ban_test *bt, const struct object *o, +ban_cond_str(const struct ban_test *bt, const char *p) +{ + int i; + + if (bt->flags & BAN_T_REGEXP) + i = regexec(&bt->re, p, 0, NULL, 0); + else + i = strcmp(bt->dst, p); + if (bt->flags & BAN_T_NOT) + return (i); + return (!i); +} + +static int +ban_cond_url(const struct ban_test *bt, const struct object *o, const struct sess *sp) { (void)o; - return (!regexec(&bt->re, sp->http->hd[HTTP_HDR_URL].b, 0, NULL, 0)); + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + return(ban_cond_str(bt, sp->http->hd[HTTP_HDR_URL].b)); } static int -ban_cond_hash_regexp(const struct ban_test *bt, const struct object *o, +ban_cond_hash(const struct ban_test *bt, const struct object *o, const struct sess *sp) { (void)sp; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o->objhead, OBJHEAD_MAGIC); AN(o->objhead->hash); - return (!regexec(&bt->re, o->objhead->hash, 0, NULL, 0)); + return(ban_cond_str(bt, o->objhead->hash)); } /*-------------------------------------------------------------------- @@ -211,10 +234,28 @@ */ static int +ban_parse_regexp(struct cli *cli, struct ban_test *bt, const char *a3) +{ + int i; + char buf[512]; + + i = regcomp(&bt->re, a3, REG_EXTENDED | REG_ICASE | REG_NOSUB); + if (i) { + (void)regerror(i, &bt->re, buf, sizeof buf); + regfree(&bt->re); + VSL(SLT_Debug, 0, "REGEX: <%s>", buf); + cli_out(cli, "%s", buf); + cli_result(cli, CLIS_PARAM); + return (-1); + } + bt->flags |= BAN_T_REGEXP; + return (0); +} + +static int ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) { struct ban_test *bt; - char buf[512]; struct vsb *sb; int i; @@ -226,27 +267,32 @@ return (-1); } - if (strcmp(a2, "~")) { - /* XXX: Add more conditionals */ - cli_out(cli, "expected \"~\" got \"%s\"", a2); + if (!strcmp(a2, "~")) { + i = ban_parse_regexp(cli, bt, a3); + if (i) + return (i); + } else if (!strcmp(a2, "!~")) { + bt->flags |= BAN_T_NOT; + i = ban_parse_regexp(cli, bt, a3); + if (i) + return (i); + } else if (!strcmp(a2, "==")) { + bt->dst = strdup(a3); + XXXAN(bt->dst); + } else if (!strcmp(a2, "!=")) { + bt->flags |= BAN_T_NOT; + bt->dst = strdup(a3); + XXXAN(bt->dst); + } else { + cli_out(cli, + "expected conditional (~, !~, == or !=) got \"%s\"", a2); cli_result(cli, CLIS_PARAM); return (-1); } - - i = regcomp(&bt->re, a3, REG_EXTENDED | REG_ICASE | REG_NOSUB); - if (i) { - (void)regerror(i, &bt->re, buf, sizeof buf); - regfree(&bt->re); - VSL(SLT_Debug, 0, "REGEX: <%s>", buf); - cli_out(cli, "%s", buf); - cli_result(cli, CLIS_PARAM); - return (-1); - } - if (!strcmp(a1, "req.url")) - bt->func = ban_cond_url_regexp; + bt->func = ban_cond_url; else if (!strcmp(a1, "obj.hash")) - bt->func = ban_cond_hash_regexp; + bt->func = ban_cond_hash; else { cli_out(cli, "unknown or unsupported field \"%s\"", a1); cli_result(cli, CLIS_PARAM); Modified: trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-01-18 15:14:54 UTC (rev 3517) +++ trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-01-18 15:42:29 UTC (rev 3518) @@ -28,6 +28,14 @@ varnish v1 -clierr 106 "purge a b c && a" varnish v1 -clierr 106 "purge a b c && a b" varnish v1 -clierr 106 "purge a b c || a b c" +varnish v1 -cliok "purge req.url == foo" +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.content-length == 5 +} + varnish v1 -cliok "purge req.url ~ foo && req.url ~ \"[ o]\"" varnish v1 -cliok "purge.list" From phk at projects.linpro.no Sun Jan 18 16:25:54 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 18 Jan 2009 17:25:54 +0100 (CET) Subject: r3519 - in trunk/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090118162554.D882B97B42@projects.linpro.no> Author: phk Date: 2009-01-18 17:25:54 +0100 (Sun, 18 Jan 2009) New Revision: 3519 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc Log: Add the ability to purge on random request or object headers. For instance: purge req.http.host ~ www.foo.com && req.url ~ "\.png$" purge obj.http.set-cookie ~ USER=383839 Now, why would you want purge on request headers and not object headers ? Simple, some information the object does not have, the Host: header is a good example. Assuming that the Host: header is part of the hash we use to lookup an object (as is the default), we can avoid copying that field into the object (saving memory: O(nObjects)) by using the request value to purge against. Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 15:42:29 UTC (rev 3518) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 16:25:54 UTC (rev 3519) @@ -75,6 +75,7 @@ #define BAN_T_NOT (1 << 1) regex_t re; char *dst; + char *src; }; struct ban { @@ -191,7 +192,7 @@ } /*-------------------------------------------------------------------- - * Test functions -- return 0 if the test does not match + * Test functions -- return 0 if the test matches */ static int @@ -199,13 +200,15 @@ { int i; + if (p == NULL) + return(!(bt->flags & BAN_T_NOT)); if (bt->flags & BAN_T_REGEXP) i = regexec(&bt->re, p, 0, NULL, 0); else i = strcmp(bt->dst, p); if (bt->flags & BAN_T_NOT) - return (i); - return (!i); + return (!i); + return (i); } static int @@ -229,6 +232,30 @@ return(ban_cond_str(bt, o->objhead->hash)); } +static int +ban_cond_req_http(const struct ban_test *bt, const struct object *o, + const struct sess *sp) +{ + char *s; + + (void)o; + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + http_GetHdr(sp->http, bt->src, &s); + return (ban_cond_str(bt, s)); +} + +static int +ban_cond_obj_http(const struct ban_test *bt, const struct object *o, + const struct sess *sp) +{ + char *s; + + (void)sp; + CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); + http_GetHdr(o->http, bt->src, &s); + return (ban_cond_str(bt, s)); +} + /*-------------------------------------------------------------------- * Parse and add a ban test specification */ @@ -252,6 +279,20 @@ return (0); } +static void +ban_parse_http(struct ban_test *bt, const char *a1) +{ + int l; + + l = strlen(a1); + bt->src = malloc(l + 3); + XXXAN(bt->src); + bt->src[0] = l + 1; + memcpy(bt->src + 1, a1, l); + bt->src[l + 1] = ':'; + bt->src[l + 2] = '\0'; +} + static int ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) { @@ -289,11 +330,19 @@ cli_result(cli, CLIS_PARAM); return (-1); } + + if (!strcmp(a1, "req.url")) bt->func = ban_cond_url; else if (!strcmp(a1, "obj.hash")) bt->func = ban_cond_hash; - else { + else if (!strncmp(a1, "req.http.", 9)) { + bt->func = ban_cond_req_http; + ban_parse_http(bt, a1 + 9); + } else if (!strncmp(a1, "obj.http.", 9)) { + bt->func = ban_cond_obj_http; + ban_parse_http(bt, a1 + 9); + } else { cli_out(cli, "unknown or unsupported field \"%s\"", a1); cli_result(cli, CLIS_PARAM); return (-1); @@ -439,7 +488,7 @@ if (bt->func(bt, o, sp)) break; } - if (bt != NULL) + if (bt == NULL) break; } Modified: trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-01-18 15:42:29 UTC (rev 3518) +++ trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-01-18 16:25:54 UTC (rev 3519) @@ -5,10 +5,19 @@ server s1 { rxreq expect req.url == "/foo" - txresp -body "1111\n" + txresp -hdr "foo: bar5" -body "1111\n" + rxreq expect req.url == "/foo" - txresp -body "11111\n" + txresp -hdr "foo: bar6" -body "11111\n" + + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar7" -body "111111\n" + + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar8" -body "1111111\n" } -start varnish v1 -vcl+backend { } -start @@ -17,33 +26,101 @@ txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 5 -} + expect resp.http.foo == bar5 + expect resp.bodylen == 5 +} -run -client c1 -run - +# syntax checks varnish v1 -clierr 104 "purge" varnish v1 -clierr 104 "purge foo" varnish v1 -clierr 104 "purge foo bar" varnish v1 -clierr 106 "purge a b c && a" varnish v1 -clierr 106 "purge a b c && a b" varnish v1 -clierr 106 "purge a b c || a b c" +varnish v1 -cliok "purge.list" + +# exact match, not matching varnish v1 -cliok "purge req.url == foo" +varnish v1 -cliok "purge.list" + client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 5 -} + expect resp.http.foo == bar5 + expect resp.bodylen == 5 +} -run -varnish v1 -cliok "purge req.url ~ foo && req.url ~ \"[ o]\"" +# exact match, matching +varnish v1 -cliok "purge req.url == /foo" varnish v1 -cliok "purge.list" +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar6 + expect resp.bodylen == 6 +} -run +# regexp nonmatch +varnish v1 -cliok "purge req.url ~ bar" +varnish v1 -cliok "purge.list" + client c1 { txreq -url "/foo" rxresp expect resp.status == 200 - expect resp.http.content-length == 6 -} + expect resp.http.foo == bar6 + expect resp.bodylen == 6 +} -run -client c1 -run + +# regexp match +varnish v1 -cliok "purge req.url ~ foo" +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar7 + expect resp.bodylen == 7 +} -run + +# header check, nonmatch +varnish v1 -cliok "purge obj.http.foo != bar7" +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar7 + expect resp.bodylen == 7 +} -run + +# header check, match +varnish v1 -cliok "purge req.http.foo == barcheck" +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" -hdr "foo: barcheck" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar8 + expect resp.bodylen == 8 +} -run + +# header check, no header +varnish v1 -cliok "purge obj.http.bar == barcheck" +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar8 + expect resp.bodylen == 8 +} -run + + From phk at projects.linpro.no Sun Jan 18 16:43:47 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 18 Jan 2009 17:43:47 +0100 (CET) Subject: r3520 - in trunk/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090118164347.20FB297B42@projects.linpro.no> Author: phk Date: 2009-01-18 17:43:46 +0100 (Sun, 18 Jan 2009) New Revision: 3520 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc Log: Set cost 10 on regexp tests. Let purge.list prune the tail of the list before dumping. Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 16:25:54 UTC (rev 3519) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 16:43:46 UTC (rev 3520) @@ -154,6 +154,8 @@ regfree(&bt->re); if (bt->dst != NULL) free(bt->dst); + if (bt->src != NULL) + free(bt->src); FREE_OBJ(bt); } FREE_OBJ(b); @@ -276,6 +278,7 @@ return (-1); } bt->flags |= BAN_T_REGEXP; + bt->cost = 10; return (0); } @@ -429,6 +432,23 @@ Lck_Unlock(&ban_mtx); } +static struct ban * +BAN_CheckLast(void) +{ + struct ban *b; + + Lck_AssertHeld(&ban_mtx); + b = VTAILQ_LAST(&ban_head, banhead); + if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) { + VSL_stats->n_purge--; + VSL_stats->n_purge_retire++; + VTAILQ_REMOVE(&ban_head, b, list); + } else { + b = NULL; + } + return (b); +} + void BAN_DestroyObj(struct object *o) { @@ -442,21 +462,15 @@ o->ban->refcount--; o->ban = NULL; - /* Check if we can purge the last ban entry */ - b = VTAILQ_LAST(&ban_head, banhead); - if (b != VTAILQ_FIRST(&ban_head) && b->refcount == 0) { - VSL_stats->n_purge--; - VSL_stats->n_purge_retire++; - VTAILQ_REMOVE(&ban_head, b, list); - } else { - b = NULL; - } + /* Attempt to purge last ban entry */ + b = BAN_CheckLast(); Lck_Unlock(&ban_mtx); if (b != NULL) ban_free_ban(b); } + int BAN_CheckObject(struct object *o, const struct sess *sp) { @@ -608,9 +622,16 @@ (void)av; (void)priv; - Lck_Lock(&ban_mtx); - VTAILQ_LAST(&ban_head, banhead)->refcount++; - Lck_Unlock(&ban_mtx); + do { + /* Attempt to purge last ban entry */ + Lck_Lock(&ban_mtx); + b = BAN_CheckLast(); + if (b == NULL) + VTAILQ_LAST(&ban_head, banhead)->refcount++; + Lck_Unlock(&ban_mtx); + if (b != NULL) + ban_free_ban(b); + } while (b != NULL); VTAILQ_FOREACH(b, &ban_head, list) { if (b->flags & BAN_F_GONE) Modified: trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-01-18 16:25:54 UTC (rev 3519) +++ trunk/varnish-cache/bin/varnishtest/tests/c00021.vtc 2009-01-18 16:43:46 UTC (rev 3520) @@ -112,7 +112,7 @@ } -run # header check, no header -varnish v1 -cliok "purge obj.http.bar == barcheck" +varnish v1 -cliok "purge req.url ~ foo && obj.http.bar == barcheck" varnish v1 -cliok "purge.list" client c1 { From phk at projects.linpro.no Sun Jan 18 16:57:07 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 18 Jan 2009 17:57:07 +0100 (CET) Subject: r3521 - trunk/varnish-cache/bin/varnishtest/tests Message-ID: <20090118165707.231CC97B79@projects.linpro.no> Author: phk Date: 2009-01-18 17:57:06 +0100 (Sun, 18 Jan 2009) New Revision: 3521 Modified: trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc Log: Add a protective object to prevent purge.list from pruning our purges before we test their numbers. Modified: trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-01-18 16:43:46 UTC (rev 3520) +++ trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-01-18 16:57:06 UTC (rev 3521) @@ -4,6 +4,8 @@ server s1 { rxreq + txresp -hdr "foo: 0" -body "foo0" + rxreq txresp -hdr "foo: 1" -body "foo1" rxreq txresp -hdr "foo: 2" -body "foo2" @@ -22,6 +24,9 @@ # Our fetch is not affected by the purge # as the FOO-purge was preexisting client c1 { + txreq -url /BAR + rxresp + expect resp.http.foo == 0 txreq -url /FOO rxresp expect resp.http.foo == 1 @@ -64,7 +69,7 @@ # Enable dup removal of purges varnish v1 -cliok "param.set purge_dups on" -# This should incapacitate the to previous FOO purges. +# This should incapacitate the two previous FOO purges. varnish v1 -cliok "purge.url FOO" varnish v1 -expect n_purge_add == 6 varnish v1 -expect n_purge_dups == 3 From phk at projects.linpro.no Sun Jan 18 16:57:30 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sun, 18 Jan 2009 17:57:30 +0100 (CET) Subject: r3522 - trunk/varnish-cache/bin/varnishd Message-ID: <20090118165730.16C9497B79@projects.linpro.no> Author: phk Date: 2009-01-18 17:57:29 +0100 (Sun, 18 Jan 2009) New Revision: 3522 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c Log: List referenced, but gone purges, mark them with a "G" Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 16:57:06 UTC (rev 3521) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 16:57:29 UTC (rev 3522) @@ -415,7 +415,6 @@ } Lck_Lock(&ban_mtx); be->refcount--; - /* XXX: We should check if the tail can be removed */ VSL_stats->n_purge_dups += pcount; Lck_Unlock(&ban_mtx); } @@ -634,10 +633,12 @@ } while (b != NULL); VTAILQ_FOREACH(b, &ban_head, list) { - if (b->flags & BAN_F_GONE) + if (b->refcount == 0 && (b->flags & BAN_F_GONE)) continue; bt = VTAILQ_FIRST(&b->tests); - cli_out(cli, "%5u\t%s", b->refcount, bt->test); + cli_out(cli, "%5u%s\t%s", b->refcount, + b->flags & BAN_F_GONE ? "G" : " ", + bt->test); do { bt = VTAILQ_NEXT(bt, list); if (bt != NULL) From phk at projects.linpro.no Mon Jan 19 09:22:49 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 19 Jan 2009 10:22:49 +0100 (CET) Subject: r3523 - trunk/varnish-cache/bin/varnishd Message-ID: <20090119092249.4C33228429@projects.linpro.no> Author: phk Date: 2009-01-19 10:22:49 +0100 (Mon, 19 Jan 2009) New Revision: 3523 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c Log: A couple of FlexeLint nits Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-18 16:57:29 UTC (rev 3522) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-19 09:22:49 UTC (rev 3523) @@ -242,7 +242,7 @@ (void)o; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - http_GetHdr(sp->http, bt->src, &s); + (void)http_GetHdr(sp->http, bt->src, &s); return (ban_cond_str(bt, s)); } @@ -254,7 +254,7 @@ (void)sp; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); - http_GetHdr(o->http, bt->src, &s); + (void)http_GetHdr(o->http, bt->src, &s); return (ban_cond_str(bt, s)); } @@ -288,9 +288,10 @@ int l; l = strlen(a1); + assert(l < 127); bt->src = malloc(l + 3); XXXAN(bt->src); - bt->src[0] = l + 1; + bt->src[0] = (char)l + 1; memcpy(bt->src + 1, a1, l); bt->src[l + 1] = ':'; bt->src[l + 2] = '\0'; From phk at projects.linpro.no Mon Jan 19 09:36:07 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 19 Jan 2009 10:36:07 +0100 (CET) Subject: r3524 - trunk/varnish-cache/bin/varnishd Message-ID: <20090119093607.9AAF528429@projects.linpro.no> Author: phk Date: 2009-01-19 10:36:07 +0100 (Mon, 19 Jan 2009) New Revision: 3524 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_hash.c Log: Move the fiddling of banned objects to cache_ban.c Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-19 09:22:49 UTC (rev 3523) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-19 09:36:07 UTC (rev 3524) @@ -518,6 +518,9 @@ o->ban = b0; return (0); } else { + o->ttl = 0; + WSP(sp, SLT_ExpBan, "%u was banned", o->xid); + EXP_Rearm(o); o->ban = NULL; return (1); } Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-19 09:22:49 UTC (rev 3523) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-19 09:36:07 UTC (rev 3524) @@ -255,12 +255,8 @@ continue; if (o->ttl == 0) continue; - if (BAN_CheckObject(o, sp)) { - o->ttl = 0; - WSP(sp, SLT_ExpBan, "%u was banned", o->xid); - EXP_Rearm(o); + if (BAN_CheckObject(o, sp)) continue; - } if (o->vary != NULL && !VRY_Match(sp, o->vary)) continue; From phk at projects.linpro.no Mon Jan 19 09:48:16 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 19 Jan 2009 10:48:16 +0100 (CET) Subject: r3525 - trunk/varnish-cache/bin/varnishd Message-ID: <20090119094816.9A94E28429@projects.linpro.no> Author: phk Date: 2009-01-19 10:48:16 +0100 (Mon, 19 Jan 2009) New Revision: 3525 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_acceptor.h Log: Move the vca_pipes to a more proper header file Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-01-19 09:36:07 UTC (rev 3524) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-01-19 09:48:16 UTC (rev 3525) @@ -398,7 +398,6 @@ void vca_close_session(struct sess *sp, const char *why); void VCA_Prep(struct sess *sp); void VCA_Init(void); -extern int vca_pipes[2]; /* cache_backend.c */ Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_acceptor.h 2009-01-19 09:36:07 UTC (rev 3524) +++ trunk/varnish-cache/bin/varnishd/cache_acceptor.h 2009-01-19 09:48:16 UTC (rev 3525) @@ -34,6 +34,8 @@ typedef void acceptor_init_f(void); typedef void acceptor_pass_f(struct sess *); +extern int vca_pipes[2]; + struct acceptor { const char *name; acceptor_init_f *init; From phk at projects.linpro.no Mon Jan 19 11:45:04 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 19 Jan 2009 12:45:04 +0100 (CET) Subject: r3526 - in trunk/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090119114504.2E78397B4C@projects.linpro.no> Author: phk Date: 2009-01-19 12:45:03 +0100 (Mon, 19 Jan 2009) New Revision: 3526 Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/hash_slinger.h trunk/varnish-cache/bin/varnishd/heritage.h trunk/varnish-cache/bin/varnishd/mgt_param.c trunk/varnish-cache/bin/varnishtest/tests/c00007.vtc trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc Log: Add a new paramter "purge_hash" which defaults to "off". Only save the hash-string in the session workspace and objects when this paramter is set to "on". For sites with many small objects, this will save significant VM. When this paramter is set to "off", the "purge.hash" facility will not work, but this should not be a problem, because the new purging facility allow much more expressive purging, the typical case being: purge req.http.host ~ www.foo.com && req.url ~ "article2383" Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-19 09:48:16 UTC (rev 3525) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-19 11:45:03 UTC (rev 3526) @@ -607,6 +607,14 @@ const char *aav[6]; (void)priv; + if (!save_hash) { + cli_out(cli, + "purge.hash not possible.\n" + "Set the \"purge_hash\" parameter to on\n" + "and restart the varnish worker process to enable.\n"); + cli_result(cli, CLIS_CANT); + return; + } aav[0] = NULL; aav[1] = "purge"; aav[2] = "obj.hash"; Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-19 09:48:16 UTC (rev 3525) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-19 11:45:03 UTC (rev 3526) @@ -69,6 +69,7 @@ #include "vsha256.h" static const struct hash_slinger *hash; +unsigned save_hash; double HSH_Grace(double g) @@ -151,6 +152,8 @@ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); CHECK_OBJ_NOTNULL(oh, OBJHEAD_MAGIC); + if (!save_hash) + return; oh->hash = malloc(sp->lhashptr); XXXAN(oh->hash); @@ -172,6 +175,10 @@ char *p; unsigned u; + SHA256_Init(sp->wrk->sha256ctx); + if (!save_hash) + return; + /* Allocate the pointers we need, align properly. */ sp->lhashptr = 1; /* space for NUL */ sp->ihashptr = 0; @@ -184,7 +191,6 @@ if (u) p += sizeof(const char *) - u; sp->hashptr = (void*)p; - SHA256_Init(sp->wrk->sha256ctx); } void @@ -196,6 +202,15 @@ str = ""; l = strlen(str); + SHA256_Update(sp->wrk->sha256ctx, str, l); + SHA256_Update(sp->wrk->sha256ctx, "#", 1); + + if (params->log_hash) + WSP(sp, SLT_Hash, "%s", str); + + if (!save_hash) + return; + /* * XXX: handle this by bouncing sp->vcl->nhashcount when it fails * XXX: and dispose of this request either by reallocating the @@ -207,8 +222,6 @@ sp->hashptr[sp->ihashptr + 1] = str + l; sp->ihashptr += 2; sp->lhashptr += l + 1; - SHA256_Update(sp->wrk->sha256ctx, str, l); - SHA256_Update(sp->wrk->sha256ctx, "#", 1); } struct object * @@ -284,8 +297,6 @@ if (o->hits < INT_MAX) o->hits++; Lck_Unlock(&oh->mtx); - if (params->log_hash) - WSP(sp, SLT_Hash, "%s", oh->hash); (void)hash->deref(oh); return (o); } @@ -315,8 +326,6 @@ grace_o->refcnt++; } Lck_Unlock(&oh->mtx); - if (params->log_hash) - WSP(sp, SLT_Hash, "%s", oh->hash); /* * XXX: This may be too early, relative to pass objects. * XXX: possibly move to when we commit to have it in the cache. @@ -467,6 +476,7 @@ HSH_Init(void) { + save_hash = params->save_hash; hash = heritage.hash; if (hash->start != NULL) hash->start(); Modified: trunk/varnish-cache/bin/varnishd/hash_slinger.h =================================================================== --- trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-01-19 09:48:16 UTC (rev 3525) +++ trunk/varnish-cache/bin/varnishd/hash_slinger.h 2009-01-19 11:45:03 UTC (rev 3526) @@ -105,4 +105,6 @@ #define hoh_head u.n.u_n_hoh_head #define hoh_digest u.n.u_n_hoh_digest }; + +extern unsigned save_hash; #endif /* VARNISH_CACHE_CHILD */ Modified: trunk/varnish-cache/bin/varnishd/heritage.h =================================================================== --- trunk/varnish-cache/bin/varnishd/heritage.h 2009-01-19 09:48:16 UTC (rev 3525) +++ trunk/varnish-cache/bin/varnishd/heritage.h 2009-01-19 11:45:03 UTC (rev 3526) @@ -177,6 +177,9 @@ /* Log hash string to shm */ unsigned log_hash; + /* Log hash string to shm */ + unsigned save_hash; + /* Log local socket address to shm */ unsigned log_local_addr; Modified: trunk/varnish-cache/bin/varnishd/mgt_param.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_param.c 2009-01-19 09:48:16 UTC (rev 3525) +++ trunk/varnish-cache/bin/varnishd/mgt_param.c 2009-01-19 11:45:03 UTC (rev 3526) @@ -100,7 +100,8 @@ if (arg != NULL) { u = strtod(arg, NULL); if (u < 0) { - cli_out(cli, "Timeout must be greater or equal to zero\n"); + cli_out(cli, + "Timeout must be greater or equal to zero\n"); cli_result(cli, CLIS_PARAM); return; } @@ -714,6 +715,12 @@ "Log the hash string to shared memory log.\n", 0, "off", "bool" }, + { "purge_hash", tweak_bool, &master.save_hash, 0, 0, + "Enable purge.hash command.\n" + "NB: this increases storage requirement per object " + "by the length of the hash string.\n", + MUST_RESTART, + "off", "bool" }, { "log_local_address", tweak_bool, &master.log_local_addr, 0, 0, "Log the local address on the TCP connection in the " "SessionOpen shared memory record.\n", Modified: trunk/varnish-cache/bin/varnishtest/tests/c00007.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00007.vtc 2009-01-19 09:48:16 UTC (rev 3525) +++ trunk/varnish-cache/bin/varnishtest/tests/c00007.vtc 2009-01-19 11:45:03 UTC (rev 3526) @@ -11,7 +11,11 @@ txresp -body "11111\n" } -start -varnish v1 -vcl+backend { } -start +varnish v1 -arg "-ppurge_hash=off" -vcl+backend { } -start +varnish v1 -clierr 300 "purge.hash foo" +varnish v1 -stop +varnish v1 -cliok "param.set purge_hash on" +varnish v1 -start client c1 { txreq -url "/foo" @@ -22,7 +26,7 @@ client c1 -run -varnish v1 -cli "purge.hash foo" +varnish v1 -cliok "purge.hash foo" client c1 { txreq -url "/foo" Modified: trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-01-19 09:48:16 UTC (rev 3525) +++ trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc 2009-01-19 11:45:03 UTC (rev 3526) @@ -13,7 +13,7 @@ txresp -hdr "foo: 3" -body "foo3" } -start -varnish v1 -vcl+backend {} -start +varnish v1 -arg "-p purge_hash=on" -vcl+backend {} -start varnish v1 -cliok "purge.url FOO" From tfheen at projects.linpro.no Mon Jan 19 12:44:57 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 19 Jan 2009 13:44:57 +0100 (CET) Subject: r3527 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20090119124457.9A90497B55@projects.linpro.no> Author: tfheen Date: 2009-01-19 13:44:57 +0100 (Mon, 19 Jan 2009) New Revision: 3527 Modified: trunk/varnish-cache/bin/varnishd/Makefile.am trunk/varnish-cache/include/Makefile.am Log: Make make dist happier; distribute the files we need Modified: trunk/varnish-cache/bin/varnishd/Makefile.am =================================================================== --- trunk/varnish-cache/bin/varnishd/Makefile.am 2009-01-19 11:45:03 UTC (rev 3526) +++ trunk/varnish-cache/bin/varnishd/Makefile.am 2009-01-19 12:44:57 UTC (rev 3527) @@ -70,7 +70,8 @@ mgt.h \ mgt_cli.h \ steps.h \ - stevedore.h + stevedore.h \ + vparam.h varnishd_CFLAGS = \ -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' Modified: trunk/varnish-cache/include/Makefile.am =================================================================== --- trunk/varnish-cache/include/Makefile.am 2009-01-19 11:45:03 UTC (rev 3526) +++ trunk/varnish-cache/include/Makefile.am 2009-01-19 12:44:57 UTC (rev 3527) @@ -22,9 +22,11 @@ compat/vasprintf.h \ flopen.h \ http_headers.h \ + http_response.h \ libvarnish.h \ libvcl.h \ miniobj.h \ + vsha256.h \ vqueue.h \ vpf.h \ vsb.h \ From tfheen at projects.linpro.no Mon Jan 19 12:52:30 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 19 Jan 2009 13:52:30 +0100 (CET) Subject: r3528 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090119125230.98C2297B55@projects.linpro.no> Author: tfheen Date: 2009-01-19 13:52:30 +0100 (Mon, 19 Jan 2009) New Revision: 3528 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/r00386.vtc Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Merge r3433: When we receive an If-Modified-Since on an ESI object, do not process the conditional for the child object and pretend to send a 304 reply for them, if we have decided to deliver the main object. Fixes #386 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-01-19 12:44:57 UTC (rev 3527) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-01-19 12:52:30 UTC (rev 3528) @@ -837,7 +837,14 @@ sp->director = NULL; sp->step = STP_RECV; http_ForceGet(sp->http); + + /* Don't do conditionals */ + sp->http->conds = 0; + http_Unset(sp->http, H_If_Modified_Since); + + /* Client content already taken care of */ http_Unset(sp->http, H_Content_Length); + while (1) { CNT_Session(sp); if (sp->step == STP_DONE) Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/r00386.vtc (from rev 3433, trunk/varnish-cache/bin/varnishtest/tests/r00386.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/r00386.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/r00386.vtc 2009-01-19 12:52:30 UTC (rev 3528) @@ -0,0 +1,29 @@ +# $Id$ + +test "#386, failure to insert include" + +server s1 { + rxreq + expect req.url == "/body" + txresp -hdr "Last-Modified: Tue, 25 Nov 2008 00:00:00 GMT" -body "BODY" + rxreq + expect req.url == "/" + txresp -body {} +} -start + +varnish v1 -arg "-p diag_bitmap=0x20" -vcl+backend { + sub vcl_fetch { + if (req.url == "/") { + esi; + } + } +} -start + +client c1 { + txreq -url /body + rxresp + expect resp.bodylen == 4 + txreq -url / -hdr "If-Modified-Since: Tue, 25 Nov 2008 00:00:00 GMT" + rxresp + expect resp.bodylen == 11 +} -start From tfheen at projects.linpro.no Mon Jan 19 12:57:25 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 19 Jan 2009 13:57:25 +0100 (CET) Subject: r3529 - branches/2.0/varnish-cache/man Message-ID: <20090119125725.B66C197B55@projects.linpro.no> Author: tfheen Date: 2009-01-19 13:57:25 +0100 (Mon, 19 Jan 2009) New Revision: 3529 Modified: branches/2.0/varnish-cache/man/vcl.7so Log: Merge r3361: Fix up $N vs \N in man page The VCL man page documented the capturing parentheses as using $N rather than \N which is actually used. Fixes #359 Modified: branches/2.0/varnish-cache/man/vcl.7so =================================================================== --- branches/2.0/varnish-cache/man/vcl.7so 2009-01-19 12:52:30 UTC (rev 3528) +++ branches/2.0/varnish-cache/man/vcl.7so 2009-01-19 12:57:25 UTC (rev 3529) @@ -198,11 +198,11 @@ .Fa sub . Within .Fa sub , -.Va $0 +.Va \\0 (which can also be spelled .Va & ) is replaced with the entire matched string, and -.Va $n +.Va \\n is replaced with the contents of subgroup .Ar n in the matched string. From phk at projects.linpro.no Mon Jan 19 12:58:44 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 19 Jan 2009 13:58:44 +0100 (CET) Subject: r3530 - trunk/varnish-cache/bin/varnishd Message-ID: <20090119125844.A8FC397B55@projects.linpro.no> Author: phk Date: 2009-01-19 13:58:44 +0100 (Mon, 19 Jan 2009) New Revision: 3530 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/cache_pipe.c Log: Be much more BOFH about bereq, more asserts, free them where they obviously should be freed. This could fix 421 or make it much worse, but give us more info. Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-01-19 12:57:25 UTC (rev 3529) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-01-19 12:58:44 UTC (rev 3530) @@ -155,6 +155,8 @@ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC); + AZ(sp->bereq); + sp->t_resp = TIM_real(); if (sp->obj->objhead != NULL) { sp->obj->last_use = sp->t_resp; /* XXX: locking ? */ @@ -301,6 +303,7 @@ char date[40]; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + AZ(sp->bereq); /* We always close when we take this path */ sp->doclose = "error"; @@ -663,6 +666,7 @@ sp->step = STP_FETCH; return (0); case VCL_RET_RESTART: + VBE_free_bereq(&sp->bereq); INCOMPL(); default: WRONG("Illegal action in vcl_miss{}"); @@ -713,6 +717,7 @@ VCL_pass_method(sp); if (sp->handling == VCL_RET_ERROR) { + VBE_free_bereq(&sp->bereq); sp->step = STP_ERROR; return (0); } @@ -769,6 +774,7 @@ assert(sp->handling == VCL_RET_PIPE); PipeSession(sp); + AZ(sp->bereq); AZ(sp->wrk->wfd); sp->step = STP_DONE; return (0); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2009-01-19 12:57:25 UTC (rev 3529) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2009-01-19 12:58:44 UTC (rev 3530) @@ -324,6 +324,7 @@ CHECK_OBJ_NOTNULL(sp->bereq, BEREQ_MAGIC); AN(sp->director); AN(sp->obj->busy); + AN(sp->bereq); w = sp->wrk; bereq = sp->bereq; hp = bereq->http; Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2009-01-19 12:57:25 UTC (rev 3529) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2009-01-19 12:58:44 UTC (rev 3530) @@ -634,6 +634,7 @@ struct bereq *bereq; struct http *hp; + AZ(sp->bereq); bereq = VBE_new_bereq(); AN(bereq); hp = bereq->http; Modified: trunk/varnish-cache/bin/varnishd/cache_pipe.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_pipe.c 2009-01-19 12:57:25 UTC (rev 3529) +++ trunk/varnish-cache/bin/varnishd/cache_pipe.c 2009-01-19 12:58:44 UTC (rev 3530) @@ -90,14 +90,15 @@ sp->acct_req.bodybytes += WRW_Write(w, sp->htc->pipeline.b, Tlen(sp->htc->pipeline)); - if (WRW_FlushRelease(w)) { + i = WRW_FlushRelease(w); + VBE_free_bereq(&bereq); + + if (i) { vca_close_session(sp, "pipe"); VBE_ClosedFd(sp); return; } - VBE_free_bereq(&bereq); - sp->t_resp = TIM_real(); memset(fds, 0, sizeof fds); From tfheen at projects.linpro.no Mon Jan 19 13:24:13 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 19 Jan 2009 14:24:13 +0100 (CET) Subject: r3531 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090119132413.9DD8328429@projects.linpro.no> Author: tfheen Date: 2009-01-19 14:24:13 +0100 (Mon, 19 Jan 2009) New Revision: 3531 Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.1 Log: Merge r3362: Document the size parameter to -s malloc Fixes #362 Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/varnishd.1 2009-01-19 12:58:44 UTC (rev 3530) +++ branches/2.0/varnish-cache/bin/varnishd/varnishd.1 2009-01-19 13:24:13 UTC (rev 3531) @@ -236,9 +236,27 @@ .Ss Storage Types The following storage types are available: .Bl -tag -width 4n -.It Cm malloc +.It Cm malloc Ns Op Ns , Ns Ar size Ns Storage for each object is allocated with .Xr malloc 3 . +.Pp +The +.Ar size +parameter specifies the maximum amount of memory varnishd will allocate. +The size is assumed to be in bytes, unless followed by one of the +following suffixes: +.Bl -tag -width indent +.It K, k +The size is expressed in kibibytes. +.It M, m +The size is expressed in mebibytes. +.It G, g +The size is expressed in gibibytes. +.It T, t +The size is expressed in tebibytes. +.El +.Pp +The default size is unlimited. .It Cm file Ns Op Ns , Ns Ar path Ns Op Ns , Ns Ar size Ns Op Ns , Ns Ar granularity Storage for each object is allocated from an arena backed by a file. This is the default. From tfheen at projects.linpro.no Mon Jan 19 13:29:00 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 19 Jan 2009 14:29:00 +0100 (CET) Subject: r3532 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090119132900.181FF28429@projects.linpro.no> Author: tfheen Date: 2009-01-19 14:28:59 +0100 (Mon, 19 Jan 2009) New Revision: 3532 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c Log: Merge r3366: Add a debug CLI command to seed random(3). This is a lot less useful than it could have been, as the Open Group only mandates that: Like rand(), random() shall produce by default a sequence of numbers that can be duplicated by calling srandom() with 1 as the seed. But crucially leaves out *which* sequence of numbers. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-01-19 13:24:13 UTC (rev 3531) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-01-19 13:28:59 UTC (rev 3532) @@ -1064,9 +1064,23 @@ cli_out(cli, "XID is %u", xids); } +static void +cli_debug_srandom(struct cli *cli, const char * const *av, void *priv) +{ + (void)priv; + unsigned long seed; + + if (av[2] != NULL) + seed = strtoul(av[2], NULL, 0); + srandom(seed); + cli_out(cli, "Random(3) seeded with %lu", seed); +} + static struct cli_proto debug_cmds[] = { { "debug.xid", "debug.xid", "\tExamine or set XID\n", 0, 1, cli_debug_xid }, + { "debug.srandom", "debug.srandom", + "\tSeed the random(3) function\n", 0, 1, cli_debug_srandom }, { NULL } }; From tfheen at projects.linpro.no Mon Jan 19 13:45:10 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 19 Jan 2009 14:45:10 +0100 (CET) Subject: r3533 - branches/2.0/varnish-cache/bin/varnishtest Message-ID: <20090119134510.7EE9F28429@projects.linpro.no> Author: tfheen Date: 2009-01-19 14:45:10 +0100 (Mon, 19 Jan 2009) New Revision: 3533 Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc.c Log: Merge r3367: Add a toplevel word which examines the sequence returned by srandom(1) and stops the test if we do not get the same sequence as we expect. The Open Group does not define which deterministic sequence srandom(1) should result in, on that it be deterministic, but I have high hopes in the general sanity and expect that UNIX people across the board have realized that for portability the same sequence should be returned on all platforms. At the very least FreeBSD and Linux/GLIBC, as seen on projects.linpro.no, agree. Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc.c 2009-01-19 13:28:59 UTC (rev 3532) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc.c 2009-01-19 13:45:10 UTC (rev 3533) @@ -44,6 +44,8 @@ const char *vtc_file; char *vtc_desc; +static int stop; + /********************************************************************** * Read a file into memory */ @@ -185,6 +187,8 @@ assert(cp->cmd != NULL); cp->cmd(token_s, priv, cmd, vl); + if (stop) + break; } } @@ -282,6 +286,52 @@ } /********************************************************************** + * Check random generator + */ + +#define NRNDEXPECT 12 +static const unsigned long random_expect[NRNDEXPECT] = { + 1804289383, 846930886, 1681692777, 1714636915, + 1957747793, 424238335, 719885386, 1649760492, + 596516649, 1189641421, 1025202362, 1350490027 +}; + +#define RND_NEXT_1K 0x3bdcbe30 + +static void +cmd_random(CMD_ARGS) +{ + unsigned long l; + int i; + + (void)cmd; + (void)priv; + if (av == NULL) + return; + srandom(1); + for (i = 0; i < NRNDEXPECT; i++) { + l = random(); + if (l == random_expect[i]) + continue; + vtc_log(vl, 4, "random[%d] = 0x%x (expect 0x%x)", + i, l, random_expect[i]); + vtc_log(vl, 1, "SKIPPING test: unknown srandom(1) sequence."); + stop = 1; + break; + } + l = 0; + for (i = 0; i < 1000; i++) + l += random(); + if (l != RND_NEXT_1K) { + vtc_log(vl, 4, "sum(random[%d...%d]) = 0x%x (expect 0x%x)", + NRNDEXPECT, NRNDEXPECT + 1000, + l, RND_NEXT_1K); + vtc_log(vl, 1, "SKIPPING test: unknown srandom(1) sequence."); + stop = 1; + } +} + +/********************************************************************** * Execute a file */ @@ -293,6 +343,7 @@ { "test", cmd_test }, { "shell", cmd_shell }, { "sema", cmd_sema }, + { "random", cmd_random }, { NULL, NULL } }; @@ -301,6 +352,7 @@ { char *buf; + stop = 0; vtc_file = fn; vtc_desc = NULL; vtc_log(vl, 1, "TEST %s starting", fn); From phk at projects.linpro.no Mon Jan 19 13:46:31 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Mon, 19 Jan 2009 14:46:31 +0100 (CET) Subject: r3534 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl Message-ID: <20090119134631.CDB0728429@projects.linpro.no> Author: phk Date: 2009-01-19 14:46:31 +0100 (Mon, 19 Jan 2009) New Revision: 3534 Added: trunk/varnish-cache/bin/varnishtest/tests/b00028.vtc Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl trunk/varnish-cache/lib/libvcl/vcc_parse.c trunk/varnish-cache/lib/libvcl/vcc_token_defs.h Log: Add "no match" operator !~ to VCL regexps Added: trunk/varnish-cache/bin/varnishtest/tests/b00028.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/b00028.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/b00028.vtc 2009-01-19 13:46:31 UTC (rev 3534) @@ -0,0 +1,28 @@ +# $Id$ + +test "regexp match and no-match" + +server s1 { + rxreq + txresp -hdr "Foo: bar" -hdr "Bar: foo" -body "1111\n" +} -start + +varnish v1 -vcl+backend { + + sub vcl_fetch { + if (obj.http.foo ~ "bar") { + set obj.http.foo1 = "1"; + } + if (obj.http.bar !~ "bar") { + set obj.http.bar1 = "1"; + } + } + +} -start + +client c1 { + txreq + rxresp + expect resp.http.foo1 == "1" + expect resp.http.bar1 == "1" +} -run Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-01-19 13:45:10 UTC (rev 3533) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-01-19 13:46:31 UTC (rev 3534) @@ -22,6 +22,7 @@ switch (p[0]) { case '!': + M2('~', T_NOMATCH); M2('=', T_NEQ); M1(); case '%': @@ -146,6 +147,7 @@ [T_LEQ] = "<=", [T_MUL] = "*=", [T_NEQ] = "!=", + [T_NOMATCH] = "!~", [T_SHL] = "<<", [T_SHR] = ">>", [VAR] = "VAR", Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-01-19 13:45:10 UTC (rev 3533) +++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl 2009-01-19 13:46:31 UTC (rev 3534) @@ -88,6 +88,7 @@ {"-=" DECR} {"*=" MUL} {"/=" DIV} + {"!~" NOMATCH} } # Single char tokens Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_parse.c 2009-01-19 13:45:10 UTC (rev 3533) +++ trunk/varnish-cache/lib/libvcl/vcc_parse.c 2009-01-19 13:46:31 UTC (rev 3534) @@ -248,12 +248,15 @@ switch (tl->t->tok) { case '~': + case T_NOMATCH: + Fb(tl, 1, "%sVRT_re_match(", + tl->t->tok == '~' ? "" : "!"); vcc_NextToken(tl); ExpectErr(tl, CSTR); p = vcc_regexp(tl, 0); ERRCHK(tl); vcc_NextToken(tl); - Fb(tl, 1, "VRT_re_match(%s, %s)\n", vp->rname, p); + Fb(tl, 1, "%s, %s)\n", vp->rname, p); break; case T_EQ: case T_NEQ: Modified: trunk/varnish-cache/lib/libvcl/vcc_token_defs.h =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_token_defs.h 2009-01-19 13:45:10 UTC (rev 3533) +++ trunk/varnish-cache/lib/libvcl/vcc_token_defs.h 2009-01-19 13:46:31 UTC (rev 3534) @@ -26,9 +26,10 @@ #define T_DECR 144 #define T_MUL 145 #define T_DIV 146 -#define ID 147 -#define VAR 148 -#define CNUM 149 -#define CSTR 150 -#define EOI 151 -#define CSRC 152 +#define T_NOMATCH 147 +#define ID 148 +#define VAR 149 +#define CNUM 150 +#define CSTR 151 +#define EOI 152 +#define CSRC 153 From tfheen at projects.linpro.no Mon Jan 19 14:24:04 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 19 Jan 2009 15:24:04 +0100 (CET) Subject: r3535 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090119142404.013B597B55@projects.linpro.no> Author: tfheen Date: 2009-01-19 15:24:03 +0100 (Mon, 19 Jan 2009) New Revision: 3535 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/v00022.vtc Log: Merge r3368: Add a test of the random director that uses actual randomness. This will be skipped on platforms where srandom(1) does not result in the same deterministic sequence of random numbers as on FreeBSD and Linux. Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/v00022.vtc (from rev 3368, trunk/varnish-cache/bin/varnishtest/tests/v00022.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/v00022.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/v00022.vtc 2009-01-19 14:24:03 UTC (rev 3535) @@ -0,0 +1,86 @@ +# $Id$ + +test "Deeper test of random director" + +random + +server s1 { + rxreq + txresp -body "1" +} -start +server s2 -listen 127.0.0.1:9180 { + rxreq + txresp -body "22" + rxreq + txresp -body "22" + rxreq + txresp -body "22" +} -start +server s3 -listen 127.0.0.1:9181 { + rxreq + txresp -body "333" +} -start +server s4 -listen 127.0.0.1:9182 { + rxreq + txresp -body "4444" + rxreq + txresp -body "4444" + rxreq + txresp -body "4444" + rxreq + txresp -body "4444" + rxreq + txresp -body "4444" +} -start + +varnish v1 -vcl+backend { + director foo random { + { .backend = s1; .weight = 1; } + { .backend = s2; .weight = 1; } + { .backend = s3; .weight = 1; } + { .backend = s4; .weight = 1; } + } + + sub vcl_recv { + set req.backend = foo; + pass; + } +} -start + +# NB: Do not change the number 1 +# NB: Only srandom(1) is standardized as deterministic. + +varnish v1 -cliok "debug.srandom 1" + +client c1 { + txreq + rxresp + expect resp.bodylen == 4 + txreq + rxresp + expect resp.bodylen == 2 + txreq + rxresp + expect resp.bodylen == 4 + txreq + rxresp + expect resp.bodylen == 4 + txreq + rxresp + expect resp.bodylen == 4 + txreq + rxresp + expect resp.bodylen == 1 + txreq + rxresp + expect resp.bodylen == 2 + txreq + rxresp + expect resp.bodylen == 4 + txreq + rxresp + expect resp.bodylen == 2 + txreq + rxresp + expect resp.bodylen == 3 +} -run From tfheen at projects.linpro.no Mon Jan 19 14:28:09 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Mon, 19 Jan 2009 15:28:09 +0100 (CET) Subject: r3536 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090119142809.EA4F697B55@projects.linpro.no> Author: tfheen Date: 2009-01-19 15:28:07 +0100 (Mon, 19 Jan 2009) New Revision: 3536 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c Log: Merge r3386: Implement restart in vcl_hit. Fixes #365 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-01-19 14:24:03 UTC (rev 3535) +++ branches/2.0/varnish-cache/bin/varnishd/cache_center.c 2009-01-19 14:28:07 UTC (rev 3536) @@ -548,7 +548,9 @@ sp->step = STP_ERROR; return (0); case VCL_RET_RESTART: - INCOMPL(); + sp->director = NULL; + sp->restarts++; + sp->step = STP_RECV; return (0); default: WRONG("Illegal action in vcl_hit{}"); From phk at projects.linpro.no Wed Jan 21 23:00:43 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 22 Jan 2009 00:00:43 +0100 (CET) Subject: r3537 - in trunk/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090121230043.8CA4197B4A@projects.linpro.no> Author: phk Date: 2009-01-22 00:00:43 +0100 (Thu, 22 Jan 2009) New Revision: 3537 Added: trunk/varnish-cache/bin/varnishtest/tests/r00425.vtc Modified: trunk/varnish-cache/bin/varnishd/cache_center.c Log: Enforce a minimum ttl for "hit for pass" objects to prevent a value of zero from serializing access to an object with very draconian backend cache-control headers. We could get far even with a one second TTL, but following our general "there is a reason people put Varnish there in the first place" logic we use the default_ttl parameter (default: 120 s) for this value. If another value is desired, this can be set in vcl_fetch, even if it looks somewhat counter-intuitive: sub vcl_fetch { if (obj.http.set-cookie) { set obj.ttl = 10s; pass; } } Fixes #425 Modified: trunk/varnish-cache/bin/varnishd/cache_center.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_center.c 2009-01-19 14:28:07 UTC (rev 3536) +++ trunk/varnish-cache/bin/varnishd/cache_center.c 2009-01-21 23:00:43 UTC (rev 3537) @@ -413,6 +413,8 @@ return (0); case VCL_RET_PASS: sp->obj->pass = 1; + if (sp->obj->ttl - sp->t_req < params->default_ttl) + sp->obj->ttl = sp->t_req + params->default_ttl; break; case VCL_RET_DELIVER: break; Added: trunk/varnish-cache/bin/varnishtest/tests/r00425.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/r00425.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/r00425.vtc 2009-01-21 23:00:43 UTC (rev 3537) @@ -0,0 +1,34 @@ +# $Id$ + +test "check late pass stalling" + +server s1 { + rxreq + txresp \ + -hdr "Set-Cookie: foo=bar" \ + -hdr "Expires: Thu, 19 Nov 1981 08:52:00 GMT" \ + -body "1111\n" + rxreq + txresp \ + -hdr "Set-Cookie: foo=bar" \ + -hdr "Expires: Thu, 19 Nov 1981 08:52:00 GMT" \ + -body "22222n" + rxreq + txresp \ + -hdr "Set-Cookie: foo=bar" \ + -hdr "Expires: Thu, 19 Nov 1981 08:52:00 GMT" \ + -body "33333n" +} -start + +varnish v1 -vcl+backend { } -start + +client c1 { + txreq + rxresp + txreq + rxresp + txreq + rxresp +} -run + +varnish v1 -expect cache_hitpass == 2 From phk at projects.linpro.no Thu Jan 22 10:42:58 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Thu, 22 Jan 2009 11:42:58 +0100 (CET) Subject: r3538 - in trunk/varnish-cache: bin/varnishd include Message-ID: <20090122104258.F28E71F746A@projects.linpro.no> Author: phk Date: 2009-01-22 11:42:58 +0100 (Thu, 22 Jan 2009) New Revision: 3538 Added: trunk/varnish-cache/include/purge_vars.h Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c Log: Move the purgable variables into a CPP table, so we can share them with the VCL compiler Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-21 23:00:43 UTC (rev 3537) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-22 10:42:58 UTC (rev 3538) @@ -297,11 +297,23 @@ bt->src[l + 2] = '\0'; } +static const struct pvar { + const char *name; + unsigned flag; + ban_cond_f *func; +} pvars[] = { +#define PVAR(a, b, c) { a, b, c }, +#include "purge_vars.h" +#undef PVAR + { 0, 0, 0} +}; + static int ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) { struct ban_test *bt; struct vsb *sb; + const struct pvar *pv; int i; CHECK_OBJ_NOTNULL(b, BAN_MAGIC); @@ -336,17 +348,15 @@ } - if (!strcmp(a1, "req.url")) - bt->func = ban_cond_url; - else if (!strcmp(a1, "obj.hash")) - bt->func = ban_cond_hash; - else if (!strncmp(a1, "req.http.", 9)) { - bt->func = ban_cond_req_http; - ban_parse_http(bt, a1 + 9); - } else if (!strncmp(a1, "obj.http.", 9)) { - bt->func = ban_cond_obj_http; - ban_parse_http(bt, a1 + 9); - } else { + for (pv = pvars; pv->name != NULL; pv++) { + if (strncmp(a1, pv->name, strlen(pv->name))) + continue; + bt->func = pv->func; + if (pv->flag & 1) + ban_parse_http(bt, a1 + strlen(pv->name)); + break; + } + if (pv->name == NULL) { cli_out(cli, "unknown or unsupported field \"%s\"", a1); cli_result(cli, CLIS_PARAM); return (-1); Added: trunk/varnish-cache/include/purge_vars.h =================================================================== --- trunk/varnish-cache/include/purge_vars.h (rev 0) +++ trunk/varnish-cache/include/purge_vars.h 2009-01-22 10:42:58 UTC (rev 3538) @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2008 Linpro 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. + * + * $Id$ + * + * Define which variables we can purge on, and which function does it. + */ + +PVAR("req.url", 0, ban_cond_url) +PVAR("obj.hash", 0, ban_cond_hash) +PVAR("req.http.", 1, ban_cond_req_http) +PVAR("obj.http.", 1, ban_cond_obj_http) From ingvar at projects.linpro.no Thu Jan 22 13:07:21 2009 From: ingvar at projects.linpro.no (ingvar at projects.linpro.no) Date: Thu, 22 Jan 2009 14:07:21 +0100 (CET) Subject: r3539 - trunk/varnish-cache/redhat Message-ID: <20090122130721.33BE11F746A@projects.linpro.no> Author: ingvar Date: 2009-01-22 14:07:20 +0100 (Thu, 22 Jan 2009) New Revision: 3539 Modified: trunk/varnish-cache/redhat/varnish.spec Log: Don't need debug patch outside fedora package Modified: trunk/varnish-cache/redhat/varnish.spec =================================================================== --- trunk/varnish-cache/redhat/varnish.spec 2009-01-22 10:42:58 UTC (rev 3538) +++ trunk/varnish-cache/redhat/varnish.spec 2009-01-22 13:07:20 UTC (rev 3539) @@ -6,7 +6,7 @@ Group: System Environment/Daemons URL: http://www.varnish-cache.org/ Source0: http://downloads.sourceforge.net/varnish/varnish-%{version}.tar.gz -Patch0: varnish.varnishtest_debugflag.patch +#Patch0: varnish.varnishtest_debugflag.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) # The svn sources needs autoconf, automake and libtool to generate a suitable # configure script. Release tarballs would not need this @@ -64,7 +64,7 @@ %setup -q #%setup -q -n varnish-cache -%patch0 -p0 +#%patch0 -p0 # The svn sources needs to generate a suitable configure script # Release tarballs would not need this From phk at projects.linpro.no Fri Jan 23 13:22:44 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 23 Jan 2009 14:22:44 +0100 (CET) Subject: r3540 - trunk/varnish-cache/bin/varnishtest Message-ID: <20090123132244.3C51E117903@projects.linpro.no> Author: phk Date: 2009-01-23 14:22:43 +0100 (Fri, 23 Jan 2009) New Revision: 3540 Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c Log: Don't append a CRNL to the body. And add separate rxhdrs and rxbody primitives. Submitted by: Yonatan Broza & Dmitry Rubinstein Modified: trunk/varnish-cache/bin/varnishtest/vtc_http.c =================================================================== --- trunk/varnish-cache/bin/varnishtest/vtc_http.c 2009-01-22 13:07:20 UTC (rev 3539) +++ trunk/varnish-cache/bin/varnishtest/vtc_http.c 2009-01-23 13:22:43 UTC (rev 3540) @@ -531,10 +531,8 @@ if (body != NULL) vsb_printf(hp->vsb, "Content-Length: %d%s", strlen(body), nl); vsb_cat(hp->vsb, nl); - if (body != NULL) { + if (body != NULL) vsb_cat(hp->vsb, body); - vsb_cat(hp->vsb, nl); - } http_write(hp, 4, "txresp"); } @@ -565,6 +563,48 @@ vtc_log(hp->vl, 4, "bodylen = %s", hp->bodylen); } +static void +cmd_http_rxhdrs(CMD_ARGS) +{ + struct http *hp; + + (void)cmd; + (void)vl; + CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); + AZ(hp->client); + assert(!strcmp(av[0], "rxhdrs")); + av++; + + for(; *av != NULL; av++) { + fprintf(stderr, "Unknown http rxreq spec: %s\n", *av); + exit (1); + } + vtc_log(hp->vl, 3, "rxhdrs"); + http_rxhdr(hp); + http_splitheader(hp, 1); +} + +static void +cmd_http_rxbody(CMD_ARGS) +{ + struct http *hp; + + (void)cmd; + (void)vl; + CAST_OBJ_NOTNULL(hp, priv, HTTP_MAGIC); + AZ(hp->client); + assert(!strcmp(av[0], "rxbody")); + av++; + + for(; *av != NULL; av++) { + fprintf(stderr, "Unknown http rxreq spec: %s\n", *av); + exit (1); + } + vtc_log(hp->vl, 3, "rxbody"); + http_swallow_body(hp, hp->req, 0); + vtc_log(hp->vl, 4, "bodylen = %s", hp->bodylen); +} + /********************************************************************** * Transmit a request */ @@ -698,7 +738,11 @@ static struct cmds http_cmds[] = { { "timeout", cmd_http_timeout }, { "txreq", cmd_http_txreq }, + { "rxreq", cmd_http_rxreq }, + { "rxhdrs", cmd_http_rxhdrs }, + { "rxbody", cmd_http_rxbody }, + { "txresp", cmd_http_txresp }, { "rxresp", cmd_http_rxresp }, { "expect", cmd_http_expect }, From phk at projects.linpro.no Fri Jan 23 21:17:03 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Fri, 23 Jan 2009 22:17:03 +0100 (CET) Subject: r3541 - in trunk/varnish-cache: bin/varnishd include lib/libvcl Message-ID: <20090123211703.1FC4728461@projects.linpro.no> Author: phk Date: 2009-01-23 22:17:02 +0100 (Fri, 23 Jan 2009) New Revision: 3541 Modified: trunk/varnish-cache/bin/varnishd/cache.h trunk/varnish-cache/bin/varnishd/cache_ban.c trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: First cut at VCL support for new-purge. Modified: trunk/varnish-cache/bin/varnishd/cache.h =================================================================== --- trunk/varnish-cache/bin/varnishd/cache.h 2009-01-23 13:22:43 UTC (rev 3540) +++ trunk/varnish-cache/bin/varnishd/cache.h 2009-01-23 21:17:02 UTC (rev 3541) @@ -417,7 +417,10 @@ void VBP_Init(void); /* cache_ban.c */ -int BAN_Add(struct cli *cli, const char *regexp, int hash); +struct ban *BAN_New(void); +int BAN_AddTest(struct cli *, struct ban *, const char *, const char *, const char *); +void BAN_Free(struct ban *b); +void BAN_Insert(struct ban *b); void BAN_Init(void); void BAN_NewObj(struct object *o); void BAN_DestroyObj(struct object *o); Modified: trunk/varnish-cache/bin/varnishd/cache_ban.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-23 13:22:43 UTC (rev 3540) +++ trunk/varnish-cache/bin/varnishd/cache_ban.c 2009-01-23 21:17:02 UTC (rev 3541) @@ -95,8 +95,8 @@ * Manipulation of bans */ -static struct ban * -ban_new_ban(void) +struct ban * +BAN_New(void) { struct ban *b; ALLOC_OBJ(b, BAN_MAGIC); @@ -140,8 +140,8 @@ } while (i); } -static void -ban_free_ban(struct ban *b) +void +BAN_Free(struct ban *b) { struct ban_test *bt; @@ -308,8 +308,8 @@ { 0, 0, 0} }; -static int -ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) +int +BAN_AddTest(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3) { struct ban_test *bt; struct vsb *sb; @@ -387,7 +387,7 @@ */ static struct ban * volatile ban_start; -static void +void BAN_Insert(struct ban *b) { struct ban *bi, *be; @@ -476,7 +476,7 @@ b = BAN_CheckLast(); Lck_Unlock(&ban_mtx); if (b != NULL) - ban_free_ban(b); + BAN_Free(b); } @@ -564,38 +564,20 @@ } } - b = ban_new_ban(); + b = BAN_New(); if (b == NULL) { cli_out(cli, "Out of Memory"); cli_result(cli, CLIS_CANT); return; } for (i = 0; i < narg; i += 4) - if (ban_parse_test(cli, b, av[i + 2], av[i + 3], av[i + 4])) { - ban_free_ban(b); + if (BAN_AddTest(cli, b, av[i + 2], av[i + 3], av[i + 4])) { + BAN_Free(b); return; } BAN_Insert(b); } -int -BAN_Add(struct cli *cli, const char *regexp, int hash) -{ - const char *aav[6]; - - aav[0] = NULL; - aav[1] = "purge"; - if (hash) - aav[2] = "obj.hash"; - else - aav[2] = "req.url"; - aav[3] = "~"; - aav[4] = regexp; - aav[5] = NULL; - ccf_purge(cli, aav, NULL); - return (0); -} - static void ccf_purge_url(struct cli *cli, const char * const *av, void *priv) { @@ -651,7 +633,7 @@ VTAILQ_LAST(&ban_head, banhead)->refcount++; Lck_Unlock(&ban_mtx); if (b != NULL) - ban_free_ban(b); + BAN_Free(b); } while (b != NULL); VTAILQ_FOREACH(b, &ban_head, list) { @@ -692,9 +674,17 @@ void BAN_Init(void) { + const char *aav[6]; Lck_New(&ban_mtx); CLI_AddFuncs(PUBLIC_CLI, ban_cmds); + /* Add an initial ban, since the list can never be empty */ - (void)BAN_Add(NULL, ".", 0); + aav[0] = NULL; + aav[1] = "purge"; + aav[2] = "req.url"; + aav[3] = "~"; + aav[4] = "."; + aav[5] = NULL; + ccf_purge(NULL, aav, NULL); } Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-01-23 13:22:43 UTC (rev 3540) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-01-23 21:17:02 UTC (rev 3541) @@ -762,11 +762,35 @@ /*--------------------------------------------------------------------*/ void -VRT_purge(const char *regexp, int hash) +VRT_purge(struct sess *sp, char *cmds, ...) { + char *a1, *a2, *a3; + va_list ap; + struct ban *b; + int good; - if (regexp != NULL) - (void)BAN_Add(NULL, regexp, hash); + (void)sp; + b = BAN_New(); + va_start(ap, cmds); + a1 = cmds; + good = 0; + while (a1 != NULL) { + good = 0; + a2 = va_arg(ap, char *); + if (a2 == NULL) + break; + a3 = va_arg(ap, char *); + if (a3 == NULL) + break; + if (BAN_AddTest(NULL, b, a1, a2, a3)) + break; + a1 = va_arg(ap, char *); + good = 1; + } + if (!good) + BAN_Free(b); + else + BAN_Insert(b); } /*-------------------------------------------------------------------- Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2009-01-23 13:22:43 UTC (rev 3540) +++ trunk/varnish-cache/include/vrt.h 2009-01-23 21:17:02 UTC (rev 3541) @@ -141,8 +141,8 @@ const char *VRT_regsub(const struct sess *sp, int all, const char *, void *, const char *); -void VRT_panic(struct sess *sp, const char *, ...); -void VRT_purge(const char *, int hash); +void VRT_panic(struct sess *sp, const char *, ...); +void VRT_purge(struct sess *sp, char *, ...); void VRT_count(const struct sess *, unsigned); int VRT_rewrite(const char *, const char *); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2009-01-23 13:22:43 UTC (rev 3540) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2009-01-23 21:17:02 UTC (rev 3541) @@ -348,27 +348,86 @@ /*--------------------------------------------------------------------*/ static void -parse_purge_url(struct tokenlist *tl) +parse_purge(struct tokenlist *tl) { vcc_NextToken(tl); - Fb(tl, 1, "VRT_purge("); Expect(tl, '('); vcc_NextToken(tl); + if (tl->t->tok == VAR) { + Fb(tl, 1, "VRT_purge(sp,\n"); + tl->indent += INDENT; + while (1) { + ExpectErr(tl, VAR); + Fb(tl, 1, " \"%.*s\",\n", PF(tl->t)); + vcc_NextToken(tl); + switch(tl->t->tok) { + case '~': + case T_NOMATCH: + case T_EQ: + case T_NEQ: + Fb(tl, 1, " \"%.*s\",\n", PF(tl->t)); + break; + default: + vsb_printf(tl->sb, + "Expected ~, !~, == or !=.\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + vcc_NextToken(tl); + Fb(tl, 1, " "); + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return; + } + Fb(tl, 0, ",\n"); + if (tl->t->tok == ')') + break; + ExpectErr(tl, T_CAND); + Fb(tl, 1, "\"%.*s\",\n", PF(tl->t)); + vcc_NextToken(tl); + } + Fb(tl, 1, "0);\n"); + tl->indent -= INDENT; + } else { + Fb(tl, 1, "VRT_purge_string(sp, "); + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + return; + } + do + Fb(tl, 0, ", "); + while (vcc_StringVal(tl)); + Fb(tl, 0, ", 0);\n"); + } + + Expect(tl, ')'); + vcc_NextToken(tl); +} + +/*--------------------------------------------------------------------*/ + +static void +parse_purge_url(struct tokenlist *tl) +{ + + vcc_NextToken(tl); + Expect(tl, '('); + vcc_NextToken(tl); + + Fb(tl, 1, "VRT_purge(sp, \"req.url\", \"~\", "); if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return; } - Expect(tl, ')'); vcc_NextToken(tl); Fb(tl, 0, ", 0);\n"); } - /*--------------------------------------------------------------------*/ static void @@ -376,22 +435,21 @@ { vcc_NextToken(tl); - - Fb(tl, 1, "VRT_purge("); - Expect(tl, '('); vcc_NextToken(tl); + Fb(tl, 1, "VRT_purge(sp, \"obj.hash\", \"~\", "); if (!vcc_StringVal(tl)) { vcc_ExpectedStringval(tl); return; } - Expect(tl, ')'); vcc_NextToken(tl); - Fb(tl, 0, ", 1);\n"); + Fb(tl, 0, ", 0);\n"); } +/*--------------------------------------------------------------------*/ + static void parse_esi(struct tokenlist *tl) { @@ -470,6 +528,7 @@ { "call", parse_call }, { "esi", parse_esi }, { "panic", parse_panic }, + { "purge", parse_purge }, { "purge_hash", parse_purge_hash }, { "purge_url", parse_purge_url }, { "remove", parse_unset }, /* backward compatibility */ Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-01-23 13:22:43 UTC (rev 3540) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-01-23 21:17:02 UTC (rev 3541) @@ -159,8 +159,8 @@ /* ../../include/vcl.h */ - vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3484 2008-12-21 17"); - vsb_cat(sb, ":01:58Z phk $\n *\n * NB: This file is machine genera"); + vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3534 2009-01-19 13"); + vsb_cat(sb, ":46:31Z phk $\n *\n * NB: This file is machine genera"); vsb_cat(sb, "ted, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixed_t"); vsb_cat(sb, "oken.tcl instead\n */\n\nstruct sess;\n"); vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n"); @@ -287,8 +287,8 @@ vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n"); vsb_cat(sb, "const char *VRT_regsub(const struct sess *sp, int all,"); vsb_cat(sb, " const char *,\n void *, const char *);\n"); - vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);"); - vsb_cat(sb, "\nvoid VRT_purge(const char *, int hash);\n"); + vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);\n"); + vsb_cat(sb, "void VRT_purge(struct sess *sp, char *, ...);\n"); vsb_cat(sb, "\nvoid VRT_count(const struct sess *, unsigned);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);"); From phk at projects.linpro.no Sat Jan 24 10:36:46 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 24 Jan 2009 11:36:46 +0100 (CET) Subject: r3542 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl Message-ID: <20090124103646.87AE32842E@projects.linpro.no> Author: phk Date: 2009-01-24 11:36:46 +0100 (Sat, 24 Jan 2009) New Revision: 3542 Added: trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c trunk/varnish-cache/include/vrt.h trunk/varnish-cache/lib/libvcl/vcc_action.c trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c Log: Implement the new-purge case where the entire expression comes from VCL. It is possible to instigate purges two ways from VCL now: sub vcl_recv { # Purge the req.url if (req.request == "PURGE") { purge (req.url == req.url); error 410; } # Take entire purge instruction from "Purge:" header if (req.request == "PURGESTR") { purge ("" req.http.purge); error 410; } Testcase for this. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-01-23 21:17:02 UTC (rev 3541) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-01-24 10:36:46 UTC (rev 3542) @@ -788,11 +788,61 @@ good = 1; } if (!good) + /* XXX: report error how ? */ BAN_Free(b); else BAN_Insert(b); } +/*--------------------------------------------------------------------*/ + +void +VRT_purge_string(struct sess *sp, char *str, ...) +{ + char *p, *a1, *a2, *a3; + char **av; + va_list ap; + struct ban *b; + int good; + int i; + + va_start(ap, str); + p = vrt_assemble_string(sp->http, NULL, str, ap); + if (p == NULL) + /* XXX: report error how ? */ + return; + + av = ParseArgv(p, 0); + if (av[0] != NULL) { + /* XXX: report error how ? */ + FreeArgv(av); + return; + } + b = BAN_New(); + good = 0; + for (i = 1; ; i += 3) { + a1 = av[i]; + if (a1 == NULL) + break; + good = 0; + a2 = av[i + 1]; + if (a2 == NULL) + break; + a3 = av[i + 2]; + if (a3 == NULL) + break; + if (BAN_AddTest(NULL, b, a1, a2, a3)) + break; + good = 1; + } + if (!good) + /* XXX: report error how ? */ + BAN_Free(b); + else + BAN_Insert(b); + FreeArgv(av); +} + /*-------------------------------------------------------------------- * Simple stuff */ Added: trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc 2009-01-24 10:36:46 UTC (rev 3542) @@ -0,0 +1,162 @@ +# $Id$ + +test "Test banning a url with VCL purge" + +server s1 { + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar5" -body "1111\n" + + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar6" -body "11111\n" + + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar7" -body "111111\n" + + rxreq + expect req.url == "/foo" + txresp -hdr "foo: bar8" -body "1111111\n" +} -start + +varnish v1 -vcl+backend { + sub vcl_recv { + if (req.request == "PURGE") { + purge (req.url == req.url); + error 410; + } + if (req.request == "PURGESTR") { + purge ("" req.http.purge); + error 410; + } + } +} -start + +# Fetch into cache +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar5 + expect resp.bodylen == 5 +} -run + +# Purge something else +client c1 { + txreq -req PURGE -url /foox + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +# Still in cache +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar5 + expect resp.bodylen == 5 +} -run + +# Purge it +client c1 { + txreq -req PURGE -url /foo + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +# New obj +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar6 + expect resp.bodylen == 6 +} -run + +# Purge everything else +client c1 { + txreq -req PURGESTR -hdr "purge=req.url != /foo" + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +# still there +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar6 + expect resp.bodylen == 6 +} -run + +# Purge it +client c1 { + txreq -req PURGESTR -hdr "Purge: obj.http.foo == \"bar6\"" + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +# New one +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar7 + expect resp.bodylen == 7 +} -run + +# Purge something else +client c1 { + txreq -req PURGESTR -hdr "Purge: obj.http.foo == \"bar6\"" + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +# Still there +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar7 + expect resp.bodylen == 7 +} -run + +# Header match +client c1 { + txreq -req PURGESTR -hdr "Purge: req.http.foo == \"barcheck\"" + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" -hdr "foo: barcheck" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar8 + expect resp.bodylen == 8 +} -run + +# Header match +client c1 { + txreq -req PURGESTR -hdr "Purge: obj.http.foo == \"barcheck\"" + rxresp + expect resp.status == 410 +} -run +varnish v1 -cliok "purge.list" + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.http.foo == bar8 + expect resp.bodylen == 8 +} -run + + Modified: trunk/varnish-cache/include/vrt.h =================================================================== --- trunk/varnish-cache/include/vrt.h 2009-01-23 21:17:02 UTC (rev 3541) +++ trunk/varnish-cache/include/vrt.h 2009-01-24 10:36:46 UTC (rev 3542) @@ -143,6 +143,7 @@ void VRT_panic(struct sess *sp, const char *, ...); void VRT_purge(struct sess *sp, char *, ...); +void VRT_purge_string(struct sess *sp, char *, ...); void VRT_count(const struct sess *, unsigned); int VRT_rewrite(const char *, const char *); Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2009-01-23 21:17:02 UTC (rev 3541) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2009-01-24 10:36:46 UTC (rev 3542) @@ -401,7 +401,7 @@ do Fb(tl, 0, ", "); while (vcc_StringVal(tl)); - Fb(tl, 0, ", 0);\n"); + Fb(tl, 0, "vrt_magic_string_end);\n"); } Expect(tl, ')'); Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-01-23 21:17:02 UTC (rev 3541) +++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-01-24 10:36:46 UTC (rev 3542) @@ -235,10 +235,10 @@ vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI"); vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT"); vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n"); - vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3406 2008-11-19 14:"); - vsb_cat(sb, "13:57Z petter $\n *\n * Runtime support for compiled V"); - vsb_cat(sb, "CL programs.\n *\n * XXX: When this file is changed, l"); - vsb_cat(sb, "ib/libvcl/vcc_gen_fixed_token.tcl\n"); + vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3541 2009-01-23 21:"); + vsb_cat(sb, "17:02Z phk $\n *\n * Runtime support for compiled VCL "); + vsb_cat(sb, "programs.\n *\n * XXX: When this file is changed, lib/"); + vsb_cat(sb, "libvcl/vcc_gen_fixed_token.tcl\n"); vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n"); vsb_cat(sb, "\nstruct sess;\nstruct vsb;\nstruct cli;\n"); vsb_cat(sb, "struct director;\nstruct VCL_conf;\n"); @@ -289,6 +289,7 @@ vsb_cat(sb, " const char *,\n void *, const char *);\n"); vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);\n"); vsb_cat(sb, "void VRT_purge(struct sess *sp, char *, ...);\n"); + vsb_cat(sb, "void VRT_purge_string(struct sess *sp, char *, ...);\n"); vsb_cat(sb, "\nvoid VRT_count(const struct sess *, unsigned);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);"); From phk at projects.linpro.no Sat Jan 24 12:56:27 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Sat, 24 Jan 2009 13:56:27 +0100 (CET) Subject: r3543 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl Message-ID: <20090124125627.833B197B41@projects.linpro.no> Author: phk Date: 2009-01-24 13:56:27 +0100 (Sat, 24 Jan 2009) New Revision: 3543 Modified: trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc trunk/varnish-cache/lib/libvcl/vcc_action.c Log: Test that we know the purge variable when it is compiled in. Modified: trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc 2009-01-24 10:36:46 UTC (rev 3542) +++ trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc 2009-01-24 12:56:27 UTC (rev 3543) @@ -33,6 +33,26 @@ } } -start +# Trigger syntax check +varnish v1 -badvcl { + backend foo { + .host = "127.0.0.1"; + } + sub vcl_recv { + purge (req.foo == req.url); + } +} + +# Trigger syntax check +varnish v1 -badvcl { + backend foo { + .host = "127.0.0.1"; + } + sub vcl_recv { + purge (req.http. == req.url); + } +} + # Fetch into cache client c1 { txreq -url "/foo" Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_action.c 2009-01-24 10:36:46 UTC (rev 3542) +++ trunk/varnish-cache/lib/libvcl/vcc_action.c 2009-01-24 12:56:27 UTC (rev 3543) @@ -32,6 +32,7 @@ #include "config.h" #include +#include #include "vsb.h" @@ -347,13 +348,23 @@ /*--------------------------------------------------------------------*/ +static const struct purge_var { + const char *name; + unsigned flag; +} purge_var[] = { +#define PVAR(a, b, c) { a, b }, +#include "purge_vars.h" +#undef PVAR + { 0, 0 } +}; + static void parse_purge(struct tokenlist *tl) { + const struct purge_var *pv; vcc_NextToken(tl); - Expect(tl, '('); vcc_NextToken(tl); @@ -362,6 +373,25 @@ tl->indent += INDENT; while (1) { ExpectErr(tl, VAR); + + /* Check valididity of purge variable */ + for (pv = purge_var; pv->name != NULL; pv++) { + if (!strncmp(pv->name, tl->t->b, + strlen(pv->name))) + break; + } + if (pv->name == NULL) { + vsb_printf(tl->sb, "Unknown purge variable."); + vcc_ErrWhere(tl, tl->t); + return; + } + if (pv->flag && + tl->t->b + strlen(pv->name) >= tl->t->e) { + vsb_printf(tl->sb, "Missing header name."); + vcc_ErrWhere(tl, tl->t); + return; + } + Fb(tl, 1, " \"%.*s\",\n", PF(tl->t)); vcc_NextToken(tl); switch(tl->t->tok) { From phk at projects.linpro.no Tue Jan 27 08:17:29 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 27 Jan 2009 09:17:29 +0100 (CET) Subject: r3544 - trunk/varnish-cache/bin/varnishd Message-ID: <20090127081729.84C0497B4B@projects.linpro.no> Author: phk Date: 2009-01-27 09:17:29 +0100 (Tue, 27 Jan 2009) New Revision: 3544 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c Log: Lack of a backend name is no reasonable cause for a panic. Modified: trunk/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-01-24 12:56:27 UTC (rev 3543) +++ trunk/varnish-cache/bin/varnishd/cache_vrt.c 2009-01-27 08:17:29 UTC (rev 3544) @@ -697,9 +697,10 @@ const char * VRT_backend_string(struct sess *sp) { - CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC); - return (sp->director->vcl_name); + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + if (sp->director == NULL) + return (NULL); + return (sp->director->vcl_name); } /*--------------------------------------------------------------------*/ From phk at projects.linpro.no Tue Jan 27 08:46:52 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 27 Jan 2009 09:46:52 +0100 (CET) Subject: r3545 - trunk/varnish-cache/bin/varnishd Message-ID: <20090127084652.2248697B4B@projects.linpro.no> Author: phk Date: 2009-01-27 09:46:51 +0100 (Tue, 27 Jan 2009) New Revision: 3545 Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c Log: Don't modify the obj_timer_when field outside the binheap lock. This hopefully finaly lays the sporadic assert(oe2->timer_when >= oe->timer_when); panics to rest. Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-01-27 08:17:29 UTC (rev 3544) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-01-27 08:46:51 UTC (rev 3545) @@ -133,27 +133,34 @@ * When & why does the timer fire for this object ? */ -static void +static int update_object_when(const struct object *o) { struct objexp *oe; + double when; + const char *what; CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); oe = o->objexp; CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); if (o->prefetch < 0.0) { - oe->timer_when = o->ttl + o->prefetch; - oe->timer_what = tmr_prefetch; + when = o->ttl + o->prefetch; + what = tmr_prefetch; } else if (o->prefetch > 0.0) { assert(o->prefetch <= o->ttl); - oe->timer_when = o->prefetch; - oe->timer_what = tmr_prefetch; + when = o->prefetch; + what = tmr_prefetch; } else { - oe->timer_when = o->ttl + HSH_Grace(o->grace); - oe->timer_what = tmr_ttl; + when = o->ttl + HSH_Grace(o->grace); + what = tmr_ttl; } - assert(!isnan(oe->timer_when)); + assert(!isnan(when)); + oe->timer_what = what; + if (when == oe->timer_when) + return (0); + oe->timer_when = when; + return (1); } /*-------------------------------------------------------------------- @@ -237,13 +244,20 @@ if (oe == NULL) return; CHECK_OBJ_NOTNULL(oe, OBJEXP_MAGIC); - update_object_when(o); Lck_Lock(&exp_mtx); - assert(oe->timer_idx != BINHEAP_NOIDX); - binheap_delete(exp_heap, oe->timer_idx); /* XXX: binheap_shuffle() ? */ - assert(oe->timer_idx == BINHEAP_NOIDX); - binheap_insert(exp_heap, oe); - assert(oe->timer_idx != BINHEAP_NOIDX); + if (update_object_when(o)) { + /* + * XXX: this could possibly be optimized by shuffling + * XXX: up or down, but that leaves some very nasty + * XXX: corner cases, such as shuffling all the way + * XXX: down the left half, then back up the right half. + */ + assert(oe->timer_idx != BINHEAP_NOIDX); + binheap_delete(exp_heap, oe->timer_idx); + assert(oe->timer_idx == BINHEAP_NOIDX); + binheap_insert(exp_heap, oe); + assert(oe->timer_idx != BINHEAP_NOIDX); + } Lck_Unlock(&exp_mtx); } From phk at projects.linpro.no Tue Jan 27 12:18:12 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 27 Jan 2009 13:18:12 +0100 (CET) Subject: r3546 - trunk/varnish-cache/lib/libvcl Message-ID: <20090127121812.CFAE097B4B@projects.linpro.no> Author: phk Date: 2009-01-27 13:18:12 +0100 (Tue, 27 Jan 2009) New Revision: 3546 Modified: trunk/varnish-cache/lib/libvcl/vcc_string.c Log: proper errorchecks for regsub syntax. (The recent change that moved the compiler into its own subprocess eliminates risk that a compiler error causes the management process to die, you just do not get a sensible syntax error). Fixes: #417 Modified: trunk/varnish-cache/lib/libvcl/vcc_string.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_string.c 2009-01-27 08:46:51 UTC (rev 3545) +++ trunk/varnish-cache/lib/libvcl/vcc_string.c 2009-01-27 12:18:12 UTC (rev 3546) @@ -53,6 +53,8 @@ int i; Expect(tl, CSTR); + if (tl->err) + return (NULL); memset(&t, 0, sizeof t); i = regcomp(&t, tl->t->dec, REG_EXTENDED | (sub ? 0 : REG_NOSUB)); if (i != 0) { @@ -88,6 +90,8 @@ Fb(tl, 0, "VRT_regsub(sp, %d, ", all); Expect(tl, '('); + if (tl->err) + return (0); vcc_NextToken(tl); if (!vcc_StringVal(tl)) { @@ -96,14 +100,20 @@ } Expect(tl, ','); + if (tl->err) + return (0); vcc_NextToken(tl); Expect(tl, CSTR); + if (tl->err) + return (0); p = vcc_regexp(tl, 1); vcc_NextToken(tl); Fb(tl, 0, ", %s, ", p); Expect(tl, ','); + if (tl->err) + return (0); vcc_NextToken(tl); if (!vcc_StringVal(tl)) { @@ -112,6 +122,8 @@ } Expect(tl, ')'); + if (tl->err) + return (0); vcc_NextToken(tl); Fb(tl, 0, ")"); From phk at projects.linpro.no Tue Jan 27 21:14:35 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Tue, 27 Jan 2009 22:14:35 +0100 (CET) Subject: r3547 - in trunk/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090127211435.E6E2797B4B@projects.linpro.no> Author: phk Date: 2009-01-27 22:14:35 +0100 (Tue, 27 Jan 2009) New Revision: 3547 Added: trunk/varnish-cache/bin/varnishtest/tests/r00427.vtc Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c Log: Stop processing ESI elements as soon as we discover that the client has closed the connection on us. Fixes #427 Modified: trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-01-27 12:18:12 UTC (rev 3546) +++ trunk/varnish-cache/bin/varnishd/cache_vrt_esi.c 2009-01-27 21:14:35 UTC (rev 3547) @@ -862,6 +862,8 @@ sp->esis--; sp->obj = obj; WRW_Reserve(sp->wrk, &sp->fd); + if (sp->fd < 0) + break; } if (sp->esis == 0 && sp->http->protover >= 1.1) (void)WRW_Write(sp->wrk, "0\r\n\r\n", -1); Added: trunk/varnish-cache/bin/varnishtest/tests/r00427.vtc =================================================================== --- trunk/varnish-cache/bin/varnishtest/tests/r00427.vtc (rev 0) +++ trunk/varnish-cache/bin/varnishtest/tests/r00427.vtc 2009-01-27 21:14:35 UTC (rev 3547) @@ -0,0 +1,43 @@ +# $Id$ + +test "client close in ESI delivery" + +server s1 { + rxreq + txresp -body { + + + + } + + rxreq + expect req.url == "/foo" + sema r1 sync 2 + sema r1 sync 2 + txresp -body "[foo]" + + rxreq + expect req.url == "/bar" + txresp -body "[bar]" + + rxreq + expect req.url == "/barf" + txresp -body "[barf]" +} -start + +varnish v1 -vcl+backend { + sub vcl_fetch { + esi; + } +} -start + +client c1 { + txreq + sema r1 sync 2 +} -run + +client c1 { + sema r1 sync 2 + txreq + rxresp +} -run From phk at projects.linpro.no Wed Jan 28 10:46:55 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 28 Jan 2009 11:46:55 +0100 (CET) Subject: r3548 - in trunk/varnish-cache/lib: libvarnish libvcl Message-ID: <20090128104655.1063797B4C@projects.linpro.no> Author: phk Date: 2009-01-28 11:46:54 +0100 (Wed, 28 Jan 2009) New Revision: 3548 Modified: trunk/varnish-cache/lib/libvarnish/tcp.c trunk/varnish-cache/lib/libvarnish/vss.c trunk/varnish-cache/lib/libvcl/vcc_acl.c Log: silence a couple of Flexelint complaints. Modified: trunk/varnish-cache/lib/libvarnish/tcp.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/tcp.c 2009-01-27 21:14:35 UTC (rev 3547) +++ trunk/varnish-cache/lib/libvarnish/tcp.c 2009-01-28 10:46:54 UTC (rev 3548) @@ -216,8 +216,8 @@ TCP_set_read_timeout(int s, double seconds) { struct timeval timeout; - timeout.tv_sec = floor(seconds); - timeout.tv_usec = 1e6 * (seconds - timeout.tv_sec); + timeout.tv_sec = (int)floor(seconds); + timeout.tv_usec = (int)(1e6 * (seconds - timeout.tv_sec)); #ifdef SO_RCVTIMEO_WORKS AZ(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout)); #endif Modified: trunk/varnish-cache/lib/libvarnish/vss.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vss.c 2009-01-27 21:14:35 UTC (rev 3547) +++ trunk/varnish-cache/lib/libvarnish/vss.c 2009-01-28 10:46:54 UTC (rev 3548) @@ -155,7 +155,7 @@ XXXAN(va); *vap = va; for (res = res0, i = 0; res != NULL; res = res->ai_next, ++i) { - va[i] = calloc(1, sizeof(*va[i])); + va[i] = calloc(1, sizeof(**va)); XXXAN(va[i]); va[i]->va_family = res->ai_family; va[i]->va_socktype = res->ai_socktype; Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c =================================================================== --- trunk/varnish-cache/lib/libvcl/vcc_acl.c 2009-01-27 21:14:35 UTC (rev 3547) +++ trunk/varnish-cache/lib/libvcl/vcc_acl.c 2009-01-28 10:46:54 UTC (rev 3548) @@ -321,20 +321,20 @@ * Emit a function to match the ACL we have collected */ +/* + * XXX: this is semi-silly. We try really hard to not depend in the + * XXX: systems include files while compiling VCL, but we need to know + * XXX: the size of the sa_familiy member. + * XXX: FlexeLint complains about these antics, so isolate it in a + * XXX: separate function. + */ + +/*lint -save -e506 -e774 -e550 */ static void -vcc_acl_emit(const struct tokenlist *tl, const char *acln, int anon) +c_is_a_silly_language(const struct tokenlist *tl) { - struct acl_e *ae; - int depth, l, m, i; - unsigned at[VRT_ACL_MAXADDR + 1]; - const char *oc; struct sockaddr sa; - Fh(tl, 0, "\nstatic int\n"); - Fh(tl, 0, "match_acl_%s_%s(const struct sess *sp, const void *p)\n", - anon ? "anon" : "named", acln); - Fh(tl, 0, "{\n"); - Fh(tl, 0, "\tconst unsigned char *a;\n"); assert(sizeof (unsigned char) == 1); assert(sizeof (unsigned short) == 2); assert(sizeof (unsigned int) == 4); @@ -346,7 +346,24 @@ Fh(tl, 0, "\tunsigned int fam;\n"); else assert(0 == __LINE__); +} +/*lint -restore */ +static void +vcc_acl_emit(const struct tokenlist *tl, const char *acln, int anon) +{ + struct acl_e *ae; + int depth, l, m, i; + unsigned at[VRT_ACL_MAXADDR + 1]; + const char *oc; + + Fh(tl, 0, "\nstatic int\n"); + Fh(tl, 0, "match_acl_%s_%s(const struct sess *sp, const void *p)\n", + anon ? "anon" : "named", acln); + Fh(tl, 0, "{\n"); + Fh(tl, 0, "\tconst unsigned char *a;\n"); + c_is_a_silly_language(tl); + Fh(tl, 0, "\n"); Fh(tl, 0, "\ta = p;\n"); Fh(tl, 0, "\tVRT_memmove(&fam, a + %d, sizeof fam);\n", From tfheen at projects.linpro.no Wed Jan 28 11:48:03 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 12:48:03 +0100 (CET) Subject: r3549 - trunk/varnish-cache/include Message-ID: <20090128114803.74B151F7475@projects.linpro.no> Author: tfheen Date: 2009-01-28 12:48:03 +0100 (Wed, 28 Jan 2009) New Revision: 3549 Modified: trunk/varnish-cache/include/Makefile.am Log: Add missing header file to tarball Fixes build failure Modified: trunk/varnish-cache/include/Makefile.am =================================================================== --- trunk/varnish-cache/include/Makefile.am 2009-01-28 10:46:54 UTC (rev 3548) +++ trunk/varnish-cache/include/Makefile.am 2009-01-28 11:48:03 UTC (rev 3549) @@ -26,6 +26,7 @@ libvarnish.h \ libvcl.h \ miniobj.h \ + purge_vars.h \ vsha256.h \ vqueue.h \ vpf.h \ From phk at projects.linpro.no Wed Jan 28 11:48:07 2009 From: phk at projects.linpro.no (phk at projects.linpro.no) Date: Wed, 28 Jan 2009 12:48:07 +0100 (CET) Subject: r3550 - trunk/varnish-cache/bin/varnishd Message-ID: <20090128114807.577BD97B50@projects.linpro.no> Author: phk Date: 2009-01-28 12:48:07 +0100 (Wed, 28 Jan 2009) New Revision: 3550 Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c trunk/varnish-cache/bin/varnishd/cache_fetch.c trunk/varnish-cache/bin/varnishd/cache_hash.c trunk/varnish-cache/bin/varnishd/cache_http.c trunk/varnish-cache/bin/varnishd/flint.lnt trunk/varnish-cache/bin/varnishd/mgt.h trunk/varnish-cache/bin/varnishd/mgt_cli.c trunk/varnish-cache/bin/varnishd/mgt_vcc.c trunk/varnish-cache/bin/varnishd/rfc2616.c Log: More FlexeLint silencing. Modified: trunk/varnish-cache/bin/varnishd/cache_expire.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-01-28 11:48:03 UTC (rev 3549) +++ trunk/varnish-cache/bin/varnishd/cache_expire.c 2009-01-28 11:48:07 UTC (rev 3550) @@ -184,7 +184,7 @@ assert(o->entered != 0 && !isnan(o->entered)); oe->lru_stamp = o->entered; - update_object_when(o); + (void)update_object_when(o); Lck_Lock(&exp_mtx); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); @@ -332,7 +332,7 @@ WSL(&ww, SLT_Debug, 0, "Attempt Prefetch %u", o->xid); } - update_object_when(o); + (void)update_object_when(o); Lck_Lock(&exp_mtx); binheap_insert(exp_heap, oe); assert(oe->timer_idx != BINHEAP_NOIDX); Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2009-01-28 11:48:03 UTC (rev 3549) +++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2009-01-28 11:48:07 UTC (rev 3550) @@ -351,7 +351,7 @@ TCP_blocking(vc->fd); /* XXX: we should timeout instead */ WRW_Reserve(w, &vc->fd); - http_Write(w, hp, 0); /* XXX: stats ? */ + (void)http_Write(w, hp, 0); /* XXX: stats ? */ /* Deal with any message-body the request might have */ i = FetchReqBody(sp); Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-28 11:48:03 UTC (rev 3549) +++ trunk/varnish-cache/bin/varnishd/cache_hash.c 2009-01-28 11:48:07 UTC (rev 3550) @@ -228,7 +228,6 @@ HSH_Lookup(struct sess *sp) { struct worker *w; - struct http *h; struct objhead *oh; struct object *o, *busy_o, *grace_o; @@ -237,7 +236,6 @@ CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC); AN(hash); w = sp->wrk; - h = sp->http; HSH_Prealloc(sp); SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx); Modified: trunk/varnish-cache/bin/varnishd/cache_http.c =================================================================== --- trunk/varnish-cache/bin/varnishd/cache_http.c 2009-01-28 11:48:03 UTC (rev 3549) +++ trunk/varnish-cache/bin/varnishd/cache_http.c 2009-01-28 11:48:07 UTC (rev 3550) @@ -796,8 +796,8 @@ if (http_IsHdr(&hp->hd[u], hdr)) continue; if (v != u) { - memcpy(&hp->hd[v], &hp->hd[u], sizeof hp->hd[v]); - memcpy(&hp->hdf[v], &hp->hdf[u], sizeof hp->hdf[v]); + memcpy(&hp->hd[v], &hp->hd[u], sizeof *hp->hd); + memcpy(&hp->hdf[v], &hp->hdf[u], sizeof *hp->hdf); } v++; } Modified: trunk/varnish-cache/bin/varnishd/flint.lnt =================================================================== --- trunk/varnish-cache/bin/varnishd/flint.lnt 2009-01-28 11:48:03 UTC (rev 3549) +++ trunk/varnish-cache/bin/varnishd/flint.lnt 2009-01-28 11:48:07 UTC (rev 3550) @@ -7,6 +7,7 @@ -e459 // unlocked access from func-ptr -e454 // mutex not released (...ReleaseLocked) -e457 // unprotected access +-e777 // float equality comparison -esym(458, lbv_assert) // unlocked access -esym(458, params) // unlocked access @@ -56,6 +57,8 @@ -emacro(702, WEXITSTATUS) // signed shift right -efunc(525, VCC_Return_Name) // Negative indent + + // -header(../../config.h) // Fix strchr() semtics, it can only return NULL if arg2 != 0 Modified: trunk/varnish-cache/bin/varnishd/mgt.h =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt.h 2009-01-28 11:48:03 UTC (rev 3549) +++ trunk/varnish-cache/bin/varnishd/mgt.h 2009-01-28 11:48:07 UTC (rev 3550) @@ -49,7 +49,7 @@ int mgt_cli_askchild(unsigned *status, char **resp, const char *fmt, ...); void mgt_cli_start_child(int fdi, int fdo); void mgt_cli_stop_child(void); -int mgt_cli_telnet(int dflag, const char *T_arg); +void mgt_cli_telnet(int dflag, const char *T_arg); /* mgt_param.c */ void MCF_ParamSync(void); Modified: trunk/varnish-cache/bin/varnishd/mgt_cli.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_cli.c 2009-01-28 11:48:03 UTC (rev 3549) +++ trunk/varnish-cache/bin/varnishd/mgt_cli.c 2009-01-28 11:48:07 UTC (rev 3550) @@ -454,7 +454,7 @@ return (0); } -int +void mgt_cli_telnet(int dflag, const char *T_arg) { struct vss_addr **ta; @@ -494,5 +494,4 @@ } free(addr); free(port); - return (0); } Modified: trunk/varnish-cache/bin/varnishd/mgt_vcc.c =================================================================== --- trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2009-01-28 11:48:03 UTC (rev 3549) +++ trunk/varnish-cache/bin/varnishd/mgt_vcc.c 2009-01-28 11:48:07 UTC (rev 3550) @@ -263,7 +263,7 @@ static char * mgt_VccCompile(struct vsb **sb, const char *b, int C_flag) { - char *vf = NULL; + char *vf; *sb = vsb_newauto(); XXXAN(*sb); Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c =================================================================== --- trunk/varnish-cache/bin/varnishd/rfc2616.c 2009-01-28 11:48:03 UTC (rev 3549) +++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2009-01-28 11:48:07 UTC (rev 3550) @@ -145,7 +145,7 @@ * derive a relative time from the two headers. * (the negative ttl case is caught above) */ - ttl = (h_expires - h_date); + ttl = (int)(h_expires - h_date); } while (0); From tfheen at projects.linpro.no Wed Jan 28 12:06:57 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 13:06:57 +0100 (CET) Subject: r3551 - branches/2.0/varnish-cache/bin/varnishtest/tests Message-ID: <20090128120657.D7F5728438@projects.linpro.no> Author: tfheen Date: 2009-01-28 13:06:57 +0100 (Wed, 28 Jan 2009) New Revision: 3551 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/r00365.vtc Log: Merge r3387: Regression test case for ticket 365: restart in hit. Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/r00365.vtc (from rev 3387, trunk/varnish-cache/bin/varnishtest/tests/r00365.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/r00365.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/r00365.vtc 2009-01-28 12:06:57 UTC (rev 3551) @@ -0,0 +1,31 @@ +# $Id$ + +test "Test restarts in vcl_hit" + +server s1 { + rxreq + expect req.url == "/foo" + txresp -status 200 -body "1" + rxreq + expect req.url == "/foo" + txresp -status 200 -body "22" +} -start + +varnish v1 -vcl+backend { + sub vcl_hit { + set obj.cacheable = false; + restart; + } +} -start + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.bodylen == 1 + + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.bodylen == 2 +} -run From tfheen at projects.linpro.no Wed Jan 28 12:13:06 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 13:13:06 +0100 (CET) Subject: r3552 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests Message-ID: <20090128121306.0FC1A97B4C@projects.linpro.no> Author: tfheen Date: 2009-01-28 13:13:05 +0100 (Wed, 28 Jan 2009) New Revision: 3552 Added: branches/2.0/varnish-cache/bin/varnishtest/tests/v00023.vtc Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c Log: Merge r3388: Make sure that set obj.ttl = 0s means that the object is not hit again by actually using "-1" instead. This works around the rounding error which otherwise causes the object to be inside TTL for up to one second - epsilon. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-01-28 12:06:57 UTC (rev 3551) +++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-01-28 12:13:05 UTC (rev 3552) @@ -318,9 +318,16 @@ CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC); /* XXX */ WSP(sp, SLT_TTL, "%u VCL %.0f %.0f", sp->obj->xid, a, sp->t_req); - if (a < 0) - a = 0; - sp->obj->ttl = sp->t_req + a; + /* + * If people set obj.ttl = 0s, they don't expect it to be cacheable + * any longer, but it will still be for up to 1s - epsilon because + * of the rounding to seconds. + * We special case and make sure that rounding does not surprise. + */ + if (a <= 0) + sp->obj->ttl = sp->t_req - 1; + else + sp->obj->ttl = sp->t_req + a; EXP_Rearm(sp->obj); } Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/v00023.vtc (from rev 3388, trunk/varnish-cache/bin/varnishtest/tests/v00023.vtc) =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/tests/v00023.vtc (rev 0) +++ branches/2.0/varnish-cache/bin/varnishtest/tests/v00023.vtc 2009-01-28 12:13:05 UTC (rev 3552) @@ -0,0 +1,31 @@ +# $Id$ + +test "Test that obj.ttl = 0s prevents subsequent hits" + +server s1 { + rxreq + expect req.url == "/foo" + txresp -status 200 -body "1" + rxreq + expect req.url == "/foo" + txresp -status 200 -body "22" +} -start + +varnish v1 -vcl+backend { + sub vcl_hit { + set obj.ttl = 0s; + restart; + } +} -start + +client c1 { + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.bodylen == 1 + + txreq -url "/foo" + rxresp + expect resp.status == 200 + expect resp.bodylen == 2 +} -run From tfheen at projects.linpro.no Wed Jan 28 12:18:11 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 13:18:11 +0100 (CET) Subject: r3553 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090128121811.33BFF97B4C@projects.linpro.no> Author: tfheen Date: 2009-01-28 13:18:10 +0100 (Wed, 28 Jan 2009) New Revision: 3553 Modified: branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c Log: Merge r3401: Make malloc print max storage size storage_file prints the maximum storage size, make malloc do the same, for consistency. Modified: branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c 2009-01-28 12:13:05 UTC (rev 3552) +++ branches/2.0/varnish-cache/bin/varnishd/storage_malloc.c 2009-01-28 12:18:10 UTC (rev 3553) @@ -143,6 +143,9 @@ ARGV_ERR("(-smalloc) size \"%s\": %s\n", av[0], e); if ((u != (uintmax_t)(size_t)u)) ARGV_ERR("(-smalloc) size \"%s\": too big\n", av[0]); + + printf("storage_malloc: max size %ju MB.\n", + u / (1024 * 1024)); sma_max = u; } From tfheen at projects.linpro.no Wed Jan 28 12:22:58 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 13:22:58 +0100 (CET) Subject: r3554 - branches/2.0/varnish-cache/man Message-ID: <20090128122258.C4A9597B4C@projects.linpro.no> Author: tfheen Date: 2009-01-28 13:22:58 +0100 (Wed, 28 Jan 2009) New Revision: 3554 Modified: branches/2.0/varnish-cache/man/vcl.7so Log: Merge r3402: Document grace Thanks to perbu for suggested documentation Fixes 355 Modified: branches/2.0/varnish-cache/man/vcl.7so =================================================================== --- branches/2.0/varnish-cache/man/vcl.7so 2009-01-28 12:18:10 UTC (rev 3553) +++ branches/2.0/varnish-cache/man/vcl.7so 2009-01-28 12:22:58 UTC (rev 3554) @@ -186,6 +186,24 @@ pipe; } .Ed +.Ss Grace +If the backend takes a long time to generate an object there is a risk +of a thread pile up. +In order to prevent this you can enable grace. +This allows varnish to serve an expired version of the object while a +fresh object is being generated by the backend. +.Pp +The following vcl code will make Varnish serve expired objects. +All object will be kept up to two minutes past their expiration time +or a fresh object is generated. +.Bd -literal -offset 4n +sub vcl_recv { + set req.grace = 2m; +} +sub vcl_fetch { + set obj.grace = 2m; +} +.Ed .Ss Functions The following built-in functions are available: .Bl -tag -width indent From tfheen at projects.linpro.no Wed Jan 28 13:50:47 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 14:50:47 +0100 (CET) Subject: r3555 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090128135047.68F5B28431@projects.linpro.no> Author: tfheen Date: 2009-01-28 14:50:47 +0100 (Wed, 28 Jan 2009) New Revision: 3555 Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.1 Log: Merge r3407: Correct defaults in varnishd.1 The defaults for thread_pool_min and thread_pools were wrong; fixed. Modified: branches/2.0/varnish-cache/bin/varnishd/varnishd.1 =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/varnishd.1 2009-01-28 12:22:58 UTC (rev 3554) +++ branches/2.0/varnish-cache/bin/varnishd/varnishd.1 2009-01-28 13:50:47 UTC (rev 3555) @@ -520,7 +520,7 @@ .Nm to respond faster to a sudden increase in traffic. .Pp -The default is 1. +The default is 5. .It Va thread_pools The number of worker thread pools. Higher values reduce lock contention but increase pressure on the @@ -528,7 +528,7 @@ Note that a decrease of this parameter will only take effect after a restart. .Pp -The default is 1. +The default is 2. .It Va thread_pool_timeout The amount of time a worker thread can be idle before it is killed, when the number of worker threads exceeds From tfheen at projects.linpro.no Wed Jan 28 13:56:19 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 14:56:19 +0100 (CET) Subject: r3556 - branches/2.0/varnish-cache/bin/varnishtest Message-ID: <20090128135619.6F17A28431@projects.linpro.no> Author: tfheen Date: 2009-01-28 14:56:19 +0100 (Wed, 28 Jan 2009) New Revision: 3556 Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c Log: Merge r3408: Check ECONNRESET Modified: branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c 2009-01-28 13:50:47 UTC (rev 3555) +++ branches/2.0/varnish-cache/bin/varnishtest/vtc_server.c 2009-01-28 13:56:19 UTC (rev 3556) @@ -97,7 +97,8 @@ vtc_log(vl, 3, "Accepted socket fd is %d", fd); http_process(vl, s->spec, fd, 0); vtc_log(vl, 3, "shutting fd %d", fd); - assert((shutdown(fd, SHUT_WR) == 0) || errno == ENOTCONN); + assert((shutdown(fd, SHUT_WR) == 0) + || errno == ENOTCONN || errno == ECONNRESET); TCP_close(&fd); } vtc_log(vl, 2, "Ending"); From tfheen at projects.linpro.no Wed Jan 28 14:04:12 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 15:04:12 +0100 (CET) Subject: r3557 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090128140412.6948C28431@projects.linpro.no> Author: tfheen Date: 2009-01-28 15:04:12 +0100 (Wed, 28 Jan 2009) New Revision: 3557 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.h Log: Merge r3418: Fix typo Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.h =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.h 2009-01-28 13:56:19 UTC (rev 3556) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.h 2009-01-28 14:04:12 UTC (rev 3557) @@ -30,7 +30,7 @@ */ BITMAP(good_ipv4, '4', "Good IPv4", 0) -BITMAP(good_ipv6, '6', "Good IPv4", 0) +BITMAP(good_ipv6, '6', "Good IPv6", 0) BITMAP( err_xmit, 'x', "Error Xmit", 0) BITMAP(good_xmit, 'X', "Good Xmit", 0) BITMAP( err_shut, 's', "Error Shut", 0) From tfheen at projects.linpro.no Wed Jan 28 14:08:33 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 15:08:33 +0100 (CET) Subject: r3558 - in branches/2.0/varnish-cache: include lib/libvarnish Message-ID: <20090128140833.2E2AB28431@projects.linpro.no> Author: tfheen Date: 2009-01-28 15:08:32 +0100 (Wed, 28 Jan 2009) New Revision: 3558 Modified: branches/2.0/varnish-cache/include/vsb.h branches/2.0/varnish-cache/lib/libvarnish/vsb.c Log: Merge r3420: Update license to remove the advertising clause, reflecting similar change in the FreeBSD original. Approved by: des Modified: branches/2.0/varnish-cache/include/vsb.h =================================================================== --- branches/2.0/varnish-cache/include/vsb.h 2009-01-28 14:04:12 UTC (rev 3557) +++ branches/2.0/varnish-cache/include/vsb.h 2009-01-28 14:08:32 UTC (rev 3558) @@ -11,8 +11,6 @@ * 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES Modified: branches/2.0/varnish-cache/lib/libvarnish/vsb.c =================================================================== --- branches/2.0/varnish-cache/lib/libvarnish/vsb.c 2009-01-28 14:04:12 UTC (rev 3557) +++ branches/2.0/varnish-cache/lib/libvarnish/vsb.c 2009-01-28 14:08:32 UTC (rev 3558) @@ -11,8 +11,6 @@ * 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES From tfheen at projects.linpro.no Wed Jan 28 14:12:21 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 15:12:21 +0100 (CET) Subject: r3559 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090128141221.054E128431@projects.linpro.no> Author: tfheen Date: 2009-01-28 15:12:20 +0100 (Wed, 28 Jan 2009) New Revision: 3559 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c Log: Merge r3426: Fix typo (s/timeout/interval/) in default parameters for backend health Thanks to Jonny @ globo for noticing. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c 2009-01-28 14:08:32 UTC (rev 3558) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c 2009-01-28 14:12:20 UTC (rev 3559) @@ -261,7 +261,7 @@ if (vt->probe.timeout == 0.0) vt->probe.timeout = 2.0; if (vt->probe.interval == 0.0) - vt->probe.timeout = 5.0; + vt->probe.interval = 5.0; if (vt->probe.window == 0) vt->probe.window = 8; if (vt->probe.threshold == 0) From tfheen at projects.linpro.no Wed Jan 28 14:21:04 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 15:21:04 +0100 (CET) Subject: r3560 - branches/2.0/varnish-cache/redhat Message-ID: <20090128142104.E982028431@projects.linpro.no> Author: tfheen Date: 2009-01-28 15:21:04 +0100 (Wed, 28 Jan 2009) New Revision: 3560 Modified: branches/2.0/varnish-cache/redhat/varnish.spec Log: Merge r3463: Changed rpm summary string as requested by the Fedora project Modified: branches/2.0/varnish-cache/redhat/varnish.spec =================================================================== --- branches/2.0/varnish-cache/redhat/varnish.spec 2009-01-28 14:12:20 UTC (rev 3559) +++ branches/2.0/varnish-cache/redhat/varnish.spec 2009-01-28 14:21:04 UTC (rev 3560) @@ -1,4 +1,4 @@ -Summary: Varnish is a high-performance HTTP accelerator +Summary: High-performance HTTP accelerator Name: varnish Version: 2.0.2 Release: 1%{?dist} From tfheen at projects.linpro.no Wed Jan 28 14:32:57 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 15:32:57 +0100 (CET) Subject: r3561 - branches/2.0/varnish-cache/lib/libvcl Message-ID: <20090128143257.573FF1F747B@projects.linpro.no> Author: tfheen Date: 2009-01-28 15:32:57 +0100 (Wed, 28 Jan 2009) New Revision: 3561 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c Log: Merge r3466: Add a missing error check. Fixes #409 Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c =================================================================== --- branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-01-28 14:21:04 UTC (rev 3560) +++ branches/2.0/varnish-cache/lib/libvcl/vcc_parse.c 2009-01-28 14:32:57 UTC (rev 3561) @@ -251,6 +251,7 @@ case '~': vcc_NextToken(tl); p = vcc_regexp(tl, 0); + ERRCHK(tl); vcc_NextToken(tl); Fb(tl, 1, "VRT_re_match(%s, %s)\n", vp->rname, p); break; From tfheen at projects.linpro.no Wed Jan 28 14:40:37 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 15:40:37 +0100 (CET) Subject: r3562 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090128144037.AE69B1F74A0@projects.linpro.no> Author: tfheen Date: 2009-01-28 15:40:37 +0100 (Wed, 28 Jan 2009) New Revision: 3562 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c Log: Merge r3488: Assert fcntl(2) have not failed. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2009-01-28 14:32:57 UTC (rev 3561) +++ branches/2.0/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c 2009-01-28 14:40:37 UTC (rev 3562) @@ -209,8 +209,10 @@ int i; i = fcntl(vca_pipes[0], F_GETFL); + assert(i != -1); i |= O_NONBLOCK; i = fcntl(vca_pipes[0], F_SETFL, i); + assert(i != -1); AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL)); } From tfheen at projects.linpro.no Wed Jan 28 15:09:40 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Wed, 28 Jan 2009 16:09:40 +0100 (CET) Subject: r3563 - branches/2.0/varnish-cache/bin/varnishd Message-ID: <20090128150940.63EFF28431@projects.linpro.no> Author: tfheen Date: 2009-01-28 16:09:40 +0100 (Wed, 28 Jan 2009) New Revision: 3563 Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c Log: Merge r3492: Be more stringent about our timeout: fail even if we did get a socket, but took to. Modified: branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c =================================================================== --- branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c 2009-01-28 14:40:37 UTC (rev 3562) +++ branches/2.0/varnish-cache/bin/varnishd/cache_backend_poll.c 2009-01-28 15:09:40 UTC (rev 3563) @@ -157,6 +157,11 @@ /* Got no connection: failed */ return; } + if (tmo <= 0) { + /* Spent too long time getting it */ + TCP_close(&s); + return; + } /* Send the request */ i = write(s, vt->req, vt->req_len); From tfheen at projects.linpro.no Fri Jan 30 14:40:32 2009 From: tfheen at projects.linpro.no (tfheen at projects.linpro.no) Date: Fri, 30 Jan 2009 15:40:32 +0100 (CET) Subject: r3564 - trunk/varnish-cache/lib/libvarnish Message-ID: <20090130144032.93DA497B4C@projects.linpro.no> Author: tfheen Date: 2009-01-30 15:40:32 +0100 (Fri, 30 Jan 2009) New Revision: 3564 Modified: trunk/varnish-cache/lib/libvarnish/vsha256.c Log: Move mybe{32,64}enc definitions outside of ifdef so we work on 64 bit BE platforms too. Modified: trunk/varnish-cache/lib/libvarnish/vsha256.c =================================================================== --- trunk/varnish-cache/lib/libvarnish/vsha256.c 2009-01-28 15:09:40 UTC (rev 3563) +++ trunk/varnish-cache/lib/libvarnish/vsha256.c 2009-01-30 14:40:32 UTC (rev 3564) @@ -45,6 +45,26 @@ #include "libvarnish.h" #include "vsha256.h" +static __inline void +mybe32enc(void *pp, uint32_t u) +{ + unsigned char *p = (unsigned char *)pp; + + p[0] = (u >> 24) & 0xff; + p[1] = (u >> 16) & 0xff; + p[2] = (u >> 8) & 0xff; + p[3] = u & 0xff; +} + +static __inline void +mybe64enc(void *pp, uint64_t u) +{ + unsigned char *p = (unsigned char *)pp; + + mybe32enc(p, u >> 32); + mybe32enc(p + 4, u & 0xffffffff); +} + #if defined(VBYTE_ORDER) && VBYTE_ORDER == VBIG_ENDIAN /* Copy a vector of big-endian uint32_t into a vector of bytes */ @@ -65,26 +85,6 @@ return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); } -static __inline void -mybe32enc(void *pp, uint32_t u) -{ - unsigned char *p = (unsigned char *)pp; - - p[0] = (u >> 24) & 0xff; - p[1] = (u >> 16) & 0xff; - p[2] = (u >> 8) & 0xff; - p[3] = u & 0xff; -} - -static __inline void -mybe64enc(void *pp, uint64_t u) -{ - unsigned char *p = (unsigned char *)pp; - - mybe32enc(p, u >> 32); - mybe32enc(p + 4, u & 0xffffffff); -} - /* * Encode a length len/4 vector of (uint32_t) into a length len vector of * (unsigned char) in big-endian form. Assumes len is a multiple of 4.