1/*	$Id: dhcp6.h,v 1.1.1.1 2006/12/04 00:45:22 Exp $	*/
2/*	ported from KAME: dhcp6.h,v 1.32 2002/07/04 15:03:19 jinmei Exp	*/
3
4/*
5 * Copyright (C) 1998 and 1999 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 *    may be used to endorse or promote products derived from this software
18 *    without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32/*
33 * draft-ietf-dhc-dhcpv6-26
34 */
35
36#ifndef __DHCP6_H_DEFINED
37#define __DHCP6_H_DEFINED
38
39/* Error Values */
40#define DH6ERR_FAILURE		16
41#define DH6ERR_AUTHFAIL		17
42#define DH6ERR_POORLYFORMED	18
43#define DH6ERR_UNAVAIL		19
44#define DH6ERR_OPTUNAVAIL	20
45
46/* Message type */
47#define DH6_SOLICIT	1
48#define DH6_ADVERTISE	2
49#define DH6_REQUEST	3
50#define DH6_CONFIRM	4
51#define DH6_RENEW	5
52#define DH6_REBIND	6
53#define DH6_REPLY	7
54#define DH6_RELEASE	8
55#define DH6_DECLINE	9
56#define DH6_RECONFIGURE	10
57#define DH6_INFORM_REQ	11
58#define DH6_RELAY_FORW	12
59#define DH6_RELAY_REPL	13
60
61/* Predefined addresses */
62#define DH6ADDR_ALLAGENT	"ff02::1:2"
63#define DH6ADDR_ALLSERVER	"ff05::1:3"
64#define DH6PORT_DOWNSTREAM	"546"
65#define DH6PORT_UPSTREAM	"547"
66
67/* Protocol constants */
68
69/* timer parameters (msec, unless explicitly commented) */
70#define MIN_SOL_DELAY	500
71#define MAX_SOL_DELAY	1000
72#define SOL_TIMEOUT	1000
73#define SOL_MAX_RT	120000
74#define INF_TIMEOUT	1000
75#define INF_MAX_DELAY	1000
76#define INF_MAX_RT	120000
77#define REQ_TIMEOUT	1000
78#define REQ_MAX_RT	30000
79#define REQ_MAX_RC	10	/* Max Request retry attempts */
80#define REN_TIMEOUT	10000	/* 10secs */
81#define REN_MAX_RT	600000	/* 600secs */
82#define REB_TIMEOUT	10000	/* 10secs */
83#define REB_MAX_RT	600000	/* 600secs */
84#define DEC_TIMEOUT	1000
85#define DEC_MAX_RC	5
86#define REL_TIMEOUT	1000
87#define REL_MAX_RC	5
88#define REC_TIMEOUT	2000
89#define REC_MAX_RC	8
90#define CNF_TIMEOUT	1000
91#define CNF_MAX_RD	10000
92#define CNF_MAX_RT	4000
93
94#define REQ_MAX_RC_NOTONLINK 3
95#define SOL_MAX_RC_AUTODETECT   3
96
97#define DHCP6_DURATITION_INFINITE 0xffffffff
98#define DHCP6_ELAPSEDTIME_MAX	0xffff
99
100#define IF_RA_OTHERCONF 0x80
101#define IF_RA_MANAGED   0x40
102#define RTM_F_PREFIX	0x800
103
104#ifndef MAXDNAME
105#define MAXDNAME 255
106#endif
107#define MAXDN 100
108
109#define RESOLV_CONF_FILE "/tmp/resolv.conf"
110#define RESOLV_CONF_BAK_FILE "/tmp/resolv.conf.dhcpv6.bak"
111#define RESOLV_CONF_DHCPV6_FILE "/tmp/resolv.conf.dhcpv6"
112char resolv_dhcpv6_file[254];
113
114#define RADVD_CONF_FILE "/etc/radvd.conf"
115#define RADVD_CONF_BAK_FILE "/etc/radvd.conf.dhcpv6.bak"
116#define RADVD_CONF_DHCPV6_FILE "/etc/radvd.conf.dhcpv6"
117char radvd_dhcpv6_file[254];
118
119
120#define IANA_IAID		1
121#define IAPD_IAID		11
122
123typedef enum { IANA, IATA, IAPD} iatype_t;
124
125typedef enum { ACTIVE, RENEW,
126	       REBIND, EXPIRED,
127	       INVALID } state_t;
128/* Internal data structure */
129
130struct duid {
131	u_int8_t duid_len;	/* length */
132	char *duid_id;		/* variable length ID value (must be opaque) */
133};
134
135struct intf_id {
136	u_int16_t intf_len;	/* length */
137	char *intf_id;		/* variable length ID value (must be opaque) */
138};
139
140/* iaid info for the IA_NA */
141struct dhcp6_iaid_info {
142	u_int32_t iaid;
143	u_int32_t renewtime;
144	u_int32_t rebindtime;
145};
146
147/* dhcpv6 addr */
148struct dhcp6_addr {
149	u_int32_t validlifetime;
150	u_int32_t preferlifetime;
151	struct in6_addr addr;
152	u_int8_t plen;
153	iatype_t type;
154	u_int16_t status_code;
155	char *status_msg;
156};
157
158struct dhcp6_lease {
159	TAILQ_ENTRY(dhcp6_lease) link;
160	char hostname[1024];
161	struct in6_addr linklocal;
162	struct dhcp6_addr lease_addr;
163	iatype_t addr_type;
164	state_t state;
165	struct dhcp6_iaidaddr *iaidaddr;
166	time_t start_date;
167	/* address assigned on the interface */
168	struct dhcp6_timer *timer;
169};
170
171struct dhcp6_listval {
172	TAILQ_ENTRY(dhcp6_listval) link;
173
174	union {
175		int uv_num;
176		struct in6_addr uv_addr6;
177		struct dhcp6_addr uv_dhcp6_addr;
178		struct dhcp6_lease uv_dhcp6_lease;
179	} uv;
180};
181
182#define val_num uv.uv_num
183#define val_addr6 uv.uv_addr6
184#define val_dhcp6addr uv.uv_dhcp6_addr
185#define val_dhcp6lease uv.uv_dhcp6_lease
186
187TAILQ_HEAD(dhcp6_list, dhcp6_listval);
188
189typedef enum { DHCP6_LISTVAL_NUM, DHCP6_LISTVAL_ADDR6,
190	       DHCP6_LISTVAL_DHCP6ADDR, DHCP6_LISTVAL_DHCP6LEASE } dhcp6_listval_type_t;
191
192struct domain_list {
193	struct domain_list *next;
194	char name[MAXDNAME];
195};
196
197struct dns_list {
198	struct dhcp6_list addrlist;
199	struct domain_list *domainlist;
200};
201
202/* DHCP6 relay agent base packet format */
203struct dhcp6_relay {
204	u_int8_t dh6_msg_type;
205	u_int8_t dh6_hop_count;
206	struct in6_addr link_addr;
207	struct in6_addr peer_addr;
208	/* options follow */
209} __attribute__ ((__packed__));
210
211
212struct relay_listval {
213	TAILQ_ENTRY(relay_listval) link;
214
215	struct dhcp6_relay relay;
216	struct intf_id *intf_id;
217
218	/* pointer to the Relay Message option in the RELAY-REPL */
219	struct dhcp6opt *option;
220};
221
222TAILQ_HEAD (relay_list, relay_listval);
223
224/* Currnetly GUI allow 63 chars for user-class. 128 is more than enough */
225#define MAX_USER_CLASS_LEN		128
226
227struct dhcp6_optinfo {
228	struct duid clientID;	/* DUID */
229	struct duid serverID;	/* DUID */
230	u_int16_t elapsed_time;
231	char   user_class[MAX_USER_CLASS_LEN];
232	struct dhcp6_iaid_info iaidinfo;
233	iatype_t type;
234	u_int8_t flags;	/* flags for rapid commit, info_only, temp address */
235	u_int8_t pref;		/* server preference */
236	struct in6_addr server_addr;
237	struct dhcp6_list addr_list; /* assigned ipv6 address list */
238	struct dhcp6_list prefix_list; /* assigned prefix list */
239	struct dhcp6_list reqopt_list; /*  options in option request */
240	struct dhcp6_list stcode_list; /* status code */
241	struct dns_list dns_list; /* DNS server list */
242	struct dhcp6_list sip_list; /* SIP server list */
243	struct dhcp6_list ntp_list; /* NTP server list */
244	struct relay_list relay_list; /* list of the relays the message
245					 passed through on to the server */
246};
247
248/* DHCP6 base packet format */
249struct dhcp6 {
250	union {
251		u_int8_t m;
252		u_int32_t x;
253	} dh6_msgtypexid;
254	/* options follow */
255} __attribute__ ((__packed__));
256#define dh6_msgtype	dh6_msgtypexid.m
257#define dh6_xid		dh6_msgtypexid.x
258#define DH6_XIDMASK	0x00ffffff
259
260/* options */
261#define DH6OPT_CLIENTID	1
262#define DH6OPT_SERVERID	2
263#define DH6OPT_IA_NA 3
264#define DH6OPT_IA_TA 4
265#define DH6OPT_IADDR 5
266#define DH6OPT_ORO 6
267#define DH6OPT_PREFERENCE 7
268#  define DH6OPT_PREF_UNDEF 0
269#  define DH6OPT_PREF_MAX 255
270#define DH6OPT_ELAPSED_TIME 8
271#define DH6OPT_RELAY_MSG 9
272
273#define DH6OPT_AUTH 11
274#define DH6OPT_UNICAST 12
275#define DH6OPT_STATUS_CODE 13
276
277
278#  define DH6OPT_STCODE_SUCCESS 0
279#  define DH6OPT_STCODE_UNSPECFAIL 1
280#  define DH6OPT_STCODE_NOADDRAVAIL 2
281#  define DH6OPT_STCODE_NOBINDING 3
282#  define DH6OPT_STCODE_NOTONLINK 4
283#  define DH6OPT_STCODE_USEMULTICAST 5
284
285#  define DH6OPT_STCODE_AUTHFAILED 6
286#  define DH6OPT_STCODE_ADDRUNAVAIL 7
287#  define DH6OPT_STCODE_CONFNOMATCH 8
288
289#  define DH6OPT_STCODE_NOPREFIXAVAIL 10
290
291#  define DH6OPT_STCODE_UNDEFINE 0xffff
292
293#define DH6OPT_RAPID_COMMIT 14
294#define DH6OPT_USER_CLASS 15
295#define DH6OPT_VENDOR_CLASS 16
296#define DH6OPT_VENDOR_OPTS 17
297#define DH6OPT_INTERFACE_ID 18
298#define DH6OPT_RECONF_MSG 19
299
300#define DEFAULT_VALID_LIFE_TIME 720000
301#define DEFAULT_PREFERRED_LIFE_TIME 360000
302
303#define DH6OPT_DNS_SERVERS 23
304#define DH6OPT_DOMAIN_LIST 24
305
306#define DH6OPT_IA_PD 25
307#define DH6OPT_IAPREFIX 26
308
309#define DH6OPT_SIP_SERVERS 22
310#define DH6OPT_NTP_SERVERS 31
311
312struct dhcp6opt {
313	u_int16_t dh6opt_type;
314	u_int16_t dh6opt_len;
315	/* type-dependent data follows */
316} __attribute__ ((__packed__));
317
318/* DUID type 1 */
319struct dhcp6_duid_type1 {
320	u_int16_t dh6duid1_type;
321	u_int16_t dh6duid1_hwtype;
322	/* Netgear Router Spec requires DUID to be type DUID-LL, not DUID-LLT */
323	/* u_int32_t dh6duid1_time; */
324	/* link-layer address follows */
325} __attribute__ ((__packed__));
326
327/* Prefix Information */
328struct dhcp6_prefix_info {
329	u_int16_t dh6_pi_type;
330	u_int16_t dh6_pi_len;
331	u_int32_t preferlifetime;
332	u_int32_t validlifetime;
333	u_int8_t plen;
334	struct in6_addr prefix;
335} __attribute__ ((__packed__));
336
337/* status code info */
338struct dhcp6_status_info {
339	u_int16_t dh6_status_type;
340	u_int16_t dh6_status_len;
341	u_int16_t dh6_status_code;
342} __attribute__ ((__packed__));
343
344/* IPv6 address info */
345struct dhcp6_addr_info {
346	u_int16_t dh6_ai_type;
347	u_int16_t dh6_ai_len;
348	struct in6_addr addr;
349	u_int32_t preferlifetime;
350	u_int32_t validlifetime;
351/*	u_int8_t plen;
352	struct dhcp6_status_info status;
353*/
354} __attribute__ ((__packed__));
355
356#endif /*__DHCP6_H_DEFINED*/
357