FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
node.c
Go to the documentation of this file.
1 /*
2  * node.c - - awkward chained buffer geometry test tool
3  *
4  * Copyright (c) 2019 by Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
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 #include <vlib/vlib.h>
18 #include <vnet/vnet.h>
19 #include <vppinfra/error.h>
20 #include <oddbuf/oddbuf.h>
21 
22 typedef struct
23 {
28 
29 #ifndef CLIB_MARCH_VARIANT
30 
31 /* packet trace format function */
32 static u8 *
33 format_oddbuf_trace (u8 * s, va_list * args)
34 {
35  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
36  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
37  oddbuf_trace_t *t = va_arg (*args, oddbuf_trace_t *);
38 
39  s = format (s, "ODDBUF: sw_if_index %d, next index %d, udp checksum %04x\n",
40  t->sw_if_index, t->next_index, (u32) t->udp_checksum);
41  return s;
42 }
43 
45 
46 #endif /* CLIB_MARCH_VARIANT */
47 
48 #define foreach_oddbuf_error \
49 _(SWAPPED, "Mac swap packets processed")
50 
51 typedef enum
52 {
53 #define _(sym,str) ODDBUF_ERROR_##sym,
55 #undef _
58 
59 #ifndef CLIB_MARCH_VARIANT
60 static char *oddbuf_error_strings[] = {
61 #define _(sym,string) string,
63 #undef _
64 };
65 #endif /* CLIB_MARCH_VARIANT */
66 
67 typedef enum
68 {
72 
73 
77  int is_ip4, int is_trace)
78 {
82  vlib_buffer_t *b0, *b0next;
83  u32 bi;
85  u16 save_current_length;
86  u32 next0;
87  u8 *src, *dst;
88  int i;
91  udp_header_t *udp;
92 
93 
95  n_left_from = frame->n_vectors;
96 
98  b = bufs;
99  next = nexts;
100 
101  while (n_left_from > 0)
102  {
103  b0 = b[0];
104  vnet_feature_next (&next0, b0);
105  nexts[0] = next0;
106 
107  if (vlib_buffer_alloc (vm, &bi, 1) != 1)
108  {
109  clib_warning ("Buffer alloc fail, skipping");
110  goto skip;
111  }
112 
113  if (om->first_chunk_offset)
114  {
115  memmove (b0->data + b0->current_data + om->first_chunk_offset,
116  b0->data + b0->current_data, b0->current_length);
117  b0->current_data += om->first_chunk_offset;
118  }
119 
120  eh = vlib_buffer_get_current (b0);
121  ip = (ip4_header_t *) (eh + 1);
122  udp = (udp_header_t *) (ip4_next_header (ip));
123 
124  if (1)
125  {
126  save_current_length = vlib_buffer_length_in_chain (vm, b0);
127 
128  b0next = vlib_get_buffer (vm, bi);
129  b0->flags |= VLIB_BUFFER_NEXT_PRESENT;
130  b0->flags &= ~VLIB_BUFFER_TOTAL_LENGTH_VALID;
131  b0->next_buffer = bi;
132 
133  src = b0->data + b0->current_data + b0->current_length -
134  om->n_to_copy;
135  b0next->current_data = om->second_chunk_offset;
136  b0next->current_length = om->n_to_copy;
137  dst = b0next->data + b0next->current_data;
138 
139  for (i = 0; i < om->n_to_copy; i++)
140  dst[i] = src[i];
141 
142  b0->current_length -= om->n_to_copy;
143  b0next->current_length = om->n_to_copy;
144 
145  if (vlib_buffer_length_in_chain (vm, b0) != save_current_length)
146  clib_warning ("OOPS, length incorrect after chunk split...");
147  }
148 
149  udp->checksum = 0;
151 
152  if (is_trace)
153  {
154  if (b[0]->flags & VLIB_BUFFER_IS_TRACED)
155  {
156  oddbuf_trace_t *t =
157  vlib_add_trace (vm, node, b[0], sizeof (*t));
158  t->next_index = next[0];
159  t->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
160  t->udp_checksum = clib_net_to_host_u16 (udp->checksum);
161  }
162  }
163 
164  skip:
165  b += 1;
166  next += 1;
167  n_left_from -= 1;
168  }
169 
171 
172  return frame->n_vectors;
173 }
174 
177 {
178  if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
179  return oddbuf_inline (vm, node, frame, 1 /* is_ip4 */ ,
180  1 /* is_trace */ );
181  else
182  return oddbuf_inline (vm, node, frame, 1 /* is_ip4 */ ,
183  0 /* is_trace */ );
184 }
185 
186 /* *INDENT-OFF* */
187 #ifndef CLIB_MARCH_VARIANT
189 {
190  .name = "oddbuf",
191  .vector_size = sizeof (u32),
192  .format_trace = format_oddbuf_trace,
194 
195  .n_errors = ARRAY_LEN(oddbuf_error_strings),
196  .error_strings = oddbuf_error_strings,
197 
198  .n_next_nodes = ODDBUF_N_NEXT,
199 
200  /* edit / add dispositions here */
201  .next_nodes = {
202  [ODDBUF_NEXT_DROP] = "error-drop",
203  },
204 };
205 #endif /* CLIB_MARCH_VARIANT */
206 /* *INDENT-ON* */
207 
208 /*
209  * fd.io coding-style-patch-verification: ON
210  *
211  * Local Variables:
212  * eval: (c-set-style "gnu")
213  * End:
214  */
vlib.h
oddbuf_main_t
Definition: oddbuf.h:28
vlib_buffer_t::next_buffer
u32 next_buffer
Next buffer for this linked-list of buffers.
Definition: buffer.h:149
bufs
vlib_buffer_t * bufs[VLIB_FRAME_SIZE]
Definition: nat44_ei_out2in.c:717
oddbuf_trace_t
Definition: node.c:22
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
oddbuf_error_t
oddbuf_error_t
Definition: node.c:51
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
oddbuf_main_t::second_chunk_offset
int second_chunk_offset
Definition: oddbuf.h:38
vlib_get_buffers
vlib_get_buffers(vm, from, b, n_left_from)
next
u16 * next
Definition: nat44_ei_out2in.c:718
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
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
format_oddbuf_trace
static u8 * format_oddbuf_trace(u8 *s, va_list *args)
Definition: node.c:33
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
VLIB_RX
@ VLIB_RX
Definition: defs.h:46
vlib_buffer_enqueue_to_next
vlib_buffer_enqueue_to_next(vm, node, from,(u16 *) nexts, frame->n_vectors)
oddbuf_next_t
oddbuf_next_t
Definition: node.c:67
oddbuf.h
vlib_frame_t
Definition: node.h:372
vlib_buffer_length_in_chain
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:433
udp_header_t
Definition: udp_packet.h:45
ip4_header_t
Definition: ip4_packet.h:87
ODDBUF_N_NEXT
@ ODDBUF_N_NEXT
Definition: node.c:70
vlib_buffer_t::current_data
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:119
error.h
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
vlib_buffer_alloc
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: buffer_funcs.h:702
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
VLIB_NODE_FLAG_TRACE
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:291
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
vnet_feature_next
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
Definition: feature.h:322
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
foreach_oddbuf_error
#define foreach_oddbuf_error
Definition: node.c:48
ip4_tcp_udp_compute_checksum
u16 ip4_tcp_udp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip4_header_t *ip0)
Definition: pnat_test_stubs.h:59
uword
u64 uword
Definition: types.h:112
ethernet_header_t
Definition: packet.h:52
src
vl_api_address_t src
Definition: gre.api:54
ODDBUF_NEXT_DROP
@ ODDBUF_NEXT_DROP
Definition: node.c:69
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_buffer_t::current_length
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:122
oddbuf_error_strings
static char * oddbuf_error_strings[]
Definition: node.c:60
udp_header_t::checksum
u16 checksum
Definition: udp_packet.h:55
oddbuf_main_t::first_chunk_offset
int first_chunk_offset
Definition: oddbuf.h:39
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
oddbuf_node
vlib_node_registration_t oddbuf_node
(constructor) VLIB_REGISTER_NODE (oddbuf_node)
Definition: node.c:44
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
oddbuf_trace_t::sw_if_index
u32 sw_if_index
Definition: node.c:24
dst
vl_api_ip4_address_t dst
Definition: pnat.api:41
oddbuf_inline
static uword oddbuf_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_ip4, int is_trace)
Definition: node.c:75
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
ODDBUF_N_ERROR
@ ODDBUF_N_ERROR
Definition: node.c:56
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
u8
unsigned char u8
Definition: types.h:56
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
ip
vl_api_address_t ip
Definition: l2.api:558
oddbuf_trace_t::next_index
u32 next_index
Definition: node.c:25
vlib_buffer_t::data
u8 data[]
Packet data.
Definition: buffer.h:204
oddbuf_main
oddbuf_main_t oddbuf_main
Definition: oddbuf.c:34
i
int i
Definition: flowhash_template.h:376
oddbuf_trace_t::udp_checksum
u16 udp_checksum
Definition: node.c:26
clib_warning
#define clib_warning(format, args...)
Definition: error.h:59
nexts
u16 nexts[VLIB_FRAME_SIZE]
Definition: nat44_ei_out2in.c:718
vnet.h
vlib_node_runtime_t
Definition: node.h:454
oddbuf_main_t::n_to_copy
int n_to_copy
Definition: oddbuf.h:37
from
from
Definition: nat44_ei_hairpinning.c:415
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
ip4_next_header
static void * ip4_next_header(ip4_header_t *i)
Definition: ip4_packet.h:196
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
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105