]> git.ipfire.org Git - thirdparty/libnftnl.git/commitdiff
src: remove json support
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 8 Oct 2018 22:03:28 +0000 (00:03 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 15 Oct 2018 12:04:27 +0000 (14:04 +0200)
We have better json support in libnftables these days.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
139 files changed:
configure.ac
examples/Makefile.am
examples/nft-chain-get.c
examples/nft-chain-parse-add.c [deleted file]
examples/nft-ct-helper-get.c
examples/nft-ct-timeout-get.c
examples/nft-events.c
examples/nft-flowtable-get.c
examples/nft-obj-get.c
examples/nft-rule-get.c
examples/nft-rule-parse-add.c [deleted file]
examples/nft-ruleset-get.c
examples/nft-ruleset-parse-file.c [deleted file]
examples/nft-set-elem-get.c
examples/nft-set-get.c
examples/nft-set-parse-add.c [deleted file]
examples/nft-table-get.c
examples/nft-table-parse-add.c [deleted file]
include/Makefile.am
include/common.h
include/expr_ops.h
include/internal.h
include/json.h [deleted file]
include/obj.h
src/Makefile.am
src/buffer.c [deleted file]
src/chain.c
src/common.c
src/expr/bitwise.c
src/expr/byteorder.c
src/expr/cmp.c
src/expr/connlimit.c
src/expr/counter.c
src/expr/ct.c
src/expr/data_reg.c
src/expr/dup.c
src/expr/dynset.c
src/expr/exthdr.c
src/expr/fib.c
src/expr/flow_offload.c
src/expr/fwd.c
src/expr/hash.c
src/expr/immediate.c
src/expr/limit.c
src/expr/log.c
src/expr/lookup.c
src/expr/masq.c
src/expr/match.c
src/expr/meta.c
src/expr/nat.c
src/expr/numgen.c
src/expr/objref.c
src/expr/osf.c
src/expr/payload.c
src/expr/queue.c
src/expr/quota.c
src/expr/range.c
src/expr/redir.c
src/expr/reject.c
src/expr/rt.c
src/expr/socket.c
src/expr/target.c
src/expr/tunnel.c
src/expr/xfrm.c
src/flowtable.c
src/gen.c
src/jansson.c [deleted file]
src/obj/counter.c
src/obj/ct_helper.c
src/obj/ct_timeout.c
src/obj/limit.c
src/obj/quota.c
src/obj/tunnel.c
src/object.c
src/rule.c
src/ruleset.c
src/set.c
src/set_elem.c
src/table.c
tests/Makefile.am
tests/jsonfiles/01-table.json [deleted file]
tests/jsonfiles/02-table.json [deleted file]
tests/jsonfiles/11-chain.json [deleted file]
tests/jsonfiles/12-chain.json [deleted file]
tests/jsonfiles/13-chain.json [deleted file]
tests/jsonfiles/14-chain.json [deleted file]
tests/jsonfiles/20-rule-bitwise.json [deleted file]
tests/jsonfiles/21-rule-byteorder.json [deleted file]
tests/jsonfiles/22-rule-cmp.json [deleted file]
tests/jsonfiles/23-rule-counter.json [deleted file]
tests/jsonfiles/24-rule-ct.json [deleted file]
tests/jsonfiles/25-rule-exthdr.json [deleted file]
tests/jsonfiles/26-rule-immediate.json [deleted file]
tests/jsonfiles/27-rule-limit.json [deleted file]
tests/jsonfiles/28-rule-log.json [deleted file]
tests/jsonfiles/29-rule-match.json [deleted file]
tests/jsonfiles/30-rule-lookup.json [deleted file]
tests/jsonfiles/31-rule-meta.json [deleted file]
tests/jsonfiles/32-rule-nat4.json [deleted file]
tests/jsonfiles/33-rule-nat6.json [deleted file]
tests/jsonfiles/34-rule-payload.json [deleted file]
tests/jsonfiles/35-rule-target.json [deleted file]
tests/jsonfiles/36-rule-real.json [deleted file]
tests/jsonfiles/37-rule-real.json [deleted file]
tests/jsonfiles/38-rule-real.json [deleted file]
tests/jsonfiles/39-rule-real.json [deleted file]
tests/jsonfiles/40-rule-real.json [deleted file]
tests/jsonfiles/41-rule-real.json [deleted file]
tests/jsonfiles/42-rule-real.json [deleted file]
tests/jsonfiles/43-rule-real.json [deleted file]
tests/jsonfiles/44-rule-real.json [deleted file]
tests/jsonfiles/45-rule-real.json [deleted file]
tests/jsonfiles/46-rule-real.json [deleted file]
tests/jsonfiles/47-rule-real.json [deleted file]
tests/jsonfiles/48-rule-real.json [deleted file]
tests/jsonfiles/49-rule-real.json [deleted file]
tests/jsonfiles/50-rule-real.json [deleted file]
tests/jsonfiles/51-rule-real.json [deleted file]
tests/jsonfiles/52-rule-real.json [deleted file]
tests/jsonfiles/53-rule-real.json [deleted file]
tests/jsonfiles/54-rule-real.json [deleted file]
tests/jsonfiles/55-rule-real.json [deleted file]
tests/jsonfiles/56-rule-real.json [deleted file]
tests/jsonfiles/57-rule-real.json [deleted file]
tests/jsonfiles/58-rule-real.json [deleted file]
tests/jsonfiles/59-rule-real.json [deleted file]
tests/jsonfiles/60-rule-real.json [deleted file]
tests/jsonfiles/61-rule-real.json [deleted file]
tests/jsonfiles/62-set.json [deleted file]
tests/jsonfiles/63-set.json [deleted file]
tests/jsonfiles/64-ruleset.json [deleted file]
tests/jsonfiles/65-rule-meta-target.json [deleted file]
tests/jsonfiles/66-rule-queue.json [deleted file]
tests/jsonfiles/67-rule-queue.json [deleted file]
tests/jsonfiles/68-rule-masq.json [deleted file]
tests/jsonfiles/69-rule-redir.json [deleted file]
tests/jsonfiles/70-rule-real.json [deleted file]
tests/nft-parsing-test.c [deleted file]
tests/test-script.sh

index dbb723d8eb0604f66f0d955f0984fd61042488f4..d05532d1a20e75b53677f7cf453a88c4d26dc4fd 100644 (file)
@@ -15,13 +15,6 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
 
 dnl Dependencies
 PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.3])
-AC_ARG_WITH([json-parsing],
-       AS_HELP_STRING([--with-json-parsing], [JSON parsing support]))
-
-AS_IF([test "x$with_json_parsing" = "xyes"],
-       [PKG_CHECK_MODULES([LIBJSON], [jansson >= 2.3])],
-       [with_json_parsing="no"]
-)
 AC_PROG_CC
 AM_PROG_CC_C_O
 AC_EXEEXT
@@ -35,9 +28,6 @@ esac
 
 regular_CPPFLAGS="-D_FILE_OFFSET_BITS=64 -D_REENTRANT"
 
-AS_IF([test "x$with_json_parsing" = "xyes"], [
-       regular_CPPFLAGS="$regular_CPPFLAGS -DJSON_PARSING"
-])
 regular_CFLAGS="-Wall -Waggregate-return -Wmissing-declarations \
        -Wmissing-prototypes -Wshadow -Wstrict-prototypes \
        -Wformat=2 -Wwrite-strings -pipe"
@@ -45,7 +35,3 @@ AC_SUBST([regular_CPPFLAGS])
 AC_SUBST([regular_CFLAGS])
 AC_CONFIG_FILES([Makefile src/Makefile include/Makefile include/libnftnl/Makefile include/linux/Makefile include/linux/netfilter/Makefile examples/Makefile tests/Makefile libnftnl.pc doxygen.cfg])
 AC_OUTPUT
-
-echo "
-libnftnl configuration:
-  JSON support:                                ${with_json_parsing}"
index 67f01560ef599c8f3c6b3e2570bbf60f15e0c72a..d044b90738b9bd44538f97959259db2318b67e13 100644 (file)
@@ -1,21 +1,17 @@
 include $(top_srcdir)/Make_global.am
 
 check_PROGRAMS = nft-table-add         \
-                nft-table-parse-add    \
                 nft-table-upd          \
                 nft-table-del          \
                 nft-table-get          \
                 nft-chain-add          \
-                nft-chain-parse-add    \
                 nft-chain-del          \
                 nft-chain-get          \
                 nft-rule-add           \
-                nft-rule-parse-add     \
                 nft-rule-del           \
                 nft-rule-get           \
                 nft-events             \
                 nft-set-add            \
-                nft-set-parse-add      \
                 nft-set-get            \
                 nft-set-del            \
                 nft-map-add            \
@@ -32,7 +28,6 @@ check_PROGRAMS = nft-table-add                \
                 nft-flowtable-del      \
                 nft-flowtable-get      \
                 nft-ruleset-get        \
-                nft-ruleset-parse-file \
                 nft-compat-get         \
                 nft-ct-helper-add      \
                 nft-ct-helper-get      \
@@ -43,9 +38,6 @@ check_PROGRAMS = nft-table-add                \
 nft_table_add_SOURCES = nft-table-add.c
 nft_table_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
-nft_table_parse_add_SOURCES = nft-table-parse-add.c
-nft_table_parse_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
-
 nft_table_upd_SOURCES = nft-table-upd.c
 nft_table_upd_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
@@ -58,9 +50,6 @@ nft_table_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 nft_chain_add_SOURCES = nft-chain-add.c
 nft_chain_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
-nft_chain_parse_add_SOURCES = nft-chain-parse-add.c
-nft_chain_parse_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
-
 nft_chain_del_SOURCES = nft-chain-del.c
 nft_chain_del_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
@@ -70,9 +59,6 @@ nft_chain_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 nft_rule_add_SOURCES = nft-rule-add.c
 nft_rule_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
-nft_rule_parse_add_SOURCES = nft-rule-parse-add.c
-nft_rule_parse_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
-
 nft_rule_del_SOURCES = nft-rule-del.c
 nft_rule_del_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
@@ -85,9 +71,6 @@ nft_events_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 nft_set_add_SOURCES = nft-set-add.c
 nft_set_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
-nft_set_parse_add_SOURCES = nft-set-parse-add.c
-nft_set_parse_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
-
 nft_set_del_SOURCES = nft-set-del.c
 nft_set_del_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
@@ -136,9 +119,6 @@ nft_flowtable_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 nft_ruleset_get_SOURCES = nft-ruleset-get.c
 nft_ruleset_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
-nft_ruleset_parse_file_SOURCES = nft-ruleset-parse-file.c
-nft_ruleset_parse_file_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
-
 nft_compat_get_SOURCES = nft-compat-get.c
 nft_compat_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
index 6fda2d8124d03afece55c7987b274ee9d8817900..fcccbf718fd7ee25cbdebecb1241192efa80e049 100644 (file)
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
        seq = time(NULL);
 
        if (argc < 2 || argc > 5) {
-               fprintf(stderr, "Usage: %s <family> [<table> <chain>] [json]\n",
+               fprintf(stderr, "Usage: %s <family> [<table> <chain>]\n",
                        argv[0]);
                exit(EXIT_FAILURE);
        }
@@ -95,9 +95,6 @@ int main(int argc, char *argv[])
                                                NLM_F_DUMP, seq);
        }
 
-       if (strcmp(argv[argc-1], "json") == 0)
-               type = NFTNL_OUTPUT_JSON;
-
        nl = mnl_socket_open(NETLINK_NETFILTER);
        if (nl == NULL) {
                perror("mnl_socket_open");
diff --git a/examples/nft-chain-parse-add.c b/examples/nft-chain-parse-add.c
deleted file mode 100644 (file)
index 9198615..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * (C) 2013 by Pablo Neira Ayuso <pablo@netfilter.org>
- * (C) 2014 by Arturo Borrero Gonzalez <arturo@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This code has been sponsored by Sophos Astaro <http://www.sophos.com>
- */
-
-#include <stdlib.h>
-#include <time.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <linux/netfilter.h>
-#include <linux/netfilter/nf_tables.h>
-
-#include <libmnl/libmnl.h>
-#include <libnftnl/chain.h>
-#include <libnftnl/rule.h>
-
-static struct nftnl_chain *chain_parse_file(const char *file, uint16_t format)
-{
-       int fd;
-       struct nftnl_chain *c;
-       struct nftnl_parse_err *err;
-       char data[4096];
-
-       c = nftnl_chain_alloc();
-       if (c == NULL) {
-               perror("OOM");
-               return NULL;
-       }
-
-       fd = open(file, O_RDONLY);
-       if (fd < 0) {
-               perror("open");
-               return NULL;
-       }
-
-       if (read(fd, data, sizeof(data)) < 0) {
-               perror("read");
-               close(fd);
-               return NULL;
-       }
-
-       close(fd);
-
-       err = nftnl_parse_err_alloc();
-       if (err == NULL) {
-               perror("OOM");
-               return NULL;
-       }
-
-       if (nftnl_chain_parse(c, format, data, err) < 0) {
-               nftnl_parse_perror("Unable to parse file", err);
-               nftnl_parse_err_free(err);
-               return NULL;
-       }
-
-       nftnl_parse_err_free(err);
-       return c;
-}
-
-int main(int argc, char *argv[])
-{
-       struct mnl_socket *nl;
-       char buf[MNL_SOCKET_BUFFER_SIZE];
-       struct nlmsghdr *nlh;
-       uint32_t portid, seq, chain_seq;
-       struct nftnl_chain *c;
-       uint16_t family, format, outformat;
-       struct mnl_nlmsg_batch *batch;
-       int ret;
-
-       if (argc < 3) {
-               printf("Usage: %s {json} <file>\n", argv[0]);
-               exit(EXIT_FAILURE);
-       }
-
-       if (strcmp(argv[1], "json") == 0) {
-               format = NFTNL_PARSE_JSON;
-               outformat = NFTNL_OUTPUT_JSON;
-       } else {
-               printf("Unknown format: only json is supported\n");
-               exit(EXIT_FAILURE);
-       }
-
-       c = chain_parse_file(argv[2], format);
-       if (c == NULL)
-               exit(EXIT_FAILURE);
-
-       nftnl_chain_fprintf(stdout, c, outformat, 0);
-       fprintf(stdout, "\n");
-
-       nftnl_chain_unset(c, NFTNL_CHAIN_HANDLE);
-       family = nftnl_chain_get_u32(c, NFTNL_CHAIN_FAMILY);
-
-       seq = time(NULL);
-
-       batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
-
-       nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
-       mnl_nlmsg_batch_next(batch);
-
-       chain_seq = seq;
-       nlh = nftnl_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
-                                       NFT_MSG_NEWCHAIN, family,
-                                       NLM_F_ACK, seq++);
-       nftnl_chain_nlmsg_build_payload(nlh, c);
-       nftnl_chain_free(c);
-       mnl_nlmsg_batch_next(batch);
-
-       nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
-       mnl_nlmsg_batch_next(batch);
-
-       nl = mnl_socket_open(NETLINK_NETFILTER);
-       if (nl == NULL) {
-               perror("mnl_socket_open");
-               exit(EXIT_FAILURE);
-       }
-
-       if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
-               perror("mnl_socket_bind");
-               exit(EXIT_FAILURE);
-       }
-
-       portid = mnl_socket_get_portid(nl);
-
-       if (mnl_socket_sendto(nl, mnl_nlmsg_batch_head(batch),
-                             mnl_nlmsg_batch_size(batch)) < 0) {
-               perror("mnl_socket_send");
-               exit(EXIT_FAILURE);
-       }
-
-       mnl_nlmsg_batch_stop(batch);
-
-       ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-       while (ret > 0) {
-               ret = mnl_cb_run(buf, ret, chain_seq, portid, NULL, NULL);
-               if (ret <= 0)
-                       break;
-               ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-       }
-       if (ret == -1) {
-               perror("error");
-               exit(EXIT_FAILURE);
-       }
-
-
-       mnl_socket_close(nl);
-       return EXIT_SUCCESS;
-}
index 94bd0cd8fbf70f5781dc12d0477c04130817664e..eb0313322ca792e7165855992618719580dd7474 100644 (file)
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
        uint32_t type = NFTNL_OUTPUT_DEFAULT;
 
        if (argc < 3 || argc > 5) {
-               fprintf(stderr, "%s <family> <table> [<obj>] [<default|xml|json>]\n",
+               fprintf(stderr, "%s <family> <table> [<obj>]\n",
                        argv[0]);
                return EXIT_FAILURE;
        }
@@ -76,18 +76,6 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       if (strcmp(argv[argc-1], "xml") == 0) {
-               type = NFTNL_OUTPUT_XML;
-               argv[argc-1] = NULL;
-               argc--;
-       }else if (strcmp(argv[argc-1], "json") == 0) {
-               type = NFTNL_OUTPUT_JSON;
-               argv[argc-1] = NULL;
-               argc--;
-       } else if (strcmp(argv[argc - 1], "default") == 0) {
-               argc--;
-       }
-
        if (argc == 3 || argc == 4) {
                t = nftnl_obj_alloc();
                if (t == NULL) {
index 503c488338533f12602fb7d5cbcc4c9a731af10e..badcd234529b9382caa2b4a9ec94899485527fc6 100644 (file)
@@ -58,8 +58,7 @@ int main(int argc, char *argv[])
        uint32_t type = NFTNL_OUTPUT_DEFAULT;
 
        if (argc < 3 || argc > 5) {
-               fprintf(stderr, "%s <family> <table> [<obj>] [<default|xml|json>]\n",
-                       argv[0]);
+               fprintf(stderr, "%s <family> <table> [<obj>]\n", argv[0]);
                return EXIT_FAILURE;
        }
 
@@ -76,18 +75,6 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       if (strcmp(argv[argc-1], "xml") == 0) {
-               type = NFTNL_OUTPUT_XML;
-               argv[argc-1] = NULL;
-               argc--;
-       } else if (strcmp(argv[argc-1], "json") == 0) {
-               type = NFTNL_OUTPUT_JSON;
-               argv[argc-1] = NULL;
-               argc--;
-       } else if (strcmp(argv[argc - 1], "default") == 0) {
-               argc--;
-       }
-
        if (argc == 3 || argc == 4) {
                t = nftnl_obj_alloc();
                if (t == NULL) {
index bd8c752e56687d44188c4676efb0f606e2065811..8aab90a118242287a4f2c18b5f59c77aeb777976 100644 (file)
@@ -235,18 +235,8 @@ int main(int argc, char *argv[])
        case 1:
                type = NFTNL_OUTPUT_DEFAULT;
                break;
-       case 2:
-               if (strcmp(argv[1], "json") == 0) {
-                       type = NFTNL_OUTPUT_JSON;
-               } else if (strcmp(argv[1], "default") == 0) {
-                       type = NFTNL_OUTPUT_DEFAULT;
-               } else {
-                       fprintf(stderr, "unknown format type `%s'\n", argv[1]);
-                       return EXIT_FAILURE;
-               }
-               break;
        default:
-               fprintf(stderr, "%s [<default|json>]\n", argv[0]);
+               fprintf(stderr, "%s\n", argv[0]);
                return EXIT_FAILURE;
        }
 
index 37cfadf0b1cdfefaae72871ca7df4372c5cda91a..1a034ce60579b118cb818cf2156f92951f01c7e5 100644 (file)
@@ -47,7 +47,7 @@ int main(int argc, char *argv[])
        seq = time(NULL);
 
        if (argc < 2 || argc > 5) {
-               fprintf(stderr, "Usage: %s <family> [<table> <flowtable>] [json]\n",
+               fprintf(stderr, "Usage: %s <family> [<table> <flowtable>]\n",
                        argv[0]);
                exit(EXIT_FAILURE);
        }
@@ -84,9 +84,6 @@ int main(int argc, char *argv[])
                                                NLM_F_DUMP, seq);
        }
 
-       if (strcmp(argv[argc-1], "json") == 0)
-               type = NFTNL_OUTPUT_JSON;
-
        nl = mnl_socket_open(NETLINK_NETFILTER);
        if (nl == NULL) {
                perror("mnl_socket_open");
index bec33b6937316d25925ae654f8c90a0441efb4c0..e6a19fe3baf8e811fcd6699f6e589613263ad5bd 100644 (file)
@@ -57,8 +57,7 @@ int main(int argc, char *argv[])
        uint32_t type = NFTNL_OUTPUT_DEFAULT;
 
        if (argc < 2 || argc > 5) {
-               fprintf(stderr, "%s <family> <table> [<obj>] [<default|xml|json>]\n",
-                       argv[0]);
+               fprintf(stderr, "%s <family> <table> [<obj>]\n", argv[0]);
                return EXIT_FAILURE;
        }
 
@@ -77,18 +76,6 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       if (strcmp(argv[argc-1], "xml") == 0) {
-               type = NFTNL_OUTPUT_XML;
-               argv[argc-1] = NULL;
-               argc--;
-       }else if (strcmp(argv[argc-1], "json") == 0) {
-               type = NFTNL_OUTPUT_JSON;
-               argv[argc-1] = NULL;
-               argc--;
-       } else if (strcmp(argv[argc - 1], "default") == 0) {
-               argc--;
-       }
-
        if (argc == 3 || argc == 4) {
                t = nftnl_obj_alloc();
                if (t == NULL) {
index aa496125570bd7874682a5dbecb1de7783cf4189..8a980ef180b08a5a494dcc307a47d1b66765c085 100644 (file)
@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
        int ret, family;
 
        if (argc < 2 || argc > 5) {
-               fprintf(stderr, "Usage: %s <family> [<table> <chain>] [json]\n",
+               fprintf(stderr, "Usage: %s <family> [<table> <chain>]\n",
                        argv[0]);
                exit(EXIT_FAILURE);
        }
@@ -102,12 +102,6 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       /* json specified */
-       if (argc == 3 || argc == 5) {
-               if (strcmp(argv[argc - 1], "json") == 0)
-                       type = NFTNL_OUTPUT_JSON;
-       }
-
        /* at least [<table> <chain>] specified */
        if (argc >= 4) {
                table = argv[2];
diff --git a/examples/nft-rule-parse-add.c b/examples/nft-rule-parse-add.c
deleted file mode 100644 (file)
index 3fcf269..0000000
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * (C) 2013 by Pablo Neira Ayuso <pablo@netfilter.org>
- * (C) 2013 by Arturo Borrero Gonzalez <arturo@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This code has been sponsored by Sophos Astaro <http://www.sophos.com>
- */
-
-#include <stdlib.h>
-#include <time.h>
-#include <string.h>
-#include <stddef.h>    /* for offsetof */
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <linux/netfilter.h>
-#include <linux/netfilter/nf_tables.h>
-
-#include <libmnl/libmnl.h>
-#include <libnftnl/rule.h>
-
-static struct nftnl_rule *rule_parse_file(const char *file, uint16_t format)
-{
-       int fd;
-       struct nftnl_rule *r;
-       struct nftnl_parse_err *err;
-       char data[4096];
-
-       fd = open(file, O_RDONLY);
-       if (fd < 0) {
-               perror("open");
-               return NULL;
-       }
-
-       if (read(fd, data, sizeof(data)) < 0) {
-               perror("read");
-               close(fd);
-               return NULL;
-       }
-       close(fd);
-
-       r = nftnl_rule_alloc();
-       if (r == NULL) {
-               perror("OOM");
-               exit(EXIT_FAILURE);
-       }
-
-       err = nftnl_parse_err_alloc();
-       if (err == NULL) {
-               perror("error");
-               exit(EXIT_FAILURE);
-       }
-
-       if (nftnl_rule_parse(r, format, data, err) < 0) {
-               nftnl_parse_perror("Unable to parse file", err);
-               nftnl_parse_err_free(err);
-               nftnl_rule_free(r);
-               return NULL;
-       }
-
-       nftnl_rule_unset(r, NFTNL_RULE_HANDLE);
-
-       nftnl_parse_err_free(err);
-       return r;
-}
-
-int main(int argc, char *argv[])
-{
-       struct mnl_socket *nl;
-       struct mnl_nlmsg_batch *batch;
-       char buf[MNL_SOCKET_BUFFER_SIZE];
-       struct nlmsghdr *nlh;
-       uint32_t portid, seq, rule_seq;
-       struct nftnl_rule *r;
-       int ret;
-       uint16_t family, format, outformat;
-
-       if (argc < 3) {
-               printf("Usage: %s {json} <file>\n", argv[0]);
-               exit(EXIT_FAILURE);
-       }
-
-       if (strcmp(argv[1], "json") == 0) {
-               format = NFTNL_PARSE_JSON;
-               outformat = NFTNL_OUTPUT_JSON;
-       } else {
-               printf("Unknown format: json\n");
-               exit(EXIT_FAILURE);
-       }
-
-       r = rule_parse_file(argv[2], format);
-       if (r == NULL)
-               exit(EXIT_FAILURE);
-
-       nftnl_rule_fprintf(stdout, r, outformat, 0);
-       fprintf(stdout, "\n");
-
-       seq = time(NULL);
-       batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
-
-       nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
-       mnl_nlmsg_batch_next(batch);
-
-       rule_seq = seq;
-       family = nftnl_rule_get_u32(r, NFTNL_RULE_FAMILY);
-       nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
-                                      NFT_MSG_NEWRULE, family,
-                                      NLM_F_CREATE|NLM_F_APPEND|NLM_F_ACK,
-                                      seq++);
-       nftnl_rule_nlmsg_build_payload(nlh, r);
-       nftnl_rule_free(r);
-       mnl_nlmsg_batch_next(batch);
-
-       nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
-       mnl_nlmsg_batch_next(batch);
-
-       nl = mnl_socket_open(NETLINK_NETFILTER);
-       if (nl == NULL) {
-               perror("mnl_socket_open");
-               exit(EXIT_FAILURE);
-       }
-
-       if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
-               perror("mnl_socket_bind");
-               exit(EXIT_FAILURE);
-       }
-       portid = mnl_socket_get_portid(nl);
-
-       if (mnl_socket_sendto(nl, mnl_nlmsg_batch_head(batch),
-                             mnl_nlmsg_batch_size(batch)) < 0) {
-               perror("mnl_socket_send");
-               exit(EXIT_FAILURE);
-       }
-
-       mnl_nlmsg_batch_stop(batch);
-
-       ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-       while (ret > 0) {
-               ret = mnl_cb_run(buf, ret, rule_seq, portid, NULL, NULL);
-               if (ret <= 0)
-                       break;
-               ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-       }
-       if (ret == -1) {
-               perror("error");
-               exit(EXIT_FAILURE);
-       }
-       mnl_socket_close(nl);
-
-       return EXIT_SUCCESS;
-}
index 9e80bb6f8338b4eba660c3a678aba6beed88bc9f..70984370bc4d8ef5d253931c4f370dcb33e99283 100644 (file)
@@ -344,20 +344,10 @@ int main(int argc, char *argv[])
        int ret;
 
        if (argc > 2) {
-               fprintf(stderr, "%s {json}\n",
-                       argv[0]);
+               fprintf(stderr, "%s\n", argv[0]);
                exit(EXIT_FAILURE);
        }
 
-       if (argc == 2) {
-               if (strcmp(argv[1], "json") == 0)
-                       type = NFTNL_OUTPUT_JSON;
-               else {
-                       fprintf(stderr, "Unknown type: only json is supported\n");
-                       exit(EXIT_FAILURE);
-               }
-       }
-
        nl = mnl_socket_open(NETLINK_NETFILTER);
        if (nl == NULL) {
                perror("mnl_socket_open");
diff --git a/examples/nft-ruleset-parse-file.c b/examples/nft-ruleset-parse-file.c
deleted file mode 100644 (file)
index be0994f..0000000
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- * (C) 2014 by Alvaro Neira Ayuso <alvaroneay@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#include <stdlib.h>
-#include <time.h>
-#include <string.h>
-#include <stddef.h>     /* for offsetof */
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
-#include <arpa/inet.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <errno.h>
-
-#include <linux/netfilter.h>
-#include <linux/netfilter/nfnetlink.h>
-#include <linux/netfilter/nf_tables.h>
-
-#include <libmnl/libmnl.h>
-#include <libnftnl/ruleset.h>
-#include <libnftnl/table.h>
-#include <libnftnl/chain.h>
-#include <libnftnl/rule.h>
-#include <libnftnl/set.h>
-
-struct mnl_nlmsg_batch *batch;
-uint32_t seq;
-
-static int nftnl_ruleset_set_elems(const struct nftnl_parse_ctx *ctx)
-{
-       struct nftnl_set_elems_iter *iter_elems;
-       uint16_t nl_type, nl_flags;
-       uint32_t cmd;
-       struct nlmsghdr *nlh;
-       struct nftnl_set *set;
-
-       cmd = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_CMD);
-
-       set = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_SET);
-       if (set == NULL)
-               return -1;
-
-       switch (cmd) {
-       case NFTNL_CMD_ADD:
-               nl_type = NFT_MSG_NEWSETELEM;
-               nl_flags = NLM_F_CREATE|NLM_F_EXCL|NLM_F_ACK;
-               break;
-       case NFTNL_CMD_DELETE:
-               nl_type = NFT_MSG_DELSETELEM;
-               /* This will generate an ACK message for each request. When
-                * removing NLM_F_ACK, the kernel will only report when things
-                * go wrong
-                */
-               nl_flags = NLM_F_ACK;
-               break;
-       default:
-               goto err;
-       }
-
-       iter_elems = nftnl_set_elems_iter_create(set);
-       if (iter_elems == NULL)
-               goto err;
-
-       nlh = nftnl_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch), nl_type,
-                                     nftnl_set_get_u32(set,
-                                                          NFTNL_SET_FAMILY),
-                                     nl_flags, seq++);
-
-       nftnl_set_elems_nlmsg_build_payload_iter(nlh, iter_elems);
-       mnl_nlmsg_batch_next(batch);
-
-       nftnl_set_elems_iter_destroy(iter_elems);
-       return 0;
-err:
-       return -1;
-}
-
-static int nftnl_ruleset_parse_set(const struct nftnl_parse_ctx *ctx)
-{
-
-       struct nlmsghdr *nlh;
-       uint16_t nl_type, nl_flags;
-       struct nftnl_set *set;
-       uint32_t cmd;
-       int ret;
-
-       cmd = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_CMD);
-
-       set = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_SET);
-       if (set == NULL)
-               return -1;
-
-       switch (cmd) {
-       case NFTNL_CMD_ADD:
-               nl_type = NFT_MSG_NEWSET;
-               nl_flags = NLM_F_CREATE|NLM_F_ACK;
-               break;
-       case NFTNL_CMD_DELETE:
-               nl_type = NFT_MSG_DELSET;
-               nl_flags = NLM_F_ACK;
-               break;
-       default:
-               goto err;
-       }
-
-       nlh = nftnl_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
-                                     nl_type,
-                                     nftnl_set_get_u32(set,
-                                                          NFTNL_SET_FAMILY),
-                                     nl_flags,
-                                     seq++);
-
-       nftnl_set_nlmsg_build_payload(nlh, set);
-       mnl_nlmsg_batch_next(batch);
-
-       ret = nftnl_ruleset_set_elems(ctx);
-       return ret;
-err:
-       return -1;
-}
-
-static int nftnl_ruleset_rule_build_msg(const struct nftnl_parse_ctx *ctx,
-                                     uint32_t cmd, struct nftnl_rule *rule)
-{
-       struct nlmsghdr *nlh;
-       uint16_t nl_type, nl_flags;
-
-       switch (cmd) {
-       case NFTNL_CMD_ADD:
-               nl_type = NFT_MSG_NEWRULE;
-               nl_flags = NLM_F_APPEND|NLM_F_CREATE|NLM_F_ACK;
-               nftnl_rule_unset(rule, NFTNL_RULE_HANDLE);
-               break;
-       case NFTNL_CMD_DELETE:
-               nl_type = NFT_MSG_DELRULE;
-               nl_flags = NLM_F_ACK;
-               break;
-       case NFTNL_CMD_REPLACE:
-               nl_type = NFT_MSG_NEWRULE;
-               nl_flags = NLM_F_REPLACE|NLM_F_ACK;
-               break;
-       case NFTNL_CMD_INSERT:
-               nl_type = NFT_MSG_NEWRULE;
-               nl_flags = NLM_F_CREATE|NLM_F_ACK;
-               nftnl_rule_unset(rule, NFTNL_RULE_HANDLE);
-               break;
-       default:
-               return -1;
-       }
-
-       nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
-                                      nl_type,
-                                      nftnl_rule_get_u32(rule,
-                                                         NFTNL_RULE_FAMILY),
-                                      nl_flags,
-                                      seq++);
-
-       nftnl_rule_nlmsg_build_payload(nlh, rule);
-       mnl_nlmsg_batch_next(batch);
-
-       return 0;
-}
-
-static int nftnl_ruleset_rule(const struct nftnl_parse_ctx *ctx)
-{
-       struct nftnl_rule *rule;
-       int ret;
-       uint32_t cmd;
-
-       cmd = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_CMD);
-
-       rule = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_RULE);
-       if (rule == NULL)
-               return -1;
-
-       ret = nftnl_ruleset_rule_build_msg(ctx, cmd, rule);
-
-       return ret;
-}
-
-static int nftnl_ruleset_flush_rules(const struct nftnl_parse_ctx *ctx)
-{
-       struct nftnl_rule *nlr;
-       struct nftnl_table *nlt;
-       struct nftnl_chain *nlc;
-       uint32_t type;
-       int ret;
-
-       nlr = nftnl_rule_alloc();
-       if (nlr == NULL)
-               return -1;
-
-       type = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_TYPE);
-       switch (type) {
-       case NFTNL_RULESET_TABLE:
-               nlt = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_TABLE);
-               nftnl_rule_set(nlr, NFTNL_RULE_TABLE,
-                                 nftnl_table_get(nlt, NFTNL_TABLE_NAME));
-               nftnl_rule_set(nlr, NFTNL_RULE_FAMILY,
-                               nftnl_table_get(nlt, NFTNL_TABLE_FAMILY));
-               break;
-       case NFTNL_RULESET_CHAIN:
-               nlc = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_CHAIN);
-               nftnl_rule_set(nlr, NFTNL_RULE_TABLE,
-                                 nftnl_chain_get(nlc,
-                                                    NFTNL_CHAIN_TABLE));
-               nftnl_rule_set(nlr, NFTNL_RULE_CHAIN,
-                                 nftnl_chain_get(nlc,
-                                                    NFTNL_CHAIN_NAME));
-               nftnl_rule_set(nlr, NFTNL_RULE_FAMILY,
-                               nftnl_chain_get(nlc, NFTNL_TABLE_FAMILY));
-               break;
-       default:
-               goto err;
-       }
-
-       ret = nftnl_ruleset_rule_build_msg(ctx, NFTNL_CMD_DELETE, nlr);
-       nftnl_rule_free(nlr);
-
-       return ret;
-err:
-       nftnl_rule_free(nlr);
-       return -1;
-}
-
-static int nftnl_ruleset_chain(const struct nftnl_parse_ctx *ctx)
-{
-       struct nlmsghdr *nlh;
-       uint16_t nl_type, nl_flags;
-       uint32_t cmd;
-       struct nftnl_chain *chain;
-
-       cmd = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_CMD);
-
-       chain = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_CHAIN);
-       if (chain == NULL)
-               return -1;
-
-       switch (cmd) {
-       case NFTNL_CMD_ADD:
-               nl_type = NFT_MSG_NEWCHAIN;
-               nl_flags = NLM_F_CREATE|NLM_F_ACK;
-               break;
-       case NFTNL_CMD_DELETE:
-               nl_type = NFT_MSG_DELCHAIN;
-               nl_flags = NLM_F_ACK;
-               break;
-       case NFTNL_CMD_FLUSH:
-               return nftnl_ruleset_flush_rules(ctx);
-       default:
-               goto err;
-       }
-
-       nftnl_chain_unset(chain, NFTNL_CHAIN_HANDLE);
-       nlh = nftnl_chain_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
-                                       nl_type,
-                                       nftnl_chain_get_u32(chain,
-                                                        NFTNL_CHAIN_FAMILY),
-                                       nl_flags,
-                                       seq++);
-
-       nftnl_chain_nlmsg_build_payload(nlh, chain);
-       mnl_nlmsg_batch_next(batch);
-
-       return 0;
-err:
-       return -1;
-}
-
-static int nftnl_ruleset_table_build_msg(const struct nftnl_parse_ctx *ctx,
-                                      uint32_t cmd, struct nftnl_table *table)
-{
-       struct nlmsghdr *nlh;
-       uint16_t nl_type, nl_flags;
-
-       switch (cmd) {
-       case NFTNL_CMD_ADD:
-               nl_type = NFT_MSG_NEWTABLE;
-               nl_flags = NLM_F_CREATE|NLM_F_ACK;
-               break;
-       case NFTNL_CMD_DELETE:
-               nl_type = NFT_MSG_DELTABLE;
-               nl_flags = NLM_F_ACK;
-               break;
-       case NFTNL_CMD_FLUSH:
-               return nftnl_ruleset_flush_rules(ctx);
-       default:
-               return -1;
-       }
-
-       nlh = nftnl_table_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
-                                       nl_type,
-                                       nftnl_table_get_u32(table,
-                                                        NFTNL_TABLE_FAMILY),
-                                       nl_flags,
-                                       seq++);
-
-       nftnl_table_nlmsg_build_payload(nlh, table);
-       mnl_nlmsg_batch_next(batch);
-
-       return 0;
-}
-
-static int nftnl_ruleset_table(const struct nftnl_parse_ctx *ctx)
-{
-       struct nftnl_table *table;
-       uint32_t cmd;
-       int ret;
-
-       cmd = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_CMD);
-
-       table = nftnl_ruleset_ctx_get(ctx, NFTNL_RULESET_CTX_TABLE);
-       if (table == NULL)
-               return -1;
-
-       ret = nftnl_ruleset_table_build_msg(ctx, cmd, table);
-
-       return ret;
-}
-
-static int nftnl_ruleset_flush_ruleset(const struct nftnl_parse_ctx *ctx)
-{
-       struct nftnl_table *table;
-       int ret;
-
-       table = nftnl_table_alloc();
-       if (table == NULL)
-               return -1;
-
-       ret = nftnl_ruleset_table_build_msg(ctx, NFTNL_CMD_DELETE, table);
-       nftnl_table_free(table);
-
-       return ret;
-}
-
-static int ruleset_elems_cb(const struct nftnl_parse_ctx *ctx)
-{
-       uint32_t type;
-       int ret;
-
-       type = nftnl_ruleset_ctx_get_u32(ctx, NFTNL_RULESET_CTX_TYPE);
-
-       switch (type) {
-       case NFTNL_RULESET_TABLE:
-               ret = nftnl_ruleset_table(ctx);
-               break;
-       case NFTNL_RULESET_CHAIN:
-               ret = nftnl_ruleset_chain(ctx);
-               break;
-       case NFTNL_RULESET_RULE:
-               ret = nftnl_ruleset_rule(ctx);
-               break;
-       case NFTNL_RULESET_SET:
-               ret = nftnl_ruleset_parse_set(ctx);
-               break;
-       case NFTNL_RULESET_SET_ELEMS:
-               ret = nftnl_ruleset_set_elems(ctx);
-               break;
-       case NFTNL_RULESET_RULESET:
-               ret = nftnl_ruleset_flush_ruleset(ctx);
-               break;
-       default:
-               return -1;
-       }
-
-       nftnl_ruleset_ctx_free(ctx);
-       return ret;
-}
-
-int main(int argc, char *argv[])
-{
-       struct nftnl_parse_err *err;
-       const char *filename;
-       FILE *fp;
-       int ret = -1, len, portid;
-       uint32_t ruleset_seq;
-       char buf[MNL_SOCKET_BUFFER_SIZE];
-       struct mnl_socket *nl;
-
-       if (argc < 2) {
-               printf("Usage: %s <file>\n", argv[0]);
-               exit(EXIT_FAILURE);
-       }
-
-       fp = fopen(argv[1], "r");
-       if (fp == NULL) {
-               printf("unable to open file %s: %s\n", argv[1],
-                      strerror(errno));
-               exit(EXIT_FAILURE);
-       }
-
-       err = nftnl_parse_err_alloc();
-       if (err == NULL) {
-               perror("error");
-               exit(EXIT_FAILURE);
-       }
-
-       seq = time(NULL);
-       batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
-
-       nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
-       mnl_nlmsg_batch_next(batch);
-       ruleset_seq = seq;
-
-       filename = argv[1];
-       len = strlen(filename);
-       if (len >= 5 && strcmp(&filename[len - 5], ".json") == 0)
-               ret = nftnl_ruleset_parse_file_cb(NFTNL_PARSE_JSON, fp, err, NULL,
-                                               &ruleset_elems_cb);
-       else {
-               printf("the filename %s does not have a trailing .json\n",
-                       filename);
-               exit(EXIT_FAILURE);
-       }
-
-       if (ret < 0) {
-               nftnl_parse_perror("fail", err);
-               exit(EXIT_FAILURE);
-       }
-
-       fclose(fp);
-
-       nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
-       mnl_nlmsg_batch_next(batch);
-
-       nl = mnl_socket_open(NETLINK_NETFILTER);
-       if (nl == NULL) {
-               perror("mnl_socket_open");
-               exit(EXIT_FAILURE);
-       }
-
-       if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
-               perror("mnl_socket_bind");
-               exit(EXIT_FAILURE);
-       }
-       portid = mnl_socket_get_portid(nl);
-
-       if (mnl_socket_sendto(nl, mnl_nlmsg_batch_head(batch),
-                             mnl_nlmsg_batch_size(batch)) < 0) {
-               perror("mnl_socket_send");
-               exit(EXIT_FAILURE);
-       }
-
-       mnl_nlmsg_batch_stop(batch);
-
-       ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-       while (ret > 0) {
-               ret = mnl_cb_run(buf, ret, ruleset_seq, portid, NULL, NULL);
-               if (ret <= 0)
-                       break;
-               ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-       }
-       if (ret == -1) {
-               perror("error");
-               exit(EXIT_FAILURE);
-       }
-
-       mnl_socket_close(nl);
-       return EXIT_SUCCESS;
-}
index 9a3ccd7cf2d46612bfdfb107c93f98de83ebcce9..1bc9abca3711ab330cbd764e81afefa46f373dbf 100644 (file)
@@ -57,8 +57,7 @@ int main(int argc, char *argv[])
        int ret;
 
        if (argc < 4 || argc > 5) {
-               fprintf(stderr, "%s <family> <table> <set> [<json>]\n",
-                       argv[0]);
+               fprintf(stderr, "%s <family> <table> <set>\n", argv[0]);
                return EXIT_FAILURE;
        }
        t = nftnl_set_alloc();
