From cf4f500f828ccc8720a19c211bc9ffc478c1463a Mon Sep 17 00:00:00 2001 From: Arturo Borrero Gonzalez Date: Mon, 3 Jun 2013 05:58:38 +0000 Subject: src: xml: add versioning Add version to XML chunks in case of future changes. Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Pablo Neira Ayuso --- src/rule.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/rule.c') diff --git a/src/rule.c b/src/rule.c index 94eba44..698bf89 100644 --- a/src/rule.c +++ b/src/rule.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -454,6 +455,17 @@ static int nft_rule_xml_parse(struct nft_rule *r, char *xml) if (tree == NULL) return -1; + /* validate XML version */ + if (mxmlElementGetAttr(tree, "version") == NULL) { + mxmlDelete(tree); + return -1; + } + tmp = strtoll(mxmlElementGetAttr(tree, "version"), &endptr, 10); + if (tmp == LLONG_MAX || *endptr || tmp != NFT_RULE_XML_VERSION) { + mxmlDelete(tree); + return -1; + } + /* get and set */ if (mxmlElementGetAttr(tree, "family") == NULL) { mxmlDelete(tree); @@ -630,9 +642,10 @@ static int nft_rule_snprintf_xml(char *buf, size_t size, struct nft_rule *r, ret = snprintf(buf, size, " ", + "chain=\"%s\" handle=\"%llu\" version=\"%d\"> ", r->family, r->table, r->chain, - (unsigned long long)r->handle); + (unsigned long long)r->handle, + NFT_RULE_XML_VERSION); SNPRINTF_BUFFER_SIZE(ret, size, len, offset); ret = snprintf(buf+offset, len, "%u" -- cgit v1.2.3