From: Ana Rey <anarey@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: Ana Rey <anarey@gmail.com>
Subject: [libnftnl PATCH 2/6] src: chain: Use nft_rule_expr_set_* in the xml parsing code
Date: Thu, 26 Jun 2014 18:38:56 +0200 [thread overview]
Message-ID: <1403800740-10572-3-git-send-email-anarey@gmail.com> (raw)
In-Reply-To: <1403800740-10572-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/chain.c | 53 ++++++++++++++++-------------------------------------
1 file changed, 16 insertions(+), 37 deletions(-)
diff --git a/src/chain.c b/src/chain.c
index b7e1c5e..9e9f207 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -681,51 +681,41 @@ int nft_mxml_chain_parse(mxml_node_t *tree, struct nft_chain *c,
{
const char *table, *name, *hooknum_str, *policy_str, *type;
int family, hooknum, policy;
+ uint64_t handle, bytes, packets, prio;
name = nft_mxml_str_parse(tree, "name", MXML_DESCEND_FIRST,
NFT_XML_MAND, err);
if (name == NULL)
return -1;
-
- strncpy(c->name, name, NFT_CHAIN_MAXNAMELEN);
- c->flags |= (1 << NFT_CHAIN_ATTR_NAME);
+ nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_NAME, name);
if (nft_mxml_num_parse(tree, "handle", MXML_DESCEND_FIRST, BASE_DEC,
- &c->handle, NFT_TYPE_U64, NFT_XML_MAND, err) != 0)
+ &handle, NFT_TYPE_U64, NFT_XML_MAND, err) != 0)
return -1;
-
- c->flags |= (1 << NFT_CHAIN_ATTR_HANDLE);
+ nft_chain_attr_set_u64(c, NFT_CHAIN_ATTR_HANDLE, handle);
if (nft_mxml_num_parse(tree, "bytes", MXML_DESCEND_FIRST, BASE_DEC,
- &c->bytes, NFT_TYPE_U64, NFT_XML_MAND, err) != 0)
+ &bytes, NFT_TYPE_U64, NFT_XML_MAND, err) != 0)
return -1;
+ nft_chain_attr_set_u64(c, NFT_CHAIN_ATTR_BYTES, bytes);
- c->flags |= (1 << NFT_CHAIN_ATTR_BYTES);
if (nft_mxml_num_parse(tree, "packets", MXML_DESCEND_FIRST, BASE_DEC,
- &c->packets, NFT_TYPE_U64, NFT_XML_MAND, err) != 0)
+ &packets, NFT_TYPE_U64, NFT_XML_MAND, err) != 0)
return -1;
-
- c->flags |= (1 << NFT_CHAIN_ATTR_PACKETS);
+ nft_chain_attr_set_u64(c, NFT_CHAIN_ATTR_PACKETS, packets);
table = nft_mxml_str_parse(tree, "table", MXML_DESCEND_FIRST,
NFT_XML_MAND, err);
if (table == NULL)
return -1;
-
- if (c->table)
- xfree(c->table);
-
- c->table = strdup(table);
- c->flags |= (1 << NFT_CHAIN_ATTR_TABLE);
+ nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_TABLE, table);
family = nft_mxml_family_parse(tree, "family", MXML_DESCEND_FIRST,
NFT_XML_MAND, err);
if (family < 0)
return -1;
-
- c->family = family;
- c->flags |= (1 << NFT_CHAIN_ATTR_FAMILY);
+ nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_FAMILY, family);
hooknum_str = nft_mxml_str_parse(tree, "hooknum", MXML_DESCEND_FIRST,
NFT_XML_OPT, err);
@@ -733,28 +723,19 @@ int nft_mxml_chain_parse(mxml_node_t *tree, struct nft_chain *c,
hooknum = nft_str2hooknum(c->family, hooknum_str);
if (hooknum < 0)
return -1;
-
- c->hooknum = hooknum;
- c->flags |= (1 << NFT_CHAIN_ATTR_HOOKNUM);
+ nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_HOOKNUM, hooknum);
type = nft_mxml_str_parse(tree, "type", MXML_DESCEND_FIRST,
NFT_XML_MAND, err);
if (type == NULL)
return -1;
-
- if (c->type)
- xfree(c->type);
-
- c->type = strdup(type);
- c->flags |= (1 << NFT_CHAIN_ATTR_TYPE);
-
+ nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_TYPE, type);
if (nft_mxml_num_parse(tree, "prio", MXML_DESCEND, BASE_DEC,
- &c->prio, NFT_TYPE_S32,
- NFT_XML_MAND, err) != 0)
+ &prio, NFT_TYPE_S32, NFT_XML_MAND,
+ err) != 0)
return -1;
-
- c->flags |= (1 << NFT_CHAIN_ATTR_PRIO);
+ nft_chain_attr_set_s32(c, NFT_CHAIN_ATTR_PRIO, prio);
policy_str = nft_mxml_str_parse(tree, "policy",
MXML_DESCEND_FIRST,
@@ -768,9 +749,7 @@ int nft_mxml_chain_parse(mxml_node_t *tree, struct nft_chain *c,
err->error = NFT_PARSE_EBADTYPE;
return -1;
}
-
- c->policy = policy;
- c->flags |= (1 << NFT_CHAIN_ATTR_POLICY);
+ nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_POLICY, policy);
}
return 0;
--
2.0.0
next prev parent reply other threads:[~2014-06-26 16:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-26 16:38 [libnftnl PATCH 0/6] src: chain: Do not print unset values in json and xml Ana Rey
2014-06-26 16:38 ` [libnftnl PATCH 1/6] src: chain: Free memory in the same function that is reserved Ana Rey
2014-06-30 10:42 ` Pablo Neira Ayuso
2014-06-26 16:38 ` Ana Rey [this message]
2014-06-30 10:42 ` [libnftnl PATCH 2/6] src: chain: Use nft_rule_expr_set_* in the xml parsing code Pablo Neira Ayuso
2014-06-26 16:38 ` [libnftnl PATCH 3/6] src: chain: add set, unset, get, parse and build payload implementation for use value Ana Rey
2014-06-30 10:42 ` Pablo Neira Ayuso
2014-06-26 16:38 ` [libnftnl PATCH 4/6] src: chain: Do not print unset values in xml Ana Rey
2014-06-26 16:38 ` [libnftnl PATCH 5/6] src: chain: Rename variables in nft_jansson_parse_chain functions Ana Rey
2014-06-26 16:39 ` [libnftnl PATCH 6/6] src: chain: Do not print unser values in json Ana Rey
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=1403800740-10572-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).