1.. SPDX-License-Identifier: BSD-3-Clause 2 Copyright(c) 2016-2017 Intel Corporation. 3 Copyright (C) 2020 Marvell International Ltd. 4 5IPsec Security Gateway Sample Application 6========================================= 7 8The IPsec Security Gateway application is an example of a "real world" 9application using DPDK cryptodev framework. 10 11Overview 12-------- 13 14The application demonstrates the implementation of a Security Gateway 15(not IPsec compliant, see the Constraints section below) using DPDK based on RFC4301, 16RFC4303, RFC3602 and RFC2404. 17 18Internet Key Exchange (IKE) is not implemented, so only manual setting of 19Security Policies and Security Associations is supported. 20 21The Security Policies (SP) are implemented as ACL rules, the Security 22Associations (SA) are stored in a table and the routing is implemented 23using LPM. 24 25The application classifies the ports as *Protected* and *Unprotected*. 26Thus, traffic received on an Unprotected or Protected port is consider 27Inbound or Outbound respectively. 28 29The application also supports complete IPsec protocol offload to hardware 30(Look aside crypto accelerator or using ethernet device). It also support 31inline ipsec processing by the supported ethernet device during transmission. 32These modes can be selected during the SA creation configuration. 33 34In case of complete protocol offload, the processing of headers(ESP and outer 35IP header) is done by the hardware and the application does not need to 36add/remove them during outbound/inbound processing. 37 38For inline offloaded outbound traffic, the application will not do the LPM 39lookup for routing, as the port on which the packet has to be forwarded will be 40part of the SA. Security parameters will be configured on that port only, and 41sending the packet on other ports could result in unencrypted packets being 42sent out. 43 44The Path for IPsec Inbound traffic is: 45 46* Read packets from the port. 47* Classify packets between IPv4 and ESP. 48* Perform Inbound SA lookup for ESP packets based on their SPI. 49* Perform Verification/Decryption (Not needed in case of inline ipsec). 50* Remove ESP and outer IP header (Not needed in case of protocol offload). 51* Inbound SP check using ACL of decrypted packets and any other IPv4 packets. 52* Routing. 53* Write packet to port. 54 55The Path for the IPsec Outbound traffic is: 56 57* Read packets from the port. 58* Perform Outbound SP check using ACL of all IPv4 traffic. 59* Perform Outbound SA lookup for packets that need IPsec protection. 60* Add ESP and outer IP header (Not needed in case protocol offload). 61* Perform Encryption/Digest (Not needed in case of inline ipsec). 62* Routing. 63* Write packet to port. 64 65The application supports two modes of operation: poll mode and event mode. 66 67* In the poll mode a core receives packets from statically configured list 68 of eth ports and eth ports' queues. 69 70* In the event mode a core receives packets as events. After packet processing 71 is done core submits them back as events to an event device. This enables 72 multicore scaling and HW assisted scheduling by making use of the event device 73 capabilities. The event mode configuration is predefined. All packets reaching 74 given eth port will arrive at the same event queue. All event queues are mapped 75 to all event ports. This allows all cores to receive traffic from all ports. 76 Since the underlying event device might have varying capabilities, the worker 77 threads can be drafted differently to maximize performance. For example, if an 78 event device - eth device pair has Tx internal port, then application can call 79 rte_event_eth_tx_adapter_enqueue() instead of regular rte_event_enqueue_burst(). 80 So a thread which assumes that the device pair has internal port will not be the 81 right solution for another pair. The infrastructure added for the event mode aims 82 to help application to have multiple worker threads by maximizing performance from 83 every type of event device without affecting existing paths/use cases. The worker 84 to be used will be determined by the operating conditions and the underlying device 85 capabilities. 86 **Currently the application provides non-burst, internal port worker threads.** 87 It also provides infrastructure for non-internal port 88 however does not define any worker threads. 89 90 Event mode also supports event vectorization. The event devices, ethernet device 91 pairs which support the capability ``RTE_EVENT_ETH_RX_ADAPTER_CAP_EVENT_VECTOR`` can 92 aggregate packets based on flow characteristics and generate a ``rte_event`` 93 containing ``rte_event_vector``. 94 The aggregation size and timeout can be given using command line options vector-size 95 (default vector-size is 16) and vector-tmo (default vector-tmo is 102400ns). 96 By default event vectorization is disabled and it can be enabled using event-vector 97 option. 98 For the event devices, crypto device pairs which support the capability 99 ``RTE_EVENT_CRYPTO_ADAPTER_CAP_EVENT_VECTOR`` vector aggregation 100 could also be enable using event-vector option. 101 102Additionally the event mode introduces two submodes of processing packets: 103 104* Driver submode: This submode has bare minimum changes in the application to support 105 IPsec. There are no lookups, no routing done in the application. And for inline 106 protocol use case, the worker thread resembles l2fwd worker thread as the IPsec 107 processing is done entirely in HW. This mode can be used to benchmark the raw 108 performance of the HW. The driver submode is selected with --single-sa option 109 (used also by poll mode). When --single-sa option is used in conjunction with event 110 mode then index passed to --single-sa is ignored. 111 112* App submode: This submode has all the features currently implemented with the 113 application (non librte_ipsec path). All the lookups, routing follows existing 114 methods and report numbers that can be compared against regular poll mode 115 benchmark numbers. 116 117Constraints 118----------- 119 120* No IPv6 options headers. 121* No AH mode. 122* Supported algorithms: AES-CBC, AES-CTR, AES-GCM, 3DES-CBC, DES-CBC, 123 HMAC-SHA1, HMAC-SHA256, AES-GMAC, AES_CTR, AES_XCBC_MAC, AES_CCM, 124 CHACHA20_POLY1305 and NULL. 125* Each SA must be handle by a unique lcore (*1 RX queue per port*). 126 127Compiling the Application 128------------------------- 129 130To compile the sample application see :doc:`compiling`. 131 132The application is located in the ``ipsec-secgw`` sub-directory. 133 134 135Running the Application 136----------------------- 137 138The application has a number of command line options:: 139 140 141 ./<build_dir>/examples/dpdk-ipsec-secgw [EAL options] -- 142 -p PORTMASK -P -u PORTMASK -j FRAMESIZE 143 -l -w REPLAY_WINDOW_SIZE -e -a 144 -c SAD_CACHE_SIZE 145 -t STATISTICS_INTERVAL 146 -s NUMBER_OF_MBUFS_IN_PACKET_POOL 147 -f CONFIG_FILE_PATH 148 --config (port,queue,lcore)[,(port,queue,lcore)] 149 --single-sa SAIDX 150 --cryptodev_mask MASK 151 --transfer-mode MODE 152 --event-schedule-type TYPE 153 --rxoffload MASK 154 --txoffload MASK 155 --reassemble NUM 156 --mtu MTU 157 --frag-ttl FRAG_TTL_NS 158 --desc-nb NUMBER_OF_DESC 159 160Where: 161 162* ``-p PORTMASK``: Hexadecimal bitmask of ports to configure. 163 164* ``-P``: *optional*. Sets all ports to promiscuous mode so that packets are 165 accepted regardless of the packet's Ethernet MAC destination address. 166 Without this option, only packets with the Ethernet MAC destination address 167 set to the Ethernet address of the port are accepted (default is enabled). 168 169* ``-u PORTMASK``: hexadecimal bitmask of unprotected ports 170 171* ``-j FRAMESIZE``: *optional*. data buffer size (in bytes), 172 in other words maximum data size for one segment. 173 Packets with length bigger then FRAMESIZE still can be received, 174 but will be segmented. 175 Default value: RTE_MBUF_DEFAULT_BUF_SIZE (2176) 176 Minimum value: RTE_MBUF_DEFAULT_BUF_SIZE (2176) 177 Maximum value: UINT16_MAX (65535). 178 179* ``-l``: enables code-path that uses librte_ipsec. 180 181* ``-w REPLAY_WINDOW_SIZE``: specifies the IPsec sequence number replay window 182 size for each Security Association (available only with librte_ipsec 183 code path). 184 185* ``-e``: enables Security Association extended sequence number processing 186 (available only with librte_ipsec code path). 187 188* ``-a``: enables Security Association sequence number atomic behavior 189 (available only with librte_ipsec code path). 190 191* ``-c``: specifies the SAD cache size. Stores the most recent SA in a per 192 lcore cache. Cache represents flat array containing SA's indexed by SPI. 193 Zero value disables cache. 194 Default value: 128. 195 196* ``-t``: specifies the statistics screen update interval in seconds. If set 197 to zero or omitted statistics screen is disabled. 198 Default value: 0. 199 200* ``-s``: sets number of mbufs in packet pool, if not provided number of mbufs 201 will be calculated based on number of cores, eth ports and crypto queues. 202 203* ``-f CONFIG_FILE_PATH``: the full path of text-based file containing all 204 configuration items for running the application (See Configuration file 205 syntax section below). ``-f CONFIG_FILE_PATH`` **must** be specified. 206 **ONLY** the UNIX format configuration file is accepted. 207 208* ``--config (port,queue,lcore)[,(port,queue,lcore)]``: in poll mode determines 209 which queues from which ports are mapped to which cores. In event mode this 210 option is not used as packets are dynamically scheduled to cores by HW. 211 212* ``--single-sa SAIDX``: in poll mode use a single SA for outbound traffic, 213 bypassing the SP on both Inbound and Outbound. This option is meant for 214 debugging/performance purposes. In event mode selects driver submode, SA index 215 value is ignored. 216 217* ``--cryptodev_mask MASK``: hexadecimal bitmask of the crypto devices 218 to configure. 219 220* ``--transfer-mode MODE``: sets operating mode of the application 221 "poll" : packet transfer via polling (default) 222 "event" : Packet transfer via event device 223 224* ``--event-schedule-type TYPE``: queue schedule type, applies only when 225 --transfer-mode is set to event. 226 "ordered" : Ordered (default) 227 "atomic" : Atomic 228 "parallel" : Parallel 229 When --event-schedule-type is set as RTE_SCHED_TYPE_ORDERED/ATOMIC, event 230 device will ensure the ordering. Ordering will be lost when tried in PARALLEL. 231 232* ``--rxoffload MASK``: RX HW offload capabilities to enable/use on this port 233 (bitmask of RTE_ETH_RX_OFFLOAD_* values). It is an optional parameter and 234 allows user to disable some of the RX HW offload capabilities. 235 By default all HW RX offloads are enabled. 236 237* ``--txoffload MASK``: TX HW offload capabilities to enable/use on this port 238 (bitmask of RTE_ETH_TX_OFFLOAD_* values). It is an optional parameter and 239 allows user to disable some of the TX HW offload capabilities. 240 By default all HW TX offloads are enabled. 241 242* ``--reassemble NUM``: max number of entries in reassemble fragment table. 243 Zero value disables reassembly functionality. 244 Default value: 0. 245 246* ``--mtu MTU``: MTU value (in bytes) on all attached ethernet ports. 247 Outgoing packets with length bigger then MTU will be fragmented. 248 Incoming packets with length bigger then MTU will be discarded. 249 Default value: 1500. 250 251* ``--frag-ttl FRAG_TTL_NS``: fragment lifetime (in nanoseconds). 252 If packet is not reassembled within this time, received fragments 253 will be discarded. Fragment lifetime should be decreased when 254 there is a high fragmented traffic loss in high bandwidth networks. 255 Should be lower for low number of reassembly buckets. 256 Valid values: from 1 ns to 10 s. Default value: 10000000 (10 s). 257 258* ``--per-port-pool``: Enable per ethdev port pktmbuf pool. 259 By default one packet mbuf pool per socket is created and configured 260 via Rx queue setup. 261 262* ``--vector-pool-sz``: Number of buffers in vector pool. 263 By default, vector pool size depeneds on packet pool size 264 and size of each vector. 265 266* ``--desc-nb NUMBER_OF_DESC``: Number of descriptors per queue pair. 267 Default value: 2048. 268 269The mapping of lcores to port/queues is similar to other l3fwd applications. 270 271For example, given the following command line to run application in poll mode:: 272 273 ./<build_dir>/examples/dpdk-ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048 \ 274 --vdev "crypto_null" -- -p 0xf -P -u 0x3 \ 275 --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)" \ 276 -f /path/to/config_file --transfer-mode poll \ 277 278where each option means: 279 280* The ``-l`` option enables cores 20 and 21. 281 282* The ``-n`` option sets memory 4 channels. 283 284* The ``--socket-mem`` to use 2GB on socket 1. 285 286* The ``--vdev "crypto_null"`` option creates virtual NULL cryptodev PMD. 287 288* The ``-p`` option enables ports (detected) 0, 1, 2 and 3. 289 290* The ``-P`` option enables promiscuous mode. 291 292* The ``-u`` option sets ports 0 and 1 as unprotected, leaving 2 and 3 as protected. 293 294* The ``--config`` option enables one queue per port with the following mapping: 295 296 +----------+-----------+-----------+---------------------------------------+ 297 | **Port** | **Queue** | **lcore** | **Description** | 298 | | | | | 299 +----------+-----------+-----------+---------------------------------------+ 300 | 0 | 0 | 20 | Map queue 0 from port 0 to lcore 20. | 301 | | | | | 302 +----------+-----------+-----------+---------------------------------------+ 303 | 1 | 0 | 20 | Map queue 0 from port 1 to lcore 20. | 304 | | | | | 305 +----------+-----------+-----------+---------------------------------------+ 306 | 2 | 0 | 21 | Map queue 0 from port 2 to lcore 21. | 307 | | | | | 308 +----------+-----------+-----------+---------------------------------------+ 309 | 3 | 0 | 21 | Map queue 0 from port 3 to lcore 21. | 310 | | | | | 311 +----------+-----------+-----------+---------------------------------------+ 312 313* The ``-f /path/to/config_file`` option enables the application read and 314 parse the configuration file specified, and configures the application 315 with a given set of SP, SA and Routing entries accordingly. The syntax of 316 the configuration file will be explained below in more detail. Please 317 **note** the parser only accepts UNIX format text file. Other formats 318 such as DOS/MAC format will cause a parse error. 319 320* The ``--transfer-mode`` option selects poll mode for processing packets. 321 322Similarly for example, given the following command line to run application in 323event app mode:: 324 325 ./<build_dir>/examples/dpdk-ipsec-secgw -c 0x3 -- -P -p 0x3 -u 0x1 \ 326 -f /path/to/config_file --transfer-mode event \ 327 --event-schedule-type parallel --event-vector --vector-size 32 \ 328 --vector-tmo 102400 \ 329 330where each option means: 331 332* The ``-c`` option selects cores 0 and 1 to run on. 333 334* The ``-P`` option enables promiscuous mode. 335 336* The ``-p`` option enables ports (detected) 0 and 1. 337 338* The ``-u`` option sets ports 0 as unprotected, leaving 1 as protected. 339 340* The ``-f /path/to/config_file`` option has the same behavior as in poll 341 mode example. 342 343* The ``--transfer-mode`` option selects event mode for processing packets. 344 345* The ``--event-schedule-type`` option selects parallel ordering of event queues. 346 347* The ``--event-vector`` option enables event vectorization. 348 349* The ``--vector-size`` option specifies max vector size. 350 351* The ``--vector-tmo`` option specifies max timeout in nanoseconds for vectorization. 352 353 354Refer to the *DPDK Getting Started Guide* for general information on running 355applications and the Environment Abstraction Layer (EAL) options. 356 357The application would do a best effort to "map" crypto devices to cores, with 358hardware devices having priority. Basically, hardware devices if present would 359be assigned to a core before software ones. 360This means that if the application is using a single core and both hardware 361and software crypto devices are detected, hardware devices will be used. 362 363A way to achieve the case where you want to force the use of virtual crypto 364devices is to only use the Ethernet devices needed (via the allow flag) 365and therefore implicitly blocking all hardware crypto devices. 366 367For example, something like the following command line: 368 369.. code-block:: console 370 371 ./<build_dir>/examples/dpdk-ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048 \ 372 -a 81:00.0 -a 81:00.1 -a 81:00.2 -a 81:00.3 \ 373 --vdev "crypto_aesni_mb" --vdev "crypto_null" \ 374 -- \ 375 -p 0xf -P -u 0x3 --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)" \ 376 -f sample.cfg 377 378 379Configurations 380-------------- 381 382The following sections provide the syntax of configurations to initialize 383your SP, SA, Routing, Flow and Neighbour tables. 384Configurations shall be specified in the configuration file to be passed to 385the application. The file is then parsed by the application. The successful 386parsing will result in the appropriate rules being applied to the tables 387accordingly. 388 389 390Configuration File Syntax 391~~~~~~~~~~~~~~~~~~~~~~~~~ 392 393As mention in the overview, the Security Policies are ACL rules. 394The application parsers the rules specified in the configuration file and 395passes them to the ACL table, and replicates them per socket in use. 396 397Following are the configuration file syntax. 398 399General rule syntax 400^^^^^^^^^^^^^^^^^^^ 401 402The parse treats one line in the configuration file as one configuration 403item (unless the line concatenation symbol exists). Every configuration 404item shall follow the syntax of either SP, SA, Routing, Flow or Neighbour 405rules specified below. 406 407The configuration parser supports the following special symbols: 408 409 * Comment symbol **#**. Any character from this symbol to the end of 410 line is treated as comment and will not be parsed. 411 412 * Line concatenation symbol **\\**. This symbol shall be placed in the end 413 of the line to be concatenated to the line below. Multiple lines' 414 concatenation is supported. 415 416 417SP rule syntax 418^^^^^^^^^^^^^^ 419 420The SP rule syntax is shown as follows: 421 422.. code-block:: console 423 424 sp <ip_ver> <dir> esp <action> <priority> <src_ip> <dst_ip> 425 <proto> <sport> <dport> 426 427 428where each options means: 429 430``<ip_ver>`` 431 432 * IP protocol version 433 434 * Optional: No 435 436 * Available options: 437 438 * *ipv4*: IP protocol version 4 439 * *ipv6*: IP protocol version 6 440 441``<dir>`` 442 443 * The traffic direction 444 445 * Optional: No 446 447 * Available options: 448 449 * *in*: inbound traffic 450 * *out*: outbound traffic 451 452``<action>`` 453 454 * IPsec action 455 456 * Optional: No 457 458 * Available options: 459 460 * *protect <SA_idx>*: the specified traffic is protected by SA rule 461 with id SA_idx 462 * *bypass*: the specified traffic is bypassed 463 * *discard*: the specified traffic is discarded 464 465``<priority>`` 466 467 * Rule priority 468 469 * Optional: Yes, default priority 0 will be used 470 471 * Syntax: *pri <id>* 472 473``<src_ip>`` 474 475 * The source IP address and mask 476 477 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used 478 479 * Syntax: 480 481 * *src X.X.X.X/Y* for IPv4 482 * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6 483 484``<dst_ip>`` 485 486 * The destination IP address and mask 487 488 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used 489 490 * Syntax: 491 492 * *dst X.X.X.X/Y* for IPv4 493 * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6 494 495``<proto>`` 496 497 * The protocol start and end range 498 499 * Optional: yes, default range of 0 to 0 will be used 500 501 * Syntax: *proto X:Y* 502 503``<sport>`` 504 505 * The source port start and end range 506 507 * Optional: yes, default range of 0 to 0 will be used 508 509 * Syntax: *sport X:Y* 510 511``<dport>`` 512 513 * The destination port start and end range 514 515 * Optional: yes, default range of 0 to 0 will be used 516 517 * Syntax: *dport X:Y* 518 519Example SP rules: 520 521.. code-block:: console 522 523 sp ipv4 out esp protect 105 pri 1 dst 192.168.115.0/24 sport 0:65535 \ 524 dport 0:65535 525 526 sp ipv6 in esp bypass pri 1 dst 0000:0000:0000:0000:5555:5555:\ 527 0000:0000/96 sport 0:65535 dport 0:65535 528 529 530SA rule syntax 531^^^^^^^^^^^^^^ 532 533The successfully parsed SA rules will be stored in an array table. 534 535The SA rule syntax is shown as follows: 536 537.. code-block:: console 538 539 sa <dir> <spi> <cipher_algo> <cipher_key> <auth_algo> <auth_key> 540 <mode> <src_ip> <dst_ip> <action_type> <port_id> <fallback> 541 <flow-direction> <port_id> <queue_id> <udp-encap> <reassembly_en> 542 543where each options means: 544 545``<dir>`` 546 547 * The traffic direction 548 549 * Optional: No 550 551 * Available options: 552 553 * *in*: inbound traffic 554 * *out*: outbound traffic 555 556``<spi>`` 557 558 * The SPI number 559 560 * Optional: No 561 562 * Syntax: unsigned integer number 563 564``<cipher_algo>`` 565 566 * Cipher algorithm 567 568 * Optional: Yes, unless <aead_algo> is not used 569 570 * Available options: 571 572 * *null*: NULL algorithm 573 * *aes-128-cbc*: AES-CBC 128-bit algorithm 574 * *aes-192-cbc*: AES-CBC 192-bit algorithm 575 * *aes-256-cbc*: AES-CBC 256-bit algorithm 576 * *aes-128-ctr*: AES-CTR 128-bit algorithm 577 * *3des-cbc*: 3DES-CBC 192-bit algorithm 578 * *des-cbc*: DES-CBC 64-bit algorithm 579 580 * Syntax: *cipher_algo <your algorithm>* 581 582``<cipher_key>`` 583 584 * Cipher key, NOT available when 'null' algorithm is used 585 586 * Optional: Yes, unless <aead_algo> is not used. 587 Must be followed by <cipher_algo> option 588 589 * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'. 590 The number of bytes should be as same as the specified cipher algorithm 591 key size. 592 593 For example: *cipher_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4: 594 A1:B2:C3:D4* 595 596``<auth_algo>`` 597 598 * Authentication algorithm 599 600 * Optional: Yes, unless <aead_algo> is not used 601 602 * Available options: 603 604 * *null*: NULL algorithm 605 * *sha1-hmac*: HMAC SHA1 algorithm 606 * *sha256-hmac*: HMAC SHA256 algorithm 607 * *aes-xcbc-mac*: AES XCBC MAC algorithm 608 609``<auth_key>`` 610 611 * Authentication key, NOT available when 'null' or 'aes-128-gcm' algorithm 612 is used. 613 614 * Optional: Yes, unless <aead_algo> is not used. 615 Must be followed by <auth_algo> option 616 617 * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'. 618 The number of bytes should be as same as the specified authentication 619 algorithm key size. 620 621 For example: *auth_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4: 622 A1:B2:C3:D4* 623 624``<aead_algo>`` 625 626 * AEAD algorithm 627 628 * Optional: Yes, unless <cipher_algo> and <auth_algo> are not used 629 630 * Available options: 631 632 * *aes-128-gcm*: AES-GCM 128-bit algorithm 633 * *aes-192-gcm*: AES-GCM 192-bit algorithm 634 * *aes-256-gcm*: AES-GCM 256-bit algorithm 635 636 * Syntax: *cipher_algo <your algorithm>* 637 638``<aead_key>`` 639 640 * Cipher key, NOT available when 'null' algorithm is used 641 642 * Optional: Yes, unless <cipher_algo> and <auth_algo> are not used. 643 Must be followed by <aead_algo> option 644 645 * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'. 646 Last 4 bytes of the provided key will be used as 'salt' and so, the 647 number of bytes should be same as the sum of specified AEAD algorithm 648 key size and salt size (4 bytes). 649 650 For example: *aead_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4: 651 A1:B2:C3:D4:A1:B2:C3:D4* 652 653``<mode>`` 654 655 * The operation mode 656 657 * Optional: No 658 659 * Available options: 660 661 * *ipv4-tunnel*: Tunnel mode for IPv4 packets 662 * *ipv6-tunnel*: Tunnel mode for IPv6 packets 663 * *transport*: transport mode 664 665 * Syntax: mode XXX 666 667``<src_ip>`` 668 669 * The source IP address. This option is not available when 670 transport mode is used 671 672 * Optional: Yes, default address 0.0.0.0 will be used 673 674 * Syntax: 675 676 * *src X.X.X.X* for IPv4 677 * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX* for IPv6 678 679``<dst_ip>`` 680 681 * The destination IP address. This option is not available when 682 transport mode is used 683 684 * Optional: Yes, default address 0.0.0.0 will be used 685 686 * Syntax: 687 688 * *dst X.X.X.X* for IPv4 689 * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX* for IPv6 690 691``<type>`` 692 693 * Action type to specify the security action. This option specify 694 the SA to be performed with look aside protocol offload to HW 695 accelerator or protocol offload on ethernet device or inline 696 crypto processing on the ethernet device during transmission. 697 698 * Optional: Yes, default type *no-offload* 699 700 * Available options: 701 702 * *lookaside-protocol-offload*: look aside protocol offload to HW accelerator 703 * *inline-protocol-offload*: inline protocol offload on ethernet device 704 * *inline-crypto-offload*: inline crypto processing on ethernet device 705 * *no-offload*: no offloading to hardware 706 707 ``<port_id>`` 708 709 * Port/device ID of the ethernet/crypto accelerator for which the SA is 710 configured. For *inline-crypto-offload* and *inline-protocol-offload*, this 711 port will be used for routing. The routing table will not be referred in 712 this case. 713 714 * Optional: No, if *type* is not *no-offload* 715 716 * Syntax: 717 718 * *port_id X* X is a valid device number in decimal 719 720 ``<fallback>`` 721 722 * Action type for ingress IPsec packets that inline processor failed to 723 process. Only a combination of *inline-crypto-offload* as a primary 724 session and *lookaside-none* as a fall-back session is supported at the 725 moment. 726 727 If used in conjunction with IPsec window, its width needs be increased 728 due to different processing times of inline and lookaside modes which 729 results in packet reordering. 730 731 * Optional: Yes. 732 733 * Available options: 734 735 * *lookaside-none*: use automatically chosen cryptodev to process packets 736 737 * Syntax: 738 739 * *fallback lookaside-none* 740 741``<flow-direction>`` 742 743 * Option for redirecting a specific inbound ipsec flow of a port to a specific 744 queue of that port. 745 746 * Optional: Yes. 747 748 * Available options: 749 750 * *port_id*: Port ID of the NIC for which the SA is configured. 751 * *queue_id*: Queue ID to which traffic should be redirected. 752 753 ``<udp-encap>`` 754 755 * Option to enable IPsec UDP encapsulation for NAT Traversal. 756 Only *lookaside-protocol-offload* and *inline-crypto-offload* modes are 757 supported at the moment. 758 759 * Optional: Yes, it is disabled by default 760 761 * Syntax: 762 763 * *udp-encap* 764 765 ``<mss>`` 766 767 * Maximum segment size for TSO offload, available for egress SAs only. 768 769 * Optional: Yes, TSO offload not set by default 770 771 * Syntax: 772 773 * *mss N* N is the segment size in bytes 774 775 776``<telemetry>`` 777 778 * Option to enable per SA telemetry. 779 Currently only supported with IPsec library path. 780 781 * Optional: Yes, it is disabled by default 782 783 * Syntax: 784 785 * *telemetry* 786 787 ``<esn>`` 788 789 * Enable ESN and set the initial ESN value. 790 791 * Optional: Yes, ESN not enabled by default 792 793 * Syntax: 794 795 * *esn N* N is the initial ESN value 796 797 ``<reassembly_en>`` 798 799 * Option to enable HW reassembly per SA. 800 801 * Optional: Yes, it is disabled by default 802 803 * Syntax: 804 805 * *reassembly_en* 806 807Example SA rules: 808 809.. code-block:: console 810 811 sa out 5 cipher_algo null auth_algo null mode ipv4-tunnel \ 812 src 172.16.1.5 dst 172.16.2.5 813 814 sa out 25 cipher_algo aes-128-cbc \ 815 cipher_key c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3 \ 816 auth_algo sha1-hmac \ 817 auth_key c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3 \ 818 mode ipv6-tunnel \ 819 src 1111:1111:1111:1111:1111:1111:1111:5555 \ 820 dst 2222:2222:2222:2222:2222:2222:2222:5555 821 822 sa in 105 aead_algo aes-128-gcm \ 823 aead_key de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef \ 824 mode ipv4-tunnel src 172.16.2.5 dst 172.16.1.5 825 826 sa out 5 cipher_algo aes-128-cbc cipher_key 0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0 \ 827 auth_algo sha1-hmac auth_key 0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0 \ 828 mode ipv4-tunnel src 172.16.1.5 dst 172.16.2.5 \ 829 type lookaside-protocol-offload port_id 4 830 831 sa in 35 aead_algo aes-128-gcm \ 832 aead_key de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef \ 833 mode ipv4-tunnel src 172.16.2.5 dst 172.16.1.5 \ 834 type inline-crypto-offload port_id 0 835 836 sa in 117 cipher_algo null auth_algo null mode ipv4-tunnel src 172.16.2.7 \ 837 dst 172.16.1.7 flow-direction 0 2 838 839Routing rule syntax 840^^^^^^^^^^^^^^^^^^^ 841 842The Routing rule syntax is shown as follows: 843 844.. code-block:: console 845 846 rt <ip_ver> <src_ip> <dst_ip> <port> 847 848 849where each options means: 850 851``<ip_ver>`` 852 853 * IP protocol version 854 855 * Optional: No 856 857 * Available options: 858 859 * *ipv4*: IP protocol version 4 860 * *ipv6*: IP protocol version 6 861 862``<src_ip>`` 863 864 * The source IP address and mask 865 866 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used 867 868 * Syntax: 869 870 * *src X.X.X.X/Y* for IPv4 871 * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6 872 873``<dst_ip>`` 874 875 * The destination IP address and mask 876 877 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used 878 879 * Syntax: 880 881 * *dst X.X.X.X/Y* for IPv4 882 * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6 883 884``<port>`` 885 886 * The traffic output port id 887 888 * Optional: yes, default output port 0 will be used 889 890 * Syntax: *port X* 891 892Example SP rules: 893 894.. code-block:: console 895 896 rt ipv4 dst 172.16.1.5/32 port 0 897 898 rt ipv6 dst 1111:1111:1111:1111:1111:1111:1111:5555/116 port 0 899 900Flow rule syntax 901^^^^^^^^^^^^^^^^ 902 903Flow rule enables the usage of hardware classification capabilities to match specific 904ingress traffic and redirect the packets to the specified queue. This feature is 905optional and relies on hardware ``rte_flow`` support. 906 907The flow rule syntax is shown as follows: 908 909.. code-block:: console 910 911 flow <mark> <eth> <ip_ver> <src_ip> <dst_ip> <port> <queue> \ 912 <count> <security> <set_mark> 913 914where each options means: 915 916``<mark>`` 917 918 * Set RTE_FLOW_ITEM_TYPE_MARK pattern item in the flow rule with the given 919 mark value. This option can be used to match an arbitrary integer value 920 which was set using the RTE_FLOW_ACTION_TYPE_MARK action (see ``<set_mark>``) 921 in a previously matched rule. 922 923 * Optional: Yes, this pattern is not set by default. 924 925 * Syntax: *mark X* 926 927``<eth>`` 928 929 * Set RTE_FLOW_ITEM_TYPE_ETH pattern item. This matches all ethernet packets. 930 931 * Optional: Yes, this pattern is not set by default. 932 933 * Syntax: *eth* 934 935``<ip_ver>`` 936 937 * IP protocol version 938 939 * Optional: Yes, this pattern is not set by default. 940 941 * Available options: 942 943 * *ipv4*: IP protocol version 4 944 * *ipv6*: IP protocol version 6 945 946``<src_ip>`` 947 948 * The source IP address and mask 949 950 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used 951 952 * Syntax: 953 954 * *src X.X.X.X/Y* for IPv4 955 * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6 956 957``<dst_ip>`` 958 959 * The destination IP address and mask 960 961 * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used 962 963 * Syntax: 964 965 * *dst X.X.X.X/Y* for IPv4 966 * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6 967 968``<port>`` 969 970 * The traffic input port id 971 972 * Optional: yes, default input port 0 will be used 973 974 * Syntax: *port X* 975 976``<queue>`` 977 978 * The traffic input queue id 979 980 * Optional: yes, default input queue 0 will be used 981 982 * Syntax: *queue X* 983 984``<count>`` 985 986 * Set RTE_FLOW_ACTION_TYPE_COUNT action. 987 988 * Optional: yes, this action is not set by default. 989 990 * Syntax: *count* 991 992``<security>`` 993 994 * Set RTE_FLOW_ITEM_TYPE_ESP pattern and RTE_FLOW_ACTION_TYPE_SECURITY action. 995 996 * Optional: yes, this pattern and action are not set by default. 997 998 * Syntax: *security* 999 1000``<set_mark>`` 1001 1002 * Set RTE_FLOW_ACTION_TYPE_MARK action in the flow rule with the given mark 1003 value. This option can be used to set the given integer value(mark) to 1004 packets and set RTE_MBUF_F_RX_FDIR and RTE_MBUF_F_RX_FDIR_ID mbuf flags. 1005 1006 * Optional: yes, this action is not set by default. 1007 1008 * Syntax: *set_mark X* 1009 1010Example flow rules: 1011 1012.. code-block:: console 1013 1014 flow ipv4 dst 172.16.1.5/32 port 0 queue 0 1015 1016 flow ipv6 dst 1111:1111:1111:1111:1111:1111:1111:5555/116 port 1 queue 0 1017 1018 flow mark 123 ipv4 dst 192.168.0.0/16 port 0 queue 0 count 1019 1020 flow eth ipv4 dst 192.168.0.0/16 port 0 queue 0 count 1021 1022 flow ipv4 dst 192.168.0.0/16 port 0 queue 0 count 1023 1024 flow ipv4 dst 192.168.0.0/16 port 0 queue 0 1025 1026 flow port 0 security set_mark 123 1027 1028 flow ipv4 dst 1.1.0.0/16 port 0 count set_mark 123 security 1029 1030 1031Neighbour rule syntax 1032^^^^^^^^^^^^^^^^^^^^^ 1033 1034The Neighbour rule syntax is shown as follows: 1035 1036.. code-block:: console 1037 1038 neigh <port> <dst_mac> 1039 1040 1041where each options means: 1042 1043``<port>`` 1044 1045 * The output port id 1046 1047 * Optional: No 1048 1049 * Syntax: *port X* 1050 1051``<dst_mac>`` 1052 1053 * The destination ethernet address to use for that port 1054 1055 * Optional: No 1056 1057 * Syntax: 1058 1059 * XX:XX:XX:XX:XX:XX 1060 1061Example Neighbour rules: 1062 1063.. code-block:: console 1064 1065 neigh port 0 DE:AD:BE:EF:01:02 1066 1067Test directory 1068-------------- 1069 1070The test directory contains scripts for testing the various encryption 1071algorithms. 1072 1073The purpose of the scripts is to automate ipsec-secgw testing 1074using another system running linux as a DUT. 1075 1076The user must setup the following environment variables: 1077 1078* ``SGW_PATH``: path to the ipsec-secgw binary to test. 1079 1080* ``REMOTE_HOST``: IP address/hostname of the DUT. 1081 1082* ``REMOTE_IFACE``: interface name for the test-port on the DUT. 1083 1084* ``ETH_DEV``: ethernet device to be used on the SUT by DPDK ('-a <pci-id>') 1085 1086Also the user can optionally setup: 1087 1088* ``SGW_LCORE``: lcore to run ipsec-secgw on (default value is 0) 1089 1090* ``CRYPTO_DEV``: crypto device to be used ('-a <pci-id>'). If none specified 1091 appropriate vdevs will be created by the script 1092 1093Scripts can be used for multiple test scenarios. To check all available 1094options run: 1095 1096.. code-block:: console 1097 1098 /bin/bash run_test.sh -h 1099 1100Note that most of the tests require the appropriate crypto PMD/device to be 1101available. 1102 1103Server configuration 1104~~~~~~~~~~~~~~~~~~~~ 1105 1106Two servers are required for the tests, SUT and DUT. 1107 1108Make sure the user from the SUT can ssh to the DUT without entering the password. 1109To enable this feature keys must be setup on the DUT. 1110 1111``ssh-keygen`` will make a private & public key pair on the SUT. 1112 1113``ssh-copy-id`` <user name>@<target host name> on the SUT will copy the public 1114key to the DUT. It will ask for credentials so that it can upload the public key. 1115 1116The SUT and DUT are connected through at least 2 NIC ports. 1117 1118One NIC port is expected to be managed by linux on both machines and will be 1119used as a control path. 1120 1121The second NIC port (test-port) should be bound to DPDK on the SUT, and should 1122be managed by linux on the DUT. 1123 1124The script starts ``ipsec-secgw`` with 2 NIC devices: ``test-port`` and 1125``tap vdev``. 1126 1127It then configures the local tap interface and the remote interface and IPsec 1128policies in the following way: 1129 1130Traffic going over the test-port in both directions has to be protected by IPsec. 1131 1132Traffic going over the TAP port in both directions does not have to be protected. 1133 1134i.e: 1135 1136DUT OS(NIC1)--(IPsec)-->(NIC1)ipsec-secgw(TAP)--(plain)-->(TAP)SUT OS 1137 1138SUT OS(TAP)--(plain)-->(TAP)psec-secgw(NIC1)--(IPsec)-->(NIC1)DUT OS 1139 1140It then tries to perform some data transfer using the scheme described above. 1141 1142Usage 1143~~~~~ 1144 1145In the ipsec-secgw/test directory run 1146 1147/bin/bash run_test.sh <options> <ipsec_mode> 1148 1149Available options: 1150 1151* ``-4`` Perform tests with use of IPv4. One or both [-46] options needs to be 1152 selected. 1153 1154* ``-6`` Perform tests with use of IPv6. One or both [-46] options needs to be 1155 selected. 1156 1157* ``-m`` Add IPSec tunnel mixed IP version tests - outer IP version different 1158 than inner. Inner IP version will match selected option [-46]. 1159 1160* ``-i`` Run tests in inline mode. Regular tests will not be invoked. 1161 1162* ``-f`` Run tests for fallback mechanism. Regular tests will not be invoked. 1163 1164* ``-l`` Run tests in legacy mode only. It cannot be used with options [-fsc]. 1165 On default library mode is used. 1166 1167* ``-s`` Run all tests with reassembly support. On default only tests for 1168 fallback mechanism use reassembly support. 1169 1170* ``-c`` Run tests with use of cpu-crypto. For inline tests it will not be 1171 applied. On default lookaside-none is used. 1172 1173* ``-p`` Perform packet validation tests. Option [-46] is not required. 1174 1175* ``-h`` Show usage. 1176 1177If <ipsec_mode> is specified, only tests for that mode will be invoked. For the 1178list of available modes please refer to run_test.sh. 1179