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, 106 u32 new_dst_addr0 = 0, old_dst_addr0, ti = 0, si;
107 u16 new_dst_port0, old_dst_port0;
120 new_dst_port0 = sm0.
port;
128 (clib_net_to_host_u16 (udp0->
dst_port) -
153 new_dst_addr0 = s0->in2out.addr.as_u32;
154 new_dst_port0 = s0->in2out.port;
168 old_dst_port0 = tcp0->dst;
173 tcp0->dst = new_dst_port0;
174 sum0 = tcp0->checksum;
191 sum0 = tcp0->checksum;
209 u32 old_dst_addr0, new_dst_addr0;
210 u32 old_addr0, new_addr0;
211 u16 old_port0, new_port0;
212 u16 old_checksum0, new_checksum0;
227 if (protocol != SNAT_PROTOCOL_TCP && protocol != SNAT_PROTOCOL_UDP)
254 new_dst_addr0 = s0->in2out.addr.as_u32;
261 sum0 = icmp0->checksum;
267 old_checksum0 = inner_ip0->
checksum;
272 new_checksum0 = inner_ip0->
checksum;
273 sum0 = icmp0->checksum;
280 l4_header->
src_port = s0->in2out.port;
282 sum0 = icmp0->checksum;
295 if (clib_bihash_search_8_8
303 key0.
port = icmp_id0;
309 (clib_net_to_host_u16 (icmp_id0) -
321 new_dst_addr0 = s0->in2out.addr.as_u32;
323 s0->in2out.fib_index;
325 sum0 = icmp0->checksum;
362 u32 old_addr, new_addr;
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
430 u16 sport,
u16 dport,
u32 proto0,
int is_ed)
436 u32 new_dst_addr0 = 0, old_dst_addr0, ti = 0, si;
437 u16 new_dst_port0, old_dst_port0;
454 new_dst_port0 = sm0.
port;
462 (clib_net_to_host_u16 (udp0->
dst_port) -
486 new_dst_addr0 = s0->in2out.addr.as_u32;
487 new_dst_port0 = s0->in2out.port;
502 old_dst_port0 = dport;
509 tcp0->dst = new_dst_port0;
510 sum0 = tcp0->checksum;
528 sum0 = tcp0->checksum;
542 u32 n_left_from, *from, *to_next, stats_node_index;
544 u32 pkts_processed = 0;
556 while (n_left_from > 0)
562 while (n_left_from > 0 && n_left_to_next > 0)
597 to_next, n_left_to_next,
605 NAT44_HAIRPIN_ERROR_PROCESSED, pkts_processed);
619 .name =
"nat44-hairpinning",
620 .vector_size =
sizeof (
u32),
644 .name =
"nat44-ed-hairpinning",
645 .vector_size =
sizeof (
u32),
665 u32 n_left_from, *from, *to_next, stats_node_index;
667 u32 pkts_processed = 0;
677 while (n_left_from > 0)
683 while (n_left_from > 0 && n_left_to_next > 0)
708 if (proto0 == SNAT_PROTOCOL_TCP || proto0 == SNAT_PROTOCOL_UDP)
715 else if (proto0 == SNAT_PROTOCOL_ICMP)
736 to_next, n_left_to_next,
744 NAT44_HAIRPIN_ERROR_PROCESSED, pkts_processed);
758 .name =
"nat44-hairpin-dst",
759 .vector_size =
sizeof (
u32),
783 .name =
"nat44-ed-hairpin-dst",
784 .vector_size =
sizeof (
u32),
804 u32 n_left_from, *from, *to_next, stats_node_index;
806 u32 pkts_processed = 0;
816 while (n_left_from > 0)
822 while (n_left_from > 0 && n_left_to_next > 0)
846 if ((nat_interface_is_inside(i)) && (sw_if_index0 == i->sw_if_index))
848 if (PREDICT_FALSE ((vnet_buffer (b0)->snat.flags) &
849 SNAT_FLAG_HAIRPINNING))
851 if (PREDICT_TRUE (sm->num_workers > 1))
852 next0 = SNAT_HAIRPIN_SRC_NEXT_SNAT_IN2OUT_WH;
854 next0 = SNAT_HAIRPIN_SRC_NEXT_SNAT_IN2OUT;
865 to_next, n_left_to_next,
873 NAT44_HAIRPIN_ERROR_PROCESSED, pkts_processed);
874 return frame->n_vectors;
887 .name =
"nat44-hairpin-src",
888 .vector_size =
sizeof (
u32),
914 .name =
"nat44-ed-hairpin-src",
915 .vector_size =
sizeof (
u32),
vnet_config_main_t config_main
vlib_node_registration_t snat_hairpin_src_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_src_node)
u32 current_config_index
Used by feature subgraph arcs to visit enabled feature nodes.
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 uword snat_hairpin_src_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
static char * nat44_hairpin_error_strings[]
struct _tcp_header tcp_header_t
#define static_always_inline
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#define foreach_nat44_hairpin_error
static void * ip4_next_header(ip4_header_t *i)
static uword snat_hairpin_dst_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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)
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
static uword nat44_ed_hairpin_src_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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)
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
#define VLIB_REGISTER_NODE(x,...)
vlib_node_registration_t snat_hairpin_dst_node
(constructor) VLIB_REGISTER_NODE (snat_hairpin_dst_node)
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.
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)
struct _vlib_node_registration vlib_node_registration_t
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)
The NAT inline functions.
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)
static uword nat44_hairpinning_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
snat_address_t * addresses
static uword nat44_ed_hairpinning_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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)
static uword nat44_ed_hairpin_dst_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
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)
VLIB_NODE_FUNCTION_MULTIARCH(nat44_hairpinning_node, nat44_hairpinning_fn)
u32 snat_icmp_hairpinning(snat_main_t *sm, vlib_buffer_t *b0, ip4_header_t *ip0, icmp46_header_t *icmp0, int is_ed)