8173a68
diff -up dhcp-4.3.4/client/clparse.c.rfc3442 dhcp-4.3.4/client/clparse.c
8173a68
--- dhcp-4.3.4/client/clparse.c.rfc3442	2016-04-29 12:23:34.192032714 +0200
8173a68
+++ dhcp-4.3.4/client/clparse.c	2016-04-29 12:24:37.531016317 +0200
90936e4
@@ -31,7 +31,7 @@
a21bc05
 
a21bc05
 struct client_config top_level_config;
a21bc05
 
a21bc05
-#define NUM_DEFAULT_REQUESTED_OPTS	14
a21bc05
+#define NUM_DEFAULT_REQUESTED_OPTS	15
8173a68
 /* There can be 2 extra requested options for DHCPv4-over-DHCPv6. */
8173a68
 struct option *default_requested_options[NUM_DEFAULT_REQUESTED_OPTS + 2 + 1];
a21bc05
 
8173a68
@@ -87,7 +87,11 @@ isc_result_t read_client_conf ()
a21bc05
 				dhcp_universe.code_hash, &code, 0, MDL);
a21bc05
 
a21bc05
 	/* 4 */
a21bc05
-	code = DHO_ROUTERS;
a21bc05
+	/* The Classless Static Routes option code MUST appear in the parameter
a21bc05
+     * request list prior to both the Router option code and the Static
a21bc05
+     * Routes option code, if present. (RFC3442)
a21bc05
+	 */
a21bc05
+	code = DHO_CLASSLESS_STATIC_ROUTES;
a21bc05
 	option_code_hash_lookup(&default_requested_options[3],
a21bc05
 				dhcp_universe.code_hash, &code, 0, MDL);
a21bc05
 
8173a68
@@ -141,6 +145,11 @@ isc_result_t read_client_conf ()
a21bc05
 	option_code_hash_lookup(&default_requested_options[13],
a21bc05
 				dhcp_universe.code_hash, &code, 0, MDL);
a21bc05
 
