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