42 #define foreach_nat44_hairpin_error \ 43 _(PROCESSED, "NAT44 hairpinning packets processed") 47 #define _(sym,str) NAT44_HAIRPIN_ERROR_##sym, 54 #define _(sym,string) string, 87 #ifndef CLIB_MARCH_VARIANT 99 u32 new_dst_addr0 = 0, old_dst_addr0, ti = 0,
si;
100 u16 new_dst_port0, old_dst_port0;
113 new_dst_port0 = sm0.
port;
121 (clib_net_to_host_u16 (udp0->
dst_port) -
146 new_dst_addr0 = s0->in2out.addr.as_u32;
147 new_dst_port0 = s0->in2out.port;
161 old_dst_port0 = tcp0->dst;
166 tcp0->dst = new_dst_port0;
167 sum0 = tcp0->checksum;
184 sum0 = tcp0->checksum;
196 #ifndef CLIB_MARCH_VARIANT 204 u32 old_dst_addr0, new_dst_addr0;
205 u32 old_addr0, new_addr0;
206 u16 old_port0, new_port0;
207 u16 old_checksum0, new_checksum0;
223 if (protocol != NAT_PROTOCOL_TCP && protocol != NAT_PROTOCOL_UDP)
233 if (clib_bihash_search_16_8
251 new_dst_addr0 = s0->in2out.addr.as_u32;
258 sum0 = icmp0->checksum;
264 old_checksum0 = inner_ip0->
checksum;
269 new_checksum0 = inner_ip0->
checksum;
270 sum0 = icmp0->checksum;
277 l4_header->
src_port = s0->in2out.port;
279 sum0 = icmp0->checksum;
292 if (clib_bihash_search_8_8
300 key0.
port = icmp_id0;
306 (clib_net_to_host_u16 (icmp_id0) -
318 new_dst_addr0 = s0->in2out.addr.as_u32;
320 s0->in2out.fib_index;
322 sum0 = icmp0->checksum;
354 #ifndef CLIB_MARCH_VARIANT 361 u32 old_addr, new_addr;
381 #ifndef CLIB_MARCH_VARIANT 386 u32 old_addr, new_addr = 0, ti = 0;
403 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &s_kv, &s_value))
406 if (clib_bihash_search_8_8
433 u32 n_left_from, *from, *to_next, stats_node_index;
435 u32 pkts_processed = 0;
447 while (n_left_from > 0)
453 while (n_left_from > 0 && n_left_to_next > 0)
488 to_next, n_left_to_next,
496 NAT44_HAIRPIN_ERROR_PROCESSED, pkts_processed);
509 .name =
"nat44-hairpinning",
510 .vector_size =
sizeof (
u32),
531 .name =
"nat44-ed-hairpinning",
532 .vector_size =
sizeof (
u32),
549 u32 n_left_from, *from, *to_next, stats_node_index;
551 u32 pkts_processed = 0;
561 while (n_left_from > 0)
567 while (n_left_from > 0 && n_left_to_next > 0)
592 if (proto0 == NAT_PROTOCOL_TCP || proto0 == NAT_PROTOCOL_UDP)
599 else if (proto0 == NAT_PROTOCOL_ICMP)
620 to_next, n_left_to_next,
628 NAT44_HAIRPIN_ERROR_PROCESSED, pkts_processed);
641 .name =
"nat44-hairpin-dst",
642 .vector_size =
sizeof (
u32),
663 .name =
"nat44-ed-hairpin-dst",
664 .vector_size =
sizeof (
u32),
681 u32 n_left_from, *from, *to_next, stats_node_index;
683 u32 pkts_processed = 0;
693 while (n_left_from > 0)
699 while (n_left_from > 0 && n_left_to_next > 0)
723 if ((nat_interface_is_inside(i)) && (sw_if_index0 == i->sw_if_index))
725 if (PREDICT_FALSE ((vnet_buffer (b0)->snat.flags) &
726 SNAT_FLAG_HAIRPINNING))
728 if (PREDICT_TRUE (sm->num_workers > 1))
729 next0 = SNAT_HAIRPIN_SRC_NEXT_SNAT_IN2OUT_WH;
731 next0 = SNAT_HAIRPIN_SRC_NEXT_SNAT_IN2OUT;
742 to_next, n_left_to_next,
750 NAT44_HAIRPIN_ERROR_PROCESSED, pkts_processed);
751 return frame->n_vectors;
763 .name =
"nat44-hairpin-src",
764 .vector_size =
sizeof (
u32),
787 .name =
"nat44-ed-hairpin-src",
788 .vector_size =
sizeof (
u32),
vnet_config_main_t config_main
u32 hairpin_dst_node_index
u32 ed_hairpinning_node_index
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 make_sm_kv(clib_bihash_kv_8_8_t *kv, ip4_address_t *addr, u8 proto, u32 fib_index, u16 port)
static char * nat44_hairpin_error_strings[]
#define VLIB_NODE_FN(node)
struct _tcp_header tcp_header_t
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.
vl_api_interface_index_t sw_if_index
#define foreach_nat44_hairpin_error
static_always_inline u8 icmp_type_is_error_message(u8 icmp_type)
static void * ip4_next_header(ip4_header_t *i)
int snat_static_mapping_match(snat_main_t *sm, snat_session_key_t match, snat_session_key_t *mapping, 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)
Match NAT44 static mapping.
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.
clib_bihash_16_8_t out2in_ed
snat_static_mapping_t * static_mappings
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
static void * vnet_get_config_data(vnet_config_main_t *cm, u32 *config_index, u32 *next_index, u32 n_data_bytes)
u32 hairpin_src_node_index
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 vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
snat_interface_t * output_feature_interfaces
u32 ed_hairpin_src_node_index
#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)
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.
u32 ed_hairpin_dst_node_index
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.
int snat_hairpinning(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)
u32 hairpinning_node_index
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 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.
vlib_main_t vlib_node_runtime_t vlib_frame_t * frame
vlib_node_registration_t nat44_hairpinning_node
(constructor) VLIB_REGISTER_NODE (nat44_hairpinning_node)
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 void make_ed_kv(ip4_address_t *l_addr, ip4_address_t *r_addr, u8 proto, u32 fib_index, u16 l_port, u16 r_port, u64 value, clib_bihash_kv_16_8_t *kv)
static u16 ip_csum_fold(ip_csum_t c)
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)