dhcp-eval(5)                                                      dhcp-eval(5)



[1mNAME[0m
       dhcp-eval - ISC DHCP conditional evaluation

[1mDESCRIPTION[0m
       The Internet Systems Consortium DHCP client and server both provide the
       ability to perform conditional behavior depending on the contents of
       packets they receive.   The syntax for specifying this conditional
       behaviour is documented here.

[1mREFERENCE: CONDITIONAL BEHAVIOUR[0m
       Conditional behaviour is specified using the if statement and the else
       or elsif 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:

       if option dhcp-user-class = "accounting" {
         max-lease-time 17600;
         option domain-name "accounting.example.org";
         option domain-name-servers ns1.accounting.example.org,
                           ns2.accounting.example.org;
       } elsif option dhcp-user-class = "sales" {
         max-lease-time 17600;
         option domain-name "sales.example.org";
         option domain-name-servers ns1.sales.example.org,
                           ns2.sales.example.org;
       } elsif option dhcp-user-class = "engineering" {
         max-lease-time 17600;
         option domain-name "engineering.example.org";
         option domain-name-servers ns1.engineering.example.org,
                           ns2.engineering.example.org;
       } else {
         max-lease-time 600;
         option domain-name "misc.example.org";
         option domain-name-servers ns1.misc.example.org,
                           ns2.misc.example.org;
       }

       On the client side, an example of conditional evaluation might be:

       # example.org filters DNS at its firewall, so we have to use their DNS
       # servers when we connect to their network.   If we are not at
       # example.org, prefer our own DNS server.
       if not option domain-name = "example.org" {
         prepend domain-name-servers 127.0.0.1;
       }

       The [1mif [22mstatement and the [1melsif [22mcontinuation statement both take boolean
       expressions as their arguments.   That is, they take expressions that,
       when evaluated, produce a boolean result.   If the expression evaluates
       to true, then the statements enclosed in braces following the [1mif[0m
       statement are executed, and all subsequent [1melsif [22mand [1melse [22mclauses are
       skipped.   Otherwise, each subsequent [1melsif [22mclause's expression is
       checked, until an elsif clause is encountered whose test evaluates to
       true.   If such a clause is found, the statements in braces following
       it are executed, and then any subsequent [1melsif [22mand [1melse [22mclauses are
       skipped.   If all the [1mif [22mand [1melsif [22mclauses are checked but none of
       their expressions evaluate true, then if there is an [1melse [22mclause, the
       statements enclosed in braces following the [1melse [22mare evaluated.
       Boolean expressions that evaluate to null are treated as false in
       conditionals.

[1mBOOLEAN EXPRESSIONS[0m
       The following is the current list of boolean expressions that are
       supported by the DHCP distribution.

       [4mdata-expression-1[24m [1m= [4m[22mdata-expression-2[0m

         The [1m= [22moperator compares the values of two data expressions, returning
         true if they are the same, false if they are not.   If either the
         left-hand side or the right-hand side are null, the result is also
         null.

       [4mboolean-expression-1[24m [1mand [4m[22mboolean-expression-2[0m

         The [1mand [22moperator evaluates to true if the boolean expression on the
         left-hand side and the boolean expression on the right-hand side both
         evaluate to true.  Otherwise, it evaluates to false.  If either the
         expression on the left-hand side or the expression on the right-hand
         side are null, the result is null.

       [4mboolean-expression-1[24m [1mor [4m[22mboolean-expression-2[0m

         The [1mor [22moperator evaluates to true if either the boolean expression on
         the left-hand side or the boolean expression on the right-hand side
         evaluate to true.  Otherwise, it evaluates to false.  If either the
         expression on the left-hand side or the expression on the right-hand
         side are null, the result is null.

       [1mnot [4m[22mboolean-expression[0m

         The [1mnot [22moperator evaluates to true if [4mboolean-expression[24m evaluates to
         false, and returns false if [4mboolean-expression[24m evaluates to true.
         If [4mboolean-expression[24m evaluates to null, the result is also null.

       [1mexists [4m[22moption-name[0m

         The [1mexists [22mexpression returns true if the specified option exists in
         the incoming DHCP packet being processed.
       [1mknown[0m

         The [1mknown [22mexpression returns true if the client whose request is
         currently being processed is known - that is, if there's a host
         declaration for it.
       [1mstatic[0m

         The [1mstatic [22mexpression returns true if the lease assigned to the
         client whose request is currently being processed is derived from a
         static address assignment.

[1mDATA EXPRESSIONS[0m
       Several of the boolean expressions above depend on the results of
       evaluating data expressions.   A list of these expressions is provided
       here.

       [1msubstring ([4m[22mdata-expr[24m[1m, [4m[22moffset[24m[1m, [4m[22mlength[24m[1m)[0m

         The [1msubstring [22moperator evaluates the data expression and returns the
         substring of the result of that evaluation that starts [4moffset[24m bytes
         from the beginning, continuing for [4mlength[24m bytes.  [4mOffset[24m and [4mlength[0m
         are both numeric expressions.  If [4mdata-expr[24m, [4moffset[24m or [4mlength[0m
         evaluate to null, then the result is also null.  If [4moffset[24m is greater
         than or equal to the length of the evaluated data, then a zero-length
         data string is returned.  If [4mlength[24m [4mis[24m [4mgreater[24m [4mthen[24m [4mthe[24m [4mremaining[0m
         [4mlength[24m [4mof[24m [4mthe[24m [4mevaluated[24m [4mdata[24m [4mafter[24m [4moffset[24m, then a data string
         containing all data from [4moffset[24m to the end of the evaluated data is
         returned.

       [1msuffix ([4m[22mdata-expr[24m[1m, [4m[22mlength[24m[1m)[0m

         The [1msuffix [22moperator evaluates [4mdata-expr[24m and returns the last [4mlength[0m
         bytes of the result of that evaluation. [4mLength[24m is a numeric
         expression.  If [4mdata-expr[24m or [4mlength[24m evaluate to null, then the result
         is also null.  If [4msuffix[24m evaluates to a number greater than the
         length of the evaluated data, then the evaluated data is returned.

       [1mlcase ([4m[22mdata-expr[24m[1m)[0m

         The [1mlcase [22mfunction returns the result of evaluating [4mdata-expr[0m
         converted to lower case.   If [4mdata-expr[24m evaluates to null, then the
         result is also null.

       [1mucase ([4m[22mdata-expr[24m[1m)[0m

         The [1mucase [22mfunction returns the result of evaluating [4mdata-expr[0m
         converted to upper case.   If [4mdata-expr[24m evaluates to null, then the
         result is also null.

       [1moption [4m[22moption-name[0m

         The [1moption [22moperator returns the contents of the specified option in
         the packet to which the server is responding.

       [1mconfig-option [4m[22moption-name[0m

         The [1mconfig-option [22moperator returns the value for the specified option
         that the DHCP client or server has been configured to send.

       [1mhardware[0m

         The [1mhardware [22moperator returns a data string whose first element is
         the type of network interface indicated in packet being considered,
         and whose subsequent elements are client's link-layer address.   If
         there is no packet, or if the RFC2131 [4mhlen[24m field is invalid, then the
         result is null.   Hardware types include ethernet (1), token-ring
         (6), and fddi (8).   Hardware types are specified by the IETF, and
         details on how the type numbers are defined can be found in RFC2131
         (in the ISC DHCP distribution, this is included in the doc/
         subdirectory).

       [1mpacket ([4m[22moffset[24m[1m, [4m[22mlength[24m[1m)[0m

         The [1mpacket [22moperator returns the specified portion of the packet being
         considered, or null in contexts where no packet is being considered.
         [4mOffset[24m and [4mlength[24m are applied to the contents packet as in the
         [1msubstring [22moperator.

       [4mstring[0m

         A string, enclosed in quotes, may be specified as a data expression,
         and returns the text between the quotes, encoded in ASCII.   The
         backslash ('\') character is treated specially, as in C programming:
         '\t' means TAB, '\r' means carriage return, '\n' means newline, and
         '\b' means bell.   Any octal value can be specified with '\nnn',
         where nnn is any positive octal number less than 0400.  Any
         hexadecimal value can be specified with '\xnn', where nn is any
         positive hexadecimal number less than or equal to 0xff.

       [4mcolon-separated[24m [4mhexadecimal[24m [4mlist[0m

         A list of hexadecimal octet values, separated by colons, may be
         specified as a data expression.

       [1mconcat ([4m[22mdata-expr1[24m[1m, ..., [4m[22mdata-exprN[24m[1m)[0m
         The expressions are evaluated, and the results of each evaluation are
         concatenated in the sequence that the subexpressions are listed.   If
         any subexpression evaluates to null, the result of the concatenation
         is null.

       [1mreverse ([4m[22mnumeric-expr1[24m[1m, [4m[22mdata-expr2[24m[1m)[0m
         The two expressions are evaluated, and then the result of evaluating
         the data expression is reversed in place, using hunks of the size
         specified in the numeric expression.   For example, if the numeric
         expression evaluates to four, and the data expression evaluates to
         twelve bytes of data, then the reverse expression will evaluate to
         twelve bytes of data, consisting of the last four bytes of the the
         input data, followed by the middle four bytes, followed by the first
         four bytes.

       [1mleased-address[0m
         In any context where the client whose request is being processed has
         been assigned an IP address, this data expression returns that IP
         address.  In any context where the client whose request is being
         processed has not been assigned an ip address, if this data
         expression is found in executable statements executed on that
         client's behalf, a log message indicating "there is no lease
         associated with this client" is syslogged to the debug level (this is
         considered dhcpd.conf debugging information).

       [1mbinary-to-ascii ([4m[22mnumeric-expr1[24m[1m, [4m[22mnumeric-expr2[24m[1m, [4m[22mdata-expr1[24m[1m, [4m[22mdata-expr2[24m[1m)[0m
         Converts the result of evaluating data-expr2 into a text string
         containing one number for each element of the result of evaluating
         data-expr2.   Each number is separated from the other by the result
         of evaluating data-expr1.   The result of evaluating numeric-expr1
         specifies the base (2 through 16) into which the numbers should be
         converted.   The result of evaluating numeric-expr2 specifies the
         width in bits of each number, which may be either 8, 16 or 32.

         As an example of the preceding three types of expressions, to produce
         the name of a PTR record for the IP address being assigned to a
         client, one could write the following expression:

               concat (binary-to-ascii (10, 8, ".",
                                        reverse (1, leased-address)),
                       ".in-addr.arpa.");


       [1mencode-int ([4m[22mnumeric-expr[24m[1m, [4m[22mwidth[24m[1m)[0m
         Numeric-expr is evaluated and encoded as a data string of the
         specified width, in network byte order (most significant byte first).
         If the numeric expression evaluates to the null value, the result is
         also null.

       [1mpick-first-value ([4m[22mdata-expr1[24m [ ... [4mexpr[24mn ] [1m)[0m
         The pick-first-value function takes any number of data expressions as
         its arguments.   Each expression is evaluated, starting with the
         first in the list, until an expression is found that does not
         evaluate to a null value.   That expression is returned, and none of
         the subsequent expressions are evaluated.   If all expressions
         evaluate to a null value, the null value is returned.

       [1mhost-decl-name[0m
         The host-decl-name function returns the name of the host declaration
         that matched the client whose request is currently being processed,
         if any.   If no host declaration matched, the result is the null
         value.

[1mNUMERIC EXPRESSIONS[0m
       Numeric expressions are expressions that evaluate to an integer.   In
       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.

       [1mextract-int ([4m[22mdata-expr[24m[1m, [4m[22mwidth[24m[1m)[0m

         The [1mextract-int [22moperator extracts an integer value in network byte
         order from the result of evaluating the specified data expression.
         Width is the width in bits of the integer to extract.  Currently, the
         only supported widths are 8, 16 and 32.   If the evaluation of the
         data expression doesn't provide sufficient bits to extract an integer
         of the specified size, the null value is returned.

       [1mlease-time[0m

         The duration of the current lease - that is, the difference between
         the current time and the time that the lease expires.

       [4mnumber[0m

         Any number between zero and the maximum representable size may be
         specified as a numeric expression.

       [1mclient-state[0m

         The current state of the client instance being processed.   This is
         only useful in DHCP client configuration files.   Possible values
         are:

         [4mo[24m Booting - DHCP client is in the INIT state, and does not yet have
           an IP address.   The next message transmitted will be a
           DHCPDISCOVER, which will be broadcast.

         [4mo[24m Reboot - DHCP client is in the INIT-REBOOT state.   It has an IP
           address, but is not yet using it.   The next message to be
           transmitted will be a DHCPREQUEST, which will be broadcast.   If no
           response is heard, the client will bind to its address and move to
           the BOUND state.

         [4mo[24m Select - DHCP client is in the SELECTING state - it has received at
           least one DHCPOFFER message, but is waiting to see if it may
           receive other DHCPOFFER messages from other servers.   No messages
           are sent in the SELECTING state.

         [4mo[24m Request - DHCP client is in the REQUESTING state - it has received
           at least one DHCPOFFER message, and has chosen which one it will
           request.   The next message to be sent will be a DHCPREQUEST
           message, which will be broadcast.

         [4mo[24m Bound - DHCP client is in the BOUND state - it has an IP address.
           No messages are transmitted in this state.

         [4mo[24m Renew - DHCP client is in the RENEWING state - it has an IP
           address, and is trying to contact the server to renew it.   The
           next message to be sent will be a DHCPREQUEST message, which will
           be unicast directly to the server.

         [4mo[24m Rebind - DHCP client is in the REBINDING state - it has an IP
           address, and is trying to contact any server to renew it.   The
           next message to be sent will be a DHCPREQUEST, which will be
           broadcast.

[1mREFERENCE: ACTION EXPRESSIONS[0m
       [1mlog ([4m[22mpriority[24m[1m, [4m[22mdata-expr[24m[1m)[0m

         Logging statements may be used to send information to the standard
         logging channels.  A logging statement includes an optional priority
         ([1mfatal[22m, [1merror[22m, [1minfo[22m, or [1mdebug[22m), and a data expression.

         Logging statements take only a single data expression argument, so if
         you want to output multiple data values, you will need to use the
         [1mconcat [22moperator to concatenate them.

       [1mexecute ([4m[22mcommand-path[24m [1m[, [4m[22mdata-expr1[24m[1m, ... [4m[22mdata-exprN[24m[1m]);[0m

         The [1mexecute [22mstatement runs an external command.  The first argument
         is a string literal containing the name or path of the command to
         run.  The other arguments, if present, are either string literals or
         data- expressions which evaluate to text strings, to be passed as
         command-line arguments to the command.

         [1mexecute [22mis synchronous; the program will block until the external
         command being run has finished.  Please note that lengthy program
         execution (for example, in an "on commit" in dhcpd.conf) may result
         in bad performance and timeouts.  Only external applications with
         very short execution times are suitable for use.

         Passing user-supplied data to an external application might be
         dangerous.  Make sure the external application checks input buffers
         for validity.  Non-printable ASCII characters will be converted into
         dhcpd.conf language octal escapes ("777"), make sure your external
         command handles them as such.

         It is possible to use the execute statement in any context, not only
         on events. If you put it in a regular scope in the configuration file
         you will execute that command every time a scope is evaluated.

[1mREFERENCE: DYNAMIC DNS UPDATES[0m
       The DHCP client and server have the ability to dynamically update the
       Domain Name System.  Within the configuration files, you can define how
       you want the Domain Name System to be updated.  These updates are RFC
       2136 compliant so any DNS server supporting RFC 2136 should be able to
       accept updates from the DHCP server.

[1mSECURITY[0m
       Support for TSIG and DNSSEC is not yet available.  When you set your
       DNS server up to allow updates from the DHCP server or client, you may
       be exposing it to unauthorized updates.  To avoid this, the best you
       can do right now is to use IP address-based packet filtering to prevent
       unauthorized hosts from submitting update requests.  Obviously, there
       is currently no way to provide security for client updates - this will
       require TSIG or DNSSEC, neither of which is yet available in the DHCP
       distribution.

       Dynamic DNS (DDNS) updates are performed by using the [1mdns-update[0m
       expression.  The [1mdns-update [22mexpression is a boolean expression that
       takes four parameters.  If the update succeeds, the result is true.  If
       it fails, the result is false.  The four parameters that the are the
       resource record type (RR), the left hand side of the RR, the right hand
       side of the RR and the ttl that should be applied to the record.  The
       simplest example of the use of the function can be found in the
       reference section of the dhcpd.conf file, where events are described.
       In this example several statements are being used to make the arguments
       to the [1mdns-update[22m.

       In the example, the first argument to the first Bdns-update expression
       is a data expression that evaluates to the A RR type.  The second
       argument is constructed by concatenating the DHCP host-name option with
       a text string containing the local domain, in this case
       "ssd.example.net".  The third argument is constructed by converting the
       address the client has been assigned from a 32-bit number into an ascii
       string with each byte separated by a ".".  The fourth argument, the
       TTL, specifies the amount of time remaining in the lease (note that
       this isn't really correct, since the DNS server will pass this TTL out
       whenever a request comes in, even if that is only a few seconds before
       the lease expires).

       If the first [1mdns-update [22mstatement succeeds, it is followed up with a
       second update to install a PTR RR.  The installation of a PTR record is
       similar to installing an A RR except that the left hand side of the
       record is the leased address, reversed, with ".in-addr.arpa"
       concatenated.  The right hand side is the fully qualified domain name
       of the client to which the address is being leased.

[1mSEE ALSO[0m
       dhcpd.conf(5), dhcpd.leases(5), dhclient.conf(5), dhcp-options(5),
       dhcpd(8), dhclient(8), RFC2132, RFC2131.

[1mAUTHOR[0m
       The Internet Systems Consortium DHCP Distribution was written by Ted
       Lemon under a contract with Vixie Labs.  Funding for this project was
       provided through Internet Systems Consortium.  Information about
       Internet Systems Consortium can be found at [1mhttps://www.isc.org.[0m



                                                                  dhcp-eval(5)
