From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 922D0A0C4B; Fri, 15 Oct 2021 11:58:52 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7C6E4411F6; Fri, 15 Oct 2021 11:58:52 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id B3DC640692 for ; Fri, 15 Oct 2021 11:58:50 +0200 (CEST) X-IronPort-AV: E=McAfee;i="6200,9189,10137"; a="208000580" X-IronPort-AV: E=Sophos;i="5.85,375,1624345200"; d="scan'208";a="208000580" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2021 02:58:49 -0700 X-IronPort-AV: E=Sophos;i="5.85,375,1624345200"; d="scan'208";a="492394808" Received: from dpdk.cd.intel.com ([10.240.178.133]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2021 02:58:45 -0700 From: Jie Wang To: dev@dpdk.org Cc: orika@nvidia.com, ferruh.yigit@intel.com, thomas@monjalon.net, andrew.rybchenko@oktetlabs.ru, xiaoyun.li@intel.com, stevex.yang@intel.com, jingjing.wu@intel.com, beilei.xing@intel.com, wenjun1.wu@intel.com, Jie Wang Date: Fri, 15 Oct 2021 17:58:21 +0800 Message-Id: <20211015095823.701188-2-jie1x.wang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211015095823.701188-1-jie1x.wang@intel.com> References: <20211012102508.275790-1-jie1x.wang@intel.com> <20211015095823.701188-1-jie1x.wang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v3 1/3] ethdev: support PPP and L2TPV2 procotol X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Added flow pattern items and header formats of L2TPv2 and PPP to support PPP over L2TPv2 over UDP protocol RSS Hash. Signed-off-by: Wenjun Wu Signed-off-by: Jie Wang --- doc/guides/prog_guide/rte_flow.rst | 25 +++ doc/guides/rel_notes/release_21_11.rst | 5 + lib/ethdev/rte_flow.c | 2 + lib/ethdev/rte_flow.h | 117 ++++++++++++++ lib/net/rte_l2tpv2.h | 214 +++++++++++++++++++++++++ 5 files changed, 363 insertions(+) create mode 100644 lib/net/rte_l2tpv2.h diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst index 3cb014c1fa..59fe7e79b5 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -1425,6 +1425,31 @@ Matches a conntrack state after conntrack action. - ``flags``: conntrack packet state flags. - Default ``mask`` matches all state bits. +Item: ``L2TPV2`` +^^^^^^^^^^^^^^^^^^^ + +Matches a L2TPv2 header. + +- ``flags_version``: flags(12b), version(4b). +- ``length``: total length of the message. +- ``tunnel_id``: identifier for the control connection. +- ``session_id``: identifier for a session within a tunnel. +- ``ns``: sequence number for this date or control message. +- ``nr``: sequence number expected in the next control message to be received. +- ``offset_size``: offset of payload data. +- ``offset_padding``: offset padding, variable length. +- Default ``mask`` matches flags_version only. + +Item: ``PPP`` +^^^^^^^^^^^^^^^^^^^ + +Matches a PPP header. + +- ``addr``: ppp address. +- ``ctrl``: ppp control. +- ``proto_id``: ppp protocol identifier. +- Default ``mask`` matches addr, ctrl, proto_id. + Actions ~~~~~~~ diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index d5c762df62..503f6dd828 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -81,6 +81,11 @@ New Features * Default VLAN strip behavior was changed. VLAN tag won't be stripped unless ``DEV_RX_OFFLOAD_VLAN_STRIP`` offload is enabled. +* **Added L2TPV2 and PPP protocol support in rte_flow.** + + Added flow pattern items and header formats of L2TPv2 and PPP to support + PPP over L2TPv2 over UDP protocol RSS Hash. + * **Updated AF_XDP PMD.** * Disabled secondary process support. diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index 8cb7a069c8..1ec739a031 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -100,6 +100,8 @@ static const struct rte_flow_desc_data rte_flow_desc_item[] = { MK_FLOW_ITEM(GENEVE_OPT, sizeof(struct rte_flow_item_geneve_opt)), MK_FLOW_ITEM(INTEGRITY, sizeof(struct rte_flow_item_integrity)), MK_FLOW_ITEM(CONNTRACK, sizeof(uint32_t)), + MK_FLOW_ITEM(L2TPV2, sizeof(struct rte_flow_item_l2tpv2)), + MK_FLOW_ITEM(PPP, sizeof(struct rte_flow_item_ppp)), }; /** Generate flow_action[] entry. */ diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h index 5f87851f8c..f8fcf9c1f8 100644 --- a/lib/ethdev/rte_flow.h +++ b/lib/ethdev/rte_flow.h @@ -35,6 +35,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -574,6 +575,21 @@ enum rte_flow_item_type { * @see struct rte_flow_item_conntrack. */ RTE_FLOW_ITEM_TYPE_CONNTRACK, + + /** + * Matches L2TPV2 Header. + * + * See struct rte_flow_item_l2tpv2. + */ + RTE_FLOW_ITEM_TYPE_L2TPV2, + + /** + * Matches PPP Header. + * + * See struct rte_flow_item_ppp. + */ + RTE_FLOW_ITEM_TYPE_PPP, + }; /** @@ -1799,6 +1815,55 @@ static const struct rte_flow_item_conntrack rte_flow_item_conntrack_mask = { }; #endif +/** + * @warning + * @b EXPERIMENTAL: this structure may change without prior notice + * RTE_FLOW_ITEM_TYPE_L2TPV2 + * + * Matches L2TPv2 Header + */ +struct rte_flow_item_l2tpv2 { + struct rte_l2tpv2_combined_msg_hdr hdr; +}; + +/** Default mask for RTE_FLOW_ITEM_TYPE_L2TPV2. */ +#ifndef __cplusplus +static const struct rte_flow_item_l2tpv2 rte_flow_item_l2tpv2_mask = { + /* + * flags and version bit mask + * 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 + * T L x x S x O P x x x x V V V V + */ + .hdr = { + .common = { + .flags_version = 0xcb0f, + }, + }, +}; +#endif + +/** + * @warning + * @b EXPERIMENTAL: this structure may change without prior notice + * RTE_FLOW_ITEM_TYPE_PPP + * + * Matches PPP Header + */ +struct rte_flow_item_ppp { + uint8_t addr; /**< ppp address(8) */ + uint8_t ctrl; /**< ppp control(8) */ + rte_be16_t proto_id; /**< ppp protocol id(16) */ +}; + +/** Default mask for RTE_FLOW_ITEM_TYPE_PPP. */ +#ifndef __cplusplus +static const struct rte_flow_item_ppp rte_flow_item_ppp_mask = { + .addr = 0xff, + .ctrl = 0xff, + .proto_id = 0xffff, +}; +#endif + /** * Matching pattern item definition. * @@ -2417,6 +2482,23 @@ enum rte_flow_action_type { * See struct rte_flow_action_meter_color. */ RTE_FLOW_ACTION_TYPE_METER_COLOR, + + /** + * Encapsulate flow in L2TPV2 tunnel defined in the + * rte_flow_action_l2tpv2_encap action structure. + * + * See struct rte_flow_action_l2tpv2_encap. + */ + RTE_FLOW_ACTION_TYPE_L2TPV2_ENCAP, + + /** + * Decapsulate outer most L2TPV2 tunnel from matched flow. + * + * If flow pattern does not define a valid L2TPV2 tunnel (as specified + * by RFC2661) then the PMD should return a RTE_FLOW_ERROR_TYPE_ACTION + * error. + */ + RTE_FLOW_ACTION_TYPE_L2TPV2_DECAP, }; /** @@ -3162,6 +3244,41 @@ struct rte_flow_action_meter_color { enum rte_color color; /**< Packet color. */ }; +/** + * @warning + * @b EXPERIMENTAL: this structure may change without prior notice + * + * RTE_FLOW_ACTION_TYPE_L2TPV2_ENCAP + * + * L2TPV2 tunnel end-point encapsulation data definition + * + * The tunnel definition is provided through the flow item pattern the + * provided pattern must conform with RFC7637. The flow definition must be + * provided in order from the RTE_FLOW_ITEM_TYPE_ETH definition up the end item + * which is specified by RTE_FLOW_ITEM_TYPE_END. + * + * The mask field allows user to specify which fields in the flow item + * definitions can be ignored and which have valid data and can be used + * verbatim. + * + * Note: the last field is not used in the definition of a tunnel and can be + * ignored. + * + * Valid flow definition for RTE_FLOW_ACTION_TYPE_L2TPV2_ENCAP include: + * + * - ETH / IPV4 / UDP / L2TPV2 / END + * - ETH / IPV6 / UDP / L2TPV2 / END + * - ETH / VLAN / IPV4 / UDP / L2TPV2 / END + * + */ +struct rte_flow_action_l2tpv2_encap { + /** + * Encapsulating l2tpv2 tunnel definition + * (terminated by the END pattern item). + */ + struct rte_flow_item *definition; +}; + /** * Field IDs for MODIFY_FIELD action. */ diff --git a/lib/net/rte_l2tpv2.h b/lib/net/rte_l2tpv2.h new file mode 100644 index 0000000000..aea3c689be --- /dev/null +++ b/lib/net/rte_l2tpv2.h @@ -0,0 +1,214 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2021 Mellanox Technologies, Ltd + */ + +#ifndef _RTE_L2TPV2_H_ +#define _RTE_L2TPV2_H_ + +/** + * @file + * + * L2TP header: + * 0 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * |T|L|x|x|S|x|O|P|x|x|x|x| Ver | Length (opt) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Tunnel ID | Session ID | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Ns (opt) | Nr (opt) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Offset Size (opt) | Offset pad... (opt) + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * + * The Type (T) bit indicates the type of message. It is set to 0 for a data + * message and 1 for a control message. + * + * If the Length (L) bit is 1, the Length field is present. This bit MUST be + * set to 1 for control messages. + * + * The x bits are reserved for future extensions. All reserved bits MUST + * be set to 0 on outgoing messages and ignored on incoming messages. + * + * If the Sequence (S) bit is set to 1 the Ns and Nr fields are present. + * The S bit MUST be set to 1 for control messages. + * + * If the Offset (O) bit is 1, the Offset Size field is present. The O + * bit MUST be set to 0 for control messages. + * + * If the Priority (P) bit is 1, this data message should receive + * preferential treatment in its local queuing and transmission. + * The P bit MUST be set to 0 for control messages. + * + * Ver MUST be 2, indicating the version of the L2TP data message header. + * + * The Length field indicates the total length of the message in octets. + * + * Tunnel ID indicates the identifier for the control connection. + * + * Session ID indicates the identifier for a session within a tunnel. + * + * Ns indicates the sequence number for this data or control message. + * + * Nr indicates the sequence number expected in the next control message + * to be received. + * + * The Offset Size field, if present, specifies the number of octets + * past the L2TP header at which the payload data is expected to start. + * Actual data within the offset padding is undefined. If the offset + * field is present, the L2TP header ends after the last octet of the + * offset padding. + */ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * L2TPv2 Common Header + */ +RTE_STD_C11 +struct rte_l2tpv2_common_hdr { + union { + rte_be16_t flags_version; + struct { +#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN + rte_be16_t t:1; /**< message Type */ + rte_be16_t l:1; /**< length option bit*/ + rte_be16_t res1:2; /**< reserved */ + rte_be16_t s:1; /**< ns/nr option bit*/ + rte_be16_t res2:1; /**< reserved */ + rte_be16_t o:1; /**< offset option bit*/ + rte_be16_t p:1; /**< priority option bit*/ + rte_be16_t res3:4; /**< reserved */ + rte_be16_t ver:4; /**< protocol version */ +#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN + rte_be16_t ver:4; /**< protocol version */ + rte_be16_t res3:4; /**< reserved */ + rte_be16_t p:1; /**< priority option bit*/ + rte_be16_t o:1; /**< offset option bit*/ + rte_be16_t res2:1; /**< reserved */ + rte_be16_t s:1; /**< ns/nr option bit*/ + rte_be16_t res1:2; /**< reserved */ + rte_be16_t l:1; /**< length option bit*/ + rte_be16_t t:1; /**< message Type */ +#endif + }; + }; +}; + +/* + * L2TPv2 message Header contains all options(length, ns, nr, + * offset size, offset padding). + */ +struct rte_l2tpv2_msg_with_all_options { + rte_be16_t length; /**< length(16) */ + rte_be16_t tunnel_id; /**< tunnel id(16) */ + rte_be16_t session_id; /**< session id(16) */ + rte_be16_t ns; /**< Ns(16) */ + rte_be16_t nr; /**< Nr(16) */ + rte_be16_t offset_size; /**< offset size(16) */ + uint8_t *offset_padding; /**< offset padding(variable length) */ +}; + +/* + * L2TPv2 message Header contains all options except length(ns, nr, + * offset size, offset padding). + */ +struct rte_l2tpv2_msg_without_length { + rte_be16_t tunnel_id; /**< tunnel id(16) */ + rte_be16_t session_id; /**< session id(16) */ + rte_be16_t ns; /**< Ns(16) */ + rte_be16_t nr; /**< Nr(16) */ + rte_be16_t offset_size; /**< offset size(16) */ + uint8_t *offset_padding; /**< offset padding(variable length) */ +}; + +/* + * L2TPv2 message Header contains all options except ns_nr(length, + * offset size, offset padding). + * Ns and Nr MUST be toghter. + */ +struct rte_l2tpv2_msg_without_ns_nr { + rte_be16_t length; /**< length(16) */ + rte_be16_t tunnel_id; /**< tunnel id(16) */ + rte_be16_t session_id; /**< session id(16) */ + rte_be16_t offset_size; /**< offset size(16) */ + uint8_t *offset_padding; /**< offset padding(variable length) */ +}; + +/* + * L2TPv2 message Header contains all options except ns_nr(length, ns, nr). + * offset size and offset padding MUST be toghter. + */ +struct rte_l2tpv2_msg_without_offset { + rte_be16_t length; /**< length(16) */ + rte_be16_t tunnel_id; /**< tunnel id(16) */ + rte_be16_t session_id; /**< session id(16) */ + rte_be16_t ns; /**< Ns(16) */ + rte_be16_t nr; /**< Nr(16) */ +}; + +/* + * L2TPv2 message Header contains options offset size and offset padding. + */ +struct rte_l2tpv2_msg_with_offset { + rte_be16_t tunnel_id; /**< tunnel id(16) */ + rte_be16_t session_id; /**< session id(16) */ + rte_be16_t offset_size; /**< offset size(16) */ + uint8_t *offset_padding; /**< offset padding(variable length) */ +}; + +/* + * L2TPv2 message Header contains options ns and nr. + */ +struct rte_l2tpv2_msg_with_ns_nr { + rte_be16_t tunnel_id; /**< tunnel id(16) */ + rte_be16_t session_id; /**< session id(16) */ + rte_be16_t ns; /**< Ns(16) */ + rte_be16_t nr; /**< Nr(16) */ +}; + +/* + * L2TPv2 message Header contains option length. + */ +struct rte_l2tpv2_msg_with_length { + rte_be16_t length; /**< length(16) */ + rte_be16_t tunnel_id; /**< tunnel id(16) */ + rte_be16_t session_id; /**< session id(16) */ +}; + +/* + * L2TPv2 message Header without all options. + */ +struct rte_l2tpv2_msg_without_all_options { + rte_be16_t tunnel_id; /**< tunnel id(16) */ + rte_be16_t session_id; /**< session id(16) */ +}; + +/** + * L2TPv2 Combined Message Header Format: Common Header + Options + */ +RTE_STD_C11 +struct rte_l2tpv2_combined_msg_hdr { + struct rte_l2tpv2_common_hdr common; + union { + struct rte_l2tpv2_msg_with_all_options type0; + struct rte_l2tpv2_msg_without_length type1; + struct rte_l2tpv2_msg_without_ns_nr type2; + struct rte_l2tpv2_msg_without_offset type3; + struct rte_l2tpv2_msg_with_offset type4; + struct rte_l2tpv2_msg_with_ns_nr type5; + struct rte_l2tpv2_msg_with_length type6; + struct rte_l2tpv2_msg_without_all_options type7; + }; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_L2TPV2_H_ */ -- 2.25.1