#include <netpacket/packet.h>
#include <linux/filter.h>
-/* "struct client_config_t client_config" is in bb_common_bufsiz1 */
+/* "struct client_data_t client_data" is in bb_common_bufsiz1 */
static const struct dhcp_optflag d6_optflags[] = {
#if ENABLE_FEATURE_UDHCPC6_RFC3646
client6_data.env_ptr = NULL;
client6_data.env_idx = 0;
- *new_env() = xasprintf("interface=%s", client_config.interface);
+ *new_env() = xasprintf("interface=%s", client_data.interface);
if (option)
option_to_env(option, option_end);
envp = fill_envp(option, option_end);
/* call script */
- log1("executing %s %s", client_config.script, name);
- argv[0] = (char*) client_config.script;
+ log1("executing %s %s", client_data.script, name);
+ argv[0] = (char*) client_data.script;
argv[1] = (char*) name;
argv[2] = NULL;
spawn_and_wait(argv);
packet->d6_xid32 = xid;
packet->d6_msg_type = type;
- clientid = (void*)client_config.clientid;
+ clientid = (void*)client_data.clientid;
return mempcpy(packet->d6_options, clientid, clientid->len + 2+2);
}
ptr += 4;
for (option = 1; option < 256; option++) {
- if (client_config.opt_mask[option >> 3] & (1 << (option & 7))) {
+ if (client_data.opt_mask[option >> 3] & (1 << (option & 7))) {
ptr[0] = (option >> 8);
ptr[1] = option;
ptr += 2;
ptr = mempcpy(ptr, &opt_fqdn_req, sizeof(opt_fqdn_req));
#endif
/* Add -x options if any */
- curr = client_config.options;
+ curr = client_data.options;
while (curr) {
len = (curr->data[D6_OPT_LEN] << 8) | curr->data[D6_OPT_LEN + 1];
ptr = mempcpy(ptr, curr->data, D6_OPT_DATA + len);
return ptr;
}
-static int d6_mcast_from_client_config_ifindex(struct d6_packet *packet, uint8_t *end)
+static int d6_mcast_from_client_data_ifindex(struct d6_packet *packet, uint8_t *end)
{
/* FF02::1:2 is "All_DHCP_Relay_Agents_and_Servers" address */
static const uint8_t FF02__1_2[16] = {
packet, (end - (uint8_t*) packet),
/*src*/ &client6_data.ll_ip6, CLIENT_PORT6,
/*dst*/ (struct in6_addr*)FF02__1_2, SERVER_PORT6, MAC_BCAST_ADDR,
- client_config.ifindex
+ client_data.ifindex
);
}
opt_ptr = add_d6_client_options(opt_ptr);
bb_info_msg("sending %s", "discover");
- return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
+ return d6_mcast_from_client_data_ifindex(&packet, opt_ptr);
}
/* Multicast a DHCPv6 request message
opt_ptr = add_d6_client_options(opt_ptr);
bb_info_msg("sending %s", "select");
- return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
+ return d6_mcast_from_client_data_ifindex(&packet, opt_ptr);
}
/* Unicast or broadcast a DHCP renew message
&packet, (opt_ptr - (uint8_t*) &packet),
our_cur_ipv6, CLIENT_PORT6,
server_ipv6, SERVER_PORT6,
- client_config.ifindex
+ client_data.ifindex
);
- return d6_mcast_from_client_config_ifindex(&packet, opt_ptr);
+ return d6_mcast_from_client_data_ifindex(&packet, opt_ptr);
}
/* Unicast a DHCP release message */
&packet, (opt_ptr - (uint8_t*) &packet),
our_cur_ipv6, CLIENT_PORT6,
server_ipv6, SERVER_PORT6,
- client_config.ifindex
+ client_data.ifindex
);
}
/*** Main ***/
-/* Values for client_config.listen_mode */
+/* Values for client_data.listen_mode */
#define LISTEN_NONE 0
#define LISTEN_KERNEL 1
#define LISTEN_RAW 2
-/* Values for client_config.state */
+/* Values for client_data.state */
/* initial state: (re)start DHCP negotiation */
#define INIT_SELECTING 0
/* discover was sent, DHCPOFFER reply received */
: "none"
);
- client_config.listen_mode = new_mode;
- if (client_config.sockfd >= 0) {
- close(client_config.sockfd);
- client_config.sockfd = -1;
+ client_data.listen_mode = new_mode;
+ if (client_data.sockfd >= 0) {
+ close(client_data.sockfd);
+ client_data.sockfd = -1;
}
if (new_mode == LISTEN_KERNEL)
- client_config.sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT6, client_config.interface);
+ client_data.sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT6, client_data.interface);
else if (new_mode != LISTEN_NONE)
- client_config.sockfd = d6_raw_socket(client_config.ifindex);
- /* else LISTEN_NONE: client_config.sockfd stays closed */
+ client_data.sockfd = d6_raw_socket(client_data.ifindex);
+ /* else LISTEN_NONE: client_data.sockfd stays closed */
}
/* Called only on SIGUSR1 */
static void perform_renew(void)
{
bb_info_msg("performing DHCP renew");
- switch (client_config.state) {
+ switch (client_data.state) {
case BOUND:
change_listen_mode(LISTEN_KERNEL);
case RENEWING:
case REBINDING:
- client_config.state = RENEW_REQUESTED;
+ client_data.state = RENEW_REQUESTED;
break;
case RENEW_REQUESTED: /* impatient are we? fine, square 1 */
d6_run_script_no_option("deconfig");
case REQUESTING:
case RELEASED:
change_listen_mode(LISTEN_RAW);
- client_config.state = INIT_SELECTING;
+ client_data.state = INIT_SELECTING;
break;
case INIT_SELECTING:
break;
static void perform_d6_release(struct in6_addr *server_ipv6, struct in6_addr *our_cur_ipv6)
{
/* send release packet */
- if (client_config.state == BOUND
- || client_config.state == RENEWING
- || client_config.state == REBINDING
- || client_config.state == RENEW_REQUESTED
+ if (client_data.state == BOUND
+ || client_data.state == RENEWING
+ || client_data.state == REBINDING
+ || client_data.state == RENEW_REQUESTED
) {
bb_info_msg("unicasting a release");
send_d6_release(server_ipv6, our_cur_ipv6); /* unicast */
*/
d6_run_script_no_option("deconfig");
change_listen_mode(LISTEN_NONE);
- client_config.state = RELEASED;
+ client_data.state = RELEASED;
}
///static uint8_t* alloc_dhcp_option(int code, const char *str, int extra)
bb_daemonize(0);
logmode &= ~LOGMODE_STDIO;
/* rewrite pidfile, as our pid is different now */
- write_pidfile(client_config.pidfile);
+ write_pidfile(client_data.pidfile);
}
#endif
/* Default options */
IF_FEATURE_UDHCP_PORT(SERVER_PORT6 = 547;)
IF_FEATURE_UDHCP_PORT(CLIENT_PORT6 = 546;)
- client_config.interface = "eth0";
- client_config.script = CONFIG_UDHCPC_DEFAULT_SCRIPT;
- client_config.sockfd = -1;
+ client_data.interface = "eth0";
+ client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT;
+ client_data.sockfd = -1;
/* Parse command line */
opt = getopt32long(argv, "^"
"v"
"\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */
, udhcpc6_longopts
- , &client_config.interface, &client_config.pidfile, &str_r /* i,p */
- , &client_config.script /* s */
+ , &client_data.interface, &client_data.pidfile, &str_r /* i,p */
+ , &client_data.script /* s */
, &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */
, &list_O
, &list_x
n = udhcp_option_idx(optstr, d6_option_strings);
n = d6_optflags[n].code;
}
- client_config.opt_mask[n >> 3] |= 1 << (n & 7);
+ client_data.opt_mask[n >> 3] |= 1 << (n & 7);
}
if (!(opt & OPT_o)) {
unsigned i, n;
for (i = 0; (n = d6_optflags[i].code) != 0; i++) {
if (d6_optflags[i].flags & OPTION_REQ) {
- client_config.opt_mask[n >> 3] |= 1 << (n & 7);
+ client_data.opt_mask[n >> 3] |= 1 << (n & 7);
}
}
}
while (list_x) {
char *optstr = xstrdup(llist_pop(&list_x));
- udhcp_str2optset(optstr, &client_config.options,
+ udhcp_str2optset(optstr, &client_data.options,
d6_optflags, d6_option_strings,
/*dhcpv6:*/ 1
);
free(optstr);
}
- if (d6_read_interface(client_config.interface,
- &client_config.ifindex,
+ if (d6_read_interface(client_data.interface,
+ &client_data.ifindex,
&client6_data.ll_ip6,
- client_config.client_mac)
+ client_data.client_mac)
) {
return 1;
}
clientid->data[1] = 3; /* DUID-LL */
clientid->data[3] = 1; /* ethernet */
clientid_mac_ptr = clientid->data + 2+2;
- memcpy(clientid_mac_ptr, client_config.client_mac, 6);
- client_config.clientid = (void*)clientid;
+ memcpy(clientid_mac_ptr, client_data.client_mac, 6);
+ client_data.clientid = (void*)clientid;
}
#if !BB_MMU
/* Make sure fd 0,1,2 are open */
bb_sanitize_stdio();
/* Create pidfile */
- write_pidfile(client_config.pidfile);
+ write_pidfile(client_data.pidfile);
/* Goes to stdout (unless NOMMU) and possibly syslog */
bb_info_msg("started, v"BB_VER);
/* Set up the signal pipe */
udhcp_sp_setup();
- client_config.state = INIT_SELECTING;
+ client_data.state = INIT_SELECTING;
d6_run_script_no_option("deconfig");
change_listen_mode(LISTEN_RAW);
packet_num = 0;
/* silence "uninitialized!" warning */
unsigned timestamp_before_wait = timestamp_before_wait;
- //bb_error_msg("sockfd:%d, listen_mode:%d", client_config.sockfd, client_config.listen_mode);
+ //bb_error_msg("sockfd:%d, listen_mode:%d", client_data.sockfd, client_data.listen_mode);
/* Was opening raw or udp socket here
- * if (client_config.listen_mode != LISTEN_NONE && client_config.sockfd < 0),
+ * if (client_data.listen_mode != LISTEN_NONE && client_data.sockfd < 0),
* but on fast network renew responses return faster
* than we open sockets. Thus this code is moved
* to change_listen_mode(). Thus we open listen socket
* BEFORE we send renew request (see "case BOUND:"). */
- udhcp_sp_fd_set(pfds, client_config.sockfd);
+ udhcp_sp_fd_set(pfds, client_data.sockfd);
tv = timeout - already_waited_sec;
retval = 0;
* or if the status of the bridge changed).
* Refresh ifindex and client_mac:
*/
- if (d6_read_interface(client_config.interface,
- &client_config.ifindex,
+ if (d6_read_interface(client_data.interface,
+ &client_data.ifindex,
&client6_data.ll_ip6,
- client_config.client_mac)
+ client_data.client_mac)
) {
goto ret0; /* iface is gone? */
}
- memcpy(clientid_mac_ptr, client_config.client_mac, 6);
+ memcpy(clientid_mac_ptr, client_data.client_mac, 6);
/* We will restart the wait in any case */
already_waited_sec = 0;
- switch (client_config.state) {
+ switch (client_data.state) {
case INIT_SELECTING:
if (!discover_retries || packet_num < discover_retries) {
if (packet_num == 0)
* were seen in the wild. Treat them similarly
* to "no response to discover" case */
change_listen_mode(LISTEN_RAW);
- client_config.state = INIT_SELECTING;
+ client_data.state = INIT_SELECTING;
goto leasefail;
case BOUND:
/* 1/2 lease passed, enter renewing state */
- client_config.state = RENEWING;
- client_config.first_secs = 0; /* make secs field count from 0 */
+ client_data.state = RENEWING;
+ client_data.first_secs = 0; /* make secs field count from 0 */
change_listen_mode(LISTEN_KERNEL);
log1("entering renew state");
/* fall right through */
}
/* Timed out, enter rebinding state */
log1("entering rebinding state");
- client_config.state = REBINDING;
+ client_data.state = REBINDING;
/* fall right through */
case REBINDING:
/* Switch to bcast receive */
/* Timed out, enter init state */
bb_info_msg("lease lost, entering init state");
d6_run_script_no_option("deconfig");
- client_config.state = INIT_SELECTING;
- client_config.first_secs = 0; /* make secs field count from 0 */
+ client_data.state = INIT_SELECTING;
+ client_data.first_secs = 0; /* make secs field count from 0 */
/*timeout = 0; - already is */
packet_num = 0;
continue;
/* Is it a signal? */
switch (udhcp_sp_read()) {
case SIGUSR1:
- client_config.first_secs = 0; /* make secs field count from 0 */
+ client_data.first_secs = 0; /* make secs field count from 0 */
already_waited_sec = 0;
perform_renew();
- if (client_config.state == RENEW_REQUESTED) {
+ if (client_data.state == RENEW_REQUESTED) {
/* We might be either on the same network
* (in which case renew might work),
* or we might be on a completely different one
int len;
/* A packet is ready, read it */
- if (client_config.listen_mode == LISTEN_KERNEL)
- len = d6_recv_kernel_packet(&srv6_buf, &packet, client_config.sockfd);
+ if (client_data.listen_mode == LISTEN_KERNEL)
+ len = d6_recv_kernel_packet(&srv6_buf, &packet, client_data.sockfd);
else
- len = d6_recv_raw_packet(&srv6_buf, &packet, client_config.sockfd);
+ len = d6_recv_raw_packet(&srv6_buf, &packet, client_data.sockfd);
if (len == -1) {
/* Error is severe, reopen socket */
bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO);
sleep(discover_timeout); /* 3 seconds by default */
- change_listen_mode(client_config.listen_mode); /* just close and reopen */
+ change_listen_mode(client_data.listen_mode); /* just close and reopen */
}
/* If this packet will turn out to be unrelated/bogus,
* we will go back and wait for next one.
continue;
}
- switch (client_config.state) {
+ switch (client_data.state) {
case INIT_SELECTING:
if (packet.d6_msg_type == D6_MSG_ADVERTISE)
goto type_is_ok;
bb_info_msg("received DHCP NAK (%u)", option->data[4]);
d6_run_script(packet.d6_options,
packet_end, "nak");
- if (client_config.state != REQUESTING)
+ if (client_data.state != REQUESTING)
d6_run_script_no_option("deconfig");
change_listen_mode(LISTEN_RAW);
sleep(3); /* avoid excessive network traffic */
- client_config.state = INIT_SELECTING;
- client_config.first_secs = 0; /* make secs field count from 0 */
+ client_data.state = INIT_SELECTING;
+ client_data.first_secs = 0; /* make secs field count from 0 */
requested_ipv6 = NULL;
timeout = 0;
packet_num = 0;
client6_data.server_id = option;
if (packet.d6_msg_type == D6_MSG_ADVERTISE) {
/* enter requesting state */
- client_config.state = REQUESTING;
+ client_data.state = REQUESTING;
timeout = 0;
packet_num = 0;
already_waited_sec = 0;
timeout = 61;
/* enter bound state */
d6_run_script(packet.d6_options, packet_end,
- (client_config.state == REQUESTING ? "bound" : "renew"));
+ (client_data.state == REQUESTING ? "bound" : "renew"));
- client_config.state = BOUND;
+ client_data.state = BOUND;
change_listen_mode(LISTEN_NONE);
if (opt & OPT_q) { /* quit after lease */
goto ret0;
perform_d6_release(&srv6_buf, requested_ipv6);
retval = 0;
ret:
- /*if (client_config.pidfile) - remove_pidfile has its own check */
- remove_pidfile(client_config.pidfile);
+ /*if (client_data.pidfile) - remove_pidfile has its own check */
+ remove_pidfile(client_data.pidfile);
return retval;
}
#endif
-/* "struct client_config_t client_config" is in bb_common_bufsiz1 */
+/* "struct client_data_t client_data" is in bb_common_bufsiz1 */
#if ENABLE_LONG_OPTS
}
curr = envp = xzalloc(sizeof(envp[0]) * envc);
- *curr = xasprintf("interface=%s", client_config.interface);
+ *curr = xasprintf("interface=%s", client_data.interface);
putenv(*curr++);
if (!packet)
envp = fill_envp(packet);
/* call script */
- log1("executing %s %s", client_config.script, name);
- argv[0] = (char*) client_config.script;
+ log1("executing %s %s", client_data.script, name);
+ argv[0] = (char*) client_data.script;
argv[1] = (char*) name;
argv[2] = NULL;
spawn_and_wait(argv);
packet->xid = random_xid();
- client_config.last_secs = monotonic_sec();
- if (client_config.first_secs == 0)
- client_config.first_secs = client_config.last_secs;
- secs = client_config.last_secs - client_config.first_secs;
+ client_data.last_secs = monotonic_sec();
+ if (client_data.first_secs == 0)
+ client_data.first_secs = client_data.last_secs;
+ secs = client_data.last_secs - client_data.first_secs;
packet->secs = htons(secs);
- memcpy(packet->chaddr, client_config.client_mac, 6);
- if (client_config.clientid)
- udhcp_add_binary_option(packet, client_config.clientid);
+ memcpy(packet->chaddr, client_data.client_mac, 6);
+ if (client_data.clientid)
+ udhcp_add_binary_option(packet, client_data.clientid);
}
static void add_client_options(struct dhcp_packet *packet)
end = udhcp_end_option(packet->options);
len = 0;
for (i = 1; i < DHCP_END; i++) {
- if (client_config.opt_mask[i >> 3] & (1 << (i & 7))) {
+ if (client_data.opt_mask[i >> 3] & (1 << (i & 7))) {
packet->options[end + OPT_DATA + len] = i;
len++;
}
packet->options[end + OPT_DATA + len] = DHCP_END;
}
- if (client_config.vendorclass)
- udhcp_add_binary_option(packet, client_config.vendorclass);
- if (client_config.hostname)
- udhcp_add_binary_option(packet, client_config.hostname);
- if (client_config.fqdn)
- udhcp_add_binary_option(packet, client_config.fqdn);
+ if (client_data.vendorclass)
+ udhcp_add_binary_option(packet, client_data.vendorclass);
+ if (client_data.hostname)
+ udhcp_add_binary_option(packet, client_data.hostname);
+ if (client_data.fqdn)
+ udhcp_add_binary_option(packet, client_data.fqdn);
/* Request broadcast replies if we have no IP addr */
if ((option_mask32 & OPT_B) && packet->ciaddr == 0)
/* Add -x options if any */
{
- struct option_set *curr = client_config.options;
+ struct option_set *curr = client_data.options;
while (curr) {
udhcp_add_binary_option(packet, curr->data);
curr = curr->next;
}
-// if (client_config.sname)
-// strncpy((char*)packet->sname, client_config.sname, sizeof(packet->sname) - 1);
-// if (client_config.boot_file)
-// strncpy((char*)packet->file, client_config.boot_file, sizeof(packet->file) - 1);
+// if (client_data.sname)
+// strncpy((char*)packet->sname, client_data.sname, sizeof(packet->sname) - 1);
+// if (client_data.boot_file)
+// strncpy((char*)packet->file, client_data.boot_file, sizeof(packet->file) - 1);
}
// This will be needed if we remove -V VENDOR_STR in favor of
* client reverts to using the IP broadcast address.
*/
-static int raw_bcast_from_client_config_ifindex(struct dhcp_packet *packet, uint32_t src_nip)
+static int raw_bcast_from_client_data_ifindex(struct dhcp_packet *packet, uint32_t src_nip)
{
return udhcp_send_raw_packet(packet,
/*src*/ src_nip, CLIENT_PORT,
/*dst*/ INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR,
- client_config.ifindex);
+ client_data.ifindex);
}
static int bcast_or_ucast(struct dhcp_packet *packet, uint32_t ciaddr, uint32_t server)
return udhcp_send_kernel_packet(packet,
ciaddr, CLIENT_PORT,
server, SERVER_PORT);
- return raw_bcast_from_client_config_ifindex(packet, ciaddr);
+ return raw_bcast_from_client_data_ifindex(packet, ciaddr);
}
/* Broadcast a DHCP discover packet to the network, with an optionally requested IP */
add_client_options(&packet);
bb_info_msg("sending %s", "discover");
- return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
+ return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY);
}
/* Broadcast a DHCP request message */
temp_addr.s_addr = requested;
bb_info_msg("sending select for %s", inet_ntoa(temp_addr));
- return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
+ return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY);
}
/* Unicast or broadcast a DHCP renew message */
udhcp_add_simple_option(&packet, DHCP_SERVER_ID, server);
bb_info_msg("sending %s", "decline");
- return raw_bcast_from_client_config_ifindex(&packet, INADDR_ANY);
+ return raw_bcast_from_client_data_ifindex(&packet, INADDR_ANY);
}
#endif
/*** Main ***/
-/* Values for client_config.listen_mode */
+/* Values for client_data.listen_mode */
#define LISTEN_NONE 0
#define LISTEN_KERNEL 1
#define LISTEN_RAW 2
-/* Values for client_config.state */
+/* Values for client_data.state */
/* initial state: (re)start DHCP negotiation */
#define INIT_SELECTING 0
/* discover was sent, DHCPOFFER reply received */
: "none"
);
- client_config.listen_mode = new_mode;
- if (client_config.sockfd >= 0) {
- close(client_config.sockfd);
- client_config.sockfd = -1;
+ client_data.listen_mode = new_mode;
+ if (client_data.sockfd >= 0) {
+ close(client_data.sockfd);
+ client_data.sockfd = -1;
}
if (new_mode == LISTEN_KERNEL)
- client_config.sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_config.interface);
+ client_data.sockfd = udhcp_listen_socket(/*INADDR_ANY,*/ CLIENT_PORT, client_data.interface);
else if (new_mode != LISTEN_NONE)
- client_config.sockfd = udhcp_raw_socket(client_config.ifindex);
- /* else LISTEN_NONE: client_config.sockfd stays closed */
+ client_data.sockfd = udhcp_raw_socket(client_data.ifindex);
+ /* else LISTEN_NONE: client_data.sockfd stays closed */
}
/* Called only on SIGUSR1 */
static void perform_renew(void)
{
bb_info_msg("performing DHCP renew");
- switch (client_config.state) {
+ switch (client_data.state) {
case BOUND:
change_listen_mode(LISTEN_KERNEL);
case RENEWING:
case REBINDING:
- client_config.state = RENEW_REQUESTED;
+ client_data.state = RENEW_REQUESTED;
break;
case RENEW_REQUESTED: /* impatient are we? fine, square 1 */
udhcp_run_script(NULL, "deconfig");
case REQUESTING:
case RELEASED:
change_listen_mode(LISTEN_RAW);
- client_config.state = INIT_SELECTING;
+ client_data.state = INIT_SELECTING;
break;
case INIT_SELECTING:
break;
struct in_addr temp_addr;
/* send release packet */
- if (client_config.state == BOUND
- || client_config.state == RENEWING
- || client_config.state == REBINDING
- || client_config.state == RENEW_REQUESTED
+ if (client_data.state == BOUND
+ || client_data.state == RENEWING
+ || client_data.state == REBINDING
+ || client_data.state == RENEW_REQUESTED
) {
temp_addr.s_addr = server_addr;
strcpy(buffer, inet_ntoa(temp_addr));
udhcp_run_script(NULL, "deconfig");
change_listen_mode(LISTEN_NONE);
- client_config.state = RELEASED;
+ client_data.state = RELEASED;
}
static uint8_t* alloc_dhcp_option(int code, const char *str, int extra)
bb_daemonize(0);
logmode &= ~LOGMODE_STDIO;
/* rewrite pidfile, as our pid is different now */
- write_pidfile(client_config.pidfile);
+ write_pidfile(client_data.pidfile);
}
#endif
/* Default options */
IF_FEATURE_UDHCP_PORT(SERVER_PORT = 67;)
IF_FEATURE_UDHCP_PORT(CLIENT_PORT = 68;)
- client_config.interface = "eth0";
- client_config.script = CONFIG_UDHCPC_DEFAULT_SCRIPT;
- client_config.sockfd = -1;
+ client_data.interface = "eth0";
+ client_data.script = CONFIG_UDHCPC_DEFAULT_SCRIPT;
+ client_data.sockfd = -1;
str_V = "udhcp "BB_VER;
/* Parse command line */
"\0" IF_UDHCP_VERBOSE("vv") /* -v is a counter */
, udhcpc_longopts
, &str_V, &str_h, &str_h, &str_F
- , &client_config.interface, &client_config.pidfile /* i,p */
+ , &client_data.interface, &client_data.pidfile /* i,p */
, &str_r /* r */
- , &client_config.script /* s */
+ , &client_data.script /* s */
, &discover_timeout, &discover_retries, &tryagain_timeout /* T,t,A */
, &list_O
, &list_x
if (opt & (OPT_h|OPT_H)) {
//msg added 2011-11
bb_error_msg("option -h NAME is deprecated, use -x hostname:NAME");
- client_config.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0);
+ client_data.hostname = alloc_dhcp_option(DHCP_HOST_NAME, str_h, 0);
}
if (opt & OPT_F) {
/* FQDN option format: [0x51][len][flags][0][0]<fqdn> */
- client_config.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3);
+ client_data.fqdn = alloc_dhcp_option(DHCP_FQDN, str_F, 3);
/* Flag bits: 0000NEOS
* S: 1 = Client requests server to update A RR in DNS as well as PTR
* O: 1 = Server indicates to client that DNS has been updated regardless
* N: 1 = Client requests server to not update DNS (S must be 0 then)
* Two [0] bytes which follow are deprecated and must be 0.
*/
- client_config.fqdn[OPT_DATA + 0] = 0x1;
- /*client_config.fqdn[OPT_DATA + 1] = 0; - xzalloc did it */
- /*client_config.fqdn[OPT_DATA + 2] = 0; */
+ client_data.fqdn[OPT_DATA + 0] = 0x1;
+ /*client_data.fqdn[OPT_DATA + 1] = 0; - xzalloc did it */
+ /*client_data.fqdn[OPT_DATA + 2] = 0; */
}
if (opt & OPT_r)
requested_ip = inet_addr(str_r);
n = udhcp_option_idx(optstr, dhcp_option_strings);
n = dhcp_optflags[n].code;
}
- client_config.opt_mask[n >> 3] |= 1 << (n & 7);
+ client_data.opt_mask[n >> 3] |= 1 << (n & 7);
}
if (!(opt & OPT_o)) {
unsigned i, n;
for (i = 0; (n = dhcp_optflags[i].code) != 0; i++) {
if (dhcp_optflags[i].flags & OPTION_REQ) {
- client_config.opt_mask[n >> 3] |= 1 << (n & 7);
+ client_data.opt_mask[n >> 3] |= 1 << (n & 7);
}
}
}
while (list_x) {
char *optstr = xstrdup(llist_pop(&list_x));
- udhcp_str2optset(optstr, &client_config.options,
+ udhcp_str2optset(optstr, &client_data.options,
dhcp_optflags, dhcp_option_strings,
/*dhcpv6:*/ 0
);
free(optstr);
}
- if (udhcp_read_interface(client_config.interface,
- &client_config.ifindex,
+ if (udhcp_read_interface(client_data.interface,
+ &client_data.ifindex,
NULL,
- client_config.client_mac)
+ client_data.client_mac)
) {
return 1;
}
clientid_mac_ptr = NULL;
- if (!(opt & OPT_C) && !udhcp_find_option(client_config.options, DHCP_CLIENT_ID)) {
+ if (!(opt & OPT_C) && !udhcp_find_option(client_data.options, DHCP_CLIENT_ID)) {
/* not suppressed and not set, set the default client ID */
- client_config.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7);
- client_config.clientid[OPT_DATA] = 1; /* type: ethernet */
- clientid_mac_ptr = client_config.clientid + OPT_DATA+1;
- memcpy(clientid_mac_ptr, client_config.client_mac, 6);
+ client_data.clientid = alloc_dhcp_option(DHCP_CLIENT_ID, "", 7);
+ client_data.clientid[OPT_DATA] = 1; /* type: ethernet */
+ clientid_mac_ptr = client_data.clientid + OPT_DATA+1;
+ memcpy(clientid_mac_ptr, client_data.client_mac, 6);
}
if (str_V[0] != '\0') {
- // can drop -V, str_V, client_config.vendorclass,
+ // can drop -V, str_V, client_data.vendorclass,
// but need to add "vendor" to the list of recognized
// string opts for this to work;
// and need to tweak add_client_options() too...
// ...so the question is, should we?
//bb_error_msg("option -V VENDOR is deprecated, use -x vendor:VENDOR");
- client_config.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0);
+ client_data.vendorclass = alloc_dhcp_option(DHCP_VENDOR, str_V, 0);
}
#if !BB_MMU
/* Make sure fd 0,1,2 are open */
bb_sanitize_stdio();
/* Create pidfile */
- write_pidfile(client_config.pidfile);
+ write_pidfile(client_data.pidfile);
/* Goes to stdout (unless NOMMU) and possibly syslog */
bb_info_msg("started, v"BB_VER);
/* Set up the signal pipe */
/* We want random_xid to be random... */
srand(monotonic_us());
- client_config.state = INIT_SELECTING;
+ client_data.state = INIT_SELECTING;
udhcp_run_script(NULL, "deconfig");
change_listen_mode(LISTEN_RAW);
packet_num = 0;
/* silence "uninitialized!" warning */
unsigned timestamp_before_wait = timestamp_before_wait;
- //bb_error_msg("sockfd:%d, listen_mode:%d", client_config.sockfd, client_config.listen_mode);
+ //bb_error_msg("sockfd:%d, listen_mode:%d", client_data.sockfd, client_data.listen_mode);
/* Was opening raw or udp socket here
- * if (client_config.listen_mode != LISTEN_NONE && client_config.sockfd < 0),
+ * if (client_data.listen_mode != LISTEN_NONE && client_data.sockfd < 0),
* but on fast network renew responses return faster
* than we open sockets. Thus this code is moved
* to change_listen_mode(). Thus we open listen socket
* BEFORE we send renew request (see "case BOUND:"). */
- udhcp_sp_fd_set(pfds, client_config.sockfd);
+ udhcp_sp_fd_set(pfds, client_data.sockfd);
tv = timeout - already_waited_sec;
retval = 0;
* or if the status of the bridge changed).
* Refresh ifindex and client_mac:
*/
- if (udhcp_read_interface(client_config.interface,
- &client_config.ifindex,
+ if (udhcp_read_interface(client_data.interface,
+ &client_data.ifindex,
NULL,
- client_config.client_mac)
+ client_data.client_mac)
) {
goto ret0; /* iface is gone? */
}
if (clientid_mac_ptr)
- memcpy(clientid_mac_ptr, client_config.client_mac, 6);
+ memcpy(clientid_mac_ptr, client_data.client_mac, 6);
/* We will restart the wait in any case */
already_waited_sec = 0;
- switch (client_config.state) {
+ switch (client_data.state) {
case INIT_SELECTING:
if (!discover_retries || packet_num < discover_retries) {
if (packet_num == 0)
* were seen in the wild. Treat them similarly
* to "no response to discover" case */
change_listen_mode(LISTEN_RAW);
- client_config.state = INIT_SELECTING;
+ client_data.state = INIT_SELECTING;
goto leasefail;
case BOUND:
/* 1/2 lease passed, enter renewing state */
- client_config.state = RENEWING;
- client_config.first_secs = 0; /* make secs field count from 0 */
+ client_data.state = RENEWING;
+ client_data.first_secs = 0; /* make secs field count from 0 */
change_listen_mode(LISTEN_KERNEL);
log1("entering renew state");
/* fall right through */
}
/* Timed out or error, enter rebinding state */
log1("entering rebinding state");
- client_config.state = REBINDING;
+ client_data.state = REBINDING;
/* fall right through */
case REBINDING:
/* Switch to bcast receive */
/* Timed out, enter init state */
bb_info_msg("lease lost, entering init state");
udhcp_run_script(NULL, "deconfig");
- client_config.state = INIT_SELECTING;
- client_config.first_secs = 0; /* make secs field count from 0 */
+ client_data.state = INIT_SELECTING;
+ client_data.first_secs = 0; /* make secs field count from 0 */
/*timeout = 0; - already is */
packet_num = 0;
continue;
/* Is it a signal? */
switch (udhcp_sp_read()) {
case SIGUSR1:
- client_config.first_secs = 0; /* make secs field count from 0 */
+ client_data.first_secs = 0; /* make secs field count from 0 */
already_waited_sec = 0;
perform_renew();
- if (client_config.state == RENEW_REQUESTED) {
+ if (client_data.state == RENEW_REQUESTED) {
/* We might be either on the same network
* (in which case renew might work),
* or we might be on a completely different one
int len;
/* A packet is ready, read it */
- if (client_config.listen_mode == LISTEN_KERNEL)
- len = udhcp_recv_kernel_packet(&packet, client_config.sockfd);
+ if (client_data.listen_mode == LISTEN_KERNEL)
+ len = udhcp_recv_kernel_packet(&packet, client_data.sockfd);
else
- len = udhcp_recv_raw_packet(&packet, client_config.sockfd);
+ len = udhcp_recv_raw_packet(&packet, client_data.sockfd);
if (len == -1) {
/* Error is severe, reopen socket */
bb_error_msg("read error: "STRERROR_FMT", reopening socket" STRERROR_ERRNO);
sleep(discover_timeout); /* 3 seconds by default */
- change_listen_mode(client_config.listen_mode); /* just close and reopen */
+ change_listen_mode(client_data.listen_mode); /* just close and reopen */
}
/* If this packet will turn out to be unrelated/bogus,
* we will go back and wait for next one.
/* Ignore packets that aren't for us */
if (packet.hlen != 6
- || memcmp(packet.chaddr, client_config.client_mac, 6) != 0
+ || memcmp(packet.chaddr, client_data.client_mac, 6) != 0
) {
//FIXME: need to also check that last 10 bytes are zero
log1("chaddr does not match, ignoring packet"); // log2?
continue;
}
- switch (client_config.state) {
+ switch (client_data.state) {
case INIT_SELECTING:
/* Must be a DHCPOFFER */
if (*message == DHCPOFFER) {
requested_ip = packet.yiaddr;
/* enter requesting state */
- client_config.state = REQUESTING;
+ client_data.state = REQUESTING;
timeout = 0;
packet_num = 0;
already_waited_sec = 0;
if (!arpping(packet.yiaddr,
NULL,
(uint32_t) 0,
- client_config.client_mac,
- client_config.interface,
+ client_data.client_mac,
+ client_data.interface,
arpping_ms)
) {
bb_info_msg("offered address is in use "
"(got ARP reply), declining");
send_decline(/*xid,*/ server_addr, packet.yiaddr);
- if (client_config.state != REQUESTING)
+ if (client_data.state != REQUESTING)
udhcp_run_script(NULL, "deconfig");
change_listen_mode(LISTEN_RAW);
- client_config.state = INIT_SELECTING;
- client_config.first_secs = 0; /* make secs field count from 0 */
+ client_data.state = INIT_SELECTING;
+ client_data.first_secs = 0; /* make secs field count from 0 */
requested_ip = 0;
timeout = tryagain_timeout;
packet_num = 0;
requested_ip = packet.yiaddr;
start = monotonic_sec();
- udhcp_run_script(&packet, client_config.state == REQUESTING ? "bound" : "renew");
+ udhcp_run_script(&packet, client_data.state == REQUESTING ? "bound" : "renew");
already_waited_sec = (unsigned)monotonic_sec() - start;
timeout = lease_seconds / 2;
if ((unsigned)timeout < already_waited_sec) {
timeout = already_waited_sec = 0;
}
- client_config.state = BOUND;
+ client_data.state = BOUND;
change_listen_mode(LISTEN_NONE);
if (opt & OPT_q) { /* quit after lease */
goto ret0;
/* return to init state */
bb_info_msg("received %s", "DHCP NAK");
udhcp_run_script(&packet, "nak");
- if (client_config.state != REQUESTING)
+ if (client_data.state != REQUESTING)
udhcp_run_script(NULL, "deconfig");
change_listen_mode(LISTEN_RAW);
sleep(3); /* avoid excessive network traffic */
- client_config.state = INIT_SELECTING;
- client_config.first_secs = 0; /* make secs field count from 0 */
+ client_data.state = INIT_SELECTING;
+ client_data.first_secs = 0; /* make secs field count from 0 */
requested_ip = 0;
timeout = 0;
packet_num = 0;
perform_release(server_addr, requested_ip);
retval = 0;
ret:
- /*if (client_config.pidfile) - remove_pidfile has its own check */
- remove_pidfile(client_config.pidfile);
+ /*if (client_data.pidfile) - remove_pidfile has its own check */
+ remove_pidfile(client_data.pidfile);
return retval;
}