1dhcp-eval(5)                  File Formats Manual                 dhcp-eval(5)
2
3
4

NAME

6       dhcp-eval - ISC DHCP conditional evaluation
7

DESCRIPTION

9       The Internet Systems Consortium DHCP client and server both provide the
10       ability to perform conditional behavior depending on  the  contents  of
11       packets  they receive.   The syntax for specifying this conditional be‐
12       haviour is documented here.
13

REFERENCE: CONDITIONAL BEHAVIOUR

15       Conditional behaviour is specified using the if statement and the  else
16       or elsif statements.   A conditional statement can appear anywhere that
17       a regular statement (e.g., an option statement)  can  appear,  and  can
18       enclose  one or more such statements.   A typical conditional statement
19       in a server might be:
20
21       if option dhcp-user-class = "accounting" {
22         max-lease-time 17600;
23         option domain-name "accounting.example.org";
24         option domain-name-servers ns1.accounting.example.org,
25                           ns2.accounting.example.org;
26       } elsif option dhcp-user-class = "sales" {
27         max-lease-time 17600;
28         option domain-name "sales.example.org";
29         option domain-name-servers ns1.sales.example.org,
30                           ns2.sales.example.org;
31       } elsif option dhcp-user-class = "engineering" {
32         max-lease-time 17600;
33         option domain-name "engineering.example.org";
34         option domain-name-servers ns1.engineering.example.org,
35                           ns2.engineering.example.org;
36       } else {
37         max-lease-time 600;
38         option domain-name "misc.example.org";
39         option domain-name-servers ns1.misc.example.org,
40                           ns2.misc.example.org;
41       }
42
43       On the client side, an example of conditional evaluation might be:
44
45       # example.org filters DNS at its firewall, so we have to use their DNS
46       # servers when we connect to their network.   If we are not at
47       # example.org, prefer our own DNS server.
48       if not option domain-name = "example.org" {
49         prepend domain-name-servers 127.0.0.1;
50       }
51
52       The if statement and the elsif continuation statement both take boolean
53       expressions  as their arguments.   That is, they take expressions that,
54       when evaluated, produce a boolean result.   If the expression evaluates
55       to true, then the statements enclosed in braces following the if state‐
56       ment are executed, and  all  subsequent  elsif  and  else  clauses  are
57       skipped.    Otherwise,  each  subsequent  elsif  clause's expression is
58       checked, until an elsif clause is encountered whose test  evaluates  to
59       true.    If  such a clause is found, the statements in braces following
60       it are executed, and then any subsequent elsif  and  else  clauses  are
61       skipped.    If  all  the  if  and elsif clauses are checked but none of
62       their expressions evaluate true, then if there is an else  clause,  the
63       statements enclosed in braces following the else are evaluated.   Bool‐
64       ean expressions that evaluate to null are treated as  false  in  condi‐
65       tionals.
66

BOOLEAN EXPRESSIONS

68       The  following is the current list of boolean expressions that are sup‐
69       ported by the DHCP distribution.
70
71       data-expression-1 = data-expression-2
72
73         The = operator compares the values of two data expressions, returning
74         true  if  they  are  the same, false if they are not.   If either the
75         left-hand side or the right-hand side are null, the  result  is  also
76         null.
77
78       data-expression-1   ~=  data-expression-2  data-expression-1  ~~  data-
79       expression-2
80
81         The ~= and ~~  operators  (not  available  on  all  systems)  perform
82         extended  regex(7)  matching  of  the values of two data expressions,
83         returning true  if  data-expression-1  matches  against  the  regular
84         expression  evaluated  by  data-expression-2, or false if it does not
85         match or encounters some error.  If either the left-hand side or  the
86         right-hand  side are null or empty strings, the result is also false.
87         The ~~ operator differs from the ~= operator  in  that  it  is  case-
88         insensitive.
89
90       boolean-expression-1 and boolean-expression-2
91
92         The  and  operator evaluates to true if the boolean expression on the
93         left-hand side and the boolean expression on the right-hand side both
94         evaluate  to  true.  Otherwise, it evaluates to false.  If either the
95         expression on the left-hand side or the expression on the  right-hand
96         side are null, the result is null.
97
98       boolean-expression-1 or boolean-expression-2
99
100         The or operator evaluates to true if either the boolean expression on
101         the left-hand side or the boolean expression on the  right-hand  side
102         evaluate  to  true.  Otherwise, it evaluates to false.  If either the
103         expression on the left-hand side or the expression on the  right-hand
104         side are null, the result is null.
105
106       not boolean-expression
107
108         The not operator evaluates to true if boolean-expression evaluates to
109         false, and returns false if  boolean-expression  evaluates  to  true.
110         If boolean-expression evaluates to null, the result is also null.
111
112       exists option-name
113
114         The  exists expression returns true if the specified option exists in
115         the incoming DHCP packet being processed.
116       known
117
118         The known expression returns true if the client whose request is cur‐
119         rently being processed is known - that is, if there's a host declara‐
120         tion for it.
121       static
122
123         The static expression returns true  if  the  lease  assigned  to  the
124         client  whose  request is currently being processed is derived from a
125         static address assignment.
126

