Support for shifted port-ranges in NAT
Subsystems (2)
cover Support for shifted port-ranges in NAT
Commit 2eb0f624b709 ("netfilter: add NAT support for shifted portmap ranges") introduced support for shifting port-ranges in DNAT. This allows one to redirect packets intended for one port to another in a range in such a way that the new port chosen has the same offset in the range as the original port had from a specified base value.
For example, by using the base value 2000, one could redirect packets intended for 10.0.0.1:2000-3000 to 10.10.0.1:12000-13000 so that the old and new ports were at the same offset in their respective ranges, i.e.:
10.0.0.1:2345 -> 10.10.0.1:12345
However, while support for this was added to the common DNAT infra- structure, only the xt_nat module was updated to make use of it. This patch-set extends the core support and updates all the nft NAT modules to support it too.
* Patches 1 & 2 contain small tidy-ups.
* Patch 3 extends the core NAT support for shifted port-ranges to SNAT.
* Patches 4 & 5 correct the size in a nft_parse_register_load call and add shifted port-range support to nft_nat.
* Patches 6-8 correct the size in a nft_parse_register_load call and add shifted port-range support to nft_masq.
* Patch 9 corrects a C&P mistake in an nft_redir nft_expr_type definition.
* Patch 10-13 correct the size in a nft_parse_register_load call and add shifted port-range support to nft_redir.
Jeremy Sowden (13):
netfilter: conntrack: fix typo
netfilter: nat: fix indentation of function arguments
netfilter: nat: extend core support for shifted port-ranges
netfilter: nft_nat: correct length for loading protocol registers
netfilter: nft_nat: add support for shifted port-ranges
netfilter: nft_masq: correct length for loading protocol registers
netfilter: nft_masq: deduplicate eval call-backs
netfilter: nft_masq: add support for shifted port-ranges
netfilter: nft_redir: correct value of inet type .maxattrs
netfilter: nf_nat_redirect: use struct nf_nat_range2 in ipv4 API
netfilter: nft_redir: correct length for loading protocol registers
netfilter: nft_redir: deduplicate eval call-backs
netfilter: nft_redir: add support for shifted port-ranges
include/net/netfilter/nf_nat_redirect.h | 3 +- include/uapi/linux/netfilter/nf_tables.h | 6 ++ net/netfilter/nf_conntrack_core.c | 2 +- net/netfilter/nf_nat_core.c | 7 +- net/netfilter/nf_nat_masquerade.c | 2 + net/netfilter/nf_nat_redirect.c | 59 ++++++------- net/netfilter/nft_masq.c | 97 ++++++++++----------- net/netfilter/nft_nat.c | 38 ++++++--- net/netfilter/nft_redir.c | 104 +++++++++++------------ net/netfilter/xt_REDIRECT.c | 10 ++- 10 files changed, 177 insertions(+), 151 deletions(-)
Signature · 1 line
2.39.2
PATCH 1/13 netfilter: conntrack: fix typo
There's a spelling mistake in a comment. Fix it.
--- net/netfilter/nf_conntrack_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nf_conntrack_core.c +1 -1
@@ -1294,7 +1294,7 @@ __nf_conntrack_confirm(struct sk_buff *skb) }EXPORT_SYMBOL_GPL (__nf_conntrack_confirm); -/* Returns true if a connection correspondings to the tuple (required +/* Returns true if a connection corresponds to the tuple (required for NAT). */ int nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
Signature · 1 line
2.39.2
PATCH 2/13 netfilter: nat: fix indentation of function arguments
In reply to Jeremy SowdenA couple of arguments to a function call are incorrectly indented. Fix them.
--- net/netfilter/nf_nat_core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_nat_core.c +2 -2
@@ -549,8 +549,8 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,if (range->flags &NF_NAT_RANGE_PROTO_SPECIFIED ) {if (!(range->flags &NF_NAT_RANGE_PROTO_OFFSET ) &&l4proto_in_range (tuple, maniptype, - &range->min_proto, - &range->max_proto) && + &range->min_proto, + &range->max_proto) && (range->min_proto.all == range->max_proto.all || !nf_nat_used_tuple (tuple, ct)))return ;
Signature · 1 line
2.39.2
PATCH 3/13 netfilter: nat: extend core support for shifted port-ranges
In reply to Jeremy SowdenCommit 2eb0f624b709 ("netfilter: add NAT support for shifted portmap ranges") makes changes in the NAT core to add support for shifted port-ranges to iptables DNAT. Before adding support for these to the nft NAT modules extend the core changes to support SNAT as well.
--- net/netfilter/nf_nat_core.c | 3 +++ 1 file changed, 3 insertions(+)
net/netfilter/nf_nat_core.c +3 -0
@@ -255,6 +255,9 @@ static int in_range(const struct nf_conntrack_tuple *tuple,if (!(range->flags &NF_NAT_RANGE_PROTO_SPECIFIED ))return 1 ; +if (range->flags &NF_NAT_RANGE_PROTO_OFFSET ) +return 0 ; +return l4proto_in_range (tuple,NF_NAT_MANIP_SRC , &range->min_proto, &range->max_proto); }
Signature · 1 line
2.39.2
PATCH 4/13 netfilter: nft_nat: correct length for loading protocol registers
In reply to Jeremy SowdenThe values in the protocol registers are two bytes wide. However, when parsing the register loads, the code currently uses the larger 16-byte size of a union nf_inet_addr. Change it to use the (correct) size of a union nf_conntrack_man_proto instead.
--- net/netfilter/nft_nat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_nat.c +1 -1
@@ -226,7 +226,7 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr, priv->flags |=NF_NAT_RANGE_MAP_IPS ; } - plen = sizeof_field(struct nf_nat_range, min_addr.all); + plen = sizeof_field(struct nf_nat_range, min_proto.all);if (tb[NFTA_NAT_REG_PROTO_MIN ]) { err =nft_parse_register_load (tb[NFTA_NAT_REG_PROTO_MIN ], &priv->sreg_proto_min, plen);
Signature · 1 line
2.39.2
PATCH 5/13 netfilter: nft_nat: add support for shifted port-ranges
In reply to Jeremy SowdenCommit 2eb0f624b709 ("netfilter: add NAT support for shifted portmap ranges") introduced support for shifting port-ranges in NAT. This allows one to redirect packets intended for one port to another in a range in such a way that the new port chosen has the same offset in the range as the original port had from a specified base value.
For example, by using the base value 2000, one could redirect packets intended for 10.0.0.1:2000-3000 to 10.10.0.1:12000-13000 so that the old and new ports were at the same offset in their respective ranges, i.e.:
10.0.0.1:2345 -> 10.10.0.1:12345
However, while support for this was added to the common NAT infra- structure, only the xt_nat module was updated to make use of it. This commit updates the nft_nat module to allow shifted port-ranges to be used by nftables.
In contrast to xt_nat, where shifting is only available for DNAT, both DNAT and SNAT are supported.
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nft_nat.c | 38 +++++++++++++++++------- 2 files changed, 29 insertions(+), 11 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -1432,6 +1432,7 @@ enum nft_nat_types {* @NFTA_NAT_REG_PROTO_MIN: source register of proto range start (NLA_U32: nft_registers) * @NFTA_NAT_REG_PROTO_MAX: source register of proto range end (NLA_U32: nft_registers) * @NFTA_NAT_FLAGS: NAT flags (see NF_NAT_RANGE_* in linux/netfilter/nf_nat.h) (NLA_U32) +* @NFTA_NAT_REG_PROTO_BASE: source register of proto range base offset (NLA_U32: nft_registers) */ enum nft_nat_attributes {NFTA_NAT_UNSPEC ,
@@ -1442,6 +1443,7 @@ enum nft_nat_attributes {NFTA_NAT_REG_PROTO_MIN ,NFTA_NAT_REG_PROTO_MAX ,NFTA_NAT_FLAGS , +NFTA_NAT_REG_PROTO_BASE , __NFTA_NAT_MAX };#define NFTA_NAT_MAX (__NFTA_NAT_MAX - 1)
net/netfilter/nft_nat.c +27 -11
@@ -25,6 +25,7 @@ struct nft_nat {u8 sreg_addr_max;u8 sreg_proto_min;u8 sreg_proto_max; +u8 sreg_proto_base; enum nf_nat_manip_type type:8;u8 family;u16 flags;
@@ -58,6 +59,8 @@ static void nft_nat_setup_proto(struct nf_nat_range2 *range,nft_reg_load16 (®s->data[priv->sreg_proto_min]); range->max_proto.all = (__force __be16 )nft_reg_load16 (®s->data[priv->sreg_proto_max]); + range->base_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_base]); } static void nft_nat_setup_netmap(struct nf_nat_range2 *range,
@@ -126,13 +129,14 @@ static void nft_nat_eval(const struct nft_expr *expr, }static const struct nla_policy nft_nat_policy[NFTA_NAT_MAX +1 ] = { - [NFTA_NAT_TYPE ] = { .type =NLA_U32 }, - [NFTA_NAT_FAMILY ] = { .type =NLA_U32 }, - [NFTA_NAT_REG_ADDR_MIN ] = { .type =NLA_U32 }, - [NFTA_NAT_REG_ADDR_MAX ] = { .type =NLA_U32 }, - [NFTA_NAT_REG_PROTO_MIN ] = { .type =NLA_U32 }, - [NFTA_NAT_REG_PROTO_MAX ] = { .type =NLA_U32 }, - [NFTA_NAT_FLAGS ] = { .type =NLA_U32 }, + [NFTA_NAT_TYPE ] = { .type =NLA_U32 }, + [NFTA_NAT_FAMILY ] = { .type =NLA_U32 }, + [NFTA_NAT_REG_ADDR_MIN ] = { .type =NLA_U32 }, + [NFTA_NAT_REG_ADDR_MAX ] = { .type =NLA_U32 }, + [NFTA_NAT_REG_PROTO_MIN ] = { .type =NLA_U32 }, + [NFTA_NAT_REG_PROTO_MAX ] = { .type =NLA_U32 }, + [NFTA_NAT_REG_PROTO_BASE ] = { .type =NLA_U32 }, + [NFTA_NAT_FLAGS ] = { .type =NLA_U32 }, }; static int nft_nat_validate(const struct nft_ctx *ctx,
@@ -195,10 +199,10 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr,switch (family) {case NFPROTO_IPV4 : - alen = sizeof_field(struct nf_nat_range, min_addr.ip); + alen = sizeof_field(struct nf_nat_range2, min_addr.ip);break ;case NFPROTO_IPV6 : - alen = sizeof_field(struct nf_nat_range, min_addr.ip6); + alen = sizeof_field(struct nf_nat_range2, min_addr.ip6);break ;default :if (tb[NFTA_NAT_REG_ADDR_MIN ])
@@ -226,7 +230,7 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr, priv->flags |=NF_NAT_RANGE_MAP_IPS ; } - plen = sizeof_field(struct nf_nat_range, min_proto.all); + plen = sizeof_field(struct nf_nat_range2, min_proto.all);if (tb[NFTA_NAT_REG_PROTO_MIN ]) { err =nft_parse_register_load (tb[NFTA_NAT_REG_PROTO_MIN ], &priv->sreg_proto_min, plen);
@@ -239,6 +243,16 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr, plen);if (err <0 )return err; + +if (tb[NFTA_NAT_REG_PROTO_BASE ]) { + err =nft_parse_register_load + (tb[NFTA_NAT_REG_PROTO_BASE ], + &priv->sreg_proto_base, plen); +if (err <0 ) +return err; + + priv->flags |=NF_NAT_RANGE_PROTO_OFFSET ; + } }else { priv->sreg_proto_max = priv->sreg_proto_min; }
@@ -286,7 +300,9 @@ static int nft_nat_dump(struct sk_buff *skb,if (nft_dump_register (skb,NFTA_NAT_REG_PROTO_MIN , priv->sreg_proto_min) ||nft_dump_register (skb,NFTA_NAT_REG_PROTO_MAX , - priv->sreg_proto_max)) + priv->sreg_proto_max) || +nft_dump_register (skb,NFTA_NAT_REG_PROTO_BASE , + priv->sreg_proto_base)) goto nla_put_failure; }
Signature · 1 line
2.39.2
Florian Westphal
maintainerRe: [PATCH nf-next 05/13] netfilter: nft_nat: add support for shifted port-ranges
Quoted 12 lines · Jeremy Sowden
index
5c29915ab028..0517a3efb259100644net/netfilter/nft_nat.c +1
-0@@ -25,6 +25,7 @@ struct nft_nat {u8 sreg_addr_max;u8 sreg_proto_min;u8 sreg_proto_max; +u8 sreg_proto_base; enum nf_nat_manip_type type:8;u8 family;u16 flags;
net/netfilter/nft_nat.c static void nft_nat_setup_proto(struct nf_nat_range2 *range, · line 63
Quoted 5 lines
net/netfilter/nft_nat.c +2
-0@@ -58,6 +59,8 @@ static void nft_nat_setup_proto(struct nf_nat_range2 *range,nft_reg_load16 (®s->data[priv->sreg_proto_min]); range->max_proto.all = (__force __be16 )nft_reg_load16 (®s->data[priv->sreg_proto_max]); + range->base_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_base]);
Hmmm! See below.
Quoted 8 lines
net/netfilter/nft_nat.c +1
-1- plen = sizeof_field(struct nf_nat_range, min_proto.all); + plen = sizeof_field(struct nf_nat_range2, min_proto.all);if (tb[NFTA_NAT_REG_PROTO_MIN ]) { err = nft_parse_register_load(tb[NFTA_NAT_REG_PROTO_MIN],net/netfilter/nft_nat.c +0
-0&priv->sreg_proto_min, plen);@@ -239,6 +243,16 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr, plen);if (err <0 )
net/netfilter/nft_nat.c static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr, · line 254
Quoted 10 lines
net/netfilter/nft_nat.c +9
-0return err; + +if (tb[NFTA_NAT_REG_PROTO_BASE ]) { + err =nft_parse_register_load + (tb[NFTA_NAT_REG_PROTO_BASE ], + &priv->sreg_proto_base, plen); +if (err <0 ) +return err; + + priv->flags |=NF_NAT_RANGE_PROTO_OFFSET ;
So sreg_proto_base is only set if tb[NFTA_NAT_REG_PROTO_BASE] gets passed.
So, I would expect that all accesses to priv->sreg_proto_base are guarded with a 'if (priv->sreg_proto_base)' check.
net/netfilter/nft_nat.c static int nft_nat_dump(struct sk_buff *skb, · line 305
Quoted 8 lines
net/netfilter/nft_nat.c +3
-1@@ -286,7 +300,9 @@ static int nft_nat_dump(struct sk_buff *skb,if (nft_dump_register (skb,NFTA_NAT_REG_PROTO_MIN , priv->sreg_proto_min) ||nft_dump_register (skb,NFTA_NAT_REG_PROTO_MAX , - priv->sreg_proto_max)) + priv->sreg_proto_max) || +nft_dump_register (skb,NFTA_NAT_REG_PROTO_BASE , + priv->sreg_proto_base))
sreg_proto_min/max are only dumped when set, so NFTA_NAT_REG_PROTO_BASE should not be dumped unconditionally either?
Re: [PATCH nf-next 05/13] netfilter: nft_nat: add support for shifted port-ranges
Quoted 46 lines · Florian Westphal
Quoted 12 lines · Jeremy Sowden
index
5c29915ab028..0517a3efb259100644net/netfilter/nft_nat.c +1
-0@@ -25,6 +25,7 @@ struct nft_nat {u8 sreg_addr_max;u8 sreg_proto_min;u8 sreg_proto_max; +u8 sreg_proto_base; enum nf_nat_manip_type type:8;u8 family;u16 flags;net/netfilter/nft_nat.c static void nft_nat_setup_proto(struct nf_nat_range2 *range, · line 63
Quoted 5 lines
net/netfilter/nft_nat.c +2
-0@@ -58,6 +59,8 @@ static void nft_nat_setup_proto(struct nf_nat_range2 *range,nft_reg_load16 (®s->data[priv->sreg_proto_min]); range->max_proto.all = (__force __be16 )nft_reg_load16 (®s->data[priv->sreg_proto_max]); + range->base_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_base]);Hmmm! See below.
Quoted 8 lines
net/netfilter/nft_nat.c +1
-1- plen = sizeof_field(struct nf_nat_range, min_proto.all); + plen = sizeof_field(struct nf_nat_range2, min_proto.all);if (tb[NFTA_NAT_REG_PROTO_MIN ]) { err = nft_parse_register_load(tb[NFTA_NAT_REG_PROTO_MIN],net/netfilter/nft_nat.c +0
-0&priv->sreg_proto_min, plen);@@ -239,6 +243,16 @@ static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr, plen);if (err <0 )net/netfilter/nft_nat.c static int nft_nat_init(const struct nft_ctx *ctx, const struct nft_expr *expr, · line 254
Quoted 10 lines
net/netfilter/nft_nat.c +9
-0return err; + +if (tb[NFTA_NAT_REG_PROTO_BASE ]) { + err =nft_parse_register_load + (tb[NFTA_NAT_REG_PROTO_BASE ], + &priv->sreg_proto_base, plen); +if (err <0 ) +return err; + + priv->flags |=NF_NAT_RANGE_PROTO_OFFSET ;So
sreg_proto_baseis only set if tb[NFTA_NAT_REG_PROTO_BASE] gets passed.So, I would expect that all accesses to
priv->sreg_proto_baseare guarded with a 'if (priv->sreg_proto_base)' check.
Quoted 12 lines
net/netfilter/nft_nat.c static int nft_nat_dump(struct sk_buff *skb, · line 305
Quoted 8 lines
net/netfilter/nft_nat.c +3
-1@@ -286,7 +300,9 @@ static int nft_nat_dump(struct sk_buff *skb,if (nft_dump_register (skb,NFTA_NAT_REG_PROTO_MIN , priv->sreg_proto_min) ||nft_dump_register (skb,NFTA_NAT_REG_PROTO_MAX , - priv->sreg_proto_max)) + priv->sreg_proto_max) || +nft_dump_register (skb,NFTA_NAT_REG_PROTO_BASE , + priv->sreg_proto_base))sreg_proto_min/max are only dumped when set, so
NFTA_NAT_REG_PROTO_BASEshould not be dumped unconditionally either?
Agreed. Will fix.
J.
PATCH 6/13 netfilter: nft_masq: correct length for loading protocol registers
In reply to Jeremy SowdenThe values in the protocol registers are two bytes wide. However, when parsing the register loads, the code currently uses the larger 16-byte size of a union nf_inet_addr. Change it to use the (correct) size of a union nf_conntrack_man_proto instead.
--- net/netfilter/nft_masq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_masq.c +1 -1
@@ -43,7 +43,7 @@ static int nft_masq_init(const struct nft_ctx *ctx,const struct nft_expr *expr, const struct nlattr * const tb[]) { - u32 plen = sizeof_field(struct nf_nat_range, min_addr.all); + u32 plen = sizeof_field(struct nf_nat_range, min_proto.all);struct nft_masq *priv =nft_expr_priv (expr);int err;
Signature · 1 line
2.39.2
PATCH 7/13 netfilter: nft_masq: deduplicate eval call-backs
In reply to Jeremy Sowdennft_masq has separate ipv4 and ipv6 call-backs which share much of their code, and an inet one switch containing a switch that calls one of the others based on the family of the packet. Merge the ipv4 and ipv6 ones into the inet one in order to get rid of the duplicate code.
Const-qualify the priv pointer since we don't need to write through it.
--- net/netfilter/nft_masq.c | 75 ++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 46 deletions(-)
net/netfilter/nft_masq.c +29 -46
@@ -96,23 +96,39 @@ static int nft_masq_dump(struct sk_buff *skb,return -1 ; } -static void nft_masq_ipv4_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) +static void nft_masq_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt) { -struct nft_masq *priv =nft_expr_priv (expr); +const struct nft_masq *priv =nft_expr_priv (expr);struct nf_nat_range2 range;memset (&range,0 ,sizeof (range)); range.flags = priv->flags;if (priv->sreg_proto_min) { - range.min_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_min]); - range.max_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_max]); + range.min_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_min]); + range.max_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_max]); + } + +switch (nft_pf (pkt)) { +case NFPROTO_IPV4 : + regs->verdict.code =nf_nat_masquerade_ipv4 (pkt->skb, +nft_hook (pkt), + &range, +nft_out (pkt)); +break ; +#ifdef CONFIG_NF_TABLES_IPV6 +case NFPROTO_IPV6 : + regs->verdict.code =nf_nat_masquerade_ipv6 (pkt->skb, &range, +nft_out (pkt)); +break ; +#endif +default : +WARN_ON_ONCE (1 ); +break ; } - regs->verdict.code =nf_nat_masquerade_ipv4 (pkt->skb,nft_hook (pkt), - &range,nft_out (pkt)); } static void
@@ -125,7 +141,7 @@ static struct nft_expr_type nft_masq_ipv4_type;static const struct nft_expr_ops nft_masq_ipv4_ops = { .type = &nft_masq_ipv4_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_masq )), - .eval = nft_masq_ipv4_eval, + .eval = nft_masq_eval, .init = nft_masq_init, .destroy = nft_masq_ipv4_destroy, .dump = nft_masq_dump,
@@ -143,25 +159,6 @@ static struct nft_expr_type nft_masq_ipv4_type __read_mostly = { };#ifdef CONFIG_NF_TABLES_IPV6 -static void nft_masq_ipv6_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) -{ -struct nft_masq *priv =nft_expr_priv (expr); -struct nf_nat_range2 range; - -memset (&range,0 ,sizeof (range)); - range.flags = priv->flags; -if (priv->sreg_proto_min) { - range.min_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_min]); - range.max_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_max]); - } - regs->verdict.code =nf_nat_masquerade_ipv6 (pkt->skb, &range, -nft_out (pkt)); -} -static void nft_masq_ipv6_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr) {
@@ -172,7 +169,7 @@ static struct nft_expr_type nft_masq_ipv6_type;static const struct nft_expr_ops nft_masq_ipv6_ops = { .type = &nft_masq_ipv6_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_masq )), - .eval = nft_masq_ipv6_eval, + .eval = nft_masq_eval, .init = nft_masq_init, .destroy = nft_masq_ipv6_destroy, .dump = nft_masq_dump,
@@ -204,20 +201,6 @@ static inline void nft_masq_module_exit_ipv6(void) {}#endif #ifdef CONFIG_NF_TABLES_INET -static void nft_masq_inet_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) -{ -switch (nft_pf (pkt)) { -case NFPROTO_IPV4 : -return nft_masq_ipv4_eval (expr, regs, pkt); -case NFPROTO_IPV6 : -return nft_masq_ipv6_eval (expr, regs, pkt); - } - -WARN_ON_ONCE (1 ); -} -static void nft_masq_inet_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr) {
@@ -228,7 +211,7 @@ static struct nft_expr_type nft_masq_inet_type;static const struct nft_expr_ops nft_masq_inet_ops = { .type = &nft_masq_inet_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_masq )), - .eval = nft_masq_inet_eval, + .eval = nft_masq_eval, .init = nft_masq_init, .destroy = nft_masq_inet_destroy, .dump = nft_masq_dump,
Signature · 1 line
2.39.2
PATCH 8/13 netfilter: nft_masq: add support for shifted port-ranges
In reply to Jeremy SowdenSupport was recently added to nft_nat to allow shifting port-ranges during NAT. Extend this support to allow them to used in masquerading as well.
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_nat_masquerade.c | 2 ++ net/netfilter/nft_masq.c | 22 ++++++++++++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -1470,12 +1470,14 @@ enum nft_tproxy_attributes {* @NFTA_MASQ_FLAGS: NAT flags (see NF_NAT_RANGE_* in linux/netfilter/nf_nat.h) (NLA_U32) * @NFTA_MASQ_REG_PROTO_MIN: source register of proto range start (NLA_U32: nft_registers) * @NFTA_MASQ_REG_PROTO_MAX: source register of proto range end (NLA_U32: nft_registers) +* @NFTA_MASQ_REG_PROTO_BASE: source register of proto range base offset (NLA_U32: nft_registers) */ enum nft_masq_attributes {NFTA_MASQ_UNSPEC ,NFTA_MASQ_FLAGS ,NFTA_MASQ_REG_PROTO_MIN ,NFTA_MASQ_REG_PROTO_MAX , +NFTA_MASQ_REG_PROTO_BASE , __NFTA_MASQ_MAX };#define NFTA_MASQ_MAX (__NFTA_MASQ_MAX - 1)
net/netfilter/nf_nat_masquerade.c +2 -0
@@ -69,6 +69,7 @@ nf_nat_masquerade_ipv4(struct sk_buff *skb, unsigned int hooknum, newrange.max_addr.ip = newsrc; newrange.min_proto = range->min_proto; newrange.max_proto = range->max_proto; + newrange.base_proto = range->base_proto;/* Hand modified range to generic setup. */ return nf_nat_setup_info (ct, &newrange,NF_NAT_MANIP_SRC );
@@ -264,6 +265,7 @@ nf_nat_masquerade_ipv6(struct sk_buff *skb, const struct nf_nat_range2 *range, newrange.max_addr.in6 = src; newrange.min_proto = range->min_proto; newrange.max_proto = range->max_proto; + newrange.base_proto = range->base_proto;return nf_nat_setup_info (ct, &newrange,NF_NAT_MANIP_SRC ); }
net/netfilter/nft_masq.c +20 -2
@@ -17,12 +17,14 @@ struct nft_masq {u32 flags;u8 sreg_proto_min;u8 sreg_proto_max; +u8 sreg_proto_base; };static const struct nla_policy nft_masq_policy[NFTA_MASQ_MAX +1 ] = { [NFTA_MASQ_FLAGS ] = { .type =NLA_U32 }, [NFTA_MASQ_REG_PROTO_MIN ] = { .type =NLA_U32 }, [NFTA_MASQ_REG_PROTO_MAX ] = { .type =NLA_U32 }, + [NFTA_MASQ_REG_PROTO_BASE ] = { .type =NLA_U32 }, }; static int nft_masq_validate(const struct nft_ctx *ctx,
@@ -43,7 +45,7 @@ static int nft_masq_init(const struct nft_ctx *ctx,const struct nft_expr *expr, const struct nlattr * const tb[]) { - u32 plen = sizeof_field(struct nf_nat_range, min_proto.all); + u32 plen = sizeof_field(struct nf_nat_range2, min_proto.all);struct nft_masq *priv =nft_expr_priv (expr);int err;
@@ -65,9 +67,21 @@ static int nft_masq_init(const struct nft_ctx *ctx, plen);if (err <0 )return err; + +if (tb[NFTA_MASQ_REG_PROTO_BASE ]) { + err =nft_parse_register_load + (tb[NFTA_MASQ_REG_PROTO_BASE ], + &priv->sreg_proto_base, plen); +if (err <0 ) +return err; + + priv->flags |=NF_NAT_RANGE_PROTO_OFFSET ; + } }else { priv->sreg_proto_max = priv->sreg_proto_min; } + + priv->flags |=NF_NAT_RANGE_PROTO_SPECIFIED ; }return nf_ct_netns_get (ctx->net, ctx->family);
@@ -86,7 +100,9 @@ static int nft_masq_dump(struct sk_buff *skb,if (nft_dump_register (skb,NFTA_MASQ_REG_PROTO_MIN , priv->sreg_proto_min) ||nft_dump_register (skb,NFTA_MASQ_REG_PROTO_MAX , - priv->sreg_proto_max)) + priv->sreg_proto_max) || +nft_dump_register (skb,NFTA_MASQ_REG_PROTO_BASE , + priv->sreg_proto_base)) goto nla_put_failure; }
@@ -110,6 +126,8 @@ static void nft_masq_eval(const struct nft_expr *expr,nft_reg_load16 (®s->data[priv->sreg_proto_min]); range.max_proto.all = (__force __be16 )nft_reg_load16 (®s->data[priv->sreg_proto_max]); + range.base_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_base]); }switch (nft_pf (pkt)) {
Signature · 1 line
2.39.2
PATCH 9/13 netfilter: nft_redir: correct value of inet type `.maxattrs`
In reply to Jeremy Sowdennft_redir_inet_type.maxattrs was being set, presumably because of a cut-and-paste error, to NFTA_MASQ_MAX, instead of NFTA_REDIR_MAX.
--- net/netfilter/nft_redir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_redir.c +1 -1
@@ -236,7 +236,7 @@ static struct nft_expr_type nft_redir_inet_type __read_mostly = { .name = "redir", .ops = &nft_redir_inet_ops, .policy = nft_redir_policy, - .maxattr = NFTA_MASQ_MAX, + .maxattr = NFTA_REDIR_MAX, .owner = THIS_MODULE, };
Signature · 1 line
2.39.2
PATCH 10/13 netfilter: nf_nat_redirect: use `struct nf_nat_range2` in ipv4 API
In reply to Jeremy Sowdennf_nat_redirect_ipv4 takes a struct nf_nat_ipv4_multi_range_compat, but converts it internally to a struct nf_nat_range2. Change the function to take the latter, factor out the code now shared with nf_nat_redirect_ipv6, move the conversion to the xt_REDIRECT module, and update the ipv4 range initialization in the nft_redir module.
Replace a bare hex constant for 127.0.0.1 with a macro.
--- include/net/netfilter/nf_nat_redirect.h | 3 +- net/netfilter/nf_nat_redirect.c | 58 ++++++++++++------------- net/netfilter/nft_redir.c | 15 ++++--- net/netfilter/xt_REDIRECT.c | 10 ++++- 4 files changed, 44 insertions(+), 42 deletions(-)
include/net/netfilter/nf_nat_redirect.h +1 -2
@@ -6,8 +6,7 @@#include <uapi/linux/netfilter/nf_nat.h> unsigned int -nf_nat_redirect_ipv4 (struct sk_buff *skb, -const struct nf_nat_ipv4_multi_range_compat *mr, +nf_nat_redirect_ipv4 (struct sk_buff *skb,const struct nf_nat_range2 *range,unsigned int hooknum); unsigned int nf_nat_redirect_ipv6(struct sk_buff *skb, const struct nf_nat_range2 *range,
net/netfilter/nf_nat_redirect.c +27 -31
99 lines not on this page · raw message
net/netfilter/nft_redir.c +8 -7
@@ -104,20 +104,21 @@ static void nft_redir_ipv4_eval(const struct nft_expr *expr, const struct nft_pktinfo *pkt) {struct nft_redir *priv =nft_expr_priv (expr); -struct nf_nat_ipv4_multi_range_compat mr; +struct nf_nat_range2 range; -memset (&mr,0 ,sizeof (mr)); +memset (&range,0 ,sizeof (range));if (priv->sreg_proto_min) { - mr.range[0 ].min.all = (__force __be16 )nft_reg_load16 ( + range.min_proto.all = (__force __be16 )nft_reg_load16 ( ®s->data[priv->sreg_proto_min]); - mr.range[0 ].max.all = (__force __be16 )nft_reg_load16 ( + range.max_proto.all = (__force __be16 )nft_reg_load16 ( ®s->data[priv->sreg_proto_max]); - mr.range[0 ].flags |=NF_NAT_RANGE_PROTO_SPECIFIED ; + range.flags |=NF_NAT_RANGE_PROTO_SPECIFIED ; } - mr.range[0 ].flags |= priv->flags; + range.flags |= priv->flags; - regs->verdict.code =nf_nat_redirect_ipv4 (pkt->skb, &mr,nft_hook (pkt)); + regs->verdict.code = +nf_nat_redirect_ipv4 (pkt->skb, &range,nft_hook (pkt)); } static void
net/netfilter/xt_REDIRECT.c +8 -2
@@ -46,7 +46,6 @@ static void redirect_tg_destroy(const struct xt_tgdtor_param *par)nf_ct_netns_put (par->net, par->family); } -/* FIXME: Take multiple ranges --RR */ static int redirect_tg4_check (const struct xt_tgchk_param *par) {const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo;
@@ -65,7 +64,14 @@ static int redirect_tg4_check(const struct xt_tgchk_param *par)static unsigned int redirect_tg4 (struct sk_buff *skb,const struct xt_action_param *par) { -return nf_nat_redirect_ipv4 (skb, par->targinfo,xt_hooknum (par)); +const struct nf_nat_ipv4_multi_range_compat *mr = par->targinfo; +struct nf_nat_range2 range = { + .flags = mr->range[0 ].flags, + .min_proto = mr->range[0 ].min, + .max_proto = mr->range[0 ].max, + }; + +return nf_nat_redirect_ipv4 (skb, &range,xt_hooknum (par)); }static struct xt_target redirect_tg_reg[]__read_mostly = {
Signature · 1 line
2.39.2
Re: [PATCH nf-next 10/13] netfilter: nf_nat_redirect: use `struct nf_nat_range2` in ipv4 API
Quoted 5 lines · Jeremy Sowden
nf_nat_redirect_ipv4takes astruct nf_nat_ipv4_multi_range_compat, but converts it internally to astruct nf_nat_range2. Change the function to take the latter, factor out the code now shared withnf_nat_redirect_ipv6, move the conversion to thext_REDIRECTmodule, and update the ipv4 range initialization in thenft_redirmodule.
PATCH 11/13 netfilter: nft_redir: correct length for loading protocol registers
In reply to Jeremy SowdenThe values in the protocol registers are two bytes wide. However, when parsing the register loads, the code currently uses the larger 16-byte size of a union nf_inet_addr. Change it to use the (correct) size of a union nf_conntrack_man_proto instead.
--- net/netfilter/nft_redir.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/nft_redir.c +1 -1
@@ -48,7 +48,7 @@ static int nft_redir_init(const struct nft_ctx *ctx,unsigned int plen;int err; - plen = sizeof_field(struct nf_nat_range, min_addr.all); + plen = sizeof_field(struct nf_nat_range, min_proto.all);if (tb[NFTA_REDIR_REG_PROTO_MIN ]) { err =nft_parse_register_load (tb[NFTA_REDIR_REG_PROTO_MIN ], &priv->sreg_proto_min, plen);
Signature · 1 line
2.39.2
PATCH 12/13 netfilter: nft_redir: deduplicate eval call-backs
In reply to Jeremy Sowdennft_redir has separate ipv4 and ipv6 call-backs which share much of their code, and an inet one switch containing a switch that calls one of the others based on the family of the packet. Merge the ipv4 and ipv6 ones into the inet one in order to get rid of the duplicate code.
Const-qualify the priv pointer since we don't need to write through it.
Set the NF_NAT_RANGE_PROTO_SPECIFIED flag once during init, rather than on every eval.
--- net/netfilter/nft_redir.c | 78 ++++++++++++++------------------------- 1 file changed, 28 insertions(+), 50 deletions(-)
net/netfilter/nft_redir.c +28 -50
@@ -64,6 +64,8 @@ static int nft_redir_init(const struct nft_ctx *ctx, }else { priv->sreg_proto_max = priv->sreg_proto_min; } + + priv->flags |=NF_NAT_RANGE_PROTO_SPECIFIED ; }if (tb[NFTA_REDIR_FLAGS ]) {
@@ -99,26 +101,38 @@ static int nft_redir_dump(struct sk_buff *skb,return -1 ; } -static void nft_redir_ipv4_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) +static void nft_redir_eval (const struct nft_expr *expr, +struct nft_regs *regs, +const struct nft_pktinfo *pkt) { -struct nft_redir *priv =nft_expr_priv (expr); +const struct nft_redir *priv =nft_expr_priv (expr);struct nf_nat_range2 range;memset (&range,0 ,sizeof (range));if (priv->sreg_proto_min) { - range.min_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_min]); - range.max_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_max]); - range.flags |=NF_NAT_RANGE_PROTO_SPECIFIED ; + range.min_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_min]); + range.max_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_max]); } range.flags |= priv->flags; - regs->verdict.code = -nf_nat_redirect_ipv4 (pkt->skb, &range,nft_hook (pkt)); +switch (nft_pf (pkt)) { +case NFPROTO_IPV4 : + regs->verdict.code =nf_nat_redirect_ipv4 (pkt->skb, &range, +nft_hook (pkt)); +break ; +#ifdef CONFIG_NF_TABLES_IPV6 +case NFPROTO_IPV6 : + regs->verdict.code =nf_nat_redirect_ipv6 (pkt->skb, &range, +nft_hook (pkt)); +break ; +#endif +default : +WARN_ON_ONCE (1 ); +break ; + } } static void
@@ -131,7 +145,7 @@ static struct nft_expr_type nft_redir_ipv4_type;static const struct nft_expr_ops nft_redir_ipv4_ops = { .type = &nft_redir_ipv4_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_redir )), - .eval = nft_redir_ipv4_eval, + .eval = nft_redir_eval, .init = nft_redir_init, .destroy = nft_redir_ipv4_destroy, .dump = nft_redir_dump,
@@ -149,28 +163,6 @@ static struct nft_expr_type nft_redir_ipv4_type __read_mostly = { };#ifdef CONFIG_NF_TABLES_IPV6 -static void nft_redir_ipv6_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) -{ -struct nft_redir *priv =nft_expr_priv (expr); -struct nf_nat_range2 range; - -memset (&range,0 ,sizeof (range)); -if (priv->sreg_proto_min) { - range.min_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_min]); - range.max_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_max]); - range.flags |=NF_NAT_RANGE_PROTO_SPECIFIED ; - } - - range.flags |= priv->flags; - - regs->verdict.code = -nf_nat_redirect_ipv6 (pkt->skb, &range,nft_hook (pkt)); -} -static void nft_redir_ipv6_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr) {
@@ -181,7 +173,7 @@ static struct nft_expr_type nft_redir_ipv6_type;static const struct nft_expr_ops nft_redir_ipv6_ops = { .type = &nft_redir_ipv6_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_redir )), - .eval = nft_redir_ipv6_eval, + .eval = nft_redir_eval, .init = nft_redir_init, .destroy = nft_redir_ipv6_destroy, .dump = nft_redir_dump,
@@ -200,20 +192,6 @@ static struct nft_expr_type nft_redir_ipv6_type __read_mostly = {#endif #ifdef CONFIG_NF_TABLES_INET -static void nft_redir_inet_eval (const struct nft_expr *expr, -struct nft_regs *regs, -const struct nft_pktinfo *pkt) -{ -switch (nft_pf (pkt)) { -case NFPROTO_IPV4 : -return nft_redir_ipv4_eval (expr, regs, pkt); -case NFPROTO_IPV6 : -return nft_redir_ipv6_eval (expr, regs, pkt); - } - -WARN_ON_ONCE (1 ); -} -static void nft_redir_inet_destroy (const struct nft_ctx *ctx,const struct nft_expr *expr) {
@@ -224,7 +202,7 @@ static struct nft_expr_type nft_redir_inet_type;static const struct nft_expr_ops nft_redir_inet_ops = { .type = &nft_redir_inet_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_redir )), - .eval = nft_redir_inet_eval, + .eval = nft_redir_eval, .init = nft_redir_init, .destroy = nft_redir_inet_destroy, .dump = nft_redir_dump,
Signature · 1 line
2.39.2
Re: [PATCH nf-next 12/13] netfilter: nft_redir: deduplicate eval call-backs
Quoted 10 lines · Jeremy Sowden
nft_redirhas separate ipv4 and ipv6 call-backs which share much of their code, and an inet one switch containing a switch that calls one of the others based on the family of the packet. Merge the ipv4 and ipv6 ones into the inet one in order to get rid of the duplicate code.Const-qualify the
privpointer since we don't need to write through it.Set the
NF_NAT_RANGE_PROTO_SPECIFIEDflag once during init, rather than on every eval.
Quoted 8 lines
net/netfilter/nft_redir.c +1
-3-struct nft_redir *priv =nft_expr_priv (expr); +const struct nft_redir *priv =nft_expr_priv (expr);struct nf_nat_range2 range;memset (&range,0 ,sizeof (range));if (priv->sreg_proto_min) { - range.min_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_min]);
net/netfilter/nft_redir.c static int nft_redir_dump(struct sk_buff *skb, · line 119
Quoted 10 lines
net/netfilter/nft_redir.c +4
-3- range.max_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_max]); - range.flags |=NF_NAT_RANGE_PROTO_SPECIFIED ; + range.min_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_min]); + range.max_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_max]); } range.flags |= priv->flags;
Nit: This could be updated to 'range.flags = priv->flags'
Re: [PATCH nf-next 12/13] netfilter: nft_redir: deduplicate eval call-backs
Quoted 31 lines · Florian Westphal
Quoted 10 lines · Jeremy Sowden
nft_redirhas separate ipv4 and ipv6 call-backs which share much of their code, and an inet one switch containing a switch that calls one of the others based on the family of the packet. Merge the ipv4 and ipv6 ones into the inet one in order to get rid of the duplicate code.Const-qualify the
privpointer since we don't need to write through it.Set the
NF_NAT_RANGE_PROTO_SPECIFIEDflag once during init, rather than on every eval.Reviewed-by Florian Westphal <[email protected]>Quoted 17 lines
net/netfilter/nft_redir.c +5
-6-struct nft_redir *priv =nft_expr_priv (expr); +const struct nft_redir *priv =nft_expr_priv (expr);struct nf_nat_range2 range;memset (&range,0 ,sizeof (range));if (priv->sreg_proto_min) { - range.min_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_min]); - range.max_proto.all = (__force __be16 )nft_reg_load16 ( - ®s->data[priv->sreg_proto_max]); - range.flags |=NF_NAT_RANGE_PROTO_SPECIFIED ; + range.min_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_min]); + range.max_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_max]); }
Quoted 3 lines
Quoted 1 line
range.flags |=
priv->flags;Nit: This could be updated to 'range.flags =
priv->flags'
Will fix.
J.
PATCH 13/13 netfilter: nft_redir: add support for shifted port-ranges
In reply to Jeremy SowdenSupport was recently added to nft_nat to allow shifting port-ranges during NAT. Extend this support to allow them to used in redirecting as well.
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_nat_redirect.c | 1 + net/netfilter/nft_redir.c | 19 ++++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -1488,12 +1488,14 @@ enum nft_masq_attributes {* @NFTA_REDIR_REG_PROTO_MIN: source register of proto range start (NLA_U32: nft_registers) * @NFTA_REDIR_REG_PROTO_MAX: source register of proto range end (NLA_U32: nft_registers) * @NFTA_REDIR_FLAGS: NAT flags (see NF_NAT_RANGE_* in linux/netfilter/nf_nat.h) (NLA_U32) +* @NFTA_REDIR_REG_PROTO_BASE: source register of proto range base offset (NLA_U32: nft_registers) */ enum nft_redir_attributes {NFTA_REDIR_UNSPEC ,NFTA_REDIR_REG_PROTO_MIN ,NFTA_REDIR_REG_PROTO_MAX ,NFTA_REDIR_FLAGS , +NFTA_REDIR_REG_PROTO_BASE , __NFTA_REDIR_MAX };#define NFTA_REDIR_MAX (__NFTA_REDIR_MAX - 1)
net/netfilter/nf_nat_redirect.c +1 -0
@@ -41,6 +41,7 @@ nf_nat_redirect(struct sk_buff *skb, const struct nf_nat_range2 *range, newrange.max_addr = *newdst; newrange.min_proto = range->min_proto; newrange.max_proto = range->max_proto; + newrange.base_proto = range->base_proto;return nf_nat_setup_info (ct, &newrange,NF_NAT_MANIP_DST ); }
net/netfilter/nft_redir.c +18 -1
@@ -16,12 +16,14 @@struct nft_redir {u8 sreg_proto_min;u8 sreg_proto_max; +u8 sreg_proto_base;u16 flags; };static const struct nla_policy nft_redir_policy[NFTA_REDIR_MAX +1 ] = { [NFTA_REDIR_REG_PROTO_MIN ] = { .type =NLA_U32 }, [NFTA_REDIR_REG_PROTO_MAX ] = { .type =NLA_U32 }, + [NFTA_REDIR_REG_PROTO_BASE ] = { .type =NLA_U32 }, [NFTA_REDIR_FLAGS ] = { .type =NLA_U32 }, };
@@ -48,7 +50,7 @@ static int nft_redir_init(const struct nft_ctx *ctx,unsigned int plen;int err; - plen = sizeof_field(struct nf_nat_range, min_proto.all); + plen = sizeof_field(struct nf_nat_range2, min_proto.all);if (tb[NFTA_REDIR_REG_PROTO_MIN ]) { err =nft_parse_register_load (tb[NFTA_REDIR_REG_PROTO_MIN ], &priv->sreg_proto_min, plen);
@@ -61,6 +63,16 @@ static int nft_redir_init(const struct nft_ctx *ctx, plen);if (err <0 )return err; + +if (tb[NFTA_REDIR_REG_PROTO_BASE ]) { + err =nft_parse_register_load + (tb[NFTA_REDIR_REG_PROTO_BASE ], + &priv->sreg_proto_base, plen); +if (err <0 ) +return err; + + priv->flags |=NF_NAT_RANGE_PROTO_OFFSET ; + } }else { priv->sreg_proto_max = priv->sreg_proto_min; }
@@ -89,6 +101,9 @@ static int nft_redir_dump(struct sk_buff *skb,if (nft_dump_register (skb,NFTA_REDIR_REG_PROTO_MAX , priv->sreg_proto_max)) goto nla_put_failure; +if (nft_dump_register (skb,NFTA_REDIR_REG_PROTO_BASE , + priv->sreg_proto_base)) + goto nla_put_failure; } if (priv->flags != 0 &&
@@ -114,6 +129,8 @@ static void nft_redir_eval(const struct nft_expr *expr,nft_reg_load16 (®s->data[priv->sreg_proto_min]); range.max_proto.all = (__force __be16 )nft_reg_load16 (®s->data[priv->sreg_proto_max]); + range.base_proto.all = (__force __be16 ) +nft_reg_load16 (®s->data[priv->sreg_proto_base]); } range.flags |= priv->flags;
Signature · 1 line
2.39.2
Florian Westphal
maintainerQuoted 5 lines · Jeremy Sowden
Jeremy Sowden (13):
netfilter:nft_nat: correct length for loading protocol registers
netfilter:nft_masq: correct length for loading protocol registers
netfilter:nft_redir: correct value of inet type.maxattrs
netfilter:nft_redir: correct length for loading protocol registers
I think the fixess above should be routed through the 'nf' tree, I don't see why we need to hold them in -next trees for another 3 months.
Quoted 11 lines · Florian Westphal
Quoted 6 lines · Jeremy Sowden
Jeremy Sowden (13):
netfilter:nft_nat: correct length for loading protocol registers
netfilter:nft_masq: correct length for loading protocol registers
netfilter:nft_redir: correct value of inet type.maxattrs
netfilter:nft_redir: correct length for loading protocol registersI think the fixess above should be routed through the 'nf' tree, I don't see why we need to hold them in -next trees for another 3 months.
When I send v2, I'll separate these out.
J.