第2部分 范例配置文件分析--3
时间:2007-06-20 来源:liufirst
下面一段是类的使用:
# You can declare a class of clients and then do address allocation # based on that. The example below shows a case where all clients # in a certain class get addresses on the 10.17.224/24 subnet, and all # other clients get addresses on the 10.0.29/24 subnet.
class "foo" { match if substring (option vendor-class-identifier, 0, 4) = "SUNW"; }
|
有关substring的说明:
substring (data-expr, offset, length)
The substring operator evaluates the data expression and returns the substring of the result of that evaluation that starts offset bytes from the beginning, continuing for length bytes. Offset and length are both numeric expressions. If data-expr, offset or length evaluate to null, then the result is also null. If offset is greater than or equal to the length of the evaluated data, then a zero-length data string is returned. If length is greater then the remaining length of the evaluated data after offset, then a data string containing all data from offset to the end of the evaluated data is returned. Substring 操作符对data-expr进行操作,data-expr是一个字符串,此操作符返回从data-expr的第offset个字符开始的第length个字符。Offset(偏移量)和length(长度)都是数值型表达式,如果data-expr、offset、length中有一个是null(空),返回值也是null;如果offset大于或等于字符串的长度,返回一个0长度的字符串(空串),如果length大于剩余部分字符串的长度,那么返回全部剩余部分。 |
括号中option的说明:
option option-name
The option operator returns the contents of the specified option in the packet to which the server is responding. 返回服务器响应的指定的option的内容。 |
有关vender-class-identifer的说明:
option vendor-class-identifier string;
This option is used by some DHCP clients to identify the vendor type and possibly the configuration of a DHCP client. The information is a string of bytes whose contents are specific to the vendor and are not specified in a standard. To see what vendor class identifier clients are sending, you can write the following in your DHCP server configuration file:
set vendor-string = option vendor-class-identifier;
This will result in all entries in the DHCP server lease database file for clients that sent vendor-class-identifier options having a set statement that looks something like this:
set vendor-string = "SUNW.Ultra-5_10";
The vendor-class-identifier option is normally used by the DHCP server to determine the options that are returned in the vendor-encapsulated-options option. Please see the VENDOR ENCAPSULATED OPTIONS section later in this manual page for further information. 某些DHCP客户端用来确定开发商类型并使对客户端根据类型配置成为可能,这个信息是字符串,它的内容就是开发商的名字,但是这个名字并没有标准化。要在服务器上看客户端发送的这个信息,可以在dhcp服务器的配置文件中写上这样的一句: set vendor-string = option vendor-class-identifier;
这会使DHCP服务器的lease数据库文件中记录所有的客户端发送vendor-class-identifier,就像这个样子: set vendor-string = "SUNW.Ultra-5_10"; 这个选项经常由DHCP服务器用来确定vendor-encapsulated-options选项返回的值。参见vendor encapsulated options。 |
再看vendor-encapsulated-options选项:
option vendor-encapsulated-options string;
The vendor-encapsulated-options option can contain either a single vendor-specific value or one or more vendor-specific suboptions. This option is not normally specified in the DHCP server configuration file - instead, a vendor class is defined for each vendor, vendor class suboptions are defined, values for those suboptions are defined, and the DHCP server makes up a response on that basis. Some default behaviours for well-known DHCP client vendors (currently, the Microsoft Windows 2000 DHCP client) are configured automatically, but otherwise this must be configured manually - see the VENDOR ENCAPSULATED OPTIONS section later in this manual page for details. 这个选项即包含了一个单独的开发商指定值或多个开发商指定的子选项,这个选项不经常在配置文件中指定,而是,为每个开发商定义开发商类,定义每个子类,确定每个子类的值,然后DHCP服务器基于那些值做出回应。 一些著名的DHCP客户端开发商(比如WIN2000)是自动配置的,但是对于其它的客户端必须手工配置,参见VENDOR ENCAPSULATED OPTIONS。 |
VENDOR ENCAPSULATED OPTIONS的内容
VENDOR ENCAPSULATED OPTIONS The DHCP protocol defines the vendor-encapsulated-options option, which allows vendors to define their own options that will be sent encapsulated in a standard DHCP option. The format of the vendor-encapsu-lated-options option is either a series of bytes whose format is not specified, or a sequence of options, each of which consists of a single-byte vendor-specific option code, followed by a single-byte length, followed by as many bytes of data as are specified in the length (the length does not include itself or the option code).
The value of this option can be set in one of two ways. The first way is to simply specify the data directly, using a text string or a colon-separated list of hexadecimal values. For example:
option vendor-encapsulated-options 2:4:AC:11:41:1: 3:12:73:75:6e:64:68:63:70:2d:73:65:72:76:65:72:31:37:2d:31: 4:12:2f:65:78:70:6f:72:74:2f:72:6f:6f:74:2f:69:38:36:70:63;
The second way of setting the value of this option is to have the DHCP server generate a vendor-specific option buffer. To do this, you must do four things: define an option space, define some options in that option space, provide values for them, and specify that that option space should be used to generate the vendor-encapsulated-options option.
To define a new option space in which vendor options can be stored, use the option space statement:
option space name ;
The name can then be used in option definitions, as described earlier in this document. For example:
option space SUNW; option SUNW.server-address code 2 = ip-address; option SUNW.server-name code 3 = text; option SUNW.root-path code 4 = text;
Once you have defined an option space and the format of some options, you can set up scopes that define values for those options, and you can say when to use them. For example, suppose you want to handle two different classes of clients. Using the option space definition shown in the previous example, you can send different option values to different clients based on the vendor-class-identifier option that the clients send, as follows:
class "vendor-classes" { match option vendor-class-identifier; }
option SUNW.server-address 172.17.65.1; option SUNW.server-name "sundhcp-server17-1";
subclass "vendor-classes" "SUNW.Ultra-5_10" { vendor-option-space SUNW; option SUNW.root-path "/export/root/sparc"; }
subclass "vendor-classes" "SUNW.i86pc" { vendor-option-space SUNW; option SUNW.root-path "/export/root/i86pc"; }
As you can see in the preceding example, regular scoping rules apply, so you can define values that are global in the global scope, and only define values that are specific to a particular class in the local scope. The vendor-option-space declaration tells the DHCP server to use options in the SUNW option space to construct the vendor-encapsulated-options option. |
翻译中文如下:
DHCP协议定义了vendor-encapsulated-options选项,它允许开发商定义他们自己的选项,这些选项会被封装在一起形成一个标准的DHCP选项。vendor-encapsu-lated-options选项也是一系列字节,它的格式不是特定的,它是一个选项序列,每一个选项包含一个单字节的开发商指定的选项代码,然后是一个单字节的长度,然后是这个长度规定的数目的字节的数据,长度不包含前面的选项代码和长度字节自身。 两种方法可以设定这个选项的值。第一种方法是简单的指定数据,使用文本字符串或者是冒号分隔的一组16进制数,例如: option vendor-encapsulated-options 2:4:AC:11:41:1: 3:12:73:75:6e:64:68:63:70:2d:73:65:72:76:65:72:31:37:2d:31: 4:12:2f:65:78:70:6f:72:74:2f:72:6f:6f:74:2f:69:38:36:70:63;
第二种方法是让DHCP服务器产生一个开发商指定的选项缓存。这样需要做4件事:定义一个选项空间,在这个空间中定义一些选项,为这些选项提供值,指定选项空间应该用来产生vendor-encapsulated-options选项。 为了定义一个开发商选项可以存储的新的选项空间,使用option space语句:
option space name ;
这里的name用在option定义中,例如:
option space SUNW; option SUNW.server-address code 2 = ip-address; option SUNW.server-name code 3 = text; option SUNW.root-path code 4 = text;
定义完选项空间和它的格式后,就可以在某个范围里定义这些选项的值,指定何时使用它们。例如,假定要管理两种客户端类,使用选项空间定义在前面的例子中,现在可以依据不同的vendor-class-identifier值向客户端发送不同的选项值,如下:
class "vendor-classes" { match option vendor-class-identifier; }
option SUNW.server-address 172.17.65.1; option SUNW.server-name "sundhcp-server17-1";
subclass "vendor-classes" "SUNW.Ultra-5_10" { vendor-option-space SUNW; option SUNW.root-path "/export/root/sparc"; }
subclass "vendor-classes" "SUNW.i86pc" { vendor-option-space SUNW; option SUNW.root-path "/export/root/i86pc"; }
就像这个例子一样,它作用的范围是由它所在的位置决定,这样就可以在全局范围里定义一个值,而在局部指定个别的类。vendor-option-space语句告诉DHCP服务器使用SUNW中的选项空间构建vendor-encapsulated-options选项。 |
最后看多子网网络定义:
shared-network 224-29 { subnet 10.17.224.0 netmask 255.255.255.0 { option routers rtr-224.example.org; } subnet 10.0.29.0 netmask 255.255.255.0 { option routers rtr-29.example.org; } pool { allow members of "foo"; range 10.17.224.10 10.17.224.250; } pool { deny members of "foo"; range 10.0.29.10 10.0.29.230; } } |
根据前面定义的类”foo”,这里定义了两个子网的池,一个池允许前面定义的foo用户,一个池拒绝。这样把用户按一个标准分成了2类。
以上是范例文件的解释,下面正式生成一个可用的配置文件。