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