1 |
|
/* |
2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (c) 1997-2018 ircd-hybrid development team |
4 |
> |
* Copyright (c) 1997-2019 ircd-hybrid development team |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
35 |
|
|
36 |
|
|
37 |
|
static dlink_list ipcache_list; |
38 |
< |
static patricia_tree_t *ipcache_trie; |
38 |
> |
static patricia_tree_t *ipcache_trie_v6; |
39 |
> |
static patricia_tree_t *ipcache_trie_v4; |
40 |
|
|
41 |
|
|
42 |
+ |
static void * |
43 |
+ |
ipcache_get_trie(void *addr) |
44 |
+ |
{ |
45 |
+ |
if (((struct sockaddr *)addr)->sa_family == AF_INET6) |
46 |
+ |
return ipcache_trie_v6; |
47 |
+ |
else |
48 |
+ |
return ipcache_trie_v4; |
49 |
+ |
} |
50 |
+ |
|
51 |
|
/* ipcache_find_or_add_address() |
52 |
|
* |
53 |
|
* inputs - pointer to struct irc_ssaddr |
60 |
|
struct ip_entry * |
61 |
|
ipcache_record_find_or_add(void *addr) |
62 |
|
{ |
63 |
< |
patricia_node_t *pnode = patricia_make_and_lookup_addr(ipcache_trie, addr, 0); |
63 |
> |
patricia_tree_t *ptrie = ipcache_get_trie(addr); |
64 |
> |
patricia_node_t *pnode = patricia_make_and_lookup_addr(ptrie, addr, 0); |
65 |
|
|
66 |
|
if (pnode->data) /* Deliberate crash if 'pnode' is NULL */ |
67 |
|
return pnode->data; /* Already added to the trie */ |
68 |
|
|
69 |
|
struct ip_entry *iptr = xcalloc(sizeof(*iptr)); |
70 |
+ |
iptr->trie_pointer = ptrie; |
71 |
|
dlinkAdd(pnode, &iptr->node, &ipcache_list); |
72 |
|
|
73 |
|
PATRICIA_DATA_SET(pnode, iptr); |
83 |
|
if (iptr->count_local == 0 && iptr->count_remote == 0 && |
84 |
|
(CurrentTime - iptr->last_attempt) >= ConfigGeneral.throttle_time) |
85 |
|
{ |
86 |
+ |
patricia_remove(iptr->trie_pointer, pnode); |
87 |
+ |
|
88 |
|
dlinkDelete(&iptr->node, &ipcache_list); |
89 |
|
xfree(iptr); |
76 |
– |
|
77 |
– |
patricia_remove(ipcache_trie, pnode); |
90 |
|
} |
91 |
|
} |
92 |
|
|
102 |
|
void |
103 |
|
ipcache_record_remove(void *addr, int local) |
104 |
|
{ |
105 |
< |
patricia_node_t *pnode = patricia_try_search_exact_addr(ipcache_trie, addr, 0); |
105 |
> |
patricia_node_t *pnode = patricia_try_search_exact_addr(ipcache_get_trie(addr), addr, 0); |
106 |
|
|
107 |
|
if (pnode == NULL) |
108 |
|
return; |
161 |
|
.when = 123 |
162 |
|
}; |
163 |
|
|
164 |
< |
ipcache_trie = patricia_new(PATRICIA_MAXBITS); |
164 |
> |
ipcache_trie_v6 = patricia_new(128); |
165 |
> |
ipcache_trie_v4 = patricia_new( 32); |
166 |
|
|
167 |
|
event_add(&event_expire_ipcache, NULL); |
168 |
|
} |