summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2018-06-15 14:30:18 +0200
committerHans Dedecker <dedeckeh@gmail.com>2018-06-15 14:32:28 +0200
commitd5726ff3edc32222baa7a7aea9df47f1afc53724 (patch)
tree04a92144cca6a1bd7c1ec242843a878e67f8e79d /src
parent948435112e5c4eb4802c1dfba0732dd92fb9199e (diff)
dhcpv4: improve logging when sending DHCP messages
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/dhcpv4.c52
1 files changed, 23 insertions, 29 deletions
diff --git a/src/dhcpv4.c b/src/dhcpv4.c
index 2a1d49f..9b8186f 100644
--- a/src/dhcpv4.c
+++ b/src/dhcpv4.c
@@ -584,14 +584,13 @@ static void dhcpv4_fr_send(struct dhcpv4_assignment *a)
dest.sin_port = htons(DHCPV4_CLIENT_PORT);
dest.sin_addr.s_addr = a->addr;
- syslog(LOG_WARNING, "sending %s to %02x:%02x:%02x:%02x:%02x:%02x - %s",
- dhcpv4_msg_to_string(msg),
- a->hwaddr[0], a->hwaddr[1], a->hwaddr[2],
- a->hwaddr[3], a->hwaddr[4], a->hwaddr[5],
- inet_ntoa(dest.sin_addr));
-
- sendto(iface->dhcpv4_event.uloop.fd, &fr_msg, sizeof(fr_msg),
- MSG_DONTWAIT, (struct sockaddr*)&dest, sizeof(dest));
+ if (sendto(iface->dhcpv4_event.uloop.fd, &fr_msg, sizeof(fr_msg),
+ MSG_DONTWAIT, (struct sockaddr*)&dest, sizeof(dest)) < 0)
+ syslog(LOG_ERR, "Failed to send %s to %s - %s: %m", dhcpv4_msg_to_string(msg),
+ odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr));
+ else
+ syslog(LOG_WARNING, "Sent %s to %s - %s", dhcpv4_msg_to_string(msg),
+ odhcpd_print_mac(a->hwaddr, sizeof(a->hwaddr)), inet_ntoa(dest.sin_addr));
}
static void dhcpv4_fr_timer(struct uloop_timeout *event)
@@ -762,10 +761,8 @@ static void handle_dhcpv4(void *addr, void *data, size_t len,
req->ciaddr.s_addr = INADDR_ANY;
}
- syslog(LOG_WARNING, "received %s from %02x:%02x:%02x:%02x:%02x:%02x",
- dhcpv4_msg_to_string(reqmsg),
- req->chaddr[0],req->chaddr[1],req->chaddr[2],
- req->chaddr[3],req->chaddr[4],req->chaddr[5]);
+ syslog(LOG_WARNING, "received %s from %s", dhcpv4_msg_to_string(reqmsg),
+ odhcpd_print_mac(req->chaddr, req->hlen));
#ifdef WITH_UBUS
if (reqmsg == DHCPV4_MSG_RELEASE)
@@ -905,24 +902,21 @@ static void handle_dhcpv4(void *addr, void *data, size_t len,
ioctl(sock, SIOCSARP, &arp);
}
- if (dest.sin_addr.s_addr == INADDR_BROADCAST)
- /* reply goes to IP broadcast -> MAC broadcast */
- syslog(LOG_WARNING, "sending %s to ff:ff:ff:ff:ff:ff - %s",
- dhcpv4_msg_to_string(msg),
- inet_ntoa(dest.sin_addr));
+
+ if (sendto(sock, &reply, sizeof(reply), MSG_DONTWAIT,
+ (struct sockaddr*)&dest, sizeof(dest)) < 0)
+ syslog(LOG_ERR, "Failed to send %s to %s - %s: %m",
+ dhcpv4_msg_to_string(msg),
+ dest.sin_addr.s_addr == INADDR_BROADCAST ?
+ "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen),
+ inet_ntoa(dest.sin_addr));
else
- /*
- * reply is send directly to IP,
- * MAC is assumed to be the same as the request
- */
- syslog(LOG_WARNING, "sending %s to %02x:%02x:%02x:%02x:%02x:%02x - %s",
- dhcpv4_msg_to_string(msg),
- req->chaddr[0],req->chaddr[1],req->chaddr[2],
- req->chaddr[3],req->chaddr[4],req->chaddr[5],
- inet_ntoa(dest.sin_addr));
-
- sendto(sock, &reply, sizeof(reply), MSG_DONTWAIT,
- (struct sockaddr*)&dest, sizeof(dest));
+ syslog(LOG_ERR, "Sent %s to %s - %s",
+ dhcpv4_msg_to_string(msg),
+ dest.sin_addr.s_addr == INADDR_BROADCAST ?
+ "ff:ff:ff:ff:ff:ff": odhcpd_print_mac(req->chaddr, req->hlen),
+ inet_ntoa(dest.sin_addr));
+
#ifdef WITH_UBUS
if (msg == DHCPV4_MSG_ACK)