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> |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 17 | #include <vnet/classify/in_out_acl.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 25 | } |
| 26 | ip_in_out_acl_trace_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 27 | |
| 28 | /* packet trace format function */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 29 | static u8 * |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 30 | format_ip_in_out_acl_trace (u8 * s, u32 is_output, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | { |
| 32 | CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); |
| 33 | CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 34 | ip_in_out_acl_trace_t *t = va_arg (*args, ip_in_out_acl_trace_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 35 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 36 | s = format (s, "%s: sw_if_index %d, next_index %d, table %d, offset %d", |
| 37 | is_output ? "OUTACL" : "INACL", |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 38 | t->sw_if_index, t->next_index, t->table_index, t->offset); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | return s; |
| 40 | } |
| 41 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 42 | static u8 * |
| 43 | format_ip_inacl_trace (u8 * s, va_list * args) |
| 44 | { |
| 45 | return format_ip_in_out_acl_trace (s, 0 /* is_output */ , args); |
| 46 | } |
| 47 | |
| 48 | static u8 * |
| 49 | format_ip_outacl_trace (u8 * s, va_list * args) |
| 50 | { |
| 51 | return format_ip_in_out_acl_trace (s, 1 /* is_output */ , args); |
| 52 | } |
| 53 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 54 | extern vlib_node_registration_t ip4_inacl_node; |
| 55 | extern vlib_node_registration_t ip4_outacl_node; |
| 56 | extern vlib_node_registration_t ip6_inacl_node; |
| 57 | extern vlib_node_registration_t ip6_outacl_node; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | |
| 59 | #define foreach_ip_inacl_error \ |
| 60 | _(MISS, "input ACL misses") \ |
| 61 | _(HIT, "input ACL hits") \ |
| 62 | _(CHAIN_HIT, "input ACL hits after chain walk") |
| 63 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 64 | #define foreach_ip_outacl_error \ |
| 65 | _(MISS, "output ACL misses") \ |
| 66 | _(HIT, "output ACL hits") \ |
| 67 | _(CHAIN_HIT, "output ACL hits after chain walk") |
| 68 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 69 | typedef enum |
| 70 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | #define _(sym,str) IP_INACL_ERROR_##sym, |
| 72 | foreach_ip_inacl_error |
| 73 | #undef _ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 74 | IP_INACL_N_ERROR, |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 75 | } |
| 76 | ip_inacl_error_t; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 78 | static char *ip_inacl_error_strings[] = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 79 | #define _(sym,string) string, |
| 80 | foreach_ip_inacl_error |
| 81 | #undef _ |
| 82 | }; |
| 83 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 84 | typedef enum |
| 85 | { |
| 86 | #define _(sym,str) IP_OUTACL_ERROR_##sym, |
| 87 | foreach_ip_outacl_error |
| 88 | #undef _ |
| 89 | IP_OUTACL_N_ERROR, |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 90 | } |
| 91 | ip_outacl_error_t; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 92 | |
| 93 | static char *ip_outacl_error_strings[] = { |
| 94 | #define _(sym,string) string, |
| 95 | foreach_ip_outacl_error |
| 96 | #undef _ |
| 97 | }; |
| 98 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 99 | static_always_inline void |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 100 | ip_in_out_acl_inline_trace (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 101 | vlib_frame_t *frame, vlib_buffer_t **b, u16 *next, |
| 102 | u32 n_left, u32 *hits__, u32 *misses__, |
| 103 | u32 *chain_hits__, const vlib_error_t error_none, |
| 104 | const vlib_error_t error_deny, |
| 105 | const vlib_error_t error_miss, |
| 106 | vnet_classify_table_t *tables, |
| 107 | const u32 *table_index_by_sw_if_index, |
| 108 | vnet_config_main_t *cm, const vlib_rx_or_tx_t way, |
| 109 | const int is_output, const int do_trace) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 110 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | f64 now = vlib_time_now (vm); |
| 112 | u32 hits = 0; |
| 113 | u32 misses = 0; |
| 114 | u32 chain_hits = 0; |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 115 | u32 n_next_nodes = node->n_next_nodes; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 116 | u8 *h[4]; |
| 117 | u32 sw_if_index[4]; |
| 118 | u32 table_index[4]; |
| 119 | vnet_classify_table_t *t[4] = { 0, 0 }; |
| 120 | u64 hash[4]; |
| 121 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 122 | /* calculate hashes for b[0] & b[1] */ |
| 123 | if (n_left >= 2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | { |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 125 | /* ~0 is used as a wildcard to say 'always use sw_if_index 0' |
| 126 | * aka local0. It is used when we do not care about the sw_if_index, as |
| 127 | * when punting */ |
| 128 | sw_if_index[2] = ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way]; |
| 129 | sw_if_index[3] = ~0 == way ? 0 : vnet_buffer (b[1])->sw_if_index[way]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 131 | table_index[2] = table_index_by_sw_if_index[sw_if_index[2]]; |
| 132 | table_index[3] = table_index_by_sw_if_index[sw_if_index[3]]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 133 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 134 | t[2] = pool_elt_at_index (tables, table_index[2]); |
| 135 | t[3] = pool_elt_at_index (tables, table_index[3]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 136 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 137 | if (t[2]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 138 | h[2] = |
| 139 | (void *) vlib_buffer_get_current (b[0]) + t[2]->current_data_offset; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 140 | else |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 141 | h[2] = b[0]->data; |
| 142 | |
| 143 | if (t[3]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 144 | h[3] = |
| 145 | (void *) vlib_buffer_get_current (b[1]) + t[3]->current_data_offset; |
| 146 | else |
| 147 | h[3] = b[1]->data; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 148 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 149 | if (is_output) |
| 150 | { |
| 151 | /* Save the rewrite length, since we are using the l2_classify struct */ |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 152 | vnet_buffer (b[0])->l2_classify.pad.l2_len = |
| 153 | vnet_buffer (b[0])->ip.save_rewrite_length; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 154 | /* advance the match pointer so the matching happens on IP header */ |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 155 | h[2] += vnet_buffer (b[0])->l2_classify.pad.l2_len; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 156 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 157 | /* Save the rewrite length, since we are using the l2_classify struct */ |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 158 | vnet_buffer (b[1])->l2_classify.pad.l2_len = |
| 159 | vnet_buffer (b[1])->ip.save_rewrite_length; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 160 | /* advance the match pointer so the matching happens on IP header */ |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 161 | h[3] += vnet_buffer (b[1])->l2_classify.pad.l2_len; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 164 | hash[2] = vnet_classify_hash_packet_inline (t[2], (u8 *) h[2]); |
| 165 | hash[3] = vnet_classify_hash_packet_inline (t[3], (u8 *) h[3]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 167 | vnet_buffer (b[0])->l2_classify.hash = hash[2]; |
| 168 | vnet_buffer (b[1])->l2_classify.hash = hash[3]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 170 | vnet_buffer (b[0])->l2_classify.table_index = table_index[2]; |
| 171 | vnet_buffer (b[1])->l2_classify.table_index = table_index[3]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 172 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 173 | vnet_buffer (b[0])->l2_classify.opaque_index = ~0; |
| 174 | vnet_buffer (b[1])->l2_classify.opaque_index = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 176 | vnet_classify_prefetch_bucket (t[2], |
| 177 | vnet_buffer (b[0])->l2_classify.hash); |
| 178 | vnet_classify_prefetch_bucket (t[3], |
| 179 | vnet_buffer (b[1])->l2_classify.hash); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 182 | while (n_left >= 2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 183 | { |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 184 | vnet_classify_entry_t *e[2] = { 0, 0 }; |
| 185 | u32 _next[2] = { ACL_NEXT_INDEX_DENY, ACL_NEXT_INDEX_DENY }; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 186 | |
| 187 | h[0] = h[2]; |
| 188 | h[1] = h[3]; |
| 189 | t[0] = t[2]; |
| 190 | t[1] = t[3]; |
| 191 | |
| 192 | sw_if_index[0] = sw_if_index[2]; |
| 193 | sw_if_index[1] = sw_if_index[3]; |
| 194 | |
| 195 | table_index[0] = table_index[2]; |
| 196 | table_index[1] = table_index[3]; |
| 197 | |
| 198 | hash[0] = hash[2]; |
| 199 | hash[1] = hash[3]; |
| 200 | |
| 201 | /* prefetch next iteration */ |
| 202 | if (n_left >= 6) |
| 203 | { |
| 204 | vlib_prefetch_buffer_header (b[4], LOAD); |
| 205 | vlib_prefetch_buffer_header (b[5], LOAD); |
| 206 | |
Damjan Marion | af7fb04 | 2021-07-15 11:54:41 +0200 | [diff] [blame] | 207 | clib_prefetch_load (b[4]->data); |
| 208 | clib_prefetch_load (b[5]->data); |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /* calculate hashes for b[2] & b[3] */ |
| 212 | if (n_left >= 4) |
| 213 | { |
| 214 | sw_if_index[2] = |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 215 | ~0 == way ? 0 : vnet_buffer (b[2])->sw_if_index[way]; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 216 | sw_if_index[3] = |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 217 | ~0 == way ? 0 : vnet_buffer (b[3])->sw_if_index[way]; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 218 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 219 | table_index[2] = table_index_by_sw_if_index[sw_if_index[2]]; |
| 220 | table_index[3] = table_index_by_sw_if_index[sw_if_index[3]]; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 221 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 222 | t[2] = pool_elt_at_index (tables, table_index[2]); |
| 223 | t[3] = pool_elt_at_index (tables, table_index[3]); |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 224 | |
| 225 | if (t[2]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 226 | h[2] = |
| 227 | (void *) vlib_buffer_get_current (b[2]) + |
| 228 | t[2]->current_data_offset; |
| 229 | else |
| 230 | h[2] = b[2]->data; |
| 231 | |
| 232 | if (t[3]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 233 | h[3] = |
| 234 | (void *) vlib_buffer_get_current (b[3]) + |
| 235 | t[3]->current_data_offset; |
| 236 | else |
| 237 | h[3] = b[3]->data; |
| 238 | |
| 239 | if (is_output) |
| 240 | { |
| 241 | /* Save the rewrite length, since we are using the l2_classify struct */ |
| 242 | vnet_buffer (b[2])->l2_classify.pad.l2_len = |
| 243 | vnet_buffer (b[2])->ip.save_rewrite_length; |
| 244 | /* advance the match pointer so the matching happens on IP header */ |
| 245 | h[2] += vnet_buffer (b[2])->l2_classify.pad.l2_len; |
| 246 | |
| 247 | /* Save the rewrite length, since we are using the l2_classify struct */ |
| 248 | vnet_buffer (b[3])->l2_classify.pad.l2_len = |
| 249 | vnet_buffer (b[3])->ip.save_rewrite_length; |
| 250 | /* advance the match pointer so the matching happens on IP header */ |
| 251 | h[3] += vnet_buffer (b[3])->l2_classify.pad.l2_len; |
| 252 | } |
| 253 | |
| 254 | hash[2] = vnet_classify_hash_packet_inline (t[2], (u8 *) h[2]); |
| 255 | hash[3] = vnet_classify_hash_packet_inline (t[3], (u8 *) h[3]); |
| 256 | |
| 257 | vnet_buffer (b[2])->l2_classify.hash = hash[2]; |
| 258 | vnet_buffer (b[3])->l2_classify.hash = hash[3]; |
| 259 | |
| 260 | vnet_buffer (b[2])->l2_classify.table_index = table_index[2]; |
| 261 | vnet_buffer (b[3])->l2_classify.table_index = table_index[3]; |
| 262 | |
| 263 | vnet_buffer (b[2])->l2_classify.opaque_index = ~0; |
| 264 | vnet_buffer (b[3])->l2_classify.opaque_index = ~0; |
| 265 | |
| 266 | vnet_classify_prefetch_bucket (t[2], |
| 267 | vnet_buffer (b[2])-> |
| 268 | l2_classify.hash); |
| 269 | vnet_classify_prefetch_bucket (t[3], |
| 270 | vnet_buffer (b[3])-> |
| 271 | l2_classify.hash); |
| 272 | } |
| 273 | |
| 274 | /* find entry for b[0] & b[1] */ |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 275 | vnet_get_config_data (cm, &b[0]->current_config_index, &_next[0], |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 276 | /* # bytes of config data */ 0); |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 277 | vnet_get_config_data (cm, &b[1]->current_config_index, &_next[1], |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 278 | /* # bytes of config data */ 0); |
| 279 | |
| 280 | if (PREDICT_TRUE (table_index[0] != ~0)) |
| 281 | { |
| 282 | e[0] = |
| 283 | vnet_classify_find_entry_inline (t[0], (u8 *) h[0], hash[0], now); |
| 284 | if (e[0]) |
| 285 | { |
| 286 | vnet_buffer (b[0])->l2_classify.opaque_index |
| 287 | = e[0]->opaque_index; |
| 288 | vlib_buffer_advance (b[0], e[0]->advance); |
| 289 | |
| 290 | _next[0] = (e[0]->next_index < n_next_nodes) ? |
| 291 | e[0]->next_index : _next[0]; |
| 292 | |
| 293 | hits++; |
| 294 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 295 | b[0]->error = |
| 296 | (_next[0] == ACL_NEXT_INDEX_DENY) ? error_deny : error_none; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 297 | |
| 298 | if (!is_output) |
| 299 | { |
| 300 | if (e[0]->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX || |
| 301 | e[0]->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX) |
| 302 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] = e[0]->metadata; |
| 303 | else if (e[0]->action == CLASSIFY_ACTION_SET_METADATA) |
| 304 | vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = |
| 305 | e[0]->metadata; |
| 306 | } |
| 307 | } |
| 308 | else |
| 309 | { |
| 310 | while (1) |
| 311 | { |
| 312 | if (PREDICT_TRUE (t[0]->next_table_index != ~0)) |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 313 | t[0] = pool_elt_at_index (tables, t[0]->next_table_index); |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 314 | else |
| 315 | { |
| 316 | _next[0] = (t[0]->miss_next_index < n_next_nodes) ? |
| 317 | t[0]->miss_next_index : _next[0]; |
| 318 | |
| 319 | misses++; |
| 320 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 321 | b[0]->error = (_next[0] == ACL_NEXT_INDEX_DENY) ? |
| 322 | error_miss : |
| 323 | error_none; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 324 | break; |
| 325 | } |
| 326 | |
| 327 | if (t[0]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 328 | h[0] = |
| 329 | (void *) vlib_buffer_get_current (b[0]) + |
| 330 | t[0]->current_data_offset; |
| 331 | else |
| 332 | h[0] = b[0]->data; |
| 333 | |
| 334 | /* advance the match pointer so the matching happens on IP header */ |
| 335 | if (is_output) |
| 336 | h[0] += vnet_buffer (b[0])->l2_classify.pad.l2_len; |
| 337 | |
| 338 | hash[0] = |
| 339 | vnet_classify_hash_packet_inline (t[0], (u8 *) h[0]); |
| 340 | e[0] = |
| 341 | vnet_classify_find_entry_inline (t[0], (u8 *) h[0], |
| 342 | hash[0], now); |
| 343 | if (e[0]) |
| 344 | { |
| 345 | vnet_buffer (b[0])->l2_classify.opaque_index |
| 346 | = e[0]->opaque_index; |
| 347 | vlib_buffer_advance (b[0], e[0]->advance); |
| 348 | _next[0] = (e[0]->next_index < n_next_nodes) ? |
| 349 | e[0]->next_index : _next[0]; |
| 350 | hits++; |
| 351 | chain_hits++; |
| 352 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 353 | b[0]->error = (_next[0] == ACL_NEXT_INDEX_DENY) ? |
| 354 | error_deny : |
| 355 | error_none; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 356 | |
| 357 | if (!is_output) |
| 358 | { |
| 359 | if (e[0]->action == |
| 360 | CLASSIFY_ACTION_SET_IP4_FIB_INDEX |
| 361 | || e[0]->action == |
| 362 | CLASSIFY_ACTION_SET_IP6_FIB_INDEX) |
| 363 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] = |
| 364 | e[0]->metadata; |
| 365 | else if (e[0]->action == |
| 366 | CLASSIFY_ACTION_SET_METADATA) |
| 367 | vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = |
| 368 | e[0]->metadata; |
| 369 | } |
| 370 | break; |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | if (PREDICT_TRUE (table_index[1] != ~0)) |
| 377 | { |
| 378 | e[1] = |
| 379 | vnet_classify_find_entry_inline (t[1], (u8 *) h[1], hash[1], now); |
| 380 | if (e[1]) |
| 381 | { |
| 382 | vnet_buffer (b[1])->l2_classify.opaque_index |
| 383 | = e[1]->opaque_index; |
| 384 | vlib_buffer_advance (b[1], e[1]->advance); |
| 385 | |
| 386 | _next[1] = (e[1]->next_index < n_next_nodes) ? |
| 387 | e[1]->next_index : _next[1]; |
| 388 | |
| 389 | hits++; |
| 390 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 391 | b[1]->error = |
| 392 | (_next[1] == ACL_NEXT_INDEX_DENY) ? error_deny : error_none; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 393 | |
| 394 | if (!is_output) |
| 395 | { |
| 396 | if (e[1]->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX || |
| 397 | e[1]->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX) |
| 398 | vnet_buffer (b[1])->sw_if_index[VLIB_TX] = e[1]->metadata; |
| 399 | else if (e[1]->action == CLASSIFY_ACTION_SET_METADATA) |
| 400 | vnet_buffer (b[1])->ip.adj_index[VLIB_TX] = |
| 401 | e[1]->metadata; |
| 402 | } |
| 403 | } |
| 404 | else |
| 405 | { |
| 406 | while (1) |
| 407 | { |
| 408 | if (PREDICT_TRUE (t[1]->next_table_index != ~0)) |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 409 | t[1] = pool_elt_at_index (tables, t[1]->next_table_index); |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 410 | else |
| 411 | { |
| 412 | _next[1] = (t[1]->miss_next_index < n_next_nodes) ? |
| 413 | t[1]->miss_next_index : _next[1]; |
| 414 | |
| 415 | misses++; |
| 416 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 417 | b[1]->error = (_next[1] == ACL_NEXT_INDEX_DENY) ? |
| 418 | error_miss : |
| 419 | error_none; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 420 | break; |
| 421 | } |
| 422 | |
| 423 | if (t[1]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 424 | h[1] = |
| 425 | (void *) vlib_buffer_get_current (b[1]) + |
| 426 | t[1]->current_data_offset; |
| 427 | else |
| 428 | h[1] = b[1]->data; |
| 429 | |
| 430 | /* advance the match pointer so the matching happens on IP header */ |
| 431 | if (is_output) |
| 432 | h[1] += vnet_buffer (b[1])->l2_classify.pad.l2_len; |
| 433 | |
| 434 | hash[1] = |
| 435 | vnet_classify_hash_packet_inline (t[1], (u8 *) h[1]); |
| 436 | e[1] = |
| 437 | vnet_classify_find_entry_inline (t[1], (u8 *) h[1], |
| 438 | hash[1], now); |
| 439 | if (e[1]) |
| 440 | { |
| 441 | vnet_buffer (b[1])->l2_classify.opaque_index |
| 442 | = e[1]->opaque_index; |
| 443 | vlib_buffer_advance (b[1], e[1]->advance); |
| 444 | _next[1] = (e[1]->next_index < n_next_nodes) ? |
| 445 | e[1]->next_index : _next[1]; |
| 446 | hits++; |
| 447 | chain_hits++; |
| 448 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 449 | b[1]->error = (_next[1] == ACL_NEXT_INDEX_DENY) ? |
| 450 | error_deny : |
| 451 | error_none; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 452 | |
| 453 | if (!is_output) |
| 454 | { |
| 455 | if (e[1]->action == |
| 456 | CLASSIFY_ACTION_SET_IP4_FIB_INDEX |
| 457 | || e[1]->action == |
| 458 | CLASSIFY_ACTION_SET_IP6_FIB_INDEX) |
| 459 | vnet_buffer (b[1])->sw_if_index[VLIB_TX] = |
| 460 | e[1]->metadata; |
| 461 | else if (e[1]->action == |
| 462 | CLASSIFY_ACTION_SET_METADATA) |
| 463 | vnet_buffer (b[1])->ip.adj_index[VLIB_TX] = |
| 464 | e[1]->metadata; |
| 465 | } |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | if (do_trace && b[0]->flags & VLIB_BUFFER_IS_TRACED) |
| 473 | { |
| 474 | ip_in_out_acl_trace_t *_t = |
| 475 | vlib_add_trace (vm, node, b[0], sizeof (*_t)); |
| 476 | _t->sw_if_index = |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 477 | ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way]; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 478 | _t->next_index = _next[0]; |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 479 | _t->table_index = t[0] ? t[0] - tables : ~0; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 480 | _t->offset = (e[0] |
| 481 | && t[0]) ? vnet_classify_get_offset (t[0], e[0]) : ~0; |
| 482 | } |
| 483 | |
| 484 | if (do_trace && b[1]->flags & VLIB_BUFFER_IS_TRACED) |
| 485 | { |
| 486 | ip_in_out_acl_trace_t *_t = |
| 487 | vlib_add_trace (vm, node, b[1], sizeof (*_t)); |
| 488 | _t->sw_if_index = |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 489 | ~0 == way ? 0 : vnet_buffer (b[1])->sw_if_index[way]; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 490 | _t->next_index = _next[1]; |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 491 | _t->table_index = t[1] ? t[1] - tables : ~0; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 492 | _t->offset = (e[1] |
| 493 | && t[1]) ? vnet_classify_get_offset (t[1], e[1]) : ~0; |
| 494 | } |
| 495 | |
| 496 | if ((_next[0] == ACL_NEXT_INDEX_DENY) && is_output) |
| 497 | { |
| 498 | /* on output, for the drop node to work properly, go back to ip header */ |
| 499 | vlib_buffer_advance (b[0], vnet_buffer (b[0])->l2.l2_len); |
| 500 | } |
| 501 | |
| 502 | if ((_next[1] == ACL_NEXT_INDEX_DENY) && is_output) |
| 503 | { |
| 504 | /* on output, for the drop node to work properly, go back to ip header */ |
| 505 | vlib_buffer_advance (b[1], vnet_buffer (b[1])->l2.l2_len); |
| 506 | } |
| 507 | |
| 508 | next[0] = _next[0]; |
| 509 | next[1] = _next[1]; |
| 510 | |
| 511 | /* _next */ |
| 512 | next += 2; |
| 513 | b += 2; |
| 514 | n_left -= 2; |
| 515 | } |
| 516 | |
| 517 | while (n_left > 0) |
| 518 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 519 | u8 *h0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 520 | u32 sw_if_index0; |
| 521 | u32 table_index0; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 522 | vnet_classify_table_t *t0 = 0; |
| 523 | vnet_classify_entry_t *e0 = 0; |
| 524 | u32 next0 = ACL_NEXT_INDEX_DENY; |
| 525 | u64 hash0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 526 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 527 | sw_if_index0 = ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way]; |
| 528 | table_index0 = table_index_by_sw_if_index[sw_if_index0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 529 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 530 | t0 = pool_elt_at_index (tables, table_index0); |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 531 | |
| 532 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 533 | h0 = |
| 534 | (void *) vlib_buffer_get_current (b[0]) + t0->current_data_offset; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 535 | else |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 536 | h0 = b[0]->data; |
Steve Shin | 25e26dc | 2016-11-08 10:47:10 -0800 | [diff] [blame] | 537 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 538 | if (is_output) |
| 539 | { |
| 540 | /* Save the rewrite length, since we are using the l2_classify struct */ |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 541 | vnet_buffer (b[0])->l2_classify.pad.l2_len = |
| 542 | vnet_buffer (b[0])->ip.save_rewrite_length; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 543 | /* advance the match pointer so the matching happens on IP header */ |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 544 | h0 += vnet_buffer (b[0])->l2_classify.pad.l2_len; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 545 | } |
| 546 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 547 | vnet_buffer (b[0])->l2_classify.hash = |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 548 | vnet_classify_hash_packet (t0, (u8 *) h0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 549 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 550 | vnet_buffer (b[0])->l2_classify.table_index = table_index0; |
| 551 | vnet_buffer (b[0])->l2_classify.opaque_index = ~0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 552 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 553 | vnet_get_config_data (cm, &b[0]->current_config_index, &next0, |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 554 | /* # bytes of config data */ 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 555 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 556 | if (PREDICT_TRUE (table_index0 != ~0)) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 557 | { |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 558 | hash0 = vnet_buffer (b[0])->l2_classify.hash; |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 559 | t0 = pool_elt_at_index (tables, table_index0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 560 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 561 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 562 | h0 = |
| 563 | (void *) vlib_buffer_get_current (b[0]) + |
| 564 | t0->current_data_offset; |
| 565 | else |
| 566 | h0 = b[0]->data; |
| 567 | |
| 568 | /* advance the match pointer so the matching happens on IP header */ |
| 569 | if (is_output) |
| 570 | h0 += vnet_buffer (b[0])->l2_classify.pad.l2_len; |
| 571 | |
| 572 | e0 = vnet_classify_find_entry_inline (t0, (u8 *) h0, hash0, now); |
| 573 | if (e0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 574 | { |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 575 | vnet_buffer (b[0])->l2_classify.opaque_index = e0->opaque_index; |
| 576 | vlib_buffer_advance (b[0], e0->advance); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 577 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 578 | next0 = (e0->next_index < n_next_nodes) ? |
| 579 | e0->next_index : next0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 580 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 581 | hits++; |
| 582 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 583 | b[0]->error = |
| 584 | (next0 == ACL_NEXT_INDEX_DENY) ? error_deny : error_none; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 585 | |
| 586 | if (!is_output) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 587 | { |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 588 | if (e0->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX || |
| 589 | e0->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX) |
| 590 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] = e0->metadata; |
| 591 | else if (e0->action == CLASSIFY_ACTION_SET_METADATA) |
| 592 | vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = e0->metadata; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 593 | } |
| 594 | } |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 595 | else |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 596 | { |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 597 | while (1) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 598 | { |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 599 | if (PREDICT_TRUE (t0->next_table_index != ~0)) |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 600 | t0 = pool_elt_at_index (tables, t0->next_table_index); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 601 | else |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 602 | { |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 603 | next0 = (t0->miss_next_index < n_next_nodes) ? |
| 604 | t0->miss_next_index : next0; |
| 605 | |
| 606 | misses++; |
| 607 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 608 | b[0]->error = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 609 | error_miss : |
| 610 | error_none; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 611 | break; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 612 | } |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 613 | |
| 614 | if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA) |
| 615 | h0 = |
| 616 | (void *) vlib_buffer_get_current (b[0]) + |
| 617 | t0->current_data_offset; |
| 618 | else |
| 619 | h0 = b[0]->data; |
| 620 | |
| 621 | /* advance the match pointer so the matching happens on IP header */ |
| 622 | if (is_output) |
| 623 | h0 += vnet_buffer (b[0])->l2_classify.pad.l2_len; |
| 624 | |
| 625 | hash0 = vnet_classify_hash_packet_inline (t0, (u8 *) h0); |
| 626 | e0 = vnet_classify_find_entry_inline |
| 627 | (t0, (u8 *) h0, hash0, now); |
| 628 | if (e0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 629 | { |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 630 | vnet_buffer (b[0])->l2_classify.opaque_index |
| 631 | = e0->opaque_index; |
| 632 | vlib_buffer_advance (b[0], e0->advance); |
| 633 | next0 = (e0->next_index < n_next_nodes) ? |
| 634 | e0->next_index : next0; |
| 635 | hits++; |
| 636 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 637 | b[0]->error = (next0 == ACL_NEXT_INDEX_DENY) ? |
| 638 | error_deny : |
| 639 | error_none; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 640 | |
| 641 | if (!is_output) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 642 | { |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 643 | if (e0->action == |
| 644 | CLASSIFY_ACTION_SET_IP4_FIB_INDEX |
| 645 | || e0->action == |
| 646 | CLASSIFY_ACTION_SET_IP6_FIB_INDEX) |
| 647 | vnet_buffer (b[0])->sw_if_index[VLIB_TX] = |
| 648 | e0->metadata; |
| 649 | else if (e0->action == CLASSIFY_ACTION_SET_METADATA) |
| 650 | vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = |
| 651 | e0->metadata; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 652 | } |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 653 | break; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 654 | } |
| 655 | } |
| 656 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 657 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 658 | |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 659 | if (do_trace && b[0]->flags & VLIB_BUFFER_IS_TRACED) |
| 660 | { |
| 661 | ip_in_out_acl_trace_t *t = |
| 662 | vlib_add_trace (vm, node, b[0], sizeof (*t)); |
| 663 | t->sw_if_index = |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 664 | ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way]; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 665 | t->next_index = next0; |
Klement Sekera | 849b474 | 2021-10-25 13:39:13 +0200 | [diff] [blame] | 666 | t->table_index = t0 - tables; |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 667 | t->offset = (e0 && t0) ? vnet_classify_get_offset (t0, e0) : ~0; |
| 668 | } |
| 669 | |
| 670 | if ((next0 == ACL_NEXT_INDEX_DENY) && is_output) |
| 671 | { |
| 672 | /* on output, for the drop node to work properly, go back to ip header */ |
| 673 | vlib_buffer_advance (b[0], vnet_buffer (b[0])->l2.l2_len); |
| 674 | } |
| 675 | |
| 676 | next[0] = next0; |
| 677 | |
| 678 | /* next */ |
| 679 | next++; |
| 680 | b++; |
| 681 | n_left--; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 684 | *hits__ = hits; |
| 685 | *misses__ = misses; |
| 686 | *chain_hits__ = chain_hits; |
| 687 | } |
| 688 | |
| 689 | static_always_inline uword |
| 690 | ip_in_out_acl_inline (vlib_main_t *vm, vlib_node_runtime_t *node, |
| 691 | vlib_frame_t *frame, const in_out_acl_table_id_t tid, |
| 692 | const vlib_node_registration_t *parent_error_node, |
| 693 | const u32 error_none_index, const u32 error_deny_index, |
| 694 | const u32 error_miss_index, const vlib_rx_or_tx_t way, |
| 695 | const int is_output) |
| 696 | { |
| 697 | const in_out_acl_main_t *am = &in_out_acl_main; |
| 698 | vnet_classify_table_t *tables = am->vnet_classify_main->tables; |
| 699 | u32 *from = vlib_frame_vector_args (frame); |
| 700 | const u32 *table_index_by_sw_if_index = |
| 701 | am->classify_table_index_by_sw_if_index[is_output][tid]; |
| 702 | vnet_config_main_t *cm = am->vnet_config_main[is_output][tid]; |
| 703 | const vlib_node_runtime_t *error_node = |
| 704 | vlib_node_get_runtime (vm, parent_error_node->index); |
| 705 | const vlib_error_t error_none = error_node->errors[error_none_index]; |
| 706 | const vlib_error_t error_deny = error_node->errors[error_deny_index]; |
| 707 | const vlib_error_t error_miss = error_node->errors[error_miss_index]; |
| 708 | vlib_buffer_t *bufs[VLIB_FRAME_SIZE]; |
| 709 | u16 nexts[VLIB_FRAME_SIZE]; |
| 710 | u32 hits, misses, chain_hits; |
| 711 | |
| 712 | vlib_get_buffers (vm, from, bufs, frame->n_vectors); |
| 713 | |
| 714 | #define ip_in_out_acl_inline_trace__(do_trace) \ |
| 715 | ip_in_out_acl_inline_trace ( \ |
| 716 | vm, node, frame, bufs, nexts, frame->n_vectors, &hits, &misses, \ |
| 717 | &chain_hits, error_deny, error_miss, error_none, tables, \ |
| 718 | table_index_by_sw_if_index, cm, way, is_output, do_trace) |
| 719 | |
| 720 | if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE)) |
| 721 | ip_in_out_acl_inline_trace__ (1 /* do_trace */); |
| 722 | else |
| 723 | ip_in_out_acl_inline_trace__ (0 /* do_trace */); |
| 724 | |
| 725 | vlib_node_increment_counter ( |
| 726 | vm, node->node_index, |
| 727 | is_output ? IP_OUTACL_ERROR_MISS : IP_INACL_ERROR_MISS, misses); |
| 728 | vlib_node_increment_counter ( |
| 729 | vm, node->node_index, is_output ? IP_OUTACL_ERROR_HIT : IP_INACL_ERROR_HIT, |
| 730 | hits); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 731 | vlib_node_increment_counter (vm, node->node_index, |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 732 | is_output ? IP_OUTACL_ERROR_CHAIN_HIT : |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 733 | IP_INACL_ERROR_CHAIN_HIT, |
| 734 | chain_hits); |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 735 | |
| 736 | vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors); |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 737 | return frame->n_vectors; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 738 | } |
| 739 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 740 | VLIB_NODE_FN (ip4_inacl_node) |
| 741 | (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 742 | { |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 743 | return ip_in_out_acl_inline ( |
| 744 | vm, node, frame, IN_OUT_ACL_TABLE_IP4, &ip4_input_node, IP4_ERROR_NONE, |
| 745 | IP4_ERROR_INACL_SESSION_DENY, IP4_ERROR_INACL_TABLE_MISS, VLIB_RX, |
| 746 | 0 /* is_output */); |
| 747 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 748 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 749 | VLIB_NODE_FN (ip4_punt_acl_node) |
| 750 | (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) |
| 751 | { |
| 752 | return ip_in_out_acl_inline ( |
| 753 | vm, node, frame, IN_OUT_ACL_TABLE_IP4_PUNT, &ip4_input_node, |
| 754 | IP4_ERROR_NONE, IP4_ERROR_INACL_SESSION_DENY, IP4_ERROR_INACL_TABLE_MISS, |
| 755 | ~0 /* way */, 0 /* is_output */); |
| 756 | } |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 757 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 758 | VLIB_NODE_FN (ip4_outacl_node) |
| 759 | (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) |
| 760 | { |
| 761 | return ip_in_out_acl_inline ( |
| 762 | vm, node, frame, IN_OUT_ACL_TABLE_IP4, &ip4_input_node, IP4_ERROR_NONE, |
| 763 | IP4_ERROR_INACL_SESSION_DENY, IP4_ERROR_INACL_TABLE_MISS, VLIB_TX, |
| 764 | 1 /* is_output */); |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 765 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 766 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 767 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 768 | VLIB_REGISTER_NODE (ip4_inacl_node) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 769 | .name = "ip4-inacl", |
| 770 | .vector_size = sizeof (u32), |
| 771 | .format_trace = format_ip_inacl_trace, |
| 772 | .n_errors = ARRAY_LEN(ip_inacl_error_strings), |
| 773 | .error_strings = ip_inacl_error_strings, |
| 774 | |
| 775 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 776 | .next_nodes = { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 777 | [ACL_NEXT_INDEX_DENY] = "ip4-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 778 | }, |
| 779 | }; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 780 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 781 | VLIB_REGISTER_NODE (ip4_punt_acl_node) = { |
| 782 | .name = "ip4-punt-acl", |
| 783 | .vector_size = sizeof (u32), |
| 784 | .format_trace = format_ip_inacl_trace, |
| 785 | .n_errors = ARRAY_LEN(ip_inacl_error_strings), |
| 786 | .error_strings = ip_inacl_error_strings, |
| 787 | |
| 788 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 789 | .next_nodes = { |
| 790 | [ACL_NEXT_INDEX_DENY] = "ip4-drop", |
| 791 | }, |
| 792 | }; |
| 793 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 794 | VLIB_REGISTER_NODE (ip4_outacl_node) = { |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 795 | .name = "ip4-outacl", |
| 796 | .vector_size = sizeof (u32), |
| 797 | .format_trace = format_ip_outacl_trace, |
| 798 | .n_errors = ARRAY_LEN(ip_outacl_error_strings), |
| 799 | .error_strings = ip_outacl_error_strings, |
| 800 | |
| 801 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 802 | .next_nodes = { |
| 803 | [ACL_NEXT_INDEX_DENY] = "ip4-drop", |
| 804 | }, |
| 805 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 806 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 807 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 808 | VNET_FEATURE_INIT (ip4_punt_acl_feature) = { |
| 809 | .arc_name = "ip4-punt", |
| 810 | .node_name = "ip4-punt-acl", |
| 811 | .runs_after = VNET_FEATURES ("ip4-punt-policer"), |
| 812 | }; |
| 813 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 814 | VLIB_NODE_FN (ip6_inacl_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 815 | vlib_frame_t * frame) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 816 | { |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 817 | return ip_in_out_acl_inline ( |
| 818 | vm, node, frame, IN_OUT_ACL_TABLE_IP6, &ip6_input_node, IP6_ERROR_NONE, |
| 819 | IP6_ERROR_INACL_SESSION_DENY, IP6_ERROR_INACL_TABLE_MISS, VLIB_RX, |
| 820 | 0 /* is_output */); |
| 821 | } |
Ray Kinsella | 8899ce0 | 2020-03-12 15:52:41 +0000 | [diff] [blame] | 822 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 823 | VLIB_NODE_FN (ip6_punt_acl_node) |
| 824 | (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame) |
| 825 | { |
| 826 | return ip_in_out_acl_inline ( |
| 827 | vm, node, frame, IN_OUT_ACL_TABLE_IP6_PUNT, &ip6_input_node, |
| 828 | IP6_ERROR_NONE, IP6_ERROR_INACL_SESSION_DENY, IP6_ERROR_INACL_TABLE_MISS, |
| 829 | ~0 /* way */, 0 /* is_output */); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 832 | VLIB_NODE_FN (ip6_outacl_node) (vlib_main_t * vm, vlib_node_runtime_t * node, |
| 833 | vlib_frame_t * frame) |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 834 | { |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 835 | return ip_in_out_acl_inline ( |
| 836 | vm, node, frame, IN_OUT_ACL_TABLE_IP6, &ip6_input_node, IP6_ERROR_NONE, |
| 837 | IP6_ERROR_INACL_SESSION_DENY, IP6_ERROR_INACL_TABLE_MISS, VLIB_TX, |
| 838 | 1 /* is_output */); |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 839 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 840 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 841 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 842 | VLIB_REGISTER_NODE (ip6_inacl_node) = { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 843 | .name = "ip6-inacl", |
| 844 | .vector_size = sizeof (u32), |
| 845 | .format_trace = format_ip_inacl_trace, |
| 846 | .n_errors = ARRAY_LEN(ip_inacl_error_strings), |
| 847 | .error_strings = ip_inacl_error_strings, |
| 848 | |
| 849 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 850 | .next_nodes = { |
Vijayabhaskar Katamreddy | ce07412 | 2017-11-15 13:50:26 -0800 | [diff] [blame] | 851 | [ACL_NEXT_INDEX_DENY] = "ip6-drop", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 852 | }, |
| 853 | }; |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 854 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 855 | VLIB_REGISTER_NODE (ip6_punt_acl_node) = { |
| 856 | .name = "ip6-punt-acl", |
| 857 | .vector_size = sizeof (u32), |
| 858 | .format_trace = format_ip_inacl_trace, |
| 859 | .n_errors = ARRAY_LEN(ip_inacl_error_strings), |
| 860 | .error_strings = ip_inacl_error_strings, |
| 861 | |
| 862 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 863 | .next_nodes = { |
| 864 | [ACL_NEXT_INDEX_DENY] = "ip6-drop", |
| 865 | }, |
| 866 | }; |
| 867 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 868 | VLIB_REGISTER_NODE (ip6_outacl_node) = { |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 869 | .name = "ip6-outacl", |
| 870 | .vector_size = sizeof (u32), |
| 871 | .format_trace = format_ip_outacl_trace, |
| 872 | .n_errors = ARRAY_LEN(ip_outacl_error_strings), |
| 873 | .error_strings = ip_outacl_error_strings, |
| 874 | |
| 875 | .n_next_nodes = ACL_NEXT_INDEX_N_NEXT, |
| 876 | .next_nodes = { |
| 877 | [ACL_NEXT_INDEX_DENY] = "ip6-drop", |
| 878 | }, |
| 879 | }; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 880 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 881 | |
Benoît Ganne | abb2a42 | 2021-09-30 13:41:00 +0200 | [diff] [blame] | 882 | VNET_FEATURE_INIT (ip6_punt_acl_feature) = { |
| 883 | .arc_name = "ip6-punt", |
| 884 | .node_name = "ip6-punt-acl", |
| 885 | .runs_after = VNET_FEATURES ("ip6-punt-policer"), |
| 886 | }; |
| 887 | |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 888 | #ifndef CLIB_MARCH_VARIANT |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 889 | static clib_error_t * |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 890 | ip_in_out_acl_init (vlib_main_t * vm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 891 | { |
| 892 | return 0; |
| 893 | } |
| 894 | |
Andrew Yourtchenko | 815d7d5 | 2018-02-07 11:37:02 +0100 | [diff] [blame] | 895 | VLIB_INIT_FUNCTION (ip_in_out_acl_init); |
Filip Tehlar | 26ea14e | 2019-03-11 05:30:21 -0700 | [diff] [blame] | 896 | #endif /* CLIB_MARCH_VARIANT */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 897 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 898 | |
| 899 | /* |
| 900 | * fd.io coding-style-patch-verification: ON |
| 901 | * |
| 902 | * Local Variables: |
| 903 | * eval: (c-set-style "gnu") |
| 904 | * End: |
| 905 | */ |