philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

Blame SOURCES/dhcp-4.2.5-rfc3442-classless-static-routes.patch

45d60a
diff -up dhcp-4.2.5b1/client/clparse.c.rfc3442 dhcp-4.2.5b1/client/clparse.c
45d60a
--- dhcp-4.2.5b1/client/clparse.c.rfc3442	2012-12-17 13:23:34.387564654 +0100
45d60a
+++ dhcp-4.2.5b1/client/clparse.c	2012-12-17 13:23:34.437563996 +0100
45d60a
@@ -37,7 +37,7 @@
45d60a
 
45d60a
 struct client_config top_level_config;
45d60a
 
45d60a
-#define NUM_DEFAULT_REQUESTED_OPTS	14
45d60a
+#define NUM_DEFAULT_REQUESTED_OPTS	15
45d60a
 struct option *default_requested_options[NUM_DEFAULT_REQUESTED_OPTS + 1];
45d60a
 
45d60a
 static void parse_client_default_duid(struct parse *cfile);
45d60a
@@ -90,7 +90,11 @@ isc_result_t read_client_conf ()
45d60a
 				dhcp_universe.code_hash, &code, 0, MDL);
45d60a
 
45d60a
 	/* 4 */
45d60a
-	code = DHO_ROUTERS;
45d60a
+	/* The Classless Static Routes option code MUST appear in the parameter
45d60a
+     * request list prior to both the Router option code and the Static
45d60a
+     * Routes option code, if present. (RFC3442)
45d60a
+	 */
45d60a
+	code = DHO_CLASSLESS_STATIC_ROUTES;
45d60a
 	option_code_hash_lookup(&default_requested_options[3],
45d60a
 				dhcp_universe.code_hash, &code, 0, MDL);
45d60a
 
45d60a
@@ -144,6 +148,11 @@ isc_result_t read_client_conf ()
45d60a
 	option_code_hash_lookup(&default_requested_options[13],
45d60a
 				dhcp_universe.code_hash, &code, 0, MDL);
45d60a
 
