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;
108 #define foreach_nat_in2out_ed_error \
109 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
110 _ (OUT_OF_PORTS, "out of ports") \
111 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
112 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
113 _ (NON_SYN, "non-SYN packet try to create session") \
114 _ (TRNSL_FAILED, "couldn't translate packet")
118 #define _(sym,str) NAT_IN2OUT_ED_ERROR_##sym,
119 foreach_nat_in2out_ed_error
121 NAT_IN2OUT_ED_N_ERROR,
122 } nat_in2out_ed_error_t;
124 #define foreach_nat_out2in_ed_error \
125 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \
126 _ (OUT_OF_PORTS, "out of ports") \
127 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \
128 _ (NO_TRANSLATION, "no translation") \
129 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \
130 _ (NON_SYN, "non-SYN packet try to create session") \
131 _ (TCP_CLOSED, "drops due to TCP in transitory timeout") \
132 _ (HASH_ADD_FAILED, "hash table add failed") \
133 _ (TRNSL_FAILED, "couldn't translate packet")
137 #define _(sym,str) NAT_OUT2IN_ED_ERROR_##sym,
138 foreach_nat_out2in_ed_error
140 NAT_OUT2IN_ED_N_ERROR,
141 } nat_out2in_ed_error_t;
145 NAT44_ED_TCP_FLAG_NONE = 0,
146 NAT44_ED_TCP_FLAG_FIN,
147 NAT44_ED_TCP_FLAG_SYN,
148 NAT44_ED_TCP_FLAG_SYNFIN,
149 NAT44_ED_TCP_FLAG_RST,
150 NAT44_ED_TCP_FLAG_FINRST,
151 NAT44_ED_TCP_FLAG_SYNRST,
152 NAT44_ED_TCP_FLAG_SYNFINRST,
154 } nat44_ed_tcp_flag_e;
158 NAT44_ED_DIR_I2O = 0,
163 /* Endpoint dependent TCP session state */
166 NAT44_ED_TCP_STATE_CLOSED = 0,
167 NAT44_ED_TCP_STATE_SYN_I2O,
168 NAT44_ED_TCP_STATE_SYN_O2I,
169 NAT44_ED_TCP_STATE_ESTABLISHED,
170 NAT44_ED_TCP_STATE_FIN_I2O,
171 NAT44_ED_TCP_STATE_FIN_O2I,
172 NAT44_ED_TCP_STATE_RST_TRANS,
173 NAT44_ED_TCP_STATE_FIN_TRANS,
174 NAT44_ED_TCP_STATE_FIN_REOPEN_SYN_I2O,
175 NAT44_ED_TCP_STATE_FIN_REOPEN_SYN_O2I,
176 NAT44_ED_TCP_N_STATE,
177 } nat44_ed_tcp_state_e;
179 format_function_t format_nat44_ed_tcp_state;
182 #define SNAT_SESSION_FLAG_STATIC_MAPPING (1 << 0)
183 #define SNAT_SESSION_FLAG_LOAD_BALANCING (1 << 2)
184 #define SNAT_SESSION_FLAG_TWICE_NAT (1 << 3)
185 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT (1 << 4)
186 #define SNAT_SESSION_FLAG_FWD_BYPASS (1 << 5)
187 #define SNAT_SESSION_FLAG_AFFINITY (1 << 6)
188 #define SNAT_SESSION_FLAG_EXACT_ADDRESS (1 << 7)
189 #define SNAT_SESSION_FLAG_HAIRPINNING (1 << 8)
191 /* NAT interface flags */
192 #define NAT_INTERFACE_FLAG_IS_INSIDE 1
193 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2
195 /* Static mapping flags */
196 #define NAT_SM_FLAG_SELF_TWICE_NAT (1 << 1)
197 #define NAT_SM_FLAG_TWICE_NAT (1 << 2)
198 #define NAT_SM_FLAG_IDENTITY_NAT (1 << 3)
199 #define NAT_SM_FLAG_ADDR_ONLY (1 << 4)
200 #define NAT_SM_FLAG_EXACT_ADDRESS (1 << 5)
201 #define NAT_SM_FLAG_OUT2IN_ONLY (1 << 6)
202 #define NAT_SM_FLAG_LB (1 << 7)
203 #define NAT_SM_FLAG_SWITCH_ADDRESS (1 << 8)
205 typedef CLIB_PACKED(struct
207 // number of sessions in this vrf
213 // is this vrf expired
215 }) per_vrf_sessions_t;
221 ip4_address_t saddr, daddr;
222 u16 sport; // ICMP id for ICMP case
231 STATIC_ASSERT_SIZEOF (nat_6t_t, 2 * sizeof (u64));
235 #define NAT_FLOW_OP_SADDR_REWRITE (1 << 1)
236 #define NAT_FLOW_OP_SPORT_REWRITE (1 << 2)
237 #define NAT_FLOW_OP_DADDR_REWRITE (1 << 3)
238 #define NAT_FLOW_OP_DPORT_REWRITE (1 << 4)
239 #define NAT_FLOW_OP_ICMP_ID_REWRITE (1 << 5)
240 #define NAT_FLOW_OP_TXFIB_REWRITE (1 << 6)
245 ip4_address_t saddr, daddr;
256 void nat44_ed_forwarding_enable_disable (u8 is_enable);
259 nat_6t_flow_saddr_rewrite_set (nat_6t_flow_t *f, u32 saddr)
261 f->ops |= NAT_FLOW_OP_SADDR_REWRITE;
262 f->rewrite.saddr.as_u32 = saddr;
266 nat_6t_flow_daddr_rewrite_set (nat_6t_flow_t *f, u32 daddr)
268 f->ops |= NAT_FLOW_OP_DADDR_REWRITE;
269 f->rewrite.daddr.as_u32 = daddr;
273 nat_6t_flow_sport_rewrite_set (nat_6t_flow_t *f, u32 sport)
275 f->ops |= NAT_FLOW_OP_SPORT_REWRITE;
276 f->rewrite.sport = sport;
280 nat_6t_flow_dport_rewrite_set (nat_6t_flow_t *f, u32 dport)
282 f->ops |= NAT_FLOW_OP_DPORT_REWRITE;
283 f->rewrite.dport = dport;
287 nat_6t_flow_txfib_rewrite_set (nat_6t_flow_t *f, u32 tx_fib_index)
289 f->ops |= NAT_FLOW_OP_TXFIB_REWRITE;
290 f->rewrite.fib_index = tx_fib_index;
294 nat_6t_flow_icmp_id_rewrite_set (nat_6t_flow_t *f, u16 id)
296 f->ops |= NAT_FLOW_OP_ICMP_ID_REWRITE;
297 f->rewrite.icmp_id = id;
300 typedef CLIB_PACKED(struct
302 /* Outside network tuple */
310 /* Inside network tuple */
326 /* head of LRU list in which this session is tracked */
328 /* index in global LRU list */
332 /* Last heard timer */
335 /* Last HA refresh */
336 f64 ha_last_refreshed;
342 /* External host address and port */
343 ip4_address_t ext_host_addr;
346 /* External host address and port after translation */
347 ip4_address_t ext_host_nat_addr;
348 u16 ext_host_nat_port;
350 /* TCP session state */
351 nat44_ed_tcp_state_e tcp_state;
353 /* per vrf sessions index */
354 u32 per_vrf_sessions_index;
382 /* backend IP address */
384 /* backend port number */
386 /* probability of the backend to be randomly matched */
389 /* backend FIB table */
392 } nat44_lb_addr_port_t;
396 /* twice-nat disabled */
398 /* twice-nat enabled */
400 /* twice-nat only when src IP equals dst IP after translation */
406 /* no load-balancing */
410 /* load-balancing with affinity */
416 /* preferred pool address */
417 ip4_address_t pool_addr;
418 /* local IP address */
419 ip4_address_t local_addr;
420 /* external IP address */
421 ip4_address_t external_addr;
426 /* local FIB table */
431 /* 0 = disabled, otherwise client IP affinity sticky time in seconds */
433 /* worker threads used by backends/local host */
435 /* opaque string tag */
437 /* backends for load-balancing mode */
438 nat44_lb_addr_port_t *locals;
439 /* affinity per service lis */
440 u32 affinity_per_service_list_head_index;
443 } snat_static_mapping_t;
454 ip4_address_t l_addr;
455 ip4_address_t pool_addr;
463 } snat_static_mapping_resolve_t;
470 } snat_address_resolve_t;
477 } snat_fib_entry_reg_t;
482 snat_session_t *sessions;
484 /* Pool of doubly-linked list elements */
485 dlist_elt_t *list_pool;
487 /* LRU session list - head is stale, tail is fresh */
488 dlist_elt_t *lru_pool;
489 u32 tcp_trans_lru_head_index;
490 u32 tcp_estab_lru_head_index;
491 u32 udp_lru_head_index;
492 u32 icmp_lru_head_index;
493 u32 unk_proto_lru_head_index;
495 /* NAT thread index */
496 u32 snat_thread_index;
498 /* real thread index */
501 per_vrf_sessions_t *per_vrf_sessions_vec;
503 } snat_main_per_thread_data_t;
507 u32 nat44_ed_get_in2out_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
508 u32 rx_fib_index, u8 is_output);
509 u32 nat44_ed_get_out2in_worker_index (vlib_buffer_t *b, ip4_header_t *ip,
510 u32 rx_fib_index, u8 is_output);
512 /* Return worker thread index for given packet */
513 /* NAT address and port allocation function */
514 typedef int (nat_alloc_out_addr_and_port_function_t) (
515 snat_address_t *addresses, u32 fib_index, u32 thread_index,
516 ip_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread,
517 u32 snat_thread_index);
519 typedef struct snat_main_s
521 /* Thread settings */
523 u32 first_worker_index;
527 /* Per thread data */
528 snat_main_per_thread_data_t *per_thread_data;
530 /* Static mapping pool */
531 snat_static_mapping_t *static_mappings;
533 /* Endpoint independent lookup tables */
534 clib_bihash_8_8_t in2out;
535 clib_bihash_8_8_t out2in;
537 /* Endpoint dependent lookup table */
538 clib_bihash_16_8_t flow_hash;
541 snat_interface_t *interfaces;
542 snat_interface_t *output_feature_interfaces;
543 // broken api backward compatibility
544 snat_interface_t *output_feature_dummy_interfaces;
546 /* Vector of outside addresses */
547 snat_address_t *addresses;
548 /* Vector of twice NAT addresses for external hosts */
549 snat_address_t *twice_nat_addresses;
551 /* first interface address should be auto-added */
552 snat_address_resolve_t *addr_to_resolve;
554 /* Address and port allocation function */
555 nat_alloc_out_addr_and_port_function_t *alloc_addr_and_port;
556 /* Address and port allocation type */
557 nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg;
558 /* Port set parameters (MAP-E) */
562 /* Port range parameters */
569 /* vector of outside fibs */
570 nat_outside_fib_t *outside_fibs;
572 /* vector of fib entries */
573 snat_fib_entry_reg_t *fib_entry_reg;
575 /* vector of interface address static mappings to resolve. */
576 snat_static_mapping_resolve_t *sm_to_resolve;
578 /* Randomize port allocation order */
581 /* Worker handoff frame-queue index */
583 u32 fq_in2out_output_index;
586 u32 out2in_node_index;
587 u32 in2out_node_index;
588 u32 in2out_output_node_index;
590 nat44_config_t rconfig;
591 //nat44_config_t cconfig;
593 /* If forwarding is enabled */
594 u8 forwarding_enabled;
596 /* Is translation memory size calculated or user defined */
597 u8 translation_memory_size_set;
599 u32 translation_buckets;
600 u32 max_translations_per_thread;
601 u32 *max_translations_per_fib;
604 u32 outside_fib_index;
606 u32 inside_fib_index;
608 nat_timeouts_t timeouts;
610 /* TCP MSS clamping */
614 vlib_simple_counter_main_t total_sessions;
615 u32 max_cfg_sessions_gauge; /* Index of max configured sessions gauge in
618 #define _(x) vlib_simple_counter_main_t x;
647 vlib_simple_counter_main_t hairpinning;
651 /* API message ID base */
655 vlib_log_class_t log_class;
660 api_main_t *api_main;
661 ip4_main_t *ip4_main;
662 ip_lookup_main_t *ip4_lookup_main;
664 fib_source_t fib_src_hi;
665 fib_source_t fib_src_low;
667 /* number of worker handoff frame queue elements */
668 u32 frame_queue_nelts;
670 /* nat44 plugin enabled */
673 vnet_main_t *vnet_main;
675 /* TCP session state machine table:
676 * first dimension is possible states
677 * second dimension is direction (in2out/out2in)
678 * third dimension is TCP flag (SYN, RST, FIN)
680 * value is next state to change to
682 nat44_ed_tcp_state_e tcp_state_change_table[NAT44_ED_TCP_N_STATE]
684 [NAT44_ED_TCP_N_FLAG];
691 } nat44_is_idle_session_ctx_t;
695 u32 cached_sw_if_index;
696 uword *cached_presence_by_ip4_address;
699 extern snat_main_t snat_main;
701 // nat pre ed next_node feature classification
702 extern vlib_node_registration_t nat_default_node;
703 extern vlib_node_registration_t nat_pre_in2out_node;
704 extern vlib_node_registration_t nat_pre_out2in_node;
706 extern vlib_node_registration_t snat_in2out_node;
707 extern vlib_node_registration_t snat_in2out_output_node;
708 extern vlib_node_registration_t snat_out2in_node;
709 extern vlib_node_registration_t snat_in2out_worker_handoff_node;
710 extern vlib_node_registration_t snat_in2out_output_worker_handoff_node;
711 extern vlib_node_registration_t snat_out2in_worker_handoff_node;
712 extern vlib_node_registration_t nat44_ed_in2out_node;
713 extern vlib_node_registration_t nat44_ed_in2out_output_node;
714 extern vlib_node_registration_t nat44_ed_out2in_node;
716 extern fib_source_t nat_fib_src_hi;
717 extern fib_source_t nat_fib_src_low;
719 /* format functions */
720 format_function_t format_snat_static_mapping;
721 format_function_t format_snat_static_map_to_resolve;
722 format_function_t format_snat_session;
723 format_function_t format_static_mapping_key;
724 format_function_t format_nat_addr_and_port_alloc_alg;
726 /** \brief Check if SNAT session is created from static mapping.
727 @param s SNAT session
728 @return true if SNAT session is created from static mapping otherwise 0
731 nat44_ed_is_session_static (snat_session_t *s)
733 return s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING;
736 /** \brief Check if NAT session is twice NAT.
738 @return true if NAT session is twice NAT
741 nat44_ed_is_twice_nat_session (snat_session_t *s)
743 return s->flags & SNAT_SESSION_FLAG_TWICE_NAT;
746 /** \brief Check if NAT session is load-balancing.
748 @return true if NAT session is load-balancing
751 nat44_ed_is_lb_session (snat_session_t *s)
753 return s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING;
756 /** \brief Check if NAT session is forwarding bypass.
758 @return true if NAT session is load-balancing
761 na44_ed_is_fwd_bypass_session (snat_session_t *s)
763 return s->flags & SNAT_SESSION_FLAG_FWD_BYPASS;
766 /** \brief Check if NAT session has affinity record.
768 @return true if NAT session has affinity record
771 nat44_ed_is_affinity_session (snat_session_t *s)
773 return s->flags & SNAT_SESSION_FLAG_AFFINITY;
776 /** \brief Check if exact pool address should be used.
777 @param s SNAT session
778 @return true if exact pool address
781 nat44_ed_is_exact_address_session (snat_session_t *s)
783 return s->flags & SNAT_SESSION_FLAG_EXACT_ADDRESS;
786 /** \brief Check if NAT interface is inside.
787 @param i NAT interface
788 @return true if inside interface
791 nat44_ed_is_interface_inside (snat_interface_t *i)
793 return i->flags & NAT_INTERFACE_FLAG_IS_INSIDE;
796 /** \brief Check if NAT interface is outside.
797 @param i NAT interface
798 @return true if outside interface
801 nat44_ed_is_interface_outside (snat_interface_t *i)
803 return i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE;
806 /** \brief Check if client initiating TCP connection (received SYN from client)
808 @return true if client initiating TCP connection
811 tcp_flags_is_init (u8 f)
813 return (f & TCP_FLAG_SYN) && !(f & TCP_FLAG_ACK);
817 is_sm_addr_only (u32 f)
819 return (f & NAT_SM_FLAG_ADDR_ONLY);
823 is_sm_out2in_only (u32 f)
825 return (f & NAT_SM_FLAG_OUT2IN_ONLY);
829 is_sm_identity_nat (u32 f)
831 return (f & NAT_SM_FLAG_IDENTITY_NAT);
837 return (f & NAT_SM_FLAG_LB);
841 is_sm_exact_address (u32 f)
843 return (f & NAT_SM_FLAG_EXACT_ADDRESS);
847 is_sm_self_twice_nat (u32 f)
849 return (f & NAT_SM_FLAG_SELF_TWICE_NAT);
853 is_sm_twice_nat (u32 f)
855 return (f & NAT_SM_FLAG_TWICE_NAT);
859 is_sm_switch_address (u32 f)
861 return (f & NAT_SM_FLAG_SWITCH_ADDRESS);
865 #define nat_log_err(...) \
866 vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__)
867 #define nat_log_warn(...) \
868 vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__)
869 #define nat_log_notice(...) \
870 vlib_log(VLIB_LOG_LEVEL_NOTICE, snat_main.log_class, __VA_ARGS__)
871 #define nat_log_info(...) \
872 vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__)
873 #define nat_log_debug(...)\
874 vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__)
876 clib_error_t *nat44_api_hookup (vlib_main_t *vm);
878 int snat_set_workers (uword *bitmap);
880 int nat44_plugin_enable (nat44_config_t c);
881 int nat44_plugin_disable ();
883 int nat44_ed_add_interface (u32 sw_if_index, u8 is_inside);
884 int nat44_ed_del_interface (u32 sw_if_index, u8 is_inside);
885 int nat44_ed_add_output_interface (u32 sw_if_index);
886 int nat44_ed_del_output_interface (u32 sw_if_index);
888 int nat44_ed_add_address (ip4_address_t *addr, u32 vrf_id, u8 twice_nat);
889 int nat44_ed_del_address (ip4_address_t addr, u8 twice_nat);
890 int nat44_ed_add_interface_address (u32 sw_if_index, u8 twice_nat);
891 int nat44_ed_del_interface_address (u32 sw_if_index, u8 twice_nat);
893 int nat44_ed_add_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
894 u16 l_port, u16 e_port, ip_protocol_t proto,
895 u32 vrf_id, u32 sw_if_index, u32 flags,
896 ip4_address_t pool_addr, u8 *tag);
898 int nat44_ed_del_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr,
899 u16 l_port, u16 e_port, ip_protocol_t proto,
900 u32 vrf_id, u32 sw_if_index, u32 flags);
902 int nat44_ed_add_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
904 nat44_lb_addr_port_t *locals, u32 flags,
905 u8 *tag, u32 affinity);
907 int nat44_ed_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port,
908 ip_protocol_t proto, u32 flags);
910 int nat44_ed_add_del_lb_static_mapping_local (ip4_address_t e_addr, u16 e_port,
911 ip4_address_t l_addr, u16 l_port,
912 ip_protocol_t proto, u32 vrf_id,
913 u8 probability, u8 is_add);
916 * @brief Delete NAT44 endpoint-dependent session
918 * @param sm snat global configuration data
919 * @param addr IPv4 address
920 * @param port L4 port number
921 * @param proto L4 protocol
922 * @param vrf_id VRF ID
923 * @param is_in 1 = inside network address and port pair, 0 = outside
925 * @return 0 on success, non-zero value otherwise
927 int nat44_ed_del_session (snat_main_t *sm, ip4_address_t *addr, u16 port,
928 ip4_address_t *eh_addr, u16 eh_port, u8 proto,
929 u32 vrf_id, int is_in);
931 void nat44_ed_free_session_data (snat_main_t *sm, snat_session_t *s,
932 u32 thread_index, u8 is_ha);
935 * @brief Set NAT44 session limit (session limit, vrf id)
937 * @param session_limit Session limit
938 * @param vrf_id VRF id
939 * @return 0 on success, non-zero value otherwise
941 int nat44_set_session_limit (u32 session_limit, u32 vrf_id);
944 * @brief Update NAT44 session limit flushing all data (session limit, vrf id)
946 * @param session_limit Session limit
947 * @param vrf_id VRF id
948 * @return 0 on success, non-zero value otherwise
950 int nat44_update_session_limit (u32 session_limit, u32 vrf_id);
952 void expire_per_vrf_sessions (u32 fib_index);
955 * @brief Match NAT44 static mapping.
957 * @param key address and port to match
958 * @param addr external/local address of the matched mapping
959 * @param port port of the matched mapping
960 * @param fib_index fib index of the matched mapping
961 * @param by_external if 0 match by local address otherwise match by external
963 * @param is_addr_only 1 if matched mapping is address only
964 * @param twice_nat matched mapping is twice NAT type
965 * @param lb 1 if matched mapping is load-balanced
966 * @param ext_host_addr external host address
967 * @param is_identity_nat 1 if indentity mapping
968 * @param out if !=0 set to pointer of the mapping structure
970 * @returns 0 if match found otherwise 1.
972 int snat_static_mapping_match (
973 vlib_main_t *vm, snat_main_t *sm, ip4_address_t match_addr, u16 match_port,
974 u32 match_fib_index, ip_protocol_t match_protocol,
975 ip4_address_t *mapping_addr, u16 *mapping_port, u32 *mapping_fib_index,
976 int by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat,
977 lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat,
978 snat_static_mapping_t **out);
981 * Why is this here? Because we don't need to touch this layer to
982 * simply reply to an icmp. We need to change id to a unique
983 * value to NAT an echo request/reply.
990 } icmp_echo_header_t;
994 u16 src_port, dst_port;
997 u32 get_thread_idx_by_port (u16 e_port);
999 u8 *format_static_mapping_kvp (u8 *s, va_list *args);
1001 u8 *format_session_kvp (u8 *s, va_list *args);
1003 u32 nat_calc_bihash_buckets (u32 n_elts);
1005 void nat44_addresses_free (snat_address_t **addresses);
1007 void nat44_ed_sessions_clear ();
1009 int nat44_ed_set_frame_queue_nelts (u32 frame_queue_nelts);
1013 NAT_ED_TRNSL_ERR_SUCCESS = 0,
1014 NAT_ED_TRNSL_ERR_TRANSLATION_FAILED = 1,
1015 NAT_ED_TRNSL_ERR_FLOW_MISMATCH = 2,
1016 NAT_ED_TRNSL_ERR_PACKET_TRUNCATED = 3,
1017 NAT_ED_TRNSL_ERR_INNER_IP_CORRUPT = 4,
1018 NAT_ED_TRNSL_ERR_INVALID_CSUM = 5,
1019 } nat_translation_error_e;
1021 nat_translation_error_e nat_6t_flow_buf_translate_i2o (
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 nat_translation_error_e nat_6t_flow_buf_translate_o2i (
1026 vlib_main_t *vm, snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip,
1027 nat_6t_flow_t *f, ip_protocol_t proto, int is_output_feature);
1029 void nat_6t_l3_l4_csum_calc (nat_6t_flow_t *f);
1031 format_function_t format_nat_ed_translation_error;
1032 format_function_t format_nat_6t_flow;
1033 format_function_t format_ed_session_kvp;
1035 snat_static_mapping_t *nat44_ed_sm_i2o_lookup (snat_main_t *sm,
1036 ip4_address_t addr, u16 port,
1037 u32 fib_index, u8 proto);
1039 snat_static_mapping_t *nat44_ed_sm_o2i_lookup (snat_main_t *sm,
1040 ip4_address_t addr, u16 port,
1041 u32 fib_index, u8 proto);
1043 void nat_syslog_nat44_sadd (u32 ssubix, u32 sfibix, ip4_address_t *isaddr,
1044 u16 isport, ip4_address_t *idaddr, u16 idport,
1045 ip4_address_t *xsaddr, u16 xsport,
1046 ip4_address_t *xdaddr, u16 xdport, u8 proto,
1049 void nat_syslog_nat44_sdel (u32 ssubix, u32 sfibix, ip4_address_t *isaddr,
1050 u16 isport, ip4_address_t *idaddr, u16 idport,
1051 ip4_address_t *xsaddr, u16 xsport,
1052 ip4_address_t *xdaddr, u16 xdport, u8 proto,
1055 #endif /* __included_nat44_ed_h__ */
1057 * fd.io coding-style-patch-verification: ON
1060 * eval: (c-set-style "gnu")