Netstack S/R: Mark all the structs in netstack as savable.

Marks the structs in netstack as savable. This does not change or break any
existing behavior as the netstack itself is not savable yet.

PiperOrigin-RevId: 635943481
This commit is contained in:
Nayana Bidari
2024-05-21 15:19:07 -07:00
committed by gVisor bot
parent 79331f35cf
commit 90266aa28a
53 changed files with 515 additions and 177 deletions
+12
View File
@@ -100,6 +100,7 @@ func init() {
// The stack package provides some basic, useful targets for us. The following
// types wrap them for compatibility with the extension system.
// +stateify savable
type acceptTarget struct {
stack.AcceptTarget
}
@@ -110,6 +111,7 @@ func (at *acceptTarget) id() targetID {
}
}
// +stateify savable
type dropTarget struct {
stack.DropTarget
}
@@ -120,6 +122,7 @@ func (dt *dropTarget) id() targetID {
}
}
// +stateify savable
type errorTarget struct {
stack.ErrorTarget
}
@@ -131,6 +134,7 @@ func (et *errorTarget) id() targetID {
}
}
// +stateify savable
type userChainTarget struct {
stack.UserChainTarget
}
@@ -142,6 +146,7 @@ func (uc *userChainTarget) id() targetID {
}
}
// +stateify savable
type returnTarget struct {
stack.ReturnTarget
}
@@ -152,6 +157,7 @@ func (rt *returnTarget) id() targetID {
}
}
// +stateify savable
type redirectTarget struct {
stack.RedirectTarget
@@ -167,6 +173,7 @@ func (rt *redirectTarget) id() targetID {
}
}
// +stateify savable
type standardTargetMaker struct {
NetworkProtocol tcpip.NetworkProtocolNumber
}
@@ -224,6 +231,7 @@ func (*standardTargetMaker) unmarshal(buf []byte, filter stack.IPHeaderFilter) (
}, nil
}
// +stateify savable
type errorTargetMaker struct {
NetworkProtocol tcpip.NetworkProtocolNumber
}
@@ -287,6 +295,7 @@ func (*errorTargetMaker) unmarshal(buf []byte, filter stack.IPHeaderFilter) (tar
}
}
// +stateify savable
type redirectTargetMaker struct {
NetworkProtocol tcpip.NetworkProtocolNumber
}
@@ -364,6 +373,7 @@ func (*redirectTargetMaker) unmarshal(buf []byte, filter stack.IPHeaderFilter) (
return &target, nil
}
// +stateify savable
type nfNATTargetMaker struct {
NetworkProtocol tcpip.NetworkProtocolNumber
}
@@ -478,6 +488,8 @@ func parseTarget(filter stack.IPHeaderFilter, optVal []byte, ipv6 bool) (stack.T
}
// JumpTarget implements stack.Target.
//
// +stateify savable
type JumpTarget struct {
// Offset is the byte offset of the rule to jump to. It is used for
// marshaling and unmarshaling.
+35 -21
View File
@@ -25,6 +25,8 @@ import (
)
// NullClock implements a clock that never advances.
//
// +stateify savable
type NullClock struct{}
var _ tcpip.Clock = (*NullClock)(nil)
@@ -40,6 +42,8 @@ func (*NullClock) NowMonotonic() tcpip.MonotonicTime {
}
// nullTimer implements a timer that never fires.
//
// +stateify savable
type nullTimer struct{}
var _ tcpip.Timer = (*nullTimer)(nil)
@@ -92,26 +96,31 @@ func (n *notificationChannels) wait() {
}
}
// +stateify savable
type manualClockMutex struct {
sync.RWMutex `state:"nosave"`
// now is the current (fake) time of the clock.
now time.Time
// times is min-heap of times.
times timeHeap
// timers holds the timers scheduled for each time.
timers map[time.Time]map[*manualTimer]struct{}
}
// ManualClock implements tcpip.Clock and only advances manually with Advance
// method.
//
// +stateify savable
type ManualClock struct {
// runningTimers tracks the completion of timer callbacks that began running
// immediately upon their scheduling. It is used to ensure the proper ordering
// of timer callback dispatch.
runningTimers notificationChannels
mu struct {
sync.RWMutex
// now is the current (fake) time of the clock.
now time.Time
// times is min-heap of times.
times timeHeap
// timers holds the timers scheduled for each time.
timers map[time.Time]map[*manualTimer]struct{}
}
mu manualClockMutex
}
// NewManualClock creates a new ManualClock instance.
@@ -325,18 +334,23 @@ func (mc *ManualClock) stopTimer(mt *manualTimer) bool {
return true
}
// +stateify savable
type manualTimerMu struct {
sync.Mutex `state:"nosave"`
// firesAt is the time when the timer will fire.
//
// Zero only when the timer is not active.
firesAt time.Time
}
// +stateify savable
type manualTimer struct {
clock *ManualClock
f func()
// TODO(b/341946753): Restore when netstack is savable.
f func() `state:"nosave"`
mu struct {
sync.Mutex
// firesAt is the time when the timer will fire.
//
// Zero only when the timer is not active.
firesAt time.Time
}
mu manualTimerMu
}
var _ tcpip.Timer = (*manualTimer)(nil)
+3 -1
View File
@@ -134,13 +134,15 @@ var _ stack.GSOEndpoint = (*Endpoint)(nil)
// Endpoint is link layer endpoint that stores outbound packets in a channel
// and allows injection of inbound packets.
//
// +stateify savable
type Endpoint struct {
mtu uint32
linkAddr tcpip.LinkAddress
LinkEPCapabilities stack.LinkEndpointCapabilities
SupportedGSOKind stack.SupportedGSO
mu sync.RWMutex
mu sync.RWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
+2
View File
@@ -38,6 +38,8 @@ func New(ep stack.LinkEndpoint) *Endpoint {
// It adds an ethernet header to packets before sending them out through its
// inner link endpoint and consumes an ethernet header before sending the
// packet to the stack.
//
// +stateify savable
type Endpoint struct {
nested.Endpoint
}
+8 -2
View File
@@ -107,11 +107,13 @@ func (p PacketDispatchMode) String() string {
var _ stack.LinkEndpoint = (*endpoint)(nil)
var _ stack.GSOEndpoint = (*endpoint)(nil)
// +stateify savable
type fdInfo struct {
fd int
isSocket bool
}
// +stateify savable
type endpoint struct {
// fds is the set of file descriptors each identifying one inbound/outbound
// channel. The endpoint will dispatch from all inbound channels as well as
@@ -137,7 +139,7 @@ type endpoint struct {
inboundDispatchers []linkDispatcher
mu sync.RWMutex
mu sync.RWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
@@ -171,6 +173,8 @@ type endpoint struct {
}
// Options specify the details about the fd-based endpoint to be created.
//
// +stateify savable
type Options struct {
// FDs is a set of FDs used to read/write packets.
FDs []int
@@ -800,10 +804,12 @@ func (e *endpoint) ARPHardwareType() header.ARPHardwareType {
// InjectableEndpoint is an injectable fd-based endpoint. The endpoint writes
// to the FD, but does not read from it. All reads come from injected packets.
//
// +satetify savable
type InjectableEndpoint struct {
endpoint
mu sync.RWMutex
mu sync.RWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
}
+2 -1
View File
@@ -28,8 +28,9 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/stack"
)
// +stateify savable
type endpoint struct {
mu sync.RWMutex
mu sync.RWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
}
+3 -1
View File
@@ -28,10 +28,12 @@ import (
// trivial routing rules that determine which InjectableEndpoint a given packet
// will be written to. Note that HandleLocal works differently for this
// endpoint (see WritePacket).
//
// +stateify savable
type InjectableEndpoint struct {
routes map[tcpip.Address]stack.InjectableLinkEndpoint
mu sync.RWMutex
mu sync.RWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
}
+3 -1
View File
@@ -28,12 +28,14 @@ import (
// concurrency guards.
//
// See the tests in this package for example usage.
//
// +stateify savable
type Endpoint struct {
child stack.LinkEndpoint
embedder stack.NetworkDispatcher
// mu protects dispatcher.
mu sync.RWMutex
mu sync.RWMutex `state:"nosave"`
dispatcher stack.NetworkDispatcher
}
@@ -25,6 +25,7 @@ import (
var _ stack.NetworkDispatcher = (*endpoint)(nil)
var _ stack.LinkEndpoint = (*endpoint)(nil)
// +stateify savable
type endpoint struct {
nested.Endpoint
}
+3 -1
View File
@@ -42,12 +42,14 @@ func New(linkAddr1, linkAddr2 tcpip.LinkAddress, mtu uint32) (*Endpoint, *Endpoi
}
// Endpoint is one end of a pipe.
//
// +stateify savable
type Endpoint struct {
linked *Endpoint
linkAddr tcpip.LinkAddress
mtu uint32
mu sync.RWMutex
mu sync.RWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
}
+8 -2
View File
@@ -41,6 +41,8 @@ import (
// QueueConfig holds all the file descriptors needed to describe a tx or rx
// queue over shared memory. It is used when creating new shared memory
// endpoints to describe tx and rx queues.
//
// +stateify savable
type QueueConfig struct {
// DataFD is a file descriptor for the file that contains the data to
// be transmitted via this queue. Descriptors contain offsets within
@@ -92,6 +94,8 @@ func QueueConfigFromFDs(fds []int) (QueueConfig, error) {
}
// Options specify the details about the sharedmem endpoint to be created.
//
// +stateify savable
type Options struct {
// MTU is the mtu to use for this endpoint.
MTU uint32
@@ -142,6 +146,7 @@ type Options struct {
var _ stack.LinkEndpoint = (*endpoint)(nil)
var _ stack.GSOEndpoint = (*endpoint)(nil)
// +stateify savable
type endpoint struct {
// mtu (maximum transmission unit) is the maximum size of a packet.
// mtu is immutable.
@@ -187,10 +192,11 @@ type endpoint struct {
// onClosed is a function to be called when the FD's peer (if any) closes
// its end of the communication pipe.
onClosed func(tcpip.Error)
// TODO(b/341946753): Restore when netstack is savable.
onClosed func(tcpip.Error) `state:"nosave"`
// mu protects the following fields.
mu sync.Mutex
mu sync.Mutex `state:"nosave"`
// tx is the transmit queue.
// +checklocks:mu
+1
View File
@@ -44,6 +44,7 @@ var LogPackets atomicbitops.Uint32 = atomicbitops.FromUint32(1)
// sniffer was created for this flag to have effect.
var LogPacketsToPCAP atomicbitops.Uint32 = atomicbitops.FromUint32(1)
// +stateify savable
type endpoint struct {
nested.Endpoint
writer io.Writer
+3 -1
View File
@@ -32,10 +32,12 @@ var _ stack.NetworkDispatcher = (*Endpoint)(nil)
var _ stack.LinkEndpoint = (*Endpoint)(nil)
// Endpoint is a waitable link-layer endpoint.
//
// +stateify savable
type Endpoint struct {
dispatchGate sync.Gate
mu sync.RWMutex
mu sync.RWMutex `state:"nosave"`
// +checklocks:mu
dispatcher stack.NetworkDispatcher
+5 -3
View File
@@ -40,6 +40,7 @@ const MTU = 1500
var _ stack.LinkEndpoint = (*endpoint)(nil)
// +stateify savable
type endpoint struct {
// fd is the underlying AF_XDP socket.
fd int
@@ -52,14 +53,15 @@ type endpoint struct {
// closed is a function to be called when the FD's peer (if any) closes
// its end of the communication pipe.
closed func(tcpip.Error)
// TODO(b/341946753): Restore when netstack is savable.
closed func(tcpip.Error) `state:"nosave"`
mu sync.RWMutex
mu sync.RWMutex `state:"nosave"`
// +checkloks:mu
networkDispatcher stack.NetworkDispatcher
// wg keeps track of running goroutines.
wg sync.WaitGroup
wg sync.WaitGroup `state:"nosave"`
// control is used to control the AF_XDP socket.
control *xdp.ControlBlock
+5 -1
View File
@@ -45,6 +45,7 @@ var _ ip.DADProtocol = (*endpoint)(nil)
// the link-layer is via stack.NetworkEndpoint.HandlePacket.
var _ stack.NetworkEndpoint = (*endpoint)(nil)
// +stateify savable
type endpoint struct {
protocol *protocol
@@ -55,7 +56,7 @@ type endpoint struct {
stats sharedStats
// mu protects annotated fields below.
mu sync.Mutex
mu sync.Mutex `state:"nosave"`
// +checklocks:mu
dad ip.DAD
@@ -257,6 +258,7 @@ func (e *endpoint) Stats() stack.NetworkEndpointStats {
var _ stack.NetworkProtocol = (*protocol)(nil)
// +stateify savable
type protocol struct {
stack *stack.Stack
options Options
@@ -388,6 +390,8 @@ func (*protocol) Parse(pkt *stack.PacketBuffer) (proto tcpip.TransportProtocolNu
}
// Options holds options to configure a protocol.
//
// +stateify savable
type Options struct {
// DADConfigs is the default DAD configurations used by ARP endpoints.
DADConfigs stack.DADConfigurations
+4
View File
@@ -22,6 +22,8 @@ import (
var _ stack.NetworkEndpointStats = (*Stats)(nil)
// Stats holds statistics related to ARP.
//
// +stateify savable
type Stats struct {
// ARP holds ARP statistics.
ARP tcpip.ARPStats
@@ -30,6 +32,7 @@ type Stats struct {
// IsNetworkEndpointStats implements stack.NetworkEndpointStats.
func (*Stats) IsNetworkEndpointStats() {}
// +stateify savable
type sharedStats struct {
localStats Stats
arp multiCounterARPStats
@@ -37,6 +40,7 @@ type sharedStats struct {
// LINT.IfChange(multiCounterARPStats)
// +stateify savable
type multiCounterARPStats struct {
packetsReceived tcpip.MultiCounterStat
disabledPacketsReceived tcpip.MultiCounterStat
@@ -60,6 +60,8 @@ var (
)
// FragmentID is the identifier for a fragment.
//
// +stateify savable
type FragmentID struct {
// Source is the source address of the fragment.
Source tcpip.Address
@@ -78,8 +80,10 @@ type FragmentID struct {
// Fragmentation is the main structure that other modules
// of the stack should use to implement IP Fragmentation.
//
// +stateify savable
type Fragmentation struct {
mu sync.Mutex
mu sync.Mutex `state:"nosave"`
highLimit int
lowLimit int
reassemblers map[FragmentID]*reassembler
@@ -23,6 +23,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/stack"
)
// +stateify savable
type hole struct {
first uint16
last uint16
@@ -33,12 +34,13 @@ type hole struct {
pkt *stack.PacketBuffer
}
// +stateify savable
type reassembler struct {
reassemblerEntry
id FragmentID
memSize int
proto uint8
mu sync.Mutex
mu sync.Mutex `state:"nosave"`
holes []hole
filled int
done bool
@@ -33,6 +33,7 @@ const (
extended
)
// +stateify savable
type dadState struct {
nonce []byte
extendRequest extendRequest
@@ -50,9 +51,12 @@ type DADProtocol interface {
}
// DADOptions holds options for DAD.
//
// +stateify savable
type DADOptions struct {
Clock tcpip.Clock
SecureRNG io.Reader
Clock tcpip.Clock
// TODO(b/341946753): Restore when netstack is savable.
SecureRNG io.Reader `state:"nosave"`
NonceSize uint8
ExtendDADTransmits uint8
Protocol DADProtocol
@@ -60,11 +64,13 @@ type DADOptions struct {
}
// DAD performs duplicate address detection for addresses.
//
// +stateify savable
type DAD struct {
opts DADOptions
configs stack.DADConfigurations
protocolMU sync.Locker
protocolMU sync.Locker `state:"nosave"`
addresses map[tcpip.Address]dadState
}
@@ -105,6 +105,8 @@ const (
// multicastGroupState holds the Generic Multicast Protocol state for a
// multicast group.
//
// +stateify savable
type multicastGroupState struct {
// joins is the number of times the group has been joined.
joins uint64
@@ -130,7 +132,8 @@ type multicastGroupState struct {
// delyedReportJobFiresAt is the time when the delayed report job will fire.
//
// A zero value indicates that the job is not scheduled.
delayedReportJobFiresAt time.Time
// TODO(b/341946753): Restore when netstack is savable.
delayedReportJobFiresAt time.Time `state:"nosave"`
// queriedIncludeSources holds sources that were queried for.
//
@@ -155,9 +158,12 @@ func (m *multicastGroupState) clearQueriedIncludeSources() {
// GenericMulticastProtocolOptions holds options for the generic multicast
// protocol.
//
// +stateify savable
type GenericMulticastProtocolOptions struct {
// Rand is the source of random numbers.
Rand *rand.Rand
// TODO(b/341946753): Restore when netstack is savable.
Rand *rand.Rand `state:"nosave"`
// Clock is the clock used to create timers.
Clock tcpip.Clock
@@ -267,9 +273,11 @@ const (
//
// GenericMulticastProtocolState.MakeAllNonMemberLocked MUST be called when the
// multicast group protocol is disabled so that leave messages may be sent.
//
// +stateify savable
type GenericMulticastProtocolState struct {
// Do not allow overwriting this state.
_ sync.NoCopy
_ sync.NoCopy `state:"nosave"`
opts GenericMulticastProtocolOptions
@@ -277,7 +285,7 @@ type GenericMulticastProtocolState struct {
memberships map[tcpip.Address]multicastGroupState
// protocolMU is the mutex used to protect the protocol.
protocolMU *sync.RWMutex
protocolMU *sync.RWMutex `state:"nosave"`
// V2 state.
robustnessVariable uint8
@@ -285,8 +293,9 @@ type GenericMulticastProtocolState struct {
mode protocolMode
modeTimer tcpip.Timer
generalQueryV2Timer tcpip.Timer
generalQueryV2TimerFiresAt time.Time
generalQueryV2Timer tcpip.Timer
// TODO(b/341946753): Restore when netstack is savable.
generalQueryV2TimerFiresAt time.Time `state:"nosave"`
stateChangedReportV2Timer tcpip.Timer
stateChangedReportV2TimerSet bool

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