summaryrefslogtreecommitdiffstats
path: root/src/xt.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2022-11-24 16:16:41 +0100
committerPhil Sutter <phil@nwl.cc>2022-12-13 14:59:55 +0100
commite41c53ca5b043e8cee493bf4a7f78195827279d2 (patch)
tree87d269c210d426130a9177ad4ea75a9014ddfa90 /src/xt.c
parent79195a8cc9e9d9cf2d17165bf07ac4cc9d55539f (diff)
xt: Fall back to generic printing from translation
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>
Diffstat (limited to 'src/xt.c')
-rw-r--r--src/xt.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/xt.c b/src/xt.c
index 12b52aa3..b75c94e8 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, &params);
- nft_print(octx, "%s", xt_xlate_get(xl));
- } else if (mt->print) {
- printf("#");
- mt->print(&entry, m, 0);
+ rc = mt->xlate(xl, &params);
}
xfree(m);
break;
@@ -102,27 +104,20 @@ void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx)
.numeric = 1,
};
- tg->xlate(xl, &params);
- nft_print(octx, "%s", xt_xlate_get(xl));
- } else if (tg->print) {
- printf("#");
- tg->print(NULL, t, 0);
+ rc = tg->xlate(xl, &params);
}
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)