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