diff --git a/pkg/tcpip/link/channel/channel.go b/pkg/tcpip/link/channel/channel.go index 2f61b871c..1b4d5d7ee 100644 --- a/pkg/tcpip/link/channel/channel.go +++ b/pkg/tcpip/link/channel/channel.go @@ -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 -} diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go index 51505aadf..60348afe4 100644 --- a/pkg/tcpip/link/fdbased/endpoint.go +++ b/pkg/tcpip/link/fdbased/endpoint.go @@ -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 { diff --git a/pkg/tcpip/link/loopback/loopback.go b/pkg/tcpip/link/loopback/loopback.go index c9f3d2af5..72e6dc176 100644 --- a/pkg/tcpip/link/loopback/loopback.go +++ b/pkg/tcpip/link/loopback/loopback.go @@ -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 -} diff --git a/pkg/tcpip/link/muxed/injectable.go b/pkg/tcpip/link/muxed/injectable.go index 48dcf3176..d043e5bf2 100644 --- a/pkg/tcpip/link/muxed/injectable.go +++ b/pkg/tcpip/link/muxed/injectable.go @@ -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{ diff --git a/pkg/tcpip/link/nested/nested.go b/pkg/tcpip/link/nested/nested.go index 38485ff0e..2920dc0ee 100644 --- a/pkg/tcpip/link/nested/nested.go +++ b/pkg/tcpip/link/nested/nested.go @@ -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) -} diff --git a/pkg/tcpip/link/pipe/pipe.go b/pkg/tcpip/link/pipe/pipe.go index 5bce2376b..e95f8b9a6 100644 --- a/pkg/tcpip/link/pipe/pipe.go +++ b/pkg/tcpip/link/pipe/pipe.go @@ -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 -} diff --git a/pkg/tcpip/link/sharedmem/sharedmem.go b/pkg/tcpip/link/sharedmem/sharedmem.go index 9fec2614b..f8838d8a0 100644 --- a/pkg/tcpip/link/sharedmem/sharedmem.go +++ b/pkg/tcpip/link/sharedmem/sharedmem.go @@ -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 { diff --git a/pkg/tcpip/link/sharedmem/sharedmem_server.go b/pkg/tcpip/link/sharedmem/sharedmem_server.go index a5626b74a..7c5f5571d 100644 --- a/pkg/tcpip/link/sharedmem/sharedmem_server.go +++ b/pkg/tcpip/link/sharedmem/sharedmem_server.go @@ -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 { diff --git a/pkg/tcpip/link/waitable/waitable.go b/pkg/tcpip/link/waitable/waitable.go index 1185309e8..8babb4525 100644 --- a/pkg/tcpip/link/waitable/waitable.go +++ b/pkg/tcpip/link/waitable/waitable.go @@ -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{} } diff --git a/pkg/tcpip/link/waitable/waitable_test.go b/pkg/tcpip/link/waitable/waitable_test.go index 019415ddc..6437d743e 100644 --- a/pkg/tcpip/link/waitable/waitable_test.go +++ b/pkg/tcpip/link/waitable/waitable_test.go @@ -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") diff --git a/pkg/tcpip/network/internal/testutil/testutil.go b/pkg/tcpip/network/internal/testutil/testutil.go index 43a9e8a6d..c03e6072b 100644 --- a/pkg/tcpip/network/internal/testutil/testutil.go +++ b/pkg/tcpip/network/internal/testutil/testutil.go @@ -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 diff --git a/pkg/tcpip/stack/forwarding_test.go b/pkg/tcpip/stack/forwarding_test.go index 79b7d9f4a..452da39b4 100644 --- a/pkg/tcpip/stack/forwarding_test.go +++ b/pkg/tcpip/stack/forwarding_test.go @@ -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() {} diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go index 996ad0f3f..6e9a0f30c 100644 --- a/pkg/tcpip/stack/nic.go +++ b/pkg/tcpip/stack/nic.go @@ -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 } diff --git a/pkg/tcpip/stack/registration.go b/pkg/tcpip/stack/registration.go index 5e1d8f045..22c35baf7 100644 --- a/pkg/tcpip/stack/registration.go +++ b/pkg/tcpip/stack/registration.go @@ -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 diff --git a/pkg/tcpip/stack/stack.go b/pkg/tcpip/stack/stack.go index e4ba3a9b3..2a05d29b3 100644 --- a/pkg/tcpip/stack/stack.go +++ b/pkg/tcpip/stack/stack.go @@ -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