FD.io VPP  v21.01.1
Vector Packet Processing
nat.c File Reference

NAT plugin global declarations. More...

+ Include dependency graph for nat.c:

Go to the source code of this file.

Macros

#define nat_init_simple_counter(c, n, sn)
 

Functions

 VNET_FEATURE_INIT (nat_pre_in2out, static)
 
 VNET_FEATURE_INIT (nat_pre_out2in, static)
 
 VNET_FEATURE_INIT (snat_in2out_worker_handoff, static)
 
 VNET_FEATURE_INIT (snat_out2in_worker_handoff, static)
 
 VNET_FEATURE_INIT (ip4_snat_in2out, static)
 
 VNET_FEATURE_INIT (ip4_snat_out2in, static)
 
 VNET_FEATURE_INIT (ip4_nat_classify, static)
 
 VNET_FEATURE_INIT (ip4_nat44_ed_in2out, static)
 
 VNET_FEATURE_INIT (ip4_nat44_ed_out2in, static)
 
 VNET_FEATURE_INIT (ip4_nat44_ed_classify, static)
 
 VNET_FEATURE_INIT (ip4_nat_handoff_classify, static)
 
 VNET_FEATURE_INIT (ip4_snat_in2out_fast, static)
 
 VNET_FEATURE_INIT (ip4_snat_out2in_fast, static)
 
 VNET_FEATURE_INIT (ip4_snat_hairpin_dst, static)
 
 VNET_FEATURE_INIT (ip4_nat44_ed_hairpin_dst, static)
 
 VNET_FEATURE_INIT (ip4_snat_in2out_output, static)
 
 VNET_FEATURE_INIT (ip4_snat_in2out_output_worker_handoff, static)
 
 VNET_FEATURE_INIT (ip4_snat_hairpin_src, static)
 
 VNET_FEATURE_INIT (nat_pre_in2out_output, static)
 
 VNET_FEATURE_INIT (ip4_nat44_ed_in2out_output, static)
 
 VNET_FEATURE_INIT (ip4_nat44_ed_hairpin_src, static)
 
 VNET_FEATURE_INIT (ip4_nat_hairpinning, static)
 
 VNET_FEATURE_INIT (ip4_nat44_ed_hairpinning, static)
 
 VLIB_PLUGIN_REGISTER ()
 
