From: Elise Lennion <elise.lennion@gmail.com>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH nft v2 2/2] src: Always print range expressions numerically
Date: Thu, 2 Feb 2017 10:31:56 -0200 [thread overview]
Message-ID: <20170202123156.GA17914@lennorien.com> (raw)
Because the rules are more legible this way. Also, the parser doesn't
accept strings on ranges, so, printing ranges numerically better match
the rules definition.
Fixes(Bug 1046 - mobility header with range gives illegible rule).
Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
---
v2: Replace ternary operator with if statements.
Remove the new NUMERIC_CONSTANT, now uses a value bigger than
NUMERIC_ALL to print symbolic constants as numbers, this case
is only met during expr_range_print.
src/datatype.c | 8 +++++++-
src/expression.c | 2 ++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/src/datatype.c b/src/datatype.c
index 1518606..d697a07 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -175,9 +175,15 @@ void symbolic_constant_print(const struct symbol_table *tbl,
return expr_basetype(expr)->print(expr);
if (quotes)
- printf("\"%s\"", s->identifier);
+ printf("\"");
+
+ if (numeric_output > NUMERIC_ALL)
+ printf("%lu", val);
else
printf("%s", s->identifier);
+
+ if (quotes)
+ printf("\"");
}
static void switch_byteorder(void *data, unsigned int len)
diff --git a/src/expression.c b/src/expression.c
index 1567870..da94b79 100644
--- a/src/expression.c
+++ b/src/expression.c
@@ -597,9 +597,11 @@ struct expr *relational_expr_alloc(const struct location *loc, enum ops op,
static void range_expr_print(const struct expr *expr)
{
+ numeric_output += NUMERIC_ALL + 1;
expr_print(expr->left);
printf("-");
expr_print(expr->right);
+ numeric_output -= NUMERIC_ALL + 1;
}
static void range_expr_clone(struct expr *new, const struct expr *expr)
--
2.7.4
next reply other threads:[~2017-02-02 12:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-02 12:31 Elise Lennion [this message]
2017-02-05 20:42 ` [PATCH nft v2 2/2] src: Always print range expressions numerically Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170202123156.GA17914@lennorien.com \
--to=elise.lennion@gmail.com \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).