46 #define foreach_nat64_out2in_error \ 47 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \ 48 _(NO_TRANSLATION, "no translation") \ 53 #define _(sym,str) NAT64_OUT2IN_ERROR_##sym, 60 #define _(sym,string) string, 93 nat64_db_bib_entry_t *bibe;
94 nat64_db_st_entry_t *ste;
97 ip6_address_t ip6_saddr;
110 if (ip4->
protocol == IP_PROTOCOL_UDP)
118 clib_host_to_net_u16 (ip4->
length) -
sizeof (*ip4);
124 clib_host_to_net_u16 (IP_PROTOCOL_UDP));
132 checksum = &tcp->checksum;
145 sizeof (*ip4) -
sizeof (*ip6) -
148 (ip6_frag_hdr_t *)
u8_ptr_add (ip4,
sizeof (*ip4) -
sizeof (*frag));
154 ip6 = (
ip6_header_t *) (((
u8 *) ip4) +
sizeof (*ip4) -
sizeof (*ip6));
160 clib_host_to_net_u32 ((6 << 28) + (ip4->
tos << 20));
201 ip6->
src_address.as_u64[0] = ste->in_r_addr.as_u64[0];
202 ip6->
src_address.as_u64[1] = ste->in_r_addr.as_u64[1];
204 ip6->
dst_address.as_u64[0] = bibe->in_addr.as_u64[0];
205 ip6->
dst_address.as_u64[1] = bibe->in_addr.as_u64[1];
214 frag->identification = frag_id;
216 frag->fragment_offset_and_more =
218 ip6->
protocol = IP_PROTOCOL_IPV6_FRAGMENTATION;
226 if (proto == IP_PROTOCOL_TCP)
251 nat64_db_bib_entry_t *bibe;
252 nat64_db_st_entry_t *ste;
253 ip46_address_t saddr, daddr;
254 ip6_address_t ip6_saddr;
267 if (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply)
269 u16 out_id = ((
u16 *) (icmp))[2];
272 IP_PROTOCOL_ICMP, fib_index, 0);
286 IP_PROTOCOL_ICMP, fib_index, 0);
293 bibe, &ip6_saddr, &saddr.ip4, 0);
304 ip6->
src_address.as_u64[0] = ste->in_r_addr.as_u64[0];
305 ip6->
src_address.as_u64[1] = ste->in_r_addr.as_u64[1];
307 ip6->
dst_address.as_u64[0] = bibe->in_addr.as_u64[0];
308 ip6->
dst_address.as_u64[1] = bibe->in_addr.as_u64[1];
309 ((
u16 *) (icmp))[2] = bibe->in_port;
332 nat64_db_bib_entry_t *bibe;
333 nat64_db_st_entry_t *ste;
334 ip46_address_t saddr, daddr;
348 if (proto == IP_PROTOCOL_ICMP6)
351 u16 out_id = ((
u16 *) (icmp))[2];
352 proto = IP_PROTOCOL_ICMP;
355 (icmp->type == ICMP6_echo_request
356 || icmp->type == ICMP6_echo_reply))
369 ip6->
dst_address.as_u64[0] = ste->in_r_addr.as_u64[0];
370 ip6->
dst_address.as_u64[1] = ste->in_r_addr.as_u64[1];
371 ip6->
src_address.as_u64[0] = bibe->in_addr.as_u64[0];
372 ip6->
src_address.as_u64[1] = bibe->in_addr.as_u64[1];
373 ((
u16 *) (icmp))[2] = bibe->in_port;
397 ip6->
src_address.as_u64[0] = bibe->in_addr.as_u64[0];
398 ip6->
src_address.as_u64[1] = bibe->in_addr.as_u64[1];
401 if (proto == IP_PROTOCOL_UDP)
404 checksum = &tcp->checksum;
424 ip6_frag_hdr_t *frag;
428 nat64_db_bib_entry_t *bibe;
429 nat64_db_st_entry_t *ste;
430 ip46_address_t saddr, daddr;
431 ip6_address_t ip6_saddr;
442 sizeof (*ip4) -
sizeof (*ip6) -
445 (ip6_frag_hdr_t *)
u8_ptr_add (ip4,
sizeof (*ip4) -
sizeof (*frag));
451 ip6 = (
ip6_header_t *) (((
u8 *) ip4) +
sizeof (*ip4) -
sizeof (*ip6));
457 clib_host_to_net_u32 ((6 << 28) + (ip4->
tos << 20));
465 frag->identification = frag_id;
467 frag->fragment_offset_and_more =
469 ip6->
protocol = IP_PROTOCOL_IPV6_FRAGMENTATION;
498 bibe, &ip6_saddr, &saddr.ip4, 0);
509 ip6->
src_address.as_u64[0] = ste->in_r_addr.as_u64[0];
510 ip6->
src_address.as_u64[1] = ste->in_r_addr.as_u64[1];
512 ip6->
dst_address.as_u64[0] = bibe->in_addr.as_u64[0];
513 ip6->
dst_address.as_u64[1] = bibe->in_addr.as_u64[1];
524 u32 n_left_from, *from, *to_next;
530 n_left_from =
frame->n_vectors;
531 next_index =
node->cached_next_index;
532 while (n_left_from > 0)
538 while (n_left_from > 0 && n_left_to_next > 0)
573 b0->
error =
node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
576 thread_index, sw_if_index0, 1);
580 if (proto0 == NAT_PROTOCOL_ICMP)
583 thread_index, sw_if_index0, 1);
589 b0->
error =
node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
595 if (proto0 == NAT_PROTOCOL_TCP)
597 thread_index, sw_if_index0, 1);
600 thread_index, sw_if_index0, 1);
609 if ((proto0 == NAT_PROTOCOL_UDP)
611 clib_host_to_net_u16 (UDP_DST_PORT_dhcp_to_client)))
617 b0->
error =
node->errors[NAT64_OUT2IN_ERROR_NO_TRANSLATION];
624 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
635 thread_index, sw_if_index0, 1);
640 n_left_to_next, bi0, next0);
644 return frame->n_vectors;
649 .name =
"nat64-out2in",
650 .vector_size =
sizeof (
u32),
675 #define foreach_nat64_out2in_handoff_error \ 676 _(CONGESTION_DROP, "congestion drop") \ 677 _(SAME_WORKER, "same worker") \ 678 _(DO_HANDOFF, "do handoff") 682 #define _(sym,str) NAT64_OUT2IN_HANDOFF_ERROR_##sym, 689 #define _(sym,string) string, 719 u32 n_enq, n_left_from, *from;
723 u32 do_handoff = 0, same_worker = 0;
726 n_left_from =
frame->n_vectors;
734 while (n_left_from > 0)
741 if (ti[0] != thread_index)
748 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
762 frame->n_vectors, 1);
764 if (n_enq < frame->n_vectors)
766 NAT64_OUT2IN_HANDOFF_ERROR_CONGESTION_DROP,
767 frame->n_vectors - n_enq);
769 NAT64_OUT2IN_HANDOFF_ERROR_SAME_WORKER,
772 NAT64_OUT2IN_HANDOFF_ERROR_DO_HANDOFF,
775 return frame->n_vectors;
780 .name =
"nat64-out2in-handoff",
781 .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.
static char * nat64_out2in_error_strings[]
struct nat64_out2in_frag_set_ctx_t_ nat64_out2in_frag_set_ctx_t
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
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.
static ip_csum_t ip_csum_with_carry(ip_csum_t sum, ip_csum_t x)
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
#define VLIB_NODE_FN(node)
static int nat64_out2in_icmp_set_cb(vlib_buffer_t *b, ip4_header_t *ip4, ip6_header_t *ip6, void *arg)
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 u8_ptr_add(ptr, index)
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
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 u16 ip4_get_fragment_more(const ip4_header_t *i)
struct nat64_main_t::@102 counters
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.
vl_api_fib_path_type_t type
vlib_error_t error
Error code for buffers to be enqueued to error handler.
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 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
static int nat64_out2in_tcp_udp(vlib_main_t *vm, vlib_buffer_t *b, nat64_out2in_set_ctx_t *ctx)
#define VLIB_REGISTER_NODE(x,...)
static u8 * format_nat64_out2in_handoff_trace(u8 *s, va_list *args)
static u16 ip4_get_fragment_offset(const ip4_header_t *i)
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_unk_proto(vlib_main_t *vm, vlib_buffer_t *p, nat64_out2in_set_ctx_t *ctx)
vlib_main_t vlib_node_runtime_t * node
struct nat64_main_t::@102::@104 out2in
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_get_worker_out2in(vlib_buffer_t *b, ip4_header_t *ip)
Get worker thread index for NAT64 out2in.
static int nat64_out2in_inner_icmp_set_cb(vlib_buffer_t *b, ip4_header_t *ip4, ip6_header_t *ip6, void *arg)
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)
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
NAT64 global declarations.
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.
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)
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define u16_net_add(u, val)
#define ip6_frag_hdr_offset_and_more(offset, more)
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
static ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
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)
vl_api_interface_index_t sw_if_index
#define foreach_nat64_out2in_error
static ip_csum_t ip_csum_add_even(ip_csum_t c, ip_csum_t x)