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