mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Merge pull request #8776 from raggi:raggi/nil-dispatchers
PiperOrigin-RevId: 521862637
This commit is contained in:
@@ -192,12 +192,15 @@ func (e *Endpoint) NumQueued() int {
|
||||
return e.q.Num()
|
||||
}
|
||||
|
||||
// InjectInbound injects an inbound packet.
|
||||
// InjectInbound injects an inbound packet. If the endpoint is not attached, the
|
||||
// packet is not delivered.
|
||||
func (e *Endpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
|
||||
e.mu.RLock()
|
||||
d := e.dispatcher
|
||||
e.mu.RUnlock()
|
||||
d.DeliverNetworkPacket(protocol, pkt)
|
||||
if d != nil {
|
||||
d.DeliverNetworkPacket(protocol, pkt)
|
||||
}
|
||||
}
|
||||
|
||||
// Attach saves the stack network-layer dispatcher for use later when packets
|
||||
|
||||
@@ -785,12 +785,15 @@ func (e *InjectableEndpoint) Attach(dispatcher stack.NetworkDispatcher) {
|
||||
e.dispatcher = dispatcher
|
||||
}
|
||||
|
||||
// InjectInbound injects an inbound packet.
|
||||
// InjectInbound injects an inbound packet. If the endpoint is not attached, the
|
||||
// packet is not delivered.
|
||||
func (e *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
|
||||
e.mu.RLock()
|
||||
d := e.dispatcher
|
||||
e.mu.RUnlock()
|
||||
d.DeliverNetworkPacket(protocol, pkt)
|
||||
if d != nil {
|
||||
d.DeliverNetworkPacket(protocol, pkt)
|
||||
}
|
||||
}
|
||||
|
||||
// NewInjectable creates a new fd-based InjectableEndpoint.
|
||||
|
||||
@@ -81,7 +81,8 @@ func (*endpoint) LinkAddress() tcpip.LinkAddress {
|
||||
// Wait implements stack.LinkEndpoint.Wait.
|
||||
func (*endpoint) Wait() {}
|
||||
|
||||
// WritePackets implements stack.LinkEndpoint.WritePackets.
|
||||
// WritePackets implements stack.LinkEndpoint.WritePackets. If the endpoint is
|
||||
// not attached, the packets are not delivered.
|
||||
func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) {
|
||||
e.mu.RLock()
|
||||
d := e.dispatcher
|
||||
@@ -93,7 +94,9 @@ func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error)
|
||||
newPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Payload: pkt.ToBuffer(),
|
||||
})
|
||||
d.DeliverNetworkPacket(pkt.NetworkProtocolNumber, newPkt)
|
||||
if d != nil {
|
||||
d.DeliverNetworkPacket(pkt.NetworkProtocolNumber, newPkt)
|
||||
}
|
||||
newPkt.DecRef()
|
||||
}
|
||||
return pkts.Len(), nil
|
||||
|
||||
@@ -63,7 +63,9 @@ func (e *Endpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pk
|
||||
e.mu.RLock()
|
||||
d := e.dispatcher
|
||||
e.mu.RUnlock()
|
||||
d.DeliverNetworkPacket(protocol, pkt)
|
||||
if d != nil {
|
||||
d.DeliverNetworkPacket(protocol, pkt)
|
||||
}
|
||||
e.dispatchGate.Leave()
|
||||
}
|
||||
|
||||
@@ -75,7 +77,9 @@ func (e *Endpoint) DeliverLinkPacket(protocol tcpip.NetworkProtocolNumber, pkt s
|
||||
e.mu.RLock()
|
||||
d := e.dispatcher
|
||||
e.mu.RUnlock()
|
||||
d.DeliverLinkPacket(protocol, pkt)
|
||||
if d != nil {
|
||||
d.DeliverLinkPacket(protocol, pkt)
|
||||
}
|
||||
e.dispatchGate.Leave()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user