Import dhcpcd-6.0.4 with the following changes:
* hostname is not stamped on anymore if already set * hostname will be set to a FQDN when possible as per RFC4702 section 3.1 * a domain is derived from the FQDN if no domain option is set * add new hostname_short command to send a short hostname for DDNS * hostname_fqdn is now documented, along with a new server setting and the potential problems associated with it * the FQDN option is no longer sent by default for DHCPv4 messages
This commit is contained in:
parent
3d23719d01
commit
cceb514049
|
@ -1,5 +1,5 @@
|
|||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: common.c,v 1.1.1.12 2013/06/21 19:33:06 roy Exp $");
|
||||
__RCSID("$NetBSD: common.c,v 1.1.1.13 2013/07/29 20:35:31 roy Exp $");
|
||||
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
|
@ -139,8 +139,9 @@ set_nonblock(int fd)
|
|||
}
|
||||
|
||||
const char *
|
||||
get_hostname(void)
|
||||
get_hostname(int short_hostname)
|
||||
{
|
||||
char *p;
|
||||
|
||||
gethostname(hostname_buffer, sizeof(hostname_buffer));
|
||||
hostname_buffer[sizeof(hostname_buffer) - 1] = '\0';
|
||||
|
@ -149,6 +150,13 @@ get_hostname(void)
|
|||
strncmp(hostname_buffer, "localhost.", strlen("localhost.")) == 0 ||
|
||||
hostname_buffer[0] == '.')
|
||||
return NULL;
|
||||
|
||||
if (short_hostname) {
|
||||
p = strchr(hostname_buffer, '.');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
}
|
||||
|
||||
return hostname_buffer;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: common.h,v 1.1.1.8 2013/06/21 19:33:08 roy Exp $ */
|
||||
/* $NetBSD: common.h,v 1.1.1.9 2013/07/29 20:35:33 roy Exp $ */
|
||||
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
|
@ -102,7 +102,7 @@
|
|||
int set_cloexec(int);
|
||||
int set_nonblock(int);
|
||||
char *get_line(FILE * __restrict);
|
||||
const char *get_hostname(void);
|
||||
const char *get_hostname(int);
|
||||
extern int clock_monotonic;
|
||||
int get_monotonic(struct timeval *);
|
||||
ssize_t setvar(char ***, const char *, const char *, const char *);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: defs.h,v 1.1.1.29 2013/07/19 11:52:57 roy Exp $ */
|
||||
/* $NetBSD: defs.h,v 1.1.1.30 2013/07/29 20:35:33 roy Exp $ */
|
||||
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
|
@ -30,7 +30,7 @@
|
|||
#define CONFIG_H
|
||||
|
||||
#define PACKAGE "dhcpcd"
|
||||
#define VERSION "6.0.3"
|
||||
#define VERSION "6.0.4"
|
||||
|
||||
#ifndef CONFIG
|
||||
# define CONFIG SYSCONFDIR "/" PACKAGE ".conf"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: dhcp6.c,v 1.1.1.2 2013/06/22 09:25:33 roy Exp $");
|
||||
__RCSID("$NetBSD: dhcp6.c,v 1.1.1.3 2013/07/29 20:35:33 roy Exp $");
|
||||
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
|
@ -127,9 +127,9 @@ const struct dhcp_opt dhcp6_opts[] = {
|
|||
{ D6_OPTION_INFO_REFRESH_TIME, UINT32, "info_refresh_time" },
|
||||
{ D6_OPTION_BCMS_SERVER_D, RFC3397, "bcms_server_d" },
|
||||
{ D6_OPTION_BCMS_SERVER_A, IPV6A, "bcms_server_a" },
|
||||
{ D6_OPTION_FQDN, RFC3397, "fqdn" },
|
||||
{ D6_OPTION_POSIX_TIMEZONE, STRING, "posix_timezone" },
|
||||
{ D6_OPTION_TZDB_TIMEZONE, STRING, "tzdb_timezone" },
|
||||
{ D6_OPTION_FQDN, RFC3397, "fqdn" },
|
||||
{ 0, 0, NULL }
|
||||
};
|
||||
|
||||
|
@ -383,6 +383,7 @@ dhcp6_makemessage(struct interface *ifp)
|
|||
uint32_t u32;
|
||||
const struct ipv6_addr *ap;
|
||||
const char *hostname = NULL; /* assignment just to appease GCC*/
|
||||
int fqdn;
|
||||
|
||||
state = D6_STATE(ifp);
|
||||
if (state->send) {
|
||||
|
@ -390,8 +391,23 @@ dhcp6_makemessage(struct interface *ifp)
|
|||
state->send = NULL;
|
||||
}
|
||||
|
||||
/* Work out option size first */
|
||||
ifo = ifp->options;
|
||||
fqdn = ifo->fqdn;
|
||||
|
||||
if (fqdn == FQDN_DISABLE || ifo->options & DHCPCD_HOSTNAME) {
|
||||
/* We're sending the DHCPv4 hostname option, so send FQDN as
|
||||
* DHCPv6 has no FQDN option and DHCPv4 must not send
|
||||
* hostname and FQDN according to RFC4702 */
|
||||
if (fqdn == FQDN_DISABLE)
|
||||
fqdn = FQDN_BOTH;
|
||||
if (ifo->hostname[0] == '\0')
|
||||
hostname = get_hostname(ifo->options &
|
||||
DHCPCD_HOSTNAME_SHORT ? 1 : 0);
|
||||
else
|
||||
hostname = ifo->hostname;
|
||||
}
|
||||
|
||||
/* Work out option size first */
|
||||
n_options = 0;
|
||||
len = 0;
|
||||
si = NULL;
|
||||
|
@ -408,13 +424,8 @@ dhcp6_makemessage(struct interface *ifp)
|
|||
if (len)
|
||||
len += sizeof(*o);
|
||||
|
||||
if (ifo->fqdn != FQDN_DISABLE) {
|
||||
if (ifo->hostname[0] == '\0')
|
||||
hostname = get_hostname();
|
||||
else
|
||||
hostname = ifo->hostname;
|
||||
if (fqdn != FQDN_DISABLE)
|
||||
len += sizeof(*o) + 1 + encode_rfc1035(hostname, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
len += sizeof(*state->send);
|
||||
|
@ -620,11 +631,11 @@ dhcp6_makemessage(struct interface *ifp)
|
|||
}
|
||||
|
||||
if (state->send->type != DHCP6_RELEASE) {
|
||||
if (ifo->fqdn != FQDN_DISABLE) {
|
||||
if (fqdn != FQDN_DISABLE) {
|
||||
o = D6_NEXT_OPTION(o);
|
||||
o->code = htons(D6_OPTION_FQDN);
|
||||
p = D6_OPTION_DATA(o);
|
||||
switch (ifo->fqdn) {
|
||||
switch (fqdn) {
|
||||
case FQDN_BOTH:
|
||||
*p = D6_FQDN_BOTH;
|
||||
break;
|
||||
|
@ -2306,7 +2317,8 @@ dhcp6_start1(void *arg)
|
|||
add_option_mask(ifo->requestmask6,
|
||||
dhc->dhcp6_opt);
|
||||
}
|
||||
if (ifo->fqdn != FQDN_DISABLE)
|
||||
if (ifo->fqdn != FQDN_DISABLE ||
|
||||
ifo->options & DHCPCD_HOSTNAME)
|
||||
add_option_mask(ifo->requestmask6, D6_OPTION_FQDN);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: 20-resolv.conf,v 1.1.1.11 2013/06/21 19:33:08 roy Exp $
|
||||
# $NetBSD: 20-resolv.conf,v 1.1.1.12 2013/07/29 20:35:33 roy Exp $
|
||||
|
||||
# Generate /etc/resolv.conf
|
||||
# Support resolvconf(8) if available
|
||||
|
@ -91,6 +91,18 @@ add_resolv_conf()
|
|||
return $?
|
||||
fi
|
||||
|
||||
# Derive a new domain from our various hostname options
|
||||
new_domain_name=
|
||||
if [ -z "$new_domain_name" ]; then
|
||||
if [ "$new_dhcp6_fqdn" != "${new_dhcp6_fqdn#*.}" ]; then
|
||||
new_domain_name="${new_dhcp6_fqdn#*.}"
|
||||
elif [ "$new_fqdn" != "${new_fqdn#*.}" ]; then
|
||||
new_domain_name="${new_fqdn#*.}"
|
||||
elif [ "$new_host_name" != "${new_host_name#*.}" ]; then
|
||||
new_domain_name="${new_host_name#*.}"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "$new_domain_name" ]; then
|
||||
set -- $new_domain_name
|
||||
new_domain_name="$1"
|
||||
|
|
|
@ -1,9 +1,21 @@
|
|||
# $NetBSD: 30-hostname,v 1.1.1.9 2013/07/19 11:52:57 roy Exp $
|
||||
# $NetBSD: 30-hostname,v 1.1.1.10 2013/07/29 20:35:33 roy Exp $
|
||||
|
||||
# Set the hostname from DHCP data if required
|
||||
|
||||
# Generally we should not set the system hostname to be fully qualified
|
||||
: ${hostname_fqdn:=false}
|
||||
# A hostname can either be a short hostname or a FQDN.
|
||||
# hostname_fqdn=true
|
||||
# hostname_fqdn=false
|
||||
# hostname_fqdn=server
|
||||
|
||||
# A value of server means just what the server says, don't manipulate it.
|
||||
# This could lead to an inconsistent hostname on a DHCPv4 and DHCPv6 network
|
||||
# where the DHCPv4 hostname is short and the DHCPv6 has an FQDN.
|
||||
# DHCPv6 has no hostname option.
|
||||
# RFC4702 section 3.1 says FQDN should be prefered over hostname.
|
||||
#
|
||||
# As such, the default is hostname_fqdn=true so that a consistent hostname
|
||||
# is always assigned.
|
||||
: ${hostname_fqdn:=true}
|
||||
|
||||
# Some systems don't have hostname(1)
|
||||
_hostname()
|
||||
|
@ -43,7 +55,7 @@ _hostname()
|
|||
|
||||
need_hostname()
|
||||
{
|
||||
local hostname hfqdn
|
||||
local hostname hfqdn=false hshort=false
|
||||
|
||||
case "$force_hostname" in
|
||||
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) return 0;;
|
||||
|
@ -56,14 +68,15 @@ need_hostname()
|
|||
|
||||
case "$hostname_fqdn" in
|
||||
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;;
|
||||
*) hfqdn=false;;
|
||||
[Ss][Ee][Rr][Vv][Ee][Rr]) ;;
|
||||
*) hshort=true;;
|
||||
esac
|
||||
|
||||
if [ -n "$old_fqdn_name" ]; then
|
||||
if ${hfqdn}; then
|
||||
[ "$hostname" = "$old_fqdn_name" ]
|
||||
else
|
||||
[ "$hostname" = "${old_fqdn_name%%.*}" ]
|
||||
if [ -n "$old_fqdn" ]; then
|
||||
if ${hfqdn} || ! ${hsort}; then
|
||||
[ "$hostname" = "$old_fqdn" ]
|
||||
else
|
||||
[ "$hostname" = "${old_fqdn%%.*}" ]
|
||||
fi
|
||||
elif [ -n "$old_host_name" ]; then
|
||||
if ${hfqdn}; then
|
||||
|
@ -75,9 +88,14 @@ need_hostname()
|
|||
else
|
||||
[ "$hostname" = "$old_host_name" ]
|
||||
fi
|
||||
else
|
||||
elif ${hshort}; then
|
||||
[ "$hostname" = "${old_host_name%%.*}" ]
|
||||
else
|
||||
[ "$hostname" = "$old_host_name" ]
|
||||
fi
|
||||
else
|
||||
# No old hostname
|
||||
false
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -93,20 +111,21 @@ try_hostname()
|
|||
|
||||
set_hostname()
|
||||
{
|
||||
local hfqdn
|
||||
local hfqdn=false hshort=false
|
||||
|
||||
need_hostname || return
|
||||
|
||||
case "$hostname_fqdn" in
|
||||
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;;
|
||||
*) hfqdn=false;;
|
||||
"") ;;
|
||||
*) hshort=true;;
|
||||
esac
|
||||
|
||||
if [ -n "$new_fqdn_name" ]; then
|
||||
if ${hfqdn}; then
|
||||
try_hostname "$new_fqdn_name"
|
||||
if [ -n "$new_fqdn" ]; then
|
||||
if ${hfqdn} || ! ${hshort}; then
|
||||
try_hostname "$new_fqdn"
|
||||
else
|
||||
try_hostname "${new_fqdn_name%%.*}"
|
||||
try_hostname "${new_fqdn%%.*}"
|
||||
fi
|
||||
elif [ -n "$new_host_name" ]; then
|
||||
if ${hfqdn}; then
|
||||
|
@ -117,8 +136,10 @@ set_hostname()
|
|||
else
|
||||
try_hostname "$new_host_name"
|
||||
fi
|
||||
else
|
||||
elif ${hshort}; then
|
||||
try_hostname "${new_host_name%%.*}"
|
||||
else
|
||||
try_hostname "$new_host_name"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -126,7 +147,7 @@ set_hostname()
|
|||
# For ease of use, map DHCP6 names onto our DHCP4 names
|
||||
case "$reason" in
|
||||
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
|
||||
new_fqdn_name="$new_dhcp6_fqdn"
|
||||
new_fqdn="$new_dhcp6_fqdn"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: if-options.c,v 1.1.1.19 2013/06/21 19:33:07 roy Exp $");
|
||||
__RCSID("$NetBSD: if-options.c,v 1.1.1.20 2013/07/29 20:35:32 roy Exp $");
|
||||
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
|
@ -70,6 +70,7 @@ unsigned long long options = 0;
|
|||
#define O_IA_NA O_BASE + 10
|
||||
#define O_IA_TA O_BASE + 11
|
||||
#define O_IA_PD O_BASE + 12
|
||||
#define O_HOSTNAME_SHORT O_BASE + 13
|
||||
|
||||
const struct option cf_options[] = {
|
||||
{"background", no_argument, NULL, 'b'},
|
||||
|
@ -131,6 +132,7 @@ const struct option cf_options[] = {
|
|||
{"ia_na", no_argument, NULL, O_IA_NA},
|
||||
{"ia_ta", no_argument, NULL, O_IA_TA},
|
||||
{"ia_pd", no_argument, NULL, O_IA_PD},
|
||||
{"hostname_short", no_argument, NULL, O_HOSTNAME_SHORT},
|
||||
{NULL, 0, NULL, '\0'}
|
||||
};
|
||||
|
||||
|
@ -1082,6 +1084,9 @@ got_iaid:
|
|||
}
|
||||
}
|
||||
break;
|
||||
case O_HOSTNAME_SHORT:
|
||||
ifo->options |= DHCPCD_HOSTNAME | DHCPCD_HOSTNAME_SHORT;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: if-options.h,v 1.1.1.16 2013/06/21 19:33:08 roy Exp $ */
|
||||
/* $NetBSD: if-options.h,v 1.1.1.17 2013/07/29 20:35:33 roy Exp $ */
|
||||
|
||||
/*
|
||||
* dhcpcd - DHCP client daemon
|
||||
|
@ -96,6 +96,7 @@
|
|||
#define DHCPCD_IA_FORCED (1ULL << 40)
|
||||
#define DHCPCD_STOPPING (1ULL << 41)
|
||||
#define DHCPCD_DEPARTED (1ULL << 42)
|
||||
#define DHCPCD_HOSTNAME_SHORT (1ULL << 43)
|
||||
|
||||
extern const struct option cf_options[];
|
||||
|
||||
|
|
Loading…
Reference in New Issue