18 #ifndef __included_snat_h__ 19 #define __included_snat_h__ 32 #define SNAT_UDP_TIMEOUT 300 33 #define SNAT_UDP_TIMEOUT_MIN 120 34 #define SNAT_TCP_TRANSITORY_TIMEOUT 240 35 #define SNAT_TCP_ESTABLISHED_TIMEOUT 7440 36 #define SNAT_TCP_INCOMING_SYN 6 37 #define SNAT_ICMP_TIMEOUT 60 93 #define foreach_snat_protocol \ 94 _(UDP, 0, udp, "udp") \ 95 _(TCP, 1, tcp, "tcp") \ 96 _(ICMP, 2, icmp, "icmp") 99 #define _(N, i, n, s) SNAT_PROTOCOL_##N = i, 105 #define foreach_snat_session_state \ 106 _(0, UNKNOWN, "unknown") \ 107 _(1, UDP_ACTIVE, "udp-active") \ 108 _(2, TCP_SYN_SENT, "tcp-syn-sent") \ 109 _(3, TCP_ESTABLISHED, "tcp-established") \ 110 _(4, TCP_FIN_WAIT, "tcp-fin-wait") \ 111 _(5, TCP_CLOSE_WAIT, "tcp-close-wait") \ 112 _(6, TCP_LAST_ACK, "tcp-last-ack") \ 113 _(7, ICMP_ACTIVE, "icmp-active") 116 #define _(v, N, s) SNAT_SESSION_##N = v, 122 #define SNAT_SESSION_FLAG_STATIC_MAPPING 1 134 u32 per_user_list_head_index;
144 u32 outside_address_index;
160 #define _(N, i, n, s) \ 161 u32 busy_##n##_ports; \ 162 uword * busy_##n##_port_bitmap; 232 u8 *p_dont_translate,
351 u32 * address_indexp);
375 #define snat_is_session_static(s) s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING 393 snat_proto = (ip_proto == IP_PROTOCOL_UDP) ? SNAT_PROTOCOL_UDP : snat_proto;
394 snat_proto = (ip_proto == IP_PROTOCOL_TCP) ? SNAT_PROTOCOL_TCP : snat_proto;
395 snat_proto = (ip_proto == IP_PROTOCOL_ICMP) ? SNAT_PROTOCOL_ICMP : snat_proto;
396 snat_proto = (ip_proto == IP_PROTOCOL_ICMP6) ? SNAT_PROTOCOL_ICMP : snat_proto;
406 ip_proto = (snat_proto == SNAT_PROTOCOL_UDP) ? IP_PROTOCOL_UDP : ip_proto;
407 ip_proto = (snat_proto == SNAT_PROTOCOL_TCP) ? IP_PROTOCOL_TCP : ip_proto;
408 ip_proto = (snat_proto == SNAT_PROTOCOL_ICMP) ? IP_PROTOCOL_ICMP : ip_proto;
420 u8 *p_dont_translate,
void *d,
void *e);
424 u8 *p_dont_translate,
void *d,
void *e);
428 u8 *p_dont_translate,
void *d,
void *e);
432 u8 *p_dont_translate,
void *d,
void *e);
436 u8 *p_dont_translate,
void *d,
void *e);
440 u8 *p_dont_translate,
void *d,
void *e);
445 u16 l_port,
u16 e_port,
u32 vrf_id,
int addr_only,
446 u32 sw_if_index, snat_protocol_t proto,
int is_add);
459 case ICMP4_destination_unreachable:
460 case ICMP4_time_exceeded:
461 case ICMP4_parameter_problem:
462 case ICMP4_source_quench:
464 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 icmp_match_out2in_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for packet SNAT translation and create session if needed...
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)
u8 runtime_data[0]
Function dependent node-runtime data.
u32 snat_icmp_match_function_t(struct snat_main_s *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
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
u32 icmp_match_out2in_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for packet SNAT translation.
clib_bihash_8_8_t worker_by_out
int snat_interface_add_del(u32 sw_if_index, u8 is_inside, int is_del)
u32 max_translations_per_user
#define static_always_inline
u32 icmp_match_in2out_slow(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for packet SNAT translation and create session if needed...
ip4_address_t ext_host_addr
static_always_inline u8 is_interface_addr(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, u32 ip4_addr)
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
void snat_add_address(snat_main_t *sm, ip4_address_t *addr, u32 vrf_id)
format_function_t format_snat_user
uword unformat_snat_protocol(unformat_input_t *input, va_list *args)
snat_det_session_t * sessions
int snat_del_address(snat_main_t *sm, ip4_address_t addr, u8 delete_sm)
snat_static_mapping_t * static_mappings
int snat_set_workers(uword *bitmap)
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
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)
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, snat_protocol_t proto, int is_add)
Add static mapping.
struct snat_main_s snat_main_t
u8 static_mapping_connection_tracking
snat_get_worker_function_t * worker_in2out_cb
void increment_v4_address(ip4_address_t *a)
u32 icmp_match_out2in_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for packet SNAT translation and create session if needed...
clib_bihash_8_8_t worker_by_in
static u8 snat_proto_to_ip_proto(snat_protocol_t snat_proto)
u8 * format_snat_protocol(u8 *s, va_list *args)
#define foreach_snat_session_state
u32 tcp_transitory_timeout
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.
clib_error_t * snat_api_init(vlib_main_t *vm, snat_main_t *sm)
u32 * auto_add_sw_if_indices
snat_get_worker_function_t * worker_out2in_cb
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)
u32 icmp_match_in2out_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for packet SNAT translation.
snat_main_per_thread_data_t * per_thread_data
int snat_add_interface_address(snat_main_t *sm, u32 sw_if_index, int is_del)
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
static u32 ip_proto_to_snat_proto(u8 ip_proto)
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
u32 icmp_match_in2out_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, u8 *p_proto, snat_session_key_t *p_value, u8 *p_dont_translate, void *d, void *e)
Get address and port values to be used for packet SNAT translation and create session if needed...
snat_icmp_match_function_t * icmp_match_in2out_cb
clib_bihash_8_8_t static_mapping_by_local
snat_interface_t * interfaces
u32 tcp_established_timeout