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;
370 /* backend IP address */
372 /* backend port number */
374 /* probability of the backend to be randomly matched */
377 /* backend FIB table */
380 } nat44_lb_addr_port_t;
384 /* twice-nat disabled */
386 /* twice-nat enabled */
388 /* twice-nat only when src IP equals dst IP after translation */
394 /* no load-balancing */
398 /* load-balancing with affinity */
404 /* preferred pool address */
405 ip4_address_t pool_addr;
406 /* local IP address */
407 ip4_address_t local_addr;
408 /* external IP address */
409 ip4_address_t external_addr;
414 /* local FIB table */
419 /* 0 = disabled, otherwise client IP affinity sticky time in seconds */
421 /* worker threads used by backends/local host */
423 /* opaque string tag */
425 /* backends for load-balancing mode */
426 nat44_lb_addr_port_t *locals;
427 /* affinity per service lis */
428 u32 affinity_per_service_list_head_index;
431 } snat_static_mapping_t;
442 ip4_address_t l_addr;
443 ip4_address_t pool_addr;
451 } snat_static_mapping_resolve_t;
458 } snat_address_resolve_t;
465 } snat_fib_entry_reg_t;
470 snat_session_t *sessions;
472 /* Pool of doubly-linked list elements */
473 dlist_elt_t *list_pool;
475 /* LRU session list - head is stale, tail is fresh */
476 dlist_elt_t *lru_pool;
477 u32 tcp_trans_lru_head_index;
478 u32 tcp_estab_lru_head_index;
479 u32 udp_lru_head_index;
480 u32 icmp_lru_head_index;
481 u32 unk_proto_lru_head_index;
483 /* NAT thread index */
484 u32 snat_thread_index;
486 /* real thread index */
489 per_vrf_sessions_t *per_vrf_sessions_vec;
491 } snat_main_per_thread_data_t;
495 u32 nat44_ed_get_in2out_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
496 u32 rx_fib_index, u8 is_output);
497 u32 nat44_ed_get_out2in_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
498 u32 rx_fib_index, u8 is_output);
500 /* Return worker thread index for given packet */
501 /* NAT address and port allocation function */
502 typedef int (nat_alloc_out_addr_and_port_function_t) (
503 snat_address_t *addresses, u32 fib_index, u32 thread_index,
504 ip_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread,
505 u32 snat_thread_index);
507 typedef struct snat_main_s
509 /* Thread settings */
511 u32 first_worker_index;
515 /* Per thread data */
516 snat_main_per_thread_data_t *per_thread_data;
518 /* Static mapping pool */
519 snat_static_mapping_t *static_mappings;
521 /* Endpoint independent lookup tables */
522 clib_bihash_8_8_t in2out;
523 clib_bihash_8_8_t out2in;
525 /* Endpoint dependent lookup table */
526 clib_bihash_16_8_t flow_hash;
529 snat_interface_t *interfaces;
530 snat_interface_t *output_feature_interfaces;
531 // broken api backward compatibility
532 snat_interface_t *output_feature_dummy_interfaces;
534 /* Vector of outside addresses */
535 snat_address_t *addresses;
536 /* Vector of twice NAT addresses for external hosts */
537 snat_address_t *twice_nat_addresses;
539 /* first interface address should be auto-added */
540 snat_address_resolve_t *addr_to_resolve;
545 /* vector of outside fibs */
546 nat_outside_fib_t *outside_fibs;
548 /* vector of fib entries */
549 snat_fib_entry_reg_t *fib_entry_reg;
551 /* vector of interface address static mappings to resolve. */
552 snat_static_mapping_resolve_t *sm_to_resolve;
554 /* Randomize port allocation order */
557 /* Worker handoff frame-queue index */
559 u32 fq_in2out_output_index;
562 nat44_config_t rconfig;
564 /* If forwarding is enabled */
565 u8 forwarding_enabled;
567 /* Is translation memory size calculated or user defined */
568 u8 translation_memory_size_set;
570 u32 translation_buckets;
571 u32 max_translations_per_thread;
572 u32 *max_translations_per_fib;
575 u32 outside_fib_index;
577 u32 inside_fib_index;
579 nat_timeouts_t timeouts;
581 /* TCP MSS clamping */
585 vlib_simple_counter_main_t total_sessions;
586 u32 max_cfg_sessions_gauge; /* Index of max configured sessions gauge in
589 #define _(x) vlib_simple_counter_main_t x;
618 vlib_simple_counter_main_t hairpinning;
622 /* API message ID base */
626 vlib_log_class_t log_class;
631 ip4_main_t *ip4_main;
633 fib_source_t fib_src_hi;
634 fib_source_t fib_src_low;
636 /* number of worker handoff frame queue elements */
637 u32 frame_queue_nelts;
639 /* nat44 plugin enabled */
642 vnet_main_t *vnet_main;
644 /* TCP session state machine table:
645 * first dimension is possible states
646 * second dimension is direction (in2out/out2in)
647 * third dimension is TCP flag (SYN, RST, FIN)
649 * value is next state to change to
651 nat44_ed_tcp_state_e tcp_state_change_table[NAT44_ED_TCP_N_STATE]
653 [NAT44_ED_TCP_N_FLAG];
660 } nat44_is_idle_session_ctx_t;
664 u32 cached_sw_if_index;
665 uword *cached_presence_by_ip4_address;
669 * Why is this here? Because we don't need to touch this layer to
670 * simply reply to an icmp. We need to change id to a unique
671 * value to NAT an echo request/reply.
674 extern snat_main_t snat_main;
676 extern vlib_node_registration_t nat_default_node;
677 extern vlib_node_registration_t nat_pre_in2out_node;
678 extern vlib_node_registration_t nat_pre_out2in_node;
680 extern vlib_node_registration_t nat44_ed_in2out_node;
681 extern vlib_node_registration_t nat44_ed_in2out_output_node;
682 extern vlib_node_registration_t nat44_ed_out2in_node;
684 extern vlib_node_registration_t snat_in2out_worker_handoff_node;
685 extern vlib_node_registration_t snat_in2out_output_worker_handoff_node;
686 extern vlib_node_registration_t snat_out2in_worker_handoff_node;
688 /** \brief Check if SNAT session is created from static mapping.
689 @param s SNAT session
690 @return true if SNAT session is created from static mapping otherwise 0
693 nat44_ed_is_session_static (snat_session_t *s)
695 return s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING;
698 /** \brief Check if NAT session is twice NAT.
700 @return true if NAT session is twice NAT
703 nat44_ed_is_twice_nat_session (snat_session_t *s)
705 return s->flags & SNAT_SESSION_FLAG_TWICE_NAT;
708 /** \brief Check if NAT session is load-balancing.
710 @return true if NAT session is load-balancing
713 nat44_ed_is_lb_session (snat_session_t *s)
715 return s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING;
718 /** \brief Check if NAT session is forwarding bypass.
720 @return true if NAT session is load-balancing
723 na44_ed_is_fwd_bypass_session (snat_session_t *s)
725 return s->flags & SNAT_SESSION_FLAG_FWD_BYPASS;
728 /** \brief Check if NAT session has affinity record.
730 @return true if NAT session has affinity record
733 nat44_ed_is_affinity_session (snat_session_t *s)
735 return s->flags & SNAT_SESSION_FLAG_AFFINITY;
738 /** \brief Check if exact pool address should be used.
739 @param s SNAT session
740 @return true if exact pool address
743 nat44_ed_is_exact_address_session (snat_session_t *s)
745 return s->flags & SNAT_SESSION_FLAG_EXACT_ADDRESS;
748 /** \brief Check if NAT interface is inside.
749 @param i NAT interface
750 @return true if inside interface
753 nat44_ed_is_interface_inside (snat_interface_t *i)
755 return i->flags & NAT_INTERFACE_FLAG_IS_INSIDE;
758 /** \brief Check if NAT interface is outside.
759 @param i NAT interface
760 @return true if outside interface
763 nat44_ed_is_interface_outside (snat_interface_t *i)
765 return i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE;
768 /** \brief Check if client initiating TCP connection (received SYN from client)
770 @return true if client initiating TCP connection
773 tcp_flags_is_init (u8 f)
775 return (f & TCP_FLAG_SYN) && !(f & TCP_FLAG_ACK);
779 is_sm_addr_only (u32 f)
781 return (f & NAT_SM_FLAG_ADDR_ONLY);
785 is_sm_out2in_only (u32 f)
787 return (f & NAT_SM_FLAG_OUT2IN_ONLY);
791 is_sm_identity_nat (u32 f)
793 return (f & NAT_SM_FLAG_IDENTITY_NAT);
799 return (f & NAT_SM_FLAG_LB);
803 is_sm_exact_address (u32 f)
805 return (f & NAT_SM_FLAG_EXACT_ADDRESS);
809 is_sm_self_twice_nat (u32 f)
811 return (f & NAT_SM_FLAG_SELF_TWICE_NAT);
815 is_sm_twice_nat (u32 f)
817 return (f & NAT_SM_FLAG_TWICE_NAT);
821 is_sm_switch_address (u32 f)
823 return (f & NAT_SM_FLAG_SWITCH_ADDRESS);
826 #define nat_log_err(...) \
827 vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
828 #define nat_log_warn(...) \
829 vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
830 #define nat_log_info(...) \
831 vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
832 #define nat_log_debug(...)\
833 vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
835 clib_error_t *nat44_api_hookup (vlib_main_t *vm);
837 int snat_set_workers (uword *bitmap);
839 int nat44_plugin_enable (nat44_config_t c);
840 int nat44_plugin_disable ();
842 int nat44_ed_add_interface (u32 sw_if_index, u8 is_inside);
843 int nat44_ed_del_interface (u32 sw_if_index, u8 is_inside);
844 int nat44_ed_add_output_interface (u32 sw_if_index);
845 int nat44_ed_del_output_interface (u32 sw_if_index);
847 int nat44_ed_add_address (ip4_address_t *addr, u32 vrf_id, u8 twice_nat);
848 int nat44_ed_del_address (ip4_address_t addr, u8 twice_nat);
849 int nat44_ed_add_interface_address (u32 sw_if_index, u8 twice_nat);
850 int nat44_ed_del_interface_address (u32 sw_if_index, u8 twice_nat);
852 int nat44_ed_add_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
853 u16 l_port, u16 e_port, ip_protocol_t proto,
854 u32 vrf_id, u32 sw_if_index, u32 flags,
855 ip4_address_t pool_addr, u8 *tag);
857 int nat44_ed_del_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
858 u16 l_port, u16 e_port, ip_protocol_t proto,
859 u32 vrf_id, u32 sw_if_index, u32 flags);
861 int nat44_ed_add_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
863 nat44_lb_addr_port_t *locals, u32 flags,
864 u8 *tag, u32 affinity);
866 int nat44_ed_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
867 ip_protocol_t proto, u32 flags);
869 int nat44_ed_add_del_lb_static_mapping_local (ip4_address_t e_addr, u16 e_port,
870 ip4_address_t l_addr, u16 l_port,
871 ip_protocol_t proto, u32 vrf_id,
872 u8 probability, u8 is_add);
875 * @brief Delete NAT44 endpoint-dependent session
877 * @param sm snat global configuration data
878 * @param addr IPv4 address
879 * @param port L4 port number
880 * @param proto L4 protocol
881 * @param vrf_id VRF ID
882 * @param is_in 1 = inside network address and port pair, 0 = outside
884 * @return 0 on success, non-zero value otherwise
886 int nat44_ed_del_session (snat_main_t *sm, ip4_address_t *addr, u16 port,
887 ip4_address_t *eh_addr, u16 eh_port, u8 proto,
888 u32 vrf_id, int is_in);
890 void nat44_ed_free_session_data (snat_main_t *sm, snat_session_t *s,
891 u32 thread_index, u8 is_ha);
894 * @brief Set NAT44 session limit (session limit, vrf id)
896 * @param session_limit Session limit
897 * @param vrf_id VRF id
898 * @return 0 on success, non-zero value otherwise
900 int nat44_set_session_limit (u32 session_limit, u32 vrf_id);
903 * @brief Update NAT44 session limit flushing all data (session limit, vrf id)
905 * @param session_limit Session limit
906 * @param vrf_id VRF id
907 * @return 0 on success, non-zero value otherwise
909 int nat44_update_session_limit (u32 session_limit, u32 vrf_id);
911 void expire_per_vrf_sessions (u32 fib_index);
914 * @brief Match NAT44 static mapping.
916 * @param key address and port to match
917 * @param addr external/local address of the matched mapping
918 * @param port port of the matched mapping
919 * @param fib_index fib index of the matched mapping
920 * @param by_external if 0 match by local address otherwise match by external
922 * @param is_addr_only 1 if matched mapping is address only
923 * @param twice_nat matched mapping is twice NAT type
924 * @param lb 1 if matched mapping is load-balanced
925 * @param ext_host_addr external host address
926 * @param is_identity_nat 1 if indentity mapping
927 * @param out if !=0 set to pointer of the mapping structure
929 * @returns 0 if match found otherwise 1.
931 int snat_static_mapping_match (
932 vlib_main_t *vm, snat_main_t *sm, ip4_address_t match_addr, u16 match_port,
933 u32 match_fib_index, ip_protocol_t match_protocol,
934 ip4_address_t *mapping_addr, u16 *mapping_port, u32 *mapping_fib_index,
935 int by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat,
936 lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat,
937 snat_static_mapping_t **out);
939 u32 get_thread_idx_by_port (u16 e_port);
941 u32 nat_calc_bihash_buckets (u32 n_elts);
943 void nat44_addresses_free (snat_address_t **addresses);
945 void nat44_ed_sessions_clear ();
947 int nat44_ed_set_frame_queue_nelts (u32 frame_queue_nelts);
949 void nat_6t_l3_l4_csum_calc (nat_6t_flow_t *f);
951 snat_static_mapping_t *nat44_ed_sm_i2o_lookup (snat_main_t *sm,
952 ip4_address_t addr, u16 port,
953 u32 fib_index, u8 proto);
955 snat_static_mapping_t *nat44_ed_sm_o2i_lookup (snat_main_t *sm,
956 ip4_address_t addr, u16 port,
957 u32 fib_index, u8 proto);
959 void nat_syslog_nat44_sadd (u32 ssubix, u32 sfibix, ip4_address_t *isaddr,
960 u16 isport, ip4_address_t *idaddr, u16 idport,
961 ip4_address_t *xsaddr, u16 xsport,
962 ip4_address_t *xdaddr, u16 xdport, u8 proto,
965 void nat_syslog_nat44_sdel (u32 ssubix, u32 sfibix, ip4_address_t *isaddr,
966 u16 isport, ip4_address_t *idaddr, u16 idport,
967 ip4_address_t *xsaddr, u16 xsport,
968 ip4_address_t *xdaddr, u16 xdport, u8 proto,
973 NAT_ED_TRNSL_ERR_SUCCESS = 0,
974 NAT_ED_TRNSL_ERR_TRANSLATION_FAILED = 1,
975 NAT_ED_TRNSL_ERR_FLOW_MISMATCH = 2,
976 NAT_ED_TRNSL_ERR_PACKET_TRUNCATED = 3,
977 NAT_ED_TRNSL_ERR_INNER_IP_CORRUPT = 4,
978 NAT_ED_TRNSL_ERR_INVALID_CSUM = 5,
979 } nat_translation_error_e;
981 nat_translation_error_e nat_6t_flow_buf_translate_i2o (
982 vlib_main_t *vm, snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip,
983 nat_6t_flow_t *f, ip_protocol_t proto, int is_output_feature);
985 nat_translation_error_e nat_6t_flow_buf_translate_o2i (
986 vlib_main_t *vm, snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip,
987 nat_6t_flow_t *f, ip_protocol_t proto, int is_output_feature);
989 #endif /* __included_nat44_ed_h__ */
991 * fd.io coding-style-patch-verification: ON
994 * eval: (c-set-style "gnu")