mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
netstack: make TCP's endpoint type public
This is in preparation for a child CL. PiperOrigin-RevId: 616963627
This commit is contained in:
committed by
gVisor bot
parent
5f5e01d186
commit
365f85680d
@@ -36,8 +36,8 @@ go_template_instance(
|
||||
prefix = "endpoint",
|
||||
template = "//pkg/ilist:generic_list",
|
||||
types = {
|
||||
"Element": "*endpoint",
|
||||
"Linker": "*endpoint",
|
||||
"Element": "*Endpoint",
|
||||
"Linker": "*Endpoint",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ type listenContext struct {
|
||||
|
||||
// listenEP is a reference to the listening endpoint associated with
|
||||
// this context. Can be nil if the context is created by the forwarder.
|
||||
listenEP *endpoint
|
||||
listenEP *Endpoint
|
||||
|
||||
// hasherMu protects hasher.
|
||||
hasherMu sync.Mutex
|
||||
@@ -107,7 +107,7 @@ func timeStamp(clock tcpip.Clock) uint32 {
|
||||
}
|
||||
|
||||
// newListenContext creates a new listen context.
|
||||
func newListenContext(stk *stack.Stack, protocol *protocol, listenEP *endpoint, rcvWnd seqnum.Size, v6Only bool, netProto tcpip.NetworkProtocolNumber) *listenContext {
|
||||
func newListenContext(stk *stack.Stack, protocol *protocol, listenEP *Endpoint, rcvWnd seqnum.Size, v6Only bool, netProto tcpip.NetworkProtocolNumber) *listenContext {
|
||||
l := &listenContext{
|
||||
stack: stk,
|
||||
protocol: protocol,
|
||||
@@ -183,7 +183,7 @@ func (l *listenContext) isCookieValid(id stack.TransportEndpointID, cookie seqnu
|
||||
// the connection parameters given by the arguments. The newly created endpoint
|
||||
// will be locked.
|
||||
// +checklocksacquire:n.mu
|
||||
func (l *listenContext) createConnectingEndpoint(s *segment, rcvdSynOpts header.TCPSynOptions, queue *waiter.Queue) (n *endpoint, _ tcpip.Error) {
|
||||
func (l *listenContext) createConnectingEndpoint(s *segment, rcvdSynOpts header.TCPSynOptions, queue *waiter.Queue) (n *Endpoint, _ tcpip.Error) {
|
||||
// Create a new endpoint.
|
||||
netProto := l.netProto
|
||||
if netProto == 0 {
|
||||
@@ -302,7 +302,7 @@ func (l *listenContext) startHandshake(s *segment, opts header.TCPSynOptions, qu
|
||||
// established endpoint is returned.
|
||||
//
|
||||
// Precondition: if l.listenEP != nil, l.listenEP.mu must be locked.
|
||||
func (l *listenContext) performHandshake(s *segment, opts header.TCPSynOptions, queue *waiter.Queue, owner tcpip.PacketOwner) (*endpoint, tcpip.Error) {
|
||||
func (l *listenContext) performHandshake(s *segment, opts header.TCPSynOptions, queue *waiter.Queue, owner tcpip.PacketOwner) (*Endpoint, tcpip.Error) {
|
||||
waitEntry, notifyCh := waiter.NewChannelEntry(waiter.WritableEvents)
|
||||
queue.EventRegister(&waitEntry)
|
||||
defer queue.EventUnregister(&waitEntry)
|
||||
@@ -357,7 +357,7 @@ func (l *listenContext) performHandshake(s *segment, opts header.TCPSynOptions,
|
||||
//
|
||||
// +checklocks:e.mu
|
||||
// +checklocks:n.mu
|
||||
func (e *endpoint) propagateInheritableOptionsLocked(n *endpoint) {
|
||||
func (e *Endpoint) propagateInheritableOptionsLocked(n *Endpoint) {
|
||||
n.userTimeout = e.userTimeout
|
||||
n.portFlags = e.portFlags
|
||||
n.boundBindToDevice = e.boundBindToDevice
|
||||
@@ -370,7 +370,7 @@ func (e *endpoint) propagateInheritableOptionsLocked(n *endpoint) {
|
||||
// Precondition: e.propagateInheritableOptionsLocked has been called.
|
||||
//
|
||||
// +checklocks:e.mu
|
||||
func (e *endpoint) reserveTupleLocked() bool {
|
||||
func (e *Endpoint) reserveTupleLocked() bool {
|
||||
dest := tcpip.FullAddress{
|
||||
Addr: e.TransportEndpointInfo.ID.RemoteAddress,
|
||||
Port: e.TransportEndpointInfo.ID.RemotePort,
|
||||
@@ -400,11 +400,11 @@ func (e *endpoint) reserveTupleLocked() bool {
|
||||
// This is strictly not required normally as a socket that was never accepted
|
||||
// can't really have any registered waiters except when stack.Wait() is called
|
||||
// which waits for all registered endpoints to stop and expects an EventHUp.
|
||||
func (e *endpoint) notifyAborted() {
|
||||
func (e *Endpoint) notifyAborted() {
|
||||
e.waiterQueue.Notify(waiter.EventHUp | waiter.EventErr | waiter.ReadableEvents | waiter.WritableEvents)
|
||||
}
|
||||
|
||||
func (e *endpoint) acceptQueueIsFull() bool {
|
||||
func (e *Endpoint) acceptQueueIsFull() bool {
|
||||
e.acceptMu.Lock()
|
||||
full := e.acceptQueue.isFull()
|
||||
e.acceptMu.Unlock()
|
||||
@@ -416,11 +416,11 @@ type acceptQueue struct {
|
||||
// NB: this could be an endpointList, but ilist only permits endpoints to
|
||||
// belong to one list at a time, and endpoints are already stored in the
|
||||
// dispatcher's list.
|
||||
endpoints list.List `state:".([]*endpoint)"`
|
||||
endpoints list.List `state:".([]*Endpoint)"`
|
||||
|
||||
// pendingEndpoints is a set of all endpoints for which a handshake is
|
||||
// in progress.
|
||||
pendingEndpoints map[*endpoint]struct{}
|
||||
pendingEndpoints map[*Endpoint]struct{}
|
||||
|
||||
// capacity is the maximum number of endpoints that can be in endpoints.
|
||||
capacity int
|
||||
@@ -434,7 +434,7 @@ func (a *acceptQueue) isFull() bool {
|
||||
// and needs to handle it.
|
||||
//
|
||||
// +checklocks:e.mu
|
||||
func (e *endpoint) handleListenSegment(ctx *listenContext, s *segment) tcpip.Error {
|
||||
func (e *Endpoint) handleListenSegment(ctx *listenContext, s *segment) tcpip.Error {
|
||||
e.rcvQueueMu.Lock()
|
||||
rcvClosed := e.RcvClosed
|
||||
e.rcvQueueMu.Unlock()
|
||||
@@ -561,7 +561,7 @@ func (e *endpoint) handleListenSegment(ctx *listenContext, s *segment) tcpip.Err
|
||||
}
|
||||
for _, netProto := range netProtos {
|
||||
if newEP := e.stack.FindTransportEndpoint(netProto, ProtocolNumber, s.id, s.pkt.NICID); newEP != nil && newEP != e {
|
||||
tcpEP := newEP.(*endpoint)
|
||||
tcpEP := newEP.(*Endpoint)
|
||||
if !tcpEP.EndpointState().connected() {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ const (
|
||||
//
|
||||
// +stateify savable
|
||||
type handshake struct {
|
||||
ep *endpoint
|
||||
listenEP *endpoint
|
||||
ep *Endpoint
|
||||
listenEP *Endpoint
|
||||
state handshakeState
|
||||
active bool
|
||||
flags header.TCPFlags
|
||||
@@ -122,7 +122,7 @@ type handshake struct {
|
||||
// processor if there are pending segments that need to be processed.
|
||||
//
|
||||
// NOTE: e.mu is held for the duration of the call to f().
|
||||
func timerHandler(e *endpoint, f func() tcpip.Error) func() {
|
||||
func timerHandler(e *Endpoint, f func() tcpip.Error) func() {
|
||||
return func() {
|
||||
e.mu.Lock()
|
||||
if err := f(); err != nil {
|
||||
@@ -155,7 +155,7 @@ func timerHandler(e *endpoint, f func() tcpip.Error) func() {
|
||||
|
||||
// +checklocks:e.mu
|
||||
// +checklocksacquire:h.ep.mu
|
||||
func (e *endpoint) newHandshake() (h *handshake) {
|
||||
func (e *Endpoint) newHandshake() (h *handshake) {
|
||||
h = &handshake{
|
||||
ep: e,
|
||||
active: true,
|
||||
@@ -178,7 +178,7 @@ func (e *endpoint) newHandshake() (h *handshake) {
|
||||
|
||||
// +checklocks:e.mu
|
||||
// +checklocksacquire:h.ep.mu
|
||||
func (e *endpoint) newPassiveHandshake(isn, irs seqnum.Value, opts header.TCPSynOptions, deferAccept time.Duration) (h *handshake) {
|
||||
func (e *Endpoint) newPassiveHandshake(isn, irs seqnum.Value, opts header.TCPSynOptions, deferAccept time.Duration) (h *handshake) {
|
||||
h = e.newHandshake()
|
||||
h.resetToSynRcvd(isn, irs, opts, deferAccept)
|
||||
return h
|
||||
@@ -796,7 +796,7 @@ type tcpFields struct {
|
||||
txHash uint32
|
||||
}
|
||||
|
||||
func (e *endpoint) sendSynTCP(r *stack.Route, tf tcpFields, opts header.TCPSynOptions) tcpip.Error {
|
||||
func (e *Endpoint) sendSynTCP(r *stack.Route, tf tcpFields, opts header.TCPSynOptions) tcpip.Error {
|
||||
tf.opts = makeSynOptions(opts)
|
||||
// We ignore SYN send errors and let the callers re-attempt send.
|
||||
p := stack.NewPacketBuffer(stack.PacketBufferOptions{ReserveHeaderBytes: header.TCPMinimumSize + int(r.MaxHeaderLength()) + len(tf.opts)})
|
||||
@@ -809,7 +809,7 @@ func (e *endpoint) sendSynTCP(r *stack.Route, tf tcpFields, opts header.TCPSynOp
|
||||
}
|
||||
|
||||
// This method takes ownership of pkt.
|
||||
func (e *endpoint) sendTCP(r *stack.Route, tf tcpFields, pkt *stack.PacketBuffer, gso stack.GSO) tcpip.Error {
|
||||
func (e *Endpoint) sendTCP(r *stack.Route, tf tcpFields, pkt *stack.PacketBuffer, gso stack.GSO) tcpip.Error {
|
||||
tf.txHash = e.txHash
|
||||
if err := sendTCP(r, tf, pkt, gso, e.owner); err != nil {
|
||||
e.stats.SendErrors.SegmentSendToNetworkFailed.Increment()
|
||||
@@ -925,7 +925,7 @@ func sendTCP(r *stack.Route, tf tcpFields, pkt *stack.PacketBuffer, gso stack.GS
|
||||
}
|
||||
|
||||
// makeOptions makes an options slice.
|
||||
func (e *endpoint) makeOptions(sackBlocks []header.SACKBlock) []byte {
|
||||
func (e *Endpoint) makeOptions(sackBlocks []header.SACKBlock) []byte {
|
||||
options := getOptions()
|
||||
offset := 0
|
||||
|
||||
@@ -964,7 +964,7 @@ func (e *endpoint) makeOptions(sackBlocks []header.SACKBlock) []byte {
|
||||
}
|
||||
|
||||
// sendEmptyRaw sends a TCP segment with no payload to the endpoint's peer.
|
||||
func (e *endpoint) sendEmptyRaw(flags header.TCPFlags, seq, ack seqnum.Value, rcvWnd seqnum.Size) tcpip.Error {
|
||||
func (e *Endpoint) sendEmptyRaw(flags header.TCPFlags, seq, ack seqnum.Value, rcvWnd seqnum.Size) tcpip.Error {
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{})
|
||||
defer pkt.DecRef()
|
||||
return e.sendRaw(pkt, flags, seq, ack, rcvWnd)
|
||||
@@ -972,7 +972,7 @@ func (e *endpoint) sendEmptyRaw(flags header.TCPFlags, seq, ack seqnum.Value, rc
|
||||
|
||||
// sendRaw sends a TCP segment to the endpoint's peer. This method takes
|
||||
// ownership of pkt. pkt must not have any headers set.
|
||||
func (e *endpoint) sendRaw(pkt *stack.PacketBuffer, flags header.TCPFlags, seq, ack seqnum.Value, rcvWnd seqnum.Size) tcpip.Error {
|
||||
func (e *Endpoint) sendRaw(pkt *stack.PacketBuffer, flags header.TCPFlags, seq, ack seqnum.Value, rcvWnd seqnum.Size) tcpip.Error {
|
||||
var sackBlocks []header.SACKBlock
|
||||
if e.EndpointState() == StateEstablished && e.rcv.pendingRcvdSegments.Len() > 0 && (flags&header.TCPFlagAck != 0) {
|
||||
sackBlocks = e.sack.Blocks[:e.sack.NumBlocks]
|
||||
@@ -994,7 +994,7 @@ func (e *endpoint) sendRaw(pkt *stack.PacketBuffer, flags header.TCPFlags, seq,
|
||||
|
||||
// +checklocks:e.mu
|
||||
// +checklocksalias:e.snd.ep.mu=e.mu
|
||||
func (e *endpoint) sendData(next *segment) {
|
||||
func (e *Endpoint) sendData(next *segment) {
|
||||
// Initialize the next segment to write if it's currently nil.
|
||||
if e.snd.writeNext == nil {
|
||||
if next == nil {
|
||||
@@ -1012,7 +1012,7 @@ func (e *endpoint) sendData(next *segment) {
|
||||
// indicating that the connection is being reset due to receiving a RST. This
|
||||
// method must only be called from the protocol goroutine.
|
||||
// +checklocks:e.mu
|
||||
func (e *endpoint) resetConnectionLocked(err tcpip.Error) {
|
||||
func (e *Endpoint) resetConnectionLocked(err tcpip.Error) {
|
||||
// Only send a reset if the connection is being aborted for a reason
|
||||
// other than receiving a reset.
|
||||
e.hardError = err
|
||||
@@ -1047,7 +1047,7 @@ func (e *endpoint) resetConnectionLocked(err tcpip.Error) {
|
||||
// delivered to this endpoint from the demuxer when the endpoint
|
||||
// is transitioned to StateClose.
|
||||
// +checklocks:e.mu
|
||||
func (e *endpoint) transitionToStateCloseLocked() {
|
||||
func (e *Endpoint) transitionToStateCloseLocked() {
|
||||
s := e.EndpointState()
|
||||
if s == StateClose {
|
||||
return
|
||||
@@ -1066,7 +1066,7 @@ func (e *endpoint) transitionToStateCloseLocked() {
|
||||
// segment to any other endpoint other than the current one. This is called
|
||||
// only when the endpoint is in StateClose and we want to deliver the segment
|
||||
// to any other listening endpoint. We reply with RST if we cannot find one.
|
||||
func (e *endpoint) tryDeliverSegmentFromClosedEndpoint(s *segment) {
|
||||
func (e *Endpoint) tryDeliverSegmentFromClosedEndpoint(s *segment) {
|
||||
ep := e.stack.FindTransportEndpoint(e.NetProto, e.TransProto, e.TransportEndpointInfo.ID, s.pkt.NICID)
|
||||
if ep == nil && e.NetProto == header.IPv6ProtocolNumber && e.TransportEndpointInfo.ID.LocalAddress.To4() != (tcpip.Address{}) {
|
||||
// Dual-stack socket, try IPv4.
|
||||
@@ -1088,7 +1088,7 @@ func (e *endpoint) tryDeliverSegmentFromClosedEndpoint(s *segment) {
|
||||
panic(fmt.Sprintf("current endpoint not removed from demuxer, enqueuing segments to itself, endpoint in state %v", e.EndpointState()))
|
||||
}
|
||||
|
||||
if ep := ep.(*endpoint); ep.enqueueSegment(s) {
|
||||
if ep := ep.(*Endpoint); ep.enqueueSegment(s) {
|
||||
ep.notifyProcessor()
|
||||
}
|
||||
}
|
||||
@@ -1096,7 +1096,7 @@ func (e *endpoint) tryDeliverSegmentFromClosedEndpoint(s *segment) {
|
||||
// Drain segment queue from the endpoint and try to re-match the segment to a
|
||||
// different endpoint. This is used when the current endpoint is transitioned to
|
||||
// StateClose and has been unregistered from the transport demuxer.
|
||||
func (e *endpoint) drainClosingSegmentQueue() {
|
||||
func (e *Endpoint) drainClosingSegmentQueue() {
|
||||
for {
|
||||
s := e.segmentQueue.dequeue()
|
||||
if s == nil {
|
||||
@@ -1109,7 +1109,7 @@ func (e *endpoint) drainClosingSegmentQueue() {
|
||||
}
|
||||
|
||||
// +checklocks:e.mu
|
||||
func (e *endpoint) handleReset(s *segment) (ok bool, err tcpip.Error) {
|
||||
func (e *Endpoint) handleReset(s *segment) (ok bool, err tcpip.Error) {
|
||||
if e.rcv.acceptable(s.sequenceNumber, 0) {
|
||||
// RFC 793, page 37 states that "in all states
|
||||
// except SYN-SENT, all reset (RST) segments are
|
||||
@@ -1158,7 +1158,7 @@ func (e *endpoint) handleReset(s *segment) (ok bool, err tcpip.Error) {
|
||||
//
|
||||
// +checklocks:e.mu
|
||||
// +checklocksalias:e.snd.ep.mu=e.mu
|
||||
func (e *endpoint) handleSegmentsLocked() tcpip.Error {
|
||||
func (e *Endpoint) handleSegmentsLocked() tcpip.Error {
|
||||
sndUna := e.snd.SndUna
|
||||
for i := 0; i < maxSegmentsPerWake; i++ {
|
||||
if state := e.EndpointState(); state.closed() || state == StateTimeWait || state == StateError {
|
||||
@@ -1200,7 +1200,7 @@ func (e *endpoint) handleSegmentsLocked() tcpip.Error {
|
||||
}
|
||||
|
||||
// +checklocks:e.mu
|
||||
func (e *endpoint) probeSegmentLocked() {
|
||||
func (e *Endpoint) probeSegmentLocked() {
|
||||
if fn := e.probe; fn != nil {
|
||||
var state stack.TCPEndpointState
|
||||
e.completeStateLocked(&state)
|
||||
@@ -1214,7 +1214,7 @@ func (e *endpoint) probeSegmentLocked() {
|
||||
// +checklocks:e.mu
|
||||
// +checklocksalias:e.rcv.ep.mu=e.mu
|
||||
// +checklocksalias:e.snd.ep.mu=e.mu
|
||||
func (e *endpoint) handleSegmentLocked(s *segment) (cont bool, err tcpip.Error) {
|
||||
func (e *Endpoint) handleSegmentLocked(s *segment) (cont bool, err tcpip.Error) {
|
||||
// Invoke the tcp probe if installed. The tcp probe function will update
|
||||
// the TCPEndpointState after the segment is processed.
|
||||
defer e.probeSegmentLocked()
|
||||
@@ -1289,7 +1289,7 @@ func (e *endpoint) handleSegmentLocked(s *segment) (cont bool, err tcpip.Error)
|
||||
// from the other side after a number of tries, we terminate the connection.
|
||||
// +checklocks:e.mu
|
||||
// +checklocksalias:e.snd.ep.mu=e.mu
|
||||
func (e *endpoint) keepaliveTimerExpired() tcpip.Error {
|
||||
func (e *Endpoint) keepaliveTimerExpired() tcpip.Error {
|
||||
userTimeout := e.userTimeout
|
||||
|
||||
e.keepalive.Lock()
|
||||
@@ -1323,7 +1323,7 @@ func (e *endpoint) keepaliveTimerExpired() tcpip.Error {
|
||||
|
||||
// resetKeepaliveTimer restarts or stops the keepalive timer, depending on
|
||||
// whether it is enabled for this endpoint.
|
||||
func (e *endpoint) resetKeepaliveTimer(receivedData bool) {
|
||||
func (e *Endpoint) resetKeepaliveTimer(receivedData bool) {
|
||||
e.keepalive.Lock()
|
||||
defer e.keepalive.Unlock()
|
||||
if e.keepalive.timer.isUninitialized() {
|
||||
@@ -1349,7 +1349,7 @@ func (e *endpoint) resetKeepaliveTimer(receivedData bool) {
|
||||
}
|
||||
|
||||
// disableKeepaliveTimer stops the keepalive timer.
|
||||
func (e *endpoint) disableKeepaliveTimer() {
|
||||
func (e *Endpoint) disableKeepaliveTimer() {
|
||||
e.keepalive.Lock()
|
||||
e.keepalive.timer.disable()
|
||||
e.keepalive.Unlock()
|
||||
@@ -1357,7 +1357,7 @@ func (e *endpoint) disableKeepaliveTimer() {
|
||||
|
||||
// finWait2TimerExpired is called when the FIN-WAIT-2 timeout is hit
|
||||
// and the peer hasn't sent us a FIN.
|
||||
func (e *endpoint) finWait2TimerExpired() {
|
||||
func (e *Endpoint) finWait2TimerExpired() {
|
||||
e.mu.Lock()
|
||||
e.transitionToStateCloseLocked()
|
||||
e.mu.Unlock()
|
||||
@@ -1366,7 +1366,7 @@ func (e *endpoint) finWait2TimerExpired() {
|
||||
}
|
||||
|
||||
// +checklocks:e.mu
|
||||
func (e *endpoint) handshakeFailed(err tcpip.Error) {
|
||||
func (e *Endpoint) handshakeFailed(err tcpip.Error) {
|
||||
e.lastErrorMu.Lock()
|
||||
e.lastError = err
|
||||
e.lastErrorMu.Unlock()
|
||||
@@ -1386,7 +1386,7 @@ func (e *endpoint) handshakeFailed(err tcpip.Error) {
|
||||
// state.
|
||||
// +checklocks:e.mu
|
||||
// +checklocksalias:e.rcv.ep.mu=e.mu
|
||||
func (e *endpoint) handleTimeWaitSegments() (extendTimeWait bool, reuseTW func()) {
|
||||
func (e *Endpoint) handleTimeWaitSegments() (extendTimeWait bool, reuseTW func()) {
|
||||
for i := 0; i < maxSegmentsPerWake; i++ {
|
||||
s := e.segmentQueue.dequeue()
|
||||
if s == nil {
|
||||
@@ -1407,7 +1407,7 @@ func (e *endpoint) handleTimeWaitSegments() (extendTimeWait bool, reuseTW func()
|
||||
}
|
||||
for _, netProto := range netProtos {
|
||||
if listenEP := e.stack.FindTransportEndpoint(netProto, info.TransProto, newID, s.pkt.NICID); listenEP != nil {
|
||||
tcpEP := listenEP.(*endpoint)
|
||||
tcpEP := listenEP.(*Endpoint)
|
||||
if EndpointState(tcpEP.State()) == StateListen {
|
||||
reuseTW = func() {
|
||||
if !tcpEP.enqueueSegment(s) {
|
||||
@@ -1432,7 +1432,7 @@ func (e *endpoint) handleTimeWaitSegments() (extendTimeWait bool, reuseTW func()
|
||||
}
|
||||
|
||||
// +checklocks:e.mu
|
||||
func (e *endpoint) getTimeWaitDuration() time.Duration {
|
||||
func (e *Endpoint) getTimeWaitDuration() time.Duration {
|
||||
timeWaitDuration := DefaultTCPTimeWaitTimeout
|
||||
|
||||
// Get the stack wide configuration.
|
||||
@@ -1446,7 +1446,7 @@ func (e *endpoint) getTimeWaitDuration() time.Duration {
|
||||
// timeWaitTimerExpired is called when an endpoint completes the required time
|
||||
// (typically 2 * MSL unless configured to something else at a stack level) in
|
||||
// TIME-WAIT state.
|
||||
func (e *endpoint) timeWaitTimerExpired() {
|
||||
func (e *Endpoint) timeWaitTimerExpired() {
|
||||
e.mu.Lock()
|
||||
if e.EndpointState() != StateTimeWait {
|
||||
e.mu.Unlock()
|
||||
@@ -1459,7 +1459,7 @@ func (e *endpoint) timeWaitTimerExpired() {
|
||||
}
|
||||
|
||||
// notifyProcessor queues this endpoint for processing to its TCP processor.
|
||||
func (e *endpoint) notifyProcessor() {
|
||||
func (e *Endpoint) notifyProcessor() {
|
||||
// We use TryLock here to avoid deadlocks in cases where a listening endpoint that is being
|
||||
// closed tries to abort half completed connections which in turn try to queue any segments
|
||||
// queued to that endpoint back to the same listening endpoint (because it may have got
|
||||
|
||||
@@ -35,7 +35,7 @@ type epQueue struct {
|
||||
}
|
||||
|
||||
// enqueue adds e to the queue if the endpoint is not already on the queue.
|
||||
func (q *epQueue) enqueue(e *endpoint) {
|
||||
func (q *epQueue) enqueue(e *Endpoint) {
|
||||
q.mu.Lock()
|
||||
defer q.mu.Unlock()
|
||||
e.pendingProcessingMu.Lock()
|
||||
@@ -50,7 +50,7 @@ func (q *epQueue) enqueue(e *endpoint) {
|
||||
|
||||
// dequeue removes and returns the first element from the queue if available,
|
||||
// returns nil otherwise.
|
||||
func (q *epQueue) dequeue() *endpoint {
|
||||
func (q *epQueue) dequeue() *Endpoint {
|
||||
q.mu.Lock()
|
||||
if e := q.list.Front(); e != nil {
|
||||
q.list.Remove(e)
|
||||
@@ -87,7 +87,7 @@ func (p *processor) close() {
|
||||
p.closeWaker.Assert()
|
||||
}
|
||||
|
||||
func (p *processor) queueEndpoint(ep *endpoint) {
|
||||
func (p *processor) queueEndpoint(ep *Endpoint) {
|
||||
// Queue an endpoint for processing by the processor goroutine.
|
||||
p.epQ.enqueue(ep)
|
||||
p.newEndpointWaker.Assert()
|
||||
@@ -97,7 +97,7 @@ func (p *processor) queueEndpoint(ep *endpoint) {
|
||||
// of its associated listening endpoint.
|
||||
//
|
||||
// +checklocks:ep.mu
|
||||
func deliverAccepted(ep *endpoint) bool {
|
||||
func deliverAccepted(ep *Endpoint) bool {
|
||||
lEP := ep.h.listenEP
|
||||
lEP.acceptMu.Lock()
|
||||
|
||||
@@ -129,7 +129,7 @@ func deliverAccepted(ep *endpoint) bool {
|
||||
|
||||
// handleConnecting is responsible for TCP processing for an endpoint in one of
|
||||
// the connecting states.
|
||||
func handleConnecting(ep *endpoint) {
|
||||
func handleConnecting(ep *Endpoint) {
|
||||
if !ep.TryLock() {
|
||||
return
|
||||
}
|
||||
@@ -172,7 +172,7 @@ func handleConnecting(ep *endpoint) {
|
||||
|
||||
// handleConnected is responsible for TCP processing for an endpoint in one of
|
||||
// the connected states(StateEstablished, StateFinWait1 etc.)
|
||||
func handleConnected(ep *endpoint) {
|
||||
func handleConnected(ep *Endpoint) {
|
||||
if !ep.TryLock() {
|
||||
return
|
||||
}
|
||||
@@ -208,7 +208,7 @@ func handleConnected(ep *endpoint) {
|
||||
// startTimeWait starts a new goroutine to handle TIME-WAIT.
|
||||
//
|
||||
// +checklocks:ep.mu
|
||||
func startTimeWait(ep *endpoint) {
|
||||
func startTimeWait(ep *Endpoint) {
|
||||
// Disable close timer as we are now entering real TIME_WAIT.
|
||||
if ep.finWait2Timer != nil {
|
||||
ep.finWait2Timer.Stop()
|
||||
@@ -221,7 +221,7 @@ func startTimeWait(ep *endpoint) {
|
||||
|
||||
// handleTimeWait is responsible for TCP processing for an endpoint in TIME-WAIT
|
||||
// state.
|
||||
func handleTimeWait(ep *endpoint) {
|
||||
func handleTimeWait(ep *Endpoint) {
|
||||
if !ep.TryLock() {
|
||||
return
|
||||
}
|
||||
@@ -251,7 +251,7 @@ func handleTimeWait(ep *endpoint) {
|
||||
|
||||
// handleListen is responsible for TCP processing for an endpoint in LISTEN
|
||||
// state.
|
||||
func handleListen(ep *endpoint) {
|
||||
func handleListen(ep *Endpoint) {
|
||||
if !ep.TryLock() {
|
||||
return
|
||||
}
|
||||
@@ -418,7 +418,7 @@ func (d *dispatcher) queuePacket(stackEP stack.TransportEndpoint, id stack.Trans
|
||||
return
|
||||
}
|
||||
|
||||
ep := stackEP.(*endpoint)
|
||||
ep := stackEP.(*Endpoint)
|
||||
|
||||
s, err := newIncomingSegment(id, clock, pkt)
|
||||
if err != nil {
|
||||
|
||||
+118
-115
File diff suppressed because it is too large
Load Diff
@@ -27,7 +27,7 @@ import (
|
||||
)
|
||||
|
||||
// beforeSave is invoked by stateify.
|
||||
func (e *endpoint) beforeSave() {
|
||||
func (e *Endpoint) beforeSave() {
|
||||
// Stop incoming packets.
|
||||
e.segmentQueue.freeze()
|
||||
|
||||
@@ -62,23 +62,23 @@ func (e *endpoint) beforeSave() {
|
||||
}
|
||||
|
||||
// saveEndpoints is invoked by stateify.
|
||||
func (a *acceptQueue) saveEndpoints() []*endpoint {
|
||||
acceptedEndpoints := make([]*endpoint, a.endpoints.Len())
|
||||
func (a *acceptQueue) saveEndpoints() []*Endpoint {
|
||||
acceptedEndpoints := make([]*Endpoint, a.endpoints.Len())
|
||||
for i, e := 0, a.endpoints.Front(); e != nil; i, e = i+1, e.Next() {
|
||||
acceptedEndpoints[i] = e.Value.(*endpoint)
|
||||
acceptedEndpoints[i] = e.Value.(*Endpoint)
|
||||
}
|
||||
return acceptedEndpoints
|
||||
}
|
||||
|
||||
// loadEndpoints is invoked by stateify.
|
||||
func (a *acceptQueue) loadEndpoints(_ context.Context, acceptedEndpoints []*endpoint) {
|
||||
func (a *acceptQueue) loadEndpoints(_ context.Context, acceptedEndpoints []*Endpoint) {
|
||||
for _, ep := range acceptedEndpoints {
|
||||
a.endpoints.PushBack(ep)
|
||||
}
|
||||
}
|
||||
|
||||
// saveState is invoked by stateify.
|
||||
func (e *endpoint) saveState() EndpointState {
|
||||
func (e *Endpoint) saveState() EndpointState {
|
||||
return e.EndpointState()
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ var connectingLoading sync.WaitGroup
|
||||
// Bound endpoint loading happens last.
|
||||
|
||||
// loadState is invoked by stateify.
|
||||
func (e *endpoint) loadState(_ context.Context, epState EndpointState) {
|
||||
func (e *Endpoint) loadState(_ context.Context, epState EndpointState) {
|
||||
// This is to ensure that the loading wait groups include all applicable
|
||||
// endpoints before any asynchronous calls to the Wait() methods.
|
||||
// For restore purposes we treat TimeWait like a connected endpoint.
|
||||
@@ -112,7 +112,7 @@ func (e *endpoint) loadState(_ context.Context, epState EndpointState) {
|
||||
}
|
||||
|
||||
// afterLoad is invoked by stateify.
|
||||
func (e *endpoint) afterLoad(ctx context.Context) {
|
||||
func (e *Endpoint) afterLoad(ctx context.Context) {
|
||||
// RacyLoad() can be used because we are initializing e.
|
||||
e.origEndpointState = e.state.RacyLoad()
|
||||
// Restore the endpoint to InitialState as it will be moved to
|
||||
@@ -122,7 +122,7 @@ func (e *endpoint) afterLoad(ctx context.Context) {
|
||||
}
|
||||
|
||||
// Restore implements tcpip.RestoredEndpoint.Restore.
|
||||
func (e *endpoint) Restore(s *stack.Stack) {
|
||||
func (e *Endpoint) Restore(s *stack.Stack) {
|
||||
if !e.EndpointState().closed() {
|
||||
e.keepalive.timer.init(s.Clock(), timerHandler(e, e.keepaliveTimerExpired))
|
||||
}
|
||||
@@ -280,6 +280,6 @@ func (e *endpoint) Restore(s *stack.Stack) {
|
||||
}
|
||||
|
||||
// Resume implements tcpip.ResumableEndpoint.Resume.
|
||||
func (e *endpoint) Resume() {
|
||||
func (e *Endpoint) Resume() {
|
||||
e.segmentQueue.thaw()
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import (
|
||||
// +stateify savable
|
||||
type receiver struct {
|
||||
stack.TCPReceiverState
|
||||
ep *endpoint
|
||||
ep *Endpoint
|
||||
|
||||
// rcvWnd is the non-scaled receive window last advertised to the peer.
|
||||
rcvWnd seqnum.Size
|
||||
@@ -52,7 +52,7 @@ type receiver struct {
|
||||
lastRcvdAckTime tcpip.MonotonicTime
|
||||
}
|
||||
|
||||
func newReceiver(ep *endpoint, irs seqnum.Value, rcvWnd seqnum.Size, rcvWndScale uint8) *receiver {
|
||||
func newReceiver(ep *Endpoint, irs seqnum.Value, rcvWnd seqnum.Size, rcvWndScale uint8) *receiver {
|
||||
return &receiver{
|
||||
ep: ep,
|
||||
TCPReceiverState: stack.TCPReceiverState{
|
||||
|
||||
@@ -55,7 +55,7 @@ type segment struct {
|
||||
segmentEntry
|
||||
segmentRefs
|
||||
|
||||
ep *endpoint
|
||||
ep *Endpoint
|
||||
qFlags queueFlags
|
||||
id stack.TransportEndpointID `state:"manual"`
|
||||
|
||||
@@ -182,7 +182,7 @@ func (s *segment) merge(oth *segment) {
|
||||
// setOwner sets the owning endpoint for this segment. Its required
|
||||
// to be called to ensure memory accounting for receive/send buffer
|
||||
// queues is done properly.
|
||||
func (s *segment) setOwner(ep *endpoint, qFlags queueFlags) {
|
||||
func (s *segment) setOwner(ep *Endpoint, qFlags queueFlags) {
|
||||
switch qFlags {
|
||||
case recvQ:
|
||||
ep.updateReceiveMemUsed(s.segMemSize())
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
type segmentQueue struct {
|
||||
mu sync.Mutex `state:"nosave"`
|
||||
list segmentList `state:"wait"`
|
||||
ep *endpoint
|
||||
ep *Endpoint
|
||||
frozen bool
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ type lossRecovery interface {
|
||||
// +stateify savable
|
||||
type sender struct {
|
||||
stack.TCPSenderState
|
||||
ep *endpoint
|
||||
ep *Endpoint
|
||||
|
||||
// lr is the loss recovery algorithm used by the sender.
|
||||
lr lossRecovery
|
||||
@@ -171,7 +171,7 @@ type rtt struct {
|
||||
}
|
||||
|
||||
// +checklocks:ep.mu
|
||||
func newSender(ep *endpoint, iss, irs seqnum.Value, sndWnd seqnum.Size, mss uint16, sndWndScale int) *sender {
|
||||
func newSender(ep *Endpoint, iss, irs seqnum.Value, sndWnd seqnum.Size, mss uint16, sndWndScale int) *sender {
|
||||
// The sender MUST reduce the TCP data length to account for any IP or
|
||||
// TCP options that it is including in the packets that it sends.
|
||||
// See: https://tools.ietf.org/html/rfc6691#section-2
|
||||
|
||||
Reference in New Issue
Block a user