Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
Neale Ranns | 999c8ee | 2019-02-01 03:31:24 -0800 | [diff] [blame] | 2 | * ipsec.c : IPSEC module functions |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3 | * |
| 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 Sekera | 4b089f2 | 2018-04-17 18:04:57 +0200 | [diff] [blame] | 22 | #include <vnet/udp/udp.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 23 | |
| 24 | #include <vnet/ipsec/ipsec.h> |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 25 | #include <vnet/ipsec/esp.h> |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 26 | #include <vnet/ipsec/ah.h> |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 27 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 28 | ipsec_main_t ipsec_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | |
| 30 | static clib_error_t * |
Klement Sekera | 4fd5a9d | 2019-01-30 11:11:23 +0100 | [diff] [blame] | 31 | ipsec_check_ah_support (ipsec_sa_t * sa) |
| 32 | { |
| 33 | if (sa->integ_alg == IPSEC_INTEG_ALG_NONE) |
| 34 | return clib_error_return (0, "unsupported none integ-alg"); |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static clib_error_t * |
| 39 | ipsec_check_esp_support (ipsec_sa_t * sa) |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 40 | { |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 41 | return 0; |
| 42 | } |
| 43 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 44 | clib_error_t * |
| 45 | ipsec_add_del_sa_sess_cb (ipsec_main_t * im, u32 sa_index, u8 is_add) |
| 46 | { |
| 47 | ipsec_ah_backend_t *ah = |
| 48 | pool_elt_at_index (im->ah_backends, im->ah_current_backend); |
| 49 | if (ah->add_del_sa_sess_cb) |
| 50 | { |
| 51 | clib_error_t *err = ah->add_del_sa_sess_cb (sa_index, is_add); |
| 52 | if (err) |
| 53 | return err; |
| 54 | } |
| 55 | ipsec_esp_backend_t *esp = |
| 56 | pool_elt_at_index (im->esp_backends, im->esp_current_backend); |
| 57 | if (esp->add_del_sa_sess_cb) |
| 58 | { |
| 59 | clib_error_t *err = esp->add_del_sa_sess_cb (sa_index, is_add); |
| 60 | if (err) |
| 61 | return err; |
| 62 | } |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | clib_error_t * |
| 67 | ipsec_check_support_cb (ipsec_main_t * im, ipsec_sa_t * sa) |
| 68 | { |
| 69 | clib_error_t *error = 0; |
Matthew Smith | 461caa5 | 2018-12-21 11:53:16 -0600 | [diff] [blame] | 70 | |
| 71 | if (PREDICT_FALSE (sa->protocol == IPSEC_PROTOCOL_AH)) |
| 72 | { |
| 73 | ipsec_ah_backend_t *ah = |
| 74 | pool_elt_at_index (im->ah_backends, im->ah_current_backend); |
| 75 | ASSERT (ah->check_support_cb); |
| 76 | error = ah->check_support_cb (sa); |
| 77 | } |
| 78 | else |
| 79 | { |
| 80 | ipsec_esp_backend_t *esp = |
| 81 | pool_elt_at_index (im->esp_backends, im->esp_current_backend); |
| 82 | ASSERT (esp->check_support_cb); |
| 83 | error = esp->check_support_cb (sa); |
| 84 | } |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 85 | return error; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | static void |
| 90 | ipsec_add_node (vlib_main_t * vm, const char *node_name, |
| 91 | const char *prev_node_name, u32 * out_node_index, |
| 92 | u32 * out_next_index) |
| 93 | { |
| 94 | vlib_node_t *prev_node, *node; |
| 95 | prev_node = vlib_get_node_by_name (vm, (u8 *) prev_node_name); |
| 96 | ASSERT (prev_node); |
| 97 | node = vlib_get_node_by_name (vm, (u8 *) node_name); |
| 98 | ASSERT (node); |
| 99 | *out_node_index = node->index; |
| 100 | *out_next_index = vlib_node_add_next (vm, prev_node->index, node->index); |
| 101 | } |
| 102 | |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 103 | static void |
| 104 | ipsec_add_feature (const char *arc_name, |
| 105 | const char *node_name, u32 * out_feature_index) |
| 106 | { |
| 107 | u8 arc; |
| 108 | |
| 109 | arc = vnet_get_feature_arc_index (arc_name); |
Neale Ranns | 0224514 | 2019-05-13 23:07:43 -0700 | [diff] [blame] | 110 | ASSERT (arc != (u8) ~ 0); |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 111 | *out_feature_index = vnet_get_feature_index (arc, node_name); |
| 112 | } |
| 113 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 114 | u32 |
| 115 | ipsec_register_ah_backend (vlib_main_t * vm, ipsec_main_t * im, |
| 116 | const char *name, |
| 117 | const char *ah4_encrypt_node_name, |
| 118 | const char *ah4_decrypt_node_name, |
| 119 | const char *ah6_encrypt_node_name, |
| 120 | const char *ah6_decrypt_node_name, |
| 121 | check_support_cb_t ah_check_support_cb, |
| 122 | add_del_sa_sess_cb_t ah_add_del_sa_sess_cb) |
| 123 | { |
| 124 | ipsec_ah_backend_t *b; |
| 125 | pool_get (im->ah_backends, b); |
Kingwel Xie | 561d1ca | 2019-03-05 22:56:17 -0500 | [diff] [blame] | 126 | b->name = format (0, "%s%c", name, 0); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 127 | |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 128 | ipsec_add_node (vm, ah4_encrypt_node_name, "ipsec4-output-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 129 | &b->ah4_encrypt_node_index, &b->ah4_encrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 130 | ipsec_add_node (vm, ah4_decrypt_node_name, "ipsec4-input-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 131 | &b->ah4_decrypt_node_index, &b->ah4_decrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 132 | ipsec_add_node (vm, ah6_encrypt_node_name, "ipsec6-output-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 133 | &b->ah6_encrypt_node_index, &b->ah6_encrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 134 | ipsec_add_node (vm, ah6_decrypt_node_name, "ipsec6-input-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 135 | &b->ah6_decrypt_node_index, &b->ah6_decrypt_next_index); |
| 136 | |
| 137 | b->check_support_cb = ah_check_support_cb; |
| 138 | b->add_del_sa_sess_cb = ah_add_del_sa_sess_cb; |
| 139 | return b - im->ah_backends; |
| 140 | } |
| 141 | |
| 142 | u32 |
| 143 | ipsec_register_esp_backend (vlib_main_t * vm, ipsec_main_t * im, |
| 144 | const char *name, |
| 145 | const char *esp4_encrypt_node_name, |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 146 | const char *esp4_encrypt_node_tun_name, |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 147 | const char *esp4_decrypt_node_name, |
| 148 | const char *esp6_encrypt_node_name, |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 149 | const char *esp6_encrypt_node_tun_name, |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 150 | const char *esp6_decrypt_node_name, |
| 151 | check_support_cb_t esp_check_support_cb, |
| 152 | add_del_sa_sess_cb_t esp_add_del_sa_sess_cb) |
| 153 | { |
| 154 | ipsec_esp_backend_t *b; |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 155 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 156 | pool_get (im->esp_backends, b); |
Kingwel Xie | 561d1ca | 2019-03-05 22:56:17 -0500 | [diff] [blame] | 157 | b->name = format (0, "%s%c", name, 0); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 158 | |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 159 | ipsec_add_node (vm, esp4_encrypt_node_name, "ipsec4-output-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 160 | &b->esp4_encrypt_node_index, &b->esp4_encrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 161 | ipsec_add_node (vm, esp4_decrypt_node_name, "ipsec4-input-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 162 | &b->esp4_decrypt_node_index, &b->esp4_decrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 163 | ipsec_add_node (vm, esp6_encrypt_node_name, "ipsec6-output-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 164 | &b->esp6_encrypt_node_index, &b->esp6_encrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 165 | ipsec_add_node (vm, esp6_decrypt_node_name, "ipsec6-input-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 166 | &b->esp6_decrypt_node_index, &b->esp6_decrypt_next_index); |
| 167 | |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 168 | ipsec_add_feature ("ip4-output", esp4_encrypt_node_tun_name, |
| 169 | &b->esp4_encrypt_tun_feature_index); |
| 170 | ipsec_add_feature ("ip6-output", esp6_encrypt_node_tun_name, |
| 171 | &b->esp6_encrypt_tun_feature_index); |
| 172 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 173 | b->check_support_cb = esp_check_support_cb; |
| 174 | b->add_del_sa_sess_cb = esp_add_del_sa_sess_cb; |
| 175 | return b - im->esp_backends; |
| 176 | } |
| 177 | |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 178 | clib_error_t * |
| 179 | ipsec_rsc_in_use (ipsec_main_t * im) |
Neale Ranns | b4cfd55 | 2019-02-13 02:08:06 -0800 | [diff] [blame] | 180 | { |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 181 | /* return an error is crypto resource are in use */ |
| 182 | if (pool_elts (im->sad) > 0) |
| 183 | return clib_error_return (0, |
| 184 | "%d SA entries configured", |
| 185 | pool_elts (im->sad)); |
Neale Ranns | b4cfd55 | 2019-02-13 02:08:06 -0800 | [diff] [blame] | 186 | |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 187 | if (pool_elts (im->tunnel_interfaces)) |
| 188 | return clib_error_return (0, |
| 189 | "%d tunnel-interface entries configured", |
| 190 | pool_elts (im->tunnel_interfaces)); |
| 191 | |
| 192 | return (NULL); |
Neale Ranns | b4cfd55 | 2019-02-13 02:08:06 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 195 | int |
| 196 | ipsec_select_ah_backend (ipsec_main_t * im, u32 backend_idx) |
| 197 | { |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 198 | if (ipsec_rsc_in_use (im)) |
| 199 | return VNET_API_ERROR_RSRC_IN_USE; |
| 200 | |
| 201 | if (pool_is_free_index (im->ah_backends, backend_idx)) |
| 202 | return VNET_API_ERROR_INVALID_VALUE; |
| 203 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 204 | ipsec_ah_backend_t *b = pool_elt_at_index (im->ah_backends, backend_idx); |
| 205 | im->ah_current_backend = backend_idx; |
| 206 | im->ah4_encrypt_node_index = b->ah4_encrypt_node_index; |
| 207 | im->ah4_decrypt_node_index = b->ah4_decrypt_node_index; |
| 208 | im->ah4_encrypt_next_index = b->ah4_encrypt_next_index; |
| 209 | im->ah4_decrypt_next_index = b->ah4_decrypt_next_index; |
| 210 | im->ah6_encrypt_node_index = b->ah6_encrypt_node_index; |
| 211 | im->ah6_decrypt_node_index = b->ah6_decrypt_node_index; |
| 212 | im->ah6_encrypt_next_index = b->ah6_encrypt_next_index; |
| 213 | im->ah6_decrypt_next_index = b->ah6_decrypt_next_index; |
Neale Ranns | b4cfd55 | 2019-02-13 02:08:06 -0800 | [diff] [blame] | 214 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | int |
| 219 | ipsec_select_esp_backend (ipsec_main_t * im, u32 backend_idx) |
| 220 | { |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 221 | if (ipsec_rsc_in_use (im)) |
| 222 | return VNET_API_ERROR_RSRC_IN_USE; |
| 223 | |
| 224 | if (pool_is_free_index (im->esp_backends, backend_idx)) |
| 225 | return VNET_API_ERROR_INVALID_VALUE; |
| 226 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 227 | ipsec_esp_backend_t *b = pool_elt_at_index (im->esp_backends, backend_idx); |
| 228 | im->esp_current_backend = backend_idx; |
| 229 | im->esp4_encrypt_node_index = b->esp4_encrypt_node_index; |
| 230 | im->esp4_decrypt_node_index = b->esp4_decrypt_node_index; |
| 231 | im->esp4_encrypt_next_index = b->esp4_encrypt_next_index; |
| 232 | im->esp4_decrypt_next_index = b->esp4_decrypt_next_index; |
| 233 | im->esp6_encrypt_node_index = b->esp6_encrypt_node_index; |
| 234 | im->esp6_decrypt_node_index = b->esp6_decrypt_node_index; |
| 235 | im->esp6_encrypt_next_index = b->esp6_encrypt_next_index; |
| 236 | im->esp6_decrypt_next_index = b->esp6_decrypt_next_index; |
Neale Ranns | b4cfd55 | 2019-02-13 02:08:06 -0800 | [diff] [blame] | 237 | |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 238 | im->esp4_encrypt_tun_feature_index = b->esp4_encrypt_tun_feature_index; |
| 239 | im->esp6_encrypt_tun_feature_index = b->esp6_encrypt_tun_feature_index; |
| 240 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 241 | return 0; |
| 242 | } |
| 243 | |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 244 | static clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 245 | ipsec_init (vlib_main_t * vm) |
| 246 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 247 | clib_error_t *error; |
| 248 | ipsec_main_t *im = &ipsec_main; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 249 | ipsec_main_crypto_alg_t *a; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 250 | |
Dave Barach | 0dd9165 | 2019-05-05 13:34:28 -0400 | [diff] [blame] | 251 | /* Backend registration requires the feature arcs to be set up */ |
| 252 | if ((error = vlib_call_init_function (vm, vnet_feature_init))) |
| 253 | return (error); |
| 254 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 255 | im->vnet_main = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 256 | im->vlib_main = vm; |
| 257 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 258 | im->spd_index_by_spd_id = hash_create (0, sizeof (uword)); |
| 259 | im->sa_index_by_sa_id = hash_create (0, sizeof (uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 260 | im->spd_index_by_sw_if_index = hash_create (0, sizeof (uword)); |
| 261 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 262 | vlib_node_t *node = vlib_get_node_by_name (vm, (u8 *) "error-drop"); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 263 | ASSERT (node); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 264 | im->error_drop_node_index = node->index; |
| 265 | |
Neale Ranns | d1a5b2d | 2019-05-16 17:09:28 +0000 | [diff] [blame] | 266 | u32 idx = ipsec_register_ah_backend (vm, im, "crypto engine backend", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 267 | "ah4-encrypt", |
| 268 | "ah4-decrypt", |
| 269 | "ah6-encrypt", |
| 270 | "ah6-decrypt", |
Klement Sekera | 4fd5a9d | 2019-01-30 11:11:23 +0100 | [diff] [blame] | 271 | ipsec_check_ah_support, |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 272 | NULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 273 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 274 | im->ah_default_backend = idx; |
| 275 | int rv = ipsec_select_ah_backend (im, idx); |
| 276 | ASSERT (0 == rv); |
| 277 | (void) (rv); // avoid warning |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 278 | |
Neale Ranns | d1a5b2d | 2019-05-16 17:09:28 +0000 | [diff] [blame] | 279 | idx = ipsec_register_esp_backend (vm, im, "crypto engine backend", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 280 | "esp4-encrypt", |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 281 | "esp4-encrypt-tun", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 282 | "esp4-decrypt", |
| 283 | "esp6-encrypt", |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 284 | "esp6-encrypt-tun", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 285 | "esp6-decrypt", |
Klement Sekera | 4fd5a9d | 2019-01-30 11:11:23 +0100 | [diff] [blame] | 286 | ipsec_check_esp_support, NULL); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 287 | im->esp_default_backend = idx; |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 288 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 289 | rv = ipsec_select_esp_backend (im, idx); |
| 290 | ASSERT (0 == rv); |
| 291 | (void) (rv); // avoid warning |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 292 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 293 | if ((error = vlib_call_init_function (vm, ipsec_cli_init))) |
| 294 | return error; |
| 295 | |
| 296 | if ((error = vlib_call_init_function (vm, ipsec_tunnel_if_init))) |
| 297 | return error; |
| 298 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 299 | vec_validate (im->crypto_algs, IPSEC_CRYPTO_N_ALG - 1); |
| 300 | |
| 301 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_DES_CBC; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 302 | a->enc_op_id = VNET_CRYPTO_OP_DES_CBC_ENC; |
| 303 | a->dec_op_id = VNET_CRYPTO_OP_DES_CBC_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 304 | a->alg = VNET_CRYPTO_ALG_DES_CBC; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 305 | a->iv_size = a->block_size = 8; |
| 306 | |
| 307 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_3DES_CBC; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 308 | a->enc_op_id = VNET_CRYPTO_OP_3DES_CBC_ENC; |
| 309 | a->dec_op_id = VNET_CRYPTO_OP_3DES_CBC_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 310 | a->alg = VNET_CRYPTO_ALG_3DES_CBC; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 311 | a->iv_size = a->block_size = 8; |
| 312 | |
| 313 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_128; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 314 | a->enc_op_id = VNET_CRYPTO_OP_AES_128_CBC_ENC; |
| 315 | a->dec_op_id = VNET_CRYPTO_OP_AES_128_CBC_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 316 | a->alg = VNET_CRYPTO_ALG_AES_128_CBC; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 317 | a->iv_size = a->block_size = 16; |
| 318 | |
| 319 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_192; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 320 | a->enc_op_id = VNET_CRYPTO_OP_AES_192_CBC_ENC; |
| 321 | a->dec_op_id = VNET_CRYPTO_OP_AES_192_CBC_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 322 | a->alg = VNET_CRYPTO_ALG_AES_192_CBC; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 323 | a->iv_size = a->block_size = 16; |
| 324 | |
| 325 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_256; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 326 | a->enc_op_id = VNET_CRYPTO_OP_AES_256_CBC_ENC; |
| 327 | a->dec_op_id = VNET_CRYPTO_OP_AES_256_CBC_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 328 | a->alg = VNET_CRYPTO_ALG_AES_256_CBC; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 329 | a->iv_size = a->block_size = 16; |
| 330 | |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 331 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_128; |
| 332 | a->enc_op_id = VNET_CRYPTO_OP_AES_128_GCM_ENC; |
| 333 | a->dec_op_id = VNET_CRYPTO_OP_AES_128_GCM_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 334 | a->alg = VNET_CRYPTO_ALG_AES_128_GCM; |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 335 | a->iv_size = a->block_size = 8; |
| 336 | a->icv_size = 16; |
| 337 | |
| 338 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_192; |
| 339 | a->enc_op_id = VNET_CRYPTO_OP_AES_192_GCM_ENC; |
| 340 | a->dec_op_id = VNET_CRYPTO_OP_AES_192_GCM_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 341 | a->alg = VNET_CRYPTO_ALG_AES_192_GCM; |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 342 | a->iv_size = a->block_size = 8; |
| 343 | a->icv_size = 16; |
| 344 | |
| 345 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_256; |
| 346 | a->enc_op_id = VNET_CRYPTO_OP_AES_256_GCM_ENC; |
| 347 | a->dec_op_id = VNET_CRYPTO_OP_AES_256_GCM_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 348 | a->alg = VNET_CRYPTO_ALG_AES_256_GCM; |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 349 | a->iv_size = a->block_size = 8; |
| 350 | a->icv_size = 16; |
| 351 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 352 | vec_validate (im->integ_algs, IPSEC_INTEG_N_ALG - 1); |
| 353 | ipsec_main_integ_alg_t *i; |
| 354 | |
| 355 | i = &im->integ_algs[IPSEC_INTEG_ALG_SHA1_96]; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 356 | i->op_id = VNET_CRYPTO_OP_SHA1_HMAC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 357 | i->alg = VNET_CRYPTO_ALG_HMAC_SHA1; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 358 | i->icv_size = 12; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 359 | |
| 360 | i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_96]; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 361 | i->op_id = VNET_CRYPTO_OP_SHA1_HMAC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 362 | i->alg = VNET_CRYPTO_ALG_HMAC_SHA256; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 363 | i->icv_size = 12; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 364 | |
| 365 | i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_128]; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 366 | i->op_id = VNET_CRYPTO_OP_SHA256_HMAC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 367 | i->alg = VNET_CRYPTO_ALG_HMAC_SHA256; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 368 | i->icv_size = 16; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 369 | |
| 370 | i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_384_192]; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 371 | i->op_id = VNET_CRYPTO_OP_SHA384_HMAC; |
Damjan Marion | 4cb8381 | 2019-04-24 17:32:01 +0200 | [diff] [blame] | 372 | i->alg = VNET_CRYPTO_ALG_HMAC_SHA384; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 373 | i->icv_size = 24; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 374 | |
| 375 | i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_512_256]; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 376 | i->op_id = VNET_CRYPTO_OP_SHA512_HMAC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 377 | i->alg = VNET_CRYPTO_ALG_HMAC_SHA512; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 378 | i->icv_size = 32; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 379 | |
Neale Ranns | 5ae793a | 2019-04-03 13:36:56 +0000 | [diff] [blame] | 380 | vec_validate_aligned (im->ptd, vlib_num_workers (), CLIB_CACHE_LINE_BYTES); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 381 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | VLIB_INIT_FUNCTION (ipsec_init); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 386 | |
| 387 | /* |
| 388 | * fd.io coding-style-patch-verification: ON |
| 389 | * |
| 390 | * Local Variables: |
| 391 | * eval: (c-set-style "gnu") |
| 392 | * End: |
| 393 | */ |