FD.io VPP  v17.07.01-10-g3be13f0
Vector Packet Processing
snat.c File Reference
+ Include dependency graph for snat.c:

Go to the source code of this file.

Functions

 VNET_FEATURE_INIT (ip4_snat_in2out, static)
 
 VNET_FEATURE_INIT (ip4_snat_out2in, static)
 
 VNET_FEATURE_INIT (ip4_snat_det_in2out, static)
 
 VNET_FEATURE_INIT (ip4_snat_det_out2in, static)
 
 VNET_FEATURE_INIT (ip4_snat_in2out_worker_handoff, static)
 
 VNET_FEATURE_INIT (ip4_snat_out2in_worker_handoff, static)
 
 VNET_FEATURE_INIT (ip4_snat_in2out_fast, static)
 
 VNET_FEATURE_INIT (ip4_snat_out2in_fast, static)
 
 VLIB_PLUGIN_REGISTER ()
 
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...
 
void snat_add_address (snat_main_t *sm, ip4_address_t *addr, u32 vrf_id)
 
static int is_snat_address_used_in_static_mapping (snat_main_t *sm, ip4_address_t addr)
 
void increment_v4_address (ip4_address_t *a)
 
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, snat_protocol_t proto, int addr_only, int is_add)
 
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, snat_protocol_t proto, int is_add)
 Add static mapping. More...
 
int snat_del_address (snat_main_t *sm, ip4_address_t addr, u8 delete_sm)
 
int snat_interface_add_del (u32 sw_if_index, u8 is_inside, int is_del)
 
int snat_set_workers (uword *bitmap)
 
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 clib_error_tsnat_init (vlib_main_t *vm)
 
void snat_free_outside_address_and_port (snat_main_t *sm, snat_session_key_t *k, u32 address_index)
 
int snat_static_mapping_match (snat_main_t *sm, snat_session_key_t match, snat_session_key_t *mapping, u8 by_external, u8 *is_addr_only)
 Match SNAT static mapping. More...
 
int snat_alloc_outside_address_and_port (snat_main_t *sm, u32 fib_index, snat_session_key_t *k, u32 *address_indexp)
 
static clib_error_tadd_address_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_tsnat_feature_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
uword unformat_snat_protocol (unformat_input_t *input, va_list *args)
 
u8format_snat_protocol (u8 *s, va_list *args)
 
static clib_error_tadd_static_mapping_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_tset_workers_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_tsnat_ipfix_logging_enable_disable_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static u32 snat_get_worker_in2out_cb (ip4_header_t *ip0, u32 rx_fib_index0)
 
static u32 snat_get_worker_out2in_cb (ip4_header_t *ip0, u32 rx_fib_index0)
 
static clib_error_tsnat_config (vlib_main_t *vm, unformat_input_t *input)
 
u8format_snat_session_state (u8 *s, va_list *args)
 
u8format_snat_key (u8 *s, va_list *args)
 
u8format_snat_session (u8 *s, va_list *args)
 
u8format_snat_user (u8 *s, va_list *args)
 
u8format_snat_static_mapping (u8 *s, va_list *args)
 
u8format_snat_static_map_to_resolve (u8 *s, va_list *args)
 
u8format_det_map_ses (u8 *s, va_list *args)
 
static clib_error_tshow_snat_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
int snat_add_interface_address (snat_main_t *sm, u32 sw_if_index, int is_del)
 
static clib_error_tsnat_add_interface_address_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_tsnat_det_map_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_tsnat_det_forward_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_tsnat_det_reverse_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_tset_timeout_command_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_tsnat_det_close_session_out_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 
static clib_error_tsnat_det_close_session_in_fn (vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
 

Variables

snat_main_t snat_main
 
static vlib_cli_command_t add_address_command
 (constructor) VLIB_CLI_COMMAND (add_address_command) More...
 
static vlib_cli_command_t set_interface_snat_command
 (constructor) VLIB_CLI_COMMAND (set_interface_snat_command) More...
 
static vlib_cli_command_t add_static_mapping_command
 (constructor) VLIB_CLI_COMMAND (add_static_mapping_command) More...
 
static vlib_cli_command_t set_workers_command
 (constructor) VLIB_CLI_COMMAND (set_workers_command) More...
 
static vlib_cli_command_t snat_ipfix_logging_enable_disable_command
 (constructor) VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command) More...
 
