Update more message prints to prefix with the interface name.

This commit is contained in:
Nicholas J. Kain 2014-04-15 15:24:22 -04:00
parent 58b4ba768c
commit a9055b5ca5
3 changed files with 48 additions and 31 deletions

View File

@ -433,8 +433,8 @@ void arp_success(struct client_state_t *cs)
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("Lease of %s obtained. Lease time is %ld seconds.", log_line("%s: Lease of %s obtained. Lease time is %ld seconds.",
clibuf, cs->lease); client_config.interface, clibuf, cs->lease);
cs->clientAddr = garp.dhcp_packet.yiaddr; cs->clientAddr = garp.dhcp_packet.yiaddr;
cs->dhcpState = DS_BOUND; cs->dhcpState = DS_BOUND;
cs->init = 0; cs->init = 0;

View File

@ -553,12 +553,16 @@ void perform_ip_subnet_bcast(const char *str_ipaddr,
return; return;
} }
log_line("Interface IP set to: '%s'", str_ipaddr); log_line("%s: Interface IP set to: '%s'", client_config.interface,
log_line("Interface subnet set to: '%s'", str_subnet); str_ipaddr);
log_line("%s: Interface subnet set to: '%s'", client_config.interface,
str_subnet);
if (str_bcast) if (str_bcast)
log_line("Broadcast address set to: '%s'", str_bcast); log_line("%s: Broadcast address set to: '%s'",
client_config.interface, str_bcast);
} else } else
log_line("Interface IP, subnet, and broadcast were already OK."); log_line("%s: Interface IP, subnet, and broadcast were already OK.",
client_config.interface);
if (link_set_flags(fd, IFF_UP | IFF_RUNNING) < 0) if (link_set_flags(fd, IFF_UP | IFF_RUNNING) < 0)
log_error("%s: (%s) Failed to set link to be up and running.", log_error("%s: (%s) Failed to set link to be up and running.",
@ -592,7 +596,8 @@ void perform_router(const char *str_router, size_t len)
log_error("%s: (%s) failed to set route: %s", log_error("%s: (%s) failed to set route: %s",
client_config.interface, __func__, strerror(errno)); client_config.interface, __func__, strerror(errno));
else else
log_line("Gateway router set to: '%s'", str_router); log_line("%s: Gateway router set to: '%s'", client_config.interface,
str_router);
close(fd); close(fd);
} }
@ -639,7 +644,7 @@ void perform_mtu(const char *str, size_t len)
log_error("%s: (%s) failed to set MTU [%d]", log_error("%s: (%s) failed to set MTU [%d]",
client_config.interface, __func__, mtu); client_config.interface, __func__, mtu);
else else
log_line("MTU set to: '%s'", str); log_line("%s: MTU set to: '%s'", client_config.interface, str);
close(fd); close(fd);
} }

View File

