2

Actually I want to dinamically assign bootfile-name based on clients MAC.

I have tried this config:

option bootfile-name concat( binary-to-ascii(16, 8, "", substring (hardware, 1, 6)), ".cfg");

But this is wrong config (as dhcp server isn't starting at all). If instead of concat(...) I put just real filename (e.g. "000102030405.cfg") everything is ok. But this is not what I need. Is there any way to dynamically set bootfile-name?

halt
  • 106
  • 7

2 Answers2

4

Well, good news. I found an answer by myself. The answer itself was in man pages. All you need is to use EXPRESSIONS. This is correct for any option (not only bootfile-name), to which you want assign a value from client's request.

From the man dhcp-options:

SETTING OPTION VALUES USING EXPRESSIONS
   Sometimes it's helpful to be able to set the value of a DHCP option based on
   some value that the client has sent.   To do this, you can use expression
   evaluation. The dhcp-eval(5) manual page describes how to write expressions.
   To assign the result of an evaluation to an option,
   define the option as follows:

     option my-option = expression ;

   For example:

     option hostname = binary-to-ascii (16, 8, "-", substring (hardware, 1, 6));

So, as you can see, the only difference between this code and mine is equal sign!

For curious one, the answer to my question is:

option bootfile-name = concat( binary-to-ascii(16, 8, "",
                               substring (hardware, 1, 6)), ".cfg");

Did you noticed "="?

halt
  • 106
  • 7
1

110022334455 becomes 11022334455 in the ASCII output

see also: https://kb.isc.org/article/AA-01039/0/Formatting-MAC-addresses-in-dhcpd-or-why-does-binary-to-ascii-strip-leading-zeroes.html