* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
- * $Id: reject.c 3446 2007-05-14 22:21:16Z jilles $
+ * $Id: reject.c 3456 2007-05-18 19:14:18Z jilles $
*/
#include "stdinc.h"
#include "reject.h"
#include "s_stats.h"
#include "msg.h"
+#include "hash.h"
static patricia_tree_t *reject_tree;
dlink_list delay_exit;
dlink_node rnode;
time_t time;
unsigned int count;
+ uint32_t mask_hashv;
};
static patricia_tree_t *unknown_tree;
void
-add_reject(struct Client *client_p)
+add_reject(struct Client *client_p, const char *mask1, const char *mask2)
{
patricia_node_t *pnode;
struct reject_data *rdata;
+ uint32_t hashv;
/* Reject is disabled */
if(ConfigFileEntry.reject_after_count == 0 || ConfigFileEntry.reject_ban_time == 0)
return;
+ hashv = 0;
+ if (mask1 != NULL)
+ hashv ^= fnv_hash_upper(mask1, 32);
+ if (mask2 != NULL)
+ hashv ^= fnv_hash_upper(mask2, 32);
+
if((pnode = match_ip(reject_tree, (struct sockaddr *)&client_p->localClient->ip)) != NULL)
{
rdata = pnode->data;
rdata->time = CurrentTime;
rdata->count = 1;
}
+ rdata->mask_hashv = hashv;
}
int
{
ServerStats->is_rej++;
SetReject(client_p);
- comm_setselect(client_p->localClient->fd, FDLIST_NONE, COMM_SELECT_WRITE | COMM_SELECT_READ, NULL, NULL, 0);
+ rb_setselect(client_p->localClient->F->fd, FDLIST_NONE, COMM_SELECT_WRITE | COMM_SELECT_READ, NULL, NULL, 0);
SetClosing(client_p);
dlinkMoveNode(&client_p->localClient->tnode, &unknown_list, &delay_exit);
return 1;
}
int
-remove_reject(const char *ip)
+remove_reject_ip(const char *ip)
{
patricia_node_t *pnode;
return 0;
}
+int
+remove_reject_mask(const char *mask1, const char *mask2)
+{
+ dlink_node *ptr, *next;
+ patricia_node_t *pnode;
+ struct reject_data *rdata;
+ uint32_t hashv;
+ int n = 0;
+
+ hashv = 0;
+ if (mask1 != NULL)
+ hashv ^= fnv_hash_upper(mask1, 32);
+ if (mask2 != NULL)
+ hashv ^= fnv_hash_upper(mask2, 32);
+ DLINK_FOREACH_SAFE(ptr, next, reject_list.head)
+ {
+ pnode = ptr->data;
+ rdata = pnode->data;
+ if (rdata->mask_hashv == hashv)
+ {
+ dlinkDelete(ptr, &reject_list);
+ MyFree(rdata);
+ patricia_remove(reject_tree, pnode);
+ n++;
+ }
+ }
+ return n;
+}
+
int
add_unknown_ip(struct Client *client_p)
{
SetExUnknown(client_p);
SetReject(client_p);
- comm_setselect(client_p->localClient->fd, FDLIST_NONE, COMM_SELECT_WRITE | COMM_SELECT_READ, NULL, NULL, 0);
+ rb_setselect(client_p->localClient->F->fd, FDLIST_NONE, COMM_SELECT_WRITE | COMM_SELECT_READ, NULL, NULL, 0);
SetClosing(client_p);
dlinkMoveNode(&client_p->localClient->tnode, &unknown_list, &delay_exit);
return 1;
patricia_remove(unknown_tree, pnode);
}
}
- /* well..this shouldn't happen */
- s_assert(0);
+ /* this can happen due to m_webirc.c's manipulations, for example */
}