My first bout of untangling udhcp. Make lots of gratuitous #defines go
away, substitutie BB_VER for an external VERSION, use busybox CONFIG symbols rather than checking for them then defining others, etc. Lots more cleanup to do...
This commit is contained in:
parent
8fba99f35e
commit
3f78561d63
@ -2,27 +2,14 @@
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
|
||||
ifndef top_srcdir
|
||||
top_srcdir=../..
|
||||
endif
|
||||
ifndef top_builddir
|
||||
top_builddir=../..
|
||||
endif
|
||||
#ifndef top_srcdir
|
||||
#top_srcdir=../..
|
||||
#endif
|
||||
#ifndef top_builddir
|
||||
#top_builddir=../..
|
||||
#endif
|
||||
srcdir=$(top_srcdir)/networking/udhcp
|
||||
UDHCP_DIR:=./
|
||||
include $(top_srcdir)/Rules.mak
|
||||
|
@ -4,19 +4,7 @@
|
||||
*
|
||||
* Russ Dill <Russ.Dill@asu.edu> July 2001
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
@ -69,7 +57,7 @@ unsigned long random_xid(void)
|
||||
/* initialize a packet with the proper defaults */
|
||||
static void init_packet(struct dhcpMessage *packet, char type)
|
||||
{
|
||||
init_header(packet, type);
|
||||
udhcp_init_header(packet, type);
|
||||
memcpy(packet->chaddr, client_config.arp, 6);
|
||||
if (client_config.clientid)
|
||||
add_option_string(packet->options, client_config.clientid);
|
||||
@ -109,7 +97,7 @@ int send_discover(unsigned long xid, unsigned long requested)
|
||||
|
||||
add_requests(&packet);
|
||||
LOG(LOG_DEBUG, "Sending discover...");
|
||||
return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
||||
return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
||||
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
|
||||
}
|
||||
|
||||
@ -129,7 +117,7 @@ int send_selecting(unsigned long xid, unsigned long server, unsigned long reques
|
||||
add_requests(&packet);
|
||||
addr.s_addr = requested;
|
||||
LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr));
|
||||
return raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
||||
return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
||||
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
|
||||
}
|
||||
|
||||
@ -147,8 +135,8 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr)
|
||||
add_requests(&packet);
|
||||
LOG(LOG_DEBUG, "Sending renew...");
|
||||
if (server)
|
||||
ret = kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
|
||||
else ret = raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
||||
ret = udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
|
||||
else ret = udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
|
||||
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
|
||||
return ret;
|
||||
}
|
||||
@ -167,7 +155,7 @@ int send_release(unsigned long server, unsigned long ciaddr)
|
||||
add_simple_option(packet.options, DHCP_SERVER_ID, server);
|
||||
|
||||
LOG(LOG_DEBUG, "Sending release...");
|
||||
return kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
|
||||
return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
|
||||
}
|
||||
|
||||
|
||||
@ -212,7 +200,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
|
||||
/* check IP checksum */
|
||||
check = packet.ip.check;
|
||||
packet.ip.check = 0;
|
||||
if (check != checksum(&(packet.ip), sizeof(packet.ip))) {
|
||||
if (check != udhcp_checksum(&(packet.ip), sizeof(packet.ip))) {
|
||||
DEBUG(LOG_INFO, "bad IP header checksum, ignoring");
|
||||
return -1;
|
||||
}
|
||||
@ -228,7 +216,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
|
||||
packet.ip.saddr = source;
|
||||
packet.ip.daddr = dest;
|
||||
packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */
|
||||
if (check && check != checksum(&packet, bytes)) {
|
||||
if (check && check != udhcp_checksum(&packet, bytes)) {
|
||||
DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring");
|
||||
return -2;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ static inline void sanitize_fds(void)
|
||||
}
|
||||
|
||||
|
||||
void background(const char *pidfile)
|
||||
void udhcp_background(const char *pidfile)
|
||||
{
|
||||
#ifdef __uClinux__
|
||||
LOG(LOG_ERR, "Cannot background in uclinux (yet)");
|
||||
@ -69,7 +69,7 @@ void background(const char *pidfile)
|
||||
}
|
||||
|
||||
|
||||
#ifdef UDHCP_SYSLOG
|
||||
#ifdef CONFIG_FEATURE_UDHCP_SYSLOG
|
||||
|
||||
void udhcp_logging(int level, const char *fmt, ...)
|
||||
{
|
||||
@ -115,7 +115,7 @@ void udhcp_logging(int level, const char *fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
void start_log_and_pid(const char *client_server, const char *pidfile)
|
||||
void udhcp_start_log_and_pid(const char *client_server, const char *pidfile)
|
||||
{
|
||||
int pid_fd;
|
||||
|
||||
@ -129,9 +129,8 @@ void start_log_and_pid(const char *client_server, const char *pidfile)
|
||||
/* equivelent of doing a fflush after every \n */
|
||||
setlinebuf(stdout);
|
||||
|
||||
#ifdef UDHCP_SYSLOG
|
||||
openlog(client_server, LOG_PID | LOG_CONS, LOG_LOCAL0);
|
||||
#endif
|
||||
if (ENABLE_FEATURE_UDHCP_SYSLOG)
|
||||
openlog(client_server, LOG_PID | LOG_CONS, LOG_LOCAL0);
|
||||
|
||||
udhcp_logging(LOG_INFO, "%s (v%s) started", client_server, VERSION);
|
||||
udhcp_logging(LOG_INFO, "%s (v%s) started", client_server, BB_VER);
|
||||
}
|
||||
|
@ -3,29 +3,15 @@
|
||||
* Russ Dill <Russ.Dill@asu.edu> September 2001
|
||||
* Rewritten by Vladimir Oleynik <dzo@simtreas.ru> (C) 2003
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#ifndef _COMMON_H
|
||||
#define _COMMON_H
|
||||
|
||||
#include "version.h"
|
||||
#include "libbb_udhcp.h"
|
||||
|
||||
|
||||
#ifndef UDHCP_SYSLOG
|
||||
enum syslog_levels {
|
||||
LOG_EMERG = 0,
|
||||
LOG_ALERT,
|
||||
@ -35,18 +21,13 @@ enum syslog_levels {
|
||||
LOG_INFO,
|
||||
LOG_DEBUG
|
||||
};
|
||||
#else
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
long uptime(void);
|
||||
void background(const char *pidfile);
|
||||
void start_log_and_pid(const char *client_server, const char *pidfile);
|
||||
void udhcp_logging(int level, const char *fmt, ...);
|
||||
|
||||
#define LOG(level, str, args...) udhcp_logging(level, str, ## args)
|
||||
|
||||
#ifdef UDHCP_DEBUG
|
||||
#if ENABLE_FEATURE_UDHCP_DEBUG
|
||||
# define DEBUG(level, str, args...) LOG(level, str, ## args)
|
||||
#else
|
||||
# define DEBUG(level, str, args...) do {;} while(0)
|
||||
|
@ -27,7 +27,6 @@
|
||||
#include "options.h"
|
||||
#include "clientpacket.h"
|
||||
#include "clientsocket.h"
|
||||
#include "script.h"
|
||||
#include "socket.h"
|
||||
#include "signalpipe.h"
|
||||
|
||||
@ -120,7 +119,7 @@ static void perform_renew(void)
|
||||
state = RENEW_REQUESTED;
|
||||
break;
|
||||
case RENEW_REQUESTED: /* impatient are we? fine, square 1 */
|
||||
run_script(NULL, "deconfig");
|
||||
udhcp_run_script(NULL, "deconfig");
|
||||
case REQUESTING:
|
||||
case RELEASED:
|
||||
change_mode(LISTEN_RAW);
|
||||
@ -152,7 +151,7 @@ static void perform_release(void)
|
||||
LOG(LOG_INFO, "Unicasting a release of %s to %s",
|
||||
inet_ntoa(temp_addr), buffer);
|
||||
send_release(server_addr, requested_ip); /* unicast */
|
||||
run_script(NULL, "deconfig");
|
||||
udhcp_run_script(NULL, "deconfig");
|
||||
}
|
||||
LOG(LOG_INFO, "Entering released state");
|
||||
|
||||
@ -164,7 +163,7 @@ static void perform_release(void)
|
||||
|
||||
static void client_background(void)
|
||||
{
|
||||
background(client_config.pidfile);
|
||||
udhcp_background(client_config.pidfile);
|
||||
client_config.foreground = 1; /* Do not fork again. */
|
||||
client_config.background_if_no_lease = 0;
|
||||
}
|
||||
@ -297,7 +296,7 @@ int main(int argc, char *argv[])
|
||||
client_config.retries = atoi(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
printf("udhcpcd, version %s\n\n", VERSION);
|
||||
printf("version %s\n\n", BB_VER);
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
@ -306,7 +305,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Start the log, sanitize fd's, and write a pid file */
|
||||
start_log_and_pid("udhcpc", client_config.pidfile);
|
||||
udhcp_start_log_and_pid("udhcpc", client_config.pidfile);
|
||||
|
||||
if (read_interface(client_config.interface, &client_config.ifindex,
|
||||
NULL, client_config.arp) < 0)
|
||||
@ -322,12 +321,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (!client_config.vendorclass) {
|
||||
client_config.vendorclass = xmalloc(sizeof("udhcp "VERSION) + 2);
|
||||
client_config.vendorclass = xmalloc(sizeof("udhcp "BB_VER) + 2);
|
||||
client_config.vendorclass[OPT_CODE] = DHCP_VENDOR;
|
||||
client_config.vendorclass[OPT_LEN] = sizeof("udhcp "VERSION) - 1;
|
||||
client_config.vendorclass[OPT_LEN] = sizeof("udhcp "BB_VER) - 1;
|
||||
client_config.vendorclass[OPT_DATA] = 1;
|
||||
memcpy(&client_config.vendorclass[OPT_DATA],
|
||||
"udhcp "VERSION, sizeof("udhcp "VERSION) - 1);
|
||||
"udhcp "BB_VER, sizeof("udhcp "BB_VER) - 1);
|
||||
}
|
||||
|
||||
|
||||
@ -335,7 +334,7 @@ int main(int argc, char *argv[])
|
||||
udhcp_sp_setup();
|
||||
|
||||
state = INIT_SELECTING;
|
||||
run_script(NULL, "deconfig");
|
||||
udhcp_run_script(NULL, "deconfig");
|
||||
change_mode(LISTEN_RAW);
|
||||
|
||||
for (;;) {
|
||||
@ -375,7 +374,7 @@ int main(int argc, char *argv[])
|
||||
timeout = now + client_config.timeout;
|
||||
packet_num++;
|
||||
} else {
|
||||
run_script(NULL, "leasefail");
|
||||
udhcp_run_script(NULL, "leasefail");
|
||||
if (client_config.background_if_no_lease) {
|
||||
LOG(LOG_INFO, "No lease, forking to background.");
|
||||
client_background();
|
||||
@ -400,7 +399,7 @@ int main(int argc, char *argv[])
|
||||
packet_num++;
|
||||
} else {
|
||||
/* timed out, go back to init state */
|
||||
if (state == RENEW_REQUESTED) run_script(NULL, "deconfig");
|
||||
if (state == RENEW_REQUESTED) udhcp_run_script(NULL, "deconfig");
|
||||
state = INIT_SELECTING;
|
||||
timeout = now;
|
||||
packet_num = 0;
|
||||
@ -434,7 +433,7 @@ int main(int argc, char *argv[])
|
||||
/* timed out, enter init state */
|
||||
state = INIT_SELECTING;
|
||||
LOG(LOG_INFO, "Lease lost, entering init state");
|
||||
run_script(NULL, "deconfig");
|
||||
udhcp_run_script(NULL, "deconfig");
|
||||
timeout = now;
|
||||
packet_num = 0;
|
||||
change_mode(LISTEN_RAW);
|
||||
@ -455,7 +454,7 @@ int main(int argc, char *argv[])
|
||||
/* a packet is ready, read it */
|
||||
|
||||
if (listen_mode == LISTEN_KERNEL)
|
||||
len = get_packet(&packet, fd);
|
||||
len = udhcp_get_packet(&packet, fd);
|
||||
else len = get_raw_packet(&packet, fd);
|
||||
|
||||
if (len == -1 && errno != EINTR) {
|
||||
@ -523,7 +522,7 @@ int main(int argc, char *argv[])
|
||||
start = now;
|
||||
timeout = t1 + start;
|
||||
requested_ip = packet.yiaddr;
|
||||
run_script(&packet,
|
||||
udhcp_run_script(&packet,
|
||||
((state == RENEWING || state == REBINDING) ? "renew" : "bound"));
|
||||
|
||||
state = BOUND;
|
||||
@ -536,9 +535,9 @@ int main(int argc, char *argv[])
|
||||
} else if (*message == DHCPNAK) {
|
||||
/* return to init state */
|
||||
LOG(LOG_INFO, "Received DHCP NAK");
|
||||
run_script(&packet, "nak");
|
||||
udhcp_run_script(&packet, "nak");
|
||||
if (state != REQUESTING)
|
||||
run_script(NULL, "deconfig");
|
||||
udhcp_run_script(NULL, "deconfig");
|
||||
state = INIT_SELECTING;
|
||||
timeout = now;
|
||||
requested_ip = 0;
|
||||
|
@ -6,19 +6,7 @@
|
||||
*
|
||||
* Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
@ -66,7 +54,7 @@ int udhcpd_main(int argc, char *argv[])
|
||||
read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]);
|
||||
|
||||
/* Start the log, sanitize fd's, and write a pid file */
|
||||
start_log_and_pid("udhcpd", server_config.pidfile);
|
||||
udhcp_start_log_and_pid("udhcpd", server_config.pidfile);
|
||||
|
||||
if ((option = find_option(server_config.options, DHCP_LEASE_TIME))) {
|
||||
memcpy(&server_config.lease, option->data + 2, 4);
|
||||
@ -90,9 +78,8 @@ int udhcpd_main(int argc, char *argv[])
|
||||
&server_config.server, server_config.arp) < 0)
|
||||
return 1;
|
||||
|
||||
#ifndef UDHCP_DEBUG
|
||||
background(server_config.pidfile); /* hold lock during fork. */
|
||||
#endif
|
||||
if (!ENABLE_FEATURE_UDHCP_DEBUG)
|
||||
udhcp_background(server_config.pidfile); /* hold lock during fork. */
|
||||
|
||||
/* Setup the signal pipe */
|
||||
udhcp_sp_setup();
|
||||
@ -139,7 +126,7 @@ int udhcpd_main(int argc, char *argv[])
|
||||
default: continue; /* signal or error (probably EINTR) */
|
||||
}
|
||||
|
||||
if ((bytes = get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */
|
||||
if ((bytes = udhcp_get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */
|
||||
if (bytes == -1 && errno != EINTR) {
|
||||
DEBUG(LOG_INFO, "error on read, %m, reopening socket");
|
||||
close(server_socket);
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "libbb_udhcp.h"
|
||||
#include "leases.h"
|
||||
#include "version.h"
|
||||
|
||||
/************************************/
|
||||
/* Defaults _you_ may want to tweak */
|
||||
|
@ -241,9 +241,7 @@ static int read_staticlease(const char *const_line, void *arg)
|
||||
|
||||
addStaticLease(arg, mac_bytes, ip);
|
||||
|
||||
#ifdef UDHCP_DEBUG
|
||||
printStaticLeases(arg);
|
||||
#endif
|
||||
if (ENABLE_FEATURE_UDHCP_DEBUG) printStaticLeases(arg);
|
||||
|
||||
return 1;
|
||||
|
||||
@ -280,9 +278,6 @@ int read_config(const char *file)
|
||||
{
|
||||
FILE *in;
|
||||
char buffer[READ_CONFIG_BUF_SIZE], *token, *line;
|
||||
#ifdef UDHCP_DEBUG
|
||||
char orig[READ_CONFIG_BUF_SIZE];
|
||||
#endif
|
||||
int i, lm = 0;
|
||||
|
||||
for (i = 0; keywords[i].keyword[0]; i++)
|
||||
@ -295,11 +290,11 @@ int read_config(const char *file)
|
||||
}
|
||||
|
||||
while (fgets(buffer, READ_CONFIG_BUF_SIZE, in)) {
|
||||
char debug_orig[READ_CONFIG_BUF_SIZE];
|
||||
|
||||
lm++;
|
||||
if (strchr(buffer, '\n')) *(strchr(buffer, '\n')) = '\0';
|
||||
#ifdef UDHCP_DEBUG
|
||||
strcpy(orig, buffer);
|
||||
#endif
|
||||
if (ENABLE_FEATURE_UDHCP_DEBUG) strcpy(debug_orig, buffer);
|
||||
if (strchr(buffer, '#')) *(strchr(buffer, '#')) = '\0';
|
||||
|
||||
if (!(token = strtok(buffer, " \t"))) continue;
|
||||
@ -315,7 +310,7 @@ int read_config(const char *file)
|
||||
if (!strcasecmp(token, keywords[i].keyword))
|
||||
if (!keywords[i].handler(line, keywords[i].var)) {
|
||||
LOG(LOG_ERR, "Failure parsing line %d of %s", lm, file);
|
||||
DEBUG(LOG_ERR, "unable to parse '%s'", orig);
|
||||
DEBUG(LOG_ERR, "unable to parse '%s'", debug_orig);
|
||||
/* reset back to the default value */
|
||||
keywords[i].handler(keywords[i].def, keywords[i].var);
|
||||
}
|
||||
|
@ -6,40 +6,29 @@
|
||||
#ifndef _LIBBB_UDHCP_H
|
||||
#define _LIBBB_UDHCP_H
|
||||
|
||||
#include "packet.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#ifdef CONFIG_INSTALL_NO_USR
|
||||
# define DEFAULT_SCRIPT "/share/udhcpc/default.script"
|
||||
#else
|
||||
# define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script"
|
||||
#endif
|
||||
|
||||
#ifdef IN_BUSYBOX
|
||||
#include "busybox.h"
|
||||
|
||||
#ifdef CONFIG_FEATURE_UDHCP_SYSLOG
|
||||
#define UDHCP_SYSLOG
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FEATURE_UDHCP_DEBUG
|
||||
#define UDHCP_DEBUG
|
||||
#endif
|
||||
|
||||
#define COMBINED_BINARY
|
||||
#include "version.h"
|
||||
|
||||
#define xfopen bb_xfopen
|
||||
|
||||
/* make safe the exported namespace */
|
||||
/* from common.h */
|
||||
#define background udhcp_background
|
||||
#define start_log_and_pid udhcp_start_log_and_pid
|
||||
/* from script.h */
|
||||
#define run_script udhcp_run_script
|
||||
/* from packet.h */
|
||||
#define init_header udhcp_init_header
|
||||
#define get_packet udhcp_get_packet
|
||||
#define checksum udhcp_checksum
|
||||
#define raw_packet udhcp_raw_packet
|
||||
#define kernel_packet udhcp_kernel_packet
|
||||
void udhcp_background(const char *pidfile);
|
||||
void udhcp_start_log_and_pid(const char *client_server, const char *pidfile);
|
||||
void udhcp_logging(int level, const char *fmt, ...);
|
||||
|
||||
void udhcp_run_script(struct dhcpMessage *packet, const char *name);
|
||||
|
||||
// Still need to clean these up...
|
||||
|
||||
/* from pidfile.h */
|
||||
#define pidfile_acquire udhcp_pidfile_acquire
|
||||
#define pidfile_write_release udhcp_pidfile_write_release
|
||||
@ -57,36 +46,4 @@
|
||||
/* from dhcpd.h */
|
||||
#define server_config udhcp_server_config
|
||||
|
||||
#else /* ! IN_BUSYBOX */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/sysinfo.h>
|
||||
|
||||
#ifndef ATTRIBUTE_NORETURN
|
||||
#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
|
||||
#endif /* ATTRIBUTE_NORETURN */
|
||||
|
||||
#ifndef ATTRIBUTE_PACKED
|
||||
#define ATTRIBUTE_PACKED __attribute__ ((__packed__))
|
||||
#endif /* ATTRIBUTE_PACKED */
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#define xmalloc malloc
|
||||
#define xcalloc calloc
|
||||
|
||||
static inline FILE *xfopen(const char *file, const char *mode)
|
||||
{
|
||||
FILE *fp;
|
||||
if (!(fp = fopen(file, mode))) {
|
||||
perror("could not open input file");
|
||||
exit(0);
|
||||
}
|
||||
return fp;
|
||||
}
|
||||
|
||||
#endif /* IN_BUSYBOX */
|
||||
|
||||
#endif /* _LIBBB_UDHCP_H */
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include "options.h"
|
||||
|
||||
|
||||
void init_header(struct dhcpMessage *packet, char type)
|
||||
void udhcp_init_header(struct dhcpMessage *packet, char type)
|
||||
{
|
||||
memset(packet, 0, sizeof(struct dhcpMessage));
|
||||
switch (type) {
|
||||
@ -44,7 +44,7 @@ void init_header(struct dhcpMessage *packet, char type)
|
||||
|
||||
|
||||
/* read a packet from socket fd, return -1 on read error, -2 on packet error */
|
||||
int get_packet(struct dhcpMessage *packet, int fd)
|
||||
int udhcp_get_packet(struct dhcpMessage *packet, int fd)
|
||||
{
|
||||
static const char broken_vendors[][8] = {
|
||||
"MSFT 98",
|
||||
@ -82,7 +82,7 @@ int get_packet(struct dhcpMessage *packet, int fd)
|
||||
}
|
||||
|
||||
|
||||
uint16_t checksum(void *addr, int count)
|
||||
uint16_t udhcp_checksum(void *addr, int count)
|
||||
{
|
||||
/* Compute Internet Checksum for "count" bytes
|
||||
* beginning at location "addr".
|
||||
@ -113,7 +113,7 @@ uint16_t checksum(void *addr, int count)
|
||||
|
||||
|
||||
/* Construct a ip/udp header for a packet, and specify the source and dest hardware address */
|
||||
int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
|
||||
int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
|
||||
uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex)
|
||||
{
|
||||
int fd;
|
||||
@ -148,13 +148,13 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
|
||||
packet.udp.len = htons(sizeof(packet.udp) + sizeof(struct dhcpMessage)); /* cheat on the psuedo-header */
|
||||
packet.ip.tot_len = packet.udp.len;
|
||||
memcpy(&(packet.data), payload, sizeof(struct dhcpMessage));
|
||||
packet.udp.check = checksum(&packet, sizeof(struct udp_dhcp_packet));
|
||||
packet.udp.check = udhcp_checksum(&packet, sizeof(struct udp_dhcp_packet));
|
||||
|
||||
packet.ip.tot_len = htons(sizeof(struct udp_dhcp_packet));
|
||||
packet.ip.ihl = sizeof(packet.ip) >> 2;
|
||||
packet.ip.version = IPVERSION;
|
||||
packet.ip.ttl = IPDEFTTL;
|
||||
packet.ip.check = checksum(&(packet.ip), sizeof(packet.ip));
|
||||
packet.ip.check = udhcp_checksum(&(packet.ip), sizeof(packet.ip));
|
||||
|
||||
result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest));
|
||||
if (result <= 0) {
|
||||
@ -166,7 +166,7 @@ int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
|
||||
|
||||
|
||||
/* Let the kernel do all the work for packet generation */
|
||||
int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
|
||||
int udhcp_kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
|
||||
uint32_t dest_ip, int dest_port)
|
||||
{
|
||||
int n = 1;
|
||||
|
@ -29,12 +29,12 @@ struct udp_dhcp_packet {
|
||||
struct dhcpMessage data;
|
||||
};
|
||||
|
||||
void init_header(struct dhcpMessage *packet, char type);
|
||||
int get_packet(struct dhcpMessage *packet, int fd);
|
||||
uint16_t checksum(void *addr, int count);
|
||||
int raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
|
||||
void udhcp_init_header(struct dhcpMessage *packet, char type);
|
||||
int udhcp_get_packet(struct dhcpMessage *packet, int fd);
|
||||
uint16_t udhcp_checksum(void *addr, int count);
|
||||
int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
|
||||
uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex);
|
||||
int kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
|
||||
int udhcp_kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
|
||||
uint32_t dest_ip, int dest_port);
|
||||
|
||||
|
||||
|
@ -4,19 +4,7 @@
|
||||
*
|
||||
* Russ Dill <Russ.Dill@asu.edu> July 2001
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
@ -33,7 +21,6 @@
|
||||
#include "options.h"
|
||||
#include "dhcpd.h"
|
||||
#include "dhcpc.h"
|
||||
#include "script.h"
|
||||
|
||||
/* get a rough idea of how long an option will be (rounding up...) */
|
||||
static const int max_option_length[] = {
|
||||
@ -161,10 +148,10 @@ static char **fill_envp(struct dhcpMessage *packet)
|
||||
|
||||
envp = xzalloc(sizeof(char *) * (num_options + 5));
|
||||
j = 0;
|
||||
asprintf(&envp[j++], "interface=%s", client_config.interface);
|
||||
asprintf(&envp[j++], "%s=%s", "PATH",
|
||||
envp[j++] = bb_xasprintf("interface=%s", client_config.interface);
|
||||
envp[j++] = bb_xasprintf("PATH=%s",
|
||||
getenv("PATH") ? : "/bin:/usr/bin:/sbin:/usr/sbin");
|
||||
asprintf(&envp[j++], "%s=%s", "HOME", getenv("HOME") ? : "/");
|
||||
envp[j++] = bb_xasprintf("HOME=%s", getenv("HOME") ? : "/");
|
||||
|
||||
if (packet == NULL) return envp;
|
||||
|
||||
@ -182,7 +169,7 @@ static char **fill_envp(struct dhcpMessage *packet)
|
||||
/* Fill in a subnet bits option for things like /24 */
|
||||
if (dhcp_options[i].code == DHCP_SUBNET) {
|
||||
memcpy(&subnet, temp, 4);
|
||||
asprintf(&envp[j++], "mask=%d", mton(&subnet));
|
||||
envp[j++] = bb_xasprintf("mask=%d", mton(&subnet));
|
||||
}
|
||||
}
|
||||
if (packet->siaddr) {
|
||||
@ -192,19 +179,19 @@ static char **fill_envp(struct dhcpMessage *packet)
|
||||
if (!(over & FILE_FIELD) && packet->file[0]) {
|
||||
/* watch out for invalid packets */
|
||||
packet->file[sizeof(packet->file) - 1] = '\0';
|
||||
asprintf(&envp[j++], "boot_file=%s", packet->file);
|
||||
envp[j++] = bb_xasprintf("boot_file=%s", packet->file);
|
||||
}
|
||||
if (!(over & SNAME_FIELD) && packet->sname[0]) {
|
||||
/* watch out for invalid packets */
|
||||
packet->sname[sizeof(packet->sname) - 1] = '\0';
|
||||
asprintf(&envp[j++], "sname=%s", packet->sname);
|
||||
envp[j++] = bb_xasprintf("sname=%s", packet->sname);
|
||||
}
|
||||
return envp;
|
||||
}
|
||||
|
||||
|
||||
/* Call a script with a par file and env vars */
|
||||
void run_script(struct dhcpMessage *packet, const char *name)
|
||||
void udhcp_run_script(struct dhcpMessage *packet, const char *name)
|
||||
{
|
||||
int pid;
|
||||
char **envp, **curr;
|
||||
|
@ -1,6 +0,0 @@
|
||||
#ifndef _SCRIPT_H
|
||||
#define _SCRIPT_H
|
||||
|
||||
extern void run_script(struct dhcpMessage *packet, const char *name);
|
||||
|
||||
#endif
|
@ -36,7 +36,7 @@ static int send_packet_to_relay(struct dhcpMessage *payload)
|
||||
{
|
||||
DEBUG(LOG_INFO, "Forwarding packet to relay");
|
||||
|
||||
return kernel_packet(payload, server_config.server, SERVER_PORT,
|
||||
return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT,
|
||||
payload->giaddr, SERVER_PORT);
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas
|
||||
ciaddr = payload->yiaddr;
|
||||
chaddr = payload->chaddr;
|
||||
}
|
||||
return raw_packet(payload, server_config.server, SERVER_PORT,
|
||||
return udhcp_raw_packet(payload, server_config.server, SERVER_PORT,
|
||||
ciaddr, CLIENT_PORT, chaddr, server_config.ifindex);
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ static int send_packet(struct dhcpMessage *payload, int force_broadcast)
|
||||
|
||||
static void init_packet(struct dhcpMessage *packet, struct dhcpMessage *oldpacket, char type)
|
||||
{
|
||||
init_header(packet, type);
|
||||
udhcp_init_header(packet, type);
|
||||
packet->xid = oldpacket->xid;
|
||||
memcpy(packet->chaddr, oldpacket->chaddr, 16);
|
||||
packet->flags = oldpacket->flags;
|
||||
|
@ -93,7 +93,7 @@ uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip)
|
||||
|
||||
}
|
||||
|
||||
#ifdef UDHCP_DEBUG
|
||||
#ifdef CONFIG_FEATURE_UDHCP_DEBUG
|
||||
/* Print out static leases just to check what's going on */
|
||||
/* Takes the address of the pointer to the static_leases linked list */
|
||||
void printStaticLeases(struct static_lease **arg)
|
||||
|
@ -14,10 +14,8 @@ uint32_t getIpByMac(struct static_lease *lease_struct, void *arg);
|
||||
/* Check to see if an ip is reserved as a static ip */
|
||||
uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip);
|
||||
|
||||
#ifdef UDHCP_DEBUG
|
||||
/* Print out static leases just to check what's going on */
|
||||
/* Print out static leases just to check what's going on (debug code) */
|
||||
void printStaticLeases(struct static_lease **lease_struct);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
#ifndef _UDHCP_VERSION_H
|
||||
#define _UDHCP_VERSION_H
|
||||
|
||||
#define VERSION "0.9.9-pre"
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user