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