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, 75 s =
format (s,
"NAT_DET_IN2OUT: sw_if_index %d, next index %d, session %d",
100 u8 * p_dont_translate,
void *d,
void *e)
102 icmp46_header_t *icmp0;
107 u8 dont_translate = 0;
112 icmp46_header_t *inner_icmp0;
127 protocol = SNAT_PROTOCOL_ICMP;
139 case SNAT_PROTOCOL_ICMP:
140 inner_icmp0 = (icmp46_header_t *) l4_header;
144 case SNAT_PROTOCOL_UDP:
145 case SNAT_PROTOCOL_TCP:
149 b0->
error = node->
errors[NAT_DET_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
168 b0->
error = node->
errors[NAT_DET_IN2OUT_ERROR_NO_TRANSLATION];
187 if (icmp0->type != ICMP4_echo_request)
189 b0->
error = node->
errors[NAT_DET_IN2OUT_ERROR_BAD_ICMP_TYPE];
195 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;
249 u32 n_left_from, *from, *to_next;
251 u32 pkts_processed = 0;
260 while (n_left_from > 0)
266 while (n_left_from >= 4 && n_left_to_next >= 2)
271 u32 sw_if_index0, sw_if_index1;
275 u16 old_port0, new_port0, lo_port0, i0;
276 u16 old_port1, new_port1, lo_port1, i1;
283 u32 rx_fib_index0, rx_fib_index1;
284 icmp46_header_t *icmp0, *icmp1;
301 to_next[0] = bi0 = from[0];
302 to_next[1] = bi1 = from[1];
324 ICMP4_time_exceeded_ttl_exceeded_in_transit,
336 icmp0 = (icmp46_header_t *) udp0;
338 next0 =
icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0,
339 rx_fib_index0, node, next0, thread_index,
350 b0->
error = node->
errors[NAT_DET_IN2OUT_ERROR_NO_TRANSLATION];
365 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
386 ICMP4_destination_unreachable,
387 ICMP4_destination_unreachable_destination_unreachable_host,
409 ses0->
state = SNAT_SESSION_TCP_SYN_SENT;
411 && ses0->
state == SNAT_SESSION_TCP_SYN_SENT)
412 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
414 && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
415 ses0->
state = SNAT_SESSION_TCP_FIN_WAIT;
417 && ses0->
state == SNAT_SESSION_TCP_FIN_WAIT)
420 && ses0->
state == SNAT_SESSION_TCP_CLOSE_WAIT)
421 ses0->
state = SNAT_SESSION_TCP_LAST_ACK;
422 else if (tcp0->flags == 0
423 && ses0->
state == SNAT_SESSION_UNKNOWN)
424 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
426 old_port0 = tcp0->src;
427 tcp0->src = new_port0;
429 sum0 = tcp0->checksum;
441 ses0->
state = SNAT_SESSION_UDP_ACTIVE;
449 case SNAT_SESSION_UDP_ACTIVE:
452 case SNAT_SESSION_TCP_SYN_SENT:
453 case SNAT_SESSION_TCP_FIN_WAIT:
454 case SNAT_SESSION_TCP_CLOSE_WAIT:
455 case SNAT_SESSION_TCP_LAST_ACK:
458 case SNAT_SESSION_TCP_ESTABLISHED:
465 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
488 ICMP4_time_exceeded_ttl_exceeded_in_transit,
500 icmp1 = (icmp46_header_t *) udp1;
502 next1 =
icmp_in2out (sm, b1, ip1, icmp1, sw_if_index1,
503 rx_fib_index1, node, next1, thread_index,
514 b1->
error = node->
errors[NAT_DET_IN2OUT_ERROR_NO_TRANSLATION];
529 key1.
out_port = clib_host_to_net_u16 (lo_port1 +
550 ICMP4_destination_unreachable,
551 ICMP4_destination_unreachable_destination_unreachable_host,
558 new_port1 = ses1->out.out_port;
573 ses1->state = SNAT_SESSION_TCP_SYN_SENT;
575 && ses1->state == SNAT_SESSION_TCP_SYN_SENT)
576 ses1->state = SNAT_SESSION_TCP_ESTABLISHED;
578 && ses1->state == SNAT_SESSION_TCP_ESTABLISHED)
579 ses1->state = SNAT_SESSION_TCP_FIN_WAIT;
581 && ses1->state == SNAT_SESSION_TCP_FIN_WAIT)
584 && ses1->state == SNAT_SESSION_TCP_CLOSE_WAIT)
585 ses1->state = SNAT_SESSION_TCP_LAST_ACK;
586 else if (tcp1->flags == 0
587 && ses1->state == SNAT_SESSION_UNKNOWN)
588 ses1->state = SNAT_SESSION_TCP_ESTABLISHED;
590 old_port1 = tcp1->src;
591 tcp1->src = new_port1;
593 sum1 = tcp1->checksum;
605 ses1->state = SNAT_SESSION_UDP_ACTIVE;
613 case SNAT_SESSION_UDP_ACTIVE:
616 case SNAT_SESSION_TCP_SYN_SENT:
617 case SNAT_SESSION_TCP_FIN_WAIT:
618 case SNAT_SESSION_TCP_CLOSE_WAIT:
619 case SNAT_SESSION_TCP_LAST_ACK:
622 case SNAT_SESSION_TCP_ESTABLISHED:
629 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
644 to_next, n_left_to_next,
645 bi0, bi1, next0, next1);
648 while (n_left_from > 0 && n_left_to_next > 0)
657 u16 old_port0, new_port0, lo_port0, i0;
665 icmp46_header_t *icmp0;
688 ICMP4_time_exceeded_ttl_exceeded_in_transit,
700 icmp0 = (icmp46_header_t *) udp0;
702 next0 =
icmp_in2out (sm, b0, ip0, icmp0, sw_if_index0,
703 rx_fib_index0, node, next0, thread_index,
714 b0->
error = node->
errors[NAT_DET_IN2OUT_ERROR_NO_TRANSLATION];
729 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
750 ICMP4_destination_unreachable,
751 ICMP4_destination_unreachable_destination_unreachable_host,
773 ses0->
state = SNAT_SESSION_TCP_SYN_SENT;
775 && ses0->
state == SNAT_SESSION_TCP_SYN_SENT)
776 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
778 && ses0->
state == SNAT_SESSION_TCP_ESTABLISHED)
779 ses0->
state = SNAT_SESSION_TCP_FIN_WAIT;
781 && ses0->
state == SNAT_SESSION_TCP_FIN_WAIT)
784 && ses0->
state == SNAT_SESSION_TCP_CLOSE_WAIT)
785 ses0->
state = SNAT_SESSION_TCP_LAST_ACK;
786 else if (tcp0->flags == 0
787 && ses0->
state == SNAT_SESSION_UNKNOWN)
788 ses0->
state = SNAT_SESSION_TCP_ESTABLISHED;
790 old_port0 = tcp0->src;
791 tcp0->src = new_port0;
793 sum0 = tcp0->checksum;
805 ses0->
state = SNAT_SESSION_UDP_ACTIVE;
813 case SNAT_SESSION_UDP_ACTIVE:
816 case SNAT_SESSION_TCP_SYN_SENT:
817 case SNAT_SESSION_TCP_FIN_WAIT:
818 case SNAT_SESSION_TCP_CLOSE_WAIT:
819 case SNAT_SESSION_TCP_LAST_ACK:
822 case SNAT_SESSION_TCP_ESTABLISHED:
829 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
844 to_next, n_left_to_next,
852 NAT_DET_IN2OUT_ERROR_IN2OUT_PACKETS,
860 .name =
"nat44-det-in2out",
861 .vector_size =
sizeof (
u32),
#define nat_log_info(...)
vlib_node_registration_t snat_det_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)
VLIB_NODE_FUNCTION_MULTIARCH(snat_det_in2out_node, snat_det_in2out_node_fn)
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)
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
#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)
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).
vlib_error_t error
Error code for buffers to be enqueued to error handler.
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)
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
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
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)
struct _vlib_node_registration vlib_node_registration_t
static u32 ip_proto_to_snat_proto(u8 ip_proto)
The NAT inline functions.
static uword snat_det_in2out_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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)
u16 flags
Copy of main node flags.
#define VLIB_NODE_FLAG_TRACE
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static snat_det_session_t * snat_det_ses_create(snat_det_map_t *dm, ip4_address_t *in_addr, u16 in_port, snat_det_out_key_t *out)
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