88147e1f572f62e2d2a8f72e20a515a14b73b15e
[dpdk.git] / lib / security / rte_security.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2017,2019-2020 NXP
3  * Copyright(c) 2017-2020 Intel Corporation.
4  */
5
6 #ifndef _RTE_SECURITY_H_
7 #define _RTE_SECURITY_H_
8
9 /**
10  * @file rte_security.h
11  *
12  * RTE Security Common Definitions
13  *
14  */
15
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19
20 #include <sys/types.h>
21
22 #include <netinet/in.h>
23 #include <netinet/ip.h>
24 #include <netinet/ip6.h>
25
26 #include <rte_compat.h>
27 #include <rte_common.h>
28 #include <rte_crypto.h>
29 #include <rte_mbuf.h>
30 #include <rte_mbuf_dyn.h>
31 #include <rte_memory.h>
32 #include <rte_mempool.h>
33
34 /** IPSec protocol mode */
35 enum rte_security_ipsec_sa_mode {
36         RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT = 1,
37         /**< IPSec Transport mode */
38         RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
39         /**< IPSec Tunnel mode */
40 };
41
42 /** IPSec Protocol */
43 enum rte_security_ipsec_sa_protocol {
44         RTE_SECURITY_IPSEC_SA_PROTO_AH = 1,
45         /**< AH protocol */
46         RTE_SECURITY_IPSEC_SA_PROTO_ESP,
47         /**< ESP protocol */
48 };
49
50 /** IPSEC tunnel type */
51 enum rte_security_ipsec_tunnel_type {
52         RTE_SECURITY_IPSEC_TUNNEL_IPV4 = 1,
53         /**< Outer header is IPv4 */
54         RTE_SECURITY_IPSEC_TUNNEL_IPV6,
55         /**< Outer header is IPv6 */
56 };
57
58 /**
59  * Security context for crypto/eth devices
60  *
61  * Security instance for each driver to register security operations.
62  * The application can get the security context from the crypto/eth device id
63  * using the APIs rte_cryptodev_get_sec_ctx()/rte_eth_dev_get_sec_ctx()
64  * This structure is used to identify the device(crypto/eth) for which the
65  * security operations need to be performed.
66  */
67 struct rte_security_ctx {
68         void *device;
69         /**< Crypto/ethernet device attached */
70         const struct rte_security_ops *ops;
71         /**< Pointer to security ops for the device */
72         uint16_t sess_cnt;
73         /**< Number of sessions attached to this context */
74         uint32_t flags;
75         /**< Flags for security context */
76 };
77
78 #define RTE_SEC_CTX_F_FAST_SET_MDATA 0x00000001
79 /**< Driver uses fast metadata update without using driver specific callback */
80
81 #define RTE_SEC_CTX_F_FAST_GET_UDATA 0x00000002
82 /**< Driver provides udata using fast method without using driver specific
83  * callback. For fast mdata and udata, mbuf dynamic field would be registered
84  * by driver via rte_security_dynfield_register().
85  */
86
87 /**
88  * IPSEC tunnel parameters
89  *
90  * These parameters are used to build outbound tunnel headers.
91  */
92 struct rte_security_ipsec_tunnel_param {
93         enum rte_security_ipsec_tunnel_type type;
94         /**< Tunnel type: IPv4 or IPv6 */
95         RTE_STD_C11
96         union {
97                 struct {
98                         struct in_addr src_ip;
99                         /**< IPv4 source address */
100                         struct in_addr dst_ip;
101                         /**< IPv4 destination address */
102                         uint8_t dscp;
103                         /**< IPv4 Differentiated Services Code Point */
104                         uint8_t df;
105                         /**< IPv4 Don't Fragment bit */
106                         uint8_t ttl;
107                         /**< IPv4 Time To Live */
108                 } ipv4;
109                 /**< IPv4 header parameters */
110                 struct {
111                         struct in6_addr src_addr;
112                         /**< IPv6 source address */
113                         struct in6_addr dst_addr;
114                         /**< IPv6 destination address */
115                         uint8_t dscp;
116                         /**< IPv6 Differentiated Services Code Point */
117                         uint32_t flabel;
118                         /**< IPv6 flow label */
119                         uint8_t hlimit;
120                         /**< IPv6 hop limit */
121                 } ipv6;
122                 /**< IPv6 header parameters */
123         };
124 };
125
126 /**
127  * IPsec Security Association option flags
128  */
129 struct rte_security_ipsec_sa_options {
130         /** Extended Sequence Numbers (ESN)
131          *
132          * * 1: Use extended (64 bit) sequence numbers
133          * * 0: Use normal sequence numbers
134          */
135         uint32_t esn : 1;
136
137         /** UDP encapsulation
138          *
139          * * 1: Do UDP encapsulation/decapsulation so that IPSEC packets can
140          *      traverse through NAT boxes.
141          * * 0: No UDP encapsulation
142          */
143         uint32_t udp_encap : 1;
144
145         /** Copy DSCP bits
146          *
147          * * 1: Copy IPv4 or IPv6 DSCP bits from inner IP header to
148          *      the outer IP header in encapsulation, and vice versa in
149          *      decapsulation.
150          * * 0: Do not change DSCP field.
151          */
152         uint32_t copy_dscp : 1;
153
154         /** Copy IPv6 Flow Label
155          *
156          * * 1: Copy IPv6 flow label from inner IPv6 header to the
157          *      outer IPv6 header.
158          * * 0: Outer header is not modified.
159          */
160         uint32_t copy_flabel : 1;
161
162         /** Copy IPv4 Don't Fragment bit
163          *
164          * * 1: Copy the DF bit from the inner IPv4 header to the outer
165          *      IPv4 header.
166          * * 0: Outer header is not modified.
167          */
168         uint32_t copy_df : 1;
169
170         /** Decrement inner packet Time To Live (TTL) field
171          *
172          * * 1: In tunnel mode, decrement inner packet IPv4 TTL or
173          *      IPv6 Hop Limit after tunnel decapsulation, or before tunnel
174          *      encapsulation.
175          * * 0: Inner packet is not modified.
176          */
177         uint32_t dec_ttl : 1;
178
179         /** Explicit Congestion Notification (ECN)
180          *
181          * * 1: In tunnel mode, enable outer header ECN Field copied from
182          *      inner header in tunnel encapsulation, or inner header ECN
183          *      field construction in decapsulation.
184          * * 0: Inner/outer header are not modified.
185          */
186         uint32_t ecn : 1;
187
188         /** Security statistics
189          *
190          * * 1: Enable per session security statistics collection for
191          *      this SA, if supported by the driver.
192          * * 0: Disable per session security statistics collection for this SA.
193          */
194         uint32_t stats : 1;
195
196         /** Disable IV generation in PMD
197          *
198          * * 1: Disable IV generation in PMD. When disabled, IV provided in
199          *      rte_crypto_op will be used by the PMD.
200          *
201          * * 0: Enable IV generation in PMD. When enabled, PMD generated random
202          *      value would be used and application is not required to provide
203          *      IV.
204          *
205          * Note: For inline cases, IV generation would always need to be handled
206          * by the PMD.
207          */
208         uint32_t iv_gen_disable : 1;
209 };
210
211 /** IPSec security association direction */
212 enum rte_security_ipsec_sa_direction {
213         RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
214         /**< Encrypt and generate digest */
215         RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
216         /**< Verify digest and decrypt */
217 };
218
219 /**
220  * Configure soft and hard lifetime of an IPsec SA
221  *
222  * Lifetime of an IPsec SA would specify the maximum number of packets or bytes
223  * that can be processed. IPsec operations would start failing once any hard
224  * limit is reached.
225  *
226  * Soft limits can be specified to generate notification when the SA is
227  * approaching hard limits for lifetime. For inline operations, reaching soft
228  * expiry limit would result in raising an eth event for the same. For lookaside
229  * operations, this would result in a warning returned in
230  * ``rte_crypto_op.aux_flags``.
231  */
232 struct rte_security_ipsec_lifetime {
233         uint64_t packets_soft_limit;
234         /**< Soft expiry limit in number of packets */
235         uint64_t bytes_soft_limit;
236         /**< Soft expiry limit in bytes */
237         uint64_t packets_hard_limit;
238         /**< Soft expiry limit in number of packets */
239         uint64_t bytes_hard_limit;
240         /**< Soft expiry limit in bytes */
241 };
242
243 /**
244  * IPsec security association configuration data.
245  *
246  * This structure contains data required to create an IPsec SA security session.
247  */
248 struct rte_security_ipsec_xform {
249         uint32_t spi;
250         /**< SA security parameter index */
251         uint32_t salt;
252         /**< SA salt */
253         struct rte_security_ipsec_sa_options options;
254         /**< various SA options */
255         enum rte_security_ipsec_sa_direction direction;
256         /**< IPSec SA Direction - Egress/Ingress */
257         enum rte_security_ipsec_sa_protocol proto;
258         /**< IPsec SA Protocol - AH/ESP */
259         enum rte_security_ipsec_sa_mode mode;
260         /**< IPsec SA Mode - transport/tunnel */
261         struct rte_security_ipsec_tunnel_param tunnel;
262         /**< Tunnel parameters, NULL for transport mode */
263         struct rte_security_ipsec_lifetime life;
264         /**< IPsec SA lifetime */
265         uint32_t replay_win_sz;
266         /**< Anti replay window size to enable sequence replay attack handling.
267          * replay checking is disabled if the window size is 0.
268          */
269 };
270
271 /**
272  * MACsec security session configuration
273  */
274 struct rte_security_macsec_xform {
275         /** To be Filled */
276         int dummy;
277 };
278
279 /**
280  * PDCP Mode of session
281  */
282 enum rte_security_pdcp_domain {
283         RTE_SECURITY_PDCP_MODE_CONTROL, /**< PDCP control plane */
284         RTE_SECURITY_PDCP_MODE_DATA,    /**< PDCP data plane */
285         RTE_SECURITY_PDCP_MODE_SHORT_MAC,       /**< PDCP short mac */
286 };
287
288 /** PDCP Frame direction */
289 enum rte_security_pdcp_direction {
290         RTE_SECURITY_PDCP_UPLINK,       /**< Uplink */
291         RTE_SECURITY_PDCP_DOWNLINK,     /**< Downlink */
292 };
293
294 /** PDCP Sequence Number Size selectors */
295 enum rte_security_pdcp_sn_size {
296         /** PDCP_SN_SIZE_5: 5bit sequence number */
297         RTE_SECURITY_PDCP_SN_SIZE_5 = 5,
298         /** PDCP_SN_SIZE_7: 7bit sequence number */
299         RTE_SECURITY_PDCP_SN_SIZE_7 = 7,
300         /** PDCP_SN_SIZE_12: 12bit sequence number */
301         RTE_SECURITY_PDCP_SN_SIZE_12 = 12,
302         /** PDCP_SN_SIZE_15: 15bit sequence number */
303         RTE_SECURITY_PDCP_SN_SIZE_15 = 15,
304         /** PDCP_SN_SIZE_18: 18bit sequence number */
305         RTE_SECURITY_PDCP_SN_SIZE_18 = 18
306 };
307
308 /**
309  * PDCP security association configuration data.
310  *
311  * This structure contains data required to create a PDCP security session.
312  */
313 struct rte_security_pdcp_xform {
314         int8_t bearer;  /**< PDCP bearer ID */
315         /** Enable in order delivery, this field shall be set only if
316          * driver/HW is capable. See RTE_SECURITY_PDCP_ORDERING_CAP.
317          */
318         uint8_t en_ordering;
319         /** Notify driver/HW to detect and remove duplicate packets.
320          * This field should be set only when driver/hw is capable.
321          * See RTE_SECURITY_PDCP_DUP_DETECT_CAP.
322          */
323         uint8_t remove_duplicates;
324         /** PDCP mode of operation: Control or data */
325         enum rte_security_pdcp_domain domain;
326         /** PDCP Frame Direction 0:UL 1:DL */
327         enum rte_security_pdcp_direction pkt_dir;
328         /** Sequence number size, 5/7/12/15/18 */
329         enum rte_security_pdcp_sn_size sn_size;
330         /** Starting Hyper Frame Number to be used together with the SN
331          * from the PDCP frames
332          */
333         uint32_t hfn;
334         /** HFN Threshold for key renegotiation */
335         uint32_t hfn_threshold;
336         /** HFN can be given as a per packet value also.
337          * As we do not have IV in case of PDCP, and HFN is
338          * used to generate IV. IV field can be used to get the
339          * per packet HFN while enq/deq.
340          * If hfn_ovrd field is set, user is expected to set the
341          * per packet HFN in place of IV. PMDs will extract the HFN
342          * and perform operations accordingly.
343          */
344         uint8_t hfn_ovrd;
345         /** In case of 5G NR, a new protocol (SDAP) header may be set
346          * inside PDCP payload which should be authenticated but not
347          * encrypted. Hence, driver should be notified if SDAP is
348          * enabled or not, so that SDAP header is not encrypted.
349          */
350         uint8_t sdap_enabled;
351         /** Reserved for future */
352         uint16_t reserved;
353 };
354
355 /** DOCSIS direction */
356 enum rte_security_docsis_direction {
357         RTE_SECURITY_DOCSIS_UPLINK,
358         /**< Uplink
359          * - Decryption, followed by CRC Verification
360          */
361         RTE_SECURITY_DOCSIS_DOWNLINK,
362         /**< Downlink
363          * - CRC Generation, followed by Encryption
364          */
365 };
366
367 /**
368  * DOCSIS security session configuration.
369  *
370  * This structure contains data required to create a DOCSIS security session.
371  */
372 struct rte_security_docsis_xform {
373         enum rte_security_docsis_direction direction;
374         /**< DOCSIS direction */
375 };
376
377 /**
378  * Security session action type.
379  */
380 enum rte_security_session_action_type {
381         RTE_SECURITY_ACTION_TYPE_NONE,
382         /**< No security actions */
383         RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
384         /**< Crypto processing for security protocol is processed inline
385          * during transmission
386          */
387         RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
388         /**< All security protocol processing is performed inline during
389          * transmission
390          */
391         RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
392         /**< All security protocol processing including crypto is performed
393          * on a lookaside accelerator
394          */
395         RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO
396         /**< Similar to ACTION_TYPE_NONE but crypto processing for security
397          * protocol is processed synchronously by a CPU.
398          */
399 };
400
401 /** Security session protocol definition */
402 enum rte_security_session_protocol {
403         RTE_SECURITY_PROTOCOL_IPSEC = 1,
404         /**< IPsec Protocol */
405         RTE_SECURITY_PROTOCOL_MACSEC,
406         /**< MACSec Protocol */
407         RTE_SECURITY_PROTOCOL_PDCP,
408         /**< PDCP Protocol */
409         RTE_SECURITY_PROTOCOL_DOCSIS,
410         /**< DOCSIS Protocol */
411 };
412
413 /**
414  * Security session configuration
415  */
416 struct rte_security_session_conf {
417         enum rte_security_session_action_type action_type;
418         /**< Type of action to be performed on the session */
419         enum rte_security_session_protocol protocol;
420         /**< Security protocol to be configured */
421         RTE_STD_C11
422         union {
423                 struct rte_security_ipsec_xform ipsec;
424                 struct rte_security_macsec_xform macsec;
425                 struct rte_security_pdcp_xform pdcp;
426                 struct rte_security_docsis_xform docsis;
427         };
428         /**< Configuration parameters for security session */
429         struct rte_crypto_sym_xform *crypto_xform;
430         /**< Security Session Crypto Transformations */
431         void *userdata;
432         /**< Application specific userdata to be saved with session */
433 };
434
435 struct rte_security_session {
436         void *sess_private_data;
437         /**< Private session material */
438         uint64_t opaque_data;
439         /**< Opaque user defined data */
440 };
441
442 /**
443  * Create security session as specified by the session configuration
444  *
445  * @param   instance    security instance
446  * @param   conf        session configuration parameters
447  * @param   mp          mempool to allocate session objects from
448  * @param   priv_mp     mempool to allocate session private data objects from
449  * @return
450  *  - On success, pointer to session
451  *  - On failure, NULL
452  */
453 struct rte_security_session *
454 rte_security_session_create(struct rte_security_ctx *instance,
455                             struct rte_security_session_conf *conf,
456                             struct rte_mempool *mp,
457                             struct rte_mempool *priv_mp);
458
459 /**
460  * Update security session as specified by the session configuration
461  *
462  * @param   instance    security instance
463  * @param   sess        session to update parameters
464  * @param   conf        update configuration parameters
465  * @return
466  *  - On success returns 0
467  *  - On failure returns a negative errno value.
468  */
469 __rte_experimental
470 int
471 rte_security_session_update(struct rte_security_ctx *instance,
472                             struct rte_security_session *sess,
473                             struct rte_security_session_conf *conf);
474
475 /**
476  * Get the size of the security session data for a device.
477  *
478  * @param   instance    security instance.
479  *
480  * @return
481  *   - Size of the private data, if successful
482  *   - 0 if device is invalid or does not support the operation.
483  */
484 unsigned int
485 rte_security_session_get_size(struct rte_security_ctx *instance);
486
487 /**
488  * Free security session header and the session private data and
489  * return it to its original mempool.
490  *
491  * @param   instance    security instance
492  * @param   sess        security session to be freed
493  *
494  * @return
495  *  - 0 if successful.
496  *  - -EINVAL if session or context instance is NULL.
497  *  - -EBUSY if not all device private data has been freed.
498  *  - -ENOTSUP if destroying private data is not supported.
499  *  - other negative values in case of freeing private data errors.
500  */
501 int
502 rte_security_session_destroy(struct rte_security_ctx *instance,
503                              struct rte_security_session *sess);
504
505 /** Device-specific metadata field type */
506 typedef uint64_t rte_security_dynfield_t;
507 /** Dynamic mbuf field for device-specific metadata */
508 extern int rte_security_dynfield_offset;
509
510 /**
511  * @warning
512  * @b EXPERIMENTAL: this API may change without prior notice
513  *
514  * Get pointer to mbuf field for device-specific metadata.
515  *
516  * For performance reason, no check is done,
517  * the dynamic field may not be registered.
518  * @see rte_security_dynfield_is_registered
519  *
520  * @param       mbuf    packet to access
521  * @return pointer to mbuf field
522  */
523 __rte_experimental
524 static inline rte_security_dynfield_t *
525 rte_security_dynfield(struct rte_mbuf *mbuf)
526 {
527         return RTE_MBUF_DYNFIELD(mbuf,
528                 rte_security_dynfield_offset,
529                 rte_security_dynfield_t *);
530 }
531
532 /**
533  * @warning
534  * @b EXPERIMENTAL: this API may change without prior notice
535  *
536  * Check whether the dynamic field is registered.
537  *
538  * @return true if rte_security_dynfield_register() has been called.
539  */
540 __rte_experimental
541 static inline bool rte_security_dynfield_is_registered(void)
542 {
543         return rte_security_dynfield_offset >= 0;
544 }
545
546 /** Function to call PMD specific function pointer set_pkt_metadata() */
547 __rte_experimental
548 extern int __rte_security_set_pkt_metadata(struct rte_security_ctx *instance,
549                                            struct rte_security_session *sess,
550                                            struct rte_mbuf *m, void *params);
551
552 /**
553  *  Updates the buffer with device-specific defined metadata
554  *
555  * @param       instance        security instance
556  * @param       sess            security session
557  * @param       mb              packet mbuf to set metadata on.
558  * @param       params          device-specific defined parameters
559  *                              required for metadata
560  *
561  * @return
562  *  - On success, zero.
563  *  - On failure, a negative value.
564  */
565 static inline int
566 rte_security_set_pkt_metadata(struct rte_security_ctx *instance,
567                               struct rte_security_session *sess,
568                               struct rte_mbuf *mb, void *params)
569 {
570         /* Fast Path */
571         if (instance->flags & RTE_SEC_CTX_F_FAST_SET_MDATA) {
572                 *rte_security_dynfield(mb) =
573                         (rte_security_dynfield_t)(sess->sess_private_data);
574                 return 0;
575         }
576
577         /* Jump to PMD specific function pointer */
578         return __rte_security_set_pkt_metadata(instance, sess, mb, params);
579 }
580
581 /** Function to call PMD specific function pointer get_userdata() */
582 __rte_experimental
583 extern void *__rte_security_get_userdata(struct rte_security_ctx *instance,
584                                          uint64_t md);
585
586 /**
587  * Get userdata associated with the security session. Device specific metadata
588  * provided would be used to uniquely identify the security session being
589  * referred to. This userdata would be registered while creating the session,
590  * and application can use this to identify the SA etc.
591  *
592  * Device specific metadata would be set in mbuf for inline processed inbound
593  * packets. In addition, the same metadata would be set for IPsec events
594  * reported by rte_eth_event framework.
595  *
596  * @param   instance    security instance
597  * @param   md          device-specific metadata
598  *
599  * @return
600  *  - On success, userdata
601  *  - On failure, NULL
602  */
603 __rte_experimental
604 static inline void *
605 rte_security_get_userdata(struct rte_security_ctx *instance, uint64_t md)
606 {
607         /* Fast Path */
608         if (instance->flags & RTE_SEC_CTX_F_FAST_GET_UDATA)
609                 return (void *)(uintptr_t)md;
610
611         /* Jump to PMD specific function pointer */
612         return __rte_security_get_userdata(instance, md);
613 }
614
615 /**
616  * Attach a session to a symmetric crypto operation
617  *
618  * @param       sym_op  crypto operation
619  * @param       sess    security session
620  */
621 static inline int
622 __rte_security_attach_session(struct rte_crypto_sym_op *sym_op,
623                               struct rte_security_session *sess)
624 {
625         sym_op->sec_session = sess;
626
627         return 0;
628 }
629
630 static inline void *
631 get_sec_session_private_data(const struct rte_security_session *sess)
632 {
633         return sess->sess_private_data;
634 }
635
636 static inline void
637 set_sec_session_private_data(struct rte_security_session *sess,
638                              void *private_data)
639 {
640         sess->sess_private_data = private_data;
641 }
642
643 /**
644  * Attach a session to a crypto operation.
645  * This API is needed only in case of RTE_SECURITY_SESS_CRYPTO_PROTO_OFFLOAD
646  * For other rte_security_session_action_type, ol_flags in rte_mbuf may be
647  * defined to perform security operations.
648  *
649  * @param       op      crypto operation
650  * @param       sess    security session
651  */
652 static inline int
653 rte_security_attach_session(struct rte_crypto_op *op,
654                             struct rte_security_session *sess)
655 {
656         if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC))
657                 return -EINVAL;
658
659         op->sess_type =  RTE_CRYPTO_OP_SECURITY_SESSION;
660
661         return __rte_security_attach_session(op->sym, sess);
662 }
663
664 struct rte_security_macsec_stats {
665         uint64_t reserved;
666 };
667
668 struct rte_security_ipsec_stats {
669         uint64_t ipackets;  /**< Successfully received IPsec packets. */
670         uint64_t opackets;  /**< Successfully transmitted IPsec packets.*/
671         uint64_t ibytes;    /**< Successfully received IPsec bytes. */
672         uint64_t obytes;    /**< Successfully transmitted IPsec bytes. */
673         uint64_t ierrors;   /**< IPsec packets receive/decrypt errors. */
674         uint64_t oerrors;   /**< IPsec packets transmit/encrypt errors. */
675         uint64_t reserved1; /**< Reserved for future use. */
676         uint64_t reserved2; /**< Reserved for future use. */
677 };
678
679 struct rte_security_pdcp_stats {
680         uint64_t reserved;
681 };
682
683 struct rte_security_docsis_stats {
684         uint64_t reserved;
685 };
686
687 struct rte_security_stats {
688         enum rte_security_session_protocol protocol;
689         /**< Security protocol to be configured */
690
691         RTE_STD_C11
692         union {
693                 struct rte_security_macsec_stats macsec;
694                 struct rte_security_ipsec_stats ipsec;
695                 struct rte_security_pdcp_stats pdcp;
696                 struct rte_security_docsis_stats docsis;
697         };
698 };
699
700 /**
701  * Get security session statistics
702  *
703  * @param       instance        security instance
704  * @param       sess            security session
705  * If security session is NULL then global (per security instance) statistics
706  * will be retrieved, if supported. Global statistics collection is not
707  * dependent on the per session statistics configuration.
708  * @param       stats           statistics
709  * @return
710  *  - On success, return 0
711  *  - On failure, a negative value
712  */
713 __rte_experimental
714 int
715 rte_security_session_stats_get(struct rte_security_ctx *instance,
716                                struct rte_security_session *sess,
717                                struct rte_security_stats *stats);
718
719 /**
720  * Security capability definition
721  */
722 struct rte_security_capability {
723         enum rte_security_session_action_type action;
724         /**< Security action type*/
725         enum rte_security_session_protocol protocol;
726         /**< Security protocol */
727         RTE_STD_C11
728         union {
729                 struct {
730                         enum rte_security_ipsec_sa_protocol proto;
731                         /**< IPsec SA protocol */
732                         enum rte_security_ipsec_sa_mode mode;
733                         /**< IPsec SA mode */
734                         enum rte_security_ipsec_sa_direction direction;
735                         /**< IPsec SA direction */
736                         struct rte_security_ipsec_sa_options options;
737                         /**< IPsec SA supported options */
738                         uint32_t replay_win_sz_max;
739                         /**< IPsec Anti Replay Window Size. A '0' value
740                          * indicates that Anti Replay is not supported.
741                          */
742                 } ipsec;
743                 /**< IPsec capability */
744                 struct {
745                         /* To be Filled */
746                         int dummy;
747                 } macsec;
748                 /**< MACsec capability */
749                 struct {
750                         enum rte_security_pdcp_domain domain;
751                         /**< PDCP mode of operation: Control or data */
752                         uint32_t capa_flags;
753                         /**< Capability flags, see RTE_SECURITY_PDCP_* */
754                 } pdcp;
755                 /**< PDCP capability */
756                 struct {
757                         enum rte_security_docsis_direction direction;
758                         /**< DOCSIS direction */
759                 } docsis;
760                 /**< DOCSIS capability */
761         };
762
763         const struct rte_cryptodev_capabilities *crypto_capabilities;
764         /**< Corresponding crypto capabilities for security capability  */
765
766         uint32_t ol_flags;
767         /**< Device offload flags */
768 };
769
770 /** Underlying Hardware/driver which support PDCP may or may not support
771  * packet ordering. Set RTE_SECURITY_PDCP_ORDERING_CAP if it support.
772  * If it is not set, driver/HW assumes packets received are in order
773  * and it will be application's responsibility to maintain ordering.
774  */
775 #define RTE_SECURITY_PDCP_ORDERING_CAP          0x00000001
776
777 /** Underlying Hardware/driver which support PDCP may or may not detect
778  * duplicate packet. Set RTE_SECURITY_PDCP_DUP_DETECT_CAP if it support.
779  * If it is not set, driver/HW assumes there is no duplicate packet received.
780  */
781 #define RTE_SECURITY_PDCP_DUP_DETECT_CAP        0x00000002
782
783 #define RTE_SECURITY_TX_OLOAD_NEED_MDATA        0x00000001
784 /**< HW needs metadata update, see rte_security_set_pkt_metadata().
785  */
786
787 #define RTE_SECURITY_TX_HW_TRAILER_OFFLOAD      0x00000002
788 /**< HW constructs trailer of packets
789  * Transmitted packets will have the trailer added to them
790  * by hardware. The next protocol field will be based on
791  * the mbuf->inner_esp_next_proto field.
792  */
793 #define RTE_SECURITY_RX_HW_TRAILER_OFFLOAD      0x00010000
794 /**< HW removes trailer of packets
795  * Received packets have no trailer, the next protocol field
796  * is supplied in the mbuf->inner_esp_next_proto field.
797  * Inner packet is not modified.
798  */
799
800 /**
801  * Security capability index used to query a security instance for a specific
802  * security capability
803  */
804 struct rte_security_capability_idx {
805         enum rte_security_session_action_type action;
806         enum rte_security_session_protocol protocol;
807
808         RTE_STD_C11
809         union {
810                 struct {
811                         enum rte_security_ipsec_sa_protocol proto;
812                         enum rte_security_ipsec_sa_mode mode;
813                         enum rte_security_ipsec_sa_direction direction;
814                 } ipsec;
815                 struct {
816                         enum rte_security_pdcp_domain domain;
817                         uint32_t capa_flags;
818                 } pdcp;
819                 struct {
820                         enum rte_security_docsis_direction direction;
821                 } docsis;
822         };
823 };
824
825 /**
826  *  Returns array of security instance capabilities
827  *
828  * @param       instance        Security instance.
829  *
830  * @return
831  *   - Returns array of security capabilities.
832  *   - Return NULL if no capabilities available.
833  */
834 const struct rte_security_capability *
835 rte_security_capabilities_get(struct rte_security_ctx *instance);
836
837 /**
838  * Query if a specific capability is available on security instance
839  *
840  * @param       instance        security instance.
841  * @param       idx             security capability index to match against
842  *
843  * @return
844  *   - Returns pointer to security capability on match of capability
845  *     index criteria.
846  *   - Return NULL if the capability not matched on security instance.
847  */
848 const struct rte_security_capability *
849 rte_security_capability_get(struct rte_security_ctx *instance,
850                             struct rte_security_capability_idx *idx);
851
852 #ifdef __cplusplus
853 }
854 #endif
855
856 #endif /* _RTE_SECURITY_H_ */