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