FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
vxlan_gpe_ioam_util.h
Go to the documentation of this file.
1 /*
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:
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 #ifndef __included_vxlan_gpe_ioam_util_h__
16 #define __included_vxlan_gpe_ioam_util_h__
17 
20 #include <vnet/ip/ip.h>
21 
22 
23 typedef struct
24 {
28 
29 
30 static u8 *
31 format_vxlan_gpe_ioam_v4_trace (u8 * s, va_list * args)
32 {
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 *);
36  ioam_trace_t *t = &(t1->fmt_trace);
37  vxlan_gpe_ioam_option_t *fmt_trace0;
38  vxlan_gpe_ioam_option_t *opt0, *limit0;
40 
41  u8 type0;
42 
43  fmt_trace0 = (vxlan_gpe_ioam_option_t *) t->option_data;
44 
45  s = format (s, "VXLAN-GPE-IOAM: next_index %d len %d traced %d",
46  t->next_index, fmt_trace0->length, t->trace_len);
47 
48  opt0 = (vxlan_gpe_ioam_option_t *) (fmt_trace0 + 1);
49  limit0 = (vxlan_gpe_ioam_option_t *) ((u8 *) fmt_trace0) + t->trace_len;
50 
51  while (opt0 < limit0)
52  {
53  type0 = opt0->type;
54  switch (type0)
55  {
56  case 0: /* Pad, just stop */
57  opt0 = (vxlan_gpe_ioam_option_t *) ((u8 *) opt0) + 1;
58  break;
59 
60  default:
61  if (hm->trace[type0])
62  {
63  s = (*hm->trace[type0]) (s, opt0);
64  }
65  else
66  {
67  s =
68  format (s, "\n unrecognized option %d length %d", type0,
69  opt0->length);
70  }
71  opt0 =
72  (vxlan_gpe_ioam_option_t *) (((u8 *) opt0) + opt0->length +
73  sizeof (vxlan_gpe_ioam_option_t));
74  break;
75  }
76  }
77 
78  s = format (s, "VXLAN-GPE-IOAM: tunnel %d", t1->tunnel_index);
79  return s;
80 }
81 
82 
83 always_inline void
86  vlib_buffer_t * b0,
87  u32 * next0, u32 drop_node_val,
88  u8 use_adj)
89 {
90  ip4_header_t *ip0;
91  udp_header_t *udp_hdr0;
92  vxlan_gpe_header_t *gpe_hdr0;
93  vxlan_gpe_ioam_hdr_t *gpe_ioam0;
97 
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);
105 
106  /*
107  * Basic validity checks
108  */
109  if (gpe_ioam0->length > clib_net_to_host_u16 (ip0->length))
110  {
111  *next0 = drop_node_val;
112  return;
113  }
114 
115  /* Scan the set of h-b-h options, process ones that we understand */
116  while (opt0 < limit0)
117  {
118  u8 type0;
119  type0 = opt0->type;
120  switch (type0)
121  {
122  case 0: /* Pad1 */
123  opt0 = (vxlan_gpe_ioam_option_t *) ((u8 *) opt0) + 1;
124  continue;
125  case 1: /* PadN */
126  break;
127  default:
128  if (hm->options[type0])
129  {
130  if ((*hm->options[type0]) (b0, opt0, 1 /* is_ipv4 */ ,
131  use_adj) < 0)
132  {
133  *next0 = drop_node_val;
134  return;
135  }
136  }
137  break;
138  }
139  opt0 =
140  (vxlan_gpe_ioam_option_t *) (((u8 *) opt0) + opt0->length +
141  sizeof (vxlan_gpe_ioam_hdr_t));
142  }
143 
144 
145  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
146  {
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 */
152  trace_len =
153  trace_len <
154  ARRAY_LEN (t->fmt_trace.
155  option_data) ? trace_len : ARRAY_LEN (t->fmt_trace.
156  option_data);
157  t->fmt_trace.trace_len = trace_len;
158  clib_memcpy (&(t->fmt_trace.option_data), gpe_ioam0, trace_len);
159  }
160  return;
161 }
162 
163 
164 #endif
165 
166 /*
167  * fd.io coding-style-patch-verification: ON
168  *
169  * Local Variables:
170  * eval: (c-set-style "gnu")
171  * End:
172  */
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 CLIB_UNUSED(x)
Definition: clib.h:86
VXLAN GPE definitions.
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unsigned char u8
Definition: types.h:56
#define clib_memcpy(d, s, n)
Definition: string.h:180
vxlan_gpe_ioam_main_t vxlan_gpe_ioam_main
unsigned int u32
Definition: types.h:88
u8 option_data[256]
VXLAN GPE packet header structure.
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
#define PREDICT_FALSE(x)
Definition: clib.h:118
#define always_inline
Definition: ipsec.h:28
vlib_main_t * vm
Definition: in2out_ed.c:1599
static u8 * format_vxlan_gpe_ioam_v4_trace(u8 *s, va_list *args)
static void vxlan_gpe_encap_decap_ioam_v4_one_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_buffer_t *b0, u32 *next0, u32 drop_node_val, u8 use_adj)
#define ARRAY_LEN(x)
Definition: clib.h:66
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1599
int(* options[256])(vlib_buffer_t *b, vxlan_gpe_ioam_option_t *opt, u8 is_ipv4, u8 use_adj)
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
VLIB buffer representation.
Definition: buffer.h:102
VXLAN GPE Extension (iOAM) Header definition.
VXLAN GPE Header definition.
u8 *(* trace[256])(u8 *s, vxlan_gpe_ioam_option_t *opt)