acl-plugin: create forward and return sessions in lieu of making a special per-packet...
[vpp.git] / src / plugins / acl / dataplane_node.c
1 /*
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:
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 <stddef.h>
16 #include <netinet/in.h>
17
18 #include <vlib/vlib.h>
19 #include <vnet/vnet.h>
20 #include <vnet/pg/pg.h>
21 #include <vppinfra/error.h>
22
23
24 #include <acl/acl.h>
25 #include <vnet/ip/icmp46_packet.h>
26
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>
32
33 #include <vppinfra/bihash_40_8.h>
34 #include <vppinfra/bihash_template.h>
35
36 typedef struct
37 {
38   u32 next_index;
39   u32 sw_if_index;
40   u32 lc_index;
41   u32 match_acl_in_index;
42   u32 match_rule_index;
43   u64 packet_info[6];
44   u32 trace_bitmap;
45   u8 action;
46 } acl_fa_trace_t;
47
48 /* *INDENT-OFF* */
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") \
57 /* end  of errors */
58
59 typedef enum
60 {
61 #define _(sym,str) ACL_FA_ERROR_##sym,
62   foreach_acl_fa_error
63 #undef _
64     ACL_FA_N_ERROR,
65 } acl_fa_error_t;
66
67 /* *INDENT-ON* */
68
69
70 always_inline uword
71 acl_fa_node_fn (vlib_main_t * vm,
72                 vlib_node_runtime_t * node, vlib_frame_t * frame, int is_ip6,
73                 int is_input, int is_l2_path, u32 * l2_feat_next_node_index,
74                 vlib_node_registration_t * acl_fa_node)
75 {
76   u32 n_left_from, *from, *to_next;
77   acl_fa_next_t next_index;
78   u32 pkts_acl_checked = 0;
79   u32 pkts_new_session = 0;
80   u32 pkts_exist_session = 0;
81   u32 pkts_acl_permit = 0;
82   u32 pkts_restart_session_timer = 0;
83   u32 trace_bitmap = 0;
84   acl_main_t *am = &acl_main;
85   fa_5tuple_t fa_5tuple;
86   clib_bihash_kv_40_8_t value_sess;
87   vlib_node_runtime_t *error_node;
88   u64 now = clib_cpu_time_now ();
89   uword thread_index = os_get_thread_index ();
90   acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
91
92   from = vlib_frame_vector_args (frame);
93   n_left_from = frame->n_vectors;
94   next_index = node->cached_next_index;
95
96   error_node = vlib_node_get_runtime (vm, acl_fa_node->index);
97
98   while (n_left_from > 0)
99     {
100       u32 n_left_to_next;
101
102       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
103
104       while (n_left_from > 0 && n_left_to_next > 0)
105         {
106           u32 bi0;
107           vlib_buffer_t *b0;
108           u32 next0 = 0;
109           u8 action = 0;
110           u32 sw_if_index0;
111           u32 lc_index0;
112           int acl_check_needed = 1;
113           u32 match_acl_in_index = ~0;
114           u32 match_acl_pos = ~0;
115           u32 match_rule_index = ~0;
116           u8 error0 = 0;
117
118           /* speculatively enqueue b0 to the current next frame */
119           bi0 = from[0];
120           to_next[0] = bi0;
121           from += 1;
122           to_next += 1;
123           n_left_from -= 1;
124           n_left_to_next -= 1;
125
126           b0 = vlib_get_buffer (vm, bi0);
127
128           if (is_input)
129             sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
130           else
131             sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
132
133           if (is_input)
134             lc_index0 = am->input_lc_index_by_sw_if_index[sw_if_index0];
135           else
136             lc_index0 = am->output_lc_index_by_sw_if_index[sw_if_index0];
137
138           u32 **p_epoch_vec =
139             is_input ? &am->input_policy_epoch_by_sw_if_index :
140             &am->output_policy_epoch_by_sw_if_index;
141           u16 current_policy_epoch =
142             sw_if_index0 < vec_len (*p_epoch_vec) ? vec_elt (*p_epoch_vec,
143                                                              sw_if_index0)
144             : (is_input * FA_POLICY_EPOCH_IS_INPUT);
145           /*
146            * Extract the L3/L4 matching info into a 5-tuple structure.
147            */
148
149           acl_plugin_fill_5tuple_inline (lc_index0, b0, is_ip6, is_input,
150                                          is_l2_path,
151                                          (fa_5tuple_opaque_t *) & fa_5tuple);
152           fa_5tuple.l4.lsb_of_sw_if_index = sw_if_index0 & 0xffff;
153           fa_5tuple.pkt.mask_type_index_lsb = ~0;
154 #ifdef FA_NODE_VERBOSE_DEBUG
155           clib_warning
156             ("ACL_FA_NODE_DBG: packet 5-tuple %016llx %016llx %016llx %016llx %016llx %016llx",
157              fa_5tuple.kv.key[0], fa_5tuple.kv.key[1], fa_5tuple.kv.key[2],
158              fa_5tuple.kv.key[3], fa_5tuple.kv.key[4], fa_5tuple.kv.value);
159 #endif
160
161           /* Try to match an existing session first */
162
163           if (acl_fa_ifc_has_sessions (am, sw_if_index0))
164             {
165               if (acl_fa_find_session
166                   (am, sw_if_index0, &fa_5tuple, &value_sess))
167                 {
168                   trace_bitmap |= 0x80000000;
169                   error0 = ACL_FA_ERROR_ACL_EXIST_SESSION;
170                   fa_full_session_id_t f_sess_id;
171
172                   f_sess_id.as_u64 = value_sess.value;
173                   ASSERT (f_sess_id.thread_index < vec_len (vlib_mains));
174
175                   fa_session_t *sess =
176                     get_session_ptr (am, f_sess_id.thread_index,
177                                      f_sess_id.session_index);
178                   int old_timeout_type =
179                     fa_session_get_timeout_type (am, sess);
180                   action =
181                     acl_fa_track_session (am, is_input, sw_if_index0, now,
182                                           sess, &fa_5tuple);
183                   /* expose the session id to the tracer */
184                   match_rule_index = f_sess_id.session_index;
185                   int new_timeout_type =
186                     fa_session_get_timeout_type (am, sess);
187                   acl_check_needed = 0;
188                   pkts_exist_session += 1;
189                   /* Tracking might have changed the session timeout type, e.g. from transient to established */
190                   if (PREDICT_FALSE (old_timeout_type != new_timeout_type))
191                     {
192                       acl_fa_restart_timer_for_session (am, now, f_sess_id);
193                       pkts_restart_session_timer++;
194                       trace_bitmap |=
195                         0x00010000 + ((0xff & old_timeout_type) << 8) +
196                         (0xff & new_timeout_type);
197                     }
198                   /*
199                    * I estimate the likelihood to be very low - the VPP needs
200                    * to have >64K interfaces to start with and then on
201                    * exactly 64K indices apart needs to be exactly the same
202                    * 5-tuple... Anyway, since this probability is nonzero -
203                    * print an error and drop the unlucky packet.
204                    * If this shows up in real world, we would need to bump
205                    * the hash key length.
206                    */
207                   if (PREDICT_FALSE (sess->sw_if_index != sw_if_index0))
208                     {
209                       clib_warning
210                         ("BUG: session LSB16(sw_if_index) and 5-tuple collision!");
211                       acl_check_needed = 0;
212                       action = 0;
213                     }
214                   if (PREDICT_FALSE (am->reclassify_sessions))
215                     {
216                       /* if the MSB of policy epoch matches but not the LSB means it is a stale session */
217                       if ((0 ==
218                            ((current_policy_epoch ^
219                              f_sess_id.intf_policy_epoch) &
220                             FA_POLICY_EPOCH_IS_INPUT))
221                           && (current_policy_epoch !=
222                               f_sess_id.intf_policy_epoch))
223                         {
224                           /* delete session and increment the counter */
225                           vec_validate
226                             (pw->fa_session_epoch_change_by_sw_if_index,
227                              sw_if_index0);
228                           vec_elt (pw->fa_session_epoch_change_by_sw_if_index,
229                                    sw_if_index0)++;
230                           if (acl_fa_conn_list_delete_session (am, f_sess_id))
231                             {
232                               /* delete the session only if we were able to unlink it */
233                               acl_fa_delete_session (am, sw_if_index0,
234                                                      f_sess_id);
235                             }
236                           acl_check_needed = 1;
237                           trace_bitmap |= 0x40000000;
238                         }
239                     }
240                 }
241             }
242
243           if (acl_check_needed)
244             {
245               action = 0;       /* deny by default */
246               acl_plugin_match_5tuple_inline (lc_index0,
247                                               (fa_5tuple_opaque_t *) &
248                                               fa_5tuple, is_ip6, &action,
249                                               &match_acl_pos,
250                                               &match_acl_in_index,
251                                               &match_rule_index,
252                                               &trace_bitmap);
253               error0 = action;
254               if (1 == action)
255                 pkts_acl_permit += 1;
256               if (2 == action)
257                 {
258                   if (!acl_fa_can_add_session (am, is_input, sw_if_index0))
259                     acl_fa_try_recycle_session (am, is_input, thread_index,
260                                                 sw_if_index0);
261
262                   if (acl_fa_can_add_session (am, is_input, sw_if_index0))
263                     {
264                       fa_session_t *sess =
265                         acl_fa_add_session (am, is_input, is_ip6,
266                                             sw_if_index0,
267                                             now, &fa_5tuple,
268                                             current_policy_epoch);
269                       acl_fa_track_session (am, is_input, sw_if_index0,
270                                             now, sess, &fa_5tuple);
271                       pkts_new_session += 1;
272                     }
273                   else
274                     {
275                       action = 0;
276                       error0 = ACL_FA_ERROR_ACL_TOO_MANY_SESSIONS;
277                     }
278                 }
279             }
280
281
282
283           if (action > 0)
284             {
285               if (is_l2_path)
286                 next0 = vnet_l2_feature_next (b0, l2_feat_next_node_index, 0);
287               else
288                 vnet_feature_next (sw_if_index0, &next0, b0);
289             }
290 #ifdef FA_NODE_VERBOSE_DEBUG
291           clib_warning
292             ("ACL_FA_NODE_DBG: sw_if_index %d lc_index %d action %d acl_index %d rule_index %d",
293              sw_if_index0, lc_index0, action, match_acl_in_index,
294              match_rule_index);
295 #endif
296
297           if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
298                              && (b0->flags & VLIB_BUFFER_IS_TRACED)))
299             {
300               acl_fa_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
301               t->sw_if_index = sw_if_index0;
302               t->lc_index = lc_index0;
303               t->next_index = next0;
304               t->match_acl_in_index = match_acl_in_index;
305               t->match_rule_index = match_rule_index;
306               t->packet_info[0] = fa_5tuple.kv.key[0];
307               t->packet_info[1] = fa_5tuple.kv.key[1];
308               t->packet_info[2] = fa_5tuple.kv.key[2];
309               t->packet_info[3] = fa_5tuple.kv.key[3];
310               t->packet_info[4] = fa_5tuple.kv.key[4];
311               t->packet_info[5] = fa_5tuple.kv.value;
312               t->action = action;
313               t->trace_bitmap = trace_bitmap;
314             }
315
316           next0 = next0 < node->n_next_nodes ? next0 : 0;
317           if (0 == next0)
318             b0->error = error_node->errors[error0];
319
320           pkts_acl_checked += 1;
321
322           /* verify speculative enqueue, maybe switch current next frame */
323           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
324                                            to_next, n_left_to_next, bi0,
325                                            next0);
326         }
327
328       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
329     }
330
331   vlib_node_increment_counter (vm, acl_fa_node->index,
332                                ACL_FA_ERROR_ACL_CHECK, pkts_acl_checked);
333   vlib_node_increment_counter (vm, acl_fa_node->index,
334                                ACL_FA_ERROR_ACL_PERMIT, pkts_acl_permit);
335   vlib_node_increment_counter (vm, acl_fa_node->index,
336                                ACL_FA_ERROR_ACL_NEW_SESSION,
337                                pkts_new_session);
338   vlib_node_increment_counter (vm, acl_fa_node->index,
339                                ACL_FA_ERROR_ACL_EXIST_SESSION,
340                                pkts_exist_session);
341   vlib_node_increment_counter (vm, acl_fa_node->index,
342                                ACL_FA_ERROR_ACL_RESTART_SESSION_TIMER,
343                                pkts_restart_session_timer);
344   return frame->n_vectors;
345 }
346
347 vlib_node_function_t __clib_weak acl_in_ip4_l2_node_fn_avx512;
348 vlib_node_function_t __clib_weak acl_in_ip4_l2_node_fn_avx2;
349
350 vlib_node_function_t __clib_weak acl_out_ip4_l2_node_fn_avx512;
351 vlib_node_function_t __clib_weak acl_out_ip4_l2_node_fn_avx2;
352
353 vlib_node_function_t __clib_weak acl_in_ip6_l2_node_fn_avx512;
354 vlib_node_function_t __clib_weak acl_in_ip6_l2_node_fn_avx2;
355
356 vlib_node_function_t __clib_weak acl_out_ip6_l2_node_fn_avx512;
357 vlib_node_function_t __clib_weak acl_out_ip6_l2_node_fn_avx2;
358
359 vlib_node_function_t __clib_weak acl_in_ip4_fa_node_fn_avx512;
360 vlib_node_function_t __clib_weak acl_in_ip4_fa_node_fn_avx2;
361
362 vlib_node_function_t __clib_weak acl_out_ip4_fa_node_fn_avx512;
363 vlib_node_function_t __clib_weak acl_out_ip4_fa_node_fn_avx2;
364
365 vlib_node_function_t __clib_weak acl_in_ip6_fa_node_fn_avx512;
366 vlib_node_function_t __clib_weak acl_in_ip6_fa_node_fn_avx2;
367
368 vlib_node_function_t __clib_weak acl_out_ip6_fa_node_fn_avx512;
369 vlib_node_function_t __clib_weak acl_out_ip6_fa_node_fn_avx2;
370
371
372 vlib_node_registration_t acl_in_l2_ip6_node;
373 uword CLIB_CPU_OPTIMIZED
374 CLIB_MULTIARCH_FN (acl_in_ip6_l2_node_fn) (vlib_main_t * vm,
375                                            vlib_node_runtime_t * node,
376                                            vlib_frame_t * frame)
377 {
378   acl_main_t *am = &acl_main;
379   return acl_fa_node_fn (vm, node, frame, 1, 1, 1,
380                          am->fa_acl_in_ip6_l2_node_feat_next_node_index,
381                          &acl_in_l2_ip6_node);
382 }
383
384 vlib_node_registration_t acl_in_l2_ip4_node;
385 uword CLIB_CPU_OPTIMIZED
386 CLIB_MULTIARCH_FN (acl_in_ip4_l2_node_fn) (vlib_main_t * vm,
387                                            vlib_node_runtime_t * node,
388                                            vlib_frame_t * frame)
389 {
390   acl_main_t *am = &acl_main;
391   return acl_fa_node_fn (vm, node, frame, 0, 1, 1,
392                          am->fa_acl_in_ip4_l2_node_feat_next_node_index,
393                          &acl_in_l2_ip4_node);
394 }
395
396 vlib_node_registration_t acl_out_l2_ip6_node;
397 uword CLIB_CPU_OPTIMIZED
398 CLIB_MULTIARCH_FN (acl_out_ip6_l2_node_fn) (vlib_main_t * vm,
399                                             vlib_node_runtime_t * node,
400                                             vlib_frame_t * frame)
401 {
402   acl_main_t *am = &acl_main;
403   return acl_fa_node_fn (vm, node, frame, 1, 0, 1,
404                          am->fa_acl_out_ip6_l2_node_feat_next_node_index,
405                          &acl_out_l2_ip6_node);
406 }
407
408 vlib_node_registration_t acl_out_l2_ip4_node;
409 uword CLIB_CPU_OPTIMIZED
410 CLIB_MULTIARCH_FN (acl_out_ip4_l2_node_fn) (vlib_main_t * vm,
411                                             vlib_node_runtime_t * node,
412                                             vlib_frame_t * frame)
413 {
414   acl_main_t *am = &acl_main;
415   return acl_fa_node_fn (vm, node, frame, 0, 0, 1,
416                          am->fa_acl_out_ip4_l2_node_feat_next_node_index,
417                          &acl_out_l2_ip4_node);
418 }
419
420 /**** L3 processing path nodes ****/
421
422 vlib_node_registration_t acl_in_fa_ip6_node;
423 uword CLIB_CPU_OPTIMIZED
424 CLIB_MULTIARCH_FN (acl_in_ip6_fa_node_fn) (vlib_main_t * vm,
425                                            vlib_node_runtime_t * node,
426                                            vlib_frame_t * frame)
427 {
428   return acl_fa_node_fn (vm, node, frame, 1, 1, 0, 0, &acl_in_fa_ip6_node);
429 }
430
431 vlib_node_registration_t acl_in_fa_ip4_node;
432 uword CLIB_CPU_OPTIMIZED
433 CLIB_MULTIARCH_FN (acl_in_ip4_fa_node_fn) (vlib_main_t * vm,
434                                            vlib_node_runtime_t * node,
435                                            vlib_frame_t * frame)
436 {
437   return acl_fa_node_fn (vm, node, frame, 0, 1, 0, 0, &acl_in_fa_ip4_node);
438 }
439
440 vlib_node_registration_t acl_out_fa_ip6_node;
441 uword CLIB_CPU_OPTIMIZED
442 CLIB_MULTIARCH_FN (acl_out_ip6_fa_node_fn) (vlib_main_t * vm,
443                                             vlib_node_runtime_t * node,
444                                             vlib_frame_t * frame)
445 {
446   return acl_fa_node_fn (vm, node, frame, 1, 0, 0, 0, &acl_out_fa_ip6_node);
447 }
448
449 vlib_node_registration_t acl_out_fa_ip4_node;
450 uword CLIB_CPU_OPTIMIZED
451 CLIB_MULTIARCH_FN (acl_out_ip4_fa_node_fn) (vlib_main_t * vm,
452                                             vlib_node_runtime_t * node,
453                                             vlib_frame_t * frame)
454 {
455   return acl_fa_node_fn (vm, node, frame, 0, 0, 0, 0, &acl_out_fa_ip4_node);
456 }
457
458
459
460 #if __x86_64__
461 static void __clib_constructor
462 acl_plugin_multiarch_select (void)
463 {
464   if (acl_in_ip4_l2_node_fn_avx512 && clib_cpu_supports_avx512f ())
465     acl_in_l2_ip4_node.function = acl_in_ip4_l2_node_fn_avx512;
466   else if (acl_in_ip4_l2_node_fn_avx2 && clib_cpu_supports_avx2 ())
467     acl_in_l2_ip4_node.function = acl_in_ip4_l2_node_fn_avx2;
468
469   if (acl_out_ip4_l2_node_fn_avx512 && clib_cpu_supports_avx512f ())
470     acl_out_l2_ip4_node.function = acl_out_ip4_l2_node_fn_avx512;
471   else if (acl_out_ip4_l2_node_fn_avx2 && clib_cpu_supports_avx2 ())
472     acl_out_l2_ip4_node.function = acl_out_ip4_l2_node_fn_avx2;
473
474   if (acl_in_ip6_l2_node_fn_avx512 && clib_cpu_supports_avx512f ())
475     acl_in_l2_ip6_node.function = acl_in_ip6_l2_node_fn_avx512;
476   else if (acl_in_ip6_l2_node_fn_avx2 && clib_cpu_supports_avx2 ())
477     acl_in_l2_ip6_node.function = acl_in_ip6_l2_node_fn_avx2;
478
479   if (acl_out_ip6_l2_node_fn_avx512 && clib_cpu_supports_avx512f ())
480     acl_out_l2_ip6_node.function = acl_out_ip6_l2_node_fn_avx512;
481   else if (acl_out_ip6_l2_node_fn_avx2 && clib_cpu_supports_avx2 ())
482     acl_out_l2_ip6_node.function = acl_out_ip6_l2_node_fn_avx2;
483
484   if (acl_in_ip4_fa_node_fn_avx512 && clib_cpu_supports_avx512f ())
485     acl_in_fa_ip4_node.function = acl_in_ip4_fa_node_fn_avx512;
486   else if (acl_in_ip4_fa_node_fn_avx2 && clib_cpu_supports_avx2 ())
487     acl_in_fa_ip4_node.function = acl_in_ip4_fa_node_fn_avx2;
488
489   if (acl_out_ip4_fa_node_fn_avx512 && clib_cpu_supports_avx512f ())
490     acl_out_fa_ip4_node.function = acl_out_ip4_fa_node_fn_avx512;
491   else if (acl_out_ip4_fa_node_fn_avx2 && clib_cpu_supports_avx2 ())
492     acl_out_fa_ip4_node.function = acl_out_ip4_fa_node_fn_avx2;
493
494   if (acl_in_ip6_fa_node_fn_avx512 && clib_cpu_supports_avx512f ())
495     acl_in_fa_ip6_node.function = acl_in_ip6_fa_node_fn_avx512;
496   else if (acl_in_ip6_fa_node_fn_avx2 && clib_cpu_supports_avx2 ())
497     acl_in_fa_ip6_node.function = acl_in_ip6_fa_node_fn_avx2;
498
499   if (acl_out_ip6_fa_node_fn_avx512 && clib_cpu_supports_avx512f ())
500     acl_out_fa_ip6_node.function = acl_out_ip6_fa_node_fn_avx512;
501   else if (acl_out_ip6_fa_node_fn_avx2 && clib_cpu_supports_avx2 ())
502     acl_out_fa_ip6_node.function = acl_out_ip6_fa_node_fn_avx2;
503
504 }
505 #endif
506
507
508
509 #ifndef CLIB_MULTIARCH_VARIANT
510 static u8 *
511 format_fa_5tuple (u8 * s, va_list * args)
512 {
513   fa_5tuple_t *p5t = va_arg (*args, fa_5tuple_t *);
514
515   return format (s, "lc_index %d (lsb16 of sw_if_index %d) l3 %s%s %U -> %U"
516                  " l4 proto %d l4_valid %d port %d -> %d tcp flags (%s) %02x rsvd %x",
517                  p5t->pkt.lc_index, p5t->l4.lsb_of_sw_if_index,
518                  p5t->pkt.is_ip6 ? "ip6" : "ip4",
519                  p5t->pkt.is_nonfirst_fragment ? " non-initial fragment" : "",
520                  format_ip46_address, &p5t->addr[0],
521                  p5t->pkt.is_ip6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
522                  format_ip46_address, &p5t->addr[1],
523                  p5t->pkt.is_ip6 ? IP46_TYPE_IP6 : IP46_TYPE_IP4,
524                  p5t->l4.proto, p5t->pkt.l4_valid, p5t->l4.port[0],
525                  p5t->l4.port[1],
526                  p5t->pkt.tcp_flags_valid ? "valid" : "invalid",
527                  p5t->pkt.tcp_flags, p5t->pkt.flags_reserved);
528 }
529
530 u8 *
531 format_acl_plugin_5tuple (u8 * s, va_list * args)
532 {
533   return format_fa_5tuple (s, args);
534 }
535
536 /* packet trace format function */
537 u8 *
538 format_acl_plugin_trace (u8 * s, va_list * args)
539 {
540   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
541   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
542   acl_fa_trace_t *t = va_arg (*args, acl_fa_trace_t *);
543
544   s =
545     format (s,
546             "acl-plugin: lc_index: %d, sw_if_index %d, next index %d, action: %d, match: acl %d rule %d trace_bits %08x\n"
547             "  pkt info %016llx %016llx %016llx %016llx %016llx %016llx",
548             t->lc_index, t->sw_if_index, t->next_index, t->action,
549             t->match_acl_in_index, t->match_rule_index, t->trace_bitmap,
550             t->packet_info[0], t->packet_info[1], t->packet_info[2],
551             t->packet_info[3], t->packet_info[4], t->packet_info[5]);
552
553   /* Now also print out the packet_info in a form usable by humans */
554   s = format (s, "\n   %U", format_fa_5tuple, t->packet_info);
555   return s;
556 }
557
558
559 /* *INDENT-OFF* */
560
561 static char *acl_fa_error_strings[] = {
562 #define _(sym,string) string,
563   foreach_acl_fa_error
564 #undef _
565 };
566
567 VLIB_REGISTER_NODE (acl_in_l2_ip6_node) =
568 {
569   .function = acl_in_ip6_l2_node_fn,
570   .name = "acl-plugin-in-ip6-l2",
571   .vector_size = sizeof (u32),
572   .format_trace = format_acl_plugin_trace,
573   .type = VLIB_NODE_TYPE_INTERNAL,
574   .n_errors = ARRAY_LEN (acl_fa_error_strings),
575   .error_strings = acl_fa_error_strings,
576   .n_next_nodes = ACL_FA_N_NEXT,
577   .next_nodes =
578   {
579     [ACL_FA_ERROR_DROP] = "error-drop",
580   }
581 };
582
583 VLIB_REGISTER_NODE (acl_in_l2_ip4_node) =
584 {
585   .function = acl_in_ip4_l2_node_fn,
586   .name = "acl-plugin-in-ip4-l2",
587   .vector_size = sizeof (u32),
588   .format_trace = format_acl_plugin_trace,
589   .type = VLIB_NODE_TYPE_INTERNAL,
590   .n_errors = ARRAY_LEN (acl_fa_error_strings),
591   .error_strings = acl_fa_error_strings,
592   .n_next_nodes = ACL_FA_N_NEXT,
593   .next_nodes =
594   {
595     [ACL_FA_ERROR_DROP] = "error-drop",
596   }
597 };
598
599 VLIB_REGISTER_NODE (acl_out_l2_ip6_node) =
600 {
601   .function = acl_out_ip6_l2_node_fn,
602   .name = "acl-plugin-out-ip6-l2",
603   .vector_size = sizeof (u32),
604   .format_trace = format_acl_plugin_trace,
605   .type = VLIB_NODE_TYPE_INTERNAL,
606   .n_errors = ARRAY_LEN (acl_fa_error_strings),
607   .error_strings = acl_fa_error_strings,
608   .n_next_nodes = ACL_FA_N_NEXT,
609   .next_nodes =
610   {
611     [ACL_FA_ERROR_DROP] = "error-drop",
612   }
613 };
614
615 VLIB_REGISTER_NODE (acl_out_l2_ip4_node) =
616 {
617   .function = acl_out_ip4_l2_node_fn,
618   .name = "acl-plugin-out-ip4-l2",
619   .vector_size = sizeof (u32),
620   .format_trace = format_acl_plugin_trace,
621   .type = VLIB_NODE_TYPE_INTERNAL,
622   .n_errors = ARRAY_LEN (acl_fa_error_strings),
623   .error_strings = acl_fa_error_strings,
624   .n_next_nodes = ACL_FA_N_NEXT,
625   .next_nodes =
626   {
627     [ACL_FA_ERROR_DROP] = "error-drop",
628   }
629 };
630
631
632 VLIB_REGISTER_NODE (acl_in_fa_ip6_node) =
633 {
634   .function = acl_in_ip6_fa_node_fn,
635   .name = "acl-plugin-in-ip6-fa",
636   .vector_size = sizeof (u32),
637   .format_trace = format_acl_plugin_trace,
638   .type = VLIB_NODE_TYPE_INTERNAL,
639   .n_errors = ARRAY_LEN (acl_fa_error_strings),
640   .error_strings = acl_fa_error_strings,
641   .n_next_nodes = ACL_FA_N_NEXT,
642   .next_nodes =
643   {
644     [ACL_FA_ERROR_DROP] = "error-drop",
645   }
646 };
647
648 VNET_FEATURE_INIT (acl_in_ip6_fa_feature, static) =
649 {
650   .arc_name = "ip6-unicast",
651   .node_name = "acl-plugin-in-ip6-fa",
652   .runs_before = VNET_FEATURES ("ip6-flow-classify"),
653 };
654
655 VLIB_REGISTER_NODE (acl_in_fa_ip4_node) =
656 {
657   .function = acl_in_ip4_fa_node_fn,
658   .name = "acl-plugin-in-ip4-fa",
659   .vector_size = sizeof (u32),
660   .format_trace = format_acl_plugin_trace,
661   .type = VLIB_NODE_TYPE_INTERNAL,
662   .n_errors = ARRAY_LEN (acl_fa_error_strings),
663   .error_strings = acl_fa_error_strings,
664   .n_next_nodes = ACL_FA_N_NEXT,
665   .next_nodes =
666   {
667     [ACL_FA_ERROR_DROP] = "error-drop",
668   }
669 };
670
671 VNET_FEATURE_INIT (acl_in_ip4_fa_feature, static) =
672 {
673   .arc_name = "ip4-unicast",
674   .node_name = "acl-plugin-in-ip4-fa",
675   .runs_before = VNET_FEATURES ("ip4-flow-classify"),
676 };
677
678
679 VLIB_REGISTER_NODE (acl_out_fa_ip6_node) =
680 {
681   .function = acl_out_ip6_fa_node_fn,
682   .name = "acl-plugin-out-ip6-fa",
683   .vector_size = sizeof (u32),
684   .format_trace = format_acl_plugin_trace,
685   .type = VLIB_NODE_TYPE_INTERNAL,
686   .n_errors = ARRAY_LEN (acl_fa_error_strings),
687   .error_strings = acl_fa_error_strings,
688   .n_next_nodes = ACL_FA_N_NEXT,
689   .next_nodes =
690   {
691     [ACL_FA_ERROR_DROP] = "error-drop",
692   }
693 };
694
695 VNET_FEATURE_INIT (acl_out_ip6_fa_feature, static) =
696 {
697   .arc_name = "ip6-output",
698   .node_name = "acl-plugin-out-ip6-fa",
699   .runs_before = VNET_FEATURES ("interface-output"),
700 };
701
702 VLIB_REGISTER_NODE (acl_out_fa_ip4_node) =
703 {
704   .function = acl_out_ip4_fa_node_fn,
705   .name = "acl-plugin-out-ip4-fa",
706   .vector_size = sizeof (u32),
707   .format_trace = format_acl_plugin_trace,
708   .type = VLIB_NODE_TYPE_INTERNAL,
709   .n_errors = ARRAY_LEN (acl_fa_error_strings),
710   .error_strings = acl_fa_error_strings,
711   .n_next_nodes = ACL_FA_N_NEXT,
712     /* edit / add dispositions here */
713   .next_nodes =
714   {
715     [ACL_FA_ERROR_DROP] = "error-drop",
716   }
717 };
718
719 VNET_FEATURE_INIT (acl_out_ip4_fa_feature, static) =
720 {
721   .arc_name = "ip4-output",
722   .node_name = "acl-plugin-out-ip4-fa",
723   .runs_before = VNET_FEATURES ("interface-output"),
724 };
725 #endif
726
727 /* *INDENT-ON* */
728
729 /*
730  * fd.io coding-style-patch-verification: ON
731  *
732  * Local Variables:
733  * eval: (c-set-style "gnu")
734  * End:
735  */