From patchwork Fri Jun 22 09:56:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Lakkireddy X-Patchwork-Id: 41385 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id CB2F01BB35; Fri, 22 Jun 2018 11:57:16 +0200 (CEST) Received: from stargate.chelsio.com (stargate.chelsio.com [12.32.117.8]) by dpdk.org (Postfix) with ESMTP id 887C31B8F6 for ; Fri, 22 Jun 2018 11:57:14 +0200 (CEST) Received: from localhost (scalar.blr.asicdesigners.com [10.193.185.94]) by stargate.chelsio.com (8.13.8/8.13.8) with ESMTP id w5M9v5rV000804; Fri, 22 Jun 2018 02:57:10 -0700 From: Rahul Lakkireddy To: dev@dpdk.org Cc: shaguna@chelsio.com, indranil@chelsio.com, nirranjan@chelsio.com Date: Fri, 22 Jun 2018 15:26:03 +0530 Message-Id: X-Mailer: git-send-email 2.5.3 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [RFC 1/3] ethdev: add flow api actions to modify IP addresses X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Shagun Agrawal Add actions: - OF_SET_NW_IPV4_SRC - set a new IPv4 source address. - OF_SET_NW_IPV4_DST - set a new IPv4 destination address. - OF_SET_NW_IPV6_SRC - set a new IPv6 source address. - OF_SET_NW_IPV6_DST - set a new IPv6 destination address. Based on OFPAT_SET_NW_SRC and OFPAT_SET_NW_DST in OpenFlow Specification. Signed-off-by: Shagun Agrawal Signed-off-by: Rahul Lakkireddy --- app/test-pmd/cmdline_flow.c | 100 ++++++++++++++++++++++++++++ app/test-pmd/config.c | 8 +++ doc/guides/prog_guide/rte_flow.rst | 68 +++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 16 +++++ lib/librte_ethdev/rte_flow.c | 8 +++ lib/librte_ethdev/rte_flow.h | 62 +++++++++++++++++ 6 files changed, 262 insertions(+) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 9918d7fda..4550491ec 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -237,6 +237,14 @@ enum index { ACTION_OF_POP_MPLS_ETHERTYPE, ACTION_OF_PUSH_MPLS, ACTION_OF_PUSH_MPLS_ETHERTYPE, + ACTION_OF_SET_NW_IPV4_SRC, + ACTION_OF_SET_NW_IPV4_SRC_NW_IPV4_SRC, + ACTION_OF_SET_NW_IPV4_DST, + ACTION_OF_SET_NW_IPV4_DST_NW_IPV4_DST, + ACTION_OF_SET_NW_IPV6_SRC, + ACTION_OF_SET_NW_IPV6_SRC_NW_IPV6_SRC, + ACTION_OF_SET_NW_IPV6_DST, + ACTION_OF_SET_NW_IPV6_DST_NW_IPV6_DST, }; /** Maximum size for pattern in struct rte_flow_item_raw. */ @@ -773,6 +781,10 @@ static const enum index next_action[] = { ACTION_OF_SET_VLAN_PCP, ACTION_OF_POP_MPLS, ACTION_OF_PUSH_MPLS, + ACTION_OF_SET_NW_IPV4_SRC, + ACTION_OF_SET_NW_IPV4_DST, + ACTION_OF_SET_NW_IPV6_SRC, + ACTION_OF_SET_NW_IPV6_DST, ZERO, }; @@ -868,6 +880,30 @@ static const enum index action_of_push_mpls[] = { ZERO, }; +static const enum index action_of_set_nw_ipv4_src[] = { + ACTION_OF_SET_NW_IPV4_SRC_NW_IPV4_SRC, + ACTION_NEXT, + ZERO, +}; + +static const enum index action_of_set_nw_ipv4_dst[] = { + ACTION_OF_SET_NW_IPV4_DST_NW_IPV4_DST, + ACTION_NEXT, + ZERO, +}; + +static const enum index action_of_set_nw_ipv6_src[] = { + ACTION_OF_SET_NW_IPV6_SRC_NW_IPV6_SRC, + ACTION_NEXT, + ZERO, +}; + +static const enum index action_of_set_nw_ipv6_dst[] = { + ACTION_OF_SET_NW_IPV6_DST_NW_IPV6_DST, + ACTION_NEXT, + ZERO, +}; + static const enum index action_jump[] = { ACTION_JUMP_GROUP, ACTION_NEXT, @@ -2362,6 +2398,70 @@ static const struct token token_list[] = { ethertype)), .call = parse_vc_conf, }, + [ACTION_OF_SET_NW_IPV4_SRC] = { + .name = "of_set_ipv4_src", + .help = "set ipv4 source address", + .priv = PRIV_ACTION(OF_SET_NW_IPV4_SRC, + sizeof(struct rte_flow_action_of_set_nw_ipv4)), + .next = NEXT(action_of_set_nw_ipv4_src), + .call = parse_vc, + }, + [ACTION_OF_SET_NW_IPV4_SRC_NW_IPV4_SRC] = { + .name = "ipv4_addr", + .help = "new ipv4 source address to set", + .next = NEXT(action_of_set_nw_ipv4_src, NEXT_ENTRY(IPV4_ADDR)), + .args = ARGS(ARGS_ENTRY_HTON + (struct rte_flow_action_of_set_nw_ipv4, ipv4_addr)), + .call = parse_vc_conf, + }, + [ACTION_OF_SET_NW_IPV4_DST] = { + .name = "of_set_ipv4_dst", + .help = "set ipv4 destination address", + .priv = PRIV_ACTION(OF_SET_NW_IPV4_DST, + sizeof(struct rte_flow_action_of_set_nw_ipv4)), + .next = NEXT(action_of_set_nw_ipv4_dst), + .call = parse_vc, + }, + [ACTION_OF_SET_NW_IPV4_DST_NW_IPV4_DST] = { + .name = "ipv4_addr", + .help = "new ipv4 destination address to set", + .next = NEXT(action_of_set_nw_ipv4_dst, NEXT_ENTRY(IPV4_ADDR)), + .args = ARGS(ARGS_ENTRY_HTON + (struct rte_flow_action_of_set_nw_ipv4, ipv4_addr)), + .call = parse_vc_conf, + }, + [ACTION_OF_SET_NW_IPV6_SRC] = { + .name = "of_set_ipv6_src", + .help = "set ipv6 source address", + .priv = PRIV_ACTION(OF_SET_NW_IPV6_SRC, + sizeof(struct rte_flow_action_of_set_nw_ipv6)), + .next = NEXT(action_of_set_nw_ipv6_src), + .call = parse_vc, + }, + [ACTION_OF_SET_NW_IPV6_SRC_NW_IPV6_SRC] = { + .name = "ipv6_addr", + .help = "new ipv6 source address to set", + .next = NEXT(action_of_set_nw_ipv6_src, NEXT_ENTRY(IPV6_ADDR)), + .args = ARGS(ARGS_ENTRY_HTON + (struct rte_flow_action_of_set_nw_ipv6, ipv6_addr)), + .call = parse_vc_conf, + }, + [ACTION_OF_SET_NW_IPV6_DST] = { + .name = "of_set_ipv6_dst", + .help = "set ipv6 destination address", + .priv = PRIV_ACTION(OF_SET_NW_IPV6_DST, + sizeof(struct rte_flow_action_of_set_nw_ipv6)), + .next = NEXT(action_of_set_nw_ipv6_dst), + .call = parse_vc, + }, + [ACTION_OF_SET_NW_IPV6_DST_NW_IPV6_DST] = { + .name = "ipv6_addr", + .help = "new ipv6 destination address to set", + .next = NEXT(action_of_set_nw_ipv6_dst, NEXT_ENTRY(IPV6_ADDR)), + .args = ARGS(ARGS_ENTRY_HTON + (struct rte_flow_action_of_set_nw_ipv6, ipv6_addr)), + .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 97020fb3d..83cb0354d 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -1153,6 +1153,14 @@ static const struct { sizeof(struct rte_flow_action_of_pop_mpls)), MK_FLOW_ACTION(OF_PUSH_MPLS, sizeof(struct rte_flow_action_of_push_mpls)), + MK_FLOW_ACTION(OF_SET_NW_IPV4_SRC, + sizeof(struct rte_flow_action_of_set_nw_ipv4)), + MK_FLOW_ACTION(OF_SET_NW_IPV4_DST, + sizeof(struct rte_flow_action_of_set_nw_ipv4)), + MK_FLOW_ACTION(OF_SET_NW_IPV6_SRC, + sizeof(struct rte_flow_action_of_set_nw_ipv6)), + MK_FLOW_ACTION(OF_SET_NW_IPV6_DST, + sizeof(struct rte_flow_action_of_set_nw_ipv6)), }; /** 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 b305a72a5..3f56cc2d1 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -2076,6 +2076,74 @@ RTE_FLOW_ERROR_TYPE_ACTION error should be returned. This action modifies the payload of matched flows. +Action: ``OF_SET_NW_IPV4_SRC`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Set a new IPv4 source address. It is based on ``OFPAT_SET_NW_SRC`` +("set the network source address") as defined by the +`OpenFlow Switch Specification`_. + +.. _table_rte_flow_action_of_set_nw_ipv4_src: + +.. table:: OF_SET_NW_IPV4_SRC + + +---------------+-------------------------+ + | Field | Value | + +===============+=========================+ + | ``ipv4_addr`` | new IPv4 source address | + +---------------+-------------------------+ + +Action: ``OF_SET_NW_IPV4_DST`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Set a new IPv4 destination address. It is based on ``OFPAT_SET_NW_DST`` +("set the network destination address") as defined by the +`OpenFlow Switch Specification`_. + +.. _table_rte_flow_action_of_set_nw_ipv4_dst: + +.. table:: OF_SET_NW_IPV4_DST + + +---------------+------------------------------+ + | Field | Value | + +===============+==============================+ + | ``ipv4_addr`` | new IPv4 destination address | + +---------------+------------------------------+ + +Action: ``OF_SET_NW_IPV6_SRC`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Set a new IPv6 source address. It is based on ``OFPAT_SET_NW_SRC`` +("set the network source address") as defined by the +`OpenFlow Switch Specification`_. + +.. _table_rte_flow_action_of_set_nw_ipv6_src: + +.. table:: OF_SET_NW_IPV6_SRC + + +---------------+-------------------------+ + | Field | Value | + +===============+=========================+ + | ``ipv6_addr`` | new IPv6 source address | + +---------------+-------------------------+ + +Action: ``OF_SET_NW_IPV6_DST`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Set a new IPv6 destination address. It is based on ``OFPAT_SET_NW_DST`` +("set the network destination address") as defined by the +`OpenFlow Switch Specification`_. + +.. _table_rte_flow_action_of_set_nw_ipv6_dst: + +.. table:: OF_SET_NW_IPV6_DST + + +---------------+------------------------------+ + | Field | Value | + +===============+==============================+ + | ``ipv6_addr`` | new IPv6 destination address | + +---------------+------------------------------+ + Negative types ~~~~~~~~~~~~~~ diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 0d6fd50ca..56e3d6326 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -3650,6 +3650,22 @@ This section lists supported actions and their attributes, if any. - ``ethertype``: Ethertype. +- ``of_set_ipv4_src``: Set a new IPv4 source address. + + - ``ipv4_addr``: New IPv4 source address. + +- ``of_set_ipv4_dst``: Set a new IPv4 destination address. + + - ``ipv4_addr``: New IPv4 destination address. + +- ``of_set_ipv6_src``: Set a new IPv6 source address. + + - ``ipv6_addr``: New IPv6 source address. + +- ``of_set_ipv6_dst``: Set a new ipv6 destination address. + + - ``ipv6_addr``: New IPv6 destination address. + Destroying flow rules ~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c index b2afba089..29f846783 100644 --- a/lib/librte_ethdev/rte_flow.c +++ b/lib/librte_ethdev/rte_flow.c @@ -109,6 +109,14 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = { sizeof(struct rte_flow_action_of_pop_mpls)), MK_FLOW_ACTION(OF_PUSH_MPLS, sizeof(struct rte_flow_action_of_push_mpls)), + MK_FLOW_ACTION(OF_SET_NW_IPV4_SRC, + sizeof(struct rte_flow_action_of_set_nw_ipv4)), + MK_FLOW_ACTION(OF_SET_NW_IPV4_DST, + sizeof(struct rte_flow_action_of_set_nw_ipv4)), + MK_FLOW_ACTION(OF_SET_NW_IPV6_SRC, + sizeof(struct rte_flow_action_of_set_nw_ipv6)), + MK_FLOW_ACTION(OF_SET_NW_IPV6_DST, + sizeof(struct rte_flow_action_of_set_nw_ipv6)), }; static int diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h index f8ba71cdb..76cf652c5 100644 --- a/lib/librte_ethdev/rte_flow.h +++ b/lib/librte_ethdev/rte_flow.h @@ -1505,6 +1505,38 @@ enum rte_flow_action_type { * error. */ RTE_FLOW_ACTION_TYPE_NVGRE_DECAP, + + /** + * Implements OFPAT_SET_NW_SRC (set the network src addr) as defined + * by the OpenFlow Switch Specification for ipv4 address. + * + * See struct rte_flow_action_of_set_nw_ipv4. + */ + RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV4_SRC, + + /** + * Implements OFPAT_SET_NW_DST (set the network dst addr) as defined + * by the OpenFlow Switch Specification for ipv4 address. + * + * See struct rte_flow_action_of_set_nw_ipv4. + */ + RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV4_DST, + + /** + * Implements OFPAT_SET_NW_SRC (set the network src addr) as defined + * by the OpenFlow Switch Specification for ipv6 address. + * + * See struct rte_flow_action_of_set_nw_ipv6. + */ + RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV6_SRC, + + /** + * Implements OFPAT_SET_NW_DST (set the network dst addr) as defined + * by the OpenFlow Switch Specification for ipv6 address. + * + * See struct rte_flow_action_of_set_nw_ipv6. + */ + RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV6_DST, }; /** @@ -1868,6 +1900,36 @@ struct rte_flow_action_nvgre_encap { struct rte_flow_item *definition; }; +/** + * @warning + * @b EXPERIMENTAL: this structure may change without prior notice + * + * RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV4_SRC + * RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV4_DST + * + * Implements OFPAT_SET_NW_SRC & OFPAT_SET_NW_DST (set the network + * src/dst addr) as defined by the OpenFlow Switch Specification + * for ipv4 address. + */ +struct rte_flow_action_of_set_nw_ipv4 { + uint32_t ipv4_addr; +}; + +/** + * @warning + * @b EXPERIMENTAL: this structure may change without prior notice + * + * RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV6_SRC + * RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV6_DST + * + * Implements OFPAT_SET_NW_SRC & OFPAT_SET_NW_DST (set the network + * src/dst addr) as defined by the OpenFlow Switch Specification + * for ipv6 address. + */ +struct rte_flow_action_of_set_nw_ipv6 { + uint8_t ipv6_addr[16]; +}; + /* * Definition of a single action. * From patchwork Fri Jun 22 09:56:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Lakkireddy X-Patchwork-Id: 41386 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4933A1BB52; Fri, 22 Jun 2018 11:57:20 +0200 (CEST) Received: from stargate.chelsio.com (stargate.chelsio.com [12.32.117.8]) by dpdk.org (Postfix) with ESMTP id 072041BB20 for ; Fri, 22 Jun 2018 11:57:15 +0200 (CEST) Received: from localhost (scalar.blr.asicdesigners.com [10.193.185.94]) by stargate.chelsio.com (8.13.8/8.13.8) with ESMTP id w5M9vCI0000809; Fri, 22 Jun 2018 02:57:13 -0700 From: Rahul Lakkireddy To: dev@dpdk.org Cc: shaguna@chelsio.com, indranil@chelsio.com, nirranjan@chelsio.com Date: Fri, 22 Jun 2018 15:26:04 +0530 Message-Id: X-Mailer: git-send-email 2.5.3 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [RFC 2/3] ethdev: add flow api actions to modify TCP/UDP port numbers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Shagun Agrawal Add actions: - OF_SET_TP_SRC - set a new TCP/UDP source port number. - OF_SET_TP_DST - set a new TCP/UDP destination port number. Based on OFPAT_SET_TP_SRC and OFPAT_SET_TP_DST actions from OpenFlow Specification. Signed-off-by: Shagun Agrawal Signed-off-by: Rahul Lakkireddy --- app/test-pmd/cmdline_flow.c | 50 +++++++++++++++++++++++++++++ app/test-pmd/config.c | 4 +++ doc/guides/prog_guide/rte_flow.rst | 34 ++++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 8 +++++ lib/librte_ethdev/rte_flow.c | 4 +++ lib/librte_ethdev/rte_flow.h | 30 +++++++++++++++++ 6 files changed, 130 insertions(+) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 4550491ec..87745ada9 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -245,6 +245,10 @@ enum index { ACTION_OF_SET_NW_IPV6_SRC_NW_IPV6_SRC, ACTION_OF_SET_NW_IPV6_DST, ACTION_OF_SET_NW_IPV6_DST_NW_IPV6_DST, + ACTION_OF_SET_TP_SRC, + ACTION_OF_SET_TP_SRC_TP_SRC, + ACTION_OF_SET_TP_DST, + ACTION_OF_SET_TP_DST_TP_DST, }; /** Maximum size for pattern in struct rte_flow_item_raw. */ @@ -785,6 +789,8 @@ static const enum index next_action[] = { ACTION_OF_SET_NW_IPV4_DST, ACTION_OF_SET_NW_IPV6_SRC, ACTION_OF_SET_NW_IPV6_DST, + ACTION_OF_SET_TP_SRC, + ACTION_OF_SET_TP_DST, ZERO, }; @@ -904,6 +910,18 @@ static const enum index action_of_set_nw_ipv6_dst[] = { ZERO, }; +static const enum index action_of_set_tp_src[] = { + ACTION_OF_SET_TP_SRC_TP_SRC, + ACTION_NEXT, + ZERO, +}; + +static const enum index action_of_set_tp_dst[] = { + ACTION_OF_SET_TP_DST_TP_DST, + ACTION_NEXT, + ZERO, +}; + static const enum index action_jump[] = { ACTION_JUMP_GROUP, ACTION_NEXT, @@ -2462,6 +2480,38 @@ static const struct token token_list[] = { (struct rte_flow_action_of_set_nw_ipv6, ipv6_addr)), .call = parse_vc_conf, }, + [ACTION_OF_SET_TP_SRC] = { + .name = "of_set_tp_src", + .help = "set tcp/udp source port number", + .priv = PRIV_ACTION(OF_SET_TP_SRC, + sizeof(struct rte_flow_action_of_set_tp)), + .next = NEXT(action_of_set_tp_src), + .call = parse_vc, + }, + [ACTION_OF_SET_TP_SRC_TP_SRC] = { + .name = "port", + .help = "new source port number to set", + .next = NEXT(action_of_set_tp_src, NEXT_ENTRY(UNSIGNED)), + .args = ARGS(ARGS_ENTRY_HTON + (struct rte_flow_action_of_set_tp, port)), + .call = parse_vc_conf, + }, + [ACTION_OF_SET_TP_DST] = { + .name = "of_set_tp_dst", + .help = "set tcp/udp destination port number", + .priv = PRIV_ACTION(OF_SET_TP_DST, + sizeof(struct rte_flow_action_of_set_tp)), + .next = NEXT(action_of_set_tp_dst), + .call = parse_vc, + }, + [ACTION_OF_SET_TP_DST_TP_DST] = { + .name = "port", + .help = "new destination port number to set", + .next = NEXT(action_of_set_tp_dst, NEXT_ENTRY(UNSIGNED)), + .args = ARGS(ARGS_ENTRY_HTON + (struct rte_flow_action_of_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 83cb0354d..1faf0071e 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -1161,6 +1161,10 @@ static const struct { sizeof(struct rte_flow_action_of_set_nw_ipv6)), MK_FLOW_ACTION(OF_SET_NW_IPV6_DST, sizeof(struct rte_flow_action_of_set_nw_ipv6)), + MK_FLOW_ACTION(OF_SET_TP_SRC, + sizeof(struct rte_flow_action_of_set_tp)), + MK_FLOW_ACTION(OF_SET_TP_DST, + sizeof(struct rte_flow_action_of_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 3f56cc2d1..76c25a606 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -2144,6 +2144,40 @@ Set a new IPv6 destination address. It is based on ``OFPAT_SET_NW_DST`` | ``ipv6_addr`` | new IPv6 destination address | +---------------+------------------------------+ +Action: ``OF_SET_TP_SRC`` +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Set a new TCP/UDP source port number. It is based on ``OFPAT_SET_TP_SRC`` +("set the transport source address") as defined by the +`OpenFlow Switch Specification`_. + +.. _table_rte_flow_action_of_set_tp_src: + +.. table:: OF_SET_TP_SRC + + +----------+-------------------------+ + | Field | Value | + +==========+=========================+ + | ``port`` | new TCP/UDP source port | + +---------------+--------------------+ + +Action: ``OF_SET_TP_DST`` +^^^^^^^^^^^^^^^^^^^^^^^^^ + +Set a new TCP/UDP destination port number. It is based on ``OFPAT_SET_TP_DST`` +("set the transport destination address") as defined by the +`OpenFlow Switch Specification`_. + +.. _table_rte_flow_action_of_set_tp_dst: + +.. table:: OF_SET_TP_DST + + +----------+------------------------------+ + | Field | Value | + +==========+==============================+ + | ``port`` | new TCP/UDP destination port | + +---------------+-------------------------+ + Negative types ~~~~~~~~~~~~~~ diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 56e3d6326..488b84de8 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -3666,6 +3666,14 @@ This section lists supported actions and their attributes, if any. - ``ipv6_addr``: New IPv6 destination address. +- ``of_set_tp_src``: Set a new TCP/UDP source port number. + + - ``port``: New TCP/UDP source port number. + +- ``of_set_tp_dst``: Set a new TCP/UDP destination port number. + + - ``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 29f846783..c1ec26276 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_of_set_nw_ipv6)), MK_FLOW_ACTION(OF_SET_NW_IPV6_DST, sizeof(struct rte_flow_action_of_set_nw_ipv6)), + MK_FLOW_ACTION(OF_SET_TP_SRC, + sizeof(struct rte_flow_action_of_set_tp)), + MK_FLOW_ACTION(OF_SET_TP_DST, + sizeof(struct rte_flow_action_of_set_tp)), }; static int diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h index 76cf652c5..9b58f3894 100644 --- a/lib/librte_ethdev/rte_flow.h +++ b/lib/librte_ethdev/rte_flow.h @@ -1537,6 +1537,22 @@ enum rte_flow_action_type { * See struct rte_flow_action_of_set_nw_ipv6. */ RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV6_DST, + + /** + * Implements OFPAT_SET_TP_SRC (set the source transport port) as + * defined by the OpenFlow Switch Specification for tcp/udp. + * + * See struct rte_flow_action_of_set_tp. + */ + RTE_FLOW_ACTION_TYPE_OF_SET_TP_SRC, + + /** + * Implements OFPAT_SET_TP_DST (set the destination transport port) + * as defined by the OpenFlow Switch Specification for tcp/udp. + * + * See struct rte_flow_action_of_set_tp. + */ + RTE_FLOW_ACTION_TYPE_OF_SET_TP_DST, }; /** @@ -1930,6 +1946,20 @@ struct rte_flow_action_of_set_nw_ipv6 { uint8_t ipv6_addr[16]; }; +/** + * @warning + * @b EXPERIMENTAL: this structure may change without prior notice + * + * RTE_FLOW_ACTION_TYPE_OF_SET_TP_SRC + * RTE_FLOW_ACTION_TYPE_OF_SET_TP_DST + * + * Implements OFPAT_SET_TP_SRC & OFPAT_SET_TP_DST (set the transport port) + * as defined by the OpenFlow Switch Specification for tcp/udp. + */ +struct rte_flow_action_of_set_tp { + uint16_t port; +}; + /* * Definition of a single action. * From patchwork Fri Jun 22 09:56:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Lakkireddy X-Patchwork-Id: 41387 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A26611BB71; Fri, 22 Jun 2018 11:57:21 +0200 (CEST) Received: from stargate.chelsio.com (stargate.chelsio.com [12.32.117.8]) by dpdk.org (Postfix) with ESMTP id 832641BB3D for ; Fri, 22 Jun 2018 11:57:19 +0200 (CEST) Received: from localhost (scalar.blr.asicdesigners.com [10.193.185.94]) by stargate.chelsio.com (8.13.8/8.13.8) with ESMTP id w5M9vF7G000812; Fri, 22 Jun 2018 02:57:15 -0700 From: Rahul Lakkireddy To: dev@dpdk.org Cc: shaguna@chelsio.com, indranil@chelsio.com, nirranjan@chelsio.com Date: Fri, 22 Jun 2018 15:26:05 +0530 Message-Id: <22b7a1f11b2076719c3fee60306eec860ea3eed1.1529650435.git.rahul.lakkireddy@chelsio.com> X-Mailer: git-send-email 2.5.3 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [RFC 3/3] net/cxgbe: add flow actions to modify IP and TCP/UDP port address X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Shagun Agrawal Query firmware for the new filter work request to offload flows with actions to modify IP and TCP/UDP port addresses. When available, translate IP and TCP/UDP port address modify actions to internal hardware specification and offload the flow to hardware. Signed-off-by: Shagun Agrawal Signed-off-by: Rahul Lakkireddy --- drivers/net/cxgbe/base/common.h | 1 + drivers/net/cxgbe/base/t4fw_interface.h | 50 +++++++++++++ drivers/net/cxgbe/cxgbe_filter.c | 23 +++++- drivers/net/cxgbe/cxgbe_filter.h | 26 ++++++- drivers/net/cxgbe/cxgbe_flow.c | 127 ++++++++++++++++++++++++++++++++ drivers/net/cxgbe/cxgbe_main.c | 10 +++ 6 files changed, 233 insertions(+), 4 deletions(-) diff --git a/drivers/net/cxgbe/base/common.h b/drivers/net/cxgbe/base/common.h index e524f7931..f4b2e14cd 100644 --- a/drivers/net/cxgbe/base/common.h +++ b/drivers/net/cxgbe/base/common.h @@ -256,6 +256,7 @@ struct adapter_params { bool ulptx_memwrite_dsgl; /* use of T5 DSGL allowed */ u8 fw_caps_support; /* 32-bit Port Capabilities */ + bool filter2_wr_support; /* FW support for FILTER2_WR */ }; /* Firmware Port Capabilities types. diff --git a/drivers/net/cxgbe/base/t4fw_interface.h b/drivers/net/cxgbe/base/t4fw_interface.h index 842aa1263..d20d73590 100644 --- a/drivers/net/cxgbe/base/t4fw_interface.h +++ b/drivers/net/cxgbe/base/t4fw_interface.h @@ -59,6 +59,7 @@ enum fw_wr_opcodes { FW_ETH_TX_PKTS_WR = 0x09, FW_ETH_TX_PKT_VM_WR = 0x11, FW_ETH_TX_PKTS_VM_WR = 0x12, + FW_FILTER2_WR = 0x77, FW_ETH_TX_PKTS2_WR = 0x78, }; @@ -185,6 +186,51 @@ struct fw_filter_wr { __u8 sma[6]; }; +struct fw_filter2_wr { + __be32 op_pkd; + __be32 len16_pkd; + __be64 r3; + __be32 tid_to_iq; + __be32 del_filter_to_l2tix; + __be16 ethtype; + __be16 ethtypem; + __u8 frag_to_ovlan_vldm; + __u8 smac_sel; + __be16 rx_chan_rx_rpl_iq; + __be32 maci_to_matchtypem; + __u8 ptcl; + __u8 ptclm; + __u8 ttyp; + __u8 ttypm; + __be16 ivlan; + __be16 ivlanm; + __be16 ovlan; + __be16 ovlanm; + __u8 lip[16]; + __u8 lipm[16]; + __u8 fip[16]; + __u8 fipm[16]; + __be16 lp; + __be16 lpm; + __be16 fp; + __be16 fpm; + __be16 r7; + __u8 sma[6]; + __be16 r8; + __u8 filter_type_swapmac; + __u8 natmode_to_ulp_type; + __be16 newlport; + __be16 newfport; + __u8 newlip[16]; + __u8 newfip[16]; + __be32 natseqcheck; + __be32 r9; + __be64 r10; + __be64 r11; + __be64 r12; + __be64 r13; +}; + #define S_FW_FILTER_WR_TID 12 #define V_FW_FILTER_WR_TID(x) ((x) << S_FW_FILTER_WR_TID) @@ -288,6 +334,9 @@ struct fw_filter_wr { #define S_FW_FILTER_WR_MATCHTYPEM 0 #define V_FW_FILTER_WR_MATCHTYPEM(x) ((x) << S_FW_FILTER_WR_MATCHTYPEM) +#define S_FW_FILTER2_WR_NATMODE 5 +#define V_FW_FILTER2_WR_NATMODE(x) ((x) << S_FW_FILTER2_WR_NATMODE) + /****************************************************************************** * C O M M A N D s *********************/ @@ -642,6 +691,7 @@ enum fw_params_param_dev { FW_PARAMS_PARAM_DEV_FWREV = 0x0B, /* fw version */ FW_PARAMS_PARAM_DEV_TPREV = 0x0C, /* tp version */ FW_PARAMS_PARAM_DEV_ULPTX_MEMWRITE_DSGL = 0x17, + FW_PARAMS_PARAM_DEV_FILTER2_WR = 0x1D, }; /* diff --git a/drivers/net/cxgbe/cxgbe_filter.c b/drivers/net/cxgbe/cxgbe_filter.c index d098b9308..6744b6a60 100644 --- a/drivers/net/cxgbe/cxgbe_filter.c +++ b/drivers/net/cxgbe/cxgbe_filter.c @@ -30,6 +30,10 @@ int validate_filter(struct adapter *adapter, struct ch_filter_specification *fs) #undef S #undef U + + if (fs->nat_mode && !adapter->params.filter2_wr_support) + return -EOPNOTSUPP; + return 0; } @@ -193,7 +197,7 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx) struct adapter *adapter = ethdev2adap(dev); struct filter_entry *f = &adapter->tids.ftid_tab[fidx]; struct rte_mbuf *mbuf; - struct fw_filter_wr *fwr; + struct fw_filter2_wr *fwr; struct sge_ctrl_txq *ctrlq; unsigned int port_id = ethdev2pinfo(dev)->port_id; int ret; @@ -208,13 +212,16 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx) mbuf->data_len = sizeof(*fwr); mbuf->pkt_len = mbuf->data_len; - fwr = rte_pktmbuf_mtod(mbuf, struct fw_filter_wr *); + fwr = rte_pktmbuf_mtod(mbuf, struct fw_filter2_wr *); memset(fwr, 0, sizeof(*fwr)); /* * Construct the work request to set the filter. */ - fwr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER_WR)); + if (adapter->params.filter2_wr_support) + fwr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER2_WR)); + else + fwr->op_pkd = cpu_to_be32(V_FW_WR_OP(FW_FILTER_WR)); fwr->len16_pkd = cpu_to_be32(V_FW_WR_LEN16(sizeof(*fwr) / 16)); fwr->tid_to_iq = cpu_to_be32(V_FW_FILTER_WR_TID(f->tid) | @@ -224,6 +231,7 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx) fwr->del_filter_to_l2tix = cpu_to_be32(V_FW_FILTER_WR_DROP(f->fs.action == FILTER_DROP) | V_FW_FILTER_WR_DIRSTEER(f->fs.dirsteer) | + V_FW_FILTER_WR_LPBK(f->fs.action == FILTER_SWITCH) | V_FW_FILTER_WR_HITCNTS(f->fs.hitcnts) | V_FW_FILTER_WR_PRIO(f->fs.prio)); fwr->ethtype = cpu_to_be16(f->fs.val.ethtype); @@ -244,6 +252,15 @@ int set_filter_wr(struct rte_eth_dev *dev, unsigned int fidx) fwr->fp = cpu_to_be16(f->fs.val.fport); fwr->fpm = cpu_to_be16(f->fs.mask.fport); + if (adapter->params.filter2_wr_support && f->fs.nat_mode) { + fwr->natmode_to_ulp_type = + V_FW_FILTER2_WR_NATMODE(f->fs.nat_mode); + memcpy(fwr->newlip, f->fs.nat_lip, sizeof(fwr->newlip)); + memcpy(fwr->newfip, f->fs.nat_fip, sizeof(fwr->newfip)); + fwr->newlport = cpu_to_be16(f->fs.nat_lport); + fwr->newfport = cpu_to_be16(f->fs.nat_fport); + } + /* * Mark the filter as "pending" and ship off the Filter Work Request. * When we get the Work Request Reply we'll clear the pending status. diff --git a/drivers/net/cxgbe/cxgbe_filter.h b/drivers/net/cxgbe/cxgbe_filter.h index 4df37b9cd..609751474 100644 --- a/drivers/net/cxgbe/cxgbe_filter.h +++ b/drivers/net/cxgbe/cxgbe_filter.h @@ -97,6 +97,18 @@ struct ch_filter_specification { uint32_t dirsteer:1; /* 0 => RSS, 1 => steer to iq */ uint32_t iq:10; /* ingress queue */ + /* + * Switch proxy/rewrite fields. An ingress packet which matches a + * filter with "switch" set will be looped back out as an egress + * packet -- potentially with some Ethernet header rewriting. + */ + uint32_t nat_mode:3; /* specify NAT operation mode */ + + uint8_t nat_lip[16]; /* local IP to use after NAT'ing */ + uint8_t nat_fip[16]; /* foreign IP to use after NAT'ing */ + uint16_t nat_lport; /* local port to use after NAT'ing */ + uint16_t nat_fport; /* foreign port to use after NAT'ing */ + /* Filter rule value/mask pairs. */ struct ch_filter_tuple val; struct ch_filter_tuple mask; @@ -104,7 +116,19 @@ struct ch_filter_specification { enum { FILTER_PASS = 0, /* default */ - FILTER_DROP + FILTER_DROP, + FILTER_SWITCH, +}; + +enum { + NAT_MODE_NONE = 0, /* No NAT performed */ + NAT_MODE_DIP, /* NAT on Dst IP */ + NAT_MODE_DIP_DP, /* NAT on Dst IP, Dst Port */ + NAT_MODE_DIP_DP_SIP, /* NAT on Dst IP, Dst Port and Src IP */ + NAT_MODE_DIP_DP_SP, /* NAT on Dst IP, Dst Port and Src Port */ + NAT_MODE_SIP_SP, /* NAT on Src IP and Src Port */ + NAT_MODE_DIP_SIP_SP, /* NAT on Dst IP, Src IP and Src Port */ + NAT_MODE_ALL /* NAT on entire 4-tuple */ }; enum filter_type { diff --git a/drivers/net/cxgbe/cxgbe_flow.c b/drivers/net/cxgbe/cxgbe_flow.c index 23b7d00b3..1ef330a0f 100644 --- a/drivers/net/cxgbe/cxgbe_flow.c +++ b/drivers/net/cxgbe/cxgbe_flow.c @@ -249,6 +249,97 @@ static int cxgbe_get_fidx(struct rte_flow *flow, unsigned int *fidx) return 0; } +static int +ch_rte_parse_nat(uint8_t nmode, struct ch_filter_specification *fs) +{ + /* nmode: + * BIT_0 = [src_ip], BIT_1 = [dst_ip] + * BIT_2 = [src_port], BIT_3 = [dst_port] + * + * Only below cases are supported as per our spec. + */ + switch (nmode) { + case 0: /* 0000b */ + fs->nat_mode = NAT_MODE_NONE; + break; + case 2: /* 0010b */ + fs->nat_mode = NAT_MODE_DIP; + break; + case 5: /* 0101b */ + fs->nat_mode = NAT_MODE_SIP_SP; + break; + case 7: /* 0111b */ + fs->nat_mode = NAT_MODE_DIP_SIP_SP; + break; + case 10: /* 1010b */ + fs->nat_mode = NAT_MODE_DIP_DP; + break; + case 11: /* 1011b */ + fs->nat_mode = NAT_MODE_DIP_DP_SIP; + break; + case 14: /* 1110 */ + fs->nat_mode = NAT_MODE_DIP_DP_SP; + break; + case 15: /* 1111b */ + fs->nat_mode = NAT_MODE_ALL; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int +ch_rte_parse_atype_switch(const struct rte_flow_action *a, uint8_t *nmode, + struct ch_filter_specification *fs, + struct rte_flow_error *e) +{ + const struct rte_flow_action_of_set_nw_ipv4 *ipv4; + const struct rte_flow_action_of_set_nw_ipv6 *ipv6; + const struct rte_flow_action_of_set_tp *port; + + switch (a->type) { + case RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV4_SRC: + ipv4 = (const struct rte_flow_action_of_set_nw_ipv4 *)a->conf; + memcpy(fs->nat_fip, &ipv4->ipv4_addr, sizeof(ipv4->ipv4_addr)); + *nmode |= 1 << 0; + break; + case RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV4_DST: + ipv4 = (const struct rte_flow_action_of_set_nw_ipv4 *)a->conf; + memcpy(fs->nat_lip, &ipv4->ipv4_addr, sizeof(ipv4->ipv4_addr)); + *nmode |= 1 << 1; + break; + case RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV6_SRC: + ipv6 = (const struct rte_flow_action_of_set_nw_ipv6 *)a->conf; + memcpy(fs->nat_fip, ipv6->ipv6_addr, sizeof(ipv6->ipv6_addr)); + *nmode |= 1 << 0; + break; + case RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV6_DST: + ipv6 = (const struct rte_flow_action_of_set_nw_ipv6 *)a->conf; + memcpy(fs->nat_lip, ipv6->ipv6_addr, sizeof(ipv6->ipv6_addr)); + *nmode |= 1 << 1; + break; + case RTE_FLOW_ACTION_TYPE_OF_SET_TP_SRC: + port = (const struct rte_flow_action_of_set_tp *)a->conf; + fs->nat_fport = be16_to_cpu(port->port); + *nmode |= 1 << 2; + break; + case RTE_FLOW_ACTION_TYPE_OF_SET_TP_DST: + port = (const struct rte_flow_action_of_set_tp *)a->conf; + fs->nat_lport = be16_to_cpu(port->port); + *nmode |= 1 << 3; + break; + default: + /* We are not supposed to come here */ + return rte_flow_error_set(e, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, a, + "Action not supported"); + } + + return 0; +} + static int cxgbe_rtef_parse_actions(struct rte_flow *flow, const struct rte_flow_action action[], @@ -257,6 +348,8 @@ cxgbe_rtef_parse_actions(struct rte_flow *flow, struct ch_filter_specification *fs = &flow->fs; const struct rte_flow_action_queue *q; const struct rte_flow_action *a; + int ret; + uint8_t nmode = 0, nat_ipv4 = 0, nat_ipv6 = 0; char abit = 0; for (a = action; a->type != RTE_FLOW_ACTION_TYPE_END; a++) { @@ -291,6 +384,36 @@ cxgbe_rtef_parse_actions(struct rte_flow *flow, case RTE_FLOW_ACTION_TYPE_COUNT: fs->hitcnts = 1; break; + + /* switch actions */ + case RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV4_SRC: + case RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV4_DST: + nat_ipv4++; + goto action_switch; + case RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV6_SRC: + case RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV6_DST: + nat_ipv6++; + case RTE_FLOW_ACTION_TYPE_OF_SET_TP_SRC: + case RTE_FLOW_ACTION_TYPE_OF_SET_TP_DST: +action_switch: + /* We allow multiple switch actions, but switch is + * not compatible with either queue or drop + */ + if (abit++ && fs->action != FILTER_SWITCH) + return rte_flow_error_set(e, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, a, + "overlapping action specified"); + if (nat_ipv4 && nat_ipv6) + return rte_flow_error_set(e, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, a, + "Can't have one address ipv4 and the" + " other ipv6"); + + ret = ch_rte_parse_atype_switch(a, &nmode, fs, e); + if (ret) + return ret; + fs->action = FILTER_SWITCH; + break; default: /* Not supported action : return error */ return rte_flow_error_set(e, ENOTSUP, @@ -299,6 +422,10 @@ cxgbe_rtef_parse_actions(struct rte_flow *flow, } } + if (ch_rte_parse_nat(nmode, fs)) + return rte_flow_error_set(e, EINVAL, + RTE_FLOW_ERROR_TYPE_ACTION, a, + "invalid settings for swich action"); return 0; } diff --git a/drivers/net/cxgbe/cxgbe_main.c b/drivers/net/cxgbe/cxgbe_main.c index 21ad380ae..50d93e7da 100644 --- a/drivers/net/cxgbe/cxgbe_main.c +++ b/drivers/net/cxgbe/cxgbe_main.c @@ -990,6 +990,16 @@ static int adap_init0(struct adapter *adap) if (ret < 0) goto bye; + /* See if FW supports FW_FILTER2 work request */ + if (is_t4(adap->params.chip)) { + adap->params.filter2_wr_support = 0; + } else { + params[0] = FW_PARAM_DEV(FILTER2_WR); + ret = t4_query_params(adap, adap->mbox, adap->pf, 0, + 1, params, val); + adap->params.filter2_wr_support = (ret == 0 && val[0] != 0); + } + /* query tid-related parameters */ params[0] = FW_PARAM_DEV(NTID); ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,