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,
411 ses0->
state = SNAT_SESSION_TCP_SYN_SENT;
413 && ses0->
state == SNAT_SESSION_TCP_SYN_SENT)
414 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
416 && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
417 ses0->
state = SNAT_SESSION_TCP_FIN_WAIT;
419 && ses0->
state == SNAT_SESSION_TCP_FIN_WAIT)
422 && ses0->
state == SNAT_SESSION_TCP_CLOSE_WAIT)
423 ses0->
state = SNAT_SESSION_TCP_LAST_ACK;
424 else if (tcp0->flags == 0
425 && ses0->
state == SNAT_SESSION_UNKNOWN)
426 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
428 sum0 = tcp0->checksum;
440 ses0->
state = SNAT_SESSION_UDP_ACTIVE;
459 case SNAT_SESSION_UDP_ACTIVE:
462 case SNAT_SESSION_TCP_SYN_SENT:
463 case SNAT_SESSION_TCP_FIN_WAIT:
464 case SNAT_SESSION_TCP_CLOSE_WAIT:
465 case SNAT_SESSION_TCP_LAST_ACK:
468 case SNAT_SESSION_TCP_ESTABLISHED:
475 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
498 ICMP4_time_exceeded_ttl_exceeded_in_transit,
510 icmp1 = (icmp46_header_t *) udp1;
512 next1 =
icmp_in2out (sm, b1, ip1, icmp1, sw_if_index1,
513 rx_fib_index1, node, next1, thread_index,
524 b1->
error = node->errors[NAT_DET_IN2OUT_ERROR_NO_TRANSLATION];
539 key1.
out_port = clib_host_to_net_u16 (lo_port1 +
560 ICMP4_destination_unreachable,
561 ICMP4_destination_unreachable_destination_unreachable_host,
569 udp1->
src_port = new_port1 = ses1->out.out_port;
584 ses1->state = SNAT_SESSION_TCP_SYN_SENT;
586 && ses1->state == SNAT_SESSION_TCP_SYN_SENT)
587 ses1->state = SNAT_SESSION_TCP_ESTABLISHED;
589 && ses1->state == SNAT_SESSION_TCP_ESTABLISHED)
590 ses1->state = SNAT_SESSION_TCP_FIN_WAIT;
592 && ses1->state == SNAT_SESSION_TCP_FIN_WAIT)
595 && ses1->state == SNAT_SESSION_TCP_CLOSE_WAIT)
596 ses1->state = SNAT_SESSION_TCP_LAST_ACK;
597 else if (tcp1->flags == 0
598 && ses1->state == SNAT_SESSION_UNKNOWN)
599 ses1->state = SNAT_SESSION_TCP_ESTABLISHED;
601 sum1 = tcp1->checksum;
613 ses1->state = SNAT_SESSION_UDP_ACTIVE;
632 case SNAT_SESSION_UDP_ACTIVE:
635 case SNAT_SESSION_TCP_SYN_SENT:
636 case SNAT_SESSION_TCP_FIN_WAIT:
637 case SNAT_SESSION_TCP_CLOSE_WAIT:
638 case SNAT_SESSION_TCP_LAST_ACK:
641 case SNAT_SESSION_TCP_ESTABLISHED:
648 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
663 to_next, n_left_to_next,
664 bi0, bi1, next0, next1);
667 while (n_left_from > 0 && n_left_to_next > 0)
676 u16 old_port0, new_port0, lo_port0, i0;
684 icmp46_header_t *icmp0;
707 ICMP4_time_exceeded_ttl_exceeded_in_transit,
719 icmp0 = (icmp46_header_t *) udp0;
721 next0 =
icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0,
722 rx_fib_index0, node, next0, thread_index,
733 b0->
error = node->errors[NAT_DET_IN2OUT_ERROR_NO_TRANSLATION];
748 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
769 ICMP4_destination_unreachable,
770 ICMP4_destination_unreachable_destination_unreachable_host,
793 ses0->
state = SNAT_SESSION_TCP_SYN_SENT;
795 && ses0->
state == SNAT_SESSION_TCP_SYN_SENT)
796 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
798 && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
799 ses0->
state = SNAT_SESSION_TCP_FIN_WAIT;
801 && ses0->
state == SNAT_SESSION_TCP_FIN_WAIT)
804 && ses0->
state == SNAT_SESSION_TCP_CLOSE_WAIT)
805 ses0->
state = SNAT_SESSION_TCP_LAST_ACK;
806 else if (tcp0->flags == 0
807 && ses0->
state == SNAT_SESSION_UNKNOWN)
808 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
810 sum0 = tcp0->checksum;
822 ses0->
state = SNAT_SESSION_UDP_ACTIVE;
841 case SNAT_SESSION_UDP_ACTIVE:
844 case SNAT_SESSION_TCP_SYN_SENT:
845 case SNAT_SESSION_TCP_FIN_WAIT:
846 case SNAT_SESSION_TCP_CLOSE_WAIT:
847 case SNAT_SESSION_TCP_LAST_ACK:
850 case SNAT_SESSION_TCP_ESTABLISHED:
857 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
872 to_next, n_left_to_next,
880 NAT_DET_IN2OUT_ERROR_IN2OUT_PACKETS,
882 return frame->n_vectors;
887 .name =
"nat44-det-in2out",
888 .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)
vl_api_fib_path_type_t type
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
vl_api_ip_proto_t protocol
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)
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)
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_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)
static u8 * format_nat_det_in2out_trace(u8 *s, va_list *args)
u32 tcp_established_timeout