src: nat concatenation support with anonymous maps
Pablo Neira Ayuso
maintainerThis patch extends the parser to define the mapping datatypes, eg.
... dnat ip addr . port to ip saddr map { 1.1.1.1 : 2.2.2.2 . 30 } ... dnat ip addr . port to ip saddr map @y
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
Florian, this applies on top of you patchset.
src/evaluate.c | 10 ++++++++-- src/netlink_delinearize.c | 1 + src/parser_bison.y | 7 +++++++ src/scanner.l | 1 + src/statement.c | 3 +++ 5 files changed, 20 insertions(+), 2 deletions(-)
src/evaluate.c +8 -2
@@ -2855,13 +2855,20 @@ static int stmt_evaluate_nat_map(struct eval_ctx *ctx, struct stmt *stmt)const struct datatype *dtype;int err; - dtype =get_addr_dtype (stmt->nat.family); +if (stmt->nat.ipportmap) { + dtype =concat_type_alloc ((TYPE_IPADDR <<TYPE_BITS ) | +TYPE_INET_SERVICE ); + }else { + dtype =get_addr_dtype (stmt->nat.family); + }expr_set_context (&ctx->ectx, dtype, dtype->size);if (expr_evaluate (ctx, &stmt->nat.addr))return -1 ; data = stmt->nat.addr->mappings->set->data; +datatype_set (data, dtype); +if (expr_ops (data)->type !=EXPR_CONCAT ) return __stmt_evaluate_arg(ctx, stmt, dtype, dtype->size, BYTEORDER_BIG_ENDIAN,
@@ -2891,7 +2898,6 @@ static int stmt_evaluate_nat_map(struct eval_ctx *ctx, struct stmt *stmt)if (tmp != two)BUG ("Internal error: Unexpected alteration of l4 expression" ); - stmt->nat.ipportmap = true;return err; }
src/netlink_delinearize.c +1 -0
@@ -1065,6 +1065,7 @@ static void netlink_parse_nat(struct netlink_parse_ctx *ctx, }if (is_nat_proto_map (addr, family)) { + stmt->nat.family = family; stmt->nat.ipportmap = true; ctx->stmt = stmt;return ;
src/parser_bison.y +7 -0
@@ -373,6 +373,7 @@ int nft_lex(void *, void *, void *); %token FLAGS "flags" %token CPI "cpi" +%token PORT "port" %token UDP "udp" %token SPORT "sport" %token DPORT "dport"
@@ -3141,6 +3142,12 @@ nat_stmt_args : stmt_expr { $<stmt>0->nat.flags = $2; } + | nf_key_proto ADDR DOT PORT TO stmt_expr + { + $<stmt>0->nat.family = $1; + $<stmt>0->nat.addr = $6; + $<stmt>0->nat.ipportmap = true; + } ; masq_stmt : masq_stmt_alloc masq_stmt_args
src/scanner.l +1 -0
@@ -471,6 +471,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "udplite" { return UDPLITE; } "sport" { return SPORT; } "dport" { return DPORT; } +"port" { return PORT; } "tcp" { return TCP; } "ackseq" { return ACKSEQ; }
src/statement.c +3 -0
@@ -607,6 +607,9 @@ static void nat_stmt_print(const struct stmt *stmt, struct output_ctx *octx)break ; } +if (stmt->nat.ipportmap) +nft_print (octx," addr . port" ); +nft_print (octx," to" ); }
Signature · 1 line
2.11.0