iwm: Fix S:N reporting in ifconfig(8)
[dragonfly.git] / sbin / dhclient / dhcpd.h
CommitLineData
dafcba85 1/* $OpenBSD: src/sbin/dhclient/dhcpd.h,v 1.82 2012/10/27 23:08:53 krw 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;
846204b6
HT
112 unsigned int is_static : 1;
113 unsigned int is_bootp : 1;
114 struct option_data options[256];
115};
116
117/* Possible states in which the client can be. */
118enum dhcp_state {
119 S_REBOOTING,
120 S_INIT,
121 S_SELECTING,
122 S_REQUESTING,
123 S_BOUND,
124 S_RENEWING,
125 S_REBINDING
126};
127
128struct client_config {
129 struct option_data defaults[256];
130 enum {
131 ACTION_DEFAULT,
04e4af02 132 ACTION_IGNORE,
846204b6
HT
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;
846204b6
HT
149 char *script_name;
150 enum { IGNORE, ACCEPT, PREFER }
151 bootp_policy;
846204b6
HT
152 struct iaddrlist *reject_list;
153};
154
155struct client_state {
156 struct client_lease *active;
157 struct client_lease *new;
158 struct client_lease *offered_leases;
159 struct client_lease *leases;
846204b6
HT
160 enum dhcp_state state;
161 struct iaddr destination;
162 u_int32_t xid;
163 u_int16_t secs;
164 time_t first_sending;
165 time_t interval;
846204b6
HT
166 struct dhcp_packet packet;
167 int packet_length;
168 struct iaddr requested_address;
169 char **scriptEnv;
170 int scriptEnvsize;
171};
172
173struct interface_info {
174 struct hardware hw_address;
175 struct in_addr primary_address;
176 char name[IFNAMSIZ];
177 int rfdesc;
178 int wfdesc;
179 int ufdesc; /* unicast */
180 unsigned char *rbuf;
181 size_t rbuf_max;
182 size_t rbuf_offset;
183 size_t rbuf_len;
184 struct ifreq *ifp;
185 int noifmedia;
186 int errors;
187 u_int16_t index;
188 int linkstat;
189};
190
191struct timeout {
846204b6
HT
192 time_t when;
193 void (*func)(void);
194};
195
196#define _PATH_DHCLIENT_CONF "/etc/dhclient.conf"
197#define _PATH_DHCLIENT_DB "/var/db/dhclient.leases"
198#define _PATH_DHCLIENT_SCRIPT "/sbin/dhclient-script"
199#define DHCPD_LOG_FACILITY LOG_DAEMON
200
201/* External definitions... */
202
203extern struct interface_info *ifi;
204extern struct client_state *client;
205extern struct client_config *config;
206
207/* options.c */
741bbb9f 208int cons_options(struct option_data *);
dafcba85 209char *pretty_print_option(unsigned int, struct option_data *, int);
846204b6
HT
210void do_packet(int, unsigned int, struct iaddr, struct hardware *);
211
212/* errwarn.c */
213extern int warnings_occurred;
a92dccf2 214void error(char *, ...) __attribute__((__noreturn__)) __attribute__ ((__format__ (__printf__, 1, 2)));
846204b6
HT
215int warning(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
216int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
4cada237 217#ifdef DEBUG
846204b6 218int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
4cada237 219#endif
846204b6
HT
220int parse_warn(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
221
222/* conflex.c */
223extern int lexline, lexchar;
224extern char *token_line, *tlname;
225void new_parse(char *);
226int next_token(char **, FILE *);
227int peek_token(char **, FILE *);
228
229/* parse.c */
230void skip_to_semi(FILE *);
231int parse_semi(FILE *);
232char *parse_string(FILE *);
233int parse_ip_addr(FILE *, struct iaddr *);
234void parse_hardware_param(FILE *, struct hardware *);
235void parse_lease_time(FILE *, time_t *);
236int parse_numeric_aggregate(FILE *, unsigned char *, int, int, int);
237void convert_num(unsigned char *, char *, int, int);
238time_t parse_date(FILE *);
239
240/* bpf.c */
241int if_register_bpf(void);
242void if_register_send(void);
243void if_register_receive(void);
244ssize_t send_packet(struct in_addr, struct sockaddr_in *, struct hardware *);
245ssize_t receive_packet(struct sockaddr_in *, struct hardware *);
246
247/* dispatch.c */
248void discover_interface(void);
a92dccf2 249void dispatch(void) __dead2;
846204b6 250void got_one(void);
8d05e1a0 251void set_timeout(time_t, void (*)(void));
3c279f6e 252void set_timeout_interval(time_t, void (*)(void));
8d05e1a0 253void cancel_timeout(void);
846204b6 254int interface_status(char *);
846204b6 255int interface_link_forceup(char *);
107428a4 256int subnet_exists(struct client_lease *);
846204b6
HT
257
258/* tables.c */
259extern const struct option dhcp_options[256];
260
261/* convert.c */
262u_int32_t getULong(unsigned char *);
263int32_t getLong(unsigned char *);
264u_int16_t getUShort(unsigned char *);
265int16_t getShort(unsigned char *);
266void putULong(unsigned char *, u_int32_t);
267void putLong(unsigned char *, int32_t);
268void putUShort(unsigned char *, unsigned int);
269void putShort(unsigned char *, int);
270
271/* inet.c */
272struct iaddr subnet_number(struct iaddr, struct iaddr);
273struct iaddr broadcast_addr(struct iaddr, struct iaddr);
274int addr_eq(struct iaddr, struct iaddr);
275char *piaddr(struct iaddr);
276
277/* dhclient.c */
278extern char *path_dhclient_conf;
279extern char *path_dhclient_db;
846204b6
HT
280extern int log_perror;
281extern int routefd;
282
283void dhcpoffer(struct iaddr, struct option_data *);
284void dhcpack(struct iaddr, struct option_data *);
285void dhcpnak(struct iaddr, struct option_data *);
286
287void send_discover(void);
288void send_request(void);
289void send_decline(void);
290
291void state_reboot(void);
292void state_init(void);
293void state_selecting(void);
294void state_bound(void);
295void state_panic(void);
296
297void bind_lease(void);
298
299void make_discover(struct client_lease *);
300void make_request(struct client_lease *);
301void make_decline(struct client_lease *);
302
303void free_client_lease(struct client_lease *);
304void rewrite_client_leases(void);
cc08537d 305void write_client_lease(struct client_lease *);
846204b6 306
7cbe3601 307void priv_script_init(char *);
846204b6
HT
308void priv_script_write_params(char *, struct client_lease *);
309int priv_script_go(void);
310
7cbe3601 311void script_init(char *);
846204b6
HT
312void script_write_params(char *, struct client_lease *);
313int script_go(void);
314void script_set_env(const char *, const char *, const char *);
315void script_flush_env(void);
316int dhcp_option_ev_name(char *, size_t, const struct option *);
317
318struct client_lease *packet_to_lease(struct option_data *);
319void go_daemon(void);
320
321void routehandler(void);
322
323/* packet.c */
324void assemble_hw_header(unsigned char *, int *, struct hardware *);
325void assemble_udp_ip_header(unsigned char *, int *, u_int32_t, u_int32_t,
326 unsigned int, unsigned char *, int);
327ssize_t decode_hw_header(unsigned char *, int, struct hardware *);
328ssize_t decode_udp_ip_header(unsigned char *, int, struct sockaddr_in *,
329 unsigned char *, int);
330
331/* clparse.c */
332int read_client_conf(void);
333void read_client_leases(void);
334void parse_client_statement(FILE *);
335int parse_X(FILE *, u_int8_t *, int);
336int parse_option_list(FILE *, u_int8_t *);
337void parse_interface_declaration(FILE *);
338void parse_client_lease_statement(FILE *, int);
339void parse_client_lease_declaration(FILE *, struct client_lease *);
340int parse_option_decl(FILE *, struct option_data *);
341void parse_string_list(FILE *, struct string_list **, int);
342void parse_reject_statement(FILE *);