2 * Copyright (c) 2015 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <vppinfra/error.h>
16 #include <vppinfra/hash.h>
17 #include <vnet/vnet.h>
18 #include <vnet/ip/ip.h>
19 #include <vnet/ethernet/ethernet.h>
20 #include <vnet/vxlan-gpe/vxlan_gpe.h>
21 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
23 /* Statistics (not really errors) */
24 #define foreach_vxlan_gpe_pop_ioam_v4_error \
25 _(POPPED, "good packets popped")
27 static char *vxlan_gpe_pop_ioam_v4_error_strings[] = {
28 #define _(sym,string) string,
29 foreach_vxlan_gpe_pop_ioam_v4_error
35 #define _(sym,str) VXLAN_GPE_POP_IOAM_V4_ERROR_##sym,
36 foreach_vxlan_gpe_pop_ioam_v4_error
38 VXLAN_GPE_POP_IOAM_V4_N_ERROR,
39 } vxlan_gpe_pop_ioam_v4_error_t;
43 ioam_trace_t fmt_trace;
44 } vxlan_gpe_pop_ioam_v4_trace_t;
48 format_vxlan_gpe_pop_ioam_v4_trace (u8 * s, va_list * args)
50 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
51 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
52 vxlan_gpe_pop_ioam_v4_trace_t *t1
53 = va_arg (*args, vxlan_gpe_pop_ioam_v4_trace_t *);
54 ioam_trace_t *t = &(t1->fmt_trace);
55 vxlan_gpe_ioam_option_t *fmt_trace0;
56 vxlan_gpe_ioam_option_t *opt0, *limit0;
57 vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
61 fmt_trace0 = (vxlan_gpe_ioam_option_t *) t->option_data;
63 s = format (s, "VXLAN_GPE_IOAM_POP: next_index %d len %d traced %d",
64 t->next_index, fmt_trace0->length, t->trace_len);
66 opt0 = (vxlan_gpe_ioam_option_t *) (fmt_trace0 + 1);
67 limit0 = (vxlan_gpe_ioam_option_t *) ((u8 *) fmt_trace0) + t->trace_len;
74 case 0: /* Pad, just stop */
75 opt0 = (vxlan_gpe_ioam_option_t *) ((u8 *) opt0) + 1;
81 s = (*hm->trace[type0]) (s, opt0);
86 format (s, "\n unrecognized option %d length %d", type0,
90 (vxlan_gpe_ioam_option_t *) (((u8 *) opt0) + opt0->length +
91 sizeof (vxlan_gpe_ioam_option_t));
100 vxlan_gpe_ioam_pop_v4 (vlib_main_t * vm, vlib_node_runtime_t * node,
104 udp_header_t *udp_hdr0;
105 vxlan_gpe_header_t *gpe_hdr0;
106 vxlan_gpe_ioam_hdr_t *gpe_ioam0;
108 ip0 = vlib_buffer_get_current (b0);
110 udp_hdr0 = (udp_header_t *) (ip0 + 1);
111 gpe_hdr0 = (vxlan_gpe_header_t *) (udp_hdr0 + 1);
112 gpe_ioam0 = (vxlan_gpe_ioam_hdr_t *) (gpe_hdr0 + 1);
114 /* Pop the iOAM data */
115 vlib_buffer_advance (b0,
116 (word) (sizeof (udp_header_t) +
117 sizeof (ip4_header_t) +
118 sizeof (vxlan_gpe_header_t) +
127 vxlan_gpe_pop_ioam_v4_one_inline (vlib_main_t * vm,
128 vlib_node_runtime_t * node,
129 vxlan_gpe_main_t * ngm,
130 vlib_buffer_t * b0, u32 * next0)
132 CLIB_UNUSED (ip4_header_t * ip0);
133 CLIB_UNUSED (udp_header_t * udp_hdr0);
134 CLIB_UNUSED (vxlan_gpe_header_t * gpe_hdr0);
135 CLIB_UNUSED (vxlan_gpe_ioam_hdr_t * gpe_ioam0);
136 CLIB_UNUSED (vxlan_gpe_ioam_option_t * opt0);
137 CLIB_UNUSED (vxlan_gpe_ioam_option_t * limit0);
138 vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
141 /* Pop the iOAM header */
142 ip0 = vlib_buffer_get_current (b0);
143 udp_hdr0 = (udp_header_t *) (ip0 + 1);
144 gpe_hdr0 = (vxlan_gpe_header_t *) (udp_hdr0 + 1);
145 gpe_ioam0 = (vxlan_gpe_ioam_hdr_t *) (gpe_hdr0 + 1);
146 opt0 = (vxlan_gpe_ioam_option_t *) (gpe_ioam0 + 1);
147 limit0 = (vxlan_gpe_ioam_option_t *) ((u8 *) gpe_ioam0 + gpe_ioam0->length);
150 * Basic validity checks
152 if (gpe_ioam0->length > clib_net_to_host_u16 (ip0->length))
154 *next0 = VXLAN_GPE_INPUT_NEXT_DROP;
158 /* Scan the set of h-b-h options, process ones that we understand */
159 while (opt0 < limit0)
166 opt0 = (vxlan_gpe_ioam_option_t *) ((u8 *) opt0) + 1;
171 if (hm->pop_options[type0])
173 if ((*hm->pop_options[type0]) (ip0, opt0) < 0)
175 *next0 = VXLAN_GPE_INPUT_NEXT_DROP;
182 (vxlan_gpe_ioam_option_t *) (((u8 *) opt0) + opt0->length +
183 sizeof (vxlan_gpe_ioam_hdr_t));
188 (gpe_ioam0->protocol < VXLAN_GPE_PROTOCOL_MAX) ?
190 decap_next_node_list[gpe_ioam0->protocol] : VXLAN_GPE_INPUT_NEXT_DROP;
193 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
195 vxlan_gpe_pop_ioam_v4_trace_t *t =
196 vlib_add_trace (vm, node, b0, sizeof (*t));
197 u32 trace_len = gpe_ioam0->length;
198 t->fmt_trace.next_index = *next0;
199 /* Capture the h-b-h option verbatim */
202 ARRAY_LEN (t->fmt_trace.
203 option_data) ? trace_len : ARRAY_LEN (t->fmt_trace.
205 t->fmt_trace.trace_len = trace_len;
206 clib_memcpy (&(t->fmt_trace.option_data), gpe_ioam0, trace_len);
209 /* Remove the iOAM header inside the VxLAN-GPE header */
210 vxlan_gpe_ioam_pop_v4 (vm, node, b0);
215 vxlan_gpe_pop_ioam_v4_two_inline (vlib_main_t * vm,
216 vlib_node_runtime_t * node,
217 vxlan_gpe_main_t * ngm,
218 vlib_buffer_t * b0, vlib_buffer_t * b1,
219 u32 * next0, u32 * next1)
222 vxlan_gpe_pop_ioam_v4_one_inline (vm, node, ngm, b0, next0);
223 vxlan_gpe_pop_ioam_v4_one_inline (vm, node, ngm, b1, next1);
229 vxlan_gpe_pop_ioam (vlib_main_t * vm,
230 vlib_node_runtime_t * node,
231 vlib_frame_t * from_frame, u8 is_ipv6)
233 u32 n_left_from, next_index, *from, *to_next;
234 vxlan_gpe_main_t *ngm = &vxlan_gpe_main;
236 from = vlib_frame_vector_args (from_frame);
237 n_left_from = from_frame->n_vectors;
239 next_index = node->cached_next_index;
241 while (n_left_from > 0)
245 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
247 while (n_left_from >= 4 && n_left_to_next >= 2)
250 vlib_buffer_t *b0, *b1;
253 /* Prefetch next iteration. */
255 vlib_buffer_t *p2, *p3;
257 p2 = vlib_get_buffer (vm, from[2]);
258 p3 = vlib_get_buffer (vm, from[3]);
260 vlib_prefetch_buffer_header (p2, LOAD);
261 vlib_prefetch_buffer_header (p3, LOAD);
263 CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
264 CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
276 b0 = vlib_get_buffer (vm, bi0);
277 b1 = vlib_get_buffer (vm, bi1);
279 vxlan_gpe_pop_ioam_v4_two_inline (vm, node, ngm, b0, b1, &next0,
283 vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next,
284 n_left_to_next, bi0, bi1, next0,
288 while (n_left_from > 0 && n_left_to_next > 0)
301 b0 = vlib_get_buffer (vm, bi0);
303 vxlan_gpe_pop_ioam_v4_one_inline (vm, node, ngm, b0, &next0);
306 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
307 n_left_to_next, bi0, next0);
310 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
313 return from_frame->n_vectors;
318 vxlan_gpe_pop_ioam_v4 (vlib_main_t * vm,
319 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
321 return vxlan_gpe_pop_ioam (vm, node, from_frame, 0);
325 VLIB_REGISTER_NODE (vxlan_gpe_pop_ioam_v4_node) = {
326 .function = vxlan_gpe_pop_ioam_v4,
327 .name = "vxlan-gpe-pop-ioam-v4",
328 .vector_size = sizeof (u32),
329 .format_trace = format_vxlan_gpe_pop_ioam_v4_trace,
330 .type = VLIB_NODE_TYPE_INTERNAL,
332 .n_errors = ARRAY_LEN(vxlan_gpe_pop_ioam_v4_error_strings),
333 .error_strings = vxlan_gpe_pop_ioam_v4_error_strings,
335 .n_next_nodes = VXLAN_GPE_INPUT_N_NEXT,
338 #define _(s,n) [VXLAN_GPE_INPUT_NEXT_##s] = n,
339 foreach_vxlan_gpe_input_next
348 * fd.io coding-style-patch-verification: ON
351 * eval: (c-set-style "gnu")