[3/3] net/mlx5: eswitch-modify TTL actions
Checks
Commit Message
Offload following modify TTL actions to E-Swtich via
TC-Flower driver
- RTE_FLOW_ACTION_TYPE_SET_TTL
- RTE_FLOW_ACTION_TYPE_DEC_TTL
The corresponding IP protocol rte_flow_item_ipv[4|6]
must be present in rte_flow pattern otherwith PMD
return error
Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
drivers/net/mlx5/mlx5_flow.h | 2 +
drivers/net/mlx5/mlx5_flow_tcf.c | 74 +++++++++++++++++++++++++++++++-
2 files changed, 74 insertions(+), 2 deletions(-)
Comments
On Tue, Sep 25, 2018 at 09:47:18PM +0800, Xiaoyu Min wrote:
> Offload following modify TTL actions to E-Swtich via
> TC-Flower driver
>
> - RTE_FLOW_ACTION_TYPE_SET_TTL
> - RTE_FLOW_ACTION_TYPE_DEC_TTL
>
> The corresponding IP protocol rte_flow_item_ipv[4|6]
> must be present in rte_flow pattern otherwith PMD
> return error
>
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---
As it is quite similar to the other patch of IP addr and UDP/TCP port, I have
the same comments on this patch too.
Two more things.
1) commit title.
'eswitch' isn't allowed. Like you mentioned in the commit message, it is
officially E-Switch. And I'm curious why '-' is needed for the title.
2) MLX5_ACTION_*
As there are a few more pending patches which add new actions - encap/decap and
multi-table, we may have to have final rebasing in order at the last moment.
Thanks,
Yongseok
> drivers/net/mlx5/mlx5_flow.h | 2 +
> drivers/net/mlx5/mlx5_flow_tcf.c | 74 +++++++++++++++++++++++++++++++-
> 2 files changed, 74 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
> index be182a643..5237e31dd 100644
> --- a/drivers/net/mlx5/mlx5_flow.h
> +++ b/drivers/net/mlx5/mlx5_flow.h
> @@ -93,6 +93,8 @@
> #define MLX5_ACTION_SET_IPV6_DST (1u << 14)
> #define MLX5_ACTION_SET_TP_SRC (1u << 15)
> #define MLX5_ACTION_SET_TP_DST (1u << 16)
> +#define MLX5_ACTION_SET_TTL (1u << 17)
> +#define MLX5_ACTION_DEC_TTL (1u << 18)
>
> /* possible L3 layers protocols filtering. */
> #define MLX5_IP_PROTOCOL_TCP 6
> diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
> index 85c92f369..af88c4a0d 100644
> --- a/drivers/net/mlx5/mlx5_flow_tcf.c
> +++ b/drivers/net/mlx5/mlx5_flow_tcf.c
> @@ -217,6 +217,10 @@ struct tc_pedit_sel {
> #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
> #endif
>
> +#ifndef TTL_LEN
> +#define TTL_LEN 1
> +#endif
> +
> /** Empty masks for known item types. */
> static const union {
> struct rte_flow_item_port_id port_id;
> @@ -297,7 +301,9 @@ struct flow_tcf_ptoi {
> (act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC || \
> (act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_DST || \
> (act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC || \
> - (act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST) ? \
> + (act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST || \
> + (act) == RTE_FLOW_ACTION_TYPE_SET_TTL || \
> + (act) == RTE_FLOW_ACTION_TYPE_DEC_TTL) ? \
> 1 : 0; })
> #define MAX_PEDIT_KEYS (128)
> #define SZ_PEDIT_KEY_VAL (4)
> @@ -321,6 +327,34 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
> return keys;
> }
>
> +static void
> +flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
> + struct pedit_parser *p_parser,
> + uint64_t item_flags)
> +{
> + int idx = p_parser->sel.nkeys;
> +
> + p_parser->keys[idx].mask = 0xFFFFFF00;
> + if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
> + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
> + p_parser->keys[idx].off = 8; /* IPv4 TTL Offset */
> + }
> + if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
> + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
> + p_parser->keys[idx].off = 7; /* IPv6 HopLimit Offset */
> + }
> + if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
> + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
> + p_parser->keys[idx].val = 0xFF;
> + } else {
> + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
> + p_parser->keys[idx].val =
> + ((const struct rte_flow_action_set_ttl *)
> + actions->conf)->ttl_value;
> + }
> + p_parser->sel.nkeys = (++idx);
> +}
> +
> static void
> flow_tcf_pedit_key_set_tp_port(const struct rte_flow_action *actions,
> struct pedit_parser *p_parser,
> @@ -408,6 +442,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
> flow_tcf_pedit_key_set_tp_port(*actions,
> &p_parser, item_flags);
> break;
> + case RTE_FLOW_ACTION_TYPE_SET_TTL:
> + case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> + flow_tcf_pedit_key_set_dec_ttl(*actions,
> + &p_parser, item_flags);
> + break;
> default:
> goto pedit_mnl_msg_done;
> }
> @@ -488,6 +527,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
> keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN);
> flags |= MLX5_ACTION_SET_TP_DST;
> break;
> + case RTE_FLOW_ACTION_TYPE_SET_TTL:
> + keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> + flags |= MLX5_ACTION_SET_TTL;
> + break;
> + case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> + keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> + flags |= MLX5_ACTION_DEC_TTL;
> + break;
> default:
> goto get_pedit_action_size_done;
> }
> @@ -988,13 +1035,20 @@ flow_tcf_validate(struct rte_eth_dev *dev,
> case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> action_flags |= MLX5_ACTION_SET_TP_DST;
> break;
> + case RTE_FLOW_ACTION_TYPE_SET_TTL:
> + action_flags |= MLX5_ACTION_SET_TTL;
> + break;
> + case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> + action_flags |= MLX5_ACTION_DEC_TTL;
> + break;
> default:
> return rte_flow_error_set(error, ENOTSUP,
> RTE_FLOW_ERROR_TYPE_ACTION,
> actions,
> "action not supported");
> }
> - if (IS_MODIFY_ACTION(actions->type)) {
> + if (IS_MODIFY_ACTION(actions->type) &&
> + actions->type != RTE_FLOW_ACTION_TYPE_DEC_TTL) {
> if (!actions->conf)
> return rte_flow_error_set(error, ENOTSUP,
> RTE_FLOW_ERROR_TYPE_ACTION_CONF,
> @@ -1029,6 +1083,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
> "no TCP/UDP item found in"
> " pattern");
> }
> + if (action_flags &
> + (MLX5_ACTION_SET_TTL | MLX5_ACTION_DEC_TTL)) {
> + if (!(item_flags &
> + (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
> + MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
> + return rte_flow_error_set(error, ENOTSUP,
> + RTE_FLOW_ERROR_TYPE_ACTION,
> + actions,
> + "no IP found in pattern");
> + }
> return 0;
> }
>
> @@ -1178,6 +1242,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
> case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
> case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
> case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> + case RTE_FLOW_ACTION_TYPE_SET_TTL:
> + case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> size += flow_tcf_get_pedit_actions_size(&actions,
> &flags);
> break;
> @@ -1451,6 +1517,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> RTE_BE16(0x0fff)));
> break;
> case RTE_FLOW_ITEM_TYPE_IPV4:
> + item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
> mask.ipv4 = flow_tcf_item_mask
> (items, &rte_flow_item_ipv4_mask,
> &flow_tcf_mask_supported.ipv4,
> @@ -1490,6 +1557,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> }
> break;
> case RTE_FLOW_ITEM_TYPE_IPV6:
> + item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
> mask.ipv6 = flow_tcf_item_mask
> (items, &rte_flow_item_ipv6_mask,
> &flow_tcf_mask_supported.ipv6,
> @@ -1718,6 +1786,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
> case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
> case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> + case RTE_FLOW_ACTION_TYPE_SET_TTL:
> + case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> na_act_index =
> mnl_attr_nest_start(nlh, na_act_index_cur++);
> flow_tcf_create_pedit_mnl_msg(nlh,
> --
> 2.17.1
>
On 18-10-04 04:07:02, Yongseok Koh wrote:
> On Tue, Sep 25, 2018 at 09:47:18PM +0800, Xiaoyu Min wrote:
> > Offload following modify TTL actions to E-Swtich via
> > TC-Flower driver
> >
> > - RTE_FLOW_ACTION_TYPE_SET_TTL
> > - RTE_FLOW_ACTION_TYPE_DEC_TTL
> >
> > The corresponding IP protocol rte_flow_item_ipv[4|6]
> > must be present in rte_flow pattern otherwith PMD
> > return error
> >
> > Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> > ---
>
> As it is quite similar to the other patch of IP addr and UDP/TCP port, I have
> the same comments on this patch too.
>
> Two more things.
>
> 1) commit title.
> 'eswitch' isn't allowed. Like you mentioned in the commit message, it is
> officially E-Switch. And I'm curious why '-' is needed for the title.
>
Yes you are right I should use officially one.
'-' is wrongly used, I will remove it.
> 2) MLX5_ACTION_*
> As there are a few more pending patches which add new actions - encap/decap and
> multi-table, we may have to have final rebasing in order at the last moment.
>
Definitely we need.
>
> Thanks,
> Yongseok
>
> > drivers/net/mlx5/mlx5_flow.h | 2 +
> > drivers/net/mlx5/mlx5_flow_tcf.c | 74 +++++++++++++++++++++++++++++++-
> > 2 files changed, 74 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
> > index be182a643..5237e31dd 100644
> > --- a/drivers/net/mlx5/mlx5_flow.h
> > +++ b/drivers/net/mlx5/mlx5_flow.h
> > @@ -93,6 +93,8 @@
> > #define MLX5_ACTION_SET_IPV6_DST (1u << 14)
> > #define MLX5_ACTION_SET_TP_SRC (1u << 15)
> > #define MLX5_ACTION_SET_TP_DST (1u << 16)
> > +#define MLX5_ACTION_SET_TTL (1u << 17)
> > +#define MLX5_ACTION_DEC_TTL (1u << 18)
> >
> > /* possible L3 layers protocols filtering. */
> > #define MLX5_IP_PROTOCOL_TCP 6
> > diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
> > index 85c92f369..af88c4a0d 100644
> > --- a/drivers/net/mlx5/mlx5_flow_tcf.c
> > +++ b/drivers/net/mlx5/mlx5_flow_tcf.c
> > @@ -217,6 +217,10 @@ struct tc_pedit_sel {
> > #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
> > #endif
> >
> > +#ifndef TTL_LEN
> > +#define TTL_LEN 1
> > +#endif
> > +
> > /** Empty masks for known item types. */
> > static const union {
> > struct rte_flow_item_port_id port_id;
> > @@ -297,7 +301,9 @@ struct flow_tcf_ptoi {
> > (act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC || \
> > (act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_DST || \
> > (act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC || \
> > - (act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST) ? \
> > + (act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST || \
> > + (act) == RTE_FLOW_ACTION_TYPE_SET_TTL || \
> > + (act) == RTE_FLOW_ACTION_TYPE_DEC_TTL) ? \
> > 1 : 0; })
> > #define MAX_PEDIT_KEYS (128)
> > #define SZ_PEDIT_KEY_VAL (4)
> > @@ -321,6 +327,34 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
> > return keys;
> > }
> >
> > +static void
> > +flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
> > + struct pedit_parser *p_parser,
> > + uint64_t item_flags)
> > +{
> > + int idx = p_parser->sel.nkeys;
> > +
> > + p_parser->keys[idx].mask = 0xFFFFFF00;
> > + if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
> > + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
> > + p_parser->keys[idx].off = 8; /* IPv4 TTL Offset */
> > + }
> > + if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
> > + p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
> > + p_parser->keys[idx].off = 7; /* IPv6 HopLimit Offset */
> > + }
> > + if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
> > + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
> > + p_parser->keys[idx].val = 0xFF;
> > + } else {
> > + p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
> > + p_parser->keys[idx].val =
> > + ((const struct rte_flow_action_set_ttl *)
> > + actions->conf)->ttl_value;
> > + }
> > + p_parser->sel.nkeys = (++idx);
> > +}
> > +
> > static void
> > flow_tcf_pedit_key_set_tp_port(const struct rte_flow_action *actions,
> > struct pedit_parser *p_parser,
> > @@ -408,6 +442,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
> > flow_tcf_pedit_key_set_tp_port(*actions,
> > &p_parser, item_flags);
> > break;
> > + case RTE_FLOW_ACTION_TYPE_SET_TTL:
> > + case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> > + flow_tcf_pedit_key_set_dec_ttl(*actions,
> > + &p_parser, item_flags);
> > + break;
> > default:
> > goto pedit_mnl_msg_done;
> > }
> > @@ -488,6 +527,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
> > keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN);
> > flags |= MLX5_ACTION_SET_TP_DST;
> > break;
> > + case RTE_FLOW_ACTION_TYPE_SET_TTL:
> > + keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> > + flags |= MLX5_ACTION_SET_TTL;
> > + break;
> > + case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> > + keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> > + flags |= MLX5_ACTION_DEC_TTL;
> > + break;
> > default:
> > goto get_pedit_action_size_done;
> > }
> > @@ -988,13 +1035,20 @@ flow_tcf_validate(struct rte_eth_dev *dev,
> > case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> > action_flags |= MLX5_ACTION_SET_TP_DST;
> > break;
> > + case RTE_FLOW_ACTION_TYPE_SET_TTL:
> > + action_flags |= MLX5_ACTION_SET_TTL;
> > + break;
> > + case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> > + action_flags |= MLX5_ACTION_DEC_TTL;
> > + break;
> > default:
> > return rte_flow_error_set(error, ENOTSUP,
> > RTE_FLOW_ERROR_TYPE_ACTION,
> > actions,
> > "action not supported");
> > }
> > - if (IS_MODIFY_ACTION(actions->type)) {
> > + if (IS_MODIFY_ACTION(actions->type) &&
> > + actions->type != RTE_FLOW_ACTION_TYPE_DEC_TTL) {
> > if (!actions->conf)
> > return rte_flow_error_set(error, ENOTSUP,
> > RTE_FLOW_ERROR_TYPE_ACTION_CONF,
> > @@ -1029,6 +1083,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
> > "no TCP/UDP item found in"
> > " pattern");
> > }
> > + if (action_flags &
> > + (MLX5_ACTION_SET_TTL | MLX5_ACTION_DEC_TTL)) {
> > + if (!(item_flags &
> > + (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
> > + MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
> > + return rte_flow_error_set(error, ENOTSUP,
> > + RTE_FLOW_ERROR_TYPE_ACTION,
> > + actions,
> > + "no IP found in pattern");
> > + }
> > return 0;
> > }
> >
> > @@ -1178,6 +1242,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
> > case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
> > case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
> > case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> > + case RTE_FLOW_ACTION_TYPE_SET_TTL:
> > + case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> > size += flow_tcf_get_pedit_actions_size(&actions,
> > &flags);
> > break;
> > @@ -1451,6 +1517,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> > RTE_BE16(0x0fff)));
> > break;
> > case RTE_FLOW_ITEM_TYPE_IPV4:
> > + item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
> > mask.ipv4 = flow_tcf_item_mask
> > (items, &rte_flow_item_ipv4_mask,
> > &flow_tcf_mask_supported.ipv4,
> > @@ -1490,6 +1557,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> > }
> > break;
> > case RTE_FLOW_ITEM_TYPE_IPV6:
> > + item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
> > mask.ipv6 = flow_tcf_item_mask
> > (items, &rte_flow_item_ipv6_mask,
> > &flow_tcf_mask_supported.ipv6,
> > @@ -1718,6 +1786,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> > case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
> > case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
> > case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> > + case RTE_FLOW_ACTION_TYPE_SET_TTL:
> > + case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> > na_act_index =
> > mnl_attr_nest_start(nlh, na_act_index_cur++);
> > flow_tcf_create_pedit_mnl_msg(nlh,
> > --
> > 2.17.1
> >
@@ -93,6 +93,8 @@
#define MLX5_ACTION_SET_IPV6_DST (1u << 14)
#define MLX5_ACTION_SET_TP_SRC (1u << 15)
#define MLX5_ACTION_SET_TP_DST (1u << 16)
+#define MLX5_ACTION_SET_TTL (1u << 17)
+#define MLX5_ACTION_DEC_TTL (1u << 18)
/* possible L3 layers protocols filtering. */
#define MLX5_IP_PROTOCOL_TCP 6
@@ -217,6 +217,10 @@ struct tc_pedit_sel {
#define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
#endif
+#ifndef TTL_LEN
+#define TTL_LEN 1
+#endif
+
/** Empty masks for known item types. */
static const union {
struct rte_flow_item_port_id port_id;
@@ -297,7 +301,9 @@ struct flow_tcf_ptoi {
(act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC || \
(act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_DST || \
(act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC || \
- (act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST) ? \
+ (act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST || \
+ (act) == RTE_FLOW_ACTION_TYPE_SET_TTL || \
+ (act) == RTE_FLOW_ACTION_TYPE_DEC_TTL) ? \
1 : 0; })
#define MAX_PEDIT_KEYS (128)
#define SZ_PEDIT_KEY_VAL (4)
@@ -321,6 +327,34 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
return keys;
}
+static void
+flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
+ struct pedit_parser *p_parser,
+ uint64_t item_flags)
+{
+ int idx = p_parser->sel.nkeys;
+
+ p_parser->keys[idx].mask = 0xFFFFFF00;
+ if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
+ p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
+ p_parser->keys[idx].off = 8; /* IPv4 TTL Offset */
+ }
+ if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
+ p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
+ p_parser->keys[idx].off = 7; /* IPv6 HopLimit Offset */
+ }
+ if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
+ p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
+ p_parser->keys[idx].val = 0xFF;
+ } else {
+ p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+ p_parser->keys[idx].val =
+ ((const struct rte_flow_action_set_ttl *)
+ actions->conf)->ttl_value;
+ }
+ p_parser->sel.nkeys = (++idx);
+}
+
static void
flow_tcf_pedit_key_set_tp_port(const struct rte_flow_action *actions,
struct pedit_parser *p_parser,
@@ -408,6 +442,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
flow_tcf_pedit_key_set_tp_port(*actions,
&p_parser, item_flags);
break;
+ case RTE_FLOW_ACTION_TYPE_SET_TTL:
+ case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ flow_tcf_pedit_key_set_dec_ttl(*actions,
+ &p_parser, item_flags);
+ break;
default:
goto pedit_mnl_msg_done;
}
@@ -488,6 +527,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN);
flags |= MLX5_ACTION_SET_TP_DST;
break;
+ case RTE_FLOW_ACTION_TYPE_SET_TTL:
+ keys += flow_tcf_calc_pedit_keys(TTL_LEN);
+ flags |= MLX5_ACTION_SET_TTL;
+ break;
+ case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ keys += flow_tcf_calc_pedit_keys(TTL_LEN);
+ flags |= MLX5_ACTION_DEC_TTL;
+ break;
default:
goto get_pedit_action_size_done;
}
@@ -988,13 +1035,20 @@ flow_tcf_validate(struct rte_eth_dev *dev,
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
action_flags |= MLX5_ACTION_SET_TP_DST;
break;
+ case RTE_FLOW_ACTION_TYPE_SET_TTL:
+ action_flags |= MLX5_ACTION_SET_TTL;
+ break;
+ case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+ action_flags |= MLX5_ACTION_DEC_TTL;
+ break;
default:
return rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_ACTION,
actions,
"action not supported");
}
- if (IS_MODIFY_ACTION(actions->type)) {
+ if (IS_MODIFY_ACTION(actions->type) &&
+ actions->type != RTE_FLOW_ACTION_TYPE_DEC_TTL) {
if (!actions->conf)
return rte_flow_error_set(error, ENOTSUP,
RTE_FLOW_ERROR_TYPE_ACTION_CONF,
@@ -1029,6 +1083,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
"no TCP/UDP item found in"
" pattern");
}
+ if (action_flags &
+ (MLX5_ACTION_SET_TTL | MLX5_ACTION_DEC_TTL)) {
+ if (!(item_flags &
+ (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
+ MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
+ return rte_flow_error_set(error, ENOTSUP,
+ RTE_FLOW_ERROR_TYPE_ACTION,
+ actions,
+ "no IP found in pattern");
+ }
return 0;
}
@@ -1178,6 +1242,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+ case RTE_FLOW_ACTION_TYPE_SET_TTL:
+ case RTE_FLOW_ACTION_TYPE_DEC_TTL:
size += flow_tcf_get_pedit_actions_size(&actions,
&flags);
break;
@@ -1451,6 +1517,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
RTE_BE16(0x0fff)));
break;
case RTE_FLOW_ITEM_TYPE_IPV4:
+ item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
mask.ipv4 = flow_tcf_item_mask
(items, &rte_flow_item_ipv4_mask,
&flow_tcf_mask_supported.ipv4,
@@ -1490,6 +1557,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
}
break;
case RTE_FLOW_ITEM_TYPE_IPV6:
+ item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
mask.ipv6 = flow_tcf_item_mask
(items, &rte_flow_item_ipv6_mask,
&flow_tcf_mask_supported.ipv6,
@@ -1718,6 +1786,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+ case RTE_FLOW_ACTION_TYPE_SET_TTL:
+ case RTE_FLOW_ACTION_TYPE_DEC_TTL:
na_act_index =
mnl_attr_nest_start(nlh, na_act_index_cur++);
flow_tcf_create_pedit_mnl_msg(nlh,