Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 15 | /** |
| 16 | * @file |
| 17 | * @brief VXLAN GPE definitions |
| 18 | * |
| 19 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 20 | #ifndef included_vnet_vxlan_gpe_h |
| 21 | #define included_vnet_vxlan_gpe_h |
| 22 | |
| 23 | #include <vppinfra/error.h> |
| 24 | #include <vppinfra/hash.h> |
| 25 | #include <vnet/vnet.h> |
| 26 | #include <vnet/ip/ip.h> |
| 27 | #include <vnet/l2/l2_input.h> |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 28 | #include <vnet/l2/l2_output.h> |
| 29 | #include <vnet/l2/l2_bd.h> |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 30 | #include <vnet/ethernet/ethernet.h> |
| 31 | #include <vnet/vxlan-gpe/vxlan_gpe_packet.h> |
| 32 | #include <vnet/ip/ip4_packet.h> |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 33 | #include <vnet/ip/ip6_packet.h> |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 34 | #include <vnet/udp/udp.h> |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 35 | #include <vnet/dpo/dpo.h> |
| 36 | #include <vnet/adj/adj_types.h> |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 37 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 38 | /** |
| 39 | * @brief VXLAN GPE header struct |
| 40 | * |
| 41 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 42 | typedef CLIB_PACKED (struct { |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 43 | /** 20 bytes */ |
| 44 | ip4_header_t ip4; |
| 45 | /** 8 bytes */ |
| 46 | udp_header_t udp; |
| 47 | /** 8 bytes */ |
| 48 | vxlan_gpe_header_t vxlan; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 49 | }) ip4_vxlan_gpe_header_t; |
| 50 | |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 51 | typedef CLIB_PACKED (struct { |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 52 | /** 40 bytes */ |
| 53 | ip6_header_t ip6; |
| 54 | /** 8 bytes */ |
| 55 | udp_header_t udp; |
| 56 | /** 8 bytes */ |
| 57 | vxlan_gpe_header_t vxlan; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 58 | }) ip6_vxlan_gpe_header_t; |
| 59 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 60 | /** |
| 61 | * @brief Key struct for IPv4 VXLAN GPE tunnel. |
| 62 | * Key fields: local remote, vni |
| 63 | * all fields in NET byte order |
| 64 | * VNI shifted 8 bits |
| 65 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 66 | typedef CLIB_PACKED(struct { |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 67 | union { |
| 68 | struct { |
| 69 | u32 local; |
| 70 | u32 remote; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 71 | |
| 72 | u32 vni; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 73 | u32 pad; |
| 74 | }; |
| 75 | u64 as_u64[2]; |
| 76 | }; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 77 | }) vxlan4_gpe_tunnel_key_t; |
| 78 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 79 | /** |
| 80 | * @brief Key struct for IPv6 VXLAN GPE tunnel. |
| 81 | * Key fields: local remote, vni |
| 82 | * all fields in NET byte order |
| 83 | * VNI shifted 8 bits |
| 84 | */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 85 | typedef CLIB_PACKED(struct { |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 86 | ip6_address_t local; |
| 87 | ip6_address_t remote; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 88 | u32 vni; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 89 | }) vxlan6_gpe_tunnel_key_t; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 90 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 91 | /** |
| 92 | * @brief Struct for VXLAN GPE tunnel |
| 93 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 94 | typedef struct { |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 95 | /** Rewrite string. $$$$ embed vnet_rewrite header */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 96 | u8 * rewrite; |
| 97 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 98 | /** encapsulated protocol */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 99 | u8 protocol; |
| 100 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 101 | /* FIB DPO for IP forwarding of VXLAN-GPE encap packet */ |
| 102 | dpo_id_t next_dpo; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 103 | /** tunnel local address */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 104 | ip46_address_t local; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 105 | /** tunnel remote address */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 106 | ip46_address_t remote; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 107 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 108 | /* mcast packet output intfc index (used only if dst is mcast) */ |
| 109 | u32 mcast_sw_if_index; |
| 110 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 111 | /** FIB indices - tunnel partner lookup here */ |
| 112 | u32 encap_fib_index; |
| 113 | /** FIB indices - inner IP packet lookup here */ |
| 114 | u32 decap_fib_index; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 115 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 116 | /** VXLAN GPE VNI in HOST byte order, shifted left 8 bits */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 117 | u32 vni; |
| 118 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 119 | /** vnet intfc hw_if_index */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 120 | u32 hw_if_index; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 121 | /** vnet intfc sw_if_index */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 122 | u32 sw_if_index; |
| 123 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 124 | /** flags */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 125 | u32 flags; |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 126 | |
| 127 | /** rewrite size for dynamic plugins like iOAM */ |
| 128 | u8 rewrite_size; |
| 129 | |
| 130 | /** Next node after VxLAN-GPE encap */ |
| 131 | uword encap_next_node; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 132 | |
| 133 | /** |
| 134 | * Linkage into the FIB object graph |
| 135 | */ |
| 136 | fib_node_t node; |
| 137 | |
| 138 | /* |
| 139 | * The FIB entry for (depending on VXLAN-GPE tunnel is unicast or mcast) |
| 140 | * sending unicast VXLAN-GPE encap packets or receiving mcast VXLAN-GPE packets |
| 141 | */ |
| 142 | fib_node_index_t fib_entry_index; |
| 143 | adj_index_t mcast_adj_index; |
| 144 | |
| 145 | /** |
| 146 | * The tunnel is a child of the FIB entry for its desintion. This is |
| 147 | * so it receives updates when the forwarding information for that entry |
| 148 | * changes. |
| 149 | * The tunnels sibling index on the FIB entry's dependency list. |
| 150 | */ |
| 151 | u32 sibling_index; |
| 152 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 153 | } vxlan_gpe_tunnel_t; |
| 154 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 155 | /** Flags for vxlan_gpe_tunnel_t */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 156 | #define VXLAN_GPE_TUNNEL_IS_IPV4 1 |
| 157 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 158 | /** next nodes for VXLAN GPE input */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 159 | #define foreach_vxlan_gpe_input_next \ |
| 160 | _(DROP, "error-drop") \ |
| 161 | _(IP4_INPUT, "ip4-input") \ |
| 162 | _(IP6_INPUT, "ip6-input") \ |
Hongjun Ni | 7deb139 | 2016-06-15 22:49:23 +0800 | [diff] [blame] | 163 | _(ETHERNET_INPUT, "ethernet-input") |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 164 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 165 | /** struct for next nodes for VXLAN GPE input */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 166 | typedef enum { |
| 167 | #define _(s,n) VXLAN_GPE_INPUT_NEXT_##s, |
| 168 | foreach_vxlan_gpe_input_next |
| 169 | #undef _ |
| 170 | VXLAN_GPE_INPUT_N_NEXT, |
| 171 | } vxlan_gpe_input_next_t; |
| 172 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 173 | /** struct for VXLAN GPE errors */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 174 | typedef enum { |
| 175 | #define vxlan_gpe_error(n,s) VXLAN_GPE_ERROR_##n, |
| 176 | #include <vnet/vxlan-gpe/vxlan_gpe_error.def> |
| 177 | #undef vxlan_gpe_error |
| 178 | VXLAN_GPE_N_ERROR, |
| 179 | } vxlan_gpe_input_error_t; |
| 180 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 181 | /** Struct for VXLAN GPE node state */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 182 | typedef struct { |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 183 | /** vector of encap tunnel instances */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 184 | vxlan_gpe_tunnel_t *tunnels; |
| 185 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 186 | /** lookup IPv4 VXLAN GPE tunnel by key */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 187 | uword * vxlan4_gpe_tunnel_by_key; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 188 | /** lookup IPv6 VXLAN GPE tunnel by key */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 189 | uword * vxlan6_gpe_tunnel_by_key; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 190 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 191 | /* local VTEP IPs ref count used by vxlan-bypass node to check if |
| 192 | received VXLAN packet DIP matches any local VTEP address */ |
| 193 | uword * vtep4; /* local ip4 VTEPs keyed on their ip4 addr */ |
| 194 | uword * vtep6; /* local ip6 VTEPs keyed on their ip6 addr */ |
| 195 | /* mcast shared info */ |
| 196 | uword * mcast_shared; /* keyed on mcast ip46 addr */ |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 197 | /** Free vlib hw_if_indices */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 198 | u32 * free_vxlan_gpe_tunnel_hw_if_indices; |
| 199 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 200 | /** Mapping from sw_if_index to tunnel index */ |
Hongjun Ni | 0e06e2b | 2016-05-30 19:45:51 +0800 | [diff] [blame] | 201 | u32 * tunnel_index_by_sw_if_index; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 202 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 203 | /** State convenience vlib_main_t */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 204 | vlib_main_t * vlib_main; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 205 | /** State convenience vnet_main_t */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 206 | vnet_main_t * vnet_main; |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 207 | |
| 208 | /** List of next nodes for the decap indexed on protocol */ |
| 209 | uword decap_next_node_list[VXLAN_GPE_PROTOCOL_MAX]; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 210 | } vxlan_gpe_main_t; |
| 211 | |
| 212 | vxlan_gpe_main_t vxlan_gpe_main; |
| 213 | |
| 214 | extern vlib_node_registration_t vxlan_gpe_encap_node; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 215 | extern vlib_node_registration_t vxlan4_gpe_input_node; |
| 216 | extern vlib_node_registration_t vxlan6_gpe_input_node; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 217 | |
| 218 | u8 * format_vxlan_gpe_encap_trace (u8 * s, va_list * args); |
| 219 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 220 | /** Struct for VXLAN GPE add/del args */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 221 | typedef struct { |
| 222 | u8 is_add; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 223 | u8 is_ip6; |
| 224 | ip46_address_t local, remote; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 225 | u8 protocol; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 226 | u32 mcast_sw_if_index; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 227 | u32 encap_fib_index; |
| 228 | u32 decap_fib_index; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 229 | u32 vni; |
| 230 | } vnet_vxlan_gpe_add_del_tunnel_args_t; |
| 231 | |
| 232 | |
Hongjun Ni | 7deb139 | 2016-06-15 22:49:23 +0800 | [diff] [blame] | 233 | int vnet_vxlan_gpe_add_del_tunnel |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 234 | (vnet_vxlan_gpe_add_del_tunnel_args_t *a, u32 * sw_if_indexp); |
| 235 | |
| 236 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 237 | int vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size, |
| 238 | u8 protocol_override, uword encap_next_node); |
| 239 | int vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size, |
| 240 | u8 protocol_override, uword encap_next_node); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 241 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 242 | /** |
| 243 | * @brief Struct for defining VXLAN GPE next nodes |
| 244 | */ |
| 245 | typedef enum { |
| 246 | VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP, |
| 247 | VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP, |
| 248 | VXLAN_GPE_ENCAP_NEXT_DROP, |
| 249 | VXLAN_GPE_ENCAP_N_NEXT |
| 250 | } vxlan_gpe_encap_next_t; |
| 251 | |
| 252 | |
| 253 | void vxlan_gpe_unregister_decap_protocol (u8 protocol_id, uword next_node_index); |
| 254 | |
| 255 | void vxlan_gpe_register_decap_protocol (u8 protocol_id, uword next_node_index); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 256 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 257 | void vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, u8 is_ip6, u8 is_enable); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 258 | |
| 259 | #endif /* included_vnet_vxlan_gpe_h */ |