From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org, Florian Westphal <fw@strlen.de>
Subject: [nft PATCH 4/4] xt: Fall back to generic printing from translation
Date: Thu, 24 Nov 2022 17:56:41 +0100 [thread overview]
Message-ID: <20221124165641.26921-5-phil@nwl.cc> (raw)
In-Reply-To: <20221124165641.26921-1-phil@nwl.cc>
If translation is not available or fails, print the generic format
instead of calling the print callback (which does not respect
output_fp) or silently failing.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
src/xt.c | 31 +++++++++++++------------------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/src/xt.c b/src/xt.c
index 12b52aa33bc30..b75c94e856ca7 100644
--- a/src/xt.c
+++ b/src/xt.c
@@ -34,6 +34,12 @@ static void *xt_entry_alloc(const struct xt_stmt *xt, uint32_t af);
void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx)
{
+ static const char *typename[NFT_XT_MAX] = {
+ [NFT_XT_MATCH] = "match",
+ [NFT_XT_TARGET] = "target",
+ [NFT_XT_WATCHER] = "watcher",
+ };
+ int rc = 0;
#ifdef HAVE_LIBXTABLES
struct xt_xlate *xl = xt_xlate_alloc(10240);
struct xtables_target *tg;
@@ -69,11 +75,7 @@ void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx)
.numeric = 1,
};
- mt->xlate(xl, ¶ms);
- nft_print(octx, "%s", xt_xlate_get(xl));
- } else if (mt->print) {
- printf("#");
- mt->print(&entry, m, 0);
+ rc = mt->xlate(xl, ¶ms);
}
xfree(m);
break;
@@ -102,27 +104,20 @@ void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx)
.numeric = 1,
};
- tg->xlate(xl, ¶ms);
- nft_print(octx, "%s", xt_xlate_get(xl));
- } else if (tg->print) {
- printf("#");
- tg->print(NULL, t, 0);
+ rc = tg->xlate(xl, ¶ms);
}
xfree(t);
break;
}
+ if (rc == 1)
+ nft_print(octx, "%s", xt_xlate_get(xl));
xt_xlate_free(xl);
xfree(entry);
-#else
- static const char *typename[NFT_XT_MAX] = {
- [NFT_XT_MATCH] = "match",
- [NFT_XT_TARGET] = "target",
- [NFT_XT_WATCHER] = "watcher",
- };
-
- nft_print(octx, "xt %s %s", typename[stmt->xt.type], stmt->xt.name);
#endif
+ if (!rc)
+ nft_print(octx, "xt %s %s",
+ typename[stmt->xt.type], stmt->xt.name);
}
void xt_stmt_destroy(struct stmt *stmt)
--
2.38.0
next prev parent reply other threads:[~2022-11-24 16:57 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-24 16:56 [nft PATCH 0/4] xt: Rewrite unsupported compat expression dumping Phil Sutter
2022-11-24 16:56 ` [nft PATCH 1/4] xt: Delay libxtables access until translation Phil Sutter
2022-12-08 21:21 ` Pablo Neira Ayuso
2022-12-09 0:14 ` Phil Sutter
2022-12-09 16:06 ` Pablo Neira Ayuso
2022-11-24 16:56 ` [nft PATCH 2/4] xt: Purify enum nft_xt_type Phil Sutter
2022-11-24 16:56 ` [nft PATCH 3/4] xt: Rewrite unsupported compat expression dumping Phil Sutter
2022-11-24 17:04 ` Florian Westphal
2022-11-24 17:22 ` Phil Sutter
2022-11-24 17:35 ` Florian Westphal
2022-12-09 16:07 ` Pablo Neira Ayuso
2022-12-09 16:45 ` Phil Sutter
2022-12-09 20:10 ` Pablo Neira Ayuso
2022-11-24 16:56 ` Phil Sutter [this message]
2022-12-13 14:03 ` [nft PATCH 0/4] " 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=20221124165641.26921-5-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=fw@strlen.de \
--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).