2 Copyright(c) 2016 Intel Corporation. All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
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
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.
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.
31 IPsec Security Gateway Sample Application
32 =========================================
34 The IPsec Security Gateway application is an example of a "real world"
35 application using DPDK cryptodev framework.
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.
44 Internet Key Exchange (IKE) is not implemented, so only manual setting of
45 Security Policies and Security Associations is supported.
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
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.
55 The Path for IPsec Inbound traffic is:
57 * Read packets from the port.
58 * Classify packets between IPv4 and ESP.
59 * Perform Inbound SA lookup for ESP packets based on their SPI.
60 * Perform Verification/Decryption.
61 * Remove ESP and outer IP header
62 * Inbound SP check using ACL of decrypted packets and any other IPv4 packets.
64 * Write packet to port.
66 The Path for the IPsec Outbound traffic is:
68 * Read packets from the port.
69 * Perform Outbound SP check using ACL of all IPv4 traffic.
70 * Perform Outbound SA lookup for packets that need IPsec protection.
71 * Add ESP and outer IP header.
72 * Perform Encryption/Digest.
74 * Write packet to port.
80 * No IPv6 options headers.
82 * Currently only EAS-CBC, HMAC-SHA1 and NULL.
83 * Each SA must be handle by a unique lcore (*1 RX queue per port*).
87 Compiling the Application
88 -------------------------
90 To compile the application:
92 #. Go to the sample application directory::
94 export RTE_SDK=/path/to/rte_sdk
95 cd ${RTE_SDK}/examples/ipsec-secgw
97 #. Set the target (a default target is used if not specified). For example::
100 export RTE_TARGET=x86_64-native-linuxapp-gcc
102 See the *DPDK Getting Started Guide* for possible RTE_TARGET values.
104 #. Build the application::
108 #. [Optional] Build the application for debugging:
109 This option adds some extra flags, disables compiler optimizations and
115 Running the Application
116 -----------------------
118 The application has a number of command line options::
121 ./build/ipsec-secgw [EAL options] --
122 -p PORTMASK -P -u PORTMASK
123 --config (port,queue,lcore)[,(port,queue,lcore]
129 * ``-p PORTMASK``: Hexadecimal bitmask of ports to configure.
131 * ``-P``: *optional*. Sets all ports to promiscuous mode so that packets are
132 accepted regardless of the packet's Ethernet MAC destination address.
133 Without this option, only packets with the Ethernet MAC destination address
134 set to the Ethernet address of the port are accepted (default is enabled).
136 * ``-u PORTMASK``: hexadecimal bitmask of unprotected ports
138 * ``--config (port,queue,lcore)[,(port,queue,lcore)]``: determines which queues
139 from which ports are mapped to which cores.
141 * ``--single-sa SAIDX``: use a single SA for outbound traffic, bypassing the SP
142 on both Inbound and Outbound. This option is meant for debugging/performance
145 * ``--ep0``: configure the app as Endpoint 0.
147 * ``--ep1``: configure the app as Endpoint 1.
149 Either one of ``--ep0`` or ``--ep1`` **must** be specified.
150 The main purpose of these options is to easily configure two systems
151 back-to-back that would forward traffic through an IPsec tunnel (see
152 :ref:`figure_ipsec_endpoints`).
154 The mapping of lcores to port/queues is similar to other l3fwd applications.
156 For example, given the following command line::
158 ./build/ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048 \
159 --vdev "cryptodev_null_pmd" -- -p 0xf -P -u 0x3 \
160 --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)" --ep0 \
162 where each options means:
164 * The ``-l`` option enables cores 20 and 21.
166 * The ``-n`` option sets memory 4 channels.
168 * The ``--socket-mem`` to use 2GB on socket 1.
170 * The ``--vdev "cryptodev_null_pmd"`` option creates virtual NULL cryptodev PMD.
172 * The ``-p`` option enables ports (detected) 0, 1, 2 and 3.
174 * The ``-P`` option enables promiscuous mode.
176 * The ``-u`` option sets ports 1 and 2 as unprotected, leaving 2 and 3 as protected.
178 * The ``--config`` option enables one queue per port with the following mapping:
180 +----------+-----------+-----------+---------------------------------------+
181 | **Port** | **Queue** | **lcore** | **Description** |
183 +----------+-----------+-----------+---------------------------------------+
184 | 0 | 0 | 20 | Map queue 0 from port 0 to lcore 20. |
186 +----------+-----------+-----------+---------------------------------------+
187 | 1 | 0 | 20 | Map queue 0 from port 1 to lcore 20. |
189 +----------+-----------+-----------+---------------------------------------+
190 | 2 | 0 | 21 | Map queue 0 from port 2 to lcore 21. |
192 +----------+-----------+-----------+---------------------------------------+
193 | 3 | 0 | 21 | Map queue 0 from port 3 to lcore 21. |
195 +----------+-----------+-----------+---------------------------------------+
197 * The ``--ep0`` options configures the app with a given set of SP, SA and Routing
198 entries as explained below in more detail.
200 Refer to the *DPDK Getting Started Guide* for general information on running
201 applications and the Environment Abstraction Layer (EAL) options.
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.
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.
213 For example, something like the following command line:
215 .. code-block:: console
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 "cryptodev_aesni_mb_pmd" --vdev "cryptodev_null_pmd" \
221 -p 0xf -P -u 0x3 --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)" \
228 The following sections provide some details on the default values used to
229 initialize the SP, SA and Routing tables.
230 Currently all configuration information is hard coded into the application.
232 The following image illustrate a few of the concepts regarding IPSec, such
233 as protected/unprotected and inbound/outbound traffic, from the point of
234 view of two back-to-back endpoints:
236 .. _figure_ipsec_endpoints:
238 .. figure:: img/ipsec_endpoints.*
240 IPSec Inbound/Outbound traffic
242 Note that the above image only displays unidirectional traffic per port
243 for illustration purposes.
244 The application supports bidirectional traffic on all ports,
247 Security Policy Initialization
248 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250 As mention in the overview, the Security Policies are ACL rules.
251 The application defines two ACLs, one each of Inbound and Outbound, and
252 it replicates them per socket in use.
254 Following are the default rules which show only the relevant information,
255 assuming ANY value is valid for the fields not mentioned (src ip, proto,
258 .. _table_ipsec_endpoint_outbound_sp:
260 .. table:: Endpoint 0 Outbound Security Policies
262 +-----------------------------------+------------+
263 | **Dst** | **SA idx** |
265 +-----------------------------------+------------+
266 | 192.168.105.0/24 | 5 |
268 +-----------------------------------+------------+
269 | 192.168.106.0/24 | 6 |
271 +-----------------------------------+------------+
272 | 192.168.175.0/24 | 10 |
274 +-----------------------------------+------------+
275 | 192.168.176.0/24 | 11 |
277 +-----------------------------------+------------+
278 | 192.168.200.0/24 | 15 |
280 +-----------------------------------+------------+
281 | 192.168.201.0/24 | 16 |
283 +-----------------------------------+------------+
284 | 192.168.55.0/24 | 25 |
286 +-----------------------------------+------------+
287 | 192.168.56.0/24 | 26 |
289 +-----------------------------------+------------+
290 | 192.168.240.0/24 | BYPASS |
292 +-----------------------------------+------------+
293 | 192.168.241.0/24 | BYPASS |
295 +-----------------------------------+------------+
296 | 0:0:0:0:5555:5555:0:0/96 | 5 |
298 +-----------------------------------+------------+
299 | 0:0:0:0:6666:6666:0:0/96 | 6 |
301 +-----------------------------------+------------+
302 | 0:0:1111:1111:0:0:0:0/96 | 10 |
304 +-----------------------------------+------------+
305 | 0:0:1111:1111:1111:1111:0:0/96 | 11 |
307 +-----------------------------------+------------+
308 | 0:0:0:0:aaaa:aaaa:0:0/96 | 25 |
310 +-----------------------------------+------------+
311 | 0:0:0:0:bbbb:bbbb:0:0/96 | 26 |
313 +-----------------------------------+------------+
315 .. _table_ipsec_endpoint_inbound_sp:
317 .. table:: Endpoint 0 Inbound Security Policies
319 +-----------------------------------+------------+
320 | **Dst** | **SA idx** |
322 +-----------------------------------+------------+
323 | 192.168.115.0/24 | 105 |
325 +-----------------------------------+------------+
326 | 192.168.116.0/24 | 106 |
328 +-----------------------------------+------------+
329 | 192.168.185.0/24 | 110 |
331 +-----------------------------------+------------+
332 | 192.168.186.0/24 | 111 |
334 +-----------------------------------+------------+
335 | 192.168.210.0/24 | 115 |
337 +-----------------------------------+------------+
338 | 192.168.211.0/24 | 116 |
340 +-----------------------------------+------------+
341 | 192.168.65.0/24 | 125 |
343 +-----------------------------------+------------+
344 | 192.168.66.0/24 | 126 |
346 +-----------------------------------+------------+
347 | 192.168.245.0/24 | BYPASS |
349 +-----------------------------------+------------+
350 | 192.168.246.0/24 | BYPASS |
352 +-----------------------------------+------------+
353 | ffff:0:0:0:5555:5555:0:0/96 | 105 |
355 +-----------------------------------+------------+
356 | ffff:0:0:0:6666:6666:0:0/96 | 106 |
358 +-----------------------------------+------------+
359 | ffff:0:1111:1111:0:0:0:0/96 | 110 |
361 +-----------------------------------+------------+
362 | ffff:0:1111:1111:1111:1111:0:0/96 | 111 |
364 +-----------------------------------+------------+
365 | ffff:0:0:0:aaaa:aaaa:0:0/96 | 125 |
367 +-----------------------------------+------------+
368 | ffff:0:0:0:bbbb:bbbb:0:0/96 | 126 |
370 +-----------------------------------+------------+
372 For Endpoint 1, we use the same policies in reverse, meaning the Inbound SP
373 entries are set as Outbound and vice versa.
376 Security Association Initialization
377 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
379 The SAs are kept in a array table.
381 For Inbound, the SPI is used as index modulo the table size.
382 This means that on a table for 100 SA, SPI 5 and 105 would use the same index
383 and that is not currently supported.
385 Notice that it is not an issue for Outbound traffic as we store the index and
386 not the SPI in the Security Policy.
388 All SAs configured with AES-CBC and HMAC-SHA1 share the same values for cipher
389 block size and key, and authentication digest size and key.
391 The following are the default values:
393 .. _table_ipsec_endpoint_outbound_sa:
395 .. table:: Endpoint 0 Outbound Security Associations
397 +---------+----------+------------+-----------+----------------+----------------+
398 | **SPI** | **Mode** | **Cipher** | **Auth** | **Tunnel src** | **Tunnel dst** |
400 +---------+----------+------------+-----------+----------------+----------------+
401 | 5 | Tunnel | AES-CBC | HMAC-SHA1 | 172.16.1.5 | 172.16.2.5 |
403 +---------+----------+------------+-----------+----------------+----------------+
404 | 6 | Tunnel | AES-CBC | HMAC-SHA1 | 172.16.1.6 | 172.16.2.6 |
406 +---------+----------+------------+-----------+----------------+----------------+
407 | 10 | Trans | AES-CBC | HMAC-SHA1 | N/A | N/A |
409 +---------+----------+------------+-----------+----------------+----------------+
410 | 11 | Trans | AES-CBC | HMAC-SHA1 | N/A | N/A |
412 +---------+----------+------------+-----------+----------------+----------------+
413 | 15 | Tunnel | NULL | NULL | 172.16.1.5 | 172.16.2.5 |
415 +---------+----------+------------+-----------+----------------+----------------+
416 | 16 | Tunnel | NULL | NULL | 172.16.1.6 | 172.16.2.6 |
418 +---------+----------+------------+-----------+----------------+----------------+
419 | 25 | Tunnel | AES-CBC | HMAC-SHA1 | 1111:1111: | 2222:2222: |
420 | | | | | 1111:1111: | 2222:2222: |
421 | | | | | 1111:1111: | 2222:2222: |
422 | | | | | 1111:5555 | 2222:5555 |
424 +---------+----------+------------+-----------+----------------+----------------+
425 | 26 | Tunnel | AES-CBC | HMAC-SHA1 | 1111:1111: | 2222:2222: |
426 | | | | | 1111:1111: | 2222:2222: |
427 | | | | | 1111:1111: | 2222:2222: |
428 | | | | | 1111:6666 | 2222:6666 |
430 +---------+----------+------------+-----------+----------------+----------------+
432 .. _table_ipsec_endpoint_inbound_sa:
434 .. table:: Endpoint 0 Inbound Security Associations
436 +---------+----------+------------+-----------+----------------+----------------+
437 | **SPI** | **Mode** | **Cipher** | **Auth** | **Tunnel src** | **Tunnel dst** |
439 +---------+----------+------------+-----------+----------------+----------------+
440 | 105 | Tunnel | AES-CBC | HMAC-SHA1 | 172.16.2.5 | 172.16.1.5 |
442 +---------+----------+------------+-----------+----------------+----------------+
443 | 106 | Tunnel | AES-CBC | HMAC-SHA1 | 172.16.2.6 | 172.16.1.6 |
445 +---------+----------+------------+-----------+----------------+----------------+
446 | 110 | Trans | AES-CBC | HMAC-SHA1 | N/A | N/A |
448 +---------+----------+------------+-----------+----------------+----------------+
449 | 111 | Trans | AES-CBC | HMAC-SHA1 | N/A | N/A |
451 +---------+----------+------------+-----------+----------------+----------------+
452 | 115 | Tunnel | NULL | NULL | 172.16.2.5 | 172.16.1.5 |
454 +---------+----------+------------+-----------+----------------+----------------+
455 | 116 | Tunnel | NULL | NULL | 172.16.2.6 | 172.16.1.6 |
457 +---------+----------+------------+-----------+----------------+----------------+
458 | 125 | Tunnel | AES-CBC | HMAC-SHA1 | 2222:2222: | 1111:1111: |
459 | | | | | 2222:2222: | 1111:1111: |
460 | | | | | 2222:2222: | 1111:1111: |
461 | | | | | 2222:5555 | 1111:5555 |
463 +---------+----------+------------+-----------+----------------+----------------+
464 | 126 | Tunnel | AES-CBC | HMAC-SHA1 | 2222:2222: | 1111:1111: |
465 | | | | | 2222:2222: | 1111:1111: |
466 | | | | | 2222:2222: | 1111:1111: |
467 | | | | | 2222:6666 | 1111:6666 |
469 +---------+----------+------------+-----------+----------------+----------------+
471 For Endpoint 1, we use the same policies in reverse, meaning the Inbound SP
472 entries are set as Outbound and vice versa.
475 Routing Initialization
476 ~~~~~~~~~~~~~~~~~~~~~~
478 The Routing is implemented using an LPM table.
480 Following default values:
482 .. _table_ipsec_endpoint_outbound_routing:
484 .. table:: Endpoint 0 Routing Table
486 +------------------+----------+
487 | **Dst addr** | **Port** |
489 +------------------+----------+
490 | 172.16.2.5/32 | 0 |
492 +------------------+----------+
493 | 172.16.2.6/32 | 1 |
495 +------------------+----------+
496 | 192.168.175.0/24 | 0 |
498 +------------------+----------+
499 | 192.168.176.0/24 | 1 |
501 +------------------+----------+
502 | 192.168.240.0/24 | 0 |
504 +------------------+----------+
505 | 192.168.241.0/24 | 1 |
507 +------------------+----------+
508 | 192.168.115.0/24 | 2 |
510 +------------------+----------+
511 | 192.168.116.0/24 | 3 |
513 +------------------+----------+
514 | 192.168.65.0/24 | 2 |
516 +------------------+----------+
517 | 192.168.66.0/24 | 3 |
519 +------------------+----------+
520 | 192.168.185.0/24 | 2 |
522 +------------------+----------+
523 | 192.168.186.0/24 | 3 |
525 +------------------+----------+
526 | 192.168.210.0/24 | 2 |
528 +------------------+----------+
529 | 192.168.211.0/24 | 3 |
531 +------------------+----------+
532 | 192.168.245.0/24 | 2 |
534 +------------------+----------+
535 | 192.168.246.0/24 | 3 |
537 +------------------+----------+
543 +------------------+----------+
549 +------------------+----------+
555 +------------------+----------+
561 +------------------+----------+
567 +------------------+----------+
573 +------------------+----------+
579 +------------------+----------+
585 +------------------+----------+
591 +------------------+----------+
597 +------------------+----------+
599 .. _table_ipsec_endpoint_inbound_routing:
601 .. table:: Endpoint 1 Routing Table
603 +------------------+----------+
604 | **Dst addr** | **Port** |
606 +------------------+----------+
607 | 172.16.1.5/32 | 0 |
609 +------------------+----------+
610 | 172.16.1.6/32 | 1 |
612 +------------------+----------+
613 | 192.168.185.0/24 | 0 |
615 +------------------+----------+
616 | 192.168.186.0/24 | 1 |
618 +------------------+----------+
619 | 192.168.245.0/24 | 0 |
621 +------------------+----------+
622 | 192.168.246.0/24 | 1 |
624 +------------------+----------+
625 | 192.168.105.0/24 | 2 |
627 +------------------+----------+
628 | 192.168.106.0/24 | 3 |
630 +------------------+----------+
631 | 192.168.55.0/24 | 2 |
633 +------------------+----------+
634 | 192.168.56.0/24 | 3 |
636 +------------------+----------+
637 | 192.168.175.0/24 | 2 |
639 +------------------+----------+
640 | 192.168.176.0/24 | 3 |
642 +------------------+----------+
643 | 192.168.200.0/24 | 2 |
645 +------------------+----------+
646 | 192.168.201.0/24 | 3 |
648 +------------------+----------+
649 | 192.168.240.0/24 | 2 |
651 +------------------+----------+
652 | 192.168.241.0/24 | 3 |
654 +------------------+----------+
660 +------------------+----------+
666 +------------------+----------+
672 +------------------+----------+
678 +------------------+----------+
684 +------------------+----------+
690 +------------------+----------+
696 +------------------+----------+
702 +------------------+----------+
708 +------------------+----------+
714 +------------------+----------+