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