Skip to contentSkip to conversation

src: support for XML parsing

PATCH In review Arturo Borrero 2 participants 4 messages May 14, 2013 – May 24, 2013 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 src: support for XML parsing

This patch adds capabilities for parsing a XML table/chain/rule

Some points to note:
* the XML data is case sensitive (so <chain>asd</chain> != <chain>ASD</chain> != <CHAIN>asd</CHAIN>)
* all exported functions will receive a XML and return an object (aka table|chain|rule)
* To compile the lib with XML parsing support, run './configure --with-xml-parsing'
* XML parsing is done with libmxml (http://minixml.org). XML parsing depends on this external lib.

NOTE: expr/target and expr/match binary data are ignored.

Some code examples/test cases will be added to libnftables in a future patch.

---
Changes since previous versions of this patch:
* Conditional support for XML parsing (libmxml)
* Improved validation of parsed numerical values

 Make_global.am              |    2 
 configure.ac                |    7 +
 include/libnftables/chain.h |    7 +
 include/libnftables/rule.h  |    7 +
 include/libnftables/table.h |    7 +
 src/chain.c                 |  186 ++++++++++++++++++++++++++++++++
 src/expr/bitwise.c          |  110 +++++++++++++++++++
 src/expr/cmp.c              |   94 ++++++++++++++++
 src/expr/counter.c          |   61 +++++++++++
 src/expr/data_reg.c         |  249 ++++++++++++++++++++++++++++++++++++++++++-
 src/expr/immediate.c        |  100 +++++++++++++++++
 src/expr/lookup.c           |   77 +++++++++++++
 src/expr/match.c            |   58 ++++++++++
 src/expr/meta.c             |   65 +++++++++++
 src/expr/nat.c              |  126 ++++++++++++++++++++++
 src/expr/payload.c          |   87 +++++++++++++++
 src/expr/target.c           |   61 +++++++++++
 src/expr_ops.h              |    1 
 src/internal.h              |    4 +
 src/libnftables.map         |    3 +
 src/rule.c                  |  183 ++++++++++++++++++++++++++++++++
 src/table.c                 |   92 ++++++++++++++++
 22 files changed, 1583 insertions(+), 4 deletions(-)
Make_global.am +1 -1
index 1654f10..8205938 100644
@@ -20,5 +20,5 @@
 #
 LIBVERSION=0:0:0
 
-AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include ${LIBMNL_CFLAGS}
+AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include ${LIBMNL_CFLAGS} ${LIBMXML_CFLAGS}
 AM_CFLAGS = ${regular_CFLAGS} ${GCC_FVISIBILITY_HIDDEN}
configure.ac +7 -0
index 01c170a..0eec5bd 100644
@@ -14,6 +14,10 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 dnl Dependencies
 PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.0])
+AC_ARG_WITH([xml-parsing], AS_HELP_STRING([--with-xml-parsing], [XML parsing support]))
+AS_IF([test "x$with_xml_parsing" = "xyes"], [
+	PKG_CHECK_MODULES([LIBXML], [mxml >= 2.6])
+])
 
 AC_PROG_CC
 AM_PROG_CC_C_O
@@ -26,6 +30,9 @@ case "$host" in
 esac
 
 regular_CPPFLAGS="-D_FILE_OFFSET_BITS=64 -D_REENTRANT"
+AS_IF([test "x$with_xml_parsing" = "xyes"], [
+	regular_CPPFLAGS="$regular_CPPFLAGS -DXML_PARSING"
+])
 regular_CFLAGS="-Wall -Waggregate-return -Wmissing-declarations \
 	-Wmissing-prototypes -Wshadow -Wstrict-prototypes \
 	-Wformat=2 -pipe"
include/libnftables/chain.h +7 -0
index a7f6a50..7b21719 100644
@@ -44,6 +44,13 @@ enum {
 	NFT_CHAIN_O_XML,
 };
 
+enum nft_chain_parse_type {
+	NFT_CHAIN_PARSE_NONE	= 0,
+	NFT_CHAIN_PARSE_XML,
+	NFT_CHAIN_PARSE_MAX
+};
+
+int nft_chain_parse(struct nft_chain *c, enum nft_chain_parse_type type, char *data);
 int nft_chain_snprintf(char *buf, size_t size, struct nft_chain *t, uint32_t type, uint32_t flags);
 
 struct nlmsghdr *nft_chain_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq);
include/libnftables/rule.h +7 -0
index 50944cd..1dc817a 100644
@@ -43,6 +43,13 @@ enum {
 	NFT_RULE_O_XML,
 };
 
+enum nft_rule_parse_type {
+	NFT_RULE_PARSE_NONE	= 0,
+	NFT_RULE_PARSE_XML,
+	NFT_RULE_PARSE_MAX,
+};
+
+int nft_rule_parse(struct nft_rule *r, enum nft_rule_parse_type type, char *data);
 int nft_rule_snprintf(char *buf, size_t size, struct nft_rule *t, uint32_t type, uint32_t flags);
 
 struct nlmsghdr *nft_rule_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq);
include/libnftables/table.h +7 -0
index c50650f..612e1ad 100644
@@ -31,6 +31,13 @@ enum {
 	NFT_TABLE_O_XML,
 };
 
