sp->lhashptr += l + 1;
}
+/**********************************************************************
+ * This is a debugging hack to enable testing of boundary conditions
+ * in the hash algorithm.
+ * We trap the first 9 different digests and translate them to different
+ * digests with edge bit conditions
+ */
+
+static struct hsh_magiclist {
+ unsigned char was[SHA256_LEN];
+ unsigned char now[SHA256_LEN];
+} hsh_magiclist[] = {
+ { .now = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+ { .now = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } },
+ { .now = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 } },
+ { .now = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40 } },
+ { .now = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80 } },
+ { .now = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+ { .now = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+ { .now = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+ { .now = { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },
+};
+
+#define HSH_NMAGIC (sizeof hsh_magiclist / sizeof hsh_magiclist[0])
+
+static void
+hsh_testmagic(void *result)
+{
+ int i, j;
+ static int nused;
+
+ for (i = 0; i < nused; i++)
+ if (!memcmp(hsh_magiclist[i].was, result, SHA256_LEN))
+ break;
+ if (i == nused && i < HSH_NMAGIC)
+ memcpy(hsh_magiclist[nused++].was, result, SHA256_LEN);
+ if (i == nused)
+ return;
+ fprintf(stderr, "HASHMAGIC: <");
+ for (j = 0; j < SHA256_LEN; j++)
+ fprintf(stderr, "%02x", ((unsigned char*)result)[j]);
+ fprintf(stderr, "> -> <");
+ memcpy(result, hsh_magiclist[i].now, SHA256_LEN);
+ for (j = 0; j < SHA256_LEN; j++)
+ fprintf(stderr, "%02x", ((unsigned char*)result)[j]);
+ fprintf(stderr, ">\n");
+}
+
+/**********************************************************************/
+
+
struct objcore *
HSH_Lookup(struct sess *sp, struct objhead **poh)
{
HSH_Prealloc(sp);
SHA256_Final(sp->wrk->nobjhead->digest, sp->wrk->sha256ctx);
+ if (params->diag_bitmap & 0x80000000)
+ hsh_testmagic(sp->wrk->nobjhead->digest);
if (sp->objhead != NULL) {
CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
--- /dev/null
+# $Id$
+
+test "Test -h critbit for digest edges"
+
+server s1 {
+ rxreq
+ expect req.url == "/1"
+ txresp -body "\n"
+ rxreq
+ expect req.url == "/2"
+ txresp -body "x\n"
+ rxreq
+ expect req.url == "/3"
+ txresp -body "xx\n"
+ rxreq
+ expect req.url == "/4"
+ txresp -body "xxx\n"
+ rxreq
+ expect req.url == "/5"
+ txresp -body "xxxx\n"
+ rxreq
+ expect req.url == "/6"
+ txresp -body "xxxxx\n"
+ rxreq
+ expect req.url == "/7"
+ txresp -body "xxxxxx\n"
+ rxreq
+ expect req.url == "/8"
+ txresp -body "xxxxxxx\n"
+ rxreq
+ expect req.url == "/9"
+ txresp -body "xxxxxxxx\n"
+} -start
+
+varnish v1 -arg "-hcritbit" -vcl+backend { } -start
+varnish v1 -cliok "param.set diag_bitmap 0x8000000"
+
+client c1 {
+ txreq -url "/1"
+ rxresp
+ expect resp.status == 200
+ expect resp.bodylen == 1
+ expect resp.http.X-Varnish == "1001"
+
+ txreq -url "/2"
+ rxresp
+ expect resp.bodylen == 2
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1002"
+
+ txreq -url "/3"
+ rxresp
+ expect resp.bodylen == 3
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1003"
+
+ txreq -url "/4"
+ rxresp
+ expect resp.bodylen == 4
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1004"
+
+ txreq -url "/5"
+ rxresp
+ expect resp.bodylen == 5
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1005"
+
+ txreq -url "/6"
+ rxresp
+ expect resp.bodylen == 6
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1006"
+
+ txreq -url "/7"
+ rxresp
+ expect resp.bodylen == 7
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1007"
+
+ txreq -url "/8"
+ rxresp
+ expect resp.bodylen == 8
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1008"
+
+ txreq -url "/9"
+ rxresp
+ expect resp.bodylen == 9
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1009"
+} -run
+
+
+client c1 {
+ txreq -url "/1"
+ rxresp
+ expect resp.status == 200
+ expect resp.bodylen == 1
+ expect resp.http.X-Varnish == "1010 1001"
+
+ txreq -url "/2"
+ rxresp
+ expect resp.bodylen == 2
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1011 1002"
+
+ txreq -url "/3"
+ rxresp
+ expect resp.bodylen == 3
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1012 1003"
+
+ txreq -url "/4"
+ rxresp
+ expect resp.bodylen == 4
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1013 1004"
+
+ txreq -url "/5"
+ rxresp
+ expect resp.bodylen == 5
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1014 1005"
+
+ txreq -url "/6"
+ rxresp
+ expect resp.bodylen == 6
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1015 1006"
+
+ txreq -url "/7"
+ rxresp
+ expect resp.bodylen == 7
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1016 1007"
+
+ txreq -url "/8"
+ rxresp
+ expect resp.bodylen == 8
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1017 1008"
+
+ txreq -url "/9"
+ rxresp
+ expect resp.bodylen == 9
+ expect resp.status == 200
+ expect resp.http.X-Varnish == "1018 1009"
+} -run
+
+varnish v1 -cliok "hcb.dump"
+
+varnish v1 -expect client_conn == 2
+varnish v1 -expect cache_hit == 9
+varnish v1 -expect cache_miss == 9
+varnish v1 -expect client_req == 18