1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright 2017,2019-2020 NXP 3 * Copyright(c) 2017-2020 Intel Corporation. 4 */ 5 6 #ifndef _RTE_SECURITY_H_ 7 #define _RTE_SECURITY_H_ 8 9 /** 10 * @file rte_security.h 11 * 12 * RTE Security Common Definitions 13 * 14 */ 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 #include <sys/types.h> 21 22 #include <rte_compat.h> 23 #include <rte_common.h> 24 #include <rte_crypto.h> 25 #include <rte_ip.h> 26 #include <rte_mbuf_dyn.h> 27 28 /** IPSec protocol mode */ 29 enum rte_security_ipsec_sa_mode { 30 RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT = 1, 31 /**< IPSec Transport mode */ 32 RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, 33 /**< IPSec Tunnel mode */ 34 }; 35 36 /** IPSec Protocol */ 37 enum rte_security_ipsec_sa_protocol { 38 RTE_SECURITY_IPSEC_SA_PROTO_AH = 1, 39 /**< AH protocol */ 40 RTE_SECURITY_IPSEC_SA_PROTO_ESP, 41 /**< ESP protocol */ 42 }; 43 44 /** IPSEC tunnel type */ 45 enum rte_security_ipsec_tunnel_type { 46 RTE_SECURITY_IPSEC_TUNNEL_IPV4 = 1, 47 /**< Outer header is IPv4 */ 48 RTE_SECURITY_IPSEC_TUNNEL_IPV6, 49 /**< Outer header is IPv6 */ 50 }; 51 52 /** 53 * IPSEC tunnel header verification mode 54 * 55 * Controls how outer IP header is verified in inbound. 56 */ 57 #define RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR 0x1 58 #define RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR 0x2 59 60 /** 61 * Security context for crypto/eth devices 62 * 63 * Security instance for each driver to register security operations. 64 * The application can get the security context from the crypto/eth device id 65 * using the APIs rte_cryptodev_get_sec_ctx()/rte_eth_dev_get_sec_ctx() 66 * This structure is used to identify the device(crypto/eth) for which the 67 * security operations need to be performed. 68 */ 69 struct rte_security_ctx { 70 void *device; 71 /**< Crypto/ethernet device attached */ 72 const struct rte_security_ops *ops; 73 /**< Pointer to security ops for the device */ 74 uint16_t sess_cnt; 75 /**< Number of sessions attached to this context */ 76 uint16_t macsec_sc_cnt; 77 /**< Number of MACsec SC attached to this context */ 78 uint16_t macsec_sa_cnt; 79 /**< Number of MACsec SA attached to this context */ 80 uint32_t flags; 81 /**< Flags for security context */ 82 }; 83 84 #define RTE_SEC_CTX_F_FAST_SET_MDATA 0x00000001 85 /**< Driver uses fast metadata update without using driver specific callback. 86 * For fast mdata, mbuf dynamic field would be registered by driver 87 * via rte_security_dynfield_register(). 88 */ 89 90 /** 91 * IPSEC tunnel parameters 92 * 93 * These parameters are used to build outbound tunnel headers. 94 */ 95 struct rte_security_ipsec_tunnel_param { 96 enum rte_security_ipsec_tunnel_type type; 97 /**< Tunnel type: IPv4 or IPv6 */ 98 RTE_STD_C11 99 union { 100 struct { 101 struct in_addr src_ip; 102 /**< IPv4 source address */ 103 struct in_addr dst_ip; 104 /**< IPv4 destination address */ 105 uint8_t dscp; 106 /**< IPv4 Differentiated Services Code Point */ 107 uint8_t df; 108 /**< IPv4 Don't Fragment bit */ 109 uint8_t ttl; 110 /**< IPv4 Time To Live */ 111 } ipv4; 112 /**< IPv4 header parameters */ 113 struct { 114 struct in6_addr src_addr; 115 /**< IPv6 source address */ 116 struct in6_addr dst_addr; 117 /**< IPv6 destination address */ 118 uint8_t dscp; 119 /**< IPv6 Differentiated Services Code Point */ 120 uint32_t flabel; 121 /**< IPv6 flow label */ 122 uint8_t hlimit; 123 /**< IPv6 hop limit */ 124 } ipv6; 125 /**< IPv6 header parameters */ 126 }; 127 }; 128 129 struct rte_security_ipsec_udp_param { 130 uint16_t sport; 131 uint16_t dport; 132 }; 133 134 /** 135 * IPsec Security Association option flags 136 */ 137 struct rte_security_ipsec_sa_options { 138 /** Extended Sequence Numbers (ESN) 139 * 140 * * 1: Use extended (64 bit) sequence numbers 141 * * 0: Use normal sequence numbers 142 */ 143 uint32_t esn : 1; 144 145 /** UDP encapsulation 146 * 147 * * 1: Do UDP encapsulation/decapsulation so that IPSEC packets can 148 * traverse through NAT boxes. 149 * * 0: No UDP encapsulation 150 */ 151 uint32_t udp_encap : 1; 152 153 /** Copy DSCP bits 154 * 155 * * 1: Copy IPv4 or IPv6 DSCP bits from inner IP header to 156 * the outer IP header in encapsulation, and vice versa in 157 * decapsulation. 158 * * 0: Do not change DSCP field. 159 */ 160 uint32_t copy_dscp : 1; 161 162 /** Copy IPv6 Flow Label 163 * 164 * * 1: Copy IPv6 flow label from inner IPv6 header to the 165 * outer IPv6 header. 166 * * 0: Outer header is not modified. 167 */ 168 uint32_t copy_flabel : 1; 169 170 /** Copy IPv4 Don't Fragment bit 171 * 172 * * 1: Copy the DF bit from the inner IPv4 header to the outer 173 * IPv4 header. 174 * * 0: Outer header is not modified. 175 */ 176 uint32_t copy_df : 1; 177 178 /** Decrement inner packet Time To Live (TTL) field 179 * 180 * * 1: In tunnel mode, decrement inner packet IPv4 TTL or 181 * IPv6 Hop Limit after tunnel decapsulation, or before tunnel 182 * encapsulation. 183 * * 0: Inner packet is not modified. 184 */ 185 uint32_t dec_ttl : 1; 186 187 /** Explicit Congestion Notification (ECN) 188 * 189 * * 1: In tunnel mode, enable outer header ECN Field copied from 190 * inner header in tunnel encapsulation, or inner header ECN 191 * field construction in decapsulation. 192 * * 0: Inner/outer header are not modified. 193 */ 194 uint32_t ecn : 1; 195 196 /** Security statistics 197 * 198 * * 1: Enable per session security statistics collection for 199 * this SA, if supported by the driver. 200 * * 0: Disable per session security statistics collection for this SA. 201 */ 202 uint32_t stats : 1; 203 204 /** Disable IV generation in PMD 205 * 206 * * 1: Disable IV generation in PMD. When disabled, IV provided in 207 * rte_crypto_op will be used by the PMD. 208 * 209 * * 0: Enable IV generation in PMD. When enabled, PMD generated random 210 * value would be used and application is not required to provide 211 * IV. 212 * 213 * Note: For inline cases, IV generation would always need to be handled 214 * by the PMD. 215 */ 216 uint32_t iv_gen_disable : 1; 217 218 /** Verify tunnel header in inbound 219 * * ``RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR``: Verify destination 220 * IP address. 221 * 222 * * ``RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR``: Verify both 223 * source and destination IP addresses. 224 */ 225 uint32_t tunnel_hdr_verify : 2; 226 227 /** Verify UDP encapsulation ports in inbound 228 * 229 * * 1: Match UDP source and destination ports 230 * * 0: Do not match UDP ports 231 */ 232 uint32_t udp_ports_verify : 1; 233 234 /** Compute/verify inner packet IPv4 header checksum in tunnel mode 235 * 236 * * 1: For outbound, compute inner packet IPv4 header checksum 237 * before tunnel encapsulation and for inbound, verify after 238 * tunnel decapsulation. 239 * * 0: Inner packet IP header checksum is not computed/verified. 240 * 241 * The checksum verification status would be set in mbuf using 242 * RTE_MBUF_F_RX_IP_CKSUM_xxx flags. 243 * 244 * Inner IP checksum computation can also be enabled(per operation) 245 * by setting the flag RTE_MBUF_F_TX_IP_CKSUM in mbuf. 246 */ 247 uint32_t ip_csum_enable : 1; 248 249 /** Compute/verify inner packet L4 checksum in tunnel mode 250 * 251 * * 1: For outbound, compute inner packet L4 checksum before 252 * tunnel encapsulation and for inbound, verify after 253 * tunnel decapsulation. 254 * * 0: Inner packet L4 checksum is not computed/verified. 255 * 256 * The checksum verification status would be set in mbuf using 257 * RTE_MBUF_F_RX_L4_CKSUM_xxx flags. 258 * 259 * Inner L4 checksum computation can also be enabled(per operation) 260 * by setting the flags RTE_MBUF_F_TX_TCP_CKSUM or RTE_MBUF_F_TX_SCTP_CKSUM or 261 * RTE_MBUF_F_TX_UDP_CKSUM or RTE_MBUF_F_TX_L4_MASK in mbuf. 262 */ 263 uint32_t l4_csum_enable : 1; 264 265 /** Enable IP reassembly on inline inbound packets. 266 * 267 * * 1: Enable driver to try reassembly of encrypted IP packets for 268 * this SA, if supported by the driver. This feature will work 269 * only if user has successfully set IP reassembly config params 270 * using rte_eth_ip_reassembly_conf_set() for the inline Ethernet 271 * device. PMD need to register mbuf dynamic fields using 272 * rte_eth_ip_reassembly_dynfield_register() and security session 273 * creation would fail if dynfield is not registered successfully. 274 * * 0: Disable IP reassembly of packets (default). 275 */ 276 uint32_t ip_reassembly_en : 1; 277 278 /** Reserved bit fields for future extension 279 * 280 * User should ensure reserved_opts is cleared as it may change in 281 * subsequent releases to support new options. 282 * 283 * Note: Reduce number of bits in reserved_opts for every new option. 284 */ 285 uint32_t reserved_opts : 17; 286 }; 287 288 /** IPSec security association direction */ 289 enum rte_security_ipsec_sa_direction { 290 RTE_SECURITY_IPSEC_SA_DIR_EGRESS, 291 /**< Encrypt and generate digest */ 292 RTE_SECURITY_IPSEC_SA_DIR_INGRESS, 293 /**< Verify digest and decrypt */ 294 }; 295 296 /** 297 * Configure soft and hard lifetime of an IPsec SA 298 * 299 * Lifetime of an IPsec SA would specify the maximum number of packets or bytes 300 * that can be processed. IPsec operations would start failing once any hard 301 * limit is reached. 302 * 303 * Soft limits can be specified to generate notification when the SA is 304 * approaching hard limits for lifetime. For inline operations, reaching soft 305 * expiry limit would result in raising an eth event for the same. For lookaside 306 * operations, this would result in a warning returned in 307 * ``rte_crypto_op.aux_flags``. 308 */ 309 struct rte_security_ipsec_lifetime { 310 uint64_t packets_soft_limit; 311 /**< Soft expiry limit in number of packets */ 312 uint64_t bytes_soft_limit; 313 /**< Soft expiry limit in bytes */ 314 uint64_t packets_hard_limit; 315 /**< Hard expiry limit in number of packets */ 316 uint64_t bytes_hard_limit; 317 /**< Hard expiry limit in bytes */ 318 }; 319 320 /** 321 * IPsec security association configuration data. 322 * 323 * This structure contains data required to create an IPsec SA security session. 324 */ 325 struct rte_security_ipsec_xform { 326 uint32_t spi; 327 /**< SA security parameter index */ 328 uint32_t salt; 329 /**< SA salt */ 330 struct rte_security_ipsec_sa_options options; 331 /**< various SA options */ 332 enum rte_security_ipsec_sa_direction direction; 333 /**< IPSec SA Direction - Egress/Ingress */ 334 enum rte_security_ipsec_sa_protocol proto; 335 /**< IPsec SA Protocol - AH/ESP */ 336 enum rte_security_ipsec_sa_mode mode; 337 /**< IPsec SA Mode - transport/tunnel */ 338 struct rte_security_ipsec_tunnel_param tunnel; 339 /**< Tunnel parameters, NULL for transport mode */ 340 struct rte_security_ipsec_lifetime life; 341 /**< IPsec SA lifetime */ 342 uint32_t replay_win_sz; 343 /**< Anti replay window size to enable sequence replay attack handling. 344 * replay checking is disabled if the window size is 0. 345 */ 346 union { 347 uint64_t value; 348 struct { 349 uint32_t low; 350 uint32_t hi; 351 }; 352 } esn; 353 /**< Extended Sequence Number */ 354 struct rte_security_ipsec_udp_param udp; 355 /**< UDP parameters, ignored when udp_encap option not specified */ 356 }; 357 358 /** 359 * MACSec packet flow direction 360 */ 361 enum rte_security_macsec_direction { 362 /** Generate SecTag and encrypt/authenticate */ 363 RTE_SECURITY_MACSEC_DIR_TX, 364 /** Remove SecTag and decrypt/verify */ 365 RTE_SECURITY_MACSEC_DIR_RX, 366 }; 367 368 /** Maximum number of association numbers for a secure channel. */ 369 #define RTE_SECURITY_MACSEC_NUM_AN 4 370 /** Salt length for MACsec SA. */ 371 #define RTE_SECURITY_MACSEC_SALT_LEN 12 372 373 /** 374 * MACsec secure association (SA) configuration structure. 375 */ 376 struct rte_security_macsec_sa { 377 /** Direction of SA */ 378 enum rte_security_macsec_direction dir; 379 /** MACsec SA key for AES-GCM 128/256 */ 380 struct { 381 const uint8_t *data; /**< pointer to key data */ 382 uint16_t length; /**< key length in bytes */ 383 } key; 384 /** 96-bit value distributed by key agreement protocol */ 385 uint8_t salt[RTE_SECURITY_MACSEC_SALT_LEN]; 386 /** Association number to be used */ 387 uint8_t an : 2; 388 /** Short Secure Channel Identifier, to be used for XPN cases */ 389 uint32_t ssci; 390 /** Extended packet number */ 391 uint32_t xpn; 392 /** Packet number expected/ to be used for next packet of this SA */ 393 uint32_t next_pn; 394 }; 395 396 /** 397 * MACsec Secure Channel configuration parameters. 398 */ 399 struct rte_security_macsec_sc { 400 /** Direction of SC */ 401 enum rte_security_macsec_direction dir; 402 union { 403 struct { 404 /** SAs for each association number */ 405 uint16_t sa_id[RTE_SECURITY_MACSEC_NUM_AN]; 406 /** flag to denote which all SAs are in use for each association number */ 407 uint8_t sa_in_use[RTE_SECURITY_MACSEC_NUM_AN]; 408 /** Channel is active */ 409 uint8_t active : 1; 410 /** Reserved bitfields for future */ 411 uint8_t reserved : 7; 412 } sc_rx; 413 struct { 414 uint16_t sa_id; /**< SA ID to be used for encryption */ 415 uint16_t sa_id_rekey; /**< Rekeying SA ID to be used for encryption */ 416 uint64_t sci; /**< SCI value to be used if send_sci is set */ 417 uint8_t active : 1; /**< Channel is active */ 418 uint8_t re_key_en : 1; /**< Enable Rekeying */ 419 /** Reserved bitfields for future */ 420 uint8_t reserved : 6; 421 } sc_tx; 422 }; 423 }; 424 425 /** 426 * MACsec Supported Algorithm list as per IEEE Std 802.1AE. 427 */ 428 enum rte_security_macsec_alg { 429 RTE_SECURITY_MACSEC_ALG_GCM_128, /**< AES-GCM 128 bit block cipher */ 430 RTE_SECURITY_MACSEC_ALG_GCM_256, /**< AES-GCM 256 bit block cipher */ 431 RTE_SECURITY_MACSEC_ALG_GCM_XPN_128, /**< AES-GCM 128 bit block cipher with unique SSCI */ 432 RTE_SECURITY_MACSEC_ALG_GCM_XPN_256, /**< AES-GCM 256 bit block cipher with unique SSCI */ 433 }; 434 435 /** Disable Validation of MACsec frame. */ 436 #define RTE_SECURITY_MACSEC_VALIDATE_DISABLE 0 437 /** Validate MACsec frame but do not discard invalid frame. */ 438 #define RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD 1 439 /** Validate MACsec frame and discart invalid frame. */ 440 #define RTE_SECURITY_MACSEC_VALIDATE_STRICT 2 441 /** Do not perform any MACsec operation. */ 442 #define RTE_SECURITY_MACSEC_VALIDATE_NO_OP 3 443 444 /** 445 * MACsec security session configuration 446 */ 447 struct rte_security_macsec_xform { 448 /** Direction of flow/secure channel */ 449 enum rte_security_macsec_direction dir; 450 /** MACsec algorithm to be used */ 451 enum rte_security_macsec_alg alg; 452 /** Cipher offset from start of Ethernet header */ 453 uint8_t cipher_off; 454 /** 455 * SCI to be used for RX flow identification or 456 * to set SCI in packet for TX when send_sci is set 457 */ 458 uint64_t sci; 459 /** Receive/transmit secure channel ID created by *rte_security_macsec_sc_create* */ 460 uint16_t sc_id; 461 union { 462 struct { 463 /** MTU for transmit frame (valid for inline processing) */ 464 uint16_t mtu; 465 /** 466 * Offset to insert sectag from start of ethernet header or 467 * from a matching VLAN tag 468 */ 469 uint8_t sectag_off; 470 /** Enable MACsec protection of frames */ 471 uint16_t protect_frames : 1; 472 /** 473 * Sectag insertion mode 474 * If 1, Sectag is inserted at fixed sectag_off set above. 475 * If 0, Sectag is inserted at relative sectag_off from a matching 476 * VLAN tag set. 477 */ 478 uint16_t sectag_insert_mode : 1; 479 /** ICV includes source and destination MAC addresses */ 480 uint16_t icv_include_da_sa : 1; 481 /** Control port is enabled */ 482 uint16_t ctrl_port_enable : 1; 483 /** Version of MACsec header. Should be 0 */ 484 uint16_t sectag_version : 1; 485 /** Enable end station. SCI is not valid */ 486 uint16_t end_station : 1; 487 /** Send SCI along with sectag */ 488 uint16_t send_sci : 1; 489 /** enable secure channel support EPON - single copy broadcast */ 490 uint16_t scb : 1; 491 /** 492 * Enable packet encryption and set RTE_MACSEC_TCI_C and 493 * RTE_MACSEC_TCI_E in sectag 494 */ 495 uint16_t encrypt : 1; 496 /** Reserved bitfields for future */ 497 uint16_t reserved : 7; 498 } tx_secy; 499 struct { 500 /** Replay Window size to be supported */ 501 uint32_t replay_win_sz; 502 /** Set bits as per RTE_SECURITY_MACSEC_VALIDATE_* */ 503 uint16_t validate_frames : 2; 504 /** ICV includes source and destination MAC addresses */ 505 uint16_t icv_include_da_sa : 1; 506 /** Control port is enabled */ 507 uint16_t ctrl_port_enable : 1; 508 /** Do not strip SecTAG after processing */ 509 uint16_t preserve_sectag : 1; 510 /** Do not strip ICV from the packet after processing */ 511 uint16_t preserve_icv : 1; 512 /** Enable anti-replay protection */ 513 uint16_t replay_protect : 1; 514 /** Reserved bitfields for future */ 515 uint16_t reserved : 9; 516 } rx_secy; 517 }; 518 }; 519 520 /** 521 * PDCP Mode of session 522 */ 523 enum rte_security_pdcp_domain { 524 RTE_SECURITY_PDCP_MODE_CONTROL, /**< PDCP control plane */ 525 RTE_SECURITY_PDCP_MODE_DATA, /**< PDCP data plane */ 526 RTE_SECURITY_PDCP_MODE_SHORT_MAC, /**< PDCP short mac */ 527 }; 528 529 /** PDCP Frame direction */ 530 enum rte_security_pdcp_direction { 531 RTE_SECURITY_PDCP_UPLINK, /**< Uplink */ 532 RTE_SECURITY_PDCP_DOWNLINK, /**< Downlink */ 533 }; 534 535 /** PDCP Sequence Number Size selectors */ 536 enum rte_security_pdcp_sn_size { 537 /** PDCP_SN_SIZE_5: 5bit sequence number */ 538 RTE_SECURITY_PDCP_SN_SIZE_5 = 5, 539 /** PDCP_SN_SIZE_7: 7bit sequence number */ 540 RTE_SECURITY_PDCP_SN_SIZE_7 = 7, 541 /** PDCP_SN_SIZE_12: 12bit sequence number */ 542 RTE_SECURITY_PDCP_SN_SIZE_12 = 12, 543 /** PDCP_SN_SIZE_15: 15bit sequence number */ 544 RTE_SECURITY_PDCP_SN_SIZE_15 = 15, 545 /** PDCP_SN_SIZE_18: 18bit sequence number */ 546 RTE_SECURITY_PDCP_SN_SIZE_18 = 18 547 }; 548 549 /** 550 * PDCP security association configuration data. 551 * 552 * This structure contains data required to create a PDCP security session. 553 */ 554 struct rte_security_pdcp_xform { 555 int8_t bearer; /**< PDCP bearer ID */ 556 /** Enable in order delivery, this field shall be set only if 557 * driver/HW is capable. See RTE_SECURITY_PDCP_ORDERING_CAP. 558 */ 559 uint8_t en_ordering; 560 /** Notify driver/HW to detect and remove duplicate packets. 561 * This field should be set only when driver/hw is capable. 562 * See RTE_SECURITY_PDCP_DUP_DETECT_CAP. 563 */ 564 uint8_t remove_duplicates; 565 /** PDCP mode of operation: Control or data */ 566 enum rte_security_pdcp_domain domain; 567 /** PDCP Frame Direction 0:UL 1:DL */ 568 enum rte_security_pdcp_direction pkt_dir; 569 /** Sequence number size, 5/7/12/15/18 */ 570 enum rte_security_pdcp_sn_size sn_size; 571 /** Starting Hyper Frame Number to be used together with the SN 572 * from the PDCP frames 573 */ 574 uint32_t hfn; 575 /** HFN Threshold for key renegotiation */ 576 uint32_t hfn_threshold; 577 /** HFN can be given as a per packet value also. 578 * As we do not have IV in case of PDCP, and HFN is 579 * used to generate IV. IV field can be used to get the 580 * per packet HFN while enq/deq. 581 * If hfn_ovrd field is set, user is expected to set the 582 * per packet HFN in place of IV. PMDs will extract the HFN 583 * and perform operations accordingly. 584 */ 585 uint8_t hfn_ovrd; 586 /** In case of 5G NR, a new protocol (SDAP) header may be set 587 * inside PDCP payload which should be authenticated but not 588 * encrypted. Hence, driver should be notified if SDAP is 589 * enabled or not, so that SDAP header is not encrypted. 590 */ 591 uint8_t sdap_enabled; 592 /** Reserved for future */ 593 uint16_t reserved; 594 }; 595 596 /** DOCSIS direction */ 597 enum rte_security_docsis_direction { 598 RTE_SECURITY_DOCSIS_UPLINK, 599 /**< Uplink 600 * - Decryption, followed by CRC Verification 601 */ 602 RTE_SECURITY_DOCSIS_DOWNLINK, 603 /**< Downlink 604 * - CRC Generation, followed by Encryption 605 */ 606 }; 607 608 /** 609 * DOCSIS security session configuration. 610 * 611 * This structure contains data required to create a DOCSIS security session. 612 */ 613 struct rte_security_docsis_xform { 614 enum rte_security_docsis_direction direction; 615 /**< DOCSIS direction */ 616 }; 617 618 /** 619 * Security session action type. 620 */ 621 enum rte_security_session_action_type { 622 RTE_SECURITY_ACTION_TYPE_NONE, 623 /**< No security actions */ 624 RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO, 625 /**< Crypto processing for security protocol is processed inline 626 * during transmission 627 */ 628 RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL, 629 /**< All security protocol processing is performed inline during 630 * transmission 631 */ 632 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 633 /**< All security protocol processing including crypto is performed 634 * on a lookaside accelerator 635 */ 636 RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO 637 /**< Similar to ACTION_TYPE_NONE but crypto processing for security 638 * protocol is processed synchronously by a CPU. 639 */ 640 }; 641 642 /** Security session protocol definition */ 643 enum rte_security_session_protocol { 644 RTE_SECURITY_PROTOCOL_IPSEC = 1, 645 /**< IPsec Protocol */ 646 RTE_SECURITY_PROTOCOL_MACSEC, 647 /**< MACSec Protocol */ 648 RTE_SECURITY_PROTOCOL_PDCP, 649 /**< PDCP Protocol */ 650 RTE_SECURITY_PROTOCOL_DOCSIS, 651 /**< DOCSIS Protocol */ 652 }; 653 654 /** 655 * Security session configuration 656 */ 657 struct rte_security_session_conf { 658 enum rte_security_session_action_type action_type; 659 /**< Type of action to be performed on the session */ 660 enum rte_security_session_protocol protocol; 661 /**< Security protocol to be configured */ 662 RTE_STD_C11 663 union { 664 struct rte_security_ipsec_xform ipsec; 665 struct rte_security_macsec_xform macsec; 666 struct rte_security_pdcp_xform pdcp; 667 struct rte_security_docsis_xform docsis; 668 }; 669 /**< Configuration parameters for security session */ 670 struct rte_crypto_sym_xform *crypto_xform; 671 /**< Security Session Crypto Transformations. NULL in case of MACsec. */ 672 void *userdata; 673 /**< Application specific userdata to be saved with session */ 674 }; 675 676 /** 677 * Create security session as specified by the session configuration 678 * 679 * @param instance security instance 680 * @param conf session configuration parameters 681 * @param mp mempool to allocate session objects from 682 * @return 683 * - On success, pointer to session 684 * - On failure, NULL 685 */ 686 void * 687 rte_security_session_create(struct rte_security_ctx *instance, 688 struct rte_security_session_conf *conf, 689 struct rte_mempool *mp); 690 691 /** 692 * Update security session as specified by the session configuration 693 * 694 * @param instance security instance 695 * @param sess session to update parameters 696 * @param conf update configuration parameters 697 * @return 698 * - On success returns 0 699 * - On failure returns a negative errno value. 700 */ 701 __rte_experimental 702 int 703 rte_security_session_update(struct rte_security_ctx *instance, 704 void *sess, 705 struct rte_security_session_conf *conf); 706 707 /** 708 * Get the size of the security session data for a device. 709 * 710 * @param instance security instance. 711 * 712 * @return 713 * - Size of the private data, if successful 714 * - 0 if device is invalid or does not support the operation. 715 */ 716 unsigned int 717 rte_security_session_get_size(struct rte_security_ctx *instance); 718 719 /** 720 * Free security session header and the session private data and 721 * return it to its original mempool. 722 * 723 * @param instance security instance 724 * @param sess security session to be freed 725 * 726 * @return 727 * - 0 if successful. 728 * - -EINVAL if session or context instance is NULL. 729 * - -EBUSY if not all device private data has been freed. 730 * - -ENOTSUP if destroying private data is not supported. 731 * - other negative values in case of freeing private data errors. 732 */ 733 int 734 rte_security_session_destroy(struct rte_security_ctx *instance, void *sess); 735 736 /** 737 * @warning 738 * @b EXPERIMENTAL: this API may change without prior notice 739 * 740 * Create MACsec security channel (SC). 741 * 742 * @param instance security instance 743 * @param conf MACsec SC configuration params 744 * @return 745 * - secure channel ID if successful. 746 * - -EINVAL if configuration params are invalid of instance is NULL. 747 * - -ENOTSUP if device does not support MACsec. 748 * - -ENOMEM if PMD is not capable to create more SC. 749 * - other negative value for other errors. 750 */ 751 __rte_experimental 752 int 753 rte_security_macsec_sc_create(struct rte_security_ctx *instance, 754 struct rte_security_macsec_sc *conf); 755 756 /** 757 * @warning 758 * @b EXPERIMENTAL: this API may change without prior notice 759 * 760 * Destroy MACsec security channel (SC). 761 * 762 * @param instance security instance 763 * @param sc_id SC ID to be destroyed 764 * @return 765 * - 0 if successful. 766 * - -EINVAL if sc_id is invalid or instance is NULL. 767 * - -EBUSY if sc is being used by some session. 768 */ 769 __rte_experimental 770 int 771 rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id); 772 773 /** 774 * @warning 775 * @b EXPERIMENTAL: this API may change without prior notice 776 * 777 * Create MACsec security association (SA). 778 * 779 * @param instance security instance 780 * @param conf MACsec SA configuration params 781 * @return 782 * - positive SA ID if successful. 783 * - -EINVAL if configuration params are invalid of instance is NULL. 784 * - -ENOTSUP if device does not support MACsec. 785 * - -ENOMEM if PMD is not capable to create more SAs. 786 * - other negative value for other errors. 787 */ 788 __rte_experimental 789 int 790 rte_security_macsec_sa_create(struct rte_security_ctx *instance, 791 struct rte_security_macsec_sa *conf); 792 793 /** 794 * @warning 795 * @b EXPERIMENTAL: this API may change without prior notice 796 * 797 * Destroy MACsec security association (SA). 798 * 799 * @param instance security instance 800 * @param sa_id SA ID to be destroyed 801 * @return 802 * - 0 if successful. 803 * - -EINVAL if sa_id is invalid or instance is NULL. 804 * - -EBUSY if sa is being used by some session. 805 */ 806 __rte_experimental 807 int 808 rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id); 809 810 /** Device-specific metadata field type */ 811 typedef uint64_t rte_security_dynfield_t; 812 /** Dynamic mbuf field for device-specific metadata */ 813 extern int rte_security_dynfield_offset; 814 815 /** 816 * @warning 817 * @b EXPERIMENTAL: this API may change without prior notice 818 * 819 * Get pointer to mbuf field for device-specific metadata. 820 * 821 * For performance reason, no check is done, 822 * the dynamic field may not be registered. 823 * @see rte_security_dynfield_is_registered 824 * 825 * @param mbuf packet to access 826 * @return pointer to mbuf field 827 */ 828 __rte_experimental 829 static inline rte_security_dynfield_t * 830 rte_security_dynfield(struct rte_mbuf *mbuf) 831 { 832 return RTE_MBUF_DYNFIELD(mbuf, 833 rte_security_dynfield_offset, 834 rte_security_dynfield_t *); 835 } 836 837 /** 838 * @warning 839 * @b EXPERIMENTAL: this API may change without prior notice 840 * 841 * Check whether the dynamic field is registered. 842 * 843 * @return true if rte_security_dynfield_register() has been called. 844 */ 845 __rte_experimental 846 static inline bool rte_security_dynfield_is_registered(void) 847 { 848 return rte_security_dynfield_offset >= 0; 849 } 850 851 #define RTE_SECURITY_SESS_OPAQUE_DATA_OFF 0 852 #define RTE_SECURITY_SESS_FAST_MDATA_OFF 1 853 /** 854 * Get opaque data from session handle 855 */ 856 static inline uint64_t 857 rte_security_session_opaque_data_get(void *sess) 858 { 859 return *((uint64_t *)sess + RTE_SECURITY_SESS_OPAQUE_DATA_OFF); 860 } 861 862 /** 863 * Set opaque data in session handle 864 */ 865 static inline void 866 rte_security_session_opaque_data_set(void *sess, uint64_t opaque) 867 { 868 uint64_t *data; 869 data = (((uint64_t *)sess) + RTE_SECURITY_SESS_OPAQUE_DATA_OFF); 870 *data = opaque; 871 } 872 873 /** 874 * Get fast mdata from session handle 875 */ 876 static inline uint64_t 877 rte_security_session_fast_mdata_get(void *sess) 878 { 879 return *((uint64_t *)sess + RTE_SECURITY_SESS_FAST_MDATA_OFF); 880 } 881 882 /** 883 * Set fast mdata in session handle 884 */ 885 static inline void 886 rte_security_session_fast_mdata_set(void *sess, uint64_t fdata) 887 { 888 uint64_t *data; 889 data = (((uint64_t *)sess) + RTE_SECURITY_SESS_FAST_MDATA_OFF); 890 *data = fdata; 891 } 892 893 /** Function to call PMD specific function pointer set_pkt_metadata() */ 894 __rte_experimental 895 extern int __rte_security_set_pkt_metadata(struct rte_security_ctx *instance, 896 void *sess, 897 struct rte_mbuf *m, void *params); 898 899 /** 900 * Updates the buffer with device-specific defined metadata 901 * 902 * @param instance security instance 903 * @param sess security session 904 * @param mb packet mbuf to set metadata on. 905 * @param params device-specific defined parameters 906 * required for metadata 907 * 908 * @return 909 * - On success, zero. 910 * - On failure, a negative value. 911 */ 912 static inline int 913 rte_security_set_pkt_metadata(struct rte_security_ctx *instance, 914 void *sess, 915 struct rte_mbuf *mb, void *params) 916 { 917 /* Fast Path */ 918 if (instance->flags & RTE_SEC_CTX_F_FAST_SET_MDATA) { 919 *rte_security_dynfield(mb) = (rte_security_dynfield_t) 920 rte_security_session_fast_mdata_get(sess); 921 return 0; 922 } 923 924 /* Jump to PMD specific function pointer */ 925 return __rte_security_set_pkt_metadata(instance, sess, mb, params); 926 } 927 928 /** 929 * Attach a session to a symmetric crypto operation 930 * 931 * @param sym_op crypto operation 932 * @param sess security session 933 */ 934 static inline int 935 __rte_security_attach_session(struct rte_crypto_sym_op *sym_op, void *sess) 936 { 937 sym_op->session = sess; 938 939 return 0; 940 } 941 942 /** 943 * Attach a session to a crypto operation. 944 * This API is needed only in case of RTE_SECURITY_SESS_CRYPTO_PROTO_OFFLOAD 945 * For other rte_security_session_action_type, ol_flags in rte_mbuf may be 946 * defined to perform security operations. 947 * 948 * @param op crypto operation 949 * @param sess security session 950 */ 951 static inline int 952 rte_security_attach_session(struct rte_crypto_op *op, 953 void *sess) 954 { 955 if (unlikely(op->type != RTE_CRYPTO_OP_TYPE_SYMMETRIC)) 956 return -EINVAL; 957 958 op->sess_type = RTE_CRYPTO_OP_SECURITY_SESSION; 959 960 return __rte_security_attach_session(op->sym, sess); 961 } 962 963 struct rte_security_macsec_secy_stats { 964 uint64_t ctl_pkt_bcast_cnt; 965 uint64_t ctl_pkt_mcast_cnt; 966 uint64_t ctl_pkt_ucast_cnt; 967 uint64_t ctl_octet_cnt; 968 uint64_t unctl_pkt_bcast_cnt; 969 uint64_t unctl_pkt_mcast_cnt; 970 uint64_t unctl_pkt_ucast_cnt; 971 uint64_t unctl_octet_cnt; 972 /* Valid only for Rx */ 973 uint64_t octet_decrypted_cnt; 974 uint64_t octet_validated_cnt; 975 uint64_t pkt_port_disabled_cnt; 976 uint64_t pkt_badtag_cnt; 977 uint64_t pkt_nosa_cnt; 978 uint64_t pkt_nosaerror_cnt; 979 uint64_t pkt_tagged_ctl_cnt; 980 uint64_t pkt_untaged_cnt; 981 uint64_t pkt_ctl_cnt; 982 uint64_t pkt_notag_cnt; 983 /* Valid only for Tx */ 984 uint64_t octet_encrypted_cnt; 985 uint64_t octet_protected_cnt; 986 uint64_t pkt_noactivesa_cnt; 987 uint64_t pkt_toolong_cnt; 988 uint64_t pkt_untagged_cnt; 989 }; 990 991 struct rte_security_macsec_sc_stats { 992 /* Rx */ 993 uint64_t hit_cnt; 994 uint64_t pkt_invalid_cnt; 995 uint64_t pkt_late_cnt; 996 uint64_t pkt_notvalid_cnt; 997 uint64_t pkt_unchecked_cnt; 998 uint64_t pkt_delay_cnt; 999 uint64_t pkt_ok_cnt; 1000 uint64_t octet_decrypt_cnt; 1001 uint64_t octet_validate_cnt; 1002 /* Tx */ 1003 uint64_t pkt_encrypt_cnt; 1004 uint64_t pkt_protected_cnt; 1005 uint64_t octet_encrypt_cnt; 1006 uint64_t octet_protected_cnt; 1007 }; 1008 1009 struct rte_security_macsec_sa_stats { 1010 /* Rx */ 1011 uint64_t pkt_invalid_cnt; 1012 uint64_t pkt_nosaerror_cnt; 1013 uint64_t pkt_notvalid_cnt; 1014 uint64_t pkt_ok_cnt; 1015 uint64_t pkt_nosa_cnt; 1016 /* Tx */ 1017 uint64_t pkt_encrypt_cnt; 1018 uint64_t pkt_protected_cnt; 1019 }; 1020 1021 struct rte_security_ipsec_stats { 1022 uint64_t ipackets; /**< Successfully received IPsec packets. */ 1023 uint64_t opackets; /**< Successfully transmitted IPsec packets.*/ 1024 uint64_t ibytes; /**< Successfully received IPsec bytes. */ 1025 uint64_t obytes; /**< Successfully transmitted IPsec bytes. */ 1026 uint64_t ierrors; /**< IPsec packets receive/decrypt errors. */ 1027 uint64_t oerrors; /**< IPsec packets transmit/encrypt errors. */ 1028 uint64_t reserved1; /**< Reserved for future use. */ 1029 uint64_t reserved2; /**< Reserved for future use. */ 1030 }; 1031 1032 struct rte_security_pdcp_stats { 1033 uint64_t reserved; 1034 }; 1035 1036 struct rte_security_docsis_stats { 1037 uint64_t reserved; 1038 }; 1039 1040 struct rte_security_stats { 1041 enum rte_security_session_protocol protocol; 1042 /**< Security protocol to be configured */ 1043 1044 RTE_STD_C11 1045 union { 1046 struct rte_security_macsec_secy_stats macsec; 1047 struct rte_security_ipsec_stats ipsec; 1048 struct rte_security_pdcp_stats pdcp; 1049 struct rte_security_docsis_stats docsis; 1050 }; 1051 }; 1052 1053 /** 1054 * Get security session statistics 1055 * 1056 * @param instance security instance 1057 * @param sess security session 1058 * If security session is NULL then global (per security instance) statistics 1059 * will be retrieved, if supported. Global statistics collection is not 1060 * dependent on the per session statistics configuration. 1061 * @param stats statistics 1062 * @return 1063 * - On success, return 0 1064 * - On failure, a negative value 1065 */ 1066 __rte_experimental 1067 int 1068 rte_security_session_stats_get(struct rte_security_ctx *instance, 1069 void *sess, 1070 struct rte_security_stats *stats); 1071 1072 /** 1073 * @warning 1074 * @b EXPERIMENTAL: this API may change without prior notice 1075 * 1076 * Get MACsec SA statistics. 1077 * 1078 * @param instance security instance 1079 * @param sa_id SA ID for which stats are needed 1080 * @param stats statistics 1081 * @return 1082 * - On success, return 0. 1083 * - On failure, a negative value. 1084 */ 1085 __rte_experimental 1086 int 1087 rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance, 1088 uint16_t sa_id, 1089 struct rte_security_macsec_sa_stats *stats); 1090 1091 /** 1092 * @warning 1093 * @b EXPERIMENTAL: this API may change without prior notice 1094 * 1095 * Get MACsec SC statistics. 1096 * 1097 * @param instance security instance 1098 * @param sc_id SC ID for which stats are needed 1099 * @param stats SC statistics 1100 * @return 1101 * - On success, return 0. 1102 * - On failure, a negative value. 1103 */ 1104 __rte_experimental 1105 int 1106 rte_security_macsec_sc_stats_get(struct rte_security_ctx *instance, 1107 uint16_t sc_id, 1108 struct rte_security_macsec_sc_stats *stats); 1109 1110 /** 1111 * Security capability definition 1112 */ 1113 struct rte_security_capability { 1114 enum rte_security_session_action_type action; 1115 /**< Security action type*/ 1116 enum rte_security_session_protocol protocol; 1117 /**< Security protocol */ 1118 RTE_STD_C11 1119 union { 1120 struct { 1121 enum rte_security_ipsec_sa_protocol proto; 1122 /**< IPsec SA protocol */ 1123 enum rte_security_ipsec_sa_mode mode; 1124 /**< IPsec SA mode */ 1125 enum rte_security_ipsec_sa_direction direction; 1126 /**< IPsec SA direction */ 1127 struct rte_security_ipsec_sa_options options; 1128 /**< IPsec SA supported options */ 1129 uint32_t replay_win_sz_max; 1130 /**< IPsec Anti Replay Window Size. A '0' value 1131 * indicates that Anti Replay is not supported. 1132 */ 1133 } ipsec; 1134 /**< IPsec capability */ 1135 struct { 1136 /** MTU supported for inline TX */ 1137 uint16_t mtu; 1138 /** MACsec algorithm to be used */ 1139 enum rte_security_macsec_alg alg; 1140 /** Maximum number of secure channels supported */ 1141 uint16_t max_nb_sc; 1142 /** Maximum number of SAs supported */ 1143 uint16_t max_nb_sa; 1144 /** Maximum number of SAs supported */ 1145 uint16_t max_nb_sess; 1146 /** MACsec anti replay window size */ 1147 uint32_t replay_win_sz; 1148 /** Support Sectag insertion at relative offset */ 1149 uint16_t relative_sectag_insert : 1; 1150 /** Support Sectag insertion at fixed offset */ 1151 uint16_t fixed_sectag_insert : 1; 1152 /** ICV includes source and destination MAC addresses */ 1153 uint16_t icv_include_da_sa : 1; 1154 /** Control port traffic is supported */ 1155 uint16_t ctrl_port_enable : 1; 1156 /** Do not strip SecTAG after processing */ 1157 uint16_t preserve_sectag : 1; 1158 /** Do not strip ICV from the packet after processing */ 1159 uint16_t preserve_icv : 1; 1160 /** Support frame validation as per RTE_SECURITY_MACSEC_VALIDATE_* */ 1161 uint16_t validate_frames : 1; 1162 /** support re-keying on SA expiry */ 1163 uint16_t re_key : 1; 1164 /** support anti replay */ 1165 uint16_t anti_replay : 1; 1166 /** Reserved bitfields for future capabilities */ 1167 uint16_t reserved : 7; 1168 } macsec; 1169 /**< MACsec capability */ 1170 struct { 1171 enum rte_security_pdcp_domain domain; 1172 /**< PDCP mode of operation: Control or data */ 1173 uint32_t capa_flags; 1174 /**< Capability flags, see RTE_SECURITY_PDCP_* */ 1175 } pdcp; 1176 /**< PDCP capability */ 1177 struct { 1178 enum rte_security_docsis_direction direction; 1179 /**< DOCSIS direction */ 1180 } docsis; 1181 /**< DOCSIS capability */ 1182 }; 1183 1184 const struct rte_cryptodev_capabilities *crypto_capabilities; 1185 /**< Corresponding crypto capabilities for security capability */ 1186 1187 uint32_t ol_flags; 1188 /**< Device offload flags */ 1189 }; 1190 1191 /** Underlying Hardware/driver which support PDCP may or may not support 1192 * packet ordering. Set RTE_SECURITY_PDCP_ORDERING_CAP if it support. 1193 * If it is not set, driver/HW assumes packets received are in order 1194 * and it will be application's responsibility to maintain ordering. 1195 */ 1196 #define RTE_SECURITY_PDCP_ORDERING_CAP 0x00000001 1197 1198 /** Underlying Hardware/driver which support PDCP may or may not detect 1199 * duplicate packet. Set RTE_SECURITY_PDCP_DUP_DETECT_CAP if it support. 1200 * If it is not set, driver/HW assumes there is no duplicate packet received. 1201 */ 1202 #define RTE_SECURITY_PDCP_DUP_DETECT_CAP 0x00000002 1203 1204 #define RTE_SECURITY_TX_OLOAD_NEED_MDATA 0x00000001 1205 /**< HW needs metadata update, see rte_security_set_pkt_metadata(). 1206 */ 1207 1208 #define RTE_SECURITY_TX_HW_TRAILER_OFFLOAD 0x00000002 1209 /**< HW constructs trailer of packets 1210 * Transmitted packets will have the trailer added to them 1211 * by hardware. The next protocol field will be based on 1212 * the mbuf->inner_esp_next_proto field. 1213 */ 1214 #define RTE_SECURITY_RX_HW_TRAILER_OFFLOAD 0x00010000 1215 /**< HW removes trailer of packets 1216 * Received packets have no trailer, the next protocol field 1217 * is supplied in the mbuf->inner_esp_next_proto field. 1218 * Inner packet is not modified. 1219 */ 1220 1221 /** 1222 * Security capability index used to query a security instance for a specific 1223 * security capability 1224 */ 1225 struct rte_security_capability_idx { 1226 enum rte_security_session_action_type action; 1227 enum rte_security_session_protocol protocol; 1228 1229 RTE_STD_C11 1230 union { 1231 struct { 1232 enum rte_security_ipsec_sa_protocol proto; 1233 enum rte_security_ipsec_sa_mode mode; 1234 enum rte_security_ipsec_sa_direction direction; 1235 } ipsec; 1236 struct { 1237 enum rte_security_pdcp_domain domain; 1238 uint32_t capa_flags; 1239 } pdcp; 1240 struct { 1241 enum rte_security_docsis_direction direction; 1242 } docsis; 1243 }; 1244 }; 1245 1246 /** 1247 * Returns array of security instance capabilities 1248 * 1249 * @param instance Security instance. 1250 * 1251 * @return 1252 * - Returns array of security capabilities. 1253 * - Return NULL if no capabilities available. 1254 */ 1255 const struct rte_security_capability * 1256 rte_security_capabilities_get(struct rte_security_ctx *instance); 1257 1258 /** 1259 * Query if a specific capability is available on security instance 1260 * 1261 * @param instance security instance. 1262 * @param idx security capability index to match against 1263 * 1264 * @return 1265 * - Returns pointer to security capability on match of capability 1266 * index criteria. 1267 * - Return NULL if the capability not matched on security instance. 1268 */ 1269 const struct rte_security_capability * 1270 rte_security_capability_get(struct rte_security_ctx *instance, 1271 struct rte_security_capability_idx *idx); 1272 1273 #ifdef __cplusplus 1274 } 1275 #endif 1276 1277 #endif /* _RTE_SECURITY_H_ */ 1278