1.. SPDX-License-Identifier: BSD-3-Clause 2 Copyright 2017,2020-2021 NXP 3 4 5 6Security Library 7================ 8 9The security library provides a framework for management and provisioning 10of security protocol operations offloaded to hardware based devices. The 11library defines generic APIs to create and free security sessions which can 12support full protocol offload as well as inline crypto operation with 13NIC or crypto devices. The framework currently only supports the IPsec, PDCP 14and DOCSIS protocols and associated operations, other protocols will be added 15in the future. 16 17Design Principles 18----------------- 19 20The security library provides an additional offload capability to an existing 21crypto device and/or ethernet device. 22 23.. code-block:: console 24 25 +---------------+ 26 | rte_security | 27 +---------------+ 28 \ / 29 +-----------+ +--------------+ 30 | NIC PMD | | CRYPTO PMD | 31 +-----------+ +--------------+ 32 33.. note:: 34 35 Currently, the security library does not support the case of multi-process. 36 It will be updated in the future releases. 37 38The supported offload types are explained in the sections below. 39 40Inline Crypto 41~~~~~~~~~~~~~ 42 43RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO: 44The crypto processing for security protocol (e.g. IPsec) is processed 45inline during receive and transmission on NIC port. The flow based 46security action should be configured on the port. 47 48Ingress Data path - The packet is decrypted in RX path and relevant 49crypto status is set in Rx descriptors. After the successful inline 50crypto processing the packet is presented to host as a regular Rx packet 51however all security protocol related headers are still attached to the 52packet. e.g. In case of IPsec, the IPsec tunnel headers (if any), 53ESP/AH headers will remain in the packet but the received packet 54contains the decrypted data where the encrypted data was when the packet 55arrived. The driver Rx path check the descriptors and based on the 56crypto status sets additional flags in the rte_mbuf.ol_flags field. 57 58.. note:: 59 60 The underlying device may not support crypto processing for all ingress packet 61 matching to a particular flow (e.g. fragmented packets), such packets will 62 be passed as encrypted packets. It is the responsibility of application to 63 process such encrypted packets using other crypto driver instance. 64 65Egress Data path - The software prepares the egress packet by adding 66relevant security protocol headers. Only the data will not be 67encrypted by the software. The driver will accordingly configure the 68tx descriptors. The hardware device will encrypt the data before sending the 69packet out. 70 71.. note:: 72 73 The underlying device may support post encryption TSO. 74 75.. code-block:: console 76 77 Egress Data Path 78 | 79 +--------|--------+ 80 | egress IPsec | 81 | | | 82 | +------V------+ | 83 | | SADB lookup | | 84 | +------|------+ | 85 | +------V------+ | 86 | | Tunnel | | <------ Add tunnel header to packet 87 | +------|------+ | 88 | +------V------+ | 89 | | ESP | | <------ Add ESP header without trailer to packet 90 | | | | <------ Mark packet to be offloaded, add trailer 91 | +------|------+ | meta-data to mbuf 92 +--------V--------+ 93 | 94 +--------V--------+ 95 | L2 Stack | 96 +--------|--------+ 97 | 98 +--------V--------+ 99 | | 100 | NIC PMD | <------ Set hw context for inline crypto offload 101 | | 102 +--------|--------+ 103 | 104 +--------|--------+ 105 | HW ACCELERATED | <------ Packet Encryption and 106 | NIC | Authentication happens inline 107 | | 108 +-----------------+ 109 110 111Inline protocol offload 112~~~~~~~~~~~~~~~~~~~~~~~ 113 114RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL: 115The crypto and protocol processing for security protocol (e.g. IPsec) 116is processed inline during receive and transmission. The flow based 117security action should be configured on the port. 118 119Ingress Data path - The packet is decrypted in the RX path and relevant 120crypto status is set in the Rx descriptors. After the successful inline 121crypto processing the packet is presented to the host as a regular Rx packet 122but all security protocol related headers are optionally removed from the 123packet. e.g. in the case of IPsec, the IPsec tunnel headers (if any), 124ESP/AH headers will be removed from the packet and the received packet 125will contains the decrypted packet only. The driver Rx path checks the 126descriptors and based on the crypto status sets additional flags in 127``rte_mbuf.ol_flags`` field. The driver would also set device-specific 128metadata in ``RTE_SECURITY_DYNFIELD_NAME`` field. 129This will allow the application to identify the security processing 130done on the packet. 131 132.. note:: 133 134 The underlying device in this case is stateful. It is expected that 135 the device shall support crypto processing for all kind of packets matching 136 to a given flow, this includes fragmented packets (post reassembly). 137 E.g. in case of IPsec the device may internally manage anti-replay etc. 138 It will provide a configuration option for anti-replay behavior i.e. to drop 139 the packets or pass them to driver with error flags set in the descriptor. 140 141Egress Data path - The software will send the plain packet without any 142security protocol headers added to the packet. The driver will configure 143the security index and other requirement in tx descriptors. 144The hardware device will do security processing on the packet that includes 145adding the relevant protocol headers and encrypting the data before sending 146the packet out. The software should make sure that the buffer 147has required head room and tail room for any protocol header addition. The 148software may also do early fragmentation if the resultant packet is expected 149to cross the MTU size. The software should also make sure that L2 header contents 150are updated with the final L2 header which is expected post IPsec processing as 151the IPsec offload will only update L3 and above in egress path. 152 153 154.. note:: 155 156 The underlying device will manage state information required for egress 157 processing. E.g. in case of IPsec, the seq number will be added to the 158 packet, however the device shall provide indication when the sequence number 159 is about to overflow. The underlying device may support post encryption TSO. 160 161.. code-block:: console 162 163 Egress Data Path 164 | 165 +--------|--------+ 166 | egress IPsec | 167 | | | 168 | +------V------+ | 169 | | SADB lookup | | 170 | +------|------+ | 171 | +------V------+ | 172 | | Desc | | <------ Mark packet to be offloaded 173 | +------|------+ | 174 +--------V--------+ 175 | 176 +--------V--------+ 177 | L2 Stack | 178 +--------|--------+ 179 | 180 +--------V--------+ 181 | | 182 | NIC PMD | <------ Set hw context for inline crypto offload 183 | | 184 +--------|--------+ 185 | 186 +--------|--------+ 187 | HW ACCELERATED | <------ Add tunnel, ESP header etc header to 188 | NIC | packet. Packet Encryption and 189 | | Authentication happens inline. 190 +-----------------+ 191 192 193Lookaside protocol offload 194~~~~~~~~~~~~~~~~~~~~~~~~~~ 195 196RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL: 197This extends librte_cryptodev to support the programming of IPsec 198Security Association (SA) as part of a crypto session creation including 199the definition. In addition to standard crypto processing, as defined by 200the cryptodev, the security protocol processing is also offloaded to the 201crypto device. 202 203Decryption: The packet is sent to the crypto device for security 204protocol processing. The device will decrypt the packet and it will also 205optionally remove additional security headers from the packet. 206E.g. in case of IPsec, IPsec tunnel headers (if any), ESP/AH headers 207will be removed from the packet and the decrypted packet may contain 208plain data only. 209 210.. note:: 211 212 In case of IPsec the device may internally manage anti-replay etc. 213 It will provide a configuration option for anti-replay behavior i.e. to drop 214 the packets or pass them to driver with error flags set in descriptor. 215 216Encryption: The software will submit the packet to cryptodev as usual 217for encryption, the hardware device in this case will also add the relevant 218security protocol header along with encrypting the packet. The software 219should make sure that the buffer has required head room and tail room 220for any protocol header addition. 221 222.. note:: 223 224 In the case of IPsec, the seq number will be added to the packet, 225 It shall provide an indication when the sequence number is about to 226 overflow. 227 228.. code-block:: console 229 230 Egress Data Path 231 | 232 +--------|--------+ 233 | egress IPsec | 234 | | | 235 | +------V------+ | 236 | | SADB lookup | | <------ SA maps to cryptodev session 237 | +------|------+ | 238 | +------|------+ | 239 | | \--------------------\ 240 | | Crypto | | | <- Crypto processing through 241 | | /----------------\ | inline crypto PMD 242 | +------|------+ | | | 243 +--------V--------+ | | 244 | | | 245 +--------V--------+ | | create <-- SA is added to hw 246 | L2 Stack | | | inline using existing create 247 +--------|--------+ | | session sym session APIs 248 | | | | 249 +--------V--------+ +---|---|----V---+ 250 | | | \---/ | | <--- Add tunnel, ESP header etc 251 | NIC PMD | | INLINE | | header to packet.Packet 252 | | | CRYPTO PMD | | Encryption/Decryption and 253 +--------|--------+ +----------------+ Authentication happens 254 | inline. 255 +--------|--------+ 256 | NIC | 257 +--------|--------+ 258 V 259 260PDCP Flow Diagram 261~~~~~~~~~~~~~~~~~ 262 263Based on 3GPP TS 36.323 Evolved Universal Terrestrial Radio Access (E-UTRA); 264Packet Data Convergence Protocol (PDCP) specification 265 266.. code-block:: c 267 268 Transmitting PDCP Entity Receiving PDCP Entity 269 | ^ 270 | +-----------|-----------+ 271 V | In order delivery and | 272 +---------|----------+ | Duplicate detection | 273 | Sequence Numbering | | (Data Plane only) | 274 +---------|----------+ +-----------|-----------+ 275 | | 276 +---------|----------+ +-----------|----------+ 277 | Header Compression*| | Header Decompression*| 278 | (Data-Plane only) | | (Data Plane only) | 279 +---------|----------+ +-----------|----------+ 280 | | 281 +---------|-----------+ +-----------|----------+ 282 | Integrity Protection| |Integrity Verification| 283 | (Control Plane only)| | (Control Plane only) | 284 +---------|-----------+ +-----------|----------+ 285 +---------|-----------+ +----------|----------+ 286 | Ciphering | | Deciphering | 287 +---------|-----------+ +----------|----------+ 288 +---------|-----------+ +----------|----------+ 289 | Add PDCP header | | Remove PDCP Header | 290 +---------|-----------+ +----------|----------+ 291 | | 292 +----------------->>----------------+ 293 294 295.. note:: 296 297 * Header Compression and decompression are not supported currently. 298 299Just like IPsec, in case of PDCP also header addition/deletion, cipher/ 300de-cipher, integrity protection/verification is done based on the action 301type chosen. 302 303DOCSIS Protocol 304~~~~~~~~~~~~~~~ 305 306The Data Over Cable Service Interface Specification (DOCSIS) support comprises 307the combination of encryption/decryption and CRC generation/verification, for 308use in a DOCSIS-MAC pipeline. 309 310.. code-block:: c 311 312 313 Downlink Uplink 314 -------- ------ 315 316 Ethernet frame Ethernet frame 317 from core network to core network 318 | ^ 319 ~ | 320 | ~ ----+ 321 V | | 322 +---------|----------+ +----------|---------+ | 323 | CRC generation | | CRC verification | | 324 +---------|----------+ +----------|---------+ | combined 325 | | > Crypto + CRC 326 +---------|----------+ +----------|---------+ | 327 | Encryption | | Decryption | | 328 +---------|----------+ +----------|---------+ | 329 | ^ | 330 ~ | ----+ 331 | ~ 332 V | 333 DOCSIS frame DOCSIS frame 334 to Cable Modem from Cable Modem 335 336The encryption/decryption is a combination of CBC and CFB modes using either AES 337or DES algorithms as specified in the DOCSIS Security Specification (from DPDK 338lib_rtecryptodev perspective, these are RTE_CRYPTO_CIPHER_AES_DOCSISBPI and 339RTE_CRYPTO_CIPHER_DES_DOCSISBPI). 340 341The CRC is Ethernet CRC-32 as specified in Ethernet/[ISO/IEC 8802-3]. 342 343.. note:: 344 345 * The offset and length of data for which CRC needs to be computed are 346 specified via the auth offset and length fields of the rte_crypto_sym_op. 347 * Other DOCSIS protocol functionality such as Header Checksum (HCS) 348 calculation may be added in the future. 349 350MACSEC Protocol 351~~~~~~~~~~~~~~~ 352 353Media Access Control security (MACsec) provides point-to-point security 354on Ethernet links and is defined by IEEE standard 802.1AE. 355MACsec secures an Ethernet link for almost all traffic, 356including frames from the Link Layer Discovery Protocol (LLDP), 357Link Aggregation Control Protocol (LACP), 358Dynamic Host Configuration Protocol (DHCP), 359Address Resolution Protocol (ARP), 360and other protocols that are not typically secured on an Ethernet link 361because of limitations with other security solutions. 362 363.. code-block:: c 364 365 Receive Transmit 366 ------- -------- 367 368 Ethernet frame Ethernet frame 369 from network towards network 370 | ^ 371 ~ | 372 | ~ 373 V | 374 +-----------------------+ +------------------+ +-------------------------+ 375 | Secure Frame Verify | | Cipher Suite(SA) | | Secure Frame Generation | 376 +-----------------------+<-----+------------------+----->+-------------------------+ 377 | SecTAG + ICV remove | | SECY | SC | | SecTAG + ICV Added | 378 +---+-------------------+ +------------------+ +-------------------------+ 379 | ^ 380 | | 381 V | 382 Packet to Core/App Packet from Core/App 383 384 385 386To configure MACsec on an inline NIC device or a lookaside crypto device, 387a security association (SA) and a secure channel (SC) are created 388before creating rte_security session. 389 390SA is created using API ``rte_security_macsec_sa_create`` 391which allows setting SA keys, salt, SSCI, packet number (PN) into the PMD, 392and the API returns a handle which can be used to map it with a secure channel, 393using the API ``rte_security_macsec_sc_create``. 394Same SAs can be used for multiple SCs. 395The Rx SC will need a set of 4 SAs for each of the association numbers (AN). 396For Tx SC a single SA is set which will be used by hardware to process the packet. 397 398The API ``rte_security_macsec_sc_create`` returns a handle for SC, 399and this handle is set in ``rte_security_macsec_xform`` 400to create a MACsec session using ``rte_security_session_create``. 401 402TLS-Record Protocol 403~~~~~~~~~~~~~~~~~~~ 404 405The Transport Layer Protocol provides communications security over the Internet. 406The protocol allows client/server applications to communicate in a way 407that is designed to prevent eavesdropping, tampering, or message forgery. 408 409TLS protocol is composed of two layers: the TLS Record Protocol and the TLS Handshake Protocol. 410At the lowest level, layered on top of some reliable transport protocol (e.g., TCP), 411is the TLS Record Protocol. 412The TLS Record Protocol provides connection security that has two basic properties: 413 414 - The connection is private. 415 Symmetric cryptography is used for data encryption (e.g., AES, DES, etc.). 416 The keys for this symmetric encryption are generated uniquely 417 for each connection and are based on a secret negotiated during TLS Handshake Protocol. 418 The Record Protocol can also be used without encryption. 419 420 - The connection is reliable. 421 Message transport includes a message integrity check using a keyed MAC. 422 Secure hash functions (e.g., SHA-1, etc.) are used for MAC computations. 423 The Record Protocol can operate without a MAC when it is being used as a transport 424 for negotiating security parameters by another protocol. 425 426.. code-block:: c 427 428 Record Write Record Read 429 ------------ ----------- 430 431 TLSPlaintext TLSCiphertext 432 | | 433 ~ ~ 434 | | 435 V V 436 +----------|-----------+ +----------|-----------+ 437 | Generate sequence no.| | Generate sequence no.| 438 +----------|-----------+ +----------------------+ 439 | | AR check (DTLS) | 440 +----------|-----------+ +----------|-----------+ 441 | Insert TLS header | | 442 | & trailer. | +----------|-----------+ 443 | (including padding) | | Decrypt & MAC verify | 444 +----------|-----------+ +----------|-----------+ 445 | | 446 +---------|-----------+ +----------|-----------+ 447 | MAC generate & | | Remove TLS header | 448 | Encrypt | | & trailer. | 449 +---------|-----------+ | (including padding) | 450 | +----------|-----------+ 451 | | 452 ~ ~ 453 | | 454 V V 455 TLSCiphertext TLSPlaintext 456 457Supported Versions 458^^^^^^^^^^^^^^^^^^ 459 460* TLS 1.2 461* TLS 1.3 462* DTLS 1.2 463 464Device Features and Capabilities 465--------------------------------- 466 467Device Capabilities For Security Operations 468~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 469 470The device (crypto or ethernet) capabilities which support security operations, 471are defined by the security action type, security protocol, protocol 472capabilities and corresponding crypto capabilities for security. For the full 473scope of the Security capability see definition of rte_security_capability 474structure in the *DPDK API Reference*. 475 476.. code-block:: c 477 478 struct rte_security_capability; 479 480Each driver (crypto or ethernet) defines its own private array of capabilities 481for the operations it supports. Below is an example of the capabilities for a 482PMD which supports the IPsec and PDCP protocol. 483 484.. code-block:: c 485 486 static const struct rte_security_capability pmd_security_capabilities[] = { 487 { /* IPsec Lookaside Protocol offload ESP Tunnel Egress */ 488 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 489 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 490 .ipsec = { 491 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, 492 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, 493 .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS, 494 .options = { 0 } 495 }, 496 .crypto_capabilities = pmd_capabilities 497 }, 498 { /* IPsec Lookaside Protocol offload ESP Tunnel Ingress */ 499 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 500 .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 501 .ipsec = { 502 .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, 503 .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, 504 .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS, 505 .options = { 0 } 506 }, 507 .crypto_capabilities = pmd_capabilities 508 }, 509 { /* PDCP Lookaside Protocol offload Data Plane */ 510 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 511 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 512 .pdcp = { 513 .domain = RTE_SECURITY_PDCP_MODE_DATA, 514 .capa_flags = 0 515 }, 516 .crypto_capabilities = pmd_capabilities 517 }, 518 { /* PDCP Lookaside Protocol offload Control */ 519 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 520 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 521 .pdcp = { 522 .domain = RTE_SECURITY_PDCP_MODE_CONTROL, 523 .capa_flags = 0 524 }, 525 .crypto_capabilities = pmd_capabilities 526 }, 527 { /* PDCP Lookaside Protocol offload short MAC-I */ 528 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 529 .protocol = RTE_SECURITY_PROTOCOL_PDCP, 530 .pdcp = { 531 .domain = RTE_SECURITY_PDCP_MODE_SHORT_MAC, 532 .capa_flags = 0 533 }, 534 .crypto_capabilities = pmd_capabilities 535 }, 536 { 537 .action = RTE_SECURITY_ACTION_TYPE_NONE 538 } 539 }; 540 static const struct rte_cryptodev_capabilities pmd_capabilities[] = { 541 { /* SHA1 HMAC */ 542 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, 543 .sym = { 544 .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH, 545 .auth = { 546 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC, 547 .block_size = 64, 548 .key_size = { 549 .min = 64, 550 .max = 64, 551 .increment = 0 552 }, 553 .digest_size = { 554 .min = 12, 555 .max = 12, 556 .increment = 0 557 }, 558 .aad_size = { 0 }, 559 .iv_size = { 0 } 560 } 561 } 562 }, 563 { /* AES CBC */ 564 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, 565 .sym = { 566 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, 567 .cipher = { 568 .algo = RTE_CRYPTO_CIPHER_AES_CBC, 569 .block_size = 16, 570 .key_size = { 571 .min = 16, 572 .max = 32, 573 .increment = 8 574 }, 575 .iv_size = { 576 .min = 16, 577 .max = 16, 578 .increment = 0 579 } 580 } 581 } 582 } 583 } 584 585Below is an example of the capabilities for a PMD which supports the DOCSIS 586protocol. 587 588.. code-block:: c 589 590 static const struct rte_security_capability pmd_security_capabilities[] = { 591 { /* DOCSIS Uplink */ 592 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 593 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 594 .docsis = { 595 .direction = RTE_SECURITY_DOCSIS_UPLINK 596 }, 597 .crypto_capabilities = pmd_capabilities 598 }, 599 { /* DOCSIS Downlink */ 600 .action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 601 .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 602 .docsis = { 603 .direction = RTE_SECURITY_DOCSIS_DOWNLINK 604 }, 605 .crypto_capabilities = pmd_capabilities 606 }, 607 { 608 .action = RTE_SECURITY_ACTION_TYPE_NONE 609 } 610 }; 611 static const struct rte_cryptodev_capabilities pmd_capabilities[] = { 612 { /* AES DOCSIS BPI */ 613 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC, 614 .sym = { 615 .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER, 616 .cipher = { 617 .algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI, 618 .block_size = 16, 619 .key_size = { 620 .min = 16, 621 .max = 32, 622 .increment = 16 623 }, 624 .iv_size = { 625 .min = 16, 626 .max = 16, 627 .increment = 0 628 } 629 } 630 } 631 }, 632 633 RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() 634 }; 635 636Below is the example PMD capability for MACsec 637 638.. code-block:: c 639 640 static const struct rte_security_capability pmd_security_capabilities[] = { 641 { 642 .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL, 643 .protocol = RTE_SECURITY_PROTOCOL_MACSEC, 644 .macsec = { 645 .mtu = 1500, 646 .alg = RTE_SECURITY_MACSEC_ALG_GCM_128, 647 .max_nb_sc = 64, 648 .max_nb_sa = 128, 649 .max_nb_sess = 64, 650 .replay_win_sz = 4096, 651 .relative_sectag_insert = 1, 652 .fixed_sectag_insert = 1, 653 .icv_include_da_sa = 1, 654 .ctrl_port_enable = 1, 655 .preserve_sectag = 1, 656 .preserve_icv = 1, 657 .validate_frames = 1, 658 .re_key = 1, 659 .anti_replay = 1, 660 }, 661 .crypto_capabilities = NULL, 662 }, 663 }; 664 665Capabilities Discovery 666~~~~~~~~~~~~~~~~~~~~~~ 667 668Discovering the features and capabilities of a driver (crypto/ethernet) 669is achieved through the ``rte_security_capabilities_get()`` function. 670 671.. code-block:: c 672 673 const struct rte_security_capability *rte_security_capabilities_get(uint16_t id); 674 675This allows the user to query a specific driver and get all device 676security capabilities. It returns an array of ``rte_security_capability`` structures 677which contains all the capabilities for that device. 678 679Security Session Create/Free 680~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 681 682Security Sessions are created to store the immutable fields of a particular Security 683Association for a particular protocol which is defined by a security session 684configuration structure which is used in the operation processing of a packet flow. 685Sessions are used to manage protocol specific information as well as crypto parameters. 686Security sessions cache this immutable data in a optimal way for the underlying PMD 687and this allows further acceleration of the offload of Crypto workloads. 688 689The Security framework provides APIs to create and free sessions for crypto/ethernet 690devices, where sessions are mempool objects. It is the application's responsibility 691to create and manage two session mempools - one for session and other for session 692private data. The private session data mempool object size should be able to 693accommodate the driver's private data of security session. The application can get 694the size of session private data using API ``rte_security_session_get_size``. 695And the session mempool object size should be enough to accommodate 696``rte_security_session``. 697 698Once the session mempools have been created, ``rte_security_session_create()`` 699is used to allocate and initialize a session for the required crypto/ethernet device. 700 701Session APIs need an opaque handle to identify the crypto/ethernet 702security ops. This parameter can be retrieved using the APIs 703``rte_cryptodev_get_sec_ctx()`` (for crypto device) or ``rte_eth_dev_get_sec_ctx`` 704(for ethernet port). 705 706Sessions already created can be updated with ``rte_security_session_update()``. 707 708When a session is no longer used, the user must call ``rte_security_session_destroy()`` 709to free the driver private session data and return the memory back to the mempool. 710 711For look aside protocol offload to hardware crypto device, the ``rte_crypto_op`` 712created by the application is attached to the security session by the API 713``rte_security_attach_session()``. 714 715For Inline Crypto and Inline protocol offload, device specific defined metadata is 716updated in the mbuf using ``rte_security_set_pkt_metadata()`` if 717``RTE_ETH_TX_OFFLOAD_SEC_NEED_MDATA`` is set. 718 719.. note:: 720 721 In case of inline processed packets, ``RTE_SECURITY_DYNFIELD_NAME`` field 722 would be used by the driver to relay information on the security processing 723 associated with the packet. In ingress, the driver would set this in Rx 724 path while in egress, ``rte_security_set_pkt_metadata()`` would perform a 725 similar operation. The application is expected not to modify the field 726 when it has relevant info. For ingress, this device-specific 64 bit value 727 is required to derive other information (like userdata), required for 728 identifying the security processing done on the packet. 729 730Security session configuration 731~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 732 733Security Session configuration structure is defined as ``rte_security_session_conf`` 734 735.. literalinclude:: ../../../lib/security/rte_security.h 736 :language: c 737 :start-after: Structure rte_security_session_conf 8< 738 :end-before: >8 End of structure rte_security_session_conf. 739 740The configuration structure reuses the ``rte_crypto_sym_xform`` struct for crypto related 741configuration. The ``rte_security_session_action_type`` struct is used to specify whether the 742session is configured for Lookaside Protocol offload or Inline Crypto or Inline Protocol 743Offload. 744 745.. literalinclude:: ../../../lib/security/rte_security.h 746 :language: c 747 :start-after: Enumeration of rte_security_session_action_type 8< 748 :end-before: >8 End enumeration of rte_security_session_action_type. 749 750The ``rte_security_session_protocol`` is defined as 751 752.. literalinclude:: ../../../lib/security/rte_security.h 753 :language: c 754 :start-after: Enumeration of rte_security_session_protocol 8< 755 :end-before: >8 End enumeration of rte_security_session_protocol. 756 757IPsec related configuration parameters are defined in ``rte_security_ipsec_xform`` 758 759MACsec related configuration parameters are defined in ``rte_security_macsec_xform`` 760 761PDCP related configuration parameters are defined in ``rte_security_pdcp_xform`` 762 763DOCSIS related configuration parameters are defined in ``rte_security_docsis_xform`` 764 765TLS record related configuration parameters are defined in ``rte_security_tls_record_xform`` 766 767 768Security API 769~~~~~~~~~~~~ 770 771The rte_security Library API is described in the *DPDK API Reference* document. 772 773Flow based Security Session 774~~~~~~~~~~~~~~~~~~~~~~~~~~~ 775 776In the case of NIC based offloads, the security session specified in the 777'rte_flow_action_security' must be created on the same port as the 778flow action that is being specified. 779 780The ingress/egress flow attribute should match that specified in the security 781session if the security session supports the definition of the direction. 782 783Multiple flows can be configured to use the same security session. For 784example if the security session specifies an egress IPsec/MACsec SA, then multiple 785flows can be specified to that SA. In the case of an ingress IPsec SA then 786it is only valid to have a single flow to map to that security session. 787 788.. code-block:: console 789 790 Configuration Path 791 | 792 +--------|--------+ 793 | Add/Remove | 794 | IPsec/MACsec SA | <------ Build security flow action of 795 | | | IPsec/MACsec transform 796 |--------|--------| 797 | 798 +--------V--------+ 799 | Flow API | 800 +--------|--------+ 801 | 802 +--------V--------+ 803 | | 804 | NIC PMD | <------ Add/Remove SA to/from hw context 805 | | 806 +--------|--------+ 807 | 808 +--------|--------+ 809 | HW ACCELERATED | 810 | NIC | 811 | | 812 +--------|--------+ 813 814* Add/Delete IPsec SA flow: 815 To add a new inline SA construct a rte_flow_item for Ethernet + IP + ESP 816 using the SA selectors and the ``rte_security_ipsec_xform`` as the ``rte_flow_action``. 817 Note that any rte_flow_items may be empty, which means it is not checked. 818 819.. code-block:: console 820 821 In its most basic form, IPsec flow specification is as follows: 822 +-------+ +----------+ +--------+ +-----+ 823 | Eth | -> | IP4/6 | -> | ESP | -> | END | 824 +-------+ +----------+ +--------+ +-----+ 825 826 However, the API can represent, IPsec crypto offload with any encapsulation: 827 +-------+ +--------+ +-----+ 828 | Eth | -> ... -> | ESP | -> | END | 829 +-------+ +--------+ +-----+ 830 831* Add/Delete MACsec SA flow: 832 To add a new inline SA construct a rte_flow_item for Ethernet + SecTAG 833 using the SA selectors and the ``rte_security_macsec_xform`` as the ``rte_flow_action``. 834 Note that any rte_flow_items may be empty, which means it is not checked. 835 836.. code-block:: console 837 838 In its most basic form, MACsec flow specification is as follows: 839 +-------+ +----------+ +-----+ 840 | Eth | -> | SecTag | -> | END | 841 +-------+ +----------+ +-----+ 842 843 However, the API can represent, MACsec offload with any encapsulation: 844 +-------+ +--------+ +-----+ 845 | Eth | -> ... -> | SecTag | -> | END | 846 +-------+ +--------+ +-----+ 847 848 849Telemetry support 850----------------- 851 852The Security library has support for displaying Crypto device information 853with respect to its Security capabilities. Telemetry commands that can be used 854are shown below. 855 856#. Get the list of available Crypto devices by ID, that supports Security features:: 857 858 --> /security/cryptodev/list 859 {"/security/cryptodev/list": [0, 1, 2, 3]} 860 861#. Get the security capabilities of a Crypto device:: 862 863 --> /security/cryptodev/sec_caps,0 864 {"/security/cryptodev/sec_caps": {"sec_caps": [<array of serialized bytes of 865 capabilities>], "sec_caps_n": <number of capabilities>}} 866 867 #. Get the security crypto capabilities of a Crypto device:: 868 869 --> /security/cryptodev/crypto_caps,0,0 870 {"/security/cryptodev/crypto_caps": {"crypto_caps": [<array of serialized bytes of 871 capabilities>], "crypto_caps_n": <number of capabilities>}} 872 873For more information on how to use the Telemetry interface, see 874the :doc:`../howto/telemetry`. 875