summaryrefslogtreecommitdiffstats
path: root/src/plugins/nat/in2out.c
diff options
context:
space:
mode:
authorFilip Varga <fivarga@cisco.com>2019-10-21 18:18:00 +0200
committerOle Troan <ot@cisco.com>2019-11-07 22:17:13 +0100
commita6a98b5460f066e0955b89e6782e55ed3e4f0ede (patch)
treeb377525240434f64ee3c9c1802b0806a99395632 /src/plugins/nat/in2out.c
parent3bacbc975f1638ebdf66de2603eb0fd2fb1e61b7 (diff)
nat: reapply respect udp checksum
Type: fix Signed-off-by: Filip Varga <fivarga@cisco.com> (cherry picked from commit 16572355c9069e2e8e4836dc6bd6a65feed2d390) Signed-off-by: Ole Troan <ot@cisco.com> Change-Id: I119ee45f7007e0a689d46c9f75eb6314f15990e2
Diffstat (limited to 'src/plugins/nat/in2out.c')
-rwxr-xr-xsrc/plugins/nat/in2out.c110
1 files changed, 74 insertions, 36 deletions
diff --git a/src/plugins/nat/in2out.c b/src/plugins/nat/in2out.c
index c69bc61236b..802202d7939 100755
--- a/src/plugins/nat/in2out.c
+++ b/src/plugins/nat/in2out.c
@@ -1075,12 +1075,11 @@ 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,
@@ -1094,9 +1093,17 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
}
else
{
- old_port0 = udp0->src_port;
- udp0->src_port = s0->out2in.port;
- udp0->checksum = 0;
+ 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);
+ }
udp_packets++;
}
@@ -1264,12 +1271,11 @@ 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,
@@ -1283,9 +1289,17 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
}
else
{
- old_port1 = udp1->src_port;
- udp1->src_port = s1->out2in.port;
- udp1->checksum = 0;
+ 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);
+ }
udp_packets++;
}
@@ -1488,12 +1502,11 @@ 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,
@@ -1507,9 +1520,17 @@ snat_in2out_node_fn_inline (vlib_main_t * vm,
}
else
{
- old_port0 = udp0->src_port;
- udp0->src_port = s0->out2in.port;
- udp0->checksum = 0;
+ 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);
+ }
udp_packets++;
}
@@ -1869,12 +1890,11 @@ 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,
@@ -1884,11 +1904,16 @@ VLIB_NODE_FN (nat44_in2out_reass_node) (vlib_main_t * vm,
length /* changed member */ );
tcp0->checksum = ip_csum_fold (sum0);
}
- else
+ else if (PREDICT_FALSE (udp0->checksum))
{
- old_port0 = udp0->src_port;
- udp0->src_port = s0->out2in.port;
- udp0->checksum = 0;
+ 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);
}
}
@@ -2099,11 +2124,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,
@@ -2114,11 +2139,16 @@ VLIB_NODE_FN (snat_in2out_fast_node) (vlib_main_t * vm,
mss_clamping (sm, tcp0, &sum0);
tcp0->checksum = ip_csum_fold (sum0);
}
- else
+ else if (udp0->checksum)
{
- old_port0 = udp0->src_port;
- udp0->src_port = new_port0;
- udp0->checksum = 0;
+ 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);
}
}
else
@@ -2132,6 +2162,14 @@ 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 */