blob: 9a782abeb949b273a66c345cb353c6feb4edbcce [file] [log] [blame]
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +00001/*
2 * esp_decrypt.c : IPSec ESP Decrypt node using DPDK Cryptodev
3 *
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +01004 * Copyright (c) 2017 Intel and/or its affiliates.
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +00005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +01007 * You may obtain a opy of the License at:
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +00008 *
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
22#include <vnet/ipsec/ipsec.h>
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010023#include <vnet/ipsec/esp.h>
Damjan Mariona5c308e2019-01-20 02:02:51 +010024#include <dpdk/buffer.h>
Damjan Marionc3a814b2017-02-28 19:22:22 +010025#include <dpdk/ipsec/ipsec.h>
Damjan Marionc3a814b2017-02-28 19:22:22 +010026#include <dpdk/device/dpdk.h>
27#include <dpdk/device/dpdk_priv.h>
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000028
29#define foreach_esp_decrypt_next \
30_(DROP, "error-drop") \
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010031_(IP4_INPUT, "ip4-input-no-checksum") \
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000032_(IP6_INPUT, "ip6-input")
33
34#define _(v, s) ESP_DECRYPT_NEXT_##v,
Kingwel Xie8861c1a2018-11-30 04:43:25 -050035typedef enum
36{
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000037 foreach_esp_decrypt_next
38#undef _
Kingwel Xie8861c1a2018-11-30 04:43:25 -050039 ESP_DECRYPT_N_NEXT,
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000040} esp_decrypt_next_t;
41
42#define foreach_esp_decrypt_error \
43 _(RX_PKTS, "ESP pkts received") \
44 _(DECRYPTION_FAILED, "ESP decryption failed") \
45 _(REPLAY, "SA replayed packet") \
46 _(NOT_IP, "Not IP packet (dropped)") \
Christian Hopps942b9802020-07-14 09:41:43 -040047 _(ENQ_FAIL, "Enqueue decrypt failed (queue full)") \
Christian Hoppsf6cb0442020-07-14 08:39:30 -040048 _(DISCARD, "Not enough crypto operations") \
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010049 _(BAD_LEN, "Invalid ciphertext length") \
50 _(SESSION, "Failed to get crypto session") \
51 _(NOSUP, "Cipher/Auth not supported")
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000052
53
Kingwel Xie8861c1a2018-11-30 04:43:25 -050054typedef enum
55{
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000056#define _(sym,str) ESP_DECRYPT_ERROR_##sym,
57 foreach_esp_decrypt_error
58#undef _
Kingwel Xie8861c1a2018-11-30 04:43:25 -050059 ESP_DECRYPT_N_ERROR,
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000060} esp_decrypt_error_t;
61
Kingwel Xie8861c1a2018-11-30 04:43:25 -050062static char *esp_decrypt_error_strings[] = {
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000063#define _(sym,string) string,
64 foreach_esp_decrypt_error
65#undef _
66};
67
Kingwel Xie040950a2018-11-28 02:10:35 -050068extern vlib_node_registration_t dpdk_esp4_decrypt_node;
69extern vlib_node_registration_t dpdk_esp6_decrypt_node;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000070
Kingwel Xie8861c1a2018-11-30 04:43:25 -050071typedef struct
72{
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000073 ipsec_crypto_alg_t crypto_alg;
74 ipsec_integ_alg_t integ_alg;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010075 u8 packet_data[64];
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000076} esp_decrypt_trace_t;
77
78/* packet trace format function */
Kingwel Xie8861c1a2018-11-30 04:43:25 -050079static u8 *
80format_esp_decrypt_trace (u8 * s, va_list * args)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000081{
82 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
83 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Kingwel Xie8861c1a2018-11-30 04:43:25 -050084 esp_decrypt_trace_t *t = va_arg (*args, esp_decrypt_trace_t *);
Gabriel Gannee3ea7972017-10-12 10:53:31 +020085 u32 indent = format_get_indent (s);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000086
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010087 s = format (s, "cipher %U auth %U\n",
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000088 format_ipsec_crypto_alg, t->crypto_alg,
89 format_ipsec_integ_alg, t->integ_alg);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +010090 s = format (s, "%U%U",
Kingwel Xie8861c1a2018-11-30 04:43:25 -050091 format_white_space, indent, format_esp_header, t->packet_data);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000092 return s;
93}
94
Klement Sekerabe5a5dd2018-10-09 16:05:48 +020095always_inline uword
96dpdk_esp_decrypt_inline (vlib_main_t * vm,
Kingwel Xie8861c1a2018-11-30 04:43:25 -050097 vlib_node_runtime_t * node,
98 vlib_frame_t * from_frame, int is_ip6)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +000099{
Neale Rannseba31ec2019-02-17 18:04:27 +0000100 u32 n_left_from, *from, *to_next, next_index, thread_index;
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500101 u32 thread_idx = vlib_get_thread_index ();
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100102 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
103 crypto_resource_t *res = 0;
104 ipsec_sa_t *sa0 = 0;
105 crypto_alg_t *cipher_alg = 0, *auth_alg = 0;
106 struct rte_cryptodev_sym_session *session = 0;
107 u32 ret, last_sa_index = ~0;
108 u8 numa = rte_socket_id ();
109 u8 is_aead = 0;
110 crypto_worker_main_t *cwm =
111 vec_elt_at_index (dcm->workers_main, thread_idx);
112 struct rte_crypto_op **ops = cwm->ops;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000113
114 from = vlib_frame_vector_args (from_frame);
115 n_left_from = from_frame->n_vectors;
Neale Rannseba31ec2019-02-17 18:04:27 +0000116 thread_index = vm->thread_index;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000117
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100118 ret = crypto_alloc_ops (numa, ops, n_left_from);
119 if (ret)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000120 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500121 if (is_ip6)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200122 vlib_node_increment_counter (vm, dpdk_esp6_decrypt_node.index,
Christian Hoppsf6cb0442020-07-14 08:39:30 -0400123 ESP_DECRYPT_ERROR_DISCARD, n_left_from);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200124 else
125 vlib_node_increment_counter (vm, dpdk_esp4_decrypt_node.index,
Christian Hoppsf6cb0442020-07-14 08:39:30 -0400126 ESP_DECRYPT_ERROR_DISCARD, n_left_from);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100127 /* Discard whole frame */
Christian Hoppsf6cb0442020-07-14 08:39:30 -0400128 vlib_buffer_free (vm, from, n_left_from);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100129 return n_left_from;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000130 }
131
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000132 next_index = ESP_DECRYPT_NEXT_DROP;
133
134 while (n_left_from > 0)
135 {
136 u32 n_left_to_next;
137
138 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
139
140 while (n_left_from > 0 && n_left_to_next > 0)
141 {
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100142 clib_error_t *error;
Damjan Marion1f4e1cb2019-03-28 19:19:31 +0100143 u32 bi0, sa_index0, iv_size;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100144 u8 trunc_size;
145 vlib_buffer_t *b0;
146 esp_header_t *esp0;
147 struct rte_mbuf *mb0;
148 struct rte_crypto_op *op;
149 u16 res_idx;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000150
151 bi0 = from[0];
152 from += 1;
153 n_left_from -= 1;
154
155 b0 = vlib_get_buffer (vm, bi0);
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500156 mb0 = rte_mbuf_from_vlib_buffer (b0);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000157 esp0 = vlib_buffer_get_current (b0);
158
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100159 /* ih0/ih6_0 */
160 CLIB_PREFETCH (esp0, sizeof (esp0[0]) + 16, LOAD);
161 /* mb0 */
162 CLIB_PREFETCH (mb0, CLIB_CACHE_LINE_BYTES, STORE);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000163
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100164 op = ops[0];
165 ops += 1;
166 ASSERT (op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED);
167
168 dpdk_op_priv_t *priv = crypto_op_get_priv (op);
Kingwel Xie3b3464e2019-02-13 02:48:41 -0500169 /* store bi in op private */
170 priv->bi = bi0;
Sergio Gonzalez Monroyd8a34a52019-05-06 22:44:14 +0200171 priv->encrypt = 0;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100172
173 u16 op_len =
174 sizeof (op[0]) + sizeof (op[0].sym[0]) + sizeof (priv[0]);
175 CLIB_PREFETCH (op, op_len, STORE);
176
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500177 sa_index0 = vnet_buffer (b0)->ipsec.sad_index;
Neale Rannseba31ec2019-02-17 18:04:27 +0000178 vlib_prefetch_combined_counter (&ipsec_sa_counters,
179 thread_index, sa_index0);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100180
181 if (sa_index0 != last_sa_index)
182 {
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000183 sa0 = ipsec_sa_get (sa_index0);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100184
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500185 cipher_alg =
186 vec_elt_at_index (dcm->cipher_algs, sa0->crypto_alg);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100187 auth_alg = vec_elt_at_index (dcm->auth_algs, sa0->integ_alg);
188
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100189 is_aead = (cipher_alg->type == RTE_CRYPTO_SYM_XFORM_AEAD);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100190 if (is_aead)
191 auth_alg = cipher_alg;
192
193 res_idx = get_resource (cwm, sa0);
194
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500195 if (PREDICT_FALSE (res_idx == (u16) ~ 0))
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100196 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500197 if (is_ip6)
198 vlib_node_increment_counter (vm,
199 dpdk_esp6_decrypt_node.index,
200 ESP_DECRYPT_ERROR_NOSUP, 1);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200201 else
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500202 vlib_node_increment_counter (vm,
203 dpdk_esp4_decrypt_node.index,
204 ESP_DECRYPT_ERROR_NOSUP, 1);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100205 to_next[0] = bi0;
206 to_next += 1;
207 n_left_to_next -= 1;
208 goto trace;
209 }
210 res = vec_elt_at_index (dcm->resource, res_idx);
211
212 error = crypto_get_session (&session, sa_index0, res, cwm, 0);
213 if (PREDICT_FALSE (error || !session))
214 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500215 if (is_ip6)
216 vlib_node_increment_counter (vm,
217 dpdk_esp6_decrypt_node.index,
218 ESP_DECRYPT_ERROR_SESSION,
219 1);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200220 else
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500221 vlib_node_increment_counter (vm,
222 dpdk_esp4_decrypt_node.index,
223 ESP_DECRYPT_ERROR_SESSION,
224 1);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100225 to_next[0] = bi0;
226 to_next += 1;
227 n_left_to_next -= 1;
228 goto trace;
229 }
Sergio Gonzalez Monroy20960632017-10-12 11:43:41 +0100230
231 last_sa_index = sa_index0;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100232 }
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000233
234 /* anti-replay check */
Neale Ranns6afaae12019-07-17 15:07:14 +0000235 if (ipsec_sa_anti_replay_check
236 (sa0, clib_host_to_net_u32 (esp0->seq)))
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000237 {
Damjan Marion1f4e1cb2019-03-28 19:19:31 +0100238 if (is_ip6)
239 vlib_node_increment_counter (vm,
240 dpdk_esp6_decrypt_node.index,
241 ESP_DECRYPT_ERROR_REPLAY, 1);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100242 else
Damjan Marion1f4e1cb2019-03-28 19:19:31 +0100243 vlib_node_increment_counter (vm,
244 dpdk_esp4_decrypt_node.index,
245 ESP_DECRYPT_ERROR_REPLAY, 1);
246 to_next[0] = bi0;
247 to_next += 1;
248 n_left_to_next -= 1;
249 goto trace;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000250 }
251
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500252 if (is_ip6)
Klement Sekera73343932018-10-22 13:17:19 +0200253 priv->next = DPDK_CRYPTO_INPUT_NEXT_DECRYPT6_POST;
254 else
Neale Ranns7ec120e2020-01-21 04:58:02 +0000255 {
256 priv->next = DPDK_CRYPTO_INPUT_NEXT_DECRYPT4_POST;
257 b0->flags |= VNET_BUFFER_F_IS_IP4;
258 }
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100259
260 /* FIXME multi-seg */
Neale Rannseba31ec2019-02-17 18:04:27 +0000261 vlib_increment_combined_counter
262 (&ipsec_sa_counters, thread_index, sa_index0,
263 1, b0->current_length);
Radu Nicolaucb33dc22017-02-16 16:49:46 +0000264
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100265 res->ops[res->n_ops] = op;
266 res->bi[res->n_ops] = bi0;
267 res->n_ops += 1;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000268
269 /* Convert vlib buffer to mbuf */
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000270 mb0->data_len = b0->current_length;
271 mb0->pkt_len = b0->current_length;
272 mb0->data_off = RTE_PKTMBUF_HEADROOM + b0->current_data;
273
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100274 trunc_size = auth_alg->trunc_size;
275 iv_size = cipher_alg->iv_len;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000276
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100277 /* Outer IP header has already been stripped */
278 u16 payload_len =
279 b0->current_length - sizeof (esp_header_t) - iv_size - trunc_size;
280
281 ASSERT (payload_len >= 4);
282
283 if (payload_len & (cipher_alg->boundary - 1))
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000284 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500285 if (is_ip6)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200286 vlib_node_increment_counter (vm, dpdk_esp6_decrypt_node.index,
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500287 ESP_DECRYPT_ERROR_BAD_LEN, 1);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200288 else
289 vlib_node_increment_counter (vm, dpdk_esp4_decrypt_node.index,
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500290 ESP_DECRYPT_ERROR_BAD_LEN, 1);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100291 res->n_ops -= 1;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000292 to_next[0] = bi0;
293 to_next += 1;
294 n_left_to_next -= 1;
295 goto trace;
296 }
297
Sergio Gonzalez Monroyacdc3062017-08-24 14:09:17 +0100298 u32 cipher_off, cipher_len;
Sergio Gonzalez Monroy99214ce2017-11-26 15:25:43 +0000299 u32 auth_len = 0;
Sergio Gonzalez Monroyaa3a25c2017-10-31 15:55:39 +0000300 u8 *aad = NULL;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000301
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500302 u8 *iv = (u8 *) (esp0 + 1);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100303
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500304 dpdk_gcm_cnt_blk *icb = &priv->cb;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000305
Sergio Gonzalez Monroyacdc3062017-08-24 14:09:17 +0100306 cipher_off = sizeof (esp_header_t) + iv_size;
307 cipher_len = payload_len;
308
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500309 u8 *digest = vlib_buffer_get_tail (b0) - trunc_size;
Fan Zhangf0419a02020-12-01 15:10:43 +0000310 u64 digest_paddr = mb0->buf_iova + digest - ((u8 *) mb0->buf_addr);
Sergio Gonzalez Monroyacdc3062017-08-24 14:09:17 +0100311
Sergio Gonzalez Monroy20960632017-10-12 11:43:41 +0100312 if (!is_aead && cipher_alg->alg == RTE_CRYPTO_CIPHER_AES_CBC)
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500313 clib_memcpy_fast (icb, iv, 16);
314 else /* CTR/GCM */
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100315 {
Sergio Gonzalez Monroyacdc3062017-08-24 14:09:17 +0100316 u32 *_iv = (u32 *) iv;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000317
Sergio Gonzalez Monroyacdc3062017-08-24 14:09:17 +0100318 crypto_set_icb (icb, sa0->salt, _iv[0], _iv[1]);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100319 }
Sergio Gonzalez Monroyacdc3062017-08-24 14:09:17 +0100320
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500321 if (is_aead)
322 {
323 aad = priv->aad;
324 u32 *_aad = (u32 *) aad;
325 clib_memcpy_fast (aad, esp0, 8);
Sergio Gonzalez Monroy99214ce2017-11-26 15:25:43 +0000326
327 /* _aad[3] should always be 0 */
Damjan Marion1e3aa5e2019-03-28 10:58:59 +0100328 if (PREDICT_FALSE (ipsec_sa_is_set_USE_ESN (sa0)))
Christian Hoppsd58419f2019-11-03 01:02:18 -0400329 {
330 _aad[2] = _aad[1];
331 _aad[1] = clib_host_to_net_u32 (sa0->seq_hi);
332 }
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100333 else
Sergio Gonzalez Monroy99214ce2017-11-26 15:25:43 +0000334 _aad[2] = 0;
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500335 }
336 else
337 {
338 auth_len = sizeof (esp_header_t) + iv_size + payload_len;
Radu Nicolau6929ea92016-11-29 11:00:30 +0000339
Damjan Marion1e3aa5e2019-03-28 10:58:59 +0100340 if (ipsec_sa_is_set_USE_ESN (sa0))
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500341 {
342 clib_memcpy_fast (priv->icv, digest, trunc_size);
Sergio Gonzalez Monroy99214ce2017-11-26 15:25:43 +0000343 u32 *_digest = (u32 *) digest;
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500344 _digest[0] = clib_host_to_net_u32 (sa0->seq_hi);
345 auth_len += sizeof (sa0->seq_hi);
Radu Nicolau6929ea92016-11-29 11:00:30 +0000346
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500347 digest = priv->icv;
Sergio Gonzalez Monroyacdc3062017-08-24 14:09:17 +0100348 digest_paddr =
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100349 op->phys_addr + (uintptr_t) priv->icv - (uintptr_t) op;
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500350 }
351 }
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000352
Sergio Gonzalez Monroy99214ce2017-11-26 15:25:43 +0000353 crypto_op_setup (is_aead, mb0, op, session, cipher_off, cipher_len,
354 0, auth_len, aad, digest, digest_paddr);
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500355 trace:
356 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000357 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500358 esp_decrypt_trace_t *tr =
359 vlib_add_trace (vm, node, b0, sizeof (*tr));
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000360 tr->crypto_alg = sa0->crypto_alg;
361 tr->integ_alg = sa0->integ_alg;
Dave Barach178cf492018-11-13 16:34:13 -0500362 clib_memcpy_fast (tr->packet_data, vlib_buffer_get_current (b0),
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500363 sizeof (esp_header_t));
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000364 }
365 }
366 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
367 }
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100368
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500369 if (is_ip6)
370 {
371 vlib_node_increment_counter (vm, dpdk_esp6_decrypt_node.index,
372 ESP_DECRYPT_ERROR_RX_PKTS,
373 from_frame->n_vectors);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000374
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100375 crypto_enqueue_ops (vm, cwm, dpdk_esp6_decrypt_node.index,
Sergio Gonzalez Monroyd8a34a52019-05-06 22:44:14 +0200376 ESP_DECRYPT_ERROR_ENQ_FAIL, numa, 0 /* encrypt */ );
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500377 }
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200378 else
379 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500380 vlib_node_increment_counter (vm, dpdk_esp4_decrypt_node.index,
381 ESP_DECRYPT_ERROR_RX_PKTS,
382 from_frame->n_vectors);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200383
Sergio Gonzalez Monroy35467f12019-01-30 11:26:00 +0100384 crypto_enqueue_ops (vm, cwm, dpdk_esp4_decrypt_node.index,
Sergio Gonzalez Monroyd8a34a52019-05-06 22:44:14 +0200385 ESP_DECRYPT_ERROR_ENQ_FAIL, numa, 0 /* encrypt */ );
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200386 }
Sergio Gonzalez Monroyacdc3062017-08-24 14:09:17 +0100387
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100388 crypto_free_ops (numa, ops, cwm->ops + from_frame->n_vectors - ops);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000389
390 return from_frame->n_vectors;
391}
392
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500393VLIB_NODE_FN (dpdk_esp4_decrypt_node) (vlib_main_t * vm,
394 vlib_node_runtime_t * node,
395 vlib_frame_t * from_frame)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200396{
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500397 return dpdk_esp_decrypt_inline (vm, node, from_frame, 0 /*is_ip6 */ );
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200398}
399
Sergio Gonzalez Monroy539ed4f2017-05-17 11:43:41 +0100400/* *INDENT-OFF* */
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200401VLIB_REGISTER_NODE (dpdk_esp4_decrypt_node) = {
Klement Sekera73343932018-10-22 13:17:19 +0200402 .name = "dpdk-esp4-decrypt",
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000403 .vector_size = sizeof (u32),
404 .format_trace = format_esp_decrypt_trace,
405 .type = VLIB_NODE_TYPE_INTERNAL,
406
407 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
408 .error_strings = esp_decrypt_error_strings,
409
410 .n_next_nodes = ESP_DECRYPT_N_NEXT,
411 .next_nodes = {
412#define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
413 foreach_esp_decrypt_next
414#undef _
415 },
416};
Sergio Gonzalez Monroy539ed4f2017-05-17 11:43:41 +0100417/* *INDENT-ON* */
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000418
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500419VLIB_NODE_FN (dpdk_esp6_decrypt_node) (vlib_main_t * vm,
420 vlib_node_runtime_t * node,
421 vlib_frame_t * from_frame)
Matthew Smith1dfdb282018-10-22 16:37:25 -0500422{
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500423 return dpdk_esp_decrypt_inline (vm, node, from_frame, 1 /*is_ip6 */ );
Matthew Smith1dfdb282018-10-22 16:37:25 -0500424}
425
426/* *INDENT-OFF* */
427VLIB_REGISTER_NODE (dpdk_esp6_decrypt_node) = {
Matthew Smith1dfdb282018-10-22 16:37:25 -0500428 .name = "dpdk-esp6-decrypt",
429 .vector_size = sizeof (u32),
430 .format_trace = format_esp_decrypt_trace,
431 .type = VLIB_NODE_TYPE_INTERNAL,
432
433 .n_errors = ARRAY_LEN(esp_decrypt_error_strings),
434 .error_strings = esp_decrypt_error_strings,
435
436 .n_next_nodes = ESP_DECRYPT_N_NEXT,
437 .next_nodes = {
438#define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
439 foreach_esp_decrypt_next
440#undef _
441 },
442};
443/* *INDENT-ON* */
444
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000445/*
446 * Decrypt Post Node
447 */
448
449#define foreach_esp_decrypt_post_error \
450 _(PKTS, "ESP post pkts")
451
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500452typedef enum
453{
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000454#define _(sym,str) ESP_DECRYPT_POST_ERROR_##sym,
455 foreach_esp_decrypt_post_error
456#undef _
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500457 ESP_DECRYPT_POST_N_ERROR,
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000458} esp_decrypt_post_error_t;
459
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500460static char *esp_decrypt_post_error_strings[] = {
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000461#define _(sym,string) string,
462 foreach_esp_decrypt_post_error
463#undef _
464};
465
Kingwel Xie040950a2018-11-28 02:10:35 -0500466extern vlib_node_registration_t dpdk_esp4_decrypt_post_node;
467extern vlib_node_registration_t dpdk_esp6_decrypt_post_node;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000468
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500469static u8 *
470format_esp_decrypt_post_trace (u8 * s, va_list * args)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000471{
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100472 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
473 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500474 esp_decrypt_trace_t *t = va_arg (*args, esp_decrypt_trace_t *);
Gabriel Gannee3ea7972017-10-12 10:53:31 +0200475 u32 indent = format_get_indent (s);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100476
477 s = format (s, "cipher %U auth %U\n",
478 format_ipsec_crypto_alg, t->crypto_alg,
479 format_ipsec_integ_alg, t->integ_alg);
480
481 ip4_header_t *ih4 = (ip4_header_t *) t->packet_data;
482 if ((ih4->ip_version_and_header_length & 0xF0) == 0x60)
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500483 s =
484 format (s, "%U%U", format_white_space, indent, format_ip6_header, ih4);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100485 else
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500486 s =
487 format (s, "%U%U", format_white_space, indent, format_ip4_header, ih4);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100488
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000489 return s;
490}
491
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200492always_inline uword
493dpdk_esp_decrypt_post_inline (vlib_main_t * vm,
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500494 vlib_node_runtime_t * node,
495 vlib_frame_t * from_frame, int is_ip6)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000496{
497 u32 n_left_from, *from, *to_next = 0, next_index;
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500498 ipsec_sa_t *sa0;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000499 u32 sa_index0 = ~0;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100500 dpdk_crypto_main_t *dcm = &dpdk_crypto_main;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000501
502 from = vlib_frame_vector_args (from_frame);
503 n_left_from = from_frame->n_vectors;
504
505 next_index = node->cached_next_index;
506
507 while (n_left_from > 0)
508 {
509 u32 n_left_to_next;
510
511 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
512
513 while (n_left_from > 0 && n_left_to_next > 0)
514 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500515 esp_footer_t *f0;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100516 u32 bi0, iv_size, next0;
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500517 vlib_buffer_t *b0 = 0;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000518 ip4_header_t *ih4 = 0, *oh4 = 0;
519 ip6_header_t *ih6 = 0, *oh6 = 0;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100520 crypto_alg_t *cipher_alg, *auth_alg;
521 esp_header_t *esp0;
522 u8 trunc_size, is_aead;
Radu Nicolau0c58ad42018-06-13 16:39:05 +0100523 u16 udp_encap_adv = 0;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000524
525 next0 = ESP_DECRYPT_NEXT_DROP;
526
527 bi0 = from[0];
528 from += 1;
529 n_left_from -= 1;
530 n_left_to_next -= 1;
531
532 b0 = vlib_get_buffer (vm, bi0);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100533 esp0 = vlib_buffer_get_current (b0);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000534
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500535 sa_index0 = vnet_buffer (b0)->ipsec.sad_index;
Neale Rannsc5fe57d2021-02-25 16:01:28 +0000536 sa0 = ipsec_sa_get (sa_index0);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000537
538 to_next[0] = bi0;
539 to_next += 1;
540
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100541 cipher_alg = vec_elt_at_index (dcm->cipher_algs, sa0->crypto_alg);
542 auth_alg = vec_elt_at_index (dcm->auth_algs, sa0->integ_alg);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100543 is_aead = cipher_alg->type == RTE_CRYPTO_SYM_XFORM_AEAD;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100544 if (is_aead)
545 auth_alg = cipher_alg;
546
547 trunc_size = auth_alg->trunc_size;
548
549 iv_size = cipher_alg->iv_len;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000550
Neale Ranns6afaae12019-07-17 15:07:14 +0000551 ipsec_sa_anti_replay_advance (sa0,
552 clib_host_to_net_u32 (esp0->seq));
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000553
Radu Nicolau0c58ad42018-06-13 16:39:05 +0100554 /* if UDP encapsulation is used adjust the address of the IP header */
Damjan Mariond709cbc2019-03-26 13:16:42 +0100555 if (ipsec_sa_is_set_UDP_ENCAP (sa0)
556 && (b0->flags & VNET_BUFFER_F_IS_IP4))
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500557 {
558 udp_encap_adv = sizeof (udp_header_t);
559 }
Radu Nicolau0c58ad42018-06-13 16:39:05 +0100560
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500561 if (b0->flags & VNET_BUFFER_F_IS_IP4)
562 ih4 = (ip4_header_t *)
563 ((u8 *) esp0 - udp_encap_adv - sizeof (ip4_header_t));
564 else
565 ih4 = (ip4_header_t *) ((u8 *) esp0 - sizeof (ip6_header_t));
Szymon Sliwa65a27272018-05-09 14:28:08 +0200566
Radu Nicolau6929ea92016-11-29 11:00:30 +0000567 vlib_buffer_advance (b0, sizeof (esp_header_t) + iv_size);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000568
Sergio Gonzalez Monroy539ed4f2017-05-17 11:43:41 +0100569 b0->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100570 f0 = (esp_footer_t *) (vlib_buffer_get_tail (b0) - trunc_size - 2);
571 b0->current_length -= (f0->pad_length + trunc_size + 2);
572#if 0
573 /* check padding */
574 const u8 *padding = vlib_buffer_get_tail (b0);
575 if (PREDICT_FALSE (memcmp (padding, pad_data, f0->pad_length)))
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000576 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500577 clib_warning ("bad padding");
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100578 vlib_node_increment_counter (vm, dpdk_esp_decrypt_node.index,
579 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
580 1);
581 goto trace;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000582 }
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100583#endif
Damjan Mariond709cbc2019-03-26 13:16:42 +0100584 if (ipsec_sa_is_set_IS_TUNNEL (sa0))
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000585 {
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100586 if (f0->next_header == IP_PROTOCOL_IP_IN_IP)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000587 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
Matthew G Smith5025d402019-08-06 08:43:50 -0500588 else if (f0->next_header == IP_PROTOCOL_IPV6)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000589 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
590 else
591 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500592 clib_warning ("next header: 0x%x", f0->next_header);
593 if (is_ip6)
594 vlib_node_increment_counter (vm,
595 dpdk_esp6_decrypt_node.index,
596 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
597 1);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200598 else
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500599 vlib_node_increment_counter (vm,
600 dpdk_esp4_decrypt_node.index,
601 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
602 1);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000603 goto trace;
604 }
605 }
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500606 else /* transport mode */
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000607 {
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100608 if ((ih4->ip_version_and_header_length & 0xF0) == 0x40)
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000609 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500610 u16 ih4_len = ip4_header_bytes (ih4);
Alexander Chernavin82fc98f2020-04-03 10:18:44 -0400611 vlib_buffer_advance (b0, -ih4_len);
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500612 next0 = ESP_DECRYPT_NEXT_IP4_INPUT;
Alexander Chernavin82fc98f2020-04-03 10:18:44 -0400613
614 oh4 = vlib_buffer_get_current (b0);
615 memmove (oh4, ih4, ih4_len);
616 oh4->protocol = f0->next_header;
617 oh4->length = clib_host_to_net_u16 (b0->current_length);
618 oh4->checksum = ip4_header_checksum (oh4);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100619 }
620 else if ((ih4->ip_version_and_header_length & 0xF0) == 0x60)
621 {
Sergio Gonzalez Monroy99214ce2017-11-26 15:25:43 +0000622 ih6 = (ip6_header_t *) ih4;
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500623 vlib_buffer_advance (b0, -sizeof (ip6_header_t));
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000624 oh6 = vlib_buffer_get_current (b0);
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500625 memmove (oh6, ih6, sizeof (ip6_header_t));
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000626
Radu Nicolau6929ea92016-11-29 11:00:30 +0000627 next0 = ESP_DECRYPT_NEXT_IP6_INPUT;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000628 oh6->protocol = f0->next_header;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100629 u16 len = b0->current_length - sizeof (ip6_header_t);
630 oh6->payload_length = clib_host_to_net_u16 (len);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000631 }
632 else
633 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500634 clib_warning ("next header: 0x%x", f0->next_header);
635 if (is_ip6)
636 vlib_node_increment_counter (vm,
637 dpdk_esp6_decrypt_node.index,
638 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
639 1);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200640 else
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500641 vlib_node_increment_counter (vm,
642 dpdk_esp4_decrypt_node.index,
643 ESP_DECRYPT_ERROR_DECRYPTION_FAILED,
644 1);
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100645 goto trace;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000646 }
647 }
648
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500649 vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0;
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000650
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100651 trace:
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500652 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000653 {
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500654 esp_decrypt_trace_t *tr =
655 vlib_add_trace (vm, node, b0, sizeof (*tr));
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000656 tr->crypto_alg = sa0->crypto_alg;
657 tr->integ_alg = sa0->integ_alg;
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100658 ih4 = vlib_buffer_get_current (b0);
Dave Barach178cf492018-11-13 16:34:13 -0500659 clib_memcpy_fast (tr->packet_data, ih4, sizeof (ip6_header_t));
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000660 }
661
662 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500663 to_next, n_left_to_next, bi0,
664 next0);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000665 }
666 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
667 }
Sergio Gonzalez Monroydb93cd92017-08-26 15:22:05 +0100668
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500669 if (is_ip6)
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200670 vlib_node_increment_counter (vm, dpdk_esp6_decrypt_post_node.index,
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500671 ESP_DECRYPT_POST_ERROR_PKTS,
672 from_frame->n_vectors);
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200673 else
674 vlib_node_increment_counter (vm, dpdk_esp4_decrypt_post_node.index,
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500675 ESP_DECRYPT_POST_ERROR_PKTS,
676 from_frame->n_vectors);
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000677
678 return from_frame->n_vectors;
679}
680
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500681VLIB_NODE_FN (dpdk_esp4_decrypt_post_node) (vlib_main_t * vm,
682 vlib_node_runtime_t * node,
683 vlib_frame_t * from_frame)
684{
685 return dpdk_esp_decrypt_post_inline (vm, node, from_frame, 0 /*is_ip6 */ );
686}
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200687
Sergio Gonzalez Monroy539ed4f2017-05-17 11:43:41 +0100688/* *INDENT-OFF* */
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200689VLIB_REGISTER_NODE (dpdk_esp4_decrypt_post_node) = {
Klement Sekera73343932018-10-22 13:17:19 +0200690 .name = "dpdk-esp4-decrypt-post",
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000691 .vector_size = sizeof (u32),
692 .format_trace = format_esp_decrypt_post_trace,
693 .type = VLIB_NODE_TYPE_INTERNAL,
694
695 .n_errors = ARRAY_LEN(esp_decrypt_post_error_strings),
696 .error_strings = esp_decrypt_post_error_strings,
697
698 .n_next_nodes = ESP_DECRYPT_N_NEXT,
699 .next_nodes = {
700#define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
701 foreach_esp_decrypt_next
702#undef _
703 },
704};
Sergio Gonzalez Monroy539ed4f2017-05-17 11:43:41 +0100705/* *INDENT-ON* */
Sergio Gonzalez Monroya10f62b2016-11-25 13:36:12 +0000706
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500707VLIB_NODE_FN (dpdk_esp6_decrypt_post_node) (vlib_main_t * vm,
708 vlib_node_runtime_t * node,
709 vlib_frame_t * from_frame)
Kingwel Xie040950a2018-11-28 02:10:35 -0500710{
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500711 return dpdk_esp_decrypt_post_inline (vm, node, from_frame, 0 /*is_ip6 */ );
Kingwel Xie040950a2018-11-28 02:10:35 -0500712}
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200713
714/* *INDENT-OFF* */
715VLIB_REGISTER_NODE (dpdk_esp6_decrypt_post_node) = {
Klement Sekera73343932018-10-22 13:17:19 +0200716 .name = "dpdk-esp6-decrypt-post",
Klement Sekerabe5a5dd2018-10-09 16:05:48 +0200717 .vector_size = sizeof (u32),
718 .format_trace = format_esp_decrypt_post_trace,
719 .type = VLIB_NODE_TYPE_INTERNAL,
720
721 .n_errors = ARRAY_LEN(esp_decrypt_post_error_strings),
722 .error_strings = esp_decrypt_post_error_strings,
723
724 .n_next_nodes = ESP_DECRYPT_N_NEXT,
725 .next_nodes = {
726#define _(s,n) [ESP_DECRYPT_NEXT_##s] = n,
727 foreach_esp_decrypt_next
728#undef _
729 },
730};
731/* *INDENT-ON* */
Kingwel Xie040950a2018-11-28 02:10:35 -0500732
Kingwel Xie8861c1a2018-11-30 04:43:25 -0500733/*
734 * fd.io coding-style-patch-verification: ON
735 *
736 * Local Variables:
737 * eval: (c-set-style "gnu")
738 * End:
739 */