xref: /dpdk/doc/guides/prog_guide/rte_security.rst (revision 1a08c379b9b5edeb0214378daa3fb2e56fba49ba)
1d81734caSHemant Agrawal..  SPDX-License-Identifier: BSD-3-Clause
2d81734caSHemant Agrawal    Copyright 2017 NXP
340ff8c99SAkhil Goyal
440ff8c99SAkhil Goyal
540ff8c99SAkhil Goyal
640ff8c99SAkhil GoyalSecurity Library
740ff8c99SAkhil Goyal================
840ff8c99SAkhil Goyal
940ff8c99SAkhil GoyalThe security library provides a framework for management and provisioning
1040ff8c99SAkhil Goyalof security protocol operations offloaded to hardware based devices. The
1140ff8c99SAkhil Goyallibrary defines generic APIs to create and free security sessions which can
1240ff8c99SAkhil Goyalsupport full protocol offload as well as inline crypto operation with
1340ff8c99SAkhil GoyalNIC or crypto devices. The framework currently only supports the IPSec protocol
1440ff8c99SAkhil Goyaland associated operations, other protocols will be added in future.
1540ff8c99SAkhil Goyal
1640ff8c99SAkhil GoyalDesign Principles
1740ff8c99SAkhil Goyal-----------------
1840ff8c99SAkhil Goyal
1940ff8c99SAkhil GoyalThe security library provides an additional offload capability to an existing
2040ff8c99SAkhil Goyalcrypto device and/or ethernet device.
2140ff8c99SAkhil Goyal
2240ff8c99SAkhil Goyal.. code-block:: console
2340ff8c99SAkhil Goyal
2440ff8c99SAkhil Goyal               +---------------+
2540ff8c99SAkhil Goyal               | rte_security  |
2640ff8c99SAkhil Goyal               +---------------+
2740ff8c99SAkhil Goyal                 \            /
2840ff8c99SAkhil Goyal        +-----------+    +--------------+
2940ff8c99SAkhil Goyal        |  NIC PMD  |    |  CRYPTO PMD  |
3040ff8c99SAkhil Goyal        +-----------+    +--------------+
3140ff8c99SAkhil Goyal
3240ff8c99SAkhil Goyal.. note::
3340ff8c99SAkhil Goyal
3440ff8c99SAkhil Goyal    Currently, the security library does not support the case of multi-process.
3540ff8c99SAkhil Goyal    It will be updated in the future releases.
3640ff8c99SAkhil Goyal
3740ff8c99SAkhil GoyalThe supported offload types are explained in the sections below.
3840ff8c99SAkhil Goyal
3940ff8c99SAkhil GoyalInline Crypto
4040ff8c99SAkhil Goyal~~~~~~~~~~~~~
4140ff8c99SAkhil Goyal
4240ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO:
4340ff8c99SAkhil GoyalThe crypto processing for security protocol (e.g. IPSec) is processed
4440ff8c99SAkhil Goyalinline during receive and transmission on NIC port. The flow based
4540ff8c99SAkhil Goyalsecurity action should be configured on the port.
4640ff8c99SAkhil Goyal
4740ff8c99SAkhil GoyalIngress Data path - The packet is decrypted in RX path and relevant
4840ff8c99SAkhil Goyalcrypto status is set in Rx descriptors. After the successful inline
4940ff8c99SAkhil Goyalcrypto processing the packet is presented to host as a regular Rx packet
5040ff8c99SAkhil Goyalhowever all security protocol related headers are still attached to the
5140ff8c99SAkhil Goyalpacket. e.g. In case of IPSec, the IPSec tunnel headers (if any),
5240ff8c99SAkhil GoyalESP/AH headers will remain in the packet but the received packet
5340ff8c99SAkhil Goyalcontains the decrypted data where the encrypted data was when the packet
5440ff8c99SAkhil Goyalarrived. The driver Rx path check the descriptors and and based on the
5540ff8c99SAkhil Goyalcrypto status sets additional flags in the rte_mbuf.ol_flags field.
5640ff8c99SAkhil Goyal
5740ff8c99SAkhil Goyal.. note::
5840ff8c99SAkhil Goyal
5940ff8c99SAkhil Goyal    The underlying device may not support crypto processing for all ingress packet
6040ff8c99SAkhil Goyal    matching to a particular flow (e.g. fragmented packets), such packets will
6140ff8c99SAkhil Goyal    be passed as encrypted packets. It is the responsibility of application to
6240ff8c99SAkhil Goyal    process such encrypted packets using other crypto driver instance.
6340ff8c99SAkhil Goyal
6440ff8c99SAkhil GoyalEgress Data path - The software prepares the egress packet by adding
6540ff8c99SAkhil Goyalrelevant security protocol headers. Only the data will not be
6640ff8c99SAkhil Goyalencrypted by the software. The driver will accordingly configure the
6740ff8c99SAkhil Goyaltx descriptors. The hardware device will encrypt the data before sending the
6840ff8c99SAkhil Goyalthe packet out.
6940ff8c99SAkhil Goyal
7040ff8c99SAkhil Goyal.. note::
7140ff8c99SAkhil Goyal
7240ff8c99SAkhil Goyal    The underlying device may support post encryption TSO.
7340ff8c99SAkhil Goyal
7440ff8c99SAkhil Goyal.. code-block:: console
7540ff8c99SAkhil Goyal
7640ff8c99SAkhil Goyal          Egress Data Path
7740ff8c99SAkhil Goyal                 |
7840ff8c99SAkhil Goyal        +--------|--------+
7940ff8c99SAkhil Goyal        |  egress IPsec   |
8040ff8c99SAkhil Goyal        |        |        |
8140ff8c99SAkhil Goyal        | +------V------+ |
8240ff8c99SAkhil Goyal        | | SADB lookup | |
8340ff8c99SAkhil Goyal        | +------|------+ |
8440ff8c99SAkhil Goyal        | +------V------+ |
8540ff8c99SAkhil Goyal        | |   Tunnel    | |   <------ Add tunnel header to packet
8640ff8c99SAkhil Goyal        | +------|------+ |
8740ff8c99SAkhil Goyal        | +------V------+ |
8840ff8c99SAkhil Goyal        | |     ESP     | |   <------ Add ESP header without trailer to packet
8940ff8c99SAkhil Goyal        | |             | |   <------ Mark packet to be offloaded, add trailer
9040ff8c99SAkhil Goyal        | +------|------+ |            meta-data to mbuf
9140ff8c99SAkhil Goyal        +--------V--------+
9240ff8c99SAkhil Goyal                 |
9340ff8c99SAkhil Goyal        +--------V--------+
9440ff8c99SAkhil Goyal        |    L2 Stack     |
9540ff8c99SAkhil Goyal        +--------|--------+
9640ff8c99SAkhil Goyal                 |
9740ff8c99SAkhil Goyal        +--------V--------+
9840ff8c99SAkhil Goyal        |                 |
9940ff8c99SAkhil Goyal        |     NIC PMD     |   <------ Set hw context for inline crypto offload
10040ff8c99SAkhil Goyal        |                 |
10140ff8c99SAkhil Goyal        +--------|--------+
10240ff8c99SAkhil Goyal                 |
10340ff8c99SAkhil Goyal        +--------|--------+
10440ff8c99SAkhil Goyal        |  HW ACCELERATED |   <------ Packet Encryption and
10540ff8c99SAkhil Goyal        |        NIC      |           Authentication happens inline
10640ff8c99SAkhil Goyal        |                 |
10740ff8c99SAkhil Goyal        +-----------------+
10840ff8c99SAkhil Goyal
10940ff8c99SAkhil Goyal
11040ff8c99SAkhil GoyalInline protocol offload
11140ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~
11240ff8c99SAkhil Goyal
11340ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL:
11440ff8c99SAkhil GoyalThe crypto and protocol processing for security protocol (e.g. IPSec)
11540ff8c99SAkhil Goyalis processed inline during receive and transmission.  The flow based
11640ff8c99SAkhil Goyalsecurity action should be configured on the port.
11740ff8c99SAkhil Goyal
11840ff8c99SAkhil GoyalIngress Data path - The packet is decrypted in the RX path and relevant
11940ff8c99SAkhil Goyalcrypto status is set in the Rx descriptors. After the successful inline
12040ff8c99SAkhil Goyalcrypto processing the packet is presented to the host as a regular Rx packet
12140ff8c99SAkhil Goyalbut all security protocol related headers are optionally removed from the
12240ff8c99SAkhil Goyalpacket. e.g. in the case of IPSec, the IPSec tunnel headers (if any),
12340ff8c99SAkhil GoyalESP/AH headers will be removed from the packet and the received packet
12440ff8c99SAkhil Goyalwill contains the decrypted packet only. The driver Rx path checks the
12540ff8c99SAkhil Goyaldescriptors and based on the crypto status sets additional flags in
126*1a08c379SAnoob Joseph``rte_mbuf.ol_flags`` field. The driver would also set device-specific
127*1a08c379SAnoob Josephmetadata in ``rte_mbuf.udata64`` field. This will allow the application
128*1a08c379SAnoob Josephto identify the security processing done on the packet.
12940ff8c99SAkhil Goyal
13040ff8c99SAkhil Goyal.. note::
13140ff8c99SAkhil Goyal
13240ff8c99SAkhil Goyal    The underlying device in this case is stateful. It is expected that
13340ff8c99SAkhil Goyal    the device shall support crypto processing for all kind of packets matching
13440ff8c99SAkhil Goyal    to a given flow, this includes fragmented packets (post reassembly).
13540ff8c99SAkhil Goyal    E.g. in case of IPSec the device may internally manage anti-replay etc.
13640ff8c99SAkhil Goyal    It will provide a configuration option for anti-replay behavior i.e. to drop
13740ff8c99SAkhil Goyal    the packets or pass them to driver with error flags set in the descriptor.
13840ff8c99SAkhil Goyal
13940ff8c99SAkhil GoyalEgress Data path - The software will send the plain packet without any
14040ff8c99SAkhil Goyalsecurity protocol headers added to the packet. The driver will configure
14140ff8c99SAkhil Goyalthe security index and other requirement in tx descriptors.
14240ff8c99SAkhil GoyalThe hardware device will do security processing on the packet that includes
14340ff8c99SAkhil Goyaladding the relevant protocol headers and encrypting the data before sending
14440ff8c99SAkhil Goyalthe packet out. The software should make sure that the buffer
14540ff8c99SAkhil Goyalhas required head room and tail room for any protocol header addition. The
14640ff8c99SAkhil Goyalsoftware may also do early fragmentation if the resultant packet is expected
14740ff8c99SAkhil Goyalto cross the MTU size.
14840ff8c99SAkhil Goyal
14940ff8c99SAkhil Goyal
15040ff8c99SAkhil Goyal.. note::
15140ff8c99SAkhil Goyal
15240ff8c99SAkhil Goyal    The underlying device will manage state information required for egress
15340ff8c99SAkhil Goyal    processing. E.g. in case of IPSec, the seq number will be added to the
15440ff8c99SAkhil Goyal    packet, however the device shall provide indication when the sequence number
15540ff8c99SAkhil Goyal    is about to overflow. The underlying device may support post encryption TSO.
15640ff8c99SAkhil Goyal
15740ff8c99SAkhil Goyal.. code-block:: console
15840ff8c99SAkhil Goyal
15940ff8c99SAkhil Goyal         Egress Data Path
16040ff8c99SAkhil Goyal                 |
16140ff8c99SAkhil Goyal        +--------|--------+
16240ff8c99SAkhil Goyal        |  egress IPsec   |
16340ff8c99SAkhil Goyal        |        |        |
16440ff8c99SAkhil Goyal        | +------V------+ |
16540ff8c99SAkhil Goyal        | | SADB lookup | |
16640ff8c99SAkhil Goyal        | +------|------+ |
16740ff8c99SAkhil Goyal        | +------V------+ |
16840ff8c99SAkhil Goyal        | |   Desc      | |   <------ Mark packet to be offloaded
16940ff8c99SAkhil Goyal        | +------|------+ |
17040ff8c99SAkhil Goyal        +--------V--------+
17140ff8c99SAkhil Goyal                 |
17240ff8c99SAkhil Goyal        +--------V--------+
17340ff8c99SAkhil Goyal        |    L2 Stack     |
17440ff8c99SAkhil Goyal        +--------|--------+
17540ff8c99SAkhil Goyal                 |
17640ff8c99SAkhil Goyal        +--------V--------+
17740ff8c99SAkhil Goyal        |                 |
17840ff8c99SAkhil Goyal        |     NIC PMD     |   <------ Set hw context for inline crypto offload
17940ff8c99SAkhil Goyal        |                 |
18040ff8c99SAkhil Goyal        +--------|--------+
18140ff8c99SAkhil Goyal                 |
18240ff8c99SAkhil Goyal        +--------|--------+
18340ff8c99SAkhil Goyal        |  HW ACCELERATED |   <------ Add tunnel, ESP header etc header to
18440ff8c99SAkhil Goyal        |        NIC      |           packet. Packet Encryption and
18540ff8c99SAkhil Goyal        |                 |           Authentication happens inline.
18640ff8c99SAkhil Goyal        +-----------------+
18740ff8c99SAkhil Goyal
18840ff8c99SAkhil Goyal
18940ff8c99SAkhil GoyalLookaside protocol offload
19040ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~
19140ff8c99SAkhil Goyal
19240ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL:
19340ff8c99SAkhil GoyalThis extends librte_cryptodev to support the programming of IPsec
19440ff8c99SAkhil GoyalSecurity Association (SA) as part of a crypto session creation including
19540ff8c99SAkhil Goyalthe definition. In addition to standard crypto processing, as defined by
19640ff8c99SAkhil Goyalthe cryptodev, the security protocol processing is also offloaded to the
19740ff8c99SAkhil Goyalcrypto device.
19840ff8c99SAkhil Goyal
19940ff8c99SAkhil GoyalDecryption: The packet is sent to the crypto device for security
20040ff8c99SAkhil Goyalprotocol processing. The device will decrypt the packet and it will also
20140ff8c99SAkhil Goyaloptionally remove additional security headers from the packet.
20240ff8c99SAkhil GoyalE.g. in case of IPSec, IPSec tunnel headers (if any), ESP/AH headers
20340ff8c99SAkhil Goyalwill be removed from the packet and the decrypted packet may contain
20440ff8c99SAkhil Goyalplain data only.
20540ff8c99SAkhil Goyal
20640ff8c99SAkhil Goyal.. note::
20740ff8c99SAkhil Goyal
20840ff8c99SAkhil Goyal    In case of IPSec the device may internally manage anti-replay etc.
20940ff8c99SAkhil Goyal    It will provide a configuration option for anti-replay behavior i.e. to drop
21040ff8c99SAkhil Goyal    the packets or pass them to driver with error flags set in descriptor.
21140ff8c99SAkhil Goyal
21240ff8c99SAkhil GoyalEncryption: The software will submit the packet to cryptodev as usual
21340ff8c99SAkhil Goyalfor encryption, the hardware device in this case will also add the relevant
21440ff8c99SAkhil Goyalsecurity protocol header along with encrypting the packet. The software
21540ff8c99SAkhil Goyalshould make sure that the buffer has required head room and tail room
21640ff8c99SAkhil Goyalfor any protocol header addition.
21740ff8c99SAkhil Goyal
21840ff8c99SAkhil Goyal.. note::
21940ff8c99SAkhil Goyal
22040ff8c99SAkhil Goyal    In the case of IPSec, the seq number will be added to the packet,
22140ff8c99SAkhil Goyal    It shall provide an indication when the sequence number is about to
22240ff8c99SAkhil Goyal    overflow.
22340ff8c99SAkhil Goyal
22440ff8c99SAkhil Goyal.. code-block:: console
22540ff8c99SAkhil Goyal
22640ff8c99SAkhil Goyal          Egress Data Path
22740ff8c99SAkhil Goyal                 |
22840ff8c99SAkhil Goyal        +--------|--------+
22940ff8c99SAkhil Goyal        |  egress IPsec   |
23040ff8c99SAkhil Goyal        |        |        |
23140ff8c99SAkhil Goyal        | +------V------+ |
23240ff8c99SAkhil Goyal        | | SADB lookup | |   <------ SA maps to cryptodev session
23340ff8c99SAkhil Goyal        | +------|------+ |
23440ff8c99SAkhil Goyal        | +------|------+ |
23540ff8c99SAkhil Goyal        | |      \--------------------\
23640ff8c99SAkhil Goyal        | |    Crypto   | |           |  <- Crypto processing through
23740ff8c99SAkhil Goyal        | |      /----------------\   |     inline crypto PMD
23840ff8c99SAkhil Goyal        | +------|------+ |       |   |
23940ff8c99SAkhil Goyal        +--------V--------+       |   |
24040ff8c99SAkhil Goyal                 |                |   |
24140ff8c99SAkhil Goyal        +--------V--------+       |   |  create   <-- SA is added to hw
24240ff8c99SAkhil Goyal        |    L2 Stack     |       |   |  inline       using existing create
24340ff8c99SAkhil Goyal        +--------|--------+       |   |  session      sym session APIs
24440ff8c99SAkhil Goyal                 |                |   |    |
24540ff8c99SAkhil Goyal        +--------V--------+   +---|---|----V---+
24640ff8c99SAkhil Goyal        |                 |   |   \---/    |   | <--- Add tunnel, ESP header etc
24740ff8c99SAkhil Goyal        |     NIC PMD     |   |   INLINE   |   |      header to packet.Packet
24840ff8c99SAkhil Goyal        |                 |   | CRYPTO PMD |   |      Encryption/Decryption and
24940ff8c99SAkhil Goyal        +--------|--------+   +----------------+      Authentication happens
25040ff8c99SAkhil Goyal                 |                                    inline.
25140ff8c99SAkhil Goyal        +--------|--------+
25240ff8c99SAkhil Goyal        |       NIC       |
25340ff8c99SAkhil Goyal        +--------|--------+
25440ff8c99SAkhil Goyal                 V
25540ff8c99SAkhil Goyal
25640ff8c99SAkhil GoyalDevice Features and Capabilities
25740ff8c99SAkhil Goyal---------------------------------
25840ff8c99SAkhil Goyal
25940ff8c99SAkhil GoyalDevice Capabilities For Security Operations
26040ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26140ff8c99SAkhil Goyal
26240ff8c99SAkhil GoyalThe device (crypto or ethernet) capabilities which support security operations,
26340ff8c99SAkhil Goyalare defined by the security action type, security protocol, protocol
26440ff8c99SAkhil Goyalcapabilities and corresponding crypto capabilities for security. For the full
26540ff8c99SAkhil Goyalscope of the Security capability see definition of rte_security_capability
26640ff8c99SAkhil Goyalstructure in the *DPDK API Reference*.
26740ff8c99SAkhil Goyal
26840ff8c99SAkhil Goyal.. code-block:: c
26940ff8c99SAkhil Goyal
27040ff8c99SAkhil Goyal   struct rte_security_capability;
27140ff8c99SAkhil Goyal
27240ff8c99SAkhil GoyalEach driver (crypto or ethernet) defines its own private array of capabilities
27340ff8c99SAkhil Goyalfor the operations it supports. Below is an example of the capabilities for a
27440ff8c99SAkhil GoyalPMD which supports the IPSec protocol.
27540ff8c99SAkhil Goyal
27640ff8c99SAkhil Goyal.. code-block:: c
27740ff8c99SAkhil Goyal
27840ff8c99SAkhil Goyal    static const struct rte_security_capability pmd_security_capabilities[] = {
27940ff8c99SAkhil Goyal        { /* IPsec Lookaside Protocol offload ESP Tunnel Egress */
28040ff8c99SAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
28140ff8c99SAkhil Goyal                .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
28240ff8c99SAkhil Goyal                .ipsec = {
28340ff8c99SAkhil Goyal                        .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
28440ff8c99SAkhil Goyal                        .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
28540ff8c99SAkhil Goyal                        .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
28640ff8c99SAkhil Goyal                        .options = { 0 }
28740ff8c99SAkhil Goyal                },
28840ff8c99SAkhil Goyal                .crypto_capabilities = pmd_capabilities
28940ff8c99SAkhil Goyal        },
29040ff8c99SAkhil Goyal        { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
29140ff8c99SAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
29240ff8c99SAkhil Goyal                .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
29340ff8c99SAkhil Goyal                .ipsec = {
29440ff8c99SAkhil Goyal                        .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
29540ff8c99SAkhil Goyal                        .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
29640ff8c99SAkhil Goyal                        .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
29740ff8c99SAkhil Goyal                        .options = { 0 }
29840ff8c99SAkhil Goyal                },
29940ff8c99SAkhil Goyal                .crypto_capabilities = pmd_capabilities
30040ff8c99SAkhil Goyal        },
30140ff8c99SAkhil Goyal        {
30240ff8c99SAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_NONE
30340ff8c99SAkhil Goyal        }
30440ff8c99SAkhil Goyal    };
30540ff8c99SAkhil Goyal    static const struct rte_cryptodev_capabilities pmd_capabilities[] = {
30640ff8c99SAkhil Goyal        {    /* SHA1 HMAC */
30740ff8c99SAkhil Goyal            .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
30840ff8c99SAkhil Goyal            .sym = {
30940ff8c99SAkhil Goyal                .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
31040ff8c99SAkhil Goyal                .auth = {
31140ff8c99SAkhil Goyal                    .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
31240ff8c99SAkhil Goyal                    .block_size = 64,
31340ff8c99SAkhil Goyal                    .key_size = {
31440ff8c99SAkhil Goyal                        .min = 64,
31540ff8c99SAkhil Goyal                        .max = 64,
31640ff8c99SAkhil Goyal                        .increment = 0
31740ff8c99SAkhil Goyal                    },
31840ff8c99SAkhil Goyal                    .digest_size = {
31940ff8c99SAkhil Goyal                        .min = 12,
32040ff8c99SAkhil Goyal                        .max = 12,
32140ff8c99SAkhil Goyal                        .increment = 0
32240ff8c99SAkhil Goyal                    },
32340ff8c99SAkhil Goyal                    .aad_size = { 0 },
32440ff8c99SAkhil Goyal                    .iv_size = { 0 }
32540ff8c99SAkhil Goyal                }
32640ff8c99SAkhil Goyal            }
32740ff8c99SAkhil Goyal        },
32840ff8c99SAkhil Goyal        {    /* AES CBC */
32940ff8c99SAkhil Goyal            .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
33040ff8c99SAkhil Goyal            .sym = {
33140ff8c99SAkhil Goyal                .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
33240ff8c99SAkhil Goyal                .cipher = {
33340ff8c99SAkhil Goyal                    .algo = RTE_CRYPTO_CIPHER_AES_CBC,
33440ff8c99SAkhil Goyal                    .block_size = 16,
33540ff8c99SAkhil Goyal                    .key_size = {
33640ff8c99SAkhil Goyal                        .min = 16,
33740ff8c99SAkhil Goyal                        .max = 32,
33840ff8c99SAkhil Goyal                        .increment = 8
33940ff8c99SAkhil Goyal                    },
34040ff8c99SAkhil Goyal                    .iv_size = {
34140ff8c99SAkhil Goyal                        .min = 16,
34240ff8c99SAkhil Goyal                        .max = 16,
34340ff8c99SAkhil Goyal                        .increment = 0
34440ff8c99SAkhil Goyal                    }
34540ff8c99SAkhil Goyal                }
34640ff8c99SAkhil Goyal            }
34740ff8c99SAkhil Goyal        }
34840ff8c99SAkhil Goyal    }
34940ff8c99SAkhil Goyal
35040ff8c99SAkhil Goyal
35140ff8c99SAkhil GoyalCapabilities Discovery
35240ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~
35340ff8c99SAkhil Goyal
35440ff8c99SAkhil GoyalDiscovering the features and capabilities of a driver (crypto/ethernet)
35540ff8c99SAkhil Goyalis achieved through the ``rte_security_capabilities_get()`` function.
35640ff8c99SAkhil Goyal
35740ff8c99SAkhil Goyal.. code-block:: c
35840ff8c99SAkhil Goyal
35940ff8c99SAkhil Goyal   const struct rte_security_capability *rte_security_capabilities_get(uint16_t id);
36040ff8c99SAkhil Goyal
36140ff8c99SAkhil GoyalThis allows the user to query a specific driver and get all device
36240ff8c99SAkhil Goyalsecurity capabilities. It returns an array of ``rte_security_capability`` structures
36340ff8c99SAkhil Goyalwhich contains all the capabilities for that device.
36440ff8c99SAkhil Goyal
36540ff8c99SAkhil GoyalSecurity Session Create/Free
36640ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36740ff8c99SAkhil Goyal
36840ff8c99SAkhil GoyalSecurity Sessions are created to store the immutable fields of a particular Security
36940ff8c99SAkhil GoyalAssociation for a particular protocol which is defined by a security session
37040ff8c99SAkhil Goyalconfiguration structure which is used in the operation processing of a packet flow.
37140ff8c99SAkhil GoyalSessions are used to manage protocol specific information as well as crypto parameters.
37240ff8c99SAkhil GoyalSecurity sessions cache this immutable data in a optimal way for the underlying PMD
37340ff8c99SAkhil Goyaland this allows further acceleration of the offload of Crypto workloads.
37440ff8c99SAkhil Goyal
37540ff8c99SAkhil GoyalThe Security framework provides APIs to create and free sessions for crypto/ethernet
37640ff8c99SAkhil Goyaldevices, where sessions are mempool objects. It is the application's responsibility
37740ff8c99SAkhil Goyalto create and manage the session mempools. The mempool object size should be able to
37840ff8c99SAkhil Goyalaccommodate the driver's private data of security session.
37940ff8c99SAkhil Goyal
38040ff8c99SAkhil GoyalOnce the session mempools have been created, ``rte_security_session_create()``
38140ff8c99SAkhil Goyalis used to allocate and initialize a session for the required crypto/ethernet device.
38240ff8c99SAkhil Goyal
38340ff8c99SAkhil GoyalSession APIs need a parameter ``rte_security_ctx`` to identify the crypto/ethernet
38440ff8c99SAkhil Goyalsecurity ops. This parameter can be retrieved using the APIs
38540ff8c99SAkhil Goyal``rte_cryptodev_get_sec_ctx()`` (for crypto device) or ``rte_eth_dev_get_sec_ctx``
38640ff8c99SAkhil Goyal(for ethernet port).
38740ff8c99SAkhil Goyal
38840ff8c99SAkhil GoyalSessions already created can be updated with ``rte_security_session_update()``.
38940ff8c99SAkhil Goyal
39040ff8c99SAkhil GoyalWhen a session is no longer used, the user must call ``rte_security_session_destroy()``
39140ff8c99SAkhil Goyalto free the driver private session data and return the memory back to the mempool.
39240ff8c99SAkhil Goyal
39340ff8c99SAkhil GoyalFor look aside protocol offload to hardware crypto device, the ``rte_crypto_op``
39440ff8c99SAkhil Goyalcreated by the application is attached to the security session by the API
39540ff8c99SAkhil Goyal``rte_security_attach_session()``.
39640ff8c99SAkhil Goyal
39740ff8c99SAkhil GoyalFor Inline Crypto and Inline protocol offload, device specific defined metadata is
39840ff8c99SAkhil Goyalupdated in the mbuf using ``rte_security_set_pkt_metadata()`` if
39940ff8c99SAkhil Goyal``DEV_TX_OFFLOAD_SEC_NEED_MDATA`` is set.
40040ff8c99SAkhil Goyal
401*1a08c379SAnoob JosephFor inline protocol offloaded ingress traffic, the application can register a
402*1a08c379SAnoob Josephpointer, ``userdata`` , in the security session. When the packet is received,
403*1a08c379SAnoob Joseph``rte_security_get_userdata()`` would return the userdata registered for the
404*1a08c379SAnoob Josephsecurity session which processed the packet.
405*1a08c379SAnoob Joseph
406*1a08c379SAnoob Joseph.. note::
407*1a08c379SAnoob Joseph
408*1a08c379SAnoob Joseph    In case of inline processed packets, ``rte_mbuf.udata64`` field would be
409*1a08c379SAnoob Joseph    used by the driver to relay information on the security processing
410*1a08c379SAnoob Joseph    associated with the packet. In ingress, the driver would set this in Rx
411*1a08c379SAnoob Joseph    path while in egress, ``rte_security_set_pkt_metadata()`` would perform a
412*1a08c379SAnoob Joseph    similar operation. The application is expected not to modify the field
413*1a08c379SAnoob Joseph    when it has relevant info. For ingress, this device-specific 64 bit value
414*1a08c379SAnoob Joseph    is required to derive other information (like userdata), required for
415*1a08c379SAnoob Joseph    identifying the security processing done on the packet.
416*1a08c379SAnoob Joseph
41740ff8c99SAkhil GoyalSecurity session configuration
41840ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41940ff8c99SAkhil Goyal
42040ff8c99SAkhil GoyalSecurity Session configuration structure is defined as ``rte_security_session_conf``
42140ff8c99SAkhil Goyal
42240ff8c99SAkhil Goyal.. code-block:: c
42340ff8c99SAkhil Goyal
42440ff8c99SAkhil Goyal    struct rte_security_session_conf {
42540ff8c99SAkhil Goyal        enum rte_security_session_action_type action_type;
42640ff8c99SAkhil Goyal        /**< Type of action to be performed on the session */
42740ff8c99SAkhil Goyal        enum rte_security_session_protocol protocol;
42840ff8c99SAkhil Goyal        /**< Security protocol to be configured */
42940ff8c99SAkhil Goyal        union {
43040ff8c99SAkhil Goyal                struct rte_security_ipsec_xform ipsec;
43140ff8c99SAkhil Goyal                struct rte_security_macsec_xform macsec;
43240ff8c99SAkhil Goyal        };
43340ff8c99SAkhil Goyal        /**< Configuration parameters for security session */
43440ff8c99SAkhil Goyal        struct rte_crypto_sym_xform *crypto_xform;
43540ff8c99SAkhil Goyal        /**< Security Session Crypto Transformations */
436*1a08c379SAnoob Joseph        void *userdata;
437*1a08c379SAnoob Joseph        /**< Application specific userdata to be saved with session */
43840ff8c99SAkhil Goyal    };
43940ff8c99SAkhil Goyal
44040ff8c99SAkhil GoyalThe configuration structure reuses the ``rte_crypto_sym_xform`` struct for crypto related
44140ff8c99SAkhil Goyalconfiguration. The ``rte_security_session_action_type`` struct is used to specify whether the
44240ff8c99SAkhil Goyalsession is configured for Lookaside Protocol offload or Inline Crypto or Inline Protocol
44340ff8c99SAkhil GoyalOffload.
44440ff8c99SAkhil Goyal
44540ff8c99SAkhil Goyal.. code-block:: c
44640ff8c99SAkhil Goyal
44740ff8c99SAkhil Goyal    enum rte_security_session_action_type {
44840ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_NONE,
44940ff8c99SAkhil Goyal        /**< No security actions */
45040ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
45140ff8c99SAkhil Goyal        /**< Crypto processing for security protocol is processed inline
45240ff8c99SAkhil Goyal         * during transmission */
45340ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
45440ff8c99SAkhil Goyal        /**< All security protocol processing is performed inline during
45540ff8c99SAkhil Goyal         * transmission */
45640ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL
45740ff8c99SAkhil Goyal        /**< All security protocol processing including crypto is performed
45840ff8c99SAkhil Goyal         * on a lookaside accelerator */
45940ff8c99SAkhil Goyal    };
46040ff8c99SAkhil Goyal
46140ff8c99SAkhil GoyalThe ``rte_security_session_protocol`` is defined as
46240ff8c99SAkhil Goyal
46340ff8c99SAkhil Goyal.. code-block:: c
46440ff8c99SAkhil Goyal
46540ff8c99SAkhil Goyal    enum rte_security_session_protocol {
46640ff8c99SAkhil Goyal        RTE_SECURITY_PROTOCOL_IPSEC,
46740ff8c99SAkhil Goyal        /**< IPsec Protocol */
46840ff8c99SAkhil Goyal        RTE_SECURITY_PROTOCOL_MACSEC,
46940ff8c99SAkhil Goyal        /**< MACSec Protocol */
47040ff8c99SAkhil Goyal    };
47140ff8c99SAkhil Goyal
47240ff8c99SAkhil GoyalCurrently the library defines configuration parameters for IPSec only. For other
47340ff8c99SAkhil Goyalprotocols like MACSec, structures and enums are defined as place holders which
47440ff8c99SAkhil Goyalwill be updated in the future.
47540ff8c99SAkhil Goyal
47640ff8c99SAkhil GoyalIPsec related configuration parameters are defined in ``rte_security_ipsec_xform``
47740ff8c99SAkhil Goyal
47840ff8c99SAkhil Goyal.. code-block:: c
47940ff8c99SAkhil Goyal
48040ff8c99SAkhil Goyal    struct rte_security_ipsec_xform {
48140ff8c99SAkhil Goyal        uint32_t spi;
48240ff8c99SAkhil Goyal        /**< SA security parameter index */
48340ff8c99SAkhil Goyal        uint32_t salt;
48440ff8c99SAkhil Goyal        /**< SA salt */
48540ff8c99SAkhil Goyal        struct rte_security_ipsec_sa_options options;
48640ff8c99SAkhil Goyal        /**< various SA options */
48740ff8c99SAkhil Goyal        enum rte_security_ipsec_sa_direction direction;
48840ff8c99SAkhil Goyal        /**< IPSec SA Direction - Egress/Ingress */
48940ff8c99SAkhil Goyal        enum rte_security_ipsec_sa_protocol proto;
49040ff8c99SAkhil Goyal        /**< IPsec SA Protocol - AH/ESP */
49140ff8c99SAkhil Goyal        enum rte_security_ipsec_sa_mode mode;
49240ff8c99SAkhil Goyal        /**< IPsec SA Mode - transport/tunnel */
49340ff8c99SAkhil Goyal        struct rte_security_ipsec_tunnel_param tunnel;
49440ff8c99SAkhil Goyal        /**< Tunnel parameters, NULL for transport mode */
49540ff8c99SAkhil Goyal    };
49640ff8c99SAkhil Goyal
49740ff8c99SAkhil Goyal
49840ff8c99SAkhil GoyalSecurity API
49940ff8c99SAkhil Goyal~~~~~~~~~~~~
50040ff8c99SAkhil Goyal
50140ff8c99SAkhil GoyalThe rte_security Library API is described in the *DPDK API Reference* document.
50240ff8c99SAkhil Goyal
50340ff8c99SAkhil GoyalFlow based Security Session
50440ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~
50540ff8c99SAkhil Goyal
50640ff8c99SAkhil GoyalIn the case of NIC based offloads, the security session specified in the
50740ff8c99SAkhil Goyal'rte_flow_action_security' must be created on the same port as the
50840ff8c99SAkhil Goyalflow action that is being specified.
50940ff8c99SAkhil Goyal
51040ff8c99SAkhil GoyalThe ingress/egress flow attribute should match that specified in the security
51140ff8c99SAkhil Goyalsession if the security session supports the definition of the direction.
51240ff8c99SAkhil Goyal
51340ff8c99SAkhil GoyalMultiple flows can be configured to use the same security session. For
51440ff8c99SAkhil Goyalexample if the security session specifies an egress IPsec SA, then multiple
51540ff8c99SAkhil Goyalflows can be specified to that SA. In the case of an ingress IPsec SA then
51640ff8c99SAkhil Goyalit is only valid to have a single flow to map to that security session.
51740ff8c99SAkhil Goyal
51840ff8c99SAkhil Goyal.. code-block:: console
51940ff8c99SAkhil Goyal
52040ff8c99SAkhil Goyal         Configuration Path
52140ff8c99SAkhil Goyal                 |
52240ff8c99SAkhil Goyal        +--------|--------+
52340ff8c99SAkhil Goyal        |    Add/Remove   |
52440ff8c99SAkhil Goyal        |     IPsec SA    |   <------ Build security flow action of
52540ff8c99SAkhil Goyal        |        |        |           ipsec transform
52640ff8c99SAkhil Goyal        |--------|--------|
52740ff8c99SAkhil Goyal                 |
52840ff8c99SAkhil Goyal        +--------V--------+
52940ff8c99SAkhil Goyal        |   Flow API      |
53040ff8c99SAkhil Goyal        +--------|--------+
53140ff8c99SAkhil Goyal                 |
53240ff8c99SAkhil Goyal        +--------V--------+
53340ff8c99SAkhil Goyal        |                 |
53440ff8c99SAkhil Goyal        |     NIC PMD     |   <------ Add/Remove SA to/from hw context
53540ff8c99SAkhil Goyal        |                 |
53640ff8c99SAkhil Goyal        +--------|--------+
53740ff8c99SAkhil Goyal                 |
53840ff8c99SAkhil Goyal        +--------|--------+
53940ff8c99SAkhil Goyal        |  HW ACCELERATED |
54040ff8c99SAkhil Goyal        |        NIC      |
54140ff8c99SAkhil Goyal        |                 |
54240ff8c99SAkhil Goyal        +--------|--------+
54340ff8c99SAkhil Goyal
54440ff8c99SAkhil Goyal* Add/Delete SA flow:
54540ff8c99SAkhil Goyal  To add a new inline SA construct a rte_flow_item for Ethernet + IP + ESP
54640ff8c99SAkhil Goyal  using the SA selectors and the ``rte_crypto_ipsec_xform`` as the ``rte_flow_action``.
54740ff8c99SAkhil Goyal  Note that any rte_flow_items may be empty, which means it is not checked.
54840ff8c99SAkhil Goyal
54940ff8c99SAkhil Goyal.. code-block:: console
55040ff8c99SAkhil Goyal
55140ff8c99SAkhil Goyal    In its most basic form, IPsec flow specification is as follows:
55240ff8c99SAkhil Goyal        +-------+     +----------+    +--------+    +-----+
55340ff8c99SAkhil Goyal        |  Eth  | ->  |   IP4/6  | -> |   ESP  | -> | END |
55440ff8c99SAkhil Goyal        +-------+     +----------+    +--------+    +-----+
55540ff8c99SAkhil Goyal
55640ff8c99SAkhil Goyal    However, the API can represent, IPsec crypto offload with any encapsulation:
55740ff8c99SAkhil Goyal        +-------+            +--------+    +-----+
55840ff8c99SAkhil Goyal        |  Eth  | ->  ... -> |   ESP  | -> | END |
55940ff8c99SAkhil Goyal        +-------+            +--------+    +-----+
560