net: flow_offload: mangle 128-bit packet field with one action
Subsystems (8)
Pablo Neira Ayuso
maintainerPATCH 1/2 net: flow_offload: mangle 128-bit packet field with one action
The existing infrastructure needs the front-end to generate up to four actions (one for each 32-bit word) to mangle an IPv6 address. This patch allows you to mangle fields than are longer than 4-bytes with one single action. Drivers have been adapted to this new representation following a simple approach, that is, iterate over the array of words and configure the hardware IR to make the packet mangling. FLOW_ACTION_MANGLE_MAX_WORDS defines the maximum number of words from one given offset (currently 4 words).
--- .../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 44 ++++++++++---- drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 50 +++++++++++----- drivers/net/ethernet/netronome/nfp/flower/action.c | 69 ++++++++++++++-------- include/net/flow_offload.h | 9 ++- net/sched/cls_api.c | 7 ++- 5 files changed, 125 insertions(+), 54 deletions(-)
drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c +32 -12
@@ -428,13 +428,17 @@ static void cxgb4_process_flow_actions(struct net_device *in,case FLOW_ACTION_MANGLE : {u32 mask, val, offset;u8 htype; +int i; htype = act->mangle.htype; - mask = act->mangle.mask; - val = act->mangle.val; offset = act->mangle.offset; -process_pedit_field (fs, val, mask, offset, htype); +for (i =0 ; i < act->mangle.words; i++) { + mask = act->mangle.data[i].mask; + val = act->mangle.data[i].val; +process_pedit_field (fs, val, mask, offset, htype); + offset +=sizeof (u32); + } }break ;default :
@@ -456,16 +460,9 @@ static bool valid_l4_mask(u32 mask)return hi && lo ? false : true; } -static bool valid_pedit_action (struct net_device *dev, -const struct flow_action_entry *act) +static bool __valid_pedit_action (struct net_device *dev,u8 htype, +__be32 mask,__be32 offset) { -u32 mask, offset; -u8 htype; - - htype = act->mangle.htype; - mask = act->mangle.mask; - offset = act->mangle.offset; -switch (htype) {case FLOW_ACT_MANGLE_HDR_TYPE_ETH :switch (offset) {
@@ -541,6 +538,29 @@ static bool valid_pedit_action(struct net_device *dev,netdev_err (dev,"%s: Unsupported pedit type\n" , __func__);return false; } + +return true; +} + +static bool valid_pedit_action (struct net_device *dev, +const struct flow_action_entry *act) +{ +u32 mask, offset; +u8 htype; +int i; + + htype = act->mangle.htype; + offset = act->mangle.offset; + +for (i =0 ; i < act->mangle.words; i++) { + mask = act->mangle.data[i].mask; + +if (!__valid_pedit_action (dev, htype, mask, offset)) +return false; + + offset +=sizeof (u32); + } +return true; }
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +35 -15
84 lines not on this page · raw message
drivers/net/ethernet/netronome/nfp/flower/action.c +46 -23
144 lines not on this page · raw message
include/net/flow_offload.h +7 -2
@@ -153,6 +153,8 @@ enum flow_action_mangle_base { FLOW_ACT_MANGLE_HDR_TYPE_UDP, }; +#define FLOW_ACTION_MANGLE_MAX_WORDS 4 +struct flow_action_entry {enum flow_action_id id;union {
@@ -166,8 +168,11 @@ struct flow_action_entry {struct {/* FLOW_ACTION_PACKET_EDIT */ enum flow_action_mangle_base htype;u32 offset; -u32 mask; -u32 val; +struct { +u32 mask; +u32 val; + } data[FLOW_ACTION_MANGLE_MAX_WORDS ]; +u32 words; } mangle;const struct ip_tunnel_info *tunnel;/* FLOW_ACTION_TUNNEL_ENCAP */ u32 csum_flags;/* FLOW_ACTION_CSUM */
net/sched/cls_api.c +5 -2
@@ -3077,9 +3077,12 @@ int tc_setup_flow_action(struct flow_action *flow_action, goto err_out; } entry->mangle.htype =tcf_pedit_htype (act, k); - entry->mangle.mask =tcf_pedit_mask (act, k); - entry->mangle.val =tcf_pedit_val (act, k); + entry->mangle.data[0 ].mask = +tcf_pedit_mask (act, k); + entry->mangle.data[0 ].val = +tcf_pedit_val (act, k); entry->mangle.offset =tcf_pedit_offset (act, k); + entry->mangle.words =1 ; entry = &flow_action->entries[++j]; } }else if (is_tcf_csum (act)) {
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/2 netfilter: nft_payload: packet mangling offload support
This patch allows for mangling packet fields using hardware offload infrastructure.
--- net/netfilter/nft_payload.c | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+)
net/netfilter/nft_payload.c +82 -0
@@ -562,12 +562,94 @@ static int nft_payload_set_dump(struct sk_buff *skb, const struct nft_expr *exprreturn -1 ; } +static int nft_payload_offload_set_nh (struct nft_offload_ctx *ctx, +struct nft_flow_rule *flow, +const struct nft_payload_set *priv) +{ +int type =FLOW_ACT_MANGLE_UNSPEC ; + +switch (ctx->dep.l3num) { +case htons (ETH_P_IP ): + type =FLOW_ACT_MANGLE_HDR_TYPE_IP4 ; +break ; +case htons (ETH_P_IPV6 ): + type =FLOW_ACT_MANGLE_HDR_TYPE_IP6 ; +break ; + } + +return type; +} + +static int nft_payload_offload_set_th (struct nft_offload_ctx *ctx, +struct nft_flow_rule *flow, +const struct nft_payload_set *priv) +{ +int type =FLOW_ACT_MANGLE_UNSPEC ; + +switch (ctx->dep.protonum) { +case IPPROTO_TCP : + type =FLOW_ACT_MANGLE_HDR_TYPE_TCP ; +break ; +case IPPROTO_UDP : + type =FLOW_ACT_MANGLE_HDR_TYPE_UDP ; +break ; + } + +return type; +} + +static inline u32 nft_payload_mask (int len) +{ +return (1 << (len *BITS_PER_BYTE )) -1 ; +} + +static int nft_payload_set_offload (struct nft_offload_ctx *ctx, +struct nft_flow_rule *flow, +const struct nft_expr *expr) +{ +const struct nft_payload_set *priv =nft_expr_priv (expr); +struct nft_offload_reg *sreg = &ctx->regs[priv->sreg]; +int type =FLOW_ACT_MANGLE_UNSPEC ; +struct flow_action_entry *entry; +u32 words; +int i; + +switch (priv->base) { +case NFT_PAYLOAD_LL_HEADER : + type =FLOW_ACT_MANGLE_HDR_TYPE_ETH ; +break ; +case NFT_PAYLOAD_NETWORK_HEADER : + type =nft_payload_offload_set_nh (ctx, flow, priv); +break ; +case NFT_PAYLOAD_TRANSPORT_HEADER : + type =nft_payload_offload_set_th (ctx, flow, priv); +break ; +default : +WARN_ON_ONCE (1 ); +break ; + } + words =round_up (priv->len,sizeof (u32)) /sizeof (u32); + + entry = &flow->rule->action.entries[ctx->num_actions++]; + entry->mangle.htype = type; + entry->mangle.offset = priv->offset; +for (i =0 ; i < words; i++) { + entry->mangle.data[i].mask = + ~htonl (nft_payload_mask (priv->len)); + entry->mangle.data[i].val = sreg->data.data[i]; + } + entry->mangle.words = words; + +return type !=FLOW_ACT_MANGLE_UNSPEC ?0 : -EOPNOTSUPP ; +} +static const struct nft_expr_ops nft_payload_set_ops = { .type = &nft_payload_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_payload_set )), .eval = nft_payload_set_eval, .init = nft_payload_set_init, .dump = nft_payload_set_dump, + .offload = nft_payload_set_offload, }; static const struct nft_expr_ops *
Signature · 1 line
2.11.0
Quoted 10 lines · Pablo Neira Ayuso
The existing infrastructure needs the front-end to generate up to four actions (one for each 32-bit word) to mangle an IPv6 address. This patch allows you to mangle fields than are longer than 4-bytes with one single action. Drivers have been adapted to this new representation following a simple approach, that is, iterate over the array of words and configure the hardware IR to make the packet mangling.
FLOW_ACTION_MANGLE_MAX_WORDSdefines the maximum number of words from one given offset (currently 4 words).Signed-off-by Pablo Neira Ayuso <[email protected]>
What's the point of this?
Why do you need to be able to do this with a single action? It doesn't look like this extra 70 lines of code is actually buying you anything, and it makes more work for any other drivers that want to implement the offload API.
Pablo Neira Ayuso
maintainerQuoted 10 lines · Edward Cree
Quoted 9 lines · Pablo Neira Ayuso
The existing infrastructure needs the front-end to generate up to four actions (one for each 32-bit word) to mangle an IPv6 address. This patch allows you to mangle fields than are longer than 4-bytes with one single action. Drivers have been adapted to this new representation following a simple approach, that is, iterate over the array of words and configure the hardware IR to make the packet mangling.
FLOW_ACTION_MANGLE_MAX_WORDSdefines the maximum number of words from one given offset (currently 4 words).
Quoted 7 lines
Quoted 1 line
Signed-off-by Pablo Neira Ayuso <[email protected]>What's the point of this?
Why do you need to be able to do this with a single action? It doesn't look like this extra 70 lines of code is actually buying you anything, and it makes more work for any other drivers that want to implement the offload API.
It looks to me this limitation is coming from tc pedit.
Four actions to mangle an IPv6 address consume more memory when making the translation, and if you expect a lot of rules.
I think drivers can do more than one 32-bit word mangling in one go.
Quoted 4 lines · Pablo Neira Ayuso
It looks to me this limitation is coming from tc pedit.
Four actions to mangle an IPv6 address consume more memory when making the translation, and if you expect a lot of rules.
Your change means that now every pedit uses four hw entries, even if it was only meant to be a 32-bit mangle. Host memory used to keep track of the pedit actions is cheap, hw entries in pedit tables are not. Nor is driver implementation complexity.
NAK.
Pablo Neira Ayuso
maintainerQuoted 8 lines · Edward Cree
Quoted 4 lines · Pablo Neira Ayuso
It looks to me this limitation is coming from tc pedit.
Four actions to mangle an IPv6 address consume more memory when making the translation, and if you expect a lot of rules.
Your change means that now every pedit uses four hw entries, even if it was only meant to be a 32-bit mangle.
It makes no sense to me that matching an IPv6 address takes _one_ action, while mangling an IPv6 address takes _four_ actions.
A consistent model for drivers is good to have.
I can update tc pedit to generate one single action for offset consecutive packet editions, if that is the concern, I'll send a v2.
Quoted 2 lines · Pablo Neira Ayuso
I can update tc pedit to generate one single action for offset consecutive packet editions, if that is the concern, I'll send a v2.
IMHO the fix belongs in TC userland (i.e. iproute2), to turn a single action on the commandline for an ipv6 addr into four pedit actions before the kernel ever sees it.
Similarly if nftables wants to use this it should generate four separate pedit actions, probably in the kernel netfilter code as (I assume) your uAPI talks in terms of named fields rather than the u32ish offsets and masks of tc pedit. The TC (well, flow_offload now I suppose) API should be kept narrow, not widened for things that can already be expressed adequately. Your array of words inside a pedit action looks like a kind of loop unrolling but for data structures, which doesn't look sensible to me.
-Ed
Pablo Neira Ayuso
maintainerQuoted 10 lines · Edward Cree
Quoted 2 lines · Pablo Neira Ayuso
I can update tc pedit to generate one single action for offset consecutive packet editions, if that is the concern, I'll send a v2.
IMHO the fix belongs in TC userland (i.e. iproute2), to turn a single action on the commandline for an ipv6 addr into four pedit actions before the kernel ever sees it.
Similarly if nftables wants to use this it should generate four separate pedit actions, probably in the kernel netfilter code as (I assume) your uAPI talks in terms of named fields rather than the u32ish offsets and masks of tc pedit.
The driver flow_offload API does not necessarily need to map 1:1 to the netlink control plane / UAPI. The driver flow_offload API is detached from UAPI and it is internal to drivers.
Quoted 5 lines
The TC (well,
flow_offloadnow I suppose) API should be kept narrow, not widened for things that can already be expressed adequately. Your array of words inside a pedit action looks like a kind of loop unrolling but for data structures, which doesn't look sensible to me.
With one action that says "mangle an IPv6 at offset ip6 daddr field" the driver has more global view on what is going on, rather than having four actions to mangle four 32-bit words at some offset.
If this patch adds some loops here is because I did not want to make too smart changes on the drivers.
The only reason I can find why mangling is restricted to 32-bits word is tc pedit. The existing flow_offload API was modeled after tc actions, which was exposing tc pedit implementation details to hardware.
Please, allow for incremental updates on the flow_offload API to get it better now. Later we'll have way more drivers it will become harder to update this.
Quoted 3 lines · Pablo Neira Ayuso
With one action that says "mangle an IPv6 at offset ip6 daddr field" the driver has more global view on what is going on, rather than having four actions to mangle four 32-bit words at some offset.
But the action doesn't say that, it still says "mangle four 32-bit words", it's just that they're now contiguous. The driver doesn't know whether that's an IPv6 address or just a bunch of fields that happened to be next to one another.
(Besides, the driver can't rely on that 'global view', because if the actions did come from the TC uAPI, they're still going to be single u32 mangles.)
Quoted 2 lines
If this patch adds some loops here is because I did not want to make too smart changes on the drivers.
The thing is, the drivers are already looping over TC actions, so they already naturally support multiple pedits. You don't gain any expressiveness by combining them into batches of four, meanwhile you make the API less orthogonal and more laborious to implement.
Quoted 3 lines
Please, allow for incremental updates on the
flow_offloadAPI to get it better now. Later we'll have way more drivers it will become harder to update this.
I'm not opposed to making the API better. I just don't believe that this patch series achieves that.