From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: herbert@gondor.apana.org.au, tgraf@suug.ch
Subject: [PATCH nf-next 1/2] rhashtable: add rhashtable_lookup_get_insert_key()
Date: Wed, 24 Aug 2016 16:23:14 +0200 [thread overview]
Message-ID: <1472048595-7214-1-git-send-email-pablo@netfilter.org> (raw)
This patch modifies __rhashtable_insert_fast() so it returns the
existing element that clashes with the one that you want to insert.
This adds a new rhashtable_lookup_get_insert_key() interface to fetch
this existing element.
nf_tables needs this change to improve handling of EEXIST cases via
honoring the NLM_F_EXCL flag and by checking if the data part of the
mapping matches what we have.
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Thomas Graf <tgraf@suug.ch>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/linux/rhashtable.h | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/include/linux/rhashtable.h b/include/linux/rhashtable.h
index 3eef080..a632cf0 100644
--- a/include/linux/rhashtable.h
+++ b/include/linux/rhashtable.h
@@ -566,7 +566,7 @@ restart:
/* Internal function, please use rhashtable_insert_fast() instead */
static inline int __rhashtable_insert_fast(
struct rhashtable *ht, const void *key, struct rhash_head *obj,
- const struct rhashtable_params params)
+ const struct rhashtable_params params, void **data)
{
struct rhashtable_compare_arg arg = {
.ht = ht,
@@ -630,8 +630,11 @@ slow_path:
if (key &&
unlikely(!(params.obj_cmpfn ?
params.obj_cmpfn(&arg, rht_obj(ht, head)) :
- rhashtable_compare(&arg, rht_obj(ht, head)))))
+ rhashtable_compare(&arg, rht_obj(ht, head))))) {
+ if (data)
+ *data = rht_obj(ht, head);
goto out;
+ }
if (!--elasticity)
goto slow_path;
}
@@ -675,7 +678,7 @@ static inline int rhashtable_insert_fast(
struct rhashtable *ht, struct rhash_head *obj,
const struct rhashtable_params params)
{
- return __rhashtable_insert_fast(ht, NULL, obj, params);
+ return __rhashtable_insert_fast(ht, NULL, obj, params, NULL);
}
/**
@@ -708,7 +711,7 @@ static inline int rhashtable_lookup_insert_fast(
BUG_ON(ht->p.obj_hashfn);
return __rhashtable_insert_fast(ht, key + ht->p.key_offset, obj,
- params);
+ params, NULL);
}
/**
@@ -739,7 +742,26 @@ static inline int rhashtable_lookup_insert_key(
{
BUG_ON(!ht->p.obj_hashfn || !key);
- return __rhashtable_insert_fast(ht, key, obj, params);
+ return __rhashtable_insert_fast(ht, key, obj, params, NULL);
+}
+
+/**
+ * rhashtable_lookup_get_insert_key - lookup and insert object into hash table
+ * @ht: hash table
+ * @obj: pointer to hash head inside object
+ * @params: hash table parameters
+ * @data: pointer to element data already in hashes
+ *
+ * Just like rhashtable_lookup_insert_key(), but it returns the matching
+ * element in case that it already exists in the hashes.
+ */
+static inline int rhashtable_lookup_get_insert_key(
+ struct rhashtable *ht, const void *key, struct rhash_head *obj,
+ const struct rhashtable_params params, void **data)
+{
+ BUG_ON(!ht->p.obj_hashfn || !key);
+
+ return __rhashtable_insert_fast(ht, key, obj, params, data);
}
/* Internal function, please use rhashtable_remove_fast() instead */
--
2.1.4
next reply other threads:[~2016-08-24 14:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-24 14:23 Pablo Neira Ayuso [this message]
2016-08-24 14:23 ` [PATCH nf-next 2/2] netfilter: nf_tables: honor NLM_F_EXCL flag in set element insertion Pablo Neira Ayuso
2016-08-25 4:21 ` [PATCH nf-next 1/2] rhashtable: add rhashtable_lookup_get_insert_key() Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1472048595-7214-1-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=herbert@gondor.apana.org.au \
--cc=netfilter-devel@vger.kernel.org \
--cc=tgraf@suug.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).