50 #define foreach_det44_in2out_error \ 51 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 52 _(NO_TRANSLATION, "No translation") \ 53 _(BAD_ICMP_TYPE, "unsupported ICMP type") \ 54 _(OUT_OF_PORTS, "Out of ports") \ 55 _(IN2OUT_PACKETS, "Good in2out packets processed") 59 #define _(sym,str) DET44_IN2OUT_ERROR_##sym, 66 #define _(sym,string) string, 78 s =
format (s,
"DET44_IN2OUT: sw_if_index %d, next index %d, session %d",
84 #ifndef CLIB_MARCH_VARIANT 109 icmp46_header_t *icmp0;
118 icmp46_header_t *inner_icmp0;
135 protocol = NAT_PROTOCOL_ICMP;
148 case NAT_PROTOCOL_ICMP:
149 inner_icmp0 = (icmp46_header_t *) l4_header;
153 case NAT_PROTOCOL_UDP:
154 case NAT_PROTOCOL_TCP:
158 b0->
error = node->
errors[DET44_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
168 IP_PROTOCOL_ICMP, rx_fib_index0)))
174 b0->
error = node->
errors[DET44_IN2OUT_ERROR_NO_TRANSLATION];
187 IP_PROTOCOL_ICMP, rx_fib_index0)))
192 if (icmp0->type != ICMP4_echo_request)
194 b0->
error = node->
errors[DET44_IN2OUT_ERROR_BAD_ICMP_TYPE];
200 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
217 b0->
error = node->
errors[DET44_IN2OUT_ERROR_OUT_OF_PORTS];
223 (
vnet_buffer (b0)->
ip.reass.icmp_type_or_tcp_flags != ICMP4_echo_request
225 reass.icmp_type_or_tcp_flags)))
227 b0->
error = node->
errors[DET44_IN2OUT_ERROR_BAD_ICMP_TYPE];
234 ses0->
state = DET44_SESSION_ICMP_ACTIVE;
253 #ifndef CLIB_MARCH_VARIANT 257 icmp46_header_t * icmp0,
261 u32 next0,
u32 thread_index,
void *d,
void *e)
264 u16 old_id0, new_id0,
port, checksum0, old_checksum0, new_checksum0;
265 u32 new_addr0, old_addr0, next0_tmp, fib_index;
267 icmp46_header_t *inner_icmp0;
277 &addr, &port, &fib_index, &protocol,
278 d, e, &dont_translate);
310 if (icmp0->checksum == 0)
311 icmp0->checksum = 0xffff;
322 sum0 = icmp0->checksum;
344 sum0 = icmp0->checksum;
350 old_checksum0 = inner_ip0->
checksum;
355 new_checksum0 = inner_ip0->
checksum;
356 sum0 = icmp0->checksum;
364 case NAT_PROTOCOL_ICMP:
365 inner_icmp0 = (icmp46_header_t *) l4_header;
372 sum0 = icmp0->checksum;
378 case NAT_PROTOCOL_UDP:
379 case NAT_PROTOCOL_TCP:
384 sum0 = icmp0->checksum;
406 u32 n_left_from, *from;
407 u32 pkts_processed = 0;
413 n_left_from =
frame->n_vectors;
419 while (n_left_from >= 2)
423 u32 sw_if_index0, sw_if_index1;
427 u16 old_port0, new_port0, lo_port0, i0;
428 u16 old_port1, new_port1, lo_port1, i1;
435 u32 rx_fib_index0, rx_fib_index1;
436 icmp46_header_t *icmp0, *icmp1;
471 ICMP4_time_exceeded_ttl_exceeded_in_transit,
483 icmp0 = (icmp46_header_t *) udp0;
487 rx_fib_index0,
node, next0,
488 thread_index, &ses0, &mp0);
498 b0->
error =
node->errors[DET44_IN2OUT_ERROR_NO_TRANSLATION];
513 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
533 ICMP4_destination_unreachable,
534 ICMP4_destination_unreachable_destination_unreachable_host,
556 ses0->
state = DET44_SESSION_TCP_SYN_SENT;
558 && ses0->
state == DET44_SESSION_TCP_SYN_SENT)
559 ses0->
state = DET44_SESSION_TCP_ESTABLISHED;
561 && ses0->
state == DET44_SESSION_TCP_ESTABLISHED)
562 ses0->
state = DET44_SESSION_TCP_FIN_WAIT;
564 && ses0->
state == DET44_SESSION_TCP_FIN_WAIT)
567 && ses0->
state == DET44_SESSION_TCP_CLOSE_WAIT)
568 ses0->
state = DET44_SESSION_TCP_LAST_ACK;
569 else if (tcp0->flags == 0 && ses0->
state == DET44_SESSION_UNKNOWN)
570 ses0->
state = DET44_SESSION_TCP_ESTABLISHED;
572 sum0 = tcp0->checksum;
584 ses0->
state = DET44_SESSION_UDP_ACTIVE;
603 case DET44_SESSION_UDP_ACTIVE:
606 case DET44_SESSION_TCP_SYN_SENT:
607 case DET44_SESSION_TCP_FIN_WAIT:
608 case DET44_SESSION_TCP_CLOSE_WAIT:
609 case DET44_SESSION_TCP_LAST_ACK:
612 case DET44_SESSION_TCP_ESTABLISHED:
619 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
642 ICMP4_time_exceeded_ttl_exceeded_in_transit,
654 icmp1 = (icmp46_header_t *) udp1;
657 rx_fib_index1,
node, next1,
658 thread_index, &ses1, &mp1);
668 b1->
error =
node->errors[DET44_IN2OUT_ERROR_NO_TRANSLATION];
683 key1.
out_port = clib_host_to_net_u16 (lo_port1 +
703 ICMP4_destination_unreachable,
704 ICMP4_destination_unreachable_destination_unreachable_host,
712 udp1->
src_port = new_port1 = ses1->out.out_port;
726 ses1->state = DET44_SESSION_TCP_SYN_SENT;
728 && ses1->state == DET44_SESSION_TCP_SYN_SENT)
729 ses1->state = DET44_SESSION_TCP_ESTABLISHED;
731 && ses1->state == DET44_SESSION_TCP_ESTABLISHED)
732 ses1->state = DET44_SESSION_TCP_FIN_WAIT;
734 && ses1->state == DET44_SESSION_TCP_FIN_WAIT)
737 && ses1->state == DET44_SESSION_TCP_CLOSE_WAIT)
738 ses1->state = DET44_SESSION_TCP_LAST_ACK;
739 else if (tcp1->flags == 0 && ses1->state == DET44_SESSION_UNKNOWN)
740 ses1->state = DET44_SESSION_TCP_ESTABLISHED;
742 sum1 = tcp1->checksum;
754 ses1->state = DET44_SESSION_UDP_ACTIVE;
773 case DET44_SESSION_UDP_ACTIVE:
776 case DET44_SESSION_TCP_SYN_SENT:
777 case DET44_SESSION_TCP_FIN_WAIT:
778 case DET44_SESSION_TCP_CLOSE_WAIT:
779 case DET44_SESSION_TCP_LAST_ACK:
782 case DET44_SESSION_TCP_ESTABLISHED:
789 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
808 while (n_left_from > 0)
816 u16 old_port0, new_port0, lo_port0, i0;
824 icmp46_header_t *icmp0;
840 ICMP4_time_exceeded_ttl_exceeded_in_transit,
852 icmp0 = (icmp46_header_t *) udp0;
855 rx_fib_index0,
node, next0,
856 thread_index, &ses0, &mp0);
866 b0->
error =
node->errors[DET44_IN2OUT_ERROR_NO_TRANSLATION];
881 key0.
out_port = clib_host_to_net_u16 (lo_port0 +
901 ICMP4_destination_unreachable,
902 ICMP4_destination_unreachable_destination_unreachable_host,
924 ses0->
state = DET44_SESSION_TCP_SYN_SENT;
926 && ses0->
state == DET44_SESSION_TCP_SYN_SENT)
927 ses0->
state = DET44_SESSION_TCP_ESTABLISHED;
929 && ses0->
state == DET44_SESSION_TCP_ESTABLISHED)
930 ses0->
state = DET44_SESSION_TCP_FIN_WAIT;
932 && ses0->
state == DET44_SESSION_TCP_FIN_WAIT)
935 && ses0->
state == DET44_SESSION_TCP_CLOSE_WAIT)
936 ses0->
state = DET44_SESSION_TCP_LAST_ACK;
937 else if (tcp0->flags == 0 && ses0->
state == DET44_SESSION_UNKNOWN)
938 ses0->
state = DET44_SESSION_TCP_ESTABLISHED;
940 sum0 = tcp0->checksum;
952 ses0->
state = DET44_SESSION_UDP_ACTIVE;
971 case DET44_SESSION_UDP_ACTIVE:
974 case DET44_SESSION_TCP_SYN_SENT:
975 case DET44_SESSION_TCP_FIN_WAIT:
976 case DET44_SESSION_TCP_CLOSE_WAIT:
977 case DET44_SESSION_TCP_LAST_ACK:
980 case DET44_SESSION_TCP_ESTABLISHED:
987 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1009 DET44_IN2OUT_ERROR_IN2OUT_PACKETS,
1011 return frame->n_vectors;
1016 .name =
"det44-in2out",
1017 .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.
static ip_csum_t ip_incremental_checksum_buffer(vlib_main_t *vm, vlib_buffer_t *first_buffer, u32 first_buffer_offset, u32 n_bytes_to_checksum, ip_csum_t sum)
static_always_inline int det44_translate(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.
vlib_node_registration_t det44_in2out_node
(constructor) VLIB_REGISTER_NODE (det44_in2out_node)
static_always_inline snat_det_session_t * snat_det_get_ses_by_out(snat_det_map_t *dm, ip4_address_t *in_addr, u64 out_key)
vl_api_ip_port_and_mask_t dst_port
static f64 vlib_time_now(vlib_main_t *vm)
Deterministic NAT (CGN) definitions.
#define VLIB_NODE_FN(node)
NAT port/address allocation lib.
vlib_error_t * errors
Vector of errors for this node.
struct _tcp_header tcp_header_t
struct nat_timeouts_s::@74 tcp
static int ip4_is_fragment(const ip4_header_t *i)
vl_api_ip_proto_t protocol
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
static uword ip4_header_checksum_is_valid(ip4_header_t *i)
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
ip4_address_t ext_host_addr
static_always_inline 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_always_inline 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_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)
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
#define foreach_det44_in2out_error
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static void mss_clamping(u16 mss_clamping, tcp_header_t *tcp, ip_csum_t *sum)
vl_api_address_union_t src_address
#define det44_log_info(...)
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_always_inline void snat_det_forward(snat_det_map_t *dm, ip4_address_t *in_addr, ip4_address_t *out_addr, u16 *lo_port)
#define VLIB_REGISTER_NODE(x,...)
#define CLIB_PREFETCH(addr, size, type)
static_always_inline void vlib_buffer_enqueue_to_next(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, u16 *nexts, uword count)
static_always_inline void snat_det_ses_close(snat_det_map_t *dm, snat_det_session_t *ses)
vlib_main_t vlib_node_runtime_t * node
Deterministic NAT (CGN) inlines.
static char * det44_in2out_error_strings[]
static vlib_main_t * vlib_get_main(void)
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
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)
u32 det44_icmp_in2out(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 u8 * format_det44_in2out_trace(u8 *s, va_list *args)
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static int ip4_header_bytes(const ip4_header_t *i)
static_always_inline snat_det_map_t * snat_det_map_by_user(ip4_address_t *user_addr)
static_always_inline void vlib_get_buffers(vlib_main_t *vm, u32 *bi, vlib_buffer_t **b, int count)
Translate array of buffer indices into buffer pointers.
#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 u16 ip_csum_fold(ip_csum_t c)
u32 icmp_match_in2out_det(vlib_node_runtime_t *node, u32 thread_index, vlib_buffer_t *b0, ip4_header_t *ip0, ip4_address_t *addr, u16 *port, u32 *fib_index, nat_protocol_t *proto, void *d, void *e, u8 *dont_translate)
Get address and port values to be used for ICMP packet translation and create session if needed...
vl_api_interface_index_t sw_if_index