@@ -80,9 +79,6 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       if (argc == 5 && strcmp(argv[4], "json") == 0 )
-               type = NFTNL_OUTPUT_JSON;
-
        nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_GETSETELEM, family,
                                        NLM_F_DUMP|NLM_F_ACK, seq);
        nftnl_set_set(t, NFTNL_SET_NAME, argv[3]);
index c4ad8ee3b4dde8d0ad45ac99297dbb7fd37a5ba2..bb33674c0df7c2b673920123e0f6ac68f23157c3 100644 (file)
@@ -57,7 +57,7 @@ int main(int argc, char *argv[])
        int ret;
 
        if (argc < 2 || argc > 3) {
-               fprintf(stderr, "%s <family> [<json>]\n", argv[0]);
+               fprintf(stderr, "%s <family>\n", argv[0]);
                return EXIT_FAILURE;
        }
        t = nftnl_set_alloc();
@@ -81,9 +81,6 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       if (argc == 3 && strcmp(argv[2], "json") == 0)
-               type = NFTNL_OUTPUT_JSON;
-
        nlh = nftnl_set_nlmsg_build_hdr(buf, NFT_MSG_GETSET, family,
                                        NLM_F_DUMP|NLM_F_ACK, seq);
        /* Use this below if you want to obtain sets per table */
diff --git a/examples/nft-set-parse-add.c b/examples/nft-set-parse-add.c
deleted file mode 100644 (file)
index 5197dc3..0000000
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * (C) 2013 by Álvaro Neira Ayuso <alvaroneay@gmail.com>
- *
- * Based on nft-set-xml-add from:
- *
- * (C) 2013 by Pablo Neira Ayuso <pablo@netfilter.org>
- * (C) 2013 by Arturo Borrero Gonzalez <arturo@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#include <stdlib.h>
-#include <time.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <linux/netfilter.h>
-#include <linux/netfilter/nf_tables.h>
-#include <linux/netfilter/nfnetlink.h>
-
-#include <libmnl/libmnl.h>
-#include <libnftnl/set.h>
-
-static struct nftnl_set *set_parse_file(const char *file, uint16_t format)
-{
-       int fd;
-       struct nftnl_set *s;
-       struct nftnl_parse_err *err;
-       char data[4096];
-
-       s = nftnl_set_alloc();
-       if (s == NULL) {
-               perror("OOM");
-               return NULL;
-       }
-
-       fd = open(file, O_RDONLY);
-       if (fd < 0) {
-               perror("open");
-               return NULL;
-       }
-
-       if (read(fd, data, sizeof(data)) < 0) {
-               perror("read");
-               close(fd);
-               return NULL;
-       }
-       close(fd);
-
-       err = nftnl_parse_err_alloc();
-       if (err == NULL) {
-               perror("error");
-               return NULL;
-       }
-
-       if (nftnl_set_parse(s, format, data, err) < 0) {
-               nftnl_parse_perror("Unable to parse file", err);
-               nftnl_parse_err_free(err);
-               return NULL;
-       }
-
-       nftnl_parse_err_free(err);
-
-       nftnl_set_set_u32(s, NFTNL_SET_ID, 1);
-       return s;
-
-}
-
-int main(int argc, char *argv[])
-{
-       struct mnl_socket *nl;
-       char buf[MNL_SOCKET_BUFFER_SIZE];
-       struct nlmsghdr *nlh;
-       uint32_t portid, seq, set_seq;
-       struct nftnl_set *s;
-       uint16_t family, format, outformat;
-       struct mnl_nlmsg_batch *batch;
-       int ret;
-
-       if (argc < 2) {
-               printf("Usage: %s {json} <file>\n", argv[0]);
-               exit(EXIT_FAILURE);
-       }
-
-       if (strcmp(argv[1], "json") == 0) {
-               format = NFTNL_PARSE_JSON;
-               outformat = NFTNL_OUTPUT_JSON;
-       } else {
-               printf("Unknown format: only json is supported\n");
-               exit(EXIT_FAILURE);
-       }
-
-       s = set_parse_file(argv[2], format);
-       if (s == NULL)
-               exit(EXIT_FAILURE);
-
-       nftnl_set_fprintf(stdout, s, outformat, 0);
-       fprintf(stdout, "\n");
-
-       seq = time(NULL);
-
-       batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
-
-       nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
-       mnl_nlmsg_batch_next(batch);
-
-       family = nftnl_set_get_u32(s, NFTNL_SET_FAMILY);
-
-       set_seq = seq;
-       nlh = nftnl_set_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
-                                     NFT_MSG_NEWSET, family,
-                                     NLM_F_CREATE|NLM_F_ACK, seq++);
-       nftnl_set_nlmsg_build_payload(nlh, s);
-       nftnl_set_free(s);
-       mnl_nlmsg_batch_next(batch);
-
-       nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
-       mnl_nlmsg_batch_next(batch);
-
-       nl = mnl_socket_open(NETLINK_NETFILTER);
-       if (nl == NULL) {
-               perror("mnl_socket_open");
-               exit(EXIT_FAILURE);
-       }
-
-       if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
-               perror("mnl_socket_bind");
-               exit(EXIT_FAILURE);
-       }
-       portid = mnl_socket_get_portid(nl);
-
-       if (mnl_socket_sendto(nl, mnl_nlmsg_batch_head(batch),
-                             mnl_nlmsg_batch_size(batch)) < 0) {
-               perror("mnl_socket_send");
-               exit(EXIT_FAILURE);
-       }
-
-       mnl_nlmsg_batch_stop(batch);
-
-       ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-       while (ret > 0) {
-               ret = mnl_cb_run(buf, ret, set_seq, portid, NULL, NULL);
-               if (ret <= 0)
-                       break;
-               ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-       }
-       if (ret == -1) {
-               perror("error");
-               exit(EXIT_FAILURE);
-       }
-
-       mnl_socket_close(nl);
-
-       return EXIT_SUCCESS;
-}
index 193db7724a9ec7580cecb285877d6e4ce7e5bcf2..eac2f2f6dfc8f49a559cf0a9e21ced423e6b0a70 100644 (file)
@@ -57,8 +57,7 @@ int main(int argc, char *argv[])
        uint32_t type = NFTNL_OUTPUT_DEFAULT;
 
        if (argc < 2 || argc > 4) {
-               fprintf(stderr, "%s <family> [<table>] [<default|json>]\n",
-                       argv[0]);
+               fprintf(stderr, "%s <family> [<table>]\n", argv[0]);
                return EXIT_FAILURE;
        }
 
@@ -77,14 +76,6 @@ int main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       if (strcmp(argv[argc-1], "json") == 0) {
-               type = NFTNL_OUTPUT_JSON;
-               argv[argc-1] = NULL;
-               argc--;
-       } else if (strcmp(argv[argc - 1], "default") == 0) {
-               argc--;
-       }
-
        if (argc == 3) {
                t = nftnl_table_alloc();
                if (t == NULL) {
diff --git a/examples/nft-table-parse-add.c b/examples/nft-table-parse-add.c
deleted file mode 100644 (file)
index 55dbc13..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * (C) 2013 by Pablo Neira Ayuso <pablo@netfilter.org>
- * (C) 2013 by Arturo Borrero Gonzalez <arturo@debian.org>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This code has been sponsored by Sophos Astaro <http://www.sophos.com>
- */
-
-#include <stdlib.h>
-#include <time.h>
-#include <string.h>
-#include <netinet/in.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-
-#include <linux/netfilter/nf_tables.h>
-
-#include <libmnl/libmnl.h>
-#include <libnftnl/table.h>
-#include <libnftnl/common.h>
-
-static struct nftnl_table *table_parse_file(const char *file, uint16_t format)
-{
-       int fd;
-       struct nftnl_table *t;
-       struct nftnl_parse_err *err;
-       char data[4096];
-
-       t = nftnl_table_alloc();
-       if (t == NULL) {
-               perror("OOM");
-               return NULL;
-       }
-
-       fd = open(file, O_RDONLY);
-       if (fd < 0) {
-               perror("open");
-               return NULL;
-       }
-
-       if (read(fd, data, sizeof(data)) < 0) {
-               perror("read");
-               close(fd);
-               return NULL;
-       }
-       close(fd);
-
-       err = nftnl_parse_err_alloc();
-       if (err == NULL) {
-               perror("error");
-               return NULL;
-       }
-
-       if (nftnl_table_parse(t, format, data, err) < 0) {
-               nftnl_parse_perror("Unable to parse file", err);
-               nftnl_parse_err_free(err);
-               return NULL;
-       }
-
-       nftnl_parse_err_free(err);
-       return t;
-
-}
-
-int main(int argc, char *argv[])
-{
-       struct mnl_socket *nl;
-       char buf[MNL_SOCKET_BUFFER_SIZE];
-       struct nlmsghdr *nlh;
-       uint32_t portid, seq, table_seq;
-       struct nftnl_table *t = NULL;
-       uint16_t family, format, outformat;
-       struct mnl_nlmsg_batch *batch;
-       int ret;
-
-       if (argc < 3) {
-               printf("Usage: %s {json} <file>\n", argv[0]);
-               exit(EXIT_FAILURE);
-       }
-
-       if (strcmp(argv[1], "json") == 0) {
-               format = NFTNL_PARSE_JSON;
-               outformat = NFTNL_OUTPUT_JSON;
-       } else {
-               printf("Unknown format: only json is supported\n");
-               exit(EXIT_FAILURE);
-       }
-
-       t = table_parse_file(argv[2], format);
-       if (t == NULL)
-               exit(EXIT_FAILURE);
-
-       nftnl_table_fprintf(stdout, t, outformat, 0);
-       fprintf(stdout, "\n");
-
-       seq = time(NULL);
-
-       batch = mnl_nlmsg_batch_start(buf, sizeof(buf));
-
-       nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++);
-       mnl_nlmsg_batch_next(batch);
-
-       family = nftnl_table_get_u32(t, NFTNL_TABLE_FAMILY);
-
-       table_seq = seq;
-       nlh = nftnl_table_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch),
-                                       NFT_MSG_NEWTABLE, family,
-                                       NLM_F_CREATE|NLM_F_ACK, seq++);
-       nftnl_table_nlmsg_build_payload(nlh, t);
-       nftnl_table_free(t);
-       mnl_nlmsg_batch_next(batch);
-
-       nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++);
-       mnl_nlmsg_batch_next(batch);
-
-       nl = mnl_socket_open(NETLINK_NETFILTER);
-       if (nl == NULL) {
-               perror("mnl_socket_open");
-               exit(EXIT_FAILURE);
-       }
-
-       if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
-               perror("mnl_socket_bind");
-               exit(EXIT_FAILURE);
-       }
-       portid = mnl_socket_get_portid(nl);
-
-       if (mnl_socket_sendto(nl, mnl_nlmsg_batch_head(batch),
-                             mnl_nlmsg_batch_size(batch)) < 0) {
-               perror("mnl_socket_send");
-               exit(EXIT_FAILURE);
-       }
-
-       mnl_nlmsg_batch_stop(batch);
-
-       ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-       while (ret > 0) {
-               ret = mnl_cb_run(buf, ret, table_seq, portid, NULL, NULL);
-               if (ret <= 0)
-                       break;
-               ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-       }
-       if (ret == -1) {
-               perror("error");
-               exit(EXIT_FAILURE);
-       }
-
-       mnl_socket_close(nl);
-
-       return EXIT_SUCCESS;
-}
index fd4cb408a44a5725c8107c67b797c9bc8ca22f7d..01667f57a7b17bde80b97e6ddff664d6d3427705 100644 (file)
@@ -10,7 +10,6 @@ noinst_HEADERS = internal.h   \
                 set.h          \
                 common.h       \
                 expr.h         \
-                json.h         \
                 set_elem.h     \
                 udata.h        \
                 utils.h
index 425bbf5f8dd32b5e6fb53de17dd977dede1065cc..d05a81ad542c14bbace90e983be12f3f095ee768 100644 (file)
@@ -18,15 +18,4 @@ enum nftnl_parse_input {
        NFTNL_PARSE_FILE,
 };
 
-#include <stdio.h>
-
-int nftnl_cmd_header_snprintf(char *buf, size_t bufsize, uint32_t cmd,
-                          uint32_t format, uint32_t flags);
-int nftnl_cmd_header_fprintf(FILE *fp, uint32_t cmd, uint32_t format,
-                         uint32_t flags);
-int nftnl_cmd_footer_snprintf(char *buf, size_t bufsize, uint32_t cmd,
-                          uint32_t format, uint32_t flags);
-int nftnl_cmd_footer_fprintf(FILE *fp, uint32_t cmd, uint32_t format,
-                         uint32_t flags);
-
 #endif
index e63939039c38a508d0cd3b3c96df14ee4c0c0d31..00548b35584169963d10934f66a89693040d3392 100644 (file)
@@ -19,8 +19,6 @@ struct expr_ops {
        int     (*parse)(struct nftnl_expr *e, struct nlattr *attr);
        void    (*build)(struct nlmsghdr *nlh, const struct nftnl_expr *e);
        int     (*snprintf)(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_expr *e);
-       int     (*json_parse)(struct nftnl_expr *e, json_t *data,
-                             struct nftnl_parse_err *err);
 };
 
 struct expr_ops *nftnl_expr_ops_lookup(const char *name);
index 7e97c4a8a2e4ac6d1c8bbf264291fd4bdf90143a..b762a4a542611d32ceea687a888ebf9c413645af 100644 (file)
@@ -6,7 +6,6 @@
 #include "linux_list.h"
 #include "utils.h"
 #include "common.h"
-#include "json.h"
 #include "linux_list.h"
 #include "set.h"
 #include "set_elem.h"
diff --git a/include/json.h b/include/json.h
deleted file mode 100644 (file)
index bd70cec..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-#ifndef LIBNFTNL_JSON_INTERNAL_H
-#define LIBNFTNL_JSON_INTERNAL_H
-
-#ifdef JSON_PARSING
-#include <jansson.h>
-#include <stdbool.h>
-#include "common.h"
-
-struct nftnl_table;
-struct nftnl_chain;
-struct nftnl_rule;
-struct nftnl_set;
-struct nftnl_set_elem;
-struct nftnl_set_list;
-union nftnl_data_reg;
-
-int nftnl_jansson_parse_val(json_t *root, const char *node_name, int type,
-                         void *out, struct nftnl_parse_err *err);
-const char *nftnl_jansson_parse_str(json_t *root, const char *node_name,
-                                 struct nftnl_parse_err *err);
-bool nftnl_jansson_node_exist(json_t *root, const char *node_name);
-json_t *nftnl_jansson_create_root(const void *json, json_error_t *error,
-                               struct nftnl_parse_err *err, enum nftnl_parse_input input);
-json_t *nftnl_jansson_get_node(json_t *root, const char *node_name,
-                            struct nftnl_parse_err *err);
-void nftnl_jansson_free_root(json_t *root);
-int nftnl_jansson_parse_family(json_t *root, void *out, struct nftnl_parse_err *err);
-int nftnl_jansson_str2num(json_t *root, const char *node_name, int base, void *out,
-                       enum nftnl_type type, struct nftnl_parse_err *err);
-int nftnl_jansson_parse_reg(json_t *root, const char *node_name, int type,
-                         void *out, struct nftnl_parse_err *err);
-struct nftnl_expr *nftnl_jansson_expr_parse(json_t *root,
-                                            struct nftnl_parse_err *err,
-                                            struct nftnl_set_list *set_list);
-int nftnl_jansson_data_reg_parse(json_t *root, const char *node_name,
-                              union nftnl_data_reg *data_reg,
-                              struct nftnl_parse_err *err);
-int nftnl_jansson_set_elem_parse(struct nftnl_set_elem *e, json_t *root,
-                              struct nftnl_parse_err *err);
-int nftnl_jansson_parse_table(struct nftnl_table *t, json_t *tree,
-                           struct nftnl_parse_err *err);
-int nftnl_jansson_parse_chain(struct nftnl_chain *c, json_t *tree,
-                           struct nftnl_parse_err *err);
-int nftnl_jansson_parse_rule(struct nftnl_rule *r, json_t *tree,
-                          struct nftnl_parse_err *err,
-                          struct nftnl_set_list *set_list);
-int nftnl_jansson_parse_set(struct nftnl_set *s, json_t *tree,
-                         struct nftnl_parse_err *err);
-int nftnl_jansson_parse_elem(struct nftnl_set *s, json_t *tree,
-                          struct nftnl_parse_err *err);
-
-int nftnl_data_reg_json_parse(union nftnl_data_reg *reg, json_t *data,
-                           struct nftnl_parse_err *err);
-#else
-#define json_t void
-#endif
-
-#endif /* LIBNFTNL_JSON_INTERNAL_H */
index 435d8a07e3156c542b90263b3061910d7e2b2c27..35b5c40d6fb0212d13e2a1b26a5d35e3b8b956aa 100644 (file)
@@ -93,8 +93,6 @@ struct obj_ops {
        int     (*parse)(struct nftnl_obj *e, struct nlattr *attr);
        void    (*build)(struct nlmsghdr *nlh, const struct nftnl_obj *e);
        int     (*snprintf)(char *buf, size_t len, uint32_t type, uint32_t flags, const struct nftnl_obj *e);
-       int     (*json_parse)(struct nftnl_obj *e, json_t *data,
-                             struct nftnl_parse_err *err);
 };
 
 extern struct obj_ops obj_ops_counter;
index 90704e66b88bf5a785e9adf0f0f96948cdab91bb..2d5873f017b3115f98cfda82ce097da028feab77 100644 (file)
@@ -1,13 +1,12 @@
 include $(top_srcdir)/Make_global.am
 lib_LTLIBRARIES = libnftnl.la
 
-libnftnl_la_LIBADD = ${LIBMNL_LIBS} ${LIBJSON_LIBS}
+libnftnl_la_LIBADD = ${LIBMNL_LIBS}
 libnftnl_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libnftnl.map      \
                      -version-info $(LIBVERSION)
 
 libnftnl_la_SOURCES = utils.c          \
                      batch.c           \
-                     buffer.c          \
                      flowtable.c       \
                      common.c          \
                      gen.c             \
@@ -19,7 +18,6 @@ libnftnl_la_SOURCES = utils.c         \
                      set.c             \
                      set_elem.c        \
                      ruleset.c         \
-                     jansson.c         \
                      udata.c           \
                      expr.c            \
                      expr_ops.c        \
diff --git a/src/buffer.c b/src/buffer.c
deleted file mode 100644 (file)
index 9ec86af..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * (C) 2012-2014 by Pablo Neira Ayuso <pablo@netfilter.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#include <stdio.h>
-#include <stdint.h>
-#include <stdarg.h>
-#include <inttypes.h>
-#include <string.h>
-#include <buffer.h>
-#include <libnftnl/common.h>
-#include <libnftnl/expr.h>
-#include "internal.h"
-
-int nftnl_buf_update(struct nftnl_buf *b, int ret)
-{
-       if (ret < 0) {
-               b->fail = true;
-       } else {
-               b->off += ret;
-               if (ret > b->len)
-                       ret = b->len;
-               b->size += ret;
-               b->len -= ret;
-       }
-
-       return ret;
-}
-
-int nftnl_buf_done(struct nftnl_buf *b)
-{
-       if (b->fail)
-               return -1;
-
-       /* Remove trailing comma in json */
-       if (b->size > 0 && b->buf[b->size - 1] == ',') {
-               b->off--;
-               b->size--;
-               b->len++;
-       }
-
-       return b->off;
-}
-
-static int nftnl_buf_put(struct nftnl_buf *b, const char *fmt, ...)
-{
-       int ret;
-       va_list ap;
-
-       va_start(ap, fmt);
-       ret = vsnprintf(b->buf + b->off, b->len, fmt, ap);
-       ret = nftnl_buf_update(b, ret);
-       va_end(ap);
-
-       return ret;
-}
-
-int nftnl_buf_open(struct nftnl_buf *b, int type, const char *tag)
-{
-       switch (type) {
-       case NFTNL_OUTPUT_JSON:
-               return nftnl_buf_put(b, "{\"%s\":{", tag);
-       case NFTNL_OUTPUT_XML:
-       default:
-               return 0;
-       }
-}
-
-int nftnl_buf_close(struct nftnl_buf *b, int type, const char *tag)
-{
-       switch (type) {
-       case NFTNL_OUTPUT_JSON:
-               /* Remove trailing comma in json */
-               if (b->size > 0 && b->buf[b->size - 1] == ',') {
-                       b->off--;
-                       b->size--;
-                       b->len++;
-               }
-
-               return nftnl_buf_put(b, "}}");
-       case NFTNL_OUTPUT_XML:
-       default:
-               return 0;
-       }
-}
-
-int nftnl_buf_open_array(struct nftnl_buf *b, int type, const char *tag)
-{
-       switch (type) {
-       case NFTNL_OUTPUT_JSON:
-               return nftnl_buf_put(b, "{\"%s\":[", tag);
-       case NFTNL_OUTPUT_XML:
-       default:
-               return 0;
-       }
-}
-
-int nftnl_buf_close_array(struct nftnl_buf *b, int type, const char *tag)
-{
-       switch (type) {
-       case NFTNL_OUTPUT_JSON:
-               return nftnl_buf_put(b, "]}");
-       case NFTNL_OUTPUT_XML:
-       default:
-               return 0;
-       }
-}
-
-int nftnl_buf_u32(struct nftnl_buf *b, int type, uint32_t value, const char *tag)
-{
-       switch (type) {
-       case NFTNL_OUTPUT_JSON:
-               return nftnl_buf_put(b, "\"%s\":%u,", tag, value);
-       case NFTNL_OUTPUT_XML:
-       default:
-               return 0;
-       }
-}
-
-int nftnl_buf_s32(struct nftnl_buf *b, int type, uint32_t value, const char *tag)
-{
-       switch (type) {
-       case NFTNL_OUTPUT_JSON:
-               return nftnl_buf_put(b, "\"%s\":%d,", tag, value);
-       case NFTNL_OUTPUT_XML:
-       default:
-               return 0;
-       }
-}
-
-int nftnl_buf_u64(struct nftnl_buf *b, int type, uint64_t value, const char *tag)
-{
-       switch (type) {
-       case NFTNL_OUTPUT_JSON:
-               return nftnl_buf_put(b, "\"%s\":%"PRIu64",", tag, value);
-       case NFTNL_OUTPUT_XML:
-       default:
-               return 0;
-       }
-}
-
-int nftnl_buf_str(struct nftnl_buf *b, int type, const char *str, const char *tag)
-{
-       switch (type) {
-       case NFTNL_OUTPUT_JSON:
-               return nftnl_buf_put(b, "\"%s\":\"%s\",", tag, str);
-       case NFTNL_OUTPUT_XML:
-       default:
-               return 0;
-       }
-}
-
-int nftnl_buf_reg(struct nftnl_buf *b, int type, union nftnl_data_reg *reg,
-               int reg_type, const char *tag)
-{
-       int ret;
-
-       switch (type) {
-       case NFTNL_OUTPUT_XML:
-               return 0;
-       case NFTNL_OUTPUT_JSON:
-               nftnl_buf_put(b, "\"%s\":{", tag);
-               ret = nftnl_data_reg_snprintf(b->buf + b->off, b->len, reg,
-                                           NFTNL_OUTPUT_JSON, 0, reg_type);
-               nftnl_buf_update(b, ret);
-               return nftnl_buf_put(b, "},");
-       }
-       return 0;
-}
-
-int nftnl_buf_expr_open(struct nftnl_buf *b, int type)
-{
-       switch (type) {
-       case NFTNL_OUTPUT_XML:
-               return 0;
-       case NFTNL_OUTPUT_JSON:
-               return nftnl_buf_put(b, "\"expr\":[");
-       }
-       return 0;
-}
-
-int nftnl_buf_expr_close(struct nftnl_buf *b, int type)
-{
-       switch (type) {
-       case NFTNL_OUTPUT_XML:
-               return 0;
-       case NFTNL_OUTPUT_JSON:
-               nftnl_buf_done(b);
-               return nftnl_buf_put(b, "]");
-       }
-       return 0;
-}
-
-int nftnl_buf_expr(struct nftnl_buf *b, int type, uint32_t flags,
-                  struct nftnl_expr *expr)
-{
-       int ret;
-
-       switch (type) {
-       case NFTNL_OUTPUT_XML:
-               return 0;
-       case NFTNL_OUTPUT_JSON:
-               nftnl_buf_put(b, "{");
-               nftnl_buf_str(b, type, expr->ops->name, TYPE);
-               ret = nftnl_expr_snprintf(b->buf + b->off, b->len, expr, type,
-                                         flags);
-               if (ret > 0)
-                       nftnl_buf_update(b, ret);
-               else
-                       nftnl_buf_done(b);
-
-               return nftnl_buf_put(b, "},");
-       }
-       return 0;
-}
index eff5186808739c179026296227d1f1542d60130c..06252b66a0183fe216007b097f5929a3ab940192 100644 (file)
@@ -603,188 +603,6 @@ static inline int nftnl_str2hooknum(int family, const char *hook)
        return -1;
 }
 
