FD.io VPP  v17.04.2-2-ga8f93f8
Vector Packet Processing
ipsec.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Intel and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __DPDK_IPSEC_H__
16 #define __DPDK_IPSEC_H__
17 
18 #include <vnet/vnet.h>
19 
20 #undef always_inline
21 #include <rte_config.h>
22 #include <rte_crypto.h>
23 #include <rte_cryptodev.h>
24 
25 #if CLIB_DEBUG > 0
26 #define always_inline static inline
27 #else
28 #define always_inline static inline __attribute__ ((__always_inline__))
29 #endif
30 
31 
32 #define MAX_QP_PER_LCORE 16
33 
34 typedef struct
35 {
37  u32 iv[2];
40 
41 typedef struct
42 {
44  union
45  {
46  u8 aad[12];
47  u8 icv[64];
48  };
50 
51 typedef struct
52 {
57 
58 typedef struct
59 {
65  struct rte_crypto_op *cops[VLIB_FRAME_SIZE];
66  struct rte_crypto_op **free_cops;
68 
69 typedef struct
70 {
72  void *sess;
74 
75 typedef struct
76 {
77  crypto_sa_session_t *sa_sess_d[2];
81 
82 typedef struct
83 {
84  struct rte_mempool **cop_pools;
87 
89 
91 
92 #define CRYPTO_N_FREE_COPS (VLIB_FRAME_SIZE * 3)
93 
96 {
98  u32 cpu_index = os_get_cpu_number ();
99  crypto_worker_main_t *cwm = &dcm->workers_main[cpu_index];
100  unsigned socket_id = rte_socket_id ();
101  crypto_qp_data_t *qpd;
102 
103  /* *INDENT-OFF* */
104  vec_foreach (qpd, cwm->qp_data)
105  {
106  u32 l = vec_len (qpd->free_cops);
107 
108  if (PREDICT_FALSE (l < VLIB_FRAME_SIZE))
109  {
110  u32 n_alloc;
111 
112  if (PREDICT_FALSE (!qpd->free_cops))
114 
115  n_alloc = rte_crypto_op_bulk_alloc (dcm->cop_pools[socket_id],
116  RTE_CRYPTO_OP_TYPE_SYMMETRIC,
117  &qpd->free_cops[l],
118  CRYPTO_N_FREE_COPS - l - 1);
119 
120  _vec_len (qpd->free_cops) = l + n_alloc;
121  }
122  }
123  /* *INDENT-ON* */
124 }
125 
127 crypto_free_cop (crypto_qp_data_t * qpd, struct rte_crypto_op **cops, u32 n)
128 {
129  u32 l = vec_len (qpd->free_cops);
130 
131  if (l + n >= CRYPTO_N_FREE_COPS)
132  {
133  l -= VLIB_FRAME_SIZE;
134  rte_mempool_put_bulk (cops[0]->mempool,
135  (void **) &qpd->free_cops[l], VLIB_FRAME_SIZE);
136  }
137  clib_memcpy (&qpd->free_cops[l], cops, sizeof (*cops) * n);
138 
139  _vec_len (qpd->free_cops) = l + n;
140 }
141 
143 check_algo_is_supported (const struct rte_cryptodev_capabilities *cap,
144  char *name)
145 {
146  struct
147  {
148  uint8_t cipher_algo;
149  enum rte_crypto_sym_xform_type type;
150  union
151  {
152  enum rte_crypto_auth_algorithm auth;
153  enum rte_crypto_cipher_algorithm cipher;
154  };
155  char *name;
156  } supported_algo[] =
157  {
158  {
159  .type = RTE_CRYPTO_SYM_XFORM_CIPHER,.cipher =
160  RTE_CRYPTO_CIPHER_NULL,.name = "NULL"},
161  {
162  .type = RTE_CRYPTO_SYM_XFORM_CIPHER,.cipher =
163  RTE_CRYPTO_CIPHER_AES_CBC,.name = "AES_CBC"},
164  {
165  .type = RTE_CRYPTO_SYM_XFORM_CIPHER,.cipher =
166  RTE_CRYPTO_CIPHER_AES_CTR,.name = "AES_CTR"},
167  {
168  .type = RTE_CRYPTO_SYM_XFORM_CIPHER,.cipher =
169  RTE_CRYPTO_CIPHER_3DES_CBC,.name = "3DES-CBC"},
170  {
171  .type = RTE_CRYPTO_SYM_XFORM_CIPHER,.cipher =
172  RTE_CRYPTO_CIPHER_AES_GCM,.name = "AES-GCM"},
173  {
174  .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
175  RTE_CRYPTO_AUTH_SHA1_HMAC,.name = "HMAC-SHA1"},
176  {
177  .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
178  RTE_CRYPTO_AUTH_SHA256_HMAC,.name = "HMAC-SHA256"},
179  {
180  .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
181  RTE_CRYPTO_AUTH_SHA384_HMAC,.name = "HMAC-SHA384"},
182  {
183  .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
184  RTE_CRYPTO_AUTH_SHA512_HMAC,.name = "HMAC-SHA512"},
185  {
186  .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
187  RTE_CRYPTO_AUTH_AES_XCBC_MAC,.name = "AES-XCBC-MAC"},
188  {
189  .type = RTE_CRYPTO_SYM_XFORM_AUTH,.auth =
190  RTE_CRYPTO_AUTH_AES_GCM,.name = "AES-GCM"},
191  {
192  /* tail */
193  .type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED},};
194  uint32_t i = 0;
195 
196  if (cap->op != RTE_CRYPTO_OP_TYPE_SYMMETRIC)
197  return -1;
198 
199  while (supported_algo[i].type != RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED)
200  {
201  if (cap->sym.xform_type == supported_algo[i].type)
202  {
203  if ((cap->sym.xform_type == RTE_CRYPTO_SYM_XFORM_CIPHER &&
204  cap->sym.cipher.algo == supported_algo[i].cipher) ||
205  (cap->sym.xform_type == RTE_CRYPTO_SYM_XFORM_AUTH &&
206  cap->sym.auth.algo == supported_algo[i].auth))
207  {
208  if (name)
209  strcpy (name, supported_algo[i].name);
210  return 0;
211  }
212  }
213 
214  i++;
215  }
216 
217  return -1;
218 }
219 
220 #endif /* __DPDK_IPSEC_H__ */
221 
222 /*
223  * fd.io coding-style-patch-verification: ON
224  *
225  * Local Variables:
226  * eval: (c-set-style "gnu")
227  * End:
228  */
struct rte_crypto_op ** free_cops
Definition: ipsec.h:66
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
u16 is_outbound
Definition: ipsec.h:62
struct _vlib_node_registration vlib_node_registration_t
#define vec_alloc(V, N)
Allocate space for N more elements (no header, unspecified alignment)
Definition: vec.h:279
static_always_inline void crypto_free_cop(crypto_qp_data_t *qpd, struct rte_crypto_op **cops, u32 n)
Definition: ipsec.h:127
dpdk_crypto_main_t dpdk_crypto_main
Definition: ipsec.h:88
uword * algo_qp_map
Definition: ipsec.h:79
#define static_always_inline
Definition: clib.h:85
static_always_inline void crypto_alloc_cops()
Definition: ipsec.h:95
i16 inflights
Definition: ipsec.h:63
vlib_node_registration_t dpdk_crypto_input_node
(constructor) VLIB_REGISTER_NODE (dpdk_crypto_input_node)
Definition: crypto_node.c:60
uword os_get_cpu_number(void)
Definition: unix-misc.c:224
#define PREDICT_FALSE(x)
Definition: clib.h:97
#define VLIB_FRAME_SIZE
Definition: node.h:328
dpdk_gcm_cnt_blk cb
Definition: ipsec.h:43
#define clib_memcpy(a, b, c)
Definition: string.h:69
unsigned int u32
Definition: types.h:88
struct rte_mempool ** cop_pools
Definition: ipsec.h:84
crypto_worker_main_t * workers_main
Definition: ipsec.h:85
crypto_qp_data_t * qp_data
Definition: ipsec.h:78
u64 uword
Definition: types.h:112
unsigned short u16
Definition: types.h:57
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
#define CRYPTO_N_FREE_COPS
Definition: ipsec.h:92
static_always_inline int check_algo_is_supported(const struct rte_cryptodev_capabilities *cap, char *name)
Definition: ipsec.h:143
short i16
Definition: types.h:46
#define vec_foreach(var, vec)
Vector iterator.