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