xref: /dpdk/doc/guides/prog_guide/rte_security.rst (revision 40ff8c99ea99bd890b9b2a306b1310893dd7ce5a)
1*40ff8c99SAkhil Goyal..  BSD LICENSE
2*40ff8c99SAkhil Goyal    Copyright 2017 NXP.
3*40ff8c99SAkhil Goyal
4*40ff8c99SAkhil Goyal    Redistribution and use in source and binary forms, with or without
5*40ff8c99SAkhil Goyal    modification, are permitted provided that the following conditions
6*40ff8c99SAkhil Goyal    are met:
7*40ff8c99SAkhil Goyal
8*40ff8c99SAkhil Goyal    * Redistributions of source code must retain the above copyright
9*40ff8c99SAkhil Goyal    notice, this list of conditions and the following disclaimer.
10*40ff8c99SAkhil Goyal    * Redistributions in binary form must reproduce the above copyright
11*40ff8c99SAkhil Goyal    notice, this list of conditions and the following disclaimer in
12*40ff8c99SAkhil Goyal    the documentation and/or other materials provided with the
13*40ff8c99SAkhil Goyal    distribution.
14*40ff8c99SAkhil Goyal    * Neither the name of NXP nor the names of its
15*40ff8c99SAkhil Goyal    contributors may be used to endorse or promote products derived
16*40ff8c99SAkhil Goyal    from this software without specific prior written permission.
17*40ff8c99SAkhil Goyal
18*40ff8c99SAkhil Goyal    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19*40ff8c99SAkhil Goyal    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20*40ff8c99SAkhil Goyal    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21*40ff8c99SAkhil Goyal    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22*40ff8c99SAkhil Goyal    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23*40ff8c99SAkhil Goyal    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24*40ff8c99SAkhil Goyal    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25*40ff8c99SAkhil Goyal    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26*40ff8c99SAkhil Goyal    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27*40ff8c99SAkhil Goyal    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28*40ff8c99SAkhil Goyal    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29*40ff8c99SAkhil Goyal
30*40ff8c99SAkhil Goyal
31*40ff8c99SAkhil GoyalSecurity Library
32*40ff8c99SAkhil Goyal================
33*40ff8c99SAkhil Goyal
34*40ff8c99SAkhil GoyalThe security library provides a framework for management and provisioning
35*40ff8c99SAkhil Goyalof security protocol operations offloaded to hardware based devices. The
36*40ff8c99SAkhil Goyallibrary defines generic APIs to create and free security sessions which can
37*40ff8c99SAkhil Goyalsupport full protocol offload as well as inline crypto operation with
38*40ff8c99SAkhil GoyalNIC or crypto devices. The framework currently only supports the IPSec protocol
39*40ff8c99SAkhil Goyaland associated operations, other protocols will be added in future.
40*40ff8c99SAkhil Goyal
41*40ff8c99SAkhil GoyalDesign Principles
42*40ff8c99SAkhil Goyal-----------------
43*40ff8c99SAkhil Goyal
44*40ff8c99SAkhil GoyalThe security library provides an additional offload capability to an existing
45*40ff8c99SAkhil Goyalcrypto device and/or ethernet device.
46*40ff8c99SAkhil Goyal
47*40ff8c99SAkhil Goyal.. code-block:: console
48*40ff8c99SAkhil Goyal
49*40ff8c99SAkhil Goyal               +---------------+
50*40ff8c99SAkhil Goyal               | rte_security  |
51*40ff8c99SAkhil Goyal               +---------------+
52*40ff8c99SAkhil Goyal                 \            /
53*40ff8c99SAkhil Goyal        +-----------+    +--------------+
54*40ff8c99SAkhil Goyal        |  NIC PMD  |    |  CRYPTO PMD  |
55*40ff8c99SAkhil Goyal        +-----------+    +--------------+
56*40ff8c99SAkhil Goyal
57*40ff8c99SAkhil Goyal.. note::
58*40ff8c99SAkhil Goyal
59*40ff8c99SAkhil Goyal    Currently, the security library does not support the case of multi-process.
60*40ff8c99SAkhil Goyal    It will be updated in the future releases.
61*40ff8c99SAkhil Goyal
62*40ff8c99SAkhil GoyalThe supported offload types are explained in the sections below.
63*40ff8c99SAkhil Goyal
64*40ff8c99SAkhil GoyalInline Crypto
65*40ff8c99SAkhil Goyal~~~~~~~~~~~~~
66*40ff8c99SAkhil Goyal
67*40ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO:
68*40ff8c99SAkhil GoyalThe crypto processing for security protocol (e.g. IPSec) is processed
69*40ff8c99SAkhil Goyalinline during receive and transmission on NIC port. The flow based
70*40ff8c99SAkhil Goyalsecurity action should be configured on the port.
71*40ff8c99SAkhil Goyal
72*40ff8c99SAkhil GoyalIngress Data path - The packet is decrypted in RX path and relevant
73*40ff8c99SAkhil Goyalcrypto status is set in Rx descriptors. After the successful inline
74*40ff8c99SAkhil Goyalcrypto processing the packet is presented to host as a regular Rx packet
75*40ff8c99SAkhil Goyalhowever all security protocol related headers are still attached to the
76*40ff8c99SAkhil Goyalpacket. e.g. In case of IPSec, the IPSec tunnel headers (if any),
77*40ff8c99SAkhil GoyalESP/AH headers will remain in the packet but the received packet
78*40ff8c99SAkhil Goyalcontains the decrypted data where the encrypted data was when the packet
79*40ff8c99SAkhil Goyalarrived. The driver Rx path check the descriptors and and based on the
80*40ff8c99SAkhil Goyalcrypto status sets additional flags in the rte_mbuf.ol_flags field.
81*40ff8c99SAkhil Goyal
82*40ff8c99SAkhil Goyal.. note::
83*40ff8c99SAkhil Goyal
84*40ff8c99SAkhil Goyal    The underlying device may not support crypto processing for all ingress packet
85*40ff8c99SAkhil Goyal    matching to a particular flow (e.g. fragmented packets), such packets will
86*40ff8c99SAkhil Goyal    be passed as encrypted packets. It is the responsibility of application to
87*40ff8c99SAkhil Goyal    process such encrypted packets using other crypto driver instance.
88*40ff8c99SAkhil Goyal
89*40ff8c99SAkhil GoyalEgress Data path - The software prepares the egress packet by adding
90*40ff8c99SAkhil Goyalrelevant security protocol headers. Only the data will not be
91*40ff8c99SAkhil Goyalencrypted by the software. The driver will accordingly configure the
92*40ff8c99SAkhil Goyaltx descriptors. The hardware device will encrypt the data before sending the
93*40ff8c99SAkhil Goyalthe packet out.
94*40ff8c99SAkhil Goyal
95*40ff8c99SAkhil Goyal.. note::
96*40ff8c99SAkhil Goyal
97*40ff8c99SAkhil Goyal    The underlying device may support post encryption TSO.
98*40ff8c99SAkhil Goyal
99*40ff8c99SAkhil Goyal.. code-block:: console
100*40ff8c99SAkhil Goyal
101*40ff8c99SAkhil Goyal          Egress Data Path
102*40ff8c99SAkhil Goyal                 |
103*40ff8c99SAkhil Goyal        +--------|--------+
104*40ff8c99SAkhil Goyal        |  egress IPsec   |
105*40ff8c99SAkhil Goyal        |        |        |
106*40ff8c99SAkhil Goyal        | +------V------+ |
107*40ff8c99SAkhil Goyal        | | SADB lookup | |
108*40ff8c99SAkhil Goyal        | +------|------+ |
109*40ff8c99SAkhil Goyal        | +------V------+ |
110*40ff8c99SAkhil Goyal        | |   Tunnel    | |   <------ Add tunnel header to packet
111*40ff8c99SAkhil Goyal        | +------|------+ |
112*40ff8c99SAkhil Goyal        | +------V------+ |
113*40ff8c99SAkhil Goyal        | |     ESP     | |   <------ Add ESP header without trailer to packet
114*40ff8c99SAkhil Goyal        | |             | |   <------ Mark packet to be offloaded, add trailer
115*40ff8c99SAkhil Goyal        | +------|------+ |            meta-data to mbuf
116*40ff8c99SAkhil Goyal        +--------V--------+
117*40ff8c99SAkhil Goyal                 |
118*40ff8c99SAkhil Goyal        +--------V--------+
119*40ff8c99SAkhil Goyal        |    L2 Stack     |
120*40ff8c99SAkhil Goyal        +--------|--------+
121*40ff8c99SAkhil Goyal                 |
122*40ff8c99SAkhil Goyal        +--------V--------+
123*40ff8c99SAkhil Goyal        |                 |
124*40ff8c99SAkhil Goyal        |     NIC PMD     |   <------ Set hw context for inline crypto offload
125*40ff8c99SAkhil Goyal        |                 |
126*40ff8c99SAkhil Goyal        +--------|--------+
127*40ff8c99SAkhil Goyal                 |
128*40ff8c99SAkhil Goyal        +--------|--------+
129*40ff8c99SAkhil Goyal        |  HW ACCELERATED |   <------ Packet Encryption and
130*40ff8c99SAkhil Goyal        |        NIC      |           Authentication happens inline
131*40ff8c99SAkhil Goyal        |                 |
132*40ff8c99SAkhil Goyal        +-----------------+
133*40ff8c99SAkhil Goyal
134*40ff8c99SAkhil Goyal
135*40ff8c99SAkhil GoyalInline protocol offload
136*40ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~
137*40ff8c99SAkhil Goyal
138*40ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL:
139*40ff8c99SAkhil GoyalThe crypto and protocol processing for security protocol (e.g. IPSec)
140*40ff8c99SAkhil Goyalis processed inline during receive and transmission.  The flow based
141*40ff8c99SAkhil Goyalsecurity action should be configured on the port.
142*40ff8c99SAkhil Goyal
143*40ff8c99SAkhil GoyalIngress Data path - The packet is decrypted in the RX path and relevant
144*40ff8c99SAkhil Goyalcrypto status is set in the Rx descriptors. After the successful inline
145*40ff8c99SAkhil Goyalcrypto processing the packet is presented to the host as a regular Rx packet
146*40ff8c99SAkhil Goyalbut all security protocol related headers are optionally removed from the
147*40ff8c99SAkhil Goyalpacket. e.g. in the case of IPSec, the IPSec tunnel headers (if any),
148*40ff8c99SAkhil GoyalESP/AH headers will be removed from the packet and the received packet
149*40ff8c99SAkhil Goyalwill contains the decrypted packet only. The driver Rx path checks the
150*40ff8c99SAkhil Goyaldescriptors and based on the crypto status sets additional flags in
151*40ff8c99SAkhil Goyal``rte_mbuf.ol_flags`` field.
152*40ff8c99SAkhil Goyal
153*40ff8c99SAkhil Goyal.. note::
154*40ff8c99SAkhil Goyal
155*40ff8c99SAkhil Goyal    The underlying device in this case is stateful. It is expected that
156*40ff8c99SAkhil Goyal    the device shall support crypto processing for all kind of packets matching
157*40ff8c99SAkhil Goyal    to a given flow, this includes fragmented packets (post reassembly).
158*40ff8c99SAkhil Goyal    E.g. in case of IPSec the device may internally manage anti-replay etc.
159*40ff8c99SAkhil Goyal    It will provide a configuration option for anti-replay behavior i.e. to drop
160*40ff8c99SAkhil Goyal    the packets or pass them to driver with error flags set in the descriptor.
161*40ff8c99SAkhil Goyal
162*40ff8c99SAkhil GoyalEgress Data path - The software will send the plain packet without any
163*40ff8c99SAkhil Goyalsecurity protocol headers added to the packet. The driver will configure
164*40ff8c99SAkhil Goyalthe security index and other requirement in tx descriptors.
165*40ff8c99SAkhil GoyalThe hardware device will do security processing on the packet that includes
166*40ff8c99SAkhil Goyaladding the relevant protocol headers and encrypting the data before sending
167*40ff8c99SAkhil Goyalthe packet out. The software should make sure that the buffer
168*40ff8c99SAkhil Goyalhas required head room and tail room for any protocol header addition. The
169*40ff8c99SAkhil Goyalsoftware may also do early fragmentation if the resultant packet is expected
170*40ff8c99SAkhil Goyalto cross the MTU size.
171*40ff8c99SAkhil Goyal
172*40ff8c99SAkhil Goyal
173*40ff8c99SAkhil Goyal.. note::
174*40ff8c99SAkhil Goyal
175*40ff8c99SAkhil Goyal    The underlying device will manage state information required for egress
176*40ff8c99SAkhil Goyal    processing. E.g. in case of IPSec, the seq number will be added to the
177*40ff8c99SAkhil Goyal    packet, however the device shall provide indication when the sequence number
178*40ff8c99SAkhil Goyal    is about to overflow. The underlying device may support post encryption TSO.
179*40ff8c99SAkhil Goyal
180*40ff8c99SAkhil Goyal.. code-block:: console
181*40ff8c99SAkhil Goyal
182*40ff8c99SAkhil Goyal         Egress Data Path
183*40ff8c99SAkhil Goyal                 |
184*40ff8c99SAkhil Goyal        +--------|--------+
185*40ff8c99SAkhil Goyal        |  egress IPsec   |
186*40ff8c99SAkhil Goyal        |        |        |
187*40ff8c99SAkhil Goyal        | +------V------+ |
188*40ff8c99SAkhil Goyal        | | SADB lookup | |
189*40ff8c99SAkhil Goyal        | +------|------+ |
190*40ff8c99SAkhil Goyal        | +------V------+ |
191*40ff8c99SAkhil Goyal        | |   Desc      | |   <------ Mark packet to be offloaded
192*40ff8c99SAkhil Goyal        | +------|------+ |
193*40ff8c99SAkhil Goyal        +--------V--------+
194*40ff8c99SAkhil Goyal                 |
195*40ff8c99SAkhil Goyal        +--------V--------+
196*40ff8c99SAkhil Goyal        |    L2 Stack     |
197*40ff8c99SAkhil Goyal        +--------|--------+
198*40ff8c99SAkhil Goyal                 |
199*40ff8c99SAkhil Goyal        +--------V--------+
200*40ff8c99SAkhil Goyal        |                 |
201*40ff8c99SAkhil Goyal        |     NIC PMD     |   <------ Set hw context for inline crypto offload
202*40ff8c99SAkhil Goyal        |                 |
203*40ff8c99SAkhil Goyal        +--------|--------+
204*40ff8c99SAkhil Goyal                 |
205*40ff8c99SAkhil Goyal        +--------|--------+
206*40ff8c99SAkhil Goyal        |  HW ACCELERATED |   <------ Add tunnel, ESP header etc header to
207*40ff8c99SAkhil Goyal        |        NIC      |           packet. Packet Encryption and
208*40ff8c99SAkhil Goyal        |                 |           Authentication happens inline.
209*40ff8c99SAkhil Goyal        +-----------------+
210*40ff8c99SAkhil Goyal
211*40ff8c99SAkhil Goyal
212*40ff8c99SAkhil GoyalLookaside protocol offload
213*40ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~
214*40ff8c99SAkhil Goyal
215*40ff8c99SAkhil GoyalRTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL:
216*40ff8c99SAkhil GoyalThis extends librte_cryptodev to support the programming of IPsec
217*40ff8c99SAkhil GoyalSecurity Association (SA) as part of a crypto session creation including
218*40ff8c99SAkhil Goyalthe definition. In addition to standard crypto processing, as defined by
219*40ff8c99SAkhil Goyalthe cryptodev, the security protocol processing is also offloaded to the
220*40ff8c99SAkhil Goyalcrypto device.
221*40ff8c99SAkhil Goyal
222*40ff8c99SAkhil GoyalDecryption: The packet is sent to the crypto device for security
223*40ff8c99SAkhil Goyalprotocol processing. The device will decrypt the packet and it will also
224*40ff8c99SAkhil Goyaloptionally remove additional security headers from the packet.
225*40ff8c99SAkhil GoyalE.g. in case of IPSec, IPSec tunnel headers (if any), ESP/AH headers
226*40ff8c99SAkhil Goyalwill be removed from the packet and the decrypted packet may contain
227*40ff8c99SAkhil Goyalplain data only.
228*40ff8c99SAkhil Goyal
229*40ff8c99SAkhil Goyal.. note::
230*40ff8c99SAkhil Goyal
231*40ff8c99SAkhil Goyal    In case of IPSec the device may internally manage anti-replay etc.
232*40ff8c99SAkhil Goyal    It will provide a configuration option for anti-replay behavior i.e. to drop
233*40ff8c99SAkhil Goyal    the packets or pass them to driver with error flags set in descriptor.
234*40ff8c99SAkhil Goyal
235*40ff8c99SAkhil GoyalEncryption: The software will submit the packet to cryptodev as usual
236*40ff8c99SAkhil Goyalfor encryption, the hardware device in this case will also add the relevant
237*40ff8c99SAkhil Goyalsecurity protocol header along with encrypting the packet. The software
238*40ff8c99SAkhil Goyalshould make sure that the buffer has required head room and tail room
239*40ff8c99SAkhil Goyalfor any protocol header addition.
240*40ff8c99SAkhil Goyal
241*40ff8c99SAkhil Goyal.. note::
242*40ff8c99SAkhil Goyal
243*40ff8c99SAkhil Goyal    In the case of IPSec, the seq number will be added to the packet,
244*40ff8c99SAkhil Goyal    It shall provide an indication when the sequence number is about to
245*40ff8c99SAkhil Goyal    overflow.
246*40ff8c99SAkhil Goyal
247*40ff8c99SAkhil Goyal.. code-block:: console
248*40ff8c99SAkhil Goyal
249*40ff8c99SAkhil Goyal          Egress Data Path
250*40ff8c99SAkhil Goyal                 |
251*40ff8c99SAkhil Goyal        +--------|--------+
252*40ff8c99SAkhil Goyal        |  egress IPsec   |
253*40ff8c99SAkhil Goyal        |        |        |
254*40ff8c99SAkhil Goyal        | +------V------+ |
255*40ff8c99SAkhil Goyal        | | SADB lookup | |   <------ SA maps to cryptodev session
256*40ff8c99SAkhil Goyal        | +------|------+ |
257*40ff8c99SAkhil Goyal        | +------|------+ |
258*40ff8c99SAkhil Goyal        | |      \--------------------\
259*40ff8c99SAkhil Goyal        | |    Crypto   | |           |  <- Crypto processing through
260*40ff8c99SAkhil Goyal        | |      /----------------\   |     inline crypto PMD
261*40ff8c99SAkhil Goyal        | +------|------+ |       |   |
262*40ff8c99SAkhil Goyal        +--------V--------+       |   |
263*40ff8c99SAkhil Goyal                 |                |   |
264*40ff8c99SAkhil Goyal        +--------V--------+       |   |  create   <-- SA is added to hw
265*40ff8c99SAkhil Goyal        |    L2 Stack     |       |   |  inline       using existing create
266*40ff8c99SAkhil Goyal        +--------|--------+       |   |  session      sym session APIs
267*40ff8c99SAkhil Goyal                 |                |   |    |
268*40ff8c99SAkhil Goyal        +--------V--------+   +---|---|----V---+
269*40ff8c99SAkhil Goyal        |                 |   |   \---/    |   | <--- Add tunnel, ESP header etc
270*40ff8c99SAkhil Goyal        |     NIC PMD     |   |   INLINE   |   |      header to packet.Packet
271*40ff8c99SAkhil Goyal        |                 |   | CRYPTO PMD |   |      Encryption/Decryption and
272*40ff8c99SAkhil Goyal        +--------|--------+   +----------------+      Authentication happens
273*40ff8c99SAkhil Goyal                 |                                    inline.
274*40ff8c99SAkhil Goyal        +--------|--------+
275*40ff8c99SAkhil Goyal        |       NIC       |
276*40ff8c99SAkhil Goyal        +--------|--------+
277*40ff8c99SAkhil Goyal                 V
278*40ff8c99SAkhil Goyal
279*40ff8c99SAkhil GoyalDevice Features and Capabilities
280*40ff8c99SAkhil Goyal---------------------------------
281*40ff8c99SAkhil Goyal
282*40ff8c99SAkhil GoyalDevice Capabilities For Security Operations
283*40ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
284*40ff8c99SAkhil Goyal
285*40ff8c99SAkhil GoyalThe device (crypto or ethernet) capabilities which support security operations,
286*40ff8c99SAkhil Goyalare defined by the security action type, security protocol, protocol
287*40ff8c99SAkhil Goyalcapabilities and corresponding crypto capabilities for security. For the full
288*40ff8c99SAkhil Goyalscope of the Security capability see definition of rte_security_capability
289*40ff8c99SAkhil Goyalstructure in the *DPDK API Reference*.
290*40ff8c99SAkhil Goyal
291*40ff8c99SAkhil Goyal.. code-block:: c
292*40ff8c99SAkhil Goyal
293*40ff8c99SAkhil Goyal   struct rte_security_capability;
294*40ff8c99SAkhil Goyal
295*40ff8c99SAkhil GoyalEach driver (crypto or ethernet) defines its own private array of capabilities
296*40ff8c99SAkhil Goyalfor the operations it supports. Below is an example of the capabilities for a
297*40ff8c99SAkhil GoyalPMD which supports the IPSec protocol.
298*40ff8c99SAkhil Goyal
299*40ff8c99SAkhil Goyal.. code-block:: c
300*40ff8c99SAkhil Goyal
301*40ff8c99SAkhil Goyal    static const struct rte_security_capability pmd_security_capabilities[] = {
302*40ff8c99SAkhil Goyal        { /* IPsec Lookaside Protocol offload ESP Tunnel Egress */
303*40ff8c99SAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
304*40ff8c99SAkhil Goyal                .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
305*40ff8c99SAkhil Goyal                .ipsec = {
306*40ff8c99SAkhil Goyal                        .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
307*40ff8c99SAkhil Goyal                        .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
308*40ff8c99SAkhil Goyal                        .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
309*40ff8c99SAkhil Goyal                        .options = { 0 }
310*40ff8c99SAkhil Goyal                },
311*40ff8c99SAkhil Goyal                .crypto_capabilities = pmd_capabilities
312*40ff8c99SAkhil Goyal        },
313*40ff8c99SAkhil Goyal        { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */
314*40ff8c99SAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
315*40ff8c99SAkhil Goyal                .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
316*40ff8c99SAkhil Goyal                .ipsec = {
317*40ff8c99SAkhil Goyal                        .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
318*40ff8c99SAkhil Goyal                        .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
319*40ff8c99SAkhil Goyal                        .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
320*40ff8c99SAkhil Goyal                        .options = { 0 }
321*40ff8c99SAkhil Goyal                },
322*40ff8c99SAkhil Goyal                .crypto_capabilities = pmd_capabilities
323*40ff8c99SAkhil Goyal        },
324*40ff8c99SAkhil Goyal        {
325*40ff8c99SAkhil Goyal                .action = RTE_SECURITY_ACTION_TYPE_NONE
326*40ff8c99SAkhil Goyal        }
327*40ff8c99SAkhil Goyal    };
328*40ff8c99SAkhil Goyal    static const struct rte_cryptodev_capabilities pmd_capabilities[] = {
329*40ff8c99SAkhil Goyal        {    /* SHA1 HMAC */
330*40ff8c99SAkhil Goyal            .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
331*40ff8c99SAkhil Goyal            .sym = {
332*40ff8c99SAkhil Goyal                .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
333*40ff8c99SAkhil Goyal                .auth = {
334*40ff8c99SAkhil Goyal                    .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
335*40ff8c99SAkhil Goyal                    .block_size = 64,
336*40ff8c99SAkhil Goyal                    .key_size = {
337*40ff8c99SAkhil Goyal                        .min = 64,
338*40ff8c99SAkhil Goyal                        .max = 64,
339*40ff8c99SAkhil Goyal                        .increment = 0
340*40ff8c99SAkhil Goyal                    },
341*40ff8c99SAkhil Goyal                    .digest_size = {
342*40ff8c99SAkhil Goyal                        .min = 12,
343*40ff8c99SAkhil Goyal                        .max = 12,
344*40ff8c99SAkhil Goyal                        .increment = 0
345*40ff8c99SAkhil Goyal                    },
346*40ff8c99SAkhil Goyal                    .aad_size = { 0 },
347*40ff8c99SAkhil Goyal                    .iv_size = { 0 }
348*40ff8c99SAkhil Goyal                }
349*40ff8c99SAkhil Goyal            }
350*40ff8c99SAkhil Goyal        },
351*40ff8c99SAkhil Goyal        {    /* AES CBC */
352*40ff8c99SAkhil Goyal            .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
353*40ff8c99SAkhil Goyal            .sym = {
354*40ff8c99SAkhil Goyal                .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
355*40ff8c99SAkhil Goyal                .cipher = {
356*40ff8c99SAkhil Goyal                    .algo = RTE_CRYPTO_CIPHER_AES_CBC,
357*40ff8c99SAkhil Goyal                    .block_size = 16,
358*40ff8c99SAkhil Goyal                    .key_size = {
359*40ff8c99SAkhil Goyal                        .min = 16,
360*40ff8c99SAkhil Goyal                        .max = 32,
361*40ff8c99SAkhil Goyal                        .increment = 8
362*40ff8c99SAkhil Goyal                    },
363*40ff8c99SAkhil Goyal                    .iv_size = {
364*40ff8c99SAkhil Goyal                        .min = 16,
365*40ff8c99SAkhil Goyal                        .max = 16,
366*40ff8c99SAkhil Goyal                        .increment = 0
367*40ff8c99SAkhil Goyal                    }
368*40ff8c99SAkhil Goyal                }
369*40ff8c99SAkhil Goyal            }
370*40ff8c99SAkhil Goyal        }
371*40ff8c99SAkhil Goyal    }
372*40ff8c99SAkhil Goyal
373*40ff8c99SAkhil Goyal
374*40ff8c99SAkhil GoyalCapabilities Discovery
375*40ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~
376*40ff8c99SAkhil Goyal
377*40ff8c99SAkhil GoyalDiscovering the features and capabilities of a driver (crypto/ethernet)
378*40ff8c99SAkhil Goyalis achieved through the ``rte_security_capabilities_get()`` function.
379*40ff8c99SAkhil Goyal
380*40ff8c99SAkhil Goyal.. code-block:: c
381*40ff8c99SAkhil Goyal
382*40ff8c99SAkhil Goyal   const struct rte_security_capability *rte_security_capabilities_get(uint16_t id);
383*40ff8c99SAkhil Goyal
384*40ff8c99SAkhil GoyalThis allows the user to query a specific driver and get all device
385*40ff8c99SAkhil Goyalsecurity capabilities. It returns an array of ``rte_security_capability`` structures
386*40ff8c99SAkhil Goyalwhich contains all the capabilities for that device.
387*40ff8c99SAkhil Goyal
388*40ff8c99SAkhil GoyalSecurity Session Create/Free
389*40ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~
390*40ff8c99SAkhil Goyal
391*40ff8c99SAkhil GoyalSecurity Sessions are created to store the immutable fields of a particular Security
392*40ff8c99SAkhil GoyalAssociation for a particular protocol which is defined by a security session
393*40ff8c99SAkhil Goyalconfiguration structure which is used in the operation processing of a packet flow.
394*40ff8c99SAkhil GoyalSessions are used to manage protocol specific information as well as crypto parameters.
395*40ff8c99SAkhil GoyalSecurity sessions cache this immutable data in a optimal way for the underlying PMD
396*40ff8c99SAkhil Goyaland this allows further acceleration of the offload of Crypto workloads.
397*40ff8c99SAkhil Goyal
398*40ff8c99SAkhil GoyalThe Security framework provides APIs to create and free sessions for crypto/ethernet
399*40ff8c99SAkhil Goyaldevices, where sessions are mempool objects. It is the application's responsibility
400*40ff8c99SAkhil Goyalto create and manage the session mempools. The mempool object size should be able to
401*40ff8c99SAkhil Goyalaccommodate the driver's private data of security session.
402*40ff8c99SAkhil Goyal
403*40ff8c99SAkhil GoyalOnce the session mempools have been created, ``rte_security_session_create()``
404*40ff8c99SAkhil Goyalis used to allocate and initialize a session for the required crypto/ethernet device.
405*40ff8c99SAkhil Goyal
406*40ff8c99SAkhil GoyalSession APIs need a parameter ``rte_security_ctx`` to identify the crypto/ethernet
407*40ff8c99SAkhil Goyalsecurity ops. This parameter can be retrieved using the APIs
408*40ff8c99SAkhil Goyal``rte_cryptodev_get_sec_ctx()`` (for crypto device) or ``rte_eth_dev_get_sec_ctx``
409*40ff8c99SAkhil Goyal(for ethernet port).
410*40ff8c99SAkhil Goyal
411*40ff8c99SAkhil GoyalSessions already created can be updated with ``rte_security_session_update()``.
412*40ff8c99SAkhil Goyal
413*40ff8c99SAkhil GoyalWhen a session is no longer used, the user must call ``rte_security_session_destroy()``
414*40ff8c99SAkhil Goyalto free the driver private session data and return the memory back to the mempool.
415*40ff8c99SAkhil Goyal
416*40ff8c99SAkhil GoyalFor look aside protocol offload to hardware crypto device, the ``rte_crypto_op``
417*40ff8c99SAkhil Goyalcreated by the application is attached to the security session by the API
418*40ff8c99SAkhil Goyal``rte_security_attach_session()``.
419*40ff8c99SAkhil Goyal
420*40ff8c99SAkhil GoyalFor Inline Crypto and Inline protocol offload, device specific defined metadata is
421*40ff8c99SAkhil Goyalupdated in the mbuf using ``rte_security_set_pkt_metadata()`` if
422*40ff8c99SAkhil Goyal``DEV_TX_OFFLOAD_SEC_NEED_MDATA`` is set.
423*40ff8c99SAkhil Goyal
424*40ff8c99SAkhil GoyalSecurity session configuration
425*40ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
426*40ff8c99SAkhil Goyal
427*40ff8c99SAkhil GoyalSecurity Session configuration structure is defined as ``rte_security_session_conf``
428*40ff8c99SAkhil Goyal
429*40ff8c99SAkhil Goyal.. code-block:: c
430*40ff8c99SAkhil Goyal
431*40ff8c99SAkhil Goyal    struct rte_security_session_conf {
432*40ff8c99SAkhil Goyal        enum rte_security_session_action_type action_type;
433*40ff8c99SAkhil Goyal        /**< Type of action to be performed on the session */
434*40ff8c99SAkhil Goyal        enum rte_security_session_protocol protocol;
435*40ff8c99SAkhil Goyal        /**< Security protocol to be configured */
436*40ff8c99SAkhil Goyal        union {
437*40ff8c99SAkhil Goyal                struct rte_security_ipsec_xform ipsec;
438*40ff8c99SAkhil Goyal                struct rte_security_macsec_xform macsec;
439*40ff8c99SAkhil Goyal        };
440*40ff8c99SAkhil Goyal        /**< Configuration parameters for security session */
441*40ff8c99SAkhil Goyal        struct rte_crypto_sym_xform *crypto_xform;
442*40ff8c99SAkhil Goyal        /**< Security Session Crypto Transformations */
443*40ff8c99SAkhil Goyal    };
444*40ff8c99SAkhil Goyal
445*40ff8c99SAkhil GoyalThe configuration structure reuses the ``rte_crypto_sym_xform`` struct for crypto related
446*40ff8c99SAkhil Goyalconfiguration. The ``rte_security_session_action_type`` struct is used to specify whether the
447*40ff8c99SAkhil Goyalsession is configured for Lookaside Protocol offload or Inline Crypto or Inline Protocol
448*40ff8c99SAkhil GoyalOffload.
449*40ff8c99SAkhil Goyal
450*40ff8c99SAkhil Goyal.. code-block:: c
451*40ff8c99SAkhil Goyal
452*40ff8c99SAkhil Goyal    enum rte_security_session_action_type {
453*40ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_NONE,
454*40ff8c99SAkhil Goyal        /**< No security actions */
455*40ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
456*40ff8c99SAkhil Goyal        /**< Crypto processing for security protocol is processed inline
457*40ff8c99SAkhil Goyal         * during transmission */
458*40ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
459*40ff8c99SAkhil Goyal        /**< All security protocol processing is performed inline during
460*40ff8c99SAkhil Goyal         * transmission */
461*40ff8c99SAkhil Goyal        RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL
462*40ff8c99SAkhil Goyal        /**< All security protocol processing including crypto is performed
463*40ff8c99SAkhil Goyal         * on a lookaside accelerator */
464*40ff8c99SAkhil Goyal    };
465*40ff8c99SAkhil Goyal
466*40ff8c99SAkhil GoyalThe ``rte_security_session_protocol`` is defined as
467*40ff8c99SAkhil Goyal
468*40ff8c99SAkhil Goyal.. code-block:: c
469*40ff8c99SAkhil Goyal
470*40ff8c99SAkhil Goyal    enum rte_security_session_protocol {
471*40ff8c99SAkhil Goyal        RTE_SECURITY_PROTOCOL_IPSEC,
472*40ff8c99SAkhil Goyal        /**< IPsec Protocol */
473*40ff8c99SAkhil Goyal        RTE_SECURITY_PROTOCOL_MACSEC,
474*40ff8c99SAkhil Goyal        /**< MACSec Protocol */
475*40ff8c99SAkhil Goyal    };
476*40ff8c99SAkhil Goyal
477*40ff8c99SAkhil GoyalCurrently the library defines configuration parameters for IPSec only. For other
478*40ff8c99SAkhil Goyalprotocols like MACSec, structures and enums are defined as place holders which
479*40ff8c99SAkhil Goyalwill be updated in the future.
480*40ff8c99SAkhil Goyal
481*40ff8c99SAkhil GoyalIPsec related configuration parameters are defined in ``rte_security_ipsec_xform``
482*40ff8c99SAkhil Goyal
483*40ff8c99SAkhil Goyal.. code-block:: c
484*40ff8c99SAkhil Goyal
485*40ff8c99SAkhil Goyal    struct rte_security_ipsec_xform {
486*40ff8c99SAkhil Goyal        uint32_t spi;
487*40ff8c99SAkhil Goyal        /**< SA security parameter index */
488*40ff8c99SAkhil Goyal        uint32_t salt;
489*40ff8c99SAkhil Goyal        /**< SA salt */
490*40ff8c99SAkhil Goyal        struct rte_security_ipsec_sa_options options;
491*40ff8c99SAkhil Goyal        /**< various SA options */
492*40ff8c99SAkhil Goyal        enum rte_security_ipsec_sa_direction direction;
493*40ff8c99SAkhil Goyal        /**< IPSec SA Direction - Egress/Ingress */
494*40ff8c99SAkhil Goyal        enum rte_security_ipsec_sa_protocol proto;
495*40ff8c99SAkhil Goyal        /**< IPsec SA Protocol - AH/ESP */
496*40ff8c99SAkhil Goyal        enum rte_security_ipsec_sa_mode mode;
497*40ff8c99SAkhil Goyal        /**< IPsec SA Mode - transport/tunnel */
498*40ff8c99SAkhil Goyal        struct rte_security_ipsec_tunnel_param tunnel;
499*40ff8c99SAkhil Goyal        /**< Tunnel parameters, NULL for transport mode */
500*40ff8c99SAkhil Goyal    };
501*40ff8c99SAkhil Goyal
502*40ff8c99SAkhil Goyal
503*40ff8c99SAkhil GoyalSecurity API
504*40ff8c99SAkhil Goyal~~~~~~~~~~~~
505*40ff8c99SAkhil Goyal
506*40ff8c99SAkhil GoyalThe rte_security Library API is described in the *DPDK API Reference* document.
507*40ff8c99SAkhil Goyal
508*40ff8c99SAkhil GoyalFlow based Security Session
509*40ff8c99SAkhil Goyal~~~~~~~~~~~~~~~~~~~~~~~~~~~
510*40ff8c99SAkhil Goyal
511*40ff8c99SAkhil GoyalIn the case of NIC based offloads, the security session specified in the
512*40ff8c99SAkhil Goyal'rte_flow_action_security' must be created on the same port as the
513*40ff8c99SAkhil Goyalflow action that is being specified.
514*40ff8c99SAkhil Goyal
515*40ff8c99SAkhil GoyalThe ingress/egress flow attribute should match that specified in the security
516*40ff8c99SAkhil Goyalsession if the security session supports the definition of the direction.
517*40ff8c99SAkhil Goyal
518*40ff8c99SAkhil GoyalMultiple flows can be configured to use the same security session. For
519*40ff8c99SAkhil Goyalexample if the security session specifies an egress IPsec SA, then multiple
520*40ff8c99SAkhil Goyalflows can be specified to that SA. In the case of an ingress IPsec SA then
521*40ff8c99SAkhil Goyalit is only valid to have a single flow to map to that security session.
522*40ff8c99SAkhil Goyal
523*40ff8c99SAkhil Goyal.. code-block:: console
524*40ff8c99SAkhil Goyal
525*40ff8c99SAkhil Goyal         Configuration Path
526*40ff8c99SAkhil Goyal                 |
527*40ff8c99SAkhil Goyal        +--------|--------+
528*40ff8c99SAkhil Goyal        |    Add/Remove   |
529*40ff8c99SAkhil Goyal        |     IPsec SA    |   <------ Build security flow action of
530*40ff8c99SAkhil Goyal        |        |        |           ipsec transform
531*40ff8c99SAkhil Goyal        |--------|--------|
532*40ff8c99SAkhil Goyal                 |
533*40ff8c99SAkhil Goyal        +--------V--------+
534*40ff8c99SAkhil Goyal        |   Flow API      |
535*40ff8c99SAkhil Goyal        +--------|--------+
536*40ff8c99SAkhil Goyal                 |
537*40ff8c99SAkhil Goyal        +--------V--------+
538*40ff8c99SAkhil Goyal        |                 |
539*40ff8c99SAkhil Goyal        |     NIC PMD     |   <------ Add/Remove SA to/from hw context
540*40ff8c99SAkhil Goyal        |                 |
541*40ff8c99SAkhil Goyal        +--------|--------+
542*40ff8c99SAkhil Goyal                 |
543*40ff8c99SAkhil Goyal        +--------|--------+
544*40ff8c99SAkhil Goyal        |  HW ACCELERATED |
545*40ff8c99SAkhil Goyal        |        NIC      |
546*40ff8c99SAkhil Goyal        |                 |
547*40ff8c99SAkhil Goyal        +--------|--------+
548*40ff8c99SAkhil Goyal
549*40ff8c99SAkhil Goyal* Add/Delete SA flow:
550*40ff8c99SAkhil Goyal  To add a new inline SA construct a rte_flow_item for Ethernet + IP + ESP
551*40ff8c99SAkhil Goyal  using the SA selectors and the ``rte_crypto_ipsec_xform`` as the ``rte_flow_action``.
552*40ff8c99SAkhil Goyal  Note that any rte_flow_items may be empty, which means it is not checked.
553*40ff8c99SAkhil Goyal
554*40ff8c99SAkhil Goyal.. code-block:: console
555*40ff8c99SAkhil Goyal
556*40ff8c99SAkhil Goyal    In its most basic form, IPsec flow specification is as follows:
557*40ff8c99SAkhil Goyal        +-------+     +----------+    +--------+    +-----+
558*40ff8c99SAkhil Goyal        |  Eth  | ->  |   IP4/6  | -> |   ESP  | -> | END |
559*40ff8c99SAkhil Goyal        +-------+     +----------+    +--------+    +-----+
560*40ff8c99SAkhil Goyal
561*40ff8c99SAkhil Goyal    However, the API can represent, IPsec crypto offload with any encapsulation:
562*40ff8c99SAkhil Goyal        +-------+            +--------+    +-----+
563*40ff8c99SAkhil Goyal        |  Eth  | ->  ... -> |   ESP  | -> | END |
564*40ff8c99SAkhil Goyal        +-------+            +--------+    +-----+
565