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 #ifndef __included_vxlan_gpe_ioam_util_h__
16 #define __included_vxlan_gpe_ioam_util_h__
18 #include <vnet/vxlan-gpe/vxlan_gpe.h>
19 #include <vnet/vxlan-gpe/vxlan_gpe_packet.h>
20 #include <vnet/ip/ip.h>
26 ioam_trace_t fmt_trace;
27 } vxlan_gpe_ioam_v4_trace_t;
31 format_vxlan_gpe_ioam_v4_trace (u8 * s, va_list * args)
33 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
34 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
35 vxlan_gpe_ioam_v4_trace_t *t1 = va_arg (*args, vxlan_gpe_ioam_v4_trace_t *);
36 ioam_trace_t *t = &(t1->fmt_trace);
37 vxlan_gpe_ioam_option_t *fmt_trace0;
38 vxlan_gpe_ioam_option_t *opt0, *limit0;
39 vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
43 fmt_trace0 = (vxlan_gpe_ioam_option_t *) t->option_data;
45 s = format (s, "VXLAN-GPE-IOAM: next_index %d len %d traced %d",
46 t->next_index, fmt_trace0->length, t->trace_len);
48 opt0 = (vxlan_gpe_ioam_option_t *) (fmt_trace0 + 1);
49 limit0 = (vxlan_gpe_ioam_option_t *) ((u8 *) fmt_trace0) + t->trace_len;
56 case 0: /* Pad, just stop */
57 opt0 = (vxlan_gpe_ioam_option_t *) ((u8 *) opt0) + 1;
63 s = (*hm->trace[type0]) (s, opt0);
68 format (s, "\n unrecognized option %d length %d", type0,
72 (vxlan_gpe_ioam_option_t *) (((u8 *) opt0) + opt0->length +
73 sizeof (vxlan_gpe_ioam_option_t));
78 s = format (s, "VXLAN-GPE-IOAM: tunnel %d", t1->tunnel_index);
84 vxlan_gpe_encap_decap_ioam_v4_one_inline (vlib_main_t * vm,
85 vlib_node_runtime_t * node,
87 u32 * next0, u32 drop_node_val,
91 udp_header_t *udp_hdr0;
92 vxlan_gpe_header_t *gpe_hdr0;
93 vxlan_gpe_ioam_hdr_t *gpe_ioam0;
94 vxlan_gpe_ioam_option_t *opt0;
95 vxlan_gpe_ioam_option_t *limit0;
96 vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
98 /* Populate the iOAM header */
99 ip0 = vlib_buffer_get_current (b0);
100 udp_hdr0 = (udp_header_t *) (ip0 + 1);
101 gpe_hdr0 = (vxlan_gpe_header_t *) (udp_hdr0 + 1);
102 gpe_ioam0 = (vxlan_gpe_ioam_hdr_t *) (gpe_hdr0 + 1);
103 opt0 = (vxlan_gpe_ioam_option_t *) (gpe_ioam0 + 1);
104 limit0 = (vxlan_gpe_ioam_option_t *) ((u8 *) gpe_ioam0 + gpe_ioam0->length);
107 * Basic validity checks
109 if (gpe_ioam0->length > clib_net_to_host_u16 (ip0->length))
111 *next0 = drop_node_val;
115 /* Scan the set of h-b-h options, process ones that we understand */
116 while (opt0 < limit0)
123 opt0 = (vxlan_gpe_ioam_option_t *) ((u8 *) opt0) + 1;
128 if (hm->options[type0])
130 if ((*hm->options[type0]) (b0, opt0, 1 /* is_ipv4 */ ,
133 *next0 = drop_node_val;
140 (vxlan_gpe_ioam_option_t *) (((u8 *) opt0) + opt0->length +
141 sizeof (vxlan_gpe_ioam_hdr_t));
145 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
147 vxlan_gpe_ioam_v4_trace_t *t =
148 vlib_add_trace (vm, node, b0, sizeof (*t));
149 u32 trace_len = gpe_ioam0->length;
150 t->fmt_trace.next_index = *next0;
151 /* Capture the ioam option verbatim */
154 ARRAY_LEN (t->fmt_trace.
155 option_data) ? trace_len : ARRAY_LEN (t->fmt_trace.
157 t->fmt_trace.trace_len = trace_len;
158 clib_memcpy (&(t->fmt_trace.option_data), gpe_ioam0, trace_len);
167 * fd.io coding-style-patch-verification: ON
170 * eval: (c-set-style "gnu")