aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp
diff options
context:
space:
mode:
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)
time_t prevTime;
- if ((s = socket (PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) == -1) {
- LOG(LOG_ERR, bb_msg_can_not_create_raw_socket);
+ if ((s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP))) == -1) {
+ bb_perror_msg(bb_msg_can_not_create_raw_socket);
return -1;
}
if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval)) == -1) {
- LOG(LOG_ERR, "Could not setsocketopt on raw socket");
+ bb_perror_msg("Could not setsocketopt on raw socket");
close(s);
return -1;
}
@@ -81,14 +81,14 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
FD_SET(s, &fdset);
tm.tv_sec = timeout;
if (select(s + 1, &fdset, (fd_set *) NULL, (fd_set *) NULL, &tm) < 0) {
- DEBUG(LOG_ERR, "Error on ARPING request: %m");
+ bb_perror_msg("Error on ARPING request");
if (errno != EINTR) rv = 0;
} else if (FD_ISSET(s, &fdset)) {
if (recv(s, &arp, sizeof(arp), 0) < 0 ) rv = 0;
if (arp.operation == htons(ARPOP_REPLY) &&
memcmp(arp.tHaddr, mac, 6) == 0 &&
*((uint32_t *) arp.sInaddr) == yiaddr) {
- DEBUG(LOG_INFO, "Valid arp reply receved for this address");
+ DEBUG("Valid arp reply received for this address");
rv = 0;
break;
}
@@ -97,6 +97,6 @@ int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface)
prevTime = uptime();
}
close(s);
- DEBUG(LOG_INFO, "%salid arp replies for this address", rv ? "No v" : "V");
+ DEBUG("%salid arp replies for this address", rv ? "No v" : "V");
return rv;
}
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)
fd = open("/dev/urandom", 0);
if (fd < 0 || read(fd, &seed, sizeof(seed)) < 0) {
- LOG(LOG_WARNING, "Could not load seed from /dev/urandom: %m");
+ bb_info_msg("Could not load seed "
+ "from /dev/urandom: %s", strerror(errno));
seed = time(0);
}
if (fd >= 0) close(fd);
@@ -97,7 +98,7 @@ int send_discover(unsigned long xid, unsigned long requested)
add_simple_option(packet.options, DHCP_REQUESTED_IP, requested);
add_requests(&packet);
- LOG(LOG_DEBUG, "Sending discover...");
+ bb_info_msg("Sending discover...");
return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
}
@@ -117,7 +118,7 @@ int send_selecting(unsigned long xid, unsigned long server, unsigned long reques
add_requests(&packet);
addr.s_addr = requested;
- LOG(LOG_DEBUG, "Sending select for %s...", inet_ntoa(addr));
+ bb_info_msg("Sending select for %s...", inet_ntoa(addr));
return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST,
SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex);
}
@@ -134,7 +135,7 @@ int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr)
packet.ciaddr = ciaddr;
add_requests(&packet);
- LOG(LOG_DEBUG, "Sending renew...");
+ bb_info_msg("Sending renew...");
if (server)
ret = udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
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)
add_simple_option(packet.options, DHCP_REQUESTED_IP, ciaddr);
add_simple_option(packet.options, DHCP_SERVER_ID, server);
- LOG(LOG_DEBUG, "Sending release...");
+ bb_info_msg("Sending release...");
return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT);
}
@@ -171,18 +172,18 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
memset(&packet, 0, sizeof(struct udp_dhcp_packet));
bytes = read(fd, &packet, sizeof(struct udp_dhcp_packet));
if (bytes < 0) {
- DEBUG(LOG_INFO, "couldn't read on raw listening socket -- ignoring");
+ DEBUG("Couldn't read on raw listening socket - ignoring");
usleep(500000); /* possible down interface, looping condition */
return -1;
}
if (bytes < (int) (sizeof(struct iphdr) + sizeof(struct udphdr))) {
- DEBUG(LOG_INFO, "message too short, ignoring");
+ DEBUG("Message too short, ignoring");
return -2;
}
if (bytes < ntohs(packet.ip.tot_len)) {
- DEBUG(LOG_INFO, "Truncated packet");
+ DEBUG("Truncated packet");
return -2;
}
@@ -194,7 +195,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
packet.ip.ihl != sizeof(packet.ip) >> 2 || packet.udp.dest != htons(CLIENT_PORT) ||
bytes > (int) sizeof(struct udp_dhcp_packet) ||
ntohs(packet.udp.len) != (uint16_t) (bytes - sizeof(packet.ip))) {
- DEBUG(LOG_INFO, "unrelated/bogus packet");
+ DEBUG("Unrelated/bogus packet");
return -2;
}
@@ -202,7 +203,7 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
check = packet.ip.check;
packet.ip.check = 0;
if (check != udhcp_checksum(&(packet.ip), sizeof(packet.ip))) {
- DEBUG(LOG_INFO, "bad IP header checksum, ignoring");
+ DEBUG("bad IP header checksum, ignoring");
return -1;
}
@@ -218,17 +219,17 @@ int get_raw_packet(struct dhcpMessage *payload, int fd)
packet.ip.daddr = dest;
packet.ip.tot_len = packet.udp.len; /* cheat on the psuedo-header */
if (check && check != udhcp_checksum(&packet, bytes)) {
- DEBUG(LOG_ERR, "packet with bad UDP checksum received, ignoring");
+ bb_error_msg("Packet with bad UDP checksum received, ignoring");
return -2;
}
memcpy(payload, &(packet.data), bytes - (sizeof(packet.ip) + sizeof(packet.udp)));
if (ntohl(payload->cookie) != DHCP_MAGIC) {
- LOG(LOG_ERR, "received bogus message (bad magic) -- ignoring");
+ bb_error_msg("Received bogus message (bad magic) - ignoring");
return -2;
}
- DEBUG(LOG_INFO, "oooooh!!! got some!");
+ DEBUG("oooooh!!! got some!");
return bytes - (sizeof(packet.ip) + sizeof(packet.udp));
}
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)
int fd;
struct sockaddr_ll sock;
- DEBUG(LOG_INFO, "Opening raw socket on ifindex %d", ifindex);
+ DEBUG("Opening raw socket on ifindex %d", ifindex);
if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
- DEBUG(LOG_ERR, "socket call failed: %m");
+ bb_perror_msg("socket");
return -1;
}
@@ -54,7 +54,7 @@ int raw_socket(int ifindex)
sock.sll_protocol = htons(ETH_P_IP);
sock.sll_ifindex = ifindex;
if (bind(fd, (struct sockaddr *) &sock, sizeof(sock)) < 0) {
- DEBUG(LOG_ERR, "bind call failed: %m");
+ bb_perror_msg("bind:");
close(fd);
return -1;
}
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 @@
#include <paths.h>
#include <sys/socket.h>
#include <stdarg.h>
+#include <syslog.h>
#include "common.h"
#include "pidfile.h"
@@ -33,7 +34,6 @@ long uptime(void)
return info.uptime;
}
-
/*
* This function makes sure our first socket calls
* aren't going to fd 1 (printf badness...) and are
@@ -41,77 +41,32 @@ long uptime(void)
*/
static inline void sanitize_fds(void)
{
- int zero;
- if ((zero = open(bb_dev_null, O_RDWR, 0)) < 0)
+ int fd = open(bb_dev_null, O_RDWR, 0);
+ if (fd < 0)
return;
- while (zero < 3)
- zero = dup(zero);
- close(zero);
+ while (fd < 3)
+ fd = dup(fd);
+ close(fd);
}
void udhcp_background(const char *pidfile)
{
#ifdef __uClinux__
- LOG(LOG_ERR, "Cannot background in uclinux (yet)");
+ bb_error_msg("Cannot background in uclinux (yet)");
#else /* __uClinux__ */
int pid_fd;
/* hold lock during fork. */
pid_fd = pidfile_acquire(pidfile);
+ setsid();
xdaemon(0, 0);
daemonized++;
+ logmode &= ~LOGMODE_STDIO;
pidfile_write_release(pid_fd);
#endif /* __uClinux__ */
}
-
-#ifdef CONFIG_FEATURE_UDHCP_SYSLOG
-
-void udhcp_logging(int level, const char *fmt, ...)
-{
- va_list p;
- va_list p2;
-
- va_start(p, fmt);
- __va_copy(p2, p);
- if (!daemonized) {
- vprintf(fmt, p);
- putchar('\n');
- }
- vsyslog(level, fmt, p2);
- va_end(p);
-}
-
-#else
-
-
-static char *syslog_level_msg[] = {
- [LOG_EMERG] = "EMERGENCY!",
- [LOG_ALERT] = "ALERT!",
- [LOG_CRIT] = "critical!",
- [LOG_WARNING] = "warning",
- [LOG_ERR] = "error",
- [LOG_INFO] = "info",
- [LOG_DEBUG] = "debug"
-};
-
-
-void udhcp_logging(int level, const char *fmt, ...)
-{
- va_list p;
-
- va_start(p, fmt);
- if (!daemonized) {
- printf("%s, ", syslog_level_msg[level]);
- vprintf(fmt, p);
- putchar('\n');
- }
- va_end(p);
-}
-#endif
-
-
void udhcp_start_log_and_pid(const char *client_server, const char *pidfile)
{
int pid_fd;
@@ -126,8 +81,10 @@ void udhcp_start_log_and_pid(const char *client_server, const char *pidfile)
/* equivelent of doing a fflush after every \n */
setlinebuf(stdout);
- if (ENABLE_FEATURE_UDHCP_SYSLOG)
- openlog(client_server, LOG_PID | LOG_CONS, LOG_LOCAL0);
+ if (ENABLE_FEATURE_UDHCP_SYSLOG) {
+ openlog(client_server, LOG_PID, LOG_LOCAL0);
+ logmode |= LOGMODE_SYSLOG;
+ }
- udhcp_logging(LOG_INFO, "%s (v%s) started", client_server, BB_VER);
+ bb_info_msg("%s (v%s) started", client_server, BB_VER);
}
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 @@
#include "libbb_udhcp.h"
-
-enum syslog_levels {
- LOG_EMERG = 0,
- LOG_ALERT,
- LOG_CRIT,
- LOG_WARNING,
- LOG_ERR,
- LOG_INFO,
- LOG_DEBUG
-};
-#include <syslog.h>
-
long uptime(void);
-#define LOG(level, str, args...) udhcp_logging(level, str, ## args)
-
#if ENABLE_FEATURE_UDHCP_DEBUG
-# define DEBUG(level, str, args...) LOG(level, str, ## args)
+# define DEBUG(str, args...) bb_info_msg(str, ## args)
#else
-# define DEBUG(level, str, args...) do {;} while(0)
+# define DEBUG(str, args...) do {;} while(0)
#endif
#endif
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c
index 989759ab8..5b2612e56 100644
--- a/networking/udhcp/dhcpc.c
+++ b/networking/udhcp/dhcpc.c
@@ -65,7 +65,7 @@ struct client_config_t client_config = {
/* just a little helper */
static void change_mode(int new_mode)
{
- DEBUG(LOG_INFO, "entering %s listen mode",
+ DEBUG("entering %s listen mode",
new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none");
if (fd >= 0) close(fd);
fd = -1;
@@ -76,7 +76,7 @@ static void change_mode(int new_mode)
/* perform a renew */
static void perform_renew(void)
{
- LOG(LOG_INFO, "Performing a DHCP renew");
+ bb_info_msg("Performing a DHCP renew");
switch (state) {
case BOUND:
change_mode(LISTEN_KERNEL);
@@ -114,12 +114,12 @@ static void perform_release(void)
temp_addr.s_addr = server_addr;
sprintf(buffer, "%s", inet_ntoa(temp_addr));
temp_addr.s_addr = requested_ip;
- LOG(LOG_INFO, "Unicasting a release of %s to %s",
+ bb_info_msg("Unicasting a release of %s to %s",
inet_ntoa(temp_addr), buffer);
send_release(server_addr, requested_ip); /* unicast */
udhcp_run_script(NULL, "deconfig");
}
- LOG(LOG_INFO, "Entering released state");
+ bb_info_msg("Entering released state");
change_mode(LISTEN_NONE);
state = RELEASED;
@@ -310,14 +310,14 @@ int udhcpc_main(int argc, char *argv[])
else
fd = raw_socket(client_config.ifindex);
if (fd < 0) {
- LOG(LOG_ERR, "FATAL: couldn't listen on socket, %m");
+ bb_perror_msg("FATAL: couldn't listen on socket");
return 0;
}
}
max_fd = udhcp_sp_fd_set(&rfds, fd);
if (tv.tv_sec > 0) {
- DEBUG(LOG_INFO, "Waiting on select...");
+ DEBUG("Waiting on select...");
retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
} else retval = 0; /* If we already timed out, fall through */
@@ -338,10 +338,10 @@ int udhcpc_main(int argc, char *argv[])
} else {
udhcp_run_script(NULL, "leasefail");
if (client_config.background_if_no_lease) {
- LOG(LOG_INFO, "No lease, forking to background.");
+ bb_info_msg("No lease, forking to background");
client_background();
} else if (client_config.abort_if_no_lease) {
- LOG(LOG_INFO, "No lease, failing.");
+ bb_info_msg("No lease, failing");
return 1;
}
/* wait to try again */
@@ -372,7 +372,7 @@ int udhcpc_main(int argc, char *argv[])
/* Lease is starting to run out, time to enter renewing state */
state = RENEWING;
change_mode(LISTEN_KERNEL);
- DEBUG(LOG_INFO, "Entering renew state");
+ DEBUG("Entering renew state");
/* fall right through */
case RENEWING:
/* Either set a new T1, or enter REBINDING state */
@@ -380,7 +380,7 @@ int udhcpc_main(int argc, char *argv[])
/* timed out, enter rebinding state */
state = REBINDING;
timeout = now + (t2 - t1);
- DEBUG(LOG_INFO, "Entering rebinding state");
+ DEBUG("Entering rebinding state");
} else {
/* send a request packet */
send_renew(xid, server_addr, requested_ip); /* unicast */
@@ -394,7 +394,7 @@ int udhcpc_main(int argc, char *argv[])
if ((lease - t2) <= (lease / 14400 + 1)) {
/* timed out, enter init state */
state = INIT_SELECTING;
- LOG(LOG_INFO, "Lease lost, entering init state");
+ bb_info_msg("Lease lost, entering init state");
udhcp_run_script(NULL, "deconfig");
timeout = now;
packet_num = 0;
@@ -420,25 +420,25 @@ int udhcpc_main(int argc, char *argv[])
else len = get_raw_packet(&packet, fd);
if (len == -1 && errno != EINTR) {
- DEBUG(LOG_INFO, "error on read, %m, reopening socket");
+ DEBUG("error on read, %s, reopening socket", strerror(errno));
change_mode(listen_mode); /* just close and reopen */
}
if (len < 0) continue;
if (packet.xid != xid) {
- DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)",
+ DEBUG("Ignoring XID %lx (our xid is %lx)",
(unsigned long) packet.xid, xid);
continue;
}
/* Ignore packets that aren't for us */
if (memcmp(packet.chaddr, client_config.arp, 6)) {
- DEBUG(LOG_INFO, "packet does not have our chaddr -- ignoring");
+ DEBUG("Packet does not have our chaddr - ignoring");
continue;
}
if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) {
- DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring");
+ bb_error_msg("Couldnt get option from packet - ignoring");
continue;
}
@@ -456,7 +456,7 @@ int udhcpc_main(int argc, char *argv[])
timeout = now;
packet_num = 0;
} else {
- DEBUG(LOG_ERR, "No server ID in message");
+ bb_error_msg("No server ID in message");
}
}
break;
@@ -466,7 +466,7 @@ int udhcpc_main(int argc, char *argv[])
case REBINDING:
if (*message == DHCPACK) {
if (!(temp = get_option(&packet, DHCP_LEASE_TIME))) {
- LOG(LOG_ERR, "No lease time with ACK, using 1 hour lease");
+ bb_error_msg("No lease time with ACK, using 1 hour lease");
lease = 60 * 60;
} else {
memcpy(&lease, temp, 4);
@@ -479,7 +479,7 @@ int udhcpc_main(int argc, char *argv[])
/* little fixed point for n * .875 */
t2 = (lease * 0x7) >> 3;
temp_addr.s_addr = packet.yiaddr;
- LOG(LOG_INFO, "Lease of %s obtained, lease time %ld",
+ bb_info_msg("Lease of %s obtained, lease time %ld",
inet_ntoa(temp_addr), lease);
start = now;
timeout = t1 + start;
@@ -496,7 +496,7 @@ int udhcpc_main(int argc, char *argv[])
} else if (*message == DHCPNAK) {
/* return to init state */
- LOG(LOG_INFO, "Received DHCP NAK");
+ bb_info_msg("Received DHCP NAK");
udhcp_run_script(&packet, "nak");
if (state != REQUESTING)
udhcp_run_script(NULL, "deconfig");
@@ -519,14 +519,14 @@ int udhcpc_main(int argc, char *argv[])
perform_release();
break;
case SIGTERM:
- LOG(LOG_INFO, "Received SIGTERM");
+ bb_info_msg("Received SIGTERM");
return 0;
}
} else if (retval == -1 && errno == EINTR) {
/* a signal was caught */
} else {
/* An error occured */
- DEBUG(LOG_ERR, "Error on select");
+ bb_perror_msg("select");
}
}
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[])
/* Sanity check */
num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1;
if (server_config.max_leases > num_ips) {
- LOG(LOG_ERR, "max_leases value (%lu) not sane, "
+ bb_error_msg("max_leases value (%lu) not sane, "
"setting to %lu instead",
server_config.max_leases, num_ips);
server_config.max_leases = num_ips;
@@ -90,7 +90,7 @@ int udhcpd_main(int argc, char *argv[])
if (server_socket < 0)
if ((server_socket = listen_socket(INADDR_ANY, SERVER_PORT, server_config.interface)) < 0) {
- LOG(LOG_ERR, "FATAL: couldn't create server socket, %m");
+ bb_perror_msg("FATAL: couldn't create server socket");
return 2;
}
@@ -109,19 +109,19 @@ int udhcpd_main(int argc, char *argv[])
timeout_end = time(0) + server_config.auto_time;
continue;
} else if (retval < 0 && errno != EINTR) {
- DEBUG(LOG_INFO, "error on select");
+ DEBUG("error on select");
continue;
}
switch (udhcp_sp_read(&rfds)) {
case SIGUSR1:
- LOG(LOG_INFO, "Received a SIGUSR1");
+ bb_info_msg("Received a SIGUSR1");
write_leases();
/* why not just reset the timeout, eh */
timeout_end = time(0) + server_config.auto_time;
continue;
case SIGTERM:
- LOG(LOG_INFO, "Received a SIGTERM");
+ bb_info_msg("Received a SIGTERM");
return 0;
case 0: break; /* no signal */
default: continue; /* signal or error (probably EINTR) */
@@ -129,7 +129,7 @@ int udhcpd_main(int argc, char *argv[])
if ((bytes = udhcp_get_packet(&packet, server_socket)) < 0) { /* this waits for a packet - idle */
if (bytes == -1 && errno != EINTR) {
- DEBUG(LOG_INFO, "error on read, %m, reopening socket");
+ DEBUG("error on read, %s, reopening socket", strerror(errno));
close(server_socket);
server_socket = -1;
}
@@ -137,7 +137,7 @@ int udhcpd_main(int argc, char *argv[])
}
if ((state = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) {
- DEBUG(LOG_ERR, "couldn't get option from packet, ignoring");
+ bb_error_msg("Couldn't get option from packet, ignoring");
continue;
}
@@ -146,7 +146,7 @@ int udhcpd_main(int argc, char *argv[])
if(static_lease_ip)
{
- printf("Found static lease: %x\n", static_lease_ip);
+ bb_info_msg("Found static lease: %x", static_lease_ip);
memcpy(&static_lease.chaddr, &packet.chaddr, 16);
static_lease.yiaddr = static_lease_ip;
@@ -162,14 +162,14 @@ int udhcpd_main(int argc, char *argv[])
switch (state[0]) {
case DHCPDISCOVER:
- DEBUG(LOG_INFO,"received DISCOVER");
+ DEBUG("Received DISCOVER");
if (sendOffer(&packet) < 0) {
- LOG(LOG_ERR, "send OFFER failed");
+ bb_error_msg("Send OFFER failed");
}
break;
case DHCPREQUEST:
- DEBUG(LOG_INFO, "received REQUEST");
+ DEBUG("received REQUEST");
requested = get_option(&packet, DHCP_REQUESTED_IP);
server_id = get_option(&packet, DHCP_SERVER_ID);
@@ -180,7 +180,7 @@ int udhcpd_main(int argc, char *argv[])
if (lease) {
if (server_id) {
/* SELECTING State */
- DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align));
+ DEBUG("server_id = %08x", ntohl(server_id_align));
if (server_id_align == server_config.server && requested &&
requested_align == lease->yiaddr) {
sendACK(&packet, lease->yiaddr);
@@ -224,22 +224,22 @@ int udhcpd_main(int argc, char *argv[])
}
break;
case DHCPDECLINE:
- DEBUG(LOG_INFO,"received DECLINE");
+ DEBUG("Received DECLINE");
if (lease) {
memset(lease->chaddr, 0, 16);
lease->expires = time(0) + server_config.decline_time;
}
break;
case DHCPRELEASE:
- DEBUG(LOG_INFO,"received RELEASE");
+ DEBUG("Received RELEASE");
if (lease) lease->expires = time(0);
break;
case DHCPINFORM:
- DEBUG(LOG_INFO,"received INFORM");
+ DEBUG("Received INFORM");
send_inform(&packet);
break;
default:
- LOG(LOG_WARNING, "unsupported DHCP message (%02x) -- ignoring", state[0]);
+ bb_info_msg("Unsupported DHCP message (%02x) - ignoring", state[0]);
}
}
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
/* add it to an existing option */
if ((existing = find_option(*opt_list, option->code))) {
- DEBUG(LOG_INFO, "Attaching option %s to existing member of list", option->name);
+ DEBUG("Attaching option %s to existing member of list", option->name);
if (option->flags & OPTION_LIST) {
if (existing->data[OPT_LEN] + length <= 255) {
existing->data = realloc(existing->data,
@@ -122,7 +122,7 @@ static void attach_option(struct option_set **opt_list, struct dhcp_option *opti
} /* else, ignore the data, we could put this in a second option in the future */
} /* else, ignore the new data */
} else {
- DEBUG(LOG_INFO, "Attaching option %s to list", option->name);
+ DEBUG("Attaching option %s to list", option->name);
/* make a new option */
new = xmalloc(sizeof(struct option_set));
@@ -286,7 +286,7 @@ int read_config(const char *file)
keywords[i].handler(keywords[i].def, keywords[i].var);
if (!(in = fopen(file, "r"))) {
- LOG(LOG_ERR, "unable to open config file: %s", file);
+ bb_error_msg("Unable to open config file: %s", file);
return 0;
}
@@ -310,8 +310,9 @@ int read_config(const char *file)
for (i = 0; keywords[i].keyword[0]; i++)
if (!strcasecmp(token, keywords[i].keyword))
if (!keywords[i].handler(line, keywords[i].var)) {
- LOG(LOG_ERR, "Failure parsing line %d of %s", lm, file);
- DEBUG(LOG_ERR, "unable to parse '%s'", debug_orig);
+ bb_error_msg("Failure parsing line %d of %s", lm, file);
+ if (ENABLE_FEATURE_UDHCP_DEBUG)
+ bb_error_msg("unable to parse '%s'", debug_orig);
/* reset back to the default value */
keywords[i].handler(keywords[i].def, keywords[i].var);
}
@@ -330,7 +331,7 @@ void write_leases(void)
unsigned long tmp_time;
if (!(fp = fopen(server_config.lease_file, "w"))) {
- LOG(LOG_ERR, "Unable to open %s for writing", server_config.lease_file);
+ bb_error_msg("Unable to open %s for writing", server_config.lease_file);
return;
}
@@ -368,7 +369,7 @@ void read_leases(const char *file)
struct dhcpOfferedAddr lease;
if (!(fp = fopen(file, "r"))) {
- LOG(LOG_ERR, "Unable to open %s for reading", file);
+ bb_error_msg("Unable to open %s for reading", file);
return;
}
@@ -378,12 +379,12 @@ void read_leases(const char *file)
lease.expires = ntohl(lease.expires);
if (!server_config.remaining) lease.expires -= time(0);
if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) {
- LOG(LOG_WARNING, "Too many leases while loading %s\n", file);
+ bb_error_msg("Too many leases while loading %s", file);
break;
}
i++;
}
}
- DEBUG(LOG_INFO, "Read %d leases", i);
+ DEBUG("Read %d leases", i);
fclose(fp);
}
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)
if (arpping(addr, server_config.server, server_config.arp, server_config.interface) == 0) {
temp.s_addr = addr;
- LOG(LOG_INFO, "%s belongs to someone, reserving it for %ld seconds",
+ bb_info_msg("%s belongs to someone, reserving it for %ld seconds",
inet_ntoa(temp), server_config.conflict_time);
add_lease(blank_chaddr, addr, server_config.conflict_time);
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 @@
void udhcp_background(const char *pidfile);
void udhcp_start_log_and_pid(const char *client_server, const char *pidfile);
-void udhcp_logging(int level, const char *fmt, ...);
void udhcp_run_script(struct dhcpMessage *packet, const char *name);
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)
length = 308;
while (!done) {
if (i >= length) {
- LOG(LOG_WARNING, "bogus packet, option fields too long.");
+ bb_error_msg("Bogus packet, option fields too long");
return NULL;
}
if (optionptr[i + OPT_CODE] == code) {
if (i + 1 + optionptr[i + OPT_LEN] >= length) {
- LOG(LOG_WARNING, "bogus packet, option fields too long.");
+ bb_error_msg("Bogus packet, option fields too long");
return NULL;
}
return optionptr + i + 2;
@@ -89,7 +89,7 @@ uint8_t *get_option(struct dhcpMessage *packet, int code)
break;
case DHCP_OPTION_OVER:
if (i + 1 + optionptr[i + OPT_LEN] >= length) {
- LOG(LOG_WARNING, "bogus packet, option fields too long.");
+ bb_error_msg("Bogus packet, option fields too long");
return NULL;
}
over = optionptr[i + 3];
@@ -137,10 +137,11 @@ int add_option_string(uint8_t *optionptr, uint8_t *string)
/* end position + string length + option code/length + end option */
if (end + string[OPT_LEN] + 2 + 1 >= 308) {
- LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]);
+ bb_error_msg("Option 0x%02x did not fit into the packet",
+ string[OPT_CODE]);
return 0;
}
- DEBUG(LOG_INFO, "adding option 0x%02x", string[OPT_CODE]);
+ DEBUG("adding option 0x%02x", string[OPT_CODE]);
memcpy(optionptr + end, string, string[OPT_LEN] + 2);
optionptr[end + string[OPT_LEN] + 2] = DHCP_END;
return string[OPT_LEN] + 2;
@@ -167,6 +168,6 @@ int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data)
}
}
- DEBUG(LOG_ERR, "Could not add option 0x%02x", code);
+ bb_error_msg("Could not add option 0x%02x", code);
return 0;
}
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)
memset(packet, 0, sizeof(struct dhcpMessage));
bytes = read(fd, packet, sizeof(struct dhcpMessage));
if (bytes < 0) {
- DEBUG(LOG_INFO, "couldn't read on listening socket, ignoring");
+ DEBUG("couldn't read on listening socket, ignoring");
return -1;
}
if (ntohl(packet->cookie) != DHCP_MAGIC) {
- LOG(LOG_ERR, "received bogus message, ignoring");
+ bb_error_msg("Received bogus message, ignoring");
return -2;
}
- DEBUG(LOG_INFO, "Received a packet");
+ DEBUG("Received a packet");
if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) {
for (i = 0; broken_vendors[i][0]; i++) {
if (vendor[OPT_LEN - 2] == (uint8_t) strlen(broken_vendors[i]) &&
!strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])) {
- DEBUG(LOG_INFO, "broken client (%s), forcing broadcast",
+ DEBUG("broken client (%s), forcing broadcast",
broken_vendors[i]);
packet->flags |= htons(BROADCAST_FLAG);
}
@@ -123,7 +123,7 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
struct udp_dhcp_packet packet;
if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
- DEBUG(LOG_ERR, "socket call failed: %m");
+ bb_perror_msg("socket");
return -1;
}
@@ -136,7 +136,7 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
dest.sll_halen = 6;
memcpy(dest.sll_addr, dest_arp, 6);
if (bind(fd, (struct sockaddr *)&dest, sizeof(struct sockaddr_ll)) < 0) {
- DEBUG(LOG_ERR, "bind call failed: %m");
+ bb_perror_msg("bind");
close(fd);
return -1;
}
@@ -159,7 +159,7 @@ int udhcp_raw_packet(struct dhcpMessage *payload, uint32_t source_ip, int source
result = sendto(fd, &packet, sizeof(struct udp_dhcp_packet), 0, (struct sockaddr *) &dest, sizeof(dest));
if (result <= 0) {
- DEBUG(LOG_ERR, "write on socket failed: %m");
+ bb_perror_msg("sendto");
}
close(fd);
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)
pid_fd = open(pidfile, O_CREAT | O_WRONLY, 0644);
if (pid_fd < 0) {
- LOG(LOG_ERR, "Unable to open pidfile %s: %m\n", pidfile);
+ bb_perror_msg("Unable to open pidfile %s", pidfile);
} else {
lockf(pid_fd, F_LOCK, 0);
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)
if (client_config.script == NULL)
return;
- DEBUG(LOG_INFO, "vforking and execle'ing %s", client_config.script);
+ DEBUG("vfork'ing and execle'ing %s", client_config.script);
envp = fill_envp(packet);
/* call script */
@@ -216,7 +216,7 @@ void udhcp_run_script(struct dhcpMessage *packet, const char *name)
/* exec script */
execle(client_config.script, client_config.script,
name, NULL, envp);
- LOG(LOG_ERR, "script %s failed: %m", client_config.script);
+ bb_perror_msg("script %s failed", client_config.script);
exit(1);
}
}
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 @@
/* send a packet to giaddr using the kernel ip stack */
static int send_packet_to_relay(struct dhcpMessage *payload)
{
- DEBUG(LOG_INFO, "Forwarding packet to relay");
+ DEBUG("Forwarding packet to relay");
return udhcp_kernel_packet(payload, server_config.server, SERVER_PORT,
payload->giaddr, SERVER_PORT);
@@ -49,19 +49,19 @@ static int send_packet_to_client(struct dhcpMessage *payload, int force_broadcas
uint32_t ciaddr;
if (force_broadcast) {
- DEBUG(LOG_INFO, "broadcasting packet to client (NAK)");
+ DEBUG("broadcasting packet to client (NAK)");
ciaddr = INADDR_BROADCAST;
chaddr = MAC_BCAST_ADDR;
} else if (payload->ciaddr) {
- DEBUG(LOG_INFO, "unicasting packet to client ciaddr");
+ DEBUG("unicasting packet to client ciaddr");
ciaddr = payload->ciaddr;
chaddr = payload->chaddr;
} else if (ntohs(payload->flags) & BROADCAST_FLAG) {
- DEBUG(LOG_INFO, "broadcasting packet to client (requested)");
+ DEBUG("broadcasting packet to client (requested)");
ciaddr = INADDR_BROADCAST;
chaddr = MAC_BCAST_ADDR;
} else {
- DEBUG(LOG_INFO, "unicasting packet to client yiaddr");
+ DEBUG("unicasting packet to client yiaddr");
ciaddr = payload->yiaddr;
chaddr = payload->chaddr;
}
@@ -158,12 +158,12 @@ int sendOffer(struct dhcpMessage *oldpacket)
}
if(!packet.yiaddr) {
- LOG(LOG_WARNING, "no IP addresses to give -- OFFER abandoned");
+ bb_error_msg("No IP addresses to give - OFFER abandoned");
return -1;
}
if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
- LOG(LOG_WARNING, "lease pool is full -- OFFER abandoned");
+ bb_error_msg("Lease pool is full - OFFER abandoned");
return -1;
}
@@ -197,7 +197,7 @@ int sendOffer(struct dhcpMessage *oldpacket)
add_bootp_options(&packet);
addr.s_addr = packet.yiaddr;
- LOG(LOG_INFO, "sending OFFER of %s", inet_ntoa(addr));
+ bb_info_msg("Sending OFFER of %s", inet_ntoa(addr));
return send_packet(&packet, 0);
}
@@ -208,7 +208,7 @@ int sendNAK(struct dhcpMessage *oldpacket)
init_packet(&packet, oldpacket, DHCPNAK);
- DEBUG(LOG_INFO, "sending NAK");
+ DEBUG("Sending NAK");
return send_packet(&packet, 1);
}
@@ -245,7 +245,7 @@ int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr)
add_bootp_options(&packet);
addr.s_addr = packet.yiaddr;
- LOG(LOG_INFO, "sending ACK to %s", inet_ntoa(addr));
+ bb_info_msg("Sending ACK to %s", inet_ntoa(addr));
if (send_packet(&packet, 0) < 0)
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];
static void signal_handler(int sig)
{
if (send(signal_pipe[1], &sig, sizeof(sig), MSG_DONTWAIT) < 0)
- DEBUG(LOG_ERR, "Could not send signal: %m");
+ bb_perror_msg("Could not send signal");
}
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)
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {
our_ip = (struct sockaddr_in *) &ifr.ifr_addr;
*addr = our_ip->sin_addr.s_addr;
- DEBUG(LOG_INFO, "%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
+ DEBUG("%s (our ip) = %s", ifr.ifr_name, inet_ntoa(our_ip->sin_addr));
} else {
- LOG(LOG_ERR, "SIOCGIFADDR failed, is the interface up and configured?: %m");
+ bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?");
close(fd);
return -1;
}
}
if (ioctl(fd, SIOCGIFINDEX, &ifr) == 0) {
- DEBUG(LOG_INFO, "adapter index %d", ifr.ifr_ifindex);
+ DEBUG("adapter index %d", ifr.ifr_ifindex);
*ifindex = ifr.ifr_ifindex;
} else {
- LOG(LOG_ERR, "SIOCGIFINDEX failed!: %m");
+ bb_perror_msg("SIOCGIFINDEX failed");
close(fd);
return -1;
}
if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0) {
memcpy(arp, ifr.ifr_hwaddr.sa_data, 6);
- DEBUG(LOG_INFO, "adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
+ DEBUG("adapter hardware address %02x:%02x:%02x:%02x:%02x:%02x",
arp[0], arp[1], arp[2], arp[3], arp[4], arp[5]);
} else {
- LOG(LOG_ERR, "SIOCGIFHWADDR failed!: %m");
+ bb_perror_msg("SIOCGIFHWADDR failed");
close(fd);
return -1;
}
} else {
- LOG(LOG_ERR, "socket failed!: %m");
+ bb_perror_msg("socket failed");
return -1;
}
close(fd);
@@ -101,9 +101,9 @@ int listen_socket(uint32_t ip, int port, char *inf)
struct sockaddr_in addr;
int n = 1;
- DEBUG(LOG_INFO, "Opening listen socket on 0x%08x:%d %s", ip, port, inf);
+ DEBUG("Opening listen socket on 0x%08x:%d %s", ip, port, inf);
if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
- DEBUG(LOG_ERR, "socket call failed: %m");
+ bb_perror_msg("socket");
return -1;
}