From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0058.outbound.protection.outlook.com [104.47.38.58]) by dpdk.org (Postfix) with ESMTP id 3FCD71B026 for ; Fri, 15 Dec 2017 12:03:34 +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=gabs54vBBxwK2Vd+tDZIS1/B3TuehHJ8QIAq6/ADuho=; b=jemOZDynlMScWaqe+OOXZ1GOsoYLnPKk3w0wQn7Jv47Kk7i8W83fjye4ZrE74WfUbGsq84WLtM/RKhqcdkeSi3djXOCIB77a1q+a+ysccUbwiueiMYSwWu5kqDV5/qagiV/ImNRYhTnubPaZZug5/83QU15z9hs4XoXOgZZgtpU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Anoob.Joseph@cavium.com; Received: from hyd1ajoseph-dt.caveonetworks.com (115.113.156.2) by CY4PR0701MB3635.namprd07.prod.outlook.com (2603:10b6:910:93::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.302.9; Fri, 15 Dec 2017 11:03:30 +0000 Cc: anoob.joseph@caviumnetworks.com, Akhil Goyal , Declan Doherty , Radu Nicolau , Sergio Gonzalez Monroy , Jerin Jacob , Narayana Prasad , dev@dpdk.org To: Nelio Laranjeiro References: <1513326606-21970-1-git-send-email-anoob.joseph@caviumnetworks.com> <1513327396-22178-1-git-send-email-anoob.joseph@caviumnetworks.com> <1513327396-22178-3-git-send-email-anoob.joseph@caviumnetworks.com> <20171215093931.rfpqwzincbcob6q4@laranjeiro-vm.dev.6wind.com> From: Anoob Joseph Message-ID: <923257f6-4ddf-6885-f7ad-caf5926a0545@caviumnetworks.com> Date: Fri, 15 Dec 2017 16:33:25 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20171215093931.rfpqwzincbcob6q4@laranjeiro-vm.dev.6wind.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [115.113.156.2] X-ClientProxiedBy: DM5PR1101CA0022.namprd11.prod.outlook.com (2603:10b6:4:4c::32) To CY4PR0701MB3635.namprd07.prod.outlook.com (2603:10b6:910:93::10) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a5afa2f3-88b6-465f-fe3d-08d543ab7b37 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(2017052603307); SRVR:CY4PR0701MB3635; X-Microsoft-Exchange-Diagnostics: 1; CY4PR0701MB3635; 3:6BvtkPhtf0PhG+beA9vARFbgzr61YhyyVRL+R3p15w5L9m/oVLOIRUjez5Su9IzwKdvkZsUMeBw/SZt00+YuQh7PGiSPgA6gGdNZMqlrFuN2ZoJzeVwSA/R1J2GYti5wA2S86HVy8ztU3SvU6+jH5WLAcMruHXW7EDrcyt4yoK6KHzY1omvtSnHEgd0EInU4pKmBgatS1Ui10+rt5WeF5OQfQRES2Glk8WyBHXqoUCRqMzbb9+9cNcnn4QkSeGCn; 25:mUUBmx5N9oJllcbM+94cSfzF7HrZtElw/vqKdh9GZsKgFwzFXHBZUKq/s0TYZ42JVnqIifprz6haCEtPP0i3t43AtVMMuvAwSnOZAX4cVfed6jRcHORr8wXgmZSBQW4CcJ5dJVDfz3jUMdvI0IZHYHkw9LHjf6VSLVUGeyVq8gmFzCZBlZlg0pGuf8JBAtBEPHqnk+77WXM2ZgYmh2JdP8CS/Uw065btf6W2mCQqQi7mEuCBVr9S/WZ1rcABgQBM3DVBg8bbsMPYpuxXx6OX18jO2P6ZUZHJG6aT5zM3Nn6ekGMFE5bwoMqZo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V/JlzJ6YEgygdZaMLEXVTVqhZkidjMrqFlhYV9/j8//JbUDPoRHcPhJMv9o6uj/28lmPM1Pa1NBoCAqL1/E0rfqxaEeoPAoHKc6HOs6wbjDUzIbtP0LXrO6lN6wVy+dPLQ4GLWXeBLLPZpp7mhDLpBY6+U1fbvCr6f7sY8ygqzmEmWROxVHQIqdby3r86vFYK83h8j/9Mgx1Cn0mmK8hGJ1uuKMsNoZNf1leZ9w 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)(93006095)(3231023)(10201501046)(3002001)(6041248)(20161123558100)(20161123555025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123562025)(6072148)(201708071742011); SRVR:CY4PR0701MB3635; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:CY4PR0701MB3635; X-Forefront-PRVS: 05220145DE X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(346002)(376002)(396003)(39860400002)(189003)(24454002)(199004)(23676004)(6486002)(31686004)(52146003)(2486003)(305945005)(52116002)(53936002)(81166006)(81156014)(25786009)(4326008)(230700001)(8676002)(7736002)(6246003)(6512007)(5660300001)(97736004)(6116002)(3846002)(50466002)(76176011)(36756003)(229853002)(6916009)(105586002)(42882006)(6666003)(67846002)(2950100002)(65826007)(106356001)(8656006)(478600001)(72206003)(83506002)(64126003)(68736007)(8936002)(69596002)(54906003)(53546011)(59450400001)(93886005)(6506007)(47776003)(58126008)(16526018)(65806001)(386003)(65956001)(316002)(2906002)(31696002)(53416004)(66066001)(55236004); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR0701MB3635; H:hyd1ajoseph-dt.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-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0FtUVHI+zu6vas7nXhCNVEaGIlx3G7gMxT12h+MCUN+YNathF6m2/fE/RQlV9ONzU12dBH8VKY2YcLzuATB84HesC9TugH4rsJPKLJuyLAfLBbHYCuHC0ZHvRdN3BXEAL/lyLxz0tKSsB/KycHGw610FB24MIL8PNK45IOrKQ4ChsCxwHN6OCdeW5L+KOG8fb/UW5dHgcPalDqf1I1wO318qwpUmIEInM/oT3jlnm6p33+smhX0rAg1IDR SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Dec 2017 11:03:30.0091 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a5afa2f3-88b6-465f-fe3d-08d543ab7b37 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR0701MB3635 Subject: Re: [dpdk-dev] [PATCH v5 2/2] examples/ipsec-secgw: add support for inline protocol 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: Fri, 15 Dec 2017 11:03:34 -0000 Hi Nelio, On 12/15/2017 03:09 PM, Nelio Laranjeiro wrote: > Hi Anoob, > > On Fri, Dec 15, 2017 at 08:43:16AM +0000, Anoob Joseph wrote: >> Adding support for inline protocol processing >> >> In ingress side, application will receive regular IP packets, without >> any IPsec related info. Application will do a selector check (SP-SA >> check) by making use of the metadata from the packet. The >> device-specific metadata in mbuf would aid in determing the security >> session which processed the packet. > This means that your devices removes the tunnel header? What happens > for packets which could not be decrypted correctly, is also the header > removed? > Anyway this description is wrong as it is not true for all inline > devices. This is particularly for inline protocol processed packets. For inline crypto, tunnel headers will be present, but for inline protocol tunnel headers need not be present. > > In addition, in ingress, the same result can be archived by using a mark > id to identify the flow and thus its security association. > >> In egress side, the plain packet would be submitted to the driver. The >> packet will have optional metadata, which could be used to identify the >> security session associated with the packet. > Not true for all inline devices, some only need the next-proto for the > ESP part. This is more or less existing behavior for inline crypto. Inline protocol shares most of it's behavior with inline crypto. > >> Signed-off-by: Anoob Joseph >> --- >> v5: >> * Fixed checkpatch reported warnings >> >> v4: >> * Directly using rte_mbuf.udata64 as the metadata from the packet >> * Removed usage of rte_security_get_pkt_metadata API >> >> v3: >> * Using (void *)userdata instead of 64 bit metadata in conf >> * Changes parallel to the change in API >> >> v2: >> * Using get_pkt_metadata API instead of get_session & get_cookie APIs >> >> examples/ipsec-secgw/esp.c | 6 +- >> examples/ipsec-secgw/ipsec-secgw.c | 42 ++++++++++++- >> examples/ipsec-secgw/ipsec.c | 121 +++++++++++++++++++++++++++++++------ >> 3 files changed, 147 insertions(+), 22 deletions(-) >> >> diff --git a/examples/ipsec-secgw/esp.c b/examples/ipsec-secgw/esp.c >> index c3efe52..561f873 100644 >> --- a/examples/ipsec-secgw/esp.c >> +++ b/examples/ipsec-secgw/esp.c >> @@ -178,7 +178,8 @@ esp_inbound_post(struct rte_mbuf *m, struct ipsec_sa *sa, >> RTE_ASSERT(sa != NULL); >> RTE_ASSERT(cop != NULL); >> >> - if (sa->type == RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO) { >> + if ((sa->type == RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL) || >> + (sa->type == RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO)) { >> if (m->ol_flags & PKT_RX_SEC_OFFLOAD) { >> if (m->ol_flags & PKT_RX_SEC_OFFLOAD_FAILED) >> cop->status = RTE_CRYPTO_OP_STATUS_ERROR; >> @@ -474,7 +475,8 @@ esp_outbound_post(struct rte_mbuf *m, >> RTE_ASSERT(m != NULL); >> RTE_ASSERT(sa != NULL); >> >> - if (sa->type == RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO) { >> + if ((sa->type == RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL) || >> + (sa->type == RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO)) { >> m->ol_flags |= PKT_TX_SEC_OFFLOAD; >> } else { >> RTE_ASSERT(cop != NULL); >> diff --git a/examples/ipsec-secgw/ipsec-secgw.c b/examples/ipsec-secgw/ipsec-secgw.c >> index c98454a..8254056 100644 >> --- a/examples/ipsec-secgw/ipsec-secgw.c >> +++ b/examples/ipsec-secgw/ipsec-secgw.c >> @@ -265,6 +265,40 @@ prepare_one_packet(struct rte_mbuf *pkt, struct ipsec_traffic *t) >> RTE_LOG(ERR, IPSEC, "Unsupported packet type\n"); >> rte_pktmbuf_free(pkt); >> } >> + >> + /* Check if the packet has been processed inline. For inline protocol >> + * processed packets, the metadata in the mbuf can be used to identify >> + * the security processing done on the packet. The metadata will be >> + * used to retrieve the application registered userdata associated >> + * with the security session. >> + */ >> + >> + if (pkt->ol_flags & PKT_RX_SEC_OFFLOAD) { >> + struct ipsec_sa *sa; >> + struct ipsec_mbuf_metadata *priv; >> + struct rte_security_ctx *ctx = (struct rte_security_ctx *) >> + rte_eth_dev_get_sec_ctx( >> + pkt->port); >> + >> + /* Retrieve the userdata registered. Here, the userdata >> + * registered is the SA pointer. >> + */ >> + >> + sa = (struct ipsec_sa *) >> + rte_security_get_userdata(ctx, pkt->udata64); >> + >> + if (sa == NULL) { >> + /* userdata could not be retrieved */ >> + return; >> + } >> + >> + /* Save SA as priv member in mbuf. This will be used in the >> + * IPsec selector(SP-SA) check. >> + */ >> + >> + priv = get_priv(pkt); >> + priv->sa = sa; >> + } > You must verify the function exists on all drivers, those who don't > support such userdata to be inserted won't implement it. That check is there in library. It will return NULL and then the function would exit > > What happens on security session where the application don't set such > information? How the application knows the pointer is set correctly? Application is the one who sets and gets the pointer. If application doesn't set it correctly, application will not able to use it. If application doesn't set this, for inline protocol, the application won't have any information which it can use to identify the security processing done. > >> } >> >> static inline void >> @@ -401,11 +435,17 @@ inbound_sp_sa(struct sp_ctx *sp, struct sa_ctx *sa, struct traffic_type *ip, >> ip->pkts[j++] = m; >> continue; >> } >> - if (res & DISCARD || i < lim) { >> + if (res & DISCARD) { >> rte_pktmbuf_free(m); >> continue; >> } >> + >> /* Only check SPI match for processed IPSec packets */ >> + if (i < lim && ((m->ol_flags & PKT_RX_SEC_OFFLOAD) == 0)) { >> + rte_pktmbuf_free(m); >> + continue; >> + } >> + >> sa_idx = ip->res[i] & PROTECT_MASK; >> if (sa_idx == 0 || !inbound_sa_check(sa, m, sa_idx)) { >> rte_pktmbuf_free(m); >> diff --git a/examples/ipsec-secgw/ipsec.c b/examples/ipsec-secgw/ipsec.c >> index 70ed227..bd68ec6 100644 >> --- a/examples/ipsec-secgw/ipsec.c >> +++ b/examples/ipsec-secgw/ipsec.c >> @@ -46,6 +46,27 @@ >> #include "ipsec.h" >> #include "esp.h" >> >> +static inline void >> +set_ipsec_conf(struct ipsec_sa *sa, struct rte_security_ipsec_xform *ipsec) >> +{ >> + if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) { >> + struct rte_security_ipsec_tunnel_param *tunnel = >> + &ipsec->tunnel; >> + if (sa->flags == IP4_TUNNEL) { >> + tunnel->type = >> + RTE_SECURITY_IPSEC_TUNNEL_IPV4; >> + tunnel->ipv4.ttl = IPDEFTTL; >> + >> + memcpy((uint8_t *)&tunnel->ipv4.src_ip, >> + (uint8_t *)&sa->src.ip.ip4, 4); >> + >> + memcpy((uint8_t *)&tunnel->ipv4.dst_ip, >> + (uint8_t *)&sa->dst.ip.ip4, 4); >> + } >> + /* TODO support for Transport and IPV6 tunnel */ >> + } >> +} >> + >> static inline int >> create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa) >> { >> @@ -95,7 +116,8 @@ create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa) >> RTE_SECURITY_IPSEC_SA_MODE_TUNNEL : >> RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT, >> } }, >> - .crypto_xform = sa->xforms >> + .crypto_xform = sa->xforms, >> + .userdata = NULL, >> >> }; >> >> @@ -104,23 +126,8 @@ create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa) >> rte_cryptodev_get_sec_ctx( >> ipsec_ctx->tbl[cdev_id_qp].id); >> >> - if (sess_conf.ipsec.mode == >> - RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) { >> - struct rte_security_ipsec_tunnel_param *tunnel = >> - &sess_conf.ipsec.tunnel; >> - if (sa->flags == IP4_TUNNEL) { >> - tunnel->type = >> - RTE_SECURITY_IPSEC_TUNNEL_IPV4; >> - tunnel->ipv4.ttl = IPDEFTTL; >> - >> - memcpy((uint8_t *)&tunnel->ipv4.src_ip, >> - (uint8_t *)&sa->src.ip.ip4, 4); >> - >> - memcpy((uint8_t *)&tunnel->ipv4.dst_ip, >> - (uint8_t *)&sa->dst.ip.ip4, 4); >> - } >> - /* TODO support for Transport and IPV6 tunnel */ >> - } >> + /* Set IPsec parameters in conf */ >> + set_ipsec_conf(sa, &(sess_conf.ipsec)); >> >> sa->sec_session = rte_security_session_create(ctx, >> &sess_conf, ipsec_ctx->session_pool); >> @@ -206,6 +213,70 @@ create_session(struct ipsec_ctx *ipsec_ctx, struct ipsec_sa *sa) >> err.message); >> return -1; >> } >> + } else if (sa->type == >> + RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL) { >> + struct rte_security_ctx *ctx = >> + (struct rte_security_ctx *) >> + rte_eth_dev_get_sec_ctx(sa->portid); >> + const struct rte_security_capability *sec_cap; >> + >> + if (ctx == NULL) { >> + RTE_LOG(ERR, IPSEC, >> + "Ethernet device doesn't have security features registered\n"); >> + return -1; >> + } >> + >> + /* Set IPsec parameters in conf */ >> + set_ipsec_conf(sa, &(sess_conf.ipsec)); >> + >> + /* Save SA as userdata for the security session. When >> + * the packet is received, this userdata will be >> + * retrieved using the metadata from the packet. >> + * >> + * This is required only for inbound SAs. >> + */ > Again not true for all inline devices. Should be valid for all inline protocol devices. May be addition of capability would look better? > >> + >> + if (sa->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) >> + sess_conf.userdata = (void *) sa; >> + >> + sa->sec_session = rte_security_session_create(ctx, >> + &sess_conf, ipsec_ctx->session_pool); >> + if (sa->sec_session == NULL) { >> + RTE_LOG(ERR, IPSEC, >> + "SEC Session init failed: err: %d\n", ret); >> + return -1; >> + } >> + >> + sec_cap = rte_security_capabilities_get(ctx); >> + >> + if (sec_cap == NULL) { >> + RTE_LOG(ERR, IPSEC, >> + "No capabilities registered\n"); >> + return -1; >> + } >> + >> + /* iterate until ESP tunnel*/ >> + while (sec_cap->action != >> + RTE_SECURITY_ACTION_TYPE_NONE) { >> + >> + if (sec_cap->action == sa->type && >> + sec_cap->protocol == >> + RTE_SECURITY_PROTOCOL_IPSEC && >> + sec_cap->ipsec.mode == >> + RTE_SECURITY_IPSEC_SA_MODE_TUNNEL && >> + sec_cap->ipsec.direction == sa->direction) >> + break; >> + sec_cap++; >> + } >> + >> + if (sec_cap->action == RTE_SECURITY_ACTION_TYPE_NONE) { >> + RTE_LOG(ERR, IPSEC, >> + "No suitable security capability found\n"); >> + return -1; >> + } >> + >> + sa->ol_flags = sec_cap->ol_flags; >> + sa->security_ctx = ctx; >> } >> } else { >> sa->crypto_session = rte_cryptodev_sym_session_create( >> @@ -323,7 +394,19 @@ ipsec_enqueue(ipsec_xform_fn xform_func, struct ipsec_ctx *ipsec_ctx, >> } >> break; >> case RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL: >> - break; >> + if ((unlikely(sa->sec_session == NULL)) && >> + create_session(ipsec_ctx, sa)) { >> + rte_pktmbuf_free(pkts[i]); >> + continue; >> + } >> + >> + cqp = &ipsec_ctx->tbl[sa->cdev_id_qp]; >> + cqp->ol_pkts[cqp->ol_pkts_cnt++] = pkts[i]; >> + if (sa->ol_flags & RTE_SECURITY_TX_OLOAD_NEED_MDATA) >> + rte_security_set_pkt_metadata( >> + sa->security_ctx, >> + sa->sec_session, pkts[i], NULL); >> + continue; >> case RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO: >> priv->cop.type = RTE_CRYPTO_OP_TYPE_SYMMETRIC; >> priv->cop.status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; >> -- >> 2.7.4 >> > Thanks, > Thanks, Anoob