aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-11-18 19:51:32 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-11-18 19:51:32 +0000
commit5a3395bc01cd4b11309595a6ecdaf32f8279f378 (patch)
tree1e63aa591a05e9ec75aefdcd639ca4188e583648
parentabfc4cf6d8b9c59724aceb70df5081a1368fdb62 (diff)
downloadbusybox-5a3395bc01cd4b11309595a6ecdaf32f8279f378.tar.gz
udhcp: fix indentation and style.
Eliminate (group) a lot of smallish *.h files Remove lots of unneeded #includes
-rw-r--r--networking/udhcp/arpping.c29
-rw-r--r--networking/udhcp/arpping.h36
-rw-r--r--networking/udhcp/clientpacket.c28
-rw-r--r--networking/udhcp/clientpacket.h15
-rw-r--r--networking/udhcp/clientsocket.c10
-rw-r--r--networking/udhcp/clientsocket.h8
-rw-r--r--networking/udhcp/common.c13
-rw-r--r--networking/udhcp/common.h89
-rw-r--r--networking/udhcp/dhcpc.c17
-rw-r--r--networking/udhcp/dhcpc.h15
-rw-r--r--networking/udhcp/dhcpd.c34
-rw-r--r--networking/udhcp/dhcpd.h61
-rw-r--r--networking/udhcp/dumpleases.c29
-rw-r--r--networking/udhcp/files.c21
-rw-r--r--networking/udhcp/files.h20
-rw-r--r--networking/udhcp/leases.c42
-rw-r--r--networking/udhcp/leases.h24
-rw-r--r--networking/udhcp/libbb_udhcp.h47
-rw-r--r--networking/udhcp/options.c4
-rw-r--r--networking/udhcp/options.h2
-rw-r--r--networking/udhcp/packet.c32
-rw-r--r--networking/udhcp/packet.h42
-rw-r--r--networking/udhcp/pidfile.c9
-rw-r--r--networking/udhcp/pidfile.h26
-rw-r--r--networking/udhcp/script.c15
-rw-r--r--networking/udhcp/serverpacket.c111
-rw-r--r--networking/udhcp/serverpacket.h13
-rw-r--r--networking/udhcp/signalpipe.c10
-rw-r--r--networking/udhcp/signalpipe.h23
-rw-r--r--networking/udhcp/socket.c75
-rw-r--r--networking/udhcp/socket.h9
-rw-r--r--networking/udhcp/static_leases.c41
-rw-r--r--networking/udhcp/static_leases.h24
33 files changed, 332 insertions, 642 deletions
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c
index 2716a28c6..471e36d62 100644
--- a/networking/udhcp/arpping.c
+++ b/networking/udhcp/arpping.c
@@ -6,18 +6,31 @@
* by Yoichi Hariguchi <yoichi@fore.com>
*/
-#include <time.h>
-#include <sys/socket.h>
#include <netinet/if_ether.h>
#include <net/if_arp.h>
-#include <netinet/in.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include "dhcpd.h"
-#include "arpping.h"
#include "common.h"
+#include "dhcpd.h"
+
+
+struct arpMsg {
+ /* Ethernet header */
+ u_char h_dest[6]; /* destination ether addr */
+ u_char h_source[6]; /* source ether addr */
+ u_short h_proto; /* packet type ID field */
+
+ /* ARP packet */
+ uint16_t htype; /* hardware type (must be ARPHRD_ETHER) */
+ uint16_t ptype; /* protocol type (must be ETH_P_IP) */
+ uint8_t hlen; /* hardware address length (must be 6) */
+ uint8_t plen; /* protocol address length (must be 4) */
+ uint16_t operation; /* ARP opcode */
+ uint8_t sHaddr[6]; /* sender's hardware address */
+ uint8_t sInaddr[4]; /* sender's IP address */
+ uint8_t tHaddr[6]; /* target's hardware address */
+ uint8_t tInaddr[4]; /* target's IP address */
+ uint8_t pad[18]; /* pad for min. Ethernet payload (60 bytes) */
+} ATTRIBUTE_PACKED;
/* args: yiaddr - what IP to ping
* ip - our ip
diff --git a/networking/udhcp/arpping.h b/networking/udhcp/arpping.h
deleted file mode 100644
index 2990e30f6..000000000
--- a/networking/udhcp/arpping.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * arpping .h
- */
-
-#ifndef ARPPING_H
-#define ARPPING_H
-
-#include <netinet/if_ether.h>
-#include <net/if_arp.h>
-#include <net/if.h>
-#include <netinet/in.h>
-
-struct arpMsg {
- /* Ethernet header */
- u_char h_dest[6]; /* destination ether addr */
- u_char h_source[6]; /* source ether addr */
- u_short h_proto; /* packet type ID field */
-
- /* ARP packet */
- uint16_t htype; /* hardware type (must be ARPHRD_ETHER) */
- uint16_t ptype; /* protocol type (must be ETH_P_IP) */
- uint8_t hlen; /* hardware address length (must be 6) */
- uint8_t plen; /* protocol address length (must be 4) */
- uint16_t operation; /* ARP opcode */
- uint8_t sHaddr[6]; /* sender's hardware address */
- uint8_t sInaddr[4]; /* sender's IP address */
- uint8_t tHaddr[6]; /* target's hardware address */
- uint8_t tInaddr[4]; /* target's IP address */
- uint8_t pad[18]; /* pad for min. Ethernet payload (60 bytes) */
-} ATTRIBUTE_PACKED;
-
-/* function prototypes */
-int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *arp, char *interface);
-
-#endif
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index 4299c2dbd..15cbda2f5 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -8,8 +8,6 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <string.h>
-#include <sys/socket.h>
#include <features.h>
#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
#include <netpacket/packet.h>
@@ -19,19 +17,11 @@
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#endif
-#include <stdlib.h>
-#include <time.h>
-#include <unistd.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <fcntl.h>
-
+#include "common.h"
#include "dhcpd.h"
-#include "clientpacket.h"
-#include "options.h"
#include "dhcpc.h"
-#include "common.h"
+#include "options.h"
/* Create a random xid */
@@ -59,7 +49,7 @@ static void init_packet(struct dhcpMessage *packet, char 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);
+ add_option_string(packet->options, client_config.clientid);
if (client_config.hostname) add_option_string(packet->options, client_config.hostname);
if (client_config.fqdn) add_option_string(packet->options, client_config.fqdn);
add_option_string(packet->options, client_config.vendorclass);
@@ -97,7 +87,7 @@ int send_discover(unsigned long xid, unsigned long requested)
add_requests(&packet);
bb_info_msg("Sending discover...");
return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
- SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
+ SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
}
@@ -188,10 +178,12 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
bytes = ntohs(packet.ip.tot_len);
/* Make sure its the right packet for us, and that it passes sanity checks */
- if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION ||
- packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) ||
- bytes > (int) sizeof(struct udp_dhcp_packet) ||
- ntohs(packet.udp.len) != (uint16_t) (bytes - sizeof(packet.ip))) {
+ if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION
+ || packet.ip.ihl != sizeof(packet.ip) >> 2
+ || packet.udp.dest != htons(CLIENT_PORT)
+ || bytes > (int) sizeof(struct udp_dhcp_packet)
+ || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip))
+ ) {
DEBUG("Unrelated/bogus packet");
return -2;
}
diff --git a/networking/udhcp/clientpacket.h b/networking/udhcp/clientpacket.h
deleted file mode 100644
index b9b9a668f..000000000
--- a/networking/udhcp/clientpacket.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* vi: set sw=4 ts=4: */
-#ifndef _CLIENTPACKET_H
-#define _CLIENTPACKET_H
-
-#include "packet.h"
-
-unsigned long random_xid(void);
-int send_discover(unsigned long xid, unsigned long requested);
-int send_selecting(unsigned long xid, unsigned long server, unsigned long requested);
-int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
-int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
-int send_release(unsigned long server, unsigned long ciaddr);
-int get_raw_packet(struct dhcpMessage *payload, int fd);
-
-#endif
diff --git a/networking/udhcp/clientsocket.c b/networking/udhcp/clientsocket.c
index 6aa61754d..852061968 100644
--- a/networking/udhcp/clientsocket.c
+++ b/networking/udhcp/clientsocket.c
@@ -21,10 +21,6 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <netinet/in.h>
#include <features.h>
#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION)
#include <netpacket/packet.h>
@@ -35,7 +31,6 @@
#include <linux/if_ether.h>
#endif
-#include "clientsocket.h"
#include "common.h"
@@ -45,7 +40,8 @@ int raw_socket(int ifindex)
struct sockaddr_ll sock;
DEBUG("Opening raw socket on ifindex %d", ifindex);
- if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
+ fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
+ if (fd < 0) {
bb_perror_msg("socket");
return -1;
}
@@ -54,7 +50,7 @@ int raw_socket(int ifindex)
sock.sll_protocol = htons(ETH_P_IP);
sock.sll_ifindex = ifindex;
if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) {
- bb_perror_msg("bind:");
+ bb_perror_msg("bind");
close(fd);
return -1;
}
diff --git a/networking/udhcp/clientsocket.h b/networking/udhcp/clientsocket.h
deleted file mode 100644
index ea6078397..000000000
--- a/networking/udhcp/clientsocket.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/* clientsocket.h */
-#ifndef _CLIENTSOCKET_H
-#define _CLIENTSOCKET_H
-
-int raw_socket(int ifindex);
-
-#endif
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index a0a21fdce..4c18e5d51 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -10,23 +10,11 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <paths.h>
-#include <sys/socket.h>
-#include <stdarg.h>
#include <syslog.h>
#include "common.h"
-#include "pidfile.h"
-static int daemonized;
-
long uptime(void)
{
struct sysinfo info;
@@ -61,7 +49,6 @@ void udhcp_background(const char *pidfile)
pid_fd = pidfile_acquire(pidfile);
setsid();
xdaemon(0, 0);
- daemonized++;
logmode &= ~LOGMODE_STDIO;
pidfile_write_release(pid_fd);
#endif /* __uClinux__ */
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index d5291f2f3..70a769342 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -10,14 +10,99 @@
#ifndef _COMMON_H
#define _COMMON_H
-#include "libbb_udhcp.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
+
+#define COMBINED_BINARY
+
+
+/*** packet.h ***/
+
+#include <netinet/udp.h>
+#include <netinet/ip.h>
+
+struct dhcpMessage {
+ uint8_t op;
+ uint8_t htype;
+ uint8_t hlen;
+ uint8_t hops;
+ uint32_t xid;
+ uint16_t secs;
+ uint16_t flags;
+ uint32_t ciaddr;
+ uint32_t yiaddr;
+ uint32_t siaddr;
+ uint32_t giaddr;
+ uint8_t chaddr[16];
+ uint8_t sname[64];
+ uint8_t file[128];
+ uint32_t cookie;
+ uint8_t options[308]; /* 312 - cookie */
+};
+
+struct udp_dhcp_packet {
+ struct iphdr ip;
+ struct udphdr udp;
+ struct dhcpMessage data;
+};
+
+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 udhcp_kernel_packet(struct dhcpMessage *payload,
+ uint32_t source_ip, int source_port,
+ uint32_t dest_ip, int dest_port);
+
+
+/**/
+
+void udhcp_background(const char *pidfile);
+void udhcp_start_log_and_pid(const char *pidfile);
+
+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
+/* from options.h */
+#define get_option udhcp_get_option
+#define end_option udhcp_end_option
+#define add_option_string udhcp_add_option_string
+#define add_simple_option udhcp_add_simple_option
+#define option_lengths udhcp_option_lengths
+/* from socket.h */
+#define listen_socket udhcp_listen_socket
+#define read_interface udhcp_read_interface
+/* from dhcpc.h */
+#define client_config udhcp_client_config
+/* from dhcpd.h */
+#define server_config udhcp_server_config
long uptime(void);
+void udhcp_sp_setup(void);
+int udhcp_sp_fd_set(fd_set *rfds, int extra_fd);
+int udhcp_sp_read(fd_set *rfds);
+int raw_socket(int ifindex);
+int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp);
+int listen_socket(uint32_t ip, int port, char *inf);
+int pidfile_acquire(const char *pidfile);
+void pidfile_write_release(int pid_fd);
+int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *arp, char *interface);
#if ENABLE_FEATURE_UDHCP_DEBUG
# define DEBUG(str, args...) bb_info_msg(str, ## args)
#else
-# define DEBUG(str, args...) do {;} while(0)
+# define DEBUG(str, args...) do {;} while (0)
#endif
#endif
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index e2ddf4fb1..4ccd8ec34 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -8,28 +8,13 @@
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <sys/file.h>
-#include <unistd.h>
#include <getopt.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <signal.h>
-#include <time.h>
-#include <string.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <errno.h>
#include "common.h"
#include "dhcpd.h"
#include "dhcpc.h"
#include "options.h"
-#include "clientpacket.h"
-#include "clientsocket.h"
-#include "socket.h"
-#include "signalpipe.h"
+
static int state;
/* Something is definitely wrong here. IPv4 addresses
diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h
index 6cf59a950..d5c8a4ba5 100644
--- a/networking/udhcp/dhcpc.h
+++ b/networking/udhcp/dhcpc.h
@@ -3,9 +3,6 @@
#ifndef _DHCPC_H
#define _DHCPC_H
-/* grab define DEFAULT_SCRIPT */
-#include "libbb_udhcp.h"
-
#define INIT_SELECTING 0
#define REQUESTING 1
#define BOUND 2
@@ -15,7 +12,6 @@
#define RENEW_REQUESTED 6
#define RELEASED 7
-
struct client_config_t {
char foreground; /* Do not fork */
char quit_after_lease; /* Quit after obtaining lease */
@@ -38,4 +34,15 @@ struct client_config_t {
extern struct client_config_t client_config;
+/*** clientpacket.h ***/
+
+unsigned long random_xid(void);
+int send_discover(unsigned long xid, unsigned long requested);
+int send_selecting(unsigned long xid, unsigned long server, unsigned long requested);
+int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
+int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
+int send_release(unsigned long server, unsigned long ciaddr);
+int get_raw_packet(struct dhcpMessage *payload, int fd);
+
+
#endif
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index 62057bed8..0935a9453 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -10,29 +10,9 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <fcntl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/wait.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <unistd.h>
-#include <signal.h>
-#include <errno.h>
-#include <sys/ioctl.h>
-#include <time.h>
-
+#include "common.h"
#include "dhcpd.h"
-#include "arpping.h"
-#include "socket.h"
#include "options.h"
-#include "files.h"
-#include "serverpacket.h"
-#include "common.h"
-#include "signalpipe.h"
-#include "static_leases.h"
/* globals */
@@ -86,7 +66,7 @@ int udhcpd_main(int argc, char *argv[])
udhcp_sp_setup();
timeout_end = time(0) + server_config.auto_time;
- while(1) { /* loop until universe collapses */
+ while (1) { /* loop until universe collapses */
if (server_socket < 0)
if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) {
@@ -144,8 +124,7 @@ int udhcpd_main(int argc, char *argv[])
/* Look for a static lease */
static_lease_ip = getIpByMac(server_config.static_leases, &packet.chaddr);
- if(static_lease_ip)
- {
+ if (static_lease_ip) {
bb_info_msg("Found static lease: %x", static_lease_ip);
memcpy(&static_lease.chaddr, &packet.chaddr, 16);
@@ -154,10 +133,8 @@ int udhcpd_main(int argc, char *argv[])
lease = &static_lease;
- }
- else
- {
- lease = find_lease_by_chaddr(packet.chaddr);
+ } else {
+ lease = find_lease_by_chaddr(packet.chaddr);
}
switch (state[0]) {
@@ -245,4 +222,3 @@ int udhcpd_main(int argc, char *argv[])
return 0;
}
-
diff --git a/networking/udhcp/dhcpd.h b/networking/udhcp/dhcpd.h
index dc8f3c427..40959e4ae 100644
--- a/networking/udhcp/dhcpd.h
+++ b/networking/udhcp/dhcpd.h
@@ -3,12 +3,6 @@
#ifndef _DHCPD_H
#define _DHCPD_H
-#include <netinet/ip.h>
-#include <netinet/udp.h>
-
-#include "libbb_udhcp.h"
-#include "leases.h"
-
/************************************/
/* Defaults _you_ may want to tweak */
/************************************/
@@ -138,4 +132,59 @@ extern struct server_config_t server_config;
extern struct dhcpOfferedAddr *leases;
+/*** leases.h ***/
+
+struct dhcpOfferedAddr {
+ uint8_t chaddr[16];
+ uint32_t yiaddr; /* network order */
+ uint32_t expires; /* host order */
+};
+
+extern uint8_t blank_chaddr[];
+
+void clear_lease(uint8_t *chaddr, uint32_t yiaddr);
+struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease);
+int lease_expired(struct dhcpOfferedAddr *lease);
+struct dhcpOfferedAddr *oldest_expired_lease(void);
+struct dhcpOfferedAddr *find_lease_by_chaddr(uint8_t *chaddr);
+struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr);
+uint32_t find_address(int check_expired);
+
+
+/*** static_leases.h ***/
+
+/* Config file will pass static lease info to this function which will add it
+ * to a data structure that can be searched later */
+int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip);
+/* Check to see if a mac has an associated static lease */
+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);
+/* Print out static leases just to check what's going on (debug code) */
+void printStaticLeases(struct static_lease **lease_struct);
+
+
+/*** serverpacket.h ***/
+
+int sendOffer(struct dhcpMessage *oldpacket);
+int sendNAK(struct dhcpMessage *oldpacket);
+int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr);
+int send_inform(struct dhcpMessage *oldpacket);
+
+
+/*** files.h ***/
+
+struct config_keyword {
+ const char *keyword;
+ int (* const handler)(const char *line, void *var);
+ void *var;
+ const char *def;
+};
+
+int read_config(const char *file);
+void write_leases(void);
+void read_leases(const char *file);
+struct option_set *find_option(struct option_set *opt_list, char code);
+
+
#endif
diff --git a/networking/udhcp/dumpleases.c b/networking/udhcp/dumpleases.c
index 60e6b7edf..4422d3099 100644
--- a/networking/udhcp/dumpleases.c
+++ b/networking/udhcp/dumpleases.c
@@ -2,23 +2,11 @@
/*
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
-#include <fcntl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <sys/wait.h>
-#include <arpa/inet.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <stdio.h>
-#include <sys/socket.h>
-#include <unistd.h>
#include <getopt.h>
-#include <time.h>
+#include "common.h"
#include "dhcpd.h"
-#include "leases.h"
-#include "libbb_udhcp.h"
+
#define REMAINING 0
#define ABSOLUTE 1
@@ -60,17 +48,16 @@ int dumpleases_main(int argc, char *argv[])
printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at");
/* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */
while (fread(&lease, sizeof(lease), 1, fp)) {
-
- for (i = 0; i < 6; i++) {
- printf("%02x", lease.chaddr[i]);
- if (i != 5) printf(":");
+ printf(":%02x"+1, lease.chaddr[0]);
+ for (i = 1; i < 6; i++) {
+ printf(":%02x", lease.chaddr[i]);
}
addr.s_addr = lease.yiaddr;
- printf(" %-15s", inet_ntoa(addr));
+ printf(" %-15s ", inet_ntoa(addr));
expires = ntohl(lease.expires);
- printf(" ");
if (mode == REMAINING) {
- if (!expires) printf("expired\n");
+ if (!expires)
+ printf("expired\n");
else {
if (expires > 60*60*24) {
printf("%ld days, ", expires / (60*60*24));
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index 36bcc31d9..317e861c0 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -4,21 +4,12 @@
* Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
*/
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <ctype.h>
-#include <netdb.h>
-
#include <netinet/ether.h>
-#include "static_leases.h"
+#include "common.h"
#include "dhcpd.h"
#include "options.h"
-#include "files.h"
-#include "common.h"
+
/*
* Domain names may have 254 chars, and string options can be 254
@@ -51,7 +42,7 @@ static int read_mac(const char *line, void *arg)
temp_ether_addr = ether_aton(line);
- if(temp_ether_addr == NULL)
+ if (temp_ether_addr == NULL)
retval = 0;
else
memcpy(mac_bytes, temp_ether_addr, 6);
@@ -217,7 +208,6 @@ static int read_opt(const char *const_line, void *arg)
static int read_staticlease(const char *const_line, void *arg)
{
-
char *line;
char *mac_string;
char *ip_string;
@@ -243,7 +233,6 @@ static int read_staticlease(const char *const_line, void *arg)
if (ENABLE_FEATURE_UDHCP_DEBUG) printStaticLeases(arg);
return 1;
-
}
@@ -308,9 +297,9 @@ int read_config(const char *file)
for (i = 0; keywords[i].keyword[0]; i++)
if (!strcasecmp(token, keywords[i].keyword))
if (!keywords[i].handler(line, keywords[i].var)) {
- bb_error_msg("failure parsing line %d of %s", lm, file);
+ bb_error_msg("cannot parse line %d of %s", lm, file);
if (ENABLE_FEATURE_UDHCP_DEBUG)
- bb_error_msg("unable to parse '%s'", debug_orig);
+ bb_error_msg("cannot parse '%s'", debug_orig);
/* reset back to the default value */
keywords[i].handler(keywords[i].def, keywords[i].var);
}
diff --git a/networking/udhcp/files.h b/networking/udhcp/files.h
deleted file mode 100644
index 884693117..000000000
--- a/networking/udhcp/files.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/* files.h */
-#ifndef _FILES_H
-#define _FILES_H
-
-struct config_keyword {
- const char *keyword;
- int (* const handler)(const char *line, void *var);
- void *var;
- const char *def;
-};
-
-
-int read_config(const char *file);
-void write_leases(void);
-void read_leases(const char *file);
-
-struct option_set *find_option(struct option_set *opt_list, char code);
-
-#endif
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c
index f5113408b..2f7847d74 100644
--- a/networking/udhcp/leases.c
+++ b/networking/udhcp/leases.c
@@ -4,20 +4,8 @@
* Russ Dill <Russ.Dill@asu.edu> July 2001
*/
-#include <time.h>
-#include <string.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include "dhcpd.h"
-#include "files.h"
-#include "options.h"
-#include "leases.h"
-#include "arpping.h"
#include "common.h"
-
-#include "static_leases.h"
+#include "dhcpd.h"
uint8_t blank_chaddr[] = {[0 ... 15] = 0};
@@ -138,22 +126,20 @@ uint32_t find_address(int check_expired)
if ((addr & 0xFF) == 0xFF) continue;
/* Only do if it isn't an assigned as a static lease */
- if(!reservedIp(server_config.static_leases, htonl(addr)))
- {
-
- /* lease is not taken */
- ret = htonl(addr);
- if ((!(lease = find_lease_by_yiaddr(ret)) ||
-
- /* or it expired and we are checking for expired leases */
- (check_expired && lease_expired(lease))) &&
-
- /* and it isn't on the network */
- !check_ip(ret)) {
- return ret;
- break;
+ if (!reservedIp(server_config.static_leases, htonl(addr))) {
+
+ /* lease is not taken */
+ ret = htonl(addr);
+ lease = find_lease_by_yiaddr(ret);
+
+ /* no lease or it expired and we are checking for expired leases */
+ if ( (!lease || (check_expired && lease_expired(lease)))
+ && /* and it isn't on the network */ !check_ip(ret)
+ ) {
+ return ret;
+ break;
+ }
}
}
- }
return 0;
}
diff --git a/networking/udhcp/leases.h b/networking/udhcp/leases.h
deleted file mode 100644
index 8dba65e29..000000000
--- a/networking/udhcp/leases.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/* leases.h */
-#ifndef _LEASES_H
-#define _LEASES_H
-
-
-struct dhcpOfferedAddr {
- uint8_t chaddr[16];
- uint32_t yiaddr; /* network order */
- uint32_t expires; /* host order */
-};
-
-extern uint8_t blank_chaddr[];
-
-void clear_lease(uint8_t *chaddr, uint32_t yiaddr);
-struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease);
-int lease_expired(struct dhcpOfferedAddr *lease);
-struct dhcpOfferedAddr *oldest_expired_lease(void);
-struct dhcpOfferedAddr *find_lease_by_chaddr(uint8_t *chaddr);
-struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr);
-uint32_t find_address(int check_expired);
-
-
-#endif
diff --git a/networking/udhcp/libbb_udhcp.h b/networking/udhcp/libbb_udhcp.h
deleted file mode 100644
index ab4ad06a4..000000000
--- a/networking/udhcp/libbb_udhcp.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/* libbb_udhcp.h - busybox compatibility wrapper */
-
-/* bit of a hack, do this no matter what the order of the includes.
- * (for busybox) */
-
-#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
-
-
-
-#define COMBINED_BINARY
-
-void udhcp_background(const char *pidfile);
-void udhcp_start_log_and_pid(const char *pidfile);
-
-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
-/* from options.h */
-#define get_option udhcp_get_option
-#define end_option udhcp_end_option
-#define add_option_string udhcp_add_option_string
-#define add_simple_option udhcp_add_simple_option
-#define option_lengths udhcp_option_lengths
-/* from socket.h */
-#define listen_socket udhcp_listen_socket
-#define read_interface udhcp_read_interface
-/* from dhcpc.h */
-#define client_config udhcp_client_config
-/* from dhcpd.h */
-#define server_config udhcp_server_config
-
-#endif /* _LIBBB_UDHCP_H */
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 5cc08cca0..9fcbc8474 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -4,13 +4,9 @@
* Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
*/
-#include <stdlib.h>
-#include <string.h>
-
#include "common.h"
#include "dhcpd.h"
#include "options.h"
-#include "files.h"
/* supported options are easily added here */
diff --git a/networking/udhcp/options.h b/networking/udhcp/options.h
index 3c1f5b921..1b179f173 100644
--- a/networking/udhcp/options.h
+++ b/networking/udhcp/options.h
@@ -3,8 +3,6 @@
#ifndef _OPTIONS_H
#define _OPTIONS_H
-#include "packet.h"
-
#define TYPE_MASK 0x0F
enum {
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index e861b825a..e79542d08 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -1,10 +1,6 @@
/* vi: set sw=4 ts=4: */
-#include <unistd.h>
-#include <string.h>
+
#include <netinet/in.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <features.h>
#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
#include <netpacket/packet.h>
#include <net/ethernet.h>
@@ -13,10 +9,8 @@
#include <linux/if_packet.h>
#include <linux/if_ether.h>
#endif
-#include <errno.h>
#include "common.h"
-#include "packet.h"
#include "dhcpd.h"
#include "options.h"
@@ -70,8 +64,9 @@ int udhcp_get_packet(struct dhcpMessage *packet, int fd)
if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) {
for (i = 0; broken_vendors[i][0]; i++) {
- if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) &&
- !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])) {
+ if (vendor[OPT_LEN - 2] == (uint8_t)strlen(broken_vendors[i])
+ && !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])
+ ) {
DEBUG("broken client (%s), forcing broadcast",
broken_vendors[i]);
packet->flags |= htons(BROADCAST_FLAG);
@@ -114,15 +109,17 @@ uint16_t udhcp_checksum(void *addr, int count)
/* Construct a ip/udp header for a packet, and specify the source and dest hardware address */
-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 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;
int result;
struct sockaddr_ll dest;
struct udp_dhcp_packet packet;
- if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
+ fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
+ if (fd < 0) {
bb_perror_msg("socket");
return -1;
}
@@ -157,7 +154,8 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
packet.ip.ttl = IPDEFTTL;
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));
+ result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0,
+ (struct sockaddr *) &dest, sizeof(dest));
if (result <= 0) {
bb_perror_msg("sendto");
}
@@ -167,14 +165,16 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
/* Let the kernel do all the work for packet generation */
-int udhcp_kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
- uint32_t dest_ip, int dest_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;
int fd, result;
struct sockaddr_in client;
- if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
+ fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (fd < 0)
return -1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) {
diff --git a/networking/udhcp/packet.h b/networking/udhcp/packet.h
deleted file mode 100644
index 0257a2ca9..000000000
--- a/networking/udhcp/packet.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* vi: set sw=4 ts=4: */
-#ifndef _PACKET_H
-#define _PACKET_H
-
-#include <netinet/udp.h>
-#include <netinet/ip.h>
-
-struct dhcpMessage {
- uint8_t op;
- uint8_t htype;
- uint8_t hlen;
- uint8_t hops;
- uint32_t xid;
- uint16_t secs;
- uint16_t flags;
- uint32_t ciaddr;
- uint32_t yiaddr;
- uint32_t siaddr;
- uint32_t giaddr;
- uint8_t chaddr[16];
- uint8_t sname[64];
- uint8_t file[128];
- uint32_t cookie;
- uint8_t options[308]; /* 312 - cookie */
-};
-
-struct udp_dhcp_packet {
- struct iphdr ip;
- struct udphdr udp;
- struct dhcpMessage data;
-};
-
-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 udhcp_kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
- uint32_t dest_ip, int dest_port);
-
-
-#endif
diff --git a/networking/udhcp/pidfile.c b/networking/udhcp/pidfile.c
index 6673c9502..8d00490af 100644
--- a/networking/udhcp/pidfile.c
+++ b/networking/udhcp/pidfile.c
@@ -20,15 +20,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-
#include "common.h"
-#include "pidfile.h"
+
static char *saved_pidfile;
diff --git a/networking/udhcp/pidfile.h b/networking/udhcp/pidfile.h
deleted file mode 100644
index 38c849305..000000000
--- a/networking/udhcp/pidfile.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/* pidfile.h
- *
- * Functions to assist in the writing and removing of pidfiles.
- *
- * Russ Dill <Russ.Dill@asu.edu> September 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.
- */
-
-
-int pidfile_acquire(const char *pidfile);
-void pidfile_write_release(int pid_fd);
-
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 3c4b51b24..6e0ca885f 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -8,20 +8,11 @@
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
-#include <string.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
#include "common.h"
-#include "options.h"
#include "dhcpd.h"
#include "dhcpc.h"
+#include "options.h"
+
/* get a rough idea of how long an option will be (rounding up...) */
static const int max_option_length[] = {
@@ -76,7 +67,7 @@ static void fill_options(char *dest, uint8_t *option, struct dhcp_option *type_p
type = type_p->flags & TYPE_MASK;
optlen = option_lengths[type];
- for(;;) {
+ for (;;) {
switch (type) {
case OPTION_IP_PAIR:
dest += sprintip(dest, "", option);
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c
index b5cfcf405..8889fda86 100644
--- a/networking/udhcp/serverpacket.c
+++ b/networking/udhcp/serverpacket.c
@@ -20,17 +20,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include <time.h>
-
#include "common.h"
-#include "serverpacket.h"
#include "dhcpd.h"
#include "options.h"
-#include "static_leases.h"
+
/* send a packet to giaddr using the kernel ip stack */
static int send_packet_to_relay(struct dhcpMessage *payload)
@@ -122,65 +115,57 @@ int sendOffer(struct dhcpMessage *oldpacket)
static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr);
/* ADDME: if static, short circuit */
- if(!static_lease_ip)
- {
- /* the client is in our lease/offered table */
- if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) {
- if (!lease_expired(lease))
- lease_time_align = lease->expires - time(0);
- packet.yiaddr = lease->yiaddr;
-
- /* Or the client has a requested ip */
- } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) &&
-
- /* Don't look here (ugly hackish thing to do) */
- memcpy(&req_align, req, 4) &&
-
- /* and the ip is in the lease range */
- ntohl(req_align) >= ntohl(server_config.start) &&
- ntohl(req_align) <= ntohl(server_config.end) &&
-
- !static_lease_ip && /* Check that its not a static lease */
+ if (!static_lease_ip) {
+ /* the client is in our lease/offered table */
+ lease = find_lease_by_chaddr(oldpacket->chaddr);
+ if (lease) {
+ if (!lease_expired(lease))
+ lease_time_align = lease->expires - time(0);
+ packet.yiaddr = lease->yiaddr;
+
+ /* Or the client has a requested ip */
+ } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP))
+ /* Don't look here (ugly hackish thing to do) */
+ && memcpy(&req_align, req, 4)
+ /* and the ip is in the lease range */
+ && ntohl(req_align) >= ntohl(server_config.start)
+ && ntohl(req_align) <= ntohl(server_config.end)
+ && !static_lease_ip /* Check that its not a static lease */
/* and is not already taken/offered */
- ((!(lease = find_lease_by_yiaddr(req_align)) ||
-
- /* or its taken, but expired */ /* ADDME: or maybe in here */
- lease_expired(lease)))) {
- packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
-
+ && (!(lease = find_lease_by_yiaddr(req_align))
+ /* or its taken, but expired */ /* ADDME: or maybe in here */
+ || lease_expired(lease))
+ ) {
+ packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
/* otherwise, find a free IP */
- } else {
+ } else {
/* Is it a static lease? (No, because find_address skips static lease) */
- packet.yiaddr = find_address(0);
-
- /* try for an expired lease */
- if (!packet.yiaddr) packet.yiaddr = find_address(1);
- }
-
- if(!packet.yiaddr) {
- bb_error_msg("no IP addresses to give - OFFER abandoned");
- return -1;
- }
-
- if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
- bb_error_msg("lease pool is full - OFFER abandoned");
- return -1;
- }
-
- if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) {
- memcpy(&lease_time_align, lease_time, 4);
- lease_time_align = ntohl(lease_time_align);
- if (lease_time_align > server_config.lease)
+ packet.yiaddr = find_address(0);
+ /* try for an expired lease */
+ if (!packet.yiaddr) packet.yiaddr = find_address(1);
+ }
+
+ if (!packet.yiaddr) {
+ bb_error_msg("no IP addresses to give - OFFER abandoned");
+ return -1;
+ }
+ if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
+ bb_error_msg("lease pool is full - OFFER abandoned");
+ return -1;
+ }
+ lease_time = get_option(oldpacket, DHCP_LEASE_TIME);
+ if (lease_time) {
+ memcpy(&lease_time_align, lease_time, 4);
+ lease_time_align = ntohl(lease_time_align);
+ if (lease_time_align > server_config.lease)
+ lease_time_align = server_config.lease;
+ }
+
+ /* Make sure we aren't just using the lease time from the previous offer */
+ if (lease_time_align < server_config.min_lease)
lease_time_align = server_config.lease;
- }
-
- /* Make sure we aren't just using the lease time from the previous offer */
- if (lease_time_align < server_config.min_lease)
- lease_time_align = server_config.lease;
- }
- /* ADDME: end of short circuit */
- else
- {
+ /* ADDME: end of short circuit */
+ } else {
/* It is a static lease... use it */
packet.yiaddr = static_lease_ip;
}
diff --git a/networking/udhcp/serverpacket.h b/networking/udhcp/serverpacket.h
deleted file mode 100644
index 20e1d5d2b..000000000
--- a/networking/udhcp/serverpacket.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/* vi: set sw=4 ts=4: */
-#ifndef _SERVERPACKET_H
-#define _SERVERPACKET_H
-
-#include "packet.h"
-
-int sendOffer(struct dhcpMessage *oldpacket);
-int sendNAK(struct dhcpMessage *oldpacket);
-int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr);
-int send_inform(struct dhcpMessage *oldpacket);
-
-
-#endif
diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c
index bece4193a..361596580 100644
--- a/networking/udhcp/signalpipe.c
+++ b/networking/udhcp/signalpipe.c
@@ -20,17 +20,9 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <unistd.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/select.h>
-
-
-#include "signalpipe.h"
#include "common.h"
+
static int signal_pipe[2];
static void signal_handler(int sig)
diff --git a/networking/udhcp/signalpipe.h b/networking/udhcp/signalpipe.h
deleted file mode 100644
index 1621d5772..000000000
--- a/networking/udhcp/signalpipe.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/* signalpipe.h
- *
- * Russ Dill <Russ.Dill@asu.edu> December 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.
- */
-
-void udhcp_sp_setup(void);
-int udhcp_sp_fd_set(fd_set *rfds, int extra_fd);
-int udhcp_sp_read(fd_set *rfds);
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index d1867e9a8..ea2913172 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -23,15 +23,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <netinet/in.h>
-#include <unistd.h>
-#include <string.h>
-#include <arpa/inet.h>
#include <net/if.h>
-#include <errno.h>
#include <features.h>
#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
#include <netpacket/packet.h>
@@ -43,7 +35,7 @@
#endif
#include "common.h"
-#include "socket.h"
+
int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp)
{
@@ -52,44 +44,42 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp)
struct sockaddr_in *our_ip;
memset(&ifr, 0, sizeof(struct ifreq));
- if((fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) {
- ifr.ifr_addr.sa_family = AF_INET;
- strcpy(ifr.ifr_name, interface);
-
- if (addr) {
- if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
- our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
- *addr = our_ip->sin_addr.s_addr;
- DEBUG("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
- } else {
- bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?");
- close(fd);
- return -1;
- }
- }
+ fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
+ if (fd < 0) {
+ bb_perror_msg("socket failed");
+ return -1;
+ }
- if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) {
- DEBUG("adapter index %d", ifr.ifr_ifindex);
- *ifindex = ifr.ifr_ifindex;
- } else {
- bb_perror_msg("SIOCGIFINDEX failed");
+ ifr.ifr_addr.sa_family = AF_INET;
+ strcpy(ifr.ifr_name, interface);
+ if (addr) {
+ if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
+ bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?");
close(fd);
return -1;
}
- if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) {
- memcpy(arp, ifr.ifr_hwaddr.sa_data, 6);
- DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
- arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
- } else {
- bb_perror_msg("SIOCGIFHWADDR failed");
- close(fd);
- return -1;
- }
- } else {
- bb_perror_msg("socket failed");
+ our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
+ *addr = our_ip->sin_addr.s_addr;
+ DEBUG("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
+ }
+
+ if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) {
+ bb_perror_msg("SIOCGIFINDEX failed");
+ close(fd);
+ return -1;
+ }
+
+ DEBUG("adapter index %d", ifr.ifr_ifindex);
+ *ifindex = ifr.ifr_ifindex;
+ if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0) {
+ bb_perror_msg("SIOCGIFHWADDR failed");
+ close(fd);
return -1;
}
- close(fd);
+
+ memcpy(arp, ifr.ifr_hwaddr.sa_data, 6);
+ DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
+ arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
return 0;
}
@@ -102,7 +92,8 @@ int listen_socket(uint32_t ip, int port, char *inf)
int n = 1;
DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf);
- if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ if (fd < 0) {
bb_perror_msg("socket");
return -1;
}
diff --git a/networking/udhcp/socket.h b/networking/udhcp/socket.h
deleted file mode 100644
index 23bffa16d..000000000
--- a/networking/udhcp/socket.h
+++ /dev/null
@@ -1,9 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/* socket.h */
-#ifndef _SOCKET_H
-#define _SOCKET_H
-
-int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp);
-int listen_socket(uint32_t ip, int port, char *inf);
-
-#endif
diff --git a/networking/udhcp/static_leases.c b/networking/udhcp/static_leases.c
index 0d962c56e..b53eac5a4 100644
--- a/networking/udhcp/static_leases.c
+++ b/networking/udhcp/static_leases.c
@@ -7,20 +7,15 @@
*
*/
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "static_leases.h"
+#include "common.h"
#include "dhcpd.h"
+
/* Takes the address of the pointer to the static_leases linked list,
* Address to a 6 byte mac address
* Address to a 4 byte ip address */
int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip)
{
-
struct static_lease *cur;
struct static_lease *new_static_lease;
@@ -31,15 +26,11 @@ int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *i
new_static_lease->next = NULL;
/* If it's the first node to be added... */
- if(*lease_struct == NULL)
- {
+ if (*lease_struct == NULL) {
*lease_struct = new_static_lease;
- }
- else
- {
+ } else {
cur = *lease_struct;
- while(cur->next != NULL)
- {
+ while (cur->next) {
cur = cur->next;
}
@@ -47,7 +38,6 @@ int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *i
}
return 1;
-
}
/* Check to see if a mac has an associated static lease */
@@ -59,11 +49,9 @@ uint32_t getIpByMac(struct static_lease *lease_struct, void *arg)
return_ip = 0;
- while(cur != NULL)
- {
+ while (cur) {
/* If the client has the correct mac */
- if(memcmp(cur->mac, mac, 6) == 0)
- {
+ if (memcmp(cur->mac, mac, 6) == 0) {
return_ip = *(cur->ip);
}
@@ -71,7 +59,6 @@ uint32_t getIpByMac(struct static_lease *lease_struct, void *arg)
}
return return_ip;
-
}
/* Check to see if an ip is reserved as a static ip */
@@ -81,17 +68,15 @@ uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip)
uint32_t return_val = 0;
- while(cur != NULL)
- {
+ while (cur) {
/* If the client has the correct ip */
- if(*cur->ip == ip)
+ if (*cur->ip == ip)
return_val = 1;
cur = cur->next;
}
return return_val;
-
}
#ifdef CONFIG_FEATURE_UDHCP_DEBUG
@@ -102,8 +87,7 @@ void printStaticLeases(struct static_lease **arg)
/* Get a pointer to the linked list */
struct static_lease *cur = *arg;
- while(cur != NULL)
- {
+ while (cur) {
/* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */
printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac));
/* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */
@@ -111,10 +95,5 @@ void printStaticLeases(struct static_lease **arg)
cur = cur->next;
}
-
-
}
#endif
-
-
-
diff --git a/networking/udhcp/static_leases.h b/networking/udhcp/static_leases.h
deleted file mode 100644
index b23bbcfff..000000000
--- a/networking/udhcp/static_leases.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/* static_leases.h */
-#ifndef _STATIC_LEASES_H
-#define _STATIC_LEASES_H
-
-#include "dhcpd.h"
-
-/* Config file will pass static lease info to this function which will add it
- * to a data structure that can be searched later */
-int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip);
-
-/* Check to see if a mac has an associated static lease */
-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);
-
-/* Print out static leases just to check what's going on (debug code) */
-void printStaticLeases(struct static_lease **lease_struct);
-
-#endif
-
-
-