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