DATA EXPRESSIONS

128       Several of the boolean expressions above depend on the results of eval‐
129       uating  data  expressions.    A  list  of these expressions is provided
130       here.
131
132       substring (data-expr, offset, length)
133
134         The substring operator evaluates the data expression and returns  the
135         substring  of  the result of that evaluation that starts offset bytes
136         from the beginning, continuing for length bytes.  Offset  and  length
137         are  both numeric expressions.  If data-expr, offset or length evalu‐
138         ate to null, then the result is also null.  If offset is greater than
139         or equal to the length of the evaluated data, then a zero-length data
140         string is returned.  If length is greater then the  remaining  length
141         of the evaluated data after offset, then a data string containing all
142         data from offset to the end of the evaluated data is returned.
143
144       suffix (data-expr, length)
145
146         The suffix operator evaluates data-expr and returns the  last  length
147         bytes  of  the result of that evaluation. Length is a numeric expres‐
148         sion.  If data-expr or length evaluate to null, then  the  result  is
149         also  null.   If suffix evaluates to a number greater than the length
150         of the evaluated data, then the evaluated data is returned.
151
152       lcase (data-expr)
153
154         The lcase function returns the result of  evaluating  data-expr  con‐
155         verted  to  lower  case.    If  data-expr evaluates to null, then the
156         result is also null.
157
158       ucase (data-expr)
159
160         The ucase function returns the result of  evaluating  data-expr  con‐
161         verted  to  upper  case.    If  data-expr evaluates to null, then the
162         result is also null.
163
164       option option-name
165
166         The option operator returns the contents of the specified  option  in
167         the packet to which the server is responding.
168
169       config-option option-name
170
171         The config-option operator returns the value for the specified option
172         that the DHCP client or server has been configured to send.
173
174       hardware
175
176         The hardware operator returns a data string whose  first  element  is
177         the  type  of network interface indicated in packet being considered,
178         and whose subsequent elements are client's link-layer  address.    If
179         there is no packet, or if the RFC2131 hlen field is invalid, then the
180         result is null.   Hardware types  include  ethernet  (1),  token-ring
181         (6),  and  fddi  (8).   Hardware types are specified by the IETF, and
182         details on how the type numbers are defined can be found  in  RFC2131
183         (in the ISC DHCP distribution, this is included in the doc/ subdirec‐
184         tory).
185
186       packet (offset, length)
187
188         The packet operator returns the specified portion of the packet being
189         considered,  or null in contexts where no packet is being considered.
190         Offset and length are applied to the contents packet as in  the  sub‐
191         string operator.
192
193       string
194
195         A  string, enclosed in quotes, may be specified as a data expression,
196         and returns the text between the  quotes,  encoded  in  ASCII.    The
197         backslash  ('\') character is treated specially, as in C programming:
198         '\t' means TAB, '\r' means carriage return, '\n' means  newline,  and
199         '\b'  means  bell.    Any  octal  value can be specified with '\nnn',
200         where nnn is any positive octal number less than 0400.  Any hexadeci‐
201         mal  value  can  be  specified  with '\xnn', where nn is any positive
202         hexadecimal number less than or equal to 0xff.
203
204       colon-separated hexadecimal list
205
206         A list of hexadecimal octet values, separated by colons, may be spec‐
207         ified as a data expression.
208
209       concat (data-expr1, ..., data-exprN)
210         The expressions are evaluated, and the results of each evaluation are
211         concatenated in the sequence that the subexpressions are listed.   If
212         any  subexpression evaluates to null, the result of the concatenation
213         is null.
214
215       reverse (numeric-expr1, data-expr2)
216         The two expressions are evaluated, and then the result of  evaluating
217         the  data  expression  is  reversed in place, using hunks of the size
218         specified in the numeric expression.   For example,  if  the  numeric
219         expression  evaluates  to  four, and the data expression evaluates to
220         twelve bytes of data, then the reverse expression  will  evaluate  to
221         twelve  bytes  of  data, consisting of the last four bytes of the the
222         input data, followed by the middle four bytes, followed by the  first
223         four bytes.
224
225       leased-address
226         In  any context where the client whose request is being processed has
227         been assigned an IP address, this data  expression  returns  that  IP
228         address.  In any context where the client whose request is being pro‐
229         cessed has not been assigned an ip address, if this  data  expression
230         is found in executable statements executed on that client's behalf, a
231         log message indicating  "there  is  no  lease  associated  with  this
232         client"   is  syslogged  to  the  debug  level  (this  is  considered
233         dhcpd.conf debugging information).
234
235       binary-to-ascii (numeric-expr1, numeric-expr2, data-expr1, data-expr2)
236         Converts the result of evaluating data-expr2 into a text string  con‐
237         taining one number for each element of the result of evaluating data-
238         expr2.   Each number is separated from the other  by  the  result  of
239         evaluating data-expr1.   The result of evaluating numeric-expr1 spec‐
240         ifies the base (2 through 16) into which the numbers should  be  con‐
241         verted.    The result of evaluating numeric-expr2 specifies the width
242         in bits of each number, which may be either 8, 16 or 32.
243
244         As an example of the preceding three types of expressions, to produce
245         the  name  of  a  PTR  record  for the IP address being assigned to a
246         client, one could write the following expression:
247
248               concat (binary-to-ascii (10, 8, ".",
249                                        reverse (1, leased-address)),
250                       ".in-addr.arpa.");
251
252
253       encode-int (numeric-expr, width)
254         Numeric-expr is evaluated and encoded as a data string of the  speci‐
255         fied  width, in network byte order (most significant byte first).  If
256         the numeric expression evaluates to the null  value,  the  result  is
257         also null.
258
259       pick-first-value (data-expr1 [ ... exprn ] )
260         The pick-first-value function takes any number of data expressions as
261         its arguments.   Each expression  is  evaluated,  starting  with  the
262         first  in the list, until an expression is found that does not evalu‐
263         ate to a null value.   That expression is returned, and none  of  the
264         subsequent  expressions  are evaluated.   If all expressions evaluate
265         to a null value, the null value is returned.
266
267       host-decl-name
268         The host-decl-name function returns the name of the host  declaration
269         that  matched  the client whose request is currently being processed,
270         if any.   If no host declaration matched,  the  result  is  the  null
271         value.
272

