Support for shifted port-ranges was recently added to nat statements. Extend this to redir statements. Signed-off-by: Jeremy Sowden <jeremy@xxxxxxxxxx> --- src/netlink_delinearize.c | 16 +++++++++++++++- src/netlink_linearize.c | 5 +++-- src/parser_bison.y | 11 +++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c index 867ca914cf96..0c48cdd70428 100644 --- a/src/netlink_delinearize.c +++ b/src/netlink_delinearize.c @@ -1505,7 +1505,7 @@ static void netlink_parse_redir(struct netlink_parse_ctx *ctx, { struct stmt *stmt; struct expr *proto; - enum nft_registers reg1, reg2; + enum nft_registers reg1, reg2, reg3; uint32_t flags; stmt = nat_stmt_alloc(loc, NFT_NAT_REDIR); @@ -1542,6 +1542,20 @@ static void netlink_parse_redir(struct netlink_parse_ctx *ctx, proto = range_expr_alloc(loc, stmt->nat.proto, proto); stmt->nat.proto = proto; + + reg3 = netlink_parse_register(nle, NFTNL_EXPR_REDIR_REG_PROTO_BASE); + if (reg3) { + proto = netlink_get_register(ctx, loc, reg3); + if (proto == NULL) { + netlink_error(ctx, loc, + "redirect statement has no base proto expression"); + goto out_err; + } + + expr_set_type(proto, &inet_service_type, + BYTEORDER_BIG_ENDIAN); + stmt->nat.proto_base = proto; + } } ctx->stmt = stmt; diff --git a/src/netlink_linearize.c b/src/netlink_linearize.c index a018290a7f56..684cfdcaf91c 100644 --- a/src/netlink_linearize.c +++ b/src/netlink_linearize.c @@ -1227,8 +1227,9 @@ static void netlink_gen_nat_stmt(struct netlink_linearize_ctx *ctx, nle = alloc_nft_expr("redir"); nftnl_flag_attr = NFTNL_EXPR_REDIR_FLAGS; - nftnl_reg_pmin = NFTNL_EXPR_REDIR_REG_PROTO_MIN; - nftnl_reg_pmax = NFTNL_EXPR_REDIR_REG_PROTO_MAX; + nftnl_reg_pmin = NFTNL_EXPR_REDIR_REG_PROTO_MIN; + nftnl_reg_pmax = NFTNL_EXPR_REDIR_REG_PROTO_MAX; + nftnl_reg_pbase = NFTNL_EXPR_REDIR_REG_PROTO_BASE; break; default: BUG("unknown nat type %d\n", stmt->nat.type); diff --git a/src/parser_bison.y b/src/parser_bison.y index 8a7c5f066daa..5b8e48363233 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -3965,6 +3965,11 @@ redir_stmt_arg : TO stmt_expr { $<stmt>0->nat.proto = $3; } + | TO COLON range_stmt_expr SLASH primary_stmt_expr + { + $<stmt>0->nat.proto = $3; + $<stmt>0->nat.proto_base = $5; + } | nf_nat_flags { $<stmt>0->nat.flags = $1; @@ -3979,6 +3984,12 @@ redir_stmt_arg : TO stmt_expr $<stmt>0->nat.proto = $3; $<stmt>0->nat.flags = $4; } + | TO COLON range_stmt_expr SLASH primary_stmt_expr nf_nat_flags + { + $<stmt>0->nat.proto = $3; + $<stmt>0->nat.proto_base = $5; + $<stmt>0->nat.flags = $6; + } ; dup_stmt : DUP TO stmt_expr -- 2.39.2