Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | */ |
| 15 | |
| 16 | #include <vlib/vlib.h> |
| 17 | |
| 18 | #include <vnet/mfib/mfib_entry.h> |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 19 | #include <vnet/mfib/mfib_entry_src.h> |
| 20 | #include <vnet/mfib/mfib_entry_cover.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 21 | #include <vnet/fib/fib_path_list.h> |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 22 | #include <vnet/fib/fib_walk.h> |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 23 | |
| 24 | #include <vnet/dpo/drop_dpo.h> |
| 25 | #include <vnet/dpo/replicate_dpo.h> |
| 26 | |
| 27 | /** |
Neale Ranns | 710071b | 2018-09-24 12:36:26 +0000 | [diff] [blame] | 28 | * the logger |
| 29 | */ |
| 30 | vlib_log_class_t mfib_entry_logger; |
| 31 | |
| 32 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 33 | * Pool of path extensions |
| 34 | */ |
| 35 | static mfib_path_ext_t *mfib_path_ext_pool; |
| 36 | |
| 37 | /** |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 38 | * String names for each source |
| 39 | */ |
| 40 | static const char *mfib_source_names[] = MFIB_SOURCE_NAMES; |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 41 | static const char *mfib_src_attribute_names[] = MFIB_ENTRY_SRC_ATTRIBUTES; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Pool for all fib_entries |
| 45 | */ |
| 46 | mfib_entry_t *mfib_entry_pool; |
| 47 | |
| 48 | static fib_node_t * |
| 49 | mfib_entry_get_node (fib_node_index_t index) |
| 50 | { |
| 51 | return ((fib_node_t*)mfib_entry_get(index)); |
| 52 | } |
| 53 | |
| 54 | static fib_protocol_t |
| 55 | mfib_entry_get_proto (const mfib_entry_t * mfib_entry) |
| 56 | { |
| 57 | return (mfib_entry->mfe_prefix.fp_proto); |
| 58 | } |
| 59 | |
| 60 | fib_forward_chain_type_t |
| 61 | mfib_entry_get_default_chain_type (const mfib_entry_t *mfib_entry) |
| 62 | { |
| 63 | switch (mfib_entry->mfe_prefix.fp_proto) |
| 64 | { |
| 65 | case FIB_PROTOCOL_IP4: |
| 66 | return (FIB_FORW_CHAIN_TYPE_MCAST_IP4); |
| 67 | case FIB_PROTOCOL_IP6: |
| 68 | return (FIB_FORW_CHAIN_TYPE_MCAST_IP6); |
| 69 | case FIB_PROTOCOL_MPLS: |
| 70 | ASSERT(0); |
| 71 | break; |
| 72 | } |
| 73 | return (FIB_FORW_CHAIN_TYPE_MCAST_IP4); |
| 74 | } |
| 75 | |
| 76 | static u8 * |
| 77 | format_mfib_entry_dpo (u8 * s, va_list * args) |
| 78 | { |
| 79 | index_t fei = va_arg(*args, index_t); |
| 80 | CLIB_UNUSED(u32 indent) = va_arg(*args, u32); |
| 81 | |
| 82 | return (format(s, "%U", |
| 83 | format_mfib_entry, fei, |
| 84 | MFIB_ENTRY_FORMAT_BRIEF)); |
| 85 | } |
| 86 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 87 | static inline mfib_path_ext_t * |
| 88 | mfib_entry_path_ext_get (index_t mi) |
| 89 | { |
| 90 | return (pool_elt_at_index(mfib_path_ext_pool, mi)); |
| 91 | } |
| 92 | |
| 93 | static u8 * |
| 94 | format_mfib_entry_path_ext (u8 * s, va_list * args) |
| 95 | { |
| 96 | mfib_path_ext_t *path_ext; |
| 97 | index_t mpi = va_arg(*args, index_t); |
| 98 | |
| 99 | path_ext = mfib_entry_path_ext_get(mpi); |
| 100 | return (format(s, "path:%d flags:%U", |
| 101 | path_ext->mfpe_path, |
| 102 | format_mfib_itf_flags, path_ext->mfpe_flags)); |
| 103 | } |
| 104 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 105 | u8 * |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 106 | format_mfib_entry_src_flags (u8 *s, va_list *args) |
| 107 | { |
| 108 | mfib_entry_src_attribute_t sattr; |
| 109 | mfib_entry_src_flags_t flag = va_arg(*args, int); |
| 110 | |
| 111 | if (!flag) |
| 112 | { |
| 113 | return format(s, "none"); |
| 114 | } |
| 115 | |
| 116 | FOR_EACH_MFIB_SRC_ATTRIBUTE(sattr) { |
| 117 | if ((1 << sattr) & flag) { |
| 118 | s = format (s, "%s,", mfib_src_attribute_names[sattr]); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | return (s); |
| 123 | } |
| 124 | |
| 125 | u8 * |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 126 | format_mfib_entry (u8 * s, va_list * args) |
| 127 | { |
| 128 | fib_node_index_t fei, mfi; |
| 129 | mfib_entry_t *mfib_entry; |
| 130 | mfib_entry_src_t *msrc; |
| 131 | u32 sw_if_index; |
| 132 | int level; |
| 133 | |
| 134 | fei = va_arg (*args, fib_node_index_t); |
| 135 | level = va_arg (*args, int); |
| 136 | mfib_entry = mfib_entry_get(fei); |
| 137 | |
| 138 | s = format (s, "%U", format_mfib_prefix, &mfib_entry->mfe_prefix); |
| 139 | s = format (s, ": %U", format_mfib_entry_flags, mfib_entry->mfe_flags); |
| 140 | |
| 141 | if (level >= MFIB_ENTRY_FORMAT_DETAIL) |
| 142 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 143 | fib_node_index_t path_index, mpi; |
| 144 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 145 | s = format (s, "\n"); |
| 146 | s = format (s, " fib:%d", mfib_entry->mfe_fib_index); |
| 147 | s = format (s, " index:%d", mfib_entry_get_index(mfib_entry)); |
| 148 | s = format (s, " locks:%d\n", mfib_entry->mfe_node.fn_locks); |
| 149 | vec_foreach(msrc, mfib_entry->mfe_srcs) |
| 150 | { |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 151 | s = format (s, " src:%s flags:%U locks:%d:", |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 152 | mfib_source_names[msrc->mfes_src], |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 153 | format_mfib_entry_src_flags, msrc->mfes_flags, |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 154 | msrc->mfes_ref_count); |
| 155 | if (msrc->mfes_cover != FIB_NODE_INDEX_INVALID) |
| 156 | { |
| 157 | s = format (s, " cover:%d", msrc->mfes_cover); |
| 158 | } |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 159 | s = format (s, " %U\n", format_mfib_entry_flags, msrc->mfes_route_flags); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 160 | if (FIB_NODE_INDEX_INVALID != msrc->mfes_pl) |
| 161 | { |
| 162 | s = fib_path_list_format(msrc->mfes_pl, s); |
| 163 | } |
Neale Ranns | 5d85f2d | 2017-05-02 10:17:17 -0700 | [diff] [blame] | 164 | s = format (s, " Extensions:\n"); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 165 | hash_foreach(path_index, mpi, msrc->mfes_exts, |
| 166 | ({ |
| 167 | s = format(s, " %U\n", format_mfib_entry_path_ext, mpi); |
| 168 | })); |
Neale Ranns | 5d85f2d | 2017-05-02 10:17:17 -0700 | [diff] [blame] | 169 | s = format (s, " Interface-Forwarding:\n"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 170 | hash_foreach(sw_if_index, mfi, msrc->mfes_itfs, |
| 171 | ({ |
| 172 | s = format(s, " %U\n", format_mfib_itf, mfi); |
| 173 | })); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | s = format(s, "\n Interfaces:"); |
| 178 | hash_foreach(sw_if_index, mfi, mfib_entry->mfe_itfs, |
| 179 | ({ |
| 180 | s = format(s, "\n %U", format_mfib_itf, mfi); |
| 181 | })); |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 182 | if (MFIB_RPF_ID_NONE != mfib_entry->mfe_rpf_id) |
| 183 | { |
| 184 | s = format(s, "\n RPF-ID:%d", mfib_entry->mfe_rpf_id); |
| 185 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 186 | s = format(s, "\n %U-chain\n %U", |
| 187 | format_fib_forw_chain_type, |
| 188 | mfib_entry_get_default_chain_type(mfib_entry), |
| 189 | format_dpo_id, |
| 190 | &mfib_entry->mfe_rep, |
| 191 | 2); |
| 192 | s = format(s, "\n"); |
| 193 | |
| 194 | if (level >= MFIB_ENTRY_FORMAT_DETAIL2) |
| 195 | { |
| 196 | s = format(s, "\nchildren:"); |
| 197 | s = fib_node_children_format(mfib_entry->mfe_node.fn_children, s); |
| 198 | } |
| 199 | |
| 200 | return (s); |
| 201 | } |
| 202 | |
| 203 | static mfib_entry_t* |
| 204 | mfib_entry_from_fib_node (fib_node_t *node) |
| 205 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 206 | ASSERT(FIB_NODE_TYPE_MFIB_ENTRY == node->fn_type); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 207 | return ((mfib_entry_t*)node); |
| 208 | } |
| 209 | |
| 210 | static int |
| 211 | mfib_entry_src_cmp_for_sort (void * v1, |
| 212 | void * v2) |
| 213 | { |
| 214 | mfib_entry_src_t *esrc1 = v1, *esrc2 = v2; |
| 215 | |
| 216 | return (esrc1->mfes_src - esrc2->mfes_src); |
| 217 | } |
| 218 | |
| 219 | static void |
| 220 | mfib_entry_src_init (mfib_entry_t *mfib_entry, |
| 221 | mfib_source_t source) |
| 222 | |
| 223 | { |
| 224 | mfib_entry_src_t esrc = { |
| 225 | .mfes_pl = FIB_NODE_INDEX_INVALID, |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 226 | .mfes_route_flags = MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 227 | .mfes_src = source, |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 228 | .mfes_cover = FIB_NODE_INDEX_INVALID, |
| 229 | .mfes_sibling = FIB_NODE_INDEX_INVALID, |
| 230 | .mfes_ref_count = 1, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | vec_add1(mfib_entry->mfe_srcs, esrc); |
| 234 | vec_sort_with_function(mfib_entry->mfe_srcs, |
| 235 | mfib_entry_src_cmp_for_sort); |
| 236 | } |
| 237 | |
| 238 | static mfib_entry_src_t * |
| 239 | mfib_entry_src_find (const mfib_entry_t *mfib_entry, |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 240 | mfib_source_t source, |
| 241 | u32 *index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 242 | |
| 243 | { |
| 244 | mfib_entry_src_t *esrc; |
| 245 | int ii; |
| 246 | |
| 247 | ii = 0; |
| 248 | vec_foreach(esrc, mfib_entry->mfe_srcs) |
| 249 | { |
| 250 | if (esrc->mfes_src == source) |
| 251 | { |
| 252 | if (NULL != index) |
| 253 | { |
| 254 | *index = ii; |
| 255 | } |
| 256 | return (esrc); |
| 257 | } |
| 258 | else |
| 259 | { |
| 260 | ii++; |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | return (NULL); |
| 265 | } |
| 266 | |
| 267 | static mfib_entry_src_t * |
| 268 | mfib_entry_src_find_or_create (mfib_entry_t *mfib_entry, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 269 | mfib_source_t source) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 270 | { |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 271 | mfib_entry_src_t *msrc; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 272 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 273 | msrc = mfib_entry_src_find(mfib_entry, source, NULL); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 274 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 275 | if (NULL == msrc) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 276 | { |
| 277 | mfib_entry_src_init(mfib_entry, source); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 278 | msrc = mfib_entry_src_find(mfib_entry, source, NULL); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 281 | return (msrc); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 284 | static mfib_entry_src_t * |
| 285 | mfib_entry_src_update (mfib_entry_t *mfib_entry, |
| 286 | mfib_source_t source, |
| 287 | fib_rpf_id_t rpf_id, |
| 288 | mfib_entry_flags_t entry_flags) |
| 289 | { |
| 290 | mfib_entry_src_t *msrc; |
| 291 | |
| 292 | msrc = mfib_entry_src_find_or_create(mfib_entry, source); |
| 293 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 294 | msrc->mfes_route_flags = entry_flags; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 295 | msrc->mfes_rpf_id = rpf_id; |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 296 | msrc->mfes_flags &= ~MFIB_ENTRY_SRC_FLAG_STALE; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 297 | |
| 298 | return (msrc); |
| 299 | } |
| 300 | |
| 301 | static mfib_entry_src_t * |
| 302 | mfib_entry_src_update_and_lock (mfib_entry_t *mfib_entry, |
| 303 | mfib_source_t source, |
| 304 | fib_rpf_id_t rpf_id, |
| 305 | mfib_entry_flags_t entry_flags) |
| 306 | { |
| 307 | mfib_entry_src_t *msrc; |
| 308 | |
| 309 | msrc = mfib_entry_src_update(mfib_entry, source, rpf_id, entry_flags); |
| 310 | |
| 311 | msrc->mfes_ref_count++; |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 312 | msrc->mfes_flags &= ~MFIB_ENTRY_SRC_FLAG_STALE; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 313 | |
| 314 | return (msrc); |
| 315 | } |
| 316 | |
| 317 | mfib_entry_src_t* |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 318 | mfib_entry_get_best_src (const mfib_entry_t *mfib_entry) |
| 319 | { |
| 320 | mfib_entry_src_t *bsrc; |
| 321 | |
| 322 | /* |
| 323 | * the enum of sources is deliberately arranged in priority order |
| 324 | */ |
| 325 | if (0 == vec_len(mfib_entry->mfe_srcs)) |
| 326 | { |
| 327 | bsrc = NULL; |
| 328 | } |
| 329 | else |
| 330 | { |
| 331 | bsrc = vec_elt_at_index(mfib_entry->mfe_srcs, 0); |
| 332 | } |
| 333 | |
| 334 | return (bsrc); |
| 335 | } |
| 336 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 337 | static mfib_source_t |
| 338 | mfib_entry_get_best_source (const mfib_entry_t *mfib_entry) |
| 339 | { |
| 340 | mfib_entry_src_t *bsrc; |
| 341 | |
| 342 | bsrc = mfib_entry_get_best_src(mfib_entry); |
| 343 | |
| 344 | return (bsrc->mfes_src); |
| 345 | } |
| 346 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 347 | int |
| 348 | mfib_entry_is_sourced (fib_node_index_t mfib_entry_index, |
| 349 | mfib_source_t source) |
| 350 | { |
| 351 | mfib_entry_t *mfib_entry; |
| 352 | |
| 353 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 354 | |
| 355 | return (NULL != mfib_entry_src_find(mfib_entry, source, NULL)); |
| 356 | } |
| 357 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 358 | int |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 359 | mfib_entry_is_marked (fib_node_index_t mfib_entry_index, |
| 360 | mfib_source_t source) |
| 361 | { |
| 362 | mfib_entry_t *mfib_entry; |
| 363 | mfib_entry_src_t *esrc; |
| 364 | |
| 365 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 366 | |
| 367 | esrc = mfib_entry_src_find(mfib_entry, source, NULL); |
| 368 | |
| 369 | if (NULL == esrc) |
| 370 | { |
| 371 | return (0); |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | return (!!(esrc->mfes_flags & MFIB_ENTRY_SRC_FLAG_STALE)); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | void |
| 380 | mfib_entry_mark (fib_node_index_t fib_entry_index, |
| 381 | mfib_source_t source) |
| 382 | { |
| 383 | mfib_entry_t *mfib_entry; |
| 384 | mfib_entry_src_t *esrc; |
| 385 | |
| 386 | mfib_entry = mfib_entry_get(fib_entry_index); |
| 387 | |
| 388 | esrc = mfib_entry_src_find(mfib_entry, source, NULL); |
| 389 | |
| 390 | if (NULL != esrc) |
| 391 | { |
| 392 | esrc->mfes_flags |= MFIB_ENTRY_SRC_FLAG_STALE; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | int |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 397 | mfib_entry_is_host (fib_node_index_t mfib_entry_index) |
| 398 | { |
| 399 | return (mfib_prefix_is_host(mfib_entry_get_prefix(mfib_entry_index))); |
| 400 | } |
| 401 | |
| 402 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 403 | static void |
| 404 | mfib_entry_src_flush (mfib_entry_src_t *msrc) |
| 405 | { |
| 406 | u32 sw_if_index; |
| 407 | index_t mfii; |
| 408 | |
| 409 | hash_foreach(sw_if_index, mfii, msrc->mfes_itfs, |
| 410 | ({ |
| 411 | mfib_itf_delete(mfib_itf_get(mfii)); |
| 412 | })); |
Neale Ranns | bcc6aa4 | 2017-02-24 01:34:14 -0800 | [diff] [blame] | 413 | hash_free(msrc->mfes_itfs); |
| 414 | msrc->mfes_itfs = NULL; |
Steven Luong | 221be7c | 2021-12-15 13:27:53 -0800 | [diff] [blame^] | 415 | hash_free(msrc->mfes_exts); |
| 416 | msrc->mfes_exts = NULL; |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 417 | fib_path_list_unlock(msrc->mfes_pl); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | static void |
| 421 | mfib_entry_src_remove (mfib_entry_t *mfib_entry, |
| 422 | mfib_source_t source) |
| 423 | |
| 424 | { |
| 425 | mfib_entry_src_t *msrc; |
| 426 | u32 index = ~0; |
| 427 | |
| 428 | msrc = mfib_entry_src_find(mfib_entry, source, &index); |
| 429 | |
| 430 | if (NULL != msrc) |
| 431 | { |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 432 | ASSERT(0 != msrc->mfes_ref_count); |
| 433 | msrc->mfes_ref_count--; |
| 434 | |
| 435 | if (0 == msrc->mfes_ref_count) |
| 436 | { |
| 437 | mfib_entry_src_deactivate(mfib_entry, msrc); |
| 438 | mfib_entry_src_flush(msrc); |
| 439 | |
| 440 | vec_del1(mfib_entry->mfe_srcs, index); |
| 441 | if (vec_len (mfib_entry->mfe_srcs) > 1) |
| 442 | vec_sort_with_function(mfib_entry->mfe_srcs, |
| 443 | mfib_entry_src_cmp_for_sort); |
| 444 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 445 | } |
| 446 | } |
| 447 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 448 | u32 |
| 449 | mfib_entry_child_add (fib_node_index_t mfib_entry_index, |
| 450 | fib_node_type_t child_type, |
| 451 | fib_node_index_t child_index) |
| 452 | { |
| 453 | return (fib_node_child_add(FIB_NODE_TYPE_MFIB_ENTRY, |
| 454 | mfib_entry_index, |
| 455 | child_type, |
| 456 | child_index)); |
| 457 | }; |
| 458 | |
| 459 | void |
| 460 | mfib_entry_child_remove (fib_node_index_t mfib_entry_index, |
| 461 | u32 sibling_index) |
| 462 | { |
| 463 | fib_node_child_remove(FIB_NODE_TYPE_MFIB_ENTRY, |
| 464 | mfib_entry_index, |
| 465 | sibling_index); |
| 466 | } |
| 467 | |
| 468 | static mfib_entry_t * |
| 469 | mfib_entry_alloc (u32 fib_index, |
| 470 | const mfib_prefix_t *prefix, |
| 471 | fib_node_index_t *mfib_entry_index) |
| 472 | { |
| 473 | mfib_entry_t *mfib_entry; |
| 474 | |
Marco Varlese | 47501da | 2017-08-29 14:04:06 +0200 | [diff] [blame] | 475 | pool_get_aligned(mfib_entry_pool, mfib_entry, CLIB_CACHE_LINE_BYTES); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 476 | |
| 477 | fib_node_init(&mfib_entry->mfe_node, |
| 478 | FIB_NODE_TYPE_MFIB_ENTRY); |
| 479 | |
Neale Ranns | 5a72c1c | 2017-02-24 08:29:22 -0800 | [diff] [blame] | 480 | /* |
| 481 | * Some of the members require non-default initialisation |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 482 | * so we also init those that don't and thus save on the call to clib_memset. |
Neale Ranns | 5a72c1c | 2017-02-24 08:29:22 -0800 | [diff] [blame] | 483 | */ |
| 484 | mfib_entry->mfe_flags = 0; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 485 | mfib_entry->mfe_fib_index = fib_index; |
| 486 | mfib_entry->mfe_prefix = *prefix; |
Neale Ranns | 5a72c1c | 2017-02-24 08:29:22 -0800 | [diff] [blame] | 487 | mfib_entry->mfe_srcs = NULL; |
| 488 | mfib_entry->mfe_itfs = NULL; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 489 | mfib_entry->mfe_rpf_id = MFIB_RPF_ID_NONE; |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 490 | mfib_entry->mfe_pl = FIB_NODE_INDEX_INVALID; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 491 | |
| 492 | dpo_reset(&mfib_entry->mfe_rep); |
| 493 | |
| 494 | *mfib_entry_index = mfib_entry_get_index(mfib_entry); |
| 495 | |
| 496 | MFIB_ENTRY_DBG(mfib_entry, "alloc"); |
| 497 | |
| 498 | return (mfib_entry); |
| 499 | } |
| 500 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 501 | static inline mfib_path_ext_t * |
| 502 | mfib_entry_path_ext_find (mfib_path_ext_t *exts, |
| 503 | fib_node_index_t path_index) |
| 504 | { |
| 505 | uword *p; |
| 506 | |
| 507 | p = hash_get(exts, path_index); |
| 508 | |
| 509 | if (NULL != p) |
| 510 | { |
| 511 | return (mfib_entry_path_ext_get(p[0])); |
| 512 | } |
| 513 | |
| 514 | return (NULL); |
| 515 | } |
| 516 | |
| 517 | static mfib_path_ext_t* |
| 518 | mfib_path_ext_add (mfib_entry_src_t *msrc, |
| 519 | fib_node_index_t path_index, |
| 520 | mfib_itf_flags_t mfi_flags) |
| 521 | { |
| 522 | mfib_path_ext_t *path_ext; |
| 523 | |
| 524 | pool_get(mfib_path_ext_pool, path_ext); |
| 525 | |
| 526 | path_ext->mfpe_flags = mfi_flags; |
| 527 | path_ext->mfpe_path = path_index; |
| 528 | |
| 529 | hash_set(msrc->mfes_exts, path_index, |
| 530 | path_ext - mfib_path_ext_pool); |
| 531 | |
| 532 | return (path_ext); |
| 533 | } |
| 534 | |
| 535 | static void |
| 536 | mfib_path_ext_remove (mfib_entry_src_t *msrc, |
| 537 | fib_node_index_t path_index) |
| 538 | { |
| 539 | mfib_path_ext_t *path_ext; |
| 540 | |
| 541 | path_ext = mfib_entry_path_ext_find(msrc->mfes_exts, path_index); |
| 542 | |
| 543 | hash_unset(msrc->mfes_exts, path_index); |
| 544 | pool_put(mfib_path_ext_pool, path_ext); |
| 545 | } |
| 546 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 547 | typedef struct mfib_entry_collect_forwarding_ctx_t_ |
| 548 | { |
| 549 | load_balance_path_t * next_hops; |
| 550 | fib_forward_chain_type_t fct; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 551 | mfib_entry_src_t *msrc; |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 552 | dpo_proto_t payload_proto; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 553 | } mfib_entry_collect_forwarding_ctx_t; |
| 554 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 555 | static fib_path_list_walk_rc_t |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 556 | mfib_entry_src_collect_forwarding (fib_node_index_t pl_index, |
| 557 | fib_node_index_t path_index, |
| 558 | void *arg) |
| 559 | { |
| 560 | mfib_entry_collect_forwarding_ctx_t *ctx; |
| 561 | load_balance_path_t *nh; |
| 562 | |
| 563 | ctx = arg; |
| 564 | |
| 565 | /* |
| 566 | * if the path is not resolved, don't include it. |
| 567 | */ |
| 568 | if (!fib_path_is_resolved(path_index)) |
| 569 | { |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 570 | return (FIB_PATH_LIST_WALK_CONTINUE); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 573 | /* |
| 574 | * If the path is not forwarding to use it |
| 575 | */ |
| 576 | mfib_path_ext_t *path_ext; |
| 577 | |
| 578 | path_ext = mfib_entry_path_ext_find(ctx->msrc->mfes_exts, |
| 579 | path_index); |
| 580 | |
| 581 | if (NULL != path_ext && |
| 582 | !(path_ext->mfpe_flags & MFIB_ITF_FLAG_FORWARD)) |
| 583 | { |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 584 | return (FIB_PATH_LIST_WALK_CONTINUE); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 587 | switch (ctx->fct) |
| 588 | { |
| 589 | case FIB_FORW_CHAIN_TYPE_MCAST_IP4: |
| 590 | case FIB_FORW_CHAIN_TYPE_MCAST_IP6: |
| 591 | /* |
| 592 | * EOS traffic with no label to stack, we need the IP Adj |
| 593 | */ |
| 594 | vec_add2(ctx->next_hops, nh, 1); |
| 595 | |
| 596 | nh->path_index = path_index; |
| 597 | nh->path_weight = fib_path_get_weight(path_index); |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 598 | fib_path_contribute_forwarding(path_index, ctx->fct, |
| 599 | ctx->payload_proto, &nh->path_dpo); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 600 | break; |
| 601 | |
| 602 | case FIB_FORW_CHAIN_TYPE_UNICAST_IP4: |
| 603 | case FIB_FORW_CHAIN_TYPE_UNICAST_IP6: |
| 604 | case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS: |
| 605 | case FIB_FORW_CHAIN_TYPE_MPLS_EOS: |
| 606 | case FIB_FORW_CHAIN_TYPE_ETHERNET: |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 607 | case FIB_FORW_CHAIN_TYPE_NSH: |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 608 | case FIB_FORW_CHAIN_TYPE_BIER: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 609 | ASSERT(0); |
| 610 | break; |
| 611 | } |
| 612 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 613 | return (FIB_PATH_LIST_WALK_CONTINUE); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static void |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 617 | mfib_entry_stack (mfib_entry_t *mfib_entry, |
| 618 | mfib_entry_src_t *msrc) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 619 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 620 | dpo_proto_t dp; |
| 621 | |
| 622 | dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry)); |
| 623 | |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 624 | /* |
| 625 | * unlink the enty from the previous path list. |
| 626 | */ |
| 627 | if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_pl) |
| 628 | { |
| 629 | fib_path_list_child_remove(mfib_entry->mfe_pl, |
| 630 | mfib_entry->mfe_sibling); |
| 631 | } |
| 632 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 633 | if (NULL != msrc) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 634 | { |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 635 | mfib_entry_collect_forwarding_ctx_t ctx = { |
| 636 | .next_hops = NULL, |
| 637 | .fct = mfib_entry_get_default_chain_type(mfib_entry), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 638 | .msrc = msrc, |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 639 | .payload_proto = fib_proto_to_dpo(mfib_entry->mfe_prefix.fp_proto), |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 640 | }; |
| 641 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 642 | /* |
| 643 | * link the entry to the path-list. |
| 644 | * The entry needs to be a child so that we receive the back-walk |
| 645 | * updates to recalculate forwarding. |
| 646 | */ |
| 647 | mfib_entry->mfe_pl = msrc->mfes_pl; |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 648 | mfib_entry->mfe_flags = msrc->mfes_route_flags; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 649 | mfib_entry->mfe_itfs = msrc->mfes_itfs; |
| 650 | mfib_entry->mfe_rpf_id = msrc->mfes_rpf_id; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 651 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 652 | if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_pl) |
| 653 | { |
| 654 | mfib_entry->mfe_sibling = |
| 655 | fib_path_list_child_add(mfib_entry->mfe_pl, |
| 656 | FIB_NODE_TYPE_MFIB_ENTRY, |
| 657 | mfib_entry_get_index(mfib_entry)); |
| 658 | |
| 659 | fib_path_list_walk(mfib_entry->mfe_pl, |
| 660 | mfib_entry_src_collect_forwarding, |
| 661 | &ctx); |
| 662 | } |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 663 | if (!(MFIB_ENTRY_FLAG_EXCLUSIVE & mfib_entry->mfe_flags)) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 664 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 665 | if (NULL == ctx.next_hops) |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 666 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 667 | /* |
| 668 | * no next-hops, stack directly on the drop |
| 669 | */ |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 670 | dpo_stack(DPO_MFIB_ENTRY, dp, |
| 671 | &mfib_entry->mfe_rep, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 672 | drop_dpo_get(dp)); |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 673 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 674 | else |
| 675 | { |
| 676 | /* |
| 677 | * each path contirbutes a next-hop. form a replicate |
| 678 | * from those choices. |
| 679 | */ |
| 680 | if (!dpo_id_is_valid(&mfib_entry->mfe_rep) || |
| 681 | dpo_is_drop(&mfib_entry->mfe_rep)) |
| 682 | { |
| 683 | dpo_id_t tmp_dpo = DPO_INVALID; |
| 684 | |
| 685 | dpo_set(&tmp_dpo, |
| 686 | DPO_REPLICATE, dp, |
| 687 | replicate_create(0, dp)); |
| 688 | |
| 689 | dpo_stack(DPO_MFIB_ENTRY, dp, |
| 690 | &mfib_entry->mfe_rep, |
| 691 | &tmp_dpo); |
| 692 | |
| 693 | dpo_reset(&tmp_dpo); |
| 694 | } |
| 695 | replicate_multipath_update(&mfib_entry->mfe_rep, |
| 696 | ctx.next_hops); |
| 697 | } |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 698 | } |
| 699 | else |
| 700 | { |
| 701 | /* |
| 702 | * for exclusive routes the source provided a replicate DPO |
Neale Ranns | b7778b6 | 2018-12-21 07:00:56 -0800 | [diff] [blame] | 703 | * which we stashed in the special path list with one path, |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 704 | * so we can stack directly on that. |
| 705 | */ |
| 706 | ASSERT(1 == vec_len(ctx.next_hops)); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 707 | |
Neale Ranns | b7778b6 | 2018-12-21 07:00:56 -0800 | [diff] [blame] | 708 | if (NULL != ctx.next_hops) |
| 709 | { |
| 710 | dpo_stack(DPO_MFIB_ENTRY, dp, |
| 711 | &mfib_entry->mfe_rep, |
| 712 | &ctx.next_hops[0].path_dpo); |
| 713 | dpo_reset(&ctx.next_hops[0].path_dpo); |
| 714 | vec_free(ctx.next_hops); |
| 715 | } |
| 716 | else |
| 717 | { |
| 718 | dpo_stack(DPO_MFIB_ENTRY, dp, |
| 719 | &mfib_entry->mfe_rep, |
| 720 | drop_dpo_get(dp)); |
| 721 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 722 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 723 | } |
| 724 | else |
| 725 | { |
| 726 | dpo_stack(DPO_MFIB_ENTRY, dp, |
| 727 | &mfib_entry->mfe_rep, |
| 728 | drop_dpo_get(dp)); |
| 729 | } |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 730 | |
| 731 | /* |
| 732 | * time for walkies fido. |
| 733 | */ |
| 734 | fib_node_back_walk_ctx_t bw_ctx = { |
| 735 | .fnbw_reason = FIB_NODE_BW_REASON_FLAG_EVALUATE, |
| 736 | }; |
| 737 | |
| 738 | fib_walk_sync(FIB_NODE_TYPE_MFIB_ENTRY, |
| 739 | mfib_entry_get_index(mfib_entry), |
| 740 | &bw_ctx); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 741 | } |
| 742 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 743 | static fib_node_index_t* |
| 744 | mfib_entry_src_paths_add (mfib_entry_src_t *msrc, |
| 745 | const fib_route_path_t *rpaths) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 746 | { |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 747 | ASSERT(!(MFIB_ENTRY_FLAG_EXCLUSIVE & msrc->mfes_route_flags)); |
| 748 | |
| 749 | msrc->mfes_flags &= ~MFIB_ENTRY_SRC_FLAG_STALE; |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 750 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 751 | if (FIB_NODE_INDEX_INVALID == msrc->mfes_pl) |
| 752 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 753 | /* A non-shared path-list */ |
| 754 | msrc->mfes_pl = fib_path_list_create(FIB_PATH_LIST_FLAG_NO_URPF, |
| 755 | NULL); |
| 756 | fib_path_list_lock(msrc->mfes_pl); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 757 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 758 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 759 | return (fib_path_list_paths_add(msrc->mfes_pl, rpaths)); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 760 | } |
| 761 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 762 | static fib_node_index_t* |
| 763 | mfib_entry_src_paths_remove (mfib_entry_src_t *msrc, |
| 764 | const fib_route_path_t *rpaths) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 765 | { |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 766 | ASSERT(!(MFIB_ENTRY_FLAG_EXCLUSIVE & msrc->mfes_route_flags)); |
| 767 | |
| 768 | msrc->mfes_flags &= ~MFIB_ENTRY_SRC_FLAG_STALE; |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 769 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 770 | return (fib_path_list_paths_remove(msrc->mfes_pl, rpaths)); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | static void |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 774 | mfib_entry_recalculate_forwarding (mfib_entry_t *mfib_entry, |
| 775 | mfib_source_t old_best) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 776 | { |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 777 | mfib_entry_src_t *bsrc, *osrc; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 778 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 779 | /* |
| 780 | * copy the forwarding data from the bast source |
| 781 | */ |
| 782 | bsrc = mfib_entry_get_best_src(mfib_entry); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 783 | osrc = mfib_entry_src_find(mfib_entry, old_best, NULL); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 784 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 785 | if (NULL != bsrc) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 786 | { |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 787 | if (bsrc->mfes_src != old_best) |
| 788 | { |
| 789 | /* |
| 790 | * we are changing from one source to another |
| 791 | * deactivate the old, and activate the new |
| 792 | */ |
| 793 | mfib_entry_src_deactivate(mfib_entry, osrc); |
| 794 | mfib_entry_src_activate(mfib_entry, bsrc); |
| 795 | } |
| 796 | } |
| 797 | else |
| 798 | { |
| 799 | mfib_entry_src_deactivate(mfib_entry, osrc); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 802 | mfib_entry_stack(mfib_entry, bsrc); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 803 | mfib_entry_cover_update_notify(mfib_entry); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | |
| 807 | fib_node_index_t |
| 808 | mfib_entry_create (u32 fib_index, |
| 809 | mfib_source_t source, |
| 810 | const mfib_prefix_t *prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 811 | fib_rpf_id_t rpf_id, |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 812 | mfib_entry_flags_t entry_flags, |
| 813 | index_t repi) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 814 | { |
| 815 | fib_node_index_t mfib_entry_index; |
| 816 | mfib_entry_t *mfib_entry; |
| 817 | mfib_entry_src_t *msrc; |
| 818 | |
| 819 | mfib_entry = mfib_entry_alloc(fib_index, prefix, |
| 820 | &mfib_entry_index); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 821 | msrc = mfib_entry_src_update(mfib_entry, source, |
| 822 | rpf_id, entry_flags); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 823 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 824 | if (INDEX_INVALID != repi) |
| 825 | { |
| 826 | /* |
| 827 | * The source is providing its own replicate DPO. |
| 828 | * Create a sepcial path-list to manage it, that way |
| 829 | * this entry and the source are equivalent to a normal |
| 830 | * entry |
| 831 | */ |
| 832 | fib_node_index_t old_pl_index; |
| 833 | dpo_proto_t dp; |
| 834 | dpo_id_t dpo = DPO_INVALID; |
| 835 | |
| 836 | dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry)); |
| 837 | old_pl_index = msrc->mfes_pl; |
| 838 | |
| 839 | dpo_set(&dpo, DPO_REPLICATE, dp, repi); |
| 840 | |
| 841 | msrc->mfes_pl = |
| 842 | fib_path_list_create_special(dp, |
| 843 | FIB_PATH_LIST_FLAG_EXCLUSIVE, |
| 844 | &dpo); |
| 845 | |
| 846 | dpo_reset(&dpo); |
| 847 | fib_path_list_lock(msrc->mfes_pl); |
| 848 | fib_path_list_unlock(old_pl_index); |
| 849 | } |
| 850 | |
| 851 | mfib_entry_recalculate_forwarding(mfib_entry, MFIB_SOURCE_NONE); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 852 | |
| 853 | return (mfib_entry_index); |
| 854 | } |
| 855 | |
| 856 | static int |
| 857 | mfib_entry_ok_for_delete (mfib_entry_t *mfib_entry) |
| 858 | { |
| 859 | return (0 == vec_len(mfib_entry->mfe_srcs)); |
| 860 | } |
| 861 | |
| 862 | static int |
| 863 | mfib_entry_src_ok_for_delete (const mfib_entry_src_t *msrc) |
| 864 | { |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 865 | return ((INDEX_INVALID == msrc->mfes_cover && |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 866 | MFIB_ENTRY_FLAG_NONE == msrc->mfes_route_flags && |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 867 | 0 == fib_path_list_get_n_paths(msrc->mfes_pl)) && |
| 868 | (0 == hash_elts(msrc->mfes_itfs))); |
| 869 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 870 | /* return ((MFIB_ENTRY_FLAG_NONE == msrc->mfes_route_flags) && */ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 871 | /* (0 == fib_path_list_get_n_paths(msrc->mfes_pl)) && */ |
| 872 | /* (0 == hash_elts(msrc->mfes_itfs))); */ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 875 | |
| 876 | static void |
| 877 | mfib_entry_update_i (mfib_entry_t *mfib_entry, |
| 878 | mfib_entry_src_t *msrc, |
| 879 | mfib_source_t current_best, |
| 880 | index_t repi) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 881 | { |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 882 | if (INDEX_INVALID != repi) |
| 883 | { |
| 884 | /* |
| 885 | * The source is providing its own replicate DPO. |
| 886 | * Create a sepcial path-list to manage it, that way |
| 887 | * this entry and the source are equivalent to a normal |
| 888 | * entry |
| 889 | */ |
| 890 | fib_node_index_t old_pl_index; |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 891 | dpo_proto_t dp; |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 892 | dpo_id_t dpo = DPO_INVALID; |
| 893 | |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 894 | dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry)); |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 895 | old_pl_index = msrc->mfes_pl; |
| 896 | |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 897 | dpo_set(&dpo, DPO_REPLICATE, dp, repi); |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 898 | |
| 899 | msrc->mfes_pl = |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 900 | fib_path_list_create_special(dp, |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 901 | FIB_PATH_LIST_FLAG_EXCLUSIVE, |
| 902 | &dpo); |
| 903 | |
| 904 | dpo_reset(&dpo); |
| 905 | fib_path_list_lock(msrc->mfes_pl); |
| 906 | fib_path_list_unlock(old_pl_index); |
| 907 | } |
| 908 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 909 | if (mfib_entry_src_ok_for_delete(msrc)) |
| 910 | { |
| 911 | /* |
| 912 | * this source has no interfaces and no flags. |
| 913 | * it has nothing left to give - remove it |
| 914 | */ |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 915 | mfib_entry_src_remove(mfib_entry, msrc->mfes_src); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 918 | mfib_entry_recalculate_forwarding(mfib_entry, current_best); |
| 919 | } |
| 920 | |
| 921 | int |
| 922 | mfib_entry_special_add (fib_node_index_t mfib_entry_index, |
| 923 | mfib_source_t source, |
| 924 | mfib_entry_flags_t entry_flags, |
| 925 | fib_rpf_id_t rpf_id, |
| 926 | index_t repi) |
| 927 | { |
| 928 | mfib_source_t current_best; |
| 929 | mfib_entry_t *mfib_entry; |
| 930 | mfib_entry_src_t *msrc; |
| 931 | |
| 932 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 933 | current_best = mfib_entry_get_best_source(mfib_entry); |
| 934 | |
| 935 | msrc = mfib_entry_src_update_and_lock(mfib_entry, source, rpf_id, |
| 936 | entry_flags); |
| 937 | |
| 938 | mfib_entry_update_i(mfib_entry, msrc, current_best, repi); |
| 939 | |
| 940 | return (mfib_entry_ok_for_delete(mfib_entry)); |
| 941 | } |
| 942 | |
| 943 | int |
| 944 | mfib_entry_update (fib_node_index_t mfib_entry_index, |
| 945 | mfib_source_t source, |
| 946 | mfib_entry_flags_t entry_flags, |
| 947 | fib_rpf_id_t rpf_id, |
| 948 | index_t repi) |
| 949 | { |
| 950 | mfib_source_t current_best; |
| 951 | mfib_entry_t *mfib_entry; |
| 952 | mfib_entry_src_t *msrc; |
| 953 | |
| 954 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 955 | current_best = mfib_entry_get_best_source(mfib_entry); |
| 956 | msrc = mfib_entry_src_update(mfib_entry, source, rpf_id, entry_flags); |
| 957 | |
| 958 | mfib_entry_update_i(mfib_entry, msrc, current_best, repi); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 959 | |
| 960 | return (mfib_entry_ok_for_delete(mfib_entry)); |
| 961 | } |
| 962 | |
| 963 | static void |
| 964 | mfib_entry_itf_add (mfib_entry_src_t *msrc, |
| 965 | u32 sw_if_index, |
| 966 | index_t mi) |
| 967 | { |
| 968 | hash_set(msrc->mfes_itfs, sw_if_index, mi); |
| 969 | } |
| 970 | |
| 971 | static void |
| 972 | mfib_entry_itf_remove (mfib_entry_src_t *msrc, |
| 973 | u32 sw_if_index) |
| 974 | { |
| 975 | mfib_itf_t *mfi; |
| 976 | |
| 977 | mfi = mfib_entry_itf_find(msrc->mfes_itfs, sw_if_index); |
| 978 | |
| 979 | mfib_itf_delete(mfi); |
| 980 | |
| 981 | hash_unset(msrc->mfes_itfs, sw_if_index); |
| 982 | } |
| 983 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 984 | static int |
| 985 | mfib_entry_path_itf_based (const fib_route_path_t *rpath) |
| 986 | { |
| 987 | return (!(rpath->frp_flags & FIB_ROUTE_PATH_BIER_IMP) && |
| 988 | ~0 != rpath->frp_sw_if_index); |
| 989 | } |
| 990 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 991 | void |
| 992 | mfib_entry_path_update (fib_node_index_t mfib_entry_index, |
| 993 | mfib_source_t source, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 994 | const fib_route_path_t *rpaths) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 995 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 996 | fib_node_index_t* path_indices, path_index; |
| 997 | const fib_route_path_t *rpath; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 998 | mfib_source_t current_best; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 999 | mfib_path_ext_t *path_ext; |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1000 | const mfib_prefix_t *pfx; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1001 | mfib_entry_t *mfib_entry; |
| 1002 | mfib_entry_src_t *msrc; |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 1003 | mfib_itf_flags_t old; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1004 | u32 ii; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1005 | |
| 1006 | mfib_entry = mfib_entry_get(mfib_entry_index); |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1007 | pfx = mfib_entry_get_prefix(mfib_entry_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1008 | ASSERT(NULL != mfib_entry); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1009 | current_best = mfib_entry_get_best_source(mfib_entry); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1010 | msrc = mfib_entry_src_find_or_create(mfib_entry, source); |
| 1011 | |
| 1012 | /* |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1013 | * add the path to the path-list. If it's a duplicate we'll get |
| 1014 | * back the original path. |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1015 | */ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1016 | path_indices = mfib_entry_src_paths_add(msrc, rpaths); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1017 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1018 | vec_foreach_index(ii, path_indices) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1019 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1020 | path_index = path_indices[ii]; |
| 1021 | rpath = &rpaths[ii]; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1022 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1023 | if (FIB_NODE_INDEX_INVALID == path_index) |
| 1024 | continue; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1025 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1026 | /* |
| 1027 | * find the path extension for that path |
| 1028 | */ |
| 1029 | path_ext = mfib_entry_path_ext_find(msrc->mfes_exts, path_index); |
| 1030 | |
| 1031 | if (NULL == path_ext) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1032 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1033 | old = MFIB_ITF_FLAG_NONE; |
| 1034 | path_ext = mfib_path_ext_add(msrc, path_index, |
| 1035 | rpath->frp_mitf_flags); |
| 1036 | } |
| 1037 | else |
| 1038 | { |
| 1039 | old = path_ext->mfpe_flags; |
| 1040 | path_ext->mfpe_flags = rpath->frp_mitf_flags; |
| 1041 | } |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 1042 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1043 | /* |
| 1044 | * Has the path changed its contribution to the input interface set. |
| 1045 | * Which only paths with interfaces can do... |
| 1046 | */ |
| 1047 | if (mfib_entry_path_itf_based(rpath)) |
| 1048 | { |
| 1049 | mfib_itf_t *mfib_itf; |
| 1050 | |
| 1051 | if (old != rpath->frp_mitf_flags) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1052 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1053 | /* |
| 1054 | * change of flag contributions |
| 1055 | */ |
| 1056 | mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs, |
| 1057 | rpath->frp_sw_if_index); |
| 1058 | |
| 1059 | if (NULL == mfib_itf) |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 1060 | { |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1061 | index_t mfib_itf_i = mfib_itf_create(path_index, |
| 1062 | rpath->frp_mitf_flags); |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1063 | mfib_entry_itf_add(msrc, |
| 1064 | rpath->frp_sw_if_index, |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1065 | mfib_itf_i); |
| 1066 | |
| 1067 | if (MFIB_ITF_FLAG_ACCEPT & rpath->frp_mitf_flags) |
| 1068 | { |
| 1069 | /* new accepting interface - add the mac to the driver */ |
| 1070 | mfib_itf_mac_add(mfib_itf_get(mfib_itf_i), pfx); |
| 1071 | } |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1072 | } |
| 1073 | else |
| 1074 | { |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1075 | u8 was_accept = !!(old & MFIB_ITF_FLAG_ACCEPT); |
| 1076 | u8 is_accept = !!(rpath->frp_mitf_flags & MFIB_ITF_FLAG_ACCEPT); |
| 1077 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1078 | if (mfib_itf_update(mfib_itf, |
| 1079 | path_index, |
| 1080 | rpath->frp_mitf_flags)) |
| 1081 | { |
| 1082 | /* |
| 1083 | * no more interface flags on this path, remove |
| 1084 | * from the data-plane set |
| 1085 | */ |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1086 | if (was_accept) |
| 1087 | { |
| 1088 | mfib_itf_mac_del(mfib_itf, pfx); |
| 1089 | |
| 1090 | } |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1091 | mfib_entry_itf_remove(msrc, rpath->frp_sw_if_index); |
| 1092 | } |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1093 | else |
| 1094 | { |
| 1095 | /* |
| 1096 | * is there a change to the ACCEPT flag that |
| 1097 | * requires us to update hte driver with the |
| 1098 | * MAC |
| 1099 | */ |
| 1100 | if (is_accept != was_accept) |
| 1101 | { |
| 1102 | if (is_accept) |
| 1103 | { |
| 1104 | mfib_itf_mac_add(mfib_itf, pfx); |
| 1105 | } |
| 1106 | else if (was_accept) |
| 1107 | { |
| 1108 | mfib_itf_mac_del(mfib_itf, pfx); |
| 1109 | } |
| 1110 | } |
| 1111 | } |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 1112 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1113 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1114 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1115 | } |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1116 | vec_free(path_indices); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1117 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1118 | mfib_entry_recalculate_forwarding(mfib_entry, current_best); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | /* |
| 1122 | * mfib_entry_path_remove |
| 1123 | * |
| 1124 | * remove a path from the entry. |
| 1125 | * return the mfib_entry's index if it is still present, INVALID otherwise. |
| 1126 | */ |
| 1127 | int |
| 1128 | mfib_entry_path_remove (fib_node_index_t mfib_entry_index, |
| 1129 | mfib_source_t source, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1130 | const fib_route_path_t *rpaths) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1131 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1132 | fib_node_index_t path_index, *path_indices; |
| 1133 | const fib_route_path_t *rpath; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1134 | mfib_source_t current_best; |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1135 | const mfib_prefix_t *pfx; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1136 | mfib_entry_t *mfib_entry; |
| 1137 | mfib_entry_src_t *msrc; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1138 | u32 ii; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1139 | |
| 1140 | mfib_entry = mfib_entry_get(mfib_entry_index); |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1141 | pfx = mfib_entry_get_prefix(mfib_entry_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1142 | ASSERT(NULL != mfib_entry); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1143 | current_best = mfib_entry_get_best_source(mfib_entry); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1144 | msrc = mfib_entry_src_find(mfib_entry, source, NULL); |
| 1145 | |
| 1146 | if (NULL == msrc) |
| 1147 | { |
| 1148 | /* |
| 1149 | * there are no paths left for this source |
| 1150 | */ |
| 1151 | return (mfib_entry_ok_for_delete(mfib_entry)); |
| 1152 | } |
| 1153 | |
| 1154 | /* |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1155 | * remove the paths from the path-list. If it's not there we'll get |
| 1156 | * back an empty vector |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1157 | */ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1158 | path_indices = mfib_entry_src_paths_remove(msrc, rpaths); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1159 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1160 | vec_foreach_index(ii, path_indices) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1161 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1162 | path_index = path_indices[ii]; |
| 1163 | rpath = &rpaths[ii]; |
| 1164 | |
| 1165 | if (FIB_NODE_INDEX_INVALID == path_index) |
| 1166 | continue; |
| 1167 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1168 | /* |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1169 | * don't need the extension, nor the interface anymore |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1170 | */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1171 | mfib_path_ext_remove(msrc, path_index); |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1172 | if (mfib_entry_path_itf_based(rpath)) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1173 | { |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1174 | u8 was_accept, is_accept; |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 1175 | mfib_itf_t *mfib_itf; |
| 1176 | |
| 1177 | mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1178 | rpath->frp_sw_if_index); |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1179 | was_accept = !!(MFIB_ITF_FLAG_ACCEPT & mfib_itf->mfi_flags); |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 1180 | |
| 1181 | if (mfib_itf_update(mfib_itf, |
| 1182 | path_index, |
| 1183 | MFIB_ITF_FLAG_NONE)) |
| 1184 | { |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1185 | if (was_accept) |
| 1186 | { |
| 1187 | mfib_itf_mac_del(mfib_itf, pfx); |
| 1188 | } |
| 1189 | |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 1190 | /* |
| 1191 | * no more interface flags on this path, remove |
| 1192 | * from the data-plane set |
| 1193 | */ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1194 | mfib_entry_itf_remove(msrc, rpath->frp_sw_if_index); |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 1195 | } |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 1196 | else |
| 1197 | { |
| 1198 | is_accept = !!(MFIB_ITF_FLAG_ACCEPT & mfib_itf->mfi_flags); |
| 1199 | |
| 1200 | if (was_accept && !is_accept) |
| 1201 | { |
| 1202 | mfib_itf_mac_del(mfib_itf, pfx); |
| 1203 | } |
| 1204 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1205 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1206 | } |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1207 | vec_free(path_indices); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1208 | |
BenoƮt Ganne | 95eb01f | 2020-04-16 12:38:48 +0200 | [diff] [blame] | 1209 | if (mfib_entry_src_ok_for_delete(msrc)) |
| 1210 | { |
| 1211 | /* |
| 1212 | * this source has no interfaces and no flags. |
| 1213 | * it has nothing left to give - remove it |
| 1214 | */ |
| 1215 | mfib_entry_src_remove(mfib_entry, source); |
| 1216 | } |
| 1217 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1218 | mfib_entry_recalculate_forwarding(mfib_entry, current_best); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1219 | |
| 1220 | return (mfib_entry_ok_for_delete(mfib_entry)); |
| 1221 | } |
| 1222 | |
| 1223 | /** |
| 1224 | * mfib_entry_delete |
| 1225 | * |
| 1226 | * The source is withdrawing all the paths it provided |
| 1227 | */ |
| 1228 | int |
| 1229 | mfib_entry_delete (fib_node_index_t mfib_entry_index, |
| 1230 | mfib_source_t source) |
| 1231 | { |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1232 | mfib_source_t current_best; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1233 | mfib_entry_t *mfib_entry; |
| 1234 | |
| 1235 | mfib_entry = mfib_entry_get(mfib_entry_index); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1236 | current_best = mfib_entry_get_best_source(mfib_entry); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1237 | mfib_entry_src_remove(mfib_entry, source); |
| 1238 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1239 | mfib_entry_recalculate_forwarding(mfib_entry, current_best); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1240 | |
| 1241 | return (mfib_entry_ok_for_delete(mfib_entry)); |
| 1242 | } |
| 1243 | |
| 1244 | static int |
| 1245 | fib_ip4_address_compare (ip4_address_t * a1, |
| 1246 | ip4_address_t * a2) |
| 1247 | { |
| 1248 | /* |
| 1249 | * IP addresses are unsiged ints. the return value here needs to be signed |
| 1250 | * a simple subtraction won't cut it. |
| 1251 | * If the addresses are the same, the sort order is undefiend, so phoey. |
| 1252 | */ |
| 1253 | return ((clib_net_to_host_u32(a1->data_u32) > |
| 1254 | clib_net_to_host_u32(a2->data_u32) ) ? |
| 1255 | 1 : -1); |
| 1256 | } |
| 1257 | |
| 1258 | static int |
| 1259 | fib_ip6_address_compare (ip6_address_t * a1, |
| 1260 | ip6_address_t * a2) |
| 1261 | { |
| 1262 | int i; |
| 1263 | for (i = 0; i < ARRAY_LEN (a1->as_u16); i++) |
| 1264 | { |
| 1265 | int cmp = (clib_net_to_host_u16 (a1->as_u16[i]) - |
| 1266 | clib_net_to_host_u16 (a2->as_u16[i])); |
| 1267 | if (cmp != 0) |
| 1268 | return cmp; |
| 1269 | } |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
| 1273 | static int |
| 1274 | mfib_entry_cmp (fib_node_index_t mfib_entry_index1, |
| 1275 | fib_node_index_t mfib_entry_index2) |
| 1276 | { |
| 1277 | mfib_entry_t *mfib_entry1, *mfib_entry2; |
| 1278 | int cmp = 0; |
| 1279 | |
| 1280 | mfib_entry1 = mfib_entry_get(mfib_entry_index1); |
| 1281 | mfib_entry2 = mfib_entry_get(mfib_entry_index2); |
| 1282 | |
| 1283 | switch (mfib_entry1->mfe_prefix.fp_proto) |
| 1284 | { |
| 1285 | case FIB_PROTOCOL_IP4: |
| 1286 | cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip4, |
| 1287 | &mfib_entry2->mfe_prefix.fp_grp_addr.ip4); |
| 1288 | |
| 1289 | if (0 == cmp) |
| 1290 | { |
| 1291 | cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip4, |
| 1292 | &mfib_entry2->mfe_prefix.fp_src_addr.ip4); |
| 1293 | } |
| 1294 | break; |
| 1295 | case FIB_PROTOCOL_IP6: |
| 1296 | cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip6, |
| 1297 | &mfib_entry2->mfe_prefix.fp_grp_addr.ip6); |
| 1298 | |
| 1299 | if (0 == cmp) |
| 1300 | { |
| 1301 | cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip6, |
| 1302 | &mfib_entry2->mfe_prefix.fp_src_addr.ip6); |
| 1303 | } |
| 1304 | break; |
| 1305 | case FIB_PROTOCOL_MPLS: |
| 1306 | ASSERT(0); |
| 1307 | cmp = 0; |
| 1308 | break; |
| 1309 | } |
| 1310 | |
| 1311 | if (0 == cmp) { |
| 1312 | cmp = (mfib_entry1->mfe_prefix.fp_len - mfib_entry2->mfe_prefix.fp_len); |
| 1313 | } |
| 1314 | return (cmp); |
| 1315 | } |
| 1316 | |
| 1317 | int |
| 1318 | mfib_entry_cmp_for_sort (void *i1, void *i2) |
| 1319 | { |
| 1320 | fib_node_index_t *mfib_entry_index1 = i1, *mfib_entry_index2 = i2; |
| 1321 | |
| 1322 | return (mfib_entry_cmp(*mfib_entry_index1, |
| 1323 | *mfib_entry_index2)); |
| 1324 | } |
| 1325 | |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 1326 | static void |
| 1327 | mfib_entry_last_lock_gone (fib_node_t *node) |
| 1328 | { |
| 1329 | mfib_entry_t *mfib_entry; |
| 1330 | mfib_entry_src_t *msrc; |
| 1331 | |
| 1332 | mfib_entry = mfib_entry_from_fib_node(node); |
| 1333 | |
| 1334 | dpo_reset(&mfib_entry->mfe_rep); |
| 1335 | |
| 1336 | MFIB_ENTRY_DBG(mfib_entry, "last-lock"); |
| 1337 | |
| 1338 | vec_foreach(msrc, mfib_entry->mfe_srcs) |
| 1339 | { |
| 1340 | mfib_entry_src_flush(msrc); |
| 1341 | } |
| 1342 | |
| 1343 | vec_free(mfib_entry->mfe_srcs); |
| 1344 | |
| 1345 | fib_node_deinit(&mfib_entry->mfe_node); |
| 1346 | pool_put(mfib_entry_pool, mfib_entry); |
| 1347 | } |
| 1348 | |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 1349 | u32 |
| 1350 | mfib_entry_get_stats_index (fib_node_index_t fib_entry_index) |
| 1351 | { |
| 1352 | mfib_entry_t *mfib_entry; |
| 1353 | |
| 1354 | mfib_entry = mfib_entry_get(fib_entry_index); |
| 1355 | |
| 1356 | return (mfib_entry->mfe_rep.dpoi_index); |
| 1357 | } |
| 1358 | |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 1359 | /* |
| 1360 | * mfib_entry_back_walk_notify |
| 1361 | * |
| 1362 | * A back walk has reach this entry. |
| 1363 | */ |
| 1364 | static fib_node_back_walk_rc_t |
| 1365 | mfib_entry_back_walk_notify (fib_node_t *node, |
| 1366 | fib_node_back_walk_ctx_t *ctx) |
| 1367 | { |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1368 | mfib_entry_t *mfib_entry; |
| 1369 | |
| 1370 | mfib_entry = mfib_entry_from_fib_node(node); |
| 1371 | mfib_entry_recalculate_forwarding(mfib_entry, |
| 1372 | mfib_entry_get_best_source(mfib_entry)); |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 1373 | |
| 1374 | return (FIB_NODE_BACK_WALK_CONTINUE); |
| 1375 | } |
| 1376 | |
| 1377 | static void |
| 1378 | mfib_entry_show_memory (void) |
| 1379 | { |
| 1380 | fib_show_memory_usage("multicast-Entry", |
| 1381 | pool_elts(mfib_entry_pool), |
| 1382 | pool_len(mfib_entry_pool), |
| 1383 | sizeof(mfib_entry_t)); |
| 1384 | } |
| 1385 | |
| 1386 | /* |
| 1387 | * The MFIB entry's graph node virtual function table |
| 1388 | */ |
| 1389 | static const fib_node_vft_t mfib_entry_vft = { |
| 1390 | .fnv_get = mfib_entry_get_node, |
| 1391 | .fnv_last_lock = mfib_entry_last_lock_gone, |
| 1392 | .fnv_back_walk = mfib_entry_back_walk_notify, |
| 1393 | .fnv_mem_show = mfib_entry_show_memory, |
| 1394 | }; |
| 1395 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1396 | void |
| 1397 | mfib_entry_lock (fib_node_index_t mfib_entry_index) |
| 1398 | { |
| 1399 | mfib_entry_t *mfib_entry; |
| 1400 | |
| 1401 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1402 | |
| 1403 | fib_node_lock(&mfib_entry->mfe_node); |
| 1404 | } |
| 1405 | |
| 1406 | void |
| 1407 | mfib_entry_unlock (fib_node_index_t mfib_entry_index) |
| 1408 | { |
| 1409 | mfib_entry_t *mfib_entry; |
| 1410 | |
| 1411 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1412 | |
| 1413 | fib_node_unlock(&mfib_entry->mfe_node); |
| 1414 | } |
| 1415 | |
| 1416 | static void |
| 1417 | mfib_entry_dpo_lock (dpo_id_t *dpo) |
| 1418 | { |
| 1419 | } |
| 1420 | static void |
| 1421 | mfib_entry_dpo_unlock (dpo_id_t *dpo) |
| 1422 | { |
| 1423 | } |
| 1424 | |
| 1425 | const static dpo_vft_t mfib_entry_dpo_vft = { |
| 1426 | .dv_lock = mfib_entry_dpo_lock, |
| 1427 | .dv_unlock = mfib_entry_dpo_unlock, |
| 1428 | .dv_format = format_mfib_entry_dpo, |
| 1429 | .dv_mem_show = mfib_entry_show_memory, |
| 1430 | }; |
| 1431 | |
| 1432 | const static char* const mfib_entry_ip4_nodes[] = |
| 1433 | { |
| 1434 | "ip4-mfib-forward-rpf", |
| 1435 | NULL, |
| 1436 | }; |
| 1437 | const static char* const mfib_entry_ip6_nodes[] = |
| 1438 | { |
| 1439 | "ip6-mfib-forward-rpf", |
| 1440 | NULL, |
| 1441 | }; |
| 1442 | |
| 1443 | const static char* const * const mfib_entry_nodes[DPO_PROTO_NUM] = |
| 1444 | { |
| 1445 | [DPO_PROTO_IP4] = mfib_entry_ip4_nodes, |
| 1446 | [DPO_PROTO_IP6] = mfib_entry_ip6_nodes, |
| 1447 | }; |
| 1448 | |
| 1449 | void |
| 1450 | mfib_entry_module_init (void) |
| 1451 | { |
| 1452 | fib_node_register_type (FIB_NODE_TYPE_MFIB_ENTRY, &mfib_entry_vft); |
| 1453 | dpo_register(DPO_MFIB_ENTRY, &mfib_entry_dpo_vft, mfib_entry_nodes); |
Neale Ranns | 710071b | 2018-09-24 12:36:26 +0000 | [diff] [blame] | 1454 | mfib_entry_logger = vlib_log_register_class("mfib", "entry"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1457 | fib_route_path_t* |
| 1458 | mfib_entry_encode (fib_node_index_t mfib_entry_index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1459 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1460 | fib_path_encode_ctx_t ctx = { |
| 1461 | .rpaths = NULL, |
| 1462 | }; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1463 | mfib_entry_t *mfib_entry; |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1464 | fib_route_path_t *rpath; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1465 | mfib_entry_src_t *bsrc; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1466 | |
| 1467 | mfib_entry = mfib_entry_get(mfib_entry_index); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1468 | bsrc = mfib_entry_get_best_src(mfib_entry); |
| 1469 | |
| 1470 | if (FIB_NODE_INDEX_INVALID != bsrc->mfes_pl) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1471 | { |
Neale Ranns | 775f73c | 2018-12-20 03:01:49 -0800 | [diff] [blame] | 1472 | fib_path_list_walk_w_ext(bsrc->mfes_pl, |
| 1473 | NULL, |
| 1474 | fib_path_encode, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1475 | &ctx); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1476 | } |
Neale Ranns | 7c03ed4 | 2018-12-27 03:21:28 -0800 | [diff] [blame] | 1477 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1478 | vec_foreach(rpath, ctx.rpaths) |
Neale Ranns | 7c03ed4 | 2018-12-27 03:21:28 -0800 | [diff] [blame] | 1479 | { |
| 1480 | mfib_itf_t *mfib_itf; |
| 1481 | |
| 1482 | mfib_itf = mfib_entry_itf_find(bsrc->mfes_itfs, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1483 | rpath->frp_sw_if_index); |
Neale Ranns | 7c03ed4 | 2018-12-27 03:21:28 -0800 | [diff] [blame] | 1484 | if (mfib_itf) |
| 1485 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1486 | rpath->frp_mitf_flags = mfib_itf->mfi_flags; |
Neale Ranns | 7c03ed4 | 2018-12-27 03:21:28 -0800 | [diff] [blame] | 1487 | } |
| 1488 | } |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1489 | |
| 1490 | return (ctx.rpaths); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1493 | const mfib_prefix_t * |
| 1494 | mfib_entry_get_prefix (fib_node_index_t mfib_entry_index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1495 | { |
| 1496 | mfib_entry_t *mfib_entry; |
| 1497 | |
| 1498 | mfib_entry = mfib_entry_get(mfib_entry_index); |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1499 | |
| 1500 | return (&mfib_entry->mfe_prefix); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
| 1503 | u32 |
| 1504 | mfib_entry_get_fib_index (fib_node_index_t mfib_entry_index) |
| 1505 | { |
| 1506 | mfib_entry_t *mfib_entry; |
| 1507 | |
| 1508 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1509 | |
| 1510 | return (mfib_entry->mfe_fib_index); |
| 1511 | } |
| 1512 | |
Neale Ranns | ff23389 | 2017-12-12 00:21:19 -0800 | [diff] [blame] | 1513 | const dpo_id_t* |
| 1514 | mfib_entry_contribute_ip_forwarding (fib_node_index_t mfib_entry_index) |
| 1515 | { |
| 1516 | mfib_entry_t *mfib_entry; |
| 1517 | |
| 1518 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1519 | |
| 1520 | return (&mfib_entry->mfe_rep); |
| 1521 | } |
| 1522 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1523 | void |
| 1524 | mfib_entry_contribute_forwarding (fib_node_index_t mfib_entry_index, |
| 1525 | fib_forward_chain_type_t type, |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1526 | mfib_entry_fwd_flags_t flags, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1527 | dpo_id_t *dpo) |
| 1528 | { |
| 1529 | /* |
| 1530 | * An IP mFIB entry can only provide a forwarding chain that |
| 1531 | * is the same IP proto as the prefix. |
| 1532 | * No use-cases (i know of) for other combinations. |
| 1533 | */ |
| 1534 | mfib_entry_t *mfib_entry; |
| 1535 | dpo_proto_t dp; |
| 1536 | |
| 1537 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1538 | |
| 1539 | dp = fib_proto_to_dpo(mfib_entry->mfe_prefix.fp_proto); |
| 1540 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1541 | if (type == mfib_forw_chain_type_from_dpo_proto(dp)) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1542 | { |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1543 | replicate_t * rep; |
| 1544 | |
| 1545 | rep = replicate_get(mfib_entry->mfe_rep.dpoi_index); |
| 1546 | |
| 1547 | if ((rep->rep_flags & REPLICATE_FLAGS_HAS_LOCAL) && |
| 1548 | (flags & MFIB_ENTRY_FWD_FLAG_NO_LOCAL)) |
| 1549 | { |
| 1550 | /* |
| 1551 | * caller does not want the local paths that the entry has |
| 1552 | */ |
BenoƮt Ganne | 95eb01f | 2020-04-16 12:38:48 +0200 | [diff] [blame] | 1553 | dpo_proto_t rep_proto = rep->rep_proto; |
| 1554 | dpo_set(dpo, DPO_REPLICATE, rep_proto, |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1555 | replicate_dup(REPLICATE_FLAGS_NONE, |
| 1556 | mfib_entry->mfe_rep.dpoi_index)); |
| 1557 | } |
| 1558 | else |
| 1559 | { |
| 1560 | dpo_copy(dpo, &mfib_entry->mfe_rep); |
| 1561 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1562 | } |
| 1563 | else |
| 1564 | { |
| 1565 | dpo_copy(dpo, drop_dpo_get(dp)); |
| 1566 | } |
| 1567 | } |
| 1568 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 1569 | /* |
| 1570 | * fib_entry_cover_changed |
| 1571 | * |
| 1572 | * this entry is tracking its cover and that cover has changed. |
| 1573 | */ |
| 1574 | void |
| 1575 | mfib_entry_cover_changed (fib_node_index_t mfib_entry_index) |
| 1576 | { |
| 1577 | mfib_entry_t *mfib_entry; |
| 1578 | mfib_entry_src_t *msrc; |
| 1579 | mfib_src_res_t res; |
| 1580 | |
| 1581 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1582 | msrc = mfib_entry_get_best_src(mfib_entry); |
| 1583 | |
| 1584 | res = mfib_entry_src_cover_change(mfib_entry, msrc); |
| 1585 | |
| 1586 | if (MFIB_SRC_REEVALUATE == res) |
| 1587 | { |
| 1588 | mfib_entry_recalculate_forwarding(mfib_entry, msrc->mfes_src); |
| 1589 | } |
| 1590 | MFIB_ENTRY_DBG(mfib_entry, "cover-changed"); |
| 1591 | } |
| 1592 | |
| 1593 | /* |
| 1594 | * mfib_entry_cover_updated |
| 1595 | * |
| 1596 | * this entry is tracking its cover and that cover has been updated |
| 1597 | * (i.e. its forwarding information has changed). |
| 1598 | */ |
| 1599 | void |
| 1600 | mfib_entry_cover_updated (fib_node_index_t mfib_entry_index) |
| 1601 | { |
| 1602 | mfib_entry_t *mfib_entry; |
| 1603 | mfib_entry_src_t *msrc; |
| 1604 | mfib_src_res_t res; |
| 1605 | |
| 1606 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1607 | msrc = mfib_entry_get_best_src(mfib_entry); |
| 1608 | |
| 1609 | res = mfib_entry_src_cover_update(mfib_entry, msrc); |
| 1610 | |
| 1611 | if (MFIB_SRC_REEVALUATE == res) |
| 1612 | { |
| 1613 | mfib_entry_recalculate_forwarding(mfib_entry, msrc->mfes_src); |
| 1614 | } |
| 1615 | MFIB_ENTRY_DBG(mfib_entry, "cover-updated"); |
| 1616 | } |
| 1617 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1618 | u32 |
| 1619 | mfib_entry_pool_size (void) |
| 1620 | { |
| 1621 | return (pool_elts(mfib_entry_pool)); |
| 1622 | } |
| 1623 | |
| 1624 | static clib_error_t * |
| 1625 | show_mfib_entry_command (vlib_main_t * vm, |
| 1626 | unformat_input_t * input, |
| 1627 | vlib_cli_command_t * cmd) |
| 1628 | { |
| 1629 | fib_node_index_t fei; |
| 1630 | |
| 1631 | if (unformat (input, "%d", &fei)) |
| 1632 | { |
| 1633 | /* |
| 1634 | * show one in detail |
| 1635 | */ |
| 1636 | if (!pool_is_free_index(mfib_entry_pool, fei)) |
| 1637 | { |
| 1638 | vlib_cli_output (vm, "%d@%U", |
| 1639 | fei, |
| 1640 | format_mfib_entry, fei, |
| 1641 | MFIB_ENTRY_FORMAT_DETAIL2); |
| 1642 | } |
| 1643 | else |
| 1644 | { |
| 1645 | vlib_cli_output (vm, "entry %d invalid", fei); |
| 1646 | } |
| 1647 | } |
| 1648 | else |
| 1649 | { |
| 1650 | /* |
| 1651 | * show all |
| 1652 | */ |
| 1653 | vlib_cli_output (vm, "FIB Entries:"); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1654 | pool_foreach_index (fei, mfib_entry_pool) |
| 1655 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1656 | vlib_cli_output (vm, "%d@%U", |
| 1657 | fei, |
| 1658 | format_mfib_entry, fei, |
| 1659 | MFIB_ENTRY_FORMAT_BRIEF); |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 1660 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | return (NULL); |
| 1664 | } |
| 1665 | |
Neale Ranns | c756c1c | 2017-02-08 09:11:57 -0800 | [diff] [blame] | 1666 | /*? |
Nathan Skrzypczak | da33105 | 2021-09-29 15:28:26 +0200 | [diff] [blame] | 1667 | * This command displays an entry, or all entries, in the mfib tables indexed |
| 1668 | * by their unique numerical identifier. |
Neale Ranns | c756c1c | 2017-02-08 09:11:57 -0800 | [diff] [blame] | 1669 | ?*/ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1670 | VLIB_CLI_COMMAND (show_mfib_entry, static) = { |
| 1671 | .path = "show mfib entry", |
| 1672 | .function = show_mfib_entry_command, |
| 1673 | .short_help = "show mfib entry", |
| 1674 | }; |