-#ifdef JSON_PARSING
-int nftnl_jansson_parse_chain(struct nftnl_chain *c, json_t *tree,
-                           struct nftnl_parse_err *err)
-{
-       json_t *root;
-       uint64_t handle, bytes, packets;
-       int policy_num;
-       int32_t family, prio, hooknum, use;
-       const char *name, *table, *type, *hooknum_str, *policy, *dev;
-
-       root = nftnl_jansson_get_node(tree, "chain", err);
-       if (root == NULL)
-               return -1;
-
-       name = nftnl_jansson_parse_str(root, "name", err);
-       if (name != NULL)
-               nftnl_chain_set_str(c, NFTNL_CHAIN_NAME, name);
-
-       if (nftnl_jansson_parse_val(root, "handle", NFTNL_TYPE_U64, &handle,
-                                 err) == 0)
-               nftnl_chain_set_u64(c,NFTNL_CHAIN_HANDLE, handle);
-
-       if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &bytes,
-                                 err) == 0)
-               nftnl_chain_set_u64(c, NFTNL_CHAIN_BYTES, bytes);
-
-       if (nftnl_jansson_parse_val(root, "packets", NFTNL_TYPE_U64, &packets,
-                                 err) == 0)
-               nftnl_chain_set_u64(c, NFTNL_CHAIN_PACKETS, packets);
-
-       if (nftnl_jansson_parse_family(root, &family, err) == 0)
-               nftnl_chain_set_u32(c, NFTNL_CHAIN_FAMILY, family);
-
-       table = nftnl_jansson_parse_str(root, "table", err);
-
-       if (table != NULL)
-               nftnl_chain_set_str(c, NFTNL_CHAIN_TABLE, table);
-
-       if (nftnl_jansson_parse_val(root, "use", NFTNL_TYPE_U32, &use, err) == 0)
-               nftnl_chain_set_u32(c, NFTNL_CHAIN_USE, use);
-
-       if (nftnl_jansson_node_exist(root, "hooknum")) {
-               type = nftnl_jansson_parse_str(root, "type", err);
-
-               if (type != NULL)
-                       nftnl_chain_set_str(c, NFTNL_CHAIN_TYPE, type);
-
-               if (nftnl_jansson_parse_val(root, "prio", NFTNL_TYPE_S32,
-                                         &prio, err) == 0)
-                       nftnl_chain_set_s32(c, NFTNL_CHAIN_PRIO, prio);
-
-               hooknum_str = nftnl_jansson_parse_str(root, "hooknum", err);
-               if (hooknum_str != NULL) {
-                       hooknum = nftnl_str2hooknum(c->family, hooknum_str);
-                       if (hooknum == -1)
-                               return -1;
-                       nftnl_chain_set_u32(c, NFTNL_CHAIN_HOOKNUM,
-                                              hooknum);
-               }
-
-               policy = nftnl_jansson_parse_str(root, "policy", err);
-               if (policy != NULL) {
-                       if (nftnl_str2verdict(policy, &policy_num) != 0) {
-                               errno = EINVAL;
-                               err->node_name = "policy";
-                               err->error = NFTNL_PARSE_EBADTYPE;
-                               return -1;
-                       }
-                       nftnl_chain_set_u32(c, NFTNL_CHAIN_POLICY,
-                                              policy_num);
-               }
-
-               dev = nftnl_jansson_parse_str(root, "device", err);
-               if (dev != NULL)
-                       nftnl_chain_set_str(c, NFTNL_CHAIN_DEV, dev);
-       }
-
-       return 0;
-}
-#endif
-
-static int nftnl_chain_json_parse(struct nftnl_chain *c, const void *json,
-                               struct nftnl_parse_err *err,
-                               enum nftnl_parse_input input)
-{
-#ifdef JSON_PARSING
-       json_t *tree;
-       json_error_t error;
-       int ret;
-
-       tree = nftnl_jansson_create_root(json, &error, err, input);
-       if (tree == NULL)
-               return -1;
-
-       ret = nftnl_jansson_parse_chain(c, tree, err);
-
-       nftnl_jansson_free_root(tree);
-
-       return ret;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_chain_do_parse(struct nftnl_chain *c, enum nftnl_parse_type type,
-                             const void *data, struct nftnl_parse_err *err,
-                             enum nftnl_parse_input input)
-{
-       int ret;
-       struct nftnl_parse_err perr = {};
-
-       switch (type) {
-       case NFTNL_PARSE_JSON:
-               ret = nftnl_chain_json_parse(c, data, &perr, input);
-               break;
-       case NFTNL_PARSE_XML:
-       default:
-               ret = -1;
-               errno = EOPNOTSUPP;
-               break;
-       }
-
-       if (err != NULL)
-               *err = perr;
-
-       return ret;
-}
-
-EXPORT_SYMBOL(nftnl_chain_parse);
-int nftnl_chain_parse(struct nftnl_chain *c, enum nftnl_parse_type type,
-                   const char *data, struct nftnl_parse_err *err)
-{
-       return nftnl_chain_do_parse(c, type, data, err, NFTNL_PARSE_BUFFER);
-}
-
-EXPORT_SYMBOL(nftnl_chain_parse_file);
-int nftnl_chain_parse_file(struct nftnl_chain *c, enum nftnl_parse_type type,
-                        FILE *fp, struct nftnl_parse_err *err)
-{
-       return nftnl_chain_do_parse(c, type, fp, err, NFTNL_PARSE_FILE);
-}
-
-static int nftnl_chain_export(char *buf, size_t size,
-                             const struct nftnl_chain *c, int type)
-{
-       NFTNL_BUF_INIT(b, buf, size);
-
-       nftnl_buf_open(&b, type, CHAIN);
-       if (c->flags & (1 << NFTNL_CHAIN_NAME))
-               nftnl_buf_str(&b, type, c->name, NAME);
-       if (c->flags & (1 << NFTNL_CHAIN_HANDLE))
-               nftnl_buf_u64(&b, type, c->handle, HANDLE);
-       if (c->flags & (1 << NFTNL_CHAIN_BYTES))
-               nftnl_buf_u64(&b, type, c->bytes, BYTES);
-       if (c->flags & (1 << NFTNL_CHAIN_PACKETS))
-               nftnl_buf_u64(&b, type, c->packets, PACKETS);
-       if (c->flags & (1 << NFTNL_CHAIN_TABLE))
-               nftnl_buf_str(&b, type, c->table, TABLE);
-       if (c->flags & (1 << NFTNL_CHAIN_FAMILY))
-               nftnl_buf_str(&b, type, nftnl_family2str(c->family), FAMILY);
-       if (c->flags & (1 << NFTNL_CHAIN_USE))
-               nftnl_buf_u32(&b, type, c->use, USE);
-       if (c->flags & (1 << NFTNL_CHAIN_HOOKNUM)) {
-               if (c->flags & (1 << NFTNL_CHAIN_TYPE))
-                       nftnl_buf_str(&b, type, c->type, TYPE);
-               if (c->flags & (1 << NFTNL_CHAIN_HOOKNUM))
-                       nftnl_buf_str(&b, type, nftnl_hooknum2str(c->family,
-                                        c->hooknum), HOOKNUM);
-               if (c->flags & (1 << NFTNL_CHAIN_PRIO))
-                       nftnl_buf_s32(&b, type, c->prio, PRIO);
-               if (c->flags & (1 << NFTNL_CHAIN_POLICY))
-                       nftnl_buf_str(&b, type, nftnl_verdict2str(c->policy), POLICY);
-               if (c->flags & (1 << NFTNL_CHAIN_DEV))
-                       nftnl_buf_str(&b, type, c->dev, DEVICE);
-       }
-
-       nftnl_buf_close(&b, type, CHAIN);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_chain_snprintf_default(char *buf, size_t size,
                                        const struct nftnl_chain *c)
 {
@@ -827,26 +645,17 @@ static int nftnl_chain_cmd_snprintf(char *buf, size_t size,
 {
        int ret, remain = size, offset = 0;
 
-       ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                ret = nftnl_chain_snprintf_default(buf + offset, remain, c);
+               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                break;
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               ret = nftnl_chain_export(buf + offset, remain, c, type);
-               break;
        default:
                return -1;
        }
 
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = nftnl_cmd_footer_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        return offset;
 }
 
index 561c954391147e517ee0044466c7ab4234d7fe32..feb13b2aa836c2fc1d5e33595b8d937428bba18b 100644 (file)
@@ -91,80 +91,6 @@ int nftnl_parse_perror(const char *msg, struct nftnl_parse_err *err)
        }
 }
 
-int nftnl_cmd_header_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type,
-                           uint32_t flags)
-{
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (cmd == NFTNL_CMD_UNSPEC)
-               return 0;
-
-       switch (type) {
-       case NFTNL_OUTPUT_XML:
-       case NFTNL_OUTPUT_JSON:
-               nftnl_buf_open_array(&b, type, nftnl_cmd2tag(cmd));
-               break;
-       default:
-               switch (cmd) {
-               case NFTNL_CMD_ADD:
-                       return snprintf(buf, size, "%9s", "[ADD] ");
-               case NFTNL_CMD_DELETE:
-                       return snprintf(buf, size, "%9s", "[DELETE] ");
-               default:
-                       return snprintf(buf, size, "%9s", "[unknown] ");
-               }
-               break;
-       }
-       return nftnl_buf_done(&b);
-}
-
-static int nftnl_cmd_header_fprintf_cb(char *buf, size_t size, const void *obj,
-                                      uint32_t cmd, uint32_t type,
-                                      uint32_t flags)
-{
-       return nftnl_cmd_header_snprintf(buf, size, cmd, type, flags);
-}
-
-int nftnl_cmd_header_fprintf(FILE *fp, uint32_t cmd, uint32_t type,
-                          uint32_t flags)
-{
-       return nftnl_fprintf(fp, NULL, cmd, type, flags,
-                          nftnl_cmd_header_fprintf_cb);
-}
-
-int nftnl_cmd_footer_snprintf(char *buf, size_t size, uint32_t cmd, uint32_t type,
-                           uint32_t flags)
-{
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (cmd == NFTNL_CMD_UNSPEC)
-               return 0;
-
-       switch (type) {
-       case NFTNL_OUTPUT_XML:
-       case NFTNL_OUTPUT_JSON:
-               nftnl_buf_close_array(&b, type, nftnl_cmd2tag(cmd));
-               break;
-       default:
-               return 0;
-       }
-       return nftnl_buf_done(&b);
-}
-
-static int nftnl_cmd_footer_fprintf_cb(char *buf, size_t size, const void *obj,
-                                      uint32_t cmd, uint32_t type,
-                                      uint32_t flags)
-{
-       return nftnl_cmd_footer_snprintf(buf, size, cmd, type, flags);
-}
-
-int nftnl_cmd_footer_fprintf(FILE *fp, uint32_t cmd, uint32_t type,
-                          uint32_t flags)
-{
-       return nftnl_fprintf(fp, NULL, cmd, type, flags,
-                          nftnl_cmd_footer_fprintf_cb);
-}
-
 EXPORT_SYMBOL(nftnl_batch_begin);
 struct nlmsghdr *nftnl_batch_begin(char *buf, uint32_t seq)
 {
index a89734b5f2d4e9f3eeef5a8b0c420a1fa06cfd2b..ebfbcd0772370a80aa0df0e7e7a74cc7794b4c8e 100644 (file)
@@ -174,61 +174,6 @@ nftnl_expr_bitwise_parse(struct nftnl_expr *e, struct nlattr *attr)
        return ret;
 }
 
-static int
-nftnl_expr_bitwise_json_parse(struct nftnl_expr *e, json_t *root,
-                                struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e);
-       uint32_t reg, len;
-
-       if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_BITWISE_SREG, reg);
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_BITWISE_DREG, reg);
-
-       if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &len, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_BITWISE_LEN, len);
-
-       if (nftnl_jansson_data_reg_parse(root, "mask", &bitwise->mask,
-                                      err) == DATA_VALUE)
-               e->flags |= (1 << NFTNL_EXPR_BITWISE_MASK);
-
-       if (nftnl_jansson_data_reg_parse(root, "xor", &bitwise->xor,
-                                      err) == DATA_VALUE)
-               e->flags |= (1 << NFTNL_EXPR_BITWISE_XOR);
-
-       if (bitwise->mask.len != bitwise->xor.len)
-               return -1;
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_bitwise_export(char *buf, size_t size,
-                                    const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_bitwise *bitwise = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_BITWISE_SREG))
-               nftnl_buf_u32(&b, type, bitwise->sreg, SREG);
-       if (e->flags & (1 << NFTNL_EXPR_BITWISE_DREG))
-               nftnl_buf_u32(&b, type, bitwise->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_BITWISE_LEN))
-               nftnl_buf_u32(&b, type, bitwise->len, LEN);
-       if (e->flags & (1 << NFTNL_EXPR_BITWISE_MASK))
-               nftnl_buf_reg(&b, type, &bitwise->mask, DATA_VALUE, MASK);
-       if (e->flags & (1 << NFTNL_EXPR_BITWISE_XOR))
-               nftnl_buf_reg(&b, type, &bitwise->xor, DATA_VALUE, XOR);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_bitwise_snprintf_default(char *buf, size_t size,
                                               const struct nftnl_expr *e)
 {
@@ -260,9 +205,6 @@ nftnl_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type,
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_expr_bitwise_snprintf_default(buf, size, e);
-       case NFTNL_OUTPUT_XML:
-       case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_bitwise_export(buf, size, e, type);
        default:
                break;
        }
@@ -300,5 +242,4 @@ struct expr_ops expr_ops_bitwise = {
        .parse          = nftnl_expr_bitwise_parse,
        .build          = nftnl_expr_bitwise_build,
        .snprintf       = nftnl_expr_bitwise_snprintf,
-       .json_parse     = nftnl_expr_bitwise_json_parse,
 };
index 47c04cfea69fb9341631c5cd2deb36155ad54ed1..4cddd4a052c2ab862d8415d16e66dd01d86d0059 100644 (file)
@@ -197,63 +197,6 @@ static inline int nftnl_str2ntoh(const char *op)
        }
 }
 
-static int
-nftnl_expr_byteorder_json_parse(struct nftnl_expr *e, json_t *root,
-                                  struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *op;
-       uint32_t sreg, dreg, len, size;
-       int ntoh;
-
-       if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &sreg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_SREG, sreg);
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &dreg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_DREG, dreg);
-
-       op = nftnl_jansson_parse_str(root, "op", err);
-       if (op != NULL) {
-               ntoh = nftnl_str2ntoh(op);
-               if (ntoh < 0)
-                       return -1;
-
-               nftnl_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_OP, ntoh);
-       }
-
-       if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &len, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_LEN, len);
-
-       if (nftnl_jansson_parse_val(root, "size", NFTNL_TYPE_U32, &size, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_BYTEORDER_SIZE, size);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_byteorder_export(char *buf, size_t size,
-                                      const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_byteorder *byteorder = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_SREG))
-               nftnl_buf_u32(&b, type, byteorder->sreg, SREG);
-       if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_DREG))
-               nftnl_buf_u32(&b, type, byteorder->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_OP))
-               nftnl_buf_str(&b, type, bo2str(byteorder->op), OP);
-       if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_LEN))
-               nftnl_buf_u32(&b, type, byteorder->len, LEN);
-       if (e->flags & (1 << NFTNL_EXPR_BYTEORDER_SIZE))
-               nftnl_buf_u32(&b, type, byteorder->size, SIZE);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_byteorder_snprintf_default(char *buf, size_t size,
                                                 const struct nftnl_expr *e)
 {
@@ -277,7 +220,6 @@ nftnl_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type,
                return nftnl_expr_byteorder_snprintf_default(buf, size, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_byteorder_export(buf, size, e, type);
        default:
                break;
        }
@@ -315,5 +257,4 @@ struct expr_ops expr_ops_byteorder = {
        .parse          = nftnl_expr_byteorder_parse,
        .build          = nftnl_expr_byteorder_build,
        .snprintf       = nftnl_expr_byteorder_snprintf,
-       .json_parse     = nftnl_expr_byteorder_json_parse,
 };
index b26d0eb08bb20f6274c0b7da9e31a8057da70522..86708a48410f9bf53b76a3daa3fe3cee36a31c52 100644 (file)
@@ -176,55 +176,6 @@ static inline int nftnl_str2cmp(const char *op)
        }
 }
 
-static int nftnl_expr_cmp_json_parse(struct nftnl_expr *e, json_t *root,
-                                       struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       struct nftnl_expr_cmp *cmp = nftnl_expr_data(e);
-       const char *op;
-       uint32_t uval32;
-       int base;
-
-       if (nftnl_jansson_parse_val(root, "sreg", NFTNL_TYPE_U32, &uval32,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_CMP_SREG, uval32);
-
-       op = nftnl_jansson_parse_str(root, "op", err);
-       if (op != NULL) {
-               base = nftnl_str2cmp(op);
-               if (base < 0)
-                       return -1;
-
-               nftnl_expr_set_u32(e, NFTNL_EXPR_CMP_OP, base);
-       }
-
-       if (nftnl_jansson_data_reg_parse(root, "data",
-                                      &cmp->data, err) == DATA_VALUE)
-               e->flags |= (1 << NFTNL_EXPR_CMP_DATA);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_cmp_export(char *buf, size_t size,
-                                const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_cmp *cmp = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_CMP_SREG))
-               nftnl_buf_u32(&b, type, cmp->sreg, SREG);
-       if (e->flags & (1 << NFTNL_EXPR_CMP_OP))
-               nftnl_buf_str(&b, type, cmp2str(cmp->op), OP);
-       if (e->flags & (1 << NFTNL_EXPR_CMP_DATA))
-               nftnl_buf_reg(&b, type, &cmp->data, DATA_VALUE, DATA);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_cmp_snprintf_default(char *buf, size_t size,
                                           const struct nftnl_expr *e)
 {
@@ -251,7 +202,6 @@ nftnl_expr_cmp_snprintf(char *buf, size_t size, uint32_t type,
                return nftnl_expr_cmp_snprintf_default(buf, size, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_cmp_export(buf, size, e, type);
        default:
                break;
        }
@@ -285,5 +235,4 @@ struct expr_ops expr_ops_cmp = {
        .parse          = nftnl_expr_cmp_parse,
        .build          = nftnl_expr_cmp_build,
        .snprintf       = nftnl_expr_cmp_snprintf,
-       .json_parse     = nftnl_expr_cmp_json_parse,
 };
index 60965b5d83295863c71e70b7339f5de5da912858..61fd299e6e31a902a9da52ccdf21d4f58a285d96 100644 (file)
@@ -117,42 +117,6 @@ nftnl_expr_connlimit_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_expr_connlimit_json_parse(struct nftnl_expr *e, json_t *root,
-                                struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t uval32;
-
-       if (nftnl_jansson_parse_val(root, "count", NFTNL_TYPE_U32, &uval32,
-                                   err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_CONNLIMIT_COUNT, uval32);
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &uval32,
-                                   err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_CONNLIMIT_FLAGS, uval32);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_connlimit_export(char *buf, size_t size,
-                                    const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_connlimit *connlimit = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_CONNLIMIT_COUNT))
-               nftnl_buf_u32(&b, type, connlimit->count, COUNT);
-       if (e->flags & (1 << NFTNL_EXPR_CONNLIMIT_FLAGS))
-               nftnl_buf_u32(&b, type, connlimit->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_connlimit_snprintf_default(char *buf, size_t len,
                                               const struct nftnl_expr *e)
 {
@@ -171,7 +135,6 @@ static int nftnl_expr_connlimit_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_connlimit_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_connlimit_export(buf, len, e, type);
        default:
                break;
        }
@@ -203,5 +166,4 @@ struct expr_ops expr_ops_connlimit = {
        .parse          = nftnl_expr_connlimit_parse,
        .build          = nftnl_expr_connlimit_build,
        .snprintf       = nftnl_expr_connlimit_snprintf,
-       .json_parse     = nftnl_expr_connlimit_json_parse,
 };
index 21901e892471ee808e15a2a82f38334666d06c42..2036cb0c1502c3d142888d07801cb60043afe76c 100644 (file)
@@ -115,42 +115,6 @@ nftnl_expr_counter_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_expr_counter_json_parse(struct nftnl_expr *e, json_t *root,
-                                struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint64_t uval64;
-
-       if (nftnl_jansson_parse_val(root, "pkts", NFTNL_TYPE_U64, &uval64,
-                                 err) == 0)
-               nftnl_expr_set_u64(e, NFTNL_EXPR_CTR_PACKETS, uval64);
-
-       if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &uval64,
-                                 err) == 0)
-               nftnl_expr_set_u64(e, NFTNL_EXPR_CTR_BYTES, uval64);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_counter_export(char *buf, size_t size,
-                                    const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_counter *ctr = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_CTR_PACKETS))
-               nftnl_buf_u64(&b, type, ctr->pkts, PKTS);
-       if (e->flags & (1 << NFTNL_EXPR_CTR_BYTES))
-               nftnl_buf_u64(&b, type, ctr->bytes, BYTES);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_counter_snprintf_default(char *buf, size_t len,
                                               const struct nftnl_expr *e)
 {
@@ -169,7 +133,6 @@ static int nftnl_expr_counter_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_counter_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_counter_export(buf, len, e, type);
        default:
                break;
        }
@@ -201,5 +164,4 @@ struct expr_ops expr_ops_counter = {
        .parse          = nftnl_expr_counter_parse,
        .build          = nftnl_expr_counter_build,
        .snprintf       = nftnl_expr_counter_snprintf,
-       .json_parse     = nftnl_expr_counter_json_parse,
 };
index 39e9be6c5da28cbea85b210184c9bfba54614cbb..bb7fe8a4bac2e636a6423ec7e311b24a4585020c 100644 (file)
@@ -221,70 +221,6 @@ static inline int str2ctdir(const char *str, uint8_t *ctdir)
        return -1;
 }
 
-static int nftnl_expr_ct_json_parse(struct nftnl_expr *e, json_t *root,
-                                      struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *key_str, *dir_str;
-       uint32_t reg;
-       uint8_t dir;
-       int key;
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_CT_DREG, reg);
-
-       if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_CT_SREG, reg);
-
-       key_str = nftnl_jansson_parse_str(root, "key", err);
-       if (key_str != NULL) {
-               key = str2ctkey(key_str);
-               if (key < 0)
-                       return -1;
-
-               nftnl_expr_set_u32(e, NFTNL_EXPR_CT_KEY, key);
-       }
-
-       dir_str = nftnl_jansson_parse_str(root, "dir", err);
-       if (dir_str != NULL) {
-               if (str2ctdir(dir_str, &dir) != 0) {
-                       err->node_name = "dir";
-                       err->error = NFTNL_PARSE_EBADTYPE;
-                       goto err;
-               }
-               nftnl_expr_set_u8(e, NFTNL_EXPR_CT_DIR, dir);
-       }
-
-       return 0;
-err:
-       errno = EINVAL;
-       return -1;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-
-static int
-nftnl_expr_ct_export(char *buf, size_t size, const struct nftnl_expr *e,
-                    int type)
-{
-       struct nftnl_expr_ct *ct = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_CT_SREG))
-               nftnl_buf_u32(&b, type, ct->sreg, SREG);
-       if (e->flags & (1 << NFTNL_EXPR_CT_DREG))
-               nftnl_buf_u32(&b, type, ct->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_CT_KEY))
-               nftnl_buf_str(&b, type, ctkey2str(ct->key), KEY);
-       if (e->flags & (1 << NFTNL_EXPR_CT_DIR))
-               nftnl_buf_str(&b, type, ctdir2str(ct->dir), DIR);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_ct_snprintf_default(char *buf, size_t size,
                               const struct nftnl_expr *e)
@@ -322,7 +258,6 @@ nftnl_expr_ct_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_ct_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_ct_export(buf, len, e, type);
        default:
                break;
        }
@@ -358,5 +293,4 @@ struct expr_ops expr_ops_ct = {
        .parse          = nftnl_expr_ct_parse,
        .build          = nftnl_expr_ct_build,
        .snprintf       = nftnl_expr_ct_snprintf,
-       .json_parse     = nftnl_expr_ct_json_parse,
 };
index ad7f4cb28ebd7e70081eaba26b18e21e0c765a11..48a012bb6cbf9cf5953901cb3e9694a1c233b70d 100644 (file)
 #include <libnftnl/rule.h>
 #include "internal.h"
 
