]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
[master] Add math operators and switch construct to eval
authorShawn Routhier <sar@isc.org>
Thu, 12 Jun 2014 04:50:08 +0000 (21:50 -0700)
committerShawn Routhier <sar@isc.org>
Thu, 12 Jun 2014 04:50:08 +0000 (21:50 -0700)
common/dhcp-eval.5

index 11c961577026027d4b3f56e31970dd6044dc099a..1ba2e449240618140cfc216f2aa3761688000d3b 100644 (file)
@@ -34,11 +34,15 @@ the ability to perform conditional behavior depending on the contents
 of packets they receive.  The syntax for specifying this conditional
 behaviour is documented here.
 .SH REFERENCE: CONDITIONAL BEHAVIOUR
-Conditional behaviour is specified using the if statement and the else
-or elsif statements.  A conditional statement can appear anywhere
+Conditional behaviour may be  specified using the if statement and the else
+or elsif statements or the switch and case statements.
+A conditional statement can appear anywhere
 that a regular statement (e.g., an option statement) can appear, and
-can enclose one or more such statements.  A typical conditional
-statement in a server might be:
+can enclose one or more such statements.
+.PP
+.B CONDITIONAL BEHAVIOUR: IF
+.PP
+A typical conditional if statement in a server might be:
 .PP
 .nf
 if option dhcp-user-class = "accounting" {
@@ -108,6 +112,53 @@ clause, the statements enclosed in braces following the
 .B else
 are evaluated.  Boolean expressions that evaluate to null are
 treated as false in conditionals.
+.PP
+.B CONDITIONAL BEHAVIOUR: SWITCH
+.PP
+The above example can be rewritten using a switch construct as well.
+.PP
+.nf
+switch (option dhcp-user-class) {
+  case "accounting":
+    max-lease-time 17600;
+    option domain-name "accounting.example.org";
+    option domain-name-servers ns1.accounting.example.org,
+                              ns2.accounting.example.org;
+  case "sales":
+    max-lease-time 17600;
+    option domain-name "sales.example.org";
+    option domain-name-servers ns1.sales.example.org,
+                              ns2.sales.example.org;
+    break;
+  case "engineering":
+    max-lease-time 17600;
+    option domain-name "engineering.example.org";
+    option domain-name-servers ns1.engineering.example.org,
+                              ns2.engineering.example.org;
+    break;
+  default:
+    max-lease-time 600;
+    option domain-name "misc.example.org";
+    option domain-name-servers ns1.misc.example.org,
+                              ns2.misc.example.org;
+    break;
+}
+.fi
+.PP
+The
+.B switch
+statement and the
+.B case
+statements can both be data expressions or numeric expressions.  Within
+a switch statement they all must be the same type.  The server 
+evaluates the expression from the switch statement and then it evaluates
+the expressions from the case statements until it finds a match.
+.PP
+If it finds a match it starts executing statements from that case
+until the next break statement.  If it doesn't find a match it
+starts from the default statement and again proceeds to the next
+break statement.  If there is no match and no default it does nothing.
+.PP
 .SH BOOLEAN EXPRESSIONS
 The following is the current list of boolean expressions that are
 supported by the DHCP distribution.
@@ -384,6 +435,20 @@ general, the maximum size of such an integer should not be assumed to
 be representable in fewer than 32 bits, but the precision of such
 integers may be more than 32 bits.
 .PP
+In addition to the following operators several standard math functions
+are available.  They are:
+.nf
+operation    symbol
+add            \fB+\fR
+subtract       \fB-\fR
+divide         \fB/\fR
+multiply       \fB*\fR
+modulus        \fB%\fR
+bitwise and    \fB&\fR
+bitwise or     \fB|\fR
+bitwise xor    \fB^\fR
+.fi
+.PP
 .B extract-int (\fIdata-expr\fB, \fIwidth\fB)\fR
 .PP
 .RS 0.25i