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