FD.io VPP  v21.01.1
Vector Packet Processing
nat64.c File Reference
+ Include dependency graph for nat64.c:

Go to the source code of this file.

Macros

#define nat_elog_str(_str)
 

Functions

 VNET_FEATURE_INIT (nat64_in2out, static)
 
 VNET_FEATURE_INIT (nat64_out2in, static)
 
 VNET_FEATURE_INIT (nat64_in2out_handoff, static)
 
 VNET_FEATURE_INIT (nat64_out2in_handoff, static)
 
 VLIB_PLUGIN_REGISTER ()
 
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. More...
 
u32 nat64_get_worker_out2in (vlib_buffer_t *b, ip4_header_t *ip)
 Get worker thread index for NAT64 out2in. More...
 
clib_error_tnat64_init (vlib_main_t *vm)
 Initialize NAT64. More...
 
static void nat64_free_out_addr_and_port (struct nat64_db_s *db, ip4_address_t *addr, u16 port, u8 protocol)
 
int nat64_init_hash (nat64_config_t c)
 
int nat64_free_hash ()
 
int nat64_add_del_pool_addr (u32 thread_index, ip4_address_t *addr, u32 vrf_id, u8 is_add)
 Add/delete address to NAT64 pool. More...
 
void nat64_pool_addr_walk (nat64_pool_addr_walk_fn_t fn, void *ctx)
 Walk NAT64 pool. More...
 
int nat64_add_interface_address (u32 sw_if_index, int is_add)
 NAT64 pool address from specific (DHCP addressed) interface. More...
 
static void nat64_validate_counters (nat64_main_t *nm, u32 sw_if_index)
 
void nat64_add_del_addr_to_fib (ip4_address_t *addr, u8 p_len, u32 sw_if_index, int is_add)
 
int nat64_interface_add_del (u32 sw_if_index, u8 is_inside, u8 is_add)
 Enable/disable NAT64 feature on the interface. More...
 
void nat64_interfaces_walk (nat64_interface_walk_fn_t fn, void *ctx)
 Walk NAT64 interfaces. More...
 
static_always_inline u16 nat64_random_port (u16 min, u16 max)
 
static_always_inline int nat64_alloc_addr_and_port_default (nat64_address_t *addresses, u32 fib_index, u32 thread_index, nat_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread, u32 nat_thread_index)
 
int nat64_alloc_out_addr_and_port (u32 fib_index, nat_protocol_t proto, ip4_address_t *addr, u16 *port, u32 thread_index)
 Alloce IPv4 address and port pair from NAT64 pool. More...
 
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. More...
 
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. More...
 
int nat64_set_udp_timeout (u32 timeout)
 Set UDP session timeout. More...
 
u32 nat64_get_udp_timeout (void)
 Get UDP session timeout. More...
 
int nat64_set_icmp_timeout (u32 timeout)
 Set ICMP session timeout. More...
 
void nat64_reset_timeouts ()
 
u32 nat64_get_icmp_timeout (void)
 Get ICMP session timeout. More...
 
int nat64_set_tcp_timeouts (u32 trans, u32 est)
 Set TCP session timeouts. More...
 
u32 nat64_get_tcp_trans_timeout (void)
 Get TCP transitory timeout. More...
 
u32 nat64_get_tcp_est_timeout (void)
 Get TCP established timeout. More...
 
void nat64_session_reset_timeout (nat64_db_st_entry_t *ste, vlib_main_t *vm)
 Reset NAT64 session timeout. More...
 
void nat64_tcp_session_set_state (nat64_db_st_entry_t *ste, tcp_header_t *tcp, u8 is_ip6)
 Set NAT64 TCP session state. More...
 
int nat64_add_del_prefix (ip6_address_t *prefix, u8 plen, u32 vrf_id, u8 is_add)
 Add/delete NAT64 prefix. More...
 
void nat64_prefix_walk (nat64_prefix_walk_fn_t fn, void *ctx)
 Walk NAT64 prefixes. More...
 
void nat64_compose_ip6 (ip6_address_t *ip6, ip4_address_t *ip4, u32 fib_index)
 Compose IPv4-embedded IPv6 addresses. More...
 
void nat64_extract_ip4 (ip6_address_t *ip6, ip4_address_t *ip4, u32 fib_index)
 Extract IPv4 address from the IPv4-embedded IPv6 addresses. More...
 
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. More...
 
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. More...
 
void nat64_create_expire_walk_process ()
 
int nat64_plugin_enable (nat64_config_t c)
 
int nat64_plugin_disable ()
 
uword unformat_nat_protocol (unformat_input_t *input, va_list *args)
 
