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