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

SVN commits to the AADK repository aadk-commits at lists.digium.com
Mon Jul 2 09:13:00 CDT 2007


Author: dbailey
Date: Mon Jul  2 09:12:59 2007
New Revision: 498

URL: http://svn.digium.com/view/aadk?view=rev&rev=498
Log:
Add in variable substitution into the dhcp daemon

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

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=498&r1=497&r2=498
==============================================================================
--- uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.c (original)
+++ uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/dhcpd.c Mon Jul  2 09:12:59 2007
@@ -166,6 +166,10 @@
 			DEBUG(LOG_ERR, "couldn't get option from packet, ignoring");
 			continue;
 		}
+		
+		/* Re-bind the interface information every time through this loop */
+		read_interface(server_config.interface, &server_config.ifindex,
+					   &server_config.server, server_config.arp);
 		
 		/* If server is running in authoritative mode */
 		if(server_config.authoritative) {

Modified: uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/options.c
URL: http://svn.digium.com/view/aadk/uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/options.c?view=diff&rev=498&r1=497&r2=498
==============================================================================
--- uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/options.c (original)
+++ uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/options.c Mon Jul  2 09:12:59 2007
@@ -5,6 +5,8 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <ctype.h>
+#include <arpa/inet.h>
 
 #include "dhcpd.h"
 #include "files.h"
@@ -58,6 +60,20 @@
 };
 
 
+static char get_option_flags(int code)
+{
+	int i;
+	char flag = 0; 
+	for(i= 0; dhcp_options[i].code != 0; i++)
+	{
+		if(code == dhcp_options[i].code) { 
+			flag = dhcp_options[i].flags;
+			break;
+		}
+	}
+	return flag;
+}
+
 /* get an option with bounds checking (warning, not aligned). */
 uint8_t *get_option(struct dhcpMessage *packet, int code)
 {
@@ -131,16 +147,66 @@
 int add_option_string(uint8_t *optionptr, uint8_t *string)
 {
 	int end = end_option(optionptr);
+	char * embed;
+	int x, y;
+ 	uint8_t code, datalen;
+	uint8_t *data; 
+	int	need_to_free_data = 0;  
+	struct in_addr host_address; 
+	char code_flag;
+	
+	datalen = string[OPT_LEN];
+	code = string[OPT_CODE];
+	data = &(string[OPT_DATA]);
+	code_flag = get_option_flags(code);
+
+	/* If this is a string field, check to see if IP address substitution is needed */
+	if(OPTION_STRING == (TYPE_MASK & code_flag)) {  
+		embed = strstr(&(string[OPT_DATA]), VAR_SUBST_STRING);
+		if(NULL != embed) {
+			/* Need to substitute the Interface's IP address into the option */
+			data = xmalloc(datalen + MAX_V4_IP_LEN);
+			if(NULL == data){
+				LOG(LOG_ERR, "Option 0x%02x could not reconcile variable substitution!", string[OPT_CODE]);
+				return 0;
+			}
+			need_to_free_data = 1;
+			x = (int)embed - (int)&(string[OPT_DATA]);
+			embed += strlen(VAR_SUBST_STRING);
+			y = datalen - strlen(VAR_SUBST_STRING) - x;
+			/* copy the prefix to the variable */		
+			memcpy(data, &(string[OPT_DATA]), x);
+			/* Decode the IP address of the interface */		
+			host_address.s_addr = server_config.server;
+			strcpy(&(data[x]), inet_ntoa(host_address));
+			/* copy over the suffix data */
+			x = strlen(data);
+			memcpy(&(data[x]), embed, y);
+			datalen = x+y;
+		}
+	}
+	/* Else if this is an IP address option (V4 only), check to see if substitution is needed */
+	else if(OPTION_IP == (TYPE_MASK & code_flag)) {  
+		if( 4 == datalen && 0 == string[OPT_DATA]   && 0 == string[OPT_DATA+1] && 
+							0 == string[OPT_DATA+2] && 0 == string[OPT_DATA+3] ) {
+			data = &(server_config.server);
+		}
+	}
 
 	/* end position + string length + option code/length + end option */
-	if (end + string[OPT_LEN] + 2 + 1 >= 308) {
+	if (end + datalen + 3 >= 308) {
 		LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]);
 		return 0;
 	}
 	DEBUG(LOG_INFO, "adding option 0x%02x", string[OPT_CODE]);
-	memcpy(optionptr + end, string, string[OPT_LEN] + 2);
-	optionptr[end + string[OPT_LEN] + 2] = DHCP_END;
-	return string[OPT_LEN] + 2;
+	*(optionptr + end) = code;
+	*(optionptr + end +1 ) = datalen;
+	memcpy(optionptr + end + 2, data, datalen);
+	optionptr[end + datalen + 2] = DHCP_END;
+	
+	if (need_to_free_data)
+		free(data);
+	return datalen + 2;
 }
 
 

Modified: uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/options.h
URL: http://svn.digium.com/view/aadk/uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/options.h?view=diff&rev=498&r1=497&r2=498
==============================================================================
--- uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/options.h (original)
+++ uClinux/trunk/uClinux-dist/user/busybox/networking/udhcp/options.h Mon Jul  2 09:12:59 2007
@@ -30,6 +30,9 @@
 extern struct dhcp_option dhcp_options[];
 extern int option_lengths[];
 
+#define MAX_V4_IP_LEN	16
+#define VAR_SUBST_STRING "0.0.0.0"
+
 uint8_t *get_option(struct dhcpMessage *packet, int code);
 int end_option(uint8_t *optionptr);
 int add_option_string(uint8_t *optionptr, uint8_t *string);




More information about the aadk-commits mailing list