a21bc05
+	/* 15 */
a21bc05
+	code = DHO_ROUTERS;
a21bc05
+	option_code_hash_lookup(&default_requested_options[14],
a21bc05
+				dhcp_universe.code_hash, &code, 0, MDL);
a21bc05
+
a21bc05
 	for (code = 0 ; code < NUM_DEFAULT_REQUESTED_OPTS ; code++) {
a21bc05
 		if (default_requested_options[code] == NULL)
a21bc05
 			log_fatal("Unable to find option definition for "
8173a68
diff -up dhcp-4.3.4/common/dhcp-options.5.rfc3442 dhcp-4.3.4/common/dhcp-options.5
8173a68
--- dhcp-4.3.4/common/dhcp-options.5.rfc3442	2016-04-29 12:23:34.183032716 +0200
8173a68
+++ dhcp-4.3.4/common/dhcp-options.5	2016-04-29 12:23:34.237032703 +0200
90936e4
@@ -111,6 +111,26 @@ hexadecimal, separated by colons.  For e
a21bc05
 or
a21bc05
   option dhcp-client-identifier 43:4c:49:45:54:2d:46:4f:4f;
a21bc05
 .fi
a21bc05
+.PP
a21bc05
+The
a21bc05
+.B destination-descriptor
a21bc05
+describe the IP subnet number and subnet mask
a21bc05
+of a particular destination using a compact encoding. This encoding
a21bc05
+consists of one octet describing the width of the subnet mask,
a21bc05
+followed by all the significant octets of the subnet number.
a21bc05
+The following table contains some examples of how various subnet
a21bc05
+number/mask combinations can be encoded:
a21bc05
+.nf
a21bc05
+.sp 1
a21bc05
+Subnet number   Subnet mask      Destination descriptor
a21bc05
+0               0                0
a21bc05
+10.0.0.0        255.0.0.0        8.10
a21bc05
+10.0.0.0        255.255.255.0    24.10.0.0
a21bc05
+10.17.0.0       255.255.0.0      16.10.17
a21bc05
+10.27.129.0     255.255.255.0    24.10.27.129
a21bc05
+10.229.0.128    255.255.255.128  25.10.229.0.128
a21bc05
+10.198.122.47   255.255.255.255  32.10.198.122.47
a21bc05
+.fi
a21bc05
 .SH SETTING OPTION VALUES USING EXPRESSIONS
a21bc05
 Sometimes it's helpful to be able to set the value of a DHCP option
c72a792
 based on some value that the client has sent.  To do this, you can
7406750
@@ -1031,6 +1051,29 @@ dhclient-script will create routes:
a21bc05
 .RE
a21bc05
 .PP
a21bc05
 .nf
a21bc05
+.B option \fBclassless-static-routes\fR \fIdestination-descriptor ip-address\fR
7b41fdb
+                            [\fB,\fR \fIdestination-descriptor ip-address\fR...]\fB;\fR
a21bc05
+.fi
a21bc05
+.RS 0.25i
a21bc05
+.PP
a21bc05
+This option (see RFC3442) specifies a list of classless static routes
a21bc05
+that the client should install in its routing cache.
a21bc05
+.PP
a21bc05
+This option can contain one or more static routes, each of which
a21bc05
+consists of a destination descriptor and the IP address of the router
a21bc05
+that should be used to reach that destination.
a21bc05
+.PP
a21bc05
+Many clients may not implement the Classless Static Routes option.
a21bc05
+DHCP server administrators should therefore configure their DHCP
a21bc05
+servers to send both a Router option and a Classless Static Routes
a21bc05
+option, and should specify the default router(s) both in the Router
a21bc05
+option and in the Classless Static Routes option.
a21bc05
+.PP
a21bc05
+If the DHCP server returns both a Classless Static Routes option and
a21bc05
+a Router option, the DHCP client ignores the Router option.
a21bc05
+.RE
a21bc05
+.PP
a21bc05
+.nf
a21bc05
 .B option \fBstreettalk-directory-assistance-server\fR \fIip-address\fR
a21bc05
                                            [\fB,\fR \fIip-address\fR...]\fB;\fR
a21bc05
 .fi
8173a68
diff -up dhcp-4.3.4/common/inet.c.rfc3442 dhcp-4.3.4/common/inet.c
8173a68
--- dhcp-4.3.4/common/inet.c.rfc3442	2016-03-22 14:16:51.000000000 +0100
8173a68
+++ dhcp-4.3.4/common/inet.c	2016-04-29 12:23:34.237032703 +0200
8173a68
@@ -519,6 +519,60 @@ free_iaddrcidrnetlist(struct iaddrcidrne
a21bc05
 	return ISC_R_SUCCESS;
a21bc05
 }
a21bc05
 
a21bc05
+static const char *
a21bc05
+inet_ntopdd(const unsigned char *src, unsigned srclen, char *dst, size_t size)
a21bc05
+{
a21bc05
+	char tmp[sizeof("32.255.255.255.255")];
a21bc05
+	int len;
a21bc05
+
a21bc05
+	switch (srclen) {
a21bc05
+		case 2:
a21bc05
+			len = sprintf (tmp, "%u.%u", src[0], src[1]);
a21bc05
+			break;
a21bc05
+		case 3:
a21bc05
+			len = sprintf (tmp, "%u.%u.%u", src[0], src[1], src[2]);
a21bc05
+			break;
a21bc05
+		case 4:
a21bc05
+			len = sprintf (tmp, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]);
a21bc05
+			break;
a21bc05
+		case 5:
a21bc05
+			len = sprintf (tmp, "%u.%u.%u.%u.%u", src[0], src[1], src[2], src[3], src[4]);
a21bc05
+			break;
a21bc05
+		default:
a21bc05
+			return NULL;
a21bc05
+	}
a21bc05
+	if (len < 0)
a21bc05
+		return NULL;
a21bc05
+
a21bc05
+	if (len > size) {
a21bc05
+		errno = ENOSPC;
a21bc05
+		return NULL;
a21bc05
+	}
a21bc05
+
a21bc05
+	return strcpy (dst, tmp);
a21bc05
+}
a21bc05
+
a21bc05
+/* pdestdesc() turns an iaddr structure into a printable dest. descriptor */
a21bc05
+const char *
a21bc05
+pdestdesc(const struct iaddr addr) {
a21bc05
+	static char pbuf[sizeof("255.255.255.255.255")];
a21bc05
+
a21bc05
+	if (addr.len == 0) {
a21bc05
+		return "<null destination descriptor>";
a21bc05
+	}
a21bc05
+	if (addr.len == 1) {
a21bc05
+		return "0";
a21bc05
+	}
a21bc05
+	if ((addr.len >= 2) && (addr.len <= 5)) {
a21bc05
+		return inet_ntopdd(addr.iabuf, addr.len, pbuf, sizeof(pbuf));
a21bc05
+	}
a21bc05
+
a21bc05
+	log_fatal("pdestdesc():%s:%d: Invalid destination descriptor length %d.",
a21bc05
+		  MDL, addr.len);
a21bc05
+	/* quell compiler warnings */
a21bc05
+	return NULL;
a21bc05
+}
a21bc05
+
a21bc05
 /* piaddr() turns an iaddr structure into a printable address. */
a21bc05
 /* XXX: should use a const pointer rather than passing the structure */
a21bc05
 const char *
8173a68
diff -up dhcp-4.3.4/common/options.c.rfc3442 dhcp-4.3.4/common/options.c
8173a68
--- dhcp-4.3.4/common/options.c.rfc3442	2016-03-22 14:16:51.000000000 +0100
8173a68
+++ dhcp-4.3.4/common/options.c	2016-04-29 12:23:34.237032703 +0200
7406750
@@ -713,7 +713,11 @@ cons_options(struct packet *inpacket, st
a21bc05
 		 * packet.
a21bc05
 		 */
a21bc05
 		priority_list[priority_len++] = DHO_SUBNET_MASK;
a21bc05
-		priority_list[priority_len++] = DHO_ROUTERS;
2b40dd8
+		if (lookup_option(&dhcp_universe, cfg_options,
2b40dd8
+							DHO_CLASSLESS_STATIC_ROUTES))
a21bc05
+			priority_list[priority_len++] = DHO_CLASSLESS_STATIC_ROUTES;
a21bc05
+		else
a21bc05
+			priority_list[priority_len++] = DHO_ROUTERS;
a21bc05
 		priority_list[priority_len++] = DHO_DOMAIN_NAME_SERVERS;
a21bc05
 		priority_list[priority_len++] = DHO_HOST_NAME;
a21bc05
 		priority_list[priority_len++] = DHO_FQDN;
7406750
@@ -1694,6 +1698,7 @@ const char *pretty_print_option (option,
a21bc05
 	unsigned long tval;
c72a792
 	isc_boolean_t a_array = ISC_FALSE;
c72a792
 	int len_used;
c72a792
+	unsigned int octets = 0;
a21bc05
 
a21bc05
 	if (emit_commas)
a21bc05
 		comma = ',';
7406750
@@ -1702,6 +1707,7 @@ const char *pretty_print_option (option,
a21bc05
 
a21bc05
 	memset (enumbuf, 0, sizeof enumbuf);
a21bc05
 
a21bc05
+	if (option->format[0] != 'R') { /* see explanation lower */
a21bc05
 	/* Figure out the size of the data. */
a21bc05
 	for (l = i = 0; option -> format [i]; i++, l++) {
a21bc05
 		if (l >= sizeof(fmtbuf) - 1)
7406750
@@ -1894,6 +1900,33 @@ const char *pretty_print_option (option,
a21bc05
 	if (numhunk < 0)
a21bc05
 		numhunk = 1;
a21bc05
 
a21bc05
+	} else { /* option->format[i] == 'R') */
a21bc05
+		/* R (destination descriptor) has variable length.
a21bc05
+		 * We can find it only in classless static route option,
a21bc05
+		 * so we are for sure parsing classless static route option now.
a21bc05
+		 * We go through whole the option to check whether there are no
a21bc05
+		 * missing/extra bytes.
a21bc05
+		 * I didn't find out how to improve the existing code and that's the
a21bc05
+		 * reason for this separate 'else' where I do my own checkings.
a21bc05
+		 * I know it's little bit unsystematic, but it works.
a21bc05
+		 */
a21bc05
+		numhunk = 0;
a21bc05
+		numelem = 2; /* RI */
a21bc05
+		fmtbuf[0]='R'; fmtbuf[1]='I'; fmtbuf[2]=0;
a21bc05
+		for (i =0; i < len; i = i + octets + 5) {
a21bc05
+			if (data[i] > 32) { /* subnet mask width */
a21bc05
+				log_error ("wrong subnet mask width in destination descriptor");
a21bc05
+				break;
a21bc05
+			}
a21bc05
+			numhunk++;
a21bc05
+			octets = ((data[i]+7) / 8);
a21bc05
+		}
a21bc05
+		if (i != len) {
a21bc05
+			log_error ("classless static routes option has wrong size or "
a21bc05
+					   "there's some garbage in format");
a21bc05
+		}
a21bc05
+	}
a21bc05
+
a21bc05
 	/* Cycle through the array (or hunk) printing the data. */
a21bc05
 	for (i = 0; i < numhunk; i++) {
c72a792
 		if ((a_array == ISC_TRUE) && (i != 0) && (numelem > 0)) {
7406750
@@ -2049,6 +2082,20 @@ const char *pretty_print_option (option,
a21bc05
 				strcpy(op, piaddr(iaddr));
a21bc05
 				dp += 4;
a21bc05
 				break;
a21bc05
+
a21bc05
+			      case 'R':
a21bc05
+				if (dp[0] <= 32)
a21bc05
+					iaddr.len = (((dp[0]+7)/8)+1);
a21bc05
+				else {
a21bc05
+					log_error ("wrong subnet mask width in destination descriptor");
a21bc05
+					return "<error>";
a21bc05
+				}
a21bc05
+
a21bc05
+				memcpy(iaddr.iabuf, dp, iaddr.len);
a21bc05
+				strcpy(op, pdestdesc(iaddr));
a21bc05
+				dp += iaddr.len;
a21bc05
+				break;
a21bc05
+
a21bc05
 			      case '6':
a21bc05
 				iaddr.len = 16;
a21bc05
 				memcpy(iaddr.iabuf, dp, 16);
8173a68
diff -up dhcp-4.3.4/common/parse.c.rfc3442 dhcp-4.3.4/common/parse.c
8173a68
--- dhcp-4.3.4/common/parse.c.rfc3442	2016-04-29 12:23:34.220032707 +0200
8173a68
+++ dhcp-4.3.4/common/parse.c	2016-04-29 12:23:34.238032702 +0200
7406750
@@ -341,6 +341,39 @@ int parse_ip_addr (cfile, addr)
a21bc05
 }	
a21bc05
 
a21bc05
 /*
a21bc05
+ * destination-descriptor :== NUMBER DOT NUMBER |
a21bc05
+ *                            NUMBER DOT NUMBER DOT NUMBER |
a21bc05
+ *                            NUMBER DOT NUMBER DOT NUMBER DOT NUMBER |
a21bc05
+ *                            NUMBER DOT NUMBER DOT NUMBER DOT NUMBER DOT NUMBER
a21bc05
+ */
a21bc05
+
a21bc05
+int parse_destination_descriptor (cfile, addr)
a21bc05
+	struct parse *cfile;
a21bc05
+	struct iaddr *addr;
a21bc05
+{
a21bc05
+		unsigned int mask_width, dest_dest_len;
a21bc05
+		addr -> len = 0;
a21bc05
+		if (parse_numeric_aggregate (cfile, addr -> iabuf,
a21bc05
+									 &addr -> len, DOT, 10, 8)) {
a21bc05
+			mask_width = (unsigned int)addr->iabuf[0];
a21bc05
+			dest_dest_len = (((mask_width+7)/8)+1);
a21bc05
+			if (mask_width > 32) {
a21bc05
+				parse_warn (cfile,
a21bc05
+				"subnet mask width (%u) greater than 32.", mask_width);
a21bc05
+			}
a21bc05
+			else if (dest_dest_len != addr->len) {
a21bc05
+				parse_warn (cfile,
a21bc05
+				"destination descriptor with subnet mask width %u "
a21bc05
+				"should have %u octets, but has %u octets.",
a21bc05
+				mask_width, dest_dest_len, addr->len);
a21bc05
+			}
a21bc05
+
a21bc05
+			return 1;
a21bc05
+		}
a21bc05
+		return 0;
a21bc05
+}
a21bc05
+
a21bc05
+/*
a21bc05
  * Return true if every character in the string is hexadecimal.
a21bc05
  */
a21bc05
 static int
7406750
@@ -720,8 +753,10 @@ unsigned char *parse_numeric_aggregate (
a21bc05
 		if (count) {
a21bc05
 			token = peek_token (&val, (unsigned *)0, cfile);
a21bc05
 			if (token != separator) {
a21bc05
-				if (!*max)
a21bc05
+				if (!*max) {
a21bc05
+					*max = count;
a21bc05
 					break;
a21bc05
+				}
a21bc05
 				if (token != RBRACE && token != LBRACE)
a21bc05
 					token = next_token (&val,
a21bc05
 							    (unsigned *)0,
7406750
@@ -1668,6 +1703,9 @@ int parse_option_code_definition (cfile,
a21bc05
 	      case IP_ADDRESS:
a21bc05
 		type = 'I';
a21bc05
 		break;
a21bc05
+	      case DESTINATION_DESCRIPTOR:
a21bc05
+		type = 'R';
a21bc05
+		break;
a21bc05
 	      case IP6_ADDRESS:
a21bc05
 		type = '6';
a21bc05
 		break;
7406750
@@ -5097,6 +5135,15 @@ int parse_option_token (rv, cfile, fmt,
a21bc05
 		}
a21bc05
 		break;
a21bc05
 
a21bc05
+	      case 'R': /* destination descriptor */
a21bc05
+		if (!parse_destination_descriptor (cfile, &addr)) {
a21bc05
+			return 0;
a21bc05
+		}
a21bc05
+		if (!make_const_data (&t, addr.iabuf, addr.len, 0, 1, MDL)) {
a21bc05
+			return 0;
a21bc05
+		}
a21bc05
+		break;
a21bc05
+
a21bc05
 	      case '6': /* IPv6 address. */
a21bc05
 		if (!parse_ip6_addr(cfile, &addr)) {
a21bc05
 			return 0;
7406750
@@ -5374,6 +5421,13 @@ int parse_option_decl (oc, cfile)
a21bc05
 					goto exit;
a21bc05
 				len = ip_addr.len;
a21bc05
 				dp = ip_addr.iabuf;
a21bc05
+				goto alloc;
a21bc05
+
a21bc05
+			      case 'R': /* destination descriptor */
a21bc05
+				if (!parse_destination_descriptor (cfile, &ip_addr))
a21bc05
+					goto exit;
a21bc05
+				len = ip_addr.len;
a21bc05
+				dp = ip_addr.iabuf;
a21bc05
 
a21bc05
 			      alloc:
a21bc05
 				if (hunkix + len > sizeof hunkbuf) {
8173a68
diff -up dhcp-4.3.4/common/tables.c.rfc3442 dhcp-4.3.4/common/tables.c
8173a68
--- dhcp-4.3.4/common/tables.c.rfc3442	2016-04-29 12:23:34.209032710 +0200
8173a68
+++ dhcp-4.3.4/common/tables.c	2016-04-29 12:23:34.238032702 +0200
8173a68
@@ -45,6 +45,7 @@ HASH_FUNCTIONS (option_code, const unsig
a21bc05
    Format codes:
a21bc05
 
a21bc05
    I - IPv4 address
a21bc05
+   R - destination descriptor (RFC3442)
a21bc05
    6 - IPv6 address
a21bc05
    l - 32-bit signed integer
a21bc05
    L - 32-bit unsigned integer
8173a68
@@ -216,6 +217,7 @@ static struct option dhcp_options[] = {
90936e4
 #endif
a21bc05
 	{ "subnet-selection", "I",		&dhcp_universe, 118, 1 },
90936e4
 	{ "domain-search", "D",			&dhcp_universe, 119, 1 },
a21bc05
+	{ "classless-static-routes", "RIA",	&dhcp_universe, 121, 1 },
a21bc05
 	{ "vivco", "Evendor-class.",		&dhcp_universe, 124, 1 },
a21bc05
 	{ "vivso", "Evendor.",			&dhcp_universe, 125, 1 },
a21bc05
 #if 0
8173a68
diff -up dhcp-4.3.4/includes/dhcpd.h.rfc3442 dhcp-4.3.4/includes/dhcpd.h
8173a68
--- dhcp-4.3.4/includes/dhcpd.h.rfc3442	2016-04-29 12:23:34.186032716 +0200
8173a68
+++ dhcp-4.3.4/includes/dhcpd.h	2016-04-29 12:23:34.239032702 +0200
8173a68
@@ -2894,6 +2894,7 @@ isc_result_t range2cidr(struct iaddrcidr
a21bc05
 			const struct iaddr *lo, const struct iaddr *hi);
a21bc05
 isc_result_t free_iaddrcidrnetlist(struct iaddrcidrnetlist **result);
bb77af8
 const char *piaddr (struct iaddr);
bb77af8
+const char *pdestdesc (struct iaddr);
a21bc05
 char *piaddrmask(struct iaddr *, struct iaddr *);
a21bc05
 char *piaddrcidr(const struct iaddr *, unsigned int);
a21bc05
 u_int16_t validate_port(char *);
8173a68
@@ -3108,6 +3109,7 @@ void parse_client_lease_declaration (str
bb77af8
 int parse_option_decl (struct option_cache **, struct parse *);
bb77af8
 void parse_string_list (struct parse *, struct string_list **, int);
bb77af8
 int parse_ip_addr (struct parse *, struct iaddr *);
bb77af8
+int parse_destination_descriptor (struct parse *, struct iaddr *);
a21bc05
 int parse_ip_addr_with_subnet(struct parse *, struct iaddrmatch *);
bb77af8
 void parse_reject_statement (struct parse *, struct client_config *);
a21bc05
 
8173a68
diff -up dhcp-4.3.4/includes/dhcp.h.rfc3442 dhcp-4.3.4/includes/dhcp.h
8173a68
--- dhcp-4.3.4/includes/dhcp.h.rfc3442	2016-03-22 14:16:51.000000000 +0100
8173a68
+++ dhcp-4.3.4/includes/dhcp.h	2016-04-29 12:23:34.239032702 +0200
90936e4
@@ -159,6 +159,7 @@ struct dhcp_packet {
90936e4
 #define DHO_ASSOCIATED_IP			92
90936e4
 #define DHO_SUBNET_SELECTION			118 /* RFC3011! */
90936e4
 #define DHO_DOMAIN_SEARCH			119 /* RFC3397 */
90936e4
+#define DHO_CLASSLESS_STATIC_ROUTES		121 /* RFC3442 */
90936e4
 #define DHO_VIVCO_SUBOPTIONS			124
90936e4
 #define DHO_VIVSO_SUBOPTIONS			125
90936e4
 
8173a68
diff -up dhcp-4.3.4/includes/dhctoken.h.rfc3442 dhcp-4.3.4/includes/dhctoken.h
8173a68
--- dhcp-4.3.4/includes/dhctoken.h.rfc3442	2016-04-29 12:23:34.239032702 +0200
8173a68
+++ dhcp-4.3.4/includes/dhctoken.h	2016-04-29 12:25:07.236008628 +0200
8173a68
@@ -374,7 +374,8 @@ enum dhcp_token {
8173a68
 	LEASE_ID_FORMAT = 676,
8173a68
 	TOKEN_HEX = 677,
8173a68
 	TOKEN_OCTAL = 678,
97ad575
-	BOOTP_BROADCAST_ALWAYS = 679
97ad575
+	BOOTP_BROADCAST_ALWAYS = 679,
97ad575
+	DESTINATION_DESCRIPTOR = 680
a21bc05
 };
a21bc05
 
a21bc05
 #define is_identifier(x)	((x) >= FIRST_TOKEN &&	\