From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0042.outbound.protection.outlook.com [104.47.36.42]) by dpdk.org (Postfix) with ESMTP id 1368F199B3 for ; Mon, 11 Dec 2017 16:36:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=uwIOvXnhQJh1+1KWOdCqBn8MZQFJ4CJiJ0Sru17y2u0=; b=QNqJTkvIyR4NwNREU95YTtmEeRwbDjsL4uuKUh+r4Xy/fVG5n2vfa5IeKc1SsdvbQo5lfrI1JqNhJ+TgJKSxZHq98gwDdsPg7RJKEJr/IDlF2SHhXMnsSEPL7m2zpvmJvMKYUaCmnXuf5UjmZKzi6nJUL54obWWrPvjXuP9Qo9Q= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Anoob.Joseph@cavium.com; Received: from ajoseph83.caveonetworks.com (115.113.156.2) by CY4PR0701MB3634.namprd07.prod.outlook.com (2603:10b6:910:92::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.302.9; Mon, 11 Dec 2017 15:36:44 +0000 From: Anoob Joseph To: Akhil Goyal , Declan Doherty , Sergio Gonzalez Monroy , Radu Nicolau Cc: Anoob Joseph , Narayana Prasad , Jerin Jacob , dev@dpdk.org Date: Mon, 11 Dec 2017 15:35:57 +0000 Message-Id: <1513006557-14898-1-git-send-email-anoob.joseph@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510738915-14712-1-git-send-email-anoob.joseph@caviumnetworks.com> References: <1510738915-14712-1-git-send-email-anoob.joseph@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [115.113.156.2] X-ClientProxiedBy: YQBPR0101CA0040.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c00:1::17) To CY4PR0701MB3634.namprd07.prod.outlook.com (2603:10b6:910:92::36) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 91e74e72-55b2-4dde-70a4-08d540acfda9 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(2017052603307); SRVR:CY4PR0701MB3634; X-Microsoft-Exchange-Diagnostics: 1; CY4PR0701MB3634; 3:V8FgMKC+o9zh1CkPwItHZqL92JCN2AJzQok3PLjuDZP5DWgViO6lNXkSWuQHdlPR408ZAfgfZ44Diyy5N4sxdkIyTfiGlqI2WeFC1Rd++h9OfcSvPRKnotr0ijQsJPKDJB9Gvc9ZkTpO7wR+QSrSnr8o5gRxbyF8Dtdg6SW0zT64Bqc9ARMYA6LDr2ohB/4uupEMydkO0CYqj+UtndnAxCC7wJ1tiNnK6z1iwjFAGKGC4VgbtRQF0S3DIjdOL330; 25:IvYJlDtMaZi2T/QWhVDPT2eVx9yQ863+DaSSZcG3ZzBC3xaybbOm5ShpA5Nr1Tz7mwCcSKdDRzVHNiGyKmU1REBZ/vWxvD9dQ76e/PePtWPu3ekorpJoAyM3s1o8H7RBmsJrWrmRmQHYGjIunWlAneq20/Gtyao3TINIMLH570DxrOZwSuzshVYD556gMed+iBSKQxBEk5swr5b1g68wboY7sfc6UndFp7xV/vQ1gHFGeDzvsGhv0M8TJUVRrFK10rr70YgECiPChKHb1HbW36E5fRAYRdRuvBvvpPNFz+zF+qKF+Wz/Y7LZ2DCgJfQjVucGFIlAiXlo8kYqIyDoAw==; 31:maKctgTLwG67nnQ3zahHfYKK71fGeLV5vFHCqyTR/aAy5kVh16ZFYJaYEEeQpG+iam/dPYfREnIS1jwdspHQOsaxUeqR3l5kPRy5JeEFaFwe/mm+S7a4fLAHMwyh5cXsYMAYnrGsoZbzzuTyWVS/YfJG19ZCz3BZOtYJK1aZEqkXpM+FeGaJi10uNXxfygBcBYMEs+dBJd0nbpZ7CnPOIHlN4Rd35M9ccrVX+WKB6RQ= X-MS-TrafficTypeDiagnostic: CY4PR0701MB3634: X-Microsoft-Exchange-Diagnostics: 1; CY4PR0701MB3634; 20:vpRl2u9U3VD3ZMlbp4UZkaMnWPYIjV2x1PtzmnjdWnx55+n1HQq6Hg8UMehwl+AQAEWLihPDEYMWujXf/FHHymDh3u7SB2O08GujeYw2sBKm1M/Rd0UtjURoJVKtzpOMYdKog012v2tS79B8qoTqhjHwbcImtEDArDIj9D1BOc5SFHVKkYU+Uu/wWpQc4rxlxvlX2KlMlMYjxU+qUi+CN/9FKXKcdRLs9/593WgbQby8ZYMs01S64X79iEBjmdpI3bOFzYQ078BfC+srZJgUYubPB1Cij3D+fjWsD1HqzjkQDp0JiS2oNq+aQK20sIFhKKUaoEakfBoaef3HmE9p/Pes+085Y7tqqZKpbIk2MKptzkBwHJAip8MABC1wreImo0+fBb+2pPZGVLhw5TKjQekms3mp25a0rcOzyNJlQznz3SO4yZjaKNpK+3fPdTuvEM7jhDIv5ZxeZMhng5cBOezg0gR73YhTWB0qe2Cf9QPE5wCXkSHNaUlPA32KRpVchSnUD6RvA/mJ4Ps7iqiR4a7m5cYmrINmfomKRLk5uHj9QA/gPVsCoEpZlc3dBue0+y4U8SiAFvKG4aWJLZEX3hDyJR2UraPr/MytfZ2wyLA=; 4:AIaYxus0S0lws4L4gL4/LdgRLgudDhJhpkObC6WWUXelkueh3PBQB2HxlaXYDcX7t14QH2RHvX29mee0zPVJflc9HvrrXMzp0v4PPIk4COK2e81QjxjVzx85Rg6UenUUqGKAa9OznXNzxx62cGQ3Y0wWXGa6hM6CMVhPGdrfCv1+XBTmTHv8gY5GKgVTODUeNeWt3wOfm41iefncLhphQe0i0MRF+1QLg+udheiYrTd1zQLbPECAKoEBL2wL1sgKWKOGFK1CeJBy35We8MxN0wS2Rs92KNOJeP5nXWeTDfR54K5evDJkUcVTRQhZOC90 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192374486261705); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(3231022)(93006095)(10201501046)(3002001)(6041248)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(20161123560025)(20161123555025)(20161123558100)(6072148)(201708071742011); SRVR:CY4PR0701MB3634; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY4PR0701MB3634; X-Forefront-PRVS: 0518EEFB48 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(366004)(346002)(189003)(199004)(2950100002)(25786009)(66066001)(16586007)(53936002)(59450400001)(6506006)(316002)(305945005)(2906002)(6512007)(76176011)(8656006)(8676002)(81156014)(81166006)(4326008)(16526018)(97736004)(52116002)(50466002)(51416003)(575784001)(6486002)(7736002)(69596002)(5660300001)(3846002)(106356001)(68736007)(53416004)(6116002)(50226002)(8936002)(42882006)(47776003)(48376002)(105586002)(6666003)(55236003)(110136005)(54906003)(36756003)(72206003)(478600001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR0701MB3634; H:ajoseph83.caveonetworks.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY4PR0701MB3634; 23:aopdjglG2fgEkzBGRdqZeYRVlf3fiR5d3//syB+?= =?us-ascii?Q?xbesnw6tH+eRl7jimtZkJ0AcrjJEBEyvi3YgQ9+rNqcxGK4RQqTV8s8r5Glq?= =?us-ascii?Q?j5igQia8J6ty/KJrL3v7R4DVZSP7xb8/1c4M0WuBQPTPIDTlAdnYGo5xgit5?= =?us-ascii?Q?9+Pdjfww8Qt6Ye5jr9pJBFGp8iuyU6IXqi0HPZDFmSK7ZrvcHHcW30QSqkpI?= =?us-ascii?Q?rqufLl20cYLK3X5e/CQIF0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X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Dec 2017 15:36:44.9116 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 91e74e72-55b2-4dde-70a4-08d540acfda9 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR0701MB3634 Subject: [dpdk-dev] [PATCH v4] examples/ipsec-secgw: fix usage of incorrect port 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: , X-List-Received-Date: Mon, 11 Dec 2017 15:36:50 -0000 When security offload is enabled, the packet should be forwarded on the port configured in the SA. Security session will be configured on that port only, and sending the packet on other ports could result in unencrypted packets being sent out. This would have performance improvements too, as the per packet LPM lookup would be avoided for IPsec packets, in inline mode. Fixes: ec17993a145a ("examples/ipsec-secgw: support security offload") Signed-off-by: Anoob Joseph --- v4 * Made get_hop_for_offload_pkt() be aware of the packet type (ipv4/ipv6) and return success/error values accordingly v3 * Bug fix (fixed a wrong if condition) * Minor changes in documentation v2: * Updated documentation with the change in behavior for outbound inline offloaded packets. doc/guides/sample_app_ug/ipsec_secgw.rst | 10 ++- examples/ipsec-secgw/ipsec-secgw.c | 101 ++++++++++++++++++++++++++----- 2 files changed, 96 insertions(+), 15 deletions(-) diff --git a/doc/guides/sample_app_ug/ipsec_secgw.rst b/doc/guides/sample_app_ug/ipsec_secgw.rst index d6cfdbf..ae18acd 100644 --- a/doc/guides/sample_app_ug/ipsec_secgw.rst +++ b/doc/guides/sample_app_ug/ipsec_secgw.rst @@ -61,6 +61,12 @@ In case of complete protocol offload, the processing of headers(ESP and outer IP header) is done by the hardware and the application does not need to add/remove them during outbound/inbound processing. +For inline offloaded outbound traffic, the application will not do the LPM +lookup for routing, as the port on which the packet has to be forwarded will be +part of the SA. Security parameters will be configured on that port only, and +sending the packet on other ports could result in unencrypted packets being +sent out. + The Path for IPsec Inbound traffic is: * Read packets from the port. @@ -543,7 +549,9 @@ where each options means: ```` * Port/device ID of the ethernet/crypto accelerator for which the SA is - configured. This option is used when *type* is NOT *no-offload* + configured. For *inline-crypto-offload* and *inline-protocol-offload*, this + port will be used for routing. The routing table will not be referred in + this case. * Optional: No, if *type* is not *no-offload* diff --git a/examples/ipsec-secgw/ipsec-secgw.c b/examples/ipsec-secgw/ipsec-secgw.c index c98454a..c75dd0d 100644 --- a/examples/ipsec-secgw/ipsec-secgw.c +++ b/examples/ipsec-secgw/ipsec-secgw.c @@ -585,31 +585,81 @@ process_pkts_outbound_nosp(struct ipsec_ctx *ipsec_ctx, traffic->ip6.num = nb_pkts_out; } +static inline int32_t +get_hop_for_offload_pkt(struct rte_mbuf *pkt, int is_ipv6) +{ + struct ipsec_mbuf_metadata *priv; + struct ipsec_sa *sa; + + priv = get_priv(pkt); + + sa = priv->sa; + if (unlikely(sa == NULL)) { + RTE_LOG(ERR, IPSEC, "SA not saved in private data\n"); + goto fail; + } + + if (is_ipv6) + return sa->portid; + + /* else */ + return (sa->portid | RTE_LPM_LOOKUP_SUCCESS); + +fail: + if (is_ipv6) + return -1; + + /* else */ + return 0; +} + static inline void route4_pkts(struct rt_ctx *rt_ctx, struct rte_mbuf *pkts[], uint8_t nb_pkts) { uint32_t hop[MAX_PKT_BURST * 2]; uint32_t dst_ip[MAX_PKT_BURST * 2]; + int32_t pkt_hop = 0; uint16_t i, offset; + uint16_t lpm_pkts = 0; if (nb_pkts == 0) return; + /* Need to do an LPM lookup for non-offload packets. Offload packets + * will have port ID in the SA + */ + for (i = 0; i < nb_pkts; i++) { - offset = offsetof(struct ip, ip_dst); - dst_ip[i] = *rte_pktmbuf_mtod_offset(pkts[i], - uint32_t *, offset); - dst_ip[i] = rte_be_to_cpu_32(dst_ip[i]); + if (!(pkts[i]->ol_flags & PKT_TX_SEC_OFFLOAD)) { + /* Security offload not enabled. So an LPM lookup is + * required to get the hop + */ + offset = offsetof(struct ip, ip_dst); + dst_ip[lpm_pkts] = *rte_pktmbuf_mtod_offset(pkts[i], + uint32_t *, offset); + dst_ip[lpm_pkts] = rte_be_to_cpu_32(dst_ip[lpm_pkts]); + lpm_pkts++; + } } - rte_lpm_lookup_bulk((struct rte_lpm *)rt_ctx, dst_ip, hop, nb_pkts); + rte_lpm_lookup_bulk((struct rte_lpm *)rt_ctx, dst_ip, hop, lpm_pkts); + + lpm_pkts = 0; for (i = 0; i < nb_pkts; i++) { - if ((hop[i] & RTE_LPM_LOOKUP_SUCCESS) == 0) { + if (pkts[i]->ol_flags & PKT_TX_SEC_OFFLOAD) { + /* Read hop from the SA */ + pkt_hop = get_hop_for_offload_pkt(pkts[i], 0); + } else { + /* Need to use hop returned by lookup */ + pkt_hop = hop[lpm_pkts++]; + } + + if ((pkt_hop & RTE_LPM_LOOKUP_SUCCESS) == 0) { rte_pktmbuf_free(pkts[i]); continue; } - send_single_packet(pkts[i], hop[i] & 0xff); + send_single_packet(pkts[i], pkt_hop & 0xff); } } @@ -619,26 +669,49 @@ route6_pkts(struct rt_ctx *rt_ctx, struct rte_mbuf *pkts[], uint8_t nb_pkts) int32_t hop[MAX_PKT_BURST * 2]; uint8_t dst_ip[MAX_PKT_BURST * 2][16]; uint8_t *ip6_dst; + int32_t pkt_hop = 0; uint16_t i, offset; + uint16_t lpm_pkts = 0; if (nb_pkts == 0) return; + /* Need to do an LPM lookup for non-offload packets. Offload packets + * will have port ID in the SA + */ + for (i = 0; i < nb_pkts; i++) { - offset = offsetof(struct ip6_hdr, ip6_dst); - ip6_dst = rte_pktmbuf_mtod_offset(pkts[i], uint8_t *, offset); - memcpy(&dst_ip[i][0], ip6_dst, 16); + if (!(pkts[i]->ol_flags & PKT_TX_SEC_OFFLOAD)) { + /* Security offload not enabled. So an LPM lookup is + * required to get the hop + */ + offset = offsetof(struct ip6_hdr, ip6_dst); + ip6_dst = rte_pktmbuf_mtod_offset(pkts[i], uint8_t *, + offset); + memcpy(&dst_ip[lpm_pkts][0], ip6_dst, 16); + lpm_pkts++; + } } - rte_lpm6_lookup_bulk_func((struct rte_lpm6 *)rt_ctx, dst_ip, - hop, nb_pkts); + rte_lpm6_lookup_bulk_func((struct rte_lpm6 *)rt_ctx, dst_ip, hop, + lpm_pkts); + + lpm_pkts = 0; for (i = 0; i < nb_pkts; i++) { - if (hop[i] == -1) { + if (pkts[i]->ol_flags & PKT_TX_SEC_OFFLOAD) { + /* Read hop from the SA */ + pkt_hop = get_hop_for_offload_pkt(pkts[i], 1); + } else { + /* Need to use hop returned by lookup */ + pkt_hop = hop[lpm_pkts++]; + } + + if (pkt_hop == -1) { rte_pktmbuf_free(pkts[i]); continue; } - send_single_packet(pkts[i], hop[i] & 0xff); + send_single_packet(pkts[i], pkt_hop & 0xff); } } -- 2.7.4