From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: kaber@trash.net, ast@fiberby.dk
Subject: [PATCH 3/5 nft] segtree: when checks when qsorting from interval_map_decompose()
Date: Tue, 19 Jan 2016 18:52:54 +0100 [thread overview]
Message-ID: <1453225976-23749-3-git-send-email-pablo@netfilter.org> (raw)
In-Reply-To: <1453225976-23749-1-git-send-email-pablo@netfilter.org>
If we have two elements with the same key, check the interval flag so we
make sure that the one with the end flag set (ie. closing interval)
comes before the one that starts it.
This is required to decompose adjacent ranges the right way when listing
sets from userspace.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/segtree.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/segtree.c b/src/segtree.c
index 060951c..86c37b4 100644
--- a/src/segtree.c
+++ b/src/segtree.c
@@ -483,8 +483,15 @@ static int expr_value_cmp(const void *p1, const void *p2)
{
struct expr *e1 = *(void * const *)p1;
struct expr *e2 = *(void * const *)p2;
+ int ret;
- return mpz_cmp(expr_value(e1)->value, expr_value(e2)->value);
+ ret = mpz_cmp(expr_value(e1)->value, expr_value(e2)->value);
+ if (ret == 0 && (e1->flags & EXPR_F_INTERVAL_END))
+ return -1;
+ else
+ return 1;
+
+ return ret;
}
void interval_map_decompose(struct expr *set)
--
2.1.4
next prev parent reply other threads:[~2016-01-19 17:53 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-19 17:52 [PATCH 1/5 nf,kernel] netfilter: nft_rbtree: allow adjacent intervals with dynamic updates Pablo Neira Ayuso
2016-01-19 17:52 ` [PATCH 2/5 nft] rule: use netlink_add_setelems() when creating literal sets Pablo Neira Ayuso
2016-01-19 17:52 ` Pablo Neira Ayuso [this message]
2016-01-19 17:52 ` [PATCH 4/5 nft] segtree: pass element expression as parameter to set_to_intervals() Pablo Neira Ayuso
2016-01-19 17:52 ` [PATCH 5/5, nft] rule: allow dynamic updates for intervals in set declarations Pablo Neira Ayuso
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=1453225976-23749-3-git-send-email-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=ast@fiberby.dk \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
/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).