[libnftnl PATCH 3/6] src: chain: add set, unset, get, parse and build payload implementation for use value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add some parts of the implemention of 'use' vualue in chain that miss it.

These changes are neeeded for a correct import/export of xml/json file

Signed-off-by: Ana Rey <anarey@xxxxxxxxx>
---
 src/chain.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/chain.c b/src/chain.c
index 9e9f207..f01abb9 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -115,8 +115,7 @@ void nft_chain_attr_unset(struct nft_chain *c, uint16_t attr)
 		}
 		break;
 	case NFT_CHAIN_ATTR_USE:
-		/* cannot be unset?, ignore it */
-		return;
+		break;
 	case NFT_CHAIN_ATTR_TYPE:
 		if (c->type) {
 			xfree(c->type);
@@ -178,8 +177,8 @@ void nft_chain_attr_set_data(struct nft_chain *c, uint16_t attr,
 		c->policy = *((uint32_t *)data);
 		break;
 	case NFT_CHAIN_ATTR_USE:
-		/* cannot be set, ignore it */
-		return;
+		c->use = *((uint32_t *)data);
+		break;
 	case NFT_CHAIN_ATTR_BYTES:
 		c->bytes = *((uint64_t *)data);
 		break;
@@ -356,6 +355,8 @@ void nft_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nft_chain
 	}
 	if (c->flags & (1 << NFT_CHAIN_ATTR_POLICY))
 		mnl_attr_put_u32(nlh, NFTA_CHAIN_POLICY, htonl(c->policy));
+	if (c->flags & (1 << NFT_CHAIN_ATTR_USE))
+		mnl_attr_put_u32(nlh, NFTA_CHAIN_USE, htonl(c->use));
 	if ((c->flags & (1 << NFT_CHAIN_ATTR_PACKETS)) &&
 	    (c->flags & (1 << NFT_CHAIN_ATTR_BYTES))) {
 		struct nlattr *nest;
@@ -566,7 +567,7 @@ int nft_jansson_parse_chain(struct nft_chain *c, json_t *tree,
 	json_t *root;
 	uint64_t uval64;
 	int policy;
-	int32_t val32;
+	int32_t val32, use;
 	const char *valstr;
 
 	root = nft_jansson_get_node(tree, "chain", err);
@@ -609,6 +610,9 @@ int nft_jansson_parse_chain(struct nft_chain *c, json_t *tree,
 
 	nft_chain_attr_set_str(c, NFT_CHAIN_ATTR_TABLE, valstr);
 
+	if (nft_jansson_parse_val(root, "use", NFT_TYPE_U32, &use, err) == 0)
+		nft_chain_attr_set_u32(c, NFT_CHAIN_ATTR_USE, use);
+
 	if (nft_jansson_node_exist(root, "hooknum")) {
 		valstr = nft_jansson_parse_str(root, "type", err);
 
-- 
2.0.0

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




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux