acl-plugin: make the ACL plugin multicore-capable
[vpp.git] / src / plugins / acl / fa_node.c
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include <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 #include <acl/acl.h>
23 #include "bihash_40_8.h"
24
25 #include <vppinfra/bihash_template.h>
26 #include <vppinfra/bihash_template.c>
27
28 #include "fa_node.h"
29
30 typedef struct
31 {
32   u32 next_index;
33   u32 sw_if_index;
34   u32 match_acl_in_index;
35   u32 match_rule_index;
36   u64 packet_info[6];
37   u32 trace_bitmap;
38   u8 action;
39 } acl_fa_trace_t;
40
41 /* packet trace format function */
42 static u8 *
43 format_acl_fa_trace (u8 * s, va_list * args)
44 {
45   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
46   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
47   acl_fa_trace_t *t = va_arg (*args, acl_fa_trace_t *);
48
49   s =
50     format (s,
51             "acl-plugin: sw_if_index %d, next index %d, action: %d, match: acl %d rule %d trace_bits %08x\n"
52             "  pkt info %016llx %016llx %016llx %016llx %016llx %016llx",
53             t->sw_if_index, t->next_index, t->action, t->match_acl_in_index,
54             t->match_rule_index, t->trace_bitmap,
55             t->packet_info[0], t->packet_info[1], t->packet_info[2],
56             t->packet_info[3], t->packet_info[4], t->packet_info[5]);
57   return s;
58 }
59
60 /* *INDENT-OFF* */
61 #define foreach_acl_fa_error \
62 _(ACL_DROP, "ACL deny packets")  \
63 _(ACL_PERMIT, "ACL permit packets")  \
64 _(ACL_NEW_SESSION, "new sessions added") \
65 _(ACL_EXIST_SESSION, "existing session packets") \
66 _(ACL_CHECK, "checked packets") \
67 _(ACL_RESTART_SESSION_TIMER, "restart session timer") \
68 _(ACL_TOO_MANY_SESSIONS, "too many sessions to add new") \
69 /* end  of errors */
70
71 typedef enum
72 {
73 #define _(sym,str) ACL_FA_ERROR_##sym,
74   foreach_acl_fa_error
75 #undef _
76     ACL_FA_N_ERROR,
77 } acl_fa_error_t;
78
79 static char *acl_fa_error_strings[] = {
80 #define _(sym,string) string,
81   foreach_acl_fa_error
82 #undef _
83 };
84 /* *INDENT-ON* */
85
86 static void *
87 get_ptr_to_offset (vlib_buffer_t * b0, int offset)
88 {
89   u8 *p = vlib_buffer_get_current (b0) + offset;
90   return p;
91 }
92
93
94 static int
95 fa_acl_match_addr (ip46_address_t * addr1, ip46_address_t * addr2,
96                    int prefixlen, int is_ip6)
97 {
98   if (prefixlen == 0)
99     {
100       /* match any always succeeds */
101       return 1;
102     }
103   if (is_ip6)
104     {
105       if (memcmp (addr1, addr2, prefixlen / 8))
106         {
107           /* If the starting full bytes do not match, no point in bittwidling the thumbs further */
108           return 0;
109         }
110       if (prefixlen % 8)
111         {
112           u8 b1 = *((u8 *) addr1 + 1 + prefixlen / 8);
113           u8 b2 = *((u8 *) addr2 + 1 + prefixlen / 8);
114           u8 mask0 = (0xff - ((1 << (8 - (prefixlen % 8))) - 1));
115           return (b1 & mask0) == b2;
116         }
117       else
118         {
119           /* The prefix fits into integer number of bytes, so nothing left to do */
120           return 1;
121         }
122     }
123   else
124     {
125       uint32_t a1 = ntohl (addr1->ip4.as_u32);
126       uint32_t a2 = ntohl (addr2->ip4.as_u32);
127       uint32_t mask0 = 0xffffffff - ((1 << (32 - prefixlen)) - 1);
128       return (a1 & mask0) == a2;
129     }
130 }
131
132 static int
133 fa_acl_match_port (u16 port, u16 port_first, u16 port_last, int is_ip6)
134 {
135   return ((port >= port_first) && (port <= port_last));
136 }
137
138 int
139 acl_match_5tuple (acl_main_t * am, u32 acl_index, fa_5tuple_t * pkt_5tuple,
140                   int is_ip6, u8 * r_action, u32 * r_acl_match_p,
141                   u32 * r_rule_match_p, u32 * trace_bitmap)
142 {
143   int i;
144   acl_list_t *a;
145   acl_rule_t *r;
146
147   if (pool_is_free_index (am->acls, acl_index))
148     {
149       if (r_acl_match_p)
150         *r_acl_match_p = acl_index;
151       if (r_rule_match_p)
152         *r_rule_match_p = -1;
153       /* the ACL does not exist but is used for policy. Block traffic. */
154       return 0;
155     }
156   a = am->acls + acl_index;
157   for (i = 0; i < a->count; i++)
158     {
159       r = a->rules + i;
160       if (is_ip6 != r->is_ipv6)
161         {
162           continue;
163         }
164       if (!fa_acl_match_addr
165           (&pkt_5tuple->addr[1], &r->dst, r->dst_prefixlen, is_ip6))
166         continue;
167
168 #ifdef FA_NODE_VERBOSE_DEBUG
169       clib_warning
170         ("ACL_FA_NODE_DBG acl %d rule %d pkt dst addr %U match rule addr %U/%d",
171          acl_index, i, format_ip46_address, &pkt_5tuple->addr[1],
172          IP46_TYPE_ANY, format_ip46_address, &r->dst, IP46_TYPE_ANY,
173          r->dst_prefixlen);
174 #endif
175
176       if (!fa_acl_match_addr
177           (&pkt_5tuple->addr[0], &r->src, r->src_prefixlen, is_ip6))
178         continue;
179
180 #ifdef FA_NODE_VERBOSE_DEBUG
181       clib_warning
182         ("ACL_FA_NODE_DBG acl %d rule %d pkt src addr %U match rule addr %U/%d",
183          acl_index, i, format_ip46_address, &pkt_5tuple->addr[0],
184          IP46_TYPE_ANY, format_ip46_address, &r->src, IP46_TYPE_ANY,
185          r->src_prefixlen);
186       clib_warning
187         ("ACL_FA_NODE_DBG acl %d rule %d trying to match pkt proto %d with rule %d",
188          acl_index, i, pkt_5tuple->l4.proto, r->proto);
189 #endif
190       if (r->proto)
191         {
192           if (pkt_5tuple->l4.proto != r->proto)
193             continue;
194
195           if (PREDICT_FALSE (pkt_5tuple->pkt.is_nonfirst_fragment &&
196                      am->l4_match_nonfirst_fragment))
197           {
198             /* non-initial fragment with frag match configured - match this rule */
199             *trace_bitmap |= 0x80000000;
200             *r_action = r->is_permit;
201             if (r_acl_match_p)
202               *r_acl_match_p = acl_index;
203             if (r_rule_match_p)
204               *r_rule_match_p = i;
205             return 1;
206           }
207
208           /* A sanity check just to ensure we are about to match the ports extracted from the packet */
209           if (PREDICT_FALSE (!pkt_5tuple->pkt.l4_valid))
210             continue;
211
212 #ifdef FA_NODE_VERBOSE_DEBUG
213           clib_warning
214             ("ACL_FA_NODE_DBG acl %d rule %d pkt proto %d match rule %d",
215              acl_index, i, pkt_5tuple->l4.proto, r->proto);
216 #endif
217
218           if (!fa_acl_match_port
219               (pkt_5tuple->l4.port[0], r->src_port_or_type_first,
220                r->src_port_or_type_last, is_ip6))
221             continue;
222
223 #ifdef FA_NODE_VERBOSE_DEBUG
224           clib_warning
225             ("ACL_FA_NODE_DBG acl %d rule %d pkt sport %d match rule [%d..%d]",
226              acl_index, i, pkt_5tuple->l4.port[0], r->src_port_or_type_first,
227              r->src_port_or_type_last);
228 #endif
229
230           if (!fa_acl_match_port
231               (pkt_5tuple->l4.port[1], r->dst_port_or_code_first,
232                r->dst_port_or_code_last, is_ip6))
233             continue;
234
235 #ifdef FA_NODE_VERBOSE_DEBUG
236           clib_warning
237             ("ACL_FA_NODE_DBG acl %d rule %d pkt dport %d match rule [%d..%d]",
238              acl_index, i, pkt_5tuple->l4.port[1], r->dst_port_or_code_first,
239              r->dst_port_or_code_last);
240 #endif
241           if (pkt_5tuple->pkt.tcp_flags_valid
242               && ((pkt_5tuple->pkt.tcp_flags & r->tcp_flags_mask) !=
243                   r->tcp_flags_value))
244             continue;
245         }
246       /* everything matches! */
247 #ifdef FA_NODE_VERBOSE_DEBUG
248       clib_warning ("ACL_FA_NODE_DBG acl %d rule %d FULL-MATCH, action %d",
249                     acl_index, i, r->is_permit);
250 #endif
251       *r_action = r->is_permit;
252       if (r_acl_match_p)
253         *r_acl_match_p = acl_index;
254       if (r_rule_match_p)
255         *r_rule_match_p = i;
256       return 1;
257     }
258   return 0;
259 }
260
261 static u8
262 full_acl_match_5tuple (u32 sw_if_index, fa_5tuple_t * pkt_5tuple, int is_l2,
263                        int is_ip6, int is_input, u32 * acl_match_p,
264                        u32 * rule_match_p, u32 * trace_bitmap)
265 {
266   acl_main_t *am = &acl_main;
267   int i;
268   u32 *acl_vector;
269   u8 action = 0;
270
271   if (is_input)
272     {
273       vec_validate (am->input_acl_vec_by_sw_if_index, sw_if_index);
274       acl_vector = am->input_acl_vec_by_sw_if_index[sw_if_index];
275     }
276   else
277     {
278       vec_validate (am->output_acl_vec_by_sw_if_index, sw_if_index);
279       acl_vector = am->output_acl_vec_by_sw_if_index[sw_if_index];
280     }
281   for (i = 0; i < vec_len (acl_vector); i++)
282     {
283 #ifdef FA_NODE_VERBOSE_DEBUG
284       clib_warning ("ACL_FA_NODE_DBG: Trying to match ACL: %d",
285                     acl_vector[i]);
286 #endif
287       if (acl_match_5tuple
288           (am, acl_vector[i], pkt_5tuple, is_ip6, &action,
289            acl_match_p, rule_match_p, trace_bitmap))
290         {
291           return action;
292         }
293     }
294   if (vec_len (acl_vector) > 0)
295     {
296       /* If there are ACLs and none matched, deny by default */
297       return 0;
298     }
299 #ifdef FA_NODE_VERBOSE_DEBUG
300   clib_warning ("ACL_FA_NODE_DBG: No ACL on sw_if_index %d", sw_if_index);
301 #endif
302   /* Deny by default. If there are no ACLs defined we should not be here. */
303   return 0;
304 }
305
306 static int
307 offset_within_packet (vlib_buffer_t * b0, int offset)
308 {
309   /* For the purposes of this code, "within" means we have at least 8 bytes after it */
310   return (offset <= (b0->current_length - 8));
311 }
312
313 static void
314 acl_fill_5tuple (acl_main_t * am, vlib_buffer_t * b0, int is_ip6,
315                  int is_input, int is_l2_path, fa_5tuple_t * p5tuple_pkt)
316 {
317   int l3_offset = 14;
318   int l4_offset;
319   u16 ports[2];
320   u16 proto;
321   /* IP4 and IP6 protocol numbers of ICMP */
322   static u8 icmp_protos[] = { IP_PROTOCOL_ICMP, IP_PROTOCOL_ICMP6 };
323
324   if (is_input && !(is_l2_path))
325     {
326       l3_offset = 0;
327     }
328
329   /* key[0..3] contains src/dst address and is cleared/set below */
330   /* Remainder of the key and per-packet non-key data */
331   p5tuple_pkt->kv.key[4] = 0;
332   p5tuple_pkt->kv.value = 0;
333
334   if (is_ip6)
335     {
336       clib_memcpy (&p5tuple_pkt->addr,
337                    get_ptr_to_offset (b0,
338                                       offsetof (ip6_header_t,
339                                                 src_address) + l3_offset),
340                    sizeof (p5tuple_pkt->addr));
341       proto =
342         *(u8 *) get_ptr_to_offset (b0,
343                                    offsetof (ip6_header_t,
344                                              protocol) + l3_offset);
345       l4_offset = l3_offset + sizeof (ip6_header_t);
346 #ifdef FA_NODE_VERBOSE_DEBUG
347       clib_warning ("ACL_FA_NODE_DBG: proto: %d, l4_offset: %d", proto,
348                     l4_offset);
349 #endif
350       /* IP6 EH handling is here, increment l4_offset if needs to, update the proto */
351       int need_skip_eh = clib_bitmap_get (am->fa_ipv6_known_eh_bitmap, proto);
352       if (PREDICT_FALSE (need_skip_eh))
353         {
354           while (need_skip_eh && offset_within_packet (b0, l4_offset))
355             {
356               /* Fragment header needs special handling */
357               if (PREDICT_FALSE(ACL_EH_FRAGMENT == proto))
358                 {
359                   proto = *(u8 *) get_ptr_to_offset (b0, l4_offset);
360                   u16 frag_offset;
361                   clib_memcpy (&frag_offset, get_ptr_to_offset (b0, 2 + l4_offset), sizeof(frag_offset));
362                   frag_offset = ntohs(frag_offset) >> 3;
363                   if (frag_offset)
364                     {
365                       p5tuple_pkt->pkt.is_nonfirst_fragment = 1;
366                       /* invalidate L4 offset so we don't try to find L4 info */
367                       l4_offset += b0->current_length;
368                     }
369                   else
370                     {
371                       /* First fragment: skip the frag header and move on. */
372                       l4_offset += 8;
373                     }
374                 }
375               else
376                 {
377                   u8 nwords = *(u8 *) get_ptr_to_offset (b0, 1 + l4_offset);
378                   proto = *(u8 *) get_ptr_to_offset (b0, l4_offset);
379                   l4_offset += 8 * (1 + (u16) nwords);
380                 }
381 #ifdef FA_NODE_VERBOSE_DEBUG
382               clib_warning ("ACL_FA_NODE_DBG: new proto: %d, new offset: %d",
383                             proto, l4_offset);
384 #endif
385               need_skip_eh =
386                 clib_bitmap_get (am->fa_ipv6_known_eh_bitmap, proto);
387             }
388         }
389     }
390   else
391     {
392       p5tuple_pkt->kv.key[0] = 0;
393       p5tuple_pkt->kv.key[1] = 0;
394       p5tuple_pkt->kv.key[2] = 0;
395       p5tuple_pkt->kv.key[3] = 0;
396       clib_memcpy (&p5tuple_pkt->addr[0].ip4,
397                    get_ptr_to_offset (b0,
398                                       offsetof (ip4_header_t,
399                                                 src_address) + l3_offset),
400                    sizeof (p5tuple_pkt->addr[0].ip4));
401       clib_memcpy (&p5tuple_pkt->addr[1].ip4,
402                    get_ptr_to_offset (b0,
403                                       offsetof (ip4_header_t,
404                                                 dst_address) + l3_offset),
405                    sizeof (p5tuple_pkt->addr[1].ip4));
406       proto =
407         *(u8 *) get_ptr_to_offset (b0,
408                                    offsetof (ip4_header_t,
409                                              protocol) + l3_offset);
410       l4_offset = l3_offset + sizeof (ip4_header_t);
411       u16 flags_and_fragment_offset;
412       clib_memcpy (&flags_and_fragment_offset,
413                    get_ptr_to_offset (b0,
414                                       offsetof (ip4_header_t,
415                                                 flags_and_fragment_offset)) + l3_offset,
416                                                 sizeof(flags_and_fragment_offset));
417       flags_and_fragment_offset = ntohs (flags_and_fragment_offset);
418
419       /* non-initial fragments have non-zero offset */
420       if ((PREDICT_FALSE(0xfff & flags_and_fragment_offset)))
421         {
422           p5tuple_pkt->pkt.is_nonfirst_fragment = 1;
423           /* invalidate L4 offset so we don't try to find L4 info */
424           l4_offset += b0->current_length;
425         }
426
427     }
428   p5tuple_pkt->l4.proto = proto;
429   if (PREDICT_TRUE (offset_within_packet (b0, l4_offset)))
430     {
431       p5tuple_pkt->pkt.l4_valid = 1;
432       if (icmp_protos[is_ip6] == proto)
433         {
434           /* type */
435           p5tuple_pkt->l4.port[0] =
436             *(u8 *) get_ptr_to_offset (b0,
437                                        l4_offset + offsetof (icmp46_header_t,
438                                                              type));
439           /* code */
440           p5tuple_pkt->l4.port[1] =
441             *(u8 *) get_ptr_to_offset (b0,
442                                        l4_offset + offsetof (icmp46_header_t,
443                                                              code));
444         }
445       else if ((IPPROTO_TCP == proto) || (IPPROTO_UDP == proto))
446         {
447           clib_memcpy (&ports,
448                        get_ptr_to_offset (b0,
449                                           l4_offset + offsetof (tcp_header_t,
450                                                                 src_port)),
451                        sizeof (ports));
452           p5tuple_pkt->l4.port[0] = ntohs (ports[0]);
453           p5tuple_pkt->l4.port[1] = ntohs (ports[1]);
454
455           p5tuple_pkt->pkt.tcp_flags =
456             *(u8 *) get_ptr_to_offset (b0,
457                                        l4_offset + offsetof (tcp_header_t,
458                                                              flags));
459           p5tuple_pkt->pkt.tcp_flags_valid = (proto == IPPROTO_TCP);
460         }
461       /*
462        * FIXME: rather than the above conditional, here could
463        * be a nice generic mechanism to extract two L4 values:
464        *
465        * have a per-protocol array of 4 elements like this:
466        *   u8 offset; to take the byte from, off L4 header
467        *   u8 mask; to mask it with, before storing
468        *
469        * this way we can describe UDP, TCP and ICMP[46] semantics,
470        * and add a sort of FPM-type behavior for other protocols.
471        *
472        * Of course, is it faster ? and is it needed ?
473        *
474        */
475     }
476 }
477
478
479 /* Session keys match the packets received, and mirror the packets sent */
480 static void
481 acl_make_5tuple_session_key (int is_input, fa_5tuple_t * p5tuple_pkt,
482                              fa_5tuple_t * p5tuple_sess)
483 {
484   int src_index = is_input ? 0 : 1;
485   int dst_index = is_input ? 1 : 0;
486   p5tuple_sess->addr[src_index] = p5tuple_pkt->addr[0];
487   p5tuple_sess->addr[dst_index] = p5tuple_pkt->addr[1];
488   p5tuple_sess->l4.as_u64 = p5tuple_pkt->l4.as_u64;
489   p5tuple_sess->l4.port[src_index] = p5tuple_pkt->l4.port[0];
490   p5tuple_sess->l4.port[dst_index] = p5tuple_pkt->l4.port[1];
491 }
492
493
494 static int
495 acl_fa_ifc_has_sessions (acl_main_t * am, int sw_if_index0)
496 {
497   int has_sessions =
498     clib_bitmap_get (am->fa_sessions_on_sw_if_index, sw_if_index0);
499   return has_sessions;
500 }
501
502 static int
503 acl_fa_ifc_has_in_acl (acl_main_t * am, int sw_if_index0)
504 {
505   int it_has = clib_bitmap_get (am->fa_in_acl_on_sw_if_index, sw_if_index0);
506   return it_has;
507 }
508
509 static int
510 acl_fa_ifc_has_out_acl (acl_main_t * am, int sw_if_index0)
511 {
512   int it_has = clib_bitmap_get (am->fa_out_acl_on_sw_if_index, sw_if_index0);
513   return it_has;
514 }
515
516
517 static int
518 fa_session_get_timeout_type (acl_main_t * am, fa_session_t * sess)
519 {
520   /* seen both SYNs and ACKs but not FINs means we are in establshed state */
521   u16 masked_flags =
522     sess->tcp_flags_seen.as_u16 & ((TCP_FLAGS_RSTFINACKSYN << 8) +
523                                    TCP_FLAGS_RSTFINACKSYN);
524   switch (sess->info.l4.proto)
525     {
526     case IPPROTO_TCP:
527       if (((TCP_FLAGS_ACKSYN << 8) + TCP_FLAGS_ACKSYN) == masked_flags)
528         {
529           return ACL_TIMEOUT_TCP_IDLE;
530         }
531       else
532         {
533           return ACL_TIMEOUT_TCP_TRANSIENT;
534         }
535       break;
536     case IPPROTO_UDP:
537       return ACL_TIMEOUT_UDP_IDLE;
538       break;
539     default:
540       return ACL_TIMEOUT_UDP_IDLE;
541     }
542 }
543
544
545 static u64
546 fa_session_get_shortest_timeout(acl_main_t * am)
547 {
548   int timeout_type;
549   u64 timeout = ~0LL;
550   for(timeout_type = 0; timeout_type < ACL_N_TIMEOUTS; timeout_type++) {
551     if (timeout > am->session_timeout_sec[timeout_type]) {
552       timeout = am->session_timeout_sec[timeout_type];
553     }
554   }
555   return timeout;
556 }
557
558 /*
559  * Get the timeout of the session in a list since its enqueue time.
560  */
561
562 static u64
563 fa_session_get_list_timeout (acl_main_t * am, fa_session_t * sess)
564 {
565   u64 timeout = am->vlib_main->clib_time.clocks_per_second;
566   /*
567    * we have the shortest possible timeout type in all the lists
568    * (see README-multicore for the rationale)
569    */
570   timeout *= fa_session_get_shortest_timeout(am);
571   return timeout;
572 }
573
574 /*
575  * Get the idle timeout of a session.
576  */
577
578 static u64
579 fa_session_get_timeout (acl_main_t * am, fa_session_t * sess)
580 {
581   u64 timeout = am->vlib_main->clib_time.clocks_per_second;
582   int timeout_type = fa_session_get_timeout_type (am, sess);
583   timeout *= am->session_timeout_sec[timeout_type];
584   return timeout;
585 }
586
587 static void
588 acl_fa_ifc_init_sessions (acl_main_t * am, int sw_if_index0)
589 {
590   /// FIXME-MULTICORE: lock around this function
591 #ifdef FA_NODE_VERBOSE_DEBUG
592   clib_warning
593     ("Initializing bihash for sw_if_index %d num buckets %lu memory size %llu",
594      sw_if_index0, am->fa_conn_table_hash_num_buckets,
595      am->fa_conn_table_hash_memory_size);
596 #endif
597   vec_validate (am->fa_sessions_by_sw_if_index, sw_if_index0);
598   BV (clib_bihash_init) (&am->fa_sessions_by_sw_if_index
599                          [sw_if_index0], "ACL plugin FA session bihash",
600                          am->fa_conn_table_hash_num_buckets,
601                          am->fa_conn_table_hash_memory_size);
602   am->fa_sessions_on_sw_if_index =
603     clib_bitmap_set (am->fa_sessions_on_sw_if_index, sw_if_index0, 1);
604 }
605
606 static inline fa_session_t *get_session_ptr(acl_main_t *am, u16 thread_index, u32 session_index)
607 {
608   acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
609   fa_session_t *sess = pw->fa_sessions_pool + session_index;
610   return sess;
611 }
612
613 static void
614 acl_fa_conn_list_add_session (acl_main_t * am, fa_full_session_id_t sess_id, u64 now)
615 {
616   fa_session_t *sess = get_session_ptr(am, sess_id.thread_index, sess_id.session_index);
617   u8 list_id = fa_session_get_timeout_type(am, sess);
618   uword thread_index = os_get_thread_index ();
619   acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
620   /* the retrieved session thread index must be necessarily the same as the one in the key */
621   ASSERT (sess->thread_index == sess_id.thread_index);
622   /* the retrieved session thread index must be the same as current thread */
623   ASSERT (sess->thread_index == thread_index);
624   sess->link_enqueue_time = now;
625   sess->link_list_id = list_id;
626   sess->link_next_idx = ~0;
627   sess->link_prev_idx = pw->fa_conn_list_tail[list_id];
628   if (~0 != pw->fa_conn_list_tail[list_id]) {
629     fa_session_t *prev_sess = get_session_ptr(am, thread_index, pw->fa_conn_list_tail[list_id]);
630     prev_sess->link_next_idx = sess_id.session_index;
631     /* We should never try to link with a session on another thread */
632     ASSERT(prev_sess->thread_index == sess->thread_index);
633   }
634   pw->fa_conn_list_tail[list_id] = sess_id.session_index;
635   pw->serviced_sw_if_index_bitmap = clib_bitmap_set(pw->serviced_sw_if_index_bitmap, sess->sw_if_index, 1);
636
637   if (~0 == pw->fa_conn_list_head[list_id]) {
638     pw->fa_conn_list_head[list_id] = sess_id.session_index;
639     /* If it is a first conn in any list, kick the cleaner */
640     vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
641                                  ACL_FA_CLEANER_RESCHEDULE, 0);
642   }
643 }
644
645 static int
646 acl_fa_conn_list_delete_session (acl_main_t *am, fa_full_session_id_t sess_id)
647 {
648   uword thread_index = os_get_thread_index ();
649   acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
650   if (thread_index != sess_id.thread_index) {
651     /* If another thread attempts to delete the session, fail it. */
652 #ifdef FA_NODE_VERBOSE_DEBUG
653     clib_warning("thread id in key %d != curr thread index, not deleting");
654 #endif
655     return 0;
656   }
657   fa_session_t *sess = get_session_ptr(am, sess_id.thread_index, sess_id.session_index);
658   /* we should never try to delete the session with another thread index */
659   ASSERT(sess->thread_index == thread_index);
660   if (~0 != sess->link_prev_idx) {
661     fa_session_t *prev_sess = get_session_ptr(am, thread_index, sess->link_prev_idx);
662     /* the previous session must be in the same list as this one */
663     ASSERT(prev_sess->link_list_id == sess->link_list_id);
664     prev_sess->link_next_idx = sess->link_next_idx;
665   }
666   if (~0 != sess->link_next_idx) {
667     fa_session_t *next_sess = get_session_ptr(am, thread_index, sess->link_next_idx);
668     /* The next session must be in the same list as the one we are deleting */
669     ASSERT(next_sess->link_list_id == sess->link_list_id);
670     next_sess->link_prev_idx = sess->link_prev_idx;
671   }
672   if (pw->fa_conn_list_head[sess->link_list_id] == sess_id.session_index) {
673     pw->fa_conn_list_head[sess->link_list_id] = sess->link_next_idx;
674   }
675   if (pw->fa_conn_list_tail[sess->link_list_id] == sess_id.session_index) {
676     pw->fa_conn_list_tail[sess->link_list_id] = sess->link_prev_idx;
677   }
678   return 1;
679 }
680
681 static int
682 acl_fa_restart_timer_for_session (acl_main_t * am, u64 now, fa_full_session_id_t sess_id)
683 {
684   if (acl_fa_conn_list_delete_session(am, sess_id)) {
685     acl_fa_conn_list_add_session(am, sess_id, now);
686     return 1;
687   } else {
688     /*
689      * Our thread does not own this connection, so we can not delete
690      * The session. To avoid the complicated signaling, we simply
691      * pick the list waiting time to be the shortest of the timeouts.
692      * This way we do not have to do anything special, and let
693      * the regular requeue check take care of everything.
694      */
695     return 0;
696   }
697 }
698
699
700 static u8
701 acl_fa_track_session (acl_main_t * am, int is_input, u32 sw_if_index, u64 now,
702                       fa_session_t * sess, fa_5tuple_t * pkt_5tuple)
703 {
704   sess->last_active_time = now;
705   if (pkt_5tuple->pkt.tcp_flags_valid)
706     {
707       sess->tcp_flags_seen.as_u8[is_input] |= pkt_5tuple->pkt.tcp_flags;
708     }
709   return 3;
710 }
711
712
713 static void
714 acl_fa_delete_session (acl_main_t * am, u32 sw_if_index, fa_full_session_id_t sess_id)
715 {
716   fa_session_t *sess = get_session_ptr(am, sess_id.thread_index, sess_id.session_index);
717   ASSERT(sess->thread_index == os_get_thread_index ());
718   BV (clib_bihash_add_del) (&am->fa_sessions_by_sw_if_index[sw_if_index],
719                             &sess->info.kv, 0);
720   acl_fa_per_worker_data_t *pw = &am->per_worker_data[sess_id.thread_index];
721   pool_put_index (pw->fa_sessions_pool, sess_id.session_index);
722   /* Deleting from timer structures not needed,
723      as the caller must have dealt with the timers. */
724   vec_validate (am->fa_session_dels_by_sw_if_index, sw_if_index);
725   am->fa_session_dels_by_sw_if_index[sw_if_index]++;
726 }
727
728 static int
729 acl_fa_can_add_session (acl_main_t * am, int is_input, u32 sw_if_index)
730 {
731   u64 curr_sess;
732   vec_validate (am->fa_session_adds_by_sw_if_index, sw_if_index);
733   vec_validate (am->fa_session_dels_by_sw_if_index, sw_if_index);
734   curr_sess =
735     am->fa_session_adds_by_sw_if_index[sw_if_index] -
736     am->fa_session_dels_by_sw_if_index[sw_if_index];
737   return (curr_sess < am->fa_conn_table_max_entries);
738 }
739
740 static u64
741 acl_fa_get_list_head_expiry_time(acl_main_t *am, acl_fa_per_worker_data_t *pw, u64 now, u16 thread_index, int timeout_type)
742 {
743   if (~0 == pw->fa_conn_list_head[timeout_type]) {
744     return ~0LL; // infinity.
745   } else {
746     fa_session_t *sess = get_session_ptr(am, thread_index, pw->fa_conn_list_head[timeout_type]);
747     u64 timeout_time =
748               sess->link_enqueue_time + fa_session_get_list_timeout (am, sess);
749     return timeout_time;
750   }
751 }
752
753 static int
754 acl_fa_conn_time_to_check (acl_main_t *am, acl_fa_per_worker_data_t *pw, u64 now, u16 thread_index, u32 session_index)
755 {
756   fa_session_t *sess = get_session_ptr(am, thread_index, session_index);
757   u64 timeout_time =
758               sess->link_enqueue_time + fa_session_get_list_timeout (am, sess);
759   return (timeout_time < now) || (sess->link_enqueue_time <= pw->swipe_end_time);
760 }
761
762 /*
763  * see if there are sessions ready to be checked,
764  * do the maintenance (requeue or delete), and
765  * return the total number of sessions reclaimed.
766  */
767 static int
768 acl_fa_check_idle_sessions(acl_main_t *am, u16 thread_index, u64 now)
769 {
770   acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
771   fa_full_session_id_t fsid;
772   fsid.thread_index = thread_index;
773   int total_expired = 0;
774
775   {
776     u8 tt = 0;
777     for(tt = 0; tt < ACL_N_TIMEOUTS; tt++) {
778       while((vec_len(pw->expired) < am->fa_max_deleted_sessions_per_interval)
779             && (~0 != pw->fa_conn_list_head[tt])
780             && (acl_fa_conn_time_to_check(am, pw, now, thread_index,
781                                           pw->fa_conn_list_head[tt]))) {
782         fsid.session_index = pw->fa_conn_list_head[tt];
783         vec_add1(pw->expired, fsid.session_index);
784         acl_fa_conn_list_delete_session(am, fsid);
785       }
786     }
787   }
788
789   u32 *psid = NULL;
790   vec_foreach (psid, pw->expired)
791   {
792     fsid.session_index = *psid;
793     if (!pool_is_free_index (pw->fa_sessions_pool, fsid.session_index))
794       {
795         fa_session_t *sess = get_session_ptr(am, thread_index, fsid.session_index);
796         u32 sw_if_index = sess->sw_if_index;
797         u64 sess_timeout_time =
798           sess->last_active_time + fa_session_get_timeout (am, sess);
799         if ((now < sess_timeout_time) && (0 == clib_bitmap_get(pw->pending_clear_sw_if_index_bitmap, sw_if_index)))
800           {
801 #ifdef FA_NODE_VERBOSE_DEBUG
802             clib_warning ("ACL_FA_NODE_CLEAN: Restarting timer for session %d",
803                (int) session_index);
804 #endif
805             /* There was activity on the session, so the idle timeout
806                has not passed. Enqueue for another time period. */
807
808             acl_fa_conn_list_add_session(am, fsid, now);
809             pw->cnt_session_timer_restarted++;
810           }
811         else
812           {
813 #ifdef FA_NODE_VERBOSE_DEBUG
814             clib_warning ("ACL_FA_NODE_CLEAN: Deleting session %d",
815                (int) session_index);
816 #endif
817             acl_fa_delete_session (am, sw_if_index, fsid);
818             pw->cnt_deleted_sessions++;
819           }
820       }
821     else
822       {
823         pw->cnt_already_deleted_sessions++;
824       }
825   }
826   total_expired = vec_len(pw->expired);
827   /* zero out the vector which we have acted on */
828   if (pw->expired)
829     _vec_len (pw->expired) = 0;
830   /* if we were advancing and reached the end
831    * (no more sessions to recycle), reset the fast-forward timestamp */
832
833   if (pw->swipe_end_time && 0 == total_expired)
834     pw->swipe_end_time = 0;
835   return (total_expired);
836 }
837
838 always_inline void
839 acl_fa_try_recycle_session (acl_main_t * am, int is_input, u16 thread_index, u32 sw_if_index)
840 {
841   /* try to recycle a TCP transient session */
842   acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
843   u8 timeout_type = ACL_TIMEOUT_TCP_TRANSIENT;
844   fa_full_session_id_t sess_id;
845   sess_id.session_index = pw->fa_conn_list_head[timeout_type];
846   if (~0 != sess_id.session_index) {
847     sess_id.thread_index = thread_index;
848     acl_fa_conn_list_delete_session(am, sess_id);
849     acl_fa_delete_session(am, sw_if_index, sess_id);
850   }
851 }
852
853 static void
854 acl_fa_add_session (acl_main_t * am, int is_input, u32 sw_if_index, u64 now,
855                     fa_5tuple_t * p5tuple)
856 {
857   clib_bihash_kv_40_8_t *pkv = &p5tuple->kv;
858   clib_bihash_kv_40_8_t kv;
859   fa_full_session_id_t f_sess_id;
860   uword thread_index = os_get_thread_index();
861   acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
862
863   f_sess_id.thread_index = thread_index;
864   fa_session_t *sess;
865
866   pool_get_aligned (pw->fa_sessions_pool, sess, CLIB_CACHE_LINE_BYTES);
867   f_sess_id.session_index = sess - pw->fa_sessions_pool;
868
869   kv.key[0] = pkv->key[0];
870   kv.key[1] = pkv->key[1];
871   kv.key[2] = pkv->key[2];
872   kv.key[3] = pkv->key[3];
873   kv.key[4] = pkv->key[4];
874   kv.value = f_sess_id.as_u64;
875
876   memcpy (sess, pkv, sizeof (pkv->key));
877   sess->last_active_time = now;
878   sess->sw_if_index = sw_if_index;
879   sess->tcp_flags_seen.as_u16 = 0;
880   sess->thread_index = thread_index;
881   sess->link_list_id = ~0;
882   sess->link_prev_idx = ~0;
883   sess->link_next_idx = ~0;
884
885
886
887   if (!acl_fa_ifc_has_sessions (am, sw_if_index))
888     {
889       acl_fa_ifc_init_sessions (am, sw_if_index);
890     }
891
892   BV (clib_bihash_add_del) (&am->fa_sessions_by_sw_if_index[sw_if_index],
893                             &kv, 1);
894   acl_fa_conn_list_add_session(am, f_sess_id, now);
895
896   vec_validate (am->fa_session_adds_by_sw_if_index, sw_if_index);
897   am->fa_session_adds_by_sw_if_index[sw_if_index]++;
898 }
899
900 static int
901 acl_fa_find_session (acl_main_t * am, u32 sw_if_index0, fa_5tuple_t * p5tuple,
902                      clib_bihash_kv_40_8_t * pvalue_sess)
903 {
904   return (BV (clib_bihash_search)
905           (&am->fa_sessions_by_sw_if_index[sw_if_index0], &p5tuple->kv,
906            pvalue_sess) == 0);
907 }
908
909
910 always_inline uword
911 acl_fa_node_fn (vlib_main_t * vm,
912                 vlib_node_runtime_t * node, vlib_frame_t * frame, int is_ip6,
913                 int is_input, int is_l2_path, u32 * l2_feat_next_node_index,
914                 vlib_node_registration_t * acl_fa_node)
915 {
916   u32 n_left_from, *from, *to_next;
917   acl_fa_next_t next_index;
918   u32 pkts_acl_checked = 0;
919   u32 pkts_new_session = 0;
920   u32 pkts_exist_session = 0;
921   u32 pkts_acl_permit = 0;
922   u32 pkts_restart_session_timer = 0;
923   u32 trace_bitmap = 0;
924   u32 feature_bitmap0;
925   acl_main_t *am = &acl_main;
926   fa_5tuple_t fa_5tuple, kv_sess;
927   clib_bihash_kv_40_8_t value_sess;
928   vlib_node_runtime_t *error_node;
929   u64 now = clib_cpu_time_now ();
930   uword thread_index = os_get_thread_index ();
931
932   from = vlib_frame_vector_args (frame);
933   n_left_from = frame->n_vectors;
934   next_index = node->cached_next_index;
935
936   error_node = vlib_node_get_runtime (vm, acl_fa_node->index);
937
938   while (n_left_from > 0)
939     {
940       u32 n_left_to_next;
941
942       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
943
944       while (n_left_from > 0 && n_left_to_next > 0)
945         {
946           u32 bi0;
947           vlib_buffer_t *b0;
948           u32 next0 = 0;
949           u8 action = 0;
950           u32 sw_if_index0;
951           int acl_check_needed = 1;
952           u32 match_acl_in_index = ~0;
953           u32 match_rule_index = ~0;
954           u8 error0 = 0;
955
956           /* speculatively enqueue b0 to the current next frame */
957           bi0 = from[0];
958           to_next[0] = bi0;
959           from += 1;
960           to_next += 1;
961           n_left_from -= 1;
962           n_left_to_next -= 1;
963
964           b0 = vlib_get_buffer (vm, bi0);
965
966           if (is_input)
967             sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
968           else
969             sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_TX];
970           if (is_l2_path)
971             feature_bitmap0 = vnet_buffer (b0)->l2.feature_bitmap;
972
973           /*
974            * Extract the L3/L4 matching info into a 5-tuple structure,
975            * then create a session key whose layout is independent on forward or reverse
976            * direction of the packet.
977            */
978
979           acl_fill_5tuple (am, b0, is_ip6, is_input, is_l2_path, &fa_5tuple);
980           acl_make_5tuple_session_key (is_input, &fa_5tuple, &kv_sess);
981 #ifdef FA_NODE_VERBOSE_DEBUG
982           clib_warning
983             ("ACL_FA_NODE_DBG: session 5-tuple %016llx %016llx %016llx %016llx %016llx : %016llx",
984              kv_sess.kv.key[0], kv_sess.kv.key[1], kv_sess.kv.key[2],
985              kv_sess.kv.key[3], kv_sess.kv.key[4], kv_sess.kv.value);
986           clib_warning
987             ("ACL_FA_NODE_DBG: packet 5-tuple %016llx %016llx %016llx %016llx %016llx : %016llx",
988              fa_5tuple.kv.key[0], fa_5tuple.kv.key[1], fa_5tuple.kv.key[2],
989              fa_5tuple.kv.key[3], fa_5tuple.kv.key[4], fa_5tuple.kv.value);
990 #endif
991
992           /* Try to match an existing session first */
993
994           if (acl_fa_ifc_has_sessions (am, sw_if_index0))
995             {
996               if (acl_fa_find_session
997                   (am, sw_if_index0, &kv_sess, &value_sess))
998                 {
999                   trace_bitmap |= 0x80000000;
1000                   error0 = ACL_FA_ERROR_ACL_EXIST_SESSION;
1001                   fa_full_session_id_t f_sess_id;
1002
1003                   f_sess_id.as_u64 = value_sess.value;
1004                   ASSERT(f_sess_id.thread_index < vec_len(vlib_mains));
1005
1006                   fa_session_t *sess = get_session_ptr(am, f_sess_id.thread_index, f_sess_id.session_index);
1007                   int old_timeout_type =
1008                     fa_session_get_timeout_type (am, sess);
1009                   action =
1010                     acl_fa_track_session (am, is_input, sw_if_index0, now,
1011                                           sess, &fa_5tuple);
1012                   /* expose the session id to the tracer */
1013                   match_rule_index = f_sess_id.session_index;
1014                   int new_timeout_type =
1015                     fa_session_get_timeout_type (am, sess);
1016                   acl_check_needed = 0;
1017                   pkts_exist_session += 1;
1018                   /* Tracking might have changed the session timeout type, e.g. from transient to established */
1019                   if (PREDICT_FALSE (old_timeout_type != new_timeout_type))
1020                     {
1021                       acl_fa_restart_timer_for_session (am, now, f_sess_id);
1022                       pkts_restart_session_timer++;
1023                       trace_bitmap |=
1024                         0x00010000 + ((0xff & old_timeout_type) << 8) +
1025                         (0xff & new_timeout_type);
1026                     }
1027                 }
1028             }
1029
1030           if (acl_check_needed)
1031             {
1032               action =
1033                 full_acl_match_5tuple (sw_if_index0, &fa_5tuple, is_l2_path,
1034                                        is_ip6, is_input, &match_acl_in_index,
1035                                        &match_rule_index, &trace_bitmap);
1036               error0 = action;
1037               if (1 == action)
1038                 pkts_acl_permit += 1;
1039               if (2 == action)
1040                 {
1041                   if (!acl_fa_can_add_session (am, is_input, sw_if_index0))
1042                     acl_fa_try_recycle_session (am, is_input, thread_index, sw_if_index0);
1043
1044                   if (acl_fa_can_add_session (am, is_input, sw_if_index0))
1045                     {
1046                       acl_fa_add_session (am, is_input, sw_if_index0, now,
1047                                           &kv_sess);
1048                       pkts_new_session += 1;
1049                     }
1050                   else
1051                     {
1052                       action = 0;
1053                       error0 = ACL_FA_ERROR_ACL_TOO_MANY_SESSIONS;
1054                     }
1055                 }
1056             }
1057
1058
1059
1060           if (action > 0)
1061             {
1062               if (is_l2_path)
1063                 next0 =
1064                   feat_bitmap_get_next_node_index (l2_feat_next_node_index,
1065                                                    feature_bitmap0);
1066               else
1067                 vnet_feature_next (sw_if_index0, &next0, b0);
1068             }
1069
1070           if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1071                              && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1072             {
1073               acl_fa_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
1074               t->sw_if_index = sw_if_index0;
1075               t->next_index = next0;
1076               t->match_acl_in_index = match_acl_in_index;
1077               t->match_rule_index = match_rule_index;
1078               t->packet_info[0] = fa_5tuple.kv.key[0];
1079               t->packet_info[1] = fa_5tuple.kv.key[1];
1080               t->packet_info[2] = fa_5tuple.kv.key[2];
1081               t->packet_info[3] = fa_5tuple.kv.key[3];
1082               t->packet_info[4] = fa_5tuple.kv.key[4];
1083               t->packet_info[5] = fa_5tuple.kv.value;
1084               t->action = action;
1085               t->trace_bitmap = trace_bitmap;
1086             }
1087
1088           next0 = next0 < node->n_next_nodes ? next0 : 0;
1089           if (0 == next0)
1090             b0->error = error_node->errors[error0];
1091
1092           pkts_acl_checked += 1;
1093
1094           /* verify speculative enqueue, maybe switch current next frame */
1095           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1096                                            to_next, n_left_to_next, bi0,
1097                                            next0);
1098         }
1099
1100       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1101     }
1102
1103   vlib_node_increment_counter (vm, acl_fa_node->index,
1104                                ACL_FA_ERROR_ACL_CHECK, pkts_acl_checked);
1105   vlib_node_increment_counter (vm, acl_fa_node->index,
1106                                ACL_FA_ERROR_ACL_PERMIT, pkts_acl_permit);
1107   vlib_node_increment_counter (vm, acl_fa_node->index,
1108                                ACL_FA_ERROR_ACL_NEW_SESSION,
1109                                pkts_new_session);
1110   vlib_node_increment_counter (vm, acl_fa_node->index,
1111                                ACL_FA_ERROR_ACL_EXIST_SESSION,
1112                                pkts_exist_session);
1113   vlib_node_increment_counter (vm, acl_fa_node->index,
1114                                ACL_FA_ERROR_ACL_RESTART_SESSION_TIMER,
1115                                pkts_restart_session_timer);
1116   return frame->n_vectors;
1117 }
1118
1119
1120 vlib_node_registration_t acl_in_l2_ip6_node;
1121 static uword
1122 acl_in_ip6_l2_node_fn (vlib_main_t * vm,
1123                        vlib_node_runtime_t * node, vlib_frame_t * frame)
1124 {
1125   acl_main_t *am = &acl_main;
1126   return acl_fa_node_fn (vm, node, frame, 1, 1, 1,
1127                          am->fa_acl_in_ip6_l2_node_feat_next_node_index,
1128                          &acl_in_l2_ip6_node);
1129 }
1130
1131 vlib_node_registration_t acl_in_l2_ip4_node;
1132 static uword
1133 acl_in_ip4_l2_node_fn (vlib_main_t * vm,
1134                        vlib_node_runtime_t * node, vlib_frame_t * frame)
1135 {
1136   acl_main_t *am = &acl_main;
1137   return acl_fa_node_fn (vm, node, frame, 0, 1, 1,
1138                          am->fa_acl_in_ip4_l2_node_feat_next_node_index,
1139                          &acl_in_l2_ip4_node);
1140 }
1141
1142 vlib_node_registration_t acl_out_l2_ip6_node;
1143 static uword
1144 acl_out_ip6_l2_node_fn (vlib_main_t * vm,
1145                         vlib_node_runtime_t * node, vlib_frame_t * frame)
1146 {
1147   acl_main_t *am = &acl_main;
1148   return acl_fa_node_fn (vm, node, frame, 1, 0, 1,
1149                          am->fa_acl_out_ip6_l2_node_feat_next_node_index,
1150                          &acl_out_l2_ip6_node);
1151 }
1152
1153 vlib_node_registration_t acl_out_l2_ip4_node;
1154 static uword
1155 acl_out_ip4_l2_node_fn (vlib_main_t * vm,
1156                         vlib_node_runtime_t * node, vlib_frame_t * frame)
1157 {
1158   acl_main_t *am = &acl_main;
1159   return acl_fa_node_fn (vm, node, frame, 0, 0, 1,
1160                          am->fa_acl_out_ip4_l2_node_feat_next_node_index,
1161                          &acl_out_l2_ip4_node);
1162 }
1163
1164
1165 /**** L3 processing path nodes ****/
1166
1167
1168 vlib_node_registration_t acl_in_fa_ip6_node;
1169 static uword
1170 acl_in_ip6_fa_node_fn (vlib_main_t * vm,
1171                        vlib_node_runtime_t * node, vlib_frame_t * frame)
1172 {
1173   return acl_fa_node_fn (vm, node, frame, 1, 1, 0, 0, &acl_in_fa_ip6_node);
1174 }
1175
1176 vlib_node_registration_t acl_in_fa_ip4_node;
1177 static uword
1178 acl_in_ip4_fa_node_fn (vlib_main_t * vm,
1179                        vlib_node_runtime_t * node, vlib_frame_t * frame)
1180 {
1181   return acl_fa_node_fn (vm, node, frame, 0, 1, 0, 0, &acl_in_fa_ip4_node);
1182 }
1183
1184 vlib_node_registration_t acl_out_fa_ip6_node;
1185 static uword
1186 acl_out_ip6_fa_node_fn (vlib_main_t * vm,
1187                         vlib_node_runtime_t * node, vlib_frame_t * frame)
1188 {
1189   return acl_fa_node_fn (vm, node, frame, 1, 0, 0, 0, &acl_out_fa_ip6_node);
1190 }
1191
1192 vlib_node_registration_t acl_out_fa_ip4_node;
1193 static uword
1194 acl_out_ip4_fa_node_fn (vlib_main_t * vm,
1195                         vlib_node_runtime_t * node, vlib_frame_t * frame)
1196 {
1197   return acl_fa_node_fn (vm, node, frame, 0, 0, 0, 0, &acl_out_fa_ip4_node);
1198 }
1199
1200 /*
1201  * This process ensures the connection cleanup happens every so often
1202  * even in absence of traffic, as well as provides general orchestration
1203  * for requests like connection deletion on a given sw_if_index.
1204  */
1205
1206
1207 /* *INDENT-OFF* */
1208 #define foreach_acl_fa_cleaner_error \
1209 _(UNKNOWN_EVENT, "unknown event received")  \
1210 /* end  of errors */
1211
1212 typedef enum
1213 {
1214 #define _(sym,str) ACL_FA_CLEANER_ERROR_##sym,
1215   foreach_acl_fa_cleaner_error
1216 #undef _
1217     ACL_FA_CLEANER_N_ERROR,
1218 } acl_fa_cleaner_error_t;
1219
1220 static char *acl_fa_cleaner_error_strings[] = {
1221 #define _(sym,string) string,
1222   foreach_acl_fa_cleaner_error
1223 #undef _
1224 };
1225
1226 /* *INDENT-ON* */
1227
1228 static vlib_node_registration_t acl_fa_session_cleaner_process_node;
1229 static vlib_node_registration_t acl_fa_worker_session_cleaner_process_node;
1230
1231 /*
1232  * Per-worker thread interrupt-driven cleaner thread
1233  * to clean idle connections if there are no packets
1234  */
1235 static uword
1236 acl_fa_worker_conn_cleaner_process(vlib_main_t * vm,
1237               vlib_node_runtime_t * rt, vlib_frame_t * f)
1238 {
1239    acl_main_t *am = &acl_main;
1240    u64 now = clib_cpu_time_now ();
1241    u16 thread_index = os_get_thread_index ();
1242    acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
1243    int num_expired;
1244 #ifdef FA_NODE_VERBOSE_DEBUG
1245    clib_warning("\nacl_fa_worker_conn_cleaner: thread index %d now %lu\n\n", thread_index, now);
1246 #endif
1247    /* allow another interrupt to be queued */
1248    pw->interrupt_is_pending = 0;
1249    if (pw->clear_in_process) {
1250      if (0 == pw->swipe_end_time) {
1251        /*
1252         * Someone has just set the flag to start clearing.
1253         * we do this by combing through the connections up to a "time T"
1254         * which is now, and requeueing everything except the expired
1255         * connections and those matching the interface(s) being cleared.
1256         */
1257
1258        /*
1259         * first filter the sw_if_index bitmap that they want from us, by
1260         * a bitmap of sw_if_index for which we actually have connections.
1261         */
1262        if ((pw->pending_clear_sw_if_index_bitmap == 0)
1263            || (pw->serviced_sw_if_index_bitmap == 0)) {
1264 #ifdef FA_NODE_VERBOSE_DEBUG
1265          clib_warning("WORKER-CLEAR: someone tried to call clear, but one of the bitmaps are empty");
1266 #endif
1267          clib_bitmap_zero(pw->pending_clear_sw_if_index_bitmap);
1268        } else {
1269 #ifdef FA_NODE_VERBOSE_DEBUG
1270          clib_warning("WORKER-CLEAR: (before and) swiping sw-if-index bitmap: %U, my serviced bitmap %U",
1271                       format_bitmap_hex, pw->pending_clear_sw_if_index_bitmap,
1272                       format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
1273 #endif
1274          pw->pending_clear_sw_if_index_bitmap = clib_bitmap_and(pw->pending_clear_sw_if_index_bitmap,
1275                                                               pw->serviced_sw_if_index_bitmap);
1276        }
1277
1278        if (clib_bitmap_is_zero(pw->pending_clear_sw_if_index_bitmap)) {
1279          /* if the cross-section is a zero vector, no need to do anything. */
1280          clib_warning("WORKER: clearing done - nothing to do");
1281          pw->clear_in_process = 0;
1282        } else {
1283 #ifdef FA_NODE_VERBOSE_DEBUG
1284          clib_warning("WORKER-CLEAR: swiping sw-if-index bitmap: %U, my serviced bitmap %U",
1285                       format_bitmap_hex, pw->pending_clear_sw_if_index_bitmap,
1286                       format_bitmap_hex, pw->serviced_sw_if_index_bitmap);
1287 #endif
1288          /* swipe through the connection lists until enqueue timestamps become above "now" */
1289          pw->swipe_end_time = now;
1290        }
1291      }
1292    }
1293    num_expired = acl_fa_check_idle_sessions(am, thread_index, now);
1294    // clib_warning("WORKER-CLEAR: checked %d sessions (clear_in_progress: %d)", num_expired, pw->clear_in_process);
1295    if (pw->clear_in_process) {
1296      if (0 == num_expired) {
1297        /* we were clearing but we could not process any more connections. time to stop. */
1298        clib_bitmap_zero(pw->pending_clear_sw_if_index_bitmap);
1299        pw->clear_in_process = 0;
1300 #ifdef FA_NODE_VERBOSE_DEBUG
1301        clib_warning("WORKER: clearing done, all done");
1302 #endif
1303      } else {
1304 #ifdef FA_NODE_VERBOSE_DEBUG
1305        clib_warning("WORKER-CLEAR: more work to do, raising interrupt");
1306 #endif
1307        /* should continue clearing.. So could they please sent an interrupt again? */
1308        pw->interrupt_is_needed = 1;
1309      }
1310    } else {
1311      if (num_expired >= am->fa_max_deleted_sessions_per_interval) {
1312        /* there was too much work, we should get an interrupt ASAP */
1313        pw->interrupt_is_needed = 1;
1314      } else if (num_expired <= am->fa_min_deleted_sessions_per_interval) {
1315        /* signal that they should trigger us less */
1316        pw->interrupt_is_unwanted = 1;
1317      } else {
1318        /* the current rate of interrupts is ok */
1319        pw->interrupt_is_needed = 0;
1320        pw->interrupt_is_unwanted = 0;
1321      }
1322    }
1323    return 0;
1324 }
1325
1326 static void
1327 send_one_worker_interrupt (vlib_main_t * vm, acl_main_t *am, int thread_index)
1328 {
1329   acl_fa_per_worker_data_t *pw = &am->per_worker_data[thread_index];
1330   if (!pw->interrupt_is_pending) {
1331     vlib_node_set_interrupt_pending (vlib_mains[thread_index],
1332                   acl_fa_worker_session_cleaner_process_node.index);
1333     pw->interrupt_is_pending = 1;
1334     /* if the interrupt was requested, mark that done. */
1335     pw->interrupt_is_needed = 0;
1336   }
1337 }
1338
1339 static void
1340 send_interrupts_to_workers (vlib_main_t * vm, acl_main_t *am)
1341 {
1342   int i;
1343   /* Can't use vec_len(am->per_worker_data) since the threads might not have come up yet; */
1344   int n_threads = vec_len(vlib_mains);
1345   for (i = n_threads > 1 ? 1 : 0; i < n_threads; i++) {
1346     send_one_worker_interrupt(vm, am, i);
1347   }
1348 }
1349
1350 /* centralized process to drive per-worker cleaners */
1351 static uword
1352 acl_fa_session_cleaner_process (vlib_main_t * vm, vlib_node_runtime_t * rt,
1353                                 vlib_frame_t * f)
1354 {
1355   acl_main_t *am = &acl_main;
1356   u64 now = clib_cpu_time_now ();
1357   f64 cpu_cps = vm->clib_time.clocks_per_second;
1358   u64 next_expire;
1359   /* We should check if there are connections to clean up - at least twice a second */
1360   u64 max_timer_wait_interval = cpu_cps / 2;
1361   uword event_type, *event_data = 0;
1362   acl_fa_per_worker_data_t *pw0;
1363
1364   am->fa_current_cleaner_timer_wait_interval = max_timer_wait_interval;
1365   am->fa_cleaner_node_index = acl_fa_session_cleaner_process_node.index;
1366
1367   while (1)
1368     {
1369       now = clib_cpu_time_now ();
1370       next_expire = now + am->fa_current_cleaner_timer_wait_interval;
1371       int has_pending_conns = 0;
1372       u16 ti;
1373       u8 tt;
1374
1375       /*
1376        * walk over all per-thread list heads of different timeouts,
1377        * and see if there are any connections pending.
1378        * If there aren't - we do not need to wake up until the
1379        * worker code signals that it has added a connection.
1380        *
1381        * Also, while we are at it, calculate the earliest we need to wake up.
1382        */
1383       for(ti = 0; ti < vec_len(vlib_mains); ti++) {
1384         if (ti >= vec_len(am->per_worker_data)) {
1385           continue;
1386         }
1387         acl_fa_per_worker_data_t *pw = &am->per_worker_data[ti];
1388         for(tt = 0; tt < vec_len(pw->fa_conn_list_head); tt++) {
1389           u64 head_expiry = acl_fa_get_list_head_expiry_time(am, pw, now, ti, tt);
1390           if ((head_expiry < next_expire) && !pw->interrupt_is_pending) {
1391 #ifdef FA_NODE_VERBOSE_DEBUG
1392             clib_warning("Head expiry: %lu, now: %lu, next_expire: %lu (worker: %d, tt: %d)", head_expiry, now, next_expire, ti, tt);
1393 #endif
1394             next_expire = head_expiry;
1395           }
1396           if (~0 != pw->fa_conn_list_head[tt]) {
1397             has_pending_conns = 1;
1398           }
1399         }
1400       }
1401
1402       /* If no pending connections then no point in timing out */
1403       if (!has_pending_conns)
1404         {
1405           am->fa_cleaner_cnt_wait_without_timeout++;
1406           (void) vlib_process_wait_for_event (vm);
1407           event_type = vlib_process_get_events (vm, &event_data);
1408         }
1409       else
1410         {
1411           f64 timeout = ((i64) next_expire - (i64) now) / cpu_cps;
1412           if (timeout <= 0)
1413             {
1414               /* skip waiting altogether */
1415               event_type = ~0;
1416             }
1417           else
1418             {
1419               am->fa_cleaner_cnt_wait_with_timeout++;
1420               (void) vlib_process_wait_for_event_or_clock (vm, timeout);
1421               event_type = vlib_process_get_events (vm, &event_data);
1422             }
1423         }
1424
1425       now = clib_cpu_time_now ();
1426       switch (event_type)
1427         {
1428         case ~0:
1429           /* nothing to do */
1430           break;
1431         case ACL_FA_CLEANER_RESCHEDULE:
1432           /* Nothing to do. */
1433           break;
1434         case ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX:
1435           {
1436             uword *clear_sw_if_index_bitmap = 0;
1437             uword *sw_if_index0;
1438 #ifdef FA_NODE_VERBOSE_DEBUG
1439             clib_warning("ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX received");
1440 #endif
1441             vec_foreach (sw_if_index0, event_data)
1442             {
1443               am->fa_cleaner_cnt_delete_by_sw_index++;
1444 #ifdef FA_NODE_VERBOSE_DEBUG
1445               clib_warning
1446                 ("ACL_FA_NODE_CLEAN: ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX: %d",
1447                  *sw_if_index0);
1448 #endif
1449               clear_sw_if_index_bitmap = clib_bitmap_set(clear_sw_if_index_bitmap, *sw_if_index0, 1);
1450             }
1451 #ifdef FA_NODE_VERBOSE_DEBUG
1452             clib_warning("ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX bitmap: %U", format_bitmap_hex, clear_sw_if_index_bitmap);
1453 #endif
1454             vec_foreach(pw0, am->per_worker_data) {
1455               CLIB_MEMORY_BARRIER ();
1456               while (pw0->clear_in_process) {
1457                 CLIB_MEMORY_BARRIER ();
1458 #ifdef FA_NODE_VERBOSE_DEBUG
1459                 clib_warning("ACL_FA_NODE_CLEAN: waiting previous cleaning cycle to finish on %d...", pw0 - am->per_worker_data);
1460 #endif
1461                 vlib_process_suspend(vm, 0.0001);
1462                 if (pw0->interrupt_is_needed) {
1463                   send_one_worker_interrupt(vm, am, (pw0 - am->per_worker_data));
1464                 }
1465               }
1466               if (pw0->clear_in_process) {
1467                 clib_warning("ERROR-BUG! Could not initiate cleaning on worker because another cleanup in progress");
1468               } else {
1469                 pw0->pending_clear_sw_if_index_bitmap = clib_bitmap_dup(clear_sw_if_index_bitmap);
1470                 pw0->clear_in_process = 1;
1471               }
1472             }
1473             /* send some interrupts so they can start working */
1474             send_interrupts_to_workers(vm, am);
1475
1476             /* now wait till they all complete */
1477 #ifdef FA_NODE_VERBOSE_DEBUG
1478             clib_warning("CLEANER mains len: %d per-worker len: %d", vec_len(vlib_mains), vec_len(am->per_worker_data));
1479 #endif
1480             vec_foreach(pw0, am->per_worker_data) {
1481               CLIB_MEMORY_BARRIER ();
1482               while (pw0->clear_in_process) {
1483                 CLIB_MEMORY_BARRIER ();
1484 #ifdef FA_NODE_VERBOSE_DEBUG
1485                 clib_warning("ACL_FA_NODE_CLEAN: waiting for my cleaning cycle to finish on %d...", pw0 - am->per_worker_data);
1486 #endif
1487                 vlib_process_suspend(vm, 0.0001);
1488                 if (pw0->interrupt_is_needed) {
1489                   send_one_worker_interrupt(vm, am, (pw0 - am->per_worker_data));
1490                 }
1491               }
1492             }
1493 #ifdef FA_NODE_VERBOSE_DEBUG
1494             clib_warning("ACL_FA_NODE_CLEAN: cleaning done");
1495 #endif
1496             clib_bitmap_free(clear_sw_if_index_bitmap);
1497           }
1498           break;
1499         default:
1500 #ifdef FA_NODE_VERBOSE_DEBUG
1501           clib_warning ("ACL plugin connection cleaner: unknown event %u",
1502                         event_type);
1503 #endif
1504           vlib_node_increment_counter (vm,
1505                                        acl_fa_session_cleaner_process_node.
1506                                        index,
1507                                        ACL_FA_CLEANER_ERROR_UNKNOWN_EVENT, 1);
1508           am->fa_cleaner_cnt_unknown_event++;
1509           break;
1510         }
1511
1512       send_interrupts_to_workers(vm, am);
1513
1514       if (event_data)
1515         _vec_len (event_data) = 0;
1516
1517
1518       int interrupts_needed = 0;
1519       int interrupts_unwanted = 0;
1520
1521       vec_foreach(pw0, am->per_worker_data) {
1522         if (pw0->interrupt_is_needed) {
1523           interrupts_needed++;
1524           /* the per-worker value is reset when sending the interrupt */
1525         }
1526         if (pw0->interrupt_is_unwanted) {
1527           interrupts_unwanted++;
1528           pw0->interrupt_is_unwanted = 0;
1529         }
1530       }
1531       if (interrupts_needed) {
1532         /* they need more interrupts, do less waiting around next time */
1533         am->fa_current_cleaner_timer_wait_interval /= 2;
1534       } else if (interrupts_unwanted) {
1535         /* slowly increase the amount of sleep up to a limit */
1536         if (am->fa_current_cleaner_timer_wait_interval < max_timer_wait_interval)
1537           am->fa_current_cleaner_timer_wait_interval += cpu_cps * am->fa_cleaner_wait_time_increment;
1538       }
1539       am->fa_cleaner_cnt_event_cycles++;
1540     }
1541   /* NOT REACHED */
1542   return 0;
1543 }
1544
1545
1546 void
1547 acl_fa_enable_disable (u32 sw_if_index, int is_input, int enable_disable)
1548 {
1549   acl_main_t *am = &acl_main;
1550   if (is_input)
1551     {
1552       vnet_feature_enable_disable ("ip4-unicast", "acl-plugin-in-ip4-fa",
1553                                    sw_if_index, enable_disable, 0, 0);
1554       vnet_feature_enable_disable ("ip6-unicast", "acl-plugin-in-ip6-fa",
1555                                    sw_if_index, enable_disable, 0, 0);
1556       am->fa_in_acl_on_sw_if_index =
1557         clib_bitmap_set (am->fa_in_acl_on_sw_if_index, sw_if_index,
1558                          enable_disable);
1559     }
1560   else
1561     {
1562       vnet_feature_enable_disable ("ip4-output", "acl-plugin-out-ip4-fa",
1563                                    sw_if_index, enable_disable, 0, 0);
1564       vnet_feature_enable_disable ("ip6-output", "acl-plugin-out-ip6-fa",
1565                                    sw_if_index, enable_disable, 0, 0);
1566       am->fa_out_acl_on_sw_if_index =
1567         clib_bitmap_set (am->fa_out_acl_on_sw_if_index, sw_if_index,
1568                          enable_disable);
1569     }
1570   if ((!enable_disable) && (!acl_fa_ifc_has_in_acl (am, sw_if_index))
1571       && (!acl_fa_ifc_has_out_acl (am, sw_if_index)))
1572     {
1573 #ifdef FA_NODE_VERBOSE_DEBUG
1574       clib_warning("ENABLE-DISABLE: clean the connections on interface %d", sw_if_index);
1575 #endif
1576       vlib_process_signal_event (am->vlib_main, am->fa_cleaner_node_index,
1577                                  ACL_FA_CLEANER_DELETE_BY_SW_IF_INDEX,
1578                                  sw_if_index);
1579     }
1580 }
1581
1582
1583
1584 /* *INDENT-OFF* */
1585
1586 VLIB_REGISTER_NODE (acl_fa_worker_session_cleaner_process_node, static) = {
1587   .function = acl_fa_worker_conn_cleaner_process,
1588   .name = "acl-plugin-fa-worker-cleaner-process",
1589   .type = VLIB_NODE_TYPE_INPUT,
1590   .state = VLIB_NODE_STATE_INTERRUPT,
1591 };
1592
1593 VLIB_REGISTER_NODE (acl_fa_session_cleaner_process_node, static) = {
1594   .function = acl_fa_session_cleaner_process,
1595   .type = VLIB_NODE_TYPE_PROCESS,
1596   .name = "acl-plugin-fa-cleaner-process",
1597   .n_errors = ARRAY_LEN (acl_fa_cleaner_error_strings),
1598   .error_strings = acl_fa_cleaner_error_strings,
1599   .n_next_nodes = 0,
1600   .next_nodes = {},
1601 };
1602
1603
1604 VLIB_REGISTER_NODE (acl_in_l2_ip6_node) =
1605 {
1606   .function = acl_in_ip6_l2_node_fn,
1607   .name = "acl-plugin-in-ip6-l2",
1608   .vector_size = sizeof (u32),
1609   .format_trace = format_acl_fa_trace,
1610   .type = VLIB_NODE_TYPE_INTERNAL,
1611   .n_errors = ARRAY_LEN (acl_fa_error_strings),
1612   .error_strings = acl_fa_error_strings,
1613   .n_next_nodes = ACL_FA_N_NEXT,
1614   .next_nodes =
1615   {
1616     [ACL_FA_ERROR_DROP] = "error-drop",
1617   }
1618 };
1619
1620 VLIB_REGISTER_NODE (acl_in_l2_ip4_node) =
1621 {
1622   .function = acl_in_ip4_l2_node_fn,
1623   .name = "acl-plugin-in-ip4-l2",
1624   .vector_size = sizeof (u32),
1625   .format_trace = format_acl_fa_trace,
1626   .type = VLIB_NODE_TYPE_INTERNAL,
1627   .n_errors = ARRAY_LEN (acl_fa_error_strings),
1628   .error_strings = acl_fa_error_strings,
1629   .n_next_nodes = ACL_FA_N_NEXT,
1630   .next_nodes =
1631   {
1632     [ACL_FA_ERROR_DROP] = "error-drop",
1633   }
1634 };
1635
1636 VLIB_REGISTER_NODE (acl_out_l2_ip6_node) =
1637 {
1638   .function = acl_out_ip6_l2_node_fn,
1639   .name = "acl-plugin-out-ip6-l2",
1640   .vector_size = sizeof (u32),
1641   .format_trace = format_acl_fa_trace,
1642   .type = VLIB_NODE_TYPE_INTERNAL,
1643   .n_errors = ARRAY_LEN (acl_fa_error_strings),
1644   .error_strings = acl_fa_error_strings,
1645   .n_next_nodes = ACL_FA_N_NEXT,
1646   .next_nodes =
1647   {
1648     [ACL_FA_ERROR_DROP] = "error-drop",
1649   }
1650 };
1651
1652 VLIB_REGISTER_NODE (acl_out_l2_ip4_node) =
1653 {
1654   .function = acl_out_ip4_l2_node_fn,
1655   .name = "acl-plugin-out-ip4-l2",
1656   .vector_size = sizeof (u32),
1657   .format_trace = format_acl_fa_trace,
1658   .type = VLIB_NODE_TYPE_INTERNAL,
1659   .n_errors = ARRAY_LEN (acl_fa_error_strings),
1660   .error_strings = acl_fa_error_strings,
1661   .n_next_nodes = ACL_FA_N_NEXT,
1662   .next_nodes =
1663   {
1664     [ACL_FA_ERROR_DROP] = "error-drop",
1665   }
1666 };
1667
1668
1669 VLIB_REGISTER_NODE (acl_in_fa_ip6_node) =
1670 {
1671   .function = acl_in_ip6_fa_node_fn,
1672   .name = "acl-plugin-in-ip6-fa",
1673   .vector_size = sizeof (u32),
1674   .format_trace = format_acl_fa_trace,
1675   .type = VLIB_NODE_TYPE_INTERNAL,
1676   .n_errors = ARRAY_LEN (acl_fa_error_strings),
1677   .error_strings = acl_fa_error_strings,
1678   .n_next_nodes = ACL_FA_N_NEXT,
1679   .next_nodes =
1680   {
1681     [ACL_FA_ERROR_DROP] = "error-drop",
1682   }
1683 };
1684
1685 VNET_FEATURE_INIT (acl_in_ip6_fa_feature, static) =
1686 {
1687   .arc_name = "ip6-unicast",
1688   .node_name = "acl-plugin-in-ip6-fa",
1689   .runs_before = VNET_FEATURES ("ip6-flow-classify"),
1690 };
1691
1692 VLIB_REGISTER_NODE (acl_in_fa_ip4_node) =
1693 {
1694   .function = acl_in_ip4_fa_node_fn,
1695   .name = "acl-plugin-in-ip4-fa",
1696   .vector_size = sizeof (u32),
1697   .format_trace = format_acl_fa_trace,
1698   .type = VLIB_NODE_TYPE_INTERNAL,
1699   .n_errors = ARRAY_LEN (acl_fa_error_strings),
1700   .error_strings = acl_fa_error_strings,
1701   .n_next_nodes = ACL_FA_N_NEXT,
1702   .next_nodes =
1703   {
1704     [ACL_FA_ERROR_DROP] = "error-drop",
1705   }
1706 };
1707
1708 VNET_FEATURE_INIT (acl_in_ip4_fa_feature, static) =
1709 {
1710   .arc_name = "ip4-unicast",
1711   .node_name = "acl-plugin-in-ip4-fa",
1712   .runs_before = VNET_FEATURES ("ip4-flow-classify"),
1713 };
1714
1715
1716 VLIB_REGISTER_NODE (acl_out_fa_ip6_node) =
1717 {
1718   .function = acl_out_ip6_fa_node_fn,
1719   .name = "acl-plugin-out-ip6-fa",
1720   .vector_size = sizeof (u32),
1721   .format_trace = format_acl_fa_trace,
1722   .type = VLIB_NODE_TYPE_INTERNAL,
1723   .n_errors = ARRAY_LEN (acl_fa_error_strings),
1724   .error_strings = acl_fa_error_strings,
1725   .n_next_nodes = ACL_FA_N_NEXT,
1726   .next_nodes =
1727   {
1728     [ACL_FA_ERROR_DROP] = "error-drop",
1729   }
1730 };
1731
1732 VNET_FEATURE_INIT (acl_out_ip6_fa_feature, static) =
1733 {
1734   .arc_name = "ip6-output",
1735   .node_name = "acl-plugin-out-ip6-fa",
1736   .runs_before = VNET_FEATURES ("interface-output"),
1737 };
1738
1739 VLIB_REGISTER_NODE (acl_out_fa_ip4_node) =
1740 {
1741   .function = acl_out_ip4_fa_node_fn,
1742   .name = "acl-plugin-out-ip4-fa",
1743   .vector_size = sizeof (u32),
1744   .format_trace = format_acl_fa_trace,
1745   .type = VLIB_NODE_TYPE_INTERNAL,
1746   .n_errors = ARRAY_LEN (acl_fa_error_strings),
1747   .error_strings = acl_fa_error_strings,
1748   .n_next_nodes = ACL_FA_N_NEXT,
1749     /* edit / add dispositions here */
1750   .next_nodes =
1751   {
1752     [ACL_FA_ERROR_DROP] = "error-drop",
1753   }
1754 };
1755
1756 VNET_FEATURE_INIT (acl_out_ip4_fa_feature, static) =
1757 {
1758   .arc_name = "ip4-output",
1759   .node_name = "acl-plugin-out-ip4-fa",
1760   .runs_before = VNET_FEATURES ("interface-output"),
1761 };
1762
1763
1764 /* *INDENT-ON* */