From fde8ddfc31bbc4015e8a76b40cc7e27bcd7920ff Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sat, 17 Mar 2018 10:39:27 +0100 Subject: Combine redir and masq statements into nat All these statements are very similar, handling them with the same code is obvious. The only thing required here is a custom extension of enum nft_nat_types which is used in nat_stmt to distinguish between snat and dnat already. Though since enum nft_nat_types is part of kernel uAPI, create a local extended version containing the additional fields. Note that nat statement printing got a bit more complicated to get the number of spaces right for every possible combination of attributes. Note also that there wasn't a case for STMT_MASQ in rule_parse_postprocess(), which seems like a bug. Since STMT_MASQ became just a variant of STMT_NAT, postprocessing will take place for it now anyway. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/evaluate.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'src/evaluate.c') diff --git a/src/evaluate.c b/src/evaluate.c index 8de5e48d..6ae94b0f 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -2465,42 +2465,6 @@ static int stmt_evaluate_nat(struct eval_ctx *ctx, struct stmt *stmt) return 0; } -static int stmt_evaluate_masq(struct eval_ctx *ctx, struct stmt *stmt) -{ - int err; - - err = nat_evaluate_family(ctx, stmt); - if (err < 0) - return err; - - if (stmt->masq.proto != NULL) { - err = nat_evaluate_transport(ctx, stmt, &stmt->masq.proto); - if (err < 0) - return err; - } - - stmt->flags |= STMT_F_TERMINAL; - return 0; -} - -static int stmt_evaluate_redir(struct eval_ctx *ctx, struct stmt *stmt) -{ - int err; - - err = nat_evaluate_family(ctx, stmt); - if (err < 0) - return err; - - if (stmt->redir.proto != NULL) { - err = nat_evaluate_transport(ctx, stmt, &stmt->redir.proto); - if (err < 0) - return err; - } - - stmt->flags |= STMT_F_TERMINAL; - return 0; -} - static int stmt_evaluate_dup(struct eval_ctx *ctx, struct stmt *stmt) { int err; @@ -2758,10 +2722,6 @@ int stmt_evaluate(struct eval_ctx *ctx, struct stmt *stmt) return stmt_evaluate_reject(ctx, stmt); case STMT_NAT: return stmt_evaluate_nat(ctx, stmt); - case STMT_MASQ: - return stmt_evaluate_masq(ctx, stmt); - case STMT_REDIR: - return stmt_evaluate_redir(ctx, stmt); case STMT_QUEUE: return stmt_evaluate_queue(ctx, stmt); case STMT_DUP: -- cgit v1.2.3