|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
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)
250 f->rewrite.saddr.as_u32 = saddr;
257 f->rewrite.daddr.as_u32 = daddr;
278 f->rewrite.fib_index = tx_fib_index;
285 f->rewrite.icmp_id =
id;
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__)
916 u8 * tag,
u8 identity_nat,
938 u8 out2in_only,
u8 * tag,
u32 affinity);
1108 u32 fib_index,
u32 total_pkts,
u64 total_bytes,
1157 int is_output_feature);
snat_static_map_resolve_t * to_resolve
NAT port/address allocation lib.
int snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
Add external address to NAT44 pool.
ip_lookup_main_t * ip4_lookup_main
unformat_function_t unformat_nat_protocol
u32 unk_proto_lru_head_index
static bool tcp_flags_is_init(u8 f)
Check if client initiating TCP connection (received SYN from client)
static void nat_6t_flow_saddr_rewrite_set(nat_6t_flow_t *f, u32 saddr)
vlib_node_registration_t snat_in2out_output_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_output_worker_handoff_node)
enum nat44_config_flags_t_ nat44_config_flags_t
nat44_lb_addr_port_t * locals
u32 in2out_output_node_index
struct snat_main_s::@736 counters
snat_static_mapping_t * static_mappings
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)
snat_address_t * twice_nat_addresses
vl_api_ip_port_and_mask_t dst_port
format_function_t format_nat_protocol
vlib_simple_counter_main_t total_sessions
int nat44_plugin_disable()
Disable NAT44 plugin.
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)
format_function_t format_snat_key
struct snat_main_s::@736::@738 slowpath
u32 nat_calc_bihash_buckets(u32 n_elts)
fib_source_t nat_fib_src_low
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.
u8 translation_memory_size_set
format_function_t format_nat_addr_and_port_alloc_alg
@ NAT_NEXT_IN2OUT_CLASSIFY
clib_error_t * nat44_api_hookup(vlib_main_t *vm)
#define foreach_nat44_config_flag
#define NAT_FLOW_OP_TXFIB_REWRITE
int snat_set_workers(uword *bitmap)
Set NAT plugin workers.
vlib_node_registration_t snat_out2in_node
snat_interface_t * interfaces
vlib_node_registration_t snat_in2out_node
vlib_log_class_t log_class
struct snat_main_s snat_main_t
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
vl_api_dhcp_client_state_t state
@ NAT_NEXT_IN2OUT_ED_SLOW_PATH
static void nat_6t_flow_daddr_rewrite_set(nat_6t_flow_t *f, u32 daddr)
snat_address_t * addresses
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.
typedef CLIB_PACKED(struct { u32 ses_count;u32 rx_fib_index;u32 tx_fib_index;u8 expired;}) per_vrf_sessions_t
clib_bihash_8_8_t static_mapping_by_external
void nat_6t_l3_l4_csum_calc(nat_6t_flow_t *f)
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.
format_function_t format_snat_static_mapping
format_function_t format_static_mapping_key
vlib_node_registration_t nat_pre_in2out_node
(constructor) VLIB_REGISTER_NODE (nat_pre_in2out_node)
u8 * format_session_kvp(u8 *s, va_list *args)
u32 get_thread_idx_by_port(u16 e_port)
u32 nat44_ed_get_out2in_worker_index(vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
vlib_node_registration_t nat44_ed_in2out_output_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_output_node)
nat_addr_and_port_alloc_alg_t addr_and_port_alloc_alg
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
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.
@ NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH
nat_addr_and_port_alloc_alg_t
snat_main_per_thread_data_t * per_thread_data
void nat44_ed_forwarding_enable_disable(u8 is_enable)
clib_bihash_16_8_t flow_hash
@ NAT_NEXT_IN2OUT_ED_FAST_PATH
per_vrf_sessions_t * per_vrf_sessions_vec
#define NAT_FLOW_OP_DADDR_REWRITE
@ NAT_NEXT_OUT2IN_ED_FAST_PATH
nat_outside_fib_t * outside_fibs
void nat44_ed_sessions_clear()
u32 affinity_per_service_list_head_index
int nat44_update_session_limit(u32 session_limit, u32 vrf_id)
Update NAT44 session limit flushing all data (session limit, vrf id)
#define foreach_snat_session_state
vlib_node_registration_t snat_in2out_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node)
void expire_per_vrf_sessions(u32 fib_index)
u8 * format_static_mapping_kvp(u8 *s, va_list *args)
#define NAT_FLOW_OP_ICMP_ID_REWRITE
u32 fq_in2out_output_index
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)
vl_api_ip_port_and_mask_t src_port
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 void nat_6t_flow_icmp_id_rewrite_set(nat_6t_flow_t *f, u16 id)
u32 nat44_ed_get_in2out_worker_index(vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
format_function_t format_snat_static_map_to_resolve
struct snat_main_s::@736::@737 fastpath
twice_nat_type_t twice_nat
snat_session_t * sessions
@ NAT_ED_TRNSL_ERR_FLOW_MISMATCH
struct _vlib_node_registration vlib_node_registration_t
vlib_node_registration_t nat44_ed_out2in_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_out2in_node)
void nat44_add_del_address_dpo(ip4_address_t addr, u8 is_add)
Add/delete external address to FIB DPO (out2in DPO mode)
STATIC_ASSERT_SIZEOF(nat_6t_t, 2 *sizeof(u64))
int nat_set_outside_address_and_port(snat_address_t *addresses, u32 thread_index, ip4_address_t addr, u16 port, nat_protocol_t protocol)
#define foreach_nat_in2out_ed_error
API main structure, used by both vpp and binary API clients.
format_function_t format_nat_ed_translation_error
u32 tcp_trans_lru_head_index
vlib_node_registration_t nat_default_node
(constructor) VLIB_REGISTER_NODE (nat_default_node)
#define NAT_FLOW_OP_DPORT_REWRITE
u32 * max_translations_per_fib
@ NAT_NEXT_IN2OUT_ED_OUTPUT_FAST_PATH
int nat44_set_session_limit(u32 session_limit, u32 vrf_id)
Set NAT44 session limit (session limit, vrf id)
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.
int nat44_ed_set_frame_queue_nelts(u32 frame_queue_nelts)
vl_api_ip_proto_t protocol
u32 max_cfg_sessions_gauge
u32 * auto_add_sw_if_indices
#define NAT_FLOW_OP_SADDR_REWRITE
clib_bihash_8_8_t static_mapping_by_local
format_function_t format_ed_session_kvp
u32 max_translations_per_thread
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm, u8 twice_nat)
Delete external address from NAT44 pool.
@ NAT_NEXT_OUT2IN_ED_SLOW_PATH
format_function_t format_nat_6t_flow
fib_source_t nat_fib_src_hi
@ NAT_NEXT_OUT2IN_CLASSIFY
int nat44_plugin_enable(nat44_config_t c)
Enable NAT44 plugin.
A collection of simple counters.
vlib_node_registration_t nat_pre_out2in_node
(constructor) VLIB_REGISTER_NODE (nat_pre_out2in_node)
vlib_simple_counter_main_t hairpinning
#define foreach_nat_addr_and_port_alloc_alg
ip4_address_t external_addr
#define NAT_FLOW_OP_SPORT_REWRITE
#define foreach_nat_out2in_ed_error
enum fib_source_t_ fib_source_t
The different sources that can create a route.
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
vlib_node_registration_t nat44_ed_in2out_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_in2out_node)
vlib_node_registration_t snat_in2out_output_node
u32 tcp_estab_lru_head_index
vl_api_interface_index_t sw_if_index
void nat44_addresses_free(snat_address_t **addresses)
@ NAT_ED_TRNSL_ERR_SUCCESS
static void nat_6t_flow_dport_rewrite_set(nat_6t_flow_t *f, u32 dport)
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)
@ NAT_ED_TRNSL_ERR_TRANSLATION_FAILED
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)
u8 static_mapping_connection_tracking
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)
u32 * auto_add_sw_if_indices_twice_nat
format_function_t format_snat_session
static void nat_6t_flow_txfib_rewrite_set(nat_6t_flow_t *f, u32 tx_fib_index)
VLIB buffer representation.
snat_interface_t * output_feature_interfaces
vl_api_wireguard_peer_flags_t flags