#undef _
};
-vlib_node_registration_t snat_det_out2in_node;
-
static u8 *
format_nat_det_out2in_trace (u8 * s, va_list * args)
{
return s;
}
+#ifndef CLIB_MARCH_VARIANT
/**
* Get address and port values to be used for ICMP packet translation
* and create session if needed
echo0 = (icmp_echo_header_t *) (icmp0 + 1);
sw_if_index0 = vnet_buffer (b0)->sw_if_index[VLIB_RX];
- if (!icmp_is_error_message (icmp0))
+ if (!icmp_type_is_error_message
+ (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags))
{
protocol = SNAT_PROTOCOL_ICMP;
key0.ext_host_addr = ip0->src_address;
key0.ext_host_port = 0;
- key0.out_port = echo0->identifier;
+ key0.out_port = vnet_buffer (b0)->ip.reass.l4_src_port;
out_addr = ip0->dst_address;
}
else
{
+ /* if error message, then it's not fragmented and we can access it */
inner_ip0 = (ip4_header_t *) (echo0 + 1);
l4_header = ip4_next_header (inner_ip0);
protocol = ip_proto_to_snat_proto (inner_ip0->protocol);
goto out;
}
- if (PREDICT_FALSE (icmp0->type != ICMP4_echo_reply &&
- !icmp_is_error_message (icmp0)))
+ if (PREDICT_FALSE
+ (vnet_buffer (b0)->ip.reass.icmp_type_or_tcp_flags != ICMP4_echo_reply
+ && !icmp_type_is_error_message (vnet_buffer (b0)->ip.
+ reass.icmp_type_or_tcp_flags)))
{
b0->error = node->errors[NAT_DET_OUT2IN_ERROR_BAD_ICMP_TYPE];
next0 = NAT_DET_OUT2IN_NEXT_DROP;
*(snat_det_map_t **) e = dm0;
return next0;
}
+#endif
-static uword
-snat_det_out2in_node_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
+VLIB_NODE_FN (snat_det_out2in_node) (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
{
u32 n_left_from, *from, *to_next;
nat_det_out2in_next_t next_index;
b0->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
goto trace0;
}
- new_port0 = ses0->in_port;
+ old_port0 = udp0->dst_port;
+ udp0->dst_port = new_port0 = ses0->in_port;
old_addr0 = ip0->dst_address;
ip0->dst_address = new_addr0;
&& ses0->state == SNAT_SESSION_TCP_LAST_ACK)
snat_det_ses_close (dm0, ses0);
- old_port0 = tcp0->dst;
- tcp0->dst = new_port0;
-
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
ip4_header_t,
dst_address /* changed member */ );
-
sum0 = ip_csum_update (sum0, old_port0, new_port0,
ip4_header_t /* cheat */ ,
length /* changed member */ );
tcp0->checksum = ip_csum_fold (sum0);
}
- else
+ else if (udp0->checksum)
{
- old_port0 = udp0->dst_port;
- udp0->dst_port = new_port0;
- udp0->checksum = 0;
+ sum0 = udp0->checksum;
+ sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
+ ip4_header_t,
+ dst_address /* changed member */ );
+ sum0 = ip_csum_update (sum0, old_port0, new_port0,
+ ip4_header_t /* cheat */ ,
+ length /* changed member */ );
+ udp0->checksum = ip_csum_fold (sum0);
}
trace0:
b1->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
goto trace1;
}
- new_port1 = ses1->in_port;
+ old_port1 = udp1->dst_port;
+ udp1->dst_port = new_port1 = ses1->in_port;
old_addr1 = ip1->dst_address;
ip1->dst_address = new_addr1;
&& ses1->state == SNAT_SESSION_TCP_LAST_ACK)
snat_det_ses_close (dm1, ses1);
- old_port1 = tcp1->dst;
- tcp1->dst = new_port1;
-
sum1 = tcp1->checksum;
sum1 = ip_csum_update (sum1, old_addr1.as_u32, new_addr1.as_u32,
ip4_header_t,
dst_address /* changed member */ );
-
sum1 = ip_csum_update (sum1, old_port1, new_port1,
ip4_header_t /* cheat */ ,
length /* changed member */ );
tcp1->checksum = ip_csum_fold (sum1);
}
- else
+ else if (udp1->checksum)
{
- old_port1 = udp1->dst_port;
- udp1->dst_port = new_port1;
- udp1->checksum = 0;
+ sum1 = udp1->checksum;
+ sum1 = ip_csum_update (sum1, old_addr1.as_u32, new_addr1.as_u32,
+ ip4_header_t,
+ dst_address /* changed member */ );
+ sum1 = ip_csum_update (sum1, old_port1, new_port1,
+ ip4_header_t /* cheat */ ,
+ length /* changed member */ );
+ udp1->checksum = ip_csum_fold (sum1);
}
trace1:
b0->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
goto trace00;
}
- new_port0 = ses0->in_port;
+ old_port0 = udp0->dst_port;
+ udp0->dst_port = new_port0 = ses0->in_port;
old_addr0 = ip0->dst_address;
ip0->dst_address = new_addr0;
&& ses0->state == SNAT_SESSION_TCP_LAST_ACK)
snat_det_ses_close (dm0, ses0);
- old_port0 = tcp0->dst;
- tcp0->dst = new_port0;
-
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
ip4_header_t,
dst_address /* changed member */ );
-
sum0 = ip_csum_update (sum0, old_port0, new_port0,
ip4_header_t /* cheat */ ,
length /* changed member */ );
tcp0->checksum = ip_csum_fold (sum0);
}
- else
+ else if (udp0->checksum)
{
- old_port0 = udp0->dst_port;
- udp0->dst_port = new_port0;
- udp0->checksum = 0;
+ sum0 = udp0->checksum;
+ sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
+ ip4_header_t,
+ dst_address /* changed member */ );
+ sum0 = ip_csum_update (sum0, old_port0, new_port0,
+ ip4_header_t /* cheat */ ,
+ length /* changed member */ );
+ udp0->checksum = ip_csum_fold (sum0);
}
trace00:
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- vlib_node_increment_counter (vm, snat_det_out2in_node.index,
+ vlib_node_increment_counter (vm, sm->det_out2in_node_index,
NAT_DET_OUT2IN_ERROR_OUT2IN_PACKETS,
pkts_processed);
return frame->n_vectors;
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (snat_det_out2in_node) = {
- .function = snat_det_out2in_node_fn,
.name = "nat44-det-out2in",
.vector_size = sizeof (u32),
.format_trace = format_nat_det_out2in_trace,
};
/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (snat_det_out2in_node, snat_det_out2in_node_fn);
-
/*
* fd.io coding-style-patch-verification: ON
*