[2/3] ethdev: add flow api actions to modify TCP/UDP port numbers
diff mbox series

Message ID e7ea6aedcdebef4f2f904d9138e076f06289e7ce.1537776502.git.rahul.lakkireddy@chelsio.com
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers show
Series
  • ethdev: add IP address and TCP/UDP port rewrite actions to flow API
Related show

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Rahul Lakkireddy Sept. 24, 2018, 8:28 a.m. UTC
Add actions:
- SET_TP_SRC - set a new TCP/UDP source port number.
- SET_TP_DST - set a new TCP/UDP destination port number.

Original work by Shagun Agrawal

Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
---
Changes since RFC v2:
- Updated comments, help messages, and doc to indicate that IP/TCP/UDP
  of the outermost headers are modified.
- Updated comments and doc to indicate that a corresponding valid flow
  pattern item must be specified to offload corresponding header rewrite
  action.
- Updated release notes.

 app/test-pmd/cmdline_flow.c                 | 52 +++++++++++++++++++++
 app/test-pmd/config.c                       |  4 ++
 doc/guides/prog_guide/rte_flow.rst          | 36 ++++++++++++++
 doc/guides/rel_notes/release_18_11.rst      |  2 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 10 ++++
 lib/librte_ethdev/rte_flow.c                |  4 ++
 lib/librte_ethdev/rte_flow.h                | 37 +++++++++++++++
 7 files changed, 145 insertions(+)

Comments

