[ovs-dev] [PATCH] datapath: Fix tunnel hashing.
Pravin B Shelar
pshelar at nicira.com
Tue Oct 4 13:20:52 PDT 2011
Following patch fixes tunnel hashing bug by using correct key length.
This bug was introduced by commit f686a33af8cb41ee228e6a35410c9a488fba3eb1
Signed-off-by: Pravin B Shelar <pshelar at nicira.com>
---
datapath/tunnel.c | 7 +++++--
datapath/tunnel.h | 2 ++
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/datapath/tunnel.c b/datapath/tunnel.c
index 100794e..81b97d3 100644
--- a/datapath/tunnel.c
+++ b/datapath/tunnel.c
@@ -174,7 +174,7 @@ static unsigned int *find_port_pool(const struct tnl_mutable_config *mutable)
static u32 port_hash(const struct port_lookup_key *key)
{
- return jhash2((u32*)key, (sizeof(*key) / sizeof(u32)), 0);
+ return jhash2((u32*)key, (PORT_KEY_LEN / sizeof(u32)), 0);
}
static inline struct hlist_head *find_bucket(u32 hash)
@@ -241,7 +241,7 @@ static struct tnl_vport *port_table_lookup(struct port_lookup_key *key,
struct tnl_mutable_config *mutable;
mutable = rcu_dereference_rtnl(tnl_vport->mutable);
- if (!memcmp(&mutable->key, key, sizeof(*key))) {
+ if (!memcmp(&mutable->key, key, PORT_KEY_LEN)) {
*pmutable = mutable;
return tnl_vport;
}
@@ -1512,6 +1512,9 @@ int tnl_init(void)
{
int i;
+ BUILD_BUG_ON(PORT_KEY_LEN !=
+ (offsetof(struct port_lookup_key, tunnel_type) + sizeof(u32)));
+
port_table = kmalloc(PORT_TABLE_SIZE * sizeof(struct hlist_head *),
GFP_KERNEL);
if (!port_table)
diff --git a/datapath/tunnel.h b/datapath/tunnel.h
index b3e21fa..7149319 100644
--- a/datapath/tunnel.h
+++ b/datapath/tunnel.h
@@ -58,6 +58,8 @@ struct port_lookup_key {
u32 tunnel_type;
};
+#define PORT_KEY_LEN 20
+
/**
* struct tnl_mutable_config - modifiable configuration for a tunnel.
* @key: Used as key for tunnel port. Configured via OVS_TUNNEL_ATTR_*
--
1.7.1
More information about the dev
mailing list