Skip to content

Commit

Permalink
removed bug when client closes connection before server side connecti…
Browse files Browse the repository at this point in the history
…on is established
  • Loading branch information
rstade committed Apr 12, 2019
1 parent 2be2419 commit 2ba2482
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
16 changes: 13 additions & 3 deletions src/nftcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ pub fn setup_delayed_proxy<F1, F2>(
}
}
*/
// attention: after calling select_server, p points to a different mbuf and has different headers
/// attention: after calling select_server, p points to a different mbuf and has different headers
/// selects the server by calling the closure, sends SYN to server
fn select_server<F>(
p: &mut Pdu,
Expand Down Expand Up @@ -688,7 +688,7 @@ pub fn setup_delayed_proxy<F1, F2>(
}
}
_ => {
// we use a clone for reading tcp header to avoid immutable borrow
// we use a clone for reading tcp header to avoid immutable borrow. But attention, this clone does not update, when we change the original header!
let tcp = pdu.headers().tcp(2).clone();
let src_sock = (pdu.headers().ip(1).src(), tcp.src_port());

Expand Down Expand Up @@ -779,7 +779,8 @@ pub fn setup_delayed_proxy<F1, F2>(
c.s_set_release_cause(ReleaseCause::PassiveClose);
counter_c[TcpStatistics::SentFinPssv] += 1;
counter_c[TcpStatistics::SentAck4Fin] += 1;
c.seqn.ack_for_fin_p2c = tcp.seq_num().wrapping_add(1);
// do not use the clone "tcp" here:
c.seqn.ack_for_fin_p2c = c.c_seqn.wrapping_add(1);
//TODO send restart to server?
trace!("FIN-ACK to client, L3: { }, L4: { }", pdu.headers().ip(1), tcp);
} else {
Expand All @@ -795,6 +796,12 @@ pub fn setup_delayed_proxy<F1, F2>(
release_connection = Some(c.port());
} else if tcp.ack_flag() && tcp.ack_num() == unsafe { c.seqn.ack_for_fin_p2c } && old_s_state >= TcpState::FinWait1 {
// ACK from client for FIN of Server
trace!(
"{} ACK from client, src_port= {}, old_s_state = {:?}",
thread_id,
tcp.src_port(),
old_s_state,
);
match old_s_state {
TcpState::FinWait1 => { c.s_push_state(TcpState::FinWait2); }
TcpState::Closing => { c.s_push_state(TcpState::Closed); }
Expand Down Expand Up @@ -846,6 +853,9 @@ pub fn setup_delayed_proxy<F1, F2>(
counter_c[TcpStatistics::Unexpected] += 1;
group_index = 2;
}
else {
trace!{"c2s: nothing to do?, tcp= {}, tcp_payload_size={}, expected ackn_for_fin ={}", tcp, tcp_payload_size(pdu), unsafe { c.seqn.ack_for_fin_p2c} };
}

if c.client_state() == TcpState::Closed && c.server_state() == TcpState::Closed {
release_connection = Some(c.port());
Expand Down
6 changes: 3 additions & 3 deletions tests/client_syn_fin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name = "client_syn_fin"
master_core = 0
pool_size = 2048 # default 2048
cache_size = 32 # default 32
cores = [ 1, 2 ]
cores = [ 1]
ports = [
{ name="7:00.0", rxd= 512, txd= 512, cores = [1, 2], checksum = true, fdir = { pballoc="RteFdirPballoc256k", mode="RteFdirModePerfect", ipv4_mask= {src_ip="0.0.0.0", dst_ip="FFFFFFFF"}, src_port_mask="0", dst_port_mask="FC00"}},
{ name="7:00.0", rxd= 512, txd= 512, cores = [1], checksum = true, fdir = { pballoc="RteFdirPballoc256k", mode="RteFdirModePerfect", ipv4_mask= {src_ip="0.0.0.0", dst_ip="FFFFFFFF"}, src_port_mask="0", dst_port_mask="FC00"}},
{ name="kni:1", rxd=64, txd=64, cores = [1], k_cores = [1] }
]
vdev = [ "net_kni0" ] # for use of vdev with KNI PMD, see https://dpdk.org/doc/guides/nics/kni.html
Expand All @@ -18,4 +18,4 @@ engine = { flow_steering="Ip", namespace="nskni", mac="a0:36:9f:82:9c:fc",
targets = [ { id = "server 1", ip = "192.168.222.244", linux_if="enp7s0f1" , port = 12345 },
{ id = "server 2", ip = "192.168.222.244", linux_if="enp7s0f1" , port = 12346 },
]
test_size = 4
test_size = 1
2 changes: 1 addition & 1 deletion tests/test_rfs_port.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ targets = [ { id = "server 1", ip = "192.168.222.32", linux_if="enp7s0f1" ,
{ id = "server 6", ip = "192.168.222.32", linux_if="enp7s0f1" , port= 12350 },
{ id = "server 7", ip = "192.168.222.32", linux_if="enp7s0f1" , port= 12351 },
]
test_size = 1
test_size = 128

0 comments on commit 2ba2482

Please sign in to comment.