static u32 nat44_ed_get_worker_out2in_cb (vlib_buffer_t *b, ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
 
static u32 nat44_ed_get_worker_in2out_cb (ip4_header_t *ip, u32 rx_fib_index, u8 is_output)
 
static u32 snat_get_worker_out2in_cb (vlib_buffer_t *b, ip4_header_t *ip0, u32 rx_fib_index0, u8 is_output)
 
static u32 snat_get_worker_in2out_cb (ip4_header_t *ip0, u32 rx_fib_index0, u8 is_output)
 
static u32 nat_calc_bihash_buckets (u32 n_elts)
 
u8format_session_kvp (u8 *s, va_list *args)
 
u8format_static_mapping_kvp (u8 *s, va_list *args)
 
u8format_user_kvp (u8 *s, va_list *args)
 
u8format_ed_session_kvp (u8 *s, va_list *args)
 
void nat44_ei_free_session_data (snat_main_t *sm, snat_session_t *s, u32 thread_index, u8 is_ha)
 
static_always_inline void nat44_ei_user_del_sessions (snat_user_t *u, u32 thread_index)
 
int nat44_ei_user_del (ip4_address_t *addr, u32 fib_index)
 Delete specific NAT44 EI user and his sessions. More...
 
void nat_free_session_data (snat_main_t *sm, snat_session_t *s, u32 thread_index, u8 is_ha)
 Free NAT44 session data (lookup keys, external address port) More...
 
snat_user_tnat_user_get_or_create (snat_main_t *sm, ip4_address_t *addr, u32 fib_index, u32 thread_index)
 Find or create NAT user. More...
 
snat_session_t * nat_session_alloc_or_recycle (snat_main_t *sm, snat_user_t *u, u32 thread_index, f64 now)
 Allocate new NAT session or recycle last used. More...
 
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. More...
 
int snat_add_address (snat_main_t *sm, ip4_address_t *addr, u32 vrf_id, u8 twice_nat)
 Add external address to NAT44 pool. More...
 
static int is_snat_address_used_in_static_mapping (snat_main_t *sm, ip4_address_t addr)
 
static void snat_add_static_mapping_when_resolved (snat_main_t *sm, ip4_address_t l_addr, u16 l_port, u32 sw_if_index, u16 e_port, u32 vrf_id, nat_protocol_t proto, int addr_only, int is_add, u8 *tag, int twice_nat, int out2in_only, int identity_nat, ip4_address_t pool_addr, int exact)
 
static u32 get_thread_idx_by_port (u16 e_port)
 
void nat_ei_static_mapping_del_sessions (snat_main_t *sm, snat_main_per_thread_data_t *tsm, snat_user_key_t u_key, int addr_only, ip4_address_t e_addr, u16 e_port)
 
void nat_ed_static_mapping_del_sessions (snat_main_t *sm, snat_main_per_thread_data_t *tsm, ip4_address_t l_addr, u16 l_port, u8 protocol, u32 fib_index, int addr_only, ip4_address_t e_addr, u16 e_port)
 
int snat_add_static_mapping (ip4_address_t l_addr, ip4_address_t e_addr, u16 l_port, u16 e_port, u32 vrf_id, int addr_only, u32 sw_if_index, nat_protocol_t proto, int is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u8 identity_nat, ip4_address_t pool_addr, int exact)
 Add/delete NAT44 static mapping. More...
 
int nat44_add_del_lb_static_mapping (ip4_address_t e_addr, u16 e_port, nat_protocol_t proto, nat44_lb_addr_port_t *locals, u8 is_add, twice_nat_type_t twice_nat, u8 out2in_only, u8 *tag, u32 affinity)
 Add/delete static mapping with load-balancing (multiple backends) More...
 
int nat44_lb_static_mapping_add_del_local (ip4_address_t e_addr, u16 e_port, ip4_address_t l_addr, u16 l_port, nat_protocol_t proto, u32 vrf_id, u8 probability, u8 is_add)
 
int snat_del_address (snat_main_t *sm, ip4_address_t addr, u8 delete_sm, u8 twice_nat)
 Delete external address from NAT44 pool. More...
 
static void nat_validate_counters (snat_main_t *sm, u32 sw_if_index)
 
void expire_per_vrf_sessions (u32 fib_index)
 
void update_per_vrf_sessions_vec (u32 fib_index, int is_del)
 
int snat_interface_add_del (u32 sw_if_index, u8 is_inside, int is_del)
 Enable/disable NAT44 feature on the interface. More...
 
int snat_interface_add_del_output_feature (u32 sw_if_index, u8 is_inside, int is_del)
 Enable/disable NAT44 output feature on the interface (postrouting NAT) More...
 
int snat_set_workers (uword *bitmap)
 Set NAT plugin workers. More...
 
static void snat_update_outside_fib (ip4_main_t *im, uword opaque, u32 sw_if_index, u32 new_fib_index, u32 old_fib_index)
 
static void snat_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 void nat_ip4_add_del_addr_only_sm_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 int nat_alloc_addr_and_port_default (snat_address_t *addresses, u32 fib_index, u32 thread_index, nat_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread, u32 snat_thread_index)
 
void test_key_calc_split ()
 
static clib_error_tnat_ip_table_add_del (vnet_main_t *vnm, u32 table_id, u32 is_add)
 
 VNET_IP_TABLE_ADD_DEL_FUNCTION (nat_ip_table_add_del)
 
void nat44_set_node_indexes (snat_main_t *sm, vlib_main_t *vm)
 
static clib_error_tnat_init (vlib_main_t *vm)
 
int nat44_plugin_enable (nat44_config_t c)
 Enable NAT44 plugin. More...
 
void nat44_addresses_free (snat_address_t **addresses)
 
int nat44_plugin_disable ()
 Disable NAT44 plugin. More...
 
void snat_free_outside_address_and_port (snat_address_t *addresses, u32 thread_index, ip4_address_t *addr, u16 port, nat_protocol_t protocol)
 Free outside address and port pair. More...
 
static int nat_set_outside_address_and_port (snat_address_t *addresses, u32 thread_index, ip4_address_t addr, u16 port, nat_protocol_t protocol)
 
int snat_static_mapping_match (snat_main_t *sm, ip4_address_t match_addr, u16 match_port, u32 match_fib_index, nat_protocol_t match_protocol, ip4_address_t *mapping_addr, u16 *mapping_port, u32 *mapping_fib_index, u8 by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat, lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat, snat_static_mapping_t **out)
 Match NAT44 static mapping. More...
 
int snat_alloc_outside_address_and_port (snat_address_t *addresses, u32 fib_index, u32 thread_index, nat_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread, u32 snat_thread_index)
 Alloc outside address and port. More...
 
static int nat_alloc_addr_and_port_mape (snat_address_t *addresses, u32 fib_index, u32 thread_index, nat_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread, u32 snat_thread_index)
 
static int nat_alloc_addr_and_port_range (snat_address_t *addresses, u32 fib_index, u32 thread_index, nat_protocol_t proto, ip4_address_t *addr, u16 *port, u16 port_per_thread, u32 snat_thread_index)
 
void nat44_add_del_address_dpo (ip4_address_t addr, u8 is_add)
 Add/delete external address to FIB DPO (out2in DPO mode) More...
 
void nat_ha_sadd_cb (ip4_address_t *in_addr, u16 in_port, ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, ip4_address_t *ehn_addr, u16 ehn_port, u8 proto, u32 fib_index, u16 flags, u32 thread_index)
 
void nat_ha_sdel_cb (ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 ti)
 
void nat_ha_sref_cb (ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 total_pkts, u64 total_bytes, u32 thread_index)
 
void nat_ha_sadd_ed_cb (ip4_address_t *in_addr, u16 in_port, ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, ip4_address_t *ehn_addr, u16 ehn_port, u8 proto, u32 fib_index, u16 flags, u32 thread_index)
 
void nat_ha_sdel_ed_cb (ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 ti)
 
void nat_ha_sref_ed_cb (ip4_address_t *out_addr, u16 out_port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 fib_index, u32 total_pkts, u64 total_bytes, u32 thread_index)
 
u32 nat44_get_max_session_limit ()
 
int nat44_set_session_limit (u32 session_limit, u32 vrf_id)
 Set NAT44 session limit (session limit, vrf id) More...
 
int nat44_update_session_limit (u32 session_limit, u32 vrf_id)
 Update NAT44 session limit flushing all data (session limit, vrf id) More...
 
void nat44_db_init (snat_main_per_thread_data_t *tsm)
 Initialize NAT44 data. More...
 
void nat44_db_free (snat_main_per_thread_data_t *tsm)
 Free NAT44 data. More...
 
void nat44_sessions_clear ()
 Free all NAT44 sessions. More...
 
int snat_add_interface_address (snat_main_t *sm, u32 sw_if_index, int is_del, u8 twice_nat)
 Add/delete NAT44 pool address from specific interface. More...
 
int nat44_del_session (snat_main_t *sm, ip4_address_t *addr, u16 port, nat_protocol_t proto, u32 vrf_id, int is_in)
 Delete NAT44 session. More...
 
int nat44_del_ed_session (snat_main_t *sm, ip4_address_t *addr, u16 port, ip4_address_t *eh_addr, u16 eh_port, u8 proto, u32 vrf_id, int is_in)
 Delete NAT44 endpoint-dependent session. More...
 
void nat_set_alloc_addr_and_port_mape (u16 psid, u16 psid_offset, u16 psid_length)
 Set address and port assignment algorithm for MAP-E CE. More...
 
void nat_set_alloc_addr_and_port_range (u16 start_port, u16 end_port)
 Set address and port assignment algorithm for port range. More...
 
void nat_set_alloc_addr_and_port_default (void)
 Set address and port assignment algorithm to default/standard. More...
 
VLIB_NODE_FN() nat_default_node (vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
 

Variables

snat_main_t snat_main
 
vlib_node_registration_t nat_default_node
 (constructor) VLIB_REGISTER_NODE (nat_default_node) More...
 

Detailed Description

NAT plugin global declarations.

Definition in file nat.c.

Macro Definition Documentation

◆ nat_init_simple_counter

#define nat_init_simple_counter (   c,
  n,
  sn 
)
Value:
do \
{ \
c.name = n; \
c.stat_segment_name = sn; \
vlib_validate_simple_counter (&c, 0); \
vlib_zero_simple_counter (&c, 0); \
} while (0);
svmdb_client_t * c

Definition at line 2710 of file nat.c.

Function Documentation

◆ expire_per_vrf_sessions()

void expire_per_vrf_sessions ( u32  fib_index)

Definition at line 1917 of file nat.c.

+ Here is the caller graph for this function:

◆ format_ed_session_kvp()

u8* format_ed_session_kvp ( u8 s,
va_list *  args 
)

Definition at line 236 of file nat.c.

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

◆ format_session_kvp()

u8* format_session_kvp ( u8 s,
va_list *  args 
)

Definition at line 201 of file nat.c.

+ Here is the caller graph for this function:

◆ format_static_mapping_kvp()

u8* format_static_mapping_kvp ( u8 s,
va_list *  args 
)

Definition at line 211 of file nat.c.

+ Here is the caller graph for this function:

◆ format_user_kvp()

u8* format_user_kvp ( u8 s,
va_list *  args 
)

Definition at line 222 of file nat.c.

+ Here is the caller graph for this function:

◆ get_thread_idx_by_port()

static u32 get_thread_idx_by_port ( u16  e_port)
static

Definition at line 806 of file nat.c.

◆ is_snat_address_used_in_static_mapping()

static int is_snat_address_used_in_static_mapping ( snat_main_t sm,
ip4_address_t  addr 
)
static

Definition at line 755 of file nat.c.

+ Here is the caller graph for this function:

◆ nat44_add_del_address_dpo()

void nat44_add_del_address_dpo ( ip4_address_t  addr,
u8  is_add 
)

Add/delete external address to FIB DPO (out2in DPO mode)

Parameters
addrIPv4 address
is_add1 = add, 0 = delete
Returns
0 on success, non-zero value otherwise

Definition at line 3545 of file nat.c.

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

◆ nat44_add_del_lb_static_mapping()

int nat44_add_del_lb_static_mapping ( ip4_address_t  e_addr,
u16  e_port,
nat_protocol_t  proto,
nat44_lb_addr_port_t locals,
u8  is_add,
twice_nat_type_t  twice_nat,
u8  out2in_only,
u8 tag,
u32  affinity 
)

Add/delete static mapping with load-balancing (multiple backends)

Parameters
e_addrexternal IPv4 address
e_portexternal port number
protoL4 protocol
localslist of local backends
is_add1 = add, 0 = delete
twice_nattwice-nat mode
out2in_onlyif 1 rule match only out2in direction
tagopaque string tag
affinity0 = disabled, otherwise client IP affinity sticky time
Returns
0 on success, non-zero value otherwise

Definition at line 1365 of file nat.c.

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

◆ nat44_addresses_free()

void nat44_addresses_free ( snat_address_t **  addresses)

Definition at line 2992 of file nat.c.

+ Here is the caller graph for this function:

◆ nat44_db_free()

void nat44_db_free ( snat_main_per_thread_data_t tsm)

Free NAT44 data.

Parameters
tsmper thread data

Definition at line 4347 of file nat.c.

+ Here is the caller graph for this function:

◆ nat44_db_init()

void nat44_db_init ( snat_main_per_thread_data_t tsm)

Initialize NAT44 data.

Parameters
tsmper thread data

Definition at line 4288 of file nat.c.

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

◆ nat44_del_ed_session()

int nat44_del_ed_session ( snat_main_t sm,
ip4_address_t addr,
u16  port,
ip4_address_t eh_addr,
u16  eh_port,
u8  proto,
u32  vrf_id,
int  is_in 
)

Delete NAT44 endpoint-dependent session.

Parameters
smsnat global configuration data
addrIPv4 address
portL4 port number
protoL4 protocol
vrf_idVRF ID
is_in1 = inside network address and port pair, 0 = outside
Returns
0 on success, non-zero value otherwise

Definition at line 4660 of file nat.c.

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

◆ nat44_del_session()

int nat44_del_session ( snat_main_t sm,
ip4_address_t addr,
u16  port,
nat_protocol_t  proto,
u32  vrf_id,
int  is_in 
)

Delete NAT44 session.

Parameters
addrIPv4 address
portL4 port number
protoL4 protocol
vrf_idVRF ID
is_in1 = inside network address and port pair, 0 = outside
Returns
0 on success, non-zero value otherwise

Definition at line 4622 of file nat.c.

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

◆ nat44_ed_get_worker_in2out_cb()

static u32 nat44_ed_get_worker_in2out_cb ( ip4_header_t ip,
u32  rx_fib_index,
u8  is_output 
)
static

Definition at line 3673 of file nat.c.

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

◆ nat44_ed_get_worker_out2in_cb()

static u32 nat44_ed_get_worker_out2in_cb ( vlib_buffer_t b,
ip4_header_t ip,
u32  rx_fib_index,
u8  is_output 
)
static

Definition at line 3775 of file nat.c.

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

◆ nat44_ei_free_session_data()

void nat44_ei_free_session_data ( snat_main_t sm,
snat_session_t *  s,
u32  thread_index,
u8  is_ha 
)

Definition at line 258 of file nat.c.

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

◆ nat44_ei_user_del()

int nat44_ei_user_del ( ip4_address_t addr,
u32  fib_index 
)

Delete specific NAT44 EI user and his sessions.

Parameters
addrIPv4 address
fib_indexFIB table index

Definition at line 328 of file nat.c.

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

◆ nat44_ei_user_del_sessions()

static_always_inline void nat44_ei_user_del_sessions ( snat_user_t u,
u32  thread_index 
)

Definition at line 303 of file nat.c.

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

◆ nat44_get_max_session_limit()

u32 nat44_get_max_session_limit ( )

Definition at line 4239 of file nat.c.

+ Here is the caller graph for this function:

◆ nat44_lb_static_mapping_add_del_local()

int nat44_lb_static_mapping_add_del_local ( ip4_address_t  e_addr,
u16  e_port,
ip4_address_t  l_addr,
u16  l_port,
nat_protocol_t  proto,
u32  vrf_id,
u8  probability,
u8  is_add 
)

Definition at line 1599 of file nat.c.

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

◆ nat44_plugin_disable()

int nat44_plugin_disable ( )

Disable NAT44 plugin.

Returns
0 on success, non-zero value otherwise

Definition at line 3009 of file nat.c.

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

◆ nat44_plugin_enable()

int nat44_plugin_enable ( nat44_config_t  c)

Enable NAT44 plugin.

Parameters
cnat44_config_t
Returns
0 on success, non-zero value otherwise

Definition at line 2843 of file nat.c.

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

◆ nat44_sessions_clear()

void nat44_sessions_clear ( )

Free all NAT44 sessions.

Definition at line 4372 of file nat.c.

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

◆ nat44_set_node_indexes()

void nat44_set_node_indexes ( snat_main_t sm,
vlib_main_t vm 
)

Definition at line 2656 of file nat.c.

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

◆ nat44_set_session_limit()

int nat44_set_session_limit ( u32  session_limit,
u32  vrf_id 
)

Set NAT44 session limit (session limit, vrf id)

Parameters
session_limitSession limit
vrf_idVRF id
Returns
0 on success, non-zero value otherwise

Definition at line 4253 of file nat.c.

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

◆ nat44_update_session_limit()

int nat44_update_session_limit ( u32  session_limit,
u32  vrf_id 
)

Update NAT44 session limit flushing all data (session limit, vrf id)

Parameters
session_limitSession limit
vrf_idVRF id
Returns
0 on success, non-zero value otherwise

Definition at line 4272 of file nat.c.

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

◆ nat_alloc_addr_and_port_default()

static int nat_alloc_addr_and_port_default ( snat_address_t addresses,
u32  fib_index,
u32  thread_index,
nat_protocol_t  proto,
ip4_address_t addr,
u16 port,
u16  port_per_thread,
u32  snat_thread_index 
)
static

Definition at line 3360 of file nat.c.

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

◆ nat_alloc_addr_and_port_mape()

static int nat_alloc_addr_and_port_mape ( snat_address_t addresses,
u32  fib_index,
u32  thread_index,
nat_protocol_t  proto,
ip4_address_t addr,
u16 port,
u16  port_per_thread,
u32  snat_thread_index 
)
static

Definition at line 3449 of file nat.c.

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

◆ nat_alloc_addr_and_port_range()

static int nat_alloc_addr_and_port_range ( snat_address_t addresses,
u32  fib_index,
u32  thread_index,
nat_protocol_t  proto,
ip4_address_t addr,
u16 port,
u16  port_per_thread,
u32  snat_thread_index 
)
static

Definition at line 3498 of file nat.c.

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

◆ nat_calc_bihash_buckets()

static u32 nat_calc_bihash_buckets ( u32  n_elts)
static

Definition at line 4219 of file nat.c.

+ Here is the caller graph for this function:

◆ nat_default_node()

VLIB_NODE_FN() nat_default_node ( vlib_main_t vm,
vlib_node_runtime_t node,
vlib_frame_t frame 
)

Definition at line 4729 of file nat.c.

◆ nat_ed_static_mapping_del_sessions()

void nat_ed_static_mapping_del_sessions ( snat_main_t sm,
snat_main_per_thread_data_t tsm,
ip4_address_t  l_addr,
u16  l_port,
u8  protocol,
u32  fib_index,
int  addr_only,
ip4_address_t  e_addr,
u16  e_port 
)

Definition at line 874 of file nat.c.

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

◆ nat_ei_static_mapping_del_sessions()

void nat_ei_static_mapping_del_sessions ( snat_main_t sm,
snat_main_per_thread_data_t tsm,
snat_user_key_t  u_key,
int  addr_only,
ip4_address_t  e_addr,
u16  e_port 
)

Definition at line 820 of file nat.c.

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

◆ nat_free_session_data()

void nat_free_session_data ( snat_main_t sm,
snat_session_t *  s,
u32  thread_index,
u8  is_ha 
)

Free NAT44 session data (lookup keys, external address port)

Parameters
smsnat global configuration data
sNAT session
thread_indexthread index
is_hais HA event

Definition at line 376 of file nat.c.

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

◆ nat_ha_sadd_cb()

void nat_ha_sadd_cb ( ip4_address_t in_addr,
u16  in_port,
ip4_address_t out_addr,
u16  out_port,
ip4_address_t eh_addr,
u16  eh_port,
ip4_address_t ehn_addr,
u16  ehn_port,
u8  proto,
u32  fib_index,
u16  flags,
u32  thread_index 
)

Definition at line 3932 of file nat.c.

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

◆ nat_ha_sadd_ed_cb()

void nat_ha_sadd_ed_cb ( ip4_address_t in_addr,
u16  in_port,
ip4_address_t out_addr,
u16  out_port,
ip4_address_t eh_addr,
u16  eh_port,
ip4_address_t ehn_addr,
u16  ehn_port,
u8  proto,
u32  fib_index,
u16  flags,
u32  thread_index 
)

Definition at line 4071 of file nat.c.

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

◆ nat_ha_sdel_cb()

void nat_ha_sdel_cb ( ip4_address_t out_addr,
u16  out_port,
ip4_address_t eh_addr,
u16  eh_port,
u8  proto,
u32  fib_index,
u32  ti 
)

Definition at line 4021 of file nat.c.

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

◆ nat_ha_sdel_ed_cb()

void nat_ha_sdel_ed_cb ( ip4_address_t out_addr,
u16  out_port,
ip4_address_t eh_addr,
u16  eh_port,
u8  proto,
u32  fib_index,
u32  ti 
)

Definition at line 4168 of file nat.c.

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

◆ nat_ha_sref_cb()

void nat_ha_sref_cb ( ip4_address_t out_addr,
u16  out_port,
ip4_address_t eh_addr,
u16  eh_port,
u8  proto,
u32  fib_index,
u32  total_pkts,
u64  total_bytes,
u32  thread_index 
)

Definition at line 4050 of file nat.c.

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

◆ nat_ha_sref_ed_cb()

void nat_ha_sref_ed_cb ( ip4_address_t out_addr,
u16  out_port,
ip4_address_t eh_addr,
u16  eh_port,
u8  proto,
u32  fib_index,
u32  total_pkts,
u64  total_bytes,
u32  thread_index 
)

Definition at line 4197 of file nat.c.

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

◆ nat_init()

static clib_error_t* nat_init ( vlib_main_t vm)
static

Definition at line 2720 of file nat.c.

+ Here is the call graph for this function:

◆ nat_ip4_add_del_addr_only_sm_cb()

static void nat_ip4_add_del_addr_only_sm_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 4401 of file nat.c.

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

◆ nat_ip_table_add_del()

static clib_error_t* nat_ip_table_add_del ( vnet_main_t vnm,
u32  table_id,
u32  is_add 
)
static

Definition at line 2635 of file nat.c.

+ Here is the call graph for this function:

◆ nat_session_alloc_or_recycle()

snat_session_t* nat_session_alloc_or_recycle ( snat_main_t sm,
snat_user_t u,
u32  thread_index,
f64  now 
)

Allocate new NAT session or recycle last used.

Parameters
smsnat global configuration data
uNAT user
thread_indexthread index
nowtime now
Returns
session data structure on success otherwise zero value

Definition at line 574 of file nat.c.

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

◆ nat_set_alloc_addr_and_port_default()

void nat_set_alloc_addr_and_port_default ( void  )

Set address and port assignment algorithm to default/standard.

Definition at line 4721 of file nat.c.

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

◆ nat_set_alloc_addr_and_port_mape()

void nat_set_alloc_addr_and_port_mape ( u16  psid,
u16  psid_offset,
u16  psid_length 
)

Set address and port assignment algorithm for MAP-E CE.

Parameters
psidPort Set Identifier value
psid_offsetnumber of offset bits
psid_lengthlength of PSID

Definition at line 4698 of file nat.c.

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

◆ nat_set_alloc_addr_and_port_range()

void nat_set_alloc_addr_and_port_range ( u16  start_port,
u16  end_port 
)

Set address and port assignment algorithm for port range.

Parameters
start_portbeginning of the port range
end_portend of the port range

Definition at line 4710 of file nat.c.

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

◆ nat_set_outside_address_and_port()

static int nat_set_outside_address_and_port ( snat_address_t addresses,
u32  thread_index,
ip4_address_t  addr,
u16  port,
nat_protocol_t  protocol 
)
static

Definition at line 3146 of file nat.c.

+ Here is the caller graph for this function:

◆ nat_user_get_or_create()

snat_user_t* nat_user_get_or_create ( snat_main_t sm,
ip4_address_t addr,
u32  fib_index,
u32  thread_index 
)

Find or create NAT user.

Parameters
smsnat global configuration data
addrIPv4 address
fib_indexFIB table index
thread_indexthread index
Returns
NAT user data structure on success otherwise zero value

Definition at line 514 of file nat.c.

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

◆ nat_validate_counters()

static void nat_validate_counters ( snat_main_t sm,
u32  sw_if_index 
)
static

Definition at line 1883 of file nat.c.

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

◆ snat_add_address()

int snat_add_address ( snat_main_t sm,
ip4_address_t addr,
u32  vrf_id,
u8  twice_nat 
)

Add external address to NAT44 pool.

Parameters
smsnat global configuration data
addrIPv4 address
vrf_idVRF id of tenant, ~0 means independent of VRF
twice_nat1 if twice NAT address
Returns
0 on success, non-zero value otherwise

Definition at line 680 of file nat.c.

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

◆ snat_add_del_addr_to_fib()

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.

Add the external NAT address to the FIB as receive entries. This ensures that VPP will reply to ARP for this address and we don't need to enable proxy ARP on the outside interface.

Parameters
addrIPv4 address
plenaddress prefix length
sw_if_indexsoftware index of the outside interface
is_add0 = delete, 1 = add.

Definition at line 651 of file nat.c.

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

◆ snat_add_interface_address()

int snat_add_interface_address ( snat_main_t sm,
u32  sw_if_index,
int  is_del,
u8  twice_nat 
)

Add/delete NAT44 pool address from specific interface.

Parameters
sw_if_indexsoftware index of the interface
is_del1 = delete, 0 = add
twice_nat1 = twice NAT address for external hosts
Returns
0 on success, non-zero value otherwise

Definition at line 4554 of file nat.c.

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

◆ snat_add_static_mapping()

int snat_add_static_mapping ( ip4_address_t  l_addr,
ip4_address_t  e_addr,
u16  l_port,
u16  e_port,
u32  vrf_id,
int  addr_only,
u32  sw_if_index,
nat_protocol_t  proto,
int  is_add,
twice_nat_type_t  twice_nat,
u8  out2in_only,
u8 tag,
u8  identity_nat,
ip4_address_t  pool_addr,
int  exact 
)

Add/delete NAT44 static mapping.

Parameters
l_addrlocal IPv4 address
e_addrexternal IPv4 address
l_portlocal port number
e_portexternal port number
vrf_idlocal VRF ID
addr_only1 = 1:1NAT, 0 = 1:1NAPT
sw_if_indexuse interface address as external IPv4 address
protoL4 protocol
is_add1 = add, 0 = delete
twice_nattwice-nat mode
out2in_onlyif 1 rule match only out2in direction
tagopaque string tag
identity_natidentity NAT
pool_addrpool IPv4 address
exact1 = exact pool address
Returns
0 on success, non-zero value otherwise

Definition at line 920 of file nat.c.

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

◆ snat_add_static_mapping_when_resolved()

static void snat_add_static_mapping_when_resolved ( snat_main_t sm,
ip4_address_t  l_addr,
u16  l_port,
u32  sw_if_index,
u16  e_port,
u32  vrf_id,
nat_protocol_t  proto,
int  addr_only,
int  is_add,
u8 tag,
int  twice_nat,
int  out2in_only,
int  identity_nat,
ip4_address_t  pool_addr,
int  exact 
)
static

Definition at line 774 of file nat.c.

+ Here is the caller graph for this function:

◆ snat_alloc_outside_address_and_port()

int snat_alloc_outside_address_and_port ( snat_address_t addresses,
u32  fib_index,
u32  thread_index,
nat_protocol_t  proto,
ip4_address_t addr,
u16 port,
u16  port_per_thread,
u32  snat_thread_index 
)

Alloc outside address and port.

Parameters
addressesvector of outside addresses
fib_indexFIB table index
thread_indexthread index
port_per_threadnumber of ports per thread
snat_thread_indexNAT thread index
Returns
0 on success, non-zero value otherwise

Definition at line 3343 of file nat.c.

+ Here is the caller graph for this function:

◆ snat_del_address()

int snat_del_address ( snat_main_t sm,
ip4_address_t  addr,
u8  delete_sm,
u8  twice_nat 
)

Delete external address from NAT44 pool.

Parameters
smsnat global configuration data
addrIPv4 address
delete_sm1 if delete static mapping using address
twice_nat1 if twice NAT address
Returns
0 on success, non-zero value otherwise

Definition at line 1750 of file nat.c.

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

◆ snat_free_outside_address_and_port()

void snat_free_outside_address_and_port ( snat_address_t addresses,
u32  thread_index,
ip4_address_t addr,
u16  port,
nat_protocol_t  protocol 
)

Free outside address and port pair.

Parameters
addressesvector of outside addresses
thread_indexthread index
keyaddress, port and protocol

Definition at line 3108 of file nat.c.

+ Here is the caller graph for this function:

◆ snat_get_worker_in2out_cb()

static u32 snat_get_worker_in2out_cb ( ip4_header_t ip0,
u32  rx_fib_index0,
u8  is_output 
)
static

Definition at line 3569 of file nat.c.

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

◆ snat_get_worker_out2in_cb()

static u32 snat_get_worker_out2in_cb ( vlib_buffer_t b,
ip4_header_t ip0,
u32  rx_fib_index0,
u8  is_output 
)
static

Definition at line 3589 of file nat.c.

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

◆ snat_interface_add_del()

int snat_interface_add_del ( u32  sw_if_index,
u8  is_inside,
int  is_del 
)

Enable/disable NAT44 feature on the interface.

Parameters
sw_if_indexsoftware index of the interface
is_inside1 = inside, 0 = outside
is_del1 = delete, 0 = add
Returns
0 on success, non-zero value otherwise

Definition at line 1976 of file nat.c.

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

◆ snat_interface_add_del_output_feature()

int snat_interface_add_del_output_feature ( u32  sw_if_index,
u8  is_inside,
int  is_del 
)

Enable/disable NAT44 output feature on the interface (postrouting NAT)

Parameters
sw_if_indexsoftware index of the interface
is_inside1 = inside, 0 = outside
is_del1 = delete, 0 = add
Returns
0 on success, non-zero value otherwise

Definition at line 2242 of file nat.c.

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

◆ snat_ip4_add_del_interface_address_cb()

static void snat_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 4469 of file nat.c.

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

◆ snat_set_workers()

int snat_set_workers ( uword bitmap)

Set NAT plugin workers.

Parameters
bitmapNAT workers bitmap
Returns
0 on success, non-zero value otherwise

Definition at line 2457 of file nat.c.

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

◆ snat_static_mapping_match()

int snat_static_mapping_match ( snat_main_t sm,
ip4_address_t  match_addr,
u16  match_port,
u32  match_fib_index,
nat_protocol_t  match_protocol,
ip4_address_t mapping_addr,
u16 mapping_port,
u32 mapping_fib_index,
u8  by_external,
u8 is_addr_only,
twice_nat_type_t twice_nat,
lb_nat_type_t lb,
ip4_address_t ext_host_addr,
u8 is_identity_nat,
snat_static_mapping_t **  out 
)

Match NAT44 static mapping.

Parameters
keyaddress and port to match
addrexternal/local address of the matched mapping
portport of the matched mapping
fib_indexfib index of the matched mapping
by_externalif 0 match by local address otherwise match by external address
is_addr_only1 if matched mapping is address only
twice_natmatched mapping is twice NAT type
lb1 if matched mapping is load-balanced
ext_host_addrexternal host address
is_identity_nat1 if indentity mapping
outif !=0 set to pointer of the mapping structure
Returns
0 if match found otherwise 1.

Definition at line 3183 of file nat.c.

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

◆ snat_update_outside_fib()

static void snat_update_outside_fib ( ip4_main_t im,
uword  opaque,
u32  sw_if_index,
u32  new_fib_index,
u32  old_fib_index 
)
static

Definition at line 2485 of file nat.c.

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

◆ test_key_calc_split()

void test_key_calc_split ( )

Definition at line 2583 of file nat.c.

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

◆ update_per_vrf_sessions_vec()

void update_per_vrf_sessions_vec ( u32  fib_index,
int  is_del 
)

Definition at line 1939 of file nat.c.

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

◆ VLIB_PLUGIN_REGISTER()

VLIB_PLUGIN_REGISTER ( )

◆ VNET_FEATURE_INIT() [1/23]

VNET_FEATURE_INIT ( nat_pre_in2out  ,
static   
)

◆ VNET_FEATURE_INIT() [2/23]

VNET_FEATURE_INIT ( nat_pre_out2in  ,
static   
)

◆ VNET_FEATURE_INIT() [3/23]

VNET_FEATURE_INIT ( snat_in2out_worker_handoff  ,
static   
)

◆ VNET_FEATURE_INIT() [4/23]

VNET_FEATURE_INIT ( snat_out2in_worker_handoff  ,
static   
)

◆ VNET_FEATURE_INIT() [5/23]

VNET_FEATURE_INIT ( ip4_snat_in2out  ,
static   
)

◆ VNET_FEATURE_INIT() [6/23]

VNET_FEATURE_INIT ( ip4_snat_out2in  ,
static   
)

◆ VNET_FEATURE_INIT() [7/23]

VNET_FEATURE_INIT ( ip4_nat_classify  ,
static   
)

◆ VNET_FEATURE_INIT() [8/23]

VNET_FEATURE_INIT ( ip4_nat44_ed_in2out  ,
static   
)

◆ VNET_FEATURE_INIT() [9/23]

VNET_FEATURE_INIT ( ip4_nat44_ed_out2in  ,
static   
)

◆ VNET_FEATURE_INIT() [10/23]

VNET_FEATURE_INIT ( ip4_nat44_ed_classify  ,
static   
)

◆ VNET_FEATURE_INIT() [11/23]

VNET_FEATURE_INIT ( ip4_nat_handoff_classify  ,
static   
)

◆ VNET_FEATURE_INIT() [12/23]

VNET_FEATURE_INIT ( ip4_snat_in2out_fast  ,
static   
)

◆ VNET_FEATURE_INIT() [13/23]

VNET_FEATURE_INIT ( ip4_snat_out2in_fast  ,
static   
)

◆ VNET_FEATURE_INIT() [14/23]

VNET_FEATURE_INIT ( ip4_snat_hairpin_dst  ,
static   
)

◆ VNET_FEATURE_INIT() [15/23]

VNET_FEATURE_INIT ( ip4_nat44_ed_hairpin_dst  ,
static   
)

◆ VNET_FEATURE_INIT() [16/23]

VNET_FEATURE_INIT ( ip4_snat_in2out_output  ,
static   
)

◆ VNET_FEATURE_INIT() [17/23]

VNET_FEATURE_INIT ( ip4_snat_in2out_output_worker_handoff  ,
static   
)

◆ VNET_FEATURE_INIT() [18/23]

VNET_FEATURE_INIT ( ip4_snat_hairpin_src  ,
static   
)

◆ VNET_FEATURE_INIT() [19/23]

VNET_FEATURE_INIT ( nat_pre_in2out_output  ,
static   
)

◆ VNET_FEATURE_INIT() [20/23]

VNET_FEATURE_INIT ( ip4_nat44_ed_in2out_output  ,
static   
)

◆ VNET_FEATURE_INIT() [21/23]

VNET_FEATURE_INIT ( ip4_nat44_ed_hairpin_src  ,
static   
)

◆ VNET_FEATURE_INIT() [22/23]

VNET_FEATURE_INIT ( ip4_nat_hairpinning  ,
static   
)

◆ VNET_FEATURE_INIT() [23/23]

VNET_FEATURE_INIT ( ip4_nat44_ed_hairpinning  ,
static   
)

◆ VNET_IP_TABLE_ADD_DEL_FUNCTION()

VNET_IP_TABLE_ADD_DEL_FUNCTION ( nat_ip_table_add_del  )
+ Here is the caller graph for this function:

Variable Documentation

◆ nat_default_node

vlib_node_registration_t nat_default_node
Initial value:
= {
.name = "nat-default",
.vector_size = sizeof (u32),
.format_trace = 0,
.n_errors = 0,
.n_next_nodes = NAT_N_NEXT,
.next_nodes = {
[NAT_NEXT_DROP] = "error-drop",
[NAT_NEXT_ICMP_ERROR] = "ip4-icmp-error",
[NAT_NEXT_IN2OUT_ED_FAST_PATH] = "nat44-ed-in2out",
[NAT_NEXT_IN2OUT_ED_SLOW_PATH] = "nat44-ed-in2out-slowpath",
[NAT_NEXT_IN2OUT_ED_OUTPUT_FAST_PATH] = "nat44-ed-in2out-output",
[NAT_NEXT_IN2OUT_ED_OUTPUT_SLOW_PATH] = "nat44-ed-in2out-output-slowpath",
[NAT_NEXT_OUT2IN_ED_FAST_PATH] = "nat44-ed-out2in",
[NAT_NEXT_OUT2IN_ED_SLOW_PATH] = "nat44-ed-out2in-slowpath",
[NAT_NEXT_OUT2IN_ED_HANDOFF] = "nat44-ed-out2in-handoff",
[NAT_NEXT_IN2OUT_CLASSIFY] = "nat44-in2out-worker-handoff",
[NAT_NEXT_OUT2IN_CLASSIFY] = "nat44-out2in-worker-handoff",
},
}
Definition: nat.h:94
unsigned int u32
Definition: types.h:88
vl_api_fib_path_type_t type
Definition: fib_types.api:123

(constructor) VLIB_REGISTER_NODE (nat_default_node)

Definition at line 4737 of file nat.c.

◆ snat_main

snat_main_t snat_main

Definition at line 39 of file nat.c.