diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2015-10-16 18:47:53 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2015-10-16 18:47:53 +0000 |
commit | 8dbabbdf54f968070bc0e899d68d4f03d57488f7 (patch) | |
tree | cd5739daefc32dc2270d2ec0a036e61e8c3f97f5 /usr.sbin/rebound | |
parent | 4ed693815e29b1fede608c6fa3216a8d834ec2dd (diff) |
life is simpler if all requests go in the fifo, and then just remove them
in the error case instead of duplicating code.
Diffstat (limited to 'usr.sbin/rebound')
-rw-r--r-- | usr.sbin/rebound/rebound.c | 71 |
1 files changed, 32 insertions, 39 deletions
diff --git a/usr.sbin/rebound/rebound.c b/usr.sbin/rebound/rebound.c index e6ed797f158..dcad25a35c1 100644 --- a/usr.sbin/rebound/rebound.c +++ b/usr.sbin/rebound/rebound.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rebound.c,v 1.22 2015/10/16 18:38:53 tedu Exp $ */ +/* $OpenBSD: rebound.c,v 1.23 2015/10/16 18:47:52 tedu Exp $ */ /* * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org> * @@ -139,6 +139,32 @@ cachelookup(struct dnspacket *dnsreq, size_t reqlen) return hit; } +static void +freerequest(struct request *req) +{ + struct dnscache *ent; + + TAILQ_REMOVE(&reqfifo, req, fifo); + if (req->client != -1) + close(req->client); + if (req->s != -1) + close(req->s); + if ((ent = req->cacheent) && !ent->resp) { + free(ent->req); + free(ent); + } + free(req); +} + +static void +freecacheent(struct dnscache *ent) +{ + TAILQ_REMOVE(&cache, ent, cache); + free(ent->req); + free(ent->resp); + free(ent); +} + static struct request * newrequest(int ud, struct sockaddr *remoteaddr) { @@ -166,6 +192,7 @@ newrequest(int ud, struct sockaddr *remoteaddr) if (!(req = calloc(1, sizeof(*req)))) return NULL; + TAILQ_INSERT_TAIL(&reqfifo, req, fifo); req->ts = now; req->ts.tv_sec += 30; @@ -203,11 +230,9 @@ newrequest(int ud, struct sockaddr *remoteaddr) goto fail; return req; + fail: - free(hit); - if (req->s != -1) - close(req->s); - free(req); + freerequest(req); return NULL; } @@ -240,32 +265,6 @@ sendreply(int ud, struct request *req) } } -static void -freerequest(struct request *req) -{ - struct dnscache *ent; - - TAILQ_REMOVE(&reqfifo, req, fifo); - if (req->client != -1) - close(req->client); - if (req->s != -1) - close(req->s); - if ((ent = req->cacheent) && !ent->resp) { - free(ent->req); - free(ent); - } - free(req); -} - -static void -freecacheent(struct dnscache *ent) -{ - TAILQ_REMOVE(&cache, ent, cache); - free(ent->req); - free(ent->resp); - free(ent); -} - static struct request * tcpphasetwo(struct request *req) { @@ -299,6 +298,7 @@ newtcprequest(int ld, struct sockaddr *remoteaddr) if (!(req = calloc(1, sizeof(*req)))) return NULL; + TAILQ_INSERT_TAIL(&reqfifo, req, fifo); req->ts = now; req->ts.tv_sec += 30; @@ -318,19 +318,13 @@ newtcprequest(int ld, struct sockaddr *remoteaddr) if (errno != EINPROGRESS) goto fail; } else { - TAILQ_INSERT_TAIL(&reqfifo, req, fifo); return tcpphasetwo(req); } - TAILQ_INSERT_TAIL(&reqfifo, req, fifo); return req; fail: - if (req->s != -1) - close(req->s); - if (req->client != -1) - close(req->client); - free(req); + freerequest(req); return NULL; } @@ -433,7 +427,6 @@ launch(const char *confname, int ud, int ld, int kq) EV_SET(&chlist[0], req->s, EVFILT_READ, EV_ADD, 0, 0, NULL); kevent(kq, chlist, 1, NULL, 0, NULL); - TAILQ_INSERT_TAIL(&reqfifo, req, fifo); } } else if (kev[i].ident == ld) { req = newtcprequest(ld, |