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

btb at bitrate.net btb at bitrate.net
Fri Mar 15 02:06:35 UTC 2013


On Mar 14, 2013, at 09.32, Peter Rathlev <peter at rathlev.dk> wrote:

> 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.

thank you for this guidance.  you've prompted me to think a bit more about what i'm actually trying to do here in terms of each of these values and the potential that one or more of them is invalid.  i'll spend some time with this and maybe reformulate my question in another thread, depending on how it goes.

-ben



More information about the dhcp-users mailing list