[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    udhcpd host name issue
From:       Mahavir Jain <mahavir.coep () gmail ! com>
Date:       2009-03-30 5:51:20
Message-ID: 76fb5440903292250m3180bb36v22ddf6cb262bf485 () mail ! gmail ! com
[Download RAW message or body]

Hello,

I have dhcp server configured in busybox 1.13.3. , but for me it is
very difficult identify clients based on

dumpleases -f udhcpd.lease file . This file gives me idea of connected
clients with mac address & assigned lease.

But i could see that it is very easy to get host name of client in
bootp protocol with DHCP_HOST_NAME macro in busybox.
Following patch (attached) does trick for me , which gives me good
idea about clients.

Though not sure it works for me.



As previously suggested by vda  that dumpleases -a option is broken &
following patch is needed.
Why yet this is not included in busybox stable 1.13.3. ...?

dumpleases  -a option
is supposed to show "absolute" expiration time, but is broken.
Add these lines in networking/udhcp/dumpleases.c:

              } else /* -a */
+{
+                      expires += time(NULL);
                      fputs(ctime(&expires), stdout);
+}

to fix it.


Appreciate your kind feedback & suggestions.


Thanks

max

["review.patch" (text/x-patch)]

diff -dur busybox-1.13.3/networking/udhcp/dhcpd.h busybox-my/networking/udhcp/dhcpd.h
--- busybox-1.13.3/networking/udhcp/dhcpd.h	2009-02-26 17:16:21.000000000 +0530
+++ busybox-my/networking/udhcp/dhcpd.h	2009-03-27 18:11:45.000000000 +0530
@@ -79,10 +79,11 @@
 struct dhcpOfferedAddr {
 	uint8_t chaddr[16];
 	uint32_t yiaddr;	/* network order */
+	uint8_t hostname[30];   /* host name */
 	uint32_t expires;	/* host order */
 };
 
-struct dhcpOfferedAddr *add_lease(const uint8_t *chaddr, uint32_t yiaddr, unsigned \
long lease) FAST_FUNC; +struct dhcpOfferedAddr *add_lease(const uint8_t *chaddr, \
uint32_t yiaddr, uint8_t *hostname, unsigned long lease) FAST_FUNC;  int \
lease_expired(struct dhcpOfferedAddr *lease) FAST_FUNC;  struct dhcpOfferedAddr \
*find_lease_by_chaddr(const uint8_t *chaddr) FAST_FUNC;  struct dhcpOfferedAddr \
*find_lease_by_yiaddr(uint32_t yiaddr) FAST_FUNC; Binary files \
busybox-1.13.3/networking/udhcp/dhcpd.o and busybox-my/networking/udhcp/dhcpd.o \
                differ
diff -dur busybox-1.13.3/networking/udhcp/dumpleases.c \
                busybox-my/networking/udhcp/dumpleases.c
--- busybox-1.13.3/networking/udhcp/dumpleases.c	2009-02-26 17:16:21.000000000 +0530
+++ busybox-my/networking/udhcp/dumpleases.c	2009-03-27 15:04:00.000000000 +0530
@@ -36,8 +36,8 @@
 
 	fd = xopen(file, O_RDONLY);
 
-	printf("Mac Address       IP-Address      Expires %s\n", (opt & OPT_a) ? "at" : \
                "in");
