1 /*-
2  * Copyright (c) 2004 Andrey Simonenko
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  *   @(#)$Id: ipactl.h,v 1.2 2011/01/23 18:42:35 simon Exp $
27  */
28 
29 #ifndef IPACTL_H
30 #define IPACTL_H
31 
32 /*
33  * Protocol version.
34  */
35 #define CTL_PROTOCOL_VERSION	2
36 
37 /*
38  * Control commands answers codes.
39  */
40 #define CTL_ANS_DONE			 0 /* Command succeeded.	*/
41 #define CTL_ANS_SYSTEM_ERROR		 1 /* System error occurred.	*/
42 #define CTL_ANS_WRONG_COMMAND		 2 /* Wrong command.		*/
43 #define CTL_ANS_ILLEGAL_NAME		 3 /* Illegal name.		*/
44 #define CTL_ANS_DENIED			 4 /* Command was denied.	*/
45 #define CTL_ANS_UNKNOWN_AUTORULE	 5 /* Unknown autorule name.	*/
46 #define CTL_ANS_UNKNOWN_RULE		 6 /* Unknown rule name.	*/
47 #define CTL_ANS_UNKNOWN_LIMIT		 7 /* Unknown limit name.	*/
48 #define CTL_ANS_UNKNOWN_THRESHOLD	 8 /* Unknown threshold name.	*/
49 #define CTL_ANS_CANNOT_MODIFY		 9 /* Cannot modify value.	*/
50 #define CTL_ANS_CANNOT_EXPIRE		10 /* Cannot expire limit.	*/
51 #define CTL_ANS_CANNOT_RESTART		11 /* Cannot restart limit.	*/
52 #define CTL_ANS_CANNOT_CREATE		12 /* Cannot create rule.	*/
53 #define CTL_ANS_CANNOT_DELETE		13 /* Cannot delete rule.	*/
54 
55 #define CTL_MAX_ANS	CTL_ANS_CANNOT_DELETE
56 
57 /* Max length of mzone name. */
58 #define CTL_MZONE_NAME_LEN	30
59 
60 /* Max length of mzone description. */
61 #define CTL_MZONE_DESC_LEN	40
62 
63 /* Max length of marray name. */
64 #define CTL_MARRAY_NAME_LEN	30
65 
66 /* Max length of marray description. */
67 #define CTL_MARRAY_DESC_LEN	40
68 
69 /* Max length of memory type name. */
70 #define CTL_MEM_TYPE_NAME_LEN	30
71 
72 /* Max length of memory type description. */
73 #define CTL_MEM_TYPE_DESC_LEN	40
74 
75 /*
76  * Control commands query codes.
77  */
78 #define CTL_CMD_STATUS			0
79 #define CTL_CMD_MEMORY			1
80 #define CTL_CMD_DUMP			2
81 #define CTL_CMD_FREEZE			3
82 #define CTL_CMD_RESTART			4
83 #define CTL_CMD_EXPIRE			5
84 #define CTL_CMD_SET			6
85 #define CTL_CMD_CREATE			7
86 #define CTL_CMD_DELETE			8
87 
88 #define CTL_MAX_CMD	CTL_CMD_DELETE
89 
90 #define CTL_CFLAG_WAIT			0x0001
91 #define CTL_CFLAG_AUTORULE		0x0002
92 #define CTL_CFLAG_RULE			0x0004
93 #define CTL_CFLAG_LIMIT			0x0008
94 #define CTL_CFLAG_THRESHOLD		0x0010
95 #define CTL_CFLAG_VALUE1		0x0020
96 #define CTL_CFLAG_VALUE1_INC		0x0040
97 #define CTL_CFLAG_VALUE1_DEC		0x0080
98 #define CTL_CFLAG_VALUE2		0x0100
99 #define CTL_CFLAG_VALUE2_INC		0x0200
100 #define CTL_CFLAG_VALUE2_DEC		0x0400
101 
102 #define CTL_ALL_CFLAGS (	  \
103 	CTL_CFLAG_WAIT		| \
104 	CTL_CFLAG_AUTORULE	| \
105 	CTL_CFLAG_RULE		| \
106 	CTL_CFLAG_LIMIT		| \
107 	CTL_CFLAG_THRESHOLD	| \
108 	CTL_CFLAG_VALUE1	| \
109 	CTL_CFLAG_VALUE1_INC	| \
110 	CTL_CFLAG_VALUE1_DEC	| \
111 	CTL_CFLAG_VALUE2	| \
112 	CTL_CFLAG_VALUE2_INC	| \
113 	CTL_CFLAG_VALUE2_DEC)
114 
115 /*
116  * Control command query.
117  */
118 struct ctl_cmdq {
119 	unsigned int	ver;		/* Version of protocol.		*/
120 	unsigned int	cmd;		/* Command code.		*/
121 	unsigned int	flags;		/* Command flags.		*/
122 	size_t		size;		/* Size of next data.		*/
123 };
124 
125 struct ctl_cmdq_val {
126 	uint64_t	value1;		/* Value1.			*/
127 	uint64_t	value2;		/* Value2.			*/
128 };
129 
130 /*
131  * Control command answer.
132  */
133 struct ctl_cmda {
134 	unsigned int	result;		/* Result of control command.	*/
135 	size_t		size;		/* Size of next data.		*/
136 };
137 
138 struct ctl_cmda_all_status {
139 	unsigned int	nac_mods;	/* Number of ac_mods.		*/
140 	unsigned int	ndb_mods;	/* Number of db_mods.		*/
141 	unsigned int	nautorules;	/* Number of autorules.		*/
142 	unsigned int	nstatrules;	/* Number of static rules.	*/
143 	unsigned int	ndynrules;	/* Number of dynamic rules.	*/
144 	unsigned int	nstatlimits;	/* Number of static limits.	*/
145 	unsigned int	ndynlimits;	/* Number of dynamic limits.	*/
146 	unsigned int	nstatsublimits;	/* Number of static sublimits.	*/
147 	unsigned int	ndynsublimits;	/* Number of dynamic sublimits.	*/
148 	unsigned int	nstatthresholds;/* Number of static thresholds.	*/
149 	unsigned int	ndynthresholds;	/* Number of dynamic thresholds.*/
150 };
151 
152 struct ctl_cmda_autorule_status {
153 	unsigned int	nrules;		/* Number of its dynamic rules.	*/
154 	char		active;		/* Set if active.		*/
155 };
156 
157 struct ctl_cmda_rule_status {
158 	unsigned int	nlimits;	/* Number of limits.		*/
159 	unsigned int	nsublimits;	/* Number of sublimits.		*/
160 	unsigned int	nthresholds;	/* Number of thresholds.	*/
161 	char		dynamic;	/* Set if dynamic.		*/
162 	char		active;		/* Set if active.		*/
163 };
164 
165 struct ctl_cmda_limit_status {
166 	ipa_tm		tm;		/* Limit event date.		*/
167 	uint64_t	value1;		/* Limit value.			*/
168 	uint64_t	value2;		/* Limit counter.		*/
169 	unsigned int	nsublimits;	/* Number of sublimits.		*/
170 	unsigned char	value_type;	/* Type of values.		*/
171 	char		value2_sign;	/* Set if value2 is negative.	*/
172 	char		reached;	/* Set if reached.		*/
173 	char		dynamic;	/* Set if dynamic.		*/
174 	char		active;		/* Set if active.		*/
175 };
176 
177 struct ctl_cmda_threshold_status {
178 	ipa_tm		tm[2];		/* Time window.			*/
179 	uint64_t	value1;		/* Threshold value.		*/
180 	uint64_t	value2;		/* Threshold counter.		*/
181 	uint64_t	deviation;	/* Threshold deviation.		*/
182 	unsigned char	value_type;	/* Type of values.		*/
183 	char		value2_sign;	/* Set if value2 is negative.	*/
184 	char		dynamic;	/* Set if dynamic.		*/
185 	char		active;		/* Set if active.		*/
186 };
187 
188 struct ctl_cmda_memory {
189 	size_t		size;		/* Amount of allocated memory.	*/
190 	unsigned int	nmem_type;	/* Number of memory types.	*/
191 	unsigned int	nmzones;	/* Number of mzones.		*/
192 	unsigned int	nmarrays;	/* Number of marrays.		*/
193 };
194 
195 struct ctl_cmda_mem_type {
196 	size_t		size;		/* Amount of allocated memory.	*/
197 	unsigned int	reqs;		/* Number of requests.		*/
198 	char	name[CTL_MEM_TYPE_NAME_LEN]; /* Name of memory type.	*/
199 	char	desc[CTL_MEM_TYPE_DESC_LEN]; /* Description.		*/
200 };
201 
202 struct ctl_cmda_mzone {
203 	size_t		isize;		/* Size of one item.		*/
204 	size_t		pools_size;	/* Used memory by pools.	*/
205 	unsigned int	nused;		/* Number of used items.	*/
206 	unsigned int	nfree;		/* Number of free items.	*/
207 	unsigned int	reqs;		/* Number of requests.		*/
208 	char	name[CTL_MZONE_NAME_LEN]; /* Name of mzone.		*/
209 	char	desc[CTL_MZONE_DESC_LEN]; /* Description.		*/
210 };
211 
212 struct ctl_cmda_marray {
213 	size_t		isize;		/* Size of one item.		*/
214 	size_t		arr_size;	/* Used memory by array.	*/
215 	size_t		bitmap_size;	/* Used memory by bitmap.	*/
216 	unsigned int	nused;		/* Number of used items.	*/
217 	unsigned int	nfree;		/* Number of free items.	*/
218 	unsigned int	reqs;		/* Number of requests.		*/
219 	char	name[CTL_MARRAY_NAME_LEN]; /* Name of marrays.		*/
220 	char	desc[CTL_MARRAY_DESC_LEN]; /* Description.		*/
221 };
222 
223 struct ctl_cmda_set {
224 	uint64_t	value1;		/* Limit or threshold value.	*/
225 	uint64_t	value2;		/* Limit or threshold counter.	*/
226 	unsigned char	value_type;	/* Type of values.		*/
227 	char		value2_sign;	/* Set if value2 is negative.	*/
228 };
229 
230 #endif /* !IPACTL_H */
231