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 "fib_entry.h" |
| 17 | #include "fib_entry_src.h" |
| 18 | #include "fib_path_list.h" |
| 19 | #include "fib_internal.h" |
| 20 | #include "fib_table.h" |
| 21 | #include "fib_entry_cover.h" |
| 22 | #include "fib_attached_export.h" |
| 23 | |
| 24 | /** |
| 25 | * Source initialisation Function |
| 26 | */ |
| 27 | static void |
| 28 | fib_entry_src_interface_init (fib_entry_src_t *src) |
| 29 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 30 | src->u.interface.fesi_cover = FIB_NODE_INDEX_INVALID; |
| 31 | src->u.interface.fesi_sibling = FIB_NODE_INDEX_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static void |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 35 | fib_entry_src_interface_add (fib_entry_src_t *src, |
| 36 | const fib_entry_t *entry, |
| 37 | fib_entry_flag_t flags, |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 38 | dpo_proto_t proto, |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 39 | const dpo_id_t *dpo) |
| 40 | { |
| 41 | src->fes_pl = fib_path_list_create_special( |
| 42 | proto, |
| 43 | fib_entry_src_flags_2_path_list_flags(flags), |
| 44 | dpo); |
| 45 | } |
| 46 | |
| 47 | static void |
| 48 | fib_entry_src_interface_remove (fib_entry_src_t *src) |
| 49 | { |
| 50 | src->fes_pl = FIB_NODE_INDEX_INVALID; |
| 51 | } |
| 52 | |
| 53 | static void |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 54 | fib_entry_src_interface_path_swap (fib_entry_src_t *src, |
| 55 | const fib_entry_t *entry, |
| 56 | fib_path_list_flags_t pl_flags, |
| 57 | const fib_route_path_t *paths) |
| 58 | { |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 59 | fib_node_index_t fib_entry_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 60 | ip_adjacency_t *adj; |
| 61 | |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 62 | fib_entry_index = fib_entry_get_index(entry); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 63 | src->fes_pl = fib_path_list_create(pl_flags, paths); |
| 64 | |
| 65 | /* |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 66 | * this is a hack to get the entry's prefix into the glean adjacency |
| 67 | * so that it is available for fast retrieval in the switch path. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 68 | */ |
| 69 | if (!(FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags)) |
| 70 | { |
Neale Ranns | 3fd9904 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 71 | adj_index_t ai; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 72 | |
Neale Ranns | 3fd9904 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 73 | ai = fib_path_list_get_adj(src->fes_pl, |
Neale Ranns | 6ede570 | 2020-02-13 09:12:36 +0000 | [diff] [blame] | 74 | fib_entry_get_default_chain_type( |
| 75 | fib_entry_get(fib_entry_index))); |
Neale Ranns | 3fd9904 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 76 | if (INDEX_INVALID != ai) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 77 | { |
Neale Ranns | 3fd9904 | 2019-12-16 00:53:11 +0000 | [diff] [blame] | 78 | adj = adj_get(ai); |
| 79 | |
| 80 | if (IP_LOOKUP_NEXT_GLEAN == adj->lookup_next_index) |
| 81 | { |
| 82 | /* |
| 83 | * the connected prefix will link to a glean on a non-p2p |
| 84 | * u.interface. |
| 85 | */ |
| 86 | adj->sub_type.glean.receive_addr = entry->fe_prefix.fp_addr; |
| 87 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | /* |
| 93 | * Source activate. |
| 94 | * Called when the source is teh new longer best source on the entry |
| 95 | */ |
| 96 | static int |
| 97 | fib_entry_src_interface_activate (fib_entry_src_t *src, |
| 98 | const fib_entry_t *fib_entry) |
| 99 | { |
| 100 | fib_entry_t *cover; |
| 101 | |
| 102 | if (FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags) |
| 103 | { |
| 104 | /* |
| 105 | * Track the covering attached/connected cover. This is so that |
| 106 | * during an attached export of the cover, this local prefix is |
| 107 | * also exported |
| 108 | */ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 109 | src->u.interface.fesi_cover = |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 110 | fib_table_get_less_specific(fib_entry->fe_fib_index, |
| 111 | &fib_entry->fe_prefix); |
| 112 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 113 | ASSERT(FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 114 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 115 | cover = fib_entry_get(src->u.interface.fesi_cover); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 116 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 117 | src->u.interface.fesi_sibling = |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 118 | fib_entry_cover_track(cover, fib_entry_get_index(fib_entry)); |
| 119 | } |
| 120 | |
| 121 | return (!0); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | /* |
| 126 | * Source Deactivate. |
| 127 | * Called when the source is no longer best source on the entry |
| 128 | */ |
| 129 | static void |
| 130 | fib_entry_src_interface_deactivate (fib_entry_src_t *src, |
| 131 | const fib_entry_t *fib_entry) |
| 132 | { |
| 133 | fib_entry_t *cover; |
| 134 | |
| 135 | /* |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 136 | * remove the dependency on the covering entry |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 137 | */ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 138 | if (FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 139 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 140 | cover = fib_entry_get(src->u.interface.fesi_cover); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 141 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 142 | fib_entry_cover_untrack(cover, src->u.interface.fesi_sibling); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 143 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 144 | src->u.interface.fesi_cover = FIB_NODE_INDEX_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
| 148 | static fib_entry_src_cover_res_t |
| 149 | fib_entry_src_interface_cover_change (fib_entry_src_t *src, |
| 150 | const fib_entry_t *fib_entry) |
| 151 | { |
| 152 | fib_entry_src_cover_res_t res = { |
| 153 | .install = !0, |
| 154 | .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE, |
| 155 | }; |
| 156 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 157 | if (FIB_NODE_INDEX_INVALID == src->u.interface.fesi_cover) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 158 | { |
| 159 | /* |
| 160 | * not tracking the cover. surprised we got poked? |
| 161 | */ |
| 162 | return (res); |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * this function is called when this entry's cover has a more specific |
| 167 | * entry inserted benaeth it. That does not necessarily mean that this |
| 168 | * entry is covered by the new prefix. check that |
| 169 | */ |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 170 | if (src->u.interface.fesi_cover != |
| 171 | fib_table_get_less_specific(fib_entry->fe_fib_index, |
| 172 | &fib_entry->fe_prefix)) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 173 | { |
| 174 | fib_entry_src_interface_deactivate(src, fib_entry); |
| 175 | fib_entry_src_interface_activate(src, fib_entry); |
| 176 | } |
| 177 | return (res); |
| 178 | } |
| 179 | |
| 180 | static void |
| 181 | fib_entry_src_interface_installed (fib_entry_src_t *src, |
| 182 | const fib_entry_t *fib_entry) |
| 183 | { |
| 184 | /* |
| 185 | * The interface source now rules! poke our cover to get exported |
| 186 | */ |
| 187 | fib_entry_t *cover; |
| 188 | |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 189 | if (FIB_NODE_INDEX_INVALID != src->u.interface.fesi_cover) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 190 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 191 | cover = fib_entry_get(src->u.interface.fesi_cover); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 192 | |
| 193 | fib_attached_export_covered_added(cover, |
| 194 | fib_entry_get_index(fib_entry)); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | static u8* |
| 199 | fib_entry_src_interface_format (fib_entry_src_t *src, |
| 200 | u8* s) |
| 201 | { |
Neale Ranns | 2303cb1 | 2018-02-21 04:57:17 -0800 | [diff] [blame] | 202 | return (format(s, " cover:%d", src->u.interface.fesi_cover)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | const static fib_entry_src_vft_t interface_src_vft = { |
| 206 | .fesv_init = fib_entry_src_interface_init, |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 207 | .fesv_add = fib_entry_src_interface_add, |
| 208 | .fesv_remove = fib_entry_src_interface_remove, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 209 | .fesv_path_swap = fib_entry_src_interface_path_swap, |
| 210 | .fesv_activate = fib_entry_src_interface_activate, |
| 211 | .fesv_deactivate = fib_entry_src_interface_deactivate, |
| 212 | .fesv_format = fib_entry_src_interface_format, |
| 213 | .fesv_installed = fib_entry_src_interface_installed, |
| 214 | .fesv_cover_change = fib_entry_src_interface_cover_change, |
| 215 | /* |
| 216 | * not concerned about updates to the cover. the cover will |
| 217 | * decide to export or not |
| 218 | */ |
| 219 | }; |
| 220 | |
| 221 | void |
| 222 | fib_entry_src_interface_register (void) |
| 223 | { |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 224 | fib_entry_src_behaviour_register(FIB_SOURCE_BH_INTERFACE, |
| 225 | &interface_src_vft); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 226 | } |