diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2017-07-03 16:36:49 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2017-07-03 16:36:49 +0000 |
commit | e26e792fc3f4608f0112b59c1767613824e61139 (patch) | |
tree | f044935e8e6bc8948c3b0b27f5ed28e16cdfd008 /usr.sbin/rebound/rebound.c | |
parent | 90fc364917c33e98c9ebee44e86dfc9385ccd749 (diff) |
don't bother caching invalid or very short lived responses
Diffstat (limited to 'usr.sbin/rebound/rebound.c')
-rw-r--r-- | usr.sbin/rebound/rebound.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/usr.sbin/rebound/rebound.c b/usr.sbin/rebound/rebound.c index 3b6d5144433..03c93332472 100644 --- a/usr.sbin/rebound/rebound.c +++ b/usr.sbin/rebound/rebound.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rebound.c,v 1.85 2017/07/03 09:39:48 tedu Exp $ */ +/* $OpenBSD: rebound.c,v 1.86 2017/07/03 16:36:48 tedu Exp $ */ /* * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org> * @@ -72,7 +72,7 @@ struct dnspacket { /* * requests will point to cache entries until a response is received. * until then, the request owns the entry and must free it. - * after it's on the list, the request must not free it. + * after the response is set, the request must not free it. */ struct dnscache { TAILQ_ENTRY(dnscache) fifo; @@ -433,16 +433,17 @@ sendreply(struct request *req) } sendto(req->client, buf, r, 0, &req->from.a, req->fromlen); if ((ent = req->cacheent)) { + /* check that the response is worth caching */ + ttl = minttl(resp, r); + if (ttl == -1 || ttl == 0) + return; /* - * we do this first, because there's a potential race against + * we do this next, because there's a potential race against * other requests made at the same time. if we lose, abort. * if anything else goes wrong, though, we need to reverse. */ if (RB_INSERT(cachetree, &cachetree, ent)) return; - ttl = minttl(resp, r); - if (ttl == -1) - ttl = 0; ent->ts = now; ent->ts.tv_sec += MINIMUM(ttl, 300); ent->resp = malloc(r); |