Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * gre.h: types/functions for gre. |
| 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 | #ifndef included_gre_h |
| 19 | #define included_gre_h |
| 20 | |
| 21 | #include <vnet/vnet.h> |
| 22 | #include <vnet/gre/packet.h> |
| 23 | #include <vnet/ip/ip.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 24 | #include <vnet/pg/pg.h> |
| 25 | #include <vnet/ip/format.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 26 | #include <vnet/adj/adj_types.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | |
Damjan Marion | b8abf87 | 2016-03-14 20:02:35 +0100 | [diff] [blame] | 28 | extern vnet_hw_interface_class_t gre_hw_interface_class; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 30 | typedef enum |
| 31 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 32 | #define gre_error(n,s) GRE_ERROR_##n, |
| 33 | #include <vnet/gre/error.def> |
| 34 | #undef gre_error |
| 35 | GRE_N_ERROR, |
| 36 | } gre_error_t; |
| 37 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 38 | /** |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 39 | * @brief The GRE tunnel type |
| 40 | */ |
| 41 | typedef enum gre_tunnel_type_t_ |
| 42 | { |
| 43 | /** |
| 44 | * L3 GRE (i.e. this tunnel is in L3 mode) |
| 45 | */ |
| 46 | GRE_TUNNEL_TYPE_L3 = 0, |
| 47 | /** |
| 48 | * Transparent Ethernet Bridging - the tunnel is in L2 mode |
| 49 | */ |
| 50 | GRE_TUNNEL_TYPE_TEB = 1, |
| 51 | /** |
| 52 | * ERSPAN type 2 - the tunnel is for port mirror SPAN output. Each tunnel is |
| 53 | * associated with a session ID and expected to be used for encap and output |
| 54 | * of mirrored packet from a L2 network only. There is no support for |
| 55 | * receiving ERSPAN packets from a GRE ERSPAN tunnel in VPP. |
| 56 | */ |
| 57 | GRE_TUNNEL_TYPE_ERSPAN = 2, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 58 | } gre_tunnel_type_t; |
| 59 | |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 60 | #define GRE_TUNNEL_TYPE_N (GRE_TUNNEL_TYPE_ERSPAN + 1) |
| 61 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 62 | #define GRE_TUNNEL_TYPE_NAMES { \ |
| 63 | [GRE_TUNNEL_TYPE_L3] = "L3", \ |
| 64 | [GRE_TUNNEL_TYPE_TEB] = "TEB", \ |
| 65 | [GRE_TUNNEL_TYPE_ERSPAN] = "ERSPAN", \ |
| 66 | } |
| 67 | |
| 68 | /** |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 69 | * A GRE payload protocol registration |
| 70 | */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 71 | typedef struct |
| 72 | { |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 73 | /** Name (a c string). */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 74 | char *name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 75 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 76 | /** GRE protocol type in host byte order. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | gre_protocol_t protocol; |
| 78 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 79 | /** GRE tunnel type */ |
| 80 | gre_tunnel_type_t tunnel_type; |
| 81 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 82 | /** Node which handles this type. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 83 | u32 node_index; |
| 84 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 85 | /** Next index for this type. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | u32 next_index; |
| 87 | } gre_protocol_info_t; |
| 88 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 89 | /** |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 90 | * @brief Key for a IPv4 GRE Tunnel |
| 91 | */ |
| 92 | typedef struct gre_tunnel_key4_t_ |
| 93 | { |
| 94 | /** |
| 95 | * Source and destination IP addresses |
| 96 | */ |
| 97 | union |
| 98 | { |
| 99 | struct |
| 100 | { |
| 101 | ip4_address_t gtk_src; |
| 102 | ip4_address_t gtk_dst; |
| 103 | }; |
| 104 | u64 gtk_as_u64; |
| 105 | }; |
| 106 | |
| 107 | /** |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 108 | * FIB table index, ERSPAN session ID and tunnel type in u32 bit fields: |
| 109 | * - The FIB table index the src,dst addresses are in, top 20 bits |
| 110 | * - The Session ID for ERSPAN tunnel type and 0 otherwise, next 10 bits |
| 111 | * - Tunnel type, bottom 2 bits |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 112 | */ |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 113 | u32 gtk_fidx_ssid_type; |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 114 | } __attribute__ ((packed)) gre_tunnel_key4_t; |
| 115 | |
| 116 | /** |
| 117 | * @brief Key for a IPv6 GRE Tunnel |
| 118 | * We use a different type so that the V4 key hash is as small as possible |
| 119 | */ |
| 120 | typedef struct gre_tunnel_key6_t_ |
| 121 | { |
| 122 | /** |
| 123 | * Source and destination IP addresses |
| 124 | */ |
| 125 | ip6_address_t gtk_src; |
| 126 | ip6_address_t gtk_dst; |
| 127 | |
| 128 | /** |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 129 | * FIB table index, ERSPAN session ID and tunnel type in u32 bit fields: |
| 130 | * - The FIB table index the src,dst addresses are in, top 20 bits |
| 131 | * - The Session ID for ERSPAN tunnel type and 0 otherwise, next 10 bits |
| 132 | * - Tunnel type, bottom 2 bits |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 133 | */ |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 134 | u32 gtk_fidx_ssid_type; |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 135 | } __attribute__ ((packed)) gre_tunnel_key6_t; |
| 136 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 137 | #define GTK_FIB_INDEX_SHIFT 12 |
| 138 | #define GTK_FIB_INDEX_MASK 0xfffff000 |
| 139 | #define GTK_TYPE_SHIFT 0 |
| 140 | #define GTK_TYPE_MASK 0x3 |
| 141 | #define GTK_SESSION_ID_SHIFT 2 |
| 142 | #define GTK_SESSION_ID_MASK 0xffc |
| 143 | #define GTK_SESSION_ID_MAX (GTK_SESSION_ID_MASK >> GTK_SESSION_ID_SHIFT) |
| 144 | |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 145 | /** |
| 146 | * Union of the two possible key types |
| 147 | */ |
| 148 | typedef union gre_tunnel_key_t_ |
| 149 | { |
| 150 | gre_tunnel_key4_t gtk_v4; |
| 151 | gre_tunnel_key6_t gtk_v6; |
| 152 | } gre_tunnel_key_t; |
| 153 | |
| 154 | /** |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 155 | * Used for GRE header seq number generation for ERSPAN encap |
| 156 | */ |
| 157 | typedef struct |
| 158 | { |
| 159 | u32 seq_num; |
| 160 | u32 ref_count; |
| 161 | } gre_sn_t; |
| 162 | |
| 163 | /** |
| 164 | * Hash key for GRE header seq number generation for ERSPAN encap |
| 165 | */ |
| 166 | typedef struct |
| 167 | { |
| 168 | ip46_address_t src; |
| 169 | ip46_address_t dst; |
| 170 | u32 fib_index; |
| 171 | } gre_sn_key_t; |
| 172 | |
| 173 | /** |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 174 | * @brief A representation of a GRE tunnel |
| 175 | */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 176 | typedef struct |
| 177 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 178 | /** |
Dave Barach | eb987d3 | 2018-05-03 08:26:39 -0400 | [diff] [blame] | 179 | * Required for pool_get_aligned |
| 180 | */ |
| 181 | CLIB_CACHE_LINE_ALIGN_MARK (cacheline0); |
| 182 | |
| 183 | /** |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 184 | * The hash table's key stored in separate memory since the tunnel_t |
| 185 | * memory can realloc. |
| 186 | */ |
| 187 | gre_tunnel_key_t *key; |
| 188 | |
| 189 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 190 | * The tunnel's source/local address |
| 191 | */ |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 192 | ip46_address_t tunnel_src; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 193 | /** |
| 194 | * The tunnel's destination/remote address |
| 195 | */ |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 196 | fib_prefix_t tunnel_dst; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 197 | /** |
| 198 | * The FIB in which the src.dst address are present |
| 199 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 200 | u32 outer_fib_index; |
| 201 | u32 hw_if_index; |
Chris Luke | 27fe48f | 2016-04-28 13:44:38 -0400 | [diff] [blame] | 202 | u32 sw_if_index; |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 203 | gre_tunnel_type_t type; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 204 | |
| 205 | /** |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 206 | * an L2 tunnel always rquires an L2 midchain. cache here for DP. |
| 207 | */ |
| 208 | adj_index_t l2_adj_index; |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 209 | |
| 210 | /** |
| 211 | * ERSPAN type 2 session ID, least significant 10 bits of u16 |
| 212 | */ |
| 213 | u16 session_id; |
| 214 | |
| 215 | /** |
| 216 | * GRE header sequence number (SN) used for ERSPAN type 2 header, must be |
| 217 | * bumped automically to be thread safe. As multiple GRE tunnels are created |
| 218 | * for the same fib-idx/DIP/SIP with different ERSPAN session number, they all |
| 219 | * share the same SN which is kept per FIB/DIP/SIP, as specified by RFC2890. |
| 220 | */ |
| 221 | gre_sn_t *gre_sn; |
| 222 | |
| 223 | |
| 224 | u32 dev_instance; /* Real device instance in tunnel vector */ |
| 225 | u32 user_instance; /* Instance name being shown to user */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | } gre_tunnel_t; |
| 227 | |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 228 | typedef struct |
| 229 | { |
| 230 | u8 next_index; |
| 231 | u8 tunnel_type; |
| 232 | } next_info_t; |
| 233 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 234 | /** |
| 235 | * @brief GRE related global data |
| 236 | */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 237 | typedef struct |
| 238 | { |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 239 | /** |
| 240 | * pool of tunnel instances |
| 241 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 242 | gre_tunnel_t *tunnels; |
| 243 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 244 | /** |
| 245 | * GRE payload protocol registrations |
| 246 | */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 247 | gre_protocol_info_t *protocol_infos; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 248 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 249 | /** |
| 250 | * Hash tables mapping name/protocol to protocol info index. |
| 251 | */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 252 | uword *protocol_info_by_name, *protocol_info_by_protocol; |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 253 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 254 | /** |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 255 | * Hash mapping to tunnels with ipv4 src/dst addr |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 256 | */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 257 | uword *tunnel_by_key4; |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 258 | |
| 259 | /** |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 260 | * Hash mapping to tunnels with ipv6 src/dst addr |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 261 | */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 262 | uword *tunnel_by_key6; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 263 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 264 | /** |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 265 | * Hash mapping tunnel src/dst addr and fib-idx to sequence number |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 266 | */ |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 267 | uword *seq_num_by_key; |
Chris Luke | 27fe48f | 2016-04-28 13:44:38 -0400 | [diff] [blame] | 268 | |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 269 | /** |
| 270 | * Mapping from sw_if_index to tunnel index |
| 271 | */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 272 | u32 *tunnel_index_by_sw_if_index; |
Chris Luke | 27fe48f | 2016-04-28 13:44:38 -0400 | [diff] [blame] | 273 | |
Damjan Marion | 63d5bae | 2017-04-04 01:28:26 +0200 | [diff] [blame] | 274 | /* Sparse vector mapping gre protocol in network byte order |
| 275 | to next index. */ |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 276 | next_info_t *next_by_protocol; |
Damjan Marion | 63d5bae | 2017-04-04 01:28:26 +0200 | [diff] [blame] | 277 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 278 | /* convenience */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 279 | vlib_main_t *vlib_main; |
| 280 | vnet_main_t *vnet_main; |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 281 | |
| 282 | /* Record used instances */ |
| 283 | uword *instance_used; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 284 | } gre_main_t; |
| 285 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 286 | /** |
| 287 | * @brief IPv4 and GRE header. |
Neale Ranns | 177bbdc | 2016-11-15 09:46:51 +0000 | [diff] [blame] | 288 | */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 289 | /* *INDENT-OFF* */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 290 | typedef CLIB_PACKED (struct { |
| 291 | ip4_header_t ip4; |
| 292 | gre_header_t gre; |
| 293 | }) ip4_and_gre_header_t; |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 294 | /* *INDENT-ON* */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 295 | |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 296 | /** |
| 297 | * @brief IPv6 and GRE header. |
| 298 | */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 299 | /* *INDENT-OFF* */ |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 300 | typedef CLIB_PACKED (struct { |
| 301 | ip6_header_t ip6; |
| 302 | gre_header_t gre; |
| 303 | }) ip6_and_gre_header_t; |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 304 | /* *INDENT-ON* */ |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 305 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 306 | always_inline gre_protocol_info_t * |
| 307 | gre_get_protocol_info (gre_main_t * em, gre_protocol_t protocol) |
| 308 | { |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 309 | uword *p = hash_get (em->protocol_info_by_protocol, protocol); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 310 | return p ? vec_elt_at_index (em->protocol_infos, p[0]) : 0; |
| 311 | } |
| 312 | |
Dave Wallace | 71612d6 | 2017-10-24 01:32:41 -0400 | [diff] [blame] | 313 | extern gre_main_t gre_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 314 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 315 | extern clib_error_t *gre_interface_admin_up_down (vnet_main_t * vnm, |
| 316 | u32 hw_if_index, u32 flags); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 317 | |
| 318 | extern void gre_tunnel_stack (adj_index_t ai); |
| 319 | extern void gre_update_adj (vnet_main_t * vnm, |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 320 | u32 sw_if_index, adj_index_t ai); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 321 | |
| 322 | format_function_t format_gre_protocol; |
| 323 | format_function_t format_gre_header; |
| 324 | format_function_t format_gre_header_with_length; |
| 325 | |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 326 | extern vlib_node_registration_t gre4_input_node; |
| 327 | extern vlib_node_registration_t gre6_input_node; |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 328 | extern vlib_node_registration_t gre_encap_node; |
Damjan Marion | b8abf87 | 2016-03-14 20:02:35 +0100 | [diff] [blame] | 329 | extern vnet_device_class_t gre_device_class; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 330 | |
| 331 | /* Parse gre protocol as 0xXXXX or protocol name. |
| 332 | In either host or network byte order. */ |
| 333 | unformat_function_t unformat_gre_protocol_host_byte_order; |
| 334 | unformat_function_t unformat_gre_protocol_net_byte_order; |
| 335 | |
| 336 | /* Parse gre header. */ |
| 337 | unformat_function_t unformat_gre_header; |
| 338 | unformat_function_t unformat_pg_gre_header; |
| 339 | |
| 340 | void |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 341 | gre_register_input_protocol (vlib_main_t * vm, gre_protocol_t protocol, |
| 342 | u32 node_index, gre_tunnel_type_t tunnel_type); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 343 | |
| 344 | /* manually added to the interface output node in gre.c */ |
| 345 | #define GRE_OUTPUT_NEXT_LOOKUP 1 |
| 346 | |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 347 | typedef struct |
| 348 | { |
Chris Luke | 27fe48f | 2016-04-28 13:44:38 -0400 | [diff] [blame] | 349 | u8 is_add; |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 350 | gre_tunnel_type_t type; |
Ciara Loftus | 7eac916 | 2016-09-30 15:47:03 +0100 | [diff] [blame] | 351 | u8 is_ipv6; |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 352 | u32 instance; |
| 353 | ip46_address_t src, dst; |
Hongjun Ni | 11bfc2f | 2016-07-22 18:19:19 +0800 | [diff] [blame] | 354 | u32 outer_fib_id; |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 355 | u16 session_id; |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 356 | } vnet_gre_tunnel_add_del_args_t; |
Chris Luke | 27fe48f | 2016-04-28 13:44:38 -0400 | [diff] [blame] | 357 | |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 358 | extern int vnet_gre_tunnel_add_del (vnet_gre_tunnel_add_del_args_t * a, |
| 359 | u32 * sw_if_indexp); |
Chris Luke | 27fe48f | 2016-04-28 13:44:38 -0400 | [diff] [blame] | 360 | |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 361 | static inline void |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 362 | gre_mk_key4 (ip4_address_t src, |
| 363 | ip4_address_t dst, |
| 364 | u32 fib_index, u8 ttype, u16 session_id, gre_tunnel_key4_t * key) |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 365 | { |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 366 | key->gtk_src = src; |
| 367 | key->gtk_dst = dst; |
| 368 | key->gtk_fidx_ssid_type = ttype | |
| 369 | (fib_index << GTK_FIB_INDEX_SHIFT) | (session_id << GTK_SESSION_ID_SHIFT); |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static inline int |
| 373 | gre_match_key4 (const gre_tunnel_key4_t * key1, |
| 374 | const gre_tunnel_key4_t * key2) |
| 375 | { |
| 376 | return ((key1->gtk_as_u64 == key2->gtk_as_u64) && |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 377 | (key1->gtk_fidx_ssid_type == key2->gtk_fidx_ssid_type)); |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | static inline void |
| 381 | gre_mk_key6 (const ip6_address_t * src, |
| 382 | const ip6_address_t * dst, |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 383 | u32 fib_index, u8 ttype, u16 session_id, gre_tunnel_key6_t * key) |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 384 | { |
| 385 | key->gtk_src = *src; |
| 386 | key->gtk_dst = *dst; |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 387 | key->gtk_fidx_ssid_type = ttype | |
| 388 | (fib_index << GTK_FIB_INDEX_SHIFT) | (session_id << GTK_SESSION_ID_SHIFT); |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static inline int |
| 392 | gre_match_key6 (const gre_tunnel_key6_t * key1, |
| 393 | const gre_tunnel_key6_t * key2) |
| 394 | { |
| 395 | return ((key1->gtk_src.as_u64[0] == key2->gtk_src.as_u64[0]) && |
| 396 | (key1->gtk_src.as_u64[1] == key2->gtk_src.as_u64[1]) && |
| 397 | (key1->gtk_dst.as_u64[0] == key2->gtk_dst.as_u64[0]) && |
| 398 | (key1->gtk_dst.as_u64[1] == key2->gtk_dst.as_u64[1]) && |
John Lo | a43ccae | 2018-02-13 17:15:23 -0500 | [diff] [blame] | 399 | (key1->gtk_fidx_ssid_type == key2->gtk_fidx_ssid_type)); |
| 400 | } |
| 401 | |
| 402 | static inline void |
| 403 | gre_mk_sn_key (const gre_tunnel_t * gt, gre_sn_key_t * key) |
| 404 | { |
| 405 | key->src = gt->tunnel_src; |
| 406 | key->dst = gt->tunnel_dst.fp_addr; |
| 407 | key->fib_index = gt->outer_fib_index; |
Neale Ranns | 33ce60d | 2017-12-14 08:51:32 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 410 | #endif /* included_gre_h */ |
Swarup Nayak | 9ff647a | 2017-11-27 10:27:43 +0530 | [diff] [blame] | 411 | |
| 412 | /* |
| 413 | * fd.io coding-style-patch-verification: ON |
| 414 | * |
| 415 | * Local Variables: |
| 416 | * eval: (c-set-style "gnu") |
| 417 | * End: |
| 418 | */ |