1 /*
2     pmacct (Promiscuous mode IP Accounting package)
3     pmacct is Copyright (C) 2003-2019 by Paolo Lucente
4 */
5 
6 /*
7     This program is free software; you can redistribute it and/or modify
8     it under the terms of the GNU General Public License as published by
9     the Free Software Foundation; either version 2 of the License, or
10     (at your option) any later version.
11 
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16 
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21 #ifndef PREPROCESS_H
22 #define PREPROCESS_H
23 
24 /* defines */
25 #define PREP_DICT_SQL	1
26 #define PREP_DICT_PRINT	2
27 
28 /* structures */
29 struct _preprocess_dictionary_line {
30   char key[SRVBUFLEN];
31 };
32 
33 struct preprocess {
34   u_int32_t qnum;
35   u_int16_t minp;
36   u_int16_t minf;
37   u_int32_t minb;
38   u_int16_t maxp;
39   u_int16_t maxf;
40   u_int32_t maxb;
41   u_int16_t maxbpp;
42   u_int16_t maxppf;
43   u_int16_t minbpp;
44   u_int16_t minppf;
45   u_int32_t fss;	/* threshold: flow size (flow size dependent sampling) */
46   u_int32_t fsrc;	/* threshold: flows number (flow sampling with resource constraints) */
47   int usrf;		/* renormalization factor for uniform sampling methods */
48   int adjb;		/* adjusts bytes counter by 'adjb' bytes */
49   u_int8_t recover;
50   u_int8_t num;		/* total number of preprocess clauses specified: actions + checks */
51   u_int8_t checkno;	/* number of checks */
52   u_int8_t actionno;	/* number of actions */
53 };
54 
55 struct fsrc_queue_elem {
56   struct fsrc_queue_elem *next;
57   struct db_cache *cache_ptr;
58   float z;
59 };
60 
61 struct _fsrc_queue {
62   struct fsrc_queue_elem head;
63   u_int32_t num;
64 };
65 
66 /* typedefs */
67 //fwd decl
68 struct chained_cache;
69 typedef int (*sql_preprocess_func) (struct db_cache *[], int *, int);
70 typedef int (*P_preprocess_func) (struct chained_cache *[], int *, int);
71 
72 extern void set_preprocess_funcs(char *, struct preprocess *, int);
73 extern int cond_qnum(struct db_cache *[], int *, int);
74 extern int check_minp(struct db_cache *[], int *, int);
75 extern int check_minb(struct db_cache *[], int *, int);
76 extern int check_minf(struct db_cache *[], int *, int);
77 extern int check_maxp(struct db_cache *[], int *, int);
78 extern int check_maxb(struct db_cache *[], int *, int);
79 extern int check_maxf(struct db_cache *[], int *, int);
80 extern int check_maxbpp(struct db_cache *[], int *, int);
81 extern int check_maxppf(struct db_cache *[], int *, int);
82 extern int check_minbpp(struct db_cache *[], int *, int);
83 extern int check_minppf(struct db_cache *[], int *, int);
84 extern int check_fss(struct db_cache *[], int *, int);
85 extern int check_fsrc(struct db_cache *[], int *, int);
86 extern int action_usrf(struct db_cache *[], int *, int);
87 extern int action_adjb(struct db_cache *[], int *, int);
88 extern int P_check_minp(struct chained_cache *[], int *, int);
89 extern int P_check_minb(struct chained_cache *[], int *, int);
90 extern int P_check_minf(struct chained_cache *[], int *, int);
91 extern int P_check_minbpp(struct chained_cache *[], int *, int);
92 extern int P_check_minppf(struct chained_cache *[], int *, int);
93 
94 extern int mandatory_invalidate(struct db_cache *[], int *, int);
95 extern int mandatory_validate(struct db_cache *[], int *, int);
96 extern void check_validity(struct db_cache *, int);
97 extern int P_mandatory_invalidate(struct chained_cache *[], int *, int);
98 extern void P_check_validity(struct chained_cache *, int);
99 
100 extern sql_preprocess_func sql_preprocess_funcs[2*N_FUNCS]; /* 20 */
101 extern P_preprocess_func P_preprocess_funcs[2*N_FUNCS]; /* 20 */
102 extern struct preprocess prep;
103 extern struct _fsrc_queue fsrc_queue;
104 
105 #endif // PREPROCESS_H
106