FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Cisco 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 
16 #include <stdbool.h>
17 #include <vlib/vlib.h>
18 #include <vnet/crypto/crypto.h>
19 
20 typedef enum
21 {
22 #define _(sym,str) VNET_CRYPTO_ASYNC_ERROR_##sym,
24 #undef _
27 
29 #define _(sym,string) string,
31 #undef _
32 };
33 
34 #define foreach_crypto_dispatch_next \
35  _(ERR_DROP, "error-drop")
36 
37 typedef enum
38 {
39 #define _(n, s) CRYPTO_DISPATCH_NEXT_##n,
41 #undef _
44 
45 typedef struct
46 {
50 
51 static u8 *
52 format_crypto_dispatch_trace (u8 * s, va_list * args)
53 {
54  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
55  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
56  crypto_dispatch_trace_t *t = va_arg (*args, crypto_dispatch_trace_t *);
57 
58  s = format (s, "%U: %U", format_vnet_crypto_async_op, t->op,
60  return s;
61 }
62 
63 static void
65  vlib_buffer_t * b,
68 {
69  crypto_dispatch_trace_t *tr = vlib_add_trace (vm, node, b, sizeof (*tr));
70  tr->op_status = status;
71  tr->op = op_id;
72 }
73 
77  vnet_crypto_frame_dequeue_t * hdl, u32 n_cache,
78  u32 * n_total)
79 {
81  u32 n_elts = 0;
82  u32 enqueue_thread_idx = ~0;
83  vnet_crypto_async_frame_t *cf = (hdl) (vm, &n_elts, &enqueue_thread_idx);
84  *n_total += n_elts;
85 
86  while (cf || n_elts)
87  {
88  if (cf)
89  {
90  vec_validate (ct->buffer_indices, n_cache + cf->n_elts);
91  vec_validate (ct->nexts, n_cache + cf->n_elts);
93  sizeof (u32) * cf->n_elts);
95  {
96  clib_memcpy_fast (ct->nexts + n_cache, cf->next_node_index,
97  sizeof (u16) * cf->n_elts);
98  }
99  else
100  {
101  u32 i;
102  for (i = 0; i < cf->n_elts; i++)
103  {
104  if (cf->elts[i].status != VNET_CRYPTO_OP_STATUS_COMPLETED)
105  {
106  ct->nexts[i + n_cache] = CRYPTO_DISPATCH_NEXT_ERR_DROP;
107  vlib_node_increment_counter (vm, node->node_index,
108  cf->elts[i].status, 1);
109  }
110  else
111  ct->nexts[i + n_cache] = cf->next_node_index[i];
112  }
113  }
114  n_cache += cf->n_elts;
115  if (n_cache >= VLIB_FRAME_SIZE)
116  {
118  &ct->nexts, n_cache);
119  n_cache = 0;
120  }
121 
122  if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
123  {
124  u32 i;
125 
126  for (i = 0; i < cf->n_elts; i++)
127  {
129  cf->buffer_indices[i]);
130  if (b->flags & VLIB_BUFFER_IS_TRACED)
132  cf->elts[i].status);
133  }
134  }
136  }
137  /* signal enqueue-thread to dequeue the processed frame (n_elts>0) */
138  if (cm->dispatch_mode == VNET_CRYPTO_ASYNC_DISPATCH_INTERRUPT
139  && n_elts > 0)
140  {
142  vlib_get_main_by_index (enqueue_thread_idx),
143  cm->crypto_node_index);
144  }
145 
146  n_elts = 0;
147  enqueue_thread_idx = 0;
148  cf = (hdl) (vm, &n_elts, &enqueue_thread_idx);
149  *n_total += n_elts;
150  }
151 
152  return n_cache;
153 }
154 
158 {
160  vnet_crypto_thread_t *ct = cm->threads + vm->thread_index;
161  u32 n_dispatched = 0, n_cache = 0;
162  u32 index;
163 
164  /* *INDENT-OFF* */
165  clib_bitmap_foreach (index, cm->async_active_ids) {
166  n_cache = crypto_dequeue_frame (vm, node, ct, cm->dequeue_handlers[index],
167  n_cache, &n_dispatched);
168  }
169  /* *INDENT-ON* */
170  if (n_cache)
172  n_cache);
173 
174  return n_dispatched;
175 }
176 
177 /* *INDENT-OFF* */
179  .name = "crypto-dispatch",
180  .type = VLIB_NODE_TYPE_INPUT,
181  .state = VLIB_NODE_STATE_DISABLED,
182  .format_trace = format_crypto_dispatch_trace,
183 
185  .error_strings = vnet_crypto_async_error_strings,
186 
187  .n_next_nodes = CRYPTO_DISPATCH_N_NEXT,
188  .next_nodes = {
189 #define _(n, s) \
190  [CRYPTO_DISPATCH_NEXT_##n] = s,
192 #undef _
193  },
194 };
195 /* *INDENT-ON* */
196 
197 /*
198  * fd.io coding-style-patch-verification: ON
199  *
200  * Local Variables:
201  * eval: (c-set-style "gnu")
202  * End:
203  */
vlib.h
vnet_crypto_frame_dequeue_t
vnet_crypto_async_frame_t *() vnet_crypto_frame_dequeue_t(vlib_main_t *vm, u32 *nb_elts_processed, u32 *enqueue_thread_idx)
Definition: crypto.h:397
vnet_crypto_async_free_frame
static_always_inline void vnet_crypto_async_free_frame(vlib_main_t *vm, vnet_crypto_async_frame_t *frame)
Definition: crypto.h:580
vnet_crypto_async_frame_t::elts
vnet_crypto_async_frame_elt_t elts[VNET_CRYPTO_FRAME_SIZE]
Definition: crypto.h:364
vnet_crypto_async_frame_t::buffer_indices
u32 buffer_indices[VNET_CRYPTO_FRAME_SIZE]
Definition: crypto.h:365
foreach_crypto_op_status
#define foreach_crypto_op_status
Definition: crypto.h:73
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
CRYPTO_DISPATCH_N_NEXT
@ CRYPTO_DISPATCH_N_NEXT
Definition: node.c:42
crypto.h
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
crypto_dispatch_next_t
crypto_dispatch_next_t
Definition: node.c:37
vnet_crypto_main_t
Definition: crypto.h:451
VLIB_FRAME_SIZE
#define VLIB_FRAME_SIZE
Definition: node.h:368
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
crypto_dispatch_trace_t
Definition: node.c:45
crypto_dequeue_frame
static_always_inline u32 crypto_dequeue_frame(vlib_main_t *vm, vlib_node_runtime_t *node, vnet_crypto_thread_t *ct, vnet_crypto_frame_dequeue_t *hdl, u32 n_cache, u32 *n_total)
Definition: node.c:75
VLIB_NODE_TYPE_INPUT
@ VLIB_NODE_TYPE_INPUT
Definition: node.h:76
u16
unsigned short u16
Definition: types.h:57
vnet_crypto_async_frame_t
Definition: crypto.h:358
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vnet_crypto_async_frame_t::next_node_index
u16 next_node_index[VNET_CRYPTO_FRAME_SIZE]
Definition: crypto.h:366
vnet_crypto_async_frame_t::state
vnet_crypto_async_frame_state_t state
Definition: crypto.h:361
VNET_CRYPTO_ASYNC_DISPATCH_INTERRUPT
#define VNET_CRYPTO_ASYNC_DISPATCH_INTERRUPT
Definition: crypto.h:472
vlib_frame_t
Definition: node.h:372
crypto_dispatch_node
vlib_node_registration_t crypto_dispatch_node
(constructor) VLIB_REGISTER_NODE (crypto_dispatch_node)
Definition: node.c:178
clib_memcpy_fast
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
Definition: string.h:92
vnet_crypto_async_frame_t::op
vnet_crypto_async_op_id_t op
Definition: crypto.h:362
vnet_crypto_async_frame_elt_t::status
vnet_crypto_op_status_t status
Definition: crypto.h:341
VNET_CRYPTO_ASYNC_N_ERROR
@ VNET_CRYPTO_ASYNC_N_ERROR
Definition: node.c:25
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_buffer_enqueue_to_next_vec
static_always_inline void vlib_buffer_enqueue_to_next_vec(vlib_main_t *vm, vlib_node_runtime_t *node, u32 **buffers, u16 **nexts, uword count)
Definition: buffer_node.h:359
static_always_inline
#define static_always_inline
Definition: clib.h:112
vnet_crypto_thread_t::nexts
u16 * nexts
Definition: crypto.h:375
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:215
vlib_node_increment_counter
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1244
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:594
vec_validate
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment)
Definition: vec.h:523
foreach_crypto_dispatch_next
#define foreach_crypto_dispatch_next
Definition: node.c:34
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
crypto_main
vnet_crypto_main_t crypto_main
Definition: crypto.c:20
vnet_crypto_async_frame_t::n_elts
u16 n_elts
Definition: crypto.h:363
index
u32 index
Definition: flow_types.api:221
format_crypto_dispatch_trace
static u8 * format_crypto_dispatch_trace(u8 *s, va_list *args)
Definition: node.c:52
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
vnet_crypto_async_error_strings
static char * vnet_crypto_async_error_strings[]
Definition: node.c:28
vlib_node_set_interrupt_pending
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
Definition: node_funcs.h:249
VNET_CRYPTO_FRAME_STATE_SUCCESS
@ VNET_CRYPTO_FRAME_STATE_SUCCESS
Definition: crypto.h:354
crypto_dispatch_trace_t::op_status
vnet_crypto_op_status_t op_status
Definition: node.c:47
vlib_get_main_by_index
static vlib_main_t * vlib_get_main_by_index(u32 thread_index)
Definition: global_funcs.h:29
vnet_crypto_async_error_t
vnet_crypto_async_error_t
Definition: node.c:20
vnet_crypto_async_add_trace
static void vnet_crypto_async_add_trace(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b, vnet_crypto_async_op_id_t op_id, vnet_crypto_op_status_t status)
Definition: node.c:64
vlib_main_t
Definition: main.h:102
vlib_node_t
Definition: node.h:247
vlib_add_trace
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:628
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
vnet_crypto_async_op_id_t
vnet_crypto_async_op_id_t
Definition: crypto.h:182
i
int i
Definition: flowhash_template.h:376
crypto_dispatch_trace_t::op
vnet_crypto_async_op_id_t op
Definition: node.c:48
clib_bitmap_foreach
#define clib_bitmap_foreach(i, ai)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
vlib_node_runtime_t
Definition: node.h:454
vnet_crypto_thread_t
Definition: crypto.h:370
vnet_crypto_thread_t::buffer_indices
u32 * buffer_indices
Definition: crypto.h:374
format_vnet_crypto_async_op
format_function_t format_vnet_crypto_async_op
Definition: crypto.h:523
format_vnet_crypto_op_status
format_function_t format_vnet_crypto_op_status
Definition: crypto.h:520
vnet_crypto_op_status_t
vnet_crypto_op_status_t
Definition: crypto.h:136
vlib_buffer_t::flags
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
Definition: buffer.h:133
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169