31 .arc_name =
"ip6-unicast",
32 .node_name =
"nat64-in2out",
36 .arc_name =
"ip4-unicast",
37 .node_name =
"nat64-out2in",
42 0x00, 0x64, 0xff, 0x9b,
43 0x00, 0x00, 0x00, 0x00,
44 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x00
103 return VNET_API_ERROR_VALUE_EXIST;
111 #define _(N, i, n, s) \ 112 clib_bitmap_alloc (a->busy_##n##_port_bitmap, 65535); 119 return VNET_API_ERROR_NO_SUCH_ENTRY;
121 #define _(N, id, n, s) \ 122 clib_bitmap_free (a->busy_##n##_port_bitmap); 132 if (interface->is_inside)
135 snat_add_del_addr_to_fib (addr, 32, interface->sw_if_index, is_add);
164 const char *feature_name, *arc_name;
170 if (i->sw_if_index == sw_if_index)
181 return VNET_API_ERROR_VALUE_EXIST;
183 pool_get (nm->interfaces, interface);
184 interface->sw_if_index = sw_if_index;
185 interface->is_inside = is_inside;
191 return VNET_API_ERROR_NO_SUCH_ENTRY;
193 pool_put (nm->interfaces, interface);
204 arc_name = is_inside ? "ip6-unicast" : "ip4-unicast";
205 feature_name = is_inside ? "nat64-in2out" : "nat64-out2in";
241 #define _(N, j, n, s) \ 242 case SNAT_PROTOCOL_##N: \ 243 if (a->busy_##n##_ports < (65535-1024)) \ 245 if (a->fib_index == fib_index) \ 249 portnum = random_u32 (&sm->random_seed); \ 251 if (portnum < 1024) \ 253 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 256 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 258 a->busy_##n##_ports++; \ 260 addr->as_u32 = a->addr.as_u32; \ 264 else if (a->fib_index == 0) \ 280 #define _(N, j, n, s) \ 281 case SNAT_PROTOCOL_##N: \ 284 portnum = random_u32 (&sm->random_seed); \ 286 if (portnum < 1024) \ 288 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 291 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 293 a->busy_##n##_ports++; \ 295 addr->as_u32 = a->addr.as_u32; \ 327 #define _(N, j, n, s) \ 328 case SNAT_PROTOCOL_##N: \ 329 ASSERT (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 331 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, port, 0); \ 332 a->busy_##n##_ports--; \ 347 u16 out_port,
u8 proto,
u32 vrf_id,
u8 is_add)
350 nat64_db_bib_entry_t *bibe;
358 addr.as_u64[0] = in_addr->
as_u64[0];
359 addr.as_u64[1] = in_addr->
as_u64[1];
367 return VNET_API_ERROR_VALUE_EXIST;
376 #define _(N, j, n, s) \ 377 case SNAT_PROTOCOL_##N: \ 378 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 380 return VNET_API_ERROR_INVALID_VALUE; \ 381 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 383 if (out_port > 1024) \ 384 a->busy_##n##_ports++; \ 390 return VNET_API_ERROR_INVALID_VALUE_2;
396 clib_host_to_net_u16 (in_port),
397 clib_host_to_net_u16 (out_port), fib_index,
400 return VNET_API_ERROR_UNSPECIFIED;
405 return VNET_API_ERROR_NO_SUCH_ENTRY;
422 return VNET_API_ERROR_INVALID_VALUE;
473 if (incoming_syn == 0)
513 case SNAT_PROTOCOL_ICMP:
516 case SNAT_PROTOCOL_TCP:
518 switch (ste->tcp_state)
520 case NAT64_TCP_STATE_V4_INIT:
521 case NAT64_TCP_STATE_V6_INIT:
522 case NAT64_TCP_STATE_V4_FIN_RCV:
523 case NAT64_TCP_STATE_V6_FIN_RCV:
524 case NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV:
525 case NAT64_TCP_STATE_TRANS:
528 case NAT64_TCP_STATE_ESTABLISHED:
535 case SNAT_PROTOCOL_UDP:
547 switch (ste->tcp_state)
549 case NAT64_TCP_STATE_CLOSED:
554 ste->tcp_state = NAT64_TCP_STATE_V6_INIT;
556 ste->tcp_state = NAT64_TCP_STATE_V4_INIT;
560 case NAT64_TCP_STATE_V4_INIT:
563 ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
566 case NAT64_TCP_STATE_V6_INIT:
569 ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
572 case NAT64_TCP_STATE_ESTABLISHED:
577 ste->tcp_state = NAT64_TCP_STATE_V6_FIN_RCV;
579 ste->tcp_state = NAT64_TCP_STATE_V4_FIN_RCV;
583 ste->tcp_state = NAT64_TCP_STATE_TRANS;
587 case NAT64_TCP_STATE_V4_FIN_RCV:
590 ste->tcp_state = NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV;
593 case NAT64_TCP_STATE_V6_FIN_RCV:
596 ste->tcp_state = NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV;
599 case NAT64_TCP_STATE_TRANS:
602 ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
618 if (plen != 32 && plen != 40 && plen != 48 && plen != 56 && plen != 64
620 return VNET_API_ERROR_INVALID_VALUE;
649 return VNET_API_ERROR_NO_SUCH_ENTRY;
842 .name =
"nat64-expire-walk",
u32 nat64_get_icmp_timeout(void)
Get ICMP session timeout.
sll srl srl sll sra u16x4 i
int nat64_set_udp_timeout(u32 timeout)
Set UDP session timeout.
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.
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...
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.
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.
int nat64_add_del_interface(u32 sw_if_index, u8 is_inside, u8 is_add)
Enable/disable NAT64 feature on the interface.
static f64 vlib_time_now(vlib_main_t *vm)
int nat64_add_del_pool_addr(ip4_address_t *addr, u32 vrf_id, u8 is_add)
Add/delete address to NAT64 pool.
struct _vlib_node_registration vlib_node_registration_t
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
struct _tcp_header tcp_header_t
int nat64_set_tcp_timeouts(u32 trans, u32 est, u32 incoming_syn)
Set TCP session timeouts.
#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...
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.
int nat64_set_icmp_timeout(u32 timeout)
Set ICMP session timeout.
#define SNAT_ICMP_TIMEOUT
#define clib_error_return(e, args...)
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
nat64_db_t db
BIB and session DB.
#define SNAT_TCP_TRANSITORY_TIMEOUT
nat64_prefix_t * pref64
Pref64 vector.
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.
#define SNAT_UDP_TIMEOUT_MIN
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)
The 'nat64-expire-walk' process's main loop.
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.
void nat64_pool_addr_walk(nat64_pool_addr_walk_fn_t fn, void *ctx)
Walk NAT64 pool.
int nat64_add_del_prefix(ip6_address_t *prefix, u8 plen, u32 vrf_id, u8 is_add)
Add/delete NAT64 prefix.
#define clib_warning(format, args...)
u32 nat64_get_tcp_incoming_syn_timeout(void)
Get TCP incoming SYN timeout.
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.
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
#define VNET_FEATURES(...)
void nat64_prefix_walk(nat64_prefix_walk_fn_t fn, void *ctx)
Walk NAT64 prefixes.
#define SNAT_TCP_INCOMING_SYN
void nat64_interfaces_walk(nat64_interface_walk_fn_t fn, void *ctx)
Walk NAT64 interfaces.
clib_error_t * nat64_init(vlib_main_t *vm)
Initialize NAT64.
NAT64 global declarations.
static vlib_node_registration_t nat64_expire_walk_node
(constructor) VLIB_REGISTER_NODE (nat64_expire_walk_node)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static u32 ip_proto_to_snat_proto(u8 ip_proto)
#define VLIB_REGISTER_NODE(x,...)
static vlib_thread_main_t * vlib_get_thread_main()
#define vec_foreach(var, vec)
Vector iterator.
int nat64_db_init(nat64_db_t *db)
Initialize NAT64 DB.
VNET_FEATURE_INIT(nat64_in2out, static)
void nat64_free_out_addr_and_port(ip4_address_t *addr, u16 port, snat_protocol_t proto)
Free IPv4 address and port pair from NAT64 pool.
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...
#define SNAT_TCP_ESTABLISHED_TIMEOUT
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...