/[cvs]/botnetop.mod/flood.c
ViewVC logotype

Contents of /botnetop.mod/flood.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sun Jul 14 09:29:53 2002 UTC (16 years, 5 months ago) by sup
Branch: MAIN
CVS Tags: HEAD
File MIME type: text/x-chdr
Updated to 1.1.0-gamma

1 /*
2 * flood.c -- part of botnetop.mod
3 *
4 * $Id$
5 */
6 /*
7 * Copyright (C) 2000, 2001, 2002 Teemu Hjelt <temex@iki.fi>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23
24 static struct flood_t *find_flood(char *chan)
25 {
26 struct flood_t *f = NULL;
27
28 for (f = flood_start; f != NULL; f = f->next) {
29 if (!rfc_casecmp(f->chan, chan))
30 return f;
31 }
32
33 return NULL;
34 }
35
36 static struct flood_t *add_flood(char *chan)
37 {
38 struct flood_t *f = NULL;
39
40 f = (struct flood_t *) nmalloc(sizeof(struct flood_t));
41 if (f == NULL)
42 return NULL;
43
44 f->chan = (char *) nmalloc(strlen(chan) + 1);
45 if (f->chan == NULL) {
46 nfree(f);
47 return NULL;
48 }
49
50 strncpyz(f->chan, chan, strlen(chan) + 1);
51 f->time = now;
52 f->amount = 0;
53 f->ignore = 0;
54
55 f->next = flood_start;
56 flood_start = f;
57
58 putlog(LOG_DEBUG, "*", "botnetop.mod: new flood record created for %s (address: %u)", f->chan, f);
59
60 return f;
61 }
62
63 static void del_flood(struct flood_t *flood)
64 {
65 struct flood_t *f = NULL, *old = NULL;
66
67 for (f = flood_start; f != NULL; old = f, f = f->next) {
68 if (f == flood) {
69 if (old != NULL)
70 old->next = f->next;
71 else
72 flood_start = f->next;
73 putlog(LOG_DEBUG, "*", "botnetop.mod: flood record removed from %s (address: %u)", f->chan, f);
74 if (f->chan != NULL)
75 nfree(f->chan);
76 nfree(f);
77 break;
78 }
79 }
80 }
81
82 static int check_flood_status(char *chan)
83 {
84 struct flood_t *f = NULL;
85
86 if (bop_flood_amount) {
87 if (!(f = find_flood(chan))) {
88 if (!(f = add_flood(chan)))
89 return 0;
90 }
91
92 if (f->ignore)
93 return 1; /* We're currently ignoring. */
94
95 if (f->time < now - bop_flood_time) {
96 /* Flood timer has expired, reset variables. */
97 f->time = now;
98 f->amount = 0;
99 return 0;
100 }
101
102 f->amount++;
103
104 if (f->amount >= bop_flood_amount) {
105 /* We got flooded, start ignoring. */
106 f->amount = 0;
107 f->time = 0;
108 f->ignore = now;
109 putlog(LOG_DEBUG, "*", "botnetop.mod: added %ds ignore for %s", bop_ignore, f->chan);
110 return 1;
111 }
112 }
113
114 return 0;
115 }
116
117 static void check_flood()
118 {
119 struct flood_t *f = NULL;
120
121 for (f = flood_start; f != NULL; f = f->next) {
122 if ((f->ignore > 0) && (f->ignore < now - bop_ignore)) {
123 f->ignore = 0;
124 putlog(LOG_DEBUG, "*", "botnetop.mod: removed ignore from %s", f->chan);
125 }
126 }
127 }
128
129 static void flood_free_mem()
130 {
131 struct flood_t *f = NULL, *fnext = NULL;
132
133 for (f = flood_start; f != NULL; f = fnext) {
134 fnext = f->next;
135 if (f->chan != NULL)
136 nfree(f->chan);
137 nfree(f);
138 }
139 flood_start = NULL;
140 }
141
142 static int flood_expmem()
143 {
144 int size = 0;
145 struct flood_t *f = NULL;
146
147 for (f = flood_start; f != NULL; f = f->next) {
148 if (f->chan != NULL)
149 size += strlen(f->chan) + 1;
150 size += sizeof(struct flood_t);
151 }
152
153 return size;
154 }
155

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23