62 s =
format (s,
" is-static-mapping");
95 #ifndef CLIB_MARCH_VARIANT 100 int is_ed,
int do_trace)
102 snat_session_t *s0 = NULL;
105 u32 new_dst_addr0 = 0, old_dst_addr0, ti = 0,
si = ~0;
106 u16 new_dst_port0 = ~0, old_dst_port0;
114 &sm0_addr, &sm0_port, &sm0_fib_index, 1, 0, 0, 0, 0, 0, 0))
116 new_dst_addr0 = sm0_addr.
as_u32;
117 new_dst_port0 = sm0_port;
125 (clib_net_to_host_u16 (udp0->
dst_port) -
136 rv = clib_bihash_search_16_8 (&sm->
out2in_ed, &ed_kv, &ed_value);
157 new_dst_addr0 = s0->in2out.addr.as_u32;
158 new_dst_port0 = s0->in2out.port;
172 old_dst_port0 = tcp0->dst;
177 tcp0->dst = new_dst_port0;
178 sum0 = tcp0->checksum;
195 sum0 = tcp0->checksum;
207 && (b0->
flags & VLIB_BUFFER_IS_TRACED)))
211 t->
port = new_dst_port0;
226 #ifndef CLIB_MARCH_VARIANT 233 u32 old_dst_addr0, new_dst_addr0;
234 u32 old_addr0, new_addr0;
235 u16 old_port0, new_port0;
236 u16 old_checksum0, new_checksum0;
252 if (protocol != NAT_PROTOCOL_TCP && protocol != NAT_PROTOCOL_UDP)
261 if (clib_bihash_search_16_8 (&sm->
out2in_ed, &ed_kv, &ed_value))
270 if (clib_bihash_search_8_8
276 new_dst_addr0 = s0->in2out.addr.as_u32;
283 sum0 = icmp0->checksum;
289 old_checksum0 = inner_ip0->
checksum;
294 new_checksum0 = inner_ip0->
checksum;
295 sum0 = icmp0->checksum;
302 l4_header->
src_port = s0->in2out.port;
304 sum0 = icmp0->checksum;
312 if (clib_bihash_search_8_8
323 (clib_net_to_host_u16 (icmp_id0) -
335 new_dst_addr0 = s0->in2out.addr.as_u32;
337 s0->in2out.fib_index;
339 sum0 = icmp0->checksum;
371 #ifndef CLIB_MARCH_VARIANT 378 u32 old_addr, new_addr;
398 #ifndef CLIB_MARCH_VARIANT 403 u32 old_addr, new_addr = 0, ti = 0;
418 if (clib_bihash_search_16_8 (&sm->
out2in_ed, &s_kv, &s_value))
421 if (clib_bihash_search_8_8
451 u32 n_left_from, *from, *to_next;
462 while (n_left_from > 0)
468 while (n_left_from > 0 && n_left_to_next > 0)
499 (vm, node, sm, b0, ip0, udp0, tcp0, proto0, is_ed,
512 to_next, n_left_to_next,
531 .name =
"nat44-hairpinning",
532 .vector_size =
sizeof (
u32),
552 .name =
"nat44-ed-hairpinning",
553 .vector_size =
sizeof (
u32),
569 u32 n_left_from, *from, *to_next;
577 while (n_left_from > 0)
583 while (n_left_from > 0 && n_left_to_next > 0)
610 if (proto0 == NAT_PROTOCOL_TCP || proto0 == NAT_PROTOCOL_UDP)
618 else if (proto0 == NAT_PROTOCOL_ICMP)
645 to_next, n_left_to_next,
664 .name =
"nat44-hairpin-dst",
665 .vector_size =
sizeof (
u32),
685 .name =
"nat44-ed-hairpin-dst",
686 .vector_size =
sizeof (
u32),
702 u32 n_left_from, *from, *to_next;
710 while (n_left_from > 0)
716 while (n_left_from > 0 && n_left_to_next > 0)
740 if ((nat_interface_is_inside(i)) && (sw_if_index0 == i->sw_if_index))
742 if (PREDICT_FALSE ((vnet_buffer (b0)->snat.flags) &
743 SNAT_FLAG_HAIRPINNING))
745 if (PREDICT_TRUE (sm->num_workers > 1))
746 next0 = SNAT_HAIRPIN_SRC_NEXT_SNAT_IN2OUT_WH;
748 next0 = SNAT_HAIRPIN_SRC_NEXT_SNAT_IN2OUT;
764 to_next, n_left_to_next,
771 return frame->n_vectors;
783 .name =
"nat44-hairpin-src",
784 .vector_size =
sizeof (
u32),
805 .name =
"nat44-ed-hairpin-src",
806 .vector_size =
sizeof (
u32),
vnet_config_main_t config_main
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
clib_bihash_16_8_t out2in_ed
vlib_node_registration_t snat_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_src_node)
vlib_node_registration_t nat44_ed_hairpinning_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_hairpinning_node)
vlib_node_registration_t nat44_ed_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_hairpin_dst_node)
vlib_node_registration_t nat44_ed_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (nat44_ed_hairpin_src_node)
static void vlib_increment_simple_counter(vlib_simple_counter_main_t *cm, u32 thread_index, u32 index, u64 increment)
Increment a simple counter.
#define VLIB_NODE_FN(node)
static u8 * format_nat_hairpin_trace(u8 *s, va_list *args)
struct _tcp_header tcp_header_t
vlib_simple_counter_main_t hairpinning
vl_api_ip_proto_t protocol
snat_get_worker_out2in_function_t * worker_out2in_cb
#define static_always_inline
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
static nat_protocol_t ip_proto_to_nat_proto(u8 ip_proto)
Common NAT inline functions.
int snat_static_mapping_match(snat_main_t *sm, ip4_address_t match_addr, u16 match_port, u32 match_fib_index, nat_protocol_t match_protocol, ip4_address_t *mapping_addr, u16 *mapping_port, u32 *mapping_fib_index, u8 by_external, u8 *is_addr_only, twice_nat_type_t *twice_nat, lb_nat_type_t *lb, ip4_address_t *ext_host_addr, u8 *is_identity_nat, snat_static_mapping_t **out)
Match NAT44 static mapping.
static_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
static void * ip4_next_header(ip4_header_t *i)
void nat_hairpinning_sm_unknown_proto(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip)
vl_api_fib_path_type_t type
static uword snat_hairpin_dst_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_ed)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static u32 ed_value_get_session_index(clib_bihash_kv_16_8_t *value)
snat_static_mapping_t * static_mappings
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
struct snat_main_s::@91 counters
static void * vnet_get_config_data(vnet_config_main_t *cm, u32 *config_index, u32 *next_index, u32 n_data_bytes)
clib_bihash_8_8_t static_mapping_by_external
vl_api_address_union_t src_address
#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).
static void init_nat_k(clib_bihash_kv_8_8_t *kv, ip4_address_t addr, u16 port, u32 fib_index, nat_protocol_t proto)
snat_interface_t * output_feature_interfaces
vl_api_ip_port_and_mask_t src_port
vl_api_mac_address_t dst_addr
#define VLIB_REGISTER_NODE(x,...)
vlib_node_registration_t snat_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_dst_node)
sll srl srl sll sra u16x4 i
static_always_inline void vnet_feature_next(u32 *next0, vlib_buffer_t *b0)
int snat_hairpinning(vlib_main_t *vm, vlib_node_runtime_t *node, snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, udp_header_t *udp0, tcp_header_t *tcp0, u32 proto0, int is_ed, int do_trace)
u32 current_config_index
Used by feature subgraph arcs to visit enabled feature nodes.
8 octet key, 8 octet key value pair
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_main_t vlib_node_runtime_t * node
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
VLIB buffer representation.
snat_main_per_thread_data_t * per_thread_data
#define SNAT_FLAG_HAIRPINNING
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 uword nat44_hairpinning_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_ed)
snat_address_t * addresses
struct _vnet_feature_arc_registration vnet_feature_arc_registration_t
feature registration object
static void init_ed_k(clib_bihash_kv_16_8_t *kv, ip4_address_t l_addr, u16 l_port, ip4_address_t r_addr, u16 r_port, u32 fib_index, u8 proto)
static uword snat_hairpin_src_fn_inline(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame, int is_ed)
#define vec_foreach(var, vec)
Vector iterator.
u16 flags
Copy of main node flags.
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
vlib_node_registration_t nat44_hairpinning_node
(constructor) VLIB_REGISTER_NODE (nat44_hairpinning_node)
#define VLIB_NODE_FLAG_TRACE
vnet_feature_config_main_t * feature_config_mains
feature config main objects
vnet_feature_main_t feature_main
vnet_feature_arc_registration_t vnet_feat_arc_ip4_local
snat_session_t * sessions
static_always_inline int is_hairpinning(snat_main_t *sm, ip4_address_t *dst_addr)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
static u32 ed_value_get_thread_index(clib_bihash_kv_16_8_t *value)
static u16 ip_csum_fold(ip_csum_t c)
vl_api_interface_index_t sw_if_index
void nat44_ed_hairpinning_unknown_proto(snat_main_t *sm, vlib_buffer_t *b, ip4_header_t *ip)
u32 snat_icmp_hairpinning(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, int is_ed)