u8format_nat_protocol (u8 *s, va_list *args)
 

Variables

nat64_main_t nat64_main
 
static u8 well_known_prefix []
 
static vlib_node_registration_t nat64_static_bib_worker_node
 (constructor) VLIB_REGISTER_NODE (nat64_static_bib_worker_node) More...
 
static vlib_node_registration_t nat64_expire_worker_walk_node
 (constructor) VLIB_REGISTER_NODE (nat64_expire_worker_walk_node) More...
 

Macro Definition Documentation

◆ nat_elog_str

#define nat_elog_str (   _str)
Value:
do \
{ \
ELOG_TYPE_DECLARE (e) = \
{ \
.format = "nat-msg " _str, \
.format_args = "", \
}; \
ELOG_DATA (&vlib_global_main.elog_main, e); \
} while (0);
vlib_main_t vlib_global_main
Definition: main.c:2041
elog_main_t elog_main
Definition: main.h:224

Definition at line 67 of file nat64.c.

Function Documentation

◆ format_nat_protocol()

u8* format_nat_protocol ( u8 s,
va_list *  args 
)

Definition at line 1627 of file nat64.c.

◆ nat64_add_del_addr_to_fib()

void nat64_add_del_addr_to_fib ( ip4_address_t addr,
u8  p_len,
u32  sw_if_index,
int  is_add 
)

Definition at line 509 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_add_del_pool_addr()

int nat64_add_del_pool_addr ( u32  thread_index,
ip4_address_t addr,
u32  vrf_id,
u8  is_add 
)

Add/delete address to NAT64 pool.

Parameters
thread_indexThread index used by ipfix nat logging (not address per thread).
addrIPv4 address.
vrf_idVRF id of tenant, ~0 means independent of VRF.
is_add1 if add, 0 if delete.
Returns
0 on success, non-zero value otherwise.

Definition at line 364 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_add_del_prefix()

int nat64_add_del_prefix ( ip6_address_t *  prefix,
u8  plen,
u32  vrf_id,
u8  is_add 
)

Add/delete NAT64 prefix.

Parameters
prefixNAT64 prefix.
plenPrefix length.
vrf_idVRF id of tenant.
is_add1 if add, 0 if delete.
Returns
0 on success, non-zero value otherwise.

Definition at line 1206 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_add_del_static_bib_entry()

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.

Parameters
in_addrInside IPv6 address.
out_addrOutside IPv4 address.
in_portInside port number.
out_portOutside port number.
protoL4 protocol.
vrf_idVRF id of tenant.
is_add1 if add, 0 if delete.
Returns
0 on success, non-zero value otherwise.

Definition at line 879 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_add_interface_address()

int nat64_add_interface_address ( u32  sw_if_index,
int  is_add 
)

NAT64 pool address from specific (DHCP addressed) interface.

Parameters
sw_if_indexIndex of the interface.
is_add1 if add, 0 if delete.
Returns
0 on success, non-zero value otherwise.

Definition at line 455 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_alloc_addr_and_port_default()

static_always_inline int nat64_alloc_addr_and_port_default ( nat64_address_t addresses,
u32  fib_index,
u32  thread_index,
nat_protocol_t  proto,
ip4_address_t addr,
u16 port,
u16  port_per_thread,
u32  nat_thread_index 
)

Definition at line 670 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_alloc_out_addr_and_port()

int nat64_alloc_out_addr_and_port ( u32  fib_index,
nat_protocol_t  proto,
ip4_address_t addr,
u16 port,
u32  thread_index 
)

Alloce IPv4 address and port pair from NAT64 pool.

Parameters
fib_indexFIB index of tenant.
protoL4 protocol.
addrAllocated IPv4 address.
portAllocated port number.
thread_indexThread index.
Returns
0 on success, non-zero value otherwise.

Definition at line 757 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_compose_ip6()

void nat64_compose_ip6 ( ip6_address_t *  ip6,
ip4_address_t ip4,
u32  fib_index 
)

Compose IPv4-embedded IPv6 addresses.

Parameters
ip6IPv4-embedded IPv6 addresses.
ip4IPv4 address.
fib_indexTenant FIB index.

Definition at line 1271 of file nat64.c.

+ Here is the caller graph for this function:

◆ nat64_create_expire_walk_process()

void nat64_create_expire_walk_process ( )

Definition at line 1503 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_expire_walk_fn()

static uword nat64_expire_walk_fn ( vlib_main_t vm,
vlib_node_runtime_t rt,
vlib_frame_t f 
)
static

Centralized process to drive per worker expire walk.

