Making use of classes

Jeffrey Hutzelman jhutz at cmu.edu
Sat Jan 17 07:58:44 UTC 2009


--On Saturday, January 17, 2009 02:16:51 AM +0100 Gustaf Ankarloo 
<gustaf at nestil.se> wrote:

> Im trying to figure out how the [match if substring (option
> dhcp-client-identifier, x, x) = "somevalue"] Works inside a class
> statement.

The statement is "match if <boolean expression>", and causes a client to be 
added to the class if the expression is true.  For more information on 
expressions, see dhcp-eval(5).

In the example above, the expression is
'substring(opton dhcp-client-identifier,x,x) = "somevalue"'

"somevalue" is fairly self-explanatory; substring() returns a portion of 
its first argument, with the other two determining which portion.  This, 
too, is documented in dhcp-eval(5); Jeff Haran quoted the relevant section 
in his message.


> class "test1" {
>         match if substring (option host-name, 12, 12) = "karins-lilla";

As Jeff Haran pointed, out, this doesn't work because the offset is wrong; 
you're comparing "karins-lilla" to a string starting 12 characters into the
hostname, which is to say, just beyond its end.

And, these don't work because "option dhcp-client-identifier" refers to the 
DHCP client identifier option, which in your example is 
01:00:0f:b0:6e:9d:46, and that doesn't contain "karins-lilla" at any offset.

You could write something like

match if substring(option host-name, 0, 12) = "karins-lilla", and that 
would work for that host, but it's not really what you want.  For example, 
that will also match a client with a hostname like "karins-lilla234234". 
If what you want is to match by hostname, you should just write that:

match if option host-name = "karins-lilla";


-- Jeffrey T. Hutzelman (N3NHS) <jhutz+ at cmu.edu>
   Carnegie Mellon University - Pittsburgh, PA




More information about the dhcp-users mailing list