63 format (s,
"NAT64-out2in-reass: sw_if_index %d, next index %d, status %s",
65 t->
cached ?
"cached" :
"translated");
74 #define foreach_nat64_out2in_error \ 75 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 76 _(OUT2IN_PACKETS, "Good out2in packets processed") \ 77 _(NO_TRANSLATION, "No translation") \ 78 _(UNKNOWN, "unknown") \ 79 _(DROP_FRAGMENT, "Drop fragment") \ 80 _(MAX_REASS, "Maximum reassemblies exceeded") \ 81 _(MAX_FRAG, "Maximum fragments per reassembly exceeded") 86 #define _(sym,str) NAT64_OUT2IN_ERROR_##sym, 93 #define _(sym,string) string, 120 nat64_db_bib_entry_t *bibe;
121 nat64_db_st_entry_t *ste;
122 ip46_address_t saddr, daddr;
129 u32 sw_if_index, fib_index;
137 memset (&saddr, 0,
sizeof (saddr));
139 memset (&daddr, 0,
sizeof (daddr));
172 if (proto == IP_PROTOCOL_UDP)
175 checksum = &tcp->checksum;
190 nat64_db_bib_entry_t *bibe;
191 nat64_db_st_entry_t *ste;
192 ip46_address_t saddr, daddr;
194 u32 sw_if_index, fib_index;
201 memset (&saddr, 0,
sizeof (saddr));
203 memset (&daddr, 0,
sizeof (daddr));
206 if (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply)
208 u16 out_id = ((
u16 *) (icmp))[2];
211 IP_PROTOCOL_ICMP, fib_index, 0);
225 IP_PROTOCOL_ICMP, fib_index, 0);
241 ((
u16 *) (icmp))[2] = bibe->in_port;
264 nat64_db_bib_entry_t *bibe;
265 nat64_db_st_entry_t *ste;
266 ip46_address_t saddr, daddr;
267 u32 sw_if_index, fib_index;
275 memset (&saddr, 0,
sizeof (saddr));
277 memset (&daddr, 0,
sizeof (daddr));
280 if (proto == IP_PROTOCOL_ICMP6)
283 u16 out_id = ((
u16 *) (icmp))[2];
284 proto = IP_PROTOCOL_ICMP;
287 (icmp->type == ICMP6_echo_request
288 || icmp->type == ICMP6_echo_reply))
305 ((
u16 *) (icmp))[2] = bibe->in_port;
333 if (proto == IP_PROTOCOL_UDP)
336 checksum = &tcp->checksum;
356 nat64_db_bib_entry_t *bibe;
357 nat64_db_st_entry_t *ste;
358 ip46_address_t saddr, daddr;
360 u32 sw_if_index, fib_index;
367 memset (&saddr, 0,
sizeof (saddr));
369 memset (&daddr, 0,
sizeof (daddr));
408 u32 n_left_from, *from, *to_next;
410 u32 pkts_processed = 0;
416 while (n_left_from > 0)
422 while (n_left_from > 0 && n_left_to_next > 0)
456 b0->
error = node->
errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
467 if (proto0 == SNAT_PROTOCOL_ICMP)
474 b0->
error = node->
errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
487 if ((proto0 == SNAT_PROTOCOL_UDP)
489 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client)))
495 b0->
error = node->
errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
502 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
514 n_left_to_next, bi0, next0);
519 NAT64_OUT2IN_ERROR_OUT2IN_PACKETS,
527 .name =
"nat64-out2in",
528 .vector_size =
sizeof (
u32),
561 nat64_db_st_entry_t *ste;
562 nat64_db_bib_entry_t *bibe;
582 if (ip4->
protocol == IP_PROTOCOL_UDP)
589 clib_host_to_net_u16 (ip4->
length) -
sizeof (*ip4);
595 clib_host_to_net_u16 (IP_PROTOCOL_UDP));
618 checksum = &tcp->checksum;
647 u32 n_left_from, *from, *to_next;
649 u32 pkts_processed = 0;
650 u32 *fragments_to_drop = 0;
651 u32 *fragments_to_loopback = 0;
659 while (n_left_from > 0)
665 while (n_left_from > 0 && n_left_to_next > 0)
672 u32 sw_if_index0, fib_index0;
674 nat_reass_ip4_t *reass0;
675 ip46_address_t saddr0, daddr0;
676 nat64_db_st_entry_t *ste0;
677 nat64_db_bib_entry_t *bibe0;
703 b0->
error = node->
errors[NAT64_OUT2IN_ERROR_DROP_FRAGMENT];
710 || ip40->
protocol == IP_PROTOCOL_UDP)))
713 b0->
error = node->
errors[NAT64_OUT2IN_ERROR_DROP_FRAGMENT];
723 1, &fragments_to_drop);
728 b0->
error = node->
errors[NAT64_OUT2IN_ERROR_MAX_REASS];
736 memset (&saddr0, 0,
sizeof (saddr0));
738 memset (&daddr0, 0,
sizeof (daddr0));
754 node->
errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
768 node->
errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
785 b0->
error = node->
errors[NAT64_OUT2IN_ERROR_MAX_FRAG];
802 b0->
error = node->
errors[NAT64_OUT2IN_ERROR_UNKNOWN];
809 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
829 to_next, n_left_to_next,
833 if (n_left_from == 0 &&
vec_len (fragments_to_loopback))
847 fragments_to_loopback + (len -
860 NAT64_OUT2IN_ERROR_OUT2IN_PACKETS,
864 &node->
errors[NAT64_OUT2IN_ERROR_DROP_FRAGMENT],
875 .name =
"nat64-out2in-reass",
876 .vector_size =
sizeof (
u32),
910 m = t->
do_handoff ?
"next worker" :
"same worker";
922 u32 n_left_from, *from, *to_next = 0, *to_next_drop = 0;
930 u32 n_left_to_next_worker = 0, *to_next_worker = 0;
931 u32 next_worker_index = 0;
932 u32 current_worker_index = ~0;
952 while (n_left_from > 0)
973 if (next_worker_index != current_worker_index)
978 congested_handoff_queue_by_worker_index);
989 to_next_drop[0] = bi0;
1001 handoff_queue_elt_by_worker_index);
1004 current_worker_index = next_worker_index;
1007 ASSERT (to_next_worker != 0);
1010 to_next_worker[0] = bi0;
1012 n_left_to_next_worker--;
1014 if (n_left_to_next_worker == 0)
1018 current_worker_index = ~0;
1019 handoff_queue_elt_by_worker_index[next_worker_index] = 0;
1041 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1060 for (i = 0; i <
vec_len (handoff_queue_elt_by_worker_index); i++)
1062 if (handoff_queue_elt_by_worker_index[i])
1064 hf = handoff_queue_elt_by_worker_index[
i];
1072 handoff_queue_elt_by_worker_index[
i] = 0;
1077 congested_handoff_queue_by_worker_index[
i] =
1081 current_worker_index = ~0;
1088 .name =
"nat64-out2in-handoff",
1089 .vector_size =
sizeof (
u32),
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
nat64_db_t * db
BIB and session DB per thread.
static char * nat64_out2in_error_strings[]
struct nat64_out2in_frag_set_ctx_t_ nat64_out2in_frag_set_ctx_t
nat64_db_st_entry_t * nat64_db_st_entry_create(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.
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.
int nat_ip4_reass_add_fragment(nat_reass_ip4_t *reass, u32 bi)
Cache fragment.
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.
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)
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.
u32 buffer_index[VLIB_FRAME_SIZE]
vlib_error_t * errors
Vector of errors for this node.
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
static vlib_frame_queue_t * is_vlib_frame_queue_congested(u32 frame_queue_index, u32 index, u32 queue_hi_thresh, vlib_frame_queue_t **handoff_queue_by_worker_index)
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.
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
static void * ip4_next_header(ip4_header_t *i)
static int ip4_is_fragment(ip4_header_t *i)
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.
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
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 vlib_frame_queue_elt_t * vlib_get_worker_handoff_queue_elt(u32 frame_queue_index, u32 vlib_worker_index, vlib_frame_queue_elt_t **handoff_queue_elt_by_worker_index)
#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.
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)
static uword nat64_out2in_handoff_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define VLIB_REGISTER_NODE(x,...)
static_always_inline uword vlib_get_thread_index(void)
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)
#define clib_memcpy(a, b, c)
static int ip4_is_first_fragment(ip4_header_t *i)
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)
static uword nat64_out2in_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
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.
VLIB_NODE_FUNCTION_MULTIARCH(nat64_out2in_node, nat64_out2in_node_fn)
static uword nat64_out2in_reass_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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)
struct _vlib_node_registration vlib_node_registration_t
static int nat64_out2in_unk_proto_set_cb(ip4_header_t *ip4, ip6_header_t *ip6, void *arg)
NAT64 global declarations.
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)
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 void vlib_put_frame_queue_elt(vlib_frame_queue_elt_t *hf)
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 vlib_thread_main_t * vlib_get_thread_main()
u16 flags
Copy of main node flags.
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.
NAT plugin virtual fragmentation reassembly.
#define VLIB_NODE_FLAG_TRACE
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
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 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)