NUMERIC EXPRESSIONS

274       Numeric  expressions  are expressions that evaluate to an integer.   In
275       general, the maximum size of such an integer should not be  assumed  to
276       be representable in fewer than 32 bits, but the precision of such inte‐
277       gers may be more than 32 bits.
278
279       extract-int (data-expr, width)
280
281         The extract-int operator extracts an integer value  in  network  byte
282         order  from  the  result of evaluating the specified data expression.
283         Width is the width in bits of the integer to extract.  Currently, the
284         only  supported  widths  are 8, 16 and 32.   If the evaluation of the
285         data expression doesn't provide sufficient bits to extract an integer
286         of the specified size, the null value is returned.
287
288       lease-time
289
290         The  duration  of the current lease - that is, the difference between
291         the current time and the time that the lease expires.
292
293       number
294
295         Any number between zero and the maximum  representable  size  may  be
296         specified as a numeric expression.
297
298       client-state
299
300         The  current  state of the client instance being processed.   This is
301         only useful in DHCP client  configuration  files.    Possible  values
302         are:
303
304         · Booting  -  DHCP client is in the INIT state, and does not yet have
305           an IP address.   The next message transmitted will  be  a  DHCPDIS‐
306           COVER, which will be broadcast.
307
308         · Reboot  -  DHCP  client is in the INIT-REBOOT state.   It has an IP
309           address, but is not yet using it.   The next message to  be  trans‐
310           mitted  will  be  a  DHCPREQUEST,  which will be broadcast.   If no
311           response is heard, the client will bind to its address and move  to
312           the BOUND state.
313
314         · Select - DHCP client is in the SELECTING state - it has received at
315           least one DHCPOFFER message, but  is  waiting  to  see  if  it  may
316           receive  other DHCPOFFER messages from other servers.   No messages
317           are sent in the SELECTING state.
318
319         · Request - DHCP client is in the REQUESTING state - it has  received
320           at  least  one  DHCPOFFER message, and has chosen which one it will
321           request.   The next message to be sent will be a  DHCPREQUEST  mes‐
322           sage, which will be broadcast.
323
324         · Bound  -  DHCP client is in the BOUND state - it has an IP address.
325           No messages are transmitted in this state.
326
327         · Renew - DHCP client is in  the  RENEWING  state  -  it  has  an  IP
328           address,  and  is  trying  to contact the server to renew it.   The
329           next message to be sent will be a DHCPREQUEST message,  which  will
330           be unicast directly to the server.
331
332         · Rebind  -  DHCP  client  is  in  the REBINDING state - it has an IP
333           address, and is trying to contact any server  to  renew  it.    The
334           next message to be sent will be a DHCPREQUEST, which will be broad‐
335           cast.
336

