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