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