00001
00002
00003
00004 #ifndef _SF_THRESHOLDING_
00005 #define _SF_THRESHOLDING_
00006
00007 #include "sflsq.h"
00008
00009 #include "sfghash.h"
00010 #include "sfxhash.h"
00011
00012
00013
00014
00015
00016
00017 #define THD_MAX_GENID 8129
00018 #define THD_GEN_ID_1_ROWS 4096
00019 #define THD_GEN_ID_ROWS 512
00020
00021 #define THD_TOO_MANY_THDOBJ -15
00022
00023
00024
00025
00026 enum
00027 {
00028 THD_TYPE_LIMIT,
00029 THD_TYPE_THRESHOLD,
00030 THD_TYPE_BOTH,
00031 THD_TYPE_SUPPRESS,
00032 };
00033
00034
00035
00036
00037
00038 #define THD_PRIORITY_SUPPRESS 1000000
00039
00040
00041
00042
00043 enum
00044 {
00045 THD_TRK_SRC,
00046 THD_TRK_DST,
00047 };
00048
00049
00050
00051
00052
00053
00054
00055
00056 typedef struct {
00057
00058 unsigned ip;
00059 unsigned count;
00060 time_t tstart;
00061
00062 }THD_IP_NODE;
00063
00064
00065 typedef struct {
00066
00067 unsigned count;
00068 time_t tstart;
00069
00070 }THD_IP_GNODE;
00071
00072
00073
00074
00075
00076
00077 typedef struct{
00078
00079 int thd_id;
00080 unsigned ip;
00081
00082 } THD_IP_NODE_KEY ;
00083
00084 typedef struct{
00085
00086 unsigned gen_id;
00087 unsigned sig_id;
00088 unsigned ip;
00089
00090 } THD_IP_GNODE_KEY ;
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 typedef struct {
00101
00102 int thd_id;
00103
00104 unsigned gen_id;
00105 unsigned sig_id;
00106 int tracking;
00107 int type;
00108 int priority;
00109 unsigned count;
00110 unsigned seconds;
00111
00112 unsigned ip_address;
00113 unsigned ip_mask;
00114
00115 unsigned not_flag;
00116
00117 }THD_NODE;
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 typedef struct {
00132
00133 unsigned gen_id;
00134 unsigned sig_id;
00135
00136
00137
00138
00139 SF_LIST * sfthd_node_list;
00140
00141 }THD_ITEM;
00142
00143
00144
00145
00146
00147 typedef struct {
00148 unsigned gen_id;
00149 unsigned sig_id;
00150 int type;
00151 int tracking;
00152 int priority;
00153 int count;
00154 int seconds;
00155 int ip_address;
00156 int ip_mask;
00157 unsigned not_flag;
00158 }THDX_STRUCT;
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 typedef struct {
00169
00170 SFGHASH * sfthd_array [THD_MAX_GENID];
00171
00172 THD_NODE * sfthd_garray[THD_MAX_GENID];
00173
00174 SFXHASH * ip_nodes;
00175
00176 int count;
00177
00178 SFXHASH * ip_gnodes;
00179
00180 SFXHASH * supress;
00181
00182
00183 }THD_STRUCT;
00184
00185
00186
00187
00188
00189 THD_STRUCT * sfthd_new( unsigned nbytes );
00190
00191 int sfthd_create_threshold( THD_STRUCT * thd,
00192 unsigned gen_id,
00193 unsigned sig_id,
00194 int tracking,
00195 int type,
00196 int priority,
00197 int count,
00198 int seconds,
00199 unsigned ip_address,
00200 unsigned ip_mask,
00201 unsigned not_flag );
00202
00203 int sfthd_test_threshold( THD_STRUCT * thd,
00204 unsigned gen_id,
00205 unsigned sig_id,
00206 unsigned sip,
00207 unsigned dip,
00208 long curtime ) ;
00209
00210 int sfthd_show_objects( THD_STRUCT * thd );
00211
00212 #endif