FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
md2_ioam_transit.c
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 #include <vppinfra/error.h>
16 #include <vppinfra/hash.h>
17 #include <vnet/vnet.h>
18 #include <vnet/ip/ip.h>
19 #include <vnet/udp/udp.h>
20 #include <vnet/ethernet/ethernet.h>
21 #include <vnet/lisp-gpe/lisp_gpe.h>
23 #include <nsh/nsh.h>
24 #include <nsh/nsh_packet.h>
27 #include <vnet/fib/ip6_fib.h>
28 #include <vnet/fib/ip4_fib.h>
29 #include <vnet/fib/fib_entry.h>
30 
31 /* Statistics (not really errors) */
32 #define foreach_nsh_md2_ioam_encap_transit_error \
33 _(ENCAPSULATED, "good packets encapsulated")
34 
36 #define _(sym,string) string,
38 #undef _
39 };
40 
41 typedef enum
42 {
43 #define _(sym,str) NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_ERROR_##sym,
45 #undef _
48 
49 typedef enum
50 {
55 
56 
57 /* *INDENT-OFF* */
59 {
60  .arc_name = "ip4-output",
61  .node_name = "nsh-md2-ioam-encap-transit",
62 };
63 /* *INDENT-ON* */
64 
65 
66 static uword
69  vlib_frame_t * from_frame)
70 {
71  u32 n_left_from, next_index, *from, *to_next;
72 
73  from = vlib_frame_vector_args (from_frame);
74  n_left_from = from_frame->n_vectors;
75 
76  next_index = node->cached_next_index;
77 
78  while (n_left_from > 0)
79  {
80  u32 n_left_to_next;
81 
82  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
83 
84 
85  while (n_left_from > 0 && n_left_to_next > 0)
86  {
87  u32 bi0;
88  vlib_buffer_t *b0;
90 
91  bi0 = from[0];
92  to_next[0] = bi0;
93  from += 1;
94  to_next += 1;
95  n_left_from -= 1;
96  n_left_to_next -= 1;
97  ip4_header_t *ip0;
98  u32 iph_offset = 0;
99 
100  b0 = vlib_get_buffer (vm, bi0);
101  iph_offset = vnet_buffer (b0)->ip.save_rewrite_length;
102  ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0)
103  + iph_offset);
104 
105  /* just forward non ipv4 packets */
106  if (PREDICT_FALSE
107  ((ip0->ip_version_and_header_length & 0xF0) == 0x40))
108  {
109  /* ipv4 packets */
110  udp_header_t *udp_hdr0 = (udp_header_t *) (ip0 + 1);
111  if (PREDICT_FALSE
112  ((ip0->protocol == IP_PROTOCOL_UDP) &&
113  (clib_net_to_host_u16 (udp_hdr0->dst_port) ==
114  UDP_DST_PORT_lisp_gpe)))
115  {
116 
117  /* Check the iOAM header */
118  lisp_gpe_header_t *lisp_gpe_hdr0 =
119  (lisp_gpe_header_t *) (udp_hdr0 + 1);
120  nsh_base_header_t *nsh_hdr =
121  (nsh_base_header_t *) (lisp_gpe_hdr0 + 1);
122 
123  if (PREDICT_FALSE
124  (lisp_gpe_hdr0->next_protocol ==
125  LISP_GPE_NEXT_PROTO_NSH) && (nsh_hdr->md_type == 2))
126  {
127  uword *t = NULL;
129  fib_prefix_t key4;
130  clib_memset (&key4, 0, sizeof (key4));
131  key4.fp_proto = FIB_PROTOCOL_IP4;
132  key4.fp_addr.ip4.as_u32 = ip0->dst_address.as_u32;
133  t = hash_get_mem (hm->dst_by_ip4, &key4);
134  if (t)
135  {
137  (word) (sizeof
138  (ethernet_header_t)));
140  node,
141  b0,
142  &next0,
144  1
145  /* use_adj */
146  );
148  -(word) (sizeof
149  (ethernet_header_t)));
150  }
151  }
152  }
153  }
154 
155  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
156  n_left_to_next, bi0, next0);
157  }
158 
159  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
160  }
161 
162  return from_frame->n_vectors;
163 }
164 
165 extern u8 *format_nsh_node_map_trace (u8 * s, va_list * args);
166 /* *INDENT-OFF* */
168  .function = nsh_md2_ioam_encap_transit,
169  .name = "nsh-md2-ioam-encap-transit",
170  .vector_size = sizeof (u32),
171  .format_trace = format_nsh_node_map_trace,
173 
176 
178 
179  .next_nodes = {
180  [NSH_MD2_IOAM_ENCAP_TRANSIT_IOAM_NEXT_OUTPUT] = "interface-output",
182  },
183 
184 };
185 /* *INDENT-ON* */
186 
187 
188 /*
189  * fd.io coding-style-patch-verification: ON
190  *
191  * Local Variables:
192  * eval: (c-set-style "gnu")
193  * End:
194  */
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
u8 * format_nsh_node_map_trace(u8 *s, va_list *args)
Definition: nsh_cli.c:597
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_node_registration_t nsh_md2_ioam_encap_transit_node
(constructor) VLIB_REGISTER_NODE (nsh_md2_ioam_encap_transit_node)
VNET_FEATURE_INIT(nsh_md2_ioam_encap_transit, static)
vlib_main_t * vm
Definition: in2out_ed.c:1582
unsigned char u8
Definition: types.h:56
i64 word
Definition: types.h:111
ip4_address_t dst_address
Definition: ip4_packet.h:125
nsh_md2_ioam_encap_transit_next_t
Aggregate type for a prefix.
Definition: fib_types.h:203
static uword nsh_md2_ioam_encap_transit(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
unsigned int u32
Definition: types.h:88
vl_api_fib_path_type_t type
Definition: fib_types.api:123
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
nsh_md2_ioam_main_t nsh_md2_ioam_main
Definition: nsh_md2_ioam.c:42
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:120
#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
#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:391
LISP-GPE packet header structure.
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
u16 n_vectors
Definition: node.h:396
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)
#define ARRAY_LEN(x)
Definition: clib.h:67
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:483
LISP-GPE header.
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1582
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:510
nsh_md2_ioam_encap_transit_error_t
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:297
#define hash_get_mem(h, key)
Definition: hash.h:269
#define vnet_buffer(b)
Definition: buffer.h:417
static char * nsh_md2_ioam_encap_transit_error_strings[]
u8 ip_version_and_header_length
Definition: ip4_packet.h:93
#define foreach_nsh_md2_ioam_encap_transit_error
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
LISP-GPE definitions.