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> |
| 19 | #include <vnet/fib/fib_path_list.h> |
| 20 | |
| 21 | #include <vnet/dpo/drop_dpo.h> |
| 22 | #include <vnet/dpo/replicate_dpo.h> |
| 23 | |
| 24 | /** |
Neale Ranns | 710071b | 2018-09-24 12:36:26 +0000 | [diff] [blame] | 25 | * the logger |
| 26 | */ |
| 27 | vlib_log_class_t mfib_entry_logger; |
| 28 | |
| 29 | /** |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 30 | * Debug macro |
| 31 | */ |
Neale Ranns | 710071b | 2018-09-24 12:36:26 +0000 | [diff] [blame] | 32 | #define MFIB_ENTRY_DBG(_e, _fmt, _args...) \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 33 | { \ |
Neale Ranns | 710071b | 2018-09-24 12:36:26 +0000 | [diff] [blame] | 34 | vlib_log_debug(mfib_entry_logger, \ |
| 35 | "e:[%d:%U]: " _fmt, \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 36 | mfib_entry_get_index(_e), \ |
Neale Ranns | 710071b | 2018-09-24 12:36:26 +0000 | [diff] [blame] | 37 | format_mfib_prefix, \ |
| 38 | &_e->mfe_prefix, \ |
| 39 | ##_args); \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 40 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 41 | |
| 42 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 43 | * MFIB extensions to each path |
| 44 | */ |
| 45 | typedef struct mfib_path_ext_t_ |
| 46 | { |
| 47 | mfib_itf_flags_t mfpe_flags; |
| 48 | fib_node_index_t mfpe_path; |
| 49 | } mfib_path_ext_t; |
| 50 | |
| 51 | /** |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 52 | * The source of an MFIB entry |
| 53 | */ |
| 54 | typedef struct mfib_entry_src_t_ |
| 55 | { |
| 56 | /** |
| 57 | * Which source this is |
| 58 | */ |
| 59 | mfib_source_t mfes_src; |
| 60 | |
| 61 | /** |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 62 | * Route flags |
| 63 | */ |
| 64 | mfib_entry_flags_t mfes_flags; |
| 65 | |
| 66 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 67 | * The path-list of forwarding interfaces |
| 68 | */ |
| 69 | fib_node_index_t mfes_pl; |
| 70 | |
| 71 | /** |
| 72 | * RPF-ID |
| 73 | */ |
| 74 | fib_rpf_id_t mfes_rpf_id; |
| 75 | |
| 76 | /** |
| 77 | * Hash table of path extensions |
| 78 | */ |
| 79 | mfib_path_ext_t *mfes_exts; |
| 80 | |
| 81 | /** |
| 82 | * The hash table of all interfaces. |
| 83 | * This is forwarding time information derived from the paths |
| 84 | * and their extensions. |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 85 | */ |
| 86 | mfib_itf_t *mfes_itfs; |
| 87 | } mfib_entry_src_t; |
| 88 | |
| 89 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 90 | * Pool of path extensions |
| 91 | */ |
| 92 | static mfib_path_ext_t *mfib_path_ext_pool; |
| 93 | |
| 94 | /** |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 95 | * String names for each source |
| 96 | */ |
| 97 | static const char *mfib_source_names[] = MFIB_SOURCE_NAMES; |
| 98 | |
| 99 | /* |
| 100 | * Pool for all fib_entries |
| 101 | */ |
| 102 | mfib_entry_t *mfib_entry_pool; |
| 103 | |
| 104 | static fib_node_t * |
| 105 | mfib_entry_get_node (fib_node_index_t index) |
| 106 | { |
| 107 | return ((fib_node_t*)mfib_entry_get(index)); |
| 108 | } |
| 109 | |
| 110 | static fib_protocol_t |
| 111 | mfib_entry_get_proto (const mfib_entry_t * mfib_entry) |
| 112 | { |
| 113 | return (mfib_entry->mfe_prefix.fp_proto); |
| 114 | } |
| 115 | |
| 116 | fib_forward_chain_type_t |
| 117 | mfib_entry_get_default_chain_type (const mfib_entry_t *mfib_entry) |
| 118 | { |
| 119 | switch (mfib_entry->mfe_prefix.fp_proto) |
| 120 | { |
| 121 | case FIB_PROTOCOL_IP4: |
| 122 | return (FIB_FORW_CHAIN_TYPE_MCAST_IP4); |
| 123 | case FIB_PROTOCOL_IP6: |
| 124 | return (FIB_FORW_CHAIN_TYPE_MCAST_IP6); |
| 125 | case FIB_PROTOCOL_MPLS: |
| 126 | ASSERT(0); |
| 127 | break; |
| 128 | } |
| 129 | return (FIB_FORW_CHAIN_TYPE_MCAST_IP4); |
| 130 | } |
| 131 | |
| 132 | static u8 * |
| 133 | format_mfib_entry_dpo (u8 * s, va_list * args) |
| 134 | { |
| 135 | index_t fei = va_arg(*args, index_t); |
| 136 | CLIB_UNUSED(u32 indent) = va_arg(*args, u32); |
| 137 | |
| 138 | return (format(s, "%U", |
| 139 | format_mfib_entry, fei, |
| 140 | MFIB_ENTRY_FORMAT_BRIEF)); |
| 141 | } |
| 142 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 143 | static inline mfib_path_ext_t * |
| 144 | mfib_entry_path_ext_get (index_t mi) |
| 145 | { |
| 146 | return (pool_elt_at_index(mfib_path_ext_pool, mi)); |
| 147 | } |
| 148 | |
| 149 | static u8 * |
| 150 | format_mfib_entry_path_ext (u8 * s, va_list * args) |
| 151 | { |
| 152 | mfib_path_ext_t *path_ext; |
| 153 | index_t mpi = va_arg(*args, index_t); |
| 154 | |
| 155 | path_ext = mfib_entry_path_ext_get(mpi); |
| 156 | return (format(s, "path:%d flags:%U", |
| 157 | path_ext->mfpe_path, |
| 158 | format_mfib_itf_flags, path_ext->mfpe_flags)); |
| 159 | } |
| 160 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 161 | u8 * |
| 162 | format_mfib_entry (u8 * s, va_list * args) |
| 163 | { |
| 164 | fib_node_index_t fei, mfi; |
| 165 | mfib_entry_t *mfib_entry; |
| 166 | mfib_entry_src_t *msrc; |
| 167 | u32 sw_if_index; |
| 168 | int level; |
| 169 | |
| 170 | fei = va_arg (*args, fib_node_index_t); |
| 171 | level = va_arg (*args, int); |
| 172 | mfib_entry = mfib_entry_get(fei); |
| 173 | |
| 174 | s = format (s, "%U", format_mfib_prefix, &mfib_entry->mfe_prefix); |
| 175 | s = format (s, ": %U", format_mfib_entry_flags, mfib_entry->mfe_flags); |
| 176 | |
| 177 | if (level >= MFIB_ENTRY_FORMAT_DETAIL) |
| 178 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 179 | fib_node_index_t path_index, mpi; |
| 180 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 181 | s = format (s, "\n"); |
| 182 | s = format (s, " fib:%d", mfib_entry->mfe_fib_index); |
| 183 | s = format (s, " index:%d", mfib_entry_get_index(mfib_entry)); |
| 184 | s = format (s, " locks:%d\n", mfib_entry->mfe_node.fn_locks); |
| 185 | vec_foreach(msrc, mfib_entry->mfe_srcs) |
| 186 | { |
| 187 | s = format (s, " src:%s", mfib_source_names[msrc->mfes_src]); |
| 188 | s = format (s, ": %U\n", format_mfib_entry_flags, msrc->mfes_flags); |
| 189 | if (FIB_NODE_INDEX_INVALID != msrc->mfes_pl) |
| 190 | { |
| 191 | s = fib_path_list_format(msrc->mfes_pl, s); |
| 192 | } |
Neale Ranns | 5d85f2d | 2017-05-02 10:17:17 -0700 | [diff] [blame] | 193 | s = format (s, " Extensions:\n"); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 194 | hash_foreach(path_index, mpi, msrc->mfes_exts, |
| 195 | ({ |
| 196 | s = format(s, " %U\n", format_mfib_entry_path_ext, mpi); |
| 197 | })); |
Neale Ranns | 5d85f2d | 2017-05-02 10:17:17 -0700 | [diff] [blame] | 198 | s = format (s, " Interface-Forwarding:\n"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 199 | hash_foreach(sw_if_index, mfi, msrc->mfes_itfs, |
| 200 | ({ |
| 201 | s = format(s, " %U\n", format_mfib_itf, mfi); |
| 202 | })); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | s = format(s, "\n Interfaces:"); |
| 207 | hash_foreach(sw_if_index, mfi, mfib_entry->mfe_itfs, |
| 208 | ({ |
| 209 | s = format(s, "\n %U", format_mfib_itf, mfi); |
| 210 | })); |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 211 | if (MFIB_RPF_ID_NONE != mfib_entry->mfe_rpf_id) |
| 212 | { |
| 213 | s = format(s, "\n RPF-ID:%d", mfib_entry->mfe_rpf_id); |
| 214 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 215 | s = format(s, "\n %U-chain\n %U", |
| 216 | format_fib_forw_chain_type, |
| 217 | mfib_entry_get_default_chain_type(mfib_entry), |
| 218 | format_dpo_id, |
| 219 | &mfib_entry->mfe_rep, |
| 220 | 2); |
| 221 | s = format(s, "\n"); |
| 222 | |
| 223 | if (level >= MFIB_ENTRY_FORMAT_DETAIL2) |
| 224 | { |
| 225 | s = format(s, "\nchildren:"); |
| 226 | s = fib_node_children_format(mfib_entry->mfe_node.fn_children, s); |
| 227 | } |
| 228 | |
| 229 | return (s); |
| 230 | } |
| 231 | |
| 232 | static mfib_entry_t* |
| 233 | mfib_entry_from_fib_node (fib_node_t *node) |
| 234 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 235 | ASSERT(FIB_NODE_TYPE_MFIB_ENTRY == node->fn_type); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 236 | return ((mfib_entry_t*)node); |
| 237 | } |
| 238 | |
| 239 | static int |
| 240 | mfib_entry_src_cmp_for_sort (void * v1, |
| 241 | void * v2) |
| 242 | { |
| 243 | mfib_entry_src_t *esrc1 = v1, *esrc2 = v2; |
| 244 | |
| 245 | return (esrc1->mfes_src - esrc2->mfes_src); |
| 246 | } |
| 247 | |
| 248 | static void |
| 249 | mfib_entry_src_init (mfib_entry_t *mfib_entry, |
| 250 | mfib_source_t source) |
| 251 | |
| 252 | { |
| 253 | mfib_entry_src_t esrc = { |
| 254 | .mfes_pl = FIB_NODE_INDEX_INVALID, |
| 255 | .mfes_flags = MFIB_ENTRY_FLAG_NONE, |
| 256 | .mfes_src = source, |
| 257 | }; |
| 258 | |
| 259 | vec_add1(mfib_entry->mfe_srcs, esrc); |
| 260 | vec_sort_with_function(mfib_entry->mfe_srcs, |
| 261 | mfib_entry_src_cmp_for_sort); |
| 262 | } |
| 263 | |
| 264 | static mfib_entry_src_t * |
| 265 | mfib_entry_src_find (const mfib_entry_t *mfib_entry, |
| 266 | mfib_source_t source, |
| 267 | u32 *index) |
| 268 | |
| 269 | { |
| 270 | mfib_entry_src_t *esrc; |
| 271 | int ii; |
| 272 | |
| 273 | ii = 0; |
| 274 | vec_foreach(esrc, mfib_entry->mfe_srcs) |
| 275 | { |
| 276 | if (esrc->mfes_src == source) |
| 277 | { |
| 278 | if (NULL != index) |
| 279 | { |
| 280 | *index = ii; |
| 281 | } |
| 282 | return (esrc); |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | ii++; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | return (NULL); |
| 291 | } |
| 292 | |
| 293 | static mfib_entry_src_t * |
| 294 | mfib_entry_src_find_or_create (mfib_entry_t *mfib_entry, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 295 | mfib_source_t source) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 296 | { |
| 297 | mfib_entry_src_t *esrc; |
| 298 | |
| 299 | esrc = mfib_entry_src_find(mfib_entry, source, NULL); |
| 300 | |
| 301 | if (NULL == esrc) |
| 302 | { |
| 303 | mfib_entry_src_init(mfib_entry, source); |
| 304 | } |
| 305 | |
| 306 | return (mfib_entry_src_find(mfib_entry, source, NULL)); |
| 307 | } |
| 308 | |
| 309 | static mfib_entry_src_t* |
| 310 | mfib_entry_get_best_src (const mfib_entry_t *mfib_entry) |
| 311 | { |
| 312 | mfib_entry_src_t *bsrc; |
| 313 | |
| 314 | /* |
| 315 | * the enum of sources is deliberately arranged in priority order |
| 316 | */ |
| 317 | if (0 == vec_len(mfib_entry->mfe_srcs)) |
| 318 | { |
| 319 | bsrc = NULL; |
| 320 | } |
| 321 | else |
| 322 | { |
| 323 | bsrc = vec_elt_at_index(mfib_entry->mfe_srcs, 0); |
| 324 | } |
| 325 | |
| 326 | return (bsrc); |
| 327 | } |
| 328 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 329 | int |
| 330 | mfib_entry_is_sourced (fib_node_index_t mfib_entry_index, |
| 331 | mfib_source_t source) |
| 332 | { |
| 333 | mfib_entry_t *mfib_entry; |
| 334 | |
| 335 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 336 | |
| 337 | return (NULL != mfib_entry_src_find(mfib_entry, source, NULL)); |
| 338 | } |
| 339 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 340 | static void |
| 341 | mfib_entry_src_flush (mfib_entry_src_t *msrc) |
| 342 | { |
| 343 | u32 sw_if_index; |
| 344 | index_t mfii; |
| 345 | |
| 346 | hash_foreach(sw_if_index, mfii, msrc->mfes_itfs, |
| 347 | ({ |
| 348 | mfib_itf_delete(mfib_itf_get(mfii)); |
| 349 | })); |
Neale Ranns | bcc6aa4 | 2017-02-24 01:34:14 -0800 | [diff] [blame] | 350 | hash_free(msrc->mfes_itfs); |
| 351 | msrc->mfes_itfs = NULL; |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 352 | fib_path_list_unlock(msrc->mfes_pl); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | static void |
| 356 | mfib_entry_src_remove (mfib_entry_t *mfib_entry, |
| 357 | mfib_source_t source) |
| 358 | |
| 359 | { |
| 360 | mfib_entry_src_t *msrc; |
| 361 | u32 index = ~0; |
| 362 | |
| 363 | msrc = mfib_entry_src_find(mfib_entry, source, &index); |
| 364 | |
| 365 | if (NULL != msrc) |
| 366 | { |
| 367 | mfib_entry_src_flush(msrc); |
| 368 | vec_del1(mfib_entry->mfe_srcs, index); |
| 369 | } |
| 370 | } |
| 371 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 372 | u32 |
| 373 | mfib_entry_child_add (fib_node_index_t mfib_entry_index, |
| 374 | fib_node_type_t child_type, |
| 375 | fib_node_index_t child_index) |
| 376 | { |
| 377 | return (fib_node_child_add(FIB_NODE_TYPE_MFIB_ENTRY, |
| 378 | mfib_entry_index, |
| 379 | child_type, |
| 380 | child_index)); |
| 381 | }; |
| 382 | |
| 383 | void |
| 384 | mfib_entry_child_remove (fib_node_index_t mfib_entry_index, |
| 385 | u32 sibling_index) |
| 386 | { |
| 387 | fib_node_child_remove(FIB_NODE_TYPE_MFIB_ENTRY, |
| 388 | mfib_entry_index, |
| 389 | sibling_index); |
| 390 | } |
| 391 | |
| 392 | static mfib_entry_t * |
| 393 | mfib_entry_alloc (u32 fib_index, |
| 394 | const mfib_prefix_t *prefix, |
| 395 | fib_node_index_t *mfib_entry_index) |
| 396 | { |
| 397 | mfib_entry_t *mfib_entry; |
| 398 | |
Marco Varlese | 47501da | 2017-08-29 14:04:06 +0200 | [diff] [blame] | 399 | pool_get_aligned(mfib_entry_pool, mfib_entry, CLIB_CACHE_LINE_BYTES); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 400 | |
| 401 | fib_node_init(&mfib_entry->mfe_node, |
| 402 | FIB_NODE_TYPE_MFIB_ENTRY); |
| 403 | |
Neale Ranns | 5a72c1c | 2017-02-24 08:29:22 -0800 | [diff] [blame] | 404 | /* |
| 405 | * Some of the members require non-default initialisation |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 406 | * 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] | 407 | */ |
| 408 | mfib_entry->mfe_flags = 0; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 409 | mfib_entry->mfe_fib_index = fib_index; |
| 410 | mfib_entry->mfe_prefix = *prefix; |
Neale Ranns | 5a72c1c | 2017-02-24 08:29:22 -0800 | [diff] [blame] | 411 | mfib_entry->mfe_srcs = NULL; |
| 412 | mfib_entry->mfe_itfs = NULL; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 413 | mfib_entry->mfe_rpf_id = MFIB_RPF_ID_NONE; |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 414 | mfib_entry->mfe_pl = FIB_NODE_INDEX_INVALID; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 415 | |
| 416 | dpo_reset(&mfib_entry->mfe_rep); |
| 417 | |
| 418 | *mfib_entry_index = mfib_entry_get_index(mfib_entry); |
| 419 | |
| 420 | MFIB_ENTRY_DBG(mfib_entry, "alloc"); |
| 421 | |
| 422 | return (mfib_entry); |
| 423 | } |
| 424 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 425 | static inline mfib_path_ext_t * |
| 426 | mfib_entry_path_ext_find (mfib_path_ext_t *exts, |
| 427 | fib_node_index_t path_index) |
| 428 | { |
| 429 | uword *p; |
| 430 | |
| 431 | p = hash_get(exts, path_index); |
| 432 | |
| 433 | if (NULL != p) |
| 434 | { |
| 435 | return (mfib_entry_path_ext_get(p[0])); |
| 436 | } |
| 437 | |
| 438 | return (NULL); |
| 439 | } |
| 440 | |
| 441 | static mfib_path_ext_t* |
| 442 | mfib_path_ext_add (mfib_entry_src_t *msrc, |
| 443 | fib_node_index_t path_index, |
| 444 | mfib_itf_flags_t mfi_flags) |
| 445 | { |
| 446 | mfib_path_ext_t *path_ext; |
| 447 | |
| 448 | pool_get(mfib_path_ext_pool, path_ext); |
| 449 | |
| 450 | path_ext->mfpe_flags = mfi_flags; |
| 451 | path_ext->mfpe_path = path_index; |
| 452 | |
| 453 | hash_set(msrc->mfes_exts, path_index, |
| 454 | path_ext - mfib_path_ext_pool); |
| 455 | |
| 456 | return (path_ext); |
| 457 | } |
| 458 | |
| 459 | static void |
| 460 | mfib_path_ext_remove (mfib_entry_src_t *msrc, |
| 461 | fib_node_index_t path_index) |
| 462 | { |
| 463 | mfib_path_ext_t *path_ext; |
| 464 | |
| 465 | path_ext = mfib_entry_path_ext_find(msrc->mfes_exts, path_index); |
| 466 | |
| 467 | hash_unset(msrc->mfes_exts, path_index); |
| 468 | pool_put(mfib_path_ext_pool, path_ext); |
| 469 | } |
| 470 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 471 | typedef struct mfib_entry_collect_forwarding_ctx_t_ |
| 472 | { |
| 473 | load_balance_path_t * next_hops; |
| 474 | fib_forward_chain_type_t fct; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 475 | mfib_entry_src_t *msrc; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 476 | } mfib_entry_collect_forwarding_ctx_t; |
| 477 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 478 | static fib_path_list_walk_rc_t |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 479 | mfib_entry_src_collect_forwarding (fib_node_index_t pl_index, |
| 480 | fib_node_index_t path_index, |
| 481 | void *arg) |
| 482 | { |
| 483 | mfib_entry_collect_forwarding_ctx_t *ctx; |
| 484 | load_balance_path_t *nh; |
| 485 | |
| 486 | ctx = arg; |
| 487 | |
| 488 | /* |
| 489 | * if the path is not resolved, don't include it. |
| 490 | */ |
| 491 | if (!fib_path_is_resolved(path_index)) |
| 492 | { |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 493 | return (FIB_PATH_LIST_WALK_CONTINUE); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 494 | } |
| 495 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 496 | /* |
| 497 | * If the path is not forwarding to use it |
| 498 | */ |
| 499 | mfib_path_ext_t *path_ext; |
| 500 | |
| 501 | path_ext = mfib_entry_path_ext_find(ctx->msrc->mfes_exts, |
| 502 | path_index); |
| 503 | |
| 504 | if (NULL != path_ext && |
| 505 | !(path_ext->mfpe_flags & MFIB_ITF_FLAG_FORWARD)) |
| 506 | { |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 507 | return (FIB_PATH_LIST_WALK_CONTINUE); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 508 | } |
| 509 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 510 | switch (ctx->fct) |
| 511 | { |
| 512 | case FIB_FORW_CHAIN_TYPE_MCAST_IP4: |
| 513 | case FIB_FORW_CHAIN_TYPE_MCAST_IP6: |
| 514 | /* |
| 515 | * EOS traffic with no label to stack, we need the IP Adj |
| 516 | */ |
| 517 | vec_add2(ctx->next_hops, nh, 1); |
| 518 | |
| 519 | nh->path_index = path_index; |
| 520 | nh->path_weight = fib_path_get_weight(path_index); |
| 521 | fib_path_contribute_forwarding(path_index, ctx->fct, &nh->path_dpo); |
| 522 | break; |
| 523 | |
| 524 | case FIB_FORW_CHAIN_TYPE_UNICAST_IP4: |
| 525 | case FIB_FORW_CHAIN_TYPE_UNICAST_IP6: |
| 526 | case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS: |
| 527 | case FIB_FORW_CHAIN_TYPE_MPLS_EOS: |
| 528 | case FIB_FORW_CHAIN_TYPE_ETHERNET: |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 529 | case FIB_FORW_CHAIN_TYPE_NSH: |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 530 | case FIB_FORW_CHAIN_TYPE_BIER: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 531 | ASSERT(0); |
| 532 | break; |
| 533 | } |
| 534 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 535 | return (FIB_PATH_LIST_WALK_CONTINUE); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | static void |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 539 | mfib_entry_stack (mfib_entry_t *mfib_entry, |
| 540 | mfib_entry_src_t *msrc) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 541 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 542 | dpo_proto_t dp; |
| 543 | |
| 544 | dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry)); |
| 545 | |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 546 | /* |
| 547 | * unlink the enty from the previous path list. |
| 548 | */ |
| 549 | if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_pl) |
| 550 | { |
| 551 | fib_path_list_child_remove(mfib_entry->mfe_pl, |
| 552 | mfib_entry->mfe_sibling); |
| 553 | } |
| 554 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 555 | if (NULL != msrc && |
| 556 | FIB_NODE_INDEX_INVALID != msrc->mfes_pl) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 557 | { |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 558 | mfib_entry_collect_forwarding_ctx_t ctx = { |
| 559 | .next_hops = NULL, |
| 560 | .fct = mfib_entry_get_default_chain_type(mfib_entry), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 561 | .msrc = msrc, |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 562 | }; |
| 563 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 564 | fib_path_list_walk(msrc->mfes_pl, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 565 | mfib_entry_src_collect_forwarding, |
| 566 | &ctx); |
| 567 | |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 568 | if (!(MFIB_ENTRY_FLAG_EXCLUSIVE & mfib_entry->mfe_flags)) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 569 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 570 | if (NULL == ctx.next_hops) |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 571 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 572 | /* |
| 573 | * no next-hops, stack directly on the drop |
| 574 | */ |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 575 | dpo_stack(DPO_MFIB_ENTRY, dp, |
| 576 | &mfib_entry->mfe_rep, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 577 | drop_dpo_get(dp)); |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 578 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 579 | else |
| 580 | { |
| 581 | /* |
| 582 | * each path contirbutes a next-hop. form a replicate |
| 583 | * from those choices. |
| 584 | */ |
| 585 | if (!dpo_id_is_valid(&mfib_entry->mfe_rep) || |
| 586 | dpo_is_drop(&mfib_entry->mfe_rep)) |
| 587 | { |
| 588 | dpo_id_t tmp_dpo = DPO_INVALID; |
| 589 | |
| 590 | dpo_set(&tmp_dpo, |
| 591 | DPO_REPLICATE, dp, |
| 592 | replicate_create(0, dp)); |
| 593 | |
| 594 | dpo_stack(DPO_MFIB_ENTRY, dp, |
| 595 | &mfib_entry->mfe_rep, |
| 596 | &tmp_dpo); |
| 597 | |
| 598 | dpo_reset(&tmp_dpo); |
| 599 | } |
| 600 | replicate_multipath_update(&mfib_entry->mfe_rep, |
| 601 | ctx.next_hops); |
| 602 | } |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 603 | } |
| 604 | else |
| 605 | { |
| 606 | /* |
| 607 | * for exclusive routes the source provided a replicate DPO |
| 608 | * we we stashed inthe special path list with one path |
| 609 | * so we can stack directly on that. |
| 610 | */ |
| 611 | ASSERT(1 == vec_len(ctx.next_hops)); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 612 | |
| 613 | dpo_stack(DPO_MFIB_ENTRY, dp, |
| 614 | &mfib_entry->mfe_rep, |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 615 | &ctx.next_hops[0].path_dpo); |
| 616 | dpo_reset(&ctx.next_hops[0].path_dpo); |
| 617 | vec_free(ctx.next_hops); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 618 | } |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 619 | |
| 620 | /* |
| 621 | * link the entry to the path-list. |
| 622 | * The entry needs to be a child so that we receive the back-walk |
| 623 | * updates to recalculate forwarding. |
| 624 | */ |
| 625 | mfib_entry->mfe_pl = msrc->mfes_pl; |
| 626 | mfib_entry->mfe_sibling = |
| 627 | fib_path_list_child_add(mfib_entry->mfe_pl, |
| 628 | FIB_NODE_TYPE_MFIB_ENTRY, |
| 629 | mfib_entry_get_index(mfib_entry)); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 630 | } |
| 631 | else |
| 632 | { |
| 633 | dpo_stack(DPO_MFIB_ENTRY, dp, |
| 634 | &mfib_entry->mfe_rep, |
| 635 | drop_dpo_get(dp)); |
| 636 | } |
| 637 | } |
| 638 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 639 | static fib_node_index_t |
| 640 | mfib_entry_src_path_add (mfib_entry_src_t *msrc, |
| 641 | const fib_route_path_t *rpath) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 642 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 643 | fib_node_index_t path_index; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 644 | fib_route_path_t *rpaths; |
| 645 | |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 646 | ASSERT(!(MFIB_ENTRY_FLAG_EXCLUSIVE & msrc->mfes_flags)); |
| 647 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 648 | /* |
| 649 | * path-lists require a vector of paths |
| 650 | */ |
| 651 | rpaths = NULL; |
| 652 | vec_add1(rpaths, rpath[0]); |
| 653 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 654 | if (FIB_NODE_INDEX_INVALID == msrc->mfes_pl) |
| 655 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 656 | /* A non-shared path-list */ |
| 657 | msrc->mfes_pl = fib_path_list_create(FIB_PATH_LIST_FLAG_NO_URPF, |
| 658 | NULL); |
| 659 | fib_path_list_lock(msrc->mfes_pl); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 660 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 661 | |
| 662 | path_index = fib_path_list_path_add(msrc->mfes_pl, rpaths); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 663 | |
| 664 | vec_free(rpaths); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 665 | |
| 666 | return (path_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 669 | static fib_node_index_t |
| 670 | mfib_entry_src_path_remove (mfib_entry_src_t *msrc, |
| 671 | const fib_route_path_t *rpath) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 672 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 673 | fib_node_index_t path_index; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 674 | fib_route_path_t *rpaths; |
| 675 | |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 676 | ASSERT(!(MFIB_ENTRY_FLAG_EXCLUSIVE & msrc->mfes_flags)); |
| 677 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 678 | /* |
| 679 | * path-lists require a vector of paths |
| 680 | */ |
| 681 | rpaths = NULL; |
| 682 | vec_add1(rpaths, rpath[0]); |
| 683 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 684 | path_index = fib_path_list_path_remove(msrc->mfes_pl, rpaths); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 685 | |
| 686 | vec_free(rpaths); |
| 687 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 688 | return (path_index); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | static void |
| 692 | mfib_entry_recalculate_forwarding (mfib_entry_t *mfib_entry) |
| 693 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 694 | mfib_entry_src_t *bsrc; |
| 695 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 696 | /* |
| 697 | * copy the forwarding data from the bast source |
| 698 | */ |
| 699 | bsrc = mfib_entry_get_best_src(mfib_entry); |
| 700 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 701 | if (NULL != bsrc) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 702 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 703 | mfib_entry->mfe_flags = bsrc->mfes_flags; |
| 704 | mfib_entry->mfe_itfs = bsrc->mfes_itfs; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 705 | mfib_entry->mfe_rpf_id = bsrc->mfes_rpf_id; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 708 | mfib_entry_stack(mfib_entry, bsrc); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | |
| 712 | fib_node_index_t |
| 713 | mfib_entry_create (u32 fib_index, |
| 714 | mfib_source_t source, |
| 715 | const mfib_prefix_t *prefix, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 716 | fib_rpf_id_t rpf_id, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 717 | mfib_entry_flags_t entry_flags) |
| 718 | { |
| 719 | fib_node_index_t mfib_entry_index; |
| 720 | mfib_entry_t *mfib_entry; |
| 721 | mfib_entry_src_t *msrc; |
| 722 | |
| 723 | mfib_entry = mfib_entry_alloc(fib_index, prefix, |
| 724 | &mfib_entry_index); |
| 725 | msrc = mfib_entry_src_find_or_create(mfib_entry, source); |
| 726 | msrc->mfes_flags = entry_flags; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 727 | msrc->mfes_rpf_id = rpf_id; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 728 | |
| 729 | mfib_entry_recalculate_forwarding(mfib_entry); |
| 730 | |
| 731 | return (mfib_entry_index); |
| 732 | } |
| 733 | |
| 734 | static int |
| 735 | mfib_entry_ok_for_delete (mfib_entry_t *mfib_entry) |
| 736 | { |
| 737 | return (0 == vec_len(mfib_entry->mfe_srcs)); |
| 738 | } |
| 739 | |
| 740 | static int |
| 741 | mfib_entry_src_ok_for_delete (const mfib_entry_src_t *msrc) |
| 742 | { |
| 743 | return ((MFIB_ENTRY_FLAG_NONE == msrc->mfes_flags && |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 744 | 0 == fib_path_list_get_n_paths(msrc->mfes_pl))); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | int |
| 748 | mfib_entry_update (fib_node_index_t mfib_entry_index, |
| 749 | mfib_source_t source, |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 750 | mfib_entry_flags_t entry_flags, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 751 | fib_rpf_id_t rpf_id, |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 752 | index_t repi) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 753 | { |
| 754 | mfib_entry_t *mfib_entry; |
| 755 | mfib_entry_src_t *msrc; |
| 756 | |
| 757 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 758 | msrc = mfib_entry_src_find_or_create(mfib_entry, source); |
| 759 | msrc->mfes_flags = entry_flags; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 760 | msrc->mfes_rpf_id = rpf_id; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 761 | |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 762 | if (INDEX_INVALID != repi) |
| 763 | { |
| 764 | /* |
| 765 | * The source is providing its own replicate DPO. |
| 766 | * Create a sepcial path-list to manage it, that way |
| 767 | * this entry and the source are equivalent to a normal |
| 768 | * entry |
| 769 | */ |
| 770 | fib_node_index_t old_pl_index; |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 771 | dpo_proto_t dp; |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 772 | dpo_id_t dpo = DPO_INVALID; |
| 773 | |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 774 | dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry)); |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 775 | old_pl_index = msrc->mfes_pl; |
| 776 | |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 777 | dpo_set(&dpo, DPO_REPLICATE, dp, repi); |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 778 | |
| 779 | msrc->mfes_pl = |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 780 | fib_path_list_create_special(dp, |
Neale Ranns | a9374df | 2017-02-02 02:18:18 -0800 | [diff] [blame] | 781 | FIB_PATH_LIST_FLAG_EXCLUSIVE, |
| 782 | &dpo); |
| 783 | |
| 784 | dpo_reset(&dpo); |
| 785 | fib_path_list_lock(msrc->mfes_pl); |
| 786 | fib_path_list_unlock(old_pl_index); |
| 787 | } |
| 788 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 789 | if (mfib_entry_src_ok_for_delete(msrc)) |
| 790 | { |
| 791 | /* |
| 792 | * this source has no interfaces and no flags. |
| 793 | * it has nothing left to give - remove it |
| 794 | */ |
| 795 | mfib_entry_src_remove(mfib_entry, source); |
| 796 | } |
| 797 | |
| 798 | mfib_entry_recalculate_forwarding(mfib_entry); |
| 799 | |
| 800 | return (mfib_entry_ok_for_delete(mfib_entry)); |
| 801 | } |
| 802 | |
| 803 | static void |
| 804 | mfib_entry_itf_add (mfib_entry_src_t *msrc, |
| 805 | u32 sw_if_index, |
| 806 | index_t mi) |
| 807 | { |
| 808 | hash_set(msrc->mfes_itfs, sw_if_index, mi); |
| 809 | } |
| 810 | |
| 811 | static void |
| 812 | mfib_entry_itf_remove (mfib_entry_src_t *msrc, |
| 813 | u32 sw_if_index) |
| 814 | { |
| 815 | mfib_itf_t *mfi; |
| 816 | |
| 817 | mfi = mfib_entry_itf_find(msrc->mfes_itfs, sw_if_index); |
| 818 | |
| 819 | mfib_itf_delete(mfi); |
| 820 | |
| 821 | hash_unset(msrc->mfes_itfs, sw_if_index); |
| 822 | } |
| 823 | |
| 824 | void |
| 825 | mfib_entry_path_update (fib_node_index_t mfib_entry_index, |
| 826 | mfib_source_t source, |
| 827 | const fib_route_path_t *rpath, |
| 828 | mfib_itf_flags_t itf_flags) |
| 829 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 830 | fib_node_index_t path_index; |
| 831 | mfib_path_ext_t *path_ext; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 832 | mfib_entry_t *mfib_entry; |
| 833 | mfib_entry_src_t *msrc; |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 834 | mfib_itf_flags_t old; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 835 | |
| 836 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 837 | ASSERT(NULL != mfib_entry); |
| 838 | msrc = mfib_entry_src_find_or_create(mfib_entry, source); |
| 839 | |
| 840 | /* |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 841 | * add the path to the path-list. If it's a duplicate we'll get |
| 842 | * back the original path. |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 843 | */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 844 | path_index = mfib_entry_src_path_add(msrc, rpath); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 845 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 846 | /* |
| 847 | * find the path extension for that path |
| 848 | */ |
| 849 | path_ext = mfib_entry_path_ext_find(msrc->mfes_exts, path_index); |
| 850 | |
| 851 | if (NULL == path_ext) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 852 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 853 | old = MFIB_ITF_FLAG_NONE; |
| 854 | path_ext = mfib_path_ext_add(msrc, path_index, itf_flags); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 855 | } |
| 856 | else |
| 857 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 858 | old = path_ext->mfpe_flags; |
| 859 | path_ext->mfpe_flags = itf_flags; |
| 860 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 861 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 862 | /* |
| 863 | * Has the path changed its contribution to the input interface set. |
| 864 | * Which only paths with interfaces can do... |
| 865 | */ |
| 866 | if (~0 != rpath[0].frp_sw_if_index) |
| 867 | { |
| 868 | mfib_itf_t *mfib_itf; |
| 869 | |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 870 | if (old != itf_flags) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 871 | { |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 872 | /* |
| 873 | * change of flag contributions |
| 874 | */ |
| 875 | mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs, |
| 876 | rpath[0].frp_sw_if_index); |
| 877 | |
| 878 | if (NULL == mfib_itf) |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 879 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 880 | mfib_entry_itf_add(msrc, |
| 881 | rpath[0].frp_sw_if_index, |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 882 | mfib_itf_create(path_index, itf_flags)); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 883 | } |
| 884 | else |
| 885 | { |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 886 | if (mfib_itf_update(mfib_itf, |
| 887 | path_index, |
| 888 | itf_flags)) |
| 889 | { |
| 890 | /* |
| 891 | * no more interface flags on this path, remove |
| 892 | * from the data-plane set |
| 893 | */ |
| 894 | mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index); |
| 895 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 896 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 897 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | mfib_entry_recalculate_forwarding(mfib_entry); |
| 901 | } |
| 902 | |
| 903 | /* |
| 904 | * mfib_entry_path_remove |
| 905 | * |
| 906 | * remove a path from the entry. |
| 907 | * return the mfib_entry's index if it is still present, INVALID otherwise. |
| 908 | */ |
| 909 | int |
| 910 | mfib_entry_path_remove (fib_node_index_t mfib_entry_index, |
| 911 | mfib_source_t source, |
| 912 | const fib_route_path_t *rpath) |
| 913 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 914 | fib_node_index_t path_index; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 915 | mfib_entry_t *mfib_entry; |
| 916 | mfib_entry_src_t *msrc; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 917 | |
| 918 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 919 | ASSERT(NULL != mfib_entry); |
| 920 | msrc = mfib_entry_src_find(mfib_entry, source, NULL); |
| 921 | |
| 922 | if (NULL == msrc) |
| 923 | { |
| 924 | /* |
| 925 | * there are no paths left for this source |
| 926 | */ |
| 927 | return (mfib_entry_ok_for_delete(mfib_entry)); |
| 928 | } |
| 929 | |
| 930 | /* |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 931 | * remove the path from the path-list. If it's not there we'll get |
| 932 | * back invalid |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 933 | */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 934 | path_index = mfib_entry_src_path_remove(msrc, rpath); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 935 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 936 | if (FIB_NODE_INDEX_INVALID != path_index) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 937 | { |
| 938 | /* |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 939 | * don't need the extension, nor the interface anymore |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 940 | */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 941 | mfib_path_ext_remove(msrc, path_index); |
| 942 | if (~0 != rpath[0].frp_sw_if_index) |
| 943 | { |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 944 | mfib_itf_t *mfib_itf; |
| 945 | |
| 946 | mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs, |
| 947 | rpath[0].frp_sw_if_index); |
| 948 | |
| 949 | if (mfib_itf_update(mfib_itf, |
| 950 | path_index, |
| 951 | MFIB_ITF_FLAG_NONE)) |
| 952 | { |
| 953 | /* |
| 954 | * no more interface flags on this path, remove |
| 955 | * from the data-plane set |
| 956 | */ |
| 957 | mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index); |
| 958 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 959 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 962 | if (mfib_entry_src_ok_for_delete(msrc)) |
| 963 | { |
| 964 | /* |
| 965 | * this source has no interfaces and no flags. |
| 966 | * it has nothing left to give - remove it |
| 967 | */ |
| 968 | mfib_entry_src_remove(mfib_entry, source); |
| 969 | } |
| 970 | |
| 971 | mfib_entry_recalculate_forwarding(mfib_entry); |
| 972 | |
| 973 | return (mfib_entry_ok_for_delete(mfib_entry)); |
| 974 | } |
| 975 | |
| 976 | /** |
| 977 | * mfib_entry_delete |
| 978 | * |
| 979 | * The source is withdrawing all the paths it provided |
| 980 | */ |
| 981 | int |
| 982 | mfib_entry_delete (fib_node_index_t mfib_entry_index, |
| 983 | mfib_source_t source) |
| 984 | { |
| 985 | mfib_entry_t *mfib_entry; |
| 986 | |
| 987 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 988 | mfib_entry_src_remove(mfib_entry, source); |
| 989 | |
| 990 | mfib_entry_recalculate_forwarding(mfib_entry); |
| 991 | |
| 992 | return (mfib_entry_ok_for_delete(mfib_entry)); |
| 993 | } |
| 994 | |
| 995 | static int |
| 996 | fib_ip4_address_compare (ip4_address_t * a1, |
| 997 | ip4_address_t * a2) |
| 998 | { |
| 999 | /* |
| 1000 | * IP addresses are unsiged ints. the return value here needs to be signed |
| 1001 | * a simple subtraction won't cut it. |
| 1002 | * If the addresses are the same, the sort order is undefiend, so phoey. |
| 1003 | */ |
| 1004 | return ((clib_net_to_host_u32(a1->data_u32) > |
| 1005 | clib_net_to_host_u32(a2->data_u32) ) ? |
| 1006 | 1 : -1); |
| 1007 | } |
| 1008 | |
| 1009 | static int |
| 1010 | fib_ip6_address_compare (ip6_address_t * a1, |
| 1011 | ip6_address_t * a2) |
| 1012 | { |
| 1013 | int i; |
| 1014 | for (i = 0; i < ARRAY_LEN (a1->as_u16); i++) |
| 1015 | { |
| 1016 | int cmp = (clib_net_to_host_u16 (a1->as_u16[i]) - |
| 1017 | clib_net_to_host_u16 (a2->as_u16[i])); |
| 1018 | if (cmp != 0) |
| 1019 | return cmp; |
| 1020 | } |
| 1021 | return 0; |
| 1022 | } |
| 1023 | |
| 1024 | static int |
| 1025 | mfib_entry_cmp (fib_node_index_t mfib_entry_index1, |
| 1026 | fib_node_index_t mfib_entry_index2) |
| 1027 | { |
| 1028 | mfib_entry_t *mfib_entry1, *mfib_entry2; |
| 1029 | int cmp = 0; |
| 1030 | |
| 1031 | mfib_entry1 = mfib_entry_get(mfib_entry_index1); |
| 1032 | mfib_entry2 = mfib_entry_get(mfib_entry_index2); |
| 1033 | |
| 1034 | switch (mfib_entry1->mfe_prefix.fp_proto) |
| 1035 | { |
| 1036 | case FIB_PROTOCOL_IP4: |
| 1037 | cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip4, |
| 1038 | &mfib_entry2->mfe_prefix.fp_grp_addr.ip4); |
| 1039 | |
| 1040 | if (0 == cmp) |
| 1041 | { |
| 1042 | cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip4, |
| 1043 | &mfib_entry2->mfe_prefix.fp_src_addr.ip4); |
| 1044 | } |
| 1045 | break; |
| 1046 | case FIB_PROTOCOL_IP6: |
| 1047 | cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip6, |
| 1048 | &mfib_entry2->mfe_prefix.fp_grp_addr.ip6); |
| 1049 | |
| 1050 | if (0 == cmp) |
| 1051 | { |
| 1052 | cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip6, |
| 1053 | &mfib_entry2->mfe_prefix.fp_src_addr.ip6); |
| 1054 | } |
| 1055 | break; |
| 1056 | case FIB_PROTOCOL_MPLS: |
| 1057 | ASSERT(0); |
| 1058 | cmp = 0; |
| 1059 | break; |
| 1060 | } |
| 1061 | |
| 1062 | if (0 == cmp) { |
| 1063 | cmp = (mfib_entry1->mfe_prefix.fp_len - mfib_entry2->mfe_prefix.fp_len); |
| 1064 | } |
| 1065 | return (cmp); |
| 1066 | } |
| 1067 | |
| 1068 | int |
| 1069 | mfib_entry_cmp_for_sort (void *i1, void *i2) |
| 1070 | { |
| 1071 | fib_node_index_t *mfib_entry_index1 = i1, *mfib_entry_index2 = i2; |
| 1072 | |
| 1073 | return (mfib_entry_cmp(*mfib_entry_index1, |
| 1074 | *mfib_entry_index2)); |
| 1075 | } |
| 1076 | |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 1077 | static void |
| 1078 | mfib_entry_last_lock_gone (fib_node_t *node) |
| 1079 | { |
| 1080 | mfib_entry_t *mfib_entry; |
| 1081 | mfib_entry_src_t *msrc; |
| 1082 | |
| 1083 | mfib_entry = mfib_entry_from_fib_node(node); |
| 1084 | |
| 1085 | dpo_reset(&mfib_entry->mfe_rep); |
| 1086 | |
| 1087 | MFIB_ENTRY_DBG(mfib_entry, "last-lock"); |
| 1088 | |
| 1089 | vec_foreach(msrc, mfib_entry->mfe_srcs) |
| 1090 | { |
| 1091 | mfib_entry_src_flush(msrc); |
| 1092 | } |
| 1093 | |
| 1094 | vec_free(mfib_entry->mfe_srcs); |
| 1095 | |
| 1096 | fib_node_deinit(&mfib_entry->mfe_node); |
| 1097 | pool_put(mfib_entry_pool, mfib_entry); |
| 1098 | } |
| 1099 | |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 1100 | u32 |
| 1101 | mfib_entry_get_stats_index (fib_node_index_t fib_entry_index) |
| 1102 | { |
| 1103 | mfib_entry_t *mfib_entry; |
| 1104 | |
| 1105 | mfib_entry = mfib_entry_get(fib_entry_index); |
| 1106 | |
| 1107 | return (mfib_entry->mfe_rep.dpoi_index); |
| 1108 | } |
| 1109 | |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 1110 | /* |
| 1111 | * mfib_entry_back_walk_notify |
| 1112 | * |
| 1113 | * A back walk has reach this entry. |
| 1114 | */ |
| 1115 | static fib_node_back_walk_rc_t |
| 1116 | mfib_entry_back_walk_notify (fib_node_t *node, |
| 1117 | fib_node_back_walk_ctx_t *ctx) |
| 1118 | { |
| 1119 | mfib_entry_recalculate_forwarding(mfib_entry_from_fib_node(node)); |
| 1120 | |
| 1121 | return (FIB_NODE_BACK_WALK_CONTINUE); |
| 1122 | } |
| 1123 | |
| 1124 | static void |
| 1125 | mfib_entry_show_memory (void) |
| 1126 | { |
| 1127 | fib_show_memory_usage("multicast-Entry", |
| 1128 | pool_elts(mfib_entry_pool), |
| 1129 | pool_len(mfib_entry_pool), |
| 1130 | sizeof(mfib_entry_t)); |
| 1131 | } |
| 1132 | |
| 1133 | /* |
| 1134 | * The MFIB entry's graph node virtual function table |
| 1135 | */ |
| 1136 | static const fib_node_vft_t mfib_entry_vft = { |
| 1137 | .fnv_get = mfib_entry_get_node, |
| 1138 | .fnv_last_lock = mfib_entry_last_lock_gone, |
| 1139 | .fnv_back_walk = mfib_entry_back_walk_notify, |
| 1140 | .fnv_mem_show = mfib_entry_show_memory, |
| 1141 | }; |
| 1142 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1143 | void |
| 1144 | mfib_entry_lock (fib_node_index_t mfib_entry_index) |
| 1145 | { |
| 1146 | mfib_entry_t *mfib_entry; |
| 1147 | |
| 1148 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1149 | |
| 1150 | fib_node_lock(&mfib_entry->mfe_node); |
| 1151 | } |
| 1152 | |
| 1153 | void |
| 1154 | mfib_entry_unlock (fib_node_index_t mfib_entry_index) |
| 1155 | { |
| 1156 | mfib_entry_t *mfib_entry; |
| 1157 | |
| 1158 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1159 | |
| 1160 | fib_node_unlock(&mfib_entry->mfe_node); |
| 1161 | } |
| 1162 | |
| 1163 | static void |
| 1164 | mfib_entry_dpo_lock (dpo_id_t *dpo) |
| 1165 | { |
| 1166 | } |
| 1167 | static void |
| 1168 | mfib_entry_dpo_unlock (dpo_id_t *dpo) |
| 1169 | { |
| 1170 | } |
| 1171 | |
| 1172 | const static dpo_vft_t mfib_entry_dpo_vft = { |
| 1173 | .dv_lock = mfib_entry_dpo_lock, |
| 1174 | .dv_unlock = mfib_entry_dpo_unlock, |
| 1175 | .dv_format = format_mfib_entry_dpo, |
| 1176 | .dv_mem_show = mfib_entry_show_memory, |
| 1177 | }; |
| 1178 | |
| 1179 | const static char* const mfib_entry_ip4_nodes[] = |
| 1180 | { |
| 1181 | "ip4-mfib-forward-rpf", |
| 1182 | NULL, |
| 1183 | }; |
| 1184 | const static char* const mfib_entry_ip6_nodes[] = |
| 1185 | { |
| 1186 | "ip6-mfib-forward-rpf", |
| 1187 | NULL, |
| 1188 | }; |
| 1189 | |
| 1190 | const static char* const * const mfib_entry_nodes[DPO_PROTO_NUM] = |
| 1191 | { |
| 1192 | [DPO_PROTO_IP4] = mfib_entry_ip4_nodes, |
| 1193 | [DPO_PROTO_IP6] = mfib_entry_ip6_nodes, |
| 1194 | }; |
| 1195 | |
| 1196 | void |
| 1197 | mfib_entry_module_init (void) |
| 1198 | { |
| 1199 | fib_node_register_type (FIB_NODE_TYPE_MFIB_ENTRY, &mfib_entry_vft); |
| 1200 | dpo_register(DPO_MFIB_ENTRY, &mfib_entry_dpo_vft, mfib_entry_nodes); |
Neale Ranns | 710071b | 2018-09-24 12:36:26 +0000 | [diff] [blame] | 1201 | mfib_entry_logger = vlib_log_register_class("mfib", "entry"); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | void |
| 1205 | mfib_entry_encode (fib_node_index_t mfib_entry_index, |
| 1206 | fib_route_path_encode_t **api_rpaths) |
| 1207 | { |
| 1208 | mfib_entry_t *mfib_entry; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1209 | mfib_entry_src_t *bsrc; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1210 | |
| 1211 | mfib_entry = mfib_entry_get(mfib_entry_index); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1212 | bsrc = mfib_entry_get_best_src(mfib_entry); |
| 1213 | |
| 1214 | if (FIB_NODE_INDEX_INVALID != bsrc->mfes_pl) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1215 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1216 | fib_path_list_walk(bsrc->mfes_pl, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1217 | fib_path_encode, |
| 1218 | api_rpaths); |
| 1219 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 1222 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1223 | void |
| 1224 | mfib_entry_get_prefix (fib_node_index_t mfib_entry_index, |
| 1225 | mfib_prefix_t *pfx) |
| 1226 | { |
| 1227 | mfib_entry_t *mfib_entry; |
| 1228 | |
| 1229 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1230 | *pfx = mfib_entry->mfe_prefix; |
| 1231 | } |
| 1232 | |
| 1233 | u32 |
| 1234 | mfib_entry_get_fib_index (fib_node_index_t mfib_entry_index) |
| 1235 | { |
| 1236 | mfib_entry_t *mfib_entry; |
| 1237 | |
| 1238 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1239 | |
| 1240 | return (mfib_entry->mfe_fib_index); |
| 1241 | } |
| 1242 | |
Neale Ranns | ff23389 | 2017-12-12 00:21:19 -0800 | [diff] [blame] | 1243 | const dpo_id_t* |
| 1244 | mfib_entry_contribute_ip_forwarding (fib_node_index_t mfib_entry_index) |
| 1245 | { |
| 1246 | mfib_entry_t *mfib_entry; |
| 1247 | |
| 1248 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1249 | |
| 1250 | return (&mfib_entry->mfe_rep); |
| 1251 | } |
| 1252 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1253 | void |
| 1254 | mfib_entry_contribute_forwarding (fib_node_index_t mfib_entry_index, |
| 1255 | fib_forward_chain_type_t type, |
| 1256 | dpo_id_t *dpo) |
| 1257 | { |
| 1258 | /* |
| 1259 | * An IP mFIB entry can only provide a forwarding chain that |
| 1260 | * is the same IP proto as the prefix. |
| 1261 | * No use-cases (i know of) for other combinations. |
| 1262 | */ |
| 1263 | mfib_entry_t *mfib_entry; |
| 1264 | dpo_proto_t dp; |
| 1265 | |
| 1266 | mfib_entry = mfib_entry_get(mfib_entry_index); |
| 1267 | |
| 1268 | dp = fib_proto_to_dpo(mfib_entry->mfe_prefix.fp_proto); |
| 1269 | |
| 1270 | if (type == fib_forw_chain_type_from_dpo_proto(dp)) |
| 1271 | { |
| 1272 | dpo_copy(dpo, &mfib_entry->mfe_rep); |
| 1273 | } |
| 1274 | else |
| 1275 | { |
| 1276 | dpo_copy(dpo, drop_dpo_get(dp)); |
| 1277 | } |
| 1278 | } |
| 1279 | |
| 1280 | u32 |
| 1281 | mfib_entry_pool_size (void) |
| 1282 | { |
| 1283 | return (pool_elts(mfib_entry_pool)); |
| 1284 | } |
| 1285 | |
| 1286 | static clib_error_t * |
| 1287 | show_mfib_entry_command (vlib_main_t * vm, |
| 1288 | unformat_input_t * input, |
| 1289 | vlib_cli_command_t * cmd) |
| 1290 | { |
| 1291 | fib_node_index_t fei; |
| 1292 | |
| 1293 | if (unformat (input, "%d", &fei)) |
| 1294 | { |
| 1295 | /* |
| 1296 | * show one in detail |
| 1297 | */ |
| 1298 | if (!pool_is_free_index(mfib_entry_pool, fei)) |
| 1299 | { |
| 1300 | vlib_cli_output (vm, "%d@%U", |
| 1301 | fei, |
| 1302 | format_mfib_entry, fei, |
| 1303 | MFIB_ENTRY_FORMAT_DETAIL2); |
| 1304 | } |
| 1305 | else |
| 1306 | { |
| 1307 | vlib_cli_output (vm, "entry %d invalid", fei); |
| 1308 | } |
| 1309 | } |
| 1310 | else |
| 1311 | { |
| 1312 | /* |
| 1313 | * show all |
| 1314 | */ |
| 1315 | vlib_cli_output (vm, "FIB Entries:"); |
| 1316 | pool_foreach_index(fei, mfib_entry_pool, |
| 1317 | ({ |
| 1318 | vlib_cli_output (vm, "%d@%U", |
| 1319 | fei, |
| 1320 | format_mfib_entry, fei, |
| 1321 | MFIB_ENTRY_FORMAT_BRIEF); |
| 1322 | })); |
| 1323 | } |
| 1324 | |
| 1325 | return (NULL); |
| 1326 | } |
| 1327 | |
Neale Ranns | c756c1c | 2017-02-08 09:11:57 -0800 | [diff] [blame] | 1328 | /*? |
| 1329 | * This commnad displays an entry, or all entries, in the mfib tables indexed by their unique |
| 1330 | * numerical indentifier. |
| 1331 | ?*/ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 1332 | VLIB_CLI_COMMAND (show_mfib_entry, static) = { |
| 1333 | .path = "show mfib entry", |
| 1334 | .function = show_mfib_entry_command, |
| 1335 | .short_help = "show mfib entry", |
| 1336 | }; |