Simplify logging and fix some format specifiers.
This commit is contained in:
parent
2e3c504cc5
commit
28e1b34bac
@ -200,7 +200,6 @@ add_dependencies(ndhc ndhc_ragel)
|
||||
|
||||
target_sources(ndhc PRIVATE
|
||||
"src/lib/io.c"
|
||||
"src/lib/log.c"
|
||||
"src/lib/hwrng.c"
|
||||
"src/lib/random.c"
|
||||
"src/lib/privs.c"
|
||||
|
46
src/arp.c
46
src/arp.c
@ -156,7 +156,7 @@ static int arp_open_fd(struct client_state_t cs[static 1], bool defense)
|
||||
cs->arpFd = defense ? get_arp_defense_socket(cs)
|
||||
: get_arp_basic_socket(cs);
|
||||
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));
|
||||
return -1;
|
||||
}
|
||||
@ -175,13 +175,13 @@ static int arp_send(struct client_state_t cs[static 1],
|
||||
memcpy(addr.sll_addr, client_config.arp, 6);
|
||||
|
||||
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);
|
||||
return ret;
|
||||
}
|
||||
|
||||
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__);
|
||||
ret = -99;
|
||||
goto carrier_down;
|
||||
@ -190,10 +190,10 @@ static int arp_send(struct client_state_t cs[static 1],
|
||||
(struct sockaddr *)&addr, sizeof addr);
|
||||
if (ret < 0 || (size_t)ret != sizeof *arp) {
|
||||
if (ret < 0)
|
||||
log_error("%s: (%s) sendto failed: %s",
|
||||
log_line("%s: (%s) sendto failed: %s",
|
||||
client_config.interface, __func__, strerror(errno));
|
||||
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);
|
||||
carrier_down:
|
||||
return ret;
|
||||
@ -343,27 +343,27 @@ static int arp_gw_success(struct client_state_t cs[static 1])
|
||||
static int arp_validate_bpf(struct arpMsg *am)
|
||||
{
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
@ -437,7 +437,7 @@ 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...",
|
||||
client_config.interface);
|
||||
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);
|
||||
return ARPR_FAIL;
|
||||
}
|
||||
@ -446,7 +446,7 @@ 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...",
|
||||
client_config.interface);
|
||||
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);
|
||||
return ARPR_FAIL;
|
||||
}
|
||||
@ -474,7 +474,7 @@ int arp_gw_query_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||
client_config.interface);
|
||||
++cs->router_arp_sent;
|
||||
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);
|
||||
return ARPR_FAIL;
|
||||
}
|
||||
@ -490,7 +490,7 @@ int arp_gw_query_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||
client_config.interface);
|
||||
++cs->server_arp_sent;
|
||||
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);
|
||||
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];
|
||||
struct in_addr temp_addr = {.s_addr = garp.dhcp_packet.yiaddr};
|
||||
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);
|
||||
cs->clientAddr = garp.dhcp_packet.yiaddr;
|
||||
cs->program_init = false;
|
||||
@ -530,7 +530,7 @@ int arp_collision_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||
return ARPR_OK;
|
||||
}
|
||||
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);
|
||||
return ARPR_FAIL;
|
||||
}
|
||||
@ -547,7 +547,7 @@ int arp_query_gateway(struct client_state_t cs[static 1])
|
||||
return ARPR_OK;
|
||||
}
|
||||
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));
|
||||
garp.wake_ts[AS_QUERY_GW_SEND] = curms() + ARP_RETRANS_DELAY;
|
||||
return ARPR_FAIL;
|
||||
@ -575,7 +575,7 @@ int arp_announce(struct client_state_t cs[static 1])
|
||||
return ARPR_OK;
|
||||
}
|
||||
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));
|
||||
garp.wake_ts[AS_ANNOUNCE] = curms() + ARP_RETRANS_DELAY ;
|
||||
return ARPR_FAIL;
|
||||
@ -608,16 +608,16 @@ int arp_do_defense(struct client_state_t cs[static 1])
|
||||
if (!arp_validate_bpf_defense(cs, &garp.reply))
|
||||
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();
|
||||
garp.wake_ts[AS_DEFENSE] = -1;
|
||||
if (!garp.last_conflict_ts ||
|
||||
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)
|
||||
return ARPR_FAIL;
|
||||
} 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);
|
||||
send_release(cs);
|
||||
return ARPR_CONFLICT;
|
||||
@ -686,7 +686,7 @@ int arp_do_collision_check(struct client_state_t cs[static 1])
|
||||
client_config.interface);
|
||||
int r = send_decline(cs, garp.dhcp_packet.yiaddr);
|
||||
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);
|
||||
return ARPR_FAIL;
|
||||
}
|
||||
@ -744,7 +744,7 @@ bool arp_packet_get(struct client_state_t cs[static 1])
|
||||
if (r == 0)
|
||||
return false;
|
||||
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));
|
||||
// Timeouts will trigger anyway without being forced.
|
||||
arp_min_close_fd(cs);
|
||||
|
@ -244,7 +244,7 @@ static void parse_cfgfile(const char fname[static 1])
|
||||
if (reached_eof)
|
||||
break;
|
||||
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);
|
||||
|
||||
if (consumed + 1 > lc) suicide("lc[%zu] - consumed[%zu] would underflow", lc, lend);
|
||||
|
63
src/dhcp.c
63
src/dhcp.c
@ -83,7 +83,7 @@ static ssize_t send_dhcp_unicast(struct client_state_t cs[static 1],
|
||||
ssize_t ret = -1;
|
||||
int fd = get_udp_unicast_socket(cs);
|
||||
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__);
|
||||
goto out;
|
||||
}
|
||||
@ -94,7 +94,7 @@ static ssize_t send_dhcp_unicast(struct client_state_t cs[static 1],
|
||||
.sin_addr.s_addr = cs->serverAddr,
|
||||
};
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
@ -102,27 +102,27 @@ static ssize_t send_dhcp_unicast(struct client_state_t cs[static 1],
|
||||
// Send packets that are as short as possible.
|
||||
ssize_t endloc = get_end_option_idx(payload);
|
||||
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__);
|
||||
goto out_fd;
|
||||
}
|
||||
const size_t el = (size_t)endloc + 1;
|
||||
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__);
|
||||
goto out_fd;
|
||||
}
|
||||
size_t payload_len =
|
||||
sizeof *payload - (sizeof payload->options - el);
|
||||
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__);
|
||||
ret = -99;
|
||||
goto out_fd;
|
||||
}
|
||||
ret = safe_write(fd, (const char *)payload, 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);
|
||||
out_fd:
|
||||
close(fd);
|
||||
@ -157,27 +157,27 @@ 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])
|
||||
{
|
||||
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;
|
||||
}
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
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));
|
||||
return 0;
|
||||
}
|
||||
if (ntohs(packet->udp.len) !=
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
@ -197,7 +197,7 @@ static ssize_t get_raw_packet(struct client_state_t cs[static 1],
|
||||
if (inc < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
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));
|
||||
return -1;
|
||||
}
|
||||
@ -208,22 +208,23 @@ static ssize_t get_raw_packet(struct client_state_t cs[static 1],
|
||||
return -2;
|
||||
|
||||
if (!ip_checksum(&packet)) {
|
||||
log_error("%s: IP header checksum incorrect.",
|
||||
log_line("%s: IP header checksum incorrect.",
|
||||
client_config.interface);
|
||||
return -2;
|
||||
}
|
||||
if (iphdrlen <= sizeof packet.ip + sizeof packet.udp) {
|
||||
log_error("%s: Packet received that is too small (%zu bytes).",
|
||||
iphdrlen);
|
||||
log_line("%s: Packet received that is too small (%zu bytes).",
|
||||
client_config.interface, iphdrlen);
|
||||
return -2;
|
||||
}
|
||||
size_t l = iphdrlen - sizeof packet.ip - sizeof packet.udp;
|
||||
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;
|
||||
}
|
||||
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);
|
||||
return -2;
|
||||
}
|
||||
@ -239,7 +240,7 @@ static ssize_t send_dhcp_raw(struct dhcpmsg payload[static 1])
|
||||
ssize_t ret = -1;
|
||||
int fd = get_raw_broadcast_socket();
|
||||
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__);
|
||||
return ret;
|
||||
}
|
||||
@ -247,14 +248,14 @@ static ssize_t send_dhcp_raw(struct dhcpmsg payload[static 1])
|
||||
// Send packets that are as short as possible.
|
||||
ssize_t endloc = get_end_option_idx(payload);
|
||||
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__);
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
const size_t el = (size_t)endloc + 1;
|
||||
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__);
|
||||
close(fd);
|
||||
return ret;
|
||||
@ -299,7 +300,7 @@ static ssize_t send_dhcp_raw(struct dhcpmsg payload[static 1])
|
||||
};
|
||||
memcpy(da.sll_addr, "\xff\xff\xff\xff\xff\xff", 6);
|
||||
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__);
|
||||
ret = -99;
|
||||
goto carrier_down;
|
||||
@ -308,10 +309,10 @@ static ssize_t send_dhcp_raw(struct dhcpmsg payload[static 1])
|
||||
(struct sockaddr *)&da, sizeof da);
|
||||
if (ret < 0 || (size_t)ret != iud_len) {
|
||||
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));
|
||||
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);
|
||||
}
|
||||
carrier_down:
|
||||
@ -342,22 +343,22 @@ static int validate_dhcp_packet(struct client_state_t cs[static 1],
|
||||
uint8_t msgtype[static 1])
|
||||
{
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
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,
|
||||
packet->chaddr[0], packet->chaddr[1], packet->chaddr[2],
|
||||
packet->chaddr[3], packet->chaddr[4], packet->chaddr[5],
|
||||
@ -368,12 +369,12 @@ static int validate_dhcp_packet(struct client_state_t cs[static 1],
|
||||
}
|
||||
ssize_t endloc = get_end_option_idx(packet);
|
||||
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;
|
||||
}
|
||||
*msgtype = get_option_msgtype(packet);
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
@ -383,7 +384,7 @@ static int validate_dhcp_packet(struct client_state_t cs[static 1],
|
||||
return 1;
|
||||
if (memcmp(client_config.clientid, clientid,
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
@ -401,7 +402,7 @@ bool dhcp_packet_get(struct client_state_t cs[static 1],
|
||||
if (r < 0) {
|
||||
// Not a transient issue handled by packet collection functions.
|
||||
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));
|
||||
stop_dhcp_listen(cs);
|
||||
start_dhcp_listen(cs);
|
||||
|
12
src/duiaid.c
12
src/duiaid.c
@ -47,7 +47,7 @@ static void get_duid_path(char duidfile[static 1], size_t dlen)
|
||||
if (splen < 0)
|
||||
suicide("%s: snprintf failed; return=%d", __func__, splen);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
if (hwaddrlen != 6)
|
||||
suicide("%s: Hardware address length=%u != 6 bytes",
|
||||
suicide("%s: Hardware address length=%zu != 6 bytes",
|
||||
__func__, hwaddrlen);
|
||||
int splen = snprintf
|
||||
(iaidfile, ilen,
|
||||
@ -65,7 +65,7 @@ static void get_iaid_path(char iaidfile[static 1], size_t ilen,
|
||||
if (splen < 0)
|
||||
suicide("%s: snprintf failed; return=%d", __func__, splen);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
if (dlen < tlen)
|
||||
suicide("%s: dlen < %u", __func__, tlen);
|
||||
suicide("%s: dlen < %zu", __func__, tlen);
|
||||
size_t off = 0;
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
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;
|
||||
size_t cdl = sizeof cid_type + iaid_len + duid_len;
|
||||
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);
|
||||
|
||||
uint8_t cid_len = 0;
|
||||
|
@ -52,17 +52,17 @@ static int ifcmd_raw(char buf[static 1], size_t buflen,
|
||||
char *optdata, size_t optlen)
|
||||
{
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
@ -70,7 +70,7 @@ static int ifcmd_raw(char buf[static 1], size_t buflen,
|
||||
ssize_t olen = snprintf(buf, buflen, "%s:%.*s;",
|
||||
optname, ioptlen, optdata);
|
||||
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);
|
||||
memset(buf, 0, buflen);
|
||||
return -1;
|
||||
@ -187,7 +187,7 @@ 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);
|
||||
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);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
char data[256], control[256];
|
||||
@ -304,7 +304,7 @@ static size_t send_client_ip(char out[static 1], size_t olen,
|
||||
snlen = snprintf(out, olen, "ip4:%s,%s;", ip, sn);
|
||||
}
|
||||
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__);
|
||||
memset(out, 0, olen);
|
||||
return 0;
|
||||
|
@ -198,12 +198,12 @@ int execute_buffer(const char newbuf[static 1])
|
||||
|
||||
ssize_t buflen = snprintf(buf, sizeof buf, "%s%s", cl.ibuf, newbuf);
|
||||
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__);
|
||||
return -99;
|
||||
}
|
||||
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__);
|
||||
return -99;
|
||||
}
|
||||
@ -224,19 +224,19 @@ int execute_buffer(const char newbuf[static 1])
|
||||
size_t taken = init_siz - bytes_left;
|
||||
ssize_t ilen = snprintf(cl.ibuf, sizeof cl.ibuf, "%s", buf + taken);
|
||||
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__);
|
||||
return -99;
|
||||
}
|
||||
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__);
|
||||
return -99;
|
||||
}
|
||||
}
|
||||
|
||||
if (cs < ifchd_parser_first_final) {
|
||||
log_error("%s: ifch received invalid commands",
|
||||
log_line("%s: ifch received invalid commands",
|
||||
client_config.interface);
|
||||
return -99;
|
||||
}
|
||||
|
22
src/ifchd.c
22
src/ifchd.c
@ -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);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -78,12 +78,12 @@ 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);
|
||||
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);
|
||||
return -2;
|
||||
}
|
||||
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);
|
||||
return -2;
|
||||
}
|
||||
@ -131,7 +131,7 @@ static int write_resolve_conf(void)
|
||||
*q++ = '\0';
|
||||
ssize_t sl = snprintf(buf, sizeof buf, "%s", p);
|
||||
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__);
|
||||
}
|
||||
|
||||
@ -152,7 +152,7 @@ static int write_resolve_conf(void)
|
||||
*q++ = '\0';
|
||||
ssize_t sl = snprintf(buf, sizeof buf, "%s", p);
|
||||
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__);
|
||||
}
|
||||
|
||||
@ -213,12 +213,12 @@ int perform_dns(const char str[static 1], size_t len)
|
||||
return 0;
|
||||
int ret = -1;
|
||||
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;
|
||||
}
|
||||
ssize_t sl = snprintf(cl.namesvrs, sizeof cl.namesvrs, "%s", str);
|
||||
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__);
|
||||
}
|
||||
ret = write_resolve_conf();
|
||||
@ -255,12 +255,12 @@ int perform_domain(const char str[static 1], size_t len)
|
||||
return 0;
|
||||
int ret = -1;
|
||||
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;
|
||||
}
|
||||
ssize_t sl = snprintf(cl.domains, sizeof cl.domains, "%s", str);
|
||||
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__);
|
||||
}
|
||||
ret = write_resolve_conf();
|
||||
@ -378,13 +378,13 @@ static void setup_resolv_conf(void)
|
||||
|
||||
ssize_t sl = snprintf(buf, sizeof buf, "%s.head", resolv_conf_d);
|
||||
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
|
||||
resolv_conf_head_fd = open(buf, O_RDONLY|O_CLOEXEC, 0);
|
||||
|
||||
sl = snprintf(buf, sizeof buf, "%s.tail", resolv_conf_d);
|
||||
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
|
||||
resolv_conf_tail_fd = open(buf, O_RDONLY|O_CLOEXEC, 0);
|
||||
|
||||
|
72
src/ifset.c
72
src/ifset.c
@ -93,10 +93,10 @@ static ssize_t rtnl_do_send(int fd, const uint8_t *sbuf, size_t slen,
|
||||
(struct sockaddr *)&nl_addr, sizeof nl_addr);
|
||||
if (r < 0 || (size_t)r != slen) {
|
||||
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));
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
@ -112,12 +112,12 @@ static ssize_t rtnl_do_send(int fd, const uint8_t *sbuf, size_t slen,
|
||||
};
|
||||
r = safe_recvmsg(fd, &msg, 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));
|
||||
return -1;
|
||||
}
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
@ -137,14 +137,14 @@ static ssize_t rtnl_do_send(int fd, const uint8_t *sbuf, size_t slen,
|
||||
client_config.interface, fnname, nlerr);
|
||||
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));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (nlh->nlmsg_type == NLMSG_DONE)
|
||||
return -2;
|
||||
log_error("%s: (%s) netlink sendto returned an error.",
|
||||
log_line("%s: (%s) netlink sendto returned an error.",
|
||||
client_config.interface, __func__);
|
||||
return -1;
|
||||
}
|
||||
@ -182,7 +182,7 @@ static ssize_t rtnl_addr_broadcast_send(int fd, int type, int ifa_flags,
|
||||
struct ifaddrmsg *ifaddrmsg;
|
||||
|
||||
if (!ipaddr && !bcast) {
|
||||
log_warning("%s: (%s) no ipaddr or bcast!",
|
||||
log_line("%s: (%s) no ipaddr or bcast!",
|
||||
client_config.interface, __func__);
|
||||
return -1;
|
||||
}
|
||||
@ -205,7 +205,7 @@ static ssize_t rtnl_addr_broadcast_send(int fd, int type, int ifa_flags,
|
||||
if (ipaddr) {
|
||||
if (nl_add_rtattr(header, sizeof request, IFA_LOCAL,
|
||||
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__);
|
||||
return -1;
|
||||
}
|
||||
@ -213,7 +213,7 @@ static ssize_t rtnl_addr_broadcast_send(int fd, int type, int ifa_flags,
|
||||
if (bcast) {
|
||||
if (nl_add_rtattr(header, sizeof request, IFA_BROADCAST,
|
||||
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__);
|
||||
return -1;
|
||||
}
|
||||
@ -248,27 +248,27 @@ static ssize_t rtnl_set_default_gw_v4(int fd, uint32_t gw4, int metric)
|
||||
uint32_t dstaddr4 = 0;
|
||||
if (nl_add_rtattr(header, sizeof request, RTA_DST,
|
||||
&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__);
|
||||
return -1;
|
||||
}
|
||||
if (nl_add_rtattr(header, sizeof request, RTA_OIF,
|
||||
&client_config.ifindex,
|
||||
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__);
|
||||
return -1;
|
||||
}
|
||||
if (nl_add_rtattr(header, sizeof request, RTA_GATEWAY,
|
||||
&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__);
|
||||
return -1;
|
||||
}
|
||||
if (metric > 0) {
|
||||
if (nl_add_rtattr(header, sizeof request, RTA_PRIORITY,
|
||||
&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__);
|
||||
return -1;
|
||||
}
|
||||
@ -333,7 +333,7 @@ int perform_carrier(void)
|
||||
uint32_t flags;
|
||||
int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE);
|
||||
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));
|
||||
goto fail;
|
||||
}
|
||||
@ -359,7 +359,7 @@ static int link_set_flags(int fd, uint32_t flags)
|
||||
|
||||
int r = link_flags_get(fd, &oldflags);
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
@ -375,7 +375,7 @@ static int link_unset_flags(int fd, uint32_t flags)
|
||||
|
||||
int r = link_flags_get(fd, &oldflags);
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
@ -430,7 +430,7 @@ static void ipbcpfx_clear_others_do(const struct nlmsghdr *nlh, void *data)
|
||||
tb[IFA_BROADCAST] ? RTA_DATA(tb[IFA_BROADCAST]) : (uint32_t *)0,
|
||||
ifm->ifa_prefixlen);
|
||||
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__);
|
||||
}
|
||||
return;
|
||||
@ -469,7 +469,7 @@ static ssize_t rtnl_if_mtu_set(int fd, unsigned int mtu)
|
||||
|
||||
int r = link_flags_get(fd, &oldflags);
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
@ -488,7 +488,7 @@ static ssize_t rtnl_if_mtu_set(int fd, unsigned int mtu)
|
||||
|
||||
if (nl_add_rtattr(header, sizeof request, IFLA_MTU,
|
||||
&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__);
|
||||
return -1;
|
||||
}
|
||||
@ -508,7 +508,7 @@ int perform_ifup(void)
|
||||
int r = link_set_flags(fd, IFF_UP);
|
||||
if (r < 0) {
|
||||
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__);
|
||||
else
|
||||
log_line("%s: (%s) rfkill is set; waiting until it is unset",
|
||||
@ -528,13 +528,13 @@ int perform_ip_subnet_bcast(const char str_ipaddr[static 1],
|
||||
uint8_t prefixlen;
|
||||
|
||||
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);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
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);
|
||||
goto fail;
|
||||
}
|
||||
@ -542,7 +542,7 @@ int perform_ip_subnet_bcast(const char str_ipaddr[static 1],
|
||||
|
||||
if (str_bcast) {
|
||||
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);
|
||||
goto fail;
|
||||
}
|
||||
@ -553,7 +553,7 @@ int perform_ip_subnet_bcast(const char str_ipaddr[static 1],
|
||||
|
||||
fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE);
|
||||
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));
|
||||
goto fail;
|
||||
}
|
||||
@ -561,10 +561,10 @@ int perform_ip_subnet_bcast(const char str_ipaddr[static 1],
|
||||
r = ipbcpfx_clear_others(fd, ipaddr.s_addr, bcast.s_addr, prefixlen);
|
||||
if (r < 0 && r > -3) {
|
||||
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__);
|
||||
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__);
|
||||
goto fail_fd;
|
||||
}
|
||||
@ -589,7 +589,7 @@ int perform_ip_subnet_bcast(const char str_ipaddr[static 1],
|
||||
|
||||
if (link_set_flags(fd, IFF_UP | IFF_RUNNING) < 0) {
|
||||
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__);
|
||||
goto fail_fd;
|
||||
}
|
||||
@ -608,20 +608,20 @@ int perform_router(const char str_router[static 1], size_t len)
|
||||
goto fail;
|
||||
struct in_addr router;
|
||||
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);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE);
|
||||
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));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
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));
|
||||
goto fail_fd;
|
||||
}
|
||||
@ -644,23 +644,23 @@ int perform_mtu(const char str[static 1], size_t len)
|
||||
char *estr;
|
||||
long tmtu = strtol(str, &estr, 10);
|
||||
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__);
|
||||
goto fail;
|
||||
}
|
||||
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__);
|
||||
goto fail;
|
||||
}
|
||||
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__);
|
||||
goto fail;
|
||||
}
|
||||
// 68 bytes for IPv4. 1280 bytes for IPv6.
|
||||
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);
|
||||
goto fail;
|
||||
}
|
||||
@ -668,13 +668,13 @@ int perform_mtu(const char str[static 1], size_t len)
|
||||
|
||||
fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE);
|
||||
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));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
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);
|
||||
goto fail_fd;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ static void get_leasefile_path(char *leasefile, size_t dlen, char *ifname)
|
||||
suicide("%s: (%s) snprintf failed; return=%d",
|
||||
client_config.interface, __func__, splen);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -71,31 +71,31 @@ void write_leasefile(struct in_addr ipnum)
|
||||
char ip[INET_ADDRSTRLEN];
|
||||
char out[INET_ADDRSTRLEN*2];
|
||||
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__);
|
||||
return;
|
||||
}
|
||||
inet_ntop(AF_INET, &ipnum, ip, sizeof ip);
|
||||
ssize_t olen = snprintf(out, sizeof out, "%s\n", 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);
|
||||
return;
|
||||
}
|
||||
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));
|
||||
return;
|
||||
}
|
||||
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));
|
||||
return;
|
||||
}
|
||||
size_t outlen = strlen(out);
|
||||
ssize_t ret = safe_write(leasefilefd, out, 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__);
|
||||
else
|
||||
fsync(leasefilefd);
|
||||
|
@ -50,12 +50,12 @@ static bool nk_getrandom(char *seed, size_t len)
|
||||
if (r <= 0) {
|
||||
if (r == 0) {
|
||||
// Failsafe to guard against infinite loops.
|
||||
log_warning("%s: getrandom() returned no entropy", __func__);
|
||||
log_line("%s: getrandom() returned no entropy", __func__);
|
||||
return false;
|
||||
}
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
log_warning("%s: getrandom() failed: %s", __func__, strerror(errno));
|
||||
log_line("%s: getrandom() failed: %s", __func__, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
fetched += (size_t)r;
|
||||
@ -76,7 +76,7 @@ static bool nk_get_rnd_clk(char *seed, size_t len)
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
int r = clock_gettime(CLOCK_REALTIME, &ts);
|
||||
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));
|
||||
return false;
|
||||
}
|
||||
@ -97,7 +97,7 @@ static bool nk_get_urandom(char *seed, size_t len)
|
||||
{
|
||||
int fd = open("/dev/urandom", O_RDONLY);
|
||||
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));
|
||||
return false;
|
||||
}
|
||||
@ -105,7 +105,7 @@ static bool nk_get_urandom(char *seed, size_t len)
|
||||
int r = safe_read(fd, seed, len);
|
||||
if (r < 0) {
|
||||
ret = false;
|
||||
log_warning("%s: Could not read /dev/urandom: %s",
|
||||
log_line("%s: Could not read /dev/urandom: %s",
|
||||
__func__, strerror(errno));
|
||||
}
|
||||
close(fd);
|
||||
@ -119,7 +119,7 @@ void nk_get_hwrng(void *seed, size_t len)
|
||||
return;
|
||||
if (nk_get_urandom(s, len))
|
||||
return;
|
||||
log_warning("%s: Seeding PRNG via system clock. May be predictable.",
|
||||
log_line("%s: Seeding PRNG via system clock. May be predictable.",
|
||||
__func__);
|
||||
if (nk_get_rnd_clk(s, len))
|
||||
return;
|
||||
|
@ -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
|
||||
|
@ -71,7 +71,7 @@ static size_t nk_get_capability_vinfo(uint32_t version[static 1])
|
||||
case _LINUX_CAPABILITY_VERSION_2:
|
||||
*version = _LINUX_CAPABILITY_VERSION_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);
|
||||
case _LINUX_CAPABILITY_VERSION_3:
|
||||
*version = _LINUX_CAPABILITY_VERSION_3;
|
||||
@ -105,8 +105,8 @@ static void nk_set_capability_epilogue(const unsigned char *caps,
|
||||
for (size_t i = 0; i < caplen; ++i) {
|
||||
size_t j = caps[i] / 32;
|
||||
if (j >= csize)
|
||||
suicide("%s: caps[%zu] == %u, which is >= %u and out of range",
|
||||
__func__, caps[i], csize * 32);
|
||||
suicide("%s: caps[%zu] == %d, which is >= %zu and out of range",
|
||||
__func__, i, caps[i], csize * 32);
|
||||
mask[j] |= (uint32_t)CAP_TO_MASK(caps[i] - 32 * j);
|
||||
}
|
||||
for (size_t i = 0; i < csize; ++i) {
|
||||
|
@ -115,7 +115,7 @@ static int get_if_index_and_mac(const struct nlmsghdr *nlh,
|
||||
sizeof client_config.interface)) {
|
||||
client_config.ifindex = ifm->ifi_index;
|
||||
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;
|
||||
if (maclen != 6)
|
||||
suicide("FATAL: Adapter hardware address length should be 6, but is %u.",
|
||||
|
29
src/nk/log.h
29
src/nk/log.h
@ -1,6 +1,6 @@
|
||||
/* 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.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -29,20 +29,25 @@
|
||||
#ifndef NCM_LOG_H_
|
||||
#define NCM_LOG_H_
|
||||
|
||||
#include <syslog.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int gflags_quiet;
|
||||
extern int gflags_detach;
|
||||
extern int gflags_debug;
|
||||
extern char *gflags_log_name;
|
||||
#define log_line(...) do { \
|
||||
dprintf(2, __VA_ARGS__); \
|
||||
dprintf(2, "\n"); } while (0)
|
||||
|
||||
#define log_line(...) log_line_l(LOG_INFO, __VA_ARGS__)
|
||||
#define log_debug(...) if (gflags_debug) log_line_l(LOG_DEBUG, __VA_ARGS__)
|
||||
#define log_warning(...) log_line_l(LOG_WARNING, __VA_ARGS__)
|
||||
#define log_error(...) log_line_l(LOG_ERR, __VA_ARGS__)
|
||||
#ifndef NDEBUG
|
||||
#define log_debug(...) do { \
|
||||
dprintf(2, __VA_ARGS__); \
|
||||
dprintf(2, "\n"); } while (0)
|
||||
#else
|
||||
#define log_debug(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
void log_line_l(int level, const char *format, ...);
|
||||
void __attribute__((noreturn)) suicide(const char *format, ...);
|
||||
#define suicide(...) do { \
|
||||
dprintf(2, __VA_ARGS__); \
|
||||
dprintf(2, "\n"); \
|
||||
exit(EXIT_FAILURE); } while (0)
|
||||
|
||||
#endif
|
||||
|
||||
|
24
src/nl.c
24
src/nl.c
@ -99,15 +99,15 @@ ssize_t nl_recv_buf(int fd, char buf[static 1], size_t blen)
|
||||
if (ret < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
return 0;
|
||||
log_error("%s: recvmsg failed: %s", __func__, strerror(errno));
|
||||
log_line("%s: recvmsg failed: %s", __func__, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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__);
|
||||
return -1;
|
||||
}
|
||||
@ -172,10 +172,10 @@ static int nl_sendgetlink_do(int fd, uint32_t seq, int ifindex, int by_ifindex)
|
||||
(struct sockaddr *)&addr, sizeof addr);
|
||||
if (r < 0 || (size_t)r != nlh->nlmsg_len) {
|
||||
if (r < 0)
|
||||
log_error("%s: sendto socket failed: %s", __func__,
|
||||
log_line("%s: sendto socket failed: %s", __func__,
|
||||
strerror(errno));
|
||||
else
|
||||
log_error("%s: sendto short write: %z < %zu", __func__, r,
|
||||
log_line("%s: sendto short write: %zd < %u", __func__, r,
|
||||
nlh->nlmsg_len);
|
||||
return -1;
|
||||
}
|
||||
@ -218,10 +218,10 @@ static int nl_sendgetaddr_do(int fd, uint32_t seq, uint32_t ifindex, int by_ifin
|
||||
(struct sockaddr *)&addr, sizeof addr);
|
||||
if (r < 0 || (size_t)r != nlh->nlmsg_len) {
|
||||
if (r < 0)
|
||||
log_error("%s: sendto socket failed: %s", __func__,
|
||||
log_line("%s: sendto socket failed: %s", __func__,
|
||||
strerror(errno));
|
||||
else
|
||||
log_error("%s: sendto short write: %z < %zu", __func__, r,
|
||||
log_line("%s: sendto short write: %zd < %u", __func__, r,
|
||||
nlh->nlmsg_len);
|
||||
return -1;
|
||||
}
|
||||
@ -263,7 +263,7 @@ int nl_open(int nltype, unsigned nlgroup, uint32_t *nlportid)
|
||||
int fd;
|
||||
fd = socket(AF_NETLINK, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, nltype);
|
||||
if (fd < 0) {
|
||||
log_error("%s: socket failed: %s", __func__, strerror(errno));
|
||||
log_line("%s: socket failed: %s", __func__, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
socklen_t al;
|
||||
@ -272,23 +272,23 @@ int nl_open(int nltype, unsigned nlgroup, uint32_t *nlportid)
|
||||
.nl_groups = nlgroup,
|
||||
};
|
||||
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));
|
||||
goto err_close;
|
||||
}
|
||||
al = sizeof nlsock;
|
||||
if (getsockname(fd, (struct sockaddr *)&nlsock, &al) < 0) {
|
||||
log_error("%s: getsockname failed: %s",
|
||||
log_line("%s: getsockname failed: %s",
|
||||
__func__, strerror(errno));
|
||||
goto err_close;
|
||||
}
|
||||
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__);
|
||||
goto err_close;
|
||||
}
|
||||
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__);
|
||||
goto err_close;
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ ssize_t get_end_option_idx(const struct dhcpmsg * const packet)
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -148,17 +148,17 @@ size_t add_option_string(struct dhcpmsg *packet, uint8_t code,
|
||||
{
|
||||
size_t len = sizeof_option_str(code, slen);
|
||||
if (slen > 255 || len != slen + 2) {
|
||||
log_warning("add_option_string: Length checks failed.");
|
||||
log_line("add_option_string: Length checks failed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t end = get_end_option_idx(packet);
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
packet->options[end] = code;
|
||||
@ -173,11 +173,11 @@ static ssize_t add_option_check(struct dhcpmsg *packet, uint8_t code,
|
||||
{
|
||||
ssize_t end = get_end_option_idx(packet);
|
||||
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;
|
||||
}
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
|
@ -58,11 +58,11 @@ int rfkill_get(struct client_state_t cs[static 1],
|
||||
struct rfkill_event event;
|
||||
ssize_t len = safe_read(cs->rfkillFd, (char *)&event, sizeof event);
|
||||
if (len < 0) {
|
||||
log_error("rfkill: safe_read failed: %s", strerror(errno));
|
||||
log_line("rfkill: safe_read failed: %s", strerror(errno));
|
||||
return RFK_FAIL;
|
||||
}
|
||||
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;
|
||||
}
|
||||
log_line("rfkill: idx[%u] type[%u] op[%u] soft[%u] hard[%u]",
|
||||
|
44
src/sockd.c
44
src/sockd.c
@ -68,7 +68,7 @@ int request_sockd_fd(char buf[static 1], size_t buflen, char *response)
|
||||
return -1;
|
||||
ssize_t r = safe_write(sockdSock[0], buf, 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);
|
||||
|
||||
char data[MAX_BUF], control[MAX_BUF];
|
||||
@ -112,19 +112,19 @@ static int create_arp_socket(void)
|
||||
{
|
||||
int fd = socket(AF_PACKET, SOCK_RAW | SOCK_NONBLOCK, htons(ETH_P_ARP));
|
||||
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));
|
||||
goto out;
|
||||
}
|
||||
|
||||
int opt = 1;
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
@ -134,7 +134,7 @@ static int create_arp_socket(void)
|
||||
.sll_ifindex = client_config.ifindex,
|
||||
};
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
@ -150,18 +150,18 @@ static int create_udp_socket(uint32_t ip, uint16_t port, char *iface)
|
||||
{
|
||||
int fd;
|
||||
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));
|
||||
goto out;
|
||||
}
|
||||
int opt = 1;
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
@ -169,17 +169,17 @@ static int create_udp_socket(uint32_t ip, uint16_t port, char *iface)
|
||||
memset(&ifr, 0, sizeof ifr);
|
||||
ssize_t sl = snprintf(ifr.ifr_name, sizeof ifr.ifr_name, "%s", iface);
|
||||
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__);
|
||||
goto out_fd;
|
||||
}
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
@ -190,7 +190,7 @@ static int create_udp_socket(uint32_t ip, uint16_t port, char *iface)
|
||||
.sin_addr.s_addr = ip,
|
||||
};
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
@ -208,7 +208,7 @@ static int create_raw_socket(struct sockaddr_ll *sa, bool *using_bpf,
|
||||
int fd;
|
||||
if ((fd = socket(AF_PACKET, SOCK_DGRAM | SOCK_NONBLOCK,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -224,26 +224,26 @@ static int create_raw_socket(struct sockaddr_ll *sa, bool *using_bpf,
|
||||
if (using_bpf)
|
||||
*using_bpf = true;
|
||||
} 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));
|
||||
} 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));
|
||||
}
|
||||
|
||||
int opt = 1;
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
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));
|
||||
goto out_fd;
|
||||
}
|
||||
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;
|
||||
}
|
||||
return fd;
|
||||
@ -350,11 +350,11 @@ static bool arp_set_bpf_basic(int fd)
|
||||
// checks to run just in case an attacker tries to DETACH the
|
||||
// filter.
|
||||
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));
|
||||
return ret >= 0;
|
||||
} 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));
|
||||
return false;
|
||||
}
|
||||
@ -416,11 +416,11 @@ static bool arp_set_bpf_defense(int fd, uint32_t client_addr,
|
||||
// checks to run just in case an attacker tries to DETACH the
|
||||
// filter.
|
||||
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));
|
||||
return ret >= 0;
|
||||
} 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));
|
||||
return false;
|
||||
}
|
||||
|
22
src/state.c
22
src/state.c
@ -115,7 +115,7 @@ static int requesting_timeout(struct client_state_t cs[static 1],
|
||||
return REQ_TIMEOUT;
|
||||
}
|
||||
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);
|
||||
return REQ_FAIL;
|
||||
}
|
||||
@ -138,7 +138,7 @@ static int rebinding_timeout(struct client_state_t cs[static 1],
|
||||
}
|
||||
start_dhcp_listen(cs);
|
||||
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);
|
||||
return BTO_HARDFAIL;
|
||||
}
|
||||
@ -157,7 +157,7 @@ static int renewing_timeout(struct client_state_t cs[static 1],
|
||||
return rebinding_timeout(cs, nowts);
|
||||
start_dhcp_listen(cs);
|
||||
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);
|
||||
return BTO_HARDFAIL;
|
||||
}
|
||||
@ -191,7 +191,7 @@ static void get_leasetime(struct client_state_t cs[static 1],
|
||||
cs->lease = 60 * 60;
|
||||
} else {
|
||||
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);
|
||||
cs->lease = 60;
|
||||
}
|
||||
@ -253,7 +253,7 @@ static int extend_packet(struct client_state_t cs[static 1],
|
||||
log_line("%s: Lease refreshed to %u seconds.",
|
||||
client_config.interface, cs->lease);
|
||||
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);
|
||||
stop_dhcp_listen(cs);
|
||||
return ANP_SUCCESS;
|
||||
@ -331,7 +331,7 @@ static int selecting_timeout(struct client_state_t cs[static 1],
|
||||
suicide("%s: No lease; failing.", client_config.interface);
|
||||
}
|
||||
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);
|
||||
return SEL_FAIL;
|
||||
}
|
||||
@ -362,7 +362,7 @@ static int xmit_release(struct client_state_t cs[static 1])
|
||||
log_line("%s: Unicasting a release of %s to %s.", client_config.interface,
|
||||
clibuf, svrbuf);
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
@ -377,7 +377,7 @@ static int frenew(struct client_state_t cs[static 1], bool is_bound)
|
||||
log_line("%s: Forcing a DHCP renew...", client_config.interface);
|
||||
start_dhcp_listen(cs);
|
||||
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);
|
||||
return -1;
|
||||
}
|
||||
@ -405,7 +405,7 @@ static int ifup_action(struct client_state_t cs[static 1])
|
||||
client_config.interface);
|
||||
return IFUP_REVALIDATE;
|
||||
} 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);
|
||||
return IFUP_FAIL;
|
||||
}
|
||||
@ -519,7 +519,7 @@ skip_to_requesting:
|
||||
if (r == ANP_IGNORE) {
|
||||
} else if (r == ANP_CHECK_IP) {
|
||||
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);
|
||||
reinit_selecting(cs, 3000);
|
||||
sev_dhcp = false;
|
||||
@ -610,7 +610,7 @@ skip_to_requesting:
|
||||
goto reinit;
|
||||
} else if (r == ANP_CHECK_IP) {
|
||||
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);
|
||||
reinit_selecting(cs, 3000);
|
||||
sev_dhcp = false;
|
||||
|
Loading…
Reference in New Issue
Block a user