summaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-06 18:36:50 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-06 18:36:50 +0000
commit3538b9a8822421b7c8596a33a917dcf2f99c92b7 (patch)
tree768c23fe79bb81583de7376a4d744632d888d303 /networking/udhcp
parent5d725462d44268f9a86030daaa6f6396d32f796c (diff)
downloadbusybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.tar.gz
busybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.tar.bz2
busybox-w32-3538b9a8822421b7c8596a33a917dcf2f99c92b7.zip
Implement optional syslog logging using ordinary
bb_xx_msg calls, and convert networking/* to it. The rest of bbox will be converted gradually.
Diffstat (limited to 'networking/udhcp')
-rw-r--r--networking/udhcp/arpping.c12
-rw-r--r--networking/udhcp/clientpacket.c27
-rw-r--r--networking/udhcp/clientsocket.c6
-rw-r--r--networking/udhcp/common.c71
-rw-r--r--networking/udhcp/common.h18
-rw-r--r--networking/udhcp/dhcpc.c42
-rw-r--r--networking/udhcp/dhcpd.c32
-rw-r--r--networking/udhcp/files.c19
-rw-r--r--networking/udhcp/leases.c2
-rw-r--r--networking/udhcp/libbb_udhcp.h1
-rw-r--r--networking/udhcp/options.c13
-rw-r--r--networking/udhcp/packet.c14
-rw-r--r--networking/udhcp/pidfile.c2
-rw-r--r--networking/udhcp/script.c4
-rw-r--r--networking/udhcp/serverpacket.c20
-rw-r--r--networking/udhcp/signalpipe.c2
-rw-r--r--networking/udhcp/socket.c18
17 files changed, 124 insertions, 179 deletions
diff --git a/networking/udhcp/arpping.c b/networking/udhcp/arpping.c
index 6e254f604..587339f9b 100644
--- a/networking/udhcp/arpping.c
+++ b/networking/udhcp/arpping.c
@@ -43,13 +43,13 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
43 time_t prevTime; 43 time_t prevTime;
44 44
45 45
46 if ((s = socket (PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) == -1) { 46 if ((s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) == -1) {
47 LOG(LOG_ERR, bb_msg_can_not_create_raw_socket); 47 bb_perror_msg(bb_msg_can_not_create_raw_socket);
48 return -1; 48 return -1;
49 } 49 }
50 50
51 if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) { 51 if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) {
52 LOG(LOG_ERR, "Could not setsocketopt on raw socket"); 52 bb_perror_msg("Could not setsocketopt on raw socket");
53 close(s); 53 close(s);
54 return -1; 54 return -1;
55 } 55 }
@@ -81,14 +81,14 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
81 FD_SET(s, &fdset); 81 FD_SET(s, &fdset);
82 tm.tv_sec = timeout; 82 tm.tv_sec = timeout;
83 if (select(s + 1, &fdset, (fd_set *) NULL, (fd_set *) NULL, &tm) < 0) { 83 if (select(s + 1, &fdset, (fd_set *) NULL, (fd_set *) NULL, &tm) < 0) {
84 DEBUG(LOG_ERR, "Error on ARPING request: %m"); 84 bb_perror_msg("Error on ARPING request");
85 if (errno != EINTR) rv = 0; 85 if (errno != EINTR) rv = 0;
86 } else if (FD_ISSET(s, &fdset)) { 86 } else if (FD_ISSET(s, &fdset)) {
87 if (recv(s, &arp, sizeof(arp), 0) < 0 ) rv = 0; 87 if (recv(s, &arp, sizeof(arp), 0) < 0 ) rv = 0;
88 if (arp.operation == htons(ARPOP_REPLY) && 88 if (arp.operation == htons(ARPOP_REPLY) &&
89 memcmp(arp.tHaddr, mac, 6) == 0 && 89 memcmp(arp.tHaddr, mac, 6) == 0 &&
90 *((uint32_t *) arp.sInaddr) == yiaddr) { 90 *((uint32_t *) arp.sInaddr) == yiaddr) {
91 DEBUG(LOG_INFO, "Valid arp reply receved for this address"); 91 DEBUG("Valid arp reply received for this address");
92 rv = 0; 92 rv = 0;
93 break; 93 break;
94 } 94 }
@@ -97,6 +97,6 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
97 prevTime = uptime(); 97 prevTime = uptime();
98 } 98 }
99 close(s); 99 close(s);
100 DEBUG(LOG_INFO, "%salid arp replies for this address", rv ? "No v" : "V"); 100 DEBUG("%salid arp replies for this address", rv ? "No v" : "V");
101 return rv; 101 return rv;
102} 102}
diff --git a/networking/udhcp/clientpacket.c b/networking/udhcp/clientpacket.c
index 82975700c..f7e7d442c 100644
--- a/networking/udhcp/clientpacket.c
+++ b/networking/udhcp/clientpacket.c
@@ -44,7 +44,8 @@ unsigned long random_xid(void)
44 44
45 fd = open("/dev/urandom", 0); 45 fd = open("/dev/urandom", 0);
46 if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) { 46 if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) {
47 LOG(LOG_WARNING, "Could not load seed from /dev/urandom: %m"); 47 bb_info_msg("Could not load seed "
48 "from /dev/urandom: %s", strerror(errno));
48 seed = time(0); 49 seed = time(0);
49 } 50 }
50 if (fd >= 0) close(fd); 51 if (fd >= 0) close(fd);
@@ -97,7 +98,7 @@ int send_discover(unsigned long xid, unsigned long requested)
97 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested); 98 add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
98 99
99 add_requests(&packet); 100 add_requests(&packet);
100 LOG(LOG_DEBUG, "Sending discover..."); 101 bb_info_msg("Sending discover...");
101 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 102 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
102 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 103 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
103} 104}
@@ -117,7 +118,7 @@ int send_selecting(unsigned long xid, unsigned long server, unsigned long reques
117 118
118 add_requests(&packet); 119 add_requests(&packet);
119 addr.s_addr = requested; 120 addr.s_addr = requested;
120 LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr)); 121 bb_info_msg("Sending select for %s...", inet_ntoa(addr));
121 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 122 return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
122 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); 123 SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
123} 124}
@@ -134,7 +135,7 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr)
134 packet.ciaddr = ciaddr; 135 packet.ciaddr = ciaddr;
135 136
136 add_requests(&packet); 137 add_requests(&packet);
137 LOG(LOG_DEBUG, "Sending renew..."); 138 bb_info_msg("Sending renew...");
138 if (server) 139 if (server)
139 ret = udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); 140 ret = udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
140 else ret = udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, 141 else ret = udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
@@ -155,7 +156,7 @@ int send_release(unsigned long server, unsigned long ciaddr)
155 add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr); 156 add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr);
156 add_simple_option(packet.options, DHCP_SERVER_ID, server); 157 add_simple_option(packet.options, DHCP_SERVER_ID, server);
157 158
158 LOG(LOG_DEBUG, "Sending release..."); 159 bb_info_msg("Sending release...");
159 return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); 160 return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
160} 161}
161 162
@@ -171,18 +172,18 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
171 memset(&packet, 0, sizeof(struct udp_dhcp_packet)); 172 memset(&packet, 0, sizeof(struct udp_dhcp_packet));
172 bytes = read(fd, &packet, sizeof(struct udp_dhcp_packet)); 173 bytes = read(fd, &packet, sizeof(struct udp_dhcp_packet));
173 if (bytes < 0) { 174 if (bytes < 0) {
174 DEBUG(LOG_INFO, "couldn't read on raw listening socket -- ignoring"); 175 DEBUG("Couldn't read on raw listening socket - ignoring");
175 usleep(500000); /* possible down interface, looping condition */ 176 usleep(500000); /* possible down interface, looping condition */
176 return -1; 177 return -1;
177 } 178 }
178 179
179 if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) { 180 if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) {
180 DEBUG(LOG_INFO, "message too short, ignoring"); 181 DEBUG("Message too short, ignoring");
181 return -2; 182 return -2;
182 } 183 }
183 184
184 if (bytes < ntohs(packet.ip.tot_len)) { 185 if (bytes < ntohs(packet.ip.tot_len)) {
185 DEBUG(LOG_INFO, "Truncated packet"); 186 DEBUG("Truncated packet");
186 return -2; 187 return -2;
187 } 188 }
188 189
@@ -194,7 +195,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
194 packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) || 195 packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) ||
195 bytes > (int) sizeof(struct udp_dhcp_packet) || 196 bytes > (int) sizeof(struct udp_dhcp_packet) ||
196 ntohs(packet.udp.len) != (uint16_t) (bytes - sizeof(packet.ip))) { 197 ntohs(packet.udp.len) != (uint16_t) (bytes - sizeof(packet.ip))) {
197 DEBUG(LOG_INFO, "unrelated/bogus packet"); 198 DEBUG("Unrelated/bogus packet");
198 return -2; 199 return -2;
199 } 200 }
200 201
@@ -202,7 +203,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
202 check = packet.ip.check; 203 check = packet.ip.check;
203 packet.ip.check = 0; 204 packet.ip.check = 0;
204 if (check != udhcp_checksum(&(packet.ip), sizeof(packet.ip))) { 205 if (check != udhcp_checksum(&(packet.ip), sizeof(packet.ip))) {
205 DEBUG(LOG_INFO, "bad IP header checksum, ignoring"); 206 DEBUG("bad IP header checksum, ignoring");
206 return -1; 207 return -1;
207 } 208 }
208 209
@@ -218,17 +219,17 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
218 packet.ip.daddr = dest; 219 packet.ip.daddr = dest;
219 packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */ 220 packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */
220 if (check && check != udhcp_checksum(&packet, bytes)) { 221 if (check && check != udhcp_checksum(&packet, bytes)) {
221 DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring"); 222 bb_error_msg("Packet with bad UDP checksum received, ignoring");
222 return -2; 223 return -2;
223 } 224 }
224 225
225 memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp))); 226 memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp)));
226 227
227 if (ntohl(payload->cookie) != DHCP_MAGIC) { 228 if (ntohl(payload->cookie) != DHCP_MAGIC) {
228 LOG(LOG_ERR, "received bogus message (bad magic) -- ignoring"); 229 bb_error_msg("Received bogus message (bad magic) - ignoring");
229 return -2; 230 return -2;
230 } 231 }
231 DEBUG(LOG_INFO, "oooooh!!! got some!"); 232 DEBUG("oooooh!!! got some!");
232 return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); 233 return bytes - (sizeof(packet.ip) + sizeof(packet.udp));
233 234
234} 235}
diff --git a/networking/udhcp/clientsocket.c b/networking/udhcp/clientsocket.c
index a1c4eadab..982aca1bb 100644
--- a/networking/udhcp/clientsocket.c
+++ b/networking/udhcp/clientsocket.c
@@ -44,9 +44,9 @@ int raw_socket(int ifindex)
44 int fd; 44 int fd;
45 struct sockaddr_ll sock; 45 struct sockaddr_ll sock;
46 46
47 DEBUG(LOG_INFO, "Opening raw socket on ifindex %d", ifindex); 47 DEBUG("Opening raw socket on ifindex %d", ifindex);
48 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { 48 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
49 DEBUG(LOG_ERR, "socket call failed: %m"); 49 bb_perror_msg("socket");
50 return -1; 50 return -1;
51 } 51 }
52 52
@@ -54,7 +54,7 @@ int raw_socket(int ifindex)
54 sock.sll_protocol = htons(ETH_P_IP); 54 sock.sll_protocol = htons(ETH_P_IP);
55 sock.sll_ifindex = ifindex; 55 sock.sll_ifindex = ifindex;
56 if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) { 56 if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) {
57 DEBUG(LOG_ERR, "bind call failed: %m"); 57 bb_perror_msg("bind:");
58 close(fd); 58 close(fd);
59 return -1; 59 return -1;
60 } 60 }
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index c2025e588..1ae65f750 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -19,6 +19,7 @@
19#include <paths.h> 19#include <paths.h>
20#include <sys/socket.h> 20#include <sys/socket.h>
21#include <stdarg.h> 21#include <stdarg.h>
22#include <syslog.h>
22 23
23#include "common.h" 24#include "common.h"
24#include "pidfile.h" 25#include "pidfile.h"
@@ -33,7 +34,6 @@ long uptime(void)
33 return info.uptime; 34 return info.uptime;
34} 35}
35 36
36
37/* 37/*
38 * This function makes sure our first socket calls 38 * This function makes sure our first socket calls
39 * aren't going to fd 1 (printf badness...) and are 39 * aren't going to fd 1 (printf badness...) and are
@@ -41,77 +41,32 @@ long uptime(void)
41 */ 41 */
42static inline void sanitize_fds(void) 42static inline void sanitize_fds(void)
43{ 43{
44 int zero; 44 int fd = open(bb_dev_null, O_RDWR, 0);
45 if ((zero = open(bb_dev_null, O_RDWR, 0)) < 0) 45 if (fd < 0)
46 return; 46 return;
47 while (zero < 3) 47 while (fd < 3)
48 zero = dup(zero); 48 fd = dup(fd);
49 close(zero); 49 close(fd);
50} 50}
51 51
52 52
53void udhcp_background(const char *pidfile) 53void udhcp_background(const char *pidfile)
54{ 54{
55#ifdef __uClinux__ 55#ifdef __uClinux__
56 LOG(LOG_ERR, "Cannot background in uclinux (yet)"); 56 bb_error_msg("Cannot background in uclinux (yet)");
57#else /* __uClinux__ */ 57#else /* __uClinux__ */
58 int pid_fd; 58 int pid_fd;
59 59
60 /* hold lock during fork. */ 60 /* hold lock during fork. */
61 pid_fd = pidfile_acquire(pidfile); 61 pid_fd = pidfile_acquire(pidfile);
62 setsid();
62 xdaemon(0, 0); 63 xdaemon(0, 0);
63 daemonized++; 64 daemonized++;
65 logmode &= ~LOGMODE_STDIO;
64 pidfile_write_release(pid_fd); 66 pidfile_write_release(pid_fd);
65#endif /* __uClinux__ */ 67#endif /* __uClinux__ */
66} 68}
67 69
68
69#ifdef CONFIG_FEATURE_UDHCP_SYSLOG
70
71void udhcp_logging(int level, const char *fmt, ...)
72{
73 va_list p;
74 va_list p2;
75
76 va_start(p, fmt);
77 __va_copy(p2, p);
78 if (!daemonized) {
79 vprintf(fmt, p);
80 putchar('\n');
81 }
82 vsyslog(level, fmt, p2);
83 va_end(p);
84}
85
86#else
87
88
89static char *syslog_level_msg[] = {
90 [LOG_EMERG] = "EMERGENCY!",
91 [LOG_ALERT] = "ALERT!",
92 [LOG_CRIT] = "critical!",
93 [LOG_WARNING] = "warning",
94 [LOG_ERR] = "error",
95 [LOG_INFO] = "info",
96 [LOG_DEBUG] = "debug"
97};
98
99
100void udhcp_logging(int level, const char *fmt, ...)
101{
102 va_list p;
103
104 va_start(p, fmt);
105 if (!daemonized) {
106 printf("%s, ", syslog_level_msg[level]);
107 vprintf(fmt, p);
108 putchar('\n');
109 }
110 va_end(p);
111}
112#endif
113
114
115void udhcp_start_log_and_pid(const char *client_server, const char *pidfile) 70void udhcp_start_log_and_pid(const char *client_server, const char *pidfile)
116{ 71{
117 int pid_fd; 72 int pid_fd;
@@ -126,8 +81,10 @@ void udhcp_start_log_and_pid(const char *client_server, const char *pidfile)
126 /* equivelent of doing a fflush after every \n */ 81 /* equivelent of doing a fflush after every \n */
127 setlinebuf(stdout); 82 setlinebuf(stdout);
128 83
129 if (ENABLE_FEATURE_UDHCP_SYSLOG) 84 if (ENABLE_FEATURE_UDHCP_SYSLOG) {
130 openlog(client_server, LOG_PID | LOG_CONS, LOG_LOCAL0); 85 openlog(client_server, LOG_PID, LOG_LOCAL0);
86 logmode |= LOGMODE_SYSLOG;
87 }
131 88
132 udhcp_logging(LOG_INFO, "%s (v%s) started", client_server, BB_VER); 89 bb_info_msg("%s (v%s) started", client_server, BB_VER);
133} 90}
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index eb73c2162..d5291f2f3 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -12,26 +12,12 @@
12 12
13#include "libbb_udhcp.h" 13#include "libbb_udhcp.h"
14 14
15
16enum syslog_levels {
17 LOG_EMERG = 0,
18 LOG_ALERT,
19 LOG_CRIT,
20 LOG_WARNING,
21 LOG_ERR,
22 LOG_INFO,
23 LOG_DEBUG
24};
25#include <syslog.h>
26
27long uptime(void); 15long uptime(void);
28 16
29#define LOG(level, str, args...) udhcp_logging(level, str, ## args)
30
31#if ENABLE_FEATURE_UDHCP_DEBUG 17#if ENABLE_FEATURE_UDHCP_DEBUG
32# define DEBUG(level, str, args...) LOG(level, str, ## args) 18# define DEBUG(str, args...) bb_info_msg(str, ## args)
33#else 19#else
34# define DEBUG(level, str, args...) do {;} while(0) 20# define DEBUG(str, args...) do {;} while(0)
35#endif 21#endif
36 22
37#endif 23#endif
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 989759ab8..5b2612e56 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -65,7 +65,7 @@ struct client_config_t client_config = {
65/* just a little helper */ 65/* just a little helper */
66static void change_mode(int new_mode) 66static void change_mode(int new_mode)
67{ 67{
68 DEBUG(LOG_INFO, "entering %s listen mode", 68 DEBUG("entering %s listen mode",
69 new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none"); 69 new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none");
70 if (fd >= 0) close(fd); 70 if (fd >= 0) close(fd);
71 fd = -1; 71 fd = -1;
@@ -76,7 +76,7 @@ static void change_mode(int new_mode)
76/* perform a renew */ 76/* perform a renew */
77static void perform_renew(void) 77static void perform_renew(void)
78{ 78{
79 LOG(LOG_INFO, "Performing a DHCP renew"); 79 bb_info_msg("Performing a DHCP renew");
80 switch (state) { 80 switch (state) {
81 case BOUND: 81 case BOUND:
82 change_mode(LISTEN_KERNEL); 82 change_mode(LISTEN_KERNEL);
@@ -114,12 +114,12 @@ static void perform_release(void)
114 temp_addr.s_addr = server_addr; 114 temp_addr.s_addr = server_addr;
115 sprintf(buffer, "%s", inet_ntoa(temp_addr)); 115 sprintf(buffer, "%s", inet_ntoa(temp_addr));
116 temp_addr.s_addr = requested_ip; 116 temp_addr.s_addr = requested_ip;
117 LOG(LOG_INFO, "Unicasting a release of %s to %s", 117 bb_info_msg("Unicasting a release of %s to %s",
118 inet_ntoa(temp_addr), buffer); 118 inet_ntoa(temp_addr), buffer);
119 send_release(server_addr, requested_ip); /* unicast */ 119 send_release(server_addr, requested_ip); /* unicast */
120 udhcp_run_script(NULL, "deconfig"); 120 udhcp_run_script(NULL, "deconfig");
121 } 121 }
122 LOG(LOG_INFO, "Entering released state"); 122 bb_info_msg("Entering released state");
123 123
124 change_mode(LISTEN_NONE); 124 change_mode(LISTEN_NONE);
125 state = RELEASED; 125 state = RELEASED;
@@ -310,14 +310,14 @@ int udhcpc_main(int argc, char *argv[])
310 else 310 else
311 fd = raw_socket(client_config.ifindex); 311 fd = raw_socket(client_config.ifindex);
312 if (fd < 0) { 312 if (fd < 0) {
313 LOG(LOG_ERR, "FATAL: couldn't listen on socket, %m"); 313 bb_perror_msg("FATAL: couldn't listen on socket");
314 return 0; 314 return 0;
315 } 315 }
316 } 316 }
317 max_fd = udhcp_sp_fd_set(&rfds, fd); 317 max_fd = udhcp_sp_fd_set(&rfds, fd);
318 318
319 if (tv.tv_sec > 0) { 319 if (tv.tv_sec > 0) {
320 DEBUG(LOG_INFO, "Waiting on select..."); 320 DEBUG("Waiting on select...");
321 retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); 321 retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
322 } else retval = 0; /* If we already timed out, fall through */ 322 } else retval = 0; /* If we already timed out, fall through */
323 323
@@ -338,10 +338,10 @@ int udhcpc_main(int argc, char *argv[])
338 } else { 338 } else {
339 udhcp_run_script(NULL, "leasefail"); 339 udhcp_run_script(NULL, "leasefail");
340 if (client_config.background_if_no_lease) { 340 if (client_config.background_if_no_lease) {
341 LOG(LOG_INFO, "No lease, forking to background."); 341 bb_info_msg("No lease, forking to background");
342 client_background(); 342 client_background();
343 } else if (client_config.abort_if_no_lease) { 343 } else if (client_config.abort_if_no_lease) {
344 LOG(LOG_INFO, "No lease, failing."); 344 bb_info_msg("No lease, failing");
345 return 1; 345 return 1;
346 } 346 }
347 /* wait to try again */ 347 /* wait to try again */
@@ -372,7 +372,7 @@ int udhcpc_main(int argc, char *argv[])
372 /* Lease is starting to run out, time to enter renewing state */ 372 /* Lease is starting to run out, time to enter renewing state */
373 state = RENEWING; 373 state = RENEWING;
374 change_mode(LISTEN_KERNEL); 374 change_mode(LISTEN_KERNEL);
375 DEBUG(LOG_INFO, "Entering renew state"); 375 DEBUG("Entering renew state");
376 /* fall right through */ 376 /* fall right through */
377 case RENEWING: 377 case RENEWING:
378 /* Either set a new T1, or enter REBINDING state */ 378 /* Either set a new T1, or enter REBINDING state */
@@ -380,7 +380,7 @@ int udhcpc_main(int argc, char *argv[])
380 /* timed out, enter rebinding state */ 380 /* timed out, enter rebinding state */
381 state = REBINDING; 381 state = REBINDING;
382 timeout = now + (t2 - t1); 382 timeout = now + (t2 - t1);
383 DEBUG(LOG_INFO, "Entering rebinding state"); 383 DEBUG("Entering rebinding state");
384 } else { 384 } else {
385 /* send a request packet */ 385 /* send a request packet */
386 send_renew(xid, server_addr, requested_ip); /* unicast */ 386 send_renew(xid, server_addr, requested_ip); /* unicast */
@@ -394,7 +394,7 @@ int udhcpc_main(int argc, char *argv[])
394 if ((lease - t2) <= (lease / 14400 + 1)) { 394 if ((lease - t2) <= (lease / 14400 + 1)) {
395 /* timed out, enter init state */ 395 /* timed out, enter init state */
396 state = INIT_SELECTING; 396 state = INIT_SELECTING;
397 LOG(LOG_INFO, "Lease lost, entering init state"); 397 bb_info_msg("Lease lost, entering init state");
398 udhcp_run_script(NULL, "deconfig"); 398 udhcp_run_script(NULL, "deconfig");
399 timeout = now; 399 timeout = now;
400 packet_num = 0; 400 packet_num = 0;
@@ -420,25 +420,25 @@ int udhcpc_main(int argc, char *argv[])
420 else len = get_raw_packet(&packet, fd); 420 else len = get_raw_packet(&packet, fd);
421 421
422 if (len == -1 && errno != EINTR) { 422 if (len == -1 && errno != EINTR) {
423 DEBUG(LOG_INFO, "error on read, %m, reopening socket"); 423 DEBUG("error on read, %s, reopening socket", strerror(errno));
424 change_mode(listen_mode); /* just close and reopen */ 424 change_mode(listen_mode); /* just close and reopen */
425 } 425 }
426 if (len < 0) continue; 426 if (len < 0) continue;
427 427
428 if (packet.xid != xid) { 428 if (packet.xid != xid) {
429 DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)", 429 DEBUG("Ignoring XID %lx (our xid is %lx)",
430 (unsigned long) packet.xid, xid); 430 (unsigned long) packet.xid, xid);
431 continue; 431 continue;
432 } 432 }
433 433
434 /* Ignore packets that aren't for us */ 434 /* Ignore packets that aren't for us */
435 if (memcmp(packet.chaddr, client_config.arp, 6)) { 435 if (memcmp(packet.chaddr, client_config.arp, 6)) {
436 DEBUG(LOG_INFO, "packet does not have our chaddr -- ignoring"); 436 DEBUG("Packet does not have our chaddr - ignoring");
437 continue; 437 continue;
438 } 438 }
439 439
440 if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { 440 if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) {
441 DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring"); 441 bb_error_msg("Couldnt get option from packet - ignoring");
442 continue; 442 continue;
443 } 443 }
444 444
@@ -456,7 +456,7 @@ int udhcpc_main(int argc, char *argv[])
456 timeout = now; 456 timeout = now;
457 packet_num = 0; 457 packet_num = 0;
458 } else { 458 } else {
459 DEBUG(LOG_ERR, "No server ID in message"); 459 bb_error_msg("No server ID in message");
460 } 460 }
461 } 461 }
462 break; 462 break;
@@ -466,7 +466,7 @@ int udhcpc_main(int argc, char *argv[])
466 case REBINDING: 466 case REBINDING:
467 if (*message == DHCPACK) { 467 if (*message == DHCPACK) {
468 if (!(temp = get_option(&packet, DHCP_LEASE_TIME))) { 468 if (!(temp = get_option(&packet, DHCP_LEASE_TIME))) {
469 LOG(LOG_ERR, "No lease time with ACK, using 1 hour lease"); 469 bb_error_msg("No lease time with ACK, using 1 hour lease");
470 lease = 60 * 60; 470 lease = 60 * 60;
471 } else { 471 } else {
472 memcpy(&lease, temp, 4); 472 memcpy(&lease, temp, 4);
@@ -479,7 +479,7 @@ int udhcpc_main(int argc, char *argv[])
479 /* little fixed point for n * .875 */ 479 /* little fixed point for n * .875 */
480 t2 = (lease * 0x7) >> 3; 480 t2 = (lease * 0x7) >> 3;
481 temp_addr.s_addr = packet.yiaddr; 481 temp_addr.s_addr = packet.yiaddr;
482 LOG(LOG_INFO, "Lease of %s obtained, lease time %ld", 482 bb_info_msg("Lease of %s obtained, lease time %ld",
483 inet_ntoa(temp_addr), lease); 483 inet_ntoa(temp_addr), lease);
484 start = now; 484 start = now;
485 timeout = t1 + start; 485 timeout = t1 + start;
@@ -496,7 +496,7 @@ int udhcpc_main(int argc, char *argv[])
496 496
497 } else if (*message == DHCPNAK) { 497 } else if (*message == DHCPNAK) {
498 /* return to init state */ 498 /* return to init state */
499 LOG(LOG_INFO, "Received DHCP NAK"); 499 bb_info_msg("Received DHCP NAK");
500 udhcp_run_script(&packet, "nak"); 500 udhcp_run_script(&packet, "nak");
501 if (state != REQUESTING) 501 if (state != REQUESTING)
502 udhcp_run_script(NULL, "deconfig"); 502 udhcp_run_script(NULL, "deconfig");
@@ -519,14 +519,14 @@ int udhcpc_main(int argc, char *argv[])
519 perform_release(); 519 perform_release();
520 break; 520 break;
521 case SIGTERM: 521 case SIGTERM:
522 LOG(LOG_INFO, "Received SIGTERM"); 522 bb_info_msg("Received SIGTERM");
523 return 0; 523 return 0;
524 } 524 }
525 } else if (retval == -1 && errno == EINTR) { 525 } else if (retval == -1 && errno == EINTR) {
526 /* a signal was caught */ 526 /* a signal was caught */
527 } else { 527 } else {
528 /* An error occured */ 528 /* An error occured */
529 DEBUG(LOG_ERR, "Error on select"); 529 bb_perror_msg("select");
530 } 530 }
531 531
532 } 532 }
diff --git a/networking/udhcp/dhcpd.c b/networking/udhcp/dhcpd.c
index b481e6ef2..8715661b7 100644
--- a/networking/udhcp/dhcpd.c
+++ b/networking/udhcp/dhcpd.c
@@ -66,7 +66,7 @@ int udhcpd_main(int argc, char *argv[])
66 /* Sanity check */ 66 /* Sanity check */
67 num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1; 67 num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1;
68 if (server_config.max_leases > num_ips) { 68 if (server_config.max_leases > num_ips) {
69 LOG(LOG_ERR, "max_leases value (%lu) not sane, " 69 bb_error_msg("max_leases value (%lu) not sane, "
70 "setting to %lu instead", 70 "setting to %lu instead",
71 server_config.max_leases, num_ips); 71 server_config.max_leases, num_ips);
72 server_config.max_leases = num_ips; 72 server_config.max_leases = num_ips;
@@ -90,7 +90,7 @@ int udhcpd_main(int argc, char *argv[])
90 90
91 if (server_socket < 0) 91 if (server_socket < 0)
92 if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) { 92 if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) {
93 LOG(LOG_ERR, "FATAL: couldn't create server socket, %m"); 93 bb_perror_msg("FATAL: couldn't create server socket");
94 return 2; 94 return 2;
95 } 95 }
96 96
@@ -109,19 +109,19 @@ int udhcpd_main(int argc, char *argv[])
109 timeout_end = time(0) + server_config.auto_time; 109 timeout_end = time(0) + server_config.auto_time;
110 continue; 110 continue;
111 } else if (retval < 0 && errno != EINTR) { 111 } else if (retval < 0 && errno != EINTR) {
112 DEBUG(LOG_INFO, "error on select"); 112 DEBUG("error on select");
113 continue; 113 continue;
114 } 114 }
115 115
116 switch (udhcp_sp_read(&rfds)) { 116 switch (udhcp_sp_read(&rfds)) {
117 case SIGUSR1: 117 case SIGUSR1:
118 LOG(LOG_INFO, "Received a SIGUSR1"); 118 bb_info_msg("Received a SIGUSR1");
119 write_leases(); 119 write_leases();
120 /* why not just reset the timeout, eh */ 120 /* why not just reset the timeout, eh */
121 timeout_end = time(0) + server_config.auto_time; 121 timeout_end = time(0) + server_config.auto_time;
122 continue; 122 continue;
123 case SIGTERM: 123 case SIGTERM:
124 LOG(LOG_INFO, "Received a SIGTERM"); 124 bb_info_msg("Received a SIGTERM");
125 return 0; 125 return 0;
126 case 0: break; /* no signal */ 126 case 0: break; /* no signal */
127 default: continue; /* signal or error (probably EINTR) */ 127 default: continue; /* signal or error (probably EINTR) */
@@ -129,7 +129,7 @@ int udhcpd_main(int argc, char *argv[])
129 129
130 if ((bytes = udhcp_get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */ 130 if ((bytes = udhcp_get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */
131 if (bytes == -1 && errno != EINTR) { 131 if (bytes == -1 && errno != EINTR) {
132 DEBUG(LOG_INFO, "error on read, %m, reopening socket"); 132 DEBUG("error on read, %s, reopening socket", strerror(errno));
133 close(server_socket); 133 close(server_socket);
134 server_socket = -1; 134 server_socket = -1;
135 } 135 }
@@ -137,7 +137,7 @@ int udhcpd_main(int argc, char *argv[])
137 } 137 }
138 138
139 if ((state = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) { 139 if ((state = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) {
140 DEBUG(LOG_ERR, "couldn't get option from packet, ignoring"); 140 bb_error_msg("Couldn't get option from packet, ignoring");
141 continue; 141 continue;
142 } 142 }
143 143
@@ -146,7 +146,7 @@ int udhcpd_main(int argc, char *argv[])
146 146
147 if(static_lease_ip) 147 if(static_lease_ip)
148 { 148 {
149 printf("Found static lease: %x\n", static_lease_ip); 149 bb_info_msg("Found static lease: %x", static_lease_ip);
150 150
151 memcpy(&static_lease.chaddr, &packet.chaddr, 16); 151 memcpy(&static_lease.chaddr, &packet.chaddr, 16);
152 static_lease.yiaddr = static_lease_ip; 152 static_lease.yiaddr = static_lease_ip;
@@ -162,14 +162,14 @@ int udhcpd_main(int argc, char *argv[])
162 162
163 switch (state[0]) { 163 switch (state[0]) {
164 case DHCPDISCOVER: 164 case DHCPDISCOVER:
165 DEBUG(LOG_INFO,"received DISCOVER"); 165 DEBUG("Received DISCOVER");
166 166
167 if (sendOffer(&packet) < 0) { 167 if (sendOffer(&packet) < 0) {
168 LOG(LOG_ERR, "send OFFER failed"); 168 bb_error_msg("Send OFFER failed");
169 } 169 }
170 break; 170 break;
171 case DHCPREQUEST: 171 case DHCPREQUEST:
172 DEBUG(LOG_INFO, "received REQUEST"); 172 DEBUG("received REQUEST");
173 173
174 requested = get_option(&packet, DHCP_REQUESTED_IP); 174 requested = get_option(&packet, DHCP_REQUESTED_IP);
175 server_id = get_option(&packet, DHCP_SERVER_ID); 175 server_id = get_option(&packet, DHCP_SERVER_ID);
@@ -180,7 +180,7 @@ int udhcpd_main(int argc, char *argv[])
180 if (lease) { 180 if (lease) {
181 if (server_id) { 181 if (server_id) {
182 /* SELECTING State */ 182 /* SELECTING State */
183 DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align)); 183 DEBUG("server_id = %08x", ntohl(server_id_align));
184 if (server_id_align == server_config.server && requested && 184 if (server_id_align == server_config.server && requested &&
185 requested_align == lease->yiaddr) { 185 requested_align == lease->yiaddr) {
186 sendACK(&packet, lease->yiaddr); 186 sendACK(&packet, lease->yiaddr);
@@ -224,22 +224,22 @@ int udhcpd_main(int argc, char *argv[])
224 } 224 }
225 break; 225 break;
226 case DHCPDECLINE: 226 case DHCPDECLINE:
227 DEBUG(LOG_INFO,"received DECLINE"); 227 DEBUG("Received DECLINE");
228 if (lease) { 228 if (lease) {
229 memset(lease->chaddr, 0, 16); 229 memset(lease->chaddr, 0, 16);
230 lease->expires = time(0) + server_config.decline_time; 230 lease->expires = time(0) + server_config.decline_time;
231 } 231 }
232 break; 232 break;
233 case DHCPRELEASE: 233 case DHCPRELEASE:
234 DEBUG(LOG_INFO,"received RELEASE"); 234 DEBUG("Received RELEASE");
235 if (lease) lease->expires = time(0); 235 if (lease) lease->expires = time(0);
236 break; 236 break;
237 case DHCPINFORM: 237 case DHCPINFORM:
238 DEBUG(LOG_INFO,"received INFORM"); 238 DEBUG("Received INFORM");
239 send_inform(&packet); 239 send_inform(&packet);
240 break; 240 break;
241 default: 241 default:
242 LOG(LOG_WARNING, "unsupported DHCP message (%02x) -- ignoring", state[0]); 242 bb_info_msg("Unsupported DHCP message (%02x) - ignoring", state[0]);
243 } 243 }
244 } 244 }
245 245
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index a0a3bfcd8..d9dfb8965 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -112,7 +112,7 @@ static void attach_option(struct option_set **opt_list, struct dhcp_option *opti
112 112
113 /* add it to an existing option */ 113 /* add it to an existing option */
114 if ((existing = find_option(*opt_list, option->code))) { 114 if ((existing = find_option(*opt_list, option->code))) {
115 DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name); 115 DEBUG("Attaching option %s to existing member of list", option->name);
116 if (option->flags & OPTION_LIST) { 116 if (option->flags & OPTION_LIST) {
117 if (existing->data[OPT_LEN] + length <= 255) { 117 if (existing->data[OPT_LEN] + length <= 255) {
118 existing->data = realloc(existing->data, 118 existing->data = realloc(existing->data,
@@ -122,7 +122,7 @@ static void attach_option(struct option_set **opt_list, struct dhcp_option *opti
122 } /* else, ignore the data, we could put this in a second option in the future */ 122 } /* else, ignore the data, we could put this in a second option in the future */
123 } /* else, ignore the new data */ 123 } /* else, ignore the new data */
124 } else { 124 } else {
125 DEBUG(LOG_INFO, "Attaching option %s to list", option->name); 125 DEBUG("Attaching option %s to list", option->name);
126 126
127 /* make a new option */ 127 /* make a new option */
128 new = xmalloc(sizeof(struct option_set)); 128 new = xmalloc(sizeof(struct option_set));
@@ -286,7 +286,7 @@ int read_config(const char *file)
286 keywords[i].handler(keywords[i].def, keywords[i].var); 286 keywords[i].handler(keywords[i].def, keywords[i].var);
287 287
288 if (!(in = fopen(file, "r"))) { 288 if (!(in = fopen(file, "r"))) {
289 LOG(LOG_ERR, "unable to open config file: %s", file); 289 bb_error_msg("Unable to open config file: %s", file);
290 return 0; 290 return 0;
291 } 291 }
292 292
@@ -310,8 +310,9 @@ int read_config(const char *file)
310 for (i = 0; keywords[i].keyword[0]; i++) 310 for (i = 0; keywords[i].keyword[0]; i++)
311 if (!strcasecmp(token, keywords[i].keyword)) 311 if (!strcasecmp(token, keywords[i].keyword))
312 if (!keywords[i].handler(line, keywords[i].var)) { 312 if (!keywords[i].handler(line, keywords[i].var)) {
313 LOG(LOG_ERR, "Failure parsing line %d of %s", lm, file); 313 bb_error_msg("Failure parsing line %d of %s", lm, file);
314 DEBUG(LOG_ERR, "unable to parse '%s'", debug_orig); 314 if (ENABLE_FEATURE_UDHCP_DEBUG)
315 bb_error_msg("unable to parse '%s'", debug_orig);
315 /* reset back to the default value */ 316 /* reset back to the default value */
316 keywords[i].handler(keywords[i].def, keywords[i].var); 317 keywords[i].handler(keywords[i].def, keywords[i].var);
317 } 318 }
@@ -330,7 +331,7 @@ void write_leases(void)
330 unsigned long tmp_time; 331 unsigned long tmp_time;
331 332
332 if (!(fp = fopen(server_config.lease_file, "w"))) { 333 if (!(fp = fopen(server_config.lease_file, "w"))) {
333 LOG(LOG_ERR, "Unable to open %s for writing", server_config.lease_file); 334 bb_error_msg("Unable to open %s for writing", server_config.lease_file);
334 return; 335 return;
335 } 336 }
336 337
@@ -368,7 +369,7 @@ void read_leases(const char *file)
368 struct dhcpOfferedAddr lease; 369 struct dhcpOfferedAddr lease;
369 370
370 if (!(fp = fopen(file, "r"))) { 371 if (!(fp = fopen(file, "r"))) {
371 LOG(LOG_ERR, "Unable to open %s for reading", file); 372 bb_error_msg("Unable to open %s for reading", file);
372 return; 373 return;
373 } 374 }
374 375
@@ -378,12 +379,12 @@ void read_leases(const char *file)
378 lease.expires = ntohl(lease.expires); 379 lease.expires = ntohl(lease.expires);
379 if (!server_config.remaining) lease.expires -= time(0); 380 if (!server_config.remaining) lease.expires -= time(0);
380 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) { 381 if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) {
381 LOG(LOG_WARNING, "Too many leases while loading %s\n", file); 382 bb_error_msg("Too many leases while loading %s", file);
382 break; 383 break;
383 } 384 }
384 i++; 385 i++;
385 } 386 }
386 } 387 }
387 DEBUG(LOG_INFO, "Read %d leases", i); 388 DEBUG("Read %d leases", i);
388 fclose(fp); 389 fclose(fp);
389} 390}
diff --git a/networking/udhcp/leases.c b/networking/udhcp/leases.c
index 4c69c1f93..f5113408b 100644
--- a/networking/udhcp/leases.c
+++ b/networking/udhcp/leases.c
@@ -113,7 +113,7 @@ static int check_ip(uint32_t addr)
113 113
114 if (arpping(addr, server_config.server, server_config.arp, server_config.interface) == 0) { 114 if (arpping(addr, server_config.server, server_config.arp, server_config.interface) == 0) {
115 temp.s_addr = addr; 115 temp.s_addr = addr;
116 LOG(LOG_INFO, "%s belongs to someone, reserving it for %ld seconds", 116 bb_info_msg("%s belongs to someone, reserving it for %ld seconds",
117 inet_ntoa(temp), server_config.conflict_time); 117 inet_ntoa(temp), server_config.conflict_time);
118 add_lease(blank_chaddr, addr, server_config.conflict_time); 118 add_lease(blank_chaddr, addr, server_config.conflict_time);
119 return 1; 119 return 1;
diff --git a/networking/udhcp/libbb_udhcp.h b/networking/udhcp/libbb_udhcp.h
index c21d3baab..b353876d2 100644
--- a/networking/udhcp/libbb_udhcp.h
+++ b/networking/udhcp/libbb_udhcp.h
@@ -22,7 +22,6 @@
22 22
23void udhcp_background(const char *pidfile); 23void udhcp_background(const char *pidfile);
24void udhcp_start_log_and_pid(const char *client_server, const char *pidfile); 24void udhcp_start_log_and_pid(const char *client_server, const char *pidfile);
25void udhcp_logging(int level, const char *fmt, ...);
26 25
27void udhcp_run_script(struct dhcpMessage *packet, const char *name); 26void udhcp_run_script(struct dhcpMessage *packet, const char *name);
28 27
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c
index 02c251083..652647229 100644
--- a/networking/udhcp/options.c
+++ b/networking/udhcp/options.c
@@ -73,12 +73,12 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
73 length = 308; 73 length = 308;
74 while (!done) { 74 while (!done) {
75 if (i >= length) { 75 if (i >= length) {
76 LOG(LOG_WARNING, "bogus packet, option fields too long."); 76 bb_error_msg("Bogus packet, option fields too long");
77 return NULL; 77 return NULL;
78 } 78 }
79 if (optionptr[i + OPT_CODE] == code) { 79 if (optionptr[i + OPT_CODE] == code) {
80 if (i + 1 + optionptr[i + OPT_LEN] >= length) { 80 if (i + 1 + optionptr[i + OPT_LEN] >= length) {
81 LOG(LOG_WARNING, "bogus packet, option fields too long."); 81 bb_error_msg("Bogus packet, option fields too long");
82 return NULL; 82 return NULL;
83 } 83 }
84 return optionptr + i + 2; 84 return optionptr + i + 2;
@@ -89,7 +89,7 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
89 break; 89 break;
90 case DHCP_OPTION_OVER: 90 case DHCP_OPTION_OVER:
91 if (i + 1 + optionptr[i + OPT_LEN] >= length) { 91 if (i + 1 + optionptr[i + OPT_LEN] >= length) {
92 LOG(LOG_WARNING, "bogus packet, option fields too long."); 92 bb_error_msg("Bogus packet, option fields too long");
93 return NULL; 93 return NULL;
94 } 94 }
95 over = optionptr[i + 3]; 95 over = optionptr[i + 3];
@@ -137,10 +137,11 @@ int add_option_string(uint8_t *optionptr, uint8_t *string)
137 137
138 /* end position + string length + option code/length + end option */ 138 /* end position + string length + option code/length + end option */
139 if (end + string[OPT_LEN] + 2 + 1 >= 308) { 139 if (end + string[OPT_LEN] + 2 + 1 >= 308) {
140 LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]); 140 bb_error_msg("Option 0x%02x did not fit into the packet",
141 string[OPT_CODE]);
141 return 0; 142 return 0;
142 } 143 }
143 DEBUG(LOG_INFO, "adding option 0x%02x", string[OPT_CODE]); 144 DEBUG("adding option 0x%02x", string[OPT_CODE]);
144 memcpy(optionptr + end, string, string[OPT_LEN] + 2); 145 memcpy(optionptr + end, string, string[OPT_LEN] + 2);
145 optionptr[end + string[OPT_LEN] + 2] = DHCP_END; 146 optionptr[end + string[OPT_LEN] + 2] = DHCP_END;
146 return string[OPT_LEN] + 2; 147 return string[OPT_LEN] + 2;
@@ -167,6 +168,6 @@ int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
167 } 168 }
168 } 169 }
169 170
170 DEBUG(LOG_ERR, "Could not add option 0x%02x", code); 171 bb_error_msg("Could not add option 0x%02x", code);
171 return 0; 172 return 0;
172} 173}
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c
index 67a452dbc..30675eaab 100644
--- a/networking/udhcp/packet.c
+++ b/networking/udhcp/packet.c
@@ -58,21 +58,21 @@ int udhcp_get_packet(struct dhcpMessage *packet, int fd)
58 memset(packet, 0, sizeof(struct dhcpMessage)); 58 memset(packet, 0, sizeof(struct dhcpMessage));
59 bytes = read(fd, packet, sizeof(struct dhcpMessage)); 59 bytes = read(fd, packet, sizeof(struct dhcpMessage));
60 if (bytes < 0) { 60 if (bytes < 0) {
61 DEBUG(LOG_INFO, "couldn't read on listening socket, ignoring"); 61 DEBUG("couldn't read on listening socket, ignoring");
62 return -1; 62 return -1;
63 } 63 }
64 64
65 if (ntohl(packet->cookie) != DHCP_MAGIC) { 65 if (ntohl(packet->cookie) != DHCP_MAGIC) {
66 LOG(LOG_ERR, "received bogus message, ignoring"); 66 bb_error_msg("Received bogus message, ignoring");
67 return -2; 67 return -2;
68 } 68 }
69 DEBUG(LOG_INFO, "Received a packet"); 69 DEBUG("Received a packet");
70 70
71 if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) { 71 if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) {
72 for (i = 0; broken_vendors[i][0]; i++) { 72 for (i = 0; broken_vendors[i][0]; i++) {
73 if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) && 73 if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) &&
74 !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])) { 74 !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])) {
75 DEBUG(LOG_INFO, "broken client (%s), forcing broadcast", 75 DEBUG("broken client (%s), forcing broadcast",
76 broken_vendors[i]); 76 broken_vendors[i]);
77 packet->flags |= htons(BROADCAST_FLAG); 77 packet->flags |= htons(BROADCAST_FLAG);
78 } 78 }
@@ -123,7 +123,7 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
123 struct udp_dhcp_packet packet; 123 struct udp_dhcp_packet packet;
124 124
125 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { 125 if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
126 DEBUG(LOG_ERR, "socket call failed: %m"); 126 bb_perror_msg("socket");
127 return -1; 127 return -1;
128 } 128 }
129 129
@@ -136,7 +136,7 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
136 dest.sll_halen = 6; 136 dest.sll_halen = 6;
137 memcpy(dest.sll_addr, dest_arp, 6); 137 memcpy(dest.sll_addr, dest_arp, 6);
138 if (bind(fd, (struct sockaddr *)&dest, sizeof(struct sockaddr_ll)) < 0) { 138 if (bind(fd, (struct sockaddr *)&dest, sizeof(struct sockaddr_ll)) < 0) {
139 DEBUG(LOG_ERR, "bind call failed: %m"); 139 bb_perror_msg("bind");
140 close(fd); 140 close(fd);
141 return -1; 141 return -1;
142 } 142 }
@@ -159,7 +159,7 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
159 159
160 result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest)); 160 result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest));
161 if (result <= 0) { 161 if (result <= 0) {
162 DEBUG(LOG_ERR, "write on socket failed: %m"); 162 bb_perror_msg("sendto");
163 } 163 }
164 close(fd); 164 close(fd);
165 return result; 165 return result;
diff --git a/networking/udhcp/pidfile.c b/networking/udhcp/pidfile.c
index b837270fb..148b07b34 100644
--- a/networking/udhcp/pidfile.c
+++ b/networking/udhcp/pidfile.c
@@ -45,7 +45,7 @@ int pidfile_acquire(const char *pidfile)
45 45
46 pid_fd = open(pidfile, O_CREAT | O_WRONLY, 0644); 46 pid_fd = open(pidfile, O_CREAT | O_WRONLY, 0644);
47 if (pid_fd < 0) { 47 if (pid_fd < 0) {
48 LOG(LOG_ERR, "Unable to open pidfile %s: %m\n", pidfile); 48 bb_perror_msg("Unable to open pidfile %s", pidfile);
49 } else { 49 } else {
50 lockf(pid_fd, F_LOCK, 0); 50 lockf(pid_fd, F_LOCK, 0);
51 if (!saved_pidfile) 51 if (!saved_pidfile)
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 5a4b33a53..3c4b51b24 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -200,7 +200,7 @@ void udhcp_run_script(struct dhcpMessage *packet, const char *name)
200 if (client_config.script == NULL) 200 if (client_config.script == NULL)
201 return; 201 return;
202 202
203 DEBUG(LOG_INFO, "vforking and execle'ing %s", client_config.script); 203 DEBUG("vfork'ing and execle'ing %s", client_config.script);
204 204
205 envp = fill_envp(packet); 205 envp = fill_envp(packet);
206 /* call script */ 206 /* call script */
@@ -216,7 +216,7 @@ void udhcp_run_script(struct dhcpMessage *packet, const char *name)
216 /* exec script */ 216 /* exec script */
217 execle(client_config.script, client_config.script, 217 execle(client_config.script, client_config.script,
218 name, NULL, envp); 218 name, NULL, envp);
219 LOG(LOG_ERR, "script %s failed: %m", client_config.script); 219 bb_perror_msg("script %s failed", client_config.script);
220 exit(1); 220 exit(1);
221 } 221 }
222} 222}
diff --git a/networking/udhcp/serverpacket.c b/networking/udhcp/serverpacket.c
index 8c7b1642a..cfead413c 100644
--- a/networking/udhcp/serverpacket.c
+++ b/networking/udhcp/serverpacket.c
@@ -35,7 +35,7 @@
35/* send a packet to giaddr using the kernel ip stack */ 35/* send a packet to giaddr using the kernel ip stack */
36static int send_packet_to_relay(struct dhcpMessage *payload) 36static int send_packet_to_relay(struct dhcpMessage *payload)
37{ 37{
38 DEBUG(LOG_INFO, "Forwarding packet to relay"); 38 DEBUG("Forwarding packet to relay");
39 39
40 return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT, 40 return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT,
41 payload->giaddr, SERVER_PORT); 41 payload->giaddr, SERVER_PORT);
@@ -49,19 +49,19 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas
49 uint32_t ciaddr; 49 uint32_t ciaddr;
50 50
51 if (force_broadcast) { 51 if (force_broadcast) {
52 DEBUG(LOG_INFO, "broadcasting packet to client (NAK)"); 52 DEBUG("broadcasting packet to client (NAK)");
53 ciaddr = INADDR_BROADCAST; 53 ciaddr = INADDR_BROADCAST;
54 chaddr = MAC_BCAST_ADDR; 54 chaddr = MAC_BCAST_ADDR;
55 } else if (payload->ciaddr) { 55 } else if (payload->ciaddr) {
56 DEBUG(LOG_INFO, "unicasting packet to client ciaddr"); 56 DEBUG("unicasting packet to client ciaddr");
57 ciaddr = payload->ciaddr; 57 ciaddr = payload->ciaddr;
58 chaddr = payload->chaddr; 58 chaddr = payload->chaddr;
59 } else if (ntohs(payload->flags) & BROADCAST_FLAG) { 59 } else if (ntohs(payload->flags) & BROADCAST_FLAG) {
60 DEBUG(LOG_INFO, "broadcasting packet to client (requested)"); 60 DEBUG("broadcasting packet to client (requested)");
61 ciaddr = INADDR_BROADCAST; 61 ciaddr = INADDR_BROADCAST;
62 chaddr = MAC_BCAST_ADDR; 62 chaddr = MAC_BCAST_ADDR;
63 } else { 63 } else {
64 DEBUG(LOG_INFO, "unicasting packet to client yiaddr"); 64 DEBUG("unicasting packet to client yiaddr");
65 ciaddr = payload->yiaddr; 65 ciaddr = payload->yiaddr;
66 chaddr = payload->chaddr; 66 chaddr = payload->chaddr;
67 } 67 }
@@ -158,12 +158,12 @@ int sendOffer(struct dhcpMessage *oldpacket)
158 } 158 }
159 159
160 if(!packet.yiaddr) { 160 if(!packet.yiaddr) {
161 LOG(LOG_WARNING, "no IP addresses to give -- OFFER abandoned"); 161 bb_error_msg("No IP addresses to give - OFFER abandoned");
162 return -1; 162 return -1;
163 } 163 }
164 164
165 if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) { 165 if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
166 LOG(LOG_WARNING, "lease pool is full -- OFFER abandoned"); 166 bb_error_msg("Lease pool is full - OFFER abandoned");
167 return -1; 167 return -1;
168 } 168 }
169 169
@@ -197,7 +197,7 @@ int sendOffer(struct dhcpMessage *oldpacket)
197 add_bootp_options(&packet); 197 add_bootp_options(&packet);
198 198
199 addr.s_addr = packet.yiaddr; 199 addr.s_addr = packet.yiaddr;
200 LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr)); 200 bb_info_msg("Sending OFFER of %s", inet_ntoa(addr));
201 return send_packet(&packet, 0); 201 return send_packet(&packet, 0);
202} 202}
203 203
@@ -208,7 +208,7 @@ int sendNAK(struct dhcpMessage *oldpacket)
208 208
209 init_packet(&packet, oldpacket, DHCPNAK); 209 init_packet(&packet, oldpacket, DHCPNAK);
210 210
211 DEBUG(LOG_INFO, "sending NAK"); 211 DEBUG("Sending NAK");
212 return send_packet(&packet, 1); 212 return send_packet(&packet, 1);
213} 213}
214 214
@@ -245,7 +245,7 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
245 add_bootp_options(&packet); 245 add_bootp_options(&packet);
246 246
247 addr.s_addr = packet.yiaddr; 247 addr.s_addr = packet.yiaddr;
248 LOG(LOG_INFO, "sending ACK to %s", inet_ntoa(addr)); 248 bb_info_msg("Sending ACK to %s", inet_ntoa(addr));
249 249
250 if (send_packet(&packet, 0) < 0) 250 if (send_packet(&packet, 0) < 0)
251 return -1; 251 return -1;
diff --git a/networking/udhcp/signalpipe.c b/networking/udhcp/signalpipe.c
index 9951eb57d..6c4a9f1f2 100644
--- a/networking/udhcp/signalpipe.c
+++ b/networking/udhcp/signalpipe.c
@@ -36,7 +36,7 @@ static int signal_pipe[2];
36static void signal_handler(int sig) 36static void signal_handler(int sig)
37{ 37{
38 if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0) 38 if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0)
39 DEBUG(LOG_ERR, "Could not send signal: %m"); 39 bb_perror_msg("Could not send signal");
40} 40}
41 41
42 42
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index 2d253c1f2..3f481c33c 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -60,33 +60,33 @@ int read_interface(char *interface, int *ifindex, uint32_t *addr, uint8_t *arp)
60 if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { 60 if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
61 our_ip = (struct sockaddr_in *) &ifr.ifr_addr; 61 our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
62 *addr = our_ip->sin_addr.s_addr; 62 *addr = our_ip->sin_addr.s_addr;
63 DEBUG(LOG_INFO, "%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr)); 63 DEBUG("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
64 } else { 64 } else {
65 LOG(LOG_ERR, "SIOCGIFADDR failed, is the interface up and configured?: %m"); 65 bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?");
66 close(fd); 66 close(fd);
67 return -1; 67 return -1;
68 } 68 }
69 } 69 }
70 70
71 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) { 71 if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) {
72 DEBUG(LOG_INFO, "adapter index %d", ifr.ifr_ifindex); 72 DEBUG("adapter index %d", ifr.ifr_ifindex);
73 *ifindex = ifr.ifr_ifindex; 73 *ifindex = ifr.ifr_ifindex;
74 } else { 74 } else {
75 LOG(LOG_ERR, "SIOCGIFINDEX failed!: %m"); 75 bb_perror_msg("SIOCGIFINDEX failed");
76 close(fd); 76 close(fd);
77 return -1; 77 return -1;
78 } 78 }
79 if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) { 79 if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) {
80 memcpy(arp, ifr.ifr_hwaddr.sa_data, 6); 80 memcpy(arp, ifr.ifr_hwaddr.sa_data, 6);
81 DEBUG(LOG_INFO, "adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x", 81 DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
82 arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]); 82 arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
83 } else { 83 } else {
84 LOG(LOG_ERR, "SIOCGIFHWADDR failed!: %m"); 84 bb_perror_msg("SIOCGIFHWADDR failed");
85 close(fd); 85 close(fd);
86 return -1; 86 return -1;
87 } 87 }
88 } else { 88 } else {
89 LOG(LOG_ERR, "socket failed!: %m"); 89 bb_perror_msg("socket failed");
90 return -1; 90 return -1;
91 } 91 }
92 close(fd); 92 close(fd);
@@ -101,9 +101,9 @@ int listen_socket(uint32_t ip, int port, char *inf)
101 struct sockaddr_in addr; 101 struct sockaddr_in addr;
102 int n = 1; 102 int n = 1;
103 103
104 DEBUG(LOG_INFO, "Opening listen socket on 0x%08x:%d %s", ip, port, inf); 104 DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf);
105 if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { 105 if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
106 DEBUG(LOG_ERR, "socket call failed: %m"); 106 bb_perror_msg("socket");
107 return -1; 107 return -1;
108 } 108 }
109 109