summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorThomas Markwalder <tmark@isc.org>2017-11-27 08:54:00 -0500
committerThomas Markwalder <tmark@isc.org>2017-11-27 08:55:13 -0500
commitc0e9661e70446890df9cdc3f5df48ab98b466600 (patch)
treee65c6b1ccd282b2297a74f036fe0449f1b5d407c /client
parent3e985dbf1fe0ec0cc022e57c85d7d4f1d087f402 (diff)
downloadisc-dhcp-c0e9661e70446890df9cdc3f5df48ab98b466600.tar.gz
[master] Added --prefix-len-hint command line argument to dhclient
Merges in rt43792
Diffstat (limited to 'client')
-rw-r--r--client/dhc6.c47
-rw-r--r--client/dhclient.825
-rw-r--r--client/dhclient.c19
3 files changed, 76 insertions, 15 deletions
diff --git a/client/dhc6.c b/client/dhc6.c
index ce6e03c4..a6b8ff42 100644
--- a/client/dhc6.c
+++ b/client/dhc6.c
@@ -146,6 +146,8 @@ static int dhc6_score_lease(struct client_state *client,
extern int onetry;
extern int stateless;
+extern int prefix_len_hint;
+
/*
* Assign DHCPv6 port numbers as a client.
@@ -1708,7 +1710,7 @@ dhc6_create_iaid(struct client_state *client,
int start_idx, copy_len;
memset(ia, 0, sizeof(*ia));
- if (!buffer_allocate(&ia->buffer, 12, MDL)) {
+ if (!buffer_allocate(&ia->buffer, len, MDL)) {
return (ISC_R_NOMEMORY);
}
ia->data = ia->buffer->data;
@@ -1771,18 +1773,22 @@ dhc6_bare_ia_xx(struct client_state *client,
case D6O_IA_NA:
type_string = "IA_NA";
type_option = ia_na_option;
- len = 12;
+ len = IA_NA_OFFSET;
break;
case D6O_IA_TA:
type_string = "IA_TA";
type_option = ia_ta_option;
- len = 4;
+ len = IA_TA_OFFSET;
break;
case D6O_IA_PD:
type_string = "IA_PD";
type_option = ia_pd_option;
- len = 12;
+ len = IA_PD_OFFSET;
+ if (prefix_len_hint > 0) {
+ len += IASUBOPT_PD_LEN;
+ }
break;
+
default:
return (ISC_R_FAILURE);
}
@@ -1811,7 +1817,7 @@ dhc6_bare_ia_xx(struct client_state *client,
/* If we are requesting an NA or a PD we also want to add
* the renew and rebind times we are requesting.
*/
- if (len == 12) {
+ if (ia_type != D6O_IA_TA) {
t1 = client->config->requested_lease / 2;
t2 = t1 + (t1 / 2);
putULong(ia.buffer->data + 4, t1);
@@ -1823,6 +1829,18 @@ dhc6_bare_ia_xx(struct client_state *client,
(unsigned)t2);
}
+ if (ia_type == D6O_IA_PD && prefix_len_hint > 0) {
+ unsigned char *ptr = ia.buffer->data + IA_NA_OFFSET;
+ putUShort(ptr, D6O_IAPREFIX);
+ ptr += 2;
+ putUShort(ptr, IASUBOPT_PD_LEN);
+ ptr += 2;
+ putUChar(ptr + IASUBOPT_PD_PREFLEN_OFFSET,
+ prefix_len_hint);
+ log_debug("XMT: | | X-- Request prefix ::/%u.",
+ prefix_len_hint);
+ }
+
/* and append it to the packet */
append_option(packet, &dhcpv6_universe, type_option, &ia);
data_string_forget(&ia, MDL);
@@ -2128,6 +2146,25 @@ do_init6(void *input)
data_string_forget(&addr, MDL);
}
+ } else if (prefix_len_hint > 0) {
+ memset(&addr, 0, sizeof(addr));
+ if (!buffer_allocate(&addr.buffer, 25, MDL)) {
+ log_error("Unable to allocate memory "
+ "for IAPREFIX.");
+ data_string_forget(&ia, MDL);
+ data_string_forget(&ds, MDL);
+ return;
+ }
+
+ addr.data = addr.buffer->data;
+ addr.len = 25;
+
+ putUChar(addr.buffer->data + 8, prefix_len_hint);
+ log_debug("XMT: | | X-- Request prefix ::/%u.",
+ prefix_len_hint);
+ append_option(&ia, &dhcpv6_universe, iaprefix_option,
+ &addr);
+ data_string_forget(&addr, MDL);
}
append_option(&ds, &dhcpv6_universe, ia_pd_option, &ia);
diff --git a/client/dhclient.8 b/client/dhclient.8
index 928cecbc..ab4b77d4 100644
--- a/client/dhclient.8
+++ b/client/dhclient.8
@@ -138,6 +138,10 @@ dhclient - Dynamic Host Configuration Protocol Client
.I seconds
]
[
+.B --prefix-len-hint
+.I length
+]
+[
.B -v
]
[
@@ -168,7 +172,7 @@ so on.
There are two versions of the DHCP protocol DHCPv4 and DHCPv6. At
startup the client may be started for one or the other via the
.B -4
-or
+or
.B -6
options.
.PP
@@ -301,15 +305,15 @@ combination with the
flag.
.TP
.BI \-e \ VAR=value
-Define additional environment variables for the environment where
+Define additional environment variables for the environment where
.B dhclient-script
-executes. You may specify multiple
+executes. You may specify multiple
.B \-e
options on the command line.
.TP
.BI \-r
Release the current lease and stop the running DHCP client as previously
-recorded in the PID file. When shutdown via this method
+recorded in the PID file. When shutdown via this method
.B dhclient-script
will be executed with the specific reason for calling the script set.
The client normally doesn't release the current lease as this is not
@@ -321,7 +325,7 @@ to notify the server if they wish to release an assigned IP address.
.BI \-x
Stop the running DHCP client without releasing the current lease.
Kills existing \fBdhclient\fR process as previously recorded in the
-PID file. When shutdown via this method
+PID file. When shutdown via this method
.B dhclient-script
will be executed with the specific reason for calling the script set.
.TP
@@ -336,7 +340,7 @@ one less than the specified port.
.TP
.BI \-s \ server-addr
Specify the server IP address or fully qualified domain name to use as
-a destination for DHCP protocol messages before
+a destination for DHCP protocol messages before
.B dhclient
has acquired an IP address. Normally,
.B dhclient
@@ -359,7 +363,7 @@ setting a client id in the configuration file. Overridding the
client id in this fashion is discouraged.
.TP
.BI \-I
-Use the standard DDNS scheme from RFCs 4701 & 4702.
+Use the standard DDNS scheme from RFCs 4701 & 4702.
.TP
.BI \--version
Print version number and exit.
@@ -423,6 +427,11 @@ variable. If any of the IPv6 addresses on the interface are tentative
seconds for DAD to complete. If the script ignores this variable the
parameter has no effect.
.PP
+.TP
+.BI \--prefix-len-hint \ length
+When used in conjunction with -P, it directs the client to use the given
+length to use a prefix hint of, "::/length", when requesting new prefixes.
+.PP
.I Modifying default file locations:
The following options can be used to modify the locations a client uses
for its files. They can be particularly useful if, for example,
@@ -504,7 +513,7 @@ The DHCP client provides some ability to control it while it is
running, without stopping it. This capability is provided using OMAPI,
an API for manipulating remote objects. OMAPI clients connect to the
client using TCP/IP, authenticate, and can then examine the client's
-current status and make changes to it.
+current status and make changes to it.
.PP
Rather than implementing the underlying OMAPI protocol directly, user
programs should use the dhcpctl API or OMAPI itself. Dhcpctl is a
diff --git a/client/dhclient.c b/client/dhclient.c
index 46efee50..e25ab94b 100644
--- a/client/dhclient.c
+++ b/client/dhclient.c
@@ -98,7 +98,11 @@ int wanted_ia_pd = 0;
int require_all_ias = 0; /* If the user requires all of the IAs to
be available before accepting a lease
0 = no, 1 = requries */
+#if defined(DHCPv6)
int dad_wait_time = 0;
+int prefix_len_hint = 0;
+#endif
+
char *mockup_relay = NULL;
char *progname = NULL;
@@ -156,11 +160,12 @@ static const char use_v6command[] = "Command not used for DHCPv4: %s";
#ifdef DHCP4o6
#define DHCLIENT_USAGE0 \
"[-4|-6] [-SNTPRI1dvrxi] [-nw] -4o6 <port>] [-p <port>]\n" \
-" [-D LL|LLT] [--dad-wait-time seconds]\n"
+" [-D LL|LLT] [--dad-wait-time seconds]\n" \
+" [--prefix-len-hint length]\n"
#else /* DHCP4o6 */
#define DHCLIENT_USAGE0 \
"[-4|-6] [-SNTPRI1dvrxi] [-nw] [-p <port>] [-D LL|LLT]\n" \
-" [--dad-wait-time seconds]\n"
+" [--dad-wait-time seconds] [--prefix-len-hint length]\n"
#endif
#else /* DHCPv6 */
#define DHCLIENT_USAGE0 \
@@ -490,7 +495,17 @@ main(int argc, char **argv) {
if (errno || (*s != '\0') || (dad_wait_time < 0)) {
usage("Invalid value for --dad-wait-time: %s", argv[i]);
}
+ } else if (!strcmp(argv[i], "--prefix-len-hint")) {
+ if (++i == argc) {
+ usage(use_noarg, argv[i-1]);
+ }
+ errno = 0;
+ prefix_len_hint = (int)strtol(argv[i], &s, 10);
+ if (errno || (*s != '\0') || (prefix_len_hint < 0)) {
+ usage("Invalid value for --prefix-len-hint: %s",
+ argv[i]);
+ }
#endif /* DHCPv6 */
} else if (!strcmp(argv[i], "-D")) {
duid_v4 = 1;