45 tag = t->
is_slow_path ?
"SNAT_IN2OUT_SLOW_PATH" :
"SNAT_IN2OUT_FAST_PATH";
47 s =
format (s,
"%s: sw_if_index %d, next index %d, session %d", tag,
55 #define foreach_snat_in2out_error \ 56 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 57 _(IN2OUT_PACKETS, "Good in2out packets processed") \ 58 _(OUT_OF_PORTS, "Out of ports") \ 59 _(BAD_OUTSIDE_FIB, "Outside VRF ID not found") \ 60 _(BAD_ICMP_TYPE, "icmp type not echo-request") 63 #define _(sym,str) SNAT_IN2OUT_ERROR_##sym, 70 #define _(sym,string) string, 87 snat_session_t ** sessionp,
95 u32 oldest_per_user_translation_list_index;
102 u32 outside_fib_index;
108 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_BAD_OUTSIDE_FIB];
111 outside_fib_index = p[0];
118 if (clib_bihash_search_8_8 (&sm->
user_hash, &kv0, &value0))
122 memset (u, 0,
sizeof (*u));
135 clib_bihash_add_del_8_8 (&sm->
user_hash, &kv0, 1 );
146 oldest_per_user_translation_list_index =
150 ASSERT (oldest_per_user_translation_list_index != ~0);
154 oldest_per_user_translation_list_index);
157 oldest_per_user_translation_list_elt =
159 oldest_per_user_translation_list_index);
162 session_index = oldest_per_user_translation_list_elt->
value;
168 kv0.
key = s->in2out.as_u64;
169 if (clib_bihash_add_del_8_8 (&sm->
in2out, &kv0, 0 ))
171 kv0.
key = s->out2in.as_u64;
172 if (clib_bihash_add_del_8_8 (&sm->
out2in, &kv0, 0 ))
176 (sm, &s->
out2in, s->outside_address_index);
177 s->outside_address_index = ~0;
183 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_OUT_OF_PORTS];
186 s->outside_address_index = address_index;
194 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_OUT_OF_PORTS];
200 memset (s, 0,
sizeof (*s));
202 s->outside_address_index = address_index;
210 s->per_user_index = per_user_translation_list_elt - sm->
list_pool;
214 per_user_translation_list_elt - sm->
list_pool);
221 s->out2in.fib_index = outside_fib_index;
225 kv0.
key = s->in2out.as_u64;
227 if (clib_bihash_add_del_8_8 (&sm->
in2out, &kv0, 1 ))
230 kv0.
key = s->out2in.as_u64;
233 if (clib_bihash_add_del_8_8 (&sm->
out2in, &kv0, 1 ))
242 icmp46_header_t * icmp0,
253 u32 new_addr0, old_addr0;
254 u16 old_id0, new_id0;
260 b0->
error = node->
errors[SNAT_IN2OUT_ERROR_BAD_ICMP_TYPE];
273 if (clib_bihash_search_8_8 (&sm->
in2out, &kv0, &value0))
291 next0 =
slow_path (sm, b0, ip0, rx_fib_index0, &key0,
312 new_id0 = s0->out2in.port;
315 sum0 = icmp0->checksum;
321 s0->last_heard = now;
336 u32 n_left_from, * from, * to_next;
338 u32 pkts_processed = 0;
342 u32 stats_node_index;
351 while (n_left_from > 0)
356 to_next, n_left_to_next);
358 while (n_left_from >= 4 && n_left_to_next >= 2)
363 u32 sw_if_index0, sw_if_index1;
366 u32 new_addr0, old_addr0, new_addr1, old_addr1;
367 u16 old_port0, new_port0, old_port1, new_port1;
370 icmp46_header_t * icmp0, * icmp1;
372 u32 rx_fib_index0, rx_fib_index1;
374 snat_session_t * s0 = 0, * s1 = 0;
392 to_next[0] = bi0 = from[0];
393 to_next[1] = bi1 = from[1];
405 icmp0 = (icmp46_header_t *) udp0;
422 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
424 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
426 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
438 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0,
479 next0 =
slow_path (sm, b0, ip0, rx_fib_index0, &key0,
527 s0->last_heard = now;
553 icmp1 = (icmp46_header_t *) udp1;
567 proto1 = (ip1->
protocol == IP_PROTOCOL_UDP)
569 proto1 = (ip1->
protocol == IP_PROTOCOL_TCP)
571 proto1 = (ip1->
protocol == IP_PROTOCOL_ICMP)
583 (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node, next1,
624 next1 =
slow_path (sm, b1, ip1, rx_fib_index1, &key1,
672 s1->last_heard = now;
696 to_next, n_left_to_next,
697 bi0, bi1, next0, next1);
700 while (n_left_from > 0 && n_left_to_next > 0)
708 u32 new_addr0, old_addr0;
709 u16 old_port0, new_port0;
712 icmp46_header_t * icmp0;
716 snat_session_t * s0 = 0;
733 icmp0 = (icmp46_header_t *) udp0;
748 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
750 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
752 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
764 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node, next0,
785 if (clib_bihash_search_8_8 (&sm->
in2out, &kv0, &value0))
805 next0 =
slow_path (sm, b0, ip0, rx_fib_index0, &key0,
853 s0->last_heard = now;
878 to_next, n_left_to_next,
886 SNAT_IN2OUT_ERROR_IN2OUT_PACKETS,
901 .name =
"snat-in2out",
902 .vector_size =
sizeof (
u32),
933 .name =
"snat-in2out-slowpath",
934 .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
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)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
#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)
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,...)
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)
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
uword runtime_data[(128-1 *sizeof(vlib_node_function_t *)-1 *sizeof(vlib_error_t *)-11 *sizeof(u32)-5 *sizeof(u16))/sizeof(uword)]
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u16 ip_csum_fold(ip_csum_t c)
static u32 clib_dlist_remove_head(dlist_elt_t *pool, u32 head_index)