42 s =
format (s,
"SNAT_OUT2IN: sw_if_index %d, next index %d, session index %d",
53 s =
format (s,
"SNAT_OUT2IN_FAST: sw_if_index %d, next index %d",
62 #define foreach_snat_out2in_error \ 63 _(UNSUPPORTED_PROTOCOL, "Unsupported protocol") \ 64 _(OUT2IN_PACKETS, "Good out2in packets processed") \ 65 _(BAD_ICMP_TYPE, "icmp type not echo-reply") \ 66 _(NO_TRANSLATION, "No translation") 69 #define _(sym,str) SNAT_OUT2IN_ERROR_##sym, 76 #define _(sym,string) string, 100 static inline snat_session_t *
119 if (clib_bihash_search_8_8 (&sm->
user_hash, &kv0, &value0))
123 memset (u, 0,
sizeof (*u));
136 clib_bihash_add_del_8_8 (&sm->
user_hash, &kv0, 1 );
144 memset (s, 0,
sizeof (*s));
146 s->outside_address_index = ~0;
156 s->per_user_index = per_user_translation_list_elt - sm->
list_pool;
160 per_user_translation_list_elt - sm->
list_pool);
167 kv0.
key = s->in2out.as_u64;
169 if (clib_bihash_add_del_8_8 (&sm->
in2out, &kv0, 1 ))
172 kv0.
key = s->out2in.as_u64;
175 if (clib_bihash_add_del_8_8 (&sm->
out2in, &kv0, 1 ))
184 icmp46_header_t * icmp0,
194 u32 new_addr0, old_addr0;
195 u16 old_id0, new_id0;
208 if (clib_bihash_search_8_8 (&sm->
out2in, &kv0, &value0))
230 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
255 new_id0 = s0->in2out.port;
258 sum0 = icmp0->checksum;
264 s0->last_heard = now;
283 u32 n_left_from, * from, * to_next;
285 u32 pkts_processed = 0;
295 while (n_left_from > 0)
300 to_next, n_left_to_next);
302 while (n_left_from >= 4 && n_left_to_next >= 2)
308 u32 sw_if_index0, sw_if_index1;
311 u32 new_addr0, old_addr0;
312 u16 new_port0, old_port0;
313 u32 new_addr1, old_addr1;
314 u16 new_port1, old_port1;
317 icmp46_header_t * icmp0, * icmp1;
319 u32 rx_fib_index0, rx_fib_index1;
321 snat_session_t * s0 = 0, * s1 = 0;
339 to_next[0] = bi0 = from[0];
340 to_next[1] = bi1 = from[1];
352 icmp0 = (icmp46_header_t *) udp0;
363 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
365 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
367 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
376 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
388 if (clib_bihash_search_8_8 (&sm->
out2in, &kv0, &value0))
394 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
419 old_port0 = tcp0->
ports.dst;
420 tcp0->
ports.dst = s0->in2out.port;
421 new_port0 = tcp0->
ports.dst;
441 s0->last_heard = now;
471 icmp1 = (icmp46_header_t *) udp1;
482 proto1 = (ip1->
protocol == IP_PROTOCOL_UDP)
484 proto1 = (ip1->
protocol == IP_PROTOCOL_TCP)
486 proto1 = (ip1->
protocol == IP_PROTOCOL_ICMP)
495 (sm, b1, ip1, icmp1, sw_if_index1, rx_fib_index1, node,
507 if (clib_bihash_search_8_8 (&sm->
out2in, &kv1, &value1))
513 b1->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
538 old_port1 = tcp1->
ports.dst;
539 tcp1->
ports.dst = s1->in2out.port;
540 new_port1 = tcp1->
ports.dst;
560 s1->last_heard = now;
589 to_next, n_left_to_next,
590 bi0, bi1, next0, next1);
593 while (n_left_from > 0 && n_left_to_next > 0)
601 u32 new_addr0, old_addr0;
602 u16 new_port0, old_port0;
605 icmp46_header_t * icmp0;
609 snat_session_t * s0 = 0;
625 icmp0 = (icmp46_header_t *) udp0;
636 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
638 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
640 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
649 (sm, b0, ip0, icmp0, sw_if_index0, rx_fib_index0, node,
661 if (clib_bihash_search_8_8 (&sm->
out2in, &kv0, &value0))
667 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
692 old_port0 = tcp0->
ports.dst;
693 tcp0->
ports.dst = s0->in2out.port;
694 new_port0 = tcp0->
ports.dst;
714 s0->last_heard = now;
742 to_next, n_left_to_next,
750 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
757 .name =
"snat-out2in",
758 .vector_size =
sizeof (
u32),
779 icmp46_header_t * icmp0,
787 u32 new_addr0, old_addr0;
788 u16 old_id0, new_id0;
816 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
838 sum0 = icmp0->checksum;
852 u32 n_left_from, * from, * to_next;
854 u32 pkts_processed = 0;
863 while (n_left_from > 0)
868 to_next, n_left_to_next);
870 while (n_left_from > 0 && n_left_to_next > 0)
878 u32 new_addr0, old_addr0;
879 u16 new_port0, old_port0;
882 icmp46_header_t * icmp0;
900 icmp0 = (icmp46_header_t *) udp0;
910 proto0 = (ip0->
protocol == IP_PROTOCOL_UDP)
912 proto0 = (ip0->
protocol == IP_PROTOCOL_TCP)
914 proto0 = (ip0->
protocol == IP_PROTOCOL_ICMP)
923 (sm, b0, ip0, icmp0, sw_if_index0, node, next0, rx_fib_index0);
933 b0->
error = node->
errors[SNAT_OUT2IN_ERROR_NO_TRANSLATION];
938 new_port0 = sm0.
port;
953 old_port0 = tcp0->
ports.dst;
954 tcp0->
ports.dst = new_port0;
1001 to_next, n_left_to_next,
1009 SNAT_OUT2IN_ERROR_OUT2IN_PACKETS,
1016 .name =
"snat-out2in-fast",
1017 .vector_size =
sizeof (
u32),
vlib_node_registration_t snat_out2in_fast_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_fast_node)
vnet_config_main_t config_main
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
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_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)
ip_lookup_main_t * ip4_lookup_main
struct _vlib_node_registration vlib_node_registration_t
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).
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.
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
#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)
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.
vlib_node_registration_t snat_out2in_node
(constructor) VLIB_REGISTER_NODE (snat_out2in_node)
#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)
vnet_feature_config_main_t feature_config_mains[VNET_N_IP_FEAT]
rx unicast, multicast, tx interface/feature configuration.
#define CLIB_PREFETCH(addr, size, type)
clib_bihash_8_8_t user_hash
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)
Create session for static mapping.
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 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 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)
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)
#define SNAT_SESSION_FLAG_STATIC_MAPPING
#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)