+enum nft_table_parse_type {
+	NFT_TABLE_PARSE_NONE	= 0,
+	NFT_TABLE_PARSE_XML,
+	NFT_TABLE_PARSE_MAX,
+};
+
+int nft_table_parse(struct nft_table *t, enum nft_table_parse_type type, char *data);
 int nft_table_snprintf(char *buf, size_t size, struct nft_table *t, uint32_t type, uint32_t flags);
 
 struct nlmsghdr *nft_table_nlmsg_build_hdr(char *buf, uint16_t cmd, uint16_t family, uint16_t type, uint32_t seq);
src/chain.c +186 -0

192 lines not on this page · raw message

src/expr/bitwise.c +110 -0

120 lines not on this page · raw message

src/expr/cmp.c +94 -0

104 lines not on this page · raw message

src/expr/counter.c +61 -0

71 lines not on this page · raw message

src/expr/data_reg.c +246 -3

264 lines not on this page · raw message

src/expr/immediate.c +100 -0

110 lines not on this page · raw message

src/expr/lookup.c +77 -0

87 lines not on this page · raw message

src/expr/match.c +58 -0

68 lines not on this page · raw message

src/expr/meta.c +65 -0

75 lines not on this page · raw message

src/expr/nat.c +126 -0

142 lines not on this page · raw message

src/expr/payload.c +87 -0

103 lines not on this page · raw message

src/expr/target.c +61 -0

71 lines not on this page · raw message

src/expr_ops.h +1 -0
index d6e4ec9..ff4c648 100644
@@ -17,6 +17,7 @@ struct expr_ops {
 	int 	(*parse)(struct nft_rule_expr *e, struct nlattr *attr);
 	void	(*build)(struct nlmsghdr *nlh, struct nft_rule_expr *e);
 	int	(*snprintf)(char *buf, size_t len, uint32_t type, uint32_t flags, struct nft_rule_expr *e);
+	int	(*xml_parse)(struct nft_rule_expr *e, char *xml);
 };
 
 struct expr_ops *nft_expr_ops_lookup(const char *name);
src/internal.h +4 -0
index f5717ed..b3c3642 100644
@@ -13,6 +13,10 @@
 
 #include <stdint.h>
 
+#ifdef XML_PARSING
+#include <mxml.h>
+#endif
+
 struct expr_ops;
 
 struct nft_rule_expr {
src/libnftables.map +3 -0
index 957e3b6..41afdfb 100644
@@ -6,6 +6,7 @@ global:
   nft_table_attr_get;
   nft_table_attr_set_u32;
   nft_table_attr_get_u32;
+  nft_table_parse;
   nft_table_snprintf;
   nft_table_nlmsg_build_hdr;
   nft_table_nlmsg_build_payload;
@@ -28,6 +29,7 @@ global:
   nft_chain_attr_get_s32;
   nft_chain_attr_get_u64;
   nft_chain_attr_get_str;
+  nft_chain_parse;
   nft_chain_snprintf;
   nft_chain_nlmsg_build_hdr;
   nft_chain_nlmsg_build_payload;
@@ -51,6 +53,7 @@ global:
   nft_rule_attr_get_u32;
   nft_rule_attr_get_u64;
   nft_rule_attr_get_str;
+  nft_rule_parse;
   nft_rule_snprintf;
   nft_rule_nlmsg_build_hdr;
   nft_rule_nlmsg_build_payload;
src/rule.c +183 -0

189 lines not on this page · raw message

src/table.c +92 -0

104 lines not on this page · raw message

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

#1 lore raw
Quoted 7 lines · Arturo Borrero

This patch adds capabilities for parsing a XML table/chain/rule

Some points to note:
* the XML data is case sensitive (so <chain>asd</chain> != <chain>ASD</chain> != <CHAIN>asd</CHAIN>)
* all exported functions will receive a XML and return an object (aka table|chain|rule)
* To compile the lib with XML parsing support, run './configure --with-xml-parsing'
* XML parsing is done with libmxml (http://minixml.org). XML parsing depends on this external lib.

This looks good. Thanks for the patch.

Quoted 3 lines

NOTE: expr/target and expr/match binary data are ignored.

Some code examples/test cases will be added to libnftables in a future patch.

I'm looking forward to having those example files, I would like to use them to test this before applying it to master.

#2 lore raw
In reply to Arturo Borrero
Quoted 9 lines · Arturo Borrero

This patch adds capabilities for parsing a XML table/chain/rule

Some points to note:
* the XML data is case sensitive (so <chain>asd</chain> != <chain>ASD</chain> != <CHAIN>asd</CHAIN>)
* all exported functions will receive a XML and return an object (aka table|chain|rule)
* To compile the lib with XML parsing support, run './configure --with-xml-parsing'
* XML parsing is done with libmxml (http://minixml.org). XML parsing depends on this external lib.

NOTE: expr/target and expr/match binary data are ignored.

I fixed compilation without --with-xml-parsing, that case was probably untested.

Finally applied with minor glitches. If you have follow up patches, please make sure you rebase your tree upon current.

Thanks Arturo.

#3 lore raw

2013/5/23 Pablo Neira Ayuso <[email protected]>:

Quoted 2 lines

I fixed compilation without --with-xml-parsing, that case was probably untested.

Understood.

Quoted 4 lines

Finally applied with minor glitches. If you have follow up patches, please make sure you rebase your tree upon current.

Thanks, please let me know when you push to git.netfilter.org.

--
Arturo Borrero González
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html