Repair Doxygen build infrastructure
[vpp.git] / src / plugins / acl / node_out.c
1 /*
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:
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 <vlib/vlib.h>
16 #include <vnet/vnet.h>
17 #include <vnet/pg/pg.h>
18 #include <vppinfra/error.h>
19 #include <acl/acl.h>
20
21 #include "node_out.h"
22
23 typedef struct
24 {
25   u32 next_index;
26   u32 sw_if_index;
27   u32 match_acl_index;
28   u32 match_rule_index;
29   u32 trace_bitmap;
30 } acl_out_trace_t;
31
32 /* packet trace format function */
33 static u8 *
34 format_acl_out_trace (u8 * s, va_list * args)
35 {
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 *);
39   s =
40     format (s,
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);
44   return s;
45 }
46
47 vlib_node_registration_t acl_out_node;
48
49 #define foreach_acl_out_error \
50 _(ACL_CHECK, "OutACL check packets processed")
51
52 typedef enum
53 {
54 #define _(sym,str) ACL_OUT_ERROR_##sym,
55   foreach_acl_out_error
56 #undef _
57     ACL_OUT_N_ERROR,
58 } acl_out_error_t;
59
60 static char *acl_out_error_strings[] = {
61 #define _(sym,string) string,
62   foreach_acl_out_error
63 #undef _
64 };
65
66 static uword
67 acl_out_node_fn (vlib_main_t * vm,
68                  vlib_node_runtime_t * node, vlib_frame_t * frame)
69 {
70   acl_main_t *am = &acl_main;
71   l2_output_next_nodes_st *next_nodes = &am->acl_out_output_next_nodes;
72   u32 n_left_from, *from, *to_next;
73   acl_out_next_t next_index;
74   u32 pkts_acl_checked = 0;
75   u32 feature_bitmap0;
76   u32 cached_sw_if_index = (u32) ~ 0;
77   u32 cached_next_index = (u32) ~ 0;
78   u32 match_acl_index = ~0;
79   u32 match_rule_index = ~0;
80   u32 trace_bitmap = 0;
81
82   from = vlib_frame_vector_args (frame);
83   n_left_from = frame->n_vectors;
84   next_index = node->cached_next_index;
85
86   while (n_left_from > 0)
87     {
88       u32 n_left_to_next;
89
90       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
91
92       while (n_left_from > 0 && n_left_to_next > 0)
93         {
94           u32 bi0;
95           vlib_buffer_t *b0;
96           u32 next0 = ~0;
97           u32 next = 0;
98           u32 sw_if_index0;
99
100           /* speculatively enqueue b0 to the current next frame */
101           bi0 = from[0];
102           to_next[0] = bi0;
103           from += 1;
104           to_next += 1;
105           n_left_from -= 1;
106           n_left_to_next -= 1;
107
108           b0 = vlib_get_buffer (vm, bi0);
109
110
111           sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
112           feature_bitmap0 = vnet_buffer (b0)->l2.feature_bitmap;
113
114           output_acl_packet_match (sw_if_index0, b0, &next, &match_acl_index,
115                                    &match_rule_index, &trace_bitmap);
116           if (next != ~0)
117             {
118               next0 = next;
119             }
120           if (next0 == ~0)
121             {
122               l2_output_dispatch (vm,
123                                   am->vnet_main,
124                                   node,
125                                   acl_out_node.index,
126                                   &cached_sw_if_index,
127                                   &cached_next_index,
128                                   next_nodes,
129                                   b0, sw_if_index0, feature_bitmap0, &next0);
130             }
131
132
133
134           if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
135                              && (b0->flags & VLIB_BUFFER_IS_TRACED)))
136             {
137               acl_out_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
138               t->sw_if_index = sw_if_index0;
139               t->next_index = next0;
140               t->match_acl_index = match_acl_index;
141               t->match_rule_index = match_rule_index;
142               t->trace_bitmap = trace_bitmap;
143             }
144
145           pkts_acl_checked += 1;
146
147           /* verify speculative enqueue, maybe switch current next frame */
148           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
149                                            to_next, n_left_to_next,
150                                            bi0, next0);
151         }
152
153       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
154     }
155
156   vlib_node_increment_counter (vm, acl_out_node.index,
157                                ACL_OUT_ERROR_ACL_CHECK, pkts_acl_checked);
158   return frame->n_vectors;
159 }
160
161 VLIB_REGISTER_NODE (acl_out_node) =
162 {
163   .function = acl_out_node_fn,.name = "acl-plugin-out",.vector_size =
164     sizeof (u32),.format_trace = format_acl_out_trace,.type =
165     VLIB_NODE_TYPE_INTERNAL,.n_errors =
166     ARRAY_LEN (acl_out_error_strings),.error_strings =
167     acl_out_error_strings,.n_next_nodes = ACL_OUT_N_NEXT,
168     /* edit / add dispositions here */
169     .next_nodes =
170   {
171   [ACL_OUT_ERROR_DROP] = "error-drop",
172       [ACL_OUT_INTERFACE_OUTPUT] = "interface-output",
173       [ACL_OUT_L2S_OUTPUT_IP4_ADD] = "aclp-l2s-output-ip4-add",
174       [ACL_OUT_L2S_OUTPUT_IP6_ADD] = "aclp-l2s-output-ip6-add",}
175 ,};