From 901fb07e6281be04521440f4581a90c54caf849a Mon Sep 17 00:00:00 2001 From: Arturo Borrero Gonzalez Date: Wed, 26 Jun 2013 13:37:10 +0200 Subject: chain: xml: use string for policy Now the node is using "accept" or "drop". Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Pablo Neira Ayuso --- src/chain.c | 51 ++++++++++++++++++++++++++++++++--------------- test/nft-chain-xml-add.sh | 6 +++--- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/chain.c b/src/chain.c index e8f6c71..bdcfec2 100644 --- a/src/chain.c +++ b/src/chain.c @@ -661,13 +661,16 @@ static int nft_chain_xml_parse(struct nft_chain *c, char *xml) mxmlDelete(tree); return -1; } - utmp = strtoull(node->child->value.opaque, &endptr, 10); - if (utmp > UINT32_MAX || utmp < 0 || *endptr) { + + if (strcmp(node->child->value.opaque, "accept") == 0) { + c->policy = NF_ACCEPT; + } else if (strcmp(node->child->value.opaque, "drop") == 0) { + c->policy = NF_DROP; + } else { mxmlDelete(tree); return -1; } - c->policy = (uint32_t)utmp; c->flags |= (1 << NFT_CHAIN_ATTR_POLICY); /* Get and set */ @@ -741,23 +744,39 @@ static int nft_chain_snprintf_json(char *buf, size_t size, struct nft_chain *c) static int nft_chain_snprintf_xml(char *buf, size_t size, struct nft_chain *c) { - return snprintf(buf, size, - "" - "" + int ret, len = size, offset = 0; + + ret = snprintf(buf, size, + "" + "" "%s" "%s
" "%d" "%d" - "%s" - "%d" - "%s" - "
" - "
", - c->name, c->handle, c->bytes, c->packets, - NFT_CHAIN_XML_VERSION, c->type, c->table, - c->prio, c->use, hooknum2str_array[c->hooknum], - c->policy, nft_family2str(c->family)); + "%s", + c->name, c->handle, c->bytes, c->packets, + NFT_CHAIN_XML_VERSION, c->type, c->table, + c->prio, c->use, hooknum2str_array[c->hooknum]); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + /* The parsing will fail both if there are something different + * than {accept|drop} or if the node is missing. + */ + if (c->policy == NF_ACCEPT) { + ret = snprintf(buf+offset, size, "accept"); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + } else if (c->policy == NF_DROP) { + ret = snprintf(buf+offset, size, "drop"); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + } + + ret = snprintf(buf+offset, size, "%s" + "
", + nft_family2str(c->family)); + SNPRINTF_BUFFER_SIZE(ret, size, len, offset); + + return offset; } static int nft_chain_snprintf_default(char *buf, size_t size, diff --git a/test/nft-chain-xml-add.sh b/test/nft-chain-xml-add.sh index ab50e2b..ed39d54 100755 --- a/test/nft-chain-xml-add.sh +++ b/test/nft-chain-xml-add.sh @@ -41,7 +41,7 @@ XML="0 0 NF_INET_LOCAL_IN - 1 + accept ip " @@ -62,7 +62,7 @@ XML="1 0 NF_INET_POST_ROUTING - 1 + accept ip6 " @@ -84,7 +84,7 @@ XML="0 0 NF_INET_FORWARD - 1 + drop ip " -- cgit v1.2.3