blob: eb3c94a188adf7122116e7c9f18c3186e725a586 [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 *);
Benoît Gannec629f902022-06-08 10:56:33 +020035 const vnet_classify_main_t *vcm = &vnet_classify_main;
36 const u32 indent = format_get_indent (s);
37 vnet_classify_table_t *table;
38 vnet_classify_entry_t *e;
Ed Warnickecb9cada2015-12-08 15:45:58 -070039
Benoît Gannec629f902022-06-08 10:56:33 +020040 s =
41 format (s, "%s: sw_if_index %d, next_index %d, table_index %d, offset %d",
42 is_output ? "OUTACL" : "INACL", t->sw_if_index, t->next_index,
43 t->table_index, t->offset);
44
45 if (pool_is_free_index (vcm->tables, t->table_index))
46 return format (s, "\n%Uno table", format_white_space, indent + 4);
47
48 if (~0 == t->offset)
49 return format (s, "\n%Uno match", format_white_space, indent + 4);
50
51 table = vnet_classify_table_get (t->table_index);
52 e = vnet_classify_get_entry (table, t->offset);
53 return format (s, "\n%U%U", format_white_space, indent + 4,
54 format_classify_entry, table, e);
Ed Warnickecb9cada2015-12-08 15:45:58 -070055}
56
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010057static u8 *
58format_ip_inacl_trace (u8 * s, va_list * args)
59{
60 return format_ip_in_out_acl_trace (s, 0 /* is_output */ , args);
61}
62
63static u8 *
64format_ip_outacl_trace (u8 * s, va_list * args)
65{
66 return format_ip_in_out_acl_trace (s, 1 /* is_output */ , args);
67}
68
Filip Tehlar26ea14e2019-03-11 05:30:21 -070069extern vlib_node_registration_t ip4_inacl_node;
70extern vlib_node_registration_t ip4_outacl_node;
71extern vlib_node_registration_t ip6_inacl_node;
72extern vlib_node_registration_t ip6_outacl_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -070073
74#define foreach_ip_inacl_error \
75_(MISS, "input ACL misses") \
76_(HIT, "input ACL hits") \
77_(CHAIN_HIT, "input ACL hits after chain walk")
78
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010079#define foreach_ip_outacl_error \
80_(MISS, "output ACL misses") \
81_(HIT, "output ACL hits") \
82_(CHAIN_HIT, "output ACL hits after chain walk")
83
Dave Barachd7cb1b52016-12-09 09:52:16 -050084typedef enum
85{
Ed Warnickecb9cada2015-12-08 15:45:58 -070086#define _(sym,str) IP_INACL_ERROR_##sym,
87 foreach_ip_inacl_error
88#undef _
Dave Barachd7cb1b52016-12-09 09:52:16 -050089 IP_INACL_N_ERROR,
Ray Kinsella8899ce02020-03-12 15:52:41 +000090}
91ip_inacl_error_t;
Ed Warnickecb9cada2015-12-08 15:45:58 -070092
Dave Barachd7cb1b52016-12-09 09:52:16 -050093static char *ip_inacl_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -070094#define _(sym,string) string,
95 foreach_ip_inacl_error
96#undef _
97};
98
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010099typedef enum
100{
101#define _(sym,str) IP_OUTACL_ERROR_##sym,
102 foreach_ip_outacl_error
103#undef _
104 IP_OUTACL_N_ERROR,
Ray Kinsella8899ce02020-03-12 15:52:41 +0000105}
106ip_outacl_error_t;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100107
108static char *ip_outacl_error_strings[] = {
109#define _(sym,string) string,
110 foreach_ip_outacl_error
111#undef _
112};
113
Ray Kinsella8899ce02020-03-12 15:52:41 +0000114static_always_inline void
Arthur de Kerhor10310982021-12-22 10:58:30 +0100115ip_in_out_acl_inline_trace (
116 vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame,
117 vlib_buffer_t **b, u16 *next, u32 n_left, u32 *hits__, u32 *misses__,
118 u32 *chain_hits__, const vlib_error_t error_none,
119 const vlib_error_t error_deny, const vlib_error_t error_miss,
120 vnet_classify_table_t *tables, const u32 *table_index_by_sw_if_index,
121 u32 *fib_index_by_sw_if_index, vnet_config_main_t *cm,
122 const vlib_rx_or_tx_t way, const int is_output, const int do_trace)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700123{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124 f64 now = vlib_time_now (vm);
125 u32 hits = 0;
126 u32 misses = 0;
127 u32 chain_hits = 0;
Benoît Ganneabb2a422021-09-30 13:41:00 +0200128 u32 n_next_nodes = node->n_next_nodes;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000129 u8 *h[4];
130 u32 sw_if_index[4];
131 u32 table_index[4];
132 vnet_classify_table_t *t[4] = { 0, 0 };
Benoît Ganneb03eec92022-06-08 10:49:17 +0200133 u32 hash[4];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000134
Ray Kinsella8899ce02020-03-12 15:52:41 +0000135 /* calculate hashes for b[0] & b[1] */
136 if (n_left >= 2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700137 {
Benoît Ganneabb2a422021-09-30 13:41:00 +0200138 /* ~0 is used as a wildcard to say 'always use sw_if_index 0'
139 * aka local0. It is used when we do not care about the sw_if_index, as
140 * when punting */
141 sw_if_index[2] = ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way];
142 sw_if_index[3] = ~0 == way ? 0 : vnet_buffer (b[1])->sw_if_index[way];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700143
Benoît Ganneabb2a422021-09-30 13:41:00 +0200144 table_index[2] = table_index_by_sw_if_index[sw_if_index[2]];
145 table_index[3] = table_index_by_sw_if_index[sw_if_index[3]];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146
Benoît Ganneabb2a422021-09-30 13:41:00 +0200147 t[2] = pool_elt_at_index (tables, table_index[2]);
148 t[3] = pool_elt_at_index (tables, table_index[3]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700149
Ray Kinsella8899ce02020-03-12 15:52:41 +0000150 if (t[2]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
151 h[2] =
152 (void *) vlib_buffer_get_current (b[0]) + t[2]->current_data_offset;
Steve Shin25e26dc2016-11-08 10:47:10 -0800153 else
Ray Kinsella8899ce02020-03-12 15:52:41 +0000154 h[2] = b[0]->data;
155
156 if (t[3]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
157 h[3] =
158 (void *) vlib_buffer_get_current (b[1]) + t[3]->current_data_offset;
159 else
160 h[3] = b[1]->data;
Steve Shin25e26dc2016-11-08 10:47:10 -0800161
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100162 if (is_output)
163 {
164 /* Save the rewrite length, since we are using the l2_classify struct */
Benoît Ganneb03eec92022-06-08 10:49:17 +0200165 vnet_buffer (b[0])->l2.l2_len =
Ray Kinsella8899ce02020-03-12 15:52:41 +0000166 vnet_buffer (b[0])->ip.save_rewrite_length;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100167 /* advance the match pointer so the matching happens on IP header */
Benoît Ganneb03eec92022-06-08 10:49:17 +0200168 h[2] += vnet_buffer (b[0])->l2.l2_len;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100169
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100170 /* Save the rewrite length, since we are using the l2_classify struct */
Benoît Ganneb03eec92022-06-08 10:49:17 +0200171 vnet_buffer (b[1])->l2.l2_len =
Ray Kinsella8899ce02020-03-12 15:52:41 +0000172 vnet_buffer (b[1])->ip.save_rewrite_length;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100173 /* advance the match pointer so the matching happens on IP header */
Benoît Ganneb03eec92022-06-08 10:49:17 +0200174 h[3] += vnet_buffer (b[1])->l2.l2_len;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100175 }
176
Ray Kinsella8899ce02020-03-12 15:52:41 +0000177 hash[2] = vnet_classify_hash_packet_inline (t[2], (u8 *) h[2]);
178 hash[3] = vnet_classify_hash_packet_inline (t[3], (u8 *) h[3]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700179
Ray Kinsella8899ce02020-03-12 15:52:41 +0000180 vnet_buffer (b[0])->l2_classify.hash = hash[2];
181 vnet_buffer (b[1])->l2_classify.hash = hash[3];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700182
Ray Kinsella8899ce02020-03-12 15:52:41 +0000183 vnet_buffer (b[0])->l2_classify.table_index = table_index[2];
184 vnet_buffer (b[1])->l2_classify.table_index = table_index[3];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185
Ray Kinsella8899ce02020-03-12 15:52:41 +0000186 vnet_buffer (b[0])->l2_classify.opaque_index = ~0;
187 vnet_buffer (b[1])->l2_classify.opaque_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700188
Ray Kinsella8899ce02020-03-12 15:52:41 +0000189 vnet_classify_prefetch_bucket (t[2],
190 vnet_buffer (b[0])->l2_classify.hash);
191 vnet_classify_prefetch_bucket (t[3],
192 vnet_buffer (b[1])->l2_classify.hash);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700193 }
194
Ray Kinsella8899ce02020-03-12 15:52:41 +0000195 while (n_left >= 2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700196 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000197 vnet_classify_entry_t *e[2] = { 0, 0 };
198 u32 _next[2] = { ACL_NEXT_INDEX_DENY, ACL_NEXT_INDEX_DENY };
Ray Kinsella8899ce02020-03-12 15:52:41 +0000199
200 h[0] = h[2];
201 h[1] = h[3];
202 t[0] = t[2];
203 t[1] = t[3];
204
205 sw_if_index[0] = sw_if_index[2];
206 sw_if_index[1] = sw_if_index[3];
207
208 table_index[0] = table_index[2];
209 table_index[1] = table_index[3];
210
211 hash[0] = hash[2];
212 hash[1] = hash[3];
213
214 /* prefetch next iteration */
215 if (n_left >= 6)
216 {
217 vlib_prefetch_buffer_header (b[4], LOAD);
218 vlib_prefetch_buffer_header (b[5], LOAD);
219
Damjan Marionaf7fb042021-07-15 11:54:41 +0200220 clib_prefetch_load (b[4]->data);
221 clib_prefetch_load (b[5]->data);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000222 }
223
224 /* calculate hashes for b[2] & b[3] */
225 if (n_left >= 4)
226 {
227 sw_if_index[2] =
Benoît Ganneabb2a422021-09-30 13:41:00 +0200228 ~0 == way ? 0 : vnet_buffer (b[2])->sw_if_index[way];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000229 sw_if_index[3] =
Benoît Ganneabb2a422021-09-30 13:41:00 +0200230 ~0 == way ? 0 : vnet_buffer (b[3])->sw_if_index[way];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000231
Benoît Ganneabb2a422021-09-30 13:41:00 +0200232 table_index[2] = table_index_by_sw_if_index[sw_if_index[2]];
233 table_index[3] = table_index_by_sw_if_index[sw_if_index[3]];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000234
Benoît Ganneabb2a422021-09-30 13:41:00 +0200235 t[2] = pool_elt_at_index (tables, table_index[2]);
236 t[3] = pool_elt_at_index (tables, table_index[3]);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000237
238 if (t[2]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
239 h[2] =
240 (void *) vlib_buffer_get_current (b[2]) +
241 t[2]->current_data_offset;
242 else
243 h[2] = b[2]->data;
244
245 if (t[3]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
246 h[3] =
247 (void *) vlib_buffer_get_current (b[3]) +
248 t[3]->current_data_offset;
249 else
250 h[3] = b[3]->data;
251
252 if (is_output)
253 {
254 /* Save the rewrite length, since we are using the l2_classify struct */
Benoît Ganneb03eec92022-06-08 10:49:17 +0200255 vnet_buffer (b[2])->l2.l2_len =
Ray Kinsella8899ce02020-03-12 15:52:41 +0000256 vnet_buffer (b[2])->ip.save_rewrite_length;
257 /* advance the match pointer so the matching happens on IP header */
Benoît Ganneb03eec92022-06-08 10:49:17 +0200258 h[2] += vnet_buffer (b[2])->l2.l2_len;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000259
260 /* Save the rewrite length, since we are using the l2_classify struct */
Benoît Ganneb03eec92022-06-08 10:49:17 +0200261 vnet_buffer (b[3])->l2.l2_len =
Ray Kinsella8899ce02020-03-12 15:52:41 +0000262 vnet_buffer (b[3])->ip.save_rewrite_length;
263 /* advance the match pointer so the matching happens on IP header */
Benoît Ganneb03eec92022-06-08 10:49:17 +0200264 h[3] += vnet_buffer (b[3])->l2.l2_len;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000265 }
266
267 hash[2] = vnet_classify_hash_packet_inline (t[2], (u8 *) h[2]);
268 hash[3] = vnet_classify_hash_packet_inline (t[3], (u8 *) h[3]);
269
270 vnet_buffer (b[2])->l2_classify.hash = hash[2];
271 vnet_buffer (b[3])->l2_classify.hash = hash[3];
272
273 vnet_buffer (b[2])->l2_classify.table_index = table_index[2];
274 vnet_buffer (b[3])->l2_classify.table_index = table_index[3];
275
276 vnet_buffer (b[2])->l2_classify.opaque_index = ~0;
277 vnet_buffer (b[3])->l2_classify.opaque_index = ~0;
278
279 vnet_classify_prefetch_bucket (t[2],
280 vnet_buffer (b[2])->
281 l2_classify.hash);
282 vnet_classify_prefetch_bucket (t[3],
283 vnet_buffer (b[3])->
284 l2_classify.hash);
285 }
286
287 /* find entry for b[0] & b[1] */
Benoît Ganneabb2a422021-09-30 13:41:00 +0200288 vnet_get_config_data (cm, &b[0]->current_config_index, &_next[0],
Ray Kinsella8899ce02020-03-12 15:52:41 +0000289 /* # bytes of config data */ 0);
Benoît Ganneabb2a422021-09-30 13:41:00 +0200290 vnet_get_config_data (cm, &b[1]->current_config_index, &_next[1],
Ray Kinsella8899ce02020-03-12 15:52:41 +0000291 /* # bytes of config data */ 0);
292
293 if (PREDICT_TRUE (table_index[0] != ~0))
294 {
295 e[0] =
296 vnet_classify_find_entry_inline (t[0], (u8 *) h[0], hash[0], now);
297 if (e[0])
298 {
299 vnet_buffer (b[0])->l2_classify.opaque_index
300 = e[0]->opaque_index;
301 vlib_buffer_advance (b[0], e[0]->advance);
302
303 _next[0] = (e[0]->next_index < n_next_nodes) ?
304 e[0]->next_index : _next[0];
305
306 hits++;
307
Benoît Ganneabb2a422021-09-30 13:41:00 +0200308 b[0]->error =
309 (_next[0] == ACL_NEXT_INDEX_DENY) ? error_deny : error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000310
311 if (!is_output)
312 {
313 if (e[0]->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX ||
314 e[0]->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
315 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = e[0]->metadata;
316 else if (e[0]->action == CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100317 {
318 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] =
319 e[0]->metadata;
320 /* For source check in case we skip the lookup node */
321 ip_lookup_set_buffer_fib_index (fib_index_by_sw_if_index,
322 b[0]);
323 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000324 }
325 }
326 else
327 {
328 while (1)
329 {
Benoît Ganne051d3a32022-11-18 17:05:10 +0100330 table_index[0] = t[0]->next_table_index;
331 if (PREDICT_TRUE (table_index[0] != ~0))
332 t[0] = pool_elt_at_index (tables, table_index[0]);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000333 else
334 {
335 _next[0] = (t[0]->miss_next_index < n_next_nodes) ?
336 t[0]->miss_next_index : _next[0];
337
338 misses++;
339
Benoît Ganneabb2a422021-09-30 13:41:00 +0200340 b[0]->error = (_next[0] == ACL_NEXT_INDEX_DENY) ?
341 error_miss :
342 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000343 break;
344 }
345
346 if (t[0]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
347 h[0] =
348 (void *) vlib_buffer_get_current (b[0]) +
349 t[0]->current_data_offset;
350 else
351 h[0] = b[0]->data;
352
353 /* advance the match pointer so the matching happens on IP header */
354 if (is_output)
Benoît Ganneb03eec92022-06-08 10:49:17 +0200355 h[0] += vnet_buffer (b[0])->l2.l2_len;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000356
357 hash[0] =
358 vnet_classify_hash_packet_inline (t[0], (u8 *) h[0]);
359 e[0] =
360 vnet_classify_find_entry_inline (t[0], (u8 *) h[0],
361 hash[0], now);
362 if (e[0])
363 {
364 vnet_buffer (b[0])->l2_classify.opaque_index
365 = e[0]->opaque_index;
366 vlib_buffer_advance (b[0], e[0]->advance);
367 _next[0] = (e[0]->next_index < n_next_nodes) ?
368 e[0]->next_index : _next[0];
369 hits++;
370 chain_hits++;
371
Benoît Ganneabb2a422021-09-30 13:41:00 +0200372 b[0]->error = (_next[0] == ACL_NEXT_INDEX_DENY) ?
373 error_deny :
374 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000375
376 if (!is_output)
377 {
378 if (e[0]->action ==
379 CLASSIFY_ACTION_SET_IP4_FIB_INDEX
380 || e[0]->action ==
381 CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
382 vnet_buffer (b[0])->sw_if_index[VLIB_TX] =
383 e[0]->metadata;
384 else if (e[0]->action ==
385 CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100386 {
387 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] =
388 e[0]->metadata;
389 /* For source check in case we skip the lookup
390 * node */
391 ip_lookup_set_buffer_fib_index (
392 fib_index_by_sw_if_index, b[0]);
393 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000394 }
395 break;
396 }
397 }
398 }
399 }
400
401 if (PREDICT_TRUE (table_index[1] != ~0))
402 {
403 e[1] =
404 vnet_classify_find_entry_inline (t[1], (u8 *) h[1], hash[1], now);
405 if (e[1])
406 {
407 vnet_buffer (b[1])->l2_classify.opaque_index
408 = e[1]->opaque_index;
409 vlib_buffer_advance (b[1], e[1]->advance);
410
411 _next[1] = (e[1]->next_index < n_next_nodes) ?
412 e[1]->next_index : _next[1];
413
414 hits++;
415
Benoît Ganneabb2a422021-09-30 13:41:00 +0200416 b[1]->error =
417 (_next[1] == ACL_NEXT_INDEX_DENY) ? error_deny : error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000418
419 if (!is_output)
420 {
421 if (e[1]->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX ||
422 e[1]->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
423 vnet_buffer (b[1])->sw_if_index[VLIB_TX] = e[1]->metadata;
424 else if (e[1]->action == CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100425 {
426 vnet_buffer (b[1])->ip.adj_index[VLIB_TX] =
427 e[1]->metadata;
428 /* For source check in case we skip the lookup node */
429 ip_lookup_set_buffer_fib_index (fib_index_by_sw_if_index,
430 b[1]);
431 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000432 }
433 }
434 else
435 {
436 while (1)
437 {
Benoît Ganne051d3a32022-11-18 17:05:10 +0100438 table_index[1] = t[1]->next_table_index;
439 if (PREDICT_TRUE (table_index[1] != ~0))
440 t[1] = pool_elt_at_index (tables, table_index[1]);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000441 else
442 {
443 _next[1] = (t[1]->miss_next_index < n_next_nodes) ?
444 t[1]->miss_next_index : _next[1];
445
446 misses++;
447
Benoît Ganneabb2a422021-09-30 13:41:00 +0200448 b[1]->error = (_next[1] == ACL_NEXT_INDEX_DENY) ?
449 error_miss :
450 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000451 break;
452 }
453
454 if (t[1]->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
455 h[1] =
456 (void *) vlib_buffer_get_current (b[1]) +
457 t[1]->current_data_offset;
458 else
459 h[1] = b[1]->data;
460
461 /* advance the match pointer so the matching happens on IP header */
462 if (is_output)
Benoît Ganneb03eec92022-06-08 10:49:17 +0200463 h[1] += vnet_buffer (b[1])->l2.l2_len;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000464
465 hash[1] =
466 vnet_classify_hash_packet_inline (t[1], (u8 *) h[1]);
467 e[1] =
468 vnet_classify_find_entry_inline (t[1], (u8 *) h[1],
469 hash[1], now);
470 if (e[1])
471 {
472 vnet_buffer (b[1])->l2_classify.opaque_index
473 = e[1]->opaque_index;
474 vlib_buffer_advance (b[1], e[1]->advance);
475 _next[1] = (e[1]->next_index < n_next_nodes) ?
476 e[1]->next_index : _next[1];
477 hits++;
478 chain_hits++;
479
Benoît Ganneabb2a422021-09-30 13:41:00 +0200480 b[1]->error = (_next[1] == ACL_NEXT_INDEX_DENY) ?
481 error_deny :
482 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000483
484 if (!is_output)
485 {
486 if (e[1]->action ==
487 CLASSIFY_ACTION_SET_IP4_FIB_INDEX
488 || e[1]->action ==
489 CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
490 vnet_buffer (b[1])->sw_if_index[VLIB_TX] =
491 e[1]->metadata;
492 else if (e[1]->action ==
493 CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100494 {
495 vnet_buffer (b[1])->ip.adj_index[VLIB_TX] =
496 e[1]->metadata;
497 /* For source check in case we skip the lookup
498 * node */
499 ip_lookup_set_buffer_fib_index (
500 fib_index_by_sw_if_index, b[1]);
501 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000502 }
503 break;
504 }
505 }
506 }
507 }
508
509 if (do_trace && b[0]->flags & VLIB_BUFFER_IS_TRACED)
510 {
511 ip_in_out_acl_trace_t *_t =
512 vlib_add_trace (vm, node, b[0], sizeof (*_t));
513 _t->sw_if_index =
Benoît Ganneabb2a422021-09-30 13:41:00 +0200514 ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000515 _t->next_index = _next[0];
Benoît Gannec629f902022-06-08 10:56:33 +0200516 _t->table_index = table_index[0];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000517 _t->offset = (e[0]
518 && t[0]) ? vnet_classify_get_offset (t[0], e[0]) : ~0;
519 }
520
521 if (do_trace && b[1]->flags & VLIB_BUFFER_IS_TRACED)
522 {
523 ip_in_out_acl_trace_t *_t =
524 vlib_add_trace (vm, node, b[1], sizeof (*_t));
525 _t->sw_if_index =
Benoît Ganneabb2a422021-09-30 13:41:00 +0200526 ~0 == way ? 0 : vnet_buffer (b[1])->sw_if_index[way];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000527 _t->next_index = _next[1];
Benoît Gannec629f902022-06-08 10:56:33 +0200528 _t->table_index = table_index[1];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000529 _t->offset = (e[1]
530 && t[1]) ? vnet_classify_get_offset (t[1], e[1]) : ~0;
531 }
532
533 if ((_next[0] == ACL_NEXT_INDEX_DENY) && is_output)
534 {
535 /* on output, for the drop node to work properly, go back to ip header */
536 vlib_buffer_advance (b[0], vnet_buffer (b[0])->l2.l2_len);
537 }
538
539 if ((_next[1] == ACL_NEXT_INDEX_DENY) && is_output)
540 {
541 /* on output, for the drop node to work properly, go back to ip header */
542 vlib_buffer_advance (b[1], vnet_buffer (b[1])->l2.l2_len);
543 }
544
545 next[0] = _next[0];
546 next[1] = _next[1];
547
548 /* _next */
549 next += 2;
550 b += 2;
551 n_left -= 2;
552 }
553
554 while (n_left > 0)
555 {
Dave Barachd7cb1b52016-12-09 09:52:16 -0500556 u8 *h0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700557 u32 sw_if_index0;
558 u32 table_index0;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000559 vnet_classify_table_t *t0 = 0;
560 vnet_classify_entry_t *e0 = 0;
561 u32 next0 = ACL_NEXT_INDEX_DENY;
Benoît Ganneb03eec92022-06-08 10:49:17 +0200562 u32 hash0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700563
Benoît Ganneabb2a422021-09-30 13:41:00 +0200564 sw_if_index0 = ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way];
565 table_index0 = table_index_by_sw_if_index[sw_if_index0];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700566
Benoît Ganneabb2a422021-09-30 13:41:00 +0200567 t0 = pool_elt_at_index (tables, table_index0);
Steve Shin25e26dc2016-11-08 10:47:10 -0800568
569 if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
Ray Kinsella8899ce02020-03-12 15:52:41 +0000570 h0 =
571 (void *) vlib_buffer_get_current (b[0]) + t0->current_data_offset;
Steve Shin25e26dc2016-11-08 10:47:10 -0800572 else
Ray Kinsella8899ce02020-03-12 15:52:41 +0000573 h0 = b[0]->data;
Steve Shin25e26dc2016-11-08 10:47:10 -0800574
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100575 if (is_output)
576 {
577 /* Save the rewrite length, since we are using the l2_classify struct */
Benoît Ganneb03eec92022-06-08 10:49:17 +0200578 vnet_buffer (b[0])->l2.l2_len =
Ray Kinsella8899ce02020-03-12 15:52:41 +0000579 vnet_buffer (b[0])->ip.save_rewrite_length;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100580 /* advance the match pointer so the matching happens on IP header */
Benoît Ganneb03eec92022-06-08 10:49:17 +0200581 h0 += vnet_buffer (b[0])->l2.l2_len;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100582 }
583
Ray Kinsella8899ce02020-03-12 15:52:41 +0000584 vnet_buffer (b[0])->l2_classify.hash =
Dave Barachd7cb1b52016-12-09 09:52:16 -0500585 vnet_classify_hash_packet (t0, (u8 *) h0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700586
Ray Kinsella8899ce02020-03-12 15:52:41 +0000587 vnet_buffer (b[0])->l2_classify.table_index = table_index0;
588 vnet_buffer (b[0])->l2_classify.opaque_index = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700589
Benoît Ganneabb2a422021-09-30 13:41:00 +0200590 vnet_get_config_data (cm, &b[0]->current_config_index, &next0,
Ray Kinsella8899ce02020-03-12 15:52:41 +0000591 /* # bytes of config data */ 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700592
Ray Kinsella8899ce02020-03-12 15:52:41 +0000593 if (PREDICT_TRUE (table_index0 != ~0))
Dave Barachd7cb1b52016-12-09 09:52:16 -0500594 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000595 hash0 = vnet_buffer (b[0])->l2_classify.hash;
Benoît Ganneabb2a422021-09-30 13:41:00 +0200596 t0 = pool_elt_at_index (tables, table_index0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700597
Ray Kinsella8899ce02020-03-12 15:52:41 +0000598 if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
599 h0 =
600 (void *) vlib_buffer_get_current (b[0]) +
601 t0->current_data_offset;
602 else
603 h0 = b[0]->data;
604
605 /* advance the match pointer so the matching happens on IP header */
606 if (is_output)
Benoît Ganneb03eec92022-06-08 10:49:17 +0200607 h0 += vnet_buffer (b[0])->l2.l2_len;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000608
609 e0 = vnet_classify_find_entry_inline (t0, (u8 *) h0, hash0, now);
610 if (e0)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500611 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000612 vnet_buffer (b[0])->l2_classify.opaque_index = e0->opaque_index;
613 vlib_buffer_advance (b[0], e0->advance);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614
Ray Kinsella8899ce02020-03-12 15:52:41 +0000615 next0 = (e0->next_index < n_next_nodes) ?
616 e0->next_index : next0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700617
Ray Kinsella8899ce02020-03-12 15:52:41 +0000618 hits++;
619
Benoît Ganneabb2a422021-09-30 13:41:00 +0200620 b[0]->error =
621 (next0 == ACL_NEXT_INDEX_DENY) ? error_deny : error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000622
623 if (!is_output)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500624 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000625 if (e0->action == CLASSIFY_ACTION_SET_IP4_FIB_INDEX ||
626 e0->action == CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
627 vnet_buffer (b[0])->sw_if_index[VLIB_TX] = e0->metadata;
628 else if (e0->action == CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100629 {
630 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] = e0->metadata;
631 /* For source check in case we skip the lookup node */
632 ip_lookup_set_buffer_fib_index (fib_index_by_sw_if_index,
633 b[0]);
634 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500635 }
636 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000637 else
Dave Barachd7cb1b52016-12-09 09:52:16 -0500638 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000639 while (1)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500640 {
Benoît Ganne051d3a32022-11-18 17:05:10 +0100641 table_index0 = t0->next_table_index;
642 if (PREDICT_TRUE (table_index0 != ~0))
643 t0 = pool_elt_at_index (tables, table_index0);
Dave Barachd7cb1b52016-12-09 09:52:16 -0500644 else
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100645 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000646 next0 = (t0->miss_next_index < n_next_nodes) ?
647 t0->miss_next_index : next0;
648
649 misses++;
650
Benoît Ganneabb2a422021-09-30 13:41:00 +0200651 b[0]->error = (next0 == ACL_NEXT_INDEX_DENY) ?
652 error_miss :
653 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000654 break;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100655 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000656
657 if (t0->current_data_flag == CLASSIFY_FLAG_USE_CURR_DATA)
658 h0 =
659 (void *) vlib_buffer_get_current (b[0]) +
660 t0->current_data_offset;
661 else
662 h0 = b[0]->data;
663
664 /* advance the match pointer so the matching happens on IP header */
665 if (is_output)
Benoît Ganneb03eec92022-06-08 10:49:17 +0200666 h0 += vnet_buffer (b[0])->l2.l2_len;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000667
668 hash0 = vnet_classify_hash_packet_inline (t0, (u8 *) h0);
669 e0 = vnet_classify_find_entry_inline
670 (t0, (u8 *) h0, hash0, now);
671 if (e0)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500672 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000673 vnet_buffer (b[0])->l2_classify.opaque_index
674 = e0->opaque_index;
675 vlib_buffer_advance (b[0], e0->advance);
676 next0 = (e0->next_index < n_next_nodes) ?
677 e0->next_index : next0;
678 hits++;
679
Benoît Ganneabb2a422021-09-30 13:41:00 +0200680 b[0]->error = (next0 == ACL_NEXT_INDEX_DENY) ?
681 error_deny :
682 error_none;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000683
684 if (!is_output)
Dave Barachd7cb1b52016-12-09 09:52:16 -0500685 {
Ray Kinsella8899ce02020-03-12 15:52:41 +0000686 if (e0->action ==
687 CLASSIFY_ACTION_SET_IP4_FIB_INDEX
688 || e0->action ==
689 CLASSIFY_ACTION_SET_IP6_FIB_INDEX)
690 vnet_buffer (b[0])->sw_if_index[VLIB_TX] =
691 e0->metadata;
692 else if (e0->action == CLASSIFY_ACTION_SET_METADATA)
Arthur de Kerhor10310982021-12-22 10:58:30 +0100693 {
694 vnet_buffer (b[0])->ip.adj_index[VLIB_TX] =
695 e0->metadata;
696 /* For source check in case we skip the lookup
697 * node */
698 ip_lookup_set_buffer_fib_index (
699 fib_index_by_sw_if_index, b[0]);
700 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500701 }
Ray Kinsella8899ce02020-03-12 15:52:41 +0000702 break;
Dave Barachd7cb1b52016-12-09 09:52:16 -0500703 }
704 }
705 }
Dave Barachd7cb1b52016-12-09 09:52:16 -0500706 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700707
Ray Kinsella8899ce02020-03-12 15:52:41 +0000708 if (do_trace && b[0]->flags & VLIB_BUFFER_IS_TRACED)
709 {
710 ip_in_out_acl_trace_t *t =
711 vlib_add_trace (vm, node, b[0], sizeof (*t));
712 t->sw_if_index =
Benoît Ganneabb2a422021-09-30 13:41:00 +0200713 ~0 == way ? 0 : vnet_buffer (b[0])->sw_if_index[way];
Ray Kinsella8899ce02020-03-12 15:52:41 +0000714 t->next_index = next0;
Benoît Gannec629f902022-06-08 10:56:33 +0200715 t->table_index = table_index0;
Ray Kinsella8899ce02020-03-12 15:52:41 +0000716 t->offset = (e0 && t0) ? vnet_classify_get_offset (t0, e0) : ~0;
717 }
718
719 if ((next0 == ACL_NEXT_INDEX_DENY) && is_output)
720 {
721 /* on output, for the drop node to work properly, go back to ip header */
722 vlib_buffer_advance (b[0], vnet_buffer (b[0])->l2.l2_len);
723 }
724
725 next[0] = next0;
726
727 /* next */
728 next++;
729 b++;
730 n_left--;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700731 }
732
Benoît Ganneabb2a422021-09-30 13:41:00 +0200733 *hits__ = hits;
734 *misses__ = misses;
735 *chain_hits__ = chain_hits;
736}
737
738static_always_inline uword
739ip_in_out_acl_inline (vlib_main_t *vm, vlib_node_runtime_t *node,
740 vlib_frame_t *frame, const in_out_acl_table_id_t tid,
Arthur de Kerhor10310982021-12-22 10:58:30 +0100741 u32 *fib_index_by_sw_if_index,
Benoît Ganneabb2a422021-09-30 13:41:00 +0200742 const vlib_node_registration_t *parent_error_node,
743 const u32 error_none_index, const u32 error_deny_index,
744 const u32 error_miss_index, const vlib_rx_or_tx_t way,
745 const int is_output)
746{
747 const in_out_acl_main_t *am = &in_out_acl_main;
748 vnet_classify_table_t *tables = am->vnet_classify_main->tables;
749 u32 *from = vlib_frame_vector_args (frame);
750 const u32 *table_index_by_sw_if_index =
751 am->classify_table_index_by_sw_if_index[is_output][tid];
752 vnet_config_main_t *cm = am->vnet_config_main[is_output][tid];
753 const vlib_node_runtime_t *error_node =
754 vlib_node_get_runtime (vm, parent_error_node->index);
755 const vlib_error_t error_none = error_node->errors[error_none_index];
756 const vlib_error_t error_deny = error_node->errors[error_deny_index];
757 const vlib_error_t error_miss = error_node->errors[error_miss_index];
758 vlib_buffer_t *bufs[VLIB_FRAME_SIZE];
759 u16 nexts[VLIB_FRAME_SIZE];
760 u32 hits, misses, chain_hits;
761
762 vlib_get_buffers (vm, from, bufs, frame->n_vectors);
763
764#define ip_in_out_acl_inline_trace__(do_trace) \
765 ip_in_out_acl_inline_trace ( \
766 vm, node, frame, bufs, nexts, frame->n_vectors, &hits, &misses, \
767 &chain_hits, error_deny, error_miss, error_none, tables, \
Arthur de Kerhor10310982021-12-22 10:58:30 +0100768 table_index_by_sw_if_index, fib_index_by_sw_if_index, cm, way, is_output, \
769 do_trace)
Benoît Ganneabb2a422021-09-30 13:41:00 +0200770
771 if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
772 ip_in_out_acl_inline_trace__ (1 /* do_trace */);
773 else
774 ip_in_out_acl_inline_trace__ (0 /* do_trace */);
775
776 vlib_node_increment_counter (
777 vm, node->node_index,
778 is_output ? IP_OUTACL_ERROR_MISS : IP_INACL_ERROR_MISS, misses);
779 vlib_node_increment_counter (
780 vm, node->node_index, is_output ? IP_OUTACL_ERROR_HIT : IP_INACL_ERROR_HIT,
781 hits);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700782 vlib_node_increment_counter (vm, node->node_index,
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100783 is_output ? IP_OUTACL_ERROR_CHAIN_HIT :
Benoît Ganneabb2a422021-09-30 13:41:00 +0200784 IP_INACL_ERROR_CHAIN_HIT,
785 chain_hits);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000786
787 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000788 return frame->n_vectors;
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100789}
790
Benoît Ganneabb2a422021-09-30 13:41:00 +0200791VLIB_NODE_FN (ip4_inacl_node)
792(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100793{
Benoît Ganneabb2a422021-09-30 13:41:00 +0200794 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100795 vm, node, frame, IN_OUT_ACL_TABLE_IP4, ip4_main.fib_index_by_sw_if_index,
796 &ip4_input_node, IP4_ERROR_NONE, IP4_ERROR_INACL_SESSION_DENY,
797 IP4_ERROR_INACL_TABLE_MISS, VLIB_RX, 0 /* is_output */);
Benoît Ganneabb2a422021-09-30 13:41:00 +0200798}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700799
Benoît Ganneabb2a422021-09-30 13:41:00 +0200800VLIB_NODE_FN (ip4_punt_acl_node)
801(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
802{
803 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100804 vm, node, frame, IN_OUT_ACL_TABLE_IP4_PUNT,
805 ip4_main.fib_index_by_sw_if_index, &ip4_input_node, IP4_ERROR_NONE,
806 IP4_ERROR_INACL_SESSION_DENY, IP4_ERROR_INACL_TABLE_MISS, ~0 /* way */,
807 0 /* is_output */);
Benoît Ganneabb2a422021-09-30 13:41:00 +0200808}
Ray Kinsella8899ce02020-03-12 15:52:41 +0000809
Benoît Ganneabb2a422021-09-30 13:41:00 +0200810VLIB_NODE_FN (ip4_outacl_node)
811(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
812{
813 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100814 vm, node, frame, IN_OUT_ACL_TABLE_IP4, NULL, &ip4_input_node,
815 IP4_ERROR_NONE, IP4_ERROR_INACL_SESSION_DENY, IP4_ERROR_INACL_TABLE_MISS,
816 VLIB_TX, 1 /* is_output */);
Ray Kinsella8899ce02020-03-12 15:52:41 +0000817}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700818
819VLIB_REGISTER_NODE (ip4_inacl_node) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700820 .name = "ip4-inacl",
821 .vector_size = sizeof (u32),
822 .format_trace = format_ip_inacl_trace,
823 .n_errors = ARRAY_LEN(ip_inacl_error_strings),
824 .error_strings = ip_inacl_error_strings,
825
826 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
827 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800828 [ACL_NEXT_INDEX_DENY] = "ip4-drop",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700829 },
830};
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100831
Benoît Ganneabb2a422021-09-30 13:41:00 +0200832VLIB_REGISTER_NODE (ip4_punt_acl_node) = {
833 .name = "ip4-punt-acl",
834 .vector_size = sizeof (u32),
835 .format_trace = format_ip_inacl_trace,
836 .n_errors = ARRAY_LEN(ip_inacl_error_strings),
837 .error_strings = ip_inacl_error_strings,
838
839 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
840 .next_nodes = {
841 [ACL_NEXT_INDEX_DENY] = "ip4-drop",
842 },
843};
844
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100845VLIB_REGISTER_NODE (ip4_outacl_node) = {
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100846 .name = "ip4-outacl",
847 .vector_size = sizeof (u32),
848 .format_trace = format_ip_outacl_trace,
849 .n_errors = ARRAY_LEN(ip_outacl_error_strings),
850 .error_strings = ip_outacl_error_strings,
851
852 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
853 .next_nodes = {
854 [ACL_NEXT_INDEX_DENY] = "ip4-drop",
855 },
856};
Ed Warnickecb9cada2015-12-08 15:45:58 -0700857
Benoît Ganneabb2a422021-09-30 13:41:00 +0200858VNET_FEATURE_INIT (ip4_punt_acl_feature) = {
859 .arc_name = "ip4-punt",
860 .node_name = "ip4-punt-acl",
861 .runs_after = VNET_FEATURES ("ip4-punt-policer"),
862};
863
Filip Tehlar26ea14e2019-03-11 05:30:21 -0700864VLIB_NODE_FN (ip6_inacl_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
865 vlib_frame_t * frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700866{
Benoît Ganneabb2a422021-09-30 13:41:00 +0200867 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100868 vm, node, frame, IN_OUT_ACL_TABLE_IP6, ip6_main.fib_index_by_sw_if_index,
869 &ip6_input_node, IP6_ERROR_NONE, IP6_ERROR_INACL_SESSION_DENY,
870 IP6_ERROR_INACL_TABLE_MISS, VLIB_RX, 0 /* is_output */);
Benoît Ganneabb2a422021-09-30 13:41:00 +0200871}
Ray Kinsella8899ce02020-03-12 15:52:41 +0000872
Benoît Ganneabb2a422021-09-30 13:41:00 +0200873VLIB_NODE_FN (ip6_punt_acl_node)
874(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
875{
876 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100877 vm, node, frame, IN_OUT_ACL_TABLE_IP6_PUNT,
878 ip4_main.fib_index_by_sw_if_index, &ip6_input_node, IP6_ERROR_NONE,
879 IP6_ERROR_INACL_SESSION_DENY, IP6_ERROR_INACL_TABLE_MISS, ~0 /* way */,
880 0 /* is_output */);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700881}
882
Filip Tehlar26ea14e2019-03-11 05:30:21 -0700883VLIB_NODE_FN (ip6_outacl_node) (vlib_main_t * vm, vlib_node_runtime_t * node,
884 vlib_frame_t * frame)
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100885{
Benoît Ganneabb2a422021-09-30 13:41:00 +0200886 return ip_in_out_acl_inline (
Arthur de Kerhor10310982021-12-22 10:58:30 +0100887 vm, node, frame, IN_OUT_ACL_TABLE_IP6, NULL, &ip6_input_node,
888 IP6_ERROR_NONE, IP6_ERROR_INACL_SESSION_DENY, IP6_ERROR_INACL_TABLE_MISS,
889 VLIB_TX, 1 /* is_output */);
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100890}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700891
892VLIB_REGISTER_NODE (ip6_inacl_node) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700893 .name = "ip6-inacl",
894 .vector_size = sizeof (u32),
895 .format_trace = format_ip_inacl_trace,
896 .n_errors = ARRAY_LEN(ip_inacl_error_strings),
897 .error_strings = ip_inacl_error_strings,
898
899 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
900 .next_nodes = {
Vijayabhaskar Katamreddyce074122017-11-15 13:50:26 -0800901 [ACL_NEXT_INDEX_DENY] = "ip6-drop",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700902 },
903};
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100904
Benoît Ganneabb2a422021-09-30 13:41:00 +0200905VLIB_REGISTER_NODE (ip6_punt_acl_node) = {
906 .name = "ip6-punt-acl",
907 .vector_size = sizeof (u32),
908 .format_trace = format_ip_inacl_trace,
909 .n_errors = ARRAY_LEN(ip_inacl_error_strings),
910 .error_strings = ip_inacl_error_strings,
911
912 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
913 .next_nodes = {
914 [ACL_NEXT_INDEX_DENY] = "ip6-drop",
915 },
916};
917
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100918VLIB_REGISTER_NODE (ip6_outacl_node) = {
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100919 .name = "ip6-outacl",
920 .vector_size = sizeof (u32),
921 .format_trace = format_ip_outacl_trace,
922 .n_errors = ARRAY_LEN(ip_outacl_error_strings),
923 .error_strings = ip_outacl_error_strings,
924
925 .n_next_nodes = ACL_NEXT_INDEX_N_NEXT,
926 .next_nodes = {
927 [ACL_NEXT_INDEX_DENY] = "ip6-drop",
928 },
929};
Ed Warnickecb9cada2015-12-08 15:45:58 -0700930
Benoît Ganneabb2a422021-09-30 13:41:00 +0200931VNET_FEATURE_INIT (ip6_punt_acl_feature) = {
932 .arc_name = "ip6-punt",
933 .node_name = "ip6-punt-acl",
934 .runs_after = VNET_FEATURES ("ip6-punt-policer"),
935};
936
Filip Tehlar26ea14e2019-03-11 05:30:21 -0700937#ifndef CLIB_MARCH_VARIANT
Ed Warnickecb9cada2015-12-08 15:45:58 -0700938static clib_error_t *
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100939ip_in_out_acl_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700940{
941 return 0;
942}
943
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +0100944VLIB_INIT_FUNCTION (ip_in_out_acl_init);
Filip Tehlar26ea14e2019-03-11 05:30:21 -0700945#endif /* CLIB_MARCH_VARIANT */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700946
Dave Barachd7cb1b52016-12-09 09:52:16 -0500947
948/*
949 * fd.io coding-style-patch-verification: ON
950 *
951 * Local Variables:
952 * eval: (c-set-style "gnu")
953 * End:
954 */