static vlib_cli_command_t show_snat_command
 (constructor) VLIB_CLI_COMMAND (show_snat_command) More...
 
static vlib_cli_command_t snat_add_interface_address_command
 (constructor) VLIB_CLI_COMMAND (snat_add_interface_address_command) More...
 
static vlib_cli_command_t snat_det_map_command
 (constructor) VLIB_CLI_COMMAND (snat_det_map_command) More...
 
static vlib_cli_command_t snat_det_forward_command
 (constructor) VLIB_CLI_COMMAND (snat_det_forward_command) More...
 
static vlib_cli_command_t snat_det_reverse_command
 (constructor) VLIB_CLI_COMMAND (snat_det_reverse_command) More...
 
static vlib_cli_command_t set_timeout_command
 (constructor) VLIB_CLI_COMMAND (set_timeout_command) More...
 
static vlib_cli_command_t snat_det_close_sesion_out_command
 (constructor) VLIB_CLI_COMMAND (snat_det_close_sesion_out_command) More...
 
static vlib_cli_command_t snat_det_close_session_in_command
 (constructor) VLIB_CLI_COMMAND (snat_det_close_session_in_command) More...
 

Function Documentation

static clib_error_t* add_address_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 943 of file snat.c.

+ Here is the call graph for this function:

static clib_error_t* add_static_mapping_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 1144 of file snat.c.

+ Here is the call graph for this function:

u8* format_det_map_ses ( u8 s,
va_list *  args 
)

Definition at line 1733 of file snat.c.

+ Here is the call graph for this function:

u8* format_snat_key ( u8 s,
va_list *  args 
)

Definition at line 1615 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_snat_protocol ( u8 s,
va_list *  args 
)

Definition at line 1126 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_snat_session ( u8 s,
va_list *  args 
)

Definition at line 1634 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_snat_session_state ( u8 s,
va_list *  args 
)

Definition at line 1598 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_snat_static_map_to_resolve ( u8 s,
va_list *  args 
)

Definition at line 1711 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u8* format_snat_static_mapping ( u8 s,
va_list *  args 
)

Definition at line 1692 of file snat.c.

+ Here is the call graph for this function:

u8* format_snat_user ( u8 s,
va_list *  args 
)

Definition at line 1652 of file snat.c.

+ Here is the call graph for this function:

void increment_v4_address ( ip4_address_t a)

Definition at line 175 of file snat.c.

+ Here is the caller graph for this function:

static int is_snat_address_used_in_static_mapping ( snat_main_t sm,
ip4_address_t  addr 
)
static

Definition at line 162 of file snat.c.

+ Here is the caller graph for this function:

static clib_error_t* set_timeout_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 2350 of file snat.c.

+ Here is the call graph for this function:

static clib_error_t* set_workers_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 1257 of file snat.c.

+ Here is the call graph for this function:

static clib_error_t* show_snat_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 1763 of file snat.c.

+ Here is the call graph for this function:

void snat_add_address ( snat_main_t sm,
ip4_address_t addr,
u32  vrf_id 
)

Definition at line 128 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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_indexInterface.
is_addIf 0 delete, otherwise add.

Definition at line 96 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 2043 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static clib_error_t* snat_add_interface_address_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 2101 of file snat.c.

+ Here is the call graph for this function:

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,
snat_protocol_t  proto,
int  is_add 
)

Add static mapping.

Create static mapping between local addr+port and external addr+port.

Parameters
l_addrLocal IPv4 address.
e_addrExternal IPv4 address.
l_portLocal port number.
e_portExternal port number.
vrf_idVRF ID.
addr_onlyIf 0 address port and pair mapping, otherwise address only.
sw_if_indexExternal port instead of specific IP address.
is_addIf 0 delete static mapping, otherwise add.
Returns

Definition at line 223 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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,
snat_protocol_t  proto,
int  addr_only,
int  is_add 
)
static

Definition at line 184 of file snat.c.

+ Here is the caller graph for this function:

int snat_alloc_outside_address_and_port ( snat_main_t sm,
u32  fib_index,
snat_session_key_t k,
u32 address_indexp 
)

