#include <linux/slab.h>
#include <linux/init.h>
#include <linux/tcp.h>
+#include <linux/hash.h>
#include <net/inet_connection_sock.h>
#include <net/net_namespace.h>
return NULL;
}
- hash ^= (hash >> 24) ^ (hash >> 16) ^ (hash >> 8);
-
net = dev_net(dst->dev);
- hash &= net->ipv4.tcp_metrics_hash_mask;
+ hash = hash_32(hash, net->ipv4.tcp_metrics_hash_log);
for (tm = rcu_dereference(net->ipv4.tcp_metrics_hash[hash].chain); tm;
tm = rcu_dereference(tm->tcpm_next)) {
return NULL;
}
- hash ^= (hash >> 24) ^ (hash >> 16) ^ (hash >> 8);
-
net = twsk_net(tw);
- hash &= net->ipv4.tcp_metrics_hash_mask;
+ hash = hash_32(hash, net->ipv4.tcp_metrics_hash_log);
for (tm = rcu_dereference(net->ipv4.tcp_metrics_hash[hash].chain); tm;
tm = rcu_dereference(tm->tcpm_next)) {
return NULL;
}
- hash ^= (hash >> 24) ^ (hash >> 16) ^ (hash >> 8);
-
net = dev_net(dst->dev);
- hash &= net->ipv4.tcp_metrics_hash_mask;
+ hash = hash_32(hash, net->ipv4.tcp_metrics_hash_log);
tm = __tcp_get_metrics(&addr, net, hash);
reclaim = false;
rcu_read_unlock();
}
-static unsigned long tcpmhash_entries;
+static unsigned int tcpmhash_entries;
static int __init set_tcpmhash_entries(char *str)
{
ssize_t ret;
if (!str)
return 0;
- ret = kstrtoul(str, 0, &tcpmhash_entries);
+ ret = kstrtouint(str, 0, &tcpmhash_entries);
if (ret)
return 0;
static int __net_init tcp_net_metrics_init(struct net *net)
{
- int slots, size;
+ size_t size;
+ unsigned int slots;
slots = tcpmhash_entries;
if (!slots) {
slots = 8 * 1024;
}
- size = slots * sizeof(struct tcpm_hash_bucket);
+ net->ipv4.tcp_metrics_hash_log = order_base_2(slots);
+ size = sizeof(struct tcpm_hash_bucket) << net->ipv4.tcp_metrics_hash_log;
net->ipv4.tcp_metrics_hash = kzalloc(size, GFP_KERNEL);
if (!net->ipv4.tcp_metrics_hash)
return -ENOMEM;
- net->ipv4.tcp_metrics_hash_mask = (slots - 1);
-
return 0;
}