blob: 691bc071bba4c9dbc3d24e0c635ff6f6f71ef03f [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000015#ifndef __IPSEC_H__
16#define __IPSEC_H__
17
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010018#include <vnet/ip/ip.h>
19#include <vnet/feature/feature.h>
20
Klement Sekera4f10db32018-11-12 14:32:19 +010021#include <openssl/hmac.h>
22#include <openssl/rand.h>
23#include <openssl/evp.h>
24
25#include <vppinfra/types.h>
26#include <vppinfra/cache.h>
27
Matus Fabian694265d2016-08-10 01:55:36 -070028#define IPSEC_FLAG_IPSEC_GRE_TUNNEL (1 << 0)
29
Klement Sekerab4d30532018-11-08 13:00:02 +010030#define foreach_ipsec_output_next \
31 _ (DROP, "error-drop") \
Klement Sekerabe5a5dd2018-10-09 16:05:48 +020032 _ (ESP4_ENCRYPT, "esp4-encrypt") \
33 _ (AH4_ENCRYPT, "ah4-encrypt") \
34 _ (ESP6_ENCRYPT, "esp6-encrypt") \
35 _ (AH6_ENCRYPT, "ah6-encrypt")
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +000036
37#define _(v, s) IPSEC_OUTPUT_NEXT_##v,
38typedef enum
39{
40 foreach_ipsec_output_next
41#undef _
42 IPSEC_OUTPUT_N_NEXT,
43} ipsec_output_next_t;
44
Klement Sekerab4d30532018-11-08 13:00:02 +010045#define foreach_ipsec_input_next \
46 _ (DROP, "error-drop") \
Klement Sekerabe5a5dd2018-10-09 16:05:48 +020047 _ (ESP4_DECRYPT, "esp4-decrypt") \
48 _ (AH4_DECRYPT, "ah4-decrypt") \
49 _ (ESP6_DECRYPT, "esp6-decrypt") \
50 _ (AH6_DECRYPT, "ah6-decrypt")
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +000051
52#define _(v, s) IPSEC_INPUT_NEXT_##v,
53typedef enum
54{
55 foreach_ipsec_input_next
56#undef _
57 IPSEC_INPUT_N_NEXT,
58} ipsec_input_next_t;
59
Ed Warnickecb9cada2015-12-08 15:45:58 -070060#define foreach_ipsec_policy_action \
Klement Sekerab4d30532018-11-08 13:00:02 +010061 _ (0, BYPASS, "bypass") \
62 _ (1, DISCARD, "discard") \
63 _ (2, RESOLVE, "resolve") \
64 _ (3, PROTECT, "protect")
Ed Warnickecb9cada2015-12-08 15:45:58 -070065
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070066typedef enum
67{
Klement Sekerab4d30532018-11-08 13:00:02 +010068#define _(v, f, s) IPSEC_POLICY_ACTION_##f = v,
Ed Warnickecb9cada2015-12-08 15:45:58 -070069 foreach_ipsec_policy_action
70#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070071 IPSEC_POLICY_N_ACTION,
Ed Warnickecb9cada2015-12-08 15:45:58 -070072} ipsec_policy_action_t;
73
Klement Sekerab4d30532018-11-08 13:00:02 +010074#define foreach_ipsec_crypto_alg \
75 _ (0, NONE, "none") \
76 _ (1, AES_CBC_128, "aes-cbc-128") \
77 _ (2, AES_CBC_192, "aes-cbc-192") \
78 _ (3, AES_CBC_256, "aes-cbc-256") \
79 _ (4, AES_CTR_128, "aes-ctr-128") \
80 _ (5, AES_CTR_192, "aes-ctr-192") \
81 _ (6, AES_CTR_256, "aes-ctr-256") \
82 _ (7, AES_GCM_128, "aes-gcm-128") \
83 _ (8, AES_GCM_192, "aes-gcm-192") \
84 _ (9, AES_GCM_256, "aes-gcm-256") \
85 _ (10, DES_CBC, "des-cbc") \
86 _ (11, 3DES_CBC, "3des-cbc")
Ed Warnickecb9cada2015-12-08 15:45:58 -070087
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070088typedef enum
89{
Klement Sekerab4d30532018-11-08 13:00:02 +010090#define _(v, f, s) IPSEC_CRYPTO_ALG_##f = v,
Ed Warnickecb9cada2015-12-08 15:45:58 -070091 foreach_ipsec_crypto_alg
92#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070093 IPSEC_CRYPTO_N_ALG,
Ed Warnickecb9cada2015-12-08 15:45:58 -070094} ipsec_crypto_alg_t;
95
Klement Sekerab4d30532018-11-08 13:00:02 +010096#define foreach_ipsec_integ_alg \
97 _ (0, NONE, "none") \
98 _ (1, MD5_96, "md5-96") /* RFC2403 */ \
99 _ (2, SHA1_96, "sha1-96") /* RFC2404 */ \
100 _ (3, SHA_256_96, "sha-256-96") /* draft-ietf-ipsec-ciph-sha-256-00 */ \
101 _ (4, SHA_256_128, "sha-256-128") /* RFC4868 */ \
102 _ (5, SHA_384_192, "sha-384-192") /* RFC4868 */ \
103 _ (6, SHA_512_256, "sha-512-256") /* RFC4868 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700105typedef enum
106{
Klement Sekerab4d30532018-11-08 13:00:02 +0100107#define _(v, f, s) IPSEC_INTEG_ALG_##f = v,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108 foreach_ipsec_integ_alg
109#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700110 IPSEC_INTEG_N_ALG,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700111} ipsec_integ_alg_t;
112
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700113typedef enum
114{
115 IPSEC_PROTOCOL_AH = 0,
116 IPSEC_PROTOCOL_ESP = 1
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117} ipsec_protocol_t;
118
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700119typedef struct
120{
121 u32 id;
122 u32 spi;
123 ipsec_protocol_t protocol;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700125 ipsec_crypto_alg_t crypto_alg;
126 u8 crypto_key_len;
127 u8 crypto_key[128];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700129 ipsec_integ_alg_t integ_alg;
130 u8 integ_key_len;
131 u8 integ_key[128];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700132
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700133 u8 use_esn;
134 u8 use_anti_replay;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700136 u8 is_tunnel;
137 u8 is_tunnel_ip6;
Klement Sekera4b089f22018-04-17 18:04:57 +0200138 u8 udp_encap;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700139 ip46_address_t tunnel_src_addr;
140 ip46_address_t tunnel_dst_addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141
Pierre Pfister4c422f92018-12-10 11:19:08 +0100142 u32 tx_fib_index;
Radu Nicolau6929ea92016-11-29 11:00:30 +0000143 u32 salt;
144
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700145 /* runtime */
146 u32 seq;
147 u32 seq_hi;
148 u32 last_seq;
149 u32 last_seq_hi;
150 u64 replay_window;
Radu Nicolaucb33dc22017-02-16 16:49:46 +0000151
Klement Sekerab4d30532018-11-08 13:00:02 +0100152 /* lifetime data */
Radu Nicolaucb33dc22017-02-16 16:49:46 +0000153 u64 total_data_size;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700154} ipsec_sa_t;
155
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700156typedef struct
157{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 ip46_address_t start, stop;
159} ip46_address_range_t;
160
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700161typedef struct
162{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700163 u16 start, stop;
164} port_range_t;
165
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700166typedef struct
167{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700168 u8 is_add;
169 u8 esn;
170 u8 anti_replay;
171 ip4_address_t local_ip, remote_ip;
172 u32 local_spi;
173 u32 remote_spi;
Matthew Smith2838a232016-06-21 16:05:09 -0500174 ipsec_crypto_alg_t crypto_alg;
175 u8 local_crypto_key_len;
176 u8 local_crypto_key[128];
177 u8 remote_crypto_key_len;
178 u8 remote_crypto_key[128];
179 ipsec_integ_alg_t integ_alg;
180 u8 local_integ_key_len;
181 u8 local_integ_key[128];
182 u8 remote_integ_key_len;
183 u8 remote_integ_key[128];
Matthew Smith8e1039a2018-04-12 07:32:56 -0500184 u8 renumber;
185 u32 show_instance;
Radu Nicolau717de092018-08-03 10:37:24 +0100186 u8 udp_encap;
Pierre Pfister4c422f92018-12-10 11:19:08 +0100187 u32 tx_table_id;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700188} ipsec_add_del_tunnel_args_t;
189
Matus Fabian694265d2016-08-10 01:55:36 -0700190typedef struct
191{
192 u8 is_add;
193 u32 local_sa_id;
194 u32 remote_sa_id;
195 ip4_address_t local_ip;
196 ip4_address_t remote_ip;
197} ipsec_add_del_ipsec_gre_tunnel_args_t;
198
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700199typedef enum
200{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700201 IPSEC_IF_SET_KEY_TYPE_NONE,
202 IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO,
203 IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO,
204 IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG,
205 IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG,
206} ipsec_if_set_key_type_t;
207
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700208typedef struct
209{
210 u32 id;
211 i32 priority;
212 u8 is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700213
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700214 // Selector
215 u8 is_ipv6;
216 ip46_address_range_t laddr;
217 ip46_address_range_t raddr;
218 u8 protocol;
219 port_range_t lport;
220 port_range_t rport;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700221
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700222 // Policy
223 u8 policy;
224 u32 sa_id;
225 u32 sa_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700226
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700227 // Counter
228 vlib_counter_t counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700229} ipsec_policy_t;
230
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700231typedef struct
232{
233 u32 id;
234 /* pool of policies */
235 ipsec_policy_t *policies;
236 /* vectors of policy indices */
237 u32 *ipv4_outbound_policies;
238 u32 *ipv6_outbound_policies;
239 u32 *ipv4_inbound_protect_policy_indices;
240 u32 *ipv4_inbound_policy_discard_and_bypass_indices;
241 u32 *ipv6_inbound_protect_policy_indices;
242 u32 *ipv6_inbound_policy_discard_and_bypass_indices;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700243} ipsec_spd_t;
244
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700245typedef struct
246{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700247 u32 spd_index;
248} ip4_ipsec_config_t;
249
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700250typedef struct
251{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700252 u32 spd_index;
253} ip6_ipsec_config_t;
254
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700255typedef struct
256{
Dave Baracheb987d32018-05-03 08:26:39 -0400257 /* Required for pool_get_aligned */
258 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700259 u32 input_sa_index;
260 u32 output_sa_index;
261 u32 hw_if_index;
Matthew Smith8e1039a2018-04-12 07:32:56 -0500262 u32 show_instance;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700263} ipsec_tunnel_if_t;
264
Klement Sekerab4d30532018-11-08 13:00:02 +0100265typedef clib_error_t *(*add_del_sa_sess_cb_t) (u32 sa_index, u8 is_add);
266typedef clib_error_t *(*check_support_cb_t) (ipsec_sa_t * sa);
267
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700268typedef struct
269{
Klement Sekerab4d30532018-11-08 13:00:02 +0100270 u8 *name;
271 /* add/del callback */
272 add_del_sa_sess_cb_t add_del_sa_sess_cb;
273 /* check support function */
274 check_support_cb_t check_support_cb;
275 u32 ah4_encrypt_node_index;
276 u32 ah4_decrypt_node_index;
277 u32 ah4_encrypt_next_index;
278 u32 ah4_decrypt_next_index;
279 u32 ah6_encrypt_node_index;
280 u32 ah6_decrypt_node_index;
281 u32 ah6_encrypt_next_index;
282 u32 ah6_decrypt_next_index;
283} ipsec_ah_backend_t;
284
285typedef struct
286{
287 u8 *name;
288 /* add/del callback */
289 add_del_sa_sess_cb_t add_del_sa_sess_cb;
290 /* check support function */
291 check_support_cb_t check_support_cb;
292 u32 esp4_encrypt_node_index;
293 u32 esp4_decrypt_node_index;
294 u32 esp4_encrypt_next_index;
295 u32 esp4_decrypt_next_index;
296 u32 esp6_encrypt_node_index;
297 u32 esp6_decrypt_node_index;
298 u32 esp6_encrypt_next_index;
299 u32 esp6_decrypt_next_index;
300} ipsec_esp_backend_t;
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000301
302typedef struct
303{
Klement Sekera4f10db32018-11-12 14:32:19 +0100304 const EVP_CIPHER *type;
305 u8 iv_size;
306 u8 block_size;
307} ipsec_proto_main_crypto_alg_t;
308
309typedef struct
310{
311 const EVP_MD *md;
312 u8 trunc_size;
313} ipsec_proto_main_integ_alg_t;
314
315typedef struct
316{
317 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
318#if OPENSSL_VERSION_NUMBER >= 0x10100000L
319 EVP_CIPHER_CTX *encrypt_ctx;
320#else
321 EVP_CIPHER_CTX encrypt_ctx;
322#endif
323 CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
324#if OPENSSL_VERSION_NUMBER >= 0x10100000L
325 EVP_CIPHER_CTX *decrypt_ctx;
326#else
327 EVP_CIPHER_CTX decrypt_ctx;
328#endif
329 CLIB_CACHE_LINE_ALIGN_MARK (cacheline2);
330#if OPENSSL_VERSION_NUMBER >= 0x10100000L
331 HMAC_CTX *hmac_ctx;
332#else
333 HMAC_CTX hmac_ctx;
334#endif
335 ipsec_crypto_alg_t last_encrypt_alg;
336 ipsec_crypto_alg_t last_decrypt_alg;
337 ipsec_integ_alg_t last_integ_alg;
338} ipsec_proto_main_per_thread_data_t;
339
340typedef struct
341{
342 ipsec_proto_main_crypto_alg_t *ipsec_proto_main_crypto_algs;
343 ipsec_proto_main_integ_alg_t *ipsec_proto_main_integ_algs;
344 ipsec_proto_main_per_thread_data_t *per_thread_data;
345} ipsec_proto_main_t;
346
347extern ipsec_proto_main_t ipsec_proto_main;
348
349typedef struct
350{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700351 /* pool of tunnel instances */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700352 ipsec_spd_t *spds;
353 ipsec_sa_t *sad;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700354
355 /* pool of tunnel interfaces */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700356 ipsec_tunnel_if_t *tunnel_interfaces;
357 u32 *free_tunnel_if_indices;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700358
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700359 u32 **empty_buffers;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700360
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700361 uword *tunnel_index_by_key;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700362
363 /* convenience */
364 vlib_main_t *vlib_main;
365 vnet_main_t *vnet_main;
366
367 /* next node indices */
368 u32 feature_next_node_index[32];
369
370 /* hashes */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700371 uword *spd_index_by_spd_id;
372 uword *spd_index_by_sw_if_index;
373 uword *sa_index_by_sa_id;
374 uword *ipsec_if_pool_index_by_key;
Matthew Smith8e1039a2018-04-12 07:32:56 -0500375 uword *ipsec_if_real_dev_by_show_dev;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700376
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700377 /* node indices */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700378 u32 error_drop_node_index;
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200379 u32 esp4_encrypt_node_index;
380 u32 esp4_decrypt_node_index;
381 u32 ah4_encrypt_node_index;
382 u32 ah4_decrypt_node_index;
383 u32 esp6_encrypt_node_index;
384 u32 esp6_decrypt_node_index;
385 u32 ah6_encrypt_node_index;
386 u32 ah6_decrypt_node_index;
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700387 /* next node indices */
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200388 u32 esp4_encrypt_next_index;
389 u32 esp4_decrypt_next_index;
390 u32 ah4_encrypt_next_index;
391 u32 ah4_decrypt_next_index;
392 u32 esp6_encrypt_next_index;
393 u32 esp6_decrypt_next_index;
394 u32 ah6_encrypt_next_index;
395 u32 ah6_decrypt_next_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700396
Klement Sekerab4d30532018-11-08 13:00:02 +0100397 /* pool of ah backends */
398 ipsec_ah_backend_t *ah_backends;
399 /* pool of esp backends */
400 ipsec_esp_backend_t *esp_backends;
401 /* index of current ah backend */
402 u32 ah_current_backend;
403 /* index of current esp backend */
404 u32 esp_current_backend;
405 /* index of default ah backend */
406 u32 ah_default_backend;
407 /* index of default esp backend */
408 u32 esp_default_backend;
Klement Sekeraee52d872018-06-07 19:36:07 +0200409
410 /* helper for sort function */
411 ipsec_spd_t *spd_to_sort;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700412} ipsec_main_t;
413
Dave Wallace71612d62017-10-24 01:32:41 -0400414extern ipsec_main_t ipsec_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700415
Klement Sekerab4d30532018-11-08 13:00:02 +0100416clib_error_t *ipsec_add_del_sa_sess_cb (ipsec_main_t * im, u32 sa_index,
417 u8 is_add);
418
419clib_error_t *ipsec_check_support_cb (ipsec_main_t * im, ipsec_sa_t * sa);
420
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200421extern vlib_node_registration_t esp4_encrypt_node;
422extern vlib_node_registration_t esp4_decrypt_node;
423extern vlib_node_registration_t ah4_encrypt_node;
424extern vlib_node_registration_t ah4_decrypt_node;
425extern vlib_node_registration_t esp6_encrypt_node;
426extern vlib_node_registration_t esp6_decrypt_node;
427extern vlib_node_registration_t ah6_encrypt_node;
428extern vlib_node_registration_t ah6_decrypt_node;
Jean-Mickael Guerin8941ec22016-03-04 14:14:21 +0100429extern vlib_node_registration_t ipsec_if_input_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700430
Ed Warnickecb9cada2015-12-08 15:45:58 -0700431/*
432 * functions
433 */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700434int ipsec_set_interface_spd (vlib_main_t * vm, u32 sw_if_index, u32 spd_id,
435 int is_add);
436int ipsec_add_del_spd (vlib_main_t * vm, u32 spd_id, int is_add);
437int ipsec_add_del_policy (vlib_main_t * vm, ipsec_policy_t * policy,
438 int is_add);
Radu Nicolau717de092018-08-03 10:37:24 +0100439int ipsec_add_del_sa (vlib_main_t * vm, ipsec_sa_t * new_sa, int is_add);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700440int ipsec_set_sa_key (vlib_main_t * vm, ipsec_sa_t * sa_update);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700441
Matus Fabian694265d2016-08-10 01:55:36 -0700442u32 ipsec_get_sa_index_by_sa_id (u32 sa_id);
Matthew Smithca514fd2017-10-12 12:06:59 -0500443u8 ipsec_is_sa_used (u32 sa_index);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700444u8 *format_ipsec_policy_action (u8 * s, va_list * args);
445u8 *format_ipsec_crypto_alg (u8 * s, va_list * args);
446u8 *format_ipsec_integ_alg (u8 * s, va_list * args);
447u8 *format_ipsec_replay_window (u8 * s, va_list * args);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700448uword unformat_ipsec_policy_action (unformat_input_t * input, va_list * args);
449uword unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args);
450uword unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args);
451
Matthew Smithe04d09d2017-05-14 21:47:18 -0500452int ipsec_add_del_tunnel_if_internal (vnet_main_t * vnm,
453 ipsec_add_del_tunnel_args_t * args,
454 u32 * sw_if_index);
Matthew Smith2838a232016-06-21 16:05:09 -0500455int ipsec_add_del_tunnel_if (ipsec_add_del_tunnel_args_t * args);
Matus Fabian694265d2016-08-10 01:55:36 -0700456int ipsec_add_del_ipsec_gre_tunnel (vnet_main_t * vnm,
457 ipsec_add_del_ipsec_gre_tunnel_args_t *
458 args);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700459int ipsec_set_interface_key (vnet_main_t * vnm, u32 hw_if_index,
460 ipsec_if_set_key_type_t type, u8 alg, u8 * key);
Matthew Smithca514fd2017-10-12 12:06:59 -0500461int ipsec_set_interface_sa (vnet_main_t * vnm, u32 hw_if_index, u32 sa_id,
462 u8 is_outbound);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700463
Ed Warnickecb9cada2015-12-08 15:45:58 -0700464/*
465 * inline functions
466 */
467
468always_inline void
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700469ipsec_alloc_empty_buffers (vlib_main_t * vm, ipsec_main_t * im)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700470{
Damjan Marion067cd622018-07-11 12:47:43 +0200471 u32 thread_index = vm->thread_index;
Damjan Marion586afd72017-04-05 19:18:20 +0200472 uword l = vec_len (im->empty_buffers[thread_index]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700473 uword n_alloc = 0;
474
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700475 if (PREDICT_FALSE (l < VLIB_FRAME_SIZE))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700476 {
Damjan Marion586afd72017-04-05 19:18:20 +0200477 if (!im->empty_buffers[thread_index])
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700478 {
Damjan Marion586afd72017-04-05 19:18:20 +0200479 vec_alloc (im->empty_buffers[thread_index], 2 * VLIB_FRAME_SIZE);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700480 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700481
Damjan Marion586afd72017-04-05 19:18:20 +0200482 n_alloc = vlib_buffer_alloc (vm, im->empty_buffers[thread_index] + l,
Damjan Marion67655492016-11-15 12:50:28 +0100483 2 * VLIB_FRAME_SIZE - l);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700484
Damjan Marion586afd72017-04-05 19:18:20 +0200485 _vec_len (im->empty_buffers[thread_index]) = l + n_alloc;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700486 }
487}
488
Matus Fabian08a6f012016-11-15 06:08:51 -0800489static_always_inline u32
490get_next_output_feature_node_index (vlib_buffer_t * b,
491 vlib_node_runtime_t * nr)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700492{
Matus Fabian08a6f012016-11-15 06:08:51 -0800493 u32 next;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700494 vlib_main_t *vm = vlib_get_main ();
Matus Fabian08a6f012016-11-15 06:08:51 -0800495 vlib_node_t *node = vlib_get_node (vm, nr->node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700496
Damjan Marion7d98a122018-07-19 20:42:08 +0200497 vnet_feature_next (&next, b);
Matus Fabian08a6f012016-11-15 06:08:51 -0800498 return node->next_nodes[next];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700499}
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700500
Klement Sekerab4d30532018-11-08 13:00:02 +0100501u32 ipsec_register_ah_backend (vlib_main_t * vm, ipsec_main_t * im,
502 const char *name,
503 const char *ah4_encrypt_node_name,
504 const char *ah4_decrypt_node_name,
505 const char *ah6_encrypt_node_name,
506 const char *ah6_decrypt_node_name,
507 check_support_cb_t ah_check_support_cb,
508 add_del_sa_sess_cb_t ah_add_del_sa_sess_cb);
509
510u32 ipsec_register_esp_backend (vlib_main_t * vm, ipsec_main_t * im,
511 const char *name,
512 const char *esp4_encrypt_node_name,
513 const char *esp4_decrypt_node_name,
514 const char *esp6_encrypt_node_name,
515 const char *esp6_decrypt_node_name,
516 check_support_cb_t esp_check_support_cb,
517 add_del_sa_sess_cb_t esp_add_del_sa_sess_cb);
518
519int ipsec_select_ah_backend (ipsec_main_t * im, u32 ah_backend_idx);
520int ipsec_select_esp_backend (ipsec_main_t * im, u32 esp_backend_idx);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000521#endif /* __IPSEC_H__ */
522
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700523/*
524 * fd.io coding-style-patch-verification: ON
525 *
526 * Local Variables:
527 * eval: (c-set-style "gnu")
528 * End:
529 */