| 55 |
|
hash = ((ip >> 12) + ip) & (IP_HASH_SIZE - 1); |
| 56 |
|
return hash; |
| 57 |
|
} |
| 58 |
– |
#ifdef IPV6 |
| 58 |
|
else |
| 59 |
|
{ |
| 60 |
|
const struct sockaddr_in6 *v6 = (const struct sockaddr_in6 *)addr; |
| 66 |
|
hash = hash & (IP_HASH_SIZE - 1); |
| 67 |
|
return hash; |
| 68 |
|
} |
| 70 |
– |
#else |
| 71 |
– |
return 0; |
| 72 |
– |
#endif |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
/* ipcache_find_or_add_address() |
| 83 |
|
dlink_node *ptr = NULL; |
| 84 |
|
struct ip_entry *iptr = NULL; |
| 85 |
|
uint32_t hash_index = ipcache_hash_address(addr); |
| 90 |
– |
int res = 0; |
| 86 |
|
struct sockaddr_in *v4 = (struct sockaddr_in *)addr, *ptr_v4; |
| 92 |
– |
#ifdef IPV6 |
| 87 |
|
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr, *ptr_v6; |
| 94 |
– |
#endif |
| 88 |
|
|
| 89 |
|
DLINK_FOREACH(ptr, ip_hash_table[hash_index].head) |
| 90 |
|
{ |
| 91 |
|
iptr = ptr->data; |
| 92 |
< |
#ifdef IPV6 |
| 92 |
> |
|
| 93 |
|
if (iptr->ip.ss.ss_family != addr->ss.ss_family) |
| 94 |
|
continue; |
| 95 |
|
|
| 96 |
|
if (addr->ss.ss_family == AF_INET6) |
| 97 |
|
{ |
| 98 |
|
ptr_v6 = (struct sockaddr_in6 *)&iptr->ip; |
| 99 |
< |
res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr)); |
| 99 |
> |
if (!memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr))) |
| 100 |
> |
return iptr; /* Found entry already in hash, return it. */ |
| 101 |
|
} |
| 102 |
|
else |
| 109 |
– |
#endif |
| 103 |
|
{ |
| 104 |
|
ptr_v4 = (struct sockaddr_in *)&iptr->ip; |
| 105 |
< |
res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr)); |
| 105 |
> |
if (!memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr))) |
| 106 |
> |
return iptr; /* Found entry already in hash, return it. */ |
| 107 |
|
} |
| 114 |
– |
|
| 115 |
– |
if (res == 0) |
| 116 |
– |
return iptr; /* Found entry already in hash, return it. */ |
| 108 |
|
} |
| 109 |
|
|
| 110 |
|
iptr = mp_pool_get(ip_entry_pool); |
| 129 |
|
{ |
| 130 |
|
dlink_node *ptr = NULL; |
| 131 |
|
uint32_t hash_index = ipcache_hash_address(addr); |
| 141 |
– |
int res = 0; |
| 132 |
|
struct sockaddr_in *v4 = (struct sockaddr_in *)addr, *ptr_v4; |
| 143 |
– |
#ifdef IPV6 |
| 133 |
|
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr, *ptr_v6; |
| 145 |
– |
#endif |
| 134 |
|
|
| 135 |
|
DLINK_FOREACH(ptr, ip_hash_table[hash_index].head) |
| 136 |
|
{ |
| 137 |
|
struct ip_entry *iptr = ptr->data; |
| 138 |
< |
#ifdef IPV6 |
| 138 |
> |
|
| 139 |
|
if (iptr->ip.ss.ss_family != addr->ss.ss_family) |
| 140 |
|
continue; |
| 141 |
+ |
|
| 142 |
|
if (addr->ss.ss_family == AF_INET6) |
| 143 |
|
{ |
| 144 |
|
ptr_v6 = (struct sockaddr_in6 *)&iptr->ip; |
| 145 |
< |
res = memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr)); |
| 145 |
> |
if (memcmp(&v6->sin6_addr, &ptr_v6->sin6_addr, sizeof(struct in6_addr))) |
| 146 |
> |
continue; |
| 147 |
|
} |
| 148 |
|
else |
| 159 |
– |
#endif |
| 149 |
|
{ |
| 150 |
|
ptr_v4 = (struct sockaddr_in *)&iptr->ip; |
| 151 |
< |
res = memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr)); |
| 151 |
> |
if (memcmp(&v4->sin_addr, &ptr_v4->sin_addr, sizeof(struct in_addr))) |
| 152 |
> |
continue; |
| 153 |
|
} |
| 154 |
|
|
| 165 |
– |
if (res) |
| 166 |
– |
continue; |
| 155 |
|
assert(iptr->count > 0); |
| 156 |
|
|
| 157 |
|
if (--iptr->count == 0 && |
| 158 |
< |
(CurrentTime - iptr->last_attempt) >= ConfigFileEntry.throttle_time) |
| 158 |
> |
(CurrentTime - iptr->last_attempt) >= ConfigGeneral.throttle_time) |
| 159 |
|
{ |
| 160 |
|
dlinkDelete(&iptr->node, &ip_hash_table[hash_index]); |
| 161 |
|
mp_pool_release(iptr); |
| 182 |
|
struct ip_entry *iptr = ptr->data; |
| 183 |
|
|
| 184 |
|
if (iptr->count == 0 && |
| 185 |
< |
(CurrentTime - iptr->last_attempt) >= ConfigFileEntry.throttle_time) |
| 185 |
> |
(CurrentTime - iptr->last_attempt) >= ConfigGeneral.throttle_time) |
| 186 |
|
{ |
| 187 |
|
dlinkDelete(&iptr->node, &ip_hash_table[i]); |
| 188 |
|
mp_pool_release(iptr); |