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;
112 #define _(N, i, n, s) \ 113 clib_bitmap_alloc (a->busy_##n##_port_bitmap, 65535); 120 return VNET_API_ERROR_NO_SUCH_ENTRY;
126 #define _(N, id, n, s) \ 127 clib_bitmap_free (a->busy_##n##_port_bitmap); 139 if (interface->is_inside)
142 snat_add_del_addr_to_fib (addr, 32, interface->sw_if_index, is_add);
171 const char *feature_name, *arc_name;
177 if (i->sw_if_index == sw_if_index)
188 return VNET_API_ERROR_VALUE_EXIST;
190 pool_get (nm->interfaces, interface);
191 interface->sw_if_index = sw_if_index;
192 interface->is_inside = is_inside;
198 return VNET_API_ERROR_NO_SUCH_ENTRY;
200 pool_put (nm->interfaces, interface);
211 arc_name = is_inside ? "ip6-unicast" : "ip4-unicast";
212 feature_name = is_inside ? "nat64-in2out" : "nat64-out2in";
248 #define _(N, j, n, s) \ 249 case SNAT_PROTOCOL_##N: \ 250 if (a->busy_##n##_ports < (65535-1024)) \ 252 if (a->fib_index == fib_index) \ 256 portnum = random_u32 (&sm->random_seed); \ 258 if (portnum < 1024) \ 260 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 263 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 265 a->busy_##n##_ports++; \ 267 addr->as_u32 = a->addr.as_u32; \ 271 else if (a->fib_index == 0) \ 287 #define _(N, j, n, s) \ 288 case SNAT_PROTOCOL_##N: \ 291 portnum = random_u32 (&sm->random_seed); \ 293 if (portnum < 1024) \ 295 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 298 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 300 a->busy_##n##_ports++; \ 302 addr->as_u32 = a->addr.as_u32; \ 334 #define _(N, j, n, s) \ 335 case SNAT_PROTOCOL_##N: \ 336 ASSERT (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 338 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, port, 0); \ 339 a->busy_##n##_ports--; \ 354 u16 out_port,
u8 proto,
u32 vrf_id,
u8 is_add)
357 nat64_db_bib_entry_t *bibe;
365 addr.as_u64[0] = in_addr->
as_u64[0];
366 addr.as_u64[1] = in_addr->
as_u64[1];
369 proto, fib_index, 1);
374 return VNET_API_ERROR_VALUE_EXIST;
383 #define _(N, j, n, s) \ 384 case SNAT_PROTOCOL_##N: \ 385 if (clib_bitmap_get_no_check (a->busy_##n##_port_bitmap, \ 387 return VNET_API_ERROR_INVALID_VALUE; \ 388 clib_bitmap_set_no_check (a->busy_##n##_port_bitmap, \ 390 if (out_port > 1024) \ 391 a->busy_##n##_ports++; \ 396 memset (&addr, 0,
sizeof (addr));
397 addr.ip4.as_u32 = out_addr->
as_u32;
399 (&nm->
db, &addr, 0, proto, fib_index, 0))
400 return VNET_API_ERROR_INVALID_VALUE;
406 clib_host_to_net_u16 (in_port),
407 clib_host_to_net_u16 (out_port), fib_index,
410 return VNET_API_ERROR_UNSPECIFIED;
415 return VNET_API_ERROR_NO_SUCH_ENTRY;
432 return VNET_API_ERROR_INVALID_VALUE;
483 if (incoming_syn == 0)
523 case SNAT_PROTOCOL_ICMP:
526 case SNAT_PROTOCOL_TCP:
528 switch (ste->tcp_state)
530 case NAT64_TCP_STATE_V4_INIT:
531 case NAT64_TCP_STATE_V6_INIT:
532 case NAT64_TCP_STATE_V4_FIN_RCV:
533 case NAT64_TCP_STATE_V6_FIN_RCV:
534 case NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV:
535 case NAT64_TCP_STATE_TRANS:
538 case NAT64_TCP_STATE_ESTABLISHED:
545 case SNAT_PROTOCOL_UDP:
558 switch (ste->tcp_state)
560 case NAT64_TCP_STATE_CLOSED:
565 ste->tcp_state = NAT64_TCP_STATE_V6_INIT;
567 ste->tcp_state = NAT64_TCP_STATE_V4_INIT;
571 case NAT64_TCP_STATE_V4_INIT:
574 ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
577 case NAT64_TCP_STATE_V6_INIT:
580 ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
583 case NAT64_TCP_STATE_ESTABLISHED:
588 ste->tcp_state = NAT64_TCP_STATE_V6_FIN_RCV;
590 ste->tcp_state = NAT64_TCP_STATE_V4_FIN_RCV;
594 ste->tcp_state = NAT64_TCP_STATE_TRANS;
598 case NAT64_TCP_STATE_V4_FIN_RCV:
601 ste->tcp_state = NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV;
604 case NAT64_TCP_STATE_V6_FIN_RCV:
607 ste->tcp_state = NAT64_TCP_STATE_V6_FIN_V4_FIN_RCV;
610 case NAT64_TCP_STATE_TRANS:
613 ste->tcp_state = NAT64_TCP_STATE_ESTABLISHED;
629 if (plen != 32 && plen != 40 && plen != 48 && plen != 56 && plen != 64
631 return VNET_API_ERROR_INVALID_VALUE;
661 return VNET_API_ERROR_NO_SUCH_ENTRY;
851 .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.
#define SNAT_TCP_ESTABLISHED_TIMEOUT
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)
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.
int nat64_add_del_pool_addr(ip4_address_t *addr, u32 vrf_id, u8 is_add)
Add/delete address to NAT64 pool.
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
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
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.
#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...
int nat64_set_icmp_timeout(u32 timeout)
Set ICMP session timeout.
A high priority source a plugin can use.
#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.
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.
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 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.
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.
static u32 ip_proto_to_snat_proto(u8 ip_proto)
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.
#define VNET_FEATURES(...)
void nat64_prefix_walk(nat64_prefix_walk_fn_t fn, void *ctx)
Walk NAT64 prefixes.
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.
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)
#define SNAT_ICMP_TIMEOUT
#define VLIB_REGISTER_NODE(x,...)
static vlib_thread_main_t * vlib_get_thread_main()
#define SNAT_UDP_TIMEOUT_MIN
#define vec_foreach(var, vec)
Vector iterator.
int nat64_db_init(nat64_db_t *db)
Initialize NAT64 DB.
#define SNAT_TCP_INCOMING_SYN
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.
#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...