Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 2 | * l2_in_out_acl.c : layer 2 input/output acl processing |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 3 | * |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 4 | * Copyright (c) 2013,2018 Cisco and/or its affiliates. |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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> |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 28 | #include <vnet/l2/l2_output.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 29 | #include <vnet/l2/feat_bitmap.h> |
| 30 | |
| 31 | #include <vppinfra/error.h> |
| 32 | #include <vppinfra/hash.h> |
| 33 | #include <vppinfra/cache.h> |
| 34 | |
| 35 | #include <vnet/classify/vnet_classify.h> |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 36 | #include <vnet/classify/in_out_acl.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 38 | typedef struct |
| 39 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 40 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 41 | /* Next nodes for each feature */ |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 42 | u32 feat_next_node_index[IN_OUT_ACL_N_TABLE_GROUPS][32]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | |
| 44 | /* convenience variables */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 45 | vlib_main_t *vlib_main; |
| 46 | vnet_main_t *vnet_main; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 47 | } l2_in_out_acl_main_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 49 | typedef struct |
| 50 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | u32 sw_if_index; |
| 52 | u32 next_index; |
| 53 | u32 table_index; |
| 54 | u32 offset; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 55 | } l2_in_out_acl_trace_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | |
| 57 | /* packet trace format function */ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 58 | static u8 * |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 59 | format_l2_in_out_acl_trace (u8 * s, u32 is_output, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | { |
| 61 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 62 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 63 | l2_in_out_acl_trace_t *t = va_arg (*args, l2_in_out_acl_trace_t *); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 64 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 65 | s = format (s, "%s: sw_if_index %d, next_index %d, table %d, offset %d", |
| 66 | is_output ? "OUTACL" : "INACL", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | t->sw_if_index, t->next_index, t->table_index, t->offset); |
| 68 | return s; |
| 69 | } |
| 70 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 71 | static u8 * |
| 72 | format_l2_inacl_trace (u8 * s, va_list * args) |
| 73 | { |
| 74 | return format_l2_in_out_acl_trace (s, IN_OUT_ACL_INPUT_TABLE_GROUP, args); |
| 75 | } |
| 76 | |
| 77 | static u8 * |
| 78 | format_l2_outacl_trace (u8 * s, va_list * args) |
| 79 | { |
| 80 | return format_l2_in_out_acl_trace (s, IN_OUT_ACL_OUTPUT_TABLE_GROUP, args); |
| 81 | } |
| 82 | |
| 83 | l2_in_out_acl_main_t l2_in_out_acl_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 84 | |
| 85 | static vlib_node_registration_t l2_inacl_node; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 86 | static vlib_node_registration_t l2_outacl_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | |
| 88 | #define foreach_l2_inacl_error \ |
| 89 | _(NONE, "valid input ACL packets") \ |
| 90 | _(MISS, "input ACL misses") \ |
| 91 | _(HIT, "input ACL hits") \ |
| 92 | _(CHAIN_HIT, "input ACL hits after chain walk") \ |
| 93 | _(TABLE_MISS, "input ACL table-miss drops") \ |
| 94 | _(SESSION_DENY, "input ACL session deny drops") |
| 95 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 96 | #define foreach_l2_outacl_error \ |
| 97 | _(NONE, "valid output ACL packets") \ |
| 98 | _(MISS, "output ACL misses") \ |
| 99 | _(HIT, "output ACL hits") \ |
| 100 | _(CHAIN_HIT, "output ACL hits after chain walk") \ |
| 101 | _(TABLE_MISS, "output ACL table-miss drops") \ |
| 102 | _(SESSION_DENY, "output ACL session deny drops") |
| 103 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 105 | typedef enum |
| 106 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 107 | #define _(sym,str) L2_INACL_ERROR_##sym, |
| 108 | foreach_l2_inacl_error |
| 109 | #undef _ |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 110 | L2_INACL_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | } l2_inacl_error_t; |
| 112 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 113 | static char *l2_inacl_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 114 | #define _(sym,string) string, |
| 115 | foreach_l2_inacl_error |
| 116 | #undef _ |
| 117 | }; |
| 118 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 119 | typedef enum |
| 120 | { |
| 121 | #define _(sym,str) L2_OUTACL_ERROR_##sym, |
| 122 | foreach_l2_outacl_error |
| 123 | #undef _ |
| 124 | L2_OUTACL_N_ERROR, |
| 125 | } l2_outacl_error_t; |
| 126 | |
| 127 | static char *l2_outacl_error_strings[] = { |
| 128 | #define _(sym,string) string, |
| 129 | foreach_l2_outacl_error |
| 130 | #undef _ |
| 131 | }; |
| 132 | |
| 133 | |
| 134 | static inline uword |
| 135 | l2_in_out_acl_node_fn (vlib_main_t * vm, |
| 136 | vlib_node_runtime_t * node, vlib_frame_t * frame, |
| 137 | int is_output) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 138 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 139 | u32 n_left_from, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 140 | acl_next_index_t next_index; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 141 | l2_in_out_acl_main_t *msm = &l2_in_out_acl_main; |
| 142 | in_out_acl_main_t *am = &in_out_acl_main; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 143 | vnet_classify_main_t *vcm = am->vnet_classify_main; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 144 | in_out_acl_table_id_t tid = IN_OUT_ACL_TABLE_L2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 145 | f64 now = vlib_time_now (vm); |
| 146 | u32 hits = 0; |
| 147 | u32 misses = 0; |
| 148 | u32 chain_hits = 0; |
| 149 | |
| 150 | from = vlib_frame_vector_args (frame); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 151 | n_left_from = frame->n_vectors; /* number of packets to process */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 152 | next_index = node->cached_next_index; |
| 153 | |
| 154 | /* First pass: compute hashes */ |
| 155 | while (n_left_from > 2) |
| 156 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 157 | vlib_buffer_t *b0, *b1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | u32 bi0, bi1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 159 | u8 *h0, *h1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 160 | u32 sw_if_index0, sw_if_index1; |
| 161 | u32 table_index0, table_index1; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 162 | vnet_classify_table_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 163 | |
| 164 | /* prefetch next iteration */ |
| 165 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 166 | vlib_buffer_t *p1, *p2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 167 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 168 | p1 = vlib_get_buffer (vm, from[1]); |
| 169 | p2 = vlib_get_buffer (vm, from[2]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 171 | vlib_prefetch_buffer_header (p1, STORE); |
| 172 | CLIB_PREFETCH (p1->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 173 | vlib_prefetch_buffer_header (p2, STORE); |
| 174 | CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | bi0 = from[0]; |
| 178 | b0 = vlib_get_buffer (vm, bi0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | |
| 180 | bi1 = from[1]; |
| 181 | b1 = vlib_get_buffer (vm, bi1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 182 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 183 | sw_if_index0 = |
| 184 | vnet_buffer (b0)->sw_if_index[is_output ? VLIB_TX : VLIB_RX]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 185 | table_index0 = |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 186 | am->classify_table_index_by_sw_if_index[is_output][tid][sw_if_index0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 187 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 188 | sw_if_index1 = |
| 189 | vnet_buffer (b1)->sw_if_index[is_output ? VLIB_TX : VLIB_RX]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 190 | table_index1 = |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 191 | am->classify_table_index_by_sw_if_index[is_output][tid][sw_if_index1]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 192 | |
| 193 | t0 = pool_elt_at_index (vcm->tables, table_index0); |
| 194 | |
| 195 | t1 = pool_elt_at_index (vcm->tables, table_index1); |
| 196 | |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 197 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 198 | h0 = (void *) vlib_buffer_get_current (b0) + t0->current_data_offset; |
| 199 | else |
Steve Shin | 2ae03d2 | 2018-02-26 11:43:31 -0800 | [diff] [blame] | 200 | h0 = (void *) vlib_buffer_get_current (b0); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 201 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 202 | vnet_buffer (b0)->l2_classify.hash = |
| 203 | vnet_classify_hash_packet (t0, (u8 *) h0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 204 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 205 | vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 206 | |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 207 | if (t1->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 208 | h1 = (void *) vlib_buffer_get_current (b1) + t1->current_data_offset; |
| 209 | else |
Steve Shin | 2ae03d2 | 2018-02-26 11:43:31 -0800 | [diff] [blame] | 210 | h1 = (void *) vlib_buffer_get_current (b1); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 211 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 212 | vnet_buffer (b1)->l2_classify.hash = |
| 213 | vnet_classify_hash_packet (t1, (u8 *) h1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 214 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 215 | vnet_classify_prefetch_bucket (t1, vnet_buffer (b1)->l2_classify.hash); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 216 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 217 | vnet_buffer (b0)->l2_classify.table_index = table_index0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 218 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 219 | vnet_buffer (b1)->l2_classify.table_index = table_index1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 220 | |
| 221 | from += 2; |
| 222 | n_left_from -= 2; |
| 223 | } |
| 224 | |
| 225 | while (n_left_from > 0) |
| 226 | { |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 227 | vlib_buffer_t *b0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | u32 bi0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 229 | u8 *h0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 230 | u32 sw_if_index0; |
| 231 | u32 table_index0; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 232 | vnet_classify_table_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | |
| 234 | bi0 = from[0]; |
| 235 | b0 = vlib_get_buffer (vm, bi0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 236 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 237 | sw_if_index0 = |
| 238 | vnet_buffer (b0)->sw_if_index[is_output ? VLIB_TX : VLIB_RX]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 239 | table_index0 = |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 240 | am->classify_table_index_by_sw_if_index[is_output][tid][sw_if_index0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 241 | |
| 242 | t0 = pool_elt_at_index (vcm->tables, table_index0); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 243 | |
| 244 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 245 | h0 = (void *) vlib_buffer_get_current (b0) + t0->current_data_offset; |
| 246 | else |
Steve Shin | 2ae03d2 | 2018-02-26 11:43:31 -0800 | [diff] [blame] | 247 | h0 = (void *) vlib_buffer_get_current (b0); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 248 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 249 | vnet_buffer (b0)->l2_classify.hash = |
| 250 | vnet_classify_hash_packet (t0, (u8 *) h0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 251 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 252 | vnet_buffer (b0)->l2_classify.table_index = table_index0; |
| 253 | vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 254 | |
| 255 | from++; |
| 256 | n_left_from--; |
| 257 | } |
| 258 | |
| 259 | next_index = node->cached_next_index; |
| 260 | from = vlib_frame_vector_args (frame); |
| 261 | n_left_from = frame->n_vectors; |
| 262 | |
| 263 | while (n_left_from > 0) |
| 264 | { |
| 265 | u32 n_left_to_next; |
| 266 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 267 | 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] | 268 | |
| 269 | /* Not enough load/store slots to dual loop... */ |
| 270 | while (n_left_from > 0 && n_left_to_next > 0) |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 271 | { |
| 272 | u32 bi0; |
| 273 | vlib_buffer_t *b0; |
| 274 | u32 next0 = ACL_NEXT_INDEX_DENY; |
| 275 | u32 table_index0; |
| 276 | vnet_classify_table_t *t0; |
| 277 | vnet_classify_entry_t *e0; |
| 278 | u64 hash0; |
| 279 | u8 *h0; |
| 280 | u8 error0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 281 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 282 | /* Stride 3 seems to work best */ |
| 283 | if (PREDICT_TRUE (n_left_from > 3)) |
| 284 | { |
| 285 | vlib_buffer_t *p1 = vlib_get_buffer (vm, from[3]); |
| 286 | vnet_classify_table_t *tp1; |
| 287 | u32 table_index1; |
| 288 | u64 phash1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 289 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 290 | table_index1 = vnet_buffer (p1)->l2_classify.table_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 291 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 292 | if (PREDICT_TRUE (table_index1 != ~0)) |
| 293 | { |
| 294 | tp1 = pool_elt_at_index (vcm->tables, table_index1); |
| 295 | phash1 = vnet_buffer (p1)->l2_classify.hash; |
| 296 | vnet_classify_prefetch_entry (tp1, phash1); |
| 297 | } |
| 298 | } |
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 | /* speculatively enqueue b0 to the current next frame */ |
| 301 | bi0 = from[0]; |
| 302 | to_next[0] = bi0; |
| 303 | from += 1; |
| 304 | to_next += 1; |
| 305 | n_left_from -= 1; |
| 306 | n_left_to_next -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 307 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 308 | b0 = vlib_get_buffer (vm, bi0); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 309 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 310 | table_index0 = vnet_buffer (b0)->l2_classify.table_index; |
| 311 | e0 = 0; |
| 312 | t0 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 313 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 314 | vnet_buffer (b0)->l2_classify.opaque_index = ~0; |
John Lo | beb0b2e | 2017-07-22 00:21:36 -0400 | [diff] [blame] | 315 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 316 | /* Determine the next node */ |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 317 | next0 = |
| 318 | vnet_l2_feature_next (b0, msm->feat_next_node_index[is_output], |
| 319 | is_output ? L2OUTPUT_FEAT_ACL : |
| 320 | L2INPUT_FEAT_ACL); |
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 | if (PREDICT_TRUE (table_index0 != ~0)) |
| 323 | { |
| 324 | hash0 = vnet_buffer (b0)->l2_classify.hash; |
| 325 | t0 = pool_elt_at_index (vcm->tables, table_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 326 | |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 327 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 328 | h0 = |
| 329 | (void *) vlib_buffer_get_current (b0) + |
| 330 | t0->current_data_offset; |
| 331 | else |
Steve Shin | 2ae03d2 | 2018-02-26 11:43:31 -0800 | [diff] [blame] | 332 | h0 = (void *) vlib_buffer_get_current (b0); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 333 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 334 | e0 = vnet_classify_find_entry (t0, (u8 *) h0, hash0, now); |
| 335 | if (e0) |
| 336 | { |
| 337 | vnet_buffer (b0)->l2_classify.opaque_index |
| 338 | = e0->opaque_index; |
| 339 | vlib_buffer_advance (b0, e0->advance); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 340 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 341 | next0 = (e0->next_index < ACL_NEXT_INDEX_N_NEXT) ? |
| 342 | e0->next_index : next0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 343 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 344 | hits++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 345 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 346 | if (is_output) |
| 347 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 348 | L2_OUTACL_ERROR_SESSION_DENY : L2_INACL_ERROR_NONE; |
| 349 | else |
| 350 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 351 | L2_OUTACL_ERROR_SESSION_DENY : L2_OUTACL_ERROR_NONE; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 352 | b0->error = node->errors[error0]; |
| 353 | } |
| 354 | else |
| 355 | { |
| 356 | while (1) |
| 357 | { |
| 358 | if (PREDICT_TRUE (t0->next_table_index != ~0)) |
| 359 | t0 = pool_elt_at_index (vcm->tables, |
| 360 | t0->next_table_index); |
| 361 | else |
| 362 | { |
| 363 | next0 = |
| 364 | (t0->miss_next_index < |
| 365 | ACL_NEXT_INDEX_N_NEXT) ? t0->miss_next_index : |
| 366 | next0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 367 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 368 | misses++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 369 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 370 | if (is_output) |
| 371 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 372 | L2_OUTACL_ERROR_TABLE_MISS : |
| 373 | L2_OUTACL_ERROR_NONE; |
| 374 | else |
| 375 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 376 | L2_INACL_ERROR_TABLE_MISS : L2_INACL_ERROR_NONE; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 377 | b0->error = node->errors[error0]; |
| 378 | break; |
| 379 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 381 | if (t0->current_data_flag == |
| 382 | CLASSIFY_FLAG_USE_CURR_DATA) |
| 383 | h0 = |
| 384 | (void *) vlib_buffer_get_current (b0) + |
| 385 | t0->current_data_offset; |
| 386 | else |
Steve Shin | 2ae03d2 | 2018-02-26 11:43:31 -0800 | [diff] [blame] | 387 | h0 = (void *) vlib_buffer_get_current (b0); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 388 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 389 | hash0 = vnet_classify_hash_packet (t0, (u8 *) h0); |
| 390 | e0 = vnet_classify_find_entry |
| 391 | (t0, (u8 *) h0, hash0, now); |
| 392 | if (e0) |
| 393 | { |
| 394 | vlib_buffer_advance (b0, e0->advance); |
| 395 | next0 = (e0->next_index < ACL_NEXT_INDEX_N_NEXT) ? |
| 396 | e0->next_index : next0; |
| 397 | hits++; |
| 398 | chain_hits++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 399 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 400 | if (is_output) |
| 401 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 402 | L2_OUTACL_ERROR_SESSION_DENY : |
| 403 | L2_OUTACL_ERROR_NONE; |
| 404 | else |
| 405 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 406 | L2_INACL_ERROR_SESSION_DENY : |
| 407 | L2_INACL_ERROR_NONE; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 408 | b0->error = node->errors[error0]; |
| 409 | break; |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 414 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 415 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) |
| 416 | && (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 417 | { |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 418 | l2_in_out_acl_trace_t *t = |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 419 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 420 | t->sw_if_index = |
| 421 | vnet_buffer (b0)->sw_if_index[is_output ? VLIB_TX : VLIB_RX]; |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 422 | t->next_index = next0; |
| 423 | t->table_index = t0 ? t0 - vcm->tables : ~0; |
| 424 | t->offset = (t0 && e0) ? vnet_classify_get_offset (t0, e0) : ~0; |
| 425 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 426 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 427 | /* verify speculative enqueue, maybe switch current next frame */ |
| 428 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 429 | to_next, n_left_to_next, |
| 430 | bi0, next0); |
| 431 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 432 | |
| 433 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 434 | } |
| 435 | |
| 436 | vlib_node_increment_counter (vm, node->node_index, |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 437 | is_output ? L2_OUTACL_ERROR_MISS : |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 438 | L2_INACL_ERROR_MISS, misses); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 439 | vlib_node_increment_counter (vm, node->node_index, |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 440 | is_output ? L2_OUTACL_ERROR_HIT : |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 441 | L2_INACL_ERROR_HIT, hits); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 442 | vlib_node_increment_counter (vm, node->node_index, |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 443 | is_output ? L2_OUTACL_ERROR_CHAIN_HIT : |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 444 | L2_INACL_ERROR_CHAIN_HIT, chain_hits); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 445 | return frame->n_vectors; |
| 446 | } |
| 447 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 448 | static uword |
| 449 | l2_inacl_node_fn (vlib_main_t * vm, |
| 450 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 451 | { |
| 452 | return l2_in_out_acl_node_fn (vm, node, frame, |
| 453 | IN_OUT_ACL_INPUT_TABLE_GROUP); |
| 454 | } |
| 455 | |
| 456 | static uword |
| 457 | l2_outacl_node_fn (vlib_main_t * vm, |
| 458 | vlib_node_runtime_t * node, vlib_frame_t * frame) |
| 459 | { |
| 460 | return l2_in_out_acl_node_fn (vm, node, frame, |
| 461 | IN_OUT_ACL_OUTPUT_TABLE_GROUP); |
| 462 | } |
| 463 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 464 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 465 | VLIB_REGISTER_NODE (l2_inacl_node,static) = { |
| 466 | .function = l2_inacl_node_fn, |
| 467 | .name = "l2-input-acl", |
| 468 | .vector_size = sizeof (u32), |
| 469 | .format_trace = format_l2_inacl_trace, |
| 470 | .type = VLIB_NODE_TYPE_INTERNAL, |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 471 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 472 | .n_errors = ARRAY_LEN(l2_inacl_error_strings), |
| 473 | .error_strings = l2_inacl_error_strings, |
| 474 | |
| 475 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 476 | |
| 477 | /* edit / add dispositions here */ |
| 478 | .next_nodes = { |
| 479 | [ACL_NEXT_INDEX_DENY] = "error-drop", |
| 480 | }, |
| 481 | }; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 482 | |
| 483 | VLIB_REGISTER_NODE (l2_outacl_node,static) = { |
| 484 | .function = l2_outacl_node_fn, |
| 485 | .name = "l2-output-acl", |
| 486 | .vector_size = sizeof (u32), |
| 487 | .format_trace = format_l2_outacl_trace, |
| 488 | .type = VLIB_NODE_TYPE_INTERNAL, |
| 489 | |
| 490 | .n_errors = ARRAY_LEN(l2_outacl_error_strings), |
| 491 | .error_strings = l2_outacl_error_strings, |
| 492 | |
| 493 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 494 | |
| 495 | /* edit / add dispositions here */ |
| 496 | .next_nodes = { |
| 497 | [ACL_NEXT_INDEX_DENY] = "error-drop", |
| 498 | }, |
| 499 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 500 | |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 501 | VLIB_NODE_FUNCTION_MULTIARCH (l2_inacl_node, l2_inacl_node_fn) |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 502 | VLIB_NODE_FUNCTION_MULTIARCH (l2_outacl_node, l2_outacl_node_fn) |
| 503 | /* *INDENT-ON* */ |
| 504 | |
| 505 | |
| 506 | clib_error_t * |
| 507 | l2_in_out_acl_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 508 | { |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 509 | l2_in_out_acl_main_t *mp = &l2_in_out_acl_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 510 | |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 511 | mp->vlib_main = vm; |
| 512 | mp->vnet_main = vnet_get_main (); |
| 513 | |
| 514 | /* Initialize the feature next-node indexes */ |
| 515 | feat_bitmap_init_next_nodes (vm, |
| 516 | l2_inacl_node.index, |
| 517 | L2INPUT_N_FEAT, |
| 518 | l2input_get_feat_names (), |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 519 | mp->feat_next_node_index |
| 520 | [IN_OUT_ACL_INPUT_TABLE_GROUP]); |
| 521 | feat_bitmap_init_next_nodes (vm, l2_outacl_node.index, L2OUTPUT_N_FEAT, |
| 522 | l2output_get_feat_names (), |
| 523 | mp->feat_next_node_index |
| 524 | [IN_OUT_ACL_OUTPUT_TABLE_GROUP]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 529 | VLIB_INIT_FUNCTION (l2_in_out_acl_init); |
Dave Barach | 97d8dc2 | 2016-08-15 15:31:15 -0400 | [diff] [blame] | 530 | |
| 531 | /* |
| 532 | * fd.io coding-style-patch-verification: ON |
| 533 | * |
| 534 | * Local Variables: |
| 535 | * eval: (c-set-style "gnu") |
| 536 | * End: |
| 537 | */ |