Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * decap.c - decapsulate VXLAN GPE |
| 3 | * |
| 4 | * Copyright (c) 2013 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 17 | /** |
| 18 | * @file |
| 19 | * @brief Functions for decapsulating VXLAN GPE tunnels |
| 20 | * |
| 21 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 22 | |
| 23 | #include <vlib/vlib.h> |
Florin Coras | b040f98 | 2020-10-20 14:59:43 -0700 | [diff] [blame] | 24 | #include <vnet/udp/udp_local.h> |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 25 | #include <vnet/vxlan-gpe/vxlan_gpe.h> |
| 26 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 27 | /** |
| 28 | * @brief Struct for VXLAN GPE decap packet tracing |
| 29 | * |
| 30 | */ |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 31 | typedef struct |
| 32 | { |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 33 | u32 next_index; |
| 34 | u32 tunnel_index; |
| 35 | u32 error; |
| 36 | } vxlan_gpe_rx_trace_t; |
| 37 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 38 | /** |
| 39 | * @brief Tracing function for VXLAN GPE packet decapsulation |
| 40 | * |
| 41 | * @param *s |
| 42 | * @param *args |
| 43 | * |
| 44 | * @return *s |
| 45 | * |
| 46 | */ |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 47 | static u8 * |
| 48 | format_vxlan_gpe_rx_trace (u8 * s, va_list * args) |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 49 | { |
| 50 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 51 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 52 | vxlan_gpe_rx_trace_t *t = va_arg (*args, vxlan_gpe_rx_trace_t *); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 53 | |
| 54 | if (t->tunnel_index != ~0) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 55 | { |
| 56 | s = format (s, "VXLAN-GPE: tunnel %d next %d error %d", t->tunnel_index, |
| 57 | t->next_index, t->error); |
| 58 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 59 | else |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 60 | { |
| 61 | s = format (s, "VXLAN-GPE: no tunnel next %d error %d\n", t->next_index, |
| 62 | t->error); |
| 63 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 64 | return s; |
| 65 | } |
| 66 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 67 | /** |
| 68 | * @brief Tracing function for VXLAN GPE packet decapsulation including length |
| 69 | * |
| 70 | * @param *s |
| 71 | * @param *args |
| 72 | * |
| 73 | * @return *s |
| 74 | * |
| 75 | */ |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 76 | static u8 * |
| 77 | format_vxlan_gpe_with_length (u8 * s, va_list * args) |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 78 | { |
| 79 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 80 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 81 | |
| 82 | |
| 83 | return s; |
| 84 | } |
| 85 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 86 | /** |
| 87 | * @brief Common processing for IPv4 and IPv6 VXLAN GPE decap dispatch functions |
| 88 | * |
| 89 | * It is worth noting that other than trivial UDP forwarding (transit), VXLAN GPE |
| 90 | * tunnels are "terminate local". This means that there is no "TX" interface for this |
| 91 | * decap case, so that field in the buffer_metadata can be "used for something else". |
| 92 | * The something else in this case is, for the IPv4/IPv6 inner-packet type case, the |
| 93 | * FIB index used to look up the inner-packet's adjacency. |
| 94 | * |
| 95 | * vnet_buffer(b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index; |
| 96 | * |
| 97 | * @param *vm |
| 98 | * @param *node |
| 99 | * @param *from_frame |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 100 | * @param is_ip4 |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 101 | * |
| 102 | * @return from_frame->n_vectors |
| 103 | * |
| 104 | */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 105 | always_inline uword |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 106 | vxlan_gpe_input (vlib_main_t * vm, |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 107 | vlib_node_runtime_t * node, |
| 108 | vlib_frame_t * from_frame, u8 is_ip4) |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 109 | { |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 110 | u32 n_left_from, next_index, *from, *to_next; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 111 | vxlan_gpe_main_t *nngm = &vxlan_gpe_main; |
| 112 | vnet_main_t *vnm = nngm->vnet_main; |
| 113 | vnet_interface_main_t *im = &vnm->interface_main; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 114 | u32 last_tunnel_index = ~0; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 115 | vxlan4_gpe_tunnel_key_t last_key4; |
| 116 | vxlan6_gpe_tunnel_key_t last_key6; |
Zhiyong Yang | 73c8d1d | 2019-07-03 22:56:24 -0400 | [diff] [blame] | 117 | u32 pkts_decapsulated = 0; |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 118 | u32 thread_index = vm->thread_index; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 119 | u32 stats_sw_if_index, stats_n_packets, stats_n_bytes; |
| 120 | |
Dave Barach | f9c231e | 2016-08-05 10:10:18 -0400 | [diff] [blame] | 121 | if (is_ip4) |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 122 | clib_memset (&last_key4, 0xff, sizeof (last_key4)); |
Dave Barach | f9c231e | 2016-08-05 10:10:18 -0400 | [diff] [blame] | 123 | else |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 124 | clib_memset (&last_key6, 0xff, sizeof (last_key6)); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 125 | |
| 126 | from = vlib_frame_vector_args (from_frame); |
| 127 | n_left_from = from_frame->n_vectors; |
| 128 | |
| 129 | next_index = node->cached_next_index; |
| 130 | stats_sw_if_index = node->runtime_data[0]; |
| 131 | stats_n_packets = stats_n_bytes = 0; |
| 132 | |
| 133 | while (n_left_from > 0) |
| 134 | { |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 135 | u32 n_left_to_next; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 136 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 137 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 138 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 139 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 140 | { |
| 141 | u32 bi0, bi1; |
| 142 | vlib_buffer_t *b0, *b1; |
| 143 | u32 next0, next1; |
| 144 | ip4_vxlan_gpe_header_t *iuvn4_0, *iuvn4_1; |
| 145 | ip6_vxlan_gpe_header_t *iuvn6_0, *iuvn6_1; |
| 146 | uword *p0, *p1; |
| 147 | u32 tunnel_index0, tunnel_index1; |
| 148 | vxlan_gpe_tunnel_t *t0, *t1; |
| 149 | vxlan4_gpe_tunnel_key_t key4_0, key4_1; |
| 150 | vxlan6_gpe_tunnel_key_t key6_0, key6_1; |
| 151 | u32 error0, error1; |
| 152 | u32 sw_if_index0, sw_if_index1, len0, len1; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 153 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 154 | /* Prefetch next iteration. */ |
| 155 | { |
| 156 | vlib_buffer_t *p2, *p3; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 157 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 158 | p2 = vlib_get_buffer (vm, from[2]); |
| 159 | p3 = vlib_get_buffer (vm, from[3]); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 160 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 161 | vlib_prefetch_buffer_header (p2, LOAD); |
| 162 | vlib_prefetch_buffer_header (p3, LOAD); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 163 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 164 | CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 165 | CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 166 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 167 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 168 | bi0 = from[0]; |
| 169 | bi1 = from[1]; |
| 170 | to_next[0] = bi0; |
| 171 | to_next[1] = bi1; |
| 172 | from += 2; |
| 173 | to_next += 2; |
| 174 | n_left_to_next -= 2; |
| 175 | n_left_from -= 2; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 176 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 177 | b0 = vlib_get_buffer (vm, bi0); |
| 178 | b1 = vlib_get_buffer (vm, bi1); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 179 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 180 | if (is_ip4) |
| 181 | { |
| 182 | /* udp leaves current_data pointing at the vxlan-gpe header */ |
| 183 | vlib_buffer_advance (b0, |
| 184 | -(word) (sizeof (udp_header_t) + |
| 185 | sizeof (ip4_header_t))); |
| 186 | vlib_buffer_advance (b1, |
| 187 | -(word) (sizeof (udp_header_t) + |
| 188 | sizeof (ip4_header_t))); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 189 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 190 | iuvn4_0 = vlib_buffer_get_current (b0); |
| 191 | iuvn4_1 = vlib_buffer_get_current (b1); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 192 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 193 | /* pop (ip, udp, vxlan) */ |
| 194 | vlib_buffer_advance (b0, sizeof (*iuvn4_0)); |
| 195 | vlib_buffer_advance (b1, sizeof (*iuvn4_1)); |
| 196 | } |
| 197 | else |
| 198 | { |
| 199 | /* udp leaves current_data pointing at the vxlan-gpe header */ |
| 200 | vlib_buffer_advance (b0, |
| 201 | -(word) (sizeof (udp_header_t) + |
| 202 | sizeof (ip6_header_t))); |
| 203 | vlib_buffer_advance (b1, |
| 204 | -(word) (sizeof (udp_header_t) + |
| 205 | sizeof (ip6_header_t))); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 206 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 207 | iuvn6_0 = vlib_buffer_get_current (b0); |
| 208 | iuvn6_1 = vlib_buffer_get_current (b1); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 209 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 210 | /* pop (ip, udp, vxlan) */ |
| 211 | vlib_buffer_advance (b0, sizeof (*iuvn6_0)); |
| 212 | vlib_buffer_advance (b1, sizeof (*iuvn6_1)); |
| 213 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 214 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 215 | tunnel_index0 = ~0; |
| 216 | tunnel_index1 = ~0; |
| 217 | error0 = 0; |
| 218 | error1 = 0; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 219 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 220 | if (is_ip4) |
| 221 | { |
| 222 | next0 = |
| 223 | (iuvn4_0->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ? |
| 224 | nngm->decap_next_node_list[iuvn4_0->vxlan.protocol] : |
| 225 | VXLAN_GPE_INPUT_NEXT_DROP; |
| 226 | next1 = |
| 227 | (iuvn4_1->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ? |
| 228 | nngm->decap_next_node_list[iuvn4_1->vxlan.protocol] : |
| 229 | VXLAN_GPE_INPUT_NEXT_DROP; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 230 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 231 | key4_0.local = iuvn4_0->ip4.dst_address.as_u32; |
| 232 | key4_1.local = iuvn4_1->ip4.dst_address.as_u32; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 233 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 234 | key4_0.remote = iuvn4_0->ip4.src_address.as_u32; |
| 235 | key4_1.remote = iuvn4_1->ip4.src_address.as_u32; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 236 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 237 | key4_0.vni = iuvn4_0->vxlan.vni_res; |
| 238 | key4_1.vni = iuvn4_1->vxlan.vni_res; |
Hongjun Ni | e74c1dc | 2016-10-27 18:39:44 +0800 | [diff] [blame] | 239 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 240 | key4_0.pad = 0; |
| 241 | key4_1.pad = 0; |
| 242 | } |
| 243 | else /* is_ip6 */ |
| 244 | { |
| 245 | next0 = (iuvn6_0->vxlan.protocol < node->n_next_nodes) ? |
| 246 | iuvn6_0->vxlan.protocol : VXLAN_GPE_INPUT_NEXT_DROP; |
| 247 | next1 = (iuvn6_1->vxlan.protocol < node->n_next_nodes) ? |
| 248 | iuvn6_1->vxlan.protocol : VXLAN_GPE_INPUT_NEXT_DROP; |
Hongjun Ni | e74c1dc | 2016-10-27 18:39:44 +0800 | [diff] [blame] | 249 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 250 | key6_0.local.as_u64[0] = iuvn6_0->ip6.dst_address.as_u64[0]; |
| 251 | key6_0.local.as_u64[1] = iuvn6_0->ip6.dst_address.as_u64[1]; |
| 252 | key6_1.local.as_u64[0] = iuvn6_1->ip6.dst_address.as_u64[0]; |
| 253 | key6_1.local.as_u64[1] = iuvn6_1->ip6.dst_address.as_u64[1]; |
Hongjun Ni | e74c1dc | 2016-10-27 18:39:44 +0800 | [diff] [blame] | 254 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 255 | key6_0.remote.as_u64[0] = iuvn6_0->ip6.src_address.as_u64[0]; |
| 256 | key6_0.remote.as_u64[1] = iuvn6_0->ip6.src_address.as_u64[1]; |
| 257 | key6_1.remote.as_u64[0] = iuvn6_1->ip6.src_address.as_u64[0]; |
| 258 | key6_1.remote.as_u64[1] = iuvn6_1->ip6.src_address.as_u64[1]; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 259 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 260 | key6_0.vni = iuvn6_0->vxlan.vni_res; |
| 261 | key6_1.vni = iuvn6_1->vxlan.vni_res; |
| 262 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 263 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 264 | /* Processing packet 0 */ |
| 265 | if (is_ip4) |
| 266 | { |
| 267 | /* Processing for key4_0 */ |
| 268 | if (PREDICT_FALSE ((key4_0.as_u64[0] != last_key4.as_u64[0]) |
| 269 | || (key4_0.as_u64[1] != |
| 270 | last_key4.as_u64[1]))) |
| 271 | { |
| 272 | p0 = hash_get_mem (nngm->vxlan4_gpe_tunnel_by_key, &key4_0); |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 273 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 274 | if (p0 == 0) |
| 275 | { |
| 276 | error0 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL; |
| 277 | goto trace0; |
| 278 | } |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 279 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 280 | last_key4.as_u64[0] = key4_0.as_u64[0]; |
| 281 | last_key4.as_u64[1] = key4_0.as_u64[1]; |
| 282 | tunnel_index0 = last_tunnel_index = p0[0]; |
| 283 | } |
| 284 | else |
| 285 | tunnel_index0 = last_tunnel_index; |
| 286 | } |
| 287 | else /* is_ip6 */ |
| 288 | { |
| 289 | next0 = |
| 290 | (iuvn6_0->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ? |
| 291 | nngm->decap_next_node_list[iuvn6_0->vxlan.protocol] : |
| 292 | VXLAN_GPE_INPUT_NEXT_DROP; |
| 293 | next1 = |
| 294 | (iuvn6_1->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ? |
| 295 | nngm->decap_next_node_list[iuvn6_1->vxlan.protocol] : |
| 296 | VXLAN_GPE_INPUT_NEXT_DROP; |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 297 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 298 | key6_0.local.as_u64[0] = iuvn6_0->ip6.dst_address.as_u64[0]; |
| 299 | key6_0.local.as_u64[1] = iuvn6_0->ip6.dst_address.as_u64[1]; |
| 300 | key6_1.local.as_u64[0] = iuvn6_1->ip6.dst_address.as_u64[0]; |
| 301 | key6_1.local.as_u64[1] = iuvn6_1->ip6.dst_address.as_u64[1]; |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 302 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 303 | key6_0.remote.as_u64[0] = iuvn6_0->ip6.src_address.as_u64[0]; |
| 304 | key6_0.remote.as_u64[1] = iuvn6_0->ip6.src_address.as_u64[1]; |
| 305 | key6_1.remote.as_u64[0] = iuvn6_1->ip6.src_address.as_u64[0]; |
| 306 | key6_1.remote.as_u64[1] = iuvn6_1->ip6.src_address.as_u64[1]; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 307 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 308 | key6_0.vni = iuvn6_0->vxlan.vni_res; |
| 309 | key6_1.vni = iuvn6_1->vxlan.vni_res; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 310 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 311 | /* Processing for key6_0 */ |
| 312 | if (PREDICT_FALSE |
| 313 | (memcmp (&key6_0, &last_key6, sizeof (last_key6)) != 0)) |
| 314 | { |
| 315 | p0 = hash_get_mem (nngm->vxlan6_gpe_tunnel_by_key, &key6_0); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 316 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 317 | if (p0 == 0) |
| 318 | { |
| 319 | error0 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL; |
| 320 | goto trace0; |
| 321 | } |
| 322 | |
| 323 | memcpy (&last_key6, &key6_0, sizeof (key6_0)); |
| 324 | tunnel_index0 = last_tunnel_index = p0[0]; |
| 325 | } |
| 326 | else |
| 327 | tunnel_index0 = last_tunnel_index; |
| 328 | } |
| 329 | |
| 330 | t0 = pool_elt_at_index (nngm->tunnels, tunnel_index0); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 331 | |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 332 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 333 | sw_if_index0 = t0->sw_if_index; |
| 334 | len0 = vlib_buffer_length_in_chain (vm, b0); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 335 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 336 | /* Required to make the l2 tag push / pop code work on l2 subifs */ |
| 337 | vnet_update_l2_len (b0); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 338 | |
Gabriel Ganne | 7e665d6 | 2017-11-17 09:18:53 +0100 | [diff] [blame] | 339 | /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */ |
| 340 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index; |
| 341 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 342 | /** |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 343 | * ip[46] lookup in the configured FIB |
| 344 | */ |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 345 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 346 | |
Zhiyong Yang | 73c8d1d | 2019-07-03 22:56:24 -0400 | [diff] [blame] | 347 | pkts_decapsulated++; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 348 | stats_n_packets += 1; |
| 349 | stats_n_bytes += len0; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 350 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 351 | if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index)) |
| 352 | { |
| 353 | stats_n_packets -= 1; |
| 354 | stats_n_bytes -= len0; |
| 355 | if (stats_n_packets) |
| 356 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 357 | VNET_INTERFACE_COUNTER_RX, |
| 358 | thread_index, |
| 359 | stats_sw_if_index, |
| 360 | stats_n_packets, |
| 361 | stats_n_bytes); |
| 362 | stats_n_packets = 1; |
| 363 | stats_n_bytes = len0; |
| 364 | stats_sw_if_index = sw_if_index0; |
| 365 | } |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 366 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 367 | trace0:b0->error = error0 ? node->errors[error0] : 0; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 368 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 369 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 370 | { |
| 371 | vxlan_gpe_rx_trace_t *tr = |
| 372 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 373 | tr->next_index = next0; |
| 374 | tr->error = error0; |
| 375 | tr->tunnel_index = tunnel_index0; |
| 376 | } |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 377 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 378 | /* Process packet 1 */ |
| 379 | if (is_ip4) |
| 380 | { |
| 381 | /* Processing for key4_1 */ |
| 382 | if (PREDICT_FALSE ((key4_1.as_u64[0] != last_key4.as_u64[0]) |
| 383 | || (key4_1.as_u64[1] != |
| 384 | last_key4.as_u64[1]))) |
| 385 | { |
| 386 | p1 = hash_get_mem (nngm->vxlan4_gpe_tunnel_by_key, &key4_1); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 387 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 388 | if (p1 == 0) |
| 389 | { |
| 390 | error1 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL; |
| 391 | goto trace1; |
| 392 | } |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 393 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 394 | last_key4.as_u64[0] = key4_1.as_u64[0]; |
| 395 | last_key4.as_u64[1] = key4_1.as_u64[1]; |
| 396 | tunnel_index1 = last_tunnel_index = p1[0]; |
| 397 | } |
| 398 | else |
| 399 | tunnel_index1 = last_tunnel_index; |
| 400 | } |
| 401 | else /* is_ip6 */ |
| 402 | { |
| 403 | /* Processing for key6_1 */ |
| 404 | if (PREDICT_FALSE |
| 405 | (memcmp (&key6_1, &last_key6, sizeof (last_key6)) != 0)) |
| 406 | { |
| 407 | p1 = hash_get_mem (nngm->vxlan6_gpe_tunnel_by_key, &key6_1); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 408 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 409 | if (p1 == 0) |
| 410 | { |
| 411 | error1 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL; |
| 412 | goto trace1; |
| 413 | } |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 414 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 415 | memcpy (&last_key6, &key6_1, sizeof (key6_1)); |
| 416 | tunnel_index1 = last_tunnel_index = p1[0]; |
| 417 | } |
| 418 | else |
| 419 | tunnel_index1 = last_tunnel_index; |
| 420 | } |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 421 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 422 | t1 = pool_elt_at_index (nngm->tunnels, tunnel_index1); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 423 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 424 | sw_if_index1 = t1->sw_if_index; |
| 425 | len1 = vlib_buffer_length_in_chain (vm, b1); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 426 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 427 | /* Required to make the l2 tag push / pop code work on l2 subifs */ |
| 428 | vnet_update_l2_len (b1); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 429 | |
Gabriel Ganne | 7e665d6 | 2017-11-17 09:18:53 +0100 | [diff] [blame] | 430 | /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */ |
| 431 | vnet_buffer (b1)->sw_if_index[VLIB_RX] = t1->sw_if_index; |
| 432 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 433 | /* |
| 434 | * ip[46] lookup in the configured FIB |
| 435 | */ |
| 436 | vnet_buffer (b1)->sw_if_index[VLIB_TX] = t1->decap_fib_index; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 437 | |
Zhiyong Yang | 73c8d1d | 2019-07-03 22:56:24 -0400 | [diff] [blame] | 438 | pkts_decapsulated++; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 439 | stats_n_packets += 1; |
| 440 | stats_n_bytes += len1; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 441 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 442 | /* Batch stats increment on the same vxlan tunnel so counter |
| 443 | is not incremented per packet */ |
| 444 | if (PREDICT_FALSE (sw_if_index1 != stats_sw_if_index)) |
| 445 | { |
| 446 | stats_n_packets -= 1; |
| 447 | stats_n_bytes -= len1; |
| 448 | if (stats_n_packets) |
| 449 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 450 | VNET_INTERFACE_COUNTER_RX, |
| 451 | thread_index, |
| 452 | stats_sw_if_index, |
| 453 | stats_n_packets, |
| 454 | stats_n_bytes); |
| 455 | stats_n_packets = 1; |
| 456 | stats_n_bytes = len1; |
| 457 | stats_sw_if_index = sw_if_index1; |
| 458 | } |
| 459 | vnet_buffer (b1)->sw_if_index[VLIB_TX] = t1->decap_fib_index; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 460 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 461 | trace1:b1->error = error1 ? node->errors[error1] : 0; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 462 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 463 | if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) |
| 464 | { |
| 465 | vxlan_gpe_rx_trace_t *tr = |
| 466 | vlib_add_trace (vm, node, b1, sizeof (*tr)); |
| 467 | tr->next_index = next1; |
| 468 | tr->error = error1; |
| 469 | tr->tunnel_index = tunnel_index1; |
| 470 | } |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 471 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 472 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, |
| 473 | n_left_to_next, bi0, bi1, next0, |
| 474 | next1); |
| 475 | } |
| 476 | |
| 477 | while (n_left_from > 0 && n_left_to_next > 0) |
| 478 | { |
| 479 | u32 bi0; |
| 480 | vlib_buffer_t *b0; |
| 481 | u32 next0; |
| 482 | ip4_vxlan_gpe_header_t *iuvn4_0; |
| 483 | ip6_vxlan_gpe_header_t *iuvn6_0; |
| 484 | uword *p0; |
| 485 | u32 tunnel_index0; |
| 486 | vxlan_gpe_tunnel_t *t0; |
| 487 | vxlan4_gpe_tunnel_key_t key4_0; |
| 488 | vxlan6_gpe_tunnel_key_t key6_0; |
| 489 | u32 error0; |
| 490 | u32 sw_if_index0, len0; |
| 491 | |
| 492 | bi0 = from[0]; |
| 493 | to_next[0] = bi0; |
| 494 | from += 1; |
| 495 | to_next += 1; |
| 496 | n_left_from -= 1; |
| 497 | n_left_to_next -= 1; |
| 498 | |
| 499 | b0 = vlib_get_buffer (vm, bi0); |
| 500 | |
| 501 | if (is_ip4) |
| 502 | { |
| 503 | /* udp leaves current_data pointing at the vxlan-gpe header */ |
| 504 | vlib_buffer_advance (b0, |
| 505 | -(word) (sizeof (udp_header_t) + |
| 506 | sizeof (ip4_header_t))); |
| 507 | |
| 508 | iuvn4_0 = vlib_buffer_get_current (b0); |
| 509 | |
| 510 | /* pop (ip, udp, vxlan) */ |
| 511 | vlib_buffer_advance (b0, sizeof (*iuvn4_0)); |
| 512 | } |
| 513 | else |
| 514 | { |
| 515 | /* udp leaves current_data pointing at the vxlan-gpe header */ |
| 516 | vlib_buffer_advance (b0, |
| 517 | -(word) (sizeof (udp_header_t) + |
| 518 | sizeof (ip6_header_t))); |
| 519 | |
| 520 | iuvn6_0 = vlib_buffer_get_current (b0); |
| 521 | |
| 522 | /* pop (ip, udp, vxlan) */ |
| 523 | vlib_buffer_advance (b0, sizeof (*iuvn6_0)); |
| 524 | } |
| 525 | |
| 526 | tunnel_index0 = ~0; |
| 527 | error0 = 0; |
| 528 | |
| 529 | if (is_ip4) |
| 530 | { |
| 531 | next0 = |
| 532 | (iuvn4_0->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ? |
| 533 | nngm->decap_next_node_list[iuvn4_0->vxlan.protocol] : |
| 534 | VXLAN_GPE_INPUT_NEXT_DROP; |
| 535 | |
| 536 | key4_0.local = iuvn4_0->ip4.dst_address.as_u32; |
| 537 | key4_0.remote = iuvn4_0->ip4.src_address.as_u32; |
| 538 | key4_0.vni = iuvn4_0->vxlan.vni_res; |
| 539 | key4_0.pad = 0; |
| 540 | |
| 541 | /* Processing for key4_0 */ |
| 542 | if (PREDICT_FALSE ((key4_0.as_u64[0] != last_key4.as_u64[0]) |
| 543 | || (key4_0.as_u64[1] != |
| 544 | last_key4.as_u64[1]))) |
| 545 | { |
| 546 | p0 = hash_get_mem (nngm->vxlan4_gpe_tunnel_by_key, &key4_0); |
| 547 | |
| 548 | if (p0 == 0) |
| 549 | { |
| 550 | error0 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL; |
| 551 | goto trace00; |
| 552 | } |
| 553 | |
| 554 | last_key4.as_u64[0] = key4_0.as_u64[0]; |
| 555 | last_key4.as_u64[1] = key4_0.as_u64[1]; |
| 556 | tunnel_index0 = last_tunnel_index = p0[0]; |
| 557 | } |
| 558 | else |
| 559 | tunnel_index0 = last_tunnel_index; |
| 560 | } |
| 561 | else /* is_ip6 */ |
| 562 | { |
| 563 | next0 = |
| 564 | (iuvn6_0->vxlan.protocol < VXLAN_GPE_PROTOCOL_MAX) ? |
| 565 | nngm->decap_next_node_list[iuvn6_0->vxlan.protocol] : |
| 566 | VXLAN_GPE_INPUT_NEXT_DROP; |
| 567 | |
| 568 | key6_0.local.as_u64[0] = iuvn6_0->ip6.dst_address.as_u64[0]; |
| 569 | key6_0.local.as_u64[1] = iuvn6_0->ip6.dst_address.as_u64[1]; |
| 570 | key6_0.remote.as_u64[0] = iuvn6_0->ip6.src_address.as_u64[0]; |
| 571 | key6_0.remote.as_u64[1] = iuvn6_0->ip6.src_address.as_u64[1]; |
| 572 | key6_0.vni = iuvn6_0->vxlan.vni_res; |
| 573 | |
| 574 | /* Processing for key6_0 */ |
| 575 | if (PREDICT_FALSE |
| 576 | (memcmp (&key6_0, &last_key6, sizeof (last_key6)) != 0)) |
| 577 | { |
| 578 | p0 = hash_get_mem (nngm->vxlan6_gpe_tunnel_by_key, &key6_0); |
| 579 | |
| 580 | if (p0 == 0) |
| 581 | { |
| 582 | error0 = VXLAN_GPE_ERROR_NO_SUCH_TUNNEL; |
| 583 | goto trace00; |
| 584 | } |
| 585 | |
| 586 | memcpy (&last_key6, &key6_0, sizeof (key6_0)); |
| 587 | tunnel_index0 = last_tunnel_index = p0[0]; |
| 588 | } |
| 589 | else |
| 590 | tunnel_index0 = last_tunnel_index; |
| 591 | } |
| 592 | |
| 593 | t0 = pool_elt_at_index (nngm->tunnels, tunnel_index0); |
| 594 | |
| 595 | |
| 596 | sw_if_index0 = t0->sw_if_index; |
| 597 | len0 = vlib_buffer_length_in_chain (vm, b0); |
| 598 | |
| 599 | /* Required to make the l2 tag push / pop code work on l2 subifs */ |
| 600 | vnet_update_l2_len (b0); |
| 601 | |
Gabriel Ganne | 7e665d6 | 2017-11-17 09:18:53 +0100 | [diff] [blame] | 602 | /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */ |
| 603 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index; |
| 604 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 605 | /* |
| 606 | * ip[46] lookup in the configured FIB |
| 607 | */ |
| 608 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = t0->decap_fib_index; |
| 609 | |
Zhiyong Yang | 73c8d1d | 2019-07-03 22:56:24 -0400 | [diff] [blame] | 610 | pkts_decapsulated++; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 611 | stats_n_packets += 1; |
| 612 | stats_n_bytes += len0; |
| 613 | |
| 614 | /* Batch stats increment on the same vxlan-gpe tunnel so counter |
| 615 | is not incremented per packet */ |
| 616 | if (PREDICT_FALSE (sw_if_index0 != stats_sw_if_index)) |
| 617 | { |
| 618 | stats_n_packets -= 1; |
| 619 | stats_n_bytes -= len0; |
| 620 | if (stats_n_packets) |
| 621 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 622 | VNET_INTERFACE_COUNTER_RX, |
| 623 | thread_index, |
| 624 | stats_sw_if_index, |
| 625 | stats_n_packets, |
| 626 | stats_n_bytes); |
| 627 | stats_n_packets = 1; |
| 628 | stats_n_bytes = len0; |
| 629 | stats_sw_if_index = sw_if_index0; |
| 630 | } |
| 631 | |
| 632 | trace00:b0->error = error0 ? node->errors[error0] : 0; |
| 633 | |
| 634 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 635 | { |
| 636 | vxlan_gpe_rx_trace_t *tr = |
| 637 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 638 | tr->next_index = next0; |
| 639 | tr->error = error0; |
| 640 | tr->tunnel_index = tunnel_index0; |
| 641 | } |
| 642 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, |
| 643 | n_left_to_next, bi0, next0); |
| 644 | } |
| 645 | |
| 646 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 647 | } |
Zhiyong Yang | 73c8d1d | 2019-07-03 22:56:24 -0400 | [diff] [blame] | 648 | |
| 649 | vlib_node_increment_counter (vm, |
| 650 | is_ip4 ? vxlan4_gpe_input_node.index : |
| 651 | vxlan6_gpe_input_node.index, |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 652 | VXLAN_GPE_ERROR_DECAPSULATED, |
Zhiyong Yang | 73c8d1d | 2019-07-03 22:56:24 -0400 | [diff] [blame] | 653 | pkts_decapsulated); |
| 654 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 655 | /* Increment any remaining batch stats */ |
| 656 | if (stats_n_packets) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 657 | { |
| 658 | vlib_increment_combined_counter (im->combined_sw_if_counters + |
| 659 | VNET_INTERFACE_COUNTER_RX, |
| 660 | thread_index, stats_sw_if_index, |
| 661 | stats_n_packets, stats_n_bytes); |
| 662 | node->runtime_data[0] = stats_sw_if_index; |
| 663 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 664 | return from_frame->n_vectors; |
| 665 | } |
| 666 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 667 | /** |
| 668 | * @brief Graph processing dispatch function for IPv4 VXLAN GPE |
| 669 | * |
| 670 | * @node vxlan4-gpe-input |
| 671 | * @param *vm |
| 672 | * @param *node |
| 673 | * @param *from_frame |
| 674 | * |
| 675 | * @return from_frame->n_vectors |
| 676 | * |
| 677 | */ |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 678 | VLIB_NODE_FN (vxlan4_gpe_input_node) (vlib_main_t * vm, |
| 679 | vlib_node_runtime_t * node, |
| 680 | vlib_frame_t * from_frame) |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 681 | { |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 682 | return vxlan_gpe_input (vm, node, from_frame, /* is_ip4 */ 1); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 683 | } |
| 684 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 685 | #ifndef CLIB_MARCH_VARIANT |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 686 | void |
| 687 | vxlan_gpe_register_decap_protocol (u8 protocol_id, uword next_node_index) |
| 688 | { |
| 689 | vxlan_gpe_main_t *hm = &vxlan_gpe_main; |
| 690 | hm->decap_next_node_list[protocol_id] = next_node_index; |
| 691 | return; |
| 692 | } |
| 693 | |
| 694 | void |
| 695 | vxlan_gpe_unregister_decap_protocol (u8 protocol_id, uword next_node_index) |
| 696 | { |
| 697 | vxlan_gpe_main_t *hm = &vxlan_gpe_main; |
| 698 | hm->decap_next_node_list[protocol_id] = VXLAN_GPE_INPUT_NEXT_DROP; |
| 699 | return; |
| 700 | } |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 701 | #endif /* CLIB_MARCH_VARIANT */ |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 702 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 703 | /** |
| 704 | * @brief Graph processing dispatch function for IPv6 VXLAN GPE |
| 705 | * |
| 706 | * @node vxlan6-gpe-input |
| 707 | * @param *vm |
| 708 | * @param *node |
| 709 | * @param *from_frame |
| 710 | * |
| 711 | * @return from_frame->n_vectors - uword |
| 712 | * |
| 713 | */ |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 714 | VLIB_NODE_FN (vxlan6_gpe_input_node) (vlib_main_t * vm, |
| 715 | vlib_node_runtime_t * node, |
| 716 | vlib_frame_t * from_frame) |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 717 | { |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 718 | return vxlan_gpe_input (vm, node, from_frame, /* is_ip4 */ 0); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 719 | } |
| 720 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 721 | /** |
| 722 | * @brief VXLAN GPE error strings |
| 723 | */ |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 724 | static char *vxlan_gpe_error_strings[] = { |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 725 | #define vxlan_gpe_error(n,s) s, |
| 726 | #include <vnet/vxlan-gpe/vxlan_gpe_error.def> |
| 727 | #undef vxlan_gpe_error |
| 728 | #undef _ |
| 729 | }; |
| 730 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 731 | /* *INDENT-OFF* */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 732 | VLIB_REGISTER_NODE (vxlan4_gpe_input_node) = { |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 733 | .name = "vxlan4-gpe-input", |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 734 | /* Takes a vector of packets. */ |
| 735 | .vector_size = sizeof (u32), |
| 736 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 737 | .n_errors = ARRAY_LEN(vxlan_gpe_error_strings), |
| 738 | .error_strings = vxlan_gpe_error_strings, |
| 739 | |
| 740 | .n_next_nodes = VXLAN_GPE_INPUT_N_NEXT, |
| 741 | .next_nodes = { |
| 742 | #define _(s,n) [VXLAN_GPE_INPUT_NEXT_##s] = n, |
| 743 | foreach_vxlan_gpe_input_next |
| 744 | #undef _ |
| 745 | }, |
| 746 | |
| 747 | .format_buffer = format_vxlan_gpe_with_length, |
| 748 | .format_trace = format_vxlan_gpe_rx_trace, |
| 749 | // $$$$ .unformat_buffer = unformat_vxlan_gpe_header, |
| 750 | }; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 751 | /* *INDENT-ON* */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 752 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 753 | /* *INDENT-OFF* */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 754 | VLIB_REGISTER_NODE (vxlan6_gpe_input_node) = { |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 755 | .name = "vxlan6-gpe-input", |
| 756 | /* Takes a vector of packets. */ |
| 757 | .vector_size = sizeof (u32), |
| 758 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 759 | .n_errors = ARRAY_LEN(vxlan_gpe_error_strings), |
| 760 | .error_strings = vxlan_gpe_error_strings, |
| 761 | |
| 762 | .n_next_nodes = VXLAN_GPE_INPUT_N_NEXT, |
| 763 | .next_nodes = { |
| 764 | #define _(s,n) [VXLAN_GPE_INPUT_NEXT_##s] = n, |
| 765 | foreach_vxlan_gpe_input_next |
| 766 | #undef _ |
| 767 | }, |
| 768 | |
| 769 | .format_buffer = format_vxlan_gpe_with_length, |
| 770 | .format_trace = format_vxlan_gpe_rx_trace, |
| 771 | // $$$$ .unformat_buffer = unformat_vxlan_gpe_header, |
| 772 | }; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 773 | /* *INDENT-ON* */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 774 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 775 | typedef enum |
| 776 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 777 | IP_VXLAN_BYPASS_NEXT_DROP, |
| 778 | IP_VXLAN_BYPASS_NEXT_VXLAN, |
| 779 | IP_VXLAN_BYPASS_N_NEXT, |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 780 | } ip_vxlan_bypass_next_t; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 781 | |
| 782 | always_inline uword |
| 783 | ip_vxlan_gpe_bypass_inline (vlib_main_t * vm, |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 784 | vlib_node_runtime_t * node, |
| 785 | vlib_frame_t * frame, u32 is_ip4) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 786 | { |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 787 | vxlan_gpe_main_t *ngm = &vxlan_gpe_main; |
| 788 | u32 *from, *to_next, n_left_from, n_left_to_next, next_index; |
| 789 | vlib_node_runtime_t *error_node = |
| 790 | vlib_node_get_runtime (vm, ip4_input_node.index); |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 791 | vtep4_key_t last_vtep4; /* last IPv4 address / fib index |
| 792 | matching a local VTEP address */ |
| 793 | vtep6_key_t last_vtep6; /* last IPv6 address / fib index |
| 794 | matching a local VTEP address */ |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 795 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 796 | |
| 797 | from = vlib_frame_vector_args (frame); |
| 798 | n_left_from = frame->n_vectors; |
| 799 | next_index = node->cached_next_index; |
| 800 | |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 801 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 802 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 803 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 804 | ip4_forward_next_trace (vm, node, frame, VLIB_TX); |
| 805 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 806 | if (is_ip4) |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 807 | vtep4_key_init (&last_vtep4); |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 808 | else |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 809 | vtep6_key_init (&last_vtep6); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 810 | |
| 811 | while (n_left_from > 0) |
| 812 | { |
| 813 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 814 | |
| 815 | while (n_left_from >= 4 && n_left_to_next >= 2) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 816 | { |
| 817 | vlib_buffer_t *b0, *b1; |
| 818 | ip4_header_t *ip40, *ip41; |
| 819 | ip6_header_t *ip60, *ip61; |
| 820 | udp_header_t *udp0, *udp1; |
| 821 | u32 bi0, ip_len0, udp_len0, flags0, next0; |
| 822 | u32 bi1, ip_len1, udp_len1, flags1, next1; |
| 823 | i32 len_diff0, len_diff1; |
| 824 | u8 error0, good_udp0, proto0; |
| 825 | u8 error1, good_udp1, proto1; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 826 | |
| 827 | /* Prefetch next iteration. */ |
| 828 | { |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 829 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 830 | vlib_prefetch_buffer_header (b[3], LOAD); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 831 | |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 832 | CLIB_PREFETCH (b[2]->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 833 | CLIB_PREFETCH (b[3]->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 834 | } |
| 835 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 836 | bi0 = to_next[0] = from[0]; |
| 837 | bi1 = to_next[1] = from[1]; |
| 838 | from += 2; |
| 839 | n_left_from -= 2; |
| 840 | to_next += 2; |
| 841 | n_left_to_next -= 2; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 842 | |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 843 | b0 = b[0]; |
| 844 | b1 = b[1]; |
| 845 | b += 2; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 846 | if (is_ip4) |
| 847 | { |
| 848 | ip40 = vlib_buffer_get_current (b0); |
| 849 | ip41 = vlib_buffer_get_current (b1); |
| 850 | } |
| 851 | else |
| 852 | { |
| 853 | ip60 = vlib_buffer_get_current (b0); |
| 854 | ip61 = vlib_buffer_get_current (b1); |
| 855 | } |
| 856 | |
| 857 | /* Setup packet for next IP feature */ |
Damjan Marion | 7d98a12 | 2018-07-19 20:42:08 +0200 | [diff] [blame] | 858 | vnet_feature_next (&next0, b0); |
| 859 | vnet_feature_next (&next1, b1); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 860 | |
| 861 | if (is_ip4) |
| 862 | { |
| 863 | proto0 = ip40->protocol; |
| 864 | proto1 = ip41->protocol; |
| 865 | } |
| 866 | else |
| 867 | { |
| 868 | proto0 = ip60->protocol; |
| 869 | proto1 = ip61->protocol; |
| 870 | } |
| 871 | |
| 872 | /* Process packet 0 */ |
| 873 | if (proto0 != IP_PROTOCOL_UDP) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 874 | goto exit0; /* not UDP packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 875 | |
| 876 | if (is_ip4) |
| 877 | udp0 = ip4_next_header (ip40); |
| 878 | else |
| 879 | udp0 = ip6_next_header (ip60); |
| 880 | |
| 881 | if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE)) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 882 | goto exit0; /* not VXLAN packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 883 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 884 | /* Validate DIP against VTEPs */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 885 | if (is_ip4) |
| 886 | { |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 887 | #ifdef CLIB_HAVE_VEC512 |
Junfeng Wang | 290526e | 2021-03-09 16:44:57 +0800 | [diff] [blame] | 888 | if (!vtep4_check_vector (&ngm->vtep_table, b0, ip40, &last_vtep4, |
| 889 | &ngm->vtep4_u512)) |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 890 | #else |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 891 | if (!vtep4_check (&ngm->vtep_table, b0, ip40, &last_vtep4)) |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 892 | #endif |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 893 | goto exit0; /* no local VTEP for VXLAN packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 894 | } |
| 895 | else |
| 896 | { |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 897 | if (!vtep6_check (&ngm->vtep_table, b0, ip60, &last_vtep6)) |
| 898 | goto exit0; /* no local VTEP for VXLAN packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | flags0 = b0->flags; |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 902 | good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 903 | |
| 904 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 905 | good_udp0 |= udp0->checksum == 0; |
| 906 | |
| 907 | /* Verify UDP length */ |
| 908 | if (is_ip4) |
| 909 | ip_len0 = clib_net_to_host_u16 (ip40->length); |
| 910 | else |
| 911 | ip_len0 = clib_net_to_host_u16 (ip60->payload_length); |
| 912 | udp_len0 = clib_net_to_host_u16 (udp0->length); |
| 913 | len_diff0 = ip_len0 - udp_len0; |
| 914 | |
| 915 | /* Verify UDP checksum */ |
| 916 | if (PREDICT_FALSE (!good_udp0)) |
| 917 | { |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 918 | if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 919 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 920 | if (is_ip4) |
| 921 | flags0 = ip4_tcp_udp_validate_checksum (vm, b0); |
| 922 | else |
| 923 | flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0); |
| 924 | good_udp0 = |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 925 | (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 926 | } |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 927 | } |
| 928 | |
| 929 | if (is_ip4) |
| 930 | { |
| 931 | error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM; |
| 932 | error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH; |
| 933 | } |
| 934 | else |
| 935 | { |
| 936 | error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM; |
| 937 | error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH; |
| 938 | } |
| 939 | |
| 940 | next0 = error0 ? |
| 941 | IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN; |
| 942 | b0->error = error0 ? error_node->errors[error0] : 0; |
| 943 | |
| 944 | /* vxlan_gpe-input node expect current at VXLAN header */ |
| 945 | if (is_ip4) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 946 | vlib_buffer_advance (b0, |
| 947 | sizeof (ip4_header_t) + |
| 948 | sizeof (udp_header_t)); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 949 | else |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 950 | vlib_buffer_advance (b0, |
| 951 | sizeof (ip6_header_t) + |
| 952 | sizeof (udp_header_t)); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 953 | |
| 954 | exit0: |
| 955 | /* Process packet 1 */ |
| 956 | if (proto1 != IP_PROTOCOL_UDP) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 957 | goto exit1; /* not UDP packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 958 | |
| 959 | if (is_ip4) |
| 960 | udp1 = ip4_next_header (ip41); |
| 961 | else |
| 962 | udp1 = ip6_next_header (ip61); |
| 963 | |
| 964 | if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE)) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 965 | goto exit1; /* not VXLAN packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 966 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 967 | /* Validate DIP against VTEPs */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 968 | if (is_ip4) |
| 969 | { |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 970 | #ifdef CLIB_HAVE_VEC512 |
Junfeng Wang | 290526e | 2021-03-09 16:44:57 +0800 | [diff] [blame] | 971 | if (!vtep4_check_vector (&ngm->vtep_table, b1, ip41, &last_vtep4, |
| 972 | &ngm->vtep4_u512)) |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 973 | #else |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 974 | if (!vtep4_check (&ngm->vtep_table, b1, ip41, &last_vtep4)) |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 975 | #endif |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 976 | goto exit1; /* no local VTEP for VXLAN packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 977 | } |
| 978 | else |
| 979 | { |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 980 | if (!vtep6_check (&ngm->vtep_table, b1, ip61, &last_vtep6)) |
| 981 | goto exit1; /* no local VTEP for VXLAN packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | flags1 = b1->flags; |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 985 | good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 986 | |
| 987 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 988 | good_udp1 |= udp1->checksum == 0; |
| 989 | |
| 990 | /* Verify UDP length */ |
| 991 | if (is_ip4) |
| 992 | ip_len1 = clib_net_to_host_u16 (ip41->length); |
| 993 | else |
| 994 | ip_len1 = clib_net_to_host_u16 (ip61->payload_length); |
| 995 | udp_len1 = clib_net_to_host_u16 (udp1->length); |
| 996 | len_diff1 = ip_len1 - udp_len1; |
| 997 | |
| 998 | /* Verify UDP checksum */ |
| 999 | if (PREDICT_FALSE (!good_udp1)) |
| 1000 | { |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1001 | if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1002 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1003 | if (is_ip4) |
| 1004 | flags1 = ip4_tcp_udp_validate_checksum (vm, b1); |
| 1005 | else |
| 1006 | flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1); |
| 1007 | good_udp1 = |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1008 | (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1009 | } |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | if (is_ip4) |
| 1013 | { |
| 1014 | error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM; |
| 1015 | error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH; |
| 1016 | } |
| 1017 | else |
| 1018 | { |
| 1019 | error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM; |
| 1020 | error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH; |
| 1021 | } |
| 1022 | |
| 1023 | next1 = error1 ? |
| 1024 | IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN; |
| 1025 | b1->error = error1 ? error_node->errors[error1] : 0; |
| 1026 | |
| 1027 | /* vxlan_gpe-input node expect current at VXLAN header */ |
| 1028 | if (is_ip4) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1029 | vlib_buffer_advance (b1, |
| 1030 | sizeof (ip4_header_t) + |
| 1031 | sizeof (udp_header_t)); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1032 | else |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1033 | vlib_buffer_advance (b1, |
| 1034 | sizeof (ip6_header_t) + |
| 1035 | sizeof (udp_header_t)); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1036 | |
| 1037 | exit1: |
| 1038 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 1039 | to_next, n_left_to_next, |
| 1040 | bi0, bi1, next0, next1); |
| 1041 | } |
| 1042 | |
| 1043 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1044 | { |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1045 | vlib_buffer_t *b0; |
| 1046 | ip4_header_t *ip40; |
| 1047 | ip6_header_t *ip60; |
| 1048 | udp_header_t *udp0; |
| 1049 | u32 bi0, ip_len0, udp_len0, flags0, next0; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1050 | i32 len_diff0; |
| 1051 | u8 error0, good_udp0, proto0; |
| 1052 | |
| 1053 | bi0 = to_next[0] = from[0]; |
| 1054 | from += 1; |
| 1055 | n_left_from -= 1; |
| 1056 | to_next += 1; |
| 1057 | n_left_to_next -= 1; |
| 1058 | |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 1059 | b0 = b[0]; |
| 1060 | b++; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1061 | if (is_ip4) |
| 1062 | ip40 = vlib_buffer_get_current (b0); |
| 1063 | else |
| 1064 | ip60 = vlib_buffer_get_current (b0); |
| 1065 | |
| 1066 | /* Setup packet for next IP feature */ |
Damjan Marion | 7d98a12 | 2018-07-19 20:42:08 +0200 | [diff] [blame] | 1067 | vnet_feature_next (&next0, b0); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1068 | |
| 1069 | if (is_ip4) |
| 1070 | proto0 = ip40->protocol; |
| 1071 | else |
| 1072 | proto0 = ip60->protocol; |
| 1073 | |
| 1074 | if (proto0 != IP_PROTOCOL_UDP) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1075 | goto exit; /* not UDP packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1076 | |
| 1077 | if (is_ip4) |
| 1078 | udp0 = ip4_next_header (ip40); |
| 1079 | else |
| 1080 | udp0 = ip6_next_header (ip60); |
| 1081 | |
| 1082 | if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE)) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1083 | goto exit; /* not VXLAN packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1084 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1085 | /* Validate DIP against VTEPs */ |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 1086 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1087 | if (is_ip4) |
| 1088 | { |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 1089 | #ifdef CLIB_HAVE_VEC512 |
Junfeng Wang | 290526e | 2021-03-09 16:44:57 +0800 | [diff] [blame] | 1090 | if (!vtep4_check_vector (&ngm->vtep_table, b0, ip40, &last_vtep4, |
| 1091 | &ngm->vtep4_u512)) |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 1092 | #else |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 1093 | if (!vtep4_check (&ngm->vtep_table, b0, ip40, &last_vtep4)) |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 1094 | #endif |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 1095 | goto exit; /* no local VTEP for VXLAN packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1096 | } |
| 1097 | else |
| 1098 | { |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 1099 | if (!vtep6_check (&ngm->vtep_table, b0, ip60, &last_vtep6)) |
| 1100 | goto exit; /* no local VTEP for VXLAN packet */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | flags0 = b0->flags; |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1104 | good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1105 | |
| 1106 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 1107 | good_udp0 |= udp0->checksum == 0; |
| 1108 | |
| 1109 | /* Verify UDP length */ |
| 1110 | if (is_ip4) |
| 1111 | ip_len0 = clib_net_to_host_u16 (ip40->length); |
| 1112 | else |
| 1113 | ip_len0 = clib_net_to_host_u16 (ip60->payload_length); |
| 1114 | udp_len0 = clib_net_to_host_u16 (udp0->length); |
| 1115 | len_diff0 = ip_len0 - udp_len0; |
| 1116 | |
| 1117 | /* Verify UDP checksum */ |
| 1118 | if (PREDICT_FALSE (!good_udp0)) |
| 1119 | { |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1120 | if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1121 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1122 | if (is_ip4) |
| 1123 | flags0 = ip4_tcp_udp_validate_checksum (vm, b0); |
| 1124 | else |
| 1125 | flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0); |
| 1126 | good_udp0 = |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 1127 | (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1128 | } |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | if (is_ip4) |
| 1132 | { |
| 1133 | error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM; |
| 1134 | error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH; |
| 1135 | } |
| 1136 | else |
| 1137 | { |
| 1138 | error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM; |
| 1139 | error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH; |
| 1140 | } |
| 1141 | |
| 1142 | next0 = error0 ? |
| 1143 | IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN; |
| 1144 | b0->error = error0 ? error_node->errors[error0] : 0; |
| 1145 | |
| 1146 | /* vxlan_gpe-input node expect current at VXLAN header */ |
| 1147 | if (is_ip4) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1148 | vlib_buffer_advance (b0, |
| 1149 | sizeof (ip4_header_t) + |
| 1150 | sizeof (udp_header_t)); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1151 | else |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1152 | vlib_buffer_advance (b0, |
| 1153 | sizeof (ip6_header_t) + |
| 1154 | sizeof (udp_header_t)); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1155 | |
| 1156 | exit: |
| 1157 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 1158 | to_next, n_left_to_next, |
| 1159 | bi0, next0); |
| 1160 | } |
| 1161 | |
| 1162 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1163 | } |
| 1164 | |
| 1165 | return frame->n_vectors; |
| 1166 | } |
| 1167 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1168 | VLIB_NODE_FN (ip4_vxlan_gpe_bypass_node) (vlib_main_t * vm, |
| 1169 | vlib_node_runtime_t * node, |
| 1170 | vlib_frame_t * frame) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1171 | { |
| 1172 | return ip_vxlan_gpe_bypass_inline (vm, node, frame, /* is_ip4 */ 1); |
| 1173 | } |
| 1174 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1175 | /* *INDENT-OFF* */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1176 | VLIB_REGISTER_NODE (ip4_vxlan_gpe_bypass_node) = { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1177 | .name = "ip4-vxlan-gpe-bypass", |
| 1178 | .vector_size = sizeof (u32), |
| 1179 | |
| 1180 | .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT, |
| 1181 | .next_nodes = { |
| 1182 | [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop", |
| 1183 | [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan4-gpe-input", |
| 1184 | }, |
| 1185 | |
| 1186 | .format_buffer = format_ip4_header, |
| 1187 | .format_trace = format_ip4_forward_next_trace, |
| 1188 | }; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1189 | /* *INDENT-ON* */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1190 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1191 | #ifndef CLIB_MARCH_VARIANT |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1192 | /* Dummy init function to get us linked in. */ |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1193 | clib_error_t * |
| 1194 | ip4_vxlan_gpe_bypass_init (vlib_main_t * vm) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1195 | { |
| 1196 | return 0; |
| 1197 | } |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1198 | |
| 1199 | VLIB_INIT_FUNCTION (ip4_vxlan_gpe_bypass_init); |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1200 | #endif /* CLIB_MARCH_VARIANT */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1201 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1202 | VLIB_NODE_FN (ip6_vxlan_gpe_bypass_node) (vlib_main_t * vm, |
| 1203 | vlib_node_runtime_t * node, |
| 1204 | vlib_frame_t * frame) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1205 | { |
| 1206 | return ip_vxlan_gpe_bypass_inline (vm, node, frame, /* is_ip4 */ 0); |
| 1207 | } |
| 1208 | |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1209 | /* *INDENT-OFF* */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1210 | VLIB_REGISTER_NODE (ip6_vxlan_gpe_bypass_node) = { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1211 | .name = "ip6-vxlan-gpe-bypass", |
| 1212 | .vector_size = sizeof (u32), |
| 1213 | |
| 1214 | .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT, |
| 1215 | .next_nodes = { |
| 1216 | [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop", |
| 1217 | [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan6-gpe-input", |
| 1218 | }, |
| 1219 | |
| 1220 | .format_buffer = format_ip6_header, |
| 1221 | .format_trace = format_ip6_forward_next_trace, |
| 1222 | }; |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1223 | /* *INDENT-ON* */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1224 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1225 | #ifndef CLIB_MARCH_VARIANT |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1226 | /* Dummy init function to get us linked in. */ |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1227 | clib_error_t * |
| 1228 | ip6_vxlan_gpe_bypass_init (vlib_main_t * vm) |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1229 | { |
| 1230 | return 0; |
| 1231 | } |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1232 | |
| 1233 | VLIB_INIT_FUNCTION (ip6_vxlan_gpe_bypass_init); |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1234 | #endif /* CLIB_MARCH_VARIANT */ |
sharath reddy | 6f8273a | 2017-12-11 11:31:31 +0530 | [diff] [blame] | 1235 | |
| 1236 | /* |
| 1237 | * fd.io coding-style-patch-verification: ON |
| 1238 | * |
| 1239 | * Local Variables: |
| 1240 | * eval: (c-set-style "gnu") |
| 1241 | * End: |
| 1242 | */ |