FD.io VPP  v19.08-27-gf4dcae4
Vector Packet Processing
nsh_md2_ioam_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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_nsh_md2_ioam_util_h__
16 #define __included_nsh_md2_ioam_util_h__
17 
18 #include <vnet/lisp-gpe/lisp_gpe.h>
20 #include <vnet/ip/ip.h>
21 #include <nsh/nsh.h>
23 #include <nsh/nsh_packet.h>
24 
25 
27 
28 
29 typedef struct
30 {
31  u8 trace_data[256];
33 
34 always_inline void
36  vlib_node_runtime_t * node,
37  vlib_buffer_t * b0,
38  u32 * next0, u32 drop_node_val,
39  u8 use_adj)
40 {
41  ip4_header_t *ip0;
42  udp_header_t *udp_hdr0;
43  lisp_gpe_header_t *lisp_gpe_hdr0;
44  nsh_base_header_t *nsh_hdr;
45  nsh_tlv_header_t *opt0;
46  nsh_tlv_header_t *limit0;
47  nsh_main_t *hm = &nsh_main;
48  nsh_option_map_t *nsh_option;
49 
50  /* Populate the iOAM header */
51  ip0 = vlib_buffer_get_current (b0);
52  udp_hdr0 = (udp_header_t *) (ip0 + 1);
53  lisp_gpe_hdr0 = (lisp_gpe_header_t *) (udp_hdr0 + 1);
54  nsh_hdr = (nsh_base_header_t *) (lisp_gpe_hdr0 + 1);
55  opt0 = (nsh_tlv_header_t *) (nsh_hdr + 1);
56  limit0 =
57  (nsh_tlv_header_t *) ((u8 *) opt0 + (nsh_hdr->length * 4) -
58  sizeof (nsh_base_header_t));
59 
60  /*
61  * Basic validity checks
62  */
63  if ((nsh_hdr->length * 4) > clib_net_to_host_u16 (ip0->length))
64  {
65  *next0 = drop_node_val;
66  return;
67  }
68 
69  if (nsh_hdr->md_type != 2)
70  {
71  *next0 = drop_node_val;
72  return;
73  }
74 
75  /* Scan the set of h-b-h options, process ones that we understand */
76  while (opt0 < limit0)
77  {
78  u8 type0;
79  type0 = opt0->type;
80  switch (type0)
81  {
82  case 0: /* Pad1 */
83  opt0 = (nsh_tlv_header_t *) ((u8 *) opt0) + 1;
84  continue;
85  case 1: /* PadN */
86  break;
87  default:
88  nsh_option = nsh_md2_lookup_option (opt0->class, opt0->type);
89  if ((nsh_option != NULL) && (hm->options[nsh_option->option_id]))
90  {
91  if ((*hm->options[nsh_option->option_id]) (b0, opt0) < 0)
92  {
93  *next0 = drop_node_val;
94  return;
95  }
96  }
97  break;
98  }
99  opt0 =
100  (nsh_tlv_header_t *) (((u8 *) opt0) + opt0->length +
101  sizeof (nsh_tlv_header_t));
102  }
103 
104 
105  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
106  {
107  nsh_transit_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr));
108  clib_memcpy_fast (&(tr->trace_data), nsh_hdr, (nsh_hdr->length * 4));
109  }
110  return;
111 }
112 
113 
114 #endif
115 
116 /*
117  * fd.io coding-style-patch-verification: ON
118  *
119  * Local Variables:
120  * eval: (c-set-style "gnu")
121  * End:
122  */
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_memcpy_fast(a, b, c)
Definition: string.h:81
#define NULL
Definition: clib.h:58
unsigned char u8
Definition: types.h:56
#define always_inline
Definition: clib.h:98
unsigned int u32
Definition: types.h:88
nsh_option_map_t * nsh_md2_lookup_option(u16 class, u8 type)
Definition: nsh.c:88
vl_api_fib_path_type_t type
Definition: fib_types.api:123
unsigned short u16
Definition: types.h:57
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:111
LISP-GPE packet header structure.
vlib_main_t * vm
Definition: buffer.c:312
static void nsh_md2_ioam_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)
nsh_main_t nsh_main
Definition: nsh.c:28
LISP-GPE header.
u32 option_id
Definition: nsh.h:29
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
int(* options[MAX_MD2_OPTIONS])(vlib_buffer_t *b, nsh_tlv_header_t *opt)
Definition: nsh.h:148
VLIB buffer representation.
Definition: buffer.h:102
LISP-GPE definitions.