45d60a
+	/* 15 */
45d60a
+	code = DHO_ROUTERS;
45d60a
+	option_code_hash_lookup(&default_requested_options[14],
45d60a
+				dhcp_universe.code_hash, &code, 0, MDL);
45d60a
+
45d60a
 	for (code = 0 ; code < NUM_DEFAULT_REQUESTED_OPTS ; code++) {
45d60a
 		if (default_requested_options[code] == NULL)
45d60a
 			log_fatal("Unable to find option definition for "
45d60a
diff -up dhcp-4.2.5b1/common/dhcp-options.5.rfc3442 dhcp-4.2.5b1/common/dhcp-options.5
45d60a
--- dhcp-4.2.5b1/common/dhcp-options.5.rfc3442	2012-12-17 13:23:34.376564797 +0100
45d60a
+++ dhcp-4.2.5b1/common/dhcp-options.5	2012-12-17 13:25:18.435141385 +0100
45d60a
@@ -116,6 +116,26 @@ hexadecimal, separated by colons.  For e
45d60a
 or
45d60a
   option dhcp-client-identifier 43:4c:49:45:54:2d:46:4f:4f;
45d60a
 .fi
45d60a
+.PP
45d60a
+The
45d60a
+.B destination-descriptor
45d60a
+describe the IP subnet number and subnet mask
45d60a
+of a particular destination using a compact encoding. This encoding
45d60a
+consists of one octet describing the width of the subnet mask,
45d60a
+followed by all the significant octets of the subnet number.
45d60a
+The following table contains some examples of how various subnet
45d60a
+number/mask combinations can be encoded:
45d60a
+.nf
45d60a
+.sp 1
45d60a
+Subnet number   Subnet mask      Destination descriptor
45d60a
+0               0                0
45d60a
+10.0.0.0        255.0.0.0        8.10
45d60a
+10.0.0.0        255.255.255.0    24.10.0.0
45d60a
+10.17.0.0       255.255.0.0      16.10.17
45d60a
+10.27.129.0     255.255.255.0    24.10.27.129
45d60a
+10.229.0.128    255.255.255.128  25.10.229.0.128
45d60a
+10.198.122.47   255.255.255.255  32.10.198.122.47
45d60a
+.fi
45d60a
 .SH SETTING OPTION VALUES USING EXPRESSIONS
45d60a
 Sometimes it's helpful to be able to set the value of a DHCP option
45d60a
 based on some value that the client has sent.  To do this, you can
45d60a
@@ -932,6 +952,29 @@ dhclient-script will create routes:
45d60a
 .RE
45d60a
 .PP
45d60a
 .nf
45d60a
+.B option \fBclassless-static-routes\fR \fIdestination-descriptor ip-address\fR
45d60a
+                            [\fB,\fR \fIdestination-descriptor ip-address\fR...]\fB;\fR
45d60a
+.fi
45d60a
+.RS 0.25i
45d60a
+.PP
45d60a
+This option (see RFC3442) specifies a list of classless static routes
45d60a
+that the client should install in its routing cache.
45d60a
+.PP
45d60a
+This option can contain one or more static routes, each of which
45d60a
+consists of a destination descriptor and the IP address of the router
45d60a
+that should be used to reach that destination.
45d60a
+.PP
45d60a
+Many clients may not implement the Classless Static Routes option.
45d60a
+DHCP server administrators should therefore configure their DHCP
45d60a
+servers to send both a Router option and a Classless Static Routes
45d60a
+option, and should specify the default router(s) both in the Router
45d60a
+option and in the Classless Static Routes option.
45d60a
+.PP
45d60a
+If the DHCP server returns both a Classless Static Routes option and
45d60a
+a Router option, the DHCP client ignores the Router option.
45d60a
+.RE
45d60a
+.PP
45d60a
+.nf
45d60a
 .B option \fBstreettalk-directory-assistance-server\fR \fIip-address\fR
45d60a
                                            [\fB,\fR \fIip-address\fR...]\fB;\fR
45d60a
 .fi
45d60a
diff -up dhcp-4.2.5b1/common/inet.c.rfc3442 dhcp-4.2.5b1/common/inet.c
45d60a
--- dhcp-4.2.5b1/common/inet.c.rfc3442	2012-12-05 02:17:38.000000000 +0100
45d60a
+++ dhcp-4.2.5b1/common/inet.c	2012-12-17 13:23:34.440563957 +0100
45d60a
@@ -528,6 +528,60 @@ free_iaddrcidrnetlist(struct iaddrcidrne
45d60a
 	return ISC_R_SUCCESS;
45d60a
 }
45d60a
 
45d60a
+static const char *
45d60a
+inet_ntopdd(const unsigned char *src, unsigned srclen, char *dst, size_t size)
45d60a
+{
45d60a
+	char tmp[sizeof("32.255.255.255.255")];
45d60a
+	int len;
45d60a
+
45d60a
+	switch (srclen) {
45d60a
+		case 2:
45d60a
+			len = sprintf (tmp, "%u.%u", src[0], src[1]);
45d60a
+			break;
45d60a
+		case 3:
45d60a
+			len = sprintf (tmp, "%u.%u.%u", src[0], src[1], src[2]);
45d60a
+			break;
45d60a
+		case 4:
45d60a
+			len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]);
45d60a
+			break;
45d60a
+		case 5:
45d60a
+			len = sprintf (tmp, "%u.%u.%u.%u.%u", src[0], src[1], src[2], src[3], src[4]);
45d60a
+			break;
45d60a
+		default:
45d60a
+			return NULL;
45d60a
+	}
45d60a
+	if (len < 0)
45d60a
+		return NULL;
45d60a
+
45d60a
+	if (len > size) {
45d60a
+		errno = ENOSPC;
45d60a
+		return NULL;
45d60a
+	}
45d60a
+
45d60a
+	return strcpy (dst, tmp);
45d60a
+}
45d60a
+
45d60a
+/* pdestdesc() turns an iaddr structure into a printable dest. descriptor */
45d60a
+const char *
45d60a
+pdestdesc(const struct iaddr addr) {
45d60a
+	static char pbuf[sizeof("255.255.255.255.255")];
45d60a
+
45d60a
+	if (addr.len == 0) {
45d60a
+		return "<null destination descriptor>";
45d60a
+	}
45d60a
+	if (addr.len == 1) {
45d60a
+		return "0";
45d60a
+	}
45d60a
+	if ((addr.len >= 2) && (addr.len <= 5)) {
45d60a
+		return inet_ntopdd(addr.iabuf, addr.len, pbuf, sizeof(pbuf));
45d60a
+	}
45d60a
+
45d60a
+	log_fatal("pdestdesc():%s:%d: Invalid destination descriptor length %d.",
45d60a
+		  MDL, addr.len);
45d60a
+	/* quell compiler warnings */
45d60a
+	return NULL;
45d60a
+}
45d60a
+
45d60a
 /* piaddr() turns an iaddr structure into a printable address. */
