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_nbr.h> |
| 17 | #include <vnet/adj/adj_internal.h> |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 18 | #include <vnet/adj/adj_l2.h> |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 19 | #include <vnet/adj/adj_nsh.h> |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 20 | #include <vnet/adj/adj_midchain.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 21 | #include <vnet/dpo/drop_dpo.h> |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 22 | #include <vnet/dpo/load_balance.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 23 | #include <vnet/fib/fib_walk.h> |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 24 | #include <vnet/fib/fib_entry.h> |
Neale Ranns | e403113 | 2020-10-26 13:00:06 +0000 | [diff] [blame] | 25 | #include <vnet/ip/ip4_inlines.h> |
| 26 | #include <vnet/ip/ip6_inlines.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 27 | |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 28 | u8 |
| 29 | adj_is_midchain (adj_index_t ai) |
| 30 | { |
| 31 | ip_adjacency_t *adj; |
| 32 | |
| 33 | adj = adj_get(ai); |
| 34 | |
| 35 | switch (adj->lookup_next_index) |
| 36 | { |
| 37 | case IP_LOOKUP_NEXT_MIDCHAIN: |
| 38 | case IP_LOOKUP_NEXT_MCAST_MIDCHAIN: |
| 39 | return (1); |
| 40 | case IP_LOOKUP_NEXT_ARP: |
| 41 | case IP_LOOKUP_NEXT_GLEAN: |
| 42 | case IP_LOOKUP_NEXT_BCAST: |
| 43 | case IP_LOOKUP_NEXT_MCAST: |
| 44 | case IP_LOOKUP_NEXT_DROP: |
| 45 | case IP_LOOKUP_NEXT_PUNT: |
| 46 | case IP_LOOKUP_NEXT_LOCAL: |
| 47 | case IP_LOOKUP_NEXT_REWRITE: |
| 48 | case IP_LOOKUP_NEXT_ICMP_ERROR: |
| 49 | case IP_LOOKUP_N_NEXT: |
| 50 | return (0); |
| 51 | } |
| 52 | |
| 53 | return (0); |
| 54 | } |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 55 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 56 | static inline u32 |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 57 | adj_get_midchain_node (vnet_link_t link) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 58 | { |
| 59 | switch (link) { |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 60 | case VNET_LINK_IP4: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 61 | return (ip4_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 62 | case VNET_LINK_IP6: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 63 | return (ip6_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 64 | case VNET_LINK_MPLS: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 65 | return (mpls_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 66 | case VNET_LINK_ETHERNET: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 67 | return (adj_l2_midchain_node.index); |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 68 | case VNET_LINK_NSH: |
| 69 | return (adj_nsh_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 70 | case VNET_LINK_ARP: |
| 71 | break; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 72 | } |
| 73 | ASSERT(0); |
| 74 | return (0); |
| 75 | } |
| 76 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 77 | static u8 |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 78 | adj_midchain_get_feature_arc_index (const ip_adjacency_t *adj) |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 79 | { |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 80 | switch (adj->ia_link) |
| 81 | { |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 82 | case VNET_LINK_IP4: |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 83 | return ip4_main.lookup_main.output_feature_arc_index; |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 84 | case VNET_LINK_IP6: |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 85 | return ip6_main.lookup_main.output_feature_arc_index; |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 86 | case VNET_LINK_MPLS: |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 87 | return mpls_main.output_feature_arc_index; |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 88 | case VNET_LINK_ETHERNET: |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 89 | return ethernet_main.output_feature_arc_index; |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 90 | case VNET_LINK_NSH: |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 91 | case VNET_LINK_ARP: |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 92 | break; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 93 | } |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 94 | ASSERT (0); |
| 95 | return (0); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 96 | } |
| 97 | |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 98 | static u32 |
| 99 | adj_nbr_midchain_get_tx_node (ip_adjacency_t *adj) |
| 100 | { |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 101 | return (adj_midchain_tx.index); |
| 102 | } |
| 103 | |
| 104 | static u32 |
| 105 | adj_nbr_midchain_get_next_node (ip_adjacency_t *adj) |
| 106 | { |
| 107 | return (vnet_feature_get_end_node(adj_midchain_get_feature_arc_index(adj), |
| 108 | adj->rewrite_header.sw_if_index)); |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 111 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 112 | * adj_midchain_setup |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 113 | * |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 114 | * Setup the adj as a mid-chain |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 115 | */ |
| 116 | void |
Neale Ranns | 3ebebc3 | 2020-02-18 13:56:24 +0000 | [diff] [blame] | 117 | adj_midchain_teardown (ip_adjacency_t *adj) |
| 118 | { |
Neale Ranns | 3ebebc3 | 2020-02-18 13:56:24 +0000 | [diff] [blame] | 119 | dpo_reset(&adj->sub_type.midchain.next_dpo); |
Neale Ranns | 3ebebc3 | 2020-02-18 13:56:24 +0000 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** |
| 123 | * adj_midchain_setup |
| 124 | * |
| 125 | * Setup the adj as a mid-chain |
| 126 | */ |
| 127 | void |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 128 | adj_midchain_setup (adj_index_t adj_index, |
| 129 | adj_midchain_fixup_t fixup, |
Neale Ranns | db14f5a | 2018-01-29 10:43:33 -0800 | [diff] [blame] | 130 | const void *data, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 131 | adj_flags_t flags) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 132 | { |
| 133 | ip_adjacency_t *adj; |
| 134 | |
| 135 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 136 | |
| 137 | adj = adj_get(adj_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 138 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 139 | adj->sub_type.midchain.fixup_func = fixup; |
Neale Ranns | db14f5a | 2018-01-29 10:43:33 -0800 | [diff] [blame] | 140 | adj->sub_type.midchain.fixup_data = data; |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 141 | adj->sub_type.midchain.fei = FIB_NODE_INDEX_INVALID; |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 142 | adj->ia_flags |= flags; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 143 | |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 144 | if (flags & ADJ_FLAG_MIDCHAIN_FIXUP_IP4O4_HDR) |
| 145 | { |
| 146 | adj->rewrite_header.flags |= VNET_REWRITE_FIXUP_IP4_O_4; |
| 147 | } |
| 148 | else |
| 149 | { |
| 150 | adj->rewrite_header.flags &= ~VNET_REWRITE_FIXUP_IP4_O_4; |
| 151 | } |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 152 | if (!(flags & ADJ_FLAG_MIDCHAIN_FIXUP_FLOW_HASH)) |
| 153 | { |
| 154 | adj->rewrite_header.flags &= ~VNET_REWRITE_FIXUP_FLOW_HASH; |
| 155 | } |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 156 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 157 | /* |
| 158 | * stack the midchain on the drop so it's ready to forward in the adj-midchain-tx. |
| 159 | * The graph arc used/created here is from the midchain-tx node to the |
| 160 | * child's registered node. This is because post adj processing the next |
| 161 | * node are any output features, then the midchain-tx. from there we |
| 162 | * need to get to the stacked child's node. |
| 163 | */ |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 164 | dpo_stack_from_node(adj_nbr_midchain_get_tx_node(adj), |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 165 | &adj->sub_type.midchain.next_dpo, |
| 166 | drop_dpo_get(vnet_link_to_dpo_proto(adj->ia_link))); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | /** |
| 170 | * adj_nbr_midchain_update_rewrite |
| 171 | * |
| 172 | * Update the adjacency's rewrite string. A NULL string implies the |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 173 | * rewrite is reset (i.e. when ARP/ND entry is gone). |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 174 | * NB: the adj being updated may be handling traffic in the DP. |
| 175 | */ |
| 176 | void |
| 177 | adj_nbr_midchain_update_rewrite (adj_index_t adj_index, |
| 178 | adj_midchain_fixup_t fixup, |
Neale Ranns | db14f5a | 2018-01-29 10:43:33 -0800 | [diff] [blame] | 179 | const void *fixup_data, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 180 | adj_flags_t flags, |
| 181 | u8 *rewrite) |
| 182 | { |
| 183 | ip_adjacency_t *adj; |
| 184 | |
| 185 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 186 | |
| 187 | adj = adj_get(adj_index); |
| 188 | |
| 189 | /* |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 190 | * one time only update. since we don't support changing the tunnel |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 191 | * src,dst, this is all we need. |
| 192 | */ |
Neale Ranns | 174959c | 2020-02-03 10:33:51 +0000 | [diff] [blame] | 193 | if (adj->lookup_next_index != IP_LOOKUP_NEXT_MIDCHAIN && |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 194 | adj->lookup_next_index != IP_LOOKUP_NEXT_MCAST_MIDCHAIN) |
| 195 | { |
| 196 | adj_midchain_setup(adj_index, fixup, fixup_data, flags); |
| 197 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 198 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 199 | /* |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 200 | * update the rewrite with the workers paused. |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 201 | */ |
| 202 | adj_nbr_update_rewrite_internal(adj, |
| 203 | IP_LOOKUP_NEXT_MIDCHAIN, |
| 204 | adj_get_midchain_node(adj->ia_link), |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 205 | adj_nbr_midchain_get_next_node(adj), |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 206 | rewrite); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 207 | } |
| 208 | |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 209 | void |
| 210 | adj_nbr_midchain_update_next_node (adj_index_t adj_index, |
| 211 | u32 next_node) |
| 212 | { |
| 213 | ip_adjacency_t *adj; |
| 214 | vlib_main_t * vm; |
| 215 | |
| 216 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 217 | |
| 218 | adj = adj_get(adj_index); |
| 219 | vm = vlib_get_main(); |
| 220 | |
| 221 | vlib_worker_thread_barrier_sync(vm); |
| 222 | |
| 223 | adj->rewrite_header.next_index = vlib_node_add_next(vlib_get_main(), |
| 224 | adj->ia_node_index, |
| 225 | next_node); |
| 226 | |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 227 | vlib_worker_thread_barrier_release(vm); |
| 228 | } |
| 229 | |
| 230 | void |
Neale Ranns | 5d0136f | 2020-05-12 08:51:02 +0000 | [diff] [blame] | 231 | adj_nbr_midchain_reset_next_node (adj_index_t adj_index) |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 232 | { |
| 233 | ip_adjacency_t *adj; |
| 234 | vlib_main_t * vm; |
| 235 | |
| 236 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 237 | |
| 238 | adj = adj_get(adj_index); |
| 239 | vm = vlib_get_main(); |
| 240 | |
| 241 | vlib_worker_thread_barrier_sync(vm); |
| 242 | |
| 243 | adj->rewrite_header.next_index = |
| 244 | vlib_node_add_next(vlib_get_main(), |
| 245 | adj->ia_node_index, |
Neale Ranns | 6fdcc3d | 2021-10-08 07:30:47 +0000 | [diff] [blame] | 246 | adj_nbr_midchain_get_next_node(adj)); |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 247 | |
| 248 | vlib_worker_thread_barrier_release(vm); |
| 249 | } |
| 250 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 251 | /** |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 252 | * adj_nbr_midchain_unstack |
| 253 | * |
| 254 | * Unstack the adj. stack it on drop |
| 255 | */ |
| 256 | void |
| 257 | adj_nbr_midchain_unstack (adj_index_t adj_index) |
| 258 | { |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 259 | fib_node_index_t *entry_indicies, tmp; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 260 | ip_adjacency_t *adj; |
| 261 | |
| 262 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 263 | adj = adj_get (adj_index); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 264 | |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 265 | /* |
| 266 | * check to see if this unstacking breaks a recursion loop |
| 267 | */ |
| 268 | entry_indicies = NULL; |
| 269 | tmp = adj->sub_type.midchain.fei; |
| 270 | adj->sub_type.midchain.fei = FIB_NODE_INDEX_INVALID; |
| 271 | |
| 272 | if (FIB_NODE_INDEX_INVALID != tmp) |
| 273 | { |
| 274 | fib_entry_recursive_loop_detect(tmp, &entry_indicies); |
| 275 | vec_free(entry_indicies); |
| 276 | } |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 277 | |
| 278 | /* |
| 279 | * stack on the drop |
| 280 | */ |
| 281 | dpo_stack(DPO_ADJACENCY_MIDCHAIN, |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 282 | vnet_link_to_dpo_proto(adj->ia_link), |
| 283 | &adj->sub_type.midchain.next_dpo, |
| 284 | drop_dpo_get(vnet_link_to_dpo_proto(adj->ia_link))); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 285 | CLIB_MEMORY_BARRIER(); |
| 286 | } |
| 287 | |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 288 | void |
| 289 | adj_nbr_midchain_stack_on_fib_entry (adj_index_t ai, |
| 290 | fib_node_index_t fei, |
| 291 | fib_forward_chain_type_t fct) |
| 292 | { |
| 293 | fib_node_index_t *entry_indicies; |
| 294 | dpo_id_t tmp = DPO_INVALID; |
| 295 | ip_adjacency_t *adj; |
| 296 | |
| 297 | adj = adj_get (ai); |
| 298 | |
| 299 | /* |
| 300 | * check to see if this stacking will form a recursion loop |
| 301 | */ |
| 302 | entry_indicies = NULL; |
| 303 | adj->sub_type.midchain.fei = fei; |
| 304 | |
| 305 | if (fib_entry_recursive_loop_detect(adj->sub_type.midchain.fei, &entry_indicies)) |
| 306 | { |
| 307 | /* |
| 308 | * loop formed, stack on the drop. |
| 309 | */ |
| 310 | dpo_copy(&tmp, drop_dpo_get(fib_forw_chain_type_to_dpo_proto(fct))); |
| 311 | } |
| 312 | else |
| 313 | { |
| 314 | fib_entry_contribute_forwarding (fei, fct, &tmp); |
| 315 | |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 316 | if (DPO_LOAD_BALANCE == tmp.dpoi_type) |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 317 | { |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 318 | load_balance_t *lb; |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 319 | |
| 320 | lb = load_balance_get (tmp.dpoi_index); |
| 321 | |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 322 | if ((adj->ia_flags & ADJ_FLAG_MIDCHAIN_IP_STACK) || |
| 323 | lb->lb_n_buckets == 1) |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 324 | { |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 325 | /* |
| 326 | * do that hash now and stack on the choice. |
| 327 | * If the choice is an incomplete adj then we will need a poke when |
| 328 | * it becomes complete. This happens since the adj update walk propagates |
| 329 | * as far a recursive paths. |
| 330 | */ |
| 331 | const dpo_id_t *choice; |
| 332 | int hash; |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 333 | |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 334 | if (FIB_FORW_CHAIN_TYPE_UNICAST_IP4 == fct) |
| 335 | { |
| 336 | hash = ip4_compute_flow_hash ((ip4_header_t *) adj_get_rewrite (ai), |
| 337 | lb->lb_hash_config); |
| 338 | } |
| 339 | else if (FIB_FORW_CHAIN_TYPE_UNICAST_IP6 == fct) |
| 340 | { |
| 341 | hash = ip6_compute_flow_hash ((ip6_header_t *) adj_get_rewrite (ai), |
| 342 | lb->lb_hash_config); |
| 343 | } |
| 344 | else |
| 345 | { |
| 346 | hash = 0; |
| 347 | ASSERT(0); |
| 348 | } |
| 349 | |
| 350 | choice = load_balance_get_bucket_i (lb, hash & lb->lb_n_buckets_minus_1); |
| 351 | dpo_copy (&tmp, choice); |
| 352 | } |
Neale Ranns | 65d789e | 2021-02-08 15:24:56 +0000 | [diff] [blame] | 353 | else if (lb->lb_n_buckets > 1) |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 354 | { |
Neale Ranns | 65d789e | 2021-02-08 15:24:56 +0000 | [diff] [blame] | 355 | /* |
| 356 | * the client has chosen not to use the stacking to select a |
| 357 | * bucket, and there are more than one buckets. there's no |
| 358 | * value in using the midchain's fixed rewrite string to select |
| 359 | * the path, so force a flow hash on the inner. |
| 360 | */ |
| 361 | adj->rewrite_header.flags |= VNET_REWRITE_FIXUP_FLOW_HASH; |
| 362 | } |
| 363 | |
| 364 | if (adj->ia_flags & ADJ_FLAG_MIDCHAIN_FIXUP_FLOW_HASH) |
| 365 | { |
| 366 | /* |
| 367 | * The client, for reasons unbeknownst to adj, wants to force |
| 368 | * a flow hash on the inner, we will oblige. |
| 369 | */ |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 370 | adj->rewrite_header.flags |= VNET_REWRITE_FIXUP_FLOW_HASH; |
| 371 | } |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | adj_nbr_midchain_stack (ai, &tmp); |
| 375 | dpo_reset(&tmp); |
| 376 | vec_free(entry_indicies); |
| 377 | } |
| 378 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 379 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 380 | * adj_nbr_midchain_stack |
| 381 | */ |
| 382 | void |
| 383 | adj_nbr_midchain_stack (adj_index_t adj_index, |
| 384 | const dpo_id_t *next) |
| 385 | { |
| 386 | ip_adjacency_t *adj; |
| 387 | |
| 388 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 389 | |
| 390 | adj = adj_get(adj_index); |
| 391 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 392 | ASSERT((IP_LOOKUP_NEXT_MIDCHAIN == adj->lookup_next_index) || |
| 393 | (IP_LOOKUP_NEXT_MCAST_MIDCHAIN == adj->lookup_next_index)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 394 | |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 395 | dpo_stack_from_node(adj_nbr_midchain_get_tx_node(adj), |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 396 | &adj->sub_type.midchain.next_dpo, |
| 397 | next); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 398 | } |
| 399 | |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 400 | int |
| 401 | adj_ndr_midchain_recursive_loop_detect (adj_index_t ai, |
| 402 | fib_node_index_t **entry_indicies) |
| 403 | { |
| 404 | fib_node_index_t *entry_index, *entries; |
| 405 | ip_adjacency_t * adj; |
| 406 | |
| 407 | adj = adj_get(ai); |
| 408 | entries = *entry_indicies; |
| 409 | |
| 410 | vec_foreach(entry_index, entries) |
| 411 | { |
| 412 | if (*entry_index == adj->sub_type.midchain.fei) |
| 413 | { |
| 414 | /* |
| 415 | * The entry this midchain links to is already in the set |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 416 | * of visited entries, this is a loop |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 417 | */ |
| 418 | adj->ia_flags |= ADJ_FLAG_MIDCHAIN_LOOPED; |
| 419 | return (1); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | adj->ia_flags &= ~ADJ_FLAG_MIDCHAIN_LOOPED; |
| 424 | return (0); |
| 425 | } |
| 426 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 427 | u8* |
| 428 | format_adj_midchain (u8* s, va_list *ap) |
| 429 | { |
Billy McFall | cfcf1e2 | 2016-10-14 09:51:49 -0400 | [diff] [blame] | 430 | index_t index = va_arg(*ap, index_t); |
| 431 | u32 indent = va_arg(*ap, u32); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 432 | ip_adjacency_t * adj = adj_get(index); |
| 433 | |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 434 | s = format (s, "%U", format_vnet_link, adj->ia_link); |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 435 | if (adj->rewrite_header.flags & VNET_REWRITE_HAS_FEATURES) |
| 436 | s = format(s, " [features]"); |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 437 | s = format (s, " via %U", |
| 438 | format_ip46_address, &adj->sub_type.nbr.next_hop, |
| 439 | adj_proto_to_46(adj->ia_nh_proto)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 440 | s = format (s, " %U", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 441 | format_vnet_rewrite, |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 442 | &adj->rewrite_header, sizeof (adj->rewrite_data), indent); |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 443 | s = format (s, "\n%Ustacked-on", |
| 444 | format_white_space, indent); |
| 445 | |
| 446 | if (FIB_NODE_INDEX_INVALID != adj->sub_type.midchain.fei) |
| 447 | { |
| 448 | s = format (s, " entry:%d", adj->sub_type.midchain.fei); |
| 449 | |
| 450 | } |
| 451 | s = format (s, ":\n%U%U", |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 452 | format_white_space, indent+2, |
| 453 | format_dpo_id, &adj->sub_type.midchain.next_dpo, indent+2); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 454 | |
| 455 | return (s); |
| 456 | } |
| 457 | |
| 458 | static void |
| 459 | adj_dpo_lock (dpo_id_t *dpo) |
| 460 | { |
| 461 | adj_lock(dpo->dpoi_index); |
| 462 | } |
| 463 | static void |
| 464 | adj_dpo_unlock (dpo_id_t *dpo) |
| 465 | { |
| 466 | adj_unlock(dpo->dpoi_index); |
| 467 | } |
| 468 | |
| 469 | const static dpo_vft_t adj_midchain_dpo_vft = { |
| 470 | .dv_lock = adj_dpo_lock, |
| 471 | .dv_unlock = adj_dpo_unlock, |
| 472 | .dv_format = format_adj_midchain, |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 473 | .dv_get_urpf = adj_dpo_get_urpf, |
Neale Ranns | 8f5fef2 | 2020-12-21 08:29:34 +0000 | [diff] [blame] | 474 | .dv_get_mtu = adj_dpo_get_mtu, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 475 | }; |
| 476 | |
| 477 | /** |
| 478 | * @brief The per-protocol VLIB graph nodes that are assigned to a midchain |
| 479 | * object. |
| 480 | * |
| 481 | * this means that these graph nodes are ones from which a midchain is the |
| 482 | * parent object in the DPO-graph. |
| 483 | */ |
| 484 | const static char* const midchain_ip4_nodes[] = |
| 485 | { |
| 486 | "ip4-midchain", |
| 487 | NULL, |
| 488 | }; |
| 489 | const static char* const midchain_ip6_nodes[] = |
| 490 | { |
| 491 | "ip6-midchain", |
| 492 | NULL, |
| 493 | }; |
| 494 | const static char* const midchain_mpls_nodes[] = |
| 495 | { |
| 496 | "mpls-midchain", |
| 497 | NULL, |
| 498 | }; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 499 | const static char* const midchain_ethernet_nodes[] = |
| 500 | { |
| 501 | "adj-l2-midchain", |
| 502 | NULL, |
| 503 | }; |
Florin Coras | b69111e | 2017-02-13 23:55:27 -0800 | [diff] [blame] | 504 | const static char* const midchain_nsh_nodes[] = |
| 505 | { |
| 506 | "adj-nsh-midchain", |
| 507 | NULL, |
| 508 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 509 | |
| 510 | const static char* const * const midchain_nodes[DPO_PROTO_NUM] = |
| 511 | { |
| 512 | [DPO_PROTO_IP4] = midchain_ip4_nodes, |
| 513 | [DPO_PROTO_IP6] = midchain_ip6_nodes, |
| 514 | [DPO_PROTO_MPLS] = midchain_mpls_nodes, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 515 | [DPO_PROTO_ETHERNET] = midchain_ethernet_nodes, |
Florin Coras | b69111e | 2017-02-13 23:55:27 -0800 | [diff] [blame] | 516 | [DPO_PROTO_NSH] = midchain_nsh_nodes, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 517 | }; |
| 518 | |
| 519 | void |
| 520 | adj_midchain_module_init (void) |
| 521 | { |
| 522 | dpo_register(DPO_ADJACENCY_MIDCHAIN, &adj_midchain_dpo_vft, midchain_nodes); |
| 523 | } |