Definition at line 891 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static clib_error_t* snat_config ( vlib_main_t vm,
unformat_input_t input 
)
static

Definition at line 1477 of file snat.c.

+ Here is the call graph for this function:

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

Definition at line 521 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static clib_error_t* snat_det_close_session_in_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 2487 of file snat.c.

+ Here is the call graph for this function:

static clib_error_t* snat_det_close_session_out_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 2416 of file snat.c.

+ Here is the call graph for this function:

static clib_error_t* snat_det_forward_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 2223 of file snat.c.

+ Here is the call graph for this function:

static clib_error_t* snat_det_map_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 2157 of file snat.c.

+ Here is the call graph for this function:

static clib_error_t* snat_det_reverse_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 2285 of file snat.c.

+ Here is the call graph for this function:

static clib_error_t* snat_feature_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 1042 of file snat.c.

+ Here is the call graph for this function:

void snat_free_outside_address_and_port ( snat_main_t sm,
snat_session_key_t k,
u32  address_index 
)

Definition at line 794 of file snat.c.

+ Here is the caller graph for this function:

static u32 snat_get_worker_in2out_cb ( ip4_header_t ip0,
u32  rx_fib_index0 
)
static

Definition at line 1387 of file snat.c.

+ Here is the caller graph for this function:

static u32 snat_get_worker_out2in_cb ( ip4_header_t ip0,
u32  rx_fib_index0 
)
static

Definition at line 1421 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static clib_error_t* snat_init ( vlib_main_t vm)
static

Definition at line 725 of file snat.c.

+ Here is the call graph for this function:

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

Definition at line 621 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 1974 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static clib_error_t* snat_ipfix_logging_enable_disable_command_fn ( vlib_main_t vm,
unformat_input_t input,
vlib_cli_command_t cmd 
)
static

Definition at line 1326 of file snat.c.

+ Here is the call graph for this function:

int snat_set_workers ( uword bitmap)

Definition at line 695 of file snat.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int snat_static_mapping_match ( snat_main_t sm,
snat_session_key_t  match,
snat_session_key_t mapping,
u8  by_external,
u8 is_addr_only 
)

Match SNAT static mapping.

Parameters
smSNAT main.
matchAddress and port to match.
mappingExternal or local address and port of the matched mapping.
by_externalIf 0 match by local address otherwise match by external address.
is_addr_onlyIf matched mapping is address only
Returns
0 if match found otherwise 1.

Definition at line 835 of file snat.c.

+ Here is the caller graph for this function:

uword unformat_snat_protocol ( unformat_input_t input,
va_list *  args 
)

Definition at line 1112 of file snat.c.

+ Here is the caller graph for this function:

VLIB_PLUGIN_REGISTER ( )
VNET_FEATURE_INIT ( ip4_snat_in2out  ,
static   
)
VNET_FEATURE_INIT ( ip4_snat_out2in  ,
static   
)
VNET_FEATURE_INIT ( ip4_snat_det_in2out  ,
static   
)
VNET_FEATURE_INIT ( ip4_snat_det_out2in  ,
static   
)
VNET_FEATURE_INIT ( ip4_snat_in2out_worker_handoff  ,
static   
)
VNET_FEATURE_INIT ( ip4_snat_out2in_worker_handoff  ,
static   
)
VNET_FEATURE_INIT ( ip4_snat_in2out_fast  ,
static   
)
VNET_FEATURE_INIT ( ip4_snat_out2in_fast  ,
static   
)

Variable Documentation

vlib_cli_command_t add_address_command
static
Initial value:
= {
.path = "snat add address",
.short_help = "snat add addresses <ip4-range-start> [- <ip4-range-end>] "
"[tenant-vrf <vrf-id>] [del]",
}
static clib_error_t * add_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:943

(constructor) VLIB_CLI_COMMAND (add_address_command)

Definition at line 1034 of file snat.c.

vlib_cli_command_t add_static_mapping_command
static
Initial value:
= {
.path = "snat add static mapping",
.short_help =
"snat add static mapping local tcp|udp|icmp <addr> [<port>] external <addr> [<port>] [vrf <table-id>] [del]",
}
static clib_error_t * add_static_mapping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:1144

(constructor) VLIB_CLI_COMMAND (add_static_mapping_command)

Definition at line 1249 of file snat.c.

