regexp or substring match
Glenn Satchell
glenn.satchell at uniq.com.au
Wed Jul 21 00:34:10 UTC 2010
On 07/21/10 05:17, Tony Hunter wrote:
> On Tue, Jul 20, 2010 at 02:58:46PM -0400, Adam Moffett wrote:
>> Could I put a client in a class based on his ethernet MAC address like so?:
>>
>> class "A1" {
>> match if hardware ethernet=a:0:3e:d4:60:73;
>> }
>>
>> If I can do that, is there a way to match only the first 3 bytes of
>> the MAC address, so that I'm assigning a certain ethernet vendor
>> code to a class?
>>
>> Like something along these lines:
>> class "A1" {
>> match if hardware ethernet=a:0:3e:*;
>> }
>
> We've used something very similar to match vendor specific hardware:
> class "joohong" {
> match if binary-to-ascii(16,8,":",substring(option dhcp-client-identifier,0,4)) = "1:0:50:d4" ;
> }
>
No need to convert to an ascii string first as you can compare as a
binary hex list, eg:
class "A1" {
match if substring(hardware, 0, 3) = a:0:3e;
}
With today's cpu speeds this optimisation probably makes little
difference for any size of network, but you'll know you're doing your
part :)
See the dhcp-eval man page for the list of functions available and the
definition of strings, eg:
substring (data-expr, offset, length)
The substring operator evaluates the data expression and
returns the substring of the result of that evaluation
that starts offset bytes from the beginning, continuing
for length bytes.
colon-separated hexadecimal list
A list of hexadecimal octet values, separated by colons,
may be specified as a data expression.
string
A string, enclosed in quotes, may be specified as a data
expression, and returns the text between the quotes,
encoded in ASCII.
HTH
regards,
-glenn
More information about the dhcp-users
mailing list