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 | { |
| 30 | src->interface.fesi_cover = FIB_NODE_INDEX_INVALID; |
| 31 | src->interface.fesi_sibling = FIB_NODE_INDEX_INVALID; |
| 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 | { |
| 59 | ip_adjacency_t *adj; |
| 60 | |
| 61 | src->fes_pl = fib_path_list_create(pl_flags, paths); |
| 62 | |
| 63 | /* |
| 64 | * this is a hack to get the entry's prefix into the glean adjacnecy |
| 65 | * so that it is available for fast retreival in the switch path. |
| 66 | */ |
| 67 | if (!(FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags)) |
| 68 | { |
| 69 | adj = adj_get(fib_path_list_get_adj( |
| 70 | src->fes_pl, |
| 71 | fib_entry_get_default_chain_type(entry))); |
| 72 | |
Neale Ranns | 5899fde | 2016-10-12 13:51:05 +0100 | [diff] [blame] | 73 | if (IP_LOOKUP_NEXT_GLEAN == adj->lookup_next_index) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 74 | { |
| 75 | /* |
| 76 | * the connected prefix will link to a glean on a non-p2p |
| 77 | * interface. |
| 78 | */ |
| 79 | adj->sub_type.glean.receive_addr = entry->fe_prefix.fp_addr; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * Source activate. |
| 86 | * Called when the source is teh new longer best source on the entry |
| 87 | */ |
| 88 | static int |
| 89 | fib_entry_src_interface_activate (fib_entry_src_t *src, |
| 90 | const fib_entry_t *fib_entry) |
| 91 | { |
| 92 | fib_entry_t *cover; |
| 93 | |
| 94 | if (FIB_ENTRY_FLAG_LOCAL & src->fes_entry_flags) |
| 95 | { |
| 96 | /* |
| 97 | * Track the covering attached/connected cover. This is so that |
| 98 | * during an attached export of the cover, this local prefix is |
| 99 | * also exported |
| 100 | */ |
| 101 | src->interface.fesi_cover = |
| 102 | fib_table_get_less_specific(fib_entry->fe_fib_index, |
| 103 | &fib_entry->fe_prefix); |
| 104 | |
| 105 | ASSERT(FIB_NODE_INDEX_INVALID != src->interface.fesi_cover); |
| 106 | |
| 107 | cover = fib_entry_get(src->interface.fesi_cover); |
| 108 | |
| 109 | src->interface.fesi_sibling = |
| 110 | fib_entry_cover_track(cover, fib_entry_get_index(fib_entry)); |
| 111 | } |
| 112 | |
| 113 | return (!0); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | /* |
| 118 | * Source Deactivate. |
| 119 | * Called when the source is no longer best source on the entry |
| 120 | */ |
| 121 | static void |
| 122 | fib_entry_src_interface_deactivate (fib_entry_src_t *src, |
| 123 | const fib_entry_t *fib_entry) |
| 124 | { |
| 125 | fib_entry_t *cover; |
| 126 | |
| 127 | /* |
| 128 | * remove the depednecy on the covering entry |
| 129 | */ |
| 130 | if (FIB_NODE_INDEX_INVALID != src->interface.fesi_cover) |
| 131 | { |
| 132 | cover = fib_entry_get(src->interface.fesi_cover); |
| 133 | |
| 134 | fib_entry_cover_untrack(cover, src->interface.fesi_sibling); |
| 135 | |
| 136 | src->interface.fesi_cover = FIB_NODE_INDEX_INVALID; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | static fib_entry_src_cover_res_t |
| 141 | fib_entry_src_interface_cover_change (fib_entry_src_t *src, |
| 142 | const fib_entry_t *fib_entry) |
| 143 | { |
| 144 | fib_entry_src_cover_res_t res = { |
| 145 | .install = !0, |
| 146 | .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE, |
| 147 | }; |
| 148 | |
| 149 | if (FIB_NODE_INDEX_INVALID == src->interface.fesi_cover) |
| 150 | { |
| 151 | /* |
| 152 | * not tracking the cover. surprised we got poked? |
| 153 | */ |
| 154 | return (res); |
| 155 | } |
| 156 | |
| 157 | /* |
| 158 | * this function is called when this entry's cover has a more specific |
| 159 | * entry inserted benaeth it. That does not necessarily mean that this |
| 160 | * entry is covered by the new prefix. check that |
| 161 | */ |
| 162 | if (src->rr.fesr_cover != fib_table_get_less_specific(fib_entry->fe_fib_index, |
| 163 | &fib_entry->fe_prefix)) |
| 164 | { |
| 165 | fib_entry_src_interface_deactivate(src, fib_entry); |
| 166 | fib_entry_src_interface_activate(src, fib_entry); |
| 167 | } |
| 168 | return (res); |
| 169 | } |
| 170 | |
| 171 | static void |
| 172 | fib_entry_src_interface_installed (fib_entry_src_t *src, |
| 173 | const fib_entry_t *fib_entry) |
| 174 | { |
| 175 | /* |
| 176 | * The interface source now rules! poke our cover to get exported |
| 177 | */ |
| 178 | fib_entry_t *cover; |
| 179 | |
| 180 | if (FIB_NODE_INDEX_INVALID != src->interface.fesi_cover) |
| 181 | { |
| 182 | cover = fib_entry_get(src->interface.fesi_cover); |
| 183 | |
| 184 | fib_attached_export_covered_added(cover, |
| 185 | fib_entry_get_index(fib_entry)); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | static u8* |
| 190 | fib_entry_src_interface_format (fib_entry_src_t *src, |
| 191 | u8* s) |
| 192 | { |
| 193 | return (format(s, "cover:%d", src->interface.fesi_cover)); |
| 194 | } |
| 195 | |
| 196 | const static fib_entry_src_vft_t interface_src_vft = { |
| 197 | .fesv_init = fib_entry_src_interface_init, |
Neale Ranns | 9a69a60 | 2017-03-26 10:56:33 -0700 | [diff] [blame] | 198 | .fesv_add = fib_entry_src_interface_add, |
| 199 | .fesv_remove = fib_entry_src_interface_remove, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 200 | .fesv_path_swap = fib_entry_src_interface_path_swap, |
| 201 | .fesv_activate = fib_entry_src_interface_activate, |
| 202 | .fesv_deactivate = fib_entry_src_interface_deactivate, |
| 203 | .fesv_format = fib_entry_src_interface_format, |
| 204 | .fesv_installed = fib_entry_src_interface_installed, |
| 205 | .fesv_cover_change = fib_entry_src_interface_cover_change, |
| 206 | /* |
| 207 | * not concerned about updates to the cover. the cover will |
| 208 | * decide to export or not |
| 209 | */ |
| 210 | }; |
| 211 | |
| 212 | void |
| 213 | fib_entry_src_interface_register (void) |
| 214 | { |
| 215 | fib_entry_src_register(FIB_SOURCE_INTERFACE, &interface_src_vft); |
| 216 | } |