summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAna Rey <anarey@gmail.com>2014-06-26 18:38:56 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2014-06-30 12:44:53 +0200
commitc39a79220f2c490cae43c6458e55e659b7d0ff39 (patch)
tree0dab83b702a5f0d4e18a98d5919997cbd35d0b03 /src
parent05f3bc8ca8434b1d588f02a2077ab212f61ffaf0 (diff)
chain: Use nft_rule_expr_set_* in the xml parsing code
Code refactoring to use nft_rule_expr_set_* in parse functions. Signed-off-by: Ana Rey <anarey@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/chain.c53
1 files 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;