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

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