diff options
author | Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> | 2013-06-03 05:58:38 +0000 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2013-06-06 12:16:30 +0200 |
commit | cf4f500f828ccc8720a19c211bc9ffc478c1463a (patch) | |
tree | 15e60c66643dfc946a296e04172bfa363e9a8b8e /src/table.c | |
parent | dcb90d7f41d9770820060167f128d815f8a09f0d (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/table.c')
-rw-r--r-- | src/table.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/table.c b/src/table.c index 70f482d..a868da4 100644 --- a/src/table.c +++ b/src/table.c @@ -203,6 +203,7 @@ static int nft_table_xml_parse(struct nft_table *t, char *xml) mxml_node_t *node = NULL; char *endptr = NULL; uint64_t tmp; + int64_t stmp; /* NOTE: all XML nodes are mandatory */ @@ -211,6 +212,18 @@ static int nft_table_xml_parse(struct nft_table *t, char *xml) if (tree == NULL) return -1; + /* Check the version of the XML */ + if (mxmlElementGetAttr(tree, "version") == NULL) { + mxmlDelete(tree); + return -1; + } + + stmp = strtoll(mxmlElementGetAttr(tree, "version"), &endptr, 10); + if (stmp == LLONG_MAX || *endptr || stmp != NFT_TABLE_XML_VERSION) { + mxmlDelete(tree); + return -1; + } + /* Get and set the name of the table */ if (mxmlElementGetAttr(tree, "name") == NULL) { mxmlDelete(tree); @@ -290,13 +303,14 @@ EXPORT_SYMBOL(nft_table_parse); static int nft_table_snprintf_xml(char *buf, size_t size, struct nft_table *t) { return snprintf(buf, size, - "<table name=\"%s\">" + "<table name=\"%s\" version=\"%d\">" "<properties>" "<family>%u</family>" "<table_flags>%d</table_flags>" "</properties>" "</table>" , - t->name, t->family, t->table_flags); + t->name, NFT_TABLE_XML_VERSION, + t->family, t->table_flags); } static int nft_table_snprintf_default(char *buf, size_t size, struct nft_table *t) |