1/*	$Id: config.h,v 1.1.1.1 2006/12/04 00:45:21 Exp $	*/
2/*	ported from KAME: config.h,v 1.18 2002/06/14 15:32:55 jinmei Exp */
3
4/*
5 * Copyright (C) 2002 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#define MAX_DEVICE 100
34
35struct hardware {
36	u_int16_t type;
37	u_int8_t len;
38	unsigned char data[6];
39};
40
41struct iaid_table {
42	/* so far we support ethernet cards only */
43	struct hardware  hwaddr;
44	u_int32_t iaid;
45};
46
47struct ra_info {
48	struct ra_info *next;
49	struct in6_addr prefix;
50	int plen;
51	int flags;
52};
53
54struct dhcp6_option {
55	TAILQ_ENTRY(dhcp6_option) link;
56	int type;
57	int len;
58	void *val;
59};
60
61TAILQ_HEAD(dhcp6_option_list, dhcp6_option);
62
63/* per-interface information */
64struct dhcp6_if {
65	struct dhcp6_if *next;
66
67	int outsock;
68
69	/* timer for the interface to sync file every 5 mins*/
70	struct dhcp6_timer *sync_timer;
71#define DHCP6_SYNCFILE_TIME	60
72	/* timer to check interface off->on link to send confirm message*/
73	struct dhcp6_timer *link_timer;
74#define DHCP6_CHECKLINK_TIME	5
75	struct dhcp6_timer *dad_timer;
76#define DHCP6_CHECKDAD_TIME	5
77	/* event queue */
78	TAILQ_HEAD(, dhcp6_event) event_list;
79
80	/* static parameters of the interface */
81	char *ifname;
82	unsigned int ifid;
83	struct ra_info *ralist;
84	struct dns_list dnslist;
85	struct dhcp6_list siplist;
86	struct dhcp6_list ntplist;
87	u_int32_t linkid;	/* to send link-local packets */
88	struct dhcp6_iaid_info iaidinfo;
89
90	u_int16_t ra_flag;
91	u_int16_t link_flag;
92	/* configuration parameters */
93	u_long send_flags;
94	u_long allow_flags;
95
96#define DHCIFF_INFO_ONLY 0x1
97#define DHCIFF_RAPID_COMMIT 0x2
98#define DHCIFF_TEMP_ADDRS 0x4
99#define DHCIFF_PREFIX_DELEGATION 0x8
100#define DHCIFF_UNICAST 0x10
101#define DHCIFF_SOLICIT_ONLY 0x20		// Foxconn added pling 08/26/2009
102#define DHCIFF_IANA_ONLY    0x40		// Foxconn added pling 09/21/2010
103#define DHCIFF_IAPD_ONLY    0x80		// Foxconn added pling 09/21/2010
104
105	struct in6_addr linklocal;
106	int server_pref;	/* server preference (server only) */
107
108	struct dhcp6_list reqopt_list;
109	/* request specific addresses list from client */
110	struct dhcp6_list addr_list;
111	struct dhcp6_list prefix_list;
112	struct dhcp6_option_list option_list;
113	struct dhcp6_serverinfo *current_server;
114	struct dhcp6_serverinfo *servers;
115
116	char user_class[MAX_USER_CLASS_LEN];	// Foxconn added pling 09/07/2010
117};
118
119struct dhcp6_event {
120	TAILQ_ENTRY(dhcp6_event) link;
121
122	struct dhcp6_if *ifp;
123	struct dhcp6_timer *timer;
124
125	struct duid serverid;
126
127	/* internal timer parameters */
128	struct timeval start_time;
129	long retrans;
130	long init_retrans;
131	long max_retrans_cnt;
132	long max_retrans_time;
133	long max_retrans_dur;
134	int timeouts;		/* number of timeouts */
135
136	u_int32_t xid;		/* current transaction ID */
137	int state;
138
139	TAILQ_HEAD(, dhcp6_eventdata) data_list;
140};
141
142typedef enum { DHCP6_DATA_PREFIX, DHCP6_DATA_ADDR } dhcp6_eventdata_t;
143
144struct dhcp6_eventdata {
145	TAILQ_ENTRY(dhcp6_eventdata) link;
146
147	struct dhcp6_event *event;
148	dhcp6_eventdata_t type;
149	void *data;
150};
151
152struct dhcp6_serverinfo {
153	struct dhcp6_serverinfo *next;
154
155	/* option information provided in the advertisement */
156	struct dhcp6_optinfo optinfo;
157	struct in6_addr server_addr;
158	u_int8_t pref;		/* preference */
159	int active;		/* bool; if this server is active or not */
160	/* TODO: remember available information from the server */
161};
162
163/* client status code */
164enum {DHCP6S_INIT, DHCP6S_SOLICIT, DHCP6S_INFOREQ, DHCP6S_REQUEST,
165      DHCP6S_RENEW, DHCP6S_REBIND, DHCP6S_CONFIRM, DHCP6S_DECLINE,
166      DHCP6S_RELEASE, DHCP6S_IDLE};
167
168struct dhcp6_ifconf {
169	struct dhcp6_ifconf *next;
170
171	char *ifname;
172
173	/* configuration flags */
174	u_long send_flags;
175	u_long allow_flags;
176
177	int server_pref;	/* server preference (server only) */
178	struct dhcp6_iaid_info iaidinfo;
179
180	struct dhcp6_list prefix_list;
181	struct dhcp6_list addr_list;
182	struct dhcp6_list reqopt_list;
183
184	struct dhcp6_option_list option_list;
185
186	char user_class[MAX_USER_CLASS_LEN];	// Foxconn added pling 09/07/2010
187};
188
189struct prefix_ifconf {
190	struct prefix_ifconf *next;
191
192	char *ifname;		/* interface name such as eth0 */
193	int sla_len;		/* SLA ID length in bits */
194	u_int32_t sla_id;	/* need more than 32bits? */
195	int ifid_len;		/* interface ID length in bits */
196	int ifid_type;		/* EUI-64 and manual (unused?) */
197	char ifid[16];		/* Interface ID, up to 128bits */
198};
199#define IFID_LEN_DEFAULT 64
200#define SLA_LEN_DEFAULT 16
201
202/* per-host configuration */
203struct host_conf {
204	struct host_conf *next;
205
206	char *name;		/* host name to identify the host */
207	struct duid duid;	/* DUID for the host */
208	struct dhcp6_iaid_info iaidinfo;
209	struct in6_addr linklocal;
210	/* delegated prefixes for the host: */
211	struct dhcp6_list prefix_list;
212
213	/* bindings of delegated prefixes */
214	struct dhcp6_list prefix_binding_list;
215
216	struct dhcp6_list addr_list;
217	struct dhcp6_list addr_binding_list;
218};
219
220/* structures and definitions used in the config file parser */
221struct cf_namelist {
222	struct cf_namelist *next;
223	char *name;
224	int line;		/* the line number of the config file */
225	struct cf_list *params;
226};
227
228struct cf_list {
229	struct cf_list *next;
230	struct cf_list *tail;
231	int type;
232	int line;		/* the line number of the config file */
233
234	/* type dependent values: */
235	long long num;
236	struct cf_list *list;
237	void *ptr;
238};
239
240/* Some systems define thes in in.h */
241#ifndef IN6_IS_ADDR_UNSPECIFIED
242#define IN6_IS_ADDR_UNSPECIFIED(a) \
243	(((__const u_int32_t *) (a))[0] == 0				\
244	 && ((__const u_int32_t *) (a))[1] == 0				\
245	 && ((__const u_int32_t *) (a))[2] == 0				\
246	 && ((__const u_int32_t *) (a))[3] == 0)
247#endif
248
249#ifndef IN6_IS_ADDR_LOOPBACK
250#define IN6_IS_ADDR_LOOPBACK(a) \
251	(((__const u_int32_t *) (a))[0] == 0				\
252	 && ((__const u_int32_t *) (a))[1] == 0				\
253	 && ((__const u_int32_t *) (a))[2] == 0				\
254	 && ((__const u_int32_t *) (a))[3] == htonl (1))
255#endif
256
257#ifndef IN6_IS_ADDR_MULTICAST
258#define IN6_IS_ADDR_MULTICAST(a) (((__const u_int8_t *) (a))[0] == 0xff)
259#endif
260
261#ifndef IN6_IS_ADDR_LINKLOCAL
262#define IN6_IS_ADDR_LINKLOCAL(a) \
263	((((__const u_int32_t *) (a))[0] & htonl (0xffc00000))		\
264	 == htonl (0xfe800000))
265#endif
266
267#ifndef IN6_IS_ADDR_SITELOCAL
268#define IN6_IS_ADDR_SITELOCAL(a) \
269	((((__const u_int32_t *) (a))[0] & htonl (0xffc00000))		\
270	 == htonl (0xfec00000))
271#endif
272
273#ifndef IN6_ARE_ADDR_EQUAL
274#define IN6_ARE_ADDR_EQUAL(a,b) \
275	((((__const u_int32_t *) (a))[0] == ((__const u_int32_t *) (b))[0])     \
276	 && (((__const u_int32_t *) (a))[1] == ((__const u_int32_t *) (b))[1])  \
277	 && (((__const u_int32_t *) (a))[2] == ((__const u_int32_t *) (b))[2])  \
278	 && (((__const u_int32_t *) (a))[3] == ((__const u_int32_t *) (b))[3]))
279#endif
280
281#ifndef IN6_IS_ADDR_RESERVED
282#define IN6_IS_ADDR_RESERVED(a) \
283	IN6_IS_ADDR_MULTICAST(a) || IN6_IS_ADDR_LOOPBACK(a) 		\
284	|| IN6_IS_ADDR_UNSPECIFIED(a)
285#endif
286/* ANYCAST later */
287
288enum {DECL_SEND, DECL_ALLOW, DECL_INFO_ONLY, DECL_TEMP_ADDR, DECL_REQUEST, DECL_DUID, DECL_SOLICIT_ONLY,
289      DECL_IANA_ONLY, DECL_IAPD_ONLY,
290      DECL_PREFIX, DECL_PREFERENCE, DECL_IAID, DECL_RENEWTIME, DECL_REBINDTIME,
291      DECL_ADDRESS, DECL_LINKLOCAL, DECL_PREFIX_INFO, DECL_PREFIX_REQ, DECL_PREFIX_DELEGATION_INTERFACE, DECL_USER_CLASS,
292      DECL_XID_SOL, DECL_XID_REQ, DECL_DUID_TIME,
293      DHCPOPT_PREFIX_DELEGATION, IFPARAM_SLA_ID, IFPARAM_SLA_LEN,
294      DHCPOPT_RAPID_COMMIT,
295      DHCPOPT_DNS, DHCPOPT_DOMAIN_LIST, DHCPOPT_SIP, DHCPOPT_NTP, ADDRESS_LIST_ENT };
296
297typedef enum {DHCP6_MODE_SERVER, DHCP6_MODE_CLIENT, DHCP6_MODE_RELAY }
298dhcp6_mode_t;
299
300extern const dhcp6_mode_t dhcp6_mode;
301extern struct cf_list *cf_dns_list;
302extern const char *configfilename;
303
304extern struct dhcp6_if *dhcp6_if;
305extern struct dhcp6_ifconf *dhcp6_iflist;
306extern struct prefix_ifconf *prefix_ifconflist;
307extern struct dns_list dnslist;
308extern struct dhcp6_list siplist;
309extern struct dhcp6_list ntplist;
310
311extern int configure_interface (const struct cf_namelist *);
312extern int configure_prefix_interface (struct cf_namelist *);
313extern int configure_host (const struct cf_namelist *);
314extern int configure_global_option (void);
315extern void configure_cleanup (void);
316extern void configure_commit (void);
317extern int cfparse (const char *);
318extern int resolv_parse (struct dns_list *);
319extern int get_if_rainfo(struct dhcp6_if *ifp);
320
321extern void *get_if_option( struct dhcp6_option_list *, int);
322