From patchwork Fri Aug 9 11:13:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alvaro Neira X-Patchwork-Id: 265999 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 902D92C008E for ; Fri, 9 Aug 2013 21:13:56 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967757Ab3HILNz (ORCPT ); Fri, 9 Aug 2013 07:13:55 -0400 Received: from mail-wg0-f51.google.com ([74.125.82.51]:46230 "EHLO mail-wg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967573Ab3HILNz (ORCPT ); Fri, 9 Aug 2013 07:13:55 -0400 Received: by mail-wg0-f51.google.com with SMTP id a12so3398572wgh.6 for ; Fri, 09 Aug 2013 04:13:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; bh=S1Fjx5ykKPqZkAN7EwqjfVMUFtOAetevmYFhkunaims=; b=FXudjyhP3ud9ipoOJYbd9uwBOmjJOdxj+Rt5xnavuM7x12IbY2OH2tVf3AmKqCQ5hr 01jZP/prl5yXpvmhRy6IRzWfp5xiY/AxuzEK5dh7oVCru3q21FoTj38PKQkfLNOY6321 rGAATphu5gjXYbD8I/d5UFZuw++qetG9/aPTAJ1SG3g56iC516KeH9SVBKHBJd7xdeUp neDgonad1hMT1+8iuVJufaxSrj6l+SfJj/l3PJlWJRosnCyFjp+eE1b12Lm44Qmqxlxu GMh6bHzwNEyaZvSB3hOSdEHRLIPL4Uz77Yswa0Dd+cGwWROa2JVX5bA8H1jeld2NJoi9 zHsA== X-Received: by 10.180.205.236 with SMTP id lj12mr43238wic.22.1376046834020; Fri, 09 Aug 2013 04:13:54 -0700 (PDT) Received: from [127.0.1.1] ([90.174.0.186]) by mx.google.com with ESMTPSA id dt17sm2199698wic.1.2013.08.09.04.13.49 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 09 Aug 2013 04:13:53 -0700 (PDT) Subject: [libnftables PATCH 09/13] expr: cmp: add nft_str2cmp function To: netfilter-devel@vger.kernel.org From: Alvaro Neira Cc: eric@regit.org Date: Fri, 09 Aug 2013 13:13:45 +0200 Message-ID: <20130809111345.29819.80871.stgit@Ph0enix> In-Reply-To: <20130809111148.29819.95689.stgit@Ph0enix> References: <20130809111148.29819.95689.stgit@Ph0enix> User-Agent: StGit/0.15 MIME-Version: 1.0 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org From: Álvaro Neira Ayuso Add function that will be use in the JSON parser Signed-off-by: Alvaro Neira Ayuso --- src/expr/cmp.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) -- 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 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",