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