50 #define foreach_det44_out2in_error \ 51 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 52 _(NO_TRANSLATION, "No translation") \ 53 _(BAD_ICMP_TYPE, "unsupported ICMP type") \ 54 _(OUT2IN_PACKETS, "Good out2in packets processed") 58 #define _(sym,str) DET44_OUT2IN_ERROR_##sym, 65 #define _(sym,string) string, 79 "DET44_OUT2IN: sw_if_index %d, next index %d, session index %d",
84 #ifndef CLIB_MARCH_VARIANT 108 icmp46_header_t *icmp0;
116 icmp46_header_t *inner_icmp0;
130 protocol = NAT_PROTOCOL_ICMP;
146 case NAT_PROTOCOL_ICMP:
147 inner_icmp0 = (icmp46_header_t *) l4_header;
152 case NAT_PROTOCOL_UDP:
153 case NAT_PROTOCOL_TCP:
158 b0->
error = node->
errors[DET44_OUT2IN_ERROR_UNSUPPORTED_PROTOCOL];
180 clib_net_to_host_u16 (key0.
out_port), &new_addr0);
196 clib_net_to_host_u16 (key0.
out_port),
198 b0->
error = node->
errors[DET44_OUT2IN_ERROR_NO_TRANSLATION];
204 (
vnet_buffer (b0)->
ip.reass.icmp_type_or_tcp_flags != ICMP4_echo_reply
206 reass.icmp_type_or_tcp_flags)))
208 b0->
error = node->
errors[DET44_OUT2IN_ERROR_BAD_ICMP_TYPE];
231 #ifndef CLIB_MARCH_VARIANT 235 icmp46_header_t * icmp0,
239 u32 next0,
u32 thread_index,
void *d,
void *e)
242 u32 new_addr0, old_addr0, next0_tmp, fib_index;
243 u16 old_id0, new_id0,
port, checksum0;
245 icmp46_header_t *inner_icmp0;
255 &addr, &port, &fib_index, &proto,
256 d, e, &dont_translate);
271 if (checksum0 != 0 && checksum0 != 0xffff)
290 if (icmp0->checksum == 0)
291 icmp0->checksum = 0xffff;
302 sum0 = icmp0->checksum;
324 sum0 = icmp0->checksum;
331 case NAT_PROTOCOL_ICMP:
332 inner_icmp0 = (icmp46_header_t *) l4_header;
339 sum0 = icmp0->checksum;
345 case NAT_PROTOCOL_UDP:
346 case NAT_PROTOCOL_TCP:
351 sum0 = icmp0->checksum;
371 u32 n_left_from, *from;
372 u32 pkts_processed = 0;
377 n_left_from =
frame->n_vectors;
383 while (n_left_from >= 2)
388 u32 sw_if_index0, sw_if_index1;
392 u16 new_port0, old_port0, old_port1, new_port1;
399 u32 rx_fib_index0, rx_fib_index1;
400 icmp46_header_t *icmp0, *icmp1;
433 ICMP4_time_exceeded_ttl_exceeded_in_transit,
445 icmp0 = (icmp46_header_t *) udp0;
448 rx_fib_index0,
node, next0,
449 thread_index, &ses0, &mp0);
463 b0->
error =
node->errors[DET44_OUT2IN_ERROR_NO_TRANSLATION];
468 clib_net_to_host_u16 (tcp0->dst), &new_addr0);
475 clib_net_to_host_u16 (tcp0->src),
477 clib_net_to_host_u16 (tcp0->dst),
480 b0->
error =
node->errors[DET44_OUT2IN_ERROR_NO_TRANSLATION];
498 && ses0->
state == DET44_SESSION_TCP_ESTABLISHED)
499 ses0->
state = DET44_SESSION_TCP_CLOSE_WAIT;
501 && ses0->
state == DET44_SESSION_TCP_LAST_ACK)
504 sum0 = tcp0->checksum;
528 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
551 ICMP4_time_exceeded_ttl_exceeded_in_transit,
563 icmp1 = (icmp46_header_t *) udp1;
566 rx_fib_index1,
node, next1,
567 thread_index, &ses1, &mp1);
581 b1->
error =
node->errors[DET44_OUT2IN_ERROR_NO_TRANSLATION];
586 clib_net_to_host_u16 (tcp1->dst), &new_addr1);
593 clib_net_to_host_u16 (tcp1->src),
595 clib_net_to_host_u16 (tcp1->dst),
598 b1->
error =
node->errors[DET44_OUT2IN_ERROR_NO_TRANSLATION];
602 udp1->
dst_port = new_port1 = ses1->in_port;
616 && ses1->state == DET44_SESSION_TCP_ESTABLISHED)
617 ses1->state = DET44_SESSION_TCP_CLOSE_WAIT;
619 && ses1->state == DET44_SESSION_TCP_LAST_ACK)
622 sum1 = tcp1->checksum;
646 && (b1->
flags & VLIB_BUFFER_IS_TRACED)))
665 while (n_left_from > 0)
673 u16 new_port0, old_port0;
681 icmp46_header_t *icmp0;
696 ICMP4_time_exceeded_ttl_exceeded_in_transit,
708 icmp0 = (icmp46_header_t *) udp0;
711 rx_fib_index0,
node, next0,
712 thread_index, &ses0, &mp0);
726 b0->
error =
node->errors[DET44_OUT2IN_ERROR_NO_TRANSLATION];
731 clib_net_to_host_u16 (tcp0->dst), &new_addr0);
738 clib_net_to_host_u16 (tcp0->src),
740 clib_net_to_host_u16 (tcp0->dst),
743 b0->
error =
node->errors[DET44_OUT2IN_ERROR_NO_TRANSLATION];
761 && ses0->
state == DET44_SESSION_TCP_ESTABLISHED)
762 ses0->
state = DET44_SESSION_TCP_CLOSE_WAIT;
764 && ses0->
state == DET44_SESSION_TCP_LAST_ACK)
767 sum0 = tcp0->checksum;
791 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
813 DET44_OUT2IN_ERROR_OUT2IN_PACKETS,
815 return frame->n_vectors;
820 .name =
"det44-out2in",
821 .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 snat_det_session_t * snat_det_get_ses_by_out(snat_det_map_t *dm, ip4_address_t *in_addr, u64 out_key)
static_always_inline void snat_det_reverse(snat_det_map_t *dm, ip4_address_t *out_addr, u16 out_port, ip4_address_t *in_addr)
vlib_node_registration_t det44_out2in_node
(constructor) VLIB_REGISTER_NODE (det44_out2in_node)
vl_api_ip_proto_t protocol
Deterministic NAT (CGN) definitions.
u32 icmp_match_out2in_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...
#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
static int ip4_is_fragment(const ip4_header_t *i)
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
description fragment has unexpected format
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
static_always_inline snat_det_map_t * snat_det_map_by_out(ip4_address_t *out_addr)
static_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
static void * ip4_next_header(ip4_header_t *i)
static char * det44_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 void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
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...
vl_api_ip_port_and_mask_t src_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 u8 * format_det44_out2in_trace(u8 *s, va_list *args)
#define foreach_det44_out2in_error
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)
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 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
u32 det44_icmp_out2in(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)
#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_always_inline int det44_is_interface_addr(vlib_node_runtime_t *node, u32 sw_if_index0, u32 ip4_addr)
static u16 ip_csum_fold(ip_csum_t c)