From 1a08c379b9b5edeb0214378daa3fb2e56fba49ba Mon Sep 17 00:00:00 2001 From: Anoob Joseph Date: Mon, 18 Dec 2017 07:15:04 +0000 Subject: [PATCH] security: support user data retrieval In case of inline protocol processed ingress traffic, the packet may not have enough information to determine the security parameters with which the packet was processed. In such cases, application could get metadata from the packet which could be used to identify the security parameters with which the packet was processed. Application could register "userdata" with the security session, and this could be retrieved from the metadata of inline processed packets. The metadata returned by "rte_security_get_pkt_metadata()" will be device specific. Also the driver is expected to return the application registered "userdata" as is, without any modifications. Signed-off-by: Anoob Joseph Acked-by: Akhil Goyal --- doc/guides/prog_guide/rte_security.rst | 22 +++++++++++++++++++- lib/librte_security/rte_security.c | 12 +++++++++++ lib/librte_security/rte_security.h | 20 ++++++++++++++++++ lib/librte_security/rte_security_driver.h | 18 ++++++++++++++++ lib/librte_security/rte_security_version.map | 1 + 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/doc/guides/prog_guide/rte_security.rst b/doc/guides/prog_guide/rte_security.rst index 9be946bac2..0812abe779 100644 --- a/doc/guides/prog_guide/rte_security.rst +++ b/doc/guides/prog_guide/rte_security.rst @@ -123,7 +123,9 @@ packet. e.g. in the case of IPSec, the IPSec tunnel headers (if any), ESP/AH headers will be removed from the packet and the received packet will contains the decrypted packet only. The driver Rx path checks the descriptors and based on the crypto status sets additional flags in -``rte_mbuf.ol_flags`` field. +``rte_mbuf.ol_flags`` field. The driver would also set device-specific +metadata in ``rte_mbuf.udata64`` field. This will allow the application +to identify the security processing done on the packet. .. note:: @@ -396,6 +398,22 @@ For Inline Crypto and Inline protocol offload, device specific defined metadata updated in the mbuf using ``rte_security_set_pkt_metadata()`` if ``DEV_TX_OFFLOAD_SEC_NEED_MDATA`` is set. +For inline protocol offloaded ingress traffic, the application can register a +pointer, ``userdata`` , in the security session. When the packet is received, +``rte_security_get_userdata()`` would return the userdata registered for the +security session which processed the packet. + +.. note:: + + In case of inline processed packets, ``rte_mbuf.udata64`` field would be + used by the driver to relay information on the security processing + associated with the packet. In ingress, the driver would set this in Rx + path while in egress, ``rte_security_set_pkt_metadata()`` would perform a + similar operation. The application is expected not to modify the field + when it has relevant info. For ingress, this device-specific 64 bit value + is required to derive other information (like userdata), required for + identifying the security processing done on the packet. + Security session configuration ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -415,6 +433,8 @@ Security Session configuration structure is defined as ``rte_security_session_co /**< Configuration parameters for security session */ struct rte_crypto_sym_xform *crypto_xform; /**< Security Session Crypto Transformations */ + void *userdata; + /**< Application specific userdata to be saved with session */ }; The configuration structure reuses the ``rte_crypto_sym_xform`` struct for crypto related diff --git a/lib/librte_security/rte_security.c b/lib/librte_security/rte_security.c index 1227fca8a6..5805051168 100644 --- a/lib/librte_security/rte_security.c +++ b/lib/librte_security/rte_security.c @@ -108,6 +108,18 @@ rte_security_set_pkt_metadata(struct rte_security_ctx *instance, sess, m, params); } +void * +rte_security_get_userdata(struct rte_security_ctx *instance, uint64_t md) +{ + void *userdata = NULL; + + RTE_FUNC_PTR_OR_ERR_RET(*instance->ops->get_userdata, NULL); + if (instance->ops->get_userdata(instance->device, md, &userdata)) + return NULL; + + return userdata; +} + const struct rte_security_capability * rte_security_capabilities_get(struct rte_security_ctx *instance) { diff --git a/lib/librte_security/rte_security.h b/lib/librte_security/rte_security.h index 2b609cbf7a..004a0ebe3d 100644 --- a/lib/librte_security/rte_security.h +++ b/lib/librte_security/rte_security.h @@ -275,6 +275,8 @@ struct rte_security_session_conf { /**< Configuration parameters for security session */ struct rte_crypto_sym_xform *crypto_xform; /**< Security Session Crypto Transformations */ + void *userdata; + /**< Application specific userdata to be saved with session */ }; struct rte_security_session { @@ -346,6 +348,24 @@ rte_security_set_pkt_metadata(struct rte_security_ctx *instance, struct rte_security_session *sess, struct rte_mbuf *mb, void *params); +/** + * Get userdata associated with the security session which processed the + * packet. This userdata would be registered while creating the session, and + * application can use this to identify the SA etc. Device-specific metadata + * in the mbuf would be used for this. + * + * This is valid only for inline processed ingress packets. + * + * @param instance security instance + * @param md device-specific metadata set in mbuf + * + * @return + * - On success, userdata + * - On failure, NULL + */ +void * +rte_security_get_userdata(struct rte_security_ctx *instance, uint64_t md); + /** * Attach a session to a symmetric crypto operation * diff --git a/lib/librte_security/rte_security_driver.h b/lib/librte_security/rte_security_driver.h index 997fbe79f1..bf0170ec93 100644 --- a/lib/librte_security/rte_security_driver.h +++ b/lib/librte_security/rte_security_driver.h @@ -121,6 +121,22 @@ typedef int (*security_set_pkt_metadata_t)(void *device, struct rte_security_session *sess, struct rte_mbuf *m, void *params); +/** + * Get application specific userdata associated with the security session which + * processed the packet. This would be retrieved using the metadata obtained + * from packet. + * + * @param device Crypto/eth device pointer + * @param md Metadata + * @param userdata Pointer to receive userdata + * + * @return + * - Returns 0 if userdata is retrieved successfully. + * - Returns -ve value for errors. + */ +typedef int (*security_get_userdata_t)(void *device, + uint64_t md, void **userdata); + /** * Get security capabilities of the device. * @@ -145,6 +161,8 @@ struct rte_security_ops { /**< Clear a security sessions private data. */ security_set_pkt_metadata_t set_pkt_metadata; /**< Update mbuf metadata. */ + security_get_userdata_t get_userdata; + /**< Get userdata associated with session which processed the packet. */ security_capabilities_get_t capabilities_get; /**< Get security capabilities. */ }; diff --git a/lib/librte_security/rte_security_version.map b/lib/librte_security/rte_security_version.map index e12c04b2e2..bff5039b60 100644 --- a/lib/librte_security/rte_security_version.map +++ b/lib/librte_security/rte_security_version.map @@ -4,6 +4,7 @@ EXPERIMENTAL { rte_security_attach_session; rte_security_capabilities_get; rte_security_capability_get; + rte_security_get_userdata; rte_security_session_create; rte_security_session_destroy; rte_security_session_stats_get; -- 2.20.1