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> |
| 23 | #include <vnet/fib/fib_walk.h> |
| 24 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 25 | /** |
| 26 | * The two midchain tx feature node indices |
| 27 | */ |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 28 | static u32 adj_midchain_tx_feature_node[VNET_LINK_NUM]; |
| 29 | static u32 adj_midchain_tx_no_count_feature_node[VNET_LINK_NUM]; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * @brief Trace data for packets traversing the midchain tx node |
| 33 | */ |
| 34 | typedef struct adj_midchain_tx_trace_t_ |
| 35 | { |
| 36 | /** |
| 37 | * @brief the midchain adj we are traversing |
| 38 | */ |
| 39 | adj_index_t ai; |
| 40 | } adj_midchain_tx_trace_t; |
| 41 | |
| 42 | always_inline uword |
Damjan Marion | 77766a1 | 2016-11-02 01:21:05 +0100 | [diff] [blame] | 43 | adj_midchain_tx_inline (vlib_main_t * vm, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 44 | vlib_node_runtime_t * node, |
| 45 | vlib_frame_t * frame, |
| 46 | int interface_count) |
| 47 | { |
| 48 | u32 * from, * to_next, n_left_from, n_left_to_next; |
| 49 | u32 next_index; |
| 50 | vnet_main_t *vnm = vnet_get_main (); |
| 51 | vnet_interface_main_t *im = &vnm->interface_main; |
| 52 | u32 cpu_index = vm->cpu_index; |
| 53 | |
| 54 | /* Vector of buffer / pkt indices we're supposed to process */ |
| 55 | from = vlib_frame_vector_args (frame); |
| 56 | |
| 57 | /* Number of buffers / pkts */ |
| 58 | n_left_from = frame->n_vectors; |
| 59 | |
| 60 | /* Speculatively send the first buffer to the last disposition we used */ |
| 61 | next_index = node->cached_next_index; |
| 62 | |
| 63 | while (n_left_from > 0) |
| 64 | { |
| 65 | /* set up to enqueue to our disposition with index = next_index */ |
| 66 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 67 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 68 | |
Neale Ranns | d3b85b0 | 2016-10-22 15:17:21 -0700 | [diff] [blame] | 69 | while (n_left_from >= 4 && n_left_to_next > 2) |
| 70 | { |
| 71 | u32 bi0, adj_index0, next0; |
| 72 | const ip_adjacency_t * adj0; |
| 73 | const dpo_id_t *dpo0; |
| 74 | vlib_buffer_t * b0; |
| 75 | u32 bi1, adj_index1, next1; |
| 76 | const ip_adjacency_t * adj1; |
| 77 | const dpo_id_t *dpo1; |
| 78 | vlib_buffer_t * b1; |
| 79 | |
| 80 | /* Prefetch next iteration. */ |
| 81 | { |
| 82 | vlib_buffer_t * p2, * p3; |
| 83 | |
| 84 | p2 = vlib_get_buffer (vm, from[2]); |
| 85 | p3 = vlib_get_buffer (vm, from[3]); |
| 86 | |
| 87 | vlib_prefetch_buffer_header (p2, LOAD); |
| 88 | vlib_prefetch_buffer_header (p3, LOAD); |
| 89 | |
| 90 | CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 91 | CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 92 | } |
| 93 | |
| 94 | bi0 = from[0]; |
| 95 | to_next[0] = bi0; |
| 96 | bi1 = from[1]; |
| 97 | to_next[1] = bi1; |
| 98 | |
| 99 | from += 2; |
| 100 | to_next += 2; |
| 101 | n_left_from -= 2; |
| 102 | n_left_to_next -= 2; |
| 103 | |
| 104 | b0 = vlib_get_buffer(vm, bi0); |
| 105 | b1 = vlib_get_buffer(vm, bi1); |
| 106 | |
| 107 | /* Follow the DPO on which the midchain is stacked */ |
| 108 | adj_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; |
| 109 | adj_index1 = vnet_buffer(b1)->ip.adj_index[VLIB_TX]; |
| 110 | |
| 111 | adj0 = adj_get(adj_index0); |
| 112 | adj1 = adj_get(adj_index1); |
| 113 | |
| 114 | dpo0 = &adj0->sub_type.midchain.next_dpo; |
| 115 | dpo1 = &adj1->sub_type.midchain.next_dpo; |
| 116 | |
| 117 | next0 = dpo0->dpoi_next_node; |
| 118 | next1 = dpo1->dpoi_next_node; |
| 119 | |
| 120 | vnet_buffer(b1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index; |
| 121 | vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; |
| 122 | |
| 123 | if (interface_count) |
| 124 | { |
| 125 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 126 | + VNET_INTERFACE_COUNTER_TX, |
| 127 | cpu_index, |
| 128 | adj0->rewrite_header.sw_if_index, |
| 129 | 1, |
| 130 | vlib_buffer_length_in_chain (vm, b0)); |
| 131 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 132 | + VNET_INTERFACE_COUNTER_TX, |
| 133 | cpu_index, |
| 134 | adj1->rewrite_header.sw_if_index, |
| 135 | 1, |
| 136 | vlib_buffer_length_in_chain (vm, b1)); |
| 137 | } |
| 138 | |
| 139 | if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 140 | { |
| 141 | adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, |
| 142 | b0, sizeof (*tr)); |
| 143 | tr->ai = adj_index0; |
| 144 | } |
| 145 | if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED)) |
| 146 | { |
| 147 | adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, |
| 148 | b1, sizeof (*tr)); |
| 149 | tr->ai = adj_index1; |
| 150 | } |
| 151 | |
| 152 | vlib_validate_buffer_enqueue_x2 (vm, node, next_index, |
| 153 | to_next, n_left_to_next, |
| 154 | bi0, bi1, |
| 155 | next0, next1); |
| 156 | } |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 157 | while (n_left_from > 0 && n_left_to_next > 0) |
| 158 | { |
| 159 | u32 bi0, adj_index0, next0; |
| 160 | const ip_adjacency_t * adj0; |
| 161 | const dpo_id_t *dpo0; |
| 162 | vlib_buffer_t * b0; |
| 163 | |
| 164 | bi0 = from[0]; |
| 165 | to_next[0] = bi0; |
| 166 | from += 1; |
| 167 | to_next += 1; |
| 168 | n_left_from -= 1; |
| 169 | n_left_to_next -= 1; |
| 170 | |
| 171 | b0 = vlib_get_buffer(vm, bi0); |
| 172 | |
| 173 | /* Follow the DPO on which the midchain is stacked */ |
| 174 | adj_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; |
| 175 | adj0 = adj_get(adj_index0); |
| 176 | dpo0 = &adj0->sub_type.midchain.next_dpo; |
| 177 | next0 = dpo0->dpoi_next_node; |
| 178 | vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; |
| 179 | |
| 180 | if (interface_count) |
| 181 | { |
| 182 | vlib_increment_combined_counter (im->combined_sw_if_counters |
| 183 | + VNET_INTERFACE_COUNTER_TX, |
| 184 | cpu_index, |
| 185 | adj0->rewrite_header.sw_if_index, |
| 186 | 1, |
| 187 | vlib_buffer_length_in_chain (vm, b0)); |
| 188 | } |
| 189 | |
| 190 | if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) |
| 191 | { |
| 192 | adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, |
| 193 | b0, sizeof (*tr)); |
| 194 | tr->ai = adj_index0; |
| 195 | } |
| 196 | |
| 197 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 198 | to_next, n_left_to_next, |
| 199 | bi0, next0); |
| 200 | } |
| 201 | |
| 202 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 203 | } |
| 204 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 205 | return frame->n_vectors; |
| 206 | } |
| 207 | |
| 208 | static u8 * |
| 209 | format_adj_midchain_tx_trace (u8 * s, va_list * args) |
| 210 | { |
| 211 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 212 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 213 | adj_midchain_tx_trace_t *tr = va_arg (*args, adj_midchain_tx_trace_t*); |
| 214 | |
| 215 | s = format(s, "adj-midchain:[%d]:%U", tr->ai, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 216 | format_ip_adjacency, tr->ai, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 217 | FORMAT_IP_ADJACENCY_NONE); |
| 218 | |
| 219 | return (s); |
| 220 | } |
| 221 | |
| 222 | static uword |
| 223 | adj_midchain_tx (vlib_main_t * vm, |
| 224 | vlib_node_runtime_t * node, |
| 225 | vlib_frame_t * frame) |
| 226 | { |
Damjan Marion | 77766a1 | 2016-11-02 01:21:05 +0100 | [diff] [blame] | 227 | return (adj_midchain_tx_inline(vm, node, frame, 1)); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | VLIB_REGISTER_NODE (adj_midchain_tx_node, static) = { |
| 231 | .function = adj_midchain_tx, |
| 232 | .name = "adj-midchain-tx", |
| 233 | .vector_size = sizeof (u32), |
| 234 | |
| 235 | .format_trace = format_adj_midchain_tx_trace, |
| 236 | |
| 237 | .n_next_nodes = 1, |
| 238 | .next_nodes = { |
| 239 | [0] = "error-drop", |
| 240 | }, |
| 241 | }; |
| 242 | |
| 243 | static uword |
| 244 | adj_midchain_tx_no_count (vlib_main_t * vm, |
| 245 | vlib_node_runtime_t * node, |
| 246 | vlib_frame_t * frame) |
| 247 | { |
Damjan Marion | 77766a1 | 2016-11-02 01:21:05 +0100 | [diff] [blame] | 248 | return (adj_midchain_tx_inline(vm, node, frame, 0)); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | VLIB_REGISTER_NODE (adj_midchain_tx_no_count_node, static) = { |
| 252 | .function = adj_midchain_tx_no_count, |
| 253 | .name = "adj-midchain-tx-no-count", |
| 254 | .vector_size = sizeof (u32), |
| 255 | |
| 256 | .format_trace = format_adj_midchain_tx_trace, |
| 257 | |
| 258 | .n_next_nodes = 1, |
| 259 | .next_nodes = { |
| 260 | [0] = "error-drop", |
| 261 | }, |
| 262 | }; |
| 263 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 264 | VNET_FEATURE_INIT (adj_midchain_tx_ip4, static) = { |
| 265 | .arc_name = "ip4-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 266 | .node_name = "adj-midchain-tx", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 267 | .runs_before = VNET_FEATURES ("interface-output"), |
| 268 | .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_IP4], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 269 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 270 | VNET_FEATURE_INIT (adj_midchain_tx_no_count_ip4, static) = { |
| 271 | .arc_name = "ip4-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 272 | .node_name = "adj-midchain-tx-no-count", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 273 | .runs_before = VNET_FEATURES ("interface-output"), |
| 274 | .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] | 275 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 276 | VNET_FEATURE_INIT (adj_midchain_tx_ip6, static) = { |
| 277 | .arc_name = "ip6-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 278 | .node_name = "adj-midchain-tx", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 279 | .runs_before = VNET_FEATURES ("interface-output"), |
| 280 | .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_IP6], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 281 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 282 | VNET_FEATURE_INIT (adj_midchain_tx_no_count_ip6, static) = { |
| 283 | .arc_name = "ip6-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 284 | .node_name = "adj-midchain-tx-no-count", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 285 | .runs_before = VNET_FEATURES ("interface-output"), |
| 286 | .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] | 287 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 288 | VNET_FEATURE_INIT (adj_midchain_tx_mpls, static) = { |
| 289 | .arc_name = "mpls-output", |
Damjan Marion | 77766a1 | 2016-11-02 01:21:05 +0100 | [diff] [blame] | 290 | .node_name = "adj-midchain-tx", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 291 | .runs_before = VNET_FEATURES ("interface-output"), |
| 292 | .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_MPLS], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 293 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 294 | VNET_FEATURE_INIT (adj_midchain_tx_no_count_mpls, static) = { |
| 295 | .arc_name = "mpls-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 296 | .node_name = "adj-midchain-tx-no-count", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 297 | .runs_before = VNET_FEATURES ("interface-output"), |
| 298 | .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] | 299 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 300 | VNET_FEATURE_INIT (adj_midchain_tx_ethernet, static) = { |
| 301 | .arc_name = "ethernet-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 302 | .node_name = "adj-midchain-tx", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 303 | .runs_before = VNET_FEATURES ("error-drop"), |
| 304 | .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_ETHERNET], |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 305 | }; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 306 | VNET_FEATURE_INIT (adj_midchain_tx_no_count_ethernet, static) = { |
| 307 | .arc_name = "ethernet-output", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 308 | .node_name = "adj-midchain-tx-no-count", |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 309 | .runs_before = VNET_FEATURES ("error-drop"), |
| 310 | .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] | 311 | }; |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 312 | VNET_FEATURE_INIT (adj_midchain_tx_nsh, static) = { |
| 313 | .arc_name = "nsh-output", |
| 314 | .node_name = "adj-midchain-tx", |
| 315 | .runs_before = VNET_FEATURES ("error-drop"), |
| 316 | .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_NSH], |
| 317 | }; |
| 318 | VNET_FEATURE_INIT (adj_midchain_tx_no_count_nsh, static) = { |
| 319 | .arc_name = "nsh-output", |
| 320 | .node_name = "adj-midchain-tx-no-count", |
| 321 | .runs_before = VNET_FEATURES ("error-drop"), |
| 322 | .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_NSH], |
| 323 | }; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 324 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 325 | static inline u32 |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 326 | adj_get_midchain_node (vnet_link_t link) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 327 | { |
| 328 | switch (link) { |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 329 | case VNET_LINK_IP4: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 330 | return (ip4_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 331 | case VNET_LINK_IP6: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 332 | return (ip6_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 333 | case VNET_LINK_MPLS: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 334 | return (mpls_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 335 | case VNET_LINK_ETHERNET: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 336 | return (adj_l2_midchain_node.index); |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 337 | case VNET_LINK_NSH: |
| 338 | return (adj_nsh_midchain_node.index); |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 339 | case VNET_LINK_ARP: |
| 340 | break; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 341 | } |
| 342 | ASSERT(0); |
| 343 | return (0); |
| 344 | } |
| 345 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 346 | static u8 |
| 347 | 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] | 348 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 349 | u8 arc = (u8) ~0; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 350 | switch (adj->ia_link) |
| 351 | { |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 352 | case VNET_LINK_IP4: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 353 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 354 | arc = ip4_main.lookup_main.output_feature_arc_index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 355 | break; |
| 356 | } |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 357 | case VNET_LINK_IP6: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 358 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 359 | arc = ip6_main.lookup_main.output_feature_arc_index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 360 | break; |
| 361 | } |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 362 | case VNET_LINK_MPLS: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 363 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 364 | arc = mpls_main.output_feature_arc_index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 365 | break; |
| 366 | } |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 367 | case VNET_LINK_ETHERNET: |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 368 | { |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 369 | arc = ethernet_main.output_feature_arc_index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 370 | break; |
| 371 | } |
Florin Coras | ce1b4c7 | 2017-01-26 14:25:34 -0800 | [diff] [blame] | 372 | case VNET_LINK_NSH: |
| 373 | { |
| 374 | arc = nsh_main_dummy.output_feature_arc_index; |
| 375 | break; |
| 376 | } |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 377 | case VNET_LINK_ARP: |
| 378 | ASSERT(0); |
| 379 | break; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 380 | } |
| 381 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 382 | ASSERT (arc != (u8) ~0); |
| 383 | |
| 384 | return (arc); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 385 | } |
| 386 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 387 | /** |
| 388 | * adj_nbr_midchain_update_rewrite |
| 389 | * |
| 390 | * Update the adjacency's rewrite string. A NULL string implies the |
| 391 | * rewrite is reset (i.e. when ARP/ND etnry is gone). |
| 392 | * NB: the adj being updated may be handling traffic in the DP. |
| 393 | */ |
| 394 | void |
| 395 | adj_nbr_midchain_update_rewrite (adj_index_t adj_index, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 396 | adj_midchain_fixup_t fixup, |
| 397 | adj_midchain_flag_t flags, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 398 | u8 *rewrite) |
| 399 | { |
| 400 | ip_adjacency_t *adj; |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 401 | u8 arc_index; |
| 402 | u32 feature_index; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 403 | |
| 404 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 405 | |
| 406 | adj = adj_get(adj_index); |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 407 | |
| 408 | /* |
| 409 | * one time only update. since we don't support chainging the tunnel |
| 410 | * src,dst, this is all we need. |
| 411 | */ |
| 412 | ASSERT(adj->lookup_next_index == IP_LOOKUP_NEXT_ARP); |
| 413 | /* |
| 414 | * tunnels can always provide a rewrite. |
| 415 | */ |
| 416 | ASSERT(NULL != rewrite); |
| 417 | |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 418 | adj->sub_type.midchain.fixup_func = fixup; |
| 419 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 420 | arc_index = adj_midchain_get_feature_arc_index_for_link_type (adj); |
| 421 | feature_index = (flags & ADJ_MIDCHAIN_FLAG_NO_COUNT) ? |
| 422 | adj_midchain_tx_no_count_feature_node[adj->ia_link] : |
| 423 | adj_midchain_tx_feature_node[adj->ia_link]; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 424 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 425 | adj->sub_type.midchain.tx_function_node = (flags & ADJ_MIDCHAIN_FLAG_NO_COUNT) ? |
| 426 | adj_midchain_tx_no_count_node.index : |
| 427 | adj_midchain_tx_node.index; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 428 | |
Damjan Marion | 8b3191e | 2016-11-09 19:54:20 +0100 | [diff] [blame] | 429 | vnet_feature_enable_disable_with_index (arc_index, feature_index, |
| 430 | adj->rewrite_header.sw_if_index, |
| 431 | 1 /* enable */, 0, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 432 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 433 | /* |
| 434 | * stack the midchain on the drop so it's ready to forward in the adj-midchain-tx. |
| 435 | * The graph arc used/created here is from the midchain-tx node to the |
| 436 | * child's registered node. This is because post adj processing the next |
| 437 | * node are any output features, then the midchain-tx. from there we |
| 438 | * need to get to the stacked child's node. |
| 439 | */ |
| 440 | dpo_stack_from_node(adj->sub_type.midchain.tx_function_node, |
| 441 | &adj->sub_type.midchain.next_dpo, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 442 | drop_dpo_get(vnet_link_to_dpo_proto(adj->ia_link))); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 443 | |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 444 | /* |
| 445 | * update the rewirte with the workers paused. |
| 446 | */ |
| 447 | adj_nbr_update_rewrite_internal(adj, |
| 448 | IP_LOOKUP_NEXT_MIDCHAIN, |
| 449 | adj_get_midchain_node(adj->ia_link), |
| 450 | adj->sub_type.midchain.tx_function_node, |
| 451 | rewrite); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /** |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 455 | * adj_nbr_midchain_unstack |
| 456 | * |
| 457 | * Unstack the adj. stack it on drop |
| 458 | */ |
| 459 | void |
| 460 | adj_nbr_midchain_unstack (adj_index_t adj_index) |
| 461 | { |
| 462 | ip_adjacency_t *adj; |
| 463 | |
| 464 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 465 | |
| 466 | adj = adj_get(adj_index); |
| 467 | |
| 468 | /* |
| 469 | * stack on the drop |
| 470 | */ |
| 471 | dpo_stack(DPO_ADJACENCY_MIDCHAIN, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 472 | vnet_link_to_dpo_proto(adj->ia_link), |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 473 | &adj->sub_type.midchain.next_dpo, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 474 | drop_dpo_get(vnet_link_to_dpo_proto(adj->ia_link))); |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 475 | |
| 476 | CLIB_MEMORY_BARRIER(); |
| 477 | } |
| 478 | |
| 479 | /** |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 480 | * adj_nbr_midchain_stack |
| 481 | */ |
| 482 | void |
| 483 | adj_nbr_midchain_stack (adj_index_t adj_index, |
| 484 | const dpo_id_t *next) |
| 485 | { |
| 486 | ip_adjacency_t *adj; |
| 487 | |
| 488 | ASSERT(ADJ_INDEX_INVALID != adj_index); |
| 489 | |
| 490 | adj = adj_get(adj_index); |
| 491 | |
| 492 | ASSERT(IP_LOOKUP_NEXT_MIDCHAIN == adj->lookup_next_index); |
| 493 | |
| 494 | dpo_stack_from_node(adj->sub_type.midchain.tx_function_node, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 495 | &adj->sub_type.midchain.next_dpo, |
| 496 | next); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | u8* |
| 500 | format_adj_midchain (u8* s, va_list *ap) |
| 501 | { |
Billy McFall | cfcf1e2 | 2016-10-14 09:51:49 -0400 | [diff] [blame] | 502 | index_t index = va_arg(*ap, index_t); |
| 503 | u32 indent = va_arg(*ap, u32); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 504 | vnet_main_t * vnm = vnet_get_main(); |
| 505 | ip_adjacency_t * adj = adj_get(index); |
| 506 | |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 507 | s = format (s, "%U", format_vnet_link, adj->ia_link); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 508 | s = format (s, " via %U ", |
| 509 | format_ip46_address, &adj->sub_type.nbr.next_hop); |
| 510 | s = format (s, " %U", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 511 | format_vnet_rewrite, |
| 512 | vnm->vlib_main, &adj->rewrite_header, |
| 513 | sizeof (adj->rewrite_data), indent); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 514 | s = format (s, "\n%Ustacked-on:\n%U%U", |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 515 | format_white_space, indent, |
| 516 | format_white_space, indent+2, |
| 517 | format_dpo_id, &adj->sub_type.midchain.next_dpo, indent+2); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 518 | |
| 519 | return (s); |
| 520 | } |
| 521 | |
| 522 | static void |
| 523 | adj_dpo_lock (dpo_id_t *dpo) |
| 524 | { |
| 525 | adj_lock(dpo->dpoi_index); |
| 526 | } |
| 527 | static void |
| 528 | adj_dpo_unlock (dpo_id_t *dpo) |
| 529 | { |
| 530 | adj_unlock(dpo->dpoi_index); |
| 531 | } |
| 532 | |
| 533 | const static dpo_vft_t adj_midchain_dpo_vft = { |
| 534 | .dv_lock = adj_dpo_lock, |
| 535 | .dv_unlock = adj_dpo_unlock, |
| 536 | .dv_format = format_adj_midchain, |
| 537 | }; |
| 538 | |
| 539 | /** |
| 540 | * @brief The per-protocol VLIB graph nodes that are assigned to a midchain |
| 541 | * object. |
| 542 | * |
| 543 | * this means that these graph nodes are ones from which a midchain is the |
| 544 | * parent object in the DPO-graph. |
| 545 | */ |
| 546 | const static char* const midchain_ip4_nodes[] = |
| 547 | { |
| 548 | "ip4-midchain", |
| 549 | NULL, |
| 550 | }; |
| 551 | const static char* const midchain_ip6_nodes[] = |
| 552 | { |
| 553 | "ip6-midchain", |
| 554 | NULL, |
| 555 | }; |
| 556 | const static char* const midchain_mpls_nodes[] = |
| 557 | { |
| 558 | "mpls-midchain", |
| 559 | NULL, |
| 560 | }; |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 561 | const static char* const midchain_ethernet_nodes[] = |
| 562 | { |
| 563 | "adj-l2-midchain", |
| 564 | NULL, |
| 565 | }; |
Florin Coras | b69111e | 2017-02-13 23:55:27 -0800 | [diff] [blame] | 566 | const static char* const midchain_nsh_nodes[] = |
| 567 | { |
| 568 | "adj-nsh-midchain", |
| 569 | NULL, |
| 570 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 571 | |
| 572 | const static char* const * const midchain_nodes[DPO_PROTO_NUM] = |
| 573 | { |
| 574 | [DPO_PROTO_IP4] = midchain_ip4_nodes, |
| 575 | [DPO_PROTO_IP6] = midchain_ip6_nodes, |
| 576 | [DPO_PROTO_MPLS] = midchain_mpls_nodes, |
Neale Ranns | 5e575b1 | 2016-10-03 09:40:25 +0100 | [diff] [blame] | 577 | [DPO_PROTO_ETHERNET] = midchain_ethernet_nodes, |
Florin Coras | b69111e | 2017-02-13 23:55:27 -0800 | [diff] [blame] | 578 | [DPO_PROTO_NSH] = midchain_nsh_nodes, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 579 | }; |
| 580 | |
| 581 | void |
| 582 | adj_midchain_module_init (void) |
| 583 | { |
| 584 | dpo_register(DPO_ADJACENCY_MIDCHAIN, &adj_midchain_dpo_vft, midchain_nodes); |
| 585 | } |