regexp or substring match

Tony Hunter tony at uniserve.com
Wed Jul 21 16:07:02 UTC 2010


On Wed, Jul 21, 2010 at 10:34:10AM +1000, Glenn Satchell wrote:
> 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 :)

Thanks for that Glenn. In fact we no longer have need for such class 
matching and I had pulled the example from notes. But I will update 
those notes, as one never knows when the need will resurface.  :)
 
> 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
> _______________________________________________
> dhcp-users mailing list
> dhcp-users at lists.isc.org
> https://lists.isc.org/mailman/listinfo/dhcp-users




More information about the dhcp-users mailing list