REFERENCE: ACTION EXPRESSIONS

338       log (priority, data-expr)
339
340         Logging statements may be used to send information  to  the  standard
341         logging  channels.  A logging statement includes an optional priority
342         (fatal, error, info, or debug), and a data expression.
343
344         Logging statements take only a single data expression argument, so if
345         you  want  to  output  multiple data values, you will need to use the
346         concat operator to concatenate them.
347
348       execute (command-path [, data-expr1, ... data-exprN]);
349
350         The execute statement runs an external command.  The  first  argument
351         is  a  string  literal  containing the name or path of the command to
352         run.  The other arguments, if present, are either string literals  or
353         data-  expressions  which  evaluate  to text strings, to be passed as
354         command-line arguments to the command.
355
356         execute is synchronous; the program will  block  until  the  external
357         command  being  run  has  finished.  Please note that lengthy program
358         execution (for example, in an "on commit" in dhcpd.conf)  may  result
359         in  bad  performance  and  timeouts.  Only external applications with
360         very short execution times are suitable for use.
361
362         Passing user-supplied data to an external application might  be  dan‐
363         gerous.   Make sure the external application checks input buffers for
364         validity.  Non-printable ASCII  characters  will  be  converted  into
365         dhcpd.conf  language  octal  escapes ("777"), make sure your external
366         command handles them as such.
367
368         It is possible to use the execute statement in any context, not  only
369         on events. If you put it in a regular scope in the configuration file
370         you will execute that command every time a scope is evaluated.
371

REFERENCE: DYNAMIC DNS UPDATES

373       The DHCP client and server have the ability to dynamically  update  the
374       Domain Name System.  Within the configuration files, you can define how
375       you want the Domain Name System to be updated.  These updates  are  RFC
376       2136  compliant so any DNS server supporting RFC 2136 should be able to
377       accept updates from the DHCP server.
378

SECURITY

380       Support for TSIG and DNSSEC is not yet available.  When  you  set  your
381       DNS  server up to allow updates from the DHCP server or client, you may
382       be exposing it to unauthorized updates.  To avoid this,  the  best  you
383       can do right now is to use IP address-based packet filtering to prevent
384       unauthorized hosts from submitting update requests.   Obviously,  there
385       is  currently no way to provide security for client updates - this will
386       require TSIG or DNSSEC, neither of which is yet available in  the  DHCP
387       distribution.
388
389       Dynamic  DNS  (DDNS)  updates  are  performed  by  using the dns-update
390       expression.  The dns-update expression is  a  boolean  expression  that
391       takes four parameters.  If the update succeeds, the result is true.  If
392       it fails, the result is false.  The four parameters that  the  are  the
393       resource record type (RR), the left hand side of the RR, the right hand
394       side of the RR and the ttl that should be applied to the  record.   The
395       simplest  example of the use of the function can be found in the refer‐
396       ence section of the dhcpd.conf file, where events  are  described.   In
397       this example several statements are being used to make the arguments to
398       the dns-update.
399
400       In the example, the first argument to the first Bdns-update  expression
401       is a data expression that evaluates to the A RR type.  The second argu‐
402       ment is constructed by concatenating the DHCP host-name option  with  a
403       text  string  containing  the  local  domain,  in  this case "ssd.exam‐
404       ple.net".  The third argument is constructed by converting the  address
405       the  client has been assigned from a 32-bit number into an ascii string
406       with each byte separated by a ".".  The fourth argument, the TTL, spec‐
407       ifies  the  amount of time remaining in the lease (note that this isn't
408       really correct, since the DNS server will pass this TTL out whenever  a
409       request  comes  in, even if that is only a few seconds before the lease
410       expires).
411
412       If the first dns-update statement succeeds, it is followed  up  with  a
413       second update to install a PTR RR.  The installation of a PTR record is
414       similar to installing an A RR except that the left  hand  side  of  the
415       record  is  the leased address, reversed, with ".in-addr.arpa" concate‐
416       nated.  The right hand side is the fully qualified domain name  of  the
417       client to which the address is being leased.
418

SEE ALSO

420       dhcpd.conf(5),   dhcpd.leases(5),   dhclient.conf(5),  dhcp-options(5),
421       dhcpd(8), dhclient(8), RFC2132, RFC2131.
422

AUTHOR

424       The Internet Systems Consortium DHCP Distribution was  written  by  Ted
425       Lemon  under  a contract with Vixie Labs.  Funding for this project was
426       provided through Internet Systems Consortium.  Information about Inter‐
427       net Systems Consortium can be found at https://www.isc.org.
428
429
430
431                                                                  dhcp-eval(5)
Impressum