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