From: Elise Lennion <elise.lennion@gmail.com>
To: pablo@netfilter.org
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] src: Always print range expressions numerically
Date: Mon, 30 Jan 2017 12:05:20 -0200 [thread overview]
Message-ID: <20170130140520.GA5818@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).
A new NUMERIC constant was defined to fill the previous role of
NUMERIC_ALL, so the option -nnn doesn't affect symbolic constants.
Signed-off-by: Elise Lennion <elise.lennion@gmail.com>
---
include/nftables.h | 1 +
src/datatype.c | 11 +++++++----
src/expression.c | 2 ++
src/main.c | 3 ++-
src/meta.c | 4 ++--
5 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/include/nftables.h b/include/nftables.h
index 6f54155..2730f65 100644
--- a/include/nftables.h
+++ b/include/nftables.h
@@ -9,6 +9,7 @@ enum numeric_level {
NUMERIC_NONE,
NUMERIC_ADDR,
NUMERIC_PORT,
+ NUMERIC_PROTO_UGID,
NUMERIC_ALL,
};
diff --git a/src/datatype.c b/src/datatype.c
index 1518606..f9981a6 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -175,9 +175,12 @@ void symbolic_constant_print(const struct symbol_table *tbl,
return expr_basetype(expr)->print(expr);
if (quotes)
- printf("\"%s\"", s->identifier);
- else
- printf("%s", s->identifier);
+ printf("\"");
+
+ numeric_output >= NUMERIC_ALL ? printf("%lu", val) : printf("%s", s->identifier);
+
+ if (quotes)
+ printf("\"");
}
static void switch_byteorder(void *data, unsigned int len)
@@ -530,7 +533,7 @@ static void inet_protocol_type_print(const struct expr *expr)
{
struct protoent *p;
- if (numeric_output < NUMERIC_ALL) {
+ if (numeric_output < NUMERIC_PROTO_UGID) {
p = getprotobynumber(mpz_get_uint8(expr->value));
if (p != NULL) {
printf("%s", p->p_name);
diff --git a/src/expression.c b/src/expression.c
index 1567870..bdbbd45 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;
expr_print(expr->left);
printf("-");
expr_print(expr->right);
+ numeric_output -= NUMERIC_ALL;
}
static void range_expr_clone(struct expr *new, const struct expr *expr)
diff --git a/src/main.c b/src/main.c
index 6ba752b..1b28836 100644
--- a/src/main.c
+++ b/src/main.c
@@ -288,7 +288,8 @@ int main(int argc, char * const *argv)
include_paths[num_include_paths++] = optarg;
break;
case OPT_NUMERIC:
- numeric_output++;
+ if (numeric_output + 1 < NUMERIC_ALL)
+ numeric_output++;
break;
case OPT_STATELESS:
stateless_output++;
diff --git a/src/meta.c b/src/meta.c
index cb7c136..9e8a987 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -226,7 +226,7 @@ static void uid_type_print(const struct expr *expr)
{
struct passwd *pw;
- if (numeric_output < NUMERIC_ALL) {
+ if (numeric_output < NUMERIC_PROTO_UGID) {
uint32_t uid = mpz_get_uint32(expr->value);
pw = getpwuid(uid);
@@ -278,7 +278,7 @@ static void gid_type_print(const struct expr *expr)
{
struct group *gr;
- if (numeric_output < NUMERIC_ALL) {
+ if (numeric_output < NUMERIC_PROTO_UGID) {
uint32_t gid = mpz_get_uint32(expr->value);
gr = getgrgid(gid);
--
2.7.4
next reply other threads:[~2017-01-30 14:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-30 14:05 Elise Lennion [this message]
2017-02-01 17:58 ` [PATCH nft] 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=20170130140520.GA5818@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).