Index: dhcpd.c =================================================================== RCS file: /cvs/src/usr.sbin/dhcpd/dhcpd.c,v diff -u -p -r1.60 dhcpd.c --- dhcpd.c 21 Aug 2024 09:19:55 -0000 1.60 +++ dhcpd.c 3 Jun 2025 22:38:24 -0000 @@ -204,8 +204,7 @@ main(int argc, char *argv[]) fatal("setrtable"); if (syncsend || syncrecv) { - syncfd = sync_init(sync_iface, sync_baddr, sync_port); - if (syncfd == -1) + if (sync_init(sync_iface, sync_baddr, sync_port) == -1) err(1, "sync init"); } Index: dispatch.c =================================================================== RCS file: /cvs/src/usr.sbin/dhcpd/dispatch.c,v diff -u -p -r1.48 dispatch.c --- dispatch.c 31 May 2025 07:49:48 -0000 1.48 +++ dispatch.c 3 Jun 2025 22:38:29 -0000 @@ -67,8 +67,6 @@ #include "log.h" #include "sync.h" -extern int syncfd; - struct interface_info *interfaces; struct protocol *protocols; struct dhcpd_timeout *timeouts; @@ -305,11 +303,10 @@ dispatch(void) static struct pollfd *fds; static int nfds_max; time_t howlong; + int nifaces; for (nfds = 0, l = protocols; l; l = l->next) nfds++; - if (syncfd != -1) - nfds++; if (nfds > nfds_max) { fds = reallocarray(fds, nfds, sizeof(struct pollfd)); if (fds == NULL) @@ -348,13 +345,15 @@ another: to_msec = -1; /* Set up the descriptors to be polled. */ + nifaces = 0; for (i = 0, l = protocols; l; l = l->next) { if (l->handler == got_one) { struct interface_info *ip = l->local; if (ip->dead) { l->pfd = -1; continue; - } + } else + nifaces++; } fds[i].fd = l->fd; @@ -362,15 +361,9 @@ another: l->pfd = i++; } - if (i == 0) + if (nifaces == 0) fatalx("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: @@ -390,8 +383,6 @@ another: if (fds[i].revents & (POLLIN | POLLHUP)) l->handler(l); } - if ((syncfd != -1) && (fds[i].revents & (POLLIN | POLLHUP))) - sync_recv(); interfaces_invalidated = 0; } } Index: sync.c =================================================================== RCS file: /cvs/src/usr.sbin/dhcpd/sync.c,v diff -u -p -r1.25 sync.c --- sync.c 24 Aug 2024 08:35:24 -0000 1.25 +++ sync.c 3 Jun 2025 22:38:29 -0000 @@ -61,6 +61,7 @@ struct sync_host { }; LIST_HEAD(synchosts, sync_host) sync_hosts = LIST_HEAD_INITIALIZER(sync_hosts); +void sync_recv(struct protocol *); void sync_send(struct iovec *, int); int @@ -223,6 +224,8 @@ sync_init(const char *iface, const char sendmcast ? "" : "receive ", ttl, inet_ntoa(sync_out.sin_addr), port); + add_protocol("sync", syncfd, sync_recv, NULL); + return (syncfd); fail: @@ -231,7 +234,7 @@ sync_init(const char *iface, const char } void -sync_recv(void) +sync_recv(struct protocol *protocol) { struct dhcp_synchdr *hdr; struct sockaddr_in addr; Index: sync.h =================================================================== RCS file: /cvs/src/usr.sbin/dhcpd/sync.h,v diff -u -p -r1.5 sync.h --- sync.h 4 Oct 2016 22:47:51 -0000 1.5 +++ sync.h 3 Jun 2025 22:38:29 -0000 @@ -67,9 +67,7 @@ struct dhcp_synctlv_lease { #define DHCP_SYNC_END 0x0000 #define DHCP_SYNC_LEASE 0x0001 -extern int syncfd; extern int sync_init(const char *, const char *, u_short); extern int sync_addhost(const char *, u_short); -extern void sync_recv(void); extern void sync_lease(struct lease *); #endif /* _DHCPD_SYNC */