Class selection ekspression
Glenn Satchell
Glenn.Satchell at uniq.com.au
Wed Mar 15 10:59:05 UTC 2006
>From: Simon Hobson <dhcp at thehobsons.co.uk>
>Subject: Re: Class selection ekspression
>
>Lars Jacobsen wrote:
>
>>Thanks but this still does not give me answer on how to make a class
>>match where two (or more) conditions is true.
>>My RID/CID is also unique but part of it is sequential and that is
>>what I want to make a (sub)class selection on.
>>RID/CID = 2102011 or 2102021 or 2102031 ... 2102161 all have to end
>>up in class one.
>>RID/CID = 2102171 or 2102181 or 2102191 ... 2102321 all have to end
>>up in class two.
>>RID/CID = 2102331 or 2102341 or 2102351 ... 2102481 all have to end
>>up in class tree.
>>I have no problem making an exact match based on the RID/CID.
>
>You can use logical operators (ie AND, OR) in expressions, I think
>it's in 'man dhcp-eval'.
>
>Also, have you considered subclassing ? There's a section (including
>example) in 'man dhcpd.conf' - just replace all references to MAC
>addresses with RID/CID. IIRC, it's said to be more efficient than
>large "if x or y or z or ..." constructs due to hashing.
>
>Simon
>
Ok, first up lets try and answer your question, then I'll offer a
suggestion.
class "one" {
match if substring(option agent.remoteid, 3, 2) = "01"
or substring(option agent.remoteid, 3, 2) = "02"
or ... ;
}
The syntax for and/or are in the dhcp-eval page, but you need to look
at two places:
The if statement and the elsif continuation statement both
take boolean expressions as their arguments. That is, they
take expressions that, when evaluated, produce a boolean
result.
then it gives some syntax
The following is the current list of boolean expressions
that are supported by the DHCP distribution.
data-expression-1 = data-expression-2
this last line is a boolean expression. They can be combined using logical
operators
boolean-expression-1 and boolean-expression-2
boolean-expression-1 or boolean-expression-2
Maybe a simple example would work here:
match if option agent.remote-id = "2021" and option agent.circuit-id = "31";
Of course you can use substring to get parts of the RID or CID.
You can also concatenate strings before extracting a substring.
Perhaps this is closer to a solution for you? Note substring starts
counting from 0.
class "one" {
match substring(concat(option agent.remoteid, option agent.circuit-id), 2, 2);
}
class "two" {
match substring(concat(option agent.remoteid, option agent.circuit-id), 2, 2);
}
class "three" {
match substring(concat(option agent.remoteid, option agent.circuit-id), 2, 2);
}
subclass "one" "0201";
subclass "one" "0202";
...
subclass "one" "0216";
subclass "two" "0217";
subclass "two" "0218";
...
subclass "two" "0232";
subclass "three" "0233";
subclass "three" "0234";
...
subclass "three" "0248";
Note that I haven't actually used tested this, but I believe it
fairly should be close. If not please post some more details,
especially showing which bit of the string is remote-id and which
is circuit-id.
regards,
-glenn
More information about the dhcp-users
mailing list