-#ifdef JSON_PARSING
-static int nftnl_data_reg_verdict_json_parse(union nftnl_data_reg *reg, json_t *data,
-                                          struct nftnl_parse_err *err)
-{
-       int verdict;
-       const char *verdict_str;
-       const char *chain;
-
-       verdict_str = nftnl_jansson_parse_str(data, "verdict", err);
-       if (verdict_str == NULL)
-               return DATA_NONE;
-
-       if (nftnl_str2verdict(verdict_str, &verdict) != 0) {
-               err->node_name = "verdict";
-               err->error = NFTNL_PARSE_EBADTYPE;
-               errno = EINVAL;
-               return -1;
-       }
-
-       reg->verdict = (uint32_t)verdict;
-
-       if (nftnl_jansson_node_exist(data, "chain")) {
-               chain = nftnl_jansson_parse_str(data, "chain", err);
-               if (chain == NULL)
-                       return DATA_NONE;
-
-               reg->chain = strdup(chain);
-       }
-
-       return DATA_VERDICT;
-}
-
-static int nftnl_data_reg_value_json_parse(union nftnl_data_reg *reg, json_t *data,
-                                        struct nftnl_parse_err *err)
-{
-       char node_name[32] = {};
-       int ret, remain = sizeof(node_name), offset = 0, i;
-
-       if (nftnl_jansson_parse_val(data, "len", NFTNL_TYPE_U32, &reg->len, err) < 0)
-                       return DATA_NONE;
-
-       for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) {
-               ret = snprintf(node_name, sizeof(node_name), "data%u", i);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-               if (nftnl_jansson_str2num(data, node_name, BASE_HEX,
-                                       &reg->val[i], NFTNL_TYPE_U32, err) != 0)
-                       return DATA_NONE;
-       }
-
-       return DATA_VALUE;
-}
-
-int nftnl_data_reg_json_parse(union nftnl_data_reg *reg, json_t *data,
-                           struct nftnl_parse_err *err)
-{
-
-       const char *type;
-
-       type = nftnl_jansson_parse_str(data, "type", err);
-       if (type == NULL)
-               return -1;
-
-       /* Select what type of parsing is needed */
-       if (strcmp(type, "value") == 0)
-               return nftnl_data_reg_value_json_parse(reg, data, err);
-       else if (strcmp(type, "verdict") == 0)
-               return nftnl_data_reg_verdict_json_parse(reg, data, err);
-
-       return DATA_NONE;
-}
-#endif
-
-static int
-nftnl_data_reg_value_snprintf_json(char *buf, size_t size,
-                                  const union nftnl_data_reg *reg,
-                                  uint32_t flags)
-{
-       int remain = size, offset = 0, ret, i, j;
-       uint32_t utemp;
-       uint8_t *tmp;
-
-       ret = snprintf(buf, remain, "\"reg\":{\"type\":\"value\",");
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = snprintf(buf + offset, remain, "\"len\":%u,", reg->len);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       for (i = 0; i < div_round_up(reg->len, sizeof(uint32_t)); i++) {
-               ret = snprintf(buf + offset, remain, "\"data%d\":\"0x", i);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-               utemp = htonl(reg->val[i]);
-               tmp = (uint8_t *)&utemp;
-
-               for (j = 0; j<sizeof(uint32_t); j++) {
-                       ret = snprintf(buf + offset, remain, "%.02x", tmp[j]);
-                       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-               }
-
-               ret = snprintf(buf + offset, remain, "\",");
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-       offset--;
-       ret = snprintf(buf + offset, remain, "}");
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       return offset;
-}
-
 static int
 nftnl_data_reg_value_snprintf_default(char *buf, size_t size,
                                      const union nftnl_data_reg *reg,
@@ -167,29 +57,6 @@ nftnl_data_reg_verdict_snprintf_def(char *buf, size_t size,
        return offset;
 }
 
-static int
-nftnl_data_reg_verdict_snprintf_json(char *buf, size_t size,
-                                    const union nftnl_data_reg *reg,
-                                    uint32_t flags)
-{
-       int remain = size, offset = 0, ret = 0;
-
-       ret = snprintf(buf, size, "\"reg\":{\"type\":\"verdict\","
-                      "\"verdict\":\"%s\"", nftnl_verdict2str(reg->verdict));
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       if (reg->chain != NULL) {
-               ret = snprintf(buf + offset, remain, ",\"chain\":\"%s\"",
-                              reg->chain);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-
-       ret = snprintf(buf + offset, remain, "}");
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       return offset;
-}
-
 int nftnl_data_reg_snprintf(char *buf, size_t size,
                            const union nftnl_data_reg *reg,
                            uint32_t output_format, uint32_t flags,
@@ -202,8 +69,6 @@ int nftnl_data_reg_snprintf(char *buf, size_t size,
                        return nftnl_data_reg_value_snprintf_default(buf, size,
                                                                   reg, flags);
                case NFTNL_OUTPUT_JSON:
-                       return nftnl_data_reg_value_snprintf_json(buf, size,
-                                                              reg, flags);
                case NFTNL_OUTPUT_XML:
                default:
                        break;
@@ -216,8 +81,6 @@ int nftnl_data_reg_snprintf(char *buf, size_t size,
                        return nftnl_data_reg_verdict_snprintf_def(buf, size,
                                                                 reg, flags);
                case NFTNL_OUTPUT_JSON:
-                       return nftnl_data_reg_verdict_snprintf_json(buf, size,
-                                                                 reg, flags);
                case NFTNL_OUTPUT_XML:
                default:
                        break;
index ed8e6208cfabaf0b82ae4c401b415cf1fffe763c..6fa65988c835f6359ab733a168227b3cd00392ab 100644 (file)
@@ -112,41 +112,6 @@ static int nftnl_expr_dup_parse(struct nftnl_expr *e, struct nlattr *attr)
        return ret;
 }
 
-static int nftnl_expr_dup_json_parse(struct nftnl_expr *e, json_t *root,
-                                    struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t sreg_addr, sreg_dev;
-       int ret;
-
-       ret = nftnl_jansson_parse_val(root, "sreg_addr", NFTNL_TYPE_U32, &sreg_addr, err);
-       if (ret >= 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_DUP_SREG_DEV, sreg_addr);
-       ret = nftnl_jansson_parse_val(root, "sreg_dev", NFTNL_TYPE_U32, &sreg_dev, err);
-       if (ret >= 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_DUP_SREG_DEV, sreg_dev);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_dup_export(char *buf, size_t size,
-                                const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_dup *dup = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_DUP_SREG_ADDR))
-               nftnl_buf_u32(&b, type, dup->sreg_addr, "sreg_addr");
-       if (e->flags & (1 << NFTNL_EXPR_DUP_SREG_DEV))
-               nftnl_buf_u32(&b, type, dup->sreg_addr, "sreg_dev");
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_dup_snprintf_default(char *buf, size_t len,
                                           const struct nftnl_expr *e,
                                           uint32_t flags)
@@ -175,7 +140,6 @@ static int nftnl_expr_dup_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_dup_snprintf_default(buf, len, e, flags);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_dup_export(buf, len, e, type);
        default:
                break;
        }
@@ -207,5 +171,4 @@ struct expr_ops expr_ops_dup = {
        .parse          = nftnl_expr_dup_parse,
        .build          = nftnl_expr_dup_build,
        .snprintf       = nftnl_expr_dup_snprintf,
-       .json_parse     = nftnl_expr_dup_json_parse,
 };
index 160d0e15c1514b28d2ba2a1c1c9bdca89eb8fd0e..3d24ef8da0f8fb61d8399252f6dc4e3f3417a3fb 100644 (file)
@@ -205,59 +205,6 @@ nftnl_expr_dynset_parse(struct nftnl_expr *e, struct nlattr *attr)
        return ret;
 }
 
-static int
-nftnl_expr_dynset_json_parse(struct nftnl_expr *e, json_t *root,
-                               struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *set_name;
-       uint32_t uval32;
-       uint64_t uval64;
-
-       set_name = nftnl_jansson_parse_str(root, "set", err);
-       if (set_name != NULL)
-               nftnl_expr_set_str(e, NFTNL_EXPR_DYNSET_SET_NAME, set_name);
-
-       if (nftnl_jansson_parse_reg(root, "sreg_key",
-                                 NFTNL_TYPE_U32, &uval32, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_DYNSET_SREG_KEY, uval32);
-
-       if (nftnl_jansson_parse_reg(root, "sreg_data",
-                                 NFTNL_TYPE_U32, &uval32, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_DYNSET_SREG_DATA, uval32);
-
-       if (nftnl_jansson_parse_val(root, "op", NFTNL_TYPE_U32, &uval32,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_DYNSET_OP, uval32);
-
-       if (nftnl_jansson_parse_val(root, "timeout", NFTNL_TYPE_U64, &uval64,
-                                 err) == 0)
-               nftnl_expr_set_u64(e, NFTNL_EXPR_DYNSET_TIMEOUT, uval64);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int
-nftnl_expr_dynset_export(char *buf, size_t size,
-                        const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_dynset *dynset = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_DYNSET_SET_NAME))
-               nftnl_buf_str(&b, type, dynset->set_name, SET_NAME);
-       if (e->flags & (1 << NFTNL_EXPR_DYNSET_SREG_KEY))
-               nftnl_buf_u32(&b, type, dynset->sreg_key, SREG_KEY);
-       if (e->flags & (1 << NFTNL_EXPR_DYNSET_SREG_DATA))
-               nftnl_buf_u32(&b, type, dynset->sreg_data, SREG_DATA);
-
-       return nftnl_buf_done(&b);
-}
-
 static const char *op2str_array[] = {
        [NFT_DYNSET_OP_ADD]             = "add",
        [NFT_DYNSET_OP_UPDATE]          = "update",
@@ -319,7 +266,6 @@ nftnl_expr_dynset_snprintf(char *buf, size_t size, uint32_t type,
                return nftnl_expr_dynset_snprintf_default(buf, size, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_dynset_export(buf, size, e, type);
        default:
                break;
        }
@@ -369,5 +315,4 @@ struct expr_ops expr_ops_dynset = {
        .parse          = nftnl_expr_dynset_parse,
        .build          = nftnl_expr_dynset_build,
        .snprintf       = nftnl_expr_dynset_snprintf,
-       .json_parse     = nftnl_expr_dynset_json_parse,
 };
index a3518353be09aebb65a460e25feaefbd98bbb197..ec6a855b3f8e1b7f3b095c80ded3e3f0a26c2fdb 100644 (file)
@@ -205,24 +205,6 @@ static const char *op2str(uint8_t op)
        }
 }
 
-static const char *type2str(uint32_t type)
-{
-       switch (type) {
-       case IPPROTO_HOPOPTS:
-               return "hopopts";
-       case IPPROTO_ROUTING:
-               return "routing";
-       case IPPROTO_FRAGMENT:
-               return "fragment";
-       case IPPROTO_DSTOPTS:
-               return "dstopts";
-       case IPPROTO_MH:
-               return "mh";
-       default:
-               return "unknown";
-       }
-}
-
 static inline int str2exthdr_op(const char* str)
 {
        if (!strcmp(str, "tcpopt"))
@@ -248,75 +230,6 @@ static inline int str2exthdr_type(const char *str)
        return -1;
 }
 
-static int
-nftnl_expr_exthdr_json_parse(struct nftnl_expr *e, json_t *root,
-                               struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *exthdr_type;
-       uint32_t uval32;
-       int type;
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &uval32,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_DREG, uval32);
-
-       if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &uval32,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_SREG, uval32);
-
-       exthdr_type = nftnl_jansson_parse_str(root, "exthdr_type", err);
-       if (exthdr_type != NULL) {
-               type = str2exthdr_type(exthdr_type);
-               if (type < 0)
-                       return -1;
-               nftnl_expr_set_u8(e, NFTNL_EXPR_EXTHDR_TYPE, type);
-       }
-
-       if (nftnl_jansson_parse_val(root, "offset", NFTNL_TYPE_U32, &uval32,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_OFFSET, uval32);
-
-       if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &uval32, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_LEN, uval32);
-
-       if (nftnl_jansson_parse_val(root, "op", NFTNL_TYPE_U32, &uval32, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_OP, uval32);
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &uval32, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_EXTHDR_FLAGS, uval32);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_exthdr_export(char *buf, size_t len,
-                                   const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_exthdr *exthdr = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, len);
-
-       if (e->flags & (1 << NFTNL_EXPR_EXTHDR_DREG))
-               nftnl_buf_u32(&b, type, exthdr->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_EXTHDR_SREG))
-               nftnl_buf_u32(&b, type, exthdr->dreg, SREG);
-       if (e->flags & (1 << NFTNL_EXPR_EXTHDR_TYPE))
-               nftnl_buf_str(&b, type, type2str(exthdr->type), EXTHDR_TYPE);
-       if (e->flags & (1 << NFTNL_EXPR_EXTHDR_OFFSET))
-               nftnl_buf_u32(&b, type, exthdr->offset, OFFSET);
-       if (e->flags & (1 << NFTNL_EXPR_EXTHDR_LEN))
-               nftnl_buf_u32(&b, type, exthdr->len, LEN);
-       if (e->flags & (1 << NFTNL_EXPR_EXTHDR_OP))
-               nftnl_buf_u32(&b, type, exthdr->op, OP);
-       if (e->flags & (1 << NFTNL_EXPR_EXTHDR_FLAGS))
-               nftnl_buf_u32(&b, type, exthdr->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_exthdr_snprintf_default(char *buf, size_t len,
                                              const struct nftnl_expr *e)
 {
@@ -344,7 +257,6 @@ nftnl_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_exthdr_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_exthdr_export(buf, len, e, type);
        default:
                break;
        }
@@ -386,5 +298,4 @@ struct expr_ops expr_ops_exthdr = {
        .parse          = nftnl_expr_exthdr_parse,
        .build          = nftnl_expr_exthdr_build,
        .snprintf       = nftnl_expr_exthdr_snprintf,
-       .json_parse     = nftnl_expr_exthdr_json_parse,
 };
index b922b26681e799a7ac2986ccbac469eec6107ea2..f1eec73a2927a732c744b2def5c3ecc0391c931f 100644 (file)
@@ -128,31 +128,6 @@ nftnl_expr_fib_parse(struct nftnl_expr *e, struct nlattr *attr)
        return ret;
 }
 
-static int nftnl_expr_fib_json_parse(struct nftnl_expr *e, json_t *root,
-                                     struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t result, flags, dreg;
-
-       if (nftnl_jansson_parse_reg(root, "result", NFTNL_TYPE_U32,
-                                   &result, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_FIB_RESULT, result);
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32,
-                                   &dreg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_FIB_DREG, dreg);
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32,
-                                   &flags, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_FIB_FLAGS, flags);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static const char *fib_type[NFT_FIB_RESULT_MAX + 1] = {
        [NFT_FIB_RESULT_OIF] = "oif",
        [NFT_FIB_RESULT_OIFNAME] = "oifname",
@@ -215,23 +190,6 @@ nftnl_expr_fib_snprintf_default(char *buf, size_t size,
        return offset;
 }
 
-static int nftnl_expr_fib_export(char *buf, size_t size,
-                                 const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_fib *fib = nftnl_expr_data(e);
-
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_FIB_RESULT))
-               nftnl_buf_u32(&b, type, fib->result, OP);
-       if (e->flags & (1 << NFTNL_EXPR_FIB_DREG))
-               nftnl_buf_u32(&b, type, fib->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_FIB_FLAGS))
-               nftnl_buf_u32(&b, type, fib->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_fib_snprintf(char *buf, size_t len, uint32_t type,
                         uint32_t flags, const struct nftnl_expr *e)
@@ -241,7 +199,6 @@ nftnl_expr_fib_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_fib_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_fib_export(buf, len, e, type);
        default:
                break;
        }
@@ -275,5 +232,4 @@ struct expr_ops expr_ops_fib = {
        .parse          = nftnl_expr_fib_parse,
        .build          = nftnl_expr_fib_build,
        .snprintf       = nftnl_expr_fib_snprintf,
-       .json_parse     = nftnl_expr_fib_json_parse,
 };
index a2001c9ae9dbbe8f4eea1d580e5507c31de084c6..648099a2d6afd1988b2ed7b108b16dea90914f68 100644 (file)
@@ -92,36 +92,6 @@ static int nftnl_expr_flow_parse(struct nftnl_expr *e, struct nlattr *attr)
        return ret;
 }
 
-static int
-nftnl_expr_flow_json_parse(struct nftnl_expr *e, json_t *root,
-                               struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *table_name;
-
-       table_name = nftnl_jansson_parse_str(root, "flowtable", err);
-       if (table_name != NULL)
-               nftnl_expr_set_str(e, NFTNL_EXPR_FLOW_TABLE_NAME, table_name);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_flow_export(char *buf, size_t size,
-                                 const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_flow *l = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_FLOW_TABLE_NAME))
-               nftnl_buf_str(&b, type, l->table_name, SET);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_flow_snprintf_default(char *buf, size_t size,
                                            const struct nftnl_expr *e)
 {
@@ -142,7 +112,6 @@ static int nftnl_expr_flow_snprintf(char *buf, size_t size, uint32_t type,
                return nftnl_expr_flow_snprintf_default(buf, size, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_flow_export(buf, size, e, type);
        default:
                break;
        }
@@ -180,5 +149,4 @@ struct expr_ops expr_ops_flow = {
        .parse          = nftnl_expr_flow_parse,
        .build          = nftnl_expr_flow_build,
        .snprintf       = nftnl_expr_flow_snprintf,
-       .json_parse     = nftnl_expr_flow_json_parse,
 };
index 90216066cb07f987d34fec6712ba5eb80482e756..9890e9aca5465e1cd278adc88e7b54254e8a83cd 100644 (file)
@@ -126,46 +126,6 @@ static int nftnl_expr_fwd_parse(struct nftnl_expr *e, struct nlattr *attr)
        return ret;
 }
 
-static int nftnl_expr_fwd_json_parse(struct nftnl_expr *e, json_t *root,
-                                    struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t u32val;
-       int ret;
-
-       ret = nftnl_jansson_parse_val(root, "sreg_dev", NFTNL_TYPE_U32, &u32val, err);
-       if (ret >= 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_FWD_SREG_DEV, u32val);
-       ret = nftnl_jansson_parse_val(root, "sreg_addr", NFTNL_TYPE_U32, &u32val, err);
-       if (ret >= 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_FWD_SREG_ADDR, u32val);
-       ret = nftnl_jansson_parse_val(root, "nfproto", NFTNL_TYPE_U32, &u32val, err);
-       if (ret >= 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_FWD_NFPROTO, u32val);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_fwd_export(char *buf, size_t size,
-                                const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_fwd *fwd = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_FWD_SREG_DEV))
-               nftnl_buf_u32(&b, type, fwd->sreg_dev, "sreg_dev");
-       if (e->flags & (1 << NFTNL_EXPR_FWD_SREG_ADDR))
-               nftnl_buf_u32(&b, type, fwd->sreg_dev, "sreg_addr");
-       if (e->flags & (1 << NFTNL_EXPR_FWD_NFPROTO))
-               nftnl_buf_u32(&b, type, fwd->nfproto, "nfproto");
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_fwd_snprintf_default(char *buf, size_t len,
                                           const struct nftnl_expr *e,
                                           uint32_t flags)
@@ -200,7 +160,6 @@ static int nftnl_expr_fwd_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_fwd_snprintf_default(buf, len, e, flags);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_fwd_export(buf, len, e, type);
        default:
                break;
        }
@@ -234,5 +193,4 @@ struct expr_ops expr_ops_fwd = {
        .parse          = nftnl_expr_fwd_parse,
        .build          = nftnl_expr_fwd_build,
        .snprintf       = nftnl_expr_fwd_snprintf,
-       .json_parse     = nftnl_expr_fwd_json_parse,
 };
index 415537ea721b130f2905811dafa470661832dfda..280ea0c41e75e4f1ee80d21f01c2d278b30c1aa4 100644 (file)
@@ -220,47 +220,6 @@ nftnl_expr_hash_parse(struct nftnl_expr *e, struct nlattr *attr)
        return ret;
 }
 
-static int nftnl_expr_hash_json_parse(struct nftnl_expr *e, json_t *root,
-                                     struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t sreg, dreg, len, modulus, seed, offset, type;
-
-       if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32,
-                                   &sreg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_SREG, sreg);
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32,
-                                   &dreg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_DREG, dreg);
-
-       if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32,
-                                   &len, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_LEN, len);
-
-       if (nftnl_jansson_parse_val(root, "modulus", NFTNL_TYPE_U32,
-                                   &modulus, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_MODULUS, modulus);
-
-       if (nftnl_jansson_parse_val(root, "seed", NFTNL_TYPE_U32,
-                                   &seed, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_SEED, seed);
-
-       if (nftnl_jansson_parse_val(root, "offset", NFTNL_TYPE_U32,
-                                   &offset, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_OFFSET, offset);
-
-       if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32,
-                                   &type, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_HASH_TYPE, type);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int
 nftnl_expr_hash_snprintf_default(char *buf, size_t size,
                                 const struct nftnl_expr *e)
@@ -302,33 +261,6 @@ nftnl_expr_hash_snprintf_default(char *buf, size_t size,
        return offset;
 }
 
-static int nftnl_expr_hash_export(char *buf, size_t size,
-                                 const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_hash *hash = nftnl_expr_data(e);
-
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_HASH_SREG))
-               nftnl_buf_u32(&b, type, hash->sreg, SREG);
-       if (e->flags & (1 << NFTNL_EXPR_HASH_DREG))
-               nftnl_buf_u32(&b, type, hash->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_HASH_LEN))
-               nftnl_buf_u32(&b, type, hash->len, LEN);
-       if (e->flags & (1 << NFTNL_EXPR_HASH_MODULUS))
-               nftnl_buf_u32(&b, type, hash->modulus, MODULUS);
-       if (e->flags & (1 << NFTNL_EXPR_HASH_SEED))
-               nftnl_buf_u32(&b, type, hash->seed, SEED);
-       if (e->flags & (1 << NFTNL_EXPR_HASH_OFFSET))
-               nftnl_buf_u32(&b, type, hash->offset, OFFSET);
-       if (e->flags & (1 << NFTNL_EXPR_HASH_TYPE))
-               nftnl_buf_u32(&b, type, hash->type, TYPE);
-       if (e->flags & (1 << NFTNL_EXPR_HASH_SET_NAME))
-               nftnl_buf_str(&b, type, hash->map.name, SET);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_hash_snprintf(char *buf, size_t len, uint32_t type,
                         uint32_t flags, const struct nftnl_expr *e)
@@ -338,7 +270,6 @@ nftnl_expr_hash_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_hash_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_hash_export(buf, len, e, type);
        default:
                break;
        }
@@ -384,5 +315,4 @@ struct expr_ops expr_ops_hash = {
        .parse          = nftnl_expr_hash_parse,
        .build          = nftnl_expr_hash_build,
        .snprintf       = nftnl_expr_hash_snprintf,
-       .json_parse     = nftnl_expr_hash_json_parse,
 };
index b0570bd539a4e409f9021f53981a8924e804e206..22edbc80b7f430f56f1dd86233ba03a9809d5795 100644 (file)
@@ -173,61 +173,6 @@ nftnl_expr_immediate_parse(struct nftnl_expr *e, struct nlattr *attr)
        return ret;
 }
 
-static int
-nftnl_expr_immediate_json_parse(struct nftnl_expr *e, json_t *root,
-                                  struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       struct nftnl_expr_immediate *imm = nftnl_expr_data(e);
-       int datareg_type;
-       uint32_t reg;
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_IMM_DREG, reg);
-
-       datareg_type = nftnl_jansson_data_reg_parse(root, "data",
-                                                 &imm->data, err);
-       if (datareg_type >= 0) {
-               switch (datareg_type) {
-               case DATA_VALUE:
-                       e->flags |= (1 << NFTNL_EXPR_IMM_DATA);
-                       break;
-               case DATA_VERDICT:
-                       e->flags |= (1 << NFTNL_EXPR_IMM_VERDICT);
-                       break;
-               case DATA_CHAIN:
-                       e->flags |= (1 << NFTNL_EXPR_IMM_CHAIN);
-                       break;
-               default:
-                       return -1;
-               }
-       }
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int
-nftnl_expr_immediate_export(char *buf, size_t size, const struct nftnl_expr *e,
-                           int type)
-{
-       struct nftnl_expr_immediate *imm = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_IMM_DREG))
-               nftnl_buf_u32(&b, type, imm->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_IMM_DATA))
-               nftnl_buf_reg(&b, type, &imm->data, DATA_VALUE, DATA);
-       if (e->flags & (1 << NFTNL_EXPR_IMM_VERDICT))
-               nftnl_buf_reg(&b, type, &imm->data, DATA_VERDICT, DATA);
-       if (e->flags & (1 << NFTNL_EXPR_IMM_CHAIN))
-               nftnl_buf_reg(&b, type, &imm->data, DATA_CHAIN, DATA);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_immediate_snprintf_default(char *buf, size_t len,
                                      const struct nftnl_expr *e,
@@ -267,7 +212,6 @@ nftnl_expr_immediate_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_immediate_snprintf_default(buf, len, e, flags);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_immediate_export(buf, len, e, type);
        default:
                break;
        }
@@ -317,5 +261,4 @@ struct expr_ops expr_ops_immediate = {
        .parse          = nftnl_expr_immediate_parse,
        .build          = nftnl_expr_immediate_build,
        .snprintf       = nftnl_expr_immediate_snprintf,
-       .json_parse     = nftnl_expr_immediate_json_parse,
 };
index 856ab1839b0a6fbf88af47a92730516202c9d56e..4831abd4bdfc210ba6c91ad0fd80a1071804ea70 100644 (file)
@@ -160,32 +160,6 @@ nftnl_expr_limit_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int nftnl_expr_limit_json_parse(struct nftnl_expr *e, json_t *root,
-                                         struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint64_t uval64;
-       uint32_t uval32;
-
-       if (nftnl_jansson_parse_val(root, "rate", NFTNL_TYPE_U64, &uval64, err) == 0)
-               nftnl_expr_set_u64(e, NFTNL_EXPR_LIMIT_RATE, uval64);
-
-       if (nftnl_jansson_parse_val(root, "unit", NFTNL_TYPE_U64, &uval64, err) == 0)
-               nftnl_expr_set_u64(e, NFTNL_EXPR_LIMIT_UNIT, uval64);
-       if (nftnl_jansson_parse_val(root, "burst", NFTNL_TYPE_U32, &uval32, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_LIMIT_BURST, uval32);
-       if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, &uval32, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_LIMIT_TYPE, uval32);
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &uval32, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_LIMIT_FLAGS, uval32);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static const char *get_unit(uint64_t u)
 {
        switch (u) {
@@ -198,26 +172,6 @@ static const char *get_unit(uint64_t u)
        return "error";
 }
 
-static int nftnl_expr_limit_export(char *buf, size_t size,
-                                  const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_limit *limit = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_LIMIT_RATE))
-               nftnl_buf_u64(&b, type, limit->rate, RATE);
-       if (e->flags & (1 << NFTNL_EXPR_LIMIT_UNIT))
-               nftnl_buf_u64(&b, type, limit->unit, UNIT);
-       if (e->flags & (1 << NFTNL_EXPR_LIMIT_BURST))
-               nftnl_buf_u32(&b, type, limit->burst, BURST);
-       if (e->flags & (1 << NFTNL_EXPR_LIMIT_TYPE))
-               nftnl_buf_u32(&b, type, limit->type, TYPE);
-       if (e->flags & (1 << NFTNL_EXPR_LIMIT_FLAGS))
-               nftnl_buf_u32(&b, type, limit->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static const char *limit_to_type(enum nft_limit_type type)
 {
        switch (type) {
@@ -248,7 +202,6 @@ nftnl_expr_limit_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_limit_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_limit_export(buf, len, e, type);
        default:
                break;
        }
@@ -286,5 +239,4 @@ struct expr_ops expr_ops_limit = {
        .parse          = nftnl_expr_limit_parse,
        .build          = nftnl_expr_limit_build,
        .snprintf       = nftnl_expr_limit_snprintf,
-       .json_parse     = nftnl_expr_limit_json_parse,
 };
index 86d965136cd4c6c574f9987c70783f5aa47d6348..e4bf0516e966f6458d686cd7ae439b7f8a6835dd 100644 (file)
@@ -186,45 +186,6 @@ nftnl_expr_log_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int nftnl_expr_log_json_parse(struct nftnl_expr *e, json_t *root,
-                                       struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *prefix;
-       uint32_t snaplen, level, flags;
-       uint16_t group, qthreshold;
-
-       prefix = nftnl_jansson_parse_str(root, "prefix", err);
-       if (prefix != NULL)
-               nftnl_expr_set_str(e, NFTNL_EXPR_LOG_PREFIX, prefix);
-
-       if (nftnl_jansson_parse_val(root, "group", NFTNL_TYPE_U16, &group,
-                                 err) == 0)
-               nftnl_expr_set_u16(e, NFTNL_EXPR_LOG_GROUP, group);
-
-       if (nftnl_jansson_parse_val(root, "snaplen", NFTNL_TYPE_U32, &snaplen,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_LOG_SNAPLEN, snaplen);
-
-       if (nftnl_jansson_parse_val(root, "qthreshold", NFTNL_TYPE_U16,
-                                 &qthreshold, err) == 0)
-               nftnl_expr_set_u16(e, NFTNL_EXPR_LOG_QTHRESHOLD, qthreshold);
-
-       if (nftnl_jansson_parse_val(root, "level", NFTNL_TYPE_U32, &level,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_LOG_LEVEL, level);
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_LOG_FLAGS, flags);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int nftnl_expr_log_snprintf_default(char *buf, size_t size,
                                           const struct nftnl_expr *e)
 {
@@ -275,28 +236,6 @@ static int nftnl_expr_log_snprintf_default(char *buf, size_t size,
        return offset;
 }
 
-static int nftnl_expr_log_export(char *buf, size_t size,
-                                const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_log *log = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_LOG_PREFIX))
-               nftnl_buf_str(&b, type, log->prefix, PREFIX);
-       if (e->flags & (1 << NFTNL_EXPR_LOG_GROUP))
-               nftnl_buf_u32(&b, type, log->group, GROUP);
-       if (e->flags & (1 << NFTNL_EXPR_LOG_SNAPLEN))
-               nftnl_buf_u32(&b, type, log->snaplen, SNAPLEN);
-       if (e->flags & (1 << NFTNL_EXPR_LOG_QTHRESHOLD))
-               nftnl_buf_u32(&b, type, log->qthreshold, QTHRESH);
-       if (e->flags & (1 << NFTNL_EXPR_LOG_LEVEL))
-               nftnl_buf_u32(&b, type, log->level, LEVEL);
-       if (e->flags & (1 << NFTNL_EXPR_LOG_FLAGS))
-               nftnl_buf_u32(&b, type, log->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_log_snprintf(char *buf, size_t len, uint32_t type,
                        uint32_t flags, const struct nftnl_expr *e)
@@ -306,7 +245,6 @@ nftnl_expr_log_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_log_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_log_export(buf, len, e, type);
        default:
                break;
        }
@@ -354,5 +292,4 @@ struct expr_ops expr_ops_log = {
        .parse          = nftnl_expr_log_parse,
        .build          = nftnl_expr_log_build,
        .snprintf       = nftnl_expr_log_snprintf,
-       .json_parse     = nftnl_expr_log_json_parse,
 };
index 5fcb81f3a7a24d6b3a5882b56ff6e5927ac1daf5..132dc4e66dc64d852fec4ccd8acee07d94bca92d 100644 (file)
@@ -167,54 +167,6 @@ nftnl_expr_lookup_parse(struct nftnl_expr *e, struct nlattr *attr)
        return ret;
 }
 
-static int
-nftnl_expr_lookup_json_parse(struct nftnl_expr *e, json_t *root,
-                               struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *set_name;
-       uint32_t sreg, dreg, flags;
-
-       set_name = nftnl_jansson_parse_str(root, "set", err);
-       if (set_name != NULL)
-               nftnl_expr_set_str(e, NFTNL_EXPR_LOOKUP_SET, set_name);
-
-       if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &sreg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_LOOKUP_SREG, sreg);
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &dreg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_LOOKUP_DREG, dreg);
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32,
-                                   &flags, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_LOOKUP_FLAGS, flags);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int
-nftnl_expr_lookup_export(char *buf, size_t size,
-                        const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_lookup *l = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SET))
-               nftnl_buf_str(&b, type, l->set_name, SET);
-       if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SREG))
-               nftnl_buf_u32(&b, type, l->sreg, SREG);
-       if (e->flags & (1 << NFTNL_EXPR_LOOKUP_DREG))
-               nftnl_buf_u32(&b, type, l->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_LOOKUP_FLAGS))
-               nftnl_buf_u32(&b, type, l->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_lookup_snprintf_default(char *buf, size_t size,
                                   const struct nftnl_expr *e)
@@ -247,7 +199,6 @@ nftnl_expr_lookup_snprintf(char *buf, size_t size, uint32_t type,
                return nftnl_expr_lookup_snprintf_default(buf, size, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_lookup_export(buf, size, e, type);
        default:
                break;
        }
@@ -293,5 +244,4 @@ struct expr_ops expr_ops_lookup = {
        .parse          = nftnl_expr_lookup_parse,
        .build          = nftnl_expr_lookup_build,
        .snprintf       = nftnl_expr_lookup_snprintf,
-       .json_parse     = nftnl_expr_lookup_json_parse,
 };
index 7c235d3b0bdc75dbc508ed369c2d9f9728fcc75d..78dd76b1a3b3dfd60441aeafcc5e23a4f0759b84 100644 (file)
@@ -131,46 +131,6 @@ nftnl_expr_masq_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_expr_masq_json_parse(struct nftnl_expr *e, json_t *root,
-                             struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t reg, flags;
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_MASQ_FLAGS, flags);
-       if (nftnl_jansson_parse_reg(root, "sreg_proto_min", NFTNL_TYPE_U32,
-                                   &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_MASQ_REG_PROTO_MIN, reg);
-       if (nftnl_jansson_parse_reg(root, "sreg_proto_max", NFTNL_TYPE_U32,
-                                   &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_MASQ_REG_PROTO_MAX, reg);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_masq_export(char *buf, size_t size,
-                                 const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_masq *masq = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_MASQ_FLAGS))
-               nftnl_buf_u32(&b, type, masq->flags, FLAGS);
-       if (e->flags & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MIN))
-               nftnl_buf_u32(&b, type, masq->sreg_proto_min, SREG_PROTO_MIN);
-       if (e->flags & (1 << NFTNL_EXPR_MASQ_REG_PROTO_MAX))
-               nftnl_buf_u32(&b, type, masq->sreg_proto_max, SREG_PROTO_MAX);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_masq_snprintf_default(char *buf, size_t len,
                                            const struct nftnl_expr *e)
 {
@@ -195,7 +155,6 @@ static int nftnl_expr_masq_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_masq_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_masq_export(buf, len, e, type);
        default:
                break;
        }
@@ -229,5 +188,4 @@ struct expr_ops expr_ops_masq = {
        .parse          = nftnl_expr_masq_parse,
        .build          = nftnl_expr_masq_build,
        .snprintf       = nftnl_expr_masq_snprintf,
-       .json_parse     = nftnl_expr_masq_json_parse,
 };
index dd09e1e851925579b393ffae1558a9d7e14d74a3..85dd79c6a63d9d4fe866051467b33aadd8ba301b 100644 (file)
@@ -164,36 +164,6 @@ static int nftnl_expr_match_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int nftnl_expr_match_json_parse(struct nftnl_expr *e, json_t *root,
-                                         struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *name;
-
-       name = nftnl_jansson_parse_str(root, "name", err);
-       if (name != NULL)
-               nftnl_expr_set_str(e, NFTNL_EXPR_MT_NAME, name);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-
-static int nftnl_expr_match_export(char *buf, size_t size,
-                                  const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_match *mt = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_MT_NAME))
-               nftnl_buf_str(&b, type, mt->name, NAME);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_match_snprintf(char *buf, size_t len, uint32_t type,
                          uint32_t flags, const struct nftnl_expr *e)
@@ -206,7 +176,6 @@ nftnl_expr_match_snprintf(char *buf, size_t len, uint32_t type,
                                match->name, match->rev);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_match_export(buf, len, e, type);
        default:
                break;
        }
@@ -250,5 +219,4 @@ struct expr_ops expr_ops_match = {
        .parse          = nftnl_expr_match_parse,
        .build          = nftnl_expr_match_build,
        .snprintf       = nftnl_expr_match_snprintf,
-       .json_parse     = nftnl_expr_match_json_parse,
 };
index de82105de44ff570f5d27f8b3023afbdcbeb109c..b66b9b702ca2bf0fdbdabb04def46995cac2bdc0 100644 (file)
@@ -182,40 +182,6 @@ static inline int str2meta_key(const char *str)
        return -1;
 }
 
-static int nftnl_expr_meta_json_parse(struct nftnl_expr *e, json_t *root,
-                                        struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *key_str;
-       uint32_t reg;
-       int key;
-
-       key_str = nftnl_jansson_parse_str(root, "key", err);
-       if (key_str != NULL) {
-               key = str2meta_key(key_str);
-               if (key >= 0)
-                       nftnl_expr_set_u32(e, NFTNL_EXPR_META_KEY, key);
-       }
-
-       if (nftnl_jansson_node_exist(root, "dreg")) {
-               if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg,
-                                         err) == 0)
-                       nftnl_expr_set_u32(e, NFTNL_EXPR_META_DREG, reg);
-       }
-
-       if (nftnl_jansson_node_exist(root, "sreg")) {
-               if (nftnl_jansson_parse_reg(root, "sreg", NFTNL_TYPE_U32, &reg,
-                                         err) == 0)
-                       nftnl_expr_set_u32(e, NFTNL_EXPR_META_SREG, reg);
-       }
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int
 nftnl_expr_meta_snprintf_default(char *buf, size_t len,
                                 const struct nftnl_expr *e)
@@ -233,22 +199,6 @@ nftnl_expr_meta_snprintf_default(char *buf, size_t len,
        return 0;
 }
 
-static int nftnl_expr_meta_export(char *buf, size_t size,
-                                 const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_meta *meta = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_META_DREG))
-               nftnl_buf_u32(&b, type, meta->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_META_KEY))
-               nftnl_buf_str(&b, type, meta_key2str(meta->key), KEY);
-       if (e->flags & (1 << NFTNL_EXPR_META_SREG))
-               nftnl_buf_u32(&b, type, meta->sreg, SREG);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_meta_snprintf(char *buf, size_t len, uint32_t type,
                         uint32_t flags, const struct nftnl_expr *e)
@@ -258,7 +208,6 @@ nftnl_expr_meta_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_meta_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_meta_export(buf, len, e, type);
        default:
                break;
        }
@@ -292,5 +241,4 @@ struct expr_ops expr_ops_meta = {
        .parse          = nftnl_expr_meta_parse,
        .build          = nftnl_expr_meta_build,
        .snprintf       = nftnl_expr_meta_snprintf,
-       .json_parse     = nftnl_expr_meta_json_parse,
 };
index 92713033a6e766b81137a207a5eb48cebfe6eabf..9be78f39c31d54140b75f42405dfdbb27b07661f 100644 (file)
@@ -220,85 +220,6 @@ static inline int nftnl_str2nat(const char *nat)
        }
 }
 
