using variable

Glenn Satchell Glenn.Satchell at uniq.com.au
Wed Mar 22 11:13:12 UTC 2006


>Date: Wed, 22 Mar 2006 12:33:13 +0100
>From: Pierre LEONARD <pier.leonard at free.fr>
>To: dhcp-users at isc.org
>Subject: Re: using variable
>
>Simon Hobson a e'crit:
>>Pierre LEONARD wrote:
>>
>>  
>>
>>>you understood my problem but there is another problem:
>>>
>>>/*class "vlan1-clients" { match if <insert conditions here> } ;
>>>
>>>*/it's not possible to use my variable instead of "<insert conditions
>>>here>" and i don't why
>>>i can just use it like following:
>>>
>>>/*set test = "value";
>>>if test = "value" {<treatement>;}
>>>*/
>>>and the treatment cannot be a block subnet, shared-network, pool, class...
>>>so i'm blocked
>>>
>>>
>>>
>>>_my complete code:_
>>>
>>>#checking vlan
>>>if (binary-to-ascii (10, 16, "", substring( option agent.circuit-id, 2,
>>>2))= "10" {
>>>log(info , "checking vlan");
>>>
>>>#checking switch
>>>if binary-to-ascii(16, 8, ":", substring( option agent.remote-id, 2, 6))
>>>= "<mac address>") {
>>>log( info, "checking switch mac address");
>>>set test = "ok";
>>>}
>>>}
>>>
>>>#*********************************************class
>>>definitions**************************************************
>>>class "port20" {
>>>match if binary-to-ascii (10, 8, "/", suffix( option agent.circuit-id,
>>>2)) = "0/19";
>>># match if test = "ok"; #launch but don't function
>>>}
>>>
>>>class "port21" {
>>>match if binary-to-ascii (10, 8, "/", suffix (option agent.circuit-id,
>>>2)) = "0/20";
>>># match if test = "ok"; #launch but don't function
>>>}
>>>    
>>>
>>
>>OK, I can't help with the way you want to do it as I've never gone 
>>into that detail with the server. But how about :
>>
>>class "s1p20" {
>>   match if (substring( option agent.remote-id, 2, 6) = aa:bb:cc:dd:ee:ff)
>>        and (suffix( option agent.circuit-id, 2) = 00:16) ;
>>   log (info, "Switch 1, Port 0/20 matched" ) ;
>>}
>>
>>Someone please correct me if I'm wrong, but I think you can specify a 
>>hex string like that instead of using binary-to-ascii. Hence, a 
>>decrease in size of the config, and a decrease in the processing 
>>required to evaluate all the possible classes - note that the server 
>>must evaluate every class definition since (in the general case) any 
>>client may be a member of more than one class.
>>
>>Since this sort of thing should be machine generated anyway for 
>>anything more than a trivial setup, it should be no problem using hex 
>>like that.
>>
>>Simon
>>
>>
>>
>>  
>>
>i tried your proposition and all it's good but there is still a problem 
>with the offset of the substring function
>in each tutorial that i found in order to get the vlan we use the 
>followinf syntaxe :
>
>/substring( option agent.circuit-id, 2,2)= "10";
>/
>if we read the man we can explain this syntaxe like this : " 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" but it's not very logical because in this case substring 
>return 2 bytes and begin at the the third byte (offset = 2).
>
>unfortunately the structure of circuit-id is :
>
>-------------------------------------------------------------------------------
----------------------------------------------------------------------------
>|suboption type (1) | length (1) | circuit-id type (1) | length (1) | 
>vlan (2) | module (1) | port (1)|
>-------------------------------------------------------------------------------
----------------------------------------------------------------------------
>
>in order to respect this structure the correct syntaxe of substring 
>function to get the vlan had to be :
>
>/substring (option agent circuit-id, 4, 2)= "10"; /but that does not 
>function...
>
>who could explain me why ?????

The option agent.circuit-id returns binary data, so you must compare
that with binary data rather than an ascii string.

In dhcpd.conf syntax "10" is the ascii string "1" followed by "0".
01:00 is the binary data 0x0100.

substring (option agent circuit-id, 4, 2) = "10" will probably never
evaluate to be true. It needs to be

  substring (option agent circuit-id, 4, 2) = 01:00;

or something similar.

regards,
-glenn



More information about the dhcp-users mailing list