| 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 |
|
{ |
| 160 |
|
*b = bits; |
| 161 |
|
return HM_IPV6; |
| 162 |
|
} |
| 164 |
– |
#endif |
| 163 |
|
|
| 164 |
|
/* int try_parse_v4_netmask(const char *, struct irc_ssaddr *, int *); |
| 165 |
|
* Input: A possible IPV4 address as a string. |
| 251 |
|
{ |
| 252 |
|
if (strchr(text, '.')) |
| 253 |
|
return try_parse_v4_netmask(text, addr, b); |
| 256 |
– |
#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 |
|
*/ |
| 269 |
– |
#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 |
|
} |
| 288 |
– |
#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; |
| 319 |
– |
#ifdef IPV6 |
| 314 |
|
struct sockaddr_in6 *v6_base_ip; |
| 315 |
|
int i, m, n; |
| 322 |
– |
#endif |
| 316 |
|
struct sockaddr_in *v4_base_ip; |
| 317 |
|
|
| 318 |
< |
#ifdef IPV6 |
| 326 |
< |
if (ip->ss.ss_family != AF_INET6) |
| 327 |
< |
#endif |
| 318 |
> |
if (ip->ss.ss_family == AF_INET) |
| 319 |
|
{ |
| 320 |
|
uint32_t tmp = 0; |
| 321 |
|
v4_base_ip = (struct sockaddr_in *)ip; |
| 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 it's used in m_stats.c */ |
| 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. |
| 455 |
|
if (addr) |
| 456 |
|
{ |
| 457 |
|
/* Check for IPV6 matches... */ |
| 470 |
– |
#ifdef IPV6 |
| 458 |
|
if (fam == AF_INET6) |
| 459 |
|
{ |
| 460 |
|
for (b = 128; b >= 0; b -= 16) |
| 478 |
|
} |
| 479 |
|
} |
| 480 |
|
} |
| 481 |
< |
else |
| 495 |
< |
#endif |
| 496 |
< |
if (fam == AF_INET) |
| 481 |
> |
else if (fam == AF_INET) |
| 482 |
|
{ |
| 483 |
|
for (b = 32; b >= 0; b -= 8) |
| 484 |
|
{ |
| 641 |
|
bits -= bits % 8; |
| 642 |
|
dlinkAdd(arec, &arec->node, &atable[hash_ipv4(&arec->Mask.ipa.addr, bits)]); |
| 643 |
|
break; |
| 659 |
– |
#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; |
| 665 |
– |
#endif |
| 649 |
|
default: /* HM_HOST */ |
| 650 |
|
arec->Mask.hostname = hostname; |
| 651 |
|
dlinkAdd(arec, &arec->node, &atable[get_mask_hash(hostname)]); |
| 676 |
|
bits -= bits % 8; |
| 677 |
|
hv = hash_ipv4(&addr, bits); |
| 678 |
|
break; |
| 696 |
– |
#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; |
| 702 |
– |
#endif |
| 684 |
|
default: /* HM_HOST */ |
| 685 |
|
hv = get_mask_hash(address); |
| 686 |
|
break; |