Xiaoyu Min Sept. 25, 2018, 3:06 a.m. UTC | #1
On 18-09-24 13:58:18, Rahul Lakkireddy wrote:
> Add actions:
> - SET_TP_SRC - set a new TCP/UDP source port number.
> - SET_TP_DST - set a new TCP/UDP destination port number.
> 
> Original work by Shagun Agrawal
> 
> Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
> ---
> Changes since RFC v2:
> - Updated comments, help messages, and doc to indicate that IP/TCP/UDP
>   of the outermost headers are modified.
> - Updated comments and doc to indicate that a corresponding valid flow
>   pattern item must be specified to offload corresponding header rewrite
>   action.
> - Updated release notes.
> 
>  app/test-pmd/cmdline_flow.c                 | 52 +++++++++++++++++++++
>  app/test-pmd/config.c                       |  4 ++
>  doc/guides/prog_guide/rte_flow.rst          | 36 ++++++++++++++
>  doc/guides/rel_notes/release_18_11.rst      |  2 +
>  doc/guides/testpmd_app_ug/testpmd_funcs.rst | 10 ++++
>  lib/librte_ethdev/rte_flow.c                |  4 ++
>  lib/librte_ethdev/rte_flow.h                | 37 +++++++++++++++
>  7 files changed, 145 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
> index 1432498a3..a9888cacf 100644
> --- a/app/test-pmd/cmdline_flow.c
> +++ b/app/test-pmd/cmdline_flow.c
> @@ -251,6 +251,10 @@ enum index {
>  	ACTION_SET_IPV6_SRC_IPV6_SRC,
>  	ACTION_SET_IPV6_DST,
>  	ACTION_SET_IPV6_DST_IPV6_DST,
> +	ACTION_SET_TP_SRC,
> +	ACTION_SET_TP_SRC_TP_SRC,
> +	ACTION_SET_TP_DST,
> +	ACTION_SET_TP_DST_TP_DST,
>  };
>  
>  /** Maximum size for pattern in struct rte_flow_item_raw. */
> @@ -828,6 +832,8 @@ static const enum index next_action[] = {
>  	ACTION_SET_IPV4_DST,
>  	ACTION_SET_IPV6_SRC,
>  	ACTION_SET_IPV6_DST,
> +	ACTION_SET_TP_SRC,
> +	ACTION_SET_TP_DST,
>  	ZERO,
>  };
>  
> @@ -954,6 +960,18 @@ static const enum index action_set_ipv6_dst[] = {
>  	ZERO,
>  };
>  
> +static const enum index action_set_tp_src[] = {
> +	ACTION_SET_TP_SRC_TP_SRC,
> +	ACTION_NEXT,
> +	ZERO,
> +};
> +
> +static const enum index action_set_tp_dst[] = {
> +	ACTION_SET_TP_DST_TP_DST,
> +	ACTION_NEXT,
> +	ZERO,
> +};
> +
>  static const enum index action_jump[] = {
>  	ACTION_JUMP_GROUP,
>  	ACTION_NEXT,
> @@ -2574,6 +2592,40 @@ static const struct token token_list[] = {
>  			(struct rte_flow_action_set_ipv6, ipv6_addr)),
>  		.call = parse_vc_conf,
>  	},
> +	[ACTION_SET_TP_SRC] = {
> +		.name = "set_tp_src",
> +		.help = "set a new source port number in the outermost"
> +			" TCP/UDP header",
> +		.priv = PRIV_ACTION(SET_TP_SRC,
> +			sizeof(struct rte_flow_action_set_tp)),
> +		.next = NEXT(action_set_tp_src),
> +		.call = parse_vc,
> +	},
> +	[ACTION_SET_TP_SRC_TP_SRC] = {
> +		.name = "port",
> +		.help = "new source port number to set",
> +		.next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
> +		.args = ARGS(ARGS_ENTRY_HTON
> +			     (struct rte_flow_action_set_tp, port)),
> +		.call = parse_vc_conf,
> +	},
> +	[ACTION_SET_TP_DST] = {
> +		.name = "set_tp_dst",
> +		.help = "set a new destination port number in the outermost"
> +			" TCP/UDP header",
> +		.priv = PRIV_ACTION(SET_TP_DST,
> +			sizeof(struct rte_flow_action_set_tp)),
> +		.next = NEXT(action_set_tp_dst),
> +		.call = parse_vc,
> +	},
> +	[ACTION_SET_TP_DST_TP_DST] = {
> +		.name = "port",
> +		.help = "new destination port number to set",
> +		.next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
> +		.args = ARGS(ARGS_ENTRY_HTON
> +			     (struct rte_flow_action_set_tp, port)),
> +		.call = parse_vc_conf,
> +	},
>  };
>  
>  /** Remove and return last entry from argument stack. */
> diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
> index 14dbdf7a3..1629a6d7a 100644
> --- a/app/test-pmd/config.c
> +++ b/app/test-pmd/config.c
> @@ -1180,6 +1180,10 @@ static const struct {
>  		       sizeof(struct rte_flow_action_set_ipv6)),
>  	MK_FLOW_ACTION(SET_IPV6_DST,
>  		       sizeof(struct rte_flow_action_set_ipv6)),
> +	MK_FLOW_ACTION(SET_TP_SRC,
> +		       sizeof(struct rte_flow_action_set_tp)),
> +	MK_FLOW_ACTION(SET_TP_DST,
> +		       sizeof(struct rte_flow_action_set_tp)),
>  };
>  
>  /** Compute storage space needed by action configuration and copy it. */
> diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
> index b9bcaa3d1..4be160209 100644
> --- a/doc/guides/prog_guide/rte_flow.rst
> +++ b/doc/guides/prog_guide/rte_flow.rst
> @@ -2148,6 +2148,42 @@ Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
>     | ``ipv6_addr`` | new IPv6 destination address |
>     +---------------+------------------------------+
>  
> +Action: ``SET_TP_SRC``
> +^^^^^^^^^^^^^^^^^^^^^^^^^
> +
> +Set a new source port number in the outermost TCP/UDP header.
> +
> +It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
> +flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
> +
> +.. _table_rte_flow_action_set_tp_src:
> +
> +.. table:: SET_TP_SRC
> +
> +   +----------+-------------------------+
> +   | Field    | Value                   |
> +   +==========+=========================+
> +   | ``port`` | new TCP/UDP source port |
> +   +---------------+--------------------+
> +
> +Action: ``SET_TP_DST``
> +^^^^^^^^^^^^^^^^^^^^^^^^^
> +
> +Set a new destination port number in the outermost TCP/UDP header.
> +
> +It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
> +flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
> +
> +.. _table_rte_flow_action_set_tp_dst:
> +
> +.. table:: SET_TP_DST
> +
> +   +----------+------------------------------+
> +   | Field    | Value                        |
> +   +==========+==============================+
> +   | ``port`` | new TCP/UDP destination port |
> +   +---------------+-------------------------+
> +
>  Negative types
>  ~~~~~~~~~~~~~~
>  
> diff --git a/doc/guides/rel_notes/release_18_11.rst b/doc/guides/rel_notes/release_18_11.rst
> index 782722318..84b0a6a4b 100644
> --- a/doc/guides/rel_notes/release_18_11.rst
> +++ b/doc/guides/rel_notes/release_18_11.rst
> @@ -93,6 +93,8 @@ New Features
>  
>    * Modify source and destination IP addresses in the outermost IPv4/IPv6
>      headers.
> +  * Modify source and destination port numbers in the outermost TCP/UDP
> +    headers.
>  
>  API Changes
>  -----------
> diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> index 97d91f066..ffec7013b 100644
> --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> @@ -3722,6 +3722,16 @@ This section lists supported actions and their attributes, if any.
>  
>    - ``ipv6_addr``: New IPv6 destination address.
>  
> +- ``of_set_tp_src``: Set a new source port number in the outermost TCP/UDP
> +  header.
> +
> +  - ``port``: New TCP/UDP source port number.
> +
> +- ``of_set_tp_dst``: Set a new destination port number in the outermost TCP/UDP
> +  header.
> +
> +  - ``port``: New TCP/UDP destination port number.
> +
>  Destroying flow rules
>  ~~~~~~~~~~~~~~~~~~~~~
>  
> diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
> index d4f1b9a05..409c79741 100644
> --- a/lib/librte_ethdev/rte_flow.c
> +++ b/lib/librte_ethdev/rte_flow.c
> @@ -117,6 +117,10 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
>  		       sizeof(struct rte_flow_action_set_ipv6)),
>  	MK_FLOW_ACTION(SET_IPV6_DST,
>  		       sizeof(struct rte_flow_action_set_ipv6)),
> +	MK_FLOW_ACTION(SET_TP_SRC,
> +		       sizeof(struct rte_flow_action_set_tp)),
> +	MK_FLOW_ACTION(SET_TP_DST,
> +		       sizeof(struct rte_flow_action_set_tp)),
>  };
>  
>  static int
> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> index 0fe91ae89..cf5cecf42 100644
> --- a/lib/librte_ethdev/rte_flow.h
> +++ b/lib/librte_ethdev/rte_flow.h
> @@ -1545,6 +1545,28 @@ enum rte_flow_action_type {
>  	 * See struct rte_flow_action_set_ipv6.
>  	 */
>  	RTE_FLOW_ACTION_TYPE_SET_IPV6_DST,
> +
> +	/**
> +	 * Modify source port number in the outermost TCP/UDP header.
> +	 *
> +	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
> +	 * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
> +	 * RTE_FLOW_ERROR_TYPE_ACTION error.
> +	 *
> +	 * See struct rte_flow_action_set_tp.
> +	 */
> +	RTE_FLOW_ACTION_TYPE_SET_TP_SRC,
> +
> +	/**
> +	 * Modify destination port number in the outermost TCP/UDP header.
> +	 *
> +	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
> +	 * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
> +	 * RTE_FLOW_ERROR_TYPE_ACTION error.
> +	 *
> +	 * See struct rte_flow_action_set_tp.
> +	 */
> +	RTE_FLOW_ACTION_TYPE_SET_TP_DST,
>  };
>  
>  /**
> @@ -1938,6 +1960,21 @@ struct rte_flow_action_set_ipv6 {
>  	uint8_t ipv6_addr[16];
>  };
>  
> +/**
> + * @warning
> + * @b EXPERIMENTAL: this structure may change without prior notice
> + *
> + * RTE_FLOW_ACTION_TYPE_SET_TP_SRC
> + * RTE_FLOW_ACTION_TYPE_SET_TP_DST
> + *
> + * Allows modification of source (RTE_FLOW_ACTION_TYPE_SET_TP_SRC)
> + * and destination (RTE_FLOW_ACTION_TYPE_SET_TP_DST) port numbers
> + * in the specified outermost TCP/UDP header.
> + */
> +struct rte_flow_action_set_tp {
> +	uint16_t port;
> +};
> +
>  /*
>   * Definition of a single action.
>   *
> -- 
> 2.18.0
> 
Acked-by: Xiaoyu Min <jackmin@mellanox.com>

Thanks
Ori Kam Oct. 4, 2018, 1:55 p.m. UTC | #2
> -----Original Message-----
> From: dev <dev-bounces@dpdk.org> On Behalf Of Rahul Lakkireddy
> Sent: Monday, September 24, 2018 11:28 AM
> To: dev@dpdk.org
> Cc: indranil@chelsio.com; nirranjan@chelsio.com
> Subject: [dpdk-dev] [PATCH 2/3] ethdev: add flow api actions to modify
> TCP/UDP port numbers
> 
> Add actions:
> - SET_TP_SRC - set a new TCP/UDP source port number.
> - SET_TP_DST - set a new TCP/UDP destination port number.
> 
> Original work by Shagun Agrawal
> 
> Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
> ---
> Changes since RFC v2:
> - Updated comments, help messages, and doc to indicate that IP/TCP/UDP
>   of the outermost headers are modified.
> - Updated comments and doc to indicate that a corresponding valid flow
>   pattern item must be specified to offload corresponding header rewrite
>   action.
> - Updated release notes.
> 
>  app/test-pmd/cmdline_flow.c                 | 52 +++++++++++++++++++++
>  app/test-pmd/config.c                       |  4 ++
>  doc/guides/prog_guide/rte_flow.rst          | 36 ++++++++++++++
>  doc/guides/rel_notes/release_18_11.rst      |  2 +
>  doc/guides/testpmd_app_ug/testpmd_funcs.rst | 10 ++++
>  lib/librte_ethdev/rte_flow.c                |  4 ++
>  lib/librte_ethdev/rte_flow.h                | 37 +++++++++++++++
>  7 files changed, 145 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
> index 1432498a3..a9888cacf 100644
> --- a/app/test-pmd/cmdline_flow.c
> +++ b/app/test-pmd/cmdline_flow.c
> @@ -251,6 +251,10 @@ enum index {
>  	ACTION_SET_IPV6_SRC_IPV6_SRC,
>  	ACTION_SET_IPV6_DST,
>  	ACTION_SET_IPV6_DST_IPV6_DST,
> +	ACTION_SET_TP_SRC,
> +	ACTION_SET_TP_SRC_TP_SRC,
> +	ACTION_SET_TP_DST,
> +	ACTION_SET_TP_DST_TP_DST,
>  };
> 
>  /** Maximum size for pattern in struct rte_flow_item_raw. */
> @@ -828,6 +832,8 @@ static const enum index next_action[] = {
>  	ACTION_SET_IPV4_DST,
>  	ACTION_SET_IPV6_SRC,
>  	ACTION_SET_IPV6_DST,
> +	ACTION_SET_TP_SRC,
> +	ACTION_SET_TP_DST,
>  	ZERO,
>  };
> 
> @@ -954,6 +960,18 @@ static const enum index action_set_ipv6_dst[] = {
>  	ZERO,
>  };
> 
> +static const enum index action_set_tp_src[] = {
> +	ACTION_SET_TP_SRC_TP_SRC,
> +	ACTION_NEXT,
> +	ZERO,
> +};
> +
> +static const enum index action_set_tp_dst[] = {
> +	ACTION_SET_TP_DST_TP_DST,
> +	ACTION_NEXT,
> +	ZERO,
> +};
> +
>  static const enum index action_jump[] = {
>  	ACTION_JUMP_GROUP,
>  	ACTION_NEXT,
> @@ -2574,6 +2592,40 @@ static const struct token token_list[] = {
>  			(struct rte_flow_action_set_ipv6, ipv6_addr)),
>  		.call = parse_vc_conf,
>  	},
> +	[ACTION_SET_TP_SRC] = {
> +		.name = "set_tp_src",
> +		.help = "set a new source port number in the outermost"
> +			" TCP/UDP header",
> +		.priv = PRIV_ACTION(SET_TP_SRC,
> +			sizeof(struct rte_flow_action_set_tp)),
> +		.next = NEXT(action_set_tp_src),
> +		.call = parse_vc,
> +	},
> +	[ACTION_SET_TP_SRC_TP_SRC] = {
> +		.name = "port",
> +		.help = "new source port number to set",
> +		.next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
> +		.args = ARGS(ARGS_ENTRY_HTON
> +			     (struct rte_flow_action_set_tp, port)),
> +		.call = parse_vc_conf,
> +	},
> +	[ACTION_SET_TP_DST] = {
> +		.name = "set_tp_dst",
> +		.help = "set a new destination port number in the outermost"
> +			" TCP/UDP header",
> +		.priv = PRIV_ACTION(SET_TP_DST,
> +			sizeof(struct rte_flow_action_set_tp)),
> +		.next = NEXT(action_set_tp_dst),
> +		.call = parse_vc,
> +	},
> +	[ACTION_SET_TP_DST_TP_DST] = {
> +		.name = "port",
> +		.help = "new destination port number to set",
> +		.next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
> +		.args = ARGS(ARGS_ENTRY_HTON
> +			     (struct rte_flow_action_set_tp, port)),
> +		.call = parse_vc_conf,
> +	},
>  };
> 
>  /** Remove and return last entry from argument stack. */
> diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
> index 14dbdf7a3..1629a6d7a 100644
> --- a/app/test-pmd/config.c
> +++ b/app/test-pmd/config.c
> @@ -1180,6 +1180,10 @@ static const struct {
>  		       sizeof(struct rte_flow_action_set_ipv6)),
>  	MK_FLOW_ACTION(SET_IPV6_DST,
>  		       sizeof(struct rte_flow_action_set_ipv6)),
> +	MK_FLOW_ACTION(SET_TP_SRC,
> +		       sizeof(struct rte_flow_action_set_tp)),
> +	MK_FLOW_ACTION(SET_TP_DST,
> +		       sizeof(struct rte_flow_action_set_tp)),
>  };
> 
>  /** Compute storage space needed by action configuration and copy it. */
> diff --git a/doc/guides/prog_guide/rte_flow.rst
> b/doc/guides/prog_guide/rte_flow.rst
> index b9bcaa3d1..4be160209 100644
> --- a/doc/guides/prog_guide/rte_flow.rst
> +++ b/doc/guides/prog_guide/rte_flow.rst
> @@ -2148,6 +2148,42 @@ Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error
> will be returned.
>     | ``ipv6_addr`` | new IPv6 destination address |
>     +---------------+------------------------------+
> 
> +Action: ``SET_TP_SRC``
> +^^^^^^^^^^^^^^^^^^^^^^^^^
> +
> +Set a new source port number in the outermost TCP/UDP header.
> +
> +It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or
> RTE_FLOW_ITEM_TYPE_UDP
> +flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be
> returned.
> +
> +.. _table_rte_flow_action_set_tp_src:
> +
> +.. table:: SET_TP_SRC
> +
> +   +----------+-------------------------+
> +   | Field    | Value                   |
> +   +==========+=========================+
> +   | ``port`` | new TCP/UDP source port |
> +   +---------------+--------------------+
> +
> +Action: ``SET_TP_DST``
> +^^^^^^^^^^^^^^^^^^^^^^^^^
> +
> +Set a new destination port number in the outermost TCP/UDP header.
> +
> +It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or
> RTE_FLOW_ITEM_TYPE_UDP
> +flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be
> returned.
> +
> +.. _table_rte_flow_action_set_tp_dst:
> +
> +.. table:: SET_TP_DST
> +
> +   +----------+------------------------------+
> +   | Field    | Value                        |
> +   +==========+==============================+
> +   | ``port`` | new TCP/UDP destination port |
> +   +---------------+-------------------------+
> +
>  Negative types
>  ~~~~~~~~~~~~~~
> 
> diff --git a/doc/guides/rel_notes/release_18_11.rst
> b/doc/guides/rel_notes/release_18_11.rst
> index 782722318..84b0a6a4b 100644
> --- a/doc/guides/rel_notes/release_18_11.rst
> +++ b/doc/guides/rel_notes/release_18_11.rst
> @@ -93,6 +93,8 @@ New Features
> 
>    * Modify source and destination IP addresses in the outermost IPv4/IPv6
>      headers.
> +  * Modify source and destination port numbers in the outermost TCP/UDP
> +    headers.
> 
>  API Changes
>  -----------
> diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> index 97d91f066..ffec7013b 100644
> --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> @@ -3722,6 +3722,16 @@ This section lists supported actions and their
> attributes, if any.
> 
>    - ``ipv6_addr``: New IPv6 destination address.
> 
> +- ``of_set_tp_src``: Set a new source port number in the outermost TCP/UDP
> +  header.
> +
> +  - ``port``: New TCP/UDP source port number.
> +
> +- ``of_set_tp_dst``: Set a new destination port number in the outermost
> TCP/UDP
> +  header.
> +
> +  - ``port``: New TCP/UDP destination port number.
> +
>  Destroying flow rules
>  ~~~~~~~~~~~~~~~~~~~~~
> 
> diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
> index d4f1b9a05..409c79741 100644
> --- a/lib/librte_ethdev/rte_flow.c
> +++ b/lib/librte_ethdev/rte_flow.c
> @@ -117,6 +117,10 @@ static const struct rte_flow_desc_data
> rte_flow_desc_action[] = {
>  		       sizeof(struct rte_flow_action_set_ipv6)),
>  	MK_FLOW_ACTION(SET_IPV6_DST,
>  		       sizeof(struct rte_flow_action_set_ipv6)),
> +	MK_FLOW_ACTION(SET_TP_SRC,
> +		       sizeof(struct rte_flow_action_set_tp)),
> +	MK_FLOW_ACTION(SET_TP_DST,
> +		       sizeof(struct rte_flow_action_set_tp)),
>  };
> 
>  static int
> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> index 0fe91ae89..cf5cecf42 100644
> --- a/lib/librte_ethdev/rte_flow.h
> +++ b/lib/librte_ethdev/rte_flow.h
> @@ -1545,6 +1545,28 @@ enum rte_flow_action_type {
>  	 * See struct rte_flow_action_set_ipv6.
>  	 */
>  	RTE_FLOW_ACTION_TYPE_SET_IPV6_DST,
> +
> +	/**
> +	 * Modify source port number in the outermost TCP/UDP header.
> +	 *
> +	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
> +	 * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
> +	 * RTE_FLOW_ERROR_TYPE_ACTION error.
> +	 *
> +	 * See struct rte_flow_action_set_tp.
> +	 */
> +	RTE_FLOW_ACTION_TYPE_SET_TP_SRC,
> +
> +	/**
> +	 * Modify destination port number in the outermost TCP/UDP header.
> +	 *
> +	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
> +	 * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
> +	 * RTE_FLOW_ERROR_TYPE_ACTION error.
> +	 *
> +	 * See struct rte_flow_action_set_tp.
> +	 */
> +	RTE_FLOW_ACTION_TYPE_SET_TP_DST,
>  };
> 
>  /**
> @@ -1938,6 +1960,21 @@ struct rte_flow_action_set_ipv6 {
>  	uint8_t ipv6_addr[16];
>  };
> 
> +/**
> + * @warning
> + * @b EXPERIMENTAL: this structure may change without prior notice
> + *
> + * RTE_FLOW_ACTION_TYPE_SET_TP_SRC
> + * RTE_FLOW_ACTION_TYPE_SET_TP_DST
> + *
> + * Allows modification of source (RTE_FLOW_ACTION_TYPE_SET_TP_SRC)
> + * and destination (RTE_FLOW_ACTION_TYPE_SET_TP_DST) port numbers
> + * in the specified outermost TCP/UDP header.
> + */
> +struct rte_flow_action_set_tp {
> +	uint16_t port;
> +};
> +
>  /*
>   * Definition of a single action.
>   *
> --
> 2.18.0

Acked-by: Ori Kam <orika@mellanox.com>
Ferruh Yigit Oct. 4, 2018, 3:35 p.m. UTC | #3
On 10/4/2018 2:55 PM, Ori Kam wrote:
> 
> 
>> -----Original Message-----
>> From: dev <dev-bounces@dpdk.org> On Behalf Of Rahul Lakkireddy
>> Sent: Monday, September 24, 2018 11:28 AM
>> To: dev@dpdk.org
>> Cc: indranil@chelsio.com; nirranjan@chelsio.com
>> Subject: [dpdk-dev] [PATCH 2/3] ethdev: add flow api actions to modify
>> TCP/UDP port numbers
>>
>> Add actions:
>> - SET_TP_SRC - set a new TCP/UDP source port number.
>> - SET_TP_DST - set a new TCP/UDP destination port number.
>>
>> Original work by Shagun Agrawal
>>
>> Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
<...>
> Acked-by: Ori Kam <orika@mellanox.com>

Hi Rahul,

Can you please rebase the set on top of latest head? Please keep Acks in new
version of the set.

Thanks,
ferruh

Patch
diff mbox series

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 1432498a3..a9888cacf 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -251,6 +251,10 @@  enum index {
 	ACTION_SET_IPV6_SRC_IPV6_SRC,
 	ACTION_SET_IPV6_DST,
 	ACTION_SET_IPV6_DST_IPV6_DST,
+	ACTION_SET_TP_SRC,
+	ACTION_SET_TP_SRC_TP_SRC,
+	ACTION_SET_TP_DST,
+	ACTION_SET_TP_DST_TP_DST,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -828,6 +832,8 @@  static const enum index next_action[] = {
 	ACTION_SET_IPV4_DST,
 	ACTION_SET_IPV6_SRC,
 	ACTION_SET_IPV6_DST,
+	ACTION_SET_TP_SRC,
+	ACTION_SET_TP_DST,
 	ZERO,
 };
 
@@ -954,6 +960,18 @@  static const enum index action_set_ipv6_dst[] = {
 	ZERO,
 };
 
+static const enum index action_set_tp_src[] = {
+	ACTION_SET_TP_SRC_TP_SRC,
+	ACTION_NEXT,
+	ZERO,
+};
+
+static const enum index action_set_tp_dst[] = {
+	ACTION_SET_TP_DST_TP_DST,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_jump[] = {
 	ACTION_JUMP_GROUP,
 	ACTION_NEXT,
@@ -2574,6 +2592,40 @@  static const struct token token_list[] = {
 			(struct rte_flow_action_set_ipv6, ipv6_addr)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_SET_TP_SRC] = {
+		.name = "set_tp_src",
+		.help = "set a new source port number in the outermost"
+			" TCP/UDP header",
+		.priv = PRIV_ACTION(SET_TP_SRC,
+			sizeof(struct rte_flow_action_set_tp)),
+		.next = NEXT(action_set_tp_src),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TP_SRC_TP_SRC] = {
+		.name = "port",
+		.help = "new source port number to set",
+		.next = NEXT(action_set_tp_src, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_tp, port)),
+		.call = parse_vc_conf,
+	},
+	[ACTION_SET_TP_DST] = {
+		.name = "set_tp_dst",
+		.help = "set a new destination port number in the outermost"
+			" TCP/UDP header",
+		.priv = PRIV_ACTION(SET_TP_DST,
+			sizeof(struct rte_flow_action_set_tp)),
+		.next = NEXT(action_set_tp_dst),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TP_DST_TP_DST] = {
+		.name = "port",
+		.help = "new destination port number to set",
+		.next = NEXT(action_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_tp, port)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 14dbdf7a3..1629a6d7a 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1180,6 +1180,10 @@  static const struct {
 		       sizeof(struct rte_flow_action_set_ipv6)),
 	MK_FLOW_ACTION(SET_IPV6_DST,
 		       sizeof(struct rte_flow_action_set_ipv6)),
+	MK_FLOW_ACTION(SET_TP_SRC,
+		       sizeof(struct rte_flow_action_set_tp)),
+	MK_FLOW_ACTION(SET_TP_DST,
+		       sizeof(struct rte_flow_action_set_tp)),
 };
 
 /** Compute storage space needed by action configuration and copy it. */
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index b9bcaa3d1..4be160209 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2148,6 +2148,42 @@  Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
    | ``ipv6_addr`` | new IPv6 destination address |
    +---------------+------------------------------+
 
