1 |
|
/* |
2 |
|
* ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd) |
3 |
|
* |
4 |
< |
* Copyright (c) 1997-2015 ircd-hybrid development team |
4 |
> |
* Copyright (c) 1997-2018 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 |
37 |
|
static mp_pool_t *ip_entry_pool; |
38 |
|
|
39 |
|
|
40 |
– |
|
40 |
|
/* ipcache_hash_address() |
41 |
|
* |
42 |
|
* input - pointer to an irc_inaddr |
77 |
|
* count set to 0. |
78 |
|
*/ |
79 |
|
struct ip_entry * |
80 |
< |
ipcache_find_or_add_address(struct irc_ssaddr *addr) |
80 |
> |
ipcache_find_or_add_address(const struct irc_ssaddr *addr) |
81 |
|
{ |
82 |
|
dlink_node *node = NULL; |
83 |
|
struct ip_entry *iptr = NULL; |
84 |
|
const uint32_t hash_index = ipcache_hash_address(addr); |
85 |
< |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr, *ptr_v4; |
86 |
< |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr, *ptr_v6; |
85 |
> |
const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr, *ptr_v4; |
86 |
> |
const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr, *ptr_v6; |
87 |
|
|
88 |
|
DLINK_FOREACH(node, ip_hash_table[hash_index].head) |
89 |
|
{ |
94 |
|
|
95 |
|
if (addr->ss.ss_family == AF_INET6) |
96 |
|
{ |
97 |
< |
ptr_v6 = (struct sockaddr_in6 *)&iptr->ip; |
97 |
> |
ptr_v6 = (const struct sockaddr_in6 *)&iptr->ip; |
98 |
|
if (!memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr))) |
99 |
|
return iptr; /* Found entry already in hash, return it. */ |
100 |
|
} |
101 |
|
else |
102 |
|
{ |
103 |
< |
ptr_v4 = (struct sockaddr_in *)&iptr->ip; |
103 |
> |
ptr_v4 = (const struct sockaddr_in *)&iptr->ip; |
104 |
|
if (!memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr))) |
105 |
|
return iptr; /* Found entry already in hash, return it. */ |
106 |
|
} |
124 |
|
* the struct ip_entry is returned to the ip_entry_heap |
125 |
|
*/ |
126 |
|
void |
127 |
< |
ipcache_remove_address(struct irc_ssaddr *addr) |
127 |
> |
ipcache_remove_address(const struct irc_ssaddr *addr) |
128 |
|
{ |
129 |
|
dlink_node *node = NULL; |
130 |
|
const uint32_t hash_index = ipcache_hash_address(addr); |
131 |
< |
struct sockaddr_in *v4 = (struct sockaddr_in *)addr, *ptr_v4; |
132 |
< |
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr, *ptr_v6; |
131 |
> |
const struct sockaddr_in *v4 = (const struct sockaddr_in *)addr, *ptr_v4; |
132 |
> |
const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr, *ptr_v6; |
133 |
|
|
134 |
|
DLINK_FOREACH(node, ip_hash_table[hash_index].head) |
135 |
|
{ |
140 |
|
|
141 |
|
if (addr->ss.ss_family == AF_INET6) |
142 |
|
{ |
143 |
< |
ptr_v6 = (struct sockaddr_in6 *)&iptr->ip; |
143 |
> |
ptr_v6 = (const struct sockaddr_in6 *)&iptr->ip; |
144 |
|
if (memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr))) |
145 |
|
continue; |
146 |
|
} |
147 |
|
else |
148 |
|
{ |
149 |
< |
ptr_v4 = (struct sockaddr_in *)&iptr->ip; |
149 |
> |
ptr_v4 = (const struct sockaddr_in *)&iptr->ip; |
150 |
|
if (memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr))) |
151 |
|
continue; |
152 |
|
} |
201 |
|
* used in the hash. |
202 |
|
*/ |
203 |
|
void |
204 |
< |
ipcache_get_stats(unsigned int *const number_ips_stored, uint64_t *const mem_ips_stored) |
204 |
> |
ipcache_get_stats(unsigned int *const number_ips_stored, size_t *const mem_ips_stored) |
205 |
|
{ |
206 |
|
for (unsigned int i = 0; i < IP_HASH_SIZE; ++i) |
207 |
|
*number_ips_stored += dlink_list_length(&ip_hash_table[i]); |