New upstream version 17.11-rc3
[deb_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 Compiling the Application
96 -------------------------
97
98 To compile the sample application see :doc:`compiling`.
99
100 The application is located in the ``rpsec-secgw`` sub-directory.
101
102 #. [Optional] Build the application for debugging:
103    This option adds some extra flags, disables compiler optimizations and
104    is verbose::
105
106        make DEBUG=1
107
108
109 Running the Application
110 -----------------------
111
112 The application has a number of command line options::
113
114
115    ./build/ipsec-secgw [EAL options] --
116                         -p PORTMASK -P -u PORTMASK -j FRAMESIZE
117                         --config (port,queue,lcore)[,(port,queue,lcore]
118                         --single-sa SAIDX
119                         -f CONFIG_FILE_PATH
120
121 Where:
122
123 *   ``-p PORTMASK``: Hexadecimal bitmask of ports to configure.
124
125 *   ``-P``: *optional*. Sets all ports to promiscuous mode so that packets are
126     accepted regardless of the packet's Ethernet MAC destination address.
127     Without this option, only packets with the Ethernet MAC destination address
128     set to the Ethernet address of the port are accepted (default is enabled).
129
130 *   ``-u PORTMASK``: hexadecimal bitmask of unprotected ports
131
132 *   ``-j FRAMESIZE``: *optional*. Enables jumbo frames with the maximum size
133     specified as FRAMESIZE. If an invalid value is provided as FRAMESIZE
134     then the default value 9000 is used.
135
136 *   ``--config (port,queue,lcore)[,(port,queue,lcore)]``: determines which queues
137     from which ports are mapped to which cores.
138
139 *   ``--single-sa SAIDX``: use a single SA for outbound traffic, bypassing the SP
140     on both Inbound and Outbound. This option is meant for debugging/performance
141     purposes.
142
143 *   ``-f CONFIG_FILE_PATH``: the full path of text-based file containing all
144     configuration items for running the application (See Configuration file
145     syntax section below). ``-f CONFIG_FILE_PATH`` **must** be specified.
146     **ONLY** the UNIX format configuration file is accepted.
147
148
149 The mapping of lcores to port/queues is similar to other l3fwd applications.
150
151 For example, given the following command line::
152
153     ./build/ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048       \
154            --vdev "crypto_null" -- -p 0xf -P -u 0x3      \
155            --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)"       \
156            -f /path/to/config_file                              \
157
158 where each options means:
159
160 *   The ``-l`` option enables cores 20 and 21.
161
162 *   The ``-n`` option sets memory 4 channels.
163
164 *   The ``--socket-mem`` to use 2GB on socket 1.
165
166 *   The ``--vdev "crypto_null"`` option creates virtual NULL cryptodev PMD.
167
168 *   The ``-p`` option enables ports (detected) 0, 1, 2 and 3.
169
170 *   The ``-P`` option enables promiscuous mode.
171
172 *   The ``-u`` option sets ports 1 and 2 as unprotected, leaving 2 and 3 as protected.
173
174 *   The ``--config`` option enables one queue per port with the following mapping:
175
176     +----------+-----------+-----------+---------------------------------------+
177     | **Port** | **Queue** | **lcore** | **Description**                       |
178     |          |           |           |                                       |
179     +----------+-----------+-----------+---------------------------------------+
180     | 0        | 0         | 20        | Map queue 0 from port 0 to lcore 20.  |
181     |          |           |           |                                       |
182     +----------+-----------+-----------+---------------------------------------+
183     | 1        | 0         | 20        | Map queue 0 from port 1 to lcore 20.  |
184     |          |           |           |                                       |
185     +----------+-----------+-----------+---------------------------------------+
186     | 2        | 0         | 21        | Map queue 0 from port 2 to lcore 21.  |
187     |          |           |           |                                       |
188     +----------+-----------+-----------+---------------------------------------+
189     | 3        | 0         | 21        | Map queue 0 from port 3 to lcore 21.  |
190     |          |           |           |                                       |
191     +----------+-----------+-----------+---------------------------------------+
192
193 *   The ``-f /path/to/config_file`` option enables the application read and
194     parse the configuration file specified, and configures the application
195     with a given set of SP, SA and Routing entries accordingly. The syntax of
196     the configuration file will be explained below in more detail. Please
197     **note** the parser only accepts UNIX format text file. Other formats
198     such as DOS/MAC format will cause a parse error.
199
200 Refer to the *DPDK Getting Started Guide* for general information on running
201 applications and the Environment Abstraction Layer (EAL) options.
202
203 The application would do a best effort to "map" crypto devices to cores, with
204 hardware devices having priority. Basically, hardware devices if present would
205 be assigned to a core before software ones.
206 This means that if the application is using a single core and both hardware
207 and software crypto devices are detected, hardware devices will be used.
208
209 A way to achieve the case where you want to force the use of virtual crypto
210 devices is to whitelist the Ethernet devices needed and therefore implicitly
211 blacklisting all hardware crypto devices.
212
213 For example, something like the following command line:
214
215 .. code-block:: console
216
217     ./build/ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048 \
218             -w 81:00.0 -w 81:00.1 -w 81:00.2 -w 81:00.3 \
219             --vdev "crypto_aesni_mb" --vdev "crypto_null" \
220             -- \
221             -p 0xf -P -u 0x3 --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)" \
222             -f sample.cfg
223
224
225 Configurations
226 --------------
227
228 The following sections provide the syntax of configurations to initialize
229 your SP, SA and Routing tables.
230 Configurations shall be specified in the configuration file to be passed to
231 the application. The file is then parsed by the application. The successful
232 parsing will result in the appropriate rules being applied to the tables
233 accordingly.
234
235
236 Configuration File Syntax
237 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
238
239 As mention in the overview, the Security Policies are ACL rules.
240 The application parsers the rules specified in the configuration file and
241 passes them to the ACL table, and replicates them per socket in use.
242
243 Following are the configuration file syntax.
244
245 General rule syntax
246 ^^^^^^^^^^^^^^^^^^^
247
248 The parse treats one line in the configuration file as one configuration
249 item (unless the line concatenation symbol exists). Every configuration
250 item shall follow the syntax of either SP, SA, or Routing rules specified
251 below.
252
253 The configuration parser supports the following special symbols:
254
255  * Comment symbol **#**. Any character from this symbol to the end of
256    line is treated as comment and will not be parsed.
257
258  * Line concatenation symbol **\\**. This symbol shall be placed in the end
259    of the line to be concatenated to the line below. Multiple lines'
260    concatenation is supported.
261
262
263 SP rule syntax
264 ^^^^^^^^^^^^^^
265
266 The SP rule syntax is shown as follows:
267
268 .. code-block:: console
269
270     sp <ip_ver> <dir> esp <action> <priority> <src_ip> <dst_ip>
271     <proto> <sport> <dport>
272
273
274 where each options means:
275
276 ``<ip_ver>``
277
278  * IP protocol version
279
280  * Optional: No
281
282  * Available options:
283
284    * *ipv4*: IP protocol version 4
285    * *ipv6*: IP protocol version 6
286
287 ``<dir>``
288
289  * The traffic direction
290
291  * Optional: No
292
293  * Available options:
294
295    * *in*: inbound traffic
296    * *out*: outbound traffic
297
298 ``<action>``
299
300  * IPsec action
301
302  * Optional: No
303
304  * Available options:
305
306    * *protect <SA_idx>*: the specified traffic is protected by SA rule
307      with id SA_idx
308    * *bypass*: the specified traffic traffic is bypassed
309    * *discard*: the specified traffic is discarded
310
311 ``<priority>``
312
313  * Rule priority
314
315  * Optional: Yes, default priority 0 will be used
316
317  * Syntax: *pri <id>*
318
319 ``<src_ip>``
320
321  * The source IP address and mask
322
323  * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
324
325  * Syntax:
326
327    * *src X.X.X.X/Y* for IPv4
328    * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
329
330 ``<dst_ip>``
331
332  * The destination IP address and mask
333
334  * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
335
336  * Syntax:
337
338    * *dst X.X.X.X/Y* for IPv4
339    * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
340
341 ``<proto>``
342
343  * The protocol start and end range
344
345  * Optional: yes, default range of 0 to 0 will be used
346
347  * Syntax: *proto X:Y*
348
349 ``<sport>``
350
351  * The source port start and end range
352
353  * Optional: yes, default range of 0 to 0 will be used
354
355  * Syntax: *sport X:Y*
356
357 ``<dport>``
358
359  * The destination port start and end range
360
361  * Optional: yes, default range of 0 to 0 will be used
362
363  * Syntax: *dport X:Y*
364
365 Example SP rules:
366
367 .. code-block:: console
368
369     sp ipv4 out esp protect 105 pri 1 dst 192.168.115.0/24 sport 0:65535 \
370     dport 0:65535
371
372     sp ipv6 in esp bypass pri 1 dst 0000:0000:0000:0000:5555:5555:\
373     0000:0000/96 sport 0:65535 dport 0:65535
374
375
376 SA rule syntax
377 ^^^^^^^^^^^^^^
378
379 The successfully parsed SA rules will be stored in an array table.
380
381 The SA rule syntax is shown as follows:
382
383 .. code-block:: console
384
385     sa <dir> <spi> <cipher_algo> <cipher_key> <auth_algo> <auth_key>
386     <mode> <src_ip> <dst_ip> <action_type> <port_id>
387
388 where each options means:
389
390 ``<dir>``
391
392  * The traffic direction
393
394  * Optional: No
395
396  * Available options:
397
398    * *in*: inbound traffic
399    * *out*: outbound traffic
400
401 ``<spi>``
402
403  * The SPI number
404
405  * Optional: No
406
407  * Syntax: unsigned integer number
408
409 ``<cipher_algo>``
410
411  * Cipher algorithm
412
413  * Optional: Yes, unless <aead_algo> is not used
414
415  * Available options:
416
417    * *null*: NULL algorithm
418    * *aes-128-cbc*: AES-CBC 128-bit algorithm
419    * *aes-128-ctr*: AES-CTR 128-bit algorithm
420
421  * Syntax: *cipher_algo <your algorithm>*
422
423 ``<cipher_key>``
424
425  * Cipher key, NOT available when 'null' algorithm is used
426
427  * Optional: Yes, unless <aead_algo> is not used.
428    Must be followed by <cipher_algo> option
429
430  * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'.
431    The number of bytes should be as same as the specified cipher algorithm
432    key size.
433
434    For example: *cipher_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:
435    A1:B2:C3:D4*
436
437 ``<auth_algo>``
438
439  * Authentication algorithm
440
441  * Optional: Yes, unless <aead_algo> is not used
442
443  * Available options:
444
445     * *null*: NULL algorithm
446     * *sha1-hmac*: HMAC SHA1 algorithm
447
448 ``<auth_key>``
449
450  * Authentication key, NOT available when 'null' or 'aes-128-gcm' algorithm
451    is used.
452
453  * Optional: Yes, unless <aead_algo> is not used.
454    Must be followed by <auth_algo> option
455
456  * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'.
457    The number of bytes should be as same as the specified authentication
458    algorithm key size.
459
460    For example: *auth_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:
461    A1:B2:C3:D4*
462
463 ``<aead_algo>``
464
465  * AEAD algorithm
466
467  * Optional: Yes, unless <cipher_algo> and <auth_algo> are not used
468
469  * Available options:
470
471    * *aes-128-gcm*: AES-GCM 128-bit algorithm
472
473  * Syntax: *cipher_algo <your algorithm>*
474
475 ``<aead_key>``
476
477  * Cipher key, NOT available when 'null' algorithm is used
478
479  * Optional: Yes, unless <cipher_algo> and <auth_algo> are not used.
480    Must be followed by <aead_algo> option
481
482  * Syntax: Hexadecimal bytes (0x0-0xFF) concatenate by colon symbol ':'.
483    The number of bytes should be as same as the specified AEAD algorithm
484    key size.
485
486    For example: *aead_key A1:B2:C3:D4:A1:B2:C3:D4:A1:B2:C3:D4:
487    A1:B2:C3:D4*
488
489 ``<mode>``
490
491  * The operation mode
492
493  * Optional: No
494
495  * Available options:
496
497    * *ipv4-tunnel*: Tunnel mode for IPv4 packets
498    * *ipv6-tunnel*: Tunnel mode for IPv6 packets
499    * *transport*: transport mode
500
501  * Syntax: mode XXX
502
503 ``<src_ip>``
504
505  * The source IP address. This option is not available when
506    transport mode is used
507
508  * Optional: Yes, default address 0.0.0.0 will be used
509
510  * Syntax:
511
512    * *src X.X.X.X* for IPv4
513    * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX* for IPv6
514
515 ``<dst_ip>``
516
517  * The destination IP address. This option is not available when
518    transport mode is used
519
520  * Optional: Yes, default address 0.0.0.0 will be used
521
522  * Syntax:
523
524    * *dst X.X.X.X* for IPv4
525    * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX* for IPv6
526
527 ``<type>``
528
529  * Action type to specify the security action. This option specify
530    the SA to be performed with look aside protocol offload to HW
531    accelerator or protocol offload on ethernet device or inline
532    crypto processing on the ethernet device during transmission.
533
534  * Optional: Yes, default type *no-offload*
535
536  * Available options:
537
538    * *lookaside-protocol-offload*: look aside protocol offload to HW accelerator
539    * *inline-protocol-offload*: inline protocol offload on ethernet device
540    * *inline-crypto-offload*: inline crypto processing on ethernet device
541    * *no-offload*: no offloading to hardware
542
543  ``<port_id>``
544
545  * Port/device ID of the ethernet/crypto accelerator for which the SA is
546    configured. This option is used when *type* is NOT *no-offload*
547
548  * Optional: No, if *type* is not *no-offload*
549
550  * Syntax:
551
552    * *port_id X* X is a valid device number in decimal
553
554
555 Example SA rules:
556
557 .. code-block:: console
558
559     sa out 5 cipher_algo null auth_algo null mode ipv4-tunnel \
560     src 172.16.1.5 dst 172.16.2.5
561
562     sa out 25 cipher_algo aes-128-cbc \
563     cipher_key c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3 \
564     auth_algo sha1-hmac \
565     auth_key c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3:c3 \
566     mode ipv6-tunnel \
567     src 1111:1111:1111:1111:1111:1111:1111:5555 \
568     dst 2222:2222:2222:2222:2222:2222:2222:5555
569
570     sa in 105 aead_algo aes-128-gcm \
571     aead_key de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef:de:ad:be:ef \
572     mode ipv4-tunnel src 172.16.2.5 dst 172.16.1.5
573
574     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 \
575     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 \
576     mode ipv4-tunnel src 172.16.1.5 dst 172.16.2.5 \
577     type lookaside-protocol-offload port_id 4
578
579 Routing rule syntax
580 ^^^^^^^^^^^^^^^^^^^
581
582 The Routing rule syntax is shown as follows:
583
584 .. code-block:: console
585
586     rt <ip_ver> <src_ip> <dst_ip> <port>
587
588
589 where each options means:
590
591 ``<ip_ver>``
592
593  * IP protocol version
594
595  * Optional: No
596
597  * Available options:
598
599    * *ipv4*: IP protocol version 4
600    * *ipv6*: IP protocol version 6
601
602 ``<src_ip>``
603
604  * The source IP address and mask
605
606  * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
607
608  * Syntax:
609
610    * *src X.X.X.X/Y* for IPv4
611    * *src XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
612
613 ``<dst_ip>``
614
615  * The destination IP address and mask
616
617  * Optional: Yes, default address 0.0.0.0 and mask of 0 will be used
618
619  * Syntax:
620
621    * *dst X.X.X.X/Y* for IPv4
622    * *dst XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX/Y* for IPv6
623
624 ``<port>``
625
626  * The traffic output port id
627
628  * Optional: yes, default output port 0 will be used
629
630  * Syntax: *port X*
631
632 Example SP rules:
633
634 .. code-block:: console
635
636     rt ipv4 dst 172.16.1.5/32 port 0
637
638     rt ipv6 dst 1111:1111:1111:1111:1111:1111:1111:5555/116 port 0