blob: 0f4f282034949dc7023b8c751ec5bc799cf1aebc [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;
Ed Warnickecb9cada2015-12-08 15:45:58 -070029
30static clib_error_t *
Klement Sekera4fd5a9d2019-01-30 11:11:23 +010031ipsec_check_ah_support (ipsec_sa_t * sa)
32{
Neale Rannsece2ae02019-06-21 12:44:11 +000033 ipsec_main_t *im = &ipsec_main;
34
Klement Sekera4fd5a9d2019-01-30 11:11:23 +010035 if (sa->integ_alg == IPSEC_INTEG_ALG_NONE)
36 return clib_error_return (0, "unsupported none integ-alg");
Neale Rannsece2ae02019-06-21 12:44:11 +000037
38 if (!vnet_crypto_is_set_handler (im->integ_algs[sa->integ_alg].alg))
39 return clib_error_return (0, "No crypto engine support for %U",
40 format_ipsec_integ_alg, sa->integ_alg);
41
Klement Sekera4fd5a9d2019-01-30 11:11:23 +010042 return 0;
43}
44
45static clib_error_t *
46ipsec_check_esp_support (ipsec_sa_t * sa)
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +000047{
Neale Rannsece2ae02019-06-21 12:44:11 +000048 ipsec_main_t *im = &ipsec_main;
49
50 if (IPSEC_INTEG_ALG_NONE != sa->integ_alg)
51 {
52 if (!vnet_crypto_is_set_handler (im->integ_algs[sa->integ_alg].alg))
53 return clib_error_return (0, "No crypto engine support for %U",
54 format_ipsec_integ_alg, sa->integ_alg);
55 }
56 if (IPSEC_CRYPTO_ALG_NONE != sa->crypto_alg)
57 {
58 if (!vnet_crypto_is_set_handler (im->crypto_algs[sa->crypto_alg].alg))
59 return clib_error_return (0, "No crypto engine support for %U",
60 format_ipsec_crypto_alg, sa->crypto_alg);
61 }
62
63 return (0);
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +000064}
65
Klement Sekerab4d30532018-11-08 13:00:02 +010066clib_error_t *
67ipsec_add_del_sa_sess_cb (ipsec_main_t * im, u32 sa_index, u8 is_add)
68{
69 ipsec_ah_backend_t *ah =
70 pool_elt_at_index (im->ah_backends, im->ah_current_backend);
71 if (ah->add_del_sa_sess_cb)
72 {
73 clib_error_t *err = ah->add_del_sa_sess_cb (sa_index, is_add);
74 if (err)
75 return err;
76 }
77 ipsec_esp_backend_t *esp =
78 pool_elt_at_index (im->esp_backends, im->esp_current_backend);
79 if (esp->add_del_sa_sess_cb)
80 {
81 clib_error_t *err = esp->add_del_sa_sess_cb (sa_index, is_add);
82 if (err)
83 return err;
84 }
85 return 0;
86}
87
88clib_error_t *
89ipsec_check_support_cb (ipsec_main_t * im, ipsec_sa_t * sa)
90{
91 clib_error_t *error = 0;
Matthew Smith461caa52018-12-21 11:53:16 -060092
93 if (PREDICT_FALSE (sa->protocol == IPSEC_PROTOCOL_AH))
94 {
95 ipsec_ah_backend_t *ah =
96 pool_elt_at_index (im->ah_backends, im->ah_current_backend);
97 ASSERT (ah->check_support_cb);
98 error = ah->check_support_cb (sa);
99 }
100 else
101 {
102 ipsec_esp_backend_t *esp =
103 pool_elt_at_index (im->esp_backends, im->esp_current_backend);
104 ASSERT (esp->check_support_cb);
105 error = esp->check_support_cb (sa);
106 }
Klement Sekerab4d30532018-11-08 13:00:02 +0100107 return error;
108}
109
110
111static void
112ipsec_add_node (vlib_main_t * vm, const char *node_name,
113 const char *prev_node_name, u32 * out_node_index,
114 u32 * out_next_index)
115{
116 vlib_node_t *prev_node, *node;
117 prev_node = vlib_get_node_by_name (vm, (u8 *) prev_node_name);
118 ASSERT (prev_node);
119 node = vlib_get_node_by_name (vm, (u8 *) node_name);
120 ASSERT (node);
121 *out_node_index = node->index;
122 *out_next_index = vlib_node_add_next (vm, prev_node->index, node->index);
123}
124
Matthew Smith401aedf2019-07-08 14:45:04 -0500125void
Neale Rannse8915fc2019-04-23 20:57:55 -0400126ipsec_add_feature (const char *arc_name,
127 const char *node_name, u32 * out_feature_index)
128{
129 u8 arc;
130
131 arc = vnet_get_feature_arc_index (arc_name);
Neale Ranns02245142019-05-13 23:07:43 -0700132 ASSERT (arc != (u8) ~ 0);
Neale Rannse8915fc2019-04-23 20:57:55 -0400133 *out_feature_index = vnet_get_feature_index (arc, node_name);
134}
135
Klement Sekerab4d30532018-11-08 13:00:02 +0100136u32
137ipsec_register_ah_backend (vlib_main_t * vm, ipsec_main_t * im,
138 const char *name,
139 const char *ah4_encrypt_node_name,
140 const char *ah4_decrypt_node_name,
141 const char *ah6_encrypt_node_name,
142 const char *ah6_decrypt_node_name,
143 check_support_cb_t ah_check_support_cb,
144 add_del_sa_sess_cb_t ah_add_del_sa_sess_cb)
145{
146 ipsec_ah_backend_t *b;
147 pool_get (im->ah_backends, b);
Kingwel Xie561d1ca2019-03-05 22:56:17 -0500148 b->name = format (0, "%s%c", name, 0);
Klement Sekerab4d30532018-11-08 13:00:02 +0100149
Pierre Pfister057b3562018-12-10 17:01:01 +0100150 ipsec_add_node (vm, ah4_encrypt_node_name, "ipsec4-output-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100151 &b->ah4_encrypt_node_index, &b->ah4_encrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100152 ipsec_add_node (vm, ah4_decrypt_node_name, "ipsec4-input-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100153 &b->ah4_decrypt_node_index, &b->ah4_decrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100154 ipsec_add_node (vm, ah6_encrypt_node_name, "ipsec6-output-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100155 &b->ah6_encrypt_node_index, &b->ah6_encrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100156 ipsec_add_node (vm, ah6_decrypt_node_name, "ipsec6-input-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100157 &b->ah6_decrypt_node_index, &b->ah6_decrypt_next_index);
158
159 b->check_support_cb = ah_check_support_cb;
160 b->add_del_sa_sess_cb = ah_add_del_sa_sess_cb;
161 return b - im->ah_backends;
162}
163
164u32
165ipsec_register_esp_backend (vlib_main_t * vm, ipsec_main_t * im,
166 const char *name,
167 const char *esp4_encrypt_node_name,
Neale Rannse8915fc2019-04-23 20:57:55 -0400168 const char *esp4_encrypt_node_tun_name,
Klement Sekerab4d30532018-11-08 13:00:02 +0100169 const char *esp4_decrypt_node_name,
170 const char *esp6_encrypt_node_name,
Neale Rannse8915fc2019-04-23 20:57:55 -0400171 const char *esp6_encrypt_node_tun_name,
Klement Sekerab4d30532018-11-08 13:00:02 +0100172 const char *esp6_decrypt_node_name,
173 check_support_cb_t esp_check_support_cb,
174 add_del_sa_sess_cb_t esp_add_del_sa_sess_cb)
175{
176 ipsec_esp_backend_t *b;
Neale Rannse8915fc2019-04-23 20:57:55 -0400177
Klement Sekerab4d30532018-11-08 13:00:02 +0100178 pool_get (im->esp_backends, b);
Kingwel Xie561d1ca2019-03-05 22:56:17 -0500179 b->name = format (0, "%s%c", name, 0);
Klement Sekerab4d30532018-11-08 13:00:02 +0100180
Pierre Pfister057b3562018-12-10 17:01:01 +0100181 ipsec_add_node (vm, esp4_encrypt_node_name, "ipsec4-output-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100182 &b->esp4_encrypt_node_index, &b->esp4_encrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100183 ipsec_add_node (vm, esp4_decrypt_node_name, "ipsec4-input-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100184 &b->esp4_decrypt_node_index, &b->esp4_decrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100185 ipsec_add_node (vm, esp6_encrypt_node_name, "ipsec6-output-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100186 &b->esp6_encrypt_node_index, &b->esp6_encrypt_next_index);
Pierre Pfister057b3562018-12-10 17:01:01 +0100187 ipsec_add_node (vm, esp6_decrypt_node_name, "ipsec6-input-feature",
Klement Sekerab4d30532018-11-08 13:00:02 +0100188 &b->esp6_decrypt_node_index, &b->esp6_decrypt_next_index);
189
Neale Rannse8915fc2019-04-23 20:57:55 -0400190 ipsec_add_feature ("ip4-output", esp4_encrypt_node_tun_name,
191 &b->esp4_encrypt_tun_feature_index);
192 ipsec_add_feature ("ip6-output", esp6_encrypt_node_tun_name,
193 &b->esp6_encrypt_tun_feature_index);
194
Klement Sekerab4d30532018-11-08 13:00:02 +0100195 b->check_support_cb = esp_check_support_cb;
196 b->add_del_sa_sess_cb = esp_add_del_sa_sess_cb;
197 return b - im->esp_backends;
198}
199
Neale Rannse8915fc2019-04-23 20:57:55 -0400200clib_error_t *
201ipsec_rsc_in_use (ipsec_main_t * im)
Neale Rannsb4cfd552019-02-13 02:08:06 -0800202{
Neale Rannse8915fc2019-04-23 20:57:55 -0400203 /* return an error is crypto resource are in use */
204 if (pool_elts (im->sad) > 0)
205 return clib_error_return (0,
206 "%d SA entries configured",
207 pool_elts (im->sad));
Neale Rannsb4cfd552019-02-13 02:08:06 -0800208
Neale Rannse8915fc2019-04-23 20:57:55 -0400209 return (NULL);
Neale Rannsb4cfd552019-02-13 02:08:06 -0800210}
211
Klement Sekerab4d30532018-11-08 13:00:02 +0100212int
213ipsec_select_ah_backend (ipsec_main_t * im, u32 backend_idx)
214{
Neale Rannse8915fc2019-04-23 20:57:55 -0400215 if (ipsec_rsc_in_use (im))
216 return VNET_API_ERROR_RSRC_IN_USE;
217
218 if (pool_is_free_index (im->ah_backends, backend_idx))
219 return VNET_API_ERROR_INVALID_VALUE;
220
Klement Sekerab4d30532018-11-08 13:00:02 +0100221 ipsec_ah_backend_t *b = pool_elt_at_index (im->ah_backends, backend_idx);
222 im->ah_current_backend = backend_idx;
223 im->ah4_encrypt_node_index = b->ah4_encrypt_node_index;
224 im->ah4_decrypt_node_index = b->ah4_decrypt_node_index;
225 im->ah4_encrypt_next_index = b->ah4_encrypt_next_index;
226 im->ah4_decrypt_next_index = b->ah4_decrypt_next_index;
227 im->ah6_encrypt_node_index = b->ah6_encrypt_node_index;
228 im->ah6_decrypt_node_index = b->ah6_decrypt_node_index;
229 im->ah6_encrypt_next_index = b->ah6_encrypt_next_index;
230 im->ah6_decrypt_next_index = b->ah6_decrypt_next_index;
Neale Rannsb4cfd552019-02-13 02:08:06 -0800231
Klement Sekerab4d30532018-11-08 13:00:02 +0100232 return 0;
233}
234
235int
236ipsec_select_esp_backend (ipsec_main_t * im, u32 backend_idx)
237{
Neale Rannse8915fc2019-04-23 20:57:55 -0400238 if (ipsec_rsc_in_use (im))
239 return VNET_API_ERROR_RSRC_IN_USE;
240
241 if (pool_is_free_index (im->esp_backends, backend_idx))
242 return VNET_API_ERROR_INVALID_VALUE;
243
Klement Sekerab4d30532018-11-08 13:00:02 +0100244 ipsec_esp_backend_t *b = pool_elt_at_index (im->esp_backends, backend_idx);
245 im->esp_current_backend = backend_idx;
246 im->esp4_encrypt_node_index = b->esp4_encrypt_node_index;
247 im->esp4_decrypt_node_index = b->esp4_decrypt_node_index;
248 im->esp4_encrypt_next_index = b->esp4_encrypt_next_index;
249 im->esp4_decrypt_next_index = b->esp4_decrypt_next_index;
250 im->esp6_encrypt_node_index = b->esp6_encrypt_node_index;
251 im->esp6_decrypt_node_index = b->esp6_decrypt_node_index;
252 im->esp6_encrypt_next_index = b->esp6_encrypt_next_index;
253 im->esp6_decrypt_next_index = b->esp6_decrypt_next_index;
Neale Rannsb4cfd552019-02-13 02:08:06 -0800254
Neale Rannse8915fc2019-04-23 20:57:55 -0400255 im->esp4_encrypt_tun_feature_index = b->esp4_encrypt_tun_feature_index;
256 im->esp6_encrypt_tun_feature_index = b->esp6_encrypt_tun_feature_index;
257
Klement Sekerab4d30532018-11-08 13:00:02 +0100258 return 0;
259}
260
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000261static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700262ipsec_init (vlib_main_t * vm)
263{
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700264 clib_error_t *error;
265 ipsec_main_t *im = &ipsec_main;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100266 ipsec_main_crypto_alg_t *a;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700267
Dave Barach0dd91652019-05-05 13:34:28 -0400268 /* Backend registration requires the feature arcs to be set up */
269 if ((error = vlib_call_init_function (vm, vnet_feature_init)))
270 return (error);
271
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700272 im->vnet_main = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700273 im->vlib_main = vm;
274
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700275 im->spd_index_by_spd_id = hash_create (0, sizeof (uword));
276 im->sa_index_by_sa_id = hash_create (0, sizeof (uword));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700277 im->spd_index_by_sw_if_index = hash_create (0, sizeof (uword));
278
Klement Sekerab4d30532018-11-08 13:00:02 +0100279 vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700280 ASSERT (node);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281 im->error_drop_node_index = node->index;
282
Neale Rannsd1a5b2d2019-05-16 17:09:28 +0000283 u32 idx = ipsec_register_ah_backend (vm, im, "crypto engine backend",
Klement Sekerab4d30532018-11-08 13:00:02 +0100284 "ah4-encrypt",
285 "ah4-decrypt",
286 "ah6-encrypt",
287 "ah6-decrypt",
Klement Sekera4fd5a9d2019-01-30 11:11:23 +0100288 ipsec_check_ah_support,
Klement Sekerab4d30532018-11-08 13:00:02 +0100289 NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700290
Klement Sekerab4d30532018-11-08 13:00:02 +0100291 im->ah_default_backend = idx;
292 int rv = ipsec_select_ah_backend (im, idx);
293 ASSERT (0 == rv);
294 (void) (rv); // avoid warning
Sergio Gonzalez Monroyd04b60b2017-01-20 15:35:23 +0000295
Neale Rannsd1a5b2d2019-05-16 17:09:28 +0000296 idx = ipsec_register_esp_backend (vm, im, "crypto engine backend",
Klement Sekerab4d30532018-11-08 13:00:02 +0100297 "esp4-encrypt",
Neale Rannse8915fc2019-04-23 20:57:55 -0400298 "esp4-encrypt-tun",
Klement Sekerab4d30532018-11-08 13:00:02 +0100299 "esp4-decrypt",
300 "esp6-encrypt",
Neale Rannse8915fc2019-04-23 20:57:55 -0400301 "esp6-encrypt-tun",
Klement Sekerab4d30532018-11-08 13:00:02 +0100302 "esp6-decrypt",
Klement Sekera4fd5a9d2019-01-30 11:11:23 +0100303 ipsec_check_esp_support, NULL);
Klement Sekerab4d30532018-11-08 13:00:02 +0100304 im->esp_default_backend = idx;
“mukeshyadav1984”430ac932017-11-23 02:39:33 -0800305
Klement Sekerab4d30532018-11-08 13:00:02 +0100306 rv = ipsec_select_esp_backend (im, idx);
307 ASSERT (0 == rv);
308 (void) (rv); // avoid warning
Ed Warnickecb9cada2015-12-08 15:45:58 -0700309
Ed Warnickecb9cada2015-12-08 15:45:58 -0700310 if ((error = vlib_call_init_function (vm, ipsec_cli_init)))
311 return error;
312
Damjan Marion91f17dc2019-03-18 18:59:25 +0100313 vec_validate (im->crypto_algs, IPSEC_CRYPTO_N_ALG - 1);
314
Neale Ranns2cdcd0c2019-08-27 12:26:14 +0000315 a = im->crypto_algs + IPSEC_CRYPTO_ALG_NONE;
316 a->enc_op_id = VNET_CRYPTO_OP_NONE;
317 a->dec_op_id = VNET_CRYPTO_OP_NONE;
318 a->alg = VNET_CRYPTO_ALG_NONE;
319 a->iv_size = 0;
320 a->block_size = 1;
321
Damjan Marion91f17dc2019-03-18 18:59:25 +0100322 a = im->crypto_algs + IPSEC_CRYPTO_ALG_DES_CBC;
Damjan Marion060bfb92019-03-29 13:47:54 +0100323 a->enc_op_id = VNET_CRYPTO_OP_DES_CBC_ENC;
324 a->dec_op_id = VNET_CRYPTO_OP_DES_CBC_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200325 a->alg = VNET_CRYPTO_ALG_DES_CBC;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100326 a->iv_size = a->block_size = 8;
327
328 a = im->crypto_algs + IPSEC_CRYPTO_ALG_3DES_CBC;
Damjan Marion060bfb92019-03-29 13:47:54 +0100329 a->enc_op_id = VNET_CRYPTO_OP_3DES_CBC_ENC;
330 a->dec_op_id = VNET_CRYPTO_OP_3DES_CBC_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200331 a->alg = VNET_CRYPTO_ALG_3DES_CBC;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100332 a->iv_size = a->block_size = 8;
333
334 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_128;
Damjan Marion060bfb92019-03-29 13:47:54 +0100335 a->enc_op_id = VNET_CRYPTO_OP_AES_128_CBC_ENC;
336 a->dec_op_id = VNET_CRYPTO_OP_AES_128_CBC_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200337 a->alg = VNET_CRYPTO_ALG_AES_128_CBC;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100338 a->iv_size = a->block_size = 16;
339
340 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_192;
Damjan Marion060bfb92019-03-29 13:47:54 +0100341 a->enc_op_id = VNET_CRYPTO_OP_AES_192_CBC_ENC;
342 a->dec_op_id = VNET_CRYPTO_OP_AES_192_CBC_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200343 a->alg = VNET_CRYPTO_ALG_AES_192_CBC;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100344 a->iv_size = a->block_size = 16;
345
346 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_256;
Damjan Marion060bfb92019-03-29 13:47:54 +0100347 a->enc_op_id = VNET_CRYPTO_OP_AES_256_CBC_ENC;
348 a->dec_op_id = VNET_CRYPTO_OP_AES_256_CBC_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200349 a->alg = VNET_CRYPTO_ALG_AES_256_CBC;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100350 a->iv_size = a->block_size = 16;
351
Neale Ranns47feb112019-04-11 15:14:07 +0000352 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_128;
353 a->enc_op_id = VNET_CRYPTO_OP_AES_128_GCM_ENC;
354 a->dec_op_id = VNET_CRYPTO_OP_AES_128_GCM_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200355 a->alg = VNET_CRYPTO_ALG_AES_128_GCM;
Neale Ranns47feb112019-04-11 15:14:07 +0000356 a->iv_size = a->block_size = 8;
357 a->icv_size = 16;
358
359 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_192;
360 a->enc_op_id = VNET_CRYPTO_OP_AES_192_GCM_ENC;
361 a->dec_op_id = VNET_CRYPTO_OP_AES_192_GCM_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200362 a->alg = VNET_CRYPTO_ALG_AES_192_GCM;
Neale Ranns47feb112019-04-11 15:14:07 +0000363 a->iv_size = a->block_size = 8;
364 a->icv_size = 16;
365
366 a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_256;
367 a->enc_op_id = VNET_CRYPTO_OP_AES_256_GCM_ENC;
368 a->dec_op_id = VNET_CRYPTO_OP_AES_256_GCM_DEC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200369 a->alg = VNET_CRYPTO_ALG_AES_256_GCM;
Neale Ranns47feb112019-04-11 15:14:07 +0000370 a->iv_size = a->block_size = 8;
371 a->icv_size = 16;
372
Damjan Marion91f17dc2019-03-18 18:59:25 +0100373 vec_validate (im->integ_algs, IPSEC_INTEG_N_ALG - 1);
374 ipsec_main_integ_alg_t *i;
375
Dmitry Vakhrushev77cc14a2019-08-14 00:12:33 -0400376 i = &im->integ_algs[IPSEC_INTEG_ALG_MD5_96];
377 i->op_id = VNET_CRYPTO_OP_MD5_HMAC;
378 i->alg = VNET_CRYPTO_ALG_HMAC_MD5;
379 i->icv_size = 12;
380
Damjan Marion91f17dc2019-03-18 18:59:25 +0100381 i = &im->integ_algs[IPSEC_INTEG_ALG_SHA1_96];
Damjan Marion060bfb92019-03-29 13:47:54 +0100382 i->op_id = VNET_CRYPTO_OP_SHA1_HMAC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200383 i->alg = VNET_CRYPTO_ALG_HMAC_SHA1;
Damjan Marion7c22ff72019-04-04 12:25:44 +0200384 i->icv_size = 12;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100385
386 i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_96];
Damjan Marion060bfb92019-03-29 13:47:54 +0100387 i->op_id = VNET_CRYPTO_OP_SHA1_HMAC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200388 i->alg = VNET_CRYPTO_ALG_HMAC_SHA256;
Damjan Marion7c22ff72019-04-04 12:25:44 +0200389 i->icv_size = 12;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100390
391 i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_128];
Damjan Marion060bfb92019-03-29 13:47:54 +0100392 i->op_id = VNET_CRYPTO_OP_SHA256_HMAC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200393 i->alg = VNET_CRYPTO_ALG_HMAC_SHA256;
Damjan Marion7c22ff72019-04-04 12:25:44 +0200394 i->icv_size = 16;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100395
396 i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_384_192];
Damjan Marion060bfb92019-03-29 13:47:54 +0100397 i->op_id = VNET_CRYPTO_OP_SHA384_HMAC;
Damjan Marion4cb83812019-04-24 17:32:01 +0200398 i->alg = VNET_CRYPTO_ALG_HMAC_SHA384;
Damjan Marion7c22ff72019-04-04 12:25:44 +0200399 i->icv_size = 24;
Damjan Marion91f17dc2019-03-18 18:59:25 +0100400
401 i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_512_256];
Damjan Marion060bfb92019-03-29 13:47:54 +0100402 i->op_id = VNET_CRYPTO_OP_SHA512_HMAC;
Damjan Mariond1bed682019-04-24 15:20:35 +0200403 i->alg = VNET_CRYPTO_ALG_HMAC_SHA512;
Damjan Marion7c22ff72019-04-04 12:25:44 +0200404 i->icv_size = 32;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700405
Neale Ranns5ae793a2019-04-03 13:36:56 +0000406 vec_validate_aligned (im->ptd, vlib_num_workers (), CLIB_CACHE_LINE_BYTES);
Damjan Marionc59b9a22019-03-19 15:38:40 +0100407
Neale Rannsf62a8c02019-04-02 08:13:33 +0000408 im->ah4_enc_fq_index =
409 vlib_frame_queue_main_init (ah4_encrypt_node.index, 0);
410 im->ah4_dec_fq_index =
411 vlib_frame_queue_main_init (ah4_decrypt_node.index, 0);
412 im->ah6_enc_fq_index =
413 vlib_frame_queue_main_init (ah6_encrypt_node.index, 0);
414 im->ah6_dec_fq_index =
415 vlib_frame_queue_main_init (ah6_decrypt_node.index, 0);
416
417 im->esp4_enc_fq_index =
418 vlib_frame_queue_main_init (esp4_encrypt_node.index, 0);
419 im->esp4_dec_fq_index =
420 vlib_frame_queue_main_init (esp4_decrypt_node.index, 0);
421 im->esp6_enc_fq_index =
422 vlib_frame_queue_main_init (esp6_encrypt_node.index, 0);
423 im->esp6_dec_fq_index =
424 vlib_frame_queue_main_init (esp6_decrypt_node.index, 0);
425 im->esp4_enc_tun_fq_index =
426 vlib_frame_queue_main_init (esp4_encrypt_tun_node.index, 0);
427 im->esp6_enc_tun_fq_index =
428 vlib_frame_queue_main_init (esp6_encrypt_tun_node.index, 0);
429 im->esp4_dec_tun_fq_index =
430 vlib_frame_queue_main_init (esp4_decrypt_tun_node.index, 0);
431 im->esp6_dec_tun_fq_index =
432 vlib_frame_queue_main_init (esp6_decrypt_tun_node.index, 0);
433
Ed Warnickecb9cada2015-12-08 15:45:58 -0700434 return 0;
435}
436
437VLIB_INIT_FUNCTION (ipsec_init);
Keith Burns (alagalah)166a9d42016-08-06 11:00:56 -0700438
439/*
440 * fd.io coding-style-patch-verification: ON
441 *
442 * Local Variables:
443 * eval: (c-set-style "gnu")
444 * End:
445 */