+nonip_in_out_node_fn (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame,
+ int is_output)
+{
+ acl_main_t *am = &acl_main;
+ u32 n_left, *from;
+ u16 nexts[VLIB_FRAME_SIZE], *next;
+ vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
+ vlib_node_runtime_t *error_node;
+
+ from = vlib_frame_vector_args (frame);
+ error_node = vlib_node_get_runtime (vm, node->node_index);
+ vlib_get_buffers (vm, from, bufs, frame->n_vectors);
+ /* set the initial values for the current buffer the next pointers */
+ b = bufs;
+ next = nexts;
+
+ n_left = frame->n_vectors;
+ while (n_left > 0)
+ {
+ u32 next_index = 0;
+ u32 sw_if_index0 =
+ vnet_buffer (b[0])->sw_if_index[is_output ? VLIB_TX : VLIB_RX];
+ u16 ethertype = 0;
+
+ int error0 = 0;
+
+ ethernet_header_t *h0 = vlib_buffer_get_current (b[0]);
+ u8 *l3h0 = (u8 *) h0 + vnet_buffer (b[0])->l2.l2_len;
+ ethertype = clib_net_to_host_u16 (get_u16 (l3h0 - 2));
+
+ if (is_permitted_ethertype (am, sw_if_index0, is_output, ethertype))
+ vnet_feature_next (&next_index, b[0]);
+
+ next[0] = next_index;
+
+ if (0 == next[0])
+ b[0]->error = error_node->errors[error0];
+
+ if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
+ && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
+ {
+ nonip_in_out_trace_t *t =
+ vlib_add_trace (vm, node, b[0], sizeof (*t));
+ t->sw_if_index = sw_if_index0;
+ t->ethertype = ethertype;
+ t->next_index = next[0];
+ }
+ next[0] = next[0] < node->n_next_nodes ? next[0] : 0;
+
+ next++;
+ b++;
+ n_left--;
+ }
+ vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
+
+ return frame->n_vectors;
+}
+
+VLIB_NODE_FN (acl_in_nonip_node) (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ return nonip_in_out_node_fn (vm, node, frame, 0);
+}
+
+VLIB_NODE_FN (acl_out_nonip_node) (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ return nonip_in_out_node_fn (vm, node, frame, 1);
+}
+
+
+/* *INDENT-OFF* */
+
+VLIB_REGISTER_NODE (acl_in_nonip_node) =
+{
+ .name = "acl-plugin-in-nonip-l2",
+ .vector_size = sizeof (u32),
+ .format_trace = format_l2_nonip_in_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+ .n_errors = ARRAY_LEN (fa_in_nonip_error_strings),
+ .error_strings = fa_in_nonip_error_strings,
+ .n_next_nodes = ACL_FA_N_NEXT,
+ .next_nodes =
+ {
+ [ACL_FA_ERROR_DROP] = "error-drop",
+ }
+};
+
+VNET_FEATURE_INIT (acl_in_l2_nonip_fa_feature, static) =
+{
+ .arc_name = "l2-input-nonip",
+ .node_name = "acl-plugin-in-nonip-l2",
+ .runs_before = VNET_FEATURES ("l2-input-feat-arc-end"),
+};
+
+VLIB_REGISTER_NODE (acl_out_nonip_node) =
+{
+ .name = "acl-plugin-out-nonip-l2",
+ .vector_size = sizeof (u32),
+ .format_trace = format_l2_nonip_out_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+ .n_errors = ARRAY_LEN (fa_out_nonip_error_strings),
+ .error_strings = fa_out_nonip_error_strings,
+ .n_next_nodes = ACL_FA_N_NEXT,
+ .next_nodes =
+ {
+ [ACL_FA_ERROR_DROP] = "error-drop",
+ }
+};
+
+VNET_FEATURE_INIT (acl_out_l2_nonip_fa_feature, static) =
+{
+ .arc_name = "l2-output-nonip",
+ .node_name = "acl-plugin-out-nonip-l2",
+ .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"),
+};
+
+/* *INDENT-ON* */
+
+
+
+always_inline u16
+get_current_policy_epoch (acl_main_t * am, int is_input, u32 sw_if_index0)
+{
+ u32 **p_epoch_vec =
+ is_input ? &am->input_policy_epoch_by_sw_if_index :
+ &am->output_policy_epoch_by_sw_if_index;
+ u16 current_policy_epoch =
+ sw_if_index0 < vec_len (*p_epoch_vec) ? vec_elt (*p_epoch_vec,
+ sw_if_index0)
+ : (is_input * FA_POLICY_EPOCH_IS_INPUT);
+ return current_policy_epoch;
+}
+
+always_inline void
+maybe_trace_buffer (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_buffer_t * b, u32 sw_if_index0, u32 lc_index0,
+ u16 next0, int match_acl_in_index, int match_rule_index,
+ fa_5tuple_t * fa_5tuple, u8 action, u32 trace_bitmap)
+{
+ if (PREDICT_FALSE (b->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ acl_fa_trace_t *t = vlib_add_trace (vm, node, b, sizeof (*t));
+ t->sw_if_index = sw_if_index0;
+ t->lc_index = lc_index0;
+ t->next_index = next0;
+ t->match_acl_in_index = match_acl_in_index;
+ t->match_rule_index = match_rule_index;
+ t->packet_info[0] = fa_5tuple->kv_40_8.key[0];
+ t->packet_info[1] = fa_5tuple->kv_40_8.key[1];
+ t->packet_info[2] = fa_5tuple->kv_40_8.key[2];
+ t->packet_info[3] = fa_5tuple->kv_40_8.key[3];
+ t->packet_info[4] = fa_5tuple->kv_40_8.key[4];
+ t->packet_info[5] = fa_5tuple->kv_40_8.value;
+ t->action = action;
+ t->trace_bitmap = trace_bitmap;
+ }
+}
+
+
+always_inline int
+stale_session_deleted (acl_main_t * am, int is_input,
+ acl_fa_per_worker_data_t * pw, u64 now,
+ u32 sw_if_index0, fa_full_session_id_t f_sess_id)
+{
+ u16 current_policy_epoch =
+ get_current_policy_epoch (am, is_input, sw_if_index0);
+
+ /* if the MSB of policy epoch matches but not the LSB means it is a stale session */
+ if ((0 ==
+ ((current_policy_epoch ^
+ f_sess_id.intf_policy_epoch) &
+ FA_POLICY_EPOCH_IS_INPUT))
+ && (current_policy_epoch != f_sess_id.intf_policy_epoch))
+ {
+ /* delete session and increment the counter */
+ vec_validate (pw->fa_session_epoch_change_by_sw_if_index, sw_if_index0);
+ vec_elt (pw->fa_session_epoch_change_by_sw_if_index, sw_if_index0)++;
+ if (acl_fa_conn_list_delete_session (am, f_sess_id, now))
+ {
+ /* delete the session only if we were able to unlink it */
+ acl_fa_two_stage_delete_session (am, sw_if_index0, f_sess_id, now);
+ }
+ return 1;
+ }
+ else
+ return 0;
+}
+
+
+
+
+
+always_inline void
+get_sw_if_index_xN (int vector_sz, int is_input, vlib_buffer_t ** b,
+ u32 * out_sw_if_index)
+{
+ int ii;
+ for (ii = 0; ii < vector_sz; ii++)
+ if (is_input)
+ out_sw_if_index[ii] = vnet_buffer (b[ii])->sw_if_index[VLIB_RX];
+ else
+ out_sw_if_index[ii] = vnet_buffer (b[ii])->sw_if_index[VLIB_TX];
+}
+
+always_inline void
+fill_5tuple_xN (int vector_sz, acl_main_t * am, int is_ip6, int is_input,
+ int is_l2_path, vlib_buffer_t ** b, u32 * sw_if_index,
+ fa_5tuple_t * out_fa_5tuple)
+{
+ int ii;
+ for (ii = 0; ii < vector_sz; ii++)
+ acl_fill_5tuple (am, sw_if_index[ii], b[ii], is_ip6,
+ is_input, is_l2_path, &out_fa_5tuple[ii]);
+}
+
+always_inline void
+make_session_hash_xN (int vector_sz, acl_main_t * am, int is_ip6,
+ u32 * sw_if_index, fa_5tuple_t * fa_5tuple,
+ u64 * out_hash)
+{
+ int ii;
+ for (ii = 0; ii < vector_sz; ii++)
+ out_hash[ii] =
+ acl_fa_make_session_hash (am, is_ip6, sw_if_index[ii], &fa_5tuple[ii]);
+}
+
+always_inline void
+prefetch_session_entry (acl_main_t * am, fa_full_session_id_t f_sess_id)
+{
+ fa_session_t *sess = get_session_ptr_no_check (am, f_sess_id.thread_index,
+ f_sess_id.session_index);
+ CLIB_PREFETCH (sess, 2 * CLIB_CACHE_LINE_BYTES, STORE);
+}
+
+always_inline u8
+process_established_session (vlib_main_t * vm, acl_main_t * am,
+ u32 counter_node_index, int is_input, u64 now,
+ fa_full_session_id_t f_sess_id,
+ u32 * sw_if_index, fa_5tuple_t * fa_5tuple,
+ u32 pkt_len, int node_trace_on,
+ u32 * trace_bitmap)
+{
+ u8 action = 0;
+ fa_session_t *sess = get_session_ptr_no_check (am, f_sess_id.thread_index,
+ f_sess_id.session_index);
+
+ int old_timeout_type = fa_session_get_timeout_type (am, sess);
+ action =
+ acl_fa_track_session (am, is_input, sw_if_index[0], now,
+ sess, &fa_5tuple[0], pkt_len);
+ int new_timeout_type = fa_session_get_timeout_type (am, sess);
+ /* Tracking might have changed the session timeout type, e.g. from transient to established */
+ if (PREDICT_FALSE (old_timeout_type != new_timeout_type))
+ {
+ acl_fa_restart_timer_for_session (am, now, f_sess_id);
+ vlib_node_increment_counter (vm, counter_node_index,
+ ACL_FA_ERROR_ACL_RESTART_SESSION_TIMER, 1);
+ if (node_trace_on)
+ *trace_bitmap |=
+ 0x00010000 + ((0xff & old_timeout_type) << 8) +
+ (0xff & new_timeout_type);
+ }
+ /*
+ * I estimate the likelihood to be very low - the VPP needs
+ * to have >64K interfaces to start with and then on
+ * exactly 64K indices apart needs to be exactly the same
+ * 5-tuple... Anyway, since this probability is nonzero -
+ * print an error and drop the unlucky packet.
+ * If this shows up in real world, we would need to bump
+ * the hash key length.
+ */
+ if (PREDICT_FALSE (sess->sw_if_index != sw_if_index[0]))
+ {
+ clib_warning
+ ("BUG: session LSB16(sw_if_index)=%d and 5-tuple=%d collision!",
+ sess->sw_if_index, sw_if_index[0]);
+ action = 0;
+ }
+ return action;
+
+}
+
+#define ACL_PLUGIN_VECTOR_SIZE 4
+#define ACL_PLUGIN_PREFETCH_GAP 3
+
+always_inline uword
+acl_fa_inner_node_fn (vlib_main_t * vm,
+ vlib_node_runtime_t * node, vlib_frame_t * frame,
+ int is_ip6, int is_input, int is_l2_path,
+ int with_stateful_datapath, int node_trace_on,
+ int reclassify_sessions)