1
2#ifndef _NETINET_DHCP_OPTIONS_H
3#define _NETINET_DHCP_OPTIONS_H
4#include <sys/appleapiopts.h>
5/*
6 * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
7 *
8 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
9 *
10 * This file contains Original Code and/or Modifications of Original Code
11 * as defined in and that are subject to the Apple Public Source License
12 * Version 2.0 (the 'License'). You may not use this file except in
13 * compliance with the License. The rights granted to you under the License
14 * may not be used to create, or enable the creation or redistribution of,
15 * unlawful or unlicensed copies of an Apple operating system, or to
16 * circumvent, violate, or enable the circumvention or violation of, any
17 * terms of an Apple operating system software license agreement.
18 *
19 * Please obtain a copy of the License at
20 * http://www.opensource.apple.com/apsl/ and read it before using this file.
21 *
22 * The Original Code and all software distributed under the License are
23 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
24 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
25 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
27 * Please see the License for the specific language governing rights and
28 * limitations under the License.
29 *
30 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 */
32
33/*
34 * dhcp_options.h
35 * - routines to parse and access dhcp options
36 */
37
38/*
39 * Modification History
40 *
41 * March 15, 2002	Dieter Siegmund (dieter@apple)
42 * - imported from bootp project
43 */
44#include <mach/boolean.h>
45#include <netinet/dhcp.h>
46
47
48/* overloaded option values */
49#define DHCP_OVERLOAD_FILE	1
50#define DHCP_OVERLOAD_SNAME	2
51#define DHCP_OVERLOAD_BOTH	3
52
53/*
54 * DHCP_OPTION_SIZE_MAX
55 * - the largest size that an option can be (limited to an 8-bit quantity)
56 */
57#define DHCP_OPTION_SIZE_MAX	255
58
59#define DHCP_TAG_OFFSET		0
60#define DHCP_LEN_OFFSET		1
61#define DHCP_OPTION_OFFSET	2
62
63
64
65#define RFC_OPTIONS_MAGIC		{ 99, 130, 83, 99 }
66#define RFC_MAGIC_SIZE			4 /* bytes */
67
68enum {
69    /* rfc 1497 vendor extensions: 0..18, 255 */
70    dhcptag_pad_e                      	= 0,
71    dhcptag_end_e                      	= 255,
72    dhcptag_subnet_mask_e              	= 1,
73    dhcptag_time_offset_e              	= 2,
74    dhcptag_router_e                   	= 3,
75    dhcptag_time_server_e              	= 4,
76    dhcptag_name_server_e              	= 5,
77    dhcptag_domain_name_server_e       	= 6,
78    dhcptag_log_server_e               	= 7,
79    dhcptag_cookie_server_e            	= 8,
80    dhcptag_lpr_server_e               	= 9,
81    dhcptag_impress_server_e           	= 10,
82    dhcptag_resource_location_server_e 	= 11,
83    dhcptag_host_name_e                	= 12,
84    dhcptag_boot_file_size_e           	= 13,
85    dhcptag_merit_dump_file_e          	= 14,
86    dhcptag_domain_name_e              	= 15,
87    dhcptag_swap_server_e              	= 16,
88    dhcptag_root_path_e                	= 17,
89    dhcptag_extensions_path_e          	= 18,
90
91    /* ip layer parameters per host: 19..25 */
92    dhcptag_ip_forwarding_e            	= 19,
93    dhcptag_non_local_source_routing_e 	= 20,
94    dhcptag_policy_filter_e            	= 21,
95    dhcptag_max_dgram_reassembly_size_e	= 22,
96    dhcptag_default_ip_time_to_live_e  	= 23,
97    dhcptag_path_mtu_aging_timeout_e   	= 24,
98    dhcptag_path_mtu_plateau_table_e   	= 25,
99
100    /* ip layer parameters per interface: 26..33 */
101    dhcptag_interface_mtu_e            	= 26,
102    dhcptag_all_subnets_local_e        	= 27,
103    dhcptag_broadcast_address_e        	= 28,
104    dhcptag_perform_mask_discovery_e   	= 29,
105    dhcptag_mask_supplier_e            	= 30,
106    dhcptag_perform_router_discovery_e 	= 31,
107    dhcptag_router_solicitation_address_e	= 32,
108    dhcptag_static_route_e             	= 33,
109    dhcptag_trailer_encapsulation_e    	= 34,
110    dhcptag_arp_cache_timeout_e        	= 35,
111    dhcptag_ethernet_encapsulation_e   	= 36,
112
113    /* tcp parameters: 37..39 */
114    dhcptag_default_ttl_e              	= 37,
115    dhcptag_keepalive_interval_e       	= 38,
116    dhcptag_keepalive_garbage_e        	= 39,
117
118    /* application & service parameters: 40..49, 64, 65, 68..76, 78, 79, 95 */
119    dhcptag_nis_domain_e               	= 40,
120    dhcptag_nis_servers_e              	= 41,
121    dhcptag_network_time_protocol_servers_e	= 42,
122    dhcptag_vendor_specific_e          	= 43,
123    dhcptag_nb_over_tcpip_name_server_e	= 44,
124    dhcptag_nb_over_tcpip_dgram_dist_server_e	= 45,
125    dhcptag_nb_over_tcpip_node_type_e  	= 46,
126    dhcptag_nb_over_tcpip_scope_e      	= 47,
127    dhcptag_x_windows_font_server_e    	= 48,
128    dhcptag_x_windows_display_manager_e	= 49,
129    dhcptag_nis_plus_domain_e          	= 64,
130    dhcptag_nis_plus_servers_e         	= 65,
131    dhcptag_mobile_ip_home_agent_e     	= 68,
132    dhcptag_smtp_server_e              	= 69,
133    dhcptag_pop3_server_e              	= 70,
134    dhcptag_nntp_server_e              	= 71,
135    dhcptag_default_www_server_e       	= 72,
136    dhcptag_default_finger_server_e    	= 73,
137    dhcptag_default_irc_server_e       	= 74,
138    dhcptag_streettalk_server_e        	= 75,
139    dhcptag_stda_server_e              	= 76,
140    dhcptag_slp_directory_agent_e      	= 78,
141    dhcptag_slp_service_scope_e        	= 79,
142    dhcptag_ldap_url_e                 	= 95,
143
144    /* dhcp-specific extensions: 50..61, 66, 67 */
145    dhcptag_requested_ip_address_e     	= 50,
146    dhcptag_lease_time_e               	= 51,
147    dhcptag_option_overload_e          	= 52,
148    dhcptag_dhcp_message_type_e        	= 53,
149    dhcptag_server_identifier_e        	= 54,
150    dhcptag_parameter_request_list_e   	= 55,
151    dhcptag_message_e                  	= 56,
152    dhcptag_max_dhcp_message_size_e    	= 57,
153    dhcptag_renewal_t1_time_value_e    	= 58,
154    dhcptag_rebinding_t2_time_value_e  	= 59,
155    dhcptag_vendor_class_identifier_e  	= 60,
156    dhcptag_client_identifier_e        	= 61,
157    dhcptag_tftp_server_name_e         	= 66,
158    dhcptag_bootfile_name_e            	= 67,
159
160    /* netinfo parent tags: 112, 113 */
161    dhcptag_netinfo_server_address_e   	= 112,
162    dhcptag_netinfo_server_tag_e       	= 113,
163
164    /* ad-hoc network disable option */
165    dhcptag_auto_configure_e           	= 116,
166};
167typedef uint8_t dhcptag_t;
168
169/*
170 * Module: dhcpol (dhcp options list)
171 *
172 * Purpose:
173 *   Routines to parse and retrieve dhcp options.
174 */
175
176typedef struct {
177    const void * *	array;	/* malloc'd array of pointers */
178    int			size;	/* number of elements in array */
179    int			count;	/* number of occupied elements */
180} ptrlist_t;
181
182typedef ptrlist_t dhcpol_t;
183
184#ifdef BSD_KERNEL_PRIVATE
185
186void			dhcpol_init(dhcpol_t * list);
187void			dhcpol_free(dhcpol_t * list);
188int			dhcpol_count(dhcpol_t * list);
189boolean_t		dhcpol_add(dhcpol_t * list, const void * element);
190const void *		dhcpol_element(dhcpol_t * list, int i);
191boolean_t		dhcpol_concat(dhcpol_t * list, dhcpol_t * extra);
192boolean_t		dhcpol_parse_buffer(dhcpol_t * list,
193					    const void * buffer,
194					    int length);
195const void *		dhcpol_find(dhcpol_t * list, int tag, int * len_p,
196				    int * start);
197#if 0
198void *			dhcpol_get(dhcpol_t * list, int tag, int * len_p);
199#endif
200boolean_t		dhcpol_parse_packet(dhcpol_t * options,
201					    const struct dhcp * pkt, int len);
202void			dhcpol_print(dhcpol_t * list);
203/*
204 * Module: dhcpoa (dhcp options area)
205 *
206 * Purpose:
207 *   Types and functions to create new dhcp option areas.
208 */
209
210/*
211 * Struct: dhcpoa_s
212 * Purpose:
213 *   To record information about a dhcp option data area.
214 */
215struct dhcpoa_s {
216    uint8_t *	oa_buffer;	/* data area to hold options */
217    int		oa_size;	/* size of buffer */
218    int		oa_offset;	/* offset of next option to write */
219    int		oa_end_tag;	/* to mark when options are terminated */
220    int		oa_option_count;/* number of options present */
221    int		oa_reserve; 	/* space to reserve, either 0 or 1 */
222};
223
224/*
225 * Type: dhcpoa_t
226 *
227 * Purpose:
228 *   To record information about a dhcp option data area.
229 */
230typedef struct dhcpoa_s dhcpoa_t;
231
232/*
233 * Type:dhcpoa_ret_t
234 *
235 * Purpose:
236 *  outine return codes
237 */
238typedef enum {
239    dhcpoa_success_e = 0,
240    dhcpoa_failed_e,
241    dhcpoa_full_e,
242} dhcpoa_ret_t;
243
244void
245dhcpoa_init(dhcpoa_t * opt, void * buffer, int size);
246
247void
248dhcpoa_init_no_end(dhcpoa_t * opt, void * buffer, int size);
249
250dhcpoa_ret_t
251dhcpoa_add(dhcpoa_t * oa_p, dhcptag_t tag, int len, const void * data);
252
253dhcpoa_ret_t
254dhcpoa_add_dhcpmsg(dhcpoa_t * oa_p, dhcp_msgtype_t msgtype);
255
256#if 0
257dhcpoa_ret_t
258dhcpoa_vendor_add(dhcpoa_t * oa_p, dhcpoa_t * vendor_oa_p,
259		  dhcptag_t tag, int len, void * option);
260#endif
261
262int
263dhcpoa_used(dhcpoa_t * oa_p);
264
265int
266dhcpoa_count(dhcpoa_t * oa_p);
267
268void *
269dhcpoa_buffer(dhcpoa_t * oa_p);
270
271int
272dhcpoa_freespace(dhcpoa_t * oa_p);
273
274int
275dhcpoa_size(dhcpoa_t * oa_p);
276
277#endif /* BSD_KERNEL_PRIVATE */
278#endif /* _NETINET_DHCP_OPTIONS_H */
279