mirror of https://github.com/mirror/busybox.git
udhcp: get rid of bb_info_msg()
function old new delta udhcpd_main 1501 1531 +30 d6_recv_raw_packet 251 264 +13 perform_d6_release 188 198 +10 udhcpc6_main 2443 2449 +6 udhcp_recv_raw_packet 582 588 +6 udhcp_recv_kernel_packet 132 138 +6 send_d6_renew 140 146 +6 d6_recv_kernel_packet 118 124 +6 send_renew 77 82 +5 send_discover 85 90 +5 send_decline 84 89 +5 send_d6_select 97 102 +5 send_d6_discover 174 179 +5 perform_release 167 172 +5 count_lines 72 74 +2 udhcpc_main 2836 2837 +1 bb_info_msg 125 - -125 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 17/4 up/down: 117/-180) Total: -63 bytes text data bss dec hex filename 924935 906 17160 943001 e6399 busybox_old 924736 906 17160 942802 e62d2 busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>1_25_stable
parent
80f0f1d712
commit
8f2e99c813
|
@ -1150,7 +1150,6 @@ extern void bb_herror_msg(const char *s, ...) __attribute__ ((format (printf, 1,
|
||||||
extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
|
extern void bb_herror_msg_and_die(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2))) FAST_FUNC;
|
||||||
extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
|
extern void bb_perror_nomsg_and_die(void) NORETURN FAST_FUNC;
|
||||||
extern void bb_perror_nomsg(void) FAST_FUNC;
|
extern void bb_perror_nomsg(void) FAST_FUNC;
|
||||||
extern void bb_info_msg(const char *s, ...) __attribute__ ((format (printf, 1, 2))) FAST_FUNC;
|
|
||||||
extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
|
extern void bb_verror_msg(const char *s, va_list p, const char *strerr) FAST_FUNC;
|
||||||
extern void bb_logenv_override(void) FAST_FUNC;
|
extern void bb_logenv_override(void) FAST_FUNC;
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,6 @@ lib-y += get_volsize.o
|
||||||
lib-y += herror_msg.o
|
lib-y += herror_msg.o
|
||||||
lib-y += human_readable.o
|
lib-y += human_readable.o
|
||||||
lib-y += inet_common.o
|
lib-y += inet_common.o
|
||||||
lib-y += info_msg.o
|
|
||||||
lib-y += inode_hash.o
|
lib-y += inode_hash.o
|
||||||
lib-y += isdirectory.o
|
lib-y += isdirectory.o
|
||||||
lib-y += kernel_version.o
|
lib-y += kernel_version.o
|
||||||
|
|
|
@ -1,62 +0,0 @@
|
||||||
/* vi: set sw=4 ts=4: */
|
|
||||||
/*
|
|
||||||
* Utility routines.
|
|
||||||
*
|
|
||||||
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
|
||||||
*
|
|
||||||
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "libbb.h"
|
|
||||||
#if ENABLE_FEATURE_SYSLOG
|
|
||||||
# include <syslog.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void FAST_FUNC bb_info_msg(const char *s, ...)
|
|
||||||
{
|
|
||||||
#ifdef THIS_ONE_DOESNT_DO_SINGLE_WRITE
|
|
||||||
va_list p;
|
|
||||||
/* va_copy is used because it is not portable
|
|
||||||
* to use va_list p twice */
|
|
||||||
va_list p2;
|
|
||||||
|
|
||||||
va_start(p, s);
|
|
||||||
va_copy(p2, p);
|
|
||||||
if (logmode & LOGMODE_STDIO) {
|
|
||||||
vprintf(s, p);
|
|
||||||
fputs(msg_eol, stdout);
|
|
||||||
}
|
|
||||||
# if ENABLE_FEATURE_SYSLOG
|
|
||||||
if (logmode & LOGMODE_SYSLOG)
|
|
||||||
vsyslog(LOG_INFO, s, p2);
|
|
||||||
# endif
|
|
||||||
va_end(p2);
|
|
||||||
va_end(p);
|
|
||||||
#else
|
|
||||||
int used;
|
|
||||||
char *msg;
|
|
||||||
va_list p;
|
|
||||||
|
|
||||||
if (logmode == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
va_start(p, s);
|
|
||||||
used = vasprintf(&msg, s, p);
|
|
||||||
va_end(p);
|
|
||||||
if (used < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
# if ENABLE_FEATURE_SYSLOG
|
|
||||||
if (logmode & LOGMODE_SYSLOG)
|
|
||||||
syslog(LOG_INFO, "%s", msg);
|
|
||||||
# endif
|
|
||||||
if (logmode & LOGMODE_STDIO) {
|
|
||||||
fflush_all();
|
|
||||||
/* used = strlen(msg); - must be true already */
|
|
||||||
msg[used++] = '\n';
|
|
||||||
full_write(STDOUT_FILENO, msg, used);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(msg);
|
|
||||||
#endif
|
|
||||||
}
|
|
|
@ -132,6 +132,6 @@ int FAST_FUNC arpping(uint32_t test_nip,
|
||||||
|
|
||||||
ret:
|
ret:
|
||||||
close(s);
|
close(s);
|
||||||
log1("%srp reply received for this address", rv ? "No a" : "A");
|
log1("%srp reply received for this address", rv ? "no a" : "A");
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ static void log_option(const char *pfx, const uint8_t *opt)
|
||||||
if (dhcp_verbose >= 2) {
|
if (dhcp_verbose >= 2) {
|
||||||
char buf[256 * 2 + 2];
|
char buf[256 * 2 + 2];
|
||||||
*bin2hex(buf, (void*) (opt + OPT_DATA), opt[OPT_LEN]) = '\0';
|
*bin2hex(buf, (void*) (opt + OPT_DATA), opt[OPT_LEN]) = '\0';
|
||||||
bb_info_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf);
|
bb_error_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -269,7 +269,7 @@ uint8_t* FAST_FUNC udhcp_get_option(struct dhcp_packet *packet, int code)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* log3 because udhcpc uses it a lot - very noisy */
|
/* log3 because udhcpc uses it a lot - very noisy */
|
||||||
log3("Option 0x%02x not found", code);
|
log3("option 0x%02x not found", code);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -402,7 +402,7 @@ static NOINLINE void attach_option(
|
||||||
struct option_set *new, **curr;
|
struct option_set *new, **curr;
|
||||||
|
|
||||||
/* make a new option */
|
/* make a new option */
|
||||||
log2("Attaching option %02x to list", optflag->code);
|
log2("attaching option %02x to list", optflag->code);
|
||||||
new = xmalloc(sizeof(*new));
|
new = xmalloc(sizeof(*new));
|
||||||
new->data = xmalloc(length + OPT_DATA);
|
new->data = xmalloc(length + OPT_DATA);
|
||||||
new->data[OPT_CODE] = optflag->code;
|
new->data[OPT_CODE] = optflag->code;
|
||||||
|
@ -422,7 +422,7 @@ static NOINLINE void attach_option(
|
||||||
unsigned old_len;
|
unsigned old_len;
|
||||||
|
|
||||||
/* add it to an existing option */
|
/* add it to an existing option */
|
||||||
log2("Attaching option %02x to existing member of list", optflag->code);
|
log2("attaching option %02x to existing member of list", optflag->code);
|
||||||
old_len = existing->data[OPT_LEN];
|
old_len = existing->data[OPT_LEN];
|
||||||
if (old_len + length < 255) {
|
if (old_len + length < 255) {
|
||||||
/* actually 255 is ok too, but adding a space can overlow it */
|
/* actually 255 is ok too, but adding a space can overlow it */
|
||||||
|
|
|
@ -256,16 +256,16 @@ struct option_set *udhcp_find_option(struct option_set *opt_list, uint8_t code)
|
||||||
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
|
#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
|
||||||
# define IF_UDHCP_VERBOSE(...) __VA_ARGS__
|
# define IF_UDHCP_VERBOSE(...) __VA_ARGS__
|
||||||
extern unsigned dhcp_verbose;
|
extern unsigned dhcp_verbose;
|
||||||
# define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0)
|
# define log1(...) do { if (dhcp_verbose >= 1) bb_error_msg(__VA_ARGS__); } while (0)
|
||||||
# if CONFIG_UDHCP_DEBUG >= 2
|
# if CONFIG_UDHCP_DEBUG >= 2
|
||||||
void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC;
|
void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC;
|
||||||
# define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0)
|
# define log2(...) do { if (dhcp_verbose >= 2) bb_error_msg(__VA_ARGS__); } while (0)
|
||||||
# else
|
# else
|
||||||
# define udhcp_dump_packet(...) ((void)0)
|
# define udhcp_dump_packet(...) ((void)0)
|
||||||
# define log2(...) ((void)0)
|
# define log2(...) ((void)0)
|
||||||
# endif
|
# endif
|
||||||
# if CONFIG_UDHCP_DEBUG >= 3
|
# if CONFIG_UDHCP_DEBUG >= 3
|
||||||
# define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0)
|
# define log3(...) do { if (dhcp_verbose >= 3) bb_error_msg(__VA_ARGS__); } while (0)
|
||||||
# else
|
# else
|
||||||
# define log3(...) ((void)0)
|
# define log3(...) ((void)0)
|
||||||
# endif
|
# endif
|
||||||
|
|
|
@ -251,7 +251,7 @@ static void d6_run_script(struct d6_packet *packet, const char *name)
|
||||||
envp = fill_envp(packet);
|
envp = fill_envp(packet);
|
||||||
|
|
||||||
/* call script */
|
/* call script */
|
||||||
log1("Executing %s %s", client_config.script, name);
|
log1("executing %s %s", client_config.script, name);
|
||||||
argv[0] = (char*) client_config.script;
|
argv[0] = (char*) client_config.script;
|
||||||
argv[1] = (char*) name;
|
argv[1] = (char*) name;
|
||||||
argv[2] = NULL;
|
argv[2] = NULL;
|
||||||
|
@ -428,7 +428,7 @@ static NOINLINE int send_d6_discover(uint32_t xid, struct in6_addr *requested_ip
|
||||||
*/
|
*/
|
||||||
opt_ptr = add_d6_client_options(opt_ptr);
|
opt_ptr = add_d6_client_options(opt_ptr);
|
||||||
|
|
||||||
bb_info_msg("Sending discover...");
|
bb_error_msg("sending %s", "discover");
|
||||||
return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
|
return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,7 +481,7 @@ static NOINLINE int send_d6_select(uint32_t xid)
|
||||||
*/
|
*/
|
||||||
opt_ptr = add_d6_client_options(opt_ptr);
|
opt_ptr = add_d6_client_options(opt_ptr);
|
||||||
|
|
||||||
bb_info_msg("Sending select...");
|
bb_error_msg("sending %s", "select");
|
||||||
return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
|
return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -550,7 +550,7 @@ static NOINLINE int send_d6_renew(uint32_t xid, struct in6_addr *server_ipv6, st
|
||||||
*/
|
*/
|
||||||
opt_ptr = add_d6_client_options(opt_ptr);
|
opt_ptr = add_d6_client_options(opt_ptr);
|
||||||
|
|
||||||
bb_info_msg("Sending renew...");
|
bb_error_msg("sending %s", "renew");
|
||||||
if (server_ipv6)
|
if (server_ipv6)
|
||||||
return d6_send_kernel_packet(
|
return d6_send_kernel_packet(
|
||||||
&packet, (opt_ptr - (uint8_t*) &packet),
|
&packet, (opt_ptr - (uint8_t*) &packet),
|
||||||
|
@ -573,7 +573,7 @@ static int send_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cu
|
||||||
/* IA NA (contains our current IP) */
|
/* IA NA (contains our current IP) */
|
||||||
opt_ptr = d6_store_blob(opt_ptr, client6_data.ia_na, client6_data.ia_na->len + 2+2);
|
opt_ptr = d6_store_blob(opt_ptr, client6_data.ia_na, client6_data.ia_na->len + 2+2);
|
||||||
|
|
||||||
bb_info_msg("Sending release...");
|
bb_error_msg("sending %s", "release");
|
||||||
return d6_send_kernel_packet(
|
return d6_send_kernel_packet(
|
||||||
&packet, (opt_ptr - (uint8_t*) &packet),
|
&packet, (opt_ptr - (uint8_t*) &packet),
|
||||||
our_cur_ipv6, CLIENT_PORT6,
|
our_cur_ipv6, CLIENT_PORT6,
|
||||||
|
@ -592,19 +592,19 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6
|
||||||
|
|
||||||
bytes = safe_read(fd, &packet, sizeof(packet));
|
bytes = safe_read(fd, &packet, sizeof(packet));
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
log1("Packet read error, ignoring");
|
log1("packet read error, ignoring");
|
||||||
/* NB: possible down interface, etc. Caller should pause. */
|
/* NB: possible down interface, etc. Caller should pause. */
|
||||||
return bytes; /* returns -1 */
|
return bytes; /* returns -1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes < (int) (sizeof(packet.ip6) + sizeof(packet.udp))) {
|
if (bytes < (int) (sizeof(packet.ip6) + sizeof(packet.udp))) {
|
||||||
log1("Packet is too short, ignoring");
|
log1("packet is too short, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes < sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen)) {
|
if (bytes < sizeof(packet.ip6) + ntohs(packet.ip6.ip6_plen)) {
|
||||||
/* packet is bigger than sizeof(packet), we did partial read */
|
/* packet is bigger than sizeof(packet), we did partial read */
|
||||||
log1("Oversized packet, ignoring");
|
log1("oversized packet, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,7 +618,7 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6
|
||||||
/* || bytes > (int) sizeof(packet) - can't happen */
|
/* || bytes > (int) sizeof(packet) - can't happen */
|
||||||
|| packet.udp.len != packet.ip6.ip6_plen
|
|| packet.udp.len != packet.ip6.ip6_plen
|
||||||
) {
|
) {
|
||||||
log1("Unrelated/bogus packet, ignoring");
|
log1("unrelated/bogus packet, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -630,11 +630,11 @@ static NOINLINE int d6_recv_raw_packet(struct in6_addr *peer_ipv6
|
||||||
// check = packet.udp.check;
|
// check = packet.udp.check;
|
||||||
// packet.udp.check = 0;
|
// packet.udp.check = 0;
|
||||||
// if (check && check != inet_cksum((uint16_t *)&packet, bytes)) {
|
// if (check && check != inet_cksum((uint16_t *)&packet, bytes)) {
|
||||||
// log1("Packet with bad UDP checksum received, ignoring");
|
// log1("packet with bad UDP checksum received, ignoring");
|
||||||
// return -2;
|
// return -2;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
log1("Received a packet");
|
log1("received %s", "a packet");
|
||||||
d6_dump_packet(&packet.data);
|
d6_dump_packet(&packet.data);
|
||||||
|
|
||||||
bytes -= sizeof(packet.ip6) + sizeof(packet.udp);
|
bytes -= sizeof(packet.ip6) + sizeof(packet.udp);
|
||||||
|
@ -722,10 +722,10 @@ static int d6_raw_socket(int ifindex)
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
log1("Opening raw socket on ifindex %d", ifindex); //log2?
|
log1("opening raw socket on ifindex %d", ifindex); //log2?
|
||||||
|
|
||||||
fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6));
|
fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6));
|
||||||
log1("Got raw socket fd %d", fd); //log2?
|
log1("got raw socket fd %d", fd); //log2?
|
||||||
|
|
||||||
sock.sll_family = AF_PACKET;
|
sock.sll_family = AF_PACKET;
|
||||||
sock.sll_protocol = htons(ETH_P_IPV6);
|
sock.sll_protocol = htons(ETH_P_IPV6);
|
||||||
|
@ -738,18 +738,18 @@ static int d6_raw_socket(int ifindex)
|
||||||
/* Ignoring error (kernel may lack support for this) */
|
/* Ignoring error (kernel may lack support for this) */
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog,
|
if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog,
|
||||||
sizeof(filter_prog)) >= 0)
|
sizeof(filter_prog)) >= 0)
|
||||||
log1("Attached filter to raw socket fd %d", fd); // log?
|
log1("attached filter to raw socket fd %d", fd); // log?
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
log1("Created raw socket");
|
log1("created raw socket");
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void change_listen_mode(int new_mode)
|
static void change_listen_mode(int new_mode)
|
||||||
{
|
{
|
||||||
log1("Entering listen mode: %s",
|
log1("entering listen mode: %s",
|
||||||
new_mode != LISTEN_NONE
|
new_mode != LISTEN_NONE
|
||||||
? (new_mode == LISTEN_KERNEL ? "kernel" : "raw")
|
? (new_mode == LISTEN_KERNEL ? "kernel" : "raw")
|
||||||
: "none"
|
: "none"
|
||||||
|
@ -770,7 +770,7 @@ static void change_listen_mode(int new_mode)
|
||||||
/* Called only on SIGUSR1 */
|
/* Called only on SIGUSR1 */
|
||||||
static void perform_renew(void)
|
static void perform_renew(void)
|
||||||
{
|
{
|
||||||
bb_info_msg("Performing a DHCP renew");
|
bb_error_msg("performing DHCP renew");
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case BOUND:
|
case BOUND:
|
||||||
change_listen_mode(LISTEN_KERNEL);
|
change_listen_mode(LISTEN_KERNEL);
|
||||||
|
@ -794,11 +794,11 @@ static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *ou
|
||||||
{
|
{
|
||||||
/* send release packet */
|
/* send release packet */
|
||||||
if (state == BOUND || state == RENEWING || state == REBINDING) {
|
if (state == BOUND || state == RENEWING || state == REBINDING) {
|
||||||
bb_info_msg("Unicasting a release");
|
bb_error_msg("unicasting a release");
|
||||||
send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */
|
send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */
|
||||||
d6_run_script(NULL, "deconfig");
|
d6_run_script(NULL, "deconfig");
|
||||||
}
|
}
|
||||||
bb_info_msg("Entering released state");
|
bb_error_msg("entering released state");
|
||||||
|
|
||||||
change_listen_mode(LISTEN_NONE);
|
change_listen_mode(LISTEN_NONE);
|
||||||
state = RELEASED;
|
state = RELEASED;
|
||||||
|
@ -1034,7 +1034,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||||
/* Create pidfile */
|
/* Create pidfile */
|
||||||
write_pidfile(client_config.pidfile);
|
write_pidfile(client_config.pidfile);
|
||||||
/* Goes to stdout (unless NOMMU) and possibly syslog */
|
/* Goes to stdout (unless NOMMU) and possibly syslog */
|
||||||
bb_info_msg("%s (v"BB_VER") started", applet_name);
|
bb_error_msg("started, v"BB_VER);
|
||||||
/* Set up the signal pipe */
|
/* Set up the signal pipe */
|
||||||
udhcp_sp_setup();
|
udhcp_sp_setup();
|
||||||
/* We want random_xid to be random... */
|
/* We want random_xid to be random... */
|
||||||
|
@ -1074,7 +1074,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||||
retval = 0;
|
retval = 0;
|
||||||
/* If we already timed out, fall through with retval = 0, else... */
|
/* If we already timed out, fall through with retval = 0, else... */
|
||||||
if ((int)tv.tv_sec > 0) {
|
if ((int)tv.tv_sec > 0) {
|
||||||
log1("Waiting on select %u seconds", (int)tv.tv_sec);
|
log1("waiting on select %u seconds", (int)tv.tv_sec);
|
||||||
timestamp_before_wait = (unsigned)monotonic_sec();
|
timestamp_before_wait = (unsigned)monotonic_sec();
|
||||||
retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
|
retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
|
||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
|
@ -1124,14 +1124,14 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||||
d6_run_script(NULL, "leasefail");
|
d6_run_script(NULL, "leasefail");
|
||||||
#if BB_MMU /* -b is not supported on NOMMU */
|
#if BB_MMU /* -b is not supported on NOMMU */
|
||||||
if (opt & OPT_b) { /* background if no lease */
|
if (opt & OPT_b) { /* background if no lease */
|
||||||
bb_info_msg("No lease, forking to background");
|
bb_error_msg("no lease, forking to background");
|
||||||
client_background();
|
client_background();
|
||||||
/* do not background again! */
|
/* do not background again! */
|
||||||
opt = ((opt & ~OPT_b) | OPT_f);
|
opt = ((opt & ~OPT_b) | OPT_f);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (opt & OPT_n) { /* abort if no lease */
|
if (opt & OPT_n) { /* abort if no lease */
|
||||||
bb_info_msg("No lease, failing");
|
bb_error_msg("no lease, failing");
|
||||||
retval = 1;
|
retval = 1;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
@ -1159,7 +1159,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||||
state = RENEWING;
|
state = RENEWING;
|
||||||
client_config.first_secs = 0; /* make secs field count from 0 */
|
client_config.first_secs = 0; /* make secs field count from 0 */
|
||||||
change_listen_mode(LISTEN_KERNEL);
|
change_listen_mode(LISTEN_KERNEL);
|
||||||
log1("Entering renew state");
|
log1("entering renew state");
|
||||||
/* fall right through */
|
/* fall right through */
|
||||||
case RENEW_REQUESTED: /* manual (SIGUSR1) renew */
|
case RENEW_REQUESTED: /* manual (SIGUSR1) renew */
|
||||||
case_RENEW_REQUESTED:
|
case_RENEW_REQUESTED:
|
||||||
|
@ -1179,7 +1179,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Timed out, enter rebinding state */
|
/* Timed out, enter rebinding state */
|
||||||
log1("Entering rebinding state");
|
log1("entering rebinding state");
|
||||||
state = REBINDING;
|
state = REBINDING;
|
||||||
/* fall right through */
|
/* fall right through */
|
||||||
case REBINDING:
|
case REBINDING:
|
||||||
|
@ -1194,7 +1194,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Timed out, enter init state */
|
/* Timed out, enter init state */
|
||||||
bb_info_msg("Lease lost, entering init state");
|
bb_error_msg("lease lost, entering init state");
|
||||||
d6_run_script(NULL, "deconfig");
|
d6_run_script(NULL, "deconfig");
|
||||||
state = INIT_SELECTING;
|
state = INIT_SELECTING;
|
||||||
client_config.first_secs = 0; /* make secs field count from 0 */
|
client_config.first_secs = 0; /* make secs field count from 0 */
|
||||||
|
@ -1242,7 +1242,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||||
timeout = INT_MAX;
|
timeout = INT_MAX;
|
||||||
continue;
|
continue;
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
bb_info_msg("Received SIGTERM");
|
bb_error_msg("received %s", "SIGTERM");
|
||||||
goto ret0;
|
goto ret0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1260,7 +1260,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||||
len = d6_recv_raw_packet(&srv6_buf, &packet, sockfd);
|
len = d6_recv_raw_packet(&srv6_buf, &packet, sockfd);
|
||||||
if (len == -1) {
|
if (len == -1) {
|
||||||
/* Error is severe, reopen socket */
|
/* Error is severe, reopen socket */
|
||||||
bb_info_msg("Read error: %s, reopening socket", strerror(errno));
|
bb_error_msg("read error: %s, reopening socket", strerror(errno));
|
||||||
sleep(discover_timeout); /* 3 seconds by default */
|
sleep(discover_timeout); /* 3 seconds by default */
|
||||||
change_listen_mode(listen_mode); /* just close and reopen */
|
change_listen_mode(listen_mode); /* just close and reopen */
|
||||||
}
|
}
|
||||||
|
@ -1298,7 +1298,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||||
option = d6_find_option(packet.d6_options, packet_end, D6_OPT_STATUS_CODE);
|
option = d6_find_option(packet.d6_options, packet_end, D6_OPT_STATUS_CODE);
|
||||||
if (option && option->data[4] != 0) {
|
if (option && option->data[4] != 0) {
|
||||||
/* return to init state */
|
/* return to init state */
|
||||||
bb_info_msg("Received DHCP NAK (%u)", option->data[4]);
|
bb_error_msg("received DHCP NAK (%u)", option->data[4]);
|
||||||
d6_run_script(&packet, "nak");
|
d6_run_script(&packet, "nak");
|
||||||
if (state != REQUESTING)
|
if (state != REQUESTING)
|
||||||
d6_run_script(NULL, "deconfig");
|
d6_run_script(NULL, "deconfig");
|
||||||
|
@ -1453,7 +1453,7 @@ int udhcpc6_main(int argc UNUSED_PARAM, char **argv)
|
||||||
lease_seconds = 0x0fffffff;
|
lease_seconds = 0x0fffffff;
|
||||||
/* enter bound state */
|
/* enter bound state */
|
||||||
timeout = lease_seconds / 2;
|
timeout = lease_seconds / 2;
|
||||||
bb_info_msg("Lease obtained, lease time %u",
|
bb_error_msg("lease obtained, lease time %u",
|
||||||
/*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds);
|
/*inet_ntoa(temp_addr),*/ (unsigned)lease_seconds);
|
||||||
d6_run_script(&packet, state == REQUESTING ? "bound" : "renew");
|
d6_run_script(&packet, state == REQUESTING ? "bound" : "renew");
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,8 @@ void FAST_FUNC d6_dump_packet(struct d6_packet *packet)
|
||||||
if (dhcp_verbose < 2)
|
if (dhcp_verbose < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bb_info_msg(
|
bb_error_msg(
|
||||||
" xid %x"
|
"xid %x"
|
||||||
, packet->d6_xid32
|
, packet->d6_xid32
|
||||||
);
|
);
|
||||||
//*bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0';
|
//*bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0';
|
||||||
|
@ -35,15 +35,15 @@ int FAST_FUNC d6_recv_kernel_packet(struct in6_addr *peer_ipv6
|
||||||
memset(packet, 0, sizeof(*packet));
|
memset(packet, 0, sizeof(*packet));
|
||||||
bytes = safe_read(fd, packet, sizeof(*packet));
|
bytes = safe_read(fd, packet, sizeof(*packet));
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
log1("Packet read error, ignoring");
|
log1("packet read error, ignoring");
|
||||||
return bytes; /* returns -1 */
|
return bytes; /* returns -1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes < offsetof(struct d6_packet, d6_options)) {
|
if (bytes < offsetof(struct d6_packet, d6_options)) {
|
||||||
bb_info_msg("Packet with bad magic, ignoring");
|
bb_error_msg("packet with bad magic, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
log1("Received a packet");
|
log1("received %s", "a packet");
|
||||||
d6_dump_packet(packet);
|
d6_dump_packet(packet);
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
|
|
|
@ -13,7 +13,7 @@ int FAST_FUNC d6_listen_socket(int port, const char *inf)
|
||||||
int fd;
|
int fd;
|
||||||
struct sockaddr_in6 addr;
|
struct sockaddr_in6 addr;
|
||||||
|
|
||||||
log1("Opening listen socket on *:%d %s", port, inf);
|
log1("opening listen socket on *:%d %s", port, inf);
|
||||||
fd = xsocket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
fd = xsocket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
|
||||||
setsockopt_reuseaddr(fd);
|
setsockopt_reuseaddr(fd);
|
||||||
|
|
|
@ -561,7 +561,7 @@ static void udhcp_run_script(struct dhcp_packet *packet, const char *name)
|
||||||
envp = fill_envp(packet);
|
envp = fill_envp(packet);
|
||||||
|
|
||||||
/* call script */
|
/* call script */
|
||||||
log1("Executing %s %s", client_config.script, name);
|
log1("executing %s %s", client_config.script, name);
|
||||||
argv[0] = (char*) client_config.script;
|
argv[0] = (char*) client_config.script;
|
||||||
argv[1] = (char*) name;
|
argv[1] = (char*) name;
|
||||||
argv[2] = NULL;
|
argv[2] = NULL;
|
||||||
|
@ -714,7 +714,7 @@ static NOINLINE int send_discover(uint32_t xid, uint32_t requested)
|
||||||
*/
|
*/
|
||||||
add_client_options(&packet);
|
add_client_options(&packet);
|
||||||
|
|
||||||
bb_info_msg("Sending discover...");
|
bb_error_msg("sending %s", "discover");
|
||||||
return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
|
return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,7 +758,7 @@ static NOINLINE int send_select(uint32_t xid, uint32_t server, uint32_t requeste
|
||||||
add_client_options(&packet);
|
add_client_options(&packet);
|
||||||
|
|
||||||
addr.s_addr = requested;
|
addr.s_addr = requested;
|
||||||
bb_info_msg("Sending select for %s...", inet_ntoa(addr));
|
bb_error_msg("sending select for %s", inet_ntoa(addr));
|
||||||
return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
|
return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,7 +797,7 @@ static NOINLINE int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr)
|
||||||
*/
|
*/
|
||||||
add_client_options(&packet);
|
add_client_options(&packet);
|
||||||
|
|
||||||
bb_info_msg("Sending renew...");
|
bb_error_msg("sending %s", "renew");
|
||||||
return bcast_or_ucast(&packet, ciaddr, server);
|
return bcast_or_ucast(&packet, ciaddr, server);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -826,7 +826,7 @@ static NOINLINE int send_decline(/*uint32_t xid,*/ uint32_t server, uint32_t req
|
||||||
|
|
||||||
udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
|
udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
|
||||||
|
|
||||||
bb_info_msg("Sending decline...");
|
bb_error_msg("sending %s", "decline");
|
||||||
return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
|
return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -846,7 +846,7 @@ static int send_release(uint32_t server, uint32_t ciaddr)
|
||||||
|
|
||||||
udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
|
udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
|
||||||
|
|
||||||
bb_info_msg("Sending release...");
|
bb_error_msg("sending %s", "release");
|
||||||
/* Note: normally we unicast here since "server" is not zero.
|
/* Note: normally we unicast here since "server" is not zero.
|
||||||
* However, there _are_ people who run "address-less" DHCP servers,
|
* However, there _are_ people who run "address-less" DHCP servers,
|
||||||
* and reportedly ISC dhcp client and Windows allow that.
|
* and reportedly ISC dhcp client and Windows allow that.
|
||||||
|
@ -881,7 +881,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
if (errno == EINTR)
|
if (errno == EINTR)
|
||||||
continue;
|
continue;
|
||||||
log1("Packet read error, ignoring");
|
log1("packet read error, ignoring");
|
||||||
/* NB: possible down interface, etc. Caller should pause. */
|
/* NB: possible down interface, etc. Caller should pause. */
|
||||||
return bytes; /* returns -1 */
|
return bytes; /* returns -1 */
|
||||||
}
|
}
|
||||||
|
@ -889,13 +889,13 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) {
|
if (bytes < (int) (sizeof(packet.ip) + sizeof(packet.udp))) {
|
||||||
log1("Packet is too short, ignoring");
|
log1("packet is too short, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes < ntohs(packet.ip.tot_len)) {
|
if (bytes < ntohs(packet.ip.tot_len)) {
|
||||||
/* packet is bigger than sizeof(packet), we did partial read */
|
/* packet is bigger than sizeof(packet), we did partial read */
|
||||||
log1("Oversized packet, ignoring");
|
log1("oversized packet, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -910,7 +910,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
|
||||||
/* || bytes > (int) sizeof(packet) - can't happen */
|
/* || bytes > (int) sizeof(packet) - can't happen */
|
||||||
|| ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip))
|
|| ntohs(packet.udp.len) != (uint16_t)(bytes - sizeof(packet.ip))
|
||||||
) {
|
) {
|
||||||
log1("Unrelated/bogus packet, ignoring");
|
log1("unrelated/bogus packet, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -918,7 +918,7 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
|
||||||
check = packet.ip.check;
|
check = packet.ip.check;
|
||||||
packet.ip.check = 0;
|
packet.ip.check = 0;
|
||||||
if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) {
|
if (check != inet_cksum((uint16_t *)&packet.ip, sizeof(packet.ip))) {
|
||||||
log1("Bad IP header checksum, ignoring");
|
log1("bad IP header checksum, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -943,17 +943,17 @@ static NOINLINE int udhcp_recv_raw_packet(struct dhcp_packet *dhcp_pkt, int fd)
|
||||||
check = packet.udp.check;
|
check = packet.udp.check;
|
||||||
packet.udp.check = 0;
|
packet.udp.check = 0;
|
||||||
if (check && check != inet_cksum((uint16_t *)&packet, bytes)) {
|
if (check && check != inet_cksum((uint16_t *)&packet, bytes)) {
|
||||||
log1("Packet with bad UDP checksum received, ignoring");
|
log1("packet with bad UDP checksum received, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
skip_udp_sum_check:
|
skip_udp_sum_check:
|
||||||
|
|
||||||
if (packet.data.cookie != htonl(DHCP_MAGIC)) {
|
if (packet.data.cookie != htonl(DHCP_MAGIC)) {
|
||||||
bb_info_msg("Packet with bad magic, ignoring");
|
bb_error_msg("packet with bad magic, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
log1("Received a packet");
|
log1("received %s", "a packet");
|
||||||
udhcp_dump_packet(&packet.data);
|
udhcp_dump_packet(&packet.data);
|
||||||
|
|
||||||
bytes -= sizeof(packet.ip) + sizeof(packet.udp);
|
bytes -= sizeof(packet.ip) + sizeof(packet.udp);
|
||||||
|
@ -992,14 +992,14 @@ static int udhcp_raw_socket(int ifindex)
|
||||||
int fd;
|
int fd;
|
||||||
struct sockaddr_ll sock;
|
struct sockaddr_ll sock;
|
||||||
|
|
||||||
log1("Opening raw socket on ifindex %d", ifindex); //log2?
|
log1("opening raw socket on ifindex %d", ifindex); //log2?
|
||||||
|
|
||||||
fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
|
fd = xsocket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
|
||||||
/* ^^^^^
|
/* ^^^^^
|
||||||
* SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them)
|
* SOCK_DGRAM: remove link-layer headers on input (SOCK_RAW keeps them)
|
||||||
* ETH_P_IP: want to receive only packets with IPv4 eth type
|
* ETH_P_IP: want to receive only packets with IPv4 eth type
|
||||||
*/
|
*/
|
||||||
log1("Got raw socket fd"); //log2?
|
log1("got raw socket fd"); //log2?
|
||||||
|
|
||||||
sock.sll_family = AF_PACKET;
|
sock.sll_family = AF_PACKET;
|
||||||
sock.sll_protocol = htons(ETH_P_IP);
|
sock.sll_protocol = htons(ETH_P_IP);
|
||||||
|
@ -1055,23 +1055,23 @@ static int udhcp_raw_socket(int ifindex)
|
||||||
/* Ignoring error (kernel may lack support for this) */
|
/* Ignoring error (kernel may lack support for this) */
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog,
|
if (setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog,
|
||||||
sizeof(filter_prog)) >= 0)
|
sizeof(filter_prog)) >= 0)
|
||||||
log1("Attached filter to raw socket fd"); // log?
|
log1("attached filter to raw socket fd"); // log?
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) {
|
if (setsockopt_1(fd, SOL_PACKET, PACKET_AUXDATA) != 0) {
|
||||||
if (errno != ENOPROTOOPT)
|
if (errno != ENOPROTOOPT)
|
||||||
log1("Can't set PACKET_AUXDATA on raw socket");
|
log1("can't set PACKET_AUXDATA on raw socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
log1("Created raw socket");
|
log1("created raw socket");
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void change_listen_mode(int new_mode)
|
static void change_listen_mode(int new_mode)
|
||||||
{
|
{
|
||||||
log1("Entering listen mode: %s",
|
log1("entering listen mode: %s",
|
||||||
new_mode != LISTEN_NONE
|
new_mode != LISTEN_NONE
|
||||||
? (new_mode == LISTEN_KERNEL ? "kernel" : "raw")
|
? (new_mode == LISTEN_KERNEL ? "kernel" : "raw")
|
||||||
: "none"
|
: "none"
|
||||||
|
@ -1092,7 +1092,7 @@ static void change_listen_mode(int new_mode)
|
||||||
/* Called only on SIGUSR1 */
|
/* Called only on SIGUSR1 */
|
||||||
static void perform_renew(void)
|
static void perform_renew(void)
|
||||||
{
|
{
|
||||||
bb_info_msg("Performing a DHCP renew");
|
bb_error_msg("performing DHCP renew");
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case BOUND:
|
case BOUND:
|
||||||
change_listen_mode(LISTEN_KERNEL);
|
change_listen_mode(LISTEN_KERNEL);
|
||||||
|
@ -1122,12 +1122,12 @@ static void perform_release(uint32_t server_addr, uint32_t requested_ip)
|
||||||
temp_addr.s_addr = server_addr;
|
temp_addr.s_addr = server_addr;
|
||||||
strcpy(buffer, inet_ntoa(temp_addr));
|
strcpy(buffer, inet_ntoa(temp_addr));
|
||||||
temp_addr.s_addr = requested_ip;
|
temp_addr.s_addr = requested_ip;
|
||||||
bb_info_msg("Unicasting a release of %s to %s",
|
bb_error_msg("unicasting a release of %s to %s",
|
||||||
inet_ntoa(temp_addr), buffer);
|
inet_ntoa(temp_addr), buffer);
|
||||||
send_release(server_addr, requested_ip); /* unicast */
|
send_release(server_addr, requested_ip); /* unicast */
|
||||||
udhcp_run_script(NULL, "deconfig");
|
udhcp_run_script(NULL, "deconfig");
|
||||||
}
|
}
|
||||||
bb_info_msg("Entering released state");
|
bb_error_msg("entering released state");
|
||||||
|
|
||||||
change_listen_mode(LISTEN_NONE);
|
change_listen_mode(LISTEN_NONE);
|
||||||
state = RELEASED;
|
state = RELEASED;
|
||||||
|
@ -1395,7 +1395,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
/* Create pidfile */
|
/* Create pidfile */
|
||||||
write_pidfile(client_config.pidfile);
|
write_pidfile(client_config.pidfile);
|
||||||
/* Goes to stdout (unless NOMMU) and possibly syslog */
|
/* Goes to stdout (unless NOMMU) and possibly syslog */
|
||||||
bb_info_msg("%s (v"BB_VER") started", applet_name);
|
bb_error_msg("started, v"BB_VER);
|
||||||
/* Set up the signal pipe */
|
/* Set up the signal pipe */
|
||||||
udhcp_sp_setup();
|
udhcp_sp_setup();
|
||||||
/* We want random_xid to be random... */
|
/* We want random_xid to be random... */
|
||||||
|
@ -1434,7 +1434,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
retval = 0;
|
retval = 0;
|
||||||
/* If we already timed out, fall through with retval = 0, else... */
|
/* If we already timed out, fall through with retval = 0, else... */
|
||||||
if ((int)tv.tv_sec > 0) {
|
if ((int)tv.tv_sec > 0) {
|
||||||
log1("Waiting on select %u seconds", (int)tv.tv_sec);
|
log1("waiting on select %u seconds", (int)tv.tv_sec);
|
||||||
timestamp_before_wait = (unsigned)monotonic_sec();
|
timestamp_before_wait = (unsigned)monotonic_sec();
|
||||||
retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
|
retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
|
||||||
if (retval < 0) {
|
if (retval < 0) {
|
||||||
|
@ -1485,14 +1485,14 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
udhcp_run_script(NULL, "leasefail");
|
udhcp_run_script(NULL, "leasefail");
|
||||||
#if BB_MMU /* -b is not supported on NOMMU */
|
#if BB_MMU /* -b is not supported on NOMMU */
|
||||||
if (opt & OPT_b) { /* background if no lease */
|
if (opt & OPT_b) { /* background if no lease */
|
||||||
bb_info_msg("No lease, forking to background");
|
bb_error_msg("no lease, forking to background");
|
||||||
client_background();
|
client_background();
|
||||||
/* do not background again! */
|
/* do not background again! */
|
||||||
opt = ((opt & ~OPT_b) | OPT_f);
|
opt = ((opt & ~OPT_b) | OPT_f);
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
if (opt & OPT_n) { /* abort if no lease */
|
if (opt & OPT_n) { /* abort if no lease */
|
||||||
bb_info_msg("No lease, failing");
|
bb_error_msg("no lease, failing");
|
||||||
retval = 1;
|
retval = 1;
|
||||||
goto ret;
|
goto ret;
|
||||||
}
|
}
|
||||||
|
@ -1520,7 +1520,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
state = RENEWING;
|
state = RENEWING;
|
||||||
client_config.first_secs = 0; /* make secs field count from 0 */
|
client_config.first_secs = 0; /* make secs field count from 0 */
|
||||||
change_listen_mode(LISTEN_KERNEL);
|
change_listen_mode(LISTEN_KERNEL);
|
||||||
log1("Entering renew state");
|
log1("entering renew state");
|
||||||
/* fall right through */
|
/* fall right through */
|
||||||
case RENEW_REQUESTED: /* manual (SIGUSR1) renew */
|
case RENEW_REQUESTED: /* manual (SIGUSR1) renew */
|
||||||
case_RENEW_REQUESTED:
|
case_RENEW_REQUESTED:
|
||||||
|
@ -1540,7 +1540,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Timed out, enter rebinding state */
|
/* Timed out, enter rebinding state */
|
||||||
log1("Entering rebinding state");
|
log1("entering rebinding state");
|
||||||
state = REBINDING;
|
state = REBINDING;
|
||||||
/* fall right through */
|
/* fall right through */
|
||||||
case REBINDING:
|
case REBINDING:
|
||||||
|
@ -1555,7 +1555,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* Timed out, enter init state */
|
/* Timed out, enter init state */
|
||||||
bb_info_msg("Lease lost, entering init state");
|
bb_error_msg("lease lost, entering init state");
|
||||||
udhcp_run_script(NULL, "deconfig");
|
udhcp_run_script(NULL, "deconfig");
|
||||||
state = INIT_SELECTING;
|
state = INIT_SELECTING;
|
||||||
client_config.first_secs = 0; /* make secs field count from 0 */
|
client_config.first_secs = 0; /* make secs field count from 0 */
|
||||||
|
@ -1603,7 +1603,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
timeout = INT_MAX;
|
timeout = INT_MAX;
|
||||||
continue;
|
continue;
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
bb_info_msg("Received SIGTERM");
|
bb_error_msg("received %s", "SIGTERM");
|
||||||
goto ret0;
|
goto ret0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1621,7 +1621,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
len = udhcp_recv_raw_packet(&packet, sockfd);
|
len = udhcp_recv_raw_packet(&packet, sockfd);
|
||||||
if (len == -1) {
|
if (len == -1) {
|
||||||
/* Error is severe, reopen socket */
|
/* Error is severe, reopen socket */
|
||||||
bb_info_msg("Read error: %s, reopening socket", strerror(errno));
|
bb_error_msg("read error: %s, reopening socket", strerror(errno));
|
||||||
sleep(discover_timeout); /* 3 seconds by default */
|
sleep(discover_timeout); /* 3 seconds by default */
|
||||||
change_listen_mode(listen_mode); /* just close and reopen */
|
change_listen_mode(listen_mode); /* just close and reopen */
|
||||||
}
|
}
|
||||||
|
@ -1744,7 +1744,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
client_config.interface,
|
client_config.interface,
|
||||||
arpping_ms)
|
arpping_ms)
|
||||||
) {
|
) {
|
||||||
bb_info_msg("Offered address is in use "
|
bb_error_msg("offered address is in use "
|
||||||
"(got ARP reply), declining");
|
"(got ARP reply), declining");
|
||||||
send_decline(/*xid,*/ server_addr, packet.yiaddr);
|
send_decline(/*xid,*/ server_addr, packet.yiaddr);
|
||||||
|
|
||||||
|
@ -1763,7 +1763,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
#endif
|
#endif
|
||||||
/* enter bound state */
|
/* enter bound state */
|
||||||
temp_addr.s_addr = packet.yiaddr;
|
temp_addr.s_addr = packet.yiaddr;
|
||||||
bb_info_msg("Lease of %s obtained, lease time %u",
|
bb_error_msg("lease of %s obtained, lease time %u",
|
||||||
inet_ntoa(temp_addr), (unsigned)lease_seconds);
|
inet_ntoa(temp_addr), (unsigned)lease_seconds);
|
||||||
requested_ip = packet.yiaddr;
|
requested_ip = packet.yiaddr;
|
||||||
|
|
||||||
|
@ -1817,7 +1817,7 @@ int udhcpc_main(int argc UNUSED_PARAM, char **argv)
|
||||||
goto non_matching_svid;
|
goto non_matching_svid;
|
||||||
}
|
}
|
||||||
/* return to init state */
|
/* return to init state */
|
||||||
bb_info_msg("Received DHCP NAK");
|
bb_error_msg("received %s", "DHCP NAK");
|
||||||
udhcp_run_script(&packet, "nak");
|
udhcp_run_script(&packet, "nak");
|
||||||
if (state != REQUESTING)
|
if (state != REQUESTING)
|
||||||
udhcp_run_script(NULL, "deconfig");
|
udhcp_run_script(NULL, "deconfig");
|
||||||
|
|
|
@ -61,11 +61,11 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc
|
||||||
|| (dhcp_pkt->flags & htons(BROADCAST_FLAG))
|
|| (dhcp_pkt->flags & htons(BROADCAST_FLAG))
|
||||||
|| dhcp_pkt->ciaddr == 0
|
|| dhcp_pkt->ciaddr == 0
|
||||||
) {
|
) {
|
||||||
log1("Broadcasting packet to client");
|
log1("broadcasting packet to client");
|
||||||
ciaddr = INADDR_BROADCAST;
|
ciaddr = INADDR_BROADCAST;
|
||||||
chaddr = MAC_BCAST_ADDR;
|
chaddr = MAC_BCAST_ADDR;
|
||||||
} else {
|
} else {
|
||||||
log1("Unicasting packet to client ciaddr");
|
log1("unicasting packet to client ciaddr");
|
||||||
ciaddr = dhcp_pkt->ciaddr;
|
ciaddr = dhcp_pkt->ciaddr;
|
||||||
chaddr = dhcp_pkt->chaddr;
|
chaddr = dhcp_pkt->chaddr;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ static void send_packet_to_client(struct dhcp_packet *dhcp_pkt, int force_broadc
|
||||||
/* Send a packet to gateway_nip using the kernel ip stack */
|
/* Send a packet to gateway_nip using the kernel ip stack */
|
||||||
static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt)
|
static void send_packet_to_relay(struct dhcp_packet *dhcp_pkt)
|
||||||
{
|
{
|
||||||
log1("Forwarding packet to relay");
|
log1("forwarding packet to relay");
|
||||||
|
|
||||||
udhcp_send_kernel_packet(dhcp_pkt,
|
udhcp_send_kernel_packet(dhcp_pkt,
|
||||||
server_config.server_nip, SERVER_PORT,
|
server_config.server_nip, SERVER_PORT,
|
||||||
|
@ -214,7 +214,7 @@ static NOINLINE void send_offer(struct dhcp_packet *oldpacket,
|
||||||
add_server_options(&packet);
|
add_server_options(&packet);
|
||||||
|
|
||||||
addr.s_addr = packet.yiaddr;
|
addr.s_addr = packet.yiaddr;
|
||||||
bb_info_msg("Sending OFFER of %s", inet_ntoa(addr));
|
bb_error_msg("sending OFFER of %s", inet_ntoa(addr));
|
||||||
/* send_packet emits error message itself if it detects failure */
|
/* send_packet emits error message itself if it detects failure */
|
||||||
send_packet(&packet, /*force_bcast:*/ 0);
|
send_packet(&packet, /*force_bcast:*/ 0);
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ static NOINLINE void send_NAK(struct dhcp_packet *oldpacket)
|
||||||
|
|
||||||
init_packet(&packet, oldpacket, DHCPNAK);
|
init_packet(&packet, oldpacket, DHCPNAK);
|
||||||
|
|
||||||
log1("Sending NAK");
|
log1("sending NAK");
|
||||||
send_packet(&packet, /*force_bcast:*/ 1);
|
send_packet(&packet, /*force_bcast:*/ 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ static NOINLINE void send_ACK(struct dhcp_packet *oldpacket, uint32_t yiaddr)
|
||||||
add_server_options(&packet);
|
add_server_options(&packet);
|
||||||
|
|
||||||
addr.s_addr = yiaddr;
|
addr.s_addr = yiaddr;
|
||||||
bb_info_msg("Sending ACK to %s", inet_ntoa(addr));
|
bb_error_msg("sending ACK to %s", inet_ntoa(addr));
|
||||||
send_packet(&packet, /*force_bcast:*/ 0);
|
send_packet(&packet, /*force_bcast:*/ 0);
|
||||||
|
|
||||||
p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME);
|
p_host_name = (const char*) udhcp_get_option(oldpacket, DHCP_HOST_NAME);
|
||||||
|
@ -361,7 +361,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||||
write_pidfile(server_config.pidfile);
|
write_pidfile(server_config.pidfile);
|
||||||
/* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */
|
/* if (!..) bb_perror_msg("can't create pidfile %s", pidfile); */
|
||||||
|
|
||||||
bb_info_msg("%s (v"BB_VER") started", applet_name);
|
bb_error_msg("started, v"BB_VER);
|
||||||
|
|
||||||
option = udhcp_find_option(server_config.options, DHCP_LEASE_TIME);
|
option = udhcp_find_option(server_config.options, DHCP_LEASE_TIME);
|
||||||
server_config.max_lease_sec = DEFAULT_LEASE_TIME;
|
server_config.max_lease_sec = DEFAULT_LEASE_TIME;
|
||||||
|
@ -427,18 +427,18 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||||
goto continue_with_autotime;
|
goto continue_with_autotime;
|
||||||
}
|
}
|
||||||
if (retval < 0 && errno != EINTR) {
|
if (retval < 0 && errno != EINTR) {
|
||||||
log1("Error on select");
|
log1("error on select");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (udhcp_sp_read(&rfds)) {
|
switch (udhcp_sp_read(&rfds)) {
|
||||||
case SIGUSR1:
|
case SIGUSR1:
|
||||||
bb_info_msg("Received SIGUSR1");
|
bb_error_msg("received %s", "SIGUSR1");
|
||||||
write_leases();
|
write_leases();
|
||||||
/* why not just reset the timeout, eh */
|
/* why not just reset the timeout, eh */
|
||||||
goto continue_with_autotime;
|
goto continue_with_autotime;
|
||||||
case SIGTERM:
|
case SIGTERM:
|
||||||
bb_info_msg("Received SIGTERM");
|
bb_error_msg("received %s", "SIGTERM");
|
||||||
write_leases();
|
write_leases();
|
||||||
goto ret0;
|
goto ret0;
|
||||||
case 0: /* no signal: read a packet */
|
case 0: /* no signal: read a packet */
|
||||||
|
@ -451,7 +451,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
/* bytes can also be -2 ("bad packet data") */
|
/* bytes can also be -2 ("bad packet data") */
|
||||||
if (bytes == -1 && errno != EINTR) {
|
if (bytes == -1 && errno != EINTR) {
|
||||||
log1("Read error: %s, reopening socket", strerror(errno));
|
log1("read error: %s, reopening socket", strerror(errno));
|
||||||
close(server_socket);
|
close(server_socket);
|
||||||
server_socket = -1;
|
server_socket = -1;
|
||||||
}
|
}
|
||||||
|
@ -486,7 +486,7 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||||
/* Look for a static/dynamic lease */
|
/* Look for a static/dynamic lease */
|
||||||
static_lease_nip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr);
|
static_lease_nip = get_static_nip_by_mac(server_config.static_leases, &packet.chaddr);
|
||||||
if (static_lease_nip) {
|
if (static_lease_nip) {
|
||||||
bb_info_msg("Found static lease: %x", static_lease_nip);
|
bb_error_msg("found static lease: %x", static_lease_nip);
|
||||||
memcpy(&fake_lease.lease_mac, &packet.chaddr, 6);
|
memcpy(&fake_lease.lease_mac, &packet.chaddr, 6);
|
||||||
fake_lease.lease_nip = static_lease_nip;
|
fake_lease.lease_nip = static_lease_nip;
|
||||||
fake_lease.expires = 0;
|
fake_lease.expires = 0;
|
||||||
|
@ -504,13 +504,13 @@ int udhcpd_main(int argc UNUSED_PARAM, char **argv)
|
||||||
switch (state[0]) {
|
switch (state[0]) {
|
||||||
|
|
||||||
case DHCPDISCOVER:
|
case DHCPDISCOVER:
|
||||||
log1("Received DISCOVER");
|
log1("received %s", "DISCOVER");
|
||||||
|
|
||||||
send_offer(&packet, static_lease_nip, lease, requested_ip_opt, arpping_ms);
|
send_offer(&packet, static_lease_nip, lease, requested_ip_opt, arpping_ms);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DHCPREQUEST:
|
case DHCPREQUEST:
|
||||||
log1("Received REQUEST");
|
log1("received %s", "REQUEST");
|
||||||
/* RFC 2131:
|
/* RFC 2131:
|
||||||
|
|
||||||
o DHCPREQUEST generated during SELECTING state:
|
o DHCPREQUEST generated during SELECTING state:
|
||||||
|
@ -635,7 +635,7 @@ o DHCPREQUEST generated during REBINDING state:
|
||||||
* chaddr must be filled in,
|
* chaddr must be filled in,
|
||||||
* ciaddr must be 0 (we do not check this)
|
* ciaddr must be 0 (we do not check this)
|
||||||
*/
|
*/
|
||||||
log1("Received DECLINE");
|
log1("received %s", "DECLINE");
|
||||||
if (server_id_opt
|
if (server_id_opt
|
||||||
&& requested_ip_opt
|
&& requested_ip_opt
|
||||||
&& lease /* chaddr matches this lease */
|
&& lease /* chaddr matches this lease */
|
||||||
|
@ -655,7 +655,7 @@ o DHCPREQUEST generated during REBINDING state:
|
||||||
* chaddr must be filled in,
|
* chaddr must be filled in,
|
||||||
* ciaddr must be filled in
|
* ciaddr must be filled in
|
||||||
*/
|
*/
|
||||||
log1("Received RELEASE");
|
log1("received %s", "RELEASE");
|
||||||
if (server_id_opt
|
if (server_id_opt
|
||||||
&& lease /* chaddr matches this lease */
|
&& lease /* chaddr matches this lease */
|
||||||
&& packet.ciaddr == lease->lease_nip
|
&& packet.ciaddr == lease->lease_nip
|
||||||
|
@ -665,7 +665,7 @@ o DHCPREQUEST generated during REBINDING state:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DHCPINFORM:
|
case DHCPINFORM:
|
||||||
log1("Received INFORM");
|
log1("received %s", "INFORM");
|
||||||
send_inform(&packet);
|
send_inform(&packet);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,7 +226,7 @@ void FAST_FUNC read_leases(const char *file)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log1("Read %d leases", i);
|
log1("read %d leases", i);
|
||||||
ret:
|
ret:
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ static int nobody_responds_to_arp(uint32_t nip, const uint8_t *safe_mac, unsigne
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
temp.s_addr = nip;
|
temp.s_addr = nip;
|
||||||
bb_info_msg("%s belongs to someone, reserving it for %u seconds",
|
bb_error_msg("%s belongs to someone, reserving it for %u seconds",
|
||||||
inet_ntoa(temp), (unsigned)server_config.conflict_time);
|
inet_ntoa(temp), (unsigned)server_config.conflict_time);
|
||||||
add_lease(NULL, nip, server_config.conflict_time, NULL, 0);
|
add_lease(NULL, nip, server_config.conflict_time, NULL, 0);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -38,8 +38,8 @@ void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet)
|
||||||
if (dhcp_verbose < 2)
|
if (dhcp_verbose < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bb_info_msg(
|
bb_error_msg(
|
||||||
//" op %x"
|
//"op %x"
|
||||||
//" htype %x"
|
//" htype %x"
|
||||||
" hlen %x"
|
" hlen %x"
|
||||||
//" hops %x"
|
//" hops %x"
|
||||||
|
@ -73,7 +73,7 @@ void FAST_FUNC udhcp_dump_packet(struct dhcp_packet *packet)
|
||||||
//, packet->options[]
|
//, packet->options[]
|
||||||
);
|
);
|
||||||
*bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0';
|
*bin2hex(buf, (void *) packet->chaddr, sizeof(packet->chaddr)) = '\0';
|
||||||
bb_info_msg(" chaddr %s", buf);
|
bb_error_msg("chaddr %s", buf);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -85,17 +85,17 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd)
|
||||||
memset(packet, 0, sizeof(*packet));
|
memset(packet, 0, sizeof(*packet));
|
||||||
bytes = safe_read(fd, packet, sizeof(*packet));
|
bytes = safe_read(fd, packet, sizeof(*packet));
|
||||||
if (bytes < 0) {
|
if (bytes < 0) {
|
||||||
log1("Packet read error, ignoring");
|
log1("packet read error, ignoring");
|
||||||
return bytes; /* returns -1 */
|
return bytes; /* returns -1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bytes < offsetof(struct dhcp_packet, options)
|
if (bytes < offsetof(struct dhcp_packet, options)
|
||||||
|| packet->cookie != htonl(DHCP_MAGIC)
|
|| packet->cookie != htonl(DHCP_MAGIC)
|
||||||
) {
|
) {
|
||||||
bb_info_msg("Packet with bad magic, ignoring");
|
bb_error_msg("packet with bad magic, ignoring");
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
log1("Received a packet");
|
log1("received %s", "a packet");
|
||||||
udhcp_dump_packet(packet);
|
udhcp_dump_packet(packet);
|
||||||
|
|
||||||
return bytes;
|
return bytes;
|
||||||
|
|
|
@ -56,7 +56,7 @@ int FAST_FUNC udhcp_read_interface(const char *interface, int *ifindex, uint32_t
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
log1("Adapter index %d", ifr->ifr_ifindex);
|
log1("adapter index %d", ifr->ifr_ifindex);
|
||||||
*ifindex = ifr->ifr_ifindex;
|
*ifindex = ifr->ifr_ifindex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ int FAST_FUNC udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf)
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
char *colon;
|
char *colon;
|
||||||
|
|
||||||
log1("Opening listen socket on *:%d %s", port, inf);
|
log1("opening listen socket on *:%d %s", port, inf);
|
||||||
fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
fd = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
|
||||||
setsockopt_reuseaddr(fd);
|
setsockopt_reuseaddr(fd);
|
||||||
|
|
|
@ -66,7 +66,7 @@ void FAST_FUNC log_static_leases(struct static_lease **st_lease_pp)
|
||||||
|
|
||||||
cur = *st_lease_pp;
|
cur = *st_lease_pp;
|
||||||
while (cur) {
|
while (cur) {
|
||||||
bb_info_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x",
|
bb_error_msg("static lease: mac:%02x:%02x:%02x:%02x:%02x:%02x nip:%x",
|
||||||
cur->mac[0], cur->mac[1], cur->mac[2],
|
cur->mac[0], cur->mac[1], cur->mac[2],
|
||||||
cur->mac[3], cur->mac[4], cur->mac[5],
|
cur->mac[3], cur->mac[4], cur->mac[5],
|
||||||
cur->nip
|
cur->nip
|
||||||
|
|
Loading…
Reference in New Issue