netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 1/2] segtree: only use prefix expressions for ranges for selected datatypes
Date: Thu, 16 Jan 2014 16:21:51 +0000	[thread overview]
Message-ID: <1389889312-4055-2-git-send-email-kaber@trash.net> (raw)
In-Reply-To: <1389889312-4055-1-git-send-email-kaber@trash.net>

It is uncommon to represent f.i. port number ranges as prefix expressions.

Introduce a datatype DTYPE_F_PREFIX flag to indicate that the preferred
representation of a range is a prefix and use it for segtree decomposition
to decide whether to use a range or prefix expression.

The ipaddr, ip6addr, mark and realm datatypes are changed to include the
DTYPE_F_PREFIX flag.

This fixes completely unreadable output in cases where the ranges are
representable as prefixes, f.i. in case of port number:

{ 0/6 => jump chain1, 0/5 => jump chain2, 0/4 => continue}

becomes:

{ 0-1023 => jump chain1, 1024-2047 => jump chain2, 2048-4095 => continue}

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 include/datatype.h | 7 +++++++
 src/datatype.c     | 3 +++
 src/meta.c         | 1 +
 src/segtree.c      | 4 +++-
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/include/datatype.h b/include/datatype.h
index 9f8b44a..9e609cf 100644
--- a/include/datatype.h
+++ b/include/datatype.h
@@ -85,8 +85,15 @@ enum byteorder {
 
 struct expr;
 
+/**
+ * enum datatype_flags
+ *
+ * @DTYPE_F_ALLOC:		datatype is dynamically allocated
+ * @DTYPE_F_PREFIX:		preferred representation for ranges is a prefix
+ */
 enum datatype_flags {
 	DTYPE_F_ALLOC		= (1 << 0),
+	DTYPE_F_PREFIX		= (1 << 1),
 };
 
 /**
diff --git a/src/datatype.c b/src/datatype.c
index e228f53..5e4aacd 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -398,6 +398,7 @@ const struct datatype ipaddr_type = {
 	.basetype	= &integer_type,
 	.print		= ipaddr_type_print,
 	.parse		= ipaddr_type_parse,
+	.flags		= DTYPE_F_PREFIX,
 };
 
 static void ip6addr_type_print(const struct expr *expr)
@@ -455,6 +456,7 @@ const struct datatype ip6addr_type = {
 	.basetype	= &integer_type,
 	.print		= ip6addr_type_print,
 	.parse		= ip6addr_type_parse,
+	.flags		= DTYPE_F_PREFIX,
 };
 
 static void inet_protocol_type_print(const struct expr *expr)
@@ -680,6 +682,7 @@ const struct datatype mark_type = {
 	.basefmt	= "0x%.8Zx",
 	.print		= mark_type_print,
 	.parse		= mark_type_parse,
+	.flags		= DTYPE_F_PREFIX,
 };
 
 static void time_type_print(const struct expr *expr)
diff --git a/src/meta.c b/src/meta.c
index 098728b..0a3df39 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -61,6 +61,7 @@ static const struct datatype realm_type = {
 	.basetype	= &integer_type,
 	.print		= realm_type_print,
 	.parse		= realm_type_parse,
+	.flags		= DTYPE_F_PREFIX,
 };
 
 static void tchandle_type_print(const struct expr *expr)
diff --git a/src/segtree.c b/src/segtree.c
index 5426e24..e3bca4c 100644
--- a/src/segtree.c
+++ b/src/segtree.c
@@ -552,7 +552,9 @@ void interval_map_decompose(struct expr *set)
 
 		if (!mpz_cmp_ui(range, 0))
 			compound_expr_add(set, low);
-		else if (!range_is_prefix(range) || mpz_cmp_ui(p, 0)) {
+		else if ((!range_is_prefix(range) ||
+			  !(i->dtype->flags & DTYPE_F_PREFIX)) ||
+			 mpz_cmp_ui(p, 0)) {
 			struct expr *tmp;
 
 			tmp = constant_expr_alloc(&low->location, low->dtype,
-- 
1.8.4.2


  reply	other threads:[~2014-01-16 16:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-16 16:21 [PATCH 0/2]: nftables: segtree fixes Patrick McHardy
2014-01-16 16:21 ` Patrick McHardy [this message]
2014-01-16 16:21 ` [PATCH 2/2] segtree: fix decomposition of unclosed intervals Patrick McHardy

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=1389889312-4055-2-git-send-email-kaber@trash.net \
    --to=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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).