mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-03 17:35:06 -05:00
util: add function for IP address hashing
Move the hashing function from find_slot() in ntp_sources to make it available to clientlog and improve the hashing a bit.
This commit is contained in:
@@ -202,26 +202,16 @@ find_slot(NTP_Remote_Address *remote_addr, int *slot, int *found)
|
||||
uint32_t hash;
|
||||
unsigned int i, size;
|
||||
unsigned short port;
|
||||
uint8_t *ip6;
|
||||
|
||||
size = ARR_GetSize(records);
|
||||
|
||||
switch (remote_addr->ip_addr.family) {
|
||||
case IPADDR_INET6:
|
||||
ip6 = remote_addr->ip_addr.addr.in6;
|
||||
hash = (ip6[0] ^ ip6[4] ^ ip6[8] ^ ip6[12]) |
|
||||
(ip6[1] ^ ip6[5] ^ ip6[9] ^ ip6[13]) << 8 |
|
||||
(ip6[2] ^ ip6[6] ^ ip6[10] ^ ip6[14]) << 16 |
|
||||
(ip6[3] ^ ip6[7] ^ ip6[11] ^ ip6[15]) << 24;
|
||||
break;
|
||||
case IPADDR_INET4:
|
||||
hash = remote_addr->ip_addr.addr.in4;
|
||||
break;
|
||||
default:
|
||||
*found = *slot = 0;
|
||||
return;
|
||||
if (remote_addr->ip_addr.family != IPADDR_INET4 &&
|
||||
remote_addr->ip_addr.family != IPADDR_INET6) {
|
||||
*found = *slot = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
hash = UTI_IPToHash(&remote_addr->ip_addr);
|
||||
port = remote_addr->port;
|
||||
|
||||
for (i = 0; i < size / 2; i++) {
|
||||
|
||||
Reference in New Issue
Block a user