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