45d60a
 /* XXX: should use a const pointer rather than passing the structure */
45d60a
 const char *
45d60a
diff -up dhcp-4.2.5b1/common/options.c.rfc3442 dhcp-4.2.5b1/common/options.c
45d60a
--- dhcp-4.2.5b1/common/options.c.rfc3442	2012-12-05 02:17:38.000000000 +0100
45d60a
+++ dhcp-4.2.5b1/common/options.c	2012-12-17 13:29:38.961536040 +0100
45d60a
@@ -713,7 +713,11 @@ cons_options(struct packet *inpacket, st
45d60a
 		 * packet.
45d60a
 		 */
45d60a
 		priority_list[priority_len++] = DHO_SUBNET_MASK;
45d60a
-		priority_list[priority_len++] = DHO_ROUTERS;
45d60a
+		if (lookup_option(&dhcp_universe, cfg_options,
45d60a
+							DHO_CLASSLESS_STATIC_ROUTES))
45d60a
+			priority_list[priority_len++] = DHO_CLASSLESS_STATIC_ROUTES;
45d60a
+		else
45d60a
+			priority_list[priority_len++] = DHO_ROUTERS;
45d60a
 		priority_list[priority_len++] = DHO_DOMAIN_NAME_SERVERS;
45d60a
 		priority_list[priority_len++] = DHO_HOST_NAME;
45d60a
 		priority_list[priority_len++] = DHO_FQDN;
45d60a
@@ -1694,6 +1698,7 @@ const char *pretty_print_option (option,
45d60a
 	unsigned long tval;
45d60a
 	isc_boolean_t a_array = ISC_FALSE;
45d60a
 	int len_used;
45d60a
+	unsigned int octets = 0;
45d60a
 
45d60a
 	if (emit_commas)
45d60a
 		comma = ',';
45d60a
@@ -1702,6 +1707,7 @@ const char *pretty_print_option (option,
45d60a
 
45d60a
 	memset (enumbuf, 0, sizeof enumbuf);
45d60a
 
45d60a
+	if (option->format[0] != 'R') { /* see explanation lower */
45d60a
 	/* Figure out the size of the data. */
45d60a
 	for (l = i = 0; option -> format [i]; i++, l++) {
45d60a
 		if (l >= sizeof(fmtbuf) - 1)
45d60a
@@ -1876,6 +1882,33 @@ const char *pretty_print_option (option,
45d60a
 	if (numhunk < 0)
45d60a
 		numhunk = 1;
45d60a
 
45d60a
+	} else { /* option->format[i] == 'R') */
45d60a
+		/* R (destination descriptor) has variable length.
45d60a
+		 * We can find it only in classless static route option,
45d60a
+		 * so we are for sure parsing classless static route option now.
45d60a
+		 * We go through whole the option to check whether there are no
45d60a
+		 * missing/extra bytes.
45d60a
+		 * I didn't find out how to improve the existing code and that's the
45d60a
+		 * reason for this separate 'else' where I do my own checkings.
45d60a
+		 * I know it's little bit unsystematic, but it works.
45d60a
+		 */
45d60a
+		numhunk = 0;
45d60a
+		numelem = 2; /* RI */
45d60a
+		fmtbuf[0]='R'; fmtbuf[1]='I'; fmtbuf[2]=0;
45d60a
+		for (i =0; i < len; i = i + octets + 5) {
45d60a
+			if (data[i] > 32) { /* subnet mask width */
45d60a
+				log_error ("wrong subnet mask width in destination descriptor");
45d60a
+				break;
45d60a
+			}
45d60a
+			numhunk++;
45d60a
+			octets = ((data[i]+7) / 8);
45d60a
+		}
45d60a
+		if (i != len) {
45d60a
+			log_error ("classless static routes option has wrong size or "
45d60a
+					   "there's some garbage in format");
45d60a
+		}
45d60a
+	}
45d60a
+
45d60a
 	/* Cycle through the array (or hunk) printing the data. */
45d60a
 	for (i = 0; i < numhunk; i++) {
45d60a
 		if ((a_array == ISC_TRUE) && (i != 0) && (numelem > 0)) {
45d60a
@@ -2031,6 +2064,20 @@ const char *pretty_print_option (option,
45d60a
 				strcpy(op, piaddr(iaddr));
45d60a
 				dp += 4;
45d60a
 				break;
45d60a
+
45d60a
+			      case 'R':
45d60a
+				if (dp[0] <= 32)
45d60a
+					iaddr.len = (((dp[0]+7)/8)+1);
45d60a
+				else {
45d60a
+					log_error ("wrong subnet mask width in destination descriptor");
45d60a
+					return "<error>";
45d60a
+				}
45d60a
+
45d60a
+				memcpy(iaddr.iabuf, dp, iaddr.len);
45d60a
+				strcpy(op, pdestdesc(iaddr));
45d60a
+				dp += iaddr.len;
45d60a
+				break;
45d60a
+
45d60a
 			      case '6':
45d60a
 				iaddr.len = 16;
45d60a
 				memcpy(iaddr.iabuf, dp, 16);
45d60a
diff -up dhcp-4.2.5b1/common/parse.c.rfc3442 dhcp-4.2.5b1/common/parse.c
45d60a
--- dhcp-4.2.5b1/common/parse.c.rfc3442	2012-12-17 13:23:34.408564378 +0100
45d60a
+++ dhcp-4.2.5b1/common/parse.c	2012-12-17 13:23:34.444563905 +0100
45d60a
@@ -341,6 +341,39 @@ int parse_ip_addr (cfile, addr)
45d60a
 }	
45d60a
 
45d60a
 /*
45d60a
+ * destination-descriptor :== NUMBER DOT NUMBER |
45d60a
+ *                            NUMBER DOT NUMBER DOT NUMBER |
45d60a
+ *                            NUMBER DOT NUMBER DOT NUMBER DOT NUMBER |
45d60a
+ *                            NUMBER DOT NUMBER DOT NUMBER DOT NUMBER DOT NUMBER
45d60a
+ */
45d60a
+
45d60a
+int parse_destination_descriptor (cfile, addr)
45d60a
+	struct parse *cfile;
45d60a
+	struct iaddr *addr;
45d60a
+{
45d60a
+		unsigned int mask_width, dest_dest_len;
45d60a
+		addr -> len = 0;
45d60a
+		if (parse_numeric_aggregate (cfile, addr -> iabuf,
45d60a
+									 &addr -> len, DOT, 10, 8)) {
45d60a
+			mask_width = (unsigned int)addr->iabuf[0];
45d60a
+			dest_dest_len = (((mask_width+7)/8)+1);
45d60a
+			if (mask_width > 32) {
45d60a
+				parse_warn (cfile,
45d60a
+				"subnet mask width (%u) greater than 32.", mask_width);
45d60a
+			}
45d60a
+			else if (dest_dest_len != addr->len) {
45d60a
+				parse_warn (cfile,
45d60a
+				"destination descriptor with subnet mask width %u "
45d60a
+				"should have %u octets, but has %u octets.",
45d60a
+				mask_width, dest_dest_len, addr->len);
45d60a
+			}
45d60a
+
45d60a
+			return 1;
45d60a
+		}
45d60a
+		return 0;
45d60a
+}
45d60a
+
45d60a
+/*
45d60a
  * Return true if every character in the string is hexadecimal.
45d60a
  */
45d60a
 static int
45d60a
@@ -719,8 +752,10 @@ unsigned char *parse_numeric_aggregate (
45d60a
 		if (count) {
45d60a
 			token = peek_token (&val, (unsigned *)0, cfile);
45d60a
 			if (token != separator) {
45d60a
-				if (!*max)
45d60a
+				if (!*max) {
45d60a
+					*max = count;
45d60a
 					break;
45d60a
+				}
45d60a
 				if (token != RBRACE && token != LBRACE)
45d60a
 					token = next_token (&val,
45d60a
 							    (unsigned *)0,
45d60a
@@ -1660,6 +1695,9 @@ int parse_option_code_definition (cfile,
45d60a
 	      case IP_ADDRESS:
45d60a
 		type = 'I';
45d60a
 		break;
45d60a
+	      case DESTINATION_DESCRIPTOR:
45d60a
+		type = 'R';
45d60a
+		break;
45d60a
 	      case IP6_ADDRESS:
45d60a
 		type = '6';
45d60a
 		break;
45d60a
@@ -5418,6 +5456,15 @@ int parse_option_token (rv, cfile, fmt,
45d60a
 		}
45d60a
 		break;
45d60a
 
45d60a
+	      case 'R': /* destination descriptor */
45d60a
+		if (!parse_destination_descriptor (cfile, &addr)) {
45d60a
+			return 0;
45d60a
+		}
45d60a
+		if (!make_const_data (&t, addr.iabuf, addr.len, 0, 1, MDL)) {
45d60a
+			return 0;
45d60a
+		}
45d60a
+		break;
45d60a
+
45d60a
 	      case '6': /* IPv6 address. */
45d60a
 		if (!parse_ip6_addr(cfile, &addr)) {
45d60a
 			return 0;
45d60a
@@ -5695,6 +5742,13 @@ int parse_option_decl (oc, cfile)
45d60a
 					goto exit;
45d60a
 				len = ip_addr.len;
45d60a
 				dp = ip_addr.iabuf;
45d60a
+				goto alloc;
45d60a
+
45d60a
+			      case 'R': /* destination descriptor */
45d60a
+				if (!parse_destination_descriptor (cfile, &ip_addr))
45d60a
+					goto exit;
45d60a
+				len = ip_addr.len;
45d60a
+				dp = ip_addr.iabuf;
45d60a
 
45d60a
 			      alloc:
45d60a
 				if (hunkix + len > sizeof hunkbuf) {
45d60a
diff -up dhcp-4.2.5b1/common/tables.c.rfc3442 dhcp-4.2.5b1/common/tables.c
45d60a
--- dhcp-4.2.5b1/common/tables.c.rfc3442	2012-12-17 13:23:34.398564508 +0100
45d60a
+++ dhcp-4.2.5b1/common/tables.c	2012-12-17 13:23:34.445563891 +0100
45d60a
@@ -52,6 +52,7 @@ HASH_FUNCTIONS (option_code, const unsig
45d60a
    Format codes:
45d60a
 
45d60a
    I - IPv4 address
45d60a
+   R - destination descriptor (RFC3442)
45d60a
    6 - IPv6 address
45d60a
    l - 32-bit signed integer
45d60a
    L - 32-bit unsigned integer
45d60a
@@ -210,6 +211,7 @@ static struct option dhcp_options[] = {
45d60a
 	{ "default-url", "t",			&dhcp_universe, 114, 1 },
45d60a
 	{ "subnet-selection", "I",		&dhcp_universe, 118, 1 },
45d60a
 	{ "domain-search", "D",		&dhcp_universe, 119, 1 },
45d60a
+	{ "classless-static-routes", "RIA",	&dhcp_universe, 121, 1 },
45d60a
 	{ "vivco", "Evendor-class.",		&dhcp_universe, 124, 1 },
45d60a
 	{ "vivso", "Evendor.",			&dhcp_universe, 125, 1 },
45d60a
 #if 0
45d60a
diff -up dhcp-4.2.5b1/includes/dhcpd.h.rfc3442 dhcp-4.2.5b1/includes/dhcpd.h
45d60a
--- dhcp-4.2.5b1/includes/dhcpd.h.rfc3442	2012-12-17 13:23:34.382564719 +0100
45d60a
+++ dhcp-4.2.5b1/includes/dhcpd.h	2012-12-17 13:23:34.446563877 +0100
45d60a
@@ -2678,6 +2678,7 @@ isc_result_t range2cidr(struct iaddrcidr
45d60a
 			const struct iaddr *lo, const struct iaddr *hi);
45d60a
 isc_result_t free_iaddrcidrnetlist(struct iaddrcidrnetlist **result);
45d60a
 const char *piaddr (struct iaddr);
45d60a
+const char *pdestdesc (struct iaddr);
45d60a
 char *piaddrmask(struct iaddr *, struct iaddr *);
45d60a
 char *piaddrcidr(const struct iaddr *, unsigned int);
45d60a
 u_int16_t validate_port(char *);
45d60a
@@ -2887,6 +2888,7 @@ void parse_client_lease_declaration (str
45d60a
 int parse_option_decl (struct option_cache **, struct parse *);
45d60a
 void parse_string_list (struct parse *, struct string_list **, int);
45d60a
 int parse_ip_addr (struct parse *, struct iaddr *);
45d60a
+int parse_destination_descriptor (struct parse *, struct iaddr *);
45d60a
 int parse_ip_addr_with_subnet(struct parse *, struct iaddrmatch *);
45d60a
 void parse_reject_statement (struct parse *, struct client_config *);
45d60a
 
45d60a
diff -up dhcp-4.2.5b1/includes/dhcp.h.rfc3442 dhcp-4.2.5b1/includes/dhcp.h
45d60a
--- dhcp-4.2.5b1/includes/dhcp.h.rfc3442	2012-10-23 21:02:13.000000000 +0200
45d60a
+++ dhcp-4.2.5b1/includes/dhcp.h	2012-12-17 13:23:34.446563877 +0100
45d60a
@@ -163,6 +163,7 @@ struct dhcp_packet {
45d60a
 #define DHO_ASSOCIATED_IP			92
45d60a
 #define DHO_SUBNET_SELECTION			118 /* RFC3011! */
45d60a
 #define DHO_DOMAIN_SEARCH			119 /* RFC3397 */
45d60a
+#define DHO_CLASSLESS_STATIC_ROUTES		121 /* RFC3442 */
45d60a
 #define DHO_VIVCO_SUBOPTIONS			124
45d60a
 #define DHO_VIVSO_SUBOPTIONS			125
45d60a
 
45d60a
diff -up dhcp-4.2.5b1/includes/dhctoken.h.rfc3442 dhcp-4.2.5b1/includes/dhctoken.h
45d60a
--- dhcp-4.2.5b1/includes/dhctoken.h.rfc3442	2012-12-17 13:23:34.348565167 +0100
45d60a
+++ dhcp-4.2.5b1/includes/dhctoken.h	2012-12-17 13:23:34.446563877 +0100
45d60a
@@ -365,7 +365,8 @@ enum dhcp_token {
45d60a
 	PRIMARY6 = 666,
45d60a
 	SECONDARY6 = 667,
45d60a
 	TOKEN_INFINIBAND = 668,
45d60a
-	BOOTP_BROADCAST_ALWAYS = 669
45d60a
+	BOOTP_BROADCAST_ALWAYS = 669,
45d60a
+	DESTINATION_DESCRIPTOR = 670
45d60a
 };
45d60a
 
45d60a
 #define is_identifier(x)	((x) >= FIRST_TOKEN &&	\