summaryrefslogtreecommitdiffstats
path: root/src/statement.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2018-05-08 13:08:36 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2018-05-11 12:16:57 +0200
commite77b31f53a61a8995cd6baf91a6e557260f401bd (patch)
tree1ee2e9c20c746c8cb66ee5f70ce95c9ebcf8cafc /src/statement.c
parent7feece21f72ebf4633048b2dd447e31da30819fb (diff)
libnftables: Introduce a few helper functions
This adds a bunch of functions for conversion of different values into string (and vice-versa). * log_level_parse(): A simple helper to turn log level string representation into log level value. * nat_etype2str(): Translate nat statement type into string representation. * ct_dir2str(): Convert IP_CT_DIR_* values into string representation. * ct_label2str(): Convert ct_label values into string representation. Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/statement.c')
-rw-r--r--src/statement.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/statement.c b/src/statement.c
index 6537bbbd..8160e0ad 100644
--- a/src/statement.c
+++ b/src/statement.c
@@ -233,6 +233,18 @@ const char *log_level(uint32_t level)
return syslog_level[level];
}
+int log_level_parse(const char *level)
+{
+ int i;
+
+ for (i = 0; i <= LOG_DEBUG; i++) {
+ if (syslog_level[i] &&
+ !strcmp(level, syslog_level[i]))
+ return i;
+ }
+ return -1;
+}
+
static void log_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
{
nft_print(octx, "log");
@@ -499,7 +511,7 @@ static void print_nf_nat_flags(uint32_t flags, struct output_ctx *octx)
nft_print(octx, "%spersistent", delim);
}
-static void nat_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
+const char *nat_etype2str(enum nft_nat_etypes type)
{
static const char * const nat_types[] = {
[NFT_NAT_SNAT] = "snat",
@@ -508,7 +520,12 @@ static void nat_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
[NFT_NAT_REDIR] = "redirect",
};
- nft_print(octx, "%s", nat_types[stmt->nat.type]);
+ return nat_types[type];
+}
+
+static void nat_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
+{
+ nft_print(octx, "%s", nat_etype2str(stmt->nat.type));
if (stmt->nat.addr || stmt->nat.proto)
nft_print(octx, " to");