FD.io VPP  v20.05.1-6-gf53edbc3b
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 
78  u32 n_cache, u32 * n_total)
79 {
80  vnet_crypto_async_frame_t *cf = (hdl) (vm);
81 
82  while (cf)
83  {
84  vec_validate (ct->buffer_indice, n_cache + cf->n_elts);
85  vec_validate (ct->nexts, n_cache + cf->n_elts);
86  clib_memcpy_fast (ct->buffer_indice + n_cache, cf->buffer_indices,
87  sizeof (u32) * cf->n_elts);
89  {
90  clib_memcpy_fast (ct->nexts + n_cache, cf->next_node_index,
91  sizeof (u16) * cf->n_elts);
92  }
93  else
94  {
95  u32 i;
96  for (i = 0; i < cf->n_elts; i++)
97  {
98  if (cf->elts[i].status != VNET_CRYPTO_OP_STATUS_COMPLETED)
99  {
100  ct->nexts[i + n_cache] = CRYPTO_DISPATCH_NEXT_ERR_DROP;
102  cf->elts[i].status, 1);
103  }
104  else
105  ct->nexts[i + n_cache] = cf->next_node_index[i];
106  }
107  }
108  n_cache += cf->n_elts;
109  *n_total += cf->n_elts;
110  if (n_cache >= VLIB_FRAME_SIZE)
111  {
112  vlib_buffer_enqueue_to_next (vm, node, ct->buffer_indice, ct->nexts,
113  n_cache);
114  n_cache = 0;
115  }
116 
118  {
119  u32 i;
120 
121  for (i = 0; i < cf->n_elts; i++)
122  {
123  vlib_buffer_t *b = vlib_get_buffer (vm, cf->buffer_indices[i]);
124  if (b->flags & VLIB_BUFFER_IS_TRACED)
125  vnet_crypto_async_add_trace (vm, node, b, cf->op,
126  cf->elts[i].status);
127  }
128  }
130  cf = (hdl) (vm);
131  }
132 
133  return n_cache;
134 }
135 
139 {
141  vnet_crypto_thread_t *ct = cm->threads + vm->thread_index;
142  u32 n_dispatched = 0, n_cache = 0;
143  u32 index;
144 
145  /* *INDENT-OFF* */
146  clib_bitmap_foreach (index, cm->async_active_ids, ({
147  n_cache = crypto_dequeue_frame (vm, node, ct, cm->dequeue_handlers[index],
148  n_cache, &n_dispatched);
149  }));
150  /* *INDENT-ON* */
151  if (n_cache)
153  n_cache);
154 
155  return n_dispatched;
156 }
157 
158 /* *INDENT-OFF* */
160  .name = "crypto-dispatch",
161  .type = VLIB_NODE_TYPE_INPUT,
162  .state = VLIB_NODE_STATE_DISABLED,
163  .format_trace = format_crypto_dispatch_trace,
164 
166  .error_strings = vnet_crypto_async_error_strings,
167 
168  .n_next_nodes = CRYPTO_DISPATCH_N_NEXT,
169  .next_nodes = {
170 #define _(n, s) \
171  [CRYPTO_DISPATCH_NEXT_##n] = s,
173 #undef _
174  },
175 };
176 /* *INDENT-ON* */
177 
178 /*
179  * fd.io coding-style-patch-verification: ON
180  *
181  * Local Variables:
182  * eval: (c-set-style "gnu")
183  * End:
184  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:507
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
#define foreach_crypto_op_status
Definition: crypto.h:63
vnet_crypto_thread_t * threads
Definition: crypto.h:415
#define CLIB_UNUSED(x)
Definition: clib.h:86
crypto_dispatch_next_t
Definition: node.c:37
vnet_crypto_op_status_t op_status
Definition: node.c:47
static char * vnet_crypto_async_error_strings[]
Definition: node.c:28
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
u32 thread_index
Definition: main.h:218
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
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
#define VLIB_NODE_FN(node)
Definition: node.h:202
unsigned char u8
Definition: types.h:56
format_function_t format_vnet_crypto_async_op
Definition: crypto.h:478
#define static_always_inline
Definition: clib.h:106
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
vnet_crypto_async_op_id_t op
Definition: node.c:48
vnet_crypto_async_frame_t *() vnet_crypto_frame_dequeue_t(vlib_main_t *vm)
Definition: crypto.h:360
unsigned int u32
Definition: types.h:88
#define VLIB_FRAME_SIZE
Definition: node.h:380
vnet_crypto_main_t * cm
Definition: quic_crypto.c:53
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
u16 next_node_index[VNET_CRYPTO_FRAME_SIZE]
Definition: crypto.h:330
unsigned short u16
Definition: types.h:57
vnet_crypto_async_error_t
Definition: node.c:20
#define PREDICT_FALSE(x)
Definition: clib.h:118
static_always_inline void vnet_crypto_async_free_frame(vlib_main_t *vm, vnet_crypto_async_frame_t *frame)
Definition: crypto.h:538
u32 node_index
Node index.
Definition: node.h:498
vlib_main_t * vm
Definition: in2out_ed.c:1599
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1150
static u8 * format_crypto_dispatch_trace(u8 *s, va_list *args)
Definition: node.c:52
u32 buffer_indices[VNET_CRYPTO_FRAME_SIZE]
Definition: crypto.h:329
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
static_always_inline void vlib_buffer_enqueue_to_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 *nexts, uword count)
Definition: buffer_node.h:339
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define VNET_CRYPTO_FRAME_STATE_SUCCESS
Definition: crypto.h:323
#define ARRAY_LEN(x)
Definition: clib.h:66
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1599
vnet_crypto_op_status_t
Definition: crypto.h:112
format_function_t format_vnet_crypto_op_status
Definition: crypto.h:475
clib_bitmap_t * async_active_ids
Definition: crypto.h:420
vlib_node_registration_t crypto_dispatch_node
(constructor) VLIB_REGISTER_NODE (crypto_dispatch_node)
Definition: node.c:159
vnet_crypto_async_op_id_t
Definition: crypto.h:156
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
vnet_crypto_async_op_id_t op
Definition: crypto.h:326
VLIB buffer representation.
Definition: buffer.h:102
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: in2out_ed.c:1600
u16 flags
Copy of main node flags.
Definition: node.h:511
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:304
#define foreach_crypto_dispatch_next
Definition: node.c:34
vnet_crypto_main_t crypto_main
Definition: crypto.c:20
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
vnet_crypto_op_status_t status
Definition: crypto.h:301
vnet_crypto_async_frame_elt_t elts[VNET_CRYPTO_FRAME_SIZE]
Definition: crypto.h:328