FD.io VPP  v17.04.2-2-ga8f93f8
Vector Packet Processing
snat.h File Reference
+ Include dependency graph for snat.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  snat_session_key_t
 
struct  snat_det_out_key_t
 
struct  snat_user_key_t
 
struct  snat_worker_key_t
 
struct  snat_user_t
 
struct  snat_address_t
 
struct  snat_det_session_t
 
struct  snat_det_map_t
 
struct  snat_static_mapping_t
 
struct  snat_interface_t
 
struct  snat_static_map_resolve_t
 
struct  snat_main_per_thread_data_t
 
struct  snat_main_s
 
struct  snat_runtime_t
 
struct  icmp_echo_header_t
 
struct  tcp_udp_header_t
 

Macros

#define SNAT_UDP_TIMEOUT   300
 
#define SNAT_TCP_TRANSITORY_TIMEOUT   240
 
#define SNAT_TCP_ESTABLISHED_TIMEOUT   7440
 
#define foreach_snat_protocol
 
#define foreach_snat_session_state
 
#define SNAT_SESSION_FLAG_STATIC_MAPPING   1
 
#define snat_is_session_static(s)   s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING
 Check if SNAT session is created from static mapping. More...
 

Typedefs

typedef u32 snat_icmp_match_function_t(struct snat_main_s *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
 
typedef u32snat_get_worker_function_t) (ip4_header_t *ip, u32 rx_fib_index)
 
typedef struct snat_main_s snat_main_t
 

Enumerations

enum  snat_protocol_t { foreach_snat_protocol }
 
enum  snat_session_state_t { foreach_snat_session_state }
 

Functions

typedef CLIB_PACKED (struct{snat_session_key_t out2in;snat_session_key_t in2out;u32 flags;u32 per_user_index;u32 per_user_list_head_index;f64 last_heard;u64 total_bytes;u32 total_pkts;u32 outside_address_index;}) snat_session_t
 
void snat_free_outside_address_and_port (snat_main_t *sm, snat_session_key_t *k, u32 address_index)
 
int snat_alloc_outside_address_and_port (snat_main_t *sm, u32 fib_index, snat_session_key_t *k, u32 *address_indexp)
 
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...
 
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...
 
static snat_protocol_t ip_proto_to_snat_proto (u8 ip_proto)
 
static u8 snat_proto_to_ip_proto (snat_protocol_t snat_proto)
 
