39 tag = t->
is_slow_path ?
"NAT64-in2out-slowpath" :
"NAT64-in2out";
51 #define foreach_nat64_in2out_error \ 52 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \ 53 _(IN2OUT_PACKETS, "good in2out packets processed") \ 54 _(NO_TRANSLATION, "no translation") \ 59 #define _(sym,str) NAT64_IN2OUT_ERROR_##sym, 66 #define _(sym,string) string, 117 nat64_db_bib_entry_t *bibe;
118 nat64_db_st_entry_t *ste;
119 ip46_address_t saddr, daddr;
120 u32 sw_if_index, fib_index;
161 sport, clib_host_to_net_u16 (out_port),
162 fib_index, proto, 0);
182 if (proto == IP_PROTOCOL_TCP)
188 checksum = &tcp->checksum;
202 nat64_db_bib_entry_t *bibe;
203 nat64_db_st_entry_t *ste;
204 ip46_address_t saddr, daddr;
205 u32 sw_if_index, fib_index;
217 if (icmp->type == ICMP4_echo_request || icmp->type == ICMP4_echo_reply)
219 u16 in_id = ((
u16 *) (icmp))[2];
222 IP_PROTOCOL_ICMP, fib_index, 1);
236 IP_PROTOCOL_ICMP, fib_index, 1);
243 (fib_index, SNAT_PROTOCOL_ICMP, &out_addr, &out_id))
249 clib_host_to_net_u16 (out_id),
250 fib_index, IP_PROTOCOL_ICMP, 0);
266 ((
u16 *) (icmp))[2] = bibe->out_port;
288 nat64_db_st_entry_t *ste;
289 nat64_db_bib_entry_t *bibe;
290 ip46_address_t saddr, daddr;
291 u32 sw_if_index, fib_index;
303 if (proto == IP_PROTOCOL_ICMP6)
306 u16 in_id = ((
u16 *) (icmp))[2];
307 proto = IP_PROTOCOL_ICMP;
310 (icmp->type == ICMP4_echo_request
311 || icmp->type == ICMP4_echo_reply))
325 ((
u16 *) (icmp))[2] = bibe->out_port;
352 if (proto == IP_PROTOCOL_TCP)
353 checksum = &tcp->checksum;
378 nat64_db_bib_entry_t *bibe;
379 ip46_address_t saddr, daddr;
391 memset (&saddr, 0,
sizeof (saddr));
392 saddr.ip4.as_u32 = bibe->out_addr.as_u32;
393 memset (&daddr, 0,
sizeof (daddr));
414 nat64_db_bib_entry_t *bibe;
415 nat64_db_st_entry_t *ste;
416 ip46_address_t saddr, daddr,
addr;
417 u32 sw_if_index, fib_index;
453 .out_addr.as_u32 = 0,
454 .fib_index = fib_index,
466 memset (&addr, 0,
sizeof (addr));
477 (&nm->
db, &addr, 0, proto, 0, 0))
487 &ctx.
out_addr, 0, 0, fib_index, proto,
516 nat64_db_bib_entry_t *bibe;
517 nat64_db_st_entry_t *ste;
518 ip46_address_t saddr, daddr;
519 u32 sw_if_index, fib_index;
537 if (proto == IP_PROTOCOL_UDP)
540 checksum = &tcp->checksum;
575 sport, clib_host_to_net_u16 (out_port),
576 fib_index, proto, 0);
591 sport = udp->
src_port = bibe->out_port;
594 memset (&saddr, 0,
sizeof (saddr));
595 memset (&daddr, 0,
sizeof (daddr));
596 saddr.ip4.as_u32 = bibe->out_addr.as_u32;
597 daddr.ip4.as_u32 = ste->out_r_addr.as_u32;
641 nat64_db_bib_entry_t *bibe;
642 nat64_db_st_entry_t *ste;
645 ip46_address_t saddr, daddr;
646 u32 sw_if_index, fib_index;
650 u16 *checksum, sport, dport;
653 if (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply)
660 if (proto == IP_PROTOCOL_ICMP6)
678 if (proto == IP_PROTOCOL_UDP)
681 checksum = &tcp->checksum;
700 dport = udp->
dst_port = bibe->out_port;
703 memset (&saddr, 0,
sizeof (saddr));
704 memset (&daddr, 0,
sizeof (daddr));
705 saddr.ip4.as_u32 = ste->out_r_addr.as_u32;
706 daddr.ip4.as_u32 = bibe->out_addr.as_u32;
757 nat64_db_bib_entry_t *bibe;
758 nat64_db_st_entry_t *ste;
759 ip46_address_t saddr, daddr,
addr;
760 u32 sw_if_index, fib_index;
796 .out_addr.as_u32 = 0,
797 .fib_index = fib_index,
809 memset (&addr, 0,
sizeof (addr));
820 (&nm->
db, &addr, 0, proto, 0, 0))
830 &ctx.
out_addr, 0, 0, fib_index, proto,
848 memset (&saddr, 0,
sizeof (saddr));
849 memset (&daddr, 0,
sizeof (daddr));
850 saddr.ip4.as_u32 = bibe->out_addr.as_u32;
851 daddr.ip4.as_u32 = ste->out_r_addr.as_u32;
883 u32 n_left_from, *from, *to_next;
885 u32 pkts_processed = 0;
886 u32 stats_node_index;
895 while (n_left_from > 0)
901 while (n_left_from > 0 && n_left_to_next > 0)
907 u16 l4_offset0, frag_offset0;
934 b0->
error = node->
errors[NAT64_IN2OUT_ERROR_UNKNOWN];
939 if (frag_offset0 != 0)
943 node->
errors[NAT64_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
958 node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
967 node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
982 if (proto0 == SNAT_PROTOCOL_ICMP)
991 node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1001 b0->
error = node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1005 else if (proto0 == SNAT_PROTOCOL_TCP || proto0 == SNAT_PROTOCOL_UDP)
1014 node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1023 b0->
error = node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
1043 n_left_to_next, bi0, next0);
1048 NAT64_IN2OUT_ERROR_IN2OUT_PACKETS,
1063 .name =
"nat64-in2out",
1064 .vector_size =
sizeof (
u32),
1092 .name =
"nat64-in2out-slowpath",
1093 .vector_size =
sizeof (
u32),
static int unk_proto_st_walk(nat64_db_st_entry_t *ste, void *arg)
sll srl srl sll sra u16x4 i
int nat64_alloc_out_addr_and_port(u32 fib_index, snat_protocol_t proto, ip4_address_t *addr, u16 *port)
Alloce IPv4 address and port pair from NAT64 pool.
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)
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.
nat64_db_bib_entry_t * nat64_db_bib_entry_create(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.
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.
struct _vlib_node_registration vlib_node_registration_t
static ip_csum_t ip_csum_with_carry(ip_csum_t sum, ip_csum_t x)
static u8 * format_nat64_in2out_trace(u8 *s, va_list *args)
vlib_error_t * errors
Vector of errors for this node.
static int nat64_in2out_icmp_hairpinning(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6)
struct _tcp_header tcp_header_t
#define static_always_inline
ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
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
nat64_db_t db
BIB and session DB.
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.
u16 current_length
Nbytes between current data and the end of this buffer.
void nat64_session_reset_timeout(nat64_db_st_entry_t *ste, vlib_main_t *vm)
Reset NAT64 session timeout.
static uword nat64_in2out_slowpath_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static int nat64_in2out_inner_icmp_set_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
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).
static int nat64_in2out_unk_proto_hairpinning(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6)
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 int nat64_in2out_icmp_set_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
static int nat64_in2out_tcp_udp_set_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
#define VLIB_BUFFER_IS_TRACED
vlib_node_registration_t nat64_in2out_slowpath_node
(constructor) VLIB_REGISTER_NODE (nat64_in2out_slowpath_node)
static int nat64_in2out_tcp_udp_hairpinning(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6)
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)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
#define u8_ptr_add(ptr, index)
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.
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 u32 ip_proto_to_snat_proto(u8 ip_proto)
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.
#define VLIB_NODE_FLAG_TRACE
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.
VLIB_NODE_FUNCTION_MULTIARCH(nat64_in2out_node, nat64_in2out_node_fn)
#define ip46_address_is_equal(a1, a2)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
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)
#define VLIB_REGISTER_NODE(x,...)
static_always_inline int is_hairpinning(ip6_address_t *dst_addr)
Check whether is a hairpinning.
static uword nat64_in2out_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
u16 flags
Copy of main node flags.
#define foreach_nat64_in2out_error
struct nat64_in2out_set_ctx_t_ nat64_in2out_set_ctx_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.
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)
static ip_csum_t ip_csum_add_even(ip_csum_t c, ip_csum_t x)