FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
udp_encap_node.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2019 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 <vnet/udp/udp_encap.h>
17 #include <vnet/udp/udp.h>
18 
19 typedef struct udp4_encap_trace_t_
20 {
24 
25 typedef struct udp6_encap_trace_t_
26 {
30 
32 
33 static u8 *
34 format_udp4_encap_trace (u8 * s, va_list * args)
35 {
36  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
37  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
39 
40  t = va_arg (*args, udp4_encap_trace_t *);
41 
42  s = format (s, "%U\n %U",
43  format_ip4_header, &t->ip, sizeof (t->ip),
44  format_udp_header, &t->udp, sizeof (t->udp));
45  return (s);
46 }
47 
48 static u8 *
49 format_udp6_encap_trace (u8 * s, va_list * args)
50 {
51  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
52  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
54 
55  t = va_arg (*args, udp6_encap_trace_t *);
56 
57  s = format (s, "%U\n %U",
58  format_ip6_header, &t->ip, sizeof (t->ip),
59  format_udp_header, &t->udp, sizeof (t->udp));
60  return (s);
61 }
62 
66  vlib_frame_t * frame, int is_encap_v6)
67 {
70  u32 n_left_from, n_left_to_next, *to_next, next_index;
72 
73  n_left_from = frame->n_vectors;
74  next_index = node->cached_next_index;
75 
76  while (n_left_from > 0)
77  {
78  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
79 
80  while (n_left_from >= 4 && n_left_to_next >= 2)
81  {
82  vlib_buffer_t *b0, *b1;
83  udp_encap_t *ue0, *ue1;
84  u32 bi0, next0, uei0;
85  u32 bi1, next1, uei1;
86 
87  /* Prefetch next iteration. */
88  {
89  vlib_buffer_t *p2, *p3;
90 
91  p2 = vlib_get_buffer (vm, from[2]);
92  p3 = vlib_get_buffer (vm, from[3]);
93 
94  vlib_prefetch_buffer_header (p2, STORE);
95  vlib_prefetch_buffer_header (p3, STORE);
96  }
97 
98  bi0 = to_next[0] = from[0];
99  bi1 = to_next[1] = from[1];
100 
101  from += 2;
102  n_left_from -= 2;
103  to_next += 2;
104  n_left_to_next -= 2;
105 
106  b0 = vlib_get_buffer (vm, bi0);
107  b1 = vlib_get_buffer (vm, bi1);
108 
109  uei0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
110  uei1 = vnet_buffer (b1)->ip.adj_index[VLIB_TX];
111 
114  b0));
117  b1));
118 
119  /* Rewrite packet header and updates lengths. */
120  ue0 = udp_encap_get (uei0);
121  ue1 = udp_encap_get (uei1);
122 
123  /* Paint */
124  if (is_encap_v6)
125  {
126  const u8 n_bytes =
127  sizeof (udp_header_t) + sizeof (ip6_header_t);
128  ip_udp_encap_two (vm, b0, b1, (u8 *) & ue0->ue_hdrs,
129  (u8 *) & ue1->ue_hdrs, n_bytes, 0);
130  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
131  {
132  udp6_encap_trace_t *tr =
133  vlib_add_trace (vm, node, b0, sizeof (*tr));
134  tr->udp = ue0->ue_hdrs.ip6.ue_udp;
135  tr->ip = ue0->ue_hdrs.ip6.ue_ip6;
136  }
137  if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
138  {
139  udp6_encap_trace_t *tr =
140  vlib_add_trace (vm, node, b1, sizeof (*tr));
141  tr->udp = ue1->ue_hdrs.ip6.ue_udp;
142  tr->ip = ue1->ue_hdrs.ip6.ue_ip6;
143  }
144  }
145  else
146  {
147  const u8 n_bytes =
148  sizeof (udp_header_t) + sizeof (ip4_header_t);
149 
150  ip_udp_encap_two (vm, b0, b1,
151  (u8 *) & ue0->ue_hdrs,
152  (u8 *) & ue1->ue_hdrs, n_bytes, 1);
153 
154  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
155  {
156  udp4_encap_trace_t *tr =
157  vlib_add_trace (vm, node, b0, sizeof (*tr));
158  tr->udp = ue0->ue_hdrs.ip4.ue_udp;
159  tr->ip = ue0->ue_hdrs.ip4.ue_ip4;
160  }
161  if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
162  {
163  udp4_encap_trace_t *tr =
164  vlib_add_trace (vm, node, b1, sizeof (*tr));
165  tr->udp = ue1->ue_hdrs.ip4.ue_udp;
166  tr->ip = ue1->ue_hdrs.ip4.ue_ip4;
167  }
168  }
169 
170  next0 = ue0->ue_dpo.dpoi_next_node;
171  next1 = ue1->ue_dpo.dpoi_next_node;
172  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ue0->ue_dpo.dpoi_index;
173  vnet_buffer (b1)->ip.adj_index[VLIB_TX] = ue1->ue_dpo.dpoi_index;
174 
176  to_next, n_left_to_next,
177  bi0, bi1, next0, next1);
178  }
179 
180  while (n_left_from > 0 && n_left_to_next > 0)
181  {
182  u32 bi0, next0, uei0;
183  vlib_buffer_t *b0;
184  udp_encap_t *ue0;
185 
186  bi0 = to_next[0] = from[0];
187 
188  from += 1;
189  n_left_from -= 1;
190  to_next += 1;
191  n_left_to_next -= 1;
192 
193  b0 = vlib_get_buffer (vm, bi0);
194 
195  uei0 = vnet_buffer (b0)->ip.adj_index[VLIB_TX];
196 
197  /* Rewrite packet header and updates lengths. */
198  ue0 = udp_encap_get (uei0);
199 
202  b0));
203 
204  /* Paint */
205  if (is_encap_v6)
206  {
207  const u8 n_bytes =
208  sizeof (udp_header_t) + sizeof (ip6_header_t);
209  ip_udp_encap_one (vm, b0, (u8 *) & ue0->ue_hdrs.ip6, n_bytes,
210  0);
211 
212  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
213  {
214  udp6_encap_trace_t *tr =
215  vlib_add_trace (vm, node, b0, sizeof (*tr));
216  tr->udp = ue0->ue_hdrs.ip6.ue_udp;
217  tr->ip = ue0->ue_hdrs.ip6.ue_ip6;
218  }
219  }
220  else
221  {
222  const u8 n_bytes =
223  sizeof (udp_header_t) + sizeof (ip4_header_t);
224 
225  ip_udp_encap_one (vm, b0, (u8 *) & ue0->ue_hdrs.ip4, n_bytes,
226  1);
227 
228  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
229  {
230  udp4_encap_trace_t *tr =
231  vlib_add_trace (vm, node, b0, sizeof (*tr));
232  tr->udp = ue0->ue_hdrs.ip4.ue_udp;
233  tr->ip = ue0->ue_hdrs.ip4.ue_ip4;
234  }
235  }
236 
237  next0 = ue0->ue_dpo.dpoi_next_node;
238  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ue0->ue_dpo.dpoi_index;
239 
241  to_next, n_left_to_next,
242  bi0, next0);
243  }
244 
245  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
246  }
247 
248  return frame->n_vectors;
249 }
250 
254 {
255  return udp_encap_inline (vm, node, frame, 0);
256 }
257 
261 {
262  return udp_encap_inline (vm, node, frame, 1);
263 }
264 
265 /* *INDENT-OFF* */
267  .name = "udp4-encap",
268  .vector_size = sizeof (u32),
269 
270  .format_trace = format_udp4_encap_trace,
271 
272  .n_next_nodes = 0,
273 };
274 
276  .name = "udp6-encap",
277  .vector_size = sizeof (u32),
278 
279  .format_trace = format_udp6_encap_trace,
280 
281  .n_next_nodes = 0,
282 };
283 /* *INDENT-ON* */
284 
285 
286 /*
287  * fd.io coding-style-patch-verification: ON
288  *
289  * Local Variables:
290  * eval: (c-set-style "gnu")
291  * End:
292  */
dpo_id_t_::dpoi_next_node
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:186
dpo_id_t_::dpoi_index
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:190
thread_index
u32 thread_index
Definition: nat44_ei_hairpinning.c:495
vlib_prefetch_buffer_header
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:231
frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
Definition: nat44_ei.c:3048
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
udp4_encap_trace_t_
Definition: udp_encap_node.c:19
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
format_ip6_header
format_function_t format_ip6_header
Definition: format.h:95
udp4_encap_trace_t_::udp
udp_header_t udp
Definition: udp_encap_node.c:21
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
udp6_encap_trace_t_
Definition: udp_encap_node.c:25
udp_encap_t_::ip4
struct udp_encap_t_::@565::@566 ip4
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
udp_encap_t_::ip6
struct udp_encap_t_::@565::@567 ip6
udp_encap_t_
The UDP encap representation.
Definition: udp_encap.h:46
vlib_frame_t
Definition: node.h:372
udp4_encap_trace_t_::ip
ip4_header_t ip
Definition: udp_encap_node.c:22
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
ip_udp_encap_one
static void ip_udp_encap_one(vlib_main_t *vm, vlib_buffer_t *b0, u8 *ec0, word ec_len, u8 is_ip4)
Definition: udp_inlines.h:100
udp_header_t
Definition: udp_packet.h:45
ip4_header_t
Definition: ip4_packet.h:87
format_udp_header
format_function_t format_udp_header
Definition: format.h:100
udp4_encap_node
vlib_node_registration_t udp4_encap_node
(constructor) VLIB_REGISTER_NODE (udp4_encap_node)
Definition: udp_encap_node.c:266
VLIB_NODE_FN
#define VLIB_NODE_FN(node)
Definition: node.h:202
udp_encap.h
udp6_encap_trace_t
struct udp6_encap_trace_t_ udp6_encap_trace_t
CLIB_UNUSED
#define CLIB_UNUSED(x)
Definition: clib.h:90
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:441
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
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
udp4_encap_trace_t
struct udp4_encap_trace_t_ udp4_encap_trace_t
ip_udp_encap_two
static void ip_udp_encap_two(vlib_main_t *vm, vlib_buffer_t *b0, vlib_buffer_t *b1, u8 *ec0, u8 *ec1, word ec_len, u8 is_v4)
Definition: udp_inlines.h:130
udp_encap_counters
vlib_combined_counter_main_t udp_encap_counters
Stats for each UDP encap object.
Definition: udp_encap.c:35
uword
u64 uword
Definition: types.h:112
vlib_main_t::thread_index
u32 thread_index
Definition: main.h:215
udp_encap_get
static udp_encap_t * udp_encap_get(index_t uei)
Definition: udp_encap.h:141
cm
vnet_feature_config_main_t * cm
Definition: nat44_ei_hairpinning.c:594
format_udp6_encap_trace
static u8 * format_udp6_encap_trace(u8 *s, va_list *args)
Definition: udp_encap_node.c:49
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
vlib_validate_buffer_enqueue_x1
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
always_inline
#define always_inline
Definition: rdma_mlx5dv.h:23
udp6_encap_trace_t_::ip
ip6_header_t ip
Definition: udp_encap_node.c:28
format
description fragment has unexpected format
Definition: map.api:433
vlib_combined_counter_main_t
A collection of combined counters.
Definition: counter.h:203
udp6_encap_node
vlib_node_registration_t udp6_encap_node
(constructor) VLIB_REGISTER_NODE (udp6_encap_node)
Definition: udp_encap_node.c:275
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
u32
unsigned int u32
Definition: types.h:88
n_bytes
u32 n_bytes
Definition: interface_output.c:421
format_udp4_encap_trace
static u8 * format_udp4_encap_trace(u8 *s, va_list *args)
Definition: udp_encap_node.c:34
udp_encap_t_::ue_dpo
dpo_id_t ue_dpo
The DPO used to forward to the next node in the VLIB graph.
Definition: udp_encap.h:73
udp.h
ip6_header_t
Definition: ip6_packet.h:294
format_ip4_header
format_function_t format_ip4_header
Definition: format.h:81
udp_encap_t_::ue_hdrs
union udp_encap_t_::@565 ue_hdrs
The headers to paint, in packet painting order.
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
udp6_encap_trace_t_::udp
udp_header_t udp
Definition: udp_encap_node.c:27
u8
unsigned char u8
Definition: types.h:56
vlib_validate_buffer_enqueue_x2
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
Definition: buffer_node.h:70
vlib_node_runtime_t
Definition: node.h:454
from
from
Definition: nat44_ei_hairpinning.c:415
vlib_get_next_frame
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:395
VLIB_TX
@ VLIB_TX
Definition: defs.h:47
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
udp_encap_inline
static uword udp_encap_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_encap_v6)
Definition: udp_encap_node.c:64
vlib_increment_combined_counter
vlib_increment_combined_counter(ccm, ti, sw_if_index, n_buffers, n_bytes)
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