- 论坛徽章:
- 0
|
名称
dhcp-eval - ISC DHCP conditional evaluation条件等式
描述
ISC DHCP的客户端和服务器都支持依据接收到数据包的内容进行特定的操作。相关的文档如下。
条件行为
条件行为是由if 语句和else 语句或elsif 语句组成的。一个条件语句可以出现在任何常规的语句中(也就是任何option 语句中),并且可以包含一个或者多个这样的语句。服务器中典型的条件语句象这个样子:
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;
}
而在客户端,则可能是:
# 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;
}
If语句和elsif条件语句都使用布尔值作为参数。它们对后面的参数做一个计算,如果为得到的值为真,执行紧接着的大括号中的内容,并且其它所有的elsif和else都被忽略;否则,执行elsif语句的检查,直到找到一个匹配,或者没有找到匹配,执行最后的else语句。布尔表达式把null看作是false 。
布尔表达式
以下是DHCP支持的布尔表达式列表。
data-expression-1 = data-expression-2
等号“=”操作符。比较两边的表达式,返回真true或假false。如果左边或者右边的值是空“null”,返回值也是“null”。
boolean-expression-1 and boolean-expression-2
与“and”操作符。左右两边如果都是真,返回也是真;如果两边有一边是假,返回就是假。如果两边有一边是null,返回也是null。
boolean-expression-1 or boolean-expression-2
或者“or”操作符。左右两边有一个是真的时候返回真,如果有两个都是假时返回假,如果两边有任何一边是null,返回值也是null。
not boolean-expression
否“not”。后面的值如果是真,则返回假;如果是假,则反回真。如果后面的值是null,返回null。
exists option-name
存在“exists”操作符。在接收到的DHCP包中如果有指定的选项则返回真,否则返回假。
known
知道“known”操作符。如果客户端是已知的客户端,也就是说此客户端有host语句声明时返回真。
static
静态“static”。如果当前客户被分配的是静态地址,就返回真。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/39411/showart_331560.html |
|