Commit Diff
Diff:
806ac5983ba1a456b7111f222dcbd0613628bb23
8084b28461b5160fbab4de7fc89e81936fa2776c
Commit:
8084b28461b5160fbab4de7fc89e81936fa2776c
Tree:
61abf45cc5d8fdd4590c0f8c1bee1c62e053a472
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Sun Jul 12 20:23:37 2020 UTC
Message:
same as last patch on the struct sf_imsg, but this time on rr_imsg. This patch makes sure that rr_imsg is on a 8192 byte boundary. I'm hoping it will be cleaner.
blob - 9ce214292bd89d86ed916fa9ee39115588cf2aaa
blob + 20040db9e79918db54f8cb4647619d764a03a9f5
--- cache.c
+++ cache.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: cache.c,v 1.3 2020/07/10 10:42:27 pjp Exp $
+ * $Id: cache.c,v 1.4 2020/07/12 20:23:37 pjp Exp $
*/
#include <sys/types.h>
@@ -98,8 +98,8 @@ extern int tsig;
extern int dnssec;
extern int cache;
-int cacheit(u_char *, u_char *, u_char *, struct imsgbuf *, struct imsgbuf *, char *);
-struct scache * build_cache(u_char *, u_char *, u_char *, uint16_t, char *, int, uint32_t, uint16_t, struct imsgbuf *, struct imsgbuf *, char *);
+int cacheit(u_char *, u_char *, u_char *, struct imsgbuf *, struct imsgbuf *, struct cfg *);
+struct scache * build_cache(u_char *, u_char *, u_char *, uint16_t, char *, int, uint32_t, uint16_t, struct imsgbuf *, struct imsgbuf *, struct cfg *);
void transmit_rr(struct scache *, void *, int);
@@ -156,7 +156,7 @@ static struct cache_logic supported_cache[] = {
struct scache *
-build_cache(u_char *payload, u_char *estart, u_char *end, uint16_t rdlen, char *name, int namelen, uint32_t dnsttl, uint16_t dnstype, struct imsgbuf *imsgbuf, struct imsgbuf *bimsgbuf, char *ptr)
+build_cache(u_char *payload, u_char *estart, u_char *end, uint16_t rdlen, char *name, int namelen, uint32_t dnsttl, uint16_t dnstype, struct imsgbuf *imsgbuf, struct imsgbuf *bimsgbuf, struct cfg *cfg)
{
static struct scache ret;
@@ -171,7 +171,7 @@ build_cache(u_char *payload, u_char *estart, u_char *e
ret.rrtype = dnstype;
ret.imsgbuf = imsgbuf;
ret.bimsgbuf = bimsgbuf;
- ret.shared = ptr;
+ ret.cfg = cfg;
return (&ret);
}
@@ -180,31 +180,35 @@ void
transmit_rr(struct scache *scache, void *rr, int rrsize)
{
struct rr_imsg ri, *pri;
- int offset, i;
+ int i;
- memcpy(ri.imsg.rr.name, scache->name, sizeof(ri.imsg.rr.name));
- ri.imsg.rr.namelen = scache->namelen;
+ /* we don't fit */
+ if (rrsize > (sizeof(struct rr_imsg) - sizeof(ri.rri_rr)))
+ return;
- ri.imsg.rr.ttl = scache->dnsttl;
- ri.imsg.rr.rrtype = scache->rrtype;
+ memcpy(ri.rri_rr.name, scache->name, sizeof(ri.rri_rr.name));
+ ri.rri_rr.namelen = scache->namelen;
- memcpy(&ri.imsg.rr.un, rr, rrsize);
- ri.imsg.rr.buflen = rrsize;
- ri.read = 0;
+ ri.rri_rr.ttl = scache->dnsttl;
+ ri.rri_rr.rrtype = scache->rrtype;
+ memcpy(&ri.rri_rr.un, rr, rrsize);
+ ri.rri_rr.buflen = rrsize;
+ ri.u.s.read = 0;
+
/* wait for lock */
- while (scache->shared[0] == '*') {
+ while (scache->cfg->shptr2[scache->cfg->shptr2size - 16] == '*') {
usleep(arc4random() % 300);
}
- scache->shared[0] = '*'; /* nice semaphore eh? */
+ scache->cfg->shptr2[scache->cfg->shptr2size - 16] = '*';
- for (pri = (struct rr_imsg *)&scache->shared[16], i = 0;
+ for (pri = (struct rr_imsg *)&scache->cfg->shptr2[0], i = 0;
i < SHAREDMEMSIZE; i++, pri++) {
- if (unpack32((char *)&pri->read) == 1) {
+ if (unpack32((char *)&pri->u.s.read) == 1) {
memcpy(pri, &ri, sizeof(struct rr_imsg));
- pack32((char *)&pri->read, 0);
+ pack32((char *)&pri->u.s.read, 0);
break;
}
}
@@ -213,15 +217,11 @@ transmit_rr(struct scache *scache, void *rr, int rrsiz
dolog(LOG_INFO, "can't find an open slot in sharedmemsize\n");
}
- scache->shared[0] = ' '; /* release */
-
- offset = i;
-
-
+ scache->cfg->shptr2[scache->cfg->shptr2size - 16] = ' ';
}
int
-cacheit(u_char *payload, u_char *estart, u_char *end, struct imsgbuf *imsgbuf, struct imsgbuf *bimsgbuf, char *ptr)
+cacheit(u_char *payload, u_char *estart, u_char *end, struct imsgbuf *imsgbuf, struct imsgbuf *bimsgbuf, struct cfg *cfg)
{
struct dns_header *dh;
struct scache *scache;
@@ -295,7 +295,7 @@ cacheit(u_char *payload, u_char *estart, u_char *end,
pb += 10; /* skip answerd */
- scache = build_cache(pb, estart, end, rdlen, expand, elen, rrttl, rrtype, imsgbuf, bimsgbuf, ptr);
+ scache = build_cache(pb, estart, end, rdlen, expand, elen, rrttl, rrtype, imsgbuf, bimsgbuf, cfg);
for (cr = supported_cache; cr->rrtype != 0; cr++) {
if (rrtype == cr->rrtype) {
blob - 815d943e3d7d3c4438b13cc4a5100bf902752a0d
blob + acb7d0e7666b5fcc9bfd3fdc4e96ab6dc9a33689
--- ddd-db.h
+++ ddd-db.h
@@ -27,7 +27,7 @@
*/
/*
- * $Id: ddd-db.h,v 1.43 2020/07/12 14:44:52 pjp Exp $
+ * $Id: ddd-db.h,v 1.44 2020/07/12 20:23:37 pjp Exp $
*/
#ifndef _DB_H
@@ -443,7 +443,7 @@ struct scache {
uint16_t rrtype;
struct imsgbuf *imsgbuf;
struct imsgbuf *bimsgbuf;
- char *shared;
+ struct cfg *cfg;
};
struct cache_logic {
@@ -479,26 +479,31 @@ struct sf_imsg {
char pad[1024];
} u;
+#define sfi_sf u.s.sf
};
struct rr_imsg {
- int read;
- int len;
- char pad[12];
union {
struct {
- char name[DNS_MAXNAME + 1];
- int namelen;
- uint16_t rrtype;
- uint32_t ttl;
-
- uint16_t buflen;
+ int read; /* 4 */
+ int len; /* 8 */
+ char pad[12]; /* 20 */
- char un[7000];
- } rr;
+ struct {
+ char name[DNS_MAXNAME + 1]; /* 256 */
+ int namelen; /* 260 */
+ uint16_t rrtype; /* 262 */
+ uint32_t ttl; /* 266 */
+
+ uint16_t buflen; /* 268 */
+ char un[0];
+ } rr; /* 288 */
+ } s;
+
char pad[8192];
- } imsg;
+ } u;
+#define rri_rr u.s.rr
}; /* end of struct rr_imsg */
struct fwdpq {
blob - 4f25cce07bf60006b369cd4488a7f2d6f28e590d
blob + c9769ae530123003522a92d38929c44923aedf93
--- delphinusdnsd.c
+++ delphinusdnsd.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: delphinusdnsd.c,v 1.122 2020/07/12 14:44:52 pjp Exp $
+ * $Id: delphinusdnsd.c,v 1.123 2020/07/12 20:23:37 pjp Exp $
*/
@@ -1085,7 +1085,7 @@ main(int argc, char *argv[], char *environ[])
/* initialize */
for (sf = (struct sf_imsg *)&shptr[0], j = 0; j < SHAREDMEMSIZE; j++, sf++) {
- sf->u.s.read = 1;
+ pack32((char *)&sf->u.s.read, 1);
}
cfg->shptr = shptr;
@@ -1102,8 +1102,8 @@ main(int argc, char *argv[], char *environ[])
}
/* initialize */
- for (ri = (struct rr_imsg *)&shptr[16], j = 0; j < SHAREDMEMSIZE; j++, ri++) {
- ri->read = 1;
+ for (ri = (struct rr_imsg *)&shptr[0], j = 0; j < SHAREDMEMSIZE; j++, ri++) {
+ pack32((char *)&ri->u.s.read, 1);
}
cfg->shptr2 = shptr;
@@ -1181,12 +1181,6 @@ main(int argc, char *argv[], char *environ[])
/* shptr has no business in parse process */
minherit(cfg->shptr, cfg->shptrsize,
MAP_INHERIT_NONE);
-#if 0
- cfg->shptrsize = arc4random();
- /* disable for now */
-#endif
- cfg->shptr2size = arc4random();
- cfg->shptr3size = arc4random();
setproctitle("FORWARD engine");
forwardloop(db, cfg, ibuf, &cortex_ibuf);
@@ -1656,12 +1650,6 @@ mainloop(struct cfg *cfg, struct imsgbuf *ibuf)
MAP_INHERIT_NONE);
minherit(cfg->shptr3, cfg->shptr3size,
MAP_INHERIT_NONE);
-#if 0
- /* disable for now */
- cfg->shptrsize = arc4random();
-#endif
- cfg->shptr2size = arc4random();
- cfg->shptr3size = arc4random();
}
setproctitle("TCP engine %d", cfg->pid);
@@ -1683,12 +1671,6 @@ mainloop(struct cfg *cfg, struct imsgbuf *ibuf)
MAP_INHERIT_NONE);
minherit(cfg->shptr3, cfg->shptr3size,
MAP_INHERIT_NONE);
-#if 0
- /* disable for now */
- cfg->shptrsize = arc4random();
-#endif
- cfg->shptr2size = arc4random();
- cfg->shptr3size = arc4random();
}
sforward = (struct sforward *)calloc(1, sizeof(struct sforward));
@@ -2239,7 +2221,7 @@ forwardudp:
sforward->havemac = 0;
sforward->gotit = time(NULL);
- memcpy(&sf.u.s.sf, sforward, sizeof(struct sforward));
+ memcpy(&sf.sfi_sf, sforward, sizeof(struct sforward));
/* wait for lock */
while (cfg->shptr[cfg->shptrsize - 16] == '*') {
@@ -3298,7 +3280,7 @@ forwardtcp:
sforward->havemac = 0;
sforward->gotit = time(NULL);
- memcpy(&sf.u.s.sf, sforward, sizeof(struct sforward));
+ memcpy(&sf.sfi_sf, sforward, sizeof(struct sforward));
/* wait for lock */
while (cfg->shptr[cfg->shptrsize - 16] == '*') {
blob - 6d8f384467d05b09a3e2bfc5e466c31eb6892428
blob + 28ee26a5e893ce0380ec9cbe40e04c50e6e0ea9c
--- forward.c
+++ forward.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: forward.c,v 1.20 2020/07/12 14:44:52 pjp Exp $
+ * $Id: forward.c,v 1.21 2020/07/12 20:23:37 pjp Exp $
*/
#include <sys/types.h>
@@ -160,7 +160,7 @@ extern void build_reply(struct sreply *, int, char *,
extern struct rbtree * Lookup_zone(ddDB *, char *, int, int, int);
extern struct rbtree * lookup_zone(ddDB *, struct question *, int *, int *, char *, int);
extern char *convert_name(char *, int);
-extern int cacheit(u_char *, u_char *, u_char *, struct imsgbuf *, struct imsgbuf *, char *);
+extern int cacheit(u_char *, u_char *, u_char *, struct imsgbuf *, struct imsgbuf *, struct cfg *);
extern int reply_a(struct sreply *, ddDB *);
extern int reply_aaaa(struct sreply *, ddDB *);
@@ -651,36 +651,36 @@ drop:
memcpy(&i, imsg.data, sizeof(i));
- while (cfg->shptr2[0] == '*')
+ while (cfg->shptr2[cfg->shptr2size - 16] == '*')
usleep(arc4random() % 300);
- cfg->shptr2[0] = '*';
- ri = (struct rr_imsg *)&cfg->shptr2[16];
+ cfg->shptr2[cfg->shptr2size - 16] = '*';
+ ri = (struct rr_imsg *)&cfg->shptr2[0];
for (i = 0; i < SHAREDMEMSIZE; i++, ri++) {
- if (ri->read == 0) {
- rdata = malloc(ri->imsg.rr.buflen);
+ if (unpack32((char *)&ri->u.s.read) == 0) {
+ rdata = malloc(ri->rri_rr.buflen);
if (rdata == NULL) {
dolog(LOG_ERR, " cache insertion failed\n");
- ri->read = 1;
+ pack32((char *)&ri->u.s.read, 1);
continue;
}
- memcpy(rdata, &ri->imsg.rr.un, ri->imsg.rr.buflen);
+ memcpy(rdata, &ri->rri_rr.un, ri->rri_rr.buflen);
- if ((rbt = create_rr(db, ri->imsg.rr.name,
- ri->imsg.rr.namelen, ri->imsg.rr.rrtype,
- (void *)rdata, ri->imsg.rr.ttl)) == NULL) {
+ if ((rbt = create_rr(db, ri->rri_rr.name,
+ ri->rri_rr.namelen, ri->rri_rr.rrtype,
+ (void *)rdata, ri->rri_rr.ttl)) == NULL) {
dolog(LOG_ERR, "cache insertion failed 2\n");
free(rdata);
- ri->read = 1;
+ pack32((char *)&ri->u.s.read, 1);
continue;
}
flag_rr(rbt);
- ri->read = 1;
- } /* if ri->read == 0*/
+ pack32((char *)&ri->u.s.read, 1);
+ } /* if */
} /* for */
- cfg->shptr2[0] = ' ';
+ cfg->shptr2[cfg->shptr2size - 16] = ' ';
now = time(NULL);
@@ -2049,7 +2049,7 @@ fwdparseloop(struct imsgbuf *ibuf, struct imsgbuf *bib
rlen = tmp;
end = &packet[rlen];
- if (cacheit(packet, estart, end, ibuf, bibuf, cfg->shptr2) < 0) {
+ if (cacheit(packet, estart, end, ibuf, bibuf, cfg) < 0) {
dolog(LOG_INFO, "cacheit failed\n");
}
}
repomaster@centroid.eu