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> |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 22 | #include <vnet/udp/udp_local.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> |
Zachary Leaf | b2d3678 | 2021-07-27 05:18:47 -0500 | [diff] [blame] | 27 | #include <vnet/ipsec/ipsec_tun.h> |
Sergio Gonzalez Monroy | a10f62b | 2016-11-25 13:36:12 +0000 | [diff] [blame] | 28 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 29 | ipsec_main_t ipsec_main; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 30 | esp_async_post_next_t esp_encrypt_async_next; |
| 31 | esp_async_post_next_t esp_decrypt_async_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | |
| 33 | static clib_error_t * |
Klement Sekera | 4fd5a9d | 2019-01-30 11:11:23 +0100 | [diff] [blame] | 34 | ipsec_check_ah_support (ipsec_sa_t * sa) |
| 35 | { |
Neale Ranns | ece2ae0 | 2019-06-21 12:44:11 +0000 | [diff] [blame] | 36 | ipsec_main_t *im = &ipsec_main; |
| 37 | |
Klement Sekera | 4fd5a9d | 2019-01-30 11:11:23 +0100 | [diff] [blame] | 38 | if (sa->integ_alg == IPSEC_INTEG_ALG_NONE) |
| 39 | return clib_error_return (0, "unsupported none integ-alg"); |
Neale Ranns | ece2ae0 | 2019-06-21 12:44:11 +0000 | [diff] [blame] | 40 | |
| 41 | if (!vnet_crypto_is_set_handler (im->integ_algs[sa->integ_alg].alg)) |
| 42 | return clib_error_return (0, "No crypto engine support for %U", |
| 43 | format_ipsec_integ_alg, sa->integ_alg); |
| 44 | |
Klement Sekera | 4fd5a9d | 2019-01-30 11:11:23 +0100 | [diff] [blame] | 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | static clib_error_t * |
| 49 | ipsec_check_esp_support (ipsec_sa_t * sa) |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 50 | { |
Neale Ranns | ece2ae0 | 2019-06-21 12:44:11 +0000 | [diff] [blame] | 51 | ipsec_main_t *im = &ipsec_main; |
| 52 | |
| 53 | if (IPSEC_INTEG_ALG_NONE != sa->integ_alg) |
| 54 | { |
| 55 | if (!vnet_crypto_is_set_handler (im->integ_algs[sa->integ_alg].alg)) |
| 56 | return clib_error_return (0, "No crypto engine support for %U", |
| 57 | format_ipsec_integ_alg, sa->integ_alg); |
| 58 | } |
| 59 | if (IPSEC_CRYPTO_ALG_NONE != sa->crypto_alg) |
| 60 | { |
| 61 | if (!vnet_crypto_is_set_handler (im->crypto_algs[sa->crypto_alg].alg)) |
| 62 | return clib_error_return (0, "No crypto engine support for %U", |
| 63 | format_ipsec_crypto_alg, sa->crypto_alg); |
| 64 | } |
| 65 | |
| 66 | return (0); |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 69 | clib_error_t * |
| 70 | ipsec_add_del_sa_sess_cb (ipsec_main_t * im, u32 sa_index, u8 is_add) |
| 71 | { |
| 72 | ipsec_ah_backend_t *ah = |
| 73 | pool_elt_at_index (im->ah_backends, im->ah_current_backend); |
| 74 | if (ah->add_del_sa_sess_cb) |
| 75 | { |
| 76 | clib_error_t *err = ah->add_del_sa_sess_cb (sa_index, is_add); |
| 77 | if (err) |
| 78 | return err; |
| 79 | } |
| 80 | ipsec_esp_backend_t *esp = |
| 81 | pool_elt_at_index (im->esp_backends, im->esp_current_backend); |
| 82 | if (esp->add_del_sa_sess_cb) |
| 83 | { |
| 84 | clib_error_t *err = esp->add_del_sa_sess_cb (sa_index, is_add); |
| 85 | if (err) |
| 86 | return err; |
| 87 | } |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | clib_error_t * |
| 92 | ipsec_check_support_cb (ipsec_main_t * im, ipsec_sa_t * sa) |
| 93 | { |
| 94 | clib_error_t *error = 0; |
Matthew Smith | 461caa5 | 2018-12-21 11:53:16 -0600 | [diff] [blame] | 95 | |
| 96 | if (PREDICT_FALSE (sa->protocol == IPSEC_PROTOCOL_AH)) |
| 97 | { |
| 98 | ipsec_ah_backend_t *ah = |
| 99 | pool_elt_at_index (im->ah_backends, im->ah_current_backend); |
| 100 | ASSERT (ah->check_support_cb); |
| 101 | error = ah->check_support_cb (sa); |
| 102 | } |
| 103 | else |
| 104 | { |
| 105 | ipsec_esp_backend_t *esp = |
| 106 | pool_elt_at_index (im->esp_backends, im->esp_current_backend); |
| 107 | ASSERT (esp->check_support_cb); |
| 108 | error = esp->check_support_cb (sa); |
| 109 | } |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 110 | return error; |
| 111 | } |
| 112 | |
| 113 | |
| 114 | static void |
| 115 | ipsec_add_node (vlib_main_t * vm, const char *node_name, |
| 116 | const char *prev_node_name, u32 * out_node_index, |
| 117 | u32 * out_next_index) |
| 118 | { |
| 119 | vlib_node_t *prev_node, *node; |
| 120 | prev_node = vlib_get_node_by_name (vm, (u8 *) prev_node_name); |
| 121 | ASSERT (prev_node); |
| 122 | node = vlib_get_node_by_name (vm, (u8 *) node_name); |
| 123 | ASSERT (node); |
| 124 | *out_node_index = node->index; |
| 125 | *out_next_index = vlib_node_add_next (vm, prev_node->index, node->index); |
| 126 | } |
| 127 | |
Neale Ranns | abc5660 | 2020-04-01 09:45:23 +0000 | [diff] [blame] | 128 | void |
Neale Ranns | abc5660 | 2020-04-01 09:45:23 +0000 | [diff] [blame] | 129 | ipsec_unregister_udp_port (u16 port) |
| 130 | { |
| 131 | ipsec_main_t *im = &ipsec_main; |
| 132 | u32 n_regs; |
| 133 | uword *p; |
| 134 | |
| 135 | p = hash_get (im->udp_port_registrations, port); |
| 136 | |
| 137 | ASSERT (p); |
| 138 | |
| 139 | n_regs = p[0]; |
| 140 | |
| 141 | if (0 == --n_regs) |
| 142 | { |
| 143 | udp_unregister_dst_port (vlib_get_main (), port, 1); |
| 144 | hash_unset (im->udp_port_registrations, port); |
| 145 | } |
| 146 | else |
| 147 | { |
| 148 | hash_unset (im->udp_port_registrations, port); |
| 149 | hash_set (im->udp_port_registrations, port, n_regs); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void |
| 154 | ipsec_register_udp_port (u16 port) |
| 155 | { |
| 156 | ipsec_main_t *im = &ipsec_main; |
| 157 | u32 n_regs; |
| 158 | uword *p; |
| 159 | |
| 160 | p = hash_get (im->udp_port_registrations, port); |
| 161 | |
| 162 | n_regs = (p ? p[0] : 0); |
| 163 | |
| 164 | if (0 == n_regs++) |
| 165 | udp_register_dst_port (vlib_get_main (), port, |
| 166 | ipsec4_tun_input_node.index, 1); |
| 167 | |
| 168 | hash_unset (im->udp_port_registrations, port); |
| 169 | hash_set (im->udp_port_registrations, port, n_regs); |
| 170 | } |
| 171 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 172 | u32 |
| 173 | ipsec_register_ah_backend (vlib_main_t * vm, ipsec_main_t * im, |
| 174 | const char *name, |
| 175 | const char *ah4_encrypt_node_name, |
| 176 | const char *ah4_decrypt_node_name, |
| 177 | const char *ah6_encrypt_node_name, |
| 178 | const char *ah6_decrypt_node_name, |
| 179 | check_support_cb_t ah_check_support_cb, |
| 180 | add_del_sa_sess_cb_t ah_add_del_sa_sess_cb) |
| 181 | { |
| 182 | ipsec_ah_backend_t *b; |
| 183 | pool_get (im->ah_backends, b); |
Kingwel Xie | 561d1ca | 2019-03-05 22:56:17 -0500 | [diff] [blame] | 184 | b->name = format (0, "%s%c", name, 0); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 185 | |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 186 | ipsec_add_node (vm, ah4_encrypt_node_name, "ipsec4-output-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 187 | &b->ah4_encrypt_node_index, &b->ah4_encrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 188 | ipsec_add_node (vm, ah4_decrypt_node_name, "ipsec4-input-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 189 | &b->ah4_decrypt_node_index, &b->ah4_decrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 190 | ipsec_add_node (vm, ah6_encrypt_node_name, "ipsec6-output-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 191 | &b->ah6_encrypt_node_index, &b->ah6_encrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 192 | ipsec_add_node (vm, ah6_decrypt_node_name, "ipsec6-input-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 193 | &b->ah6_decrypt_node_index, &b->ah6_decrypt_next_index); |
| 194 | |
| 195 | b->check_support_cb = ah_check_support_cb; |
| 196 | b->add_del_sa_sess_cb = ah_add_del_sa_sess_cb; |
| 197 | return b - im->ah_backends; |
| 198 | } |
| 199 | |
| 200 | u32 |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 201 | ipsec_register_esp_backend ( |
| 202 | vlib_main_t *vm, ipsec_main_t *im, const char *name, |
| 203 | const char *esp4_encrypt_node_name, const char *esp4_encrypt_node_tun_name, |
| 204 | const char *esp4_decrypt_node_name, const char *esp4_decrypt_tun_node_name, |
| 205 | const char *esp6_encrypt_node_name, const char *esp6_encrypt_node_tun_name, |
| 206 | const char *esp6_decrypt_node_name, const char *esp6_decrypt_tun_node_name, |
| 207 | const char *esp_mpls_encrypt_node_tun_name, |
| 208 | check_support_cb_t esp_check_support_cb, |
| 209 | add_del_sa_sess_cb_t esp_add_del_sa_sess_cb, |
| 210 | enable_disable_cb_t enable_disable_cb) |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 211 | { |
| 212 | ipsec_esp_backend_t *b; |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 213 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 214 | pool_get (im->esp_backends, b); |
Kingwel Xie | 561d1ca | 2019-03-05 22:56:17 -0500 | [diff] [blame] | 215 | b->name = format (0, "%s%c", name, 0); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 216 | |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 217 | ipsec_add_node (vm, esp4_encrypt_node_name, "ipsec4-output-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 218 | &b->esp4_encrypt_node_index, &b->esp4_encrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 219 | ipsec_add_node (vm, esp4_decrypt_node_name, "ipsec4-input-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 220 | &b->esp4_decrypt_node_index, &b->esp4_decrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 221 | ipsec_add_node (vm, esp6_encrypt_node_name, "ipsec6-output-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 222 | &b->esp6_encrypt_node_index, &b->esp6_encrypt_next_index); |
Pierre Pfister | 057b356 | 2018-12-10 17:01:01 +0100 | [diff] [blame] | 223 | ipsec_add_node (vm, esp6_decrypt_node_name, "ipsec6-input-feature", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 224 | &b->esp6_decrypt_node_index, &b->esp6_decrypt_next_index); |
Neale Ranns | 7ec120e | 2020-01-21 04:58:02 +0000 | [diff] [blame] | 225 | ipsec_add_node (vm, esp4_decrypt_tun_node_name, "ipsec4-tun-input", |
| 226 | &b->esp4_decrypt_tun_node_index, |
| 227 | &b->esp4_decrypt_tun_next_index); |
| 228 | ipsec_add_node (vm, esp6_decrypt_tun_node_name, "ipsec6-tun-input", |
| 229 | &b->esp6_decrypt_tun_node_index, |
| 230 | &b->esp6_decrypt_tun_next_index); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 231 | |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 232 | b->esp6_encrypt_tun_node_index = |
| 233 | vlib_get_node_by_name (vm, (u8 *) esp6_encrypt_node_tun_name)->index; |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 234 | b->esp_mpls_encrypt_tun_node_index = |
| 235 | vlib_get_node_by_name (vm, (u8 *) esp_mpls_encrypt_node_tun_name)->index; |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 236 | b->esp4_encrypt_tun_node_index = |
| 237 | vlib_get_node_by_name (vm, (u8 *) esp4_encrypt_node_tun_name)->index; |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 238 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 239 | b->check_support_cb = esp_check_support_cb; |
| 240 | b->add_del_sa_sess_cb = esp_add_del_sa_sess_cb; |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 241 | b->enable_disable_cb = enable_disable_cb; |
| 242 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 243 | return b - im->esp_backends; |
| 244 | } |
| 245 | |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 246 | clib_error_t * |
| 247 | ipsec_rsc_in_use (ipsec_main_t * im) |
Neale Ranns | b4cfd55 | 2019-02-13 02:08:06 -0800 | [diff] [blame] | 248 | { |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 249 | /* return an error is crypto resource are in use */ |
Neale Ranns | c5fe57d | 2021-02-25 16:01:28 +0000 | [diff] [blame] | 250 | if (pool_elts (ipsec_sa_pool) > 0) |
| 251 | return clib_error_return (0, "%d SA entries configured", |
| 252 | pool_elts (ipsec_sa_pool)); |
Neale Ranns | b4cfd55 | 2019-02-13 02:08:06 -0800 | [diff] [blame] | 253 | |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 254 | return (NULL); |
Neale Ranns | b4cfd55 | 2019-02-13 02:08:06 -0800 | [diff] [blame] | 255 | } |
| 256 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 257 | int |
| 258 | ipsec_select_ah_backend (ipsec_main_t * im, u32 backend_idx) |
| 259 | { |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 260 | if (ipsec_rsc_in_use (im)) |
| 261 | return VNET_API_ERROR_RSRC_IN_USE; |
| 262 | |
| 263 | if (pool_is_free_index (im->ah_backends, backend_idx)) |
| 264 | return VNET_API_ERROR_INVALID_VALUE; |
| 265 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 266 | ipsec_ah_backend_t *b = pool_elt_at_index (im->ah_backends, backend_idx); |
| 267 | im->ah_current_backend = backend_idx; |
| 268 | im->ah4_encrypt_node_index = b->ah4_encrypt_node_index; |
| 269 | im->ah4_decrypt_node_index = b->ah4_decrypt_node_index; |
| 270 | im->ah4_encrypt_next_index = b->ah4_encrypt_next_index; |
| 271 | im->ah4_decrypt_next_index = b->ah4_decrypt_next_index; |
| 272 | im->ah6_encrypt_node_index = b->ah6_encrypt_node_index; |
| 273 | im->ah6_decrypt_node_index = b->ah6_decrypt_node_index; |
| 274 | im->ah6_encrypt_next_index = b->ah6_encrypt_next_index; |
| 275 | im->ah6_decrypt_next_index = b->ah6_decrypt_next_index; |
Neale Ranns | b4cfd55 | 2019-02-13 02:08:06 -0800 | [diff] [blame] | 276 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | int |
| 281 | ipsec_select_esp_backend (ipsec_main_t * im, u32 backend_idx) |
| 282 | { |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 283 | if (ipsec_rsc_in_use (im)) |
| 284 | return VNET_API_ERROR_RSRC_IN_USE; |
| 285 | |
| 286 | if (pool_is_free_index (im->esp_backends, backend_idx)) |
| 287 | return VNET_API_ERROR_INVALID_VALUE; |
| 288 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 289 | /* disable current backend */ |
| 290 | if (im->esp_current_backend != ~0) |
| 291 | { |
| 292 | ipsec_esp_backend_t *cb = pool_elt_at_index (im->esp_backends, |
| 293 | im->esp_current_backend); |
| 294 | if (cb->enable_disable_cb) |
| 295 | { |
| 296 | if ((cb->enable_disable_cb) (0) != 0) |
| 297 | return -1; |
| 298 | } |
| 299 | } |
| 300 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 301 | ipsec_esp_backend_t *b = pool_elt_at_index (im->esp_backends, backend_idx); |
| 302 | im->esp_current_backend = backend_idx; |
| 303 | im->esp4_encrypt_node_index = b->esp4_encrypt_node_index; |
| 304 | im->esp4_decrypt_node_index = b->esp4_decrypt_node_index; |
| 305 | im->esp4_encrypt_next_index = b->esp4_encrypt_next_index; |
| 306 | im->esp4_decrypt_next_index = b->esp4_decrypt_next_index; |
| 307 | im->esp6_encrypt_node_index = b->esp6_encrypt_node_index; |
| 308 | im->esp6_decrypt_node_index = b->esp6_decrypt_node_index; |
| 309 | im->esp6_encrypt_next_index = b->esp6_encrypt_next_index; |
| 310 | im->esp6_decrypt_next_index = b->esp6_decrypt_next_index; |
Neale Ranns | 7ec120e | 2020-01-21 04:58:02 +0000 | [diff] [blame] | 311 | im->esp4_decrypt_tun_node_index = b->esp4_decrypt_tun_node_index; |
| 312 | im->esp4_decrypt_tun_next_index = b->esp4_decrypt_tun_next_index; |
| 313 | im->esp6_decrypt_tun_node_index = b->esp6_decrypt_tun_node_index; |
| 314 | im->esp6_decrypt_tun_next_index = b->esp6_decrypt_tun_next_index; |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 315 | im->esp4_encrypt_tun_node_index = b->esp4_encrypt_tun_node_index; |
| 316 | im->esp6_encrypt_tun_node_index = b->esp6_encrypt_tun_node_index; |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 317 | im->esp_mpls_encrypt_tun_node_index = b->esp_mpls_encrypt_tun_node_index; |
Neale Ranns | e8915fc | 2019-04-23 20:57:55 -0400 | [diff] [blame] | 318 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 319 | if (b->enable_disable_cb) |
| 320 | { |
| 321 | if ((b->enable_disable_cb) (1) != 0) |
| 322 | return -1; |
| 323 | } |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 324 | return 0; |
| 325 | } |
| 326 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 327 | void |
| 328 | ipsec_set_async_mode (u32 is_enabled) |
| 329 | { |
| 330 | ipsec_main_t *im = &ipsec_main; |
| 331 | ipsec_sa_t *sa; |
| 332 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 333 | vnet_crypto_request_async_mode (is_enabled); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 334 | |
| 335 | im->async_mode = is_enabled; |
| 336 | |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 337 | /* change SA crypto op data */ |
Neale Ranns | c5fe57d | 2021-02-25 16:01:28 +0000 | [diff] [blame] | 338 | pool_foreach (sa, ipsec_sa_pool) |
| 339 | { |
| 340 | sa->crypto_op_data = |
Neale Ranns | f16e9a5 | 2021-02-25 19:09:24 +0000 | [diff] [blame] | 341 | (is_enabled ? sa->async_op_data.data : sa->sync_op_data.data); |
Neale Ranns | c5fe57d | 2021-02-25 16:01:28 +0000 | [diff] [blame] | 342 | } |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | static void |
| 346 | crypto_engine_backend_register_post_node (vlib_main_t * vm) |
| 347 | { |
| 348 | esp_async_post_next_t *eit; |
| 349 | esp_async_post_next_t *dit; |
| 350 | |
| 351 | eit = &esp_encrypt_async_next; |
| 352 | eit->esp4_post_next = |
| 353 | vnet_crypto_register_post_node (vm, "esp4-encrypt-post"); |
| 354 | eit->esp6_post_next = |
| 355 | vnet_crypto_register_post_node (vm, "esp6-encrypt-post"); |
| 356 | eit->esp4_tun_post_next = |
| 357 | vnet_crypto_register_post_node (vm, "esp4-encrypt-tun-post"); |
| 358 | eit->esp6_tun_post_next = |
| 359 | vnet_crypto_register_post_node (vm, "esp6-encrypt-tun-post"); |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 360 | eit->esp_mpls_tun_post_next = |
| 361 | vnet_crypto_register_post_node (vm, "esp-mpls-encrypt-tun-post"); |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 362 | |
| 363 | dit = &esp_decrypt_async_next; |
| 364 | dit->esp4_post_next = |
| 365 | vnet_crypto_register_post_node (vm, "esp4-decrypt-post"); |
| 366 | dit->esp6_post_next = |
| 367 | vnet_crypto_register_post_node (vm, "esp6-decrypt-post"); |
| 368 | dit->esp4_tun_post_next = |
| 369 | vnet_crypto_register_post_node (vm, "esp4-decrypt-tun-post"); |
| 370 | dit->esp6_tun_post_next = |
| 371 | vnet_crypto_register_post_node (vm, "esp6-decrypt-tun-post"); |
| 372 | } |
| 373 | |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 374 | static clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 375 | ipsec_init (vlib_main_t * vm) |
| 376 | { |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 377 | clib_error_t *error; |
| 378 | ipsec_main_t *im = &ipsec_main; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 379 | ipsec_main_crypto_alg_t *a; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | |
Dave Barach | 0dd9165 | 2019-05-05 13:34:28 -0400 | [diff] [blame] | 381 | /* Backend registration requires the feature arcs to be set up */ |
| 382 | if ((error = vlib_call_init_function (vm, vnet_feature_init))) |
| 383 | return (error); |
| 384 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 385 | im->vnet_main = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 386 | im->vlib_main = vm; |
| 387 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 388 | im->spd_index_by_spd_id = hash_create (0, sizeof (uword)); |
| 389 | im->sa_index_by_sa_id = hash_create (0, sizeof (uword)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 390 | im->spd_index_by_sw_if_index = hash_create (0, sizeof (uword)); |
| 391 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 392 | 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] | 393 | ASSERT (node); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 394 | im->error_drop_node_index = node->index; |
| 395 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 396 | im->ah_current_backend = ~0; |
| 397 | im->esp_current_backend = ~0; |
| 398 | |
Neale Ranns | d1a5b2d | 2019-05-16 17:09:28 +0000 | [diff] [blame] | 399 | u32 idx = ipsec_register_ah_backend (vm, im, "crypto engine backend", |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 400 | "ah4-encrypt", |
| 401 | "ah4-decrypt", |
| 402 | "ah6-encrypt", |
| 403 | "ah6-decrypt", |
Klement Sekera | 4fd5a9d | 2019-01-30 11:11:23 +0100 | [diff] [blame] | 404 | ipsec_check_ah_support, |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 405 | NULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 406 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 407 | im->ah_default_backend = idx; |
| 408 | int rv = ipsec_select_ah_backend (im, idx); |
| 409 | ASSERT (0 == rv); |
| 410 | (void) (rv); // avoid warning |
Sergio Gonzalez Monroy | d04b60b | 2017-01-20 15:35:23 +0000 | [diff] [blame] | 411 | |
Neale Ranns | 4a58e49 | 2020-12-21 13:19:10 +0000 | [diff] [blame] | 412 | idx = ipsec_register_esp_backend ( |
| 413 | vm, im, "crypto engine backend", "esp4-encrypt", "esp4-encrypt-tun", |
| 414 | "esp4-decrypt", "esp4-decrypt-tun", "esp6-encrypt", "esp6-encrypt-tun", |
| 415 | "esp6-decrypt", "esp6-decrypt-tun", "esp-mpls-encrypt-tun", |
| 416 | ipsec_check_esp_support, NULL, crypto_dispatch_enable_disable); |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 417 | im->esp_default_backend = idx; |
“mukeshyadav1984” | 430ac93 | 2017-11-23 02:39:33 -0800 | [diff] [blame] | 418 | |
Klement Sekera | b4d3053 | 2018-11-08 13:00:02 +0100 | [diff] [blame] | 419 | rv = ipsec_select_esp_backend (im, idx); |
| 420 | ASSERT (0 == rv); |
| 421 | (void) (rv); // avoid warning |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 422 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 423 | if ((error = vlib_call_init_function (vm, ipsec_cli_init))) |
| 424 | return error; |
| 425 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 426 | vec_validate (im->crypto_algs, IPSEC_CRYPTO_N_ALG - 1); |
| 427 | |
Neale Ranns | 2cdcd0c | 2019-08-27 12:26:14 +0000 | [diff] [blame] | 428 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_NONE; |
| 429 | a->enc_op_id = VNET_CRYPTO_OP_NONE; |
| 430 | a->dec_op_id = VNET_CRYPTO_OP_NONE; |
| 431 | a->alg = VNET_CRYPTO_ALG_NONE; |
| 432 | a->iv_size = 0; |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 433 | a->block_align = 1; |
Neale Ranns | 2cdcd0c | 2019-08-27 12:26:14 +0000 | [diff] [blame] | 434 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 435 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_DES_CBC; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 436 | a->enc_op_id = VNET_CRYPTO_OP_DES_CBC_ENC; |
| 437 | a->dec_op_id = VNET_CRYPTO_OP_DES_CBC_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 438 | a->alg = VNET_CRYPTO_ALG_DES_CBC; |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 439 | a->iv_size = a->block_align = 8; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 440 | |
| 441 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_3DES_CBC; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 442 | a->enc_op_id = VNET_CRYPTO_OP_3DES_CBC_ENC; |
| 443 | a->dec_op_id = VNET_CRYPTO_OP_3DES_CBC_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 444 | a->alg = VNET_CRYPTO_ALG_3DES_CBC; |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 445 | a->iv_size = a->block_align = 8; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 446 | |
| 447 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_128; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 448 | a->enc_op_id = VNET_CRYPTO_OP_AES_128_CBC_ENC; |
| 449 | a->dec_op_id = VNET_CRYPTO_OP_AES_128_CBC_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 450 | a->alg = VNET_CRYPTO_ALG_AES_128_CBC; |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 451 | a->iv_size = a->block_align = 16; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 452 | |
| 453 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_192; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 454 | a->enc_op_id = VNET_CRYPTO_OP_AES_192_CBC_ENC; |
| 455 | a->dec_op_id = VNET_CRYPTO_OP_AES_192_CBC_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 456 | a->alg = VNET_CRYPTO_ALG_AES_192_CBC; |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 457 | a->iv_size = a->block_align = 16; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 458 | |
| 459 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CBC_256; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 460 | a->enc_op_id = VNET_CRYPTO_OP_AES_256_CBC_ENC; |
| 461 | a->dec_op_id = VNET_CRYPTO_OP_AES_256_CBC_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 462 | a->alg = VNET_CRYPTO_ALG_AES_256_CBC; |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 463 | a->iv_size = a->block_align = 16; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 464 | |
Benoît Ganne | 490b927 | 2021-01-22 18:03:09 +0100 | [diff] [blame] | 465 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CTR_128; |
| 466 | a->enc_op_id = VNET_CRYPTO_OP_AES_128_CTR_ENC; |
| 467 | a->dec_op_id = VNET_CRYPTO_OP_AES_128_CTR_DEC; |
| 468 | a->alg = VNET_CRYPTO_ALG_AES_128_CTR; |
| 469 | a->iv_size = 8; |
| 470 | a->block_align = 1; |
| 471 | |
| 472 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CTR_192; |
| 473 | a->enc_op_id = VNET_CRYPTO_OP_AES_192_CTR_ENC; |
| 474 | a->dec_op_id = VNET_CRYPTO_OP_AES_192_CTR_DEC; |
| 475 | a->alg = VNET_CRYPTO_ALG_AES_192_CTR; |
| 476 | a->iv_size = 8; |
| 477 | a->block_align = 1; |
| 478 | |
| 479 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_CTR_256; |
| 480 | a->enc_op_id = VNET_CRYPTO_OP_AES_256_CTR_ENC; |
| 481 | a->dec_op_id = VNET_CRYPTO_OP_AES_256_CTR_DEC; |
| 482 | a->alg = VNET_CRYPTO_ALG_AES_256_CTR; |
| 483 | a->iv_size = 8; |
| 484 | a->block_align = 1; |
| 485 | |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 486 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_128; |
| 487 | a->enc_op_id = VNET_CRYPTO_OP_AES_128_GCM_ENC; |
| 488 | a->dec_op_id = VNET_CRYPTO_OP_AES_128_GCM_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 489 | a->alg = VNET_CRYPTO_ALG_AES_128_GCM; |
Damjan Marion | f1ecb65 | 2020-02-10 19:21:14 +0100 | [diff] [blame] | 490 | a->iv_size = 8; |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 491 | a->block_align = 1; |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 492 | a->icv_size = 16; |
| 493 | |
| 494 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_192; |
| 495 | a->enc_op_id = VNET_CRYPTO_OP_AES_192_GCM_ENC; |
| 496 | a->dec_op_id = VNET_CRYPTO_OP_AES_192_GCM_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 497 | a->alg = VNET_CRYPTO_ALG_AES_192_GCM; |
Damjan Marion | f1ecb65 | 2020-02-10 19:21:14 +0100 | [diff] [blame] | 498 | a->iv_size = 8; |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 499 | a->block_align = 1; |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 500 | a->icv_size = 16; |
| 501 | |
| 502 | a = im->crypto_algs + IPSEC_CRYPTO_ALG_AES_GCM_256; |
| 503 | a->enc_op_id = VNET_CRYPTO_OP_AES_256_GCM_ENC; |
| 504 | a->dec_op_id = VNET_CRYPTO_OP_AES_256_GCM_DEC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 505 | a->alg = VNET_CRYPTO_ALG_AES_256_GCM; |
Damjan Marion | f1ecb65 | 2020-02-10 19:21:14 +0100 | [diff] [blame] | 506 | a->iv_size = 8; |
Christian Hopps | fb7e7ed | 2019-11-03 07:02:15 -0500 | [diff] [blame] | 507 | a->block_align = 1; |
Neale Ranns | 47feb11 | 2019-04-11 15:14:07 +0000 | [diff] [blame] | 508 | a->icv_size = 16; |
| 509 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 510 | vec_validate (im->integ_algs, IPSEC_INTEG_N_ALG - 1); |
| 511 | ipsec_main_integ_alg_t *i; |
| 512 | |
Dmitry Vakhrushev | 77cc14a | 2019-08-14 00:12:33 -0400 | [diff] [blame] | 513 | i = &im->integ_algs[IPSEC_INTEG_ALG_MD5_96]; |
| 514 | i->op_id = VNET_CRYPTO_OP_MD5_HMAC; |
| 515 | i->alg = VNET_CRYPTO_ALG_HMAC_MD5; |
| 516 | i->icv_size = 12; |
| 517 | |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 518 | i = &im->integ_algs[IPSEC_INTEG_ALG_SHA1_96]; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 519 | i->op_id = VNET_CRYPTO_OP_SHA1_HMAC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 520 | i->alg = VNET_CRYPTO_ALG_HMAC_SHA1; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 521 | i->icv_size = 12; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 522 | |
| 523 | i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_96]; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 524 | i->op_id = VNET_CRYPTO_OP_SHA1_HMAC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 525 | i->alg = VNET_CRYPTO_ALG_HMAC_SHA256; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 526 | i->icv_size = 12; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 527 | |
| 528 | i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_256_128]; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 529 | i->op_id = VNET_CRYPTO_OP_SHA256_HMAC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 530 | i->alg = VNET_CRYPTO_ALG_HMAC_SHA256; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 531 | i->icv_size = 16; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 532 | |
| 533 | i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_384_192]; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 534 | i->op_id = VNET_CRYPTO_OP_SHA384_HMAC; |
Damjan Marion | 4cb8381 | 2019-04-24 17:32:01 +0200 | [diff] [blame] | 535 | i->alg = VNET_CRYPTO_ALG_HMAC_SHA384; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 536 | i->icv_size = 24; |
Damjan Marion | 91f17dc | 2019-03-18 18:59:25 +0100 | [diff] [blame] | 537 | |
| 538 | i = &im->integ_algs[IPSEC_INTEG_ALG_SHA_512_256]; |
Damjan Marion | 060bfb9 | 2019-03-29 13:47:54 +0100 | [diff] [blame] | 539 | i->op_id = VNET_CRYPTO_OP_SHA512_HMAC; |
Damjan Marion | d1bed68 | 2019-04-24 15:20:35 +0200 | [diff] [blame] | 540 | i->alg = VNET_CRYPTO_ALG_HMAC_SHA512; |
Damjan Marion | 7c22ff7 | 2019-04-04 12:25:44 +0200 | [diff] [blame] | 541 | i->icv_size = 32; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 542 | |
Neale Ranns | 5ae793a | 2019-04-03 13:36:56 +0000 | [diff] [blame] | 543 | vec_validate_aligned (im->ptd, vlib_num_workers (), CLIB_CACHE_LINE_BYTES); |
Damjan Marion | c59b9a2 | 2019-03-19 15:38:40 +0100 | [diff] [blame] | 544 | |
Fan Zhang | f539578 | 2020-04-29 14:00:03 +0100 | [diff] [blame] | 545 | im->async_mode = 0; |
| 546 | crypto_engine_backend_register_post_node (vm); |
| 547 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | VLIB_INIT_FUNCTION (ipsec_init); |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 552 | |
Zachary Leaf | b2d3678 | 2021-07-27 05:18:47 -0500 | [diff] [blame] | 553 | static clib_error_t * |
| 554 | ipsec_config (vlib_main_t *vm, unformat_input_t *input) |
| 555 | { |
| 556 | unformat_input_t sub_input; |
| 557 | |
| 558 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 559 | { |
| 560 | if (unformat (input, "ip4 %U", unformat_vlib_cli_sub_input, &sub_input)) |
| 561 | { |
| 562 | uword table_size = ~0; |
| 563 | u32 n_buckets = ~0; |
| 564 | |
| 565 | while (unformat_check_input (&sub_input) != UNFORMAT_END_OF_INPUT) |
| 566 | { |
| 567 | if (unformat (&sub_input, "num-buckets %u", &n_buckets)) |
| 568 | ; |
| 569 | else |
| 570 | return clib_error_return (0, "unknown input `%U'", |
| 571 | format_unformat_error, &sub_input); |
| 572 | } |
| 573 | |
| 574 | ipsec_tun_table_init (AF_IP4, table_size, n_buckets); |
| 575 | } |
| 576 | else if (unformat (input, "ip6 %U", unformat_vlib_cli_sub_input, |
| 577 | &sub_input)) |
| 578 | { |
| 579 | uword table_size = ~0; |
| 580 | u32 n_buckets = ~0; |
| 581 | |
| 582 | while (unformat_check_input (&sub_input) != UNFORMAT_END_OF_INPUT) |
| 583 | { |
| 584 | if (unformat (&sub_input, "num-buckets %u", &n_buckets)) |
| 585 | ; |
| 586 | else |
| 587 | return clib_error_return (0, "unknown input `%U'", |
| 588 | format_unformat_error, &sub_input); |
| 589 | } |
| 590 | |
| 591 | ipsec_tun_table_init (AF_IP6, table_size, n_buckets); |
| 592 | } |
| 593 | else |
| 594 | return clib_error_return (0, "unknown input `%U'", |
| 595 | format_unformat_error, input); |
| 596 | } |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | VLIB_CONFIG_FUNCTION (ipsec_config, "ipsec"); |
| 602 | |
Keith Burns (alagalah) | 166a9d4 | 2016-08-06 11:00:56 -0700 | [diff] [blame] | 603 | /* |
| 604 | * fd.io coding-style-patch-verification: ON |
| 605 | * |
| 606 | * Local Variables: |
| 607 | * eval: (c-set-style "gnu") |
| 608 | * End: |
| 609 | */ |