FD.io VPP  v17.04.2-2-ga8f93f8
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.h>
20 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/fib/ip6_fib.h>
26 #include <vnet/fib/ip4_fib.h>
27 #include <vnet/fib/fib_entry.h>
28 
29 /* Statistics (not really errors) */
30 #define foreach_vxlan_gpe_transit_ioam_error \
31 _(ENCAPSULATED, "good packets encapsulated")
32 
34 #define _(sym,string) string,
36 #undef _
37 };
38 
39 typedef enum
40 {
41 #define _(sym,str) VXLAN_GPE_TRANSIT_IOAM_ERROR_##sym,
43 #undef _
46 
47 typedef enum
48 {
53 
54 
55 /* *INDENT-OFF* */
57 {
58  .arc_name = "ip4-output",
59  .node_name = "vxlan-gpe-transit-ioam",
60  .runs_before = VNET_FEATURES ("interface-output"),
61 };
62 /* *INDENT-ON* */
63 
64 static uword
66  vlib_node_runtime_t * node, vlib_frame_t * from_frame)
67 {
68  u32 n_left_from, next_index, *from, *to_next;
69 
70  from = vlib_frame_vector_args (from_frame);
71  n_left_from = from_frame->n_vectors;
72 
73  next_index = node->cached_next_index;
74 
75  while (n_left_from > 0)
76  {
77  u32 n_left_to_next;
78 
79  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
80 
81 
82  while (n_left_from > 0 && n_left_to_next > 0)
83  {
84  u32 bi0;
85  vlib_buffer_t *b0;
87 
88  bi0 = from[0];
89  to_next[0] = bi0;
90  from += 1;
91  to_next += 1;
92  n_left_from -= 1;
93  n_left_to_next -= 1;
94  ip4_header_t *ip0;
95  u32 iph_offset = 0;
96 
97  b0 = vlib_get_buffer (vm, bi0);
98  iph_offset = vnet_buffer (b0)->ip.save_rewrite_length;
99  ip0 = (ip4_header_t *) ((u8 *) vlib_buffer_get_current (b0)
100  + iph_offset);
101 
102  /* just forward non ipv4 packets */
103  if (PREDICT_FALSE
104  ((ip0->ip_version_and_header_length & 0xF0) == 0x40))
105  {
106  /* ipv4 packets */
107  udp_header_t *udp_hdr0 = (udp_header_t *) (ip0 + 1);
108  if (PREDICT_FALSE
109  ((ip0->protocol == IP_PROTOCOL_UDP) &&
110  (clib_net_to_host_u16 (udp_hdr0->dst_port) ==
111  UDP_DST_PORT_vxlan_gpe)))
112  {
113 
114  /* Check the iOAM header */
115  vxlan_gpe_header_t *gpe_hdr0 =
116  (vxlan_gpe_header_t *) (udp_hdr0 + 1);
117 
118  if (PREDICT_FALSE
119  (gpe_hdr0->protocol == VXLAN_GPE_PROTOCOL_IOAM))
120  {
121  uword *t = NULL;
123  fib_prefix_t key4;
124  memset (&key4, 0, sizeof (key4));
125  key4.fp_proto = FIB_PROTOCOL_IP4;
126  key4.fp_addr.ip4.as_u32 = ip0->dst_address.as_u32;
127  t = hash_get_mem (hm->dst_by_ip4, &key4);
128  if (t)
129  {
130 
131 
133  (word) (sizeof
134  (ethernet_header_t)));
136  b0,
137  &next0,
139  1
140  /* use_adj */
141  );
143  -(word) (sizeof
144  (ethernet_header_t)));
145  }
146  }
147  }
148  }
149 
150  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
151  n_left_to_next, bi0, next0);
152  }
153 
154  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
155  }
156 
157  return from_frame->n_vectors;
158 }
159 
160 /* *INDENT-OFF* */
162  .function = vxlan_gpe_transit_ioam,
163  .name = "vxlan-gpe-transit-ioam",
164  .vector_size = sizeof (u32),
165  .format_trace = format_vxlan_gpe_ioam_v4_trace,
166  .type = VLIB_NODE_TYPE_INTERNAL,
167 
169  .error_strings = vxlan_gpe_transit_ioam_error_strings,
170 
171  .n_next_nodes = VXLAN_GPE_TRANSIT_IOAM_N_NEXT,
172 
173  .next_nodes = {
174  [VXLAN_GPE_TRANSIT_IOAM_NEXT_OUTPUT] = "interface-output",
175  [VXLAN_GPE_TRANSIT_IOAM_NEXT_DROP] = "error-drop",
176  },
177 
178 };
179 /* *INDENT-ON* */
180 
181 
182 /*
183  * fd.io coding-style-patch-verification: ON
184  *
185  * Local Variables:
186  * eval: (c-set-style "gnu")
187  * End:
188  */
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:169
vxlan_gpe_transit_ioam_next_t
Definition: ioam_transit.c:47
#define NULL
Definition: clib.h:55
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:459
VXLAN GPE definitions.
ip4_address_t dst_address
Definition: ip4_packet.h:163
vxlan_gpe_ioam_main_t vxlan_gpe_ioam_main
Aggregrate type for a prefix.
Definition: fib_types.h:160
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:183
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:188
#define PREDICT_FALSE(x)
Definition: clib.h:97
static char * vxlan_gpe_transit_ioam_error_strings[]
Definition: ioam_transit.c:33
#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:216
#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:350
vlib_node_registration_t vxlan_gpe_transit_ioam_node
(constructor) VLIB_REGISTER_NODE (vxlan_gpe_transit_ioam_node)
Definition: ioam_transit.c:161
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)
u16 n_vectors
Definition: node.h:344
vlib_main_t * vm
Definition: buffer.c:276
vxlan_gpe_transit_ioam_error_t
Definition: ioam_transit.c:39
#define foreach_vxlan_gpe_transit_ioam_error
Definition: ioam_transit.c:30
#define ARRAY_LEN(x)
Definition: clib.h:59
u8 protocol
see vxlan_gpe_protocol_t
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:455
unsigned int u32
Definition: types.h:88
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:201
#define VNET_FEATURES(...)
Definition: feature.h:368
u64 uword
Definition: types.h:112
i64 word
Definition: types.h:111
static uword vxlan_gpe_transit_ioam(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
Definition: ioam_transit.c:65
unsigned char u8
Definition: types.h:56
VXLAN GPE Header definition.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:253
VNET_FEATURE_INIT(vxlan_gpe_transit_ioam, static)
#define hash_get_mem(h, key)
Definition: hash.h:268
#define vnet_buffer(b)
Definition: buffer.h:294
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
u8 ip_version_and_header_length
Definition: ip4_packet.h:131
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57