]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
json: Support sets' auto-merge option
authorPhil Sutter <phil@nwl.cc>
Wed, 31 Jan 2024 16:30:24 +0000 (17:30 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Wed, 22 Jan 2025 23:41:54 +0000 (00:41 +0100)
commit 0021d264d975ac7db1ed32699487f95b41e4c2bf upstream.

If enabled, list the option as additional attribute with boolean value.

Fixes: e70354f53e9f6 ("libnftables: Implement JSON output support")
Closes: https://bugzilla.netfilter.org/show_bug.cgi?id=1734
Signed-off-by: Phil Sutter <phil@nwl.cc>
doc/libnftables-json.adoc
src/json.c
src/parser_json.c

index d985149a0af357680ae9ce5835768974a9dadcb1..6f86d149a8eb5ca7fbcacfb9194e7ae06bdce7fe 100644 (file)
@@ -312,7 +312,8 @@ ____
        "elem":* 'SET_ELEMENTS'*,
        "timeout":* 'NUMBER'*,
        "gc-interval":* 'NUMBER'*,
-       "size":* 'NUMBER'
+       "size":* 'NUMBER'*,
+       "auto-merge":* 'BOOLEAN'
 *}}*
 
 *{ "map": {
@@ -327,7 +328,8 @@ ____
        "elem":* 'SET_ELEMENTS'*,
        "timeout":* 'NUMBER'*,
        "gc-interval":* 'NUMBER'*,
-       "size":* 'NUMBER'
+       "size":* 'NUMBER'*,
+       "auto-merge":* 'BOOLEAN'
 *}}*
 
 'SET_TYPE' := 'STRING' | *[* 'SET_TYPE_LIST' *]*
@@ -366,6 +368,8 @@ that they translate a unique key to a value.
        Garbage collector interval in seconds.
 *size*::
        Maximum number of elements supported.
+*auto-merge*::
+       Automatic merging of adjacent/overlapping set elements in interval sets.
 
 ==== TYPE
 The set type might be a string, such as *"ipv4_addr"* or an array
index 705669dba91282006ece1ffcba8f0d5c824527a3..727700b85075ffee57480941424ca1cbcf5b9951 100644 (file)
@@ -184,6 +184,8 @@ static json_t *set_print_json(struct output_ctx *octx, const struct set *set)
                tmp = json_pack("i", set->gc_int / 1000);
                json_object_set_new(root, "gc-interval", tmp);
        }
+       if (set->automerge)
+               json_object_set_new(root, "auto-merge", json_true());
 
        if (!nft_output_terse(octx) && set->init && set->init->size > 0) {
                json_t *array = json_array();
index f2393588f5618155dba7db7836e877a8a5cb2567..122dfbfe58b72f2fa2caf994869561a5abbbe05c 100644 (file)
@@ -3274,6 +3274,7 @@ static struct cmd *json_parse_cmd_add_set(struct json_ctx *ctx, json_t *root,
        if (!json_unpack(root, "{s:i}", "gc-interval", &set->gc_int))
                set->gc_int *= 1000;
        json_unpack(root, "{s:i}", "size", &set->desc.size);
+       json_unpack(root, "{s:b}", "auto-merge", &set->automerge);
 
        if (!json_unpack(root, "{s:o}", "stmt", &stmt_json))
                json_parse_set_stmt_list(ctx, &set->stmt_list, stmt_json);