/*-
* Copyright (c) 2003 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: ipa_limits.h,v 1.1.4.1 2007/02/17 09:21:54 simon Exp $
*/
#ifndef IPA_LIMITS_H
#define IPA_LIMITS_H
#ifdef WITH_LIMITS
#define IS_REACHED(x) (x->is_reached)
#define IS_NOTREACHED(x) (!x->is_reached)
#ifndef LIMIT_NSIZE
# define LIMIT_NSIZE 30
#endif
#ifndef LIMIT_NALLOC
# define LIMIT_NALLOC 20
#endif
#ifdef WITH_SUBLIMITS
#ifndef SUBLIMIT_NSIZE
# define SUBLIMIT_NSIZE LIMIT_NSIZE
#endif
#ifndef SUBLIMIT_NALLOC
# define SUBLIMIT_NALLOC LIMIT_NALLOC
#endif
struct rule;
/*
* limit { sublimit {}} section.
*/
struct sublimit {
STAILQ_ENTRY(sublimit) link; /* Link for list of sublimits. */
char *sublimit_name; /* sublimit <limit> string. */
uint64_t lim; /* sublimit <limit> */
u_int lim_per_cent; /* sublimit <limit> if it is xx%. */
u_int cnt_type; /* Type of the "sublimit" parameter's argument. */
struct cmd_list reach; /* sublimit { reach {}} */
struct cmds_limit rc[2]; /* sublimit { startup|shutdown {}} */
struct wpid wpid; /* Sublimit's wpid structure. */
int is_reached; /* 1, if sublimit is reached. */
struct limit *limit; /* Pointer to sublimit's limit. */
};
extern ipa_mzone *sublimit_mzone;
extern int reach_sublimit(const struct rule *, const struct limit *, struct sublimit *);
extern void init_cmds_in_sublimit(struct sublimit *);
#endif /* WITH_SUBLIMITS */
/*
* limit { expire {}} section.
*/
struct expire {
struct texp expire; /* expire { expire } */
struct cmd_list cmdl; /* "exec" parameters. */
};
/*
* limit { restart {}} section.
*/
struct restart {
struct texp restart; /* restart { restart } */
struct cmd_list cmdl; /* "exec" parameters. */
};
/*
* rule { limit {}} section.
*/
struct limit {
STAILQ_ENTRY(limit) link; /* Link for list of limits. */
char *limit_name; /* Name of this limit. */
char *limit_info; /* limit { info } */
u_int limitno; /* Order number of this limit in its rule. */
uint64_t lim; /* limit { limit } */
uint64_t cnt; /* Counter. */
uint64_t cnt_neg; /* Negative counter. */
u_int cnt_type; /* Type of the "limit" parameter's argument. */
int load_limit; /* limit { load_limit } */
struct restart restart; /* limit { restart {}} */
struct cmd_list reach; /* limit { reach {}} */
struct expire expire; /* limit { expire {}} */
const struct worktime *worktime;/* limit { worktime } */
int is_active; /* [IN]ACTIVE_FLAG */
const struct db_list *db_list; /* limit { db_list } */
struct cmds_limit rc[2]; /* limit { startup|shutdown {}} */
#ifdef WITH_SUBLIMITS
STAILQ_HEAD(, sublimit) sublimits; /* limit { sublimit {}} */
#endif
struct wpid wpid; /* Limit's wpid structure. */
int is_reached; /* 1, if limit is reached. */
ipa_tm event_tm; /* Exact time when to check some limit's event. */
u_int event_sec; /* Time when to check some limit's event. */
u_int event_date_set; /* The same as in ipa_limit_state. */
ipa_tm event_date[IPA_LIMIT_EVENT_NUM]; /* The same as in ipa_limit_state. */
const struct rule *rule; /* Pointer to limit's rule. */
};
/*
* List of all limits in one rule.
*/
STAILQ_HEAD(limits_list, limit);
extern const char *const limit_event_msg[];
extern int global_debug_limit;
extern int global_debug_limit_init;
extern int global_load_limit;
extern ipa_mzone *limit_mzone;
extern int add_chunk_to_limit(const struct rule *, struct limit *, const uint64_t *);
extern int add_chunk_to_limits(const struct rule *, const uint64_t *);
extern int sub_chunk_from_limit(const struct rule *, struct limit *, const uint64_t *);
extern int sub_chunk_from_limits(const struct rule *, const uint64_t *);
extern int init_limits(const struct rule *);
extern int check_limits_events(const struct rule *, u_int *);
extern void limit_set_event_sec(struct limit *);
extern int limits_newday(struct rule *);
extern int restart_limit(const struct rule *, struct limit *);
extern int reach_limit(const struct rule *, struct limit *);
extern int expire_limit(const struct rule *, struct limit *);
#define set_limit_inactive(r, l) mod_set_limit_active((r), (l), INACTIVE_FLAG)
extern int mod_set_limit_active(const struct rule *, struct limit *, int);
extern int copy_limits(struct rule *, const struct limits_list *, int);
extern void free_limits(u_int, struct limits_list *, int);
extern void init_cmds_in_limit(struct limit *);
extern void set_sync_exec_in_limit(struct limit *);
extern struct limit *limit_by_name(const struct rule *, const char *);
#endif /* WITH_LIMITS */
extern u_int nstatlimits;
extern u_int ndynlimits;
extern u_int nstatsublimits;
extern u_int ndynsublimits;
#endif /* !IPA_LIMITS_H */
syntax highlighted by Code2HTML, v. 0.9.1