Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * decap.c: vxlan tunnel decap packet processing |
| 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 | */ |
| 17 | |
| 18 | #include <vlib/vlib.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 19 | #include <vnet/vxlan/vxlan.h> |
| 20 | |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 21 | #ifndef CLIB_MARCH_VARIANT |
John Lo | 13e3d45 | 2016-08-09 19:20:51 -0400 | [diff] [blame] | 22 | vlib_node_registration_t vxlan4_input_node; |
| 23 | vlib_node_registration_t vxlan6_input_node; |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 24 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 25 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 26 | typedef struct |
| 27 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | u32 next_index; |
| 29 | u32 tunnel_index; |
| 30 | u32 error; |
| 31 | u32 vni; |
| 32 | } vxlan_rx_trace_t; |
| 33 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 34 | static u8 * |
| 35 | format_vxlan_rx_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 36 | { |
| 37 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 38 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 39 | vxlan_rx_trace_t *t = va_arg (*args, vxlan_rx_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 40 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 41 | if (t->tunnel_index == ~0) |
| 42 | return format (s, "VXLAN decap error - tunnel for vni %d does not exist", |
| 43 | t->vni); |
| 44 | return format (s, "VXLAN decap from vxlan_tunnel%d vni %d next %d error %d", |
| 45 | t->tunnel_index, t->vni, t->next_index, t->error); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | } |
| 47 | |
Eyal Bari | dd47eca | 2018-07-08 08:15:56 +0300 | [diff] [blame] | 48 | typedef vxlan4_tunnel_key_t last_tunnel_cache4; |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 49 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 50 | static const vxlan_decap_info_t decap_not_found = { |
| 51 | .sw_if_index = ~0, |
| 52 | .next_index = VXLAN_INPUT_NEXT_DROP, |
| 53 | .error = VXLAN_ERROR_NO_SUCH_TUNNEL |
| 54 | }; |
| 55 | |
| 56 | static const vxlan_decap_info_t decap_bad_flags = { |
| 57 | .sw_if_index = ~0, |
| 58 | .next_index = VXLAN_INPUT_NEXT_DROP, |
| 59 | .error = VXLAN_ERROR_BAD_FLAGS |
| 60 | }; |
| 61 | |
| 62 | always_inline vxlan_decap_info_t |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 63 | vxlan4_find_tunnel (vxlan_main_t * vxm, last_tunnel_cache4 * cache, |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 64 | u32 fib_index, ip4_header_t * ip4_0, |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 65 | vxlan_header_t * vxlan0, u32 * stats_sw_if_index) |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 66 | { |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 67 | if (PREDICT_FALSE (vxlan0->flags != VXLAN_FLAGS_I)) |
| 68 | return decap_bad_flags; |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 69 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 70 | /* Make sure VXLAN tunnel exist according to packet S/D IP, VRF, and VNI */ |
| 71 | u32 dst = ip4_0->dst_address.as_u32; |
| 72 | u32 src = ip4_0->src_address.as_u32; |
| 73 | vxlan4_tunnel_key_t key4 = { |
| 74 | .key[0] = ((u64) dst << 32) | src, |
| 75 | .key[1] = ((u64) fib_index << 32) | vxlan0->vni_reserved, |
| 76 | }; |
| 77 | |
| 78 | if (PREDICT_TRUE |
Eyal Bari | 9be7c6d | 2018-10-17 17:13:42 +0300 | [diff] [blame] | 79 | (key4.key[0] == cache->key[0] && key4.key[1] == cache->key[1])) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 80 | { |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 81 | /* cache hit */ |
| 82 | vxlan_decap_info_t di = {.as_u64 = cache->value }; |
| 83 | *stats_sw_if_index = di.sw_if_index; |
| 84 | return di; |
| 85 | } |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 86 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 87 | int rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_tunnel_by_key, &key4); |
| 88 | if (PREDICT_TRUE (rv == 0)) |
| 89 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 90 | *cache = key4; |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 91 | vxlan_decap_info_t di = {.as_u64 = key4.value }; |
| 92 | *stats_sw_if_index = di.sw_if_index; |
| 93 | return di; |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 94 | } |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 95 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 96 | /* try multicast */ |
| 97 | if (PREDICT_TRUE (!ip4_address_is_multicast (&ip4_0->dst_address))) |
| 98 | return decap_not_found; |
| 99 | |
| 100 | /* search for mcast decap info by mcast address */ |
| 101 | key4.key[0] = dst; |
| 102 | rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_tunnel_by_key, &key4); |
| 103 | if (rv != 0) |
| 104 | return decap_not_found; |
| 105 | |
| 106 | /* search for unicast tunnel using the mcast tunnel local(src) ip */ |
| 107 | vxlan_decap_info_t mdi = {.as_u64 = key4.value }; |
| 108 | key4.key[0] = ((u64) mdi.local_ip.as_u32 << 32) | src; |
| 109 | rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_tunnel_by_key, &key4); |
| 110 | if (PREDICT_FALSE (rv != 0)) |
| 111 | return decap_not_found; |
| 112 | |
| 113 | /* mcast traffic does not update the cache */ |
| 114 | *stats_sw_if_index = mdi.sw_if_index; |
| 115 | vxlan_decap_info_t di = {.as_u64 = key4.value }; |
| 116 | return di; |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 117 | } |
| 118 | |
Eyal Bari | 0fa5678 | 2018-06-04 12:25:05 +0300 | [diff] [blame] | 119 | typedef vxlan6_tunnel_key_t last_tunnel_cache6; |
| 120 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 121 | always_inline vxlan_decap_info_t |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 122 | vxlan6_find_tunnel (vxlan_main_t * vxm, last_tunnel_cache6 * cache, |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 123 | u32 fib_index, ip6_header_t * ip6_0, |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 124 | vxlan_header_t * vxlan0, u32 * stats_sw_if_index) |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 125 | { |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 126 | if (PREDICT_FALSE (vxlan0->flags != VXLAN_FLAGS_I)) |
| 127 | return decap_bad_flags; |
| 128 | |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 129 | /* Make sure VXLAN tunnel exist according to packet SIP and VNI */ |
Eyal Bari | 0fa5678 | 2018-06-04 12:25:05 +0300 | [diff] [blame] | 130 | vxlan6_tunnel_key_t key6 = { |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 131 | .key[0] = ip6_0->src_address.as_u64[0], |
| 132 | .key[1] = ip6_0->src_address.as_u64[1], |
| 133 | .key[2] = (((u64) fib_index) << 32) | vxlan0->vni_reserved, |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 134 | }; |
| 135 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 136 | if (PREDICT_FALSE |
| 137 | (clib_bihash_key_compare_24_8 (key6.key, cache->key) == 0)) |
| 138 | { |
| 139 | int rv = |
| 140 | clib_bihash_search_inline_24_8 (&vxm->vxlan6_tunnel_by_key, &key6); |
| 141 | if (PREDICT_FALSE (rv != 0)) |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 142 | return decap_not_found; |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 143 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 144 | *cache = key6; |
| 145 | } |
| 146 | vxlan_tunnel_t *t0 = pool_elt_at_index (vxm->tunnels, cache->value); |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 147 | |
| 148 | /* Validate VXLAN tunnel SIP against packet DIP */ |
| 149 | if (PREDICT_TRUE (ip6_address_is_equal (&ip6_0->dst_address, &t0->src.ip6))) |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 150 | *stats_sw_if_index = t0->sw_if_index; |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 151 | else |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 152 | { |
| 153 | /* try multicast */ |
| 154 | if (PREDICT_TRUE (!ip6_address_is_multicast (&ip6_0->dst_address))) |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 155 | return decap_not_found; |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 156 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 157 | /* Make sure mcast VXLAN tunnel exist by packet DIP and VNI */ |
| 158 | key6.key[0] = ip6_0->dst_address.as_u64[0]; |
| 159 | key6.key[1] = ip6_0->dst_address.as_u64[1]; |
| 160 | int rv = |
| 161 | clib_bihash_search_inline_24_8 (&vxm->vxlan6_tunnel_by_key, &key6); |
| 162 | if (PREDICT_FALSE (rv != 0)) |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 163 | return decap_not_found; |
Eyal Bari | 0fa5678 | 2018-06-04 12:25:05 +0300 | [diff] [blame] | 164 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 165 | vxlan_tunnel_t *mcast_t0 = pool_elt_at_index (vxm->tunnels, key6.value); |
| 166 | *stats_sw_if_index = mcast_t0->sw_if_index; |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 167 | } |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 168 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 169 | vxlan_decap_info_t di = { |
| 170 | .sw_if_index = t0->sw_if_index, |
| 171 | .next_index = t0->decap_next_index, |
| 172 | }; |
| 173 | return di; |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 174 | } |
| 175 | |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 176 | always_inline uword |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 177 | vxlan_input (vlib_main_t * vm, |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 178 | vlib_node_runtime_t * node, |
| 179 | vlib_frame_t * from_frame, u32 is_ip4) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 180 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 181 | vxlan_main_t *vxm = &vxlan_main; |
| 182 | vnet_main_t *vnm = vxm->vnet_main; |
| 183 | vnet_interface_main_t *im = &vnm->interface_main; |
| 184 | vlib_combined_counter_main_t *rx_counter = |
| 185 | im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX; |
Eyal Bari | dd47eca | 2018-07-08 08:15:56 +0300 | [diff] [blame] | 186 | last_tunnel_cache4 last4; |
Eyal Bari | 0fa5678 | 2018-06-04 12:25:05 +0300 | [diff] [blame] | 187 | last_tunnel_cache6 last6; |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 188 | u32 pkts_dropped = 0; |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 189 | u32 thread_index = vlib_get_thread_index (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 190 | |
Dave Barach | f9c231e | 2016-08-05 10:10:18 -0400 | [diff] [blame] | 191 | if (is_ip4) |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 192 | clib_memset (&last4, 0xff, sizeof last4); |
Dave Barach | f9c231e | 2016-08-05 10:10:18 -0400 | [diff] [blame] | 193 | else |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 194 | clib_memset (&last6, 0xff, sizeof last6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 196 | u32 *from = vlib_frame_vector_args (from_frame); |
Eyal Bari | fb66301 | 2017-10-19 15:27:51 +0300 | [diff] [blame] | 197 | u32 n_left_from = from_frame->n_vectors; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 198 | |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 199 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
| 200 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 201 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 202 | u32 stats_if0 = ~0, stats_if1 = ~0; |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 203 | u16 nexts[VLIB_FRAME_SIZE], *next = nexts; |
| 204 | while (n_left_from >= 4) |
| 205 | { |
| 206 | /* Prefetch next iteration. */ |
| 207 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 208 | vlib_prefetch_buffer_header (b[3], LOAD); |
| 209 | |
| 210 | /* udp leaves current_data pointing at the vxlan header */ |
| 211 | void *cur0 = vlib_buffer_get_current (b[0]); |
| 212 | void *cur1 = vlib_buffer_get_current (b[1]); |
| 213 | vxlan_header_t *vxlan0 = cur0; |
| 214 | vxlan_header_t *vxlan1 = cur1; |
| 215 | |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 216 | |
| 217 | ip4_header_t *ip4_0, *ip4_1; |
| 218 | ip6_header_t *ip6_0, *ip6_1; |
| 219 | if (is_ip4) |
| 220 | { |
| 221 | ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t); |
| 222 | ip4_1 = cur1 - sizeof (udp_header_t) - sizeof (ip4_header_t); |
| 223 | } |
| 224 | else |
| 225 | { |
| 226 | ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t); |
| 227 | ip6_1 = cur1 - sizeof (udp_header_t) - sizeof (ip6_header_t); |
| 228 | } |
| 229 | |
| 230 | /* pop vxlan */ |
| 231 | vlib_buffer_advance (b[0], sizeof *vxlan0); |
| 232 | vlib_buffer_advance (b[1], sizeof *vxlan1); |
| 233 | |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 234 | u32 fi0 = vlib_buffer_get_ip_fib_index (b[0], is_ip4); |
| 235 | u32 fi1 = vlib_buffer_get_ip_fib_index (b[1], is_ip4); |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 236 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 237 | vxlan_decap_info_t di0 = is_ip4 ? |
| 238 | vxlan4_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan0, &stats_if0) : |
| 239 | vxlan6_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan0, &stats_if0); |
| 240 | vxlan_decap_info_t di1 = is_ip4 ? |
| 241 | vxlan4_find_tunnel (vxm, &last4, fi1, ip4_1, vxlan1, &stats_if1) : |
| 242 | vxlan6_find_tunnel (vxm, &last6, fi1, ip6_1, vxlan1, &stats_if1); |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 243 | |
| 244 | /* Prefetch next iteration. */ |
| 245 | CLIB_PREFETCH (b[2]->data, CLIB_CACHE_LINE_BYTES, LOAD); |
| 246 | CLIB_PREFETCH (b[3]->data, CLIB_CACHE_LINE_BYTES, LOAD); |
| 247 | |
| 248 | u32 len0 = vlib_buffer_length_in_chain (vm, b[0]); |
| 249 | u32 len1 = vlib_buffer_length_in_chain (vm, b[1]); |
| 250 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 251 | next[0] = di0.next_index; |
| 252 | next[1] = di1.next_index; |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 253 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 254 | u8 any_error = di0.error | di1.error; |
| 255 | if (PREDICT_TRUE (any_error == 0)) |
| 256 | { |
| 257 | /* Required to make the l2 tag push / pop code work on l2 subifs */ |
| 258 | vnet_update_l2_len (b[0]); |
| 259 | vnet_update_l2_len (b[1]); |
| 260 | /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */ |
| 261 | vnet_buffer (b[0])->sw_if_index[VLIB_RX] = di0.sw_if_index; |
| 262 | vnet_buffer (b[1])->sw_if_index[VLIB_RX] = di1.sw_if_index; |
| 263 | vlib_increment_combined_counter (rx_counter, thread_index, |
| 264 | stats_if0, 1, len0); |
| 265 | vlib_increment_combined_counter (rx_counter, thread_index, |
| 266 | stats_if1, 1, len1); |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 267 | } |
| 268 | else |
| 269 | { |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 270 | if (di0.error == 0) |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 271 | { |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 272 | vnet_update_l2_len (b[0]); |
| 273 | vnet_buffer (b[0])->sw_if_index[VLIB_RX] = di0.sw_if_index; |
| 274 | vlib_increment_combined_counter (rx_counter, thread_index, |
| 275 | stats_if0, 1, len0); |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 276 | } |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 277 | else |
| 278 | { |
| 279 | b[0]->error = node->errors[di0.error]; |
| 280 | pkts_dropped++; |
| 281 | } |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 282 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 283 | if (di1.error == 0) |
| 284 | { |
| 285 | vnet_update_l2_len (b[1]); |
| 286 | vnet_buffer (b[1])->sw_if_index[VLIB_RX] = di1.sw_if_index; |
| 287 | vlib_increment_combined_counter (rx_counter, thread_index, |
| 288 | stats_if1, 1, len1); |
| 289 | } |
| 290 | else |
| 291 | { |
| 292 | b[1]->error = node->errors[di1.error]; |
| 293 | pkts_dropped++; |
| 294 | } |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
| 298 | { |
| 299 | vxlan_rx_trace_t *tr = |
| 300 | vlib_add_trace (vm, node, b[0], sizeof (*tr)); |
| 301 | tr->next_index = next[0]; |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 302 | tr->error = di0.error; |
| 303 | tr->tunnel_index = di0.sw_if_index == ~0 ? |
| 304 | ~0 : vxm->tunnel_index_by_sw_if_index[di0.sw_if_index]; |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 305 | tr->vni = vnet_get_vni (vxlan0); |
| 306 | } |
| 307 | if (PREDICT_FALSE (b[1]->flags & VLIB_BUFFER_IS_TRACED)) |
| 308 | { |
| 309 | vxlan_rx_trace_t *tr = |
| 310 | vlib_add_trace (vm, node, b[1], sizeof (*tr)); |
| 311 | tr->next_index = next[1]; |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 312 | tr->error = di1.error; |
| 313 | tr->tunnel_index = di1.sw_if_index == ~0 ? |
| 314 | ~0 : vxm->tunnel_index_by_sw_if_index[di1.sw_if_index]; |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 315 | tr->vni = vnet_get_vni (vxlan1); |
| 316 | } |
| 317 | b += 2; |
| 318 | next += 2; |
| 319 | n_left_from -= 2; |
| 320 | } |
| 321 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 322 | while (n_left_from > 0) |
| 323 | { |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 324 | /* udp leaves current_data pointing at the vxlan header */ |
| 325 | void *cur0 = vlib_buffer_get_current (b[0]); |
| 326 | vxlan_header_t *vxlan0 = cur0; |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 327 | ip4_header_t *ip4_0; |
| 328 | ip6_header_t *ip6_0; |
| 329 | if (is_ip4) |
| 330 | ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t); |
| 331 | else |
| 332 | ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t); |
Eyal Bari | fb66301 | 2017-10-19 15:27:51 +0300 | [diff] [blame] | 333 | |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 334 | /* pop (ip, udp, vxlan) */ |
| 335 | vlib_buffer_advance (b[0], sizeof (*vxlan0)); |
| 336 | |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 337 | u32 fi0 = vlib_buffer_get_ip_fib_index (b[0], is_ip4); |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 338 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 339 | vxlan_decap_info_t di0 = is_ip4 ? |
| 340 | vxlan4_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan0, &stats_if0) : |
| 341 | vxlan6_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan0, &stats_if0); |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 342 | |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 343 | uword len0 = vlib_buffer_length_in_chain (vm, b[0]); |
| 344 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 345 | next[0] = di0.next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 346 | |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 347 | /* Validate VXLAN tunnel encap-fib index against packet */ |
| 348 | if (di0.error == 0) |
| 349 | { |
| 350 | /* Required to make the l2 tag push / pop code work on l2 subifs */ |
| 351 | vnet_update_l2_len (b[0]); |
| 352 | |
| 353 | /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */ |
| 354 | vnet_buffer (b[0])->sw_if_index[VLIB_RX] = di0.sw_if_index; |
| 355 | |
| 356 | vlib_increment_combined_counter (rx_counter, thread_index, |
| 357 | stats_if0, 1, len0); |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 358 | } |
| 359 | else |
| 360 | { |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 361 | b[0]->error = node->errors[di0.error]; |
| 362 | pkts_dropped++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 365 | if (PREDICT_FALSE (b[0]->flags & VLIB_BUFFER_IS_TRACED)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 366 | { |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 367 | vxlan_rx_trace_t *tr |
| 368 | = vlib_add_trace (vm, node, b[0], sizeof (*tr)); |
| 369 | tr->next_index = next[0]; |
Eyal Bari | efd9cf3 | 2018-10-02 12:23:06 +0300 | [diff] [blame] | 370 | tr->error = di0.error; |
| 371 | tr->tunnel_index = di0.sw_if_index == ~0 ? |
| 372 | ~0 : vxm->tunnel_index_by_sw_if_index[di0.sw_if_index]; |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 373 | tr->vni = vnet_get_vni (vxlan0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 374 | } |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 375 | b += 1; |
| 376 | next += 1; |
| 377 | n_left_from -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 378 | } |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 379 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, from_frame->n_vectors); |
Eyal Bari | fb66301 | 2017-10-19 15:27:51 +0300 | [diff] [blame] | 380 | /* Do we still need this now that tunnel tx stats is kept? */ |
| 381 | u32 node_idx = is_ip4 ? vxlan4_input_node.index : vxlan6_input_node.index; |
| 382 | vlib_node_increment_counter (vm, node_idx, VXLAN_ERROR_DECAPSULATED, |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 383 | from_frame->n_vectors - pkts_dropped); |
Eyal Bari | fb66301 | 2017-10-19 15:27:51 +0300 | [diff] [blame] | 384 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 385 | return from_frame->n_vectors; |
| 386 | } |
| 387 | |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 388 | VLIB_NODE_FN (vxlan4_input_node) (vlib_main_t * vm, |
| 389 | vlib_node_runtime_t * node, |
| 390 | vlib_frame_t * from_frame) |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 391 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 392 | return vxlan_input (vm, node, from_frame, /* is_ip4 */ 1); |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 393 | } |
| 394 | |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 395 | VLIB_NODE_FN (vxlan6_input_node) (vlib_main_t * vm, |
| 396 | vlib_node_runtime_t * node, |
| 397 | vlib_frame_t * from_frame) |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 398 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 399 | return vxlan_input (vm, node, from_frame, /* is_ip4 */ 0); |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 400 | } |
| 401 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 402 | static char *vxlan_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 403 | #define vxlan_error(n,s) s, |
| 404 | #include <vnet/vxlan/vxlan_error.def> |
| 405 | #undef vxlan_error |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 406 | }; |
| 407 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 408 | /* *INDENT-OFF* */ |
| 409 | VLIB_REGISTER_NODE (vxlan4_input_node) = |
| 410 | { |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 411 | .name = "vxlan4-input", |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 412 | .vector_size = sizeof (u32), |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 413 | .n_errors = VXLAN_N_ERROR, |
| 414 | .error_strings = vxlan_error_strings, |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 415 | .n_next_nodes = VXLAN_INPUT_N_NEXT, |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 416 | .format_trace = format_vxlan_rx_trace, |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 417 | .next_nodes = { |
| 418 | #define _(s,n) [VXLAN_INPUT_NEXT_##s] = n, |
| 419 | foreach_vxlan_input_next |
| 420 | #undef _ |
| 421 | }, |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 422 | }; |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 423 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 424 | VLIB_REGISTER_NODE (vxlan6_input_node) = |
| 425 | { |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 426 | .name = "vxlan6-input", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 427 | .vector_size = sizeof (u32), |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 428 | .n_errors = VXLAN_N_ERROR, |
| 429 | .error_strings = vxlan_error_strings, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 430 | .n_next_nodes = VXLAN_INPUT_N_NEXT, |
| 431 | .next_nodes = { |
| 432 | #define _(s,n) [VXLAN_INPUT_NEXT_##s] = n, |
| 433 | foreach_vxlan_input_next |
| 434 | #undef _ |
| 435 | }, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 436 | .format_trace = format_vxlan_rx_trace, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 437 | }; |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 438 | /* *INDENT-ON* */ |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 439 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 440 | typedef enum |
| 441 | { |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 442 | IP_VXLAN_BYPASS_NEXT_DROP, |
| 443 | IP_VXLAN_BYPASS_NEXT_VXLAN, |
| 444 | IP_VXLAN_BYPASS_N_NEXT, |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 445 | } ip_vxlan_bypass_next_t; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 446 | |
| 447 | always_inline uword |
| 448 | ip_vxlan_bypass_inline (vlib_main_t * vm, |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 449 | vlib_node_runtime_t * node, |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 450 | vlib_frame_t * frame, u32 is_ip4) |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 451 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 452 | vxlan_main_t *vxm = &vxlan_main; |
| 453 | u32 *from, *to_next, n_left_from, n_left_to_next, next_index; |
| 454 | vlib_node_runtime_t *error_node = |
| 455 | vlib_node_get_runtime (vm, ip4_input_node.index); |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 456 | vtep4_key_t last_vtep4; /* last IPv4 address / fib index |
| 457 | matching a local VTEP address */ |
| 458 | vtep6_key_t last_vtep6; /* last IPv6 address / fib index |
| 459 | matching a local VTEP address */ |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 460 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b = bufs; |
| 461 | |
| 462 | #ifdef CLIB_HAVE_VEC512 |
| 463 | vtep4_cache_t vtep4_u512; |
| 464 | clib_memset (&vtep4_u512, 0, sizeof (vtep4_u512)); |
| 465 | #endif |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 466 | |
| 467 | from = vlib_frame_vector_args (frame); |
| 468 | n_left_from = frame->n_vectors; |
| 469 | next_index = node->cached_next_index; |
| 470 | |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 471 | vlib_get_buffers (vm, from, bufs, n_left_from); |
| 472 | |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 473 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 474 | ip4_forward_next_trace (vm, node, frame, VLIB_TX); |
| 475 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 476 | if (is_ip4) |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 477 | vtep4_key_init (&last_vtep4); |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 478 | else |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 479 | vtep6_key_init (&last_vtep6); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 480 | |
| 481 | while (n_left_from > 0) |
| 482 | { |
| 483 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 484 | |
| 485 | while (n_left_from >= 4 && n_left_to_next >= 2) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 486 | { |
| 487 | vlib_buffer_t *b0, *b1; |
| 488 | ip4_header_t *ip40, *ip41; |
| 489 | ip6_header_t *ip60, *ip61; |
| 490 | udp_header_t *udp0, *udp1; |
| 491 | u32 bi0, ip_len0, udp_len0, flags0, next0; |
| 492 | u32 bi1, ip_len1, udp_len1, flags1, next1; |
| 493 | i32 len_diff0, len_diff1; |
| 494 | u8 error0, good_udp0, proto0; |
| 495 | u8 error1, good_udp1, proto1; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 496 | |
| 497 | /* Prefetch next iteration. */ |
| 498 | { |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 499 | vlib_prefetch_buffer_header (b[2], LOAD); |
| 500 | vlib_prefetch_buffer_header (b[3], LOAD); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 501 | |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 502 | CLIB_PREFETCH (b[2]->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 503 | CLIB_PREFETCH (b[3]->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 504 | } |
| 505 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 506 | bi0 = to_next[0] = from[0]; |
| 507 | bi1 = to_next[1] = from[1]; |
| 508 | from += 2; |
| 509 | n_left_from -= 2; |
| 510 | to_next += 2; |
| 511 | n_left_to_next -= 2; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 512 | |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 513 | b0 = b[0]; |
| 514 | b1 = b[1]; |
| 515 | b += 2; |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 516 | if (is_ip4) |
| 517 | { |
| 518 | ip40 = vlib_buffer_get_current (b0); |
| 519 | ip41 = vlib_buffer_get_current (b1); |
| 520 | } |
| 521 | else |
| 522 | { |
| 523 | ip60 = vlib_buffer_get_current (b0); |
| 524 | ip61 = vlib_buffer_get_current (b1); |
| 525 | } |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 526 | |
| 527 | /* Setup packet for next IP feature */ |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 528 | vnet_feature_next (&next0, b0); |
| 529 | vnet_feature_next (&next1, b1); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 530 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 531 | if (is_ip4) |
| 532 | { |
| 533 | /* Treat IP frag packets as "experimental" protocol for now |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 534 | until support of IP frag reassembly is implemented */ |
| 535 | proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol; |
| 536 | proto1 = ip4_is_fragment (ip41) ? 0xfe : ip41->protocol; |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 537 | } |
| 538 | else |
| 539 | { |
| 540 | proto0 = ip60->protocol; |
| 541 | proto1 = ip61->protocol; |
| 542 | } |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 543 | |
| 544 | /* Process packet 0 */ |
| 545 | if (proto0 != IP_PROTOCOL_UDP) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 546 | goto exit0; /* not UDP packet */ |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 547 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 548 | if (is_ip4) |
| 549 | udp0 = ip4_next_header (ip40); |
| 550 | else |
| 551 | udp0 = ip6_next_header (ip60); |
| 552 | |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 553 | if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan)) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 554 | goto exit0; /* not VXLAN packet */ |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 555 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 556 | /* Validate DIP against VTEPs */ |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 557 | if (is_ip4) |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 558 | { |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 559 | #ifdef CLIB_HAVE_VEC512 |
| 560 | if (!vtep4_check_vector |
| 561 | (&vxm->vtep_table, b0, ip40, &last_vtep4, &vtep4_u512)) |
| 562 | #else |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 563 | if (!vtep4_check (&vxm->vtep_table, b0, ip40, &last_vtep4)) |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 564 | #endif |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 565 | goto exit0; /* no local VTEP for VXLAN packet */ |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 566 | } |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 567 | else |
| 568 | { |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 569 | if (!vtep6_check (&vxm->vtep_table, b0, ip60, &last_vtep6)) |
| 570 | goto exit0; /* no local VTEP for VXLAN packet */ |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 571 | } |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 572 | |
| 573 | flags0 = b0->flags; |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 574 | good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 575 | |
| 576 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 577 | good_udp0 |= udp0->checksum == 0; |
| 578 | |
| 579 | /* Verify UDP length */ |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 580 | if (is_ip4) |
| 581 | ip_len0 = clib_net_to_host_u16 (ip40->length); |
| 582 | else |
| 583 | ip_len0 = clib_net_to_host_u16 (ip60->payload_length); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 584 | udp_len0 = clib_net_to_host_u16 (udp0->length); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 585 | len_diff0 = ip_len0 - udp_len0; |
| 586 | |
| 587 | /* Verify UDP checksum */ |
| 588 | if (PREDICT_FALSE (!good_udp0)) |
| 589 | { |
Zhiyong Yang | 47ea4c3 | 2020-06-10 13:23:50 +0000 | [diff] [blame] | 590 | if (is_ip4) |
| 591 | flags0 = ip4_tcp_udp_validate_checksum (vm, b0); |
| 592 | else |
| 593 | flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0); |
| 594 | good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 595 | } |
| 596 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 597 | if (is_ip4) |
| 598 | { |
| 599 | error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM; |
| 600 | error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH; |
| 601 | } |
| 602 | else |
| 603 | { |
| 604 | error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM; |
| 605 | error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH; |
| 606 | } |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 607 | |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 608 | next0 = error0 ? |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 609 | IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN; |
| 610 | b0->error = error0 ? error_node->errors[error0] : 0; |
| 611 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 612 | /* vxlan-input node expect current at VXLAN header */ |
| 613 | if (is_ip4) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 614 | vlib_buffer_advance (b0, |
| 615 | sizeof (ip4_header_t) + |
| 616 | sizeof (udp_header_t)); |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 617 | else |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 618 | vlib_buffer_advance (b0, |
| 619 | sizeof (ip6_header_t) + |
| 620 | sizeof (udp_header_t)); |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 621 | |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 622 | exit0: |
| 623 | /* Process packet 1 */ |
| 624 | if (proto1 != IP_PROTOCOL_UDP) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 625 | goto exit1; /* not UDP packet */ |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 626 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 627 | if (is_ip4) |
| 628 | udp1 = ip4_next_header (ip41); |
| 629 | else |
| 630 | udp1 = ip6_next_header (ip61); |
| 631 | |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 632 | if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan)) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 633 | goto exit1; /* not VXLAN packet */ |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 634 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 635 | /* Validate DIP against VTEPs */ |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 636 | if (is_ip4) |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 637 | { |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 638 | #ifdef CLIB_HAVE_VEC512 |
| 639 | if (!vtep4_check_vector |
| 640 | (&vxm->vtep_table, b1, ip41, &last_vtep4, &vtep4_u512)) |
| 641 | #else |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 642 | if (!vtep4_check (&vxm->vtep_table, b1, ip41, &last_vtep4)) |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 643 | #endif |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 644 | goto exit1; /* no local VTEP for VXLAN packet */ |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 645 | } |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 646 | else |
| 647 | { |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 648 | if (!vtep6_check (&vxm->vtep_table, b1, ip61, &last_vtep6)) |
| 649 | goto exit1; /* no local VTEP for VXLAN packet */ |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 650 | } |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 651 | |
| 652 | flags1 = b1->flags; |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 653 | good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 654 | |
| 655 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 656 | good_udp1 |= udp1->checksum == 0; |
| 657 | |
| 658 | /* Verify UDP length */ |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 659 | if (is_ip4) |
| 660 | ip_len1 = clib_net_to_host_u16 (ip41->length); |
| 661 | else |
| 662 | ip_len1 = clib_net_to_host_u16 (ip61->payload_length); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 663 | udp_len1 = clib_net_to_host_u16 (udp1->length); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 664 | len_diff1 = ip_len1 - udp_len1; |
| 665 | |
| 666 | /* Verify UDP checksum */ |
| 667 | if (PREDICT_FALSE (!good_udp1)) |
| 668 | { |
Zhiyong Yang | 47ea4c3 | 2020-06-10 13:23:50 +0000 | [diff] [blame] | 669 | if (is_ip4) |
| 670 | flags1 = ip4_tcp_udp_validate_checksum (vm, b1); |
| 671 | else |
| 672 | flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1); |
| 673 | good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 674 | } |
| 675 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 676 | if (is_ip4) |
| 677 | { |
| 678 | error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM; |
| 679 | error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH; |
| 680 | } |
| 681 | else |
| 682 | { |
Eyal Bari | a93ea42 | 2017-02-01 13:36:15 +0200 | [diff] [blame] | 683 | error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM; |
| 684 | error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH; |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 685 | } |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 686 | |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 687 | next1 = error1 ? |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 688 | IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN; |
| 689 | b1->error = error1 ? error_node->errors[error1] : 0; |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 690 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 691 | /* vxlan-input node expect current at VXLAN header */ |
| 692 | if (is_ip4) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 693 | vlib_buffer_advance (b1, |
| 694 | sizeof (ip4_header_t) + |
| 695 | sizeof (udp_header_t)); |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 696 | else |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 697 | vlib_buffer_advance (b1, |
| 698 | sizeof (ip6_header_t) + |
| 699 | sizeof (udp_header_t)); |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 700 | |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 701 | exit1: |
| 702 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 703 | to_next, n_left_to_next, |
| 704 | bi0, bi1, next0, next1); |
| 705 | } |
| 706 | |
| 707 | while (n_left_from > 0 && n_left_to_next > 0) |
| 708 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 709 | vlib_buffer_t *b0; |
| 710 | ip4_header_t *ip40; |
| 711 | ip6_header_t *ip60; |
| 712 | udp_header_t *udp0; |
| 713 | u32 bi0, ip_len0, udp_len0, flags0, next0; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 714 | i32 len_diff0; |
| 715 | u8 error0, good_udp0, proto0; |
| 716 | |
| 717 | bi0 = to_next[0] = from[0]; |
| 718 | from += 1; |
| 719 | n_left_from -= 1; |
| 720 | to_next += 1; |
| 721 | n_left_to_next -= 1; |
| 722 | |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 723 | b0 = b[0]; |
| 724 | b++; |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 725 | if (is_ip4) |
| 726 | ip40 = vlib_buffer_get_current (b0); |
| 727 | else |
| 728 | ip60 = vlib_buffer_get_current (b0); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 729 | |
| 730 | /* Setup packet for next IP feature */ |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 731 | vnet_feature_next (&next0, b0); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 732 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 733 | if (is_ip4) |
| 734 | /* Treat IP4 frag packets as "experimental" protocol for now |
| 735 | until support of IP frag reassembly is implemented */ |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 736 | proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol; |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 737 | else |
| 738 | proto0 = ip60->protocol; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 739 | |
| 740 | if (proto0 != IP_PROTOCOL_UDP) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 741 | goto exit; /* not UDP packet */ |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 742 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 743 | if (is_ip4) |
| 744 | udp0 = ip4_next_header (ip40); |
| 745 | else |
| 746 | udp0 = ip6_next_header (ip60); |
| 747 | |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 748 | if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan)) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 749 | goto exit; /* not VXLAN packet */ |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 750 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 751 | /* Validate DIP against VTEPs */ |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 752 | if (is_ip4) |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 753 | { |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 754 | #ifdef CLIB_HAVE_VEC512 |
| 755 | if (!vtep4_check_vector |
| 756 | (&vxm->vtep_table, b0, ip40, &last_vtep4, &vtep4_u512)) |
| 757 | #else |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 758 | if (!vtep4_check (&vxm->vtep_table, b0, ip40, &last_vtep4)) |
Zhiyong Yang | 5e52417 | 2020-07-08 20:28:36 +0000 | [diff] [blame] | 759 | #endif |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 760 | goto exit; /* no local VTEP for VXLAN packet */ |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 761 | } |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 762 | else |
| 763 | { |
Nick Zavaritsky | 27518c2 | 2020-02-27 15:54:58 +0000 | [diff] [blame] | 764 | if (!vtep6_check (&vxm->vtep_table, b0, ip60, &last_vtep6)) |
| 765 | goto exit; /* no local VTEP for VXLAN packet */ |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 766 | } |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 767 | |
| 768 | flags0 = b0->flags; |
Damjan Marion | 213b5aa | 2017-07-13 21:19:27 +0200 | [diff] [blame] | 769 | good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 770 | |
| 771 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 772 | good_udp0 |= udp0->checksum == 0; |
| 773 | |
| 774 | /* Verify UDP length */ |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 775 | if (is_ip4) |
| 776 | ip_len0 = clib_net_to_host_u16 (ip40->length); |
| 777 | else |
| 778 | ip_len0 = clib_net_to_host_u16 (ip60->payload_length); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 779 | udp_len0 = clib_net_to_host_u16 (udp0->length); |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 780 | len_diff0 = ip_len0 - udp_len0; |
| 781 | |
| 782 | /* Verify UDP checksum */ |
| 783 | if (PREDICT_FALSE (!good_udp0)) |
| 784 | { |
Zhiyong Yang | 47ea4c3 | 2020-06-10 13:23:50 +0000 | [diff] [blame] | 785 | if (is_ip4) |
| 786 | flags0 = ip4_tcp_udp_validate_checksum (vm, b0); |
| 787 | else |
| 788 | flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0); |
| 789 | good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 790 | } |
| 791 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 792 | if (is_ip4) |
| 793 | { |
| 794 | error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM; |
| 795 | error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH; |
| 796 | } |
| 797 | else |
| 798 | { |
| 799 | error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM; |
| 800 | error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH; |
| 801 | } |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 802 | |
Eyal Bari | 0f4b184 | 2018-04-12 12:39:51 +0300 | [diff] [blame] | 803 | next0 = error0 ? |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 804 | IP_VXLAN_BYPASS_NEXT_DROP : IP_VXLAN_BYPASS_NEXT_VXLAN; |
| 805 | b0->error = error0 ? error_node->errors[error0] : 0; |
| 806 | |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 807 | /* vxlan-input node expect current at VXLAN header */ |
| 808 | if (is_ip4) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 809 | vlib_buffer_advance (b0, |
| 810 | sizeof (ip4_header_t) + |
| 811 | sizeof (udp_header_t)); |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 812 | else |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 813 | vlib_buffer_advance (b0, |
| 814 | sizeof (ip6_header_t) + |
| 815 | sizeof (udp_header_t)); |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 816 | |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 817 | exit: |
| 818 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 819 | to_next, n_left_to_next, |
| 820 | bi0, next0); |
| 821 | } |
| 822 | |
| 823 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 824 | } |
| 825 | |
| 826 | return frame->n_vectors; |
| 827 | } |
| 828 | |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 829 | VLIB_NODE_FN (ip4_vxlan_bypass_node) (vlib_main_t * vm, |
| 830 | vlib_node_runtime_t * node, |
| 831 | vlib_frame_t * frame) |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 832 | { |
| 833 | return ip_vxlan_bypass_inline (vm, node, frame, /* is_ip4 */ 1); |
| 834 | } |
| 835 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 836 | /* *INDENT-OFF* */ |
| 837 | VLIB_REGISTER_NODE (ip4_vxlan_bypass_node) = |
| 838 | { |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 839 | .name = "ip4-vxlan-bypass", |
| 840 | .vector_size = sizeof (u32), |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 841 | .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT, |
| 842 | .next_nodes = { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 843 | [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop", |
| 844 | [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan4-input", |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 845 | }, |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 846 | .format_buffer = format_ip4_header, |
| 847 | .format_trace = format_ip4_forward_next_trace, |
| 848 | }; |
| 849 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 850 | /* *INDENT-ON* */ |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 851 | |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 852 | /* Dummy init function to get us linked in. */ |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 853 | static clib_error_t * |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 854 | ip4_vxlan_bypass_init (vlib_main_t * vm) |
| 855 | { |
| 856 | return 0; |
| 857 | } |
John Lo | 37682e1 | 2016-11-30 12:51:39 -0500 | [diff] [blame] | 858 | |
| 859 | VLIB_INIT_FUNCTION (ip4_vxlan_bypass_init); |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 860 | |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 861 | VLIB_NODE_FN (ip6_vxlan_bypass_node) (vlib_main_t * vm, |
| 862 | vlib_node_runtime_t * node, |
| 863 | vlib_frame_t * frame) |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 864 | { |
| 865 | return ip_vxlan_bypass_inline (vm, node, frame, /* is_ip4 */ 0); |
| 866 | } |
| 867 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 868 | /* *INDENT-OFF* */ |
| 869 | VLIB_REGISTER_NODE (ip6_vxlan_bypass_node) = |
| 870 | { |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 871 | .name = "ip6-vxlan-bypass", |
| 872 | .vector_size = sizeof (u32), |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 873 | .n_next_nodes = IP_VXLAN_BYPASS_N_NEXT, |
| 874 | .next_nodes = { |
| 875 | [IP_VXLAN_BYPASS_NEXT_DROP] = "error-drop", |
| 876 | [IP_VXLAN_BYPASS_NEXT_VXLAN] = "vxlan6-input", |
| 877 | }, |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 878 | .format_buffer = format_ip6_header, |
| 879 | .format_trace = format_ip6_forward_next_trace, |
| 880 | }; |
| 881 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 882 | /* *INDENT-ON* */ |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 883 | |
| 884 | /* Dummy init function to get us linked in. */ |
Eyal Bari | a5679e8 | 2018-08-26 15:20:07 +0300 | [diff] [blame] | 885 | static clib_error_t * |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 886 | ip6_vxlan_bypass_init (vlib_main_t * vm) |
| 887 | { |
| 888 | return 0; |
| 889 | } |
John Lo | 2b81eb8 | 2017-01-30 13:12:10 -0500 | [diff] [blame] | 890 | |
| 891 | VLIB_INIT_FUNCTION (ip6_vxlan_bypass_init); |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 892 | |
| 893 | #define foreach_vxlan_flow_input_next \ |
| 894 | _(DROP, "error-drop") \ |
| 895 | _(L2_INPUT, "l2-input") |
| 896 | |
| 897 | typedef enum |
| 898 | { |
| 899 | #define _(s,n) VXLAN_FLOW_NEXT_##s, |
| 900 | foreach_vxlan_flow_input_next |
| 901 | #undef _ |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 902 | VXLAN_FLOW_N_NEXT, |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 903 | } vxlan_flow_input_next_t; |
| 904 | |
| 905 | #define foreach_vxlan_flow_error \ |
| 906 | _(NONE, "no error") \ |
| 907 | _(IP_CHECKSUM_ERROR, "Rx ip checksum errors") \ |
| 908 | _(IP_HEADER_ERROR, "Rx ip header errors") \ |
| 909 | _(UDP_CHECKSUM_ERROR, "Rx udp checksum errors") \ |
| 910 | _(UDP_LENGTH_ERROR, "Rx udp length errors") |
| 911 | |
| 912 | typedef enum |
| 913 | { |
| 914 | #define _(f,s) VXLAN_FLOW_ERROR_##f, |
| 915 | foreach_vxlan_flow_error |
| 916 | #undef _ |
| 917 | VXLAN_FLOW_N_ERROR, |
| 918 | } vxlan_flow_error_t; |
| 919 | |
| 920 | static char *vxlan_flow_error_strings[] = { |
| 921 | #define _(n,s) s, |
| 922 | foreach_vxlan_flow_error |
| 923 | #undef _ |
| 924 | }; |
| 925 | |
| 926 | |
| 927 | static_always_inline u8 |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 928 | vxlan_validate_udp_csum (vlib_main_t * vm, vlib_buffer_t * b) |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 929 | { |
| 930 | u32 flags = b->flags; |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 931 | enum |
| 932 | { offset = |
| 933 | sizeof (ip4_header_t) + sizeof (udp_header_t) + sizeof (vxlan_header_t), |
| 934 | }; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 935 | |
| 936 | /* Verify UDP checksum */ |
| 937 | if ((flags & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 938 | { |
| 939 | vlib_buffer_advance (b, -offset); |
| 940 | flags = ip4_tcp_udp_validate_checksum (vm, b); |
| 941 | vlib_buffer_advance (b, offset); |
| 942 | } |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 943 | |
| 944 | return (flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
| 945 | } |
| 946 | |
| 947 | static_always_inline u8 |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 948 | vxlan_check_udp_csum (vlib_main_t * vm, vlib_buffer_t * b) |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 949 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 950 | ip4_vxlan_header_t *hdr = vlib_buffer_get_current (b) - sizeof *hdr; |
| 951 | udp_header_t *udp = &hdr->udp; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 952 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 953 | u8 good_csum = (b->flags & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0 || |
| 954 | udp->checksum == 0; |
| 955 | |
| 956 | return !good_csum; |
| 957 | } |
| 958 | |
| 959 | static_always_inline u8 |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 960 | vxlan_check_ip (vlib_buffer_t * b, u16 payload_len) |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 961 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 962 | ip4_vxlan_header_t *hdr = vlib_buffer_get_current (b) - sizeof *hdr; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 963 | u16 ip_len = clib_net_to_host_u16 (hdr->ip4.length); |
| 964 | u16 expected = payload_len + sizeof *hdr; |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 965 | return ip_len > expected || hdr->ip4.ttl == 0 |
| 966 | || hdr->ip4.ip_version_and_header_length != 0x45; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | static_always_inline u8 |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 970 | vxlan_check_ip_udp_len (vlib_buffer_t * b) |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 971 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 972 | ip4_vxlan_header_t *hdr = vlib_buffer_get_current (b) - sizeof *hdr; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 973 | u16 ip_len = clib_net_to_host_u16 (hdr->ip4.length); |
| 974 | u16 udp_len = clib_net_to_host_u16 (hdr->udp.length); |
| 975 | return udp_len > ip_len; |
| 976 | } |
| 977 | |
| 978 | static_always_inline u8 |
| 979 | vxlan_err_code (u8 ip_err0, u8 udp_err0, u8 csum_err0) |
| 980 | { |
| 981 | u8 error0 = VXLAN_FLOW_ERROR_NONE; |
| 982 | if (ip_err0) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 983 | error0 = VXLAN_FLOW_ERROR_IP_HEADER_ERROR; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 984 | if (udp_err0) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 985 | error0 = VXLAN_FLOW_ERROR_UDP_LENGTH_ERROR; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 986 | if (csum_err0) |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 987 | error0 = VXLAN_FLOW_ERROR_UDP_CHECKSUM_ERROR; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 988 | return error0; |
| 989 | } |
| 990 | |
Eyal Bari | 93a6f25 | 2018-06-14 08:57:39 +0300 | [diff] [blame] | 991 | VLIB_NODE_FN (vxlan4_flow_input_node) (vlib_main_t * vm, |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 992 | vlib_node_runtime_t * node, |
| 993 | vlib_frame_t * f) |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 994 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 995 | enum |
| 996 | { payload_offset = sizeof (ip4_vxlan_header_t) }; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 997 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 998 | vxlan_main_t *vxm = &vxlan_main; |
| 999 | vnet_interface_main_t *im = &vnet_main.interface_main; |
| 1000 | vlib_combined_counter_main_t *rx_counter[VXLAN_FLOW_N_NEXT] = { |
| 1001 | [VXLAN_FLOW_NEXT_DROP] = |
| 1002 | im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_DROP, |
| 1003 | [VXLAN_FLOW_NEXT_L2_INPUT] = |
| 1004 | im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX, |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 1005 | }; |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 1006 | u32 thread_index = vlib_get_thread_index (); |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 1007 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 1008 | u32 *from = vlib_frame_vector_args (f); |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 1009 | u32 n_left_from = f->n_vectors; |
| 1010 | u32 next_index = VXLAN_FLOW_NEXT_L2_INPUT; |
| 1011 | |
| 1012 | while (n_left_from > 0) |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 1013 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 1014 | u32 n_left_to_next, *to_next; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 1015 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 1016 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 1017 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 1018 | while (n_left_from > 3 && n_left_to_next > 3) |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 1019 | { |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 1020 | u32 bi0 = to_next[0] = from[0]; |
| 1021 | u32 bi1 = to_next[1] = from[1]; |
| 1022 | u32 bi2 = to_next[2] = from[2]; |
| 1023 | u32 bi3 = to_next[3] = from[3]; |
| 1024 | from += 4; |
| 1025 | n_left_from -= 4; |
| 1026 | to_next += 4; |
| 1027 | n_left_to_next -= 4; |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 1028 | |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 1029 | vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); |
| 1030 | vlib_buffer_t *b1 = vlib_get_buffer (vm, bi1); |
| 1031 | vlib_buffer_t *b2 = vlib_get_buffer (vm, bi2); |
| 1032 | vlib_buffer_t *b3 = vlib_get_buffer (vm, bi3); |
| 1033 | |
| 1034 | vlib_buffer_advance (b0, payload_offset); |
| 1035 | vlib_buffer_advance (b1, payload_offset); |
| 1036 | vlib_buffer_advance (b2, payload_offset); |
| 1037 | vlib_buffer_advance (b3, payload_offset); |
| 1038 | |
| 1039 | u16 len0 = vlib_buffer_length_in_chain (vm, b0); |
| 1040 | u16 len1 = vlib_buffer_length_in_chain (vm, b1); |
| 1041 | u16 len2 = vlib_buffer_length_in_chain (vm, b2); |
| 1042 | u16 len3 = vlib_buffer_length_in_chain (vm, b3); |
| 1043 | |
| 1044 | u32 next0 = VXLAN_FLOW_NEXT_L2_INPUT, next1 = |
| 1045 | VXLAN_FLOW_NEXT_L2_INPUT, next2 = |
| 1046 | VXLAN_FLOW_NEXT_L2_INPUT, next3 = VXLAN_FLOW_NEXT_L2_INPUT; |
| 1047 | |
| 1048 | u8 ip_err0 = vxlan_check_ip (b0, len0); |
| 1049 | u8 ip_err1 = vxlan_check_ip (b1, len1); |
| 1050 | u8 ip_err2 = vxlan_check_ip (b2, len2); |
| 1051 | u8 ip_err3 = vxlan_check_ip (b3, len3); |
| 1052 | u8 ip_err = ip_err0 | ip_err1 | ip_err2 | ip_err3; |
| 1053 | |
| 1054 | u8 udp_err0 = vxlan_check_ip_udp_len (b0); |
| 1055 | u8 udp_err1 = vxlan_check_ip_udp_len (b1); |
| 1056 | u8 udp_err2 = vxlan_check_ip_udp_len (b2); |
| 1057 | u8 udp_err3 = vxlan_check_ip_udp_len (b3); |
| 1058 | u8 udp_err = udp_err0 | udp_err1 | udp_err2 | udp_err3; |
| 1059 | |
| 1060 | u8 csum_err0 = vxlan_check_udp_csum (vm, b0); |
| 1061 | u8 csum_err1 = vxlan_check_udp_csum (vm, b1); |
| 1062 | u8 csum_err2 = vxlan_check_udp_csum (vm, b2); |
| 1063 | u8 csum_err3 = vxlan_check_udp_csum (vm, b3); |
| 1064 | u8 csum_err = csum_err0 | csum_err1 | csum_err2 | csum_err3; |
| 1065 | |
| 1066 | if (PREDICT_FALSE (csum_err)) |
| 1067 | { |
| 1068 | if (csum_err0) |
| 1069 | csum_err0 = !vxlan_validate_udp_csum (vm, b0); |
| 1070 | if (csum_err1) |
| 1071 | csum_err1 = !vxlan_validate_udp_csum (vm, b1); |
| 1072 | if (csum_err2) |
| 1073 | csum_err2 = !vxlan_validate_udp_csum (vm, b2); |
| 1074 | if (csum_err3) |
| 1075 | csum_err3 = !vxlan_validate_udp_csum (vm, b3); |
| 1076 | csum_err = csum_err0 | csum_err1 | csum_err2 | csum_err3; |
| 1077 | } |
| 1078 | |
| 1079 | if (PREDICT_FALSE (ip_err || udp_err || csum_err)) |
| 1080 | { |
| 1081 | if (ip_err0 || udp_err0 || csum_err0) |
| 1082 | { |
| 1083 | next0 = VXLAN_FLOW_NEXT_DROP; |
| 1084 | u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0); |
| 1085 | b0->error = node->errors[error0]; |
| 1086 | } |
| 1087 | if (ip_err1 || udp_err1 || csum_err1) |
| 1088 | { |
| 1089 | next1 = VXLAN_FLOW_NEXT_DROP; |
| 1090 | u8 error1 = vxlan_err_code (ip_err1, udp_err1, csum_err1); |
| 1091 | b1->error = node->errors[error1]; |
| 1092 | } |
| 1093 | if (ip_err2 || udp_err2 || csum_err2) |
| 1094 | { |
| 1095 | next2 = VXLAN_FLOW_NEXT_DROP; |
| 1096 | u8 error2 = vxlan_err_code (ip_err2, udp_err2, csum_err2); |
| 1097 | b2->error = node->errors[error2]; |
| 1098 | } |
| 1099 | if (ip_err3 || udp_err3 || csum_err3) |
| 1100 | { |
| 1101 | next3 = VXLAN_FLOW_NEXT_DROP; |
| 1102 | u8 error3 = vxlan_err_code (ip_err3, udp_err3, csum_err3); |
| 1103 | b3->error = node->errors[error3]; |
| 1104 | } |
| 1105 | } |
| 1106 | |
| 1107 | vnet_update_l2_len (b0); |
| 1108 | vnet_update_l2_len (b1); |
| 1109 | vnet_update_l2_len (b2); |
| 1110 | vnet_update_l2_len (b3); |
| 1111 | |
| 1112 | ASSERT (b0->flow_id != 0); |
| 1113 | ASSERT (b1->flow_id != 0); |
| 1114 | ASSERT (b2->flow_id != 0); |
| 1115 | ASSERT (b3->flow_id != 0); |
| 1116 | |
| 1117 | u32 t_index0 = b0->flow_id - vxm->flow_id_start; |
| 1118 | u32 t_index1 = b1->flow_id - vxm->flow_id_start; |
| 1119 | u32 t_index2 = b2->flow_id - vxm->flow_id_start; |
| 1120 | u32 t_index3 = b3->flow_id - vxm->flow_id_start; |
| 1121 | |
| 1122 | vxlan_tunnel_t *t0 = &vxm->tunnels[t_index0]; |
| 1123 | vxlan_tunnel_t *t1 = &vxm->tunnels[t_index1]; |
| 1124 | vxlan_tunnel_t *t2 = &vxm->tunnels[t_index2]; |
| 1125 | vxlan_tunnel_t *t3 = &vxm->tunnels[t_index3]; |
| 1126 | |
| 1127 | /* flow id consumed */ |
| 1128 | b0->flow_id = 0; |
| 1129 | b1->flow_id = 0; |
| 1130 | b2->flow_id = 0; |
| 1131 | b3->flow_id = 0; |
| 1132 | |
| 1133 | u32 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX] = |
| 1134 | t0->sw_if_index; |
| 1135 | u32 sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX] = |
| 1136 | t1->sw_if_index; |
| 1137 | u32 sw_if_index2 = vnet_buffer (b2)->sw_if_index[VLIB_RX] = |
| 1138 | t2->sw_if_index; |
| 1139 | u32 sw_if_index3 = vnet_buffer (b3)->sw_if_index[VLIB_RX] = |
| 1140 | t3->sw_if_index; |
| 1141 | |
| 1142 | vlib_increment_combined_counter (rx_counter[next0], thread_index, |
| 1143 | sw_if_index0, 1, len0); |
| 1144 | vlib_increment_combined_counter (rx_counter[next1], thread_index, |
| 1145 | sw_if_index1, 1, len1); |
| 1146 | vlib_increment_combined_counter (rx_counter[next2], thread_index, |
| 1147 | sw_if_index2, 1, len2); |
| 1148 | vlib_increment_combined_counter (rx_counter[next3], thread_index, |
| 1149 | sw_if_index3, 1, len3); |
| 1150 | |
| 1151 | u32 flags = b0->flags | b1->flags | b2->flags | b3->flags; |
| 1152 | |
| 1153 | if (PREDICT_FALSE (flags & VLIB_BUFFER_IS_TRACED)) |
| 1154 | { |
| 1155 | if (b0->flags & VLIB_BUFFER_IS_TRACED) |
| 1156 | { |
| 1157 | vxlan_rx_trace_t *tr = |
| 1158 | vlib_add_trace (vm, node, b0, sizeof *tr); |
| 1159 | u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0); |
| 1160 | tr->next_index = next0; |
| 1161 | tr->error = error0; |
| 1162 | tr->tunnel_index = t_index0; |
| 1163 | tr->vni = t0->vni; |
| 1164 | } |
| 1165 | if (b1->flags & VLIB_BUFFER_IS_TRACED) |
| 1166 | { |
| 1167 | vxlan_rx_trace_t *tr = |
| 1168 | vlib_add_trace (vm, node, b1, sizeof *tr); |
| 1169 | u8 error1 = vxlan_err_code (ip_err1, udp_err1, csum_err1); |
| 1170 | tr->next_index = next1; |
| 1171 | tr->error = error1; |
| 1172 | tr->tunnel_index = t_index1; |
| 1173 | tr->vni = t1->vni; |
| 1174 | } |
| 1175 | if (b2->flags & VLIB_BUFFER_IS_TRACED) |
| 1176 | { |
| 1177 | vxlan_rx_trace_t *tr = |
| 1178 | vlib_add_trace (vm, node, b2, sizeof *tr); |
| 1179 | u8 error2 = vxlan_err_code (ip_err2, udp_err2, csum_err2); |
| 1180 | tr->next_index = next2; |
| 1181 | tr->error = error2; |
| 1182 | tr->tunnel_index = t_index2; |
| 1183 | tr->vni = t2->vni; |
| 1184 | } |
| 1185 | if (b3->flags & VLIB_BUFFER_IS_TRACED) |
| 1186 | { |
| 1187 | vxlan_rx_trace_t *tr = |
| 1188 | vlib_add_trace (vm, node, b3, sizeof *tr); |
| 1189 | u8 error3 = vxlan_err_code (ip_err3, udp_err3, csum_err3); |
| 1190 | tr->next_index = next3; |
| 1191 | tr->error = error3; |
| 1192 | tr->tunnel_index = t_index3; |
| 1193 | tr->vni = t3->vni; |
| 1194 | } |
| 1195 | } |
| 1196 | vlib_validate_buffer_enqueue_x4 |
| 1197 | (vm, node, next_index, to_next, n_left_to_next, |
| 1198 | bi0, bi1, bi2, bi3, next0, next1, next2, next3); |
| 1199 | } |
| 1200 | while (n_left_from > 0 && n_left_to_next > 0) |
| 1201 | { |
| 1202 | u32 bi0 = to_next[0] = from[0]; |
| 1203 | from++; |
| 1204 | n_left_from--; |
| 1205 | to_next++; |
| 1206 | n_left_to_next--; |
| 1207 | |
| 1208 | vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); |
| 1209 | vlib_buffer_advance (b0, payload_offset); |
| 1210 | |
| 1211 | u16 len0 = vlib_buffer_length_in_chain (vm, b0); |
| 1212 | u32 next0 = VXLAN_FLOW_NEXT_L2_INPUT; |
| 1213 | |
| 1214 | u8 ip_err0 = vxlan_check_ip (b0, len0); |
| 1215 | u8 udp_err0 = vxlan_check_ip_udp_len (b0); |
| 1216 | u8 csum_err0 = vxlan_check_udp_csum (vm, b0); |
| 1217 | |
| 1218 | if (csum_err0) |
| 1219 | csum_err0 = !vxlan_validate_udp_csum (vm, b0); |
| 1220 | if (ip_err0 || udp_err0 || csum_err0) |
| 1221 | { |
| 1222 | next0 = VXLAN_FLOW_NEXT_DROP; |
| 1223 | u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0); |
| 1224 | b0->error = node->errors[error0]; |
| 1225 | } |
| 1226 | |
| 1227 | vnet_update_l2_len (b0); |
| 1228 | |
| 1229 | ASSERT (b0->flow_id != 0); |
| 1230 | u32 t_index0 = b0->flow_id - vxm->flow_id_start; |
| 1231 | vxlan_tunnel_t *t0 = &vxm->tunnels[t_index0]; |
| 1232 | b0->flow_id = 0; |
| 1233 | |
| 1234 | u32 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX] = |
| 1235 | t0->sw_if_index; |
| 1236 | vlib_increment_combined_counter (rx_counter[next0], thread_index, |
| 1237 | sw_if_index0, 1, len0); |
| 1238 | |
| 1239 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 1240 | { |
| 1241 | vxlan_rx_trace_t *tr = |
| 1242 | vlib_add_trace (vm, node, b0, sizeof *tr); |
| 1243 | u8 error0 = vxlan_err_code (ip_err0, udp_err0, csum_err0); |
| 1244 | tr->next_index = next0; |
| 1245 | tr->error = error0; |
| 1246 | tr->tunnel_index = t_index0; |
| 1247 | tr->vni = t0->vni; |
| 1248 | } |
| 1249 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 1250 | to_next, n_left_to_next, |
| 1251 | bi0, next0); |
| 1252 | } |
| 1253 | |
| 1254 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 1255 | } |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 1256 | |
| 1257 | return f->n_vectors; |
| 1258 | } |
| 1259 | |
| 1260 | /* *INDENT-OFF* */ |
| 1261 | #ifndef CLIB_MULTIARCH_VARIANT |
| 1262 | VLIB_REGISTER_NODE (vxlan4_flow_input_node) = { |
| 1263 | .name = "vxlan-flow-input", |
eyal bari | af86a48 | 2018-04-17 11:20:27 +0300 | [diff] [blame] | 1264 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 1265 | .vector_size = sizeof (u32), |
| 1266 | |
| 1267 | .format_trace = format_vxlan_rx_trace, |
| 1268 | |
| 1269 | .n_errors = VXLAN_FLOW_N_ERROR, |
| 1270 | .error_strings = vxlan_flow_error_strings, |
| 1271 | |
| 1272 | .n_next_nodes = VXLAN_FLOW_N_NEXT, |
| 1273 | .next_nodes = { |
| 1274 | #define _(s,n) [VXLAN_FLOW_NEXT_##s] = n, |
| 1275 | foreach_vxlan_flow_input_next |
| 1276 | #undef _ |
| 1277 | }, |
| 1278 | }; |
| 1279 | #endif |
| 1280 | /* *INDENT-ON* */ |
Eyal Bari | 7d92c09 | 2018-07-24 15:15:37 +0300 | [diff] [blame] | 1281 | |
| 1282 | /* |
| 1283 | * fd.io coding-style-patch-verification: ON |
| 1284 | * |
| 1285 | * Local Variables: |
| 1286 | * eval: (c-set-style "gnu") |
| 1287 | * End: |
| 1288 | */ |