2 * Copyright (c) 2016-2018 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <netinet/in.h>
18 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
20 #include <vnet/pg/pg.h>
21 #include <vppinfra/error.h>
25 #include <vnet/ip/icmp46_packet.h>
27 #include <plugins/acl/fa_node.h>
28 #include <plugins/acl/acl.h>
29 #include <plugins/acl/lookup_context.h>
30 #include <plugins/acl/public_inlines.h>
31 #include <plugins/acl/session_inlines.h>
33 #include <vppinfra/bihash_40_8.h>
34 #include <vppinfra/bihash_template.h>
41 u32 match_acl_in_index;
49 #define foreach_acl_fa_error \
50 _(ACL_DROP, "ACL deny packets") \
51 _(ACL_PERMIT, "ACL permit packets") \
52 _(ACL_NEW_SESSION, "new sessions added") \
53 _(ACL_EXIST_SESSION, "existing session packets") \
54 _(ACL_CHECK, "checked packets") \
55 _(ACL_RESTART_SESSION_TIMER, "restart session timer") \
56 _(ACL_TOO_MANY_SESSIONS, "too many sessions to add new") \
61 #define _(sym,str) ACL_FA_ERROR_##sym,
74 } nonip_in_out_trace_t;
76 /* packet trace format function */
78 format_nonip_in_out_trace (u8 * s, u32 is_output, va_list * args)
80 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
81 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
82 nonip_in_out_trace_t *t = va_arg (*args, nonip_in_out_trace_t *);
84 s = format (s, "%s: sw_if_index %d next_index %x ethertype %x",
85 is_output ? "OUT-ETHER-WHITELIST" : "IN-ETHER-WHITELIST",
86 t->sw_if_index, t->next_index, t->ethertype);
91 format_l2_nonip_in_trace (u8 * s, va_list * args)
93 return format_nonip_in_out_trace (s, 0, args);
97 format_l2_nonip_out_trace (u8 * s, va_list * args)
99 return format_nonip_in_out_trace (s, 1, args);
102 #define foreach_nonip_in_error \
103 _(DROP, "dropped inbound non-whitelisted non-ip packets") \
104 _(PERMIT, "permitted inbound whitelisted non-ip packets") \
107 #define foreach_nonip_out_error \
108 _(DROP, "dropped outbound non-whitelisted non-ip packets") \
109 _(PERMIT, "permitted outbound whitelisted non-ip packets") \
116 #define _(sym,str) FA_IN_NONIP_ERROR_##sym,
117 foreach_nonip_in_error
120 } l2_in_feat_arc_error_t;
122 static char *fa_in_nonip_error_strings[] = {
123 #define _(sym,string) string,
124 foreach_nonip_in_error
130 #define _(sym,str) FA_OUT_NONIP_ERROR_##sym,
131 foreach_nonip_out_error
133 FA_OUT_NONIP_N_ERROR,
134 } l2_out_feat_arc_error_t;
136 static char *fa_out_nonip_error_strings[] = {
137 #define _(sym,string) string,
138 foreach_nonip_out_error
145 is_permitted_ethertype (acl_main_t * am, int sw_if_index0, int is_output,
149 ? am->output_etype_whitelist_by_sw_if_index
150 : am->input_etype_whitelist_by_sw_if_index;
151 u16 *whitelist = vec_elt (v, sw_if_index0);
154 if (vec_len (whitelist) == 0)
157 for (i = 0; i < vec_len (whitelist); i++)
158 if (whitelist[i] == ethertype)
163 #define get_u16(addr) ( *((u16 *)(addr)) )
166 nonip_in_out_node_fn (vlib_main_t * vm,
167 vlib_node_runtime_t * node, vlib_frame_t * frame,
170 acl_main_t *am = &acl_main;
172 u16 nexts[VLIB_FRAME_SIZE], *next;
173 vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
174 vlib_node_runtime_t *error_node;
176 from = vlib_frame_vector_args (frame);
177 error_node = vlib_node_get_runtime (vm, node->node_index);
178 vlib_get_buffers (vm, from, bufs, frame->n_vectors);
179 /* set the initial values for the current buffer the next pointers */
183 n_left = frame->n_vectors;
188 vnet_buffer (b[0])->sw_if_index[is_output ? VLIB_TX : VLIB_RX];
193 ethernet_header_t *h0 = vlib_buffer_get_current (b[0]);
194 u8 *l3h0 = (u8 *) h0 + vnet_buffer (b[0])->l2.l2_len;
195 ethertype = clib_net_to_host_u16 (get_u16 (l3h0 - 2));
197 if (is_permitted_ethertype (am, sw_if_index0, is_output, ethertype))
198 vnet_feature_next (&next_index, b[0]);
200 next[0] = next_index;
203 b[0]->error = error_node->errors[error0];
205 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
206 && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
208 nonip_in_out_trace_t *t =
209 vlib_add_trace (vm, node, b[0], sizeof (*t));
210 t->sw_if_index = sw_if_index0;
211 t->ethertype = ethertype;
212 t->next_index = next[0];
214 next[0] = next[0] < node->n_next_nodes ? next[0] : 0;
220 vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
222 return frame->n_vectors;
225 VLIB_NODE_FN (acl_in_nonip_node) (vlib_main_t * vm,
226 vlib_node_runtime_t * node,
227 vlib_frame_t * frame)
229 return nonip_in_out_node_fn (vm, node, frame, 0);
232 VLIB_NODE_FN (acl_out_nonip_node) (vlib_main_t * vm,
233 vlib_node_runtime_t * node,
234 vlib_frame_t * frame)
236 return nonip_in_out_node_fn (vm, node, frame, 1);
242 VLIB_REGISTER_NODE (acl_in_nonip_node) =
244 .name = "acl-plugin-in-nonip-l2",
245 .vector_size = sizeof (u32),
246 .format_trace = format_l2_nonip_in_trace,
247 .type = VLIB_NODE_TYPE_INTERNAL,
248 .n_errors = ARRAY_LEN (fa_in_nonip_error_strings),
249 .error_strings = fa_in_nonip_error_strings,
250 .n_next_nodes = ACL_FA_N_NEXT,
253 [ACL_FA_ERROR_DROP] = "error-drop",
257 VNET_FEATURE_INIT (acl_in_l2_nonip_fa_feature, static) =
259 .arc_name = "l2-input-nonip",
260 .node_name = "acl-plugin-in-nonip-l2",
261 .runs_before = VNET_FEATURES ("l2-input-feat-arc-end"),
264 VLIB_REGISTER_NODE (acl_out_nonip_node) =
266 .name = "acl-plugin-out-nonip-l2",
267 .vector_size = sizeof (u32),
268 .format_trace = format_l2_nonip_out_trace,
269 .type = VLIB_NODE_TYPE_INTERNAL,
270 .n_errors = ARRAY_LEN (fa_out_nonip_error_strings),
271 .error_strings = fa_out_nonip_error_strings,
272 .n_next_nodes = ACL_FA_N_NEXT,
275 [ACL_FA_ERROR_DROP] = "error-drop",
279 VNET_FEATURE_INIT (acl_out_l2_nonip_fa_feature, static) =
281 .arc_name = "l2-output-nonip",
282 .node_name = "acl-plugin-out-nonip-l2",
283 .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"),
291 get_current_policy_epoch (acl_main_t * am, int is_input, u32 sw_if_index0)
294 is_input ? &am->input_policy_epoch_by_sw_if_index :
295 &am->output_policy_epoch_by_sw_if_index;
296 u16 current_policy_epoch =
297 sw_if_index0 < vec_len (*p_epoch_vec) ? vec_elt (*p_epoch_vec,
299 : (is_input * FA_POLICY_EPOCH_IS_INPUT);
300 return current_policy_epoch;
304 maybe_trace_buffer (vlib_main_t * vm, vlib_node_runtime_t * node,
305 vlib_buffer_t * b, u32 sw_if_index0, u32 lc_index0,
306 u16 next0, int match_acl_in_index, int match_rule_index,
307 fa_5tuple_t * fa_5tuple, u8 action, u32 trace_bitmap)
309 if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
311 acl_fa_trace_t *t = vlib_add_trace (vm, node, b, sizeof (*t));
312 t->sw_if_index = sw_if_index0;
313 t->lc_index = lc_index0;
314 t->next_index = next0;
315 t->match_acl_in_index = match_acl_in_index;
316 t->match_rule_index = match_rule_index;
317 t->packet_info[0] = fa_5tuple->kv_40_8.key[0];
318 t->packet_info[1] = fa_5tuple->kv_40_8.key[1];
319 t->packet_info[2] = fa_5tuple->kv_40_8.key[2];
320 t->packet_info[3] = fa_5tuple->kv_40_8.key[3];
321 t->packet_info[4] = fa_5tuple->kv_40_8.key[4];
322 t->packet_info[5] = fa_5tuple->kv_40_8.value;
324 t->trace_bitmap = trace_bitmap;
330 stale_session_deleted (acl_main_t * am, int is_input,
331 acl_fa_per_worker_data_t * pw, u64 now,
332 u32 sw_if_index0, fa_full_session_id_t f_sess_id)
334 u16 current_policy_epoch =
335 get_current_policy_epoch (am, is_input, sw_if_index0);
337 /* if the MSB of policy epoch matches but not the LSB means it is a stale session */
339 ((current_policy_epoch ^
340 f_sess_id.intf_policy_epoch) &
341 FA_POLICY_EPOCH_IS_INPUT))
342 && (current_policy_epoch != f_sess_id.intf_policy_epoch))
344 /* delete session and increment the counter */
345 vec_validate (pw->fa_session_epoch_change_by_sw_if_index, sw_if_index0);
346 vec_elt (pw->fa_session_epoch_change_by_sw_if_index, sw_if_index0)++;
347 if (acl_fa_conn_list_delete_session (am, f_sess_id, now))
349 /* delete the session only if we were able to unlink it */
350 acl_fa_two_stage_delete_session (am, sw_if_index0, f_sess_id, now);
363 get_sw_if_index_xN (int vector_sz, int is_input, vlib_buffer_t ** b,
364 u32 * out_sw_if_index)
367 for (ii = 0; ii < vector_sz; ii++)
369 out_sw_if_index[ii] = vnet_buffer (b[ii])->sw_if_index[VLIB_RX];
371 out_sw_if_index[ii] = vnet_buffer (b[ii])->sw_if_index[VLIB_TX];
375 fill_5tuple_xN (int vector_sz, acl_main_t * am, int is_ip6, int is_input,
376 int is_l2_path, vlib_buffer_t ** b, u32 * sw_if_index,
377 fa_5tuple_t * out_fa_5tuple)
380 for (ii = 0; ii < vector_sz; ii++)
381 acl_fill_5tuple (am, sw_if_index[ii], b[ii], is_ip6,
382 is_input, is_l2_path, &out_fa_5tuple[ii]);
386 make_session_hash_xN (int vector_sz, acl_main_t * am, int is_ip6,
387 u32 * sw_if_index, fa_5tuple_t * fa_5tuple,
391 for (ii = 0; ii < vector_sz; ii++)
393 acl_fa_make_session_hash (am, is_ip6, sw_if_index[ii], &fa_5tuple[ii]);
397 prefetch_session_entry (acl_main_t * am, fa_full_session_id_t f_sess_id)
399 fa_session_t *sess = get_session_ptr_no_check (am, f_sess_id.thread_index,
400 f_sess_id.session_index);
401 CLIB_PREFETCH (sess, 2 * CLIB_CACHE_LINE_BYTES, STORE);
405 process_established_session (vlib_main_t * vm, acl_main_t * am,
406 u32 counter_node_index, int is_input, u64 now,
407 fa_full_session_id_t f_sess_id,
408 u32 * sw_if_index, fa_5tuple_t * fa_5tuple,
409 u32 pkt_len, int node_trace_on,
413 fa_session_t *sess = get_session_ptr_no_check (am, f_sess_id.thread_index,
414 f_sess_id.session_index);
416 int old_timeout_type = fa_session_get_timeout_type (am, sess);
418 acl_fa_track_session (am, is_input, sw_if_index[0], now,
419 sess, &fa_5tuple[0], pkt_len);
420 int new_timeout_type = fa_session_get_timeout_type (am, sess);
421 /* Tracking might have changed the session timeout type, e.g. from transient to established */
422 if (PREDICT_FALSE (old_timeout_type != new_timeout_type))
424 acl_fa_restart_timer_for_session (am, now, f_sess_id);
425 vlib_node_increment_counter (vm, counter_node_index,
426 ACL_FA_ERROR_ACL_RESTART_SESSION_TIMER, 1);
429 0x00010000 + ((0xff & old_timeout_type) << 8) +
430 (0xff & new_timeout_type);
433 * I estimate the likelihood to be very low - the VPP needs
434 * to have >64K interfaces to start with and then on
435 * exactly 64K indices apart needs to be exactly the same
436 * 5-tuple... Anyway, since this probability is nonzero -
437 * print an error and drop the unlucky packet.
438 * If this shows up in real world, we would need to bump
439 * the hash key length.
441 if (PREDICT_FALSE (sess->sw_if_index != sw_if_index[0]))
444 ("BUG: session LSB16(sw_if_index)=%d and 5-tuple=%d collision!",
445 sess->sw_if_index, sw_if_index[0]);
452 #define ACL_PLUGIN_VECTOR_SIZE 4
453 #define ACL_PLUGIN_PREFETCH_GAP 3
456 acl_fa_node_common_prepare_fn (vlib_main_t * vm,
457 vlib_node_runtime_t * node,
458 vlib_frame_t * frame, int is_ip6, int is_input,
459 int is_l2_path, int with_stateful_datapath)
460 /* , int node_trace_on,
461 int reclassify_sessions) */
464 acl_main_t *am = &acl_main;
465 uword thread_index = os_get_thread_index ();
466 acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
470 fa_5tuple_t *fa_5tuple;
475 from = vlib_frame_vector_args (frame);
476 vlib_get_buffers (vm, from, pw->bufs, frame->n_vectors);
478 /* set the initial values for the current buffer the next pointers */
480 sw_if_index = pw->sw_if_indices;
481 fa_5tuple = pw->fa_5tuples;
486 * fill the sw_if_index, 5tuple and session hash,
487 * First in strides of size ACL_PLUGIN_VECTOR_SIZE,
488 * with buffer prefetch being
489 * ACL_PLUGIN_PREFETCH_GAP * ACL_PLUGIN_VECTOR_SIZE entries
490 * in front. Then with a simple single loop.
493 n_left = frame->n_vectors;
494 while (n_left >= (ACL_PLUGIN_PREFETCH_GAP + 1) * ACL_PLUGIN_VECTOR_SIZE)
496 const int vec_sz = ACL_PLUGIN_VECTOR_SIZE;
499 for (ii = ACL_PLUGIN_PREFETCH_GAP * vec_sz;
500 ii < (ACL_PLUGIN_PREFETCH_GAP + 1) * vec_sz; ii++)
502 CLIB_PREFETCH (b[ii], CLIB_CACHE_LINE_BYTES, LOAD);
503 CLIB_PREFETCH (b[ii]->data, 2 * CLIB_CACHE_LINE_BYTES, LOAD);
508 get_sw_if_index_xN (vec_sz, is_input, b, sw_if_index);
509 fill_5tuple_xN (vec_sz, am, is_ip6, is_input, is_l2_path, &b[0],
510 &sw_if_index[0], &fa_5tuple[0]);
511 if (with_stateful_datapath)
512 make_session_hash_xN (vec_sz, am, is_ip6, &sw_if_index[0],
513 &fa_5tuple[0], &hash[0]);
519 sw_if_index += vec_sz;
525 const int vec_sz = 1;
527 get_sw_if_index_xN (vec_sz, is_input, b, sw_if_index);
528 fill_5tuple_xN (vec_sz, am, is_ip6, is_input, is_l2_path, &b[0],
529 &sw_if_index[0], &fa_5tuple[0]);
530 if (with_stateful_datapath)
531 make_session_hash_xN (vec_sz, am, is_ip6, &sw_if_index[0],
532 &fa_5tuple[0], &hash[0]);
538 sw_if_index += vec_sz;
545 acl_fa_inner_node_fn (vlib_main_t * vm,
546 vlib_node_runtime_t * node, vlib_frame_t * frame,
547 int is_ip6, int is_input, int is_l2_path,
548 int with_stateful_datapath, int node_trace_on,
549 int reclassify_sessions)
552 u32 pkts_exist_session = 0;
553 u32 pkts_new_session = 0;
554 u32 pkts_acl_permit = 0;
555 u32 trace_bitmap = 0;
556 acl_main_t *am = &acl_main;
557 vlib_node_runtime_t *error_node;
558 vlib_error_t no_error_existing_session;
559 u64 now = clib_cpu_time_now ();
560 uword thread_index = os_get_thread_index ();
561 acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
566 fa_5tuple_t *fa_5tuple;
568 /* for the delayed counters */
569 u32 saved_matched_acl_index = 0;
570 u32 saved_matched_ace_index = 0;
571 u32 saved_packet_count = 0;
572 u32 saved_byte_count = 0;
574 from = vlib_frame_vector_args (frame);
575 error_node = vlib_node_get_runtime (vm, node->node_index);
576 no_error_existing_session =
577 error_node->errors[ACL_FA_ERROR_ACL_EXIST_SESSION];
581 sw_if_index = pw->sw_if_indices;
582 fa_5tuple = pw->fa_5tuples;
586 * Now the "hard" work of session lookups and ACL lookups for new sessions.
587 * Due to the complexity, do it for the time being in single loop with
588 * the pipeline of three prefetches:
589 * 1) bucket for the session bihash
590 * 2) data for the session bihash
591 * 3) worker session record
594 fa_full_session_id_t f_sess_id_next = {.as_u64 = ~0ULL };
596 /* find the "next" session so we can kickstart the pipeline */
597 if (with_stateful_datapath)
598 acl_fa_find_session_with_hash (am, is_ip6, sw_if_index[0], hash[0],
599 &fa_5tuple[0], &f_sess_id_next.as_u64);
601 n_left = frame->n_vectors;
606 int acl_check_needed = 1;
607 u32 match_acl_in_index = ~0;
608 u32 match_acl_pos = ~0;
609 u32 match_rule_index = ~0;
611 next[0] = 0; /* drop by default */
613 /* Try to match an existing session first */
615 if (with_stateful_datapath)
617 fa_full_session_id_t f_sess_id = f_sess_id_next;
621 acl_fa_prefetch_session_bucket_for_hash (am, is_ip6, hash[5]);
625 acl_fa_prefetch_session_data_for_hash (am, is_ip6, hash[3]);
629 acl_fa_find_session_with_hash (am, is_ip6, sw_if_index[1],
630 hash[1], &fa_5tuple[1],
631 &f_sess_id_next.as_u64);
632 if (f_sess_id_next.as_u64 != ~0ULL)
634 prefetch_session_entry (am, f_sess_id_next);
638 if (f_sess_id.as_u64 != ~0ULL)
642 trace_bitmap |= 0x80000000;
644 ASSERT (f_sess_id.thread_index < vec_len (vlib_mains));
645 b[0]->error = no_error_existing_session;
646 acl_check_needed = 0;
647 pkts_exist_session += 1;
649 process_established_session (vm, am, node->node_index,
650 is_input, now, f_sess_id,
653 b[0]->current_length,
657 /* expose the session id to the tracer */
660 match_rule_index = f_sess_id.session_index;
663 if (reclassify_sessions)
666 (stale_session_deleted
667 (am, is_input, pw, now, sw_if_index[0],
670 acl_check_needed = 1;
673 trace_bitmap |= 0x40000000;
676 * If we have just deleted the session, and the next
677 * buffer is the same 5-tuple, that session prediction
678 * is wrong, correct it.
680 if ((f_sess_id_next.as_u64 != ~0ULL)
681 && 0 == memcmp (&fa_5tuple[1], &fa_5tuple[0],
682 sizeof (fa_5tuple[1])))
683 f_sess_id_next.as_u64 = ~0ULL;
689 if (acl_check_needed)
692 lc_index0 = am->input_lc_index_by_sw_if_index[sw_if_index[0]];
695 am->output_lc_index_by_sw_if_index[sw_if_index[0]];
697 action = 0; /* deny by default */
698 int is_match = acl_plugin_match_5tuple_inline (am, lc_index0,
699 (fa_5tuple_opaque_t *) & fa_5tuple[0], is_ip6,
706 (is_match && am->interface_acl_counters_enabled))
708 u32 buf_len = vlib_buffer_length_in_chain (vm, b[0]);
709 vlib_increment_combined_counter (am->combined_acl_counters +
710 saved_matched_acl_index,
712 saved_matched_ace_index,
715 saved_matched_acl_index = match_acl_in_index;
716 saved_matched_ace_index = match_rule_index;
717 saved_packet_count = 1;
718 saved_byte_count = buf_len;
719 /* prefetch the counter that we are going to increment */
720 vlib_prefetch_combined_counter (am->combined_acl_counters +
721 saved_matched_acl_index,
723 saved_matched_ace_index);
726 b[0]->error = error_node->errors[action];
733 if (!acl_fa_can_add_session (am, is_input, sw_if_index[0]))
734 acl_fa_try_recycle_session (am, is_input,
736 sw_if_index[0], now);
738 if (acl_fa_can_add_session (am, is_input, sw_if_index[0]))
740 u16 current_policy_epoch =
741 get_current_policy_epoch (am, is_input,
743 fa_full_session_id_t f_sess_id =
744 acl_fa_add_session (am, is_input, is_ip6,
747 current_policy_epoch);
749 /* perform the accounting for the newly added session */
750 process_established_session (vm, am,
756 b[0]->current_length,
761 * If the next 5tuple is the same and we just added the session,
762 * the f_sess_id_next can not be ~0. Correct it.
764 if ((f_sess_id_next.as_u64 == ~0ULL)
765 && 0 == memcmp (&fa_5tuple[1], &fa_5tuple[0],
766 sizeof (fa_5tuple[1])))
767 f_sess_id_next = f_sess_id;
774 [ACL_FA_ERROR_ACL_TOO_MANY_SESSIONS];
781 /* speculatively get the next0 */
782 vnet_feature_next_u16 (&next[0], b[0]);
783 /* if the action is not deny - then use that next */
784 next[0] = action ? next[0] : 0;
787 if (node_trace_on) // PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
789 maybe_trace_buffer (vm, node, b[0], sw_if_index[0], lc_index0,
790 next[0], match_acl_in_index,
791 match_rule_index, &fa_5tuple[0], action,
804 vlib_buffer_enqueue_to_next (vm, node, from, pw->nexts, frame->n_vectors);
807 * if we were had an acl match then we have a counter to increment.
808 * else it is all zeroes, so this will be harmless.
810 vlib_increment_combined_counter (am->combined_acl_counters +
811 saved_matched_acl_index,
813 saved_matched_ace_index,
814 saved_packet_count, saved_byte_count);
816 vlib_node_increment_counter (vm, node->node_index,
817 ACL_FA_ERROR_ACL_CHECK, frame->n_vectors);
818 vlib_node_increment_counter (vm, node->node_index,
819 ACL_FA_ERROR_ACL_EXIST_SESSION,
821 vlib_node_increment_counter (vm, node->node_index,
822 ACL_FA_ERROR_ACL_NEW_SESSION,
824 vlib_node_increment_counter (vm, node->node_index,
825 ACL_FA_ERROR_ACL_PERMIT, pkts_acl_permit);
826 return frame->n_vectors;
830 acl_fa_outer_node_fn (vlib_main_t * vm,
831 vlib_node_runtime_t * node, vlib_frame_t * frame,
832 int is_ip6, int is_input, int is_l2_path,
833 int do_stateful_datapath)
835 acl_main_t *am = &acl_main;
837 acl_fa_node_common_prepare_fn (vm, node, frame, is_ip6, is_input,
838 is_l2_path, do_stateful_datapath);
840 if (am->reclassify_sessions)
842 if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
843 return acl_fa_inner_node_fn (vm, node, frame, is_ip6, is_input,
844 is_l2_path, do_stateful_datapath,
846 1 /* reclassify */ );
848 return acl_fa_inner_node_fn (vm, node, frame, is_ip6, is_input,
849 is_l2_path, do_stateful_datapath, 0,
850 1 /* reclassify */ );
854 if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE))
855 return acl_fa_inner_node_fn (vm, node, frame, is_ip6, is_input,
856 is_l2_path, do_stateful_datapath,
860 return acl_fa_inner_node_fn (vm, node, frame, is_ip6, is_input,
861 is_l2_path, do_stateful_datapath, 0, 0);
866 acl_fa_node_fn (vlib_main_t * vm,
867 vlib_node_runtime_t * node, vlib_frame_t * frame, int is_ip6,
868 int is_input, int is_l2_path)
870 /* select the reclassify/no-reclassify version of the datapath */
871 acl_main_t *am = &acl_main;
873 if (am->fa_sessions_hash_is_initialized)
874 return acl_fa_outer_node_fn (vm, node, frame, is_ip6, is_input,
877 return acl_fa_outer_node_fn (vm, node, frame, is_ip6, is_input,
883 format_fa_5tuple (u8 * s, va_list * args)
885 fa_5tuple_t *p5t = va_arg (*args, fa_5tuple_t *);
888 void *format_address_func;
891 p5t->pkt.is_nonfirst_fragment ? " non-initial fragment" : "";
896 format_address_func = format_ip6_address;
897 paddr0 = &p5t->ip6_addr[0];
898 paddr1 = &p5t->ip6_addr[1];
903 format_address_func = format_ip4_address;
904 paddr0 = &p5t->ip4_addr[0];
905 paddr1 = &p5t->ip4_addr[1];
909 format (s, "lc_index %d l3 %s%s ", p5t->pkt.lc_index, ip_af, ip_frag_txt);
911 format (s, "%U -> %U ", format_address_func, paddr0, format_address_func,
913 s = format (s, "%U ", format_fa_session_l4_key, &p5t->l4);
914 s = format (s, "tcp flags (%s) %02x rsvd %x",
915 p5t->pkt.tcp_flags_valid ? "valid" : "invalid",
916 p5t->pkt.tcp_flags, p5t->pkt.flags_reserved);
920 #ifndef CLIB_MARCH_VARIANT
922 format_acl_plugin_5tuple (u8 * s, va_list * args)
924 return format_fa_5tuple (s, args);
928 /* packet trace format function */
930 format_acl_plugin_trace (u8 * s, va_list * args)
932 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
933 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
934 acl_fa_trace_t *t = va_arg (*args, acl_fa_trace_t *);
938 "acl-plugin: lc_index: %d, sw_if_index %d, next index %d, action: %d, match: acl %d rule %d trace_bits %08x\n"
939 " pkt info %016llx %016llx %016llx %016llx %016llx %016llx",
940 t->lc_index, t->sw_if_index, t->next_index, t->action,
941 t->match_acl_in_index, t->match_rule_index, t->trace_bitmap,
942 t->packet_info[0], t->packet_info[1], t->packet_info[2],
943 t->packet_info[3], t->packet_info[4], t->packet_info[5]);
945 /* Now also print out the packet_info in a form usable by humans */
946 s = format (s, "\n %U", format_fa_5tuple, t->packet_info);
952 static char *acl_fa_error_strings[] = {
953 #define _(sym,string) string,
958 VLIB_NODE_FN (acl_in_l2_ip6_node) (vlib_main_t * vm,
959 vlib_node_runtime_t * node,
960 vlib_frame_t * frame)
962 return acl_fa_node_fn (vm, node, frame, 1, 1, 1);
965 VLIB_NODE_FN (acl_in_l2_ip4_node) (vlib_main_t * vm,
966 vlib_node_runtime_t * node,
967 vlib_frame_t * frame)
969 return acl_fa_node_fn (vm, node, frame, 0, 1, 1);
972 VLIB_NODE_FN (acl_out_l2_ip6_node) (vlib_main_t * vm,
973 vlib_node_runtime_t * node,
974 vlib_frame_t * frame)
976 return acl_fa_node_fn (vm, node, frame, 1, 0, 1);
979 VLIB_NODE_FN (acl_out_l2_ip4_node) (vlib_main_t * vm,
980 vlib_node_runtime_t * node,
981 vlib_frame_t * frame)
983 return acl_fa_node_fn (vm, node, frame, 0, 0, 1);
986 /**** L3 processing path nodes ****/
988 VLIB_NODE_FN (acl_in_fa_ip6_node) (vlib_main_t * vm,
989 vlib_node_runtime_t * node,
990 vlib_frame_t * frame)
992 return acl_fa_node_fn (vm, node, frame, 1, 1, 0);
995 VLIB_NODE_FN (acl_in_fa_ip4_node) (vlib_main_t * vm,
996 vlib_node_runtime_t * node,
997 vlib_frame_t * frame)
999 return acl_fa_node_fn (vm, node, frame, 0, 1, 0);
1002 VLIB_NODE_FN (acl_out_fa_ip6_node) (vlib_main_t * vm,
1003 vlib_node_runtime_t * node,
1004 vlib_frame_t * frame)
1006 return acl_fa_node_fn (vm, node, frame, 1, 0, 0);
1009 VLIB_NODE_FN (acl_out_fa_ip4_node) (vlib_main_t * vm,
1010 vlib_node_runtime_t * node,
1011 vlib_frame_t * frame)
1013 return acl_fa_node_fn (vm, node, frame, 0, 0, 0);
1016 VLIB_REGISTER_NODE (acl_in_l2_ip6_node) =
1018 .name = "acl-plugin-in-ip6-l2",
1019 .vector_size = sizeof (u32),
1020 .format_trace = format_acl_plugin_trace,
1021 .type = VLIB_NODE_TYPE_INTERNAL,
1022 .n_errors = ARRAY_LEN (acl_fa_error_strings),
1023 .error_strings = acl_fa_error_strings,
1024 .n_next_nodes = ACL_FA_N_NEXT,
1027 [ACL_FA_ERROR_DROP] = "error-drop",
1031 VNET_FEATURE_INIT (acl_in_l2_ip6_fa_feature, static) =
1033 .arc_name = "l2-input-ip6",
1034 .node_name = "acl-plugin-in-ip6-l2",
1035 .runs_before = VNET_FEATURES ("l2-input-feat-arc-end"),
1038 VLIB_REGISTER_NODE (acl_in_l2_ip4_node) =
1040 .name = "acl-plugin-in-ip4-l2",
1041 .vector_size = sizeof (u32),
1042 .format_trace = format_acl_plugin_trace,
1043 .type = VLIB_NODE_TYPE_INTERNAL,
1044 .n_errors = ARRAY_LEN (acl_fa_error_strings),
1045 .error_strings = acl_fa_error_strings,
1046 .n_next_nodes = ACL_FA_N_NEXT,
1049 [ACL_FA_ERROR_DROP] = "error-drop",
1053 VNET_FEATURE_INIT (acl_in_l2_ip4_fa_feature, static) =
1055 .arc_name = "l2-input-ip4",
1056 .node_name = "acl-plugin-in-ip4-l2",
1057 .runs_before = VNET_FEATURES ("l2-input-feat-arc-end"),
1061 VLIB_REGISTER_NODE (acl_out_l2_ip6_node) =
1063 .name = "acl-plugin-out-ip6-l2",
1064 .vector_size = sizeof (u32),
1065 .format_trace = format_acl_plugin_trace,
1066 .type = VLIB_NODE_TYPE_INTERNAL,
1067 .n_errors = ARRAY_LEN (acl_fa_error_strings),
1068 .error_strings = acl_fa_error_strings,
1069 .n_next_nodes = ACL_FA_N_NEXT,
1072 [ACL_FA_ERROR_DROP] = "error-drop",
1076 VNET_FEATURE_INIT (acl_out_l2_ip6_fa_feature, static) =
1078 .arc_name = "l2-output-ip6",
1079 .node_name = "acl-plugin-out-ip6-l2",
1080 .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"),
1084 VLIB_REGISTER_NODE (acl_out_l2_ip4_node) =
1086 .name = "acl-plugin-out-ip4-l2",
1087 .vector_size = sizeof (u32),
1088 .format_trace = format_acl_plugin_trace,
1089 .type = VLIB_NODE_TYPE_INTERNAL,
1090 .n_errors = ARRAY_LEN (acl_fa_error_strings),
1091 .error_strings = acl_fa_error_strings,
1092 .n_next_nodes = ACL_FA_N_NEXT,
1095 [ACL_FA_ERROR_DROP] = "error-drop",
1099 VNET_FEATURE_INIT (acl_out_l2_ip4_fa_feature, static) =
1101 .arc_name = "l2-output-ip4",
1102 .node_name = "acl-plugin-out-ip4-l2",
1103 .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"),
1107 VLIB_REGISTER_NODE (acl_in_fa_ip6_node) =
1109 .name = "acl-plugin-in-ip6-fa",
1110 .vector_size = sizeof (u32),
1111 .format_trace = format_acl_plugin_trace,
1112 .type = VLIB_NODE_TYPE_INTERNAL,
1113 .n_errors = ARRAY_LEN (acl_fa_error_strings),
1114 .error_strings = acl_fa_error_strings,
1115 .n_next_nodes = ACL_FA_N_NEXT,
1118 [ACL_FA_ERROR_DROP] = "error-drop",
1122 VNET_FEATURE_INIT (acl_in_ip6_fa_feature, static) =
1124 .arc_name = "ip6-unicast",
1125 .node_name = "acl-plugin-in-ip6-fa",
1126 .runs_before = VNET_FEATURES ("ip6-flow-classify"),
1129 VLIB_REGISTER_NODE (acl_in_fa_ip4_node) =
1131 .name = "acl-plugin-in-ip4-fa",
1132 .vector_size = sizeof (u32),
1133 .format_trace = format_acl_plugin_trace,
1134 .type = VLIB_NODE_TYPE_INTERNAL,
1135 .n_errors = ARRAY_LEN (acl_fa_error_strings),
1136 .error_strings = acl_fa_error_strings,
1137 .n_next_nodes = ACL_FA_N_NEXT,
1140 [ACL_FA_ERROR_DROP] = "error-drop",
1144 VNET_FEATURE_INIT (acl_in_ip4_fa_feature, static) =
1146 .arc_name = "ip4-unicast",
1147 .node_name = "acl-plugin-in-ip4-fa",
1148 .runs_before = VNET_FEATURES ("ip4-flow-classify"),
1152 VLIB_REGISTER_NODE (acl_out_fa_ip6_node) =
1154 .name = "acl-plugin-out-ip6-fa",
1155 .vector_size = sizeof (u32),
1156 .format_trace = format_acl_plugin_trace,
1157 .type = VLIB_NODE_TYPE_INTERNAL,
1158 .n_errors = ARRAY_LEN (acl_fa_error_strings),
1159 .error_strings = acl_fa_error_strings,
1160 .n_next_nodes = ACL_FA_N_NEXT,
1163 [ACL_FA_ERROR_DROP] = "error-drop",
1167 VNET_FEATURE_INIT (acl_out_ip6_fa_feature, static) =
1169 .arc_name = "ip6-output",
1170 .node_name = "acl-plugin-out-ip6-fa",
1171 .runs_before = VNET_FEATURES ("interface-output"),
1174 VLIB_REGISTER_NODE (acl_out_fa_ip4_node) =
1176 .name = "acl-plugin-out-ip4-fa",
1177 .vector_size = sizeof (u32),
1178 .format_trace = format_acl_plugin_trace,
1179 .type = VLIB_NODE_TYPE_INTERNAL,
1180 .n_errors = ARRAY_LEN (acl_fa_error_strings),
1181 .error_strings = acl_fa_error_strings,
1182 .n_next_nodes = ACL_FA_N_NEXT,
1183 /* edit / add dispositions here */
1186 [ACL_FA_ERROR_DROP] = "error-drop",
1190 VNET_FEATURE_INIT (acl_out_ip4_fa_feature, static) =
1192 .arc_name = "ip4-output",
1193 .node_name = "acl-plugin-out-ip4-fa",
1194 .runs_before = VNET_FEATURES ("interface-output"),
1200 * fd.io coding-style-patch-verification: ON
1203 * eval: (c-set-style "gnu")