@ -182,7 +182,8 @@ static void rebinding_timeout(struct client_state_t *cs, long long nowts)
send_rebind(cs); send_rebind(cs);
dhcp_wake_ts = nowts + ((elt - nowts) / 2); dhcp_wake_ts = nowts + ((elt - nowts) / 2);
} else { } else {
log_line("Lease expired. Searching for a new lease..."); log_line("%s: Lease expired. Searching for a new lease...",
client_config.interface);
reinit_selecting(cs, 0); reinit_selecting(cs, 0);
} }
} }
@ -200,15 +201,16 @@ static int validate_serverid(struct client_state_t *cs, struct dhcpmsg *packet,
int found; int found;
uint32_t sid = get_option_serverid(packet, &found); uint32_t sid = get_option_serverid(packet, &found);
if (!found) { if (!found) {
log_line("Received %s with no server id. Ignoring it."); log_line("%s: Received %s with no server id. Ignoring it.",
client_config.interface, typemsg);
return 0; return 0;
} }
if (cs->serverAddr != sid) { if (cs->serverAddr != sid) {
char svrbuf[INET_ADDRSTRLEN]; char svrbuf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(struct in_addr){.s_addr=sid}, inet_ntop(AF_INET, &(struct in_addr){.s_addr=sid},
svrbuf, sizeof svrbuf); svrbuf, sizeof svrbuf);
log_line("Received %s with an unexpected server id: %s. Ignoring it.", log_line("%s: Received %s with an unexpected server id: %s. Ignoring it.",
typemsg, svrbuf); client_config.interface, typemsg, svrbuf);
return 0; return 0;
} }
return 1; return 1;
@ -224,11 +226,13 @@ static void an_packet(struct client_state_t *cs, struct dhcpmsg *packet,
cs->lease = get_option_leasetime(packet); cs->lease = get_option_leasetime(packet);
cs->leaseStartTime = curms(); cs->leaseStartTime = curms();
if (!cs->lease) { if (!cs->lease) {
log_line("No lease time received, assuming 1h."); log_line("%s: No lease time received; assuming 1h.",
client_config.interface);
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_warning("Server sent lease of <1m. Forcing lease to 1m.",
client_config.interface);
cs->lease = 60; cs->lease = 60;
} }
} }
@ -245,13 +249,16 @@ static void an_packet(struct client_state_t *cs, struct dhcpmsg *packet,
char clibuf[INET_ADDRSTRLEN]; char clibuf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->clientAddr}, inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->clientAddr},
clibuf, sizeof clibuf); clibuf, sizeof clibuf);
log_line("Accepted a firm offer for %s. Validating...", clibuf); log_line("%s: Accepted a firm offer for %s. Validating...",
client_config.interface, clibuf);
if (arp_check(cs, packet) < 0) { if (arp_check(cs, packet) < 0) {
log_warning("Failed to make arp socket. Searching for new lease..."); log_warning("%s: Failed to make arp socket. Searching for new lease...",
client_config.interface);
reinit_selecting(cs, 3000); reinit_selecting(cs, 3000);
} }
} else { } else {
log_line("Lease refreshed to %u seconds.", cs->lease); log_line("%s: Lease refreshed to %u seconds.",
client_config.interface, cs->lease);
cs->dhcpState = DS_BOUND; cs->dhcpState = DS_BOUND;
arp_set_defense_mode(cs); arp_set_defense_mode(cs);
set_listen_none(cs); set_listen_none(cs);
@ -260,7 +267,8 @@ static void an_packet(struct client_state_t *cs, struct dhcpmsg *packet,
} else if (msgtype == DHCPNAK) { } else if (msgtype == DHCPNAK) {
if (!validate_serverid(cs, packet, "a DHCP NAK")) if (!validate_serverid(cs, packet, "a DHCP NAK"))
return; return;
log_line("Our request was rejected. Searching for a new lease..."); log_line("%s: Our request was rejected. Searching for a new lease...",
client_config.interface);
reinit_selecting(cs, 3000); reinit_selecting(cs, 3000);
} }
} }
@ -284,10 +292,11 @@ static void selecting_packet(struct client_state_t *cs, struct dhcpmsg *packet,
clibuf, sizeof clibuf); clibuf, sizeof clibuf);
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->serverAddr}, inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->serverAddr},
svrbuf, sizeof svrbuf); svrbuf, sizeof svrbuf);
log_line("Received an offer of %s from server %s.", log_line("%s: Received an offer of %s from server %s.",
clibuf, svrbuf); client_config.interface, clibuf, svrbuf);
} else { } else {
log_line("Invalid offer received: it didn't have a server id."); log_line("%s: Invalid offer received: it didn't have a server id.",
client_config.interface);
} }
} }
} }
@ -300,11 +309,12 @@ static void selecting_timeout(struct client_state_t *cs, long long nowts)
{ {
if (cs->init && num_dhcp_requests >= 2) { if (cs->init && num_dhcp_requests >= 2) {
if (client_config.background_if_no_lease) { if (client_config.background_if_no_lease) {
log_line("No lease, going to background."); log_line("%s: No lease; going to background.",
client_config.interface);
cs->init = 0; cs->init = 0;
background(); background();
} else if (client_config.abort_if_no_lease) } else if (client_config.abort_if_no_lease)
suicide("No lease, failing."); suicide("%s: No lease; failing.", client_config.interface);
} }
if (num_dhcp_requests == 0) if (num_dhcp_requests == 0)
cs->xid = nk_random_u32(&cs->rnd32_state); cs->xid = nk_random_u32(&cs->rnd32_state);
@ -321,21 +331,22 @@ static void xmit_release(struct client_state_t *cs)
clibuf, sizeof clibuf); clibuf, sizeof clibuf);
inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->serverAddr}, inet_ntop(AF_INET, &(struct in_addr){.s_addr=cs->serverAddr},
svrbuf, sizeof svrbuf); svrbuf, sizeof svrbuf);
log_line("Unicasting a release of %s to %s.", clibuf, svrbuf); log_line("%s: Unicasting a release of %s to %s.", client_config.interface,
clibuf, svrbuf);
send_release(cs); send_release(cs);
print_release(cs); print_release(cs);
} }
static void print_release(struct client_state_t *cs) static void print_release(struct client_state_t *cs)
{ {
log_line("ndhc going to sleep. Wake it by sending a SIGUSR1."); log_line("%s: ndhc going to sleep. Wake it by sending a SIGUSR1.", client_config.interface);
set_released(cs); set_released(cs);
} }
static void frenew(struct client_state_t *cs) static void frenew(struct client_state_t *cs)
{ {
if (cs->dhcpState == DS_BOUND) { if (cs->dhcpState == DS_BOUND) {
log_line("Forcing a DHCP renew..."); log_line("%s: Forcing a DHCP renew...", client_config.interface);
cs->dhcpState = DS_RENEWING; cs->dhcpState = DS_RENEWING;
set_listen_cooked(cs); set_listen_cooked(cs);
send_renew(cs); send_renew(cs);
@ -351,29 +362,30 @@ void ifup_action(struct client_state_t *cs)
cs->dhcpState == DS_RENEWING || cs->dhcpState == DS_RENEWING ||
cs->dhcpState == DS_REBINDING)) { cs->dhcpState == DS_REBINDING)) {
if (arp_gw_check(cs) != -1) { if (arp_gw_check(cs) != -1) {
log_line("nl: %s is back. Revalidating lease...", log_line("%s: Interface is back. Revalidating lease...",
client_config.interface); client_config.interface);
return; return;
} else } else
log_warning("nl: arp_gw_check could not make arp socket."); log_warning("%s: arp_gw_check could not make arp socket.", client_config.interface);
} }
if (cs->dhcpState == DS_SELECTING) if (cs->dhcpState == DS_SELECTING)
return; return;
log_line("nl: %s is back. Searching for new lease...", log_line("%s: Interface is back. Searching for new lease...",
client_config.interface); client_config.interface);
reinit_selecting(cs, 0); reinit_selecting(cs, 0);
} }
void ifdown_action(struct client_state_t *cs) void ifdown_action(struct client_state_t *cs)
{ {
log_line("nl: %s shut down. Going to sleep.", client_config.interface); log_line("%s: Interface shut down. Going to sleep.",
client_config.interface);
set_released(cs); set_released(cs);
} }
void ifnocarrier_action(struct client_state_t *cs) void ifnocarrier_action(struct client_state_t *cs)
{ {
(void)cs; (void)cs;
log_line("nl: %s carrier down.", client_config.interface); log_line("%s: Carrier down.", client_config.interface);
} }
void packet_action(struct client_state_t *cs, struct dhcpmsg *packet, void packet_action(struct client_state_t *cs, struct dhcpmsg *packet,