1 /*	$KAME: dhcp6.h,v 1.56 2005/03/20 06:46:09 jinmei Exp $	*/
2 /*
3  * Copyright (C) 1998 and 1999 WIDE Project.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the project nor the names of its contributors
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifndef __DHCP6_H_DEFINED
32 #define __DHCP6_H_DEFINED
33 
34 #ifdef __sun__
35 #define	__P(x)	x
36 typedef uint8_t u_int8_t;
37 #ifndef	U_INT16_T_DEFINED
38 #define	U_INT16_T_DEFINED
39 typedef uint16_t u_int16_t;
40 #endif
41 #ifndef	U_INT32_T_DEFINED
42 #define	U_INT32_T_DEFINED
43 typedef uint32_t u_int32_t;
44 #endif
45 typedef uint64_t u_int64_t;
46 #ifndef CMSG_SPACE
47 #define	CMSG_SPACE(l) \
48 	((unsigned int)_CMSG_HDR_ALIGN(sizeof (struct cmsghdr) + (l)))
49 #endif
50 #ifndef CMSG_LEN
51 #define	CMSG_LEN(l) \
52 	((unsigned int)_CMSG_DATA_ALIGN(sizeof (struct cmsghdr)) + (l))
53 #endif
54 #endif
55 
56 /* Error Values */
57 #define DH6ERR_FAILURE		16
58 #define DH6ERR_AUTHFAIL		17
59 #define DH6ERR_POORLYFORMED	18
60 #define DH6ERR_UNAVAIL		19
61 #define DH6ERR_OPTUNAVAIL	20
62 
63 /* Message type */
64 #define DH6_SOLICIT	1
65 #define DH6_ADVERTISE	2
66 #define DH6_REQUEST	3
67 #define DH6_CONFIRM	4
68 #define DH6_RENEW	5
69 #define DH6_REBIND	6
70 #define DH6_REPLY	7
71 #define DH6_RELEASE	8
72 #define DH6_DECLINE	9
73 #define DH6_RECONFIGURE	10
74 #define DH6_INFORM_REQ	11
75 #define DH6_RELAY_FORW	12
76 #define DH6_RELAY_REPLY	13
77 
78 /* Predefined addresses */
79 #define DH6ADDR_ALLAGENT	"ff02::1:2"
80 #define DH6ADDR_ALLSERVER	"ff05::1:3"
81 #define DH6PORT_DOWNSTREAM	"546"
82 #define DH6PORT_UPSTREAM	"547"
83 
84 /* Protocol constants */
85 
86 /* timer parameters (msec, unless explicitly commented) */
87 #define SOL_MAX_DELAY	1000
88 #define SOL_TIMEOUT	1000
89 #define SOL_MAX_RT	120000
90 #define INF_TIMEOUT	1000
91 #define INF_MAX_RT	120000
92 #define REQ_TIMEOUT	1000
93 #define REQ_MAX_RT	30000
94 #define REQ_MAX_RC	10	/* Max Request retry attempts */
95 #define REN_TIMEOUT	10000	/* 10secs */
96 #define REN_MAX_RT	600000	/* 600secs */
97 #define REB_TIMEOUT	10000	/* 10secs */
98 #define REB_MAX_RT	600000	/* 600secs */
99 #define REL_TIMEOUT	1000	/* 1 sec */
100 #define REL_MAX_RC	5
101 
102 #define DHCP6_DURATION_INFINITE 0xffffffff
103 #define DHCP6_DURATION_MIN 30
104 
105 #define DHCP6_RELAY_MULTICAST_HOPS 32
106 #define DHCP6_RELAY_HOP_COUNT_LIMIT 32
107 
108 #define DHCP6_IRT_DEFAULT 86400	/* 1 day */
109 #define DHCP6_IRT_MINIMUM 600
110 
111 /* DUID: DHCP unique Identifier */
112 struct duid {
113 	size_t duid_len;	/* length */
114 	char *duid_id;		/* variable length ID value (must be opaque) */
115 };
116 
117 struct dhcp6_vbuf {		/* generic variable length buffer */
118 	int dv_len;
119 	caddr_t dv_buf;
120 };
121 
122 /* option information */
123 struct dhcp6_ia {		/* identity association */
124 	u_int32_t iaid;
125 	u_int32_t t1;
126 	u_int32_t t2;
127 };
128 
129 struct dhcp6_prefix {		/* IA_PA */
130 	u_int32_t pltime;
131 	u_int32_t vltime;
132 	struct in6_addr addr;
133 	int plen;
134 };
135 
136 struct dhcp6_statefuladdr {	/* IA_NA */
137 	u_int32_t pltime;
138 	u_int32_t vltime;
139 	struct in6_addr addr;
140 };
141 
142 /* Internal data structure */
143 typedef enum { DHCP6_LISTVAL_NUM = 1,
144 	       DHCP6_LISTVAL_STCODE, DHCP6_LISTVAL_ADDR6,
145 	       DHCP6_LISTVAL_IAPD, DHCP6_LISTVAL_PREFIX6,
146 	       DHCP6_LISTVAL_IANA, DHCP6_LISTVAL_STATEFULADDR6,
147 	       DHCP6_LISTVAL_VBUF
148 } dhcp6_listval_type_t;
149 TAILQ_HEAD(dhcp6_list, dhcp6_listval);
150 struct dhcp6_listval {
151 	TAILQ_ENTRY(dhcp6_listval) link;
152 
153 	dhcp6_listval_type_t type;
154 
155 	union {
156 		int uv_num;
157 		u_int16_t uv_num16;
158 		struct in6_addr uv_addr6;
159 		struct dhcp6_prefix uv_prefix6;
160 		struct dhcp6_statefuladdr uv_statefuladdr6;
161 		struct dhcp6_ia uv_ia;
162 		struct dhcp6_vbuf uv_vbuf;
163 	} uv;
164 
165 	struct dhcp6_list sublist;
166 };
167 #define val_num uv.uv_num
168 #define val_num16 uv.uv_num16
169 #define val_addr6 uv.uv_addr6
170 #define val_ia uv.uv_ia
171 #define val_prefix6 uv.uv_prefix6
172 #define val_statefuladdr6 uv.uv_statefuladdr6
173 #define val_vbuf uv.uv_vbuf
174 
175 struct dhcp6_optinfo {
176 	struct duid clientID;	/* DUID */
177 	struct duid serverID;	/* DUID */
178 
179 	int rapidcommit;	/* bool */
180 	int pref;		/* server preference */
181 	int32_t elapsed_time;	/* elapsed time (from client to server only) */
182 	int64_t refreshtime;	/* info refresh time for stateless options */
183 
184 	struct dhcp6_list iapd_list; /* list of IA_PD */
185 	struct dhcp6_list iana_list; /* list of IA_NA */
186 	struct dhcp6_list reqopt_list; /* options in option request */
187 	struct dhcp6_list stcode_list; /* status code */
188 	struct dhcp6_list sip_list; /* SIP server list */
189 	struct dhcp6_list sipname_list; /* SIP domain list */
190 	struct dhcp6_list dns_list; /* DNS server list */
191 	struct dhcp6_list dnsname_list; /* Domain Search list */
192 	struct dhcp6_list ntp_list; /* NTP server list */
193 	struct dhcp6_list prefix_list; /* prefix list */
194 	struct dhcp6_list nis_list; /* NIS server list */
195 	struct dhcp6_list nisname_list; /* NIS domain list */
196 	struct dhcp6_list nisp_list; /* NIS+ server list */
197 	struct dhcp6_list nispname_list; /* NIS+ domain list */
198 	struct dhcp6_list bcmcs_list; /* BCMC server list */
199 	struct dhcp6_list bcmcsname_list; /* BCMC domain list */
200 
201 	struct dhcp6_vbuf relay_msg; /* relay message */
202 #define relaymsg_len relay_msg.dv_len
203 #define relaymsg_msg relay_msg.dv_buf
204 
205 	struct dhcp6_vbuf ifidopt; /* Interface-id */
206 #define ifidopt_len ifidopt.dv_len
207 #define ifidopt_id ifidopt.dv_buf
208 
209 	u_int authflags;
210 #define DHCP6OPT_AUTHFLAG_NOINFO	0x1
211 	int authproto;
212 	int authalgorithm;
213 	int authrdm;
214 	/* the followings are effective only when NOINFO is unset */
215 	u_int64_t authrd;
216 	union {
217 		struct {
218 			u_int32_t keyid;
219 			struct dhcp6_vbuf realm;
220 			int offset; /* offset to the HMAC field */
221 		} aiu_delayed;
222 		struct {
223 			int type;
224 			int offset; /* offset to the HMAC field */
225 			char val[16]; /* key value */
226 		} aiu_reconfig;
227 	} authinfo;
228 #define delayedauth_keyid authinfo.aiu_delayed.keyid
229 #define delayedauth_realmlen authinfo.aiu_delayed.realm.dv_len
230 #define delayedauth_realmval authinfo.aiu_delayed.realm.dv_buf
231 #define delayedauth_offset authinfo.aiu_delayed.offset
232 #define reconfigauth_type authinfo.aiu_reconfig.type
233 #define reconfigauth_offset authinfo.aiu_reconfig.offset
234 #define reconfigauth_val authinfo.aiu_reconfig.val
235 };
236 
237 /* DHCP6 base packet format */
238 struct dhcp6 {
239 	union {
240 		u_int8_t m;
241 		u_int32_t x;
242 	} dh6_msgtypexid;
243 	/* options follow */
244 } __attribute__ ((__packed__));
245 #define dh6_msgtype	dh6_msgtypexid.m
246 #define dh6_xid		dh6_msgtypexid.x
247 #define DH6_XIDMASK	0x00ffffff
248 
249 /* DHCPv6 relay messages */
250 struct dhcp6_relay {
251 	u_int8_t dh6relay_msgtype;
252 	u_int8_t dh6relay_hcnt;
253 	struct in6_addr dh6relay_linkaddr; /* XXX: badly aligned */
254 	struct in6_addr dh6relay_peeraddr; /* ditto */
255 	/* options follow */
256 } __attribute__ ((__packed__));
257 
258 /* options */
259 #define DH6OPT_CLIENTID	1
260 #define DH6OPT_SERVERID	2
261 #define DH6OPT_IA_NA 3
262 #define DH6OPT_IA_TA 4
263 #define DH6OPT_IAADDR 5
264 #define DH6OPT_ORO 6
265 #define DH6OPT_PREFERENCE 7
266 #  define DH6OPT_PREF_UNDEF -1
267 #  define DH6OPT_PREF_MAX 255
268 #define DH6OPT_ELAPSED_TIME 8
269 #  define DH6OPT_ELAPSED_TIME_UNDEF -1
270 #define DH6OPT_RELAY_MSG 9
271 /* #define DH6OPT_SERVER_MSG 10: deprecated */
272 #define DH6OPT_AUTH 11
273 #  define DH6OPT_AUTH_PROTO_DELAYED 2
274 #  define DH6OPT_AUTH_RRECONFIGURE 3
275 #  define DH6OPT_AUTH_ALG_HMACMD5 1
276 #define DH6OPT_UNICAST 12
277 #define DH6OPT_STATUS_CODE 13
278 #  define DH6OPT_STCODE_SUCCESS 0
279 #  define DH6OPT_STCODE_UNSPECFAIL 1
280 #  define DH6OPT_STCODE_NOADDRSAVAIL 2
281 #  define DH6OPT_STCODE_NOBINDING 3
282 #  define DH6OPT_STCODE_NOTONLINK 4
283 #  define DH6OPT_STCODE_USEMULTICAST 5
284 #  define DH6OPT_STCODE_NOPREFIXAVAIL 6
285 
286 #define DH6OPT_RAPID_COMMIT 14
287 #define DH6OPT_USER_CLASS 15
288 #define DH6OPT_VENDOR_CLASS 16
289 #define DH6OPT_VENDOR_OPTS 17
290 #define DH6OPT_INTERFACE_ID 18
291 #define DH6OPT_RECONF_MSG 19
292 
293 #define DH6OPT_SIP_SERVER_D 21
294 #define DH6OPT_SIP_SERVER_A 22
295 #define DH6OPT_DNS 23
296 #define DH6OPT_DNSNAME 24
297 #define DH6OPT_IA_PD 25
298 #define DH6OPT_IA_PD_PREFIX 26
299 #define DH6OPT_NIS_SERVERS 27
300 #define DH6OPT_NISP_SERVERS 28
301 #define DH6OPT_NIS_DOMAIN_NAME 29
302 #define DH6OPT_NISP_DOMAIN_NAME 30
303 #define DH6OPT_NTP 31
304 #define DH6OPT_REFRESHTIME 32
305  #define DH6OPT_REFRESHTIME_UNDEF -1
306 #define DH6OPT_BCMCS_SERVER_D 33
307 #define DH6OPT_BCMCS_SERVER_A 34
308 #define DH6OPT_GEOCONF_CIVIC 36
309 #define DH6OPT_REMOTE_ID 37
310 #define DH6OPT_SUBSCRIBER_ID 38
311 #define DH6OPT_CLIENT_FQDN 39
312 
313 /* The followings are KAME specific. */
314 
315 struct dhcp6opt {
316 	u_int16_t dh6opt_type;
317 	u_int16_t dh6opt_len;
318 	/* type-dependent data follows */
319 } __attribute__ ((__packed__));
320 
321 /* DUID type 1 */
322 struct dhcp6opt_duid_type1 {
323 	u_int16_t dh6_duid1_type;
324 	u_int16_t dh6_duid1_hwtype;
325 	u_int32_t dh6_duid1_time;
326 	/* link-layer address follows */
327 } __attribute__ ((__packed__));
328 
329 /* Status Code */
330 struct dhcp6opt_stcode {
331 	u_int16_t dh6_stcode_type;
332 	u_int16_t dh6_stcode_len;
333 	u_int16_t dh6_stcode_code;
334 } __attribute__ ((__packed__));
335 
336 /*
337  * General format of Identity Association.
338  * This format applies to Prefix Delegation (IA_PD) and Non-temporary Addresses
339  * (IA_NA)
340  */
341 struct dhcp6opt_ia {
342 	u_int16_t dh6_ia_type;
343 	u_int16_t dh6_ia_len;
344 	u_int32_t dh6_ia_iaid;
345 	u_int32_t dh6_ia_t1;
346 	u_int32_t dh6_ia_t2;
347 	/* sub options follow */
348 } __attribute__ ((__packed__));
349 
350 /* IA Addr */
351 struct dhcp6opt_ia_addr {
352 	u_int16_t dh6_ia_addr_type;
353 	u_int16_t dh6_ia_addr_len;
354 	struct in6_addr dh6_ia_addr_addr;
355 	u_int32_t dh6_ia_addr_preferred_time;
356 	u_int32_t dh6_ia_addr_valid_time;
357 } __attribute__ ((__packed__));
358 
359 /* IA_PD Prefix */
360 struct dhcp6opt_ia_pd_prefix {
361 	u_int16_t dh6_iapd_prefix_type;
362 	u_int16_t dh6_iapd_prefix_len;
363 	u_int32_t dh6_iapd_prefix_preferred_time;
364 	u_int32_t dh6_iapd_prefix_valid_time;
365 	u_int8_t dh6_iapd_prefix_prefix_len;
366 	struct in6_addr dh6_iapd_prefix_prefix_addr;
367 } __attribute__ ((__packed__));
368 
369 /* Authentication */
370 struct dhcp6opt_auth {
371 	u_int16_t dh6_auth_type;
372 	u_int16_t dh6_auth_len;
373 	u_int8_t dh6_auth_proto;
374 	u_int8_t dh6_auth_alg;
375 	u_int8_t dh6_auth_rdm;
376 	u_int8_t dh6_auth_rdinfo[8];
377 	/* authentication information follows */
378 } __attribute__ ((__packed__));
379 
380 enum { DHCP6_AUTHPROTO_UNDEF = -1, DHCP6_AUTHPROTO_DELAYED = 2,
381        DHCP6_AUTHPROTO_RECONFIG = 3 };
382 enum { DHCP6_AUTHALG_UNDEF = -1, DHCP6_AUTHALG_HMACMD5 = 1 };
383 enum { DHCP6_AUTHRDM_UNDEF = -1, DHCP6_AUTHRDM_MONOCOUNTER = 0 };
384 
385 #endif /*__DHCP6_H_DEFINED*/
386