-	/*     "00:00:00:00:00:00 255.255.255.255 Wed Jun 30 21:49:08 1993" */
+	printf("Mac Address       IP-Address      Host Name                     Expires \
%s\n", (opt & OPT_a) ? "at" : "in"); +	/*     "00:00:00:00:00:00 255.255.255.255 \
AAAAAAAAAAAAAAAAAAAAAAA       Wed Jun 30 21:49:08 1993" */  while (full_read(fd, \
&lease, sizeof(lease)) == sizeof(lease)) {  printf(":%02x"+1, lease.chaddr[0]);
 		for (i = 1; i < 6; i++) {
@@ -45,6 +45,7 @@
 		}
 		addr.s_addr = lease.yiaddr;
 		printf(" %-15s ", inet_ntoa(addr));
+		printf(" %-30s ", lease.hostname);
 		expires = ntohl(lease.expires);
 		if (!(opt & OPT_a)) { /* no -a */
 			if (!expires)
Binary files busybox-1.13.3/networking/udhcp/dumpleases.o and \
                busybox-my/networking/udhcp/dumpleases.o differ
diff -dur busybox-1.13.3/networking/udhcp/files.c busybox-my/networking/udhcp/files.c
--- busybox-1.13.3/networking/udhcp/files.c	2009-02-26 17:16:21.000000000 +0530
+++ busybox-my/networking/udhcp/files.c	2009-03-27 15:05:45.000000000 +0530
@@ -401,7 +401,7 @@
 			lease.expires = ntohl(lease.expires);
 			if (!server_config.remaining)
 				lease.expires -= time(NULL);
-			if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) {
+			if (!(add_lease(lease.chaddr, lease.yiaddr, lease.hostname, lease.expires))) {
 				bb_error_msg("too many leases while loading %s", file);
 				break;
 			}
Binary files busybox-1.13.3/networking/udhcp/files.o and \
                busybox-my/networking/udhcp/files.o differ
diff -dur busybox-1.13.3/networking/udhcp/leases.c \
                busybox-my/networking/udhcp/leases.c
--- busybox-1.13.3/networking/udhcp/leases.c	2009-02-26 17:16:21.000000000 +0530
+++ busybox-my/networking/udhcp/leases.c	2009-03-27 15:19:16.000000000 +0530
@@ -43,9 +43,10 @@
 
 
 /* add a lease into the table, clearing out any old ones */
-struct dhcpOfferedAddr* FAST_FUNC add_lease(const uint8_t *chaddr, uint32_t yiaddr, \
unsigned long lease) +struct dhcpOfferedAddr* FAST_FUNC add_lease(const uint8_t \
*chaddr, uint32_t yiaddr, uint8_t *host_name, unsigned long lease)  {
 	struct dhcpOfferedAddr *oldest;
+	uint8_t hostname_length;
 
 	/* clean out any old ones */
 	clear_lease(chaddr, yiaddr);
@@ -53,6 +54,16 @@
 	oldest = oldest_expired_lease();
 
 	if (oldest) {
+		if (host_name) 
+	        {
+        		hostname_length = *(host_name - 1);
+            		memcpy(oldest->hostname, host_name, hostname_length);
+        	}
+		else
+		{
+			oldest->hostname[0] = '\0';
+		}
+
 		memcpy(oldest->chaddr, chaddr, 16);
 		oldest->yiaddr = yiaddr;
 		oldest->expires = time(0) + lease;
@@ -112,7 +123,7 @@
 	temp.s_addr = addr;
 	bb_info_msg("%s belongs to someone, reserving it for %u seconds",
 		inet_ntoa(temp), (unsigned)server_config.conflict_time);
-	add_lease(blank_chaddr, addr, server_config.conflict_time);
+	add_lease(blank_chaddr, addr, NULL,server_config.conflict_time);
 	return 0;
 }
 
Binary files busybox-1.13.3/networking/udhcp/leases.o and \
busybox-my/networking/udhcp/leases.o differ Binary files \
                busybox-1.13.3/networking/udhcp/lib.a and \
                busybox-my/networking/udhcp/lib.a differ
diff -dur busybox-1.13.3/networking/udhcp/serverpacket.c \
                busybox-my/networking/udhcp/serverpacket.c
--- busybox-1.13.3/networking/udhcp/serverpacket.c	2009-02-26 17:16:21.000000000 \
                +0530
+++ busybox-my/networking/udhcp/serverpacket.c	2009-03-27 15:16:54.000000000 +0530
@@ -104,7 +104,7 @@
 	struct dhcpMessage packet;
 	struct dhcpOfferedAddr *lease = NULL;
 	uint32_t req_align, lease_time_align = server_config.lease;
-	uint8_t *req, *lease_time;
+	uint8_t *req, *lease_time, *p_host_name;
 	struct option_set *curr;
 	struct in_addr addr;
 
@@ -149,7 +149,10 @@
 			bb_error_msg("no IP addresses to give - OFFER abandoned");
 			return -1;
 		}
-		if (!add_lease(packet.chaddr, packet.yiaddr, server_config.offer_time)) {
+		 /* Get the host-name from the options field */
+	        p_host_name = get_option(oldpacket, DHCP_HOST_NAME);
+	
+		if (!add_lease(packet.chaddr, packet.yiaddr, p_host_name, \
server_config.offer_time)) {  bb_error_msg("lease pool is full - OFFER abandoned");
 			return -1;
 		}
@@ -205,6 +208,7 @@
 	uint8_t *lease_time;
 	uint32_t lease_time_align = server_config.lease;
 	struct in_addr addr;
+	uint8_t *p_host_name = NULL;	
 
 	init_packet(&packet, oldpacket, DHCPACK);
 	packet.yiaddr = yiaddr;
@@ -236,7 +240,10 @@
 	if (send_packet(&packet, 0) < 0)
 		return -1;
 
-	add_lease(packet.chaddr, packet.yiaddr, lease_time_align);
+	/* Get the host-name from the options field */
+	p_host_name = get_option(oldpacket, DHCP_HOST_NAME);
+
+	add_lease(packet.chaddr, packet.yiaddr, p_host_name, lease_time_align);
 	if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) {
 		/* rewrite the file with leases at every new acceptance */
 		write_leases();



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic