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  // Foxconn added pling 10//07/2010
95#define SOL_MAX_RC_AUTODETECT   3   // Foxconn added pling 10/14/2010
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/* Foxconn added start pling 09/22/2009 */
121#define IANA_IAID		1
122#define IAPD_IAID		11
123/* Foxconn added end pling 09/22/2009 */
124
125typedef enum { IANA, IATA, IAPD} iatype_t;
126
127typedef enum { ACTIVE, RENEW,
128	       REBIND, EXPIRED,
129	       INVALID } state_t;
130/* Internal data structure */
131
132struct duid {
133	u_int8_t duid_len;	/* length */
134	char *duid_id;		/* variable length ID value (must be opaque) */
135};
136
137struct intf_id {
138	u_int16_t intf_len;	/* length */
139	char *intf_id;		/* variable length ID value (must be opaque) */
140};
141
142/* iaid info for the IA_NA */
143struct dhcp6_iaid_info {
144	u_int32_t iaid;
145	u_int32_t renewtime;
146	u_int32_t rebindtime;
147};
148
149/* dhcpv6 addr */
150struct dhcp6_addr {
151	u_int32_t validlifetime;
152	u_int32_t preferlifetime;
153	struct in6_addr addr;
154	u_int8_t plen;
155	iatype_t type;
156	u_int16_t status_code;
157	char *status_msg;
158};
159
160struct dhcp6_lease {
161	TAILQ_ENTRY(dhcp6_lease) link;
162	char hostname[1024];
163	struct in6_addr linklocal;
164	struct dhcp6_addr lease_addr;
165	iatype_t addr_type;
166	state_t state;
167	struct dhcp6_iaidaddr *iaidaddr;
168	time_t start_date;
169	/* address assigned on the interface */
170	struct dhcp6_timer *timer;
171};
172
173struct dhcp6_listval {
174	TAILQ_ENTRY(dhcp6_listval) link;
175
176	union {
177		int uv_num;
178		struct in6_addr uv_addr6;
179		struct dhcp6_addr uv_dhcp6_addr;
180		struct dhcp6_lease uv_dhcp6_lease;
181	} uv;
182};
183
184#define val_num uv.uv_num
185#define val_addr6 uv.uv_addr6
186#define val_dhcp6addr uv.uv_dhcp6_addr
187#define val_dhcp6lease uv.uv_dhcp6_lease
188
189TAILQ_HEAD(dhcp6_list, dhcp6_listval);
190
191typedef enum { DHCP6_LISTVAL_NUM, DHCP6_LISTVAL_ADDR6,
192	       DHCP6_LISTVAL_DHCP6ADDR, DHCP6_LISTVAL_DHCP6LEASE } dhcp6_listval_type_t;
193
194struct domain_list {
195	struct domain_list *next;
196	char name[MAXDNAME];
197};
198
199struct dns_list {
200	struct dhcp6_list addrlist;
201	struct domain_list *domainlist;
202};
203
204/* DHCP6 relay agent base packet format */
205struct dhcp6_relay {
206	u_int8_t dh6_msg_type;
207	u_int8_t dh6_hop_count;
208	struct in6_addr link_addr;
209	struct in6_addr peer_addr;
210	/* options follow */
211} __attribute__ ((__packed__));
212
213
214struct relay_listval {
215	TAILQ_ENTRY(relay_listval) link;
216
217	struct dhcp6_relay relay;
218	struct intf_id *intf_id;
219
220	/* pointer to the Relay Message option in the RELAY-REPL */
221	struct dhcp6opt *option;
222};
223
224TAILQ_HEAD (relay_list, relay_listval);
225
226/* Foxconn added start pling 09/07/2010 */
227/* Currnetly GUI allow 63 chars for user-class. 128 is more than enough */
228#define MAX_USER_CLASS_LEN		128
229/* Foxconn added end pling 09/07/2010 */
230
231struct dhcp6_optinfo {
232	struct duid clientID;	/* DUID */
233	struct duid serverID;	/* DUID */
234	u_int16_t elapsed_time;
235	char   user_class[MAX_USER_CLASS_LEN];	/* Foxconn added pling 09/07/2010 */
236	struct dhcp6_iaid_info iaidinfo;
237	iatype_t type;
238	u_int8_t flags;	/* flags for rapid commit, info_only, temp address */
239	u_int8_t pref;		/* server preference */
240	struct in6_addr server_addr;
241	struct dhcp6_list addr_list; /* assigned ipv6 address list */
242	/* Foxconn added start pling 09/23/2009, to store server assigned prefix */
243	struct dhcp6_list prefix_list; /* assigned prefix list */
244	/* Foxconn added end pling 09/23/2009 */
245	struct dhcp6_list reqopt_list; /*  options in option request */
246	struct dhcp6_list stcode_list; /* status code */
247	struct dns_list dns_list; /* DNS server list */
248	struct dhcp6_list sip_list; /* SIP server list */
249	struct dhcp6_list ntp_list; /* NTP server list */
250	struct relay_list relay_list; /* list of the relays the message
251					 passed through on to the server */
252};
253
254/* DHCP6 base packet format */
255struct dhcp6 {
256	union {
257		u_int8_t m;
258		u_int32_t x;
259	} dh6_msgtypexid;
260	/* options follow */
261} __attribute__ ((__packed__));
262#define dh6_msgtype	dh6_msgtypexid.m
263#define dh6_xid		dh6_msgtypexid.x
264#define DH6_XIDMASK	0x00ffffff
265
266/* options */
267#define DH6OPT_CLIENTID	1
268#define DH6OPT_SERVERID	2
269#define DH6OPT_IA_NA 3
270#define DH6OPT_IA_TA 4
271#define DH6OPT_IADDR 5
272#define DH6OPT_ORO 6
273#define DH6OPT_PREFERENCE 7
274#  define DH6OPT_PREF_UNDEF 0
275#  define DH6OPT_PREF_MAX 255
276#define DH6OPT_ELAPSED_TIME 8
277#define DH6OPT_RELAY_MSG 9
278
279#define DH6OPT_AUTH 11
280#define DH6OPT_UNICAST 12
281#define DH6OPT_STATUS_CODE 13
282
283
284#  define DH6OPT_STCODE_SUCCESS 0
285#  define DH6OPT_STCODE_UNSPECFAIL 1
286#  define DH6OPT_STCODE_NOADDRAVAIL 2
287#  define DH6OPT_STCODE_NOBINDING 3
288#  define DH6OPT_STCODE_NOTONLINK 4
289#  define DH6OPT_STCODE_USEMULTICAST 5
290
291#  define DH6OPT_STCODE_AUTHFAILED 6
292#  define DH6OPT_STCODE_ADDRUNAVAIL 7
293#  define DH6OPT_STCODE_CONFNOMATCH 8
294
295#  define DH6OPT_STCODE_NOPREFIXAVAIL 10
296
297#  define DH6OPT_STCODE_UNDEFINE 0xffff
298
299#define DH6OPT_RAPID_COMMIT 14
300#define DH6OPT_USER_CLASS 15
301#define DH6OPT_VENDOR_CLASS 16
302#define DH6OPT_VENDOR_OPTS 17
303#define DH6OPT_INTERFACE_ID 18
304#define DH6OPT_RECONF_MSG 19
305
306#define DEFAULT_VALID_LIFE_TIME 720000
307#define DEFAULT_PREFERRED_LIFE_TIME 360000
308
309#define DH6OPT_DNS_SERVERS 23
310#define DH6OPT_DOMAIN_LIST 24
311
312#define DH6OPT_IA_PD 25
313#define DH6OPT_IAPREFIX 26
314
315/* Foxconn added start pling 01/25/2010*/
316#define DH6OPT_SIP_SERVERS 22
317#define DH6OPT_NTP_SERVERS 31
318/* Foxconn added end pling 01/25/2010 */
319
320struct dhcp6opt {
321	u_int16_t dh6opt_type;
322	u_int16_t dh6opt_len;
323	/* type-dependent data follows */
324} __attribute__ ((__packed__));
325
326/* DUID type 1 */
327struct dhcp6_duid_type1 {
328	u_int16_t dh6duid1_type;
329	u_int16_t dh6duid1_hwtype;
330	/* Foxconn removed start pling 04/26/2011 */
331	/* Netgear Router Spec requires DUID to be type DUID-LL, not DUID-LLT */
332	/* u_int32_t dh6duid1_time; */
333	/* Foxconn removed end pling 04/26/2011 */
334	/* link-layer address follows */
335} __attribute__ ((__packed__));
336
337/* Prefix Information */
338struct dhcp6_prefix_info {
339	u_int16_t dh6_pi_type;
340	u_int16_t dh6_pi_len;
341	u_int32_t preferlifetime;
342	u_int32_t validlifetime;
343	u_int8_t plen;
344	struct in6_addr prefix;
345} __attribute__ ((__packed__));
346
347/* status code info */
348struct dhcp6_status_info {
349	u_int16_t dh6_status_type;
350	u_int16_t dh6_status_len;
351	u_int16_t dh6_status_code;
352} __attribute__ ((__packed__));
353
354/* IPv6 address info */
355struct dhcp6_addr_info {
356	u_int16_t dh6_ai_type;
357	u_int16_t dh6_ai_len;
358	struct in6_addr addr;
359	u_int32_t preferlifetime;
360	u_int32_t validlifetime;
361/*	u_int8_t plen;
362	struct dhcp6_status_info status;
363*/
364} __attribute__ ((__packed__));
365
366#endif /*__DHCP6_H_DEFINED*/
367