Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 1 | /* |
| 2 | * sixrd.c - 6RD specific functions (RFC5969) |
| 3 | * |
| 4 | * Copyright (c) 2018 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * This code supports the following sixrd modes: |
| 20 | * |
| 21 | * 32 EA bits (Complete IPv4 address is embedded): |
| 22 | * ea_bits_len = 32 |
| 23 | * IPv4 suffix is embedded: |
| 24 | * ea_bits_len = < 32 |
| 25 | * No embedded address bits (1:1 mode): |
| 26 | * ea_bits_len = 0 |
| 27 | */ |
| 28 | |
| 29 | #include "ipip.h" |
| 30 | #include <vlibapi/api.h> |
| 31 | #include <vlibmemory/api.h> |
| 32 | #include <vnet/adj/adj.h> |
| 33 | #include <vnet/adj/adj_delegate.h> |
| 34 | #include <vnet/adj/adj_midchain.h> |
| 35 | #include <vnet/dpo/lookup_dpo.h> |
| 36 | #include <vnet/fib/fib_table.h> |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 37 | #include <vnet/fib/fib_entry_track.h> |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 38 | #include <vnet/fib/ip6_fib.h> |
| 39 | #include <vnet/plugin/plugin.h> |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 40 | |
| 41 | extern vlib_node_registration_t ip4_sixrd_node; |
| 42 | |
| 43 | /** |
| 44 | * Adj delegate data |
| 45 | */ |
| 46 | typedef struct sixrd_adj_delegate_t_ |
| 47 | { |
| 48 | u32 adj_index; |
| 49 | fib_node_t sixrd_node; |
| 50 | fib_node_index_t sixrd_fib_entry_index; |
| 51 | u32 sixrd_sibling; |
| 52 | } sixrd_adj_delegate_t; |
| 53 | |
| 54 | /** |
| 55 | * Pool of delegate structs |
| 56 | */ |
| 57 | static sixrd_adj_delegate_t *sixrd_adj_delegate_pool; |
| 58 | |
| 59 | /** |
| 60 | * Adj delegate registered type |
| 61 | */ |
| 62 | static adj_delegate_type_t sixrd_adj_delegate_type; |
| 63 | |
| 64 | /** |
| 65 | * FIB node registered type |
| 66 | */ |
| 67 | static fib_node_type_t sixrd_fib_node_type; |
| 68 | |
| 69 | static inline sixrd_adj_delegate_t * |
| 70 | sixrd_adj_from_base (adj_delegate_t * ad) |
| 71 | { |
| 72 | if (ad == NULL) |
| 73 | return (NULL); |
| 74 | return (pool_elt_at_index (sixrd_adj_delegate_pool, ad->ad_index)); |
| 75 | } |
| 76 | |
| 77 | static inline const sixrd_adj_delegate_t * |
| 78 | sixrd_adj_from_const_base (const adj_delegate_t * ad) |
| 79 | { |
| 80 | if (ad == NULL) |
| 81 | { |
| 82 | return (NULL); |
| 83 | } |
| 84 | return (pool_elt_at_index (sixrd_adj_delegate_pool, ad->ad_index)); |
| 85 | } |
| 86 | |
| 87 | static void |
Neale Ranns | 960eeea | 2019-12-02 23:28:50 +0000 | [diff] [blame] | 88 | sixrd_fixup (vlib_main_t * vm, |
| 89 | const ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data) |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 90 | { |
| 91 | ip4_header_t *ip4 = vlib_buffer_get_current (b0); |
| 92 | ip6_header_t *ip6 = vlib_buffer_get_current (b0) + sizeof (ip4_header_t); |
| 93 | const ipip_tunnel_t *t = data; |
| 94 | |
| 95 | ip4->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)); |
| 96 | ip4->dst_address.as_u32 = |
| 97 | sixrd_get_addr_net (t, ip6->dst_address.as_u64[0]); |
| 98 | ip4->checksum = ip4_header_checksum (ip4); |
| 99 | } |
| 100 | |
| 101 | static void |
Neale Ranns | 960eeea | 2019-12-02 23:28:50 +0000 | [diff] [blame] | 102 | ip6ip_fixup (vlib_main_t * vm, |
| 103 | const ip_adjacency_t * adj, vlib_buffer_t * b0, const void *data) |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 104 | { |
| 105 | const ipip_tunnel_t *t = data; |
| 106 | ip4_header_t *ip4 = vlib_buffer_get_current (b0); |
| 107 | ip4->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)); |
| 108 | ip4->dst_address.as_u32 = |
| 109 | sixrd_get_addr_net (t, adj->sub_type.nbr.next_hop.as_u64[0]); |
| 110 | ip4->checksum = ip4_header_checksum (ip4); |
| 111 | } |
| 112 | |
| 113 | static u8 * |
| 114 | sixrd_build_rewrite (vnet_main_t * vnm, u32 sw_if_index, |
| 115 | vnet_link_t link_type, const void *dst_address) |
| 116 | { |
| 117 | u8 *rewrite = NULL; |
| 118 | ipip_tunnel_t *t; |
| 119 | |
| 120 | t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index); |
| 121 | if (!t) |
| 122 | return 0; |
| 123 | |
| 124 | vec_validate (rewrite, sizeof (ip4_header_t) - 1); |
| 125 | ip4_header_t *ip4 = (ip4_header_t *) rewrite; |
| 126 | ip4->ip_version_and_header_length = 0x45; |
| 127 | ip4->ttl = 64; |
| 128 | ip4->protocol = IP_PROTOCOL_IPV6; |
| 129 | /* fixup ip4 header length and checksum after-the-fact */ |
| 130 | ip4->src_address.as_u32 = t->tunnel_src.ip4.as_u32; |
| 131 | ip4->dst_address.as_u32 = 0; |
| 132 | ip4->checksum = ip4_header_checksum (ip4); |
| 133 | |
| 134 | return rewrite; |
| 135 | } |
| 136 | |
| 137 | static void |
| 138 | ip6ip_tunnel_stack (adj_index_t ai, u32 fib_entry_index) |
| 139 | { |
| 140 | ip_adjacency_t *adj = adj_get (ai); |
| 141 | ipip_tunnel_t *t; |
| 142 | u32 sw_if_index = adj->rewrite_header.sw_if_index; |
| 143 | |
| 144 | t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index); |
| 145 | if (!t) |
| 146 | return; |
| 147 | |
| 148 | /* |
| 149 | * find the adjacency that is contributed by the FIB entry |
| 150 | * that this tunnel resolves via, and use it as the next adj |
| 151 | * in the midchain |
| 152 | */ |
| 153 | if (vnet_hw_interface_get_flags (vnet_get_main (), t->hw_if_index) & |
| 154 | VNET_HW_INTERFACE_FLAG_LINK_UP) |
| 155 | { |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 156 | adj_nbr_midchain_stack_on_fib_entry (ai, |
| 157 | fib_entry_index, |
| 158 | FIB_FORW_CHAIN_TYPE_UNICAST_IP4); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 159 | } |
| 160 | else |
| 161 | { |
| 162 | adj_nbr_midchain_unstack (ai); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | static void |
| 167 | sixrd_tunnel_stack (adj_index_t ai, u32 fib_index) |
| 168 | { |
| 169 | dpo_id_t dpo = DPO_INVALID; |
| 170 | ip_adjacency_t *adj = adj_get (ai); |
| 171 | u32 sw_if_index = adj->rewrite_header.sw_if_index; |
| 172 | |
| 173 | ipip_tunnel_t *t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index); |
| 174 | if (!t) |
| 175 | return; |
| 176 | |
| 177 | lookup_dpo_add_or_lock_w_fib_index (fib_index, DPO_PROTO_IP4, |
| 178 | LOOKUP_UNICAST, LOOKUP_INPUT_DST_ADDR, |
| 179 | LOOKUP_TABLE_FROM_CONFIG, &dpo); |
| 180 | adj_nbr_midchain_stack (ai, &dpo); |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 181 | dpo_reset (&dpo); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 184 | static void |
| 185 | sixrd_update_adj (vnet_main_t * vnm, u32 sw_if_index, adj_index_t ai) |
| 186 | { |
| 187 | ip_adjacency_t *adj = adj_get (ai); |
| 188 | ipip_tunnel_t *t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index); |
| 189 | |
Ole Troan | 1d977dc | 2018-03-19 12:14:02 +0100 | [diff] [blame] | 190 | /* Not our tunnel */ |
| 191 | if (!t) |
| 192 | return; |
Neale Ranns | 579092c | 2018-07-30 08:14:14 -0700 | [diff] [blame] | 193 | if (IP_LOOKUP_NEXT_BCAST == adj->lookup_next_index) |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 194 | { |
| 195 | adj_nbr_midchain_update_rewrite (ai, sixrd_fixup, t, ADJ_FLAG_NONE, |
| 196 | sixrd_build_rewrite (vnm, sw_if_index, |
| 197 | adj_get_link_type |
| 198 | (ai), NULL)); |
| 199 | sixrd_tunnel_stack (ai, t->fib_index); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | sixrd_adj_delegate_t *sixrd_ad; |
| 204 | ip4_address_t da4; |
| 205 | |
| 206 | da4.as_u32 = |
| 207 | sixrd_get_addr_net (t, adj->sub_type.nbr.next_hop.as_u64[0]); |
| 208 | |
| 209 | fib_prefix_t pfx = { |
| 210 | .fp_proto = FIB_PROTOCOL_IP4, |
| 211 | .fp_len = 32, |
| 212 | .fp_addr = { |
| 213 | .ip4 = da4, |
| 214 | } |
| 215 | , |
| 216 | }; |
| 217 | |
| 218 | adj_nbr_midchain_update_rewrite (ai, ip6ip_fixup, t, ADJ_FLAG_NONE, |
| 219 | sixrd_build_rewrite (vnm, sw_if_index, |
| 220 | adj_get_link_type |
| 221 | (ai), NULL)); |
| 222 | |
| 223 | sixrd_ad = |
| 224 | sixrd_adj_from_base (adj_delegate_get (adj, sixrd_adj_delegate_type)); |
| 225 | if (sixrd_ad == NULL) |
| 226 | { |
| 227 | pool_get (sixrd_adj_delegate_pool, sixrd_ad); |
| 228 | fib_node_init (&sixrd_ad->sixrd_node, sixrd_fib_node_type); |
| 229 | sixrd_ad->adj_index = ai; |
| 230 | sixrd_ad->sixrd_fib_entry_index = |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 231 | fib_entry_track (t->fib_index, &pfx, |
| 232 | sixrd_fib_node_type, |
| 233 | sixrd_ad - sixrd_adj_delegate_pool, |
| 234 | &sixrd_ad->sixrd_sibling); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 235 | |
| 236 | adj_delegate_add (adj, sixrd_adj_delegate_type, |
| 237 | sixrd_ad - sixrd_adj_delegate_pool); |
| 238 | |
| 239 | ip6ip_tunnel_stack (ai, sixrd_ad->sixrd_fib_entry_index); |
| 240 | } |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | clib_error_t * |
| 245 | sixrd_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags) |
| 246 | { |
| 247 | /* Always up */ |
| 248 | vnet_hw_interface_set_flags (vnm, hw_if_index, |
| 249 | VNET_HW_INTERFACE_FLAG_LINK_UP); |
| 250 | return /* no error */ 0; |
| 251 | } |
| 252 | |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 253 | VNET_HW_INTERFACE_CLASS(sixrd_hw_interface_class) = { |
| 254 | .name = "ip6ip-6rd", |
| 255 | .build_rewrite = sixrd_build_rewrite, |
| 256 | .update_adjacency = sixrd_update_adj, |
| 257 | }; |
| 258 | |
| 259 | VNET_DEVICE_CLASS(sixrd_device_class) = { |
| 260 | .name = "ip6ip-6rd", |
| 261 | .admin_up_down_function = sixrd_interface_admin_up_down, |
| 262 | #ifdef SOON |
| 263 | .clear counter = 0; |
| 264 | #endif |
| 265 | } |
| 266 | ; |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 267 | |
| 268 | int |
| 269 | sixrd_add_tunnel (ip6_address_t * ip6_prefix, u8 ip6_prefix_len, |
| 270 | ip4_address_t * ip4_prefix, u8 ip4_prefix_len, |
| 271 | ip4_address_t * ip4_src, bool security_check, |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 272 | u32 ip4_fib_index, u32 ip6_fib_index, u32 * sw_if_index) |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 273 | { |
| 274 | ipip_main_t *gm = &ipip_main; |
| 275 | ipip_tunnel_t *t; |
| 276 | |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 277 | if ((ip6_prefix_len + 32 - ip4_prefix_len) > 64) |
| 278 | return VNET_API_ERROR_INVALID_VALUE; |
| 279 | |
| 280 | /* Tunnel already configured */ |
| 281 | ip46_address_t src = ip46_address_initializer, dst = |
| 282 | ip46_address_initializer; |
| 283 | ip_set (&src, ip4_src, true); |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 284 | ipip_tunnel_key_t key; |
| 285 | |
| 286 | ipip_mk_key_i (IPIP_TRANSPORT_IP4, IPIP_MODE_6RD, &src, &dst, ip4_fib_index, |
| 287 | &key); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 288 | |
| 289 | t = ipip_tunnel_db_find (&key); |
| 290 | if (t) |
| 291 | return VNET_API_ERROR_IF_ALREADY_EXISTS; |
| 292 | |
| 293 | /* Get tunnel index */ |
| 294 | pool_get_aligned (gm->tunnels, t, CLIB_CACHE_LINE_BYTES); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 295 | clib_memset (t, 0, sizeof (*t)); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 296 | u32 t_idx = t - gm->tunnels; /* tunnel index (or instance) */ |
| 297 | |
| 298 | /* Init tunnel struct */ |
| 299 | t->mode = IPIP_MODE_6RD; |
| 300 | t->sixrd.ip4_prefix.as_u32 = ip4_prefix->as_u32; |
| 301 | t->sixrd.ip4_prefix_len = ip4_prefix_len; |
| 302 | t->sixrd.ip6_prefix = *ip6_prefix; |
| 303 | t->sixrd.ip6_prefix_len = ip6_prefix_len; |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 304 | t->sixrd.ip6_fib_index = ip6_fib_index; |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 305 | t->tunnel_src = src; |
| 306 | t->sixrd.security_check = security_check; |
| 307 | t->sixrd.shift = |
| 308 | (ip4_prefix_len < 32) ? 64 - ip6_prefix_len - (32 - ip4_prefix_len) : 0; |
| 309 | |
| 310 | /* Create interface */ |
| 311 | u32 hw_if_index = |
| 312 | vnet_register_interface (vnet_get_main (), sixrd_device_class.index, |
| 313 | t_idx, |
| 314 | sixrd_hw_interface_class.index, t_idx); |
| 315 | |
| 316 | /* Default the interface to up and enable IPv6 (payload) */ |
| 317 | vnet_hw_interface_t *hi = |
| 318 | vnet_get_hw_interface (vnet_get_main (), hw_if_index); |
| 319 | t->hw_if_index = hw_if_index; |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 320 | t->fib_index = ip4_fib_index; |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 321 | t->sw_if_index = hi->sw_if_index; |
| 322 | t->dev_instance = t_idx; |
| 323 | t->user_instance = t_idx; |
| 324 | |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 325 | vnet_sw_interface_set_mtu (vnet_get_main (), t->sw_if_index, 1480); |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 326 | vnet_set_interface_l3_output_node (gm->vlib_main, hi->sw_if_index, |
| 327 | (u8 *) "tunnel-output"); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 328 | |
| 329 | ipip_tunnel_db_add (t, &key); |
| 330 | |
| 331 | vec_validate_init_empty (gm->tunnel_index_by_sw_if_index, hi->sw_if_index, |
| 332 | ~0); |
| 333 | gm->tunnel_index_by_sw_if_index[hi->sw_if_index] = t_idx; |
| 334 | |
| 335 | vnet_hw_interface_set_flags (vnet_get_main (), hw_if_index, |
| 336 | VNET_HW_INTERFACE_FLAG_LINK_UP); |
| 337 | vnet_sw_interface_set_flags (vnet_get_main (), hi->sw_if_index, |
| 338 | VNET_SW_INTERFACE_FLAG_ADMIN_UP); |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 339 | ip6_sw_interface_enable_disable (t->sw_if_index, true); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 340 | |
| 341 | /* Create IPv6 route/adjacency */ |
| 342 | fib_prefix_t pfx6 = { |
| 343 | .fp_proto = FIB_PROTOCOL_IP6, |
| 344 | .fp_len = t->sixrd.ip6_prefix_len, |
| 345 | .fp_addr = { |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 346 | .ip6 = t->sixrd.ip6_prefix, |
| 347 | }, |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 348 | }; |
| 349 | |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 350 | fib_table_lock (ip6_fib_index, FIB_PROTOCOL_IP6, FIB_SOURCE_6RD); |
| 351 | fib_table_entry_update_one_path (ip6_fib_index, &pfx6, FIB_SOURCE_6RD, |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 352 | FIB_ENTRY_FLAG_ATTACHED, DPO_PROTO_IP6, |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 353 | &ADJ_BCAST_ADDR, t->sw_if_index, ~0, 1, |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 354 | NULL, FIB_ROUTE_PATH_FLAG_NONE); |
| 355 | |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 356 | *sw_if_index = t->sw_if_index; |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 357 | |
| 358 | if (!gm->ip4_protocol_registered) |
| 359 | { |
| 360 | vlib_node_t *ipip4_input = |
| 361 | vlib_get_node_by_name (gm->vlib_main, (u8 *) "ipip4-input"); |
| 362 | ASSERT (ipip4_input); |
| 363 | ip4_register_protocol (IP_PROTOCOL_IPV6, ipip4_input->index); |
| 364 | } |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * sixrd_del_tunnel |
| 370 | */ |
| 371 | int |
| 372 | sixrd_del_tunnel (u32 sw_if_index) |
| 373 | { |
| 374 | ipip_main_t *gm = &ipip_main; |
| 375 | ipip_tunnel_t *t = ipip_tunnel_db_find_by_sw_if_index (sw_if_index); |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 376 | ipip_tunnel_key_t key; |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 377 | |
| 378 | if (!t) |
| 379 | { |
| 380 | clib_warning ("SIXRD tunnel delete: tunnel does not exist: %d", |
| 381 | sw_if_index); |
| 382 | return -1; |
| 383 | } |
| 384 | |
| 385 | fib_prefix_t pfx6 = { |
| 386 | .fp_proto = FIB_PROTOCOL_IP6, |
| 387 | .fp_len = t->sixrd.ip6_prefix_len, |
| 388 | .fp_addr = { |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 389 | .ip6 = t->sixrd.ip6_prefix, |
| 390 | }, |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 391 | }; |
Neale Ranns | 6150211 | 2018-08-22 00:21:14 -0700 | [diff] [blame] | 392 | |
| 393 | fib_table_entry_path_remove (t->sixrd.ip6_fib_index, &pfx6, |
| 394 | FIB_SOURCE_6RD, |
| 395 | DPO_PROTO_IP6, |
| 396 | &ADJ_BCAST_ADDR, t->sw_if_index, ~0, 1, |
| 397 | FIB_ROUTE_PATH_FLAG_NONE); |
| 398 | fib_table_unlock (t->sixrd.ip6_fib_index, FIB_PROTOCOL_IP6, FIB_SOURCE_6RD); |
| 399 | |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 400 | vnet_sw_interface_set_flags (vnet_get_main (), t->sw_if_index, |
| 401 | 0 /* down */ ); |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 402 | vnet_reset_interface_l3_output_node (gm->vlib_main, t->sw_if_index); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 403 | ip6_sw_interface_enable_disable (t->sw_if_index, false); |
| 404 | gm->tunnel_index_by_sw_if_index[t->sw_if_index] = ~0; |
| 405 | |
| 406 | vnet_delete_hw_interface (vnet_get_main (), t->hw_if_index); |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 407 | ipip_mk_key (t, &key); |
| 408 | ipip_tunnel_db_remove (t, &key); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 409 | pool_put (gm->tunnels, t); |
| 410 | |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | static void |
| 415 | sixrd_adj_delegate_adj_deleted (adj_delegate_t * aed) |
| 416 | { |
| 417 | sixrd_adj_delegate_t *sixrd_ad; |
| 418 | |
| 419 | sixrd_ad = sixrd_adj_from_base (aed); |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 420 | fib_entry_untrack (sixrd_ad->sixrd_fib_entry_index, |
| 421 | sixrd_ad->sixrd_sibling); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 422 | pool_put (sixrd_adj_delegate_pool, sixrd_ad); |
| 423 | } |
| 424 | |
| 425 | static u8 * |
| 426 | sixrd_adj_delegate_format (const adj_delegate_t * aed, u8 * s) |
| 427 | { |
| 428 | const sixrd_adj_delegate_t *sixrd_ad; |
| 429 | |
| 430 | sixrd_ad = sixrd_adj_from_const_base (aed); |
| 431 | s = format (s, "SIXRD:[fib-entry:%d]", sixrd_ad->sixrd_fib_entry_index); |
| 432 | |
| 433 | return (s); |
| 434 | } |
| 435 | |
| 436 | static void |
| 437 | sixrd_fib_node_last_lock_gone (fib_node_t * node) |
| 438 | { |
| 439 | /* top of the dependency tree, locks not managed here. */ |
| 440 | } |
| 441 | |
| 442 | static sixrd_adj_delegate_t * |
| 443 | sixrd_adj_delegate_from_fib_node (fib_node_t * node) |
| 444 | { |
| 445 | return ((sixrd_adj_delegate_t *) (((char *) node) - |
| 446 | STRUCT_OFFSET_OF (sixrd_adj_delegate_t, |
| 447 | sixrd_node))); |
| 448 | } |
| 449 | |
| 450 | static fib_node_back_walk_rc_t |
| 451 | sixrd_fib_node_back_walk_notify (fib_node_t * node, |
| 452 | fib_node_back_walk_ctx_t * ctx) |
| 453 | { |
| 454 | sixrd_adj_delegate_t *sixrd_ad; |
| 455 | |
| 456 | sixrd_ad = sixrd_adj_delegate_from_fib_node (node); |
| 457 | ip6ip_tunnel_stack (sixrd_ad->adj_index, sixrd_ad->sixrd_fib_entry_index); |
| 458 | |
| 459 | return (FIB_NODE_BACK_WALK_CONTINUE); |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Function definition to get a FIB node from its index |
| 464 | */ |
| 465 | static fib_node_t * |
| 466 | sixrd_fib_node_get (fib_node_index_t index) |
| 467 | { |
| 468 | sixrd_adj_delegate_t *sixrd_ad; |
| 469 | |
| 470 | sixrd_ad = pool_elt_at_index (sixrd_adj_delegate_pool, index); |
| 471 | |
| 472 | return (&sixrd_ad->sixrd_node); |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * VFT registered with the adjacency delegate |
| 477 | */ |
| 478 | const static adj_delegate_vft_t sixrd_adj_delegate_vft = { |
| 479 | .adv_adj_deleted = sixrd_adj_delegate_adj_deleted, |
| 480 | .adv_format = sixrd_adj_delegate_format, |
| 481 | }; |
| 482 | |
| 483 | /** |
| 484 | * VFT registered with the FIB node for the adj delegate |
| 485 | */ |
| 486 | const static fib_node_vft_t sixrd_fib_node_vft = { |
| 487 | .fnv_get = sixrd_fib_node_get, |
| 488 | .fnv_last_lock = sixrd_fib_node_last_lock_gone, |
| 489 | .fnv_back_walk = sixrd_fib_node_back_walk_notify, |
| 490 | }; |
| 491 | |
| 492 | static clib_error_t * |
| 493 | sixrd_init (vlib_main_t * vm) |
| 494 | { |
| 495 | clib_error_t *error = 0; |
| 496 | |
| 497 | /* Make sure the IPIP tunnel subsystem is initialised */ |
Neale Ranns | 756cd94 | 2018-04-06 09:18:11 -0700 | [diff] [blame] | 498 | error = vlib_call_init_function (vm, ipip_init); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 499 | |
| 500 | sixrd_adj_delegate_type = |
| 501 | adj_delegate_register_new_type (&sixrd_adj_delegate_vft); |
Neale Ranns | 2008912 | 2021-12-02 17:07:14 +0000 | [diff] [blame] | 502 | sixrd_fib_node_type = |
| 503 | fib_node_register_new_type ("sixrd", &sixrd_fib_node_vft); |
Ole Troan | 298c695 | 2018-03-08 12:30:43 +0100 | [diff] [blame] | 504 | |
| 505 | return error; |
| 506 | } |
| 507 | |
| 508 | VLIB_INIT_FUNCTION (sixrd_init); |
| 509 | |
| 510 | /* |
| 511 | * fd.io coding-style-patch-verification: ON |
| 512 | * |
| 513 | * Local Variables: |
| 514 | * eval: (c-set-style "gnu") |
| 515 | * End: |
| 516 | */ |