+Action: ``SET_TP_SRC``
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Set a new source port number in the outermost TCP/UDP header.
+
+It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
+flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
+
+.. _table_rte_flow_action_set_tp_src:
+
+.. table:: SET_TP_SRC
+
+   +----------+-------------------------+
+   | Field    | Value                   |
+   +==========+=========================+
+   | ``port`` | new TCP/UDP source port |
+   +---------------+--------------------+
+
+Action: ``SET_TP_DST``
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Set a new destination port number in the outermost TCP/UDP header.
+
+It must be used with a valid RTE_FLOW_ITEM_TYPE_TCP or RTE_FLOW_ITEM_TYPE_UDP
+flow pattern item. Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
+
+.. _table_rte_flow_action_set_tp_dst:
+
+.. table:: SET_TP_DST
+
+   +----------+------------------------------+
+   | Field    | Value                        |
+   +==========+==============================+
+   | ``port`` | new TCP/UDP destination port |
+   +---------------+-------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_18_11.rst b/doc/guides/rel_notes/release_18_11.rst
index 782722318..84b0a6a4b 100644
--- a/doc/guides/rel_notes/release_18_11.rst
+++ b/doc/guides/rel_notes/release_18_11.rst
@@ -93,6 +93,8 @@  New Features
 
   * Modify source and destination IP addresses in the outermost IPv4/IPv6
     headers.
