aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/dhcpd.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-03-26 13:22:35 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-03-26 13:22:35 +0000
commitaf1c84360f08f2ee32799ba266b0c384dde68173 (patch)
tree4272fbe921bc693c52197ac5d227fcbc42b3c154 /networking/udhcp/dhcpd.c
parent5a142025d372ae5dff7d7cf98f442edaafd1dc30 (diff)
downloadbusybox-af1c84360f08f2ee32799ba266b0c384dde68173.tar.gz
Move udhcp to new NOMMU helpers.
Fix server part to compile under NOMMU. Client is not compilable yet. On MMU everything compiles (and maybe even works :)
Diffstat (limited to 'networking/udhcp/dhcpd.c')
-rw-r--r--networking/udhcp/dhcpd.c78
1 files changed, 46 insertions, 32 deletions
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 90d8f0d17..ef9aa584e 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -10,6 +10,7 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
+#include <syslog.h>
#include "common.h"
#include "dhcpd.h"
#include "options.h"
@@ -33,16 +34,30 @@ int udhcpd_main(int argc, char *argv[])
struct option_set *option;
struct dhcpOfferedAddr *lease, static_lease;
+//Huh, dhcpd don't have --foreground, --syslog options?? TODO
+
+ if (!ENABLE_FEATURE_UDHCP_DEBUG) {
+ bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
+ logmode &= ~LOGMODE_STDIO;
+ }
+
+ if (ENABLE_FEATURE_UDHCP_SYSLOG) {
+ openlog(applet_name, LOG_PID, LOG_LOCAL0);
+ logmode |= LOGMODE_SYSLOG;
+ }
+
+ /* Would rather not do read_config before daemonization -
+ * otherwise NOMMU machines will parse config twice */
read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]);
- /* Start the log, sanitize fd's, and write a pid file */
- udhcp_start_log_and_pid(server_config.pidfile);
+ udhcp_make_pidfile(server_config.pidfile);
- if ((option = find_option(server_config.options, DHCP_LEASE_TIME))) {
+ option = find_option(server_config.options, DHCP_LEASE_TIME);
+ if (option) {
memcpy(&server_config.lease, option->data + 2, 4);
server_config.lease = ntohl(server_config.lease);
- }
- else server_config.lease = LEASE_TIME;
+ } else
+ server_config.lease = LEASE_TIME;
/* Sanity check */
num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1;
@@ -60,9 +75,6 @@ int udhcpd_main(int argc, char *argv[])
&server_config.server, server_config.arp) < 0)
return 1;
- if (!ENABLE_FEATURE_UDHCP_DEBUG)
- udhcp_background(server_config.pidfile); /* hold lock during fork. */
-
/* Setup the signal pipe */
udhcp_sp_setup();
@@ -106,7 +118,8 @@ int udhcpd_main(int argc, char *argv[])
default: continue; /* signal or error (probably EINTR) */
}
- if ((bytes = udhcp_get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */
+ bytes = udhcp_get_packet(&packet, server_socket); /* this waits for a packet - idle */
+ if (bytes < 0) {
if (bytes == -1 && errno != EINTR) {
DEBUG("error on read, %s, reopening socket", strerror(errno));
close(server_socket);
@@ -115,7 +128,8 @@ int udhcpd_main(int argc, char *argv[])
continue;
}
- if ((state = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) {
+ state = get_option(&packet, DHCP_MESSAGE_TYPE);
+ if (state == NULL) {
bb_error_msg("cannot get option from packet, ignoring");
continue;
}
@@ -131,7 +145,6 @@ int udhcpd_main(int argc, char *argv[])
static_lease.expires = 0;
lease = &static_lease;
-
} else {
lease = find_lease_by_chaddr(packet.chaddr);
}
@@ -157,25 +170,23 @@ int udhcpd_main(int argc, char *argv[])
if (server_id) {
/* SELECTING State */
DEBUG("server_id = %08x", ntohl(server_id_align));
- if (server_id_align == server_config.server && requested &&
- requested_align == lease->yiaddr) {
+ if (server_id_align == server_config.server && requested
+ && requested_align == lease->yiaddr
+ ) {
sendACK(&packet, lease->yiaddr);
}
+ } else if (requested) {
+ /* INIT-REBOOT State */
+ if (lease->yiaddr == requested_align)
+ sendACK(&packet, lease->yiaddr);
+ else
+ sendNAK(&packet);
+ } else if (lease->yiaddr == packet.ciaddr) {
+ /* RENEWING or REBINDING State */
+ sendACK(&packet, lease->yiaddr);
} else {
- if (requested) {
- /* INIT-REBOOT State */
- if (lease->yiaddr == requested_align)
- sendACK(&packet, lease->yiaddr);
- else sendNAK(&packet);
- } else {
- /* RENEWING or REBINDING State */
- if (lease->yiaddr == packet.ciaddr)
- sendACK(&packet, lease->yiaddr);
- else {
- /* don't know what to do!!!! */
- sendNAK(&packet);
- }
- }
+ /* don't know what to do!!!! */
+ sendNAK(&packet);
}
/* what to do if we have no record of the client */
@@ -184,19 +195,22 @@ int udhcpd_main(int argc, char *argv[])
} else if (requested) {
/* INIT-REBOOT State */
- if ((lease = find_lease_by_yiaddr(requested_align))) {
+ lease = find_lease_by_yiaddr(requested_align);
+ if (lease) {
if (lease_expired(lease)) {
/* probably best if we drop this lease */
memset(lease->chaddr, 0, 16);
/* make some contention for this address */
- } else sendNAK(&packet);
- } else if (requested_align < server_config.start ||
- requested_align > server_config.end) {
+ } else
+ sendNAK(&packet);
+ } else if (requested_align < server_config.start
+ || requested_align > server_config.end
+ ) {
sendNAK(&packet);
} /* else remain silent */
} else {
- /* RENEWING or REBINDING State */
+ /* RENEWING or REBINDING State */
}
break;
case DHCPDECLINE: