summaryrefslogtreecommitdiff
path: root/networking/udhcp
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 /networking/udhcp
parentabfc4cf6d8b9c59724aceb70df5081a1368fdb62 (diff)
downloadbusybox-w32-5a3395bc01cd4b11309595a6ecdaf32f8279f378.tar.gz
busybox-w32-5a3395bc01cd4b11309595a6ecdaf32f8279f378.tar.bz2
busybox-w32-5a3395bc01cd4b11309595a6ecdaf32f8279f378.zip
udhcp: fix indentation and style.
Eliminate (group) a lot of smallish *.h files Remove lots of unneeded #includes
Diffstat (limited to 'networking/udhcp')
-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 @@
6 * by Yoichi Hariguchi <yoichi@fore.com> 6 * by Yoichi Hariguchi <yoichi@fore.com>
7 */ 7 */
8 8
9#include <time.h>
10#include <sys/socket.h>
11#include <netinet/if_ether.h> 9#include <netinet/if_ether.h>
12#include <net/if_arp.h> 10#include <net/if_arp.h>
13#include <netinet/in.h>
14#include <string.h>
15#include <unistd.h>
16#include <errno.h>
17 11
18#include "dhcpd.h"
19#include "arpping.h"
20#include "common.h" 12#include "common.h"
13#include "dhcpd.h"
14
15
16struct arpMsg {
17 /* Ethernet header */
18 u_char h_dest[6]; /* destination ether addr */
19 u_char h_source[6]; /* source ether addr */
20 u_short h_proto; /* packet type ID field */
21
22 /* ARP packet */
23 uint16_t htype; /* hardware type (must be ARPHRD_ETHER) */
24 uint16_t ptype; /* protocol type (must be ETH_P_IP) */
25 uint8_t hlen; /* hardware address length (must be 6) */
26 uint8_t plen; /* protocol address length (must be 4) */
27 uint16_t operation; /* ARP opcode */
28 uint8_t sHaddr[6]; /* sender's hardware address */
29 uint8_t sInaddr[4]; /* sender's IP address */
30 uint8_t tHaddr[6]; /* target's hardware address */
31 uint8_t tInaddr[4]; /* target's IP address */
32 uint8_t pad[18]; /* pad for min. Ethernet payload (60 bytes) */
33} ATTRIBUTE_PACKED;
21 34
22/* args: yiaddr - what IP to ping 35/* args: yiaddr - what IP to ping
23 * ip - our ip 36 * 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 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * arpping .h
4 */
5
6#ifndef ARPPING_H
7#define ARPPING_H
8
9#include <netinet/if_ether.h>
10#include <net/if_arp.h>
11#include <net/if.h>
12#include <netinet/in.h>
13
14struct arpMsg {
15 /* Ethernet header */
16 u_char h_dest[6]; /* destination ether addr */
17 u_char h_source[6]; /* source ether addr */
18 u_short h_proto; /* packet type ID field */
19
20 /* ARP packet */
21 uint16_t htype; /* hardware type (must be ARPHRD_ETHER) */
22 uint16_t ptype; /* protocol type (must be ETH_P_IP) */
23 uint8_t hlen; /* hardware address length (must be 6) */
24 uint8_t plen; /* protocol address length (must be 4) */
25 uint16_t operation; /* ARP opcode */
26 uint8_t sHaddr[6]; /* sender's hardware address */
27 uint8_t sInaddr[4]; /* sender's IP address */
28 uint8_t tHaddr[6]; /* target's hardware address */
29 uint8_t tInaddr[4]; /* target's IP address */
30 uint8_t pad[18]; /* pad for min. Ethernet payload (60 bytes) */
31} ATTRIBUTE_PACKED;
32
33/* function prototypes */
34int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *arp, char *interface);
35
36#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 @@
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9 */ 9 */
10 10
11#include <string.h>
12#include <sys/socket.h>
13#include <features.h> 11#include <features.h>
14#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION 12#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
15#include <netpacket/packet.h> 13#include <netpacket/packet.h>
@@ -19,19 +17,11 @@
19#include <linux/if_packet.h> 17#include <linux/if_packet.h>
20#include <linux/if_ether.h> 18#include <linux/if_ether.h>
21#endif 19#endif
22#include <stdlib.h>
23#include <time.h>
24#include <unistd.h>
25#include <netinet/in.h>
26#include <arpa/inet.h>
27#include <fcntl.h>
28
29 20
21#include "common.h"
30#include "dhcpd.h" 22#include "dhcpd.h"
31#include "clientpacket.h"
32#include "options.h"
33#include "dhcpc.h" 23#include "dhcpc.h"
34#include "common.h" 24#include "options.h"
35 25
36 26
37/* Create a random xid */ 27/* Create a random xid */
@@ -59,7 +49,7 @@ static void init_packet(struct dhcpMessage *packet, char type)
59 udhcp_init_header(packet, type); 49 udhcp_init_header(packet, type);
60 memcpy(packet->chaddr, client_config.arp, 6); 50 memcpy(packet->chaddr, client_config.arp, 6);
61 if (client_config.clientid) 51 if (client_config.clientid)
62 add_option_string(packet->options, client_config.clientid); 52 add_option_string(packet->options, client_config.clientid);
63 if (client_config.hostname) add_option_string(packet->options, client_config.hostname); 53 if (client_config.hostname) add_option_string(packet->options, client_config.hostname);
64 if (client_config.fqdn) add_option_string(packet->options, client_config.fqdn); 54 if (client_config.fqdn) add_option_string(packet->options, client_config.fqdn);
65 add_option_string(packet->options, client_config.vendorclass); 55 add_option_string(packet->options, client_config.vendorclass);
@@ -97,7 +87,7 @@ int send_discover(unsigned long xid, unsigned long requested)
97 add_requests(&packet); 87 add_requests(&packet);
98 bb_info_msg("Sending discover..."); 88 bb_info_msg("Sending discover...");
99 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 89 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
100 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 90 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
101} 91}
102 92
103 93
@@ -188,10 +178,12 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
188 bytes = ntohs(packet.ip.tot_len); 178 bytes = ntohs(packet.ip.tot_len);
189 179
190 /* Make sure its the right packet for us, and that it passes sanity checks */ 180 /* Make sure its the right packet for us, and that it passes sanity checks */
191 if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION || 181 if (packet.ip.protocol != IPPROTO_UDP || packet.ip.version != IPVERSION
192 packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) || 182 || packet.ip.ihl != sizeof(packet.ip) >> 2
193 bytes > (int) sizeof(struct udp_dhcp_packet) || 183 || packet.udp.dest != htons(CLIENT_PORT)
194 ntohs(packet.udp.len) != (uint16_t) (bytes - sizeof(packet.ip))) { 184 || bytes > (int) sizeof(struct udp_dhcp_packet)
185 || ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip))
186 ) {
195 DEBUG("Unrelated/bogus packet"); 187 DEBUG("Unrelated/bogus packet");
196 return -2; 188 return -2;
197 } 189 }
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 @@
1/* vi: set sw=4 ts=4: */
2#ifndef _CLIENTPACKET_H
3#define _CLIENTPACKET_H
4
5#include "packet.h"
6
7unsigned long random_xid(void);
8int send_discover(unsigned long xid, unsigned long requested);
9int send_selecting(unsigned long xid, unsigned long server, unsigned long requested);
10int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
11int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
12int send_release(unsigned long server, unsigned long ciaddr);
13int get_raw_packet(struct dhcpMessage *payload, int fd);
14
15#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 @@
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */ 22 */
23 23
24#include <sys/types.h>
25#include <sys/socket.h>
26#include <unistd.h>
27#include <netinet/in.h>
28#include <features.h> 24#include <features.h>
29#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION) 25#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined(_NEWLIB_VERSION)
30#include <netpacket/packet.h> 26#include <netpacket/packet.h>
@@ -35,7 +31,6 @@
35#include <linux/if_ether.h> 31#include <linux/if_ether.h>
36#endif 32#endif
37 33
38#include "clientsocket.h"
39#include "common.h" 34#include "common.h"
40 35
41 36
@@ -45,7 +40,8 @@ int raw_socket(int ifindex)
45 struct sockaddr_ll sock; 40 struct sockaddr_ll sock;
46 41
47 DEBUG("Opening raw socket on ifindex %d", ifindex); 42 DEBUG("Opening raw socket on ifindex %d", ifindex);
48 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { 43 fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
44 if (fd < 0) {
49 bb_perror_msg("socket"); 45 bb_perror_msg("socket");
50 return -1; 46 return -1;
51 } 47 }
@@ -54,7 +50,7 @@ int raw_socket(int ifindex)
54 sock.sll_protocol = htons(ETH_P_IP); 50 sock.sll_protocol = htons(ETH_P_IP);
55 sock.sll_ifindex = ifindex; 51 sock.sll_ifindex = ifindex;
56 if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) { 52 if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) {
57 bb_perror_msg("bind:"); 53 bb_perror_msg("bind");
58 close(fd); 54 close(fd);
59 return -1; 55 return -1;
60 } 56 }
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 @@
1/* vi: set sw=4 ts=4: */
2/* clientsocket.h */
3#ifndef _CLIENTSOCKET_H
4#define _CLIENTSOCKET_H
5
6int raw_socket(int ifindex);
7
8#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 @@
10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 */ 11 */
12 12
13#include <fcntl.h>
14#include <unistd.h>
15#include <errno.h>
16#include <string.h>
17#include <stdlib.h>
18#include <signal.h>
19#include <paths.h>
20#include <sys/socket.h>
21#include <stdarg.h>
22#include <syslog.h> 13#include <syslog.h>
23 14
24#include "common.h" 15#include "common.h"
25#include "pidfile.h"
26 16
27 17
28static int daemonized;
29
30long uptime(void) 18long uptime(void)
31{ 19{
32 struct sysinfo info; 20 struct sysinfo info;
@@ -61,7 +49,6 @@ void udhcp_background(const char *pidfile)
61 pid_fd = pidfile_acquire(pidfile); 49 pid_fd = pidfile_acquire(pidfile);
62 setsid(); 50 setsid();
63 xdaemon(0, 0); 51 xdaemon(0, 0);
64 daemonized++;
65 logmode &= ~LOGMODE_STDIO; 52 logmode &= ~LOGMODE_STDIO;
66 pidfile_write_release(pid_fd); 53 pidfile_write_release(pid_fd);
67#endif /* __uClinux__ */ 54#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 @@
10#ifndef _COMMON_H 10#ifndef _COMMON_H
11#define _COMMON_H 11#define _COMMON_H
12 12
13#include "libbb_udhcp.h" 13#include "busybox.h"
14
15#ifdef CONFIG_INSTALL_NO_USR
16# define DEFAULT_SCRIPT "/share/udhcpc/default.script"
17#else
18# define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script"
19#endif
20
21#define COMBINED_BINARY
22
23
24/*** packet.h ***/
25
26#include <netinet/udp.h>
27#include <netinet/ip.h>
28
29struct dhcpMessage {
30 uint8_t op;
31 uint8_t htype;
32 uint8_t hlen;
33 uint8_t hops;
34 uint32_t xid;
35 uint16_t secs;
36 uint16_t flags;
37 uint32_t ciaddr;
38 uint32_t yiaddr;
39 uint32_t siaddr;
40 uint32_t giaddr;
41 uint8_t chaddr[16];
42 uint8_t sname[64];
43 uint8_t file[128];
44 uint32_t cookie;
45 uint8_t options[308]; /* 312 - cookie */
46};
47
48struct udp_dhcp_packet {
49 struct iphdr ip;
50 struct udphdr udp;
51 struct dhcpMessage data;
52};
53
54void udhcp_init_header(struct dhcpMessage *packet, char type);
55int udhcp_get_packet(struct dhcpMessage *packet, int fd);
56uint16_t udhcp_checksum(void *addr, int count);
57int udhcp_raw_packet(struct dhcpMessage *payload,
58 uint32_t source_ip, int source_port,
59 uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex);
60int udhcp_kernel_packet(struct dhcpMessage *payload,
61 uint32_t source_ip, int source_port,
62 uint32_t dest_ip, int dest_port);
63
64
65/**/
66
67void udhcp_background(const char *pidfile);
68void udhcp_start_log_and_pid(const char *pidfile);
69
70void udhcp_run_script(struct dhcpMessage *packet, const char *name);
71
72// Still need to clean these up...
73
74/* from pidfile.h */
75#define pidfile_acquire udhcp_pidfile_acquire
76#define pidfile_write_release udhcp_pidfile_write_release
77/* from options.h */
78#define get_option udhcp_get_option
79#define end_option udhcp_end_option
80#define add_option_string udhcp_add_option_string
81#define add_simple_option udhcp_add_simple_option
82#define option_lengths udhcp_option_lengths
83/* from socket.h */
84#define listen_socket udhcp_listen_socket
85#define read_interface udhcp_read_interface
86/* from dhcpc.h */
87#define client_config udhcp_client_config
88/* from dhcpd.h */
89#define server_config udhcp_server_config
14 90
15long uptime(void); 91long uptime(void);
92void udhcp_sp_setup(void);
93int udhcp_sp_fd_set(fd_set *rfds, int extra_fd);
94int udhcp_sp_read(fd_set *rfds);
95int raw_socket(int ifindex);
96int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp);
97int listen_socket(uint32_t ip, int port, char *inf);
98int pidfile_acquire(const char *pidfile);
99void pidfile_write_release(int pid_fd);
100int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *arp, char *interface);
16 101
17#if ENABLE_FEATURE_UDHCP_DEBUG 102#if ENABLE_FEATURE_UDHCP_DEBUG
18# define DEBUG(str, args...) bb_info_msg(str, ## args) 103# define DEBUG(str, args...) bb_info_msg(str, ## args)
19#else 104#else
20# define DEBUG(str, args...) do {;} while(0) 105# define DEBUG(str, args...) do {;} while (0)
21#endif 106#endif
22 107
23#endif 108#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 @@
8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 8 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9 */ 9 */
10 10
11#include <sys/file.h>
12#include <unistd.h>
13#include <getopt.h> 11#include <getopt.h>
14#include <stdlib.h>
15#include <sys/socket.h>
16#include <netinet/in.h>
17#include <arpa/inet.h>
18#include <signal.h>
19#include <time.h>
20#include <string.h>
21#include <sys/ioctl.h>
22#include <net/if.h>
23#include <errno.h>
24 12
25#include "common.h" 13#include "common.h"
26#include "dhcpd.h" 14#include "dhcpd.h"
27#include "dhcpc.h" 15#include "dhcpc.h"
28#include "options.h" 16#include "options.h"
29#include "clientpacket.h" 17
30#include "clientsocket.h"
31#include "socket.h"
32#include "signalpipe.h"
33 18
34static int state; 19static int state;
35/* Something is definitely wrong here. IPv4 addresses 20/* 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 @@
3#ifndef _DHCPC_H 3#ifndef _DHCPC_H
4#define _DHCPC_H 4#define _DHCPC_H
5 5
6/* grab define DEFAULT_SCRIPT */
7#include "libbb_udhcp.h"
8
9#define INIT_SELECTING 0 6#define INIT_SELECTING 0
10#define REQUESTING 1 7#define REQUESTING 1
11#define BOUND 2 8#define BOUND 2
@@ -15,7 +12,6 @@
15#define RENEW_REQUESTED 6 12#define RENEW_REQUESTED 6
16#define RELEASED 7 13#define RELEASED 7
17 14
18
19struct client_config_t { 15struct client_config_t {
20 char foreground; /* Do not fork */ 16 char foreground; /* Do not fork */
21 char quit_after_lease; /* Quit after obtaining lease */ 17 char quit_after_lease; /* Quit after obtaining lease */
@@ -38,4 +34,15 @@ struct client_config_t {
38extern struct client_config_t client_config; 34extern struct client_config_t client_config;
39 35
40 36
37/*** clientpacket.h ***/
38
39unsigned long random_xid(void);
40int send_discover(unsigned long xid, unsigned long requested);
41int send_selecting(unsigned long xid, unsigned long server, unsigned long requested);
42int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
43int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr);
44int send_release(unsigned long server, unsigned long ciaddr);
45int get_raw_packet(struct dhcpMessage *payload, int fd);
46
47
41#endif 48#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 @@
10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 10 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
11 */ 11 */
12 12
13#include <fcntl.h> 13#include "common.h"
14#include <string.h>
15#include <stdlib.h>
16#include <sys/wait.h>
17#include <arpa/inet.h>
18#include <netdb.h>
19#include <netinet/in.h>
20#include <sys/socket.h>
21#include <unistd.h>
22#include <signal.h>
23#include <errno.h>
24#include <sys/ioctl.h>
25#include <time.h>
26
27#include "dhcpd.h" 14#include "dhcpd.h"
28#include "arpping.h"
29#include "socket.h"
30#include "options.h" 15#include "options.h"
31#include "files.h"
32#include "serverpacket.h"
33#include "common.h"
34#include "signalpipe.h"
35#include "static_leases.h"
36 16
37 17
38/* globals */ 18/* globals */
@@ -86,7 +66,7 @@ int udhcpd_main(int argc, char *argv[])
86 udhcp_sp_setup(); 66 udhcp_sp_setup();
87 67
88 timeout_end = time(0) + server_config.auto_time; 68 timeout_end = time(0) + server_config.auto_time;
89 while(1) { /* loop until universe collapses */ 69 while (1) { /* loop until universe collapses */
90 70
91 if (server_socket < 0) 71 if (server_socket < 0)
92 if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) { 72 if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) {
@@ -144,8 +124,7 @@ int udhcpd_main(int argc, char *argv[])
144 /* Look for a static lease */ 124 /* Look for a static lease */
145 static_lease_ip = getIpByMac(server_config.static_leases, &packet.chaddr); 125 static_lease_ip = getIpByMac(server_config.static_leases, &packet.chaddr);
146 126
147 if(static_lease_ip) 127 if (static_lease_ip) {
148 {
149 bb_info_msg("Found static lease: %x", static_lease_ip); 128 bb_info_msg("Found static lease: %x", static_lease_ip);
150 129
151 memcpy(&static_lease.chaddr, &packet.chaddr, 16); 130 memcpy(&static_lease.chaddr, &packet.chaddr, 16);
@@ -154,10 +133,8 @@ int udhcpd_main(int argc, char *argv[])
154 133
155 lease = &static_lease; 134 lease = &static_lease;
156 135
157 } 136 } else {
158 else 137 lease = find_lease_by_chaddr(packet.chaddr);
159 {
160 lease = find_lease_by_chaddr(packet.chaddr);
161 } 138 }
162 139
163 switch (state[0]) { 140 switch (state[0]) {
@@ -245,4 +222,3 @@ int udhcpd_main(int argc, char *argv[])
245 222
246 return 0; 223 return 0;
247} 224}
248
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 @@
3#ifndef _DHCPD_H 3#ifndef _DHCPD_H
4#define _DHCPD_H 4#define _DHCPD_H
5 5
6#include <netinet/ip.h>
7#include <netinet/udp.h>
8
9#include "libbb_udhcp.h"
10#include "leases.h"
11
12/************************************/ 6/************************************/
13/* Defaults _you_ may want to tweak */ 7/* Defaults _you_ may want to tweak */
14/************************************/ 8/************************************/
@@ -138,4 +132,59 @@ extern struct server_config_t server_config;
138extern struct dhcpOfferedAddr *leases; 132extern struct dhcpOfferedAddr *leases;
139 133
140 134
135/*** leases.h ***/
136
137struct dhcpOfferedAddr {
138 uint8_t chaddr[16];
139 uint32_t yiaddr; /* network order */
140 uint32_t expires; /* host order */
141};
142
143extern uint8_t blank_chaddr[];
144
145void clear_lease(uint8_t *chaddr, uint32_t yiaddr);
146struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease);
147int lease_expired(struct dhcpOfferedAddr *lease);
148struct dhcpOfferedAddr *oldest_expired_lease(void);
149struct dhcpOfferedAddr *find_lease_by_chaddr(uint8_t *chaddr);
150struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr);
151uint32_t find_address(int check_expired);
152
153
154/*** static_leases.h ***/
155
156/* Config file will pass static lease info to this function which will add it
157 * to a data structure that can be searched later */
158int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip);
159/* Check to see if a mac has an associated static lease */
160uint32_t getIpByMac(struct static_lease *lease_struct, void *arg);
161/* Check to see if an ip is reserved as a static ip */
162uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip);
163/* Print out static leases just to check what's going on (debug code) */
164void printStaticLeases(struct static_lease **lease_struct);
165
166
167/*** serverpacket.h ***/
168
169int sendOffer(struct dhcpMessage *oldpacket);
170int sendNAK(struct dhcpMessage *oldpacket);
171int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr);
172int send_inform(struct dhcpMessage *oldpacket);
173
174
175/*** files.h ***/
176
177struct config_keyword {
178 const char *keyword;
179 int (* const handler)(const char *line, void *var);
180 void *var;
181 const char *def;
182};
183
184int read_config(const char *file);
185void write_leases(void);
186void read_leases(const char *file);
187struct option_set *find_option(struct option_set *opt_list, char code);
188
189
141#endif 190#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 @@
2/* 2/*
3 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 3 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
4 */ 4 */
5#include <fcntl.h>
6#include <string.h>
7#include <stdlib.h>
8#include <stdio.h>
9#include <sys/wait.h>
10#include <arpa/inet.h>
11#include <netdb.h>
12#include <netinet/in.h>
13#include <stdio.h>
14#include <sys/socket.h>
15#include <unistd.h>
16#include <getopt.h> 5#include <getopt.h>
17#include <time.h>
18 6
7#include "common.h"
19#include "dhcpd.h" 8#include "dhcpd.h"
20#include "leases.h" 9
21#include "libbb_udhcp.h"
22 10
23#define REMAINING 0 11#define REMAINING 0
24#define ABSOLUTE 1 12#define ABSOLUTE 1
@@ -60,17 +48,16 @@ int dumpleases_main(int argc, char *argv[])
60 printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at"); 48 printf("Mac Address IP-Address Expires %s\n", mode == REMAINING ? "in" : "at");
61 /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */ 49 /* "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */
62 while (fread(&lease, sizeof(lease), 1, fp)) { 50 while (fread(&lease, sizeof(lease), 1, fp)) {
63 51 printf(":%02x"+1, lease.chaddr[0]);
64 for (i = 0; i < 6; i++) { 52 for (i = 1; i < 6; i++) {
65 printf("%02x", lease.chaddr[i]); 53 printf(":%02x", lease.chaddr[i]);
66 if (i != 5) printf(":");
67 } 54 }
68 addr.s_addr = lease.yiaddr; 55 addr.s_addr = lease.yiaddr;
69 printf(" %-15s", inet_ntoa(addr)); 56 printf(" %-15s ", inet_ntoa(addr));
70 expires = ntohl(lease.expires); 57 expires = ntohl(lease.expires);
71 printf(" ");
72 if (mode == REMAINING) { 58 if (mode == REMAINING) {
73 if (!expires) printf("expired\n"); 59 if (!expires)
60 printf("expired\n");
74 else { 61 else {
75 if (expires > 60*60*24) { 62 if (expires > 60*60*24) {
76 printf("%ld days, ", expires / (60*60*24)); 63 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 @@
4 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 4 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
5 */ 5 */
6 6
7#include <sys/socket.h>
8#include <arpa/inet.h>
9#include <string.h>
10#include <stdlib.h>
11#include <time.h>
12#include <ctype.h>
13#include <netdb.h>
14
15#include <netinet/ether.h> 7#include <netinet/ether.h>
16#include "static_leases.h"
17 8
9#include "common.h"
18#include "dhcpd.h" 10#include "dhcpd.h"
19#include "options.h" 11#include "options.h"
20#include "files.h" 12
21#include "common.h"
22 13
23/* 14/*
24 * Domain names may have 254 chars, and string options can be 254 15 * 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)
51 42
52 temp_ether_addr = ether_aton(line); 43 temp_ether_addr = ether_aton(line);
53 44
54 if(temp_ether_addr == NULL) 45 if (temp_ether_addr == NULL)
55 retval = 0; 46 retval = 0;
56 else 47 else
57 memcpy(mac_bytes, temp_ether_addr, 6); 48 memcpy(mac_bytes, temp_ether_addr, 6);
@@ -217,7 +208,6 @@ static int read_opt(const char *const_line, void *arg)
217 208
218static int read_staticlease(const char *const_line, void *arg) 209static int read_staticlease(const char *const_line, void *arg)
219{ 210{
220
221 char *line; 211 char *line;
222 char *mac_string; 212 char *mac_string;
223 char *ip_string; 213 char *ip_string;
@@ -243,7 +233,6 @@ static int read_staticlease(const char *const_line, void *arg)
243 if (ENABLE_FEATURE_UDHCP_DEBUG) printStaticLeases(arg); 233 if (ENABLE_FEATURE_UDHCP_DEBUG) printStaticLeases(arg);
244 234
245 return 1; 235 return 1;
246
247} 236}
248 237
249 238
@@ -308,9 +297,9 @@ int read_config(const char *file)
308 for (i = 0; keywords[i].keyword[0]; i++) 297 for (i = 0; keywords[i].keyword[0]; i++)
309 if (!strcasecmp(token, keywords[i].keyword)) 298 if (!strcasecmp(token, keywords[i].keyword))
310 if (!keywords[i].handler(line, keywords[i].var)) { 299 if (!keywords[i].handler(line, keywords[i].var)) {
311 bb_error_msg("failure parsing line %d of %s", lm, file); 300 bb_error_msg("cannot parse line %d of %s", lm, file);
312 if (ENABLE_FEATURE_UDHCP_DEBUG) 301 if (ENABLE_FEATURE_UDHCP_DEBUG)
313 bb_error_msg("unable to parse '%s'", debug_orig); 302 bb_error_msg("cannot parse '%s'", debug_orig);
314 /* reset back to the default value */ 303 /* reset back to the default value */
315 keywords[i].handler(keywords[i].def, keywords[i].var); 304 keywords[i].handler(keywords[i].def, keywords[i].var);
316 } 305 }
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 @@
1/* vi: set sw=4 ts=4: */
2/* files.h */
3#ifndef _FILES_H
4#define _FILES_H
5
6struct config_keyword {
7 const char *keyword;
8 int (* const handler)(const char *line, void *var);
9 void *var;
10 const char *def;
11};
12
13
14int read_config(const char *file);
15void write_leases(void);
16void read_leases(const char *file);
17
18struct option_set *find_option(struct option_set *opt_list, char code);
19
20#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 @@
4 * Russ Dill <Russ.Dill@asu.edu> July 2001 4 * Russ Dill <Russ.Dill@asu.edu> July 2001
5 */ 5 */
6 6
7#include <time.h>
8#include <string.h>
9#include <sys/socket.h>
10#include <netinet/in.h>
11#include <arpa/inet.h>
12
13#include "dhcpd.h"
14#include "files.h"
15#include "options.h"
16#include "leases.h"
17#include "arpping.h"
18#include "common.h" 7#include "common.h"
19 8#include "dhcpd.h"
20#include "static_leases.h"
21 9
22 10
23uint8_t blank_chaddr[] = {[0 ... 15] = 0}; 11uint8_t blank_chaddr[] = {[0 ... 15] = 0};
@@ -138,22 +126,20 @@ uint32_t find_address(int check_expired)
138 if ((addr & 0xFF) == 0xFF) continue; 126 if ((addr & 0xFF) == 0xFF) continue;
139 127
140 /* Only do if it isn't an assigned as a static lease */ 128 /* Only do if it isn't an assigned as a static lease */
141 if(!reservedIp(server_config.static_leases, htonl(addr))) 129 if (!reservedIp(server_config.static_leases, htonl(addr))) {
142 { 130
143 131 /* lease is not taken */
144 /* lease is not taken */ 132 ret = htonl(addr);
145 ret = htonl(addr); 133 lease = find_lease_by_yiaddr(ret);
146 if ((!(lease = find_lease_by_yiaddr(ret)) || 134
147 135 /* no lease or it expired and we are checking for expired leases */
148 /* or it expired and we are checking for expired leases */ 136 if ( (!lease || (check_expired && lease_expired(lease)))
149 (check_expired && lease_expired(lease))) && 137 && /* and it isn't on the network */ !check_ip(ret)
150 138 ) {
151 /* and it isn't on the network */ 139 return ret;
152 !check_ip(ret)) { 140 break;
153 return ret; 141 }
154 break;
155 } 142 }
156 } 143 }
157 }
158 return 0; 144 return 0;
159} 145}
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 @@
1/* vi: set sw=4 ts=4: */
2/* leases.h */
3#ifndef _LEASES_H
4#define _LEASES_H
5
6
7struct dhcpOfferedAddr {
8 uint8_t chaddr[16];
9 uint32_t yiaddr; /* network order */
10 uint32_t expires; /* host order */
11};
12
13extern uint8_t blank_chaddr[];
14
15void clear_lease(uint8_t *chaddr, uint32_t yiaddr);
16struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease);
17int lease_expired(struct dhcpOfferedAddr *lease);
18struct dhcpOfferedAddr *oldest_expired_lease(void);
19struct dhcpOfferedAddr *find_lease_by_chaddr(uint8_t *chaddr);
20struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr);
21uint32_t find_address(int check_expired);
22
23
24#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 @@
1/* vi: set sw=4 ts=4: */
2/* libbb_udhcp.h - busybox compatibility wrapper */
3
4/* bit of a hack, do this no matter what the order of the includes.
5 * (for busybox) */
6
7#ifndef _LIBBB_UDHCP_H
8#define _LIBBB_UDHCP_H
9
10#include "packet.h"
11#include "busybox.h"
12
13#ifdef CONFIG_INSTALL_NO_USR
14# define DEFAULT_SCRIPT "/share/udhcpc/default.script"
15#else
16# define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script"
17#endif
18
19
20
21#define COMBINED_BINARY
22
23void udhcp_background(const char *pidfile);
24void udhcp_start_log_and_pid(const char *pidfile);
25
26void udhcp_run_script(struct dhcpMessage *packet, const char *name);
27
28// Still need to clean these up...
29
30/* from pidfile.h */
31#define pidfile_acquire udhcp_pidfile_acquire
32#define pidfile_write_release udhcp_pidfile_write_release
33/* from options.h */
34#define get_option udhcp_get_option
35#define end_option udhcp_end_option
36#define add_option_string udhcp_add_option_string
37#define add_simple_option udhcp_add_simple_option
38#define option_lengths udhcp_option_lengths
39/* from socket.h */
40#define listen_socket udhcp_listen_socket
41#define read_interface udhcp_read_interface
42/* from dhcpc.h */
43#define client_config udhcp_client_config
44/* from dhcpd.h */
45#define server_config udhcp_server_config
46
47#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 @@
4 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001 4 * Rewrite by Russ Dill <Russ.Dill@asu.edu> July 2001
5 */ 5 */
6 6
7#include <stdlib.h>
8#include <string.h>
9
10#include "common.h" 7#include "common.h"
11#include "dhcpd.h" 8#include "dhcpd.h"
12#include "options.h" 9#include "options.h"
13#include "files.h"
14 10
15 11
16/* supported options are easily added here */ 12/* 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 @@
3#ifndef _OPTIONS_H 3#ifndef _OPTIONS_H
4#define _OPTIONS_H 4#define _OPTIONS_H
5 5
6#include "packet.h"
7
8#define TYPE_MASK 0x0F 6#define TYPE_MASK 0x0F
9 7
10enum { 8enum {
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 @@
1/* vi: set sw=4 ts=4: */ 1/* vi: set sw=4 ts=4: */
2#include <unistd.h> 2
3#include <string.h>
4#include <netinet/in.h> 3#include <netinet/in.h>
5#include <sys/types.h>
6#include <sys/socket.h>
7#include <features.h>
8#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION 4#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
9#include <netpacket/packet.h> 5#include <netpacket/packet.h>
10#include <net/ethernet.h> 6#include <net/ethernet.h>
@@ -13,10 +9,8 @@
13#include <linux/if_packet.h> 9#include <linux/if_packet.h>
14#include <linux/if_ether.h> 10#include <linux/if_ether.h>
15#endif 11#endif
16#include <errno.h>
17 12
18#include "common.h" 13#include "common.h"
19#include "packet.h"
20#include "dhcpd.h" 14#include "dhcpd.h"
21#include "options.h" 15#include "options.h"
22 16
@@ -70,8 +64,9 @@ int udhcp_get_packet(struct dhcpMessage *packet, int fd)
70 64
71 if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) { 65 if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) {
72 for (i = 0; broken_vendors[i][0]; i++) { 66 for (i = 0; broken_vendors[i][0]; i++) {
73 if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) && 67 if (vendor[OPT_LEN - 2] == (uint8_t)strlen(broken_vendors[i])
74 !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])) { 68 && !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])
69 ) {
75 DEBUG("broken client (%s), forcing broadcast", 70 DEBUG("broken client (%s), forcing broadcast",
76 broken_vendors[i]); 71 broken_vendors[i]);
77 packet->flags |= htons(BROADCAST_FLAG); 72 packet->flags |= htons(BROADCAST_FLAG);
@@ -114,15 +109,17 @@ uint16_t udhcp_checksum(void *addr, int count)
114 109
115 110
116/* Construct a ip/udp header for a packet, and specify the source and dest hardware address */ 111/* Construct a ip/udp header for a packet, and specify the source and dest hardware address */
117int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, 112int udhcp_raw_packet(struct dhcpMessage *payload,
118 uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex) 113 uint32_t source_ip, int source_port,
114 uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex)
119{ 115{
120 int fd; 116 int fd;
121 int result; 117 int result;
122 struct sockaddr_ll dest; 118 struct sockaddr_ll dest;
123 struct udp_dhcp_packet packet; 119 struct udp_dhcp_packet packet;
124 120
125 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { 121 fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
122 if (fd < 0) {
126 bb_perror_msg("socket"); 123 bb_perror_msg("socket");
127 return -1; 124 return -1;
128 } 125 }
@@ -157,7 +154,8 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
157 packet.ip.ttl = IPDEFTTL; 154 packet.ip.ttl = IPDEFTTL;
158 packet.ip.check = udhcp_checksum(&(packet.ip), sizeof(packet.ip)); 155 packet.ip.check = udhcp_checksum(&(packet.ip), sizeof(packet.ip));
159 156
160 result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest)); 157 result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0,
158 (struct sockaddr *) &dest, sizeof(dest));
161 if (result <= 0) { 159 if (result <= 0) {
162 bb_perror_msg("sendto"); 160 bb_perror_msg("sendto");
163 } 161 }
@@ -167,14 +165,16 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
167 165
168 166
169/* Let the kernel do all the work for packet generation */ 167/* Let the kernel do all the work for packet generation */
170int udhcp_kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port, 168int udhcp_kernel_packet(struct dhcpMessage *payload,
171 uint32_t dest_ip, int dest_port) 169 uint32_t source_ip, int source_port,
170 uint32_t dest_ip, int dest_port)
172{ 171{
173 int n = 1; 172 int n = 1;
174 int fd, result; 173 int fd, result;
175 struct sockaddr_in client; 174 struct sockaddr_in client;
176 175
177 if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) 176 fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
177 if (fd < 0)
178 return -1; 178 return -1;
179 179
180 if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &n, sizeof(n)) == -1) { 180 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 @@
1/* vi: set sw=4 ts=4: */
2#ifndef _PACKET_H
3#define _PACKET_H
4
5#include <netinet/udp.h>
6#include <netinet/ip.h>
7
8struct dhcpMessage {
9 uint8_t op;
10 uint8_t htype;
11 uint8_t hlen;
12 uint8_t hops;
13 uint32_t xid;
14 uint16_t secs;
15 uint16_t flags;
16 uint32_t ciaddr;
17 uint32_t yiaddr;
18 uint32_t siaddr;
19 uint32_t giaddr;
20 uint8_t chaddr[16];
21 uint8_t sname[64];
22 uint8_t file[128];
23 uint32_t cookie;
24 uint8_t options[308]; /* 312 - cookie */
25};
26
27struct udp_dhcp_packet {
28 struct iphdr ip;
29 struct udphdr udp;
30 struct dhcpMessage data;
31};
32
33void udhcp_init_header(struct dhcpMessage *packet, char type);
34int udhcp_get_packet(struct dhcpMessage *packet, int fd);
35uint16_t udhcp_checksum(void *addr, int count);
36int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
37 uint32_t dest_ip, int dest_port, uint8_t *dest_arp, int ifindex);
38int udhcp_kernel_packet(struct dhcpMessage *payload, uint32_t source_ip, int source_port,
39 uint32_t dest_ip, int dest_port);
40
41
42#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 @@
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <fcntl.h>
26#include <unistd.h>
27#include <stdio.h>
28#include <stdlib.h>
29
30#include "common.h" 23#include "common.h"
31#include "pidfile.h" 24
32 25
33static char *saved_pidfile; 26static char *saved_pidfile;
34 27
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 @@
1/* vi: set sw=4 ts=4: */
2/* pidfile.h
3 *
4 * Functions to assist in the writing and removing of pidfiles.
5 *
6 * Russ Dill <Russ.Dill@asu.edu> September 2001
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23
24int pidfile_acquire(const char *pidfile);
25void pidfile_write_release(int pid_fd);
26
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 @@
8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 8 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
9 */ 9 */
10 10
11#include <string.h>
12#include <unistd.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <sys/socket.h>
16#include <netinet/in.h>
17#include <arpa/inet.h>
18#include <sys/types.h>
19#include <sys/wait.h>
20
21#include "common.h" 11#include "common.h"
22#include "options.h"
23#include "dhcpd.h" 12#include "dhcpd.h"
24#include "dhcpc.h" 13#include "dhcpc.h"
14#include "options.h"
15
25 16
26/* get a rough idea of how long an option will be (rounding up...) */ 17/* get a rough idea of how long an option will be (rounding up...) */
27static const int max_option_length[] = { 18static const int max_option_length[] = {
@@ -76,7 +67,7 @@ static void fill_options(char *dest, uint8_t *option, struct dhcp_option *type_p
76 67
77 type = type_p->flags & TYPE_MASK; 68 type = type_p->flags & TYPE_MASK;
78 optlen = option_lengths[type]; 69 optlen = option_lengths[type];
79 for(;;) { 70 for (;;) {
80 switch (type) { 71 switch (type) {
81 case OPTION_IP_PAIR: 72 case OPTION_IP_PAIR:
82 dest += sprintip(dest, "", option); 73 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 @@
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#include <sys/socket.h>
24#include <netinet/in.h>
25#include <arpa/inet.h>
26#include <string.h>
27#include <time.h>
28
29#include "common.h" 23#include "common.h"
30#include "serverpacket.h"
31#include "dhcpd.h" 24#include "dhcpd.h"
32#include "options.h" 25#include "options.h"
33#include "static_leases.h" 26
34 27
35/* send a packet to giaddr using the kernel ip stack */ 28/* send a packet to giaddr using the kernel ip stack */
36static int send_packet_to_relay(struct dhcpMessage *payload) 29static int send_packet_to_relay(struct dhcpMessage *payload)
@@ -122,65 +115,57 @@ int sendOffer(struct dhcpMessage *oldpacket)
122 static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr); 115 static_lease_ip = getIpByMac(server_config.static_leases, oldpacket->chaddr);
123 116
124 /* ADDME: if static, short circuit */ 117 /* ADDME: if static, short circuit */
125 if(!static_lease_ip) 118 if (!static_lease_ip) {
126 { 119 /* the client is in our lease/offered table */
127 /* the client is in our lease/offered table */ 120 lease = find_lease_by_chaddr(oldpacket->chaddr);
128 if ((lease = find_lease_by_chaddr(oldpacket->chaddr))) { 121 if (lease) {
129 if (!lease_expired(lease)) 122 if (!lease_expired(lease))
130 lease_time_align = lease->expires - time(0); 123 lease_time_align = lease->expires - time(0);
131 packet.yiaddr = lease->yiaddr; 124 packet.yiaddr = lease->yiaddr;
132 125
133 /* Or the client has a requested ip */ 126 /* Or the client has a requested ip */
134 } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) && 127 } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP))
135 128 /* Don't look here (ugly hackish thing to do) */
136 /* Don't look here (ugly hackish thing to do) */ 129 && memcpy(&req_align, req, 4)
137 memcpy(&req_align, req, 4) && 130 /* and the ip is in the lease range */
138 131 && ntohl(req_align) >= ntohl(server_config.start)
139 /* and the ip is in the lease range */ 132 && ntohl(req_align) <= ntohl(server_config.end)
140 ntohl(req_align) >= ntohl(server_config.start) && 133 && !static_lease_ip /* Check that its not a static lease */
141 ntohl(req_align) <= ntohl(server_config.end) &&
142
143 !static_lease_ip && /* Check that its not a static lease */
144 /* and is not already taken/offered */ 134 /* and is not already taken/offered */
145 ((!(lease = find_lease_by_yiaddr(req_align)) || 135 && (!(lease = find_lease_by_yiaddr(req_align))
146 136 /* or its taken, but expired */ /* ADDME: or maybe in here */
147 /* or its taken, but expired */ /* ADDME: or maybe in here */ 137 || lease_expired(lease))
148 lease_expired(lease)))) { 138 ) {
149 packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */ 139 packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */
150
151 /* otherwise, find a free IP */ 140 /* otherwise, find a free IP */
152 } else { 141 } else {
153 /* Is it a static lease? (No, because find_address skips static lease) */ 142 /* Is it a static lease? (No, because find_address skips static lease) */
154 packet.yiaddr = find_address(0); 143 packet.yiaddr = find_address(0);
155 144 /* try for an expired lease */
156 /* try for an expired lease */ 145 if (!packet.yiaddr) packet.yiaddr = find_address(1);
157 if (!packet.yiaddr) packet.yiaddr = find_address(1); 146 }
158 } 147
159 148 if (!packet.yiaddr) {
160 if(!packet.yiaddr) { 149 bb_error_msg("no IP addresses to give - OFFER abandoned");
161 bb_error_msg("no IP addresses to give - OFFER abandoned"); 150 return -1;
162 return -1; 151 }
163 } 152 if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
164 153 bb_error_msg("lease pool is full - OFFER abandoned");
165 if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) { 154 return -1;
166 bb_error_msg("lease pool is full - OFFER abandoned"); 155 }
167 return -1; 156 lease_time = get_option(oldpacket, DHCP_LEASE_TIME);
168 } 157 if (lease_time) {
169 158 memcpy(&lease_time_align, lease_time, 4);
170 if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) { 159 lease_time_align = ntohl(lease_time_align);
171 memcpy(&lease_time_align, lease_time, 4); 160 if (lease_time_align > server_config.lease)
172 lease_time_align = ntohl(lease_time_align); 161 lease_time_align = server_config.lease;
173 if (lease_time_align > server_config.lease) 162 }
163
164 /* Make sure we aren't just using the lease time from the previous offer */
165 if (lease_time_align < server_config.min_lease)
174 lease_time_align = server_config.lease; 166 lease_time_align = server_config.lease;
175 } 167 /* ADDME: end of short circuit */
176 168 } else {
177 /* Make sure we aren't just using the lease time from the previous offer */
178 if (lease_time_align < server_config.min_lease)
179 lease_time_align = server_config.lease;
180 }
181 /* ADDME: end of short circuit */
182 else
183 {
184 /* It is a static lease... use it */ 169 /* It is a static lease... use it */
185 packet.yiaddr = static_lease_ip; 170 packet.yiaddr = static_lease_ip;
186 } 171 }
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 @@
1/* vi: set sw=4 ts=4: */
2#ifndef _SERVERPACKET_H
3#define _SERVERPACKET_H
4
5#include "packet.h"
6
7int sendOffer(struct dhcpMessage *oldpacket);
8int sendNAK(struct dhcpMessage *oldpacket);
9int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr);
10int send_inform(struct dhcpMessage *oldpacket);
11
12
13#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 @@
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */ 21 */
22 22
23#include <unistd.h>
24#include <fcntl.h>
25#include <signal.h>
26#include <sys/types.h>
27#include <sys/socket.h>
28#include <sys/select.h>
29
30
31#include "signalpipe.h"
32#include "common.h" 23#include "common.h"
33 24
25
34static int signal_pipe[2]; 26static int signal_pipe[2];
35 27
36static void signal_handler(int sig) 28static 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 @@
1/* vi: set sw=4 ts=4: */
2/* signalpipe.h
3 *
4 * Russ Dill <Russ.Dill@asu.edu> December 2003
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21void udhcp_sp_setup(void);
22int udhcp_sp_fd_set(fd_set *rfds, int extra_fd);
23int 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 @@
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */ 24 */
25 25
26#include <sys/types.h>
27#include <sys/socket.h>
28#include <sys/ioctl.h>
29#include <netinet/in.h>
30#include <unistd.h>
31#include <string.h>
32#include <arpa/inet.h>
33#include <net/if.h> 26#include <net/if.h>
34#include <errno.h>
35#include <features.h> 27#include <features.h>
36#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION 28#if (__GLIBC__ >= 2 && __GLIBC_MINOR__ >= 1) || defined _NEWLIB_VERSION
37#include <netpacket/packet.h> 29#include <netpacket/packet.h>
@@ -43,7 +35,7 @@
43#endif 35#endif
44 36
45#include "common.h" 37#include "common.h"
46#include "socket.h" 38
47 39
48int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp) 40int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp)
49{ 41{
@@ -52,44 +44,42 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp)
52 struct sockaddr_in *our_ip; 44 struct sockaddr_in *our_ip;
53 45
54 memset(&ifr, 0, sizeof(struct ifreq)); 46 memset(&ifr, 0, sizeof(struct ifreq));
55 if((fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) { 47 fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
56 ifr.ifr_addr.sa_family = AF_INET; 48 if (fd < 0) {
57 strcpy(ifr.ifr_name, interface); 49 bb_perror_msg("socket failed");
58 50 return -1;
59 if (addr) { 51 }
60 if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
61 our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
62 *addr = our_ip->sin_addr.s_addr;
63 DEBUG("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
64 } else {
65 bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?");
66 close(fd);
67 return -1;
68 }
69 }
70 52
71 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) { 53 ifr.ifr_addr.sa_family = AF_INET;
72 DEBUG("adapter index %d", ifr.ifr_ifindex); 54 strcpy(ifr.ifr_name, interface);
73 *ifindex = ifr.ifr_ifindex; 55 if (addr) {
74 } else { 56 if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
75 bb_perror_msg("SIOCGIFINDEX failed"); 57 bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?");
76 close(fd); 58 close(fd);
77 return -1; 59 return -1;
78 } 60 }
79 if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) { 61 our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
80 memcpy(arp, ifr.ifr_hwaddr.sa_data, 6); 62 *addr = our_ip->sin_addr.s_addr;
81 DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x", 63 DEBUG("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
82 arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]); 64 }
83 } else { 65
84 bb_perror_msg("SIOCGIFHWADDR failed"); 66 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) {
85 close(fd); 67 bb_perror_msg("SIOCGIFINDEX failed");
86 return -1; 68 close(fd);
87 } 69 return -1;
88 } else { 70 }
89 bb_perror_msg("socket failed"); 71
72 DEBUG("adapter index %d", ifr.ifr_ifindex);
73 *ifindex = ifr.ifr_ifindex;
74 if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0) {
75 bb_perror_msg("SIOCGIFHWADDR failed");
76 close(fd);
90 return -1; 77 return -1;
91 } 78 }
92 close(fd); 79
80 memcpy(arp, ifr.ifr_hwaddr.sa_data, 6);
81 DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
82 arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
93 return 0; 83 return 0;
94} 84}
95 85
@@ -102,7 +92,8 @@ int listen_socket(uint32_t ip, int port, char *inf)
102 int n = 1; 92 int n = 1;
103 93
104 DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf); 94 DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf);
105 if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { 95 fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
96 if (fd < 0) {
106 bb_perror_msg("socket"); 97 bb_perror_msg("socket");
107 return -1; 98 return -1;
108 } 99 }
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 @@
1/* vi: set sw=4 ts=4: */
2/* socket.h */
3#ifndef _SOCKET_H
4#define _SOCKET_H
5
6int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp);
7int listen_socket(uint32_t ip, int port, char *inf);
8
9#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 @@
7 * 7 *
8 */ 8 */
9 9
10 10#include "common.h"
11#include <stdlib.h>
12#include <stdio.h>
13#include <string.h>
14
15#include "static_leases.h"
16#include "dhcpd.h" 11#include "dhcpd.h"
17 12
13
18/* Takes the address of the pointer to the static_leases linked list, 14/* Takes the address of the pointer to the static_leases linked list,
19 * Address to a 6 byte mac address 15 * Address to a 6 byte mac address
20 * Address to a 4 byte ip address */ 16 * Address to a 4 byte ip address */
21int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip) 17int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip)
22{ 18{
23
24 struct static_lease *cur; 19 struct static_lease *cur;
25 struct static_lease *new_static_lease; 20 struct static_lease *new_static_lease;
26 21
@@ -31,15 +26,11 @@ int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *i
31 new_static_lease->next = NULL; 26 new_static_lease->next = NULL;
32 27
33 /* If it's the first node to be added... */ 28 /* If it's the first node to be added... */
34 if(*lease_struct == NULL) 29 if (*lease_struct == NULL) {
35 {
36 *lease_struct = new_static_lease; 30 *lease_struct = new_static_lease;
37 } 31 } else {
38 else
39 {
40 cur = *lease_struct; 32 cur = *lease_struct;
41 while(cur->next != NULL) 33 while (cur->next) {
42 {
43 cur = cur->next; 34 cur = cur->next;
44 } 35 }
45 36
@@ -47,7 +38,6 @@ int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *i
47 } 38 }
48 39
49 return 1; 40 return 1;
50
51} 41}
52 42
53/* Check to see if a mac has an associated static lease */ 43/* 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)
59 49
60 return_ip = 0; 50 return_ip = 0;
61 51
62 while(cur != NULL) 52 while (cur) {
63 {
64 /* If the client has the correct mac */ 53 /* If the client has the correct mac */
65 if(memcmp(cur->mac, mac, 6) == 0) 54 if (memcmp(cur->mac, mac, 6) == 0) {
66 {
67 return_ip = *(cur->ip); 55 return_ip = *(cur->ip);
68 } 56 }
69 57
@@ -71,7 +59,6 @@ uint32_t getIpByMac(struct static_lease *lease_struct, void *arg)
71 } 59 }
72 60
73 return return_ip; 61 return return_ip;
74
75} 62}
76 63
77/* Check to see if an ip is reserved as a static ip */ 64/* 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)
81 68
82 uint32_t return_val = 0; 69 uint32_t return_val = 0;
83 70
84 while(cur != NULL) 71 while (cur) {
85 {
86 /* If the client has the correct ip */ 72 /* If the client has the correct ip */
87 if(*cur->ip == ip) 73 if (*cur->ip == ip)
88 return_val = 1; 74 return_val = 1;
89 75
90 cur = cur->next; 76 cur = cur->next;
91 } 77 }
92 78
93 return return_val; 79 return return_val;
94
95} 80}
96 81
97#ifdef CONFIG_FEATURE_UDHCP_DEBUG 82#ifdef CONFIG_FEATURE_UDHCP_DEBUG
@@ -102,8 +87,7 @@ void printStaticLeases(struct static_lease **arg)
102 /* Get a pointer to the linked list */ 87 /* Get a pointer to the linked list */
103 struct static_lease *cur = *arg; 88 struct static_lease *cur = *arg;
104 89
105 while(cur != NULL) 90 while (cur) {
106 {
107 /* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */ 91 /* printf("PrintStaticLeases: Lease mac Address: %x\n", cur->mac); */
108 printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac)); 92 printf("PrintStaticLeases: Lease mac Value: %x\n", *(cur->mac));
109 /* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */ 93 /* printf("PrintStaticLeases: Lease ip Address: %x\n", cur->ip); */
@@ -111,10 +95,5 @@ void printStaticLeases(struct static_lease **arg)
111 95
112 cur = cur->next; 96 cur = cur->next;
113 } 97 }
114
115
116} 98}
117#endif 99#endif
118
119
120
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 @@
1/* vi: set sw=4 ts=4: */
2/* static_leases.h */
3#ifndef _STATIC_LEASES_H
4#define _STATIC_LEASES_H
5
6#include "dhcpd.h"
7
8/* Config file will pass static lease info to this function which will add it
9 * to a data structure that can be searched later */
10int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip);
11
12/* Check to see if a mac has an associated static lease */
13uint32_t getIpByMac(struct static_lease *lease_struct, void *arg);
14
15/* Check to see if an ip is reserved as a static ip */
16uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip);
17
18/* Print out static leases just to check what's going on (debug code) */
19void printStaticLeases(struct static_lease **lease_struct);
20
21#endif
22
23
24