/*-
 * Copyright (c) 2004 Andrey Simonenko
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *   @(#)$Id: ipactl.h,v 1.1.4.3 2007/02/17 09:21:55 simon Exp $
 */

#ifndef IPACTL_H
#define IPACTL_H

/*
 * Version of protocol.
 */
#define CTL_QUERY_VERSION		0x1

/*
 * Control commands answers codes.
 */
#define CTL_ANSWER_DONE			 0 /* Command was successfully done. */
#define CTL_ANSWER_SYSTEM_ERROR		 1 /* Some system error occurred. */
#define CTL_ANSWER_UNKNOWN_COMMAND	 2 /* Unknown command or flag. */
#define CTL_ANSWER_INVALID_NAME		 3 /* Illegal name in command query. */
#define CTL_ANSWER_DENIED		 4 /* Command was denied. */
#define CTL_ANSWER_UNKNOWN_RULE		 5 /* Unknown rule name. */
#define CTL_ANSWER_UNKNOWN_LIMIT	 6 /* Unknown limit name. */
#define CTL_ANSWER_UNKNOWN_THRESHOLD	 7 /* Unknown threshold name. */
#define CTL_ANSWER_CANNOT_MODIFY	 8 /* Cannot modify value. */
#define CTL_ANSWER_CANNOT_EXPIRE	 9 /* Cannot expire limit. */
#define CTL_ANSWER_CANNOT_RESTART	10 /* Cannot restart limit. */

#define CTL_ANSWER_MAX	CTL_ANSWER_CANNOT_RESTART

#ifndef CTL_NAME1_LEN
# define CTL_NAME1_LEN	24	/* Max allowed length of rule. */
#endif

#ifndef CTL_NAME2_LEN
# define CTL_NAME2_LEN	24	/* Max allowed length of limit or threshold. */
#endif

#ifndef CTL_MZONE_NAME_LEN
# define CTL_MZONE_NAME_LEN 30	/* Max length of mzone name. */
#endif

#ifndef CTL_MZONE_DESC_LEN
# define CTL_MZONE_DESC_LEN 40	/* Max length of mzone description. */
#endif

#ifndef CTL_MARRAY_NAME_LEN
# define CTL_MARRAY_NAME_LEN 30	/* Max length of marray name. */
#endif

#ifndef CTL_MARRAY_DESC_LEN
# define CTL_MARRAY_DESC_LEN 40	/* Max length of marray description. */
#endif

#ifndef CTL_MEM_TYPE_NAME_LEN
# define CTL_MEM_TYPE_NAME_LEN 30 /* Max length of memory type name. */
#endif

#ifndef CTL_MEM_TYPE_DESC_LEN
# define CTL_MEM_TYPE_DESC_LEN 40 /* Max length of memory type description. */
#endif

/*
 * Control commands query codes.
 */
#define CTL_CMD_STATUS		0
#define CTL_CMD_MEMORY		1
#define CTL_CMD_DUMP		2
#define CTL_CMD_FREEZE		3
#define CTL_CMD_RESTART		4
#define CTL_CMD_EXPIRE		5
#define CTL_CMD_SET		6

#define CTL_CMD_MAX	CTL_CMD_SET

#define CTL_CMD_FLAG_WAIT	0x0001
#define CTL_CMD_FLAG_LIMIT	0x0002
#define CTL_CMD_FLAG_THRESHOLD	0x0004
#define CTL_CMD_FLAG_COUNTER	0x0008
#define CTL_CMD_FLAG_INCREMENT	0x0010
#define CTL_CMD_FLAG_DECREMENT	0x0020

/*
 * Control command query.
 */
struct ctl_cmd_query {
	u_int	ver;			/* Version of protocol.		*/
	u_int	cmd;			/* Command code.		*/
	u_int	flags;			/* Command flags.		*/
	char	name1[CTL_NAME1_LEN];	/* Rule name.			*/
	char	name2[CTL_NAME2_LEN];	/* Limit or threshold name.	*/
	uint64_t value;			/* Value (depends on cmd).	*/
};

/*
 * Control command answer.
 */
struct ctl_cmd_answer {
	u_int	result;			/* Result code of ctl command.	*/
	size_t	size;			/* Size of the rest of answer.	*/
};

struct ctl_cmd_answer_status {
	u_int	nac_mods;		/* Number of ac_mods.		*/
	u_int	ndb_mods;		/* Number of db_mods.		*/
	u_int	nautorules;		/* Number of autorules.		*/
	u_int	nstatrules;		/* Number of static rules.	*/
	u_int	ndynrules;		/* Number of dynamic rules.	*/
	u_int	nstatlimits;		/* Number of static limits.	*/
	u_int	ndynlimits;		/* Number of dynamic limits.	*/
	u_int	nstatsublimits;		/* Number of static sublimits.	*/
	u_int	ndynsublimits;		/* Number of dynamic sublimits.	*/
	u_int	nstatthresholds;	/* Number of static thresholds.	*/
	u_int	ndynthresholds;		/* Number of dynamic thresholds. */
	int	active;			/* Non-zero if active.		*/
	int	reached;		/* Non-zero if limit is reached. */
	int	dynamic;		/* Non-zero if dynamic.		*/
	ipa_tm	tm;			/* Limit event.			*/
	u_int	value_type;		/* Type of values.		*/
	uint64_t value1;		/* Limit or threshold.		*/
	uint64_t value2;		/* Counter.			*/
	int	value2_sign;		/* Non-zero if value2 < 0.	*/
};

struct ctl_cmd_answer_memory {
	size_t	size_cnt;		/* Amount of allocated memory.	*/
	u_int	nmem_type;		/* Number of memory types.	*/
	u_int	nmzones;		/* Number of mzones.		*/
	u_int	nmarrays;		/* Number of marrays.		*/
};

struct ctl_cmd_answer_mem_type {
	char	name[CTL_MEM_TYPE_NAME_LEN]; /* Name of memory type.	*/
	char	desc[CTL_MEM_TYPE_DESC_LEN]; /* Description of memory type. */
	size_t	size;			/* Amount of allocated memory.	*/
	u_int	reqs;			/* Number of requests.		*/
};

struct ctl_cmd_answer_mzone {
	char	name[CTL_MZONE_NAME_LEN]; /* Name of mzone.		*/
	char	desc[CTL_MZONE_DESC_LEN]; /* Description of mzone.	*/
	size_t	isize;			/* Size of one item.		*/
	u_int	nused;			/* Number of used items.	*/
	u_int	nfree;			/* Number of free items.	*/
	size_t	pools_size;		/* Used memory by pools.	*/
	u_int	reqs;			/* Number of requests.		*/
};

struct ctl_cmd_answer_marray {
	char	name[CTL_MARRAY_NAME_LEN]; /* Name of marrays.		*/
	char	desc[CTL_MARRAY_DESC_LEN]; /* Description of marray.	*/
	size_t	isize;			/* Size of one item.		*/
	u_int	nused;			/* Number of used items.	*/
	u_int	nfree;			/* Number of free items.	*/
	size_t	arr_size;		/* Used memory by array.	*/
	size_t	bitmap_size;		/* Used memory by bitmap.	*/
	u_int	reqs;			/* Number of requests.		*/
};

struct ctl_cmd_answer_set {
	u_int	value_type;		/* Type of values.		*/
	uint64_t value1;		/* Limit or threshold.		*/
	uint64_t value2;		/* Counter.			*/
	int	value2_sign;		/* Non-zero if value2 < 0.	*/
};

#endif /* !IPACTL_H */


syntax highlighted by Code2HTML, v. 0.9.1