FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
ioam_transit.c
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 #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_local.h>
20 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/fib/ip4_fib.h>
26 #include <vnet/fib/fib_entry.h>
27 
28 /* Statistics (not really errors) */
29 #define foreach_vxlan_gpe_transit_ioam_error \
30 _(ENCAPSULATED, "good packets encapsulated")
31 
33 #define _(sym,string) string,
35 #undef _
36 };
37 
38 typedef enum
39 {
40 #define _(sym,str) VXLAN_GPE_TRANSIT_IOAM_ERROR_##sym,
42 #undef _
45 
46 typedef enum
47 {
52 
53 
54 /* *INDENT-OFF* */
56 {
57  .arc_name = "ip4-output",
58  .node_name = "vxlan-gpe-transit-ioam",
59  .runs_before = VNET_FEATURES ("interface-output"),
60 };
61 /* *INDENT-ON* */
62 
63 static uword
66 {
67  u32 n_left_from, next_index, *from, *to_next;
68 
70  n_left_from = from_frame->n_vectors;
71 
72  next_index = node->cached_next_index;
73 
74  while (n_left_from > 0)
75  {
76  u32 n_left_to_next;
77 
78  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
79 
80 
81  while (n_left_from > 0 && n_left_to_next > 0)
82  {
83  u32 bi0;
84  vlib_buffer_t *b0;
86 
87  bi0 = from[0];
88  to_next[0] = bi0;
89  from += 1;
90  to_next += 1;
91  n_left_from -= 1;
92  n_left_to_next -= 1;
93  ip4_header_t *ip0;
94  u32 iph_offset = 0;
95 
96  b0 = vlib_get_buffer (vm, bi0);
97  iph_offset = vnet_buffer (b0)->ip.save_rewrite_length;
98  ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0)
99  + iph_offset);
100 
101  /* just forward non ipv4 packets */
102  if (PREDICT_FALSE
103  ((ip0->ip_version_and_header_length & 0xF0) == 0x40))
104  {
105  /* ipv4 packets */
106  udp_header_t *udp_hdr0 = (udp_header_t *) (ip0 + 1);
107  if (PREDICT_FALSE
108  ((ip0->protocol == IP_PROTOCOL_UDP) &&
109  (clib_net_to_host_u16 (udp_hdr0->dst_port) ==
110  UDP_DST_PORT_VXLAN_GPE)))
111  {
112 
113  /* Check the iOAM header */
114  vxlan_gpe_header_t *gpe_hdr0 =
115  (vxlan_gpe_header_t *) (udp_hdr0 + 1);
116 
117  if (PREDICT_FALSE
118  (gpe_hdr0->protocol == VXLAN_GPE_PROTOCOL_IOAM))
119  {
120  uword *t = NULL;
122  fib_prefix_t key4;
123  clib_memset (&key4, 0, sizeof (key4));
124  key4.fp_proto = FIB_PROTOCOL_IP4;
125  key4.fp_addr.ip4.as_u32 = ip0->dst_address.as_u32;
126  t = hash_get_mem (hm->dst_by_ip4, &key4);
127  if (t)
128  {
129 
130 
132  (word) (sizeof
133  (ethernet_header_t)));
135  b0,
136  &next0,
138  1
139  /* use_adj */
140  );
142  -(word) (sizeof
143  (ethernet_header_t)));
144  }
145  }
146  }
147  }
148 
150  n_left_to_next, bi0, next0);
151  }
152 
153  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
154  }
155 
156  return from_frame->n_vectors;
157 }
158 
159 /* *INDENT-OFF* */
161  .function = vxlan_gpe_transit_ioam,
162  .name = "vxlan-gpe-transit-ioam",
163  .vector_size = sizeof (u32),
164  .format_trace = format_vxlan_gpe_ioam_v4_trace,
166 
168  .error_strings = vxlan_gpe_transit_ioam_error_strings,
169 
170  .n_next_nodes = VXLAN_GPE_TRANSIT_IOAM_N_NEXT,
171 
172  .next_nodes = {
173  [VXLAN_GPE_TRANSIT_IOAM_NEXT_OUTPUT] = "interface-output",
174  [VXLAN_GPE_TRANSIT_IOAM_NEXT_DROP] = "error-drop",
175  },
176 
177 };
178 /* *INDENT-ON* */
179 
180 
181 /*
182  * fd.io coding-style-patch-verification: ON
183  *
184  * Local Variables:
185  * eval: (c-set-style "gnu")
186  * End:
187  */
fib_entry.h
vxlan_gpe_encap_decap_ioam_v4_one_inline
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)
Definition: vxlan_gpe_ioam_util.h:84
vxlan_gpe_transit_ioam_next_t
vxlan_gpe_transit_ioam_next_t
Definition: ioam_transit.c:46
next_index
nat44_ei_hairpin_src_next_t next_index
Definition: nat44_ei_hairpinning.c:412
vlib_get_buffer
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:111
VLIB_NODE_TYPE_INTERNAL
@ VLIB_NODE_TYPE_INTERNAL
Definition: node.h:72
vxlan_gpe_ioam_packet.h
vxlan_gpe_ioam_main
vxlan_gpe_ioam_main_t vxlan_gpe_ioam_main
Definition: vxlan_gpe_ioam.c:23
node
vlib_main_t vlib_node_runtime_t * node
Definition: nat44_ei.c:3047
ip4_address_t::as_u32
u32 as_u32
Definition: ip4_packet.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
from_frame
vlib_main_t vlib_node_runtime_t vlib_frame_t * from_frame
Definition: esp_encrypt.c:1328
vlib_frame_t
Definition: node.h:372
vxlan_gpe_ioam.h
udp_header_t
Definition: udp_packet.h:45
ip4_header_t
Definition: ip4_packet.h:87
ethernet.h
VXLAN_GPE_TRANSIT_IOAM_N_NEXT
@ VXLAN_GPE_TRANSIT_IOAM_N_NEXT
Definition: ioam_transit.c:50
vxlan_gpe.h
VXLAN GPE definitions.
vxlan_gpe_header_t::protocol
u8 protocol
see vxlan_gpe_protocol_t
Definition: vxlan_gpe_packet.h:102
vlib_buffer_advance
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:276
error.h
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
ARRAY_LEN
#define ARRAY_LEN(x)
Definition: clib.h:70
vlib_frame_vector_args
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:301
udp_local.h
foreach_vxlan_gpe_transit_ioam_error
#define foreach_vxlan_gpe_transit_ioam_error
Definition: ioam_transit.c:29
uword
u64 uword
Definition: types.h:112
ethernet_header_t
Definition: packet.h:52
vxlan_gpe_ioam_util.h
FIB_PROTOCOL_IP4
@ FIB_PROTOCOL_IP4
Definition: fib_types.h:36
VXLAN_GPE_TRANSIT_IOAM_NEXT_OUTPUT
@ VXLAN_GPE_TRANSIT_IOAM_NEXT_OUTPUT
Definition: ioam_transit.c:48
vlib_node_registration_t
struct _vlib_node_registration vlib_node_registration_t
ip4_header_t::dst_address
ip4_address_t dst_address
Definition: ip4_packet.h:125
fib_prefix_t_::fp_addr
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:225
vlib_validate_buffer_enqueue_x1
#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
vxlan_gpe_transit_ioam_node
vlib_node_registration_t vxlan_gpe_transit_ioam_node
(constructor) VLIB_REGISTER_NODE (vxlan_gpe_transit_ioam_node)
Definition: ioam_transit.c:160
vxlan_gpe_transit_ioam_error_t
vxlan_gpe_transit_ioam_error_t
Definition: ioam_transit.c:38
hash_get_mem
#define hash_get_mem(h, key)
Definition: hash.h:269
vxlan_gpe_transit_ioam
static uword vxlan_gpe_transit_ioam(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: ioam_transit.c:64
vxlan_gpe_transit_ioam_error_strings
static char * vxlan_gpe_transit_ioam_error_strings[]
Definition: ioam_transit.c:32
vlib_put_next_frame
vlib_put_next_frame(vm, node, next_index, 0)
vxlan_gpe_ioam_main_
Definition: vxlan_gpe_ioam.h:38
ip.h
u32
unsigned int u32
Definition: types.h:88
udp_header_t::dst_port
u16 dst_port
Definition: udp_packet.h:48
VNET_FEATURE_INIT
VNET_FEATURE_INIT(vxlan_gpe_transit_ioam, static)
vxlan_gpe_ioam_main_::dst_by_ip4
uword * dst_by_ip4
Definition: vxlan_gpe_ioam.h:92
fib_prefix_t_::fp_proto
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:211
ip4_fib.h
clib_memset
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
vlib_main_t
Definition: main.h:102
ip4_header_t::ip_version_and_header_length
u8 ip_version_and_header_length
Definition: ip4_packet.h:93
hash.h
VNET_FEATURES
#define VNET_FEATURES(...)
Definition: feature.h:470
u8
unsigned char u8
Definition: types.h:56
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
word
i64 word
Definition: types.h:111
format_vxlan_gpe_ioam_v4_trace
static u8 * format_vxlan_gpe_ioam_v4_trace(u8 *s, va_list *args)
Definition: vxlan_gpe_ioam_util.h:31
vnet.h
vxlan_gpe_header_t
VXLAN GPE Header definition.
Definition: vxlan_gpe_packet.h:94
vlib_node_runtime_t
Definition: node.h:454
VXLAN_GPE_TRANSIT_IOAM_N_ERROR
@ VXLAN_GPE_TRANSIT_IOAM_N_ERROR
Definition: ioam_transit.c:43
from
from
Definition: nat44_ei_hairpinning.c:415
vlib_get_next_frame
#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:395
n_left_from
n_left_from
Definition: nat44_ei_hairpinning.c:416
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
type
vl_api_fib_path_type_t type
Definition: fib_types.api:123
ip4_header_t::protocol
u8 protocol
Definition: ip4_packet.h:115
VXLAN_GPE_TRANSIT_IOAM_NEXT_DROP
@ VXLAN_GPE_TRANSIT_IOAM_NEXT_DROP
Definition: ioam_transit.c:49
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
VLIB_REGISTER_NODE
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169