-static int nftnl_expr_nat_json_parse(struct nftnl_expr *e, json_t *root,
-                                       struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *nat_type, *family_str;
-       uint32_t reg, flags;
-       int val32;
-
-       nat_type = nftnl_jansson_parse_str(root, "nat_type", err);
-       if (nat_type == NULL)
-               return -1;
-
-       val32 = nftnl_str2nat(nat_type);
-       if (val32 < 0)
-               return -1;
-
-       nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_TYPE, val32);
-
-       family_str = nftnl_jansson_parse_str(root, "family", err);
-       if (family_str == NULL)
-               return -1;
-
-       val32 = nftnl_str2family(family_str);
-       if (val32 < 0)
-               return -1;
-
-       nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_FAMILY, val32);
-
-       if (nftnl_jansson_parse_reg(root, "sreg_addr_min", NFTNL_TYPE_U32,
-                                 &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_REG_ADDR_MIN, reg);
-
-       if (nftnl_jansson_parse_reg(root, "sreg_addr_max", NFTNL_TYPE_U32,
-                                 &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_REG_ADDR_MAX, reg);
-
-       if (nftnl_jansson_parse_reg(root, "sreg_proto_min", NFTNL_TYPE_U32,
-                                 &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_REG_PROTO_MIN, reg);
-
-       if (nftnl_jansson_parse_reg(root, "sreg_proto_max", NFTNL_TYPE_U32,
-                                 &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_REG_PROTO_MAX, reg);
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32,
-                                 &flags, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_NAT_FLAGS, flags);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_nat_export(char *buf, size_t size,
-                                const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_nat *nat = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_NAT_TYPE))
-               nftnl_buf_str(&b, type, nat2str(nat->type), NAT_TYPE);
-       if (e->flags & (1 << NFTNL_EXPR_NAT_FAMILY))
-               nftnl_buf_str(&b, type, nftnl_family2str(nat->family), FAMILY);
-       if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MIN))
-               nftnl_buf_u32(&b, type, nat->sreg_addr_min, SREG_ADDR_MIN);
-       if (e->flags & (1 << NFTNL_EXPR_NAT_REG_ADDR_MAX))
-               nftnl_buf_u32(&b, type, nat->sreg_addr_max, SREG_ADDR_MAX);
-       if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MIN))
-               nftnl_buf_u32(&b, type, nat->sreg_proto_min, SREG_PROTO_MIN);
-       if (e->flags & (1 << NFTNL_EXPR_NAT_REG_PROTO_MAX))
-               nftnl_buf_u32(&b, type, nat->sreg_proto_max, SREG_PROTO_MAX);
-       if (e->flags & (1 << NFTNL_EXPR_NAT_FLAGS))
-               nftnl_buf_u32(&b, type, nat->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_nat_snprintf_default(char *buf, size_t size,
                                const struct nftnl_expr *e)
@@ -344,7 +265,6 @@ nftnl_expr_nat_snprintf(char *buf, size_t size, uint32_t type,
                return nftnl_expr_nat_snprintf_default(buf, size, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_nat_export(buf, size, e, type);
        default:
                break;
        }
@@ -385,5 +305,4 @@ struct expr_ops expr_ops_nat = {
        .parse          = nftnl_expr_nat_parse,
        .build          = nftnl_expr_nat_build,
        .snprintf       = nftnl_expr_nat_snprintf,
-       .json_parse     = nftnl_expr_nat_json_parse,
 };
index 5336fdec1d69d1e8edfea879cb0b15d8bb278174..d46cf947464de834d8a6a5447f601b6876c2736c 100644 (file)
@@ -179,35 +179,6 @@ nftnl_expr_ng_parse(struct nftnl_expr *e, struct nlattr *attr)
        return ret;
 }
 
-static int nftnl_expr_ng_json_parse(struct nftnl_expr *e, json_t *root,
-                                   struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t dreg, modulus, type, offset;
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32,
-                                   &dreg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_NG_DREG, dreg);
-
-       if (nftnl_jansson_parse_val(root, "modulus", NFTNL_TYPE_U32,
-                                   &modulus, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_NG_MODULUS, modulus);
-
-       if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32,
-                                   &type, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_NG_TYPE, type);
-
-       if (nftnl_jansson_parse_val(root, "offset", NFTNL_TYPE_U32,
-                                   &offset, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_NG_OFFSET, offset);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int
 nftnl_expr_ng_snprintf_default(char *buf, size_t size,
                               const struct nftnl_expr *e)
@@ -244,27 +215,6 @@ nftnl_expr_ng_snprintf_default(char *buf, size_t size,
        return offset;
 }
 
-static int nftnl_expr_ng_export(char *buf, size_t size,
-                               const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_ng *ng = nftnl_expr_data(e);
-
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_NG_DREG))
-               nftnl_buf_u32(&b, type, ng->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_NG_MODULUS))
-               nftnl_buf_u32(&b, type, ng->modulus, MODULUS);
-       if (e->flags & (1 << NFTNL_EXPR_NG_TYPE))
-               nftnl_buf_u32(&b, type, ng->type, TYPE);
-       if (e->flags & (1 << NFTNL_EXPR_NG_OFFSET))
-               nftnl_buf_u32(&b, type, ng->type, OFFSET);
-       if (e->flags & (1 << NFTNL_EXPR_NG_SET_NAME))
-               nftnl_buf_str(&b, type, ng->map.name, SET);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_ng_snprintf(char *buf, size_t len, uint32_t type,
                       uint32_t flags, const struct nftnl_expr *e)
@@ -274,7 +224,6 @@ nftnl_expr_ng_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_ng_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_ng_export(buf, len, e, type);
        default:
                break;
        }
@@ -314,5 +263,4 @@ struct expr_ops expr_ops_ng = {
        .parse          = nftnl_expr_ng_parse,
        .build          = nftnl_expr_ng_build,
        .snprintf       = nftnl_expr_ng_snprintf,
-       .json_parse     = nftnl_expr_ng_json_parse,
 };
index 64ee8638027c97b9825e8dc5378554973c159bb6..67fd74bd8992658eae14942c63b16e02d3c36a69 100644 (file)
@@ -174,51 +174,6 @@ static int nftnl_expr_objref_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_expr_objref_json_parse(struct nftnl_expr *e, json_t *root,
-                            struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t uval32;
-       const char *str;
-
-       if (nftnl_jansson_node_exist(root, "name")) {
-               str = nftnl_jansson_parse_str(root, "name", err);
-               if (str == NULL)
-                       return -1;
-
-               nftnl_expr_set_str(e, NFTNL_EXPR_OBJREF_IMM_NAME, str);
-       }
-
-       if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, &uval32,
-                                   err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_OBJREF_IMM_TYPE, uval32);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_objref_export(char *buf, size_t size,
-                                   const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_objref *objref = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_OBJREF_IMM_TYPE))
-               nftnl_buf_u32(&b, type, objref->imm.type, BYTES);
-       if (e->flags & (1 << NFTNL_EXPR_OBJREF_IMM_NAME))
-               nftnl_buf_str(&b, type, objref->imm.name, NAME);
-       if (e->flags & (1 << NFTNL_EXPR_OBJREF_SET_SREG))
-               nftnl_buf_u32(&b, type, objref->set.sreg, SREG);
-       if (e->flags & (1 << NFTNL_EXPR_OBJREF_SET_NAME))
-               nftnl_buf_str(&b, type, objref->set.name, SET);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_objref_snprintf_default(char *buf, size_t len,
                                              const struct nftnl_expr *e)
 {
@@ -241,7 +196,6 @@ static int nftnl_expr_objref_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_objref_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_objref_export(buf, len, e, type);
        default:
                break;
        }
@@ -279,5 +233,4 @@ struct expr_ops expr_ops_objref = {
        .parse          = nftnl_expr_objref_parse,
        .build          = nftnl_expr_objref_build,
        .snprintf       = nftnl_expr_objref_snprintf,
-       .json_parse     = nftnl_expr_objref_json_parse,
 };
index 6fd62e5823328ced7e59a569af79ad6d50fcedb1..372ebe1a8588645bb8e9b59f9f74e2c315505dc9 100644 (file)
@@ -102,18 +102,6 @@ static int nftnl_expr_osf_snprintf_default(char *buf, size_t size,
        return offset;
 }
 
-static int nftnl_expr_osf_export(char *buf, size_t size,
-                                const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_osf *osf = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_OSF_DREG))
-               nftnl_buf_u32(&b, type, osf->dreg, "dreg");
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_osf_snprintf(char *buf, size_t len, uint32_t type,
                        uint32_t flags, const struct nftnl_expr *e)
@@ -123,7 +111,6 @@ nftnl_expr_osf_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_osf_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_osf_export(buf, len, e, type);
        default:
                break;
        }
index 91e1587ff239b3236705e9125e6588f4c4a359f9..4b2f32213c292fcc38391f5d9144d41e9c2f70b4 100644 (file)
@@ -231,59 +231,6 @@ static inline int nftnl_str2base(const char *base)
        }
 }
 
-static int
-nftnl_expr_payload_json_parse(struct nftnl_expr *e, json_t *root,
-                                struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *base_str;
-       uint32_t reg, uval32;
-       int base;
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_DREG, reg);
-
-       base_str = nftnl_jansson_parse_str(root, "base", err);
-       if (base_str != NULL) {
-               base = nftnl_str2base(base_str);
-               if (base < 0)
-                       return -1;
-
-               nftnl_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_BASE, base);
-       }
-
-       if (nftnl_jansson_parse_val(root, "offset", NFTNL_TYPE_U32, &uval32,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_OFFSET, uval32);
-
-       if (nftnl_jansson_parse_val(root, "len", NFTNL_TYPE_U32, &uval32, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_PAYLOAD_LEN, uval32);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_payload_export(char *buf, size_t size, uint32_t flags,
-                                    const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_payload *payload = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_DREG))
-               nftnl_buf_u32(&b, type, payload->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_OFFSET))
-               nftnl_buf_u32(&b, type, payload->offset, OFFSET);
-       if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_LEN))
-               nftnl_buf_u32(&b, type, payload->len, LEN);
-       if (e->flags & (1 << NFTNL_EXPR_PAYLOAD_BASE))
-               nftnl_buf_str(&b, type, base2str(payload->base), BASE);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_payload_snprintf(char *buf, size_t len, uint32_t type,
                            uint32_t flags, const struct nftnl_expr *e)
@@ -305,7 +252,6 @@ nftnl_expr_payload_snprintf(char *buf, size_t len, uint32_t type,
                                        payload->offset, payload->dreg);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_payload_export(buf, len, flags, e, type);
        default:
                break;
        }
@@ -349,5 +295,4 @@ struct expr_ops expr_ops_payload = {
        .parse          = nftnl_expr_payload_parse,
        .build          = nftnl_expr_payload_build,
        .snprintf       = nftnl_expr_payload_snprintf,
-       .json_parse     = nftnl_expr_payload_json_parse,
 };
index a392a271a6fb48b58ffd660236cd27591dc93c1d..e71df7dafd03cb02697721695352aea5d22a5d3a 100644 (file)
@@ -143,35 +143,6 @@ nftnl_expr_queue_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_expr_queue_json_parse(struct nftnl_expr *e, json_t *root,
-                              struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t sreg_qnum;
-       uint16_t type;
-       uint16_t code;
-
-       if (nftnl_jansson_parse_val(root, "num", NFTNL_TYPE_U16, &type, err) == 0)
-               nftnl_expr_set_u16(e, NFTNL_EXPR_QUEUE_NUM, type);
-
-       if (nftnl_jansson_parse_val(root, "total", NFTNL_TYPE_U16, &code, err) == 0)
-               nftnl_expr_set_u16(e, NFTNL_EXPR_QUEUE_TOTAL, code);
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U16, &code, err) == 0)
-               nftnl_expr_set_u16(e, NFTNL_EXPR_QUEUE_FLAGS, code);
-
-       if (nftnl_jansson_parse_val(root, "sreg_qnum", NFTNL_TYPE_U32, &sreg_qnum,
-                                   err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_QUEUE_SREG_QNUM, sreg_qnum);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int nftnl_expr_queue_snprintf_default(char *buf, size_t len,
                                             const struct nftnl_expr *e)
 {
@@ -213,24 +184,6 @@ static int nftnl_expr_queue_snprintf_default(char *buf, size_t len,
        return offset;
 }
 
-static int nftnl_expr_queue_export(char *buf, size_t size,
-                                  const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_queue *queue = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_QUEUE_NUM))
-               nftnl_buf_u32(&b, type, queue->queuenum, NUM);
-       if (e->flags & (1 << NFTNL_EXPR_QUEUE_TOTAL))
-               nftnl_buf_u32(&b, type, queue->queues_total, TOTAL);
-       if (e->flags & (1 << NFTNL_EXPR_QUEUE_FLAGS))
-               nftnl_buf_u32(&b, type, queue->flags, FLAGS);
-       if (e->flags & (1 << NFTNL_EXPR_QUEUE_SREG_QNUM))
-               nftnl_buf_u32(&b, type, queue->sreg_qnum, SREG_QNUM);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_queue_snprintf(char *buf, size_t len, uint32_t type,
                          uint32_t flags, const struct nftnl_expr *e)
@@ -240,7 +193,6 @@ nftnl_expr_queue_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_queue_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_queue_export(buf, len, e, type);
        default:
                break;
        }
@@ -276,5 +228,4 @@ struct expr_ops expr_ops_queue = {
        .parse          = nftnl_expr_queue_parse,
        .build          = nftnl_expr_queue_build,
        .snprintf       = nftnl_expr_queue_snprintf,
-       .json_parse     = nftnl_expr_queue_json_parse,
 };
index 667e6e17c28ce159182408930fec84c9bf959da1..b2808529442adb47ecc4e485984531892647197e 100644 (file)
@@ -128,47 +128,6 @@ nftnl_expr_quota_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_expr_quota_json_parse(struct nftnl_expr *e, json_t *root,
-                                struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint64_t bytes, consumed;
-       uint32_t flags;
-
-       if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &bytes,
-                                 err) == 0)
-               nftnl_expr_set_u64(e, NFTNL_EXPR_QUOTA_BYTES, bytes);
-       if (nftnl_jansson_parse_val(root, "consumed", NFTNL_TYPE_U64, &consumed,
-                                 err) == 0)
-               nftnl_expr_set_u64(e, NFTNL_EXPR_QUOTA_CONSUMED, consumed);
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_QUOTA_FLAGS, flags);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_quota_export(char *buf, size_t size,
-                                  const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_quota *quota = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_QUOTA_BYTES))
-               nftnl_buf_u64(&b, type, quota->bytes, BYTES);
-       if (e->flags & (1 << NFTNL_EXPR_QUOTA_CONSUMED))
-               nftnl_buf_u64(&b, type, quota->consumed, CONSUMED);
-       if (e->flags & (1 << NFTNL_EXPR_QUOTA_FLAGS))
-               nftnl_buf_u32(&b, type, quota->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_quota_snprintf_default(char *buf, size_t len,
                                               const struct nftnl_expr *e)
 {
@@ -188,7 +147,6 @@ static int nftnl_expr_quota_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_quota_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_quota_export(buf, len, e, type);
        default:
                break;
        }
@@ -204,5 +162,4 @@ struct expr_ops expr_ops_quota = {
        .parse          = nftnl_expr_quota_parse,
        .build          = nftnl_expr_quota_build,
        .snprintf       = nftnl_expr_quota_snprintf,
-       .json_parse     = nftnl_expr_quota_json_parse,
 };
index b2789ffaada340b425bb7b07ac3b8804c5c52fda..f5a41acd12e052b03ad1d2b0f6708310b374f0cb 100644 (file)
@@ -184,61 +184,6 @@ static inline int nftnl_str2range(const char *op)
        }
 }
 
-static int nftnl_expr_range_json_parse(struct nftnl_expr *e, json_t *root,
-                                      struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       struct nftnl_expr_range *range = nftnl_expr_data(e);
-       const char *op;
-       uint32_t uval32;
-       int base;
-
-       if (nftnl_jansson_parse_val(root, "sreg", NFTNL_TYPE_U32, &uval32,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_RANGE_SREG, uval32);
-
-       op = nftnl_jansson_parse_str(root, "op", err);
-       if (op != NULL) {
-               base = nftnl_str2range(op);
-               if (base < 0)
-                       return -1;
-
-               nftnl_expr_set_u32(e, NFTNL_EXPR_RANGE_OP, base);
-       }
-
-       if (nftnl_jansson_data_reg_parse(root, "data_from",
-                                        &range->data_from, err) == DATA_VALUE)
-               e->flags |= (1 << NFTNL_EXPR_RANGE_FROM_DATA);
-
-       if (nftnl_jansson_data_reg_parse(root, "data_to",
-                                        &range->data_to, err) == DATA_VALUE)
-               e->flags |= (1 << NFTNL_EXPR_RANGE_TO_DATA);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_range_export(char *buf, size_t size,
-                                const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_range *range = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_RANGE_SREG))
-               nftnl_buf_u32(&b, type, range->sreg, SREG);
-       if (e->flags & (1 << NFTNL_EXPR_RANGE_OP))
-               nftnl_buf_str(&b, type, range2str(range->op), OP);
-       if (e->flags & (1 << NFTNL_EXPR_RANGE_FROM_DATA))
-               nftnl_buf_reg(&b, type, &range->data_from, DATA_VALUE, DATA);
-       if (e->flags & (1 << NFTNL_EXPR_RANGE_TO_DATA))
-               nftnl_buf_reg(&b, type, &range->data_to, DATA_VALUE, DATA);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_range_snprintf_default(char *buf, size_t size,
                                           const struct nftnl_expr *e)
 {
@@ -246,7 +191,7 @@ static int nftnl_expr_range_snprintf_default(char *buf, size_t size,
        int remain = size, offset = 0, ret;
 
        ret = snprintf(buf, remain, "%s reg %u ",
-                      expr_range_str[range->op], range->sreg);
+                      range2str(range->op), range->sreg);
        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
        ret = nftnl_data_reg_snprintf(buf + offset, remain, &range->data_from,
@@ -268,7 +213,6 @@ static int nftnl_expr_range_snprintf(char *buf, size_t size, uint32_t type,
                return nftnl_expr_range_snprintf_default(buf, size, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_range_export(buf, size, e, type);
        default:
                break;
        }
@@ -284,5 +228,4 @@ struct expr_ops expr_ops_range = {
        .parse          = nftnl_expr_range_parse,
        .build          = nftnl_expr_range_build,
        .snprintf       = nftnl_expr_range_snprintf,
-       .json_parse     = nftnl_expr_range_json_parse,
 };
index b2aa3453870a90a3cd88622d3ac8a6e25095b3cb..1ed48969b15401a118747e087ddd1f177c9575e8 100644 (file)
@@ -131,48 +131,6 @@ nftnl_expr_redir_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_expr_redir_json_parse(struct nftnl_expr *e, json_t *root,
-                              struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t reg, flags;
-
-       if (nftnl_jansson_parse_reg(root, "sreg_proto_min", NFTNL_TYPE_U32,
-                                 &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_REDIR_REG_PROTO_MIN, reg);
-
-       if (nftnl_jansson_parse_reg(root, "sreg_proto_max", NFTNL_TYPE_U32,
-                                 &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_REDIR_REG_PROTO_MAX, reg);
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags,
-                                 err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_REDIR_FLAGS, flags);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_expr_redir_export(char *buf, size_t size,
-                                  const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_redir *redir = nftnl_expr_data(e);
-        NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_REDIR_REG_PROTO_MIN))
-               nftnl_buf_u32(&b, type, redir->sreg_proto_min, SREG_PROTO_MIN);
-       if (e->flags & (1 << NFTNL_EXPR_REDIR_REG_PROTO_MAX))
-               nftnl_buf_u32(&b, type, redir->sreg_proto_max, SREG_PROTO_MAX);
-       if (e->flags & (1 << NFTNL_EXPR_REDIR_FLAGS))
-               nftnl_buf_u32(&b, type, redir->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_expr_redir_snprintf_default(char *buf, size_t len,
                                             const struct nftnl_expr *e)
 {
@@ -209,7 +167,6 @@ nftnl_expr_redir_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_redir_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_redir_export(buf, len, e, type);
        default:
                break;
        }
@@ -243,5 +200,4 @@ struct expr_ops expr_ops_redir = {
        .parse          = nftnl_expr_redir_parse,
        .build          = nftnl_expr_redir_build,
        .snprintf       = nftnl_expr_redir_snprintf,
-       .json_parse     = nftnl_expr_redir_json_parse,
 };
index 11d8b20096aec74bf5779be275c673cb1bac8160..b26b0cc5711abf288b553fcc6f295b764b4cc038 100644 (file)
@@ -116,27 +116,6 @@ nftnl_expr_reject_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_expr_reject_json_parse(struct nftnl_expr *e, json_t *root,
-                               struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint32_t type;
-       uint8_t code;
-
-       if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, &type, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_REJECT_TYPE, type);
-
-       if (nftnl_jansson_parse_val(root, "code", NFTNL_TYPE_U8, &code, err) == 0)
-               nftnl_expr_set_u8(e, NFTNL_EXPR_REJECT_CODE, code);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int nftnl_expr_reject_snprintf_default(char *buf, size_t len,
                                              const struct nftnl_expr *e)
 {
@@ -146,20 +125,6 @@ static int nftnl_expr_reject_snprintf_default(char *buf, size_t len,
                        reject->type, reject->icmp_code);
 }
 
-static int nftnl_expr_reject_export(char *buf, size_t size,
-                                   const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_reject *reject = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_REJECT_TYPE))
-               nftnl_buf_u32(&b, type, reject->type, TYPE);
-       if (e->flags & (1 << NFTNL_EXPR_REJECT_CODE))
-               nftnl_buf_u32(&b, type, reject->icmp_code, CODE);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_reject_snprintf(char *buf, size_t len, uint32_t type,
                           uint32_t flags, const struct nftnl_expr *e)
@@ -169,7 +134,6 @@ nftnl_expr_reject_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_reject_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_reject_export(buf, len, e, type);
        default:
                break;
        }
@@ -201,5 +165,4 @@ struct expr_ops expr_ops_reject = {
        .parse          = nftnl_expr_reject_parse,
        .build          = nftnl_expr_reject_build,
        .snprintf       = nftnl_expr_reject_snprintf,
-       .json_parse     = nftnl_expr_reject_json_parse,
 };
index 18c3945d45ee8c5da2dc4345337306ea4449ebcc..2c0c1cf00b56212195f7c8b85b406872223a2f9d 100644 (file)
@@ -141,34 +141,6 @@ static inline int str2rt_key(const char *str)
        return -1;
 }
 
-static int nftnl_expr_rt_json_parse(struct nftnl_expr *e, json_t *root,
-                                   struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *val_str;
-       uint32_t reg;
-       int val32;
-
-       val_str = nftnl_jansson_parse_str(root, "key", err);
-       if (val_str != NULL) {
-               val32 = str2rt_key(val_str);
-               if (val32 >= 0)
-                       nftnl_expr_set_u32(e, NFTNL_EXPR_RT_KEY, val32);
-       }
-
-       if (nftnl_jansson_node_exist(root, "dreg")) {
-               if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg,
-                                         err) == 0)
-                       nftnl_expr_set_u32(e, NFTNL_EXPR_RT_DREG, reg);
-       }
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int
 nftnl_expr_rt_snprintf_default(char *buf, size_t len,
                               const struct nftnl_expr *e)
@@ -182,20 +154,6 @@ nftnl_expr_rt_snprintf_default(char *buf, size_t len,
        return 0;
 }
 
-static int nftnl_expr_rt_export(char *buf, size_t size,
-                                 const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_rt *rt = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_RT_DREG))
-               nftnl_buf_u32(&b, type, rt->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_RT_KEY))
-               nftnl_buf_str(&b, type, rt_key2str(rt->key), KEY);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_rt_snprintf(char *buf, size_t len, uint32_t type,
                       uint32_t flags, const struct nftnl_expr *e)
@@ -205,7 +163,6 @@ nftnl_expr_rt_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_rt_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_rt_export(buf, len, e, type);
        default:
                break;
        }
@@ -237,5 +194,4 @@ struct expr_ops expr_ops_rt = {
        .parse          = nftnl_expr_rt_parse,
        .build          = nftnl_expr_rt_build,
        .snprintf       = nftnl_expr_rt_snprintf,
-       .json_parse     = nftnl_expr_rt_json_parse,
 };
index 5fa2ef2ec2f32c67005cf5f3a755dc63c168309d..704b1d943d2426a3352177f8b44f355d04611d0e 100644 (file)
@@ -151,20 +151,6 @@ nftnl_expr_socket_snprintf_default(char *buf, size_t len,
        return 0;
 }
 
-static int nftnl_expr_socket_export(char *buf, size_t size,
-                                 const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_socket *socket = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_SOCKET_DREG))
-               nftnl_buf_u32(&b, type, socket->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_SOCKET_KEY))
-               nftnl_buf_str(&b, type, socket_key2str(socket->key), KEY);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_socket_snprintf(char *buf, size_t len, uint32_t type,
                       uint32_t flags, const struct nftnl_expr *e)
@@ -174,7 +160,6 @@ nftnl_expr_socket_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_socket_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_socket_export(buf, len, e, type);
        default:
                break;
        }
index ed4bf7df632879749a53cbe140862e318b58fabe..6ae6c819d2f4dd1ad7ffe3d7b91af46d1edddf5d 100644 (file)
@@ -164,36 +164,6 @@ static int nftnl_expr_target_parse(struct nftnl_expr *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_expr_target_json_parse(struct nftnl_expr *e, json_t *root,
-                               struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *name;
-
-       name = nftnl_jansson_parse_str(root, "name", err);
-       if (name != NULL)
-               nftnl_expr_set_str(e, NFTNL_EXPR_TG_NAME, name);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_rule_exp_target_export(char *buf, size_t size,
-                                       const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_target *target = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_TG_NAME))
-               nftnl_buf_str(&b, type, target->name, NAME);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_target_snprintf(char *buf, size_t len, uint32_t type,
                           uint32_t flags, const struct nftnl_expr *e)
@@ -206,7 +176,6 @@ nftnl_expr_target_snprintf(char *buf, size_t len, uint32_t type,
                                target->name, target->rev);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_rule_exp_target_export(buf, len, e, type);
        default:
                break;
        }
@@ -250,5 +219,4 @@ struct expr_ops expr_ops_target = {
        .parse          = nftnl_expr_target_parse,
        .build          = nftnl_expr_target_build,
        .snprintf       = nftnl_expr_target_snprintf,
-       .json_parse     = nftnl_expr_target_json_parse,
 };
index 2067c35d79d50ddd51c5f42713cffafff456bc49..677e9685b8ad19ec4f2607a0cfb96871f83e1a29 100644 (file)
@@ -150,20 +150,6 @@ nftnl_expr_tunnel_snprintf_default(char *buf, size_t len,
        return 0;
 }
 
-static int nftnl_expr_tunnel_export(char *buf, size_t size,
-                                 const struct nftnl_expr *e, int type)
-{
-       struct nftnl_expr_tunnel *tunnel = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_TUNNEL_DREG))
-               nftnl_buf_u32(&b, type, tunnel->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_TUNNEL_KEY))
-               nftnl_buf_str(&b, type, tunnel_key2str(tunnel->key), KEY);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_tunnel_snprintf(char *buf, size_t len, uint32_t type,
                         uint32_t flags, const struct nftnl_expr *e)
@@ -173,7 +159,6 @@ nftnl_expr_tunnel_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_tunnel_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_tunnel_export(buf, len, e, type);
        default:
                break;
        }
index b159d60d1e3fd1789687ae4690774fc5af64dcaa..dd3062c43a7457d9fc77614a8209a6ddb56878cd 100644 (file)
@@ -199,66 +199,6 @@ static int str2xfmrdir(const char *s)
 }
 #endif
 
-static int nftnl_expr_xfrm_json_parse(struct nftnl_expr *e, json_t *root,
-                                     struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       const char *key_str, *dir_str;
-       uint32_t reg, key, spnum;
-       uint8_t dir;
-
-       if (nftnl_jansson_parse_reg(root, "dreg", NFTNL_TYPE_U32, &reg, err) == 0)
-               nftnl_expr_set_u32(e, NFTNL_EXPR_XFRM_DREG, reg);
-
-       key_str = nftnl_jansson_parse_str(root, "key", err);
-       if (key_str != NULL) {
-               key = str2xfrmkey(key_str);
-               if (key < 0)
-                       return -1;
-
-               nftnl_expr_set_u32(e, NFTNL_EXPR_XFRM_KEY, key);
-       }
-
-       dir_str = nftnl_jansson_parse_str(root, "dir", err);
-       if (dir_str != NULL) {
-               dir = str2xfmrdir(dir_str);
-               if (dir == -1) {
-                       err->node_name = "dir";
-                       err->error = NFTNL_PARSE_EBADTYPE;
-                       goto err;
-               }
-               nftnl_expr_set_u8(e, NFTNL_EXPR_XFRM_DIR, dir);
-       }
-
-       return 0;
-err:
-       errno = EINVAL;
-       return -1;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int
-nftnl_expr_xfrm_export(char *buf, size_t size, const struct nftnl_expr *e,
-                    int type)
-{
-       struct nftnl_expr_xfrm *x = nftnl_expr_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_EXPR_XFRM_DREG))
-               nftnl_buf_u32(&b, type, x->dreg, DREG);
-       if (e->flags & (1 << NFTNL_EXPR_XFRM_KEY))
-               nftnl_buf_str(&b, type, xfrmkey2str(x->key), KEY);
-       if (e->flags & (1 << NFTNL_EXPR_XFRM_DIR))
-               nftnl_buf_str(&b, type, xfrmdir2str(x->dir), DIR);
-       if (e->flags & (1 << NFTNL_EXPR_XFRM_SPNUM))
-               nftnl_buf_u32(&b, type, x->spnum, NUM);
-
-       return nftnl_buf_done(&b);
-}
-
 static int
 nftnl_expr_xfrm_snprintf_default(char *buf, size_t size,
                               const struct nftnl_expr *e)
@@ -285,7 +225,6 @@ nftnl_expr_xfrm_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_expr_xfrm_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_expr_xfrm_export(buf, len, e, type);
        default:
                break;
        }
@@ -321,5 +260,4 @@ struct expr_ops expr_ops_xfrm = {
        .parse          = nftnl_expr_xfrm_parse,
        .build          = nftnl_expr_xfrm_build,
        .snprintf       = nftnl_expr_xfrm_snprintf,
-       .json_parse     = nftnl_expr_xfrm_json_parse,
 };
index c1ddae4ad65e29b41aa08f92b9d6d043500271c4..c939306b56c4de861adbbea5c15026f79b995171 100644 (file)
@@ -513,109 +513,11 @@ static inline int nftnl_str2hooknum(int family, const char *hook)
        return -1;
 }
 
