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