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