Definition at line 1447 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_expire_worker_walk_fn()

static uword nat64_expire_worker_walk_fn ( vlib_main_t vm,
vlib_node_runtime_t rt,
vlib_frame_t f 
)
static

Per worker process checking expire time for NAT64 sessions.

Definition at line 1411 of file nat64.c.

+ Here is the call graph for this function:

◆ nat64_extract_ip4()

void nat64_extract_ip4 ( ip6_address_t *  ip6,
ip4_address_t ip4,
u32  fib_index 
)

Extract IPv4 address from the IPv4-embedded IPv6 addresses.

Parameters
ip6IPv4-embedded IPv6 addresses.
ip4IPv4 address.
fib_indexTenant FIB index.

Definition at line 1341 of file nat64.c.

+ Here is the caller graph for this function:

◆ nat64_free_hash()

int nat64_free_hash ( )

Definition at line 341 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_free_out_addr_and_port()

static void nat64_free_out_addr_and_port ( struct nat64_db_s db,
ip4_address_t addr,
u16  port,
u8  protocol 
)
static

Definition at line 777 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_get_icmp_timeout()

u32 nat64_get_icmp_timeout ( void  )

Get ICMP session timeout.

Returns
ICMP session timeout in seconds.

Definition at line 1058 of file nat64.c.

◆ nat64_get_tcp_est_timeout()

u32 nat64_get_tcp_est_timeout ( void  )

Get TCP established timeout.

Returns
TCP established timeout in seconds.

Definition at line 1092 of file nat64.c.

◆ nat64_get_tcp_trans_timeout()

u32 nat64_get_tcp_trans_timeout ( void  )

Get TCP transitory timeout.

Returns
TCP transitory timeout in seconds.

Definition at line 1084 of file nat64.c.

◆ nat64_get_udp_timeout()

u32 nat64_get_udp_timeout ( void  )

Get UDP session timeout.

Returns
UDP session timeout in seconds.

Definition at line 1026 of file nat64.c.

◆ nat64_get_worker_in2out()

u32 nat64_get_worker_in2out ( ip6_address_t *  addr)

Get worker thread index for NAT64 in2out.

Parameters
addrIPv6 src address.
Returns
worker thread index.

Definition at line 117 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_get_worker_out2in()

u32 nat64_get_worker_out2in ( vlib_buffer_t b,
ip4_header_t ip 
)

Get worker thread index for NAT64 out2in.

Parameters
ipIPv4 header.
Returns
worker thread index.

Definition at line 139 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_init()

clib_error_t* nat64_init ( vlib_main_t vm)

Initialize NAT64.

Parameters
vmvlib main.
Returns
error code.

Definition at line 211 of file nat64.c.

+ Here is the call graph for this function:

◆ nat64_init_hash()

int nat64_init_hash ( nat64_config_t  c)

Definition at line 317 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_interface_add_del()

int nat64_interface_add_del ( u32  sw_if_index,
u8  is_inside,
u8  is_add 
)

Enable/disable NAT64 feature on the interface.

Parameters
sw_if_indexIndex of the interface.
is_inside1 if inside, 0 if outside.
is_add1 if add, 0 if delete.
Returns
0 on success, non-zero value otherwise.

Definition at line 538 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_interfaces_walk()

void nat64_interfaces_walk ( nat64_interface_walk_fn_t  fn,
void *  ctx 
)

Walk NAT64 interfaces.

Parameters
fnThe function to invoke on each entry visited.
ctxA context passed in the visit function.

Definition at line 639 of file nat64.c.

+ Here is the caller graph for this function:

◆ nat64_ip4_add_del_interface_address_cb()

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 
)
static

Definition at line 79 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_plugin_disable()

int nat64_plugin_disable ( )

Definition at line 1553 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_plugin_enable()

int nat64_plugin_enable ( nat64_config_t  c)

Definition at line 1516 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_pool_addr_walk()

void nat64_pool_addr_walk ( nat64_pool_addr_walk_fn_t  fn,
void *  ctx 
)

Walk NAT64 pool.

Parameters
fnThe function to invoke on each entry visited.
ctxA context passed in the visit function.

Definition at line 440 of file nat64.c.

+ Here is the caller graph for this function:

◆ nat64_prefix_walk()

void nat64_prefix_walk ( nat64_prefix_walk_fn_t  fn,
void *  ctx 
)

Walk NAT64 prefixes.

Parameters
fnThe function to invoke on each entry visited.
ctxA context passed in the visit function.

Definition at line 1256 of file nat64.c.

+ Here is the caller graph for this function:

◆ nat64_random_port()

