}
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';
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;
}
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 *);
uint32_t ul;
uint16_t sz;
size_t len;
- const char *hp;
const struct dhcp_opt *opt;
const struct if_options *ifo = iface->options;
const struct dhcp_state *state = D_CSTATE(iface);
}
if (ifo->hostname[0] == '\0')
- hostname = get_hostname();
+ hostname = get_hostname(ifo->options &
+ DHCPCD_HOSTNAME_SHORT ? 1 : 0);
else
hostname = ifo->hostname;
if (ifo->fqdn != FQDN_DISABLE) {
}
} else if (ifo->options & DHCPCD_HOSTNAME && hostname) {
*p++ = DHO_HOSTNAME;
- /*
- * Regardless of RFC2132, we should always send a
- * hostname upto the first dot (the short hostname) as
- * a FQDN confuses some DHCP servers when updating DNS.
- * The FQDN option should be used if a FQDN is wanted.
- */
- hp = strchr(hostname, '.');
- if (hp)
- len = hp - hostname;
- else
- len = strlen(hostname);
+ len = strlen(hostname);
*p++ = len;
memcpy(p, hostname, len);
p += len;
if (fqdn == FQDN_DISABLE)
fqdn = FQDN_BOTH;
if (ifo->hostname[0] == '\0')
- hostname = get_hostname();
+ hostname = get_hostname(ifo->options &
+ DHCPCD_HOSTNAME_SHORT ? 1 : 0);
else
hostname = ifo->hostname;
}
# Set the hostname from DHCP data if required
-# Generally we should not set the system hostname to be fully qualified
-: ${hostname_fqdn:=false}
+# Set one of the below to override the DHCP supplied hostname information
+# to be either a short hostname or a FQDN.
+#hostname_fqdn=false
+#hostname_fqdn=true
# Some systems don't have hostname(1)
_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;;
case "$hostname_fqdn" in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|1) hfqdn=true;;
- *) hfqdn=false;;
+ "") ;;
+ *) hshort=true;;
esac
if [ -n "$old_fqdn" ]; then
- if ${hfqdn}; then
+ if ${hfqdn} || ! ${hsort}; then
[ "$hostname" = "$old_fqdn" ]
- else
+ else
[ "$hostname" = "${old_fqdn%%.*}" ]
fi
elif [ -n "$old_host_name" ]; then
else
[ "$hostname" = "$old_host_name" ]
fi
- else
+ elif ${hshort}; then
[ "$hostname" = "${old_host_name%%.*}" ]
+ else
+ [ "$hostname" = "$old_host_name" ]
fi
fi
}
esac
if [ -n "$new_fqdn" ]; then
- if ${hfqdn}; then
+ if ${hfqdn} || ! ${hsort}; then
try_hostname "$new_fqdn"
else
try_hostname "${new_fqdn%%.*}"
else
try_hostname "$new_host_name"
fi
- else
+ elif ${hshort}; then
try_hostname "${new_host_name%%.*}"
+ else
+ try_hostname "$new_host_name"
fi
fi
}
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 19, 2013
+.Dd July 25, 2013
.Dt DHCPCD.CONF 5 SMM
.Os
.Sh NAME
If
.Ar hostname
is a FQDN (ie, contains a .) then it will be encoded as such.
+.It Ic hostname_short
+Sends the short hostname to the DHCP server instead of the FQDN.
+This is useful because DHCP servers will not register the FQDN in their
+DNS if the domain part does not match theirs.
.It Ic ia_na Op Ar iaid
Request a DHCPv6 Normal Address for
.Ar iaid .
#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'},
{"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'}
};
}
}
break;
+ case O_HOSTNAME_SHORT:
+ ifo->options |= DHCPCD_HOSTNAME_SHORT;
+ break;
#endif
default:
return 0;
#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[];