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 100 u8 * p_dont_translate,
void *d,
void *e)
102 icmp46_header_t *icmp0;
106 u8 dont_translate = 0;
111 icmp46_header_t *inner_icmp0;
124 protocol = NAT_PROTOCOL_ICMP;
140 case NAT_PROTOCOL_ICMP:
141 inner_icmp0 = (icmp46_header_t *) l4_header;
146 case NAT_PROTOCOL_UDP:
147 case NAT_PROTOCOL_TCP:
152 b0->
error = node->
errors[NAT_DET_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
174 clib_net_to_host_u16 (key0.
out_port), &new_addr0);
186 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
190 clib_net_to_host_u16 (key0.
out_port),
192 b0->
error = node->
errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
198 (
vnet_buffer (b0)->
ip.reass.icmp_type_or_tcp_flags != ICMP4_echo_reply
200 reass.icmp_type_or_tcp_flags)))
202 b0->
error = node->
errors[NAT_DET_OUT2IN_ERROR_BAD_ICMP_TYPE];
213 p_value->
addr = new_addr0;
217 *p_dont_translate = dont_translate;
230 u32 n_left_from, *from, *to_next;
232 u32 pkts_processed = 0;
237 n_left_from =
frame->n_vectors;
238 next_index =
node->cached_next_index;
240 while (n_left_from > 0)
246 while (n_left_from >= 4 && n_left_to_next >= 2)
252 u32 sw_if_index0, sw_if_index1;
256 u16 new_port0, old_port0, old_port1, new_port1;
263 u32 rx_fib_index0, rx_fib_index1;
264 icmp46_header_t *icmp0, *icmp1;
281 to_next[0] = bi0 = from[0];
282 to_next[1] = bi1 = from[1];
301 ICMP4_time_exceeded_ttl_exceeded_in_transit,
313 icmp0 = (icmp46_header_t *) udp0;
315 next0 =
icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0,
316 rx_fib_index0,
node, next0, thread_index,
331 b0->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
336 clib_net_to_host_u16 (tcp0->dst), &new_addr0);
341 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
343 clib_net_to_host_u16 (tcp0->src),
345 clib_net_to_host_u16 (tcp0->dst),
348 b0->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
367 && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
368 ses0->
state = SNAT_SESSION_TCP_CLOSE_WAIT;
370 && ses0->
state == SNAT_SESSION_TCP_LAST_ACK)
373 sum0 = tcp0->checksum;
397 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
422 ICMP4_time_exceeded_ttl_exceeded_in_transit,
434 icmp1 = (icmp46_header_t *) udp1;
436 next1 =
icmp_out2in (sm, b1, ip1, icmp1, sw_if_index1,
437 rx_fib_index1,
node, next1, thread_index,
452 b1->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
457 clib_net_to_host_u16 (tcp1->dst), &new_addr1);
462 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
464 clib_net_to_host_u16 (tcp1->src),
466 clib_net_to_host_u16 (tcp1->dst),
469 b1->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
473 udp1->
dst_port = new_port1 = ses1->in_port;
488 && ses1->state == SNAT_SESSION_TCP_ESTABLISHED)
489 ses1->state = SNAT_SESSION_TCP_CLOSE_WAIT;
491 && ses1->state == SNAT_SESSION_TCP_LAST_ACK)
494 sum1 = tcp1->checksum;
518 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
533 to_next, n_left_to_next,
534 bi0, bi1, next0, next1);
537 while (n_left_from > 0 && n_left_to_next > 0)
546 u16 new_port0, old_port0;
554 icmp46_header_t *icmp0;
576 ICMP4_time_exceeded_ttl_exceeded_in_transit,
588 icmp0 = (icmp46_header_t *) udp0;
590 next0 =
icmp_out2in (sm, b0, ip0, icmp0, sw_if_index0,
591 rx_fib_index0,
node, next0, thread_index,
606 b0->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
611 clib_net_to_host_u16 (tcp0->dst), &new_addr0);
616 nat_log_info (
"no match src %U:%d dst %U:%d for user %U",
618 clib_net_to_host_u16 (tcp0->src),
620 clib_net_to_host_u16 (tcp0->dst),
623 b0->
error =
node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
642 && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
643 ses0->
state = SNAT_SESSION_TCP_CLOSE_WAIT;
645 && ses0->
state == SNAT_SESSION_TCP_LAST_ACK)
648 sum0 = tcp0->checksum;
672 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
687 to_next, n_left_to_next,
695 NAT_DET_OUT2IN_ERROR_OUT2IN_PACKETS,
697 return frame->n_vectors;
702 .name =
"nat44-det-out2in",
703 .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)
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
ip4_address_t ext_host_addr
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
static_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
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.
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
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)