18 #ifndef __included_snat_h__ 19 #define __included_snat_h__ 32 #define SNAT_UDP_TIMEOUT 300 33 #define SNAT_TCP_TRANSITORY_TIMEOUT 240 34 #define SNAT_TCP_ESTABLISHED_TIMEOUT 7440 90 #define foreach_snat_protocol \ 91 _(UDP, 0, udp, "udp") \ 92 _(TCP, 1, tcp, "tcp") \ 93 _(ICMP, 2, icmp, "icmp") 96 #define _(N, i, n, s) SNAT_PROTOCOL_##N = i, 102 #define foreach_snat_session_state \ 103 _(0, UNKNOWN, "unknown") \ 104 _(1, UDP_ACTIVE, "udp-active") \ 105 _(2, TCP_SYN_SENT, "tcp-syn-sent") \ 106 _(3, TCP_ESTABLISHED, "tcp-established") \ 107 _(4, TCP_FIN_WAIT, "tcp-fin-wait") \ 108 _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \ 109 _(6, TCP_LAST_ACK, "tcp-last-ack") 112 #define _(v, N, s) SNAT_SESSION_##N = v, 118 #define SNAT_SESSION_FLAG_STATIC_MAPPING 1 130 u32 per_user_list_head_index;
140 u32 outside_address_index;
156 #define _(N, i, n, s) \ 157 u32 busy_##n##_ports; \ 158 uword * busy_##n##_port_bitmap; 228 u8 *p_dont_translate,
340 u32 * address_indexp);
364 #define snat_is_session_static(s) s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING 380 snat_protocol_t snat_proto = ~0;
382 snat_proto = (ip_proto == IP_PROTOCOL_UDP) ? SNAT_PROTOCOL_UDP : snat_proto;
383 snat_proto = (ip_proto == IP_PROTOCOL_TCP) ? SNAT_PROTOCOL_TCP : snat_proto;
384 snat_proto = (ip_proto == IP_PROTOCOL_ICMP) ? SNAT_PROTOCOL_ICMP : snat_proto;
394 ip_proto = (snat_proto == SNAT_PROTOCOL_UDP) ? IP_PROTOCOL_UDP : ip_proto;
395 ip_proto = (snat_proto == SNAT_PROTOCOL_TCP) ? IP_PROTOCOL_TCP : ip_proto;
396 ip_proto = (snat_proto == SNAT_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP : ip_proto;
409 u8 *p_dont_translate,
void *d);
414 u8 *p_dont_translate,
void *d);
419 u8 *p_dont_translate,
void *d);
424 u8 *p_dont_translate,
void *d);
431 case ICMP4_destination_unreachable:
432 case ICMP4_time_exceeded:
433 case ICMP4_parameter_problem:
434 case ICMP4_source_quench:
436 case ICMP4_alternate_host_address:
ip4_address_t external_addr
typedef CLIB_PACKED(struct{snat_session_key_t out2in;snat_session_key_t in2out;u32 flags;u32 per_user_index;u32 per_user_list_head_index;f64 last_heard;u64 total_bytes;u32 total_pkts;u32 outside_address_index;}) snat_session_t
u32 sessions_per_user_list_head_index
int snat_alloc_outside_address_and_port(snat_main_t *sm, u32 fib_index, snat_session_key_t *k, u32 *address_indexp)
u32 snat_icmp_match_function_t(struct snat_main_s *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
struct _vlib_node_registration vlib_node_registration_t
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
snat_det_map_t * det_maps
clib_bihash_8_8_t worker_by_out
u32 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
Get address and port values to be used for packet SNAT translation and create session if needed...
u32 max_translations_per_user
#define static_always_inline
ip4_address_t ext_host_addr
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
format_function_t format_snat_user
u32 icmp_match_out2in_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
Get address and port values to be used for packet SNAT translation.
snat_det_session_t * sessions
snat_static_mapping_t * static_mappings
u32 icmp_match_in2out_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
Get address and port values to be used for packet SNAT translation.
clib_bihash_8_8_t user_hash
vlib_node_registration_t snat_in2out_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node)
u32( snat_get_worker_function_t)(ip4_header_t *ip, u32 rx_fib_index)
clib_bihash_8_8_t static_mapping_by_external
u32 icmp_match_in2out_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
Get address and port values to be used for packet SNAT translation and create session if needed...
void snat_free_outside_address_and_port(snat_main_t *sm, snat_session_key_t *k, u32 address_index)
vlib_node_registration_t snat_det_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
struct snat_main_s snat_main_t
u8 static_mapping_connection_tracking
snat_get_worker_function_t * worker_in2out_cb
clib_bihash_8_8_t worker_by_in
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
#define foreach_snat_session_state
int snat_static_mapping_match(snat_main_t *sm, snat_session_key_t match, snat_session_key_t *mapping, u8 by_external, u8 *is_addr_only)
Match SNAT static mapping.
u32 * auto_add_sw_if_indices
snat_get_worker_function_t * worker_out2in_cb
static snat_protocol_t ip_proto_to_snat_proto(u8 ip_proto)
snat_icmp_match_function_t * icmp_match_out2in_cb
vlib_node_registration_t snat_out2in_fast_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_fast_node)
vlib_node_registration_t snat_in2out_fast_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_fast_node)
snat_main_per_thread_data_t * per_thread_data
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.
snat_address_t * addresses
snat_static_map_resolve_t * to_resolve
u32 translation_memory_size
#define foreach_snat_protocol
ip_lookup_main_t * ip4_lookup_main
snat_session_t * sessions
snat_icmp_match_function_t * icmp_match_in2out_cb
clib_bihash_8_8_t static_mapping_by_local
snat_interface_t * interfaces