Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [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 <vnet/adj/adj.h> |
| 17 | #include <vnet/dpo/load_balance.h> |
| 18 | #include <vnet/dpo/mpls_label_dpo.h> |
| 19 | #include <vnet/dpo/drop_dpo.h> |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 20 | #include <vnet/dpo/replicate_dpo.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 21 | |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 22 | #include <vnet/fib/fib_entry_src.h> |
| 23 | #include <vnet/fib/fib_table.h> |
| 24 | #include <vnet/fib/fib_path_ext.h> |
| 25 | #include <vnet/fib/fib_urpf_list.h> |
Neale Ranns | 1f50bf8 | 2019-07-16 15:28:52 +0000 | [diff] [blame] | 26 | #include <vnet/fib/fib_entry_delegate.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * per-source type vft |
| 30 | */ |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 31 | static fib_entry_src_vft_t fib_entry_src_bh_vft[FIB_SOURCE_BH_MAX]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 32 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 33 | /** |
| 34 | * Get the VFT for a given source. This is a combination of the source |
| 35 | * enum and the interposer flags |
| 36 | */ |
| 37 | const fib_entry_src_vft_t* |
| 38 | fib_entry_src_get_vft (const fib_entry_src_t *esrc) |
| 39 | { |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 40 | fib_source_behaviour_t bh; |
| 41 | |
| 42 | bh = fib_source_get_behaviour(esrc->fes_src); |
| 43 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 44 | if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_INTERPOSE) |
| 45 | { |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 46 | return (&fib_entry_src_bh_vft[FIB_SOURCE_BH_INTERPOSE]); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Andrew Yourtchenko | d2acfbc | 2022-08-23 17:29:00 +0000 | [diff] [blame] | 49 | ASSERT(bh < FIB_SOURCE_BH_MAX); |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 50 | return (&fib_entry_src_bh_vft[bh]); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static void |
| 54 | fib_entry_src_copy_default (const fib_entry_src_t *orig_src, |
| 55 | const fib_entry_t *fib_entry, |
| 56 | fib_entry_src_t *copy_src) |
| 57 | { |
| 58 | clib_memcpy(©_src->u, &orig_src->u, sizeof(copy_src->u)); |
| 59 | } |
| 60 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 61 | void |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 62 | fib_entry_src_behaviour_register (fib_source_behaviour_t bh, |
| 63 | const fib_entry_src_vft_t *vft) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 64 | { |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 65 | fib_entry_src_bh_vft[bh] = *vft; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 66 | |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 67 | if (NULL == fib_entry_src_bh_vft[bh].fesv_copy) |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 68 | { |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 69 | fib_entry_src_bh_vft[bh].fesv_copy = fib_entry_src_copy_default; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 70 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static int |
| 74 | fib_entry_src_cmp_for_sort (void * v1, |
| 75 | void * v2) |
| 76 | { |
| 77 | fib_entry_src_t *esrc1 = v1, *esrc2 = v2; |
| 78 | |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 79 | return (fib_source_get_prio(esrc1->fes_src) - |
| 80 | fib_source_get_prio(esrc2->fes_src)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 81 | } |
| 82 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 83 | static void |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 84 | fib_entry_src_action_init (fib_entry_t *fib_entry, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 85 | fib_source_t source, |
| 86 | fib_entry_flag_t flags) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 87 | { |
| 88 | fib_entry_src_t esrc = { |
| 89 | .fes_pl = FIB_NODE_INDEX_INVALID, |
| 90 | .fes_flags = FIB_ENTRY_SRC_FLAG_NONE, |
| 91 | .fes_src = source, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 92 | .fes_entry_flags = flags, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 95 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, &esrc, fesv_init, (&esrc)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 96 | |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 97 | vec_add1(fib_entry->fe_srcs, esrc); |
| 98 | vec_sort_with_function(fib_entry->fe_srcs, |
| 99 | fib_entry_src_cmp_for_sort); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static fib_entry_src_t * |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 103 | fib_entry_src_find_i (const fib_entry_t *fib_entry, |
| 104 | fib_source_t source, |
| 105 | u32 *index) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 106 | |
| 107 | { |
| 108 | fib_entry_src_t *esrc; |
| 109 | int ii; |
| 110 | |
| 111 | ii = 0; |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 112 | vec_foreach(esrc, fib_entry->fe_srcs) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 113 | { |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 114 | if (esrc->fes_src == source) |
| 115 | { |
| 116 | if (NULL != index) |
| 117 | { |
| 118 | *index = ii; |
| 119 | } |
| 120 | return (esrc); |
| 121 | } |
| 122 | else |
| 123 | { |
| 124 | ii++; |
| 125 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | return (NULL); |
| 129 | } |
| 130 | |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 131 | fib_entry_src_t * |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 132 | fib_entry_src_find (const fib_entry_t *fib_entry, |
| 133 | fib_source_t source) |
| 134 | |
| 135 | { |
| 136 | return (fib_entry_src_find_i(fib_entry, source, NULL)); |
| 137 | } |
| 138 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 139 | int |
| 140 | fib_entry_is_sourced (fib_node_index_t fib_entry_index, |
| 141 | fib_source_t source) |
| 142 | { |
| 143 | fib_entry_t *fib_entry; |
| 144 | |
| 145 | fib_entry = fib_entry_get(fib_entry_index); |
| 146 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 147 | return (NULL != fib_entry_src_find(fib_entry, source)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 150 | int |
| 151 | fib_entry_is_marked (fib_node_index_t fib_entry_index, |
| 152 | fib_source_t source) |
| 153 | { |
| 154 | fib_entry_t *fib_entry; |
| 155 | fib_entry_src_t *esrc; |
| 156 | |
| 157 | fib_entry = fib_entry_get(fib_entry_index); |
| 158 | |
| 159 | esrc = fib_entry_src_find(fib_entry, source); |
| 160 | |
| 161 | if (NULL == esrc) |
| 162 | { |
| 163 | return (0); |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | return (!!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_STALE)); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void |
| 172 | fib_entry_mark (fib_node_index_t fib_entry_index, |
| 173 | fib_source_t source) |
| 174 | { |
| 175 | fib_entry_t *fib_entry; |
| 176 | fib_entry_src_t *esrc; |
| 177 | |
| 178 | fib_entry = fib_entry_get(fib_entry_index); |
| 179 | |
| 180 | esrc = fib_entry_src_find(fib_entry, source); |
| 181 | |
| 182 | if (NULL != esrc) |
| 183 | { |
| 184 | esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_STALE; |
| 185 | } |
| 186 | } |
| 187 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 188 | static fib_entry_src_t * |
| 189 | fib_entry_src_find_or_create (fib_entry_t *fib_entry, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 190 | fib_source_t source, |
| 191 | fib_entry_flag_t flags) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 192 | { |
| 193 | fib_entry_src_t *esrc; |
| 194 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 195 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 196 | |
| 197 | if (NULL == esrc) |
| 198 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 199 | fib_entry_src_action_init(fib_entry, source, flags); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 200 | } |
| 201 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 202 | return (fib_entry_src_find(fib_entry, source)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 203 | } |
| 204 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 205 | static void |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 206 | fib_entry_src_action_deinit (fib_entry_t *fib_entry, |
| 207 | fib_source_t source) |
| 208 | |
| 209 | { |
| 210 | fib_entry_src_t *esrc; |
| 211 | u32 index = ~0; |
| 212 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 213 | esrc = fib_entry_src_find_i(fib_entry, source, &index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 214 | |
| 215 | ASSERT(NULL != esrc); |
| 216 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 217 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_deinit, (esrc)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 218 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 219 | fib_path_ext_list_flush(&esrc->fes_path_exts); |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 220 | vec_del1(fib_entry->fe_srcs, index); |
Neale Ranns | 75b39f8 | 2018-10-26 04:17:54 -0700 | [diff] [blame] | 221 | vec_sort_with_function(fib_entry->fe_srcs, |
| 222 | fib_entry_src_cmp_for_sort); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | fib_entry_src_cover_res_t |
| 226 | fib_entry_src_action_cover_change (fib_entry_t *fib_entry, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 227 | fib_entry_src_t *esrc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 228 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 229 | FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_cover_change, |
| 230 | (esrc, fib_entry)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 231 | |
| 232 | fib_entry_src_cover_res_t res = { |
| 233 | .install = !0, |
| 234 | .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE, |
| 235 | }; |
| 236 | return (res); |
| 237 | } |
| 238 | |
| 239 | fib_entry_src_cover_res_t |
| 240 | fib_entry_src_action_cover_update (fib_entry_t *fib_entry, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 241 | fib_entry_src_t *esrc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 242 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 243 | FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_cover_update, |
| 244 | (esrc, fib_entry)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 245 | |
| 246 | fib_entry_src_cover_res_t res = { |
| 247 | .install = !0, |
| 248 | .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE, |
| 249 | }; |
| 250 | return (res); |
| 251 | } |
| 252 | |
| 253 | typedef struct fib_entry_src_collect_forwarding_ctx_t_ |
| 254 | { |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 255 | load_balance_path_t *next_hops; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 256 | const fib_entry_t *fib_entry; |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 257 | i32 start_source_index, end_source_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 258 | fib_forward_chain_type_t fct; |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 259 | int n_recursive_constrained; |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 260 | u16 preference; |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 261 | dpo_proto_t payload_proto; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 262 | } fib_entry_src_collect_forwarding_ctx_t; |
| 263 | |
| 264 | /** |
| 265 | * @brief Determine whether this FIB entry should use a load-balance MAP |
| 266 | * to support PIC edge fast convergence |
| 267 | */ |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 268 | static load_balance_flags_t |
| 269 | fib_entry_calc_lb_flags (fib_entry_src_collect_forwarding_ctx_t *ctx, |
| 270 | const fib_entry_src_t *esrc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 271 | { |
| 272 | /** |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 273 | * We'll use a LB map if the path-list has multiple recursive paths. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 274 | * recursive paths implies BGP, and hence scale. |
| 275 | */ |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 276 | if (ctx->n_recursive_constrained > 1 && |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 277 | fib_path_list_is_popular(esrc->fes_pl)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 278 | { |
| 279 | return (LOAD_BALANCE_FLAG_USES_MAP); |
| 280 | } |
| 281 | return (LOAD_BALANCE_FLAG_NONE); |
| 282 | } |
| 283 | |
| 284 | static int |
| 285 | fib_entry_src_valid_out_label (mpls_label_t label) |
| 286 | { |
| 287 | return ((MPLS_LABEL_IS_REAL(label) || |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 288 | MPLS_LABEL_POP == label || |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 289 | MPLS_IETF_IPV4_EXPLICIT_NULL_LABEL == label || |
| 290 | MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL == label || |
| 291 | MPLS_IETF_IMPLICIT_NULL_LABEL == label)); |
| 292 | } |
| 293 | |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 294 | static dpo_proto_t |
| 295 | fib_prefix_get_payload_proto (const fib_prefix_t *pfx) |
| 296 | { |
| 297 | switch (pfx->fp_proto) |
| 298 | { |
| 299 | case FIB_PROTOCOL_IP4: |
| 300 | return (DPO_PROTO_IP4); |
| 301 | case FIB_PROTOCOL_IP6: |
| 302 | return (DPO_PROTO_IP6); |
| 303 | case FIB_PROTOCOL_MPLS: |
| 304 | return (pfx->fp_payload_proto); |
| 305 | } |
| 306 | |
| 307 | ASSERT(0); |
| 308 | return (DPO_PROTO_IP4); |
| 309 | } |
| 310 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 311 | static void |
| 312 | fib_entry_src_get_path_forwarding (fib_node_index_t path_index, |
| 313 | fib_entry_src_collect_forwarding_ctx_t *ctx) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 314 | { |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 315 | load_balance_path_t *nh; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 316 | |
| 317 | /* |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 318 | * no extension => no out-going label for this path. that's OK |
| 319 | * in the case of an IP or EOS chain, but not for non-EOS |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 320 | */ |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 321 | switch (ctx->fct) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 322 | { |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 323 | case FIB_FORW_CHAIN_TYPE_UNICAST_IP4: |
| 324 | case FIB_FORW_CHAIN_TYPE_UNICAST_IP6: |
| 325 | case FIB_FORW_CHAIN_TYPE_MCAST_IP4: |
| 326 | case FIB_FORW_CHAIN_TYPE_MCAST_IP6: |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 327 | case FIB_FORW_CHAIN_TYPE_BIER: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 328 | /* |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 329 | * EOS traffic with no label to stack, we need the IP Adj |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 330 | */ |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 331 | vec_add2(ctx->next_hops, nh, 1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 332 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 333 | nh->path_index = path_index; |
| 334 | nh->path_weight = fib_path_get_weight(path_index); |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 335 | fib_path_contribute_forwarding(path_index, ctx->fct, |
| 336 | ctx->payload_proto, &nh->path_dpo); |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 337 | |
| 338 | break; |
| 339 | case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS: |
| 340 | if (fib_path_is_exclusive(path_index) || |
| 341 | fib_path_is_deag(path_index)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 342 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 343 | vec_add2(ctx->next_hops, nh, 1); |
| 344 | |
| 345 | nh->path_index = path_index; |
| 346 | nh->path_weight = fib_path_get_weight(path_index); |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 347 | fib_path_contribute_forwarding(path_index, |
| 348 | FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS, |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 349 | ctx->payload_proto, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 350 | &nh->path_dpo); |
| 351 | } |
| 352 | break; |
| 353 | case FIB_FORW_CHAIN_TYPE_MPLS_EOS: |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 354 | { |
| 355 | /* |
| 356 | * no label. we need a chain based on the payload. fixup. |
| 357 | */ |
| 358 | vec_add2(ctx->next_hops, nh, 1); |
| 359 | |
| 360 | nh->path_index = path_index; |
| 361 | nh->path_weight = fib_path_get_weight(path_index); |
| 362 | fib_path_contribute_forwarding(path_index, |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 363 | ctx->fct, |
| 364 | ctx->payload_proto, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 365 | &nh->path_dpo); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 366 | fib_path_stack_mpls_disp(path_index, |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 367 | ctx->payload_proto, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 368 | FIB_MPLS_LSP_MODE_PIPE, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 369 | &nh->path_dpo); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 370 | |
| 371 | break; |
| 372 | } |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 373 | case FIB_FORW_CHAIN_TYPE_ETHERNET: |
| 374 | case FIB_FORW_CHAIN_TYPE_NSH: |
| 375 | ASSERT(0); |
| 376 | break; |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | static fib_path_list_walk_rc_t |
| 381 | fib_entry_src_collect_forwarding (fib_node_index_t pl_index, |
| 382 | fib_node_index_t path_index, |
| 383 | void *arg) |
| 384 | { |
| 385 | fib_entry_src_collect_forwarding_ctx_t *ctx; |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 386 | const fib_entry_src_t *esrc; |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 387 | fib_path_ext_t *path_ext; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 388 | u32 n_nhs; |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 389 | |
| 390 | ctx = arg; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 391 | n_nhs = vec_len(ctx->next_hops); |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 392 | |
| 393 | /* |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 394 | * walk the paths and extension of the best non-interpose source |
| 395 | */ |
| 396 | esrc = &ctx->fib_entry->fe_srcs[ctx->end_source_index]; |
| 397 | |
| 398 | /* |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 399 | * if the path is not resolved, don't include it. |
| 400 | */ |
| 401 | if (!fib_path_is_resolved(path_index)) |
| 402 | { |
| 403 | return (FIB_PATH_LIST_WALK_CONTINUE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 404 | } |
| 405 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 406 | if (fib_path_is_recursive_constrained(path_index)) |
| 407 | { |
| 408 | ctx->n_recursive_constrained += 1; |
| 409 | } |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 410 | if (0xffff == ctx->preference) |
| 411 | { |
| 412 | /* |
| 413 | * not set a preference yet, so the first path we encounter |
| 414 | * sets the preference we are collecting. |
| 415 | */ |
| 416 | ctx->preference = fib_path_get_preference(path_index); |
| 417 | } |
| 418 | else if (ctx->preference != fib_path_get_preference(path_index)) |
| 419 | { |
| 420 | /* |
| 421 | * this path does not belong to the same preference as the |
| 422 | * previous paths encountered. we are done now. |
| 423 | */ |
| 424 | return (FIB_PATH_LIST_WALK_STOP); |
| 425 | } |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 426 | |
| 427 | /* |
| 428 | * get the matching path-extension for the path being visited. |
| 429 | */ |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 430 | path_ext = fib_path_ext_list_find_by_path_index(&esrc->fes_path_exts, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 431 | path_index); |
| 432 | |
| 433 | if (NULL != path_ext) |
| 434 | { |
| 435 | switch (path_ext->fpe_type) |
| 436 | { |
| 437 | case FIB_PATH_EXT_MPLS: |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 438 | if (fib_entry_src_valid_out_label(path_ext->fpe_label_stack[0].fml_value)) |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 439 | { |
| 440 | /* |
| 441 | * found a matching extension. stack it to obtain the forwarding |
| 442 | * info for this path. |
| 443 | */ |
| 444 | ctx->next_hops = |
| 445 | fib_path_ext_stack(path_ext, |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 446 | ctx->payload_proto, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 447 | ctx->fct, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 448 | ctx->next_hops); |
| 449 | } |
| 450 | else |
| 451 | { |
| 452 | fib_entry_src_get_path_forwarding(path_index, ctx); |
| 453 | } |
| 454 | break; |
| 455 | case FIB_PATH_EXT_ADJ: |
| 456 | if (FIB_PATH_EXT_ADJ_FLAG_REFINES_COVER & path_ext->fpe_adj_flags) |
| 457 | { |
| 458 | fib_entry_src_get_path_forwarding(path_index, ctx); |
| 459 | } |
| 460 | /* |
| 461 | * else |
| 462 | * the path does not refine the cover, meaning that |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 463 | * the adjacency does/does not match the sub-net on the link. |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 464 | * So this path does not contribute forwarding. |
| 465 | */ |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | else |
| 470 | { |
| 471 | fib_entry_src_get_path_forwarding(path_index, ctx); |
| 472 | } |
| 473 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 474 | /* |
| 475 | * a this point 'ctx' has the DPO the path contributed, plus |
| 476 | * any labels from path extensions. |
| 477 | * check if there are any interpose sources that want to contribute |
| 478 | */ |
| 479 | if (n_nhs < vec_len(ctx->next_hops)) |
| 480 | { |
| 481 | /* |
| 482 | * the path contributed a new choice. |
| 483 | */ |
| 484 | const fib_entry_src_vft_t *vft; |
| 485 | |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 486 | /* |
| 487 | * roll up the sources that are interposes |
| 488 | */ |
| 489 | i32 index; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 490 | |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 491 | for (index = ctx->end_source_index; |
| 492 | index >= ctx->start_source_index; |
| 493 | index--) |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 494 | { |
| 495 | const dpo_id_t *interposer; |
| 496 | |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 497 | esrc = &ctx->fib_entry->fe_srcs[index]; |
| 498 | vft = fib_entry_src_get_vft(esrc); |
| 499 | |
| 500 | if (!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_CONTRIBUTING) || |
| 501 | !(esrc->fes_entry_flags & FIB_ENTRY_FLAG_INTERPOSE)) |
| 502 | continue; |
| 503 | |
| 504 | ASSERT(vft->fesv_contribute_interpose); |
| 505 | interposer = vft->fesv_contribute_interpose(esrc, ctx->fib_entry); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 506 | |
| 507 | if (NULL != interposer) |
| 508 | { |
| 509 | dpo_id_t clone = DPO_INVALID; |
| 510 | |
| 511 | dpo_mk_interpose(interposer, |
| 512 | &ctx->next_hops[n_nhs].path_dpo, |
| 513 | &clone); |
| 514 | |
| 515 | dpo_copy(&ctx->next_hops[n_nhs].path_dpo, &clone); |
| 516 | dpo_reset(&clone); |
| 517 | } |
| 518 | } |
| 519 | } |
| 520 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 521 | return (FIB_PATH_LIST_WALK_CONTINUE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | void |
| 525 | fib_entry_src_mk_lb (fib_entry_t *fib_entry, |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 526 | fib_source_t source, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 527 | fib_forward_chain_type_t fct, |
| 528 | dpo_id_t *dpo_lb) |
| 529 | { |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 530 | const fib_entry_src_t *esrc; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 531 | dpo_proto_t lb_proto; |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 532 | u32 start, end; |
| 533 | |
| 534 | /* |
| 535 | * The source passed here is the 'best', i.e. the one the client |
| 536 | * wants. however, if it's an interpose then it does not contribute |
| 537 | * the forwarding, the next best source that is not an interpose does. |
| 538 | * So roll down the sources, to find the best non-interpose |
| 539 | */ |
| 540 | vec_foreach_index (start, fib_entry->fe_srcs) |
| 541 | { |
| 542 | if (source == fib_entry->fe_srcs[start].fes_src) |
| 543 | break; |
| 544 | } |
| 545 | for (end = start; end < vec_len (fib_entry->fe_srcs); end++) |
| 546 | { |
| 547 | if (!(fib_entry->fe_srcs[end].fes_entry_flags & |
| 548 | FIB_ENTRY_FLAG_INTERPOSE) && |
| 549 | (fib_entry->fe_srcs[end].fes_flags & |
| 550 | FIB_ENTRY_SRC_FLAG_CONTRIBUTING)) |
| 551 | break; |
| 552 | } |
| 553 | if (end == vec_len(fib_entry->fe_srcs)) |
| 554 | { |
| 555 | /* didn't find any contributing non-interpose sources */ |
| 556 | end = start; |
| 557 | } |
| 558 | |
| 559 | esrc = &fib_entry->fe_srcs[end]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 560 | |
| 561 | /* |
| 562 | * If the entry has path extensions then we construct a load-balance |
| 563 | * by stacking the extensions on the forwarding chains of the paths. |
| 564 | * Otherwise we use the load-balance of the path-list |
| 565 | */ |
| 566 | fib_entry_src_collect_forwarding_ctx_t ctx = { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 567 | .fib_entry = fib_entry, |
| 568 | .next_hops = NULL, |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 569 | .n_recursive_constrained = 0, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 570 | .fct = fct, |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 571 | .preference = 0xffff, |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 572 | .start_source_index = start, |
| 573 | .end_source_index = end, |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 574 | .payload_proto = fib_prefix_get_payload_proto(&fib_entry->fe_prefix), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 575 | }; |
| 576 | |
Neale Ranns | c0790cf | 2017-01-05 01:01:47 -0800 | [diff] [blame] | 577 | /* |
| 578 | * As an optimisation we allocate the vector of next-hops to be sized |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 579 | * equal to the maximum number of paths we will need, which is also the |
Neale Ranns | c0790cf | 2017-01-05 01:01:47 -0800 | [diff] [blame] | 580 | * most likely number we will need, since in most cases the paths are 'up'. |
| 581 | */ |
| 582 | vec_validate(ctx.next_hops, fib_path_list_get_n_paths(esrc->fes_pl)); |
| 583 | vec_reset_length(ctx.next_hops); |
| 584 | |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 585 | lb_proto = fib_forw_chain_type_to_dpo_proto(fct); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 586 | |
| 587 | fib_path_list_walk(esrc->fes_pl, |
| 588 | fib_entry_src_collect_forwarding, |
| 589 | &ctx); |
| 590 | |
| 591 | if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_EXCLUSIVE) |
| 592 | { |
| 593 | /* |
| 594 | * the client provided the DPO that the entry should link to. |
| 595 | * all entries must link to a LB, so if it is an LB already |
| 596 | * then we can use it. |
| 597 | */ |
| 598 | if ((1 == vec_len(ctx.next_hops)) && |
| 599 | (DPO_LOAD_BALANCE == ctx.next_hops[0].path_dpo.dpoi_type)) |
| 600 | { |
| 601 | dpo_copy(dpo_lb, &ctx.next_hops[0].path_dpo); |
| 602 | dpo_reset(&ctx.next_hops[0].path_dpo); |
| 603 | return; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | if (!dpo_id_is_valid(dpo_lb)) |
| 608 | { |
| 609 | /* |
| 610 | * first time create |
| 611 | */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 612 | if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_MULTICAST) |
| 613 | { |
| 614 | dpo_set(dpo_lb, |
| 615 | DPO_REPLICATE, |
| 616 | lb_proto, |
| 617 | MPLS_IS_REPLICATE | replicate_create(0, lb_proto)); |
| 618 | } |
| 619 | else |
| 620 | { |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 621 | fib_protocol_t flow_hash_proto; |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 622 | flow_hash_config_t fhc; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 623 | |
Neale Ranns | 41da54f | 2017-05-02 10:15:19 -0700 | [diff] [blame] | 624 | /* |
| 625 | * if the protocol for the LB we are building does not match that |
| 626 | * of the fib_entry (i.e. we are build the [n]EOS LB for an IPv[46] |
| 627 | * then the fib_index is not an index that relates to the table |
| 628 | * type we need. So get the default flow-hash config instead. |
| 629 | */ |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 630 | flow_hash_proto = dpo_proto_to_fib(lb_proto); |
| 631 | if (fib_entry->fe_prefix.fp_proto != flow_hash_proto) |
Neale Ranns | 41da54f | 2017-05-02 10:15:19 -0700 | [diff] [blame] | 632 | { |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 633 | fhc = fib_table_get_default_flow_hash_config(flow_hash_proto); |
Neale Ranns | 41da54f | 2017-05-02 10:15:19 -0700 | [diff] [blame] | 634 | } |
| 635 | else |
| 636 | { |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 637 | fhc = fib_table_get_flow_hash_config(fib_entry->fe_fib_index, |
| 638 | flow_hash_proto); |
Neale Ranns | 41da54f | 2017-05-02 10:15:19 -0700 | [diff] [blame] | 639 | } |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 640 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 641 | dpo_set(dpo_lb, |
| 642 | DPO_LOAD_BALANCE, |
| 643 | lb_proto, |
| 644 | load_balance_create(0, lb_proto, fhc)); |
| 645 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 646 | } |
| 647 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 648 | if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_MULTICAST) |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 649 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 650 | /* |
| 651 | * MPLS multicast |
| 652 | */ |
| 653 | replicate_multipath_update(dpo_lb, ctx.next_hops); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 654 | } |
| 655 | else |
| 656 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 657 | load_balance_multipath_update(dpo_lb, |
| 658 | ctx.next_hops, |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 659 | fib_entry_calc_lb_flags(&ctx, esrc)); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 660 | vec_free(ctx.next_hops); |
| 661 | |
| 662 | /* |
| 663 | * if this entry is sourced by the uRPF-exempt source then we |
| 664 | * append the always present local0 interface (index 0) to the |
| 665 | * uRPF list so it is not empty. that way packets pass the loose check. |
| 666 | */ |
| 667 | index_t ui = fib_path_list_get_urpf(esrc->fes_pl); |
| 668 | |
| 669 | if ((fib_entry_is_sourced(fib_entry_get_index(fib_entry), |
| 670 | FIB_SOURCE_URPF_EXEMPT) || |
| 671 | (esrc->fes_entry_flags & FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT))&& |
| 672 | (0 == fib_urpf_check_size(ui))) |
| 673 | { |
| 674 | /* |
| 675 | * The uRPF list we get from the path-list is shared by all |
| 676 | * other users of the list, but the uRPF exemption applies |
| 677 | * only to this prefix. So we need our own list. |
| 678 | */ |
| 679 | ui = fib_urpf_list_alloc_and_lock(); |
| 680 | fib_urpf_list_append(ui, 0); |
| 681 | fib_urpf_list_bake(ui); |
| 682 | load_balance_set_urpf(dpo_lb->dpoi_index, ui); |
| 683 | fib_urpf_list_unlock(ui); |
| 684 | } |
| 685 | else |
| 686 | { |
| 687 | load_balance_set_urpf(dpo_lb->dpoi_index, ui); |
| 688 | } |
| 689 | load_balance_set_fib_entry_flags(dpo_lb->dpoi_index, |
| 690 | fib_entry_get_flags_i(fib_entry)); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 691 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | void |
| 695 | fib_entry_src_action_install (fib_entry_t *fib_entry, |
| 696 | fib_source_t source) |
| 697 | { |
| 698 | /* |
| 699 | * Install the forwarding chain for the given source into the forwarding |
| 700 | * tables |
| 701 | */ |
| 702 | fib_forward_chain_type_t fct; |
Neale Ranns | 33a7dd5 | 2016-10-07 15:14:33 +0100 | [diff] [blame] | 703 | int insert; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 704 | |
| 705 | fct = fib_entry_get_default_chain_type(fib_entry); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 706 | |
Neale Ranns | 33a7dd5 | 2016-10-07 15:14:33 +0100 | [diff] [blame] | 707 | /* |
| 708 | * Every entry has its own load-balance object. All changes to the entry's |
| 709 | * forwarding result in an inplace modify of the load-balance. This means |
| 710 | * the load-balance object only needs to be added to the forwarding |
| 711 | * DB once, when it is created. |
| 712 | */ |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 713 | insert = !dpo_id_is_valid(&fib_entry->fe_lb); |
Neale Ranns | 33a7dd5 | 2016-10-07 15:14:33 +0100 | [diff] [blame] | 714 | |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 715 | fib_entry_src_mk_lb(fib_entry, source, fct, &fib_entry->fe_lb); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 716 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 717 | ASSERT(dpo_id_is_valid(&fib_entry->fe_lb)); |
| 718 | FIB_ENTRY_DBG(fib_entry, "install: %d", fib_entry->fe_lb); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 719 | |
| 720 | /* |
| 721 | * insert the adj into the data-plane forwarding trie |
| 722 | */ |
Neale Ranns | 33a7dd5 | 2016-10-07 15:14:33 +0100 | [diff] [blame] | 723 | if (insert) |
| 724 | { |
| 725 | fib_table_fwding_dpo_update(fib_entry->fe_fib_index, |
| 726 | &fib_entry->fe_prefix, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 727 | &fib_entry->fe_lb); |
Neale Ranns | 33a7dd5 | 2016-10-07 15:14:33 +0100 | [diff] [blame] | 728 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 729 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 730 | /* |
| 731 | * if any of the other chain types are already created they will need |
| 732 | * updating too |
| 733 | */ |
| 734 | fib_entry_delegate_type_t fdt; |
| 735 | fib_entry_delegate_t *fed; |
| 736 | |
| 737 | FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 738 | { |
Neale Ranns | 1c59df7 | 2021-01-26 12:08:25 +0000 | [diff] [blame] | 739 | fib_entry_src_mk_lb(fib_entry, source, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 740 | fib_entry_delegate_type_to_chain_type(fdt), |
| 741 | &fed->fd_dpo); |
| 742 | }); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | void |
| 746 | fib_entry_src_action_uninstall (fib_entry_t *fib_entry) |
| 747 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 748 | /* |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 749 | * uninstall the forwarding chain from the forwarding tables |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 750 | */ |
Neale Ranns | 710071b | 2018-09-24 12:36:26 +0000 | [diff] [blame] | 751 | FIB_ENTRY_DBG(fib_entry, "uninstall"); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 752 | |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 753 | if (dpo_id_is_valid(&fib_entry->fe_lb)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 754 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 755 | fib_table_fwding_dpo_remove( |
| 756 | fib_entry->fe_fib_index, |
| 757 | &fib_entry->fe_prefix, |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 758 | &fib_entry->fe_lb); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 759 | |
Steven Luong | 58f37b2 | 2024-02-12 16:47:22 -0800 | [diff] [blame] | 760 | vlib_worker_wait_one_loop(); |
Neale Ranns | ad422ed | 2016-11-02 14:20:04 +0000 | [diff] [blame] | 761 | dpo_reset(&fib_entry->fe_lb); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
| 765 | static void |
| 766 | fib_entry_recursive_loop_detect_i (fib_node_index_t path_list_index) |
| 767 | { |
| 768 | fib_node_index_t *entries = NULL; |
| 769 | |
| 770 | fib_path_list_recursive_loop_detect(path_list_index, &entries); |
| 771 | |
| 772 | vec_free(entries); |
| 773 | } |
| 774 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 775 | /* |
| 776 | * fib_entry_src_action_copy |
| 777 | * |
| 778 | * copy a source data from another entry to this one |
| 779 | */ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 780 | static fib_entry_t * |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 781 | fib_entry_src_action_copy (fib_entry_t *fib_entry, |
| 782 | const fib_entry_src_t *orig_src) |
| 783 | { |
| 784 | fib_entry_src_t *esrc; |
| 785 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 786 | esrc = fib_entry_src_find_or_create(fib_entry, |
| 787 | orig_src->fes_src, |
| 788 | orig_src->fes_entry_flags); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 789 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 790 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_copy, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 791 | (orig_src, fib_entry, esrc)); |
| 792 | |
| 793 | fib_path_list_unlock(esrc->fes_pl); |
| 794 | |
| 795 | /* |
| 796 | * copy over all the data ... |
| 797 | */ |
| 798 | esrc->fes_flags = orig_src->fes_flags; |
| 799 | esrc->fes_pl = orig_src->fes_pl; |
| 800 | |
| 801 | /* |
| 802 | * ... then update |
| 803 | */ |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 804 | esrc->fes_ref_count = 1; |
| 805 | esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_INHERITED; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 806 | esrc->fes_flags &= ~(FIB_ENTRY_SRC_FLAG_ACTIVE | |
| 807 | FIB_ENTRY_SRC_FLAG_CONTRIBUTING); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 808 | esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_COVERED_INHERIT; |
| 809 | |
| 810 | /* |
| 811 | * the source owns a lock on the entry |
| 812 | */ |
| 813 | fib_path_list_lock(esrc->fes_pl); |
| 814 | fib_entry_lock(fib_entry_get_index(fib_entry)); |
| 815 | |
| 816 | return (fib_entry); |
| 817 | } |
| 818 | |
| 819 | /* |
| 820 | * fib_entry_src_action_update |
| 821 | * |
| 822 | * copy a source data from another entry to this one |
| 823 | */ |
| 824 | static fib_entry_src_t * |
| 825 | fib_entry_src_action_update_from_cover (fib_entry_t *fib_entry, |
| 826 | const fib_entry_src_t *orig_src) |
| 827 | { |
| 828 | fib_entry_src_t *esrc; |
| 829 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 830 | esrc = fib_entry_src_find_or_create(fib_entry, |
| 831 | orig_src->fes_src, |
| 832 | orig_src->fes_entry_flags); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 833 | |
| 834 | /* |
| 835 | * the source owns a lock on the entry |
| 836 | */ |
| 837 | fib_path_list_unlock(esrc->fes_pl); |
| 838 | esrc->fes_pl = orig_src->fes_pl; |
| 839 | fib_path_list_lock(esrc->fes_pl); |
| 840 | |
| 841 | return (esrc); |
| 842 | } |
| 843 | |
| 844 | static fib_table_walk_rc_t |
| 845 | fib_entry_src_covered_inherit_add_i (fib_entry_t *fib_entry, |
| 846 | const fib_entry_src_t *cover_src) |
| 847 | { |
| 848 | fib_entry_src_t *esrc; |
| 849 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 850 | esrc = fib_entry_src_find(fib_entry, cover_src->fes_src); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 851 | |
| 852 | if (cover_src == esrc) |
| 853 | { |
| 854 | return (FIB_TABLE_WALK_CONTINUE); |
| 855 | } |
| 856 | |
| 857 | if (NULL != esrc) |
| 858 | { |
| 859 | /* |
| 860 | * the covered entry already has this source. |
| 861 | */ |
| 862 | if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) |
| 863 | { |
| 864 | /* |
| 865 | * the covered source is itself a COVERED_INHERIT, i.e. |
| 866 | * it also pushes this source down the sub-tree. |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 867 | * We consider this more specific covered to be the owner |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 868 | * of the sub-tree from this point down. |
| 869 | */ |
| 870 | return (FIB_TABLE_WALK_SUB_TREE_STOP); |
| 871 | } |
| 872 | if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED) |
| 873 | { |
| 874 | /* |
| 875 | * The covered's source data has been inherited, presumably |
| 876 | * from this cover, i.e. this is a modify. |
| 877 | */ |
Maxime Peim | 6eac5ba | 2024-02-20 12:27:38 +0100 | [diff] [blame] | 878 | fib_source_t best_source; |
| 879 | |
| 880 | best_source = fib_entry_get_best_source( |
| 881 | fib_entry_get_index(fib_entry)); |
| 882 | fib_entry_src_action_update_from_cover(fib_entry, cover_src); |
| 883 | fib_entry_source_change(fib_entry, best_source, cover_src->fes_src); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 884 | } |
| 885 | else |
| 886 | { |
| 887 | /* |
| 888 | * The covered's source was not inherited and it is also |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 889 | * not inheriting. Nevertheless, it still owns the sub-tree from |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 890 | * this point down. |
| 891 | */ |
| 892 | return (FIB_TABLE_WALK_SUB_TREE_STOP); |
| 893 | } |
| 894 | } |
| 895 | else |
| 896 | { |
| 897 | /* |
| 898 | * The covered does not have this source - add it. |
| 899 | */ |
| 900 | fib_source_t best_source; |
| 901 | |
| 902 | best_source = fib_entry_get_best_source( |
| 903 | fib_entry_get_index(fib_entry)); |
| 904 | |
| 905 | fib_entry_src_action_copy(fib_entry, cover_src); |
| 906 | fib_entry_source_change(fib_entry, best_source, cover_src->fes_src); |
| 907 | |
| 908 | } |
| 909 | return (FIB_TABLE_WALK_CONTINUE); |
| 910 | } |
| 911 | |
| 912 | static fib_table_walk_rc_t |
| 913 | fib_entry_src_covered_inherit_walk_add (fib_node_index_t fei, |
| 914 | void *ctx) |
| 915 | { |
| 916 | return (fib_entry_src_covered_inherit_add_i(fib_entry_get(fei), ctx)); |
| 917 | } |
| 918 | |
| 919 | static fib_table_walk_rc_t |
| 920 | fib_entry_src_covered_inherit_walk_remove (fib_node_index_t fei, |
| 921 | void *ctx) |
| 922 | { |
| 923 | fib_entry_src_t *cover_src, *esrc; |
| 924 | fib_entry_t *fib_entry; |
| 925 | |
| 926 | fib_entry = fib_entry_get(fei); |
| 927 | |
| 928 | cover_src = ctx; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 929 | esrc = fib_entry_src_find(fib_entry, cover_src->fes_src); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 930 | |
| 931 | if (cover_src == esrc) |
| 932 | { |
| 933 | return (FIB_TABLE_WALK_CONTINUE); |
| 934 | } |
| 935 | |
| 936 | if (NULL != esrc) |
| 937 | { |
| 938 | /* |
| 939 | * the covered entry already has this source. |
| 940 | */ |
| 941 | if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) |
| 942 | { |
| 943 | /* |
| 944 | * the covered source is itself a COVERED_INHERIT, i.e. |
| 945 | * it also pushes this source down the sub-tree. |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 946 | * We consider this more specific covered to be the owner |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 947 | * of the sub-tree from this point down. |
| 948 | */ |
| 949 | return (FIB_TABLE_WALK_SUB_TREE_STOP); |
| 950 | } |
| 951 | if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED) |
| 952 | { |
| 953 | /* |
| 954 | * The covered's source data has been inherited, presumably |
| 955 | * from this cover |
| 956 | */ |
| 957 | fib_entry_src_flag_t remaining; |
| 958 | |
| 959 | remaining = fib_entry_special_remove(fei, cover_src->fes_src); |
| 960 | |
| 961 | ASSERT(FIB_ENTRY_SRC_FLAG_ADDED == remaining); |
| 962 | } |
| 963 | else |
| 964 | { |
| 965 | /* |
| 966 | * The covered's source was not inherited and it is also |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 967 | * not inheriting. Nevertheless, it still owns the sub-tree from |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 968 | * this point down. |
| 969 | */ |
| 970 | return (FIB_TABLE_WALK_SUB_TREE_STOP); |
| 971 | } |
| 972 | } |
| 973 | else |
| 974 | { |
| 975 | /* |
| 976 | * The covered does not have this source - that's an error, |
| 977 | * since it should have inherited, but there is nothing we can do |
| 978 | * about it now. |
| 979 | */ |
| 980 | } |
| 981 | return (FIB_TABLE_WALK_CONTINUE); |
| 982 | } |
| 983 | |
| 984 | void |
| 985 | fib_entry_src_inherit (const fib_entry_t *cover, |
| 986 | fib_entry_t *covered) |
| 987 | { |
| 988 | CLIB_UNUSED(fib_source_t source); |
| 989 | const fib_entry_src_t *src; |
| 990 | |
| 991 | FOR_EACH_SRC_ADDED(cover, src, source, |
| 992 | ({ |
| 993 | if ((src->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) || |
| 994 | (src->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED)) |
| 995 | { |
| 996 | fib_entry_src_covered_inherit_add_i(covered, src); |
| 997 | } |
| 998 | })) |
| 999 | } |
| 1000 | |
| 1001 | static void |
| 1002 | fib_entry_src_covered_inherit_add (fib_entry_t *fib_entry, |
| 1003 | fib_source_t source) |
| 1004 | |
| 1005 | { |
| 1006 | fib_entry_src_t *esrc; |
| 1007 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1008 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1009 | |
| 1010 | ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE); |
| 1011 | |
| 1012 | if ((esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) || |
| 1013 | (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED)) |
| 1014 | { |
| 1015 | fib_table_sub_tree_walk(fib_entry->fe_fib_index, |
| 1016 | fib_entry->fe_prefix.fp_proto, |
| 1017 | &fib_entry->fe_prefix, |
| 1018 | fib_entry_src_covered_inherit_walk_add, |
| 1019 | esrc); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | static void |
| 1024 | fib_entry_src_covered_inherit_remove (fib_entry_t *fib_entry, |
| 1025 | fib_entry_src_t *esrc) |
| 1026 | |
| 1027 | { |
| 1028 | ASSERT(!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE)); |
| 1029 | |
| 1030 | if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) |
| 1031 | { |
| 1032 | fib_table_sub_tree_walk(fib_entry->fe_fib_index, |
| 1033 | fib_entry->fe_prefix.fp_proto, |
| 1034 | &fib_entry->fe_prefix, |
| 1035 | fib_entry_src_covered_inherit_walk_remove, |
| 1036 | esrc); |
| 1037 | } |
| 1038 | } |
| 1039 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1040 | void |
| 1041 | fib_entry_src_action_activate (fib_entry_t *fib_entry, |
| 1042 | fib_source_t source) |
| 1043 | |
| 1044 | { |
| 1045 | int houston_we_are_go_for_install; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1046 | const fib_entry_src_vft_t *vft; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1047 | fib_entry_src_t *esrc; |
| 1048 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1049 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1050 | |
| 1051 | ASSERT(!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE)); |
| 1052 | ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED); |
| 1053 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1054 | esrc->fes_flags |= (FIB_ENTRY_SRC_FLAG_ACTIVE | |
| 1055 | FIB_ENTRY_SRC_FLAG_CONTRIBUTING); |
| 1056 | vft = fib_entry_src_get_vft(esrc); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1057 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1058 | if (NULL != vft->fesv_activate) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1059 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1060 | houston_we_are_go_for_install = vft->fesv_activate(esrc, fib_entry); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1061 | } |
| 1062 | else |
| 1063 | { |
| 1064 | /* |
| 1065 | * the source is not providing an activate function, we'll assume |
| 1066 | * therefore it has no objection to installing the entry |
| 1067 | */ |
| 1068 | houston_we_are_go_for_install = !0; |
| 1069 | } |
| 1070 | |
| 1071 | /* |
| 1072 | * link to the path-list provided by the source, and go check |
| 1073 | * if that forms any loops in the graph. |
| 1074 | */ |
| 1075 | fib_entry->fe_parent = esrc->fes_pl; |
| 1076 | fib_entry->fe_sibling = |
| 1077 | fib_path_list_child_add(fib_entry->fe_parent, |
| 1078 | FIB_NODE_TYPE_ENTRY, |
| 1079 | fib_entry_get_index(fib_entry)); |
| 1080 | |
| 1081 | fib_entry_recursive_loop_detect_i(fib_entry->fe_parent); |
| 1082 | |
| 1083 | FIB_ENTRY_DBG(fib_entry, "activate: %d", |
| 1084 | fib_entry->fe_parent); |
| 1085 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1086 | /* |
| 1087 | * If this source should push its state to covered prefixs, do that now. |
| 1088 | */ |
| 1089 | fib_entry_src_covered_inherit_add(fib_entry, source); |
| 1090 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1091 | if (0 != houston_we_are_go_for_install) |
| 1092 | { |
| 1093 | fib_entry_src_action_install(fib_entry, source); |
| 1094 | } |
| 1095 | else |
| 1096 | { |
| 1097 | fib_entry_src_action_uninstall(fib_entry); |
| 1098 | } |
| 1099 | } |
| 1100 | |
| 1101 | void |
| 1102 | fib_entry_src_action_deactivate (fib_entry_t *fib_entry, |
| 1103 | fib_source_t source) |
| 1104 | |
| 1105 | { |
| 1106 | fib_node_index_t path_list_index; |
| 1107 | fib_entry_src_t *esrc; |
| 1108 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1109 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1110 | |
| 1111 | ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE); |
| 1112 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1113 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_deactivate, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1114 | (esrc, fib_entry)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1115 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1116 | esrc->fes_flags &= ~(FIB_ENTRY_SRC_FLAG_ACTIVE | |
| 1117 | FIB_ENTRY_SRC_FLAG_CONTRIBUTING); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1118 | |
| 1119 | FIB_ENTRY_DBG(fib_entry, "deactivate: %d", fib_entry->fe_parent); |
| 1120 | |
| 1121 | /* |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1122 | * If this source should pull its state from covered prefixs, do that now. |
| 1123 | * If this source also has the INHERITED flag set then it has a cover |
| 1124 | * that wants to push down forwarding. We only want the covereds to see |
| 1125 | * one update. |
| 1126 | */ |
| 1127 | fib_entry_src_covered_inherit_remove(fib_entry, esrc); |
| 1128 | |
| 1129 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1130 | * un-link from an old path-list. Check for any loops this will clear |
| 1131 | */ |
| 1132 | path_list_index = fib_entry->fe_parent; |
| 1133 | fib_entry->fe_parent = FIB_NODE_INDEX_INVALID; |
| 1134 | |
| 1135 | fib_entry_recursive_loop_detect_i(path_list_index); |
| 1136 | |
| 1137 | /* |
| 1138 | * this will unlock the path-list, so it may be invalid thereafter. |
| 1139 | */ |
| 1140 | fib_path_list_child_remove(path_list_index, fib_entry->fe_sibling); |
| 1141 | fib_entry->fe_sibling = FIB_NODE_INDEX_INVALID; |
| 1142 | } |
| 1143 | |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 1144 | static void |
| 1145 | fib_entry_src_action_fwd_update (const fib_entry_t *fib_entry, |
| 1146 | fib_source_t source) |
| 1147 | { |
| 1148 | fib_entry_src_t *esrc; |
| 1149 | |
| 1150 | vec_foreach(esrc, fib_entry->fe_srcs) |
| 1151 | { |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1152 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_fwd_update, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1153 | (esrc, fib_entry, source)); |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1157 | void |
| 1158 | fib_entry_src_action_reactivate (fib_entry_t *fib_entry, |
| 1159 | fib_source_t source) |
| 1160 | { |
| 1161 | fib_node_index_t path_list_index; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1162 | const fib_entry_src_vft_t *vft; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1163 | fib_entry_src_t *esrc; |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1164 | int remain_installed; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1165 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1166 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1167 | |
| 1168 | ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE); |
| 1169 | |
| 1170 | FIB_ENTRY_DBG(fib_entry, "reactivate: %d to %d", |
| 1171 | fib_entry->fe_parent, |
| 1172 | esrc->fes_pl); |
| 1173 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1174 | /* |
| 1175 | * call the source to reactive and get the go/no-go to remain installed |
| 1176 | */ |
| 1177 | vft = fib_entry_src_get_vft(esrc); |
| 1178 | |
| 1179 | if (NULL != vft->fesv_reactivate) |
| 1180 | { |
| 1181 | remain_installed = vft->fesv_reactivate(esrc, fib_entry); |
| 1182 | } |
| 1183 | else |
| 1184 | { |
| 1185 | remain_installed = 1; |
| 1186 | } |
| 1187 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1188 | if (fib_entry->fe_parent != esrc->fes_pl) |
| 1189 | { |
| 1190 | /* |
| 1191 | * un-link from an old path-list. Check for any loops this will clear |
| 1192 | */ |
| 1193 | path_list_index = fib_entry->fe_parent; |
| 1194 | fib_entry->fe_parent = FIB_NODE_INDEX_INVALID; |
| 1195 | |
| 1196 | /* |
| 1197 | * temporary lock so it doesn't get deleted when this entry is no |
| 1198 | * longer a child. |
| 1199 | */ |
| 1200 | fib_path_list_lock(path_list_index); |
| 1201 | |
| 1202 | /* |
| 1203 | * this entry is no longer a child. after unlinking check if any loops |
| 1204 | * were broken |
| 1205 | */ |
| 1206 | fib_path_list_child_remove(path_list_index, |
| 1207 | fib_entry->fe_sibling); |
| 1208 | |
| 1209 | fib_entry_recursive_loop_detect_i(path_list_index); |
| 1210 | |
| 1211 | /* |
| 1212 | * link to the path-list provided by the source, and go check |
| 1213 | * if that forms any loops in the graph. |
| 1214 | */ |
| 1215 | fib_entry->fe_parent = esrc->fes_pl; |
| 1216 | fib_entry->fe_sibling = |
| 1217 | fib_path_list_child_add(fib_entry->fe_parent, |
| 1218 | FIB_NODE_TYPE_ENTRY, |
| 1219 | fib_entry_get_index(fib_entry)); |
| 1220 | |
| 1221 | fib_entry_recursive_loop_detect_i(fib_entry->fe_parent); |
| 1222 | fib_path_list_unlock(path_list_index); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1223 | |
| 1224 | /* |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1225 | * If this source should push its state to covered prefixs, do that now. |
| 1226 | */ |
| 1227 | fib_entry_src_covered_inherit_add(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1228 | } |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1229 | |
| 1230 | if (!remain_installed) |
| 1231 | { |
| 1232 | fib_entry_src_action_uninstall(fib_entry); |
| 1233 | } |
| 1234 | else |
| 1235 | { |
| 1236 | fib_entry_src_action_install(fib_entry, source); |
| 1237 | } |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 1238 | fib_entry_src_action_fwd_update(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1239 | } |
| 1240 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1241 | fib_entry_t * |
| 1242 | fib_entry_src_action_installed (fib_entry_t *fib_entry, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1243 | fib_source_t source) |
| 1244 | { |
| 1245 | fib_entry_src_t *esrc; |
| 1246 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1247 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1248 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1249 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_installed, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1250 | (esrc, fib_entry)); |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 1251 | |
| 1252 | fib_entry_src_action_fwd_update(fib_entry, source); |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1253 | |
| 1254 | return (fib_entry); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | /* |
| 1258 | * fib_entry_src_action_add |
| 1259 | * |
| 1260 | * Adding a source can result in a new fib_entry being created, which |
| 1261 | * can inturn mean the pool is realloc'd and thus the entry passed as |
| 1262 | * an argument it also realloc'd |
| 1263 | * @return the original entry |
| 1264 | */ |
| 1265 | fib_entry_t * |
| 1266 | fib_entry_src_action_add (fib_entry_t *fib_entry, |
| 1267 | fib_source_t source, |
| 1268 | fib_entry_flag_t flags, |
| 1269 | const dpo_id_t *dpo) |
| 1270 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1271 | fib_entry_src_t *esrc; |
| 1272 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1273 | esrc = fib_entry_src_find_or_create(fib_entry, source, flags); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1274 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1275 | ASSERT(esrc->fes_ref_count < 255); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1276 | esrc->fes_ref_count++; |
| 1277 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1278 | if (flags != esrc->fes_entry_flags) |
| 1279 | { |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1280 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_flags_change, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1281 | (esrc, fib_entry, flags)); |
| 1282 | } |
| 1283 | esrc->fes_entry_flags = flags; |
| 1284 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1285 | if (1 != esrc->fes_ref_count) |
| 1286 | { |
| 1287 | /* |
| 1288 | * we only want to add the source on the 0->1 transition |
| 1289 | */ |
| 1290 | return (fib_entry); |
| 1291 | } |
| 1292 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1293 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_add, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1294 | (esrc, |
| 1295 | fib_entry, |
| 1296 | flags, |
| 1297 | fib_entry_get_dpo_proto(fib_entry), |
| 1298 | dpo)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1299 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1300 | esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED; |
| 1301 | |
| 1302 | fib_path_list_lock(esrc->fes_pl); |
| 1303 | |
| 1304 | /* |
| 1305 | * the source owns a lock on the entry |
| 1306 | */ |
| 1307 | fib_entry_lock(fib_entry_get_index(fib_entry)); |
| 1308 | |
| 1309 | return (fib_entry); |
| 1310 | } |
| 1311 | |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1312 | /* |
| 1313 | * fib_entry_src_action_update |
| 1314 | * |
| 1315 | * Adding a source can result in a new fib_entry being created, which |
| 1316 | * can inturn mean the pool is realloc'd and thus the entry passed as |
| 1317 | * an argument it also realloc'd |
| 1318 | * @return the original entry |
| 1319 | */ |
| 1320 | fib_entry_t * |
| 1321 | fib_entry_src_action_update (fib_entry_t *fib_entry, |
| 1322 | fib_source_t source, |
| 1323 | fib_entry_flag_t flags, |
| 1324 | const dpo_id_t *dpo) |
| 1325 | { |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1326 | fib_node_index_t old_path_list_index; |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1327 | fib_entry_src_t *esrc; |
| 1328 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1329 | esrc = fib_entry_src_find_or_create(fib_entry, source, flags); |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1330 | |
| 1331 | if (NULL == esrc) |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1332 | { |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1333 | return (fib_entry_src_action_add(fib_entry, source, flags, dpo)); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1334 | } |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1335 | |
| 1336 | old_path_list_index = esrc->fes_pl; |
| 1337 | esrc->fes_entry_flags = flags; |
| 1338 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1339 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_add, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1340 | (esrc, |
| 1341 | fib_entry, |
| 1342 | flags, |
| 1343 | fib_entry_get_dpo_proto(fib_entry), |
| 1344 | dpo)); |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1345 | |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1346 | esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED; |
| 1347 | |
| 1348 | fib_path_list_lock(esrc->fes_pl); |
| 1349 | fib_path_list_unlock(old_path_list_index); |
| 1350 | |
| 1351 | return (fib_entry); |
| 1352 | } |
| 1353 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1354 | fib_entry_src_flag_t |
| 1355 | fib_entry_src_action_remove_or_update_inherit (fib_entry_t *fib_entry, |
| 1356 | fib_source_t source) |
| 1357 | { |
| 1358 | fib_entry_src_t *esrc; |
| 1359 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1360 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1361 | |
| 1362 | if (NULL == esrc) |
| 1363 | return (FIB_ENTRY_SRC_FLAG_ACTIVE); |
| 1364 | |
| 1365 | if ((esrc->fes_entry_flags & FIB_ENTRY_FLAG_COVERED_INHERIT) && |
| 1366 | (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED)) |
| 1367 | { |
| 1368 | fib_entry_src_t *cover_src; |
| 1369 | fib_node_index_t coveri; |
| 1370 | fib_entry_t *cover; |
| 1371 | |
| 1372 | /* |
| 1373 | * this source was pushing inherited state, but so is its |
| 1374 | * cover. Now that this source is going away, we need to |
| 1375 | * pull the covers forwarding and use it to update the covereds. |
| 1376 | * Go grab the path-list from the cover, rather than start a walk from |
| 1377 | * the cover, so we don't recursively update this entry. |
| 1378 | */ |
| 1379 | coveri = fib_table_get_less_specific(fib_entry->fe_fib_index, |
| 1380 | &fib_entry->fe_prefix); |
| 1381 | |
| 1382 | /* |
| 1383 | * only the default route has itself as its own cover, but the |
| 1384 | * default route cannot have inherited from something else. |
| 1385 | */ |
| 1386 | ASSERT(coveri != fib_entry_get_index(fib_entry)); |
| 1387 | |
| 1388 | cover = fib_entry_get(coveri); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1389 | cover_src = fib_entry_src_find(cover, source); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1390 | |
| 1391 | ASSERT(NULL != cover_src); |
| 1392 | |
| 1393 | esrc = fib_entry_src_action_update_from_cover(fib_entry, cover_src); |
| 1394 | esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_COVERED_INHERIT; |
| 1395 | |
| 1396 | /* |
| 1397 | * Now push the new state from the cover down to the covereds |
| 1398 | */ |
| 1399 | fib_entry_src_covered_inherit_add(fib_entry, source); |
| 1400 | |
| 1401 | return (esrc->fes_flags); |
| 1402 | } |
| 1403 | else |
| 1404 | { |
| 1405 | return (fib_entry_src_action_remove(fib_entry, source)); |
| 1406 | } |
| 1407 | } |
Neale Ranns | 948e00f | 2016-10-20 13:39:34 +0100 | [diff] [blame] | 1408 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1409 | fib_entry_src_flag_t |
| 1410 | fib_entry_src_action_remove (fib_entry_t *fib_entry, |
| 1411 | fib_source_t source) |
| 1412 | |
| 1413 | { |
| 1414 | fib_node_index_t old_path_list; |
| 1415 | fib_entry_src_flag_t sflags; |
| 1416 | fib_entry_src_t *esrc; |
| 1417 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1418 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1419 | |
| 1420 | if (NULL == esrc) |
| 1421 | return (FIB_ENTRY_SRC_FLAG_ACTIVE); |
| 1422 | |
| 1423 | esrc->fes_ref_count--; |
| 1424 | sflags = esrc->fes_flags; |
| 1425 | |
| 1426 | if (0 != esrc->fes_ref_count) |
| 1427 | { |
| 1428 | /* |
| 1429 | * only remove the source on the 1->0 transisition |
| 1430 | */ |
| 1431 | return (sflags); |
| 1432 | } |
| 1433 | |
| 1434 | if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE) |
| 1435 | { |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1436 | fib_entry_src_action_deactivate(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1437 | } |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1438 | else if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_CONTRIBUTING) |
| 1439 | { |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1440 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_deactivate, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1441 | (esrc, fib_entry)); |
| 1442 | esrc->fes_flags &= ~FIB_ENTRY_SRC_FLAG_CONTRIBUTING; |
| 1443 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1444 | |
| 1445 | old_path_list = esrc->fes_pl; |
| 1446 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1447 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_remove, (esrc)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1448 | |
| 1449 | fib_path_list_unlock(old_path_list); |
| 1450 | fib_entry_unlock(fib_entry_get_index(fib_entry)); |
| 1451 | |
| 1452 | sflags &= ~FIB_ENTRY_SRC_FLAG_ADDED; |
| 1453 | fib_entry_src_action_deinit(fib_entry, source); |
| 1454 | |
| 1455 | return (sflags); |
| 1456 | } |
| 1457 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1458 | /* |
| 1459 | * fib_route_attached_cross_table |
| 1460 | * |
| 1461 | * Return true the the route is attached via an interface that |
| 1462 | * is not in the same table as the route |
| 1463 | */ |
Neale Ranns | 50bd1d3 | 2021-10-08 07:16:12 +0000 | [diff] [blame] | 1464 | static int |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1465 | fib_route_attached_cross_table (const fib_entry_t *fib_entry, |
| 1466 | const fib_route_path_t *rpath) |
| 1467 | { |
Neale Ranns | 66edaf2 | 2021-07-09 13:03:52 +0000 | [diff] [blame] | 1468 | const fib_prefix_t *pfx = &fib_entry->fe_prefix; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1469 | |
Neale Ranns | 66edaf2 | 2021-07-09 13:03:52 +0000 | [diff] [blame] | 1470 | switch (pfx->fp_proto) |
Neale Ranns | eca834e | 2018-03-13 07:51:50 -0700 | [diff] [blame] | 1471 | { |
Neale Ranns | 66edaf2 | 2021-07-09 13:03:52 +0000 | [diff] [blame] | 1472 | case FIB_PROTOCOL_MPLS: |
| 1473 | /* MPLS routes are never imported/exported */ |
| 1474 | return (0); |
| 1475 | case FIB_PROTOCOL_IP6: |
| 1476 | /* Ignore link local addresses these also can't be imported/exported */ |
| 1477 | if (ip6_address_is_link_local_unicast (&pfx->fp_addr.ip6)) |
| 1478 | { |
Neale Ranns | e3241f0 | 2021-12-19 15:10:20 +0000 | [diff] [blame] | 1479 | return (0); |
Neale Ranns | 66edaf2 | 2021-07-09 13:03:52 +0000 | [diff] [blame] | 1480 | } |
| 1481 | break; |
| 1482 | case FIB_PROTOCOL_IP4: |
| 1483 | break; |
Neale Ranns | eca834e | 2018-03-13 07:51:50 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | /* |
Neale Ranns | 66edaf2 | 2021-07-09 13:03:52 +0000 | [diff] [blame] | 1487 | * an attached path and entry's fib index not equal to interface's index |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1488 | */ |
Neale Ranns | 66edaf2 | 2021-07-09 13:03:52 +0000 | [diff] [blame] | 1489 | if (fib_route_path_is_attached(rpath) && |
| 1490 | fib_entry->fe_fib_index != |
| 1491 | fib_table_get_index_for_sw_if_index(fib_entry_get_proto(fib_entry), |
| 1492 | rpath->frp_sw_if_index)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1493 | { |
| 1494 | return (!0); |
| 1495 | } |
| 1496 | return (0); |
| 1497 | } |
| 1498 | |
| 1499 | fib_path_list_flags_t |
| 1500 | fib_entry_src_flags_2_path_list_flags (fib_entry_flag_t eflags) |
| 1501 | { |
| 1502 | fib_path_list_flags_t plf = FIB_PATH_LIST_FLAG_NONE; |
| 1503 | |
| 1504 | if (eflags & FIB_ENTRY_FLAG_DROP) |
| 1505 | { |
| 1506 | plf |= FIB_PATH_LIST_FLAG_DROP; |
| 1507 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1508 | if (eflags & FIB_ENTRY_FLAG_EXCLUSIVE) |
| 1509 | { |
| 1510 | plf |= FIB_PATH_LIST_FLAG_EXCLUSIVE; |
| 1511 | } |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 1512 | if (eflags & FIB_ENTRY_FLAG_LOCAL) |
| 1513 | { |
| 1514 | plf |= FIB_PATH_LIST_FLAG_LOCAL; |
| 1515 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1516 | |
| 1517 | return (plf); |
| 1518 | } |
| 1519 | |
| 1520 | static void |
| 1521 | fib_entry_flags_update (const fib_entry_t *fib_entry, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1522 | const fib_route_path_t *rpaths, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1523 | fib_path_list_flags_t *pl_flags, |
| 1524 | fib_entry_src_t *esrc) |
| 1525 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1526 | const fib_route_path_t *rpath; |
| 1527 | |
| 1528 | vec_foreach(rpath, rpaths) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1529 | { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1530 | if ((esrc->fes_src == FIB_SOURCE_API) || |
| 1531 | (esrc->fes_src == FIB_SOURCE_CLI)) |
| 1532 | { |
Neale Ranns | 66edaf2 | 2021-07-09 13:03:52 +0000 | [diff] [blame] | 1533 | if (fib_route_path_is_attached(rpath)) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1534 | { |
| 1535 | esrc->fes_entry_flags |= FIB_ENTRY_FLAG_ATTACHED; |
| 1536 | } |
| 1537 | else |
| 1538 | { |
| 1539 | esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_ATTACHED; |
| 1540 | } |
| 1541 | if (rpath->frp_flags & FIB_ROUTE_PATH_DEAG) |
| 1542 | { |
| 1543 | esrc->fes_entry_flags |= FIB_ENTRY_FLAG_LOOSE_URPF_EXEMPT; |
| 1544 | } |
Dmitry Valter | e95687b | 2023-12-20 10:47:35 +0000 | [diff] [blame] | 1545 | if (rpath->frp_flags & FIB_ROUTE_PATH_DROP) |
| 1546 | { |
| 1547 | esrc->fes_entry_flags |= FIB_ENTRY_FLAG_NO_ATTACHED_EXPORT; |
| 1548 | } |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1549 | } |
| 1550 | if (fib_route_attached_cross_table(fib_entry, rpath) && |
| 1551 | !(esrc->fes_entry_flags & FIB_ENTRY_FLAG_NO_ATTACHED_EXPORT)) |
| 1552 | { |
| 1553 | esrc->fes_entry_flags |= FIB_ENTRY_FLAG_IMPORT; |
| 1554 | } |
| 1555 | else |
| 1556 | { |
| 1557 | esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_IMPORT; |
| 1558 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1563 | * fib_entry_src_action_add |
| 1564 | * |
| 1565 | * Adding a source can result in a new fib_entry being created, which |
| 1566 | * can inturn mean the pool is realloc'd and thus the entry passed as |
| 1567 | * an argument it also realloc'd |
| 1568 | * @return the entry |
| 1569 | */ |
| 1570 | fib_entry_t* |
| 1571 | fib_entry_src_action_path_add (fib_entry_t *fib_entry, |
| 1572 | fib_source_t source, |
| 1573 | fib_entry_flag_t flags, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1574 | const fib_route_path_t *rpaths) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1575 | { |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1576 | fib_node_index_t old_path_list; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1577 | fib_path_list_flags_t pl_flags; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1578 | fib_entry_src_t *esrc; |
| 1579 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1580 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1581 | if (NULL == esrc) |
| 1582 | { |
Vijayabhaskar Katamreddy | 0c2319f | 2018-10-25 13:28:12 -0700 | [diff] [blame] | 1583 | const dpo_id_t *dpo; |
| 1584 | |
| 1585 | if (flags == FIB_ENTRY_FLAG_EXCLUSIVE) { |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1586 | dpo = &rpaths->dpo; |
Vijayabhaskar Katamreddy | 0c2319f | 2018-10-25 13:28:12 -0700 | [diff] [blame] | 1587 | } else { |
| 1588 | dpo = drop_dpo_get(fib_entry_get_dpo_proto(fib_entry)); |
| 1589 | } |
| 1590 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1591 | fib_entry = |
| 1592 | fib_entry_src_action_add(fib_entry, |
| 1593 | source, |
| 1594 | flags, |
Vijayabhaskar Katamreddy | 0c2319f | 2018-10-25 13:28:12 -0700 | [diff] [blame] | 1595 | dpo); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1596 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | /* |
| 1600 | * we are no doubt modifying a path-list. If the path-list |
| 1601 | * is shared, and hence not modifiable, then the index returned |
| 1602 | * will be for a different path-list. This FIB entry to needs |
| 1603 | * to maintain its lock appropriately. |
| 1604 | */ |
| 1605 | old_path_list = esrc->fes_pl; |
| 1606 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1607 | ASSERT(FIB_ENTRY_SRC_VFT_EXISTS(esrc, fesv_path_add)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1608 | |
| 1609 | pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry)); |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1610 | fib_entry_flags_update(fib_entry, rpaths, &pl_flags, esrc); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1611 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1612 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_path_add, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1613 | (esrc, fib_entry, pl_flags, rpaths)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1614 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1615 | fib_path_list_lock(esrc->fes_pl); |
| 1616 | fib_path_list_unlock(old_path_list); |
| 1617 | |
| 1618 | return (fib_entry); |
| 1619 | } |
| 1620 | |
| 1621 | /* |
| 1622 | * fib_entry_src_action_swap |
| 1623 | * |
| 1624 | * The source is providing new paths to replace the old ones. |
| 1625 | * Adding a source can result in a new fib_entry being created, which |
| 1626 | * can inturn mean the pool is realloc'd and thus the entry passed as |
| 1627 | * an argument it also realloc'd |
| 1628 | * @return the entry |
| 1629 | */ |
| 1630 | fib_entry_t* |
| 1631 | fib_entry_src_action_path_swap (fib_entry_t *fib_entry, |
| 1632 | fib_source_t source, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1633 | fib_entry_flag_t flags, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1634 | const fib_route_path_t *rpaths) |
| 1635 | { |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1636 | fib_node_index_t old_path_list; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1637 | fib_path_list_flags_t pl_flags; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1638 | fib_entry_src_t *esrc; |
| 1639 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1640 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1641 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1642 | if (NULL == esrc) |
| 1643 | { |
Vijayabhaskar Katamreddy | 0c2319f | 2018-10-25 13:28:12 -0700 | [diff] [blame] | 1644 | const dpo_id_t *dpo; |
| 1645 | |
| 1646 | if (flags == FIB_ENTRY_FLAG_EXCLUSIVE) { |
| 1647 | dpo = &rpaths->dpo; |
| 1648 | } else { |
| 1649 | dpo = drop_dpo_get(fib_entry_get_dpo_proto(fib_entry)); |
| 1650 | } |
| 1651 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1652 | fib_entry = fib_entry_src_action_add(fib_entry, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1653 | source, |
| 1654 | flags, |
Vijayabhaskar Katamreddy | 0c2319f | 2018-10-25 13:28:12 -0700 | [diff] [blame] | 1655 | dpo); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1656 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1657 | } |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1658 | else |
| 1659 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1660 | if (flags != esrc->fes_entry_flags) |
| 1661 | { |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1662 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_flags_change, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1663 | (esrc, fib_entry, flags)); |
| 1664 | } |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1665 | esrc->fes_entry_flags = flags; |
| 1666 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1667 | |
| 1668 | /* |
| 1669 | * swapping paths may create a new path-list (or may use an existing shared) |
| 1670 | * but we are certainly getting a different one. This FIB entry to needs |
| 1671 | * to maintain its lock appropriately. |
| 1672 | */ |
| 1673 | old_path_list = esrc->fes_pl; |
| 1674 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1675 | ASSERT(FIB_ENTRY_SRC_VFT_EXISTS(esrc, fesv_path_swap)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1676 | |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 1677 | pl_flags = fib_entry_src_flags_2_path_list_flags(flags); |
| 1678 | |
Neale Ranns | b5d61a9 | 2019-07-09 14:29:35 +0000 | [diff] [blame] | 1679 | fib_entry_flags_update(fib_entry, rpaths, &pl_flags, esrc); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1680 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1681 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_path_swap, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1682 | (esrc, fib_entry, |
| 1683 | pl_flags, rpaths)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1684 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1685 | fib_path_list_lock(esrc->fes_pl); |
| 1686 | fib_path_list_unlock(old_path_list); |
| 1687 | |
| 1688 | return (fib_entry); |
| 1689 | } |
| 1690 | |
| 1691 | fib_entry_src_flag_t |
| 1692 | fib_entry_src_action_path_remove (fib_entry_t *fib_entry, |
| 1693 | fib_source_t source, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1694 | const fib_route_path_t *rpaths) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1695 | { |
| 1696 | fib_path_list_flags_t pl_flags; |
| 1697 | fib_node_index_t old_path_list; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1698 | fib_entry_src_t *esrc; |
| 1699 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1700 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1701 | |
| 1702 | ASSERT(NULL != esrc); |
| 1703 | ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED); |
| 1704 | |
| 1705 | /* |
| 1706 | * we no doubt modifying a path-list. If the path-list |
| 1707 | * is shared, and hence not modifiable, then the index returned |
| 1708 | * will be for a different path-list. This FIB entry to needs |
| 1709 | * to maintain its lock appropriately. |
| 1710 | */ |
| 1711 | old_path_list = esrc->fes_pl; |
| 1712 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1713 | ASSERT(FIB_ENTRY_SRC_VFT_EXISTS(esrc, fesv_path_remove)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1714 | |
| 1715 | pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry)); |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1716 | fib_entry_flags_update(fib_entry, rpaths, &pl_flags, esrc); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1717 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1718 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_path_remove, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1719 | (esrc, pl_flags, rpaths)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1720 | |
| 1721 | /* |
| 1722 | * lock the new path-list, unlock the old if it had one |
| 1723 | */ |
| 1724 | fib_path_list_unlock(old_path_list); |
| 1725 | |
| 1726 | if (FIB_NODE_INDEX_INVALID != esrc->fes_pl) { |
| 1727 | fib_path_list_lock(esrc->fes_pl); |
| 1728 | return (FIB_ENTRY_SRC_FLAG_ADDED); |
| 1729 | } |
| 1730 | else |
| 1731 | { |
| 1732 | /* |
| 1733 | * no more paths left from this source |
| 1734 | */ |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 1735 | fib_entry_src_action_remove_or_update_inherit(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1736 | return (FIB_ENTRY_SRC_FLAG_NONE); |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | u8* |
| 1741 | fib_entry_src_format (fib_entry_t *fib_entry, |
| 1742 | fib_source_t source, |
| 1743 | u8* s) |
| 1744 | { |
| 1745 | fib_entry_src_t *esrc; |
| 1746 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1747 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1748 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1749 | FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_format, (esrc, s)); |
| 1750 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1751 | return (s); |
| 1752 | } |
| 1753 | |
| 1754 | adj_index_t |
| 1755 | fib_entry_get_adj_for_source (fib_node_index_t fib_entry_index, |
| 1756 | fib_source_t source) |
| 1757 | { |
| 1758 | fib_entry_t *fib_entry; |
| 1759 | fib_entry_src_t *esrc; |
| 1760 | |
| 1761 | if (FIB_NODE_INDEX_INVALID == fib_entry_index) |
| 1762 | return (ADJ_INDEX_INVALID); |
| 1763 | |
| 1764 | fib_entry = fib_entry_get(fib_entry_index); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1765 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1766 | |
| 1767 | if (NULL != esrc) |
| 1768 | { |
| 1769 | if (FIB_NODE_INDEX_INVALID != esrc->fes_pl) |
| 1770 | { |
| 1771 | return (fib_path_list_get_adj( |
| 1772 | esrc->fes_pl, |
| 1773 | fib_entry_get_default_chain_type(fib_entry))); |
| 1774 | } |
| 1775 | } |
| 1776 | return (ADJ_INDEX_INVALID); |
| 1777 | } |
| 1778 | |
| 1779 | const int |
| 1780 | fib_entry_get_dpo_for_source (fib_node_index_t fib_entry_index, |
| 1781 | fib_source_t source, |
| 1782 | dpo_id_t *dpo) |
| 1783 | { |
| 1784 | fib_entry_t *fib_entry; |
| 1785 | fib_entry_src_t *esrc; |
| 1786 | |
| 1787 | if (FIB_NODE_INDEX_INVALID == fib_entry_index) |
| 1788 | return (0); |
| 1789 | |
| 1790 | fib_entry = fib_entry_get(fib_entry_index); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1791 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1792 | |
| 1793 | if (NULL != esrc) |
| 1794 | { |
| 1795 | if (FIB_NODE_INDEX_INVALID != esrc->fes_pl) |
| 1796 | { |
| 1797 | fib_path_list_contribute_forwarding( |
| 1798 | esrc->fes_pl, |
| 1799 | fib_entry_get_default_chain_type(fib_entry), |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 1800 | FIB_PATH_LIST_FWD_FLAG_NONE, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1801 | dpo); |
| 1802 | |
| 1803 | return (dpo_id_is_valid(dpo)); |
| 1804 | } |
| 1805 | } |
| 1806 | return (0); |
| 1807 | } |
| 1808 | |
Damjan Marion | 9260b88 | 2022-10-04 18:08:51 +0200 | [diff] [blame] | 1809 | fib_node_index_t |
| 1810 | fib_entry_get_path_list_for_source (fib_node_index_t fib_entry_index, |
| 1811 | fib_source_t source) |
| 1812 | { |
| 1813 | fib_entry_t *fib_entry; |
| 1814 | fib_entry_src_t *esrc; |
| 1815 | |
| 1816 | if (FIB_NODE_INDEX_INVALID == fib_entry_index) |
| 1817 | return FIB_NODE_INDEX_INVALID; |
| 1818 | |
| 1819 | fib_entry = fib_entry_get(fib_entry_index); |
| 1820 | esrc = fib_entry_src_find(fib_entry, source); |
| 1821 | |
| 1822 | if (esrc) |
| 1823 | return esrc->fes_pl; |
| 1824 | |
| 1825 | return FIB_NODE_INDEX_INVALID; |
| 1826 | } |
| 1827 | |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 1828 | u32 |
| 1829 | fib_entry_get_resolving_interface_for_source (fib_node_index_t entry_index, |
| 1830 | fib_source_t source) |
| 1831 | { |
| 1832 | fib_entry_t *fib_entry; |
| 1833 | fib_entry_src_t *esrc; |
| 1834 | |
| 1835 | fib_entry = fib_entry_get(entry_index); |
| 1836 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1837 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 1838 | |
| 1839 | if (NULL != esrc) |
| 1840 | { |
| 1841 | if (FIB_NODE_INDEX_INVALID != esrc->fes_pl) |
| 1842 | { |
| 1843 | return (fib_path_list_get_resolving_interface(esrc->fes_pl)); |
| 1844 | } |
| 1845 | } |
| 1846 | return (~0); |
| 1847 | } |
| 1848 | |
| 1849 | fib_entry_flag_t |
| 1850 | fib_entry_get_flags_for_source (fib_node_index_t entry_index, |
| 1851 | fib_source_t source) |
| 1852 | { |
| 1853 | fib_entry_t *fib_entry; |
| 1854 | fib_entry_src_t *esrc; |
| 1855 | |
| 1856 | fib_entry = fib_entry_get(entry_index); |
| 1857 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1858 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | df089a8 | 2016-10-02 16:39:06 +0100 | [diff] [blame] | 1859 | |
| 1860 | if (NULL != esrc) |
| 1861 | { |
| 1862 | return (esrc->fes_entry_flags); |
| 1863 | } |
| 1864 | |
| 1865 | return (FIB_ENTRY_FLAG_NONE); |
| 1866 | } |
| 1867 | |
Benoît Ganne | 99c358d | 2019-07-17 14:47:23 +0200 | [diff] [blame] | 1868 | fib_source_t |
| 1869 | fib_entry_get_source_i (const fib_entry_t *fib_entry) |
| 1870 | { |
| 1871 | /* the vector of sources is deliberately arranged in priority order */ |
| 1872 | if (0 == vec_len(fib_entry->fe_srcs)) |
| 1873 | return (FIB_SOURCE_INVALID); |
| 1874 | return (vec_elt(fib_entry->fe_srcs, 0).fes_src); |
| 1875 | } |
| 1876 | |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 1877 | fib_entry_flag_t |
| 1878 | fib_entry_get_flags_i (const fib_entry_t *fib_entry) |
| 1879 | { |
Benoît Ganne | 99c358d | 2019-07-17 14:47:23 +0200 | [diff] [blame] | 1880 | /* the vector of sources is deliberately arranged in priority order */ |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 1881 | if (0 == vec_len(fib_entry->fe_srcs)) |
Benoît Ganne | 99c358d | 2019-07-17 14:47:23 +0200 | [diff] [blame] | 1882 | return (FIB_ENTRY_FLAG_NONE); |
| 1883 | return (vec_elt(fib_entry->fe_srcs, 0).fes_entry_flags); |
Neale Ranns | a4e7766 | 2017-12-04 20:00:30 +0000 | [diff] [blame] | 1884 | } |
| 1885 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1886 | void |
| 1887 | fib_entry_set_source_data (fib_node_index_t fib_entry_index, |
| 1888 | fib_source_t source, |
| 1889 | const void *data) |
| 1890 | { |
| 1891 | fib_entry_t *fib_entry; |
| 1892 | fib_entry_src_t *esrc; |
| 1893 | |
| 1894 | fib_entry = fib_entry_get(fib_entry_index); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1895 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1896 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1897 | if (NULL != esrc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1898 | { |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 1899 | FIB_ENTRY_SRC_VFT_INVOKE(fib_entry, esrc, fesv_set_data, |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1900 | (esrc, fib_entry, data)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1901 | } |
| 1902 | } |
| 1903 | |
| 1904 | const void* |
| 1905 | fib_entry_get_source_data (fib_node_index_t fib_entry_index, |
| 1906 | fib_source_t source) |
| 1907 | { |
| 1908 | fib_entry_t *fib_entry; |
| 1909 | fib_entry_src_t *esrc; |
| 1910 | |
| 1911 | fib_entry = fib_entry_get(fib_entry_index); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1912 | esrc = fib_entry_src_find(fib_entry, source); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1913 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1914 | if (NULL != esrc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1915 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1916 | FIB_ENTRY_SRC_VFT_INVOKE_AND_RETURN(esrc, fesv_get_data, |
| 1917 | (esrc, fib_entry)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1918 | } |
| 1919 | return (NULL); |
| 1920 | } |
| 1921 | |
| 1922 | void |
| 1923 | fib_entry_src_module_init (void) |
| 1924 | { |
| 1925 | fib_entry_src_rr_register(); |
| 1926 | fib_entry_src_interface_register(); |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 1927 | fib_entry_src_interpose_register(); |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 1928 | fib_entry_src_drop_register(); |
| 1929 | fib_entry_src_simple_register(); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1930 | fib_entry_src_api_register(); |
| 1931 | fib_entry_src_adj_register(); |
| 1932 | fib_entry_src_mpls_register(); |
| 1933 | fib_entry_src_lisp_register(); |
| 1934 | } |