2 * Copyright (c) 2020 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * NAT plugin global declarations
19 #ifndef __included_nat44_ed_h__
20 #define __included_nat44_ed_h__
22 #include <vnet/vnet.h>
23 #include <vnet/ip/ip.h>
24 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/ip/icmp46_packet.h>
26 #include <vnet/api_errno.h>
27 #include <vnet/fib/fib_source.h>
28 #include <vppinfra/elog.h>
29 #include <vppinfra/bihash_8_8.h>
30 #include <vppinfra/bihash_16_8.h>
31 #include <vppinfra/hash.h>
32 #include <vppinfra/dlist.h>
33 #include <vppinfra/error.h>
34 #include <vlibapi/api.h>
36 #include <nat/lib/lib.h>
37 #include <nat/lib/inlines.h>
39 /* default number of worker handoff frame queue elements */
40 #define NAT_FQ_NELTS_DEFAULT 64
42 /* number of attempts to get a port for ED overloading algorithm, if rolling
43 * a dice this many times doesn't produce a free port, it's treated
44 * as if there were no free ports available to conserve resources */
45 #define ED_PORT_ALLOC_ATTEMPTS (10)
47 /* NAT buffer flags */
48 #define SNAT_FLAG_HAIRPINNING (1 << 0)
50 /* NAT44 API Configuration flags */
51 #define foreach_nat44_config_flag \
52 _ (0x00, IS_ENDPOINT_INDEPENDENT) \
53 _ (0x01, IS_ENDPOINT_DEPENDENT) \
54 _ (0x02, IS_STATIC_MAPPING_ONLY) \
55 _ (0x04, IS_CONNECTION_TRACKING)
57 typedef enum nat44_config_flags_t_
59 #define _(n,f) NAT44_API_##f = n,
60 foreach_nat44_config_flag
62 } nat44_config_flags_t;
66 /* nat44 plugin features */
67 u8 static_mapping_only;
68 u8 connection_tracking;
73 /* maximum number of sessions */
82 NAT_NEXT_IN2OUT_ED_FAST_PATH,
83 NAT_NEXT_IN2OUT_ED_SLOW_PATH,
84 NAT_NEXT_IN2OUT_ED_OUTPUT_FAST_PATH,
85 NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH,
86 NAT_NEXT_OUT2IN_ED_FAST_PATH,
87 NAT_NEXT_OUT2IN_ED_SLOW_PATH,
88 NAT_NEXT_IN2OUT_CLASSIFY,
89 NAT_NEXT_OUT2IN_CLASSIFY,
99 /* External address and port allocation modes */
100 #define foreach_nat_addr_and_port_alloc_alg \
101 _(0, DEFAULT, "default") \
102 _(1, MAPE, "map-e") \
103 _(2, RANGE, "port-range")
107 #define _(v, N, s) NAT_ADDR_AND_PORT_ALLOC_ALG_##N = v,
108 foreach_nat_addr_and_port_alloc_alg
110 } nat_addr_and_port_alloc_alg_t;
113 #define foreach_snat_session_state \
114 _(0, UNKNOWN, "unknown") \
115 _(1, UDP_ACTIVE, "udp-active") \
116 _(2, TCP_SYN_SENT, "tcp-syn-sent") \
117 _(3, TCP_ESTABLISHED, "tcp-established") \
118 _(4, TCP_FIN_WAIT, "tcp-fin-wait") \
119 _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \
120 _(6, TCP_CLOSING, "tcp-closing") \
121 _(7, TCP_LAST_ACK, "tcp-last-ack") \
122 _(8, TCP_CLOSED, "tcp-closed") \
123 _(9, ICMP_ACTIVE, "icmp-active")
127 #define _(v, N, s) SNAT_SESSION_##N = v,
128 foreach_snat_session_state
130 } snat_session_state_t;
132 #define foreach_nat_in2out_ed_error \
133 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
134 _ (OUT_OF_PORTS, "out of ports") \
135 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
136 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
137 _ (NON_SYN, "non-SYN packet try to create session") \
138 _ (TCP_CLOSED, "drops due to TCP in transitory timeout") \
139 _ (TRNSL_FAILED, "couldn't translate packet")
143 #define _(sym,str) NAT_IN2OUT_ED_ERROR_##sym,
144 foreach_nat_in2out_ed_error
146 NAT_IN2OUT_ED_N_ERROR,
147 } nat_in2out_ed_error_t;
149 #define foreach_nat_out2in_ed_error \
150 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
151 _ (OUT_OF_PORTS, "out of ports") \
152 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
153 _ (NO_TRANSLATION, "no translation") \
154 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
155 _ (NON_SYN, "non-SYN packet try to create session") \
156 _ (TCP_CLOSED, "drops due to TCP in transitory timeout") \
157 _ (HASH_ADD_FAILED, "hash table add failed") \
158 _ (TRNSL_FAILED, "couldn't translate packet")
162 #define _(sym,str) NAT_OUT2IN_ED_ERROR_##sym,
163 foreach_nat_out2in_ed_error
165 NAT_OUT2IN_ED_N_ERROR,
166 } nat_out2in_ed_error_t;
169 /* Endpoint dependent TCP session state */
170 #define NAT44_SES_I2O_FIN 1
171 #define NAT44_SES_O2I_FIN 2
172 #define NAT44_SES_I2O_FIN_ACK 4
173 #define NAT44_SES_O2I_FIN_ACK 8
174 #define NAT44_SES_I2O_SYN 16
175 #define NAT44_SES_O2I_SYN 32
176 #define NAT44_SES_RST 64
179 #define SNAT_SESSION_FLAG_STATIC_MAPPING (1 << 0)
180 #define SNAT_SESSION_FLAG_LOAD_BALANCING (1 << 2)
181 #define SNAT_SESSION_FLAG_TWICE_NAT (1 << 3)
182 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT (1 << 4)
183 #define SNAT_SESSION_FLAG_FWD_BYPASS (1 << 5)
184 #define SNAT_SESSION_FLAG_AFFINITY (1 << 6)
185 #define SNAT_SESSION_FLAG_EXACT_ADDRESS (1 << 7)
186 #define SNAT_SESSION_FLAG_HAIRPINNING (1 << 8)
188 /* NAT interface flags */
189 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
190 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
192 /* Static mapping flags */
193 #define NAT_SM_FLAG_SELF_TWICE_NAT (1 << 1)
194 #define NAT_SM_FLAG_TWICE_NAT (1 << 2)
195 #define NAT_SM_FLAG_IDENTITY_NAT (1 << 3)
196 #define NAT_SM_FLAG_ADDR_ONLY (1 << 4)
197 #define NAT_SM_FLAG_EXACT_ADDRESS (1 << 5)
198 #define NAT_SM_FLAG_OUT2IN_ONLY (1 << 6)
199 #define NAT_SM_FLAG_LB (1 << 7)
200 #define NAT_SM_FLAG_SWITCH_ADDRESS (1 << 8)
202 typedef CLIB_PACKED(struct
204 // number of sessions in this vrf
210 // is this vrf expired
212 }) per_vrf_sessions_t;
218 ip4_address_t saddr, daddr;
219 u16 sport; // ICMP id for ICMP case
228 STATIC_ASSERT_SIZEOF (nat_6t_t, 2 * sizeof (u64));
232 #define NAT_FLOW_OP_SADDR_REWRITE (1 << 1)
233 #define NAT_FLOW_OP_SPORT_REWRITE (1 << 2)
234 #define NAT_FLOW_OP_DADDR_REWRITE (1 << 3)
235 #define NAT_FLOW_OP_DPORT_REWRITE (1 << 4)
236 #define NAT_FLOW_OP_ICMP_ID_REWRITE (1 << 5)
237 #define NAT_FLOW_OP_TXFIB_REWRITE (1 << 6)
242 ip4_address_t saddr, daddr;
253 void nat44_ed_forwarding_enable_disable (u8 is_enable);
256 nat_6t_flow_saddr_rewrite_set (nat_6t_flow_t *f, u32 saddr)
258 f->ops |= NAT_FLOW_OP_SADDR_REWRITE;
259 f->rewrite.saddr.as_u32 = saddr;
263 nat_6t_flow_daddr_rewrite_set (nat_6t_flow_t *f, u32 daddr)
265 f->ops |= NAT_FLOW_OP_DADDR_REWRITE;
266 f->rewrite.daddr.as_u32 = daddr;
270 nat_6t_flow_sport_rewrite_set (nat_6t_flow_t *f, u32 sport)
272 f->ops |= NAT_FLOW_OP_SPORT_REWRITE;
273 f->rewrite.sport = sport;
277 nat_6t_flow_dport_rewrite_set (nat_6t_flow_t *f, u32 dport)
279 f->ops |= NAT_FLOW_OP_DPORT_REWRITE;
280 f->rewrite.dport = dport;
284 nat_6t_flow_txfib_rewrite_set (nat_6t_flow_t *f, u32 tx_fib_index)
286 f->ops |= NAT_FLOW_OP_TXFIB_REWRITE;
287 f->rewrite.fib_index = tx_fib_index;
291 nat_6t_flow_icmp_id_rewrite_set (nat_6t_flow_t *f, u16 id)
293 f->ops |= NAT_FLOW_OP_ICMP_ID_REWRITE;
294 f->rewrite.icmp_id = id;
297 typedef CLIB_PACKED(struct
299 /* Outside network tuple */
307 /* Inside network tuple */
323 /* head of LRU list in which this session is tracked */
325 /* index in global LRU list */
329 /* Last heard timer */
332 /* Last HA refresh */
333 f64 ha_last_refreshed;
339 /* External host address and port */
340 ip4_address_t ext_host_addr;
343 /* External host address and port after translation */
344 ip4_address_t ext_host_nat_addr;
345 u16 ext_host_nat_port;
347 /* TCP session state */
351 u64 tcp_closed_timestamp;
353 /* per vrf sessions index */
354 u32 per_vrf_sessions_index;
379 /* backend IP address */
381 /* backend port number */
383 /* probability of the backend to be randomly matched */
386 /* backend FIB table */
389 } nat44_lb_addr_port_t;
393 /* twice-nat disabled */
395 /* twice-nat enabled */
397 /* twice-nat only when src IP equals dst IP after translation */
403 /* no load-balancing */
407 /* load-balancing with affinity */
413 /* preferred pool address */
414 ip4_address_t pool_addr;
415 /* local IP address */
416 ip4_address_t local_addr;
417 /* external IP address */
418 ip4_address_t external_addr;
423 /* local FIB table */
428 /* 0 = disabled, otherwise client IP affinity sticky time in seconds */
430 /* worker threads used by backends/local host */
432 /* opaque string tag */
434 /* backends for load-balancing mode */
435 nat44_lb_addr_port_t *locals;
436 /* affinity per service lis */
437 u32 affinity_per_service_list_head_index;
440 } snat_static_mapping_t;
450 ip4_address_t l_addr;
451 ip4_address_t pool_addr;
464 } snat_static_map_resolve_t;
469 snat_session_t *sessions;
471 /* Pool of doubly-linked list elements */
472 dlist_elt_t *list_pool;
474 /* LRU session list - head is stale, tail is fresh */
475 dlist_elt_t *lru_pool;
476 u32 tcp_trans_lru_head_index;
477 u32 tcp_estab_lru_head_index;
478 u32 udp_lru_head_index;
479 u32 icmp_lru_head_index;
480 u32 unk_proto_lru_head_index;
482 /* NAT thread index */
483 u32 snat_thread_index;
485 /* real thread index */
488 per_vrf_sessions_t *per_vrf_sessions_vec;
490 } snat_main_per_thread_data_t;
494 u32 nat44_ed_get_in2out_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
495 u32 rx_fib_index, u8 is_output);
496 u32 nat44_ed_get_out2in_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
497 u32 rx_fib_index, u8 is_output);
499 /* Return worker thread index for given packet */
500 /* NAT address and port allocation function */
501 typedef int (nat_alloc_out_addr_and_port_function_t) (
502 snat_address_t *addresses, u32 fib_index, u32 thread_index,
503 ip_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread,
504 u32 snat_thread_index);
506 typedef struct snat_main_s
508 /* Thread settings */
510 u32 first_worker_index;
514 /* Per thread data */
515 snat_main_per_thread_data_t *per_thread_data;
517 /* Static mapping pool */
518 snat_static_mapping_t *static_mappings;
520 /* Endpoint independent lookup tables */
521 clib_bihash_8_8_t in2out;
522 clib_bihash_8_8_t out2in;
524 /* Endpoint dependent lookup table */
525 clib_bihash_16_8_t flow_hash;
528 snat_interface_t *interfaces;
529 snat_interface_t *output_feature_interfaces;
530 // broken api backward compatibility
531 snat_interface_t *output_feature_dummy_interfaces;
533 /* Vector of outside addresses */
534 snat_address_t *addresses;
535 /* Vector of twice NAT addresses for external hosts */
536 snat_address_t *twice_nat_addresses;
538 /* sw_if_indices whose intfc addresses should be auto-added */
539 u32 *auto_add_sw_if_indices;
540 u32 *auto_add_sw_if_indices_twice_nat;
542 /* Address and port allocation function */
543 nat_alloc_out_addr_and_port_function_t *alloc_addr_and_port;
544 /* Address and port allocation type */
545 nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg;
546 /* Port set parameters (MAP-E) */
550 /* Port range parameters */
557 /* vector of outside fibs */
558 nat_outside_fib_t *outside_fibs;
560 /* vector of interface address static mappings to resolve. */
561 snat_static_map_resolve_t *to_resolve;
563 /* Randomize port allocation order */
566 /* Worker handoff frame-queue index */
568 u32 fq_in2out_output_index;
571 u32 out2in_node_index;
572 u32 in2out_node_index;
573 u32 in2out_output_node_index;
575 nat44_config_t rconfig;
576 //nat44_config_t cconfig;
578 /* If forwarding is enabled */
579 u8 forwarding_enabled;
581 /* static mapping config */
582 u8 static_mapping_only;
583 u8 static_mapping_connection_tracking;
585 /* Is translation memory size calculated or user defined */
586 u8 translation_memory_size_set;
588 u32 translation_buckets;
589 u32 max_translations_per_thread;
590 u32 *max_translations_per_fib;
593 u32 outside_fib_index;
595 u32 inside_fib_index;
597 nat_timeouts_t timeouts;
599 /* TCP MSS clamping */
603 vlib_simple_counter_main_t total_sessions;
604 u32 max_cfg_sessions_gauge; /* Index of max configured sessions gauge in
607 #define _(x) vlib_simple_counter_main_t x;
636 vlib_simple_counter_main_t hairpinning;
640 /* API message ID base */
644 vlib_log_class_t log_class;
649 api_main_t *api_main;
650 ip4_main_t *ip4_main;
651 ip_lookup_main_t *ip4_lookup_main;
653 fib_source_t fib_src_hi;
654 fib_source_t fib_src_low;
656 /* pat - dynamic mapping enabled or conneciton tracking */
659 /* number of worker handoff frame queue elements */
660 u32 frame_queue_nelts;
662 /* nat44 plugin enabled */
665 vnet_main_t *vnet_main;
673 } nat44_is_idle_session_ctx_t;
677 u32 cached_sw_if_index;
678 uword *cached_presence_by_ip4_address;
681 extern snat_main_t snat_main;
683 // nat pre ed next_node feature classification
684 extern vlib_node_registration_t nat_default_node;
685 extern vlib_node_registration_t nat_pre_in2out_node;
686 extern vlib_node_registration_t nat_pre_out2in_node;
688 extern vlib_node_registration_t snat_in2out_node;
689 extern vlib_node_registration_t snat_in2out_output_node;
690 extern vlib_node_registration_t snat_out2in_node;
691 extern vlib_node_registration_t snat_in2out_worker_handoff_node;
692 extern vlib_node_registration_t snat_in2out_output_worker_handoff_node;
693 extern vlib_node_registration_t snat_out2in_worker_handoff_node;
694 extern vlib_node_registration_t nat44_ed_in2out_node;
695 extern vlib_node_registration_t nat44_ed_in2out_output_node;
696 extern vlib_node_registration_t nat44_ed_out2in_node;
698 extern fib_source_t nat_fib_src_hi;
699 extern fib_source_t nat_fib_src_low;
701 /* format functions */
702 format_function_t format_snat_static_mapping;
703 format_function_t format_snat_static_map_to_resolve;
704 format_function_t format_snat_session;
705 format_function_t format_static_mapping_key;
706 format_function_t format_nat_addr_and_port_alloc_alg;
708 /** \brief Check if SNAT session is created from static mapping.
709 @param s SNAT session
710 @return true if SNAT session is created from static mapping otherwise 0
713 nat44_ed_is_session_static (snat_session_t *s)
715 return s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING;
718 /** \brief Check if NAT session is twice NAT.
720 @return true if NAT session is twice NAT
723 nat44_ed_is_twice_nat_session (snat_session_t *s)
725 return s->flags & SNAT_SESSION_FLAG_TWICE_NAT;
728 /** \brief Check if NAT session is load-balancing.
730 @return true if NAT session is load-balancing
733 nat44_ed_is_lb_session (snat_session_t *s)
735 return s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING;
738 /** \brief Check if NAT session is forwarding bypass.
740 @return true if NAT session is load-balancing
743 na44_ed_is_fwd_bypass_session (snat_session_t *s)
745 return s->flags & SNAT_SESSION_FLAG_FWD_BYPASS;
748 /** \brief Check if NAT session has affinity record.
750 @return true if NAT session has affinity record
753 nat44_ed_is_affinity_session (snat_session_t *s)
755 return s->flags & SNAT_SESSION_FLAG_AFFINITY;
758 /** \brief Check if exact pool address should be used.
759 @param s SNAT session
760 @return true if exact pool address
763 nat44_ed_is_exact_address_session (snat_session_t *s)
765 return s->flags & SNAT_SESSION_FLAG_EXACT_ADDRESS;
768 /** \brief Check if NAT interface is inside.
769 @param i NAT interface
770 @return true if inside interface
773 nat44_ed_is_interface_inside (snat_interface_t *i)
775 return i->flags & NAT_INTERFACE_FLAG_IS_INSIDE;
778 /** \brief Check if NAT interface is outside.
779 @param i NAT interface
780 @return true if outside interface
783 nat44_ed_is_interface_outside (snat_interface_t *i)
785 return i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE;
788 /** \brief Check if NAT44 endpoint-dependent TCP session is closed.
790 @return true if session is closed
793 nat44_is_ses_closed (snat_session_t *s)
795 return s->state == 0xf;
798 /** \brief Check if client initiating TCP connection (received SYN from client)
800 @return true if client initiating TCP connection
803 tcp_flags_is_init (u8 f)
805 return (f & TCP_FLAG_SYN) && !(f & TCP_FLAG_ACK);
809 is_sm_addr_only (u32 f)
811 return (f & NAT_SM_FLAG_ADDR_ONLY);
815 is_sm_out2in_only (u32 f)
817 return (f & NAT_SM_FLAG_OUT2IN_ONLY);
821 is_sm_identity_nat (u32 f)
823 return (f & NAT_SM_FLAG_IDENTITY_NAT);
829 return (f & NAT_SM_FLAG_LB);
833 is_sm_exact_address (u32 f)
835 return (f & NAT_SM_FLAG_EXACT_ADDRESS);
839 is_sm_self_twice_nat (u32 f)
841 return (f & NAT_SM_FLAG_SELF_TWICE_NAT);
845 is_sm_twice_nat (u32 f)
847 return (f & NAT_SM_FLAG_TWICE_NAT);
851 is_sm_switch_address (u32 f)
853 return (f & NAT_SM_FLAG_SWITCH_ADDRESS);
857 #define nat_log_err(...) \
858 vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
859 #define nat_log_warn(...) \
860 vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
861 #define nat_log_notice(...) \
862 vlib_log(VLIB_LOG_LEVEL_NOTICE, snat_main.log_class, __VA_ARGS__)
863 #define nat_log_info(...) \
864 vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
865 #define nat_log_debug(...)\
866 vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
868 clib_error_t *nat44_api_hookup (vlib_main_t *vm);
870 int snat_set_workers (uword *bitmap);
872 int nat44_plugin_enable (nat44_config_t c);
873 int nat44_plugin_disable ();
875 int nat44_ed_add_interface (u32 sw_if_index, u8 is_inside);
876 int nat44_ed_del_interface (u32 sw_if_index, u8 is_inside);
877 int nat44_ed_add_output_interface (u32 sw_if_index);
878 int nat44_ed_del_output_interface (u32 sw_if_index);
880 int nat44_ed_add_address (ip4_address_t *addr, u32 vrf_id, u8 twice_nat);
881 int nat44_ed_del_address (ip4_address_t addr, u8 delete_sm, u8 twice_nat);
882 int nat44_ed_add_interface_address (u32 sw_if_index, u8 twice_nat);
883 int nat44_ed_del_interface_address (u32 sw_if_index, u8 twice_nat);
885 int nat44_ed_add_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
886 u16 l_port, u16 e_port, ip_protocol_t proto,
887 u32 vrf_id, u32 sw_if_index, u32 flags,
888 ip4_address_t pool_addr, u8 *tag);
890 int nat44_ed_del_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
891 u16 l_port, u16 e_port, ip_protocol_t proto,
892 u32 vrf_id, u32 sw_if_index, u32 flags);
894 int nat44_ed_add_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
896 nat44_lb_addr_port_t *locals, u32 flags,
897 u8 *tag, u32 affinity);
899 int nat44_ed_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
900 ip_protocol_t proto, u32 flags);
902 int nat44_ed_add_del_lb_static_mapping_local (ip4_address_t e_addr, u16 e_port,
903 ip4_address_t l_addr, u16 l_port,
904 ip_protocol_t proto, u32 vrf_id,
905 u8 probability, u8 is_add);
908 * @brief Delete NAT44 endpoint-dependent session
910 * @param sm snat global configuration data
911 * @param addr IPv4 address
912 * @param port L4 port number
913 * @param proto L4 protocol
914 * @param vrf_id VRF ID
915 * @param is_in 1 = inside network address and port pair, 0 = outside
917 * @return 0 on success, non-zero value otherwise
919 int nat44_ed_del_session (snat_main_t *sm, ip4_address_t *addr, u16 port,
920 ip4_address_t *eh_addr, u16 eh_port, u8 proto,
921 u32 vrf_id, int is_in);
923 void nat44_ed_free_session_data (snat_main_t *sm, snat_session_t *s,
924 u32 thread_index, u8 is_ha);
927 * @brief Set NAT44 session limit (session limit, vrf id)
929 * @param session_limit Session limit
930 * @param vrf_id VRF id
931 * @return 0 on success, non-zero value otherwise
933 int nat44_set_session_limit (u32 session_limit, u32 vrf_id);
936 * @brief Update NAT44 session limit flushing all data (session limit, vrf id)
938 * @param session_limit Session limit
939 * @param vrf_id VRF id
940 * @return 0 on success, non-zero value otherwise
942 int nat44_update_session_limit (u32 session_limit, u32 vrf_id);
944 void expire_per_vrf_sessions (u32 fib_index);
947 * @brief Match NAT44 static mapping.
949 * @param key address and port to match
950 * @param addr external/local address of the matched mapping
951 * @param port port of the matched mapping
952 * @param fib_index fib index of the matched mapping
953 * @param by_external if 0 match by local address otherwise match by external
955 * @param is_addr_only 1 if matched mapping is address only
956 * @param twice_nat matched mapping is twice NAT type
957 * @param lb 1 if matched mapping is load-balanced
958 * @param ext_host_addr external host address
959 * @param is_identity_nat 1 if indentity mapping
960 * @param out if !=0 set to pointer of the mapping structure
962 * @returns 0 if match found otherwise 1.
964 int snat_static_mapping_match (
965 vlib_main_t *vm, snat_main_t *sm, ip4_address_t match_addr, u16 match_port,
966 u32 match_fib_index, ip_protocol_t match_protocol,
967 ip4_address_t *mapping_addr, u16 *mapping_port, u32 *mapping_fib_index,
968 int by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat,
969 lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat,
970 snat_static_mapping_t **out);
973 * Why is this here? Because we don't need to touch this layer to
974 * simply reply to an icmp. We need to change id to a unique
975 * value to NAT an echo request/reply.
982 } icmp_echo_header_t;
986 u16 src_port, dst_port;
989 u32 get_thread_idx_by_port (u16 e_port);
991 u8 *format_static_mapping_kvp (u8 *s, va_list *args);
993 u8 *format_session_kvp (u8 *s, va_list *args);
995 u32 nat_calc_bihash_buckets (u32 n_elts);
997 void nat44_addresses_free (snat_address_t **addresses);
999 void nat44_ed_sessions_clear ();
1001 int nat44_ed_set_frame_queue_nelts (u32 frame_queue_nelts);
1005 NAT_ED_TRNSL_ERR_SUCCESS = 0,
1006 NAT_ED_TRNSL_ERR_TRANSLATION_FAILED = 1,
1007 NAT_ED_TRNSL_ERR_FLOW_MISMATCH = 2,
1008 NAT_ED_TRNSL_ERR_PACKET_TRUNCATED = 3,
1009 NAT_ED_TRNSL_ERR_INNER_IP_CORRUPT = 4,
1010 NAT_ED_TRNSL_ERR_INVALID_CSUM = 5,
1011 } nat_translation_error_e;
1013 nat_translation_error_e nat_6t_flow_buf_translate_i2o (
1014 vlib_main_t *vm, snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip,
1015 nat_6t_flow_t *f, ip_protocol_t proto, int is_output_feature);
1017 nat_translation_error_e nat_6t_flow_buf_translate_o2i (
1018 vlib_main_t *vm, snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip,
1019 nat_6t_flow_t *f, ip_protocol_t proto, int is_output_feature);
1021 void nat_6t_l3_l4_csum_calc (nat_6t_flow_t *f);
1023 format_function_t format_nat_ed_translation_error;
1024 format_function_t format_nat_6t_flow;
1025 format_function_t format_ed_session_kvp;
1027 snat_static_mapping_t *nat44_ed_sm_i2o_lookup (snat_main_t *sm,
1028 ip4_address_t addr, u16 port,
1029 u32 fib_index, u8 proto);
1031 snat_static_mapping_t *nat44_ed_sm_o2i_lookup (snat_main_t *sm,
1032 ip4_address_t addr, u16 port,
1033 u32 fib_index, u8 proto);
1035 void nat_syslog_nat44_sadd (u32 ssubix, u32 sfibix, ip4_address_t *isaddr,
1036 u16 isport, ip4_address_t *idaddr, u16 idport,
1037 ip4_address_t *xsaddr, u16 xsport,
1038 ip4_address_t *xdaddr, u16 xdport, u8 proto,
1041 void nat_syslog_nat44_sdel (u32 ssubix, u32 sfibix, ip4_address_t *isaddr,
1042 u16 isport, ip4_address_t *idaddr, u16 idport,
1043 ip4_address_t *xsaddr, u16 xsport,
1044 ip4_address_t *xdaddr, u16 xdport, u8 proto,
1047 #endif /* __included_nat44_ed_h__ */
1049 * fd.io coding-style-patch-verification: ON
1052 * eval: (c-set-style "gnu")