summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAna Rey <anarey@gmail.com>2014-06-24 19:14:17 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2014-06-24 19:16:15 +0200
commit7610b6c4972fdd620102c8c67d7395b30bcce094 (patch)
tree868d2f72806ae2e52e6d8457bca1d12b3bc319be /src
parent9c6b9f946e0c84a79be9dc868e2df10bd2a207ba (diff)
expr: lookup: Do not print unset values in json file
It changes the parse functions to omit unset values. Signed-off-by: Ana Rey <anarey@gmail.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r--src/expr/lookup.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/expr/lookup.c b/src/expr/lookup.c
index d0d81cb..3f77228 100644
--- a/src/expr/lookup.c
+++ b/src/expr/lookup.c
@@ -164,23 +164,17 @@ nft_rule_expr_lookup_json_parse(struct nft_rule_expr *e, json_t *root,
{
#ifdef JSON_PARSING
const char *set_name;
- int32_t reg;
+ uint32_t sreg, dreg;
set_name = nft_jansson_parse_str(root, "set", err);
- if (set_name == NULL)
- return -1;
-
- nft_rule_expr_set_str(e, NFT_EXPR_LOOKUP_SET, set_name);
-
- if (nft_jansson_parse_reg(root, "sreg", NFT_TYPE_U32, &reg, err) < 0)
- return -1;
-
- nft_rule_expr_set_u32(e, NFT_EXPR_LOOKUP_SREG, reg);
+ if (set_name != NULL)
+ nft_rule_expr_set_str(e, NFT_EXPR_LOOKUP_SET, set_name);
- if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, &reg, err) < 0)
- return -1;
+ if (nft_jansson_parse_reg(root, "sreg", NFT_TYPE_U32, &sreg, err) == 0)
+ nft_rule_expr_set_u32(e, NFT_EXPR_LOOKUP_SREG, sreg);
- nft_rule_expr_set_u32(e, NFT_EXPR_LOOKUP_DREG, reg);
+ if (nft_jansson_parse_reg(root, "dreg", NFT_TYPE_U32, &dreg, err) == 0)
+ nft_rule_expr_set_u32(e, NFT_EXPR_LOOKUP_DREG, dreg);
return 0;
#else
@@ -224,19 +218,25 @@ nft_rule_expr_lookup_snprintf_json(char *buf, size_t size,
int len = size, offset = 0, ret;
struct nft_expr_lookup *l = nft_expr_data(e);
- ret = snprintf(buf, len, "\"set\":\"%s\",\"sreg\":%u",
- l->set_name, l->sreg);
- SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
-
+ if (e->flags & (1 << NFT_EXPR_LOOKUP_SET)) {
+ ret = snprintf(buf, len, "\"set\":\"%s\",", l->set_name);
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+ }
+ if (e->flags & (1 << NFT_EXPR_LOOKUP_SREG)) {
+ ret = snprintf(buf + offset, len, "\"sreg\":%u,", l->sreg);
+ SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
+ }
if (e->flags & (1 << NFT_EXPR_LOOKUP_DREG)) {
- ret = snprintf(buf+offset, len, ",\"dreg\":%u", l->dreg);
+ ret = snprintf(buf + offset, len, "\"dreg\":%u,", l->dreg);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
}
+ /* Remove the last comma characther */
+ if (offset > 0)
+ offset--;
return offset;
}
-
static int
nft_rule_expr_lookup_snprintf_xml(char *buf, size_t size,
struct nft_rule_expr *e)