34 .arc_name =
"ip6-unicast",
35 .node_name =
"nat64-in2out",
39 .arc_name =
"ip4-unicast",
40 .node_name =
"nat64-out2in",
44 .arc_name =
"ip6-unicast",
45 .node_name =
"nat64-in2out-handoff",
49 .arc_name =
"ip4-unicast",
50 .node_name =
"nat64-out2in-handoff",
56 0x00, 0x64, 0xff, 0x9b,
57 0x00, 0x00, 0x00, 0x00,
58 0x00, 0x00, 0x00, 0x00,
59 0x00, 0x00, 0x00, 0x00
69 u32 if_address_index,
u32 is_delete)
105 #ifdef clib_crc32c_uses_intrinsics 106 hash = clib_crc32c ((
u8 *) addr->
as_u32, 16);
113 next_worker_index += sm->
workers[hash & (_vec_len (sm->
workers) - 1)];
117 return next_worker_index;
141 nat_reass_ip4_t *reass;
146 if (reass && (reass->thread_index != (
u32) ~ 0))
147 return reass->thread_index;
157 ip46_address_t daddr;
158 nat64_db_bib_entry_t *bibe;
160 memset (&daddr, 0,
sizeof (daddr));
168 return (
u32) (db - nm->
db);
177 icmp46_header_t *icmp = (icmp46_header_t *) udp;
188 case SNAT_PROTOCOL_ICMP:
189 icmp = (icmp46_header_t *) l4_header;
193 case SNAT_PROTOCOL_UDP:
194 case SNAT_PROTOCOL_TCP:
204 port = clib_net_to_host_u16 (port);
206 return nm->sm->first_worker_index + ((port - 1024) / sm->port_per_thread);
266 if (
nat64_db_init (db, bib_buckets, bib_memory_size, st_buckets,
267 st_memory_size, nat64_free_out_addr_and_port))
296 return VNET_API_ERROR_VALUE_EXIST;
305 #define _(N, id, n, s) \ 306 clib_bitmap_alloc (a->busy_##n##_port_bitmap, 65535); \ 307 a->busy_##n##_ports = 0; \ 308 vec_validate_init_empty (a->busy_##n##_ports_per_thread, tm->n_vlib_mains - 1, 0); 315 return VNET_API_ERROR_NO_SUCH_ENTRY;
324 #define _(N, id, n, s) \ 325 clib_bitmap_free (a->busy_##n##_port_bitmap); 336 if (nat_interface_is_inside(interface))
339 snat_add_del_addr_to_fib (addr, 32, interface->sw_if_index, is_add);
377 return VNET_API_ERROR_VALUE_EXIST;
391 return VNET_API_ERROR_NO_SUCH_ENTRY;
409 const char *feature_name, *arc_name;
415 if (i->sw_if_index == sw_if_index)
428 pool_get (nm->interfaces, interface);
429 interface->sw_if_index = sw_if_index;
430 interface->flags = 0;
437 nm->total_enabled_count++;
439 nm->nat64_expire_walk_node_index,
446 return VNET_API_ERROR_NO_SUCH_ENTRY;
454 pool_put (nm->interfaces, interface);
456 nm->total_enabled_count--;
467 if (nm->sm->num_workers > 1)
470 is_inside ?
"nat64-in2out-handoff" :
"nat64-out2in-handoff";
471 if (nm->fq_in2out_index == ~0)
472 nm->fq_in2out_index =
474 if (nm->fq_out2in_index == ~0)
475 nm->fq_out2in_index =
479 feature_name = is_inside ?
"nat64-in2out" :
"nat64-out2in";
481 arc_name = is_inside ?
"ip6-unicast" :
"ip4-unicast";
511 u32 worker_index = 0;
534 u16 port,
u8 protocol)
539 u32 thread_index = db - nm->
db;
541 u16 port_host_byte_order = clib_net_to_host_u16 (port);
550 #define _(N, j, n, s) \ 551 case SNAT_PROTOCOL_##N: \ 552 ASSERT (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 553 port_host_byte_order) == 1); \ 554 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, port, 0); \ 555 a->busy_##n##_ports--; \ 556 a->busy_##n##_ports_per_thread[thread_index]--; \ 579 nat64_db_bib_entry_t *bibe;
585 if ((static_bib->thread_index != thread_index) || (static_bib->done))
588 if (static_bib->is_add)
589 (void) nat64_db_bib_entry_create (db, &static_bib->in_addr,
590 &static_bib->out_addr,
592 static_bib->out_port,
593 static_bib->fib_index,
594 static_bib->proto, 1);
597 addr.as_u64[0] = static_bib->in_addr.as_u64[0];
598 addr.as_u64[1] = static_bib->in_addr.as_u64[1];
599 bibe = nat64_db_bib_entry_find (db, &addr, static_bib->in_port,
601 static_bib->fib_index, 1);
603 nat64_db_bib_entry_free (db, bibe);
606 static_bib->
done = 1;
619 .state = VLIB_NODE_STATE_INTERRUPT,
620 .name =
"nat64-static-bib-worker",
627 u16 out_port,
u8 proto,
u32 vrf_id,
u8 is_add)
630 nat64_db_bib_entry_t *bibe;
637 u32 thread_index = 0;
641 u32 *to_be_free = 0, *index;
646 db = &nm->
db[thread_index];
651 addr.as_u64[0] = in_addr->
as_u64[0];
652 addr.as_u64[1] = in_addr->
as_u64[1];
655 proto, fib_index, 1);
660 return VNET_API_ERROR_VALUE_EXIST;
666 return VNET_API_ERROR_INVALID_VALUE_2;
676 #define _(N, j, n, s) \ 677 case SNAT_PROTOCOL_##N: \ 678 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 680 return VNET_API_ERROR_INVALID_VALUE; \ 681 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 683 if (out_port > 1024) \ 685 a->busy_##n##_ports++; \ 686 a->busy_##n##_ports_per_thread[thread_index]++; \ 692 memset (&addr, 0,
sizeof (addr));
693 addr.ip4.as_u32 = out_addr->
as_u32;
695 return VNET_API_ERROR_INVALID_VALUE;
703 clib_host_to_net_u16 (in_port),
704 clib_host_to_net_u16 (out_port),
705 fib_index, proto, 1);
707 return VNET_API_ERROR_UNSPECIFIED;
713 return VNET_API_ERROR_NO_SUCH_ENTRY;
724 if (static_bib->done)
725 vec_add1 (to_be_free, static_bib - nm->static_bibs);
734 static_bib->
in_port = clib_host_to_net_u16 (in_port);
736 static_bib->
out_port = clib_host_to_net_u16 (out_port);
738 static_bib->
proto = proto;
739 static_bib->
is_add = is_add;
741 static_bib->
done = 0;
745 nat64_static_bib_worker_node.index);
747 return VNET_API_ERROR_UNSPECIFIED;
761 return VNET_API_ERROR_INVALID_VALUE;
812 if (incoming_syn == 0)
852 case SNAT_PROTOCOL_ICMP:
855 case SNAT_PROTOCOL_TCP:
857 switch (ste->tcp_state)
859 case NAT64_TCP_STATE_V4_INIT:
860 case NAT64_TCP_STATE_V6_INIT:
861 case NAT64_TCP_STATE_V4_FIN_RCV:
862 case NAT64_TCP_STATE_V6_FIN_RCV:
863 case NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV:
864 case NAT64_TCP_STATE_TRANS:
867 case NAT64_TCP_STATE_ESTABLISHED:
874 case SNAT_PROTOCOL_UDP:
887 switch (ste->tcp_state)
889 case NAT64_TCP_STATE_CLOSED:
894 ste->tcp_state = NAT64_TCP_STATE_V6_INIT;
896 ste->tcp_state = NAT64_TCP_STATE_V4_INIT;
900 case NAT64_TCP_STATE_V4_INIT:
903 ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
906 case NAT64_TCP_STATE_V6_INIT:
909 ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
912 case NAT64_TCP_STATE_ESTABLISHED:
917 ste->tcp_state = NAT64_TCP_STATE_V6_FIN_RCV;
919 ste->tcp_state = NAT64_TCP_STATE_V4_FIN_RCV;
923 ste->tcp_state = NAT64_TCP_STATE_TRANS;
927 case NAT64_TCP_STATE_V4_FIN_RCV:
930 ste->tcp_state = NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV;
933 case NAT64_TCP_STATE_V6_FIN_RCV:
936 ste->tcp_state = NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV;
939 case NAT64_TCP_STATE_TRANS:
942 ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
958 if (plen != 32 && plen != 40 && plen != 48 && plen != 56 && plen != 64
960 return VNET_API_ERROR_INVALID_VALUE;
990 return VNET_API_ERROR_NO_SUCH_ENTRY;
1173 .state = VLIB_NODE_STATE_INTERRUPT,
1174 .name =
"nat64-expire-worker-walk",
1190 uword event_type, *event_data = 0;
1230 for (i = 0; i <
vec_len (worker_vms); i++)
1232 worker_vm = worker_vms[
i];
1234 nat64_expire_worker_walk_node.index);
1245 .name =
"nat64-expire-walk",
u32 nat64_get_icmp_timeout(void)
Get ICMP session timeout.
#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.
int nat64_db_init(nat64_db_t *db, u32 bib_buckets, u32 bib_memory_size, u32 st_buckets, u32 st_memory_size, nat64_db_free_addr_port_function_t free_addr_port_cb)
Initialize NAT64 DB.
int nat64_set_udp_timeout(u32 timeout)
Set UDP session timeout.
ip4_add_del_interface_address_callback_t * add_del_interface_address_callbacks
Functions to call when interface address changes.
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
snat_address_t * addr_pool
Address pool vector.
void nat64_extract_ip4(ip6_address_t *ip6, ip4_address_t *ip4, u32 fib_index)
Extract IPv4 address from the IPv4-embedded IPv6 addresses.
#define SNAT_TCP_ESTABLISHED_TIMEOUT
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
static void vlib_node_set_interrupt_pending(vlib_main_t *vm, u32 node_index)
int nat64_add_del_interface(u32 sw_if_index, u8 is_inside, u8 is_add)
Enable/disable NAT64 feature on the interface.
u32 nat64_expire_walk_node_index
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
static f64 vlib_time_now(vlib_main_t *vm)
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.
u32 vlib_frame_queue_main_init(u32 node_index, u32 frame_queue_nelts)
nat_reass_ip4_t * nat_ip4_reass_find(ip4_address_t src, ip4_address_t dst, u16 frag_id, u8 proto)
Find reassembly.
int nat64_add_del_pool_addr(ip4_address_t *addr, u32 vrf_id, u8 is_add)
Add/delete address to NAT64 pool.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
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 u64 clib_xxhash(u64 key)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define NAT_INTERFACE_FLAG_IS_OUTSIDE
void nat64_set_hash(u32 bib_buckets, u32 bib_memory_size, u32 st_buckets, u32 st_memory_size)
Set NAT64 hash tables configuration.
void snat_add_del_addr_to_fib(ip4_address_t *addr, u8 p_len, u32 sw_if_index, int is_add)
Add/del NAT address to FIB.
nat_alloc_out_addr_and_port_function_t * alloc_addr_and_port
int nat64_add_interface_address(u32 sw_if_index, int is_add)
NAT64 pool address from specific (DHCP addressed) interface.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
struct _tcp_header tcp_header_t
u32 * auto_add_sw_if_indices
sw_if_indices whose interface addresses should be auto-added
int nat64_set_tcp_timeouts(u32 trans, u32 est, u32 incoming_syn)
Set TCP session timeouts.
vlib_main_t ** vlib_mains
#define nat_interface_is_outside(i)
static void nat64_ip4_add_del_interface_address_cb(ip4_main_t *im, uword opaque, u32 sw_if_index, ip4_address_t *address, u32 address_length, u32 if_address_index, u32 is_delete)
u32 nat64_get_worker_in2out(ip6_address_t *addr)
Get worker thread index for NAT64 in2out.
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
int nat64_set_icmp_timeout(u32 timeout)
Set ICMP session timeout.
A high priority source a plugin can use.
static void * ip4_next_header(ip4_header_t *i)
vlib_node_registration_t nat64_in2out_node
(constructor) VLIB_REGISTER_NODE (nat64_in2out_node)
void nat64_tcp_session_set_state(nat64_db_st_entry_t *ste, tcp_header_t *tcp, u8 is_ip6)
Set NAT64 TCP session state.
snat_interface_t * interfaces
Interface pool.
u32 tcp_incoming_syn_timeout
static int ip4_is_fragment(ip4_header_t *i)
u32 udp_timeout
values of various timeouts
u32 nat64_get_worker_out2in(ip4_header_t *ip)
Get worker thread index for NAT64 out2in.
nat64_prefix_t * pref64
Pref64 vector.
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
void nat64_session_reset_timeout(nat64_db_st_entry_t *ste, vlib_main_t *vm)
Reset NAT64 session timeout.
void nad64_db_st_free_expired(nat64_db_t *db, u32 now)
Free expired session entries in session tables.
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.
u32 nat64_get_udp_timeout(void)
Get UDP session timeout.
#define pool_put(P, E)
Free an object E in pool P.
void nat64_db_bib_entry_free(nat64_db_t *db, nat64_db_bib_entry_t *bibe)
Free NAT64 BIB entry.
#define vec_del1(v, i)
Delete the element at index I.
static uword nat64_expire_walk_fn(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Centralized process to drive per worker expire walk.
#define nat_interface_is_inside(i)
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
void nat64_compose_ip6(ip6_address_t *ip6, ip4_address_t *ip4, u32 fib_index)
Compose IPv4-embedded IPv6 addresses.
static u8 well_known_prefix[]
u32 nat64_get_tcp_est_timeout(void)
Get TCP established timeout.
#define VLIB_REGISTER_NODE(x,...)
vlib_node_registration_t nat64_out2in_node
(constructor) VLIB_REGISTER_NODE (nat64_out2in_node)
void nat64_pool_addr_walk(nat64_pool_addr_walk_fn_t fn, void *ctx)
Walk NAT64 pool.
static_always_inline uword vlib_get_thread_index(void)
u8 nat_reass_is_drop_frag(u8 is_ip6)
Get status of virtual fragmentation reassembly.
#define vec_free(V)
Free vector's memory (no header).
ip4_add_del_interface_address_function_t * function
int nat64_add_del_prefix(ip6_address_t *prefix, u8 plen, u32 vrf_id, u8 is_add)
Add/delete NAT64 prefix.
u32 bib_buckets
config parameters
#define clib_warning(format, args...)
#define clib_memcpy(a, b, c)
static int ip4_is_first_fragment(ip4_header_t *i)
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
#define pool_put_index(p, i)
Free pool element with given index.
#define NAT_INTERFACE_FLAG_IS_INSIDE
u32 nat64_get_tcp_incoming_syn_timeout(void)
Get TCP incoming SYN timeout.
u32 fq_in2out_index
Worker handoff.
nat64_static_bib_to_update_t * static_bibs
Pool of static BIB entries to be added/deleted in worker threads.
static void nat64_free_out_addr_and_port(struct nat64_db_s *db, ip4_address_t *addr, u16 port, u8 protocol)
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
static uword nat64_expire_worker_walk_fn(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Per worker process checking expire time for NAT64 sessions.
#define VNET_FEATURES(...)
void nat64_prefix_walk(nat64_prefix_walk_fn_t fn, void *ctx)
Walk NAT64 prefixes.
static uword is_pow2(uword x)
void nat64_interfaces_walk(nat64_interface_walk_fn_t fn, void *ctx)
Walk NAT64 interfaces.
void nat64_db_free_out_addr(nat64_db_t *db, ip4_address_t *out_addr)
Free sessions using specific outside address.
clib_error_t * nat64_init(vlib_main_t *vm)
Initialize NAT64.
struct _vlib_node_registration vlib_node_registration_t
NAT64 global declarations.
static vlib_node_registration_t nat64_expire_walk_node
(constructor) VLIB_REGISTER_NODE (nat64_expire_walk_node)
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 uword nat64_static_bib_worker_fn(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Add/delete static BIB entry in worker thread.
#define SNAT_ICMP_TIMEOUT
static vlib_node_registration_t nat64_expire_worker_walk_node
(constructor) VLIB_REGISTER_NODE (nat64_expire_worker_walk_node)
ip4_main_t ip4_main
Global ip4 main structure.
static vlib_thread_main_t * vlib_get_thread_main()
#define SNAT_UDP_TIMEOUT_MIN
#define vec_foreach(var, vec)
Vector iterator.
static vlib_node_registration_t nat64_static_bib_worker_node
(constructor) VLIB_REGISTER_NODE (nat64_static_bib_worker_node)
NAT plugin virtual fragmentation reassembly.
#define SNAT_TCP_INCOMING_SYN
VNET_FEATURE_INIT(nat64_in2out, static)
#define SNAT_TCP_TRANSITORY_TIMEOUT
int nat64_add_del_static_bib_entry(ip6_address_t *in_addr, ip4_address_t *out_addr, u16 in_port, u16 out_port, u8 proto, u32 vrf_id, u8 is_add)
Add/delete static NAT64 BIB entry.
int(* nat64_prefix_walk_fn_t)(nat64_prefix_t *pref64, void *ctx)
Call back function when walking addresses in NAT64 prefixes, non-zero return value stop walk...
u32 nat64_get_tcp_trans_timeout(void)
Get TCP transitory timeout.
int(* nat64_interface_walk_fn_t)(snat_interface_t *i, void *ctx)
Call back function when walking interfaces with NAT64 feature, non-zero return value stop walk...
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
int(* nat64_pool_addr_walk_fn_t)(snat_address_t *addr, void *ctx)
Call back function when walking addresses in NAT64 pool, non-zero return value stop walk...