forsyth20121205-174063a80cc13 years agoHistory
354 lines · 8.5 KB · Text
RawDownload
.TH DHCPCLIENT 2.SH NAMEDhcpclient: Bootconf, Lease, bootp, dhcp, applycfg, removecfg \- client's side of dynamic host configuration protocol.SH SYNOPSIS.EXinclude "dhcp.m";   # sicdhcpclient := load Dhcpclient Dhcpclient->PATH;Bootconf, Lease: import dhcpclient; Bootconf: adt {    ip:      string;    ipgw:    string;    ipmask:  string;    bootf:   string;    bootip:  string;    dhcpip:  string;    siaddr:  string;    serverid: string;    sys:     string;    dom:     string;    lease:   int;    options: array of array of byte;    vendor:  array of array of byte;     new:     fn(): ref Bootconf;    get:     fn(c: self ref Bootconf, n: int): array of byte;    getint:  fn(c: self ref Bootconf, n: int): int;    getip:   fn(c: self ref Bootconf, n: int): string;    getips:  fn(c: self ref Bootconf, n: int): list of string;    gets:    fn(c: self ref Bootconf, n: int): string;    put:     fn(c: self ref Bootconf, n: int, a: array of byte);    putint:  fn(c: self ref Bootconf, n: int, v: int);    putips:  fn(c: self ref Bootconf, n: int, ips: list of string);    puts:    fn(c: self ref Bootconf, n: int, s: string);}; Lease: adt {    configs: chan of (ref Bootconf, string);     release: fn(l: self ref Lease);}; init:      fn();tracing:   fn(debug: int);bootp:     fn(net: string, ctlifc: ref Sys->FD, device: string,               init: ref Bootconf): (ref Bootconf, string);dhcp:      fn(net: string, ctlifc: ref Sys->FD, device: string,               init: ref Bootconf, options: array of int):               (ref Bootconf, ref Lease, string); applycfg:  fn(net: string, ctlifc: ref Sys->FD,               conf: ref Bootconf): string;removecfg: fn(net: string, ctlifc: ref Sys->FD,               conf: ref Bootconf): string;.EE.SH DESCRIPTION.B Dhcpclientimplements the client side of the Dynamic Host Configuration Protocol (DHCP) of Internet RFC2131.In the interface, Internet addresses are represented as strings, in forms that.IR ip (2)can parse, and that can be written directly to control files in.IR ip (3)..PP.B Initmust be called before invoking any other operation of the module..PP.B Bootpreserves the UDP port on.I netfor use by BOOTP/DHCP clients, and sends a BOOTP request (ie, one without a DHCP operation code)..I Netis the name of the network directory (if nil, the default is.BR /net ).If.B bootpis to configure the interface according to the results received,.I ctlifcshould be open on the control file of the.IB net /ipifcdirectory for the interface to be configured; otherwise it should be nil..B Bootprepeats the request periodically until it either receives a reply or has made 5 attempts.It returns a tuple.BI ( conf,\ err ).If it has received a reply,.I confrefers to a.B Bootconfvalue that contains the values received, and.I erris nil.If.I ctlifcis not nil, the interface will also have been configured appropriately.If a valid reply has not been received, or some other error occurred,.I confis nil, and.I erris a diagnostic..PP.B Dhcphas a similar interface, but runs the full DHCP protocol.The.I optionsarray has integers representing possible DHCP options;.B dhcpasks the server to provide values for them.If.I optionsis nil, a few option values are requested that might be useful for Inferno(eg, subnet mask, gateway, DNS server, authentication and file servers, and so on).If the server does supply them, they can be retrieved either fromspecific fields of.BR Bootconf ,or using its.I getoperations..I Initis also usually nil, but can refer to a.B Bootconfthat provides some values to suggest to the server, for instance if the clientknows a previously-assigned address stored in non-volatile memory..B Dhcpreturns a tuple.BI ( conf,\ lease,\ err ),where.I confand.I errare just as for.BR bootp ,and the new component.I leaseis a reference to a.B Leasevalue that gives access to the state of the client's address assignment..PPDHCP allows a server to assign a client an address permanently, or to lease it for a specified time.In the latter case,.B Bootconf.leasewill have a non-zero value, andthe client must periodically renew the lease to retain the address, and.B dhcpcreates a process to do so.The.B Leasevalue provides a way for that process to communicate changes (if any) to the network configuration.Each time the configuration changes, the process will send a message on the channel.BR configs .(The channel is buffered, and.B dhcpfirst discards any previous notifications not yet received, so there are no ill effectsif no process ever receives from the channel.)Each message is a tuple.BI ( conf,\ diag ).If a new state change has been made successfully,.I confrefers to a.B Bootconfvalue with the details.Otherwise,.I confis nil and.I diagexplains what went wrong.In any case, the watchdog process continues to try to extend the lease, or failing that,obtain a new network configuration, perhaps from another server..B Lease.releasemay be called to release the leased address and stop the watchdog..PP.B Bootconfhas the following operations:.TP.B new()Return a reference to a.B Bootconfwith values initialised to nil or 0..TP.IB bc .get( n )Return the value of DHCP option.I nas a raw array of bytes.Return nil if the option is not set..TP.IB bc .getint( n )Return the value of option.I ninterpreted as an integer.Return zero if the option is not set..TP.IB bc .getip( n )Return the first Internet address provided for option.IR n ..TP.IB bc .getips( n )Return a list of all the Internet addresses provided for option.IR n ..TP.IB bc .gets( n )Return the value of option.I nas a string..TP.IB bc .put( n,\ a )Set the value of DHCP option.I nto the bytes of byte array.IR a .If.I ais nil,.B putremoves any existing value for the option..TP.IB bc .putint( n,\ v)Set option.I nto the integer value.IR v ..TP.IB bc .putips( n,\ ips )Set option.I nto the list of Internet addresses.IR ips ..TP.IB bc .puts( n,\ s )Set option.I nto the string.IR n ..PP.B Dhcpclientnames a few constants representing commonly-used configuration options (attributes).They are suitable parameters for the option selector.I nof.BR Bootconf 's.I getand.I putfunctions.The first set of constants name options for both BOOTP and DHCP:.PP.PD 0.TP 25.B OdnsserverInternet address(es) of Domain Name Servers.TP.B OdomainnameCurrent domain (see.BR Bootconf.dom ).TP.B OhostnameHost name (see.BR Bootconf.sys ).TP.B OmaskNetwork mask (IPv4).Also see.BR Bootconf.ipmask ..TP.B OnetbiosnsNetBIOS servers.TP.B OntpserverNetwork Time Protocol servers.TP.B Opop3serverPOP3 mail servers.TP.B OrouterDefault router for subnet (see.BR Bootconf.ipgw ).TP.B OsmtpserverSMTP mail delivery servers.TP.B OvendorinfoVendor-specific data (see below).TP.B OwwwserverHTTP proxy.PD.PPThe second set has DHCP options:.PP.PD 0.TP 25.B ObootfileName of the file containing a kernel for the client  to load (eg, by TFTP); see.BR Bootconf.bootf ..TP.B OleaseLease time for IP address, in seconds (also see.BR Bootconf.lease ).TP.B OmaxmsgMaximum DHCP size the client is willing to accept (minimum 576 bytes)..TP.B OrebindingtimeTime interval in seconds from address assignment to the time address must be rebound..TP.B OrenewaltimeTime interval in seconds from address assignment to first attempt to renew the address..TP.B OtftpserverTFTP server from which to fetch kernel and parameter files; see.BR Bootconf.bootip ..TP.B OvendorclassIdentify vendor type and configuration of client. Inferno setsthis to.B plan9_386(sic) to encourage Plan 9 DHCP servers to respond; other servers will ignore it..PD.PPThe final set give vendor-specific options that Inferno shares with Plan 9:.PP.PD 0.TP 25.B OvendorFlag OR'd in to an option number to mark it as destined for the `vendor information' section..TP.B OP9authAuthentication server.RB ( Ovendor|129 ).TP.B OP9fsFile server.RB ( Ovendor|128 ).PD.PPGiven a network configuration in.IR conf ,and a valid file descriptor for a network interface's control file,in the network.IR net ,.B applycfgsets the basic interface parameters (address, network mask, default gateway),and writes other parameters to.IR net /ndb ;conversely,.B removecfgremoves from the interface just those parameters set by.IR conf .Normally these functions are called automatically, as required, by.B dhcpand its watchdog process..SH SOURCE.B /appl/lib/dhcpclient.b.SH SEE ALSO.IR bootpd (8),.IR dhcp (8)