48 s =
format (s,
"SNAT_OUT2IN: sw_if_index %d, next index %d, session index %d",
59 s =
format (s,
"SNAT_OUT2IN_FAST: sw_if_index %d, next index %d",
72 m = t->
do_handoff ?
"next worker" :
"same worker";
82 #define foreach_snat_out2in_error \ 83 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 84 _(OUT2IN_PACKETS, "Good out2in packets processed") \ 85 _(BAD_ICMP_TYPE, "icmp type not echo-reply") \ 86 _(NO_TRANSLATION, "No translation") 89 #define _(sym,str) SNAT_OUT2IN_ERROR_##sym, 96 #define _(sym,string) string, 121 static inline snat_session_t *
141 if (clib_bihash_search_8_8 (&sm->
user_hash, &kv0, &value0))
145 memset (u, 0,
sizeof (*u));
149 per_user_list_head_elt);
160 clib_bihash_add_del_8_8 (&sm->
user_hash, &kv0, 1 );
163 kv0.
value = cpu_index;
173 memset (s, 0,
sizeof (*s));
175 s->outside_address_index = ~0;
181 per_user_translation_list_elt);
183 per_user_translation_list_elt -
186 per_user_translation_list_elt->
value =
193 s->per_user_list_head_index,
194 per_user_translation_list_elt -
202 kv0.
key = s->in2out.as_u64;
204 if (clib_bihash_add_del_8_8 (&sm->
in2out, &kv0, 1 ))
207 kv0.
key = s->out2in.as_u64;
210 if (clib_bihash_add_del_8_8 (&sm->
out2in, &kv0, 1 ))
219 icmp46_header_t * icmp0,
230 u32 new_addr0, old_addr0;
231 u16 old_id0, new_id0;
244 if (clib_bihash_search_8_8 (&sm->
out2in, &kv0, &value0))
266 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
292 new_id0 = s0->in2out.port;
295 sum0 = icmp0->checksum;
301 s0->last_heard = now;
310 s0->per_user_list_head_index,
322 u32 n_left_from, * from, * to_next;
324 u32 pkts_processed = 0;
333 while (n_left_from > 0)
338 to_next, n_left_to_next);
340 while (n_left_from >= 4 && n_left_to_next >= 2)
346 u32 sw_if_index0, sw_if_index1;
349 u32 new_addr0, old_addr0;
350 u16 new_port0, old_port0;
351 u32 new_addr1, old_addr1;
352 u16 new_port1, old_port1;
355 icmp46_header_t * icmp0, * icmp1;
357 u32 rx_fib_index0, rx_fib_index1;
359 snat_session_t * s0 = 0, * s1 = 0;
377 to_next[0] = bi0 = from[0];
378 to_next[1] = bi1 = from[1];
390 icmp0 = (icmp46_header_t *) udp0;
397 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
399 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
401 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
410 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
411 next0, now, cpu_index);
422 if (clib_bihash_search_8_8 (&sm->
out2in, &kv0, &value0))
428 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
455 old_port0 = tcp0->
ports.dst;
456 tcp0->
ports.dst = s0->in2out.port;
457 new_port0 = tcp0->
ports.dst;
477 s0->last_heard = now;
486 s0->per_user_list_head_index,
509 icmp1 = (icmp46_header_t *) udp1;
516 proto1 = (ip1->
protocol == IP_PROTOCOL_UDP)
518 proto1 = (ip1->
protocol == IP_PROTOCOL_TCP)
520 proto1 = (ip1->
protocol == IP_PROTOCOL_ICMP)
529 (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
530 next1, now, cpu_index);
541 if (clib_bihash_search_8_8 (&sm->
out2in, &kv1, &value1))
547 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
574 old_port1 = tcp1->
ports.dst;
575 tcp1->
ports.dst = s1->in2out.port;
576 new_port1 = tcp1->
ports.dst;
596 s1->last_heard = now;
605 s1->per_user_list_head_index,
626 to_next, n_left_to_next,
627 bi0, bi1, next0, next1);
630 while (n_left_from > 0 && n_left_to_next > 0)
638 u32 new_addr0, old_addr0;
639 u16 new_port0, old_port0;
642 icmp46_header_t * icmp0;
646 snat_session_t * s0 = 0;
662 icmp0 = (icmp46_header_t *) udp0;
669 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
671 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
673 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
682 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
683 next0, now, cpu_index);
694 if (clib_bihash_search_8_8 (&sm->
out2in, &kv0, &value0))
700 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
727 old_port0 = tcp0->
ports.dst;
728 tcp0->
ports.dst = s0->in2out.port;
729 new_port0 = tcp0->
ports.dst;
749 s0->last_heard = now;
758 s0->per_user_list_head_index,
779 to_next, n_left_to_next,
787 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
794 .name =
"snat-out2in",
795 .vector_size =
sizeof (
u32),
821 u32 n_left_from, *from, *to_next = 0;
828 u32 n_left_to_next_worker = 0, *to_next_worker = 0;
829 u32 next_worker_index = 0;
830 u32 current_worker_index = ~0;
847 while (n_left_from > 0)
877 icmp46_header_t * icmp0 = (icmp46_header_t *) udp0;
885 if (clib_bihash_search_8_8 (&sm->
worker_by_out, &kv0, &value0))
890 if (clib_bihash_search_8_8 (&sm->
worker_by_out, &kv0, &value0))
899 next_worker_index = value0.
value;
903 kv0.
value = next_worker_index;
907 next_worker_index = value0.
value;
913 if (next_worker_index != current_worker_index)
920 handoff_queue_elt_by_worker_index);
924 current_worker_index = next_worker_index;
928 to_next_worker[0] = bi0;
930 n_left_to_next_worker--;
932 if (n_left_to_next_worker == 0)
936 current_worker_index = ~0;
937 handoff_queue_elt_by_worker_index[next_worker_index] = 0;
973 for (i = 0; i <
vec_len (handoff_queue_elt_by_worker_index); i++)
975 if (handoff_queue_elt_by_worker_index[i])
977 hf = handoff_queue_elt_by_worker_index[
i];
985 handoff_queue_elt_by_worker_index[
i] = 0;
990 congested_handoff_queue_by_worker_index[
i] =
994 current_worker_index = ~0;
1000 .name =
"snat-out2in-worker-handoff",
1001 .vector_size =
sizeof (
u32),
1017 icmp46_header_t * icmp0,
1025 u32 new_addr0, old_addr0;
1026 u16 old_id0, new_id0;
1054 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1076 sum0 = icmp0->checksum;
1090 u32 n_left_from, * from, * to_next;
1092 u32 pkts_processed = 0;
1099 while (n_left_from > 0)
1104 to_next, n_left_to_next);
1106 while (n_left_from > 0 && n_left_to_next > 0)
1114 u32 new_addr0, old_addr0;
1115 u16 new_port0, old_port0;
1118 icmp46_header_t * icmp0;
1129 n_left_to_next -= 1;
1136 icmp0 = (icmp46_header_t *) udp0;
1144 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
1146 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
1148 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
1157 (sm, b0, ip0, icmp0, sw_if_index0, node, next0, rx_fib_index0);
1167 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
1172 new_port0 = sm0.
port;
1187 old_port0 = tcp0->
ports.dst;
1188 tcp0->
ports.dst = new_port0;
1235 to_next, n_left_to_next,
1243 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
1250 .name =
"snat-out2in-fast",
1251 .vector_size =
sizeof (
u32),
vlib_node_registration_t snat_out2in_fast_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_fast_node)
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
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.
VLIB_NODE_FUNCTION_MULTIARCH(snat_out2in_node, snat_out2in_node_fn)
u32 sessions_per_user_list_head_index
sll srl srl sll sra u16x4 i
static void clib_dlist_init(dlist_elt_t *pool, u32 index)
static u32 icmp_out2in_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, u32 cpu_index)
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
static u8 * format_snat_out2in_fast_trace(u8 *s, va_list *args)
static u32 icmp_out2in_fast(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)
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)
struct _vlib_node_registration vlib_node_registration_t
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
u32 buffer_index[VLIB_FRAME_SIZE]
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).
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
snat_main_per_thread_data_t * per_thread_data
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)
#define foreach_snat_out2in_error
static uword snat_out2in_worker_handoff_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
clib_bihash_8_8_t worker_by_in
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void clib_dlist_addtail(dlist_elt_t *pool, u32 head_index, u32 new_index)
uword os_get_cpu_number(void)
static vlib_frame_queue_elt_t * vlib_get_worker_handoff_queue_elt(u32 frame_queue_index, u32 vlib_worker_index, vlib_frame_queue_elt_t **handoff_queue_elt_by_worker_index)
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
#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.
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
static_always_inline void vnet_feature_next(u32 sw_if_index, u32 *next0, vlib_buffer_t *b0)
#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)
clib_bihash_8_8_t user_hash
static vlib_thread_main_t * vlib_get_thread_main()
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
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.
vlib_node_registration_t snat_out2in_worker_handoff_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_worker_handoff_node)
static snat_session_t * create_session_for_static_mapping(snat_main_t *sm, vlib_buffer_t *b0, snat_session_key_t in2out, snat_session_key_t out2in, vlib_node_runtime_t *node, u32 cpu_index)
Create session for static mapping.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static char * snat_out2in_error_strings[]
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)
static u8 * format_snat_out2in_trace(u8 *s, va_list *args)
static void vlib_put_frame_queue_elt(vlib_frame_queue_elt_t *hf)
static uword snat_out2in_fast_node_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 uword snat_out2in_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
#define SNAT_SESSION_FLAG_STATIC_MAPPING
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header, unspecified alignment)
#define CLIB_CACHE_LINE_BYTES
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
snat_session_t * sessions
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)
clib_bihash_8_8_t worker_by_out
static u8 * format_snat_out2in_worker_handoff_trace(u8 *s, va_list *args)