Commit Diff
Diff:
88afe3e8b7970dacfb9db3afcc2a70fc3d68505e
6a317355af361945c1164c80ad0a3913ed177da0
Commit:
6a317355af361945c1164c80ad0a3913ed177da0
Tree:
707a188551affbb2b130069d5f7dea28994ecd28
Author:
pjp <pjp@delphinusdns.org>
Committer:
pjp <pjp@delphinusdns.org>
Date:
Sat Jul 4 08:25:28 2020 UTC
Message:
forwarders could end up in a corner of the TAILQ, so we stir (randomly) the active forwarders every 1000 packets, this should better the forwarding strategy.
blob - 63136f068f1abc3617e46d6484dfab000a4c3df7
blob + fd02f0444bbb3f911fef68015344abf0d79c60eb
--- forward.c
+++ forward.c
@@ -27,7 +27,7 @@
*/
/*
- * $Id: forward.c,v 1.10 2020/07/04 07:22:58 pjp Exp $
+ * $Id: forward.c,v 1.11 2020/07/04 08:25:28 pjp Exp $
*/
#include <sys/types.h>
@@ -142,6 +142,7 @@ void returnit(struct cfg *cfg, struct forwardqueue *,
struct tsig * check_tsig(char *, int, char *);
void fwdparseloop(struct imsgbuf *);
void changeforwarder(struct forwardqueue *);
+void stirforwarders(void);
extern void dolog(int, char *, ...);
extern void pack16(char *, u_int16_t);
@@ -238,6 +239,7 @@ forwardloop(ddDB *db, struct cfg *cfg, struct imsgbuf
int len, need;
int pi[2];
int i;
+ u_int packetcount = 0;
ssize_t n, datalen;
fd_set rset;
@@ -286,6 +288,13 @@ forwardloop(ddDB *db, struct cfg *cfg, struct imsgbuf
}
for (;;) {
+ /*
+ * due to our strategy (which kinda sucks) stir some
+ * entropy into the active forwarder
+ */
+ if (packetcount++ && packetcount % 1000 == 0)
+ stirforwarders();
+
FD_ZERO(&rset);
FD_SET(ibuf->fd, &rset);
if (ibuf->fd > max)
@@ -1473,4 +1482,28 @@ changeforwarder(struct forwardqueue *fwq)
}
return;
+}
+
+void
+stirforwarders(void)
+{
+ int randomforwarder;
+ int count = 0;
+
+ TAILQ_FOREACH(fwp, &forwardhead, forward_entry) {
+ fwp->active = 0;
+ count++;
+ }
+
+ randomforwarder = arc4random() % count;
+
+ count = 0;
+ TAILQ_FOREACH(fwp, &forwardhead, forward_entry) {
+ if (randomforwarder == count) {
+ dolog(LOG_INFO, "stirforwarders: %s is now active\n", fwp->name);
+ fwp->active = 1;
+ }
+
+ count++;
+ }
}
repomaster@centroid.eu