xref: /dpdk/doc/guides/prog_guide/rte_security.rst (revision bbbe6c596b284909e4112ac9573b16da2137ffab)
1d81734caSHemant Agrawal..  SPDX-License-Identifier: BSD-3-Clause
2864c1a40SHemant Agrawal    Copyright 2017,2020-2021 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
13e44b3fafSDavid CoyleNIC or crypto devices. The framework currently only supports the IPsec, PDCP
14e44b3fafSDavid Coyleand DOCSIS protocols and associated operations, other protocols will be added
15e44b3fafSDavid Coylein the future.
1640ff8c99SAkhil Goyal
1740ff8c99SAkhil GoyalDesign Principles
1840ff8c99SAkhil Goyal-----------------
1940ff8c99SAkhil Goyal
2040ff8c99SAkhil GoyalThe security library provides an additional offload capability to an existing
2140ff8c99SAkhil Goyalcrypto device and/or ethernet device.
2240ff8c99SAkhil Goyal
2340ff8c99SAkhil Goyal.. code-block:: console
2440ff8c99SAkhil Goyal
2540ff8c99SAkhil Goyal               +---------------+
2640ff8c99SAkhil Goyal               | rte_security  |
2740ff8c99SAkhil Goyal               +---------------+
2840ff8c99SAkhil Goyal                 \            /
2940ff8c99SAkhil Goyal        +-----------+    +--------------+
3040ff8c99SAkhil Goyal        |  NIC PMD  |    |  CRYPTO PMD  |
3140ff8c99SAkhil Goyal        +-----------+    +--------------+
3240ff8c99SAkhil Goyal
3340ff8c99SAkhil Goyal.. note::
3440ff8c99SAkhil Goyal
3540ff8c99SAkhil Goyal    Currently, the security library does not support the case of multi-process.
3640ff8c99SAkhil Goyal    It will be updated in the future releases.
3740ff8c99SAkhil Goyal
3840ff8c99SAkhil GoyalThe supported offload types are explained in the sections below.
3940ff8c99SAkhil Goyal
4040ff8c99SAkhil GoyalInline Crypto
4140ff8c99SAkhil Goyal~~~~~~~~~~~~~
4240ff8c99SAkhil Goyal
4340ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO:
44d629b7b5SJohn McNamaraThe crypto processing for security protocol (e.g. IPsec) is processed
4540ff8c99SAkhil Goyalinline during receive and transmission on NIC port. The flow based
4640ff8c99SAkhil Goyalsecurity action should be configured on the port.
4740ff8c99SAkhil Goyal
4840ff8c99SAkhil GoyalIngress Data path - The packet is decrypted in RX path and relevant
4940ff8c99SAkhil Goyalcrypto status is set in Rx descriptors. After the successful inline
5040ff8c99SAkhil Goyalcrypto processing the packet is presented to host as a regular Rx packet
5140ff8c99SAkhil Goyalhowever all security protocol related headers are still attached to the
52d629b7b5SJohn McNamarapacket. e.g. In case of IPsec, the IPsec tunnel headers (if any),
5340ff8c99SAkhil GoyalESP/AH headers will remain in the packet but the received packet
5440ff8c99SAkhil Goyalcontains the decrypted data where the encrypted data was when the packet
55f43d3dbbSDavid Marchandarrived. The driver Rx path check the descriptors and based on the
5640ff8c99SAkhil Goyalcrypto status sets additional flags in the rte_mbuf.ol_flags field.
5740ff8c99SAkhil Goyal
5840ff8c99SAkhil Goyal.. note::
5940ff8c99SAkhil Goyal
6040ff8c99SAkhil Goyal    The underlying device may not support crypto processing for all ingress packet
6140ff8c99SAkhil Goyal    matching to a particular flow (e.g. fragmented packets), such packets will
6240ff8c99SAkhil Goyal    be passed as encrypted packets. It is the responsibility of application to
6340ff8c99SAkhil Goyal    process such encrypted packets using other crypto driver instance.
6440ff8c99SAkhil Goyal
6540ff8c99SAkhil GoyalEgress Data path - The software prepares the egress packet by adding
6640ff8c99SAkhil Goyalrelevant security protocol headers. Only the data will not be
6740ff8c99SAkhil Goyalencrypted by the software. The driver will accordingly configure the
6840ff8c99SAkhil Goyaltx descriptors. The hardware device will encrypt the data before sending the
69f43d3dbbSDavid Marchandpacket out.
7040ff8c99SAkhil Goyal
7140ff8c99SAkhil Goyal.. note::
7240ff8c99SAkhil Goyal
7340ff8c99SAkhil Goyal    The underlying device may support post encryption TSO.
7440ff8c99SAkhil Goyal
7540ff8c99SAkhil Goyal.. code-block:: console
7640ff8c99SAkhil Goyal
7740ff8c99SAkhil Goyal          Egress Data Path
7840ff8c99SAkhil Goyal                 |
7940ff8c99SAkhil Goyal        +--------|--------+
8040ff8c99SAkhil Goyal        |  egress IPsec   |
8140ff8c99SAkhil Goyal        |        |        |
8240ff8c99SAkhil Goyal        | +------V------+ |
8340ff8c99SAkhil Goyal        | | SADB lookup | |
8440ff8c99SAkhil Goyal        | +------|------+ |
8540ff8c99SAkhil Goyal        | +------V------+ |
8640ff8c99SAkhil Goyal        | |   Tunnel    | |   <------ Add tunnel header to packet
8740ff8c99SAkhil Goyal        | +------|------+ |
8840ff8c99SAkhil Goyal        | +------V------+ |
8940ff8c99SAkhil Goyal        | |     ESP     | |   <------ Add ESP header without trailer to packet
9040ff8c99SAkhil Goyal        | |             | |   <------ Mark packet to be offloaded, add trailer
9140ff8c99SAkhil Goyal        | +------|------+ |            meta-data to mbuf
9240ff8c99SAkhil Goyal        +--------V--------+
9340ff8c99SAkhil Goyal                 |
9440ff8c99SAkhil Goyal        +--------V--------+
9540ff8c99SAkhil Goyal        |    L2 Stack     |
9640ff8c99SAkhil Goyal        +--------|--------+
9740ff8c99SAkhil Goyal                 |
9840ff8c99SAkhil Goyal        +--------V--------+
9940ff8c99SAkhil Goyal        |                 |
10040ff8c99SAkhil Goyal        |     NIC PMD     |   <------ Set hw context for inline crypto offload
10140ff8c99SAkhil Goyal        |                 |
10240ff8c99SAkhil Goyal        +--------|--------+
10340ff8c99SAkhil Goyal                 |
10440ff8c99SAkhil Goyal        +--------|--------+
10540ff8c99SAkhil Goyal        |  HW ACCELERATED |   <------ Packet Encryption and
10640ff8c99SAkhil Goyal        |        NIC      |           Authentication happens inline
10740ff8c99SAkhil Goyal        |                 |
10840ff8c99SAkhil Goyal        +-----------------+
10940ff8c99SAkhil Goyal
11040ff8c99SAkhil Goyal
11140ff8c99SAkhil GoyalInline protocol offload
11240ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~
11340ff8c99SAkhil Goyal
11440ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL:
115d629b7b5SJohn McNamaraThe crypto and protocol processing for security protocol (e.g. IPsec)
11640ff8c99SAkhil Goyalis processed inline during receive and transmission.  The flow based
11740ff8c99SAkhil Goyalsecurity action should be configured on the port.
11840ff8c99SAkhil Goyal
11940ff8c99SAkhil GoyalIngress Data path - The packet is decrypted in the RX path and relevant
12040ff8c99SAkhil Goyalcrypto status is set in the Rx descriptors. After the successful inline
12140ff8c99SAkhil Goyalcrypto processing the packet is presented to the host as a regular Rx packet
12240ff8c99SAkhil Goyalbut all security protocol related headers are optionally removed from the
123d629b7b5SJohn McNamarapacket. e.g. in the case of IPsec, the IPsec tunnel headers (if any),
12440ff8c99SAkhil GoyalESP/AH headers will be removed from the packet and the received packet
12540ff8c99SAkhil Goyalwill contains the decrypted packet only. The driver Rx path checks the
12640ff8c99SAkhil Goyaldescriptors and based on the crypto status sets additional flags in
1271a08c379SAnoob Joseph``rte_mbuf.ol_flags`` field. The driver would also set device-specific
128614af754SThomas Monjalonmetadata in ``RTE_SECURITY_DYNFIELD_NAME`` field.
129614af754SThomas MonjalonThis will allow the application to identify the security processing
130614af754SThomas Monjalondone on the packet.
13140ff8c99SAkhil Goyal
13240ff8c99SAkhil Goyal.. note::
13340ff8c99SAkhil Goyal
13440ff8c99SAkhil Goyal    The underlying device in this case is stateful. It is expected that
13540ff8c99SAkhil Goyal    the device shall support crypto processing for all kind of packets matching
13640ff8c99SAkhil Goyal    to a given flow, this includes fragmented packets (post reassembly).
137d629b7b5SJohn McNamara    E.g. in case of IPsec the device may internally manage anti-replay etc.
13840ff8c99SAkhil Goyal    It will provide a configuration option for anti-replay behavior i.e. to drop
13940ff8c99SAkhil Goyal    the packets or pass them to driver with error flags set in the descriptor.
14040ff8c99SAkhil Goyal
14140ff8c99SAkhil GoyalEgress Data path - The software will send the plain packet without any
14240ff8c99SAkhil Goyalsecurity protocol headers added to the packet. The driver will configure
14340ff8c99SAkhil Goyalthe security index and other requirement in tx descriptors.
14440ff8c99SAkhil GoyalThe hardware device will do security processing on the packet that includes
14540ff8c99SAkhil Goyaladding the relevant protocol headers and encrypting the data before sending
14640ff8c99SAkhil Goyalthe packet out. The software should make sure that the buffer
14740ff8c99SAkhil Goyalhas required head room and tail room for any protocol header addition. The
14840ff8c99SAkhil Goyalsoftware may also do early fragmentation if the resultant packet is expected
149dcee1520SNithin Dabilpuramto cross the MTU size. The software should also make sure that L2 header contents
150dcee1520SNithin Dabilpuramare updated with the final L2 header which is expected post IPsec processing as
151dcee1520SNithin Dabilpuramthe IPsec offload will only update L3 and above in egress path.
15240ff8c99SAkhil Goyal
15340ff8c99SAkhil Goyal
15440ff8c99SAkhil Goyal.. note::
15540ff8c99SAkhil Goyal
15640ff8c99SAkhil Goyal    The underlying device will manage state information required for egress
157d629b7b5SJohn McNamara    processing. E.g. in case of IPsec, the seq number will be added to the
15840ff8c99SAkhil Goyal    packet, however the device shall provide indication when the sequence number
15940ff8c99SAkhil Goyal    is about to overflow. The underlying device may support post encryption TSO.
16040ff8c99SAkhil Goyal
16140ff8c99SAkhil Goyal.. code-block:: console
16240ff8c99SAkhil Goyal
16340ff8c99SAkhil Goyal         Egress Data Path
16440ff8c99SAkhil Goyal                 |
16540ff8c99SAkhil Goyal        +--------|--------+
16640ff8c99SAkhil Goyal        |  egress IPsec   |
16740ff8c99SAkhil Goyal        |        |        |
16840ff8c99SAkhil Goyal        | +------V------+ |
16940ff8c99SAkhil Goyal        | | SADB lookup | |
17040ff8c99SAkhil Goyal        | +------|------+ |
17140ff8c99SAkhil Goyal        | +------V------+ |
17240ff8c99SAkhil Goyal        | |   Desc      | |   <------ Mark packet to be offloaded
17340ff8c99SAkhil Goyal        | +------|------+ |
17440ff8c99SAkhil Goyal        +--------V--------+
17540ff8c99SAkhil Goyal                 |
17640ff8c99SAkhil Goyal        +--------V--------+
17740ff8c99SAkhil Goyal        |    L2 Stack     |
17840ff8c99SAkhil Goyal        +--------|--------+
17940ff8c99SAkhil Goyal                 |
18040ff8c99SAkhil Goyal        +--------V--------+
18140ff8c99SAkhil Goyal        |                 |
18240ff8c99SAkhil Goyal        |     NIC PMD     |   <------ Set hw context for inline crypto offload
18340ff8c99SAkhil Goyal        |                 |
18440ff8c99SAkhil Goyal        +--------|--------+
18540ff8c99SAkhil Goyal                 |
18640ff8c99SAkhil Goyal        +--------|--------+
18740ff8c99SAkhil Goyal        |  HW ACCELERATED |   <------ Add tunnel, ESP header etc header to
18840ff8c99SAkhil Goyal        |        NIC      |           packet. Packet Encryption and
18940ff8c99SAkhil Goyal        |                 |           Authentication happens inline.
19040ff8c99SAkhil Goyal        +-----------------+
19140ff8c99SAkhil Goyal
19240ff8c99SAkhil Goyal
19340ff8c99SAkhil GoyalLookaside protocol offload
19440ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~
19540ff8c99SAkhil Goyal
19640ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL:
19740ff8c99SAkhil GoyalThis extends librte_cryptodev to support the programming of IPsec
19840ff8c99SAkhil GoyalSecurity Association (SA) as part of a crypto session creation including
19940ff8c99SAkhil Goyalthe definition. In addition to standard crypto processing, as defined by
20040ff8c99SAkhil Goyalthe cryptodev, the security protocol processing is also offloaded to the
20140ff8c99SAkhil Goyalcrypto device.
20240ff8c99SAkhil Goyal
20340ff8c99SAkhil GoyalDecryption: The packet is sent to the crypto device for security
20440ff8c99SAkhil Goyalprotocol processing. The device will decrypt the packet and it will also
20540ff8c99SAkhil Goyaloptionally remove additional security headers from the packet.
206d629b7b5SJohn McNamaraE.g. in case of IPsec, IPsec tunnel headers (if any), ESP/AH headers
20740ff8c99SAkhil Goyalwill be removed from the packet and the decrypted packet may contain
20840ff8c99SAkhil Goyalplain data only.
20940ff8c99SAkhil Goyal
21040ff8c99SAkhil Goyal.. note::
21140ff8c99SAkhil Goyal
212d629b7b5SJohn McNamara    In case of IPsec the device may internally manage anti-replay etc.
21340ff8c99SAkhil Goyal    It will provide a configuration option for anti-replay behavior i.e. to drop
21440ff8c99SAkhil Goyal    the packets or pass them to driver with error flags set in descriptor.
21540ff8c99SAkhil Goyal
21640ff8c99SAkhil GoyalEncryption: The software will submit the packet to cryptodev as usual
21740ff8c99SAkhil Goyalfor encryption, the hardware device in this case will also add the relevant
21840ff8c99SAkhil Goyalsecurity protocol header along with encrypting the packet. The software
21940ff8c99SAkhil Goyalshould make sure that the buffer has required head room and tail room
22040ff8c99SAkhil Goyalfor any protocol header addition.
22140ff8c99SAkhil Goyal
22240ff8c99SAkhil Goyal.. note::
22340ff8c99SAkhil Goyal
224d629b7b5SJohn McNamara    In the case of IPsec, the seq number will be added to the packet,
22540ff8c99SAkhil Goyal    It shall provide an indication when the sequence number is about to
22640ff8c99SAkhil Goyal    overflow.
22740ff8c99SAkhil Goyal
22840ff8c99SAkhil Goyal.. code-block:: console
22940ff8c99SAkhil Goyal
23040ff8c99SAkhil Goyal          Egress Data Path
23140ff8c99SAkhil Goyal                 |
23240ff8c99SAkhil Goyal        +--------|--------+
23340ff8c99SAkhil Goyal        |  egress IPsec   |
23440ff8c99SAkhil Goyal        |        |        |
23540ff8c99SAkhil Goyal        | +------V------+ |
23640ff8c99SAkhil Goyal        | | SADB lookup | |   <------ SA maps to cryptodev session
23740ff8c99SAkhil Goyal        | +------|------+ |
23840ff8c99SAkhil Goyal        | +------|------+ |
23940ff8c99SAkhil Goyal        | |      \--------------------\
24040ff8c99SAkhil Goyal        | |    Crypto   | |           |  <- Crypto processing through
24140ff8c99SAkhil Goyal        | |      /----------------\   |     inline crypto PMD
24240ff8c99SAkhil Goyal        | +------|------+ |       |   |
24340ff8c99SAkhil Goyal        +--------V--------+       |   |
24440ff8c99SAkhil Goyal                 |                |   |
24540ff8c99SAkhil Goyal        +--------V--------+       |   |  create   <-- SA is added to hw
24640ff8c99SAkhil Goyal        |    L2 Stack     |       |   |  inline       using existing create
24740ff8c99SAkhil Goyal        +--------|--------+       |   |  session      sym session APIs
24840ff8c99SAkhil Goyal                 |                |   |    |
24940ff8c99SAkhil Goyal        +--------V--------+   +---|---|----V---+
25040ff8c99SAkhil Goyal        |                 |   |   \---/    |   | <--- Add tunnel, ESP header etc
25140ff8c99SAkhil Goyal        |     NIC PMD     |   |   INLINE   |   |      header to packet.Packet
25240ff8c99SAkhil Goyal        |                 |   | CRYPTO PMD |   |      Encryption/Decryption and
25340ff8c99SAkhil Goyal        +--------|--------+   +----------------+      Authentication happens
25440ff8c99SAkhil Goyal                 |                                    inline.
25540ff8c99SAkhil Goyal        +--------|--------+
25640ff8c99SAkhil Goyal        |       NIC       |
25740ff8c99SAkhil Goyal        +--------|--------+
25840ff8c99SAkhil Goyal                 V
25940ff8c99SAkhil Goyal
2608b593b8cSAkhil GoyalPDCP Flow Diagram
2618b593b8cSAkhil Goyal~~~~~~~~~~~~~~~~~
2628b593b8cSAkhil Goyal
2638b593b8cSAkhil GoyalBased on 3GPP TS 36.323 Evolved Universal Terrestrial Radio Access (E-UTRA);
2648b593b8cSAkhil GoyalPacket Data Convergence Protocol (PDCP) specification
2658b593b8cSAkhil Goyal
2668b593b8cSAkhil Goyal.. code-block:: c
2678b593b8cSAkhil Goyal
2688b593b8cSAkhil Goyal        Transmitting PDCP Entity          Receiving PDCP Entity
2698b593b8cSAkhil Goyal                  |                                   ^
2708b593b8cSAkhil Goyal                  |                       +-----------|-----------+
2718b593b8cSAkhil Goyal                  V                       | In order delivery and |
2728b593b8cSAkhil Goyal        +---------|----------+            | Duplicate detection   |
2738b593b8cSAkhil Goyal        | Sequence Numbering |            |  (Data Plane only)    |
2748b593b8cSAkhil Goyal        +---------|----------+            +-----------|-----------+
2758b593b8cSAkhil Goyal                  |                                   |
2768b593b8cSAkhil Goyal        +---------|----------+            +-----------|----------+
2778b593b8cSAkhil Goyal        | Header Compression*|            | Header Decompression*|
2788b593b8cSAkhil Goyal        | (Data-Plane only)  |            |   (Data Plane only)  |
2798b593b8cSAkhil Goyal        +---------|----------+            +-----------|----------+
2808b593b8cSAkhil Goyal                  |                                   |
2818b593b8cSAkhil Goyal        +---------|-----------+           +-----------|----------+
2828b593b8cSAkhil Goyal        | Integrity Protection|           |Integrity Verification|
2838b593b8cSAkhil Goyal        | (Control Plane only)|           | (Control Plane only) |
2848b593b8cSAkhil Goyal        +---------|-----------+           +-----------|----------+
2858b593b8cSAkhil Goyal        +---------|-----------+            +----------|----------+
2868b593b8cSAkhil Goyal        |     Ciphering       |            |     Deciphering     |
2878b593b8cSAkhil Goyal        +---------|-----------+            +----------|----------+
2888b593b8cSAkhil Goyal        +---------|-----------+            +----------|----------+
2898b593b8cSAkhil Goyal        |   Add PDCP header   |            | Remove PDCP Header  |
2908b593b8cSAkhil Goyal        +---------|-----------+            +----------|----------+
2918b593b8cSAkhil Goyal                  |                                   |
2928b593b8cSAkhil Goyal                  +----------------->>----------------+
2938b593b8cSAkhil Goyal
2948b593b8cSAkhil Goyal
2958b593b8cSAkhil Goyal.. note::
2968b593b8cSAkhil Goyal
2978b593b8cSAkhil Goyal    * Header Compression and decompression are not supported currently.
2988b593b8cSAkhil Goyal
2998b593b8cSAkhil GoyalJust like IPsec, in case of PDCP also header addition/deletion, cipher/
3008b593b8cSAkhil Goyalde-cipher, integrity protection/verification is done based on the action
3018b593b8cSAkhil Goyaltype chosen.
3028b593b8cSAkhil Goyal
303e44b3fafSDavid CoyleDOCSIS Protocol
304e44b3fafSDavid Coyle~~~~~~~~~~~~~~~
305e44b3fafSDavid Coyle
306e44b3fafSDavid CoyleThe Data Over Cable Service Interface Specification (DOCSIS) support comprises
307e44b3fafSDavid Coylethe combination of encryption/decryption and CRC generation/verification, for
308e44b3fafSDavid Coyleuse in a DOCSIS-MAC pipeline.
309e44b3fafSDavid Coyle
310e44b3fafSDavid Coyle.. code-block:: c
311e44b3fafSDavid Coyle
312e44b3fafSDavid Coyle
313e44b3fafSDavid Coyle               Downlink                       Uplink
314e44b3fafSDavid Coyle               --------                       ------
315e44b3fafSDavid Coyle
316e44b3fafSDavid Coyle            Ethernet frame                Ethernet frame
317e44b3fafSDavid Coyle           from core network              to core network
318e44b3fafSDavid Coyle                  |                              ^
319e44b3fafSDavid Coyle                  ~                              |
320e44b3fafSDavid Coyle                  |                              ~         ----+
321e44b3fafSDavid Coyle                  V                              |             |
322e44b3fafSDavid Coyle        +---------|----------+        +----------|---------+   |
323e44b3fafSDavid Coyle        |   CRC generation   |        |  CRC verification  |   |
324e44b3fafSDavid Coyle        +---------|----------+        +----------|---------+   |   combined
325e44b3fafSDavid Coyle                  |                              |             > Crypto + CRC
326e44b3fafSDavid Coyle        +---------|----------+        +----------|---------+   |
327e44b3fafSDavid Coyle        |     Encryption     |        |     Decryption     |   |
328e44b3fafSDavid Coyle        +---------|----------+        +----------|---------+   |
329e44b3fafSDavid Coyle                  |                              ^             |
330e44b3fafSDavid Coyle                  ~                              |         ----+
331e44b3fafSDavid Coyle                  |                              ~
332e44b3fafSDavid Coyle                  V                              |
333e44b3fafSDavid Coyle             DOCSIS frame                  DOCSIS frame
334e44b3fafSDavid Coyle            to Cable Modem               from Cable Modem
335e44b3fafSDavid Coyle
336e44b3fafSDavid CoyleThe encryption/decryption is a combination of CBC and CFB modes using either AES
337e44b3fafSDavid Coyleor DES algorithms as specified in the DOCSIS Security Specification (from DPDK
338e44b3fafSDavid Coylelib_rtecryptodev perspective, these are RTE_CRYPTO_CIPHER_AES_DOCSISBPI and
339e44b3fafSDavid CoyleRTE_CRYPTO_CIPHER_DES_DOCSISBPI).
340e44b3fafSDavid Coyle
341e44b3fafSDavid CoyleThe CRC is Ethernet CRC-32 as specified in Ethernet/[ISO/IEC 8802-3].
342e44b3fafSDavid Coyle
343e44b3fafSDavid Coyle.. note::
344e44b3fafSDavid Coyle
345e44b3fafSDavid Coyle    * The offset and length of data for which CRC needs to be computed are
346e44b3fafSDavid Coyle      specified via the auth offset and length fields of the rte_crypto_sym_op.
347e44b3fafSDavid Coyle    * Other DOCSIS protocol functionality such as Header Checksum (HCS)
348e44b3fafSDavid Coyle      calculation may be added in the future.
349e44b3fafSDavid Coyle
350*bbbe6c59SAkhil GoyalMACSEC Protocol
351*bbbe6c59SAkhil Goyal~~~~~~~~~~~~~~~
352*bbbe6c59SAkhil Goyal
353*bbbe6c59SAkhil GoyalMedia Access Control security (MACsec) provides point-to-point security
354*bbbe6c59SAkhil Goyalon Ethernet links and is defined by IEEE standard 802.1AE.
355*bbbe6c59SAkhil GoyalMACsec secures an Ethernet link for almost all traffic,
356*bbbe6c59SAkhil Goyalincluding frames from the Link Layer Discovery Protocol (LLDP),
357*bbbe6c59SAkhil GoyalLink Aggregation Control Protocol (LACP),
358*bbbe6c59SAkhil GoyalDynamic Host Configuration Protocol (DHCP),
359*bbbe6c59SAkhil GoyalAddress Resolution Protocol (ARP),
360*bbbe6c59SAkhil Goyaland other protocols that are not typically secured on an Ethernet link
361*bbbe6c59SAkhil Goyalbecause of limitations with other security solutions.
362*bbbe6c59SAkhil Goyal
363*bbbe6c59SAkhil Goyal.. code-block:: c
364*bbbe6c59SAkhil Goyal
365*bbbe6c59SAkhil Goyal             Receive                                                Transmit
366*bbbe6c59SAkhil Goyal             -------                                                --------
367*bbbe6c59SAkhil Goyal
368*bbbe6c59SAkhil Goyal         Ethernet frame                                          Ethernet frame
369*bbbe6c59SAkhil Goyal          from network                                           towards network
370*bbbe6c59SAkhil Goyal                |                                                      ^
371*bbbe6c59SAkhil Goyal                ~                                                      |
372*bbbe6c59SAkhil Goyal                |                                                      ~
373*bbbe6c59SAkhil Goyal                V                                                      |
374*bbbe6c59SAkhil Goyal    +-----------------------+      +------------------+      +-------------------------+
375*bbbe6c59SAkhil Goyal    | Secure Frame Verify   |      | Cipher Suite(SA) |      | Secure Frame Generation |
376*bbbe6c59SAkhil Goyal    +-----------------------+<-----+------------------+----->+-------------------------+
377*bbbe6c59SAkhil Goyal    | SecTAG + ICV remove   |      |  SECY   |   SC   |      | SecTAG + ICV Added      |
378*bbbe6c59SAkhil Goyal    +---+-------------------+      +------------------+      +-------------------------+
379*bbbe6c59SAkhil Goyal                |                                                      ^
380*bbbe6c59SAkhil Goyal                |                                                      |
381*bbbe6c59SAkhil Goyal                V                                                      |
382*bbbe6c59SAkhil Goyal        Packet to Core/App                                     Packet from Core/App
383*bbbe6c59SAkhil Goyal
384*bbbe6c59SAkhil Goyal
385*bbbe6c59SAkhil Goyal
386*bbbe6c59SAkhil GoyalTo configure MACsec on an inline NIC device or a lookaside crypto device,
387*bbbe6c59SAkhil Goyala security association (SA) and a secure channel (SC) are created
388*bbbe6c59SAkhil Goyalbefore creating rte_security session.
389*bbbe6c59SAkhil Goyal
390*bbbe6c59SAkhil GoyalSA is created using API ``rte_security_macsec_sa_create``
391*bbbe6c59SAkhil Goyalwhich allows setting SA keys, salt, SSCI, packet number (PN) into the PMD,
392*bbbe6c59SAkhil Goyaland the API returns a handle which can be used to map it with a secure channel,
393*bbbe6c59SAkhil Goyalusing the API ``rte_security_macsec_sc_create``.
394*bbbe6c59SAkhil GoyalSame SAs can be used for multiple SCs.
395*bbbe6c59SAkhil GoyalThe Rx SC will need a set of 4 SAs for each of the association numbers (AN).
396*bbbe6c59SAkhil GoyalFor Tx SC a single SA is set which will be used by hardware to process the packet.
397*bbbe6c59SAkhil Goyal
398*bbbe6c59SAkhil GoyalThe API ``rte_security_macsec_sc_create`` returns a handle for SC,
399*bbbe6c59SAkhil Goyaland this handle is set in ``rte_security_macsec_xform``
400*bbbe6c59SAkhil Goyalto create a MACsec session using ``rte_security_session_create``.
401*bbbe6c59SAkhil Goyal
402*bbbe6c59SAkhil Goyal
40340ff8c99SAkhil GoyalDevice Features and Capabilities
40440ff8c99SAkhil Goyal---------------------------------
40540ff8c99SAkhil Goyal
40640ff8c99SAkhil GoyalDevice Capabilities For Security Operations
40740ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40840ff8c99SAkhil Goyal
40940ff8c99SAkhil GoyalThe device (crypto or ethernet) capabilities which support security operations,
41040ff8c99SAkhil Goyalare defined by the security action type, security protocol, protocol
41140ff8c99SAkhil Goyalcapabilities and corresponding crypto capabilities for security. For the full
41240ff8c99SAkhil Goyalscope of the Security capability see definition of rte_security_capability
41340ff8c99SAkhil Goyalstructure in the *DPDK API Reference*.
41440ff8c99SAkhil Goyal
41540ff8c99SAkhil Goyal.. code-block:: c
41640ff8c99SAkhil Goyal
41740ff8c99SAkhil Goyal   struct rte_security_capability;
41840ff8c99SAkhil Goyal
41940ff8c99SAkhil GoyalEach driver (crypto or ethernet) defines its own private array of capabilities
42040ff8c99SAkhil Goyalfor the operations it supports. Below is an example of the capabilities for a
4218b593b8cSAkhil GoyalPMD which supports the IPsec and PDCP protocol.
42240ff8c99SAkhil Goyal
42340ff8c99SAkhil Goyal.. code-block:: c
42440ff8c99SAkhil Goyal
42540ff8c99SAkhil Goyal    static const struct rte_security_capability pmd_security_capabilities[] = {
42640ff8c99SAkhil Goyal        { /* IPsec Lookaside Protocol offload ESP Tunnel Egress */
42740ff8c99SAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
42840ff8c99SAkhil Goyal                .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
42940ff8c99SAkhil Goyal                .ipsec = {
43040ff8c99SAkhil Goyal                        .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
43140ff8c99SAkhil Goyal                        .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
43240ff8c99SAkhil Goyal                        .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
43340ff8c99SAkhil Goyal                        .options = { 0 }
43440ff8c99SAkhil Goyal                },
43540ff8c99SAkhil Goyal                .crypto_capabilities = pmd_capabilities
43640ff8c99SAkhil Goyal        },
43740ff8c99SAkhil Goyal        { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
43840ff8c99SAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
43940ff8c99SAkhil Goyal                .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
44040ff8c99SAkhil Goyal                .ipsec = {
44140ff8c99SAkhil Goyal                        .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
44240ff8c99SAkhil Goyal                        .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
44340ff8c99SAkhil Goyal                        .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
44440ff8c99SAkhil Goyal                        .options = { 0 }
44540ff8c99SAkhil Goyal                },
44640ff8c99SAkhil Goyal                .crypto_capabilities = pmd_capabilities
44740ff8c99SAkhil Goyal        },
4488b593b8cSAkhil Goyal        { /* PDCP Lookaside Protocol offload Data Plane */
4498b593b8cSAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
4508b593b8cSAkhil Goyal                .protocol = RTE_SECURITY_PROTOCOL_PDCP,
4518b593b8cSAkhil Goyal                .pdcp = {
4528b593b8cSAkhil Goyal                        .domain = RTE_SECURITY_PDCP_MODE_DATA,
4538b593b8cSAkhil Goyal                        .capa_flags = 0
4548b593b8cSAkhil Goyal                },
4558b593b8cSAkhil Goyal                .crypto_capabilities = pmd_capabilities
4568b593b8cSAkhil Goyal        },
4578b593b8cSAkhil Goyal        { /* PDCP Lookaside Protocol offload Control */
4588b593b8cSAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
4598b593b8cSAkhil Goyal                .protocol = RTE_SECURITY_PROTOCOL_PDCP,
4608b593b8cSAkhil Goyal                .pdcp = {
4618b593b8cSAkhil Goyal                        .domain = RTE_SECURITY_PDCP_MODE_CONTROL,
4628b593b8cSAkhil Goyal                        .capa_flags = 0
4638b593b8cSAkhil Goyal                },
4648b593b8cSAkhil Goyal                .crypto_capabilities = pmd_capabilities
4658b593b8cSAkhil Goyal        },
466864c1a40SHemant Agrawal	{ /* PDCP Lookaside Protocol offload short MAC-I */
467864c1a40SHemant Agrawal                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
468864c1a40SHemant Agrawal                .protocol = RTE_SECURITY_PROTOCOL_PDCP,
469864c1a40SHemant Agrawal                .pdcp = {
470864c1a40SHemant Agrawal                        .domain = RTE_SECURITY_PDCP_MODE_SHORT_MAC,
471864c1a40SHemant Agrawal                        .capa_flags = 0
472864c1a40SHemant Agrawal                },
473864c1a40SHemant Agrawal                .crypto_capabilities = pmd_capabilities
474864c1a40SHemant Agrawal        },
47540ff8c99SAkhil Goyal        {
47640ff8c99SAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_NONE
47740ff8c99SAkhil Goyal        }
47840ff8c99SAkhil Goyal    };
47940ff8c99SAkhil Goyal    static const struct rte_cryptodev_capabilities pmd_capabilities[] = {
48040ff8c99SAkhil Goyal        {    /* SHA1 HMAC */
48140ff8c99SAkhil Goyal            .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
48240ff8c99SAkhil Goyal            .sym = {
48340ff8c99SAkhil Goyal                .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
48440ff8c99SAkhil Goyal                .auth = {
48540ff8c99SAkhil Goyal                    .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
48640ff8c99SAkhil Goyal                    .block_size = 64,
48740ff8c99SAkhil Goyal                    .key_size = {
48840ff8c99SAkhil Goyal                        .min = 64,
48940ff8c99SAkhil Goyal                        .max = 64,
49040ff8c99SAkhil Goyal                        .increment = 0
49140ff8c99SAkhil Goyal                    },
49240ff8c99SAkhil Goyal                    .digest_size = {
49340ff8c99SAkhil Goyal                        .min = 12,
49440ff8c99SAkhil Goyal                        .max = 12,
49540ff8c99SAkhil Goyal                        .increment = 0
49640ff8c99SAkhil Goyal                    },
49740ff8c99SAkhil Goyal                    .aad_size = { 0 },
49840ff8c99SAkhil Goyal                    .iv_size = { 0 }
49940ff8c99SAkhil Goyal                }
50040ff8c99SAkhil Goyal            }
50140ff8c99SAkhil Goyal        },
50240ff8c99SAkhil Goyal        {    /* AES CBC */
50340ff8c99SAkhil Goyal            .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
50440ff8c99SAkhil Goyal            .sym = {
50540ff8c99SAkhil Goyal                .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
50640ff8c99SAkhil Goyal                .cipher = {
50740ff8c99SAkhil Goyal                    .algo = RTE_CRYPTO_CIPHER_AES_CBC,
50840ff8c99SAkhil Goyal                    .block_size = 16,
50940ff8c99SAkhil Goyal                    .key_size = {
51040ff8c99SAkhil Goyal                        .min = 16,
51140ff8c99SAkhil Goyal                        .max = 32,
51240ff8c99SAkhil Goyal                        .increment = 8
51340ff8c99SAkhil Goyal                    },
51440ff8c99SAkhil Goyal                    .iv_size = {
51540ff8c99SAkhil Goyal                        .min = 16,
51640ff8c99SAkhil Goyal                        .max = 16,
51740ff8c99SAkhil Goyal                        .increment = 0
51840ff8c99SAkhil Goyal                    }
51940ff8c99SAkhil Goyal                }
52040ff8c99SAkhil Goyal            }
52140ff8c99SAkhil Goyal        }
52240ff8c99SAkhil Goyal    }
52340ff8c99SAkhil Goyal
524e44b3fafSDavid CoyleBelow is an example of the capabilities for a PMD which supports the DOCSIS
525e44b3fafSDavid Coyleprotocol.
526e44b3fafSDavid Coyle
527e44b3fafSDavid Coyle.. code-block:: c
528e44b3fafSDavid Coyle
529e44b3fafSDavid Coyle    static const struct rte_security_capability pmd_security_capabilities[] = {
530e44b3fafSDavid Coyle        { /* DOCSIS Uplink */
531e44b3fafSDavid Coyle                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
532e44b3fafSDavid Coyle                .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
533e44b3fafSDavid Coyle                .docsis = {
534e44b3fafSDavid Coyle                        .direction = RTE_SECURITY_DOCSIS_UPLINK
535e44b3fafSDavid Coyle                },
536e44b3fafSDavid Coyle                .crypto_capabilities = pmd_capabilities
537e44b3fafSDavid Coyle        },
538e44b3fafSDavid Coyle        { /* DOCSIS Downlink */
539e44b3fafSDavid Coyle                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
540e44b3fafSDavid Coyle                .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
541e44b3fafSDavid Coyle                .docsis = {
542e44b3fafSDavid Coyle                        .direction = RTE_SECURITY_DOCSIS_DOWNLINK
543e44b3fafSDavid Coyle                },
544e44b3fafSDavid Coyle                .crypto_capabilities = pmd_capabilities
545e44b3fafSDavid Coyle        },
546e44b3fafSDavid Coyle        {
547e44b3fafSDavid Coyle                .action = RTE_SECURITY_ACTION_TYPE_NONE
548e44b3fafSDavid Coyle        }
549e44b3fafSDavid Coyle    };
550e44b3fafSDavid Coyle    static const struct rte_cryptodev_capabilities pmd_capabilities[] = {
551e44b3fafSDavid Coyle        {    /* AES DOCSIS BPI */
552e44b3fafSDavid Coyle            .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
553e44b3fafSDavid Coyle            .sym = {
554e44b3fafSDavid Coyle                .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
555e44b3fafSDavid Coyle                .cipher = {
556e44b3fafSDavid Coyle                    .algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI,
557e44b3fafSDavid Coyle                    .block_size = 16,
558e44b3fafSDavid Coyle                    .key_size = {
559e44b3fafSDavid Coyle                        .min = 16,
560e44b3fafSDavid Coyle                        .max = 32,
561e44b3fafSDavid Coyle                        .increment = 16
562e44b3fafSDavid Coyle                    },
563e44b3fafSDavid Coyle                    .iv_size = {
564e44b3fafSDavid Coyle                        .min = 16,
565e44b3fafSDavid Coyle                        .max = 16,
566e44b3fafSDavid Coyle                        .increment = 0
567e44b3fafSDavid Coyle                    }
568e44b3fafSDavid Coyle                }
569e44b3fafSDavid Coyle            }
570e44b3fafSDavid Coyle        },
571e44b3fafSDavid Coyle
572e44b3fafSDavid Coyle        RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
573e44b3fafSDavid Coyle    };
57440ff8c99SAkhil Goyal
575*bbbe6c59SAkhil GoyalBelow is the example PMD capability for MACsec
576*bbbe6c59SAkhil Goyal
577*bbbe6c59SAkhil Goyal.. code-block:: c
578*bbbe6c59SAkhil Goyal
579*bbbe6c59SAkhil Goyal    static const struct rte_security_capability pmd_security_capabilities[] = {
580*bbbe6c59SAkhil Goyal        {
581*bbbe6c59SAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
582*bbbe6c59SAkhil Goyal                .protocol = RTE_SECURITY_PROTOCOL_MACSEC,
583*bbbe6c59SAkhil Goyal                .macsec = {
584*bbbe6c59SAkhil Goyal                        .mtu = 1500,
585*bbbe6c59SAkhil Goyal                        .alg = RTE_SECURITY_MACSEC_ALG_GCM_128,
586*bbbe6c59SAkhil Goyal                        .max_nb_sc = 64,
587*bbbe6c59SAkhil Goyal                        .max_nb_sa = 128,
588*bbbe6c59SAkhil Goyal                        .max_nb_sess = 64,
589*bbbe6c59SAkhil Goyal                        .replay_win_sz = 4096,
590*bbbe6c59SAkhil Goyal                        .relative_sectag_insert = 1,
591*bbbe6c59SAkhil Goyal                        .fixed_sectag_insert = 1,
592*bbbe6c59SAkhil Goyal                        .icv_include_da_sa = 1,
593*bbbe6c59SAkhil Goyal                        .ctrl_port_enable = 1,
594*bbbe6c59SAkhil Goyal                        .preserve_sectag = 1,
595*bbbe6c59SAkhil Goyal                        .preserve_icv = 1,
596*bbbe6c59SAkhil Goyal                        .validate_frames = 1,
597*bbbe6c59SAkhil Goyal                        .re_key = 1,
598*bbbe6c59SAkhil Goyal                        .anti_replay = 1,
599*bbbe6c59SAkhil Goyal                },
600*bbbe6c59SAkhil Goyal                .crypto_capabilities = NULL,
601*bbbe6c59SAkhil Goyal        },
602*bbbe6c59SAkhil Goyal    };
603*bbbe6c59SAkhil Goyal
60440ff8c99SAkhil GoyalCapabilities Discovery
60540ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~
60640ff8c99SAkhil Goyal
60740ff8c99SAkhil GoyalDiscovering the features and capabilities of a driver (crypto/ethernet)
60840ff8c99SAkhil Goyalis achieved through the ``rte_security_capabilities_get()`` function.
60940ff8c99SAkhil Goyal
61040ff8c99SAkhil Goyal.. code-block:: c
61140ff8c99SAkhil Goyal
61240ff8c99SAkhil Goyal   const struct rte_security_capability *rte_security_capabilities_get(uint16_t id);
61340ff8c99SAkhil Goyal
61440ff8c99SAkhil GoyalThis allows the user to query a specific driver and get all device
61540ff8c99SAkhil Goyalsecurity capabilities. It returns an array of ``rte_security_capability`` structures
61640ff8c99SAkhil Goyalwhich contains all the capabilities for that device.
61740ff8c99SAkhil Goyal
61840ff8c99SAkhil GoyalSecurity Session Create/Free
61940ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~
62040ff8c99SAkhil Goyal
62140ff8c99SAkhil GoyalSecurity Sessions are created to store the immutable fields of a particular Security
62240ff8c99SAkhil GoyalAssociation for a particular protocol which is defined by a security session
62340ff8c99SAkhil Goyalconfiguration structure which is used in the operation processing of a packet flow.
62440ff8c99SAkhil GoyalSessions are used to manage protocol specific information as well as crypto parameters.
62540ff8c99SAkhil GoyalSecurity sessions cache this immutable data in a optimal way for the underlying PMD
62640ff8c99SAkhil Goyaland this allows further acceleration of the offload of Crypto workloads.
62740ff8c99SAkhil Goyal
62840ff8c99SAkhil GoyalThe Security framework provides APIs to create and free sessions for crypto/ethernet
62940ff8c99SAkhil Goyaldevices, where sessions are mempool objects. It is the application's responsibility
630e30b2833SAkhil Goyalto create and manage two session mempools - one for session and other for session
631e30b2833SAkhil Goyalprivate data. The private session data mempool object size should be able to
632e30b2833SAkhil Goyalaccommodate the driver's private data of security session. The application can get
633e30b2833SAkhil Goyalthe size of session private data using API ``rte_security_session_get_size``.
634e30b2833SAkhil GoyalAnd the session mempool object size should be enough to accommodate
635e30b2833SAkhil Goyal``rte_security_session``.
63640ff8c99SAkhil Goyal
63740ff8c99SAkhil GoyalOnce the session mempools have been created, ``rte_security_session_create()``
63840ff8c99SAkhil Goyalis used to allocate and initialize a session for the required crypto/ethernet device.
63940ff8c99SAkhil Goyal
64040ff8c99SAkhil GoyalSession APIs need a parameter ``rte_security_ctx`` to identify the crypto/ethernet
64140ff8c99SAkhil Goyalsecurity ops. This parameter can be retrieved using the APIs
64240ff8c99SAkhil Goyal``rte_cryptodev_get_sec_ctx()`` (for crypto device) or ``rte_eth_dev_get_sec_ctx``
64340ff8c99SAkhil Goyal(for ethernet port).
64440ff8c99SAkhil Goyal
64540ff8c99SAkhil GoyalSessions already created can be updated with ``rte_security_session_update()``.
64640ff8c99SAkhil Goyal
64740ff8c99SAkhil GoyalWhen a session is no longer used, the user must call ``rte_security_session_destroy()``
64840ff8c99SAkhil Goyalto free the driver private session data and return the memory back to the mempool.
64940ff8c99SAkhil Goyal
65040ff8c99SAkhil GoyalFor look aside protocol offload to hardware crypto device, the ``rte_crypto_op``
65140ff8c99SAkhil Goyalcreated by the application is attached to the security session by the API
65240ff8c99SAkhil Goyal``rte_security_attach_session()``.
65340ff8c99SAkhil Goyal
65440ff8c99SAkhil GoyalFor Inline Crypto and Inline protocol offload, device specific defined metadata is
65540ff8c99SAkhil Goyalupdated in the mbuf using ``rte_security_set_pkt_metadata()`` if
656295968d1SFerruh Yigit``RTE_ETH_TX_OFFLOAD_SEC_NEED_MDATA`` is set.
65740ff8c99SAkhil Goyal
6581a08c379SAnoob JosephFor inline protocol offloaded ingress traffic, the application can register a
6591a08c379SAnoob Josephpointer, ``userdata`` , in the security session. When the packet is received,
6601a08c379SAnoob Joseph``rte_security_get_userdata()`` would return the userdata registered for the
6611a08c379SAnoob Josephsecurity session which processed the packet.
6621a08c379SAnoob Joseph
6631a08c379SAnoob Joseph.. note::
6641a08c379SAnoob Joseph
665614af754SThomas Monjalon    In case of inline processed packets, ``RTE_SECURITY_DYNFIELD_NAME`` field
666614af754SThomas Monjalon    would be used by the driver to relay information on the security processing
6671a08c379SAnoob Joseph    associated with the packet. In ingress, the driver would set this in Rx
6681a08c379SAnoob Joseph    path while in egress, ``rte_security_set_pkt_metadata()`` would perform a
6691a08c379SAnoob Joseph    similar operation. The application is expected not to modify the field
6701a08c379SAnoob Joseph    when it has relevant info. For ingress, this device-specific 64 bit value
6711a08c379SAnoob Joseph    is required to derive other information (like userdata), required for
6721a08c379SAnoob Joseph    identifying the security processing done on the packet.
6731a08c379SAnoob Joseph
67440ff8c99SAkhil GoyalSecurity session configuration
67540ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
67640ff8c99SAkhil Goyal
67740ff8c99SAkhil GoyalSecurity Session configuration structure is defined as ``rte_security_session_conf``
67840ff8c99SAkhil Goyal
67940ff8c99SAkhil Goyal.. code-block:: c
68040ff8c99SAkhil Goyal
68140ff8c99SAkhil Goyal    struct rte_security_session_conf {
68240ff8c99SAkhil Goyal        enum rte_security_session_action_type action_type;
68340ff8c99SAkhil Goyal        /**< Type of action to be performed on the session */
68440ff8c99SAkhil Goyal        enum rte_security_session_protocol protocol;
68540ff8c99SAkhil Goyal        /**< Security protocol to be configured */
68640ff8c99SAkhil Goyal        union {
68740ff8c99SAkhil Goyal                struct rte_security_ipsec_xform ipsec;
68840ff8c99SAkhil Goyal                struct rte_security_macsec_xform macsec;
6898b593b8cSAkhil Goyal                struct rte_security_pdcp_xform pdcp;
690e44b3fafSDavid Coyle                struct rte_security_docsis_xform docsis;
69140ff8c99SAkhil Goyal        };
69240ff8c99SAkhil Goyal        /**< Configuration parameters for security session */
69340ff8c99SAkhil Goyal        struct rte_crypto_sym_xform *crypto_xform;
69440ff8c99SAkhil Goyal        /**< Security Session Crypto Transformations */
6951a08c379SAnoob Joseph        void *userdata;
6961a08c379SAnoob Joseph        /**< Application specific userdata to be saved with session */
69740ff8c99SAkhil Goyal    };
69840ff8c99SAkhil Goyal
69940ff8c99SAkhil GoyalThe configuration structure reuses the ``rte_crypto_sym_xform`` struct for crypto related
70040ff8c99SAkhil Goyalconfiguration. The ``rte_security_session_action_type`` struct is used to specify whether the
70140ff8c99SAkhil Goyalsession is configured for Lookaside Protocol offload or Inline Crypto or Inline Protocol
70240ff8c99SAkhil GoyalOffload.
70340ff8c99SAkhil Goyal
70440ff8c99SAkhil Goyal.. code-block:: c
70540ff8c99SAkhil Goyal
70640ff8c99SAkhil Goyal    enum rte_security_session_action_type {
70740ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_NONE,
70840ff8c99SAkhil Goyal        /**< No security actions */
70940ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
71040ff8c99SAkhil Goyal        /**< Crypto processing for security protocol is processed inline
7115d6d7e44SMarcin Smoczynski         * during transmission
7125d6d7e44SMarcin Smoczynski         */
71340ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
71440ff8c99SAkhil Goyal        /**< All security protocol processing is performed inline during
7155d6d7e44SMarcin Smoczynski         * transmission
7165d6d7e44SMarcin Smoczynski         */
7175d6d7e44SMarcin Smoczynski        RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
71840ff8c99SAkhil Goyal        /**< All security protocol processing including crypto is performed
7195d6d7e44SMarcin Smoczynski         * on a lookaside accelerator
7205d6d7e44SMarcin Smoczynski         */
7215d6d7e44SMarcin Smoczynski        RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO
7225d6d7e44SMarcin Smoczynski        /**< Similar to ACTION_TYPE_NONE but crypto processing for security
7235d6d7e44SMarcin Smoczynski         * protocol is processed synchronously by a CPU.
7245d6d7e44SMarcin Smoczynski         */
72540ff8c99SAkhil Goyal    };
72640ff8c99SAkhil Goyal
72740ff8c99SAkhil GoyalThe ``rte_security_session_protocol`` is defined as
72840ff8c99SAkhil Goyal
72940ff8c99SAkhil Goyal.. code-block:: c
73040ff8c99SAkhil Goyal
73140ff8c99SAkhil Goyal    enum rte_security_session_protocol {
7328b593b8cSAkhil Goyal        RTE_SECURITY_PROTOCOL_IPSEC = 1,
73340ff8c99SAkhil Goyal        /**< IPsec Protocol */
73440ff8c99SAkhil Goyal        RTE_SECURITY_PROTOCOL_MACSEC,
73540ff8c99SAkhil Goyal        /**< MACSec Protocol */
7368b593b8cSAkhil Goyal        RTE_SECURITY_PROTOCOL_PDCP,
7378b593b8cSAkhil Goyal        /**< PDCP Protocol */
738e44b3fafSDavid Coyle        RTE_SECURITY_PROTOCOL_DOCSIS,
739e44b3fafSDavid Coyle        /**< DOCSIS Protocol */
74040ff8c99SAkhil Goyal    };
74140ff8c99SAkhil Goyal
7428b593b8cSAkhil GoyalCurrently the library defines configuration parameters for IPsec and PDCP only.
7438b593b8cSAkhil GoyalFor other protocols like MACSec, structures and enums are defined as place holders
7448b593b8cSAkhil Goyalwhich will be updated in the future.
74540ff8c99SAkhil Goyal
74640ff8c99SAkhil GoyalIPsec related configuration parameters are defined in ``rte_security_ipsec_xform``
74740ff8c99SAkhil Goyal
748*bbbe6c59SAkhil GoyalMACsec related configuration parameters are defined in ``rte_security_macsec_xform``
749*bbbe6c59SAkhil Goyal
7508b593b8cSAkhil GoyalPDCP related configuration parameters are defined in ``rte_security_pdcp_xform``
7518b593b8cSAkhil Goyal
752e44b3fafSDavid CoyleDOCSIS related configuration parameters are defined in ``rte_security_docsis_xform``
753e44b3fafSDavid Coyle
75440ff8c99SAkhil Goyal
75540ff8c99SAkhil GoyalSecurity API
75640ff8c99SAkhil Goyal~~~~~~~~~~~~
75740ff8c99SAkhil Goyal
75840ff8c99SAkhil GoyalThe rte_security Library API is described in the *DPDK API Reference* document.
75940ff8c99SAkhil Goyal
76040ff8c99SAkhil GoyalFlow based Security Session
76140ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~
76240ff8c99SAkhil Goyal
76340ff8c99SAkhil GoyalIn the case of NIC based offloads, the security session specified in the
76440ff8c99SAkhil Goyal'rte_flow_action_security' must be created on the same port as the
76540ff8c99SAkhil Goyalflow action that is being specified.
76640ff8c99SAkhil Goyal
76740ff8c99SAkhil GoyalThe ingress/egress flow attribute should match that specified in the security
76840ff8c99SAkhil Goyalsession if the security session supports the definition of the direction.
76940ff8c99SAkhil Goyal
77040ff8c99SAkhil GoyalMultiple flows can be configured to use the same security session. For
771*bbbe6c59SAkhil Goyalexample if the security session specifies an egress IPsec/MACsec SA, then multiple
77240ff8c99SAkhil Goyalflows can be specified to that SA. In the case of an ingress IPsec SA then
77340ff8c99SAkhil Goyalit is only valid to have a single flow to map to that security session.
77440ff8c99SAkhil Goyal
77540ff8c99SAkhil Goyal.. code-block:: console
77640ff8c99SAkhil Goyal
77740ff8c99SAkhil Goyal         Configuration Path
77840ff8c99SAkhil Goyal                 |
77940ff8c99SAkhil Goyal        +--------|--------+
78040ff8c99SAkhil Goyal        |    Add/Remove   |
781*bbbe6c59SAkhil Goyal        | IPsec/MACsec SA |   <------ Build security flow action of
782*bbbe6c59SAkhil Goyal        |        |        |           IPsec/MACsec transform
78340ff8c99SAkhil Goyal        |--------|--------|
78440ff8c99SAkhil Goyal                 |
78540ff8c99SAkhil Goyal        +--------V--------+
78640ff8c99SAkhil Goyal        |   Flow API      |
78740ff8c99SAkhil Goyal        +--------|--------+
78840ff8c99SAkhil Goyal                 |
78940ff8c99SAkhil Goyal        +--------V--------+
79040ff8c99SAkhil Goyal        |                 |
79140ff8c99SAkhil Goyal        |     NIC PMD     |   <------ Add/Remove SA to/from hw context
79240ff8c99SAkhil Goyal        |                 |
79340ff8c99SAkhil Goyal        +--------|--------+
79440ff8c99SAkhil Goyal                 |
79540ff8c99SAkhil Goyal        +--------|--------+
79640ff8c99SAkhil Goyal        |  HW ACCELERATED |
79740ff8c99SAkhil Goyal        |        NIC      |
79840ff8c99SAkhil Goyal        |                 |
79940ff8c99SAkhil Goyal        +--------|--------+
80040ff8c99SAkhil Goyal
801*bbbe6c59SAkhil Goyal* Add/Delete IPsec SA flow:
80240ff8c99SAkhil Goyal  To add a new inline SA construct a rte_flow_item for Ethernet + IP + ESP
803*bbbe6c59SAkhil Goyal  using the SA selectors and the ``rte_security_ipsec_xform`` as the ``rte_flow_action``.
80440ff8c99SAkhil Goyal  Note that any rte_flow_items may be empty, which means it is not checked.
80540ff8c99SAkhil Goyal
80640ff8c99SAkhil Goyal.. code-block:: console
80740ff8c99SAkhil Goyal
80840ff8c99SAkhil Goyal    In its most basic form, IPsec flow specification is as follows:
80940ff8c99SAkhil Goyal        +-------+     +----------+    +--------+    +-----+
81040ff8c99SAkhil Goyal        |  Eth  | ->  |   IP4/6  | -> |   ESP  | -> | END |
81140ff8c99SAkhil Goyal        +-------+     +----------+    +--------+    +-----+
81240ff8c99SAkhil Goyal
81340ff8c99SAkhil Goyal    However, the API can represent, IPsec crypto offload with any encapsulation:
81440ff8c99SAkhil Goyal        +-------+            +--------+    +-----+
81540ff8c99SAkhil Goyal        |  Eth  | ->  ... -> |   ESP  | -> | END |
81640ff8c99SAkhil Goyal        +-------+            +--------+    +-----+
817259ca6d1SGowrishankar Muthukrishnan
818*bbbe6c59SAkhil Goyal* Add/Delete MACsec SA flow:
819*bbbe6c59SAkhil Goyal  To add a new inline SA construct a rte_flow_item for Ethernet + SecTAG
820*bbbe6c59SAkhil Goyal  using the SA selectors and the ``rte_security_macsec_xform`` as the ``rte_flow_action``.
821*bbbe6c59SAkhil Goyal  Note that any rte_flow_items may be empty, which means it is not checked.
822*bbbe6c59SAkhil Goyal
823*bbbe6c59SAkhil Goyal.. code-block:: console
824*bbbe6c59SAkhil Goyal
825*bbbe6c59SAkhil Goyal    In its most basic form, MACsec flow specification is as follows:
826*bbbe6c59SAkhil Goyal        +-------+     +----------+     +-----+
827*bbbe6c59SAkhil Goyal        |  Eth  | ->  |  SecTag  |  -> | END |
828*bbbe6c59SAkhil Goyal        +-------+     +----------+     +-----+
829*bbbe6c59SAkhil Goyal
830*bbbe6c59SAkhil Goyal    However, the API can represent, MACsec offload with any encapsulation:
831*bbbe6c59SAkhil Goyal        +-------+            +--------+    +-----+
832*bbbe6c59SAkhil Goyal        |  Eth  | ->  ... -> | SecTag | -> | END |
833*bbbe6c59SAkhil Goyal        +-------+            +--------+    +-----+
834*bbbe6c59SAkhil Goyal
835259ca6d1SGowrishankar Muthukrishnan
836259ca6d1SGowrishankar MuthukrishnanTelemetry support
837259ca6d1SGowrishankar Muthukrishnan-----------------
838259ca6d1SGowrishankar Muthukrishnan
839259ca6d1SGowrishankar MuthukrishnanThe Security library has support for displaying Crypto device information
840259ca6d1SGowrishankar Muthukrishnanwith respect to its Security capabilities. Telemetry commands that can be used
841259ca6d1SGowrishankar Muthukrishnanare shown below.
842259ca6d1SGowrishankar Muthukrishnan
843259ca6d1SGowrishankar Muthukrishnan#. Get the list of available Crypto devices by ID, that supports Security features::
844259ca6d1SGowrishankar Muthukrishnan
845259ca6d1SGowrishankar Muthukrishnan     --> /security/cryptodev/list
846259ca6d1SGowrishankar Muthukrishnan     {"/security/cryptodev/list": [0, 1, 2, 3]}
847259ca6d1SGowrishankar Muthukrishnan
848259ca6d1SGowrishankar Muthukrishnan#. Get the security capabilities of a Crypto device::
849259ca6d1SGowrishankar Muthukrishnan
850259ca6d1SGowrishankar Muthukrishnan     --> /security/cryptodev/sec_caps,0
851259ca6d1SGowrishankar Muthukrishnan	 {"/security/cryptodev/sec_caps": {"sec_caps": [<array of serialized bytes of
852259ca6d1SGowrishankar Muthukrishnan	 capabilities>], "sec_caps_n": <number of capabilities>}}
853259ca6d1SGowrishankar Muthukrishnan
854259ca6d1SGowrishankar Muthukrishnan #. Get the security crypto capabilities of a Crypto device::
855259ca6d1SGowrishankar Muthukrishnan
856259ca6d1SGowrishankar Muthukrishnan     --> /security/cryptodev/crypto_caps,0,0
857259ca6d1SGowrishankar Muthukrishnan	 {"/security/cryptodev/crypto_caps": {"crypto_caps": [<array of serialized bytes of
858259ca6d1SGowrishankar Muthukrishnan	 capabilities>], "crypto_caps_n": <number of capabilities>}}
859259ca6d1SGowrishankar Muthukrishnan
860259ca6d1SGowrishankar MuthukrishnanFor more information on how to use the Telemetry interface, see
861259ca6d1SGowrishankar Muthukrishnanthe :doc:`../howto/telemetry`.
862