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 | /** |
| 17 | * Given a route of the form; |
| 18 | * q.r.s.t/Y |
| 19 | * via <interface> <next-hop> |
| 20 | * |
| 21 | * The prefix is: q.r.s.t./Y |
| 22 | * the path is: 'via <interface> <next-hop> |
| 23 | * |
| 24 | * The path is the description of where to send the traffic, and the |
| 25 | * the prefix is a description of which traffic to send. |
| 26 | * It is the aim of the FIB to resolve the path, i.e. to find the corresponding |
| 27 | * adjacency to match the path's description. |
| 28 | */ |
| 29 | |
| 30 | #ifndef __FIB_PATH_H__ |
| 31 | #define __FIB_PATH_H__ |
| 32 | |
| 33 | #include <vnet/ip/ip.h> |
| 34 | #include <vnet/dpo/load_balance.h> |
| 35 | |
| 36 | #include <vnet/fib/fib_types.h> |
| 37 | #include <vnet/adj/adj_types.h> |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 38 | #include <vnet/bier/bier_types.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 39 | |
| 40 | /** |
| 41 | * Enurmeration of path configuration attributes |
| 42 | */ |
| 43 | typedef enum fib_path_cfg_attribute_t_ { |
| 44 | /** |
| 45 | * Marker. Add new types after this one. |
| 46 | */ |
| 47 | FIB_PATH_CFG_ATTRIBUTE_FIRST = 0, |
| 48 | /** |
| 49 | * The path is forced to a drop, whatever the next-hop info says. |
| 50 | * something somewhere knows better... |
| 51 | */ |
| 52 | FIB_PATH_CFG_ATTRIBUTE_DROP = FIB_PATH_CFG_ATTRIBUTE_FIRST, |
| 53 | /** |
| 54 | * The path uses an adj that is exclusive. I.e. it is known only by |
| 55 | * the source of the route. |
| 56 | */ |
| 57 | FIB_PATH_CFG_ATTRIBUTE_EXCLUSIVE, |
| 58 | /** |
| 59 | * Recursion constraint via host |
| 60 | */ |
| 61 | FIB_PATH_CFG_ATTRIBUTE_RESOLVE_HOST, |
| 62 | /** |
| 63 | * Recursion constraint via attached |
| 64 | */ |
| 65 | FIB_PATH_CFG_ATTRIBUTE_RESOLVE_ATTACHED, |
| 66 | /** |
Neale Ranns | 4b919a5 | 2017-03-11 05:55:21 -0800 | [diff] [blame] | 67 | * The path is attached |
| 68 | */ |
| 69 | FIB_PATH_CFG_ATTRIBUTE_ATTACHED, |
| 70 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 71 | * The path is a for-us path |
| 72 | */ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 73 | FIB_PATH_CFG_ATTRIBUTE_INTF_RX, |
| 74 | /** |
| 75 | * The path is a deag with rpf-id |
| 76 | */ |
| 77 | FIB_PATH_CFG_ATTRIBUTE_RPF_ID, |
| 78 | /** |
| 79 | * The path is an interface recieve |
| 80 | */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 81 | FIB_PATH_CFG_ATTRIBUTE_LOCAL, |
| 82 | /** |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 83 | * The path reolves via an ICMP unreachable |
| 84 | */ |
| 85 | FIB_PATH_CFG_ATTRIBUTE_ICMP_UNREACH, |
| 86 | /** |
| 87 | * The path reolves via an ICMP prohibit |
| 88 | */ |
| 89 | FIB_PATH_CFG_ATTRIBUTE_ICMP_PROHIBIT, |
| 90 | /** |
| 91 | * The path reolves via a classify |
| 92 | */ |
| 93 | FIB_PATH_CFG_ATTRIBUTE_CLASSIFY, |
| 94 | /** |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 95 | * The deag path does a source lookup |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 96 | */ |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 97 | FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 98 | /** |
Neale Ranns | 1dbcf30 | 2019-07-19 11:44:53 +0000 | [diff] [blame] | 99 | * The path pops a Psuedo Wire Control Word |
| 100 | */ |
| 101 | FIB_PATH_CFG_ATTRIBUTE_POP_PW_CW, |
| 102 | /** |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 103 | * The path is a glean |
| 104 | */ |
| 105 | FIB_PATH_CFG_ATTRIBUTE_GLEAN, |
| 106 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 107 | * Marker. Add new types before this one, then update it. |
| 108 | */ |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 109 | FIB_PATH_CFG_ATTRIBUTE_LAST = FIB_PATH_CFG_ATTRIBUTE_GLEAN, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 110 | } __attribute__ ((packed)) fib_path_cfg_attribute_t; |
| 111 | |
| 112 | /** |
| 113 | * The maximum number of path attributes |
| 114 | */ |
| 115 | #define FIB_PATH_CFG_ATTRIBUTE_MAX (FIB_PATH_CFG_ATTRIBUTE_LAST + 1) |
| 116 | |
| 117 | #define FIB_PATH_CFG_ATTRIBUTES { \ |
| 118 | [FIB_PATH_CFG_ATTRIBUTE_DROP] = "drop", \ |
| 119 | [FIB_PATH_CFG_ATTRIBUTE_EXCLUSIVE] = "exclusive", \ |
| 120 | [FIB_PATH_CFG_ATTRIBUTE_RESOLVE_HOST] = "resolve-host", \ |
| 121 | [FIB_PATH_CFG_ATTRIBUTE_RESOLVE_ATTACHED] = "resolve-attached", \ |
| 122 | [FIB_PATH_CFG_ATTRIBUTE_LOCAL] = "local", \ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 123 | [FIB_PATH_CFG_ATTRIBUTE_ICMP_UNREACH] = "icmp-unreach", \ |
| 124 | [FIB_PATH_CFG_ATTRIBUTE_ICMP_PROHIBIT] = "icmp-prohibit", \ |
| 125 | [FIB_PATH_CFG_ATTRIBUTE_CLASSIFY] = "classify", \ |
Neale Ranns | 4b919a5 | 2017-03-11 05:55:21 -0800 | [diff] [blame] | 126 | [FIB_PATH_CFG_ATTRIBUTE_ATTACHED] = "attached", \ |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 127 | [FIB_PATH_CFG_ATTRIBUTE_INTF_RX] = "interface-rx", \ |
| 128 | [FIB_PATH_CFG_ATTRIBUTE_RPF_ID] = "rpf-id", \ |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 129 | [FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC] = "deag-src", \ |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 130 | [FIB_PATH_CFG_ATTRIBUTE_POP_PW_CW] = "pop-pw-cw", \ |
| 131 | [FIB_PATH_CFG_ATTRIBUTE_GLEAN] = "glean", \ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | #define FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(_item) \ |
| 135 | for (_item = FIB_PATH_CFG_ATTRIBUTE_FIRST; \ |
| 136 | _item <= FIB_PATH_CFG_ATTRIBUTE_LAST; \ |
| 137 | _item++) |
| 138 | |
| 139 | /** |
| 140 | * Path config flags from the attributes |
| 141 | */ |
| 142 | typedef enum fib_path_cfg_flags_t_ { |
| 143 | FIB_PATH_CFG_FLAG_NONE = 0, |
| 144 | FIB_PATH_CFG_FLAG_DROP = (1 << FIB_PATH_CFG_ATTRIBUTE_DROP), |
| 145 | FIB_PATH_CFG_FLAG_EXCLUSIVE = (1 << FIB_PATH_CFG_ATTRIBUTE_EXCLUSIVE), |
| 146 | FIB_PATH_CFG_FLAG_RESOLVE_HOST = (1 << FIB_PATH_CFG_ATTRIBUTE_RESOLVE_HOST), |
| 147 | FIB_PATH_CFG_FLAG_RESOLVE_ATTACHED = (1 << FIB_PATH_CFG_ATTRIBUTE_RESOLVE_ATTACHED), |
| 148 | FIB_PATH_CFG_FLAG_LOCAL = (1 << FIB_PATH_CFG_ATTRIBUTE_LOCAL), |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 149 | FIB_PATH_CFG_FLAG_ICMP_UNREACH = (1 << FIB_PATH_CFG_ATTRIBUTE_ICMP_UNREACH), |
| 150 | FIB_PATH_CFG_FLAG_ICMP_PROHIBIT = (1 << FIB_PATH_CFG_ATTRIBUTE_ICMP_PROHIBIT), |
| 151 | FIB_PATH_CFG_FLAG_CLASSIFY = (1 << FIB_PATH_CFG_ATTRIBUTE_CLASSIFY), |
Neale Ranns | 4b919a5 | 2017-03-11 05:55:21 -0800 | [diff] [blame] | 152 | FIB_PATH_CFG_FLAG_ATTACHED = (1 << FIB_PATH_CFG_ATTRIBUTE_ATTACHED), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 153 | FIB_PATH_CFG_FLAG_INTF_RX = (1 << FIB_PATH_CFG_ATTRIBUTE_INTF_RX), |
| 154 | FIB_PATH_CFG_FLAG_RPF_ID = (1 << FIB_PATH_CFG_ATTRIBUTE_RPF_ID), |
Neale Ranns | 054c03a | 2017-10-13 05:15:07 -0700 | [diff] [blame] | 155 | FIB_PATH_CFG_FLAG_DEAG_SRC = (1 << FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC), |
Neale Ranns | 1dbcf30 | 2019-07-19 11:44:53 +0000 | [diff] [blame] | 156 | FIB_PATH_CFG_FLAG_POP_PW_CW = (1 << FIB_PATH_CFG_ATTRIBUTE_POP_PW_CW), |
Neale Ranns | e2fe097 | 2020-11-26 08:37:27 +0000 | [diff] [blame] | 157 | FIB_PATH_CFG_FLAG_GLEAN = (1 << FIB_PATH_CFG_ATTRIBUTE_GLEAN), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 158 | } __attribute__ ((packed)) fib_path_cfg_flags_t; |
| 159 | |
Neale Ranns | 710071b | 2018-09-24 12:36:26 +0000 | [diff] [blame] | 160 | typedef enum fib_path_format_flags_t_ |
| 161 | { |
| 162 | FIB_PATH_FORMAT_FLAGS_NONE = 0, |
| 163 | FIB_PATH_FORMAT_FLAGS_ONE_LINE = (1 << 0), |
| 164 | } fib_format_path_flags_t; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 165 | |
Neale Ranns | 9128637 | 2017-12-05 13:24:04 -0800 | [diff] [blame] | 166 | extern u8 *format_fib_path(u8 *s, va_list *args); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 167 | |
| 168 | extern fib_node_index_t fib_path_create(fib_node_index_t pl_index, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 169 | const fib_route_path_t *path); |
| 170 | extern fib_node_index_t fib_path_create_special(fib_node_index_t pl_index, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 171 | dpo_proto_t nh_proto, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 172 | fib_path_cfg_flags_t flags, |
| 173 | const dpo_id_t *dpo); |
| 174 | |
| 175 | extern int fib_path_cmp(fib_node_index_t path_index1, |
| 176 | fib_node_index_t path_index2); |
| 177 | extern int fib_path_cmp_for_sort(void * a1, void * a2); |
| 178 | extern int fib_path_cmp_w_route_path(fib_node_index_t path_index, |
| 179 | const fib_route_path_t *rpath); |
| 180 | extern fib_node_index_t fib_path_copy(fib_node_index_t path_index, |
| 181 | fib_node_index_t path_list_index); |
| 182 | extern int fib_path_resolve(fib_node_index_t path_index); |
| 183 | extern int fib_path_is_resolved(fib_node_index_t path_index); |
Neale Ranns | f12a83f | 2017-04-18 09:09:40 -0700 | [diff] [blame] | 184 | extern int fib_path_is_recursive_constrained(fib_node_index_t path_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 185 | extern int fib_path_is_exclusive(fib_node_index_t path_index); |
| 186 | extern int fib_path_is_deag(fib_node_index_t path_index); |
| 187 | extern int fib_path_is_looped(fib_node_index_t path_index); |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 188 | extern dpo_proto_t fib_path_get_proto(fib_node_index_t path_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 189 | extern void fib_path_destroy(fib_node_index_t path_index); |
| 190 | extern uword fib_path_hash(fib_node_index_t path_index); |
| 191 | extern load_balance_path_t * fib_path_append_nh_for_multipath_hash( |
| 192 | fib_node_index_t path_index, |
| 193 | fib_forward_chain_type_t fct, |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 194 | dpo_proto_t payload_proto, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 195 | load_balance_path_t *hash_key); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 196 | extern void fib_path_stack_mpls_disp(fib_node_index_t path_index, |
| 197 | dpo_proto_t payload_proto, |
Neale Ranns | 31ed744 | 2018-02-23 05:29:09 -0800 | [diff] [blame] | 198 | fib_mpls_lsp_mode_t mode, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 199 | dpo_id_t *dpo); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 200 | extern void fib_path_contribute_forwarding(fib_node_index_t path_index, |
| 201 | fib_forward_chain_type_t type, |
Neale Ranns | 53962fb | 2021-12-20 18:18:42 +0000 | [diff] [blame] | 202 | dpo_proto_t payload_proto, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 203 | dpo_id_t *dpo); |
Neale Ranns | 3ee4404 | 2016-10-03 13:05:48 +0100 | [diff] [blame] | 204 | extern void fib_path_contribute_urpf(fib_node_index_t path_index, |
| 205 | index_t urpf); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 206 | extern adj_index_t fib_path_get_adj(fib_node_index_t path_index); |
| 207 | extern int fib_path_recursive_loop_detect(fib_node_index_t path_index, |
| 208 | fib_node_index_t **entry_indicies); |
| 209 | extern u32 fib_path_get_resolving_interface(fib_node_index_t fib_entry_index); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 210 | extern index_t fib_path_get_resolving_index(fib_node_index_t path_index); |
Neale Ranns | 57b5860 | 2017-07-15 07:37:25 -0700 | [diff] [blame] | 211 | extern u16 fib_path_get_weight(fib_node_index_t path_index); |
| 212 | extern u16 fib_path_get_preference(fib_node_index_t path_index); |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 213 | extern u32 fib_path_get_rpf_id(fib_node_index_t path_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 214 | |
| 215 | extern void fib_path_module_init(void); |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * Path encode context to use when walking a path-list |
| 219 | * to encode paths |
| 220 | */ |
| 221 | typedef struct fib_path_encode_ctx_t_ |
| 222 | { |
| 223 | fib_route_path_t *rpaths; |
| 224 | } fib_path_encode_ctx_t; |
| 225 | |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 226 | extern fib_path_list_walk_rc_t fib_path_encode(fib_node_index_t path_list_index, |
| 227 | fib_node_index_t path_index, |
Neale Ranns | 775f73c | 2018-12-20 03:01:49 -0800 | [diff] [blame] | 228 | const struct fib_path_ext_t_ *ext_list, |
Neale Ranns | 8142499 | 2017-05-18 03:03:22 -0700 | [diff] [blame] | 229 | void *ctx); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 230 | |
| 231 | #endif |