[aadk-commits] dbailey: uClinux/trunk r472 - /uClinux/trunk/uClinux-dist/user/busybox/networ...

SVN commits to the AADK repository aadk-commits at lists.digium.com
Mon Jun 18 12:30:42 CDT 2007


Author: dbailey
Date: Mon Jun 18 12:30:42 2007
New Revision: 472

URL: http://svn.digium.com/view/aadk?view=rev&rev=472
Log:
Added config file option of authoritative mode.  (Defaults to yes)
Added non-authoritative mode where the server responds only to DHCPINFORM requests

Modified:
    uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.c
    uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.h
    uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/files.c

Modified: uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.c
URL: http://svn.digium.com/view/aadk/uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.c?view=diff&rev=472&r1=471&r2=472
==============================================================================
--- uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.c (original)
+++ uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.c Mon Jun 18 12:30:42 2007
@@ -87,18 +87,19 @@
 	}
 	else server_config.lease = LEASE_TIME;
 
-	/* Sanity check */
-	num_ips = ntohl(server_config.end) - ntohl(server_config.start);
-	if (server_config.max_leases > num_ips) {
-		LOG(LOG_ERR, "max_leases value (%lu) not sane, "
-			"setting to %lu instead",
-			server_config.max_leases, num_ips);
-		server_config.max_leases = num_ips;
+	if(server_config.authoritative) {
+		/* Sanity check */
+		num_ips = ntohl(server_config.end) - ntohl(server_config.start);
+		if (server_config.max_leases > num_ips) {
+			LOG(LOG_ERR, "max_leases value (%lu) not sane, "
+				"setting to %lu instead",
+				server_config.max_leases, num_ips);
+			server_config.max_leases = num_ips;
+		}
+		leases = xcalloc(server_config.max_leases, sizeof(struct dhcpOfferedAddr));
+		read_leases(server_config.lease_file);
 	}
-
-	leases = xcalloc(server_config.max_leases, sizeof(struct dhcpOfferedAddr));
-	read_leases(server_config.lease_file);
-
+	
 	if (read_interface(server_config.interface, &server_config.ifindex,
 			   &server_config.server, server_config.arp) < 0)
 		return 1;
@@ -165,106 +166,116 @@
 			DEBUG(LOG_ERR, "couldn't get option from packet, ignoring");
 			continue;
 		}
