Support lb on both vip and per-port-vip case
[vpp.git] / src / plugins / lb / 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
16 #include <lb/lb.h>
17 #include <vnet/fib/ip4_fib.h>
18
19 #include <vnet/gre/packet.h>
20 #include <lb/lbhash.h>
21
22 #define foreach_lb_error \
23  _(NONE, "no error") \
24  _(PROTO_NOT_SUPPORTED, "protocol not supported")
25
26 typedef enum
27 {
28 #define _(sym,str) LB_ERROR_##sym,
29   foreach_lb_error
30 #undef _
31   LB_N_ERROR,
32 } lb_error_t;
33
34 static char *lb_error_strings[] =
35   {
36 #define _(sym,string) string,
37       foreach_lb_error
38 #undef _
39     };
40
41 typedef struct
42 {
43   u32 vip_index;
44   u32 as_index;
45 } lb_trace_t;
46
47 typedef struct
48 {
49   u32 vip_index;
50
51   u32 node_port;
52 } lb_nodeport_trace_t;
53
54 typedef struct
55 {
56   u32 vip_index;
57   u32 as_index;
58   u32 rx_sw_if_index;
59   u32 next_index;
60 } lb_nat_trace_t;
61
62 u8 *
63 format_lb_trace (u8 * s, va_list * args)
64 {
65   lb_main_t *lbm = &lb_main;
66   CLIB_UNUSED(vlib_main_t * vm)
67 = va_arg (*args, vlib_main_t *);
68     CLIB_UNUSED(vlib_node_t * node)
69   = va_arg (*args, vlib_node_t *);
70   lb_trace_t *t = va_arg (*args, lb_trace_t *);
71   if (pool_is_free_index(lbm->vips, t->vip_index))
72     {
73       s = format (s, "lb vip[%d]: This VIP was freed since capture\n");
74     }
75   else
76     {
77       s = format (s, "lb vip[%d]: %U\n", t->vip_index, format_lb_vip,
78                   &lbm->vips[t->vip_index]);
79     }
80   if (pool_is_free_index(lbm->ass, t->as_index))
81     {
82       s = format (s, "lb as[%d]: This AS was freed since capture\n");
83     }
84   else
85     {
86       s = format (s, "lb as[%d]: %U\n", t->as_index, format_lb_as,
87                   &lbm->ass[t->as_index]);
88     }
89   return s;
90 }
91
92 u8 *
93 format_lb_nat_trace (u8 * s, va_list * args)
94 {
95   lb_main_t *lbm = &lb_main;
96   CLIB_UNUSED(vlib_main_t * vm)
97 = va_arg (*args, vlib_main_t *);
98     CLIB_UNUSED(vlib_node_t * node)
99   = va_arg (*args, vlib_node_t *);
100   lb_nat_trace_t *t = va_arg (*args, lb_nat_trace_t *);
101
102   if (pool_is_free_index(lbm->vips, t->vip_index))
103     {
104       s = format (s, "lb vip[%d]: This VIP was freed since capture\n");
105     }
106   else
107     {
108       s = format (s, "lb vip[%d]: %U\n", t->vip_index, format_lb_vip,
109                   &lbm->vips[t->vip_index]);
110     }
111   if (pool_is_free_index(lbm->ass, t->as_index))
112     {
113       s = format (s, "lb as[%d]: This AS was freed since capture\n");
114     }
115   else
116     {
117       s = format (s, "lb as[%d]: %U\n", t->as_index, format_lb_as,
118                   &lbm->ass[t->as_index]);
119     }
120   s = format (s, "lb nat: rx_sw_if_index = %d, next_index = %d",
121               t->rx_sw_if_index, t->next_index);
122
123   return s;
124 }
125
126 lb_hash_t *
127 lb_get_sticky_table (u32 thread_index)
128 {
129   lb_main_t *lbm = &lb_main;
130   lb_hash_t *sticky_ht = lbm->per_cpu[thread_index].sticky_ht;
131   //Check if size changed
132   if (PREDICT_FALSE(
133       sticky_ht && (lbm->per_cpu_sticky_buckets != lb_hash_nbuckets(sticky_ht))))
134     {
135       //Dereference everything in there
136       lb_hash_bucket_t *b;
137       u32 i;
138       lb_hash_foreach_entry(sticky_ht, b, i)
139         {
140           vlib_refcount_add (&lbm->as_refcount, thread_index, b->value[i], -1);
141           vlib_refcount_add (&lbm->as_refcount, thread_index, 0, 1);
142         }
143
144       lb_hash_free (sticky_ht);
145       sticky_ht = NULL;
146     }
147
148   //Create if necessary
149   if (PREDICT_FALSE(sticky_ht == NULL))
150     {
151       lbm->per_cpu[thread_index].sticky_ht = lb_hash_alloc (
152           lbm->per_cpu_sticky_buckets, lbm->flow_timeout);
153       sticky_ht = lbm->per_cpu[thread_index].sticky_ht;
154       clib_warning("Regenerated sticky table %p", sticky_ht);
155     }
156
157   ASSERT(sticky_ht);
158
159   //Update timeout
160   sticky_ht->timeout = lbm->flow_timeout;
161   return sticky_ht;
162 }
163
164 u64
165 lb_node_get_other_ports4 (ip4_header_t *ip40)
166 {
167   return 0;
168 }
169
170 u64
171 lb_node_get_other_ports6 (ip6_header_t *ip60)
172 {
173   return 0;
174 }
175
176 static_always_inline void
177 lb_node_get_hash (lb_main_t *lbm, vlib_buffer_t *p, u8 is_input_v4,
178                   u32 *hash, u32 *vip_idx, u8 per_port_vip)
179 {
180   vip_port_key_t key;
181   clib_bihash_kv_8_8_t kv, value;
182
183   /* For vip case, retrieve vip index for ip lookup */
184   *vip_idx = vnet_buffer (p)->ip.adj_index[VLIB_TX];
185
186   if (per_port_vip)
187     {
188       /* For per-port-vip case, ip lookup stores dummy index */
189       key.vip_prefix_index = *vip_idx;
190     }
191
192   if (is_input_v4)
193     {
194       ip4_header_t *ip40;
195       u64 ports;
196
197       ip40 = vlib_buffer_get_current (p);
198       if (PREDICT_TRUE(
199           ip40->protocol == IP_PROTOCOL_TCP
200               || ip40->protocol == IP_PROTOCOL_UDP))
201         ports = ((u64) ((udp_header_t *) (ip40 + 1))->src_port << 16)
202             | ((u64) ((udp_header_t *) (ip40 + 1))->dst_port);
203       else
204         ports = lb_node_get_other_ports4 (ip40);
205
206       *hash = lb_hash_hash (*((u64 *) &ip40->address_pair), ports, 0, 0, 0);
207
208       if (per_port_vip)
209         {
210           key.protocol = ip40->protocol;
211           key.port = (u16)(ports & 0xFFFF);
212         }
213     }
214   else
215     {
216       ip6_header_t *ip60;
217       ip60 = vlib_buffer_get_current (p);
218       u64 ports;
219
220       if (PREDICT_TRUE(
221           ip60->protocol == IP_PROTOCOL_TCP
222               || ip60->protocol == IP_PROTOCOL_UDP))
223         ports = ((u64) ((udp_header_t *) (ip60 + 1))->src_port << 16)
224             | ((u64) ((udp_header_t *) (ip60 + 1))->dst_port);
225       else
226         ports = lb_node_get_other_ports6 (ip60);
227
228       *hash = lb_hash_hash (ip60->src_address.as_u64[0],
229                            ip60->src_address.as_u64[1],
230                            ip60->dst_address.as_u64[0],
231                            ip60->dst_address.as_u64[1], ports);
232
233       if (per_port_vip)
234         {
235           key.protocol = ip60->protocol;
236           key.port = (u16)(ports & 0xFFFF);
237         }
238     }
239
240   /* For per-port-vip case, retrieve vip index for vip_port_filter table */
241   if (per_port_vip)
242     {
243       kv.key = key.as_u64;
244       if (clib_bihash_search_8_8(&lbm->vip_index_per_port, &kv, &value) < 0)
245         {
246           /* return default vip */
247           *vip_idx = 0;
248           return;
249         }
250       *vip_idx = value.value;
251     }
252 }
253
254 static_always_inline uword
255 lb_node_fn (vlib_main_t * vm,
256             vlib_node_runtime_t * node,
257             vlib_frame_t * frame,
258             u8 is_input_v4, //Compile-time parameter stating that is input is v4 (or v6)
259             lb_encap_type_t encap_type, //Compile-time parameter is GRE4/GRE6/L3DSR/NAT4/NAT6
260             u8 per_port_vip) //Compile-time parameter stating that is per_port_vip or not
261 {
262   lb_main_t *lbm = &lb_main;
263   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
264   u32 thread_index = vm->thread_index;
265   u32 lb_time = lb_hash_time_now (vm);
266
267   lb_hash_t *sticky_ht = lb_get_sticky_table (thread_index);
268   from = vlib_frame_vector_args (frame);
269   n_left_from = frame->n_vectors;
270   next_index = node->cached_next_index;
271
272   u32 nexthash0 = 0;
273   u32 next_vip_idx0 = ~0;
274   if (PREDICT_TRUE(n_left_from > 0))
275     {
276       vlib_buffer_t *p0 = vlib_get_buffer (vm, from[0]);
277       lb_node_get_hash (lbm, p0, is_input_v4, &nexthash0,
278                         &next_vip_idx0, per_port_vip);
279     }
280
281   while (n_left_from > 0)
282     {
283       vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
284       while (n_left_from > 0 && n_left_to_next > 0)
285         {
286           u32 pi0;
287           vlib_buffer_t *p0;
288           lb_vip_t *vip0;
289           u32 asindex0 = 0;
290           u16 len0;
291           u32 available_index0;
292           u8 counter = 0;
293           u32 hash0 = nexthash0;
294           u32 vip_index0 = next_vip_idx0;
295           u32 next0;
296
297           if (PREDICT_TRUE(n_left_from > 1))
298             {
299               vlib_buffer_t *p1 = vlib_get_buffer (vm, from[1]);
300               //Compute next hash and prefetch bucket
301               lb_node_get_hash (lbm, p1, is_input_v4,
302                                 &nexthash0, &next_vip_idx0,
303                                 per_port_vip);
304               lb_hash_prefetch_bucket (sticky_ht, nexthash0);
305               //Prefetch for encap, next
306               CLIB_PREFETCH(vlib_buffer_get_current (p1) - 64, 64, STORE);
307             }
308
309           if (PREDICT_TRUE(n_left_from > 2))
310             {
311               vlib_buffer_t *p2;
312               p2 = vlib_get_buffer (vm, from[2]);
313               /* prefetch packet header and data */
314               vlib_prefetch_buffer_header(p2, STORE);
315               CLIB_PREFETCH(vlib_buffer_get_current (p2), 64, STORE);
316             }
317
318           pi0 = to_next[0] = from[0];
319           from += 1;
320           n_left_from -= 1;
321           to_next += 1;
322           n_left_to_next -= 1;
323
324           p0 = vlib_get_buffer (vm, pi0);
325
326           vip0 = pool_elt_at_index(lbm->vips, vip_index0);
327
328           if (is_input_v4)
329             {
330               ip4_header_t *ip40;
331               ip40 = vlib_buffer_get_current (p0);
332               len0 = clib_net_to_host_u16 (ip40->length);
333             }
334           else
335             {
336               ip6_header_t *ip60;
337               ip60 = vlib_buffer_get_current (p0);
338               len0 = clib_net_to_host_u16 (ip60->payload_length)
339                   + sizeof(ip6_header_t);
340             }
341
342           lb_hash_get (sticky_ht, hash0,
343                        vip_index0, lb_time,
344                        &available_index0, &asindex0);
345
346           if (PREDICT_TRUE(asindex0 != ~0))
347             {
348               //Found an existing entry
349               counter = LB_VIP_COUNTER_NEXT_PACKET;
350             }
351           else if (PREDICT_TRUE(available_index0 != ~0))
352             {
353               //There is an available slot for a new flow
354               asindex0 =
355                   vip0->new_flow_table[hash0 & vip0->new_flow_table_mask].as_index;
356               counter = LB_VIP_COUNTER_FIRST_PACKET;
357               counter = (asindex0 == 0) ? LB_VIP_COUNTER_NO_SERVER : counter;
358
359               //TODO: There are race conditions with as0 and vip0 manipulation.
360               //Configuration may be changed, vectors resized, etc...
361
362               //Dereference previously used
363               vlib_refcount_add (
364                   &lbm->as_refcount, thread_index,
365                   lb_hash_available_value (sticky_ht, hash0, available_index0),
366                   -1);
367               vlib_refcount_add (&lbm->as_refcount, thread_index, asindex0, 1);
368
369               //Add sticky entry
370               //Note that when there is no AS configured, an entry is configured anyway.
371               //But no configured AS is not something that should happen
372               lb_hash_put (sticky_ht, hash0, asindex0,
373                            vip_index0,
374                            available_index0, lb_time);
375             }
376           else
377             {
378               //Could not store new entry in the table
379               asindex0 =
380                   vip0->new_flow_table[hash0 & vip0->new_flow_table_mask].as_index;
381               counter = LB_VIP_COUNTER_UNTRACKED_PACKET;
382             }
383
384           vlib_increment_simple_counter (
385               &lbm->vip_counters[counter], thread_index,
386               vip_index0,
387               1);
388
389           //Now let's encap
390           if ((encap_type == LB_ENCAP_TYPE_GRE4)
391               || (encap_type == LB_ENCAP_TYPE_GRE6))
392             {
393               gre_header_t *gre0;
394               if (encap_type == LB_ENCAP_TYPE_GRE4) /* encap GRE4*/
395                 {
396                   ip4_header_t *ip40;
397                   vlib_buffer_advance (
398                       p0, -sizeof(ip4_header_t) - sizeof(gre_header_t));
399                   ip40 = vlib_buffer_get_current (p0);
400                   gre0 = (gre_header_t *) (ip40 + 1);
401                   ip40->src_address = lbm->ip4_src_address;
402                   ip40->dst_address = lbm->ass[asindex0].address.ip4;
403                   ip40->ip_version_and_header_length = 0x45;
404                   ip40->ttl = 128;
405                   ip40->fragment_id = 0;
406                   ip40->flags_and_fragment_offset = 0;
407                   ip40->length = clib_host_to_net_u16 (
408                       len0 + sizeof(gre_header_t) + sizeof(ip4_header_t));
409                   ip40->protocol = IP_PROTOCOL_GRE;
410                   ip40->checksum = ip4_header_checksum (ip40);
411                 }
412               else /* encap GRE6*/
413                 {
414                   ip6_header_t *ip60;
415                   vlib_buffer_advance (
416                       p0, -sizeof(ip6_header_t) - sizeof(gre_header_t));
417                   ip60 = vlib_buffer_get_current (p0);
418                   gre0 = (gre_header_t *) (ip60 + 1);
419                   ip60->dst_address = lbm->ass[asindex0].address.ip6;
420                   ip60->src_address = lbm->ip6_src_address;
421                   ip60->hop_limit = 128;
422                   ip60->ip_version_traffic_class_and_flow_label =
423                       clib_host_to_net_u32 (0x6 << 28);
424                   ip60->payload_length = clib_host_to_net_u16 (
425                       len0 + sizeof(gre_header_t));
426                   ip60->protocol = IP_PROTOCOL_GRE;
427                 }
428
429               gre0->flags_and_version = 0;
430               gre0->protocol =
431                   (is_input_v4) ?
432                       clib_host_to_net_u16 (0x0800) :
433                       clib_host_to_net_u16 (0x86DD);
434             }
435           else if (encap_type == LB_ENCAP_TYPE_L3DSR) /* encap L3DSR*/
436             {
437               ip4_header_t *ip40;
438               tcp_header_t *th0;
439               ip_csum_t csum;
440               u32 old_dst, new_dst;
441               u8 old_tos, new_tos;
442
443               ip40 = vlib_buffer_get_current (p0);
444               old_dst = ip40->dst_address.as_u32;
445               new_dst = lbm->ass[asindex0].address.ip4.as_u32;
446               ip40->dst_address.as_u32 = lbm->ass[asindex0].address.ip4.as_u32;
447               /* Get and rewrite DSCP bit */
448               old_tos = ip40->tos;
449               new_tos = (u8) ((vip0->encap_args.dscp & 0x3F) << 2);
450               ip40->tos = (u8) ((vip0->encap_args.dscp & 0x3F) << 2);
451
452               csum = ip40->checksum;
453               csum = ip_csum_update (csum, old_tos, new_tos,
454                                      ip4_header_t,
455                                      tos /* changed member */);
456               csum = ip_csum_update (csum, old_dst, new_dst,
457                                      ip4_header_t,
458                                      dst_address /* changed member */);
459               ip40->checksum = ip_csum_fold (csum);
460
461               /* Recomputing L4 checksum after dst-IP modifying */
462               th0 = ip4_next_header (ip40);
463               th0->checksum = 0;
464               th0->checksum = ip4_tcp_udp_compute_checksum (vm, p0, ip40);
465             }
466           else if ((encap_type == LB_ENCAP_TYPE_NAT4)
467               || (encap_type == LB_ENCAP_TYPE_NAT6))
468             {
469               ip_csum_t csum;
470               udp_header_t *uh;
471
472               /* do NAT */
473               if ((is_input_v4 == 1) && (encap_type == LB_ENCAP_TYPE_NAT4))
474                 {
475                   /* NAT44 */
476                   ip4_header_t *ip40;
477                   u32 old_dst;
478                   ip40 = vlib_buffer_get_current (p0);
479                   uh = (udp_header_t *) (ip40 + 1);
480                   old_dst = ip40->dst_address.as_u32;
481                   ip40->dst_address = lbm->ass[asindex0].address.ip4;
482
483                   csum = ip40->checksum;
484                   csum = ip_csum_sub_even (csum, old_dst);
485                   csum = ip_csum_add_even (
486                       csum, lbm->ass[asindex0].address.ip4.as_u32);
487                   ip40->checksum = ip_csum_fold (csum);
488
489                   if (ip40->protocol == IP_PROTOCOL_UDP)
490                     {
491                       uh->dst_port = vip0->encap_args.target_port;
492                       csum = uh->checksum;
493                       csum = ip_csum_sub_even (csum, old_dst);
494                       csum = ip_csum_add_even (
495                           csum, lbm->ass[asindex0].address.ip4.as_u32);
496                       uh->checksum = ip_csum_fold (csum);
497                     }
498                   else
499                     {
500                       asindex0 = 0;
501                     }
502                 }
503               else if ((is_input_v4 == 0) && (encap_type == LB_ENCAP_TYPE_NAT6))
504                 {
505                   /* NAT66 */
506                   ip6_header_t *ip60;
507                   ip6_address_t old_dst;
508
509                   ip60 = vlib_buffer_get_current (p0);
510                   uh = (udp_header_t *) (ip60 + 1);
511
512                   old_dst.as_u64[0] = ip60->dst_address.as_u64[0];
513                   old_dst.as_u64[1] = ip60->dst_address.as_u64[1];
514                   ip60->dst_address.as_u64[0] =
515                       lbm->ass[asindex0].address.ip6.as_u64[0];
516                   ip60->dst_address.as_u64[1] =
517                       lbm->ass[asindex0].address.ip6.as_u64[1];
518
519                   if (PREDICT_TRUE(ip60->protocol == IP_PROTOCOL_UDP))
520                     {
521                       uh->dst_port = vip0->encap_args.target_port;
522                       csum = uh->checksum;
523                       csum = ip_csum_sub_even (csum, old_dst.as_u64[0]);
524                       csum = ip_csum_sub_even (csum, old_dst.as_u64[1]);
525                       csum = ip_csum_add_even (
526                           csum, lbm->ass[asindex0].address.ip6.as_u64[0]);
527                       csum = ip_csum_add_even (
528                           csum, lbm->ass[asindex0].address.ip6.as_u64[1]);
529                       uh->checksum = ip_csum_fold (csum);
530                     }
531                   else
532                     {
533                       asindex0 = 0;
534                     }
535                 }
536             }
537           next0 = lbm->ass[asindex0].dpo.dpoi_next_node;
538           //Note that this is going to error if asindex0 == 0
539           vnet_buffer (p0)->ip.adj_index[VLIB_TX] =
540               lbm->ass[asindex0].dpo.dpoi_index;
541
542           if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED))
543             {
544               lb_trace_t *tr = vlib_add_trace (vm, node, p0, sizeof(*tr));
545               tr->as_index = asindex0;
546               tr->vip_index = vip_index0;
547             }
548
549           //Enqueue to next
550           vlib_validate_buffer_enqueue_x1(
551               vm, node, next_index, to_next, n_left_to_next, pi0, next0);
552         }
553       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
554     }
555
556   return frame->n_vectors;
557 }
558
559 u8 *
560 format_nodeport_lb_trace (u8 * s, va_list * args)
561 {
562   lb_main_t *lbm = &lb_main;
563   CLIB_UNUSED(vlib_main_t * vm)
564 = va_arg (*args, vlib_main_t *);
565     CLIB_UNUSED(vlib_node_t * node)
566   = va_arg (*args, vlib_node_t *);
567   lb_nodeport_trace_t *t = va_arg (*args, lb_nodeport_trace_t *);
568   if (pool_is_free_index(lbm->vips, t->vip_index))
569     {
570       s = format (s, "lb vip[%d]: This VIP was freed since capture\n");
571     }
572   else
573     {
574       s = format (s, "lb vip[%d]: %U\n", t->vip_index, format_lb_vip,
575                   &lbm->vips[t->vip_index]);
576     }
577
578   s = format (s, "  lb node_port: %d", t->node_port);
579
580   return s;
581 }
582
583 static uword
584 lb_nodeport_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
585                      vlib_frame_t * frame, u8 is_input_v4)
586 {
587   lb_main_t *lbm = &lb_main;
588   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
589
590   from = vlib_frame_vector_args (frame);
591   n_left_from = frame->n_vectors;
592   next_index = node->cached_next_index;
593
594   while (n_left_from > 0)
595     {
596       vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
597
598       while (n_left_from > 0 && n_left_to_next > 0)
599         {
600           u32 pi0;
601           vlib_buffer_t *p0;
602           udp_header_t * udp_0;
603           uword * entry0;
604
605           if (PREDICT_TRUE(n_left_from > 1))
606             {
607               vlib_buffer_t *p1 = vlib_get_buffer (vm, from[1]);
608               //Prefetch for encap, next
609               CLIB_PREFETCH(vlib_buffer_get_current (p1) - 64, 64, STORE);
610             }
611
612           if (PREDICT_TRUE(n_left_from > 2))
613             {
614               vlib_buffer_t *p2;
615               p2 = vlib_get_buffer (vm, from[2]);
616               /* prefetch packet header and data */
617               vlib_prefetch_buffer_header(p2, STORE);
618               CLIB_PREFETCH(vlib_buffer_get_current (p2), 64, STORE);
619             }
620
621           pi0 = to_next[0] = from[0];
622           from += 1;
623           n_left_from -= 1;
624           to_next += 1;
625           n_left_to_next -= 1;
626
627           p0 = vlib_get_buffer (vm, pi0);
628
629           if (is_input_v4)
630             {
631               ip4_header_t *ip40;
632               vlib_buffer_advance (
633                   p0, -(word) (sizeof(udp_header_t) + sizeof(ip4_header_t)));
634               ip40 = vlib_buffer_get_current (p0);
635               udp_0 = (udp_header_t *) (ip40 + 1);
636             }
637           else
638             {
639               ip6_header_t *ip60;
640               vlib_buffer_advance (
641                   p0, -(word) (sizeof(udp_header_t) + sizeof(ip6_header_t)));
642               ip60 = vlib_buffer_get_current (p0);
643               udp_0 = (udp_header_t *) (ip60 + 1);
644             }
645
646           entry0 = hash_get_mem(lbm->vip_index_by_nodeport, &(udp_0->dst_port));
647
648           //Enqueue to next
649           vnet_buffer(p0)->ip.adj_index[VLIB_TX] = entry0[0];
650
651           if (PREDICT_FALSE(p0->flags & VLIB_BUFFER_IS_TRACED))
652             {
653               lb_nodeport_trace_t *tr = vlib_add_trace (vm, node, p0,
654                                                         sizeof(*tr));
655               tr->vip_index = entry0[0];
656               tr->node_port = (u32) clib_net_to_host_u16 (udp_0->dst_port);
657             }
658
659           vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next,
660               n_left_to_next, pi0,
661               is_input_v4 ?
662                   LB4_NODEPORT_NEXT_IP4_NAT4 : LB6_NODEPORT_NEXT_IP6_NAT6);
663         }
664       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
665     }
666
667   return frame->n_vectors;
668
669 }
670
671 /**
672  * @brief Match NAT44 static mapping.
673  *
674  * @param sm          NAT main.
675  * @param match       Address and port to match.
676  * @param index       index to the pool.
677  *
678  * @returns 0 if match found, otherwise -1.
679  */
680 int
681 lb_nat44_mapping_match (lb_main_t *lbm, lb_snat4_key_t * match, u32 *index)
682 {
683   clib_bihash_kv_8_8_t kv4, value;
684   clib_bihash_8_8_t *mapping_hash = &lbm->mapping_by_as4;
685
686   kv4.key = match->as_u64;
687   kv4.value = 0;
688   if (clib_bihash_search_8_8 (mapping_hash, &kv4, &value))
689     {
690       return 1;
691     }
692
693   *index = value.value;
694   return 0;
695 }
696
697 /**
698  * @brief Match NAT66 static mapping.
699  *
700  * @param sm          NAT main.
701  * @param match       Address and port to match.
702  * @param mapping     External or local address and port of the matched mapping.
703  *
704  * @returns 0 if match found otherwise 1.
705  */
706 int
707 lb_nat66_mapping_match (lb_main_t *lbm, lb_snat6_key_t * match, u32 *index)
708 {
709   clib_bihash_kv_24_8_t kv6, value;
710   lb_snat6_key_t m_key6;
711   clib_bihash_24_8_t *mapping_hash = &lbm->mapping_by_as6;
712
713   m_key6.addr.as_u64[0] = match->addr.as_u64[0];
714   m_key6.addr.as_u64[1] = match->addr.as_u64[1];
715   m_key6.port = match->port;
716   m_key6.protocol = 0;
717   m_key6.fib_index = 0;
718
719   kv6.key[0] = m_key6.as_u64[0];
720   kv6.key[1] = m_key6.as_u64[1];
721   kv6.key[2] = m_key6.as_u64[2];
722   kv6.value = 0;
723   if (clib_bihash_search_24_8 (mapping_hash, &kv6, &value))
724     {
725       return 1;
726     }
727
728   *index = value.value;
729   return 0;
730 }
731
732 static uword
733 lb_nat_in2out_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
734                        vlib_frame_t * frame, u32 is_nat4)
735 {
736   u32 n_left_from, *from, *to_next;
737   u32 next_index;
738   u32 pkts_processed = 0;
739   lb_main_t *lbm = &lb_main;
740   u32 stats_node_index;
741
742   stats_node_index =
743       is_nat4 ? lb_nat4_in2out_node.index : lb_nat6_in2out_node.index;
744
745   from = vlib_frame_vector_args (frame);
746   n_left_from = frame->n_vectors;
747   next_index = node->cached_next_index;
748
749   while (n_left_from > 0)
750     {
751       u32 n_left_to_next;
752
753       vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
754
755       while (n_left_from > 0 && n_left_to_next > 0)
756         {
757           u32 bi0;
758           vlib_buffer_t * b0;
759           u32 next0;
760           u32 sw_if_index0;
761           ip_csum_t csum;
762           u16 old_port0, new_port0;
763           udp_header_t * udp0;
764           tcp_header_t * tcp0;
765
766           u32 proto0;
767           u32 rx_fib_index0;
768
769           /* speculatively enqueue b0 to the current next frame */
770           bi0 = from[0];
771           to_next[0] = bi0;
772           from += 1;
773           to_next += 1;
774           n_left_from -= 1;
775           n_left_to_next -= 1;
776
777           b0 = vlib_get_buffer (vm, bi0);
778           next0 = LB_NAT4_IN2OUT_NEXT_LOOKUP;
779           sw_if_index0 = vnet_buffer(b0)->sw_if_index[VLIB_RX];
780           rx_fib_index0 = ip4_fib_table_get_index_for_sw_if_index (
781               sw_if_index0);
782
783           if (is_nat4)
784             {
785               ip4_header_t * ip40;
786               u32 old_addr0, new_addr0;
787               lb_snat4_key_t key40;
788               lb_snat_mapping_t *sm40;
789               u32 index40;
790
791               ip40 = vlib_buffer_get_current (b0);
792               udp0 = ip4_next_header (ip40);
793               tcp0 = (tcp_header_t *) udp0;
794               proto0 = lb_ip_proto_to_nat_proto (ip40->protocol);
795
796               key40.addr = ip40->src_address;
797               key40.protocol = proto0;
798               key40.port = udp0->src_port;
799               key40.fib_index = rx_fib_index0;
800
801               if (lb_nat44_mapping_match (lbm, &key40, &index40))
802                 {
803                   next0 = LB_NAT4_IN2OUT_NEXT_DROP;
804                   goto trace0;
805                 }
806
807               sm40 = pool_elt_at_index(lbm->snat_mappings, index40);
808               new_addr0 = sm40->src_ip.ip4.as_u32;
809               new_port0 = sm40->src_port;
810               vnet_buffer(b0)->sw_if_index[VLIB_TX] = sm40->fib_index;
811               old_addr0 = ip40->src_address.as_u32;
812               ip40->src_address.as_u32 = new_addr0;
813
814               csum = ip40->checksum;
815               csum = ip_csum_sub_even (csum, old_addr0);
816               csum = ip_csum_add_even (csum, new_addr0);
817               ip40->checksum = ip_csum_fold (csum);
818
819               if (PREDICT_TRUE(proto0 == LB_NAT_PROTOCOL_TCP))
820                 {
821                   old_port0 = tcp0->src_port;
822                   tcp0->src_port = new_port0;
823
824                   csum = tcp0->checksum;
825                   csum = ip_csum_sub_even (csum, old_addr0);
826                   csum = ip_csum_sub_even (csum, old_port0);
827                   csum = ip_csum_add_even (csum, new_addr0);
828                   csum = ip_csum_add_even (csum, new_port0);
829                   tcp0->checksum = ip_csum_fold (csum);
830                 }
831               else if (PREDICT_TRUE(proto0 == LB_NAT_PROTOCOL_UDP))
832                 {
833                   old_port0 = udp0->src_port;
834                   udp0->src_port = new_port0;
835
836                   csum = udp0->checksum;
837                   csum = ip_csum_sub_even (csum, old_addr0);
838                   csum = ip_csum_sub_even (csum, old_port0);
839                   csum = ip_csum_add_even (csum, new_addr0);
840                   csum = ip_csum_add_even (csum, new_port0);
841                   udp0->checksum = ip_csum_fold (csum);
842                 }
843
844               pkts_processed += next0 != LB_NAT4_IN2OUT_NEXT_DROP;
845             }
846           else
847             {
848               ip6_header_t * ip60;
849               ip6_address_t old_addr0, new_addr0;
850               lb_snat6_key_t key60;
851               lb_snat_mapping_t *sm60;
852               u32 index60;
853
854               ip60 = vlib_buffer_get_current (b0);
855               udp0 = ip6_next_header (ip60);
856               tcp0 = (tcp_header_t *) udp0;
857               proto0 = lb_ip_proto_to_nat_proto (ip60->protocol);
858
859               key60.addr.as_u64[0] = ip60->src_address.as_u64[0];
860               key60.addr.as_u64[1] = ip60->src_address.as_u64[1];
861               key60.protocol = proto0;
862               key60.port = udp0->src_port;
863               key60.fib_index = rx_fib_index0;
864
865               if (lb_nat66_mapping_match (lbm, &key60, &index60))
866                 {
867                   next0 = LB_NAT6_IN2OUT_NEXT_DROP;
868                   goto trace0;
869                 }
870
871               sm60 = pool_elt_at_index(lbm->snat_mappings, index60);
872               new_addr0.as_u64[0] = sm60->src_ip.as_u64[0];
873               new_addr0.as_u64[1] = sm60->src_ip.as_u64[1];
874               new_port0 = sm60->src_port;
875               vnet_buffer(b0)->sw_if_index[VLIB_TX] = sm60->fib_index;
876               old_addr0.as_u64[0] = ip60->src_address.as_u64[0];
877               old_addr0.as_u64[1] = ip60->src_address.as_u64[1];
878               ip60->src_address.as_u64[0] = new_addr0.as_u64[0];
879               ip60->src_address.as_u64[1] = new_addr0.as_u64[1];
880
881               if (PREDICT_TRUE(proto0 == LB_NAT_PROTOCOL_TCP))
882                 {
883                   old_port0 = tcp0->src_port;
884                   tcp0->src_port = new_port0;
885
886                   csum = tcp0->checksum;
887                   csum = ip_csum_sub_even (csum, old_addr0.as_u64[0]);
888                   csum = ip_csum_sub_even (csum, old_addr0.as_u64[1]);
889                   csum = ip_csum_add_even (csum, new_addr0.as_u64[0]);
890                   csum = ip_csum_add_even (csum, new_addr0.as_u64[1]);
891                   csum = ip_csum_sub_even (csum, old_port0);
892                   csum = ip_csum_add_even (csum, new_port0);
893                   tcp0->checksum = ip_csum_fold (csum);
894                 }
895               else if (PREDICT_TRUE(proto0 == LB_NAT_PROTOCOL_UDP))
896                 {
897                   old_port0 = udp0->src_port;
898                   udp0->src_port = new_port0;
899
900                   csum = udp0->checksum;
901                   csum = ip_csum_sub_even (csum, old_addr0.as_u64[0]);
902                   csum = ip_csum_sub_even (csum, old_addr0.as_u64[1]);
903                   csum = ip_csum_add_even (csum, new_addr0.as_u64[0]);
904                   csum = ip_csum_add_even (csum, new_addr0.as_u64[1]);
905                   csum = ip_csum_sub_even (csum, old_port0);
906                   csum = ip_csum_add_even (csum, new_port0);
907                   udp0->checksum = ip_csum_fold (csum);
908                 }
909
910               pkts_processed += next0 != LB_NAT4_IN2OUT_NEXT_DROP;
911             }
912
913           trace0: if (PREDICT_FALSE(
914               (node->flags & VLIB_NODE_FLAG_TRACE) && (b0->flags & VLIB_BUFFER_IS_TRACED)))
915             {
916               lb_nat_trace_t *t = vlib_add_trace (vm, node, b0, sizeof(*t));
917               t->rx_sw_if_index = sw_if_index0;
918               t->next_index = next0;
919             }
920
921           /* verify speculative enqueue, maybe switch current next frame */
922           vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next,
923                                           n_left_to_next, bi0, next0);
924         }
925
926       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
927     }
928
929   vlib_node_increment_counter (vm, stats_node_index,
930                                LB_NAT_IN2OUT_ERROR_IN2OUT_PACKETS,
931                                pkts_processed);
932   return frame->n_vectors;
933 }
934
935 static uword
936 lb6_gre6_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
937                   vlib_frame_t * frame)
938 {
939   return lb_node_fn (vm, node, frame, 0, LB_ENCAP_TYPE_GRE6, 0);
940 }
941
942 static uword
943 lb6_gre4_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
944                   vlib_frame_t * frame)
945 {
946   return lb_node_fn (vm, node, frame, 0, LB_ENCAP_TYPE_GRE4, 0);
947 }
948
949 static uword
950 lb4_gre6_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
951                   vlib_frame_t * frame)
952 {
953   return lb_node_fn (vm, node, frame, 1, LB_ENCAP_TYPE_GRE6, 0);
954 }
955
956 static uword
957 lb4_gre4_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
958                   vlib_frame_t * frame)
959 {
960   return lb_node_fn (vm, node, frame, 1, LB_ENCAP_TYPE_GRE4, 0);
961 }
962
963 static uword
964 lb6_gre6_port_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
965                        vlib_frame_t * frame)
966 {
967   return lb_node_fn (vm, node, frame, 0, LB_ENCAP_TYPE_GRE6, 1);
968 }
969
970 static uword
971 lb6_gre4_port_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
972                        vlib_frame_t * frame)
973 {
974   return lb_node_fn (vm, node, frame, 0, LB_ENCAP_TYPE_GRE4, 1);
975 }
976
977 static uword
978 lb4_gre6_port_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
979                        vlib_frame_t * frame)
980 {
981   return lb_node_fn (vm, node, frame, 1, LB_ENCAP_TYPE_GRE6, 1);
982 }
983
984 static uword
985 lb4_gre4_port_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
986                        vlib_frame_t * frame)
987 {
988   return lb_node_fn (vm, node, frame, 1, LB_ENCAP_TYPE_GRE4, 1);
989 }
990
991 static uword
992 lb4_l3dsr_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
993                         vlib_frame_t * frame)
994 {
995   return lb_node_fn (vm, node, frame, 1, LB_ENCAP_TYPE_L3DSR, 0);
996 }
997
998 static uword
999 lb4_l3dsr_port_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1000                         vlib_frame_t * frame)
1001 {
1002   return lb_node_fn (vm, node, frame, 1, LB_ENCAP_TYPE_L3DSR, 1);
1003 }
1004
1005 static uword
1006 lb6_nat6_port_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1007                        vlib_frame_t * frame)
1008 {
1009   return lb_node_fn (vm, node, frame, 0, LB_ENCAP_TYPE_NAT6, 1);
1010 }
1011
1012 static uword
1013 lb4_nat4_port_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1014                        vlib_frame_t * frame)
1015 {
1016   return lb_node_fn (vm, node, frame, 1, LB_ENCAP_TYPE_NAT4, 1);
1017 }
1018
1019 static uword
1020 lb_nat4_in2out_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1021                         vlib_frame_t * frame)
1022 {
1023   return lb_nat_in2out_node_fn (vm, node, frame, 1);
1024 }
1025
1026 static uword
1027 lb_nat6_in2out_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1028                         vlib_frame_t * frame)
1029 {
1030   return lb_nat_in2out_node_fn (vm, node, frame, 0);
1031 }
1032
1033 VLIB_REGISTER_NODE (lb6_gre6_node) =
1034   {
1035     .function = lb6_gre6_node_fn,
1036     .name = "lb6-gre6",
1037     .vector_size = sizeof(u32),
1038     .format_trace = format_lb_trace,
1039     .n_errors = LB_N_ERROR,
1040     .error_strings = lb_error_strings,
1041     .n_next_nodes = LB_N_NEXT,
1042     .next_nodes =
1043         { [LB_NEXT_DROP] = "error-drop" },
1044   };
1045
1046 VLIB_REGISTER_NODE (lb6_gre4_node) =
1047   {
1048     .function = lb6_gre4_node_fn,
1049     .name = "lb6-gre4",
1050     .vector_size = sizeof(u32),
1051     .format_trace = format_lb_trace,
1052     .n_errors = LB_N_ERROR,
1053     .error_strings = lb_error_strings,
1054     .n_next_nodes = LB_N_NEXT,
1055     .next_nodes =
1056         { [LB_NEXT_DROP] = "error-drop" },
1057   };
1058
1059 VLIB_REGISTER_NODE (lb4_gre6_node) =
1060   {
1061     .function = lb4_gre6_node_fn,
1062     .name = "lb4-gre6",
1063     .vector_size = sizeof(u32),
1064     .format_trace = format_lb_trace,
1065     .n_errors = LB_N_ERROR,
1066     .error_strings = lb_error_strings,
1067     .n_next_nodes = LB_N_NEXT,
1068     .next_nodes =
1069         { [LB_NEXT_DROP] = "error-drop" }, 
1070   };
1071
1072 VLIB_REGISTER_NODE (lb4_gre4_node) =
1073   {
1074     .function = lb4_gre4_node_fn,
1075     .name = "lb4-gre4",
1076     .vector_size = sizeof(u32),
1077     .format_trace = format_lb_trace,
1078     .n_errors = LB_N_ERROR,
1079     .error_strings = lb_error_strings,
1080     .n_next_nodes = LB_N_NEXT,
1081     .next_nodes =
1082         { [LB_NEXT_DROP] = "error-drop" },
1083   };
1084
1085 VLIB_REGISTER_NODE (lb6_gre6_port_node) =
1086   {
1087     .function = lb6_gre6_port_node_fn,
1088     .name = "lb6-gre6-port",
1089     .vector_size = sizeof(u32),
1090     .format_trace = format_lb_trace,
1091     .n_errors = LB_N_ERROR,
1092     .error_strings = lb_error_strings,
1093     .n_next_nodes = LB_N_NEXT,
1094     .next_nodes =
1095         { [LB_NEXT_DROP] = "error-drop" },
1096   };
1097
1098 VLIB_REGISTER_NODE (lb6_gre4_port_node) =
1099   {
1100     .function = lb6_gre4_port_node_fn,
1101     .name = "lb6-gre4-port",
1102     .vector_size = sizeof(u32),
1103     .format_trace = format_lb_trace,
1104     .n_errors = LB_N_ERROR,
1105     .error_strings = lb_error_strings,
1106     .n_next_nodes = LB_N_NEXT,
1107     .next_nodes =
1108         { [LB_NEXT_DROP] = "error-drop" },
1109   };
1110
1111 VLIB_REGISTER_NODE (lb4_gre6_port_node) =
1112   {
1113     .function = lb4_gre6_port_node_fn,
1114     .name = "lb4-gre6-port",
1115     .vector_size = sizeof(u32),
1116     .format_trace = format_lb_trace,
1117     .n_errors = LB_N_ERROR,
1118     .error_strings = lb_error_strings,
1119     .n_next_nodes = LB_N_NEXT,
1120     .next_nodes =
1121         { [LB_NEXT_DROP] = "error-drop" },
1122   };
1123
1124 VLIB_REGISTER_NODE (lb4_gre4_port_node) =
1125   {
1126     .function = lb4_gre4_port_node_fn,
1127     .name = "lb4-gre4-port",
1128     .vector_size = sizeof(u32),
1129     .format_trace = format_lb_trace,
1130     .n_errors = LB_N_ERROR,
1131     .error_strings = lb_error_strings,
1132     .n_next_nodes = LB_N_NEXT,
1133     .next_nodes =
1134         { [LB_NEXT_DROP] = "error-drop" },
1135   };
1136
1137 VLIB_REGISTER_NODE (lb4_l3dsr_port_node) =
1138   {
1139     .function = lb4_l3dsr_port_node_fn,
1140     .name = "lb4-l3dsr-port",
1141     .vector_size = sizeof(u32),
1142     .format_trace = format_lb_trace,
1143     .n_errors = LB_N_ERROR,
1144     .error_strings = lb_error_strings,
1145     .n_next_nodes = LB_N_NEXT,
1146     .next_nodes =
1147         { [LB_NEXT_DROP] = "error-drop" },
1148   };
1149
1150 VLIB_REGISTER_NODE (lb4_l3dsr_node) =
1151   {
1152     .function = lb4_l3dsr_node_fn,
1153     .name = "lb4-l3dsr",
1154     .vector_size = sizeof(u32),
1155     .format_trace = format_lb_trace,
1156     .n_errors = LB_N_ERROR,
1157     .error_strings = lb_error_strings,
1158     .n_next_nodes = LB_N_NEXT,
1159     .next_nodes =
1160         { [LB_NEXT_DROP] = "error-drop" },
1161   };
1162
1163 VLIB_REGISTER_NODE (lb6_nat6_port_node) =
1164   {
1165     .function = lb6_nat6_port_node_fn,
1166     .name = "lb6-nat6-port",
1167     .vector_size = sizeof(u32),
1168     .format_trace = format_lb_trace,
1169     .n_errors = LB_N_ERROR,
1170     .error_strings = lb_error_strings,
1171     .n_next_nodes = LB_N_NEXT,
1172     .next_nodes =
1173         { [LB_NEXT_DROP] = "error-drop" },
1174   };
1175
1176 VLIB_REGISTER_NODE (lb4_nat4_port_node) =
1177   {
1178     .function = lb4_nat4_port_node_fn,
1179     .name = "lb4-nat4-port",
1180     .vector_size = sizeof(u32),
1181     .format_trace = format_lb_trace,
1182     .n_errors = LB_N_ERROR,
1183     .error_strings = lb_error_strings,
1184     .n_next_nodes = LB_N_NEXT,
1185     .next_nodes =
1186         { [LB_NEXT_DROP] = "error-drop" },
1187   };
1188
1189 static uword
1190 lb4_nodeport_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1191                       vlib_frame_t * frame)
1192 {
1193   return lb_nodeport_node_fn (vm, node, frame, 1);
1194 }
1195
1196 static uword
1197 lb6_nodeport_node_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
1198                       vlib_frame_t * frame)
1199 {
1200   return lb_nodeport_node_fn (vm, node, frame, 0);
1201 }
1202
1203 VLIB_REGISTER_NODE (lb4_nodeport_node) =
1204   {
1205     .function = lb4_nodeport_node_fn,
1206     .name = "lb4-nodeport",
1207     .vector_size = sizeof(u32),
1208     .format_trace = format_nodeport_lb_trace,
1209     .n_errors = LB_N_ERROR,
1210     .error_strings = lb_error_strings,
1211     .n_next_nodes = LB4_NODEPORT_N_NEXT,
1212     .next_nodes =
1213         {
1214             [LB4_NODEPORT_NEXT_IP4_NAT4] = "lb4-nat4-port",
1215             [LB4_NODEPORT_NEXT_DROP] = "error-drop",
1216         },
1217   };
1218
1219 VLIB_REGISTER_NODE (lb6_nodeport_node) =
1220   {
1221     .function = lb6_nodeport_node_fn,
1222     .name = "lb6-nodeport",
1223     .vector_size = sizeof(u32),
1224     .format_trace = format_nodeport_lb_trace,
1225     .n_errors = LB_N_ERROR,
1226     .error_strings = lb_error_strings,
1227     .n_next_nodes = LB6_NODEPORT_N_NEXT,
1228     .next_nodes =
1229       {
1230           [LB6_NODEPORT_NEXT_IP6_NAT6] = "lb6-nat6-port",
1231           [LB6_NODEPORT_NEXT_DROP] = "error-drop",
1232       },
1233   };
1234
1235 VNET_FEATURE_INIT (lb_nat4_in2out_node_fn, static) =
1236   {
1237     .arc_name = "ip4-unicast",
1238     .node_name = "lb-nat4-in2out",
1239     .runs_before =  VNET_FEATURES("ip4-lookup"),
1240   };
1241
1242 VLIB_REGISTER_NODE (lb_nat4_in2out_node) =
1243   {
1244     .function = lb_nat4_in2out_node_fn,
1245     .name = "lb-nat4-in2out",
1246     .vector_size = sizeof(u32),
1247     .format_trace = format_lb_nat_trace,
1248     .n_errors = LB_N_ERROR,
1249     .error_strings = lb_error_strings,
1250     .n_next_nodes = LB_NAT4_IN2OUT_N_NEXT,
1251     .next_nodes =
1252       {
1253           [LB_NAT4_IN2OUT_NEXT_DROP] = "error-drop",
1254           [LB_NAT4_IN2OUT_NEXT_LOOKUP] = "ip4-lookup",
1255       },
1256   };
1257
1258 VNET_FEATURE_INIT (lb_nat6_in2out_node_fn, static) =
1259   {
1260     .arc_name = "ip6-unicast",
1261     .node_name = "lb-nat6-in2out",
1262     .runs_before = VNET_FEATURES("ip6-lookup"),
1263   };
1264
1265 VLIB_REGISTER_NODE (lb_nat6_in2out_node) =
1266   {
1267     .function = lb_nat6_in2out_node_fn,
1268     .name = "lb-nat6-in2out",
1269     .vector_size = sizeof(u32),
1270     .format_trace = format_lb_nat_trace,
1271     .n_errors = LB_N_ERROR,
1272     .error_strings = lb_error_strings,
1273     .n_next_nodes = LB_NAT6_IN2OUT_N_NEXT,
1274     .next_nodes =
1275       {
1276           [LB_NAT6_IN2OUT_NEXT_DROP] = "error-drop",
1277           [LB_NAT6_IN2OUT_NEXT_LOOKUP] = "ip6-lookup",
1278       },
1279   };
1280