Commit 9219b0dc authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

ban: Migrate to VRE

Bans using regular expressions will consume slightly more space, but
more importantly that breaks persistence binary compatibility. That's
not a concern because we are both planning for a major release where
that kind of breakage is acceptable, and in the context of a pcre2
migration we would also break ban persistence.

And now, VRE is the sole pcre consumer.
parent a635df72
......@@ -159,7 +159,6 @@ nobase_pkginclude_HEADERS = \
vcldir=$(datarootdir)/$(PACKAGE)/vcl
varnishd_CFLAGS = \
@PCRE_CFLAGS@ \
@SAN_CFLAGS@ \
-DNOT_IN_A_VMOD \
-DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' \
......@@ -174,7 +173,6 @@ varnishd_LDADD = \
$(top_builddir)/lib/libvgz/libvgz.a \
@SAN_LDFLAGS@ \
@JEMALLOC_LDADD@ \
@PCRE_LIBS@ \
${DL_LIBS} ${PTHREAD_LIBS} ${NET_LIBS} ${RT_LIBS} ${LIBM}
if WITH_UNWIND
......
......@@ -32,7 +32,7 @@
#include "config.h"
#include <pcre.h>
#include <stdlib.h>
#include <stdio.h>
#include "cache_varnishd.h"
......@@ -495,6 +495,7 @@ ban_evaluate(struct worker *wrk, const uint8_t *bsarg, struct objcore *oc,
const char *p;
const char *arg1;
double darg1, darg2;
int rv;
/*
* for ttl and age, fix the point in time such that banning refers to
......@@ -567,15 +568,15 @@ ban_evaluate(struct worker *wrk, const uint8_t *bsarg, struct objcore *oc,
}
break;
case BANS_OPER_MATCH:
if (arg1 == NULL ||
pcre_exec(bt.arg2_spec, NULL, arg1, strlen(arg1),
0, 0, NULL, 0) < 0)
rv = VRE_match(bt.arg2_spec, arg1, 0, 0, NULL);
xxxassert(rv >= -1);
if (arg1 == NULL || rv < 0)
return (0);
break;
case BANS_OPER_NMATCH:
if (arg1 != NULL &&
pcre_exec(bt.arg2_spec, NULL, arg1, strlen(arg1),
0, 0, NULL, 0) >= 0)
rv = VRE_match(bt.arg2_spec, arg1, 0, 0, NULL);
xxxassert(rv >= -1);
if (arg1 == NULL || rv >= 0)
return (0);
break;
case BANS_OPER_GT:
......
......@@ -55,11 +55,6 @@
* 4 bytes - be32: length
* n bytes - content
*
* In a perfect world, we should vector through VRE to get to PCRE,
* but since we rely on PCRE's ability to encode the regexp into a
* byte string, that would be a little bit artificial, so this is
* the exception that confirms the rule.
*
*/
/*--------------------------------------------------------------------
......
......@@ -32,7 +32,7 @@
#include "config.h"
#include <pcre.h>
#include <stdlib.h>
#include "cache_varnishd.h"
#include "cache_ban.h"
......@@ -40,6 +40,7 @@
#include "vend.h"
#include "vtim.h"
#include "vnum.h"
#include "vre.h"
void BAN_Build_Init(void);
void BAN_Build_Fini(void);
......@@ -187,18 +188,26 @@ ban_parse_http(const struct ban_proto *bp, const char *a1)
static const char *
ban_parse_regexp(struct ban_proto *bp, const char *a3)
{
const char *error;
int erroroffset, rc;
struct vsb vsb[1];
char errbuf[VRE_ERROR_LEN];
int errorcode, erroroffset;
size_t sz;
pcre *re;
re = pcre_compile(a3, 0, &error, &erroroffset, NULL);
if (re == NULL)
return (ban_error(bp, "Regex compile error: %s", error));
rc = pcre_fullinfo(re, NULL, PCRE_INFO_SIZE, &sz);
AZ(rc);
ban_add_lump(bp, re, sz);
pcre_free(re);
vre_t *re, *rex;
re = VRE_compile(a3, 0, &errorcode, &erroroffset, 0);
if (re == NULL) {
AN(VSB_init(vsb, errbuf, sizeof errbuf));
AZ(VRE_error(vsb, errorcode));
AZ(VSB_finish(vsb));
VSB_fini(vsb);
return (ban_error(bp, "Regex compile error: %s", errbuf));
}
rex = VRE_export(re, &sz);
AN(rex);
ban_add_lump(bp, rex, sz);
VRE_free(&rex);
VRE_free(&re);
return (0);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment