Commit 3b02b0ad authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso

netfilter: nft_set_hash: fix lookups with fixed size hash on big endian

Call jhash_1word() for the 4-bytes key case from the insertion and
deactivation path, otherwise big endian arch set lookups fail.

Fixes: 446a8268 ("netfilter: nft_set_hash: add lookup variant for fixed size hashtable")
Reported-by: default avatarFlorian Westphal <fw@strlen.de>
Tested-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 35acfbab
...@@ -474,6 +474,23 @@ static bool nft_hash_lookup_fast(const struct net *net, ...@@ -474,6 +474,23 @@ static bool nft_hash_lookup_fast(const struct net *net,
return false; return false;
} }
static u32 nft_jhash(const struct nft_set *set, const struct nft_hash *priv,
const struct nft_set_ext *ext)
{
const struct nft_data *key = nft_set_ext_key(ext);
u32 hash, k1;
if (set->klen == 4) {
k1 = *(u32 *)key;
hash = jhash_1word(k1, priv->seed);
} else {
hash = jhash(key, set->klen, priv->seed);
}
hash = reciprocal_scale(hash, priv->buckets);
return hash;
}
static int nft_hash_insert(const struct net *net, const struct nft_set *set, static int nft_hash_insert(const struct net *net, const struct nft_set *set,
const struct nft_set_elem *elem, const struct nft_set_elem *elem,
struct nft_set_ext **ext) struct nft_set_ext **ext)
...@@ -483,8 +500,7 @@ static int nft_hash_insert(const struct net *net, const struct nft_set *set, ...@@ -483,8 +500,7 @@ static int nft_hash_insert(const struct net *net, const struct nft_set *set,
u8 genmask = nft_genmask_next(net); u8 genmask = nft_genmask_next(net);
u32 hash; u32 hash;
hash = jhash(nft_set_ext_key(&this->ext), set->klen, priv->seed); hash = nft_jhash(set, priv, &this->ext);
hash = reciprocal_scale(hash, priv->buckets);
hlist_for_each_entry(he, &priv->table[hash], node) { hlist_for_each_entry(he, &priv->table[hash], node) {
if (!memcmp(nft_set_ext_key(&this->ext), if (!memcmp(nft_set_ext_key(&this->ext),
nft_set_ext_key(&he->ext), set->klen) && nft_set_ext_key(&he->ext), set->klen) &&
...@@ -523,8 +539,7 @@ static void *nft_hash_deactivate(const struct net *net, ...@@ -523,8 +539,7 @@ static void *nft_hash_deactivate(const struct net *net,
u8 genmask = nft_genmask_next(net); u8 genmask = nft_genmask_next(net);
u32 hash; u32 hash;
hash = jhash(nft_set_ext_key(&this->ext), set->klen, priv->seed); hash = nft_jhash(set, priv, &this->ext);
hash = reciprocal_scale(hash, priv->buckets);
hlist_for_each_entry(he, &priv->table[hash], node) { hlist_for_each_entry(he, &priv->table[hash], node) {
if (!memcmp(nft_set_ext_key(&this->ext), &elem->key.val, if (!memcmp(nft_set_ext_key(&this->ext), &elem->key.val,
set->klen) && set->klen) &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment