41 tag = t->
is_slow_path ?
"NAT64-in2out-slowpath" :
"NAT64-in2out";
66 format (s,
"NAT64-in2out-reass: sw_if_index %d, next index %d, status %s",
68 t->
cached ?
"cached" :
"translated");
74 #define foreach_nat64_in2out_error \ 75 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \ 76 _(IN2OUT_PACKETS, "good in2out 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") \ 82 _(TCP_PACKETS, "TCP packets") \ 83 _(UDP_PACKETS, "UDP packets") \ 84 _(ICMP_PACKETS, "ICMP packets") \ 85 _(OTHER_PACKETS, "other protocol packets") \ 86 _(FRAGMENTS, "fragments") \ 87 _(CACHED_FRAGMENTS, "cached fragments") \ 88 _(PROCESSED_FRAGMENTS, "processed fragments") 93 #define _(sym,str) NAT64_IN2OUT_ERROR_##sym, 100 #define _(sym,string) string, 173 nat64_db_bib_entry_t *bibe;
174 nat64_db_st_entry_t *ste;
175 ip46_address_t saddr, daddr;
218 out_port, fib_index, proto, 0);
242 if (proto == IP_PROTOCOL_TCP)
249 checksum = &tcp->checksum;
266 nat64_db_bib_entry_t *bibe;
267 nat64_db_st_entry_t *ste;
268 ip46_address_t saddr, daddr;
282 if (icmp->type == ICMP4_echo_request || icmp->type == ICMP4_echo_reply)
284 u16 in_id = ((
u16 *) (icmp))[2];
287 IP_PROTOCOL_ICMP, fib_index, 1);
301 IP_PROTOCOL_ICMP, fib_index, 1);
308 (fib_index, SNAT_PROTOCOL_ICMP, &out_addr, &out_id,
315 in_id, out_id, fib_index,
316 IP_PROTOCOL_ICMP, 0);
338 ((
u16 *) (icmp))[2] = bibe->out_port;
360 nat64_db_st_entry_t *ste;
361 nat64_db_bib_entry_t *bibe;
362 ip46_address_t saddr, daddr;
376 if (proto == IP_PROTOCOL_ICMP6)
379 u16 in_id = ((
u16 *) (icmp))[2];
380 proto = IP_PROTOCOL_ICMP;
383 (icmp->type == ICMP4_echo_request
384 || icmp->type == ICMP4_echo_reply))
398 ((
u16 *) (icmp))[2] = bibe->out_port;
425 if (proto == IP_PROTOCOL_TCP)
426 checksum = &tcp->checksum;
452 nat64_db_bib_entry_t *bibe;
453 ip46_address_t saddr, daddr;
466 saddr.ip4.as_u32 = bibe->out_addr.as_u32;
488 nat64_db_bib_entry_t *bibe;
489 nat64_db_st_entry_t *ste;
490 ip46_address_t saddr, daddr,
addr;
526 .out_addr.as_u32 = 0,
527 .fib_index = fib_index,
559 0, 0, fib_index, proto, 0);
593 nat64_db_bib_entry_t *bibe;
594 nat64_db_st_entry_t *ste;
595 ip46_address_t saddr, daddr;
615 if (proto == IP_PROTOCOL_UDP)
618 checksum = &tcp->checksum;
647 &out_port, thread_index))
652 &out_addr, sport, out_port, fib_index,
672 if (proto == IP_PROTOCOL_TCP)
677 sport = udp->
src_port = bibe->out_port;
681 daddr.ip4.as_u32 = ste->out_r_addr.as_u32;
717 nat64_db_bib_entry_t *bibe;
718 nat64_db_st_entry_t *ste;
721 ip46_address_t saddr, daddr;
726 u16 *checksum, sport, dport;
730 if (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply)
737 if (proto == IP_PROTOCOL_ICMP6)
755 if (proto == IP_PROTOCOL_UDP)
758 checksum = &tcp->checksum;
777 dport = udp->
dst_port = bibe->out_port;
782 saddr.ip4.as_u32 = ste->out_r_addr.as_u32;
783 daddr.ip4.as_u32 = bibe->out_addr.as_u32;
843 nat64_db_bib_entry_t *bibe;
844 nat64_db_st_entry_t *ste;
845 ip46_address_t saddr, daddr,
addr;
881 .out_addr.as_u32 = 0,
882 .fib_index = fib_index,
913 &ctx.
out_addr, 0, 0, fib_index, proto,
938 daddr.ip4.as_u32 = ste->out_r_addr.as_u32;
964 u32 n_left_from, *from, *to_next;
966 u32 pkts_processed = 0;
967 u32 stats_node_index;
971 u32 tcp_packets = 0, udp_packets = 0, icmp_packets = 0, other_packets =
981 while (n_left_from > 0)
987 while (n_left_from > 0 && n_left_to_next > 0)
993 u16 l4_offset0, frag_offset0;
1005 n_left_to_next -= 1;
1022 b0->
error = node->
errors[NAT64_IN2OUT_ERROR_UNKNOWN];
1045 (vm, b0, ip60, thread_index))
1049 node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1058 node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1074 (ip60->
protocol == IP_PROTOCOL_IPV6_FRAGMENTATION))
1081 if (proto0 == SNAT_PROTOCOL_ICMP)
1088 (vm, b0, ip60, thread_index))
1092 node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1102 b0->
error = node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1106 else if (proto0 == SNAT_PROTOCOL_TCP || proto0 == SNAT_PROTOCOL_UDP)
1108 if (proto0 == SNAT_PROTOCOL_TCP)
1117 (vm, b0, ip60, thread_index))
1121 node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1130 b0->
error = node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1137 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1150 n_left_to_next, bi0, next0);
1155 NAT64_IN2OUT_ERROR_IN2OUT_PACKETS,
1158 NAT64_IN2OUT_ERROR_TCP_PACKETS, tcp_packets);
1160 NAT64_IN2OUT_ERROR_UDP_PACKETS, udp_packets);
1162 NAT64_IN2OUT_ERROR_ICMP_PACKETS, icmp_packets);
1164 NAT64_IN2OUT_ERROR_OTHER_PACKETS,
1167 NAT64_IN2OUT_ERROR_FRAGMENTS, fragments);
1181 .name =
"nat64-in2out",
1182 .vector_size =
sizeof (
u32),
1208 .name =
"nat64-in2out-slowpath",
1209 .vector_size =
sizeof (
u32),
1241 nat64_db_st_entry_t *ste;
1242 nat64_db_bib_entry_t *bibe;
1260 if (ctx->
proto == IP_PROTOCOL_TCP)
1267 checksum = &tcp->checksum;
1293 nat64_db_st_entry_t *ste;
1294 nat64_db_bib_entry_t *bibe;
1301 ip46_address_t daddr;
1306 if (ctx->
proto == IP_PROTOCOL_UDP)
1309 checksum = &tcp->checksum;
1327 if (ctx->
proto == IP_PROTOCOL_TCP)
1332 sport = bibe->out_port;
1333 dport = ste->r_port;
1338 daddr.ip4.as_u32 = ste->out_r_addr.as_u32;
1377 u32 n_left_from, *from, *to_next;
1379 u32 pkts_processed = 0, cached_fragments = 0;
1380 u32 *fragments_to_drop = 0;
1381 u32 *fragments_to_loopback = 0;
1386 n_left_from = frame->n_vectors;
1387 next_index = node->cached_next_index;
1389 while (n_left_from > 0)
1395 while (n_left_from > 0 && n_left_to_next > 0)
1402 u16 l4_offset0, frag_offset0;
1404 nat_reass_ip6_t *reass0;
1405 ip6_frag_hdr_t *frag0;
1406 nat64_db_bib_entry_t *bibe0;
1407 nat64_db_st_entry_t *ste0;
1410 u32 sw_if_index0, fib_index0;
1411 ip46_address_t saddr0, daddr0;
1421 n_left_to_next -= 1;
1436 b0->
error = node->errors[NAT64_IN2OUT_ERROR_DROP_FRAGMENT];
1448 b0->
error = node->errors[NAT64_IN2OUT_ERROR_UNKNOWN];
1453 (!(l4_protocol0 == IP_PROTOCOL_TCP
1454 || l4_protocol0 == IP_PROTOCOL_UDP)))
1457 b0->
error = node->errors[NAT64_IN2OUT_ERROR_DROP_FRAGMENT];
1462 frag0 = (ip6_frag_hdr_t *)
u8_ptr_add (ip60, frag_offset0);
1467 frag0->identification,
1469 1, &fragments_to_drop);
1474 b0->
error = node->errors[NAT64_IN2OUT_ERROR_MAX_REASS];
1484 (thread_index, reass0, bi0, &fragments_to_drop))
1486 b0->
error = node->errors[NAT64_IN2OUT_ERROR_MAX_FRAG];
1506 l4_protocol0, fib_index0, 1);
1511 l4_protocol0, fib_index0, 1);
1517 (fib_index0, proto0, &out_addr0, &out_port0,
1522 node->errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1530 out_port0, fib_index0,
1536 node->errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1552 node->errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1565 ctx0.
proto = l4_protocol0;
1575 b0->
error = node->errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1584 b0->
error = node->errors[NAT64_IN2OUT_ERROR_UNKNOWN];
1592 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
1613 to_next, n_left_to_next,
1617 if (n_left_from == 0 &&
vec_len (fragments_to_loopback))
1624 sizeof (
u32) * len);
1643 NAT64_IN2OUT_ERROR_PROCESSED_FRAGMENTS,
1646 NAT64_IN2OUT_ERROR_CACHED_FRAGMENTS,
1650 &node->errors[NAT64_IN2OUT_ERROR_DROP_FRAGMENT],
1655 return frame->n_vectors;
1660 .name =
"nat64-in2out-reass",
1661 .vector_size =
sizeof (
u32),
1678 #define foreach_nat64_in2out_handoff_error \ 1679 _(CONGESTION_DROP, "congestion drop") \ 1680 _(SAME_WORKER, "same worker") \ 1681 _(DO_HANDOFF, "do handoff") 1685 #define _(sym,str) NAT64_IN2OUT_HANDOFF_ERROR_##sym, 1692 #define _(sym,string) string, 1722 u32 n_enq, n_left_from, *from;
1726 u32 do_handoff = 0, same_worker = 0;
1729 n_left_from = frame->n_vectors;
1733 ti = thread_indices;
1737 while (n_left_from > 0)
1744 if (ti[0] != thread_index)
1751 && (b[0]->
flags & VLIB_BUFFER_IS_TRACED)))
1765 frame->n_vectors, 1);
1767 if (n_enq < frame->n_vectors)
1769 NAT64_IN2OUT_HANDOFF_ERROR_CONGESTION_DROP,
1770 frame->n_vectors - n_enq);
1772 NAT64_IN2OUT_HANDOFF_ERROR_SAME_WORKER,
1775 NAT64_IN2OUT_HANDOFF_ERROR_DO_HANDOFF,
1778 return frame->n_vectors;
1783 .name =
"nat64-in2out-handoff",
1784 .vector_size =
sizeof (
u32),
u32 in2out_reass_node_index
#define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
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 int unk_proto_st_walk(nat64_db_st_entry_t *ste, void *arg)
static int nat64_in2out_frag_set_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
static int nat64_in2out_frag_hairpinning(vlib_buffer_t *b, ip6_header_t *ip6, nat64_in2out_frag_set_ctx_t *ctx)
snat_address_t * addr_pool
Address pool vector.
static int icmp6_to_icmp(vlib_buffer_t *p, ip6_to_ip4_set_fn_t fn, void *ctx, ip6_to_ip4_set_fn_t inner_fn, void *inner_ctx)
Translate ICMP6 packet to ICMP4.
void nat64_extract_ip4(ip6_address_t *ip6, ip4_address_t *ip4, u32 fib_index)
Extract IPv4 address from the IPv4-embedded IPv6 addresses.
vlib_node_registration_t nat64_in2out_node
(constructor) VLIB_REGISTER_NODE (nat64_in2out_node)
#define clib_memcpy_fast(a, b, c)
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.
void nat_ip6_reass_get_frags(nat_reass_ip6_t *reass, u32 **bi)
Get cached fragments.
u16 current_length
Nbytes between current data and the end of this buffer.
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)
int nat_ip6_reass_add_fragment(u32 thread_index, nat_reass_ip6_t *reass, u32 bi, u32 **bi_to_drop)
Cache fragment.
#define VLIB_NODE_FN(node)
static u8 * format_nat64_in2out_trace(u8 *s, va_list *args)
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.
vlib_error_t * errors
Vector of errors for this node.
vlib_node_registration_t nat64_in2out_handoff_node
(constructor) VLIB_REGISTER_NODE (nat64_in2out_handoff_node)
struct _tcp_header tcp_header_t
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static int nat64_in2out_tcp_udp_hairpinning(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6, u32 thread_index)
#define u8_ptr_add(ptr, index)
u32 nat64_get_worker_in2out(ip6_address_t *addr)
Get worker thread index for NAT64 in2out.
#define static_always_inline
vl_api_interface_index_t 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.
vlib_node_registration_t nat64_in2out_reass_node
(constructor) VLIB_REGISTER_NODE (nat64_in2out_reass_node)
static_always_inline int ip6_parse(const ip6_header_t *ip6, u32 buff_len, u8 *l4_protocol, u16 *l4_offset, u16 *frag_hdr_offset)
Parse some useful information from IPv6 header.
struct unk_proto_st_walk_ctx_t_ unk_proto_st_walk_ctx_t
void nat64_tcp_session_set_state(nat64_db_st_entry_t *ste, tcp_header_t *tcp, u8 is_ip6)
Set NAT64 TCP session state.
static int ip6_to_ip4_tcp_udp(vlib_buffer_t *p, ip6_to_ip4_set_fn_t fn, void *ctx, u8 udp_checksum)
Translate IPv6 UDP/TCP packet to IPv4.
u32 in2out_slowpath_node_index
vl_api_fib_path_type_t type
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void mss_clamping(snat_main_t *sm, tcp_header_t *tcp, ip_csum_t *sum)
void nat64_session_reset_timeout(nat64_db_st_entry_t *ste, vlib_main_t *vm)
Reset NAT64 session timeout.
int nat64_alloc_out_addr_and_port(u32 fib_index, snat_protocol_t proto, ip4_address_t *addr, u16 *port, u32 thread_index)
Alloce IPv4 address and port pair from NAT64 pool.
static u8 * format_nat64_in2out_reass_trace(u8 *s, va_list *args)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
int ip6_address_compare(ip6_address_t *a1, ip6_address_t *a2)
static int nat64_in2out_inner_icmp_set_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
static void vlib_set_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 value)
Set a simple counter.
static char * nat64_in2out_error_strings[]
#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 u8 * format_nat64_in2out_handoff_trace(u8 *s, va_list *args)
#define VLIB_REGISTER_NODE(x,...)
static int nat64_in2out_unk_proto_hairpinning(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6, u32 thread_index)
static int nat64_in2out_icmp_set_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
u8 nat_reass_is_drop_frag(u8 is_ip6)
Get status of virtual fragmentation reassembly.
static int nat64_in2out_tcp_udp_set_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
#define vec_free(V)
Free vector's memory (no header).
vlib_node_registration_t nat64_in2out_slowpath_node
(constructor) VLIB_REGISTER_NODE (nat64_in2out_slowpath_node)
#define foreach_nat64_in2out_handoff_error
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 void * ip6_next_header(ip6_header_t *i)
nat64_db_bib_entry_t * nat64_db_bib_entry_create(u32 thread_index, nat64_db_t *db, ip6_address_t *in_addr, ip4_address_t *out_addr, u16 in_port, u16 out_port, u32 fib_index, u8 proto, u8 is_static)
Create new NAT64 BIB entry.
#define ip6_frag_hdr_offset(hdr)
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.
nat64_in2out_handoff_error_t
void nat64_db_st_walk(nat64_db_t *db, u8 proto, nat64_db_st_walk_fn_t fn, void *ctx)
Walk NAT64 session table.
static int nat64_in2out_icmp_hairpinning(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6, u32 thread_index)
ip_lookup_main_t lookup_main
u32 fq_in2out_index
Worker handoff.
u32 nat64_db_st_entry_get_index(nat64_db_t *db, nat64_db_st_entry_t *ste)
static u8 nat64_not_translate(u32 sw_if_index, ip6_address_t ip6_addr)
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.
IPv6 to IPv4 translation.
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
NAT64 global declarations.
static u32 ip_proto_to_snat_proto(u8 ip_proto)
static char * nat64_in2out_handoff_error_strings[]
#define ip46_address_is_equal(a1, a2)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
VLIB buffer representation.
nat_reass_ip6_t * nat_ip6_reass_find_or_create(ip6_address_t src, ip6_address_t dst, u32 frag_id, u8 proto, u8 reset_timeout, u32 **bi_to_drop)
Find or create reassembly.
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)
static uword nat64_in2out_node_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, u8 is_slow_path)
static int nat64_in2out_unk_proto_set_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
static_always_inline int is_hairpinning(ip6_address_t *dst_addr)
Check whether is a hairpinning.
#define vec_foreach(var, vec)
Vector iterator.
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)
static void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
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
#define foreach_nat64_in2out_error
struct nat64_in2out_set_ctx_t_ nat64_in2out_set_ctx_t
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 int ip6_to_ip4(vlib_buffer_t *p, ip6_to_ip4_set_fn_t fn, void *ctx)
Translate IPv6 packet to IPv4 (IP header only).
static u16 ip_csum_fold(ip_csum_t c)
struct nat64_in2out_frag_set_ctx_t_ nat64_in2out_frag_set_ctx_t
static ip_csum_t ip_csum_add_even(ip_csum_t c, ip_csum_t x)
vl_api_fib_path_nh_proto_t proto
vlib_simple_counter_main_t total_bibs
static int ip6_to_ip4_fragmented(vlib_buffer_t *p, ip6_to_ip4_set_fn_t fn, void *ctx)
Translate IPv6 fragmented packet to IPv4.