diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-11-18 18:22:53 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-11-18 18:22:53 +0000 |
commit | 38e95b7a0943ef013f72de2e004af96fbf50883a (patch) | |
tree | 78b933e606bac1a2125473bb2bbe302f5bd4345a /pkg/tcpip/socketops.go | |
parent | 89d431b577df59d1f3bf52e2c21c4b54d60cb9db (diff) | |
parent | fc342fb43960e5f75103e727cd122479e015d321 (diff) |
Merge release-20201109.0-71-gfc342fb43 (automated)
Diffstat (limited to 'pkg/tcpip/socketops.go')
-rw-r--r-- | pkg/tcpip/socketops.go | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/pkg/tcpip/socketops.go b/pkg/tcpip/socketops.go index 2a6c7c7c0..e1b0d6354 100644 --- a/pkg/tcpip/socketops.go +++ b/pkg/tcpip/socketops.go @@ -15,31 +15,49 @@ package tcpip import ( - "gvisor.dev/gvisor/pkg/sync" + "sync/atomic" ) -// SocketOptions contains all the variables which store values for socket +// SocketOptions contains all the variables which store values for SOL_SOCKET // level options. // // +stateify savable type SocketOptions struct { - // mu protects fields below. - mu sync.Mutex `state:"nosave"` - broadcastEnabled bool + // These fields are accessed and modified using atomic operations. + + // broadcastEnabled determines whether datagram sockets are allowed to send + // packets to a broadcast address. + broadcastEnabled uint32 + + // passCredEnabled determines whether SCM_CREDENTIALS socket control messages + // are enabled. + passCredEnabled uint32 +} + +func storeAtomicBool(addr *uint32, v bool) { + var val uint32 + if v { + val = 1 + } + atomic.StoreUint32(addr, val) } // GetBroadcast gets value for SO_BROADCAST option. func (so *SocketOptions) GetBroadcast() bool { - so.mu.Lock() - defer so.mu.Unlock() - - return so.broadcastEnabled + return atomic.LoadUint32(&so.broadcastEnabled) != 0 } // SetBroadcast sets value for SO_BROADCAST option. func (so *SocketOptions) SetBroadcast(v bool) { - so.mu.Lock() - defer so.mu.Unlock() + storeAtomicBool(&so.broadcastEnabled, v) +} + +// GetPassCred gets value for SO_PASSCRED option. +func (so *SocketOptions) GetPassCred() bool { + return atomic.LoadUint32(&so.passCredEnabled) != 0 +} - so.broadcastEnabled = v +// SetPassCred sets value for SO_PASSCRED option. +func (so *SocketOptions) SetPassCred(v bool) { + storeAtomicBool(&so.passCredEnabled, v) } |