u32 icmp_match_in2out_fast (snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
 Get address and port values to be used for packet SNAT translation. More...
 
u32 icmp_match_in2out_slow (snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
 Get address and port values to be used for packet SNAT translation and create session if needed. More...
 
u32 icmp_match_out2in_fast (snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
 Get address and port values to be used for packet SNAT translation. More...
 
u32 icmp_match_out2in_slow (snat_main_t *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)
 Get address and port values to be used for packet SNAT translation and create session if needed. More...
 
static_always_inline u8 icmp_is_error_message (icmp46_header_t *icmp)
 

Variables

snat_main_t snat_main
 
vlib_node_registration_t snat_in2out_node
 (constructor) VLIB_REGISTER_NODE (snat_in2out_node) More...
 
vlib_node_registration_t snat_out2in_node
 (constructor) VLIB_REGISTER_NODE (snat_out2in_node) More...
 
vlib_node_registration_t snat_in2out_fast_node
 (constructor) VLIB_REGISTER_NODE (snat_in2out_fast_node) More...
 
vlib_node_registration_t snat_out2in_fast_node
 (constructor) VLIB_REGISTER_NODE (snat_out2in_fast_node) More...
 
vlib_node_registration_t snat_in2out_worker_handoff_node
 (constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node) More...
 
vlib_node_registration_t snat_out2in_worker_handoff_node
 (constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node) More...
 
vlib_node_registration_t snat_det_in2out_node
 (constructor) VLIB_REGISTER_NODE (snat_det_in2out_node) More...
 
vlib_node_registration_t snat_det_out2in_node
 (constructor) VLIB_REGISTER_NODE (snat_det_out2in_node) More...
 
format_function_t format_snat_user
 

Macro Definition Documentation

#define foreach_snat_protocol
Value:
_(UDP, 0, udp, "udp") \
_(TCP, 1, tcp, "tcp") \
_(ICMP, 2, icmp, "icmp")

Definition at line 90 of file snat.h.

#define foreach_snat_session_state
Value:
_(0, UNKNOWN, "unknown") \
_(1, UDP_ACTIVE, "udp-active") \
_(2, TCP_SYN_SENT, "tcp-syn-sent") \
_(3, TCP_ESTABLISHED, "tcp-established") \
_(4, TCP_FIN_WAIT, "tcp-fin-wait") \
_(5, TCP_CLOSE_WAIT, "tcp-close-wait") \
_(6, TCP_LAST_ACK, "tcp-last-ack")

Definition at line 102 of file snat.h.

#define snat_is_session_static (   s)    s->flags & SNAT_SESSION_FLAG_STATIC_MAPPING

Check if SNAT session is created from static mapping.

Parameters
sSNAT session
Returns
1 if SNAT session is created from static mapping otherwise 0

Definition at line 364 of file snat.h.

#define SNAT_SESSION_FLAG_STATIC_MAPPING   1

Definition at line 118 of file snat.h.

#define SNAT_TCP_ESTABLISHED_TIMEOUT   7440

Definition at line 34 of file snat.h.

#define SNAT_TCP_TRANSITORY_TIMEOUT   240

Definition at line 33 of file snat.h.

#define SNAT_UDP_TIMEOUT   300

Definition at line 32 of file snat.h.

Typedef Documentation

typedef u32( snat_get_worker_function_t) (ip4_header_t *ip, u32 rx_fib_index)

Definition at line 231 of file snat.h.

typedef u32 snat_icmp_match_function_t(struct snat_main_s *sm, vlib_node_runtime_t *node, u32 cpu_index, vlib_buffer_t *b0, snat_session_key_t *p_key, snat_session_key_t *p_value, u8 *p_dont_translate, void *d)

Definition at line 222 of file snat.h.

typedef struct snat_main_s snat_main_t

Enumeration Type Documentation

Enumerator
foreach_snat_protocol 

Definition at line 95 of file snat.h.

Enumerator
foreach_snat_session_state 

Definition at line 111 of file snat.h.

Function Documentation

typedef CLIB_PACKED ( struct{snat_session_key_t out2in;snat_session_key_t in2out;u32 flags;u32 per_user_index;u32 per_user_list_head_index;f64 last_heard;u64 total_bytes;u32 total_pkts;u32 outside_address_index;}  )
static_always_inline u8 icmp_is_error_message ( icmp46_header_t *  icmp)

Definition at line 427 of file snat.h.

+ Here is the caller graph for this function:

u32 icmp_match_in2out_fast ( snat_main_t sm,
vlib_node_runtime_t node,
u32  cpu_index,
vlib_buffer_t b0,
snat_session_key_t p_key,
snat_session_key_t p_value,
u8 p_dont_translate,
void *  d 
)

Get address and port values to be used for packet SNAT translation.

Parameters
[in]smSNAT main
[in,out]nodeSNAT node runtime
[in]cpu_indexCPU index
[in,out]b0buffer containing packet to be translated
[out]p_keyaddress and port before NAT translation
[out]p_valueaddress and port after NAT translation
[out]p_dont_translateif packet should not be translated
doptional parameter

Definition at line 571 of file in2out.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u32 icmp_match_in2out_slow ( snat_main_t sm,
vlib_node_runtime_t node,
u32  cpu_index,
vlib_buffer_t b0,
snat_session_key_t p_key,
snat_session_key_t p_value,
u8 p_dont_translate,
void *  d 
)

Get address and port values to be used for packet SNAT translation and create session if needed.

Parameters
[in,out]smSNAT main
[in,out]nodeSNAT node runtime
[in]cpu_indexCPU index
[in,out]b0buffer containing packet to be translated
[out]p_keyaddress and port before NAT translation
[out]p_valueaddress and port after NAT translation
[out]p_dont_translateif packet should not be translated
doptional parameter

Definition at line 477 of file in2out.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u32 icmp_match_out2in_fast ( snat_main_t sm,
vlib_node_runtime_t node,
u32  cpu_index,
vlib_buffer_t b0,
snat_session_key_t p_key,
snat_session_key_t p_value,
u8 p_dont_translate,
void *  d 
)

Get address and port values to be used for packet SNAT translation.

Parameters
[in]smSNAT main
[in,out]nodeSNAT node runtime
[in]cpu_indexCPU index
[in,out]b0buffer containing packet to be translated
[out]p_keyaddress and port before NAT translation
[out]p_valueaddress and port after NAT translation
[out]p_dont_translateif packet should not be translated
doptional parameter

Definition at line 420 of file out2in.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u32 icmp_match_out2in_slow ( snat_main_t sm,
vlib_node_runtime_t node,
u32  cpu_index,
vlib_buffer_t b0,
snat_session_key_t p_key,
snat_session_key_t p_value,
u8 p_dont_translate,
void *  d 
)

Get address and port values to be used for packet SNAT translation and create session if needed.

Parameters
[in,out]smSNAT main
[in,out]nodeSNAT node runtime
[in]cpu_indexCPU index
[in,out]b0buffer containing packet to be translated
[out]p_keyaddress and port before NAT translation
[out]p_valueaddress and port after NAT translation
[out]p_dont_translateif packet should not be translated
doptional parameter

Definition at line 312 of file out2in.c.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static snat_protocol_t ip_proto_to_snat_proto ( u8  ip_proto)
inlinestatic

Definition at line 378 of file snat.h.

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller 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 1804 of file snat.c.

+ Here is the caller graph for this function:

static u8 snat_proto_to_ip_proto ( snat_protocol_t  snat_proto)
inlinestatic

Definition at line 390 of file snat.h.

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

+ Here is the caller graph for this function:

Variable Documentation

format_function_t format_snat_user

Definition at line 353 of file snat.h.

vlib_node_registration_t snat_det_in2out_node

(constructor) VLIB_REGISTER_NODE (snat_det_in2out_node)

Definition at line 90 of file in2out.c.

vlib_node_registration_t snat_det_out2in_node

(constructor) VLIB_REGISTER_NODE (snat_det_out2in_node)

Definition at line 84 of file out2in.c.

vlib_node_registration_t snat_in2out_fast_node

(constructor) VLIB_REGISTER_NODE (snat_in2out_fast_node)

Definition at line 88 of file in2out.c.

vlib_node_registration_t snat_in2out_node

(constructor) VLIB_REGISTER_NODE (snat_in2out_node)

Definition at line 86 of file in2out.c.

vlib_node_registration_t snat_in2out_worker_handoff_node

(constructor) VLIB_REGISTER_NODE (snat_in2out_worker_handoff_node)

Definition at line 89 of file in2out.c.

snat_main_t snat_main

Definition at line 39 of file jvpp_snat.h.

vlib_node_registration_t snat_out2in_fast_node

(constructor) VLIB_REGISTER_NODE (snat_out2in_fast_node)

Definition at line 82 of file out2in.c.

vlib_node_registration_t snat_out2in_node

(constructor) VLIB_REGISTER_NODE (snat_out2in_node)

Definition at line 81 of file out2in.c.

vlib_node_registration_t snat_out2in_worker_handoff_node

(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)

Definition at line 83 of file out2in.c.