xref: /xnu-12377.41.6/bsd/netinet/dhcp_options.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1 #ifndef _NETINET_DHCP_OPTIONS_H
2 #define _NETINET_DHCP_OPTIONS_H
3 #include <sys/appleapiopts.h>
4 /*
5  * Copyright (c) 1999-2016 Apple Inc. All rights reserved.
6  *
7  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
8  *
9  * This file contains Original Code and/or Modifications of Original Code
10  * as defined in and that are subject to the Apple Public Source License
11  * Version 2.0 (the 'License'). You may not use this file except in
12  * compliance with the License. The rights granted to you under the License
13  * may not be used to create, or enable the creation or redistribution of,
14  * unlawful or unlicensed copies of an Apple operating system, or to
15  * circumvent, violate, or enable the circumvention or violation of, any
16  * terms of an Apple operating system software license agreement.
17  *
18  * Please obtain a copy of the License at
19  * http://www.opensource.apple.com/apsl/ and read it before using this file.
20  *
21  * The Original Code and all software distributed under the License are
22  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
23  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
24  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
26  * Please see the License for the specific language governing rights and
27  * limitations under the License.
28  *
29  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30  */
31 
32 /*
33  * dhcp_options.h
34  * - routines to parse and access dhcp options
35  */
36 
37 /*
38  * Modification History
39  *
40  * March 15, 2002	Dieter Siegmund (dieter@apple)
41  * - imported from bootp project
42  */
43 #include <mach/boolean.h>
44 #include <netinet/dhcp.h>
45 
46 
47 /* overloaded option values */
48 #define DHCP_OVERLOAD_FILE      1
49 #define DHCP_OVERLOAD_SNAME     2
50 #define DHCP_OVERLOAD_BOTH      3
51 
52 /*
53  * DHCP_OPTION_SIZE_MAX
54  * - the largest size that an option can be (limited to an 8-bit quantity)
55  */
56 #define DHCP_OPTION_SIZE_MAX    255
57 
58 #define DHCP_TAG_OFFSET         0
59 #define DHCP_LEN_OFFSET         1
60 #define DHCP_OPTION_OFFSET      2
61 
62 
63 
64 #define RFC_OPTIONS_MAGIC               { 99, 130, 83, 99 }
65 #define RFC_MAGIC_SIZE                  4 /* bytes */
66 
67 enum {
68 	/* rfc 1497 vendor extensions: 0..18, 255 */
69 	dhcptag_pad_e                       = 0,
70 	dhcptag_end_e                       = 255,
71 	dhcptag_subnet_mask_e               = 1,
72 	dhcptag_time_offset_e               = 2,
73 	dhcptag_router_e                    = 3,
74 	dhcptag_time_server_e               = 4,
75 	dhcptag_name_server_e               = 5,
76 	dhcptag_domain_name_server_e        = 6,
77 	dhcptag_log_server_e                = 7,
78 	dhcptag_cookie_server_e             = 8,
79 	dhcptag_lpr_server_e                = 9,
80 	dhcptag_impress_server_e            = 10,
81 	dhcptag_resource_location_server_e  = 11,
82 	dhcptag_host_name_e                 = 12,
83 	dhcptag_boot_file_size_e            = 13,
84 	dhcptag_merit_dump_file_e           = 14,
85 	dhcptag_domain_name_e               = 15,
86 	dhcptag_swap_server_e               = 16,
87 	dhcptag_root_path_e                 = 17,
88 	dhcptag_extensions_path_e           = 18,
89 
90 	/* ip layer parameters per host: 19..25 */
91 	dhcptag_ip_forwarding_e             = 19,
92 	dhcptag_non_local_source_routing_e  = 20,
93 	dhcptag_policy_filter_e             = 21,
94 	dhcptag_max_dgram_reassembly_size_e = 22,
95 	dhcptag_default_ip_time_to_live_e   = 23,
96 	dhcptag_path_mtu_aging_timeout_e    = 24,
97 	dhcptag_path_mtu_plateau_table_e    = 25,
98 
99 	/* ip layer parameters per interface: 26..33 */
100 	dhcptag_interface_mtu_e             = 26,
101 	dhcptag_all_subnets_local_e         = 27,
102 	dhcptag_broadcast_address_e         = 28,
103 	dhcptag_perform_mask_discovery_e    = 29,
104 	dhcptag_mask_supplier_e             = 30,
105 	dhcptag_perform_router_discovery_e  = 31,
106 	dhcptag_router_solicitation_address_e       = 32,
107 	dhcptag_static_route_e              = 33,
108 	dhcptag_trailer_encapsulation_e     = 34,
109 	dhcptag_arp_cache_timeout_e         = 35,
110 	dhcptag_ethernet_encapsulation_e    = 36,
111 
112 	/* tcp parameters: 37..39 */
113 	dhcptag_default_ttl_e               = 37,
114 	dhcptag_keepalive_interval_e        = 38,
115 	dhcptag_keepalive_garbage_e         = 39,
116 
117 	/* application & service parameters: 40..49, 64, 65, 68..76, 78, 79, 95 */
118 	dhcptag_nis_domain_e                = 40,
119 	dhcptag_nis_servers_e               = 41,
120 	dhcptag_network_time_protocol_servers_e     = 42,
121 	dhcptag_vendor_specific_e           = 43,
122 	dhcptag_nb_over_tcpip_name_server_e = 44,
123 	dhcptag_nb_over_tcpip_dgram_dist_server_e   = 45,
124 	dhcptag_nb_over_tcpip_node_type_e   = 46,
125 	dhcptag_nb_over_tcpip_scope_e       = 47,
126 	dhcptag_x_windows_font_server_e     = 48,
127 	dhcptag_x_windows_display_manager_e = 49,
128 	dhcptag_nis_plus_domain_e           = 64,
129 	dhcptag_nis_plus_servers_e          = 65,
130 	dhcptag_mobile_ip_home_agent_e      = 68,
131 	dhcptag_smtp_server_e               = 69,
132 	dhcptag_pop3_server_e               = 70,
133 	dhcptag_nntp_server_e               = 71,
134 	dhcptag_default_www_server_e        = 72,
135 	dhcptag_default_finger_server_e     = 73,
136 	dhcptag_default_irc_server_e        = 74,
137 	dhcptag_streettalk_server_e         = 75,
138 	dhcptag_stda_server_e               = 76,
139 	dhcptag_slp_directory_agent_e       = 78,
140 	dhcptag_slp_service_scope_e         = 79,
141 	dhcptag_ldap_url_e                  = 95,
142 
143 	/* dhcp-specific extensions: 50..61, 66, 67 */
144 	dhcptag_requested_ip_address_e      = 50,
145 	dhcptag_lease_time_e                = 51,
146 	dhcptag_option_overload_e           = 52,
147 	dhcptag_dhcp_message_type_e         = 53,
148 	dhcptag_server_identifier_e         = 54,
149 	dhcptag_parameter_request_list_e    = 55,
150 	dhcptag_message_e                   = 56,
151 	dhcptag_max_dhcp_message_size_e     = 57,
152 	dhcptag_renewal_t1_time_value_e     = 58,
153 	dhcptag_rebinding_t2_time_value_e   = 59,
154 	dhcptag_vendor_class_identifier_e   = 60,
155 	dhcptag_client_identifier_e         = 61,
156 	dhcptag_tftp_server_name_e          = 66,
157 	dhcptag_bootfile_name_e             = 67,
158 
159 	/* netinfo parent tags: 112, 113 */
160 	dhcptag_netinfo_server_address_e    = 112,
161 	dhcptag_netinfo_server_tag_e        = 113,
162 
163 	/* ad-hoc network disable option */
164 	dhcptag_auto_configure_e            = 116,
165 };
166 typedef uint8_t dhcptag_t;
167 
168 /*
169  * Module: dhcpol (dhcp options list)
170  *
171  * Purpose:
172  *   Routines to parse and retrieve dhcp options.
173  */
174 
175 typedef struct {
176 	const void * *      array;/* malloc'd array of pointers */
177 	uint32_t            size;/* number of elements in array */
178 	uint32_t            count;/* number of occupied elements */
179 } ptrlist_t;
180 
181 typedef ptrlist_t dhcpol_t;
182 
183 #ifdef BSD_KERNEL_PRIVATE
184 
185 void                    dhcpol_init(dhcpol_t * list);
186 void                    dhcpol_free(dhcpol_t * list);
187 int                     dhcpol_count(dhcpol_t * list);
188 boolean_t               dhcpol_add(dhcpol_t * list, const void * element);
189 const void *            dhcpol_element(dhcpol_t * list, int i);
190 boolean_t               dhcpol_concat(dhcpol_t * list, dhcpol_t * extra);
191 boolean_t               dhcpol_parse_buffer(dhcpol_t * list,
192     const void * buffer,
193     int length);
194 const void *            dhcpol_find(dhcpol_t * list, int tag, int * len_p,
195     int * start);
196 boolean_t               dhcpol_parse_packet(dhcpol_t * options,
197     const struct dhcp * pkt, int len);
198 
199 #endif /* BSD_KERNEL_PRIVATE */
200 #endif /* _NETINET_DHCP_OPTIONS_H */
201