NAT: TCP MSS clamping
[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   /* TCP MSS clamping */
443   u16 mss_clamping;
444   u16 mss_value_net;
445
446   /* API message ID base */
447   u16 msg_id_base;
448
449   /* log class */
450   vlib_log_class_t log_class;
451
452   /* convenience */
453   vlib_main_t * vlib_main;
454   vnet_main_t * vnet_main;
455   ip4_main_t * ip4_main;
456   ip_lookup_main_t * ip4_lookup_main;
457   api_main_t * api_main;
458 } snat_main_t;
459
460 typedef struct {
461   u32 thread_index;
462   f64 now;
463 } nat44_is_idle_session_ctx_t;
464
465 extern snat_main_t snat_main;
466 extern vlib_node_registration_t snat_in2out_node;
467 extern vlib_node_registration_t snat_in2out_output_node;
468 extern vlib_node_registration_t snat_out2in_node;
469 extern vlib_node_registration_t snat_in2out_fast_node;
470 extern vlib_node_registration_t snat_out2in_fast_node;
471 extern vlib_node_registration_t snat_in2out_worker_handoff_node;
472 extern vlib_node_registration_t snat_in2out_output_worker_handoff_node;
473 extern vlib_node_registration_t snat_out2in_worker_handoff_node;
474 extern vlib_node_registration_t snat_det_in2out_node;
475 extern vlib_node_registration_t snat_det_out2in_node;
476 extern vlib_node_registration_t snat_hairpin_dst_node;
477 extern vlib_node_registration_t snat_hairpin_src_node;
478 extern vlib_node_registration_t nat44_ed_in2out_node;
479 extern vlib_node_registration_t nat44_ed_in2out_output_node;
480 extern vlib_node_registration_t nat44_ed_out2in_node;
481 extern vlib_node_registration_t nat44_ed_hairpin_dst_node;
482 extern vlib_node_registration_t nat44_ed_hairpin_src_node;
483 extern vlib_node_registration_t nat44_ed_in2out_worker_handoff_node;
484 extern vlib_node_registration_t nat44_ed_in2out_output_worker_handoff_node;
485 extern vlib_node_registration_t nat44_ed_out2in_worker_handoff_node;
486
487 void snat_free_outside_address_and_port (snat_address_t * addresses,
488                                          u32 thread_index,
489                                          snat_session_key_t * k);
490
491 int snat_alloc_outside_address_and_port (snat_address_t * addresses,
492                                          u32 fib_index,
493                                          u32 thread_index,
494                                          snat_session_key_t * k,
495                                          u32 * address_indexp,
496                                          u16 port_per_thread,
497                                          u32 snat_thread_index);
498
499 int snat_static_mapping_match (snat_main_t * sm,
500                                snat_session_key_t match,
501                                snat_session_key_t * mapping,
502                                u8 by_external,
503                                u8 *is_addr_only,
504                                twice_nat_type_t *twice_nat,
505                                lb_nat_type_t *lb,
506                                ip4_address_t * ext_host_addr);
507
508 void snat_add_del_addr_to_fib (ip4_address_t * addr,
509                                u8 p_len,
510                                u32 sw_if_index,
511                                int is_add);
512
513 format_function_t format_snat_user;
514 format_function_t format_snat_static_mapping;
515 format_function_t format_snat_static_map_to_resolve;
516 format_function_t format_snat_session;
517 format_function_t format_det_map_ses;
518
519 typedef struct {
520   u32 cached_sw_if_index;
521   u32 cached_ip4_address;
522 } snat_runtime_t;
523
524 /** \brief Check if SNAT session is created from static mapping.
525     @param s SNAT session
526     @return 1 if SNAT session is created from static mapping otherwise 0
527 */
528 #define snat_is_session_static(s) (s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING)
529
530 /** \brief Check if SNAT session for unknown protocol.
531     @param s SNAT session
532     @return 1 if SNAT session for unknown protocol otherwise 0
533 */
534 #define snat_is_unk_proto_session(s) (s->flags & SNAT_SESSION_FLAG_UNKNOWN_PROTO)
535
536 /** \brief Check if NAT session is twice NAT.
537     @param s NAT session
538     @return 1 if NAT session is twice NAT
539 */
540 #define is_twice_nat_session(s) (s->flags & SNAT_SESSION_FLAG_TWICE_NAT)
541
542 /** \brief Check if NAT session is load-balancing.
543     @param s NAT session
544     @return 1 if NAT session is load-balancing
545 */
546 #define is_lb_session(s) (s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING)
547
548 /** \brief Check if NAT session is forwarding bypass.
549     @param s NAT session
550     @return 1 if NAT session is load-balancing
551 */
552 #define is_fwd_bypass_session(s) (s->flags & SNAT_SESSION_FLAG_FWD_BYPASS)
553
554 /** \brief Check if NAT session is endpoint dependent.
555     @param s NAT session
556     @return 1 if NAT session is endpoint dependent
557 */
558 #define is_ed_session(s) (s->flags & SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT)
559
560 /** \brief Check if NAT session has affinity record.
561     @param s NAT session
562     @return 1 if NAT session has affinity record
563 */
564 #define is_affinity_sessions(s) (s->flags & SNAT_SESSION_FLAG_AFFINITY)
565
566 #define nat_interface_is_inside(i) i->flags & NAT_INTERFACE_FLAG_IS_INSIDE
567 #define nat_interface_is_outside(i) i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE
568
569 #define nat_log_err(...) \
570   vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
571 #define nat_log_warn(...) \
572   vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
573 #define nat_log_notice(...) \
574   vlib_log(VLIB_LOG_LEVEL_NOTICE, snat_main.log_class, __VA_ARGS__)
575 #define nat_log_info(...) \
576   vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
577 #define nat_log_debug(...)\
578   vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
579
580 /*
581  * Why is this here? Because we don't need to touch this layer to
582  * simply reply to an icmp. We need to change id to a unique
583  * value to NAT an echo request/reply.
584  */
585
586 typedef struct {
587   u16 identifier;
588   u16 sequence;
589 } icmp_echo_header_t;
590
591 typedef struct {
592   u16 src_port, dst_port;
593 } tcp_udp_header_t;
594
595 u32 icmp_match_in2out_fast(snat_main_t *sm, vlib_node_runtime_t *node,
596                            u32 thread_index, vlib_buffer_t *b0,
597                            ip4_header_t *ip0, u8 *p_proto,
598                            snat_session_key_t *p_value,
599                            u8 *p_dont_translate, void *d, void *e);
600 u32 icmp_match_in2out_slow(snat_main_t *sm, vlib_node_runtime_t *node,
601                            u32 thread_index, vlib_buffer_t *b0,
602                            ip4_header_t *ip0, u8 *p_proto,
603                            snat_session_key_t *p_value,
604                            u8 *p_dont_translate, void *d, void *e);
605 u32 icmp_match_in2out_det(snat_main_t *sm, vlib_node_runtime_t *node,
606                           u32 thread_index, vlib_buffer_t *b0,
607                           ip4_header_t *ip0, u8 *p_proto,
608                           snat_session_key_t *p_value,
609                           u8 *p_dont_translate, void *d, void *e);
610 u32 icmp_match_in2out_ed(snat_main_t *sm, vlib_node_runtime_t *node,
611                          u32 thread_index, vlib_buffer_t *b0,
612                          ip4_header_t *ip0, u8 *p_proto,
613                          snat_session_key_t *p_value,
614                          u8 *p_dont_translate, void *d, void *e);
615 u32 icmp_match_out2in_fast(snat_main_t *sm, vlib_node_runtime_t *node,
616                            u32 thread_index, vlib_buffer_t *b0,
617                            ip4_header_t *ip0, u8 *p_proto,
618                            snat_session_key_t *p_value,
619                            u8 *p_dont_translate, void *d, void *e);
620 u32 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node,
621                            u32 thread_index, vlib_buffer_t *b0,
622                            ip4_header_t *ip0, u8 *p_proto,
623                            snat_session_key_t *p_value,
624                            u8 *p_dont_translate, void *d, void *e);
625 u32 icmp_match_out2in_det(snat_main_t *sm, vlib_node_runtime_t *node,
626                           u32 thread_index, vlib_buffer_t *b0,
627                           ip4_header_t *ip0, u8 *p_proto,
628                           snat_session_key_t *p_value,
629                           u8 *p_dont_translate, void *d, void *e);
630 u32 icmp_match_out2in_ed(snat_main_t *sm, vlib_node_runtime_t *node,
631                          u32 thread_index, vlib_buffer_t *b0,
632                          ip4_header_t *ip0, u8 *p_proto,
633                          snat_session_key_t *p_value,
634                          u8 *p_dont_translate, void *d, void *e);
635 void increment_v4_address(ip4_address_t * a);
636 int snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id,
637                      u8 twice_nat);
638 int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm,
639                      u8 twice_nat);
640 void nat44_add_del_address_dpo (ip4_address_t addr, u8 is_add);
641 int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr,
642                             u16 l_port, u16 e_port, u32 vrf_id, int addr_only,
643                             u32 sw_if_index, snat_protocol_t proto, int is_add,
644                             twice_nat_type_t twice_nat, u8 out2in_only,
645                             u8 *tag);
646 clib_error_t * snat_api_init(vlib_main_t * vm, snat_main_t * sm);
647 int snat_set_workers (uword * bitmap);
648 int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del);
649 int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside,
650                                           int is_del);
651 int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del,
652                                u8 twice_nat);
653 uword unformat_snat_protocol(unformat_input_t * input, va_list * args);
654 u8 * format_snat_protocol(u8 * s, va_list * args);
655 u8 * format_nat_addr_and_port_alloc_alg(u8 * s, va_list * args);
656 int nat44_add_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
657                                      snat_protocol_t proto,
658                                      nat44_lb_addr_port_t *locals, u8 is_add,
659                                      twice_nat_type_t twice_nat, u8 out2in_only,
660                                      u8 *tag, u32 affinity);
661 int nat44_del_session (snat_main_t *sm, ip4_address_t *addr, u16 port,
662                        snat_protocol_t proto, u32 vrf_id, int is_in);
663 int nat44_del_ed_session (snat_main_t *sm, ip4_address_t *addr, u16 port,
664                           ip4_address_t *eh_addr, u16 eh_port, u8 proto,
665                           u32 vrf_id, int is_in);
666 void nat_free_session_data (snat_main_t * sm, snat_session_t * s,
667                             u32 thread_index);
668 snat_user_t * nat_user_get_or_create (snat_main_t *sm, ip4_address_t *addr,
669                                       u32 fib_index, u32 thread_index);
670 snat_session_t * nat_session_alloc_or_recycle (snat_main_t *sm, snat_user_t *u,
671                                                u32 thread_index);
672 snat_session_t * nat_ed_session_alloc (snat_main_t *sm, snat_user_t *u,
673                                        u32 thread_index);
674 void nat_set_alloc_addr_and_port_mape (u16 psid, u16 psid_offset,
675                                        u16 psid_length);
676 void nat_set_alloc_addr_and_port_range (u16 start_port, u16 end_port);
677 void nat_set_alloc_addr_and_port_default (void);
678 int nat44_i2o_ed_is_idle_session_cb (clib_bihash_kv_16_8_t *kv, void *arg);
679 int nat44_o2i_ed_is_idle_session_cb (clib_bihash_kv_16_8_t *kv, void *arg);
680 int nat44_i2o_is_idle_session_cb (clib_bihash_kv_8_8_t *kv, void *arg);
681 int nat44_o2i_is_idle_session_cb (clib_bihash_kv_8_8_t *kv, void *arg);
682
683 #endif /* __included_snat_h__ */