From: Ana Rey <anarey@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: Ana Rey <anarey@gmail.com>
Subject: [libnftnl PATCH 2/5] expr: byteorder: Use nft_rule_expr_set_* in the xml parsing code
Date: Thu, 19 Jun 2014 17:07:07 +0200 [thread overview]
Message-ID: <1403190430-22173-3-git-send-email-anarey@gmail.com> (raw)
In-Reply-To: <1403190430-22173-1-git-send-email-anarey@gmail.com>
Code refactoring to use nft_rule_expr_set_* in parse functions.
Signed-off-by: Ana Rey <anarey@gmail.com>
---
src/expr/byteorder.c | 37 ++++++++++++++-----------------------
1 file changed, 14 insertions(+), 23 deletions(-)
diff --git a/src/expr/byteorder.c b/src/expr/byteorder.c
index e42d7b6..0b87eca 100644
--- a/src/expr/byteorder.c
+++ b/src/expr/byteorder.c
@@ -244,24 +244,19 @@ nft_rule_expr_byteorder_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree,
struct nft_parse_err *err)
{
#ifdef XML_PARSING
- struct nft_expr_byteorder *byteorder = nft_expr_data(e);
const char *op;
int32_t ntoh;
- uint32_t reg;
+ uint32_t sreg, dreg, len, size;
- if (nft_mxml_reg_parse(tree, "sreg", ®, MXML_DESCEND_FIRST,
- NFT_XML_MAND, err) != 0)
+ if (nft_mxml_reg_parse(tree, "sreg", &sreg, MXML_DESCEND_FIRST,
+ NFT_XML_MAND, err) < 0)
return -1;
+ nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_SREG, sreg);
- byteorder->sreg = reg;
- e->flags |= (1 << NFT_EXPR_BYTEORDER_SREG);
-
- if (nft_mxml_reg_parse(tree, "dreg", ®, MXML_DESCEND, NFT_XML_MAND,
- err) != 0)
+ if (nft_mxml_reg_parse(tree, "dreg", &dreg, MXML_DESCEND, NFT_XML_MAND,
+ err) < 0)
return -1;
-
- byteorder->dreg = reg;
- e->flags |= (1 << NFT_EXPR_BYTEORDER_DREG);
+ nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_DREG, dreg);
op = nft_mxml_str_parse(tree, "op", MXML_DESCEND_FIRST, NFT_XML_MAND,
err);
@@ -271,23 +266,19 @@ nft_rule_expr_byteorder_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree,
ntoh = nft_str2ntoh(op);
if (ntoh < 0)
return -1;
-
- byteorder->op = ntoh;
- e->flags |= (1 << NFT_EXPR_BYTEORDER_OP);
+ nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_OP, ntoh);
if (nft_mxml_num_parse(tree, "len", MXML_DESCEND_FIRST, BASE_DEC,
- &byteorder->len, NFT_TYPE_U8,
- NFT_XML_MAND, err) != 0)
+ &len, NFT_TYPE_U32, NFT_XML_MAND,
+ err) < 0)
return -1;
-
- e->flags |= (1 << NFT_EXPR_BYTEORDER_LEN);
+ nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_LEN, len);
if (nft_mxml_num_parse(tree, "size", MXML_DESCEND_FIRST, BASE_DEC,
- &byteorder->size, NFT_TYPE_U8,
- NFT_XML_MAND, err) != 0)
+ &size, NFT_TYPE_U32, NFT_XML_MAND,
+ err) != 0)
return -1;
-
- e->flags |= (1 << NFT_EXPR_BYTEORDER_SIZE);
+ nft_rule_expr_set_u32(e, NFT_EXPR_BYTEORDER_SIZE, size);
return 0;
#else
--
2.0.0
next prev parent reply other threads:[~2014-06-19 15:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-19 15:07 [libnftnl PATCH 0/5] expr: bitwise: Do not print unset values Ana Rey
2014-06-19 15:07 ` [libnftnl PATCH 1/5] expr: byteorder: Get a nft_rule_expr type in nft_rule_expr_byteorder_snprintf_* functions Ana Rey
2014-06-19 15:07 ` Ana Rey [this message]
2014-06-19 15:07 ` [libnftnl PATCH 3/5] expr: byteorder: Do not print unset values in xml file Ana Rey
2014-06-20 7:12 ` Arturo Borrero Gonzalez
2014-06-19 15:07 ` [libnftnl PATCH 4/5] expr: byteorder: Rename variables in nft_rule_expr_byteorder_json_parse functions Ana Rey
2014-06-19 15:07 ` [libnftnl PATCH 5/5] expr: byteorder: Do not print unset values in json Ana Rey
2014-06-20 7:16 ` [libnftnl PATCH 0/5] expr: bitwise: Do not print unset values Arturo Borrero Gonzalez
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=1403190430-22173-3-git-send-email-anarey@gmail.com \
--to=anarey@gmail.com \
--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).