46 #define foreach_nat64_in2out_error \ 47 _(UNSUPPORTED_PROTOCOL, "unsupported protocol") \ 48 _(IN2OUT_PACKETS, "good in2out packets processed") \ 49 _(NO_TRANSLATION, "no translation") \ 54 #define _(sym,str) NAT64_IN2OUT_ERROR_##sym, 61 #define _(sym,string) string, 111 nat64_db_bib_entry_t *bibe;
112 nat64_db_st_entry_t *ste;
113 ip46_address_t saddr, daddr;
114 u32 sw_if_index, fib_index;
149 (fib_index, proto, &out_addr, &out_port))
154 sport, clib_host_to_net_u16 (out_port),
155 fib_index, proto, 0);
175 if (proto == SNAT_PROTOCOL_TCP)
181 checksum = &tcp->checksum;
195 nat64_db_bib_entry_t *bibe;
196 nat64_db_st_entry_t *ste;
197 ip46_address_t saddr, daddr;
198 u32 sw_if_index, fib_index;
210 if (icmp->type == ICMP4_echo_request || icmp->type == ICMP4_echo_reply)
212 u16 in_id = ((
u16 *) (icmp))[2];
215 SNAT_PROTOCOL_ICMP, fib_index, 1);
229 SNAT_PROTOCOL_ICMP, fib_index, 1);
236 (fib_index, SNAT_PROTOCOL_ICMP, &out_addr, &out_id))
242 clib_host_to_net_u16 (out_id),
243 fib_index, SNAT_PROTOCOL_ICMP, 0);
259 ((
u16 *) (icmp))[2] = bibe->out_port;
281 nat64_db_st_entry_t *ste;
282 nat64_db_bib_entry_t *bibe;
283 ip46_address_t saddr, daddr;
284 u32 sw_if_index, fib_index;
296 if (proto == SNAT_PROTOCOL_ICMP)
299 u16 in_id = ((
u16 *) (icmp))[2];
302 (icmp->type == ICMP4_echo_request
303 || icmp->type == ICMP4_echo_reply))
317 ((
u16 *) (icmp))[2] = bibe->out_port;
344 if (proto == SNAT_PROTOCOL_TCP)
345 checksum = &tcp->checksum;
361 nat64_db_bib_entry_t *bibe;
362 nat64_db_st_entry_t *ste;
363 ip46_address_t saddr, daddr;
364 u32 sw_if_index, fib_index;
382 if (proto == SNAT_PROTOCOL_UDP)
385 checksum = &tcp->checksum;
414 (fib_index, proto, &out_addr, &out_port))
419 sport, clib_host_to_net_u16 (out_port),
420 fib_index, proto, 0);
435 sport = udp->
src_port = bibe->out_port;
438 memset (&saddr, 0,
sizeof (saddr));
439 memset (&daddr, 0,
sizeof (daddr));
440 saddr.ip4.as_u32 = bibe->out_addr.as_u32;
441 daddr.ip4.as_u32 = ste->out_r_addr.as_u32;
485 nat64_db_bib_entry_t *bibe;
486 nat64_db_st_entry_t *ste;
489 ip46_address_t saddr, daddr;
490 u32 sw_if_index, fib_index;
494 u16 *checksum, sport, dport;
497 if (icmp->type == ICMP6_echo_request || icmp->type == ICMP6_echo_reply)
504 if (proto == SNAT_PROTOCOL_ICMP)
522 if (proto == SNAT_PROTOCOL_UDP)
525 checksum = &tcp->checksum;
544 dport = udp->
dst_port = bibe->out_port;
547 memset (&saddr, 0,
sizeof (saddr));
548 memset (&daddr, 0,
sizeof (daddr));
549 saddr.ip4.as_u32 = ste->out_r_addr.as_u32;
550 daddr.ip4.as_u32 = bibe->out_addr.as_u32;
600 u32 n_left_from, *from, *to_next;
602 u32 pkts_processed = 0;
608 while (n_left_from > 0)
614 while (n_left_from > 0 && n_left_to_next > 0)
620 u16 l4_offset0, frag_offset0;
647 b0->
error = node->
errors[NAT64_IN2OUT_ERROR_UNKNOWN];
656 node->
errors[NAT64_IN2OUT_ERROR_UNSUPPORTED_PROTOCOL];
660 if (proto0 == SNAT_PROTOCOL_ICMP)
669 node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
679 b0->
error = node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
692 node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
701 b0->
error = node->
errors[NAT64_IN2OUT_ERROR_NO_TRANSLATION];
720 n_left_to_next, bi0, next0);
725 NAT64_IN2OUT_ERROR_IN2OUT_PACKETS,
733 .vector_size =
sizeof (
u32),
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.
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, snat_protocol_t proto, u8 is_static)
Create new NAT64 BIB entry.
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.
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.
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
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, snat_protocol_t proto, u32 fib_index, u8 is_ip6)
Find NAT64 session table entry.
#define static_always_inline
ip_csum_t ip_incremental_checksum(ip_csum_t sum, void *_data, uword n_bytes)
nat64_db_bib_entry_t * nat64_db_bib_entry_find(nat64_db_t *db, ip46_address_t *addr, u16 port, snat_protocol_t proto, u32 fib_index, u8 is_ip6)
Find NAT64 BIB entry.
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.
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 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).
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)
nat64_db_bib_entry_t * nat64_db_bib_entry_by_index(nat64_db_t *db, snat_protocol_t proto, u32 bibe_index)
Get BIB entry by index and protocol.
static int nat64_in2out_tcp_udp_set_cb(ip6_header_t *ip6, ip4_header_t *ip4, void *arg)
#define VLIB_BUFFER_IS_TRACED
static int nat64_in2out_tcp_udp_hairpinning(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6)
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)
static ip_csum_t ip_csum_sub_even(ip_csum_t c, ip_csum_t x)
#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 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 u32 ip_proto_to_snat_proto(u8 ip_proto)
#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_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)
static ip_csum_t ip_csum_add_even(ip_csum_t c, ip_csum_t x)