xref: /illumos-gate/usr/src/uts/common/netinet/dhcp6.h (revision 36e852a172cba914383d7341c988128b2c667fbd)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _DHCP6_H
28 #define	_DHCP6_H
29 
30 /*
31  * This header file describes constants and on-the-wire data structures used
32  * with DHCPv6.
33  *
34  * Note that the data structures contained here must be used with caution.  The
35  * DHCPv6 protocol generally does not maintain alignment.
36  *
37  * (Users may also need to include other header files to get ntohs/htons
38  * definitions, if the DHCPV6_{GET,SET} macros are used.)
39  */
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #include <sys/types.h>
46 #include <netinet/in.h>
47 
48 /*
49  * Message Types
50  */
51 #define	DHCPV6_MSG_SOLICIT	1	/* Client sends */
52 #define	DHCPV6_MSG_ADVERTISE	2	/* Server sends */
53 #define	DHCPV6_MSG_REQUEST	3	/* Client sends */
54 #define	DHCPV6_MSG_CONFIRM	4	/* Client sends */
55 #define	DHCPV6_MSG_RENEW	5	/* Client sends */
56 #define	DHCPV6_MSG_REBIND	6	/* Client sends */
57 #define	DHCPV6_MSG_REPLY	7	/* Server sends */
58 #define	DHCPV6_MSG_RELEASE	8	/* Client sends */
59 #define	DHCPV6_MSG_DECLINE	9	/* Client sends */
60 #define	DHCPV6_MSG_RECONFIGURE	10	/* Server sends */
61 #define	DHCPV6_MSG_INFO_REQ	11	/* Client sends */
62 #define	DHCPV6_MSG_RELAY_FORW	12	/* Relay agent sends to server */
63 #define	DHCPV6_MSG_RELAY_REPL	13	/* Server sends to relay agent */
64 
65 /*
66  * Status Codes
67  */
68 #define	DHCPV6_STAT_SUCCESS	0
69 #define	DHCPV6_STAT_UNSPECFAIL	1	/* Unknown reason */
70 #define	DHCPV6_STAT_NOADDRS	2	/* Server has no addresses available */
71 #define	DHCPV6_STAT_NOBINDING	3	/* Client record unavailable */
72 #define	DHCPV6_STAT_NOTONLINK	4	/* Prefix inappropriate for link */
73 #define	DHCPV6_STAT_USEMCAST	5	/* Client must use multicast */
74 #define	DHCPV6_STAT_NOPREFIX	6	/* No prefix available; RFC3633 */
75 
76 /*
77  * DHCP Unique Identifier (DUID) Types
78  */
79 #define	DHCPV6_DUID_LLT		1	/* Link layer address plus time */
80 #define	DHCPV6_DUID_EN		2	/* Vendor assigned */
81 #define	DHCPV6_DUID_LL		3	/* Link layer address */
82 
83 /*
84  * DHCPv6 Option Codes
85  * Note: options 10 and 35 are not assigned.
86  */
87 #define	DHCPV6_OPT_CLIENTID	1	/* Client's DUID */
88 #define	DHCPV6_OPT_SERVERID	2	/* Server's DUID */
89 #define	DHCPV6_OPT_IA_NA	3	/* Non-temporary addrs; dhcpv6_ia_na */
90 #define	DHCPV6_OPT_IA_TA	4	/* Temporary addrs; dhcpv6_ia_ta */
91 #define	DHCPV6_OPT_IAADDR	5	/* IA Address; dhcpv6_iaaddr */
92 #define	DHCPV6_OPT_ORO		6	/* Option Request; uint16_t array */
93 #define	DHCPV6_OPT_PREFERENCE	7	/* Server preference; uint8_t */
94 #define	DHCPV6_OPT_ELAPSED_TIME	8	/* Client time; uint16_t; centisec */
95 #define	DHCPV6_OPT_RELAY_MSG	9	/* Relayed client DHCP message */
96 #define	DHCPV6_OPT_AUTH		11	/* Authentication; dhcpv6_auth */
97 #define	DHCPV6_OPT_UNICAST	12	/* Client may unicast; in6_addr_t */
98 #define	DHCPV6_OPT_STATUS_CODE	13	/* Status; uint16_t plus string */
99 #define	DHCPV6_OPT_RAPID_COMMIT	14	/* Server may do RC; boolean (len 0) */
100 #define	DHCPV6_OPT_USER_CLASS	15	/* Classes; {uint16_t,uint8_t...}... */
101 #define	DHCPV6_OPT_VENDOR_CLASS	16	/* Client vendor; uint32_t + list */
102 #define	DHCPV6_OPT_VENDOR_OPT	17	/* Vendor specific; uint32_t+opts */
103 #define	DHCPV6_OPT_INTERFACE_ID	18	/* Relay agent interface */
104 #define	DHCPV6_OPT_RECONF_MSG	19	/* Reconfigure; uint8_t */
105 #define	DHCPV6_OPT_RECONF_ACC	20	/* Reconfigure accept; boolean */
106 #define	DHCPV6_OPT_SIP_NAMES	21	/* SIP srv domain names (RFC3319) */
107 #define	DHCPV6_OPT_SIP_ADDR	22	/* SIP srv IPv6 address (RFC3319) */
108 #define	DHCPV6_OPT_DNS_ADDR	23	/* DNS Recur. Name Server (RFC3646) */
109 #define	DHCPV6_OPT_DNS_SEARCH	24	/* Domain Search List (RFC3646) */
110 #define	DHCPV6_OPT_IA_PD	25	/* Delegate dhcpv6_ia_na (RFC3633) */
111 #define	DHCPV6_OPT_IAPREFIX	26	/* Prefix dhcpv6_iaprefix (RFC3633) */
112 #define	DHCPV6_OPT_NIS_SERVERS	27	/* NIS in6_addr_t array (RFC3898) */
113 #define	DHCPV6_OPT_NIS_DOMAIN	29	/* NIS Domain string (RFC3898) */
114 #define	DHCPV6_OPT_SNTP_SERVERS	31	/* SNTP in6_addr_t array (RFC4075) */
115 #define	DHCPV6_OPT_INFO_REFTIME	32	/* Info refresh uint32_t (RFC4242) */
116 #define	DHCPV6_OPT_BCMCS_SRV_D	33	/* NUL-term string list (RFC4280) */
117 #define	DHCPV6_OPT_BCMCS_SRV_A	34	/* in6_addr_t array (RFC4280) */
118 #define	DHCPV6_OPT_GEOCONF_CVC	36	/* dhcpv6_civic_t plus TLVs */
119 #define	DHCPV6_OPT_REMOTE_ID	37	/* uint32_t plus opaque */
120 #define	DHCPV6_OPT_SUBSCRIBER	38	/* opaque; may be NVT ASCII */
121 #define	DHCPV6_OPT_CLIENT_FQDN	39	/* uint8_t plus domain */
122 
123 /*
124  * Reconfiguration types; used with DHCPV6_OPT_RECONF_MSG option.
125  */
126 #define	DHCPV6_RECONF_RENEW	5	/* Renew now */
127 #define	DHCPV6_RECONF_INFO	11	/* Request information */
128 
129 /*
130  * FQDN Flags; used with DHCPV6_OPT_CLIENT_FQDN option.
131  */
132 #define	DHCPV6_FQDNF_S	0x01	/* Server should perform AAAA RR updates */
133 #define	DHCPV6_FQDNF_O	0x02	/* Server override of 'S' bit */
134 #define	DHCPV6_FQDNF_N	0x04	/* Server should not perform any updates */
135 
136 /*
137  * Miscellany
138  */
139 #define	DHCPV6_INFTIME	0xfffffffful	/* Infinity; used for timers */
140 #define	DHCPV6_FOREVER	0xffff		/* Used for elapsed time option */
141 #define	DHCPV6_SUN_ENT	42		/* Sun Microsystems enterprise ID */
142 
143 /*
144  * Basic DHCPv6 message header used for server/client communications.  The
145  * options follow this header.
146  */
147 struct dhcpv6_message {
148 	uint8_t		d6m_msg_type;
149 	uint8_t		d6m_transid_ho;
150 	uint16_t	d6m_transid_lo;
151 };
152 
153 #define	DHCPV6_GET_TRANSID(msg) \
154 	(((msg)->d6m_transid_ho << 16) + ntohs((msg)->d6m_transid_lo))
155 #define	DHCPV6_SET_TRANSID(msg, id) \
156 	((msg)->d6m_transid_ho = (id) >> 16, (msg)->d6m_transid_lo = htons(id))
157 
158 /*
159  * DHCPv6 relay agent header used only for server/relay communications.  The
160  * options follow this header, and the client message is encapsulated as an
161  * option.  Note that the IPv6 addresses are not on natural word boundaries.
162  */
163 struct dhcpv6_relay {
164 	uint8_t		d6r_msg_type;
165 	uint8_t		d6r_hop_count;
166 	uint8_t		d6r_linkaddr[16];
167 	uint8_t		d6r_peeraddr[16];
168 };
169 
170 /*
171  * DHCPv6 generic option header.  Note that options are not aligned on any
172  * convenient boundary.
173  */
174 struct dhcpv6_option {
175 	uint16_t	d6o_code;
176 	uint16_t	d6o_len;
177 };
178 
179 /*
180  * Option header for IA_NA (Non-temporary addresses) and IA_PD (Prefix
181  * delegation).  Contains IA Address options for IA_NA, IA_PD Prefixes for
182  * IA_PD.
183  */
184 struct dhcpv6_ia_na {
185 	uint16_t	d6in_code;
186 	uint16_t	d6in_len;
187 	uint32_t	d6in_iaid;	/* Unique ID [interface] */
188 	uint32_t	d6in_t1;	/* Extend from same server */
189 	uint32_t	d6in_t2;	/* Extend from any server */
190 };
191 
192 /*
193  * Option header for IA_TA (Temporary addresses).  Contains IA Address options.
194  */
195 struct dhcpv6_ia_ta {
196 	uint16_t	d6it_code;
197 	uint16_t	d6it_len;
198 	uint32_t	d6it_iaid;	/* Unique ID [interface] */
199 };
200 
201 /*
202  * Option header for IA Address.  Must be used inside of an IA_NA or IA_TA
203  * option.  May contain a Status Code option.
204  */
205 struct dhcpv6_iaaddr {
206 	uint16_t	d6ia_code;
207 	uint16_t	d6ia_len;
208 	in6_addr_t	d6ia_addr;	/* IPv6 address */
209 	uint32_t	d6ia_preflife;	/* Preferred lifetime */
210 	uint32_t	d6ia_vallife;	/* Valid lifetime */
211 };
212 
213 /*
214  * Option header for Authentication.  Followed by variable-length
215  * authentication information field.  Warning: padding may be present.  Use
216  * defined size.
217  */
218 struct dhcpv6_auth {
219 	uint16_t	d6a_code;
220 	uint16_t	d6a_len;
221 	uint8_t		d6a_proto;	/* Protocol */
222 	uint8_t		d6a_alg;	/* Algorithm */
223 	uint8_t		d6a_rdm;	/* Replay Detection Method (RDM) */
224 	uint8_t		d6a_replay[8];	/* Information for RDM */
225 };
226 #define	DHCPV6_AUTH_SIZE	15
227 
228 /* dhpv6_auth.d6a_proto values */
229 #define	DHCPV6_PROTO_DELAYED	2	/* Delayed Authentication mechanism */
230 #define	DHCPV6_PROTO_RECONFIG	3	/* Reconfigure Key mechanism */
231 
232 /* dhpv6_auth.d6a_alg values */
233 #define	DHCPV6_ALG_HMAC_MD5	1	/* HMAC-MD5 signature */
234 
235 /* dhpv6_auth.d6a_rdm values */
236 #define	DHCPV6_RDM_MONOCNT	0	/* Monotonic counter */
237 
238 /*
239  * Option header for IA_PD Prefix.  Must be used inside of an IA_PD option.
240  * May contain a Status Code option.  Warning: padding may be present; use
241  * defined size.
242  */
243 struct dhcpv6_iaprefix {
244 	uint16_t	d6ip_code;
245 	uint16_t	d6ip_len;
246 	uint32_t	d6ip_preflife;	/* Preferred lifetime */
247 	uint32_t	d6ip_vallife;	/* Valid lifetime */
248 	uint8_t		d6ip_preflen;	/* Prefix length */
249 	uint8_t		d6ip_addr[16];	/* IPv6 prefix */
250 };
251 #define	DHCPV6_IAPREFIX_SIZE	29
252 
253 /*
254  * Option header for Civic Address information.  Followed by single octet TLV
255  * encoded address elements, using CIVICADDR_* values for type.  Warning:
256  * padding may be present; use defined size.
257  */
258 struct dhcpv6_civic {
259 	uint16_t	d6c_code;
260 	uint16_t	d6c_len;
261 	uint8_t		d6c_what;	/* DHCPV6_CWHAT_* value */
262 	char		d6c_cc[2];		/* Country code; ISO 3166 */
263 };
264 #define	DHCPV6_CIVIC_SIZE	7
265 
266 #define	DHCPV6_CWHAT_SERVER	0	/* Location of server */
267 #define	DHCPV6_CWHAT_NETWORK	1	/* Location of network */
268 #define	DHCPV6_CWHAT_CLIENT	2	/* Location of client */
269 
270 #define	CIVICADDR_LANG	0	/* Language; RFC 2277 */
271 #define	CIVICADDR_A1	1	/* National division (state) */
272 #define	CIVICADDR_A2	2	/* County */
273 #define	CIVICADDR_A3	3	/* City */
274 #define	CIVICADDR_A4	4	/* City division */
275 #define	CIVICADDR_A5	5	/* Neighborhood */
276 #define	CIVICADDR_A6	6	/* Street group */
277 #define	CIVICADDR_PRD	16	/* Leading street direction */
278 #define	CIVICADDR_POD	17	/* Trailing street suffix */
279 #define	CIVICADDR_STS	18	/* Street suffix or type */
280 #define	CIVICADDR_HNO	19	/* House number */
281 #define	CIVICADDR_HNS	20	/* House number suffix */
282 #define	CIVICADDR_LMK	21	/* Landmark */
283 #define	CIVICADDR_LOC	22	/* Additional location information */
284 #define	CIVICADDR_NAM	23	/* Name/occupant */
285 #define	CIVICADDR_PC	24	/* Postal Code/ZIP */
286 #define	CIVICADDR_BLD	25	/* Building */
287 #define	CIVICADDR_UNIT	26	/* Unit/apt/suite */
288 #define	CIVICADDR_FLR	27	/* Floor */
289 #define	CIVICADDR_ROOM	28	/* Room number */
290 #define	CIVICADDR_TYPE	29	/* Place type */
291 #define	CIVICADDR_PCN	30	/* Postal community name */
292 #define	CIVICADDR_POBOX	31	/* Post office box */
293 #define	CIVICADDR_ADDL	32	/* Additional code */
294 #define	CIVICADDR_SEAT	33	/* Seat/desk */
295 #define	CIVICADDR_ROAD	34	/* Primary road or street */
296 #define	CIVICADDR_RSEC	35	/* Road section */
297 #define	CIVICADDR_RBRA	36	/* Road branch */
298 #define	CIVICADDR_RSBR	37	/* Road sub-branch */
299 #define	CIVICADDR_SPRE	38	/* Street name pre-modifier */
300 #define	CIVICADDR_SPOST	39	/* Street name post-modifier */
301 #define	CIVICADDR_SCRIPT 128	/* Script */
302 
303 /*
304  * DHCP Unique Identifier structures.  These represent the fixed portion of the
305  * unique identifier object, and are followed by the variable-length link layer
306  * address or identifier.
307  */
308 struct duid_llt {
309 	uint16_t	dllt_dutype;
310 	uint16_t	dllt_hwtype;
311 	uint32_t	dllt_time;
312 };
313 
314 /* DUID time stamps start on January 1st, 2000 UTC */
315 #define	DUID_TIME_BASE	946684800ul
316 
317 struct duid_en {
318 	uint16_t	den_dutype;
319 	uint16_t	den_entho;
320 	uint16_t	den_entlo;
321 };
322 
323 #define	DHCPV6_GET_ENTNUM(den) \
324 	((ntohs((den)->den_entho) << 16) + ntohs((den)->den_entlo))
325 #define	DHCPV6_SET_ENTNUM(den, val) \
326 	((den)->den_entho = htons((val) >> 16), (den)->den_entlo = htons(val))
327 
328 struct duid_ll {
329 	uint16_t	dll_dutype;
330 	uint16_t	dll_hwtype;
331 };
332 
333 /*
334  * Data types
335  */
336 typedef	struct dhcpv6_message	dhcpv6_message_t;
337 typedef	struct dhcpv6_relay	dhcpv6_relay_t;
338 typedef	struct dhcpv6_option	dhcpv6_option_t;
339 typedef	struct dhcpv6_ia_na	dhcpv6_ia_na_t;
340 typedef	struct dhcpv6_ia_ta	dhcpv6_ia_ta_t;
341 typedef	struct dhcpv6_iaaddr	dhcpv6_iaaddr_t;
342 typedef	struct dhcpv6_auth	dhcpv6_auth_t;
343 typedef	struct dhcpv6_iaprefix	dhcpv6_iaprefix_t;
344 typedef struct dhcpv6_civic	dhcpv6_civic_t;
345 typedef	struct duid_llt		duid_llt_t;
346 typedef	struct duid_en		duid_en_t;
347 typedef	struct duid_ll		duid_ll_t;
348 
349 #ifdef __cplusplus
350 }
351 #endif
352 
353 #endif /* _DHCP6_H */
354