15 |
|
* |
16 |
|
* You should have received a copy of the GNU General Public License |
17 |
|
* along with this program; if not, write to the Free Software |
18 |
< |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
18 |
> |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 |
19 |
|
* USA |
20 |
|
*/ |
21 |
|
|
57 |
|
Also a bug in DigitParse above. |
58 |
|
-Gozem 2002-07-19 gozem@linux.nu |
59 |
|
*/ |
60 |
– |
#ifdef IPV6 |
60 |
|
static int |
61 |
|
try_parse_v6_netmask(const char *text, struct irc_ssaddr *addr, int *b) |
62 |
|
{ |
64 |
– |
const char *p; |
63 |
|
char c; |
64 |
|
int d[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
65 |
|
int dp = 0; |
70 |
|
short dc[8]; |
71 |
|
struct sockaddr_in6 *v6 = (struct sockaddr_in6 *)addr; |
72 |
|
|
73 |
< |
for (p = text; (c = *p); ++p) |
73 |
> |
for (const char *p = text; (c = *p); ++p) |
74 |
|
{ |
75 |
|
if (IsXDigit(c)) |
76 |
|
{ |
160 |
|
*b = bits; |
161 |
|
return HM_IPV6; |
162 |
|
} |
165 |
– |
#endif |
163 |
|
|
164 |
|
/* int try_parse_v4_netmask(const char *, struct irc_ssaddr *, int *); |
165 |
|
* Input: A possible IPV4 address as a string. |
171 |
|
static int |
172 |
|
try_parse_v4_netmask(const char *text, struct irc_ssaddr *addr, int *b) |
173 |
|
{ |
177 |
– |
const char *p; |
174 |
|
const char *digits[4]; |
175 |
|
unsigned char addb[4]; |
176 |
|
int n = 0, bits = 0; |
179 |
|
|
180 |
|
digits[n++] = text; |
181 |
|
|
182 |
< |
for (p = text; (c = *p); ++p) |
182 |
> |
for (const char *p = text; (c = *p); ++p) |
183 |
|
{ |
184 |
|
if (c >= '0' && c <= '9') /* empty */ |
185 |
|
; |
251 |
|
{ |
252 |
|
if (strchr(text, '.')) |
253 |
|
return try_parse_v4_netmask(text, addr, b); |
258 |
– |
#ifdef IPV6 |
254 |
|
if (strchr(text, ':')) |
255 |
|
return try_parse_v6_netmask(text, addr, b); |
256 |
< |
#endif |
256 |
> |
|
257 |
|
return HM_HOST; |
258 |
|
} |
259 |
|
|
263 |
|
* Output: if match, -1 else 0 |
264 |
|
* Side effects: None |
265 |
|
*/ |
271 |
– |
#ifdef IPV6 |
266 |
|
int |
267 |
|
match_ipv6(const struct irc_ssaddr *addr, const struct irc_ssaddr *mask, int bits) |
268 |
|
{ |
281 |
|
return -1; |
282 |
|
return 0; |
283 |
|
} |
290 |
– |
#endif |
284 |
|
|
285 |
|
/* int match_ipv4(struct irc_ssaddr *, struct irc_ssaddr *, int) |
286 |
|
* Input: An IP address, an IP mask, the number of bits in the mask. |
311 |
|
mask_addr(struct irc_ssaddr *ip, int bits) |
312 |
|
{ |
313 |
|
int mask; |
321 |
– |
#ifdef IPV6 |
314 |
|
struct sockaddr_in6 *v6_base_ip; |
315 |
|
int i, m, n; |
324 |
– |
#endif |
316 |
|
struct sockaddr_in *v4_base_ip; |
317 |
|
|
318 |
< |
#ifdef IPV6 |
328 |
< |
if (ip->ss.ss_family != AF_INET6) |
329 |
< |
#endif |
318 |
> |
if (ip->ss.ss_family == AF_INET) |
319 |
|
{ |
320 |
+ |
uint32_t tmp = 0; |
321 |
|
v4_base_ip = (struct sockaddr_in *)ip; |
322 |
|
|
323 |
|
mask = ~((1 << (32 - bits)) - 1); |
324 |
< |
v4_base_ip->sin_addr.s_addr = htonl(ntohl(v4_base_ip->sin_addr.s_addr) & mask); |
324 |
> |
tmp = ntohl(v4_base_ip->sin_addr.s_addr); |
325 |
> |
v4_base_ip->sin_addr.s_addr = htonl(tmp & mask); |
326 |
|
} |
336 |
– |
#ifdef IPV6 |
327 |
|
else |
328 |
|
{ |
329 |
|
n = bits / 8; |
336 |
|
for (i = n + 1; i < 16; i++) |
337 |
|
v6_base_ip->sin6_addr.s6_addr[i] = 0; |
338 |
|
} |
349 |
– |
#endif |
339 |
|
} |
340 |
|
|
341 |
< |
/* Hashtable stuff...now external as its used in m_stats.c */ |
341 |
> |
/* Hashtable stuff...now external as it's used in m_stats.c */ |
342 |
|
dlink_list atable[ATABLE_SIZE]; |
343 |
|
|
344 |
|
void |
371 |
|
* Output: A hash value of the IP address. |
372 |
|
* Side effects: None |
373 |
|
*/ |
385 |
– |
#ifdef IPV6 |
374 |
|
static uint32_t |
375 |
|
hash_ipv6(const struct irc_ssaddr *addr, int bits) |
376 |
|
{ |
392 |
|
else |
393 |
|
return v & (ATABLE_SIZE - 1); |
394 |
|
} |
395 |
+ |
|
396 |
|
return v & (ATABLE_SIZE - 1); |
397 |
|
} |
409 |
– |
#endif |
398 |
|
|
399 |
|
/* int hash_text(const char *start) |
400 |
|
* Input: The start of the text to hash. |
404 |
|
static uint32_t |
405 |
|
hash_text(const char *start) |
406 |
|
{ |
419 |
– |
const char *p = start; |
407 |
|
uint32_t h = 0; |
408 |
|
|
409 |
< |
for (; *p; ++p) |
409 |
> |
for (const char *p = start; *p; ++p) |
410 |
|
h = (h << 4) - (h + ToLower(*p)); |
411 |
|
|
412 |
|
return h & (ATABLE_SIZE - 1); |
455 |
|
if (addr) |
456 |
|
{ |
457 |
|
/* Check for IPV6 matches... */ |
471 |
– |
#ifdef IPV6 |
458 |
|
if (fam == AF_INET6) |
459 |
|
{ |
460 |
|
for (b = 128; b >= 0; b -= 16) |
478 |
|
} |
479 |
|
} |
480 |
|
} |
481 |
< |
else |
496 |
< |
#endif |
497 |
< |
if (fam == AF_INET) |
481 |
> |
else if (fam == AF_INET) |
482 |
|
{ |
483 |
|
for (b = 32; b >= 0; b -= 8) |
484 |
|
{ |
558 |
|
* Side-effects: None |
559 |
|
*/ |
560 |
|
struct MaskItem * |
561 |
< |
find_address_conf(const char *host, const char *user, |
562 |
< |
struct irc_ssaddr *ip, int aftype, char *password) |
561 |
> |
find_address_conf(const char *host, const char *user, struct irc_ssaddr *ip, |
562 |
> |
int aftype, const char *password) |
563 |
|
{ |
564 |
|
struct MaskItem *authcnf = NULL, *killcnf = NULL; |
565 |
|
|
626 |
|
|
627 |
|
assert(type && !EmptyString(hostname)); |
628 |
|
|
629 |
< |
arec = MyMalloc(sizeof(struct AddressRec)); |
629 |
> |
arec = MyCalloc(sizeof(struct AddressRec)); |
630 |
|
arec->masktype = parse_netmask(hostname, &arec->Mask.ipa.addr, &bits); |
631 |
|
arec->Mask.ipa.bits = bits; |
632 |
|
arec->username = username; |
641 |
|
bits -= bits % 8; |
642 |
|
dlinkAdd(arec, &arec->node, &atable[hash_ipv4(&arec->Mask.ipa.addr, bits)]); |
643 |
|
break; |
660 |
– |
#ifdef IPV6 |
644 |
|
case HM_IPV6: |
645 |
|
/* We have to do this, since we do not re-hash for every bit -A1kmm. */ |
646 |
|
bits -= bits % 16; |
647 |
|
dlinkAdd(arec, &arec->node, &atable[hash_ipv6(&arec->Mask.ipa.addr, bits)]); |
648 |
|
break; |
666 |
– |
#endif |
649 |
|
default: /* HM_HOST */ |
650 |
|
arec->Mask.hostname = hostname; |
651 |
|
dlinkAdd(arec, &arec->node, &atable[get_mask_hash(hostname)]); |
666 |
|
{ |
667 |
|
int bits = 0; |
668 |
|
uint32_t hv = 0; |
669 |
< |
dlink_node *ptr = NULL, *ptr_next = NULL; |
669 |
> |
dlink_node *ptr = NULL; |
670 |
|
struct irc_ssaddr addr; |
671 |
|
|
672 |
|
switch (parse_netmask(address, &addr, &bits)) |
676 |
|
bits -= bits % 8; |
677 |
|
hv = hash_ipv4(&addr, bits); |
678 |
|
break; |
697 |
– |
#ifdef IPV6 |
679 |
|
case HM_IPV6: |
680 |
|
/* We have to do this, since we do not re-hash for every bit -A1kmm. */ |
681 |
|
bits -= bits % 16; |
682 |
|
hv = hash_ipv6(&addr, bits); |
683 |
|
break; |
703 |
– |
#endif |
684 |
|
default: /* HM_HOST */ |
685 |
|
hv = get_mask_hash(address); |
686 |
|
break; |
687 |
|
} |
688 |
|
|
689 |
< |
DLINK_FOREACH_SAFE(ptr, ptr_next, atable[hv].head) |
689 |
> |
DLINK_FOREACH(ptr, atable[hv].head) |
690 |
|
{ |
691 |
|
struct AddressRec *arec = ptr->data; |
692 |
|
|
729 |
|
continue; |
730 |
|
|
731 |
|
dlinkDelete(&arec->node, &atable[i]); |
732 |
+ |
arec->conf->active = 0; |
733 |
|
|
734 |
|
if (!arec->conf->ref_count) |
735 |
|
conf_free(arec->conf); |
743 |
|
{ |
744 |
|
char ban_type = '\0'; |
745 |
|
|
746 |
< |
if (!ConfigFileEntry.tkline_expire_notices) |
746 |
> |
if (!ConfigGeneral.tkline_expire_notices) |
747 |
|
return; |
748 |
|
|
749 |
|
switch (arec->type) |