Commit 5eeabe7d authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

BAN_CheckObject() can pretty far with a struct objcore, so postpone

the object instantiation until needed.
parent c55468d7
...@@ -776,7 +776,7 @@ void BAN_Init(void); ...@@ -776,7 +776,7 @@ void BAN_Init(void);
void BAN_Shutdown(void); void BAN_Shutdown(void);
void BAN_NewObjCore(struct objcore *oc); void BAN_NewObjCore(struct objcore *oc);
void BAN_DestroyObj(struct objcore *oc); void BAN_DestroyObj(struct objcore *oc);
int BAN_CheckObject(const struct object *o, struct req *sp); int BAN_CheckObject(struct worker *, struct objcore *, struct req *);
void BAN_Reload(const uint8_t *ban, unsigned len); void BAN_Reload(const uint8_t *ban, unsigned len);
struct ban *BAN_TailRef(void); struct ban *BAN_TailRef(void);
void BAN_Compile(void); void BAN_Compile(void);
......
...@@ -899,19 +899,20 @@ ban_evaluate(const uint8_t *bs, const struct http *objhttp, ...@@ -899,19 +899,20 @@ ban_evaluate(const uint8_t *bs, const struct http *objhttp,
* 1 Ban matched, object removed from ban list. * 1 Ban matched, object removed from ban list.
*/ */
static int int
ban_check_object(const struct object *o, struct vsl_log *vsl, BAN_CheckObject(struct worker *wrk, struct objcore *oc, struct req *req)
const struct http *req_http)
{ {
struct ban *b; struct ban *b;
struct objcore *oc; struct vsl_log *vsl;
struct object *o;
struct ban * volatile b0; struct ban * volatile b0;
unsigned tests; unsigned tests;
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
CHECK_OBJ_NOTNULL(req_http, HTTP_MAGIC);
oc = o->objcore;
CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC); CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
vsl = req->vsl;
CHECK_OBJ_NOTNULL(oc->ban, BAN_MAGIC); CHECK_OBJ_NOTNULL(oc->ban, BAN_MAGIC);
/* First do an optimistic unlocked check */ /* First do an optimistic unlocked check */
...@@ -929,6 +930,10 @@ ban_check_object(const struct object *o, struct vsl_log *vsl, ...@@ -929,6 +930,10 @@ ban_check_object(const struct object *o, struct vsl_log *vsl,
if (b0 == oc->ban) if (b0 == oc->ban)
return (0); return (0);
/* Now we need the object */
o = ObjGetObj(oc, &wrk->stats);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
/* /*
* This loop is safe without locks, because we know we hold * This loop is safe without locks, because we know we hold
* a refcount on a ban somewhere in the list and we do not * a refcount on a ban somewhere in the list and we do not
...@@ -939,7 +944,7 @@ ban_check_object(const struct object *o, struct vsl_log *vsl, ...@@ -939,7 +944,7 @@ ban_check_object(const struct object *o, struct vsl_log *vsl,
CHECK_OBJ_NOTNULL(b, BAN_MAGIC); CHECK_OBJ_NOTNULL(b, BAN_MAGIC);
if (b->flags & BANS_FLAG_COMPLETED) if (b->flags & BANS_FLAG_COMPLETED)
continue; continue;
if (ban_evaluate(b->spec, o->http, req_http, &tests)) if (ban_evaluate(b->spec, o->http, req->http, &tests))
break; break;
} }
...@@ -969,13 +974,6 @@ ban_check_object(const struct object *o, struct vsl_log *vsl, ...@@ -969,13 +974,6 @@ ban_check_object(const struct object *o, struct vsl_log *vsl,
} }
} }
int
BAN_CheckObject(const struct object *o, struct req *req)
{
return (ban_check_object(o, req->vsl, req->http) > 0);
}
static void static void
ban_cleantail(void) ban_cleantail(void)
{ {
......
...@@ -423,11 +423,12 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp, ...@@ -423,11 +423,12 @@ HSH_Lookup(struct req *req, struct objcore **ocp, struct objcore **bocp,
if (oc->exp.ttl <= 0.) if (oc->exp.ttl <= 0.)
continue; continue;
if (BAN_CheckObject(wrk, oc, req))
continue;
o = ObjGetObj(oc, &wrk->stats); o = ObjGetObj(oc, &wrk->stats);
CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC); CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
if (BAN_CheckObject(o, req))
continue;
if (o->vary != NULL && !VRY_Match(req, o->vary)) if (o->vary != NULL && !VRY_Match(req, o->vary))
continue; continue;
......
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