blob: 2e2cb1e7f367a0631d14b275e2d361febd4f91be [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01002 * l2_in_out_acl.c : layer 2 input/output acl processing
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 *
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01004 * Copyright (c) 2013,2018 Cisco and/or its affiliates.
Ed Warnickecb9cada2015-12-08 15:45:58 -07005 * 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>
Ed Warnickecb9cada2015-12-08 15:45:58 -070020#include <vnet/ethernet/ethernet.h>
21#include <vnet/ethernet/packet.h>
22#include <vnet/ip/ip_packet.h>
23#include <vnet/ip/ip4_packet.h>
24#include <vnet/ip/ip6_packet.h>
25#include <vlib/cli.h>
26#include <vnet/l2/l2_input.h>
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010027#include <vnet/l2/l2_output.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070028#include <vnet/l2/feat_bitmap.h>
29
30#include <vppinfra/error.h>
31#include <vppinfra/hash.h>
32#include <vppinfra/cache.h>
33
34#include <vnet/classify/vnet_classify.h>
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010035#include <vnet/classify/in_out_acl.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070036
Dave Barach97d8dc22016-08-15 15:31:15 -040037typedef struct
38{
Ed Warnickecb9cada2015-12-08 15:45:58 -070039
Dave Barach97d8dc22016-08-15 15:31:15 -040040 /* Next nodes for each feature */
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010041 u32 feat_next_node_index[IN_OUT_ACL_N_TABLE_GROUPS][32];
Ed Warnickecb9cada2015-12-08 15:45:58 -070042
43 /* convenience variables */
Dave Barach97d8dc22016-08-15 15:31:15 -040044 vlib_main_t *vlib_main;
45 vnet_main_t *vnet_main;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010046} l2_in_out_acl_main_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070047
Dave Barach97d8dc22016-08-15 15:31:15 -040048typedef struct
49{
Ed Warnickecb9cada2015-12-08 15:45:58 -070050 u32 sw_if_index;
51 u32 next_index;
52 u32 table_index;
53 u32 offset;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010054} l2_in_out_acl_trace_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070055
56/* packet trace format function */
Dave Barach97d8dc22016-08-15 15:31:15 -040057static u8 *
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010058format_l2_in_out_acl_trace (u8 * s, u32 is_output, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070059{
60 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
61 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010062 l2_in_out_acl_trace_t *t = va_arg (*args, l2_in_out_acl_trace_t *);
Dave Barach97d8dc22016-08-15 15:31:15 -040063
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010064 s = format (s, "%s: sw_if_index %d, next_index %d, table %d, offset %d",
65 is_output ? "OUTACL" : "INACL",
Ed Warnickecb9cada2015-12-08 15:45:58 -070066 t->sw_if_index, t->next_index, t->table_index, t->offset);
67 return s;
68}
69
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010070static u8 *
71format_l2_inacl_trace (u8 * s, va_list * args)
72{
73 return format_l2_in_out_acl_trace (s, IN_OUT_ACL_INPUT_TABLE_GROUP, args);
74}
75
76static u8 *
77format_l2_outacl_trace (u8 * s, va_list * args)
78{
79 return format_l2_in_out_acl_trace (s, IN_OUT_ACL_OUTPUT_TABLE_GROUP, args);
80}
81
Filip Tehlar44f0f712019-03-11 04:26:37 -070082extern l2_in_out_acl_main_t l2_in_out_acl_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070083
Filip Tehlar44f0f712019-03-11 04:26:37 -070084#ifndef CLIB_MARCH_VARIANT
85l2_in_out_acl_main_t l2_in_out_acl_main;
86#endif /* CLIB_MARCH_VARIANT */
87
88extern vlib_node_registration_t l2_inacl_node;
89extern vlib_node_registration_t l2_outacl_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -070090
91#define foreach_l2_inacl_error \
92_(NONE, "valid input ACL packets") \
93_(MISS, "input ACL misses") \
94_(HIT, "input ACL hits") \
95_(CHAIN_HIT, "input ACL hits after chain walk") \
96_(TABLE_MISS, "input ACL table-miss drops") \
97_(SESSION_DENY, "input ACL session deny drops")
98
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010099#define foreach_l2_outacl_error \
100_(NONE, "valid output ACL packets") \
101_(MISS, "output ACL misses") \
102_(HIT, "output ACL hits") \
103_(CHAIN_HIT, "output ACL hits after chain walk") \
104_(TABLE_MISS, "output ACL table-miss drops") \
105_(SESSION_DENY, "output ACL session deny drops")
106
Ed Warnickecb9cada2015-12-08 15:45:58 -0700107
Dave Barach97d8dc22016-08-15 15:31:15 -0400108typedef enum
109{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110#define _(sym,str) L2_INACL_ERROR_##sym,
111 foreach_l2_inacl_error
112#undef _
Dave Barach97d8dc22016-08-15 15:31:15 -0400113 L2_INACL_N_ERROR,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700114} l2_inacl_error_t;
115
Dave Barach97d8dc22016-08-15 15:31:15 -0400116static char *l2_inacl_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117#define _(sym,string) string,
118 foreach_l2_inacl_error
119#undef _
120};
121
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100122typedef enum
123{
124#define _(sym,str) L2_OUTACL_ERROR_##sym,
125 foreach_l2_outacl_error
126#undef _
127 L2_OUTACL_N_ERROR,
128} l2_outacl_error_t;
129
130static char *l2_outacl_error_strings[] = {
131#define _(sym,string) string,
132 foreach_l2_outacl_error
133#undef _
134};
135
136
137static inline uword
138l2_in_out_acl_node_fn (vlib_main_t * vm,
139 vlib_node_runtime_t * node, vlib_frame_t * frame,
140 int is_output)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141{
Dave Barach97d8dc22016-08-15 15:31:15 -0400142 u32 n_left_from, *from, *to_next;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700143 acl_next_index_t next_index;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100144 l2_in_out_acl_main_t *msm = &l2_in_out_acl_main;
145 in_out_acl_main_t *am = &in_out_acl_main;
Dave Barach97d8dc22016-08-15 15:31:15 -0400146 vnet_classify_main_t *vcm = am->vnet_classify_main;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100147 in_out_acl_table_id_t tid = IN_OUT_ACL_TABLE_L2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700148 f64 now = vlib_time_now (vm);
149 u32 hits = 0;
150 u32 misses = 0;
151 u32 chain_hits = 0;
152
153 from = vlib_frame_vector_args (frame);
Dave Barach97d8dc22016-08-15 15:31:15 -0400154 n_left_from = frame->n_vectors; /* number of packets to process */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700155 next_index = node->cached_next_index;
156
157 /* First pass: compute hashes */
158 while (n_left_from > 2)
159 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400160 vlib_buffer_t *b0, *b1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700161 u32 bi0, bi1;
Dave Barach97d8dc22016-08-15 15:31:15 -0400162 u8 *h0, *h1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700163 u32 sw_if_index0, sw_if_index1;
164 u32 table_index0, table_index1;
Dave Barach97d8dc22016-08-15 15:31:15 -0400165 vnet_classify_table_t *t0, *t1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700166
167 /* prefetch next iteration */
168 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400169 vlib_buffer_t *p1, *p2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170
Dave Barach97d8dc22016-08-15 15:31:15 -0400171 p1 = vlib_get_buffer (vm, from[1]);
172 p2 = vlib_get_buffer (vm, from[2]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700173
Dave Barach97d8dc22016-08-15 15:31:15 -0400174 vlib_prefetch_buffer_header (p1, STORE);
Damjan Marionaf7fb042021-07-15 11:54:41 +0200175 clib_prefetch_store (p1->data);
Dave Barach97d8dc22016-08-15 15:31:15 -0400176 vlib_prefetch_buffer_header (p2, STORE);
Damjan Marionaf7fb042021-07-15 11:54:41 +0200177 clib_prefetch_store (p2->data);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178 }
179
180 bi0 = from[0];
181 b0 = vlib_get_buffer (vm, bi0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700182
183 bi1 = from[1];
184 b1 = vlib_get_buffer (vm, bi1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100186 sw_if_index0 =
187 vnet_buffer (b0)->sw_if_index[is_output ? VLIB_TX : VLIB_RX];
Dave Barach97d8dc22016-08-15 15:31:15 -0400188 table_index0 =
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100189 am->classify_table_index_by_sw_if_index[is_output][tid][sw_if_index0];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700190
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100191 sw_if_index1 =
192 vnet_buffer (b1)->sw_if_index[is_output ? VLIB_TX : VLIB_RX];
Dave Barach97d8dc22016-08-15 15:31:15 -0400193 table_index1 =
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100194 am->classify_table_index_by_sw_if_index[is_output][tid][sw_if_index1];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700195
196 t0 = pool_elt_at_index (vcm->tables, table_index0);
197
198 t1 = pool_elt_at_index (vcm->tables, table_index1);
199
Steve Shin25e26dc2016-11-08 10:47:10 -0800200 if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
201 h0 = (void *) vlib_buffer_get_current (b0) + t0->current_data_offset;
202 else
Steve Shin2ae03d22018-02-26 11:43:31 -0800203 h0 = (void *) vlib_buffer_get_current (b0);
Steve Shin25e26dc2016-11-08 10:47:10 -0800204
Dave Barach97d8dc22016-08-15 15:31:15 -0400205 vnet_buffer (b0)->l2_classify.hash =
206 vnet_classify_hash_packet (t0, (u8 *) h0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700207
Dave Barach97d8dc22016-08-15 15:31:15 -0400208 vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700209
Steve Shin25e26dc2016-11-08 10:47:10 -0800210 if (t1->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
211 h1 = (void *) vlib_buffer_get_current (b1) + t1->current_data_offset;
212 else
Steve Shin2ae03d22018-02-26 11:43:31 -0800213 h1 = (void *) vlib_buffer_get_current (b1);
Steve Shin25e26dc2016-11-08 10:47:10 -0800214
Dave Barach97d8dc22016-08-15 15:31:15 -0400215 vnet_buffer (b1)->l2_classify.hash =
216 vnet_classify_hash_packet (t1, (u8 *) h1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700217
Dave Barach97d8dc22016-08-15 15:31:15 -0400218 vnet_classify_prefetch_bucket (t1, vnet_buffer (b1)->l2_classify.hash);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700219
Dave Barach97d8dc22016-08-15 15:31:15 -0400220 vnet_buffer (b0)->l2_classify.table_index = table_index0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700221
Dave Barach97d8dc22016-08-15 15:31:15 -0400222 vnet_buffer (b1)->l2_classify.table_index = table_index1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700223
224 from += 2;
225 n_left_from -= 2;
226 }
227
228 while (n_left_from > 0)
229 {
Dave Barach97d8dc22016-08-15 15:31:15 -0400230 vlib_buffer_t *b0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700231 u32 bi0;
Dave Barach97d8dc22016-08-15 15:31:15 -0400232 u8 *h0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700233 u32 sw_if_index0;
234 u32 table_index0;
Dave Barach97d8dc22016-08-15 15:31:15 -0400235 vnet_classify_table_t *t0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700236
237 bi0 = from[0];
238 b0 = vlib_get_buffer (vm, bi0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700239
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100240 sw_if_index0 =
241 vnet_buffer (b0)->sw_if_index[is_output ? VLIB_TX : VLIB_RX];
Dave Barach97d8dc22016-08-15 15:31:15 -0400242 table_index0 =
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100243 am->classify_table_index_by_sw_if_index[is_output][tid][sw_if_index0];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700244
245 t0 = pool_elt_at_index (vcm->tables, table_index0);
Steve Shin25e26dc2016-11-08 10:47:10 -0800246
247 if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
248 h0 = (void *) vlib_buffer_get_current (b0) + t0->current_data_offset;
249 else
Steve Shin2ae03d22018-02-26 11:43:31 -0800250 h0 = (void *) vlib_buffer_get_current (b0);
Steve Shin25e26dc2016-11-08 10:47:10 -0800251
Dave Barach97d8dc22016-08-15 15:31:15 -0400252 vnet_buffer (b0)->l2_classify.hash =
253 vnet_classify_hash_packet (t0, (u8 *) h0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700254
Dave Barach97d8dc22016-08-15 15:31:15 -0400255 vnet_buffer (b0)->l2_classify.table_index = table_index0;
256 vnet_classify_prefetch_bucket (t0, vnet_buffer (b0)->l2_classify.hash);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700257
258 from++;
259 n_left_from--;
260 }
261
262 next_index = node->cached_next_index;
263 from = vlib_frame_vector_args (frame);
264 n_left_from = frame->n_vectors;
265
266 while (n_left_from > 0)
267 {
268 u32 n_left_to_next;
269
Dave Barach97d8dc22016-08-15 15:31:15 -0400270 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700271
272 /* Not enough load/store slots to dual loop... */
273 while (n_left_from > 0 && n_left_to_next > 0)
Dave Barach97d8dc22016-08-15 15:31:15 -0400274 {
275 u32 bi0;
276 vlib_buffer_t *b0;
277 u32 next0 = ACL_NEXT_INDEX_DENY;
278 u32 table_index0;
279 vnet_classify_table_t *t0;
280 vnet_classify_entry_t *e0;
Benoît Ganneb03eec92022-06-08 10:49:17 +0200281 u32 hash0;
Dave Barach97d8dc22016-08-15 15:31:15 -0400282 u8 *h0;
283 u8 error0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700284
Dave Barach97d8dc22016-08-15 15:31:15 -0400285 /* Stride 3 seems to work best */
286 if (PREDICT_TRUE (n_left_from > 3))
287 {
288 vlib_buffer_t *p1 = vlib_get_buffer (vm, from[3]);
289 vnet_classify_table_t *tp1;
290 u32 table_index1;
Benoît Ganneb03eec92022-06-08 10:49:17 +0200291 u32 phash1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700292
Dave Barach97d8dc22016-08-15 15:31:15 -0400293 table_index1 = vnet_buffer (p1)->l2_classify.table_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700294
Dave Barach97d8dc22016-08-15 15:31:15 -0400295 if (PREDICT_TRUE (table_index1 != ~0))
296 {
297 tp1 = pool_elt_at_index (vcm->tables, table_index1);
298 phash1 = vnet_buffer (p1)->l2_classify.hash;
299 vnet_classify_prefetch_entry (tp1, phash1);
300 }
301 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700302
Dave Barach97d8dc22016-08-15 15:31:15 -0400303 /* speculatively enqueue b0 to the current next frame */
304 bi0 = from[0];
305 to_next[0] = bi0;
306 from += 1;
307 to_next += 1;
308 n_left_from -= 1;
309 n_left_to_next -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700310
Dave Barach97d8dc22016-08-15 15:31:15 -0400311 b0 = vlib_get_buffer (vm, bi0);
Steve Shin25e26dc2016-11-08 10:47:10 -0800312
Dave Barach97d8dc22016-08-15 15:31:15 -0400313 table_index0 = vnet_buffer (b0)->l2_classify.table_index;
314 e0 = 0;
315 t0 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700316
Dave Barach97d8dc22016-08-15 15:31:15 -0400317 vnet_buffer (b0)->l2_classify.opaque_index = ~0;
John Lobeb0b2e2017-07-22 00:21:36 -0400318
Dave Barach97d8dc22016-08-15 15:31:15 -0400319 /* Determine the next node */
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100320 next0 =
321 vnet_l2_feature_next (b0, msm->feat_next_node_index[is_output],
322 is_output ? L2OUTPUT_FEAT_ACL :
323 L2INPUT_FEAT_ACL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324
Dave Barach97d8dc22016-08-15 15:31:15 -0400325 if (PREDICT_TRUE (table_index0 != ~0))
326 {
327 hash0 = vnet_buffer (b0)->l2_classify.hash;
328 t0 = pool_elt_at_index (vcm->tables, table_index0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700329
Steve Shin25e26dc2016-11-08 10:47:10 -0800330 if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
331 h0 =
332 (void *) vlib_buffer_get_current (b0) +
333 t0->current_data_offset;
334 else
Steve Shin2ae03d22018-02-26 11:43:31 -0800335 h0 = (void *) vlib_buffer_get_current (b0);
Steve Shin25e26dc2016-11-08 10:47:10 -0800336
Dave Barach97d8dc22016-08-15 15:31:15 -0400337 e0 = vnet_classify_find_entry (t0, (u8 *) h0, hash0, now);
338 if (e0)
339 {
340 vnet_buffer (b0)->l2_classify.opaque_index
341 = e0->opaque_index;
342 vlib_buffer_advance (b0, e0->advance);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700343
Dave Barach97d8dc22016-08-15 15:31:15 -0400344 next0 = (e0->next_index < ACL_NEXT_INDEX_N_NEXT) ?
345 e0->next_index : next0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700346
Dave Barach97d8dc22016-08-15 15:31:15 -0400347 hits++;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700348
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100349 if (is_output)
350 error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
351 L2_OUTACL_ERROR_SESSION_DENY : L2_INACL_ERROR_NONE;
352 else
353 error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
354 L2_OUTACL_ERROR_SESSION_DENY : L2_OUTACL_ERROR_NONE;
Dave Barach97d8dc22016-08-15 15:31:15 -0400355 b0->error = node->errors[error0];
356 }
357 else
358 {
359 while (1)
360 {
361 if (PREDICT_TRUE (t0->next_table_index != ~0))
362 t0 = pool_elt_at_index (vcm->tables,
363 t0->next_table_index);
364 else
365 {
366 next0 =
367 (t0->miss_next_index <
368 ACL_NEXT_INDEX_N_NEXT) ? t0->miss_next_index :
369 next0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700370
Dave Barach97d8dc22016-08-15 15:31:15 -0400371 misses++;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700372
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100373 if (is_output)
374 error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
375 L2_OUTACL_ERROR_TABLE_MISS :
376 L2_OUTACL_ERROR_NONE;
377 else
378 error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
379 L2_INACL_ERROR_TABLE_MISS : L2_INACL_ERROR_NONE;
Dave Barach97d8dc22016-08-15 15:31:15 -0400380 b0->error = node->errors[error0];
381 break;
382 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700383
Steve Shin25e26dc2016-11-08 10:47:10 -0800384 if (t0->current_data_flag ==
385 CLASSIFY_FLAG_USE_CURR_DATA)
386 h0 =
387 (void *) vlib_buffer_get_current (b0) +
388 t0->current_data_offset;
389 else
Steve Shin2ae03d22018-02-26 11:43:31 -0800390 h0 = (void *) vlib_buffer_get_current (b0);
Steve Shin25e26dc2016-11-08 10:47:10 -0800391
Dave Barach97d8dc22016-08-15 15:31:15 -0400392 hash0 = vnet_classify_hash_packet (t0, (u8 *) h0);
393 e0 = vnet_classify_find_entry
394 (t0, (u8 *) h0, hash0, now);
395 if (e0)
396 {
397 vlib_buffer_advance (b0, e0->advance);
398 next0 = (e0->next_index < ACL_NEXT_INDEX_N_NEXT) ?
399 e0->next_index : next0;
400 hits++;
401 chain_hits++;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700402
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100403 if (is_output)
404 error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
405 L2_OUTACL_ERROR_SESSION_DENY :
406 L2_OUTACL_ERROR_NONE;
407 else
408 error0 = (next0 == ACL_NEXT_INDEX_DENY) ?
409 L2_INACL_ERROR_SESSION_DENY :
410 L2_INACL_ERROR_NONE;
Dave Barach97d8dc22016-08-15 15:31:15 -0400411 b0->error = node->errors[error0];
412 break;
413 }
414 }
415 }
416 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700417
Dave Barach97d8dc22016-08-15 15:31:15 -0400418 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
419 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
420 {
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100421 l2_in_out_acl_trace_t *t =
Dave Barach97d8dc22016-08-15 15:31:15 -0400422 vlib_add_trace (vm, node, b0, sizeof (*t));
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100423 t->sw_if_index =
424 vnet_buffer (b0)->sw_if_index[is_output ? VLIB_TX : VLIB_RX];
Dave Barach97d8dc22016-08-15 15:31:15 -0400425 t->next_index = next0;
426 t->table_index = t0 ? t0 - vcm->tables : ~0;
427 t->offset = (t0 && e0) ? vnet_classify_get_offset (t0, e0) : ~0;
428 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700429
Dave Barach97d8dc22016-08-15 15:31:15 -0400430 /* verify speculative enqueue, maybe switch current next frame */
431 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
432 to_next, n_left_to_next,
433 bi0, next0);
434 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700435
436 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
437 }
438
439 vlib_node_increment_counter (vm, node->node_index,
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100440 is_output ? L2_OUTACL_ERROR_MISS :
Dave Barach97d8dc22016-08-15 15:31:15 -0400441 L2_INACL_ERROR_MISS, misses);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700442 vlib_node_increment_counter (vm, node->node_index,
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100443 is_output ? L2_OUTACL_ERROR_HIT :
Dave Barach97d8dc22016-08-15 15:31:15 -0400444 L2_INACL_ERROR_HIT, hits);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700445 vlib_node_increment_counter (vm, node->node_index,
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100446 is_output ? L2_OUTACL_ERROR_CHAIN_HIT :
Dave Barach97d8dc22016-08-15 15:31:15 -0400447 L2_INACL_ERROR_CHAIN_HIT, chain_hits);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700448 return frame->n_vectors;
449}
450
Filip Tehlar44f0f712019-03-11 04:26:37 -0700451VLIB_NODE_FN (l2_inacl_node) (vlib_main_t * vm,
452 vlib_node_runtime_t * node,
453 vlib_frame_t * frame)
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100454{
455 return l2_in_out_acl_node_fn (vm, node, frame,
456 IN_OUT_ACL_INPUT_TABLE_GROUP);
457}
458
Filip Tehlar44f0f712019-03-11 04:26:37 -0700459VLIB_NODE_FN (l2_outacl_node) (vlib_main_t * vm,
460 vlib_node_runtime_t * node,
461 vlib_frame_t * frame)
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100462{
463 return l2_in_out_acl_node_fn (vm, node, frame,
464 IN_OUT_ACL_OUTPUT_TABLE_GROUP);
465}
466
Filip Tehlar44f0f712019-03-11 04:26:37 -0700467VLIB_REGISTER_NODE (l2_inacl_node) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700468 .name = "l2-input-acl",
469 .vector_size = sizeof (u32),
470 .format_trace = format_l2_inacl_trace,
471 .type = VLIB_NODE_TYPE_INTERNAL,
Dave Barach97d8dc22016-08-15 15:31:15 -0400472
Ed Warnickecb9cada2015-12-08 15:45:58 -0700473 .n_errors = ARRAY_LEN(l2_inacl_error_strings),
474 .error_strings = l2_inacl_error_strings,
475
476 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
477
478 /* edit / add dispositions here */
479 .next_nodes = {
480 [ACL_NEXT_INDEX_DENY] = "error-drop",
481 },
482};
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100483
Filip Tehlar44f0f712019-03-11 04:26:37 -0700484VLIB_REGISTER_NODE (l2_outacl_node) = {
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100485 .name = "l2-output-acl",
486 .vector_size = sizeof (u32),
487 .format_trace = format_l2_outacl_trace,
488 .type = VLIB_NODE_TYPE_INTERNAL,
489
490 .n_errors = ARRAY_LEN(l2_outacl_error_strings),
491 .error_strings = l2_outacl_error_strings,
492
493 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
494
495 /* edit / add dispositions here */
496 .next_nodes = {
497 [ACL_NEXT_INDEX_DENY] = "error-drop",
498 },
499};
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100500
501
Filip Tehlar44f0f712019-03-11 04:26:37 -0700502#ifndef CLIB_MARCH_VARIANT
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100503clib_error_t *
504l2_in_out_acl_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700505{
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100506 l2_in_out_acl_main_t *mp = &l2_in_out_acl_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700507
Dave Barach97d8dc22016-08-15 15:31:15 -0400508 mp->vlib_main = vm;
509 mp->vnet_main = vnet_get_main ();
510
511 /* Initialize the feature next-node indexes */
512 feat_bitmap_init_next_nodes (vm,
513 l2_inacl_node.index,
514 L2INPUT_N_FEAT,
515 l2input_get_feat_names (),
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100516 mp->feat_next_node_index
517 [IN_OUT_ACL_INPUT_TABLE_GROUP]);
518 feat_bitmap_init_next_nodes (vm, l2_outacl_node.index, L2OUTPUT_N_FEAT,
519 l2output_get_feat_names (),
520 mp->feat_next_node_index
521 [IN_OUT_ACL_OUTPUT_TABLE_GROUP]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700522
523 return 0;
524}
525
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100526VLIB_INIT_FUNCTION (l2_in_out_acl_init);
Filip Tehlar44f0f712019-03-11 04:26:37 -0700527#endif /* CLIB_MARCH_VARIANT */
Dave Barach97d8dc22016-08-15 15:31:15 -0400528
529/*
530 * fd.io coding-style-patch-verification: ON
531 *
532 * Local Variables:
533 * eval: (c-set-style "gnu")
534 * End:
535 */