Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * l2_uu_fwd.c : Foward unknown unicast packets to BD's configured interface |
| 3 | * |
| 4 | * Copyright (c) 2018 Cisco and/or its affiliates. |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <vnet/l2/l2_bd.h> |
| 19 | #include <vnet/l2/l2_input.h> |
| 20 | |
| 21 | #define foreach_l2_uu_fwd_error \ |
| 22 | _(L2_UU_FWD, "L2 UU fwd") |
| 23 | |
| 24 | typedef enum |
| 25 | { |
| 26 | #define _(sym,str) L2_UU_FWD_ERROR_##sym, |
| 27 | foreach_l2_uu_fwd_error |
| 28 | #undef _ |
| 29 | L2_UU_FWD_N_ERROR, |
| 30 | } l2_uu_fwd_error_t; |
| 31 | |
| 32 | static char *l2_uu_fwd_error_strings[] = { |
| 33 | #define _(sym,string) string, |
| 34 | foreach_l2_uu_fwd_error |
| 35 | #undef _ |
| 36 | }; |
| 37 | |
| 38 | typedef enum |
| 39 | { |
| 40 | L2_UU_FWD_NEXT_DROP, |
| 41 | L2_UU_FWD_NEXT_L2_OUTPUT, |
| 42 | L2_UU_FWD_N_NEXT, |
| 43 | } l2_uu_fwd_next_t; |
| 44 | |
| 45 | typedef struct |
| 46 | { |
| 47 | u32 sw_if_index; |
| 48 | } l2_uu_fwd_trace_t; |
| 49 | |
| 50 | /* packet trace format function */ |
| 51 | static u8 * |
| 52 | format_l2_uu_fwd_trace (u8 * s, va_list * args) |
| 53 | { |
| 54 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 55 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
| 56 | l2_uu_fwd_trace_t *t = va_arg (*args, l2_uu_fwd_trace_t *); |
| 57 | |
| 58 | s = format (s, "l2-uu-fwd: sw_if_index %d", t->sw_if_index); |
| 59 | return s; |
| 60 | } |
| 61 | |
Filip Tehlar | 44f0f71 | 2019-03-11 04:26:37 -0700 | [diff] [blame] | 62 | VLIB_NODE_FN (l2_uu_fwd_node) (vlib_main_t * vm, |
| 63 | vlib_node_runtime_t * node, |
| 64 | vlib_frame_t * frame) |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 65 | { |
| 66 | u32 n_left_from, *from, *to_next; |
| 67 | l2_uu_fwd_next_t next_index; |
| 68 | |
| 69 | from = vlib_frame_vector_args (frame); |
| 70 | n_left_from = frame->n_vectors; |
| 71 | next_index = node->cached_next_index; |
| 72 | |
| 73 | while (n_left_from > 0) |
| 74 | { |
| 75 | u32 n_left_to_next; |
| 76 | |
| 77 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
| 78 | |
| 79 | while (n_left_from >= 8 && n_left_to_next >= 4) |
| 80 | { |
| 81 | const l2_bridge_domain_t *bdc0, *bdc1, *bdc2, *bdc3; |
| 82 | l2_uu_fwd_next_t next0, next1, next2, next3; |
| 83 | vlib_buffer_t *b0, *b1, *b2, *b3; |
| 84 | u32 bi0, bi1, bi2, bi3; |
| 85 | |
| 86 | { |
| 87 | vlib_buffer_t *b4, *b5, *b6, *b7; |
| 88 | |
| 89 | b4 = vlib_get_buffer (vm, from[4]); |
| 90 | b5 = vlib_get_buffer (vm, from[5]); |
| 91 | b6 = vlib_get_buffer (vm, from[6]); |
| 92 | b7 = vlib_get_buffer (vm, from[7]); |
| 93 | |
| 94 | vlib_prefetch_buffer_header (b4, STORE); |
| 95 | vlib_prefetch_buffer_header (b5, STORE); |
| 96 | vlib_prefetch_buffer_header (b6, STORE); |
| 97 | vlib_prefetch_buffer_header (b7, STORE); |
| 98 | } |
| 99 | bi0 = to_next[0] = from[0]; |
| 100 | bi1 = to_next[1] = from[1]; |
| 101 | bi2 = to_next[2] = from[2]; |
| 102 | bi3 = to_next[3] = from[3]; |
| 103 | |
| 104 | from += 4; |
| 105 | to_next += 4; |
| 106 | n_left_from -= 4; |
| 107 | n_left_to_next -= 4; |
| 108 | |
| 109 | next3 = next2 = next1 = next0 = L2_UU_FWD_NEXT_L2_OUTPUT; |
| 110 | |
| 111 | b0 = vlib_get_buffer (vm, bi0); |
| 112 | b1 = vlib_get_buffer (vm, bi1); |
| 113 | b2 = vlib_get_buffer (vm, bi2); |
| 114 | b3 = vlib_get_buffer (vm, bi3); |
| 115 | |
| 116 | bdc0 = vec_elt_at_index (l2input_main.bd_configs, |
| 117 | vnet_buffer (b0)->l2.bd_index); |
| 118 | bdc1 = vec_elt_at_index (l2input_main.bd_configs, |
| 119 | vnet_buffer (b1)->l2.bd_index); |
| 120 | bdc2 = vec_elt_at_index (l2input_main.bd_configs, |
| 121 | vnet_buffer (b2)->l2.bd_index); |
| 122 | bdc3 = vec_elt_at_index (l2input_main.bd_configs, |
| 123 | vnet_buffer (b3)->l2.bd_index); |
| 124 | |
| 125 | ASSERT (~0 != bdc0->uu_fwd_sw_if_index); |
| 126 | |
| 127 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = bdc0->uu_fwd_sw_if_index; |
| 128 | vnet_buffer (b1)->sw_if_index[VLIB_TX] = bdc1->uu_fwd_sw_if_index; |
| 129 | vnet_buffer (b2)->sw_if_index[VLIB_TX] = bdc2->uu_fwd_sw_if_index; |
| 130 | vnet_buffer (b3)->sw_if_index[VLIB_TX] = bdc3->uu_fwd_sw_if_index; |
| 131 | |
| 132 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && |
| 133 | (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 134 | { |
| 135 | l2_uu_fwd_trace_t *t; |
| 136 | |
| 137 | t = vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 138 | t->sw_if_index = bdc0->uu_fwd_sw_if_index; |
| 139 | } |
| 140 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && |
| 141 | (b1->flags & VLIB_BUFFER_IS_TRACED))) |
| 142 | { |
| 143 | l2_uu_fwd_trace_t *t; |
| 144 | |
| 145 | t = vlib_add_trace (vm, node, b1, sizeof (*t)); |
| 146 | t->sw_if_index = bdc1->uu_fwd_sw_if_index; |
| 147 | } |
| 148 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && |
| 149 | (b1->flags & VLIB_BUFFER_IS_TRACED))) |
| 150 | { |
| 151 | l2_uu_fwd_trace_t *t; |
| 152 | |
| 153 | t = vlib_add_trace (vm, node, b2, sizeof (*t)); |
| 154 | t->sw_if_index = bdc2->uu_fwd_sw_if_index; |
| 155 | } |
| 156 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && |
| 157 | (b1->flags & VLIB_BUFFER_IS_TRACED))) |
| 158 | { |
| 159 | l2_uu_fwd_trace_t *t; |
| 160 | |
| 161 | t = vlib_add_trace (vm, node, b3, sizeof (*t)); |
| 162 | t->sw_if_index = bdc3->uu_fwd_sw_if_index; |
| 163 | } |
| 164 | vlib_validate_buffer_enqueue_x4 (vm, node, next_index, |
| 165 | to_next, n_left_to_next, |
| 166 | bi0, bi1, bi2, bi3, |
| 167 | next0, next1, next2, next3); |
| 168 | } |
| 169 | |
| 170 | while (n_left_from > 0 && n_left_to_next > 0) |
| 171 | { |
| 172 | const l2_bridge_domain_t *bdc0; |
| 173 | l2_uu_fwd_next_t next0; |
| 174 | vlib_buffer_t *b0; |
| 175 | u32 bi0; |
| 176 | |
| 177 | bi0 = from[0]; |
| 178 | to_next[0] = bi0; |
| 179 | from += 1; |
| 180 | to_next += 1; |
| 181 | n_left_from -= 1; |
| 182 | n_left_to_next -= 1; |
| 183 | next0 = L2_UU_FWD_NEXT_L2_OUTPUT; |
| 184 | b0 = vlib_get_buffer (vm, bi0); |
| 185 | |
| 186 | bdc0 = vec_elt_at_index (l2input_main.bd_configs, |
| 187 | vnet_buffer (b0)->l2.bd_index); |
| 188 | ASSERT (~0 != bdc0->uu_fwd_sw_if_index); |
| 189 | |
| 190 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = bdc0->uu_fwd_sw_if_index; |
| 191 | |
| 192 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) && |
| 193 | (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 194 | { |
| 195 | l2_uu_fwd_trace_t *t; |
| 196 | |
| 197 | t = vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 198 | t->sw_if_index = bdc0->uu_fwd_sw_if_index; |
| 199 | } |
| 200 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 201 | to_next, n_left_to_next, |
| 202 | bi0, next0); |
| 203 | } |
| 204 | |
| 205 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 206 | } |
| 207 | |
| 208 | vlib_node_increment_counter (vm, node->node_index, |
| 209 | L2_UU_FWD_ERROR_L2_UU_FWD, frame->n_vectors); |
| 210 | |
| 211 | return frame->n_vectors; |
| 212 | } |
| 213 | |
Filip Tehlar | 44f0f71 | 2019-03-11 04:26:37 -0700 | [diff] [blame] | 214 | VLIB_REGISTER_NODE (l2_uu_fwd_node) = { |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 215 | .name = "l2-uu-fwd", |
| 216 | .vector_size = sizeof (u32), |
| 217 | .format_trace = format_l2_uu_fwd_trace, |
| 218 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 219 | |
| 220 | .n_errors = ARRAY_LEN(l2_uu_fwd_error_strings), |
| 221 | .error_strings = l2_uu_fwd_error_strings, |
| 222 | |
| 223 | .n_next_nodes = L2_UU_FWD_N_NEXT, |
| 224 | |
| 225 | .next_nodes = { |
| 226 | [L2_UU_FWD_NEXT_DROP] = "error-drop", |
| 227 | [L2_UU_FWD_NEXT_L2_OUTPUT] = "l2-output", |
| 228 | }, |
| 229 | }; |
Neale Ranns | b474380 | 2018-09-05 09:13:57 -0700 | [diff] [blame] | 230 | |
| 231 | /* |
| 232 | * fd.io coding-style-patch-verification: ON |
| 233 | * |
| 234 | * Local Variables: |
| 235 | * eval: (c-set-style "gnu") |
| 236 | * End: |
| 237 | */ |