Dag-Erling Smørgrav <[EMAIL PROTECTED]> writes:
> Dag-Erling Smørgrav <[EMAIL PROTECTED]> writes:
> > Trond Michelsen <[EMAIL PROTECTED]> writes:
> > > Hi. Is it possible to configure varnishncsa so that it doesn't
> > > truncate URLs at 256 characters?
> > The limitation is not in varnishncsa, but in the shared memory log
> > format. We use only one byte to store the length of the log record.
> The attached patch increases the limit to 65535 characters, but breaks
> binary compatibility with old log files.
Once more, with patch.
DES
--
Dag-Erling Smørgrav
Senior Software Developer
Linpro AS - www.linpro.no
Index: lib/libvarnishapi/shmlog.c
===================================================================
--- lib/libvarnishapi/shmlog.c (revision 2050)
+++ lib/libvarnishapi/shmlog.c (working copy)
@@ -222,15 +222,16 @@
vsl_nextlog(struct VSL_data *vd, unsigned char **pp)
{
unsigned char *p;
- unsigned w;
+ unsigned r, w;
int i;
CHECK_OBJ_NOTNULL(vd, VSL_MAGIC);
if (vd->fi != NULL) {
- i = fread(vd->rbuf, 4, 1, vd->fi);
+ i = fread(vd->rbuf, 5, 1, vd->fi);
if (i != 1)
return (-1);
- i = fread(vd->rbuf + 4, vd->rbuf[1] + 1, 1, vd->fi);
+ r = (vd->rbuf[1] << 8) | vd->rbuf[2];
+ i = fread(vd->rbuf + 5, r + 1, 1, vd->fi);
if (i != 1)
return (-1);
*pp = vd->rbuf;
@@ -250,7 +251,7 @@
usleep(SLEEP_USEC);
continue;
}
- vd->ptr = p + p[1] + 5;
+ vd->ptr = p + p[1] + 6;
*pp = p;
return (1);
}
@@ -271,7 +272,7 @@
i = vsl_nextlog(vd, &p);
if (i != 1)
return (i);
- u = (p[2] << 8) | p[3];
+ u = (p[3] << 8) | p[4];
switch(p[0]) {
case SLT_SessionOpen:
case SLT_ReqStart:
@@ -298,15 +299,15 @@
continue;
if (vd->regincl != NULL) {
rm.rm_so = 0;
- rm.rm_eo = p[1];
- i = regexec(vd->regincl, (char *)p + 4, 1, &rm, 0);
+ rm.rm_eo = (p[1] << 8) | p[2];
+ i = regexec(vd->regincl, (char *)p + 5, 1, &rm, 0);
if (i == REG_NOMATCH)
continue;
}
if (vd->regexcl != NULL) {
rm.rm_so = 0;
- rm.rm_eo = p[1];
- i = regexec(vd->regexcl, (char *)p + 4, 1, &rm, 0);
+ rm.rm_eo = (p[1] << 8) | p[2];
+ i = regexec(vd->regexcl, (char *)p + 5, 1, &rm, 0);
if (i != REG_NOMATCH)
continue;
}
@@ -331,9 +332,9 @@
return (i);
u = (p[2] << 8) | p[3];
if (func(priv,
- p[0], u, p[1],
+ p[0], u, (p[1] << 8) | p[2],
vd->map[u] & (VSL_S_CLIENT|VSL_S_BACKEND),
- (char *)p + 4))
+ (char *)p + 5))
return (1);
}
}
Index: bin/varnishd/shmlog.c
===================================================================
--- bin/varnishd/shmlog.c (revision 2050)
+++ bin/varnishd/shmlog.c (working copy)
@@ -92,8 +92,8 @@
/* Truncate */
l = Tlen(t);
- if (l > 255) {
- l = 255;
+ if (l > 0xffff) {
+ l = 0xffff;
t.e = t.b + l;
}
@@ -104,19 +104,20 @@
assert(loghead->ptr < loghead->size);
/* Wrap if necessary */
- if (loghead->ptr + 5 + l + 1 >= loghead->size)
+ if (loghead->ptr + 6 + l + 1 >= loghead->size)
vsl_wrap();
p = logstart + loghead->ptr;
- loghead->ptr += 5 + l;
- p[5 + l] = SLT_ENDMARKER;
+ loghead->ptr += 6 + l;
+ p[6 + l] = SLT_ENDMARKER;
assert(loghead->ptr < loghead->size);
UNLOCKSHM(&vsl_mtx);
- p[1] = l & 0xff;
- p[2] = (id >> 8) & 0xff;
- p[3] = id & 0xff;
- memcpy(p + 4, t.b, l);
- p[4 + l] = '\0';
+ p[1] = (l >> 8) & 0xff;
+ p[2] = l & 0xff;
+ p[3] = (id >> 8) & 0xff;
+ p[4] = id & 0xff;
+ memcpy(p + 5, t.b, l);
+ p[5 + l] = '\0';
/* XXX: memory barrier */
p[0] = tag;
}
@@ -147,22 +148,23 @@
assert(loghead->ptr < loghead->size);
/* Wrap if we cannot fit a full size record */
- if (loghead->ptr + 5 + 255 + 1 >= loghead->size)
+ if (loghead->ptr + 6 + 0xffff + 1 >= loghead->size)
vsl_wrap();
p = logstart + loghead->ptr;
n = 0;
- n = vsnprintf((char *)(p + 4), 256, fmt, ap);
- if (n > 255)
- n = 255; /* we truncate long fields */
- p[1] = n & 0xff;
- p[2] = (id >> 8) & 0xff;
- p[3] = id & 0xff;
- p[4 + n] = '\0';;
- p[5 + n] = SLT_ENDMARKER;
+ n = vsnprintf((char *)(p + 5), 0x10000, fmt, ap);
+ if (n > 0xffff)
+ n = 0xffff; /* we truncate long fields */
+ p[1] = (n >> 8) & 0xff;
+ p[2] = n & 0xff;
+ p[3] = (id >> 8) & 0xff;
+ p[4] = id & 0xff;
+ p[5 + n] = '\0';
+ p[6 + n] = SLT_ENDMARKER;
p[0] = tag;
- loghead->ptr += 5 + n;
+ loghead->ptr += 6 + n;
assert(loghead->ptr < loghead->size);
UNLOCKSHM(&vsl_mtx);
@@ -210,26 +212,27 @@
/* Truncate */
l = Tlen(t);
- if (l > 255) {
- l = 255;
+ if (l > 0xffff) {
+ l = 0xffff;
t.e = t.b + l;
}
assert(w->wlp < w->wle);
/* Wrap if necessary */
- if (w->wlp + 5 + l + 1 >= w->wle)
+ if (w->wlp + 6 + l + 1 >= w->wle)
WSL_Flush(w);
p = w->wlp;
- w->wlp += 5 + l;
+ w->wlp += 6 + l;
assert(w->wlp < w->wle);
- p[5 + l] = SLT_ENDMARKER;
+ p[6 + l] = SLT_ENDMARKER;
- p[1] = l & 0xff;
- p[2] = (id >> 8) & 0xff;
- p[3] = id & 0xff;
- memcpy(p + 4, t.b, l);
- p[4 + l] = '\0';
+ p[1] = (l >> 8) & 0xff;
+ p[2] = l & 0xff;
+ p[3] = (id >> 8) & 0xff;
+ p[4] = id & 0xff;
+ memcpy(p + 5, t.b, l);
+ p[5 + l] = '\0';
p[0] = tag;
w->wlr++;
}
@@ -248,7 +251,7 @@
va_start(ap, fmt);
if (strchr(fmt, '%') == NULL) {
- t.b = (void*)(uintptr_t)fmt;
+ t.b = (void *)(uintptr_t)fmt;
t.e = strchr(fmt, '\0');
WSLR(w, tag, id, t);
return;
@@ -257,22 +260,23 @@
assert(w->wlp < w->wle);
/* Wrap if we cannot fit a full size record */
- if (w->wlp + 5 + 255 + 1 >= w->wle)
+ if (w->wlp + 6 + 0xffff + 1 >= w->wle)
WSL_Flush(w);
p = w->wlp;
n = 0;
- n = vsnprintf((char *)(p + 4), 256, fmt, ap);
- if (n > 255)
- n = 255; /* we truncate long fields */
+ n = vsnprintf((char *)(p + 5), 0x10000, fmt, ap);
+ if (n > 0xffff)
+ n = 0xffff; /* we truncate long fields */
+ p[0] = (n >> 8) & 0xff;
p[1] = n & 0xff;
- p[2] = (id >> 8) & 0xff;
- p[3] = id & 0xff;
- p[4 + n] = '\0';;
- p[5 + n] = SLT_ENDMARKER;
+ p[3] = (id >> 8) & 0xff;
+ p[4] = id & 0xff;
+ p[5 + n] = '\0';;
+ p[6 + n] = SLT_ENDMARKER;
p[0] = tag;
- w->wlp += 5 + n;
+ w->wlp += 6 + n;
assert(w->wlp < w->wle);
w->wlr++;
va_end(ap);
_______________________________________________
varnish-misc mailing list
[email protected]
http://projects.linpro.no/mailman/listinfo/varnish-misc