⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dhcp-client.texi

📁 this is sample about DHCP-agent
💻 TEXI
📖 第 1 页 / 共 2 页
字号:
the hostname DHCP option to the server. This allows servers to passconfiguration based on a hostname passed by the client. It will alsoinstruct the client to set the hostname to that variable. If you wantto pass a hostname to the server you should set this variable and notuse the ``override'' directive because the ``override'' directive onlyaffects system configuration.@exampleset hostname = "foo.example.com";@end example@end defvr@defvr {Client Configuration Variable} dhcp-discovery-retries This variable can be set to an integer valuewhich instructs the client on how many times it should retry a DHCPdiscover before it gives up.@exampleset dhcp-discovery-retries = 3;@end example@end defvr@defvr {Client Configuration Variable} icmp-retries This variable can be set to an integer value whichinstructs the client on how many times it should retry an ICMPoperation. This affects operations such as router latency discovery,ICMP netmask discovery etc.@exampleset icmp-retries = 3;@end example@end defvr@defvr {Client Configuration Variable} default-interface-mtuThis variable can be set to an integer valuewhich instructs the client on what it's default interface MTU shouldbe. This MTU is used during the initial DHCP discovery messages, andlater used to configure the interface MTU if no MTU was specified bythe DHCP server.@exampleset default-interface-mtu = 1500;@end example@end defvr@defvr {Client Configuration Variable} default-subnet-maskThis variable can be set to a netmask value tospecify a default subnet mask in case none is provided by the DHCPoperation. Unlike the ``override'' directive this provides a fallbackin case no subnet-mask is provided by the server.@exampleset default-subnet-mask = 255.255.255.0;@end example@end defvr@defvr {Client Configuration Variable} do-measure-router-latencyThis variable can be set to a booleanvalue to indicate whether or not the client should attempt to sendICMP ECHO requests to routers passed by the DHCP server and determinewhich is one has the least latency to become the defaultroute. Disabling this variable stops this operation from taking place,and the first router is used as the default route. This is useful ifthe routers cannot be reached by ICMP ECHO requests.@exampleenable do-measure-router-latency = yes;@end example@end defvr@section Writing Client Extensionsdhcp-client uses guile (GNU's Ubiquitous Intelligent Language forExtensions) to extend itself. Extensions can currently be written forhandling DHCP options. The rest of this section assumes you arefamiliar with the Scheme programming language. If you are not familiarwith the Scheme programming language then you cannot extend the clientto configure options is not programmed to handle.@subsection The Sysconf Scriptdhcp-client calls a sysconf script which is placed in the samedirectory as the configuration file. This script, like theconfiguration file, can be named either ``default.sysconf'' or afteran interface name.@subsection Looking At The Sysconf ScriptThe default sysconf script which is shipped with dhcp-agent is made upof several lambda expressions which are placed inside closures. Ifyou're not familiar with the concept of closures, refer to the guiledocumentation.Under each closure is a configure/unconfigure lambda expression whichare bound to top level symbols. These symbols are then placed in twohooks, one for the bound state, and one for the release state.@subsection The DNS Configuration: An ExampleWe'll walk through the DNS configuration (a very simple example) tosee how it was written. After this example a more in-depth discussionfollows. If you notice some details are skipped over, don't worry. Itwill become clear later.@example(define configure-dns #f)(define unconfigure-dns #f)@end exampleFirst we define two top level symbols to false. We'll later bindagainst these in the closure.@example(let ((configured-domain-name #f)       (configured-domain-name-servers #f)@end exampleWe begin the closure by defining two variables which will be used tohold any configured domain name and domain name servers. For DNSconfiguration these aren't useful, but for other sysconf code keepingthe values of configured data is useful when it comes time tounconfigure the system on a DHCP RELEASE.@example      ; check to see if we really need to configure       (do-configure         (lambda()          (and (client-configure? client-control          'dhcp-domain-name-servers)                (client-configure? client-control 'dhcp-domain-name)               (defined? 'dhcp-domain-name-servers)               (defined? 'dhcp-domain-name)))))@end exampleHere we define a lambda expression which will tell us whether or notwe should be performing any configuration for dns. The expression willreturn true if the options ``domain-name-servers'' and ``domain-name''have been passed to us by the DHCP server. Also it checks if the userhas requested that we configure these options.@example  ; configure dns options  (set! configure-dns        (lambda ()          (if (do-configure)              (let ((resolv-conf-file-port (open "/etc/resolv.conf" O_WRONLY 0644)))                (client-info-message "configuring resolver")                (map-in-order                 (lambda (dns-server)                   (simple-format resolv-conf-file-port "nameserver ~A\n" dns-server))  dhcp-domain-name-servers)                (simple-format resolv-conf-file-port "search ~A\n" dhcp-domain-name)                (close-port resolv-conf-file-port)                                        ; now setup the options so we can use them again in unconfigure.                (set! configured-domain-name dhcp-domain-name)                (set! configured-domain-name-servers dhcp-domain-name-servers)))))@end exampleThe ``configure-dns'' function will first check if ``do-configure''returns true. It will then open ``/etc/resolv.conf'' and notify theuser that the resolver is being configured. It then writes out thecontents of the string list ``dhcp-domain-name-servers'' to the fileprefixing each string with the keyword ``nameserver.'' Finally the``search'' keyword is written with the domain name.After the configuration is complete, the values are stored in``configured-domain-name'' and ``configured-domain-name-servers.''This allows us to remember the values in the event of unconfiguringthe system.@example                                        ; unconfigure dns options  (set! unconfigure-dns        (lambda()         ; We shouldn't really be doing anything. Any name server         ; is a good server :-)          #t)))@end exampleAs mentioned in the comment there's no need to do anyunconfiguration. We'd rather have a resolv.conf than delete it. Youcan always modify this to delete the file, or insert a different setof values.@example(add-hook! dhcp-bind-hook configure-dns)(add-hook! dhcp-release-hook unconfigure-dns)@end exampleFinally the two routines are bound to the DHCP BIND and DHCP RELEASEhooks. It is important to add the option handlers in reverseorder. You'll notice ``configure-interface'' is added last so that theinterface is configured first.@subsection The DHCP BOUND and DHCP RELEASE hooksTwo hooks are defined at the top level by theclient. ``dhcp-bind-hook'' and ``dhcp-release-hook.'' When the clientwants to configure itself it will call ``dhcp-bind-hook'' and when itreleases its lease it will call ``dhcp-release-hook.''@subsection How DHCP Options Are Passed To The Sysconf ScriptWhen the DHCP BOUND hook is called, all the options are defined astop level symbols which refer to either a string, or a list of stringsdepending on whether the option is a single atom, or a list of atoms[ TODO: make list of handled options along with their types. ]In order to check for the existance of an option, simple use``defined?'' to check if the symbol is bound.@example; check for the routers option(defined? 'dhcp-routers)@end exampleThis will return a boolean value of true of false depending on whetherthe DHCP option has been bound at the top level.@subsection Scheme Routines Provided By The ClientAt the top level a ``client-control'' symbol is bound to a controlobject which is used in every invocation of routines provided by theclient.@deffn {Client Sysconf Routine} client-configure? client-control option-symbolReturns #t of #f depending on whether or not the user has explicitlystated that the dhcp option should be configured.@end deffn@deffn {Client Sysconf Routine} client-interface-up client-control ip-address netmask mtuInitializes the network interface the client is handling and assignsthe requested @var{ip-address}, the @var{netmask} and @var{mtu}.@end deffn@deffn {Client Sysconf Routine} client-set-default-route client-control ip-addressSets the default route to the @var{ip-address} specified.@end deffn@deffn {Client Sysconf Routine} client-remove-default-route client-control ip-addressRemoves the default route to the @var{ip-address} specified.@end deffn@deffn {Client Sysconf Routine} client-get-default-mtu client-controlReturns the default mtu specified by the user.@end deffn@deffn {Client Sysconf Routine} client-get-default-subnet-mask client-controlReturns the default subnet-mask specified by the user.@end deffn@deffn {Client Sysconf Routine} client-info-message  stringPrints out the string using the client's @dfn{info_message} routine.@end deffn@deffn {Client Sysconf Routine} client-error-message stringPrints out the string using the client's @dfn{error_message} routine.@end deffn@deffn {Client Sysconf Routine} client-fatal-message stringPrints out the string using the client's @dfn{fatal_message}routine. This exits after passing the message to the user.@end deffn@deffn {Client Sysconf Routine} client-shutdown client-controlInvokes the @dfn{shutdown} routine in the client and causes theclient to exit as cleanly as possible, relinquishing any leases ithas. Warning! This should not be called from within a release hook.@end deffn@deffn {Client Sysconf Routine} client-discover-icmp-latency client-control address-listAccepts a list of addresses @var{address-list} and performs ICMP ECHOlatency tests to determine which host is responding fastest. A list ofaddress/average-latency pairs is returned.@end deffn@deffn {Client Sysconf Routine} client-do-discover-icmp-latency client-controlReturns #t if the user enabled ``do-measure-router-latency'' or #f ifnot.@end deffn@subsection Why Not Just Use A Shell Script?Traditionally the UNIX initialization process is programmed withsimple shell scripts. This is fine because all the variables arepassed from the local system (usually set by the administrator orvendor).In the case of DHCP configuration data is passed from a server whichought to be handled as untrustworthy data unless you're willing to useit in a certain way.For example, assuming you wish to configure your hostname according tothe DHCP server, you will receive the hostname as a string and usethat string for your hostname. You don't, though, want the hostnamepassed to be arbitrary shell code which is run inadvertently from yourshell script.Most DHCP clients in the wild have fixed this problem by quoting theDHCP options as they are passed to the shell. I still foresee this asproblematic, and a security hazard.Guile offers the Scheme programming language which is an incrediblysmall subset of Lisp. It's easy to pick up. The DHCP options arepassed to the Scheme system configuration script as strings or listsof strings. These strings are harmless unless you are specificallyasking the Scheme interpreter to evaluate them.On the other hand most casual users just want basic networking up, andthe ability to tweak certain options. The DHCP client already offersthis to anyone, irregardless of their knowledge of Scheme.@section Advanced Client Use[ TODO ]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -