45 #define foreach_nat_det_in2out_error \ 46 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 47 _(NO_TRANSLATION, "No translation") \ 48 _(BAD_ICMP_TYPE, "unsupported ICMP type") \ 49 _(OUT_OF_PORTS, "Out of ports") \ 50 _(IN2OUT_PACKETS, "Good in2out packets processed") 54 #define _(sym,str) NAT_DET_IN2OUT_ERROR_##sym, 61 #define _(sym,string) string, 73 s =
format (s,
"NAT_DET_IN2OUT: sw_if_index %d, next index %d, session %d",
79 #ifndef CLIB_MARCH_VARIANT 99 u8 * p_dont_translate,
void *d,
void *e)
101 icmp46_header_t *icmp0;
106 u8 dont_translate = 0;
111 icmp46_header_t *inner_icmp0;
126 protocol = SNAT_PROTOCOL_ICMP;
138 case SNAT_PROTOCOL_ICMP:
139 inner_icmp0 = (icmp46_header_t *) l4_header;
143 case SNAT_PROTOCOL_UDP:
144 case SNAT_PROTOCOL_TCP:
148 b0->
error = node->
errors[NAT_DET_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
167 b0->
error = node->
errors[NAT_DET_IN2OUT_ERROR_NO_TRANSLATION];
186 if (icmp0->type != ICMP4_echo_request)
188 b0->
error = node->
errors[NAT_DET_IN2OUT_ERROR_BAD_ICMP_TYPE];
194 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
211 b0->
error = node->
errors[NAT_DET_IN2OUT_ERROR_OUT_OF_PORTS];
219 b0->
error = node->
errors[NAT_DET_IN2OUT_ERROR_BAD_ICMP_TYPE];
226 ses0->
state = SNAT_SESSION_ICMP_ACTIVE;
233 p_value->
addr = new_addr0;
237 *p_dont_translate = dont_translate;
250 u32 n_left_from, *from, *to_next;
252 u32 pkts_processed = 0;
258 n_left_from = frame->n_vectors;
259 next_index = node->cached_next_index;
261 while (n_left_from > 0)
267 while (n_left_from >= 4 && n_left_to_next >= 2)
272 u32 sw_if_index0, sw_if_index1;
276 u16 old_port0, new_port0, lo_port0, i0;
277 u16 old_port1, new_port1, lo_port1, i1;
284 u32 rx_fib_index0, rx_fib_index1;
285 icmp46_header_t *icmp0, *icmp1;
302 to_next[0] = bi0 = from[0];
303 to_next[1] = bi1 = from[1];
325 ICMP4_time_exceeded_ttl_exceeded_in_transit,
337 icmp0 = (icmp46_header_t *) udp0;
339 next0 =
icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0,
340 rx_fib_index0, node, next0, thread_index,
351 b0->
error = node->errors[NAT_DET_IN2OUT_ERROR_NO_TRANSLATION];
366 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
387 ICMP4_destination_unreachable,
388 ICMP4_destination_unreachable_destination_unreachable_host,
410 ses0->
state = SNAT_SESSION_TCP_SYN_SENT;
412 && ses0->
state == SNAT_SESSION_TCP_SYN_SENT)
413 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
415 && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
416 ses0->
state = SNAT_SESSION_TCP_FIN_WAIT;
418 && ses0->
state == SNAT_SESSION_TCP_FIN_WAIT)
421 && ses0->
state == SNAT_SESSION_TCP_CLOSE_WAIT)
422 ses0->
state = SNAT_SESSION_TCP_LAST_ACK;
423 else if (tcp0->flags == 0
424 && ses0->
state == SNAT_SESSION_UNKNOWN)
425 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
427 old_port0 = tcp0->src;
428 tcp0->src = new_port0;
430 sum0 = tcp0->checksum;
442 ses0->
state = SNAT_SESSION_UDP_ACTIVE;
450 case SNAT_SESSION_UDP_ACTIVE:
453 case SNAT_SESSION_TCP_SYN_SENT:
454 case SNAT_SESSION_TCP_FIN_WAIT:
455 case SNAT_SESSION_TCP_CLOSE_WAIT:
456 case SNAT_SESSION_TCP_LAST_ACK:
459 case SNAT_SESSION_TCP_ESTABLISHED:
466 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
489 ICMP4_time_exceeded_ttl_exceeded_in_transit,
501 icmp1 = (icmp46_header_t *) udp1;
503 next1 =
icmp_in2out (sm, b1, ip1, icmp1, sw_if_index1,
504 rx_fib_index1, node, next1, thread_index,
515 b1->
error = node->errors[NAT_DET_IN2OUT_ERROR_NO_TRANSLATION];
530 key1.
out_port = clib_host_to_net_u16 (lo_port1 +
551 ICMP4_destination_unreachable,
552 ICMP4_destination_unreachable_destination_unreachable_host,
559 new_port1 = ses1->out.out_port;
574 ses1->state = SNAT_SESSION_TCP_SYN_SENT;
576 && ses1->state == SNAT_SESSION_TCP_SYN_SENT)
577 ses1->state = SNAT_SESSION_TCP_ESTABLISHED;
579 && ses1->state == SNAT_SESSION_TCP_ESTABLISHED)
580 ses1->state = SNAT_SESSION_TCP_FIN_WAIT;
582 && ses1->state == SNAT_SESSION_TCP_FIN_WAIT)
585 && ses1->state == SNAT_SESSION_TCP_CLOSE_WAIT)
586 ses1->state = SNAT_SESSION_TCP_LAST_ACK;
587 else if (tcp1->flags == 0
588 && ses1->state == SNAT_SESSION_UNKNOWN)
589 ses1->state = SNAT_SESSION_TCP_ESTABLISHED;
591 old_port1 = tcp1->src;
592 tcp1->src = new_port1;
594 sum1 = tcp1->checksum;
606 ses1->state = SNAT_SESSION_UDP_ACTIVE;
614 case SNAT_SESSION_UDP_ACTIVE:
617 case SNAT_SESSION_TCP_SYN_SENT:
618 case SNAT_SESSION_TCP_FIN_WAIT:
619 case SNAT_SESSION_TCP_CLOSE_WAIT:
620 case SNAT_SESSION_TCP_LAST_ACK:
623 case SNAT_SESSION_TCP_ESTABLISHED:
630 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
645 to_next, n_left_to_next,
646 bi0, bi1, next0, next1);
649 while (n_left_from > 0 && n_left_to_next > 0)
658 u16 old_port0, new_port0, lo_port0, i0;
666 icmp46_header_t *icmp0;
689 ICMP4_time_exceeded_ttl_exceeded_in_transit,
701 icmp0 = (icmp46_header_t *) udp0;
703 next0 =
icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0,
704 rx_fib_index0, node, next0, thread_index,
715 b0->
error = node->errors[NAT_DET_IN2OUT_ERROR_NO_TRANSLATION];
730 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
751 ICMP4_destination_unreachable,
752 ICMP4_destination_unreachable_destination_unreachable_host,
774 ses0->
state = SNAT_SESSION_TCP_SYN_SENT;
776 && ses0->
state == SNAT_SESSION_TCP_SYN_SENT)
777 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
779 && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
780 ses0->
state = SNAT_SESSION_TCP_FIN_WAIT;
782 && ses0->
state == SNAT_SESSION_TCP_FIN_WAIT)
785 && ses0->
state == SNAT_SESSION_TCP_CLOSE_WAIT)
786 ses0->
state = SNAT_SESSION_TCP_LAST_ACK;
787 else if (tcp0->flags == 0
788 && ses0->
state == SNAT_SESSION_UNKNOWN)
789 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
791 old_port0 = tcp0->src;
792 tcp0->src = new_port0;
794 sum0 = tcp0->checksum;
806 ses0->
state = SNAT_SESSION_UDP_ACTIVE;
814 case SNAT_SESSION_UDP_ACTIVE:
817 case SNAT_SESSION_TCP_SYN_SENT:
818 case SNAT_SESSION_TCP_FIN_WAIT:
819 case SNAT_SESSION_TCP_CLOSE_WAIT:
820 case SNAT_SESSION_TCP_LAST_ACK:
823 case SNAT_SESSION_TCP_ESTABLISHED:
830 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
845 to_next, n_left_to_next,
853 NAT_DET_IN2OUT_ERROR_IN2OUT_PACKETS,
855 return frame->n_vectors;
860 .name =
"nat44-det-in2out",
861 .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.
#define nat_log_info(...)
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
static f64 vlib_time_now(vlib_main_t *vm)
static void snat_det_ses_close(snat_det_map_t *dm, snat_det_session_t *ses)
static snat_det_session_t * snat_det_find_ses_by_in(snat_det_map_t *dm, ip4_address_t *in_addr, u16 in_port, snat_det_out_key_t out_key)
static void snat_det_forward(snat_det_map_t *dm, ip4_address_t *in_addr, ip4_address_t *out_addr, u16 *lo_port)
#define VLIB_NODE_FN(node)
vlib_error_t * errors
Vector of errors for this node.
u32 icmp_match_in2out_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...
struct _tcp_header tcp_header_t
static char * nat_det_in2out_error_strings[]
static int snat_not_translate_fast(snat_main_t *sm, vlib_node_runtime_t *node, u32 sw_if_index0, ip4_header_t *ip0, u32 proto0, u32 rx_fib_index0)
Check if packet should be translated.
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
ip4_address_t ext_host_addr
u32 det_in2out_node_index
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
u32 icmp_in2out(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 * ip4_next_header(ip4_header_t *i)
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void mss_clamping(snat_main_t *sm, tcp_header_t *tcp, ip_csum_t *sum)
snat_det_session_t * sessions
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
vl_api_address_union_t src_address
#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...
static snat_det_session_t * snat_det_ses_create(u32 thread_index, snat_det_map_t *dm, ip4_address_t *in_addr, u16 in_port, snat_det_out_key_t *out)
#define VLIB_REGISTER_NODE(x,...)
#define CLIB_PREFETCH(addr, size, type)
void icmp4_error_set_vnet_buffer(vlib_buffer_t *b, u8 type, u8 code, u32 data)
deterministic NAT definitions
#define foreach_nat_det_in2out_error
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.
u32 tcp_transitory_timeout
static snat_det_map_t * snat_det_map_by_user(snat_main_t *sm, ip4_address_t *user_addr)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static u32 ip_proto_to_snat_proto(u8 ip_proto)
The NAT inline functions.
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 snat_det_session_t * snat_det_get_ses_by_out(snat_det_map_t *dm, ip4_address_t *in_addr, u64 out_key)
#define VLIB_NODE_FLAG_TRACE
#define CLIB_CACHE_LINE_BYTES
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)
static u8 * format_nat_det_in2out_trace(u8 *s, va_list *args)
u32 tcp_established_timeout