-#ifdef JSON_PARSING
-static int nftnl_jansson_parse_flowtable(struct nftnl_flowtable *c,
-                                        json_t *tree,
-                                        struct nftnl_parse_err *err)
-{
-       const char *name, *table, *hooknum_str;
-       int32_t family, prio, hooknum;
-       uint32_t size;
-       json_t *root;
-
-       root = nftnl_jansson_get_node(tree, "flowtable", err);
-       if (root == NULL)
-               return -1;
-
-       name = nftnl_jansson_parse_str(root, "name", err);
-       if (name != NULL)
-               nftnl_flowtable_set_str(c, NFTNL_FLOWTABLE_NAME, name);
-
-       if (nftnl_jansson_parse_family(root, &family, err) == 0)
-               nftnl_flowtable_set_u32(c, NFTNL_FLOWTABLE_FAMILY, family);
-
-       table = nftnl_jansson_parse_str(root, "table", err);
-
-       if (table != NULL)
-               nftnl_flowtable_set_str(c, NFTNL_FLOWTABLE_TABLE, table);
-
-       if (nftnl_jansson_node_exist(root, "hooknum")) {
-               if (nftnl_jansson_parse_val(root, "prio", NFTNL_TYPE_S32,
-                                         &prio, err) == 0)
-                       nftnl_flowtable_set_s32(c, NFTNL_FLOWTABLE_PRIO, prio);
-
-               hooknum_str = nftnl_jansson_parse_str(root, "hooknum", err);
-               if (hooknum_str != NULL) {
-                       hooknum = nftnl_str2hooknum(c->family, hooknum_str);
-                       if (hooknum == -1)
-                               return -1;
-                       nftnl_flowtable_set_u32(c, NFTNL_FLOWTABLE_HOOKNUM,
-                                              hooknum);
-               }
-       }
-       if (nftnl_jansson_parse_val(root, "size", NFTNL_TYPE_U32,
-                                   &size, err) == 0)
-               nftnl_flowtable_set_u32(c, NFTNL_FLOWTABLE_SIZE, size);
-
-       return 0;
-}
-#endif
-
-static int nftnl_flowtable_json_parse(struct nftnl_flowtable *c,
-                                     const void *json,
-                                     struct nftnl_parse_err *err,
-                                     enum nftnl_parse_input input)
-{
-#ifdef JSON_PARSING
-       json_t *tree;
-       json_error_t error;
-       int ret;
-
-       tree = nftnl_jansson_create_root(json, &error, err, input);
-       if (tree == NULL)
-               return -1;
-
-       ret = nftnl_jansson_parse_flowtable(c, tree, err);
-
-       nftnl_jansson_free_root(tree);
-
-       return ret;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_flowtable_do_parse(struct nftnl_flowtable *c,
-                                   enum nftnl_parse_type type,
-                                   const void *data,
-                                   struct nftnl_parse_err *err,
-                                   enum nftnl_parse_input input)
-{
-       int ret;
-       struct nftnl_parse_err perr = {};
-
-       switch (type) {
-       case NFTNL_PARSE_JSON:
-               ret = nftnl_flowtable_json_parse(c, data, &perr, input);
-               break;
-       case NFTNL_PARSE_XML:
-       default:
-               ret = -1;
-               errno = EOPNOTSUPP;
-               break;
-       }
-
-       if (err != NULL)
-               *err = perr;
-
-       return ret;
-}
-
 int nftnl_flowtable_parse(struct nftnl_flowtable *c, enum nftnl_parse_type type,
                          const char *data, struct nftnl_parse_err *err)
 {
-       return nftnl_flowtable_do_parse(c, type, data, err, NFTNL_PARSE_BUFFER);
+       errno = EOPNOTSUPP;
+       return -1;
 }
 EXPORT_SYMBOL(nftnl_flowtable_parse);
 
@@ -623,41 +525,11 @@ int nftnl_flowtable_parse_file(struct nftnl_flowtable *c,
                               enum nftnl_parse_type type,
                               FILE *fp, struct nftnl_parse_err *err)
 {
-       return nftnl_flowtable_do_parse(c, type, fp, err, NFTNL_PARSE_FILE);
+       errno = EOPNOTSUPP;
+       return -1;
 }
 EXPORT_SYMBOL(nftnl_flowtable_parse_file);
 
-static int nftnl_flowtable_export(char *buf, size_t size,
-                                 const struct nftnl_flowtable *c, int type)
-{
-       NFTNL_BUF_INIT(b, buf, size);
-
-       nftnl_buf_open(&b, type, CHAIN);
-       if (c->flags & (1 << NFTNL_FLOWTABLE_NAME))
-               nftnl_buf_str(&b, type, c->name, NAME);
-       if (c->flags & (1 << NFTNL_FLOWTABLE_TABLE))
-               nftnl_buf_str(&b, type, c->table, TABLE);
-       if (c->flags & (1 << NFTNL_FLOWTABLE_FAMILY))
-               nftnl_buf_str(&b, type, nftnl_family2str(c->family), FAMILY);
-       if (c->flags & (1 << NFTNL_FLOWTABLE_USE))
-               nftnl_buf_u32(&b, type, c->use, USE);
-       if (c->flags & (1 << NFTNL_FLOWTABLE_HOOKNUM)) {
-               if (c->flags & (1 << NFTNL_FLOWTABLE_HOOKNUM))
-                       nftnl_buf_str(&b, type, nftnl_hooknum2str(c->family,
-                                        c->hooknum), HOOKNUM);
-               if (c->flags & (1 << NFTNL_FLOWTABLE_PRIO))
-                       nftnl_buf_s32(&b, type, c->prio, PRIO);
-       }
-       if (c->flags & (1 << NFTNL_FLOWTABLE_SIZE))
-               nftnl_buf_u32(&b, type, c->size, SIZE);
-       if (c->flags & (1 << NFTNL_FLOWTABLE_FLAGS))
-               nftnl_buf_u32(&b, type, c->ft_flags, FLAGS);
-
-       nftnl_buf_close(&b, type, CHAIN);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_flowtable_snprintf_default(char *buf, size_t size,
                                            const struct nftnl_flowtable *c)
 {
@@ -697,26 +569,18 @@ static int nftnl_flowtable_cmd_snprintf(char *buf, size_t size,
 {
        int ret, remain = size, offset = 0;
 
-       ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                ret = nftnl_flowtable_snprintf_default(buf + offset, remain, c);
+               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                break;
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               ret = nftnl_flowtable_export(buf + offset, remain, c, type);
                break;
        default:
                return -1;
        }
 
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = nftnl_cmd_footer_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        return offset;
 }
 
index f92180c7baf6dffeb8be95d98a0329573a52f5cc..8e1a37a3097f621433ac1c1a4d16981833205d23 100644 (file)
--- a/src/gen.c
+++ b/src/gen.c
@@ -156,32 +156,20 @@ int nftnl_gen_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_gen *gen)
        return 0;
 }
 
-static int nftnl_gen_snprintf_default(char *buf, size_t size,
-                                     const struct nftnl_gen *gen)
-{
-       return snprintf(buf, size, "ruleset generation ID %u", gen->id);
-}
-
 static int nftnl_gen_cmd_snprintf(char *buf, size_t size,
                                  const struct nftnl_gen *gen, uint32_t cmd,
                                  uint32_t type, uint32_t flags)
 {
        int ret, remain = size, offset = 0;
 
-       ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        switch(type) {
        case NFTNL_OUTPUT_DEFAULT:
-               ret = nftnl_gen_snprintf_default(buf + offset, remain, gen);
+               ret = snprintf(buf, size, "ruleset generation ID %u", gen->id);
+               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                break;
        default:
                return -1;
        }
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = nftnl_cmd_footer_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
        return offset;
 }
diff --git a/src/jansson.c b/src/jansson.c
deleted file mode 100644 (file)
index 3476ed2..0000000
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * (C) 2013 by Álvaro Neira Ayuso <alvaroneay@gmail.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- */
-
-#include <internal.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <arpa/inet.h>
-#include <errno.h>
-#include <string.h>
-#include "expr_ops.h"
-#include <libnftnl/set.h>
-
-#include <libnftnl/expr.h>
-#include <linux/netfilter/nf_tables.h>
-
-#ifdef JSON_PARSING
-
-static int nftnl_jansson_load_int_node(json_t *root, const char *node_name,
-                                     json_int_t *val, struct nftnl_parse_err *err)
-{
-       json_t *node;
-
-       node = json_object_get(root, node_name);
-       if (node == NULL) {
-               err->error = NFTNL_PARSE_EMISSINGNODE;
-               err->node_name = node_name;
-               errno = EINVAL;
-               return -1;
-       }
-
-       if (!json_is_integer(node)) {
-               err->error = NFTNL_PARSE_EBADTYPE;
-               err->node_name = node_name;
-               errno = ERANGE;
-               return -1;
-       }
-       *val = json_integer_value(node);
-
-       return 0;
-}
-
-const char *nftnl_jansson_parse_str(json_t *root, const char *node_name,
-                                 struct nftnl_parse_err *err)
-{
-       json_t *node;
-       const char *val;
-
-       node = json_object_get(root, node_name);
-       if (node == NULL) {
-               err->error = NFTNL_PARSE_EMISSINGNODE;
-               err->node_name = node_name;
-               errno = EINVAL;
-               return NULL;
-       }
-
-       val = json_string_value(node);
-       if (val == NULL) {
-               err->error = NFTNL_PARSE_EBADTYPE;
-               err->node_name = node_name;
-       }
-
-       return val;
-}
-
-int nftnl_jansson_parse_val(json_t *root, const char *node_name, int type,
-                         void *out, struct nftnl_parse_err *err)
-{
-       json_int_t val;
-
-       if (nftnl_jansson_load_int_node(root, node_name, &val, err) == -1)
-               return -1;
-
-       if (nftnl_get_value(type, &val, out) == -1)
-               return -1;
-
-       return 0;
-}
-
-bool nftnl_jansson_node_exist(json_t *root, const char *node_name)
-{
-       return json_object_get(root, node_name) != NULL;
-}
-
-json_t *nftnl_jansson_create_root(const void *json, json_error_t *error,
-                               struct nftnl_parse_err *err, enum nftnl_parse_input input)
-{
-       json_t *root;
-
-       switch (input) {
-       case NFTNL_PARSE_BUFFER:
-               root = json_loadb(json, strlen(json), 0, error);
-               break;
-       case NFTNL_PARSE_FILE:
-               root = json_loadf((FILE *)json, 0, error);
-               break;
-       default:
-               goto err;
-       }
-
-       if (root == NULL) {
-               err->error = NFTNL_PARSE_EBADINPUT;
-               err->line = error->line;
-               err->column = error->column;
-               err->node_name = error->source;
-               goto err;
-       }
-
-       return root;
-err:
-       errno = EINVAL;
-       return NULL;
-}
-
-json_t *nftnl_jansson_get_node(json_t *root, const char *node_name,
-                            struct nftnl_parse_err *err)
-{
-       json_t *node;
-
-       node = json_object_get(root, node_name);
-       if (node == NULL) {
-               err->error = NFTNL_PARSE_EMISSINGNODE;
-               err->node_name = node_name;
-               errno = EINVAL;
-               return NULL;
-       }
-
-       return node;
-}
-
-void nftnl_jansson_free_root(json_t *root)
-{
-       json_decref(root);
-}
-
-int nftnl_jansson_parse_family(json_t *root, void *out, struct nftnl_parse_err *err)
-{
-       const char *str;
-       int family;
-
-       str = nftnl_jansson_parse_str(root, "family", err);
-       if (str == NULL)
-               return -1;
-
-       family = nftnl_str2family(str);
-       if (family < 0) {
-               err->node_name = "family";
-               errno = EINVAL;
-               return -1;
-       }
-
-       memcpy(out, &family, sizeof(family));
-       return 0;
-}
-
-int nftnl_jansson_parse_reg(json_t *root, const char *node_name, int type,
-                         void *out, struct nftnl_parse_err *err)
-{
-       if (nftnl_jansson_parse_val(root, node_name, type, out, err) < 0)
-               return -1;
-
-       if (*((uint32_t *)out) > NFT_REG_MAX){
-               errno = ERANGE;
-               return -1;
-       }
-
-       return 0;
-}
-
-int nftnl_jansson_str2num(json_t *root, const char *node_name, int base,
-                       void *out, enum nftnl_type type, struct nftnl_parse_err *err)
-{
-       const char *str;
-
-       str = nftnl_jansson_parse_str(root, node_name, err);
-       if (str == NULL)
-               return -1;
-
-       return nftnl_strtoi(str, base, out, type);
-}
-
-struct nftnl_expr *nftnl_jansson_expr_parse(json_t *root,
-                                            struct nftnl_parse_err *err,
-                                            struct nftnl_set_list *set_list)
-{
-       struct nftnl_expr *e;
-       const char *type;
-       uint32_t set_id;
-       int ret;
-
-       type = nftnl_jansson_parse_str(root, "type", err);
-       if (type == NULL)
-               return NULL;
-
-       e = nftnl_expr_alloc(type);
-       if (e == NULL) {
-               err->node_name = "type";
-               return NULL;
-       }
-
-       ret = e->ops->json_parse(e, root, err);
-
-       if (set_list != NULL &&
-           strcmp(type, "lookup") == 0 &&
-           nftnl_set_lookup_id(e, set_list, &set_id))
-               nftnl_expr_set_u32(e, NFTNL_EXPR_LOOKUP_SET_ID, set_id);
-
-       return ret < 0 ? NULL : e;
-}
-
-int nftnl_jansson_data_reg_parse(json_t *root, const char *node_name,
-                              union nftnl_data_reg *data_reg,
-                              struct nftnl_parse_err *err)
-{
-       json_t *data;
-       int ret;
-
-        /* It is necessary for the compatibility with cmpdata label. */
-       data = json_object_get(root, node_name);
-       if (data == NULL)
-               data = root;
-
-       data = json_object_get(data, "reg");
-       if (data == NULL) {
-               err->error = NFTNL_PARSE_EMISSINGNODE;
-               err->node_name = "reg";
-               errno = EINVAL;
-               return -1;
-       }
-
-       ret = nftnl_data_reg_json_parse(data_reg, data, err);
-       if (ret == DATA_NONE) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       return ret;
-}
-
-int nftnl_jansson_set_elem_parse(struct nftnl_set_elem *e, json_t *root,
-                              struct nftnl_parse_err *err)
-{
-       int set_elem_data;
-       uint32_t flags;
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, err) == 0)
-               nftnl_set_elem_set_u32(e, NFTNL_SET_ELEM_FLAGS, flags);
-
-       if (nftnl_jansson_data_reg_parse(root, "key", &e->key, err) == DATA_VALUE)
-               e->flags |= (1 << NFTNL_SET_ELEM_KEY);
-
-       if (nftnl_jansson_node_exist(root, "data")) {
-               set_elem_data = nftnl_jansson_data_reg_parse(root, "data",
-                                                          &e->data, err);
-               switch (set_elem_data) {
-               case DATA_VALUE:
-                       e->flags |= (1 << NFTNL_SET_ELEM_DATA);
-                       break;
-               case DATA_VERDICT:
-                       e->flags |= (1 << NFTNL_SET_ELEM_VERDICT);
-                       if (e->data.chain != NULL)
-                               e->flags |= (1 << NFTNL_SET_ELEM_CHAIN);
-                       break;
-               case DATA_NONE:
-               default:
-                       return -1;
-               }
-       }
-
-       return 0;
-}
-#endif
index 332bb2b35fa2208043ea3d74a4dd0c28364ded61..23b60c56638ad571912fbdf51cb0a3f73eb20e6e 100644 (file)
@@ -109,42 +109,6 @@ nftnl_obj_counter_parse(struct nftnl_obj *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_obj_counter_json_parse(struct nftnl_obj *e, json_t *root,
-                                struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint64_t uval64;
-
-       if (nftnl_jansson_parse_val(root, "pkts", NFTNL_TYPE_U64, &uval64,
-                                 err) == 0)
-               nftnl_obj_set_u64(e, NFTNL_OBJ_CTR_PKTS, uval64);
-
-       if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &uval64,
-                                 err) == 0)
-               nftnl_obj_set_u64(e, NFTNL_OBJ_CTR_BYTES, uval64);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_obj_counter_export(char *buf, size_t size,
-                                   const struct nftnl_obj *e, int type)
-{
-       struct nftnl_obj_counter *ctr = nftnl_obj_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_OBJ_CTR_PKTS))
-               nftnl_buf_u64(&b, type, ctr->pkts, PKTS);
-       if (e->flags & (1 << NFTNL_OBJ_CTR_BYTES))
-               nftnl_buf_u64(&b, type, ctr->bytes, BYTES);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_obj_counter_snprintf_default(char *buf, size_t len,
                                               const struct nftnl_obj *e)
 {
@@ -166,7 +130,6 @@ static int nftnl_obj_counter_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_obj_counter_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_obj_counter_export(buf, len, e, type);
        default:
                break;
        }
@@ -183,5 +146,4 @@ struct obj_ops obj_ops_counter = {
        .parse          = nftnl_obj_counter_parse,
        .build          = nftnl_obj_counter_build,
        .snprintf       = nftnl_obj_counter_snprintf,
-       .json_parse     = nftnl_obj_counter_json_parse,
 };
index 62569fefe26f1e959abb510d8531f423ac23e73e..5a689b1405d8ba6ee38755312e51c75dc7cdceed 100644 (file)
@@ -131,47 +131,6 @@ nftnl_obj_ct_helper_parse(struct nftnl_obj *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_obj_quota_json_parse(struct nftnl_obj *e, json_t *root,
-                                struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint64_t bytes;
-       uint32_t flags;
-
-       if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &bytes,
-                                 err) == 0)
-               nftnl_obj_set_u64(e, NFTNL_OBJ_QUOTA_BYTES, bytes);
-       if (nftnl_jansson_parse_val(root, "consumed", NFTNL_TYPE_U64, &bytes,
-                                   err) == 0)
-               nftnl_obj_set_u64(e, NFTNL_OBJ_QUOTA_CONSUMED, bytes);
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags,
-                                 err) == 0)
-               nftnl_obj_set_u32(e, NFTNL_OBJ_QUOTA_FLAGS, flags);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_obj_ct_helper_export(char *buf, size_t size,
-                                  const struct nftnl_obj *e, int type)
-{
-       struct nftnl_obj_ct_helper *helper = nftnl_obj_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_OBJ_CT_HELPER_NAME))
-               nftnl_buf_str(&b, type, helper->name, NAME);
-       if (e->flags & (1 << NFTNL_OBJ_CT_HELPER_L3PROTO))
-               nftnl_buf_u32(&b, type, helper->l3proto, FAMILY);
-       if (e->flags & (1 << NFTNL_OBJ_CT_HELPER_L4PROTO))
-               nftnl_buf_u32(&b, type, helper->l4proto, "service");
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_obj_ct_helper_snprintf_default(char *buf, size_t len,
                                               const struct nftnl_obj *e)
 {
@@ -192,7 +151,6 @@ static int nftnl_obj_ct_helper_snprintf(char *buf, size_t len, uint32_t type,
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_obj_ct_helper_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_JSON:
-               return nftnl_obj_ct_helper_export(buf, len, e, type);
        default:
                break;
        }
@@ -209,5 +167,4 @@ struct obj_ops obj_ops_ct_helper = {
        .parse          = nftnl_obj_ct_helper_parse,
        .build          = nftnl_obj_ct_helper_build,
        .snprintf       = nftnl_obj_ct_helper_snprintf,
-       .json_parse     = nftnl_obj_quota_json_parse,
 };
index 7c2ea97e782109236f18357f405ab8f99514d3dc..12c8f5f9b4dfd876ba92ab331df4299344920ae1 100644 (file)
@@ -254,21 +254,6 @@ nftnl_obj_ct_timeout_parse(struct nftnl_obj *e, struct nlattr *attr)
        return 0;
 }
 
-static int nftnl_obj_ct_timeout_export(char *buf, size_t size,
-                                  const struct nftnl_obj *e, int type)
-{
-       struct nftnl_obj_ct_timeout *timeout = nftnl_obj_data(e);
-
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_OBJ_CT_TIMEOUT_L3PROTO))
-               nftnl_buf_u32(&b, type, timeout->l3proto, FAMILY);
-       if (e->flags & (1 << NFTNL_OBJ_CT_TIMEOUT_L4PROTO))
-               nftnl_buf_u32(&b, type, timeout->l4proto, "service");
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_obj_ct_timeout_snprintf_default(char *buf, size_t len,
                                               const struct nftnl_obj *e)
 {
@@ -330,7 +315,6 @@ static int nftnl_obj_ct_timeout_snprintf(char *buf, size_t len, uint32_t type,
        case NFTNL_OUTPUT_DEFAULT:
                return nftnl_obj_ct_timeout_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_JSON:
-               return nftnl_obj_ct_timeout_export(buf, len, e, type);
        default:
                break;
        }
index 7f8bcf732b1827a2ca7e01611c3ee8adbcb6434c..b0ed4c8b84b2cc88b337d486dead178e17380597 100644 (file)
@@ -148,56 +148,6 @@ static int nftnl_obj_limit_parse(struct nftnl_obj *e, struct nlattr *attr)
        return 0;
 }
 
-static int nftnl_obj_limit_json_parse(struct nftnl_obj *e, json_t *root,
-                                     struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint64_t uval64;
-       uint32_t uval32;
-
-       if (nftnl_jansson_parse_val(root, "rate", NFTNL_TYPE_U64, &uval64,
-                                   err) == 0)
-               nftnl_obj_set_u64(e, NFTNL_OBJ_LIMIT_RATE, uval64);
-       if (nftnl_jansson_parse_val(root, "unit", NFTNL_TYPE_U64, &uval64,
-                                   err) == 0)
-               nftnl_obj_set_u64(e, NFTNL_OBJ_LIMIT_UNIT, uval64);
-       if (nftnl_jansson_parse_val(root, "burst", NFTNL_TYPE_U32, &uval32,
-                                   err) == 0)
-               nftnl_obj_set_u32(e, NFTNL_OBJ_LIMIT_BURST, uval32);
-       if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, &uval32,
-                                   err) == 0)
-               nftnl_obj_set_u32(e, NFTNL_OBJ_LIMIT_TYPE, uval32);
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &uval32,
-                                   err) == 0)
-               nftnl_obj_set_u32(e, NFTNL_OBJ_LIMIT_FLAGS, uval32);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_obj_limit_export(char *buf, size_t size,
-                                 const struct nftnl_obj *e, int type)
-{
-       struct nftnl_obj_limit *limit = nftnl_obj_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_OBJ_LIMIT_RATE))
-               nftnl_buf_u64(&b, type, limit->rate, RATE);
-       if (e->flags & (1 << NFTNL_OBJ_LIMIT_UNIT))
-               nftnl_buf_u64(&b, type, limit->unit, UNIT);
-       if (e->flags & (1 << NFTNL_OBJ_LIMIT_BURST))
-               nftnl_buf_u32(&b, type, limit->burst, BURST);
-       if (e->flags & (1 << NFTNL_OBJ_LIMIT_TYPE))
-               nftnl_buf_u32(&b, type, limit->type, TYPE);
-       if (e->flags & (1 << NFTNL_OBJ_LIMIT_FLAGS))
-               nftnl_buf_u32(&b, type, limit->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_obj_limit_snprintf_default(char *buf, size_t len,
                                            const struct nftnl_obj *e)
 {
@@ -220,7 +170,6 @@ static int nftnl_obj_limit_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_obj_limit_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_obj_limit_export(buf, len, e, type);
        default:
                break;
        }
@@ -237,5 +186,4 @@ struct obj_ops obj_ops_limit = {
        .parse          = nftnl_obj_limit_parse,
        .build          = nftnl_obj_limit_build,
        .snprintf       = nftnl_obj_limit_snprintf,
-       .json_parse     = nftnl_obj_limit_json_parse,
 };
index 6d3678465d40bfe4ae044a12a7c95e6c84a489ff..b1a3f7e4b7545e7a63aaf582bf50bad9a6d5f79f 100644 (file)
@@ -125,47 +125,6 @@ nftnl_obj_quota_parse(struct nftnl_obj *e, struct nlattr *attr)
        return 0;
 }
 
-static int
-nftnl_obj_quota_json_parse(struct nftnl_obj *e, json_t *root,
-                                struct nftnl_parse_err *err)
-{
-#ifdef JSON_PARSING
-       uint64_t bytes;
-       uint32_t flags;
-
-       if (nftnl_jansson_parse_val(root, "bytes", NFTNL_TYPE_U64, &bytes,
-                                 err) == 0)
-               nftnl_obj_set_u64(e, NFTNL_OBJ_QUOTA_BYTES, bytes);
-       if (nftnl_jansson_parse_val(root, "consumed", NFTNL_TYPE_U64, &bytes,
-                                   err) == 0)
-               nftnl_obj_set_u64(e, NFTNL_OBJ_QUOTA_CONSUMED, bytes);
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags,
-                                 err) == 0)
-               nftnl_obj_set_u32(e, NFTNL_OBJ_QUOTA_FLAGS, flags);
-
-       return 0;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int nftnl_obj_quota_export(char *buf, size_t size,
-                                  const struct nftnl_obj *e, int type)
-{
-       struct nftnl_obj_quota *quota = nftnl_obj_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_OBJ_QUOTA_BYTES))
-               nftnl_buf_u64(&b, type, quota->bytes, BYTES);
-       if (e->flags & (1 << NFTNL_OBJ_QUOTA_CONSUMED))
-               nftnl_buf_u64(&b, type, quota->consumed, CONSUMED);
-       if (e->flags & (1 << NFTNL_OBJ_QUOTA_FLAGS))
-               nftnl_buf_u32(&b, type, quota->flags, FLAGS);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_obj_quota_snprintf_default(char *buf, size_t len,
                                               const struct nftnl_obj *e)
 {
@@ -187,7 +146,6 @@ static int nftnl_obj_quota_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_obj_quota_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_obj_quota_export(buf, len, e, type);
        default:
                break;
        }
@@ -204,5 +162,4 @@ struct obj_ops obj_ops_quota = {
        .parse          = nftnl_obj_quota_parse,
        .build          = nftnl_obj_quota_build,
        .snprintf       = nftnl_obj_quota_snprintf,
-       .json_parse     = nftnl_obj_quota_json_parse,
 };
index 32ca0fd5971724346af7962582b87b59d68c5048..5b2d9de74438789ebf1f83bab27413fd684aace3 100644 (file)
@@ -530,18 +530,6 @@ nftnl_obj_tunnel_parse(struct nftnl_obj *e, struct nlattr *attr)
        return 0;
 }
 
-static int nftnl_obj_tunnel_export(char *buf, size_t size,
-                                  const struct nftnl_obj *e, int type)
-{
-       struct nftnl_obj_tunnel *tun = nftnl_obj_data(e);
-       NFTNL_BUF_INIT(b, buf, size);
-
-       if (e->flags & (1 << NFTNL_OBJ_TUNNEL_ID))
-               nftnl_buf_u64(&b, type, tun->id, ID);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_obj_tunnel_snprintf_default(char *buf, size_t len,
                                             const struct nftnl_obj *e)
 {
@@ -561,7 +549,6 @@ static int nftnl_obj_tunnel_snprintf(char *buf, size_t len, uint32_t type,
                return nftnl_obj_tunnel_snprintf_default(buf, len, e);
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               return nftnl_obj_tunnel_export(buf, len, e, type);
        default:
                break;
        }
index f62395d00211afba473570ada72eab7deccf03d0..a1a553f07660a49c4be99d7c61f01d6f8a8f5533 100644 (file)
@@ -321,58 +321,6 @@ int nftnl_obj_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_obj *obj)
        return 0;
 }
 
