security: support user-specified IV
[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  * IPsec security association configuration data.
221  *
222  * This structure contains data required to create an IPsec SA security session.
223  */
224 struct rte_security_ipsec_xform {
225         uint32_t spi;
226         /**< SA security parameter index */
227         uint32_t salt;
228         /**< SA salt */
229         struct rte_security_ipsec_sa_options options;
230         /**< various SA options */
231         enum rte_security_ipsec_sa_direction direction;
232         /**< IPSec SA Direction - Egress/Ingress */
233         enum rte_security_ipsec_sa_protocol proto;
234         /**< IPsec SA Protocol - AH/ESP */
235         enum rte_security_ipsec_sa_mode mode;
236         /**< IPsec SA Mode - transport/tunnel */
237         struct rte_security_ipsec_tunnel_param tunnel;
238         /**< Tunnel parameters, NULL for transport mode */
239         uint64_t esn_soft_limit;
240         /**< ESN for which the overflow event need to be raised */
241         uint32_t replay_win_sz;
242         /**< Anti replay window size to enable sequence replay attack handling.
243          * replay checking is disabled if the window size is 0.
244          */
245 };
246
247 /**
248  * MACsec security session configuration
249  */
250 struct rte_security_macsec_xform {
251         /** To be Filled */
252         int dummy;
253 };
254
255 /**
256  * PDCP Mode of session
257  */
258 enum rte_security_pdcp_domain {
259         RTE_SECURITY_PDCP_MODE_CONTROL, /**< PDCP control plane */
260         RTE_SECURITY_PDCP_MODE_DATA,    /**< PDCP data plane */
261         RTE_SECURITY_PDCP_MODE_SHORT_MAC,       /**< PDCP short mac */
262 };
263
264 /** PDCP Frame direction */
265 enum rte_security_pdcp_direction {
266         RTE_SECURITY_PDCP_UPLINK,       /**< Uplink */
267         RTE_SECURITY_PDCP_DOWNLINK,     /**< Downlink */
268 };
269
270 /** PDCP Sequence Number Size selectors */
271 enum rte_security_pdcp_sn_size {
272         /** PDCP_SN_SIZE_5: 5bit sequence number */
273         RTE_SECURITY_PDCP_SN_SIZE_5 = 5,
274         /** PDCP_SN_SIZE_7: 7bit sequence number */
275         RTE_SECURITY_PDCP_SN_SIZE_7 = 7,
276         /** PDCP_SN_SIZE_12: 12bit sequence number */
277         RTE_SECURITY_PDCP_SN_SIZE_12 = 12,
278         /** PDCP_SN_SIZE_15: 15bit sequence number */
279         RTE_SECURITY_PDCP_SN_SIZE_15 = 15,
280         /** PDCP_SN_SIZE_18: 18bit sequence number */
281         RTE_SECURITY_PDCP_SN_SIZE_18 = 18
282 };
283
284 /**
285  * PDCP security association configuration data.
286  *
287  * This structure contains data required to create a PDCP security session.
288  */
289 struct rte_security_pdcp_xform {
290         int8_t bearer;  /**< PDCP bearer ID */
291         /** Enable in order delivery, this field shall be set only if
292          * driver/HW is capable. See RTE_SECURITY_PDCP_ORDERING_CAP.
293          */
294         uint8_t en_ordering;
295         /** Notify driver/HW to detect and remove duplicate packets.
296          * This field should be set only when driver/hw is capable.
297          * See RTE_SECURITY_PDCP_DUP_DETECT_CAP.
298          */
299         uint8_t remove_duplicates;
300         /** PDCP mode of operation: Control or data */
301         enum rte_security_pdcp_domain domain;
302         /** PDCP Frame Direction 0:UL 1:DL */
303         enum rte_security_pdcp_direction pkt_dir;
304         /** Sequence number size, 5/7/12/15/18 */
305         enum rte_security_pdcp_sn_size sn_size;
306         /** Starting Hyper Frame Number to be used together with the SN
307          * from the PDCP frames
308          */
309         uint32_t hfn;
310         /** HFN Threshold for key renegotiation */
311         uint32_t hfn_threshold;
312         /** HFN can be given as a per packet value also.
313          * As we do not have IV in case of PDCP, and HFN is
314          * used to generate IV. IV field can be used to get the
315          * per packet HFN while enq/deq.
316          * If hfn_ovrd field is set, user is expected to set the
317          * per packet HFN in place of IV. PMDs will extract the HFN
318          * and perform operations accordingly.
319          */
320         uint8_t hfn_ovrd;
321         /** In case of 5G NR, a new protocol (SDAP) header may be set
322          * inside PDCP payload which should be authenticated but not
323          * encrypted. Hence, driver should be notified if SDAP is
324          * enabled or not, so that SDAP header is not encrypted.
325          */
326         uint8_t sdap_enabled;
327         /** Reserved for future */
328         uint16_t reserved;
329 };
330
331 /** DOCSIS direction */
332 enum rte_security_docsis_direction {
333         RTE_SECURITY_DOCSIS_UPLINK,
334         /**< Uplink
335          * - Decryption, followed by CRC Verification
336          */
337         RTE_SECURITY_DOCSIS_DOWNLINK,
338         /**< Downlink
339          * - CRC Generation, followed by Encryption
340          */
341 };
342
343 /**
344  * DOCSIS security session configuration.
345  *
346  * This structure contains data required to create a DOCSIS security session.
347  */
348 struct rte_security_docsis_xform {
349         enum rte_security_docsis_direction direction;
350         /**< DOCSIS direction */
351 };
352
353 /**
354  * Security session action type.
355  */
356 enum rte_security_session_action_type {
357         RTE_SECURITY_ACTION_TYPE_NONE,
358         /**< No security actions */
359         RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
360         /**< Crypto processing for security protocol is processed inline
361          * during transmission
362          */
363         RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
364         /**< All security protocol processing is performed inline during
365          * transmission
366          */
367         RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
368         /**< All security protocol processing including crypto is performed
369          * on a lookaside accelerator
370          */
371         RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO
372         /**< Similar to ACTION_TYPE_NONE but crypto processing for security
373          * protocol is processed synchronously by a CPU.
374          */
375 };
376
377 /** Security session protocol definition */
378 enum rte_security_session_protocol {
379         RTE_SECURITY_PROTOCOL_IPSEC = 1,
380         /**< IPsec Protocol */
381         RTE_SECURITY_PROTOCOL_MACSEC,
382         /**< MACSec Protocol */
383         RTE_SECURITY_PROTOCOL_PDCP,
384         /**< PDCP Protocol */
385         RTE_SECURITY_PROTOCOL_DOCSIS,
386         /**< DOCSIS Protocol */
387 };
388
389 /**
390  * Security session configuration
391  */
392 struct rte_security_session_conf {
393         enum rte_security_session_action_type action_type;
394         /**< Type of action to be performed on the session */
395         enum rte_security_session_protocol protocol;
396         /**< Security protocol to be configured */
397         RTE_STD_C11
398         union {
399                 struct rte_security_ipsec_xform ipsec;
400                 struct rte_security_macsec_xform macsec;
401                 struct rte_security_pdcp_xform pdcp;
402                 struct rte_security_docsis_xform docsis;
403         };
404         /**< Configuration parameters for security session */
405         struct rte_crypto_sym_xform *crypto_xform;
406         /**< Security Session Crypto Transformations */
407         void *userdata;
408         /**< Application specific userdata to be saved with session */
409 };
410
411 struct rte_security_session {
412         void *sess_private_data;
413         /**< Private session material */
414         uint64_t opaque_data;
415         /**< Opaque user defined data */
416 };
417
418 /**
419  * Create security session as specified by the session configuration
420  *
421  * @param   instance    security instance
422  * @param   conf        session configuration parameters
423  * @param   mp          mempool to allocate session objects from
424  * @param   priv_mp     mempool to allocate session private data objects from
425  * @return
426  *  - On success, pointer to session
427  *  - On failure, NULL
428  */
429 struct rte_security_session *
430 rte_security_session_create(struct rte_security_ctx *instance,
431                             struct rte_security_session_conf *conf,
432                             struct rte_mempool *mp,
433                             struct rte_mempool *priv_mp);
434
435 /**
436  * Update security session as specified by the session configuration
437  *
438  * @param   instance    security instance
439  * @param   sess        session to update parameters
440  * @param   conf        update configuration parameters
441  * @return
442  *  - On success returns 0
443  *  - On failure returns a negative errno value.
444  */
445 __rte_experimental
446 int
447 rte_security_session_update(struct rte_security_ctx *instance,
448                             struct rte_security_session *sess,
449                             struct rte_security_session_conf *conf);
450
451 /**
452  * Get the size of the security session data for a device.
453  *
454  * @param   instance    security instance.
455  *
456  * @return
457  *   - Size of the private data, if successful
458  *   - 0 if device is invalid or does not support the operation.
459  */
460 unsigned int
461 rte_security_session_get_size(struct rte_security_ctx *instance);
462
463 /**
464  * Free security session header and the session private data and
465  * return it to its original mempool.
466  *
467  * @param   instance    security instance
468  * @param   sess        security session to be freed
469  *
470  * @return
471  *  - 0 if successful.
472  *  - -EINVAL if session or context instance is NULL.
473  *  - -EBUSY if not all device private data has been freed.
474  *  - -ENOTSUP if destroying private data is not supported.
475  *  - other negative values in case of freeing private data errors.
476  */
477 int
478 rte_security_session_destroy(struct rte_security_ctx *instance,
479                              struct rte_security_session *sess);
480
481 /** Device-specific metadata field type */
482 typedef uint64_t rte_security_dynfield_t;
483 /** Dynamic mbuf field for device-specific metadata */
484 extern int rte_security_dynfield_offset;
485
486 /**
487  * @warning
488  * @b EXPERIMENTAL: this API may change without prior notice
489  *
490  * Get pointer to mbuf field for device-specific metadata.
491  *
492  * For performance reason, no check is done,
493  * the dynamic field may not be registered.
494  * @see rte_security_dynfield_is_registered
495  *
496  * @param       mbuf    packet to access
497  * @return pointer to mbuf field
498  */
499 __rte_experimental
500 static inline rte_security_dynfield_t *
501 rte_security_dynfield(struct rte_mbuf *mbuf)
502 {
503         return RTE_MBUF_DYNFIELD(mbuf,
504                 rte_security_dynfield_offset,
505                 rte_security_dynfield_t *);
506 }
507
508 /**
509  * @warning
510  * @b EXPERIMENTAL: this API may change without prior notice
511  *
512  * Check whether the dynamic field is registered.
513  *
514  * @return true if rte_security_dynfield_register() has been called.
515  */
516 __rte_experimental
517 static inline bool rte_security_dynfield_is_registered(void)
518 {
519         return rte_security_dynfield_offset >= 0;
520 }
521
522 /** Function to call PMD specific function pointer set_pkt_metadata() */
523 __rte_experimental
524 extern int __rte_security_set_pkt_metadata(struct rte_security_ctx *instance,
525                                            struct rte_security_session *sess,
526                                            struct rte_mbuf *m, void *params);
527
528 /**
529  *  Updates the buffer with device-specific defined metadata
530  *
531  * @param       instance        security instance
532  * @param       sess            security session
533  * @param       mb              packet mbuf to set metadata on.
534  * @param       params          device-specific defined parameters
535  *                              required for metadata
536  *
537  * @return
538  *  - On success, zero.
539  *  - On failure, a negative value.
540  */
541 static inline int
542 rte_security_set_pkt_metadata(struct rte_security_ctx *instance,
543                               struct rte_security_session *sess,
544                               struct rte_mbuf *mb, void *params)
545 {
546         /* Fast Path */
547         if (instance->flags & RTE_SEC_CTX_F_FAST_SET_MDATA) {
548                 *rte_security_dynfield(mb) =
549                         (rte_security_dynfield_t)(sess->sess_private_data);
550                 return 0;
551         }
552
553         /* Jump to PMD specific function pointer */
554         return __rte_security_set_pkt_metadata(instance, sess, mb, params);
555 }
556
557 /** Function to call PMD specific function pointer get_userdata() */
558 __rte_experimental
559 extern void *__rte_security_get_userdata(struct rte_security_ctx *instance,
560                                          uint64_t md);
561
562 /**
563  * Get userdata associated with the security session. Device specific metadata
564  * provided would be used to uniquely identify the security session being
565  * referred to. This userdata would be registered while creating the session,
566  * and application can use this to identify the SA etc.
567  *
568  * Device specific metadata would be set in mbuf for inline processed inbound
569  * packets. In addition, the same metadata would be set for IPsec events
570  * reported by rte_eth_event framework.
571  *
572  * @param   instance    security instance
573  * @param   md          device-specific metadata
574  *
575  * @return
576  *  - On success, userdata
577  *  - On failure, NULL
578  */
579 __rte_experimental
580 static inline void *
581 rte_security_get_userdata(struct rte_security_ctx *instance, uint64_t md)
582 {
583         /* Fast Path */
584         if (instance->flags & RTE_SEC_CTX_F_FAST_GET_UDATA)
585                 return (void *)(uintptr_t)md;
586
587         /* Jump to PMD specific function pointer */
588         return __rte_security_get_userdata(instance, md);
589 }
590
591 /**
592  * Attach a session to a symmetric crypto operation
593  *
594  * @param       sym_op  crypto operation
595  * @param       sess    security session
596  */
597 static inline int
598 __rte_security_attach_session(struct rte_crypto_sym_op *sym_op,
599                               struct rte_security_session *sess)
600 {
601         sym_op->sec_session = sess;
602
603         return 0;
604 }
605
606 static inline void *
607 get_sec_session_private_data(const struct rte_security_session *sess)
608 {
609         return sess->sess_private_data;
610 }
611
612 static inline void
613 set_sec_session_private_data(struct rte_security_session *sess,
614                              void *private_data)
615 {
616         sess->sess_private_data = private_data;
617 }
618
619 /**
620  * Attach a session to a crypto operation.
621  * This API is needed only in case of RTE_SECURITY_SESS_CRYPTO_PROTO_OFFLOAD
622  * For other rte_security_session_action_type, ol_flags in rte_mbuf may be
623  * defined to perform security operations.
624  *
625  * @param       op      crypto operation
626  * @param       sess    security session
627  */
628 static inline int
629 rte_security_attach_session(struct rte_crypto_op *op,
630                             struct rte_security_session *sess)
631 {
632         if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC))
633                 return -EINVAL;
634
635         op->sess_type =  RTE_CRYPTO_OP_SECURITY_SESSION;
636
637         return __rte_security_attach_session(op->sym, sess);
638 }
639
640 struct rte_security_macsec_stats {
641         uint64_t reserved;
642 };
643
644 struct rte_security_ipsec_stats {
645         uint64_t ipackets;  /**< Successfully received IPsec packets. */
646         uint64_t opackets;  /**< Successfully transmitted IPsec packets.*/
647         uint64_t ibytes;    /**< Successfully received IPsec bytes. */
648         uint64_t obytes;    /**< Successfully transmitted IPsec bytes. */
649         uint64_t ierrors;   /**< IPsec packets receive/decrypt errors. */
650         uint64_t oerrors;   /**< IPsec packets transmit/encrypt errors. */
651         uint64_t reserved1; /**< Reserved for future use. */
652         uint64_t reserved2; /**< Reserved for future use. */
653 };
654
655 struct rte_security_pdcp_stats {
656         uint64_t reserved;
657 };
658
659 struct rte_security_docsis_stats {
660         uint64_t reserved;
661 };
662
663 struct rte_security_stats {
664         enum rte_security_session_protocol protocol;
665         /**< Security protocol to be configured */
666
667         RTE_STD_C11
668         union {
669                 struct rte_security_macsec_stats macsec;
670                 struct rte_security_ipsec_stats ipsec;
671                 struct rte_security_pdcp_stats pdcp;
672                 struct rte_security_docsis_stats docsis;
673         };
674 };
675
676 /**
677  * Get security session statistics
678  *
679  * @param       instance        security instance
680  * @param       sess            security session
681  * If security session is NULL then global (per security instance) statistics
682  * will be retrieved, if supported. Global statistics collection is not
683  * dependent on the per session statistics configuration.
684  * @param       stats           statistics
685  * @return
686  *  - On success, return 0
687  *  - On failure, a negative value
688  */
689 __rte_experimental
690 int
691 rte_security_session_stats_get(struct rte_security_ctx *instance,
692                                struct rte_security_session *sess,
693                                struct rte_security_stats *stats);
694
695 /**
696  * Security capability definition
697  */
698 struct rte_security_capability {
699         enum rte_security_session_action_type action;
700         /**< Security action type*/
701         enum rte_security_session_protocol protocol;
702         /**< Security protocol */
703         RTE_STD_C11
704         union {
705                 struct {
706                         enum rte_security_ipsec_sa_protocol proto;
707                         /**< IPsec SA protocol */
708                         enum rte_security_ipsec_sa_mode mode;
709                         /**< IPsec SA mode */
710                         enum rte_security_ipsec_sa_direction direction;
711                         /**< IPsec SA direction */
712                         struct rte_security_ipsec_sa_options options;
713                         /**< IPsec SA supported options */
714                         uint32_t replay_win_sz_max;
715                         /**< IPsec Anti Replay Window Size. A '0' value
716                          * indicates that Anti Replay is not supported.
717                          */
718                 } ipsec;
719                 /**< IPsec capability */
720                 struct {
721                         /* To be Filled */
722                         int dummy;
723                 } macsec;
724                 /**< MACsec capability */
725                 struct {
726                         enum rte_security_pdcp_domain domain;
727                         /**< PDCP mode of operation: Control or data */
728                         uint32_t capa_flags;
729                         /**< Capability flags, see RTE_SECURITY_PDCP_* */
730                 } pdcp;
731                 /**< PDCP capability */
732                 struct {
733                         enum rte_security_docsis_direction direction;
734                         /**< DOCSIS direction */
735                 } docsis;
736                 /**< DOCSIS capability */
737         };
738
739         const struct rte_cryptodev_capabilities *crypto_capabilities;
740         /**< Corresponding crypto capabilities for security capability  */
741
742         uint32_t ol_flags;
743         /**< Device offload flags */
744 };
745
746 /** Underlying Hardware/driver which support PDCP may or may not support
747  * packet ordering. Set RTE_SECURITY_PDCP_ORDERING_CAP if it support.
748  * If it is not set, driver/HW assumes packets received are in order
749  * and it will be application's responsibility to maintain ordering.
750  */
751 #define RTE_SECURITY_PDCP_ORDERING_CAP          0x00000001
752
753 /** Underlying Hardware/driver which support PDCP may or may not detect
754  * duplicate packet. Set RTE_SECURITY_PDCP_DUP_DETECT_CAP if it support.
755  * If it is not set, driver/HW assumes there is no duplicate packet received.
756  */
757 #define RTE_SECURITY_PDCP_DUP_DETECT_CAP        0x00000002
758
759 #define RTE_SECURITY_TX_OLOAD_NEED_MDATA        0x00000001
760 /**< HW needs metadata update, see rte_security_set_pkt_metadata().
761  */
762
763 #define RTE_SECURITY_TX_HW_TRAILER_OFFLOAD      0x00000002
764 /**< HW constructs trailer of packets
765  * Transmitted packets will have the trailer added to them
766  * by hardware. The next protocol field will be based on
767  * the mbuf->inner_esp_next_proto field.
768  */
769 #define RTE_SECURITY_RX_HW_TRAILER_OFFLOAD      0x00010000
770 /**< HW removes trailer of packets
771  * Received packets have no trailer, the next protocol field
772  * is supplied in the mbuf->inner_esp_next_proto field.
773  * Inner packet is not modified.
774  */
775
776 /**
777  * Security capability index used to query a security instance for a specific
778  * security capability
779  */
780 struct rte_security_capability_idx {
781         enum rte_security_session_action_type action;
782         enum rte_security_session_protocol protocol;
783
784         RTE_STD_C11
785         union {
786                 struct {
787                         enum rte_security_ipsec_sa_protocol proto;
788                         enum rte_security_ipsec_sa_mode mode;
789                         enum rte_security_ipsec_sa_direction direction;
790                 } ipsec;
791                 struct {
792                         enum rte_security_pdcp_domain domain;
793                         uint32_t capa_flags;
794                 } pdcp;
795                 struct {
796                         enum rte_security_docsis_direction direction;
797                 } docsis;
798         };
799 };
800
801 /**
802  *  Returns array of security instance capabilities
803  *
804  * @param       instance        Security instance.
805  *
806  * @return
807  *   - Returns array of security capabilities.
808  *   - Return NULL if no capabilities available.
809  */
810 const struct rte_security_capability *
811 rte_security_capabilities_get(struct rte_security_ctx *instance);
812
813 /**
814  * Query if a specific capability is available on security instance
815  *
816  * @param       instance        security instance.
817  * @param       idx             security capability index to match against
818  *
819  * @return
820  *   - Returns pointer to security capability on match of capability
821  *     index criteria.
822  *   - Return NULL if the capability not matched on security instance.
823  */
824 const struct rte_security_capability *
825 rte_security_capability_get(struct rte_security_ctx *instance,
826                             struct rte_security_capability_idx *idx);
827
828 #ifdef __cplusplus
829 }
830 #endif
831
832 #endif /* _RTE_SECURITY_H_ */