netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alvaro Neira <alvaroneay@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: eric@regit.org
Subject: [libnftables PATCH 09/13] expr: cmp: add nft_str2cmp function
Date: Fri, 09 Aug 2013 13:13:45 +0200	[thread overview]
Message-ID: <20130809111345.29819.80871.stgit@Ph0enix> (raw)
In-Reply-To: <20130809111148.29819.95689.stgit@Ph0enix>

From: Álvaro Neira Ayuso <alvaroneay@gmail.com>

Add function that will be use in the JSON parser

Signed-off-by: Alvaro Neira Ayuso <alvaroneay@gmail.com>
---
 src/expr/cmp.c |   38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/expr/cmp.c b/src/expr/cmp.c
index 291ebcd..8ca4cb5 100644
--- a/src/expr/cmp.c
+++ b/src/expr/cmp.c
@@ -154,12 +154,32 @@ static char *expr_cmp_str[] = {
 	[NFT_CMP_GTE]	= "gte",
 };
 
+static inline int nft_str2cmp(const char *op)
+{
+	if (strcmp(op, "eq") == 0)
+		return NFT_CMP_EQ;
+	else if (strcmp(op, "neq") == 0)
+		return NFT_CMP_NEQ;
+	else if (strcmp(op, "lt") == 0)
+		return NFT_CMP_LT;
+	else if (strcmp(op, "lte") == 0)
+		return NFT_CMP_LTE;
+	else if (strcmp(op, "gt") == 0)
+		return NFT_CMP_GT;
+	else if (strcmp(op, "gte") == 0)
+		return NFT_CMP_GTE;
+	else {
+		errno = EINVAL;
+		return -1;
+	}
+}
+
 static int nft_rule_expr_cmp_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
 {
 #ifdef XML_PARSING
 	struct nft_expr_cmp *cmp = nft_expr_data(e);
 	const char *op;
-	int32_t reg;
+	int32_t reg, op_value;
 
 	reg = nft_mxml_reg_parse(tree, "sreg", MXML_DESCEND_FIRST);
 	if (reg < 0)
@@ -172,21 +192,11 @@ static int nft_rule_expr_cmp_xml_parse(struct nft_rule_expr *e, mxml_node_t *tre
 	if (op == NULL)
 		return -1;
 
-	if (strcmp(op, "eq") == 0)
-		cmp->op = NFT_CMP_EQ;
-	else if (strcmp(op, "neq") == 0)
-		cmp->op = NFT_CMP_NEQ;
-	else if (strcmp(op, "lt") == 0)
-		cmp->op = NFT_CMP_LT;
-	else if (strcmp(op, "lte") == 0)
-		cmp->op = NFT_CMP_LTE;
-	else if (strcmp(op, "gt") == 0)
-		cmp->op = NFT_CMP_GT;
-	else if (strcmp(op, "gte") == 0)
-		cmp->op = NFT_CMP_GTE;
-	else
+	op_value = nft_str2cmp(op);
+	if (op_value < 0)
 		return -1;
 
+	cmp->op = op_value;
 	e->flags |= (1 << NFT_EXPR_CMP_OP);
 
 	if (nft_mxml_data_reg_parse(tree, "cmpdata",

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2013-08-09 11:13 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-09 11:11 [libnftables PATCH 01/13] src: expr: missing commas in json output support Alvaro Neira
2013-08-09 11:12 ` [libnftables PATCH 02/13] src: expr: missing curly braces " Alvaro Neira
2013-08-09 11:12 ` [libnftables PATCH 03/13] src: expr: change wrong value in data_reg Alvaro Neira
2013-08-09 11:12 ` [libnftables PATCH 04/13] src: fix display of compat_flag and compat_proto Alvaro Neira
2013-08-09 11:12 ` [libnftables PATCH 05/13] expr: ct: optional output in ct Alvaro Neira
2013-08-09 11:13 ` [libnftables PATCH 06/13] json: bitwise: add missing node len Alvaro Neira
2013-08-09 11:13 ` [libnftables PATCH 07/13] src: json: delete unneeded JSON prefixes Alvaro Neira
2013-08-09 11:13 ` [libnftables PATCH 08/13] expr: bytecode: add nft_str2ntoh function Alvaro Neira
2013-08-09 11:13 ` Alvaro Neira [this message]
2013-08-09 11:13 ` [libnftables PATCH 10/13] expr: nat: add nft_str2nat function Alvaro Neira
2013-08-09 11:14 ` [libnftables PATCH 11/13] expr: payload: add nft_str2base function Alvaro Neira
2013-08-09 11:31   ` Arturo Borrero Gonzalez
2013-08-09 11:43     ` Pablo Neira Ayuso
2013-08-09 11:34   ` Arturo Borrero Gonzalez
2013-08-09 11:14 ` [libnftables PATCH 12/13] example: nft-rule-get: family parameter added Alvaro Neira
2013-08-09 11:14 ` [libnftables PATCH 13/13] jansson: Add nft_jansson_family function Alvaro Neira
2013-08-09 11:44 ` [libnftables PATCH 01/13] src: expr: missing commas in json output support 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=20130809111345.29819.80871.stgit@Ph0enix \
    --to=alvaroneay@gmail.com \
    --cc=eric@regit.org \
    --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).