Propagate returns through ifchange_(deconfig|bind).

While doing so remove unnecessary argument null checks and
make sure not to alter the stored interface state if the
ifch requests failed.
This commit is contained in:
Nicholas J. Kain 2015-02-14 19:10:23 -05:00
parent 44175bd77c
commit 170f87c0e7
3 changed files with 21 additions and 19 deletions

View File

@ -225,19 +225,23 @@ static int ifchwrite(const char buf[static 1], size_t count)
return -1; return -1;
} }
void ifchange_deconfig(struct client_state_t cs[static 1]) int ifchange_deconfig(struct client_state_t cs[static 1])
{ {
char buf[256]; char buf[256];
int ret = -1;
if (cs->ifDeconfig) if (cs->ifDeconfig)
return; return 0;
cs->ifDeconfig = 1;
snprintf(buf, sizeof buf, "ip4:0.0.0.0,255.255.255.255;"); snprintf(buf, sizeof buf, "ip4:0.0.0.0,255.255.255.255;");
log_line("%s: Resetting IP configuration.", client_config.interface); log_line("%s: Resetting IP configuration.", client_config.interface);
ifchwrite(buf, strlen(buf)); ret = ifchwrite(buf, strlen(buf));
if (ret >= 0) {
cs->ifDeconfig = 1;
memset(&cfg_packet, 0, sizeof cfg_packet); memset(&cfg_packet, 0, sizeof cfg_packet);
}
return ret;
} }
static size_t send_client_ip(char out[static 1], size_t olen, static size_t send_client_ip(char out[static 1], size_t olen,
@ -308,9 +312,6 @@ static size_t send_cmd(char out[static 1], size_t olen,
uint8_t optdata[MAX_DOPT_SIZE], olddata[MAX_DOPT_SIZE]; uint8_t optdata[MAX_DOPT_SIZE], olddata[MAX_DOPT_SIZE];
ssize_t optlen, oldlen; ssize_t optlen, oldlen;
if (!packet)
return 0;
optlen = get_dhcp_opt(packet, code, optdata, sizeof optdata); optlen = get_dhcp_opt(packet, code, optdata, sizeof optdata);
if (!optlen) if (!optlen)
return 0; return 0;
@ -321,14 +322,12 @@ static size_t send_cmd(char out[static 1], size_t olen,
return r > 0 ? r : 0; return r > 0 ? r : 0;
} }
void ifchange_bind(struct client_state_t cs[static 1], int ifchange_bind(struct client_state_t cs[static 1],
struct dhcpmsg packet[static 1]) struct dhcpmsg packet[static 1])
{ {
char buf[2048]; char buf[2048];
size_t bo; size_t bo;
int ret = -1;
if (!packet)
return;
memset(buf, 0, sizeof buf); memset(buf, 0, sizeof buf);
bo = send_client_ip(buf, sizeof buf, packet); bo = send_client_ip(buf, sizeof buf, packet);
@ -339,8 +338,12 @@ void ifchange_bind(struct client_state_t cs[static 1],
bo += send_cmd(buf + bo, sizeof buf - bo, packet, DCODE_MTU); bo += send_cmd(buf + bo, sizeof buf - bo, packet, DCODE_MTU);
bo += send_cmd(buf + bo, sizeof buf - bo, packet, DCODE_WINS); bo += send_cmd(buf + bo, sizeof buf - bo, packet, DCODE_WINS);
if (bo) if (bo)
ifchwrite(buf, bo); ret = ifchwrite(buf, bo);
if (ret >= 0) {
cs->ifDeconfig = 0; cs->ifDeconfig = 0;
memcpy(&cfg_packet, packet, sizeof cfg_packet); memcpy(&cfg_packet, packet, sizeof cfg_packet);
}
return ret;
} }

View File

@ -29,8 +29,8 @@
#ifndef IFCHANGE_H_ #ifndef IFCHANGE_H_
#define IFCHANGE_H_ #define IFCHANGE_H_
void ifchange_bind(struct client_state_t cs[static 1], int ifchange_bind(struct client_state_t cs[static 1],
struct dhcpmsg packet[static 1]); struct dhcpmsg packet[static 1]);
void ifchange_deconfig(struct client_state_t cs[static 1]); int ifchange_deconfig(struct client_state_t cs[static 1]);
#endif #endif

View File

@ -74,7 +74,6 @@
#include "rfkill.h" #include "rfkill.h"
struct client_state_t cs = { struct client_state_t cs = {
.ifDeconfig = 0,
.init = 1, .init = 1,
.epollFd = -1, .epollFd = -1,
.signalFd = -1, .signalFd = -1,