1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
|
.TH DHCPCLIENT 2
.SH NAME
Dhcpclient: Bootconf, Lease, bootp, dhcp, applycfg, removecfg \- client's side of dynamic host configuration protocol
.SH SYNOPSIS
.EX
include "dhcp.m"; # sic
dhcpclient := 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 Dhcpclient
implements 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 Init
must be called before invoking any other operation of the module.
.PP
.B Bootp
reserves the UDP port on
.I net
for use by BOOTP/DHCP clients, and sends a BOOTP request (ie, one without a DHCP operation code).
.I Net
is the name of the network directory (if nil, the default is
.BR /net ).
If
.B bootp
is to configure the interface according to the results received,
.I ctlifc
should be open on the control file of the
.IB net /ipifc
directory for the interface to be configured; otherwise it should be nil.
.B Bootp
repeats 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 conf
refers to a
.B Bootconf
value that contains the values received, and
.I err
is nil.
If
.I ctlifc
is not nil, the interface will also have been configured appropriately.
If a valid reply has not been received, or some other error occurred,
.I conf
is nil, and
.I err
is a diagnostic.
.PP
.B Dhcp
has a similar interface, but runs the full DHCP protocol.
The
.I options
array has integers representing possible DHCP options;
.B dhcp
asks the server to provide values for them.
If
.I options
is 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 from
specific fields of
.BR Bootconf ,
or using its
.I get
operations.
.I Init
is also usually nil, but can refer to a
.B Bootconf
that provides some values to suggest to the server, for instance if the client
knows a previously-assigned address stored in non-volatile memory.
.B Dhcp
returns a tuple
.BI ( conf,\ lease,\ err ),
where
.I conf
and
.I err
are just as for
.BR bootp ,
and the new component
.I lease
is a reference to a
.B Lease
value that gives access to the state of the client's address assignment.
.PP
DHCP allows a server to assign a client an address permanently, or to lease it for a specified time.
In the latter case,
.B Bootconf.lease
will have a non-zero value, and
the client must periodically renew the lease to retain the address, and
.B dhcp
creates a process to do so.
The
.B Lease
value 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 dhcp
first discards any previous notifications not yet received, so there are no ill effects
if 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 conf
refers to a
.B Bootconf
value with the details.
Otherwise,
.I conf
is nil and
.I diag
explains 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.release
may be called to release the leased address and stop the watchdog.
.PP
.B Bootconf
has the following operations:
.TP
.B new()
Return a reference to a
.B Bootconf
with values initialised to nil or 0.
.TP
.IB bc .get( n )
Return the value of DHCP option
.I n
as a raw array of bytes.
Return nil if the option is not set.
.TP
.IB bc .getint( n )
Return the value of option
.I n
interpreted 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 n
as a string.
.TP
.IB bc .put( n,\ a )
Set the value of DHCP option
.I n
to the bytes of byte array
.IR a .
If
.I a
is nil,
.B put
removes any existing value for the option.
.TP
.IB bc .putint( n,\ v)
Set option
.I n
to the integer value
.IR v .
.TP
.IB bc .putips( n,\ ips )
Set option
.I n
to the list of Internet addresses
.IR ips .
.TP
.IB bc .puts( n,\ s )
Set option
.I n
to the string
.IR n .
.PP
.B Dhcpclient
names a few constants representing commonly-used configuration options (attributes).
They are suitable parameters for the option selector
.I n
of
.BR Bootconf 's
.I get
and
.I put
functions.
The first set of constants name options for both BOOTP and DHCP:
.PP
.PD 0
.TP 25
.B Odnsserver
Internet address(es) of Domain Name Servers
.TP
.B Odomainname
Current domain (see
.BR Bootconf.dom )
.TP
.B Ohostname
Host name (see
.BR Bootconf.sys )
.TP
.B Omask
Network mask (IPv4).
Also see
.BR Bootconf.ipmask .
.TP
.B Onetbiosns
NetBIOS servers
.TP
.B Ontpserver
Network Time Protocol servers
.TP
.B Opop3server
POP3 mail servers
.TP
.B Orouter
Default router for subnet (see
.BR Bootconf.ipgw )
.TP
.B Osmtpserver
SMTP mail delivery servers
.TP
.B Ovendorinfo
Vendor-specific data (see below)
.TP
.B Owwwserver
HTTP proxy
.PD
.PP
The second set has DHCP options:
.PP
.PD 0
.TP 25
.B Obootfile
Name of the file containing a kernel for the client to load (eg, by TFTP); see
.BR Bootconf.bootf .
.TP
.B Olease
Lease time for IP address, in seconds (also see
.BR Bootconf.lease )
.TP
.B Omaxmsg
Maximum DHCP size the client is willing to accept (minimum 576 bytes).
.TP
.B Orebindingtime
Time interval in seconds from address assignment to the time address must be rebound.
.TP
.B Orenewaltime
Time interval in seconds from address assignment to first attempt to renew the address.
.TP
.B Otftpserver
TFTP server from which to fetch kernel and parameter files; see
.BR Bootconf.bootip .
.TP
.B Ovendorclass
Identify vendor type and configuration of client. Inferno sets
this to
.B plan9_386
(sic) to encourage Plan 9 DHCP servers to respond; other servers will ignore it.
.PD
.PP
The final set give vendor-specific options that Inferno shares with Plan 9:
.PP
.PD 0
.TP 25
.B Ovendor
Flag OR'd in to an option number to mark it as destined for the `vendor information' section.
.TP
.B OP9auth
Authentication server
.RB ( Ovendor|129 )
.TP
.B OP9fs
File server
.RB ( Ovendor|128 )
.PD
.PP
Given a network configuration in
.IR conf ,
and a valid file descriptor for a network interface's control file,
in the network
.IR net ,
.B applycfg
sets the basic interface parameters (address, network mask, default gateway),
and writes other parameters to
.IR net /ndb ;
conversely,
.B removecfg
removes from the interface just those parameters set by
.IR conf .
Normally these functions are called automatically, as required, by
.B dhcp
and its watchdog process.
.SH SOURCE
.B /appl/lib/dhcpclient.b
.SH SEE ALSO
.IR bootpd (8),
.IR dhcp (8)
|