From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 963D9A0487 for ; Mon, 1 Jul 2019 12:54:33 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6483C2C38; Mon, 1 Jul 2019 12:54:32 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id D2883235 for ; Mon, 1 Jul 2019 12:54:27 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Jul 2019 03:40:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,439,1557212400"; d="scan'208";a="184224572" Received: from irsmsx152.ger.corp.intel.com ([163.33.192.66]) by fmsmga001.fm.intel.com with ESMTP; 01 Jul 2019 03:40:36 -0700 Received: from irsmsx156.ger.corp.intel.com (10.108.20.68) by IRSMSX152.ger.corp.intel.com (163.33.192.66) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 1 Jul 2019 11:40:35 +0100 Received: from irsmsx104.ger.corp.intel.com ([169.254.5.143]) by IRSMSX156.ger.corp.intel.com ([169.254.3.131]) with mapi id 14.03.0439.000; Mon, 1 Jul 2019 11:40:35 +0100 From: "Ananyev, Konstantin" To: "Zhang, Roy Fan" , "dev@dpdk.org" CC: "akhil.goyal@nxp.com" , "Kovacevic, Marko" Thread-Topic: [PATCH v5 1/2] lib/ipsec: add support for header construction Thread-Index: AQHVLbVoqSt81wYAGUW4np50LpjGP6a1lS1Q Date: Mon, 1 Jul 2019 10:40:34 +0000 Message-ID: <2601191342CEEE43887BDE71AB97725801689E8107@IRSMSX104.ger.corp.intel.com> References: <20190628123926.15762-1-roy.fan.zhang@intel.com> <20190628132245.86158-1-roy.fan.zhang@intel.com> <20190628132245.86158-2-roy.fan.zhang@intel.com> In-Reply-To: <20190628132245.86158-2-roy.fan.zhang@intel.com> Accept-Language: en-IE, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNzQ2MGVhZjQtZWNhZC00NGExLWIxMzEtNjFhNTU5MjJkYmQzIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoielAwbTJGc0RvdkdzQjJFR2xWeHUwSjlVRlR3VnhpRlZrUWZTVFhIZEEybUhhZFJ6Z0ZtRW81MVdubTNpcWtsRSJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.2.0.6 dlp-reaction: no-action x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v5 1/2] lib/ipsec: add support for header construction 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" Hi Fan, > From: Zhang, Roy Fan > Sent: Friday, June 28, 2019 2:23 PM > To: dev@dpdk.org > Cc: akhil.goyal@nxp.com; Ananyev, Konstantin ; Zhang, Roy Fan ; Kovacevic, > Marko > Subject: [PATCH v5 1/2] lib/ipsec: add support for header construction >=20 > Add support for RFC 4301(5.1.2) to update of > Type of service field and Traffic class field > bits inside ipv4/ipv6 packets for outbound cases > and inbound cases which deals with the update of > the DSCP/ENC bits inside each of the fields. Two minor nits below. Apart from that: Acked-by: Konstantin Ananyev Tested-by: Konstantin Ananyev >=20 > Signed-off-by: Marko Kovacevic > Signed-off-by: Fan Zhang > --- > diff --git a/lib/librte_ipsec/iph.h b/lib/librte_ipsec/iph.h > index 62d78b7b1..dcf26df1d 100644 > --- a/lib/librte_ipsec/iph.h > +++ b/lib/librte_ipsec/iph.h > @@ -101,23 +101,154 @@ update_trs_l3hdr(const struct rte_ipsec_sa *sa, vo= id *p, uint32_t plen, > return rc; > } >=20 > +/* > + * The masks for ipv6 header reconstruction (RFC4301) > + */ > +#define IPV6_DSCP_MASK (RTE_IP_DSCP_MASK << RTE_IPV6_HDR_TC_SHIFT) > +#define IPV6_ECN_MASK (RTE_IP_ECN_MASK << RTE_IPV6_HDR_TC_SHIFT) > +#define IPV6_TOS_MASK (IPV6_ECN_MASK | IPV6_DSCP_MASK) > +#define IPV6_ECN_CE IPV6_ECN_MASK > + > +/* > + * The macros to get and set traffic class (TC) for ipv6 packets > + */ > +#define GET_IPV6_TC(vtc_flow) \ > + (uint32_t)((rte_be_to_cpu_32(vtc_flow)) >> RTE_IPV6_HDR_TC_SHIFT) > + > +#define SET_IPV6_TC(vtc_flow, tc) \ > + (vtc_flow =3D rte_cpu_to_be_32(tc << RTE_IPV6_HDR_TC_SHIFT) | \ > + (vtc_flow & (~rte_cpu_to_be_32(IPV6_TOS_MASK)))) > + For macros we need all its parameter references to be in (). i.e. (vtc_flow) =3D rte_cpu_to_be_32((tc) << ... Though I think inline function would suit better (as you have in previous p= atch version). > +/** > + * Update type-of-service/traffic-class field of inbound/outbound tunnel > + * packet. > + * > + * @param ref_h: reference header, for outbound it is inner header, othe= rwise > + * outer header. > + * @param update_h: header to be updated tos/tc field, for outbound it i= s outer > + * header, otherwise inner header. > + * @param tos_mask: type-of-service mask stored in sa. > + * @param is_outh_ipv4: 1 if outer header is ipv4, 0 if it is ipv6. > + * @param is_inner_ipv4: 1 if inner header is ipv4, 0 if it is ipv6. > + * @param is_inbound: 1 if it is a inbound packet, 0 if it is outbound. > + */ > +static inline void > +update_tun_tos(const void *ref_h, void *update_h, uint32_t tos_mask, > + uint8_t is_outh_ipv4, uint8_t is_inh_ipv4, uint8_t is_inbound) > +{ > + uint8_t idx =3D ((is_inbound << 2) | (is_outh_ipv4 << 1) | is_inh_ipv4)= ; > + struct rte_ipv4_hdr *v4out_h; > + struct rte_ipv6_hdr *v6out_h; > + struct rte_ipv4_hdr *v4in_h; > + struct rte_ipv6_hdr *v6in_h; > + uint32_t itp, otp; > + uint8_t ecn_v4out, ecn_v4in; > + uint32_t ecn_v6out, ecn_v6in; > + > + switch (idx) { > + /* outbound */ > + case 0: /*outh ipv6, inh ipv6 */ > + v6out_h =3D update_h; > + otp =3D GET_IPV6_TC(v6out_h->vtc_flow) & ~tos_mask; > + itp =3D GET_IPV6_TC(((const struct rte_ipv6_hdr *)ref_h)-> > + vtc_flow) & tos_mask; > + SET_IPV6_TC(v6out_h->vtc_flow, (otp | itp)); > + break; > + case 1: /*outh ipv6, inh ipv4 */ > + v6out_h =3D update_h; > + otp =3D GET_IPV6_TC(v6out_h->vtc_flow) & ~tos_mask; > + itp =3D ((const struct rte_ipv4_hdr *)ref_h)->type_of_service & > + tos_mask; > + SET_IPV6_TC(v6out_h->vtc_flow, (otp | itp)); > + break; > + case 2: /*outh ipv4, inh ipv6 */ > + v4out_h =3D update_h; > + otp =3D v4out_h->type_of_service & ~tos_mask; > + itp =3D GET_IPV6_TC(((const struct rte_ipv6_hdr *)ref_h)-> > + vtc_flow) & tos_mask; > + v4out_h->type_of_service =3D (otp | itp); > + break; > + case 3: /* outh ipv4, inh ipv4 */ > + v4out_h =3D update_h; > + otp =3D v4out_h->type_of_service & ~tos_mask; > + itp =3D ((const struct rte_ipv4_hdr *)ref_h)->type_of_service & > + tos_mask; > + v4out_h->type_of_service =3D (otp | itp); > + break; Looking at the function - it might be better to split it into 2 separate fu= nctions: one for inbound, another for outbound. Then you'll have identical cases (0-3) for both, and that would probably be= easier to follow. Again in that case you wouldn't need to: uint8_t idx =3D ((is_inbound << 2) |... > + /* inbound */ > + case 4: /* outh ipv6, inh ipv6 */ > + v6in_h =3D update_h; > + ecn_v6out =3D ((const struct rte_ipv6_hdr *)ref_h)->vtc_flow & > + rte_cpu_to_be_32(IPV6_ECN_MASK); > + ecn_v6in =3D v6in_h->vtc_flow & rte_cpu_to_be_32(IPV6_ECN_MASK); > + if ((ecn_v6out =3D=3D rte_cpu_to_be_32(IPV6_ECN_CE)) && > + (ecn_v6in !=3D 0)) > + v6in_h->vtc_flow |=3D rte_cpu_to_be_32(IPV6_ECN_CE); > + break; > + case 5: /* outh ipv6, inh ipv4 */ > + v4in_h =3D update_h; > + ecn_v6out =3D ((const struct rte_ipv6_hdr *)ref_h)->vtc_flow & > + rte_cpu_to_be_32(IPV6_ECN_MASK); > + ecn_v4in =3D v4in_h->type_of_service & RTE_IP_ECN_MASK; > + if ((ecn_v6out =3D=3D rte_cpu_to_be_32(IPV6_ECN_CE)) && > + (ecn_v4in !=3D 0)) > + v4in_h->type_of_service |=3D RTE_IP_ECN_CE; > + break; > + case 6: /* outh ipv4, inh ipv6 */ > + v6in_h =3D update_h; > + ecn_v4out =3D ((const struct rte_ipv4_hdr *)ref_h)-> > + type_of_service & RTE_IP_ECN_MASK; > + ecn_v6in =3D v6in_h->vtc_flow & rte_cpu_to_be_32(IPV6_ECN_MASK); > + if (ecn_v4out =3D=3D RTE_IP_ECN_CE && ecn_v6in !=3D 0) > + v6in_h->vtc_flow |=3D rte_cpu_to_be_32(IPV6_ECN_CE); > + break; > + case 7: /* outh ipv4, inh ipv4 */ > + v4in_h =3D update_h; > + ecn_v4out =3D ((const struct rte_ipv4_hdr *)ref_h)-> > + type_of_service & RTE_IP_ECN_MASK; > + ecn_v4in =3D v4in_h->type_of_service & RTE_IP_ECN_MASK; > + if (ecn_v4out =3D=3D RTE_IP_ECN_CE && ecn_v4in !=3D 0) > + v4in_h->type_of_service |=3D RTE_IP_ECN_CE; > + break; > + } > +} > +