From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [nft PATCH 2/2] masquerade: Complain if no prerouting chain exists
Date: Thu, 27 Apr 2017 15:24:39 +0200 [thread overview]
Message-ID: <20170427132439.9443-2-phil@nwl.cc> (raw)
In-Reply-To: <20170427132439.9443-1-phil@nwl.cc>
As reported in netfilter bz#1105, masquerading won't work if there isn't
at least an empty base chain hooked into prerouting. In order to raise
awareness of this problem at the user, complain if a masquerading
statement is added and the table does not contain an appropriate
prerouting chain already.
To not break user scripts which add the required chain at a later point,
accept the command anyway.
A better solution would be to create the required chain as a dependency
and drop it again on return path or if the user adds his own one later,
though I doubt the extra effort is feasible here.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
src/evaluate.c | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index 49c5953ae1687..a89ada19298a5 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -2379,6 +2379,8 @@ static int stmt_evaluate_nat(struct eval_ctx *ctx, struct stmt *stmt)
static int stmt_evaluate_masq(struct eval_ctx *ctx, struct stmt *stmt)
{
+ struct table *table;
+ struct chain *chain;
int err;
err = nat_evaluate_family(ctx, stmt);
@@ -2392,7 +2394,23 @@ static int stmt_evaluate_masq(struct eval_ctx *ctx, struct stmt *stmt)
}
stmt->flags |= STMT_F_TERMINAL;
- return 0;
+
+ err = cache_update(CMD_INVALID, ctx->msgs);
+ if (err < 0)
+ return err;
+
+ table = table_lookup_global(ctx);
+ if (!table)
+ return stmt_error(ctx, stmt, "referenced table not found");
+
+ list_for_each_entry(chain, &table->chains, list) {
+ if (!strcmp(chain->type, "nat") &&
+ chain->hooknum == NF_INET_PRE_ROUTING)
+ return 0;
+ }
+
+ return stmt_warning(ctx, stmt,
+ "this requires at least an empty prerouting chain");
}
static int stmt_evaluate_redir(struct eval_ctx *ctx, struct stmt *stmt)
--
2.11.0
next prev parent reply other threads:[~2017-04-27 13:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-27 13:24 [nft PATCH 1/2] erec: Make __stmt_binary_error a little more versatile Phil Sutter
2017-04-27 13:24 ` Phil Sutter [this message]
2017-04-28 7:01 ` [nft PATCH 2/2] masquerade: Complain if no prerouting chain exists Arturo Borrero Gonzalez
2017-04-28 8:05 ` Phil Sutter
2017-04-28 8:11 ` Arturo Borrero Gonzalez
2017-04-28 8:28 ` Phil Sutter
2017-04-28 9:02 ` Arturo Borrero Gonzalez
2017-04-28 14:58 ` Pablo Neira Ayuso
2017-04-28 15:59 ` Phil Sutter
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=20170427132439.9443-2-phil@nwl.cc \
--to=phil@nwl.cc \
--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).