blob: ced71194f396541a0453f4e090a7bd1239326e88 [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
Matus Fabian694265d2016-08-10 01:55:36 -070021#define IPSEC_FLAG_IPSEC_GRE_TUNNEL (1 << 0)
22
Klement Sekerab4d30532018-11-08 13:00:02 +010023#define foreach_ipsec_output_next \
24 _ (DROP, "error-drop") \
Klement Sekerabe5a5dd2018-10-09 16:05:48 +020025 _ (ESP4_ENCRYPT, "esp4-encrypt") \
26 _ (AH4_ENCRYPT, "ah4-encrypt") \
27 _ (ESP6_ENCRYPT, "esp6-encrypt") \
28 _ (AH6_ENCRYPT, "ah6-encrypt")
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +000029
30#define _(v, s) IPSEC_OUTPUT_NEXT_##v,
31typedef enum
32{
33 foreach_ipsec_output_next
34#undef _
35 IPSEC_OUTPUT_N_NEXT,
36} ipsec_output_next_t;
37
Klement Sekerab4d30532018-11-08 13:00:02 +010038#define foreach_ipsec_input_next \
39 _ (DROP, "error-drop") \
Klement Sekerabe5a5dd2018-10-09 16:05:48 +020040 _ (ESP4_DECRYPT, "esp4-decrypt") \
41 _ (AH4_DECRYPT, "ah4-decrypt") \
42 _ (ESP6_DECRYPT, "esp6-decrypt") \
43 _ (AH6_DECRYPT, "ah6-decrypt")
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +000044
45#define _(v, s) IPSEC_INPUT_NEXT_##v,
46typedef enum
47{
48 foreach_ipsec_input_next
49#undef _
50 IPSEC_INPUT_N_NEXT,
51} ipsec_input_next_t;
52
Ed Warnickecb9cada2015-12-08 15:45:58 -070053#define foreach_ipsec_policy_action \
Klement Sekerab4d30532018-11-08 13:00:02 +010054 _ (0, BYPASS, "bypass") \
55 _ (1, DISCARD, "discard") \
56 _ (2, RESOLVE, "resolve") \
57 _ (3, PROTECT, "protect")
Ed Warnickecb9cada2015-12-08 15:45:58 -070058
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070059typedef enum
60{
Klement Sekerab4d30532018-11-08 13:00:02 +010061#define _(v, f, s) IPSEC_POLICY_ACTION_##f = v,
Ed Warnickecb9cada2015-12-08 15:45:58 -070062 foreach_ipsec_policy_action
63#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070064 IPSEC_POLICY_N_ACTION,
Ed Warnickecb9cada2015-12-08 15:45:58 -070065} ipsec_policy_action_t;
66
Klement Sekerab4d30532018-11-08 13:00:02 +010067#define foreach_ipsec_crypto_alg \
68 _ (0, NONE, "none") \
69 _ (1, AES_CBC_128, "aes-cbc-128") \
70 _ (2, AES_CBC_192, "aes-cbc-192") \
71 _ (3, AES_CBC_256, "aes-cbc-256") \
72 _ (4, AES_CTR_128, "aes-ctr-128") \
73 _ (5, AES_CTR_192, "aes-ctr-192") \
74 _ (6, AES_CTR_256, "aes-ctr-256") \
75 _ (7, AES_GCM_128, "aes-gcm-128") \
76 _ (8, AES_GCM_192, "aes-gcm-192") \
77 _ (9, AES_GCM_256, "aes-gcm-256") \
78 _ (10, DES_CBC, "des-cbc") \
79 _ (11, 3DES_CBC, "3des-cbc")
Ed Warnickecb9cada2015-12-08 15:45:58 -070080
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070081typedef enum
82{
Klement Sekerab4d30532018-11-08 13:00:02 +010083#define _(v, f, s) IPSEC_CRYPTO_ALG_##f = v,
Ed Warnickecb9cada2015-12-08 15:45:58 -070084 foreach_ipsec_crypto_alg
85#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070086 IPSEC_CRYPTO_N_ALG,
Ed Warnickecb9cada2015-12-08 15:45:58 -070087} ipsec_crypto_alg_t;
88
Klement Sekerab4d30532018-11-08 13:00:02 +010089#define foreach_ipsec_integ_alg \
90 _ (0, NONE, "none") \
91 _ (1, MD5_96, "md5-96") /* RFC2403 */ \
92 _ (2, SHA1_96, "sha1-96") /* RFC2404 */ \
93 _ (3, SHA_256_96, "sha-256-96") /* draft-ietf-ipsec-ciph-sha-256-00 */ \
94 _ (4, SHA_256_128, "sha-256-128") /* RFC4868 */ \
95 _ (5, SHA_384_192, "sha-384-192") /* RFC4868 */ \
96 _ (6, SHA_512_256, "sha-512-256") /* RFC4868 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070097
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -070098typedef enum
99{
Klement Sekerab4d30532018-11-08 13:00:02 +0100100#define _(v, f, s) IPSEC_INTEG_ALG_##f = v,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101 foreach_ipsec_integ_alg
102#undef _
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700103 IPSEC_INTEG_N_ALG,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700104} ipsec_integ_alg_t;
105
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700106typedef enum
107{
108 IPSEC_PROTOCOL_AH = 0,
109 IPSEC_PROTOCOL_ESP = 1
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110} ipsec_protocol_t;
111
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700112typedef struct
113{
114 u32 id;
115 u32 spi;
116 ipsec_protocol_t protocol;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700118 ipsec_crypto_alg_t crypto_alg;
119 u8 crypto_key_len;
120 u8 crypto_key[128];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700122 ipsec_integ_alg_t integ_alg;
123 u8 integ_key_len;
124 u8 integ_key[128];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700125
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700126 u8 use_esn;
127 u8 use_anti_replay;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700129 u8 is_tunnel;
130 u8 is_tunnel_ip6;
Klement Sekera4b089f22018-04-17 18:04:57 +0200131 u8 udp_encap;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700132 ip46_address_t tunnel_src_addr;
133 ip46_address_t tunnel_dst_addr;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700134
Radu Nicolau6929ea92016-11-29 11:00:30 +0000135 u32 salt;
136
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700137 /* runtime */
138 u32 seq;
139 u32 seq_hi;
140 u32 last_seq;
141 u32 last_seq_hi;
142 u64 replay_window;
Radu Nicolaucb33dc22017-02-16 16:49:46 +0000143
Klement Sekerab4d30532018-11-08 13:00:02 +0100144 /* lifetime data */
Radu Nicolaucb33dc22017-02-16 16:49:46 +0000145 u64 total_data_size;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146} ipsec_sa_t;
147
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700148typedef struct
149{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150 ip46_address_t start, stop;
151} ip46_address_range_t;
152
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700153typedef struct
154{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700155 u16 start, stop;
156} port_range_t;
157
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700158typedef struct
159{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700160 u8 is_add;
161 u8 esn;
162 u8 anti_replay;
163 ip4_address_t local_ip, remote_ip;
164 u32 local_spi;
165 u32 remote_spi;
Matthew Smith2838a232016-06-21 16:05:09 -0500166 ipsec_crypto_alg_t crypto_alg;
167 u8 local_crypto_key_len;
168 u8 local_crypto_key[128];
169 u8 remote_crypto_key_len;
170 u8 remote_crypto_key[128];
171 ipsec_integ_alg_t integ_alg;
172 u8 local_integ_key_len;
173 u8 local_integ_key[128];
174 u8 remote_integ_key_len;
175 u8 remote_integ_key[128];
Matthew Smith8e1039a2018-04-12 07:32:56 -0500176 u8 renumber;
177 u32 show_instance;
Radu Nicolau717de092018-08-03 10:37:24 +0100178 u8 udp_encap;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700179} ipsec_add_del_tunnel_args_t;
180
Matus Fabian694265d2016-08-10 01:55:36 -0700181typedef struct
182{
183 u8 is_add;
184 u32 local_sa_id;
185 u32 remote_sa_id;
186 ip4_address_t local_ip;
187 ip4_address_t remote_ip;
188} ipsec_add_del_ipsec_gre_tunnel_args_t;
189
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700190typedef enum
191{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700192 IPSEC_IF_SET_KEY_TYPE_NONE,
193 IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO,
194 IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO,
195 IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG,
196 IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG,
197} ipsec_if_set_key_type_t;
198
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700199typedef struct
200{
201 u32 id;
202 i32 priority;
203 u8 is_outbound;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700204
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700205 // Selector
206 u8 is_ipv6;
207 ip46_address_range_t laddr;
208 ip46_address_range_t raddr;
209 u8 protocol;
210 port_range_t lport;
211 port_range_t rport;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700212
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700213 // Policy
214 u8 policy;
215 u32 sa_id;
216 u32 sa_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700217
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700218 // Counter
219 vlib_counter_t counter;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700220} ipsec_policy_t;
221
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700222typedef struct
223{
224 u32 id;
225 /* pool of policies */
226 ipsec_policy_t *policies;
227 /* vectors of policy indices */
228 u32 *ipv4_outbound_policies;
229 u32 *ipv6_outbound_policies;
230 u32 *ipv4_inbound_protect_policy_indices;
231 u32 *ipv4_inbound_policy_discard_and_bypass_indices;
232 u32 *ipv6_inbound_protect_policy_indices;
233 u32 *ipv6_inbound_policy_discard_and_bypass_indices;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700234} ipsec_spd_t;
235
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700236typedef struct
237{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700238 u32 spd_index;
239} ip4_ipsec_config_t;
240
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700241typedef struct
242{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700243 u32 spd_index;
244} ip6_ipsec_config_t;
245
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700246typedef struct
247{
Dave Baracheb987d32018-05-03 08:26:39 -0400248 /* Required for pool_get_aligned */
249 CLIB_CACHE_LINE_ALIGN_MARK (cacheline0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250 u32 input_sa_index;
251 u32 output_sa_index;
252 u32 hw_if_index;
Matthew Smith8e1039a2018-04-12 07:32:56 -0500253 u32 show_instance;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700254} ipsec_tunnel_if_t;
255
Klement Sekerab4d30532018-11-08 13:00:02 +0100256typedef clib_error_t *(*add_del_sa_sess_cb_t) (u32 sa_index, u8 is_add);
257typedef clib_error_t *(*check_support_cb_t) (ipsec_sa_t * sa);
258
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700259typedef struct
260{
Klement Sekerab4d30532018-11-08 13:00:02 +0100261 u8 *name;
262 /* add/del callback */
263 add_del_sa_sess_cb_t add_del_sa_sess_cb;
264 /* check support function */
265 check_support_cb_t check_support_cb;
266 u32 ah4_encrypt_node_index;
267 u32 ah4_decrypt_node_index;
268 u32 ah4_encrypt_next_index;
269 u32 ah4_decrypt_next_index;
270 u32 ah6_encrypt_node_index;
271 u32 ah6_decrypt_node_index;
272 u32 ah6_encrypt_next_index;
273 u32 ah6_decrypt_next_index;
274} ipsec_ah_backend_t;
275
276typedef struct
277{
278 u8 *name;
279 /* add/del callback */
280 add_del_sa_sess_cb_t add_del_sa_sess_cb;
281 /* check support function */
282 check_support_cb_t check_support_cb;
283 u32 esp4_encrypt_node_index;
284 u32 esp4_decrypt_node_index;
285 u32 esp4_encrypt_next_index;
286 u32 esp4_decrypt_next_index;
287 u32 esp6_encrypt_node_index;
288 u32 esp6_decrypt_node_index;
289 u32 esp6_encrypt_next_index;
290 u32 esp6_decrypt_next_index;
291} ipsec_esp_backend_t;
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000292
293typedef struct
294{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700295 /* pool of tunnel instances */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700296 ipsec_spd_t *spds;
297 ipsec_sa_t *sad;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700298
299 /* pool of tunnel interfaces */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700300 ipsec_tunnel_if_t *tunnel_interfaces;
301 u32 *free_tunnel_if_indices;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700302
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700303 u32 **empty_buffers;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700304
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700305 uword *tunnel_index_by_key;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700306
307 /* convenience */
308 vlib_main_t *vlib_main;
309 vnet_main_t *vnet_main;
310
311 /* next node indices */
312 u32 feature_next_node_index[32];
313
314 /* hashes */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700315 uword *spd_index_by_spd_id;
316 uword *spd_index_by_sw_if_index;
317 uword *sa_index_by_sa_id;
318 uword *ipsec_if_pool_index_by_key;
Matthew Smith8e1039a2018-04-12 07:32:56 -0500319 uword *ipsec_if_real_dev_by_show_dev;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700320
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700321 /* node indices */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700322 u32 error_drop_node_index;
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200323 u32 esp4_encrypt_node_index;
324 u32 esp4_decrypt_node_index;
325 u32 ah4_encrypt_node_index;
326 u32 ah4_decrypt_node_index;
327 u32 esp6_encrypt_node_index;
328 u32 esp6_decrypt_node_index;
329 u32 ah6_encrypt_node_index;
330 u32 ah6_decrypt_node_index;
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700331 /* next node indices */
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200332 u32 esp4_encrypt_next_index;
333 u32 esp4_decrypt_next_index;
334 u32 ah4_encrypt_next_index;
335 u32 ah4_decrypt_next_index;
336 u32 esp6_encrypt_next_index;
337 u32 esp6_decrypt_next_index;
338 u32 ah6_encrypt_next_index;
339 u32 ah6_decrypt_next_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700340
Klement Sekerab4d30532018-11-08 13:00:02 +0100341 /* pool of ah backends */
342 ipsec_ah_backend_t *ah_backends;
343 /* pool of esp backends */
344 ipsec_esp_backend_t *esp_backends;
345 /* index of current ah backend */
346 u32 ah_current_backend;
347 /* index of current esp backend */
348 u32 esp_current_backend;
349 /* index of default ah backend */
350 u32 ah_default_backend;
351 /* index of default esp backend */
352 u32 esp_default_backend;
Klement Sekeraee52d872018-06-07 19:36:07 +0200353
354 /* helper for sort function */
355 ipsec_spd_t *spd_to_sort;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700356} ipsec_main_t;
357
Dave Wallace71612d62017-10-24 01:32:41 -0400358extern ipsec_main_t ipsec_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700359
Klement Sekerab4d30532018-11-08 13:00:02 +0100360clib_error_t *ipsec_add_del_sa_sess_cb (ipsec_main_t * im, u32 sa_index,
361 u8 is_add);
362
363clib_error_t *ipsec_check_support_cb (ipsec_main_t * im, ipsec_sa_t * sa);
364
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200365extern vlib_node_registration_t esp4_encrypt_node;
366extern vlib_node_registration_t esp4_decrypt_node;
367extern vlib_node_registration_t ah4_encrypt_node;
368extern vlib_node_registration_t ah4_decrypt_node;
369extern vlib_node_registration_t esp6_encrypt_node;
370extern vlib_node_registration_t esp6_decrypt_node;
371extern vlib_node_registration_t ah6_encrypt_node;
372extern vlib_node_registration_t ah6_decrypt_node;
Jean-Mickael Guerin8941ec22016-03-04 14:14:21 +0100373extern vlib_node_registration_t ipsec_if_input_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700374
Ed Warnickecb9cada2015-12-08 15:45:58 -0700375/*
376 * functions
377 */
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700378int ipsec_set_interface_spd (vlib_main_t * vm, u32 sw_if_index, u32 spd_id,
379 int is_add);
380int ipsec_add_del_spd (vlib_main_t * vm, u32 spd_id, int is_add);
381int ipsec_add_del_policy (vlib_main_t * vm, ipsec_policy_t * policy,
382 int is_add);
Radu Nicolau717de092018-08-03 10:37:24 +0100383int 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 -0700384int ipsec_set_sa_key (vlib_main_t * vm, ipsec_sa_t * sa_update);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700385
Matus Fabian694265d2016-08-10 01:55:36 -0700386u32 ipsec_get_sa_index_by_sa_id (u32 sa_id);
Matthew Smithca514fd2017-10-12 12:06:59 -0500387u8 ipsec_is_sa_used (u32 sa_index);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700388u8 *format_ipsec_policy_action (u8 * s, va_list * args);
389u8 *format_ipsec_crypto_alg (u8 * s, va_list * args);
390u8 *format_ipsec_integ_alg (u8 * s, va_list * args);
391u8 *format_ipsec_replay_window (u8 * s, va_list * args);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700392uword unformat_ipsec_policy_action (unformat_input_t * input, va_list * args);
393uword unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args);
394uword unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args);
395
Matthew Smithe04d09d2017-05-14 21:47:18 -0500396int ipsec_add_del_tunnel_if_internal (vnet_main_t * vnm,
397 ipsec_add_del_tunnel_args_t * args,
398 u32 * sw_if_index);
Matthew Smith2838a232016-06-21 16:05:09 -0500399int ipsec_add_del_tunnel_if (ipsec_add_del_tunnel_args_t * args);
Matus Fabian694265d2016-08-10 01:55:36 -0700400int ipsec_add_del_ipsec_gre_tunnel (vnet_main_t * vnm,
401 ipsec_add_del_ipsec_gre_tunnel_args_t *
402 args);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700403int ipsec_set_interface_key (vnet_main_t * vnm, u32 hw_if_index,
404 ipsec_if_set_key_type_t type, u8 alg, u8 * key);
Matthew Smithca514fd2017-10-12 12:06:59 -0500405int ipsec_set_interface_sa (vnet_main_t * vnm, u32 hw_if_index, u32 sa_id,
406 u8 is_outbound);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700407
Ed Warnickecb9cada2015-12-08 15:45:58 -0700408/*
409 * inline functions
410 */
411
412always_inline void
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700413ipsec_alloc_empty_buffers (vlib_main_t * vm, ipsec_main_t * im)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700414{
Damjan Marion067cd622018-07-11 12:47:43 +0200415 u32 thread_index = vm->thread_index;
Damjan Marion586afd72017-04-05 19:18:20 +0200416 uword l = vec_len (im->empty_buffers[thread_index]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700417 uword n_alloc = 0;
418
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700419 if (PREDICT_FALSE (l < VLIB_FRAME_SIZE))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700420 {
Damjan Marion586afd72017-04-05 19:18:20 +0200421 if (!im->empty_buffers[thread_index])
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700422 {
Damjan Marion586afd72017-04-05 19:18:20 +0200423 vec_alloc (im->empty_buffers[thread_index], 2 * VLIB_FRAME_SIZE);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700424 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700425
Damjan Marion586afd72017-04-05 19:18:20 +0200426 n_alloc = vlib_buffer_alloc (vm, im->empty_buffers[thread_index] + l,
Damjan Marion67655492016-11-15 12:50:28 +0100427 2 * VLIB_FRAME_SIZE - l);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700428
Damjan Marion586afd72017-04-05 19:18:20 +0200429 _vec_len (im->empty_buffers[thread_index]) = l + n_alloc;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700430 }
431}
432
Matus Fabian08a6f012016-11-15 06:08:51 -0800433static_always_inline u32
434get_next_output_feature_node_index (vlib_buffer_t * b,
435 vlib_node_runtime_t * nr)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700436{
Matus Fabian08a6f012016-11-15 06:08:51 -0800437 u32 next;
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700438 vlib_main_t *vm = vlib_get_main ();
Matus Fabian08a6f012016-11-15 06:08:51 -0800439 vlib_node_t *node = vlib_get_node (vm, nr->node_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700440
Damjan Marion7d98a122018-07-19 20:42:08 +0200441 vnet_feature_next (&next, b);
Matus Fabian08a6f012016-11-15 06:08:51 -0800442 return node->next_nodes[next];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700443}
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700444
Klement Sekerab4d30532018-11-08 13:00:02 +0100445u32 ipsec_register_ah_backend (vlib_main_t * vm, ipsec_main_t * im,
446 const char *name,
447 const char *ah4_encrypt_node_name,
448 const char *ah4_decrypt_node_name,
449 const char *ah6_encrypt_node_name,
450 const char *ah6_decrypt_node_name,
451 check_support_cb_t ah_check_support_cb,
452 add_del_sa_sess_cb_t ah_add_del_sa_sess_cb);
453
454u32 ipsec_register_esp_backend (vlib_main_t * vm, ipsec_main_t * im,
455 const char *name,
456 const char *esp4_encrypt_node_name,
457 const char *esp4_decrypt_node_name,
458 const char *esp6_encrypt_node_name,
459 const char *esp6_decrypt_node_name,
460 check_support_cb_t esp_check_support_cb,
461 add_del_sa_sess_cb_t esp_add_del_sa_sess_cb);
462
463int ipsec_select_ah_backend (ipsec_main_t * im, u32 ah_backend_idx);
464int ipsec_select_esp_backend (ipsec_main_t * im, u32 esp_backend_idx);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000465#endif /* __IPSEC_H__ */
466
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700467/*
468 * fd.io coding-style-patch-verification: ON
469 *
470 * Local Variables:
471 * eval: (c-set-style "gnu")
472 * End:
473 */