Simplify logging and fix some format specifiers.

This commit is contained in:
Nicholas J. Kain 2020-11-24 21:02:51 -05:00
parent 2e3c504cc5
commit 28e1b34bac
20 changed files with 363 additions and 440 deletions

View File

@ -200,7 +200,6 @@ add_dependencies(ndhc ndhc_ragel)
target_sources(ndhc PRIVATE target_sources(ndhc PRIVATE
"src/lib/io.c" "src/lib/io.c"
"src/lib/log.c"
"src/lib/hwrng.c" "src/lib/hwrng.c"
"src/lib/random.c" "src/lib/random.c"
"src/lib/privs.c" "src/lib/privs.c"

View File

@ -156,8 +156,8 @@ static int arp_open_fd(struct client_state_t cs[static 1], bool defense)
cs->arpFd = defense ? get_arp_defense_socket(cs) cs->arpFd = defense ? get_arp_defense_socket(cs)
: get_arp_basic_socket(cs); : get_arp_basic_socket(cs);
if (cs->arpFd < 0) { if (cs->arpFd < 0) {
log_error("%s: (%s) Failed to create socket: %s", log_line("%s: (%s) Failed to create socket: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
return -1; return -1;
} }
return 0; return 0;
@ -175,26 +175,26 @@ static int arp_send(struct client_state_t cs[static 1],
memcpy(addr.sll_addr, client_config.arp, 6); memcpy(addr.sll_addr, client_config.arp, 6);
if (cs->arpFd < 0) { if (cs->arpFd < 0) {
log_warning("%s: arp: Send attempted when no ARP fd is open.", log_line("%s: arp: Send attempted when no ARP fd is open.",
client_config.interface); client_config.interface);
return ret; return ret;
} }
if (!carrier_isup()) { if (!carrier_isup()) {
log_error("%s: (%s) carrier down; sendto would fail", log_line("%s: (%s) carrier down; sendto would fail",
client_config.interface, __func__); client_config.interface, __func__);
ret = -99; ret = -99;
goto carrier_down; goto carrier_down;
} }
ret = safe_sendto(cs->arpFd, (const char *)arp, sizeof *arp, 0, ret = safe_sendto(cs->arpFd, (const char *)arp, sizeof *arp, 0,
(struct sockaddr *)&addr, sizeof addr); (struct sockaddr *)&addr, sizeof addr);
if (ret < 0 || (size_t)ret != sizeof *arp) { if (ret < 0 || (size_t)ret != sizeof *arp) {
if (ret < 0) if (ret < 0)
log_error("%s: (%s) sendto failed: %s", log_line("%s: (%s) sendto failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
else else
log_error("%s: (%s) sendto short write: %d < %zu", log_line("%s: (%s) sendto short write: %d < %zu",
client_config.interface, __func__, ret, sizeof *arp); client_config.interface, __func__, ret, sizeof *arp);
carrier_down: carrier_down:
return ret; return ret;
} }
@ -343,28 +343,28 @@ static int arp_gw_success(struct client_state_t cs[static 1])
static int arp_validate_bpf(struct arpMsg *am) static int arp_validate_bpf(struct arpMsg *am)
{ {
if (am->h_proto != htons(ETH_P_ARP)) { if (am->h_proto != htons(ETH_P_ARP)) {
log_warning("%s: arp: IP header does not indicate ARP protocol", log_line("%s: arp: IP header does not indicate ARP protocol",
client_config.interface); client_config.interface);
return 0; return 0;
} }
if (am->htype != htons(ARPHRD_ETHER)) { if (am->htype != htons(ARPHRD_ETHER)) {
log_warning("%s: arp: ARP hardware type field invalid", log_line("%s: arp: ARP hardware type field invalid",
client_config.interface); client_config.interface);
return 0; return 0;
} }
if (am->ptype != htons(ETH_P_IP)) { if (am->ptype != htons(ETH_P_IP)) {
log_warning("%s: arp: ARP protocol type field invalid", log_line("%s: arp: ARP protocol type field invalid",
client_config.interface); client_config.interface);
return 0; return 0;
} }
if (am->hlen != 6) { if (am->hlen != 6) {
log_warning("%s: arp: ARP hardware address length invalid", log_line("%s: arp: ARP hardware address length invalid",
client_config.interface); client_config.interface);
return 0; return 0;
} }
if (am->plen != 4) { if (am->plen != 4) {
log_warning("%s: arp: ARP protocol address length invalid", log_line("%s: arp: ARP protocol address length invalid",
client_config.interface); client_config.interface);
return 0; return 0;
} }
return 1; return 1;
@ -437,8 +437,8 @@ int arp_gw_check_timeout(struct client_state_t cs[static 1], long long nowts)
log_line("%s: arp: Still waiting for gateway to reply to arp ping...", log_line("%s: arp: Still waiting for gateway to reply to arp ping...",
client_config.interface); client_config.interface);
if (arp_ping(cs, cs->routerAddr) < 0) { if (arp_ping(cs, cs->routerAddr) < 0) {
log_warning("%s: arp: Failed to send ARP ping in retransmission.", log_line("%s: arp: Failed to send ARP ping in retransmission.",
client_config.interface); client_config.interface);
return ARPR_FAIL; return ARPR_FAIL;
} }
} }
@ -446,8 +446,8 @@ int arp_gw_check_timeout(struct client_state_t cs[static 1], long long nowts)
log_line("%s: arp: Still waiting for DHCP agent to reply to arp ping...", log_line("%s: arp: Still waiting for DHCP agent to reply to arp ping...",
client_config.interface); client_config.interface);
if (arp_ping(cs, cs->srcAddr) < 0) { if (arp_ping(cs, cs->srcAddr) < 0) {
log_warning("%s: arp: Failed to send ARP ping in retransmission.", log_line("%s: arp: Failed to send ARP ping in retransmission.",
client_config.interface); client_config.interface);
return ARPR_FAIL; return ARPR_FAIL;
} }
} }
@ -474,8 +474,8 @@ int arp_gw_query_timeout(struct client_state_t cs[static 1], long long nowts)
client_config.interface); client_config.interface);
++cs->router_arp_sent; ++cs->router_arp_sent;
if (arp_ping(cs, cs->routerAddr) < 0) { if (arp_ping(cs, cs->routerAddr) < 0) {
log_warning("%s: arp: Failed to send ARP ping in retransmission.", log_line("%s: arp: Failed to send ARP ping in retransmission.",
client_config.interface); client_config.interface);
return ARPR_FAIL; return ARPR_FAIL;
} }
} }
@ -490,8 +490,8 @@ int arp_gw_query_timeout(struct client_state_t cs[static 1], long long nowts)
client_config.interface); client_config.interface);
++cs->server_arp_sent; ++cs->server_arp_sent;
if (arp_ping(cs, cs->srcAddr) < 0) { if (arp_ping(cs, cs->srcAddr) < 0) {
log_warning("%s: arp: Failed to send ARP ping in retransmission.", log_line("%s: arp: Failed to send ARP ping in retransmission.",
client_config.interface); client_config.interface);
return ARPR_FAIL; return ARPR_FAIL;
} }
} }
@ -508,7 +508,7 @@ int arp_collision_timeout(struct client_state_t cs[static 1], long long nowts)
char clibuf[INET_ADDRSTRLEN]; char clibuf[INET_ADDRSTRLEN];
struct in_addr temp_addr = {.s_addr = garp.dhcp_packet.yiaddr}; struct in_addr temp_addr = {.s_addr = garp.dhcp_packet.yiaddr};
inet_ntop(AF_INET, &temp_addr, clibuf, sizeof clibuf); inet_ntop(AF_INET, &temp_addr, clibuf, sizeof clibuf);
log_line("%s: Lease of %s obtained. Lease time is %ld seconds.", log_line("%s: Lease of %s obtained. Lease time is %u seconds.",
client_config.interface, clibuf, cs->lease); client_config.interface, clibuf, cs->lease);
cs->clientAddr = garp.dhcp_packet.yiaddr; cs->clientAddr = garp.dhcp_packet.yiaddr;
cs->program_init = false; cs->program_init = false;
@ -530,8 +530,8 @@ int arp_collision_timeout(struct client_state_t cs[static 1], long long nowts)
return ARPR_OK; return ARPR_OK;
} }
if (arp_ip_anon_ping(cs, garp.dhcp_packet.yiaddr) < 0) { if (arp_ip_anon_ping(cs, garp.dhcp_packet.yiaddr) < 0) {
log_warning("%s: arp: Failed to send ARP ping in retransmission.", log_line("%s: arp: Failed to send ARP ping in retransmission.",
client_config.interface); client_config.interface);
return ARPR_FAIL; return ARPR_FAIL;
} }
garp.probe_wait_time = arp_gen_probe_wait(cs); garp.probe_wait_time = arp_gen_probe_wait(cs);
@ -547,8 +547,8 @@ int arp_query_gateway(struct client_state_t cs[static 1])
return ARPR_OK; return ARPR_OK;
} }
if (arp_get_gw_hwaddr(cs) < 0) { if (arp_get_gw_hwaddr(cs) < 0) {
log_warning("%s: (%s) Failed to send request to get gateway and agent hardware addresses: %s", log_line("%s: (%s) Failed to send request to get gateway and agent hardware addresses: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
garp.wake_ts[AS_QUERY_GW_SEND] = curms() + ARP_RETRANS_DELAY; garp.wake_ts[AS_QUERY_GW_SEND] = curms() + ARP_RETRANS_DELAY;
return ARPR_FAIL; return ARPR_FAIL;
} }
@ -575,8 +575,8 @@ int arp_announce(struct client_state_t cs[static 1])
return ARPR_OK; return ARPR_OK;
} }
if (arp_announcement(cs) < 0) { if (arp_announcement(cs) < 0) {
log_warning("%s: (%s) Failed to send ARP announcement: %s", log_line("%s: (%s) Failed to send ARP announcement: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
garp.wake_ts[AS_ANNOUNCE] = curms() + ARP_RETRANS_DELAY ; garp.wake_ts[AS_ANNOUNCE] = curms() + ARP_RETRANS_DELAY ;
return ARPR_FAIL; return ARPR_FAIL;
} }
@ -608,17 +608,17 @@ int arp_do_defense(struct client_state_t cs[static 1])
if (!arp_validate_bpf_defense(cs, &garp.reply)) if (!arp_validate_bpf_defense(cs, &garp.reply))
return ARPR_OK; return ARPR_OK;
log_warning("%s: arp: Detected a peer attempting to use our IP!", client_config.interface); log_line("%s: arp: Detected a peer attempting to use our IP!", client_config.interface);
long long nowts = curms(); long long nowts = curms();
garp.wake_ts[AS_DEFENSE] = -1; garp.wake_ts[AS_DEFENSE] = -1;
if (!garp.last_conflict_ts || if (!garp.last_conflict_ts ||
nowts - garp.last_conflict_ts < DEFEND_INTERVAL) { nowts - garp.last_conflict_ts < DEFEND_INTERVAL) {
log_warning("%s: arp: Defending our lease IP.", client_config.interface); log_line("%s: arp: Defending our lease IP.", client_config.interface);
if (arp_announcement(cs) < 0) if (arp_announcement(cs) < 0)
return ARPR_FAIL; return ARPR_FAIL;
} else if (!garp.relentless_def) { } else if (!garp.relentless_def) {
log_warning("%s: arp: Conflicting peer is persistent. Requesting new lease.", log_line("%s: arp: Conflicting peer is persistent. Requesting new lease.",
client_config.interface); client_config.interface);
send_release(cs); send_release(cs);
return ARPR_CONFLICT; return ARPR_CONFLICT;
} else { } else {
@ -686,8 +686,8 @@ int arp_do_collision_check(struct client_state_t cs[static 1])
client_config.interface); client_config.interface);
int r = send_decline(cs, garp.dhcp_packet.yiaddr); int r = send_decline(cs, garp.dhcp_packet.yiaddr);
if (r < 0) { if (r < 0) {
log_warning("%s: Failed to send a decline notice packet.", log_line("%s: Failed to send a decline notice packet.",
client_config.interface); client_config.interface);
return ARPR_FAIL; return ARPR_FAIL;
} }
return ARPR_CONFLICT; return ARPR_CONFLICT;
@ -744,8 +744,8 @@ bool arp_packet_get(struct client_state_t cs[static 1])
if (r == 0) if (r == 0)
return false; return false;
if (r < 0) { if (r < 0) {
log_error("%s: (%s) ARP response read failed: %s", log_line("%s: (%s) ARP response read failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
// Timeouts will trigger anyway without being forced. // Timeouts will trigger anyway without being forced.
arp_min_close_fd(cs); arp_min_close_fd(cs);
if (arp_open_fd(cs, cs->arp_is_defense) < 0) if (arp_open_fd(cs, cs->arp_is_defense) < 0)

View File

@ -244,7 +244,7 @@ static void parse_cfgfile(const char fname[static 1])
if (reached_eof) if (reached_eof)
break; break;
if (!consumed && lend >= sizeof l - 1) if (!consumed && lend >= sizeof l - 1)
suicide("Line %u in config file '%s' is too long: %u > %u.", suicide("Line %zu in config file '%s' is too long: %zu > %zu.",
linenum, fname, lend, sizeof l - 1); linenum, fname, lend, sizeof l - 1);
if (consumed + 1 > lc) suicide("lc[%zu] - consumed[%zu] would underflow", lc, lend); if (consumed + 1 > lc) suicide("lc[%zu] - consumed[%zu] would underflow", lc, lend);

View File

@ -83,8 +83,8 @@ static ssize_t send_dhcp_unicast(struct client_state_t cs[static 1],
ssize_t ret = -1; ssize_t ret = -1;
int fd = get_udp_unicast_socket(cs); int fd = get_udp_unicast_socket(cs);
if (fd < 0) { if (fd < 0) {
log_error("%s: (%s) get_udp_unicast_socket failed", log_line("%s: (%s) get_udp_unicast_socket failed",
client_config.interface, __func__); client_config.interface, __func__);
goto out; goto out;
} }
@ -94,36 +94,36 @@ static ssize_t send_dhcp_unicast(struct client_state_t cs[static 1],
.sin_addr.s_addr = cs->serverAddr, .sin_addr.s_addr = cs->serverAddr,
}; };
if (connect(fd, (struct sockaddr *)&raddr, sizeof(struct sockaddr)) < 0) { if (connect(fd, (struct sockaddr *)&raddr, sizeof(struct sockaddr)) < 0) {
log_error("%s: (%s) connect failed: %s", client_config.interface, log_line("%s: (%s) connect failed: %s", client_config.interface,
__func__, strerror(errno)); __func__, strerror(errno));
goto out_fd; goto out_fd;
} }
// Send packets that are as short as possible. // Send packets that are as short as possible.
ssize_t endloc = get_end_option_idx(payload); ssize_t endloc = get_end_option_idx(payload);
if (endloc < 0) { if (endloc < 0) {
log_error("%s: (%s) No end marker. Not sending.", log_line("%s: (%s) No end marker. Not sending.",
client_config.interface, __func__); client_config.interface, __func__);
goto out_fd; goto out_fd;
} }
const size_t el = (size_t)endloc + 1; const size_t el = (size_t)endloc + 1;
if (el > sizeof payload->options) { if (el > sizeof payload->options) {
log_error("%s: (%s) Invalid value of endloc. Not sending.", log_line("%s: (%s) Invalid value of endloc. Not sending.",
client_config.interface, __func__); client_config.interface, __func__);
goto out_fd; goto out_fd;
} }
size_t payload_len = size_t payload_len =
sizeof *payload - (sizeof payload->options - el); sizeof *payload - (sizeof payload->options - el);
if (!carrier_isup()) { if (!carrier_isup()) {
log_error("%s: (%s) carrier down; write would fail", log_line("%s: (%s) carrier down; write would fail",
client_config.interface, __func__); client_config.interface, __func__);
ret = -99; ret = -99;
goto out_fd; goto out_fd;
} }
ret = safe_write(fd, (const char *)payload, payload_len); ret = safe_write(fd, (const char *)payload, payload_len);
if (ret < 0 || (size_t)ret != payload_len) if (ret < 0 || (size_t)ret != payload_len)
log_error("%s: (%s) write failed: %d", client_config.interface, log_line("%s: (%s) write failed: %zd", client_config.interface,
__func__, ret); __func__, ret);
out_fd: out_fd:
close(fd); close(fd);
out: out:
@ -157,28 +157,28 @@ static int udp_checksum(struct ip_udp_dhcp_packet packet[static 1])
static int get_raw_packet_validate_bpf(struct ip_udp_dhcp_packet packet[static 1]) static int get_raw_packet_validate_bpf(struct ip_udp_dhcp_packet packet[static 1])
{ {
if (packet->ip.version != IPVERSION) { if (packet->ip.version != IPVERSION) {
log_warning("%s: IP version is not IPv4.", client_config.interface); log_line("%s: IP version is not IPv4.", client_config.interface);
return 0; return 0;
} }
if (packet->ip.ihl != sizeof packet->ip >> 2) { if (packet->ip.ihl != sizeof packet->ip >> 2) {
log_warning("%s: IP header length incorrect.", log_line("%s: IP header length incorrect.",
client_config.interface); client_config.interface);
return 0; return 0;
} }
if (packet->ip.protocol != IPPROTO_UDP) { if (packet->ip.protocol != IPPROTO_UDP) {
log_warning("%s: IP header is not UDP: %d", log_line("%s: IP header is not UDP: %d",
client_config.interface, packet->ip.protocol); client_config.interface, packet->ip.protocol);
return 0; return 0;
} }
if (ntohs(packet->udp.dest) != DHCP_CLIENT_PORT) { if (ntohs(packet->udp.dest) != DHCP_CLIENT_PORT) {
log_warning("%s: UDP destination port incorrect: %d", log_line("%s: UDP destination port incorrect: %d",
client_config.interface, ntohs(packet->udp.dest)); client_config.interface, ntohs(packet->udp.dest));
return 0; return 0;
} }
if (ntohs(packet->udp.len) != if (ntohs(packet->udp.len) !=
ntohs(packet->ip.tot_len) - sizeof packet->ip) { ntohs(packet->ip.tot_len) - sizeof packet->ip) {
log_warning("%s: UDP header length incorrect.", log_line("%s: UDP header length incorrect.",
client_config.interface); client_config.interface);
return 0; return 0;
} }
return 1; return 1;
@ -197,8 +197,8 @@ static ssize_t get_raw_packet(struct client_state_t cs[static 1],
if (inc < 0) { if (inc < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) if (errno == EAGAIN || errno == EWOULDBLOCK)
return -2; return -2;
log_warning("%s: (%s) read error %s", client_config.interface, log_line("%s: (%s) read error %s", client_config.interface,
__func__, strerror(errno)); __func__, strerror(errno));
return -1; return -1;
} }
size_t iphdrlen = ntohs(packet.ip.tot_len); size_t iphdrlen = ntohs(packet.ip.tot_len);
@ -208,23 +208,24 @@ static ssize_t get_raw_packet(struct client_state_t cs[static 1],
return -2; return -2;
if (!ip_checksum(&packet)) { if (!ip_checksum(&packet)) {
log_error("%s: IP header checksum incorrect.", log_line("%s: IP header checksum incorrect.",
client_config.interface); client_config.interface);
return -2; return -2;
} }
if (iphdrlen <= sizeof packet.ip + sizeof packet.udp) { if (iphdrlen <= sizeof packet.ip + sizeof packet.udp) {
log_error("%s: Packet received that is too small (%zu bytes).", log_line("%s: Packet received that is too small (%zu bytes).",
iphdrlen); client_config.interface, iphdrlen);
return -2; return -2;
} }
size_t l = iphdrlen - sizeof packet.ip - sizeof packet.udp; size_t l = iphdrlen - sizeof packet.ip - sizeof packet.udp;
if (l > sizeof *payload) { if (l > sizeof *payload) {
log_error("%s: Packet received that is too long (%zu bytes).", l); log_line("%s: Packet received that is too long (%zu bytes).",
client_config.interface, l);
return -2; return -2;
} }
if (packet.udp.check && !udp_checksum(&packet)) { if (packet.udp.check && !udp_checksum(&packet)) {
log_error("%s: Packet with bad UDP checksum received. Ignoring.", log_line("%s: Packet with bad UDP checksum received. Ignoring.",
client_config.interface); client_config.interface);
return -2; return -2;
} }
if (srcaddr) if (srcaddr)
@ -239,23 +240,23 @@ static ssize_t send_dhcp_raw(struct dhcpmsg payload[static 1])
ssize_t ret = -1; ssize_t ret = -1;
int fd = get_raw_broadcast_socket(); int fd = get_raw_broadcast_socket();
if (fd < 0) { if (fd < 0) {
log_error("%s: (%s) get_raw_broadcast_socket failed", log_line("%s: (%s) get_raw_broadcast_socket failed",
client_config.interface, __func__); client_config.interface, __func__);
return ret; return ret;
} }
// Send packets that are as short as possible. // Send packets that are as short as possible.
ssize_t endloc = get_end_option_idx(payload); ssize_t endloc = get_end_option_idx(payload);
if (endloc < 0) { if (endloc < 0) {
log_error("%s: (%s) No end marker. Not sending.", log_line("%s: (%s) No end marker. Not sending.",
client_config.interface, __func__); client_config.interface, __func__);
close(fd); close(fd);
return ret; return ret;
} }
const size_t el = (size_t)endloc + 1; const size_t el = (size_t)endloc + 1;
if (el > sizeof payload->options) { if (el > sizeof payload->options) {
log_error("%s: (%s) Invalid value of endloc. Not sending.", log_line("%s: (%s) Invalid value of endloc. Not sending.",
client_config.interface, __func__); client_config.interface, __func__);
close(fd); close(fd);
return ret; return ret;
} }
@ -299,8 +300,8 @@ static ssize_t send_dhcp_raw(struct dhcpmsg payload[static 1])
}; };
memcpy(da.sll_addr, "\xff\xff\xff\xff\xff\xff", 6); memcpy(da.sll_addr, "\xff\xff\xff\xff\xff\xff", 6);
if (!carrier_isup()) { if (!carrier_isup()) {
log_error("%s: (%s) carrier down; sendto would fail", log_line("%s: (%s) carrier down; sendto would fail",
client_config.interface, __func__); client_config.interface, __func__);
ret = -99; ret = -99;
goto carrier_down; goto carrier_down;
} }
@ -308,11 +309,11 @@ static ssize_t send_dhcp_raw(struct dhcpmsg payload[static 1])
(struct sockaddr *)&da, sizeof da); (struct sockaddr *)&da, sizeof da);
if (ret < 0 || (size_t)ret != iud_len) { if (ret < 0 || (size_t)ret != iud_len) {
if (ret < 0) if (ret < 0)
log_error("%s: (%s) sendto failed: %s", client_config.interface, log_line("%s: (%s) sendto failed: %s", client_config.interface,
__func__, strerror(errno)); __func__, strerror(errno));
else else
log_error("%s: (%s) sendto short write: %z < %zu", log_line("%s: (%s) sendto short write: %zd < %zu",
client_config.interface, __func__, ret, iud_len); client_config.interface, __func__, ret, iud_len);
} }
carrier_down: carrier_down:
close(fd); close(fd);
@ -342,39 +343,39 @@ static int validate_dhcp_packet(struct client_state_t cs[static 1],
uint8_t msgtype[static 1]) uint8_t msgtype[static 1])
{ {
if (len < offsetof(struct dhcpmsg, options)) { if (len < offsetof(struct dhcpmsg, options)) {
log_warning("%s: Packet is too short to contain magic cookie. Ignoring.", log_line("%s: Packet is too short to contain magic cookie. Ignoring.",
client_config.interface); client_config.interface);
return 0; return 0;
} }
if (ntohl(packet->cookie) != DHCP_MAGIC) { if (ntohl(packet->cookie) != DHCP_MAGIC) {
log_warning("%s: Packet with bad magic number. Ignoring.", log_line("%s: Packet with bad magic number. Ignoring.",
client_config.interface); client_config.interface);
return 0; return 0;
} }
if (packet->xid != cs->xid) { if (packet->xid != cs->xid) {
log_warning("%s: Packet XID %lx does not equal our XID %lx. Ignoring.", log_line("%s: Packet XID %x does not equal our XID %x. Ignoring.",
client_config.interface, packet->xid, cs->xid); client_config.interface, packet->xid, cs->xid);
return 0; return 0;
} }
if (memcmp(packet->chaddr, client_config.arp, sizeof client_config.arp)) { if (memcmp(packet->chaddr, client_config.arp, sizeof client_config.arp)) {
log_warning("%s: Packet client MAC %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x does not equal our MAC %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x. Ignoring it.", log_line("%s: Packet client MAC %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x does not equal our MAC %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x. Ignoring it.",
client_config.interface, client_config.interface,
packet->chaddr[0], packet->chaddr[1], packet->chaddr[2], packet->chaddr[0], packet->chaddr[1], packet->chaddr[2],
packet->chaddr[3], packet->chaddr[4], packet->chaddr[5], packet->chaddr[3], packet->chaddr[4], packet->chaddr[5],
client_config.arp[0], client_config.arp[1], client_config.arp[0], client_config.arp[1],
client_config.arp[2], client_config.arp[3], client_config.arp[2], client_config.arp[3],
client_config.arp[4], client_config.arp[5]); client_config.arp[4], client_config.arp[5]);
return 0; return 0;
} }
ssize_t endloc = get_end_option_idx(packet); ssize_t endloc = get_end_option_idx(packet);
if (endloc < 0) { if (endloc < 0) {
log_warning("%s: Packet does not have an end option. Ignoring."); log_line("%s: Packet does not have an end option. Ignoring.", client_config.interface);
return 0; return 0;
} }
*msgtype = get_option_msgtype(packet); *msgtype = get_option_msgtype(packet);
if (!*msgtype) { if (!*msgtype) {
log_warning("%s: Packet does not specify a DHCP message type. Ignoring.", log_line("%s: Packet does not specify a DHCP message type. Ignoring.",
client_config.interface); client_config.interface);
return 0; return 0;
} }
char clientid[MAX_DOPT_SIZE]; char clientid[MAX_DOPT_SIZE];
@ -383,8 +384,8 @@ static int validate_dhcp_packet(struct client_state_t cs[static 1],
return 1; return 1;
if (memcmp(client_config.clientid, clientid, if (memcmp(client_config.clientid, clientid,
min_size_t(cidlen, client_config.clientid_len))) { min_size_t(cidlen, client_config.clientid_len))) {
log_warning("%s: Packet clientid does not match our clientid. Ignoring.", log_line("%s: Packet clientid does not match our clientid. Ignoring.",
client_config.interface); client_config.interface);
return 0; return 0;
} }
return 1; return 1;
@ -401,8 +402,8 @@ bool dhcp_packet_get(struct client_state_t cs[static 1],
if (r < 0) { if (r < 0) {
// Not a transient issue handled by packet collection functions. // Not a transient issue handled by packet collection functions.
if (r != -2) { if (r != -2) {
log_error("%s: Error reading from listening socket: %s. Reopening.", log_line("%s: Error reading from listening socket: %s. Reopening.",
client_config.interface, strerror(errno)); client_config.interface, strerror(errno));
stop_dhcp_listen(cs); stop_dhcp_listen(cs);
start_dhcp_listen(cs); start_dhcp_listen(cs);
} }

View File

@ -47,7 +47,7 @@ static void get_duid_path(char duidfile[static 1], size_t dlen)
if (splen < 0) if (splen < 0)
suicide("%s: snprintf failed; return=%d", __func__, splen); suicide("%s: snprintf failed; return=%d", __func__, splen);
if ((size_t)splen >= dlen) if ((size_t)splen >= dlen)
suicide("%s: snprintf dest buffer too small %d >= %u", suicide("%s: snprintf dest buffer too small %d >= %zu",
__func__, splen, sizeof dlen); __func__, splen, sizeof dlen);
} }
@ -55,7 +55,7 @@ static void get_iaid_path(char iaidfile[static 1], size_t ilen,
const uint8_t hwaddr[static 6], size_t hwaddrlen) const uint8_t hwaddr[static 6], size_t hwaddrlen)
{ {
if (hwaddrlen != 6) if (hwaddrlen != 6)
suicide("%s: Hardware address length=%u != 6 bytes", suicide("%s: Hardware address length=%zu != 6 bytes",
__func__, hwaddrlen); __func__, hwaddrlen);
int splen = snprintf int splen = snprintf
(iaidfile, ilen, (iaidfile, ilen,
@ -65,7 +65,7 @@ static void get_iaid_path(char iaidfile[static 1], size_t ilen,
if (splen < 0) if (splen < 0)
suicide("%s: snprintf failed; return=%d", __func__, splen); suicide("%s: snprintf failed; return=%d", __func__, splen);
if ((size_t)splen >= ilen) if ((size_t)splen >= ilen)
suicide("%s: snprintf dest buffer too small %d >= %u", suicide("%s: snprintf dest buffer too small %d >= %zu",
__func__, splen, sizeof ilen); __func__, splen, sizeof ilen);
} }
@ -126,7 +126,7 @@ static size_t generate_duid(struct nk_random_state s[static 1],
{ {
const size_t tlen = sizeof(uint16_t) + 4 * sizeof(uint32_t); const size_t tlen = sizeof(uint16_t) + 4 * sizeof(uint32_t);
if (dlen < tlen) if (dlen < tlen)
suicide("%s: dlen < %u", __func__, tlen); suicide("%s: dlen < %zu", __func__, tlen);
size_t off = 0; size_t off = 0;
uint16_t typefield = htons(4); uint16_t typefield = htons(4);
@ -147,7 +147,7 @@ static size_t generate_iaid(struct nk_random_state s[static 1],
char dest[static 1], size_t dlen) char dest[static 1], size_t dlen)
{ {
if (dlen < sizeof(uint32_t)) if (dlen < sizeof(uint32_t))
suicide("%s: dlen < %u", __func__, sizeof(uint32_t)); suicide("%s: dlen < %zu", __func__, sizeof(uint32_t));
size_t off = 0; size_t off = 0;
uint32_t r32 = nk_random_u32(s); uint32_t r32 = nk_random_u32(s);
@ -204,7 +204,7 @@ void get_clientid(struct client_state_t cs[static 1],
const uint8_t cid_type = 255; const uint8_t cid_type = 255;
size_t cdl = sizeof cid_type + iaid_len + duid_len; size_t cdl = sizeof cid_type + iaid_len + duid_len;
if (cdl > sizeof cc->clientid) if (cdl > sizeof cc->clientid)
suicide("%s: (%s) clientid length %u > %u", suicide("%s: (%s) clientid length %zu > %zu",
cc->interface, __func__, cdl, sizeof cc->clientid); cc->interface, __func__, cdl, sizeof cc->clientid);
uint8_t cid_len = 0; uint8_t cid_len = 0;

View File

@ -52,26 +52,26 @@ static int ifcmd_raw(char buf[static 1], size_t buflen,
char *optdata, size_t optlen) char *optdata, size_t optlen)
{ {
if (!optdata) { if (!optdata) {
log_warning("%s: (%s) '%s' option has no data", log_line("%s: (%s) '%s' option has no data",
client_config.interface, __func__, optname); client_config.interface, __func__, optname);
return -1; return -1;
} }
if (optlen > INT_MAX) { if (optlen > INT_MAX) {
log_warning("%s: (%s) '%s' option optlen out of bounds", log_line("%s: (%s) '%s' option optlen out of bounds",
client_config.interface, __func__, optname); client_config.interface, __func__, optname);
return -1; return -1;
} }
if (buflen < strlen(optname) + optlen + 3) { if (buflen < strlen(optname) + optlen + 3) {
log_warning("%s: (%s) '%s' option buf too short", log_line("%s: (%s) '%s' option buf too short",
client_config.interface, __func__, optname); client_config.interface, __func__, optname);
return -1; return -1;
} }
int ioptlen = (int)optlen; int ioptlen = (int)optlen;
ssize_t olen = snprintf(buf, buflen, "%s:%.*s;", ssize_t olen = snprintf(buf, buflen, "%s:%.*s;",
optname, ioptlen, optdata); optname, ioptlen, optdata);
if (olen < 0 || (size_t)olen >= buflen) { if (olen < 0 || (size_t)olen >= buflen) {
log_warning("%s: (%s) '%s' option would truncate, so it was dropped.", log_line("%s: (%s) '%s' option would truncate, so it was dropped.",
client_config.interface, __func__, optname); client_config.interface, __func__, optname);
memset(buf, 0, buflen); memset(buf, 0, buflen);
return -1; return -1;
} }
@ -187,8 +187,8 @@ static int ifchd_cmd(char b[static 1], size_t bl, uint8_t *od,
case DCODE_IPTTL: return ifcmd_u8(b, bl, "ipttl", od, ol); case DCODE_IPTTL: return ifcmd_u8(b, bl, "ipttl", od, ol);
default: break; default: break;
} }
log_warning("%s: Invalid option code (%c) for ifchd cmd.", log_line("%s: Invalid option code (%c) for ifchd cmd.",
client_config.interface, code); client_config.interface, code);
return -1; return -1;
} }
@ -196,7 +196,7 @@ static int ifchwrite(const char buf[static 1], size_t count)
{ {
ssize_t r = safe_write(ifchSock[0], buf, count); ssize_t r = safe_write(ifchSock[0], buf, count);
if (r < 0 || (size_t)r != count) { if (r < 0 || (size_t)r != count) {
log_error("%s: (%s) write failed: %d", client_config.interface, __func__, r); log_line("%s: (%s) write failed: %zd", client_config.interface, __func__, r);
return -1; return -1;
} }
char data[256], control[256]; char data[256], control[256];
@ -304,8 +304,8 @@ static size_t send_client_ip(char out[static 1], size_t olen,
snlen = snprintf(out, olen, "ip4:%s,%s;", ip, sn); snlen = snprintf(out, olen, "ip4:%s,%s;", ip, sn);
} }
if (snlen < 0 || (size_t)snlen >= olen) { if (snlen < 0 || (size_t)snlen >= olen) {
log_warning("%s: (%s) ip4 command would truncate so it was dropped.", log_line("%s: (%s) ip4 command would truncate so it was dropped.",
client_config.interface, __func__); client_config.interface, __func__);
memset(out, 0, olen); memset(out, 0, olen);
return 0; return 0;
} }

View File

@ -198,13 +198,13 @@ int execute_buffer(const char newbuf[static 1])
ssize_t buflen = snprintf(buf, sizeof buf, "%s%s", cl.ibuf, newbuf); ssize_t buflen = snprintf(buf, sizeof buf, "%s%s", cl.ibuf, newbuf);
if (buflen < 0) { if (buflen < 0) {
log_error("%s: (%s) snprintf1 failed; your system is broken?", log_line("%s: (%s) snprintf1 failed; your system is broken?",
client_config.interface, __func__); client_config.interface, __func__);
return -99; return -99;
} }
if ((size_t)buflen >= sizeof buf) { if ((size_t)buflen >= sizeof buf) {
log_error("%s: (%s) input is too long for buffer", log_line("%s: (%s) input is too long for buffer",
client_config.interface, __func__); client_config.interface, __func__);
return -99; return -99;
} }
@ -224,20 +224,20 @@ int execute_buffer(const char newbuf[static 1])
size_t taken = init_siz - bytes_left; size_t taken = init_siz - bytes_left;
ssize_t ilen = snprintf(cl.ibuf, sizeof cl.ibuf, "%s", buf + taken); ssize_t ilen = snprintf(cl.ibuf, sizeof cl.ibuf, "%s", buf + taken);
if (ilen < 0) { if (ilen < 0) {
log_error("%s: (%s) snprintf2 failed; your system is broken?", log_line("%s: (%s) snprintf2 failed; your system is broken?",
client_config.interface, __func__); client_config.interface, __func__);
return -99; return -99;
} }
if ((size_t)ilen >= sizeof buf) { if ((size_t)ilen >= sizeof buf) {
log_error("%s: (%s) unconsumed input too long for buffer", log_line("%s: (%s) unconsumed input too long for buffer",
client_config.interface, __func__); client_config.interface, __func__);
return -99; return -99;
} }
} }
if (cs < ifchd_parser_first_final) { if (cs < ifchd_parser_first_final) {
log_error("%s: ifch received invalid commands", log_line("%s: ifch received invalid commands",
client_config.interface); client_config.interface);
return -99; return -99;
} }
return !cmdf ? 0 : -1; return !cmdf ? 0 : -1;

View File

@ -67,7 +67,7 @@ static void writeordie(int fd, const char buf[static 1], size_t len)
{ {
ssize_t r = safe_write(fd, buf, len); ssize_t r = safe_write(fd, buf, len);
if (r < 0 || (size_t)r != len) if (r < 0 || (size_t)r != len)
suicide("%s: (%s) write failed: %d", client_config.interface, suicide("%s: (%s) write failed: %zd", client_config.interface,
__func__, r); __func__, r);
} }
@ -78,13 +78,13 @@ static int write_append_fd(int to_fd, int from_fd, const char descr[static 1])
const off_t lse = lseek(from_fd, 0, SEEK_END); const off_t lse = lseek(from_fd, 0, SEEK_END);
if (lse < 0) { if (lse < 0) {
log_warning("%s: (%s) lseek(SEEK_END) failed %s", log_line("%s: (%s) lseek(SEEK_END) failed %s",
client_config.interface, __func__, descr); client_config.interface, __func__, descr);
return -2; return -2;
} }
if (lseek(from_fd, 0, SEEK_SET) < 0) { if (lseek(from_fd, 0, SEEK_SET) < 0) {
log_warning("%s: (%s) lseek(SEEK_SET) failed %s", log_line("%s: (%s) lseek(SEEK_SET) failed %s",
client_config.interface, __func__, descr); client_config.interface, __func__, descr);
return -2; return -2;
} }
@ -131,8 +131,8 @@ static int write_resolve_conf(void)
*q++ = '\0'; *q++ = '\0';
ssize_t sl = snprintf(buf, sizeof buf, "%s", p); ssize_t sl = snprintf(buf, sizeof buf, "%s", p);
if (sl < 0 || (size_t)sl >= sizeof buf) { if (sl < 0 || (size_t)sl >= sizeof buf) {
log_warning("%s: (%s) snprintf failed appending nameservers", log_line("%s: (%s) snprintf failed appending nameservers",
client_config.interface, __func__); client_config.interface, __func__);
} }
writeordie(resolv_conf_fd, ns_str, strlen(ns_str)); writeordie(resolv_conf_fd, ns_str, strlen(ns_str));
@ -152,8 +152,8 @@ static int write_resolve_conf(void)
*q++ = '\0'; *q++ = '\0';
ssize_t sl = snprintf(buf, sizeof buf, "%s", p); ssize_t sl = snprintf(buf, sizeof buf, "%s", p);
if (sl < 0 || (size_t)sl >= sizeof buf) { if (sl < 0 || (size_t)sl >= sizeof buf) {
log_warning("%s: (%s) snprintf failed appending domains", log_line("%s: (%s) snprintf failed appending domains",
client_config.interface, __func__); client_config.interface, __func__);
} }
if (numdoms == 0) { if (numdoms == 0) {
@ -213,13 +213,13 @@ int perform_dns(const char str[static 1], size_t len)
return 0; return 0;
int ret = -1; int ret = -1;
if (len > sizeof cl.namesvrs) { if (len > sizeof cl.namesvrs) {
log_line("DNS server list is too long: %zu > %zu", len, cl.namesvrs); log_line("DNS server list is too long: %zu > %zu", len, sizeof cl.namesvrs);
return ret; return ret;
} }
ssize_t sl = snprintf(cl.namesvrs, sizeof cl.namesvrs, "%s", str); ssize_t sl = snprintf(cl.namesvrs, sizeof cl.namesvrs, "%s", str);
if (sl < 0 || (size_t)sl >= sizeof cl.namesvrs) { if (sl < 0 || (size_t)sl >= sizeof cl.namesvrs) {
log_warning("%s: (%s) snprintf failed", log_line("%s: (%s) snprintf failed",
client_config.interface, __func__); client_config.interface, __func__);
} }
ret = write_resolve_conf(); ret = write_resolve_conf();
if (ret >= 0) if (ret >= 0)
@ -255,13 +255,13 @@ int perform_domain(const char str[static 1], size_t len)
return 0; return 0;
int ret = -1; int ret = -1;
if (len > sizeof cl.domains) { if (len > sizeof cl.domains) {
log_line("DNS domain list is too long: %zu > %zu", len, cl.namesvrs); log_line("DNS domain list is too long: %zu > %zu", len, sizeof cl.namesvrs);
return ret; return ret;
} }
ssize_t sl = snprintf(cl.domains, sizeof cl.domains, "%s", str); ssize_t sl = snprintf(cl.domains, sizeof cl.domains, "%s", str);
if (sl < 0 || (size_t)sl >= sizeof cl.domains) { if (sl < 0 || (size_t)sl >= sizeof cl.domains) {
log_warning("%s: (%s) snprintf failed", log_line("%s: (%s) snprintf failed",
client_config.interface, __func__); client_config.interface, __func__);
} }
ret = write_resolve_conf(); ret = write_resolve_conf();
if (ret <= 0) if (ret <= 0)
@ -378,13 +378,13 @@ static void setup_resolv_conf(void)
ssize_t sl = snprintf(buf, sizeof buf, "%s.head", resolv_conf_d); ssize_t sl = snprintf(buf, sizeof buf, "%s.head", resolv_conf_d);
if (sl < 0 || (size_t)sl >= sizeof buf) if (sl < 0 || (size_t)sl >= sizeof buf)
log_warning("snprintf failed appending resolv_conf_head; path too long?"); log_line("snprintf failed appending resolv_conf_head; path too long?");
else else
resolv_conf_head_fd = open(buf, O_RDONLY|O_CLOEXEC, 0); resolv_conf_head_fd = open(buf, O_RDONLY|O_CLOEXEC, 0);
sl = snprintf(buf, sizeof buf, "%s.tail", resolv_conf_d); sl = snprintf(buf, sizeof buf, "%s.tail", resolv_conf_d);
if (sl < 0 || (size_t)sl >= sizeof buf) if (sl < 0 || (size_t)sl >= sizeof buf)
log_warning("snprintf failed appending resolv_conf_tail; path too long?"); log_line("snprintf failed appending resolv_conf_tail; path too long?");
else else
resolv_conf_tail_fd = open(buf, O_RDONLY|O_CLOEXEC, 0); resolv_conf_tail_fd = open(buf, O_RDONLY|O_CLOEXEC, 0);

View File

@ -93,11 +93,11 @@ static ssize_t rtnl_do_send(int fd, const uint8_t *sbuf, size_t slen,
(struct sockaddr *)&nl_addr, sizeof nl_addr); (struct sockaddr *)&nl_addr, sizeof nl_addr);
if (r < 0 || (size_t)r != slen) { if (r < 0 || (size_t)r != slen) {
if (r < 0) if (r < 0)
log_error("%s: (%s) netlink sendto failed: %s", log_line("%s: (%s) netlink sendto failed: %s",
client_config.interface, fnname, strerror(errno)); client_config.interface, fnname, strerror(errno));
else else
log_error("%s: (%s) netlink sendto short write: %z < %zu", log_line("%s: (%s) netlink sendto short write: %zd < %zu",
client_config.interface, fnname, r, slen); client_config.interface, fnname, r, slen);
return -1; return -1;
} }
struct iovec iov = { struct iovec iov = {
@ -112,13 +112,13 @@ static ssize_t rtnl_do_send(int fd, const uint8_t *sbuf, size_t slen,
}; };
r = safe_recvmsg(fd, &msg, 0); r = safe_recvmsg(fd, &msg, 0);
if (r < 0) { if (r < 0) {
log_error("%s: (%s) netlink recvmsg failed: %s", log_line("%s: (%s) netlink recvmsg failed: %s",
client_config.interface, fnname, strerror(errno)); client_config.interface, fnname, strerror(errno));
return -1; return -1;
} }
if (msg.msg_flags & MSG_TRUNC) { if (msg.msg_flags & MSG_TRUNC) {
log_error("%s: (%s) Buffer not long enough for message.", log_line("%s: (%s) Buffer not long enough for message.",
client_config.interface, fnname); client_config.interface, fnname);
return -1; return -1;
} }
if ((size_t)r < sizeof(struct nlmsghdr)) { if ((size_t)r < sizeof(struct nlmsghdr)) {
@ -137,15 +137,15 @@ static ssize_t rtnl_do_send(int fd, const uint8_t *sbuf, size_t slen,
client_config.interface, fnname, nlerr); client_config.interface, fnname, nlerr);
return -3; return -3;
} }
log_error("%s: (%s) netlink sendto returned NLMSG_ERROR: %s", log_line("%s: (%s) netlink sendto returned NLMSG_ERROR: %s",
client_config.interface, fnname, strerror(nlerr)); client_config.interface, fnname, strerror(nlerr));
return -1; return -1;
} }
} }
if (nlh->nlmsg_type == NLMSG_DONE) if (nlh->nlmsg_type == NLMSG_DONE)
return -2; return -2;
log_error("%s: (%s) netlink sendto returned an error.", log_line("%s: (%s) netlink sendto returned an error.",
client_config.interface, __func__); client_config.interface, __func__);
return -1; return -1;
} }
@ -182,8 +182,8 @@ static ssize_t rtnl_addr_broadcast_send(int fd, int type, int ifa_flags,
struct ifaddrmsg *ifaddrmsg; struct ifaddrmsg *ifaddrmsg;
if (!ipaddr && !bcast) { if (!ipaddr && !bcast) {
log_warning("%s: (%s) no ipaddr or bcast!", log_line("%s: (%s) no ipaddr or bcast!",
client_config.interface, __func__); client_config.interface, __func__);
return -1; return -1;
} }
@ -205,16 +205,16 @@ static ssize_t rtnl_addr_broadcast_send(int fd, int type, int ifa_flags,
if (ipaddr) { if (ipaddr) {
if (nl_add_rtattr(header, sizeof request, IFA_LOCAL, if (nl_add_rtattr(header, sizeof request, IFA_LOCAL,
ipaddr, sizeof *ipaddr) < 0) { ipaddr, sizeof *ipaddr) < 0) {
log_error("%s: (%s) couldn't add IFA_LOCAL to nlmsg", log_line("%s: (%s) couldn't add IFA_LOCAL to nlmsg",
client_config.interface, __func__); client_config.interface, __func__);
return -1; return -1;
} }
} }
if (bcast) { if (bcast) {
if (nl_add_rtattr(header, sizeof request, IFA_BROADCAST, if (nl_add_rtattr(header, sizeof request, IFA_BROADCAST,
bcast, sizeof *bcast) < 0) { bcast, sizeof *bcast) < 0) {
log_error("%s: (%s) couldn't add IFA_BROADCAST to nlmsg", log_line("%s: (%s) couldn't add IFA_BROADCAST to nlmsg",
client_config.interface, __func__); client_config.interface, __func__);
return -1; return -1;
} }
} }
@ -248,28 +248,28 @@ static ssize_t rtnl_set_default_gw_v4(int fd, uint32_t gw4, int metric)
uint32_t dstaddr4 = 0; uint32_t dstaddr4 = 0;
if (nl_add_rtattr(header, sizeof request, RTA_DST, if (nl_add_rtattr(header, sizeof request, RTA_DST,
&dstaddr4, sizeof dstaddr4) < 0) { &dstaddr4, sizeof dstaddr4) < 0) {
log_error("%s: (%s) couldn't add RTA_DST to nlmsg", log_line("%s: (%s) couldn't add RTA_DST to nlmsg",
client_config.interface, __func__); client_config.interface, __func__);
return -1; return -1;
} }
if (nl_add_rtattr(header, sizeof request, RTA_OIF, if (nl_add_rtattr(header, sizeof request, RTA_OIF,
&client_config.ifindex, &client_config.ifindex,
sizeof client_config.ifindex) < 0) { sizeof client_config.ifindex) < 0) {
log_error("%s: (%s) couldn't add RTA_OIF to nlmsg", log_line("%s: (%s) couldn't add RTA_OIF to nlmsg",
client_config.interface, __func__); client_config.interface, __func__);
return -1; return -1;
} }
if (nl_add_rtattr(header, sizeof request, RTA_GATEWAY, if (nl_add_rtattr(header, sizeof request, RTA_GATEWAY,
&gw4, sizeof gw4) < 0) { &gw4, sizeof gw4) < 0) {
log_error("%s: (%s) couldn't add RTA_GATEWAY to nlmsg", log_line("%s: (%s) couldn't add RTA_GATEWAY to nlmsg",
client_config.interface, __func__); client_config.interface, __func__);
return -1; return -1;
} }
if (metric > 0) { if (metric > 0) {
if (nl_add_rtattr(header, sizeof request, RTA_PRIORITY, if (nl_add_rtattr(header, sizeof request, RTA_PRIORITY,
&metric, sizeof metric) < 0) { &metric, sizeof metric) < 0) {
log_error("%s: (%s) couldn't add RTA_PRIORITY to nlmsg", log_line("%s: (%s) couldn't add RTA_PRIORITY to nlmsg",
client_config.interface, __func__); client_config.interface, __func__);
return -1; return -1;
} }
} }
@ -333,8 +333,8 @@ int perform_carrier(void)
uint32_t flags; uint32_t flags;
int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE); int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE);
if (fd < 0) { if (fd < 0) {
log_error("%s: (%s) netlink socket open failed: %s", log_line("%s: (%s) netlink socket open failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto fail; goto fail;
} }
@ -359,8 +359,8 @@ static int link_set_flags(int fd, uint32_t flags)
int r = link_flags_get(fd, &oldflags); int r = link_flags_get(fd, &oldflags);
if (r < 0) { if (r < 0) {
log_error("%s: (%s) failed to get old link flags: %u", log_line("%s: (%s) failed to get old link flags: %u",
client_config.interface, __func__, r); client_config.interface, __func__, r);
return -1; return -1;
} }
if ((oldflags & flags) == flags) if ((oldflags & flags) == flags)
@ -375,8 +375,8 @@ static int link_unset_flags(int fd, uint32_t flags)
int r = link_flags_get(fd, &oldflags); int r = link_flags_get(fd, &oldflags);
if (r < 0) { if (r < 0) {
log_error("%s: (%s) failed to get old link flags: %u", log_line("%s: (%s) failed to get old link flags: %u",
client_config.interface, __func__, r); client_config.interface, __func__, r);
return -1; return -1;
} }
if ((oldflags & flags) == 0) if ((oldflags & flags) == 0)
@ -430,8 +430,8 @@ static void ipbcpfx_clear_others_do(const struct nlmsghdr *nlh, void *data)
tb[IFA_BROADCAST] ? RTA_DATA(tb[IFA_BROADCAST]) : (uint32_t *)0, tb[IFA_BROADCAST] ? RTA_DATA(tb[IFA_BROADCAST]) : (uint32_t *)0,
ifm->ifa_prefixlen); ifm->ifa_prefixlen);
if (r < 0 && r != -2) { if (r < 0 && r != -2) {
log_warning("%s: (%s) Failed to delete IP and broadcast addresses.", log_line("%s: (%s) Failed to delete IP and broadcast addresses.",
client_config.interface, __func__); client_config.interface, __func__);
} }
return; return;
} }
@ -469,8 +469,8 @@ static ssize_t rtnl_if_mtu_set(int fd, unsigned int mtu)
int r = link_flags_get(fd, &oldflags); int r = link_flags_get(fd, &oldflags);
if (r < 0) { if (r < 0) {
log_error("%s: (%s) failed to get old link flags: %u", log_line("%s: (%s) failed to get old link flags: %u",
client_config.interface, __func__, r); client_config.interface, __func__, r);
return -1; return -1;
} }
@ -488,8 +488,8 @@ static ssize_t rtnl_if_mtu_set(int fd, unsigned int mtu)
if (nl_add_rtattr(header, sizeof request, IFLA_MTU, if (nl_add_rtattr(header, sizeof request, IFLA_MTU,
&mtu, sizeof mtu) < 0) { &mtu, sizeof mtu) < 0) {
log_error("%s: (%s) couldn't add IFLA_MTU to nlmsg", log_line("%s: (%s) couldn't add IFLA_MTU to nlmsg",
client_config.interface, __func__); client_config.interface, __func__);
return -1; return -1;
} }
@ -508,8 +508,8 @@ int perform_ifup(void)
int r = link_set_flags(fd, IFF_UP); int r = link_set_flags(fd, IFF_UP);
if (r < 0) { if (r < 0) {
if (r != -3) if (r != -3)
log_error("%s: (%s) Failed to set link to be up.", log_line("%s: (%s) Failed to set link to be up.",
client_config.interface, __func__); client_config.interface, __func__);
else else
log_line("%s: (%s) rfkill is set; waiting until it is unset", log_line("%s: (%s) rfkill is set; waiting until it is unset",
client_config.interface, __func__); client_config.interface, __func__);
@ -528,22 +528,22 @@ int perform_ip_subnet_bcast(const char str_ipaddr[static 1],
uint8_t prefixlen; uint8_t prefixlen;
if (inet_pton(AF_INET, str_ipaddr, &ipaddr) <= 0) { if (inet_pton(AF_INET, str_ipaddr, &ipaddr) <= 0) {
log_error("%s: (%s) bad interface ip address: '%s'", log_line("%s: (%s) bad interface ip address: '%s'",
client_config.interface, __func__, str_ipaddr); client_config.interface, __func__, str_ipaddr);
goto fail; goto fail;
} }
if (inet_pton(AF_INET, str_subnet, &subnet) <= 0) { if (inet_pton(AF_INET, str_subnet, &subnet) <= 0) {
log_error("%s: (%s) bad interface subnet address: '%s'", log_line("%s: (%s) bad interface subnet address: '%s'",
client_config.interface, __func__, str_subnet); client_config.interface, __func__, str_subnet);
goto fail; goto fail;
} }
prefixlen = subnet4_to_prefixlen(subnet.s_addr); prefixlen = subnet4_to_prefixlen(subnet.s_addr);
if (str_bcast) { if (str_bcast) {
if (inet_pton(AF_INET, str_bcast, &bcast) <= 0) { if (inet_pton(AF_INET, str_bcast, &bcast) <= 0) {
log_error("%s: (%s) bad interface broadcast address: '%s'", log_line("%s: (%s) bad interface broadcast address: '%s'",
client_config.interface, __func__, str_bcast); client_config.interface, __func__, str_bcast);
goto fail; goto fail;
} }
} else { } else {
@ -553,19 +553,19 @@ int perform_ip_subnet_bcast(const char str_ipaddr[static 1],
fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE); fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE);
if (fd < 0) { if (fd < 0) {
log_error("%s: (%s) netlink socket open failed: %s", log_line("%s: (%s) netlink socket open failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto fail; goto fail;
} }
r = ipbcpfx_clear_others(fd, ipaddr.s_addr, bcast.s_addr, prefixlen); r = ipbcpfx_clear_others(fd, ipaddr.s_addr, bcast.s_addr, prefixlen);
if (r < 0 && r > -3) { if (r < 0 && r > -3) {
if (r == -1) if (r == -1)
log_error("%s: (%s) error requesting link ip address list", log_line("%s: (%s) error requesting link ip address list",
client_config.interface, __func__); client_config.interface, __func__);
else if (r == -2) else if (r == -2)
log_error("%s: (%s) error receiving link ip address list", log_line("%s: (%s) error receiving link ip address list",
client_config.interface, __func__); client_config.interface, __func__);
goto fail_fd; goto fail_fd;
} }
@ -589,8 +589,8 @@ int perform_ip_subnet_bcast(const char str_ipaddr[static 1],
if (link_set_flags(fd, IFF_UP | IFF_RUNNING) < 0) { if (link_set_flags(fd, IFF_UP | IFF_RUNNING) < 0) {
ret = -1; ret = -1;
log_error("%s: (%s) Failed to set link to be up and running.", log_line("%s: (%s) Failed to set link to be up and running.",
client_config.interface, __func__); client_config.interface, __func__);
goto fail_fd; goto fail_fd;
} }
ret = 0; ret = 0;
@ -608,21 +608,21 @@ int perform_router(const char str_router[static 1], size_t len)
goto fail; goto fail;
struct in_addr router; struct in_addr router;
if (inet_pton(AF_INET, str_router, &router) <= 0) { if (inet_pton(AF_INET, str_router, &router) <= 0) {
log_error("%s: (%s) bad router ip address: '%s'", log_line("%s: (%s) bad router ip address: '%s'",
client_config.interface, __func__, str_router); client_config.interface, __func__, str_router);
goto fail; goto fail;
} }
int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE); int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE);
if (fd < 0) { if (fd < 0) {
log_error("%s: (%s) netlink socket open failed: %s", log_line("%s: (%s) netlink socket open failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto fail; goto fail;
} }
if (rtnl_set_default_gw_v4(fd, router.s_addr, client_config.metric) < 0) { if (rtnl_set_default_gw_v4(fd, router.s_addr, client_config.metric) < 0) {
log_error("%s: (%s) failed to set route: %s", log_line("%s: (%s) failed to set route: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto fail_fd; goto fail_fd;
} }
log_line("%s: Gateway router set to: '%s'", client_config.interface, log_line("%s: Gateway router set to: '%s'", client_config.interface,
@ -644,38 +644,38 @@ int perform_mtu(const char str[static 1], size_t len)
char *estr; char *estr;
long tmtu = strtol(str, &estr, 10); long tmtu = strtol(str, &estr, 10);
if (estr == str) { if (estr == str) {
log_error("%s: (%s) provided mtu arg isn't a valid number", log_line("%s: (%s) provided mtu arg isn't a valid number",
client_config.interface, __func__); client_config.interface, __func__);
goto fail; goto fail;
} }
if ((tmtu == LONG_MAX || tmtu == LONG_MIN) && errno == ERANGE) { if ((tmtu == LONG_MAX || tmtu == LONG_MIN) && errno == ERANGE) {
log_error("%s: (%s) provided mtu arg would overflow a long", log_line("%s: (%s) provided mtu arg would overflow a long",
client_config.interface, __func__); client_config.interface, __func__);
goto fail; goto fail;
} }
if (tmtu > INT_MAX) { if (tmtu > INT_MAX) {
log_error("%s: (%s) provided mtu arg would overflow int", log_line("%s: (%s) provided mtu arg would overflow int",
client_config.interface, __func__); client_config.interface, __func__);
goto fail; goto fail;
} }
// 68 bytes for IPv4. 1280 bytes for IPv6. // 68 bytes for IPv4. 1280 bytes for IPv6.
if (tmtu < 68) { if (tmtu < 68) {
log_error("%s: (%s) provided mtu arg (%ul) less than minimum MTU (68)", log_line("%s: (%s) provided mtu arg (%ld) less than minimum MTU (68)",
client_config.interface, __func__, tmtu); client_config.interface, __func__, tmtu);
goto fail; goto fail;
} }
mtu = (unsigned int)tmtu; mtu = (unsigned int)tmtu;
fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE); fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE);
if (fd < 0) { if (fd < 0) {
log_error("%s: (%s) netlink socket open failed: %s", log_line("%s: (%s) netlink socket open failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto fail; goto fail;
} }
if (rtnl_if_mtu_set(fd, mtu) < 0) { if (rtnl_if_mtu_set(fd, mtu) < 0) {
log_error("%s: (%s) failed to set MTU [%d]", log_line("%s: (%s) failed to set MTU [%d]",
client_config.interface, __func__, mtu); client_config.interface, __func__, mtu);
goto fail_fd; goto fail_fd;
} }
log_line("%s: MTU set to: '%s'", client_config.interface, str); log_line("%s: MTU set to: '%s'", client_config.interface, str);

View File

@ -52,7 +52,7 @@ static void get_leasefile_path(char *leasefile, size_t dlen, char *ifname)
suicide("%s: (%s) snprintf failed; return=%d", suicide("%s: (%s) snprintf failed; return=%d",
client_config.interface, __func__, splen); client_config.interface, __func__, splen);
if ((size_t)splen >= dlen) if ((size_t)splen >= dlen)
suicide("%s: (%s) snprintf dest buffer too small %d >= %u", suicide("%s: (%s) snprintf dest buffer too small %d >= %zu",
client_config.interface, __func__, splen, sizeof dlen); client_config.interface, __func__, splen, sizeof dlen);
} }
@ -71,32 +71,32 @@ void write_leasefile(struct in_addr ipnum)
char ip[INET_ADDRSTRLEN]; char ip[INET_ADDRSTRLEN];
char out[INET_ADDRSTRLEN*2]; char out[INET_ADDRSTRLEN*2];
if (leasefilefd < 0) { if (leasefilefd < 0) {
log_error("%s: (%s) leasefile fd < 0; no leasefile will be written", log_line("%s: (%s) leasefile fd < 0; no leasefile will be written",
client_config.interface, __func__); client_config.interface, __func__);
return; return;
} }
inet_ntop(AF_INET, &ipnum, ip, sizeof ip); inet_ntop(AF_INET, &ipnum, ip, sizeof ip);
ssize_t olen = snprintf(out, sizeof out, "%s\n", ip); ssize_t olen = snprintf(out, sizeof out, "%s\n", ip);
if (olen < 0 || (size_t)olen >= sizeof ip) { if (olen < 0 || (size_t)olen >= sizeof ip) {
log_error("%s: (%s) snprintf failed; return=%d", log_line("%s: (%s) snprintf failed; return=%zd",
client_config.interface, __func__, olen); client_config.interface, __func__, olen);
return; return;
} }
if (safe_ftruncate(leasefilefd, 0)) { if (safe_ftruncate(leasefilefd, 0)) {
log_warning("%s: (%s) Failed to truncate lease file: %s", log_line("%s: (%s) Failed to truncate lease file: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
return; return;
} }
if (lseek(leasefilefd, 0, SEEK_SET) == (off_t)-1) { if (lseek(leasefilefd, 0, SEEK_SET) == (off_t)-1) {
log_warning("%s: (%s) Failed to seek to start of lease file: %s", log_line("%s: (%s) Failed to seek to start of lease file: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
return; return;
} }
size_t outlen = strlen(out); size_t outlen = strlen(out);
ssize_t ret = safe_write(leasefilefd, out, outlen); ssize_t ret = safe_write(leasefilefd, out, outlen);
if (ret < 0 || (size_t)ret != outlen) if (ret < 0 || (size_t)ret != outlen)
log_warning("%s: (%s) Failed to write ip to lease file.", log_line("%s: (%s) Failed to write ip to lease file.",
client_config.interface, __func__); client_config.interface, __func__);
else else
fsync(leasefilefd); fsync(leasefilefd);
} }

View File

@ -50,12 +50,12 @@ static bool nk_getrandom(char *seed, size_t len)
if (r <= 0) { if (r <= 0) {
if (r == 0) { if (r == 0) {
// Failsafe to guard against infinite loops. // Failsafe to guard against infinite loops.
log_warning("%s: getrandom() returned no entropy", __func__); log_line("%s: getrandom() returned no entropy", __func__);
return false; return false;
} }
if (errno == EINTR) if (errno == EINTR)
continue; continue;
log_warning("%s: getrandom() failed: %s", __func__, strerror(errno)); log_line("%s: getrandom() failed: %s", __func__, strerror(errno));
return false; return false;
} }
fetched += (size_t)r; fetched += (size_t)r;
@ -76,8 +76,8 @@ static bool nk_get_rnd_clk(char *seed, size_t len)
for (size_t i = 0; i < len; ++i) { for (size_t i = 0; i < len; ++i) {
int r = clock_gettime(CLOCK_REALTIME, &ts); int r = clock_gettime(CLOCK_REALTIME, &ts);
if (r < 0) { if (r < 0) {
log_warning("%s: Could not call clock_gettime(CLOCK_REALTIME): %s", log_line("%s: Could not call clock_gettime(CLOCK_REALTIME): %s",
__func__, strerror(errno)); __func__, strerror(errno));
return false; return false;
} }
char *p = (char *)&ts.tv_sec; char *p = (char *)&ts.tv_sec;
@ -97,16 +97,16 @@ static bool nk_get_urandom(char *seed, size_t len)
{ {
int fd = open("/dev/urandom", O_RDONLY); int fd = open("/dev/urandom", O_RDONLY);
if (fd < 0) { if (fd < 0) {
log_warning("%s: Could not open /dev/urandom: %s", __func__, log_line("%s: Could not open /dev/urandom: %s", __func__,
strerror(errno)); strerror(errno));
return false; return false;
} }
bool ret = true; bool ret = true;
int r = safe_read(fd, seed, len); int r = safe_read(fd, seed, len);
if (r < 0) { if (r < 0) {
ret = false; ret = false;
log_warning("%s: Could not read /dev/urandom: %s", log_line("%s: Could not read /dev/urandom: %s",
__func__, strerror(errno)); __func__, strerror(errno));
} }
close(fd); close(fd);
return ret; return ret;
@ -119,8 +119,8 @@ void nk_get_hwrng(void *seed, size_t len)
return; return;
if (nk_get_urandom(s, len)) if (nk_get_urandom(s, len))
return; return;
log_warning("%s: Seeding PRNG via system clock. May be predictable.", log_line("%s: Seeding PRNG via system clock. May be predictable.",
__func__); __func__);
if (nk_get_rnd_clk(s, len)) if (nk_get_rnd_clk(s, len))
return; return;
suicide("%s: All methods to seed PRNG failed. Exiting.", __func__); suicide("%s: All methods to seed PRNG failed. Exiting.", __func__);

View File

@ -1,82 +0,0 @@
/* log.c - simple logging support
*
* Copyright 2003-2018 Nicholas J. Kain <njkain at gmail dot com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <strings.h>
#include <stdarg.h>
#include <stdlib.h>
#include "nk/log.h"
/* global logging flags */
int gflags_quiet = 0;
int gflags_detach = 0;
int gflags_debug = 0;
char *gflags_log_name = 0;
#define log_syslog(level) do { \
openlog(gflags_log_name, LOG_PID, LOG_DAEMON); \
va_start(argp, format); \
vsyslog(level | LOG_DAEMON, format, argp); \
va_end(argp); \
closelog(); } while(0)
#define log_stdio() do { \
va_start(argp, format); \
vfprintf(stderr, format, argp); \
fprintf(stderr, "\n"); \
va_end(argp); } while(0)
__attribute__ ((format (printf, 2, 3)))
void log_line_l(int level, const char format[static 1], ...)
{
va_list argp;
if (gflags_quiet)
return;
if (gflags_detach)
log_syslog(level);
else
log_stdio();
}
__attribute__ ((format (printf, 1, 2)))
void __attribute__((noreturn)) suicide(const char format[static 1], ...)
{
va_list argp;
if (gflags_detach)
log_syslog(LOG_ERR);
else
log_stdio();
exit(EXIT_FAILURE);
}
#undef log_syslog
#undef log_stdio

View File

@ -71,8 +71,8 @@ static size_t nk_get_capability_vinfo(uint32_t version[static 1])
case _LINUX_CAPABILITY_VERSION_2: case _LINUX_CAPABILITY_VERSION_2:
*version = _LINUX_CAPABILITY_VERSION_2; *version = _LINUX_CAPABILITY_VERSION_2;
return _LINUX_CAPABILITY_U32S_2; return _LINUX_CAPABILITY_U32S_2;
default: log_warning("%s: unknown capability version %x, using %x", default: log_line("%s: unknown capability version %x, using %x",
__func__, *version, _LINUX_CAPABILITY_VERSION_3); __func__, *version, _LINUX_CAPABILITY_VERSION_3);
case _LINUX_CAPABILITY_VERSION_3: case _LINUX_CAPABILITY_VERSION_3:
*version = _LINUX_CAPABILITY_VERSION_3; *version = _LINUX_CAPABILITY_VERSION_3;
return _LINUX_CAPABILITY_U32S_3; return _LINUX_CAPABILITY_U32S_3;
@ -105,8 +105,8 @@ static void nk_set_capability_epilogue(const unsigned char *caps,
for (size_t i = 0; i < caplen; ++i) { for (size_t i = 0; i < caplen; ++i) {
size_t j = caps[i] / 32; size_t j = caps[i] / 32;
if (j >= csize) if (j >= csize)
suicide("%s: caps[%zu] == %u, which is >= %u and out of range", suicide("%s: caps[%zu] == %d, which is >= %zu and out of range",
__func__, caps[i], csize * 32); __func__, i, caps[i], csize * 32);
mask[j] |= (uint32_t)CAP_TO_MASK(caps[i] - 32 * j); mask[j] |= (uint32_t)CAP_TO_MASK(caps[i] - 32 * j);
} }
for (size_t i = 0; i < csize; ++i) { for (size_t i = 0; i < csize; ++i) {

View File

@ -115,7 +115,7 @@ static int get_if_index_and_mac(const struct nlmsghdr *nlh,
sizeof client_config.interface)) { sizeof client_config.interface)) {
client_config.ifindex = ifm->ifi_index; client_config.ifindex = ifm->ifi_index;
if (!tb[IFLA_ADDRESS]) if (!tb[IFLA_ADDRESS])
suicide("FATAL: Adapter %s lacks a hardware address."); suicide("FATAL: Adapter %s lacks a hardware address.", client_config.interface);
int maclen = tb[IFLA_ADDRESS]->rta_len - 4; int maclen = tb[IFLA_ADDRESS]->rta_len - 4;
if (maclen != 6) if (maclen != 6)
suicide("FATAL: Adapter hardware address length should be 6, but is %u.", suicide("FATAL: Adapter hardware address length should be 6, but is %u.",

View File

@ -1,6 +1,6 @@
/* log.h - simple logging support /* log.h - simple logging support
* *
* Copyright 2003-2015 Nicholas J. Kain <njkain at gmail dot com> * Copyright 2003-2020 Nicholas J. Kain <njkain at gmail dot com>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -29,20 +29,25 @@
#ifndef NCM_LOG_H_ #ifndef NCM_LOG_H_
#define NCM_LOG_H_ #define NCM_LOG_H_
#include <syslog.h> #include <stdlib.h>
#include <stdio.h>
extern int gflags_quiet; #define log_line(...) do { \
extern int gflags_detach; dprintf(2, __VA_ARGS__); \
extern int gflags_debug; dprintf(2, "\n"); } while (0)
extern char *gflags_log_name;
#define log_line(...) log_line_l(LOG_INFO, __VA_ARGS__) #ifndef NDEBUG
#define log_debug(...) if (gflags_debug) log_line_l(LOG_DEBUG, __VA_ARGS__) #define log_debug(...) do { \
#define log_warning(...) log_line_l(LOG_WARNING, __VA_ARGS__) dprintf(2, __VA_ARGS__); \
#define log_error(...) log_line_l(LOG_ERR, __VA_ARGS__) dprintf(2, "\n"); } while (0)
#else
#define log_debug(...) do {} while (0)
#endif
void log_line_l(int level, const char *format, ...); #define suicide(...) do { \
void __attribute__((noreturn)) suicide(const char *format, ...); dprintf(2, __VA_ARGS__); \
dprintf(2, "\n"); \
exit(EXIT_FAILURE); } while (0)
#endif #endif

View File

@ -99,16 +99,16 @@ ssize_t nl_recv_buf(int fd, char buf[static 1], size_t blen)
if (ret < 0) { if (ret < 0) {
if (errno == EAGAIN || errno == EWOULDBLOCK) if (errno == EAGAIN || errno == EWOULDBLOCK)
return 0; return 0;
log_error("%s: recvmsg failed: %s", __func__, strerror(errno)); log_line("%s: recvmsg failed: %s", __func__, strerror(errno));
return -1; return -1;
} }
if (msg.msg_flags & MSG_TRUNC) { if (msg.msg_flags & MSG_TRUNC) {
log_error("%s: Buffer not long enough for message.", __func__); log_line("%s: Buffer not long enough for message.", __func__);
return -1; return -1;
} }
if (msg.msg_namelen != sizeof addr) { if (msg.msg_namelen != sizeof addr) {
log_error("%s: Response was not of the same address family.", log_line("%s: Response was not of the same address family.",
__func__); __func__);
return -1; return -1;
} }
return ret; return ret;
@ -172,11 +172,11 @@ static int nl_sendgetlink_do(int fd, uint32_t seq, int ifindex, int by_ifindex)
(struct sockaddr *)&addr, sizeof addr); (struct sockaddr *)&addr, sizeof addr);
if (r < 0 || (size_t)r != nlh->nlmsg_len) { if (r < 0 || (size_t)r != nlh->nlmsg_len) {
if (r < 0) if (r < 0)
log_error("%s: sendto socket failed: %s", __func__, log_line("%s: sendto socket failed: %s", __func__,
strerror(errno)); strerror(errno));
else else
log_error("%s: sendto short write: %z < %zu", __func__, r, log_line("%s: sendto short write: %zd < %u", __func__, r,
nlh->nlmsg_len); nlh->nlmsg_len);
return -1; return -1;
} }
return 0; return 0;
@ -218,11 +218,11 @@ static int nl_sendgetaddr_do(int fd, uint32_t seq, uint32_t ifindex, int by_ifin
(struct sockaddr *)&addr, sizeof addr); (struct sockaddr *)&addr, sizeof addr);
if (r < 0 || (size_t)r != nlh->nlmsg_len) { if (r < 0 || (size_t)r != nlh->nlmsg_len) {
if (r < 0) if (r < 0)
log_error("%s: sendto socket failed: %s", __func__, log_line("%s: sendto socket failed: %s", __func__,
strerror(errno)); strerror(errno));
else else
log_error("%s: sendto short write: %z < %zu", __func__, r, log_line("%s: sendto short write: %zd < %u", __func__, r,
nlh->nlmsg_len); nlh->nlmsg_len);
return -1; return -1;
} }
return 0; return 0;
@ -263,7 +263,7 @@ int nl_open(int nltype, unsigned nlgroup, uint32_t *nlportid)
int fd; int fd;
fd = socket(AF_NETLINK, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, nltype); fd = socket(AF_NETLINK, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, nltype);
if (fd < 0) { if (fd < 0) {
log_error("%s: socket failed: %s", __func__, strerror(errno)); log_line("%s: socket failed: %s", __func__, strerror(errno));
return -1; return -1;
} }
socklen_t al; socklen_t al;
@ -272,30 +272,30 @@ int nl_open(int nltype, unsigned nlgroup, uint32_t *nlportid)
.nl_groups = nlgroup, .nl_groups = nlgroup,
}; };
if (bind(fd, (struct sockaddr *)&nlsock, sizeof nlsock) < 0) { if (bind(fd, (struct sockaddr *)&nlsock, sizeof nlsock) < 0) {
log_error("%s: bind to group failed: %s", log_line("%s: bind to group failed: %s",
__func__, strerror(errno)); __func__, strerror(errno));
goto err_close; goto err_close;
} }
al = sizeof nlsock; al = sizeof nlsock;
if (getsockname(fd, (struct sockaddr *)&nlsock, &al) < 0) { if (getsockname(fd, (struct sockaddr *)&nlsock, &al) < 0) {
log_error("%s: getsockname failed: %s", log_line("%s: getsockname failed: %s",
__func__, strerror(errno)); __func__, strerror(errno));
goto err_close; goto err_close;
} }
if (al != sizeof nlsock) { if (al != sizeof nlsock) {
log_error("%s: Bound socket doesn't have right family size.", log_line("%s: Bound socket doesn't have right family size.",
__func__); __func__);
goto err_close; goto err_close;
} }
if (nlsock.nl_family != AF_NETLINK) { if (nlsock.nl_family != AF_NETLINK) {
log_error("%s: Bound socket isn't AF_NETLINK.", log_line("%s: Bound socket isn't AF_NETLINK.",
__func__); __func__);
goto err_close; goto err_close;
} }
if (nlportid) if (nlportid)
*nlportid = nlsock.nl_pid; *nlportid = nlsock.nl_pid;
return fd; return fd;
err_close: err_close:
close(fd); close(fd);
return -1; return -1;
} }

View File

@ -129,7 +129,7 @@ ssize_t get_end_option_idx(const struct dhcpmsg * const packet)
break; break;
i += (size_t)packet->options[i+1] + 1; i += (size_t)packet->options[i+1] + 1;
} }
log_warning("get_end_option_idx: Did not find DCODE_END marker."); log_line("get_end_option_idx: Did not find DCODE_END marker.");
return -1; return -1;
} }
@ -148,17 +148,17 @@ size_t add_option_string(struct dhcpmsg *packet, uint8_t code,
{ {
size_t len = sizeof_option_str(code, slen); size_t len = sizeof_option_str(code, slen);
if (slen > 255 || len != slen + 2) { if (slen > 255 || len != slen + 2) {
log_warning("add_option_string: Length checks failed."); log_line("add_option_string: Length checks failed.");
return 0; return 0;
} }
ssize_t end = get_end_option_idx(packet); ssize_t end = get_end_option_idx(packet);
if (end < 0) { if (end < 0) {
log_warning("add_option_string: Buffer has no DCODE_END marker."); log_line("add_option_string: Buffer has no DCODE_END marker.");
return 0; return 0;
} }
if ((size_t)end + len >= sizeof packet->options) { if ((size_t)end + len >= sizeof packet->options) {
log_warning("add_option_string: No space for option 0x%02x.", code); log_line("add_option_string: No space for option 0x%02x.", code);
return 0; return 0;
} }
packet->options[end] = code; packet->options[end] = code;
@ -173,12 +173,12 @@ static ssize_t add_option_check(struct dhcpmsg *packet, uint8_t code,
{ {
ssize_t end = get_end_option_idx(packet); ssize_t end = get_end_option_idx(packet);
if (end < 0) { if (end < 0) {
log_warning("add_u%01u_option: Buffer has no DCODE_END marker.", rlen*8); log_line("add_u%01u_option: Buffer has no DCODE_END marker.", rlen*8);
return -1; return -1;
} }
if ((size_t)end + 2 + rlen >= sizeof packet->options) { if ((size_t)end + 2 + rlen >= sizeof packet->options) {
log_warning("add_u%01u_option: No space for option 0x%02x.", log_line("add_u%01u_option: No space for option 0x%02x.",
rlen*8, code); rlen*8, code);
return -1; return -1;
} }
return end; return end;

View File

@ -58,11 +58,11 @@ int rfkill_get(struct client_state_t cs[static 1],
struct rfkill_event event; struct rfkill_event event;
ssize_t len = safe_read(cs->rfkillFd, (char *)&event, sizeof event); ssize_t len = safe_read(cs->rfkillFd, (char *)&event, sizeof event);
if (len < 0) { if (len < 0) {
log_error("rfkill: safe_read failed: %s", strerror(errno)); log_line("rfkill: safe_read failed: %s", strerror(errno));
return RFK_FAIL; return RFK_FAIL;
} }
if (len != RFKILL_EVENT_SIZE_V1) { if (len != RFKILL_EVENT_SIZE_V1) {
log_error("rfkill: event has unexpected size: %d", len); log_line("rfkill: event has unexpected size: %zd", len);
return RFK_FAIL; return RFK_FAIL;
} }
log_line("rfkill: idx[%u] type[%u] op[%u] soft[%u] hard[%u]", log_line("rfkill: idx[%u] type[%u] op[%u] soft[%u] hard[%u]",

View File

@ -68,7 +68,7 @@ int request_sockd_fd(char buf[static 1], size_t buflen, char *response)
return -1; return -1;
ssize_t r = safe_write(sockdSock[0], buf, buflen); ssize_t r = safe_write(sockdSock[0], buf, buflen);
if (r < 0 || (size_t)r != buflen) if (r < 0 || (size_t)r != buflen)
suicide("%s: (%s) write failed: %d", client_config.interface, suicide("%s: (%s) write failed: %zd", client_config.interface,
__func__, r); __func__, r);
char data[MAX_BUF], control[MAX_BUF]; char data[MAX_BUF], control[MAX_BUF];
@ -112,20 +112,20 @@ static int create_arp_socket(void)
{ {
int fd = socket(AF_PACKET, SOCK_RAW | SOCK_NONBLOCK, htons(ETH_P_ARP)); int fd = socket(AF_PACKET, SOCK_RAW | SOCK_NONBLOCK, htons(ETH_P_ARP));
if (fd < 0) { if (fd < 0) {
log_error("%s: (%s) socket failed: %s", client_config.interface, log_line("%s: (%s) socket failed: %s", client_config.interface,
__func__, strerror(errno)); __func__, strerror(errno));
goto out; goto out;
} }
int opt = 1; int opt = 1;
if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof opt) < 0) { if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof opt) < 0) {
log_error("%s: (%s) setsockopt failed: %s", client_config.interface, log_line("%s: (%s) setsockopt failed: %s", client_config.interface,
__func__, strerror(errno)); __func__, strerror(errno));
goto out_fd; goto out_fd;
} }
if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) < 0) { if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) < 0) {
log_error("%s: (%s) fcntl failed: %s", client_config.interface, log_line("%s: (%s) fcntl failed: %s", client_config.interface,
__func__, strerror(errno)); __func__, strerror(errno));
goto out_fd; goto out_fd;
} }
struct sockaddr_ll saddr = { struct sockaddr_ll saddr = {
@ -134,8 +134,8 @@ static int create_arp_socket(void)
.sll_ifindex = client_config.ifindex, .sll_ifindex = client_config.ifindex,
}; };
if (bind(fd, (struct sockaddr *)&saddr, sizeof(struct sockaddr_ll)) < 0) { if (bind(fd, (struct sockaddr *)&saddr, sizeof(struct sockaddr_ll)) < 0) {
log_error("%s: (%s) bind failed: %s", client_config.interface, log_line("%s: (%s) bind failed: %s", client_config.interface,
__func__, strerror(errno)); __func__, strerror(errno));
goto out_fd; goto out_fd;
} }
return fd; return fd;
@ -150,37 +150,37 @@ static int create_udp_socket(uint32_t ip, uint16_t port, char *iface)
{ {
int fd; int fd;
if ((fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP)) < 0) { if ((fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP)) < 0) {
log_error("%s: (%s) socket failed: %s", log_line("%s: (%s) socket failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto out; goto out;
} }
int opt = 1; int opt = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof opt) < 0) { if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof opt) < 0) {
log_error("%s: (%s) Set reuse addr failed: %s", log_line("%s: (%s) Set reuse addr failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto out_fd; goto out_fd;
} }
if (setsockopt(fd, SOL_SOCKET, SO_DONTROUTE, &opt, sizeof opt) < 0) { if (setsockopt(fd, SOL_SOCKET, SO_DONTROUTE, &opt, sizeof opt) < 0) {
log_error("%s: (%s) Set don't route failed: %s", log_line("%s: (%s) Set don't route failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto out_fd; goto out_fd;
} }
struct ifreq ifr; struct ifreq ifr;
memset(&ifr, 0, sizeof ifr); memset(&ifr, 0, sizeof ifr);
ssize_t sl = snprintf(ifr.ifr_name, sizeof ifr.ifr_name, "%s", iface); ssize_t sl = snprintf(ifr.ifr_name, sizeof ifr.ifr_name, "%s", iface);
if (sl < 0 || (size_t)sl >= sizeof ifr.ifr_name) { if (sl < 0 || (size_t)sl >= sizeof ifr.ifr_name) {
log_error("%s: (%s) Set interface name failed.", log_line("%s: (%s) Set interface name failed.",
client_config.interface, __func__); client_config.interface, __func__);
goto out_fd; goto out_fd;
} }
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof ifr) < 0) { if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof ifr) < 0) {
log_error("%s: (%s) Set bind to device failed: %s", log_line("%s: (%s) Set bind to device failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto out_fd; goto out_fd;
} }
if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) < 0) { if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) < 0) {
log_error("%s: (%s) Set non-blocking failed: %s", log_line("%s: (%s) Set non-blocking failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto out_fd; goto out_fd;
} }
@ -190,8 +190,8 @@ static int create_udp_socket(uint32_t ip, uint16_t port, char *iface)
.sin_addr.s_addr = ip, .sin_addr.s_addr = ip,
}; };
if (bind(fd, (struct sockaddr *)&sa, sizeof sa) < 0) { if (bind(fd, (struct sockaddr *)&sa, sizeof sa) < 0) {
log_error("%s: (%s) bind failed: %s", log_line("%s: (%s) bind failed: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
goto out_fd; goto out_fd;
} }
@ -208,7 +208,7 @@ static int create_raw_socket(struct sockaddr_ll *sa, bool *using_bpf,
int fd; int fd;
if ((fd = socket(AF_PACKET, SOCK_DGRAM | SOCK_NONBLOCK, if ((fd = socket(AF_PACKET, SOCK_DGRAM | SOCK_NONBLOCK,
htons(ETH_P_IP))) < 0) { htons(ETH_P_IP))) < 0) {
log_error("create_raw_socket: socket failed: %s", strerror(errno)); log_line("create_raw_socket: socket failed: %s", strerror(errno));
goto out; goto out;
} }
@ -224,26 +224,26 @@ static int create_raw_socket(struct sockaddr_ll *sa, bool *using_bpf,
if (using_bpf) if (using_bpf)
*using_bpf = true; *using_bpf = true;
} else } else
log_warning("%s: Failed to lock BPF for raw socket: %s", log_line("%s: Failed to lock BPF for raw socket: %s",
client_config.interface, strerror(errno)); client_config.interface, strerror(errno));
} else } else
log_warning("%s: Failed to set BPF for raw socket: %s", log_line("%s: Failed to set BPF for raw socket: %s",
client_config.interface, strerror(errno)); client_config.interface, strerror(errno));
} }
int opt = 1; int opt = 1;
if (setsockopt(fd, SOL_SOCKET, SO_DONTROUTE, &opt, sizeof opt) < 0) { if (setsockopt(fd, SOL_SOCKET, SO_DONTROUTE, &opt, sizeof opt) < 0) {
log_error("create_raw_socket: Failed to set don't route: %s", log_line("create_raw_socket: Failed to set don't route: %s",
strerror(errno)); strerror(errno));
goto out_fd; goto out_fd;
} }
if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) < 0) { if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) < 0) {
log_error("create_raw_socket: Set non-blocking failed: %s", log_line("create_raw_socket: Set non-blocking failed: %s",
strerror(errno)); strerror(errno));
goto out_fd; goto out_fd;
} }
if (bind(fd, (struct sockaddr *)sa, sizeof *sa) < 0) { if (bind(fd, (struct sockaddr *)sa, sizeof *sa) < 0) {
log_error("create_raw_socket: bind failed: %s", strerror(errno)); log_line("create_raw_socket: bind failed: %s", strerror(errno));
goto out_fd; goto out_fd;
} }
return fd; return fd;
@ -350,12 +350,12 @@ static bool arp_set_bpf_basic(int fd)
// checks to run just in case an attacker tries to DETACH the // checks to run just in case an attacker tries to DETACH the
// filter. // filter.
if (ret < 0) if (ret < 0)
log_warning("%s: Failed to lock BPF for basic ARP socket: %s", log_line("%s: Failed to lock BPF for basic ARP socket: %s",
client_config.interface, strerror(errno)); client_config.interface, strerror(errno));
return ret >= 0; return ret >= 0;
} else } else
log_warning("%s: Failed to set BPF for basic ARP socket: %s", log_line("%s: Failed to set BPF for basic ARP socket: %s",
client_config.interface, strerror(errno)); client_config.interface, strerror(errno));
return false; return false;
} }
@ -416,12 +416,12 @@ static bool arp_set_bpf_defense(int fd, uint32_t client_addr,
// checks to run just in case an attacker tries to DETACH the // checks to run just in case an attacker tries to DETACH the
// filter. // filter.
if (ret < 0) if (ret < 0)
log_warning("%s: Failed to lock BPF for defense ARP socket: %s", log_line("%s: Failed to lock BPF for defense ARP socket: %s",
client_config.interface, strerror(errno)); client_config.interface, strerror(errno));
return ret >= 0; return ret >= 0;
} else } else
log_warning("%s: Failed to set BPF for defense ARP socket: %s", log_line("%s: Failed to set BPF for defense ARP socket: %s",
client_config.interface, strerror(errno)); client_config.interface, strerror(errno));
return false; return false;
} }

View File

@ -115,8 +115,8 @@ static int requesting_timeout(struct client_state_t cs[static 1],
return REQ_TIMEOUT; return REQ_TIMEOUT;
} }
if (send_selecting(cs) < 0) { if (send_selecting(cs) < 0) {
log_warning("%s: Failed to send a selecting request packet.", log_line("%s: Failed to send a selecting request packet.",
client_config.interface); client_config.interface);
return REQ_FAIL; return REQ_FAIL;
} }
cs->dhcp_wake_ts = nowts + delay_timeout(cs, cs->num_dhcp_requests); cs->dhcp_wake_ts = nowts + delay_timeout(cs, cs->num_dhcp_requests);
@ -138,8 +138,8 @@ static int rebinding_timeout(struct client_state_t cs[static 1],
} }
start_dhcp_listen(cs); start_dhcp_listen(cs);
if (send_rebind(cs) < 0) { if (send_rebind(cs) < 0) {
log_warning("%s: Failed to send a rebind request packet.", log_line("%s: Failed to send a rebind request packet.",
client_config.interface); client_config.interface);
return BTO_HARDFAIL; return BTO_HARDFAIL;
} }
cs->sent_renew_or_rebind = true; cs->sent_renew_or_rebind = true;
@ -157,8 +157,8 @@ static int renewing_timeout(struct client_state_t cs[static 1],
return rebinding_timeout(cs, nowts); return rebinding_timeout(cs, nowts);
start_dhcp_listen(cs); start_dhcp_listen(cs);
if (send_renew(cs) < 0) { if (send_renew(cs) < 0) {
log_warning("%s: Failed to send a renew request packet.", log_line("%s: Failed to send a renew request packet.",
client_config.interface); client_config.interface);
return BTO_HARDFAIL; return BTO_HARDFAIL;
} }
cs->sent_renew_or_rebind = true; cs->sent_renew_or_rebind = true;
@ -191,8 +191,8 @@ static void get_leasetime(struct client_state_t cs[static 1],
cs->lease = 60 * 60; cs->lease = 60 * 60;
} else { } else {
if (cs->lease < 60) { if (cs->lease < 60) {
log_warning("Server sent lease of <1m. Forcing lease to 1m.", log_line("%s: Server sent lease of <1m. Forcing lease to 1m.",
client_config.interface); client_config.interface);
cs->lease = 60; cs->lease = 60;
} }
} }
@ -253,8 +253,8 @@ static int extend_packet(struct client_state_t cs[static 1],
log_line("%s: Lease refreshed to %u seconds.", log_line("%s: Lease refreshed to %u seconds.",
client_config.interface, cs->lease); client_config.interface, cs->lease);
if (arp_set_defense_mode(cs) < 0) if (arp_set_defense_mode(cs) < 0)
log_warning("%s: Failed to create ARP defense socket.", log_line("%s: Failed to create ARP defense socket.",
client_config.interface); client_config.interface);
stop_dhcp_listen(cs); stop_dhcp_listen(cs);
return ANP_SUCCESS; return ANP_SUCCESS;
} }
@ -331,8 +331,8 @@ static int selecting_timeout(struct client_state_t cs[static 1],
suicide("%s: No lease; failing.", client_config.interface); suicide("%s: No lease; failing.", client_config.interface);
} }
if (send_discover(cs) < 0) { if (send_discover(cs) < 0) {
log_warning("%s: Failed to send a discover request packet.", log_line("%s: Failed to send a discover request packet.",
client_config.interface); client_config.interface);
return SEL_FAIL; return SEL_FAIL;
} }
cs->dhcp_wake_ts = nowts + delay_timeout(cs, cs->num_dhcp_requests); cs->dhcp_wake_ts = nowts + delay_timeout(cs, cs->num_dhcp_requests);
@ -362,8 +362,8 @@ static int xmit_release(struct client_state_t cs[static 1])
log_line("%s: Unicasting a release of %s to %s.", client_config.interface, log_line("%s: Unicasting a release of %s to %s.", client_config.interface,
clibuf, svrbuf); clibuf, svrbuf);
if (send_release(cs) < 0) { if (send_release(cs) < 0) {
log_warning("%s: Failed to send a release request packet.", log_line("%s: Failed to send a release request packet.",
client_config.interface); client_config.interface);
return -1; return -1;
} }
print_release(cs); print_release(cs);
@ -377,8 +377,8 @@ static int frenew(struct client_state_t cs[static 1], bool is_bound)
log_line("%s: Forcing a DHCP renew...", client_config.interface); log_line("%s: Forcing a DHCP renew...", client_config.interface);
start_dhcp_listen(cs); start_dhcp_listen(cs);
if (send_renew(cs) < 0) { if (send_renew(cs) < 0) {
log_warning("%s: Failed to send a renew request packet.", log_line("%s: Failed to send a renew request packet.",
client_config.interface); client_config.interface);
return -1; return -1;
} }
} else { // RELEASED } else { // RELEASED
@ -405,8 +405,8 @@ static int ifup_action(struct client_state_t cs[static 1])
client_config.interface); client_config.interface);
return IFUP_REVALIDATE; return IFUP_REVALIDATE;
} else { } else {
log_warning("%s: arp_gw_check could not make arp socket.", log_line("%s: arp_gw_check could not make arp socket.",
client_config.interface); client_config.interface);
return IFUP_FAIL; return IFUP_FAIL;
} }
} }
@ -519,8 +519,8 @@ skip_to_requesting:
if (r == ANP_IGNORE) { if (r == ANP_IGNORE) {
} else if (r == ANP_CHECK_IP) { } else if (r == ANP_CHECK_IP) {
if (arp_check(cs, dhcp_packet) < 0) { if (arp_check(cs, dhcp_packet) < 0) {
log_warning("%s: Failed to make arp socket. Searching for new lease...", log_line("%s: Failed to make arp socket. Searching for new lease...",
client_config.interface); client_config.interface);
reinit_selecting(cs, 3000); reinit_selecting(cs, 3000);
sev_dhcp = false; sev_dhcp = false;
goto reinit; goto reinit;
@ -610,8 +610,8 @@ skip_to_requesting:
goto reinit; goto reinit;
} else if (r == ANP_CHECK_IP) { } else if (r == ANP_CHECK_IP) {
if (arp_check(cs, dhcp_packet) < 0) { if (arp_check(cs, dhcp_packet) < 0) {
log_warning("%s: Failed to make arp socket. Searching for new lease...", log_line("%s: Failed to make arp socket. Searching for new lease...",
client_config.interface); client_config.interface);
reinit_selecting(cs, 3000); reinit_selecting(cs, 3000);
sev_dhcp = false; sev_dhcp = false;
goto reinit; goto reinit;