blob: 6b31926be4f2e56ce5c415a2f89477403c7fbd8d [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
Neale Ranns999c8ee2019-02-01 03:31:24 -08002 * ipsec.c : IPSEC module functions
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 *
4 * Copyright (c) 2015 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <vnet/vnet.h>
19#include <vnet/api_errno.h>
20#include <vnet/ip/ip.h>
21#include <vnet/interface.h>
Klement Sekera4b089f22018-04-17 18:04:57 +020022#include <vnet/udp/udp.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070023
24#include <vnet/ipsec/ipsec.h>
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000025#include <vnet/ipsec/esp.h>
“mukeshyadav1984”430ac932017-11-23 02:39:33 -080026#include <vnet/ipsec/ah.h>
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000027
Dave Wallace71612d62017-10-24 01:32:41 -040028ipsec_main_t ipsec_main;
Fan Zhangf5395782020-04-29 14:00:03 +010029esp_async_post_next_t esp_encrypt_async_next;
30esp_async_post_next_t esp_decrypt_async_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -070031
32static clib_error_t *
Klement Sekera4fd5a9d2019-01-30 11:11:23 +010033ipsec_check_ah_support (ipsec_sa_t * sa)
34{
Neale Rannsece2ae02019-06-21 12:44:11 +000035 ipsec_main_t *im = &ipsec_main;
36
Klement Sekera4fd5a9d2019-01-30 11:11:23 +010037 if (sa->integ_alg == IPSEC_INTEG_ALG_NONE)
38 return clib_error_return (0, "unsupported none integ-alg");
Neale Rannsece2ae02019-06-21 12:44:11 +000039
40 if (!vnet_crypto_is_set_handler (im->integ_algs[sa->integ_alg].alg))
41 return clib_error_return (0, "No crypto engine support for %U",
42 format_ipsec_integ_alg, sa->integ_alg);
43
Klement Sekera4fd5a9d2019-01-30 11:11:23 +010044 return 0;
45}
46
47static clib_error_t *
48ipsec_check_esp_support (ipsec_sa_t * sa)
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +000049{
Neale Rannsece2ae02019-06-21 12:44:11 +000050 ipsec_main_t *im = &ipsec_main;
51
52 if (IPSEC_INTEG_ALG_NONE != sa->integ_alg)
53 {
54 if (!vnet_crypto_is_set_handler (im->integ_algs[sa->integ_alg].alg))
55 return clib_error_return (0, "No crypto engine support for %U",
56 format_ipsec_integ_alg, sa->integ_alg);
57 }
58 if (IPSEC_CRYPTO_ALG_NONE != sa->crypto_alg)
59 {
60 if (!vnet_crypto_is_set_handler (im->crypto_algs[sa->crypto_alg].alg))
61 return clib_error_return (0, "No crypto engine support for %U",
62 format_ipsec_crypto_alg, sa->crypto_alg);
63 }
64
65 return (0);
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +000066}
67
Klement Sekerab4d30532018-11-08 13:00:02 +010068clib_error_t *
69ipsec_add_del_sa_sess_cb (ipsec_main_t * im, u32 sa_index, u8 is_add)
70{
71 ipsec_ah_backend_t *ah =
72 pool_elt_at_index (im->ah_backends, im->ah_current_backend);
73 if (ah->add_del_sa_sess_cb)
74 {
75 clib_error_t *err = ah->add_del_sa_sess_cb (sa_index, is_add);
76 if (err)
77 return err;
78 }
79 ipsec_esp_backend_t *esp =
80 pool_elt_at_index (im->esp_backends, im->esp_current_backend);
81 if (esp->add_del_sa_sess_cb)
82 {
83 clib_error_t *err = esp->add_del_sa_sess_cb (sa_index, is_add);
84 if (err)
85 return err;
86 }
87 return 0;
88}
89
90clib_error_t *
91ipsec_check_support_cb (ipsec_main_t * im, ipsec_sa_t * sa)
92{
93 clib_error_t *error = 0;
Matthew Smith461caa52018-12-21 11:53:16 -060094
95 if (PREDICT_FALSE (sa->protocol == IPSEC_PROTOCOL_AH))
96 {
97 ipsec_ah_backend_t *ah =
98 pool_elt_at_index (im->ah_backends, im->ah_current_backend);
99 ASSERT (ah->check_support_cb);
100 error = ah->check_support_cb (sa);
101 }
102 else
103 {
104 ipsec_esp_backend_t *esp =
105 pool_elt_at_index (im->esp_backends, im->esp_current_backend);
106 ASSERT (esp->check_support_cb);
107 error = esp->check_support_cb (sa);
108 }
Klement Sekerab4d30532018-11-08 13:00:02 +0100109 return error;
110}
111
112
113static void
114ipsec_add_node (vlib_main_t * vm, const char *node_name,
115 const char *prev_node_name, u32 * out_node_index,
116 u32 * out_next_index)
117{
118 vlib_node_t *prev_node, *node;
119 prev_node = vlib_get_node_by_name (vm, (u8 *) prev_node_name);
120 ASSERT (prev_node);
121 node = vlib_get_node_by_name (vm, (u8 *) node_name);
122 ASSERT (node);
123 *out_node_index = node->index;
124 *out_next_index = vlib_node_add_next (vm, prev_node->index, node->index);
125}
126
Matthew Smith401aedf2019-07-08 14:45:04 -0500127void
Neale Rannse8915fc2019-04-23 20:57:55 -0400128ipsec_add_feature (const char *arc_name,
129 const char *node_name, u32 * out_feature_index)
130{
131 u8 arc;
132
133 arc = vnet_get_feature_arc_index (arc_name);
Neale Ranns02245142019-05-13 23:07:43 -0700134 ASSERT (arc != (u8) ~ 0);
Neale Rannse8915fc2019-04-23 20:57:55 -0400135 *out_feature_index = vnet_get_feature_index (arc, node_name);
136}
137
Klement Sekerab4d30532018-11-08 13:00:02 +0100138u32
139ipsec_register_ah_backend (vlib_main_t * vm, ipsec_main_t * im,
140 const char *name,
141 const char *ah4_encrypt_node_name,
142 const char *ah4_decrypt_node_name,
143 const char *ah6_encrypt_node_name,
144 const char *ah6_decrypt_node_name,
145 check_support_cb_t ah_check_support_cb,
146 add_del_sa_sess_cb_t ah_add_del_sa_sess_cb)
147{
148 ipsec_ah_backend_t *b;
149 pool_get (im->ah_backends, b);
Kingwel Xie561d1ca2019-03-05 22:56:17 -0500150 b->name = format (0, "%s%c", name, 0);
Klement Sekerab4d30532018-11-08 13:00:02 +0100151
Pierre Pfister057b3562018-12-10 17:01:01 +0100152 ipsec_add_node (vm, ah4_encrypt_node_name, "ipsec4-output-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100153 &b->ah4_encrypt_node_index, &b->ah4_encrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100154 ipsec_add_node (vm, ah4_decrypt_node_name, "ipsec4-input-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100155 &b->ah4_decrypt_node_index, &b->ah4_decrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100156 ipsec_add_node (vm, ah6_encrypt_node_name, "ipsec6-output-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100157 &b->ah6_encrypt_node_index, &b->ah6_encrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100158 ipsec_add_node (vm, ah6_decrypt_node_name, "ipsec6-input-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100159 &b->ah6_decrypt_node_index, &b->ah6_decrypt_next_index);
160
161 b->check_support_cb = ah_check_support_cb;
162 b->add_del_sa_sess_cb = ah_add_del_sa_sess_cb;
163 return b - im->ah_backends;
164}
165
166u32
167ipsec_register_esp_backend (vlib_main_t * vm, ipsec_main_t * im,
168 const char *name,
169 const char *esp4_encrypt_node_name,
Neale Rannse8915fc2019-04-23 20:57:55 -0400170 const char *esp4_encrypt_node_tun_name,
Klement Sekerab4d30532018-11-08 13:00:02 +0100171 const char *esp4_decrypt_node_name,
Neale Ranns7ec120e2020-01-21 04:58:02 +0000172 const char *esp4_decrypt_tun_node_name,
Klement Sekerab4d30532018-11-08 13:00:02 +0100173 const char *esp6_encrypt_node_name,
Neale Rannse8915fc2019-04-23 20:57:55 -0400174 const char *esp6_encrypt_node_tun_name,
Klement Sekerab4d30532018-11-08 13:00:02 +0100175 const char *esp6_decrypt_node_name,
Neale Ranns7ec120e2020-01-21 04:58:02 +0000176 const char *esp6_decrypt_tun_node_name,
Klement Sekerab4d30532018-11-08 13:00:02 +0100177 check_support_cb_t esp_check_support_cb,
Fan Zhangf5395782020-04-29 14:00:03 +0100178 add_del_sa_sess_cb_t esp_add_del_sa_sess_cb,
179 enable_disable_cb_t enable_disable_cb)
Klement Sekerab4d30532018-11-08 13:00:02 +0100180{
181 ipsec_esp_backend_t *b;
Neale Rannse8915fc2019-04-23 20:57:55 -0400182
Klement Sekerab4d30532018-11-08 13:00:02 +0100183 pool_get (im->esp_backends, b);
Kingwel Xie561d1ca2019-03-05 22:56:17 -0500184 b->name = format (0, "%s%c", name, 0);
Klement Sekerab4d30532018-11-08 13:00:02 +0100185
Pierre Pfister057b3562018-12-10 17:01:01 +0100186 ipsec_add_node (vm, esp4_encrypt_node_name, "ipsec4-output-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100187 &b->esp4_encrypt_node_index, &b->esp4_encrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100188 ipsec_add_node (vm, esp4_decrypt_node_name, "ipsec4-input-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100189 &b->esp4_decrypt_node_index, &b->esp4_decrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100190 ipsec_add_node (vm, esp6_encrypt_node_name, "ipsec6-output-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100191 &b->esp6_encrypt_node_index, &b->esp6_encrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100192 ipsec_add_node (vm, esp6_decrypt_node_name, "ipsec6-input-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100193 &b->esp6_decrypt_node_index, &b->esp6_decrypt_next_index);
Neale Ranns7ec120e2020-01-21 04:58:02 +0000194 ipsec_add_node (vm, esp4_decrypt_tun_node_name, "ipsec4-tun-input",
195 &b->esp4_decrypt_tun_node_index,
196 &b->esp4_decrypt_tun_next_index);
197 ipsec_add_node (vm, esp6_decrypt_tun_node_name, "ipsec6-tun-input",
198 &b->esp6_decrypt_tun_node_index,
199 &b->esp6_decrypt_tun_next_index);
Klement Sekerab4d30532018-11-08 13:00:02 +0100200
Neale Rannse8915fc2019-04-23 20:57:55 -0400201 ipsec_add_feature ("ip4-output", esp4_encrypt_node_tun_name,
Neale Ranns02950402019-12-20 00:54:57 +0000202 &b->esp44_encrypt_tun_feature_index);
203 ipsec_add_feature ("ip4-output", esp6_encrypt_node_tun_name,
204 &b->esp46_encrypt_tun_feature_index);
Neale Rannse8915fc2019-04-23 20:57:55 -0400205 ipsec_add_feature ("ip6-output", esp6_encrypt_node_tun_name,
Neale Ranns02950402019-12-20 00:54:57 +0000206 &b->esp66_encrypt_tun_feature_index);
207 ipsec_add_feature ("ip6-output", esp4_encrypt_node_tun_name,
208 &b->esp64_encrypt_tun_feature_index);
Neale Rannse8915fc2019-04-23 20:57:55 -0400209
Klement Sekerab4d30532018-11-08 13:00:02 +0100210 b->check_support_cb = esp_check_support_cb;
211 b->add_del_sa_sess_cb = esp_add_del_sa_sess_cb;
Fan Zhangf5395782020-04-29 14:00:03 +0100212 b->enable_disable_cb = enable_disable_cb;
213
Klement Sekerab4d30532018-11-08 13:00:02 +0100214 return b - im->esp_backends;
215}
216
Neale Rannse8915fc2019-04-23 20:57:55 -0400217clib_error_t *
218ipsec_rsc_in_use (ipsec_main_t * im)
Neale Rannsb4cfd552019-02-13 02:08:06 -0800219{
Neale Rannse8915fc2019-04-23 20:57:55 -0400220 /* return an error is crypto resource are in use */
221 if (pool_elts (im->sad) > 0)
222 return clib_error_return (0,
223 "%d SA entries configured",
224 pool_elts (im->sad));
Neale Rannsb4cfd552019-02-13 02:08:06 -0800225
Neale Rannse8915fc2019-04-23 20:57:55 -0400226 return (NULL);
Neale Rannsb4cfd552019-02-13 02:08:06 -0800227}
228
Klement Sekerab4d30532018-11-08 13:00:02 +0100229int
230ipsec_select_ah_backend (ipsec_main_t * im, u32 backend_idx)
231{
Neale Rannse8915fc2019-04-23 20:57:55 -0400232 if (ipsec_rsc_in_use (im))
233 return VNET_API_ERROR_RSRC_IN_USE;
234
235 if (pool_is_free_index (im->ah_backends, backend_idx))
236 return VNET_API_ERROR_INVALID_VALUE;
237
Klement Sekerab4d30532018-11-08 13:00:02 +0100238 ipsec_ah_backend_t *b = pool_elt_at_index (im->ah_backends, backend_idx);
239 im->ah_current_backend = backend_idx;
240 im->ah4_encrypt_node_index = b->ah4_encrypt_node_index;
241 im->ah4_decrypt_node_index = b->ah4_decrypt_node_index;
242 im->ah4_encrypt_next_index = b->ah4_encrypt_next_index;
243 im->ah4_decrypt_next_index = b->ah4_decrypt_next_index;
244 im->ah6_encrypt_node_index = b->ah6_encrypt_node_index;
245 im->ah6_decrypt_node_index = b->ah6_decrypt_node_index;
246 im->ah6_encrypt_next_index = b->ah6_encrypt_next_index;
247 im->ah6_decrypt_next_index = b->ah6_decrypt_next_index;
Neale Rannsb4cfd552019-02-13 02:08:06 -0800248
Klement Sekerab4d30532018-11-08 13:00:02 +0100249 return 0;
250}
251
252int
253ipsec_select_esp_backend (ipsec_main_t * im, u32 backend_idx)
254{
Neale Rannse8915fc2019-04-23 20:57:55 -0400255 if (ipsec_rsc_in_use (im))
256 return VNET_API_ERROR_RSRC_IN_USE;
257
258 if (pool_is_free_index (im->esp_backends, backend_idx))
259 return VNET_API_ERROR_INVALID_VALUE;
260
Fan Zhangf5395782020-04-29 14:00:03 +0100261 /* disable current backend */
262 if (im->esp_current_backend != ~0)
263 {
264 ipsec_esp_backend_t *cb = pool_elt_at_index (im->esp_backends,
265 im->esp_current_backend);
266 if (cb->enable_disable_cb)
267 {
268 if ((cb->enable_disable_cb) (0) != 0)
269 return -1;
270 }
271 }
272
Klement Sekerab4d30532018-11-08 13:00:02 +0100273 ipsec_esp_backend_t *b = pool_elt_at_index (im->esp_backends, backend_idx);
274 im->esp_current_backend = backend_idx;
275 im->esp4_encrypt_node_index = b->esp4_encrypt_node_index;
276 im->esp4_decrypt_node_index = b->esp4_decrypt_node_index;
277 im->esp4_encrypt_next_index = b->esp4_encrypt_next_index;
278 im->esp4_decrypt_next_index = b->esp4_decrypt_next_index;
279 im->esp6_encrypt_node_index = b->esp6_encrypt_node_index;
280 im->esp6_decrypt_node_index = b->esp6_decrypt_node_index;
281 im->esp6_encrypt_next_index = b->esp6_encrypt_next_index;
282 im->esp6_decrypt_next_index = b->esp6_decrypt_next_index;
Neale Ranns7ec120e2020-01-21 04:58:02 +0000283 im->esp4_decrypt_tun_node_index = b->esp4_decrypt_tun_node_index;
284 im->esp4_decrypt_tun_next_index = b->esp4_decrypt_tun_next_index;
285 im->esp6_decrypt_tun_node_index = b->esp6_decrypt_tun_node_index;
286 im->esp6_decrypt_tun_next_index = b->esp6_decrypt_tun_next_index;
Neale Rannsb4cfd552019-02-13 02:08:06 -0800287
Neale Ranns02950402019-12-20 00:54:57 +0000288 im->esp44_encrypt_tun_feature_index = b->esp44_encrypt_tun_feature_index;
289 im->esp64_encrypt_tun_feature_index = b->esp64_encrypt_tun_feature_index;
290 im->esp46_encrypt_tun_feature_index = b->esp46_encrypt_tun_feature_index;
291 im->esp66_encrypt_tun_feature_index = b->esp66_encrypt_tun_feature_index;
Neale Rannse8915fc2019-04-23 20:57:55 -0400292
Fan Zhangf5395782020-04-29 14:00:03 +0100293 if (b->enable_disable_cb)
294 {
295 if ((b->enable_disable_cb) (1) != 0)
296 return -1;
297 }
Klement Sekerab4d30532018-11-08 13:00:02 +0100298 return 0;
299}
300
Fan Zhangf5395782020-04-29 14:00:03 +0100301void
302ipsec_set_async_mode (u32 is_enabled)
303{
304 ipsec_main_t *im = &ipsec_main;
305 ipsec_sa_t *sa;
306
307 /* lock all SAs before change im->async_mode */
308 pool_foreach (sa, im->sad, (
309 {
310 fib_node_lock (&sa->node);
311 }));
312
313 im->async_mode = is_enabled;
314
315 /* change SA crypto op data before unlock them */
316 pool_foreach (sa, im->sad, (
317 {
318 sa->crypto_op_data = is_enabled ?
319 sa->async_op_data.data : sa->sync_op_data.data;
320 fib_node_unlock (&sa->node);
321 }));
322}
323
324static void
325crypto_engine_backend_register_post_node (vlib_main_t * vm)
326{
327 esp_async_post_next_t *eit;
328 esp_async_post_next_t *dit;
329
330 eit = &esp_encrypt_async_next;
331 eit->esp4_post_next =
332 vnet_crypto_register_post_node (vm, "esp4-encrypt-post");
333 eit->esp6_post_next =
334 vnet_crypto_register_post_node (vm, "esp6-encrypt-post");
335 eit->esp4_tun_post_next =
336 vnet_crypto_register_post_node (vm, "esp4-encrypt-tun-post");
337 eit->esp6_tun_post_next =
338 vnet_crypto_register_post_node (vm, "esp6-encrypt-tun-post");
339
340 dit = &esp_decrypt_async_next;
341 dit->esp4_post_next =
342 vnet_crypto_register_post_node (vm, "esp4-decrypt-post");
343 dit->esp6_post_next =
344 vnet_crypto_register_post_node (vm, "esp6-decrypt-post");
345 dit->esp4_tun_post_next =
346 vnet_crypto_register_post_node (vm, "esp4-decrypt-tun-post");
347 dit->esp6_tun_post_next =
348 vnet_crypto_register_post_node (vm, "esp6-decrypt-tun-post");
349}
350
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000351static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700352ipsec_init (vlib_main_t * vm)
353{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700354 clib_error_t *error;
355 ipsec_main_t *im = &ipsec_main;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100356 ipsec_main_crypto_alg_t *a;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700357
Dave Barach0dd91652019-05-05 13:34:28 -0400358 /* Backend registration requires the feature arcs to be set up */
359 if ((error = vlib_call_init_function (vm, vnet_feature_init)))
360 return (error);
361
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700362 im->vnet_main = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700363 im->vlib_main = vm;
364
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700365 im->spd_index_by_spd_id = hash_create (0, sizeof (uword));
366 im->sa_index_by_sa_id = hash_create (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700367 im->spd_index_by_sw_if_index = hash_create (0, sizeof (uword));
368
Klement Sekerab4d30532018-11-08 13:00:02 +0100369 vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700370 ASSERT (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700371 im->error_drop_node_index = node->index;
372
Fan Zhangf5395782020-04-29 14:00:03 +0100373 im->ah_current_backend = ~0;
374 im->esp_current_backend = ~0;
375
Neale Rannsd1a5b2d2019-05-16 17:09:28 +0000376 u32 idx = ipsec_register_ah_backend (vm, im, "crypto engine backend",
Klement Sekerab4d30532018-11-08 13:00:02 +0100377 "ah4-encrypt",
378 "ah4-decrypt",
379 "ah6-encrypt",
380 "ah6-decrypt",
Klement Sekera4fd5a9d2019-01-30 11:11:23 +0100381 ipsec_check_ah_support,
Klement Sekerab4d30532018-11-08 13:00:02 +0100382 NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700383
Klement Sekerab4d30532018-11-08 13:00:02 +0100384 im->ah_default_backend = idx;
385 int rv = ipsec_select_ah_backend (im, idx);
386 ASSERT (0 == rv);
387 (void) (rv); // avoid warning
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000388
Neale Rannsd1a5b2d2019-05-16 17:09:28 +0000389 idx = ipsec_register_esp_backend (vm, im, "crypto engine backend",
Klement Sekerab4d30532018-11-08 13:00:02 +0100390 "esp4-encrypt",
Neale Rannse8915fc2019-04-23 20:57:55 -0400391 "esp4-encrypt-tun",
Klement Sekerab4d30532018-11-08 13:00:02 +0100392 "esp4-decrypt",
Neale Ranns7ec120e2020-01-21 04:58:02 +0000393 "esp4-decrypt-tun",
Klement Sekerab4d30532018-11-08 13:00:02 +0100394 "esp6-encrypt",
Neale Rannse8915fc2019-04-23 20:57:55 -0400395 "esp6-encrypt-tun",
Klement Sekerab4d30532018-11-08 13:00:02 +0100396 "esp6-decrypt",
Neale Ranns7ec120e2020-01-21 04:58:02 +0000397 "esp6-decrypt-tun",
Fan Zhangf5395782020-04-29 14:00:03 +0100398 ipsec_check_esp_support,
399 NULL, crypto_dispatch_enable_disable);
Klement Sekerab4d30532018-11-08 13:00:02 +0100400 im->esp_default_backend = idx;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800401
Klement Sekerab4d30532018-11-08 13:00:02 +0100402 rv = ipsec_select_esp_backend (im, idx);
403 ASSERT (0 == rv);
404 (void) (rv); // avoid warning
Ed Warnickecb9cada2015-12-08 15:45:58 -0700405
Ed Warnickecb9cada2015-12-08 15:45:58 -0700406 if ((error = vlib_call_init_function (vm, ipsec_cli_init)))
407 return error;
408
Damjan Marion91f17dc2019-03-18 18:59:25 +0100409 vec_validate (im->crypto_algs, IPSEC_CRYPTO_N_ALG - 1);
410
Neale Ranns2cdcd0c2019-08-27 12:26:14 +0000411 a = im->crypto_algs + IPSEC_CRYPTO_ALG_NONE;
412 a->enc_op_id = VNET_CRYPTO_OP_NONE;
413 a->dec_op_id = VNET_CRYPTO_OP_NONE;
414 a->alg = VNET_CRYPTO_ALG_NONE;
415 a->iv_size = 0;
416 a->block_size = 1;
417
Damjan Marion91f17dc2019-03-18 18:59:25 +0100418 a = im->crypto_algs + IPSEC_CRYPTO_ALG_DES_CBC;
Damjan Marion060bfb92019-03-29 13:47:54 +0100419 a->enc_op_id = VNET_CRYPTO_OP_DES_CBC_ENC;
420 a->dec_op_id = VNET_CRYPTO_OP_DES_CBC_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200421 a->alg = VNET_CRYPTO_ALG_DES_CBC;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100422 a->iv_size = a->block_size = 8;
423
424 a = im->crypto_algs + IPSEC_CRYPTO_ALG_3DES_CBC;
Damjan Marion060bfb92019-03-29 13:47:54 +0100425 a->enc_op_id = VNET_CRYPTO_OP_3DES_CBC_ENC;
426 a->dec_op_id = VNET_CRYPTO_OP_3DES_CBC_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200427 a->alg = VNET_CRYPTO_ALG_3DES_CBC;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100428 a->iv_size = a->block_size = 8;
429
430 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_128;
Damjan Marion060bfb92019-03-29 13:47:54 +0100431 a->enc_op_id = VNET_CRYPTO_OP_AES_128_CBC_ENC;
432 a->dec_op_id = VNET_CRYPTO_OP_AES_128_CBC_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200433 a->alg = VNET_CRYPTO_ALG_AES_128_CBC;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100434 a->iv_size = a->block_size = 16;
435
436 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_192;
Damjan Marion060bfb92019-03-29 13:47:54 +0100437 a->enc_op_id = VNET_CRYPTO_OP_AES_192_CBC_ENC;
438 a->dec_op_id = VNET_CRYPTO_OP_AES_192_CBC_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200439 a->alg = VNET_CRYPTO_ALG_AES_192_CBC;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100440 a->iv_size = a->block_size = 16;
441
442 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_256;
Damjan Marion060bfb92019-03-29 13:47:54 +0100443 a->enc_op_id = VNET_CRYPTO_OP_AES_256_CBC_ENC;
444 a->dec_op_id = VNET_CRYPTO_OP_AES_256_CBC_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200445 a->alg = VNET_CRYPTO_ALG_AES_256_CBC;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100446 a->iv_size = a->block_size = 16;
447
Neale Ranns47feb112019-04-11 15:14:07 +0000448 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_128;
449 a->enc_op_id = VNET_CRYPTO_OP_AES_128_GCM_ENC;
450 a->dec_op_id = VNET_CRYPTO_OP_AES_128_GCM_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200451 a->alg = VNET_CRYPTO_ALG_AES_128_GCM;
Damjan Marionf1ecb652020-02-10 19:21:14 +0100452 a->iv_size = 8;
453 a->block_size = 16;
Neale Ranns47feb112019-04-11 15:14:07 +0000454 a->icv_size = 16;
455
456 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_192;
457 a->enc_op_id = VNET_CRYPTO_OP_AES_192_GCM_ENC;
458 a->dec_op_id = VNET_CRYPTO_OP_AES_192_GCM_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200459 a->alg = VNET_CRYPTO_ALG_AES_192_GCM;
Damjan Marionf1ecb652020-02-10 19:21:14 +0100460 a->iv_size = 8;
461 a->block_size = 16;
Neale Ranns47feb112019-04-11 15:14:07 +0000462 a->icv_size = 16;
463
464 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_256;
465 a->enc_op_id = VNET_CRYPTO_OP_AES_256_GCM_ENC;
466 a->dec_op_id = VNET_CRYPTO_OP_AES_256_GCM_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200467 a->alg = VNET_CRYPTO_ALG_AES_256_GCM;
Damjan Marionf1ecb652020-02-10 19:21:14 +0100468 a->iv_size = 8;
469 a->block_size = 16;
Neale Ranns47feb112019-04-11 15:14:07 +0000470 a->icv_size = 16;
471
Damjan Marion91f17dc2019-03-18 18:59:25 +0100472 vec_validate (im->integ_algs, IPSEC_INTEG_N_ALG - 1);
473 ipsec_main_integ_alg_t *i;
474
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400475 i = &im->integ_algs[IPSEC_INTEG_ALG_MD5_96];
476 i->op_id = VNET_CRYPTO_OP_MD5_HMAC;
477 i->alg = VNET_CRYPTO_ALG_HMAC_MD5;
478 i->icv_size = 12;
479
Damjan Marion91f17dc2019-03-18 18:59:25 +0100480 i = &im->integ_algs[IPSEC_INTEG_ALG_SHA1_96];
Damjan Marion060bfb92019-03-29 13:47:54 +0100481 i->op_id = VNET_CRYPTO_OP_SHA1_HMAC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200482 i->alg = VNET_CRYPTO_ALG_HMAC_SHA1;
Damjan Marion7c22ff72019-04-04 12:25:44 +0200483 i->icv_size = 12;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100484
485 i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_96];
Damjan Marion060bfb92019-03-29 13:47:54 +0100486 i->op_id = VNET_CRYPTO_OP_SHA1_HMAC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200487 i->alg = VNET_CRYPTO_ALG_HMAC_SHA256;
Damjan Marion7c22ff72019-04-04 12:25:44 +0200488 i->icv_size = 12;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100489
490 i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_128];
Damjan Marion060bfb92019-03-29 13:47:54 +0100491 i->op_id = VNET_CRYPTO_OP_SHA256_HMAC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200492 i->alg = VNET_CRYPTO_ALG_HMAC_SHA256;
Damjan Marion7c22ff72019-04-04 12:25:44 +0200493 i->icv_size = 16;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100494
495 i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_384_192];
Damjan Marion060bfb92019-03-29 13:47:54 +0100496 i->op_id = VNET_CRYPTO_OP_SHA384_HMAC;
Damjan Marion4cb83812019-04-24 17:32:01 +0200497 i->alg = VNET_CRYPTO_ALG_HMAC_SHA384;
Damjan Marion7c22ff72019-04-04 12:25:44 +0200498 i->icv_size = 24;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100499
500 i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_512_256];
Damjan Marion060bfb92019-03-29 13:47:54 +0100501 i->op_id = VNET_CRYPTO_OP_SHA512_HMAC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200502 i->alg = VNET_CRYPTO_ALG_HMAC_SHA512;
Damjan Marion7c22ff72019-04-04 12:25:44 +0200503 i->icv_size = 32;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700504
Neale Ranns5ae793a2019-04-03 13:36:56 +0000505 vec_validate_aligned (im->ptd, vlib_num_workers (), CLIB_CACHE_LINE_BYTES);
Damjan Marionc59b9a22019-03-19 15:38:40 +0100506
Neale Rannsf62a8c02019-04-02 08:13:33 +0000507 im->ah4_enc_fq_index =
508 vlib_frame_queue_main_init (ah4_encrypt_node.index, 0);
509 im->ah4_dec_fq_index =
510 vlib_frame_queue_main_init (ah4_decrypt_node.index, 0);
511 im->ah6_enc_fq_index =
512 vlib_frame_queue_main_init (ah6_encrypt_node.index, 0);
513 im->ah6_dec_fq_index =
514 vlib_frame_queue_main_init (ah6_decrypt_node.index, 0);
515
516 im->esp4_enc_fq_index =
517 vlib_frame_queue_main_init (esp4_encrypt_node.index, 0);
518 im->esp4_dec_fq_index =
519 vlib_frame_queue_main_init (esp4_decrypt_node.index, 0);
520 im->esp6_enc_fq_index =
521 vlib_frame_queue_main_init (esp6_encrypt_node.index, 0);
522 im->esp6_dec_fq_index =
523 vlib_frame_queue_main_init (esp6_decrypt_node.index, 0);
524 im->esp4_enc_tun_fq_index =
525 vlib_frame_queue_main_init (esp4_encrypt_tun_node.index, 0);
526 im->esp6_enc_tun_fq_index =
527 vlib_frame_queue_main_init (esp6_encrypt_tun_node.index, 0);
528 im->esp4_dec_tun_fq_index =
529 vlib_frame_queue_main_init (esp4_decrypt_tun_node.index, 0);
530 im->esp6_dec_tun_fq_index =
531 vlib_frame_queue_main_init (esp6_decrypt_tun_node.index, 0);
532
Fan Zhangf5395782020-04-29 14:00:03 +0100533 im->async_mode = 0;
534 crypto_engine_backend_register_post_node (vm);
535
Ed Warnickecb9cada2015-12-08 15:45:58 -0700536 return 0;
537}
538
539VLIB_INIT_FUNCTION (ipsec_init);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700540
541/*
542 * fd.io coding-style-patch-verification: ON
543 *
544 * Local Variables:
545 * eval: (c-set-style "gnu")
546 * End:
547 */