blob: 500eefd7c91fe1940e86b72a41692af5cd004ab9 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 Yourtchenko815d7d52018-02-07 11:37:02 +010017#include <vnet/classify/in_out_acl.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070018
Dave Barachd7cb1b52016-12-09 09:52:16 -050019typedef struct
20{
Ed Warnickecb9cada2015-12-08 15:45:58 -070021 u32 sw_if_index;
22 u32 next_index;
23 u32 table_index;
24 u32 offset;
Ray Kinsella8899ce02020-03-12 15:52:41 +000025}
26ip_in_out_acl_trace_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070027
28/* packet trace format function */
Dave Barachd7cb1b52016-12-09 09:52:16 -050029static u8 *
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010030format_ip_in_out_acl_trace (u8 * s, u32 is_output, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070031{
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 Yourtchenko815d7d52018-02-07 11:37:02 +010034 ip_in_out_acl_trace_t *t = va_arg (*args, ip_in_out_acl_trace_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070035
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010036 s = format (s, "%s: sw_if_index %d, next_index %d, table %d, offset %d",
37 is_output ? "OUTACL" : "INACL",
Dave Barachd7cb1b52016-12-09 09:52:16 -050038 t->sw_if_index, t->next_index, t->table_index, t->offset);
Ed Warnickecb9cada2015-12-08 15:45:58 -070039 return s;
40}
41
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010042static u8 *
43format_ip_inacl_trace (u8 * s, va_list * args)
44{
45 return format_ip_in_out_acl_trace (s, 0 /* is_output */ , args);
46}
47
48static u8 *
49format_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 Tehlar26ea14e2019-03-11 05:30:21 -070054extern vlib_node_registration_t ip4_inacl_node;
55extern vlib_node_registration_t ip4_outacl_node;
56extern vlib_node_registration_t ip6_inacl_node;
57extern vlib_node_registration_t ip6_outacl_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -070058
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 Yourtchenko815d7d52018-02-07 11:37:02 +010064#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 Barachd7cb1b52016-12-09 09:52:16 -050069typedef enum
70{
Ed Warnickecb9cada2015-12-08 15:45:58 -070071#define _(sym,str) IP_INACL_ERROR_##sym,
72 foreach_ip_inacl_error
73#undef _
Dave Barachd7cb1b52016-12-09 09:52:16 -050074 IP_INACL_N_ERROR,
Ray Kinsella8899ce02020-03-12 15:52:41 +000075}
76ip_inacl_error_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070077
Dave Barachd7cb1b52016-12-09 09:52:16 -050078static char *ip_inacl_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -070079#define _(sym,string) string,
80 foreach_ip_inacl_error
81#undef _
82};
83
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010084typedef enum
85{
86#define _(sym,str) IP_OUTACL_ERROR_##sym,
87 foreach_ip_outacl_error
88#undef _
89 IP_OUTACL_N_ERROR,
Ray Kinsella8899ce02020-03-12 15:52:41 +000090}
91ip_outacl_error_t;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010092
93static char *ip_outacl_error_strings[] = {
94#define _(sym,string) string,
95 foreach_ip_outacl_error
96#undef _
97};
98
Ray Kinsella8899ce02020-03-12 15:52:41 +000099static_always_inline void
Arthur de Kerhor10310982021-12-22 10:58:30 +0100100ip_in_out_acl_inline_trace (
101 vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame,
102 vlib_buffer_t **b, u16 *next, u32 n_left, u32 *hits__, u32 *misses__,
103 u32 *chain_hits__, const vlib_error_t error_none,
104 const vlib_error_t error_deny, const vlib_error_t error_miss,
105 vnet_classify_table_t *tables, const u32 *table_index_by_sw_if_index,
106 u32 *fib_index_by_sw_if_index, vnet_config_main_t *cm,
107 const vlib_rx_or_tx_t way, const int is_output, const int do_trace)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109 f64 now = vlib_time_now (vm);
110 u32 hits = 0;
111 u32 misses = 0;
112 u32 chain_hits = 0;
Benoît Ganneabb2a422021-09-30 13:41:00 +0200113 u32 n_next_nodes = node->n_next_nodes;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000114 u8 *h[4];
115 u32 sw_if_index[4];
116 u32 table_index[4];
117 vnet_classify_table_t *t[4] = { 0, 0 };
118 u64 hash[4];
119
Ray Kinsella8899ce02020-03-12 15:52:41 +0000120 /* calculate hashes for b[0] & b[1] */
121 if (n_left >= 2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122 {
Benoît Ganneabb2a422021-09-30 13:41:00 +0200123 /* ~0 is used as a wildcard to say 'always use sw_if_index 0'
124 * aka local0. It is used when we do not care about the sw_if_index, as
125 * when punting */
126 sw_if_index[2] = ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way];
127 sw_if_index[3] = ~0 == way ? 0 : vnet_buffer (b[1])->sw_if_index[way];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700128
Benoît Ganneabb2a422021-09-30 13:41:00 +0200129 table_index[2] = table_index_by_sw_if_index[sw_if_index[2]];
130 table_index[3] = table_index_by_sw_if_index[sw_if_index[3]];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131
Benoît Ganneabb2a422021-09-30 13:41:00 +0200132 t[2] = pool_elt_at_index (tables, table_index[2]);
133 t[3] = pool_elt_at_index (tables, table_index[3]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700134
Ray Kinsella8899ce02020-03-12 15:52:41 +0000135 if (t[2]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
136 h[2] =
137 (void *) vlib_buffer_get_current (b[0]) + t[2]->current_data_offset;
Steve Shin25e26dc2016-11-08 10:47:10 -0800138 else
Ray Kinsella8899ce02020-03-12 15:52:41 +0000139 h[2] = b[0]->data;
140
141 if (t[3]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
142 h[3] =
143 (void *) vlib_buffer_get_current (b[1]) + t[3]->current_data_offset;
144 else
145 h[3] = b[1]->data;
Steve Shin25e26dc2016-11-08 10:47:10 -0800146
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100147 if (is_output)
148 {
149 /* Save the rewrite length, since we are using the l2_classify struct */
Ray Kinsella8899ce02020-03-12 15:52:41 +0000150 vnet_buffer (b[0])->l2_classify.pad.l2_len =
151 vnet_buffer (b[0])->ip.save_rewrite_length;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100152 /* advance the match pointer so the matching happens on IP header */
Ray Kinsella8899ce02020-03-12 15:52:41 +0000153 h[2] += vnet_buffer (b[0])->l2_classify.pad.l2_len;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100154
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100155 /* Save the rewrite length, since we are using the l2_classify struct */
Ray Kinsella8899ce02020-03-12 15:52:41 +0000156 vnet_buffer (b[1])->l2_classify.pad.l2_len =
157 vnet_buffer (b[1])->ip.save_rewrite_length;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100158 /* advance the match pointer so the matching happens on IP header */
Ray Kinsella8899ce02020-03-12 15:52:41 +0000159 h[3] += vnet_buffer (b[1])->l2_classify.pad.l2_len;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100160 }
161
Ray Kinsella8899ce02020-03-12 15:52:41 +0000162 hash[2] = vnet_classify_hash_packet_inline (t[2], (u8 *) h[2]);
163 hash[3] = vnet_classify_hash_packet_inline (t[3], (u8 *) h[3]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164
Ray Kinsella8899ce02020-03-12 15:52:41 +0000165 vnet_buffer (b[0])->l2_classify.hash = hash[2];
166 vnet_buffer (b[1])->l2_classify.hash = hash[3];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700167
Ray Kinsella8899ce02020-03-12 15:52:41 +0000168 vnet_buffer (b[0])->l2_classify.table_index = table_index[2];
169 vnet_buffer (b[1])->l2_classify.table_index = table_index[3];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700170
Ray Kinsella8899ce02020-03-12 15:52:41 +0000171 vnet_buffer (b[0])->l2_classify.opaque_index = ~0;
172 vnet_buffer (b[1])->l2_classify.opaque_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700173
Ray Kinsella8899ce02020-03-12 15:52:41 +0000174 vnet_classify_prefetch_bucket (t[2],
175 vnet_buffer (b[0])->l2_classify.hash);
176 vnet_classify_prefetch_bucket (t[3],
177 vnet_buffer (b[1])->l2_classify.hash);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178 }
179
Ray Kinsella8899ce02020-03-12 15:52:41 +0000180 while (n_left >= 2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700181 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000182 vnet_classify_entry_t *e[2] = { 0, 0 };
183 u32 _next[2] = { ACL_NEXT_INDEX_DENY, ACL_NEXT_INDEX_DENY };
Ray Kinsella8899ce02020-03-12 15:52:41 +0000184
185 h[0] = h[2];
186 h[1] = h[3];
187 t[0] = t[2];
188 t[1] = t[3];
189
190 sw_if_index[0] = sw_if_index[2];
191 sw_if_index[1] = sw_if_index[3];
192
193 table_index[0] = table_index[2];
194 table_index[1] = table_index[3];
195
196 hash[0] = hash[2];
197 hash[1] = hash[3];
198
199 /* prefetch next iteration */
200 if (n_left >= 6)
201 {
202 vlib_prefetch_buffer_header (b[4], LOAD);
203 vlib_prefetch_buffer_header (b[5], LOAD);
204
Damjan Marionaf7fb042021-07-15 11:54:41 +0200205 clib_prefetch_load (b[4]->data);
206 clib_prefetch_load (b[5]->data);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000207 }
208
209 /* calculate hashes for b[2] & b[3] */
210 if (n_left >= 4)
211 {
212 sw_if_index[2] =
Benoît Ganneabb2a422021-09-30 13:41:00 +0200213 ~0 == way ? 0 : vnet_buffer (b[2])->sw_if_index[way];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000214 sw_if_index[3] =
Benoît Ganneabb2a422021-09-30 13:41:00 +0200215 ~0 == way ? 0 : vnet_buffer (b[3])->sw_if_index[way];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000216
Benoît Ganneabb2a422021-09-30 13:41:00 +0200217 table_index[2] = table_index_by_sw_if_index[sw_if_index[2]];
218 table_index[3] = table_index_by_sw_if_index[sw_if_index[3]];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000219
Benoît Ganneabb2a422021-09-30 13:41:00 +0200220 t[2] = pool_elt_at_index (tables, table_index[2]);
221 t[3] = pool_elt_at_index (tables, table_index[3]);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000222
223 if (t[2]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
224 h[2] =
225 (void *) vlib_buffer_get_current (b[2]) +
226 t[2]->current_data_offset;
227 else
228 h[2] = b[2]->data;
229
230 if (t[3]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
231 h[3] =
232 (void *) vlib_buffer_get_current (b[3]) +
233 t[3]->current_data_offset;
234 else
235 h[3] = b[3]->data;
236
237 if (is_output)
238 {
239 /* Save the rewrite length, since we are using the l2_classify struct */
240 vnet_buffer (b[2])->l2_classify.pad.l2_len =
241 vnet_buffer (b[2])->ip.save_rewrite_length;
242 /* advance the match pointer so the matching happens on IP header */
243 h[2] += vnet_buffer (b[2])->l2_classify.pad.l2_len;
244
245 /* Save the rewrite length, since we are using the l2_classify struct */
246 vnet_buffer (b[3])->l2_classify.pad.l2_len =
247 vnet_buffer (b[3])->ip.save_rewrite_length;
248 /* advance the match pointer so the matching happens on IP header */
249 h[3] += vnet_buffer (b[3])->l2_classify.pad.l2_len;
250 }
251
252 hash[2] = vnet_classify_hash_packet_inline (t[2], (u8 *) h[2]);
253 hash[3] = vnet_classify_hash_packet_inline (t[3], (u8 *) h[3]);
254
255 vnet_buffer (b[2])->l2_classify.hash = hash[2];
256 vnet_buffer (b[3])->l2_classify.hash = hash[3];
257
258 vnet_buffer (b[2])->l2_classify.table_index = table_index[2];
259 vnet_buffer (b[3])->l2_classify.table_index = table_index[3];
260
261 vnet_buffer (b[2])->l2_classify.opaque_index = ~0;
262 vnet_buffer (b[3])->l2_classify.opaque_index = ~0;
263
264 vnet_classify_prefetch_bucket (t[2],
265 vnet_buffer (b[2])->
266 l2_classify.hash);
267 vnet_classify_prefetch_bucket (t[3],
268 vnet_buffer (b[3])->
269 l2_classify.hash);
270 }
271
272 /* find entry for b[0] & b[1] */
Benoît Ganneabb2a422021-09-30 13:41:00 +0200273 vnet_get_config_data (cm, &b[0]->current_config_index, &_next[0],
Ray Kinsella8899ce02020-03-12 15:52:41 +0000274 /* # bytes of config data */ 0);
Benoît Ganneabb2a422021-09-30 13:41:00 +0200275 vnet_get_config_data (cm, &b[1]->current_config_index, &_next[1],
Ray Kinsella8899ce02020-03-12 15:52:41 +0000276 /* # bytes of config data */ 0);
277
278 if (PREDICT_TRUE (table_index[0] != ~0))
279 {
280 e[0] =
281 vnet_classify_find_entry_inline (t[0], (u8 *) h[0], hash[0], now);
282 if (e[0])
283 {
284 vnet_buffer (b[0])->l2_classify.opaque_index
285 = e[0]->opaque_index;
286 vlib_buffer_advance (b[0], e[0]->advance);
287
288 _next[0] = (e[0]->next_index < n_next_nodes) ?
289 e[0]->next_index : _next[0];
290
291 hits++;
292
Benoît Ganneabb2a422021-09-30 13:41:00 +0200293 b[0]->error =
294 (_next[0] == ACL_NEXT_INDEX_DENY) ? error_deny : error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000295
296 if (!is_output)
297 {
298 if (e[0]->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX ||
299 e[0]->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
300 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = e[0]->metadata;
301 else if (e[0]->action == CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100302 {
303 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] =
304 e[0]->metadata;
305 /* For source check in case we skip the lookup node */
306 ip_lookup_set_buffer_fib_index (fib_index_by_sw_if_index,
307 b[0]);
308 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000309 }
310 }
311 else
312 {
313 while (1)
314 {
315 if (PREDICT_TRUE (t[0]->next_table_index != ~0))
Benoît Ganneabb2a422021-09-30 13:41:00 +0200316 t[0] = pool_elt_at_index (tables, t[0]->next_table_index);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000317 else
318 {
319 _next[0] = (t[0]->miss_next_index < n_next_nodes) ?
320 t[0]->miss_next_index : _next[0];
321
322 misses++;
323
Benoît Ganneabb2a422021-09-30 13:41:00 +0200324 b[0]->error = (_next[0] == ACL_NEXT_INDEX_DENY) ?
325 error_miss :
326 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000327 break;
328 }
329
330 if (t[0]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
331 h[0] =
332 (void *) vlib_buffer_get_current (b[0]) +
333 t[0]->current_data_offset;
334 else
335 h[0] = b[0]->data;
336
337 /* advance the match pointer so the matching happens on IP header */
338 if (is_output)
339 h[0] += vnet_buffer (b[0])->l2_classify.pad.l2_len;
340
341 hash[0] =
342 vnet_classify_hash_packet_inline (t[0], (u8 *) h[0]);
343 e[0] =
344 vnet_classify_find_entry_inline (t[0], (u8 *) h[0],
345 hash[0], now);
346 if (e[0])
347 {
348 vnet_buffer (b[0])->l2_classify.opaque_index
349 = e[0]->opaque_index;
350 vlib_buffer_advance (b[0], e[0]->advance);
351 _next[0] = (e[0]->next_index < n_next_nodes) ?
352 e[0]->next_index : _next[0];
353 hits++;
354 chain_hits++;
355
Benoît Ganneabb2a422021-09-30 13:41:00 +0200356 b[0]->error = (_next[0] == ACL_NEXT_INDEX_DENY) ?
357 error_deny :
358 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000359
360 if (!is_output)
361 {
362 if (e[0]->action ==
363 CLASSIFY_ACTION_SET_IP4_FIB_INDEX
364 || e[0]->action ==
365 CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
366 vnet_buffer (b[0])->sw_if_index[VLIB_TX] =
367 e[0]->metadata;
368 else if (e[0]->action ==
369 CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100370 {
371 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] =
372 e[0]->metadata;
373 /* For source check in case we skip the lookup
374 * node */
375 ip_lookup_set_buffer_fib_index (
376 fib_index_by_sw_if_index, b[0]);
377 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000378 }
379 break;
380 }
381 }
382 }
383 }
384
385 if (PREDICT_TRUE (table_index[1] != ~0))
386 {
387 e[1] =
388 vnet_classify_find_entry_inline (t[1], (u8 *) h[1], hash[1], now);
389 if (e[1])
390 {
391 vnet_buffer (b[1])->l2_classify.opaque_index
392 = e[1]->opaque_index;
393 vlib_buffer_advance (b[1], e[1]->advance);
394
395 _next[1] = (e[1]->next_index < n_next_nodes) ?
396 e[1]->next_index : _next[1];
397
398 hits++;
399
Benoît Ganneabb2a422021-09-30 13:41:00 +0200400 b[1]->error =
401 (_next[1] == ACL_NEXT_INDEX_DENY) ? error_deny : error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000402
403 if (!is_output)
404 {
405 if (e[1]->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX ||
406 e[1]->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
407 vnet_buffer (b[1])->sw_if_index[VLIB_TX] = e[1]->metadata;
408 else if (e[1]->action == CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100409 {
410 vnet_buffer (b[1])->ip.adj_index[VLIB_TX] =
411 e[1]->metadata;
412 /* For source check in case we skip the lookup node */
413 ip_lookup_set_buffer_fib_index (fib_index_by_sw_if_index,
414 b[1]);
415 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000416 }
417 }
418 else
419 {
420 while (1)
421 {
422 if (PREDICT_TRUE (t[1]->next_table_index != ~0))
Benoît Ganneabb2a422021-09-30 13:41:00 +0200423 t[1] = pool_elt_at_index (tables, t[1]->next_table_index);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000424 else
425 {
426 _next[1] = (t[1]->miss_next_index < n_next_nodes) ?
427 t[1]->miss_next_index : _next[1];
428
429 misses++;
430
Benoît Ganneabb2a422021-09-30 13:41:00 +0200431 b[1]->error = (_next[1] == ACL_NEXT_INDEX_DENY) ?
432 error_miss :
433 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000434 break;
435 }
436
437 if (t[1]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
438 h[1] =
439 (void *) vlib_buffer_get_current (b[1]) +
440 t[1]->current_data_offset;
441 else
442 h[1] = b[1]->data;
443
444 /* advance the match pointer so the matching happens on IP header */
445 if (is_output)
446 h[1] += vnet_buffer (b[1])->l2_classify.pad.l2_len;
447
448 hash[1] =
449 vnet_classify_hash_packet_inline (t[1], (u8 *) h[1]);
450 e[1] =
451 vnet_classify_find_entry_inline (t[1], (u8 *) h[1],
452 hash[1], now);
453 if (e[1])
454 {
455 vnet_buffer (b[1])->l2_classify.opaque_index
456 = e[1]->opaque_index;
457 vlib_buffer_advance (b[1], e[1]->advance);
458 _next[1] = (e[1]->next_index < n_next_nodes) ?
459 e[1]->next_index : _next[1];
460 hits++;
461 chain_hits++;
462
Benoît Ganneabb2a422021-09-30 13:41:00 +0200463 b[1]->error = (_next[1] == ACL_NEXT_INDEX_DENY) ?
464 error_deny :
465 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000466
467 if (!is_output)
468 {
469 if (e[1]->action ==
470 CLASSIFY_ACTION_SET_IP4_FIB_INDEX
471 || e[1]->action ==
472 CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
473 vnet_buffer (b[1])->sw_if_index[VLIB_TX] =
474 e[1]->metadata;
475 else if (e[1]->action ==
476 CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100477 {
478 vnet_buffer (b[1])->ip.adj_index[VLIB_TX] =
479 e[1]->metadata;
480 /* For source check in case we skip the lookup
481 * node */
482 ip_lookup_set_buffer_fib_index (
483 fib_index_by_sw_if_index, b[1]);
484 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000485 }
486 break;
487 }
488 }
489 }
490 }
491
492 if (do_trace && b[0]->flags & VLIB_BUFFER_IS_TRACED)
493 {
494 ip_in_out_acl_trace_t *_t =
495 vlib_add_trace (vm, node, b[0], sizeof (*_t));
496 _t->sw_if_index =
Benoît Ganneabb2a422021-09-30 13:41:00 +0200497 ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000498 _t->next_index = _next[0];
Benoît Ganneabb2a422021-09-30 13:41:00 +0200499 _t->table_index = t[0] ? t[0] - tables : ~0;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000500 _t->offset = (e[0]
501 && t[0]) ? vnet_classify_get_offset (t[0], e[0]) : ~0;
502 }
503
504 if (do_trace && b[1]->flags & VLIB_BUFFER_IS_TRACED)
505 {
506 ip_in_out_acl_trace_t *_t =
507 vlib_add_trace (vm, node, b[1], sizeof (*_t));
508 _t->sw_if_index =
Benoît Ganneabb2a422021-09-30 13:41:00 +0200509 ~0 == way ? 0 : vnet_buffer (b[1])->sw_if_index[way];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000510 _t->next_index = _next[1];
Benoît Ganneabb2a422021-09-30 13:41:00 +0200511 _t->table_index = t[1] ? t[1] - tables : ~0;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000512 _t->offset = (e[1]
513 && t[1]) ? vnet_classify_get_offset (t[1], e[1]) : ~0;
514 }
515
516 if ((_next[0] == ACL_NEXT_INDEX_DENY) && is_output)
517 {
518 /* on output, for the drop node to work properly, go back to ip header */
519 vlib_buffer_advance (b[0], vnet_buffer (b[0])->l2.l2_len);
520 }
521
522 if ((_next[1] == ACL_NEXT_INDEX_DENY) && is_output)
523 {
524 /* on output, for the drop node to work properly, go back to ip header */
525 vlib_buffer_advance (b[1], vnet_buffer (b[1])->l2.l2_len);
526 }
527
528 next[0] = _next[0];
529 next[1] = _next[1];
530
531 /* _next */
532 next += 2;
533 b += 2;
534 n_left -= 2;
535 }
536
537 while (n_left > 0)
538 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500539 u8 *h0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700540 u32 sw_if_index0;
541 u32 table_index0;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000542 vnet_classify_table_t *t0 = 0;
543 vnet_classify_entry_t *e0 = 0;
544 u32 next0 = ACL_NEXT_INDEX_DENY;
545 u64 hash0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700546
Benoît Ganneabb2a422021-09-30 13:41:00 +0200547 sw_if_index0 = ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way];
548 table_index0 = table_index_by_sw_if_index[sw_if_index0];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700549
Benoît Ganneabb2a422021-09-30 13:41:00 +0200550 t0 = pool_elt_at_index (tables, table_index0);
Steve Shin25e26dc2016-11-08 10:47:10 -0800551
552 if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
Ray Kinsella8899ce02020-03-12 15:52:41 +0000553 h0 =
554 (void *) vlib_buffer_get_current (b[0]) + t0->current_data_offset;
Steve Shin25e26dc2016-11-08 10:47:10 -0800555 else
Ray Kinsella8899ce02020-03-12 15:52:41 +0000556 h0 = b[0]->data;
Steve Shin25e26dc2016-11-08 10:47:10 -0800557
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100558 if (is_output)
559 {
560 /* Save the rewrite length, since we are using the l2_classify struct */
Ray Kinsella8899ce02020-03-12 15:52:41 +0000561 vnet_buffer (b[0])->l2_classify.pad.l2_len =
562 vnet_buffer (b[0])->ip.save_rewrite_length;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100563 /* advance the match pointer so the matching happens on IP header */
Ray Kinsella8899ce02020-03-12 15:52:41 +0000564 h0 += vnet_buffer (b[0])->l2_classify.pad.l2_len;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100565 }
566
Ray Kinsella8899ce02020-03-12 15:52:41 +0000567 vnet_buffer (b[0])->l2_classify.hash =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500568 vnet_classify_hash_packet (t0, (u8 *) h0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700569
Ray Kinsella8899ce02020-03-12 15:52:41 +0000570 vnet_buffer (b[0])->l2_classify.table_index = table_index0;
571 vnet_buffer (b[0])->l2_classify.opaque_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700572
Benoît Ganneabb2a422021-09-30 13:41:00 +0200573 vnet_get_config_data (cm, &b[0]->current_config_index, &next0,
Ray Kinsella8899ce02020-03-12 15:52:41 +0000574 /* # bytes of config data */ 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700575
Ray Kinsella8899ce02020-03-12 15:52:41 +0000576 if (PREDICT_TRUE (table_index0 != ~0))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500577 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000578 hash0 = vnet_buffer (b[0])->l2_classify.hash;
Benoît Ganneabb2a422021-09-30 13:41:00 +0200579 t0 = pool_elt_at_index (tables, table_index0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700580
Ray Kinsella8899ce02020-03-12 15:52:41 +0000581 if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
582 h0 =
583 (void *) vlib_buffer_get_current (b[0]) +
584 t0->current_data_offset;
585 else
586 h0 = b[0]->data;
587
588 /* advance the match pointer so the matching happens on IP header */
589 if (is_output)
590 h0 += vnet_buffer (b[0])->l2_classify.pad.l2_len;
591
592 e0 = vnet_classify_find_entry_inline (t0, (u8 *) h0, hash0, now);
593 if (e0)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500594 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000595 vnet_buffer (b[0])->l2_classify.opaque_index = e0->opaque_index;
596 vlib_buffer_advance (b[0], e0->advance);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700597
Ray Kinsella8899ce02020-03-12 15:52:41 +0000598 next0 = (e0->next_index < n_next_nodes) ?
599 e0->next_index : next0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700600
Ray Kinsella8899ce02020-03-12 15:52:41 +0000601 hits++;
602
Benoît Ganneabb2a422021-09-30 13:41:00 +0200603 b[0]->error =
604 (next0 == ACL_NEXT_INDEX_DENY) ? error_deny : error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000605
606 if (!is_output)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500607 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000608 if (e0->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX ||
609 e0->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
610 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = e0->metadata;
611 else if (e0->action == CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100612 {
613 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = e0->metadata;
614 /* For source check in case we skip the lookup node */
615 ip_lookup_set_buffer_fib_index (fib_index_by_sw_if_index,
616 b[0]);
617 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500618 }
619 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000620 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500621 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000622 while (1)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500623 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000624 if (PREDICT_TRUE (t0->next_table_index != ~0))
Benoît Ganneabb2a422021-09-30 13:41:00 +0200625 t0 = pool_elt_at_index (tables, t0->next_table_index);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500626 else
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100627 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000628 next0 = (t0->miss_next_index < n_next_nodes) ?
629 t0->miss_next_index : next0;
630
631 misses++;
632
Benoît Ganneabb2a422021-09-30 13:41:00 +0200633 b[0]->error = (next0 == ACL_NEXT_INDEX_DENY) ?
634 error_miss :
635 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000636 break;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100637 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000638
639 if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
640 h0 =
641 (void *) vlib_buffer_get_current (b[0]) +
642 t0->current_data_offset;
643 else
644 h0 = b[0]->data;
645
646 /* advance the match pointer so the matching happens on IP header */
647 if (is_output)
648 h0 += vnet_buffer (b[0])->l2_classify.pad.l2_len;
649
650 hash0 = vnet_classify_hash_packet_inline (t0, (u8 *) h0);
651 e0 = vnet_classify_find_entry_inline
652 (t0, (u8 *) h0, hash0, now);
653 if (e0)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500654 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000655 vnet_buffer (b[0])->l2_classify.opaque_index
656 = e0->opaque_index;
657 vlib_buffer_advance (b[0], e0->advance);
658 next0 = (e0->next_index < n_next_nodes) ?
659 e0->next_index : next0;
660 hits++;
661
Benoît Ganneabb2a422021-09-30 13:41:00 +0200662 b[0]->error = (next0 == ACL_NEXT_INDEX_DENY) ?
663 error_deny :
664 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000665
666 if (!is_output)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500667 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000668 if (e0->action ==
669 CLASSIFY_ACTION_SET_IP4_FIB_INDEX
670 || e0->action ==
671 CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
672 vnet_buffer (b[0])->sw_if_index[VLIB_TX] =
673 e0->metadata;
674 else if (e0->action == CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100675 {
676 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] =
677 e0->metadata;
678 /* For source check in case we skip the lookup
679 * node */
680 ip_lookup_set_buffer_fib_index (
681 fib_index_by_sw_if_index, b[0]);
682 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500683 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000684 break;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500685 }
686 }
687 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500688 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700689
Ray Kinsella8899ce02020-03-12 15:52:41 +0000690 if (do_trace && b[0]->flags & VLIB_BUFFER_IS_TRACED)
691 {
692 ip_in_out_acl_trace_t *t =
693 vlib_add_trace (vm, node, b[0], sizeof (*t));
694 t->sw_if_index =
Benoît Ganneabb2a422021-09-30 13:41:00 +0200695 ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000696 t->next_index = next0;
Klement Sekera849b4742021-10-25 13:39:13 +0200697 t->table_index = t0 - tables;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000698 t->offset = (e0 && t0) ? vnet_classify_get_offset (t0, e0) : ~0;
699 }
700
701 if ((next0 == ACL_NEXT_INDEX_DENY) && is_output)
702 {
703 /* on output, for the drop node to work properly, go back to ip header */
704 vlib_buffer_advance (b[0], vnet_buffer (b[0])->l2.l2_len);
705 }
706
707 next[0] = next0;
708
709 /* next */
710 next++;
711 b++;
712 n_left--;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700713 }
714
Benoît Ganneabb2a422021-09-30 13:41:00 +0200715 *hits__ = hits;
716 *misses__ = misses;
717 *chain_hits__ = chain_hits;
718}
719
720static_always_inline uword
721ip_in_out_acl_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
722 vlib_frame_t *frame, const in_out_acl_table_id_t tid,
Arthur de Kerhor10310982021-12-22 10:58:30 +0100723 u32 *fib_index_by_sw_if_index,
Benoît Ganneabb2a422021-09-30 13:41:00 +0200724 const vlib_node_registration_t *parent_error_node,
725 const u32 error_none_index, const u32 error_deny_index,
726 const u32 error_miss_index, const vlib_rx_or_tx_t way,
727 const int is_output)
728{
729 const in_out_acl_main_t *am = &in_out_acl_main;
730 vnet_classify_table_t *tables = am->vnet_classify_main->tables;
731 u32 *from = vlib_frame_vector_args (frame);
732 const u32 *table_index_by_sw_if_index =
733 am->classify_table_index_by_sw_if_index[is_output][tid];
734 vnet_config_main_t *cm = am->vnet_config_main[is_output][tid];
735 const vlib_node_runtime_t *error_node =
736 vlib_node_get_runtime (vm, parent_error_node->index);
737 const vlib_error_t error_none = error_node->errors[error_none_index];
738 const vlib_error_t error_deny = error_node->errors[error_deny_index];
739 const vlib_error_t error_miss = error_node->errors[error_miss_index];
740 vlib_buffer_t *bufs[VLIB_FRAME_SIZE];
741 u16 nexts[VLIB_FRAME_SIZE];
742 u32 hits, misses, chain_hits;
743
744 vlib_get_buffers (vm, from, bufs, frame->n_vectors);
745
746#define ip_in_out_acl_inline_trace__(do_trace) \
747 ip_in_out_acl_inline_trace ( \
748 vm, node, frame, bufs, nexts, frame->n_vectors, &hits, &misses, \
749 &chain_hits, error_deny, error_miss, error_none, tables, \
Arthur de Kerhor10310982021-12-22 10:58:30 +0100750 table_index_by_sw_if_index, fib_index_by_sw_if_index, cm, way, is_output, \
751 do_trace)
Benoît Ganneabb2a422021-09-30 13:41:00 +0200752
753 if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
754 ip_in_out_acl_inline_trace__ (1 /* do_trace */);
755 else
756 ip_in_out_acl_inline_trace__ (0 /* do_trace */);
757
758 vlib_node_increment_counter (
759 vm, node->node_index,
760 is_output ? IP_OUTACL_ERROR_MISS : IP_INACL_ERROR_MISS, misses);
761 vlib_node_increment_counter (
762 vm, node->node_index, is_output ? IP_OUTACL_ERROR_HIT : IP_INACL_ERROR_HIT,
763 hits);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700764 vlib_node_increment_counter (vm, node->node_index,
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100765 is_output ? IP_OUTACL_ERROR_CHAIN_HIT :
Benoît Ganneabb2a422021-09-30 13:41:00 +0200766 IP_INACL_ERROR_CHAIN_HIT,
767 chain_hits);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000768
769 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000770 return frame->n_vectors;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100771}
772
Benoît Ganneabb2a422021-09-30 13:41:00 +0200773VLIB_NODE_FN (ip4_inacl_node)
774(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100775{
Benoît Ganneabb2a422021-09-30 13:41:00 +0200776 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100777 vm, node, frame, IN_OUT_ACL_TABLE_IP4, ip4_main.fib_index_by_sw_if_index,
778 &ip4_input_node, IP4_ERROR_NONE, IP4_ERROR_INACL_SESSION_DENY,
779 IP4_ERROR_INACL_TABLE_MISS, VLIB_RX, 0 /* is_output */);
Benoît Ganneabb2a422021-09-30 13:41:00 +0200780}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700781
Benoît Ganneabb2a422021-09-30 13:41:00 +0200782VLIB_NODE_FN (ip4_punt_acl_node)
783(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
784{
785 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100786 vm, node, frame, IN_OUT_ACL_TABLE_IP4_PUNT,
787 ip4_main.fib_index_by_sw_if_index, &ip4_input_node, IP4_ERROR_NONE,
788 IP4_ERROR_INACL_SESSION_DENY, IP4_ERROR_INACL_TABLE_MISS, ~0 /* way */,
789 0 /* is_output */);
Benoît Ganneabb2a422021-09-30 13:41:00 +0200790}
Ray Kinsella8899ce02020-03-12 15:52:41 +0000791
Benoît Ganneabb2a422021-09-30 13:41:00 +0200792VLIB_NODE_FN (ip4_outacl_node)
793(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
794{
795 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100796 vm, node, frame, IN_OUT_ACL_TABLE_IP4, NULL, &ip4_input_node,
797 IP4_ERROR_NONE, IP4_ERROR_INACL_SESSION_DENY, IP4_ERROR_INACL_TABLE_MISS,
798 VLIB_TX, 1 /* is_output */);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000799}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700800
Dave Barachd7cb1b52016-12-09 09:52:16 -0500801/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700802VLIB_REGISTER_NODE (ip4_inacl_node) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700803 .name = "ip4-inacl",
804 .vector_size = sizeof (u32),
805 .format_trace = format_ip_inacl_trace,
806 .n_errors = ARRAY_LEN(ip_inacl_error_strings),
807 .error_strings = ip_inacl_error_strings,
808
809 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
810 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800811 [ACL_NEXT_INDEX_DENY] = "ip4-drop",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700812 },
813};
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100814
Benoît Ganneabb2a422021-09-30 13:41:00 +0200815VLIB_REGISTER_NODE (ip4_punt_acl_node) = {
816 .name = "ip4-punt-acl",
817 .vector_size = sizeof (u32),
818 .format_trace = format_ip_inacl_trace,
819 .n_errors = ARRAY_LEN(ip_inacl_error_strings),
820 .error_strings = ip_inacl_error_strings,
821
822 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
823 .next_nodes = {
824 [ACL_NEXT_INDEX_DENY] = "ip4-drop",
825 },
826};
827
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100828VLIB_REGISTER_NODE (ip4_outacl_node) = {
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100829 .name = "ip4-outacl",
830 .vector_size = sizeof (u32),
831 .format_trace = format_ip_outacl_trace,
832 .n_errors = ARRAY_LEN(ip_outacl_error_strings),
833 .error_strings = ip_outacl_error_strings,
834
835 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
836 .next_nodes = {
837 [ACL_NEXT_INDEX_DENY] = "ip4-drop",
838 },
839};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500840/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700841
Benoît Ganneabb2a422021-09-30 13:41:00 +0200842VNET_FEATURE_INIT (ip4_punt_acl_feature) = {
843 .arc_name = "ip4-punt",
844 .node_name = "ip4-punt-acl",
845 .runs_after = VNET_FEATURES ("ip4-punt-policer"),
846};
847
Filip Tehlar26ea14e2019-03-11 05:30:21 -0700848VLIB_NODE_FN (ip6_inacl_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
849 vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700850{
Benoît Ganneabb2a422021-09-30 13:41:00 +0200851 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100852 vm, node, frame, IN_OUT_ACL_TABLE_IP6, ip6_main.fib_index_by_sw_if_index,
853 &ip6_input_node, IP6_ERROR_NONE, IP6_ERROR_INACL_SESSION_DENY,
854 IP6_ERROR_INACL_TABLE_MISS, VLIB_RX, 0 /* is_output */);
Benoît Ganneabb2a422021-09-30 13:41:00 +0200855}
Ray Kinsella8899ce02020-03-12 15:52:41 +0000856
Benoît Ganneabb2a422021-09-30 13:41:00 +0200857VLIB_NODE_FN (ip6_punt_acl_node)
858(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
859{
860 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100861 vm, node, frame, IN_OUT_ACL_TABLE_IP6_PUNT,
862 ip4_main.fib_index_by_sw_if_index, &ip6_input_node, IP6_ERROR_NONE,
863 IP6_ERROR_INACL_SESSION_DENY, IP6_ERROR_INACL_TABLE_MISS, ~0 /* way */,
864 0 /* is_output */);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700865}
866
Filip Tehlar26ea14e2019-03-11 05:30:21 -0700867VLIB_NODE_FN (ip6_outacl_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
868 vlib_frame_t * frame)
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100869{
Benoît Ganneabb2a422021-09-30 13:41:00 +0200870 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100871 vm, node, frame, IN_OUT_ACL_TABLE_IP6, NULL, &ip6_input_node,
872 IP6_ERROR_NONE, IP6_ERROR_INACL_SESSION_DENY, IP6_ERROR_INACL_TABLE_MISS,
873 VLIB_TX, 1 /* is_output */);
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100874}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700875
Dave Barachd7cb1b52016-12-09 09:52:16 -0500876/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700877VLIB_REGISTER_NODE (ip6_inacl_node) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700878 .name = "ip6-inacl",
879 .vector_size = sizeof (u32),
880 .format_trace = format_ip_inacl_trace,
881 .n_errors = ARRAY_LEN(ip_inacl_error_strings),
882 .error_strings = ip_inacl_error_strings,
883
884 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
885 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800886 [ACL_NEXT_INDEX_DENY] = "ip6-drop",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700887 },
888};
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100889
Benoît Ganneabb2a422021-09-30 13:41:00 +0200890VLIB_REGISTER_NODE (ip6_punt_acl_node) = {
891 .name = "ip6-punt-acl",
892 .vector_size = sizeof (u32),
893 .format_trace = format_ip_inacl_trace,
894 .n_errors = ARRAY_LEN(ip_inacl_error_strings),
895 .error_strings = ip_inacl_error_strings,
896
897 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
898 .next_nodes = {
899 [ACL_NEXT_INDEX_DENY] = "ip6-drop",
900 },
901};
902
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100903VLIB_REGISTER_NODE (ip6_outacl_node) = {
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100904 .name = "ip6-outacl",
905 .vector_size = sizeof (u32),
906 .format_trace = format_ip_outacl_trace,
907 .n_errors = ARRAY_LEN(ip_outacl_error_strings),
908 .error_strings = ip_outacl_error_strings,
909
910 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
911 .next_nodes = {
912 [ACL_NEXT_INDEX_DENY] = "ip6-drop",
913 },
914};
Dave Barachd7cb1b52016-12-09 09:52:16 -0500915/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700916
Benoît Ganneabb2a422021-09-30 13:41:00 +0200917VNET_FEATURE_INIT (ip6_punt_acl_feature) = {
918 .arc_name = "ip6-punt",
919 .node_name = "ip6-punt-acl",
920 .runs_after = VNET_FEATURES ("ip6-punt-policer"),
921};
922
Filip Tehlar26ea14e2019-03-11 05:30:21 -0700923#ifndef CLIB_MARCH_VARIANT
Ed Warnickecb9cada2015-12-08 15:45:58 -0700924static clib_error_t *
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100925ip_in_out_acl_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700926{
927 return 0;
928}
929
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100930VLIB_INIT_FUNCTION (ip_in_out_acl_init);
Filip Tehlar26ea14e2019-03-11 05:30:21 -0700931#endif /* CLIB_MARCH_VARIANT */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700932
Dave Barachd7cb1b52016-12-09 09:52:16 -0500933
934/*
935 * fd.io coding-style-patch-verification: ON
936 *
937 * Local Variables:
938 * eval: (c-set-style "gnu")
939 * End:
940 */