From e380531bfba0d7c4ad3b4dd50d590cddaaac0c76 Mon Sep 17 00:00:00 2001 From: Lucas Manning Date: Tue, 19 Apr 2022 11:18:32 -0700 Subject: [PATCH] Clean up tcp segment sender functions. sendRaw is entirely used to just send flags, so change the function to explicitly send empty segments. The single use case for sending data can be taken care of in sendSegment. PiperOrigin-RevId: 442861994 --- pkg/tcpip/transport/tcp/connect.go | 17 +++++++++++------ pkg/tcpip/transport/tcp/snd.go | 13 +++++++++---- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/pkg/tcpip/transport/tcp/connect.go b/pkg/tcpip/transport/tcp/connect.go index e143b1ee7..1908f11c6 100644 --- a/pkg/tcpip/transport/tcp/connect.go +++ b/pkg/tcpip/transport/tcp/connect.go @@ -290,7 +290,7 @@ func (h *handshake) checkAck(s *segment) bool { // If the segment acknowledgment is not acceptable, form a reset segment, // // and send it. - h.ep.sendRaw(buffer.VectorisedView{}, header.TCPFlagRst, s.ackNumber, 0, 0) + h.ep.sendEmptyRaw(header.TCPFlagRst, s.ackNumber, 0, 0) return false } @@ -346,7 +346,7 @@ func (h *handshake) synSentState(s *segment) tcpip.Error { h.state = handshakeCompleted h.transitionToStateEstablishedLocked(s) - h.ep.sendRaw(buffer.VectorisedView{}, header.TCPFlagAck, h.iss+1, h.ackNum, h.rcvWnd>>h.effectiveRcvWndScale()) + h.ep.sendEmptyRaw(header.TCPFlagAck, h.iss+1, h.ackNum, h.rcvWnd>>h.effectiveRcvWndScale()) return nil } @@ -407,7 +407,7 @@ func (h *handshake) synRcvdState(s *segment) tcpip.Error { // segment and return." if !s.sequenceNumber.InWindow(h.ackNum, h.rcvWnd) { if h.ep.allowOutOfWindowAck() { - h.ep.sendRaw(buffer.VectorisedView{}, header.TCPFlagAck, h.iss+1, h.ackNum, h.rcvWnd) + h.ep.sendEmptyRaw(header.TCPFlagAck, h.iss+1, h.ackNum, h.rcvWnd) } return nil } @@ -421,7 +421,7 @@ func (h *handshake) synRcvdState(s *segment) tcpip.Error { if s.flags.Contains(header.TCPFlagAck) { seq = s.ackNumber } - h.ep.sendRaw(buffer.VectorisedView{}, header.TCPFlagRst|header.TCPFlagAck, seq, ack, 0) + h.ep.sendEmptyRaw(header.TCPFlagRst|header.TCPFlagAck, seq, ack, 0) if !h.active { return &tcpip.ErrInvalidEndpointState{} @@ -957,6 +957,11 @@ func (e *endpoint) makeOptions(sackBlocks []header.SACKBlock) []byte { return options[:offset] } +// sendEmptyRaw sends a TCP segment to the endpoint's peer. +func (e *endpoint) sendEmptyRaw(flags header.TCPFlags, seq, ack seqnum.Value, rcvWnd seqnum.Size) tcpip.Error { + return e.sendRaw(buffer.VectorisedView{}, flags, seq, ack, rcvWnd) +} + // sendRaw sends a TCP segment to the endpoint's peer. func (e *endpoint) sendRaw(data buffer.VectorisedView, flags header.TCPFlags, seq, ack seqnum.Value, rcvWnd seqnum.Size) tcpip.Error { var sackBlocks []header.SACKBlock @@ -1017,7 +1022,7 @@ func (e *endpoint) resetConnectionLocked(err tcpip.Error) { if !sndWndEnd.LessThan(e.snd.SndNxt) || e.snd.SndNxt.Size(sndWndEnd) < (1<