Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * node.c: gre packet processing |
| 3 | * |
| 4 | * Copyright (c) 2012 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/gre/gre.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 21 | #include <vnet/mpls/mpls.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 22 | #include <vppinfra/sparse_vec.h> |
| 23 | |
| 24 | #define foreach_gre_input_next \ |
| 25 | _(PUNT, "error-punt") \ |
| 26 | _(DROP, "error-drop") \ |
David Hotham | a8cd309 | 2016-09-19 09:55:07 -0700 | [diff] [blame] | 27 | _(ETHERNET_INPUT, "ethernet-input") \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | _(IP4_INPUT, "ip4-input") \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 29 | _(IP6_INPUT, "ip6-input") \ |
| 30 | _(MPLS_INPUT, "mpls-input") |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 32 | typedef enum |
| 33 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 34 | #define _(s,n) GRE_INPUT_NEXT_##s, |
| 35 | foreach_gre_input_next |
| 36 | #undef _ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 37 | GRE_INPUT_N_NEXT, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 38 | } gre_input_next_t; |
| 39 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 40 | typedef struct |
| 41 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 42 | u32 tunnel_id; |
| 43 | u32 length; |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 44 | ip46_address_t src; |
| 45 | ip46_address_t dst; |
| 46 | u8 is_ipv6; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 47 | } gre_rx_trace_t; |
| 48 | |
Filip Tehlar | 0fce11f | 2019-03-04 09:21:59 -0800 | [diff] [blame] | 49 | static u8 * |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 50 | format_gre_rx_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | { |
| 52 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 53 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 54 | gre_rx_trace_t *t = va_arg (*args, gre_rx_trace_t *); |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 55 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | s = format (s, "GRE: tunnel %d len %d src %U dst %U", |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 57 | t->tunnel_id, clib_net_to_host_u16 (t->length), |
| 58 | format_ip46_address, &t->src, IP46_TYPE_ANY, |
| 59 | format_ip46_address, &t->dst, IP46_TYPE_ANY); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | return s; |
| 61 | } |
| 62 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 63 | typedef struct |
| 64 | { |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 65 | /* Sparse vector mapping gre protocol in network byte order |
| 66 | to next index. */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 67 | u16 *next_by_protocol; |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 68 | } gre_input_runtime_t; |
| 69 | |
| 70 | always_inline uword |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | gre_input (vlib_main_t * vm, |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 72 | vlib_node_runtime_t * node, vlib_frame_t * from_frame, u8 is_ipv6) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 74 | gre_main_t *gm = &gre_main; |
| 75 | __attribute__ ((unused)) u32 n_left_from, next_index, *from, *to_next; |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 76 | gre_tunnel_key_t cached_tunnel_key; |
| 77 | |
| 78 | u32 cached_tunnel_sw_if_index = ~0, tunnel_sw_if_index = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | |
Damjan Marion | 067cd62 | 2018-07-11 12:47:43 +0200 | [diff] [blame] | 80 | u32 thread_index = vm->thread_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 81 | u32 len; |
| 82 | vnet_interface_main_t *im = &gm->vnet_main->interface_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 83 | |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 84 | if (!is_ipv6) |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 85 | clib_memset (&cached_tunnel_key.gtk_v4, 0xff, |
| 86 | sizeof (cached_tunnel_key.gtk_v4)); |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 87 | else |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 88 | clib_memset (&cached_tunnel_key.gtk_v6, 0xff, |
| 89 | sizeof (cached_tunnel_key.gtk_v6)); |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 90 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | from = vlib_frame_vector_args (from_frame); |
| 92 | n_left_from = from_frame->n_vectors; |
| 93 | |
| 94 | next_index = node->cached_next_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 95 | |
| 96 | while (n_left_from > 0) |
| 97 | { |
| 98 | u32 n_left_to_next; |
| 99 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 100 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | |
| 102 | while (n_left_from >= 4 && n_left_to_next >= 2) |
| 103 | { |
| 104 | u32 bi0, bi1; |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 105 | vlib_buffer_t *b0, *b1; |
| 106 | gre_header_t *h0, *h1; |
| 107 | u16 version0, version1; |
| 108 | int verr0, verr1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 109 | u32 i0, i1, next0, next1, protocol0, protocol1; |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 110 | ip4_header_t *ip4_0, *ip4_1; |
| 111 | ip6_header_t *ip6_0, *ip6_1; |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 112 | gre_tunnel_key_t key0, key1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | |
| 114 | /* Prefetch next iteration. */ |
| 115 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 116 | vlib_buffer_t *p2, *p3; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 117 | |
| 118 | p2 = vlib_get_buffer (vm, from[2]); |
| 119 | p3 = vlib_get_buffer (vm, from[3]); |
| 120 | |
| 121 | vlib_prefetch_buffer_header (p2, LOAD); |
| 122 | vlib_prefetch_buffer_header (p3, LOAD); |
| 123 | |
| 124 | CLIB_PREFETCH (p2->data, sizeof (h0[0]), LOAD); |
| 125 | CLIB_PREFETCH (p3->data, sizeof (h1[0]), LOAD); |
| 126 | } |
| 127 | |
| 128 | bi0 = from[0]; |
| 129 | bi1 = from[1]; |
| 130 | to_next[0] = bi0; |
| 131 | to_next[1] = bi1; |
| 132 | from += 2; |
| 133 | to_next += 2; |
| 134 | n_left_to_next -= 2; |
| 135 | n_left_from -= 2; |
| 136 | |
| 137 | b0 = vlib_get_buffer (vm, bi0); |
| 138 | b1 = vlib_get_buffer (vm, bi1); |
| 139 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 140 | if (!is_ipv6) |
| 141 | { |
| 142 | /* ip4_local hands us the ip header, not the gre header */ |
| 143 | ip4_0 = vlib_buffer_get_current (b0); |
| 144 | ip4_1 = vlib_buffer_get_current (b1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 145 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 146 | vlib_buffer_advance (b0, sizeof (*ip4_0)); |
| 147 | vlib_buffer_advance (b1, sizeof (*ip4_1)); |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | /* ip6_local hands us the ip header, not the gre header */ |
| 152 | ip6_0 = vlib_buffer_get_current (b0); |
| 153 | ip6_1 = vlib_buffer_get_current (b1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 154 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 155 | vlib_buffer_advance (b0, sizeof (*ip6_0)); |
| 156 | vlib_buffer_advance (b1, sizeof (*ip6_1)); |
| 157 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | |
| 159 | h0 = vlib_buffer_get_current (b0); |
| 160 | h1 = vlib_buffer_get_current (b1); |
| 161 | |
| 162 | /* Index sparse array with network byte order. */ |
| 163 | protocol0 = h0->protocol; |
| 164 | protocol1 = h1->protocol; |
Damjan Marion | 63d5bae | 2017-04-04 01:28:26 +0200 | [diff] [blame] | 165 | sparse_vec_index2 (gm->next_by_protocol, protocol0, protocol1, |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 166 | &i0, &i1); |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 167 | next0 = vec_elt (gm->next_by_protocol, i0).next_index; |
| 168 | next1 = vec_elt (gm->next_by_protocol, i1).next_index; |
| 169 | u8 ttype0 = vec_elt (gm->next_by_protocol, i0).tunnel_type; |
| 170 | u8 ttype1 = vec_elt (gm->next_by_protocol, i1).tunnel_type; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 171 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 172 | b0->error = |
| 173 | node->errors[i0 == |
| 174 | SPARSE_VEC_INVALID_INDEX ? GRE_ERROR_UNKNOWN_PROTOCOL |
| 175 | : GRE_ERROR_NONE]; |
| 176 | b1->error = |
| 177 | node->errors[i1 == |
| 178 | SPARSE_VEC_INVALID_INDEX ? GRE_ERROR_UNKNOWN_PROTOCOL |
| 179 | : GRE_ERROR_NONE]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 180 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 181 | version0 = clib_net_to_host_u16 (h0->flags_and_version); |
| 182 | verr0 = version0 & GRE_VERSION_MASK; |
| 183 | version1 = clib_net_to_host_u16 (h1->flags_and_version); |
| 184 | verr1 = version1 & GRE_VERSION_MASK; |
| 185 | |
| 186 | b0->error = verr0 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION] |
| 187 | : b0->error; |
| 188 | next0 = verr0 ? GRE_INPUT_NEXT_DROP : next0; |
| 189 | b1->error = verr1 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION] |
| 190 | : b1->error; |
| 191 | next1 = verr1 ? GRE_INPUT_NEXT_DROP : next1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 192 | |
David Hotham | a8cd309 | 2016-09-19 09:55:07 -0700 | [diff] [blame] | 193 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 194 | /* RPF check for ip4/ip6 input */ |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 195 | if (PREDICT_TRUE (next0 > GRE_INPUT_NEXT_DROP)) |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 196 | { |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 197 | if (is_ipv6) |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 198 | { |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 199 | gre_mk_key6 (&ip6_0->dst_address, |
| 200 | &ip6_0->src_address, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 201 | vnet_buffer (b0)->ip.fib_index, |
| 202 | ttype0, 0, &key0.gtk_v6); |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 203 | } |
| 204 | else |
| 205 | { |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 206 | gre_mk_key4 (ip4_0->dst_address, |
| 207 | ip4_0->src_address, |
| 208 | vnet_buffer (b0)->ip.fib_index, |
| 209 | ttype0, 0, &key0.gtk_v4); |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 210 | } |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 211 | |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 212 | if ((!is_ipv6 && !gre_match_key4 (&cached_tunnel_key.gtk_v4, |
| 213 | &key0.gtk_v4)) || |
| 214 | (is_ipv6 && !gre_match_key6 (&cached_tunnel_key.gtk_v6, |
| 215 | &key0.gtk_v6))) |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 216 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 217 | gre_tunnel_t *t; |
| 218 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 219 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 220 | if (!is_ipv6) |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 221 | { |
| 222 | p = hash_get_mem (gm->tunnel_by_key4, &key0.gtk_v4); |
| 223 | } |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 224 | else |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 225 | { |
| 226 | p = hash_get_mem (gm->tunnel_by_key6, &key0.gtk_v6); |
| 227 | } |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 228 | if (!p) |
| 229 | { |
| 230 | next0 = GRE_INPUT_NEXT_DROP; |
| 231 | b0->error = node->errors[GRE_ERROR_NO_SUCH_TUNNEL]; |
| 232 | goto drop0; |
| 233 | } |
| 234 | t = pool_elt_at_index (gm->tunnels, p[0]); |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 235 | tunnel_sw_if_index = t->sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 236 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 237 | cached_tunnel_sw_if_index = tunnel_sw_if_index; |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 238 | if (!is_ipv6) |
| 239 | { |
| 240 | cached_tunnel_key.gtk_v4 = key0.gtk_v4; |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | cached_tunnel_key.gtk_v6 = key0.gtk_v6; |
| 245 | } |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 246 | } |
| 247 | else |
| 248 | { |
| 249 | tunnel_sw_if_index = cached_tunnel_sw_if_index; |
| 250 | } |
| 251 | } |
| 252 | else |
| 253 | { |
| 254 | next0 = GRE_INPUT_NEXT_DROP; |
| 255 | goto drop0; |
| 256 | } |
| 257 | len = vlib_buffer_length_in_chain (vm, b0); |
| 258 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 259 | + VNET_INTERFACE_COUNTER_RX, |
| 260 | thread_index, |
| 261 | tunnel_sw_if_index, |
| 262 | 1 /* packets */ , |
| 263 | len /* bytes */ ); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 264 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 265 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = tunnel_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 266 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 267 | drop0: |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 268 | if (PREDICT_TRUE (next1 > GRE_INPUT_NEXT_DROP)) |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 269 | { |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 270 | if (is_ipv6) |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 271 | { |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 272 | gre_mk_key6 (&ip6_1->dst_address, |
| 273 | &ip6_1->src_address, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 274 | vnet_buffer (b1)->ip.fib_index, |
| 275 | ttype1, 0, &key1.gtk_v6); |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 276 | } |
| 277 | else |
| 278 | { |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 279 | gre_mk_key4 (ip4_1->dst_address, |
| 280 | ip4_1->src_address, |
| 281 | vnet_buffer (b1)->ip.fib_index, |
| 282 | ttype1, 0, &key1.gtk_v4); |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 283 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 284 | |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 285 | if ((!is_ipv6 && !gre_match_key4 (&cached_tunnel_key.gtk_v4, |
| 286 | &key1.gtk_v4)) || |
| 287 | (is_ipv6 && !gre_match_key6 (&cached_tunnel_key.gtk_v6, |
| 288 | &key1.gtk_v6))) |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 289 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 290 | gre_tunnel_t *t; |
| 291 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 292 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 293 | if (!is_ipv6) |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 294 | { |
| 295 | p = hash_get_mem (gm->tunnel_by_key4, &key1.gtk_v4); |
| 296 | } |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 297 | else |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 298 | { |
| 299 | p = hash_get_mem (gm->tunnel_by_key6, &key1.gtk_v6); |
| 300 | } |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 301 | if (!p) |
| 302 | { |
| 303 | next1 = GRE_INPUT_NEXT_DROP; |
| 304 | b1->error = node->errors[GRE_ERROR_NO_SUCH_TUNNEL]; |
| 305 | goto drop1; |
| 306 | } |
| 307 | t = pool_elt_at_index (gm->tunnels, p[0]); |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 308 | tunnel_sw_if_index = t->sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 309 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 310 | cached_tunnel_sw_if_index = tunnel_sw_if_index; |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 311 | if (!is_ipv6) |
| 312 | { |
| 313 | cached_tunnel_key.gtk_v4 = key1.gtk_v4; |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | cached_tunnel_key.gtk_v6 = key1.gtk_v6; |
| 318 | } |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 319 | } |
| 320 | else |
| 321 | { |
| 322 | tunnel_sw_if_index = cached_tunnel_sw_if_index; |
| 323 | } |
| 324 | } |
| 325 | else |
| 326 | { |
| 327 | next1 = GRE_INPUT_NEXT_DROP; |
| 328 | goto drop1; |
| 329 | } |
| 330 | len = vlib_buffer_length_in_chain (vm, b1); |
| 331 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 332 | + VNET_INTERFACE_COUNTER_RX, |
| 333 | thread_index, |
| 334 | tunnel_sw_if_index, |
| 335 | 1 /* packets */ , |
| 336 | len /* bytes */ ); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 337 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 338 | vnet_buffer (b1)->sw_if_index[VLIB_RX] = tunnel_sw_if_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 339 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 340 | drop1: |
| 341 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 342 | { |
| 343 | gre_rx_trace_t *tr = vlib_add_trace (vm, node, |
| 344 | b0, sizeof (*tr)); |
| 345 | tr->tunnel_id = tunnel_sw_if_index; |
| 346 | if (!is_ipv6) |
| 347 | { |
| 348 | tr->length = ip4_0->length; |
| 349 | tr->src.ip4.as_u32 = ip4_0->src_address.as_u32; |
| 350 | tr->dst.ip4.as_u32 = ip4_0->dst_address.as_u32; |
| 351 | } |
| 352 | else |
| 353 | { |
| 354 | tr->length = ip6_0->payload_length; |
| 355 | tr->src.ip6.as_u64[0] = ip6_0->src_address.as_u64[0]; |
| 356 | tr->src.ip6.as_u64[1] = ip6_0->src_address.as_u64[1]; |
| 357 | tr->dst.ip6.as_u64[0] = ip6_0->dst_address.as_u64[0]; |
| 358 | tr->dst.ip6.as_u64[1] = ip6_0->dst_address.as_u64[1]; |
| 359 | } |
| 360 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 361 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 362 | if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED)) |
| 363 | { |
| 364 | gre_rx_trace_t *tr = vlib_add_trace (vm, node, |
| 365 | b1, sizeof (*tr)); |
| 366 | tr->tunnel_id = tunnel_sw_if_index; |
| 367 | if (!is_ipv6) |
| 368 | { |
| 369 | tr->length = ip4_1->length; |
| 370 | tr->src.ip4.as_u32 = ip4_1->src_address.as_u32; |
| 371 | tr->dst.ip4.as_u32 = ip4_1->dst_address.as_u32; |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | tr->length = ip6_1->payload_length; |
| 376 | tr->src.ip6.as_u64[0] = ip6_1->src_address.as_u64[0]; |
| 377 | tr->src.ip6.as_u64[1] = ip6_1->src_address.as_u64[1]; |
| 378 | tr->dst.ip6.as_u64[0] = ip6_1->dst_address.as_u64[0]; |
| 379 | tr->dst.ip6.as_u64[1] = ip6_1->dst_address.as_u64[1]; |
| 380 | } |
| 381 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 383 | vlib_buffer_advance (b0, sizeof (*h0)); |
| 384 | vlib_buffer_advance (b1, sizeof (*h1)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 385 | |
| 386 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 387 | to_next, n_left_to_next, |
| 388 | bi0, bi1, next0, next1); |
| 389 | } |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 390 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 391 | while (n_left_from > 0 && n_left_to_next > 0) |
| 392 | { |
| 393 | u32 bi0; |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 394 | vlib_buffer_t *b0; |
| 395 | gre_header_t *h0; |
| 396 | ip4_header_t *ip4_0; |
| 397 | ip6_header_t *ip6_0; |
| 398 | u16 version0; |
| 399 | int verr0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 400 | u32 i0, next0; |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 401 | gre_tunnel_key_t key0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 402 | |
| 403 | bi0 = from[0]; |
| 404 | to_next[0] = bi0; |
| 405 | from += 1; |
| 406 | to_next += 1; |
| 407 | n_left_from -= 1; |
| 408 | n_left_to_next -= 1; |
| 409 | |
| 410 | b0 = vlib_get_buffer (vm, bi0); |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 411 | ip4_0 = vlib_buffer_get_current (b0); |
| 412 | ip6_0 = (void *) ip4_0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 413 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 414 | if (!is_ipv6) |
| 415 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 416 | vlib_buffer_advance (b0, sizeof (*ip4_0)); |
| 417 | } |
| 418 | else |
| 419 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 420 | vlib_buffer_advance (b0, sizeof (*ip6_0)); |
| 421 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 422 | |
| 423 | h0 = vlib_buffer_get_current (b0); |
| 424 | |
Damjan Marion | 63d5bae | 2017-04-04 01:28:26 +0200 | [diff] [blame] | 425 | i0 = sparse_vec_index (gm->next_by_protocol, h0->protocol); |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 426 | next0 = vec_elt (gm->next_by_protocol, i0).next_index; |
| 427 | u8 ttype0 = vec_elt (gm->next_by_protocol, i0).tunnel_type; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 428 | |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 429 | b0->error = |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 430 | node->errors[i0 == SPARSE_VEC_INVALID_INDEX |
| 431 | ? GRE_ERROR_UNKNOWN_PROTOCOL : GRE_ERROR_NONE]; |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 432 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 433 | version0 = clib_net_to_host_u16 (h0->flags_and_version); |
| 434 | verr0 = version0 & GRE_VERSION_MASK; |
| 435 | b0->error = verr0 ? node->errors[GRE_ERROR_UNSUPPORTED_VERSION] |
| 436 | : b0->error; |
| 437 | next0 = verr0 ? GRE_INPUT_NEXT_DROP : next0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 438 | |
David Hotham | a8cd309 | 2016-09-19 09:55:07 -0700 | [diff] [blame] | 439 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 440 | /* For IP payload we need to find source interface |
| 441 | so we can increase counters and help forward node to |
| 442 | pick right FIB */ |
| 443 | /* RPF check for ip4/ip6 input */ |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 444 | if (PREDICT_TRUE (next0 > GRE_INPUT_NEXT_DROP)) |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 445 | { |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 446 | if (is_ipv6) |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 447 | { |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 448 | gre_mk_key6 (&ip6_0->dst_address, |
| 449 | &ip6_0->src_address, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 450 | vnet_buffer (b0)->ip.fib_index, |
| 451 | ttype0, 0, &key0.gtk_v6); |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 452 | } |
| 453 | else |
| 454 | { |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 455 | gre_mk_key4 (ip4_0->dst_address, |
| 456 | ip4_0->src_address, |
| 457 | vnet_buffer (b0)->ip.fib_index, |
| 458 | ttype0, 0, &key0.gtk_v4); |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 459 | } |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 460 | |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 461 | if ((!is_ipv6 && !gre_match_key4 (&cached_tunnel_key.gtk_v4, |
| 462 | &key0.gtk_v4)) || |
| 463 | (is_ipv6 && !gre_match_key6 (&cached_tunnel_key.gtk_v6, |
| 464 | &key0.gtk_v6))) |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 465 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 466 | gre_tunnel_t *t; |
| 467 | uword *p; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 468 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 469 | if (!is_ipv6) |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 470 | { |
| 471 | p = hash_get_mem (gm->tunnel_by_key4, &key0.gtk_v4); |
| 472 | } |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 473 | else |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 474 | { |
| 475 | p = hash_get_mem (gm->tunnel_by_key6, &key0.gtk_v6); |
| 476 | } |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 477 | if (!p) |
| 478 | { |
| 479 | next0 = GRE_INPUT_NEXT_DROP; |
| 480 | b0->error = node->errors[GRE_ERROR_NO_SUCH_TUNNEL]; |
| 481 | goto drop; |
| 482 | } |
| 483 | t = pool_elt_at_index (gm->tunnels, p[0]); |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 484 | tunnel_sw_if_index = t->sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 485 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 486 | cached_tunnel_sw_if_index = tunnel_sw_if_index; |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 487 | if (!is_ipv6) |
| 488 | { |
| 489 | cached_tunnel_key.gtk_v4 = key0.gtk_v4; |
| 490 | } |
| 491 | else |
| 492 | { |
| 493 | cached_tunnel_key.gtk_v6 = key0.gtk_v6; |
| 494 | } |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 495 | } |
| 496 | else |
| 497 | { |
| 498 | tunnel_sw_if_index = cached_tunnel_sw_if_index; |
| 499 | } |
| 500 | } |
| 501 | else |
| 502 | { |
| 503 | next0 = GRE_INPUT_NEXT_DROP; |
| 504 | goto drop; |
| 505 | } |
| 506 | len = vlib_buffer_length_in_chain (vm, b0); |
| 507 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 508 | + VNET_INTERFACE_COUNTER_RX, |
| 509 | thread_index, |
| 510 | tunnel_sw_if_index, |
| 511 | 1 /* packets */ , |
| 512 | len /* bytes */ ); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 513 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 514 | vnet_buffer (b0)->sw_if_index[VLIB_RX] = tunnel_sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 515 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 516 | drop: |
| 517 | if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 518 | { |
| 519 | gre_rx_trace_t *tr = vlib_add_trace (vm, node, |
| 520 | b0, sizeof (*tr)); |
| 521 | tr->tunnel_id = tunnel_sw_if_index; |
| 522 | if (!is_ipv6) |
| 523 | { |
| 524 | tr->length = ip4_0->length; |
| 525 | tr->src.ip4.as_u32 = ip4_0->src_address.as_u32; |
| 526 | tr->dst.ip4.as_u32 = ip4_0->dst_address.as_u32; |
| 527 | } |
| 528 | else |
| 529 | { |
| 530 | tr->length = ip6_0->payload_length; |
| 531 | tr->src.ip6.as_u64[0] = ip6_0->src_address.as_u64[0]; |
| 532 | tr->src.ip6.as_u64[1] = ip6_0->src_address.as_u64[1]; |
| 533 | tr->dst.ip6.as_u64[0] = ip6_0->dst_address.as_u64[0]; |
| 534 | tr->dst.ip6.as_u64[1] = ip6_0->dst_address.as_u64[1]; |
| 535 | } |
| 536 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 537 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 538 | vlib_buffer_advance (b0, sizeof (*h0)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 539 | |
| 540 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 541 | to_next, n_left_to_next, |
| 542 | bi0, next0); |
| 543 | } |
| 544 | |
| 545 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 546 | } |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 547 | vlib_node_increment_counter (vm, |
| 548 | !is_ipv6 ? gre4_input_node.index : |
| 549 | gre6_input_node.index, GRE_ERROR_PKTS_DECAP, |
| 550 | from_frame->n_vectors); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 551 | return from_frame->n_vectors; |
| 552 | } |
| 553 | |
Filip Tehlar | 0fce11f | 2019-03-04 09:21:59 -0800 | [diff] [blame] | 554 | VLIB_NODE_FN (gre4_input_node) (vlib_main_t * vm, |
| 555 | vlib_node_runtime_t * node, |
| 556 | vlib_frame_t * from_frame) |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 557 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 558 | return gre_input (vm, node, from_frame, /* is_ip6 */ 0); |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 559 | } |
| 560 | |
Filip Tehlar | 0fce11f | 2019-03-04 09:21:59 -0800 | [diff] [blame] | 561 | VLIB_NODE_FN (gre6_input_node) (vlib_main_t * vm, |
| 562 | vlib_node_runtime_t * node, |
| 563 | vlib_frame_t * from_frame) |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 564 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 565 | return gre_input (vm, node, from_frame, /* is_ip6 */ 1); |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 566 | } |
| 567 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 568 | static char *gre_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 569 | #define gre_error(n,s) s, |
| 570 | #include "error.def" |
| 571 | #undef gre_error |
| 572 | }; |
| 573 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 574 | /* *INDENT-OFF* */ |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 575 | VLIB_REGISTER_NODE (gre4_input_node) = { |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 576 | .name = "gre4-input", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 577 | /* Takes a vector of packets. */ |
| 578 | .vector_size = sizeof (u32), |
| 579 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 580 | .n_errors = GRE_N_ERROR, |
| 581 | .error_strings = gre_error_strings, |
| 582 | |
| 583 | .n_next_nodes = GRE_INPUT_N_NEXT, |
| 584 | .next_nodes = { |
| 585 | #define _(s,n) [GRE_INPUT_NEXT_##s] = n, |
| 586 | foreach_gre_input_next |
| 587 | #undef _ |
| 588 | }, |
| 589 | |
| 590 | .format_buffer = format_gre_header_with_length, |
| 591 | .format_trace = format_gre_rx_trace, |
| 592 | .unformat_buffer = unformat_gre_header, |
| 593 | }; |
| 594 | |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 595 | VLIB_REGISTER_NODE (gre6_input_node) = { |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 596 | .name = "gre6-input", |
| 597 | /* Takes a vector of packets. */ |
| 598 | .vector_size = sizeof (u32), |
| 599 | |
| 600 | .runtime_data_bytes = sizeof (gre_input_runtime_t), |
| 601 | |
| 602 | .n_errors = GRE_N_ERROR, |
| 603 | .error_strings = gre_error_strings, |
| 604 | |
| 605 | .n_next_nodes = GRE_INPUT_N_NEXT, |
| 606 | .next_nodes = { |
| 607 | #define _(s,n) [GRE_INPUT_NEXT_##s] = n, |
| 608 | foreach_gre_input_next |
| 609 | #undef _ |
| 610 | }, |
| 611 | |
| 612 | .format_buffer = format_gre_header_with_length, |
| 613 | .format_trace = format_gre_rx_trace, |
| 614 | .unformat_buffer = unformat_gre_header, |
| 615 | }; |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 616 | /* *INDENT-ON* */ |
| 617 | |
Filip Tehlar | 0fce11f | 2019-03-04 09:21:59 -0800 | [diff] [blame] | 618 | #ifndef CLIB_MARCH_VARIANT |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 619 | void |
| 620 | gre_register_input_protocol (vlib_main_t * vm, |
| 621 | gre_protocol_t protocol, u32 node_index, |
| 622 | gre_tunnel_type_t tunnel_type) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 623 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 624 | gre_main_t *em = &gre_main; |
| 625 | gre_protocol_info_t *pi; |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 626 | next_info_t *n; |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 627 | u32 i; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 628 | |
| 629 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 630 | clib_error_t *error = vlib_call_init_function (vm, gre_input_init); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 631 | if (error) |
| 632 | clib_error_report (error); |
| 633 | } |
| 634 | |
| 635 | pi = gre_get_protocol_info (em, protocol); |
| 636 | pi->node_index = node_index; |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 637 | pi->tunnel_type = tunnel_type; |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 638 | pi->next_index = vlib_node_add_next (vm, gre4_input_node.index, node_index); |
| 639 | i = vlib_node_add_next (vm, gre6_input_node.index, node_index); |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 640 | ASSERT (i == pi->next_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 641 | |
| 642 | /* Setup gre protocol -> next index sparse vector mapping. */ |
Damjan Marion | 63d5bae | 2017-04-04 01:28:26 +0200 | [diff] [blame] | 643 | n = sparse_vec_validate (em->next_by_protocol, |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 644 | clib_host_to_net_u16 (protocol)); |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 645 | n->next_index = pi->next_index; |
| 646 | n->tunnel_type = tunnel_type; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | static void |
| 650 | gre_setup_node (vlib_main_t * vm, u32 node_index) |
| 651 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 652 | vlib_node_t *n = vlib_get_node (vm, node_index); |
| 653 | pg_node_t *pn = pg_get_node (node_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 654 | |
| 655 | n->format_buffer = format_gre_header_with_length; |
| 656 | n->unformat_buffer = unformat_gre_header; |
| 657 | pn->unformat_edit = unformat_pg_gre_header; |
| 658 | } |
| 659 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 660 | static clib_error_t * |
| 661 | gre_input_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 662 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 663 | gre_main_t *gm = &gre_main; |
David Hotham | a8cd309 | 2016-09-19 09:55:07 -0700 | [diff] [blame] | 664 | vlib_node_t *ethernet_input, *ip4_input, *ip6_input, *mpls_unicast_input; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 665 | |
| 666 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 667 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 668 | error = vlib_call_init_function (vm, gre_init); |
| 669 | if (error) |
| 670 | clib_error_report (error); |
| 671 | } |
| 672 | |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 673 | gre_setup_node (vm, gre4_input_node.index); |
| 674 | gre_setup_node (vm, gre6_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 675 | |
Damjan Marion | 63d5bae | 2017-04-04 01:28:26 +0200 | [diff] [blame] | 676 | gm->next_by_protocol = sparse_vec_new |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 677 | ( /* elt bytes */ sizeof (gm->next_by_protocol[0]), |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 678 | /* bits in index */ BITS (((gre_header_t *) 0)->protocol)); |
| 679 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 680 | /* These could be moved to the supported protocol input node defn's */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 681 | ethernet_input = vlib_get_node_by_name (vm, (u8 *) "ethernet-input"); |
| 682 | ASSERT (ethernet_input); |
| 683 | ip4_input = vlib_get_node_by_name (vm, (u8 *) "ip4-input"); |
| 684 | ASSERT (ip4_input); |
| 685 | ip6_input = vlib_get_node_by_name (vm, (u8 *) "ip6-input"); |
| 686 | ASSERT (ip6_input); |
| 687 | mpls_unicast_input = vlib_get_node_by_name (vm, (u8 *) "mpls-input"); |
| 688 | ASSERT (mpls_unicast_input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 689 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 690 | gre_register_input_protocol (vm, GRE_PROTOCOL_teb, |
| 691 | ethernet_input->index, GRE_TUNNEL_TYPE_TEB); |
David Hotham | a8cd309 | 2016-09-19 09:55:07 -0700 | [diff] [blame] | 692 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 693 | gre_register_input_protocol (vm, GRE_PROTOCOL_ip4, |
| 694 | ip4_input->index, GRE_TUNNEL_TYPE_L3); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 695 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 696 | gre_register_input_protocol (vm, GRE_PROTOCOL_ip6, |
| 697 | ip6_input->index, GRE_TUNNEL_TYPE_L3); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 698 | |
| 699 | gre_register_input_protocol (vm, GRE_PROTOCOL_mpls_unicast, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 700 | mpls_unicast_input->index, GRE_TUNNEL_TYPE_L3); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 701 | |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 702 | ip4_register_protocol (IP_PROTOCOL_GRE, gre4_input_node.index); |
| 703 | ip6_register_protocol (IP_PROTOCOL_GRE, gre6_input_node.index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | VLIB_INIT_FUNCTION (gre_input_init); |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 709 | |
Filip Tehlar | 0fce11f | 2019-03-04 09:21:59 -0800 | [diff] [blame] | 710 | #endif /* CLIB_MARCH_VARIANT */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 711 | /* |
| 712 | * fd.io coding-style-patch-verification: ON |
| 713 | * |
| 714 | * Local Variables: |
| 715 | * eval: (c-set-style "gnu") |
| 716 | * End: |
| 717 | */ |