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.
16 #ifndef __included_nat44_ed_h__
17 #define __included_nat44_ed_h__
19 #include <vnet/vnet.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vnet/ip/icmp46_packet.h>
23 #include <vnet/api_errno.h>
24 #include <vnet/fib/fib_source.h>
25 #include <vppinfra/elog.h>
26 #include <vppinfra/bihash_8_8.h>
27 #include <vppinfra/bihash_16_8.h>
28 #include <vppinfra/hash.h>
29 #include <vppinfra/dlist.h>
30 #include <vppinfra/error.h>
31 #include <vlibapi/api.h>
33 #include <nat/lib/lib.h>
34 #include <nat/lib/inlines.h>
36 /* default number of worker handoff frame queue elements */
37 #define NAT_FQ_NELTS_DEFAULT 64
39 /* number of attempts to get a port for ED overloading algorithm, if rolling
40 * a dice this many times doesn't produce a free port, it's treated
41 * as if there were no free ports available to conserve resources */
42 #define ED_PORT_ALLOC_ATTEMPTS (10)
44 /* NAT buffer flags */
45 #define SNAT_FLAG_HAIRPINNING (1 << 0)
47 /* NAT44 API Configuration flags */
48 #define foreach_nat44_config_flag \
49 _ (0x00, IS_ENDPOINT_INDEPENDENT) \
50 _ (0x01, IS_ENDPOINT_DEPENDENT) \
51 _ (0x02, IS_STATIC_MAPPING_ONLY) \
52 _ (0x04, IS_CONNECTION_TRACKING)
54 typedef enum nat44_config_flags_t_
56 #define _(n,f) NAT44_API_##f = n,
57 foreach_nat44_config_flag
59 } nat44_config_flags_t;
72 NAT_NEXT_IN2OUT_ED_FAST_PATH,
73 NAT_NEXT_IN2OUT_ED_SLOW_PATH,
74 NAT_NEXT_IN2OUT_ED_OUTPUT_FAST_PATH,
75 NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH,
76 NAT_NEXT_OUT2IN_ED_FAST_PATH,
77 NAT_NEXT_OUT2IN_ED_SLOW_PATH,
78 NAT_NEXT_IN2OUT_CLASSIFY,
79 NAT_NEXT_OUT2IN_CLASSIFY,
89 #define foreach_nat_in2out_ed_error \
90 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
91 _ (OUT_OF_PORTS, "out of ports") \
92 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
93 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
94 _ (NON_SYN, "non-SYN packet try to create session") \
95 _ (TRNSL_FAILED, "couldn't translate packet")
99 #define _(sym,str) NAT_IN2OUT_ED_ERROR_##sym,
100 foreach_nat_in2out_ed_error
102 NAT_IN2OUT_ED_N_ERROR,
103 } nat_in2out_ed_error_t;
105 #define foreach_nat_out2in_ed_error \
106 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
107 _ (OUT_OF_PORTS, "out of ports") \
108 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
109 _ (NO_TRANSLATION, "no translation") \
110 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
111 _ (NON_SYN, "non-SYN packet try to create session") \
112 _ (TCP_CLOSED, "drops due to TCP in transitory timeout") \
113 _ (HASH_ADD_FAILED, "hash table add failed") \
114 _ (TRNSL_FAILED, "couldn't translate packet")
118 #define _(sym,str) NAT_OUT2IN_ED_ERROR_##sym,
119 foreach_nat_out2in_ed_error
121 NAT_OUT2IN_ED_N_ERROR,
122 } nat_out2in_ed_error_t;
126 NAT44_ED_TCP_FLAG_NONE = 0,
127 NAT44_ED_TCP_FLAG_FIN,
128 NAT44_ED_TCP_FLAG_SYN,
129 NAT44_ED_TCP_FLAG_SYNFIN,
130 NAT44_ED_TCP_FLAG_RST,
131 NAT44_ED_TCP_FLAG_FINRST,
132 NAT44_ED_TCP_FLAG_SYNRST,
133 NAT44_ED_TCP_FLAG_SYNFINRST,
135 } nat44_ed_tcp_flag_e;
139 NAT44_ED_DIR_I2O = 0,
144 /* Endpoint dependent TCP session state */
147 NAT44_ED_TCP_STATE_CLOSED = 0,
148 NAT44_ED_TCP_STATE_SYN_I2O,
149 NAT44_ED_TCP_STATE_SYN_O2I,
150 NAT44_ED_TCP_STATE_ESTABLISHED,
151 NAT44_ED_TCP_STATE_FIN_I2O,
152 NAT44_ED_TCP_STATE_FIN_O2I,
153 NAT44_ED_TCP_STATE_RST_TRANS,
154 NAT44_ED_TCP_STATE_FIN_TRANS,
155 NAT44_ED_TCP_STATE_FIN_REOPEN_SYN_I2O,
156 NAT44_ED_TCP_STATE_FIN_REOPEN_SYN_O2I,
157 NAT44_ED_TCP_N_STATE,
158 } nat44_ed_tcp_state_e;
160 format_function_t format_ed_session_kvp;
161 format_function_t format_snat_session;
162 format_function_t format_snat_static_mapping;
163 format_function_t format_snat_static_map_to_resolve;
164 format_function_t format_nat_ed_translation_error;
165 format_function_t format_nat_6t_flow;
166 format_function_t format_nat_6t;
167 format_function_t format_nat44_ed_tcp_state;
170 #define SNAT_SESSION_FLAG_STATIC_MAPPING (1 << 0)
171 #define SNAT_SESSION_FLAG_LOAD_BALANCING (1 << 2)
172 #define SNAT_SESSION_FLAG_TWICE_NAT (1 << 3)
173 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT (1 << 4)
174 #define SNAT_SESSION_FLAG_FWD_BYPASS (1 << 5)
175 #define SNAT_SESSION_FLAG_AFFINITY (1 << 6)
176 #define SNAT_SESSION_FLAG_EXACT_ADDRESS (1 << 7)
177 #define SNAT_SESSION_FLAG_HAIRPINNING (1 << 8)
179 /* NAT interface flags */
180 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
181 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
183 /* Static mapping flags */
184 #define NAT_SM_FLAG_SELF_TWICE_NAT (1 << 1)
185 #define NAT_SM_FLAG_TWICE_NAT (1 << 2)
186 #define NAT_SM_FLAG_IDENTITY_NAT (1 << 3)
187 #define NAT_SM_FLAG_ADDR_ONLY (1 << 4)
188 #define NAT_SM_FLAG_EXACT_ADDRESS (1 << 5)
189 #define NAT_SM_FLAG_OUT2IN_ONLY (1 << 6)
190 #define NAT_SM_FLAG_LB (1 << 7)
191 #define NAT_SM_FLAG_SWITCH_ADDRESS (1 << 8)
193 typedef CLIB_PACKED(struct
195 // number of sessions in this vrf
201 // is this vrf expired
203 }) per_vrf_sessions_t;
209 ip4_address_t saddr, daddr;
210 u16 sport; // ICMP id for ICMP case
219 STATIC_ASSERT_SIZEOF (nat_6t_t, 2 * sizeof (u64));
223 #define NAT_FLOW_OP_SADDR_REWRITE (1 << 1)
224 #define NAT_FLOW_OP_SPORT_REWRITE (1 << 2)
225 #define NAT_FLOW_OP_DADDR_REWRITE (1 << 3)
226 #define NAT_FLOW_OP_DPORT_REWRITE (1 << 4)
227 #define NAT_FLOW_OP_ICMP_ID_REWRITE (1 << 5)
228 #define NAT_FLOW_OP_TXFIB_REWRITE (1 << 6)
233 ip4_address_t saddr, daddr;
244 void nat44_ed_forwarding_enable_disable (u8 is_enable);
247 nat_6t_flow_saddr_rewrite_set (nat_6t_flow_t *f, u32 saddr)
249 f->ops |= NAT_FLOW_OP_SADDR_REWRITE;
250 f->rewrite.saddr.as_u32 = saddr;
254 nat_6t_flow_daddr_rewrite_set (nat_6t_flow_t *f, u32 daddr)
256 f->ops |= NAT_FLOW_OP_DADDR_REWRITE;
257 f->rewrite.daddr.as_u32 = daddr;
261 nat_6t_flow_sport_rewrite_set (nat_6t_flow_t *f, u32 sport)
263 f->ops |= NAT_FLOW_OP_SPORT_REWRITE;
264 f->rewrite.sport = sport;
268 nat_6t_flow_dport_rewrite_set (nat_6t_flow_t *f, u32 dport)
270 f->ops |= NAT_FLOW_OP_DPORT_REWRITE;
271 f->rewrite.dport = dport;
275 nat_6t_flow_txfib_rewrite_set (nat_6t_flow_t *f, u32 tx_fib_index)
277 f->ops |= NAT_FLOW_OP_TXFIB_REWRITE;
278 f->rewrite.fib_index = tx_fib_index;
282 nat_6t_flow_icmp_id_rewrite_set (nat_6t_flow_t *f, u16 id)
284 f->ops |= NAT_FLOW_OP_ICMP_ID_REWRITE;
285 f->rewrite.icmp_id = id;
288 typedef CLIB_PACKED(struct
290 /* Outside network tuple */
298 /* Inside network tuple */
314 /* head of LRU list in which this session is tracked */
316 /* index in global LRU list */
320 /* Last heard timer */
323 /* Last HA refresh */
324 f64 ha_last_refreshed;
330 /* External host address and port */
331 ip4_address_t ext_host_addr;
334 /* External host address and port after translation */
335 ip4_address_t ext_host_nat_addr;
336 u16 ext_host_nat_port;
338 /* TCP session state */
339 nat44_ed_tcp_state_e tcp_state;
341 /* per vrf sessions index */
342 u32 per_vrf_sessions_index;
358 /* backend IP address */
360 /* backend port number */
362 /* probability of the backend to be randomly matched */
365 /* backend FIB table */
368 } nat44_lb_addr_port_t;
372 /* twice-nat disabled */
374 /* twice-nat enabled */
376 /* twice-nat only when src IP equals dst IP after translation */
382 /* no load-balancing */
386 /* load-balancing with affinity */
392 /* preferred pool address */
393 ip4_address_t pool_addr;
394 /* local IP address */
395 ip4_address_t local_addr;
396 /* external IP address */
397 ip4_address_t external_addr;
402 /* local FIB table */
407 /* 0 = disabled, otherwise client IP affinity sticky time in seconds */
409 /* worker threads used by backends/local host */
411 /* opaque string tag */
413 /* backends for load-balancing mode */
414 nat44_lb_addr_port_t *locals;
415 /* affinity per service lis */
416 u32 affinity_per_service_list_head_index;
419 } snat_static_mapping_t;
430 ip4_address_t l_addr;
431 ip4_address_t pool_addr;
439 } snat_static_mapping_resolve_t;
446 } snat_address_resolve_t;
453 } snat_fib_entry_reg_t;
458 snat_session_t *sessions;
460 /* Pool of doubly-linked list elements */
461 dlist_elt_t *list_pool;
463 /* LRU session list - head is stale, tail is fresh */
464 dlist_elt_t *lru_pool;
465 u32 tcp_trans_lru_head_index;
466 u32 tcp_estab_lru_head_index;
467 u32 udp_lru_head_index;
468 u32 icmp_lru_head_index;
469 u32 unk_proto_lru_head_index;
471 /* NAT thread index */
472 u32 snat_thread_index;
474 /* real thread index */
477 per_vrf_sessions_t *per_vrf_sessions_vec;
479 } snat_main_per_thread_data_t;
483 u32 nat44_ed_get_in2out_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
484 u32 rx_fib_index, u8 is_output);
485 u32 nat44_ed_get_out2in_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
486 u32 rx_fib_index, u8 is_output);
488 /* Return worker thread index for given packet */
489 /* NAT address and port allocation function */
490 typedef int (nat_alloc_out_addr_and_port_function_t) (
491 snat_address_t *addresses, u32 fib_index, u32 thread_index,
492 ip_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread,
493 u32 snat_thread_index);
495 typedef struct nat_fib_s
501 typedef struct vrf_route_s
507 typedef struct vrf_table_s
514 typedef struct snat_main_s
516 /* Thread settings */
518 u32 first_worker_index;
522 /* Per thread data */
523 snat_main_per_thread_data_t *per_thread_data;
525 /* Static mapping pool */
526 snat_static_mapping_t *static_mappings;
528 /* Endpoint independent lookup tables */
529 clib_bihash_8_8_t in2out;
530 clib_bihash_8_8_t out2in;
532 /* Endpoint dependent lookup table */
533 clib_bihash_16_8_t flow_hash;
539 u32 inside_fib_index;
542 u32 outside_fib_index;
544 // vector of outside fibs
545 nat_fib_t *outside_fibs;
547 // VRF routing table for dynamic sessions
548 vrf_table_t *vrf_tables;
551 snat_interface_t *interfaces;
552 snat_interface_t *output_feature_interfaces;
553 // broken api backward compatibility
554 snat_interface_t *output_feature_dummy_interfaces;
556 /* Vector of outside addresses */
557 snat_address_t *addresses;
558 /* Vector of twice NAT addresses for external hosts */
559 snat_address_t *twice_nat_addresses;
561 /* first interface address should be auto-added */
562 snat_address_resolve_t *addr_to_resolve;
564 /* vector of fib entries */
565 snat_fib_entry_reg_t *fib_entry_reg;
567 /* vector of interface address static mappings to resolve. */
568 snat_static_mapping_resolve_t *sm_to_resolve;
570 /* Randomize port allocation order */
573 /* Worker handoff frame-queue index */
575 u32 fq_in2out_output_index;
578 nat44_config_t rconfig;
580 /* If forwarding is enabled */
581 u8 forwarding_enabled;
583 /* Is translation memory size calculated or user defined */
584 u8 translation_memory_size_set;
586 u32 translation_buckets;
587 u32 max_translations_per_thread;
588 u32 *max_translations_per_fib;
590 nat_timeouts_t timeouts;
592 /* TCP MSS clamping */
596 vlib_simple_counter_main_t total_sessions;
597 u32 max_cfg_sessions_gauge; /* Index of max configured sessions gauge in
600 #define _(x) vlib_simple_counter_main_t x;
629 vlib_simple_counter_main_t hairpinning;
633 /* API message ID base */
637 vlib_log_class_t log_class;
642 ip4_main_t *ip4_main;
644 fib_source_t fib_src_hi;
645 fib_source_t fib_src_low;
647 /* number of worker handoff frame queue elements */
648 u32 frame_queue_nelts;
650 /* nat44 plugin enabled */
653 vnet_main_t *vnet_main;
655 /* TCP session state machine table:
656 * first dimension is possible states
657 * second dimension is direction (in2out/out2in)
658 * third dimension is TCP flag (SYN, RST, FIN)
660 * value is next state to change to
662 nat44_ed_tcp_state_e tcp_state_change_table[NAT44_ED_TCP_N_STATE]
664 [NAT44_ED_TCP_N_FLAG];
671 } nat44_is_idle_session_ctx_t;
675 u32 cached_sw_if_index;
676 uword *cached_presence_by_ip4_address;
680 * Why is this here? Because we don't need to touch this layer to
681 * simply reply to an icmp. We need to change id to a unique
682 * value to NAT an echo request/reply.
685 extern snat_main_t snat_main;
687 extern vlib_node_registration_t nat_default_node;
688 extern vlib_node_registration_t nat_pre_in2out_node;
689 extern vlib_node_registration_t nat_pre_out2in_node;
691 extern vlib_node_registration_t nat44_ed_in2out_node;
692 extern vlib_node_registration_t nat44_ed_in2out_output_node;
693 extern vlib_node_registration_t nat44_ed_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;
699 /** \brief Check if SNAT session is created from static mapping.
700 @param s SNAT session
701 @return true if SNAT session is created from static mapping otherwise 0
704 nat44_ed_is_session_static (snat_session_t *s)
706 return s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING;
709 /** \brief Check if NAT session is twice NAT.
711 @return true if NAT session is twice NAT
714 nat44_ed_is_twice_nat_session (snat_session_t *s)
716 return s->flags & SNAT_SESSION_FLAG_TWICE_NAT;
719 /** \brief Check if NAT session is load-balancing.
721 @return true if NAT session is load-balancing
724 nat44_ed_is_lb_session (snat_session_t *s)
726 return s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING;
729 /** \brief Check if NAT session is forwarding bypass.
731 @return true if NAT session is load-balancing
734 na44_ed_is_fwd_bypass_session (snat_session_t *s)
736 return s->flags & SNAT_SESSION_FLAG_FWD_BYPASS;
739 /** \brief Check if NAT session has affinity record.
741 @return true if NAT session has affinity record
744 nat44_ed_is_affinity_session (snat_session_t *s)
746 return s->flags & SNAT_SESSION_FLAG_AFFINITY;
749 /** \brief Check if exact pool address should be used.
750 @param s SNAT session
751 @return true if exact pool address
754 nat44_ed_is_exact_address_session (snat_session_t *s)
756 return s->flags & SNAT_SESSION_FLAG_EXACT_ADDRESS;
759 /** \brief Check if NAT interface is inside.
760 @param i NAT interface
761 @return true if inside interface
764 nat44_ed_is_interface_inside (snat_interface_t *i)
766 return i->flags & NAT_INTERFACE_FLAG_IS_INSIDE;
769 /** \brief Check if NAT interface is outside.
770 @param i NAT interface
771 @return true if outside interface
774 nat44_ed_is_interface_outside (snat_interface_t *i)
776 return i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE;
779 /** \brief Check if client initiating TCP connection (received SYN from client)
781 @return true if client initiating TCP connection
784 tcp_flags_is_init (u8 f)
786 return (f & TCP_FLAG_SYN) && !(f & TCP_FLAG_ACK);
790 is_sm_addr_only (u32 f)
792 return (f & NAT_SM_FLAG_ADDR_ONLY);
796 is_sm_out2in_only (u32 f)
798 return (f & NAT_SM_FLAG_OUT2IN_ONLY);
802 is_sm_identity_nat (u32 f)
804 return (f & NAT_SM_FLAG_IDENTITY_NAT);
810 return (f & NAT_SM_FLAG_LB);
814 is_sm_exact_address (u32 f)
816 return (f & NAT_SM_FLAG_EXACT_ADDRESS);
820 is_sm_self_twice_nat (u32 f)
822 return (f & NAT_SM_FLAG_SELF_TWICE_NAT);
826 is_sm_twice_nat (u32 f)
828 return (f & NAT_SM_FLAG_TWICE_NAT);
832 is_sm_switch_address (u32 f)
834 return (f & NAT_SM_FLAG_SWITCH_ADDRESS);
837 #define nat_log_err(...) \
838 vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
839 #define nat_log_warn(...) \
840 vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
841 #define nat_log_info(...) \
842 vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
843 #define nat_log_debug(...)\
844 vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
846 clib_error_t *nat44_api_hookup (vlib_main_t *vm);
848 int snat_set_workers (uword *bitmap);
850 int nat44_plugin_enable (nat44_config_t c);
851 int nat44_plugin_disable ();
853 int nat44_ed_add_interface (u32 sw_if_index, u8 is_inside);
854 int nat44_ed_del_interface (u32 sw_if_index, u8 is_inside);
855 int nat44_ed_add_output_interface (u32 sw_if_index);
856 int nat44_ed_del_output_interface (u32 sw_if_index);
858 int nat44_ed_add_address (ip4_address_t *addr, u32 vrf_id, u8 twice_nat);
859 int nat44_ed_del_address (ip4_address_t addr, u8 twice_nat);
860 int nat44_ed_add_interface_address (u32 sw_if_index, u8 twice_nat);
861 int nat44_ed_del_interface_address (u32 sw_if_index, u8 twice_nat);
863 int nat44_ed_add_del_vrf_table (u32 table_vrf_id, bool is_add);
864 int nat44_ed_add_del_vrf_route (u32 table_vrf_id, u32 vrf_id, bool is_add);
865 void nat44_ed_del_vrf_tables ();
867 int nat44_ed_add_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
868 u16 l_port, u16 e_port, ip_protocol_t proto,
869 u32 vrf_id, u32 sw_if_index, u32 flags,
870 ip4_address_t pool_addr, u8 *tag);
872 int nat44_ed_del_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
873 u16 l_port, u16 e_port, ip_protocol_t proto,
874 u32 vrf_id, u32 sw_if_index, u32 flags);
876 int nat44_ed_add_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
878 nat44_lb_addr_port_t *locals, u32 flags,
879 u8 *tag, u32 affinity);
881 int nat44_ed_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
882 ip_protocol_t proto, u32 flags);
884 int nat44_ed_add_del_lb_static_mapping_local (ip4_address_t e_addr, u16 e_port,
885 ip4_address_t l_addr, u16 l_port,
886 ip_protocol_t proto, u32 vrf_id,
887 u8 probability, u8 is_add);
890 * @brief Delete NAT44 endpoint-dependent session
892 * @param sm snat global configuration data
893 * @param addr IPv4 address
894 * @param port L4 port number
895 * @param proto L4 protocol
896 * @param vrf_id VRF ID
897 * @param is_in 1 = inside network address and port pair, 0 = outside
899 * @return 0 on success, non-zero value otherwise
901 int nat44_ed_del_session (snat_main_t *sm, ip4_address_t *addr, u16 port,
902 ip4_address_t *eh_addr, u16 eh_port, u8 proto,
903 u32 vrf_id, int is_in);
905 void nat44_ed_free_session_data (snat_main_t *sm, snat_session_t *s,
906 u32 thread_index, u8 is_ha);
909 * @brief Set NAT44 session limit (session limit, vrf id)
911 * @param session_limit Session limit
912 * @param vrf_id VRF id
913 * @return 0 on success, non-zero value otherwise
915 int nat44_set_session_limit (u32 session_limit, u32 vrf_id);
918 * @brief Update NAT44 session limit flushing all data (session limit, vrf id)
920 * @param session_limit Session limit
921 * @param vrf_id VRF id
922 * @return 0 on success, non-zero value otherwise
924 int nat44_update_session_limit (u32 session_limit, u32 vrf_id);
926 void expire_per_vrf_sessions (u32 fib_index);
928 int snat_static_mapping_match (vlib_main_t *vm, ip4_address_t match_addr,
929 u16 match_port, u32 match_fib_index,
930 ip_protocol_t match_protocol,
931 ip4_address_t *mapping_addr, u16 *mapping_port,
932 u32 *mapping_fib_index, int by_external,
933 u8 *is_addr_only, twice_nat_type_t *twice_nat,
934 lb_nat_type_t *lb, ip4_address_t *ext_host_addr,
936 snat_static_mapping_t **out);
938 u32 get_thread_idx_by_port (u16 e_port);
940 u32 nat_calc_bihash_buckets (u32 n_elts);
942 void nat44_addresses_free (snat_address_t **addresses);
944 void nat44_ed_sessions_clear ();
946 int nat44_ed_set_frame_queue_nelts (u32 frame_queue_nelts);
948 void nat_6t_l3_l4_csum_calc (nat_6t_flow_t *f);
950 snat_static_mapping_t *nat44_ed_sm_i2o_lookup (snat_main_t *sm,
951 ip4_address_t addr, u16 port,
952 u32 fib_index, u8 proto);
954 snat_static_mapping_t *nat44_ed_sm_o2i_lookup (snat_main_t *sm,
955 ip4_address_t addr, u16 port,
956 u32 fib_index, u8 proto);
958 void nat_syslog_nat44_sadd (u32 ssubix, u32 sfibix, ip4_address_t *isaddr,
959 u16 isport, ip4_address_t *idaddr, u16 idport,
960 ip4_address_t *xsaddr, u16 xsport,
961 ip4_address_t *xdaddr, u16 xdport, u8 proto,
964 void nat_syslog_nat44_sdel (u32 ssubix, u32 sfibix, ip4_address_t *isaddr,
965 u16 isport, ip4_address_t *idaddr, u16 idport,
966 ip4_address_t *xsaddr, u16 xsport,
967 ip4_address_t *xdaddr, u16 xdport, u8 proto,
972 NAT_ED_TRNSL_ERR_SUCCESS = 0,
973 NAT_ED_TRNSL_ERR_TRANSLATION_FAILED = 1,
974 NAT_ED_TRNSL_ERR_FLOW_MISMATCH = 2,
975 NAT_ED_TRNSL_ERR_PACKET_TRUNCATED = 3,
976 NAT_ED_TRNSL_ERR_INNER_IP_CORRUPT = 4,
977 NAT_ED_TRNSL_ERR_INVALID_CSUM = 5,
978 } nat_translation_error_e;
980 nat_translation_error_e nat_6t_flow_buf_translate_i2o (
981 vlib_main_t *vm, snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip,
982 nat_6t_flow_t *f, ip_protocol_t proto, int is_output_feature);
984 nat_translation_error_e nat_6t_flow_buf_translate_o2i (
985 vlib_main_t *vm, snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip,
986 nat_6t_flow_t *f, ip_protocol_t proto, int is_output_feature);
988 #endif /* __included_nat44_ed_h__ */
990 * fd.io coding-style-patch-verification: ON
993 * eval: (c-set-style "gnu")