From fc53d1b6b93d9ca194334c43931753e19bcb127b Mon Sep 17 00:00:00 2001 From: Arturo Borrero Date: Fri, 3 Oct 2014 14:46:41 +0200 Subject: src: add nat persistent and random options This patch adds more configuration options to the nat expression. The syntax is as follow: % nft add rule nat postrouting [flags] Flags are: random, persistent, random-fully. Example: % nft add rule nat postrouting dnat 1.1.1.1 random,persistent A requirement is to cache some [recent] copies of kernel headers. Signed-off-by: Arturo Borrero Gonzalez Signed-off-by: Pablo Neira Ayuso --- src/statement.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/statement.c') diff --git a/src/statement.c b/src/statement.c index 357f0948..f1d83fcb 100644 --- a/src/statement.c +++ b/src/statement.c @@ -24,6 +24,9 @@ #include #include +#include +#include + struct stmt *stmt_alloc(const struct location *loc, const struct stmt_ops *ops) { @@ -271,6 +274,27 @@ struct stmt *reject_stmt_alloc(const struct location *loc) return stmt_alloc(loc, &reject_stmt_ops); } +static void print_nf_nat_flags(uint32_t flags) +{ + const char *delim = " "; + + if (flags == 0) + return; + + if (flags & NF_NAT_RANGE_PROTO_RANDOM) { + printf("%srandom", delim); + delim = ","; + } + + if (flags & NF_NAT_RANGE_PROTO_RANDOM_FULLY) { + printf("%srandom-fully", delim); + delim = ","; + } + + if (flags & NF_NAT_RANGE_PERSISTENT) + printf("%spersistent", delim); +} + static void nat_stmt_print(const struct stmt *stmt) { static const char *nat_types[] = { @@ -285,6 +309,8 @@ static void nat_stmt_print(const struct stmt *stmt) printf(":"); expr_print(stmt->nat.proto); } + + print_nf_nat_flags(stmt->nat.flags); } static void nat_stmt_destroy(struct stmt *stmt) -- cgit v1.2.3