Add special Twice-NAT feature (VPP-1221)
[vpp.git] / src / plugins / nat / nat.h
1
2 /*
3  * nat.h - NAT plugin definitions
4  *
5  * Copyright (c) 2016 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #ifndef __included_nat_h__
19 #define __included_nat_h__
20
21 #include <vnet/vnet.h>
22 #include <vnet/ip/ip.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vnet/ip/icmp46_packet.h>
25 #include <vnet/api_errno.h>
26 #include <vppinfra/bihash_8_8.h>
27 #include <vppinfra/bihash_16_8.h>
28 #include <vppinfra/dlist.h>
29 #include <vppinfra/error.h>
30 #include <vlibapi/api.h>
31
32
33 #define SNAT_UDP_TIMEOUT 300
34 #define SNAT_UDP_TIMEOUT_MIN 120
35 #define SNAT_TCP_TRANSITORY_TIMEOUT 240
36 #define SNAT_TCP_ESTABLISHED_TIMEOUT 7440
37 #define SNAT_TCP_INCOMING_SYN 6
38 #define SNAT_ICMP_TIMEOUT 60
39
40 #define SNAT_FLAG_HAIRPINNING (1 << 0)
41
42 /* Key */
43 typedef struct {
44   union
45   {
46     struct
47     {
48       ip4_address_t addr;
49       u16 port;
50       u16 protocol:3,
51         fib_index:13;
52     };
53     u64 as_u64;
54   };
55 } snat_session_key_t;
56
57 typedef struct {
58   union
59   {
60     struct
61     {
62       ip4_address_t l_addr;
63       ip4_address_t r_addr;
64       u32 proto:8,
65           fib_index:24;
66       u16 l_port;
67       u16 r_port;
68     };
69     u64 as_u64[2];
70   };
71 } nat_ed_ses_key_t;
72
73 typedef struct {
74   union
75   {
76     struct
77     {
78       ip4_address_t ext_host_addr;
79       u16 ext_host_port;
80       u16 out_port;
81     };
82     u64 as_u64;
83   };
84 } snat_det_out_key_t;
85
86 typedef struct {
87   union
88   {
89     struct
90     {
91       ip4_address_t addr;
92       u32 fib_index;
93     };
94     u64 as_u64;
95   };
96 } snat_user_key_t;
97
98
99 #define foreach_snat_protocol \
100   _(UDP, 0, udp, "udp")       \
101   _(TCP, 1, tcp, "tcp")       \
102   _(ICMP, 2, icmp, "icmp")
103
104 typedef enum {
105 #define _(N, i, n, s) SNAT_PROTOCOL_##N = i,
106   foreach_snat_protocol
107 #undef _
108 } snat_protocol_t;
109
110
111 #define foreach_snat_session_state          \
112   _(0, UNKNOWN, "unknown")                 \
113   _(1, UDP_ACTIVE, "udp-active")           \
114   _(2, TCP_SYN_SENT, "tcp-syn-sent")       \
115   _(3, TCP_ESTABLISHED, "tcp-established") \
116   _(4, TCP_FIN_WAIT, "tcp-fin-wait")       \
117   _(5, TCP_CLOSE_WAIT, "tcp-close-wait")   \
118   _(6, TCP_LAST_ACK, "tcp-last-ack")       \
119   _(7, ICMP_ACTIVE, "icmp-active")
120
121 typedef enum {
122 #define _(v, N, s) SNAT_SESSION_##N = v,
123   foreach_snat_session_state
124 #undef _
125 } snat_session_state_t;
126
127
128 #define SNAT_SESSION_FLAG_STATIC_MAPPING       1
129 #define SNAT_SESSION_FLAG_UNKNOWN_PROTO        2
130 #define SNAT_SESSION_FLAG_LOAD_BALANCING       4
131 #define SNAT_SESSION_FLAG_TWICE_NAT            8
132 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT   16
133 #define SNAT_SESSION_FLAG_FWD_BYPASS           32
134
135 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
136 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
137
138 typedef CLIB_PACKED(struct {
139   snat_session_key_t out2in;    /* 0-15 */
140
141   snat_session_key_t in2out;    /* 16-31 */
142
143   u32 flags;                    /* 32-35 */
144
145   /* per-user translations */
146   u32 per_user_index;           /* 36-39 */
147
148   u32 per_user_list_head_index; /* 40-43 */
149
150   /* Last heard timer */
151   f64 last_heard;               /* 44-51 */
152
153   u64 total_bytes;              /* 52-59 */
154
155   u32 total_pkts;               /* 60-63 */
156
157   /* Outside address */
158   u32 outside_address_index;    /* 64-67 */
159
160   /* External host address and port */
161   ip4_address_t ext_host_addr;  /* 68-71 */
162   u16 ext_host_port;            /* 72-73 */
163
164   /* External hos address and port after translation */
165   ip4_address_t ext_host_nat_addr; /* 74-77 */
166   u16 ext_host_nat_port;           /* 78-79 */
167 }) snat_session_t;
168
169
170 typedef struct {
171   ip4_address_t addr;
172   u32 fib_index;
173   u32 sessions_per_user_list_head_index;
174   u32 nsessions;
175   u32 nstaticsessions;
176 } snat_user_t;
177
178 typedef struct {
179   ip4_address_t addr;
180   u32 fib_index;
181 #define _(N, i, n, s) \
182   u16 busy_##n##_ports; \
183   u16 * busy_##n##_ports_per_thread; \
184   uword * busy_##n##_port_bitmap;
185   foreach_snat_protocol
186 #undef _
187 } snat_address_t;
188
189 typedef struct {
190   u16 in_port;
191   snat_det_out_key_t out;
192   u8 state;
193   u32 expire;
194 } snat_det_session_t;
195
196 typedef struct {
197   ip4_address_t in_addr;
198   u8 in_plen;
199   ip4_address_t out_addr;
200   u8 out_plen;
201   u32 sharing_ratio;
202   u16 ports_per_host;
203   u32 ses_num;
204   /* vector of sessions */
205   snat_det_session_t * sessions;
206 } snat_det_map_t;
207
208 typedef struct {
209   ip4_address_t addr;
210   u16 port;
211   u8 probability;
212   u8 prefix;
213 } nat44_lb_addr_port_t;
214
215 typedef enum {
216   TWICE_NAT_DISABLED,
217   TWICE_NAT,
218   TWICE_NAT_SELF,
219 } twice_nat_type_t;
220
221 typedef struct {
222   ip4_address_t local_addr;
223   ip4_address_t external_addr;
224   u16 local_port;
225   u16 external_port;
226   u8 addr_only;
227   twice_nat_type_t twice_nat;
228   u8 out2in_only;
229   u32 vrf_id;
230   u32 fib_index;
231   snat_protocol_t proto;
232   u32 worker_index;
233   u8 *tag;
234   nat44_lb_addr_port_t *locals;
235 } snat_static_mapping_t;
236
237 typedef struct {
238   u32 sw_if_index;
239   u8 flags;
240 } snat_interface_t;
241
242 typedef struct {
243   ip4_address_t l_addr;
244   u16 l_port;
245   u16 e_port;
246   u32 sw_if_index;
247   u32 vrf_id;
248   snat_protocol_t proto;
249   int addr_only;
250   int twice_nat;
251   int is_add;
252   u8 *tag;
253 } snat_static_map_resolve_t;
254
255 typedef struct {
256   /* Main lookup tables */
257   clib_bihash_8_8_t out2in;
258   clib_bihash_8_8_t in2out;
259
260   /* Find-a-user => src address lookup */
261   clib_bihash_8_8_t user_hash;
262
263   /* User pool */
264   snat_user_t * users;
265
266   /* Session pool */
267   snat_session_t * sessions;
268
269   /* Pool of doubly-linked list elements */
270   dlist_elt_t * list_pool;
271
272   u32 snat_thread_index;
273 } snat_main_per_thread_data_t;
274
275 struct snat_main_s;
276
277 typedef u32 snat_icmp_match_function_t (struct snat_main_s *sm,
278                                         vlib_node_runtime_t *node,
279                                         u32 thread_index,
280                                         vlib_buffer_t *b0,
281                                         ip4_header_t *ip0,
282                                         u8 *p_proto,
283                                         snat_session_key_t *p_value,
284                                         u8 *p_dont_translate,
285                                         void *d,
286                                         void *e);
287
288 typedef u32 (snat_get_worker_function_t) (ip4_header_t * ip, u32 rx_fib_index);
289
290 typedef int nat_alloc_out_addr_and_port_function_t (snat_address_t * addresses,
291                                                     u32 fib_index,
292                                                     u32 thread_index,
293                                                     snat_session_key_t * k,
294                                                     u32 * address_indexp,
295                                                     u16 port_per_thread,
296                                                     u32 snat_thread_index);
297
298 typedef struct snat_main_s {
299   /* Endpoint address dependent sessions lookup tables */
300   clib_bihash_16_8_t out2in_ed;
301   clib_bihash_16_8_t in2out_ed;
302
303   snat_icmp_match_function_t * icmp_match_in2out_cb;
304   snat_icmp_match_function_t * icmp_match_out2in_cb;
305
306   u32 num_workers;
307   u32 first_worker_index;
308   u32 next_worker;
309   u32 * workers;
310   snat_get_worker_function_t * worker_in2out_cb;
311   snat_get_worker_function_t * worker_out2in_cb;
312   u16 port_per_thread;
313   u32 num_snat_thread;
314
315   /* Per thread data */
316   snat_main_per_thread_data_t * per_thread_data;
317
318   /* Find a static mapping by local */
319   clib_bihash_8_8_t static_mapping_by_local;
320
321   /* Find a static mapping by external */
322   clib_bihash_8_8_t static_mapping_by_external;
323
324   /* Static mapping pool */
325   snat_static_mapping_t * static_mappings;
326
327   /* Interface pool */
328   snat_interface_t * interfaces;
329   snat_interface_t * output_feature_interfaces;
330
331   /* Vector of outside addresses */
332   snat_address_t * addresses;
333   nat_alloc_out_addr_and_port_function_t *alloc_addr_and_port;
334   u8 psid_offset;
335   u8 psid_length;
336   u16 psid;
337
338   /* Vector of twice NAT addresses for extenal hosts */
339   snat_address_t * twice_nat_addresses;
340
341   /* sw_if_indices whose intfc addresses should be auto-added */
342   u32 * auto_add_sw_if_indices;
343   u32 * auto_add_sw_if_indices_twice_nat;
344
345   /* vector of interface address static mappings to resolve. */
346   snat_static_map_resolve_t *to_resolve;
347
348   /* Randomize port allocation order */
349   u32 random_seed;
350
351   /* Worker handoff index */
352   u32 fq_in2out_index;
353   u32 fq_in2out_output_index;
354   u32 fq_out2in_index;
355
356   /* in2out and out2in node index */
357   u32 in2out_node_index;
358   u32 in2out_output_node_index;
359   u32 out2in_node_index;
360
361   /* Deterministic NAT */
362   snat_det_map_t * det_maps;
363
364   /* If forwarding is enabled */
365   u8 forwarding_enabled;
366
367   /* Config parameters */
368   u8 static_mapping_only;
369   u8 static_mapping_connection_tracking;
370   u8 deterministic;
371   u8 out2in_dpo;
372   u32 translation_buckets;
373   u32 translation_memory_size;
374   u32 max_translations;
375   u32 user_buckets;
376   u32 user_memory_size;
377   u32 max_translations_per_user;
378   u32 outside_vrf_id;
379   u32 outside_fib_index;
380   u32 inside_vrf_id;
381   u32 inside_fib_index;
382
383   /* values of various timeouts */
384   u32 udp_timeout;
385   u32 tcp_established_timeout;
386   u32 tcp_transitory_timeout;
387   u32 icmp_timeout;
388
389   /* API message ID base */
390   u16 msg_id_base;
391
392   /* convenience */
393   vlib_main_t * vlib_main;
394   vnet_main_t * vnet_main;
395   ip4_main_t * ip4_main;
396   ip_lookup_main_t * ip4_lookup_main;
397   api_main_t * api_main;
398 } snat_main_t;
399
400 extern snat_main_t snat_main;
401 extern vlib_node_registration_t snat_in2out_node;
402 extern vlib_node_registration_t snat_in2out_output_node;
403 extern vlib_node_registration_t snat_out2in_node;
404 extern vlib_node_registration_t snat_in2out_fast_node;
405 extern vlib_node_registration_t snat_out2in_fast_node;
406 extern vlib_node_registration_t snat_in2out_worker_handoff_node;
407 extern vlib_node_registration_t snat_in2out_output_worker_handoff_node;
408 extern vlib_node_registration_t snat_out2in_worker_handoff_node;
409 extern vlib_node_registration_t snat_det_in2out_node;
410 extern vlib_node_registration_t snat_det_out2in_node;
411 extern vlib_node_registration_t snat_hairpin_dst_node;
412 extern vlib_node_registration_t snat_hairpin_src_node;
413
414 void snat_free_outside_address_and_port (snat_address_t * addresses,
415                                          u32 thread_index,
416                                          snat_session_key_t * k,
417                                          u32 address_index);
418
419 int snat_alloc_outside_address_and_port (snat_address_t * addresses,
420                                          u32 fib_index,
421                                          u32 thread_index,
422                                          snat_session_key_t * k,
423                                          u32 * address_indexp,
424                                          u16 port_per_thread,
425                                          u32 snat_thread_index);
426
427 int snat_static_mapping_match (snat_main_t * sm,
428                                snat_session_key_t match,
429                                snat_session_key_t * mapping,
430                                u8 by_external,
431                                u8 *is_addr_only,
432                                twice_nat_type_t *twice_nat,
433                                u8 *lb);
434
435 void snat_add_del_addr_to_fib (ip4_address_t * addr,
436                                u8 p_len,
437                                u32 sw_if_index,
438                                int is_add);
439
440 format_function_t format_snat_user;
441 format_function_t format_snat_static_mapping;
442 format_function_t format_snat_static_map_to_resolve;
443 format_function_t format_det_map_ses;
444
445 typedef struct {
446   u32 cached_sw_if_index;
447   u32 cached_ip4_address;
448 } snat_runtime_t;
449
450 /** \brief Check if SNAT session is created from static mapping.
451     @param s SNAT session
452     @return 1 if SNAT session is created from static mapping otherwise 0
453 */
454 #define snat_is_session_static(s) (s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING)
455
456 /** \brief Check if SNAT session for unknown protocol.
457     @param s SNAT session
458     @return 1 if SNAT session for unknown protocol otherwise 0
459 */
460 #define snat_is_unk_proto_session(s) (s->flags & SNAT_SESSION_FLAG_UNKNOWN_PROTO)
461
462 /** \brief Check if NAT session is twice NAT.
463     @param s NAT session
464     @return 1 if NAT session is twice NAT
465 */
466 #define is_twice_nat_session(s) (s->flags & SNAT_SESSION_FLAG_TWICE_NAT)
467
468 /** \brief Check if NAT session is load-balancing.
469     @param s NAT session
470     @return 1 if NAT session is load-balancing
471 */
472 #define is_lb_session(s) (s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING)
473
474 /** \brief Check if NAT session is forwarding bypass.
475     @param s NAT session
476     @return 1 if NAT session is load-balancing
477 */
478 #define is_fwd_bypass_session(s) (s->flags & SNAT_SESSION_FLAG_FWD_BYPASS)
479
480 /** \brief Check if NAT session is endpoint dependent.
481     @param s NAT session
482     @return 1 if NAT session is endpoint dependent
483 */
484 #define is_ed_session(s) (s->flags & SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT)
485
486 #define nat_interface_is_inside(i) i->flags & NAT_INTERFACE_FLAG_IS_INSIDE
487 #define nat_interface_is_outside(i) i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE
488
489 /*
490  * Why is this here? Because we don't need to touch this layer to
491  * simply reply to an icmp. We need to change id to a unique
492  * value to NAT an echo request/reply.
493  */
494
495 typedef struct {
496   u16 identifier;
497   u16 sequence;
498 } icmp_echo_header_t;
499
500 always_inline u32
501 ip_proto_to_snat_proto (u8 ip_proto)
502 {
503   u32 snat_proto = ~0;
504
505   snat_proto = (ip_proto == IP_PROTOCOL_UDP) ? SNAT_PROTOCOL_UDP : snat_proto;
506   snat_proto = (ip_proto == IP_PROTOCOL_TCP) ? SNAT_PROTOCOL_TCP : snat_proto;
507   snat_proto = (ip_proto == IP_PROTOCOL_ICMP) ? SNAT_PROTOCOL_ICMP : snat_proto;
508   snat_proto = (ip_proto == IP_PROTOCOL_ICMP6) ? SNAT_PROTOCOL_ICMP : snat_proto;
509
510   return snat_proto;
511 }
512
513 always_inline u8
514 snat_proto_to_ip_proto (snat_protocol_t snat_proto)
515 {
516   u8 ip_proto = ~0;
517
518   ip_proto = (snat_proto == SNAT_PROTOCOL_UDP) ? IP_PROTOCOL_UDP : ip_proto;
519   ip_proto = (snat_proto == SNAT_PROTOCOL_TCP) ? IP_PROTOCOL_TCP : ip_proto;
520   ip_proto = (snat_proto == SNAT_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP : ip_proto;
521
522   return ip_proto;
523 }
524
525 typedef struct {
526   u16 src_port, dst_port;
527 } tcp_udp_header_t;
528
529 u32 icmp_match_in2out_fast(snat_main_t *sm, vlib_node_runtime_t *node,
530                            u32 thread_index, vlib_buffer_t *b0,
531                            ip4_header_t *ip0, u8 *p_proto,
532                            snat_session_key_t *p_value,
533                            u8 *p_dont_translate, void *d, void *e);
534 u32 icmp_match_in2out_slow(snat_main_t *sm, vlib_node_runtime_t *node,
535                            u32 thread_index, vlib_buffer_t *b0,
536                            ip4_header_t *ip0, u8 *p_proto,
537                            snat_session_key_t *p_value,
538                            u8 *p_dont_translate, void *d, void *e);
539 u32 icmp_match_in2out_det(snat_main_t *sm, vlib_node_runtime_t *node,
540                           u32 thread_index, vlib_buffer_t *b0,
541                           ip4_header_t *ip0, u8 *p_proto,
542                           snat_session_key_t *p_value,
543                           u8 *p_dont_translate, void *d, void *e);
544 u32 icmp_match_out2in_fast(snat_main_t *sm, vlib_node_runtime_t *node,
545                            u32 thread_index, vlib_buffer_t *b0,
546                            ip4_header_t *ip0, u8 *p_proto,
547                            snat_session_key_t *p_value,
548                            u8 *p_dont_translate, void *d, void *e);
549 u32 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node,
550                            u32 thread_index, vlib_buffer_t *b0,
551                            ip4_header_t *ip0, u8 *p_proto,
552                            snat_session_key_t *p_value,
553                            u8 *p_dont_translate, void *d, void *e);
554 u32 icmp_match_out2in_det(snat_main_t *sm, vlib_node_runtime_t *node,
555                           u32 thread_index, vlib_buffer_t *b0,
556                           ip4_header_t *ip0, u8 *p_proto,
557                           snat_session_key_t *p_value,
558                           u8 *p_dont_translate, void *d, void *e);
559 void increment_v4_address(ip4_address_t * a);
560 void snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id,
561                       u8 twice_nat);
562 int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm,
563                      u8 twice_nat);
564 void nat44_add_del_address_dpo (ip4_address_t addr, u8 is_add);
565 int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr,
566                             u16 l_port, u16 e_port, u32 vrf_id, int addr_only,
567                             u32 sw_if_index, snat_protocol_t proto, int is_add,
568                             twice_nat_type_t twice_nat, u8 out2in_only,
569                             u8 *tag);
570 clib_error_t * snat_api_init(vlib_main_t * vm, snat_main_t * sm);
571 int snat_set_workers (uword * bitmap);
572 int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del);
573 int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside,
574                                           int is_del);
575 int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del,
576                                u8 twice_nat);
577 uword unformat_snat_protocol(unformat_input_t * input, va_list * args);
578 u8 * format_snat_protocol(u8 * s, va_list * args);
579 int nat44_add_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
580                                      snat_protocol_t proto, u32 vrf_id,
581                                      nat44_lb_addr_port_t *locals, u8 is_add,
582                                      twice_nat_type_t twice_nat, u8 out2in_only,
583                                      u8 *tag);
584 int nat44_del_session (snat_main_t *sm, ip4_address_t *addr, u16 port,
585                        snat_protocol_t proto, u32 vrf_id, int is_in);
586 void nat_free_session_data (snat_main_t * sm, snat_session_t * s,
587                             u32 thread_index);
588 snat_user_t * nat_user_get_or_create (snat_main_t *sm, ip4_address_t *addr,
589                                       u32 fib_index, u32 thread_index);
590 snat_session_t * nat_session_alloc_or_recycle (snat_main_t *sm, snat_user_t *u,
591                                                u32 thread_index);
592 void nat_set_alloc_addr_and_port_mape (u16 psid, u16 psid_offset,
593                                        u16 psid_length);
594 void nat_set_alloc_addr_and_port_default (void);
595
596 static_always_inline u8
597 icmp_is_error_message (icmp46_header_t * icmp)
598 {
599   switch(icmp->type)
600     {
601     case ICMP4_destination_unreachable:
602     case ICMP4_time_exceeded:
603     case ICMP4_parameter_problem:
604     case ICMP4_source_quench:
605     case ICMP4_redirect:
606     case ICMP4_alternate_host_address:
607       return 1;
608     }
609   return 0;
610 }
611
612 static_always_inline u8
613 is_interface_addr(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0,
614                   u32 ip4_addr)
615 {
616   snat_runtime_t *rt = (snat_runtime_t *) node->runtime_data;
617   ip4_address_t * first_int_addr;
618
619   if (PREDICT_FALSE(rt->cached_sw_if_index != sw_if_index0))
620     {
621       first_int_addr =
622         ip4_interface_first_address (sm->ip4_main, sw_if_index0,
623                                      0 /* just want the address */);
624       rt->cached_sw_if_index = sw_if_index0;
625       if (first_int_addr)
626         rt->cached_ip4_address = first_int_addr->as_u32;
627       else
628         rt->cached_ip4_address = 0;
629     }
630
631   if (PREDICT_FALSE(ip4_addr == rt->cached_ip4_address))
632     return 1;
633   else
634     return 0;
635 }
636
637 always_inline u8
638 maximum_sessions_exceeded (snat_main_t *sm, u32 thread_index)
639 {
640   if (pool_elts (sm->per_thread_data[thread_index].sessions) >= sm->max_translations)
641     return 1;
642
643   return 0;
644 }
645
646 static_always_inline void
647 nat_send_all_to_node(vlib_main_t *vm, u32 *bi_vector,
648                      vlib_node_runtime_t *node, vlib_error_t *error, u32 next)
649 {
650   u32 n_left_from, *from, next_index, *to_next, n_left_to_next;
651
652   from = bi_vector;
653   n_left_from = vec_len(bi_vector);
654   next_index = node->cached_next_index;
655   while (n_left_from > 0) {
656     vlib_get_next_frame(vm, node, next_index, to_next, n_left_to_next);
657     while (n_left_from > 0 && n_left_to_next > 0) {
658       u32 bi0 = to_next[0] = from[0];
659       from += 1;
660       n_left_from -= 1;
661       to_next += 1;
662       n_left_to_next -= 1;
663       vlib_buffer_t *p0 = vlib_get_buffer(vm, bi0);
664       p0->error = *error;
665       vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next,
666                                       n_left_to_next, bi0, next);
667     }
668     vlib_put_next_frame(vm, node, next_index, n_left_to_next);
669   }
670 }
671
672 always_inline void
673 user_session_increment(snat_main_t *sm, snat_user_t *u, u8 is_static)
674 {
675   if (u->nsessions + u->nstaticsessions < sm->max_translations_per_user)
676     {
677       if (is_static)
678         u->nstaticsessions++;
679       else
680         u->nsessions++;
681     }
682 }
683
684 #endif /* __included_snat_h__ */