44 tag = t->
is_slow_path ?
"SNAT_IN2OUT_SLOW_PATH" :
"SNAT_IN2OUT_FAST_PATH";
46 s =
format (s,
"%s: sw_if_index %d, next index %d, session %d", tag,
58 s =
format (s,
"SANT_IN2OUT_FAST: sw_if_index %d, next index %d",
68 #define foreach_snat_in2out_error \ 69 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 70 _(IN2OUT_PACKETS, "Good in2out packets processed") \ 71 _(OUT_OF_PORTS, "Out of ports") \ 72 _(BAD_OUTSIDE_FIB, "Outside VRF ID not found") \ 73 _(BAD_ICMP_TYPE, "icmp type not echo-request") \ 74 _(NO_TRANSLATION, "No translation") 77 #define _(sym,str) SNAT_IN2OUT_ERROR_##sym, 84 #define _(sym,string) string, 101 snat_session_t ** sessionp,
109 u32 oldest_per_user_translation_list_index;
110 dlist_elt_t * oldest_per_user_translation_list_elt;
115 u32 address_index = ~0;
116 u32 outside_fib_index;
122 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_BAD_OUTSIDE_FIB];
125 outside_fib_index = p[0];
132 if (clib_bihash_search_8_8 (&sm->
user_hash, &kv0, &value0))
136 memset (u, 0,
sizeof (*u));
149 clib_bihash_add_del_8_8 (&sm->
user_hash, &kv0, 1 );
161 oldest_per_user_translation_list_index =
165 ASSERT (oldest_per_user_translation_list_index != ~0);
170 oldest_per_user_translation_list_index);
172 oldest_per_user_translation_list_elt =
174 oldest_per_user_translation_list_index);
177 session_index = oldest_per_user_translation_list_elt->
value;
184 kv0.
key = s->in2out.as_u64;
185 if (clib_bihash_add_del_8_8 (&sm->
in2out, &kv0, 0 ))
187 kv0.
key = s->out2in.as_u64;
188 if (clib_bihash_add_del_8_8 (&sm->
out2in, &kv0, 0 ))
192 (sm, &s->
out2in, s->outside_address_index);
193 s->outside_address_index = ~0;
199 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_OUT_OF_PORTS];
202 s->outside_address_index = address_index;
206 u8 static_mapping = 1;
215 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_OUT_OF_PORTS];
222 memset (s, 0,
sizeof (*s));
224 s->outside_address_index = address_index;
242 s->per_user_index = per_user_translation_list_elt - sm->
list_pool;
246 per_user_translation_list_elt - sm->
list_pool);
252 s->out2in.fib_index = outside_fib_index;
256 kv0.
key = s->in2out.as_u64;
258 if (clib_bihash_add_del_8_8 (&sm->
in2out, &kv0, 1 ))
261 kv0.
key = s->out2in.as_u64;
264 if (clib_bihash_add_del_8_8 (&sm->
out2in, &kv0, 1 ))
273 icmp46_header_t * icmp0,
284 u32 new_addr0, old_addr0;
285 u16 old_id0, new_id0;
291 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_BAD_ICMP_TYPE];
304 if (clib_bihash_search_8_8 (&sm->
in2out, &kv0, &value0))
322 next0 =
slow_path (sm, b0, ip0, rx_fib_index0, &key0,
343 new_id0 = s0->out2in.port;
346 sum0 = icmp0->checksum;
352 s0->last_heard = now;
371 u32 n_left_from, * from, * to_next;
373 u32 pkts_processed = 0;
377 u32 stats_node_index;
386 while (n_left_from > 0)
391 to_next, n_left_to_next);
393 while (n_left_from >= 4 && n_left_to_next >= 2)
398 u32 sw_if_index0, sw_if_index1;
401 u32 new_addr0, old_addr0, new_addr1, old_addr1;
402 u16 old_port0, new_port0, old_port1, new_port1;
405 icmp46_header_t * icmp0, * icmp1;
407 u32 rx_fib_index0, rx_fib_index1;
409 snat_session_t * s0 = 0, * s1 = 0;
427 to_next[0] = bi0 = from[0];
428 to_next[1] = bi1 = from[1];
440 icmp0 = (icmp46_header_t *) udp0;
457 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
459 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
461 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
473 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
514 next0 =
slow_path (sm, b0, ip0, rx_fib_index0, &key0,
541 old_port0 = tcp0->
ports.src;
542 tcp0->
ports.src = s0->out2in.port;
543 new_port0 = tcp0->
ports.src;
562 s0->last_heard = now;
592 icmp1 = (icmp46_header_t *) udp1;
606 proto1 = (ip1->
protocol == IP_PROTOCOL_UDP)
608 proto1 = (ip1->
protocol == IP_PROTOCOL_TCP)
610 proto1 = (ip1->
protocol == IP_PROTOCOL_ICMP)
622 (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node, next1,
663 next1 =
slow_path (sm, b1, ip1, rx_fib_index1, &key1,
690 old_port1 = tcp1->
ports.src;
691 tcp1->
ports.src = s1->out2in.port;
692 new_port1 = tcp1->
ports.src;
711 s1->last_heard = now;
739 to_next, n_left_to_next,
740 bi0, bi1, next0, next1);
743 while (n_left_from > 0 && n_left_to_next > 0)
751 u32 new_addr0, old_addr0;
752 u16 old_port0, new_port0;
755 icmp46_header_t * icmp0;
759 snat_session_t * s0 = 0;
776 icmp0 = (icmp46_header_t *) udp0;
791 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
793 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
795 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
807 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node, next0,
828 if (clib_bihash_search_8_8 (&sm->
in2out, &kv0, &value0))
848 next0 =
slow_path (sm, b0, ip0, rx_fib_index0, &key0,
875 old_port0 = tcp0->
ports.src;
876 tcp0->
ports.src = s0->out2in.port;
877 new_port0 = tcp0->
ports.src;
896 s0->last_heard = now;
925 to_next, n_left_to_next,
933 SNAT_IN2OUT_ERROR_IN2OUT_PACKETS,
948 .name =
"snat-in2out",
949 .vector_size =
sizeof (
u32),
980 .name =
"snat-in2out-slowpath",
981 .vector_size =
sizeof (
u32),
1005 icmp46_header_t * icmp0,
1013 u32 new_addr0, old_addr0;
1014 u16 old_id0, new_id0;
1042 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_NO_TRANSLATION];
1063 sum0 = icmp0->checksum;
1077 u32 n_left_from, * from, * to_next;
1079 u32 pkts_processed = 0;
1082 u32 stats_node_index;
1090 while (n_left_from > 0)
1095 to_next, n_left_to_next);
1097 while (n_left_from > 0 && n_left_to_next > 0)
1105 u32 new_addr0, old_addr0;
1106 u16 old_port0, new_port0;
1109 icmp46_header_t * icmp0;
1120 n_left_to_next -= 1;
1128 icmp0 = (icmp46_header_t *) udp0;
1134 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
1136 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
1138 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
1163 (sm, b0, ip0, icmp0, sw_if_index0, node, next0, rx_fib_index0);
1173 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_NO_TRANSLATION];
1179 new_port0 = sm0.
port;
1194 old_port0 = tcp0->
ports.src;
1195 tcp0->
ports.src = new_port0;
1239 to_next, n_left_to_next,
1247 SNAT_IN2OUT_ERROR_IN2OUT_PACKETS,
1255 .name =
"snat-in2out-fast",
1256 .vector_size =
sizeof (
u32),
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
u32 sessions_per_user_list_head_index
u32 max_translations_per_user
static u8 * format_snat_in2out_trace(u8 *s, va_list *args)
static uword snat_in2out_slow_path_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static void clib_dlist_init(dlist_elt_t *pool, u32 index)
u32 current_config_index
Used by feature subgraph arcs to visit enabled feature nodes.
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
static u8 * format_snat_in2out_fast_trace(u8 *s, va_list *args)
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
static f64 vlib_time_now(vlib_main_t *vm)
static char * snat_in2out_error_strings[]
struct _vlib_node_registration vlib_node_registration_t
static uword snat_in2out_node_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_slow_path)
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
VLIB_NODE_FUNCTION_MULTIARCH(snat_in2out_node, snat_in2out_fast_path_fn)
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
vlib_node_registration_t snat_in2out_fast_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_fast_node)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
int snat_static_mapping_match(snat_main_t *sm, snat_session_key_t match, snat_session_key_t *mapping, u8 by_external)
Match SNAT static mapping.
#define clib_warning(format, args...)
static void * ip4_next_header(ip4_header_t *i)
vlib_node_registration_t snat_in2out_slowpath_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_slowpath_node)
#define foreach_snat_in2out_error
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
uword * fib_index_by_table_id
Hash table mapping table id to fib index.
static void clib_dlist_addtail(dlist_elt_t *pool, u32 head_index, u32 new_index)
static u32 slow_path(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, u32 rx_fib_index0, snat_session_key_t *key0, snat_session_t **sessionp, vlib_node_runtime_t *node, u32 next0)
static void * vnet_get_config_data(vnet_config_main_t *cm, u32 *config_index, u32 *next_index, u32 n_data_bytes)
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
vlib_error_t error
Error code for buffers to be enqueued to error handler.
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
#define CLIB_PREFETCH(addr, size, type)
vlib_node_registration_t snat_in2out_node
(constructor) VLIB_REGISTER_NODE (snat_in2out_node)
clib_bihash_8_8_t user_hash
int snat_alloc_outside_address_and_port(snat_main_t *sm, snat_session_key_t *k, u32 *address_indexp)
static uword snat_in2out_fast_static_map_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
8 octet key, 8 octet key value pair
#define VLIB_NODE_FLAG_TRACE
static void clib_dlist_remove(dlist_elt_t *pool, u32 index)
#define VLIB_BUFFER_IS_TRACED
snat_session_t * sessions
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define vec_elt(v, i)
Get vector value at index i.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define ip_csum_update(sum, old, new, type, field)
void snat_free_outside_address_and_port(snat_main_t *sm, snat_session_key_t *k, u32 address_index)
static uword snat_in2out_fast_path_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
#define VLIB_REGISTER_NODE(x,...)
#define SNAT_SESSION_FLAG_STATIC_MAPPING
static u32 icmp_in2out_slow_path(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, u32 sw_if_index0, u32 rx_fib_index0, vlib_node_runtime_t *node, u32 next0, f64 now)
static u32 icmp_in2out_static_map(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, u32 sw_if_index0, vlib_node_runtime_t *node, u32 next0, u32 rx_fib_index0)
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
#define snat_is_session_static(s)
Check if SNAT session is created from static mapping.
static u16 ip_csum_fold(ip_csum_t c)
static u32 clib_dlist_remove_head(dlist_elt_t *pool, u32 head_index)