summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOle Troan <ot@cisco.com>2019-11-04 13:44:09 +0100
committerDave Barach <openvpp@barachs.net>2019-11-04 15:44:00 +0000
commit8f6d7a78767e6c49925bd380ed3601b70b43b3ee (patch)
treedd3158b1a32a61f402fd182ea8b9c865a59b7c9d /src
parentcb3cfe876b3bbe2f360e3b32a43a060bdcb8bf9e (diff)
nat: revert respect udp checksum
This reverts commit 0d75f783644a24b219ed79d9f9c17387783f67ca. Type: fix Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: Iaf33301201897e6646eba2b4157e2a45f5fd30f2
Diffstat (limited to 'src')
-rwxr-xr-xsrc/plugins/nat/in2out.c110
-rw-r--r--src/plugins/nat/in2out_ed.c120
-rw-r--r--src/plugins/nat/nat_det_in2out.c69
-rw-r--r--src/plugins/nat/nat_det_out2in.c60
-rwxr-xr-xsrc/plugins/nat/out2in.c108
-rw-r--r--src/plugins/nat/out2in_ed.c127
6 files changed, 166 insertions, 428 deletions
diff --git a/src/plugins/nat/in2out.c b/src/plugins/nat/in2out.c
index 802202d7939..c69bc61236b 100755
--- a/src/plugins/nat/in2out.c
+++ b/src/plugins/nat/in2out.c
@@ -1075,11 +1075,12 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
src_address /* changed member */ );
ip0->checksum = ip_csum_fold (sum0);
- old_port0 = udp0->src_port;
- new_port0 = udp0->src_port = s0->out2in.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->src_port;
+ tcp0->src_port = s0->out2in.port;
+ new_port0 = tcp0->src_port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
ip4_header_t,
@@ -1093,17 +1094,9 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
}
else
{
- if (PREDICT_FALSE (udp0->checksum))
- {
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
- 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);
- }
+ old_port0 = udp0->src_port;
+ udp0->src_port = s0->out2in.port;
+ udp0->checksum = 0;
udp_packets++;
}
@@ -1271,11 +1264,12 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
src_address /* changed member */ );
ip1->checksum = ip_csum_fold (sum1);
- old_port1 = udp1->src_port;
- new_port1 = udp1->src_port = s1->out2in.port;
-
if (PREDICT_TRUE (proto1 == SNAT_PROTOCOL_TCP))
{
+ old_port1 = tcp1->src_port;
+ tcp1->src_port = s1->out2in.port;
+ new_port1 = tcp1->src_port;
+
sum1 = tcp1->checksum;
sum1 = ip_csum_update (sum1, old_addr1, new_addr1,
ip4_header_t,
@@ -1289,17 +1283,9 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
}
else
{
- if (PREDICT_FALSE (udp1->checksum))
- {
- sum1 = udp1->checksum;
- sum1 = ip_csum_update (sum1, old_addr1, new_addr1,
- 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);
- }
+ old_port1 = udp1->src_port;
+ udp1->src_port = s1->out2in.port;
+ udp1->checksum = 0;
udp_packets++;
}
@@ -1502,11 +1488,12 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
src_address /* changed member */ );
ip0->checksum = ip_csum_fold (sum0);
- old_port0 = udp0->src_port;
- new_port0 = udp0->src_port = s0->out2in.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->src_port;
+ tcp0->src_port = s0->out2in.port;
+ new_port0 = tcp0->src_port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
ip4_header_t,
@@ -1520,17 +1507,9 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
}
else
{
- if (PREDICT_FALSE (udp0->checksum))
- {
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
- 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);
- }
+ old_port0 = udp0->src_port;
+ udp0->src_port = s0->out2in.port;
+ udp0->checksum = 0;
udp_packets++;
}
@@ -1890,11 +1869,12 @@ VLIB_NODE_FN (nat44_in2out_reass_node) (vlib_main_t * vm,
if (PREDICT_FALSE (ip4_is_first_fragment (ip0)))
{
- old_port0 = udp0->src_port;
- new_port0 = udp0->src_port = s0->out2in.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->src_port;
+ tcp0->src_port = s0->out2in.port;
+ new_port0 = tcp0->src_port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
ip4_header_t,
@@ -1904,16 +1884,11 @@ VLIB_NODE_FN (nat44_in2out_reass_node) (vlib_main_t * vm,
length /* changed member */ );
tcp0->checksum = ip_csum_fold (sum0);
}
- else if (PREDICT_FALSE (udp0->checksum))
+ else
{
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
- 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);
+ old_port0 = udp0->src_port;
+ udp0->src_port = s0->out2in.port;
+ udp0->checksum = 0;
}
}
@@ -2124,11 +2099,11 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
if (PREDICT_FALSE (new_port0 != udp0->dst_port))
{
- old_port0 = udp0->src_port;
- udp0->src_port = new_port0;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->src_port;
+ tcp0->src_port = new_port0;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
ip4_header_t,
@@ -2139,16 +2114,11 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
mss_clamping (sm, tcp0, &sum0);
tcp0->checksum = ip_csum_fold (sum0);
}
- else if (udp0->checksum)
+ else
{
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
- 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);
+ old_port0 = udp0->src_port;
+ udp0->src_port = new_port0;
+ udp0->checksum = 0;
}
}
else
@@ -2162,14 +2132,6 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
mss_clamping (sm, tcp0, &sum0);
tcp0->checksum = ip_csum_fold (sum0);
}
- else if (udp0->checksum)
- {
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
- ip4_header_t,
- dst_address /* changed member */ );
- udp0->checksum = ip_csum_fold (sum0);
- }
}
/* Hairpinning */
diff --git a/src/plugins/nat/in2out_ed.c b/src/plugins/nat/in2out_ed.c
index c878dddd13e..de00c6e7b13 100644
--- a/src/plugins/nat/in2out_ed.c
+++ b/src/plugins/nat/in2out_ed.c
@@ -1045,11 +1045,11 @@ nat44_ed_in2out_node_fn_inline (vlib_main_t * vm,
dst_address);
ip0->checksum = ip_csum_fold (sum0);
- old_port0 = udp0->src_port;
- new_port0 = udp0->src_port = s0->out2in.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->src_port;
+ new_port0 = tcp0->src_port = s0->out2in.port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
dst_address);
@@ -1073,29 +1073,10 @@ nat44_ed_in2out_node_fn_inline (vlib_main_t * vm,
(sm, s0, tcp0, thread_index))
goto trace00;
}
- else if (udp0->checksum)
- {
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
- dst_address);
- sum0 = ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
- length);
- if (PREDICT_FALSE (is_twice_nat_session (s0)))
- {
- sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
- s0->ext_host_addr.as_u32,
- ip4_header_t, dst_address);
- sum0 = ip_csum_update (sum0, tcp0->dst_port,
- s0->ext_host_port, ip4_header_t,
- length);
- udp0->dst_port = s0->ext_host_port;
- ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
- }
- udp0->checksum = ip_csum_fold (sum0);
- udp_packets++;
- }
else
{
+ udp0->src_port = s0->out2in.port;
+ udp0->checksum = 0;
if (PREDICT_FALSE (is_twice_nat_session (s0)))
{
udp0->dst_port = s0->ext_host_port;
@@ -1274,11 +1255,11 @@ nat44_ed_in2out_node_fn_inline (vlib_main_t * vm,
dst_address);
ip1->checksum = ip_csum_fold (sum1);
- old_port1 = udp1->src_port;
- new_port1 = udp1->src_port = s1->out2in.port;
-
if (PREDICT_TRUE (proto1 == SNAT_PROTOCOL_TCP))
{
+ old_port1 = tcp1->src_port;
+ new_port1 = tcp1->src_port = s1->out2in.port;
+
sum1 = tcp1->checksum;
sum1 = ip_csum_update (sum1, old_addr1, new_addr1, ip4_header_t,
dst_address);
@@ -1302,30 +1283,10 @@ nat44_ed_in2out_node_fn_inline (vlib_main_t * vm,
(sm, s1, tcp1, thread_index))
goto trace01;
}
- else if (udp1->checksum)
- {
- sum1 = udp1->checksum;
- sum1 = ip_csum_update (sum1, old_addr1, new_addr1, ip4_header_t,
- dst_address);
- sum1 = ip_csum_update (sum1, old_port1, new_port1, ip4_header_t,
- length);
-
- if (PREDICT_FALSE (is_twice_nat_session (s1)))
- {
- sum1 = ip_csum_update (sum1, ip1->dst_address.as_u32,
- s1->ext_host_addr.as_u32,
- ip4_header_t, dst_address);
- sum1 = ip_csum_update (sum1, tcp1->dst_port,
- s1->ext_host_port, ip4_header_t,
- length);
- udp1->dst_port = s1->ext_host_port;
- ip1->dst_address.as_u32 = s1->ext_host_addr.as_u32;
- }
- udp1->checksum = ip_csum_fold (sum1);
- udp_packets++;
- }
else
{
+ udp1->src_port = s1->out2in.port;
+ udp1->checksum = 0;
if (PREDICT_FALSE (is_twice_nat_session (s1)))
{
udp1->dst_port = s1->ext_host_port;
@@ -1532,11 +1493,11 @@ nat44_ed_in2out_node_fn_inline (vlib_main_t * vm,
dst_address);
ip0->checksum = ip_csum_fold (sum0);
- old_port0 = udp0->src_port;
- new_port0 = udp0->src_port = s0->out2in.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->src_port;
+ new_port0 = tcp0->src_port = s0->out2in.port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
dst_address);
@@ -1560,29 +1521,10 @@ nat44_ed_in2out_node_fn_inline (vlib_main_t * vm,
(sm, s0, tcp0, thread_index))
goto trace0;
}
- else if (udp0->checksum)
- {
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
- dst_address);
- sum0 = ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
- length);
- if (PREDICT_FALSE (is_twice_nat_session (s0)))
- {
- sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
- s0->ext_host_addr.as_u32,
- ip4_header_t, dst_address);
- sum0 = ip_csum_update (sum0, tcp0->dst_port,
- s0->ext_host_port, ip4_header_t,
- length);
- udp0->dst_port = s0->ext_host_port;
- ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
- }
- udp0->checksum = ip_csum_fold (sum0);
- udp_packets++;
- }
else
{
+ udp0->src_port = s0->out2in.port;
+ udp0->checksum = 0;
if (PREDICT_FALSE (is_twice_nat_session (s0)))
{
udp0->dst_port = s0->ext_host_port;
@@ -1973,11 +1915,12 @@ nat44_ed_in2out_reass_node_fn_inline (vlib_main_t * vm,
if (PREDICT_FALSE (ip4_is_first_fragment (ip0)))
{
- old_port0 = udp0->src_port;
- new_port0 = udp0->src_port = s0->out2in.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->src_port;
+ tcp0->src_port = s0->out2in.port;
+ new_port0 = tcp0->src_port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
ip4_header_t,
@@ -1998,30 +1941,11 @@ nat44_ed_in2out_reass_node_fn_inline (vlib_main_t * vm,
}
tcp0->checksum = ip_csum_fold (sum0);
}
- else if (udp0->checksum)
- {
- sum0 = udp0->checksum;
- sum0 =
- ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
- dst_address);
- sum0 =
- ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
- length);
- if (PREDICT_FALSE (is_twice_nat_session (s0)))
- {
- sum0 = ip_csum_update (sum0, ip0->dst_address.as_u32,
- s0->ext_host_addr.as_u32,
- ip4_header_t, dst_address);
- sum0 = ip_csum_update (sum0, tcp0->dst_port,
- s0->ext_host_port, ip4_header_t,
- length);
- udp0->dst_port = s0->ext_host_port;
- ip0->dst_address.as_u32 = s0->ext_host_addr.as_u32;
- }
- udp0->checksum = ip_csum_fold (sum0);
- }
else
{
+ old_port0 = udp0->src_port;
+ udp0->src_port = s0->out2in.port;
+ udp0->checksum = 0;
if (PREDICT_FALSE (is_twice_nat_session (s0)))
{
udp0->dst_port = s0->ext_host_port;
diff --git a/src/plugins/nat/nat_det_in2out.c b/src/plugins/nat/nat_det_in2out.c
index 832a2bae947..918e1f5f9c0 100644
--- a/src/plugins/nat/nat_det_in2out.c
+++ b/src/plugins/nat/nat_det_in2out.c
@@ -392,8 +392,7 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm,
}
}
- old_port0 = udp0->src_port;
- udp0->src_port = new_port0 = ses0->out.out_port;
+ new_port0 = ses0->out.out_port;
old_addr0.as_u32 = ip0->src_address.as_u32;
ip0->src_address.as_u32 = new_addr0.as_u32;
@@ -425,6 +424,9 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm,
&& ses0->state == SNAT_SESSION_UNKNOWN)
ses0->state = SNAT_SESSION_TCP_ESTABLISHED;
+ old_port0 = tcp0->src;
+ tcp0->src = new_port0;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
ip4_header_t,
@@ -438,20 +440,9 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm,
else
{
ses0->state = SNAT_SESSION_UDP_ACTIVE;
-
- if (PREDICT_FALSE (udp0->checksum))
- {
- 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);
- }
+ old_port0 = udp0->src_port;
+ udp0->src_port = new_port0;
+ udp0->checksum = 0;
}
switch (ses0->state)
@@ -565,8 +556,7 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm,
}
}
- old_port1 = udp1->src_port;
- udp1->src_port = new_port1 = ses1->out.out_port;
+ new_port1 = ses1->out.out_port;
old_addr1.as_u32 = ip1->src_address.as_u32;
ip1->src_address.as_u32 = new_addr1.as_u32;
@@ -598,6 +588,9 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm,
&& ses1->state == SNAT_SESSION_UNKNOWN)
ses1->state = SNAT_SESSION_TCP_ESTABLISHED;
+ old_port1 = tcp1->src;
+ tcp1->src = new_port1;
+
sum1 = tcp1->checksum;
sum1 = ip_csum_update (sum1, old_addr1.as_u32, new_addr1.as_u32,
ip4_header_t,
@@ -611,20 +604,9 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm,
else
{
ses1->state = SNAT_SESSION_UDP_ACTIVE;
-
- if (PREDICT_FALSE (udp1->checksum))
- {
- 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);
- }
+ old_port1 = udp1->src_port;
+ udp1->src_port = new_port1;
+ udp1->checksum = 0;
}
switch (ses1->state)
@@ -774,8 +756,7 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm,
}
}
- old_port0 = udp0->src_port;
- udp0->src_port = new_port0 = ses0->out.out_port;
+ new_port0 = ses0->out.out_port;
old_addr0.as_u32 = ip0->src_address.as_u32;
ip0->src_address.as_u32 = new_addr0.as_u32;
@@ -807,6 +788,9 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm,
&& ses0->state == SNAT_SESSION_UNKNOWN)
ses0->state = SNAT_SESSION_TCP_ESTABLISHED;
+ old_port0 = tcp0->src;
+ tcp0->src = new_port0;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0.as_u32, new_addr0.as_u32,
ip4_header_t,
@@ -820,20 +804,9 @@ VLIB_NODE_FN (snat_det_in2out_node) (vlib_main_t * vm,
else
{
ses0->state = SNAT_SESSION_UDP_ACTIVE;
-
- if (PREDICT_FALSE (udp0->checksum))
- {
- 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);
- }
+ old_port0 = udp0->src_port;
+ udp0->src_port = new_port0;
+ udp0->checksum = 0;
}
switch (ses0->state)
diff --git a/src/plugins/nat/nat_det_out2in.c b/src/plugins/nat/nat_det_out2in.c
index c4bd096deb1..45fba18b248 100644
--- a/src/plugins/nat/nat_det_out2in.c
+++ b/src/plugins/nat/nat_det_out2in.c
@@ -343,8 +343,7 @@ VLIB_NODE_FN (snat_det_out2in_node) (vlib_main_t * vm,
b0->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
goto trace0;
}
- old_port0 = udp0->dst_port;
- udp0->dst_port = new_port0 = ses0->in_port;
+ new_port0 = ses0->in_port;
old_addr0 = ip0->dst_address;
ip0->dst_address = new_addr0;
@@ -365,25 +364,24 @@ VLIB_NODE_FN (snat_det_out2in_node) (vlib_main_t * vm,
&& 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 if (udp0->checksum)
+ else
{
- 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);
+ old_port0 = udp0->dst_port;
+ udp0->dst_port = new_port0;
+ udp0->checksum = 0;
}
trace0:
@@ -464,8 +462,7 @@ VLIB_NODE_FN (snat_det_out2in_node) (vlib_main_t * vm,
b1->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
goto trace1;
}
- old_port1 = udp1->dst_port;
- udp1->dst_port = new_port1 = ses1->in_port;
+ new_port1 = ses1->in_port;
old_addr1 = ip1->dst_address;
ip1->dst_address = new_addr1;
@@ -486,25 +483,24 @@ VLIB_NODE_FN (snat_det_out2in_node) (vlib_main_t * vm,
&& 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 if (udp1->checksum)
+ else
{
- 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);
+ old_port1 = udp1->dst_port;
+ udp1->dst_port = new_port1;
+ udp1->checksum = 0;
}
trace1:
@@ -618,8 +614,7 @@ VLIB_NODE_FN (snat_det_out2in_node) (vlib_main_t * vm,
b0->error = node->errors[NAT_DET_OUT2IN_ERROR_NO_TRANSLATION];
goto trace00;
}
- old_port0 = udp0->dst_port;
- udp0->dst_port = new_port0 = ses0->in_port;
+ new_port0 = ses0->in_port;
old_addr0 = ip0->dst_address;
ip0->dst_address = new_addr0;
@@ -640,25 +635,24 @@ VLIB_NODE_FN (snat_det_out2in_node) (vlib_main_t * vm,
&& 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 if (udp0->checksum)
+ else
{
- 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);
+ old_port0 = udp0->dst_port;
+ udp0->dst_port = new_port0;
+ udp0->checksum = 0;
}
trace00:
diff --git a/src/plugins/nat/out2in.c b/src/plugins/nat/out2in.c
index 83c099d1bd2..8c6cb482703 100755
--- a/src/plugins/nat/out2in.c
+++ b/src/plugins/nat/out2in.c
@@ -893,9 +893,6 @@ VLIB_NODE_FN (snat_out2in_node) (vlib_main_t * vm,
dst_address /* changed member */ );
ip0->checksum = ip_csum_fold (sum0);
- old_port0 = udp0->dst_port;
- new_port0 = udp0->dst_port = s0->in2out.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
old_port0 = tcp0->dst_port;
@@ -915,17 +912,9 @@ VLIB_NODE_FN (snat_out2in_node) (vlib_main_t * vm,
}
else
{
- if (PREDICT_FALSE (udp0->checksum))
- {
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
- 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);
- }
+ old_port0 = udp0->dst_port;
+ udp0->dst_port = s0->in2out.port;
+ udp0->checksum = 0;
udp_packets++;
}
@@ -1070,11 +1059,12 @@ VLIB_NODE_FN (snat_out2in_node) (vlib_main_t * vm,
dst_address /* changed member */ );
ip1->checksum = ip_csum_fold (sum1);
- old_port1 = udp1->dst_port;
- new_port1 = udp1->dst_port = s1->in2out.port;
-
if (PREDICT_TRUE (proto1 == SNAT_PROTOCOL_TCP))
{
+ old_port1 = tcp1->dst_port;
+ tcp1->dst_port = s1->in2out.port;
+ new_port1 = tcp1->dst_port;
+
sum1 = tcp1->checksum;
sum1 = ip_csum_update (sum1, old_addr1, new_addr1,
ip4_header_t,
@@ -1088,17 +1078,9 @@ VLIB_NODE_FN (snat_out2in_node) (vlib_main_t * vm,
}
else
{
- if (PREDICT_FALSE (udp1->checksum))
- {
- sum1 = udp1->checksum;
- sum1 = ip_csum_update (sum1, old_addr1, new_addr1,
- 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);
- }
+ old_port1 = udp1->dst_port;
+ udp1->dst_port = s1->in2out.port;
+ udp1->checksum = 0;
udp_packets++;
}
@@ -1280,11 +1262,12 @@ VLIB_NODE_FN (snat_out2in_node) (vlib_main_t * vm,
dst_address /* changed member */ );
ip0->checksum = ip_csum_fold (sum0);
- old_port0 = udp0->dst_port;
- new_port0 = udp0->dst_port = s0->in2out.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->dst_port;
+ tcp0->dst_port = s0->in2out.port;
+ new_port0 = tcp0->dst_port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
ip4_header_t,
@@ -1298,17 +1281,9 @@ VLIB_NODE_FN (snat_out2in_node) (vlib_main_t * vm,
}
else
{
- if (PREDICT_FALSE (udp0->checksum))
- {
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
- 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);
- }
+ old_port0 = udp0->dst_port;
+ udp0->dst_port = s0->in2out.port;
+ udp0->checksum = 0;
udp_packets++;
}
@@ -1598,11 +1573,12 @@ VLIB_NODE_FN (nat44_out2in_reass_node) (vlib_main_t * vm,
if (PREDICT_FALSE (ip4_is_first_fragment (ip0)))
{
- old_port0 = udp0->dst_port;
- new_port0 = udp0->dst_port = s0->in2out.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->dst_port;
+ tcp0->dst_port = s0->in2out.port;
+ new_port0 = tcp0->dst_port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
ip4_header_t,
@@ -1613,16 +1589,11 @@ VLIB_NODE_FN (nat44_out2in_reass_node) (vlib_main_t * vm,
length /* changed member */ );
tcp0->checksum = ip_csum_fold (sum0);
}
- else if (udp0->checksum)
+ else
{
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
- 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);
+ old_port0 = udp0->dst_port;
+ udp0->dst_port = s0->in2out.port;
+ udp0->checksum = 0;
}
}
@@ -1826,30 +1797,26 @@ VLIB_NODE_FN (snat_out2in_fast_node) (vlib_main_t * vm,
if (PREDICT_FALSE (new_port0 != udp0->dst_port))
{
- old_port0 = udp0->dst_port;
- udp0->dst_port = new_port0;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->dst_port;
+ tcp0->dst_port = new_port0;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
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 if (udp0->checksum)
+ else
{
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
- 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);
+ old_port0 = udp0->dst_port;
+ udp0->dst_port = new_port0;
+ udp0->checksum = 0;
}
}
else
@@ -1860,16 +1827,9 @@ VLIB_NODE_FN (snat_out2in_fast_node) (vlib_main_t * vm,
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
ip4_header_t,
dst_address /* changed member */ );
+
tcp0->checksum = ip_csum_fold (sum0);
}
- else if (udp0->checksum)
- {
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
- ip4_header_t,
- dst_address /* changed member */ );
- udp0->checksum = ip_csum_fold (sum0);
- }
}
trace00:
diff --git a/src/plugins/nat/out2in_ed.c b/src/plugins/nat/out2in_ed.c
index 2067c512b92..50abebd9cfb 100644
--- a/src/plugins/nat/out2in_ed.c
+++ b/src/plugins/nat/out2in_ed.c
@@ -919,11 +919,11 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
src_address);
ip0->checksum = ip_csum_fold (sum0);
- old_port0 = udp0->dst_port;
- new_port0 = udp0->dst_port = s0->in2out.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->dst_port;
+ new_port0 = tcp0->dst_port = s0->in2out.port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
dst_address);
@@ -946,34 +946,15 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
(sm, s0, tcp0, thread_index))
goto trace00;
}
- else if (udp0->checksum)
- {
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
- dst_address);
- sum0 = ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
- length);
- if (PREDICT_FALSE (is_twice_nat_session (s0)))
- {
- sum0 = ip_csum_update (sum0, ip0->src_address.as_u32,
- s0->ext_host_nat_addr.as_u32,
- ip4_header_t, dst_address);
- sum0 = ip_csum_update (sum0, udp0->src_port,
- s0->ext_host_nat_port, ip4_header_t,
- length);
- udp0->src_port = s0->ext_host_nat_port;
- ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
- }
- udp0->checksum = ip_csum_fold (sum0);
- udp_packets++;
- }
else
{
- if (PREDICT_FALSE (is_twice_nat_session (s0)))
+ udp0->dst_port = s0->in2out.port;
+ if (is_twice_nat_session (s0))
{
udp0->src_port = s0->ext_host_nat_port;
ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
}
+ udp0->checksum = 0;
udp_packets++;
}
@@ -1176,11 +1157,11 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
src_address);
ip1->checksum = ip_csum_fold (sum1);
- old_port1 = udp1->dst_port;
- new_port1 = udp1->dst_port = s1->in2out.port;
-
if (PREDICT_TRUE (proto1 == SNAT_PROTOCOL_TCP))
{
+ old_port1 = tcp1->dst_port;
+ new_port1 = tcp1->dst_port = s1->in2out.port;
+
sum1 = tcp1->checksum;
sum1 = ip_csum_update (sum1, old_addr1, new_addr1, ip4_header_t,
dst_address);
@@ -1203,34 +1184,15 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
(sm, s1, tcp1, thread_index))
goto trace01;
}
- else if (udp1->checksum)
- {
- sum1 = udp1->checksum;
- sum1 = ip_csum_update (sum1, old_addr1, new_addr1, ip4_header_t,
- dst_address);
- sum1 = ip_csum_update (sum1, old_port1, new_port1, ip4_header_t,
- length);
- if (PREDICT_FALSE (is_twice_nat_session (s1)))
- {
- sum1 = ip_csum_update (sum1, ip1->src_address.as_u32,
- s1->ext_host_nat_addr.as_u32,
- ip4_header_t, dst_address);
- sum1 = ip_csum_update (sum1, udp1->src_port,
- s1->ext_host_nat_port, ip4_header_t,
- length);
- udp1->src_port = s1->ext_host_nat_port;
- ip1->src_address.as_u32 = s1->ext_host_nat_addr.as_u32;
- }
- udp1->checksum = ip_csum_fold (sum1);
- udp_packets++;
- }
else
{
- if (PREDICT_FALSE (is_twice_nat_session (s1)))
+ udp1->dst_port = s1->in2out.port;
+ if (is_twice_nat_session (s1))
{
udp1->src_port = s1->ext_host_nat_port;
ip1->src_address.as_u32 = s1->ext_host_nat_addr.as_u32;
}
+ udp1->checksum = 0;
udp_packets++;
}
@@ -1467,11 +1429,11 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
src_address);
ip0->checksum = ip_csum_fold (sum0);
- old_port0 = udp0->dst_port;
- new_port0 = udp0->dst_port = s0->in2out.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->dst_port;
+ new_port0 = tcp0->dst_port = s0->in2out.port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
dst_address);
@@ -1494,34 +1456,15 @@ nat44_ed_out2in_node_fn_inline (vlib_main_t * vm,
(sm, s0, tcp0, thread_index))
goto trace0;
}
- else if (udp0->checksum)
- {
- sum0 = udp0->checksum;
- sum0 = ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
- dst_address);
- sum0 = ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
- length);
- if (PREDICT_FALSE (is_twice_nat_session (s0)))
- {
- sum0 = ip_csum_update (sum0, ip0->src_address.as_u32,
- s0->ext_host_nat_addr.as_u32,
- ip4_header_t, dst_address);
- sum0 = ip_csum_update (sum0, udp0->src_port,
- s0->ext_host_nat_port, ip4_header_t,
- length);
- udp0->src_port = s0->ext_host_nat_port;
- ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
- }
- udp0->checksum = ip_csum_fold (sum0);
- udp_packets++;
- }
else
{
- if (PREDICT_FALSE (is_twice_nat_session (s0)))
+ udp0->dst_port = s0->in2out.port;
+ if (is_twice_nat_session (s0))
{
udp0->src_port = s0->ext_host_nat_port;
ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
}
+ udp0->checksum = 0;
udp_packets++;
}
@@ -1875,11 +1818,12 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
if (PREDICT_FALSE (ip4_is_first_fragment (ip0)))
{
- old_port0 = udp0->dst_port;
- new_port0 = udp0->dst_port = s0->in2out.port;
-
if (PREDICT_TRUE (proto0 == SNAT_PROTOCOL_TCP))
{
+ old_port0 = tcp0->dst_port;
+ tcp0->dst_port = s0->in2out.port;
+ new_port0 = tcp0->dst_port;
+
sum0 = tcp0->checksum;
sum0 = ip_csum_update (sum0, old_addr0, new_addr0,
ip4_header_t,
@@ -1901,35 +1845,16 @@ VLIB_NODE_FN (nat44_ed_out2in_reass_node) (vlib_main_t * vm,
}
tcp0->checksum = ip_csum_fold (sum0);
}
- else if (udp0->checksum)
- {
- sum0 = udp0->checksum;
- sum0 =
- ip_csum_update (sum0, old_addr0, new_addr0, ip4_header_t,
- dst_address);
- sum0 =
- ip_csum_update (sum0, old_port0, new_port0, ip4_header_t,
- length);
- if (PREDICT_FALSE (is_twice_nat_session (s0)))
- {
- sum0 = ip_csum_update (sum0, ip0->src_address.as_u32,
- s0->ext_host_nat_addr.as_u32,
- ip4_header_t, dst_address);
- sum0 = ip_csum_update (sum0, udp0->src_port,
- s0->ext_host_nat_port,
- ip4_header_t, length);
- udp0->src_port = s0->ext_host_nat_port;
- ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
- }
- udp0->checksum = ip_csum_fold (sum0);
- }
else
{
- if (PREDICT_FALSE (is_twice_nat_session (s0)))
+ old_port0 = udp0->dst_port;
+ udp0->dst_port = s0->in2out.port;
+ if (is_twice_nat_session (s0))
{
udp0->src_port = s0->ext_host_nat_port;
ip0->src_address.as_u32 = s0->ext_host_nat_addr.as_u32;
}
+ udp0->checksum = 0;
}
}