setting and changing values for ddns-hostname and host-name

Peter Rathlev peter at rathlev.dk
Thu Mar 14 13:32:47 UTC 2013


On Wed, 2013-03-13 at 23:26 -0400, btb at bitrate.net wrote:
> On Mar 13, 2013, at 17.12, Peter Rathlev <peter at rathlev.dk> wrote:
> > if (not (option host-name ~~ "^[a-z0-9][a-z0-9\-]+[a-z0-9]$")) {
> >    set new_host-name = concat("host-", binary-to-ascii(16, 8, "", substring(hardware, 1, 6)));
> >    log(concat("invalid hostname: ", option host-name, " => ", new_host-name));
> >    ddns-hostname = new_host-name;
> > } else {
> >    ddns-hostname = pick (option fqdn.hostname, option host-name, substring (option dhcp-client-identifier, 1, 20));
> > }
>  
> in this example, if a client sends both fqdn.hostname and host-name,
> but host-name is not "valid", then won't new_host-name take precedence
> over fqdn.hostname?

Yes, in this example it will.
> 
> my goal is to only use host-name [or new_host-name if host-name isn't
> valid] if the client has not sent fqdn.hostname, and to only use
> dhcp-client-identifier is the client has sent neither fqdn.hostname
> nor host-name.

If you always want to use fqdn.hostname (even if that would be invalid)
you could refactor it thus:

if (exists fqdn.hostname) {
    ddns-hostname = option fqdn.hostname;
} elsif (not (option host-name ~~ "^[a-z0-9][a-z0-9\-]+[a-z0-9]$")) {
    set new_host-name = concat("host-", binary-to-ascii(16, 8, "", substring(hardware, 1, 6)));
    log(concat("invalid hostname: ", option host-name, " => ", new_host-name));
    ddns-hostname = new_host-name;
} elsif (exists host-name) {
    ddns-hostname = option host-name;
}

I'm not entirely sure the last claus is needed but have only had the
time to syntax check this.
> 
> sort of on that note, i wanted to go back and read again what "pick"
> does, but i had trouble finding reference to it in the documentation.
> i looked in dhcpd(8), dhcpd.conf(5), dhcp-options(5), and
> dhcp-eval(5).  i did find pick-first-name in dhcp-eval(5) and wondered
> if pick were simply shorthand for that, but couldn't find a
> confirmation of this.

It's actually "pick-first-value" (man dhcp-eval), which dhcpd apparently
lets you shorten down to whatever is still unambigous.

-- 
Peter




More information about the dhcp-users mailing list