|
|
bacbc8 |
From 4a4acdac14e0ec770589534aa4a5ea469a76e2a5 Mon Sep 17 00:00:00 2001
|
|
|
bacbc8 |
From: Florian Westphal <fw@strlen.de>
|
|
|
bacbc8 |
Date: Tue, 6 Nov 2018 16:06:27 +0100
|
|
|
bacbc8 |
Subject: [PATCH] xt: always build with a minimal support for xt match/target
|
|
|
bacbc8 |
decode
|
|
|
bacbc8 |
|
|
|
bacbc8 |
When building without libxtables, nft would just silently omit any presence
|
|
|
bacbc8 |
of nft_compat in the output.
|
|
|
bacbc8 |
|
|
|
bacbc8 |
This adds ifdef-ry to at least print name of target/match involved when
|
|
|
bacbc8 |
libxtables isn't available for decoding.
|
|
|
bacbc8 |
|
|
|
bacbc8 |
Signed-off-by: Florian Westphal <fw@strlen.de>
|
|
|
bacbc8 |
(cherry picked from commit b3c8de9c5aecde38eec964f31120df82b9704c8c)
|
|
|
bacbc8 |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
bacbc8 |
---
|
|
|
bacbc8 |
include/xt.h | 13 +------------
|
|
|
bacbc8 |
src/Makefile.am | 2 +-
|
|
|
bacbc8 |
src/xt.c | 22 ++++++++++++++++++++++
|
|
|
bacbc8 |
3 files changed, 24 insertions(+), 13 deletions(-)
|
|
|
bacbc8 |
|
|
|
bacbc8 |
diff --git a/include/xt.h b/include/xt.h
|
|
|
bacbc8 |
index 549eb9fe41531..ab59bb3d45a41 100644
|
|
|
bacbc8 |
--- a/include/xt.h
|
|
|
bacbc8 |
+++ b/include/xt.h
|
|
|
bacbc8 |
@@ -8,7 +8,6 @@ struct rule_pp_ctx;
|
|
|
bacbc8 |
struct rule;
|
|
|
bacbc8 |
struct output_ctx;
|
|
|
bacbc8 |
|
|
|
bacbc8 |
-#ifdef HAVE_LIBXTABLES
|
|
|
bacbc8 |
void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx);
|
|
|
bacbc8 |
void xt_stmt_release(const struct stmt *stmt);
|
|
|
bacbc8 |
|
|
|
bacbc8 |
@@ -18,20 +17,10 @@ void netlink_parse_target(struct netlink_parse_ctx *ctx,
|
|
|
bacbc8 |
void netlink_parse_match(struct netlink_parse_ctx *ctx,
|
|
|
bacbc8 |
const struct location *loc,
|
|
|
bacbc8 |
const struct nftnl_expr *nle);
|
|
|
bacbc8 |
+#ifdef HAVE_LIBXTABLES
|
|
|
bacbc8 |
void stmt_xt_postprocess(struct rule_pp_ctx *rctx, struct stmt *stmt,
|
|
|
bacbc8 |
struct rule *rule);
|
|
|
bacbc8 |
#else
|
|
|
bacbc8 |
-static inline void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx) {}
|
|
|
bacbc8 |
-static inline void xt_stmt_release(const struct stmt *stmt) {}
|
|
|
bacbc8 |
-
|
|
|
bacbc8 |
-#include <erec.h>
|
|
|
bacbc8 |
-
|
|
|
bacbc8 |
-static inline void netlink_parse_target(struct netlink_parse_ctx *ctx,
|
|
|
bacbc8 |
- const struct location *loc,
|
|
|
bacbc8 |
- const struct nftnl_expr *nle) {}
|
|
|
bacbc8 |
-static inline void netlink_parse_match(struct netlink_parse_ctx *ctx,
|
|
|
bacbc8 |
- const struct location *loc,
|
|
|
bacbc8 |
- const struct nftnl_expr *nle) {}
|
|
|
bacbc8 |
static inline void stmt_xt_postprocess(struct rule_pp_ctx *rctx,
|
|
|
bacbc8 |
struct stmt *stmt, struct rule *rule) {}
|
|
|
bacbc8 |
|
|
|
bacbc8 |
diff --git a/src/Makefile.am b/src/Makefile.am
|
|
|
bacbc8 |
index a4ad8cb31236b..495511803b686 100644
|
|
|
bacbc8 |
--- a/src/Makefile.am
|
|
|
bacbc8 |
+++ b/src/Makefile.am
|
|
|
bacbc8 |
@@ -78,8 +78,8 @@ libminigmp_la_CFLAGS = ${AM_CFLAGS} -Wno-sign-compare
|
|
|
bacbc8 |
libnftables_la_LIBADD += libminigmp.la
|
|
|
bacbc8 |
endif
|
|
|
bacbc8 |
|
|
|
bacbc8 |
-if BUILD_XTABLES
|
|
|
bacbc8 |
libnftables_la_SOURCES += xt.c
|
|
|
bacbc8 |
+if BUILD_XTABLES
|
|
|
bacbc8 |
libnftables_la_LIBADD += ${XTABLES_LIBS}
|
|
|
bacbc8 |
endif
|
|
|
bacbc8 |
|
|
|
bacbc8 |
diff --git a/src/xt.c b/src/xt.c
|
|
|
bacbc8 |
index 9b7d4c29194aa..c35c84edca0e6 100644
|
|
|
bacbc8 |
--- a/src/xt.c
|
|
|
bacbc8 |
+++ b/src/xt.c
|
|
|
bacbc8 |
@@ -28,6 +28,7 @@
|
|
|
bacbc8 |
|
|
|
bacbc8 |
void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx)
|
|
|
bacbc8 |
{
|
|
|
bacbc8 |
+#ifdef HAVE_LIBXTABLES
|
|
|
bacbc8 |
struct xt_xlate *xl = xt_xlate_alloc(10240);
|
|
|
bacbc8 |
|
|
|
bacbc8 |
switch (stmt->xt.type) {
|
|
|
bacbc8 |
@@ -68,6 +69,9 @@ void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx)
|
|
|
bacbc8 |
}
|
|
|
bacbc8 |
|
|
|
bacbc8 |
xt_xlate_free(xl);
|
|
|
bacbc8 |
+#else
|
|
|
bacbc8 |
+ nft_print(octx, "# xt_%s", stmt->xt.name);
|
|
|
bacbc8 |
+#endif
|
|
|
bacbc8 |
}
|
|
|
bacbc8 |
|
|
|
bacbc8 |
void xt_stmt_release(const struct stmt *stmt)
|
|
|
bacbc8 |
@@ -95,6 +99,7 @@ void xt_stmt_release(const struct stmt *stmt)
|
|
|
bacbc8 |
xfree(stmt->xt.name);
|
|
|
bacbc8 |
}
|
|
|
bacbc8 |
|
|
|
bacbc8 |
+#ifdef HAVE_LIBXTABLES
|
|
|
bacbc8 |
static void *xt_entry_alloc(struct xt_stmt *xt, uint32_t af)
|
|
|
bacbc8 |
{
|
|
|
bacbc8 |
union nft_entry {
|
|
|
bacbc8 |
@@ -180,6 +185,7 @@ static struct xtables_match *xt_match_clone(struct xtables_match *m)
|
|
|
bacbc8 |
memcpy(clone, m, sizeof(struct xtables_match));
|
|
|
bacbc8 |
return clone;
|
|
|
bacbc8 |
}
|
|
|
bacbc8 |
+#endif
|
|
|
bacbc8 |
|
|
|
bacbc8 |
/*
|
|
|
bacbc8 |
* Delinearization
|
|
|
bacbc8 |
@@ -191,6 +197,7 @@ void netlink_parse_match(struct netlink_parse_ctx *ctx,
|
|
|
bacbc8 |
{
|
|
|
bacbc8 |
struct stmt *stmt;
|
|
|
bacbc8 |
const char *name;
|
|
|
bacbc8 |
+#ifdef HAVE_LIBXTABLES
|
|
|
bacbc8 |
struct xtables_match *mt;
|
|
|
bacbc8 |
const char *mtinfo;
|
|
|
bacbc8 |
struct xt_entry_match *m;
|
|
|
bacbc8 |
@@ -218,7 +225,13 @@ void netlink_parse_match(struct netlink_parse_ctx *ctx,
|
|
|
bacbc8 |
stmt->xt.type = NFT_XT_MATCH;
|
|
|
bacbc8 |
stmt->xt.match = xt_match_clone(mt);
|
|
|
bacbc8 |
stmt->xt.match->m = m;
|
|
|
bacbc8 |
+#else
|
|
|
bacbc8 |
+ name = nftnl_expr_get_str(nle, NFTNL_EXPR_MT_NAME);
|
|
|
bacbc8 |
|
|
|
bacbc8 |
+ stmt = xt_stmt_alloc(loc);
|
|
|
bacbc8 |
+ stmt->xt.name = strdup(name);
|
|
|
bacbc8 |
+ stmt->xt.type = NFT_XT_MATCH;
|
|
|
bacbc8 |
+#endif
|
|
|
bacbc8 |
list_add_tail(&stmt->list, &ctx->rule->stmts);
|
|
|
bacbc8 |
}
|
|
|
bacbc8 |
|
|
|
bacbc8 |
@@ -228,6 +241,7 @@ void netlink_parse_target(struct netlink_parse_ctx *ctx,
|
|
|
bacbc8 |
{
|
|
|
bacbc8 |
struct stmt *stmt;
|
|
|
bacbc8 |
const char *name;
|
|
|
bacbc8 |
+#ifdef HAVE_LIBXTABLES
|
|
|
bacbc8 |
struct xtables_target *tg;
|
|
|
bacbc8 |
const void *tginfo;
|
|
|
bacbc8 |
struct xt_entry_target *t;
|
|
|
bacbc8 |
@@ -256,10 +270,17 @@ void netlink_parse_target(struct netlink_parse_ctx *ctx,
|
|
|
bacbc8 |
stmt->xt.type = NFT_XT_TARGET;
|
|
|
bacbc8 |
stmt->xt.target = xt_target_clone(tg);
|
|
|
bacbc8 |
stmt->xt.target->t = t;
|
|
|
bacbc8 |
+#else
|
|
|
bacbc8 |
+ name = nftnl_expr_get_str(nle, NFTNL_EXPR_TG_NAME);
|
|
|
bacbc8 |
|
|
|
bacbc8 |
+ stmt = xt_stmt_alloc(loc);
|
|
|
bacbc8 |
+ stmt->xt.name = strdup(name);
|
|
|
bacbc8 |
+ stmt->xt.type = NFT_XT_TARGET;
|
|
|
bacbc8 |
+#endif
|
|
|
bacbc8 |
list_add_tail(&stmt->list, &ctx->rule->stmts);
|
|
|
bacbc8 |
}
|
|
|
bacbc8 |
|
|
|
bacbc8 |
+#ifdef HAVE_LIBXTABLES
|
|
|
bacbc8 |
static bool is_watcher(uint32_t family, struct stmt *stmt)
|
|
|
bacbc8 |
{
|
|
|
bacbc8 |
if (family != NFPROTO_BRIDGE ||
|
|
|
bacbc8 |
@@ -371,3 +392,4 @@ void xt_init(void)
|
|
|
bacbc8 |
/* Default to IPv4, but this changes in runtime */
|
|
|
bacbc8 |
xtables_init_all(&xt_nft_globals, NFPROTO_IPV4);
|
|
|
bacbc8 |
}
|
|
|
bacbc8 |
+#endif
|
|
|
bacbc8 |
--
|
|
|
bacbc8 |
2.21.0
|
|
|
bacbc8 |
|