netstack: introduce PacketBufferPtr

PiperOrigin-RevId: 479437464
This commit is contained in:
Kevin Krakauer
2022-10-06 16:16:54 -07:00
committed by gVisor bot
parent 5c9476aa87
commit 4eca206fa4
100 changed files with 700 additions and 685 deletions
+4
View File
@@ -218,3 +218,7 @@ analyzers:
suppress:
- "comment on exported type Translation" # Intentional.
- "comment on exported type PinnedRange" # Intentional.
ST1016: # CheckReceiverNamesIdentical
internal:
exclude:
- pkg/tcpip/stack/packet_buffer.go # TODO(b/233086175): Remove.
+1 -1
View File
@@ -114,7 +114,7 @@ func (*OwnerMatcher) name() string {
}
// Match implements Matcher.Match.
func (om *OwnerMatcher) Match(hook stack.Hook, pkt *stack.PacketBuffer, _, _ string) (bool, bool) {
func (om *OwnerMatcher) Match(hook stack.Hook, pkt stack.PacketBufferPtr, _, _ string) (bool, bool) {
// Support only for OUTPUT chain.
if hook != stack.Output {
return false, true
+1 -1
View File
@@ -644,7 +644,7 @@ func (jt *JumpTarget) id() targetID {
}
// Action implements stack.Target.Action.
func (jt *JumpTarget) Action(*stack.PacketBuffer, stack.Hook, *stack.Route, stack.AddressableEndpoint) (stack.RuleVerdict, int) {
func (jt *JumpTarget) Action(stack.PacketBufferPtr, stack.Hook, *stack.Route, stack.AddressableEndpoint) (stack.RuleVerdict, int) {
return stack.RuleJump, jt.RuleNum
}
+1 -1
View File
@@ -95,7 +95,7 @@ func (*TCPMatcher) name() string {
}
// Match implements Matcher.Match.
func (tm *TCPMatcher) Match(hook stack.Hook, pkt *stack.PacketBuffer, _, _ string) (bool, bool) {
func (tm *TCPMatcher) Match(hook stack.Hook, pkt stack.PacketBufferPtr, _, _ string) (bool, bool) {
switch pkt.NetworkProtocolNumber {
case header.IPv4ProtocolNumber:
netHeader := header.IPv4(pkt.NetworkHeader().Slice())
+1 -1
View File
@@ -92,7 +92,7 @@ func (*UDPMatcher) name() string {
}
// Match implements Matcher.Match.
func (um *UDPMatcher) Match(hook stack.Hook, pkt *stack.PacketBuffer, _, _ string) (bool, bool) {
func (um *UDPMatcher) Match(hook stack.Hook, pkt stack.PacketBufferPtr, _, _ string) (bool, bool) {
switch pkt.NetworkProtocolNumber {
case header.IPv4ProtocolNumber:
netHeader := header.IPv4(pkt.NetworkHeader().Slice())
+7 -7
View File
@@ -27,7 +27,7 @@ import (
// pkt.Data.
//
// Returns true if the header was successfully parsed.
func ARP(pkt *stack.PacketBuffer) bool {
func ARP(pkt stack.PacketBufferPtr) bool {
_, ok := pkt.NetworkHeader().Consume(header.ARPSize)
if ok {
pkt.NetworkProtocolNumber = header.ARPProtocolNumber
@@ -39,7 +39,7 @@ func ARP(pkt *stack.PacketBuffer) bool {
// header with the IPv4 header.
//
// Returns true if the header was successfully parsed.
func IPv4(pkt *stack.PacketBuffer) bool {
func IPv4(pkt stack.PacketBufferPtr) bool {
hdr, ok := pkt.Data().PullUp(header.IPv4MinimumSize)
if !ok {
return false
@@ -71,7 +71,7 @@ func IPv4(pkt *stack.PacketBuffer) bool {
// IPv6 parses an IPv6 packet found in pkt.Data and populates pkt's network
// header with the IPv6 header.
func IPv6(pkt *stack.PacketBuffer) (proto tcpip.TransportProtocolNumber, fragID uint32, fragOffset uint16, fragMore bool, ok bool) {
func IPv6(pkt stack.PacketBufferPtr) (proto tcpip.TransportProtocolNumber, fragID uint32, fragOffset uint16, fragMore bool, ok bool) {
hdr, ok := pkt.Data().PullUp(header.IPv6MinimumSize)
if !ok {
return 0, 0, 0, false, false
@@ -157,7 +157,7 @@ traverseExtensions:
// header with the UDP header.
//
// Returns true if the header was successfully parsed.
func UDP(pkt *stack.PacketBuffer) bool {
func UDP(pkt stack.PacketBufferPtr) bool {
_, ok := pkt.TransportHeader().Consume(header.UDPMinimumSize)
pkt.TransportProtocolNumber = header.UDPProtocolNumber
return ok
@@ -167,7 +167,7 @@ func UDP(pkt *stack.PacketBuffer) bool {
// header with the TCP header.
//
// Returns true if the header was successfully parsed.
func TCP(pkt *stack.PacketBuffer) bool {
func TCP(pkt stack.PacketBufferPtr) bool {
// TCP header is variable length, peek at it first.
hdrLen := header.TCPMinimumSize
hdr, ok := pkt.Data().PullUp(hdrLen)
@@ -191,7 +191,7 @@ func TCP(pkt *stack.PacketBuffer) bool {
// if present.
//
// Returns true if an ICMPv4 header was successfully parsed.
func ICMPv4(pkt *stack.PacketBuffer) bool {
func ICMPv4(pkt stack.PacketBufferPtr) bool {
if _, ok := pkt.TransportHeader().Consume(header.ICMPv4MinimumSize); ok {
pkt.TransportProtocolNumber = header.ICMPv4ProtocolNumber
return true
@@ -203,7 +203,7 @@ func ICMPv4(pkt *stack.PacketBuffer) bool {
// if present.
//
// Returns true if an ICMPv6 header was successfully parsed.
func ICMPv6(pkt *stack.PacketBuffer) bool {
func ICMPv6(pkt stack.PacketBufferPtr) bool {
hdr, ok := pkt.Data().PullUp(header.ICMPv6MinimumSize)
if !ok {
return false
+10 -10
View File
@@ -43,7 +43,7 @@ type NotificationHandle struct {
type queue struct {
// c is the outbound packet channel.
c chan *stack.PacketBuffer
c chan stack.PacketBufferPtr
mu sync.RWMutex
// +checklocks:mu
notify []*NotificationHandle
@@ -58,7 +58,7 @@ func (q *queue) Close() {
q.closed = true
}
func (q *queue) Read() *stack.PacketBuffer {
func (q *queue) Read() stack.PacketBufferPtr {
select {
case p := <-q.c:
return p
@@ -67,7 +67,7 @@ func (q *queue) Read() *stack.PacketBuffer {
}
}
func (q *queue) ReadContext(ctx context.Context) *stack.PacketBuffer {
func (q *queue) ReadContext(ctx context.Context) stack.PacketBufferPtr {
select {
case pkt := <-q.c:
return pkt
@@ -76,7 +76,7 @@ func (q *queue) ReadContext(ctx context.Context) *stack.PacketBuffer {
}
}
func (q *queue) Write(pkt *stack.PacketBuffer) tcpip.Error {
func (q *queue) Write(pkt stack.PacketBufferPtr) tcpip.Error {
// q holds the PacketBuffer.
q.mu.RLock()
if q.closed {
@@ -149,7 +149,7 @@ type Endpoint struct {
func New(size int, mtu uint32, linkAddr tcpip.LinkAddress) *Endpoint {
return &Endpoint{
q: &queue{
c: make(chan *stack.PacketBuffer, size),
c: make(chan stack.PacketBufferPtr, size),
},
mtu: mtu,
linkAddr: linkAddr,
@@ -164,20 +164,20 @@ func (e *Endpoint) Close() {
}
// Read does non-blocking read one packet from the outbound packet queue.
func (e *Endpoint) Read() *stack.PacketBuffer {
func (e *Endpoint) Read() stack.PacketBufferPtr {
return e.q.Read()
}
// ReadContext does blocking read for one packet from the outbound packet queue.
// It can be cancelled by ctx, and in this case, it returns nil.
func (e *Endpoint) ReadContext(ctx context.Context) *stack.PacketBuffer {
func (e *Endpoint) ReadContext(ctx context.Context) stack.PacketBufferPtr {
return e.q.ReadContext(ctx)
}
// Drain removes all outbound packets from the channel and counts them.
func (e *Endpoint) Drain() int {
c := 0
for pkt := e.Read(); pkt != nil; pkt = e.Read() {
for pkt := e.Read(); !pkt.IsNil(); pkt = e.Read() {
pkt.DecRef()
c++
}
@@ -190,7 +190,7 @@ func (e *Endpoint) NumQueued() int {
}
// InjectInbound injects an inbound packet.
func (e *Endpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (e *Endpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
e.dispatcher.DeliverNetworkPacket(protocol, pkt)
}
@@ -274,4 +274,4 @@ func (*Endpoint) ARPHardwareType() header.ARPHardwareType {
}
// AddHeader implements stack.LinkEndpoint.AddHeader.
func (*Endpoint) AddHeader(*stack.PacketBuffer) {}
func (*Endpoint) AddHeader(stack.PacketBufferPtr) {}
+2 -2
View File
@@ -59,7 +59,7 @@ func (e *Endpoint) MTU() uint32 {
}
// DeliverNetworkPacket implements stack.NetworkDispatcher.
func (e *Endpoint) DeliverNetworkPacket(_ tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (e *Endpoint) DeliverNetworkPacket(_ tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
hdr, ok := pkt.LinkHeader().Consume(header.EthernetMinimumSize)
if !ok {
return
@@ -93,7 +93,7 @@ func (e *Endpoint) ARPHardwareType() header.ARPHardwareType {
}
// AddHeader implements stack.LinkEndpoint.
func (*Endpoint) AddHeader(pkt *stack.PacketBuffer) {
func (*Endpoint) AddHeader(pkt stack.PacketBufferPtr) {
eth := header.Ethernet(pkt.LinkHeader().Push(header.EthernetMinimumSize))
fields := header.EthernetFields{
SrcAddr: pkt.EgressRoute.LocalLinkAddress,
+3 -3
View File
@@ -35,11 +35,11 @@ type testNetworkDispatcher struct {
networkPackets int
}
func (t *testNetworkDispatcher) DeliverNetworkPacket(tcpip.NetworkProtocolNumber, *stack.PacketBuffer) {
func (t *testNetworkDispatcher) DeliverNetworkPacket(tcpip.NetworkProtocolNumber, stack.PacketBufferPtr) {
t.networkPackets++
}
func (*testNetworkDispatcher) DeliverLinkPacket(tcpip.NetworkProtocolNumber, *stack.PacketBuffer, bool) {
func (*testNetworkDispatcher) DeliverLinkPacket(tcpip.NetworkProtocolNumber, stack.PacketBufferPtr, bool) {
panic("not implemented")
}
@@ -146,7 +146,7 @@ func TestWritePacketToRemoteAddHeader(t *testing.T) {
{
pkt := c.Read()
if pkt == nil {
if pkt.IsNil() {
t.Fatal("expected to read a packet")
}
+5 -5
View File
@@ -509,7 +509,7 @@ const (
)
// AddHeader implements stack.LinkEndpoint.AddHeader.
func (e *endpoint) AddHeader(pkt *stack.PacketBuffer) {
func (e *endpoint) AddHeader(pkt stack.PacketBufferPtr) {
if e.hdrSize > 0 {
// Add ethernet header if needed.
eth := header.Ethernet(pkt.LinkHeader().Push(header.EthernetMinimumSize))
@@ -523,7 +523,7 @@ func (e *endpoint) AddHeader(pkt *stack.PacketBuffer) {
// 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 {
func (e *endpoint) writePacket(pkt stack.PacketBufferPtr) tcpip.Error {
fdInfo := e.fds[pkt.Hash%uint32(len(e.fds))]
fd := fdInfo.fd
var vnetHdrBuf []byte
@@ -573,7 +573,7 @@ func (e *endpoint) writePacket(pkt *stack.PacketBuffer) tcpip.Error {
return rawfile.NonBlockingWriteIovec(fd, iovecs)
}
func (e *endpoint) sendBatch(batchFDInfo fdInfo, pkts []*stack.PacketBuffer) (int, tcpip.Error) {
func (e *endpoint) sendBatch(batchFDInfo fdInfo, pkts []stack.PacketBufferPtr) (int, tcpip.Error) {
// Degrade to writePacket if underlying fd is not a socket.
if !batchFDInfo.isSocket {
var written int
@@ -690,7 +690,7 @@ func (e *endpoint) sendBatch(batchFDInfo fdInfo, pkts []*stack.PacketBuffer) (in
// - pkt.NetworkProtocolNumber
func (e *endpoint) WritePackets(pkts stack.PacketBufferList) (int, tcpip.Error) {
// Preallocate to avoid repeated reallocation as we append to batch.
batch := make([]*stack.PacketBuffer, 0, BatchSize)
batch := make([]stack.PacketBufferPtr, 0, BatchSize)
batchFDInfo := fdInfo{fd: -1, isSocket: false}
sentPackets := 0
for _, pkt := range pkts.AsSlice() {
@@ -775,7 +775,7 @@ func (e *InjectableEndpoint) Attach(dispatcher stack.NetworkDispatcher) {
}
// InjectInbound injects an inbound packet.
func (e *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (e *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
e.dispatcher.DeliverNetworkPacket(protocol, pkt)
}
+8 -8
View File
@@ -48,7 +48,7 @@ const (
type packetInfo struct {
Proto tcpip.NetworkProtocolNumber
Contents *stack.PacketBuffer
Contents stack.PacketBufferPtr
}
type packetContents struct {
@@ -62,8 +62,8 @@ func checkPacketInfoEqual(t *testing.T, got, want packetInfo) {
t.Helper()
if diff := cmp.Diff(
want, got,
cmp.Transformer("ExtractPacketBuffer", func(pk *stack.PacketBuffer) *packetContents {
if pk == nil {
cmp.Transformer("ExtractPacketBuffer", func(pk stack.PacketBufferPtr) *packetContents {
if pk.IsNil() {
return nil
}
return &packetContents{
@@ -133,12 +133,12 @@ func (c *context) cleanup() {
}
}
func (c *context) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (c *context) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
pkt.IncRef()
c.ch <- packetInfo{protocol, pkt}
}
func (c *context) DeliverLinkPacket(tcpip.NetworkProtocolNumber, *stack.PacketBuffer, bool) {
func (c *context) DeliverLinkPacket(tcpip.NetworkProtocolNumber, stack.PacketBufferPtr, bool) {
c.t.Fatal("DeliverLinkPacket not implemented")
}
@@ -568,15 +568,15 @@ func TestIovecBufferSkipVnetHdr(t *testing.T) {
// fakeNetworkDispatcher delivers packets to pkts.
type fakeNetworkDispatcher struct {
pkts []*stack.PacketBuffer
pkts []stack.PacketBufferPtr
}
func (d *fakeNetworkDispatcher) DeliverNetworkPacket(_ tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (d *fakeNetworkDispatcher) DeliverNetworkPacket(_ tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
pkt.IncRef()
d.pkts = append(d.pkts, pkt)
}
func (*fakeNetworkDispatcher) DeliverLinkPacket(tcpip.NetworkProtocolNumber, *stack.PacketBuffer, bool) {
func (*fakeNetworkDispatcher) DeliverLinkPacket(tcpip.NetworkProtocolNumber, stack.PacketBufferPtr, bool) {
panic("not implemented")
}
+1 -1
View File
@@ -93,4 +93,4 @@ func (*endpoint) ARPHardwareType() header.ARPHardwareType {
return header.ARPHardwareLoopback
}
func (*endpoint) AddHeader(*stack.PacketBuffer) {}
func (*endpoint) AddHeader(stack.PacketBufferPtr) {}
+2 -2
View File
@@ -81,7 +81,7 @@ func (m *InjectableEndpoint) IsAttached() bool {
}
// InjectInbound implements stack.InjectableLinkEndpoint.
func (m *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (m *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
m.dispatcher.DeliverNetworkPacket(protocol, pkt)
}
@@ -133,7 +133,7 @@ func (*InjectableEndpoint) ARPHardwareType() header.ARPHardwareType {
}
// AddHeader implements stack.LinkEndpoint.AddHeader.
func (*InjectableEndpoint) AddHeader(*stack.PacketBuffer) {}
func (*InjectableEndpoint) AddHeader(stack.PacketBufferPtr) {}
// NewInjectableEndpoint creates a new multi-endpoint injectable endpoint.
func NewInjectableEndpoint(routes map[tcpip.Address]stack.InjectableLinkEndpoint) *InjectableEndpoint {
+3 -3
View File
@@ -51,7 +51,7 @@ func (e *Endpoint) Init(child stack.LinkEndpoint, embedder stack.NetworkDispatch
}
// DeliverNetworkPacket implements stack.NetworkDispatcher.
func (e *Endpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (e *Endpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
e.mu.RLock()
d := e.dispatcher
e.mu.RUnlock()
@@ -61,7 +61,7 @@ func (e *Endpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pk
}
// DeliverLinkPacket implements stack.NetworkDispatcher.
func (e *Endpoint) DeliverLinkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer, incoming bool) {
func (e *Endpoint) DeliverLinkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr, incoming bool) {
e.mu.RLock()
d := e.dispatcher
e.mu.RUnlock()
@@ -144,6 +144,6 @@ func (e *Endpoint) ARPHardwareType() header.ARPHardwareType {
}
// AddHeader implements stack.LinkEndpoint.AddHeader.
func (e *Endpoint) AddHeader(pkt *stack.PacketBuffer) {
func (e *Endpoint) AddHeader(pkt stack.PacketBufferPtr) {
e.child.AddHeader(pkt)
}
+2 -2
View File
@@ -54,11 +54,11 @@ type counterDispatcher struct {
var _ stack.NetworkDispatcher = (*counterDispatcher)(nil)
func (d *counterDispatcher) DeliverNetworkPacket(tcpip.NetworkProtocolNumber, *stack.PacketBuffer) {
func (d *counterDispatcher) DeliverNetworkPacket(tcpip.NetworkProtocolNumber, stack.PacketBufferPtr) {
d.count++
}
func (*counterDispatcher) DeliverLinkPacket(tcpip.NetworkProtocolNumber, *stack.PacketBuffer, bool) {
func (*counterDispatcher) DeliverLinkPacket(tcpip.NetworkProtocolNumber, stack.PacketBufferPtr, bool) {
panic("not implemented")
}
+1 -1
View File
@@ -40,7 +40,7 @@ func New(lower stack.LinkEndpoint) stack.LinkEndpoint {
}
// DeliverNetworkPacket implements stack.NetworkDispatcher.
func (e *endpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (e *endpoint) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
e.Endpoint.DeliverLinkPacket(protocol, pkt, true /* incoming */)
e.Endpoint.DeliverNetworkPacket(protocol, pkt)
@@ -53,18 +53,18 @@ func (e *nullEndpoint) Attach(d stack.NetworkDispatcher) { e.disp = d }
func (e *nullEndpoint) IsAttached() bool { return e.disp != nil }
func (*nullEndpoint) Wait() {}
func (*nullEndpoint) ARPHardwareType() header.ARPHardwareType { return header.ARPHardwareNone }
func (*nullEndpoint) AddHeader(*stack.PacketBuffer) {}
func (*nullEndpoint) AddHeader(stack.PacketBufferPtr) {}
var _ stack.NetworkDispatcher = (*testNetworkDispatcher)(nil)
type linkPacketInfo struct {
pkt *stack.PacketBuffer
pkt stack.PacketBufferPtr
protocol tcpip.NetworkProtocolNumber
incoming bool
}
type networkPacketInfo struct {
pkt *stack.PacketBuffer
pkt stack.PacketBufferPtr
protocol tcpip.NetworkProtocolNumber
}
@@ -77,17 +77,17 @@ type testNetworkDispatcher struct {
}
func (t *testNetworkDispatcher) reset() {
if pkt := t.linkPacket.pkt; pkt != nil {
if pkt := t.linkPacket.pkt; !pkt.IsNil() {
pkt.DecRef()
}
if pkt := t.networkPacket.pkt; pkt != nil {
if pkt := t.networkPacket.pkt; !pkt.IsNil() {
pkt.DecRef()
}
*t = testNetworkDispatcher{}
}
func (t *testNetworkDispatcher) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
func (t *testNetworkDispatcher) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr) {
networkPacket := networkPacketInfo{
pkt: pkt.IncRef(),
protocol: protocol,
@@ -100,7 +100,7 @@ func (t *testNetworkDispatcher) DeliverNetworkPacket(protocol tcpip.NetworkProto
t.networkPacket = networkPacket
}
func (t *testNetworkDispatcher) DeliverLinkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer, incoming bool) {
func (t *testNetworkDispatcher) DeliverLinkPacket(protocol tcpip.NetworkProtocolNumber, pkt stack.PacketBufferPtr, incoming bool) {
linkPacket := linkPacketInfo{
pkt: pkt.IncRef(),
protocol: protocol,
+1 -1
View File
@@ -110,4 +110,4 @@ func (*Endpoint) ARPHardwareType() header.ARPHardwareType {
}
// AddHeader implements stack.LinkEndpoint.
func (*Endpoint) AddHeader(*stack.PacketBuffer) {}
func (*Endpoint) AddHeader(stack.PacketBufferPtr) {}
+3 -3
View File
@@ -97,7 +97,7 @@ func (qd *queueDispatcher) dispatchLoop() {
case &qd.newPacketWaker:
case &qd.closeWaker:
qd.mu.Lock()
for p := qd.queue.removeFront(); p != nil; p = qd.queue.removeFront() {
for p := qd.queue.removeFront(); !p.IsNil(); p = qd.queue.removeFront() {
p.DecRef()
}
qd.queue.decRef()
@@ -107,7 +107,7 @@ func (qd *queueDispatcher) dispatchLoop() {
panic("unknown waker")
}
qd.mu.Lock()
for pkt := qd.queue.removeFront(); pkt != nil; pkt = qd.queue.removeFront() {
for pkt := qd.queue.removeFront(); !pkt.IsNil(); pkt = qd.queue.removeFront() {
batch.PushBack(pkt)
if batch.Len() < BatchSize && !qd.queue.isEmpty() {
continue
@@ -127,7 +127,7 @@ func (qd *queueDispatcher) dispatchLoop() {
// - pkt.EgressRoute
// - pkt.GSOOptions
// - pkt.NetworkProtocolNumber
func (d *discipline) WritePacket(pkt *stack.PacketBuffer) tcpip.Error {
func (d *discipline) WritePacket(pkt stack.PacketBufferPtr) tcpip.Error {
if d.closed.Load() == qDiscClosed {
return &tcpip.ErrClosedForSend{}
}
@@ -23,14 +23,14 @@ import "gvisor.dev/gvisor/pkg/tcpip/stack"
//
// +stateify savable
type packetBufferCircularList struct {
pbs []*stack.PacketBuffer
pbs []stack.PacketBufferPtr
head int
size int
}
// init initializes the list with the given size.
func (pl *packetBufferCircularList) init(size int) {
pl.pbs = make([]*stack.PacketBuffer, size)
pl.pbs = make([]stack.PacketBufferPtr, size)
}
// length returns the number of elements in the list.
@@ -60,7 +60,7 @@ func (pl *packetBufferCircularList) isEmpty() bool {
// Failing to do so may clobber existing entries.
//
//go:nosplit
func (pl *packetBufferCircularList) pushBack(pb *stack.PacketBuffer) {
func (pl *packetBufferCircularList) pushBack(pb stack.PacketBufferPtr) {
next := (pl.head + pl.size) % len(pl.pbs)
pl.pbs[next] = pb
pl.size++
@@ -69,7 +69,7 @@ func (pl *packetBufferCircularList) pushBack(pb *stack.PacketBuffer) {
// removeFront returns the first element of the list or nil.
//
//go:nosplit
func (pl *packetBufferCircularList) removeFront() *stack.PacketBuffer {
func (pl *packetBufferCircularList) removeFront() stack.PacketBufferPtr {
if pl.isEmpty() {
return nil
}

Some files were not shown because too many files have changed in this diff Show More