nat: refactor and split fo EI/ED features
[vpp.git] / src / plugins / nat / nat44-ei / nat44_ei_ha.c
1 /*
2  * Copyright (c) 2019 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
16 #include <nat/nat_inlines.h>
17 #include <nat/nat44/ed_inlines.h>
18 #include <nat/nat44-ei/nat44_ei_ha.h>
19 #include <vnet/udp/udp_local.h>
20 #include <nat/nat.h>
21 #include <vppinfra/atomics.h>
22
23 /* number of retries */
24 #define NAT_HA_RETRIES 3
25
26 #define foreach_nat_ha_counter           \
27 _(RECV_ADD, "add-event-recv", 0)         \
28 _(RECV_DEL, "del-event-recv", 1)         \
29 _(RECV_REFRESH, "refresh-event-recv", 2) \
30 _(SEND_ADD, "add-event-send", 3)         \
31 _(SEND_DEL, "del-event-send", 4)         \
32 _(SEND_REFRESH, "refresh-event-send", 5) \
33 _(RECV_ACK, "ack-recv", 6)               \
34 _(SEND_ACK, "ack-send", 7)               \
35 _(RETRY_COUNT, "retry-count", 8)         \
36 _(MISSED_COUNT, "missed-count", 9)
37
38 /* NAT HA protocol version */
39 #define NAT_HA_VERSION 0x01
40
41 /* NAT HA protocol flags */
42 #define NAT_HA_FLAG_ACK 0x01
43
44 /* NAT HA event types */
45 typedef enum
46 {
47   NAT_HA_ADD = 1,
48   NAT_HA_DEL,
49   NAT_HA_REFRESH,
50 } nat_ha_event_type_t;
51
52 /* NAT HA protocol header */
53 typedef struct
54 {
55   /* version */
56   u8 version;
57   /* flags */
58   u8 flags;
59   /* event count */
60   u16 count;
61   /* sequence number */
62   u32 sequence_number;
63   /* thread index where events originated */
64   u32 thread_index;
65 } __attribute__ ((packed)) nat_ha_message_header_t;
66
67 /* NAT HA protocol event data */
68 typedef struct
69 {
70   /* event type */
71   u8 event_type;
72   /* session data */
73   u8 protocol;
74   u16 flags;
75   u32 in_addr;
76   u32 out_addr;
77   u16 in_port;
78   u16 out_port;
79   u32 eh_addr;
80   u32 ehn_addr;
81   u16 eh_port;
82   u16 ehn_port;
83   u32 fib_index;
84   u32 total_pkts;
85   u64 total_bytes;
86 } __attribute__ ((packed)) nat_ha_event_t;
87
88 typedef enum
89 {
90 #define _(N, s, v) NAT_HA_COUNTER_##N = v,
91   foreach_nat_ha_counter
92 #undef _
93   NAT_HA_N_COUNTERS
94 } nat_ha_counter_t;
95
96 /* data waiting for ACK */
97 typedef struct
98 {
99   /* sequence number */
100   u32 seq;
101   /* retry count */
102   u32 retry_count;
103   /* next retry time */
104   f64 retry_timer;
105   /* 1 if HA resync */
106   u8 is_resync;
107   /* packet data */
108   u8 *data;
109 } nat_ha_resend_entry_t;
110
111 /* per thread data */
112 typedef struct
113 {
114   /* buffer under construction */
115   vlib_buffer_t *state_sync_buffer;
116   /* frame containing NAT HA buffers */
117   vlib_frame_t *state_sync_frame;
118   /* number of events */
119   u16 state_sync_count;
120   /* next event offset */
121   u32 state_sync_next_event_offset;
122   /* data waiting for ACK */
123   nat_ha_resend_entry_t *resend_queue;
124 } nat_ha_per_thread_data_t;
125
126 /* NAT HA settings */
127 typedef struct nat_ha_main_s
128 {
129   u8 enabled;
130   /* local IP address and UDP port */
131   ip4_address_t src_ip_address;
132   u16 src_port;
133   /* failvoer IP address and UDP port */
134   ip4_address_t dst_ip_address;
135   u16 dst_port;
136   /* path MTU between local and failover */
137   u32 state_sync_path_mtu;
138   /* number of seconds after which to send session counters refresh */
139   u32 session_refresh_interval;
140   /* counters */
141   vlib_simple_counter_main_t counters[NAT_HA_N_COUNTERS];
142   vlib_main_t *vlib_main;
143   /* sequence number counter */
144   u32 sequence_number;
145   /* 1 if resync in progress */
146   u8 in_resync;
147   /* number of remaing ACK for resync */
148   u32 resync_ack_count;
149   /* number of missed ACK for resync */
150   u32 resync_ack_missed;
151   /* resync data */
152   nat_ha_resync_event_cb_t event_callback;
153   u32 client_index;
154   u32 pid;
155   /* per thread data */
156   u32 num_workers;
157   nat_ha_per_thread_data_t *per_thread_data;
158
159   u32 ha_handoff_node_index;
160   u32 ha_process_node_index;
161   u32 ha_worker_node_index;
162   u32 ha_node_index;
163
164   /* worker handoff frame-queue index */
165   u32 fq_index;
166 } nat_ha_main_t;
167
168 nat_ha_main_t nat_ha_main;
169
170 static_always_inline void
171 nat44_ei_ha_sadd (ip4_address_t *in_addr, u16 in_port, ip4_address_t *out_addr,
172                   u16 out_port, ip4_address_t *eh_addr, u16 eh_port,
173                   ip4_address_t *ehn_addr, u16 ehn_port, u8 proto,
174                   u32 fib_index, u16 flags, u32 thread_index)
175 {
176   snat_main_t *sm = &snat_main;
177   snat_main_per_thread_data_t *tsm = &sm->per_thread_data[thread_index];
178   snat_user_t *u;
179   snat_session_t *s;
180   clib_bihash_kv_8_8_t kv;
181   vlib_main_t *vm = vlib_get_main ();
182   f64 now = vlib_time_now (vm);
183   nat_outside_fib_t *outside_fib;
184   fib_node_index_t fei = FIB_NODE_INDEX_INVALID;
185   fib_prefix_t pfx = {
186     .fp_proto = FIB_PROTOCOL_IP4,
187     .fp_len = 32,
188     .fp_addr = {
189                 .ip4.as_u32 = eh_addr->as_u32,
190                 },
191   };
192
193   if (!(flags & SNAT_SESSION_FLAG_STATIC_MAPPING))
194     {
195       if (nat_set_outside_address_and_port (sm->addresses, thread_index,
196                                             *out_addr, out_port, proto))
197         return;
198     }
199
200   u = nat_user_get_or_create (sm, in_addr, fib_index, thread_index);
201   if (!u)
202     return;
203
204   s = nat_session_alloc_or_recycle (sm, u, thread_index, now);
205   if (!s)
206     return;
207
208   if (sm->endpoint_dependent)
209     {
210       nat_ed_lru_insert (tsm, s, now, nat_proto_to_ip_proto (proto));
211     }
212
213   s->out2in.addr.as_u32 = out_addr->as_u32;
214   s->out2in.port = out_port;
215   s->nat_proto = proto;
216   s->last_heard = now;
217   s->flags = flags;
218   s->ext_host_addr.as_u32 = eh_addr->as_u32;
219   s->ext_host_port = eh_port;
220   user_session_increment (sm, u, snat_is_session_static (s));
221   switch (vec_len (sm->outside_fibs))
222     {
223     case 0:
224       s->out2in.fib_index = sm->outside_fib_index;
225       break;
226     case 1:
227       s->out2in.fib_index = sm->outside_fibs[0].fib_index;
228       break;
229     default:
230       vec_foreach (outside_fib, sm->outside_fibs)
231         {
232           fei = fib_table_lookup (outside_fib->fib_index, &pfx);
233           if (FIB_NODE_INDEX_INVALID != fei)
234             {
235               if (fib_entry_get_resolving_interface (fei) != ~0)
236                 {
237                   s->out2in.fib_index = outside_fib->fib_index;
238                   break;
239                 }
240             }
241         }
242       break;
243     }
244   init_nat_o2i_kv (&kv, s, s - tsm->sessions);
245   if (clib_bihash_add_del_8_8 (&tsm->out2in, &kv, 1))
246     nat_elog_warn ("out2in key add failed");
247
248   s->in2out.addr.as_u32 = in_addr->as_u32;
249   s->in2out.port = in_port;
250   s->in2out.fib_index = fib_index;
251   init_nat_i2o_kv (&kv, s, s - tsm->sessions);
252   if (clib_bihash_add_del_8_8 (&tsm->in2out, &kv, 1))
253     nat_elog_warn ("in2out key add failed");
254 }
255
256 static_always_inline void
257 nat44_ei_ha_sdel (ip4_address_t *out_addr, u16 out_port,
258                   ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index,
259                   u32 ti)
260 {
261   snat_main_t *sm = &snat_main;
262   clib_bihash_kv_8_8_t kv, value;
263   u32 thread_index;
264   snat_session_t *s;
265   snat_main_per_thread_data_t *tsm;
266
267   if (sm->num_workers > 1)
268     thread_index = sm->first_worker_index +
269                    (sm->workers[(clib_net_to_host_u16 (out_port) - 1024) /
270                                 sm->port_per_thread]);
271   else
272     thread_index = sm->num_workers;
273   tsm = vec_elt_at_index (sm->per_thread_data, thread_index);
274
275   init_nat_k (&kv, *out_addr, out_port, fib_index, proto);
276   if (clib_bihash_search_8_8 (&tsm->out2in, &kv, &value))
277     return;
278
279   s = pool_elt_at_index (tsm->sessions, value.value);
280   nat_free_session_data (sm, s, thread_index, 1);
281   nat44_delete_session (sm, s, thread_index);
282 }
283
284 static_always_inline void
285 nat44_ei_ha_sref (ip4_address_t *out_addr, u16 out_port,
286                   ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index,
287                   u32 total_pkts, u64 total_bytes, u32 thread_index)
288 {
289   snat_main_t *sm = &snat_main;
290   clib_bihash_kv_8_8_t kv, value;
291   snat_session_t *s;
292   snat_main_per_thread_data_t *tsm;
293
294   tsm = vec_elt_at_index (sm->per_thread_data, thread_index);
295
296   init_nat_k (&kv, *out_addr, out_port, fib_index, proto);
297   if (clib_bihash_search_8_8 (&tsm->out2in, &kv, &value))
298     return;
299
300   s = pool_elt_at_index (tsm->sessions, value.value);
301   s->total_pkts = total_pkts;
302   s->total_bytes = total_bytes;
303 }
304
305 static void
306 nat_ha_resync_fin (void)
307 {
308   nat_ha_main_t *ha = &nat_ha_main;
309
310   /* if no more resync ACK remainig we are done */
311   if (ha->resync_ack_count)
312     return;
313
314   ha->in_resync = 0;
315   if (ha->resync_ack_missed)
316     {
317       nat_elog_info ("resync completed with result FAILED");
318     }
319   else
320     {
321       nat_elog_info ("resync completed with result SUCCESS");
322     }
323   if (ha->event_callback)
324     ha->event_callback (ha->client_index, ha->pid, ha->resync_ack_missed);
325 }
326
327 /* cache HA NAT data waiting for ACK */
328 static int
329 nat_ha_resend_queue_add (u32 seq, u8 * data, u8 data_len, u8 is_resync,
330                          u32 thread_index)
331 {
332   nat_ha_main_t *ha = &nat_ha_main;
333   nat_ha_per_thread_data_t *td = &ha->per_thread_data[thread_index];
334   nat_ha_resend_entry_t *entry;
335   f64 now = vlib_time_now (ha->vlib_main);
336
337   vec_add2 (td->resend_queue, entry, 1);
338   clib_memset (entry, 0, sizeof (*entry));
339   entry->retry_timer = now + 2.0;
340   entry->seq = seq;
341   entry->is_resync = is_resync;
342   vec_add (entry->data, data, data_len);
343
344   return 0;
345 }
346
347 static_always_inline void
348 nat_ha_ack_recv (u32 seq, u32 thread_index)
349 {
350   nat_ha_main_t *ha = &nat_ha_main;
351   nat_ha_per_thread_data_t *td = &ha->per_thread_data[thread_index];
352   u32 i;
353
354   vec_foreach_index (i, td->resend_queue)
355   {
356     if (td->resend_queue[i].seq != seq)
357       continue;
358
359     vlib_increment_simple_counter (&ha->counters[NAT_HA_COUNTER_RECV_ACK],
360                                    thread_index, 0, 1);
361     /* ACK received remove cached data */
362     if (td->resend_queue[i].is_resync)
363       {
364         clib_atomic_fetch_sub (&ha->resync_ack_count, 1);
365         nat_ha_resync_fin ();
366       }
367     vec_free (td->resend_queue[i].data);
368     vec_del1 (td->resend_queue, i);
369     nat_elog_debug_X1 ("ACK for seq %d received", "i4",
370                        clib_net_to_host_u32 (seq));
371
372     return;
373   }
374 }
375
376 /* scan non-ACKed HA NAT for retry */
377 static void
378 nat_ha_resend_scan (f64 now, u32 thread_index)
379 {
380   nat_ha_main_t *ha = &nat_ha_main;
381   nat_ha_per_thread_data_t *td = &ha->per_thread_data[thread_index];
382   u32 i, *del, *to_delete = 0;
383   vlib_main_t *vm = ha->vlib_main;
384   vlib_buffer_t *b = 0;
385   vlib_frame_t *f;
386   u32 bi, *to_next;
387   ip4_header_t *ip;
388
389   vec_foreach_index (i, td->resend_queue)
390   {
391     if (td->resend_queue[i].retry_timer > now)
392       continue;
393
394     /* maximum retry reached delete cached data */
395     if (td->resend_queue[i].retry_count >= NAT_HA_RETRIES)
396       {
397         nat_elog_notice_X1 ("seq %d missed", "i4",
398                             clib_net_to_host_u32 (td->resend_queue[i].seq));
399         if (td->resend_queue[i].is_resync)
400           {
401             clib_atomic_fetch_add (&ha->resync_ack_missed, 1);
402             clib_atomic_fetch_sub (&ha->resync_ack_count, 1);
403             nat_ha_resync_fin ();
404           }
405         vec_add1 (to_delete, i);
406         vlib_increment_simple_counter (&ha->counters
407                                        [NAT_HA_COUNTER_MISSED_COUNT],
408                                        thread_index, 0, 1);
409         continue;
410       }
411
412     /* retry to send non-ACKed data */
413     nat_elog_debug_X1 ("state sync seq %d resend", "i4",
414                        clib_net_to_host_u32 (td->resend_queue[i].seq));
415     td->resend_queue[i].retry_count++;
416     vlib_increment_simple_counter (&ha->counters[NAT_HA_COUNTER_RETRY_COUNT],
417                                    thread_index, 0, 1);
418     if (vlib_buffer_alloc (vm, &bi, 1) != 1)
419       {
420         nat_elog_warn ("HA NAT state sync can't allocate buffer");
421         return;
422       }
423     b = vlib_get_buffer (vm, bi);
424     b->current_length = vec_len (td->resend_queue[i].data);
425     b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
426     b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
427     vnet_buffer (b)->sw_if_index[VLIB_RX] = 0;
428     vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
429     ip = vlib_buffer_get_current (b);
430     clib_memcpy (ip, td->resend_queue[i].data,
431                  vec_len (td->resend_queue[i].data));
432     f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
433     to_next = vlib_frame_vector_args (f);
434     to_next[0] = bi;
435     f->n_vectors = 1;
436     vlib_put_frame_to_node (vm, ip4_lookup_node.index, f);
437     td->resend_queue[i].retry_timer = now + 2.0;
438   }
439
440   vec_foreach (del, to_delete)
441   {
442     vec_free (td->resend_queue[*del].data);
443     vec_del1 (td->resend_queue, *del);
444   }
445   vec_free (to_delete);
446 }
447
448 void
449 nat_ha_enable ()
450 {
451   nat_ha_main_t *ha = &nat_ha_main;
452   ha->enabled = 1;
453 }
454
455 void
456 nat_ha_disable ()
457 {
458   nat_ha_main_t *ha = &nat_ha_main;
459   ha->dst_port = 0;
460   ha->enabled = 0;
461 }
462
463 void
464 nat_ha_set_node_indexes (nat_ha_main_t *ha, vlib_main_t *vm)
465 {
466   vlib_node_t *node;
467
468   node = vlib_get_node_by_name (vm, (u8 *) "nat-ha-handoff");
469   ha->ha_handoff_node_index = node->index;
470   node = vlib_get_node_by_name (vm, (u8 *) "nat-ha-process");
471   ha->ha_process_node_index = node->index;
472   node = vlib_get_node_by_name (vm, (u8 *) "nat-ha-worker");
473   ha->ha_worker_node_index = node->index;
474   node = vlib_get_node_by_name (vm, (u8 *) "nat-ha");
475   ha->ha_node_index = node->index;
476 }
477
478 void
479 nat_ha_init (vlib_main_t * vm, u32 num_workers, u32 num_threads)
480 {
481   nat_ha_main_t *ha = &nat_ha_main;
482   clib_memset (ha, 0, sizeof (*ha));
483
484   nat_ha_set_node_indexes (ha, vm);
485
486   ha->vlib_main = vm;
487   ha->fq_index = ~0;
488
489   ha->num_workers = num_workers;
490   vec_validate (ha->per_thread_data, num_threads);
491
492 #define _(N, s, v) ha->counters[v].name = s;          \
493   ha->counters[v].stat_segment_name = "/nat44/ha/" s; \
494   vlib_validate_simple_counter(&ha->counters[v], 0);  \
495   vlib_zero_simple_counter(&ha->counters[v], 0);
496   foreach_nat_ha_counter
497 #undef _
498 }
499
500 int
501 nat_ha_set_listener (ip4_address_t * addr, u16 port, u32 path_mtu)
502 {
503   nat_ha_main_t *ha = &nat_ha_main;
504
505   /* unregister previously set UDP port */
506   if (ha->src_port)
507     udp_unregister_dst_port (ha->vlib_main, ha->src_port, 1);
508
509   ha->src_ip_address.as_u32 = addr->as_u32;
510   ha->src_port = port;
511   ha->state_sync_path_mtu = path_mtu;
512
513   if (port)
514     {
515       /* if multiple worker threads first go to handoff node */
516       if (ha->num_workers > 1)
517         {
518           if (ha->fq_index == ~0)
519             ha->fq_index = vlib_frame_queue_main_init (ha->ha_node_index, 0);
520           udp_register_dst_port (ha->vlib_main, port,
521                                  ha->ha_handoff_node_index, 1);
522         }
523       else
524         {
525           udp_register_dst_port (ha->vlib_main, port, ha->ha_node_index, 1);
526         }
527       nat_elog_info_X1 ("HA listening on port %d for state sync", "i4", port);
528     }
529
530   return 0;
531 }
532
533 void
534 nat_ha_get_listener (ip4_address_t * addr, u16 * port, u32 * path_mtu)
535 {
536   nat_ha_main_t *ha = &nat_ha_main;
537
538   addr->as_u32 = ha->src_ip_address.as_u32;
539   *port = ha->src_port;
540   *path_mtu = ha->state_sync_path_mtu;
541 }
542
543 int
544 nat_ha_set_failover (ip4_address_t * addr, u16 port,
545                      u32 session_refresh_interval)
546 {
547   nat_ha_main_t *ha = &nat_ha_main;
548
549   ha->dst_ip_address.as_u32 = addr->as_u32;
550   ha->dst_port = port;
551   ha->session_refresh_interval = session_refresh_interval;
552
553   vlib_process_signal_event (ha->vlib_main, ha->ha_process_node_index, 1, 0);
554
555   return 0;
556 }
557
558 void
559 nat_ha_get_failover (ip4_address_t * addr, u16 * port,
560                      u32 * session_refresh_interval)
561 {
562   nat_ha_main_t *ha = &nat_ha_main;
563
564   addr->as_u32 = ha->dst_ip_address.as_u32;
565   *port = ha->dst_port;
566   *session_refresh_interval = ha->session_refresh_interval;
567 }
568
569 static_always_inline void
570 nat_ha_recv_add (nat_ha_event_t * event, f64 now, u32 thread_index)
571 {
572   nat_ha_main_t *ha = &nat_ha_main;
573   ip4_address_t in_addr, out_addr, eh_addr, ehn_addr;
574   u32 fib_index;
575   u16 flags;
576
577   vlib_increment_simple_counter (&ha->counters[NAT_HA_COUNTER_RECV_ADD],
578                                  thread_index, 0, 1);
579
580   in_addr.as_u32 = event->in_addr;
581   out_addr.as_u32 = event->out_addr;
582   eh_addr.as_u32 = event->eh_addr;
583   ehn_addr.as_u32 = event->ehn_addr;
584   fib_index = clib_net_to_host_u32 (event->fib_index);
585   flags = clib_net_to_host_u16 (event->flags);
586
587   nat44_ei_ha_sadd (&in_addr, event->in_port, &out_addr, event->out_port,
588                     &eh_addr, event->eh_port, &ehn_addr, event->ehn_port,
589                     event->protocol, fib_index, flags, thread_index);
590 }
591
592 static_always_inline void
593 nat_ha_recv_del (nat_ha_event_t * event, u32 thread_index)
594 {
595   nat_ha_main_t *ha = &nat_ha_main;
596   ip4_address_t out_addr, eh_addr;
597   u32 fib_index;
598
599   vlib_increment_simple_counter (&ha->counters[NAT_HA_COUNTER_RECV_DEL],
600                                  thread_index, 0, 1);
601
602   out_addr.as_u32 = event->out_addr;
603   eh_addr.as_u32 = event->eh_addr;
604   fib_index = clib_net_to_host_u32 (event->fib_index);
605
606   nat44_ei_ha_sdel (&out_addr, event->out_port, &eh_addr, event->eh_port,
607                     event->protocol, fib_index, thread_index);
608 }
609
610 static_always_inline void
611 nat_ha_recv_refresh (nat_ha_event_t * event, f64 now, u32 thread_index)
612 {
613   nat_ha_main_t *ha = &nat_ha_main;
614   ip4_address_t out_addr, eh_addr;
615   u32 fib_index, total_pkts;
616   u64 total_bytes;
617
618   vlib_increment_simple_counter (&ha->counters[NAT_HA_COUNTER_RECV_REFRESH],
619                                  thread_index, 0, 1);
620
621   out_addr.as_u32 = event->out_addr;
622   eh_addr.as_u32 = event->eh_addr;
623   fib_index = clib_net_to_host_u32 (event->fib_index);
624   total_pkts = clib_net_to_host_u32 (event->total_pkts);
625   total_bytes = clib_net_to_host_u64 (event->total_bytes);
626
627   nat44_ei_ha_sref (&out_addr, event->out_port, &eh_addr, event->eh_port,
628                     event->protocol, fib_index, total_pkts, total_bytes,
629                     thread_index);
630 }
631
632 /* process received NAT HA event */
633 static_always_inline void
634 nat_ha_event_process (nat_ha_event_t * event, f64 now, u32 thread_index)
635 {
636   switch (event->event_type)
637     {
638     case NAT_HA_ADD:
639       nat_ha_recv_add (event, now, thread_index);
640       break;
641     case NAT_HA_DEL:
642       nat_ha_recv_del (event, thread_index);
643       break;
644     case NAT_HA_REFRESH:
645       nat_ha_recv_refresh (event, now, thread_index);
646       break;
647     default:
648       nat_elog_notice_X1 ("Unsupported HA event type %d", "i4",
649                           event->event_type);
650       break;
651     }
652 }
653
654 static inline void
655 nat_ha_header_create (vlib_buffer_t * b, u32 * offset, u32 thread_index)
656 {
657   nat_ha_main_t *ha = &nat_ha_main;
658   nat_ha_message_header_t *h;
659   ip4_header_t *ip;
660   udp_header_t *udp;
661   u32 sequence_number;
662
663   b->current_data = 0;
664   b->current_length = sizeof (*ip) + sizeof (*udp) + sizeof (*h);
665   b->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
666   b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
667   vnet_buffer (b)->sw_if_index[VLIB_RX] = 0;
668   vnet_buffer (b)->sw_if_index[VLIB_TX] = 0;
669   ip = vlib_buffer_get_current (b);
670   udp = (udp_header_t *) (ip + 1);
671   h = (nat_ha_message_header_t *) (udp + 1);
672
673   /* IP header */
674   ip->ip_version_and_header_length = 0x45;
675   ip->ttl = 254;
676   ip->protocol = IP_PROTOCOL_UDP;
677   ip->flags_and_fragment_offset =
678     clib_host_to_net_u16 (IP4_HEADER_FLAG_DONT_FRAGMENT);
679   ip->src_address.as_u32 = ha->src_ip_address.as_u32;
680   ip->dst_address.as_u32 = ha->dst_ip_address.as_u32;
681   /* UDP header */
682   udp->src_port = clib_host_to_net_u16 (ha->src_port);
683   udp->dst_port = clib_host_to_net_u16 (ha->dst_port);
684   udp->checksum = 0;
685
686   /* NAT HA protocol header */
687   h->version = NAT_HA_VERSION;
688   h->flags = 0;
689   h->count = 0;
690   h->thread_index = clib_host_to_net_u32 (thread_index);
691   sequence_number = clib_atomic_fetch_add (&ha->sequence_number, 1);
692   h->sequence_number = clib_host_to_net_u32 (sequence_number);
693
694   *offset =
695     sizeof (ip4_header_t) + sizeof (udp_header_t) +
696     sizeof (nat_ha_message_header_t);
697 }
698
699 static inline void
700 nat_ha_send (vlib_frame_t * f, vlib_buffer_t * b, u8 is_resync,
701              u32 thread_index)
702 {
703   nat_ha_main_t *ha = &nat_ha_main;
704   nat_ha_per_thread_data_t *td = &ha->per_thread_data[thread_index];
705   nat_ha_message_header_t *h;
706   ip4_header_t *ip;
707   udp_header_t *udp;
708   vlib_main_t *vm = vlib_mains[thread_index];
709
710   ip = vlib_buffer_get_current (b);
711   udp = ip4_next_header (ip);
712   h = (nat_ha_message_header_t *) (udp + 1);
713
714   h->count = clib_host_to_net_u16 (td->state_sync_count);
715
716   ip->length = clib_host_to_net_u16 (b->current_length);
717   ip->checksum = ip4_header_checksum (ip);
718   udp->length = clib_host_to_net_u16 (b->current_length - sizeof (*ip));
719
720   nat_ha_resend_queue_add (h->sequence_number, (u8 *) ip, b->current_length,
721                            is_resync, thread_index);
722
723   vlib_put_frame_to_node (vm, ip4_lookup_node.index, f);
724 }
725
726 /* add NAT HA protocol event */
727 static_always_inline void
728 nat_ha_event_add (nat_ha_event_t * event, u8 do_flush, u32 thread_index,
729                   u8 is_resync)
730 {
731   nat_ha_main_t *ha = &nat_ha_main;
732   nat_ha_per_thread_data_t *td = &ha->per_thread_data[thread_index];
733   vlib_main_t *vm = vlib_mains[thread_index];
734   vlib_buffer_t *b = 0;
735   vlib_frame_t *f;
736   u32 bi = ~0, offset;
737
738   b = td->state_sync_buffer;
739
740   if (PREDICT_FALSE (b == 0))
741     {
742       if (do_flush)
743         return;
744
745       if (vlib_buffer_alloc (vm, &bi, 1) != 1)
746         {
747           nat_elog_warn ("HA NAT state sync can't allocate buffer");
748           return;
749         }
750
751       b = td->state_sync_buffer = vlib_get_buffer (vm, bi);
752       clib_memset (vnet_buffer (b), 0, sizeof (*vnet_buffer (b)));
753       VLIB_BUFFER_TRACE_TRAJECTORY_INIT (b);
754       offset = 0;
755     }
756   else
757     {
758       bi = vlib_get_buffer_index (vm, b);
759       offset = td->state_sync_next_event_offset;
760     }
761
762   f = td->state_sync_frame;
763   if (PREDICT_FALSE (f == 0))
764     {
765       u32 *to_next;
766       f = vlib_get_frame_to_node (vm, ip4_lookup_node.index);
767       td->state_sync_frame = f;
768       to_next = vlib_frame_vector_args (f);
769       to_next[0] = bi;
770       f->n_vectors = 1;
771     }
772
773   if (PREDICT_FALSE (td->state_sync_count == 0))
774     nat_ha_header_create (b, &offset, thread_index);
775
776   if (PREDICT_TRUE (do_flush == 0))
777     {
778       clib_memcpy_fast (b->data + offset, event, sizeof (*event));
779       offset += sizeof (*event);
780       td->state_sync_count++;
781       b->current_length += sizeof (*event);
782
783       switch (event->event_type)
784         {
785         case NAT_HA_ADD:
786           vlib_increment_simple_counter (&ha->counters
787                                          [NAT_HA_COUNTER_SEND_ADD],
788                                          thread_index, 0, 1);
789           break;
790         case NAT_HA_DEL:
791           vlib_increment_simple_counter (&ha->counters
792                                          [NAT_HA_COUNTER_SEND_DEL],
793                                          thread_index, 0, 1);
794           break;
795         case NAT_HA_REFRESH:
796           vlib_increment_simple_counter (&ha->counters
797                                          [NAT_HA_COUNTER_SEND_REFRESH],
798                                          thread_index, 0, 1);
799           break;
800         default:
801           break;
802         }
803     }
804
805   if (PREDICT_FALSE
806       (do_flush || offset + (sizeof (*event)) > ha->state_sync_path_mtu))
807     {
808       nat_ha_send (f, b, is_resync, thread_index);
809       td->state_sync_buffer = 0;
810       td->state_sync_frame = 0;
811       td->state_sync_count = 0;
812       offset = 0;
813       if (is_resync)
814         {
815           clib_atomic_fetch_add (&ha->resync_ack_count, 1);
816           nat_ha_resync_fin ();
817         }
818     }
819
820   td->state_sync_next_event_offset = offset;
821 }
822
823 #define skip_if_disabled()          \
824 do {                                \
825   nat_ha_main_t *ha = &nat_ha_main; \
826   if (PREDICT_TRUE (!ha->dst_port)) \
827     return;                         \
828 } while (0)
829
830 void
831 nat_ha_flush (u8 is_resync)
832 {
833   skip_if_disabled ();
834   nat_ha_event_add (0, 1, 0, is_resync);
835 }
836
837 void
838 nat_ha_sadd (ip4_address_t * in_addr, u16 in_port, ip4_address_t * out_addr,
839              u16 out_port, ip4_address_t * eh_addr, u16 eh_port,
840              ip4_address_t * ehn_addr, u16 ehn_port, u8 proto, u32 fib_index,
841              u16 flags, u32 thread_index, u8 is_resync)
842 {
843   nat_ha_event_t event;
844
845   skip_if_disabled ();
846
847   clib_memset (&event, 0, sizeof (event));
848   event.event_type = NAT_HA_ADD;
849   event.flags = clib_host_to_net_u16 (flags);
850   event.in_addr = in_addr->as_u32;
851   event.in_port = in_port;
852   event.out_addr = out_addr->as_u32;
853   event.out_port = out_port;
854   event.eh_addr = eh_addr->as_u32;
855   event.eh_port = eh_port;
856   event.ehn_addr = ehn_addr->as_u32;
857   event.ehn_port = ehn_port;
858   event.fib_index = clib_host_to_net_u32 (fib_index);
859   event.protocol = proto;
860   nat_ha_event_add (&event, 0, thread_index, is_resync);
861 }
862
863 void
864 nat_ha_sdel (ip4_address_t * out_addr, u16 out_port, ip4_address_t * eh_addr,
865              u16 eh_port, u8 proto, u32 fib_index, u32 thread_index)
866 {
867   nat_ha_event_t event;
868
869   skip_if_disabled ();
870
871   clib_memset (&event, 0, sizeof (event));
872   event.event_type = NAT_HA_DEL;
873   event.out_addr = out_addr->as_u32;
874   event.out_port = out_port;
875   event.eh_addr = eh_addr->as_u32;
876   event.eh_port = eh_port;
877   event.fib_index = clib_host_to_net_u32 (fib_index);
878   event.protocol = proto;
879   nat_ha_event_add (&event, 0, thread_index, 0);
880 }
881
882 void
883 nat_ha_sref (ip4_address_t * out_addr, u16 out_port, ip4_address_t * eh_addr,
884              u16 eh_port, u8 proto, u32 fib_index, u32 total_pkts,
885              u64 total_bytes, u32 thread_index, f64 * last_refreshed, f64 now)
886 {
887   nat_ha_main_t *ha = &nat_ha_main;
888   nat_ha_event_t event;
889
890   skip_if_disabled ();
891
892   if ((*last_refreshed + ha->session_refresh_interval) > now)
893     return;
894
895   *last_refreshed = now;
896   clib_memset (&event, 0, sizeof (event));
897   event.event_type = NAT_HA_REFRESH;
898   event.out_addr = out_addr->as_u32;
899   event.out_port = out_port;
900   event.eh_addr = eh_addr->as_u32;
901   event.eh_port = eh_port;
902   event.fib_index = clib_host_to_net_u32 (fib_index);
903   event.protocol = proto;
904   event.total_pkts = clib_host_to_net_u32 (total_pkts);
905   event.total_bytes = clib_host_to_net_u64 (total_bytes);
906   nat_ha_event_add (&event, 0, thread_index, 0);
907 }
908
909 static_always_inline u8
910 plugin_enabled ()
911 {
912   nat_ha_main_t *ha = &nat_ha_main;
913   return ha->enabled;
914 }
915
916 /* per thread process waiting for interrupt */
917 static uword
918 nat_ha_worker_fn (vlib_main_t * vm, vlib_node_runtime_t * rt,
919                   vlib_frame_t * f)
920 {
921   u32 thread_index = vm->thread_index;
922
923   if (plugin_enabled () == 0)
924     return 0;
925
926   /* flush HA NAT data under construction */
927   nat_ha_event_add (0, 1, thread_index, 0);
928   /* scan if we need to resend some non-ACKed data */
929   nat_ha_resend_scan (vlib_time_now (vm), thread_index);
930   return 0;
931 }
932
933 /* *INDENT-OFF* */
934 VLIB_REGISTER_NODE (nat_ha_worker_node) = {
935     .function = nat_ha_worker_fn,
936     .type = VLIB_NODE_TYPE_INPUT,
937     .state = VLIB_NODE_STATE_INTERRUPT,
938     .name = "nat-ha-worker",
939 };
940 /* *INDENT-ON* */
941
942 /* periodically send interrupt to each thread */
943 static uword
944 nat_ha_process (vlib_main_t * vm, vlib_node_runtime_t * rt, vlib_frame_t * f)
945 {
946   nat_ha_main_t *ha = &nat_ha_main;
947   uword event_type;
948   uword *event_data = 0;
949   u32 ti;
950
951   vlib_process_wait_for_event (vm);
952   event_type = vlib_process_get_events (vm, &event_data);
953   if (event_type)
954     nat_elog_info ("nat-ha-process: bogus kickoff event received");
955   vec_reset_length (event_data);
956
957   while (1)
958     {
959       vlib_process_wait_for_event_or_clock (vm, 1.0);
960       event_type = vlib_process_get_events (vm, &event_data);
961       vec_reset_length (event_data);
962       for (ti = 0; ti < vec_len (vlib_mains); ti++)
963         {
964           if (ti >= vec_len (ha->per_thread_data))
965             continue;
966
967           vlib_node_set_interrupt_pending (vlib_mains[ti],
968                                            nat_ha_worker_node.index);
969         }
970     }
971
972   return 0;
973 }
974
975 /* *INDENT-OFF* */
976 VLIB_REGISTER_NODE (nat_ha_process_node) = {
977     .function = nat_ha_process,
978     .type = VLIB_NODE_TYPE_PROCESS,
979     .name = "nat-ha-process",
980 };
981 /* *INDENT-ON* */
982
983 void
984 nat_ha_get_resync_status (u8 * in_resync, u32 * resync_ack_missed)
985 {
986   nat_ha_main_t *ha = &nat_ha_main;
987
988   *in_resync = ha->in_resync;
989   *resync_ack_missed = ha->resync_ack_missed;
990 }
991
992 typedef struct
993 {
994   ip4_address_t addr;
995   u32 event_count;
996 } nat_ha_trace_t;
997
998 static u8 *
999 format_nat_ha_trace (u8 * s, va_list * args)
1000 {
1001   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1002   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1003   nat_ha_trace_t *t = va_arg (*args, nat_ha_trace_t *);
1004
1005   s =
1006     format (s, "nat-ha: %u events from %U", t->event_count,
1007             format_ip4_address, &t->addr);
1008
1009   return s;
1010 }
1011
1012 typedef enum
1013 {
1014   NAT_HA_NEXT_IP4_LOOKUP,
1015   NAT_HA_NEXT_DROP,
1016   NAT_HA_N_NEXT,
1017 } nat_ha_next_t;
1018
1019 #define foreach_nat_ha_error   \
1020 _(PROCESSED, "pkts-processed") \
1021 _(BAD_VERSION, "bad-version")
1022
1023 typedef enum
1024 {
1025 #define _(sym, str) NAT_HA_ERROR_##sym,
1026   foreach_nat_ha_error
1027 #undef _
1028     NAT_HA_N_ERROR,
1029 } nat_ha_error_t;
1030
1031 static char *nat_ha_error_strings[] = {
1032 #define _(sym, str) str,
1033   foreach_nat_ha_error
1034 #undef _
1035 };
1036
1037 /* process received HA NAT protocol messages */
1038 static uword
1039 nat_ha_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1040                 vlib_frame_t * frame)
1041 {
1042   u32 n_left_from, *from, next_index, *to_next;
1043   f64 now = vlib_time_now (vm);
1044   u32 thread_index = vm->thread_index;
1045   u32 pkts_processed = 0;
1046   ip4_main_t *i4m = &ip4_main;
1047   u8 host_config_ttl = i4m->host_config.ttl;
1048   nat_ha_main_t *ha = &nat_ha_main;
1049
1050   from = vlib_frame_vector_args (frame);
1051   n_left_from = frame->n_vectors;
1052   next_index = node->cached_next_index;
1053
1054   while (n_left_from > 0)
1055     {
1056       u32 n_left_to_next;
1057
1058       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1059
1060       while (n_left_from > 0 && n_left_to_next > 0)
1061         {
1062           u32 bi0, next0, src_addr0, dst_addr0;;
1063           vlib_buffer_t *b0;
1064           nat_ha_message_header_t *h0;
1065           nat_ha_event_t *e0;
1066           u16 event_count0, src_port0, dst_port0, old_len0;
1067           ip4_header_t *ip0;
1068           udp_header_t *udp0;
1069           ip_csum_t sum0;
1070
1071           bi0 = from[0];
1072           to_next[0] = bi0;
1073           from += 1;
1074           to_next += 1;
1075           n_left_from -= 1;
1076           n_left_to_next -= 1;
1077
1078           b0 = vlib_get_buffer (vm, bi0);
1079           h0 = vlib_buffer_get_current (b0);
1080           vlib_buffer_advance (b0, -sizeof (*udp0));
1081           udp0 = vlib_buffer_get_current (b0);
1082           vlib_buffer_advance (b0, -sizeof (*ip0));
1083           ip0 = vlib_buffer_get_current (b0);
1084
1085           next0 = NAT_HA_NEXT_DROP;
1086
1087           if (h0->version != NAT_HA_VERSION)
1088             {
1089               b0->error = node->errors[NAT_HA_ERROR_BAD_VERSION];
1090               goto done0;
1091             }
1092
1093           event_count0 = clib_net_to_host_u16 (h0->count);
1094           /* ACK for previously send data */
1095           if (!event_count0 && (h0->flags & NAT_HA_FLAG_ACK))
1096             {
1097               nat_ha_ack_recv (h0->sequence_number, thread_index);
1098               b0->error = node->errors[NAT_HA_ERROR_PROCESSED];
1099               goto done0;
1100             }
1101
1102           e0 = (nat_ha_event_t *) (h0 + 1);
1103
1104           /* process each event */
1105           while (event_count0)
1106             {
1107               nat_ha_event_process (e0, now, thread_index);
1108               event_count0--;
1109               e0 = (nat_ha_event_t *) ((u8 *) e0 + sizeof (nat_ha_event_t));
1110             }
1111
1112           next0 = NAT_HA_NEXT_IP4_LOOKUP;
1113           pkts_processed++;
1114
1115           /* reply with ACK */
1116           b0->current_length = sizeof (*ip0) + sizeof (*udp0) + sizeof (*h0);
1117
1118           src_addr0 = ip0->src_address.data_u32;
1119           dst_addr0 = ip0->dst_address.data_u32;
1120           ip0->src_address.data_u32 = dst_addr0;
1121           ip0->dst_address.data_u32 = src_addr0;
1122           old_len0 = ip0->length;
1123           ip0->length = clib_host_to_net_u16 (b0->current_length);
1124
1125           sum0 = ip0->checksum;
1126           sum0 = ip_csum_update (sum0, ip0->ttl, host_config_ttl,
1127                                  ip4_header_t, ttl);
1128           ip0->ttl = host_config_ttl;
1129           sum0 =
1130             ip_csum_update (sum0, old_len0, ip0->length, ip4_header_t,
1131                             length);
1132           ip0->checksum = ip_csum_fold (sum0);
1133
1134           udp0->checksum = 0;
1135           src_port0 = udp0->src_port;
1136           dst_port0 = udp0->dst_port;
1137           udp0->src_port = dst_port0;
1138           udp0->dst_port = src_port0;
1139           udp0->length =
1140             clib_host_to_net_u16 (b0->current_length - sizeof (*ip0));
1141
1142           h0->flags = NAT_HA_FLAG_ACK;
1143           h0->count = 0;
1144           vlib_increment_simple_counter (&ha->counters
1145                                          [NAT_HA_COUNTER_SEND_ACK],
1146                                          thread_index, 0, 1);
1147
1148         done0:
1149           if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1150                              && (b0->flags & VLIB_BUFFER_IS_TRACED)))
1151             {
1152               nat_ha_trace_t *t = vlib_add_trace (vm, node, b0, sizeof (*t));
1153               ip4_header_t *ip =
1154                 (void *) (b0->data + vnet_buffer (b0)->l3_hdr_offset);
1155               t->event_count = clib_net_to_host_u16 (h0->count);
1156               t->addr.as_u32 = ip->src_address.data_u32;
1157             }
1158
1159           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
1160                                            to_next, n_left_to_next,
1161                                            bi0, next0);
1162         }
1163
1164       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1165     }
1166
1167   vlib_node_increment_counter (vm, ha->ha_node_index, NAT_HA_ERROR_PROCESSED,
1168                                pkts_processed);
1169
1170   return frame->n_vectors;
1171 }
1172
1173 /* *INDENT-OFF* */
1174 VLIB_REGISTER_NODE (nat_ha_node) = {
1175   .function = nat_ha_node_fn,
1176   .name = "nat-ha",
1177   .vector_size = sizeof (u32),
1178   .format_trace = format_nat_ha_trace,
1179   .type = VLIB_NODE_TYPE_INTERNAL,
1180   .n_errors = ARRAY_LEN (nat_ha_error_strings),
1181   .error_strings = nat_ha_error_strings,
1182   .n_next_nodes = NAT_HA_N_NEXT,
1183   .next_nodes = {
1184      [NAT_HA_NEXT_IP4_LOOKUP] = "ip4-lookup",
1185      [NAT_HA_NEXT_DROP] = "error-drop",
1186   },
1187 };
1188 /* *INDENT-ON* */
1189
1190 typedef struct
1191 {
1192   u32 next_worker_index;
1193   u8 in2out;
1194 } nat_ha_handoff_trace_t;
1195
1196 #define foreach_nat_ha_handoff_error  \
1197 _(CONGESTION_DROP, "congestion drop") \
1198 _(SAME_WORKER, "same worker")         \
1199 _(DO_HANDOFF, "do handoff")
1200
1201 typedef enum
1202 {
1203 #define _(sym,str) NAT_HA_HANDOFF_ERROR_##sym,
1204   foreach_nat_ha_handoff_error
1205 #undef _
1206     NAT_HA_HANDOFF_N_ERROR,
1207 } nat_ha_handoff_error_t;
1208
1209 static char *nat_ha_handoff_error_strings[] = {
1210 #define _(sym,string) string,
1211   foreach_nat_ha_handoff_error
1212 #undef _
1213 };
1214
1215 static u8 *
1216 format_nat_ha_handoff_trace (u8 * s, va_list * args)
1217 {
1218   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
1219   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
1220   nat_ha_handoff_trace_t *t = va_arg (*args, nat_ha_handoff_trace_t *);
1221
1222   s =
1223     format (s, "NAT_HA_WORKER_HANDOFF: next-worker %d", t->next_worker_index);
1224
1225   return s;
1226 }
1227
1228 /* do worker handoff based on thread_index in NAT HA protcol header */
1229 static uword
1230 nat_ha_handoff_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1231                         vlib_frame_t * frame)
1232 {
1233   nat_ha_main_t *ha = &nat_ha_main;
1234   vlib_buffer_t *bufs[VLIB_FRAME_SIZE], **b;
1235   u32 n_enq, n_left_from, *from;
1236   u16 thread_indices[VLIB_FRAME_SIZE], *ti;
1237   u32 thread_index = vm->thread_index;
1238   u32 do_handoff = 0, same_worker = 0;
1239
1240   from = vlib_frame_vector_args (frame);
1241   n_left_from = frame->n_vectors;
1242   vlib_get_buffers (vm, from, bufs, n_left_from);
1243
1244   b = bufs;
1245   ti = thread_indices;
1246
1247   while (n_left_from > 0)
1248     {
1249       nat_ha_message_header_t *h0;
1250
1251       h0 = vlib_buffer_get_current (b[0]);
1252       ti[0] = clib_net_to_host_u32 (h0->thread_index);
1253
1254       if (ti[0] != thread_index)
1255         do_handoff++;
1256       else
1257         same_worker++;
1258
1259       if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
1260                          && (b[0]->flags & VLIB_BUFFER_IS_TRACED)))
1261         {
1262           nat_ha_handoff_trace_t *t =
1263             vlib_add_trace (vm, node, b[0], sizeof (*t));
1264           t->next_worker_index = ti[0];
1265         }
1266
1267       n_left_from -= 1;
1268       ti += 1;
1269       b += 1;
1270     }
1271
1272   n_enq =
1273     vlib_buffer_enqueue_to_thread (vm, ha->fq_index, from, thread_indices,
1274                                    frame->n_vectors, 1);
1275
1276   if (n_enq < frame->n_vectors)
1277     vlib_node_increment_counter (vm, node->node_index,
1278                                  NAT_HA_HANDOFF_ERROR_CONGESTION_DROP,
1279                                  frame->n_vectors - n_enq);
1280   vlib_node_increment_counter (vm, node->node_index,
1281                                NAT_HA_HANDOFF_ERROR_SAME_WORKER, same_worker);
1282   vlib_node_increment_counter (vm, node->node_index,
1283                                NAT_HA_HANDOFF_ERROR_DO_HANDOFF, do_handoff);
1284   return frame->n_vectors;
1285 }
1286
1287 int
1288 nat_ha_resync (u32 client_index, u32 pid,
1289                nat_ha_resync_event_cb_t event_callback)
1290 {
1291   return 0;
1292 }
1293
1294 /* *INDENT-OFF* */
1295 VLIB_REGISTER_NODE (nat_ha_handoff_node) = {
1296   .function = nat_ha_handoff_node_fn,
1297   .name = "nat-ha-handoff",
1298   .vector_size = sizeof (u32),
1299   .format_trace = format_nat_ha_handoff_trace,
1300   .type = VLIB_NODE_TYPE_INTERNAL,
1301   .n_errors = ARRAY_LEN(nat_ha_handoff_error_strings),
1302   .error_strings = nat_ha_handoff_error_strings,
1303   .n_next_nodes = 1,
1304   .next_nodes = {
1305     [0] = "error-drop",
1306   },
1307 };
1308 /* *INDENT-ON* */
1309
1310 /*
1311  * fd.io coding-style-patch-verification: ON
1312  *
1313  * Local Variables:
1314  * eval: (c-set-style "gnu")
1315  * End:
1316  */