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 Constraints bellow) 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 classify the ports between Protected and Unprotected.
52 Thus, traffic received in an Unprotected or Protected port is consider
53 Inbound or Outbound respectively.
55 Path for IPsec Inbound traffic:
57 * Read packets from the port
58 * Classify packets between IPv4 and ESP.
59 * Inbound SA lookup for ESP packets based on their SPI
60 * Verification/Decryption
61 * Removal of ESP and outer IP header
62 * Inbound SP check using ACL of decrypted packets and any other IPv4 packet
65 * Write packet to port
67 Path for IPsec Outbound traffic:
69 * Read packets from the port
70 * Outbound SP check using ACL of all IPv4 traffic
71 * Outbound SA lookup for packets that need IPsec protection
72 * Add ESP and outer IP header
75 * Write packet to port
81 * EAS-CBC, HMAC-SHA1 and NULL
82 * Each SA must be handle by a unique lcore (1 RX queue per port)
85 Compiling the Application
86 -------------------------
88 To compile the application:
90 #. Go to the sample application directory:
92 .. code-block:: console
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:
99 .. code-block:: console
101 export RTE_TARGET=x86_64-native-linuxapp-gcc
103 See the *DPDK Getting Started Guide* for possible RTE_TARGET values.
105 #. Build the application:
107 .. code-block:: console
111 Running the Application
112 -----------------------
114 The application has a number of command line options:
116 .. code-block:: console
118 ./build/ipsec-secgw [EAL options] -- -p PORTMASK -P -u PORTMASK --config
119 (port,queue,lcore)[,(port,queue,lcore] --single-sa SAIDX --ep0|--ep1
123 * -p PORTMASK: Hexadecimal bitmask of ports to configure
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).
130 * -u PORTMASK: hexadecimal bitmask of unprotected ports
132 * --config (port,queue,lcore)[,(port,queue,lcore)]: determines which queues
133 from which ports are mapped to which cores
135 * --single-sa SAIDX: use a single SA for outbound traffic, bypassing the SP
136 on both Inbound and Outbound. This option is meant for debugging/performance
139 * --ep0: configure the app as Endpoint 0.
141 * --ep1: configure the app as Endpoint 1.
143 Either one of --ep0 or --ep1 *must* be specified.
144 The main purpose of these options is two easily configure two systems
145 back-to-back that would forward traffic through an IPsec tunnel.
147 The mapping of lcores to port/queues is similar to other l3fwd applications.
149 For example, given the following command line:
151 .. code-block:: console
153 ./build/ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048
154 --vdev "cryptodev_null_pmd" -- -p 0xf -P -u 0x3
155 --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)" --ep0
157 where each options means:
159 * The -l option enables cores 20 and 21
161 * The -n option sets memory 4 channels
163 * The --socket-mem to use 2GB on socket 1
165 * The --vdev "cryptodev_null_pmd" option creates virtual NULL cryptodev PMD
167 * The -p option enables ports (detected) 0, 1, 2 and 3
169 * The -P option enables promiscuous mode
171 * The -u option sets ports 1 and 2 as unprotected, leaving 2 and 3 as protected
173 * The --config option enables one queue per port with the following mapping:
175 +----------+-----------+-----------+---------------------------------------+
176 | **Port** | **Queue** | **lcore** | **Description** |
178 +----------+-----------+-----------+---------------------------------------+
179 | 0 | 0 | 20 | Map queue 0 from port 0 to lcore 20. |
181 +----------+-----------+-----------+---------------------------------------+
182 | 1 | 0 | 20 | Map queue 0 from port 1 to lcore 20. |
184 +----------+-----------+-----------+---------------------------------------+
185 | 2 | 0 | 21 | Map queue 0 from port 2 to lcore 21. |
187 +----------+-----------+-----------+---------------------------------------+
188 | 3 | 0 | 21 | Map queue 0 from port 3 to lcore 21. |
190 +----------+-----------+-----------+---------------------------------------+
192 * The --ep0 options configures the app with a given set of SP, SA and Routing
193 entries as explained below in more detail.
195 Refer to the *DPDK Getting Started Guide* for general information on running
196 applications and the Environment Abstraction Layer (EAL) options.
198 The application would do a best effort to "map" crypto devices to cores, with
199 hardware devices having priority.
200 This means that if the application is using a single core and both hardware
201 and software crypto devices are detected, hardware devices will be used.
203 A way to achieve the case where you want to force the use of virtual crypto
204 devices is to whitelist the Ethernet devices needed and therefore implicitly
205 blacklisting all hardware crypto devices.
207 For example, something like the following command line:
209 .. code-block:: console
211 ./build/ipsec-secgw -l 20,21 -n 4 --socket-mem 0,2048
212 -w 81:00.0 -w 81:00.1 -w 81:00.2 -w 81:00.3
213 --vdev "cryptodev_aesni_mb_pmd" --vdev "cryptodev_null_pmd" --
214 -p 0xf -P -u 0x3 --config="(0,0,20),(1,0,20),(2,0,21),(3,0,21)"
220 The following sections provide some details on the default values used to
221 initialize the SP, SA and Routing tables.
222 Currently all the configuration is hard coded into the application.
224 Security Policy Initialization
225 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
227 As mention in the overview, the Security Policies are ACL rules.
228 The application defines two ACLs, one each of Inbound and Outbound, and
229 it replicates them per socket in use.
231 Following are the default rules:
233 Endpoint 0 Outbound Security Policies:
235 +---------+------------------+-----------+------------+
236 | **Src** | **Dst** | **proto** | **SA idx** |
238 +---------+------------------+-----------+------------+
239 | Any | 192.168.105.0/24 | Any | 5 |
241 +---------+------------------+-----------+------------+
242 | Any | 192.168.106.0/24 | Any | 6 |
244 +---------+------------------+-----------+------------+
245 | Any | 192.168.107.0/24 | Any | 7 |
247 +---------+------------------+-----------+------------+
248 | Any | 192.168.108.0/24 | Any | 8 |
250 +---------+------------------+-----------+------------+
251 | Any | 192.168.200.0/24 | Any | 9 |
253 +---------+------------------+-----------+------------+
254 | Any | 192.168.250.0/24 | Any | BYPASS |
256 +---------+------------------+-----------+------------+
258 Endpoint 0 Inbound Security Policies:
260 +---------+------------------+-----------+------------+
261 | **Src** | **Dst** | **proto** | **SA idx** |
263 +---------+------------------+-----------+------------+
264 | Any | 192.168.115.0/24 | Any | 5 |
266 +---------+------------------+-----------+------------+
267 | Any | 192.168.116.0/24 | Any | 6 |
269 +---------+------------------+-----------+------------+
270 | Any | 192.168.117.0/24 | Any | 7 |
272 +---------+------------------+-----------+------------+
273 | Any | 192.168.118.0/24 | Any | 8 |
275 +---------+------------------+-----------+------------+
276 | Any | 192.168.210.0/24 | Any | 9 |
278 +---------+------------------+-----------+------------+
279 | Any | 192.168.240.0/24 | Any | BYPASS |
281 +---------+------------------+-----------+------------+
283 Endpoint 1 Outbound Security Policies:
285 +---------+------------------+-----------+------------+
286 | **Src** | **Dst** | **proto** | **SA idx** |
288 +---------+------------------+-----------+------------+
289 | Any | 192.168.115.0/24 | Any | 5 |
291 +---------+------------------+-----------+------------+
292 | Any | 192.168.116.0/24 | Any | 6 |
294 +---------+------------------+-----------+------------+
295 | Any | 192.168.117.0/24 | Any | 7 |
297 +---------+------------------+-----------+------------+
298 | Any | 192.168.118.0/24 | Any | 8 |
300 +---------+------------------+-----------+------------+
301 | Any | 192.168.210.0/24 | Any | 9 |
303 +---------+------------------+-----------+------------+
304 | Any | 192.168.240.0/24 | Any | BYPASS |
306 +---------+------------------+-----------+------------+
308 Endpoint 1 Inbound Security Policies:
310 +---------+------------------+-----------+------------+
311 | **Src** | **Dst** | **proto** | **SA idx** |
313 +---------+------------------+-----------+------------+
314 | Any | 192.168.105.0/24 | Any | 5 |
316 +---------+------------------+-----------+------------+
317 | Any | 192.168.106.0/24 | Any | 6 |
319 +---------+------------------+-----------+------------+
320 | Any | 192.168.107.0/24 | Any | 7 |
322 +---------+------------------+-----------+------------+
323 | Any | 192.168.108.0/24 | Any | 8 |
325 +---------+------------------+-----------+------------+
326 | Any | 192.168.200.0/24 | Any | 9 |
328 +---------+------------------+-----------+------------+
329 | Any | 192.168.250.0/24 | Any | BYPASS |
331 +---------+------------------+-----------+------------+
334 Security Association Initialization
335 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
337 The SAs are kept in a array table.
339 For Inbound, the SPI is used as index module the table size.
340 This means that on a table for 100 SA, SPI 5 and 105 would use the same index
341 and that is not currently supported.
343 Notice that it is not an issue for Outbound traffic as we store the index and
344 not the SPI in the Security Policy.
346 All SAs configured with AES-CBC and HMAC-SHA1 share the same values for cipher
347 block size and key, and authentication digest size and key.
349 Following are the default values:
351 Endpoint 0 Outbound Security Associations:
353 +---------+------------+-----------+----------------+------------------+
354 | **SPI** | **Cipher** | **Auth** | **Tunnel src** | **Tunnel dst** |
356 +---------+------------+-----------+----------------+------------------+
357 | 5 | AES-CBC | HMAC-SHA1 | 172.16.1.5 | 172.16.2.5 |
359 +---------+------------+-----------+----------------+------------------+
360 | 6 | AES-CBC | HMAC-SHA1 | 172.16.1.6 | 172.16.2.6 |
362 +---------+------------+-----------+----------------+------------------+
363 | 7 | AES-CBC | HMAC-SHA1 | 172.16.1.7 | 172.16.2.7 |
365 +---------+------------+-----------+----------------+------------------+
366 | 8 | AES-CBC | HMAC-SHA1 | 172.16.1.8 | 172.16.2.8 |
368 +---------+------------+-----------+----------------+------------------+
369 | 9 | NULL | NULL | 172.16.1.5 | 172.16.2.5 |
371 +---------+------------+-----------+----------------+------------------+
373 Endpoint 0 Inbound Security Associations:
375 +---------+------------+-----------+----------------+------------------+
376 | **SPI** | **Cipher** | **Auth** | **Tunnel src** | **Tunnel dst** |
378 +---------+------------+-----------+----------------+------------------+
379 | 5 | AES-CBC | HMAC-SHA1 | 172.16.2.5 | 172.16.1.5 |
381 +---------+------------+-----------+----------------+------------------+
382 | 6 | AES-CBC | HMAC-SHA1 | 172.16.2.6 | 172.16.1.6 |
384 +---------+------------+-----------+----------------+------------------+
385 | 7 | AES-CBC | HMAC-SHA1 | 172.16.2.7 | 172.16.1.7 |
387 +---------+------------+-----------+----------------+------------------+
388 | 8 | AES-CBC | HMAC-SHA1 | 172.16.2.8 | 172.16.1.8 |
390 +---------+------------+-----------+----------------+------------------+
391 | 9 | NULL | NULL | 172.16.2.5 | 172.16.1.5 |
393 +---------+------------+-----------+----------------+------------------+
395 Endpoint 1 Outbound Security Associations:
397 +---------+------------+-----------+----------------+------------------+
398 | **SPI** | **Cipher** | **Auth** | **Tunnel src** | **Tunnel dst** |
400 +---------+------------+-----------+----------------+------------------+
401 | 5 | AES-CBC | HMAC-SHA1 | 172.16.2.5 | 172.16.1.5 |
403 +---------+------------+-----------+----------------+------------------+
404 | 6 | AES-CBC | HMAC-SHA1 | 172.16.2.6 | 172.16.1.6 |
406 +---------+------------+-----------+----------------+------------------+
407 | 7 | AES-CBC | HMAC-SHA1 | 172.16.2.7 | 172.16.1.7 |
409 +---------+------------+-----------+----------------+------------------+
410 | 8 | AES-CBC | HMAC-SHA1 | 172.16.2.8 | 172.16.1.8 |
412 +---------+------------+-----------+----------------+------------------+
413 | 9 | NULL | NULL | 172.16.2.5 | 172.16.1.5 |
415 +---------+------------+-----------+----------------+------------------+
417 Endpoint 1 Inbound Security Associations:
419 +---------+------------+-----------+----------------+------------------+
420 | **SPI** | **Cipher** | **Auth** | **Tunnel src** | **Tunnel dst** |
422 +---------+------------+-----------+----------------+------------------+
423 | 5 | AES-CBC | HMAC-SHA1 | 172.16.1.5 | 172.16.2.5 |
425 +---------+------------+-----------+----------------+------------------+
426 | 6 | AES-CBC | HMAC-SHA1 | 172.16.1.6 | 172.16.2.6 |
428 +---------+------------+-----------+----------------+------------------+
429 | 7 | AES-CBC | HMAC-SHA1 | 172.16.1.7 | 172.16.2.7 |
431 +---------+------------+-----------+----------------+------------------+
432 | 8 | AES-CBC | HMAC-SHA1 | 172.16.1.8 | 172.16.2.8 |
434 +---------+------------+-----------+----------------+------------------+
435 | 9 | NULL | NULL | 172.16.1.5 | 172.16.2.5 |
437 +---------+------------+-----------+----------------+------------------+
439 Routing Initialization
440 ~~~~~~~~~~~~~~~~~~~~~~
442 The Routing is implemented using LPM table.
444 Following default values:
446 Endpoint 0 Routing Table:
448 +------------------+----------+
449 | **Dst addr** | **Port** |
451 +------------------+----------+
452 | 172.16.2.5/32 | 0 |
454 +------------------+----------+
455 | 172.16.2.6/32 | 0 |
457 +------------------+----------+
458 | 172.16.2.7/32 | 1 |
460 +------------------+----------+
461 | 172.16.2.8/32 | 1 |
463 +------------------+----------+
464 | 192.168.115.0/24 | 2 |
466 +------------------+----------+
467 | 192.168.116.0/24 | 2 |
469 +------------------+----------+
470 | 192.168.117.0/24 | 3 |
472 +------------------+----------+
473 | 192.168.118.0/24 | 3 |
475 +------------------+----------+
476 | 192.168.210.0/24 | 2 |
478 +------------------+----------+
479 | 192.168.240.0/24 | 2 |
481 +------------------+----------+
482 | 192.168.250.0/24 | 0 |
484 +------------------+----------+
486 Endpoint 1 Routing Table:
488 +------------------+----------+
489 | **Dst addr** | **Port** |
491 +------------------+----------+
492 | 172.16.1.5/32 | 2 |
494 +------------------+----------+
495 | 172.16.1.6/32 | 2 |
497 +------------------+----------+
498 | 172.16.1.7/32 | 3 |
500 +------------------+----------+
501 | 172.16.1.8/32 | 3 |
503 +------------------+----------+
504 | 192.168.105.0/24 | 0 |
506 +------------------+----------+
507 | 192.168.106.0/24 | 0 |
509 +------------------+----------+
510 | 192.168.107.0/24 | 1 |
512 +------------------+----------+
513 | 192.168.108.0/24 | 1 |
515 +------------------+----------+
516 | 192.168.200.0/24 | 0 |
518 +------------------+----------+
519 | 192.168.240.0/24 | 2 |
521 +------------------+----------+
522 | 192.168.250.0/24 | 0 |
524 +------------------+----------+