examples/ipsec-secgw: support security offload
[dpdk.git] / doc / guides / sample_app_ug / ipsec_secgw.rst
1 ..  BSD LICENSE
2     Copyright(c) 2016-2017 Intel Corporation. All rights reserved.
3     All rights reserved.
4
5     Redistribution and use in source and binary forms, with or without
6     modification, are permitted provided that the following conditions
7     are met:
8
9     * Redistributions of source code must retain the above copyright
10     notice, this list of conditions and the following disclaimer.
11     * Redistributions in binary form must reproduce the above copyright
12     notice, this list of conditions and the following disclaimer in
13     the documentation and/or other materials provided with the
14     distribution.
15     * Neither the name of Intel Corporation nor the names of its
16     contributors may be used to endorse or promote products derived
17     from this software without specific prior written permission.
18
19     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22     A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23     OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24     SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25     LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29     OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 IPsec Security Gateway Sample Application
32 =========================================
33
34 The IPsec Security Gateway application is an example of a "real world"
35 application using DPDK cryptodev framework.
36
37 Overview
38 --------
39
40 The application demonstrates the implementation of a Security Gateway
41 (not IPsec compliant, see the Constraints section below) using DPDK based on RFC4301,
42 RFC4303, RFC3602 and RFC2404.
43
44 Internet Key Exchange (IKE) is not implemented, so only manual setting of
45 Security Policies and Security Associations is supported.
46
47 The Security Policies (SP) are implemented as ACL rules, the Security
48 Associations (SA) are stored in a table and the routing is implemented
49 using LPM.
50
51 The application classifies the ports as *Protected* and *Unprotected*.
52 Thus, traffic received on an Unprotected or Protected port is consider
53 Inbound or Outbound respectively.
54
55 The application also supports complete IPSec protocol offload to hardware
56 (Look aside crypto accelarator or using ethernet device). It also support
57 inline ipsec processing by the supported ethernet device during transmission.
58 These modes can be selected during the SA creation configuration.
59
60 In case of complete protocol offload, the processing of headers(ESP and outer
61 IP header) is done by the hardware and the application does not need to
62 add/remove them during outbound/inbound processing.
63
64 The Path for IPsec Inbound traffic is:
65
66 *  Read packets from the port.
67 *  Classify packets between IPv4 and ESP.
68 *  Perform Inbound SA lookup for ESP packets based on their SPI.
69 *  Perform Verification/Decryption (Not needed in case of inline ipsec).
70 *  Remove ESP and outer IP header (Not needed in case of protocol offload).
71 *  Inbound SP check using ACL of decrypted packets and any other IPv4 packets.
72 *  Routing.
73 *  Write packet to port.
74
75 The Path for the IPsec Outbound traffic is:
76
77 *  Read packets from the port.
78 *  Perform Outbound SP check using ACL of all IPv4 traffic.
79 *  Perform Outbound SA lookup for packets that need IPsec protection.
80 *  Add ESP and outer IP header (Not needed in case protocol offload).
81 *  Perform Encryption/Digest (Not needed in case of inline ipsec).
82 *  Routing.
83 *  Write packet to port.
84
85
86 Constraints
87 -----------
88
89 *  No IPv6 options headers.
90 *  No AH mode.
91 *  Supported algorithms: AES-CBC, AES-CTR, AES-GCM, HMAC-SHA1 and NULL.
92 *  Each SA must be handle by a unique lcore (*1 RX queue per port*).
93 *  No chained mbufs.
94
95
96 Compiling the Application
97 -------------------------
98
99 To compile the application:
100
101 #. Go to the sample application directory::
102
103       export RTE_SDK=/path/to/rte_sdk
104       cd ${RTE_SDK}/examples/ipsec-secgw
105
106 #. Set the target (a default target is used if not specified). For example::
107
108
109       export RTE_TARGET=x86_64-native-linuxapp-gcc
110
111    See the *DPDK Getting Started Guide* for possible RTE_TARGET values.
112
113 #. Build the application::
114
115        make
116
117 #. [Optional] Build the application for debugging:
118    This option adds some extra flags, disables compiler optimizations and
119    is verbose::
120
121        make DEBUG=1
122
123
124 Running the Application
125 -----------------------
126
127 The application has a number of command line options::
128
129
130    ./build/ipsec-secgw [EAL options] --
131                         -p PORTMASK -P -u PORTMASK -j FRAMESIZE
132                         --config (port,queue,lcore)[,(port,queue,lcore]
133                         --single-sa SAIDX
134                         -f CONFIG_FILE_PATH
135
136 Where:
137
138 *   ``-p PORTMASK``: Hexadecimal bitmask of ports to configure.
139
140 *   ``-P``: *optional*. Sets all ports to promiscuous mode so that packets are
141     accepted regardless of the packet's Ethernet MAC destination address.
142     Without this option, only packets with the Ethernet MAC destination address
143     set to the Ethernet address of the port are accepted (default is enabled).
144
145 *   ``-u PORTMASK``: hexadecimal bitmask of unprotected ports
146
147 *   ``-j FRAMESIZE``: *optional*. Enables jumbo frames with the maximum size
148     specified as FRAMESIZE. If an invalid value is provided as FRAMESIZE
149     then the default value 9000 is used.
150
151 *   ``--config (port,queue,lcore)[,(port,queue,lcore)]``: determines which queues
152     from which ports are mapped to which cores.
153
154 *   ``--single-sa SAIDX``: use a single SA for outbound traffic, bypassing the SP
155     on both Inbound and Outbound. This option is meant for debugging/performance
156     purposes.
157
158 *   ``-f CONFIG_FILE_PATH``: the full path of text-based file containing all
159     configuration items for running the application (See Configuration file
160     syntax section below). ``-f CONFIG_FILE_PATH`` **must** be specified.
161     **ONLY** the UNIX format configuration file is accepted.
162
163
164 The mapping of lcores to port/queues is similar to other l3fwd applications.
165
166 For example, given the following command line::
167
168     ./build/ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048       \
169            --vdev "crypto_null" -- -p 0xf -P -u 0x3      \
170            --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)"       \
171            -f /path/to/config_file                              \
172
173 where each options means:
174
175 *   The ``-l`` option enables cores 20 and 21.
176
177 *   The ``-n`` option sets memory 4 channels.
178
179 *   The ``--socket-mem`` to use 2GB on socket 1.
180
181 *   The ``--vdev "crypto_null"`` option creates virtual NULL cryptodev PMD.
182
183 *   The ``-p`` option enables ports (detected) 0, 1, 2 and 3.
184
185 *   The ``-P`` option enables promiscuous mode.
186
187 *   The ``-u`` option sets ports 1 and 2 as unprotected, leaving 2 and 3 as protected.
188
189 *   The ``--config`` option enables one queue per port with the following mapping:
190
191     +----------+-----------+-----------+---------------------------------------+
192     | **Port** | **Queue** | **lcore** | **Description**                       |
193     |          |           |           |                                       |
194     +----------+-----------+-----------+---------------------------------------+
195     | 0        | 0         | 20        | Map queue 0 from port 0 to lcore 20.  |
196     |          |           |           |                                       |
197     +----------+-----------+-----------+---------------------------------------+
198     | 1        | 0         | 20        | Map queue 0 from port 1 to lcore 20.  |
199     |          |           |           |                                       |
200     +----------+-----------+-----------+---------------------------------------+
201     | 2        | 0         | 21        | Map queue 0 from port 2 to lcore 21.  |
202     |          |           |           |                                       |
203     +----------+-----------+-----------+---------------------------------------+
204     | 3        | 0         | 21        | Map queue 0 from port 3 to lcore 21.  |
205     |          |           |           |                                       |
206     +----------+-----------+-----------+---------------------------------------+
207
208 *   The ``-f /path/to/config_file`` option enables the application read and
209     parse the configuration file specified, and configures the application
210     with a given set of SP, SA and Routing entries accordingly. The syntax of
211     the configuration file will be explained below in more detail. Please
212     **note** the parser only accepts UNIX format text file. Other formats
213     such as DOS/MAC format will cause a parse error.
214
215 Refer to the *DPDK Getting Started Guide* for general information on running
216 applications and the Environment Abstraction Layer (EAL) options.
217
218 The application would do a best effort to "map" crypto devices to cores, with
219 hardware devices having priority. Basically, hardware devices if present would
220 be assigned to a core before software ones.
221 This means that if the application is using a single core and both hardware
222 and software crypto devices are detected, hardware devices will be used.
223
224 A way to achieve the case where you want to force the use of virtual crypto
225 devices is to whitelist the Ethernet devices needed and therefore implicitly
226 blacklisting all hardware crypto devices.
227
228 For example, something like the following command line:
229
230 .. code-block:: console
231
232     ./build/ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048 \
233             -w 81:00.0 -w 81:00.1 -w 81:00.2 -w 81:00.3 \
234             --vdev "crypto_aesni_mb" --vdev "crypto_null" \
235             -- \
236             -p 0xf -P -u 0x3 --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)" \
237             -f sample.cfg
238
239
240 Configurations
241 --------------
242
243 The following sections provide the syntax of configurations to initialize
244 your SP, SA and Routing tables.
245 Configurations shall be specified in the configuration file to be passed to
246 the application. The file is then parsed by the application. The successful
247 parsing will result in the appropriate rules being applied to the tables
248 accordingly.
249
250
251 Configuration File Syntax
252 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
253
254 As mention in the overview, the Security Policies are ACL rules.
255 The application parsers the rules specified in the configuration file and
256 passes them to the ACL table, and replicates them per socket in use.
257
258 Following are the configuration file syntax.
259
260 General rule syntax
261 ^^^^^^^^^^^^^^^^^^^
262
263 The parse treats one line in the configuration file as one configuration
264 item (unless the line concatenation symbol exists). Every configuration
265 item shall follow the syntax of either SP, SA, or Routing rules specified
266 below.
267
268 The configuration parser supports the following special symbols:
269
270  * Comment symbol **#**. Any character from this symbol to the end of
271    line is treated as comment and will not be parsed.
272
273  * Line concatenation symbol **\\**. This symbol shall be placed in the end
274    of the line to be concatenated to the line below. Multiple lines'
275    concatenation is supported.
276
277
278 SP rule syntax
279 ^^^^^^^^^^^^^^
280
281 The SP rule syntax is shown as follows:
282
283 .. code-block:: console
284
285     sp <ip_ver> <dir> esp <action> <priority> <src_ip> <dst_ip>
286     <proto> <sport> <dport>
287
288
289 where each options means:
290
291 ``<ip_ver>``
292
293  * IP protocol version
294
295  * Optional: No
296
297  * Available options:
298
299    * *ipv4*: IP protocol version 4
300    * *ipv6*: IP protocol version 6
301
302 ``<dir>``
303
304  * The traffic direction
305
306  * Optional: No
307
308  * Available options:
309
310    * *in*: inbound traffic
311    * *out*: outbound traffic
312
313 ``<action>``
314
315  * IPsec action
316
317  * Optional: No
318
319  * Available options:
320
321    * *protect <SA_idx>*: the specified traffic is protected by SA rule
322      with id SA_idx
323    * *bypass*: the specified traffic traffic is bypassed
324    * *discard*: the specified traffic is discarded
325
326 ``<priority>``
327
328  * Rule priority
329
330  * Optional: Yes, default priority 0 will be used
331
332  * Syntax: *pri <id>*
333
334 ``<src_ip>``
335
336  * The source IP address and mask
337
338  * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
339
340  * Syntax:
341
342    * *src X.X.X.X/Y* for IPv4
343    * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
344
345 ``<dst_ip>``
346
347  * The destination IP address and mask
348
349  * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
350
351  * Syntax:
352
353    * *dst X.X.X.X/Y* for IPv4
354    * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
355
356 ``<proto>``
357
358  * The protocol start and end range
359
360  * Optional: yes, default range of 0 to 0 will be used
361
362  * Syntax: *proto X:Y*
363
364 ``<sport>``
365
366  * The source port start and end range
367
368  * Optional: yes, default range of 0 to 0 will be used
369
370  * Syntax: *sport X:Y*
371
372 ``<dport>``
373
374  * The destination port start and end range
375
376  * Optional: yes, default range of 0 to 0 will be used
377
378  * Syntax: *dport X:Y*
379
380 Example SP rules:
381
382 .. code-block:: console
383
384     sp ipv4 out esp protect 105 pri 1 dst 192.168.115.0/24 sport 0:65535 \
385     dport 0:65535
386
387     sp ipv6 in esp bypass pri 1 dst 0000:0000:0000:0000:5555:5555:\
388     0000:0000/96 sport 0:65535 dport 0:65535
389
390
391 SA rule syntax
392 ^^^^^^^^^^^^^^
393
394 The successfully parsed SA rules will be stored in an array table.
395
396 The SA rule syntax is shown as follows:
397
398 .. code-block:: console
399
400     sa <dir> <spi> <cipher_algo> <cipher_key> <auth_algo> <auth_key>
401     <mode> <src_ip> <dst_ip> <action_type> <port_id>
402
403 where each options means:
404
405 ``<dir>``
406
407  * The traffic direction
408
409  * Optional: No
410
411  * Available options:
412
413    * *in*: inbound traffic
414    * *out*: outbound traffic
415
416 ``<spi>``
417
418  * The SPI number
419
420  * Optional: No
421
422  * Syntax: unsigned integer number
423
424 ``<cipher_algo>``
425
426  * Cipher algorithm
427
428  * Optional: Yes, unless <aead_algo> is not used
429
430  * Available options:
431
432    * *null*: NULL algorithm
433    * *aes-128-cbc*: AES-CBC 128-bit algorithm
434    * *aes-128-ctr*: AES-CTR 128-bit algorithm
435
436  * Syntax: *cipher_algo <your algorithm>*
437
438 ``<cipher_key>``
439
440  * Cipher key, NOT available when 'null' algorithm is used
441
442  * Optional: Yes, unless <aead_algo> is not used.
443    Must be followed by <cipher_algo> option
444
445  * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'.
446    The number of bytes should be as same as the specified cipher algorithm
447    key size.
448
449    For example: *cipher_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:
450    A1:B2:C3:D4*
451
452 ``<auth_algo>``
453
454  * Authentication algorithm
455
456  * Optional: Yes, unless <aead_algo> is not used
457
458  * Available options:
459
460     * *null*: NULL algorithm
461     * *sha1-hmac*: HMAC SHA1 algorithm
462
463 ``<auth_key>``
464
465  * Authentication key, NOT available when 'null' or 'aes-128-gcm' algorithm
466    is used.
467
468  * Optional: Yes, unless <aead_algo> is not used.
469    Must be followed by <auth_algo> option
470
471  * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'.
472    The number of bytes should be as same as the specified authentication
473    algorithm key size.
474
475    For example: *auth_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:
476    A1:B2:C3:D4*
477
478 ``<aead_algo>``
479
480  * AEAD algorithm
481
482  * Optional: Yes, unless <cipher_algo> and <auth_algo> are not used
483
484  * Available options:
485
486    * *aes-128-gcm*: AES-GCM 128-bit algorithm
487
488  * Syntax: *cipher_algo <your algorithm>*
489
490 ``<aead_key>``
491
492  * Cipher key, NOT available when 'null' algorithm is used
493
494  * Optional: Yes, unless <cipher_algo> and <auth_algo> are not used.
495    Must be followed by <aead_algo> option
496
497  * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'.
498    The number of bytes should be as same as the specified AEAD algorithm
499    key size.
500
501    For example: *aead_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:
502    A1:B2:C3:D4*
503
504 ``<mode>``
505
506  * The operation mode
507
508  * Optional: No
509
510  * Available options:
511
512    * *ipv4-tunnel*: Tunnel mode for IPv4 packets
513    * *ipv6-tunnel*: Tunnel mode for IPv6 packets
514    * *transport*: transport mode
515
516  * Syntax: mode XXX
517
518 ``<src_ip>``
519
520  * The source IP address. This option is not available when
521    transport mode is used
522
523  * Optional: Yes, default address 0.0.0.0 will be used
524
525  * Syntax:
526
527    * *src X.X.X.X* for IPv4
528    * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX* for IPv6
529
530 ``<dst_ip>``
531
532  * The destination IP address. This option is not available when
533    transport mode is used
534
535  * Optional: Yes, default address 0.0.0.0 will be used
536
537  * Syntax:
538
539    * *dst X.X.X.X* for IPv4
540    * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX* for IPv6
541
542 ``<type>``
543
544  * Action type to specify the security action. This option specify
545    the SA to be performed with look aside protocol offload to HW
546    accelerator or protocol offload on ethernet device or inline
547    crypto processing on the ethernet device during transmission.
548
549  * Optional: Yes, default type *no-offload*
550
551  * Available options:
552
553    * *lookaside-protocol-offload*: look aside protocol offload to HW accelerator
554    * *inline-protocol-offload*: inline protocol offload on ethernet device
555    * *inline-crypto-offload*: inline crypto processing on ethernet device
556    * *no-offload*: no offloading to hardware
557
558  ``<port_id>``
559
560  * Port/device ID of the ethernet/crypto accelerator for which the SA is
561    configured. This option is used when *type* is NOT *no-offload*
562
563  * Optional: No, if *type* is not *no-offload*
564
565  * Syntax:
566
567    * *port_id X* X is a valid device number in decimal
568
569
570 Example SA rules:
571
572 .. code-block:: console
573
574     sa out 5 cipher_algo null auth_algo null mode ipv4-tunnel \
575     src 172.16.1.5 dst 172.16.2.5
576
577     sa out 25 cipher_algo aes-128-cbc \
578     cipher_key c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3 \
579     auth_algo sha1-hmac \
580     auth_key c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3 \
581     mode ipv6-tunnel \
582     src 1111:1111:1111:1111:1111:1111:1111:5555 \
583     dst 2222:2222:2222:2222:2222:2222:2222:5555
584
585     sa in 105 aead_algo aes-128-gcm \
586     aead_key de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef \
587     mode ipv4-tunnel src 172.16.2.5 dst 172.16.1.5
588
589     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 \
590     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 \
591     mode ipv4-tunnel src 172.16.1.5 dst 172.16.2.5 \
592     type lookaside-protocol-offload port_id 4
593
594 Routing rule syntax
595 ^^^^^^^^^^^^^^^^^^^
596
597 The Routing rule syntax is shown as follows:
598
599 .. code-block:: console
600
601     rt <ip_ver> <src_ip> <dst_ip> <port>
602
603
604 where each options means:
605
606 ``<ip_ver>``
607
608  * IP protocol version
609
610  * Optional: No
611
612  * Available options:
613
614    * *ipv4*: IP protocol version 4
615    * *ipv6*: IP protocol version 6
616
617 ``<src_ip>``
618
619  * The source IP address and mask
620
621  * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
622
623  * Syntax:
624
625    * *src X.X.X.X/Y* for IPv4
626    * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
627
628 ``<dst_ip>``
629
630  * The destination IP address and mask
631
632  * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
633
634  * Syntax:
635
636    * *dst X.X.X.X/Y* for IPv4
637    * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
638
639 ``<port>``
640
641  * The traffic output port id
642
643  * Optional: yes, default output port 0 will be used
644
645  * Syntax: *port X*
646
647 Example SP rules:
648
649 .. code-block:: console
650
651     rt ipv4 dst 172.16.1.5/32 port 0
652
653     rt ipv6 dst 1111:1111:1111:1111:1111:1111:1111:5555/116 port 0