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