2 * Copyright (c) 2016 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.
15 #include <vlib/vlib.h>
16 #include <vnet/vnet.h>
17 #include <vnet/pg/pg.h>
18 #include <vppinfra/error.h>
32 /* packet trace format function */
34 format_acl_out_trace (u8 * s, va_list * args)
36 CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
37 CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
38 acl_out_trace_t *t = va_arg (*args, acl_out_trace_t *);
41 "ACL_OUT: sw_if_index %d, next index %d, match: outacl %d rule %d trace_bits %08x",
42 t->sw_if_index, t->next_index, t->match_acl_index,
43 t->match_rule_index, t->trace_bitmap);
47 vlib_node_registration_t acl_out_node;
49 #define foreach_acl_out_error \
50 _(ACL_CHECK, "OutACL check packets processed")
54 #define _(sym,str) ACL_OUT_ERROR_##sym,
60 static char *acl_out_error_strings[] = {
61 #define _(sym,string) string,
67 acl_out_node_fn (vlib_main_t * vm,
68 vlib_node_runtime_t * node, vlib_frame_t * frame)
70 acl_main_t *am = &acl_main;
71 u32 *output_feat_next_node_index =
72 am->acl_out_node_feat_next_node_index;
73 u32 n_left_from, *from, *to_next;
74 acl_out_next_t next_index;
75 u32 pkts_acl_checked = 0;
77 u32 match_acl_index = ~0;
78 u32 match_rule_index = ~0;
81 from = vlib_frame_vector_args (frame);
82 n_left_from = frame->n_vectors;
83 next_index = node->cached_next_index;
85 while (n_left_from > 0)
89 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
91 while (n_left_from > 0 && n_left_to_next > 0)
99 /* speculatively enqueue b0 to the current next frame */
107 b0 = vlib_get_buffer (vm, bi0);
110 sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
111 feature_bitmap0 = vnet_buffer (b0)->l2.feature_bitmap;
113 output_acl_packet_match (sw_if_index0, b0, &next, &match_acl_index,
114 &match_rule_index, &trace_bitmap);
122 feat_bitmap_get_next_node_index (output_feat_next_node_index,
128 if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
129 && (b0->flags & VLIB_BUFFER_IS_TRACED)))
131 acl_out_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
132 t->sw_if_index = sw_if_index0;
133 t->next_index = next0;
134 t->match_acl_index = match_acl_index;
135 t->match_rule_index = match_rule_index;
136 t->trace_bitmap = trace_bitmap;
139 pkts_acl_checked += 1;
141 /* verify speculative enqueue, maybe switch current next frame */
142 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
143 to_next, n_left_to_next,
147 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
150 vlib_node_increment_counter (vm, acl_out_node.index,
151 ACL_OUT_ERROR_ACL_CHECK, pkts_acl_checked);
152 return frame->n_vectors;
155 VLIB_REGISTER_NODE (acl_out_node) =
157 .function = acl_out_node_fn,.name = "acl-plugin-out",.vector_size =
158 sizeof (u32),.format_trace = format_acl_out_trace,.type =
159 VLIB_NODE_TYPE_INTERNAL,.n_errors =
160 ARRAY_LEN (acl_out_error_strings),.error_strings =
161 acl_out_error_strings,.n_next_nodes = ACL_OUT_N_NEXT,
162 /* edit / add dispositions here */
165 [ACL_OUT_ERROR_DROP] = "error-drop",
166 [ACL_OUT_INTERFACE_OUTPUT] = "interface-output",
167 [ACL_OUT_L2S_OUTPUT_IP4_ADD] = "aclp-l2s-output-ip4-add",
168 [ACL_OUT_L2S_OUTPUT_IP6_ADD] = "aclp-l2s-output-ip6-add",}