diff options
author | Phil Sutter <phil@nwl.cc> | 2018-10-24 12:35:03 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-10-24 12:55:13 +0200 |
commit | 0eb1b3f9a83dfbe2f3001fd3d9cec497a352b9af (patch) | |
tree | ba1d51a8a95fe13a191ffcb8a1fa08681e9ebec3 /src/parser_json.c | |
parent | eff35932059569d2a36a14dd911091c0bec00032 (diff) |
json: Fix osf ttl support
Having to use numerical values for ttl property in JSON is not
practical as these values are arbitrary and meaningful only in
netfilter. Instead align JSON output/input with standard API, accepting
names for TTL matching strategy.
Also add missing documentation in libnftables-json man page and fix JSON
equivalent in tests/py.
Fixes: 03eafe098d5ee ("osf: add ttl option support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/parser_json.c')
-rw-r--r-- | src/parser_json.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/parser_json.c b/src/parser_json.c index fc0dc9a9..46a02fe1 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -375,14 +375,25 @@ static struct expr *json_parse_meta_expr(struct json_ctx *ctx, static struct expr *json_parse_osf_expr(struct json_ctx *ctx, const char *type, json_t *root) { - const char *key; - uint8_t ttl; + const char *key, *ttl; + uint8_t ttlval = 0; - if (json_unpack_err(ctx, root, "{s:i, s:s}", "ttl", ttl,"key", &key)) + if (json_unpack_err(ctx, root, "{s:s}", "key", &key)) return NULL; + if (!json_unpack(root, "{s:s}", "ttl", &ttl)) { + if (!strcmp(ttl, "loose")) { + ttlval = 1; + } else if (!strcmp(ttl, "skip")) { + ttlval = 2; + } else { + json_error(ctx, "Invalid osf ttl option '%s'.", ttl); + return NULL; + } + } + if (!strcmp(key, "name")) - return osf_expr_alloc(int_loc, ttl); + return osf_expr_alloc(int_loc, ttlval); json_error(ctx, "Invalid osf key value."); return NULL; |