Drop LinkEndpoint.WriteRawPacket

PiperOrigin-RevId: 424490855
This commit is contained in:
Ghanan Gowripalan
2022-01-26 18:33:55 -08:00
committed by gVisor bot
parent 6a28dc7c59
commit f54fcc6e11
15 changed files with 13 additions and 114 deletions
-10
View File
@@ -268,13 +268,3 @@ func (*Endpoint) ARPHardwareType() header.ARPHardwareType {
// AddHeader implements stack.LinkEndpoint.AddHeader.
func (*Endpoint) AddHeader(*stack.PacketBuffer) {}
// WriteRawPacket implements stack.LinkEndpoint.
func (e *Endpoint) WriteRawPacket(pkt *stack.PacketBuffer) tcpip.Error {
// Write returns false if the queue is full. A full queue is not an error
// from the perspective of a LinkEndpoint so we ignore Write's return
// value and always return nil from this method.
_ = e.q.Write(pkt)
return nil
}
-3
View File
@@ -498,9 +498,6 @@ func (e *endpoint) AddHeader(pkt *stack.PacketBuffer) {
}
}
// WriteRawPacket implements stack.LinkEndpoint.
func (*endpoint) WriteRawPacket(*stack.PacketBuffer) tcpip.Error { return &tcpip.ErrNotSupported{} }
// writePacket writes outbound packets to the file descriptor. If it is not
// currently writable, the packet is dropped.
func (e *endpoint) writePacket(pkt *stack.PacketBuffer) tcpip.Error {
+7 -24
View File
@@ -76,14 +76,14 @@ func (*endpoint) Wait() {}
// WritePackets implements stack.LinkEndpoint.WritePackets.
func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) {
n := 0
for p := pkts.Front(); p != nil; p = p.Next() {
if err := e.WriteRawPacket(p); err != nil {
return n, err
}
n++
for pkt := pkts.Front(); pkt != nil; pkt = pkt.Next() {
newPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
Data: buffer.NewVectorisedView(pkt.Size(), pkt.Views()),
})
e.dispatcher.DeliverNetworkPacket(pkt.NetworkProtocolNumber, newPkt)
newPkt.DecRef()
}
return n, nil
return pkts.Len(), nil
}
// ARPHardwareType implements stack.LinkEndpoint.ARPHardwareType.
@@ -92,20 +92,3 @@ func (*endpoint) ARPHardwareType() header.ARPHardwareType {
}
func (*endpoint) AddHeader(*stack.PacketBuffer) {}
// WriteRawPacket implements stack.LinkEndpoint.
func (e *endpoint) WriteRawPacket(pkt *stack.PacketBuffer) tcpip.Error {
// Construct data as the unparsed portion for the loopback packet.
data := buffer.NewVectorisedView(pkt.Size(), pkt.Views())
// Because we're immediately turning around and writing the packet back
// to the rx path, we intentionally don't preserve the remote and local
// link addresses from the stack.Route we're passed.
newPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
Data: data,
})
defer newPkt.DecRef()
e.dispatcher.DeliverNetworkPacket(pkt.NetworkProtocolNumber, newPkt)
return nil
}
-5
View File
@@ -137,11 +137,6 @@ func (*InjectableEndpoint) ARPHardwareType() header.ARPHardwareType {
// AddHeader implements stack.LinkEndpoint.AddHeader.
func (*InjectableEndpoint) AddHeader(*stack.PacketBuffer) {}
// WriteRawPacket implements stack.LinkEndpoint.
func (*InjectableEndpoint) WriteRawPacket(*stack.PacketBuffer) tcpip.Error {
return &tcpip.ErrNotSupported{}
}
// NewInjectableEndpoint creates a new multi-endpoint injectable endpoint.
func NewInjectableEndpoint(routes map[tcpip.Address]stack.InjectableLinkEndpoint) *InjectableEndpoint {
return &InjectableEndpoint{
-5
View File
@@ -137,8 +137,3 @@ func (e *Endpoint) ARPHardwareType() header.ARPHardwareType {
func (e *Endpoint) AddHeader(pkt *stack.PacketBuffer) {
e.child.AddHeader(pkt)
}
// WriteRawPacket implements stack.LinkEndpoint.
func (e *Endpoint) WriteRawPacket(pkt *stack.PacketBuffer) tcpip.Error {
return e.child.WriteRawPacket(pkt)
}
-8
View File
@@ -109,11 +109,3 @@ func (*Endpoint) ARPHardwareType() header.ARPHardwareType {
// AddHeader implements stack.LinkEndpoint.
func (*Endpoint) AddHeader(*stack.PacketBuffer) {}
// WriteRawPacket implements stack.LinkEndpoint.
func (e *Endpoint) WriteRawPacket(pkt *stack.PacketBuffer) tcpip.Error {
var pkts stack.PacketBufferList
pkts.PushBack(pkt)
_, err := e.WritePackets(pkts)
return err
}
-3
View File
@@ -338,9 +338,6 @@ func (e *endpoint) AddVirtioNetHeader(pkt *stack.PacketBuffer) {
virtio.Encode(&header.VirtioNetHeaderFields{})
}
// WriteRawPacket implements stack.LinkEndpoint.
func (*endpoint) WriteRawPacket(*stack.PacketBuffer) tcpip.Error { return &tcpip.ErrNotSupported{} }
// +checklocks:e.mu
func (e *endpoint) writePacketLocked(r stack.RouteInfo, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) tcpip.Error {
if e.virtioNetHeaderRequired {
@@ -224,19 +224,6 @@ func (e *serverEndpoint) AddVirtioNetHeader(pkt *stack.PacketBuffer) {
virtio.Encode(&header.VirtioNetHeaderFields{})
}
// WriteRawPacket implements stack.LinkEndpoint.WriteRawPacket
func (e *serverEndpoint) WriteRawPacket(pkt *stack.PacketBuffer) tcpip.Error {
views := pkt.Views()
e.mu.Lock()
defer e.mu.Unlock()
ok := e.tx.transmit(views)
if !ok {
return &tcpip.ErrWouldBlock{}
}
e.tx.notify()
return nil
}
// +checklocks:e.mu
func (e *serverEndpoint) writePacketLocked(r stack.RouteInfo, protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) tcpip.Error {
if e.virtioNetHeaderRequired {
-3
View File
@@ -133,6 +133,3 @@ func (e *Endpoint) ARPHardwareType() header.ARPHardwareType {
func (e *Endpoint) AddHeader(pkt *stack.PacketBuffer) {
e.lower.AddHeader(pkt)
}
// WriteRawPacket implements stack.LinkEndpoint.
func (*Endpoint) WriteRawPacket(*stack.PacketBuffer) tcpip.Error { return &tcpip.ErrNotSupported{} }
-5
View File
@@ -76,11 +76,6 @@ func (e *countedEndpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.
return pkts.Len(), nil
}
// WriteRawPacket implements stack.LinkEndpoint.
func (*countedEndpoint) WriteRawPacket(*stack.PacketBuffer) tcpip.Error {
return &tcpip.ErrNotSupported{}
}
// ARPHardwareType implements stack.LinkEndpoint.ARPHardwareType.
func (*countedEndpoint) ARPHardwareType() header.ARPHardwareType {
panic("unimplemented")
@@ -90,11 +90,6 @@ func (*MockLinkEndpoint) ARPHardwareType() header.ARPHardwareType { return heade
// AddHeader implements LinkEndpoint.AddHeader.
func (*MockLinkEndpoint) AddHeader(*stack.PacketBuffer) {}
// WriteRawPacket implements stack.LinkEndpoint.
func (*MockLinkEndpoint) WriteRawPacket(*stack.PacketBuffer) tcpip.Error {
return &tcpip.ErrNotSupported{}
}
// MakeRandPkt generates a randomized packet. transportHeaderLength indicates
// how many random bytes will be copied in the Transport Header.
// extraHeaderReserveLength indicates how much extra space will be reserved for
-4
View File
@@ -317,10 +317,6 @@ func (e *fwdTestLinkEndpoint) WritePackets(pkts PacketBufferList) (int, tcpip.Er
return n, nil
}
func (*fwdTestLinkEndpoint) WriteRawPacket(*PacketBuffer) tcpip.Error {
return &tcpip.ErrNotSupported{}
}
// Wait implements stack.LinkEndpoint.Wait.
func (*fwdTestLinkEndpoint) Wait() {}
+5 -12
View File
@@ -85,8 +85,7 @@ type nic struct {
// +checklocks:packetEPsMu
packetEPs map[tcpip.NetworkProtocolNumber]*packetEndpointList
qDisc QueueingDiscipline
rawLinkEP LinkRawWriter
qDisc QueueingDiscipline
}
// makeNICStats initializes the NIC statistics and associates them to the global
@@ -182,7 +181,6 @@ func newNIC(stack *Stack, id tcpip.NICID, ep LinkEndpoint, opts NICOptions) *nic
linkAddrResolvers: make(map[tcpip.NetworkProtocolNumber]*linkResolver),
duplicateAddressDetectors: make(map[tcpip.NetworkProtocolNumber]DuplicateAddressDetector),
qDisc: qDisc,
rawLinkEP: ep,
}
nic.linkResQueue.init(nic)
@@ -343,11 +341,6 @@ func (n *nic) IsLoopback() bool {
return n.NetworkLinkEndpoint.Capabilities()&CapabilityLoopback != 0
}
// WriteRawPacket implements LinkRawWriter.
func (n *nic) WriteRawPacket(pkt *PacketBuffer) tcpip.Error {
return n.rawLinkEP.WriteRawPacket(pkt)
}
// WritePacket implements NetworkEndpoint.
func (n *nic) WritePacket(r *Route, pkt *PacketBuffer) tcpip.Error {
routeInfo, _, err := r.resolvedFields(nil)
@@ -392,11 +385,11 @@ func (n *nic) WritePacketToRemote(remoteLinkAddr tcpip.LinkAddress, pkt *PacketB
}
func (n *nic) writePacket(pkt *PacketBuffer) tcpip.Error {
// WritePacket modifies pkt, calculate numBytes first.
numBytes := pkt.Size()
n.NetworkLinkEndpoint.AddHeader(pkt)
return n.writeRawPacket(pkt)
}
func (n *nic) writeRawPacket(pkt *PacketBuffer) tcpip.Error {
n.deliverLinkPacket(pkt.NetworkProtocolNumber, pkt, false /* incoming */)
if err := n.qDisc.WritePacket(pkt); err != nil {
@@ -404,7 +397,7 @@ func (n *nic) writePacket(pkt *PacketBuffer) tcpip.Error {
}
n.stats.tx.packets.Increment()
n.stats.tx.bytes.IncrementBy(uint64(numBytes))
n.stats.tx.bytes.IncrementBy(uint64(pkt.Size()))
return nil
}
-13
View File
@@ -771,18 +771,6 @@ type LinkWriter interface {
WritePackets(PacketBufferList) (int, tcpip.Error)
}
// LinkRawWriter is an interface that must be implemented by all Link endpoints
// to support emitting pre-formed packets which include the Link header.
type LinkRawWriter interface {
// WriteRawPacket writes a packet directly to the link.
//
// If the link-layer has its own header, the payload must already include the
// header.
//
// WriteRawPacket may modify the packet.
WriteRawPacket(*PacketBuffer) tcpip.Error
}
// NetworkLinkEndpoint is a data-link layer that supports sending network
// layer packets.
type NetworkLinkEndpoint interface {
@@ -860,7 +848,6 @@ type QueueingDiscipline interface {
type LinkEndpoint interface {
NetworkLinkEndpoint
LinkWriter
LinkRawWriter
}
// InjectableLinkEndpoint is a LinkEndpoint where inbound packets are
+1 -1
View File
@@ -1646,7 +1646,7 @@ func (s *Stack) WriteRawPacket(nicID tcpip.NICID, proto tcpip.NetworkProtocolNum
})
defer pkt.DecRef()
pkt.NetworkProtocolNumber = proto
return nic.WriteRawPacket(pkt)
return nic.writeRawPacket(pkt)
}
// NetworkProtocolInstance returns the protocol instance in the stack for the