FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
main.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2019 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #include <vlib/vlib.h>
19 #include <vnet/plugin/plugin.h>
20 #include <vnet/crypto/crypto.h>
22 
24 
25 static void
28 {
31 
32  /** TODO: add linked alg support **/
33  if (key->type == VNET_CRYPTO_KEY_TYPE_LINK)
34  return;
35 
36  if (cm->key_fn[key->alg] == 0)
37  return;
38 
39  if (kop == VNET_CRYPTO_KEY_OP_DEL)
40  {
41  if (idx >= vec_len (cm->key_data))
42  return;
43 
44  if (cm->key_data[idx] == 0)
45  return;
46 
47  clib_mem_free_s (cm->key_data[idx]);
48  cm->key_data[idx] = 0;
49  return;
50  }
51 
53 
54  if (kop == VNET_CRYPTO_KEY_OP_MODIFY && cm->key_data[idx])
55  {
56  clib_mem_free_s (cm->key_data[idx]);
57  }
58 
59  cm->key_data[idx] = cm->key_fn[key->alg] (key);
60 }
61 
64 {
67  clib_error_t *error = 0;
68 
69  if (clib_cpu_supports_x86_aes () == 0 &&
70  clib_cpu_supports_aarch64_aes () == 0)
71  return 0;
72 
73  vec_validate_aligned (cm->per_thread_data, tm->n_vlib_mains - 1,
75 
76  cm->crypto_engine_index =
77  vnet_crypto_register_engine (vm, "native", 100,
78  "Native ISA Optimized Crypto");
79 
80  if (0);
81 #if __x86_64__
82  else if (crypto_native_aes_cbc_init_icl && clib_cpu_supports_vaes ())
83  error = crypto_native_aes_cbc_init_icl (vm);
84  else if (crypto_native_aes_cbc_init_skx && clib_cpu_supports_avx512f ())
85  error = crypto_native_aes_cbc_init_skx (vm);
86  else if (crypto_native_aes_cbc_init_hsw && clib_cpu_supports_avx2 ())
87  error = crypto_native_aes_cbc_init_hsw (vm);
90 #endif
91 #if __aarch64__
92  else if (crypto_native_aes_cbc_init_neon)
93  error = crypto_native_aes_cbc_init_neon (vm);
94 #endif
95  else
96  error = clib_error_return (0, "No AES CBC implemenation available");
97 
98  if (error)
99  goto error;
100 
101 #if __x86_64__
102  if (clib_cpu_supports_pclmulqdq ())
103  {
104  if (crypto_native_aes_gcm_init_icl && clib_cpu_supports_vaes ())
105  error = crypto_native_aes_gcm_init_icl (vm);
106  else if (crypto_native_aes_gcm_init_skx && clib_cpu_supports_avx512f ())
107  error = crypto_native_aes_gcm_init_skx (vm);
108  else if (crypto_native_aes_gcm_init_hsw && clib_cpu_supports_avx2 ())
109  error = crypto_native_aes_gcm_init_hsw (vm);
112  else
113  error = clib_error_return (0, "No AES GCM implemenation available");
114 
115  if (error)
116  goto error;
117  }
118 #endif
119 #if __aarch64__
120  if (crypto_native_aes_gcm_init_neon)
121  error = crypto_native_aes_gcm_init_neon (vm);
122  else
123  error = clib_error_return (0, "No AES GCM implemenation available");
124 
125  if (error)
126  goto error;
127 #endif
128 
129  vnet_crypto_register_key_handler (vm, cm->crypto_engine_index,
131 
132 
133 error:
134  if (error)
135  vec_free (cm->per_thread_data);
136 
137  return error;
138 }
139 
140 /* *INDENT-OFF* */
142 {
143  .runs_after = VLIB_INITS ("vnet_crypto_init"),
144 };
145 /* *INDENT-ON* */
146 
147 #include <vpp/app/version.h>
148 
149 /* *INDENT-OFF* */
151  .version = VPP_BUILD_VER,
152  .description = "Intel IA32 Software Crypto Engine",
153 };
154 /* *INDENT-ON* */
155 
156 /*
157  * fd.io coding-style-patch-verification: ON
158  *
159  * Local Variables:
160  * eval: (c-set-style "gnu")
161  * End:
162  */
vlib.h
VNET_CRYPTO_KEY_OP_DEL
@ VNET_CRYPTO_KEY_OP_DEL
Definition: crypto.h:132
crypto_native_key_handler
static void crypto_native_key_handler(vlib_main_t *vm, vnet_crypto_key_op_t kop, vnet_crypto_key_index_t idx)
Definition: main.c:26
crypto.h
VNET_CRYPTO_KEY_OP_MODIFY
@ VNET_CRYPTO_KEY_OP_MODIFY
Definition: crypto.h:133
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
crypto_native_aes_gcm_init_slm
clib_error_t * crypto_native_aes_gcm_init_slm(vlib_main_t *vm)
Definition: aes_gcm.c:1211
vnet_crypto_key_index_t
u32 vnet_crypto_key_index_t
Definition: crypto.h:378
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
crypto_native_main_t
Definition: crypto_native.h:29
error
Definition: cJSON.c:88
vnet_crypto_register_engine
u32 vnet_crypto_register_engine(vlib_main_t *vm, char *name, int prio, char *desc)
Definition: crypto.c:112
key
typedef key
Definition: ipsec_types.api:88
vlib_thread_main_t::n_vlib_mains
u32 n_vlib_mains
Definition: threads.h:283
crypto_native_aes_cbc_init_slm
clib_error_t * crypto_native_aes_cbc_init_slm(vlib_main_t *vm)
Definition: aes_cbc.c:485
vec_len
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
Definition: vec_bootstrap.h:142
vec_validate_aligned
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:534
clib_mem_free_s
static void clib_mem_free_s(void *p)
Definition: mem.h:350
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:591
vnet_crypto_get_key
static_always_inline vnet_crypto_key_t * vnet_crypto_get_key(vnet_crypto_key_index_t index)
Definition: crypto.h:548
crypto_native.h
CLIB_CACHE_LINE_BYTES
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
plugin.h
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
vnet_crypto_register_key_handler
void vnet_crypto_register_key_handler(vlib_main_t *vm, u32 engine_index, vnet_crypto_key_handler_t *key_handler)
Definition: crypto.c:316
vnet_crypto_key_t
Definition: crypto.h:198
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vlib_thread_main_t
Definition: threads.h:264
vnet_crypto_key_op_t
vnet_crypto_key_op_t
Definition: crypto.h:129
vlib_main_t
Definition: main.h:102
VLIB_INITS
#define VLIB_INITS(...)
Definition: init.h:352
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
crypto_native_init
clib_error_t * crypto_native_init(vlib_main_t *vm)
Definition: main.c:63
crypto_native_main
crypto_native_main_t crypto_native_main
Definition: main.c:23
vlib_get_thread_main
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:56
VNET_CRYPTO_KEY_TYPE_LINK
#define VNET_CRYPTO_KEY_TYPE_LINK
Definition: crypto.h:215