mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Drop TransportEndpointID from HandleControlPacket
When a control packet is delivered, it is delivered to a transport endpoint with a matching stack.TransportEndpointID so there is no need to pass the ID to the endpoint as it already knows its ID. PiperOrigin-RevId: 351497588
This commit is contained in:
committed by
gVisor bot
parent
680398ab76
commit
62b4c2f517
@@ -84,7 +84,7 @@ type TransportEndpoint interface {
|
||||
// HandleControlPacket is called by the stack when new control (e.g.
|
||||
// ICMP) packets arrive to this transport endpoint.
|
||||
// HandleControlPacket takes ownership of pkt.
|
||||
HandleControlPacket(id TransportEndpointID, typ ControlType, extra uint32, pkt *PacketBuffer)
|
||||
HandleControlPacket(typ ControlType, extra uint32, pkt *PacketBuffer)
|
||||
|
||||
// Abort initiates an expedited endpoint teardown. It puts the endpoint
|
||||
// in a closed state and frees all resources associated with it. This
|
||||
|
||||
@@ -182,7 +182,8 @@ func (epsByNIC *endpointsByNIC) handlePacket(id TransportEndpointID, pkt *Packet
|
||||
epsByNIC.mu.RUnlock() // Don't use defer for performance reasons.
|
||||
}
|
||||
|
||||
// HandleControlPacket implements stack.TransportEndpoint.HandleControlPacket.
|
||||
// handleControlPacket delivers a control packet to the transport endpoint
|
||||
// identified by id.
|
||||
func (epsByNIC *endpointsByNIC) handleControlPacket(n *NIC, id TransportEndpointID, typ ControlType, extra uint32, pkt *PacketBuffer) {
|
||||
epsByNIC.mu.RLock()
|
||||
defer epsByNIC.mu.RUnlock()
|
||||
@@ -199,7 +200,7 @@ func (epsByNIC *endpointsByNIC) handleControlPacket(n *NIC, id TransportEndpoint
|
||||
// broadcast like we are doing with handlePacket above?
|
||||
|
||||
// multiPortEndpoints are guaranteed to have at least one element.
|
||||
selectEndpoint(id, mpep, epsByNIC.seed).HandleControlPacket(id, typ, extra, pkt)
|
||||
selectEndpoint(id, mpep, epsByNIC.seed).HandleControlPacket(typ, extra, pkt)
|
||||
}
|
||||
|
||||
// registerEndpoint returns true if it succeeds. It fails and returns
|
||||
|
||||
@@ -237,7 +237,7 @@ func (f *fakeTransportEndpoint) HandlePacket(id stack.TransportEndpointID, pkt *
|
||||
f.acceptQueue = append(f.acceptQueue, ep)
|
||||
}
|
||||
|
||||
func (f *fakeTransportEndpoint) HandleControlPacket(stack.TransportEndpointID, stack.ControlType, uint32, *stack.PacketBuffer) {
|
||||
func (f *fakeTransportEndpoint) HandleControlPacket(stack.ControlType, uint32, *stack.PacketBuffer) {
|
||||
// Increment the number of received control packets.
|
||||
f.proto.controlCount++
|
||||
}
|
||||
|
||||
@@ -789,7 +789,7 @@ func (e *endpoint) HandlePacket(id stack.TransportEndpointID, pkt *stack.PacketB
|
||||
}
|
||||
|
||||
// HandleControlPacket implements stack.TransportEndpoint.HandleControlPacket.
|
||||
func (e *endpoint) HandleControlPacket(id stack.TransportEndpointID, typ stack.ControlType, extra uint32, pkt *stack.PacketBuffer) {
|
||||
func (e *endpoint) HandleControlPacket(typ stack.ControlType, extra uint32, pkt *stack.PacketBuffer) {
|
||||
}
|
||||
|
||||
// State implements tcpip.Endpoint.State. The ICMP endpoint currently doesn't
|
||||
|
||||
@@ -2728,7 +2728,7 @@ func (e *endpoint) enqueueSegment(s *segment) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (e *endpoint) onICMPError(err *tcpip.Error, id stack.TransportEndpointID, errType byte, errCode byte, extra uint32, pkt *stack.PacketBuffer) {
|
||||
func (e *endpoint) onICMPError(err *tcpip.Error, errType byte, errCode byte, extra uint32, pkt *stack.PacketBuffer) {
|
||||
// Update last error first.
|
||||
e.lastErrorMu.Lock()
|
||||
e.lastError = err
|
||||
@@ -2747,13 +2747,13 @@ func (e *endpoint) onICMPError(err *tcpip.Error, id stack.TransportEndpointID, e
|
||||
Payload: pkt.Data.ToView(),
|
||||
Dst: tcpip.FullAddress{
|
||||
NIC: pkt.NICID,
|
||||
Addr: id.RemoteAddress,
|
||||
Port: id.RemotePort,
|
||||
Addr: e.ID.RemoteAddress,
|
||||
Port: e.ID.RemotePort,
|
||||
},
|
||||
Offender: tcpip.FullAddress{
|
||||
NIC: pkt.NICID,
|
||||
Addr: id.LocalAddress,
|
||||
Port: id.LocalPort,
|
||||
Addr: e.ID.LocalAddress,
|
||||
Port: e.ID.LocalPort,
|
||||
},
|
||||
NetProto: pkt.NetworkProtocolNumber,
|
||||
})
|
||||
@@ -2764,7 +2764,7 @@ func (e *endpoint) onICMPError(err *tcpip.Error, id stack.TransportEndpointID, e
|
||||
}
|
||||
|
||||
// HandleControlPacket implements stack.TransportEndpoint.HandleControlPacket.
|
||||
func (e *endpoint) HandleControlPacket(id stack.TransportEndpointID, typ stack.ControlType, extra uint32, pkt *stack.PacketBuffer) {
|
||||
func (e *endpoint) HandleControlPacket(typ stack.ControlType, extra uint32, pkt *stack.PacketBuffer) {
|
||||
switch typ {
|
||||
case stack.ControlPacketTooBig:
|
||||
e.sndBufMu.Lock()
|
||||
@@ -2777,10 +2777,10 @@ func (e *endpoint) HandleControlPacket(id stack.TransportEndpointID, typ stack.C
|
||||
e.notifyProtocolGoroutine(notifyMTUChanged)
|
||||
|
||||
case stack.ControlNoRoute:
|
||||
e.onICMPError(tcpip.ErrNoRoute, id, byte(header.ICMPv4DstUnreachable), byte(header.ICMPv4HostUnreachable), extra, pkt)
|
||||
e.onICMPError(tcpip.ErrNoRoute, byte(header.ICMPv4DstUnreachable), byte(header.ICMPv4HostUnreachable), extra, pkt)
|
||||
|
||||
case stack.ControlNetworkUnreachable:
|
||||
e.onICMPError(tcpip.ErrNetworkUnreachable, id, byte(header.ICMPv6DstUnreachable), byte(header.ICMPv6NetworkUnreachable), extra, pkt)
|
||||
e.onICMPError(tcpip.ErrNetworkUnreachable, byte(header.ICMPv6DstUnreachable), byte(header.ICMPv6NetworkUnreachable), extra, pkt)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1352,7 +1352,7 @@ func (e *endpoint) HandlePacket(id stack.TransportEndpointID, pkt *stack.PacketB
|
||||
}
|
||||
}
|
||||
|
||||
func (e *endpoint) onICMPError(err *tcpip.Error, id stack.TransportEndpointID, errType byte, errCode byte, extra uint32, pkt *stack.PacketBuffer) {
|
||||
func (e *endpoint) onICMPError(err *tcpip.Error, errType byte, errCode byte, extra uint32, pkt *stack.PacketBuffer) {
|
||||
// Update last error first.
|
||||
e.lastErrorMu.Lock()
|
||||
e.lastError = err
|
||||
@@ -1376,13 +1376,13 @@ func (e *endpoint) onICMPError(err *tcpip.Error, id stack.TransportEndpointID, e
|
||||
Payload: payload,
|
||||
Dst: tcpip.FullAddress{
|
||||
NIC: pkt.NICID,
|
||||
Addr: id.RemoteAddress,
|
||||
Port: id.RemotePort,
|
||||
Addr: e.ID.RemoteAddress,
|
||||
Port: e.ID.RemotePort,
|
||||
},
|
||||
Offender: tcpip.FullAddress{
|
||||
NIC: pkt.NICID,
|
||||
Addr: id.LocalAddress,
|
||||
Port: id.LocalPort,
|
||||
Addr: e.ID.LocalAddress,
|
||||
Port: e.ID.LocalPort,
|
||||
},
|
||||
NetProto: pkt.NetworkProtocolNumber,
|
||||
})
|
||||
@@ -1393,7 +1393,7 @@ func (e *endpoint) onICMPError(err *tcpip.Error, id stack.TransportEndpointID, e
|
||||
}
|
||||
|
||||
// HandleControlPacket implements stack.TransportEndpoint.HandleControlPacket.
|
||||
func (e *endpoint) HandleControlPacket(id stack.TransportEndpointID, typ stack.ControlType, extra uint32, pkt *stack.PacketBuffer) {
|
||||
func (e *endpoint) HandleControlPacket(typ stack.ControlType, extra uint32, pkt *stack.PacketBuffer) {
|
||||
if typ == stack.ControlPortUnreachable {
|
||||
if e.EndpointState() == StateConnected {
|
||||
var errType byte
|
||||
@@ -1408,7 +1408,7 @@ func (e *endpoint) HandleControlPacket(id stack.TransportEndpointID, typ stack.C
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported net proto for infering ICMP type and code: %d", pkt.NetworkProtocolNumber))
|
||||
}
|
||||
e.onICMPError(tcpip.ErrConnectionRefused, id, errType, errCode, extra, pkt)
|
||||
e.onICMPError(tcpip.ErrConnectionRefused, errType, errCode, extra, pkt)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user