4c8d104b919d92cbe4cf16b6d4d83f19ca982bce
[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 typedef struct
70 {
71   u32 next_index;
72   u32 sw_if_index;
73   u16 ethertype;
74 } nonip_in_out_trace_t;
75
76 /* packet trace format function */
77 static u8 *
78 format_nonip_in_out_trace (u8 * s, u32 is_output, va_list * args)
79 {
80   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
81   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
82   nonip_in_out_trace_t *t = va_arg (*args, nonip_in_out_trace_t *);
83
84   s = format (s, "%s: sw_if_index %d next_index %x ethertype %x",
85               is_output ? "OUT-ETHER-WHITELIST" : "IN-ETHER-WHITELIST",
86               t->sw_if_index, t->next_index, t->ethertype);
87   return s;
88 }
89
90 static u8 *
91 format_l2_nonip_in_trace (u8 * s, va_list * args)
92 {
93   return format_nonip_in_out_trace (s, 0, args);
94 }
95
96 static u8 *
97 format_l2_nonip_out_trace (u8 * s, va_list * args)
98 {
99   return format_nonip_in_out_trace (s, 1, args);
100 }
101
102 #define foreach_nonip_in_error                    \
103 _(DROP, "dropped inbound non-whitelisted non-ip packets") \
104 _(PERMIT, "permitted inbound whitelisted non-ip packets") \
105
106
107 #define foreach_nonip_out_error                    \
108 _(DROP, "dropped outbound non-whitelisted non-ip packets") \
109 _(PERMIT, "permitted outbound whitelisted non-ip packets") \
110
111
112 /* *INDENT-OFF* */
113
114 typedef enum
115 {
116 #define _(sym,str) FA_IN_NONIP_ERROR_##sym,
117   foreach_nonip_in_error
118 #undef _
119     FA_IN_NONIP_N_ERROR,
120 } l2_in_feat_arc_error_t;
121
122 static char *fa_in_nonip_error_strings[] = {
123 #define _(sym,string) string,
124   foreach_nonip_in_error
125 #undef _
126 };
127
128 typedef enum
129 {
130 #define _(sym,str) FA_OUT_NONIP_ERROR_##sym,
131   foreach_nonip_out_error
132 #undef _
133     FA_OUT_NONIP_N_ERROR,
134 } l2_out_feat_arc_error_t;
135
136 static char *fa_out_nonip_error_strings[] = {
137 #define _(sym,string) string,
138   foreach_nonip_out_error
139 #undef _
140 };
141 /* *INDENT-ON* */
142
143
144 always_inline int
145 is_permitted_ethertype (acl_main_t * am, int sw_if_index0, int is_output,
146                         u16 ethertype)
147 {
148   u16 **v = is_output
149     ? am->output_etype_whitelist_by_sw_if_index
150     : am->input_etype_whitelist_by_sw_if_index;
151   u16 *whitelist = vec_elt (v, sw_if_index0);
152   int i;
153
154   if (vec_len (whitelist) == 0)
155     return 1;
156
157   for (i = 0; i < vec_len (whitelist); i++)
158     if (whitelist[i] == ethertype)
159       return 1;
160   return 0;
161 }
162
163 #define get_u16(addr) ( *((u16 *)(addr)) )
164
165 always_inline uword
166 nonip_in_out_node_fn (vlib_main_t * vm,
167                       vlib_node_runtime_t * node, vlib_frame_t * frame,
168                       int is_output)
169 {
170   acl_main_t *am = &acl_main;
171   u32 n_left, *from;
172   u16 nexts[VLIB_FRAME_SIZE], *next;
173   vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
174   vlib_node_runtime_t *error_node;
175
176   from = vlib_frame_vector_args (frame);
177   error_node = vlib_node_get_runtime (vm, node->node_index);
178   vlib_get_buffers (vm, from, bufs, frame->n_vectors);
179   /* set the initial values for the current buffer the next pointers */
180   b = bufs;
181   next = nexts;
182
183   n_left = frame->n_vectors;
184   while (n_left > 0)
185     {
186       u32 next_index = 0;
187       u32 sw_if_index0 =
188         vnet_buffer (b[0])->sw_if_index[is_output ? VLIB_TX : VLIB_RX];
189       u16 ethertype = 0;
190
191       int error0 = 0;
192
193       ethernet_header_t *h0 = vlib_buffer_get_current (b[0]);
194       u8 *l3h0 = (u8 *) h0 + vnet_buffer (b[0])->l2.l2_len;
195       ethertype = clib_net_to_host_u16 (get_u16 (l3h0 - 2));
196
197       if (is_permitted_ethertype (am, sw_if_index0, is_output, ethertype))
198         vnet_feature_next (&next_index, b[0]);
199
200       next[0] = next_index;
201
202       if (0 == next[0])
203         b[0]->error = error_node->errors[error0];
204
205       if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
206                          && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
207         {
208           nonip_in_out_trace_t *t =
209             vlib_add_trace (vm, node, b[0], sizeof (*t));
210           t->sw_if_index = sw_if_index0;
211           t->ethertype = ethertype;
212           t->next_index = next[0];
213         }
214       next[0] = next[0] < node->n_next_nodes ? next[0] : 0;
215
216       next++;
217       b++;
218       n_left--;
219     }
220   vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
221
222   return frame->n_vectors;
223 }
224
225 VLIB_NODE_FN (acl_in_nonip_node) (vlib_main_t * vm,
226                                   vlib_node_runtime_t * node,
227                                   vlib_frame_t * frame)
228 {
229   return nonip_in_out_node_fn (vm, node, frame, 0);
230 }
231
232 VLIB_NODE_FN (acl_out_nonip_node) (vlib_main_t * vm,
233                                    vlib_node_runtime_t * node,
234                                    vlib_frame_t * frame)
235 {
236   return nonip_in_out_node_fn (vm, node, frame, 1);
237 }
238
239
240 /* *INDENT-OFF* */
241
242 VLIB_REGISTER_NODE (acl_in_nonip_node) =
243 {
244   .name = "acl-plugin-in-nonip-l2",
245   .vector_size = sizeof (u32),
246   .format_trace = format_l2_nonip_in_trace,
247   .type = VLIB_NODE_TYPE_INTERNAL,
248   .n_errors = ARRAY_LEN (fa_in_nonip_error_strings),
249   .error_strings = fa_in_nonip_error_strings,
250   .n_next_nodes = ACL_FA_N_NEXT,
251   .next_nodes =
252   {
253     [ACL_FA_ERROR_DROP] = "error-drop",
254   }
255 };
256
257 VNET_FEATURE_INIT (acl_in_l2_nonip_fa_feature, static) =
258 {
259   .arc_name = "l2-input-nonip",
260   .node_name = "acl-plugin-in-nonip-l2",
261   .runs_before = VNET_FEATURES ("l2-input-feat-arc-end"),
262 };
263
264 VLIB_REGISTER_NODE (acl_out_nonip_node) =
265 {
266   .name = "acl-plugin-out-nonip-l2",
267   .vector_size = sizeof (u32),
268   .format_trace = format_l2_nonip_out_trace,
269   .type = VLIB_NODE_TYPE_INTERNAL,
270   .n_errors = ARRAY_LEN (fa_out_nonip_error_strings),
271   .error_strings = fa_out_nonip_error_strings,
272   .n_next_nodes = ACL_FA_N_NEXT,
273   .next_nodes =
274   {
275     [ACL_FA_ERROR_DROP] = "error-drop",
276   }
277 };
278
279 VNET_FEATURE_INIT (acl_out_l2_nonip_fa_feature, static) =
280 {
281   .arc_name = "l2-output-nonip",
282   .node_name = "acl-plugin-out-nonip-l2",
283   .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"),
284 };
285
286 /* *INDENT-ON* */
287
288
289
290 always_inline u16
291 get_current_policy_epoch (acl_main_t * am, int is_input, u32 sw_if_index0)
292 {
293   u32 **p_epoch_vec =
294     is_input ? &am->input_policy_epoch_by_sw_if_index :
295     &am->output_policy_epoch_by_sw_if_index;
296   u16 current_policy_epoch =
297     sw_if_index0 < vec_len (*p_epoch_vec) ? vec_elt (*p_epoch_vec,
298                                                      sw_if_index0)
299     : (is_input * FA_POLICY_EPOCH_IS_INPUT);
300   return current_policy_epoch;
301 }
302
303 always_inline uword
304 acl_fa_node_fn (vlib_main_t * vm,
305                 vlib_node_runtime_t * node, vlib_frame_t * frame, int is_ip6,
306                 int is_input, int is_l2_path)
307 {
308   u32 n_left, *from;
309   u32 pkts_acl_checked = 0;
310   u32 pkts_new_session = 0;
311   u32 pkts_exist_session = 0;
312   u32 pkts_acl_permit = 0;
313   u32 pkts_restart_session_timer = 0;
314   u32 trace_bitmap = 0;
315   acl_main_t *am = &acl_main;
316   fa_5tuple_t fa_5tuple;
317   vlib_node_runtime_t *error_node;
318   u64 now = clib_cpu_time_now ();
319   uword thread_index = os_get_thread_index ();
320   acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
321
322   u16 nexts[VLIB_FRAME_SIZE], *next;
323   vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
324
325   from = vlib_frame_vector_args (frame);
326
327   error_node = vlib_node_get_runtime (vm, node->node_index);
328
329   vlib_get_buffers (vm, from, bufs, frame->n_vectors);
330   /* set the initial values for the current buffer the next pointers */
331   b = bufs;
332   next = nexts;
333
334   n_left = frame->n_vectors;
335   while (n_left > 0)
336     {
337       u32 next0 = 0;
338       u8 action = 0;
339       u32 sw_if_index0;
340       u32 lc_index0 = ~0;
341       int acl_check_needed = 1;
342       u32 match_acl_in_index = ~0;
343       u32 match_acl_pos = ~0;
344       u32 match_rule_index = ~0;
345       u8 error0 = 0;
346
347       n_left -= 1;
348
349       if (is_input)
350         sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_RX];
351       else
352         sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_TX];
353
354       if (is_input)
355         lc_index0 = am->input_lc_index_by_sw_if_index[sw_if_index0];
356       else
357         lc_index0 = am->output_lc_index_by_sw_if_index[sw_if_index0];
358
359       u16 current_policy_epoch =
360         get_current_policy_epoch (am, is_input, sw_if_index0);
361
362
363       /*
364        * Extract the L3/L4 matching info into a 5-tuple structure.
365        */
366
367       acl_fill_5tuple (&acl_main, sw_if_index0, b[0], is_ip6,
368                        is_input, is_l2_path, &fa_5tuple);
369
370 #ifdef FA_NODE_VERBOSE_DEBUG
371       clib_warning
372         ("ACL_FA_NODE_DBG: packet 5-tuple %016llx %016llx %016llx %016llx %016llx %016llx",
373          fa_5tuple.kv.key[0], fa_5tuple.kv.key[1], fa_5tuple.kv.key[2],
374          fa_5tuple.kv.key[3], fa_5tuple.kv.key[4], fa_5tuple.kv.value);
375 #endif
376
377       /* Try to match an existing session first */
378
379       if (acl_fa_ifc_has_sessions (am, sw_if_index0))
380         {
381           u64 value_sess = ~0ULL;
382           if (acl_fa_find_session
383               (am, is_ip6, sw_if_index0, &fa_5tuple, &value_sess)
384               && (value_sess != ~0ULL))
385             {
386               trace_bitmap |= 0x80000000;
387               error0 = ACL_FA_ERROR_ACL_EXIST_SESSION;
388               fa_full_session_id_t f_sess_id;
389
390               f_sess_id.as_u64 = value_sess;
391               ASSERT (f_sess_id.thread_index < vec_len (vlib_mains));
392
393               fa_session_t *sess =
394                 get_session_ptr (am, f_sess_id.thread_index,
395                                  f_sess_id.session_index);
396               int old_timeout_type = fa_session_get_timeout_type (am, sess);
397               action =
398                 acl_fa_track_session (am, is_input, sw_if_index0, now,
399                                       sess, &fa_5tuple);
400               /* expose the session id to the tracer */
401               match_rule_index = f_sess_id.session_index;
402               int new_timeout_type = fa_session_get_timeout_type (am, sess);
403               acl_check_needed = 0;
404               pkts_exist_session += 1;
405               /* Tracking might have changed the session timeout type, e.g. from transient to established */
406               if (PREDICT_FALSE (old_timeout_type != new_timeout_type))
407                 {
408                   acl_fa_restart_timer_for_session (am, now, f_sess_id);
409                   pkts_restart_session_timer++;
410                   trace_bitmap |=
411                     0x00010000 + ((0xff & old_timeout_type) << 8) +
412                     (0xff & new_timeout_type);
413                 }
414               /*
415                * I estimate the likelihood to be very low - the VPP needs
416                * to have >64K interfaces to start with and then on
417                * exactly 64K indices apart needs to be exactly the same
418                * 5-tuple... Anyway, since this probability is nonzero -
419                * print an error and drop the unlucky packet.
420                * If this shows up in real world, we would need to bump
421                * the hash key length.
422                */
423               if (PREDICT_FALSE (sess->sw_if_index != sw_if_index0))
424                 {
425                   clib_warning
426                     ("BUG: session LSB16(sw_if_index) and 5-tuple collision!");
427                   acl_check_needed = 0;
428                   action = 0;
429                 }
430               if (PREDICT_FALSE (am->reclassify_sessions))
431                 {
432                   /* if the MSB of policy epoch matches but not the LSB means it is a stale session */
433                   if ((0 ==
434                        ((current_policy_epoch ^
435                          f_sess_id.intf_policy_epoch) &
436                         FA_POLICY_EPOCH_IS_INPUT))
437                       && (current_policy_epoch !=
438                           f_sess_id.intf_policy_epoch))
439                     {
440                       /* delete session and increment the counter */
441                       vec_validate
442                         (pw->fa_session_epoch_change_by_sw_if_index,
443                          sw_if_index0);
444                       vec_elt (pw->fa_session_epoch_change_by_sw_if_index,
445                                sw_if_index0)++;
446                       if (acl_fa_conn_list_delete_session
447                           (am, f_sess_id, now))
448                         {
449                           /* delete the session only if we were able to unlink it */
450                           acl_fa_two_stage_delete_session (am, sw_if_index0,
451                                                            f_sess_id, now);
452                         }
453                       acl_check_needed = 1;
454                       trace_bitmap |= 0x40000000;
455                     }
456                 }
457             }
458         }
459
460       if (acl_check_needed)
461         {
462           action = 0;           /* deny by default */
463           acl_plugin_match_5tuple_inline (&acl_main, lc_index0,
464                                           (fa_5tuple_opaque_t *) &
465                                           fa_5tuple, is_ip6, &action,
466                                           &match_acl_pos,
467                                           &match_acl_in_index,
468                                           &match_rule_index, &trace_bitmap);
469           error0 = action;
470           if (1 == action)
471             pkts_acl_permit += 1;
472           if (2 == action)
473             {
474               if (!acl_fa_can_add_session (am, is_input, sw_if_index0))
475                 acl_fa_try_recycle_session (am, is_input, thread_index,
476                                             sw_if_index0, now);
477
478               if (acl_fa_can_add_session (am, is_input, sw_if_index0))
479                 {
480                   fa_session_t *sess =
481                     acl_fa_add_session (am, is_input, is_ip6,
482                                         sw_if_index0,
483                                         now, &fa_5tuple,
484                                         current_policy_epoch);
485                   acl_fa_track_session (am, is_input, sw_if_index0,
486                                         now, sess, &fa_5tuple);
487                   pkts_new_session += 1;
488                 }
489               else
490                 {
491                   action = 0;
492                   error0 = ACL_FA_ERROR_ACL_TOO_MANY_SESSIONS;
493                 }
494             }
495         }
496
497
498
499       if (action > 0)
500         {
501           vnet_feature_next (&next0, b[0]);
502         }
503 #ifdef FA_NODE_VERBOSE_DEBUG
504       clib_warning
505         ("ACL_FA_NODE_DBG: sw_if_index %d lc_index %d action %d acl_index %d rule_index %d",
506          sw_if_index0, lc_index0, action, match_acl_in_index,
507          match_rule_index);
508 #endif
509
510       if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
511                          && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
512         {
513           acl_fa_trace_t *t = vlib_add_trace (vm, node, b[0], sizeof (*t));
514           t->sw_if_index = sw_if_index0;
515           t->lc_index = lc_index0;
516           t->next_index = next0;
517           t->match_acl_in_index = match_acl_in_index;
518           t->match_rule_index = match_rule_index;
519           t->packet_info[0] = fa_5tuple.kv_40_8.key[0];
520           t->packet_info[1] = fa_5tuple.kv_40_8.key[1];
521           t->packet_info[2] = fa_5tuple.kv_40_8.key[2];
522           t->packet_info[3] = fa_5tuple.kv_40_8.key[3];
523           t->packet_info[4] = fa_5tuple.kv_40_8.key[4];
524           t->packet_info[5] = fa_5tuple.kv_40_8.value;
525           t->action = action;
526           t->trace_bitmap = trace_bitmap;
527         }
528
529       next0 = next0 < node->n_next_nodes ? next0 : 0;
530       if (0 == next0)
531         b[0]->error = error_node->errors[error0];
532       next[0] = next0;
533
534       next++;
535       b++;
536       pkts_acl_checked += 1;
537     }
538
539   vlib_buffer_enqueue_to_next (vm, node, from, nexts, frame->n_vectors);
540
541   vlib_node_increment_counter (vm, node->node_index,
542                                ACL_FA_ERROR_ACL_CHECK, pkts_acl_checked);
543   vlib_node_increment_counter (vm, node->node_index,
544                                ACL_FA_ERROR_ACL_PERMIT, pkts_acl_permit);
545   vlib_node_increment_counter (vm, node->node_index,
546                                ACL_FA_ERROR_ACL_NEW_SESSION,
547                                pkts_new_session);
548   vlib_node_increment_counter (vm, node->node_index,
549                                ACL_FA_ERROR_ACL_EXIST_SESSION,
550                                pkts_exist_session);
551   vlib_node_increment_counter (vm, node->node_index,
552                                ACL_FA_ERROR_ACL_RESTART_SESSION_TIMER,
553                                pkts_restart_session_timer);
554   return frame->n_vectors;
555 }
556
557 VLIB_NODE_FN (acl_in_l2_ip6_node) (vlib_main_t * vm,
558                                    vlib_node_runtime_t * node,
559                                    vlib_frame_t * frame)
560 {
561   return acl_fa_node_fn (vm, node, frame, 1, 1, 1);
562 }
563
564 VLIB_NODE_FN (acl_in_l2_ip4_node) (vlib_main_t * vm,
565                                    vlib_node_runtime_t * node,
566                                    vlib_frame_t * frame)
567 {
568   return acl_fa_node_fn (vm, node, frame, 0, 1, 1);
569 }
570
571 VLIB_NODE_FN (acl_out_l2_ip6_node) (vlib_main_t * vm,
572                                     vlib_node_runtime_t * node,
573                                     vlib_frame_t * frame)
574 {
575   return acl_fa_node_fn (vm, node, frame, 1, 0, 1);
576 }
577
578 VLIB_NODE_FN (acl_out_l2_ip4_node) (vlib_main_t * vm,
579                                     vlib_node_runtime_t * node,
580                                     vlib_frame_t * frame)
581 {
582   return acl_fa_node_fn (vm, node, frame, 0, 0, 1);
583 }
584
585 /**** L3 processing path nodes ****/
586
587 VLIB_NODE_FN (acl_in_fa_ip6_node) (vlib_main_t * vm,
588                                    vlib_node_runtime_t * node,
589                                    vlib_frame_t * frame)
590 {
591   return acl_fa_node_fn (vm, node, frame, 1, 1, 0);
592 }
593
594 VLIB_NODE_FN (acl_in_fa_ip4_node) (vlib_main_t * vm,
595                                    vlib_node_runtime_t * node,
596                                    vlib_frame_t * frame)
597 {
598   return acl_fa_node_fn (vm, node, frame, 0, 1, 0);
599 }
600
601 VLIB_NODE_FN (acl_out_fa_ip6_node) (vlib_main_t * vm,
602                                     vlib_node_runtime_t * node,
603                                     vlib_frame_t * frame)
604 {
605   return acl_fa_node_fn (vm, node, frame, 1, 0, 0);
606 }
607
608 VLIB_NODE_FN (acl_out_fa_ip4_node) (vlib_main_t * vm,
609                                     vlib_node_runtime_t * node,
610                                     vlib_frame_t * frame)
611 {
612   return acl_fa_node_fn (vm, node, frame, 0, 0, 0);
613 }
614
615 static u8 *
616 format_fa_5tuple (u8 * s, va_list * args)
617 {
618   fa_5tuple_t *p5t = va_arg (*args, fa_5tuple_t *);
619   void *paddr0;
620   void *paddr1;
621   void *format_address_func;
622   void *ip_af;
623   void *ip_frag_txt =
624     p5t->pkt.is_nonfirst_fragment ? " non-initial fragment" : "";
625
626   if (p5t->pkt.is_ip6)
627     {
628       ip_af = "ip6";
629       format_address_func = format_ip6_address;
630       paddr0 = &p5t->ip6_addr[0];
631       paddr1 = &p5t->ip6_addr[1];
632     }
633   else
634     {
635       ip_af = "ip4";
636       format_address_func = format_ip4_address;
637       paddr0 = &p5t->ip4_addr[0];
638       paddr1 = &p5t->ip4_addr[1];
639     }
640
641   s =
642     format (s, "lc_index %d l3 %s%s ", p5t->pkt.lc_index, ip_af, ip_frag_txt);
643   s =
644     format (s, "%U -> %U ", format_address_func, paddr0, format_address_func,
645             paddr1);
646   s = format (s, "%U ", format_fa_session_l4_key, &p5t->l4);
647   s = format (s, "tcp flags (%s) %02x rsvd %x",
648               p5t->pkt.tcp_flags_valid ? "valid" : "invalid",
649               p5t->pkt.tcp_flags, p5t->pkt.flags_reserved);
650   return s;
651 }
652
653 #ifndef CLIB_MARCH_VARIANT
654 u8 *
655 format_acl_plugin_5tuple (u8 * s, va_list * args)
656 {
657   return format_fa_5tuple (s, args);
658 }
659 #endif
660
661 /* packet trace format function */
662 static u8 *
663 format_acl_plugin_trace (u8 * s, va_list * args)
664 {
665   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
666   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
667   acl_fa_trace_t *t = va_arg (*args, acl_fa_trace_t *);
668
669   s =
670     format (s,
671             "acl-plugin: lc_index: %d, sw_if_index %d, next index %d, action: %d, match: acl %d rule %d trace_bits %08x\n"
672             "  pkt info %016llx %016llx %016llx %016llx %016llx %016llx",
673             t->lc_index, t->sw_if_index, t->next_index, t->action,
674             t->match_acl_in_index, t->match_rule_index, t->trace_bitmap,
675             t->packet_info[0], t->packet_info[1], t->packet_info[2],
676             t->packet_info[3], t->packet_info[4], t->packet_info[5]);
677
678   /* Now also print out the packet_info in a form usable by humans */
679   s = format (s, "\n   %U", format_fa_5tuple, t->packet_info);
680   return s;
681 }
682
683 /* *INDENT-OFF* */
684
685 static char *acl_fa_error_strings[] = {
686 #define _(sym,string) string,
687   foreach_acl_fa_error
688 #undef _
689 };
690
691 VLIB_REGISTER_NODE (acl_in_l2_ip6_node) =
692 {
693   .name = "acl-plugin-in-ip6-l2",
694   .vector_size = sizeof (u32),
695   .format_trace = format_acl_plugin_trace,
696   .type = VLIB_NODE_TYPE_INTERNAL,
697   .n_errors = ARRAY_LEN (acl_fa_error_strings),
698   .error_strings = acl_fa_error_strings,
699   .n_next_nodes = ACL_FA_N_NEXT,
700   .next_nodes =
701   {
702     [ACL_FA_ERROR_DROP] = "error-drop",
703   }
704 };
705
706 VNET_FEATURE_INIT (acl_in_l2_ip6_fa_feature, static) =
707 {
708   .arc_name = "l2-input-ip6",
709   .node_name = "acl-plugin-in-ip6-l2",
710   .runs_before = VNET_FEATURES ("l2-input-feat-arc-end"),
711 };
712
713 VLIB_REGISTER_NODE (acl_in_l2_ip4_node) =
714 {
715   .name = "acl-plugin-in-ip4-l2",
716   .vector_size = sizeof (u32),
717   .format_trace = format_acl_plugin_trace,
718   .type = VLIB_NODE_TYPE_INTERNAL,
719   .n_errors = ARRAY_LEN (acl_fa_error_strings),
720   .error_strings = acl_fa_error_strings,
721   .n_next_nodes = ACL_FA_N_NEXT,
722   .next_nodes =
723   {
724     [ACL_FA_ERROR_DROP] = "error-drop",
725   }
726 };
727
728 VNET_FEATURE_INIT (acl_in_l2_ip4_fa_feature, static) =
729 {
730   .arc_name = "l2-input-ip4",
731   .node_name = "acl-plugin-in-ip4-l2",
732   .runs_before = VNET_FEATURES ("l2-input-feat-arc-end"),
733 };
734
735
736 VLIB_REGISTER_NODE (acl_out_l2_ip6_node) =
737 {
738   .name = "acl-plugin-out-ip6-l2",
739   .vector_size = sizeof (u32),
740   .format_trace = format_acl_plugin_trace,
741   .type = VLIB_NODE_TYPE_INTERNAL,
742   .n_errors = ARRAY_LEN (acl_fa_error_strings),
743   .error_strings = acl_fa_error_strings,
744   .n_next_nodes = ACL_FA_N_NEXT,
745   .next_nodes =
746   {
747     [ACL_FA_ERROR_DROP] = "error-drop",
748   }
749 };
750
751 VNET_FEATURE_INIT (acl_out_l2_ip6_fa_feature, static) =
752 {
753   .arc_name = "l2-output-ip6",
754   .node_name = "acl-plugin-out-ip6-l2",
755   .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"),
756 };
757
758
759 VLIB_REGISTER_NODE (acl_out_l2_ip4_node) =
760 {
761   .name = "acl-plugin-out-ip4-l2",
762   .vector_size = sizeof (u32),
763   .format_trace = format_acl_plugin_trace,
764   .type = VLIB_NODE_TYPE_INTERNAL,
765   .n_errors = ARRAY_LEN (acl_fa_error_strings),
766   .error_strings = acl_fa_error_strings,
767   .n_next_nodes = ACL_FA_N_NEXT,
768   .next_nodes =
769   {
770     [ACL_FA_ERROR_DROP] = "error-drop",
771   }
772 };
773
774 VNET_FEATURE_INIT (acl_out_l2_ip4_fa_feature, static) =
775 {
776   .arc_name = "l2-output-ip4",
777   .node_name = "acl-plugin-out-ip4-l2",
778   .runs_before = VNET_FEATURES ("l2-output-feat-arc-end"),
779 };
780
781
782 VLIB_REGISTER_NODE (acl_in_fa_ip6_node) =
783 {
784   .name = "acl-plugin-in-ip6-fa",
785   .vector_size = sizeof (u32),
786   .format_trace = format_acl_plugin_trace,
787   .type = VLIB_NODE_TYPE_INTERNAL,
788   .n_errors = ARRAY_LEN (acl_fa_error_strings),
789   .error_strings = acl_fa_error_strings,
790   .n_next_nodes = ACL_FA_N_NEXT,
791   .next_nodes =
792   {
793     [ACL_FA_ERROR_DROP] = "error-drop",
794   }
795 };
796
797 VNET_FEATURE_INIT (acl_in_ip6_fa_feature, static) =
798 {
799   .arc_name = "ip6-unicast",
800   .node_name = "acl-plugin-in-ip6-fa",
801   .runs_before = VNET_FEATURES ("ip6-flow-classify"),
802 };
803
804 VLIB_REGISTER_NODE (acl_in_fa_ip4_node) =
805 {
806   .name = "acl-plugin-in-ip4-fa",
807   .vector_size = sizeof (u32),
808   .format_trace = format_acl_plugin_trace,
809   .type = VLIB_NODE_TYPE_INTERNAL,
810   .n_errors = ARRAY_LEN (acl_fa_error_strings),
811   .error_strings = acl_fa_error_strings,
812   .n_next_nodes = ACL_FA_N_NEXT,
813   .next_nodes =
814   {
815     [ACL_FA_ERROR_DROP] = "error-drop",
816   }
817 };
818
819 VNET_FEATURE_INIT (acl_in_ip4_fa_feature, static) =
820 {
821   .arc_name = "ip4-unicast",
822   .node_name = "acl-plugin-in-ip4-fa",
823   .runs_before = VNET_FEATURES ("ip4-flow-classify"),
824 };
825
826
827 VLIB_REGISTER_NODE (acl_out_fa_ip6_node) =
828 {
829   .name = "acl-plugin-out-ip6-fa",
830   .vector_size = sizeof (u32),
831   .format_trace = format_acl_plugin_trace,
832   .type = VLIB_NODE_TYPE_INTERNAL,
833   .n_errors = ARRAY_LEN (acl_fa_error_strings),
834   .error_strings = acl_fa_error_strings,
835   .n_next_nodes = ACL_FA_N_NEXT,
836   .next_nodes =
837   {
838     [ACL_FA_ERROR_DROP] = "error-drop",
839   }
840 };
841
842 VNET_FEATURE_INIT (acl_out_ip6_fa_feature, static) =
843 {
844   .arc_name = "ip6-output",
845   .node_name = "acl-plugin-out-ip6-fa",
846   .runs_before = VNET_FEATURES ("interface-output"),
847 };
848
849 VLIB_REGISTER_NODE (acl_out_fa_ip4_node) =
850 {
851   .name = "acl-plugin-out-ip4-fa",
852   .vector_size = sizeof (u32),
853   .format_trace = format_acl_plugin_trace,
854   .type = VLIB_NODE_TYPE_INTERNAL,
855   .n_errors = ARRAY_LEN (acl_fa_error_strings),
856   .error_strings = acl_fa_error_strings,
857   .n_next_nodes = ACL_FA_N_NEXT,
858     /* edit / add dispositions here */
859   .next_nodes =
860   {
861     [ACL_FA_ERROR_DROP] = "error-drop",
862   }
863 };
864
865 VNET_FEATURE_INIT (acl_out_ip4_fa_feature, static) =
866 {
867   .arc_name = "ip4-output",
868   .node_name = "acl-plugin-out-ip4-fa",
869   .runs_before = VNET_FEATURES ("interface-output"),
870 };
871
872 /* *INDENT-ON* */
873
874 /*
875  * fd.io coding-style-patch-verification: ON
876  *
877  * Local Variables:
878  * eval: (c-set-style "gnu")
879  * End:
880  */