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