From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org,
jakub.kicinski@netronome.com, jiri@resnulli.us,
saeedm@mellanox.com, vishal@chelsio.com, vladbu@mellanox.com,
ecree@solarflare.com
Subject: [PATCH net-next,v4 1/4] net: flow_offload: bitwise AND on mangle action value field
Date: Tue, 15 Oct 2019 00:00:24 +0200 [thread overview]
Message-ID: <20191014220027.7500-2-pablo@netfilter.org> (raw)
In-Reply-To: <20191014220027.7500-1-pablo@netfilter.org>
Drivers perform a bitwise AND on the value and the mask. Update
tc_setup_flow_action() to perform this operation so drivers do not need
to do this.
Remove sanity check for sane value and mask values from the nfp driver,
the front-end already guarantees this after this patch.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
.../net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 3 +--
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +-
drivers/net/ethernet/netronome/nfp/flower/action.c | 29 +++-------------------
net/sched/cls_api.c | 3 ++-
4 files changed, 8 insertions(+), 29 deletions(-)
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
index 2d26dbca701d..5afc15a60199 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
@@ -275,7 +275,6 @@ static int cxgb4_validate_flow_match(struct net_device *dev,
static void offload_pedit(struct ch_filter_specification *fs, u32 val, u32 mask,
u8 field)
{
- u32 set_val = val & mask;
u32 offset = 0;
u8 size = 1;
int i;
@@ -287,7 +286,7 @@ static void offload_pedit(struct ch_filter_specification *fs, u32 val, u32 mask,
break;
}
}
- memcpy((u8 *)fs + offset, &set_val, size);
+ memcpy((u8 *)fs + offset, &val, size);
}
static void process_pedit_field(struct ch_filter_specification *fs, u32 val,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
index 80e02b88ed77..be25b1eae9c3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
@@ -2228,7 +2228,7 @@ static int set_pedit_val(u8 hdr_type, u32 mask, u32 val, u32 offset,
goto out_err;
*curr_pmask |= mask;
- *curr_pval |= (val & mask);
+ *curr_pval |= val;
return 0;
diff --git a/drivers/net/ethernet/netronome/nfp/flower/action.c b/drivers/net/ethernet/netronome/nfp/flower/action.c
index ee0066a7ba87..07db0a7ba0d5 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/action.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/action.c
@@ -477,7 +477,6 @@ static void nfp_fl_set_helper32(u32 value, u32 mask, u8 *p_exact, u8 *p_mask)
u32 oldvalue = get_unaligned((u32 *)p_exact);
u32 oldmask = get_unaligned((u32 *)p_mask);
- value &= mask;
value |= oldvalue & ~mask;
put_unaligned(oldmask | mask, (u32 *)p_mask);
@@ -498,11 +497,6 @@ nfp_fl_set_eth(const struct flow_action_entry *act, u32 off,
mask = act->mangle.mask;
exact = act->mangle.val;
- if (exact & ~mask) {
- NL_SET_ERR_MSG_MOD(extack, "unsupported offload: invalid pedit ethernet action");
- return -EOPNOTSUPP;
- }
-
nfp_fl_set_helper32(exact, mask, &set_eth->eth_addr_val[off],
&set_eth->eth_addr_mask[off]);
@@ -535,16 +529,11 @@ nfp_fl_set_ip4(const struct flow_action_entry *act, u32 off,
mask = (__force __be32)act->mangle.mask;
exact = (__force __be32)act->mangle.val;
- if (exact & ~mask) {
- NL_SET_ERR_MSG_MOD(extack, "unsupported offload: invalid pedit IPv4 action");
- return -EOPNOTSUPP;
- }
-
switch (off) {
case offsetof(struct iphdr, daddr):
set_ip_addr->ipv4_dst_mask |= mask;
set_ip_addr->ipv4_dst &= ~mask;
- set_ip_addr->ipv4_dst |= exact & mask;
+ set_ip_addr->ipv4_dst |= exact;
set_ip_addr->head.jump_id = NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS;
set_ip_addr->head.len_lw = sizeof(*set_ip_addr) >>
NFP_FL_LW_SIZ;
@@ -552,7 +541,7 @@ nfp_fl_set_ip4(const struct flow_action_entry *act, u32 off,
case offsetof(struct iphdr, saddr):
set_ip_addr->ipv4_src_mask |= mask;
set_ip_addr->ipv4_src &= ~mask;
- set_ip_addr->ipv4_src |= exact & mask;
+ set_ip_addr->ipv4_src |= exact;
set_ip_addr->head.jump_id = NFP_FL_ACTION_OPCODE_SET_IPV4_ADDRS;
set_ip_addr->head.len_lw = sizeof(*set_ip_addr) >>
NFP_FL_LW_SIZ;
@@ -606,7 +595,7 @@ nfp_fl_set_ip6_helper(int opcode_tag, u8 word, __be32 exact, __be32 mask,
{
ip6->ipv6[word].mask |= mask;
ip6->ipv6[word].exact &= ~mask;
- ip6->ipv6[word].exact |= exact & mask;
+ ip6->ipv6[word].exact |= exact;
ip6->reserved = cpu_to_be16(0);
ip6->head.jump_id = opcode_tag;
@@ -651,7 +640,7 @@ nfp_fl_set_ip6_hop_limit_flow_label(u32 off, __be32 exact, __be32 mask,
ip_hl_fl->ipv6_label_mask |= mask;
ip_hl_fl->ipv6_label &= ~mask;
- ip_hl_fl->ipv6_label |= exact & mask;
+ ip_hl_fl->ipv6_label |= exact;
break;
}
@@ -676,11 +665,6 @@ nfp_fl_set_ip6(const struct flow_action_entry *act, u32 off,
mask = (__force __be32)act->mangle.mask;
exact = (__force __be32)act->mangle.val;
- if (exact & ~mask) {
- NL_SET_ERR_MSG_MOD(extack, "unsupported offload: invalid pedit IPv6 action");
- return -EOPNOTSUPP;
- }
-
if (off < offsetof(struct ipv6hdr, saddr)) {
err = nfp_fl_set_ip6_hop_limit_flow_label(off, exact, mask,
ip_hl_fl, extack);
@@ -716,11 +700,6 @@ nfp_fl_set_tport(const struct flow_action_entry *act, u32 off,
mask = act->mangle.mask;
exact = act->mangle.val;
- if (exact & ~mask) {
- NL_SET_ERR_MSG_MOD(extack, "unsupported offload: invalid pedit L4 action");
- return -EOPNOTSUPP;
- }
-
nfp_fl_set_helper32(exact, mask, set_tport->tp_port_val,
set_tport->tp_port_mask);
diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 55a5556328a2..2656203eaaf1 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -3410,7 +3410,8 @@ int tc_setup_flow_action(struct flow_action *flow_action,
}
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.val = tcf_pedit_val(act, k) &
+ entry->mangle.mask;
entry->mangle.offset = tcf_pedit_offset(act, k);
entry = &flow_action->entries[++j];
}
--
2.11.0
next prev parent reply other threads:[~2019-10-14 22:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-14 22:00 [PATCH net-next,v4 0/4] flow_offload: update mangle action representation Pablo Neira Ayuso
2019-10-14 22:00 ` Pablo Neira Ayuso [this message]
2019-10-14 22:00 ` [PATCH net-next,v4 2/4] net: flow_offload: mangle action at byte level Pablo Neira Ayuso
2019-10-14 22:00 ` [PATCH net-next,v4 3/4] netfilter: nft_payload: packet mangling offload support Pablo Neira Ayuso
2019-10-14 22:00 ` [PATCH net-next,v4 4/4] net: flow_offload: add flow_rule_print() Pablo Neira Ayuso
2019-10-14 22:04 ` [PATCH net-next,v4 0/4] flow_offload: update mangle action representation Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191014220027.7500-2-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=davem@davemloft.net \
--cc=ecree@solarflare.com \
--cc=jakub.kicinski@netronome.com \
--cc=jiri@resnulli.us \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=saeedm@mellanox.com \
--cc=vishal@chelsio.com \
--cc=vladbu@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.