summaryrefslogtreecommitdiffstats
path: root/src/set_elem.c
diff options
context:
space:
mode:
authorAna Rey <anarey@gmail.com>2014-06-11 17:50:49 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2014-06-11 19:43:36 +0200
commit5e90b0df344b9b57f841b312893791c066ba382a (patch)
treee3f883ff92aab99b29514466fbafc85496b60dec /src/set_elem.c
parentcbb40e407ed32c91a4d1d84eb7ad83401ce569c9 (diff)
src: set: Do not print unset values in json
It changes the parse and the snprint functions to omit unset values. This json file is gotten for a set: { "set": { "name": "mi6set3", "table": "test6", "flags": "0", "family": "unknown", "key_type": "0", "key_len": "0", "set_elem": [ { "flags": "0", "key": { "data_reg": { "type": "value", "len": "16", "data0": "0x000080fe", "data1": "0x00000000", "data2": "0xffb30202", "data3": "0x89001efe" Now, This json file is gotten for a set without unset elements. { "set": { "name": "mi6set3", "table": "test6", "family": "unknown", "set_elem": [ { "key": { "data_reg": { "type": "value", "len": "16", "data0": "0x000080fe", "data1": "0x00000000", "data2": "0xffb30202", "data3": "0x89001efe" [ Note: These fields are unset when they are obtained from the set element information --pablo. ] Signed-off-by: Ana Rey <anarey@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/set_elem.c')
-rw-r--r--src/set_elem.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/set_elem.c b/src/set_elem.c
index d954cb8..3b27317 100644
--- a/src/set_elem.c
+++ b/src/set_elem.c
@@ -493,17 +493,19 @@ static int nft_set_elem_snprintf_json(char *buf, size_t size,
{
int ret, len = size, offset = 0, type = -1;
- ret = snprintf(buf, len, "\"flags\":%u", e->set_elem_flags);
- SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+ if (e->flags & (1 << NFT_SET_ELEM_ATTR_FLAGS)) {
+ ret = snprintf(buf, len, "\"flags\":%u,", e->set_elem_flags);
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+ }
- ret = snprintf(buf+offset, len, ",\"key\":{");
+ ret = snprintf(buf + offset, len, "\"key\":{");
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
- ret = nft_data_reg_snprintf(buf+offset, len, &e->key,
+ ret = nft_data_reg_snprintf(buf + offset, len, &e->key,
NFT_OUTPUT_JSON, flags, DATA_VALUE);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
- ret = snprintf(buf+offset, len, "}");
+ ret = snprintf(buf + offset, len, "}");
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
if (e->flags & (1 << NFT_SET_ELEM_ATTR_DATA))
@@ -514,14 +516,14 @@ static int nft_set_elem_snprintf_json(char *buf, size_t size,
type = DATA_VERDICT;
if (type != -1) {
- ret = snprintf(buf+offset, len, ",\"data\":{");
+ ret = snprintf(buf + offset, len, ",\"data\":{");
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
- ret = nft_data_reg_snprintf(buf+offset, len, &e->data,
- NFT_OUTPUT_JSON, flags, type);
+ ret = nft_data_reg_snprintf(buf + offset, len, &e->data,
+ NFT_OUTPUT_JSON, flags, type);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
- ret = snprintf(buf+offset, len, "}");
+ ret = snprintf(buf + offset, len, "}");
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}