dhclient - Remove unused function.
[dragonfly.git] / sbin / dhclient / dhcpd.h
CommitLineData
fdc8bcd5 1/* $OpenBSD: src/sbin/dhclient/dhcpd.h,v 1.71 2010/07/02 22:03:27 deraadt Exp $ */
846204b6
HT
2
3/*
4 * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
5 * Copyright (c) 1995, 1996, 1997, 1998, 1999
6 * The Internet Software Consortium. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of The Internet Software Consortium nor the names
18 * of its contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
22 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
29 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * This software has been written for the Internet Software Consortium
36 * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
37 * Enterprises. To learn more about the Internet Software Consortium,
38 * see ``http://www.vix.com/isc''. To learn more about Vixie
39 * Enterprises, see ``http://www.vix.com''.
40 */
41
42#include <sys/socket.h>
43#include <sys/sockio.h>
44#include <sys/stat.h>
45#include <sys/time.h>
46#include <sys/types.h>
47#include <sys/wait.h>
48
49#include <arpa/inet.h>
50#include <net/if.h>
51#include <net/if_dl.h>
52#include <net/route.h>
53#include <netinet/in.h>
bdf60627 54#include <netinet/if_ether.h>
846204b6
HT
55
56#include <ctype.h>
57#include <errno.h>
58#include <fcntl.h>
59#include <limits.h>
60#include <netdb.h>
61#include <paths.h>
62#include <stdarg.h>
63#include <stdio.h>
64#include <stdlib.h>
65#include <string.h>
66#include <syslog.h>
67#include <time.h>
68#include <unistd.h>
69
70#include "dhcp.h"
71
72#define LOCAL_PORT 68
73#define REMOTE_PORT 67
74
75struct option {
76 char *name;
77 char *format;
78};
79
80struct option_data {
81 unsigned int len;
82 u_int8_t *data;
83};
84
85struct string_list {
86 struct string_list *next;
87 char string[1]; /* Actually bigger. */
88};
89
90struct iaddr {
91 int len;
92 unsigned char iabuf[16];
93};
94
95struct iaddrlist {
96 struct iaddrlist *next;
97 struct iaddr addr;
98};
99
100struct hardware {
101 u_int8_t htype;
102 u_int8_t hlen;
103 u_int8_t haddr[16];
104};
105
106struct client_lease {
107 struct client_lease *next;
108 time_t expiry, renewal, rebind;
109 struct iaddr address;
110 char *server_name;
111 char *filename;
112 struct string_list *medium;
113 unsigned int is_static : 1;
114 unsigned int is_bootp : 1;
115 struct option_data options[256];
116};
117
118/* Possible states in which the client can be. */
119enum dhcp_state {
120 S_REBOOTING,
121 S_INIT,
122 S_SELECTING,
123 S_REQUESTING,
124 S_BOUND,
125 S_RENEWING,
126 S_REBINDING
127};
128
129struct client_config {
130 struct option_data defaults[256];
131 enum {
132 ACTION_DEFAULT,
133 ACTION_SUPERSEDE,
134 ACTION_PREPEND,
135 ACTION_APPEND
136 } default_actions[256];
137
138 struct option_data send_options[256];
139 u_int8_t required_options[256];
140 u_int8_t requested_options[256];
141 int requested_option_count;
142 time_t timeout;
143 time_t initial_interval;
144 time_t link_timeout;
145 time_t retry_interval;
146 time_t select_interval;
147 time_t reboot_timeout;
148 time_t backoff_cutoff;
149 struct string_list *media;
150 char *script_name;
151 enum { IGNORE, ACCEPT, PREFER }
152 bootp_policy;
153 struct string_list *medium;
154 struct iaddrlist *reject_list;
155};
156
157struct client_state {
158 struct client_lease *active;
159 struct client_lease *new;
160 struct client_lease *offered_leases;
161 struct client_lease *leases;
162 struct client_lease *alias;
163 enum dhcp_state state;
164 struct iaddr destination;
165 u_int32_t xid;
166 u_int16_t secs;
167 time_t first_sending;
168 time_t interval;
169 struct string_list *medium;
170 struct dhcp_packet packet;
171 int packet_length;
172 struct iaddr requested_address;
173 char **scriptEnv;
174 int scriptEnvsize;
175};
176
177struct interface_info {
178 struct hardware hw_address;
179 struct in_addr primary_address;
180 char name[IFNAMSIZ];
181 int rfdesc;
182 int wfdesc;
183 int ufdesc; /* unicast */
184 unsigned char *rbuf;
185 size_t rbuf_max;
186 size_t rbuf_offset;
187 size_t rbuf_len;
188 struct ifreq *ifp;
189 int noifmedia;
190 int errors;
191 u_int16_t index;
192 int linkstat;
193};
194
195struct timeout {
196 struct timeout *next;
197 time_t when;
198 void (*func)(void);
199};
200
201#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf"
202#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases"
203#define _PATH_DHCLIENT_SCRIPT "/sbin/dhclient-script"
204#define DHCPD_LOG_FACILITY LOG_DAEMON
205
206/* External definitions... */
207
208extern struct interface_info *ifi;
209extern struct client_state *client;
210extern struct client_config *config;
211
212/* options.c */
213int cons_options(unsigned char *, const int, struct option_data *);
214char *pretty_print_option(unsigned int, unsigned char *, int, int, int);
215void do_packet(int, unsigned int, struct iaddr, struct hardware *);
216
217/* errwarn.c */
218extern int warnings_occurred;
219void error(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
220int warning(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
221int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
4cada237 222#ifdef DEBUG
846204b6 223int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
4cada237 224#endif
846204b6
HT
225int parse_warn(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
226
227/* conflex.c */
228extern int lexline, lexchar;
229extern char *token_line, *tlname;
230void new_parse(char *);
231int next_token(char **, FILE *);
232int peek_token(char **, FILE *);
233
234/* parse.c */
235void skip_to_semi(FILE *);
236int parse_semi(FILE *);
237char *parse_string(FILE *);
238int parse_ip_addr(FILE *, struct iaddr *);
239void parse_hardware_param(FILE *, struct hardware *);
240void parse_lease_time(FILE *, time_t *);
241int parse_numeric_aggregate(FILE *, unsigned char *, int, int, int);
242void convert_num(unsigned char *, char *, int, int);
243time_t parse_date(FILE *);
244
245/* bpf.c */
246int if_register_bpf(void);
247void if_register_send(void);
248void if_register_receive(void);
249ssize_t send_packet(struct in_addr, struct sockaddr_in *, struct hardware *);
250ssize_t receive_packet(struct sockaddr_in *, struct hardware *);
251
252/* dispatch.c */
253void discover_interface(void);
254void reinitialize_interface(void);
255void dispatch(void);
256void got_one(void);
257void add_timeout(time_t, void (*)(void));
258void cancel_timeout(void (*)(void));
259int interface_status(char *);
260int interface_link_status(char *);
261int interface_link_forceup(char *);
846204b6
HT
262
263/* tables.c */
264extern const struct option dhcp_options[256];
265
266/* convert.c */
267u_int32_t getULong(unsigned char *);
268int32_t getLong(unsigned char *);
269u_int16_t getUShort(unsigned char *);
270int16_t getShort(unsigned char *);
271void putULong(unsigned char *, u_int32_t);
272void putLong(unsigned char *, int32_t);
273void putUShort(unsigned char *, unsigned int);
274void putShort(unsigned char *, int);
275
276/* inet.c */
277struct iaddr subnet_number(struct iaddr, struct iaddr);
278struct iaddr broadcast_addr(struct iaddr, struct iaddr);
279int addr_eq(struct iaddr, struct iaddr);
280char *piaddr(struct iaddr);
281
282/* dhclient.c */
283extern char *path_dhclient_conf;
284extern char *path_dhclient_db;
285extern time_t cur_time;
286extern int log_perror;
287extern int routefd;
288
289void dhcpoffer(struct iaddr, struct option_data *);
290void dhcpack(struct iaddr, struct option_data *);
291void dhcpnak(struct iaddr, struct option_data *);
292
293void send_discover(void);
294void send_request(void);
295void send_decline(void);
296
297void state_reboot(void);
298void state_init(void);
299void state_selecting(void);
300void state_bound(void);
301void state_panic(void);
302
303void bind_lease(void);
304
305void make_discover(struct client_lease *);
306void make_request(struct client_lease *);
307void make_decline(struct client_lease *);
308
309void free_client_lease(struct client_lease *);
310void rewrite_client_leases(void);
311void write_client_lease(struct client_lease *, int);
312
313void priv_script_init(char *, char *);
314void priv_script_write_params(char *, struct client_lease *);
315int priv_script_go(void);
316
317void script_init(char *, struct string_list *);
318void script_write_params(char *, struct client_lease *);
319int script_go(void);
320void script_set_env(const char *, const char *, const char *);
321void script_flush_env(void);
322int dhcp_option_ev_name(char *, size_t, const struct option *);
323
324struct client_lease *packet_to_lease(struct option_data *);
325void go_daemon(void);
326
327void routehandler(void);
328
329/* packet.c */
330void assemble_hw_header(unsigned char *, int *, struct hardware *);
331void assemble_udp_ip_header(unsigned char *, int *, u_int32_t, u_int32_t,
332 unsigned int, unsigned char *, int);
333ssize_t decode_hw_header(unsigned char *, int, struct hardware *);
334ssize_t decode_udp_ip_header(unsigned char *, int, struct sockaddr_in *,
335 unsigned char *, int);
336
337/* clparse.c */
338int read_client_conf(void);
339void read_client_leases(void);
340void parse_client_statement(FILE *);
341int parse_X(FILE *, u_int8_t *, int);
342int parse_option_list(FILE *, u_int8_t *);
343void parse_interface_declaration(FILE *);
344void parse_client_lease_statement(FILE *, int);
345void parse_client_lease_declaration(FILE *, struct client_lease *);
346int parse_option_decl(FILE *, struct option_data *);
347void parse_string_list(FILE *, struct string_list **, int);
348void parse_reject_statement(FILE *);