summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2020-07-04 02:43:40 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2020-07-15 21:56:18 +0200
commit1cba7a5e5e96dd920271823125b45e182f22ec82 (patch)
treefca8a5b98ef21a5552b8b84e73139d038a7f4519
parente76bb379401816bbea773e73b524cd747324760a (diff)
datatype: convert chain name from gmp value to string
Add expr_chain_export() helper function to convert the chain name that is stored in a gmp value variable to string. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--include/datatype.h2
-rw-r--r--src/datatype.c21
2 files changed, 15 insertions, 8 deletions
diff --git a/include/datatype.h b/include/datatype.h
index 04b4892b..1061a389 100644
--- a/include/datatype.h
+++ b/include/datatype.h
@@ -305,4 +305,6 @@ extern struct error_record *rate_parse(const struct location *loc,
extern struct error_record *data_unit_parse(const struct location *loc,
const char *str, uint64_t *rate);
+extern void expr_chain_export(const struct expr *e, char *chain);
+
#endif /* NFTABLES_DATATYPE_H */
diff --git a/src/datatype.c b/src/datatype.c
index 90905258..7382307e 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -247,20 +247,25 @@ const struct datatype invalid_type = {
.print = invalid_type_print,
};
+void expr_chain_export(const struct expr *e, char *chain_name)
+{
+ unsigned int len;
+
+ len = e->len / BITS_PER_BYTE;
+ if (len >= NFT_CHAIN_MAXNAMELEN)
+ BUG("verdict expression length %u is too large (%u bits max)",
+ e->len, NFT_CHAIN_MAXNAMELEN * BITS_PER_BYTE);
+
+ mpz_export_data(chain_name, e->value, BYTEORDER_HOST_ENDIAN, len);
+}
+
static void verdict_jump_chain_print(const char *what, const struct expr *e,
struct output_ctx *octx)
{
char chain[NFT_CHAIN_MAXNAMELEN];
- unsigned int len;
memset(chain, 0, sizeof(chain));
-
- len = e->len / BITS_PER_BYTE;
- if (len >= sizeof(chain))
- BUG("verdict expression length %u is too large (%lu bits max)",
- e->len, (unsigned long)sizeof(chain) * BITS_PER_BYTE);
-
- mpz_export_data(chain, e->value, BYTEORDER_HOST_ENDIAN, len);
+ expr_chain_export(e, chain);
nft_print(octx, "%s %s", what, chain);
}