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