From 64279008234c2367e1b6ffa84c6b3dff5a04a779 Mon Sep 17 00:00:00 2001 From: Alvaro Neira Ayuso Date: Mon, 9 Feb 2015 21:09:54 +0100 Subject: src: add support to import JSON/XML with the new command tag This patch adds support to parse the new command tag in XML/JSON. This patch adds two new functions: * nft_ruleset_parse_file_cb * nft_ruleset_parse_buffer_cb The idea is to invoke the callback function that is passed as parameter is called for each object that is parsed from the corresponding input. Each callback has access to the nft_parse_ctx structure that provides the necessary context such as the command, the object type and the object itself. This change also adds support to update the content of a set incrementally. {"nftables":[{"add":[{"element":{"name":"blackhole","table":"filter", "family":"ip","key_type":7,"key_len":4,"set_elem":[{"key":{ "reg":{"type":"value","len":4,"data0":"0x0403a8c0"}}}]}}]}]} This also patch consolidates the xml/json ruleset import path. Signed-off-by: Alvaro Neira Ayuso Signed-off-by: Pablo Neira Ayuso --- src/utils.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c index 1868a06..a390028 100644 --- a/src/utils.c +++ b/src/utils.c @@ -203,6 +203,22 @@ const char *nft_cmd2tag(enum nft_cmd_type cmd) return cmd2tag[cmd]; } +uint32_t nft_str2cmd(const char *cmd) +{ + if (strcmp(cmd, ADD) == 0) + return NFT_CMD_ADD; + else if (strcmp(cmd, INSERT) == 0) + return NFT_CMD_INSERT; + else if (strcmp(cmd, DELETE) == 0) + return NFT_CMD_DELETE; + else if (strcmp(cmd, REPLACE) == 0) + return NFT_CMD_REPLACE; + else if (strcmp(cmd, FLUSH) == 0) + return NFT_CMD_FLUSH; + + return NFT_CMD_UNSPEC; +} + int nft_fprintf(FILE *fp, void *obj, uint32_t cmd, uint32_t type, uint32_t flags, int (*snprintf_cb)(char *buf, size_t bufsiz, void *obj, uint32_t cmd, uint32_t type, uint32_t flags)) -- cgit v1.2.3