2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-29 13:28:14 +00:00

[master] Added --prefix-len-hint command line argument to dhclient

Merges in rt43792
This commit is contained in:
Thomas Markwalder 2017-11-27 08:54:00 -05:00
parent 3e985dbf1f
commit c0e9661e70
5 changed files with 93 additions and 15 deletions

View File

@ -183,6 +183,11 @@ dhcp-users@lists.isc.org.
they are received. they are received.
[ISC-Bugs #39669] [ISC-Bugs #39669]
- Added a new dhclient command line parameter, --prefix-len-hint <length>.
When used in conjunction with -P, it directs dhclient to use the given
length as the prefix length hint when requesting prefixes.
[ISC-Bugs #43792]
Changes since 4.3.0 (bug fixes) Changes since 4.3.0 (bug fixes)
- Tidy up several small tickets. - Tidy up several small tickets.

View File

@ -146,6 +146,8 @@ static int dhc6_score_lease(struct client_state *client,
extern int onetry; extern int onetry;
extern int stateless; extern int stateless;
extern int prefix_len_hint;
/* /*
* Assign DHCPv6 port numbers as a client. * Assign DHCPv6 port numbers as a client.
@ -1708,7 +1710,7 @@ dhc6_create_iaid(struct client_state *client,
int start_idx, copy_len; int start_idx, copy_len;
memset(ia, 0, sizeof(*ia)); memset(ia, 0, sizeof(*ia));
if (!buffer_allocate(&ia->buffer, 12, MDL)) { if (!buffer_allocate(&ia->buffer, len, MDL)) {
return (ISC_R_NOMEMORY); return (ISC_R_NOMEMORY);
} }
ia->data = ia->buffer->data; ia->data = ia->buffer->data;
@ -1771,18 +1773,22 @@ dhc6_bare_ia_xx(struct client_state *client,
case D6O_IA_NA: case D6O_IA_NA:
type_string = "IA_NA"; type_string = "IA_NA";
type_option = ia_na_option; type_option = ia_na_option;
len = 12; len = IA_NA_OFFSET;
break; break;
case D6O_IA_TA: case D6O_IA_TA:
type_string = "IA_TA"; type_string = "IA_TA";
type_option = ia_ta_option; type_option = ia_ta_option;
len = 4; len = IA_TA_OFFSET;
break; break;
case D6O_IA_PD: case D6O_IA_PD:
type_string = "IA_PD"; type_string = "IA_PD";
type_option = ia_pd_option; type_option = ia_pd_option;
len = 12; len = IA_PD_OFFSET;
if (prefix_len_hint > 0) {
len += IASUBOPT_PD_LEN;
}
break; break;
default: default:
return (ISC_R_FAILURE); 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 /* If we are requesting an NA or a PD we also want to add
* the renew and rebind times we are requesting. * the renew and rebind times we are requesting.
*/ */
if (len == 12) { if (ia_type != D6O_IA_TA) {
t1 = client->config->requested_lease / 2; t1 = client->config->requested_lease / 2;
t2 = t1 + (t1 / 2); t2 = t1 + (t1 / 2);
putULong(ia.buffer->data + 4, t1); putULong(ia.buffer->data + 4, t1);
@ -1823,6 +1829,18 @@ dhc6_bare_ia_xx(struct client_state *client,
(unsigned)t2); (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 */ /* and append it to the packet */
append_option(packet, &dhcpv6_universe, type_option, &ia); append_option(packet, &dhcpv6_universe, type_option, &ia);
data_string_forget(&ia, MDL); data_string_forget(&ia, MDL);
@ -2128,6 +2146,25 @@ do_init6(void *input)
data_string_forget(&addr, MDL); 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); append_option(&ds, &dhcpv6_universe, ia_pd_option, &ia);

View File

@ -138,6 +138,10 @@ dhclient - Dynamic Host Configuration Protocol Client
.I seconds .I seconds
] ]
[ [
.B --prefix-len-hint
.I length
]
[
.B -v .B -v
] ]
[ [
@ -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 seconds for DAD to complete. If the script ignores this variable the
parameter has no effect. parameter has no effect.
.PP .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: .I Modifying default file locations:
The following options can be used to modify the locations a client uses The following options can be used to modify the locations a client uses
for its files. They can be particularly useful if, for example, for its files. They can be particularly useful if, for example,

View File

@ -98,7 +98,11 @@ int wanted_ia_pd = 0;
int require_all_ias = 0; /* If the user requires all of the IAs to int require_all_ias = 0; /* If the user requires all of the IAs to
be available before accepting a lease be available before accepting a lease
0 = no, 1 = requries */ 0 = no, 1 = requries */
#if defined(DHCPv6)
int dad_wait_time = 0; int dad_wait_time = 0;
int prefix_len_hint = 0;
#endif
char *mockup_relay = NULL; char *mockup_relay = NULL;
char *progname = NULL; char *progname = NULL;
@ -156,11 +160,12 @@ static const char use_v6command[] = "Command not used for DHCPv4: %s";
#ifdef DHCP4o6 #ifdef DHCP4o6
#define DHCLIENT_USAGE0 \ #define DHCLIENT_USAGE0 \
"[-4|-6] [-SNTPRI1dvrxi] [-nw] -4o6 <port>] [-p <port>]\n" \ "[-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 */ #else /* DHCP4o6 */
#define DHCLIENT_USAGE0 \ #define DHCLIENT_USAGE0 \
"[-4|-6] [-SNTPRI1dvrxi] [-nw] [-p <port>] [-D LL|LLT]\n" \ "[-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 #endif
#else /* DHCPv6 */ #else /* DHCPv6 */
#define DHCLIENT_USAGE0 \ #define DHCLIENT_USAGE0 \
@ -490,7 +495,17 @@ main(int argc, char **argv) {
if (errno || (*s != '\0') || (dad_wait_time < 0)) { if (errno || (*s != '\0') || (dad_wait_time < 0)) {
usage("Invalid value for --dad-wait-time: %s", argv[i]); 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 */ #endif /* DHCPv6 */
} else if (!strcmp(argv[i], "-D")) { } else if (!strcmp(argv[i], "-D")) {
duid_v4 = 1; duid_v4 = 1;

View File

@ -280,3 +280,15 @@ struct dhcpv4_over_dhcpv6_packet {
#define EUI_64_ID_LEN 12 /* 2 for duid-type, 2 for hardware type, 8 for ID */ #define EUI_64_ID_LEN 12 /* 2 for duid-type, 2 for hardware type, 8 for ID */
#define IAID_LEN 4 #define IAID_LEN 4
/* Offsets with iasubopt wire data of data values for IA_NA and TA */
#define IASUBOPT_NA_ADDR_OFFSET 0
#define IASUBOPT_NA_PREF_OFFSET 16
#define IASUBOPT_NA_VALID_OFFSET 20
#define IASUBOPT_NA_LEN 24
/* Offsets with iasubopt wire data of data values for PD */
#define IASUBOPT_PD_PREF_OFFSET 0
#define IASUBOPT_PD_VALID_OFFSET 4
#define IASUBOPT_PD_PREFLEN_OFFSET 8
#define IASUBOPT_PD_PREFIX_OFFSET 9
#define IASUBOPT_PD_LEN 25