summaryrefslogtreecommitdiffstats
path: root/src/chain.c
diff options
context:
space:
mode:
authorArturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>2013-06-03 05:58:38 +0000
committerPablo Neira Ayuso <pablo@netfilter.org>2013-06-06 12:16:30 +0200
commitcf4f500f828ccc8720a19c211bc9ffc478c1463a (patch)
tree15e60c66643dfc946a296e04172bfa363e9a8b8e /src/chain.c
parentdcb90d7f41d9770820060167f128d815f8a09f0d (diff)
src: xml: add versioning
Add version to XML chunks in case of future changes. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/chain.c')
-rw-r--r--src/chain.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/chain.c b/src/chain.c
index 4146e6a..093e3ea 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -14,6 +14,7 @@
#include <endian.h>
#include <stdint.h>
#include <stdlib.h>
+#include <limits.h>
#include <string.h>
#include <netinet/in.h>
#include <errno.h>
@@ -469,6 +470,17 @@ static int nft_chain_xml_parse(struct nft_chain *c, char *xml)
if (tree == NULL)
return -1;
+ /* Validate version */
+ if (mxmlElementGetAttr(tree, "version") == NULL) {
+ mxmlDelete(tree);
+ return -1;
+ }
+ tmp = strtoll(mxmlElementGetAttr(tree, "version"), &endptr, 10);
+ if (tmp == LLONG_MAX || *endptr || tmp != NFT_CHAIN_XML_VERSION) {
+ mxmlDelete(tree);
+ return -1;
+ }
+
/* Get and set <chain name="xxx" ... >*/
if (mxmlElementGetAttr(tree, "name") == NULL) {
mxmlDelete(tree);
@@ -643,7 +655,7 @@ static int nft_chain_snprintf_xml(char *buf, size_t size, struct nft_chain *c)
{
return snprintf(buf, size,
"<chain name=\"%s\" handle=\"%lu\""
- " bytes=\"%lu\" packets=\"%lu\">"
+ " bytes=\"%lu\" packets=\"%lu\" version=\"%d\">"
"<properties>"
"<type>%s</type>"
"<table>%s</table>"
@@ -655,8 +667,8 @@ static int nft_chain_snprintf_xml(char *buf, size_t size, struct nft_chain *c)
"</properties>"
"</chain>",
c->name, c->handle, c->bytes, c->packets,
- c->type, c->table, c->prio, c->use, c->hooknum,
- c->policy, c->family);
+ NFT_CHAIN_XML_VERSION, c->type, c->table,
+ c->prio, c->use, c->hooknum, c->policy, c->family);
}
static int nft_chain_snprintf_default(char *buf, size_t size, struct nft_chain *c)