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> |
| 28 | #include <vnet/ethernet/ethernet.h> |
| 29 | #include <vnet/vxlan-gpe/vxlan_gpe_packet.h> |
| 30 | #include <vnet/ip/ip4_packet.h> |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 31 | #include <vnet/ip/ip6_packet.h> |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 32 | #include <vnet/ip/udp.h> |
| 33 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 34 | /** |
| 35 | * @brief VXLAN GPE header struct |
| 36 | * |
| 37 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 38 | typedef CLIB_PACKED (struct { |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 39 | /** 20 bytes */ |
| 40 | ip4_header_t ip4; |
| 41 | /** 8 bytes */ |
| 42 | udp_header_t udp; |
| 43 | /** 8 bytes */ |
| 44 | vxlan_gpe_header_t vxlan; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 45 | }) ip4_vxlan_gpe_header_t; |
| 46 | |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 47 | typedef CLIB_PACKED (struct { |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 48 | /** 40 bytes */ |
| 49 | ip6_header_t ip6; |
| 50 | /** 8 bytes */ |
| 51 | udp_header_t udp; |
| 52 | /** 8 bytes */ |
| 53 | vxlan_gpe_header_t vxlan; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 54 | }) ip6_vxlan_gpe_header_t; |
| 55 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 56 | /** |
| 57 | * @brief Key struct for IPv4 VXLAN GPE tunnel. |
| 58 | * Key fields: local remote, vni |
| 59 | * all fields in NET byte order |
| 60 | * VNI shifted 8 bits |
| 61 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 62 | typedef CLIB_PACKED(struct { |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 63 | union { |
| 64 | struct { |
| 65 | u32 local; |
| 66 | u32 remote; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 67 | |
| 68 | u32 vni; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 69 | u32 pad; |
| 70 | }; |
| 71 | u64 as_u64[2]; |
| 72 | }; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 73 | }) vxlan4_gpe_tunnel_key_t; |
| 74 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 75 | /** |
| 76 | * @brief Key struct for IPv6 VXLAN GPE tunnel. |
| 77 | * Key fields: local remote, vni |
| 78 | * all fields in NET byte order |
| 79 | * VNI shifted 8 bits |
| 80 | */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 81 | typedef CLIB_PACKED(struct { |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 82 | ip6_address_t local; |
| 83 | ip6_address_t remote; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 84 | u32 vni; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 85 | }) vxlan6_gpe_tunnel_key_t; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 86 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 87 | /** |
| 88 | * @brief Struct for VXLAN GPE tunnel |
| 89 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 90 | typedef struct { |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 91 | /** Rewrite string. $$$$ embed vnet_rewrite header */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 92 | u8 * rewrite; |
| 93 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 94 | /** encapsulated protocol */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 95 | u8 protocol; |
| 96 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 97 | /** tunnel local address */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 98 | ip46_address_t local; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 99 | /** tunnel remote address */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 100 | ip46_address_t remote; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 101 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 102 | /** FIB indices - tunnel partner lookup here */ |
| 103 | u32 encap_fib_index; |
| 104 | /** FIB indices - inner IP packet lookup here */ |
| 105 | u32 decap_fib_index; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 106 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 107 | /** VXLAN GPE VNI in HOST byte order, shifted left 8 bits */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 108 | u32 vni; |
| 109 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 110 | /** vnet intfc hw_if_index */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 111 | u32 hw_if_index; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 112 | /** vnet intfc sw_if_index */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 113 | u32 sw_if_index; |
| 114 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 115 | /** flags */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 116 | u32 flags; |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 117 | |
| 118 | /** rewrite size for dynamic plugins like iOAM */ |
| 119 | u8 rewrite_size; |
| 120 | |
| 121 | /** Next node after VxLAN-GPE encap */ |
| 122 | uword encap_next_node; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 123 | } vxlan_gpe_tunnel_t; |
| 124 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 125 | /** Flags for vxlan_gpe_tunnel_t */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 126 | #define VXLAN_GPE_TUNNEL_IS_IPV4 1 |
| 127 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 128 | /** next nodes for VXLAN GPE input */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 129 | #define foreach_vxlan_gpe_input_next \ |
| 130 | _(DROP, "error-drop") \ |
| 131 | _(IP4_INPUT, "ip4-input") \ |
| 132 | _(IP6_INPUT, "ip6-input") \ |
Hongjun Ni | 7deb139 | 2016-06-15 22:49:23 +0800 | [diff] [blame] | 133 | _(ETHERNET_INPUT, "ethernet-input") |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 134 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 135 | /** struct for next nodes for VXLAN GPE input */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 136 | typedef enum { |
| 137 | #define _(s,n) VXLAN_GPE_INPUT_NEXT_##s, |
| 138 | foreach_vxlan_gpe_input_next |
| 139 | #undef _ |
| 140 | VXLAN_GPE_INPUT_N_NEXT, |
| 141 | } vxlan_gpe_input_next_t; |
| 142 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 143 | /** struct for VXLAN GPE errors */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 144 | typedef enum { |
| 145 | #define vxlan_gpe_error(n,s) VXLAN_GPE_ERROR_##n, |
| 146 | #include <vnet/vxlan-gpe/vxlan_gpe_error.def> |
| 147 | #undef vxlan_gpe_error |
| 148 | VXLAN_GPE_N_ERROR, |
| 149 | } vxlan_gpe_input_error_t; |
| 150 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 151 | /** Struct for VXLAN GPE node state */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 152 | typedef struct { |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 153 | /** vector of encap tunnel instances */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 154 | vxlan_gpe_tunnel_t *tunnels; |
| 155 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 156 | /** lookup IPv4 VXLAN GPE tunnel by key */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 157 | uword * vxlan4_gpe_tunnel_by_key; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 158 | /** lookup IPv6 VXLAN GPE tunnel by key */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 159 | uword * vxlan6_gpe_tunnel_by_key; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 160 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 161 | /** Free vlib hw_if_indices */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 162 | u32 * free_vxlan_gpe_tunnel_hw_if_indices; |
| 163 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 164 | /** Mapping from sw_if_index to tunnel index */ |
Hongjun Ni | 0e06e2b | 2016-05-30 19:45:51 +0800 | [diff] [blame] | 165 | u32 * tunnel_index_by_sw_if_index; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 166 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 167 | /** State convenience vlib_main_t */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 168 | vlib_main_t * vlib_main; |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 169 | /** State convenience vnet_main_t */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 170 | vnet_main_t * vnet_main; |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 171 | |
| 172 | /** List of next nodes for the decap indexed on protocol */ |
| 173 | uword decap_next_node_list[VXLAN_GPE_PROTOCOL_MAX]; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 174 | } vxlan_gpe_main_t; |
| 175 | |
| 176 | vxlan_gpe_main_t vxlan_gpe_main; |
| 177 | |
| 178 | extern vlib_node_registration_t vxlan_gpe_encap_node; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 179 | extern vlib_node_registration_t vxlan4_gpe_input_node; |
| 180 | extern vlib_node_registration_t vxlan6_gpe_input_node; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 181 | |
| 182 | u8 * format_vxlan_gpe_encap_trace (u8 * s, va_list * args); |
| 183 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 184 | /** Struct for VXLAN GPE add/del args */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 185 | typedef struct { |
| 186 | u8 is_add; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 187 | u8 is_ip6; |
| 188 | ip46_address_t local, remote; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 189 | u8 protocol; |
| 190 | u32 encap_fib_index; |
| 191 | u32 decap_fib_index; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 192 | u32 vni; |
| 193 | } vnet_vxlan_gpe_add_del_tunnel_args_t; |
| 194 | |
| 195 | |
Hongjun Ni | 7deb139 | 2016-06-15 22:49:23 +0800 | [diff] [blame] | 196 | int vnet_vxlan_gpe_add_del_tunnel |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 197 | (vnet_vxlan_gpe_add_del_tunnel_args_t *a, u32 * sw_if_indexp); |
| 198 | |
| 199 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 200 | int vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size, |
| 201 | u8 protocol_override, uword encap_next_node); |
| 202 | int vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size, |
| 203 | u8 protocol_override, uword encap_next_node); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 204 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 205 | /** |
| 206 | * @brief Struct for defining VXLAN GPE next nodes |
| 207 | */ |
| 208 | typedef enum { |
| 209 | VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP, |
| 210 | VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP, |
| 211 | VXLAN_GPE_ENCAP_NEXT_DROP, |
| 212 | VXLAN_GPE_ENCAP_N_NEXT |
| 213 | } vxlan_gpe_encap_next_t; |
| 214 | |
| 215 | |
| 216 | void vxlan_gpe_unregister_decap_protocol (u8 protocol_id, uword next_node_index); |
| 217 | |
| 218 | 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] | 219 | |
| 220 | |
| 221 | #endif /* included_vnet_vxlan_gpe_h */ |