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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <vppinfra/error.h>
16 #include <vppinfra/hash.h>
17 #include <vnet/vnet.h>
18 #include <vnet/ip/ip.h>
19 #include <vnet/ip/udp.h>
20 #include <vnet/ethernet/ethernet.h>
21 #include <vnet/vxlan-gpe/vxlan_gpe.h>
22 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_packet.h>
23 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
24 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_util.h>
25 #include <vnet/fib/ip6_fib.h>
26 #include <vnet/fib/ip4_fib.h>
27 #include <vnet/fib/fib_entry.h>
29 /* Statistics (not really errors) */
30 #define foreach_vxlan_gpe_transit_ioam_error \
31 _(ENCAPSULATED, "good packets encapsulated")
33 static char *vxlan_gpe_transit_ioam_error_strings[] = {
34 #define _(sym,string) string,
35 foreach_vxlan_gpe_transit_ioam_error
41 #define _(sym,str) VXLAN_GPE_TRANSIT_IOAM_ERROR_##sym,
42 foreach_vxlan_gpe_transit_ioam_error
44 VXLAN_GPE_TRANSIT_IOAM_N_ERROR,
45 } vxlan_gpe_transit_ioam_error_t;
49 VXLAN_GPE_TRANSIT_IOAM_NEXT_OUTPUT,
50 VXLAN_GPE_TRANSIT_IOAM_NEXT_DROP,
51 VXLAN_GPE_TRANSIT_IOAM_N_NEXT
52 } vxlan_gpe_transit_ioam_next_t;
56 VNET_FEATURE_INIT (vxlan_gpe_transit_ioam, static) =
58 .arc_name = "ip4-output",
59 .node_name = "vxlan-gpe-transit-ioam",
60 .runs_before = VNET_FEATURES ("interface-output"),
65 vxlan_gpe_transit_ioam (vlib_main_t * vm,
66 vlib_node_runtime_t * node, vlib_frame_t * from_frame)
68 u32 n_left_from, next_index, *from, *to_next;
70 from = vlib_frame_vector_args (from_frame);
71 n_left_from = from_frame->n_vectors;
73 next_index = node->cached_next_index;
75 while (n_left_from > 0)
79 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
82 while (n_left_from > 0 && n_left_to_next > 0)
86 u32 next0 = VXLAN_GPE_TRANSIT_IOAM_NEXT_OUTPUT;
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)
102 /* just forward non ipv4 packets */
104 ((ip0->ip_version_and_header_length & 0xF0) == 0x40))
107 udp_header_t *udp_hdr0 = (udp_header_t *) (ip0 + 1);
109 ((ip0->protocol == IP_PROTOCOL_UDP) &&
110 (clib_net_to_host_u16 (udp_hdr0->dst_port) ==
111 UDP_DST_PORT_vxlan_gpe)))
114 /* Check the iOAM header */
115 vxlan_gpe_header_t *gpe_hdr0 =
116 (vxlan_gpe_header_t *) (udp_hdr0 + 1);
119 (gpe_hdr0->protocol == VXLAN_GPE_PROTOCOL_IOAM))
122 vxlan_gpe_ioam_main_t *hm = &vxlan_gpe_ioam_main;
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);
132 vlib_buffer_advance (b0,
134 (ethernet_header_t)));
135 vxlan_gpe_encap_decap_ioam_v4_one_inline (vm, node,
138 VXLAN_GPE_TRANSIT_IOAM_NEXT_DROP,
142 vlib_buffer_advance (b0,
144 (ethernet_header_t)));
150 vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
151 n_left_to_next, bi0, next0);
154 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
157 return from_frame->n_vectors;
161 VLIB_REGISTER_NODE (vxlan_gpe_transit_ioam_node) = {
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,
168 .n_errors = ARRAY_LEN(vxlan_gpe_transit_ioam_error_strings),
169 .error_strings = vxlan_gpe_transit_ioam_error_strings,
171 .n_next_nodes = VXLAN_GPE_TRANSIT_IOAM_N_NEXT,
174 [VXLAN_GPE_TRANSIT_IOAM_NEXT_OUTPUT] = "interface-output",
175 [VXLAN_GPE_TRANSIT_IOAM_NEXT_DROP] = "error-drop",
183 * fd.io coding-style-patch-verification: ON
186 * eval: (c-set-style "gnu")