summaryrefslogtreecommitdiff
path: root/usr.sbin/dhcpd/dispatch.c
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>2008-05-07 12:19:21 +0000
committerBob Beck <beck@cvs.openbsd.org>2008-05-07 12:19:21 +0000
commite1fc87c003c10d05e80ad1c139ab591e6ec003a4 (patch)
tree681364a876ff6c24d7dfaf815a57f4d1d1b536e4 /usr.sbin/dhcpd/dispatch.c
parent35b114188dc363874554d6bc92858cb8a2710888 (diff)
Add synchronisation support for dhcpd - this allows for two dhcpd's
with the same configuration to be run on the same net and they will keep their lease files/state in synch, and therefore allowing you to run redundant dhcpd's. Synchronization code stolen from spamd, uses an hmac key in /var/db/dhcpd.key if it exists. ok krw@ deraadt@
Diffstat (limited to 'usr.sbin/dhcpd/dispatch.c')
-rw-r--r--usr.sbin/dhcpd/dispatch.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/usr.sbin/dhcpd/dispatch.c b/usr.sbin/dhcpd/dispatch.c
index 1d371e3c153..35bedebdbef 100644
--- a/usr.sbin/dhcpd/dispatch.c
+++ b/usr.sbin/dhcpd/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.22 2006/12/12 19:38:55 stevesk Exp $ */
+/* $OpenBSD: dispatch.c,v 1.23 2008/05/07 12:19:20 beck Exp $ */
/*
* Copyright (c) 1995, 1996, 1997, 1998, 1999
@@ -39,11 +39,14 @@
*/
#include "dhcpd.h"
+#include "sync.h"
#include <ifaddrs.h>
#include <sys/ioctl.h>
#include <poll.h>
#include <net/if_media.h>
+extern int syncfd;
+
struct interface_info *interfaces;
struct protocol *protocols;
struct dhcpd_timeout *timeouts;
@@ -273,6 +276,8 @@ dispatch(void)
for (nfds = 0, l = protocols; l; l = l->next)
nfds++;
+ if (syncfd != -1)
+ nfds++;
if (nfds > nfds_max) {
fds = realloc(fds, nfds * sizeof(struct pollfd));
if (fds == NULL)
@@ -321,9 +326,16 @@ another:
++i;
}
}
+
if (i == 0)
error("No live interfaces to poll on - exiting.");
+ if (syncfd != -1) {
+ /* add syncer */
+ fds[i].fd = syncfd;
+ fds[i].events = POLLIN;
+ }
+
/* Wait for a packet or a timeout... */
switch (poll(fds, nfds, to_msec)) {
case -1:
@@ -346,6 +358,8 @@ another:
}
++i;
}
+ if ((syncfd != -1) && (fds[i].revents & (POLLIN | POLLHUP)))
+ sync_recv();
interfaces_invalidated = 0;
}
}