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/ethernet/arp_packet.h> |
| 22 | #include <vnet/dpo/drop_dpo.h> |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 23 | #include <vnet/dpo/load_balance.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 24 | #include <vnet/fib/fib_walk.h> |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 25 | #include <vnet/fib/fib_entry.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 26 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 27 | /** |
| 28 | * The two midchain tx feature node indices |
| 29 | */ |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 30 | static u32 adj_midchain_tx_feature_node[VNET_LINK_NUM]; |
| 31 | static u32 adj_midchain_tx_no_count_feature_node[VNET_LINK_NUM]; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 32 | |
Neale Ranns | 3ebebc3 | 2020-02-18 13:56:24 +0000 | [diff] [blame] | 33 | static u32 *adj_midchain_feat_count_per_sw_if_index[VNET_LINK_NUM]; |
| 34 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 35 | /** |
| 36 | * @brief Trace data for packets traversing the midchain tx node |
| 37 | */ |
| 38 | typedef struct adj_midchain_tx_trace_t_ |
| 39 | { |
| 40 | /** |
| 41 | * @brief the midchain adj we are traversing |
| 42 | */ |
| 43 | adj_index_t ai; |
| 44 | } adj_midchain_tx_trace_t; |
| 45 | |
| 46 | always_inline uword |
Damjan Marion | 77766a1 | 2016-11-02 01:21:05 +0100 | [diff] [blame] | 47 | adj_midchain_tx_inline (vlib_main_t * vm, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 48 | vlib_node_runtime_t * node, |
| 49 | vlib_frame_t * frame, |
| 50 | int interface_count) |
| 51 | { |
| 52 | u32 * from, * to_next, n_left_from, n_left_to_next; |
| 53 | u32 next_index; |
| 54 | vnet_main_t *vnm = vnet_get_main (); |
| 55 | vnet_interface_main_t *im = &vnm->interface_main; |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 56 | u32 thread_index = vm->thread_index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 57 | |
| 58 | /* Vector of buffer / pkt indices we're supposed to process */ |
| 59 | from = vlib_frame_vector_args (frame); |
| 60 | |
| 61 | /* Number of buffers / pkts */ |
| 62 | n_left_from = frame->n_vectors; |
| 63 | |
| 64 | /* Speculatively send the first buffer to the last disposition we used */ |
| 65 | next_index = node->cached_next_index; |
| 66 | |
| 67 | while (n_left_from > 0) |
| 68 | { |
| 69 | /* set up to enqueue to our disposition with index = next_index */ |
| 70 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 71 | |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 72 | while (n_left_from >= 8 && n_left_to_next > 4) |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 73 | { |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 74 | const ip_adjacency_t *adj0, *adj1, *adj2, *adj3; |
| 75 | const dpo_id_t *dpo0, *dpo1, *dpo2, *dpo3; |
| 76 | vlib_buffer_t * b0, *b1, *b2, *b3; |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 77 | u32 bi0, adj_index0, next0; |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 78 | u32 bi1, adj_index1, next1; |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 79 | u32 bi2, adj_index2, next2; |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 80 | u32 bi3, adj_index3, next3; |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 81 | |
| 82 | /* Prefetch next iteration. */ |
| 83 | { |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 84 | vlib_buffer_t * p4, * p5; |
| 85 | vlib_buffer_t * p6, * p7; |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 86 | |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 87 | p4 = vlib_get_buffer (vm, from[4]); |
| 88 | p5 = vlib_get_buffer (vm, from[5]); |
| 89 | p6 = vlib_get_buffer (vm, from[6]); |
| 90 | p7 = vlib_get_buffer (vm, from[7]); |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 91 | |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 92 | vlib_prefetch_buffer_header (p4, LOAD); |
| 93 | vlib_prefetch_buffer_header (p5, LOAD); |
| 94 | vlib_prefetch_buffer_header (p6, LOAD); |
| 95 | vlib_prefetch_buffer_header (p7, LOAD); |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | bi0 = from[0]; |
| 99 | to_next[0] = bi0; |
| 100 | bi1 = from[1]; |
| 101 | to_next[1] = bi1; |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 102 | bi2 = from[2]; |
| 103 | to_next[2] = bi2; |
| 104 | bi3 = from[3]; |
| 105 | to_next[3] = bi3; |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 106 | |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 107 | from += 4; |
| 108 | to_next += 4; |
| 109 | n_left_from -= 4; |
| 110 | n_left_to_next -= 4; |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 111 | |
| 112 | b0 = vlib_get_buffer(vm, bi0); |
| 113 | b1 = vlib_get_buffer(vm, bi1); |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 114 | b2 = vlib_get_buffer(vm, bi2); |
| 115 | b3 = vlib_get_buffer(vm, bi3); |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 116 | |
| 117 | /* Follow the DPO on which the midchain is stacked */ |
| 118 | adj_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; |
| 119 | adj_index1 = vnet_buffer(b1)->ip.adj_index[VLIB_TX]; |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 120 | adj_index2 = vnet_buffer(b2)->ip.adj_index[VLIB_TX]; |
| 121 | adj_index3 = vnet_buffer(b3)->ip.adj_index[VLIB_TX]; |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 122 | |
| 123 | adj0 = adj_get(adj_index0); |
| 124 | adj1 = adj_get(adj_index1); |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 125 | adj2 = adj_get(adj_index2); |
| 126 | adj3 = adj_get(adj_index3); |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 127 | |
| 128 | dpo0 = &adj0->sub_type.midchain.next_dpo; |
| 129 | dpo1 = &adj1->sub_type.midchain.next_dpo; |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 130 | dpo2 = &adj2->sub_type.midchain.next_dpo; |
| 131 | dpo3 = &adj3->sub_type.midchain.next_dpo; |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 132 | |
| 133 | next0 = dpo0->dpoi_next_node; |
| 134 | next1 = dpo1->dpoi_next_node; |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 135 | next2 = dpo2->dpoi_next_node; |
| 136 | next3 = dpo3->dpoi_next_node; |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 137 | |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 138 | vnet_buffer(b1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index; |
| 139 | vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; |
| 140 | vnet_buffer(b2)->ip.adj_index[VLIB_TX] = dpo2->dpoi_index; |
| 141 | vnet_buffer(b3)->ip.adj_index[VLIB_TX] = dpo3->dpoi_index; |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 142 | |
| 143 | if (interface_count) |
| 144 | { |
| 145 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 146 | + VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 147 | thread_index, |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 148 | adj0->rewrite_header.sw_if_index, |
| 149 | 1, |
| 150 | vlib_buffer_length_in_chain (vm, b0)); |
| 151 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 152 | + VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 153 | thread_index, |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 154 | adj1->rewrite_header.sw_if_index, |
| 155 | 1, |
| 156 | vlib_buffer_length_in_chain (vm, b1)); |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 157 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 158 | + VNET_INTERFACE_COUNTER_TX, |
| 159 | thread_index, |
| 160 | adj2->rewrite_header.sw_if_index, |
| 161 | 1, |
| 162 | vlib_buffer_length_in_chain (vm, b2)); |
| 163 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 164 | + VNET_INTERFACE_COUNTER_TX, |
| 165 | thread_index, |
| 166 | adj3->rewrite_header.sw_if_index, |
| 167 | 1, |
| 168 | vlib_buffer_length_in_chain (vm, b3)); |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 172 | { |
| 173 | adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, |
| 174 | b0, sizeof (*tr)); |
| 175 | tr->ai = adj_index0; |
| 176 | } |
| 177 | if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED)) |
| 178 | { |
| 179 | adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, |
| 180 | b1, sizeof (*tr)); |
| 181 | tr->ai = adj_index1; |
| 182 | } |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 183 | if (PREDICT_FALSE(b2->flags & VLIB_BUFFER_IS_TRACED)) |
| 184 | { |
| 185 | adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, |
| 186 | b2, sizeof (*tr)); |
| 187 | tr->ai = adj_index2; |
| 188 | } |
| 189 | if (PREDICT_FALSE(b3->flags & VLIB_BUFFER_IS_TRACED)) |
| 190 | { |
| 191 | adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, |
| 192 | b3, sizeof (*tr)); |
| 193 | tr->ai = adj_index3; |
| 194 | } |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 195 | |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 196 | vlib_validate_buffer_enqueue_x4 (vm, node, next_index, |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 197 | to_next, n_left_to_next, |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 198 | bi0, bi1, bi2, bi3, |
| 199 | next0, next1, next2, next3); |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 200 | } |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 201 | while (n_left_from > 0 && n_left_to_next > 0) |
| 202 | { |
| 203 | u32 bi0, adj_index0, next0; |
| 204 | const ip_adjacency_t * adj0; |
| 205 | const dpo_id_t *dpo0; |
| 206 | vlib_buffer_t * b0; |
| 207 | |
| 208 | bi0 = from[0]; |
| 209 | to_next[0] = bi0; |
| 210 | from += 1; |
| 211 | to_next += 1; |
| 212 | n_left_from -= 1; |
| 213 | n_left_to_next -= 1; |
| 214 | |
| 215 | b0 = vlib_get_buffer(vm, bi0); |
| 216 | |
| 217 | /* Follow the DPO on which the midchain is stacked */ |
| 218 | adj_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; |
| 219 | adj0 = adj_get(adj_index0); |
| 220 | dpo0 = &adj0->sub_type.midchain.next_dpo; |
| 221 | next0 = dpo0->dpoi_next_node; |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 222 | vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 223 | |
| 224 | if (interface_count) |
| 225 | { |
| 226 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 227 | + VNET_INTERFACE_COUNTER_TX, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 228 | thread_index, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 229 | adj0->rewrite_header.sw_if_index, |
| 230 | 1, |
| 231 | vlib_buffer_length_in_chain (vm, b0)); |
| 232 | } |
| 233 | |
| 234 | if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 235 | { |
| 236 | adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, |
| 237 | b0, sizeof (*tr)); |
| 238 | tr->ai = adj_index0; |
| 239 | } |
| 240 | |
| 241 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 242 | to_next, n_left_to_next, |
| 243 | bi0, next0); |
| 244 | } |
| 245 | |
| 246 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 247 | } |
| 248 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 249 | return frame->n_vectors; |
| 250 | } |
| 251 | |
| 252 | static u8 * |
| 253 | format_adj_midchain_tx_trace (u8 * s, va_list * args) |
| 254 | { |
| 255 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 256 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 257 | adj_midchain_tx_trace_t *tr = va_arg (*args, adj_midchain_tx_trace_t*); |
| 258 | |
| 259 | s = format(s, "adj-midchain:[%d]:%U", tr->ai, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 260 | format_ip_adjacency, tr->ai, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 261 | FORMAT_IP_ADJACENCY_NONE); |
| 262 | |
| 263 | return (s); |
| 264 | } |
| 265 | |
| 266 | static uword |
| 267 | adj_midchain_tx (vlib_main_t * vm, |
| 268 | vlib_node_runtime_t * node, |
| 269 | vlib_frame_t * frame) |
| 270 | { |
Damjan Marion | 77766a1 | 2016-11-02 01:21:05 +0100 | [diff] [blame] | 271 | return (adj_midchain_tx_inline(vm, node, frame, 1)); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | VLIB_REGISTER_NODE (adj_midchain_tx_node, static) = { |
| 275 | .function = adj_midchain_tx, |
| 276 | .name = "adj-midchain-tx", |
| 277 | .vector_size = sizeof (u32), |
| 278 | |
| 279 | .format_trace = format_adj_midchain_tx_trace, |
| 280 | |
| 281 | .n_next_nodes = 1, |
| 282 | .next_nodes = { |
| 283 | [0] = "error-drop", |
| 284 | }, |
| 285 | }; |
| 286 | |
| 287 | static uword |
| 288 | adj_midchain_tx_no_count (vlib_main_t * vm, |
| 289 | vlib_node_runtime_t * node, |
| 290 | vlib_frame_t * frame) |
| 291 | { |
Damjan Marion | 77766a1 | 2016-11-02 01:21:05 +0100 | [diff] [blame] | 292 | return (adj_midchain_tx_inline(vm, node, frame, 0)); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | VLIB_REGISTER_NODE (adj_midchain_tx_no_count_node, static) = { |
| 296 | .function = adj_midchain_tx_no_count, |
| 297 | .name = "adj-midchain-tx-no-count", |
| 298 | .vector_size = sizeof (u32), |
| 299 | |
| 300 | .format_trace = format_adj_midchain_tx_trace, |
| 301 | |
| 302 | .n_next_nodes = 1, |
| 303 | .next_nodes = { |
| 304 | [0] = "error-drop", |
| 305 | }, |
| 306 | }; |
| 307 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 308 | VNET_FEATURE_INIT (adj_midchain_tx_ip4, static) = { |
| 309 | .arc_name = "ip4-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 310 | .node_name = "adj-midchain-tx", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 311 | .runs_before = VNET_FEATURES ("interface-output"), |
| 312 | .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_IP4], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 313 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 314 | VNET_FEATURE_INIT (adj_midchain_tx_no_count_ip4, static) = { |
| 315 | .arc_name = "ip4-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 316 | .node_name = "adj-midchain-tx-no-count", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 317 | .runs_before = VNET_FEATURES ("interface-output"), |
| 318 | .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_IP4], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 319 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 320 | VNET_FEATURE_INIT (adj_midchain_tx_ip6, static) = { |
| 321 | .arc_name = "ip6-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 322 | .node_name = "adj-midchain-tx", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 323 | .runs_before = VNET_FEATURES ("interface-output"), |
| 324 | .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_IP6], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 325 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 326 | VNET_FEATURE_INIT (adj_midchain_tx_no_count_ip6, static) = { |
| 327 | .arc_name = "ip6-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 328 | .node_name = "adj-midchain-tx-no-count", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 329 | .runs_before = VNET_FEATURES ("interface-output"), |
| 330 | .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_IP6], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 331 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 332 | VNET_FEATURE_INIT (adj_midchain_tx_mpls, static) = { |
| 333 | .arc_name = "mpls-output", |
Damjan Marion | 77766a1 | 2016-11-02 01:21:05 +0100 | [diff] [blame] | 334 | .node_name = "adj-midchain-tx", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 335 | .runs_before = VNET_FEATURES ("interface-output"), |
| 336 | .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_MPLS], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 337 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 338 | VNET_FEATURE_INIT (adj_midchain_tx_no_count_mpls, static) = { |
| 339 | .arc_name = "mpls-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 340 | .node_name = "adj-midchain-tx-no-count", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 341 | .runs_before = VNET_FEATURES ("interface-output"), |
| 342 | .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_MPLS], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 343 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 344 | VNET_FEATURE_INIT (adj_midchain_tx_ethernet, static) = { |
| 345 | .arc_name = "ethernet-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 346 | .node_name = "adj-midchain-tx", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 347 | .runs_before = VNET_FEATURES ("error-drop"), |
| 348 | .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_ETHERNET], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 349 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 350 | VNET_FEATURE_INIT (adj_midchain_tx_no_count_ethernet, static) = { |
| 351 | .arc_name = "ethernet-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 352 | .node_name = "adj-midchain-tx-no-count", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 353 | .runs_before = VNET_FEATURES ("error-drop"), |
| 354 | .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_ETHERNET], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 355 | }; |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 356 | VNET_FEATURE_INIT (adj_midchain_tx_nsh, static) = { |
| 357 | .arc_name = "nsh-output", |
| 358 | .node_name = "adj-midchain-tx", |
| 359 | .runs_before = VNET_FEATURES ("error-drop"), |
| 360 | .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_NSH], |
| 361 | }; |
| 362 | VNET_FEATURE_INIT (adj_midchain_tx_no_count_nsh, static) = { |
| 363 | .arc_name = "nsh-output", |
| 364 | .node_name = "adj-midchain-tx-no-count", |
| 365 | .runs_before = VNET_FEATURES ("error-drop"), |
| 366 | .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_NSH], |
| 367 | }; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 368 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 369 | static inline u32 |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 370 | adj_get_midchain_node (vnet_link_t link) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 371 | { |
| 372 | switch (link) { |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 373 | case VNET_LINK_IP4: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 374 | return (ip4_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 375 | case VNET_LINK_IP6: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 376 | return (ip6_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 377 | case VNET_LINK_MPLS: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 378 | return (mpls_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 379 | case VNET_LINK_ETHERNET: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 380 | return (adj_l2_midchain_node.index); |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 381 | case VNET_LINK_NSH: |
| 382 | return (adj_nsh_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 383 | case VNET_LINK_ARP: |
| 384 | break; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 385 | } |
| 386 | ASSERT(0); |
| 387 | return (0); |
| 388 | } |
| 389 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 390 | static u8 |
| 391 | 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] | 392 | { |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 393 | u8 arc = (u8) ~0; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 394 | switch (adj->ia_link) |
| 395 | { |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 396 | case VNET_LINK_IP4: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 397 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 398 | arc = ip4_main.lookup_main.output_feature_arc_index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 399 | break; |
| 400 | } |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 401 | case VNET_LINK_IP6: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 402 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 403 | arc = ip6_main.lookup_main.output_feature_arc_index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 404 | break; |
| 405 | } |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 406 | case VNET_LINK_MPLS: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 407 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 408 | arc = mpls_main.output_feature_arc_index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 409 | break; |
| 410 | } |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 411 | case VNET_LINK_ETHERNET: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 412 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 413 | arc = ethernet_main.output_feature_arc_index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 414 | break; |
| 415 | } |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 416 | case VNET_LINK_NSH: |
| 417 | { |
| 418 | arc = nsh_main_dummy.output_feature_arc_index; |
| 419 | break; |
| 420 | } |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 421 | case VNET_LINK_ARP: |
| 422 | ASSERT(0); |
| 423 | break; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 424 | } |
| 425 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 426 | ASSERT (arc != (u8) ~0); |
| 427 | |
| 428 | return (arc); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 429 | } |
| 430 | |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 431 | static u32 |
| 432 | adj_nbr_midchain_get_tx_node (ip_adjacency_t *adj) |
| 433 | { |
| 434 | return ((adj->ia_flags & ADJ_FLAG_MIDCHAIN_NO_COUNT) ? |
| 435 | adj_midchain_tx_no_count_node.index : |
| 436 | adj_midchain_tx_node.index); |
| 437 | } |
| 438 | |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 439 | static u32 |
| 440 | adj_nbr_midchain_get_feature_node (ip_adjacency_t *adj) |
| 441 | { |
| 442 | if (adj->ia_flags & ADJ_FLAG_MIDCHAIN_NO_COUNT) |
| 443 | { |
| 444 | return (adj_midchain_tx_no_count_feature_node[adj->ia_link]); |
| 445 | } |
| 446 | |
| 447 | return (adj_midchain_tx_feature_node[adj->ia_link]); |
| 448 | } |
| 449 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 450 | /** |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 451 | * adj_midchain_setup |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 452 | * |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 453 | * Setup the adj as a mid-chain |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 454 | */ |
| 455 | void |
Neale Ranns | 3ebebc3 | 2020-02-18 13:56:24 +0000 | [diff] [blame] | 456 | adj_midchain_teardown (ip_adjacency_t *adj) |
| 457 | { |
| 458 | u32 feature_index; |
| 459 | u8 arc_index; |
| 460 | |
| 461 | dpo_reset(&adj->sub_type.midchain.next_dpo); |
| 462 | |
| 463 | arc_index = adj_midchain_get_feature_arc_index_for_link_type (adj); |
| 464 | feature_index = adj_nbr_midchain_get_feature_node(adj); |
| 465 | |
| 466 | if (0 == --adj_midchain_feat_count_per_sw_if_index[adj->ia_link][adj->rewrite_header.sw_if_index]) |
| 467 | { |
| 468 | vnet_feature_enable_disable_with_index (arc_index, feature_index, |
| 469 | adj->rewrite_header.sw_if_index, |
| 470 | 0, 0, 0); |
| 471 | } |
| 472 | } |
| 473 | |
| 474 | /** |
| 475 | * adj_midchain_setup |
| 476 | * |
| 477 | * Setup the adj as a mid-chain |
| 478 | */ |
| 479 | void |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 480 | adj_midchain_setup (adj_index_t adj_index, |
| 481 | adj_midchain_fixup_t fixup, |
Neale Ranns | db14f5a | 2018-01-29 10:43:33 -0800 | [diff] [blame] | 482 | const void *data, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 483 | adj_flags_t flags) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 484 | { |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 485 | u32 feature_index, tx_node; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 486 | ip_adjacency_t *adj; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 487 | u8 arc_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 488 | |
| 489 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 490 | |
| 491 | adj = adj_get(adj_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 492 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 493 | adj->sub_type.midchain.fixup_func = fixup; |
Neale Ranns | db14f5a | 2018-01-29 10:43:33 -0800 | [diff] [blame] | 494 | adj->sub_type.midchain.fixup_data = data; |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 495 | adj->sub_type.midchain.fei = FIB_NODE_INDEX_INVALID; |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 496 | adj->ia_flags |= flags; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 497 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 498 | arc_index = adj_midchain_get_feature_arc_index_for_link_type (adj); |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 499 | feature_index = adj_nbr_midchain_get_feature_node(adj); |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 500 | tx_node = adj_nbr_midchain_get_tx_node(adj); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 501 | |
Neale Ranns | 3ebebc3 | 2020-02-18 13:56:24 +0000 | [diff] [blame] | 502 | vec_validate (adj_midchain_feat_count_per_sw_if_index[adj->ia_link], |
| 503 | adj->rewrite_header.sw_if_index); |
| 504 | |
| 505 | if (0 == adj_midchain_feat_count_per_sw_if_index[adj->ia_link][adj->rewrite_header.sw_if_index]++) |
| 506 | { |
| 507 | vnet_feature_enable_disable_with_index (arc_index, feature_index, |
| 508 | adj->rewrite_header.sw_if_index, |
| 509 | 1 /* enable */, 0, 0); |
| 510 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 511 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 512 | /* |
| 513 | * stack the midchain on the drop so it's ready to forward in the adj-midchain-tx. |
| 514 | * The graph arc used/created here is from the midchain-tx node to the |
| 515 | * child's registered node. This is because post adj processing the next |
| 516 | * node are any output features, then the midchain-tx. from there we |
| 517 | * need to get to the stacked child's node. |
| 518 | */ |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 519 | dpo_stack_from_node(tx_node, |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 520 | &adj->sub_type.midchain.next_dpo, |
| 521 | drop_dpo_get(vnet_link_to_dpo_proto(adj->ia_link))); |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | /** |
| 525 | * adj_nbr_midchain_update_rewrite |
| 526 | * |
| 527 | * Update the adjacency's rewrite string. A NULL string implies the |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 528 | * rewrite is reset (i.e. when ARP/ND entry is gone). |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 529 | * NB: the adj being updated may be handling traffic in the DP. |
| 530 | */ |
| 531 | void |
| 532 | adj_nbr_midchain_update_rewrite (adj_index_t adj_index, |
| 533 | adj_midchain_fixup_t fixup, |
Neale Ranns | db14f5a | 2018-01-29 10:43:33 -0800 | [diff] [blame] | 534 | const void *fixup_data, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 535 | adj_flags_t flags, |
| 536 | u8 *rewrite) |
| 537 | { |
| 538 | ip_adjacency_t *adj; |
| 539 | |
| 540 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 541 | |
| 542 | adj = adj_get(adj_index); |
| 543 | |
| 544 | /* |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 545 | * one time only update. since we don't support changing the tunnel |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 546 | * src,dst, this is all we need. |
| 547 | */ |
Neale Ranns | 174959c | 2020-02-03 10:33:51 +0000 | [diff] [blame] | 548 | if (adj->lookup_next_index != IP_LOOKUP_NEXT_MIDCHAIN && |
Neale Ranns | 14053c9 | 2019-12-29 23:55:18 +0000 | [diff] [blame] | 549 | adj->lookup_next_index != IP_LOOKUP_NEXT_MCAST_MIDCHAIN) |
| 550 | { |
| 551 | adj_midchain_setup(adj_index, fixup, fixup_data, flags); |
| 552 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 553 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 554 | /* |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 555 | * update the rewrite with the workers paused. |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 556 | */ |
| 557 | adj_nbr_update_rewrite_internal(adj, |
| 558 | IP_LOOKUP_NEXT_MIDCHAIN, |
| 559 | adj_get_midchain_node(adj->ia_link), |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 560 | adj_nbr_midchain_get_tx_node(adj), |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 561 | rewrite); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | /** |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 565 | * adj_nbr_midchain_unstack |
| 566 | * |
| 567 | * Unstack the adj. stack it on drop |
| 568 | */ |
| 569 | void |
| 570 | adj_nbr_midchain_unstack (adj_index_t adj_index) |
| 571 | { |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 572 | fib_node_index_t *entry_indicies, tmp; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 573 | ip_adjacency_t *adj; |
| 574 | |
| 575 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 576 | adj = adj_get (adj_index); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 577 | |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 578 | /* |
| 579 | * check to see if this unstacking breaks a recursion loop |
| 580 | */ |
| 581 | entry_indicies = NULL; |
| 582 | tmp = adj->sub_type.midchain.fei; |
| 583 | adj->sub_type.midchain.fei = FIB_NODE_INDEX_INVALID; |
| 584 | |
| 585 | if (FIB_NODE_INDEX_INVALID != tmp) |
| 586 | { |
| 587 | fib_entry_recursive_loop_detect(tmp, &entry_indicies); |
| 588 | vec_free(entry_indicies); |
| 589 | } |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 590 | |
| 591 | /* |
| 592 | * stack on the drop |
| 593 | */ |
| 594 | dpo_stack(DPO_ADJACENCY_MIDCHAIN, |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 595 | vnet_link_to_dpo_proto(adj->ia_link), |
| 596 | &adj->sub_type.midchain.next_dpo, |
| 597 | drop_dpo_get(vnet_link_to_dpo_proto(adj->ia_link))); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 598 | CLIB_MEMORY_BARRIER(); |
| 599 | } |
| 600 | |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 601 | void |
| 602 | adj_nbr_midchain_stack_on_fib_entry (adj_index_t ai, |
| 603 | fib_node_index_t fei, |
| 604 | fib_forward_chain_type_t fct) |
| 605 | { |
| 606 | fib_node_index_t *entry_indicies; |
| 607 | dpo_id_t tmp = DPO_INVALID; |
| 608 | ip_adjacency_t *adj; |
| 609 | |
| 610 | adj = adj_get (ai); |
| 611 | |
| 612 | /* |
| 613 | * check to see if this stacking will form a recursion loop |
| 614 | */ |
| 615 | entry_indicies = NULL; |
| 616 | adj->sub_type.midchain.fei = fei; |
| 617 | |
| 618 | if (fib_entry_recursive_loop_detect(adj->sub_type.midchain.fei, &entry_indicies)) |
| 619 | { |
| 620 | /* |
| 621 | * loop formed, stack on the drop. |
| 622 | */ |
| 623 | dpo_copy(&tmp, drop_dpo_get(fib_forw_chain_type_to_dpo_proto(fct))); |
| 624 | } |
| 625 | else |
| 626 | { |
| 627 | fib_entry_contribute_forwarding (fei, fct, &tmp); |
| 628 | |
| 629 | if ((adj->ia_flags & ADJ_FLAG_MIDCHAIN_IP_STACK) && |
| 630 | (DPO_LOAD_BALANCE == tmp.dpoi_type)) |
| 631 | { |
| 632 | /* |
| 633 | * do that hash now and stack on the choice. |
| 634 | * If the choice is an incomplete adj then we will need a poke when |
| 635 | * it becomes complete. This happens since the adj update walk propagates |
| 636 | * as far a recursive paths. |
| 637 | */ |
| 638 | const dpo_id_t *choice; |
| 639 | load_balance_t *lb; |
| 640 | int hash; |
| 641 | |
| 642 | lb = load_balance_get (tmp.dpoi_index); |
| 643 | |
| 644 | if (FIB_FORW_CHAIN_TYPE_UNICAST_IP4 == fct) |
| 645 | { |
| 646 | hash = ip4_compute_flow_hash ((ip4_header_t *) adj_get_rewrite (ai), |
| 647 | lb->lb_hash_config); |
| 648 | } |
| 649 | else if (FIB_FORW_CHAIN_TYPE_UNICAST_IP6 == fct) |
| 650 | { |
| 651 | hash = ip6_compute_flow_hash ((ip6_header_t *) adj_get_rewrite (ai), |
| 652 | lb->lb_hash_config); |
| 653 | } |
| 654 | else |
| 655 | { |
| 656 | hash = 0; |
| 657 | ASSERT(0); |
| 658 | } |
| 659 | |
| 660 | choice = load_balance_get_bucket_i (lb, hash & lb->lb_n_buckets_minus_1); |
| 661 | dpo_copy (&tmp, choice); |
| 662 | } |
| 663 | } |
| 664 | adj_nbr_midchain_stack (ai, &tmp); |
| 665 | dpo_reset(&tmp); |
| 666 | vec_free(entry_indicies); |
| 667 | } |
| 668 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 669 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 670 | * adj_nbr_midchain_stack |
| 671 | */ |
| 672 | void |
| 673 | adj_nbr_midchain_stack (adj_index_t adj_index, |
| 674 | const dpo_id_t *next) |
| 675 | { |
| 676 | ip_adjacency_t *adj; |
| 677 | |
| 678 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 679 | |
| 680 | adj = adj_get(adj_index); |
| 681 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 682 | ASSERT((IP_LOOKUP_NEXT_MIDCHAIN == adj->lookup_next_index) || |
| 683 | (IP_LOOKUP_NEXT_MCAST_MIDCHAIN == adj->lookup_next_index)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 684 | |
Neale Ranns | fa5d198 | 2017-02-20 14:19:51 -0800 | [diff] [blame] | 685 | dpo_stack_from_node(adj_nbr_midchain_get_tx_node(adj), |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 686 | &adj->sub_type.midchain.next_dpo, |
| 687 | next); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 688 | } |
| 689 | |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 690 | int |
| 691 | adj_ndr_midchain_recursive_loop_detect (adj_index_t ai, |
| 692 | fib_node_index_t **entry_indicies) |
| 693 | { |
| 694 | fib_node_index_t *entry_index, *entries; |
| 695 | ip_adjacency_t * adj; |
| 696 | |
| 697 | adj = adj_get(ai); |
| 698 | entries = *entry_indicies; |
| 699 | |
| 700 | vec_foreach(entry_index, entries) |
| 701 | { |
| 702 | if (*entry_index == adj->sub_type.midchain.fei) |
| 703 | { |
| 704 | /* |
| 705 | * The entry this midchain links to is already in the set |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 706 | * of visited entries, this is a loop |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 707 | */ |
| 708 | adj->ia_flags |= ADJ_FLAG_MIDCHAIN_LOOPED; |
| 709 | return (1); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | adj->ia_flags &= ~ADJ_FLAG_MIDCHAIN_LOOPED; |
| 714 | return (0); |
| 715 | } |
| 716 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 717 | u8* |
| 718 | format_adj_midchain (u8* s, va_list *ap) |
| 719 | { |
Billy McFall | cfcf1e2 | 2016-10-14 09:51:49 -0400 | [diff] [blame] | 720 | index_t index = va_arg(*ap, index_t); |
| 721 | u32 indent = va_arg(*ap, u32); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 722 | ip_adjacency_t * adj = adj_get(index); |
| 723 | |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 724 | s = format (s, "%U", format_vnet_link, adj->ia_link); |
Neale Ranns | 25edf14 | 2019-03-22 08:12:48 +0000 | [diff] [blame] | 725 | if (adj->rewrite_header.flags & VNET_REWRITE_HAS_FEATURES) |
| 726 | s = format(s, " [features]"); |
Neale Ranns | c819fc6 | 2018-02-16 02:44:05 -0800 | [diff] [blame] | 727 | s = format (s, " via %U", |
| 728 | format_ip46_address, &adj->sub_type.nbr.next_hop, |
| 729 | adj_proto_to_46(adj->ia_nh_proto)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 730 | s = format (s, " %U", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 731 | format_vnet_rewrite, |
Neale Ranns | b069a69 | 2017-03-15 12:34:25 -0400 | [diff] [blame] | 732 | &adj->rewrite_header, sizeof (adj->rewrite_data), indent); |
Neale Ranns | 521a8d7 | 2018-12-06 13:46:49 +0000 | [diff] [blame] | 733 | s = format (s, "\n%Ustacked-on", |
| 734 | format_white_space, indent); |
| 735 | |
| 736 | if (FIB_NODE_INDEX_INVALID != adj->sub_type.midchain.fei) |
| 737 | { |
| 738 | s = format (s, " entry:%d", adj->sub_type.midchain.fei); |
| 739 | |
| 740 | } |
| 741 | s = format (s, ":\n%U%U", |
Neale Ranns | 43161a8 | 2017-08-12 02:12:00 -0700 | [diff] [blame] | 742 | format_white_space, indent+2, |
| 743 | format_dpo_id, &adj->sub_type.midchain.next_dpo, indent+2); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 744 | |
| 745 | return (s); |
| 746 | } |
| 747 | |
| 748 | static void |
| 749 | adj_dpo_lock (dpo_id_t *dpo) |
| 750 | { |
| 751 | adj_lock(dpo->dpoi_index); |
| 752 | } |
| 753 | static void |
| 754 | adj_dpo_unlock (dpo_id_t *dpo) |
| 755 | { |
| 756 | adj_unlock(dpo->dpoi_index); |
| 757 | } |
| 758 | |
| 759 | const static dpo_vft_t adj_midchain_dpo_vft = { |
| 760 | .dv_lock = adj_dpo_lock, |
| 761 | .dv_unlock = adj_dpo_unlock, |
| 762 | .dv_format = format_adj_midchain, |
Andrew Yourtchenko | 5f3fcb9 | 2017-10-25 05:50:37 -0700 | [diff] [blame] | 763 | .dv_get_urpf = adj_dpo_get_urpf, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 764 | }; |
| 765 | |
| 766 | /** |
| 767 | * @brief The per-protocol VLIB graph nodes that are assigned to a midchain |
| 768 | * object. |
| 769 | * |
| 770 | * this means that these graph nodes are ones from which a midchain is the |
| 771 | * parent object in the DPO-graph. |
| 772 | */ |
| 773 | const static char* const midchain_ip4_nodes[] = |
| 774 | { |
| 775 | "ip4-midchain", |
| 776 | NULL, |
| 777 | }; |
| 778 | const static char* const midchain_ip6_nodes[] = |
| 779 | { |
| 780 | "ip6-midchain", |
| 781 | NULL, |
| 782 | }; |
| 783 | const static char* const midchain_mpls_nodes[] = |
| 784 | { |
| 785 | "mpls-midchain", |
| 786 | NULL, |
| 787 | }; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 788 | const static char* const midchain_ethernet_nodes[] = |
| 789 | { |
| 790 | "adj-l2-midchain", |
| 791 | NULL, |
| 792 | }; |
Florin Coras | b69111e | 2017-02-13 23:55:27 -0800 | [diff] [blame] | 793 | const static char* const midchain_nsh_nodes[] = |
| 794 | { |
| 795 | "adj-nsh-midchain", |
| 796 | NULL, |
| 797 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 798 | |
| 799 | const static char* const * const midchain_nodes[DPO_PROTO_NUM] = |
| 800 | { |
| 801 | [DPO_PROTO_IP4] = midchain_ip4_nodes, |
| 802 | [DPO_PROTO_IP6] = midchain_ip6_nodes, |
| 803 | [DPO_PROTO_MPLS] = midchain_mpls_nodes, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 804 | [DPO_PROTO_ETHERNET] = midchain_ethernet_nodes, |
Florin Coras | b69111e | 2017-02-13 23:55:27 -0800 | [diff] [blame] | 805 | [DPO_PROTO_NSH] = midchain_nsh_nodes, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 806 | }; |
| 807 | |
| 808 | void |
| 809 | adj_midchain_module_init (void) |
| 810 | { |
| 811 | dpo_register(DPO_ADJACENCY_MIDCHAIN, &adj_midchain_dpo_vft, midchain_nodes); |
| 812 | } |