19 #ifndef __included_nat44_ed_h__ 20 #define __included_nat44_ed_h__ 39 #define NAT_FQ_NELTS_DEFAULT 64 42 #define SNAT_FLAG_HAIRPINNING (1 << 0) 45 #define foreach_nat44_config_flag \ 46 _(0x00, IS_ENDPOINT_INDEPENDENT) \ 47 _(0x01, IS_ENDPOINT_DEPENDENT) \ 48 _(0x02, IS_STATIC_MAPPING_ONLY) \ 49 _(0x04, IS_CONNECTION_TRACKING) \ 50 _(0x08, IS_OUT2IN_DPO) 54 #define _(n,f) NAT44_API_##f = n, 95 #define foreach_nat_addr_and_port_alloc_alg \ 96 _(0, DEFAULT, "default") \ 98 _(2, RANGE, "port-range") 102 #define _(v, N, s) NAT_ADDR_AND_PORT_ALLOC_ALG_##N = v, 108 #define foreach_snat_session_state \ 109 _(0, UNKNOWN, "unknown") \ 110 _(1, UDP_ACTIVE, "udp-active") \ 111 _(2, TCP_SYN_SENT, "tcp-syn-sent") \ 112 _(3, TCP_ESTABLISHED, "tcp-established") \ 113 _(4, TCP_FIN_WAIT, "tcp-fin-wait") \ 114 _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \ 115 _(6, TCP_CLOSING, "tcp-closing") \ 116 _(7, TCP_LAST_ACK, "tcp-last-ack") \ 117 _(8, TCP_CLOSED, "tcp-closed") \ 118 _(9, ICMP_ACTIVE, "icmp-active") 122 #define _(v, N, s) SNAT_SESSION_##N = v, 127 #define foreach_nat_in2out_ed_error \ 128 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \ 129 _(OUT_OF_PORTS, "out of ports") \ 130 _(BAD_ICMP_TYPE, "unsupported ICMP type") \ 131 _(MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \ 132 _(NON_SYN, "non-SYN packet try to create session") \ 133 _(TCP_CLOSED, "drops due to TCP in transitory timeout") 137 #define _(sym,str) NAT_IN2OUT_ED_ERROR_##sym, 143 #define foreach_nat_out2in_ed_error \ 144 _ (UNSUPPORTED_PROTOCOL, "unsupported protocol") \ 145 _ (OUT_OF_PORTS, "out of ports") \ 146 _ (BAD_ICMP_TYPE, "unsupported ICMP type") \ 147 _ (NO_TRANSLATION, "no translation") \ 148 _ (MAX_SESSIONS_EXCEEDED, "maximum sessions exceeded") \ 149 _ (NON_SYN, "non-SYN packet try to create session") \ 150 _ (TCP_CLOSED, "drops due to TCP in transitory timeout") \ 151 _ (HASH_ADD_FAILED, "hash table add failed") 155 #define _(sym,str) NAT_OUT2IN_ED_ERROR_##sym, 163 #define NAT44_SES_I2O_FIN 1 164 #define NAT44_SES_O2I_FIN 2 165 #define NAT44_SES_I2O_FIN_ACK 4 166 #define NAT44_SES_O2I_FIN_ACK 8 167 #define NAT44_SES_I2O_SYN 16 168 #define NAT44_SES_O2I_SYN 32 169 #define NAT44_SES_RST 64 172 #define SNAT_SESSION_FLAG_STATIC_MAPPING (1 << 0) 173 #define SNAT_SESSION_FLAG_UNKNOWN_PROTO (1 << 1) 174 #define SNAT_SESSION_FLAG_LOAD_BALANCING (1 << 2) 175 #define SNAT_SESSION_FLAG_TWICE_NAT (1 << 3) 176 #define SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT (1 << 4) 177 #define SNAT_SESSION_FLAG_FWD_BYPASS (1 << 5) 178 #define SNAT_SESSION_FLAG_AFFINITY (1 << 6) 179 #define SNAT_SESSION_FLAG_EXACT_ADDRESS (1 << 7) 180 #define SNAT_SESSION_FLAG_HAIRPINNING (1 << 8) 183 #define NAT_INTERFACE_FLAG_IS_INSIDE 1 184 #define NAT_INTERFACE_FLAG_IS_OUTSIDE 2 187 #define NAT_STATIC_MAPPING_FLAG_ADDR_ONLY 1 188 #define NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY 2 189 #define NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT 4 190 #define NAT_STATIC_MAPPING_FLAG_LB 8 191 #define NAT_STATIC_MAPPING_FLAG_EXACT_ADDRESS 16 203 }) per_vrf_sessions_t;
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) 324 f64 ha_last_refreshed;
336 u16 ext_host_nat_port;
342 u64 tcp_closed_timestamp;
345 u32 per_vrf_sessions_index;
354 #define _(N, i, n, s) \ 355 u32 busy_##n##_ports; \ 356 u32 * busy_##n##_ports_per_thread; \ 357 u32 busy_##n##_port_refcounts[65535]; 494 u32 rx_fib_index,
u8 is_output);
496 u32 rx_fib_index,
u8 is_output);
508 u32 snat_thread_index);
615 #define _(x) vlib_simple_counter_main_t x; 724 #define snat_is_session_static(s) (s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING) 730 #define snat_is_unk_proto_session(s) (s->flags & SNAT_SESSION_FLAG_UNKNOWN_PROTO) 736 #define is_twice_nat_session(s) (s->flags & SNAT_SESSION_FLAG_TWICE_NAT) 742 #define is_lb_session(s) (s->flags & SNAT_SESSION_FLAG_LOAD_BALANCING) 748 #define is_fwd_bypass_session(s) (s->flags & SNAT_SESSION_FLAG_FWD_BYPASS) 754 #define is_ed_session(s) (s->flags & SNAT_SESSION_FLAG_ENDPOINT_DEPENDENT) 760 #define is_affinity_sessions(s) (s->flags & SNAT_SESSION_FLAG_AFFINITY) 766 #define is_exact_address_session(s) (s->flags & SNAT_SESSION_FLAG_EXACT_ADDRESS) 772 #define nat_interface_is_inside(i) i->flags & NAT_INTERFACE_FLAG_IS_INSIDE 778 #define nat_interface_is_outside(i) i->flags & NAT_INTERFACE_FLAG_IS_OUTSIDE 784 #define nat44_is_ses_closed(s) s->state == 0xf 790 #define is_addr_only_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_ADDR_ONLY) 796 #define is_out2in_only_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_OUT2IN_ONLY) 802 #define is_identity_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_IDENTITY_NAT) 808 #define is_lb_static_mapping(sm) (sm->flags & NAT_STATIC_MAPPING_FLAG_LB) 814 #define is_exact_address(s) (s->flags & NAT_STATIC_MAPPING_FLAG_EXACT_ADDRESS) 827 #define nat_log_err(...) \ 828 vlib_log(VLIB_LOG_LEVEL_ERR, snat_main.log_class, __VA_ARGS__) 829 #define nat_log_warn(...) \ 830 vlib_log(VLIB_LOG_LEVEL_WARNING, snat_main.log_class, __VA_ARGS__) 831 #define nat_log_notice(...) \ 832 vlib_log(VLIB_LOG_LEVEL_NOTICE, snat_main.log_class, __VA_ARGS__) 833 #define nat_log_info(...) \ 834 vlib_log(VLIB_LOG_LEVEL_INFO, snat_main.log_class, __VA_ARGS__) 835 #define nat_log_debug(...)\ 836 vlib_log(VLIB_LOG_LEVEL_DEBUG, snat_main.log_class, __VA_ARGS__) 915 twice_nat_type_t twice_nat,
u8 out2in_only,
916 u8 * tag,
u8 identity_nat,
937 twice_nat_type_t twice_nat,
938 u8 out2in_only,
u8 * tag,
u32 affinity);
1016 u32 thread_index,
u8 is_ha);
1073 u8 by_external,
u8 *is_addr_only, twice_nat_type_t *twice_nat,
1108 u32 fib_index,
u32 total_pkts,
u64 total_bytes,
1157 int is_output_feature);
ip4_address_t external_addr
int nat44_set_session_limit(u32 session_limit, u32 vrf_id)
Set NAT44 session limit (session limit, vrf id)
format_function_t format_snat_static_mapping
nat_outside_fib_t * outside_fibs
enum fib_source_t_ fib_source_t
The different sources that can create a route.
u32 * max_translations_per_fib
u32 max_cfg_sessions_gauge
vl_api_wireguard_peer_flags_t flags
nat_addr_and_port_alloc_alg_t
vlib_node_registration_t nat_pre_out2in_node
(constructor) VLIB_REGISTER_NODE (nat_pre_out2in_node)
format_function_t format_static_mapping_key
u32 fq_in2out_output_index
u8 * format_static_mapping_kvp(u8 *s, va_list *args)
vl_api_ip_port_and_mask_t dst_port
vl_api_ip_proto_t protocol
unformat_function_t unformat_nat_protocol
#define foreach_nat_in2out_ed_error
per_vrf_sessions_t * per_vrf_sessions_vec
void expire_per_vrf_sessions(u32 fib_index)
#define foreach_nat_out2in_ed_error
STATIC_ASSERT_SIZEOF(nat_6t_t, 2 *sizeof(u64))
#define foreach_nat_addr_and_port_alloc_alg
static void nat_6t_flow_saddr_rewrite_set(nat_6t_flow_t *f, u32 saddr)
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
NAT port/address allocation lib.
u32 max_translations_per_thread
vlib_simple_counter_main_t hairpinning
void nat44_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Add/delete external address to FIB DPO (out2in DPO mode)
format_function_t format_snat_static_map_to_resolve
nat44_lb_addr_port_t * locals
static void nat_6t_flow_daddr_rewrite_set(nat_6t_flow_t *f, u32 daddr)
vlib_node_registration_t snat_in2out_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node)
int snat_static_mapping_match(vlib_main_t *vm, snat_main_t *sm, ip4_address_t match_addr, u16 match_port, u32 match_fib_index, nat_protocol_t match_protocol, ip4_address_t *mapping_addr, u16 *mapping_port, u32 *mapping_fib_index, u8 by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat, lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat, snat_static_mapping_t **out)
Match NAT44 static mapping.
enum nat44_config_flags_t_ nat44_config_flags_t
u32 in2out_output_node_index
void nat_6t_l3_l4_csum_calc(nat_6t_flow_t *f)
u8 * format_session_kvp(u8 *s, va_list *args)
u32 nat44_ed_get_out2in_worker_index(vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
int nat44_update_session_limit(u32 session_limit, u32 vrf_id)
Update NAT44 session limit flushing all data (session limit, vrf id)
static void nat_6t_flow_icmp_id_rewrite_set(nat_6t_flow_t *f, u16 id)
A collection of simple counters.
struct snat_main_s::@736::@737 fastpath
format_function_t format_snat_session
vlib_node_registration_t nat44_ed_out2in_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_out2in_node)
twice_nat_type_t twice_nat
vlib_node_registration_t nat_pre_in2out_node
(constructor) VLIB_REGISTER_NODE (nat_pre_in2out_node)
u32 * auto_add_sw_if_indices_twice_nat
vl_api_interface_index_t sw_if_index
nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
typedef CLIB_PACKED(struct { u32 ses_count;u32 rx_fib_index;u32 tx_fib_index;u8 expired;}) per_vrf_sessions_t
#define NAT_FLOW_OP_SPORT_REWRITE
snat_static_mapping_t * static_mappings
format_function_t format_nat_ed_translation_error
format_function_t format_nat_addr_and_port_alloc_alg
format_function_t format_ed_session_kvp
static void nat_6t_flow_sport_rewrite_set(nat_6t_flow_t *f, u32 sport)
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 feature on the interface.
clib_bihash_8_8_t static_mapping_by_external
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
int snat_set_workers(uword *bitmap)
Set NAT plugin workers.
format_function_t format_nat_protocol
u8 translation_memory_size_set
void nat_free_session_data(snat_main_t *sm, snat_session_t *s, u32 thread_index, u8 is_ha)
Free NAT44 session data (lookup keys, external address port)
API main structure, used by both vpp and binary API clients.
snat_interface_t * output_feature_interfaces
vlib_node_registration_t snat_in2out_output_node
clib_error_t * nat44_api_hookup(vlib_main_t *vm)
int nat44_del_ed_session(snat_main_t *sm, ip4_address_t *addr, u16 port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 vrf_id, int is_in)
Delete NAT44 endpoint-dependent session.
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
vl_api_ip_port_and_mask_t src_port
format_function_t format_nat_6t_flow
u8 static_mapping_connection_tracking
#define NAT_FLOW_OP_TXFIB_REWRITE
fib_source_t nat_fib_src_hi
vlib_node_registration_t snat_in2out_output_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_worker_handoff_node)
struct snat_main_s::@736 counters
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm, u8 twice_nat)
Delete external address from NAT44 pool.
static void nat_6t_flow_txfib_rewrite_set(nat_6t_flow_t *f, u32 tx_fib_index)
int nat44_plugin_disable()
Disable NAT44 plugin.
u32 * auto_add_sw_if_indices
#define NAT_FLOW_OP_SADDR_REWRITE
u32 get_thread_idx_by_port(u16 e_port)
nat_translation_error_e nat_6t_flow_buf_translate(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip, nat_6t_flow_t *f, nat_protocol_t proto, int is_output_feature)
fib_source_t nat_fib_src_low
struct snat_main_s::@736::@738 slowpath
#define NAT_FLOW_OP_DADDR_REWRITE
int snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
Add external address to NAT44 pool.
vlib_node_registration_t nat_default_node
(constructor) VLIB_REGISTER_NODE (nat_default_node)
int nat44_ed_set_frame_queue_nelts(u32 frame_queue_nelts)
#define foreach_nat44_config_flag
vlib_log_class_t log_class
vlib_node_registration_t snat_in2out_node
int snat_add_static_mapping(ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, u32 vrf_id, int addr_only, u32 sw_if_index, nat_protocol_t proto, int is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u8 identity_nat, ip4_address_t pool_addr, int exact)
Add/delete NAT44 static mapping.
void nat44_addresses_free(snat_address_t **addresses)
struct nat_6t_flow_t::@735 rewrite
snat_address_t * twice_nat_addresses
vlib_node_registration_t nat44_ed_in2out_output_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_node)
void nat44_ed_forwarding_enable_disable(u8 is_enable)
struct _vlib_node_registration vlib_node_registration_t
int nat44_lb_static_mapping_add_del_local(ip4_address_t e_addr, u16 e_port, ip4_address_t l_addr, u16 l_port, nat_protocol_t proto, u32 vrf_id, u8 probability, u8 is_add)
u32 unk_proto_lru_head_index
int nat_set_outside_address_and_port(snat_address_t *addresses, u32 thread_index, ip4_address_t addr, u16 port, nat_protocol_t protocol)
u32 tcp_trans_lru_head_index
VLIB buffer representation.
u32 tcp_estab_lru_head_index
snat_main_per_thread_data_t * per_thread_data
#define foreach_snat_session_state
format_function_t format_snat_key
#define NAT_FLOW_OP_ICMP_ID_REWRITE
u32 affinity_per_service_list_head_index
snat_address_t * addresses
struct snat_main_s snat_main_t
static void nat_6t_flow_dport_rewrite_set(nat_6t_flow_t *f, u32 dport)
snat_static_map_resolve_t * to_resolve
vl_api_dhcp_client_state_t state
void snat_free_outside_address_and_port(snat_address_t *addresses, u32 thread_index, ip4_address_t *addr, u16 port, nat_protocol_t protocol)
Free outside address and port pair.
clib_bihash_16_8_t flow_hash
u32 nat_calc_bihash_buckets(u32 n_elts)
#define NAT_FLOW_OP_DPORT_REWRITE
vlib_node_registration_t snat_out2in_node
int nat44_add_del_lb_static_mapping(ip4_address_t e_addr, u16 e_port, nat_protocol_t proto, nat44_lb_addr_port_t *locals, u8 is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u32 affinity)
Add/delete static mapping with load-balancing (multiple backends)
vlib_simple_counter_main_t total_sessions
ip_lookup_main_t * ip4_lookup_main
snat_session_t * sessions
int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del, u8 twice_nat)
Add/delete NAT44 pool address from specific interface.
static bool tcp_flags_is_init(u8 f)
Check if client initiating TCP connection (received SYN from client)
u32 nat44_ed_get_in2out_worker_index(vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
void snat_add_del_addr_to_fib(ip4_address_t *addr, u8 p_len, u32 sw_if_index, int is_add)
Add/del NAT address to FIB.
int() nat_alloc_out_addr_and_port_function_t(snat_address_t *addresses, u32 fib_index, u32 thread_index, nat_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread, u32 snat_thread_index)
clib_bihash_8_8_t static_mapping_by_local
void nat44_ed_sessions_clear()
snat_interface_t * interfaces
int snat_interface_add_del_output_feature(u32 sw_if_index, u8 is_inside, int is_del)
Enable/disable NAT44 output feature on the interface (postrouting NAT)
int nat44_plugin_enable(nat44_config_t c)
Enable NAT44 plugin.
vlib_node_registration_t nat44_ed_in2out_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_node)