Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1 | /* |
| 2 | * decap.c: vxlan gbp tunnel decap packet processing |
| 3 | * |
| 4 | * Copyright (c) 2018 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> |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame^] | 19 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 20 | #include <vnet/vxlan-gbp/vxlan_gbp.h> |
| 21 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 22 | typedef struct |
| 23 | { |
| 24 | u32 next_index; |
| 25 | u32 tunnel_index; |
| 26 | u32 error; |
| 27 | u32 vni; |
| 28 | u16 sclass; |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 29 | u8 flags; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 30 | } vxlan_gbp_rx_trace_t; |
| 31 | |
| 32 | static u8 * |
| 33 | format_vxlan_gbp_rx_trace (u8 * s, va_list * args) |
| 34 | { |
| 35 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 36 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 37 | vxlan_gbp_rx_trace_t *t = va_arg (*args, vxlan_gbp_rx_trace_t *); |
| 38 | |
| 39 | if (t->tunnel_index == ~0) |
| 40 | return format (s, |
| 41 | "VXLAN_GBP decap error - tunnel for vni %d does not exist", |
| 42 | t->vni); |
| 43 | return format (s, |
| 44 | "VXLAN_GBP decap from vxlan_gbp_tunnel%d vni %d sclass %d" |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 45 | " flags %U next %d error %d", |
| 46 | t->tunnel_index, t->vni, t->sclass, |
| 47 | format_vxlan_gbp_header_gpflags, t->flags, |
| 48 | t->next_index, t->error); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | always_inline u32 |
| 52 | buf_fib_index (vlib_buffer_t * b, u32 is_ip4) |
| 53 | { |
| 54 | u32 sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_TX]; |
| 55 | if (sw_if_index != (u32) ~ 0) |
| 56 | return sw_if_index; |
| 57 | |
| 58 | u32 *fib_index_by_sw_if_index = is_ip4 ? |
| 59 | ip4_main.fib_index_by_sw_if_index : ip6_main.fib_index_by_sw_if_index; |
| 60 | sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX]; |
| 61 | |
| 62 | return vec_elt (fib_index_by_sw_if_index, sw_if_index); |
| 63 | } |
| 64 | |
| 65 | typedef vxlan4_gbp_tunnel_key_t last_tunnel_cache4; |
| 66 | |
| 67 | always_inline vxlan_gbp_tunnel_t * |
| 68 | vxlan4_gbp_find_tunnel (vxlan_gbp_main_t * vxm, last_tunnel_cache4 * cache, |
| 69 | u32 fib_index, ip4_header_t * ip4_0, |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 70 | vxlan_gbp_header_t * vxlan_gbp0) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 71 | { |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 72 | /* |
| 73 | * Check unicast first since that's where most of the traffic comes from |
| 74 | * Make sure VXLAN_GBP tunnel exist according to packet SIP, DIP and VNI |
| 75 | */ |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 76 | vxlan4_gbp_tunnel_key_t key4; |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 77 | int rv; |
| 78 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 79 | key4.key[1] = ((u64) fib_index << 32) | vxlan_gbp0->vni_reserved; |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 80 | key4.key[0] = (((u64) ip4_0->dst_address.as_u32 << 32) | |
| 81 | ip4_0->src_address.as_u32); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 82 | |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 83 | if (PREDICT_FALSE (key4.key[0] != cache->key[0] || |
| 84 | key4.key[1] != cache->key[1])) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 85 | { |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 86 | rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_gbp_tunnel_by_key, |
| 87 | &key4); |
| 88 | if (PREDICT_FALSE (rv == 0)) |
| 89 | { |
| 90 | *cache = key4; |
| 91 | return (pool_elt_at_index (vxm->tunnels, cache->value)); |
| 92 | } |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 93 | } |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 94 | else |
| 95 | { |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 96 | return (pool_elt_at_index (vxm->tunnels, cache->value)); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 97 | } |
| 98 | |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 99 | /* No unicast match - try multicast */ |
| 100 | if (PREDICT_TRUE (!ip4_address_is_multicast (&ip4_0->dst_address))) |
| 101 | return (NULL); |
| 102 | |
| 103 | key4.key[0] = ip4_0->dst_address.as_u32; |
| 104 | /* Make sure mcast VXLAN_GBP tunnel exist by packet DIP and VNI */ |
| 105 | rv = clib_bihash_search_inline_16_8 (&vxm->vxlan4_gbp_tunnel_by_key, &key4); |
| 106 | |
| 107 | if (PREDICT_FALSE (rv != 0)) |
| 108 | return (NULL); |
| 109 | |
| 110 | return (pool_elt_at_index (vxm->tunnels, key4.value)); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | typedef vxlan6_gbp_tunnel_key_t last_tunnel_cache6; |
| 114 | |
| 115 | always_inline vxlan_gbp_tunnel_t * |
| 116 | vxlan6_gbp_find_tunnel (vxlan_gbp_main_t * vxm, last_tunnel_cache6 * cache, |
| 117 | u32 fib_index, ip6_header_t * ip6_0, |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 118 | vxlan_gbp_header_t * vxlan_gbp0) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 119 | { |
| 120 | /* Make sure VXLAN_GBP tunnel exist according to packet SIP and VNI */ |
| 121 | vxlan6_gbp_tunnel_key_t key6 = { |
| 122 | .key = { |
| 123 | [0] = ip6_0->src_address.as_u64[0], |
| 124 | [1] = ip6_0->src_address.as_u64[1], |
| 125 | [2] = (((u64) fib_index) << 32) | vxlan_gbp0->vni_reserved, |
| 126 | } |
| 127 | }; |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 128 | int rv; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 129 | |
| 130 | if (PREDICT_FALSE |
| 131 | (clib_bihash_key_compare_24_8 (key6.key, cache->key) == 0)) |
| 132 | { |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 133 | rv = clib_bihash_search_inline_24_8 (&vxm->vxlan6_gbp_tunnel_by_key, |
| 134 | &key6); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 135 | if (PREDICT_FALSE (rv != 0)) |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 136 | return NULL; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 137 | |
| 138 | *cache = key6; |
| 139 | } |
| 140 | vxlan_gbp_tunnel_t *t0 = pool_elt_at_index (vxm->tunnels, cache->value); |
| 141 | |
| 142 | /* Validate VXLAN_GBP tunnel SIP against packet DIP */ |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 143 | if (PREDICT_FALSE |
| 144 | (!ip6_address_is_equal (&ip6_0->dst_address, &t0->src.ip6))) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 145 | { |
| 146 | /* try multicast */ |
| 147 | if (PREDICT_TRUE (!ip6_address_is_multicast (&ip6_0->dst_address))) |
| 148 | return 0; |
| 149 | |
| 150 | /* Make sure mcast VXLAN_GBP tunnel exist by packet DIP and VNI */ |
| 151 | key6.key[0] = ip6_0->dst_address.as_u64[0]; |
| 152 | key6.key[1] = ip6_0->dst_address.as_u64[1]; |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 153 | rv = clib_bihash_search_inline_24_8 (&vxm->vxlan6_gbp_tunnel_by_key, |
| 154 | &key6); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 155 | if (PREDICT_FALSE (rv != 0)) |
| 156 | return 0; |
| 157 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | return t0; |
| 161 | } |
| 162 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 163 | always_inline vxlan_gbp_input_next_t |
| 164 | vxlan_gbp_tunnel_get_next (const vxlan_gbp_tunnel_t * t, vlib_buffer_t * b0) |
| 165 | { |
| 166 | if (VXLAN_GBP_TUNNEL_MODE_L2 == t->mode) |
| 167 | return (VXLAN_GBP_INPUT_NEXT_L2_INPUT); |
| 168 | else |
| 169 | { |
| 170 | ethernet_header_t *e0; |
| 171 | u16 type0; |
| 172 | |
| 173 | e0 = vlib_buffer_get_current (b0); |
| 174 | vlib_buffer_advance (b0, sizeof (*e0)); |
| 175 | type0 = clib_net_to_host_u16 (e0->type); |
| 176 | switch (type0) |
| 177 | { |
| 178 | case ETHERNET_TYPE_IP4: |
| 179 | return (VXLAN_GBP_INPUT_NEXT_IP4_INPUT); |
| 180 | case ETHERNET_TYPE_IP6: |
| 181 | return (VXLAN_GBP_INPUT_NEXT_IP6_INPUT); |
| 182 | } |
| 183 | } |
| 184 | return (VXLAN_GBP_INPUT_NEXT_DROP); |
| 185 | } |
| 186 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 187 | always_inline uword |
| 188 | vxlan_gbp_input (vlib_main_t * vm, |
| 189 | vlib_node_runtime_t * node, |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 190 | vlib_frame_t * from_frame, u8 is_ip4) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 191 | { |
| 192 | vxlan_gbp_main_t *vxm = &vxlan_gbp_main; |
| 193 | vnet_main_t *vnm = vxm->vnet_main; |
| 194 | vnet_interface_main_t *im = &vnm->interface_main; |
| 195 | vlib_combined_counter_main_t *rx_counter = |
| 196 | im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX; |
| 197 | vlib_combined_counter_main_t *drop_counter = |
| 198 | im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_DROP; |
| 199 | last_tunnel_cache4 last4; |
| 200 | last_tunnel_cache6 last6; |
| 201 | u32 pkts_decapsulated = 0; |
| 202 | u32 thread_index = vlib_get_thread_index (); |
| 203 | |
| 204 | if (is_ip4) |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 205 | clib_memset (&last4, 0xff, sizeof last4); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 206 | else |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 207 | clib_memset (&last6, 0xff, sizeof last6); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 208 | |
| 209 | u32 next_index = node->cached_next_index; |
| 210 | |
| 211 | u32 *from = vlib_frame_vector_args (from_frame); |
| 212 | u32 n_left_from = from_frame->n_vectors; |
| 213 | |
| 214 | while (n_left_from > 0) |
| 215 | { |
| 216 | u32 *to_next, n_left_to_next; |
| 217 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 218 | |
| 219 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 220 | { |
| 221 | /* Prefetch next iteration. */ |
| 222 | { |
| 223 | vlib_buffer_t *p2, *p3; |
| 224 | |
| 225 | p2 = vlib_get_buffer (vm, from[2]); |
| 226 | p3 = vlib_get_buffer (vm, from[3]); |
| 227 | |
| 228 | vlib_prefetch_buffer_header (p2, LOAD); |
| 229 | vlib_prefetch_buffer_header (p3, LOAD); |
| 230 | |
| 231 | CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 232 | CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 233 | } |
| 234 | |
| 235 | u32 bi0 = to_next[0] = from[0]; |
| 236 | u32 bi1 = to_next[1] = from[1]; |
| 237 | from += 2; |
| 238 | to_next += 2; |
| 239 | n_left_to_next -= 2; |
| 240 | n_left_from -= 2; |
| 241 | |
| 242 | vlib_buffer_t *b0, *b1; |
| 243 | b0 = vlib_get_buffer (vm, bi0); |
| 244 | b1 = vlib_get_buffer (vm, bi1); |
| 245 | |
| 246 | /* udp leaves current_data pointing at the vxlan_gbp header */ |
| 247 | void *cur0 = vlib_buffer_get_current (b0); |
| 248 | void *cur1 = vlib_buffer_get_current (b1); |
| 249 | vxlan_gbp_header_t *vxlan_gbp0 = cur0; |
| 250 | vxlan_gbp_header_t *vxlan_gbp1 = cur1; |
| 251 | |
| 252 | ip4_header_t *ip4_0, *ip4_1; |
| 253 | ip6_header_t *ip6_0, *ip6_1; |
| 254 | if (is_ip4) |
| 255 | { |
| 256 | ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t); |
| 257 | ip4_1 = cur1 - sizeof (udp_header_t) - sizeof (ip4_header_t); |
| 258 | } |
| 259 | else |
| 260 | { |
| 261 | ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t); |
| 262 | ip6_1 = cur1 - sizeof (udp_header_t) - sizeof (ip6_header_t); |
| 263 | } |
| 264 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 265 | u32 fi0 = buf_fib_index (b0, is_ip4); |
| 266 | u32 fi1 = buf_fib_index (b1, is_ip4); |
| 267 | |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 268 | vxlan_gbp_tunnel_t *t0, *t1; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 269 | if (is_ip4) |
| 270 | { |
| 271 | t0 = |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 272 | vxlan4_gbp_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan_gbp0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 273 | t1 = |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 274 | vxlan4_gbp_find_tunnel (vxm, &last4, fi1, ip4_1, vxlan_gbp1); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 275 | } |
| 276 | else |
| 277 | { |
| 278 | t0 = |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 279 | vxlan6_gbp_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan_gbp0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 280 | t1 = |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 281 | vxlan6_gbp_find_tunnel (vxm, &last6, fi1, ip6_1, vxlan_gbp1); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | u32 len0 = vlib_buffer_length_in_chain (vm, b0); |
| 285 | u32 len1 = vlib_buffer_length_in_chain (vm, b1); |
| 286 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 287 | vxlan_gbp_input_next_t next0, next1; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 288 | u8 error0 = 0, error1 = 0; |
| 289 | u8 flags0 = vxlan_gbp_get_flags (vxlan_gbp0); |
| 290 | u8 flags1 = vxlan_gbp_get_flags (vxlan_gbp1); |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 291 | /* Required to make the l2 tag push / pop code work on l2 subifs */ |
| 292 | /* pop vxlan_gbp */ |
| 293 | vlib_buffer_advance (b0, sizeof *vxlan_gbp0); |
| 294 | vlib_buffer_advance (b1, sizeof *vxlan_gbp1); |
| 295 | |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 296 | /* Validate VXLAN_GBP tunnel encap-fib index against packet */ |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 297 | if (PREDICT_FALSE |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 298 | (t0 == NULL |
| 299 | || flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G))) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 300 | { |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 301 | if (t0 != NULL |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 302 | && flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G)) |
| 303 | { |
| 304 | error0 = VXLAN_GBP_ERROR_BAD_FLAGS; |
| 305 | vlib_increment_combined_counter |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 306 | (drop_counter, thread_index, t0->sw_if_index, 1, len0); |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 307 | next0 = VXLAN_GBP_INPUT_NEXT_DROP; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 308 | } |
| 309 | else |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 310 | { |
| 311 | error0 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL; |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame^] | 312 | next0 = VXLAN_GBP_INPUT_NEXT_PUNT; |
| 313 | if (is_ip4) |
| 314 | b0->punt_reason = |
| 315 | vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP4]; |
| 316 | else |
| 317 | b0->punt_reason = |
| 318 | vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP6]; |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 319 | } |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 320 | b0->error = node->errors[error0]; |
| 321 | } |
| 322 | else |
| 323 | { |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 324 | next0 = vxlan_gbp_tunnel_get_next (t0, b0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 325 | |
| 326 | /* Set packet input sw_if_index to unicast VXLAN tunnel for learning */ |
| 327 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index; |
| 328 | vlib_increment_combined_counter |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 329 | (rx_counter, thread_index, t0->sw_if_index, 1, len0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 330 | pkts_decapsulated++; |
| 331 | } |
| 332 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 333 | vnet_buffer2 (b0)->gbp.flags = vxlan_gbp_get_gpflags (vxlan_gbp0); |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 334 | vnet_buffer2 (b0)->gbp.sclass = vxlan_gbp_get_sclass (vxlan_gbp0); |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 335 | |
| 336 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 337 | if (PREDICT_FALSE |
| 338 | (t1 == 0 || flags1 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G))) |
| 339 | { |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 340 | if (t1 != 0 |
| 341 | && flags1 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G)) |
| 342 | { |
| 343 | error1 = VXLAN_GBP_ERROR_BAD_FLAGS; |
| 344 | vlib_increment_combined_counter |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 345 | (drop_counter, thread_index, t1->sw_if_index, 1, len1); |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 346 | next1 = VXLAN_GBP_INPUT_NEXT_DROP; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 347 | } |
| 348 | else |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 349 | { |
| 350 | error1 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL; |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame^] | 351 | next1 = VXLAN_GBP_INPUT_NEXT_PUNT; |
| 352 | if (is_ip4) |
| 353 | b1->punt_reason = |
| 354 | vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP4]; |
| 355 | else |
| 356 | b1->punt_reason = |
| 357 | vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP6]; |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 358 | } |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 359 | b1->error = node->errors[error1]; |
| 360 | } |
| 361 | else |
| 362 | { |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 363 | next1 = vxlan_gbp_tunnel_get_next (t1, b1); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 364 | |
| 365 | /* Set packet input sw_if_index to unicast VXLAN_GBP tunnel for learning */ |
| 366 | vnet_buffer (b1)->sw_if_index[VLIB_RX] = t1->sw_if_index; |
| 367 | pkts_decapsulated++; |
| 368 | |
| 369 | vlib_increment_combined_counter |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 370 | (rx_counter, thread_index, t1->sw_if_index, 1, len1); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 371 | } |
| 372 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 373 | vnet_buffer2 (b1)->gbp.flags = vxlan_gbp_get_gpflags (vxlan_gbp1); |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 374 | vnet_buffer2 (b1)->gbp.sclass = vxlan_gbp_get_sclass (vxlan_gbp1); |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 375 | |
| 376 | vnet_update_l2_len (b0); |
| 377 | vnet_update_l2_len (b1); |
| 378 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 379 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 380 | { |
| 381 | vxlan_gbp_rx_trace_t *tr = |
| 382 | vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 383 | tr->next_index = next0; |
| 384 | tr->error = error0; |
| 385 | tr->tunnel_index = t0 == 0 ? ~0 : t0 - vxm->tunnels; |
| 386 | tr->vni = vxlan_gbp_get_vni (vxlan_gbp0); |
| 387 | tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp0); |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 388 | tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 389 | } |
| 390 | if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) |
| 391 | { |
| 392 | vxlan_gbp_rx_trace_t *tr = |
| 393 | vlib_add_trace (vm, node, b1, sizeof (*tr)); |
| 394 | tr->next_index = next1; |
| 395 | tr->error = error1; |
| 396 | tr->tunnel_index = t1 == 0 ? ~0 : t1 - vxm->tunnels; |
| 397 | tr->vni = vxlan_gbp_get_vni (vxlan_gbp1); |
| 398 | tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp1); |
Neale Ranns | 5ecbbc1 | 2018-11-14 08:18:12 -0800 | [diff] [blame] | 399 | tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp1); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 403 | to_next, n_left_to_next, |
| 404 | bi0, bi1, next0, next1); |
| 405 | } |
| 406 | |
| 407 | while (n_left_from > 0 && n_left_to_next > 0) |
| 408 | { |
| 409 | u32 bi0 = to_next[0] = from[0]; |
| 410 | from += 1; |
| 411 | to_next += 1; |
| 412 | n_left_from -= 1; |
| 413 | n_left_to_next -= 1; |
| 414 | |
| 415 | vlib_buffer_t *b0 = vlib_get_buffer (vm, bi0); |
| 416 | |
| 417 | /* udp leaves current_data pointing at the vxlan_gbp header */ |
| 418 | void *cur0 = vlib_buffer_get_current (b0); |
| 419 | vxlan_gbp_header_t *vxlan_gbp0 = cur0; |
| 420 | ip4_header_t *ip4_0; |
| 421 | ip6_header_t *ip6_0; |
| 422 | if (is_ip4) |
| 423 | ip4_0 = cur0 - sizeof (udp_header_t) - sizeof (ip4_header_t); |
| 424 | else |
| 425 | ip6_0 = cur0 - sizeof (udp_header_t) - sizeof (ip6_header_t); |
| 426 | |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 427 | u32 fi0 = buf_fib_index (b0, is_ip4); |
| 428 | |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 429 | vxlan_gbp_tunnel_t *t0; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 430 | if (is_ip4) |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 431 | t0 = vxlan4_gbp_find_tunnel (vxm, &last4, fi0, ip4_0, vxlan_gbp0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 432 | else |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 433 | t0 = vxlan6_gbp_find_tunnel (vxm, &last6, fi0, ip6_0, vxlan_gbp0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 434 | |
| 435 | uword len0 = vlib_buffer_length_in_chain (vm, b0); |
| 436 | |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 437 | vxlan_gbp_input_next_t next0; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 438 | u8 error0 = 0; |
| 439 | u8 flags0 = vxlan_gbp_get_flags (vxlan_gbp0); |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 440 | |
| 441 | /* pop (ip, udp, vxlan_gbp) */ |
| 442 | vlib_buffer_advance (b0, sizeof (*vxlan_gbp0)); |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 443 | /* Validate VXLAN_GBP tunnel encap-fib index against packet */ |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 444 | if (PREDICT_FALSE |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 445 | (t0 == NULL |
| 446 | || flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G))) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 447 | { |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 448 | if (t0 != NULL |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 449 | && flags0 != (VXLAN_GBP_FLAGS_I | VXLAN_GBP_FLAGS_G)) |
| 450 | { |
| 451 | error0 = VXLAN_GBP_ERROR_BAD_FLAGS; |
| 452 | vlib_increment_combined_counter |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 453 | (drop_counter, thread_index, t0->sw_if_index, 1, len0); |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 454 | next0 = VXLAN_GBP_INPUT_NEXT_DROP; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 455 | } |
| 456 | else |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 457 | { |
| 458 | error0 = VXLAN_GBP_ERROR_NO_SUCH_TUNNEL; |
Neale Ranns | 76b5649 | 2018-09-28 15:16:14 +0000 | [diff] [blame^] | 459 | next0 = VXLAN_GBP_INPUT_NEXT_PUNT; |
| 460 | if (is_ip4) |
| 461 | b0->punt_reason = |
| 462 | vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP4]; |
| 463 | else |
| 464 | b0->punt_reason = |
| 465 | vxm->punt_no_such_tunnel[FIB_PROTOCOL_IP6]; |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 466 | } |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 467 | b0->error = node->errors[error0]; |
| 468 | } |
| 469 | else |
| 470 | { |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 471 | next0 = vxlan_gbp_tunnel_get_next (t0, b0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 472 | /* Set packet input sw_if_index to unicast VXLAN_GBP tunnel for learning */ |
| 473 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = t0->sw_if_index; |
| 474 | pkts_decapsulated++; |
| 475 | |
| 476 | vlib_increment_combined_counter |
Neale Ranns | 665581a | 2019-03-05 06:11:57 -0800 | [diff] [blame] | 477 | (rx_counter, thread_index, t0->sw_if_index, 1, len0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 478 | } |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 479 | vnet_buffer2 (b0)->gbp.flags = vxlan_gbp_get_gpflags (vxlan_gbp0); |
Neale Ranns | 879d11c | 2019-01-21 23:34:18 -0800 | [diff] [blame] | 480 | vnet_buffer2 (b0)->gbp.sclass = vxlan_gbp_get_sclass (vxlan_gbp0); |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 481 | |
| 482 | /* Required to make the l2 tag push / pop code work on l2 subifs */ |
| 483 | vnet_update_l2_len (b0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 484 | |
| 485 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 486 | { |
| 487 | vxlan_gbp_rx_trace_t *tr |
| 488 | = vlib_add_trace (vm, node, b0, sizeof (*tr)); |
| 489 | tr->next_index = next0; |
| 490 | tr->error = error0; |
| 491 | tr->tunnel_index = t0 == 0 ? ~0 : t0 - vxm->tunnels; |
| 492 | tr->vni = vxlan_gbp_get_vni (vxlan_gbp0); |
| 493 | tr->sclass = vxlan_gbp_get_sclass (vxlan_gbp0); |
Neale Ranns | 93cc3ee | 2018-10-10 07:22:51 -0700 | [diff] [blame] | 494 | tr->flags = vxlan_gbp_get_gpflags (vxlan_gbp0); |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 495 | } |
| 496 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 497 | to_next, n_left_to_next, |
| 498 | bi0, next0); |
| 499 | } |
| 500 | |
| 501 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 502 | } |
| 503 | /* Do we still need this now that tunnel tx stats is kept? */ |
| 504 | u32 node_idx = |
| 505 | is_ip4 ? vxlan4_gbp_input_node.index : vxlan6_gbp_input_node.index; |
| 506 | vlib_node_increment_counter (vm, node_idx, VXLAN_GBP_ERROR_DECAPSULATED, |
| 507 | pkts_decapsulated); |
| 508 | |
| 509 | return from_frame->n_vectors; |
| 510 | } |
| 511 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 512 | VLIB_NODE_FN (vxlan4_gbp_input_node) (vlib_main_t * vm, |
| 513 | vlib_node_runtime_t * node, |
| 514 | vlib_frame_t * from_frame) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 515 | { |
| 516 | return vxlan_gbp_input (vm, node, from_frame, /* is_ip4 */ 1); |
| 517 | } |
| 518 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 519 | VLIB_NODE_FN (vxlan6_gbp_input_node) (vlib_main_t * vm, |
| 520 | vlib_node_runtime_t * node, |
| 521 | vlib_frame_t * from_frame) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 522 | { |
| 523 | return vxlan_gbp_input (vm, node, from_frame, /* is_ip4 */ 0); |
| 524 | } |
| 525 | |
| 526 | static char *vxlan_gbp_error_strings[] = { |
| 527 | #define vxlan_gbp_error(n,s) s, |
| 528 | #include <vnet/vxlan-gbp/vxlan_gbp_error.def> |
| 529 | #undef vxlan_gbp_error |
| 530 | #undef _ |
| 531 | }; |
| 532 | |
| 533 | /* *INDENT-OFF* */ |
| 534 | VLIB_REGISTER_NODE (vxlan4_gbp_input_node) = |
| 535 | { |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 536 | .name = "vxlan4-gbp-input", |
| 537 | .vector_size = sizeof (u32), |
| 538 | .n_errors = VXLAN_GBP_N_ERROR, |
| 539 | .error_strings = vxlan_gbp_error_strings, |
| 540 | .n_next_nodes = VXLAN_GBP_INPUT_N_NEXT, |
| 541 | .format_trace = format_vxlan_gbp_rx_trace, |
| 542 | .next_nodes = { |
| 543 | #define _(s,n) [VXLAN_GBP_INPUT_NEXT_##s] = n, |
| 544 | foreach_vxlan_gbp_input_next |
| 545 | #undef _ |
| 546 | }, |
| 547 | }; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 548 | |
| 549 | VLIB_REGISTER_NODE (vxlan6_gbp_input_node) = |
| 550 | { |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 551 | .name = "vxlan6-gbp-input", |
| 552 | .vector_size = sizeof (u32), |
| 553 | .n_errors = VXLAN_GBP_N_ERROR, |
| 554 | .error_strings = vxlan_gbp_error_strings, |
| 555 | .n_next_nodes = VXLAN_GBP_INPUT_N_NEXT, |
| 556 | .next_nodes = { |
| 557 | #define _(s,n) [VXLAN_GBP_INPUT_NEXT_##s] = n, |
| 558 | foreach_vxlan_gbp_input_next |
| 559 | #undef _ |
| 560 | }, |
| 561 | .format_trace = format_vxlan_gbp_rx_trace, |
| 562 | }; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 563 | /* *INDENT-ON* */ |
| 564 | |
| 565 | typedef enum |
| 566 | { |
| 567 | IP_VXLAN_GBP_BYPASS_NEXT_DROP, |
| 568 | IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP, |
| 569 | IP_VXLAN_GBP_BYPASS_N_NEXT, |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 570 | } ip_vxlan_gbp_bypass_next_t; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 571 | |
| 572 | always_inline uword |
| 573 | ip_vxlan_gbp_bypass_inline (vlib_main_t * vm, |
| 574 | vlib_node_runtime_t * node, |
| 575 | vlib_frame_t * frame, u32 is_ip4) |
| 576 | { |
| 577 | vxlan_gbp_main_t *vxm = &vxlan_gbp_main; |
| 578 | u32 *from, *to_next, n_left_from, n_left_to_next, next_index; |
| 579 | vlib_node_runtime_t *error_node = |
| 580 | vlib_node_get_runtime (vm, ip4_input_node.index); |
| 581 | ip4_address_t addr4; /* last IPv4 address matching a local VTEP address */ |
| 582 | ip6_address_t addr6; /* last IPv6 address matching a local VTEP address */ |
| 583 | |
| 584 | from = vlib_frame_vector_args (frame); |
| 585 | n_left_from = frame->n_vectors; |
| 586 | next_index = node->cached_next_index; |
| 587 | |
| 588 | if (node->flags & VLIB_NODE_FLAG_TRACE) |
| 589 | ip4_forward_next_trace (vm, node, frame, VLIB_TX); |
| 590 | |
| 591 | if (is_ip4) |
| 592 | addr4.data_u32 = ~0; |
| 593 | else |
| 594 | ip6_address_set_zero (&addr6); |
| 595 | |
| 596 | while (n_left_from > 0) |
| 597 | { |
| 598 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 599 | |
| 600 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 601 | { |
| 602 | vlib_buffer_t *b0, *b1; |
| 603 | ip4_header_t *ip40, *ip41; |
| 604 | ip6_header_t *ip60, *ip61; |
| 605 | udp_header_t *udp0, *udp1; |
| 606 | u32 bi0, ip_len0, udp_len0, flags0, next0; |
| 607 | u32 bi1, ip_len1, udp_len1, flags1, next1; |
| 608 | i32 len_diff0, len_diff1; |
| 609 | u8 error0, good_udp0, proto0; |
| 610 | u8 error1, good_udp1, proto1; |
| 611 | |
| 612 | /* Prefetch next iteration. */ |
| 613 | { |
| 614 | vlib_buffer_t *p2, *p3; |
| 615 | |
| 616 | p2 = vlib_get_buffer (vm, from[2]); |
| 617 | p3 = vlib_get_buffer (vm, from[3]); |
| 618 | |
| 619 | vlib_prefetch_buffer_header (p2, LOAD); |
| 620 | vlib_prefetch_buffer_header (p3, LOAD); |
| 621 | |
| 622 | CLIB_PREFETCH (p2->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 623 | CLIB_PREFETCH (p3->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD); |
| 624 | } |
| 625 | |
| 626 | bi0 = to_next[0] = from[0]; |
| 627 | bi1 = to_next[1] = from[1]; |
| 628 | from += 2; |
| 629 | n_left_from -= 2; |
| 630 | to_next += 2; |
| 631 | n_left_to_next -= 2; |
| 632 | |
| 633 | b0 = vlib_get_buffer (vm, bi0); |
| 634 | b1 = vlib_get_buffer (vm, bi1); |
| 635 | if (is_ip4) |
| 636 | { |
| 637 | ip40 = vlib_buffer_get_current (b0); |
| 638 | ip41 = vlib_buffer_get_current (b1); |
| 639 | } |
| 640 | else |
| 641 | { |
| 642 | ip60 = vlib_buffer_get_current (b0); |
| 643 | ip61 = vlib_buffer_get_current (b1); |
| 644 | } |
| 645 | |
| 646 | /* Setup packet for next IP feature */ |
| 647 | vnet_feature_next (&next0, b0); |
| 648 | vnet_feature_next (&next1, b1); |
| 649 | |
| 650 | if (is_ip4) |
| 651 | { |
| 652 | /* Treat IP frag packets as "experimental" protocol for now |
| 653 | until support of IP frag reassembly is implemented */ |
| 654 | proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol; |
| 655 | proto1 = ip4_is_fragment (ip41) ? 0xfe : ip41->protocol; |
| 656 | } |
| 657 | else |
| 658 | { |
| 659 | proto0 = ip60->protocol; |
| 660 | proto1 = ip61->protocol; |
| 661 | } |
| 662 | |
| 663 | /* Process packet 0 */ |
| 664 | if (proto0 != IP_PROTOCOL_UDP) |
| 665 | goto exit0; /* not UDP packet */ |
| 666 | |
| 667 | if (is_ip4) |
| 668 | udp0 = ip4_next_header (ip40); |
| 669 | else |
| 670 | udp0 = ip6_next_header (ip60); |
| 671 | |
| 672 | if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp)) |
| 673 | goto exit0; /* not VXLAN_GBP packet */ |
| 674 | |
| 675 | /* Validate DIP against VTEPs */ |
| 676 | if (is_ip4) |
| 677 | { |
| 678 | if (addr4.as_u32 != ip40->dst_address.as_u32) |
| 679 | { |
| 680 | if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32)) |
| 681 | goto exit0; /* no local VTEP for VXLAN_GBP packet */ |
| 682 | addr4 = ip40->dst_address; |
| 683 | } |
| 684 | } |
| 685 | else |
| 686 | { |
| 687 | if (!ip6_address_is_equal (&addr6, &ip60->dst_address)) |
| 688 | { |
| 689 | if (!hash_get_mem (vxm->vtep6, &ip60->dst_address)) |
| 690 | goto exit0; /* no local VTEP for VXLAN_GBP packet */ |
| 691 | addr6 = ip60->dst_address; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | flags0 = b0->flags; |
| 696 | good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
| 697 | |
| 698 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 699 | good_udp0 |= udp0->checksum == 0; |
| 700 | |
| 701 | /* Verify UDP length */ |
| 702 | if (is_ip4) |
| 703 | ip_len0 = clib_net_to_host_u16 (ip40->length); |
| 704 | else |
| 705 | ip_len0 = clib_net_to_host_u16 (ip60->payload_length); |
| 706 | udp_len0 = clib_net_to_host_u16 (udp0->length); |
| 707 | len_diff0 = ip_len0 - udp_len0; |
| 708 | |
| 709 | /* Verify UDP checksum */ |
| 710 | if (PREDICT_FALSE (!good_udp0)) |
| 711 | { |
| 712 | if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0) |
| 713 | { |
| 714 | if (is_ip4) |
| 715 | flags0 = ip4_tcp_udp_validate_checksum (vm, b0); |
| 716 | else |
| 717 | flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0); |
| 718 | good_udp0 = |
| 719 | (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | if (is_ip4) |
| 724 | { |
| 725 | error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM; |
| 726 | error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH; |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM; |
| 731 | error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH; |
| 732 | } |
| 733 | |
| 734 | next0 = error0 ? |
| 735 | IP_VXLAN_GBP_BYPASS_NEXT_DROP : |
| 736 | IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP; |
| 737 | b0->error = error0 ? error_node->errors[error0] : 0; |
| 738 | |
| 739 | /* vxlan-gbp-input node expect current at VXLAN_GBP header */ |
| 740 | if (is_ip4) |
| 741 | vlib_buffer_advance (b0, |
| 742 | sizeof (ip4_header_t) + |
| 743 | sizeof (udp_header_t)); |
| 744 | else |
| 745 | vlib_buffer_advance (b0, |
| 746 | sizeof (ip6_header_t) + |
| 747 | sizeof (udp_header_t)); |
| 748 | |
| 749 | exit0: |
| 750 | /* Process packet 1 */ |
| 751 | if (proto1 != IP_PROTOCOL_UDP) |
| 752 | goto exit1; /* not UDP packet */ |
| 753 | |
| 754 | if (is_ip4) |
| 755 | udp1 = ip4_next_header (ip41); |
| 756 | else |
| 757 | udp1 = ip6_next_header (ip61); |
| 758 | |
| 759 | if (udp1->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp)) |
| 760 | goto exit1; /* not VXLAN_GBP packet */ |
| 761 | |
| 762 | /* Validate DIP against VTEPs */ |
| 763 | if (is_ip4) |
| 764 | { |
| 765 | if (addr4.as_u32 != ip41->dst_address.as_u32) |
| 766 | { |
| 767 | if (!hash_get (vxm->vtep4, ip41->dst_address.as_u32)) |
| 768 | goto exit1; /* no local VTEP for VXLAN_GBP packet */ |
| 769 | addr4 = ip41->dst_address; |
| 770 | } |
| 771 | } |
| 772 | else |
| 773 | { |
| 774 | if (!ip6_address_is_equal (&addr6, &ip61->dst_address)) |
| 775 | { |
| 776 | if (!hash_get_mem (vxm->vtep6, &ip61->dst_address)) |
| 777 | goto exit1; /* no local VTEP for VXLAN_GBP packet */ |
| 778 | addr6 = ip61->dst_address; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | flags1 = b1->flags; |
| 783 | good_udp1 = (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
| 784 | |
| 785 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 786 | good_udp1 |= udp1->checksum == 0; |
| 787 | |
| 788 | /* Verify UDP length */ |
| 789 | if (is_ip4) |
| 790 | ip_len1 = clib_net_to_host_u16 (ip41->length); |
| 791 | else |
| 792 | ip_len1 = clib_net_to_host_u16 (ip61->payload_length); |
| 793 | udp_len1 = clib_net_to_host_u16 (udp1->length); |
| 794 | len_diff1 = ip_len1 - udp_len1; |
| 795 | |
| 796 | /* Verify UDP checksum */ |
| 797 | if (PREDICT_FALSE (!good_udp1)) |
| 798 | { |
| 799 | if ((flags1 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0) |
| 800 | { |
| 801 | if (is_ip4) |
| 802 | flags1 = ip4_tcp_udp_validate_checksum (vm, b1); |
| 803 | else |
| 804 | flags1 = ip6_tcp_udp_icmp_validate_checksum (vm, b1); |
| 805 | good_udp1 = |
| 806 | (flags1 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | if (is_ip4) |
| 811 | { |
| 812 | error1 = good_udp1 ? 0 : IP4_ERROR_UDP_CHECKSUM; |
| 813 | error1 = (len_diff1 >= 0) ? error1 : IP4_ERROR_UDP_LENGTH; |
| 814 | } |
| 815 | else |
| 816 | { |
| 817 | error1 = good_udp1 ? 0 : IP6_ERROR_UDP_CHECKSUM; |
| 818 | error1 = (len_diff1 >= 0) ? error1 : IP6_ERROR_UDP_LENGTH; |
| 819 | } |
| 820 | |
| 821 | next1 = error1 ? |
| 822 | IP_VXLAN_GBP_BYPASS_NEXT_DROP : |
| 823 | IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP; |
| 824 | b1->error = error1 ? error_node->errors[error1] : 0; |
| 825 | |
| 826 | /* vxlan_gbp-input node expect current at VXLAN_GBP header */ |
| 827 | if (is_ip4) |
| 828 | vlib_buffer_advance (b1, |
| 829 | sizeof (ip4_header_t) + |
| 830 | sizeof (udp_header_t)); |
| 831 | else |
| 832 | vlib_buffer_advance (b1, |
| 833 | sizeof (ip6_header_t) + |
| 834 | sizeof (udp_header_t)); |
| 835 | |
| 836 | exit1: |
| 837 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 838 | to_next, n_left_to_next, |
| 839 | bi0, bi1, next0, next1); |
| 840 | } |
| 841 | |
| 842 | while (n_left_from > 0 && n_left_to_next > 0) |
| 843 | { |
| 844 | vlib_buffer_t *b0; |
| 845 | ip4_header_t *ip40; |
| 846 | ip6_header_t *ip60; |
| 847 | udp_header_t *udp0; |
| 848 | u32 bi0, ip_len0, udp_len0, flags0, next0; |
| 849 | i32 len_diff0; |
| 850 | u8 error0, good_udp0, proto0; |
| 851 | |
| 852 | bi0 = to_next[0] = from[0]; |
| 853 | from += 1; |
| 854 | n_left_from -= 1; |
| 855 | to_next += 1; |
| 856 | n_left_to_next -= 1; |
| 857 | |
| 858 | b0 = vlib_get_buffer (vm, bi0); |
| 859 | if (is_ip4) |
| 860 | ip40 = vlib_buffer_get_current (b0); |
| 861 | else |
| 862 | ip60 = vlib_buffer_get_current (b0); |
| 863 | |
| 864 | /* Setup packet for next IP feature */ |
| 865 | vnet_feature_next (&next0, b0); |
| 866 | |
| 867 | if (is_ip4) |
| 868 | /* Treat IP4 frag packets as "experimental" protocol for now |
| 869 | until support of IP frag reassembly is implemented */ |
| 870 | proto0 = ip4_is_fragment (ip40) ? 0xfe : ip40->protocol; |
| 871 | else |
| 872 | proto0 = ip60->protocol; |
| 873 | |
| 874 | if (proto0 != IP_PROTOCOL_UDP) |
| 875 | goto exit; /* not UDP packet */ |
| 876 | |
| 877 | if (is_ip4) |
| 878 | udp0 = ip4_next_header (ip40); |
| 879 | else |
| 880 | udp0 = ip6_next_header (ip60); |
| 881 | |
| 882 | if (udp0->dst_port != clib_host_to_net_u16 (UDP_DST_PORT_vxlan_gbp)) |
| 883 | goto exit; /* not VXLAN_GBP packet */ |
| 884 | |
| 885 | /* Validate DIP against VTEPs */ |
| 886 | if (is_ip4) |
| 887 | { |
| 888 | if (addr4.as_u32 != ip40->dst_address.as_u32) |
| 889 | { |
| 890 | if (!hash_get (vxm->vtep4, ip40->dst_address.as_u32)) |
| 891 | goto exit; /* no local VTEP for VXLAN_GBP packet */ |
| 892 | addr4 = ip40->dst_address; |
| 893 | } |
| 894 | } |
| 895 | else |
| 896 | { |
| 897 | if (!ip6_address_is_equal (&addr6, &ip60->dst_address)) |
| 898 | { |
| 899 | if (!hash_get_mem (vxm->vtep6, &ip60->dst_address)) |
| 900 | goto exit; /* no local VTEP for VXLAN_GBP packet */ |
| 901 | addr6 = ip60->dst_address; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | flags0 = b0->flags; |
| 906 | good_udp0 = (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
| 907 | |
| 908 | /* Don't verify UDP checksum for packets with explicit zero checksum. */ |
| 909 | good_udp0 |= udp0->checksum == 0; |
| 910 | |
| 911 | /* Verify UDP length */ |
| 912 | if (is_ip4) |
| 913 | ip_len0 = clib_net_to_host_u16 (ip40->length); |
| 914 | else |
| 915 | ip_len0 = clib_net_to_host_u16 (ip60->payload_length); |
| 916 | udp_len0 = clib_net_to_host_u16 (udp0->length); |
| 917 | len_diff0 = ip_len0 - udp_len0; |
| 918 | |
| 919 | /* Verify UDP checksum */ |
| 920 | if (PREDICT_FALSE (!good_udp0)) |
| 921 | { |
| 922 | if ((flags0 & VNET_BUFFER_F_L4_CHECKSUM_COMPUTED) == 0) |
| 923 | { |
| 924 | if (is_ip4) |
| 925 | flags0 = ip4_tcp_udp_validate_checksum (vm, b0); |
| 926 | else |
| 927 | flags0 = ip6_tcp_udp_icmp_validate_checksum (vm, b0); |
| 928 | good_udp0 = |
| 929 | (flags0 & VNET_BUFFER_F_L4_CHECKSUM_CORRECT) != 0; |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | if (is_ip4) |
| 934 | { |
| 935 | error0 = good_udp0 ? 0 : IP4_ERROR_UDP_CHECKSUM; |
| 936 | error0 = (len_diff0 >= 0) ? error0 : IP4_ERROR_UDP_LENGTH; |
| 937 | } |
| 938 | else |
| 939 | { |
| 940 | error0 = good_udp0 ? 0 : IP6_ERROR_UDP_CHECKSUM; |
| 941 | error0 = (len_diff0 >= 0) ? error0 : IP6_ERROR_UDP_LENGTH; |
| 942 | } |
| 943 | |
| 944 | next0 = error0 ? |
| 945 | IP_VXLAN_GBP_BYPASS_NEXT_DROP : |
| 946 | IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP; |
| 947 | b0->error = error0 ? error_node->errors[error0] : 0; |
| 948 | |
| 949 | /* vxlan_gbp-input node expect current at VXLAN_GBP header */ |
| 950 | if (is_ip4) |
| 951 | vlib_buffer_advance (b0, |
| 952 | sizeof (ip4_header_t) + |
| 953 | sizeof (udp_header_t)); |
| 954 | else |
| 955 | vlib_buffer_advance (b0, |
| 956 | sizeof (ip6_header_t) + |
| 957 | sizeof (udp_header_t)); |
| 958 | |
| 959 | exit: |
| 960 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 961 | to_next, n_left_to_next, |
| 962 | bi0, next0); |
| 963 | } |
| 964 | |
| 965 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 966 | } |
| 967 | |
| 968 | return frame->n_vectors; |
| 969 | } |
| 970 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 971 | VLIB_NODE_FN (ip4_vxlan_gbp_bypass_node) (vlib_main_t * vm, |
| 972 | vlib_node_runtime_t * node, |
| 973 | vlib_frame_t * frame) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 974 | { |
| 975 | return ip_vxlan_gbp_bypass_inline (vm, node, frame, /* is_ip4 */ 1); |
| 976 | } |
| 977 | |
| 978 | /* *INDENT-OFF* */ |
| 979 | VLIB_REGISTER_NODE (ip4_vxlan_gbp_bypass_node) = |
| 980 | { |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 981 | .name = "ip4-vxlan-gbp-bypass", |
| 982 | .vector_size = sizeof (u32), |
| 983 | .n_next_nodes = IP_VXLAN_GBP_BYPASS_N_NEXT, |
| 984 | .next_nodes = { |
| 985 | [IP_VXLAN_GBP_BYPASS_NEXT_DROP] = "error-drop", |
| 986 | [IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP] = "vxlan4-gbp-input", |
| 987 | }, |
| 988 | .format_buffer = format_ip4_header, |
| 989 | .format_trace = format_ip4_forward_next_trace, |
| 990 | }; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 991 | /* *INDENT-ON* */ |
| 992 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 993 | #ifndef CLIB_MARCH_VARIANT |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 994 | /* Dummy init function to get us linked in. */ |
| 995 | clib_error_t * |
| 996 | ip4_vxlan_gbp_bypass_init (vlib_main_t * vm) |
| 997 | { |
| 998 | return 0; |
| 999 | } |
| 1000 | |
| 1001 | VLIB_INIT_FUNCTION (ip4_vxlan_gbp_bypass_init); |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1002 | #endif /* CLIB_MARCH_VARIANT */ |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1003 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1004 | VLIB_NODE_FN (ip6_vxlan_gbp_bypass_node) (vlib_main_t * vm, |
| 1005 | vlib_node_runtime_t * node, |
| 1006 | vlib_frame_t * frame) |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1007 | { |
| 1008 | return ip_vxlan_gbp_bypass_inline (vm, node, frame, /* is_ip4 */ 0); |
| 1009 | } |
| 1010 | |
| 1011 | /* *INDENT-OFF* */ |
| 1012 | VLIB_REGISTER_NODE (ip6_vxlan_gbp_bypass_node) = |
| 1013 | { |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1014 | .name = "ip6-vxlan-gbp-bypass", |
| 1015 | .vector_size = sizeof (u32), |
| 1016 | .n_next_nodes = IP_VXLAN_GBP_BYPASS_N_NEXT, |
| 1017 | .next_nodes = { |
| 1018 | [IP_VXLAN_GBP_BYPASS_NEXT_DROP] = "error-drop", |
| 1019 | [IP_VXLAN_GBP_BYPASS_NEXT_VXLAN_GBP] = "vxlan6-gbp-input", |
| 1020 | }, |
| 1021 | .format_buffer = format_ip6_header, |
| 1022 | .format_trace = format_ip6_forward_next_trace, |
| 1023 | }; |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1024 | /* *INDENT-ON* */ |
| 1025 | |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1026 | #ifndef CLIB_MARCH_VARIANT |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1027 | /* Dummy init function to get us linked in. */ |
| 1028 | clib_error_t * |
| 1029 | ip6_vxlan_gbp_bypass_init (vlib_main_t * vm) |
| 1030 | { |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
| 1034 | VLIB_INIT_FUNCTION (ip6_vxlan_gbp_bypass_init); |
Filip Tehlar | e1714d3 | 2019-03-05 03:01:43 -0800 | [diff] [blame] | 1035 | #endif /* CLIB_MARCH_VARIANT */ |
Mohsin Kazmi | 61b94c6 | 2018-08-20 18:32:39 +0200 | [diff] [blame] | 1036 | |
| 1037 | /* |
| 1038 | * fd.io coding-style-patch-verification: ON |
| 1039 | * |
| 1040 | * Local Variables: |
| 1041 | * eval: (c-set-style "gnu") |
| 1042 | * End: |
| 1043 | */ |