Module Name: src Committed By: snj Date: Sat Jul 8 16:32:05 UTC 2017
Modified Files: src/external/bsd/dhcp/dist/relay [netbsd-7-0]: dhcrelay.c Log Message: Pull up following revision(s) (requested by manu in ticket #1430): external/bsd/dhcp/dist/relay/dhcrelay.c: revision 1.7 Fix buggy dhcrelay(8) requirement to stay in foreground This version of dhcrelay(8) needed to stay inforeground with -d flag in order to service requests. Running inbackground turned it deaf to DHCP requests. This was caused by wrong kqueue(2) usage, where kevent(2) was used with a file descriptor obtained by a kqueue(2) call done before fork(2). kqueue(2) man page says "The queue is not inherited by a child created with fork(2)". As a result, kevent(2) calls always got EBADF. The fix is to reorder function calls in dhcrelay(8) main() function. dhcp_context_create(), which causes kqueue(2) to be invoked, is moved with its dependencies after fork(2). This matches the code layout of dhclient(8) and dhcpd(8), which do not have the bug. The fix was not submitted upstream since latest ISC DHCP code was refactored and does not have the bug anymore. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.5.4.1 src/external/bsd/dhcp/dist/relay/dhcrelay.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/dhcp/dist/relay/dhcrelay.c diff -u src/external/bsd/dhcp/dist/relay/dhcrelay.c:1.5 src/external/bsd/dhcp/dist/relay/dhcrelay.c:1.5.4.1 --- src/external/bsd/dhcp/dist/relay/dhcrelay.c:1.5 Sat Jul 12 12:09:37 2014 +++ src/external/bsd/dhcp/dist/relay/dhcrelay.c Sat Jul 8 16:32:05 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: dhcrelay.c,v 1.5 2014/07/12 12:09:37 spz Exp $ */ +/* $NetBSD: dhcrelay.c,v 1.5.4.1 2017/07/08 16:32:05 snj Exp $ */ /* dhcrelay.c DHCP/BOOTP Relay Agent. */ @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: dhcrelay.c,v 1.5 2014/07/12 12:09:37 spz Exp $"); +__RCSID("$NetBSD: dhcrelay.c,v 1.5.4.1 2017/07/08 16:32:05 snj Exp $"); #include "dhcpd.h" #include <syslog.h> @@ -207,13 +207,6 @@ main(int argc, char **argv) { setlogmask(LOG_UPTO(LOG_INFO)); #endif - /* Set up the isc and dns library managers */ - status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB, - NULL, NULL); - if (status != ISC_R_SUCCESS) - log_fatal("Can't initialize context: %s", - isc_result_totext(status)); - /* Set up the OMAPI. */ status = omapi_init(); if (status != ISC_R_SUCCESS) @@ -536,17 +529,6 @@ main(int argc, char **argv) { } #endif - /* Get the current time... */ - gettimeofday(&cur_tv, NULL); - - /* Discover all the network interfaces. */ - discover_interfaces(DISCOVER_RELAY); - -#ifdef DHCPv6 - if (local_family == AF_INET6) - setup_streams(); -#endif - /* Become a daemon... */ if (!no_daemon) { int pid; @@ -587,6 +569,24 @@ main(int argc, char **argv) { IGNORE_RET (chdir("/")); } + /* Set up the isc and dns library managers */ + status = dhcp_context_create(DHCP_CONTEXT_PRE_DB | DHCP_CONTEXT_POST_DB, + NULL, NULL); + if (status != ISC_R_SUCCESS) + log_fatal("Can't initialize context: %s", + isc_result_totext(status)); + + /* Get the current time... */ + gettimeofday(&cur_tv, NULL); + + /* Discover all the network interfaces. */ + discover_interfaces(DISCOVER_RELAY); + +#ifdef DHCPv6 + if (local_family == AF_INET6) + setup_streams(); +#endif + /* Set up the packet handler... */ if (local_family == AF_INET) bootp_packet_handler = do_relay4; @@ -945,7 +945,7 @@ find_interface_by_agent_option(struct dh */ #include <sys/cdefs.h> -__RCSID("$NetBSD: dhcrelay.c,v 1.5 2014/07/12 12:09:37 spz Exp $"); +__RCSID("$NetBSD: dhcrelay.c,v 1.5.4.1 2017/07/08 16:32:05 snj Exp $"); static int add_relay_agent_options(struct interface_info *ip, struct dhcp_packet *packet, unsigned length, struct in_addr giaddr) {