63 format (s,
"NAT64-out2in-reass: sw_if_index %d, next index %d, status %s",
65 t->
cached ?
"cached" :
"translated");
71 #define foreach_nat64_out2in_error \ 72 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \ 73 _(OUT2IN_PACKETS, "good out2in packets processed") \ 74 _(NO_TRANSLATION, "no translation") \ 75 _(UNKNOWN, "unknown") \ 76 _(DROP_FRAGMENT, "drop fragment") \ 77 _(MAX_REASS, "maximum reassemblies exceeded") \ 78 _(MAX_FRAG, "maximum fragments per reassembly exceeded") \ 79 _(TCP_PACKETS, "TCP packets") \ 80 _(UDP_PACKETS, "UDP packets") \ 81 _(ICMP_PACKETS, "ICMP packets") \ 82 _(OTHER_PACKETS, "other protocol packets") \ 83 _(FRAGMENTS, "fragments") \ 84 _(CACHED_FRAGMENTS, "cached fragments") \ 85 _(PROCESSED_FRAGMENTS, "processed fragments") 90 #define _(sym,str) NAT64_OUT2IN_ERROR_##sym, 97 #define _(sym,string) string, 124 nat64_db_bib_entry_t *bibe;
125 nat64_db_st_entry_t *ste;
126 ip46_address_t saddr, daddr;
181 if (proto == IP_PROTOCOL_UDP)
185 checksum = &tcp->checksum;
205 nat64_db_bib_entry_t *bibe;
206 nat64_db_st_entry_t *ste;
207 ip46_address_t saddr, daddr;
221 if (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply)
223 u16 out_id = ((
u16 *) (icmp))[2];
226 IP_PROTOCOL_ICMP, fib_index, 0);
240 IP_PROTOCOL_ICMP, fib_index, 0);
247 bibe, &ip6_saddr, &saddr.ip4, 0);
263 ((
u16 *) (icmp))[2] = bibe->in_port;
286 nat64_db_bib_entry_t *bibe;
287 nat64_db_st_entry_t *ste;
288 ip46_address_t saddr, daddr;
302 if (proto == IP_PROTOCOL_ICMP6)
305 u16 out_id = ((
u16 *) (icmp))[2];
306 proto = IP_PROTOCOL_ICMP;
309 (icmp->type == ICMP6_echo_request
310 || icmp->type == ICMP6_echo_reply))
327 ((
u16 *) (icmp))[2] = bibe->in_port;
355 if (proto == IP_PROTOCOL_UDP)
358 checksum = &tcp->checksum;
378 nat64_db_bib_entry_t *bibe;
379 nat64_db_st_entry_t *ste;
380 ip46_address_t saddr, daddr;
411 bibe, &ip6_saddr, &saddr.ip4, 0);
437 u32 n_left_from, *from, *to_next;
440 u32 pkts_processed = 0;
442 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets =
446 n_left_from = frame->n_vectors;
447 next_index = node->cached_next_index;
448 while (n_left_from > 0)
454 while (n_left_from > 0 && n_left_to_next > 0)
488 b0->
error = node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
501 if (proto0 == SNAT_PROTOCOL_ICMP)
509 b0->
error = node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
515 if (proto0 == SNAT_PROTOCOL_TCP)
527 if ((proto0 == SNAT_PROTOCOL_UDP)
529 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client)))
535 b0->
error = node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
542 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
554 n_left_to_next, bi0, next0);
559 NAT64_OUT2IN_ERROR_OUT2IN_PACKETS,
562 NAT64_OUT2IN_ERROR_TCP_PACKETS, tcp_packets);
564 NAT64_OUT2IN_ERROR_UDP_PACKETS, tcp_packets);
566 NAT64_OUT2IN_ERROR_ICMP_PACKETS, icmp_packets);
568 NAT64_OUT2IN_ERROR_OTHER_PACKETS,
571 NAT64_OUT2IN_ERROR_FRAGMENTS, fragments);
573 return frame->n_vectors;
578 .name =
"nat64-out2in",
579 .vector_size =
sizeof (
u32),
610 nat64_db_st_entry_t *ste;
611 nat64_db_bib_entry_t *bibe;
629 if (ip4->
protocol == IP_PROTOCOL_UDP)
636 clib_host_to_net_u16 (ip4->
length) -
sizeof (*ip4);
642 clib_host_to_net_u16 (IP_PROTOCOL_UDP));
666 checksum = &tcp->checksum;
697 u32 n_left_from, *from, *to_next;
699 u32 pkts_processed = 0, cached_fragments = 0;
700 u32 *fragments_to_drop = 0;
701 u32 *fragments_to_loopback = 0;
706 n_left_from = frame->n_vectors;
707 next_index = node->cached_next_index;
709 while (n_left_from > 0)
715 while (n_left_from > 0 && n_left_to_next > 0)
722 u32 sw_if_index0, fib_index0;
724 nat_reass_ip4_t *reass0;
725 ip46_address_t saddr0, daddr0;
726 nat64_db_st_entry_t *ste0;
727 nat64_db_bib_entry_t *bibe0;
753 b0->
error = node->errors[NAT64_OUT2IN_ERROR_DROP_FRAGMENT];
760 || ip40->
protocol == IP_PROTOCOL_UDP)))
763 b0->
error = node->errors[NAT64_OUT2IN_ERROR_DROP_FRAGMENT];
773 1, &fragments_to_drop);
778 b0->
error = node->errors[NAT64_OUT2IN_ERROR_MAX_REASS];
804 node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
812 db, bibe0, &ip6_saddr0,
819 node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
838 (thread_index, reass0, bi0, &fragments_to_drop))
840 b0->
error = node->errors[NAT64_OUT2IN_ERROR_MAX_FRAG];
857 b0->
error = node->errors[NAT64_OUT2IN_ERROR_UNKNOWN];
864 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
885 to_next, n_left_to_next,
889 if (n_left_from == 0 &&
vec_len (fragments_to_loopback))
915 NAT64_OUT2IN_ERROR_PROCESSED_FRAGMENTS,
918 NAT64_OUT2IN_ERROR_CACHED_FRAGMENTS,
922 &node->errors[NAT64_OUT2IN_ERROR_DROP_FRAGMENT],
927 return frame->n_vectors;
932 .name =
"nat64-out2in-reass",
933 .vector_size =
sizeof (
u32),
949 #define foreach_nat64_out2in_handoff_error \ 950 _(CONGESTION_DROP, "congestion drop") \ 951 _(SAME_WORKER, "same worker") \ 952 _(DO_HANDOFF, "do handoff") 956 #define _(sym,str) NAT64_OUT2IN_HANDOFF_ERROR_##sym, 963 #define _(sym,string) string, 993 u32 n_enq, n_left_from, *from;
997 u32 do_handoff = 0, same_worker = 0;
1000 n_left_from = frame->n_vectors;
1004 ti = thread_indices;
1008 while (n_left_from > 0)
1015 if (ti[0] != thread_index)
1022 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
1036 frame->n_vectors, 1);
1038 if (n_enq < frame->n_vectors)
1040 NAT64_OUT2IN_HANDOFF_ERROR_CONGESTION_DROP,
1041 frame->n_vectors - n_enq);
1043 NAT64_OUT2IN_HANDOFF_ERROR_SAME_WORKER,
1046 NAT64_OUT2IN_HANDOFF_ERROR_DO_HANDOFF,
1049 return frame->n_vectors;
1054 .name =
"nat64-out2in-handoff",
1055 .vector_size =
sizeof (
u32),
nat64_out2in_handoff_error_t
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
nat64_db_t * db
BIB and session DB per thread.
int nat_ip4_reass_add_fragment(u32 thread_index, nat_reass_ip4_t *reass, u32 bi, u32 **bi_to_drop)
Cache fragment.
static char * nat64_out2in_error_strings[]
struct nat64_out2in_frag_set_ctx_t_ nat64_out2in_frag_set_ctx_t
#define clib_memcpy_fast(a, b, c)
u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto, u32 sw_if_index)
Get the index of the FIB bound to the interface.
nat64_db_bib_entry_t * nat64_db_bib_entry_find(nat64_db_t *db, ip46_address_t *addr, u16 port, u8 proto, u32 fib_index, u8 is_ip6)
Find NAT64 BIB entry.
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
static ip_csum_t ip_csum_with_carry(ip_csum_t sum, ip_csum_t x)
static int nat64_out2in_tcp_udp_set_cb(ip4_header_t *ip4, ip6_header_t *ip6, void *arg)
#define VLIB_NODE_FN(node)
nat64_db_st_entry_t * nat64_db_st_entry_by_index(nat64_db_t *db, u8 proto, u32 ste_index)
Get ST entry by index and protocol.
static u8 * format_nat64_out2in_reass_trace(u8 *s, va_list *args)
vlib_node_registration_t nat64_out2in_reass_node
(constructor) VLIB_REGISTER_NODE (nat64_out2in_reass_node)
struct _tcp_header tcp_header_t
struct nat64_out2in_set_ctx_t_ nat64_out2in_set_ctx_t
IPv4 to IPv6 translation.
vlib_node_registration_t nat64_out2in_handoff_node
(constructor) VLIB_REGISTER_NODE (nat64_out2in_handoff_node)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static int ip4_is_fragment(const ip4_header_t *i)
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
nat64_db_st_entry_t * nat64_db_st_entry_create(u32 thread_index, nat64_db_t *db, nat64_db_bib_entry_t *bibe, ip6_address_t *in_r_addr, ip4_address_t *out_r_addr, u16 r_port)
Create new NAT64 session table entry.
static void * ip4_next_header(ip4_header_t *i)
void nat64_tcp_session_set_state(nat64_db_st_entry_t *ste, tcp_header_t *tcp, u8 is_ip6)
Set NAT64 TCP session state.
vlib_error_t error
Error code for buffers to be enqueued to error handler.
u32 nat64_get_worker_out2in(ip4_header_t *ip)
Get worker thread index for NAT64 out2in.
void nat64_session_reset_timeout(nat64_db_st_entry_t *ste, vlib_main_t *vm)
Reset NAT64 session timeout.
#define foreach_nat64_out2in_handoff_error
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static char * nat64_out2in_handoff_error_strings[]
static int nat64_out2in_icmp_set_cb(ip4_header_t *ip4, ip6_header_t *ip6, void *arg)
static u8 * format_nat64_out2in_trace(u8 *s, va_list *args)
static void vlib_set_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 value)
Set a simple counter.
#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).
void nat64_compose_ip6(ip6_address_t *ip6, ip4_address_t *ip4, u32 fib_index)
Compose IPv4-embedded IPv6 addresses.
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
vlib_simple_counter_main_t total_sessions
#define VLIB_REGISTER_NODE(x,...)
static u8 * format_nat64_out2in_handoff_trace(u8 *s, va_list *args)
u8 nat_reass_is_drop_frag(u8 is_ip6)
Get status of virtual fragmentation reassembly.
static int ip4_to_ip6_tcp_udp(vlib_buffer_t *p, ip4_to_ip6_set_fn_t fn, void *ctx)
Translate IPv4 UDP/TCP packet to IPv6.
#define vec_free(V)
Free vector's memory (no header).
static ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
u32 out2in_reass_node_index
static int nat64_out2in_frag_set_cb(ip4_header_t *ip4, ip6_header_t *ip6, void *arg)
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.
static int nat64_out2in_inner_icmp_set_cb(ip4_header_t *ip4, ip6_header_t *ip6, void *arg)
nat64_db_st_entry_t * nat64_db_st_entry_find(nat64_db_t *db, ip46_address_t *l_addr, ip46_address_t *r_addr, u16 l_port, u16 r_port, u8 proto, u32 fib_index, u8 is_ip6)
Find NAT64 session table entry.
u32 nat64_db_st_entry_get_index(nat64_db_t *db, nat64_db_st_entry_t *ste)
static ip_csum_t ip_csum_sub_even(ip_csum_t c, ip_csum_t x)
nat64_db_bib_entry_t * nat64_db_bib_entry_by_index(nat64_db_t *db, u8 proto, u32 bibe_index)
Get BIB entry by index and protocol.
static int icmp_to_icmp6(vlib_buffer_t *p, ip4_to_ip6_set_fn_t fn, void *ctx, ip4_to_ip6_set_fn_t inner_fn, void *inner_ctx)
Translate ICMP4 packet to ICMP6.
vlib_node_registration_t nat64_out2in_node
(constructor) VLIB_REGISTER_NODE (nat64_out2in_node)
#define u8_ptr_add(ptr, index)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
static int nat64_out2in_unk_proto_set_cb(ip4_header_t *ip4, ip6_header_t *ip6, void *arg)
NAT64 global declarations.
static int ip4_is_first_fragment(const ip4_header_t *i)
static u32 ip_proto_to_snat_proto(u8 ip_proto)
The NAT inline functions.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
VLIB buffer representation.
static int ip4_to_ip6_fragmented(vlib_buffer_t *p, ip4_to_ip6_set_fn_t fn, void *ctx)
Translate IPv4 fragmented packet to IPv6.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
nat_reass_ip4_t * nat_ip4_reass_find_or_create(ip4_address_t src, ip4_address_t dst, u16 frag_id, u8 proto, u8 reset_timeout, u32 **bi_to_drop)
Find or create reassembly.
static_always_inline u32 vlib_buffer_enqueue_to_thread(vlib_main_t *vm, u32 frame_queue_index, u32 *buffer_indices, u16 *thread_indices, u32 n_packets, int drop_on_congestion)
static int ip4_to_ip6(vlib_buffer_t *p, ip4_to_ip6_set_fn_t fn, void *ctx)
Translate IPv4 packet to IPv6 (IP header only).
static void nat_send_all_to_node(vlib_main_t *vm, u32 *bi_vector, vlib_node_runtime_t *node, vlib_error_t *error, u32 next)
void nat_ip4_reass_get_frags(nat_reass_ip4_t *reass, u32 **bi)
Get cached fragments.
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.
NAT plugin virtual fragmentation reassembly.
#define VLIB_NODE_FLAG_TRACE
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)
#define foreach_nat64_out2in_error
static ip_csum_t ip_csum_add_even(ip_csum_t c, ip_csum_t x)