static_always_inline u16 nat64_random_port ( u16  min,
u16  max 
)

Definition at line 655 of file nat64.c.

+ Here is the call graph for this function:

◆ nat64_reset_timeouts()

void nat64_reset_timeouts ( )

Definition at line 1047 of file nat64.c.

+ Here is the caller graph for this function:

◆ nat64_session_reset_timeout()

void nat64_session_reset_timeout ( nat64_db_st_entry_t *  ste,
vlib_main_t vm 
)

Reset NAT64 session timeout.

Parameters
steSession table entry.
vmVLIB main.

Definition at line 1100 of file nat64.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nat64_set_icmp_timeout()

int nat64_set_icmp_timeout ( u32  timeout)

Set ICMP session timeout.

Parameters
timeoutTimeout value in seconds (if 0 reset to default value 60sec).
Returns
0 on success, non-zero value otherwise.

Definition at line 1034 of file nat64.c.

◆ nat64_set_tcp_timeouts()

int nat64_set_tcp_timeouts ( u32  trans,
u32  est 
)

Set TCP session timeouts.

Parameters
transTransitory timeout in seconds (if 0 reset to default value 240sec).
estEstablished timeout in seconds (if 0 reset to default value 7440sec).
Returns
0 on success, non-zero value otherwise.

Definition at line 1066 of file nat64.c.

◆ nat64_set_udp_timeout()

int nat64_set_udp_timeout ( u32  timeout)

Set UDP session timeout.

Parameters
timeoutTimeout value in seconds (if 0 reset to default value 300sec).
Returns
0 on success, non-zero value otherwise.

Definition at line 1013 of file nat64.c.

◆ nat64_static_bib_worker_fn()

static uword nat64_static_bib_worker_fn ( vlib_main_t vm,
vlib_node_runtime_t rt,
vlib_frame_t f 
)
static

Add/delete static BIB entry in worker thread.

Definition at line 815 of file nat64.c.

+ Here is the call graph for this function:

◆ nat64_tcp_session_set_state()

void nat64_tcp_session_set_state ( nat64_db_st_entry_t *  ste,
tcp_header_t tcp,
u8  is_ip6 
)

Set NAT64 TCP session state.

Parameters
steSession table entry.
tcpTCP header.
is_ip61 if IPv6 packet, 0 if IPv4.

Definition at line 1139 of file nat64.c.

+ Here is the caller graph for this function:

◆ nat64_validate_counters()

static void nat64_validate_counters ( nat64_main_t nm,
u32  sw_if_index 
)
static

Definition at line 497 of file nat64.c.

+ Here is the caller graph for this function:

◆ unformat_nat_protocol()

uword unformat_nat_protocol ( unformat_input_t input,
va_list *  args 
)

Definition at line 1613 of file nat64.c.

◆ VLIB_PLUGIN_REGISTER()

VLIB_PLUGIN_REGISTER ( )

◆ VNET_FEATURE_INIT() [1/4]

VNET_FEATURE_INIT ( nat64_in2out  ,
static   
)

◆ VNET_FEATURE_INIT() [2/4]

VNET_FEATURE_INIT ( nat64_out2in  ,
static   
)

◆ VNET_FEATURE_INIT() [3/4]

VNET_FEATURE_INIT ( nat64_in2out_handoff  ,
static   
)

◆ VNET_FEATURE_INIT() [4/4]

VNET_FEATURE_INIT ( nat64_out2in_handoff  ,
static   
)

Variable Documentation

◆ nat64_expire_worker_walk_node

vlib_node_registration_t nat64_expire_worker_walk_node
static
Initial value:
= {
.state = VLIB_NODE_STATE_INTERRUPT,
.name = "nat64-expire-worker-walk",
}
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.
Definition: nat64.c:1411

(constructor) VLIB_REGISTER_NODE (nat64_expire_worker_walk_node)

Definition at line 1435 of file nat64.c.

◆ nat64_main

nat64_main_t nat64_main

Definition at line 27 of file nat64.c.

◆ nat64_static_bib_worker_node

static vlib_node_registration_t nat64_static_bib_worker_node
static
Initial value:
= {
.state = VLIB_NODE_STATE_INTERRUPT,
.name = "nat64-static-bib-worker",
}
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.
Definition: nat64.c:815

(constructor) VLIB_REGISTER_NODE (nat64_static_bib_worker_node)

Definition at line 867 of file nat64.c.

◆ well_known_prefix

u8 well_known_prefix[]
static
Initial value:
= {
0x00, 0x64, 0xff, 0x9b,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
}

Definition at line 59 of file nat64.c.