reject functions from ratbox3

This commit is contained in:
Valery Yatsko 2008-04-02 14:41:37 +04:00
parent dfb5a598a0
commit 92bdd4adfe
3 changed files with 16 additions and 26 deletions

View File

@ -31,6 +31,9 @@
extern rb_dlink_list delay_exit; extern rb_dlink_list delay_exit;
struct ConfItem *find_dline(struct sockaddr *addr);
struct ConfItem *find_dline_exact(struct sockaddr *addr, unsigned int bitlen);
void init_reject(void); void init_reject(void);
int check_reject(struct Client *); int check_reject(struct Client *);
void add_reject(struct Client *, const char *mask1, const char *mask2); void add_reject(struct Client *, const char *mask1, const char *mask2);

View File

@ -416,21 +416,6 @@ find_address_conf(const char *host, const char *sockhost, const char *user,
return iconf; return iconf;
} }
/* struct ConfItem* find_dline(struct rb_sockaddr_storage*, int)
* Input: An address, an address family.
* Output: The best matching D-line or exempt line.
* Side effects: None.
*/
struct ConfItem *
find_dline(struct sockaddr *addr, int aftype)
{
struct ConfItem *eline;
eline = find_conf_by_address(NULL, NULL, NULL, addr, CONF_EXEMPTDLINE | 1, aftype, NULL);
if(eline)
return eline;
return find_conf_by_address(NULL, NULL, NULL, addr, CONF_DLINE | 1, aftype, NULL);
}
/* void find_exact_conf_by_address(const char*, int, const char *) /* void find_exact_conf_by_address(const char*, int, const char *)
* Input: * Input:
* Output: ConfItem if found * Output: ConfItem if found

View File

@ -28,6 +28,8 @@
#include "patricia.h" #include "patricia.h"
#include "client.h" #include "client.h"
#include "s_conf.h" #include "s_conf.h"
#include "event.h"
#include "rb_tools.h"
#include "reject.h" #include "reject.h"
#include "s_stats.h" #include "s_stats.h"
#include "msg.h" #include "msg.h"
@ -98,11 +100,11 @@ reject_expires(void *unused)
pnode = ptr->data; pnode = ptr->data;
rdata = pnode->data; rdata = pnode->data;
if(rdata->time + ConfigFileEntry.reject_duration > rb_current_time()) if(rdata->time + ConfigFileEntry.reject_duration > CurrentTime)
continue; continue;
rb_dlinkDelete(ptr, &reject_list); rb_dlinkDelete(ptr, &reject_list);
rb_free(rdata); MyFree(rdata);
patricia_remove(reject_tree, pnode); patricia_remove(reject_tree, pnode);
} }
} }
@ -112,8 +114,8 @@ init_reject(void)
{ {
reject_tree = New_Patricia(PATRICIA_BITS); reject_tree = New_Patricia(PATRICIA_BITS);
unknown_tree = New_Patricia(PATRICIA_BITS); unknown_tree = New_Patricia(PATRICIA_BITS);
rb_event_add("reject_exit", reject_exit, NULL, DELAYED_EXIT_TIME); eventAdd("reject_exit", reject_exit, NULL, DELAYED_EXIT_TIME);
rb_event_add("reject_expires", reject_expires, NULL, 60); eventAdd("reject_expires", reject_expires, NULL, 60);
} }
@ -137,7 +139,7 @@ add_reject(struct Client *client_p, const char *mask1, const char *mask2)
if((pnode = match_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip)) != NULL) if((pnode = match_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip)) != NULL)
{ {
rdata = pnode->data; rdata = pnode->data;
rdata->time = rb_current_time(); rdata->time = CurrentTime;
rdata->count++; rdata->count++;
} }
else else
@ -148,9 +150,9 @@ add_reject(struct Client *client_p, const char *mask1, const char *mask2)
bitlen = 128; bitlen = 128;
#endif #endif
pnode = make_and_lookup_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip, bitlen); pnode = make_and_lookup_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip, bitlen);
pnode->data = rdata = rb_malloc(sizeof(struct reject_data)); pnode->data = rdata = MyMalloc(sizeof(struct reject_data));
rb_dlinkAddTail(pnode, &rdata->rnode, &reject_list); rb_dlinkAddTail(pnode, &rdata->rnode, &reject_list);
rdata->time = rb_current_time(); rdata->time = CurrentTime;
rdata->count = 1; rdata->count = 1;
} }
rdata->mask_hashv = hashv; rdata->mask_hashv = hashv;
@ -172,7 +174,7 @@ check_reject(struct Client *client_p)
{ {
rdata = pnode->data; rdata = pnode->data;
rdata->time = rb_current_time(); rdata->time = CurrentTime;
if(rdata->count > ConfigFileEntry.reject_after_count) if(rdata->count > ConfigFileEntry.reject_after_count)
{ {
ServerStats->is_rej++; ServerStats->is_rej++;
@ -199,7 +201,7 @@ flush_reject(void)
pnode = ptr->data; pnode = ptr->data;
rdata = pnode->data; rdata = pnode->data;
rb_dlinkDelete(ptr, &reject_list); rb_dlinkDelete(ptr, &reject_list);
rb_free(rdata); MyFree(rdata);
patricia_remove(reject_tree, pnode); patricia_remove(reject_tree, pnode);
} }
} }
@ -218,7 +220,7 @@ remove_reject_ip(const char *ip)
{ {
struct reject_data *rdata = pnode->data; struct reject_data *rdata = pnode->data;
rb_dlinkDelete(&rdata->rnode, &reject_list); rb_dlinkDelete(&rdata->rnode, &reject_list);
rb_free(rdata); MyFree(rdata);
patricia_remove(reject_tree, pnode); patricia_remove(reject_tree, pnode);
return 1; return 1;
} }
@ -246,7 +248,7 @@ remove_reject_mask(const char *mask1, const char *mask2)
if (rdata->mask_hashv == hashv) if (rdata->mask_hashv == hashv)
{ {
rb_dlinkDelete(ptr, &reject_list); rb_dlinkDelete(ptr, &reject_list);
rb_free(rdata); MyFree(rdata);
patricia_remove(reject_tree, pnode); patricia_remove(reject_tree, pnode);
n++; n++;
} }