dhcp-users Digest, Vol 65, Issue 11

Simon Hobson dhcp1 at thehobsons.co.uk
Thu Mar 20 11:13:46 UTC 2014

lyndon villas <sox316 at gmail.com> wrote:

>    Here's i want to accomplish:
>    1. Check if Option 61 value is in the class entry (ex. client-circuitid_class), If YES, then check if Circuit-id is is the available, if no Circuit-id please assign IP address from IP Pool.
>    2. If both Option 61 and Circuit-iD are present, compared it to the class entry (e.g client-circuitid_class). If matches the entry, please assign IP address from IP Pool.
>    3. Option 61 is not defined (null) but Circuit-id is available and can be found in the class entry (e.g client-circuitid_class), please assign IP address from IP pool.
> I hope this pseudocode helps.

It's not clear and consistent.

1 says "If A and not B, then use A".

2 says "If A and B then use 'it'" - without specifying whether 'it' is A or B !

3 says "If B and not A then use B".

A simpler way of writing it is "if A is present then use A, else if B is present then use B" (or swap A and B round depending on what 'it' is).

You can use "pick-first-value" for this.
If 'it' is A then use "pick-first-value(A,B)", or if 'it' is B then use "pick-first-value(B,A)". So your class selection becomes :

match if pick-first-value(A,B)="some string"

But you also don't specify what you want to match the options against. Are they to match against the same string (eg A or B or both would be the same string), or are they to comapre against different strings (in which case the above won't work).

If you match against different strings (so the test is "A="X" or B = "Y") then I think you need a slightly more complicated selection.
I'm not sure if just doing :
  match if A="X";
  match if B="Y";
will work. If not, then you might have to do something like :
  match if (pick-first-option(A,"")="X") or (pick-first-option(B,""="Y") ;

The reason for the pick-first-option clauses here is that if A or B is not present, then the result of comparing it with anything is unknown - and logical ORing unknown with anything is unknown. So the pick-first-value clauses ensure that if A or B is not present, it's replaced with an empty string so that the OR clause will work.

More information about the dhcp-users mailing list