-
-		/* Look for a static lease */
-		static_lease_ip = getIpByMac(server_config.static_leases, &packet.chaddr);
-
-		if(static_lease_ip)
-		{
-			printf("Found static lease: %x\n", static_lease_ip);
-
-			memcpy(&static_lease.chaddr, &packet.chaddr, 16);
-			static_lease.yiaddr = static_lease_ip;
-			static_lease.expires = 0;
-
-			lease = &static_lease;
-
-		}
-		else
-		{
-		lease = find_lease_by_chaddr(packet.chaddr);
-		}
-
-		switch (state[0]) {
-		case DHCPDISCOVER:
-			DEBUG(LOG_INFO,"received DISCOVER");
-
-			if (sendOffer(&packet) < 0) {
-				LOG(LOG_ERR, "send OFFER failed");
-			}
-			break;
- 		case DHCPREQUEST:
-			DEBUG(LOG_INFO, "received REQUEST");
-
-			requested = get_option(&packet, DHCP_REQUESTED_IP);
-			server_id = get_option(&packet, DHCP_SERVER_ID);
-
-			if (requested) memcpy(&requested_align, requested, 4);
-			if (server_id) memcpy(&server_id_align, server_id, 4);
-
-			if (lease) {
-				if (server_id) {
-					/* SELECTING State */
-					DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align));
-					if (server_id_align == server_config.server && requested &&
-					    requested_align == lease->yiaddr) {
-						sendACK(&packet, lease->yiaddr);
-					}
-				} else {
-					if (requested) {
-						/* INIT-REBOOT State */
-						if (lease->yiaddr == requested_align)
+		
+		/* If server is running in authoritative mode */
+		if(server_config.authoritative) {
+			/* Look for a static lease */
+			static_lease_ip = getIpByMac(server_config.static_leases, &packet.chaddr);
+			if(static_lease_ip)
+			{
+				printf("Found static lease: %x\n", static_lease_ip);
+	
+				memcpy(&static_lease.chaddr, &packet.chaddr, 16);
+				static_lease.yiaddr = static_lease_ip;
+				static_lease.expires = 0;
+	
+				lease = &static_lease;
+	
+			}
+			else
+			{
+				lease = find_lease_by_chaddr(packet.chaddr);
+			}
+
+			switch (state[0]) {
+			case DHCPDISCOVER:
+				DEBUG(LOG_INFO,"received DISCOVER");
+				if (sendOffer(&packet) < 0) {
+					LOG(LOG_ERR, "send OFFER failed");
+				}
+				break;
+			case DHCPREQUEST:
+				DEBUG(LOG_INFO, "received REQUEST");
+	
+				requested = get_option(&packet, DHCP_REQUESTED_IP);
+				server_id = get_option(&packet, DHCP_SERVER_ID);
+	
+				if (requested) memcpy(&requested_align, requested, 4);
+				if (server_id) memcpy(&server_id_align, server_id, 4);
+	
+				if (lease) {
+					if (server_id) {
+						/* SELECTING State */
+						DEBUG(LOG_INFO, "server_id = %08x", ntohl(server_id_align));
+						if (server_id_align == server_config.server && requested &&
+							requested_align == lease->yiaddr) {
 							sendACK(&packet, lease->yiaddr);
-						else sendNAK(&packet);
+						}
 					} else {
-						/* RENEWING or REBINDING State */
-						if (lease->yiaddr == packet.ciaddr)
-							sendACK(&packet, lease->yiaddr);
-						else {
-							/* don't know what to do!!!! */
-							sendNAK(&packet);
+						if (requested) {
+							/* INIT-REBOOT State */
+							if (lease->yiaddr == requested_align)
+								sendACK(&packet, lease->yiaddr);
+							else sendNAK(&packet);
+						} else {
+							/* RENEWING or REBINDING State */
+							if (lease->yiaddr == packet.ciaddr)
+								sendACK(&packet, lease->yiaddr);
+							else {
+								/* don't know what to do!!!! */
+								sendNAK(&packet);
+							}
 						}
 					}
+	
+				/* what to do if we have no record of the client */
+				} else if (server_id) {
+					/* SELECTING State */
+	
+				} else if (requested) {
+					/* INIT-REBOOT State */
+					if ((lease = find_lease_by_yiaddr(requested_align))) {
+						if (lease_expired(lease)) {
+							/* probably best if we drop this lease */
+							memset(lease->chaddr, 0, 16);
+						/* make some contention for this address */
+						} else sendNAK(&packet);
+					} else if (requested_align < server_config.start ||
+						requested_align > server_config.end) {
+						sendNAK(&packet);
+					} /* else remain silent */
+	
+				} else {
+					/* RENEWING or REBINDING State */
 				}
-
-			/* what to do if we have no record of the client */
-			} else if (server_id) {
-				/* SELECTING State */
-
-			} else if (requested) {
-				/* INIT-REBOOT State */
-				if ((lease = find_lease_by_yiaddr(requested_align))) {
-					if (lease_expired(lease)) {
-						/* probably best if we drop this lease */
-						memset(lease->chaddr, 0, 16);
-					/* make some contention for this address */
-					} else sendNAK(&packet);
-				} else if (requested_align < server_config.start ||
-					   requested_align > server_config.end) {
-					sendNAK(&packet);
-				} /* else remain silent */
-
-			} else {
-				 /* RENEWING or REBINDING State */
-			}
-			break;
-		case DHCPDECLINE:
-			DEBUG(LOG_INFO,"received DECLINE");
-			if (lease) {
-				memset(lease->chaddr, 0, 16);
-				lease->expires = time(0) + server_config.decline_time;
-			}
-			break;
-		case DHCPRELEASE:
-			DEBUG(LOG_INFO,"received RELEASE");
-			if (lease) lease->expires = time(0);
-			break;
-		case DHCPINFORM:
-			DEBUG(LOG_INFO,"received INFORM");
-			send_inform(&packet);
-			break;
-		default:
-			LOG(LOG_WARNING, "unsupported DHCP message (%02x) -- ignoring", state[0]);
+				break;
+			case DHCPDECLINE:
+				DEBUG(LOG_INFO,"received DECLINE");
+				if (lease) {
+					memset(lease->chaddr, 0, 16);
+					lease->expires = time(0) + server_config.decline_time;
+				}
+				break;
+			case DHCPRELEASE:
+				DEBUG(LOG_INFO,"received RELEASE");
+				if (lease) lease->expires = time(0);
+				break;
+			case DHCPINFORM:
+				DEBUG(LOG_INFO,"received INFORM");
+				send_inform(&packet);
+				break;
+			default:
+				LOG(LOG_WARNING, "Authoritative Mode - unsupported DHCP message (%02x) -- ignoring", state[0]);
+			}
+		} else {	/* Else implies this is non-authoritative mode => handle DHCPINFORM Messages */
+			switch (state[0]) {
+				case DHCPINFORM:
+					DEBUG(LOG_INFO,"received INFORM");
+					send_inform(&packet);
+					break;
+				default:
+					LOG(LOG_WARNING, "NON-Authoritative Mode - unsupported DHCP message (%02x) -- ignoring", state[0]);
+			}
 		}
 	}
 

Modified: uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.h
URL: http://svn.digium.com/view/aadk/uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.h?view=diff&rev=472&r1=471&r2=472
==============================================================================
--- uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.h (original)
+++ uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.h Mon Jun 18 12:30:42 2007
@@ -117,6 +117,7 @@
 	unsigned long max_leases; 	/* maximum number of leases (including reserved address) */
 	char remaining; 		/* should the lease file be interpreted as lease time remaining, or
 			 		 * as the time the lease expires */
+	char authoritative;		/* Is the dhcp running in authoritative mode */
 	unsigned long auto_time; 	/* how long should udhcpd wait before writing a config file.
 					 * if this is zero, it will only write one on SIGUSR1 */
 	unsigned long decline_time; 	/* how long an address is reserved if a client returns a

Modified: uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/files.c
URL: http://svn.digium.com/view/aadk/uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/files.c?view=diff&rev=472&r1=471&r2=472
==============================================================================
--- uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/files.c (original)
+++ uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/files.c Mon Jun 18 12:30:42 2007
@@ -224,6 +224,7 @@
 	{"sname",	read_str, &(server_config.sname),	""},
 	{"boot_file",	read_str, &(server_config.boot_file),	""},
 	{"static_lease",read_staticlease, &(server_config.static_leases),	""},
+	{"authoritative", read_yn, &(server_config.authoritative),	"yes"},
 	/*ADDME: static lease */
 	{"",		NULL, 	  NULL,				""}
 };




More information about the aadk-commits mailing list