xref: /titanic_52/usr/src/cmd/cmd-inet/usr.sbin/ipqosconf/ipqosconf.h (revision 6029a2d88c01674debfd7c2e16c941a97302b739)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_IPQOS_CONF_H
28 #define	_IPQOS_CONF_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/stat.h>
33 #include <sys/types.h>
34 #include <sys/nvpair.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /* debug level bits */
41 #define	L0	0x01
42 #define	L1	0x02
43 #define	L2	0x04
44 #define	DIFF	0x08
45 #define	KRET	0x10
46 #define	APPLY	0x20
47 #define	MHME	0x40
48 #define	RBK	0x80
49 
50 /* directory for types files */
51 #define	TYPES_FILE_DIR		"/usr/lib/ipqosconf/"
52 
53 /* location of lock file */
54 #define	IPQOS_CONF_LOCK_FILE	"/var/run/ipqosconf.lock"
55 
56 /* location of startup config file */
57 #define	IPQOS_CONF_INIT_PATH	"/etc/inet/ipqosinit.conf"
58 
59 /* ipqosconf commands */
60 
61 #define	IPQOS_CONF_APPLY	1
62 #define	IPQOS_CONF_VIEW		2
63 #define	IPQOS_CONF_COMMIT	3
64 #define	IPQOS_CONF_FLUSH	4
65 
66 /* print ntabs to stream fp */
67 
68 #define	PRINT_TABS(fp, ntabs)\
69 {\
70 	int x;\
71 	for (x = 0; x < ntabs; x++)\
72 		(void) fprintf(fp, "\t");\
73 }
74 
75 /* having to define this as ip6.h version in _KERNEL guard */
76 #ifndef	V4_PART_OF_V6
77 #define	V4_PART_OF_V6(v6)	v6._S6_un._S6_u32[3]
78 #endif
79 
80 /*
81  * given pointer cp advance it to the first non-space character.
82  */
83 #define	SKIPWS(cp)	while (isspace(*cp) && (*cp != '\0')) cp++
84 
85 /* extract the v4 and v6 bits of the ip_version enumeration from the filter */
86 #define	VERSION_IS_V4(flt)	((flt)->ip_versions & 0x01)
87 #define	VERSION_IS_V6(flt)	((flt)->ip_versions & 0x02)
88 
89 /* retrieve short name from a module.name nvpair name */
90 #define	SHORT_NAME(longnme)	(strchr(longnme, '.') + 1)
91 
92 /* latest version of cfg file supported (1.0) */
93 #define	IPQOS_CUR_FMT_MAJOR_VER	1
94 #define	IPQOS_CUR_FMT_MINOR_VER	0
95 
96 /* length of string buffer used for storing an integer as a string */
97 #define	IPQOS_INT_STR_LEN	15
98 
99 /* length of line buffer used to read types file */
100 #define	IPQOS_CONF_TYPE_LINE_LEN	1024
101 
102 /* length of buffer used to store name of type when reading types file */
103 #define	IPQOS_CONF_TYPE_LEN	24
104 
105 /* max length of value string in types file */
106 #define	IPQOS_VALST_MAXLEN 100
107 
108 /* initial size of line buffer used by readtoken */
109 #define	IPQOS_CONF_LINEBUF_SZ	150
110 
111 /* length of class/filter/action names */
112 #define	IPQOS_CONF_NAME_LEN	24
113 
114 /* length of module names */
115 #define	IPQOS_CONF_MOD_NAME_LEN	10
116 
117 /* IPQOS_CONF_NAME_LEN + IPQOS_CONF_MOD_NAME_LEN */
118 /* must be a numeric literal for use in scanf() format string */
119 #define	IPQOS_CONF_PNAME_LEN	34
120 
121 /* length of buffer used to construct msgs for printing */
122 #define	IPQOS_MSG_BUF_SZ	200
123 /*
124  * Define CURL here so that while you are reading
125  * the code, it does not affect "vi" in pattern
126  * matching.
127  */
128 #define	CURL_BEGIN		'{'
129 #define	CURL_END		'}'
130 
131 /* internal return codes */
132 #define	IPQOS_CONF_SUCCESS	0
133 #define	IPQOS_CONF_ERR		1
134 #define	IPQOS_CONF_RECOVER_ERR	2
135 #define	IPQOS_CONF_CURL_END	3
136 #define	IPQOS_CONF_CURL_BEGIN	4
137 #define	IPQOS_CONF_EOF		5
138 #define	IPQOS_CONF_NO_VER_STR	6
139 
140 /* special tokens in config file */
141 #define	IPQOS_CONF_IP_VERSION_STR	"ip_version"
142 #define	IPQOS_CONF_NEXT_ACTION_STR	"next_action"
143 #define	IPQOS_CONF_NAME_STR 		"name"
144 #define	IPQOS_CONF_MODULE_STR 		"module"
145 #define	IPQOS_CONF_FILTER_STR 		"filter"
146 #define	IPQOS_CONF_ACTION_STR 		"action"
147 #define	IPQOS_CONF_CLASS_STR 		"class"
148 #define	IPQOS_CONF_PARAMS_STR 		"params"
149 #define	IPQOS_CONF_NEXT_STR		"next"
150 #define	IPQOS_CONF_STATS_ENABLE_STR	"enable_stats"
151 #define	IPQOS_CONF_GLOBAL_STATS_STR	"global_stats"
152 #define	IPQOS_CONF_DROP_STR		"drop"
153 #define	IPQOS_CONF_CONT_STR		"continue"
154 #define	IPQOS_CONF_DEFER_STR		"defer"
155 #define	IPQOS_CONF_TRUE_STR		"true"
156 #define	IPQOS_CONF_FALSE_STR		"false"
157 #define	IPQOS_FMT_VERSION_STR		"fmt_version"
158 #define	IPQOS_IFNAME_STR		"if_name"
159 #define	IPQOS_PLACE_PRM_STR		IPQOS_CONF_PARAMS_STR
160 #define	IPQOS_PLACE_FILTER_STR		IPQOS_CONF_FILTER_STR
161 #define	IPQOS_PLACE_MAP_STR		"map"
162 
163 /* special tokens in types file */
164 #define	IPQOS_CONF_PERM_FILTER_MK	"#PERM_FILTER"
165 #define	IPQOS_CONF_PERM_CLASS_MK	"#PERM_CLASS"
166 #define	IPQOS_FMT_STR			"fmt_version"
167 #define	IPQOS_MOD_STR			"mod_version"
168 
169 
170 /* nvlist parameters */
171 #define	IPQOS_CONF_IP_VERSION		"ipgpc.ip_version"
172 
173 /* name lookup errors returned from domultihome() */
174 #define	IPQOS_LOOKUP_RETRY	1
175 #define	IPQOS_LOOKUP_FAIL	2
176 
177 /*
178  * used in calls to ipp_action_info() to encapuslate both an action and
179  * an ipqosconf internal return code.
180  */
181 typedef struct ipqos_actinfo_prm_s {
182 	struct ipqos_conf_action_s *action;
183 	int intl_ret;
184 } ipqos_actinfo_prm_t;
185 
186 /*
187  * skeletal list element struct used in manipulating lists of more complex
188  * structures.
189  */
190 typedef struct ipqos_list_el_s {
191 	struct ipqos_list_el_s *next;
192 } ipqos_list_el_t;
193 
194 typedef struct str_str {
195 	char *s1;
196 	char *s2;
197 } str_str_t;
198 
199 typedef struct str_val {
200 	char *string;
201 	int value;
202 } str_val_t;
203 
204 typedef struct str_val_nd {
205 	struct str_val sv;
206 	struct str_val_nd *next;
207 } str_val_nd_t;
208 
209 /* type of msg to be printed by ipqos_msg */
210 enum msg_type { MT_ERROR, MT_WARNING, MT_LOG, MT_ENOSTR };
211 
212 /* enum for allowable parameter types */
213 
214 typedef enum ipqos_nvtype_e {
215 IPQOS_DATA_TYPE_UINT8,
216 IPQOS_DATA_TYPE_INT16,
217 IPQOS_DATA_TYPE_UINT16,
218 IPQOS_DATA_TYPE_INT32,
219 IPQOS_DATA_TYPE_UINT32,
220 IPQOS_DATA_TYPE_BOOLEAN,
221 IPQOS_DATA_TYPE_STRING,
222 IPQOS_DATA_TYPE_ACTION,
223 IPQOS_DATA_TYPE_ADDRESS,
224 IPQOS_DATA_TYPE_PORT,
225 IPQOS_DATA_TYPE_PROTO,
226 IPQOS_DATA_TYPE_ENUM,
227 IPQOS_DATA_TYPE_IFNAME,
228 IPQOS_DATA_TYPE_M_INDEX,
229 IPQOS_DATA_TYPE_INT_ARRAY,
230 IPQOS_DATA_TYPE_USER,
231 IPQOS_DATA_TYPE_ADDRESS_MASK,
232 IPQOS_DATA_TYPE_IFINDEX
233 } ipqos_nvtype_t;
234 
235 /*
236  * passed to readnvpair to indicate which special meanings for nv names
237  * to use.
238  */
239 typedef enum place_e {
240 PL_ACTION, PL_FILTER, PL_CLASS, PL_PARAMS, PL_MAP, PL_ANY} place_t;
241 
242 
243 /* classifier filter representation */
244 
245 typedef struct ipqos_conf_filter_s {
246 	struct ipqos_conf_filter_s *next;
247 	char name[IPQOS_CONF_NAME_LEN];
248 	char class_name[IPQOS_CONF_NAME_LEN];
249 	nvlist_t *nvlist;
250 	boolean_t new;
251 	boolean_t modified;
252 	boolean_t cr_mod;
253 	boolean_t todel;
254 	boolean_t deleted;
255 	uint32_t originator;
256 	char *src_nd_name;
257 	char *dst_nd_name;
258 	int instance;
259 	uint32_t lineno;
260 	uint32_t ip_versions;
261 	int nlerr;
262 } ipqos_conf_filter_t;
263 
264 
265 /*
266  * action reference - used to store information and reference an action struct.
267  */
268 
269 typedef struct ipqos_conf_act_ref_s {
270 	struct ipqos_conf_act_ref_s *next;
271 	struct ipqos_conf_act_ref_s *prev;
272 	char name[IPQOS_CONF_NAME_LEN];
273 	char field[IPQOS_CONF_PNAME_LEN];
274 	struct ipqos_conf_action_s *action;
275 	nvlist_t *nvlist;
276 } ipqos_conf_act_ref_t;
277 
278 
279 /* classifier class representation */
280 
281 typedef struct ipqos_conf_class_s {
282 	struct ipqos_conf_class_s *next;
283 	char name[IPQOS_CONF_NAME_LEN];
284 	nvlist_t *nvlist;
285 	ipqos_conf_act_ref_t *alist;
286 	boolean_t modified;
287 	boolean_t new;
288 	boolean_t cr_mod;
289 	boolean_t todel;
290 	boolean_t deleted;
291 	boolean_t stats_enable;
292 	uint32_t originator;
293 	uint32_t lineno;
294 } ipqos_conf_class_t;
295 
296 /* action parameters representation */
297 
298 typedef struct ipqos_conf_params_s {
299 	struct ipqos_conf_params_s *next;
300 	ipqos_conf_act_ref_t *actions;
301 	nvlist_t *nvlist;
302 	boolean_t modified;
303 	boolean_t stats_enable;
304 	uint32_t originator;
305 	uint32_t lineno;
306 	boolean_t cr_mod;
307 } ipqos_conf_params_t;
308 
309 
310 /* signifys which stage of configuration application has just past */
311 enum visit {ADD_VISITED = 1, MOD_VISITED, REM_VISITED, INCYCLE_VISITED};
312 
313 /*
314  * action representation, with parameters, and lists of filters and classes
315  * if classifier action.
316  */
317 typedef struct ipqos_conf_action_s {
318 	struct ipqos_conf_action_s *next;
319 	char name[IPQOS_CONF_NAME_LEN];
320 	char module[IPQOS_CONF_NAME_LEN];
321 	ipqos_conf_filter_t *filters;
322 	ipqos_conf_class_t *classes;
323 	ipqos_conf_params_t *params;
324 	nvlist_t *nvlist;
325 	boolean_t todel;
326 	boolean_t deleted;
327 	boolean_t new;
328 	boolean_t modified;
329 	boolean_t cr_mod;
330 	ipqos_conf_act_ref_t *dependencies;
331 	enum visit visited;
332 	uint32_t lineno;
333 	ipqos_conf_filter_t *retry_filters;
334 	char **perm_classes;
335 	int num_perm_classes;
336 	int module_version;
337 } ipqos_conf_action_t;
338 
339 
340 #ifdef __cplusplus
341 }
342 #endif
343 
344 #endif /* _IPQOS_CONF_H */
345