FD.io VPP  v19.04.2-12-g66b1689
Vector Packet Processing
nat.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /**
16  * @file NAT plugin global declarations
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 /* default session timeouts */
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 /* number of worker handoff frame queue elements */
40 #define NAT_FQ_NELTS 64
41 
42 /* NAT buffer flags */
43 #define SNAT_FLAG_HAIRPINNING (1 << 0)
44 
45 /* session key (4-tuple) */
46 typedef struct
47 {
48  union
49  {
50  struct
51  {
54  u16 protocol:3, fib_index:13;
55  };
57  };
59 
60 /* endpoint-dependent session key (6-tuple) */
61 typedef struct
62 {
63  union
64  {
65  struct
66  {
69  u32 proto:8, fib_index:24;
72  };
73  u64 as_u64[2];
74  };
76 
77 /* deterministic session outside key */
78 typedef struct
79 {
80  union
81  {
82  struct
83  {
87  };
89  };
91 
92 /* user (internal host) key */
93 typedef struct
94 {
95  union
96  {
97  struct
98  {
101  };
103  };
105 
106 typedef struct
107 {
112 
113 /* External address and port allocation modes */
114 #define foreach_nat_addr_and_port_alloc_alg \
115  _(0, DEFAULT, "default") \
116  _(1, MAPE, "map-e") \
117  _(2, RANGE, "port-range")
118 
119 typedef enum
120 {
121 #define _(v, N, s) NAT_ADDR_AND_PORT_ALLOC_ALG_##N = v,
123 #undef _
125 
126 
127 /* Supported L4 protocols */
128 #define foreach_snat_protocol \
129  _(UDP, 0, udp, "udp") \
130  _(TCP, 1, tcp, "tcp") \
131  _(ICMP, 2, icmp, "icmp")
132 
133 typedef enum
134 {
135 #define _(N, i, n, s) SNAT_PROTOCOL_##N = i,
137 #undef _
139 
140 
141 /* Session state */
142 #define foreach_snat_session_state \
143  _(0, UNKNOWN, "unknown") \
144  _(1, UDP_ACTIVE, "udp-active") \
145  _(2, TCP_SYN_SENT, "tcp-syn-sent") \
146  _(3, TCP_ESTABLISHED, "tcp-established") \
147  _(4, TCP_FIN_WAIT, "tcp-fin-wait") \
148  _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \
149  _(6, TCP_CLOSING, "tcp-closing") \
150  _(7, TCP_LAST_ACK, "tcp-last-ack") \
151  _(8, TCP_CLOSED, "tcp-closed") \
152  _(9, ICMP_ACTIVE, "icmp-active")
153 
154 typedef enum
155 {
156 #define _(v, N, s) SNAT_SESSION_##N = v,
158 #undef _
160 
161 /* Endpoint dependent TCP session state */
162 #define NAT44_SES_I2O_FIN 1
163 #define NAT44_SES_O2I_FIN 2
164 #define NAT44_SES_I2O_FIN_ACK 4
165 #define NAT44_SES_O2I_FIN_ACK 8
166 #define NAT44_SES_I2O_SYN 16
167 #define NAT44_SES_O2I_SYN 32
168 #define NAT44_SES_RST 64
169 
170 /* Session flags */
171 #define SNAT_SESSION_FLAG_STATIC_MAPPING 1
172 #define SNAT_SESSION_FLAG_UNKNOWN_PROTO 2
173 #define SNAT_SESSION_FLAG_LOAD_BALANCING 4
174 #define SNAT_SESSION_FLAG_TWICE_NAT 8
175 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT 16
176 #define SNAT_SESSION_FLAG_FWD_BYPASS 32
177 #define SNAT_SESSION_FLAG_AFFINITY 64
178 #define SNAT_SESSION_FLAG_OUTPUT_FEATURE 128
179 
180 /* NAT interface flags */
181 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
182 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
183 
184 /* Static mapping flags */
185 #define NAT_STATIC_MAPPING_FLAG_ADDR_ONLY 1
186 #define NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY 2
187 #define NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT 4
188 #define NAT_STATIC_MAPPING_FLAG_LB 8
189 
190 /* *INDENT-OFF* */
191 typedef CLIB_PACKED(struct
192 {
193  /* Outside network key */
194  snat_session_key_t out2in;
195 
196  /* Inside network key */
197  snat_session_key_t in2out;
198 
199  /* Flags */
200  u32 flags;
201 
202  /* Per-user translations */
203  u32 per_user_index;
204  u32 per_user_list_head_index;
205 
206  /* Last heard timer */
207  f64 last_heard;
208 
209  /* Last HA refresh */
210  f64 ha_last_refreshed;
211 
212  /* Counters */
213  u64 total_bytes;
214  u32 total_pkts;
215 
216  /* External host address and port */
217  ip4_address_t ext_host_addr;
218  u16 ext_host_port;
219 
220  /* External host address and port after translation */
221  ip4_address_t ext_host_nat_addr;
222  u16 ext_host_nat_port;
223 
224  /* TCP session state */
225  u8 state;
226  u32 i2o_fin_seq;
227  u32 o2i_fin_seq;
228 
229  /* user index */
230  u32 user_index;
231 }) snat_session_t;
232 /* *INDENT-ON* */
233 
234 
235 typedef struct
236 {
242 } snat_user_t;
243 
244 typedef struct
245 {
248 /* *INDENT-OFF* */
249 #define _(N, i, n, s) \
250  u16 busy_##n##_ports; \
251  u16 * busy_##n##_ports_per_thread; \
252  uword * busy_##n##_port_bitmap;
254 #undef _
255 /* *INDENT-ON* */
256 } snat_address_t;
257 
258 typedef struct
259 {
263 
264 typedef struct
265 {
266  /* Inside network port */
268  /* Outside network address and port */
270  /* Session state */
272  /* Expire timeout */
275 
276 typedef struct
277 {
278  /* inside IP address range */
281  /* outside IP address range */
284  /* inside IP addresses / outside IP addresses */
286  /* number of ports available to internal host */
288  /* session counter */
290  /* vector of sessions */
293 
294 typedef struct
295 {
296  /* backend IP address */
298  /* backend port number */
300  /* probability of the backend to be randomly matched */
303  /* backend FIB table */
307 
308 typedef enum
309 {
310  /* twice-nat disabled */
312  /* twice-nat enabled */
314  /* twice-nat only when src IP equals dst IP after translation */
317 
318 typedef enum
319 {
320  /* no load-balancing */
322  /* load-balancing */
324  /* load-balancing with affinity */
326 } lb_nat_type_t;
327 
328 typedef struct
329 {
330  /* local IP address */
332  /* external IP address */
334  /* local port */
336  /* external port */
338  /* is twice-nat */
339  twice_nat_type_t twice_nat;
340  /* local FIB table */
343  /* protocol */
344  snat_protocol_t proto;
345  /* 0 = disabled, otherwise client IP affinity sticky time in seconds */
347  /* worker threads used by backends/local host */
349  /* opaque string tag */
350  u8 *tag;
351  /* backends for load-balancing mode */
353  /* affinity per service lis */
355  /* flags */
358 
359 typedef struct
360 {
364 
365 typedef struct
366 {
372  snat_protocol_t proto;
376  int is_add;
379  u8 *tag;
381 
382 typedef struct
383 {
384  /* Main lookup tables */
385  clib_bihash_8_8_t out2in;
386  clib_bihash_8_8_t in2out;
387 
388  /* Endpoint dependent sessions lookup tables */
389  clib_bihash_16_8_t out2in_ed;
390  clib_bihash_16_8_t in2out_ed;
391 
392  /* Find-a-user => src address lookup */
393  clib_bihash_8_8_t user_hash;
394 
395  /* User pool */
397 
398  /* Session pool */
399  snat_session_t *sessions;
400 
401  /* Pool of doubly-linked list elements */
403 
404  /* NAT thread index */
407 
408 struct snat_main_s;
409 
410 /* ICMP session match function */
412  vlib_node_runtime_t * node,
413  u32 thread_index,
414  vlib_buffer_t * b0,
415  ip4_header_t * ip0, u8 * p_proto,
416  snat_session_key_t * p_value,
417  u8 * p_dont_translate, void *d,
418  void *e);
419 
420 /* Return worker thread index for given packet */
422  u32 rx_fib_index);
423 
424 /* NAT address and port allacotaion function */
425 typedef int (nat_alloc_out_addr_and_port_function_t) (snat_address_t *
426  addresses,
427  u32 fib_index,
428  u32 thread_index,
429  snat_session_key_t * k,
431  u32 snat_thread_index);
432 
433 typedef struct snat_main_s
434 {
435  /* ICMP session match functions */
438 
439  /* Thread settings */
447 
448  /* Per thread data */
450 
451  /* Find a static mapping by local */
452  clib_bihash_8_8_t static_mapping_by_local;
453 
454  /* Find a static mapping by external */
455  clib_bihash_8_8_t static_mapping_by_external;
456 
457  /* Static mapping pool */
459 
460  /* Interface pool */
463 
464  /* Vector of outside addresses */
465  snat_address_t *addresses;
466  /* Address and port allocation function */
468  /* Address and port allocation type */
469  nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg;
470  /* Port set parameters (MAP-E) */
474  /* Port range parameters */
477 
478  /* vector of outside fibs */
480 
481  /* Vector of twice NAT addresses for extenal hosts */
482  snat_address_t *twice_nat_addresses;
483 
484  /* sw_if_indices whose intfc addresses should be auto-added */
487 
488  /* vector of interface address static mappings to resolve. */
490 
491  /* Randomize port allocation order */
493 
494  /* Worker handoff frame-queue index */
498 
499  /* node indexes */
501 
519 
526 
527 
528  /* Deterministic NAT mappings */
530 
531  /* If forwarding is enabled */
533 
534  /* Config parameters */
550 
551  /* values of various timeouts */
556 
557  /* TCP MSS clamping */
560 
561  /* counters/gauges */
564 
565  /* API message ID base */
567 
568  /* log class */
570 
571  /* convenience */
577 } snat_main_t;
578 
579 typedef struct
580 {
584 
585 typedef struct
586 {
590 
591 extern snat_main_t snat_main;
612 
613 /* format functions */
624 /* unformat functions */
626 
627 /** \brief Check if SNAT session is created from static mapping.
628  @param s SNAT session
629  @return 1 if SNAT session is created from static mapping otherwise 0
630 */
631 #define snat_is_session_static(s) (s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING)
632 
633 /** \brief Check if SNAT session for unknown protocol.
634  @param s SNAT session
635  @return 1 if SNAT session for unknown protocol otherwise 0
636 */
637 #define snat_is_unk_proto_session(s) (s->flags & SNAT_SESSION_FLAG_UNKNOWN_PROTO)
638 
639 /** \brief Check if NAT session is twice NAT.
640  @param s NAT session
641  @return 1 if NAT session is twice NAT
642 */
643 #define is_twice_nat_session(s) (s->flags & SNAT_SESSION_FLAG_TWICE_NAT)
644 
645 /** \brief Check if NAT session is load-balancing.
646  @param s NAT session
647  @return 1 if NAT session is load-balancing
648 */
649 #define is_lb_session(s) (s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING)
650 
651 /** \brief Check if NAT session is forwarding bypass.
652  @param s NAT session
653  @return 1 if NAT session is load-balancing
654 */
655 #define is_fwd_bypass_session(s) (s->flags & SNAT_SESSION_FLAG_FWD_BYPASS)
656 
657 /** \brief Check if NAT session is endpoint dependent.
658  @param s NAT session
659  @return 1 if NAT session is endpoint dependent
660 */
661 #define is_ed_session(s) (s->flags & SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT)
662 
663 /** \brief Check if NAT session has affinity record.
664  @param s NAT session
665  @return 1 if NAT session has affinity record
666 */
667 #define is_affinity_sessions(s) (s->flags & SNAT_SESSION_FLAG_AFFINITY)
668 
669 /** \brief Check if NAT interface is inside.
670  @param i NAT interfce
671  @return 1 if inside interface
672 */
673 #define nat_interface_is_inside(i) i->flags & NAT_INTERFACE_FLAG_IS_INSIDE
674 
675 /** \brief Check if NAT interface is outside.
676  @param i NAT interfce
677  @return 1 if outside interface
678 */
679 #define nat_interface_is_outside(i) i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE
680 
681 /** \brief Check if NAT44 endpoint-dependent TCP session is closed.
682  @param s NAT session
683  @return 1 if session is closed
684 */
685 #define nat44_is_ses_closed(s) s->state == 0xf
686 
687 /** \brief Check if NAT static mapping is address only (1:1NAT).
688  @param sm NAT static mapping
689  @return 1 if 1:1NAT, 0 if 1:1NAPT
690 */
691 #define is_addr_only_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_ADDR_ONLY)
692 
693 /** \brief Check if NAT static mapping match only out2in direction.
694  @param sm NAT static mapping
695  @return 1 if rule match only out2in direction
696 */
697 #define is_out2in_only_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY)
698 
699 /** \brief Check if NAT static mapping is identity NAT.
700  @param sm NAT static mapping
701  @return 1 if identity NAT
702 */
703 #define is_identity_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT)
704 
705 /** \brief Check if NAT static mapping is load-balancing.
706  @param sm NAT static mapping
707  @return 1 if load-balancing
708 */
709 #define is_lb_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_LB)
710 
711 /** \brief Check if client initiating TCP connection (received SYN from client)
712  @param t TCP header
713  @return 1 if client initiating TCP connection
714 */
715 #define tcp_is_init(t) ((t->flags & TCP_FLAG_SYN) && !(t->flags & TCP_FLAG_ACK))
716 
717 /* logging */
718 #define nat_log_err(...) \
719  vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
720 #define nat_log_warn(...) \
721  vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
722 #define nat_log_notice(...) \
723  vlib_log(VLIB_LOG_LEVEL_NOTICE, snat_main.log_class, __VA_ARGS__)
724 #define nat_log_info(...) \
725  vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
726 #define nat_log_debug(...)\
727  vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
728 
729 /* ICMP session match functions */
731  u32 thread_index, vlib_buffer_t * b0,
732  ip4_header_t * ip0, u8 * p_proto,
733  snat_session_key_t * p_value,
734  u8 * p_dont_translate, void *d, void *e);
736  u32 thread_index, vlib_buffer_t * b0,
737  ip4_header_t * ip0, u8 * p_proto,
738  snat_session_key_t * p_value,
739  u8 * p_dont_translate, void *d, void *e);
741  u32 thread_index, vlib_buffer_t * b0,
742  ip4_header_t * ip0, u8 * p_proto,
743  snat_session_key_t * p_value,
744  u8 * p_dont_translate, void *d, void *e);
746  u32 thread_index, vlib_buffer_t * b0,
747  ip4_header_t * ip0, u8 * p_proto,
748  snat_session_key_t * p_value,
749  u8 * p_dont_translate, void *d, void *e);
750 
751 /* ICMP deterministic NAT session match functions */
753  u32 thread_index, vlib_buffer_t * b0,
754  ip4_header_t * ip0, u8 * p_proto,
755  snat_session_key_t * p_value,
756  u8 * p_dont_translate, void *d, void *e);
758  u32 thread_index, vlib_buffer_t * b0,
759  ip4_header_t * ip0, u8 * p_proto,
760  snat_session_key_t * p_value,
761  u8 * p_dont_translate, void *d, void *e);
762 
763 /* ICMP endpoint-dependent session match functions */
765  u32 thread_index, vlib_buffer_t * b0,
766  ip4_header_t * ip0, u8 * p_proto,
767  snat_session_key_t * p_value,
768  u8 * p_dont_translate, void *d, void *e);
770  u32 thread_index, vlib_buffer_t * b0,
771  ip4_header_t * ip0, u8 * p_proto,
772  snat_session_key_t * p_value,
773  u8 * p_dont_translate, void *d, void *e);
774 
776  icmp46_header_t * icmp0, u32 sw_if_index0, u32 rx_fib_index0,
777  vlib_node_runtime_t * node, u32 next0, u32 thread_index,
778  void *d, void *e);
779 
781  icmp46_header_t * icmp0, u32 sw_if_index0, u32 rx_fib_index0,
782  vlib_node_runtime_t * node, u32 next0, u32 thread_index,
783  void *d, void *e);
784 
785 /* hairpinning functions */
787  ip4_header_t * ip0, icmp46_header_t * icmp0,
788  int is_ed);
790  ip4_header_t * ip);
792  ip4_header_t * ip);
794  ip4_header_t * ip0, udp_header_t * udp0,
795  tcp_header_t * tcp0, u32 proto0, int is_ed);
797  ip4_header_t * ip0, u16 sport, u16 dport,
798  u32 proto0, int is_ed);
799 
800 /* Call back functions for clib_bihash_add_or_overwrite_stale */
805 
806 /**
807  * @brief Increment IPv4 address
808  */
810 
811 /**
812  * @brief Add external address to NAT44 pool
813  *
814  * @param addr IPv4 address
815  * @param vrf_id VRF id of tenant, ~0 means independent of VRF
816  * @param twice_nat 1 if twice NAT address
817  *
818  * @return 0 on success, non-zero value otherwise
819  */
820 int snat_add_address (snat_main_t * sm, ip4_address_t * addr, u32 vrf_id,
821  u8 twice_nat);
822 
823 /**
824  * @brief Delete external address from NAT44 pool
825  *
826  * @param addr IPv4 address
827  * @param delete_sm 1 if delete static mapping using address
828  * @param twice_nat 1 if twice NAT address
829  *
830  * @return 0 on success, non-zero value otherwise
831  */
832 int snat_del_address (snat_main_t * sm, ip4_address_t addr, u8 delete_sm,
833  u8 twice_nat);
834 
835 /**
836  * @brief Add/delete external address to FIB DPO (out2in DPO mode)
837  *
838  * @param addr IPv4 address
839  * @param is_add 1 = add, 0 = delete
840  *
841  * @return 0 on success, non-zero value otherwise
842  */
844 
845 /**
846  * @brief Add/delete NAT44 static mapping
847  *
848  * @param l_addr local IPv4 address
849  * @param e_addr external IPv4 address
850  * @param l_port local port number
851  * @param e_port external port number
852  * @param vrf_id local VRF ID
853  * @param addr_only 1 = 1:1NAT, 0 = 1:1NAPT
854  * @param sw_if_index use interface address as external IPv4 address
855  * @param proto L4 protocol
856  * @param is_add 1 = add, 0 = delete
857  * @param twice_nat twice-nat mode
858  * @param out2in_only if 1 rule match only out2in direction
859  * @param tag opaque string tag
860  * @param identity_nat identity NAT
861  *
862  * @return 0 on success, non-zero value otherwise
863  */
865  u16 l_port, u16 e_port, u32 vrf_id,
866  int addr_only, u32 sw_if_index,
867  snat_protocol_t proto, int is_add,
868  twice_nat_type_t twice_nat, u8 out2in_only,
869  u8 * tag, u8 identity_nat);
870 
871 /**
872  * @brief Add/delete static mapping with load-balancing (multiple backends)
873  *
874  * @param e_addr external IPv4 address
875  * @param e_port external port number
876  * @param proto L4 protocol
877  * @param locals list of local backends
878  * @param is_add 1 = add, 0 = delete
879  * @param twice_nat twice-nat mode
880  * @param out2in_only if 1 rule match only out2in direction
881  * @param tag opaque string tag
882  * @param affinity 0 = disabled, otherwise client IP affinity sticky time
883  *
884  * @return 0 on success, non-zero value otherwise
885  */
887  snat_protocol_t proto,
888  nat44_lb_addr_port_t * locals, u8 is_add,
889  twice_nat_type_t twice_nat,
890  u8 out2in_only, u8 * tag, u32 affinity);
891 
893  ip4_address_t l_addr, u16 l_port,
894  snat_protocol_t proto, u32 vrf_id,
895  u8 probability, u8 is_add);
896 
898 
899 /**
900  * @brief Set NAT plugin workers
901  *
902  * @param bitmap NAT workers bitmap
903  *
904  * @return 0 on success, non-zero value otherwise
905  */
906 int snat_set_workers (uword * bitmap);
907 
908 /**
909  * @brief Enable/disable NAT44 feature on the interface
910  *
911  * @param sw_if_index software index of the interface
912  * @param is_inside 1 = inside, 0 = outside
913  * @param is_del 1 = delete, 0 = add
914  *
915  * @return 0 on success, non-zero value otherwise
916  */
917 int snat_interface_add_del (u32 sw_if_index, u8 is_inside, int is_del);
918 
919 /**
920  * @brief Enable/disable NAT44 output feature on the interface (postrouting NAT)
921  *
922  * @param sw_if_index software index of the interface
923  * @param is_inside 1 = inside, 0 = outside
924  * @param is_del 1 = delete, 0 = add
925  *
926  * @return 0 on success, non-zero value otherwise
927  */
929  int is_del);
930 
931 /**
932  * @brief Add/delete NAT44 pool address from specific interfce
933  *
934  * @param sw_if_index software index of the interface
935  * @param is_del 1 = delete, 0 = add
936  * @param twice_nat 1 = twice NAT address for extenal hosts
937  *
938  * @return 0 on success, non-zero value otherwise
939  */
941  u8 twice_nat);
942 
943 /**
944  * @brief Delete NAT44 session
945  *
946  * @param addr IPv4 address
947  * @param port L4 port number
948  * @param proto L4 protocol
949  * @param vrf_id VRF ID
950  * @param is_in 1 = inside network address and port pair, 0 = outside
951  *
952  * @return 0 on success, non-zero value otherwise
953  */
955  snat_protocol_t proto, u32 vrf_id, int is_in);
956 
957 /**
958  * @brief Delete NAT44 endpoint-dependent session
959  *
960  * @param addr IPv4 address
961  * @param port L4 port number
962  * @param proto L4 protocol
963  * @param vrf_id VRF ID
964  * @param is_in 1 = inside network address and port pair, 0 = outside
965  *
966  * @return 0 on success, non-zero value otherwise
967  */
969  ip4_address_t * eh_addr, u16 eh_port, u8 proto,
970  u32 vrf_id, int is_in);
971 
972 /**
973  * @brief Free NAT44 session data (lookup keys, external addrres port)
974  *
975  * @param s NAT session
976  * @param thread_index thread index
977  * @param is_ha is HA event
978  */
979 void nat_free_session_data (snat_main_t * sm, snat_session_t * s,
980  u32 thread_index, u8 is_ha);
981 
982 /**
983  * @brief Find or create NAT user
984  *
985  * @param addr IPv4 address
986  * @param fib_index FIB table index
987  * @param thread_index thread index
988  *
989  * @return NAT user data structure on success otherwise zero value
990  */
992  u32 fib_index, u32 thread_index);
993 
994 /**
995  * @brief Allocate new NAT session or recycle last used
996  *
997  * @param u NAT user
998  * @param thread_index thread index
999  *
1000  * @return session data structure on success otherwise zero value
1001  */
1002 snat_session_t *nat_session_alloc_or_recycle (snat_main_t * sm,
1003  snat_user_t * u,
1004  u32 thread_index, f64 now);
1005 
1006 /**
1007  * @brief Allocate NAT endpoint-dependent session
1008  *
1009  * @param u NAT user
1010  * @param thread_index thread index
1011  *
1012  * @return session data structure on success otherwise zero value
1013  */
1014 snat_session_t *nat_ed_session_alloc (snat_main_t * sm, snat_user_t * u,
1015  u32 thread_index, f64 now);
1016 
1017 /**
1018  * @brief Set address and port assignment algorithm for MAP-E CE
1019  *
1020  * @param psid Port Set Identifier value
1021  * @param psid_offset number of offset bits
1022  * @param psid_length length of PSID
1023  */
1025  u16 psid_length);
1026 
1027 /**
1028  * @brief Set address and port assignment algorithm for port range
1029  *
1030  * @param start_port beginning of the port range
1031  * @param end_port end of the port range
1032  */
1034 
1035 /**
1036  * @brief Set address and port assignment algorithm to default/standard
1037  */
1039 
1040 /**
1041  * @brief Free outside address and port pair
1042  *
1043  * @param addresses vector of outside addresses
1044  * @param thread_index thread index
1045  * @param k address, port and protocol
1046  */
1047 void snat_free_outside_address_and_port (snat_address_t * addresses,
1048  u32 thread_index,
1049  snat_session_key_t * k);
1050 
1051 /**
1052  * @brief Alloc outside address and port
1053  *
1054  * @param addresses vector of outside addresses
1055  * @param fib_index FIB table index
1056  * @param thread_index thread index
1057  * @param k allocated address and port pair
1058  * @param port_per_thread number of ports per threead
1059  * @param snat_thread_index NAT thread index
1060  *
1061  * @return 0 on success, non-zero value otherwise
1062  */
1063 int snat_alloc_outside_address_and_port (snat_address_t * addresses,
1064  u32 fib_index,
1065  u32 thread_index,
1066  snat_session_key_t * k,
1067  u16 port_per_thread,
1068  u32 snat_thread_index);
1069 
1070 /**
1071  * @brief Match NAT44 static mapping.
1072  *
1073  * @param match address and port to match
1074  * @param mapping external/local address and port of the matched mapping
1075  * @param by_external if 0 match by local address otherwise match by external
1076  * address
1077  * @param is_addr_only 1 if matched mapping is address only
1078  * @param twice_nat matched mapping is twice NAT type
1079  * @param lb 1 if matched mapping is load-balanced
1080  * @param ext_host_addr external host address
1081  *
1082  * @returns 0 if match found otherwise 1.
1083  */
1085  snat_session_key_t match,
1086  snat_session_key_t * mapping,
1087  u8 by_external,
1088  u8 * is_addr_only,
1089  twice_nat_type_t * twice_nat,
1090  lb_nat_type_t * lb,
1091  ip4_address_t * ext_host_addr,
1092  u8 * is_identity_nat);
1093 
1094 /**
1095  * @brief Add/del NAT address to FIB.
1096  *
1097  * Add the external NAT address to the FIB as receive entries. This ensures
1098  * that VPP will reply to ARP for this address and we don't need to enable
1099  * proxy ARP on the outside interface.
1100  *
1101  * @param addr IPv4 address
1102  * @param plen address prefix length
1103  * @param sw_if_index software index of the outside interface
1104  * @param is_add 0 = delete, 1 = add.
1105  */
1107  u8 p_len, u32 sw_if_index, int is_add);
1108 
1109 /*
1110  * Why is this here? Because we don't need to touch this layer to
1111  * simply reply to an icmp. We need to change id to a unique
1112  * value to NAT an echo request/reply.
1113  */
1114 
1115 typedef struct
1116 {
1120 
1121 typedef struct
1122 {
1125 
1126 #endif /* __included_nat_h__ */
1127 
1128 /*
1129  * fd.io coding-style-patch-verification: ON
1130  *
1131  * Local Variables:
1132  * eval: (c-set-style "gnu")
1133  * End:
1134  */
ip4_address_t external_addr
Definition: nat.h:333
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm, u8 twice_nat)
Delete external address from NAT44 pool.
Definition: nat.c:1618
u32 user_memory_size
Definition: nat.h:544
clib_error_t * snat_api_init(vlib_main_t *vm, snat_main_t *sm)
Definition: nat_api.c:3499
u32 sw_if_index
Definition: ipsec_gre.api:37
#define foreach_nat_addr_and_port_alloc_alg
Definition: nat.h:114
nat_outside_fib_t * outside_fibs
Definition: nat.h:479
vlib_node_registration_t snat_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_src_node)
nat_addr_and_port_alloc_alg_t
Definition: nat.h:119
uword( unformat_function_t)(unformat_input_t *input, va_list *args)
Definition: format.h:232
u32 sessions_per_user_list_head_index
Definition: nat.h:239
u32 flags
Definition: vhost_user.h:115
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 feature on the interface.
Definition: nat.c:1732
u16 ext_host_port
Definition: nat.h:85
u32 icmp_out2in(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0, vlib_node_runtime_t *node, u32 next0, u32 thread_index, void *d, void *e)
Definition: out2in.c:518
u32 hairpin_dst_node_index
Definition: nat.h:521
u16 out_port
Definition: nat.h:86
u32 ed_hairpinning_node_index
Definition: nat.h:523
a
Definition: bitmap.h:538
u32 icmp_timeout
Definition: nat.h:555
typedef CLIB_PACKED(struct{snat_session_key_t out2in;snat_session_key_t in2out;u32 flags;u32 per_user_index;u32 per_user_list_head_index;f64 last_heard;f64 ha_last_refreshed;u64 total_bytes;u32 total_pkts;ip4_address_t ext_host_addr;u16 ext_host_port;ip4_address_t ext_host_nat_addr;u16 ext_host_nat_port;u8 state;u32 i2o_fin_seq;u32 o2i_fin_seq;u32 user_index;}) snat_session_t
u32 fq_in2out_output_index
Definition: nat.h:496
u16 start_port
Definition: nat.h:475
u32 icmp_match_in2out_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
u32 ed_out2in_node_index
Definition: nat.h:514
u64 as_u64
Definition: bihash_doc.h:63
snat_session_t * nat_session_alloc_or_recycle(snat_main_t *sm, snat_user_t *u, u32 thread_index, f64 now)
Allocate new NAT session or recycle last used.
Definition: nat.c:351
u32 nsessions
Definition: nat.h:240
#define foreach_snat_session_state
Definition: nat.h:142
unsigned long u64
Definition: types.h:89
ip4_address_t addr
Definition: nat.h:297
int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del, u8 twice_nat)
Add/delete NAT44 pool address from specific interfce.
Definition: nat.c:3867
snat_protocol_t proto
Definition: nat.h:344
u16 port_per_thread
Definition: nat.h:445
u32 ed_in2out_reass_node_index
Definition: nat.h:510
u32 nstaticsessions
Definition: nat.h:241
u32 ed_out2in_slowpath_node_index
Definition: nat.h:515
u32 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
Definition: out2in.c:325
vlib_node_registration_t nat44_ed_in2out_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_node)
Definition: in2out_ed.c:1673
format_function_t format_det_map_ses
Definition: nat.h:618
u32( snat_icmp_match_function_t)(struct snat_main_s *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Definition: nat.h:411
vlib_node_registration_t snat_det_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)
int nat44_i2o_ed_is_idle_session_cb(clib_bihash_kv_16_8_t *kv, void *arg)
Definition: in2out_ed.c:154
vlib_node_registration_t nat44_ed_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_hairpin_src_node)
u32 fib_index
Definition: nat.h:238
format_function_t format_snat_static_mapping
Definition: nat.h:615
format_function_t format_snat_key
Definition: nat.h:619
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
snat_det_map_t * det_maps
Definition: nat.h:529
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
Definition: nat.h:467
u32 num_snat_thread
Definition: nat.h:446
#define foreach_snat_protocol
Definition: nat.h:128
dlist_elt_t * list_pool
Definition: nat.h:402
u8 in_plen
Definition: nat.h:280
struct _tcp_header tcp_header_t
int snat_hairpinning(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, udp_header_t *udp0, tcp_header_t *tcp0, u32 proto0, int is_ed)
vhost_vring_addr_t addr
Definition: vhost_user.h:121
unsigned char u8
Definition: types.h:56
u8 deterministic
Definition: nat.h:537
u32 icmp_match_out2in_ed(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Definition: out2in_ed.c:504
u16 l_port
Definition: nat.h:70
nat44_lb_addr_port_t * locals
Definition: nat.h:352
int snat_set_workers(uword *bitmap)
Set NAT plugin workers.
Definition: nat.c:2136
u32 user_buckets
Definition: nat.h:543
double f64
Definition: types.h:142
clib_bihash_8_8_t user_hash
Definition: nat.h:393
u32 cached_sw_if_index
Definition: nat.h:587
void nat_set_alloc_addr_and_port_mape(u16 psid, u16 psid_offset, u16 psid_length)
Set address and port assignment algorithm for MAP-E CE.
Definition: nat.c:4022
u32 max_translations_per_user
Definition: nat.h:545
u32( snat_get_worker_function_t)(ip4_header_t *ip, u32 rx_fib_index)
Definition: nat.h:421
clib_bihash_8_8_t in2out
Definition: nat.h:386
u32 in2out_reass_node_index
Definition: nat.h:507
u32 in2out_output_node_index
Definition: nat.h:503
u32 ed_in2out_node_index
Definition: nat.h:508
u32 vlib_log_class_t
Definition: vlib.h:50
u16 r_port
Definition: nat.h:71
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
Definition: out2in.c:1341
ip4_address_t ext_host_addr
Definition: nat.h:84
u32 det_in2out_node_index
Definition: nat.h:517
u32 translation_buckets
Definition: nat.h:540
lb_nat_type_t
Definition: nat.h:318
ip4_address_t addr
Definition: nat.h:237
int snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
Add external address to NAT44 pool.
Definition: nat.c:533
ip4_main_t * ip4_main
Definition: nat.h:574
vhost_vring_state_t state
Definition: vhost_user.h:120
unsigned int u32
Definition: types.h:88
A collection of simple counters.
Definition: counter.h:57
vlib_node_registration_t snat_in2out_output_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_node)
Definition: in2out.c:1609
ip4_address_t local_addr
Definition: nat.h:331
vlib_node_registration_t snat_in2out_output_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_worker_handoff_node)
snat_protocol_t proto
Definition: nat.h:372
u32 icmp_match_out2in_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
vlib_node_registration_t snat_out2in_fast_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_fast_node)
Definition: out2in.c:1864
twice_nat_type_t twice_nat
Definition: nat.h:339
u32 max_translations
Definition: nat.h:542
u32 * auto_add_sw_if_indices_twice_nat
Definition: nat.h:486
vlib_node_registration_t nat44_ed_out2in_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_out2in_node)
Definition: out2in_ed.c:1568
vlib_node_registration_t snat_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_dst_node)
u32 fib_index
Definition: nat.h:260
u16 mss_value_net
Definition: nat.h:559
nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
Definition: nat.h:469
clib_bihash_16_8_t out2in_ed
Definition: nat.h:389
snat_det_session_t * sessions
Definition: nat.h:291
u16 mss_clamping
Definition: nat.h:558
vlib_main_t * vlib_main
Definition: nat.h:572
unsigned short u16
Definition: types.h:57
u8 out2in_dpo
Definition: nat.h:538
snat_static_mapping_t * static_mappings
Definition: nat.h:458
u32 inside_fib_index
Definition: nat.h:549
u32 udp_timeout
Definition: nat.h:552
u8 static_mapping_only
Definition: nat.h:535
int nat44_del_ed_session(snat_main_t *sm, ip4_address_t *addr, u16 port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 vrf_id, int is_in)
Delete NAT44 endpoint-dependent session.
Definition: nat.c:3978
vlib_node_registration_t nat44_ed_out2in_worker_handoff_node
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index, u8 is_ha)
Free NAT44 session data (lookup keys, external addrres port)
Definition: nat.c:179
void nat_set_alloc_addr_and_port_default(void)
Set address and port assignment algorithm to default/standard.
Definition: nat.c:4045
int nat44_lb_static_mapping_add_del_local(ip4_address_t e_addr, u16 e_port, ip4_address_t l_addr, u16 l_port, snat_protocol_t proto, u32 vrf_id, u8 probability, u8 is_add)
Definition: nat.c:1435
void snat_add_del_addr_to_fib(ip4_address_t *addr, u8 p_len, u32 sw_if_index, int is_add)
Add/del NAT address to FIB.
Definition: nat.c:505
u32 hairpin_src_node_index
Definition: nat.h:522
clib_bihash_8_8_t static_mapping_by_external
Definition: nat.h:455
u32 in2out_slowpath_output_node_index
Definition: nat.h:506
u8 psid_offset
Definition: nat.h:471
struct snat_main_s snat_main_t
api_main_t * api_main
Definition: nat.h:576
u8 out_plen
Definition: nat.h:283
u8 psid_length
Definition: nat.h:472
u32 refcount
Definition: nat.h:261
vnet_main_t * vnet_main
Definition: nat.h:573
u32 inside_vrf_id
Definition: nat.h:548
vlib_node_registration_t nat44_ed_in2out_worker_handoff_node
Definition: nat.h:323
u32 snat_icmp_hairpinning(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, int is_ed)
u32 fq_out2in_index
Definition: nat.h:497
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
int nat44_o2i_is_idle_session_cb(clib_bihash_kv_8_8_t *kv, void *arg)
Definition: out2in.c:116
snat_interface_t * output_feature_interfaces
Definition: nat.h:462
u16 src_port
Definition: nat.h:1123
u32 ed_hairpin_src_node_index
Definition: nat.h:525
int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, u32 vrf_id, int addr_only, u32 sw_if_index, snat_protocol_t proto, int is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u8 identity_nat)
Add/delete NAT44 static mapping.
Definition: nat.c:669
snat_main_t snat_main
Definition: nat.c:39
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
snat_session_state_t
Definition: nat.h:154
snat_user_t * users
Definition: nat.h:396
int( nat_alloc_out_addr_and_port_function_t)(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u16 port_per_thread, u32 snat_thread_index)
Definition: nat.h:425
u32 random_seed
Definition: nat.h:492
u32 ed_out2in_reass_node_index
Definition: nat.h:516
clib_bihash_8_8_t out2in
Definition: nat.h:385
int nat44_o2i_ed_is_idle_session_cb(clib_bihash_kv_16_8_t *kv, void *arg)
Definition: out2in_ed.c:129
vlib_main_t * vm
Definition: buffer.c:312
u32 outside_vrf_id
Definition: nat.h:546
ip4_address_t l_addr
Definition: nat.h:67
u8 static_mapping_connection_tracking
Definition: nat.h:536
snat_get_worker_function_t * worker_in2out_cb
Definition: nat.h:443
u16 end_port
Definition: nat.h:476
format_function_t format_snat_static_map_to_resolve
Definition: nat.h:616
u32 ed_in2out_slowpath_node_index
Definition: nat.h:509
u32 error_node_index
Definition: nat.h:500
u32 sharing_ratio
Definition: nat.h:285
ip4_address_t out_addr
Definition: nat.h:282
u16 psid
Definition: nat.h:473
u32 outside_fib_index
Definition: nat.h:547
format_function_t format_nat_addr_and_port_alloc_alg
Definition: nat.h:622
int snat_static_mapping_match(snat_main_t *sm, snat_session_key_t match, snat_session_key_t *mapping, u8 by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat, lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat)
Match NAT44 static mapping.
Definition: nat.c:2498
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:31
ip4_address_t addr
Definition: nat.h:52
u32 ed_hairpin_dst_node_index
Definition: nat.h:524
u32 sw_if_index
Definition: nat.h:361
snat_user_t * nat_user_get_or_create(snat_main_t *sm, ip4_address_t *addr, u32 fib_index, u32 thread_index)
Find or create NAT user.
Definition: nat.c:304
void increment_v4_address(ip4_address_t *a)
Increment IPv4 address.
Definition: nat.c:617
u32 tcp_transitory_timeout
Definition: nat.h:554
ip4_address_t r_addr
Definition: nat.h:68
u32 * auto_add_sw_if_indices
Definition: nat.h:485
u32 in2out_fast_node_index
Definition: nat.h:504
void nat44_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Add/delete external address to FIB DPO (out2in DPO mode)
Definition: nat.c:2842
u32 icmp_match_in2out_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation and create session if needed...
Definition: in2out.c:458
u32 num_workers
Definition: nat.h:440
Definition: nat.h:313
unformat_function_t unformat_snat_protocol
Definition: nat.h:625
u32 first_worker_index
Definition: nat.h:441
u32 det_out2in_node_index
Definition: nat.h:518
void snat_free_outside_address_and_port(snat_address_t *addresses, u32 thread_index, snat_session_key_t *k)
Free outside address and port pair.
Definition: nat.c:2424
snat_get_worker_function_t * worker_out2in_cb
Definition: nat.h:444
u8 is_add
Definition: ipsec_gre.api:36
ip4_address_t l_addr
Definition: nat.h:367
u32 in2out_slowpath_node_index
Definition: nat.h:505
snat_icmp_match_function_t * icmp_match_out2in_cb
Definition: nat.h:437
IPv4 main type.
Definition: ip4.h:96
vlib_log_class_t log_class
Definition: nat.h:569
u64 as_u64
Definition: nat.h:102
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
ip4_address_t addr
Definition: nat.h:99
ip4_address_t in_addr
Definition: nat.h:279
u32 fq_in2out_index
Definition: nat.h:495
u32 out2in_node_index
Definition: nat.h:511
format_function_t format_snat_protocol
Definition: nat.h:621
ip4_address_t addr
Definition: nat.h:246
snat_address_t * twice_nat_addresses
Definition: nat.h:482
u32 icmp_match_out2in_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation.
Definition: out2in.c:455
format_function_t format_snat_session
Definition: nat.h:617
u32 out2in_reass_node_index
Definition: nat.h:513
struct _vlib_node_registration vlib_node_registration_t
Definition: nat.h:321
format_function_t format_nat44_reass_trace
Definition: nat.h:623
vlib_node_registration_t nat44_ed_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_hairpin_dst_node)
vlib_simple_counter_main_t total_users
Definition: nat.h:562
void nat_hairpinning_sm_unknown_proto(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip)
format_function_t format_static_mapping_key
Definition: nat.h:620
twice_nat_type_t
Definition: nat.h:308
u32 hairpinning_node_index
Definition: nat.h:520
u16 msg_id_base
Definition: nat.h:566
u16 ports_per_host
Definition: nat.h:287
VLIB buffer representation.
Definition: buffer.h:102
u32 * workers
Definition: nat.h:442
u64 uword
Definition: types.h:112
snat_main_per_thread_data_t * per_thread_data
Definition: nat.h:449
int nat44_i2o_is_idle_session_cb(clib_bihash_kv_8_8_t *kv, void *arg)
Definition: in2out.c:197
u32 icmp_match_in2out_ed(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Definition: in2out_ed.c:600
snat_protocol_t
Definition: nat.h:133
snat_det_out_key_t out
Definition: nat.h:269
u32 affinity_per_service_list_head_index
Definition: nat.h:354
u32 fib_index
Definition: nat.h:100
snat_address_t * addresses
Definition: nat.h:465
u32 out2in_fast_node_index
Definition: nat.h:512
void nat_set_alloc_addr_and_port_range(u16 start_port, u16 end_port)
Set address and port assignment algorithm for port range.
Definition: nat.c:4034
u32 in2out_node_index
Definition: nat.h:502
format_function_t format_snat_user
Definition: nat.h:614
snat_static_map_resolve_t * to_resolve
Definition: nat.h:489
void nat44_ed_hairpinning_unknown_proto(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip)
int nat44_add_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, snat_protocol_t proto, nat44_lb_addr_port_t *locals, u8 is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u32 affinity)
Add/delete static mapping with load-balancing (multiple backends)
Definition: nat.c:1159
vlib_node_registration_t snat_in2out_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node)
vlib_node_registration_t snat_in2out_fast_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_fast_node)
Definition: in2out.c:2169
u8 forwarding_enabled
Definition: nat.h:532
u32 translation_memory_size
Definition: nat.h:541
int snat_alloc_outside_address_and_port(snat_address_t *addresses, u32 fib_index, u32 thread_index, snat_session_key_t *k, u16 port_per_thread, u32 snat_thread_index)
Alloc outside address and port.
Definition: nat.c:2643
int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 output feature on the interface (postrouting NAT)
Definition: nat.c:1981
u32 ses_num
Definition: nat.h:289
u32 icmp_in2out(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0, vlib_node_runtime_t *node, u32 next0, u32 thread_index, void *d, void *e)
Definition: in2out.c:648
vlib_node_registration_t nat44_ed_in2out_output_worker_handoff_node
clib_bihash_16_8_t in2out_ed
Definition: nat.h:390
u8 endpoint_dependent
Definition: nat.h:539
u16 dst_port
Definition: udp.api:42
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
Definition: in2out.c:1576
vlib_node_registration_t nat44_ed_in2out_output_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_node)
Definition: in2out_ed.c:1700
vlib_simple_counter_main_t total_sessions
Definition: nat.h:563
ip_lookup_main_t * ip4_lookup_main
Definition: nat.h:575
u32 icmp_match_in2out_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for ICMP packet translation.
Definition: in2out.c:577
snat_session_t * sessions
Definition: nat.h:399
u32 cached_ip4_address
Definition: nat.h:588
snat_icmp_match_function_t * icmp_match_in2out_cb
Definition: nat.h:436
snat_session_t * nat_ed_session_alloc(snat_main_t *sm, snat_user_t *u, u32 thread_index, f64 now)
Allocate NAT endpoint-dependent session.
Definition: nat.c:426
clib_bihash_8_8_t static_mapping_by_local
Definition: nat.h:452
int nat44_del_session(snat_main_t *sm, ip4_address_t *addr, u16 port, snat_protocol_t proto, u32 vrf_id, int is_in)
Delete NAT44 session.
Definition: nat.c:3935
u32 fib_index
Definition: nat.h:247
void nat44_reass_hairpinning(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, u16 sport, u16 dport, u32 proto0, int is_ed)
snat_interface_t * interfaces
Definition: nat.h:461
u8 protocol
Definition: ipsec.api:96
u32 tcp_established_timeout
Definition: nat.h:553