[PATCH 2/2] dhclient: add support for setting an IPv6 prefix length for IA_PD

H. Peter Anvin hpa at zytor.com
Wed Dec 2 11:44:14 UTC 2015


When requesting a prefix delegation via an IA_PD option (-P), allow a
specific prefix length to be specified, via the --prefix-len option.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>
---
 client/dhc6.c     | 20 ++++++++++++++++++++
 client/dhclient.8 |  7 +++++++
 client/dhclient.c | 13 +++++++++++--
 includes/dhcpd.h  |  1 +
 4 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/client/dhc6.c b/client/dhc6.c
index bc0aa6d5d5c9..0504f668e4d3 100644
--- a/client/dhc6.c
+++ b/client/dhc6.c
@@ -3270,6 +3270,7 @@ dhc6_make_ia_pd(const struct client_state *client,
 	TIME t1, t2;
 	struct data_string iads;
 	int pfx_count;
+	struct dhc6_addr null_prefix;
 	isc_result_t rval = ISC_R_SUCCESS;
 
 	memset(&iads, 0, sizeof iads);
@@ -3356,6 +3357,13 @@ dhc6_make_ia_pd(const struct client_state *client,
 			continue;
 		}
 
+		if (message == DHCPV6_SOLICIT &&
+		    ia_pd_plen && pref->plen > ia_pd_plen) {
+			log_info("IPv6 prefix too small, ignoring. (%s:%d)",
+				 MDL);
+			continue;
+		}
+
 		rval = dhc6_make_iaprefix(&iads, pref, t1, t2);
 		if (rval != ISC_R_SUCCESS)
 			goto fail;
@@ -3363,6 +3371,18 @@ dhc6_make_ia_pd(const struct client_state *client,
 		pfx_count++;
 	}
 
+	if (message == DHCPV6_SOLICIT && ia_pd_plen && !pfx_count) {
+		memset(&null_prefix, 0, sizeof null_prefix);
+		null_prefix.address.len = 16;
+		null_prefix.plen = ia_pd_plen;
+
+		rval = dhc6_make_iaprefix(&iads, &null_prefix, t1, t2);
+		if (rval != ISC_R_SUCCESS)
+			goto fail;
+
+		pfx_count++;
+	}
+
 	/*
 	 * It doesn't make sense to make a request without any
 	 * address, except in a solicitation.
diff --git a/client/dhclient.8 b/client/dhclient.8
index 5b056981dbee..4a8f3726ae1c 100644
--- a/client/dhclient.8
+++ b/client/dhclient.8
@@ -54,6 +54,10 @@ dhclient - Dynamic Host Configuration Protocol Client
 [
 .B -P...
 ]
+[
+.B --prefix-len
+.I bits
+]
 ]
 [
 .B -i
@@ -366,6 +370,9 @@ Enable IPv6 prefix delegation.  This implies \fB\-6\fR and also
 disables the normal address query.  See \fB\-N\fR to restore it.
 Note only one requested interface is allowed.
 .TP
+.BI \-\-prefix-len \ bits
+Set the requested size of the IPv6 prefix delegation when used with \fB\-P\fR.
+.TP
 .BI \-D \ LL\ or\ LLT
 Override the default when selecting the type of DUID to use.  By default,
 DHCPv6 \fBdhclient\fR creates an identifier based on the link-layer address
diff --git a/client/dhclient.c b/client/dhclient.c
index 3a0c0611367e..35b85eff79da 100644
--- a/client/dhclient.c
+++ b/client/dhclient.c
@@ -85,6 +85,7 @@ int onetry = 0;
 int quiet = 1;
 int nowait = 0;
 int stateless = 0;
+unsigned int ia_pd_plen = 0;
 int wanted_ia_na = -1;		/* the absolute value is the real one. */
 int wanted_ia_ta = 0;
 int wanted_ia_pd = 0;
@@ -308,6 +309,13 @@ main(int argc, char **argv) {
 				wanted_ia_na = 0;
 			}
 			wanted_ia_pd++;
+		} else if (!strcmp(argv[i], "--prefix-len")) {
+			char *ep;
+			if (++i == argc)
+				usage();
+			ia_pd_plen = strtoul(argv[i], &ep, 10);
+			if (*ep || ia_pd_plen < 4 || ia_pd_plen > 128)
+				usage();
 #endif /* DHCPv6 */
 		} else if (!strcmp(argv[i], "-D")) {
 			duid_v4 = 1;
@@ -761,9 +769,10 @@ static void usage()
 
 	log_fatal("Usage: %s "
 #ifdef DHCPv6
-		  "[-4|-6] [-SNTPI1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n"
+		  "[-4|-6] [-SNTPI1dvrxi] [--prefix-len bits]\n"
+		  "                [-nw] [-p <port>] [-D LL|LLT]\n"
 #else /* DHCPv6 */
-		  "[-I1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n"
+		  "[-I1dvrxi] [-nw] [-p <port>] [-D LL|LLT]\n"
 #endif /* DHCPv6 */
 		  "                [-s server-addr] [-cf config-file]\n"
 		  "                [-df duid-file] [-lf lease-file]\n"
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
index 02cdc5c0d309..5443ac5ea286 100644
--- a/includes/dhcpd.h
+++ b/includes/dhcpd.h
@@ -2863,6 +2863,7 @@ extern int nowait;
 extern int wanted_ia_na;
 extern int wanted_ia_ta;
 extern int wanted_ia_pd;
+extern unsigned int ia_pd_plen;
 
 extern const char *path_dhclient_conf;
 extern const char *path_dhclient_db;
-- 
2.4.3



More information about the dhcp-workers mailing list