45 #define foreach_nat_det_out2in_error \ 46 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 47 _(NO_TRANSLATION, "No translation") \ 48 _(BAD_ICMP_TYPE, "unsupported ICMP type") \ 49 _(OUT2IN_PACKETS, "Good out2in packets processed") 53 #define _(sym,str) NAT_DET_OUT2IN_ERROR_##sym, 60 #define _(sym,string) string, 74 "NAT_DET_OUT2IN: sw_if_index %d, next index %d, session index %d",
79 #ifndef CLIB_MARCH_VARIANT 99 u8 * p_dont_translate,
void *d,
void *e)
101 icmp46_header_t *icmp0;
105 u8 dont_translate = 0;
110 icmp46_header_t *inner_icmp0;
123 protocol = SNAT_PROTOCOL_ICMP;
139 case SNAT_PROTOCOL_ICMP:
140 inner_icmp0 = (icmp46_header_t *) l4_header;
145 case SNAT_PROTOCOL_UDP:
146 case SNAT_PROTOCOL_TCP:
151 b0->
error = node->
errors[NAT_DET_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
173 clib_net_to_host_u16 (key0.
out_port), &new_addr0);
185 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
189 clib_net_to_host_u16 (key0.
out_port),
191 b0->
error = node->
errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
197 (
vnet_buffer (b0)->
ip.reass.icmp_type_or_tcp_flags != ICMP4_echo_reply
199 reass.icmp_type_or_tcp_flags)))
201 b0->
error = node->
errors[NAT_DET_OUT2IN_ERROR_BAD_ICMP_TYPE];
212 p_value->
addr = new_addr0;
216 *p_dont_translate = dont_translate;
229 u32 n_left_from, *from, *to_next;
231 u32 pkts_processed = 0;
236 n_left_from =
frame->n_vectors;
237 next_index =
node->cached_next_index;
239 while (n_left_from > 0)
245 while (n_left_from >= 4 && n_left_to_next >= 2)
251 u32 sw_if_index0, sw_if_index1;
255 u16 new_port0, old_port0, old_port1, new_port1;
262 u32 rx_fib_index0, rx_fib_index1;
263 icmp46_header_t *icmp0, *icmp1;
280 to_next[0] = bi0 = from[0];
281 to_next[1] = bi1 = from[1];
300 ICMP4_time_exceeded_ttl_exceeded_in_transit,
312 icmp0 = (icmp46_header_t *) udp0;
314 next0 =
icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0,
315 rx_fib_index0,
node, next0, thread_index,
330 b0->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
335 clib_net_to_host_u16 (tcp0->dst), &new_addr0);
340 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
342 clib_net_to_host_u16 (tcp0->src),
344 clib_net_to_host_u16 (tcp0->dst),
347 b0->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
366 && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
367 ses0->
state = SNAT_SESSION_TCP_CLOSE_WAIT;
369 && ses0->
state == SNAT_SESSION_TCP_LAST_ACK)
372 sum0 = tcp0->checksum;
396 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
421 ICMP4_time_exceeded_ttl_exceeded_in_transit,
433 icmp1 = (icmp46_header_t *) udp1;
435 next1 =
icmp_out2in (sm, b1, ip1, icmp1, sw_if_index1,
436 rx_fib_index1,
node, next1, thread_index,
451 b1->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
456 clib_net_to_host_u16 (tcp1->dst), &new_addr1);
461 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
463 clib_net_to_host_u16 (tcp1->src),
465 clib_net_to_host_u16 (tcp1->dst),
468 b1->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
472 udp1->
dst_port = new_port1 = ses1->in_port;
487 && ses1->state == SNAT_SESSION_TCP_ESTABLISHED)
488 ses1->state = SNAT_SESSION_TCP_CLOSE_WAIT;
490 && ses1->state == SNAT_SESSION_TCP_LAST_ACK)
493 sum1 = tcp1->checksum;
517 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
532 to_next, n_left_to_next,
533 bi0, bi1, next0, next1);
536 while (n_left_from > 0 && n_left_to_next > 0)
545 u16 new_port0, old_port0;
553 icmp46_header_t *icmp0;
575 ICMP4_time_exceeded_ttl_exceeded_in_transit,
587 icmp0 = (icmp46_header_t *) udp0;
589 next0 =
icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0,
590 rx_fib_index0,
node, next0, thread_index,
605 b0->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
610 clib_net_to_host_u16 (tcp0->dst), &new_addr0);
615 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
617 clib_net_to_host_u16 (tcp0->src),
619 clib_net_to_host_u16 (tcp0->dst),
622 b0->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
641 && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
642 ses0->
state = SNAT_SESSION_TCP_CLOSE_WAIT;
644 && ses0->
state == SNAT_SESSION_TCP_LAST_ACK)
647 sum0 = tcp0->checksum;
671 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
686 to_next, n_left_to_next,
694 NAT_DET_OUT2IN_ERROR_OUT2IN_PACKETS,
696 return frame->n_vectors;
701 .name =
"nat44-det-out2in",
702 .vector_size =
sizeof (
u32),
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
u32 icmp_match_out2in_det(snat_main_t *sm, vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, 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 ICMP packet translation and create session if needed...
#define nat_log_info(...)
vlib_node_registration_t snat_det_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)
u32 icmp_out2in(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0, vlib_node_runtime_t *node, u32 next0, u32 thread_index, void *d, void *e)
static void snat_det_ses_close(snat_det_map_t *dm, snat_det_session_t *ses)
#define VLIB_NODE_FN(node)
vlib_error_t * errors
Vector of errors for this node.
struct _tcp_header tcp_header_t
static void snat_det_reverse(snat_det_map_t *dm, ip4_address_t *out_addr, u16 out_port, ip4_address_t *in_addr)
vl_api_ip_proto_t protocol
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
ip4_address_t ext_host_addr
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
static void * ip4_next_header(ip4_header_t *i)
static char * nat_det_out2in_error_strings[]
vl_api_fib_path_type_t type
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
snat_det_session_t * sessions
static snat_det_map_t * snat_det_map_by_out(snat_main_t *sm, ip4_address_t *out_addr)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
#define VLIB_REGISTER_NODE(x,...)
#define CLIB_PREFETCH(addr, size, type)
static u8 * format_nat_det_out2in_trace(u8 *s, va_list *args)
deterministic NAT definitions
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
vlib_main_t vlib_node_runtime_t * node
u32 det_out2in_node_index
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define foreach_nat_det_out2in_error
static u32 ip_proto_to_snat_proto(u8 ip_proto)
VLIB buffer representation.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define ip_csum_update(sum, old, new, type, field)
static u8 is_interface_addr(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, u32 ip4_addr)
static snat_det_session_t * snat_det_get_ses_by_out(snat_det_map_t *dm, ip4_address_t *in_addr, u64 out_key)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
#define VLIB_NODE_FLAG_TRACE
#define CLIB_CACHE_LINE_BYTES
static_always_inline void icmp4_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u16 ip_csum_fold(ip_csum_t c)