-#ifdef JSON_PARSING
-static int nftnl_jansson_parse_obj(struct nftnl_obj *t, json_t *tree,
-                           struct nftnl_parse_err *err)
-{
-       const char *str;
-       uint32_t type;
-       json_t *root;
-
-       root = nftnl_jansson_get_node(tree, "obj", err);
-       if (root == NULL)
-               return -1;
-
-       str = nftnl_jansson_parse_str(root, "table", err);
-       if (str != NULL)
-               nftnl_obj_set_str(t, NFTNL_OBJ_TABLE, str);
-
-       str = nftnl_jansson_parse_str(root, "name", err);
-       if (str != NULL)
-               nftnl_obj_set_str(t, NFTNL_OBJ_NAME, str);
-
-       if (nftnl_jansson_parse_val(root, "type", NFTNL_TYPE_U32, &type,
-                                   err) < 0)
-               nftnl_obj_set_u32(t, NFTNL_OBJ_TYPE, type);
-
-       return 0;
-}
-#endif
-
-static int nftnl_obj_json_parse(struct nftnl_obj *t, const void *json,
-                               struct nftnl_parse_err *err,
-                               enum nftnl_parse_input input)
-{
-#ifdef JSON_PARSING
-       json_t *tree;
-       json_error_t error;
-       int ret;
-
-       tree = nftnl_jansson_create_root(json, &error, err, input);
-       if (tree == NULL)
-               return -1;
-
-       ret = nftnl_jansson_parse_obj(t, tree, err);
-
-       nftnl_jansson_free_root(tree);
-
-       return ret;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int nftnl_obj_do_parse(struct nftnl_obj *obj, enum nftnl_parse_type type,
                              const void *data, struct nftnl_parse_err *err,
                              enum nftnl_parse_input input)
@@ -382,8 +330,6 @@ static int nftnl_obj_do_parse(struct nftnl_obj *obj, enum nftnl_parse_type type,
 
        switch (type) {
        case NFTNL_PARSE_JSON:
-               ret = nftnl_obj_json_parse(obj, data, &perr, input);
-               break;
        case NFTNL_PARSE_XML:
        default:
                ret = -1;
@@ -411,36 +357,6 @@ int nftnl_obj_parse_file(struct nftnl_obj *obj, enum nftnl_parse_type type,
        return nftnl_obj_do_parse(obj, type, fp, err, NFTNL_PARSE_FILE);
 }
 
-static int nftnl_obj_export(char *buf, size_t size,
-                           const struct nftnl_obj *obj,
-                           uint32_t type, uint32_t flags)
-{
-       int ret = 0;
-
-       NFTNL_BUF_INIT(b, buf, size);
-
-       nftnl_buf_open(&b, type, TABLE);
-       if (obj->flags & (1 << NFTNL_OBJ_TABLE))
-               nftnl_buf_str(&b, type, obj->name, NAME);
-       if (obj->flags & (1 << NFTNL_OBJ_NAME))
-               nftnl_buf_str(&b, type, obj->name, NAME);
-       if (obj->flags & (1 << NFTNL_OBJ_FAMILY))
-               nftnl_buf_str(&b, type, nftnl_family2str(obj->family), FAMILY);
-       if (obj->flags & (1 << NFTNL_OBJ_USE))
-               nftnl_buf_u32(&b, type, obj->use, USE);
-       if (obj->flags & (1 << NFTNL_OBJ_HANDLE))
-               nftnl_buf_u64(&b, type, obj->handle, HANDLE);
-
-       if (obj->ops)
-               ret = obj->ops->snprintf(buf + b.len, size - b.len, type,
-                                        flags, obj);
-
-       b.len += ret;
-       nftnl_buf_close(&b, type, TABLE);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_obj_snprintf_dflt(char *buf, size_t size,
                                   const struct nftnl_obj *obj,
                                   uint32_t type, uint32_t flags)
@@ -469,26 +385,18 @@ static int nftnl_obj_cmd_snprintf(char *buf, size_t size,
 {
        int ret, remain = size, offset = 0;
 
-       ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                ret = nftnl_obj_snprintf_dflt(buf + offset, remain, obj, type,
                                              flags);
                break;
        case NFTNL_OUTPUT_JSON:
-               ret = nftnl_obj_export(buf + offset, remain, obj, type, flags);
-               break;
        case NFTNL_OUTPUT_XML:
        default:
                return -1;
        }
        SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
-       ret = nftnl_cmd_footer_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        return offset;
 }
 
index 146b06ca91ef763a89f4cac760fd558ddf3fe877..a42d087c95c58b8dc542ff7ed4244dba78cbae2d 100644 (file)
@@ -512,130 +512,6 @@ int nftnl_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_rule *r)
        return 0;
 }
 
-#ifdef JSON_PARSING
-int nftnl_jansson_parse_rule(struct nftnl_rule *r, json_t *tree,
-                          struct nftnl_parse_err *err,
-                          struct nftnl_set_list *set_list)
-{
-       json_t *root, *array;
-       struct nftnl_expr *e;
-       const char *str = NULL;
-       uint64_t uval64;
-       uint32_t uval32;
-       int i, family;
-
-       root = nftnl_jansson_get_node(tree, "rule", err);
-       if (root == NULL)
-               return -1;
-
-       if (nftnl_jansson_node_exist(root, "family")) {
-               if (nftnl_jansson_parse_family(root, &family, err) != 0)
-                       goto err;
-
-               nftnl_rule_set_u32(r, NFTNL_RULE_FAMILY, family);
-       }
-
-       if (nftnl_jansson_node_exist(root, "table")) {
-               str = nftnl_jansson_parse_str(root, "table", err);
-               if (str == NULL)
-                       goto err;
-
-               nftnl_rule_set_str(r, NFTNL_RULE_TABLE, str);
-       }
-
-       if (nftnl_jansson_node_exist(root, "chain")) {
-               str = nftnl_jansson_parse_str(root, "chain", err);
-               if (str == NULL)
-                       goto err;
-
-               nftnl_rule_set_str(r, NFTNL_RULE_CHAIN, str);
-       }
-
-       if (nftnl_jansson_node_exist(root, "handle")) {
-               if (nftnl_jansson_parse_val(root, "handle", NFTNL_TYPE_U64, &uval64,
-                                         err) < 0)
-                       goto err;
-
-               nftnl_rule_set_u64(r, NFTNL_RULE_HANDLE, uval64);
-       }
-
-       if (nftnl_jansson_node_exist(root, "compat_proto") ||
-           nftnl_jansson_node_exist(root, "compat_flags")) {
-               if (nftnl_jansson_parse_val(root, "compat_proto", NFTNL_TYPE_U32,
-                                         &uval32, err) < 0)
-                       goto err;
-
-               nftnl_rule_set_u32(r, NFTNL_RULE_COMPAT_PROTO, uval32);
-
-               if (nftnl_jansson_parse_val(root, "compat_flags", NFTNL_TYPE_U32,
-                                         &uval32, err) < 0)
-                       goto err;
-
-               nftnl_rule_set_u32(r, NFTNL_RULE_COMPAT_FLAGS, uval32);
-       }
-
-       if (nftnl_jansson_node_exist(root, "position")) {
-               if (nftnl_jansson_parse_val(root, "position", NFTNL_TYPE_U64,
-                                         &uval64, err) < 0)
-                       goto err;
-
-               nftnl_rule_set_u64(r, NFTNL_RULE_POSITION, uval64);
-       }
-
-       if (nftnl_jansson_node_exist(root, "id")) {
-               if (nftnl_jansson_parse_val(root, "id", NFTNL_TYPE_U32,
-                                           &uval32, err) < 0)
-                       goto err;
-               nftnl_rule_set_u32(r, NFTNL_RULE_COMPAT_PROTO, uval32);
-       }
-
-       array = json_object_get(root, "expr");
-       if (array == NULL) {
-               err->error = NFTNL_PARSE_EMISSINGNODE;
-               err->node_name = "expr";
-               goto err;
-       }
-
-       for (i = 0; i < json_array_size(array); ++i) {
-
-               e = nftnl_jansson_expr_parse(json_array_get(array, i), err,
-                                          set_list);
-               if (e == NULL)
-                       goto err;
-
-               nftnl_rule_add_expr(r, e);
-       }
-
-       return 0;
-err:
-       return -1;
-}
-#endif
-
-static int nftnl_rule_json_parse(struct nftnl_rule *r, const void *json,
-                              struct nftnl_parse_err *err,
-                              enum nftnl_parse_input input,
-                              struct nftnl_set_list *set_list)
-{
-#ifdef JSON_PARSING
-       json_t *tree;
-       json_error_t error;
-       int ret;
-
-       tree = nftnl_jansson_create_root(json, &error, err, input);
-       if (tree == NULL)
-               return -1;
-
-       ret = nftnl_jansson_parse_rule(r, tree, err, set_list);
-
-       nftnl_jansson_free_root(tree);
-       return ret;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int nftnl_rule_do_parse(struct nftnl_rule *r, enum nftnl_parse_type type,
                             const void *data, struct nftnl_parse_err *err,
                             enum nftnl_parse_input input)
@@ -645,8 +521,6 @@ static int nftnl_rule_do_parse(struct nftnl_rule *r, enum nftnl_parse_type type,
 
        switch (type) {
        case NFTNL_PARSE_JSON:
-               ret = nftnl_rule_json_parse(r, data, &perr, input, NULL);
-               break;
        case NFTNL_PARSE_XML:
        default:
                ret = -1;
@@ -673,43 +547,6 @@ int nftnl_rule_parse_file(struct nftnl_rule *r, enum nftnl_parse_type type,
        return nftnl_rule_do_parse(r, type, fp, err, NFTNL_PARSE_FILE);
 }
 
-static int nftnl_rule_export(char *buf, size_t size,
-                            const struct nftnl_rule *r,
-                            uint32_t type, uint32_t flags)
-{
-       struct nftnl_expr *expr;
-
-       NFTNL_BUF_INIT(b, buf, size);
-
-       nftnl_buf_open(&b, type, RULE);
-
-       if (r->flags & (1 << NFTNL_RULE_FAMILY))
-               nftnl_buf_str(&b, type, nftnl_family2str(r->family), FAMILY);
-       if (r->flags & (1 << NFTNL_RULE_TABLE))
-               nftnl_buf_str(&b, type, r->table, TABLE);
-       if (r->flags & (1 << NFTNL_RULE_CHAIN))
-               nftnl_buf_str(&b, type, r->chain, CHAIN);
-       if (r->flags & (1 << NFTNL_RULE_HANDLE))
-               nftnl_buf_u64(&b, type, r->handle, HANDLE);
-       if (r->flags & (1 << NFTNL_RULE_COMPAT_PROTO))
-               nftnl_buf_u32(&b, type, r->compat.proto, COMPAT_PROTO);
-       if (r->flags & (1 << NFTNL_RULE_COMPAT_FLAGS))
-               nftnl_buf_u32(&b, type, r->compat.flags, COMPAT_FLAGS);
-       if (r->flags & (1 << NFTNL_RULE_POSITION))
-               nftnl_buf_u64(&b, type, r->position, POSITION);
-       if (r->flags & (1 << NFTNL_RULE_ID))
-               nftnl_buf_u32(&b, type, r->id, ID);
-
-       nftnl_buf_expr_open(&b, type);
-       list_for_each_entry(expr, &r->expr_list, head)
-               nftnl_buf_expr(&b, type, flags, expr);
-       nftnl_buf_expr_close(&b, type);
-
-       nftnl_buf_close(&b, type, RULE);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_rule_snprintf_default(char *buf, size_t size,
                                       const struct nftnl_rule *r,
                                       uint32_t type, uint32_t flags)
@@ -795,28 +632,18 @@ static int nftnl_rule_cmd_snprintf(char *buf, size_t size,
 
        inner_flags &= ~NFTNL_OF_EVENT_ANY;
 
-       ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        switch(type) {
        case NFTNL_OUTPUT_DEFAULT:
                ret = nftnl_rule_snprintf_default(buf + offset, remain, r, type,
                                                inner_flags);
+               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                break;
        case NFTNL_OUTPUT_JSON:
-               ret = nftnl_rule_export(buf + offset, remain, r, type,
-                                            inner_flags);
-               break;
        case NFTNL_OUTPUT_XML:
        default:
                return -1;
        }
 
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = nftnl_cmd_footer_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        return offset;
 }
 
index eb49fde582c22e2c9cfbbbfc3364196f5f0777fa..2468bd46cd5d028d5f07f334a28292f468f53a6d 100644 (file)
@@ -45,8 +45,6 @@ struct nftnl_parse_ctx {
        void *data;
 
        /* These fields below are not exposed to the user */
-       json_t *json;
-
        uint32_t format;
        uint32_t set_id;
        struct nftnl_set_list *set_list;
@@ -212,393 +210,14 @@ uint32_t nftnl_ruleset_ctx_get_u32(const struct nftnl_parse_ctx *ctx, uint16_t a
        return ret == NULL ? 0 : *((uint32_t *)ret);
 }
 
-#if defined(JSON_PARSING)
-static void nftnl_ruleset_ctx_set(struct nftnl_parse_ctx *ctx, uint16_t attr,
-                               void *data)
-{
-       switch (attr) {
-       case NFTNL_RULESET_CTX_CMD:
-               ctx->cmd = *((uint32_t *)data);
-               break;
-       case NFTNL_RULESET_CTX_TYPE:
-               ctx->type = *((uint32_t *)data);
-               break;
-       case NFTNL_RULESET_CTX_TABLE:
-               ctx->table = data;
-               break;
-       case NFTNL_RULESET_CTX_CHAIN:
-               ctx->chain = data;
-               break;
-       case NFTNL_RULESET_CTX_RULE:
-               ctx->rule = data;
-               break;
-       case NFTNL_RULESET_CTX_SET:
-               ctx->set = data;
-               break;
-       case NFTNL_RULESET_CTX_DATA:
-               ctx->data = data;
-               break;
-       }
-       ctx->flags |= (1 << attr);
-}
-
-static void nftnl_ruleset_ctx_set_u32(struct nftnl_parse_ctx *ctx, uint16_t attr,
-                                   uint32_t val)
-{
-       nftnl_ruleset_ctx_set(ctx, attr, &val);
-}
-
-static int nftnl_ruleset_parse_tables(struct nftnl_parse_ctx *ctx,
-                                   struct nftnl_parse_err *err)
-{
-       struct nftnl_table *table;
-
-       table = nftnl_table_alloc();
-       if (table == NULL)
-               return -1;
-
-       switch (ctx->format) {
-       case NFTNL_OUTPUT_JSON:
-#ifdef JSON_PARSING
-               if (nftnl_jansson_parse_table(table, ctx->json, err) < 0)
-                       goto err;
-#endif
-               break;
-       case NFTNL_OUTPUT_XML:
-       default:
-               errno = EOPNOTSUPP;
-               goto err;
-       }
-
-       nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE, NFTNL_RULESET_TABLE);
-       nftnl_ruleset_ctx_set(ctx, NFTNL_RULESET_CTX_TABLE, table);
-       if (ctx->cb(ctx) < 0)
-               goto err;
-
-       return 0;
-err:
-       nftnl_table_free(table);
-       return -1;
-}
-
-static int nftnl_ruleset_parse_chains(struct nftnl_parse_ctx *ctx,
-                                   struct nftnl_parse_err *err)
-{
-       struct nftnl_chain *chain;
-
-       chain = nftnl_chain_alloc();
-       if (chain == NULL)
-               return -1;
-
-       switch (ctx->format) {
-       case NFTNL_OUTPUT_JSON:
-#ifdef JSON_PARSING
-               if (nftnl_jansson_parse_chain(chain, ctx->json, err) < 0)
-                       goto err;
-#endif
-               break;
-       case NFTNL_OUTPUT_XML:
-       default:
-               errno = EOPNOTSUPP;
-               goto err;
-       }
-
-       nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE, NFTNL_RULESET_CHAIN);
-       nftnl_ruleset_ctx_set(ctx, NFTNL_RULESET_CTX_CHAIN, chain);
-       if (ctx->cb(ctx) < 0)
-               goto err;
-
-       return 0;
-err:
-       nftnl_chain_free(chain);
-       return -1;
-}
-
-static int nftnl_ruleset_parse_set(struct nftnl_parse_ctx *ctx,
-                                struct nftnl_set *set, uint32_t type,
-                                struct nftnl_parse_err *err)
-{
-       struct nftnl_set *newset;
-
-       nftnl_set_set_u32(set, NFTNL_SET_ID, ctx->set_id++);
-
-       newset = nftnl_set_clone(set);
-       if (newset == NULL)
-               goto err;
-
-       nftnl_set_list_add_tail(newset, ctx->set_list);
-
-       nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE, type);
-       nftnl_ruleset_ctx_set(ctx, NFTNL_RULESET_CTX_SET, set);
-       if (ctx->cb(ctx) < 0)
-               goto err;
-
-       return 0;
-err:
-       return -1;
-}
-
-static int nftnl_ruleset_parse_set_elems(struct nftnl_parse_ctx *ctx,
-                                      struct nftnl_parse_err *err)
-{
-       struct nftnl_set *set;
-
-       set = nftnl_set_alloc();
-       if (set == NULL)
-               return -1;
-
-       switch (ctx->format) {
-       case NFTNL_OUTPUT_JSON:
-#ifdef JSON_PARSING
-               if (nftnl_jansson_parse_elem(set, ctx->json, err) < 0)
-                       goto err;
-#endif
-               break;
-       case NFTNL_OUTPUT_XML:
-       default:
-               errno = EOPNOTSUPP;
-               goto err;
-       }
-
-       if (nftnl_ruleset_parse_set(ctx, set, NFTNL_RULESET_SET_ELEMS, err) < 0)
-               goto err;
-
-       return 0;
-err:
-       nftnl_set_free(set);
-       return -1;
-}
-
-static int nftnl_ruleset_parse_sets(struct nftnl_parse_ctx *ctx,
-                                 struct nftnl_parse_err *err)
-{
-       struct nftnl_set *set;
-
-       set = nftnl_set_alloc();
-       if (set == NULL)
-               return -1;
-
-       switch (ctx->format) {
-       case NFTNL_OUTPUT_JSON:
-#ifdef JSON_PARSING
-               if (nftnl_jansson_parse_set(set, ctx->json, err) < 0)
-                       goto err;
-#endif
-               break;
-       case NFTNL_OUTPUT_XML:
-       default:
-               errno = EOPNOTSUPP;
-               goto err;
-       }
-
-       if (nftnl_ruleset_parse_set(ctx, set, NFTNL_RULESET_SET, err) < 0)
-               goto err;
-
-       return 0;
-err:
-       nftnl_set_free(set);
-       return -1;
-}
-
-static int nftnl_ruleset_parse_rules(struct nftnl_parse_ctx *ctx,
-                                  struct nftnl_parse_err *err)
-{
-       struct nftnl_rule *rule;
-
-       rule = nftnl_rule_alloc();
-       if (rule == NULL)
-               return -1;
-
-       switch (ctx->format) {
-       case NFTNL_OUTPUT_JSON:
-#ifdef JSON_PARSING
-               if (nftnl_jansson_parse_rule(rule, ctx->json, err,
-                                          ctx->set_list) < 0)
-                       goto err;
-#endif
-               break;
-       case NFTNL_OUTPUT_XML:
-       default:
-               errno = EOPNOTSUPP;
-               goto err;
-       }
-
-       nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE, NFTNL_RULESET_RULE);
-       nftnl_ruleset_ctx_set(ctx, NFTNL_RULESET_CTX_RULE, rule);
-       if (ctx->cb(ctx) < 0)
-               goto err;
-
-       return 0;
-err:
-       nftnl_rule_free(rule);
-       return -1;
-}
-#endif
-
-#ifdef JSON_PARSING
-static int nftnl_ruleset_json_parse_ruleset(struct nftnl_parse_ctx *ctx,
-                                         struct nftnl_parse_err *err)
-{
-       json_t *node, *array = ctx->json;
-       int len, i, ret;
-
-       len = json_array_size(array);
-       for (i = 0; i < len; i++) {
-               node = json_array_get(array, i);
-               if (node == NULL) {
-                       errno = EINVAL;
-                       return -1;
-               }
-
-               ctx->json = node;
-               if (nftnl_jansson_node_exist(node, "table"))
-                       ret = nftnl_ruleset_parse_tables(ctx, err);
-               else if (nftnl_jansson_node_exist(node, "chain"))
-                       ret = nftnl_ruleset_parse_chains(ctx, err);
-               else if (nftnl_jansson_node_exist(node, "set"))
-                       ret = nftnl_ruleset_parse_sets(ctx, err);
-               else if (nftnl_jansson_node_exist(node, "rule"))
-                       ret = nftnl_ruleset_parse_rules(ctx, err);
-               else if (nftnl_jansson_node_exist(node, "element"))
-                       ret = nftnl_ruleset_parse_set_elems(ctx, err);
-               else
-                       return -1;
-
-               if (ret < 0)
-                       return ret;
-       }
-
-       if (len == 0 && ctx->cmd == NFTNL_CMD_FLUSH) {
-               nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_TYPE,
-                                       NFTNL_RULESET_RULESET);
-               if (ctx->cb(ctx) < 0)
-                       return -1;
-       }
-
-       return 0;
-}
-
-static int nftnl_ruleset_json_parse_cmd(const char *cmd,
-                                     struct nftnl_parse_err *err,
-                                     struct nftnl_parse_ctx *ctx)
-{
-       uint32_t cmdnum;
-       json_t *nodecmd;
-
-       cmdnum = nftnl_str2cmd(cmd);
-       if (cmdnum == NFTNL_CMD_UNSPEC) {
-               err->error = NFTNL_PARSE_EMISSINGNODE;
-               err->node_name = strdup(cmd);
-               return -1;
-       }
-
-       nftnl_ruleset_ctx_set_u32(ctx, NFTNL_RULESET_CTX_CMD, cmdnum);
-
-       nodecmd = json_object_get(ctx->json, cmd);
-       if (nodecmd == NULL)
-               return 0;
-
-       ctx->json = nodecmd;
-       if (nftnl_ruleset_json_parse_ruleset(ctx, err) != 0)
-               goto err;
-
-       return 0;
-err:
-       return -1;
-}
-#endif
-
-static int nftnl_ruleset_json_parse(const void *json,
-                                 struct nftnl_parse_err *err,
-                                 enum nftnl_parse_input input,
-                                 enum nftnl_parse_type type, void *arg,
-                                 int (*cb)(const struct nftnl_parse_ctx *ctx))
-{
-#ifdef JSON_PARSING
-       json_t *root, *array, *node;
-       json_error_t error;
-       int i, len;
-       const char *key;
-       struct nftnl_parse_ctx ctx = {
-               .cb = cb,
-               .format = type,
-               .flags = 0,
-       };
-
-       ctx.set_list = nftnl_set_list_alloc();
-       if (ctx.set_list == NULL)
-               return -1;
-
-       if (arg != NULL)
-               nftnl_ruleset_ctx_set(&ctx, NFTNL_RULESET_CTX_DATA, arg);
-
-       root = nftnl_jansson_create_root(json, &error, err, input);
-       if (root == NULL)
-               goto err1;
-
-       array = json_object_get(root, "nftables");
-       if (array == NULL) {
-               errno = EINVAL;
-               goto err2;
-       }
-
-       len = json_array_size(array);
-       for (i = 0; i < len; i++) {
-               node = json_array_get(array, i);
-               if (node == NULL) {
-                       errno = EINVAL;
-                       goto err2;
-               }
-               ctx.json = node;
-               key = json_object_iter_key(json_object_iter(node));
-               if (key == NULL)
-                       goto err2;
-
-               if (nftnl_ruleset_json_parse_cmd(key, err, &ctx) < 0)
-                       goto err2;
-       }
-
-       nftnl_set_list_free(ctx.set_list);
-       nftnl_jansson_free_root(root);
-       return 0;
-err2:
-       nftnl_jansson_free_root(root);
-err1:
-       nftnl_set_list_free(ctx.set_list);
-       return -1;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int
-nftnl_ruleset_do_parse(enum nftnl_parse_type type, const void *data,
-                    struct nftnl_parse_err *err, enum nftnl_parse_input input,
-                    void *arg, int (*cb)(const struct nftnl_parse_ctx *ctx))
-{
-       int ret;
-
-       switch (type) {
-       case NFTNL_PARSE_JSON:
-               ret = nftnl_ruleset_json_parse(data, err, input, type, arg, cb);
-               break;
-       case NFTNL_PARSE_XML:
-       default:
-               ret = -1;
-               errno = EOPNOTSUPP;
-               break;
-       }
-
-       return ret;
-}
 
 EXPORT_SYMBOL(nftnl_ruleset_parse_file_cb);
 int nftnl_ruleset_parse_file_cb(enum nftnl_parse_type type, FILE *fp,
                              struct nftnl_parse_err *err, void *data,
                              int (*cb)(const struct nftnl_parse_ctx *ctx))
 {
-       return nftnl_ruleset_do_parse(type, fp, err, NFTNL_PARSE_FILE, data, cb);
+       errno = EOPNOTSUPP;
+       return -1;
 }
 
 EXPORT_SYMBOL(nftnl_ruleset_parse_buffer_cb);
@@ -606,8 +225,8 @@ int nftnl_ruleset_parse_buffer_cb(enum nftnl_parse_type type, const char *buffer
                                struct nftnl_parse_err *err, void *data,
                                int (*cb)(const struct nftnl_parse_ctx *ctx))
 {
-       return nftnl_ruleset_do_parse(type, buffer, err, NFTNL_PARSE_BUFFER, data,
-                                   cb);
+       errno = EOPNOTSUPP;
+       return -1;
 }
 
 static int nftnl_ruleset_cb(const struct nftnl_parse_ctx *ctx)
@@ -675,7 +294,8 @@ EXPORT_SYMBOL(nftnl_ruleset_parse);
 int nftnl_ruleset_parse(struct nftnl_ruleset *r, enum nftnl_parse_type type,
                      const char *data, struct nftnl_parse_err *err)
 {
-       return nftnl_ruleset_parse_buffer_cb(type, data, err, r, nftnl_ruleset_cb);
+       errno = EOPNOTSUPP;
+       return -1;
 }
 
 EXPORT_SYMBOL(nftnl_ruleset_parse_file);
@@ -849,13 +469,6 @@ nftnl_ruleset_do_snprintf(char *buf, size_t size, const struct nftnl_ruleset *rs
        /* dont pass events flags to child calls of _snprintf() */
        inner_flags &= ~NFTNL_OF_EVENT_ANY;
 
-       ret = snprintf(buf + offset, remain, "%s",
-                      nftnl_ruleset_o_opentag(type));
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        if (nftnl_ruleset_is_set(rs, NFTNL_RULESET_TABLELIST) &&
            (!nftnl_table_list_is_empty(rs->table_list))) {
                ret = nftnl_ruleset_snprintf_table(buf + offset, remain, rs,
@@ -905,13 +518,6 @@ nftnl_ruleset_do_snprintf(char *buf, size_t size, const struct nftnl_ruleset *rs
                SNPRINTF_BUFFER_SIZE(ret, remain, offset);
        }
 
-       ret = nftnl_cmd_footer_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = snprintf(buf + offset, remain, "%s",
-                      nftnl_ruleset_o_closetag(type));
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        return offset;
 }
 
@@ -1108,9 +714,6 @@ static int nftnl_ruleset_cmd_fprintf(FILE *fp, const struct nftnl_ruleset *rs,
        ret = fprintf(fp, "%s", nftnl_ruleset_o_opentag(type));
        NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len);
 
-       ret = nftnl_cmd_header_fprintf(fp, cmd, type, flags);
-       NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len);
-
        if ((nftnl_ruleset_is_set(rs, NFTNL_RULESET_TABLELIST)) &&
            (!nftnl_table_list_is_empty(rs->table_list))) {
                ret = nftnl_ruleset_fprintf_tables(fp, rs, type, inner_flags);
@@ -1153,9 +756,6 @@ static int nftnl_ruleset_cmd_fprintf(FILE *fp, const struct nftnl_ruleset *rs,
                NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len);
        }
 
-       ret = nftnl_cmd_footer_fprintf(fp, cmd, type, flags);
-       NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len);
-
        ret = fprintf(fp, "%s", nftnl_ruleset_o_closetag(type));
        NFTNL_FPRINTF_RETURN_OR_FIXLEN(ret, len);
 
index d2a75893ef70df1bf5ae62c7a891c03375478932..74724224b683d35c3b2751278367998300c24e5b 100644 (file)
--- a/src/set.c
+++ b/src/set.c
@@ -569,153 +569,6 @@ int nftnl_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_set *s)
        return 0;
 }
 
-#ifdef JSON_PARSING
-static int nftnl_jansson_parse_set_info(struct nftnl_set *s, json_t *tree,
-                                     struct nftnl_parse_err *err)
-{
-       json_t *root = tree, *array, *json_elem;
-       uint32_t flags, key_type, key_len, data_type, data_len, policy, size;
-       int family, i;
-       const char *name, *table;
-       struct nftnl_set_elem *elem;
-
-       name = nftnl_jansson_parse_str(root, "name", err);
-       if (name == NULL)
-               return -1;
-
-       nftnl_set_set_str(s, NFTNL_SET_NAME, name);
-
-       table = nftnl_jansson_parse_str(root, "table", err);
-       if (table == NULL)
-               return -1;
-
-       nftnl_set_set_str(s, NFTNL_SET_TABLE, table);
-
-       if (nftnl_jansson_parse_family(root, &family, err) == 0)
-               nftnl_set_set_u32(s, NFTNL_SET_FAMILY, family);
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags, err) == 0)
-               nftnl_set_set_u32(s, NFTNL_SET_FLAGS, flags);
-
-       if (nftnl_jansson_parse_val(root, "key_type", NFTNL_TYPE_U32, &key_type,
-                                 err) == 0)
-               nftnl_set_set_u32(s, NFTNL_SET_KEY_TYPE, key_type);
-
-       if (nftnl_jansson_parse_val(root, "key_len", NFTNL_TYPE_U32, &key_len,
-                                 err) == 0)
-               nftnl_set_set_u32(s, NFTNL_SET_KEY_LEN, key_len);
-
-       if (nftnl_jansson_node_exist(root, "data_type")) {
-               if (nftnl_jansson_parse_val(root, "data_type", NFTNL_TYPE_U32,
-                                         &data_type, err) < 0)
-                       return -1;
-
-               nftnl_set_set_u32(s, NFTNL_SET_DATA_TYPE, data_type);
-       }
-
-       if (nftnl_jansson_node_exist(root, "data_len")) {
-               if (nftnl_jansson_parse_val(root, "data_len", NFTNL_TYPE_U32,
-                                         &data_len, err) < 0)
-                       return -1;
-
-               nftnl_set_set_u32(s, NFTNL_SET_DATA_LEN, data_len);
-       }
-
-       if (nftnl_jansson_node_exist(root, "obj_type")) {
-               if (nftnl_jansson_parse_val(root, "obj_type", NFTNL_TYPE_U32,
-                                         &data_type, err) < 0)
-                       return -1;
-
-               nftnl_set_set_u32(s, NFTNL_SET_OBJ_TYPE, data_type);
-       }
-
-       if (nftnl_jansson_node_exist(root, "policy")) {
-               if (nftnl_jansson_parse_val(root, "policy", NFTNL_TYPE_U32,
-                                         &policy, err) < 0)
-                       return -1;
-
-               nftnl_set_set_u32(s, NFTNL_SET_POLICY, policy);
-       }
-
-       if (nftnl_jansson_node_exist(root, "desc_size")) {
-               if (nftnl_jansson_parse_val(root, "desc_size", NFTNL_TYPE_U32,
-                                         &size, err) < 0)
-                       return -1;
-
-               nftnl_set_set_u32(s, NFTNL_SET_DESC_SIZE, size);
-       }
-
-       if (nftnl_jansson_node_exist(root, "set_elem")) {
-               array = json_object_get(root, "set_elem");
-               for (i = 0; i < json_array_size(array); i++) {
-                       elem = nftnl_set_elem_alloc();
-                       if (elem == NULL)
-                               return -1;
-
-                       json_elem = json_array_get(array, i);
-                       if (json_elem == NULL ||
-                           nftnl_jansson_set_elem_parse(elem,
-                                                        json_elem, err) < 0) {
-                               free(elem);
-                               return -1;
-                       }
-
-                       list_add_tail(&elem->head, &s->element_list);
-               }
-
-       }
-
-       return 0;
-}
-
-int nftnl_jansson_parse_set(struct nftnl_set *s, json_t *tree,
-                         struct nftnl_parse_err *err)
-{
-       json_t *root;
-
-       root = nftnl_jansson_get_node(tree, "set", err);
-       if (root == NULL)
-               return -1;
-
-       return nftnl_jansson_parse_set_info(s, root, err);
-}
-
-int nftnl_jansson_parse_elem(struct nftnl_set *s, json_t *tree,
-                          struct nftnl_parse_err *err)
-{
-       json_t *root;
-
-       root = nftnl_jansson_get_node(tree, "element", err);
-       if (root == NULL)
-               return -1;
-
-       return nftnl_jansson_parse_set_info(s, root, err);
-}
-#endif
-
-static int nftnl_set_json_parse(struct nftnl_set *s, const void *json,
-                             struct nftnl_parse_err *err,
-                             enum nftnl_parse_input input)
-{
-#ifdef JSON_PARSING
-       json_t *tree;
-       json_error_t error;
-       int ret;
-
-       tree = nftnl_jansson_create_root(json, &error, err, input);
-       if (tree == NULL)
-               return -1;
-
-       ret = nftnl_jansson_parse_set(s, tree, err);
-       nftnl_jansson_free_root(tree);
-
-       return ret;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int nftnl_set_do_parse(struct nftnl_set *s, enum nftnl_parse_type type,
                            const void *data, struct nftnl_parse_err *err,
                            enum nftnl_parse_input input)
@@ -725,8 +578,6 @@ static int nftnl_set_do_parse(struct nftnl_set *s, enum nftnl_parse_type type,
 
        switch (type) {
        case NFTNL_PARSE_JSON:
-               ret = nftnl_set_json_parse(s, data, &perr, input);
-               break;
        case NFTNL_PARSE_XML:
        default:
                ret = -1;
@@ -754,104 +605,6 @@ int nftnl_set_parse_file(struct nftnl_set *s, enum nftnl_parse_type type,
        return nftnl_set_do_parse(s, type, fp, err, NFTNL_PARSE_FILE);
 }
 
-static int nftnl_set_snprintf_json(char *buf, size_t size,
-                                  const struct nftnl_set *s,
-                                  uint32_t type, uint32_t flags)
-{
-       int remain = size, offset = 0, ret;
-       struct nftnl_set_elem *elem;
-
-       ret = snprintf(buf, remain, "{\"set\":{");
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       if (s->flags & (1 << NFTNL_SET_NAME)) {
-               ret = snprintf(buf + offset, remain, "\"name\":\"%s\"",
-                              s->name);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-       if (s->flags & (1 << NFTNL_SET_TABLE)) {
-               ret = snprintf(buf + offset, remain, ",\"table\":\"%s\"",
-                              s->table);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-       if (s->flags & (1 << NFTNL_SET_FLAGS)) {
-               ret = snprintf(buf + offset, remain, ",\"flags\":%u",
-                              s->set_flags);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-       if (s->flags & (1 << NFTNL_SET_FAMILY)) {
-               ret = snprintf(buf + offset, remain, ",\"family\":\"%s\"",
-                              nftnl_family2str(s->family));
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-       if (s->flags & (1 << NFTNL_SET_KEY_TYPE)) {
-               ret = snprintf(buf + offset, remain, ",\"key_type\":%u",
-                              s->key_type);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-       if (s->flags & (1 << NFTNL_SET_KEY_LEN)) {
-               ret = snprintf(buf + offset, remain, ",\"key_len\":%u",
-                              s->key_len);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-       if(s->flags & (1 << NFTNL_SET_DATA_TYPE)) {
-               ret = snprintf(buf + offset, remain,
-                                 ",\"data_type\":%u", s->data_type);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-       if(s->flags & (1 << NFTNL_SET_DATA_LEN)) {
-               ret = snprintf(buf + offset, remain, ",\"data_len\":%u",
-                              s->data_len);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-       if (s->flags & (1 << NFTNL_SET_OBJ_TYPE)) {
-               ret = snprintf(buf + offset, remain,
-                                 ",\"obj_type\":%u", s->obj_type);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-
-       if (s->flags & (1 << NFTNL_SET_POLICY)) {
-               ret = snprintf(buf + offset, remain, ",\"policy\":%u",
-                              s->policy);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-
-       if (s->flags & (1 << NFTNL_SET_DESC_SIZE)) {
-               ret = snprintf(buf + offset, remain, ",\"desc_size\":%u",
-                              s->desc.size);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-
-       /* Empty set? Skip printinf of elements */
-       if (list_empty(&s->element_list)){
-               ret = snprintf(buf + offset, remain, "}}");
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-               return offset;
-       }
-
-       ret = snprintf(buf + offset, remain, ",\"set_elem\":[");
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       list_for_each_entry(elem, &s->element_list, head) {
-               ret = snprintf(buf + offset, remain, "{");
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-               ret = nftnl_set_elem_snprintf(buf + offset, remain, elem, type,
-                                           flags);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-               ret = snprintf(buf + offset, remain, "},");
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-       /* Overwrite trailing ", " from last set element */
-       offset --;
-
-       ret = snprintf(buf + offset, remain, "]}}");
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       return offset;
-}
-
 static int nftnl_set_snprintf_default(char *buf, size_t size,
                                      const struct nftnl_set *s,
                                      uint32_t type, uint32_t flags)
@@ -918,27 +671,16 @@ static int nftnl_set_cmd_snprintf(char *buf, size_t size,
        /* prevent set_elems to print as events */
        inner_flags &= ~NFTNL_OF_EVENT_ANY;
 
-       ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        switch(type) {
        case NFTNL_OUTPUT_DEFAULT:
                ret = nftnl_set_snprintf_default(buf + offset, remain, s, type,
                                               inner_flags);
-               break;
-       case NFTNL_OUTPUT_JSON:
-               ret = nftnl_set_snprintf_json(buf + offset, remain, s, type,
-                                           inner_flags);
+               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                break;
        default:
                return -1;
        }
 
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = nftnl_cmd_footer_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        return offset;
 }
 
index 1ac53dadbb7581f6ceba0e98839392f4688a83cb..bb8d0464087b6eda2852375734f02b4fb6a53698 100644 (file)
@@ -548,101 +548,20 @@ int nftnl_set_elems_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_set *s)
        return 0;
 }
 
-static int nftnl_set_elem_json_parse(struct nftnl_set_elem *e, const void *json,
-                                  struct nftnl_parse_err *err,
-                                  enum nftnl_parse_input input)
-{
-#ifdef JSON_PARSING
-       json_t *tree;
-       json_error_t error;
-
-       tree = nftnl_jansson_create_root(json, &error, err, input);
-       if (tree == NULL)
-               return -1;
-
-       return nftnl_jansson_set_elem_parse(e, tree, err);
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
-static int
-nftnl_set_elem_do_parse(struct nftnl_set_elem *e, enum nftnl_parse_type type,
-                     const void *data, struct nftnl_parse_err *err,
-                     enum nftnl_parse_input input)
-{
-       int ret;
-
-       switch (type) {
-       case NFTNL_PARSE_JSON:
-               ret = nftnl_set_elem_json_parse(e, data, err, input);
-               break;
-       case NFTNL_PARSE_XML:
-       default:
-               errno = EOPNOTSUPP;
-               ret = -1;
-               break;
-       }
-
-       return ret;
-}
-
 EXPORT_SYMBOL(nftnl_set_elem_parse);
 int nftnl_set_elem_parse(struct nftnl_set_elem *e, enum nftnl_parse_type type,
                       const char *data, struct nftnl_parse_err *err)
 {
-       return nftnl_set_elem_do_parse(e, type, data, err, NFTNL_PARSE_BUFFER);
+       errno = EOPNOTSUPP;
+       return -1;
 }
 
 EXPORT_SYMBOL(nftnl_set_elem_parse_file);
 int nftnl_set_elem_parse_file(struct nftnl_set_elem *e, enum nftnl_parse_type type,
                            FILE *fp, struct nftnl_parse_err *err)
 {
-       return nftnl_set_elem_do_parse(e, type, fp, err, NFTNL_PARSE_FILE);
-}
-
-static int nftnl_set_elem_snprintf_json(char *buf, size_t size,
-                                       const struct nftnl_set_elem *e,
-                                       uint32_t flags)
-{
-       int ret, remain = size, offset = 0, type = -1;
-
-       if (e->flags & (1 << NFTNL_SET_ELEM_FLAGS)) {
-               ret = snprintf(buf, remain, "\"flags\":%u,", e->set_elem_flags);
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-
-       ret = snprintf(buf + offset, remain, "\"key\":{");
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = nftnl_data_reg_snprintf(buf + offset, remain, &e->key,
-                                   NFTNL_OUTPUT_JSON, flags, DATA_VALUE);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = snprintf(buf + offset, remain, "}");
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       if (e->flags & (1 << NFTNL_SET_ELEM_DATA))
-               type = DATA_VALUE;
-       else if (e->flags & (1 << NFTNL_SET_ELEM_CHAIN))
-               type = DATA_CHAIN;
-       else if (e->flags & (1 << NFTNL_SET_ELEM_VERDICT))
-               type = DATA_VERDICT;
-
-       if (type != -1) {
-               ret = snprintf(buf + offset, remain, ",\"data\":{");
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-               ret = nftnl_data_reg_snprintf(buf + offset, remain, &e->data,
-                                           NFTNL_OUTPUT_JSON, flags, type);
-                       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-               ret = snprintf(buf + offset, remain, "}");
-               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-       }
-
-       return offset;
+       errno = EOPNOTSUPP;
+       return -1;
 }
 
 static int nftnl_set_elem_snprintf_default(char *buf, size_t size,
@@ -695,29 +614,18 @@ static int nftnl_set_elem_cmd_snprintf(char *buf, size_t size,
 {
        int ret, remain = size, offset = 0;
 
-       if (type == NFTNL_OUTPUT_XML)
-               return 0;
-
-       ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        switch(type) {
        case NFTNL_OUTPUT_DEFAULT:
                ret = nftnl_set_elem_snprintf_default(buf + offset, remain, e);
+               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                break;
+       case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               ret = nftnl_set_elem_snprintf_json(buf + offset, remain, e,
-                                                  flags);
                break;
        default:
                return -1;
        }
 
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = nftnl_cmd_footer_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        return offset;
 }
 
index e7616f6dddbc6f6cae2456e8e1f5ce2119858ca0..c987c5e7552ad3a8f5522a71b18a9b3915b7368a 100644 (file)
@@ -283,72 +283,14 @@ int nftnl_table_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_table *t)
        return 0;
 }
 
-#ifdef JSON_PARSING
-int nftnl_jansson_parse_table(struct nftnl_table *t, json_t *tree,
-                           struct nftnl_parse_err *err)
-{
-       json_t *root;
-       uint32_t flags, use;
-       const char *str;
-       int family;
-
-       root = nftnl_jansson_get_node(tree, "table", err);
-       if (root == NULL)
-               return -1;
-
-       str = nftnl_jansson_parse_str(root, "name", err);
-       if (str != NULL)
-               nftnl_table_set_str(t, NFTNL_TABLE_NAME, str);
-
-       if (nftnl_jansson_parse_family(root, &family, err) == 0)
-               nftnl_table_set_u32(t, NFTNL_TABLE_FAMILY, family);
-
-       if (nftnl_jansson_parse_val(root, "flags", NFTNL_TYPE_U32, &flags,
-                                 err) == 0)
-               nftnl_table_set_u32(t, NFTNL_TABLE_FLAGS, flags);
-
-       if (nftnl_jansson_parse_val(root, "use", NFTNL_TYPE_U32, &use, err) == 0)
-               nftnl_table_set_u32(t, NFTNL_TABLE_USE, use);
-
-       return 0;
-}
-#endif
-
-static int nftnl_table_json_parse(struct nftnl_table *t, const void *json,
-                               struct nftnl_parse_err *err,
-                               enum nftnl_parse_input input)
-{
-#ifdef JSON_PARSING
-       json_t *tree;
-       json_error_t error;
-       int ret;
-
-       tree = nftnl_jansson_create_root(json, &error, err, input);
-       if (tree == NULL)
-               return -1;
-
-       ret = nftnl_jansson_parse_table(t, tree, err);
-
-       nftnl_jansson_free_root(tree);
-
-       return ret;
-#else
-       errno = EOPNOTSUPP;
-       return -1;
-#endif
-}
-
 static int nftnl_table_do_parse(struct nftnl_table *t, enum nftnl_parse_type type,
                              const void *data, struct nftnl_parse_err *err,
                              enum nftnl_parse_input input)
 {
        int ret;
-       struct nftnl_parse_err perr = {};
 
        switch (type) {
        case NFTNL_PARSE_JSON:
-               ret = nftnl_table_json_parse(t, data, &perr, input);
-               break;
        case NFTNL_PARSE_XML:
        default:
                ret = -1;
@@ -356,9 +298,6 @@ static int nftnl_table_do_parse(struct nftnl_table *t, enum nftnl_parse_type typ
                break;
        }
 
-       if (err != NULL)
-               *err = perr;
-
        return ret;
 }
 
@@ -376,28 +315,6 @@ int nftnl_table_parse_file(struct nftnl_table *t, enum nftnl_parse_type type,
        return nftnl_table_do_parse(t, type, fp, err, NFTNL_PARSE_FILE);
 }
 
-static int nftnl_table_export(char *buf, size_t size,
-                             const struct nftnl_table *t, int type)
-{
-       NFTNL_BUF_INIT(b, buf, size);
-
-       nftnl_buf_open(&b, type, TABLE);
-       if (t->flags & (1 << NFTNL_TABLE_NAME))
-               nftnl_buf_str(&b, type, t->name, NAME);
-       if (t->flags & (1 << NFTNL_TABLE_FAMILY))
-               nftnl_buf_str(&b, type, nftnl_family2str(t->family), FAMILY);
-       if (t->flags & (1 << NFTNL_TABLE_FLAGS))
-               nftnl_buf_u32(&b, type, t->table_flags, FLAGS);
-       if (t->flags & (1 << NFTNL_TABLE_USE))
-               nftnl_buf_u32(&b, type, t->use, USE);
-       if (t->flags & (1 << NFTNL_TABLE_HANDLE))
-               nftnl_buf_u64(&b, type, t->handle, HANDLE);
-
-       nftnl_buf_close(&b, type, TABLE);
-
-       return nftnl_buf_done(&b);
-}
-
 static int nftnl_table_snprintf_default(char *buf, size_t size,
                                        const struct nftnl_table *t)
 {
@@ -412,24 +329,16 @@ static int nftnl_table_cmd_snprintf(char *buf, size_t size,
 {
        int ret, remain = size, offset = 0;
 
-       ret = nftnl_cmd_header_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
        switch (type) {
        case NFTNL_OUTPUT_DEFAULT:
                ret = nftnl_table_snprintf_default(buf + offset, remain, t);
+               SNPRINTF_BUFFER_SIZE(ret, remain, offset);
                break;
        case NFTNL_OUTPUT_XML:
        case NFTNL_OUTPUT_JSON:
-               ret = nftnl_table_export(buf + offset, remain, t, type);
-               break;
        default:
                return -1;
        }
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
-
-       ret = nftnl_cmd_footer_snprintf(buf + offset, remain, cmd, type, flags);
-       SNPRINTF_BUFFER_SIZE(ret, remain, offset);
 
        return offset;
 }
index 5872bb13990f6603127bde10d3fad89fc086b728..556575fcce4d1959e68ba83503c3cc029467852d 100644 (file)
@@ -1,10 +1,8 @@
 include $(top_srcdir)/Make_global.am
 
-EXTRA_DIST =           test-script.sh                  \
-                       jsonfiles
+EXTRA_DIST =           test-script.sh
 
-check_PROGRAMS =       nft-parsing-test                \
-                       nft-table-test                  \
+check_PROGRAMS =       nft-table-test                  \
                        nft-chain-test                  \
                        nft-object-test                 \
                        nft-rule-test                   \
@@ -37,9 +35,6 @@ check_PROGRAMS =      nft-parsing-test                \
                        nft-expr_target-test            \
                        nft-expr_hash-test
 
-nft_parsing_test_SOURCES = nft-parsing-test.c
-nft_parsing_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} ${LIBJSON_LIBS}
-
 nft_table_test_SOURCES = nft-table-test.c
 nft_table_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
diff --git a/tests/jsonfiles/01-table.json b/tests/jsonfiles/01-table.json
deleted file mode 100644 (file)
index 20754f1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"table":{"name":"filter","family":"ip","flags":0,"use":0}}]}]}
diff --git a/tests/jsonfiles/02-table.json b/tests/jsonfiles/02-table.json
deleted file mode 100644 (file)
index 797a00d..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"table":{"name":"filter2","family":"ip6","flags":0,"use":0}}]}]}
diff --git a/tests/jsonfiles/11-chain.json b/tests/jsonfiles/11-chain.json
deleted file mode 100644 (file)
index 5808819..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"chain":{"name":"input","handle":1,"bytes":1375696,"packets":4136,"table":"filter","family":"ip","use":0,"type":"filter","hooknum":"input","prio":0,"policy":"accept"}}]}]}
diff --git a/tests/jsonfiles/12-chain.json b/tests/jsonfiles/12-chain.json
deleted file mode 100644 (file)
index c1c823c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"chain":{"name":"forward","handle":2,"bytes":0,"packets":0,"table":"filter","family":"ip","use":0,"type":"filter","hooknum":"forward","prio":0,"policy":"accept"}}]}]}
diff --git a/tests/jsonfiles/13-chain.json b/tests/jsonfiles/13-chain.json
deleted file mode 100644 (file)
index 22940f9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"chain":{"name":"output","handle":3,"bytes":454786,"packets":2681,"table":"filter","family":"ip","use":0,"type":"filter","hooknum":"output","prio":0,"policy":"accept"}}]}]}
diff --git a/tests/jsonfiles/14-chain.json b/tests/jsonfiles/14-chain.json
deleted file mode 100644 (file)
index 0fb1948..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"chain":{"name":"chain1","handle":4,"bytes":0,"packets":0,"table":"filter","family":"ip","use":0}}]}]}
diff --git a/tests/jsonfiles/20-rule-bitwise.json b/tests/jsonfiles/20-rule-bitwise.json
deleted file mode 100644 (file)
index 0e2e5c6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":20,"expr":[{"type":"bitwise","sreg":1,"dreg":1,"len":4,"mask":{"reg":{"type":"value","len":4,"data0":"0x0000000a"}},"xor":{"reg":{"type":"value","len":4,"data0":"0x00000000"}}}]}}]}]}
diff --git a/tests/jsonfiles/21-rule-byteorder.json b/tests/jsonfiles/21-rule-byteorder.json
deleted file mode 100644 (file)
index 18a33f2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":21,"expr":[{"type":"byteorder","sreg":3,"dreg":4,"op":"hton","len":4,"size":4}]}}]}]}
diff --git a/tests/jsonfiles/22-rule-cmp.json b/tests/jsonfiles/22-rule-cmp.json
deleted file mode 100644 (file)
index c8f91ec..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"forward","handle":22,"expr":[{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":16,"data0":"0x00000000","data1":"0x6e6f6200","data2":"0x2e303164","data3":"0x00393331"}}}]}}]}]}
diff --git a/tests/jsonfiles/23-rule-counter.json b/tests/jsonfiles/23-rule-counter.json
deleted file mode 100644 (file)
index 30d7a06..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":23,"expr":[{"type":"counter","pkts":135,"bytes":21655}]}}]}]}
diff --git a/tests/jsonfiles/24-rule-ct.json b/tests/jsonfiles/24-rule-ct.json
deleted file mode 100644 (file)
index 71783e8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":24,"expr":[{"type":"ct","dreg":1,"key":"state"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x00000008"}}}]}}]}]}
diff --git a/tests/jsonfiles/25-rule-exthdr.json b/tests/jsonfiles/25-rule-exthdr.json
deleted file mode 100644 (file)
index 0f6988c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":25,"expr":[{"type":"exthdr","dreg":1,"exthdr_type":"mh","offset":2,"len":16}]}}]}]}
diff --git a/tests/jsonfiles/26-rule-immediate.json b/tests/jsonfiles/26-rule-immediate.json
deleted file mode 100644 (file)
index 89cd360..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":26,"expr":[{"type":"immediate","dreg":0,"data":{"reg":{"type":"verdict","verdict":"accept"}}}]}}]}]}
diff --git a/tests/jsonfiles/27-rule-limit.json b/tests/jsonfiles/27-rule-limit.json
deleted file mode 100644 (file)
index fdd5358..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":27,"expr":[{"type":"limit","rate":321321,"unit":0}]}}]}]}
diff --git a/tests/jsonfiles/28-rule-log.json b/tests/jsonfiles/28-rule-log.json
deleted file mode 100644 (file)
index 320bf29..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":28,"expr":[{"type":"log","prefix":"test_chain","group":1,"snaplen":0,"qthreshold":0}]}}]}]}
diff --git a/tests/jsonfiles/29-rule-match.json b/tests/jsonfiles/29-rule-match.json
deleted file mode 100644 (file)
index 577c63a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":9,"expr":[{"type":"match","name":"state"},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/30-rule-lookup.json b/tests/jsonfiles/30-rule-lookup.json
deleted file mode 100644 (file)
index 3eed063..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":8,"expr":[{"type":"payload","dreg":1,"offset":12,"len":4,"base":"network"},{"type":"lookup","set":"set0","sreg":1,"dreg":0}]}}]}]}
diff --git a/tests/jsonfiles/31-rule-meta.json b/tests/jsonfiles/31-rule-meta.json
deleted file mode 100644 (file)
index 2c2d681..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":8,"expr":[{"type":"meta","dreg":1,"key":"protocol"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x000003e8"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/32-rule-nat4.json b/tests/jsonfiles/32-rule-nat4.json
deleted file mode 100644 (file)
index 4ac8c87..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":10,"expr":[{"type":"nat","nat_type":"dnat","family":"ip","sreg_addr_min":1,"sreg_addr_max":2,"sreg_proto_min":3,"sreg_proto_max":4}]}}]}]}
diff --git a/tests/jsonfiles/33-rule-nat6.json b/tests/jsonfiles/33-rule-nat6.json
deleted file mode 100644 (file)
index 3e4b2e5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip6","table":"nat","chain":"output","handle":33,"expr":[{"type":"nat","nat_type":"snat","family":"ip6","sreg_addr_min":1,"sreg_addr_max":2,"sreg_proto_min":3,"sreg_proto_max":4,"flags":12}]}}]}]}
diff --git a/tests/jsonfiles/34-rule-payload.json b/tests/jsonfiles/34-rule-payload.json
deleted file mode 100644 (file)
index 127eb0c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":26,"expr":[{"type":"payload","dreg":1,"offset":9,"len":1,"base":"network"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":1,"data0":"0x00000006"}}},{"type":"payload","dreg":1,"offset":2,"len":2,"base":"transport"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":2,"data0":"0x00001600"}}},{"type":"immediate","dreg":0,"data":{"reg":{"type":"verdict","verdict":"accept"}}}]}}]}]}
diff --git a/tests/jsonfiles/35-rule-target.json b/tests/jsonfiles/35-rule-target.json
deleted file mode 100644 (file)
index 4ac72a8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"INPUT","handle":20,"expr":[{"type":"counter","pkts":17,"bytes":4436},{"type":"target","name":"LOG"}]}}]}]}
diff --git a/tests/jsonfiles/36-rule-real.json b/tests/jsonfiles/36-rule-real.json
deleted file mode 100644 (file)
index 65a0d62..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":36,"expr":[{"type":"payload","dreg":1,"offset":12,"len":8,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":8,"data0":"0x0100a8c0","data1":"0x6400a8c0"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/37-rule-real.json b/tests/jsonfiles/37-rule-real.json
deleted file mode 100644 (file)
index cfd1c13..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":37,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}}]}}]}]}
diff --git a/tests/jsonfiles/38-rule-real.json b/tests/jsonfiles/38-rule-real.json
deleted file mode 100644 (file)
index 71123aa..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":38,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}}]}}]}]}
diff --git a/tests/jsonfiles/39-rule-real.json b/tests/jsonfiles/39-rule-real.json
deleted file mode 100644 (file)
index 7b05158..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":39,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"gte","data":{"reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"cmp","sreg":1,"op":"lte","data":{"reg":{"type":"value","len":4,"data0":"0xfa00a8c0"}}}]}}]}]}
diff --git a/tests/jsonfiles/40-rule-real.json b/tests/jsonfiles/40-rule-real.json
deleted file mode 100644 (file)
index 8b1259b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":40,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/41-rule-real.json b/tests/jsonfiles/41-rule-real.json
deleted file mode 100644 (file)
index 675a95c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":41,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0},{"type":"immediate","dreg":0,"data":{"reg":{"type":"verdict","verdict":"drop"}}}]}}]}]}
diff --git a/tests/jsonfiles/42-rule-real.json b/tests/jsonfiles/42-rule-real.json
deleted file mode 100644 (file)
index b3d28d4..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":42,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0},{"type":"log","prefix":"(null)","group":0,"snaplen":0,"qthreshold":0}]}}]}]}
diff --git a/tests/jsonfiles/43-rule-real.json b/tests/jsonfiles/43-rule-real.json
deleted file mode 100644 (file)
index e0da9a8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":43,"expr":[{"type":"payload","dreg":1,"offset":9,"len":1,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":1,"data0":"0x00000006"}}},{"type":"payload","dreg":1,"offset":2,"len":2,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":2,"data0":"0x00001600"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/44-rule-real.json b/tests/jsonfiles/44-rule-real.json
deleted file mode 100644 (file)
index 50dd524..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":44,"expr":[{"type":"payload","dreg":1,"offset":9,"len":1,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":1,"data0":"0x00000006"}}},{"type":"payload","dreg":1,"offset":0,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x16000004"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/45-rule-real.json b/tests/jsonfiles/45-rule-real.json
deleted file mode 100644 (file)
index be08598..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":45,"expr":[{"type":"payload","dreg":1,"offset":12,"len":8,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":8,"data0":"0x0100a8c0","data1":"0x6400a8c0"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/46-rule-real.json b/tests/jsonfiles/46-rule-real.json
deleted file mode 100644 (file)
index 5ea3ca9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":46,"expr":[{"type":"payload","dreg":1,"offset":9,"len":1,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":1,"data0":"0x00000006"}}},{"type":"payload","dreg":1,"offset":0,"len":8,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":8,"data0":"0x16000004","data1":"0x00000000"}}}]}}]}]}
diff --git a/tests/jsonfiles/47-rule-real.json b/tests/jsonfiles/47-rule-real.json
deleted file mode 100644 (file)
index 6e9d084..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":47,"expr":[{"type":"payload","dreg":1,"offset":9,"len":1,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":1,"data0":"0x00000006"}}},{"type":"payload","dreg":1,"offset":0,"len":8,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":8,"data0":"0x16000004","data1":"0x00000000"}}}]}}]}]}
diff --git a/tests/jsonfiles/48-rule-real.json b/tests/jsonfiles/48-rule-real.json
deleted file mode 100644 (file)
index 6387e94..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":48,"expr":[{"type":"meta","dreg":1,"key":"len"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x000003e8"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/49-rule-real.json b/tests/jsonfiles/49-rule-real.json
deleted file mode 100644 (file)
index e1c84d2..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":49,"expr":[{"type":"meta","dreg":1,"key":"mark"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x00000000"}}},{"type":"counter","pkts":55,"bytes":11407}]}}]}]}
diff --git a/tests/jsonfiles/50-rule-real.json b/tests/jsonfiles/50-rule-real.json
deleted file mode 100644 (file)
index 21de049..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":50,"expr":[{"type":"meta","dreg":1,"key":"iif"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x00000001"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/51-rule-real.json b/tests/jsonfiles/51-rule-real.json
deleted file mode 100644 (file)
index 46afd76..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":51,"expr":[{"type":"meta","dreg":1,"key":"iifname"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":16,"data0":"0x00000000","data1":"0x00000000","data2":"0x65000000","data3":"0x00306874"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/52-rule-real.json b/tests/jsonfiles/52-rule-real.json
deleted file mode 100644 (file)
index e64fe80..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":52,"expr":[{"type":"meta","dreg":1,"key":"oif"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x00000001"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/53-rule-real.json b/tests/jsonfiles/53-rule-real.json
deleted file mode 100644 (file)
index 910a467..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":53,"expr":[{"type":"meta","dreg":1,"key":"oifname"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":16,"data0":"0x00000000","data1":"0x00000000","data2":"0x65000000","data3":"0x00306874"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/54-rule-real.json b/tests/jsonfiles/54-rule-real.json
deleted file mode 100644 (file)
index f271d83..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":54,"expr":[{"type":"meta","dreg":1,"key":"skuid"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x000003e8"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/55-rule-real.json b/tests/jsonfiles/55-rule-real.json
deleted file mode 100644 (file)
index f36ebe5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":55,"expr":[{"type":"meta","dreg":1,"key":"skgid"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x000003e8"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/56-rule-real.json b/tests/jsonfiles/56-rule-real.json
deleted file mode 100644 (file)
index 408b653..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":56,"expr":[{"type":"meta","dreg":1,"key":"secmark"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x00000000"}}},{"type":"counter","pkts":55,"bytes":11407}]}}]}]}
diff --git a/tests/jsonfiles/57-rule-real.json b/tests/jsonfiles/57-rule-real.json
deleted file mode 100644 (file)
index fc8a67a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":57,"expr":[{"type":"meta","dreg":1,"key":"len"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x000003e8"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/58-rule-real.json b/tests/jsonfiles/58-rule-real.json
deleted file mode 100644 (file)
index abb90d5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":58,"expr":[{"type":"meta","dreg":1,"key":"protocol"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":2,"data0":"0x00000008"}}},{"type":"counter","pkts":55,"bytes":11407}]}}]}]}
diff --git a/tests/jsonfiles/59-rule-real.json b/tests/jsonfiles/59-rule-real.json
deleted file mode 100644 (file)
index ffe2288..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":59,"expr":[{"type":"meta","dreg":1,"key":"mark"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x00000000"}}},{"type":"counter","pkts":55,"bytes":11407}]}}]}]}
diff --git a/tests/jsonfiles/60-rule-real.json b/tests/jsonfiles/60-rule-real.json
deleted file mode 100644 (file)
index 9ec79cf..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":60,"expr":[{"type":"meta","dreg":1,"key":"iif"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x00000001"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/61-rule-real.json b/tests/jsonfiles/61-rule-real.json
deleted file mode 100644 (file)
index fd35d2c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":61,"expr":[{"type":"meta","dreg":1,"key":"iifname"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":16,"data0":"0x00000000","data1":"0x00000000","data2":"0x65000000","data3":"0x00306874"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/62-set.json b/tests/jsonfiles/62-set.json
deleted file mode 100644 (file)
index 616eabe..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"set":{"name":"set0","table":"filter","flags":3,"family":"ip","key_type":12,"key_len":2,"set_elem":[{"flags":0,"key":{"reg":{"type":"value","len":2,"data0":"0x00001700"}}},{"flags":0,"key":{"reg":{"type":"value","len":2,"data0":"0x00001600"}}}]}}]}]}
diff --git a/tests/jsonfiles/63-set.json b/tests/jsonfiles/63-set.json
deleted file mode 100644 (file)
index 02aa5fb..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"set":{"name":"map0","table":"f","flags":11,"family":"ip","key_type":12,"key_len":2,"data_type":4294967040,"data_len":16,"set_elem":[{"flags":0,"key":{"reg":{"type":"value","len":2,"data0":"0x00001700"}},"data":{"reg":{"type":"verdict","verdict":"goto","chain":"o"}}},{"flags":0,"key":{"reg":{"type":"value","len":2,"data0":"0x00001600"}},"data":{"reg":{"type":"verdict","verdict":"accept"}}}]}}]}]}
diff --git a/tests/jsonfiles/64-ruleset.json b/tests/jsonfiles/64-ruleset.json
deleted file mode 100644 (file)
index 54e27c0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"table":{"name":"filter","family":"ip","flags":0,"use":0}},{"table":{"name":"filter2","family":"ip6","flags":0,"use":0}},{"chain":{"name":"input","handle":1,"bytes":10681449,"packets":16216,"table":"filter","family":"ip","use":0,"type":"filter","hooknum":"input","prio":0,"policy":"accept"}},{"chain":{"name":"forward","handle":2,"bytes":0,"packets":0,"table":"filter","family":"ip","use":0,"type":"filter","hooknum":"forward","prio":0,"policy":"accept"}},{"chain":{"name":"output","handle":3,"bytes":2375830,"packets":15184,"table":"filter","family":"ip","use":0,"type":"filter","hooknum":"output","prio":0,"policy":"accept"}},{"chain":{"name":"chain1","handle":4,"bytes":0,"packets":0,"table":"filter","family":"ip","use":0}},{"set":{"name":"set0","table":"filter","flags":3,"family":"ip","key_type":12,"key_len":2}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":6,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0},{"type":"immediate","dreg":0,"data":{"reg":{"type":"verdict","verdict":"drop"}}}]}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":9,"expr":[{"type":"payload","dreg":1,"offset":9,"len":1,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":1,"data0":"0x00000006"}}},{"type":"payload","dreg":1,"offset":2,"len":2,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":2,"data0":"0x00001600"}}},{"type":"counter","pkts":0,"bytes":0}]}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":10,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0}]}},{"rule":{"family":"ip","table":"filter","chain":"output","handle":11,"expr":[{"type":"payload","dreg":1,"offset":16,"len":4,"base":"link"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x0100a8c0"}}},{"type":"counter","pkts":0,"bytes":0},{"type":"immediate","dreg":0,"data":{"reg":{"type":"verdict","verdict":"drop"}}}]}}]}]}
diff --git a/tests/jsonfiles/65-rule-meta-target.json b/tests/jsonfiles/65-rule-meta-target.json
deleted file mode 100644 (file)
index ab4e40c..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"output","handle":1,"expr":[{"type":"meta","key":"mark","sreg":1},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":4,"data0":"0x000003e8"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/jsonfiles/66-rule-queue.json b/tests/jsonfiles/66-rule-queue.json
deleted file mode 100644 (file)
index 69a2eee..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":43,"expr":[{"type":"queue","num":4,"total":2,"flags":0}]}}]}]}
diff --git a/tests/jsonfiles/67-rule-queue.json b/tests/jsonfiles/67-rule-queue.json
deleted file mode 100644 (file)
index 0471a98..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":44,"position":43,"expr":[{"type":"queue","num":4,"total":2,"flags":3}]}}]}]}
diff --git a/tests/jsonfiles/68-rule-masq.json b/tests/jsonfiles/68-rule-masq.json
deleted file mode 100644 (file)
index e8f2a58..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip6","table":"nat","chain":"postrouting","handle":4,"expr":[{"type":"masq","flags":12}]}}]}]}
diff --git a/tests/jsonfiles/69-rule-redir.json b/tests/jsonfiles/69-rule-redir.json
deleted file mode 100644 (file)
index d0318f0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip6","table":"nat","chain":"prerouting","handle":4,"expr":[{"type":"redir"}]}}]}]}
diff --git a/tests/jsonfiles/70-rule-real.json b/tests/jsonfiles/70-rule-real.json
deleted file mode 100644 (file)
index b38947f..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"nftables":[{"add":[{"rule":{"family":"ip","table":"filter","chain":"input","handle":2,"expr":[{"type":"payload","dreg":1,"offset":9,"len":1,"base":"network"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":1,"data0":"0x00000006"}}},{"type":"payload","dreg":1,"offset":2,"len":2,"base":"transport"},{"type":"cmp","sreg":1,"op":"eq","data":{"reg":{"type":"value","len":2,"data0":"0x00001600"}}},{"type":"counter","pkts":0,"bytes":0}]}}]}]}
diff --git a/tests/nft-parsing-test.c b/tests/nft-parsing-test.c
deleted file mode 100644 (file)
index d25a73e..0000000
+++ /dev/null
@@ -1,283 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dirent.h>
-#include <limits.h>
-#include <errno.h>
-#include <getopt.h>
-
-#include <libmnl/libmnl.h> /*nlmsghdr*/
-#include <libnftnl/ruleset.h>
-#include <libnftnl/table.h>
-#include <libnftnl/chain.h>
-#include <libnftnl/rule.h>
-#include <libnftnl/set.h>
-
-enum {
-       TEST_XML_RULESET,
-       TEST_JSON_RULESET,
-};
-
-static bool update = false;
-
-static void print_detail_error(char *a, char *b)
-{
-       int i;
-       int from = -1;
-
-       for (i = 0; i < strlen(b); i++) {
-               if (from == -1 && a[i] != b[i]) {
-                       from = i;
-                       break;
-
-               }
-       }
-
-       if (from != -1) {
-               int k = from - 10;
-
-               if (k < 0)
-                       k = 0;
-
-               fprintf(stderr, "from file:     ");
-               for (i = k; i < from + 10; i++)
-                       fprintf(stderr, "%c", a[i]);
-
-               fprintf(stderr, "\nfrom snprintf: ");
-               for (i = k; i < from + 10; i++)
-                       fprintf(stderr, "%c", b[i]);
-
-               /* Don't look twice below this comment ;-) */
-               fprintf(stderr, "\n               ");
-               for (i = k; i < from + 10; i++) {
-                       if (i == from)
-                               fprintf(stderr, "^");
-                       else
-                               fprintf(stderr, " ");
-               }
-               fprintf(stderr, "\n");
-       }
-}
-
-static int compare_test(uint32_t type, struct nftnl_ruleset *rs,
-                       const char *filename, FILE *fp)
-{
-       char orig[4096];
-       char out[4096];
-
-       switch (type) {
-       case TEST_XML_RULESET:
-               nftnl_ruleset_snprintf(out, sizeof(out), rs,
-                                    NFTNL_OUTPUT_XML, NFTNL_OF_EVENT_NEW);
-               break;
-       case TEST_JSON_RULESET:
-               nftnl_ruleset_snprintf(out, sizeof(out), rs,
-                                    NFTNL_OUTPUT_JSON, NFTNL_OF_EVENT_NEW);
-               break;
-       default:
-               errno = EINVAL;
-               return -1;
-       }
-
-       rewind(fp);
-       fgets(orig, sizeof(orig), fp);
-
-       if (strncmp(orig, out, strlen(out)) == 0) {
-               if (update)
-                       printf("%s: No changes to update\n", filename);
-               return 0;
-       }
-       if (update) {
-               FILE *fout;
-               printf("%s: Updating test file\n", filename);
-               fout = fopen(filename, "w");
-               if (fout == NULL) {
-                       printf("unable to open file %s: %s\n", filename,
-                       strerror(errno));
-                       return -1;
-               }
-               fprintf(fout, "%s\n", out);
-               fclose(fout);
-               return 0;
-       }
-
-       printf("validating %s: ", filename);
-       printf("\033[31mFAILED\e[0m\n");
-       print_detail_error(orig, out);
-       return -1;
-}
-
-static int test_json(const char *filename, struct nftnl_parse_err *err)
-{
-       int ret = -1;
-       struct nftnl_ruleset *rs;
-       FILE *fp;
-
-       fp = fopen(filename, "r");
-       if (fp == NULL) {
-               printf("unable to open file %s: %s\n", filename,
-                      strerror(errno));
-               return -1;
-       }
-
-       rs = nftnl_ruleset_alloc();
-       if (rs == NULL) {
-               perror("nftnl_ruleset_alloc");
-               return -1;
-       }
-
-       if (nftnl_ruleset_parse_file(rs, NFTNL_PARSE_JSON, fp, err) == 0)
-               ret = compare_test(TEST_JSON_RULESET, rs, filename, fp);
-       else
-               goto failparsing;
-
-       nftnl_ruleset_free(rs);
-       fclose(fp);
-
-       return ret;
-
-failparsing:
-       fclose(fp);
-       printf("parsing %s: ", filename);
-       printf("\033[31mFAILED\e[0m (%s)\n", strerror(errno));
-       nftnl_parse_perror("Reason", err);
-       return -1;
-}
-
-static int execute_test(const char *dir_name)
-{
-       DIR *d;
-       struct dirent *dent;
-       char path[PATH_MAX];
-       int ret = 0, exit_code = 0;
-       struct nftnl_parse_err *err;
-
-       d = opendir(dir_name);
-       if (d == NULL) {
-               perror("opendir");
-               exit(EXIT_FAILURE);
-       }
-
-       err = nftnl_parse_err_alloc();
-       if (err == NULL) {
-               perror("error");
-               exit(EXIT_FAILURE);
-       }
-
-       while ((dent = readdir(d)) != NULL) {
-               int len = strlen(dent->d_name);
-
-               if (strcmp(dent->d_name, ".") == 0 ||
-                   strcmp(dent->d_name, "..") == 0)
-                       continue;
-
-               snprintf(path, sizeof(path), "%s/%s", dir_name, dent->d_name);
-
-               if (strcmp(&dent->d_name[len-5], ".json") == 0) {
-                       if ((ret = test_json(path, err)) == 0) {
-                               if (!update) {
-                                       printf("parsing and validating %s: ",
-                                              path);
-                                       printf("\033[32mOK\e[0m\n");
-                               }
-                       }
-                       exit_code += ret;
-               }
-       }
-
-       closedir(d);
-       nftnl_parse_err_free(err);
-
-       if (exit_code != 0)
-               exit(EXIT_FAILURE);
-
-       return 0;
-}
-
-static int execute_test_file(const char *filename)
-{
-       char path[PATH_MAX];
-       struct nftnl_parse_err *err;
-       int ret = 0, len;
-
-       err = nftnl_parse_err_alloc();
-       if (err == NULL) {
-               perror("error");
-               exit(EXIT_FAILURE);
-       }
-
-       snprintf(path, sizeof(path), "%s", filename);
-
-       len = strlen(filename);
-       if (strcmp(&filename[len-5], ".json") == 0) {
-               if ((ret = test_json(path, err)) == 0) {
-                       if (!update) {
-                               printf("parsing and validating %s: ",
-                                      path);
-                               printf("\033[32mOK\e[0m\n");
-                       }
-               }
-               nftnl_parse_err_free(err);
-               exit(EXIT_FAILURE);
-       }
-
-       nftnl_parse_err_free(err);
-
-       return 0;
-}
-
-static void show_help(const char *name)
-{
-       printf(
-"Usage: %s [option]\n"
-"\n"
-"Options:\n"
-"  -d/--dir <directory>                Check test files from <directory>.\n"
-"  -u/--update <directory>     Update test files from <directory>.\n"
-"  -f/--file <file>            Check test file <file>\n"
-"\n",
-              name);
-}
-
-int main(int argc, char *argv[])
-{
-       int val;
-       int ret = 0;
-       int option_index = 0;
-       static struct option long_options[] = {
-               { "dir", required_argument, 0, 'd' },
-               { "update", required_argument, 0, 'u' },
-               { "file", required_argument, 0, 'f' },
-               { 0 }
-       };
-
-       if (argc != 3) {
-               show_help(argv[0]);
-               exit(EXIT_FAILURE);
-       }
-
-       while (1) {
-               val = getopt_long(argc, argv, "d:u:f:", long_options,
-                                 &option_index);
-
-               if (val == -1)
-                       break;
-
-               switch (val) {
-               case 'd':
-                       ret = execute_test(optarg);
-                       break;
-               case 'u':
-                       update = true;
-                       ret = execute_test(optarg);
-                       break;
-               case 'f':
-                       ret = execute_test_file(optarg);
-                       break;
-               default:
-                       show_help(argv[0]);
-                       break;
-               }
-       }
-       return ret;
-}
index 2bd7ef0e6716a6fee90e8ecc04cf827d5cc3ba71..83dbda228abc0145744e99949d213b8c9a855a3c 100755 (executable)
@@ -29,4 +29,3 @@
 ./nft-set-test
 ./nft-table-test
 ./nft-object-test
-./nft-parsing-test -d jsonfiles