]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/authorization/inetaccess/antiflood.h
Добавление исходников
[stg.git] / projects / stargazer / plugins / authorization / inetaccess / antiflood.h
1 /*
2  *    This program is free software; you can redistribute it and/or modify
3  *    it under the terms of the GNU General Public License as published by
4  *    the Free Software Foundation; either version 2 of the License, or
5  *    (at your option) any later version.
6  *
7  *    This program is distributed in the hope that it will be useful,
8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  *    GNU General Public License for more details.
11  *
12  *    You should have received a copy of the GNU General Public License
13  *    along with this program; if not, write to the Free Software
14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15  */
16
17 /*
18  *    Date: 27.10.2002
19  */
20
21 /*
22  *    Author : Boris Mikhailenko <stg34@ua.fm>
23  */
24
25
26 #ifndef ANTIFLOOD_H
27 #define ANTIFLOOD_H
28
29
30 #include <sys/time.h>
31
32 #include "bsp.h"
33 #include "os_int.h"
34
35 #define FLOOD_LBL_MAX   (10)
36
37 //-----------------------------------------------------------------------------
38 struct FLOOD_NODE
39 {
40 uint32_t ip;
41 uint64_t timeIP[FLOOD_LBL_MAX];
42 int pos;
43 bool logged;
44 };
45
46 //-----------------------------------------------------------------------------
47 class ANTIFLOOD
48 {
49 public:
50     ANTIFLOOD();
51     bool AllowIP(uint32_t ip, bool * logged);
52     void Clean();
53     void SetAvrgTime(uint64_t);
54
55 private:
56     uint64_t CalcAvrgNodeTime(FLOOD_NODE * fn);
57     void AddNode(uint32_t ip);
58     void UpdateNodeTime(FLOOD_NODE * node);
59
60     TREE floodTree;
61     struct timeval tv;
62     uint64_t avrgTime;
63     uint64_t currentTime;
64 };
65 //-----------------------------------------------------------------------------
66
67 #endif
68
69
70
71