|
| 1 | +/* |
| 2 | + * config.c: crypto engines configuration |
| 3 | + * |
| 4 | + * Copyright (c) 2025 Cisco and/or its affiliates. |
| 5 | + * SPDX-License-Identifier: Apache-2.0 |
| 6 | + * https://spdx.org/licenses/Apache-2.0.html |
| 7 | + */ |
| 8 | + |
| 9 | +#include <vlib/vlib.h> |
| 10 | +#include <vnet/crypto/crypto.h> |
| 11 | + |
| 12 | +static clib_error_t * |
| 13 | +config_one_crypto (vlib_main_t *vm, char *name, unformat_input_t *input) |
| 14 | +{ |
| 15 | + vnet_crypto_main_t *cm = &crypto_main; |
| 16 | + vnet_crypto_config_t *pc; |
| 17 | + clib_error_t *error = 0; |
| 18 | + uword *p; |
| 19 | + int is_enable = 0; |
| 20 | + int is_disable = 0; |
| 21 | + |
| 22 | + if (cm->config_index_by_name == 0) |
| 23 | + cm->config_index_by_name = hash_create_string (0, sizeof (uword)); |
| 24 | + |
| 25 | + p = hash_get_mem (cm->config_index_by_name, name); |
| 26 | + if (p) |
| 27 | + { |
| 28 | + error = clib_error_return (0, "crypto '%s' already configured", name); |
| 29 | + goto done; |
| 30 | + } |
| 31 | + |
| 32 | + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 33 | + { |
| 34 | + if (unformat (input, "enable")) |
| 35 | + is_enable = 1; |
| 36 | + else if (unformat (input, "disable")) |
| 37 | + is_disable = 1; |
| 38 | + else |
| 39 | + { |
| 40 | + error = clib_error_return (0, "unknown input '%U'", |
| 41 | + format_unformat_error, input); |
| 42 | + goto done; |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + if (is_enable && is_disable) |
| 47 | + { |
| 48 | + error = clib_error_return (0, |
| 49 | + "please specify either enable or disable" |
| 50 | + " for crypto '%s'", |
| 51 | + name); |
| 52 | + goto done; |
| 53 | + } |
| 54 | + |
| 55 | + vec_add2 (cm->configs, pc, 1); |
| 56 | + pc->is_enabled = is_enable; |
| 57 | + pc->is_disabled = is_disable; |
| 58 | + pc->name = vec_dup (name); |
| 59 | + hash_set_mem (cm->config_index_by_name, pc->name, pc - cm->configs); |
| 60 | + |
| 61 | +done: |
| 62 | + return error; |
| 63 | +} |
| 64 | + |
| 65 | +static clib_error_t * |
| 66 | +crypto_engines_config (vlib_main_t *vm, unformat_input_t *input) |
| 67 | +{ |
| 68 | + vnet_crypto_main_t *cm = &crypto_main; |
| 69 | + clib_error_t *error = 0; |
| 70 | + |
| 71 | + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 72 | + { |
| 73 | + unformat_input_t sub_input; |
| 74 | + u8 *s = 0; |
| 75 | + if (unformat (input, "default %U", unformat_vlib_cli_sub_input, |
| 76 | + &sub_input)) |
| 77 | + { |
| 78 | + cm->default_disabled = unformat (&sub_input, "disable") ? 1 : 0; |
| 79 | + unformat_free (&sub_input); |
| 80 | + } |
| 81 | + else if (unformat (input, "%s %U", &s, unformat_vlib_cli_sub_input, |
| 82 | + &sub_input)) |
| 83 | + { |
| 84 | + error = config_one_crypto (vm, (char *) s, &sub_input); |
| 85 | + vec_free (s); |
| 86 | + unformat_free (&sub_input); |
| 87 | + if (error) |
| 88 | + goto done; |
| 89 | + } |
| 90 | + else |
| 91 | + { |
| 92 | + error = clib_error_return (0, "unknown input '%U'", |
| 93 | + format_unformat_error, input); |
| 94 | + { |
| 95 | + vec_free (s); |
| 96 | + goto done; |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | +done: |
| 102 | + return error; |
| 103 | +} |
| 104 | + |
| 105 | +VLIB_EARLY_CONFIG_FUNCTION (crypto_engines_config, "crypto-engines"); |
0 commit comments