]> git.ipfire.org Git - thirdparty/dhcp.git/blame - includes/dhcpd.h
size_t -> ssize_t in return values where < 0 == error
[thirdparty/dhcp.git] / includes / dhcpd.h
CommitLineData
d7837182
TL
1/* dhcpd.h
2
3 Definitions for dhcpd... */
4
5/*
f79e49f3 6 * Copyright (c) 1995, 1996, 1997 The Internet Software Consortium.
17b95f41 7 * All rights reserved.
d7837182
TL
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of The Internet Software Consortium nor the names
19 * of its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * This software has been written for the Internet Software Consortium
37 * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
38 * Enterprises. To learn more about the Internet Software Consortium,
39 * see ``http://www.vix.com/isc''. To learn more about Vixie
40 * Enterprises, see ``http://www.vix.com''.
41 */
42
0c7802b1 43#ifndef __CYGWIN32__
d7837182 44#include <sys/types.h>
d7837182
TL
45#include <netinet/in.h>
46#include <sys/socket.h>
47#include <arpa/inet.h>
48#include <netdb.h>
0c7802b1
TL
49#else
50#define fd_set cygwin_fd_set
51#include <sys/types.h>
52#endif
d7837182
TL
53#include <fcntl.h>
54#include <stdio.h>
089fb364 55#include <unistd.h>
8fdfeffe 56#include <string.h>
089fb364
TL
57#include <stdlib.h>
58#include <sys/stat.h>
59#include <ctype.h>
97ca1699 60#include <time.h>
089fb364 61
2f620dce 62#include "cdefs.h"
a8b53b42 63#include "osdep.h"
d7837182 64#include "dhcp.h"
d7837182
TL
65#include "tree.h"
66#include "hash.h"
089fb364 67#include "inet.h"
d7837182 68
cc26de46
TL
69struct option_data {
70 int len;
71 u_int8_t *data;
72};
73
6b3b97e1
TL
74struct string_list {
75 struct string_list *next;
76 char string [1];
77};
78
0c7802b1
TL
79/* A name server, from /etc/resolv.conf. */
80struct name_server {
81 struct name_server *next;
82 struct sockaddr_in addr;
83 TIME rcdate;
84};
85
86/* A domain search list element. */
87struct domain_search_list {
88 struct domain_search_list *next;
89 char *domain;
90 TIME rcdate;
91};
92
d7837182
TL
93/* A dhcp packet and the pointers to its option values. */
94struct packet {
95 struct dhcp_packet *raw;
96 int packet_length;
97 int packet_type;
98 int options_valid;
089fb364
TL
99 int client_port;
100 struct iaddr client_addr;
17b95f41
TL
101 struct interface_info *interface; /* Interface on which packet
102 was received. */
103 struct hardware *haddr; /* Physical link address
104 of local sender (maybe gateway). */
c626ae69 105 struct shared_network *shared_network;
cc26de46 106 struct option_data options [256];
d7837182
TL
107};
108
109struct hardware {
110 u_int8_t htype;
111 u_int8_t hlen;
112 u_int8_t haddr [16];
113};
114
d7837182
TL
115/* A dhcp lease declaration structure. */
116struct lease {
117 struct lease *next;
118 struct lease *prev;
ab370123 119 struct lease *n_uid, *n_hw;
fc2df23a
TL
120 struct lease *waitq_next;
121
089fb364 122 struct iaddr ip_addr;
d7837182
TL
123 TIME starts, ends, timestamp;
124 unsigned char *uid;
125 int uid_len;
fc2df23a
TL
126 int uid_max;
127 unsigned char uid_buf [32];
6aa71eeb 128 char *hostname;
0c7802b1 129 char *client_hostname;
d7837182 130 struct host_decl *host;
c626ae69
TL
131 struct subnet *subnet;
132 struct shared_network *shared_network;
d7837182 133 struct hardware hardware_addr;
fc2df23a 134
c626ae69
TL
135 int flags;
136# define STATIC_LEASE 1
137# define BOOTP_LEASE 2
138# define DYNAMIC_BOOTP_OK 4
139# define PERSISTENT_FLAGS (DYNAMIC_BOOTP_OK)
140# define EPHEMERAL_FLAGS (BOOTP_LEASE)
fc2df23a 141# define MS_NULL_TERMINATION 8
14b45fb6 142# define ABANDONED_LEASE 16
fc2df23a 143
6e5ed8bf
TL
144 struct lease_state *state;
145};
146
147struct lease_state {
148 struct lease_state *next;
149
150 struct interface_info *ip;
151
152 TIME offered_expiry;
153
fc2df23a
TL
154 struct tree_cache *options [256];
155 u_int32_t expiry, renewal, rebind;
156 char *filename, *server_name;
157
158 u_int32_t xid;
159 u_int16_t secs;
160 u_int16_t bootp_flags;
161 struct in_addr ciaddr;
162 struct in_addr giaddr;
163 u_int8_t hops;
164 u_int8_t offer;
c626ae69
TL
165};
166
ab370123 167#define ROOT_GROUP 0
750d0800
TL
168#define HOST_DECL 1
169#define SHARED_NET_DECL 2
170#define SUBNET_DECL 3
171#define CLASS_DECL 4
172#define GROUP_DECL 5
ab370123 173
cc26de46
TL
174/* Possible modes in which discover_interfaces can run. */
175
176#define DISCOVER_RUNNING 0
177#define DISCOVER_SERVER 1
178#define DISCOVER_UNCONFIGURED 2
f79e49f3 179#define DISCOVER_RELAY 3
cc26de46 180
750d0800 181/* Group of declarations that share common parameters. */
ab370123
TL
182struct group {
183 struct group *next;
184
185 struct subnet *subnet;
186 struct shared_network *shared_network;
187
188 TIME default_lease_time;
189 TIME max_lease_time;
190 TIME bootp_lease_cutoff;
191 TIME bootp_lease_length;
192
193 char *filename;
194 char *server_name;
195 struct iaddr next_server;
196
197 int boot_unknown_clients;
198 int dynamic_bootp;
6b3b97e1
TL
199 int allow_bootp;
200 int allow_booting;
6aa71eeb 201 int one_lease_per_client;
5fea7b10 202 int get_lease_hostnames;
c256bae9 203 int use_host_decl_names;
ab370123
TL
204
205 struct tree_cache *options [256];
206};
207
208/* A dhcp host declaration structure. */
209struct host_decl {
210 struct host_decl *n_ipaddr;
211 char *name;
212 struct hardware interface;
213 struct tree_cache *fixed_addr;
214 struct group *group;
215};
216
c626ae69
TL
217struct shared_network {
218 struct shared_network *next;
ab370123 219 char *name;
c626ae69
TL
220 struct subnet *subnets;
221 struct interface_info *interface;
222 struct lease *leases;
223 struct lease *insertion_point;
224 struct lease *last_lease;
ab370123
TL
225
226 struct group *group;
d7837182
TL
227};
228
229struct subnet {
c626ae69
TL
230 struct subnet *next_subnet;
231 struct subnet *next_sibling;
232 struct shared_network *shared_network;
233 struct interface_info *interface;
234 struct iaddr interface_address;
089fb364
TL
235 struct iaddr net;
236 struct iaddr netmask;
ab370123
TL
237
238 struct group *group;
d7837182
TL
239};
240
709f15cc
TL
241struct class {
242 char *name;
ab370123
TL
243
244 struct group *group;
709f15cc
TL
245};
246
cc26de46
TL
247/* DHCP client lease structure... */
248struct client_lease {
41fb155b
TL
249 struct client_lease *next; /* Next lease in list. */
250 TIME expiry, renewal, rebind; /* Lease timeouts. */
251 struct iaddr address; /* Address being leased. */
252 char *server_name; /* Name of boot server. */
253 char *filename; /* Name of file we're supposed to boot. */
6b3b97e1 254 struct string_list *medium; /* Network medium. */
cc26de46 255
0c7802b1
TL
256 unsigned int is_static : 1; /* If set, lease is from config file. */
257 unsigned int is_bootp: 1; /* If set, lease was aquired with BOOTP. */
41fb155b
TL
258
259 struct option_data options [256]; /* Options supplied with lease. */
cc26de46
TL
260};
261
41fb155b 262/* Possible states in which the client can be. */
cc26de46 263enum dhcp_state {
fc2df23a 264 S_REBOOTING,
cc26de46
TL
265 S_INIT,
266 S_SELECTING,
267 S_REQUESTING,
268 S_BOUND,
269 S_RENEWING,
270 S_REBINDING
271};
272
273/* Configuration information from the config file... */
274struct client_config {
6b3b97e1 275 struct option_data defaults [256]; /* Default values for options. */
0c7802b1
TL
276 enum {
277 ACTION_DEFAULT, /* Use server value if present,
278 otherwise default. */
279 ACTION_SUPERSEDE, /* Always use default. */
280 ACTION_PREPEND, /* Prepend default to server. */
281 ACTION_APPEND, /* Append default to server. */
282 } default_actions [256];
283
6b3b97e1 284 struct option_data send_options [256]; /* Send these to server. */
cc26de46
TL
285 u_int8_t required_options [256]; /* Options server must supply. */
286 u_int8_t requested_options [256]; /* Options to request from server. */
287 int requested_option_count; /* Number of requested options. */
cc26de46
TL
288 TIME timeout; /* Start to panic if we don't get a
289 lease in this time period when
290 SELECTING. */
83c1b012
TL
291 TIME initial_interval; /* All exponential backoff intervals
292 start here. */
cc26de46
TL
293 TIME retry_interval; /* If the protocol failed to produce
294 an address before the timeout,
295 try the protocol again after this
296 many seconds. */
297 TIME select_interval; /* Wait this many seconds from the
298 first DHCPDISCOVER before
299 picking an offered lease. */
fc2df23a
TL
300 TIME reboot_timeout; /* When in INIT-REBOOT, wait this
301 long before giving up and going
302 to INIT. */
83c1b012
TL
303 TIME backoff_cutoff; /* When doing exponential backoff,
304 never back off to an interval
305 longer than this amount. */
6b3b97e1 306 struct string_list *media; /* Possible network media values. */
cc26de46
TL
307 char *script_name; /* Name of config script. */
308 enum { IGNORE, ACCEPT, PREFER } bootp_policy;
309 /* Ignore, accept or prefer BOOTP
310 responses. */
6b3b97e1 311 struct string_list *medium; /* Current network medium. */
0c7802b1
TL
312
313 struct iaddrlist *reject_list; /* Servers to reject. */
cc26de46
TL
314};
315
316/* Per-interface state used in the dhcp client... */
317struct client_state {
318 struct client_lease *active; /* Currently active lease. */
319 struct client_lease *new; /* New lease. */
320 struct client_lease *offered_leases; /* Leases offered to us. */
321 struct client_lease *leases; /* Leases we currently hold. */
f79e49f3 322 struct client_lease *alias; /* Alias lease. */
cc26de46
TL
323
324 enum dhcp_state state; /* Current state for this interface. */
325 struct iaddr destination; /* Where to send packet. */
326 u_int32_t xid; /* Transaction ID. */
327 TIME first_sending; /* When was first copy sent? */
6b3b97e1
TL
328 TIME interval; /* What's the current resend interval? */
329 struct string_list *medium; /* Last media type tried. */
cc26de46
TL
330
331 struct dhcp_packet packet; /* Outgoing DHCP packet. */
332 int packet_length; /* Actual length of generated packet. */
333
41fb155b
TL
334 struct iaddr requested_address; /* Address we would like to get. */
335
cc26de46
TL
336 struct client_config *config; /* Information from config file. */
337};
338
17b95f41
TL
339/* Information about each network interface. */
340
341struct interface_info {
342 struct interface_info *next; /* Next interface in list... */
c626ae69
TL
343 struct shared_network *shared_network;
344 /* Networks connected to this interface. */
17b95f41 345 struct hardware hw_address; /* Its physical address. */
6b3b97e1 346 struct in_addr primary_address; /* Primary interface address. */
17b95f41
TL
347 char name [IFNAMSIZ]; /* Its name... */
348 int rfdesc; /* Its read file descriptor. */
349 int wfdesc; /* Its write file descriptor, if
350 different. */
351 unsigned char *rbuf; /* Read buffer, if required. */
352 size_t rbuf_max; /* Size of read buffer. */
353 size_t rbuf_offset; /* Current offset into buffer. */
354 size_t rbuf_len; /* Length of data in buffer. */
c626ae69 355
41fb155b 356 struct ifreq *ifp; /* Pointer to ifreq struct. */
7f91dcfb
TL
357 u_int32_t flags; /* Control flags... */
358#define INTERFACE_REQUESTED 1
cc26de46
TL
359
360 /* Only used by DHCP client code. */
361 struct client_state *client;
17b95f41
TL
362};
363
364struct hardware_link {
365 struct hardware_link *next;
366 char name [IFNAMSIZ];
367 struct hardware address;
368};
369
cc26de46
TL
370struct timeout {
371 struct timeout *next;
372 TIME when;
6e5ed8bf
TL
373 void (*func) PROTO ((void *));
374 void *what;
375};
376
377struct protocol {
378 struct protocol *next;
379 int fd;
380 void (*handler) PROTO ((struct protocol *));
381 void *local;
cc26de46
TL
382};
383
d7837182
TL
384/* Bitmask of dhcp option codes. */
385typedef unsigned char option_mask [16];
386
387/* DHCP Option mask manipulation macros... */
388#define OPTION_ZERO(mask) (memset (mask, 0, 16))
389#define OPTION_SET(mask, bit) (mask [bit >> 8] |= (1 << (bit & 7)))
390#define OPTION_CLR(mask, bit) (mask [bit >> 8] &= ~(1 << (bit & 7)))
391#define OPTION_ISSET(mask, bit) (mask [bit >> 8] & (1 << (bit & 7)))
392#define OPTION_ISCLR(mask, bit) (!OPTION_ISSET (mask, bit))
393
394/* An option occupies its length plus two header bytes (code and
395 length) for every 255 bytes that must be stored. */
396#define OPTION_SPACE(x) ((x) + 2 * ((x) / 255 + 1))
397
398/* Default path to dhcpd config file. */
d7837182 399#ifdef DEBUG
80ba033e 400#undef _PATH_DHCPD_CONF
d7837182 401#define _PATH_DHCPD_CONF "dhcpd.conf"
80ba033e 402#undef _PATH_DHCPD_DB
1358b874 403#define _PATH_DHCPD_DB "dhcpd.leases"
d7837182 404#else
a8b53b42 405#ifndef _PATH_DHCPD_CONF
d7837182 406#define _PATH_DHCPD_CONF "/etc/dhcpd.conf"
a8b53b42
TL
407#endif
408
409#ifndef _PATH_DHCPD_DB
6e47d3d8 410#define _PATH_DHCPD_DB "/etc/dhcpd.leases"
d7837182 411#endif
a8b53b42
TL
412
413#ifndef _PATH_DHCPD_PID
414#define _PATH_DHCPD_PID "/var/run/dhcpd.pid"
415#endif
d7837182
TL
416#endif
417
cc26de46
TL
418#ifndef _PATH_DHCLIENT_CONF
419#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf"
420#endif
421
422#ifndef _PATH_DHCLIENT_PID
423#define _PATH_DHCLIENT_PID "/var/run/dhclient.pid"
424#endif
425
426#ifndef _PATH_DHCLIENT_DB
427#define _PATH_DHCLIENT_DB "/etc/dhclient.leases"
428#endif
429
0c7802b1
TL
430#ifndef _PATH_RESOLV_CONF
431#define _PATH_RESOLV_CONF "/etc/resolv.conf"
432#endif
cc26de46 433
ab370123
TL
434#ifndef DHCPD_LOG_FACILITY
435#define DHCPD_LOG_FACILITY LOG_DAEMON
436#endif
437
d7837182
TL
438#define MAX_TIME 0x7fffffff
439#define MIN_TIME 0
440
441/* External definitions... */
442
443/* options.c */
444
445void parse_options PROTO ((struct packet *));
446void parse_option_buffer PROTO ((struct packet *, unsigned char *, int));
cc26de46 447int cons_options PROTO ((struct packet *, struct dhcp_packet *,
07b39db2 448 struct tree_cache **, int, int));
709f15cc 449int store_options PROTO ((unsigned char *, int, struct tree_cache **,
07b39db2 450 unsigned char *, int, int, int, int));
0c7802b1
TL
451char *pretty_print_option PROTO ((unsigned int,
452 unsigned char *, int, int, int));
6e5ed8bf
TL
453void do_packet PROTO ((struct interface_info *,
454 unsigned char *, int,
455 unsigned short, struct iaddr, struct hardware *));
d7837182
TL
456
457/* errwarn.c */
88ddda34 458extern int warnings_occurred;
8fdfeffe 459void error PROTO ((char *, ...));
d7837182
TL
460int warn PROTO ((char *, ...));
461int note PROTO ((char *, ...));
462int debug PROTO ((char *, ...));
463int parse_warn PROTO ((char *, ...));
464
465/* dhcpd.c */
8fdfeffe 466extern TIME cur_time;
35d1d5cd 467extern struct group root_group;
c626ae69 468
cc26de46
TL
469extern u_int16_t local_port;
470extern u_int16_t remote_port;
40950384 471extern int log_priority;
6aa71eeb 472extern int log_perror;
685963dc 473
c626ae69
TL
474#ifdef USE_FALLBACK
475extern struct interface_info fallback_interface;
476#endif
477
e2ac5814
TL
478extern char *path_dhcpd_conf;
479extern char *path_dhcpd_db;
480extern char *path_dhcpd_pid;
481
d7837182
TL
482int main PROTO ((int, char **, char **));
483void cleanup PROTO ((void));
e5078937
TL
484void lease_pinged PROTO ((struct iaddr, u_int8_t *, int));
485void lease_ping_timeout PROTO ((void *));
d7837182
TL
486
487/* conflex.c */
ab370123 488extern int lexline, lexchar;
6aa71eeb
TL
489extern char *token_line, *tlname;
490extern char comments [4096];
491extern int comment_index;
0c7802b1 492extern int eol_token;
ab370123 493void new_parse PROTO ((char *));
d7837182
TL
494int next_token PROTO ((char **, FILE *));
495int peek_token PROTO ((char **, FILE *));
496
497/* confpars.c */
88ddda34 498int readconf PROTO ((void));
1358b874 499void read_leases PROTO ((void));
ab370123 500int parse_statement PROTO ((FILE *,
750d0800 501 struct group *, int, struct host_decl *, int));
6b3b97e1 502void parse_allow_deny PROTO ((FILE *, struct group *, int));
d7837182 503void skip_to_semi PROTO ((FILE *));
6aa71eeb
TL
504int parse_boolean PROTO ((FILE *));
505int parse_semi PROTO ((FILE *));
ab370123 506int parse_lbrace PROTO ((FILE *));
750d0800 507void parse_host_declaration PROTO ((FILE *, struct group *));
ab370123 508char *parse_host_name PROTO ((FILE *));
750d0800 509void parse_class_declaration PROTO ((FILE *, struct group *, int));
ab370123 510void parse_lease_time PROTO ((FILE *, TIME *));
750d0800
TL
511void parse_shared_net_declaration PROTO ((FILE *, struct group *));
512void parse_subnet_declaration PROTO ((FILE *, struct shared_network *));
513void parse_group_declaration PROTO ((FILE *, struct group *));
514void parse_hardware_param PROTO ((FILE *, struct hardware *));
6aa71eeb 515char *parse_string PROTO ((FILE *));
ab370123 516struct tree *parse_ip_addr_or_hostname PROTO ((FILE *, int));
750d0800
TL
517struct tree_cache *parse_fixed_addr_param PROTO ((FILE *));
518void parse_option_param PROTO ((FILE *, struct group *));
ab370123 519TIME parse_timestamp PROTO ((FILE *));
750d0800 520struct lease *parse_lease_declaration PROTO ((FILE *));
ab370123
TL
521void parse_address_range PROTO ((FILE *, struct subnet *));
522TIME parse_date PROTO ((FILE *));
523unsigned char *parse_numeric_aggregate PROTO ((FILE *,
d7837182
TL
524 unsigned char *, int *,
525 int, int, int));
526void convert_num PROTO ((unsigned char *, char *, int, int));
527
528/* tree.c */
529pair cons PROTO ((caddr_t, pair));
530struct tree_cache *tree_cache PROTO ((struct tree *));
531struct tree *tree_host_lookup PROTO ((char *));
532struct dns_host_entry *enter_dns_host PROTO ((char *));
533struct tree *tree_const PROTO ((unsigned char *, int));
534struct tree *tree_concat PROTO ((struct tree *, struct tree *));
535struct tree *tree_limit PROTO ((struct tree *, int));
536int tree_evaluate PROTO ((struct tree_cache *));
537
538/* dhcp.c */
e5078937
TL
539extern int outstanding_pings;
540
d7837182 541void dhcp PROTO ((struct packet *));
8f5e2ec8
TL
542void dhcpdiscover PROTO ((struct packet *));
543void dhcprequest PROTO ((struct packet *));
544void dhcprelease PROTO ((struct packet *));
709f15cc
TL
545void dhcpdecline PROTO ((struct packet *));
546void dhcpinform PROTO ((struct packet *));
a8b53b42 547void nak_lease PROTO ((struct packet *, struct iaddr *cip));
8f5e2ec8 548void ack_lease PROTO ((struct packet *, struct lease *, unsigned char, TIME));
fc2df23a 549void dhcp_reply PROTO ((struct lease *));
03807c84
TL
550struct lease *find_lease PROTO ((struct packet *, struct shared_network *));
551struct lease *mockup_lease PROTO ((struct packet *,
552 struct shared_network *,
553 struct host_decl *));
d7837182
TL
554
555/* bootp.c */
556void bootp PROTO ((struct packet *));
557
558/* memory.c */
559void enter_host PROTO ((struct host_decl *));
c626ae69
TL
560struct host_decl *find_hosts_by_haddr PROTO ((int, unsigned char *, int));
561struct host_decl *find_hosts_by_uid PROTO ((unsigned char *, int));
562struct subnet *find_host_for_network PROTO ((struct host_decl **,
563 struct iaddr *,
564 struct shared_network *));
089fb364 565void new_address_range PROTO ((struct iaddr, struct iaddr,
c626ae69
TL
566 struct subnet *, int));
567extern struct subnet *find_grouped_subnet PROTO ((struct shared_network *,
568 struct iaddr));
2f620dce 569extern struct subnet *find_subnet PROTO ((struct iaddr));
c626ae69 570void enter_shared_network PROTO ((struct shared_network *));
2f620dce 571void enter_subnet PROTO ((struct subnet *));
d7837182 572void enter_lease PROTO ((struct lease *));
1358b874 573int supersede_lease PROTO ((struct lease *, struct lease *, int));
97ca1699 574void release_lease PROTO ((struct lease *));
e5078937 575void abandon_lease PROTO ((struct lease *, char *));
d7837182 576struct lease *find_lease_by_uid PROTO ((unsigned char *, int));
97ca1699 577struct lease *find_lease_by_hw_addr PROTO ((unsigned char *, int));
089fb364 578struct lease *find_lease_by_ip_addr PROTO ((struct iaddr));
ab370123
TL
579void uid_hash_add PROTO ((struct lease *));
580void uid_hash_delete PROTO ((struct lease *));
581void hw_hash_add PROTO ((struct lease *));
582void hw_hash_delete PROTO ((struct lease *));
709f15cc
TL
583struct class *add_class PROTO ((int, char *));
584struct class *find_class PROTO ((int, char *, int));
ab370123 585struct group *clone_group PROTO ((struct group *, char *));
1358b874 586void write_leases PROTO ((void));
97ca1699 587void dump_subnets PROTO ((void));
d7837182
TL
588
589/* alloc.c */
590VOIDPTR dmalloc PROTO ((int, char *));
591void dfree PROTO ((VOIDPTR, char *));
592struct packet *new_packet PROTO ((char *));
593struct dhcp_packet *new_dhcp_packet PROTO ((char *));
594struct tree *new_tree PROTO ((char *));
595struct tree_cache *new_tree_cache PROTO ((char *));
596struct hash_table *new_hash_table PROTO ((int, char *));
597struct hash_bucket *new_hash_bucket PROTO ((char *));
598struct lease *new_lease PROTO ((char *));
2f620dce 599struct lease *new_leases PROTO ((int, char *));
d7837182 600struct subnet *new_subnet PROTO ((char *));
709f15cc 601struct class *new_class PROTO ((char *));
c626ae69 602struct shared_network *new_shared_network PROTO ((char *));
ab370123 603struct group *new_group PROTO ((char *));
6e5ed8bf
TL
604struct protocol *new_protocol PROTO ((char *));
605struct lease_state *new_lease_state PROTO ((char *));
0c7802b1
TL
606struct domain_search_list *new_domain_search_list PROTO ((char *));
607struct name_server *new_name_server PROTO ((char *));
608void free_name_server PROTO ((struct name_server *, char *));
609void free_domain_search_list PROTO ((struct domain_search_list *, char *));
6e5ed8bf
TL
610void free_lease_state PROTO ((struct lease_state *, char *));
611void free_protocol PROTO ((struct protocol *, char *));
ab370123 612void free_group PROTO ((struct group *, char *));
c626ae69 613void free_shared_network PROTO ((struct shared_network *, char *));
709f15cc 614void free_class PROTO ((struct class *, char *));
d7837182
TL
615void free_subnet PROTO ((struct subnet *, char *));
616void free_lease PROTO ((struct lease *, char *));
617void free_hash_bucket PROTO ((struct hash_bucket *, char *));
618void free_hash_table PROTO ((struct hash_table *, char *));
619void free_tree_cache PROTO ((struct tree_cache *, char *));
620void free_packet PROTO ((struct packet *, char *));
621void free_dhcp_packet PROTO ((struct dhcp_packet *, char *));
622void free_tree PROTO ((struct tree *, char *));
623
624/* print.c */
625char *print_hw_addr PROTO ((int, int, unsigned char *));
97ca1699 626void print_lease PROTO ((struct lease *));
709f15cc 627void dump_raw PROTO ((unsigned char *, int));
17b95f41 628void dump_packet PROTO ((struct packet *));
c626ae69 629void hash_dump PROTO ((struct hash_table *));
d7837182
TL
630
631/* socket.c */
c626ae69
TL
632#if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \
633 || defined (USE_SOCKET_FALLBACK)
41fb155b 634int if_register_socket PROTO ((struct interface_info *));
17b95f41
TL
635#endif
636
c626ae69 637#ifdef USE_SOCKET_FALLBACK
41fb155b
TL
638void if_reinitialize_fallback PROTO ((struct interface_info *));
639void if_register_fallback PROTO ((struct interface_info *));
4595a58c
TL
640ssize_t send_fallback PROTO ((struct interface_info *,
641 struct packet *, struct dhcp_packet *, size_t,
642 struct in_addr,
643 struct sockaddr_in *, struct hardware *));
6e5ed8bf 644void fallback_discard PROTO ((struct protocol *));
c626ae69
TL
645#endif
646
6f10b1a4 647#ifdef USE_SOCKET_SEND
41fb155b
TL
648void if_reinitialize_send PROTO ((struct interface_info *));
649void if_register_send PROTO ((struct interface_info *));
4595a58c
TL
650ssize_t send_packet PROTO ((struct interface_info *,
651 struct packet *, struct dhcp_packet *, size_t,
652 struct in_addr,
653 struct sockaddr_in *, struct hardware *));
6f10b1a4
TL
654#endif
655#ifdef USE_SOCKET_RECEIVE
41fb155b
TL
656void if_reinitialize_receive PROTO ((struct interface_info *));
657void if_register_receive PROTO ((struct interface_info *));
4595a58c
TL
658ssize_t receive_packet PROTO ((struct interface_info *,
659 unsigned char *, size_t,
660 struct sockaddr_in *, struct hardware *));
6f10b1a4 661#endif
469cf3a4
TL
662#if defined (USE_SOCKET_SEND) && !defined (USE_SOCKET_FALLBACK)
663void if_enable PROTO ((struct interface_info *));
664#endif
6f10b1a4
TL
665
666/* bpf.c */
17b95f41 667#if defined (USE_BPF_SEND) || defined (USE_BPF_RECEIVE)
41fb155b 668int if_register_bpf PROTO ( (struct interface_info *));
17b95f41 669#endif
6f10b1a4 670#ifdef USE_BPF_SEND
41fb155b
TL
671void if_reinitialize_send PROTO ((struct interface_info *));
672void if_register_send PROTO ((struct interface_info *));
4595a58c
TL
673ssize_t send_packet PROTO ((struct interface_info *,
674 struct packet *, struct dhcp_packet *, size_t,
675 struct in_addr,
676 struct sockaddr_in *, struct hardware *));
6f10b1a4
TL
677#endif
678#ifdef USE_BPF_RECEIVE
41fb155b
TL
679void if_reinitialize_receive PROTO ((struct interface_info *));
680void if_register_receive PROTO ((struct interface_info *));
4595a58c
TL
681ssize_t receive_packet PROTO ((struct interface_info *,
682 unsigned char *, size_t,
683 struct sockaddr_in *, struct hardware *));
6f10b1a4 684#endif
469cf3a4
TL
685#if defined (USE_BPF_SEND)
686void if_enable PROTO ((struct interface_info *));
687#endif
6f10b1a4
TL
688
689/* nit.c */
41fb155b
TL
690#if defined (USE_NIT_SEND) || defined (USE_NIT_RECEIVE)
691int if_register_nit PROTO ( (struct interface_info *));
692#endif
693
6f10b1a4 694#ifdef USE_NIT_SEND
41fb155b
TL
695void if_reinitialize_send PROTO ((struct interface_info *));
696void if_register_send PROTO ((struct interface_info *));
4595a58c
TL
697ssize_t send_packet PROTO ((struct interface_info *,
698 struct packet *, struct dhcp_packet *, size_t,
699 struct in_addr,
700 struct sockaddr_in *, struct hardware *));
6f10b1a4
TL
701#endif
702#ifdef USE_NIT_RECEIVE
41fb155b
TL
703void if_reinitialize_receive PROTO ((struct interface_info *));
704void if_register_receive PROTO ((struct interface_info *));
4595a58c
TL
705ssize_t receive_packet PROTO ((struct interface_info *,
706 unsigned char *, size_t,
707 struct sockaddr_in *, struct hardware *));
6f10b1a4 708#endif
469cf3a4
TL
709#if defined (USE_BPF_SEND)
710void if_enable PROTO ((struct interface_info *));
711#endif
6f10b1a4
TL
712
713/* raw.c */
714#ifdef USE_RAW_SEND
41fb155b
TL
715void if_reinitialize_send PROTO ((struct interface_info *));
716void if_register_send PROTO ((struct interface_info *));
4595a58c
TL
717ssize_t send_packet PROTO ((struct interface_info *,
718 struct packet *, struct dhcp_packet *, size_t,
719 struct in_addr,
720 struct sockaddr_in *, struct hardware *));
6f10b1a4
TL
721#endif
722
723/* dispatch.c */
41fb155b 724extern struct interface_info *interfaces, *dummy_interfaces;
6e5ed8bf
TL
725extern struct protocol *protocols;
726extern void (*bootp_packet_handler) PROTO ((struct interface_info *,
727 unsigned char *, int, unsigned short,
728 struct iaddr, struct hardware *));
cc26de46 729extern struct timeout *timeouts;
8fec2c95 730void discover_interfaces PROTO ((int));
41fb155b 731void reinitialize_interfaces PROTO ((void));
6e5ed8bf 732void dispatch PROTO ((void));
abe9a343 733int locate_network PROTO ((struct packet *));
6e5ed8bf
TL
734void add_timeout PROTO ((TIME, void (*) PROTO ((void *)), void *));
735#if 0
736void add_fast_timeout PROTO ((UTIME, void (*) PROTO ((void *)), void *));
737#endif
738void cancel_timeout PROTO ((void (*) PROTO ((void *)), void *));
739void add_protocol PROTO ((char *, int,
740 void (*) PROTO ((struct protocol *)), void *));
d7837182
TL
741
742/* hash.c */
743struct hash_table *new_hash PROTO ((void));
744void add_hash PROTO ((struct hash_table *, char *, int, unsigned char *));
745void delete_hash_entry PROTO ((struct hash_table *, char *, int));
746unsigned char *hash_lookup PROTO ((struct hash_table *, char *, int));
747
748/* tables.c */
749extern struct option dhcp_options [256];
750extern unsigned char dhcp_option_default_priority_list [];
751extern int sizeof_dhcp_option_default_priority_list;
1358b874 752extern char *hardware_types [256];
d7837182
TL
753extern struct hash_table universe_hash;
754extern struct universe dhcp_universe;
755void initialize_universes PROTO ((void));
756
089fb364 757/* convert.c */
597e1211
TL
758u_int32_t getULong PROTO ((unsigned char *));
759int32_t getLong PROTO ((unsigned char *));
760u_int16_t getUShort PROTO ((unsigned char *));
761int16_t getShort PROTO ((unsigned char *));
762void putULong PROTO ((unsigned char *, u_int32_t));
763void putLong PROTO ((unsigned char *, int32_t));
764void putUShort PROTO ((unsigned char *, u_int16_t));
765void putShort PROTO ((unsigned char *, int16_t));
089fb364
TL
766
767/* inet.c */
1358b874 768struct iaddr subnet_number PROTO ((struct iaddr, struct iaddr));
73fd5718
TL
769struct iaddr ip_addr PROTO ((struct iaddr, struct iaddr, u_int32_t));
770u_int32_t host_addr PROTO ((struct iaddr, struct iaddr));
1358b874
TL
771int addr_eq PROTO ((struct iaddr, struct iaddr));
772char *piaddr PROTO ((struct iaddr));
95821729
TL
773
774/* dhclient.c */
cc26de46
TL
775extern char *path_dhclient_conf;
776extern char *path_dhclient_db;
777extern char *path_dhclient_pid;
778
779extern struct client_config top_level_config;
780
abe9a343
TL
781void dhcpoffer PROTO ((struct packet *));
782void dhcpack PROTO ((struct packet *));
783void dhcpnak PROTO ((struct packet *));
cc26de46 784
6e5ed8bf
TL
785void send_discover PROTO ((void *));
786void send_request PROTO ((void *));
787void send_release PROTO ((void *));
788void send_decline PROTO ((void *));
cc26de46 789
6e5ed8bf
TL
790void state_reboot PROTO ((void *));
791void state_init PROTO ((void *));
792void state_selecting PROTO ((void *));
793void state_requesting PROTO ((void *));
794void state_bound PROTO ((void *));
795void state_panic PROTO ((void *));
cc26de46 796
0c7802b1
TL
797void bind_lease PROTO ((struct interface_info *));
798
cc26de46
TL
799void make_discover PROTO ((struct interface_info *, struct client_lease *));
800void make_request PROTO ((struct interface_info *, struct client_lease *));
801void make_decline PROTO ((struct interface_info *, struct client_lease *));
802void make_release PROTO ((struct interface_info *, struct client_lease *));
803
804void free_client_lease PROTO ((struct client_lease *));
805void rewrite_client_leases PROTO ((void));
806void write_client_lease PROTO ((struct interface_info *,
807 struct client_lease *));
808char *dhcp_option_ev_name PROTO ((struct option *));
809
6b3b97e1
TL
810void script_init PROTO ((struct interface_info *, char *,
811 struct string_list *));
cc26de46
TL
812void script_write_params PROTO ((struct interface_info *,
813 char *, struct client_lease *));
814int script_go PROTO ((struct interface_info *));
815
816struct client_lease *packet_to_lease PROTO ((struct packet *));
41fb155b 817void go_daemon PROTO ((void));
95821729 818
1358b874
TL
819/* db.c */
820int write_lease PROTO ((struct lease *));
821int commit_leases PROTO ((void));
822void db_startup PROTO ((void));
823void new_lease_file PROTO ((void));
17b95f41
TL
824
825/* packet.c */
e5078937
TL
826u_int32_t checksum PROTO ((unsigned char *, int, u_int32_t));
827u_int32_t wrapsum PROTO ((u_int32_t));
17b95f41
TL
828void assemble_hw_header PROTO ((struct interface_info *, unsigned char *,
829 int *, struct hardware *));
830void assemble_udp_ip_header PROTO ((struct interface_info *, unsigned char *,
c626ae69 831 int *, u_int32_t, u_int32_t, u_int16_t,
17b95f41 832 unsigned char *, int));
4595a58c
TL
833ssize_t decode_hw_header PROTO ((struct interface_info *, unsigned char *,
834 int, struct hardware *));
835ssize_t decode_udp_ip_header PROTO ((struct interface_info *, unsigned char *,
836 int, struct sockaddr_in *,
837 unsigned char *, int));
ab370123
TL
838
839/* dhxpxlt.c */
840void convert_statement PROTO ((FILE *));
841void convert_host_statement PROTO ((FILE *, jrefproto));
842void convert_host_name PROTO ((FILE *, jrefproto));
843void convert_class_statement PROTO ((FILE *, jrefproto, int));
844void convert_class_decl PROTO ((FILE *, jrefproto));
845void convert_lease_time PROTO ((FILE *, jrefproto, char *));
846void convert_shared_net_statement PROTO ((FILE *, jrefproto));
847void convert_subnet_statement PROTO ((FILE *, jrefproto));
848void convert_subnet_decl PROTO ((FILE *, jrefproto));
849void convert_host_decl PROTO ((FILE *, jrefproto));
850void convert_hardware_decl PROTO ((FILE *, jrefproto));
851void convert_hardware_addr PROTO ((FILE *, jrefproto));
852void convert_filename_decl PROTO ((FILE *, jrefproto));
853void convert_servername_decl PROTO ((FILE *, jrefproto));
854void convert_ip_addr_or_hostname PROTO ((FILE *, jrefproto, int));
855void convert_fixed_addr_decl PROTO ((FILE *, jrefproto));
856void convert_option_decl PROTO ((FILE *, jrefproto));
857void convert_timestamp PROTO ((FILE *, jrefproto));
858void convert_lease_statement PROTO ((FILE *, jrefproto));
859void convert_address_range PROTO ((FILE *, jrefproto));
860void convert_date PROTO ((FILE *, jrefproto, char *));
861void convert_numeric_aggregate PROTO ((FILE *, jrefproto, int, int, int, int));
862void indent PROTO ((int));
469cf3a4
TL
863
864/* route.c */
865void add_route_direct PROTO ((struct interface_info *, struct in_addr));
866void add_route_net PROTO ((struct interface_info *, struct in_addr,
867 struct in_addr));
868void add_route_default_gateway PROTO ((struct interface_info *,
869 struct in_addr));
870void remove_routes PROTO ((struct in_addr));
871void remove_if_route PROTO ((struct interface_info *, struct in_addr));
872void remove_all_if_routes PROTO ((struct interface_info *));
873void set_netmask PROTO ((struct interface_info *, struct in_addr));
874void set_broadcast_addr PROTO ((struct interface_info *, struct in_addr));
875void set_ip_address PROTO ((struct interface_info *, struct in_addr));
cc26de46
TL
876
877/* clparse.c */
878int read_client_conf PROTO ((void));
879void read_client_leases PROTO ((void));
880void parse_client_statement PROTO ((FILE *, struct interface_info *,
881 struct client_config *));
41fb155b 882int parse_X PROTO ((FILE *, u_int8_t *, int));
cc26de46
TL
883int parse_option_list PROTO ((FILE *, u_int8_t *));
884void parse_interface_declaration PROTO ((FILE *, struct client_config *));
41fb155b
TL
885struct interface_info *interface_or_dummy PROTO ((char *));
886void make_client_state PROTO ((struct interface_info *));
887void make_client_config PROTO ((struct interface_info *,
888 struct client_config *));
889void parse_client_lease_statement PROTO ((FILE *, int));
cc26de46
TL
890void parse_client_lease_declaration PROTO ((FILE *, struct client_lease *,
891 struct interface_info **));
0c7802b1 892struct option *parse_option_decl PROTO ((FILE *, struct option_data *));
6b3b97e1 893void parse_string_list PROTO ((FILE *, struct string_list **, int));
0c7802b1
TL
894int parse_ip_addr PROTO ((FILE *, struct iaddr *));
895void parse_reject_statement PROTO ((FILE *, struct client_config *));
6b3b97e1
TL
896
897/* dhcrelay.c */
6e5ed8bf
TL
898void relay PROTO ((struct interface_info *, u_int8_t *, int,
899 unsigned short, struct iaddr, struct hardware *));
900
901/* icmp.c */
902void icmp_startup PROTO ((int, void (*) PROTO ((struct iaddr,
fa25cc03 903 u_int8_t *, int))));
6e5ed8bf
TL
904int icmp_echorequest PROTO ((struct iaddr *));
905void icmp_echoreply PROTO ((struct protocol *));
83c1b012
TL
906
907/* dns.c */
908void dns_startup PROTO ((void));
0c7802b1
TL
909int ns_inaddr_lookup PROTO ((u_int16_t, struct iaddr));
910void dns_packet PROTO ((struct protocol *));
911
912/* resolv.c */
913extern char path_resolv_conf [];
914struct name_server *name_servers;
915struct domain_search_list *domains;
916
917void read_resolv_conf PROTO ((TIME));
918struct sockaddr_in *pick_name_server PROTO ((void));
2b60cc68
TL
919
920/* inet_addr.c */
921#ifdef NEED_INET_ATON
922int inet_aton PROTO ((char *, struct in_addr *));
923#endif