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