Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | #include <vnet/ip/ip.h> |
| 16 | #include <vnet/classify/vnet_classify.h> |
| 17 | #include <vnet/classify/input_acl.h> |
| 18 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 19 | typedef struct |
| 20 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 21 | u32 sw_if_index; |
| 22 | u32 next_index; |
| 23 | u32 table_index; |
| 24 | u32 offset; |
| 25 | } ip_inacl_trace_t; |
| 26 | |
| 27 | /* packet trace format function */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 28 | static u8 * |
| 29 | format_ip_inacl_trace (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 30 | { |
| 31 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 32 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 33 | ip_inacl_trace_t *t = va_arg (*args, ip_inacl_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 34 | |
| 35 | s = format (s, "INACL: sw_if_index %d, next_index %d, table %d, offset %d", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 36 | t->sw_if_index, t->next_index, t->table_index, t->offset); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 37 | return s; |
| 38 | } |
| 39 | |
| 40 | vlib_node_registration_t ip4_inacl_node; |
| 41 | vlib_node_registration_t ip6_inacl_node; |
| 42 | |
| 43 | #define foreach_ip_inacl_error \ |
| 44 | _(MISS, "input ACL misses") \ |
| 45 | _(HIT, "input ACL hits") \ |
| 46 | _(CHAIN_HIT, "input ACL hits after chain walk") |
| 47 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 48 | typedef enum |
| 49 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | #define _(sym,str) IP_INACL_ERROR_##sym, |
| 51 | foreach_ip_inacl_error |
| 52 | #undef _ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 53 | IP_INACL_N_ERROR, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | } ip_inacl_error_t; |
| 55 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 56 | static char *ip_inacl_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 57 | #define _(sym,string) string, |
| 58 | foreach_ip_inacl_error |
| 59 | #undef _ |
| 60 | }; |
| 61 | |
| 62 | static inline uword |
| 63 | ip_inacl_inline (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 64 | vlib_node_runtime_t * node, vlib_frame_t * frame, int is_ip4) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 65 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 66 | u32 n_left_from, *from, *to_next; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | acl_next_index_t next_index; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 68 | input_acl_main_t *am = &input_acl_main; |
| 69 | vnet_classify_main_t *vcm = am->vnet_classify_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 70 | f64 now = vlib_time_now (vm); |
| 71 | u32 hits = 0; |
| 72 | u32 misses = 0; |
| 73 | u32 chain_hits = 0; |
| 74 | input_acl_table_id_t tid; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 75 | vlib_node_runtime_t *error_node; |
Dave Barach | f39ff74 | 2016-03-20 10:14:45 -0400 | [diff] [blame] | 76 | u32 n_next_nodes; |
| 77 | |
| 78 | n_next_nodes = node->n_next_nodes; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | |
| 80 | if (is_ip4) |
| 81 | { |
| 82 | tid = INPUT_ACL_TABLE_IP4; |
| 83 | error_node = vlib_node_get_runtime (vm, ip4_input_node.index); |
| 84 | } |
| 85 | else |
| 86 | { |
| 87 | tid = INPUT_ACL_TABLE_IP6; |
| 88 | error_node = vlib_node_get_runtime (vm, ip6_input_node.index); |
| 89 | } |
| 90 | |
| 91 | from = vlib_frame_vector_args (frame); |
| 92 | n_left_from = frame->n_vectors; |
| 93 | |
| 94 | /* First pass: compute hashes */ |
| 95 | |
| 96 | while (n_left_from > 2) |
| 97 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 98 | vlib_buffer_t *b0, *b1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | u32 bi0, bi1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 100 | u8 *h0, *h1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | u32 sw_if_index0, sw_if_index1; |
| 102 | u32 table_index0, table_index1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 103 | vnet_classify_table_t *t0, *t1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | |
| 105 | /* prefetch next iteration */ |
| 106 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 107 | vlib_buffer_t *p1, *p2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 108 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 109 | p1 = vlib_get_buffer (vm, from[1]); |
| 110 | p2 = vlib_get_buffer (vm, from[2]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 112 | vlib_prefetch_buffer_header (p1, STORE); |
| 113 | CLIB_PREFETCH (p1->data, CLIB_CACHE_LINE_BYTES, STORE); |
| 114 | vlib_prefetch_buffer_header (p2, STORE); |
| 115 | CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | bi0 = from[0]; |
| 119 | b0 = vlib_get_buffer (vm, bi0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 120 | |
| 121 | bi1 = from[1]; |
| 122 | b1 = vlib_get_buffer (vm, bi1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 123 | |
| 124 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 125 | table_index0 = |
| 126 | am->classify_table_index_by_sw_if_index[tid][sw_if_index0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 127 | |
| 128 | sw_if_index1 = vnet_buffer (b1)->sw_if_index[VLIB_RX]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 129 | table_index1 = |
| 130 | am->classify_table_index_by_sw_if_index[tid][sw_if_index1]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 131 | |
| 132 | t0 = pool_elt_at_index (vcm->tables, table_index0); |
| 133 | |
| 134 | t1 = pool_elt_at_index (vcm->tables, table_index1); |
| 135 | |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 136 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 137 | h0 = (void *) vlib_buffer_get_current (b0) + t0->current_data_offset; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 138 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 139 | h0 = b0->data; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 140 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 141 | vnet_buffer (b0)->l2_classify.hash = |
| 142 | vnet_classify_hash_packet (t0, (u8 *) h0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 144 | vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 145 | |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 146 | if (t1->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 147 | h1 = (void *) vlib_buffer_get_current (b1) + t1->current_data_offset; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 148 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 149 | h1 = b1->data; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 150 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 151 | vnet_buffer (b1)->l2_classify.hash = |
| 152 | vnet_classify_hash_packet (t1, (u8 *) h1); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 153 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 154 | vnet_classify_prefetch_bucket (t1, vnet_buffer (b1)->l2_classify.hash); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 155 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 156 | vnet_buffer (b0)->l2_classify.table_index = table_index0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 157 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 158 | vnet_buffer (b1)->l2_classify.table_index = table_index1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 159 | |
| 160 | from += 2; |
| 161 | n_left_from -= 2; |
| 162 | } |
| 163 | |
| 164 | while (n_left_from > 0) |
| 165 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 166 | vlib_buffer_t *b0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 167 | u32 bi0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 168 | u8 *h0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | u32 sw_if_index0; |
| 170 | u32 table_index0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 171 | vnet_classify_table_t *t0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 172 | |
| 173 | bi0 = from[0]; |
| 174 | b0 = vlib_get_buffer (vm, bi0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | |
| 176 | sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 177 | table_index0 = |
| 178 | am->classify_table_index_by_sw_if_index[tid][sw_if_index0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | |
| 180 | t0 = pool_elt_at_index (vcm->tables, table_index0); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 181 | |
| 182 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 183 | h0 = (void *) vlib_buffer_get_current (b0) + t0->current_data_offset; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 184 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 185 | h0 = b0->data; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 186 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 187 | vnet_buffer (b0)->l2_classify.hash = |
| 188 | vnet_classify_hash_packet (t0, (u8 *) h0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 189 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 190 | vnet_buffer (b0)->l2_classify.table_index = table_index0; |
| 191 | vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 192 | |
| 193 | from++; |
| 194 | n_left_from--; |
| 195 | } |
| 196 | |
| 197 | next_index = node->cached_next_index; |
| 198 | from = vlib_frame_vector_args (frame); |
| 199 | n_left_from = frame->n_vectors; |
| 200 | |
| 201 | while (n_left_from > 0) |
| 202 | { |
| 203 | u32 n_left_to_next; |
| 204 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 205 | 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] | 206 | |
| 207 | /* Not enough load/store slots to dual loop... */ |
| 208 | while (n_left_from > 0 && n_left_to_next > 0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 209 | { |
| 210 | u32 bi0; |
| 211 | vlib_buffer_t *b0; |
| 212 | u32 next0 = ACL_NEXT_INDEX_DENY; |
| 213 | u32 table_index0; |
| 214 | vnet_classify_table_t *t0; |
| 215 | vnet_classify_entry_t *e0; |
| 216 | u64 hash0; |
| 217 | u8 *h0; |
| 218 | u8 error0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 219 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 220 | /* Stride 3 seems to work best */ |
| 221 | if (PREDICT_TRUE (n_left_from > 3)) |
| 222 | { |
| 223 | vlib_buffer_t *p1 = vlib_get_buffer (vm, from[3]); |
| 224 | vnet_classify_table_t *tp1; |
| 225 | u32 table_index1; |
| 226 | u64 phash1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 227 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 228 | table_index1 = vnet_buffer (p1)->l2_classify.table_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 229 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 230 | if (PREDICT_TRUE (table_index1 != ~0)) |
| 231 | { |
| 232 | tp1 = pool_elt_at_index (vcm->tables, table_index1); |
| 233 | phash1 = vnet_buffer (p1)->l2_classify.hash; |
| 234 | vnet_classify_prefetch_entry (tp1, phash1); |
| 235 | } |
| 236 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 237 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 238 | /* speculatively enqueue b0 to the current next frame */ |
| 239 | bi0 = from[0]; |
| 240 | to_next[0] = bi0; |
| 241 | from += 1; |
| 242 | to_next += 1; |
| 243 | n_left_from -= 1; |
| 244 | n_left_to_next -= 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 245 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 246 | b0 = vlib_get_buffer (vm, bi0); |
| 247 | table_index0 = vnet_buffer (b0)->l2_classify.table_index; |
| 248 | e0 = 0; |
| 249 | t0 = 0; |
| 250 | vnet_get_config_data (am->vnet_config_main[tid], |
| 251 | &b0->current_config_index, &next0, |
| 252 | /* # bytes of config data */ 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 253 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 254 | vnet_buffer (b0)->l2_classify.opaque_index = ~0; |
rangan | 0930649 | 2016-04-13 17:08:11 +0530 | [diff] [blame] | 255 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 256 | if (PREDICT_TRUE (table_index0 != ~0)) |
| 257 | { |
| 258 | hash0 = vnet_buffer (b0)->l2_classify.hash; |
| 259 | t0 = pool_elt_at_index (vcm->tables, table_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 260 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 261 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 262 | h0 = |
| 263 | (void *) vlib_buffer_get_current (b0) + |
| 264 | t0->current_data_offset; |
| 265 | else |
| 266 | h0 = b0->data; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 267 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 268 | e0 = vnet_classify_find_entry (t0, (u8 *) h0, hash0, now); |
| 269 | if (e0) |
| 270 | { |
| 271 | vnet_buffer (b0)->l2_classify.opaque_index |
| 272 | = e0->opaque_index; |
| 273 | vlib_buffer_advance (b0, e0->advance); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 274 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 275 | next0 = (e0->next_index < n_next_nodes) ? |
| 276 | e0->next_index : next0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 277 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 278 | hits++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 279 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 280 | if (is_ip4) |
| 281 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 282 | IP4_ERROR_INACL_SESSION_DENY : IP4_ERROR_NONE; |
| 283 | else |
| 284 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 285 | IP6_ERROR_INACL_SESSION_DENY : IP6_ERROR_NONE; |
| 286 | b0->error = error_node->errors[error0]; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 287 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 288 | if (e0->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX || |
| 289 | e0->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX) |
| 290 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = e0->metadata; |
Gabriel Ganne | 8527f12 | 2017-10-02 11:41:24 +0200 | [diff] [blame] | 291 | else if (e0->action == CLASSIFY_ACTION_SET_SR_POLICY_INDEX) |
| 292 | vnet_buffer (b0)->ip.adj_index[VLIB_TX] = e0->metadata; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 293 | } |
| 294 | else |
| 295 | { |
| 296 | while (1) |
| 297 | { |
| 298 | if (PREDICT_TRUE (t0->next_table_index != ~0)) |
| 299 | t0 = pool_elt_at_index (vcm->tables, |
| 300 | t0->next_table_index); |
| 301 | else |
| 302 | { |
| 303 | next0 = (t0->miss_next_index < n_next_nodes) ? |
| 304 | t0->miss_next_index : next0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 305 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 306 | misses++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 307 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 308 | if (is_ip4) |
| 309 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 310 | IP4_ERROR_INACL_TABLE_MISS : IP4_ERROR_NONE; |
| 311 | else |
| 312 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 313 | IP6_ERROR_INACL_TABLE_MISS : IP6_ERROR_NONE; |
| 314 | b0->error = error_node->errors[error0]; |
| 315 | break; |
| 316 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 317 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 318 | if (t0->current_data_flag == |
| 319 | CLASSIFY_FLAG_USE_CURR_DATA) |
| 320 | h0 = |
| 321 | (void *) vlib_buffer_get_current (b0) + |
| 322 | t0->current_data_offset; |
| 323 | else |
| 324 | h0 = b0->data; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 325 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 326 | hash0 = vnet_classify_hash_packet (t0, (u8 *) h0); |
| 327 | e0 = vnet_classify_find_entry |
| 328 | (t0, (u8 *) h0, hash0, now); |
| 329 | if (e0) |
| 330 | { |
| 331 | vnet_buffer (b0)->l2_classify.opaque_index |
| 332 | = e0->opaque_index; |
| 333 | vlib_buffer_advance (b0, e0->advance); |
| 334 | next0 = (e0->next_index < n_next_nodes) ? |
| 335 | e0->next_index : next0; |
| 336 | hits++; |
| 337 | chain_hits++; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 338 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 339 | if (is_ip4) |
| 340 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 341 | IP4_ERROR_INACL_SESSION_DENY : IP4_ERROR_NONE; |
| 342 | else |
| 343 | error0 = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 344 | IP6_ERROR_INACL_SESSION_DENY : IP6_ERROR_NONE; |
| 345 | b0->error = error_node->errors[error0]; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 346 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 347 | if (e0->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX |
| 348 | || e0->action == |
| 349 | CLASSIFY_ACTION_SET_IP6_FIB_INDEX) |
| 350 | vnet_buffer (b0)->sw_if_index[VLIB_TX] = |
| 351 | e0->metadata; |
| 352 | break; |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 357 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 358 | if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) |
| 359 | && (b0->flags & VLIB_BUFFER_IS_TRACED))) |
| 360 | { |
| 361 | ip_inacl_trace_t *t = |
| 362 | vlib_add_trace (vm, node, b0, sizeof (*t)); |
| 363 | t->sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX]; |
| 364 | t->next_index = next0; |
| 365 | t->table_index = t0 ? t0 - vcm->tables : ~0; |
| 366 | t->offset = (e0 && t0) ? vnet_classify_get_offset (t0, e0) : ~0; |
| 367 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 368 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 369 | /* verify speculative enqueue, maybe switch current next frame */ |
| 370 | vlib_validate_buffer_enqueue_x1 (vm, node, next_index, |
| 371 | to_next, n_left_to_next, |
| 372 | bi0, next0); |
| 373 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 374 | |
| 375 | vlib_put_next_frame (vm, node, next_index, n_left_to_next); |
| 376 | } |
| 377 | |
| 378 | vlib_node_increment_counter (vm, node->node_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 379 | IP_INACL_ERROR_MISS, misses); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | vlib_node_increment_counter (vm, node->node_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 381 | IP_INACL_ERROR_HIT, hits); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | vlib_node_increment_counter (vm, node->node_index, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 383 | IP_INACL_ERROR_CHAIN_HIT, chain_hits); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 384 | return frame->n_vectors; |
| 385 | } |
| 386 | |
| 387 | static uword |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 388 | ip4_inacl (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 389 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 390 | return ip_inacl_inline (vm, node, frame, 1 /* is_ip4 */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 394 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 395 | VLIB_REGISTER_NODE (ip4_inacl_node) = { |
| 396 | .function = ip4_inacl, |
| 397 | .name = "ip4-inacl", |
| 398 | .vector_size = sizeof (u32), |
| 399 | .format_trace = format_ip_inacl_trace, |
| 400 | .n_errors = ARRAY_LEN(ip_inacl_error_strings), |
| 401 | .error_strings = ip_inacl_error_strings, |
| 402 | |
| 403 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 404 | .next_nodes = { |
| 405 | [ACL_NEXT_INDEX_DENY] = "error-drop", |
| 406 | }, |
| 407 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 408 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 409 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 410 | VLIB_NODE_FUNCTION_MULTIARCH (ip4_inacl_node, ip4_inacl); |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 411 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 412 | static uword |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 413 | ip6_inacl (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 414 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 415 | return ip_inacl_inline (vm, node, frame, 0 /* is_ip4 */ ); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 419 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 420 | VLIB_REGISTER_NODE (ip6_inacl_node) = { |
| 421 | .function = ip6_inacl, |
| 422 | .name = "ip6-inacl", |
| 423 | .vector_size = sizeof (u32), |
| 424 | .format_trace = format_ip_inacl_trace, |
| 425 | .n_errors = ARRAY_LEN(ip_inacl_error_strings), |
| 426 | .error_strings = ip_inacl_error_strings, |
| 427 | |
| 428 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 429 | .next_nodes = { |
| 430 | [ACL_NEXT_INDEX_DENY] = "error-drop", |
| 431 | }, |
| 432 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 433 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 434 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 435 | VLIB_NODE_FUNCTION_MULTIARCH (ip6_inacl_node, ip6_inacl); |
Damjan Marion | 1c80e83 | 2016-05-11 23:07:18 +0200 | [diff] [blame] | 436 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 437 | static clib_error_t * |
| 438 | ip_inacl_init (vlib_main_t * vm) |
| 439 | { |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | VLIB_INIT_FUNCTION (ip_inacl_init); |
| 444 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 445 | |
| 446 | /* |
| 447 | * fd.io coding-style-patch-verification: ON |
| 448 | * |
| 449 | * Local Variables: |
| 450 | * eval: (c-set-style "gnu") |
| 451 | * End: |
| 452 | */ |