netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Leblond <eric@regit.org>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org, Eric Leblond <eric@regit.org>
Subject: [nft PATCH 3/3] netlink_delinearize: fix postprocessing
Date: Thu, 26 Feb 2015 00:51:10 +0100	[thread overview]
Message-ID: <1424908270-554-4-git-send-email-eric@regit.org> (raw)
In-Reply-To: <1424908270-554-1-git-send-email-eric@regit.org>

The following rule:
  ip protocol tcp counter packets 0 bytes 0 tcp dport ssh accept

is build in byte code as:

  ip test filter
    [ payload load 1b @ network header + 9 => reg 1 ]
    [ cmp eq reg 1 0x00000006 ]
    [ counter pkts 0 bytes 0 ]
    [ payload load 2b @ transport header + 2 => reg 1 ]
    [ cmp eq reg 1 0x00001600 ]
    [ immediate reg 0 accept ]

But the simplication process is reverting it to:
  counter tcp dport ssh accept

Which is different rule.

This patch is fixing the issue by resetting the dependency when we
are seeing a counter statement.

Signed-off-by: Eric Leblond <eric@regit.org>
---
 src/netlink_delinearize.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index 387bb67..181942b 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -770,6 +770,12 @@ static void payload_dependency_store(struct rule_pp_ctx *ctx,
 	ctx->pdep  = stmt;
 }
 
+static void payload_dependency_reset(struct rule_pp_ctx *ctx)
+{
+	ctx->pbase = PROTO_BASE_INVALID;
+	ctx->pdep  = NULL;
+}
+
 static void integer_type_postprocess(struct expr *expr)
 {
 	struct expr *i;
@@ -1137,6 +1143,9 @@ static void rule_parse_postprocess(struct netlink_parse_ctx *ctx, struct rule *r
 		case STMT_REJECT:
 			stmt_reject_postprocess(rctx, stmt);
 			break;
+		case STMT_COUNTER:
+			payload_dependency_reset(&rctx);
+			break;
 		default:
 			break;
 		}
-- 
2.1.4


  parent reply	other threads:[~2015-02-26  0:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-25 23:51 [nft PATCH 0/3] fix a delinearization issue Eric Leblond
2015-02-25 23:51 ` [nft PATCH 1/3] regression: fix typo in README Eric Leblond
2015-02-25 23:51 ` [nft PATCH 2/3] regression: add test on counter related issue Eric Leblond
2015-02-25 23:51 ` Eric Leblond [this message]
2015-02-26  8:40   ` [nft PATCH 3/3] netlink_delinearize: fix postprocessing 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=1424908270-554-4-git-send-email-eric@regit.org \
    --to=eric@regit.org \
    --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).