vlib_cli_command_t set_interface_snat_command
static
Initial value:
= {
.path = "set interface snat",
.short_help = "set interface snat in <intfc> out <intfc> [del]",
}
static clib_error_t * snat_feature_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:1042

(constructor) VLIB_CLI_COMMAND (set_interface_snat_command)

Definition at line 1105 of file snat.c.

vlib_cli_command_t set_timeout_command
static
Initial value:
= {
.path = "set snat deterministic timeout",
.short_help =
"set snat deterministic timeout [udp <sec> | tcp-established <sec> "
"tcp-transitory <sec> | icmp <sec> | reset]",
}
static clib_error_t * set_timeout_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:2350

(constructor) VLIB_CLI_COMMAND (set_timeout_command)

Definition at line 2407 of file snat.c.

vlib_cli_command_t set_workers_command
static
Initial value:
= {
.path = "set snat workers",
.short_help =
"set snat workers <workers-list>",
}
static clib_error_t * set_workers_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:1257

(constructor) VLIB_CLI_COMMAND (set_workers_command)

Definition at line 1318 of file snat.c.

vlib_cli_command_t show_snat_command
static
Initial value:
= {
.path = "show snat",
.short_help = "show snat",
.function = show_snat_command_fn,
}
static clib_error_t * show_snat_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:1763

(constructor) VLIB_CLI_COMMAND (show_snat_command)

Definition at line 1966 of file snat.c.

vlib_cli_command_t snat_add_interface_address_command
static
Initial value:
= {
.path = "snat add interface address",
.short_help = "snat add interface address <interface> [del]",
}
static clib_error_t * snat_add_interface_address_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:2101

(constructor) VLIB_CLI_COMMAND (snat_add_interface_address_command)

Definition at line 2150 of file snat.c.

vlib_cli_command_t snat_det_close_sesion_out_command
static
Initial value:
= {
.path = "snat deterministic close session out",
.short_help = "snat deterministic close session out "
"<out_addr>:<out_port> <ext_addr>:<ext_port>",
}
static clib_error_t * snat_det_close_session_out_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:2416

(constructor) VLIB_CLI_COMMAND (snat_det_close_sesion_out_command)

Definition at line 2479 of file snat.c.

vlib_cli_command_t snat_det_close_session_in_command
static
Initial value:
= {
.path = "snat deterministic close session in",
.short_help = "snat deterministic close session in "
"<in_addr>:<in_port> <ext_addr>:<ext_port>",
}
static clib_error_t * snat_det_close_session_in_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:2487

(constructor) VLIB_CLI_COMMAND (snat_det_close_session_in_command)

Definition at line 2548 of file snat.c.

vlib_cli_command_t snat_det_forward_command
static
Initial value:
= {
.path = "snat deterministic forward",
.short_help = "snat deterministic forward <addr>",
}
static clib_error_t * snat_det_forward_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:2223

(constructor) VLIB_CLI_COMMAND (snat_det_forward_command)

Definition at line 2278 of file snat.c.

vlib_cli_command_t snat_det_map_command
static
Initial value:
= {
.path = "snat deterministic add",
.short_help = "snat deterministic add in <addr>/<plen> out <addr>/<plen> [del]",
}
static clib_error_t * snat_det_map_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:2157

(constructor) VLIB_CLI_COMMAND (snat_det_map_command)

Definition at line 2216 of file snat.c.

vlib_cli_command_t snat_det_reverse_command
static
Initial value:
= {
.path = "snat deterministic reverse",
.short_help = "snat deterministic reverse <addr>:<port>",
}
static clib_error_t * snat_det_reverse_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:2285

(constructor) VLIB_CLI_COMMAND (snat_det_reverse_command)

Definition at line 2343 of file snat.c.

vlib_cli_command_t snat_ipfix_logging_enable_disable_command
static
Initial value:
= {
.path = "snat ipfix logging",
.short_help = "snat ipfix logging [domain <domain-id>] [src-port <port>] [disable]",
}
static clib_error_t * snat_ipfix_logging_enable_disable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: snat.c:1326

(constructor) VLIB_CLI_COMMAND (snat_ipfix_logging_enable_disable_command)

Definition at line 1380 of file snat.c.

snat_main_t snat_main

Definition at line 31 of file snat.c.