Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * l2_input_acl.c : layer 2 input acl processing |
| 3 | * |
| 4 | * Copyright (c) 2013 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 <vlib/vlib.h> |
| 19 | #include <vnet/vnet.h> |
| 20 | #include <vnet/pg/pg.h> |
| 21 | #include <vnet/ethernet/ethernet.h> |
| 22 | #include <vnet/ethernet/packet.h> |
| 23 | #include <vnet/ip/ip_packet.h> |
| 24 | #include <vnet/ip/ip4_packet.h> |
| 25 | #include <vnet/ip/ip6_packet.h> |
| 26 | #include <vlib/cli.h> |
| 27 | #include <vnet/l2/l2_input.h> |
| 28 | #include <vnet/l2/feat_bitmap.h> |
| 29 | |
| 30 | #include <vppinfra/error.h> |
| 31 | #include <vppinfra/hash.h> |
| 32 | #include <vppinfra/cache.h> |
| 33 | |
| 34 | #include <vnet/classify/vnet_classify.h> |
| 35 | #include <vnet/classify/input_acl.h> |
| 36 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 37 | typedef struct |
| 38 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 40 | /* Next nodes for each feature */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 41 | u32 feat_next_node_index[32]; |
| 42 | |
| 43 | /* convenience variables */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 44 | vlib_main_t *vlib_main; |
| 45 | vnet_main_t *vnet_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | } l2_inacl_main_t; |
| 47 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 48 | typedef struct |
| 49 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | u32 sw_if_index; |
| 51 | u32 next_index; |
| 52 | u32 table_index; |
| 53 | u32 offset; |
| 54 | } l2_inacl_trace_t; |
| 55 | |
| 56 | /* packet trace format function */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 57 | static u8 * |
| 58 | format_l2_inacl_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 59 | { |
| 60 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 61 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 62 | l2_inacl_trace_t *t = va_arg (*args, l2_inacl_trace_t *); |
| 63 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | s = format (s, "INACL: sw_if_index %d, next_index %d, table %d, offset %d", |
| 65 | t->sw_if_index, t->next_index, t->table_index, t->offset); |
| 66 | return s; |
| 67 | } |
| 68 | |
| 69 | l2_inacl_main_t l2_inacl_main; |
| 70 | |
| 71 | static vlib_node_registration_t l2_inacl_node; |
| 72 | |
| 73 | #define foreach_l2_inacl_error \ |
| 74 | _(NONE, "valid input ACL packets") \ |
| 75 | _(MISS, "input ACL misses") \ |
| 76 | _(HIT, "input ACL hits") \ |
| 77 | _(CHAIN_HIT, "input ACL hits after chain walk") \ |
| 78 | _(TABLE_MISS, "input ACL table-miss drops") \ |
| 79 | _(SESSION_DENY, "input ACL session deny drops") |
| 80 | |
| 81 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 82 | typedef enum |
| 83 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | #define _(sym,str) L2_INACL_ERROR_##sym, |
| 85 | foreach_l2_inacl_error |
| 86 | #undef _ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 87 | L2_INACL_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | } l2_inacl_error_t; |
| 89 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 90 | static char *l2_inacl_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | #define _(sym,string) string, |
| 92 | foreach_l2_inacl_error |
| 93 | #undef _ |
| 94 | }; |
| 95 | |
| 96 | static uword |
| 97 | l2_inacl_node_fn (vlib_main_t * vm, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 98 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 100 | u32 n_left_from, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | acl_next_index_t next_index; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 102 | l2_inacl_main_t *msm = &l2_inacl_main; |
| 103 | input_acl_main_t *am = &input_acl_main; |
| 104 | vnet_classify_main_t *vcm = am->vnet_classify_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | input_acl_table_id_t tid = INPUT_ACL_TABLE_L2; |
| 106 | f64 now = vlib_time_now (vm); |
| 107 | u32 hits = 0; |
| 108 | u32 misses = 0; |
| 109 | u32 chain_hits = 0; |
| 110 | |
| 111 | from = vlib_frame_vector_args (frame); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 112 | n_left_from = frame->n_vectors; /* number of packets to process */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | next_index = node->cached_next_index; |
| 114 | |
| 115 | /* First pass: compute hashes */ |
| 116 | while (n_left_from > 2) |
| 117 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 118 | vlib_buffer_t *b0, *b1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | u32 bi0, bi1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 120 | u8 *h0, *h1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | u32 sw_if_index0, sw_if_index1; |
| 122 | u32 table_index0, table_index1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 123 | vnet_classify_table_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | |
| 125 | /* prefetch next iteration */ |
| 126 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 127 | vlib_buffer_t *p1, *p2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 128 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 129 | p1 = vlib_get_buffer (vm, from[1]); |
| 130 | p2 = vlib_get_buffer (vm, from[2]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 131 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 132 | vlib_prefetch_buffer_header (p1, STORE); |
| 133 | CLIB_PREFETCH (p1->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 134 | vlib_prefetch_buffer_header (p2, STORE); |
| 135 | CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | bi0 = from[0]; |
| 139 | b0 = vlib_get_buffer (vm, bi0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 140 | |
| 141 | bi1 = from[1]; |
| 142 | b1 = vlib_get_buffer (vm, bi1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | |
| 144 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 145 | table_index0 = |
| 146 | am->classify_table_index_by_sw_if_index[tid][sw_if_index0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 147 | |
| 148 | sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 149 | table_index1 = |
| 150 | am->classify_table_index_by_sw_if_index[tid][sw_if_index1]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | |
| 152 | t0 = pool_elt_at_index (vcm->tables, table_index0); |
| 153 | |
| 154 | t1 = pool_elt_at_index (vcm->tables, table_index1); |
| 155 | |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 156 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 157 | h0 = (void *) vlib_buffer_get_current (b0) + t0->current_data_offset; |
| 158 | else |
| 159 | h0 = b0->data; |
| 160 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 161 | vnet_buffer (b0)->l2_classify.hash = |
| 162 | vnet_classify_hash_packet (t0, (u8 *) h0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 163 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 164 | vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 165 | |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 166 | if (t1->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 167 | h1 = (void *) vlib_buffer_get_current (b1) + t1->current_data_offset; |
| 168 | else |
| 169 | h1 = b1->data; |
| 170 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 171 | vnet_buffer (b1)->l2_classify.hash = |
| 172 | vnet_classify_hash_packet (t1, (u8 *) h1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 173 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 174 | vnet_classify_prefetch_bucket (t1, vnet_buffer (b1)->l2_classify.hash); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 176 | vnet_buffer (b0)->l2_classify.table_index = table_index0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 177 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 178 | vnet_buffer (b1)->l2_classify.table_index = table_index1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | |
| 180 | from += 2; |
| 181 | n_left_from -= 2; |
| 182 | } |
| 183 | |
| 184 | while (n_left_from > 0) |
| 185 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 186 | vlib_buffer_t *b0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 187 | u32 bi0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 188 | u8 *h0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 189 | u32 sw_if_index0; |
| 190 | u32 table_index0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 191 | vnet_classify_table_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 192 | |
| 193 | bi0 = from[0]; |
| 194 | b0 = vlib_get_buffer (vm, bi0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | |
| 196 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 197 | table_index0 = |
| 198 | am->classify_table_index_by_sw_if_index[tid][sw_if_index0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 199 | |
| 200 | t0 = pool_elt_at_index (vcm->tables, table_index0); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 201 | |
| 202 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 203 | h0 = (void *) vlib_buffer_get_current (b0) + t0->current_data_offset; |
| 204 | else |
| 205 | h0 = b0->data; |
| 206 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 207 | vnet_buffer (b0)->l2_classify.hash = |
| 208 | vnet_classify_hash_packet (t0, (u8 *) h0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 209 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 210 | vnet_buffer (b0)->l2_classify.table_index = table_index0; |
| 211 | vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 212 | |
| 213 | from++; |
| 214 | n_left_from--; |
| 215 | } |
| 216 | |
| 217 | next_index = node->cached_next_index; |
| 218 | from = vlib_frame_vector_args (frame); |
| 219 | n_left_from = frame->n_vectors; |
| 220 | |
| 221 | while (n_left_from > 0) |
| 222 | { |
| 223 | u32 n_left_to_next; |
| 224 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 225 | vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | |
| 227 | /* Not enough load/store slots to dual loop... */ |
| 228 | while (n_left_from > 0 && n_left_to_next > 0) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 229 | { |
| 230 | u32 bi0; |
| 231 | vlib_buffer_t *b0; |
| 232 | u32 next0 = ACL_NEXT_INDEX_DENY; |
| 233 | u32 table_index0; |
| 234 | vnet_classify_table_t *t0; |
| 235 | vnet_classify_entry_t *e0; |
| 236 | u64 hash0; |
| 237 | u8 *h0; |
| 238 | u8 error0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 239 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 240 | /* Stride 3 seems to work best */ |
| 241 | if (PREDICT_TRUE (n_left_from > 3)) |
| 242 | { |
| 243 | vlib_buffer_t *p1 = vlib_get_buffer (vm, from[3]); |
| 244 | vnet_classify_table_t *tp1; |
| 245 | u32 table_index1; |
| 246 | u64 phash1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 247 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 248 | table_index1 = vnet_buffer (p1)->l2_classify.table_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 249 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 250 | if (PREDICT_TRUE (table_index1 != ~0)) |
| 251 | { |
| 252 | tp1 = pool_elt_at_index (vcm->tables, table_index1); |
| 253 | phash1 = vnet_buffer (p1)->l2_classify.hash; |
| 254 | vnet_classify_prefetch_entry (tp1, phash1); |
| 255 | } |
| 256 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 257 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 258 | /* speculatively enqueue b0 to the current next frame */ |
| 259 | bi0 = from[0]; |
| 260 | to_next[0] = bi0; |
| 261 | from += 1; |
| 262 | to_next += 1; |
| 263 | n_left_from -= 1; |
| 264 | n_left_to_next -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 266 | b0 = vlib_get_buffer (vm, bi0); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 267 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 268 | table_index0 = vnet_buffer (b0)->l2_classify.table_index; |
| 269 | e0 = 0; |
| 270 | t0 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 271 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 272 | vnet_buffer (b0)->l2_classify.opaque_index = ~0; |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 273 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 274 | /* Determine the next node */ |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 275 | next0 = vnet_l2_feature_next (b0, msm->feat_next_node_index, |
| 276 | L2INPUT_FEAT_ACL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 277 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 278 | if (PREDICT_TRUE (table_index0 != ~0)) |
| 279 | { |
| 280 | hash0 = vnet_buffer (b0)->l2_classify.hash; |
| 281 | t0 = pool_elt_at_index (vcm->tables, table_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 282 | |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 283 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 284 | h0 = |
| 285 | (void *) vlib_buffer_get_current (b0) + |
| 286 | t0->current_data_offset; |
| 287 | else |
| 288 | h0 = b0->data; |
| 289 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 290 | e0 = vnet_classify_find_entry (t0, (u8 *) h0, hash0, now); |
| 291 | if (e0) |
| 292 | { |
| 293 | vnet_buffer (b0)->l2_classify.opaque_index |
| 294 | = e0->opaque_index; |
| 295 | vlib_buffer_advance (b0, e0->advance); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 296 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 297 | next0 = (e0->next_index < ACL_NEXT_INDEX_N_NEXT) ? |
| 298 | e0->next_index : next0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 299 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 300 | hits++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 301 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 302 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 303 | L2_INACL_ERROR_SESSION_DENY : L2_INACL_ERROR_NONE; |
| 304 | b0->error = node->errors[error0]; |
| 305 | } |
| 306 | else |
| 307 | { |
| 308 | while (1) |
| 309 | { |
| 310 | if (PREDICT_TRUE (t0->next_table_index != ~0)) |
| 311 | t0 = pool_elt_at_index (vcm->tables, |
| 312 | t0->next_table_index); |
| 313 | else |
| 314 | { |
| 315 | next0 = |
| 316 | (t0->miss_next_index < |
| 317 | ACL_NEXT_INDEX_N_NEXT) ? t0->miss_next_index : |
| 318 | next0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 319 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 320 | misses++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 321 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 322 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 323 | L2_INACL_ERROR_TABLE_MISS : L2_INACL_ERROR_NONE; |
| 324 | b0->error = node->errors[error0]; |
| 325 | break; |
| 326 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 327 | |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 328 | if (t0->current_data_flag == |
| 329 | CLASSIFY_FLAG_USE_CURR_DATA) |
| 330 | h0 = |
| 331 | (void *) vlib_buffer_get_current (b0) + |
| 332 | t0->current_data_offset; |
| 333 | else |
| 334 | h0 = b0->data; |
| 335 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 336 | hash0 = vnet_classify_hash_packet (t0, (u8 *) h0); |
| 337 | e0 = vnet_classify_find_entry |
| 338 | (t0, (u8 *) h0, hash0, now); |
| 339 | if (e0) |
| 340 | { |
| 341 | vlib_buffer_advance (b0, e0->advance); |
| 342 | next0 = (e0->next_index < ACL_NEXT_INDEX_N_NEXT) ? |
| 343 | e0->next_index : next0; |
| 344 | hits++; |
| 345 | chain_hits++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 346 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 347 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 348 | L2_INACL_ERROR_SESSION_DENY : L2_INACL_ERROR_NONE; |
| 349 | b0->error = node->errors[error0]; |
| 350 | break; |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 355 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 356 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) |
| 357 | && (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 358 | { |
| 359 | l2_inacl_trace_t *t = |
| 360 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 361 | t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
| 362 | t->next_index = next0; |
| 363 | t->table_index = t0 ? t0 - vcm->tables : ~0; |
| 364 | t->offset = (t0 && e0) ? vnet_classify_get_offset (t0, e0) : ~0; |
| 365 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 366 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 367 | /* verify speculative enqueue, maybe switch current next frame */ |
| 368 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 369 | to_next, n_left_to_next, |
| 370 | bi0, next0); |
| 371 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 372 | |
| 373 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 374 | } |
| 375 | |
| 376 | vlib_node_increment_counter (vm, node->node_index, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 377 | L2_INACL_ERROR_MISS, misses); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 378 | vlib_node_increment_counter (vm, node->node_index, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 379 | L2_INACL_ERROR_HIT, hits); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | vlib_node_increment_counter (vm, node->node_index, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 381 | L2_INACL_ERROR_CHAIN_HIT, chain_hits); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | return frame->n_vectors; |
| 383 | } |
| 384 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 385 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 386 | VLIB_REGISTER_NODE (l2_inacl_node,static) = { |
| 387 | .function = l2_inacl_node_fn, |
| 388 | .name = "l2-input-acl", |
| 389 | .vector_size = sizeof (u32), |
| 390 | .format_trace = format_l2_inacl_trace, |
| 391 | .type = VLIB_NODE_TYPE_INTERNAL, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 392 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 393 | .n_errors = ARRAY_LEN(l2_inacl_error_strings), |
| 394 | .error_strings = l2_inacl_error_strings, |
| 395 | |
| 396 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 397 | |
| 398 | /* edit / add dispositions here */ |
| 399 | .next_nodes = { |
| 400 | [ACL_NEXT_INDEX_DENY] = "error-drop", |
| 401 | }, |
| 402 | }; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 403 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 404 | |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 405 | VLIB_NODE_FUNCTION_MULTIARCH (l2_inacl_node, l2_inacl_node_fn) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 406 | clib_error_t *l2_inacl_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 407 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 408 | l2_inacl_main_t *mp = &l2_inacl_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 409 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 410 | mp->vlib_main = vm; |
| 411 | mp->vnet_main = vnet_get_main (); |
| 412 | |
| 413 | /* Initialize the feature next-node indexes */ |
| 414 | feat_bitmap_init_next_nodes (vm, |
| 415 | l2_inacl_node.index, |
| 416 | L2INPUT_N_FEAT, |
| 417 | l2input_get_feat_names (), |
| 418 | mp->feat_next_node_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | VLIB_INIT_FUNCTION (l2_inacl_init); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 424 | |
| 425 | /* |
| 426 | * fd.io coding-style-patch-verification: ON |
| 427 | * |
| 428 | * Local Variables: |
| 429 | * eval: (c-set-style "gnu") |
| 430 | * End: |
| 431 | */ |