2
0
mirror of https://gitlab.isc.org/isc-projects/dhcp synced 2025-08-31 14:25:41 +00:00

[master] Add -df option to client code to help share DUIDs

Add the "-df <duid file>" option to the client code in order
to make it easier to share DUIDs between a v4 instance and
a v6 instance.  This option instructs the client to search
the duid file for a DUID if it didn't find one in the main
lease file.

In addition add the infrastructure for running ATF tests
for the client and write some ATF tests for this patch.
This commit is contained in:
Shawn Routhier
2014-05-16 15:24:48 -07:00
parent 63c8800c3c
commit 79818c9344
17 changed files with 1688 additions and 44 deletions

View File

@@ -47,6 +47,7 @@ const char *path_dhclient_db = NULL;
const char *path_dhclient_pid = NULL;
static char path_dhclient_script_array[] = _PATH_DHCLIENT_SCRIPT;
char *path_dhclient_script = path_dhclient_script_array;
const char *path_dhclient_duid = NULL;
/* False (default) => we write and use a pid file */
isc_boolean_t no_pid_file = ISC_FALSE;
@@ -100,6 +101,7 @@ static int check_domain_name_list(const char *ptr, size_t len, int dots);
static int check_option_values(struct universe *universe, unsigned int opt,
const char *ptr, size_t len);
#ifndef UNIT_TEST
int
main(int argc, char **argv) {
int fd;
@@ -210,6 +212,10 @@ main(int argc, char **argv) {
usage();
path_dhclient_conf = argv[i];
no_dhclient_conf = 1;
} else if (!strcmp(argv[i], "-df")) {
if (++i == argc)
usage();
path_dhclient_duid = argv[i];
} else if (!strcmp(argv[i], "-lf")) {
if (++i == argc)
usage();
@@ -504,6 +510,11 @@ main(int argc, char **argv) {
/* Parse the lease database. */
read_client_leases();
/* If desired parse the secondary lease database for a DUID */
if ((default_duid.len == 0) && (path_dhclient_duid != NULL)) {
read_client_duid();
}
/* Rewrite the lease database... */
rewrite_client_leases();
@@ -723,6 +734,7 @@ main(int argc, char **argv) {
/* In fact dispatch() never returns. */
return 0;
}
#endif /* !UNIT_TEST */
static void usage()
{
@@ -738,8 +750,8 @@ static void usage()
#else /* DHCPv6 */
"[-I1dvrxi] [-nw] [-p <port>] [-D LL|LLT] \n"
#endif /* DHCPv6 */
" [-s server-addr] [-cf config-file] "
"[-lf lease-file]\n"
" [-s server-addr] [-cf config-file]\n"
" [-df duid-file] [-lf lease-file]\n"
" [-pf pid-file] [--no-pid] [-e VAR=val]\n"
" [-sf script-file] [interface]");
}
@@ -763,6 +775,11 @@ void run_stateless(int exit_mode)
/* Parse the lease database. */
read_client_leases();
/* If desired parse the secondary lease database for a DUID */
if ((default_duid.len == 0) && (path_dhclient_duid != NULL)) {
read_client_duid();
}
/* Establish a default DUID. */
if (default_duid.len == 0) {
if (default_duid.buffer != NULL)
@@ -2884,6 +2901,7 @@ form_duid(struct data_string *duid, const char *file, int line)
{
struct interface_info *ip;
int len;
char *str;
/* For now, just use the first interface on the list. */
ip = interfaces;
@@ -2926,6 +2944,14 @@ form_duid(struct data_string *duid, const char *file, int line)
memcpy(duid->buffer->data + 4, ip->hw_address.hbuf + 1,
ip->hw_address.hlen - 1);
}
str = quotify_buf(duid->data, duid->len, MDL);
if (str == NULL)
log_info("Created duid.");
else {
log_info("Created duid %s.", str);
dfree(str, MDL);
}
}
/* Write the default DUID to the lease store. */