43 #define foreach_nat44_hairpin_error \ 44 _(PROCESSED, "NAT44 hairpinning packets processed") 48 #define _(sym,str) NAT44_HAIRPIN_ERROR_##sym, 55 #define _(sym,string) string, 88 #ifndef CLIB_MARCH_VARIANT 97 snat_session_t *s0 = NULL;
100 u32 new_dst_addr0 = 0, old_dst_addr0, ti = 0, si;
101 u16 new_dst_port0, old_dst_port0;
114 new_dst_port0 = sm0.
port;
122 (clib_net_to_host_u16 (udp0->
dst_port) -
147 new_dst_addr0 = s0->in2out.addr.as_u32;
148 new_dst_port0 = s0->in2out.port;
162 old_dst_port0 = tcp0->dst;
167 tcp0->dst = new_dst_port0;
168 sum0 = tcp0->checksum;
185 sum0 = tcp0->checksum;
197 #ifndef CLIB_MARCH_VARIANT 205 u32 old_dst_addr0, new_dst_addr0;
206 u32 old_addr0, new_addr0;
207 u16 old_port0, new_port0;
208 u16 old_checksum0, new_checksum0;
223 if (protocol != SNAT_PROTOCOL_TCP && protocol != SNAT_PROTOCOL_UDP)
250 new_dst_addr0 = s0->in2out.addr.as_u32;
257 sum0 = icmp0->checksum;
263 old_checksum0 = inner_ip0->
checksum;
268 new_checksum0 = inner_ip0->
checksum;
269 sum0 = icmp0->checksum;
276 l4_header->
src_port = s0->in2out.port;
278 sum0 = icmp0->checksum;
291 if (clib_bihash_search_8_8
299 key0.
port = icmp_id0;
305 (clib_net_to_host_u16 (icmp_id0) -
317 new_dst_addr0 = s0->in2out.addr.as_u32;
319 s0->in2out.fib_index;
321 sum0 = icmp0->checksum;
353 #ifndef CLIB_MARCH_VARIANT 360 u32 old_addr, new_addr;
380 #ifndef CLIB_MARCH_VARIANT 385 u32 old_addr, new_addr = 0, ti = 0;
402 if (clib_bihash_search_16_8 (&tsm->
out2in_ed, &s_kv, &s_value))
405 if (clib_bihash_search_8_8
427 #ifndef CLIB_MARCH_VARIANT 432 u16 sport,
u16 dport,
u32 proto0,
int is_ed)
438 u32 new_dst_addr0 = 0, old_dst_addr0, ti = 0, si;
439 u16 new_dst_port0, old_dst_port0;
456 new_dst_port0 = sm0.
port;
464 (clib_net_to_host_u16 (udp0->
dst_port) -
488 new_dst_addr0 = s0->in2out.addr.as_u32;
489 new_dst_port0 = s0->in2out.port;
504 old_dst_port0 = dport;
511 tcp0->dst = new_dst_port0;
512 sum0 = tcp0->checksum;
530 sum0 = tcp0->checksum;
545 u32 n_left_from, *from, *to_next, stats_node_index;
547 u32 pkts_processed = 0;
559 while (n_left_from > 0)
565 while (n_left_from > 0 && n_left_to_next > 0)
600 to_next, n_left_to_next,
608 NAT44_HAIRPIN_ERROR_PROCESSED, pkts_processed);
621 .name =
"nat44-hairpinning",
622 .vector_size =
sizeof (
u32),
643 .name =
"nat44-ed-hairpinning",
644 .vector_size =
sizeof (
u32),
661 u32 n_left_from, *from, *to_next, stats_node_index;
663 u32 pkts_processed = 0;
673 while (n_left_from > 0)
679 while (n_left_from > 0 && n_left_to_next > 0)
704 if (proto0 == SNAT_PROTOCOL_TCP || proto0 == SNAT_PROTOCOL_UDP)
711 else if (proto0 == SNAT_PROTOCOL_ICMP)
732 to_next, n_left_to_next,
740 NAT44_HAIRPIN_ERROR_PROCESSED, pkts_processed);
753 .name =
"nat44-hairpin-dst",
754 .vector_size =
sizeof (
u32),
775 .name =
"nat44-ed-hairpin-dst",
776 .vector_size =
sizeof (
u32),
793 u32 n_left_from, *from, *to_next, stats_node_index;
795 u32 pkts_processed = 0;
805 while (n_left_from > 0)
811 while (n_left_from > 0 && n_left_to_next > 0)
835 if ((nat_interface_is_inside(i)) && (sw_if_index0 == i->sw_if_index))
837 if (PREDICT_FALSE ((vnet_buffer (b0)->snat.flags) &
838 SNAT_FLAG_HAIRPINNING))
840 if (PREDICT_TRUE (sm->num_workers > 1))
841 next0 = SNAT_HAIRPIN_SRC_NEXT_SNAT_IN2OUT_WH;
843 next0 = SNAT_HAIRPIN_SRC_NEXT_SNAT_IN2OUT;
854 to_next, n_left_to_next,
862 NAT44_HAIRPIN_ERROR_PROCESSED, pkts_processed);
863 return frame->n_vectors;
875 .name =
"nat44-hairpin-src",
876 .vector_size =
sizeof (
u32),
899 .name =
"nat44-ed-hairpin-src",
900 .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)
static_always_inline u8 icmp_is_error_message(icmp46_header_t *icmp)
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
#define static_always_inline
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
vl_api_interface_index_t sw_if_index
#define foreach_nat44_hairpin_error
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
vl_api_ip_proto_t protocol
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)
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
static void make_ed_kv(clib_bihash_kv_16_8_t *kv, ip4_address_t *l_addr, ip4_address_t *r_addr, u8 proto, u32 fib_index, u16 l_port, u16 r_port)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
snat_get_worker_function_t * worker_out2in_cb
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)
void nat44_reass_hairpinning(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, u16 sport, u16 dport, u32 proto0, int is_ed)
static int ip4_is_first_fragment(const ip4_header_t *i)
static u32 ip_proto_to_snat_proto(u8 ip_proto)
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_node_registration_t nat44_hairpinning_node
(constructor) VLIB_REGISTER_NODE (nat44_hairpinning_node)
NAT plugin virtual fragmentation reassembly.
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 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)