summaryrefslogtreecommitdiff
path: root/usr/src/cmd/cmd-inet/usr.sbin/ipqosconf/ipqosconf.h
blob: 38172d33785bb96f55daf0f4ee0fb755427cf871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef	_IPQOS_CONF_H
#define	_IPQOS_CONF_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#include <sys/stat.h>
#include <sys/types.h>
#include <sys/nvpair.h>

#ifdef __cplusplus
extern "C" {
#endif

/* debug level bits */
#define	L0	0x01
#define	L1	0x02
#define	L2	0x04
#define	DIFF	0x08
#define	KRET	0x10
#define	APPLY	0x20
#define	MHME	0x40
#define	RBK	0x80

/* directory for types files */
#define	TYPES_FILE_DIR		"/usr/lib/ipqosconf/"

/* location of lock file */
#define	IPQOS_CONF_LOCK_FILE	"/var/run/ipqosconf.lock"

/* location of startup config file */
#define	IPQOS_CONF_INIT_PATH	"/etc/inet/ipqosinit.conf"

/* ipqosconf commands */

#define	IPQOS_CONF_APPLY	1
#define	IPQOS_CONF_VIEW		2
#define	IPQOS_CONF_COMMIT	3
#define	IPQOS_CONF_FLUSH	4

/* print ntabs to stream fp */

#define	PRINT_TABS(fp, ntabs)\
{\
	int x;\
	for (x = 0; x < ntabs; x++)\
		(void) fprintf(fp, "\t");\
}

/* having to define this as ip6.h version in _KERNEL guard */
#ifndef	V4_PART_OF_V6
#define	V4_PART_OF_V6(v6)	v6._S6_un._S6_u32[3]
#endif

/*
 * given pointer cp advance it to the first non-space character.
 */
#define	SKIPWS(cp)	while (isspace(*cp) && (*cp != '\0')) cp++

/* extract the v4 and v6 bits of the ip_version enumeration from the filter */
#define	VERSION_IS_V4(flt)	((flt)->ip_versions & 0x01)
#define	VERSION_IS_V6(flt)	((flt)->ip_versions & 0x02)

/* retrieve short name from a module.name nvpair name */
#define	SHORT_NAME(longnme)	(strchr(longnme, '.') + 1)

/* latest version of cfg file supported (1.0) */
#define	IPQOS_CUR_FMT_MAJOR_VER	1
#define	IPQOS_CUR_FMT_MINOR_VER	0

/* length of string buffer used for storing an integer as a string */
#define	IPQOS_INT_STR_LEN	15

/* length of line buffer used to read types file */
#define	IPQOS_CONF_TYPE_LINE_LEN	1024

/* length of buffer used to store name of type when reading types file */
#define	IPQOS_CONF_TYPE_LEN	24

/* max length of value string in types file */
#define	IPQOS_VALST_MAXLEN 100

/* initial size of line buffer used by readtoken */
#define	IPQOS_CONF_LINEBUF_SZ	150

/* length of class/filter/action names */
#define	IPQOS_CONF_NAME_LEN	24

/* length of module names */
#define	IPQOS_CONF_MOD_NAME_LEN	10

/* IPQOS_CONF_NAME_LEN + IPQOS_CONF_MOD_NAME_LEN */
/* must be a numeric literal for use in scanf() format string */
#define	IPQOS_CONF_PNAME_LEN	34

/* length of buffer used to construct msgs for printing */
#define	IPQOS_MSG_BUF_SZ	200
/*
 * Define CURL here so that while you are reading
 * the code, it does not affect "vi" in pattern
 * matching.
 */
#define	CURL_BEGIN		'{'
#define	CURL_END		'}'

/* internal return codes */
#define	IPQOS_CONF_SUCCESS	0
#define	IPQOS_CONF_ERR		1
#define	IPQOS_CONF_RECOVER_ERR	2
#define	IPQOS_CONF_CURL_END	3
#define	IPQOS_CONF_CURL_BEGIN	4
#define	IPQOS_CONF_EOF		5
#define	IPQOS_CONF_NO_VER_STR	6

/* special tokens in config file */
#define	IPQOS_CONF_IP_VERSION_STR	"ip_version"
#define	IPQOS_CONF_NEXT_ACTION_STR	"next_action"
#define	IPQOS_CONF_NAME_STR 		"name"
#define	IPQOS_CONF_MODULE_STR 		"module"
#define	IPQOS_CONF_FILTER_STR 		"filter"
#define	IPQOS_CONF_ACTION_STR 		"action"
#define	IPQOS_CONF_CLASS_STR 		"class"
#define	IPQOS_CONF_PARAMS_STR 		"params"
#define	IPQOS_CONF_NEXT_STR		"next"
#define	IPQOS_CONF_STATS_ENABLE_STR	"enable_stats"
#define	IPQOS_CONF_GLOBAL_STATS_STR	"global_stats"
#define	IPQOS_CONF_DROP_STR		"drop"
#define	IPQOS_CONF_CONT_STR		"continue"
#define	IPQOS_CONF_DEFER_STR		"defer"
#define	IPQOS_CONF_TRUE_STR		"true"
#define	IPQOS_CONF_FALSE_STR		"false"
#define	IPQOS_FMT_VERSION_STR		"fmt_version"
#define	IPQOS_IFNAME_STR		"if_name"
#define	IPQOS_PLACE_PRM_STR		IPQOS_CONF_PARAMS_STR
#define	IPQOS_PLACE_FILTER_STR		IPQOS_CONF_FILTER_STR
#define	IPQOS_PLACE_MAP_STR		"map"

/* special tokens in types file */
#define	IPQOS_CONF_PERM_FILTER_MK	"#PERM_FILTER"
#define	IPQOS_CONF_PERM_CLASS_MK	"#PERM_CLASS"
#define	IPQOS_FMT_STR			"fmt_version"
#define	IPQOS_MOD_STR			"mod_version"


/* nvlist parameters */
#define	IPQOS_CONF_IP_VERSION		"ipgpc.ip_version"

/* name lookup errors returned from domultihome() */
#define	IPQOS_LOOKUP_RETRY	1
#define	IPQOS_LOOKUP_FAIL	2

/*
 * used in calls to ipp_action_info() to encapuslate both an action and
 * an ipqosconf internal return code.
 */
typedef struct ipqos_actinfo_prm_s {
	struct ipqos_conf_action_s *action;
	int intl_ret;
} ipqos_actinfo_prm_t;

/*
 * skeletal list element struct used in manipulating lists of more complex
 * structures.
 */
typedef struct ipqos_list_el_s {
	struct ipqos_list_el_s *next;
} ipqos_list_el_t;

typedef struct str_str {
	char *s1;
	char *s2;
} str_str_t;

typedef struct str_val {
	char *string;
	int value;
} str_val_t;

typedef struct str_val_nd {
	struct str_val sv;
	struct str_val_nd *next;
} str_val_nd_t;

/* type of msg to be printed by ipqos_msg */
enum msg_type { MT_ERROR, MT_WARNING, MT_LOG, MT_ENOSTR };

/* enum for allowable parameter types */

typedef enum ipqos_nvtype_e {
IPQOS_DATA_TYPE_UINT8,
IPQOS_DATA_TYPE_INT16,
IPQOS_DATA_TYPE_UINT16,
IPQOS_DATA_TYPE_INT32,
IPQOS_DATA_TYPE_UINT32,
IPQOS_DATA_TYPE_BOOLEAN,
IPQOS_DATA_TYPE_STRING,
IPQOS_DATA_TYPE_ACTION,
IPQOS_DATA_TYPE_ADDRESS,
IPQOS_DATA_TYPE_PORT,
IPQOS_DATA_TYPE_PROTO,
IPQOS_DATA_TYPE_ENUM,
IPQOS_DATA_TYPE_IFNAME,
IPQOS_DATA_TYPE_M_INDEX,
IPQOS_DATA_TYPE_INT_ARRAY,
IPQOS_DATA_TYPE_USER,
IPQOS_DATA_TYPE_ADDRESS_MASK,
IPQOS_DATA_TYPE_IFINDEX
} ipqos_nvtype_t;

/*
 * passed to readnvpair to indicate which special meanings for nv names
 * to use.
 */
typedef enum place_e {
PL_ACTION, PL_FILTER, PL_CLASS, PL_PARAMS, PL_MAP, PL_ANY} place_t;


/* classifier filter representation */

typedef struct ipqos_conf_filter_s {
	struct ipqos_conf_filter_s *next;
	char name[IPQOS_CONF_NAME_LEN];
	char class_name[IPQOS_CONF_NAME_LEN];
	nvlist_t *nvlist;
	boolean_t new;
	boolean_t modified;
	boolean_t cr_mod;
	boolean_t todel;
	boolean_t deleted;
	uint32_t originator;
	char *src_nd_name;
	char *dst_nd_name;
	int instance;
	uint32_t lineno;
	uint32_t ip_versions;
	int nlerr;
} ipqos_conf_filter_t;


/*
 * action reference - used to store information and reference an action struct.
 */

typedef struct ipqos_conf_act_ref_s {
	struct ipqos_conf_act_ref_s *next;
	struct ipqos_conf_act_ref_s *prev;
	char name[IPQOS_CONF_NAME_LEN];
	char field[IPQOS_CONF_PNAME_LEN];
	struct ipqos_conf_action_s *action;
	nvlist_t *nvlist;
} ipqos_conf_act_ref_t;


/* classifier class representation */

typedef struct ipqos_conf_class_s {
	struct ipqos_conf_class_s *next;
	char name[IPQOS_CONF_NAME_LEN];
	nvlist_t *nvlist;
	ipqos_conf_act_ref_t *alist;
	boolean_t modified;
	boolean_t new;
	boolean_t cr_mod;
	boolean_t todel;
	boolean_t deleted;
	boolean_t stats_enable;
	uint32_t originator;
	uint32_t lineno;
} ipqos_conf_class_t;

/* action parameters representation */

typedef struct ipqos_conf_params_s {
	struct ipqos_conf_params_s *next;
	ipqos_conf_act_ref_t *actions;
	nvlist_t *nvlist;
	boolean_t modified;
	boolean_t stats_enable;
	uint32_t originator;
	uint32_t lineno;
	boolean_t cr_mod;
} ipqos_conf_params_t;


/* signifys which stage of configuration application has just past */
enum visit {ADD_VISITED = 1, MOD_VISITED, REM_VISITED, INCYCLE_VISITED};

/*
 * action representation, with parameters, and lists of filters and classes
 * if classifier action.
 */
typedef struct ipqos_conf_action_s {
	struct ipqos_conf_action_s *next;
	char name[IPQOS_CONF_NAME_LEN];
	char module[IPQOS_CONF_NAME_LEN];
	ipqos_conf_filter_t *filters;
	ipqos_conf_class_t *classes;
	ipqos_conf_params_t *params;
	nvlist_t *nvlist;
	boolean_t todel;
	boolean_t deleted;
	boolean_t new;
	boolean_t modified;
	boolean_t cr_mod;
	ipqos_conf_act_ref_t *dependencies;
	enum visit visited;
	uint32_t lineno;
	ipqos_conf_filter_t *retry_filters;
	char **perm_classes;
	int num_perm_classes;
	int module_version;
} ipqos_conf_action_t;


#ifdef __cplusplus
}
#endif

#endif /* _IPQOS_CONF_H */