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;
69 /* maximum number of sessions */
78 NAT_NEXT_IN2OUT_ED_FAST_PATH,
79 NAT_NEXT_IN2OUT_ED_SLOW_PATH,
80 NAT_NEXT_IN2OUT_ED_OUTPUT_FAST_PATH,
81 NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH,
82 NAT_NEXT_OUT2IN_ED_FAST_PATH,
83 NAT_NEXT_OUT2IN_ED_SLOW_PATH,
84 NAT_NEXT_IN2OUT_CLASSIFY,
85 NAT_NEXT_OUT2IN_CLASSIFY,
95 /* External address and port allocation modes */
96 #define foreach_nat_addr_and_port_alloc_alg \
97 _(0, DEFAULT, "default") \
99 _(2, RANGE, "port-range")
103 #define _(v, N, s) NAT_ADDR_AND_PORT_ALLOC_ALG_##N = v,
104 foreach_nat_addr_and_port_alloc_alg
106 } nat_addr_and_port_alloc_alg_t;
109 #define foreach_snat_session_state \
110 _(0, UNKNOWN, "unknown") \
111 _(1, UDP_ACTIVE, "udp-active") \
112 _(2, TCP_SYN_SENT, "tcp-syn-sent") \
113 _(3, TCP_ESTABLISHED, "tcp-established") \
114 _(4, TCP_FIN_WAIT, "tcp-fin-wait") \
115 _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \
116 _(6, TCP_CLOSING, "tcp-closing") \
117 _(7, TCP_LAST_ACK, "tcp-last-ack") \
118 _(8, TCP_CLOSED, "tcp-closed") \
119 _(9, ICMP_ACTIVE, "icmp-active")
123 #define _(v, N, s) SNAT_SESSION_##N = v,
124 foreach_snat_session_state
126 } snat_session_state_t;
128 #define foreach_nat_in2out_ed_error \
129 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
130 _ (OUT_OF_PORTS, "out of ports") \
131 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
132 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
133 _ (NON_SYN, "non-SYN packet try to create session") \
134 _ (TCP_CLOSED, "drops due to TCP in transitory timeout") \
135 _ (TRNSL_FAILED, "couldn't translate packet")
139 #define _(sym,str) NAT_IN2OUT_ED_ERROR_##sym,
140 foreach_nat_in2out_ed_error
142 NAT_IN2OUT_ED_N_ERROR,
143 } nat_in2out_ed_error_t;
145 #define foreach_nat_out2in_ed_error \
146 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
147 _ (OUT_OF_PORTS, "out of ports") \
148 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
149 _ (NO_TRANSLATION, "no translation") \
150 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
151 _ (NON_SYN, "non-SYN packet try to create session") \
152 _ (TCP_CLOSED, "drops due to TCP in transitory timeout") \
153 _ (HASH_ADD_FAILED, "hash table add failed") \
154 _ (TRNSL_FAILED, "couldn't translate packet")
158 #define _(sym,str) NAT_OUT2IN_ED_ERROR_##sym,
159 foreach_nat_out2in_ed_error
161 NAT_OUT2IN_ED_N_ERROR,
162 } nat_out2in_ed_error_t;
165 /* Endpoint dependent TCP session state */
166 #define NAT44_SES_I2O_FIN 1
167 #define NAT44_SES_O2I_FIN 2
168 #define NAT44_SES_I2O_FIN_ACK 4
169 #define NAT44_SES_O2I_FIN_ACK 8
170 #define NAT44_SES_I2O_SYN 16
171 #define NAT44_SES_O2I_SYN 32
172 #define NAT44_SES_RST 64
175 #define SNAT_SESSION_FLAG_STATIC_MAPPING (1 << 0)
176 #define SNAT_SESSION_FLAG_LOAD_BALANCING (1 << 2)
177 #define SNAT_SESSION_FLAG_TWICE_NAT (1 << 3)
178 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT (1 << 4)
179 #define SNAT_SESSION_FLAG_FWD_BYPASS (1 << 5)
180 #define SNAT_SESSION_FLAG_AFFINITY (1 << 6)
181 #define SNAT_SESSION_FLAG_EXACT_ADDRESS (1 << 7)
182 #define SNAT_SESSION_FLAG_HAIRPINNING (1 << 8)
184 /* NAT interface flags */
185 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
186 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
188 /* Static mapping flags */
189 #define NAT_SM_FLAG_SELF_TWICE_NAT (1 << 1)
190 #define NAT_SM_FLAG_TWICE_NAT (1 << 2)
191 #define NAT_SM_FLAG_IDENTITY_NAT (1 << 3)
192 #define NAT_SM_FLAG_ADDR_ONLY (1 << 4)
193 #define NAT_SM_FLAG_EXACT_ADDRESS (1 << 5)
194 #define NAT_SM_FLAG_OUT2IN_ONLY (1 << 6)
195 #define NAT_SM_FLAG_LB (1 << 7)
196 #define NAT_SM_FLAG_SWITCH_ADDRESS (1 << 8)
198 typedef CLIB_PACKED(struct
200 // number of sessions in this vrf
206 // is this vrf expired
208 }) per_vrf_sessions_t;
214 ip4_address_t saddr, daddr;
215 u16 sport; // ICMP id for ICMP case
224 STATIC_ASSERT_SIZEOF (nat_6t_t, 2 * sizeof (u64));
228 #define NAT_FLOW_OP_SADDR_REWRITE (1 << 1)
229 #define NAT_FLOW_OP_SPORT_REWRITE (1 << 2)
230 #define NAT_FLOW_OP_DADDR_REWRITE (1 << 3)
231 #define NAT_FLOW_OP_DPORT_REWRITE (1 << 4)
232 #define NAT_FLOW_OP_ICMP_ID_REWRITE (1 << 5)
233 #define NAT_FLOW_OP_TXFIB_REWRITE (1 << 6)
238 ip4_address_t saddr, daddr;
249 void nat44_ed_forwarding_enable_disable (u8 is_enable);
252 nat_6t_flow_saddr_rewrite_set (nat_6t_flow_t *f, u32 saddr)
254 f->ops |= NAT_FLOW_OP_SADDR_REWRITE;
255 f->rewrite.saddr.as_u32 = saddr;
259 nat_6t_flow_daddr_rewrite_set (nat_6t_flow_t *f, u32 daddr)
261 f->ops |= NAT_FLOW_OP_DADDR_REWRITE;
262 f->rewrite.daddr.as_u32 = daddr;
266 nat_6t_flow_sport_rewrite_set (nat_6t_flow_t *f, u32 sport)
268 f->ops |= NAT_FLOW_OP_SPORT_REWRITE;
269 f->rewrite.sport = sport;
273 nat_6t_flow_dport_rewrite_set (nat_6t_flow_t *f, u32 dport)
275 f->ops |= NAT_FLOW_OP_DPORT_REWRITE;
276 f->rewrite.dport = dport;
280 nat_6t_flow_txfib_rewrite_set (nat_6t_flow_t *f, u32 tx_fib_index)
282 f->ops |= NAT_FLOW_OP_TXFIB_REWRITE;
283 f->rewrite.fib_index = tx_fib_index;
287 nat_6t_flow_icmp_id_rewrite_set (nat_6t_flow_t *f, u16 id)
289 f->ops |= NAT_FLOW_OP_ICMP_ID_REWRITE;
290 f->rewrite.icmp_id = id;
293 typedef CLIB_PACKED(struct
295 /* Outside network tuple */
303 /* Inside network tuple */
319 /* head of LRU list in which this session is tracked */
321 /* index in global LRU list */
325 /* Last heard timer */
328 /* Last HA refresh */
329 f64 ha_last_refreshed;
335 /* External host address and port */
336 ip4_address_t ext_host_addr;
339 /* External host address and port after translation */
340 ip4_address_t ext_host_nat_addr;
341 u16 ext_host_nat_port;
343 /* TCP session state */
347 u64 tcp_closed_timestamp;
349 /* per vrf sessions index */
350 u32 per_vrf_sessions_index;
378 /* backend IP address */
380 /* backend port number */
382 /* probability of the backend to be randomly matched */
385 /* backend FIB table */
388 } nat44_lb_addr_port_t;
392 /* twice-nat disabled */
394 /* twice-nat enabled */
396 /* twice-nat only when src IP equals dst IP after translation */
402 /* no load-balancing */
406 /* load-balancing with affinity */
412 /* preferred pool address */
413 ip4_address_t pool_addr;
414 /* local IP address */
415 ip4_address_t local_addr;
416 /* external IP address */
417 ip4_address_t external_addr;
422 /* local FIB table */
427 /* 0 = disabled, otherwise client IP affinity sticky time in seconds */
429 /* worker threads used by backends/local host */
431 /* opaque string tag */
433 /* backends for load-balancing mode */
434 nat44_lb_addr_port_t *locals;
435 /* affinity per service lis */
436 u32 affinity_per_service_list_head_index;
439 } snat_static_mapping_t;
450 ip4_address_t l_addr;
451 ip4_address_t pool_addr;
459 } snat_static_mapping_resolve_t;
466 } snat_address_resolve_t;
473 } snat_fib_entry_reg_t;
478 snat_session_t *sessions;
480 /* Pool of doubly-linked list elements */
481 dlist_elt_t *list_pool;
483 /* LRU session list - head is stale, tail is fresh */
484 dlist_elt_t *lru_pool;
485 u32 tcp_trans_lru_head_index;
486 u32 tcp_estab_lru_head_index;
487 u32 udp_lru_head_index;
488 u32 icmp_lru_head_index;
489 u32 unk_proto_lru_head_index;
491 /* NAT thread index */
492 u32 snat_thread_index;
494 /* real thread index */
497 per_vrf_sessions_t *per_vrf_sessions_vec;
499 } snat_main_per_thread_data_t;
503 u32 nat44_ed_get_in2out_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
504 u32 rx_fib_index, u8 is_output);
505 u32 nat44_ed_get_out2in_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
506 u32 rx_fib_index, u8 is_output);
508 /* Return worker thread index for given packet */
509 /* NAT address and port allocation function */
510 typedef int (nat_alloc_out_addr_and_port_function_t) (
511 snat_address_t *addresses, u32 fib_index, u32 thread_index,
512 ip_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread,
513 u32 snat_thread_index);
515 typedef struct snat_main_s
517 /* Thread settings */
519 u32 first_worker_index;
523 /* Per thread data */
524 snat_main_per_thread_data_t *per_thread_data;
526 /* Static mapping pool */
527 snat_static_mapping_t *static_mappings;
529 /* Endpoint independent lookup tables */
530 clib_bihash_8_8_t in2out;
531 clib_bihash_8_8_t out2in;
533 /* Endpoint dependent lookup table */
534 clib_bihash_16_8_t flow_hash;
537 snat_interface_t *interfaces;
538 snat_interface_t *output_feature_interfaces;
539 // broken api backward compatibility
540 snat_interface_t *output_feature_dummy_interfaces;
542 /* Vector of outside addresses */
543 snat_address_t *addresses;
544 /* Vector of twice NAT addresses for external hosts */
545 snat_address_t *twice_nat_addresses;
547 /* first interface address should be auto-added */
548 snat_address_resolve_t *addr_to_resolve;
550 /* Address and port allocation function */
551 nat_alloc_out_addr_and_port_function_t *alloc_addr_and_port;
552 /* Address and port allocation type */
553 nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg;
554 /* Port set parameters (MAP-E) */
558 /* Port range parameters */
565 /* vector of outside fibs */
566 nat_outside_fib_t *outside_fibs;
568 /* vector of fib entries */
569 snat_fib_entry_reg_t *fib_entry_reg;
571 /* vector of interface address static mappings to resolve. */
572 snat_static_mapping_resolve_t *sm_to_resolve;
574 /* Randomize port allocation order */
577 /* Worker handoff frame-queue index */
579 u32 fq_in2out_output_index;
582 u32 out2in_node_index;
583 u32 in2out_node_index;
584 u32 in2out_output_node_index;
586 nat44_config_t rconfig;
587 //nat44_config_t cconfig;
589 /* If forwarding is enabled */
590 u8 forwarding_enabled;
592 /* Is translation memory size calculated or user defined */
593 u8 translation_memory_size_set;
595 u32 translation_buckets;
596 u32 max_translations_per_thread;
597 u32 *max_translations_per_fib;
600 u32 outside_fib_index;
602 u32 inside_fib_index;
604 nat_timeouts_t timeouts;
606 /* TCP MSS clamping */
610 vlib_simple_counter_main_t total_sessions;
611 u32 max_cfg_sessions_gauge; /* Index of max configured sessions gauge in
614 #define _(x) vlib_simple_counter_main_t x;
643 vlib_simple_counter_main_t hairpinning;
647 /* API message ID base */
651 vlib_log_class_t log_class;
656 api_main_t *api_main;
657 ip4_main_t *ip4_main;
658 ip_lookup_main_t *ip4_lookup_main;
660 fib_source_t fib_src_hi;
661 fib_source_t fib_src_low;
663 /* number of worker handoff frame queue elements */
664 u32 frame_queue_nelts;
666 /* nat44 plugin enabled */
669 vnet_main_t *vnet_main;
677 } nat44_is_idle_session_ctx_t;
681 u32 cached_sw_if_index;
682 uword *cached_presence_by_ip4_address;
685 extern snat_main_t snat_main;
687 // nat pre ed next_node feature classification
688 extern vlib_node_registration_t nat_default_node;
689 extern vlib_node_registration_t nat_pre_in2out_node;
690 extern vlib_node_registration_t nat_pre_out2in_node;
692 extern vlib_node_registration_t snat_in2out_node;
693 extern vlib_node_registration_t snat_in2out_output_node;
694 extern vlib_node_registration_t snat_out2in_node;
695 extern vlib_node_registration_t snat_in2out_worker_handoff_node;
696 extern vlib_node_registration_t snat_in2out_output_worker_handoff_node;
697 extern vlib_node_registration_t snat_out2in_worker_handoff_node;
698 extern vlib_node_registration_t nat44_ed_in2out_node;
699 extern vlib_node_registration_t nat44_ed_in2out_output_node;
700 extern vlib_node_registration_t nat44_ed_out2in_node;
702 extern fib_source_t nat_fib_src_hi;
703 extern fib_source_t nat_fib_src_low;
705 /* format functions */
706 format_function_t format_snat_static_mapping;
707 format_function_t format_snat_static_map_to_resolve;
708 format_function_t format_snat_session;
709 format_function_t format_static_mapping_key;
710 format_function_t format_nat_addr_and_port_alloc_alg;
712 /** \brief Check if SNAT session is created from static mapping.
713 @param s SNAT session
714 @return true if SNAT session is created from static mapping otherwise 0
717 nat44_ed_is_session_static (snat_session_t *s)
719 return s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING;
722 /** \brief Check if NAT session is twice NAT.
724 @return true if NAT session is twice NAT
727 nat44_ed_is_twice_nat_session (snat_session_t *s)
729 return s->flags & SNAT_SESSION_FLAG_TWICE_NAT;
732 /** \brief Check if NAT session is load-balancing.
734 @return true if NAT session is load-balancing
737 nat44_ed_is_lb_session (snat_session_t *s)
739 return s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING;
742 /** \brief Check if NAT session is forwarding bypass.
744 @return true if NAT session is load-balancing
747 na44_ed_is_fwd_bypass_session (snat_session_t *s)
749 return s->flags & SNAT_SESSION_FLAG_FWD_BYPASS;
752 /** \brief Check if NAT session has affinity record.
754 @return true if NAT session has affinity record
757 nat44_ed_is_affinity_session (snat_session_t *s)
759 return s->flags & SNAT_SESSION_FLAG_AFFINITY;
762 /** \brief Check if exact pool address should be used.
763 @param s SNAT session
764 @return true if exact pool address
767 nat44_ed_is_exact_address_session (snat_session_t *s)
769 return s->flags & SNAT_SESSION_FLAG_EXACT_ADDRESS;
772 /** \brief Check if NAT interface is inside.
773 @param i NAT interface
774 @return true if inside interface
777 nat44_ed_is_interface_inside (snat_interface_t *i)
779 return i->flags & NAT_INTERFACE_FLAG_IS_INSIDE;
782 /** \brief Check if NAT interface is outside.
783 @param i NAT interface
784 @return true if outside interface
787 nat44_ed_is_interface_outside (snat_interface_t *i)
789 return i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE;
792 /** \brief Check if NAT44 endpoint-dependent TCP session is closed.
794 @return true if session is closed
797 nat44_is_ses_closed (snat_session_t *s)
799 return s->state == 0xf;
802 /** \brief Check if client initiating TCP connection (received SYN from client)
804 @return true if client initiating TCP connection
807 tcp_flags_is_init (u8 f)
809 return (f & TCP_FLAG_SYN) && !(f & TCP_FLAG_ACK);
813 is_sm_addr_only (u32 f)
815 return (f & NAT_SM_FLAG_ADDR_ONLY);
819 is_sm_out2in_only (u32 f)
821 return (f & NAT_SM_FLAG_OUT2IN_ONLY);
825 is_sm_identity_nat (u32 f)
827 return (f & NAT_SM_FLAG_IDENTITY_NAT);
833 return (f & NAT_SM_FLAG_LB);
837 is_sm_exact_address (u32 f)
839 return (f & NAT_SM_FLAG_EXACT_ADDRESS);
843 is_sm_self_twice_nat (u32 f)
845 return (f & NAT_SM_FLAG_SELF_TWICE_NAT);
849 is_sm_twice_nat (u32 f)
851 return (f & NAT_SM_FLAG_TWICE_NAT);
855 is_sm_switch_address (u32 f)
857 return (f & NAT_SM_FLAG_SWITCH_ADDRESS);
861 #define nat_log_err(...) \
862 vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
863 #define nat_log_warn(...) \
864 vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
865 #define nat_log_notice(...) \
866 vlib_log(VLIB_LOG_LEVEL_NOTICE, snat_main.log_class, __VA_ARGS__)
867 #define nat_log_info(...) \
868 vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
869 #define nat_log_debug(...)\
870 vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
872 clib_error_t *nat44_api_hookup (vlib_main_t *vm);
874 int snat_set_workers (uword *bitmap);
876 int nat44_plugin_enable (nat44_config_t c);
877 int nat44_plugin_disable ();
879 int nat44_ed_add_interface (u32 sw_if_index, u8 is_inside);
880 int nat44_ed_del_interface (u32 sw_if_index, u8 is_inside);
881 int nat44_ed_add_output_interface (u32 sw_if_index);
882 int nat44_ed_del_output_interface (u32 sw_if_index);
884 int nat44_ed_add_address (ip4_address_t *addr, u32 vrf_id, u8 twice_nat);
885 int nat44_ed_del_address (ip4_address_t addr, u8 twice_nat);
886 int nat44_ed_add_interface_address (u32 sw_if_index, u8 twice_nat);
887 int nat44_ed_del_interface_address (u32 sw_if_index, u8 twice_nat);
889 int nat44_ed_add_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
890 u16 l_port, u16 e_port, ip_protocol_t proto,
891 u32 vrf_id, u32 sw_if_index, u32 flags,
892 ip4_address_t pool_addr, u8 *tag);
894 int nat44_ed_del_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
895 u16 l_port, u16 e_port, ip_protocol_t proto,
896 u32 vrf_id, u32 sw_if_index, u32 flags);
898 int nat44_ed_add_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
900 nat44_lb_addr_port_t *locals, u32 flags,
901 u8 *tag, u32 affinity);
903 int nat44_ed_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
904 ip_protocol_t proto, u32 flags);
906 int nat44_ed_add_del_lb_static_mapping_local (ip4_address_t e_addr, u16 e_port,
907 ip4_address_t l_addr, u16 l_port,
908 ip_protocol_t proto, u32 vrf_id,
909 u8 probability, u8 is_add);
912 * @brief Delete NAT44 endpoint-dependent session
914 * @param sm snat global configuration data
915 * @param addr IPv4 address
916 * @param port L4 port number
917 * @param proto L4 protocol
918 * @param vrf_id VRF ID
919 * @param is_in 1 = inside network address and port pair, 0 = outside
921 * @return 0 on success, non-zero value otherwise
923 int nat44_ed_del_session (snat_main_t *sm, ip4_address_t *addr, u16 port,
924 ip4_address_t *eh_addr, u16 eh_port, u8 proto,
925 u32 vrf_id, int is_in);
927 void nat44_ed_free_session_data (snat_main_t *sm, snat_session_t *s,
928 u32 thread_index, u8 is_ha);
931 * @brief Set NAT44 session limit (session limit, vrf id)
933 * @param session_limit Session limit
934 * @param vrf_id VRF id
935 * @return 0 on success, non-zero value otherwise
937 int nat44_set_session_limit (u32 session_limit, u32 vrf_id);
940 * @brief Update NAT44 session limit flushing all data (session limit, vrf id)
942 * @param session_limit Session limit
943 * @param vrf_id VRF id
944 * @return 0 on success, non-zero value otherwise
946 int nat44_update_session_limit (u32 session_limit, u32 vrf_id);
948 void expire_per_vrf_sessions (u32 fib_index);
951 * @brief Match NAT44 static mapping.
953 * @param key address and port to match
954 * @param addr external/local address of the matched mapping
955 * @param port port of the matched mapping
956 * @param fib_index fib index of the matched mapping
957 * @param by_external if 0 match by local address otherwise match by external
959 * @param is_addr_only 1 if matched mapping is address only
960 * @param twice_nat matched mapping is twice NAT type
961 * @param lb 1 if matched mapping is load-balanced
962 * @param ext_host_addr external host address
963 * @param is_identity_nat 1 if indentity mapping
964 * @param out if !=0 set to pointer of the mapping structure
966 * @returns 0 if match found otherwise 1.
968 int snat_static_mapping_match (
969 vlib_main_t *vm, snat_main_t *sm, ip4_address_t match_addr, u16 match_port,
970 u32 match_fib_index, ip_protocol_t match_protocol,
971 ip4_address_t *mapping_addr, u16 *mapping_port, u32 *mapping_fib_index,
972 int by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat,
973 lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat,
974 snat_static_mapping_t **out);
977 * Why is this here? Because we don't need to touch this layer to
978 * simply reply to an icmp. We need to change id to a unique
979 * value to NAT an echo request/reply.
986 } icmp_echo_header_t;
990 u16 src_port, dst_port;
993 u32 get_thread_idx_by_port (u16 e_port);
995 u8 *format_static_mapping_kvp (u8 *s, va_list *args);
997 u8 *format_session_kvp (u8 *s, va_list *args);
999 u32 nat_calc_bihash_buckets (u32 n_elts);
1001 void nat44_addresses_free (snat_address_t **addresses);
1003 void nat44_ed_sessions_clear ();
1005 int nat44_ed_set_frame_queue_nelts (u32 frame_queue_nelts);
1009 NAT_ED_TRNSL_ERR_SUCCESS = 0,
1010 NAT_ED_TRNSL_ERR_TRANSLATION_FAILED = 1,
1011 NAT_ED_TRNSL_ERR_FLOW_MISMATCH = 2,
1012 NAT_ED_TRNSL_ERR_PACKET_TRUNCATED = 3,
1013 NAT_ED_TRNSL_ERR_INNER_IP_CORRUPT = 4,
1014 NAT_ED_TRNSL_ERR_INVALID_CSUM = 5,
1015 } nat_translation_error_e;
1017 nat_translation_error_e nat_6t_flow_buf_translate_i2o (
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 nat_translation_error_e nat_6t_flow_buf_translate_o2i (
1022 vlib_main_t *vm, snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip,
1023 nat_6t_flow_t *f, ip_protocol_t proto, int is_output_feature);
1025 void nat_6t_l3_l4_csum_calc (nat_6t_flow_t *f);
1027 format_function_t format_nat_ed_translation_error;
1028 format_function_t format_nat_6t_flow;
1029 format_function_t format_ed_session_kvp;
1031 snat_static_mapping_t *nat44_ed_sm_i2o_lookup (snat_main_t *sm,
1032 ip4_address_t addr, u16 port,
1033 u32 fib_index, u8 proto);
1035 snat_static_mapping_t *nat44_ed_sm_o2i_lookup (snat_main_t *sm,
1036 ip4_address_t addr, u16 port,
1037 u32 fib_index, u8 proto);
1039 void nat_syslog_nat44_sadd (u32 ssubix, u32 sfibix, ip4_address_t *isaddr,
1040 u16 isport, ip4_address_t *idaddr, u16 idport,
1041 ip4_address_t *xsaddr, u16 xsport,
1042 ip4_address_t *xdaddr, u16 xdport, u8 proto,
1045 void nat_syslog_nat44_sdel (u32 ssubix, u32 sfibix, ip4_address_t *isaddr,
1046 u16 isport, ip4_address_t *idaddr, u16 idport,
1047 ip4_address_t *xsaddr, u16 xsport,
1048 ip4_address_t *xdaddr, u16 xdport, u8 proto,
1051 #endif /* __included_nat44_ed_h__ */
1053 * fd.io coding-style-patch-verification: ON
1056 * eval: (c-set-style "gnu")