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 09/12] netlink_delinearize: remove implied meta expressions
Date: Wed,  8 Jan 2014 13:09:00 +0000	[thread overview]
Message-ID: <1389186543-6919-10-git-send-email-kaber@trash.net> (raw)
In-Reply-To: <1389186543-6919-1-git-send-email-kaber@trash.net>

Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 include/expression.h      |  1 +
 src/netlink_delinearize.c | 29 +++++++++++++++++++++++------
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/include/expression.h b/include/expression.h
index 59b27c0..a9aa328 100644
--- a/include/expression.h
+++ b/include/expression.h
@@ -242,6 +242,7 @@ struct expr {
 		struct {
 			/* EXPR_META */
 			enum nft_meta_keys	key;
+			enum proto_bases	base;
 		} meta;
 		struct {
 			/* EXPR_CT */
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index c02f133..5a6cbfa 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -588,10 +588,19 @@ static void payload_dependency_kill(struct rule_pp_ctx *ctx, struct expr *expr)
 	    ctx->pdep != NULL) {
 		list_del(&ctx->pdep->list);
 		stmt_free(ctx->pdep);
+		ctx->pbase = PROTO_BASE_INVALID;
 		ctx->pdep = NULL;
 	}
 }
 
+static void payload_dependency_store(struct rule_pp_ctx *ctx,
+				     struct stmt *stmt,
+				     enum proto_bases base)
+{
+	ctx->pbase = base;
+	ctx->pdep  = stmt;
+}
+
 static void payload_match_postprocess(struct rule_pp_ctx *ctx,
 				      struct stmt *stmt, struct expr *expr)
 {
@@ -622,10 +631,10 @@ static void payload_match_postprocess(struct rule_pp_ctx *ctx,
 			 * payload expression.
 			 */
 			if (ctx->pbase == PROTO_BASE_INVALID &&
-			    left->flags & EXPR_F_PROTOCOL) {
-				ctx->pbase = left->payload.base;
-				ctx->pdep  = nstmt;
-			} else
+			    left->flags & EXPR_F_PROTOCOL)
+				payload_dependency_store(ctx, nstmt,
+							 left->payload.base);
+			else
 				payload_dependency_kill(ctx, nexpr->left);
 		}
 		list_del(&stmt->list);
@@ -635,16 +644,24 @@ static void payload_match_postprocess(struct rule_pp_ctx *ctx,
 		payload_expr_complete(left, &ctx->pctx);
 		expr_set_type(expr->right, expr->left->dtype,
 			      expr->left->byteorder);
+		payload_dependency_kill(ctx, expr->left);
 		break;
 	}
 }
 
-static void meta_match_postprocess(struct proto_ctx *ctx,
+static void meta_match_postprocess(struct rule_pp_ctx *ctx,
+				   struct stmt *stmt,
 				   const struct expr *expr)
 {
+	struct expr *left = expr->left;
+
 	switch (expr->op) {
 	case OP_EQ:
 		expr->left->ops->pctx_update(ctx, expr);
+
+		if (ctx->pbase == PROTO_BASE_INVALID &&
+		    left->flags & EXPR_F_PROTOCOL)
+			payload_dependency_store(ctx, stmt, left->meta.base);
 		break;
 	default:
 		break;
@@ -765,7 +782,7 @@ static void expr_postprocess(struct rule_pp_ctx *ctx,
 
 		switch (expr->left->ops->type) {
 		case EXPR_META:
-			meta_match_postprocess(&ctx->pctx, expr);
+			meta_match_postprocess(ctx, stmt, expr);
 			break;
 		case EXPR_BINOP:
 			relational_binop_postprocess(expr);
-- 
1.8.4.2


  parent reply	other threads:[~2014-01-08 13:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-08 13:08 [PATCH 00/12] nftables: generic protocol contexts, "inet" family Patrick McHardy
2014-01-08 13:08 ` [PATCH 01/12] expr: replace PAYLOAD_PROTOCOL_EXPR by generic flag Patrick McHardy
2014-01-08 13:08 ` [PATCH 02/12] nftables: generic procotol contexts Patrick McHardy
2014-01-08 13:08 ` [PATCH 03/12] expr: add protocol context update callback Patrick McHardy
2014-01-08 13:08 ` [PATCH 04/12] proto: add helper function to update protocol context Patrick McHardy
2014-01-08 13:08 ` [PATCH 05/12] proto: add debugging for protocol context updates Patrick McHardy
2014-01-08 13:08 ` [PATCH 06/12] ct expr: protocol context updates and dynamic typing Patrick McHardy
2014-01-08 13:08 ` [PATCH 07/12] include: resync nftables.h with kernel Patrick McHardy
2014-01-08 13:08 ` [PATCH 08/12] nftables: add support for the "inet" family Patrick McHardy
2014-01-08 13:09 ` Patrick McHardy [this message]
2014-01-09 21:48   ` [PATCH 09/12] netlink_delinearize: remove implied meta expressions Arturo Borrero Gonzalez
2014-01-09 22:01     ` Patrick McHardy
2014-01-08 13:09 ` [PATCH 10/12] proto: add support for meta templates Patrick McHardy
2014-01-08 13:09 ` [PATCH 11/12] meta: add nfproto support Patrick McHardy
2014-01-08 13:09 ` [PATCH 12/12] meta: add l4proto support Patrick McHardy
  -- strict thread matches above, loose matches on Subject: below --
2014-01-06 17:27 [RFC PATCH 00/12] nftables: generic protocol contexts, "inet" family support Patrick McHardy
2014-01-06 17:27 ` [PATCH 09/12] netlink_delinearize: remove implied meta expressions 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=1389186543-6919-10-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).