dhcpv4: log requests and replies to syslog
authorChristian Mehlis <christian@m3hlis.de>
Tue, 12 Aug 2014 12:30:02 +0000 (14:30 +0200)
committerChristian Mehlis <christian@m3hlis.de>
Tue, 12 Aug 2014 12:31:56 +0000 (14:31 +0200)
This change let odhcpd print dhcpv4 events
to syslog.

src/dhcpv4.c

index 2093ecd037b173df7b286f9e08983dae945a8266..7fe5bd8d4eb6971cfe5f6f354d9c4bca5723e6e2 100644 (file)
@@ -45,6 +45,29 @@ int init_dhcpv4(void)
        return 0;
 }
 
+char *dhcpv4_msg_to_string(uint8_t reqmsg)
+{
+       switch (reqmsg) {
+       case (DHCPV4_MSG_DISCOVER):
+               return "DHCPV4_MSG_DISCOVER";
+       case (DHCPV4_MSG_OFFER):
+               return "DHCPV4_MSG_OFFER";
+       case (DHCPV4_MSG_REQUEST):
+               return "DHCPV4_MSG_REQUEST";
+       case (DHCPV4_MSG_DECLINE):
+               return "DHCPV4_MSG_DECLINE";
+       case (DHCPV4_MSG_ACK):
+               return "DHCPV4_MSG_ACK";
+       case (DHCPV4_MSG_NAK):
+               return "DHCPV4_MSG_NAK";
+       case (DHCPV4_MSG_RELEASE):
+               return "DHCPV4_MSG_RELEASE";
+       case (DHCPV4_MSG_INFORM):
+               return "DHCPV4_MSG_INFORM";
+       default:
+               return "UNKNOWN";
+       }
+}
 
 int setup_dhcpv4_interface(struct interface *iface, bool enable)
 {
@@ -337,6 +360,11 @@ static void handle_dhcpv4(void *addr, void *data, size_t len,
                lease = NULL;
        }
 
+       syslog(LOG_WARNING, "received %s from %x:%x:%x:%x:%x:%x",
+                       dhcpv4_msg_to_string(reqmsg),
+                       req->chaddr[0],req->chaddr[1],req->chaddr[2],
+                       req->chaddr[3],req->chaddr[4],req->chaddr[5]);
+
        if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE)
                return;
 
@@ -419,6 +447,11 @@ static void handle_dhcpv4(void *addr, void *data, size_t len,
                ioctl(sock, SIOCSARP, &arp);
        }
 
+       syslog(LOG_WARNING, "sending %s to %x:%x:%x:%x:%x:%x",
+                       dhcpv4_msg_to_string(msg),
+                       req->chaddr[0],req->chaddr[1],req->chaddr[2],
+                       req->chaddr[3],req->chaddr[4],req->chaddr[5]);
+
        sendto(sock, &reply, sizeof(reply), MSG_DONTWAIT,
                        (struct sockaddr*)&dest, sizeof(dest));
 }