path: root/src/json.c
diff options
authorPablo Neira Ayuso <>2018-10-24 17:37:47 +0200
committerPablo Neira Ayuso <>2018-10-29 15:07:34 +0100
commita42d2865bc7e96fe63276e22acd523d996aaf0a4 (patch)
treeb0779465bba8cf7562628ae884278fed73963362 /src/json.c
parentf27fc14cbd3097e98c4d3549ff93c9284134b866 (diff)
src: Revert --literal, add -S/--service
This is a partial revert of b0f6a45b25dd1 ("src: add --literal option") which was added during the development cycle before 0.9.1 is released. After looking at patch: that allows to print priority, uid, gid and protocols as numerics, I decided to revisit this to provide individual options to turn on literal printing. What I'm proposing is to provide a good default for everyone, and provide options to turn on literal/numeric printing. This patch adds nft_ctx_output_{set,get}_flags() and define two flags to enable reverse DNS lookups and to print ports as service names. This patch introduces -S/--services, to print service names as per /etc/services. Acked-by: Phil Sutter <> Signed-off-by: Pablo Neira Ayuso <>
Diffstat (limited to 'src/json.c')
1 files changed, 4 insertions, 3 deletions
diff --git a/src/json.c b/src/json.c
index f08a3b64..5c426ce7 100644
--- a/src/json.c
+++ b/src/json.c
@@ -444,13 +444,14 @@ json_t *relational_expr_json(const struct expr *expr, struct output_ctx *octx)
json_t *range_expr_json(const struct expr *expr, struct output_ctx *octx)
+ unsigned int flags = octx->flags;
json_t *root;
- octx->numeric += NFT_NUMERIC_ALL + 1;
+ octx->flags &= ~NFT_CTX_OUTPUT_SERVICE;
root = json_pack("{s:[o, o]}", "range",
expr_print_json(expr->left, octx),
expr_print_json(expr->right, octx));
- octx->numeric -= NFT_NUMERIC_ALL + 1;
+ octx->flags = flags;
return root;
@@ -976,7 +977,7 @@ json_t *inet_service_type_json(const struct expr *expr, struct output_ctx *octx)
char buf[NI_MAXSERV];
- if (octx->literal < NFT_LITERAL_PORT ||
+ if (!nft_output_service(octx) ||
getnameinfo((struct sockaddr *)&sin, sizeof(sin),
NULL, 0, buf, sizeof(buf), 0))
return json_integer(ntohs(sin.sin_port));