1d30ea906Sjfb8856606 /* SPDX-License-Identifier: BSD-3-Clause 2*4418919fSjohnjiang * Copyright 2017,2019 NXP 3d30ea906Sjfb8856606 * Copyright(c) 2017 Intel Corporation. 42bfe3f2eSlogwang */ 52bfe3f2eSlogwang 62bfe3f2eSlogwang #ifndef _RTE_SECURITY_H_ 72bfe3f2eSlogwang #define _RTE_SECURITY_H_ 82bfe3f2eSlogwang 92bfe3f2eSlogwang /** 102bfe3f2eSlogwang * @file rte_security.h 112bfe3f2eSlogwang * 122bfe3f2eSlogwang * RTE Security Common Definitions 132bfe3f2eSlogwang * 142bfe3f2eSlogwang */ 152bfe3f2eSlogwang 162bfe3f2eSlogwang #ifdef __cplusplus 172bfe3f2eSlogwang extern "C" { 182bfe3f2eSlogwang #endif 192bfe3f2eSlogwang 202bfe3f2eSlogwang #include <sys/types.h> 212bfe3f2eSlogwang 222bfe3f2eSlogwang #include <netinet/in.h> 232bfe3f2eSlogwang #include <netinet/ip.h> 242bfe3f2eSlogwang #include <netinet/ip6.h> 252bfe3f2eSlogwang 26d30ea906Sjfb8856606 #include <rte_compat.h> 272bfe3f2eSlogwang #include <rte_common.h> 282bfe3f2eSlogwang #include <rte_crypto.h> 292bfe3f2eSlogwang #include <rte_mbuf.h> 302bfe3f2eSlogwang #include <rte_memory.h> 312bfe3f2eSlogwang #include <rte_mempool.h> 322bfe3f2eSlogwang 332bfe3f2eSlogwang /** IPSec protocol mode */ 342bfe3f2eSlogwang enum rte_security_ipsec_sa_mode { 352bfe3f2eSlogwang RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT = 1, 362bfe3f2eSlogwang /**< IPSec Transport mode */ 372bfe3f2eSlogwang RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, 382bfe3f2eSlogwang /**< IPSec Tunnel mode */ 392bfe3f2eSlogwang }; 402bfe3f2eSlogwang 412bfe3f2eSlogwang /** IPSec Protocol */ 422bfe3f2eSlogwang enum rte_security_ipsec_sa_protocol { 432bfe3f2eSlogwang RTE_SECURITY_IPSEC_SA_PROTO_AH = 1, 442bfe3f2eSlogwang /**< AH protocol */ 452bfe3f2eSlogwang RTE_SECURITY_IPSEC_SA_PROTO_ESP, 462bfe3f2eSlogwang /**< ESP protocol */ 472bfe3f2eSlogwang }; 482bfe3f2eSlogwang 492bfe3f2eSlogwang /** IPSEC tunnel type */ 502bfe3f2eSlogwang enum rte_security_ipsec_tunnel_type { 512bfe3f2eSlogwang RTE_SECURITY_IPSEC_TUNNEL_IPV4 = 1, 522bfe3f2eSlogwang /**< Outer header is IPv4 */ 532bfe3f2eSlogwang RTE_SECURITY_IPSEC_TUNNEL_IPV6, 542bfe3f2eSlogwang /**< Outer header is IPv6 */ 552bfe3f2eSlogwang }; 562bfe3f2eSlogwang 572bfe3f2eSlogwang /** 582bfe3f2eSlogwang * Security context for crypto/eth devices 592bfe3f2eSlogwang * 602bfe3f2eSlogwang * Security instance for each driver to register security operations. 612bfe3f2eSlogwang * The application can get the security context from the crypto/eth device id 622bfe3f2eSlogwang * using the APIs rte_cryptodev_get_sec_ctx()/rte_eth_dev_get_sec_ctx() 632bfe3f2eSlogwang * This structure is used to identify the device(crypto/eth) for which the 642bfe3f2eSlogwang * security operations need to be performed. 652bfe3f2eSlogwang */ 662bfe3f2eSlogwang struct rte_security_ctx { 672bfe3f2eSlogwang void *device; 682bfe3f2eSlogwang /**< Crypto/ethernet device attached */ 692bfe3f2eSlogwang const struct rte_security_ops *ops; 702bfe3f2eSlogwang /**< Pointer to security ops for the device */ 712bfe3f2eSlogwang uint16_t sess_cnt; 722bfe3f2eSlogwang /**< Number of sessions attached to this context */ 732bfe3f2eSlogwang }; 742bfe3f2eSlogwang 752bfe3f2eSlogwang /** 762bfe3f2eSlogwang * IPSEC tunnel parameters 772bfe3f2eSlogwang * 782bfe3f2eSlogwang * These parameters are used to build outbound tunnel headers. 792bfe3f2eSlogwang */ 802bfe3f2eSlogwang struct rte_security_ipsec_tunnel_param { 812bfe3f2eSlogwang enum rte_security_ipsec_tunnel_type type; 822bfe3f2eSlogwang /**< Tunnel type: IPv4 or IPv6 */ 832bfe3f2eSlogwang RTE_STD_C11 842bfe3f2eSlogwang union { 852bfe3f2eSlogwang struct { 862bfe3f2eSlogwang struct in_addr src_ip; 872bfe3f2eSlogwang /**< IPv4 source address */ 882bfe3f2eSlogwang struct in_addr dst_ip; 892bfe3f2eSlogwang /**< IPv4 destination address */ 902bfe3f2eSlogwang uint8_t dscp; 912bfe3f2eSlogwang /**< IPv4 Differentiated Services Code Point */ 922bfe3f2eSlogwang uint8_t df; 932bfe3f2eSlogwang /**< IPv4 Don't Fragment bit */ 942bfe3f2eSlogwang uint8_t ttl; 952bfe3f2eSlogwang /**< IPv4 Time To Live */ 962bfe3f2eSlogwang } ipv4; 972bfe3f2eSlogwang /**< IPv4 header parameters */ 982bfe3f2eSlogwang struct { 992bfe3f2eSlogwang struct in6_addr src_addr; 1002bfe3f2eSlogwang /**< IPv6 source address */ 1012bfe3f2eSlogwang struct in6_addr dst_addr; 1022bfe3f2eSlogwang /**< IPv6 destination address */ 1032bfe3f2eSlogwang uint8_t dscp; 1042bfe3f2eSlogwang /**< IPv6 Differentiated Services Code Point */ 1052bfe3f2eSlogwang uint32_t flabel; 1062bfe3f2eSlogwang /**< IPv6 flow label */ 1072bfe3f2eSlogwang uint8_t hlimit; 1082bfe3f2eSlogwang /**< IPv6 hop limit */ 1092bfe3f2eSlogwang } ipv6; 1102bfe3f2eSlogwang /**< IPv6 header parameters */ 1112bfe3f2eSlogwang }; 1122bfe3f2eSlogwang }; 1132bfe3f2eSlogwang 1142bfe3f2eSlogwang /** 1152bfe3f2eSlogwang * IPsec Security Association option flags 1162bfe3f2eSlogwang */ 1172bfe3f2eSlogwang struct rte_security_ipsec_sa_options { 118*4418919fSjohnjiang /** Extended Sequence Numbers (ESN) 1192bfe3f2eSlogwang * 1202bfe3f2eSlogwang * * 1: Use extended (64 bit) sequence numbers 1212bfe3f2eSlogwang * * 0: Use normal sequence numbers 1222bfe3f2eSlogwang */ 1232bfe3f2eSlogwang uint32_t esn : 1; 1242bfe3f2eSlogwang 125*4418919fSjohnjiang /** UDP encapsulation 1262bfe3f2eSlogwang * 1272bfe3f2eSlogwang * * 1: Do UDP encapsulation/decapsulation so that IPSEC packets can 1282bfe3f2eSlogwang * traverse through NAT boxes. 1292bfe3f2eSlogwang * * 0: No UDP encapsulation 1302bfe3f2eSlogwang */ 1312bfe3f2eSlogwang uint32_t udp_encap : 1; 1322bfe3f2eSlogwang 133*4418919fSjohnjiang /** Copy DSCP bits 1342bfe3f2eSlogwang * 1352bfe3f2eSlogwang * * 1: Copy IPv4 or IPv6 DSCP bits from inner IP header to 1362bfe3f2eSlogwang * the outer IP header in encapsulation, and vice versa in 1372bfe3f2eSlogwang * decapsulation. 1382bfe3f2eSlogwang * * 0: Do not change DSCP field. 1392bfe3f2eSlogwang */ 1402bfe3f2eSlogwang uint32_t copy_dscp : 1; 1412bfe3f2eSlogwang 142*4418919fSjohnjiang /** Copy IPv6 Flow Label 1432bfe3f2eSlogwang * 1442bfe3f2eSlogwang * * 1: Copy IPv6 flow label from inner IPv6 header to the 1452bfe3f2eSlogwang * outer IPv6 header. 1462bfe3f2eSlogwang * * 0: Outer header is not modified. 1472bfe3f2eSlogwang */ 1482bfe3f2eSlogwang uint32_t copy_flabel : 1; 1492bfe3f2eSlogwang 150*4418919fSjohnjiang /** Copy IPv4 Don't Fragment bit 1512bfe3f2eSlogwang * 1522bfe3f2eSlogwang * * 1: Copy the DF bit from the inner IPv4 header to the outer 1532bfe3f2eSlogwang * IPv4 header. 1542bfe3f2eSlogwang * * 0: Outer header is not modified. 1552bfe3f2eSlogwang */ 1562bfe3f2eSlogwang uint32_t copy_df : 1; 1572bfe3f2eSlogwang 158*4418919fSjohnjiang /** Decrement inner packet Time To Live (TTL) field 1592bfe3f2eSlogwang * 1602bfe3f2eSlogwang * * 1: In tunnel mode, decrement inner packet IPv4 TTL or 1612bfe3f2eSlogwang * IPv6 Hop Limit after tunnel decapsulation, or before tunnel 1622bfe3f2eSlogwang * encapsulation. 1632bfe3f2eSlogwang * * 0: Inner packet is not modified. 1642bfe3f2eSlogwang */ 1652bfe3f2eSlogwang uint32_t dec_ttl : 1; 166*4418919fSjohnjiang 167*4418919fSjohnjiang /** Explicit Congestion Notification (ECN) 168*4418919fSjohnjiang * 169*4418919fSjohnjiang * * 1: In tunnel mode, enable outer header ECN Field copied from 170*4418919fSjohnjiang * inner header in tunnel encapsulation, or inner header ECN 171*4418919fSjohnjiang * field construction in decapsulation. 172*4418919fSjohnjiang * * 0: Inner/outer header are not modified. 173*4418919fSjohnjiang */ 174*4418919fSjohnjiang uint32_t ecn : 1; 175*4418919fSjohnjiang 176*4418919fSjohnjiang /** Security statistics 177*4418919fSjohnjiang * 178*4418919fSjohnjiang * * 1: Enable per session security statistics collection for 179*4418919fSjohnjiang * this SA, if supported by the driver. 180*4418919fSjohnjiang * * 0: Disable per session security statistics collection for this SA. 181*4418919fSjohnjiang */ 182*4418919fSjohnjiang uint32_t stats : 1; 1832bfe3f2eSlogwang }; 1842bfe3f2eSlogwang 1852bfe3f2eSlogwang /** IPSec security association direction */ 1862bfe3f2eSlogwang enum rte_security_ipsec_sa_direction { 1872bfe3f2eSlogwang RTE_SECURITY_IPSEC_SA_DIR_EGRESS, 1882bfe3f2eSlogwang /**< Encrypt and generate digest */ 1892bfe3f2eSlogwang RTE_SECURITY_IPSEC_SA_DIR_INGRESS, 1902bfe3f2eSlogwang /**< Verify digest and decrypt */ 1912bfe3f2eSlogwang }; 1922bfe3f2eSlogwang 1932bfe3f2eSlogwang /** 1942bfe3f2eSlogwang * IPsec security association configuration data. 1952bfe3f2eSlogwang * 1962bfe3f2eSlogwang * This structure contains data required to create an IPsec SA security session. 1972bfe3f2eSlogwang */ 1982bfe3f2eSlogwang struct rte_security_ipsec_xform { 1992bfe3f2eSlogwang uint32_t spi; 2002bfe3f2eSlogwang /**< SA security parameter index */ 2012bfe3f2eSlogwang uint32_t salt; 2022bfe3f2eSlogwang /**< SA salt */ 2032bfe3f2eSlogwang struct rte_security_ipsec_sa_options options; 2042bfe3f2eSlogwang /**< various SA options */ 2052bfe3f2eSlogwang enum rte_security_ipsec_sa_direction direction; 2062bfe3f2eSlogwang /**< IPSec SA Direction - Egress/Ingress */ 2072bfe3f2eSlogwang enum rte_security_ipsec_sa_protocol proto; 2082bfe3f2eSlogwang /**< IPsec SA Protocol - AH/ESP */ 2092bfe3f2eSlogwang enum rte_security_ipsec_sa_mode mode; 2102bfe3f2eSlogwang /**< IPsec SA Mode - transport/tunnel */ 2112bfe3f2eSlogwang struct rte_security_ipsec_tunnel_param tunnel; 2122bfe3f2eSlogwang /**< Tunnel parameters, NULL for transport mode */ 213d30ea906Sjfb8856606 uint64_t esn_soft_limit; 214d30ea906Sjfb8856606 /**< ESN for which the overflow event need to be raised */ 215*4418919fSjohnjiang uint32_t replay_win_sz; 216*4418919fSjohnjiang /**< Anti replay window size to enable sequence replay attack handling. 217*4418919fSjohnjiang * replay checking is disabled if the window size is 0. 218*4418919fSjohnjiang */ 2192bfe3f2eSlogwang }; 2202bfe3f2eSlogwang 2212bfe3f2eSlogwang /** 2222bfe3f2eSlogwang * MACsec security session configuration 2232bfe3f2eSlogwang */ 2242bfe3f2eSlogwang struct rte_security_macsec_xform { 2252bfe3f2eSlogwang /** To be Filled */ 2262bfe3f2eSlogwang int dummy; 2272bfe3f2eSlogwang }; 2282bfe3f2eSlogwang 2292bfe3f2eSlogwang /** 230d30ea906Sjfb8856606 * PDCP Mode of session 231d30ea906Sjfb8856606 */ 232d30ea906Sjfb8856606 enum rte_security_pdcp_domain { 233d30ea906Sjfb8856606 RTE_SECURITY_PDCP_MODE_CONTROL, /**< PDCP control plane */ 234d30ea906Sjfb8856606 RTE_SECURITY_PDCP_MODE_DATA, /**< PDCP data plane */ 235d30ea906Sjfb8856606 }; 236d30ea906Sjfb8856606 237d30ea906Sjfb8856606 /** PDCP Frame direction */ 238d30ea906Sjfb8856606 enum rte_security_pdcp_direction { 239d30ea906Sjfb8856606 RTE_SECURITY_PDCP_UPLINK, /**< Uplink */ 240d30ea906Sjfb8856606 RTE_SECURITY_PDCP_DOWNLINK, /**< Downlink */ 241d30ea906Sjfb8856606 }; 242d30ea906Sjfb8856606 243d30ea906Sjfb8856606 /** PDCP Sequence Number Size selectors */ 244d30ea906Sjfb8856606 enum rte_security_pdcp_sn_size { 245d30ea906Sjfb8856606 /** PDCP_SN_SIZE_5: 5bit sequence number */ 246d30ea906Sjfb8856606 RTE_SECURITY_PDCP_SN_SIZE_5 = 5, 247d30ea906Sjfb8856606 /** PDCP_SN_SIZE_7: 7bit sequence number */ 248d30ea906Sjfb8856606 RTE_SECURITY_PDCP_SN_SIZE_7 = 7, 249d30ea906Sjfb8856606 /** PDCP_SN_SIZE_12: 12bit sequence number */ 250d30ea906Sjfb8856606 RTE_SECURITY_PDCP_SN_SIZE_12 = 12, 251d30ea906Sjfb8856606 /** PDCP_SN_SIZE_15: 15bit sequence number */ 252d30ea906Sjfb8856606 RTE_SECURITY_PDCP_SN_SIZE_15 = 15, 253d30ea906Sjfb8856606 /** PDCP_SN_SIZE_18: 18bit sequence number */ 254d30ea906Sjfb8856606 RTE_SECURITY_PDCP_SN_SIZE_18 = 18 255d30ea906Sjfb8856606 }; 256d30ea906Sjfb8856606 257d30ea906Sjfb8856606 /** 258d30ea906Sjfb8856606 * PDCP security association configuration data. 259d30ea906Sjfb8856606 * 260d30ea906Sjfb8856606 * This structure contains data required to create a PDCP security session. 261d30ea906Sjfb8856606 */ 262d30ea906Sjfb8856606 struct rte_security_pdcp_xform { 263d30ea906Sjfb8856606 int8_t bearer; /**< PDCP bearer ID */ 264d30ea906Sjfb8856606 /** Enable in order delivery, this field shall be set only if 265d30ea906Sjfb8856606 * driver/HW is capable. See RTE_SECURITY_PDCP_ORDERING_CAP. 266d30ea906Sjfb8856606 */ 267d30ea906Sjfb8856606 uint8_t en_ordering; 268d30ea906Sjfb8856606 /** Notify driver/HW to detect and remove duplicate packets. 269d30ea906Sjfb8856606 * This field should be set only when driver/hw is capable. 270d30ea906Sjfb8856606 * See RTE_SECURITY_PDCP_DUP_DETECT_CAP. 271d30ea906Sjfb8856606 */ 272d30ea906Sjfb8856606 uint8_t remove_duplicates; 273d30ea906Sjfb8856606 /** PDCP mode of operation: Control or data */ 274d30ea906Sjfb8856606 enum rte_security_pdcp_domain domain; 275d30ea906Sjfb8856606 /** PDCP Frame Direction 0:UL 1:DL */ 276d30ea906Sjfb8856606 enum rte_security_pdcp_direction pkt_dir; 277d30ea906Sjfb8856606 /** Sequence number size, 5/7/12/15/18 */ 278d30ea906Sjfb8856606 enum rte_security_pdcp_sn_size sn_size; 279d30ea906Sjfb8856606 /** Starting Hyper Frame Number to be used together with the SN 280d30ea906Sjfb8856606 * from the PDCP frames 281d30ea906Sjfb8856606 */ 282d30ea906Sjfb8856606 uint32_t hfn; 283d30ea906Sjfb8856606 /** HFN Threshold for key renegotiation */ 284d30ea906Sjfb8856606 uint32_t hfn_threshold; 285*4418919fSjohnjiang /** HFN can be given as a per packet value also. 286*4418919fSjohnjiang * As we do not have IV in case of PDCP, and HFN is 287*4418919fSjohnjiang * used to generate IV. IV field can be used to get the 288*4418919fSjohnjiang * per packet HFN while enq/deq. 289*4418919fSjohnjiang * If hfn_ovrd field is set, user is expected to set the 290*4418919fSjohnjiang * per packet HFN in place of IV. PMDs will extract the HFN 291*4418919fSjohnjiang * and perform operations accordingly. 292*4418919fSjohnjiang */ 293*4418919fSjohnjiang uint32_t hfn_ovrd; 294d30ea906Sjfb8856606 }; 295d30ea906Sjfb8856606 296d30ea906Sjfb8856606 /** 2972bfe3f2eSlogwang * Security session action type. 2982bfe3f2eSlogwang */ 2992bfe3f2eSlogwang enum rte_security_session_action_type { 3002bfe3f2eSlogwang RTE_SECURITY_ACTION_TYPE_NONE, 3012bfe3f2eSlogwang /**< No security actions */ 3022bfe3f2eSlogwang RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO, 3032bfe3f2eSlogwang /**< Crypto processing for security protocol is processed inline 3042bfe3f2eSlogwang * during transmission 3052bfe3f2eSlogwang */ 3062bfe3f2eSlogwang RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL, 3072bfe3f2eSlogwang /**< All security protocol processing is performed inline during 3082bfe3f2eSlogwang * transmission 3092bfe3f2eSlogwang */ 3102bfe3f2eSlogwang RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL 3112bfe3f2eSlogwang /**< All security protocol processing including crypto is performed 3122bfe3f2eSlogwang * on a lookaside accelerator 3132bfe3f2eSlogwang */ 3142bfe3f2eSlogwang }; 3152bfe3f2eSlogwang 3162bfe3f2eSlogwang /** Security session protocol definition */ 3172bfe3f2eSlogwang enum rte_security_session_protocol { 3182bfe3f2eSlogwang RTE_SECURITY_PROTOCOL_IPSEC = 1, 3192bfe3f2eSlogwang /**< IPsec Protocol */ 3202bfe3f2eSlogwang RTE_SECURITY_PROTOCOL_MACSEC, 3212bfe3f2eSlogwang /**< MACSec Protocol */ 322d30ea906Sjfb8856606 RTE_SECURITY_PROTOCOL_PDCP, 323d30ea906Sjfb8856606 /**< PDCP Protocol */ 3242bfe3f2eSlogwang }; 3252bfe3f2eSlogwang 3262bfe3f2eSlogwang /** 3272bfe3f2eSlogwang * Security session configuration 3282bfe3f2eSlogwang */ 3292bfe3f2eSlogwang struct rte_security_session_conf { 3302bfe3f2eSlogwang enum rte_security_session_action_type action_type; 3312bfe3f2eSlogwang /**< Type of action to be performed on the session */ 3322bfe3f2eSlogwang enum rte_security_session_protocol protocol; 3332bfe3f2eSlogwang /**< Security protocol to be configured */ 3342bfe3f2eSlogwang RTE_STD_C11 3352bfe3f2eSlogwang union { 3362bfe3f2eSlogwang struct rte_security_ipsec_xform ipsec; 3372bfe3f2eSlogwang struct rte_security_macsec_xform macsec; 338d30ea906Sjfb8856606 struct rte_security_pdcp_xform pdcp; 3392bfe3f2eSlogwang }; 3402bfe3f2eSlogwang /**< Configuration parameters for security session */ 3412bfe3f2eSlogwang struct rte_crypto_sym_xform *crypto_xform; 3422bfe3f2eSlogwang /**< Security Session Crypto Transformations */ 343d30ea906Sjfb8856606 void *userdata; 344d30ea906Sjfb8856606 /**< Application specific userdata to be saved with session */ 3452bfe3f2eSlogwang }; 3462bfe3f2eSlogwang 3472bfe3f2eSlogwang struct rte_security_session { 3482bfe3f2eSlogwang void *sess_private_data; 3492bfe3f2eSlogwang /**< Private session material */ 350*4418919fSjohnjiang uint64_t opaque_data; 351*4418919fSjohnjiang /**< Opaque user defined data */ 3522bfe3f2eSlogwang }; 3532bfe3f2eSlogwang 3542bfe3f2eSlogwang /** 3552bfe3f2eSlogwang * Create security session as specified by the session configuration 3562bfe3f2eSlogwang * 3572bfe3f2eSlogwang * @param instance security instance 3582bfe3f2eSlogwang * @param conf session configuration parameters 3592bfe3f2eSlogwang * @param mp mempool to allocate session objects from 3602bfe3f2eSlogwang * @return 3612bfe3f2eSlogwang * - On success, pointer to session 3622bfe3f2eSlogwang * - On failure, NULL 3632bfe3f2eSlogwang */ 3642bfe3f2eSlogwang struct rte_security_session * 3652bfe3f2eSlogwang rte_security_session_create(struct rte_security_ctx *instance, 3662bfe3f2eSlogwang struct rte_security_session_conf *conf, 3672bfe3f2eSlogwang struct rte_mempool *mp); 3682bfe3f2eSlogwang 3692bfe3f2eSlogwang /** 3702bfe3f2eSlogwang * Update security session as specified by the session configuration 3712bfe3f2eSlogwang * 3722bfe3f2eSlogwang * @param instance security instance 3732bfe3f2eSlogwang * @param sess session to update parameters 3742bfe3f2eSlogwang * @param conf update configuration parameters 3752bfe3f2eSlogwang * @return 3762bfe3f2eSlogwang * - On success returns 0 3772bfe3f2eSlogwang * - On failure return errno 3782bfe3f2eSlogwang */ 379*4418919fSjohnjiang __rte_experimental 380*4418919fSjohnjiang int 3812bfe3f2eSlogwang rte_security_session_update(struct rte_security_ctx *instance, 3822bfe3f2eSlogwang struct rte_security_session *sess, 3832bfe3f2eSlogwang struct rte_security_session_conf *conf); 3842bfe3f2eSlogwang 3852bfe3f2eSlogwang /** 386d30ea906Sjfb8856606 * Get the size of the security session data for a device. 387d30ea906Sjfb8856606 * 388d30ea906Sjfb8856606 * @param instance security instance. 389d30ea906Sjfb8856606 * 390d30ea906Sjfb8856606 * @return 391d30ea906Sjfb8856606 * - Size of the private data, if successful 392d30ea906Sjfb8856606 * - 0 if device is invalid or does not support the operation. 393d30ea906Sjfb8856606 */ 394d30ea906Sjfb8856606 unsigned int 395d30ea906Sjfb8856606 rte_security_session_get_size(struct rte_security_ctx *instance); 396d30ea906Sjfb8856606 397d30ea906Sjfb8856606 /** 3982bfe3f2eSlogwang * Free security session header and the session private data and 3992bfe3f2eSlogwang * return it to its original mempool. 4002bfe3f2eSlogwang * 4012bfe3f2eSlogwang * @param instance security instance 4022bfe3f2eSlogwang * @param sess security session to freed 4032bfe3f2eSlogwang * 4042bfe3f2eSlogwang * @return 4052bfe3f2eSlogwang * - 0 if successful. 4062bfe3f2eSlogwang * - -EINVAL if session is NULL. 4072bfe3f2eSlogwang * - -EBUSY if not all device private data has been freed. 4082bfe3f2eSlogwang */ 4092bfe3f2eSlogwang int 4102bfe3f2eSlogwang rte_security_session_destroy(struct rte_security_ctx *instance, 4112bfe3f2eSlogwang struct rte_security_session *sess); 4122bfe3f2eSlogwang 4132bfe3f2eSlogwang /** 4142bfe3f2eSlogwang * Updates the buffer with device-specific defined metadata 4152bfe3f2eSlogwang * 4162bfe3f2eSlogwang * @param instance security instance 4172bfe3f2eSlogwang * @param sess security session 4182bfe3f2eSlogwang * @param mb packet mbuf to set metadata on. 4192bfe3f2eSlogwang * @param params device-specific defined parameters 4202bfe3f2eSlogwang * required for metadata 4212bfe3f2eSlogwang * 4222bfe3f2eSlogwang * @return 4232bfe3f2eSlogwang * - On success, zero. 4242bfe3f2eSlogwang * - On failure, a negative value. 4252bfe3f2eSlogwang */ 4262bfe3f2eSlogwang int 4272bfe3f2eSlogwang rte_security_set_pkt_metadata(struct rte_security_ctx *instance, 4282bfe3f2eSlogwang struct rte_security_session *sess, 4292bfe3f2eSlogwang struct rte_mbuf *mb, void *params); 4302bfe3f2eSlogwang 4312bfe3f2eSlogwang /** 432d30ea906Sjfb8856606 * Get userdata associated with the security session. Device specific metadata 433d30ea906Sjfb8856606 * provided would be used to uniquely identify the security session being 434d30ea906Sjfb8856606 * referred to. This userdata would be registered while creating the session, 435d30ea906Sjfb8856606 * and application can use this to identify the SA etc. 436d30ea906Sjfb8856606 * 437d30ea906Sjfb8856606 * Device specific metadata would be set in mbuf for inline processed inbound 438d30ea906Sjfb8856606 * packets. In addition, the same metadata would be set for IPsec events 439d30ea906Sjfb8856606 * reported by rte_eth_event framework. 440d30ea906Sjfb8856606 * 441d30ea906Sjfb8856606 * @param instance security instance 442d30ea906Sjfb8856606 * @param md device-specific metadata 443d30ea906Sjfb8856606 * 444d30ea906Sjfb8856606 * @return 445d30ea906Sjfb8856606 * - On success, userdata 446d30ea906Sjfb8856606 * - On failure, NULL 447d30ea906Sjfb8856606 */ 448*4418919fSjohnjiang __rte_experimental 449*4418919fSjohnjiang void * 450d30ea906Sjfb8856606 rte_security_get_userdata(struct rte_security_ctx *instance, uint64_t md); 451d30ea906Sjfb8856606 452d30ea906Sjfb8856606 /** 4532bfe3f2eSlogwang * Attach a session to a symmetric crypto operation 4542bfe3f2eSlogwang * 4552bfe3f2eSlogwang * @param sym_op crypto operation 4562bfe3f2eSlogwang * @param sess security session 4572bfe3f2eSlogwang */ 4582bfe3f2eSlogwang static inline int 4592bfe3f2eSlogwang __rte_security_attach_session(struct rte_crypto_sym_op *sym_op, 4602bfe3f2eSlogwang struct rte_security_session *sess) 4612bfe3f2eSlogwang { 4622bfe3f2eSlogwang sym_op->sec_session = sess; 4632bfe3f2eSlogwang 4642bfe3f2eSlogwang return 0; 4652bfe3f2eSlogwang } 4662bfe3f2eSlogwang 4672bfe3f2eSlogwang static inline void * 4682bfe3f2eSlogwang get_sec_session_private_data(const struct rte_security_session *sess) 4692bfe3f2eSlogwang { 4702bfe3f2eSlogwang return sess->sess_private_data; 4712bfe3f2eSlogwang } 4722bfe3f2eSlogwang 4732bfe3f2eSlogwang static inline void 4742bfe3f2eSlogwang set_sec_session_private_data(struct rte_security_session *sess, 4752bfe3f2eSlogwang void *private_data) 4762bfe3f2eSlogwang { 4772bfe3f2eSlogwang sess->sess_private_data = private_data; 4782bfe3f2eSlogwang } 4792bfe3f2eSlogwang 4802bfe3f2eSlogwang /** 4812bfe3f2eSlogwang * Attach a session to a crypto operation. 4822bfe3f2eSlogwang * This API is needed only in case of RTE_SECURITY_SESS_CRYPTO_PROTO_OFFLOAD 4832bfe3f2eSlogwang * For other rte_security_session_action_type, ol_flags in rte_mbuf may be 4842bfe3f2eSlogwang * defined to perform security operations. 4852bfe3f2eSlogwang * 4862bfe3f2eSlogwang * @param op crypto operation 4872bfe3f2eSlogwang * @param sess security session 4882bfe3f2eSlogwang */ 4892bfe3f2eSlogwang static inline int 4902bfe3f2eSlogwang rte_security_attach_session(struct rte_crypto_op *op, 4912bfe3f2eSlogwang struct rte_security_session *sess) 4922bfe3f2eSlogwang { 4932bfe3f2eSlogwang if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC)) 4942bfe3f2eSlogwang return -EINVAL; 4952bfe3f2eSlogwang 4962bfe3f2eSlogwang op->sess_type = RTE_CRYPTO_OP_SECURITY_SESSION; 4972bfe3f2eSlogwang 4982bfe3f2eSlogwang return __rte_security_attach_session(op->sym, sess); 4992bfe3f2eSlogwang } 5002bfe3f2eSlogwang 5012bfe3f2eSlogwang struct rte_security_macsec_stats { 5022bfe3f2eSlogwang uint64_t reserved; 5032bfe3f2eSlogwang }; 5042bfe3f2eSlogwang 5052bfe3f2eSlogwang struct rte_security_ipsec_stats { 506*4418919fSjohnjiang uint64_t ipackets; /**< Successfully received IPsec packets. */ 507*4418919fSjohnjiang uint64_t opackets; /**< Successfully transmitted IPsec packets.*/ 508*4418919fSjohnjiang uint64_t ibytes; /**< Successfully received IPsec bytes. */ 509*4418919fSjohnjiang uint64_t obytes; /**< Successfully transmitted IPsec bytes. */ 510*4418919fSjohnjiang uint64_t ierrors; /**< IPsec packets receive/decrypt errors. */ 511*4418919fSjohnjiang uint64_t oerrors; /**< IPsec packets transmit/encrypt errors. */ 512*4418919fSjohnjiang uint64_t reserved1; /**< Reserved for future use. */ 513*4418919fSjohnjiang uint64_t reserved2; /**< Reserved for future use. */ 5142bfe3f2eSlogwang }; 5152bfe3f2eSlogwang 516d30ea906Sjfb8856606 struct rte_security_pdcp_stats { 517d30ea906Sjfb8856606 uint64_t reserved; 518d30ea906Sjfb8856606 }; 519d30ea906Sjfb8856606 5202bfe3f2eSlogwang struct rte_security_stats { 5212bfe3f2eSlogwang enum rte_security_session_protocol protocol; 5222bfe3f2eSlogwang /**< Security protocol to be configured */ 5232bfe3f2eSlogwang 5242bfe3f2eSlogwang RTE_STD_C11 5252bfe3f2eSlogwang union { 5262bfe3f2eSlogwang struct rte_security_macsec_stats macsec; 5272bfe3f2eSlogwang struct rte_security_ipsec_stats ipsec; 528d30ea906Sjfb8856606 struct rte_security_pdcp_stats pdcp; 5292bfe3f2eSlogwang }; 5302bfe3f2eSlogwang }; 5312bfe3f2eSlogwang 5322bfe3f2eSlogwang /** 5332bfe3f2eSlogwang * Get security session statistics 5342bfe3f2eSlogwang * 5352bfe3f2eSlogwang * @param instance security instance 5362bfe3f2eSlogwang * @param sess security session 537*4418919fSjohnjiang * If security session is NULL then global (per security instance) statistics 538*4418919fSjohnjiang * will be retrieved, if supported. Global statistics collection is not 539*4418919fSjohnjiang * dependent on the per session statistics configuration. 5402bfe3f2eSlogwang * @param stats statistics 5412bfe3f2eSlogwang * @return 542*4418919fSjohnjiang * - On success, return 0 543*4418919fSjohnjiang * - On failure, a negative value 5442bfe3f2eSlogwang */ 545*4418919fSjohnjiang __rte_experimental 546*4418919fSjohnjiang int 5472bfe3f2eSlogwang rte_security_session_stats_get(struct rte_security_ctx *instance, 5482bfe3f2eSlogwang struct rte_security_session *sess, 5492bfe3f2eSlogwang struct rte_security_stats *stats); 5502bfe3f2eSlogwang 5512bfe3f2eSlogwang /** 5522bfe3f2eSlogwang * Security capability definition 5532bfe3f2eSlogwang */ 5542bfe3f2eSlogwang struct rte_security_capability { 5552bfe3f2eSlogwang enum rte_security_session_action_type action; 5562bfe3f2eSlogwang /**< Security action type*/ 5572bfe3f2eSlogwang enum rte_security_session_protocol protocol; 5582bfe3f2eSlogwang /**< Security protocol */ 5592bfe3f2eSlogwang RTE_STD_C11 5602bfe3f2eSlogwang union { 5612bfe3f2eSlogwang struct { 5622bfe3f2eSlogwang enum rte_security_ipsec_sa_protocol proto; 5632bfe3f2eSlogwang /**< IPsec SA protocol */ 5642bfe3f2eSlogwang enum rte_security_ipsec_sa_mode mode; 5652bfe3f2eSlogwang /**< IPsec SA mode */ 5662bfe3f2eSlogwang enum rte_security_ipsec_sa_direction direction; 5672bfe3f2eSlogwang /**< IPsec SA direction */ 5682bfe3f2eSlogwang struct rte_security_ipsec_sa_options options; 5692bfe3f2eSlogwang /**< IPsec SA supported options */ 570*4418919fSjohnjiang uint32_t replay_win_sz_max; 571*4418919fSjohnjiang /**< IPsec Anti Replay Window Size. A '0' value 572*4418919fSjohnjiang * indicates that Anti Replay is not supported. 573*4418919fSjohnjiang */ 5742bfe3f2eSlogwang } ipsec; 5752bfe3f2eSlogwang /**< IPsec capability */ 5762bfe3f2eSlogwang struct { 5772bfe3f2eSlogwang /* To be Filled */ 5782bfe3f2eSlogwang int dummy; 5792bfe3f2eSlogwang } macsec; 5802bfe3f2eSlogwang /**< MACsec capability */ 581d30ea906Sjfb8856606 struct { 582d30ea906Sjfb8856606 enum rte_security_pdcp_domain domain; 583d30ea906Sjfb8856606 /**< PDCP mode of operation: Control or data */ 584d30ea906Sjfb8856606 uint32_t capa_flags; 5851646932aSjfb8856606 /**< Capability flags, see RTE_SECURITY_PDCP_* */ 586d30ea906Sjfb8856606 } pdcp; 587d30ea906Sjfb8856606 /**< PDCP capability */ 5882bfe3f2eSlogwang }; 5892bfe3f2eSlogwang 5902bfe3f2eSlogwang const struct rte_cryptodev_capabilities *crypto_capabilities; 5912bfe3f2eSlogwang /**< Corresponding crypto capabilities for security capability */ 5922bfe3f2eSlogwang 5932bfe3f2eSlogwang uint32_t ol_flags; 5942bfe3f2eSlogwang /**< Device offload flags */ 5952bfe3f2eSlogwang }; 5962bfe3f2eSlogwang 597d30ea906Sjfb8856606 /** Underlying Hardware/driver which support PDCP may or may not support 598d30ea906Sjfb8856606 * packet ordering. Set RTE_SECURITY_PDCP_ORDERING_CAP if it support. 599d30ea906Sjfb8856606 * If it is not set, driver/HW assumes packets received are in order 600d30ea906Sjfb8856606 * and it will be application's responsibility to maintain ordering. 601d30ea906Sjfb8856606 */ 602d30ea906Sjfb8856606 #define RTE_SECURITY_PDCP_ORDERING_CAP 0x00000001 603d30ea906Sjfb8856606 604d30ea906Sjfb8856606 /** Underlying Hardware/driver which support PDCP may or may not detect 605d30ea906Sjfb8856606 * duplicate packet. Set RTE_SECURITY_PDCP_DUP_DETECT_CAP if it support. 606d30ea906Sjfb8856606 * If it is not set, driver/HW assumes there is no duplicate packet received. 607d30ea906Sjfb8856606 */ 608d30ea906Sjfb8856606 #define RTE_SECURITY_PDCP_DUP_DETECT_CAP 0x00000002 609d30ea906Sjfb8856606 6102bfe3f2eSlogwang #define RTE_SECURITY_TX_OLOAD_NEED_MDATA 0x00000001 6112bfe3f2eSlogwang /**< HW needs metadata update, see rte_security_set_pkt_metadata(). 6122bfe3f2eSlogwang */ 6132bfe3f2eSlogwang 6142bfe3f2eSlogwang #define RTE_SECURITY_TX_HW_TRAILER_OFFLOAD 0x00000002 6152bfe3f2eSlogwang /**< HW constructs trailer of packets 6162bfe3f2eSlogwang * Transmitted packets will have the trailer added to them 6171646932aSjfb8856606 * by hardware. The next protocol field will be based on 6182bfe3f2eSlogwang * the mbuf->inner_esp_next_proto field. 6192bfe3f2eSlogwang */ 6202bfe3f2eSlogwang #define RTE_SECURITY_RX_HW_TRAILER_OFFLOAD 0x00010000 6212bfe3f2eSlogwang /**< HW removes trailer of packets 6222bfe3f2eSlogwang * Received packets have no trailer, the next protocol field 6232bfe3f2eSlogwang * is supplied in the mbuf->inner_esp_next_proto field. 6242bfe3f2eSlogwang * Inner packet is not modified. 6252bfe3f2eSlogwang */ 6262bfe3f2eSlogwang 6272bfe3f2eSlogwang /** 6282bfe3f2eSlogwang * Security capability index used to query a security instance for a specific 6292bfe3f2eSlogwang * security capability 6302bfe3f2eSlogwang */ 6312bfe3f2eSlogwang struct rte_security_capability_idx { 6322bfe3f2eSlogwang enum rte_security_session_action_type action; 6332bfe3f2eSlogwang enum rte_security_session_protocol protocol; 6342bfe3f2eSlogwang 6352bfe3f2eSlogwang RTE_STD_C11 6362bfe3f2eSlogwang union { 6372bfe3f2eSlogwang struct { 6382bfe3f2eSlogwang enum rte_security_ipsec_sa_protocol proto; 6392bfe3f2eSlogwang enum rte_security_ipsec_sa_mode mode; 6402bfe3f2eSlogwang enum rte_security_ipsec_sa_direction direction; 6412bfe3f2eSlogwang } ipsec; 642d30ea906Sjfb8856606 struct { 643d30ea906Sjfb8856606 enum rte_security_pdcp_domain domain; 644d30ea906Sjfb8856606 uint32_t capa_flags; 645d30ea906Sjfb8856606 } pdcp; 6462bfe3f2eSlogwang }; 6472bfe3f2eSlogwang }; 6482bfe3f2eSlogwang 6492bfe3f2eSlogwang /** 6502bfe3f2eSlogwang * Returns array of security instance capabilities 6512bfe3f2eSlogwang * 6522bfe3f2eSlogwang * @param instance Security instance. 6532bfe3f2eSlogwang * 6542bfe3f2eSlogwang * @return 6552bfe3f2eSlogwang * - Returns array of security capabilities. 6562bfe3f2eSlogwang * - Return NULL if no capabilities available. 6572bfe3f2eSlogwang */ 6582bfe3f2eSlogwang const struct rte_security_capability * 6592bfe3f2eSlogwang rte_security_capabilities_get(struct rte_security_ctx *instance); 6602bfe3f2eSlogwang 6612bfe3f2eSlogwang /** 6622bfe3f2eSlogwang * Query if a specific capability is available on security instance 6632bfe3f2eSlogwang * 6642bfe3f2eSlogwang * @param instance security instance. 6652bfe3f2eSlogwang * @param idx security capability index to match against 6662bfe3f2eSlogwang * 6672bfe3f2eSlogwang * @return 6682bfe3f2eSlogwang * - Returns pointer to security capability on match of capability 6692bfe3f2eSlogwang * index criteria. 6702bfe3f2eSlogwang * - Return NULL if the capability not matched on security instance. 6712bfe3f2eSlogwang */ 6722bfe3f2eSlogwang const struct rte_security_capability * 6732bfe3f2eSlogwang rte_security_capability_get(struct rte_security_ctx *instance, 6742bfe3f2eSlogwang struct rte_security_capability_idx *idx); 6752bfe3f2eSlogwang 6762bfe3f2eSlogwang #ifdef __cplusplus 6772bfe3f2eSlogwang } 6782bfe3f2eSlogwang #endif 6792bfe3f2eSlogwang 6802bfe3f2eSlogwang #endif /* _RTE_SECURITY_H_ */ 681