+  * Modify source and destination port numbers in the outermost TCP/UDP
+    headers.
 
 API Changes
 -----------
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 97d91f066..ffec7013b 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3722,6 +3722,16 @@  This section lists supported actions and their attributes, if any.
 
   - ``ipv6_addr``: New IPv6 destination address.
 
+- ``of_set_tp_src``: Set a new source port number in the outermost TCP/UDP
+  header.
+
+  - ``port``: New TCP/UDP source port number.
+
+- ``of_set_tp_dst``: Set a new destination port number in the outermost TCP/UDP
+  header.
+
+  - ``port``: New TCP/UDP destination port number.
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index d4f1b9a05..409c79741 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -117,6 +117,10 @@  static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_set_ipv6)),
 	MK_FLOW_ACTION(SET_IPV6_DST,
 		       sizeof(struct rte_flow_action_set_ipv6)),
+	MK_FLOW_ACTION(SET_TP_SRC,
+		       sizeof(struct rte_flow_action_set_tp)),
+	MK_FLOW_ACTION(SET_TP_DST,
+		       sizeof(struct rte_flow_action_set_tp)),
 };
 
 static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index 0fe91ae89..cf5cecf42 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1545,6 +1545,28 @@  enum rte_flow_action_type {
 	 * See struct rte_flow_action_set_ipv6.
 	 */
 	RTE_FLOW_ACTION_TYPE_SET_IPV6_DST,
+
+	/**
+	 * Modify source port number in the outermost TCP/UDP header.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
+	 * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_tp.
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_TP_SRC,
+
+	/**
+	 * Modify destination port number in the outermost TCP/UDP header.
+	 *
+	 * If flow pattern does not define a valid RTE_FLOW_ITEM_TYPE_TCP
+	 * or RTE_FLOW_ITEM_TYPE_UDP, then the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_tp.
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_TP_DST,
 };
 
 /**
@@ -1938,6 +1960,21 @@  struct rte_flow_action_set_ipv6 {
 	uint8_t ipv6_addr[16];
 };
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_SET_TP_SRC
+ * RTE_FLOW_ACTION_TYPE_SET_TP_DST
+ *
+ * Allows modification of source (RTE_FLOW_ACTION_TYPE_SET_TP_SRC)
+ * and destination (RTE_FLOW_ACTION_TYPE_SET_TP_DST) port numbers
+ * in the specified outermost TCP/UDP header.
+ */
+struct rte_flow_action_set_tp {
+	uint16_t port;
+};
+
 /*
  * Definition of a single action.
  *