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 Common utility functions for IPv4 and IPv6 VXLAN GPE tunnels |
| 18 | * |
| 19 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 20 | #include <vnet/vxlan-gpe/vxlan_gpe.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 21 | #include <vnet/fib/fib.h> |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 22 | #include <vnet/ip/format.h> |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 23 | #include <vnet/fib/fib_entry.h> |
| 24 | #include <vnet/fib/fib_table.h> |
| 25 | #include <vnet/mfib/mfib_table.h> |
| 26 | #include <vnet/adj/adj_mcast.h> |
| 27 | #include <vnet/interface.h> |
| 28 | #include <vlib/vlib.h> |
| 29 | |
| 30 | /** |
| 31 | * @file |
| 32 | * @brief VXLAN-GPE. |
| 33 | * |
| 34 | * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs) |
| 35 | * to span multiple servers. This is done by building an L2 overlay on |
| 36 | * top of an L3 network underlay using VXLAN-GPE tunnels. |
| 37 | * |
| 38 | * This makes it possible for servers to be co-located in the same data |
| 39 | * center or be separated geographically as long as they are reachable |
| 40 | * through the underlay L3 network. |
| 41 | * |
| 42 | * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE segment. |
| 43 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 44 | |
| 45 | vxlan_gpe_main_t vxlan_gpe_main; |
| 46 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 47 | /** |
| 48 | * @brief Tracing function for VXLAN GPE tunnel packets |
| 49 | * |
| 50 | * @param *s formatting string |
| 51 | * @param *args |
| 52 | * |
| 53 | * @return *s formatted string |
| 54 | * |
| 55 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 56 | u8 * format_vxlan_gpe_tunnel (u8 * s, va_list * args) |
| 57 | { |
| 58 | vxlan_gpe_tunnel_t * t = va_arg (*args, vxlan_gpe_tunnel_t *); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 59 | vxlan_gpe_main_t * ngm = &vxlan_gpe_main; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 60 | |
| 61 | s = format (s, "[%d] local: %U remote: %U ", |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 62 | t - ngm->tunnels, |
Hongjun Ni | c8af24f | 2016-08-05 00:58:20 +0800 | [diff] [blame] | 63 | format_ip46_address, &t->local, IP46_TYPE_ANY, |
| 64 | format_ip46_address, &t->remote, IP46_TYPE_ANY); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 65 | |
| 66 | s = format (s, " vxlan VNI %d ", t->vni); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 67 | |
| 68 | switch (t->protocol) |
| 69 | { |
| 70 | case VXLAN_GPE_PROTOCOL_IP4: |
| 71 | s = format (s, "next-protocol ip4"); |
Hongjun Ni | 4a71314 | 2016-05-24 02:54:10 +0800 | [diff] [blame] | 72 | break; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 73 | case VXLAN_GPE_PROTOCOL_IP6: |
| 74 | s = format (s, "next-protocol ip6"); |
Hongjun Ni | 4a71314 | 2016-05-24 02:54:10 +0800 | [diff] [blame] | 75 | break; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 76 | case VXLAN_GPE_PROTOCOL_ETHERNET: |
| 77 | s = format (s, "next-protocol ethernet"); |
Hongjun Ni | 4a71314 | 2016-05-24 02:54:10 +0800 | [diff] [blame] | 78 | break; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 79 | case VXLAN_GPE_PROTOCOL_NSH: |
| 80 | s = format (s, "next-protocol nsh"); |
Hongjun Ni | 4a71314 | 2016-05-24 02:54:10 +0800 | [diff] [blame] | 81 | break; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 82 | default: |
| 83 | s = format (s, "next-protocol unknown %d", t->protocol); |
| 84 | } |
| 85 | |
Hongjun Ni | 04ffd0ad | 2017-06-23 00:18:40 +0800 | [diff] [blame] | 86 | if (ip46_address_is_multicast (&t->remote)) |
| 87 | s = format (s, "mcast_sw_if_index %d ", t->mcast_sw_if_index); |
| 88 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 89 | s = format (s, " fibs: (encap %d, decap %d)", |
| 90 | t->encap_fib_index, |
| 91 | t->decap_fib_index); |
| 92 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 93 | return s; |
| 94 | } |
| 95 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 96 | /** |
| 97 | * @brief Naming for VXLAN GPE tunnel |
| 98 | * |
| 99 | * @param *s formatting string |
| 100 | * @param *args |
| 101 | * |
| 102 | * @return *s formatted string |
| 103 | * |
| 104 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 105 | static u8 * format_vxlan_gpe_name (u8 * s, va_list * args) |
| 106 | { |
Hongjun Ni | 0e06e2b | 2016-05-30 19:45:51 +0800 | [diff] [blame] | 107 | u32 dev_instance = va_arg (*args, u32); |
| 108 | return format (s, "vxlan_gpe_tunnel%d", dev_instance); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 111 | static uword dummy_interface_tx (vlib_main_t * vm, |
| 112 | vlib_node_runtime_t * node, |
| 113 | vlib_frame_t * frame) |
| 114 | { |
| 115 | clib_warning ("you shouldn't be here, leaking buffers..."); |
| 116 | return frame->n_vectors; |
| 117 | } |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * @brief CLI function for VXLAN GPE admin up/down |
| 121 | * |
| 122 | * @param *vnm |
| 123 | * @param hw_if_index |
| 124 | * @param flag |
| 125 | * |
| 126 | * @return *rc |
| 127 | * |
| 128 | */ |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 129 | static clib_error_t * |
| 130 | vxlan_gpe_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags) |
| 131 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 132 | u32 hw_flags = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? |
| 133 | VNET_HW_INTERFACE_FLAG_LINK_UP : 0; |
| 134 | vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags); |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
Hongjun Ni | 0e06e2b | 2016-05-30 19:45:51 +0800 | [diff] [blame] | 139 | VNET_DEVICE_CLASS (vxlan_gpe_device_class,static) = { |
| 140 | .name = "VXLAN_GPE", |
| 141 | .format_device_name = format_vxlan_gpe_name, |
| 142 | .format_tx_trace = format_vxlan_gpe_encap_trace, |
| 143 | .tx_function = dummy_interface_tx, |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 144 | .admin_up_down_function = vxlan_gpe_interface_admin_up_down, |
Hongjun Ni | 0e06e2b | 2016-05-30 19:45:51 +0800 | [diff] [blame] | 145 | }; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 146 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 147 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 148 | /** |
| 149 | * @brief Formatting function for tracing VXLAN GPE with length |
| 150 | * |
| 151 | * @param *s |
| 152 | * @param *args |
| 153 | * |
| 154 | * @return *s |
| 155 | * |
| 156 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 157 | static u8 * format_vxlan_gpe_header_with_length (u8 * s, va_list * args) |
| 158 | { |
| 159 | u32 dev_instance = va_arg (*args, u32); |
| 160 | s = format (s, "unimplemented dev %u", dev_instance); |
| 161 | return s; |
| 162 | } |
| 163 | |
| 164 | VNET_HW_INTERFACE_CLASS (vxlan_gpe_hw_class) = { |
| 165 | .name = "VXLAN_GPE", |
| 166 | .format_header = format_vxlan_gpe_header_with_length, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 167 | .build_rewrite = default_build_rewrite, |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 168 | }; |
| 169 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 170 | static void |
| 171 | vxlan_gpe_tunnel_restack_dpo(vxlan_gpe_tunnel_t * t) |
| 172 | { |
| 173 | dpo_id_t dpo = DPO_INVALID; |
| 174 | u32 encap_index = vxlan_gpe_encap_node.index; |
| 175 | fib_forward_chain_type_t forw_type = ip46_address_is_ip4(&t->remote) ? |
| 176 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4 : FIB_FORW_CHAIN_TYPE_UNICAST_IP6; |
| 177 | |
| 178 | fib_entry_contribute_forwarding (t->fib_entry_index, forw_type, &dpo); |
| 179 | dpo_stack_from_node (encap_index, &t->next_dpo, &dpo); |
| 180 | dpo_reset(&dpo); |
| 181 | } |
| 182 | |
| 183 | static vxlan_gpe_tunnel_t * |
| 184 | vxlan_gpe_tunnel_from_fib_node (fib_node_t *node) |
| 185 | { |
| 186 | #if (CLIB_DEBUG > 0) |
| 187 | ASSERT(FIB_NODE_TYPE_VXLAN_GPE_TUNNEL == node->fn_type); |
| 188 | #endif |
| 189 | return ((vxlan_gpe_tunnel_t*) (((char*)node) - |
| 190 | STRUCT_OFFSET_OF(vxlan_gpe_tunnel_t, node))); |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Function definition to backwalk a FIB node - |
| 195 | * Here we will restack the new dpo of VXLAN_GPE DIP to encap node. |
| 196 | */ |
| 197 | static fib_node_back_walk_rc_t |
| 198 | vxlan_gpe_tunnel_back_walk (fib_node_t *node, |
| 199 | fib_node_back_walk_ctx_t *ctx) |
| 200 | { |
| 201 | vxlan_gpe_tunnel_restack_dpo(vxlan_gpe_tunnel_from_fib_node(node)); |
| 202 | return (FIB_NODE_BACK_WALK_CONTINUE); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Function definition to get a FIB node from its index |
| 207 | */ |
| 208 | static fib_node_t* |
| 209 | vxlan_gpe_tunnel_fib_node_get (fib_node_index_t index) |
| 210 | { |
| 211 | vxlan_gpe_tunnel_t * t; |
| 212 | vxlan_gpe_main_t * ngm = &vxlan_gpe_main; |
| 213 | |
| 214 | t = pool_elt_at_index(ngm->tunnels, index); |
| 215 | |
| 216 | return (&t->node); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Function definition to inform the FIB node that its last lock has gone. |
| 221 | */ |
| 222 | static void |
| 223 | vxlan_gpe_tunnel_last_lock_gone (fib_node_t *node) |
| 224 | { |
| 225 | /* |
| 226 | * The VXLAN_GPE tunnel is a root of the graph. As such |
| 227 | * it never has children and thus is never locked. |
| 228 | */ |
| 229 | ASSERT(0); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * Virtual function table registered by VXLAN_GPE tunnels |
| 234 | * for participation in the FIB object graph. |
| 235 | */ |
| 236 | const static fib_node_vft_t vxlan_gpe_vft = { |
| 237 | .fnv_get = vxlan_gpe_tunnel_fib_node_get, |
| 238 | .fnv_last_lock = vxlan_gpe_tunnel_last_lock_gone, |
| 239 | .fnv_back_walk = vxlan_gpe_tunnel_back_walk, |
| 240 | }; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 241 | |
| 242 | #define foreach_gpe_copy_field \ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 243 | _(vni) \ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 244 | _(protocol) \ |
| 245 | _(mcast_sw_if_index) \ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 246 | _(encap_fib_index) \ |
Hongjun Ni | 7deb139 | 2016-06-15 22:49:23 +0800 | [diff] [blame] | 247 | _(decap_fib_index) |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 248 | |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 249 | #define foreach_copy_ipv4 { \ |
| 250 | _(local.ip4.as_u32) \ |
| 251 | _(remote.ip4.as_u32) \ |
| 252 | } |
| 253 | |
| 254 | #define foreach_copy_ipv6 { \ |
| 255 | _(local.ip6.as_u64[0]) \ |
| 256 | _(local.ip6.as_u64[1]) \ |
| 257 | _(remote.ip6.as_u64[0]) \ |
| 258 | _(remote.ip6.as_u64[1]) \ |
| 259 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 260 | |
| 261 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 262 | /** |
| 263 | * @brief Calculate IPv4 VXLAN GPE rewrite header |
| 264 | * |
| 265 | * @param *t |
| 266 | * |
| 267 | * @return rc |
| 268 | * |
| 269 | */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 270 | int vxlan4_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size, |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 271 | u8 protocol_override, uword encap_next_node) |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 272 | { |
| 273 | u8 *rw = 0; |
| 274 | ip4_header_t * ip0; |
| 275 | ip4_vxlan_gpe_header_t * h0; |
| 276 | int len; |
| 277 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 278 | len = sizeof (*h0) + extension_size; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 279 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 280 | vec_free(t->rewrite); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 281 | vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES); |
| 282 | |
| 283 | h0 = (ip4_vxlan_gpe_header_t *) rw; |
| 284 | |
| 285 | /* Fixed portion of the (outer) ip4 header */ |
| 286 | ip0 = &h0->ip4; |
| 287 | ip0->ip_version_and_header_length = 0x45; |
| 288 | ip0->ttl = 254; |
| 289 | ip0->protocol = IP_PROTOCOL_UDP; |
| 290 | |
| 291 | /* we fix up the ip4 header length and checksum after-the-fact */ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 292 | ip0->src_address.as_u32 = t->local.ip4.as_u32; |
| 293 | ip0->dst_address.as_u32 = t->remote.ip4.as_u32; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 294 | ip0->checksum = ip4_header_checksum (ip0); |
| 295 | |
| 296 | /* UDP header, randomize src port on something, maybe? */ |
| 297 | h0->udp.src_port = clib_host_to_net_u16 (4790); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 298 | h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 299 | |
| 300 | /* VXLAN header. Are we having fun yet? */ |
| 301 | h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P; |
| 302 | h0->vxlan.ver_res = VXLAN_GPE_VERSION; |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 303 | if (protocol_override) |
| 304 | { |
| 305 | h0->vxlan.protocol = protocol_override; |
| 306 | } |
| 307 | else |
| 308 | { |
| 309 | h0->vxlan.protocol = t->protocol; |
| 310 | } |
| 311 | t->rewrite_size = sizeof(ip4_vxlan_gpe_header_t) + extension_size; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 312 | h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni<<8); |
| 313 | |
| 314 | t->rewrite = rw; |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 315 | t->encap_next_node = encap_next_node; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 316 | return (0); |
| 317 | } |
| 318 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 319 | /** |
| 320 | * @brief Calculate IPv6 VXLAN GPE rewrite header |
| 321 | * |
| 322 | * @param *t |
| 323 | * |
| 324 | * @return rc |
| 325 | * |
| 326 | */ |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 327 | int vxlan6_gpe_rewrite (vxlan_gpe_tunnel_t * t, u32 extension_size, |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 328 | u8 protocol_override, uword encap_next_node) |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 329 | { |
| 330 | u8 *rw = 0; |
| 331 | ip6_header_t * ip0; |
| 332 | ip6_vxlan_gpe_header_t * h0; |
| 333 | int len; |
| 334 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 335 | len = sizeof (*h0) + extension_size; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 336 | |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 337 | vec_free(t->rewrite); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 338 | vec_validate_aligned (rw, len-1, CLIB_CACHE_LINE_BYTES); |
| 339 | |
| 340 | h0 = (ip6_vxlan_gpe_header_t *) rw; |
| 341 | |
| 342 | /* Fixed portion of the (outer) ip4 header */ |
| 343 | ip0 = &h0->ip6; |
| 344 | ip0->ip_version_traffic_class_and_flow_label = clib_host_to_net_u32(6 << 28); |
| 345 | ip0->hop_limit = 255; |
| 346 | ip0->protocol = IP_PROTOCOL_UDP; |
| 347 | |
| 348 | ip0->src_address.as_u64[0] = t->local.ip6.as_u64[0]; |
| 349 | ip0->src_address.as_u64[1] = t->local.ip6.as_u64[1]; |
| 350 | ip0->dst_address.as_u64[0] = t->remote.ip6.as_u64[0]; |
| 351 | ip0->dst_address.as_u64[1] = t->remote.ip6.as_u64[1]; |
| 352 | |
| 353 | /* UDP header, randomize src port on something, maybe? */ |
| 354 | h0->udp.src_port = clib_host_to_net_u16 (4790); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 355 | h0->udp.dst_port = clib_host_to_net_u16 (UDP_DST_PORT_VXLAN_GPE); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 356 | |
| 357 | /* VXLAN header. Are we having fun yet? */ |
| 358 | h0->vxlan.flags = VXLAN_GPE_FLAGS_I | VXLAN_GPE_FLAGS_P; |
| 359 | h0->vxlan.ver_res = VXLAN_GPE_VERSION; |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 360 | if (protocol_override) |
| 361 | { |
| 362 | h0->vxlan.protocol = t->protocol; |
| 363 | } |
| 364 | else |
| 365 | { |
| 366 | h0->vxlan.protocol = protocol_override; |
| 367 | } |
| 368 | t->rewrite_size = sizeof(ip4_vxlan_gpe_header_t) + extension_size; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 369 | h0->vxlan.vni_res = clib_host_to_net_u32 (t->vni<<8); |
| 370 | |
| 371 | t->rewrite = rw; |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 372 | t->encap_next_node = encap_next_node; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 373 | return (0); |
| 374 | } |
| 375 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 376 | static void |
| 377 | hash_set_key_copy (uword ** h, void * key, uword v) { |
| 378 | size_t ksz = hash_header(*h)->user; |
| 379 | void * copy = clib_mem_alloc (ksz); |
| 380 | clib_memcpy (copy, key, ksz); |
| 381 | hash_set_mem (*h, copy, v); |
| 382 | } |
| 383 | |
| 384 | static void |
| 385 | hash_unset_key_free (uword ** h, void * key) { |
| 386 | hash_pair_t * hp = hash_get_pair_mem (*h, key); |
| 387 | ASSERT (hp); |
| 388 | key = uword_to_pointer (hp->key, void *); |
| 389 | hash_unset_mem (*h, key); |
| 390 | clib_mem_free (key); |
| 391 | } |
| 392 | |
| 393 | static uword |
| 394 | vtep_addr_ref(ip46_address_t *ip) |
| 395 | { |
| 396 | uword *vtep = ip46_address_is_ip4(ip) ? |
| 397 | hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) : |
| 398 | hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6); |
| 399 | if (vtep) |
| 400 | return ++(*vtep); |
| 401 | ip46_address_is_ip4(ip) ? |
| 402 | hash_set (vxlan_gpe_main.vtep4, ip->ip4.as_u32, 1) : |
| 403 | hash_set_key_copy (&vxlan_gpe_main.vtep6, &ip->ip6, 1); |
| 404 | return 1; |
| 405 | } |
| 406 | |
| 407 | static uword |
| 408 | vtep_addr_unref(ip46_address_t *ip) |
| 409 | { |
| 410 | uword *vtep = ip46_address_is_ip4(ip) ? |
| 411 | hash_get (vxlan_gpe_main.vtep4, ip->ip4.as_u32) : |
| 412 | hash_get_mem (vxlan_gpe_main.vtep6, &ip->ip6); |
| 413 | ASSERT(vtep); |
| 414 | if (--(*vtep) != 0) |
| 415 | return *vtep; |
| 416 | ip46_address_is_ip4(ip) ? |
| 417 | hash_unset (vxlan_gpe_main.vtep4, ip->ip4.as_u32) : |
| 418 | hash_unset_key_free (&vxlan_gpe_main.vtep6, &ip->ip6); |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | typedef CLIB_PACKED(union { |
| 423 | struct { |
| 424 | fib_node_index_t mfib_entry_index; |
| 425 | adj_index_t mcast_adj_index; |
| 426 | }; |
| 427 | u64 as_u64; |
| 428 | }) mcast_shared_t; |
| 429 | |
| 430 | static inline mcast_shared_t |
| 431 | mcast_shared_get(ip46_address_t * ip) |
| 432 | { |
| 433 | ASSERT(ip46_address_is_multicast(ip)); |
| 434 | uword * p = hash_get_mem (vxlan_gpe_main.mcast_shared, ip); |
| 435 | ASSERT(p); |
| 436 | return (mcast_shared_t) { .as_u64 = *p }; |
| 437 | } |
| 438 | |
| 439 | static inline void |
| 440 | mcast_shared_add(ip46_address_t *remote, |
| 441 | fib_node_index_t mfei, |
| 442 | adj_index_t ai) |
| 443 | { |
| 444 | mcast_shared_t new_ep = { |
| 445 | .mcast_adj_index = ai, |
| 446 | .mfib_entry_index = mfei, |
| 447 | }; |
| 448 | |
| 449 | hash_set_key_copy (&vxlan_gpe_main.mcast_shared, remote, new_ep.as_u64); |
| 450 | } |
| 451 | |
| 452 | static inline void |
| 453 | mcast_shared_remove(ip46_address_t *remote) |
| 454 | { |
| 455 | mcast_shared_t ep = mcast_shared_get(remote); |
| 456 | |
| 457 | adj_unlock(ep.mcast_adj_index); |
| 458 | mfib_table_entry_delete_index(ep.mfib_entry_index, |
| 459 | MFIB_SOURCE_VXLAN_GPE); |
| 460 | |
| 461 | hash_unset_key_free (&vxlan_gpe_main.mcast_shared, remote); |
| 462 | } |
| 463 | |
| 464 | static inline fib_protocol_t |
| 465 | fib_ip_proto(bool is_ip6) |
| 466 | { |
| 467 | return (is_ip6) ? FIB_PROTOCOL_IP6 : FIB_PROTOCOL_IP4; |
| 468 | } |
| 469 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 470 | /** |
| 471 | * @brief Add or Del a VXLAN GPE tunnel |
| 472 | * |
| 473 | * @param *a |
| 474 | * @param *sw_if_index |
| 475 | * |
| 476 | * @return rc |
| 477 | * |
| 478 | */ |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 479 | int vnet_vxlan_gpe_add_del_tunnel |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 480 | (vnet_vxlan_gpe_add_del_tunnel_args_t *a, u32 * sw_if_indexp) |
| 481 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 482 | vxlan_gpe_main_t * ngm = &vxlan_gpe_main; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 483 | vxlan_gpe_tunnel_t *t = 0; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 484 | vnet_main_t * vnm = ngm->vnet_main; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 485 | vnet_hw_interface_t * hi; |
| 486 | uword * p; |
| 487 | u32 hw_if_index = ~0; |
| 488 | u32 sw_if_index = ~0; |
| 489 | int rv; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 490 | vxlan4_gpe_tunnel_key_t key4, *key4_copy; |
| 491 | vxlan6_gpe_tunnel_key_t key6, *key6_copy; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 492 | u32 is_ip6 = a->is_ip6; |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 493 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 494 | if (!is_ip6) |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 495 | { |
| 496 | key4.local = a->local.ip4.as_u32; |
| 497 | key4.remote = a->remote.ip4.as_u32; |
| 498 | key4.vni = clib_host_to_net_u32 (a->vni << 8); |
| 499 | key4.pad = 0; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 500 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 501 | p = hash_get_mem(ngm->vxlan4_gpe_tunnel_by_key, &key4); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 502 | } |
| 503 | else |
| 504 | { |
| 505 | key6.local.as_u64[0] = a->local.ip6.as_u64[0]; |
| 506 | key6.local.as_u64[1] = a->local.ip6.as_u64[1]; |
| 507 | key6.remote.as_u64[0] = a->remote.ip6.as_u64[0]; |
| 508 | key6.remote.as_u64[1] = a->remote.ip6.as_u64[1]; |
| 509 | key6.vni = clib_host_to_net_u32 (a->vni << 8); |
| 510 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 511 | p = hash_get_mem(ngm->vxlan6_gpe_tunnel_by_key, &key6); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 512 | } |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 513 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 514 | if (a->is_add) |
| 515 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 516 | l2input_main_t * l2im = &l2input_main; |
| 517 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 518 | /* adding a tunnel: tunnel must not already exist */ |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 519 | if (p) |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 520 | return VNET_API_ERROR_TUNNEL_EXIST; |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 521 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 522 | pool_get_aligned (ngm->tunnels, t, CLIB_CACHE_LINE_BYTES); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 523 | memset (t, 0, sizeof (*t)); |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 524 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 525 | /* copy from arg structure */ |
| 526 | #define _(x) t->x = a->x; |
| 527 | foreach_gpe_copy_field; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 528 | if (!a->is_ip6) foreach_copy_ipv4 |
| 529 | else foreach_copy_ipv6 |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 530 | #undef _ |
| 531 | |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 532 | if (!a->is_ip6) t->flags |= VXLAN_GPE_TUNNEL_IS_IPV4; |
| 533 | |
| 534 | if (!a->is_ip6) { |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 535 | rv = vxlan4_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP4_LOOKUP); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 536 | } else { |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 537 | rv = vxlan6_gpe_rewrite (t, 0, 0, VXLAN_GPE_ENCAP_NEXT_IP6_LOOKUP); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 538 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 539 | |
| 540 | if (rv) |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 541 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 542 | pool_put (ngm->tunnels, t); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 543 | return rv; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 544 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 545 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 546 | if (!is_ip6) |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 547 | { |
| 548 | key4_copy = clib_mem_alloc (sizeof (*key4_copy)); |
| 549 | clib_memcpy (key4_copy, &key4, sizeof (*key4_copy)); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 550 | hash_set_mem (ngm->vxlan4_gpe_tunnel_by_key, key4_copy, |
| 551 | t - ngm->tunnels); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 552 | } |
| 553 | else |
| 554 | { |
| 555 | key6_copy = clib_mem_alloc (sizeof (*key6_copy)); |
Florin Coras | 1d3b2ab | 2016-05-31 15:53:44 +0300 | [diff] [blame] | 556 | clib_memcpy (key6_copy, &key6, sizeof (*key6_copy)); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 557 | hash_set_mem (ngm->vxlan6_gpe_tunnel_by_key, key6_copy, |
| 558 | t - ngm->tunnels); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 559 | } |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 560 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 561 | if (vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) > 0) |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 562 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 563 | vnet_interface_main_t * im = &vnm->interface_main; |
| 564 | hw_if_index = ngm->free_vxlan_gpe_tunnel_hw_if_indices |
| 565 | [vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices)-1]; |
| 566 | _vec_len (ngm->free_vxlan_gpe_tunnel_hw_if_indices) -= 1; |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 567 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 568 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 569 | hi->dev_instance = t - ngm->tunnels; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 570 | hi->hw_instance = hi->dev_instance; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 571 | /* clear old stats of freed tunnel before reuse */ |
| 572 | sw_if_index = hi->sw_if_index; |
| 573 | vnet_interface_counter_lock(im); |
| 574 | vlib_zero_combined_counter |
| 575 | (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_TX], sw_if_index); |
| 576 | vlib_zero_combined_counter |
| 577 | (&im->combined_sw_if_counters[VNET_INTERFACE_COUNTER_RX], sw_if_index); |
| 578 | vlib_zero_simple_counter |
| 579 | (&im->sw_if_counters[VNET_INTERFACE_COUNTER_DROP], sw_if_index); |
| 580 | vnet_interface_counter_unlock(im); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 581 | } |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 582 | else |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 583 | { |
| 584 | hw_if_index = vnet_register_interface |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 585 | (vnm, vxlan_gpe_device_class.index, t - ngm->tunnels, |
| 586 | vxlan_gpe_hw_class.index, t - ngm->tunnels); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 587 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 588 | hi->output_node_index = vxlan_gpe_encap_node.index; |
| 589 | } |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 590 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 591 | t->hw_if_index = hw_if_index; |
| 592 | t->sw_if_index = sw_if_index = hi->sw_if_index; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 593 | vec_validate_init_empty (ngm->tunnel_index_by_sw_if_index, sw_if_index, ~0); |
| 594 | ngm->tunnel_index_by_sw_if_index[sw_if_index] = t - ngm->tunnels; |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 595 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 596 | /* setup l2 input config with l2 feature and bd 0 to drop packet */ |
| 597 | vec_validate (l2im->configs, sw_if_index); |
| 598 | l2im->configs[sw_if_index].feature_bitmap = L2INPUT_FEAT_DROP; |
| 599 | l2im->configs[sw_if_index].bd_index = 0; |
| 600 | |
| 601 | vnet_sw_interface_t * si = vnet_get_sw_interface (vnm, sw_if_index); |
| 602 | si->flags &= ~VNET_SW_INTERFACE_FLAG_HIDDEN; |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 603 | vnet_sw_interface_set_flags (vnm, hi->sw_if_index, |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 604 | VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 605 | fib_node_init(&t->node, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL); |
| 606 | fib_prefix_t tun_remote_pfx; |
| 607 | u32 encap_index = vxlan_gpe_encap_node.index; |
| 608 | vnet_flood_class_t flood_class = VNET_FLOOD_CLASS_TUNNEL_NORMAL; |
| 609 | |
| 610 | fib_prefix_from_ip46_addr(&t->remote, &tun_remote_pfx); |
| 611 | if (!ip46_address_is_multicast(&t->remote)) |
| 612 | { |
| 613 | /* Unicast tunnel - |
| 614 | * source the FIB entry for the tunnel's destination |
| 615 | * and become a child thereof. The tunnel will then get poked |
| 616 | * when the forwarding for the entry updates, and the tunnel can |
| 617 | * re-stack accordingly |
| 618 | */ |
| 619 | vtep_addr_ref(&t->local); |
| 620 | t->fib_entry_index = fib_table_entry_special_add |
| 621 | (t->encap_fib_index, &tun_remote_pfx, FIB_SOURCE_RR, |
| 622 | FIB_ENTRY_FLAG_NONE); |
| 623 | t->sibling_index = fib_entry_child_add |
| 624 | (t->fib_entry_index, FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, t - ngm->tunnels); |
| 625 | vxlan_gpe_tunnel_restack_dpo(t); |
| 626 | } |
| 627 | else |
| 628 | { |
| 629 | /* Multicast tunnel - |
| 630 | * as the same mcast group can be used for mutiple mcast tunnels |
| 631 | * with different VNIs, create the output fib adjecency only if |
| 632 | * it does not already exist |
| 633 | */ |
| 634 | fib_protocol_t fp = fib_ip_proto(is_ip6); |
| 635 | |
| 636 | if (vtep_addr_ref(&t->remote) == 1) |
| 637 | { |
| 638 | fib_node_index_t mfei; |
| 639 | adj_index_t ai; |
| 640 | fib_route_path_t path = { |
| 641 | .frp_proto = fp, |
| 642 | .frp_addr = zero_addr, |
| 643 | .frp_sw_if_index = 0xffffffff, |
| 644 | .frp_fib_index = ~0, |
| 645 | .frp_weight = 0, |
| 646 | .frp_flags = FIB_ROUTE_PATH_LOCAL, |
| 647 | }; |
| 648 | const mfib_prefix_t mpfx = { |
| 649 | .fp_proto = fp, |
| 650 | .fp_len = (is_ip6 ? 128 : 32), |
| 651 | .fp_grp_addr = tun_remote_pfx.fp_addr, |
| 652 | }; |
| 653 | |
| 654 | /* |
| 655 | * Setup the (*,G) to receive traffic on the mcast group |
| 656 | * - the forwarding interface is for-us |
| 657 | * - the accepting interface is that from the API |
| 658 | */ |
| 659 | mfib_table_entry_path_update(t->encap_fib_index, |
| 660 | &mpfx, |
| 661 | MFIB_SOURCE_VXLAN_GPE, |
| 662 | &path, |
| 663 | MFIB_ITF_FLAG_FORWARD); |
| 664 | |
| 665 | path.frp_sw_if_index = a->mcast_sw_if_index; |
| 666 | path.frp_flags = FIB_ROUTE_PATH_FLAG_NONE; |
| 667 | mfei = mfib_table_entry_path_update(t->encap_fib_index, |
| 668 | &mpfx, |
| 669 | MFIB_SOURCE_VXLAN_GPE, |
| 670 | &path, |
| 671 | MFIB_ITF_FLAG_ACCEPT); |
| 672 | |
| 673 | /* |
| 674 | * Create the mcast adjacency to send traffic to the group |
| 675 | */ |
| 676 | ai = adj_mcast_add_or_lock(fp, |
| 677 | fib_proto_to_link(fp), |
| 678 | a->mcast_sw_if_index); |
| 679 | |
| 680 | /* |
| 681 | * create a new end-point |
| 682 | */ |
| 683 | mcast_shared_add(&t->remote, mfei, ai); |
| 684 | } |
| 685 | |
| 686 | dpo_id_t dpo = DPO_INVALID; |
| 687 | mcast_shared_t ep = mcast_shared_get(&t->remote); |
| 688 | |
| 689 | /* Stack shared mcast remote mac addr rewrite on encap */ |
| 690 | dpo_set (&dpo, DPO_ADJACENCY_MCAST, |
| 691 | fib_proto_to_dpo(fp), |
| 692 | ep.mcast_adj_index); |
| 693 | |
| 694 | dpo_stack_from_node (encap_index, &t->next_dpo, &dpo); |
| 695 | dpo_reset (&dpo); |
| 696 | flood_class = VNET_FLOOD_CLASS_TUNNEL_MASTER; |
| 697 | } |
| 698 | |
| 699 | /* Set vxlan tunnel output node */ |
| 700 | hi->output_node_index = encap_index; |
| 701 | |
| 702 | vnet_get_sw_interface (vnet_get_main(), sw_if_index)->flood_class = flood_class; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 703 | } |
| 704 | else |
| 705 | { |
| 706 | /* deleting a tunnel: tunnel must exist */ |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 707 | if (!p) |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 708 | return VNET_API_ERROR_NO_SUCH_ENTRY; |
| 709 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 710 | t = pool_elt_at_index (ngm->tunnels, p[0]); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 711 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 712 | sw_if_index = t->sw_if_index; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 713 | vnet_sw_interface_set_flags (vnm, t->sw_if_index, 0 /* down */); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 714 | vnet_sw_interface_t * si = vnet_get_sw_interface (vnm, t->sw_if_index); |
| 715 | si->flags |= VNET_SW_INTERFACE_FLAG_HIDDEN; |
| 716 | set_int_l2_mode(ngm->vlib_main, vnm, MODE_L3, t->sw_if_index, 0, 0, 0, 0); |
| 717 | vec_add1 (ngm->free_vxlan_gpe_tunnel_hw_if_indices, t->hw_if_index); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 718 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 719 | ngm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0; |
Hongjun Ni | c0959c9 | 2016-06-16 20:18:15 +0800 | [diff] [blame] | 720 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 721 | if (!is_ip6) |
| 722 | hash_unset (ngm->vxlan4_gpe_tunnel_by_key, key4.as_u64); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 723 | else |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 724 | hash_unset_key_free (&ngm->vxlan6_gpe_tunnel_by_key, &key6); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 725 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 726 | if (!ip46_address_is_multicast(&t->remote)) |
| 727 | { |
| 728 | vtep_addr_unref(&t->local); |
| 729 | fib_entry_child_remove(t->fib_entry_index, t->sibling_index); |
| 730 | fib_table_entry_delete_index(t->fib_entry_index, FIB_SOURCE_RR); |
| 731 | } |
| 732 | else if (vtep_addr_unref(&t->remote) == 0) |
| 733 | { |
| 734 | mcast_shared_remove(&t->remote); |
| 735 | } |
| 736 | |
| 737 | fib_node_deinit(&t->node); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 738 | vec_free (t->rewrite); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 739 | pool_put (ngm->tunnels, t); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | if (sw_if_indexp) |
| 743 | *sw_if_indexp = sw_if_index; |
| 744 | |
| 745 | return 0; |
| 746 | } |
| 747 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 748 | static clib_error_t * |
| 749 | vxlan_gpe_add_del_tunnel_command_fn (vlib_main_t * vm, |
| 750 | unformat_input_t * input, |
| 751 | vlib_cli_command_t * cmd) |
| 752 | { |
| 753 | unformat_input_t _line_input, * line_input = &_line_input; |
| 754 | u8 is_add = 1; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 755 | ip46_address_t local, remote; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 756 | u8 local_set = 0; |
| 757 | u8 remote_set = 0; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 758 | u8 grp_set = 0; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 759 | u8 ipv4_set = 0; |
| 760 | u8 ipv6_set = 0; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 761 | u32 mcast_sw_if_index = ~0; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 762 | u32 encap_fib_index = 0; |
| 763 | u32 decap_fib_index = 0; |
| 764 | u8 protocol = VXLAN_GPE_PROTOCOL_IP4; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 765 | u32 vni; |
| 766 | u8 vni_set = 0; |
| 767 | int rv; |
| 768 | u32 tmp; |
| 769 | vnet_vxlan_gpe_add_del_tunnel_args_t _a, * a = &_a; |
Pierre Pfister | 78ea9c2 | 2016-05-23 12:51:54 +0100 | [diff] [blame] | 770 | u32 sw_if_index; |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 771 | clib_error_t *error = NULL; |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 772 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 773 | /* Get a line of input. */ |
| 774 | if (! unformat_user (input, unformat_line_input, line_input)) |
| 775 | return 0; |
| 776 | |
| 777 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { |
| 778 | if (unformat (line_input, "del")) |
| 779 | is_add = 0; |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 780 | else if (unformat (line_input, "local %U", |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 781 | unformat_ip4_address, &local.ip4)) |
| 782 | { |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 783 | local_set = 1; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 784 | ipv4_set = 1; |
| 785 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 786 | else if (unformat (line_input, "remote %U", |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 787 | unformat_ip4_address, &remote.ip4)) |
| 788 | { |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 789 | remote_set = 1; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 790 | ipv4_set = 1; |
| 791 | } |
| 792 | else if (unformat (line_input, "local %U", |
| 793 | unformat_ip6_address, &local.ip6)) |
| 794 | { |
| 795 | local_set = 1; |
| 796 | ipv6_set = 1; |
| 797 | } |
| 798 | else if (unformat (line_input, "remote %U", |
| 799 | unformat_ip6_address, &remote.ip6)) |
| 800 | { |
| 801 | remote_set = 1; |
| 802 | ipv6_set = 1; |
| 803 | } |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 804 | else if (unformat (line_input, "group %U %U", |
| 805 | unformat_ip4_address, &remote.ip4, |
| 806 | unformat_vnet_sw_interface, |
| 807 | vnet_get_main(), &mcast_sw_if_index)) |
| 808 | { |
| 809 | grp_set = remote_set = 1; |
| 810 | ipv4_set = 1; |
| 811 | } |
| 812 | else if (unformat (line_input, "group %U %U", |
| 813 | unformat_ip6_address, &remote.ip6, |
| 814 | unformat_vnet_sw_interface, |
| 815 | vnet_get_main(), &mcast_sw_if_index)) |
| 816 | { |
| 817 | grp_set = remote_set = 1; |
| 818 | ipv6_set = 1; |
| 819 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 820 | else if (unformat (line_input, "encap-vrf-id %d", &tmp)) |
| 821 | { |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 822 | if (ipv6_set) |
Neale Ranns | 630198f | 2017-05-22 09:20:20 -0400 | [diff] [blame] | 823 | encap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 824 | else |
Neale Ranns | 630198f | 2017-05-22 09:20:20 -0400 | [diff] [blame] | 825 | encap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 826 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 827 | if (encap_fib_index == ~0) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 828 | { |
| 829 | error = clib_error_return (0, "nonexistent encap fib id %d", tmp); |
| 830 | goto done; |
| 831 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 832 | } |
| 833 | else if (unformat (line_input, "decap-vrf-id %d", &tmp)) |
| 834 | { |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 835 | if (ipv6_set) |
Neale Ranns | 630198f | 2017-05-22 09:20:20 -0400 | [diff] [blame] | 836 | decap_fib_index = fib_table_find (FIB_PROTOCOL_IP6, tmp); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 837 | else |
Neale Ranns | 630198f | 2017-05-22 09:20:20 -0400 | [diff] [blame] | 838 | decap_fib_index = fib_table_find (FIB_PROTOCOL_IP4, tmp); |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 839 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 840 | if (decap_fib_index == ~0) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 841 | { |
| 842 | error = clib_error_return (0, "nonexistent decap fib id %d", tmp); |
| 843 | goto done; |
| 844 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 845 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 846 | else if (unformat (line_input, "vni %d", &vni)) |
| 847 | vni_set = 1; |
| 848 | else if (unformat(line_input, "next-ip4")) |
| 849 | protocol = VXLAN_GPE_PROTOCOL_IP4; |
| 850 | else if (unformat(line_input, "next-ip6")) |
| 851 | protocol = VXLAN_GPE_PROTOCOL_IP6; |
| 852 | else if (unformat(line_input, "next-ethernet")) |
| 853 | protocol = VXLAN_GPE_PROTOCOL_ETHERNET; |
| 854 | else if (unformat(line_input, "next-nsh")) |
| 855 | protocol = VXLAN_GPE_PROTOCOL_NSH; |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 856 | else |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 857 | { |
| 858 | error = clib_error_return (0, "parse error: '%U'", |
| 859 | format_unformat_error, line_input); |
| 860 | goto done; |
| 861 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 862 | } |
| 863 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 864 | if (local_set == 0) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 865 | { |
| 866 | error = clib_error_return (0, "tunnel local address not specified"); |
| 867 | goto done; |
| 868 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 869 | |
| 870 | if (remote_set == 0) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 871 | { |
| 872 | error = clib_error_return (0, "tunnel remote address not specified"); |
| 873 | goto done; |
| 874 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 875 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 876 | if (grp_set && !ip46_address_is_multicast(&remote)) |
| 877 | { |
| 878 | error = clib_error_return (0, "tunnel group address not multicast"); |
| 879 | goto done; |
| 880 | } |
| 881 | |
| 882 | if (grp_set == 0 && ip46_address_is_multicast(&remote)) |
| 883 | { |
| 884 | error = clib_error_return (0, "remote address must be unicast"); |
| 885 | goto done; |
| 886 | } |
| 887 | |
| 888 | if (grp_set && mcast_sw_if_index == ~0) |
| 889 | { |
| 890 | error = clib_error_return (0, "tunnel nonexistent multicast device"); |
| 891 | goto done; |
| 892 | } |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 893 | if (ipv4_set && ipv6_set) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 894 | { |
| 895 | error = clib_error_return (0, "both IPv4 and IPv6 addresses specified"); |
| 896 | goto done; |
| 897 | } |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 898 | |
| 899 | if ((ipv4_set && memcmp(&local.ip4, &remote.ip4, sizeof(local.ip4)) == 0) || |
| 900 | (ipv6_set && memcmp(&local.ip6, &remote.ip6, sizeof(local.ip6)) == 0)) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 901 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 902 | error = clib_error_return (0, "src and remote addresses are identical"); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 903 | goto done; |
| 904 | } |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 905 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 906 | if (vni_set == 0) |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 907 | { |
| 908 | error = clib_error_return (0, "vni not specified"); |
| 909 | goto done; |
| 910 | } |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 911 | |
| 912 | memset (a, 0, sizeof (*a)); |
| 913 | |
| 914 | a->is_add = is_add; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 915 | a->is_ip6 = ipv6_set; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 916 | |
| 917 | #define _(x) a->x = x; |
| 918 | foreach_gpe_copy_field; |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 919 | if (ipv4_set) foreach_copy_ipv4 |
| 920 | else foreach_copy_ipv6 |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 921 | #undef _ |
| 922 | |
Pierre Pfister | 78ea9c2 | 2016-05-23 12:51:54 +0100 | [diff] [blame] | 923 | rv = vnet_vxlan_gpe_add_del_tunnel (a, &sw_if_index); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 924 | |
| 925 | switch(rv) |
| 926 | { |
| 927 | case 0: |
Pierre Pfister | 78ea9c2 | 2016-05-23 12:51:54 +0100 | [diff] [blame] | 928 | vlib_cli_output(vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main(), sw_if_index); |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 929 | break; |
| 930 | case VNET_API_ERROR_INVALID_DECAP_NEXT: |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 931 | error = clib_error_return (0, "invalid decap-next..."); |
| 932 | goto done; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 933 | |
| 934 | case VNET_API_ERROR_TUNNEL_EXIST: |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 935 | error = clib_error_return (0, "tunnel already exists..."); |
| 936 | goto done; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 937 | |
| 938 | case VNET_API_ERROR_NO_SUCH_ENTRY: |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 939 | error = clib_error_return (0, "tunnel does not exist..."); |
| 940 | goto done; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 941 | |
| 942 | default: |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 943 | error = clib_error_return |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 944 | (0, "vnet_vxlan_gpe_add_del_tunnel returned %d", rv); |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 945 | goto done; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Billy McFall | a9a20e7 | 2017-02-15 11:39:12 -0500 | [diff] [blame] | 948 | done: |
| 949 | unformat_free (line_input); |
| 950 | |
| 951 | return error; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 954 | /*? |
| 955 | * Add or delete a VXLAN-GPE Tunnel. |
| 956 | * |
| 957 | * VXLAN-GPE provides the features needed to allow L2 bridge domains (BDs) |
| 958 | * to span multiple servers. This is done by building an L2 overlay on |
| 959 | * top of an L3 network underlay using VXLAN-GPE tunnels. |
| 960 | * |
| 961 | * This makes it possible for servers to be co-located in the same data |
| 962 | * center or be separated geographically as long as they are reachable |
| 963 | * through the underlay L3 network. |
| 964 | * |
| 965 | * You can refer to this kind of L2 overlay bridge domain as a VXLAN-GPE sengment. |
| 966 | * |
| 967 | * @cliexpar |
| 968 | * Example of how to create a VXLAN-GPE Tunnel: |
| 969 | * @cliexcmd{create vxlan-gpe tunnel local 10.0.3.1 local 10.0.3.3 vni 13 encap-vrf-id 7} |
| 970 | * Example of how to delete a VXLAN Tunnel: |
| 971 | * @cliexcmd{create vxlan tunnel src 10.0.3.1 remote 10.0.3.3 vni 13 del} |
| 972 | ?*/ |
| 973 | /* *INDENT-OFF* */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 974 | VLIB_CLI_COMMAND (create_vxlan_gpe_tunnel_command, static) = { |
| 975 | .path = "create vxlan-gpe tunnel", |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 976 | .short_help = |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 977 | "create vxlan-gpe tunnel local <local-addr> " |
| 978 | " {remote <remote-addr>|group <mcast-addr> <intf-name>}" |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 979 | " vni <nn> [next-ip4][next-ip6][next-ethernet][next-nsh]" |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 980 | " [encap-vrf-id <nn>] [decap-vrf-id <nn>] [del]\n", |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 981 | .function = vxlan_gpe_add_del_tunnel_command_fn, |
| 982 | }; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 983 | /* *INDENT-ON* */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 984 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 985 | /** |
| 986 | * @brief CLI function for showing VXLAN GPE tunnels |
| 987 | * |
| 988 | * @param *vm |
| 989 | * @param *input |
| 990 | * @param *cmd |
| 991 | * |
| 992 | * @return error |
| 993 | * |
| 994 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 995 | static clib_error_t * |
| 996 | show_vxlan_gpe_tunnel_command_fn (vlib_main_t * vm, |
| 997 | unformat_input_t * input, |
| 998 | vlib_cli_command_t * cmd) |
| 999 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1000 | vxlan_gpe_main_t * ngm = &vxlan_gpe_main; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1001 | vxlan_gpe_tunnel_t * t; |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 1002 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1003 | if (pool_elts (ngm->tunnels) == 0) |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1004 | vlib_cli_output (vm, "No vxlan-gpe tunnels configured."); |
| 1005 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1006 | pool_foreach (t, ngm->tunnels, |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1007 | ({ |
| 1008 | vlib_cli_output (vm, "%U", format_vxlan_gpe_tunnel, t); |
| 1009 | })); |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 1010 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1011 | return 0; |
| 1012 | } |
| 1013 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1014 | /*? |
| 1015 | * Display all the VXLAN-GPE Tunnel entries. |
| 1016 | * |
| 1017 | * @cliexpar |
| 1018 | * Example of how to display the VXLAN-GPE Tunnel entries: |
| 1019 | * @cliexstart{show vxlan-gpe tunnel} |
| 1020 | * [0] local 10.0.3.1 remote 10.0.3.3 vni 13 encap_fib_index 0 sw_if_index 5 decap_next l2 |
| 1021 | * @cliexend |
| 1022 | ?*/ |
| 1023 | /* *INDENT-OFF* */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1024 | VLIB_CLI_COMMAND (show_vxlan_gpe_tunnel_command, static) = { |
| 1025 | .path = "show vxlan-gpe", |
| 1026 | .function = show_vxlan_gpe_tunnel_command_fn, |
| 1027 | }; |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1028 | /* *INDENT-ON* */ |
| 1029 | |
| 1030 | void vnet_int_vxlan_gpe_bypass_mode (u32 sw_if_index, |
| 1031 | u8 is_ip6, |
| 1032 | u8 is_enable) |
| 1033 | { |
| 1034 | if (is_ip6) |
| 1035 | vnet_feature_enable_disable ("ip6-unicast", "ip6-vxlan-gpe-bypass", |
| 1036 | sw_if_index, is_enable, 0, 0); |
| 1037 | else |
| 1038 | vnet_feature_enable_disable ("ip4-unicast", "ip4-vxlan-gpe-bypass", |
| 1039 | sw_if_index, is_enable, 0, 0); |
| 1040 | } |
| 1041 | |
| 1042 | |
| 1043 | static clib_error_t * |
| 1044 | set_ip_vxlan_gpe_bypass (u32 is_ip6, |
| 1045 | unformat_input_t * input, |
| 1046 | vlib_cli_command_t * cmd) |
| 1047 | { |
| 1048 | unformat_input_t _line_input, * line_input = &_line_input; |
| 1049 | vnet_main_t * vnm = vnet_get_main(); |
| 1050 | clib_error_t * error = 0; |
| 1051 | u32 sw_if_index, is_enable; |
| 1052 | |
| 1053 | sw_if_index = ~0; |
| 1054 | is_enable = 1; |
| 1055 | |
| 1056 | if (! unformat_user (input, unformat_line_input, line_input)) |
| 1057 | return 0; |
| 1058 | |
| 1059 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1060 | { |
| 1061 | if (unformat_user (line_input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1062 | ; |
| 1063 | else if (unformat (line_input, "del")) |
| 1064 | is_enable = 0; |
| 1065 | else |
| 1066 | { |
| 1067 | error = unformat_parse_error (line_input); |
| 1068 | goto done; |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | if (~0 == sw_if_index) |
| 1073 | { |
| 1074 | error = clib_error_return (0, "unknown interface `%U'", |
| 1075 | format_unformat_error, line_input); |
| 1076 | goto done; |
| 1077 | } |
| 1078 | |
| 1079 | vnet_int_vxlan_gpe_bypass_mode (sw_if_index, is_ip6, is_enable); |
| 1080 | |
| 1081 | done: |
| 1082 | unformat_free (line_input); |
| 1083 | |
| 1084 | return error; |
| 1085 | } |
| 1086 | |
| 1087 | static clib_error_t * |
| 1088 | set_ip4_vxlan_gpe_bypass (vlib_main_t * vm, |
| 1089 | unformat_input_t * input, |
| 1090 | vlib_cli_command_t * cmd) |
| 1091 | { |
| 1092 | return set_ip_vxlan_gpe_bypass (0, input, cmd); |
| 1093 | } |
| 1094 | |
| 1095 | /*? |
| 1096 | * This command adds the 'ip4-vxlan-gpe-bypass' graph node for a given interface. |
| 1097 | * By adding the IPv4 vxlan-gpe-bypass graph node to an interface, the node checks |
| 1098 | * for and validate input vxlan_gpe packet and bypass ip4-lookup, ip4-local, |
| 1099 | * ip4-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will |
| 1100 | * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum. |
| 1101 | * |
| 1102 | * @cliexpar |
| 1103 | * @parblock |
| 1104 | * Example of graph node before ip4-vxlan-gpe-bypass is enabled: |
| 1105 | * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass} |
| 1106 | * Name Next Previous |
| 1107 | * ip4-vxlan-gpe-bypass error-drop [0] |
| 1108 | * vxlan4-gpe-input [1] |
| 1109 | * ip4-lookup [2] |
| 1110 | * @cliexend |
| 1111 | * |
| 1112 | * Example of how to enable ip4-vxlan-gpe-bypass on an interface: |
| 1113 | * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0} |
| 1114 | * |
| 1115 | * Example of graph node after ip4-vxlan-gpe-bypass is enabled: |
| 1116 | * @cliexstart{show vlib graph ip4-vxlan-gpe-bypass} |
| 1117 | * Name Next Previous |
| 1118 | * ip4-vxlan-gpe-bypass error-drop [0] ip4-input |
| 1119 | * vxlan4-gpe-input [1] ip4-input-no-checksum |
| 1120 | * ip4-lookup [2] |
| 1121 | * @cliexend |
| 1122 | * |
| 1123 | * Example of how to display the feature enabed on an interface: |
| 1124 | * @cliexstart{show ip interface features GigabitEthernet2/0/0} |
| 1125 | * IP feature paths configured on GigabitEthernet2/0/0... |
| 1126 | * ... |
| 1127 | * ipv4 unicast: |
| 1128 | * ip4-vxlan-gpe-bypass |
| 1129 | * ip4-lookup |
| 1130 | * ... |
| 1131 | * @cliexend |
| 1132 | * |
| 1133 | * Example of how to disable ip4-vxlan-gpe-bypass on an interface: |
| 1134 | * @cliexcmd{set interface ip vxlan-gpe-bypass GigabitEthernet2/0/0 del} |
| 1135 | * @endparblock |
| 1136 | ?*/ |
| 1137 | /* *INDENT-OFF* */ |
| 1138 | VLIB_CLI_COMMAND (set_interface_ip_vxlan_gpe_bypass_command, static) = { |
| 1139 | .path = "set interface ip vxlan-gpe-bypass", |
| 1140 | .function = set_ip4_vxlan_gpe_bypass, |
| 1141 | .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]", |
| 1142 | }; |
| 1143 | /* *INDENT-ON* */ |
| 1144 | |
| 1145 | static clib_error_t * |
| 1146 | set_ip6_vxlan_gpe_bypass (vlib_main_t * vm, |
| 1147 | unformat_input_t * input, |
| 1148 | vlib_cli_command_t * cmd) |
| 1149 | { |
| 1150 | return set_ip_vxlan_gpe_bypass (1, input, cmd); |
| 1151 | } |
| 1152 | |
| 1153 | /*? |
| 1154 | * This command adds the 'ip6-vxlan-gpe-bypass' graph node for a given interface. |
| 1155 | * By adding the IPv6 vxlan-gpe-bypass graph node to an interface, the node checks |
| 1156 | * for and validate input vxlan_gpe packet and bypass ip6-lookup, ip6-local, |
| 1157 | * ip6-udp-lookup nodes to speedup vxlan_gpe packet forwarding. This node will |
| 1158 | * cause extra overhead to for non-vxlan_gpe packets which is kept at a minimum. |
| 1159 | * |
| 1160 | * @cliexpar |
| 1161 | * @parblock |
| 1162 | * Example of graph node before ip6-vxlan-gpe-bypass is enabled: |
| 1163 | * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass} |
| 1164 | * Name Next Previous |
| 1165 | * ip6-vxlan-gpe-bypass error-drop [0] |
| 1166 | * vxlan6-gpe-input [1] |
| 1167 | * ip6-lookup [2] |
| 1168 | * @cliexend |
| 1169 | * |
| 1170 | * Example of how to enable ip6-vxlan-gpe-bypass on an interface: |
| 1171 | * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0} |
| 1172 | * |
| 1173 | * Example of graph node after ip6-vxlan-gpe-bypass is enabled: |
| 1174 | * @cliexstart{show vlib graph ip6-vxlan-gpe-bypass} |
| 1175 | * Name Next Previous |
| 1176 | * ip6-vxlan-gpe-bypass error-drop [0] ip6-input |
| 1177 | * vxlan6-gpe-input [1] ip4-input-no-checksum |
| 1178 | * ip6-lookup [2] |
| 1179 | * @cliexend |
| 1180 | * |
| 1181 | * Example of how to display the feature enabed on an interface: |
| 1182 | * @cliexstart{show ip interface features GigabitEthernet2/0/0} |
| 1183 | * IP feature paths configured on GigabitEthernet2/0/0... |
| 1184 | * ... |
| 1185 | * ipv6 unicast: |
| 1186 | * ip6-vxlan-gpe-bypass |
| 1187 | * ip6-lookup |
| 1188 | * ... |
| 1189 | * @cliexend |
| 1190 | * |
| 1191 | * Example of how to disable ip6-vxlan-gpe-bypass on an interface: |
| 1192 | * @cliexcmd{set interface ip6 vxlan-gpe-bypass GigabitEthernet2/0/0 del} |
| 1193 | * @endparblock |
| 1194 | ?*/ |
| 1195 | /* *INDENT-OFF* */ |
| 1196 | VLIB_CLI_COMMAND (set_interface_ip6_vxlan_gpe_bypass_command, static) = { |
| 1197 | .path = "set interface ip6 vxlan-gpe-bypass", |
| 1198 | .function = set_ip6_vxlan_gpe_bypass, |
| 1199 | .short_help = "set interface ip vxlan-gpe-bypass <interface> [del]", |
| 1200 | }; |
| 1201 | /* *INDENT-ON* */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1202 | |
Hongjun Ni | e1bf572 | 2017-08-03 20:34:45 +0800 | [diff] [blame] | 1203 | /* *INDENT-OFF* */ |
| 1204 | VNET_FEATURE_INIT (ip4_vxlan_gpe_bypass, static) = |
| 1205 | { |
| 1206 | .arc_name = "ip4-unicast", |
| 1207 | .node_name = "ip4-vxlan-gpe-bypass", |
| 1208 | .runs_before = VNET_FEATURES ("ip4-lookup"), |
| 1209 | }; |
| 1210 | |
| 1211 | VNET_FEATURE_INIT (ip6_vxlan_gpe_bypass, static) = |
| 1212 | { |
| 1213 | .arc_name = "ip6-unicast", |
| 1214 | .node_name = "ip6-vxlan-gpe-bypass", |
| 1215 | .runs_before = VNET_FEATURES ("ip6-lookup"), |
| 1216 | }; |
| 1217 | /* *INDENT-ON* */ |
| 1218 | |
Keith Burns (alagalah) | d46cca1 | 2016-08-25 11:21:39 -0700 | [diff] [blame] | 1219 | /** |
| 1220 | * @brief Feature init function for VXLAN GPE |
| 1221 | * |
| 1222 | * @param *vm |
| 1223 | * |
| 1224 | * @return error |
| 1225 | * |
| 1226 | */ |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1227 | clib_error_t *vxlan_gpe_init (vlib_main_t *vm) |
| 1228 | { |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1229 | vxlan_gpe_main_t *ngm = &vxlan_gpe_main; |
Hongjun Ni | cccd1bf | 2016-06-07 18:43:05 +0800 | [diff] [blame] | 1230 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1231 | ngm->vnet_main = vnet_get_main(); |
| 1232 | ngm->vlib_main = vm; |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1233 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1234 | ngm->vxlan4_gpe_tunnel_by_key |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 1235 | = hash_create_mem (0, sizeof(vxlan4_gpe_tunnel_key_t), sizeof (uword)); |
| 1236 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1237 | ngm->vxlan6_gpe_tunnel_by_key |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 1238 | = hash_create_mem (0, sizeof(vxlan6_gpe_tunnel_key_t), sizeof (uword)); |
| 1239 | |
| 1240 | |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1241 | ngm->mcast_shared = hash_create_mem(0, |
| 1242 | sizeof(ip46_address_t), |
| 1243 | sizeof(mcast_shared_t)); |
| 1244 | |
| 1245 | udp_register_dst_port (vm, UDP_DST_PORT_VXLAN_GPE, |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 1246 | vxlan4_gpe_input_node.index, 1 /* is_ip4 */); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1247 | udp_register_dst_port (vm, UDP_DST_PORT_VXLAN6_GPE, |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 1248 | vxlan6_gpe_input_node.index, 0 /* is_ip4 */); |
Vengada Govindan | 6d403a0 | 2016-10-12 05:54:09 -0700 | [diff] [blame] | 1249 | |
| 1250 | /* Register the list of standard decap protocols supported */ |
| 1251 | vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP4, |
| 1252 | VXLAN_GPE_INPUT_NEXT_IP4_INPUT); |
| 1253 | vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_IP6, |
| 1254 | VXLAN_GPE_INPUT_NEXT_IP6_INPUT); |
| 1255 | vxlan_gpe_register_decap_protocol (VXLAN_GPE_PROTOCOL_ETHERNET, |
| 1256 | VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT); |
Hongjun Ni | 8a0a0ae | 2017-05-27 20:23:09 +0800 | [diff] [blame] | 1257 | |
| 1258 | fib_node_register_type(FIB_NODE_TYPE_VXLAN_GPE_TUNNEL, &vxlan_gpe_vft); |
| 1259 | |
Keith Burns (alagalah) | 94b1442 | 2016-05-05 18:16:50 -0700 | [diff] [blame] | 1260 | return 0; |
| 1261 | } |
| 1262 | |
| 1263 | VLIB_INIT_FUNCTION(vxlan_gpe_init); |
| 1264 | |